Skip to content

Commit cec7dda

Browse files
committed
feat: show tool count in context command UI
Display 'Tools (X)' where X is the number of tools remaining in context (total tools minus pruned tools)
1 parent 17bc214 commit cec7dda

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/commands/context.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ interface TokenBreakdown {
5959
user: number
6060
assistant: number
6161
tools: number
62+
toolCount: number
6263
prunedTokens: number
6364
prunedCount: number
6465
total: number
@@ -70,6 +71,7 @@ function analyzeTokens(state: SessionState, messages: WithParts[]): TokenBreakdo
7071
user: 0,
7172
assistant: 0,
7273
tools: 0,
74+
toolCount: 0,
7375
prunedTokens: state.stats.totalPruneTokens,
7476
prunedCount: state.prune.toolIds.length,
7577
total: 0,
@@ -125,6 +127,7 @@ function analyzeTokens(state: SessionState, messages: WithParts[]): TokenBreakdo
125127
}
126128
} else if (part.type === "tool") {
127129
const toolPart = part as ToolPart
130+
breakdown.toolCount++
128131

129132
if (toolPart.state?.input) {
130133
const inputStr =
@@ -180,13 +183,18 @@ function formatContextMessage(breakdown: TokenBreakdown): string {
180183
const lines: string[] = []
181184
const barWidth = 30
182185

186+
const toolsInContext = breakdown.toolCount - breakdown.prunedCount
187+
const toolsLabel = `Tools (${toolsInContext})`
188+
183189
const categories = [
184190
{ label: "System", value: breakdown.system, char: "█" },
185191
{ label: "User", value: breakdown.user, char: "▓" },
186192
{ label: "Assistant", value: breakdown.assistant, char: "▒" },
187-
{ label: "Tools", value: breakdown.tools, char: "░" },
193+
{ label: toolsLabel, value: breakdown.tools, char: "░" },
188194
] as const
189195

196+
const maxLabelLen = Math.max(...categories.map((c) => c.label.length))
197+
190198
lines.push("╭───────────────────────────────────────────────────────────╮")
191199
lines.push("│ DCP Context Analysis │")
192200
lines.push("╰───────────────────────────────────────────────────────────╯")
@@ -199,7 +207,7 @@ function formatContextMessage(breakdown: TokenBreakdown): string {
199207
const bar = createBar(cat.value, breakdown.total, barWidth, cat.char)
200208
const percentage =
201209
breakdown.total > 0 ? ((cat.value / breakdown.total) * 100).toFixed(1) : "0.0"
202-
const labelWithPct = `${cat.label.padEnd(9)} ${percentage.padStart(5)}% `
210+
const labelWithPct = `${cat.label.padEnd(maxLabelLen)} ${percentage.padStart(5)}% `
203211
const valueStr = formatTokenCount(cat.value).padStart(13)
204212
lines.push(`${labelWithPct}${bar.padEnd(barWidth)}${valueStr}`)
205213
}

0 commit comments

Comments
 (0)