Expand description
Counts what an agent’s calls used against the Kanban task they belong to, as they pass through transcript::append
(docs/specs/SPEC_TOKEN_ANALYSIS_PER_KANBAN_TASK_2026_11_22.md sections 4.1 to 4.4). srv counts: no agent
reports or adds up its own tokens.
One call is one deduplicated message id. Claude writes a call’s usage again on each of its content-block lines, and only the output grows: the first sight of a call counts it, a later line of it adds what grew. Each counted call is kept (id, where it was counted, what was counted) with the counters in one write, so a replay, a restart or an upgrade adds nothing twice, however far back it goes. The task and its stage are decided when the call is counted, never rebuilt later. Counts, ids, model names and times only: nothing of a line is kept.
Which task a call belongs to, in this order (basis of its row):
held, orsharedwhen the agent held several: the task it held at that time;named: the agent holds none, and the call issued aTasksaction naming one (only its number is read);spawned: a worker of a leader that holds one, until the worker takes one of its own;unattributed: none of these. Kept per agent and day with an empty task, never spread over tasks.
The counters are written in batches, about once a second, by one thread; a crash loses at most the batch not yet written, together with the ids of its calls.
Structs§
- Found
Call - A call a provider-specific reader found in the provider’s own file: its durable id and when it was made.
- Ledger
Traits§
- Directory
- What the ledger needs to know of the world besides the task store.
Functions§
- note_
found - Counts calls a provider-specific reader found (
FoundCall), for the agent whose transcript iszone. - note_
prompt - Takes in the records srv wrote for a prompt it delivered, for the cause of the call that answers it.
- note_
records - Counts the calls in
records(newline-terminated lines an agent wrote tozone). Called for every transcript write of the agent’s own output; a line that holds no usage costs a substring test.