feat(tui,dashboard,docs): add context command parity and context health panel

This commit is contained in:
William Valentin
2026-02-16 18:08:19 -08:00
parent 21d57d991c
commit 409ab04ca1
8 changed files with 146 additions and 4 deletions
+24
View File
@@ -12,6 +12,7 @@ import type { HookEngine, HookResult } from '../../../hooks/index.js';
import type { ModelConfig, ModelProvider } from '../../../config/schema.js';
import { MODEL_PROVIDERS } from '../../../config/schema.js';
import { createClientFromConfig } from '../../../daemon/index.js';
import { estimateMessageTokens, getContextWindow } from '../../../context/tokens.js';
/** Format a tool name like "gmail.list" -> "Gmail: List" */
function formatToolName(name: string): string {
@@ -239,6 +240,29 @@ export function App({
return;
}
case 'context': {
const history = session.getHistory();
const estimated = estimateMessageTokens(history);
const tier = modelRouter?.getTier() ?? 'default';
const modelName = modelRouter?.getLabel(tier) ?? model;
const window = getContextWindow(modelName);
const usagePct = window > 0 ? (estimated / window) * 100 : 0;
const thresholdPct = 80;
const thresholdTokens = Math.floor((thresholdPct / 100) * window);
const remaining = Math.max(0, window - estimated);
const text = [
'Context Usage (estimated)',
'',
`Model: ${modelName}`,
`Used: ${estimated.toLocaleString()} / ${window.toLocaleString()} tokens (${usagePct.toFixed(1)}%)`,
`Remaining: ${remaining.toLocaleString()} tokens`,
`Compaction threshold: ${thresholdPct}% (${thresholdTokens.toLocaleString()} tokens)`,
`Should compact: ${estimated > thresholdTokens ? 'yes' : 'no'}`,
].join('\n');
setMessages(prev => [...prev, session.addMessage({ role: 'assistant', content: text })]);
return;
}
case 'verbose': {
const next = !verbose;
setVerbose(next);