Skip to content

Commit a5b760b

Browse files
committed
feat: improve /dcp context UI with pruned count and accurate bars
- Add pruned tools count, tokens, and savings % to Summary section - Change bar chart to show actual percentage of total context - Bars now accurately represent each category's share of context
1 parent e49d9eb commit a5b760b

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

lib/commands/context.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ interface TokenBreakdown {
2626
assistant: number
2727
reasoning: number
2828
tools: number
29-
pruned: number
29+
prunedTokens: number
30+
prunedCount: number
3031
total: number
3132
}
3233

@@ -37,7 +38,8 @@ function analyzeTokens(state: SessionState, messages: WithParts[]): TokenBreakdo
3738
assistant: 0,
3839
reasoning: 0,
3940
tools: 0,
40-
pruned: state.stats.totalPruneTokens,
41+
prunedTokens: state.stats.totalPruneTokens,
42+
prunedCount: state.prune.toolIds.length,
4143
total: 0,
4244
}
4345

@@ -141,7 +143,7 @@ function analyzeTokens(state: SessionState, messages: WithParts[]): TokenBreakdo
141143
}
142144
}
143145

144-
breakdown.tools = Math.max(0, breakdown.tools - breakdown.pruned)
146+
breakdown.tools = Math.max(0, breakdown.tools - breakdown.prunedTokens)
145147

146148
// Calculate reasoning as the difference between API total and our counted parts
147149
// This handles both interleaved thinking and non-interleaved models correctly
@@ -164,15 +166,6 @@ function formatContextMessage(breakdown: TokenBreakdown): string {
164166
const lines: string[] = []
165167
const barWidth = 30
166168

167-
const values = [
168-
breakdown.system,
169-
breakdown.user,
170-
breakdown.assistant,
171-
breakdown.reasoning,
172-
breakdown.tools,
173-
]
174-
const maxValue = Math.max(...values)
175-
176169
const categories = [
177170
{ label: "System", value: breakdown.system, char: "█" },
178171
{ label: "User", value: breakdown.user, char: "▓" },
@@ -190,7 +183,7 @@ function formatContextMessage(breakdown: TokenBreakdown): string {
190183
lines.push("")
191184

192185
for (const cat of categories) {
193-
const bar = createBar(cat.value, maxValue, barWidth, cat.char)
186+
const bar = createBar(cat.value, breakdown.total, barWidth, cat.char)
194187
const percentage =
195188
breakdown.total > 0 ? ((cat.value / breakdown.total) * 100).toFixed(1) : "0.0"
196189
const labelWithPct = `${cat.label.padEnd(9)} ${percentage.padStart(5)}% `
@@ -204,12 +197,13 @@ function formatContextMessage(breakdown: TokenBreakdown): string {
204197

205198
lines.push("Summary:")
206199

207-
if (breakdown.pruned > 0) {
208-
const withoutPruning = breakdown.total + breakdown.pruned
209-
const savingsPercent = ((breakdown.pruned / withoutPruning) * 100).toFixed(1)
200+
if (breakdown.prunedTokens > 0) {
201+
const withoutPruning = breakdown.total + breakdown.prunedTokens
202+
const savingsPercent = ((breakdown.prunedTokens / withoutPruning) * 100).toFixed(1)
210203
lines.push(
211-
` Current context: ~${formatTokenCount(breakdown.total)} (${savingsPercent}% saved)`,
204+
` Pruned: ${breakdown.prunedCount} tools (~${formatTokenCount(breakdown.prunedTokens)}, ${savingsPercent}% saved)`,
212205
)
206+
lines.push(` Current context: ~${formatTokenCount(breakdown.total)}`)
213207
lines.push(` Without DCP: ~${formatTokenCount(withoutPruning)}`)
214208
} else {
215209
lines.push(` Current context: ~${formatTokenCount(breakdown.total)}`)

0 commit comments

Comments
 (0)