mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 01:01:42 +00:00
feat(agent): Add /tokens command for cumulative token usage tracking
Added /tokens slash command to TUI that displays session-wide token statistics. Key changes: - Fixed SessionManager to accumulate token usage instead of storing only last event - Added cumulative token tracking to TUI renderer alongside per-request totals - Implemented slash command infrastructure with /tokens autocomplete support - Fixed file autocompletion that was missing from Tab key handling - Clean minimal display format showing input/output/reasoning/cache/tool counts The /tokens command shows: Total usage input: 1,234 output: 567 reasoning: 89 cache read: 100 cache write: 50 tool calls: 2
This commit is contained in:
parent
7e3b94ade6
commit
e21a46e68f
10 changed files with 303 additions and 283 deletions
|
|
@ -156,7 +156,17 @@ export class SessionManager implements AgentEventReceiver {
|
|||
const eventEntry: SessionEvent = entry as SessionEvent;
|
||||
events.push(eventEntry);
|
||||
if (eventEntry.event.type === "token_usage") {
|
||||
totalUsage = entry.event as Extract<AgentEvent, { type: "token_usage" }>;
|
||||
const usage = entry.event as Extract<AgentEvent, { type: "token_usage" }>;
|
||||
if (!totalUsage) {
|
||||
totalUsage = { ...usage };
|
||||
} else {
|
||||
totalUsage.inputTokens += usage.inputTokens;
|
||||
totalUsage.outputTokens += usage.outputTokens;
|
||||
totalUsage.totalTokens += usage.totalTokens;
|
||||
totalUsage.cacheReadTokens += usage.cacheReadTokens;
|
||||
totalUsage.cacheWriteTokens += usage.cacheWriteTokens;
|
||||
totalUsage.reasoningTokens += usage.reasoningTokens;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue