fix(status-line): derive remaining_percentage from used and reject empty commands

- Compute remaining_percentage as round(100 - used) to guarantee
  used + remaining always sums to exactly 100.0
- Reject empty or whitespace-only command strings in config validation
This commit is contained in:
wenshao 2026-04-08 18:58:06 +08:00
parent 0be4d32cb0
commit 55b1ab174d

View file

@ -81,7 +81,8 @@ function getStatusLineConfig(
'type' in raw &&
raw.type === 'command' &&
'command' in raw &&
typeof raw.command === 'string'
typeof raw.command === 'string' &&
raw.command.trim().length > 0
) {
const config: StatusLineConfig = {
type: 'command',
@ -247,18 +248,7 @@ export function useStatusLine(): {
context_window: {
context_window_size: contextWindowSize,
used_percentage: usedPercentage,
remaining_percentage:
contextWindowSize > 0
? Math.min(
100,
Math.max(
0,
Math.round(
(1 - stats.lastPromptTokenCount / contextWindowSize) * 1000,
) / 10,
),
)
: 100,
remaining_percentage: Math.round((100 - usedPercentage) * 10) / 10,
current_usage: stats.lastPromptTokenCount,
total_input_tokens: totalInputTokens,
total_output_tokens: totalOutputTokens,