/** * Measurements: time and tokens, per subagent. * * Nothing is estimated. Tokens and cost come from pi, read by the session * (`src/session.ts`); the only things we add are **time** - which pi does not * measure - and **attribution per subagent**. */ /** Measurements of a subagent, or of a single turn of work. */ export type Usage = { /** From spawn to close, waiting included. Monotonic clock. */ wallMs: number; /** Time actually spent working: the sum of the `ask` calls. */ busyMs: number; /** Completed `ask` calls. A turn is one prompt to the session, however many tools it ran. */ turns: number; /** * Tool calls the model made, as pi counts them in the transcript: every one * it asked for, refused or not. Never read from what the model wrote. */ toolCalls: number; /** Input tokens, as pi reported them. `0` when the provider does not say. */ input: number; /** Output tokens, as pi reported them. Never estimated from characters. */ output: number; /** Tokens served from the prompt cache. */ cacheRead: number; /** Tokens written to the prompt cache. */ cacheWrite: number; /** What pi says it cost, in the provider's currency. Summed, never recomputed. */ cost: number; /** Current context size. Mostly relevant for a persistent agent. */ contextTokens?: number; }; /** A zeroed `Usage`. The starting point of a freshly spawned subagent. */ export declare function emptyUsage(): Usage; /** * Usage of one turn: what `after` has more than `before`, two readings of a * session's cumulative counters. * * Counters are clamped at `0` - a compacted session can see its totals go * backwards, and a negative usage means nothing. `contextTokens` is not a * cumulative counter but a level, so we take the one from `after`. */ export declare function deltaUsage(before: Usage, after: Usage): Usage; /** * A subagent's usage after one more turn. * * Counters and busy time add up; `wallMs` is the subagent's own clock and is * left as it stands; `contextTokens` is a level rather than a counter, so the * turn's reading replaces the last one - a turn that reports none leaves the * last known level in place. This is the one rule {@link sumUsage} does not * have, because a context belongs to one session and a fan-out sums several. */ export declare function accumulate(total: Usage, turn: Usage): Usage; /** * Aggregates the usage of several subagents - typically a fan-out. * * We **sum**, we never average. And `wallMs` is passed separately rather than * summed: it is the real duration of the whole, not the total of the branches. * The `busyMs / wallMs` ratio then gives the parallelism actually achieved - * which is precisely the number we want to read. * * `contextTokens` is not aggregated: adding up the contexts of distinct * sessions describes nothing. */ export declare function sumUsage(parts: readonly Usage[], wallMs: number): Usage; /** What every display says of a turn that called no tool its agent had to call. */ export declare const CALLED_NO_TOOL = "called no tool"; /** * Compact usage line: `3 turns 12.4s ↑12k ↓2.1k R8k $0.0412 ctx:34k`. The * tokens wait for a turn to end and the cost for pi to report one, as in * {@link showTokens} and {@link showCost}. */ export declare function formatUsage(usage: Usage): string; /** * `↑12k ↓2.1k` once a turn has ended, and nothing before. pi's counters are * read when a turn ends, so a subagent in its first turn has no figure yet, * and a `0` there would be one nobody measured. After a turn, a provider that * reports nothing reads `↑0 ↓0`: that zero was read. */ export declare function showTokens(usage: Usage): string[]; /** * `$0.0412` when pi reported a cost, and nothing when it did not: several * providers report none, and `$0.0000` would read as free. */ export declare function showCost(usage: Usage): string[]; /** `12k`, `2.1k`, `1.4M` - a token count that fits in a narrow column. */ export declare function compact(n: number): string; //# sourceMappingURL=usage.d.ts.map