feat(tui,dashboard,docs): add context command parity and context health panel
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user