Skip to content

Commit d476e03

Browse files
authored
Merge pull request #291 from Opencode-DCP/feature/context-ui-improvements
feat: improve /dcp context UI with pruned count and accurate bars
2 parents e49d9eb + 0dc8da5 commit d476e03

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

lib/commands/context.ts

Lines changed: 10 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,12 @@ 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
210202
lines.push(
211-
` Current context: ~${formatTokenCount(breakdown.total)} (${savingsPercent}% saved)`,
203+
` Pruned: ${breakdown.prunedCount} tools (~${formatTokenCount(breakdown.prunedTokens)})`,
212204
)
205+
lines.push(` Current context: ~${formatTokenCount(breakdown.total)}`)
213206
lines.push(` Without DCP: ~${formatTokenCount(withoutPruning)}`)
214207
} else {
215208
lines.push(` Current context: ~${formatTokenCount(breakdown.total)}`)

0 commit comments

Comments
 (0)