From 55b1ab174dac755f5687d130151131938e6c08a4 Mon Sep 17 00:00:00 2001 From: wenshao Date: Wed, 8 Apr 2026 18:58:06 +0800 Subject: [PATCH] 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 --- packages/cli/src/ui/hooks/useStatusLine.ts | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/packages/cli/src/ui/hooks/useStatusLine.ts b/packages/cli/src/ui/hooks/useStatusLine.ts index 06a4d038d..6bf64997b 100644 --- a/packages/cli/src/ui/hooks/useStatusLine.ts +++ b/packages/cli/src/ui/hooks/useStatusLine.ts @@ -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,