/** * @file Pure parsers for per-agent token/cost usage embedded in a spawn's * output. `spawnAiAgent` (`spawn.mts`) returns raw `stdout`/`stderr` today — * no usage figures — so a caller that wants to track spend has nothing to * read. Claude, Codex, and OpenCode each surface usage differently (an * inline JSON usage object, a text footer, or nothing at all when the * account/mode does not report it), so `parseAgentCost` matches the GIST of * each shape with tolerant regexes rather than an exact sentence — * mirroring how `spawn.mts` detects its overload/unavailable/quota signal * phrases instead of pattern-matching one literal string. Every field is * `undefined` when unparseable: a caller must never see a guessed number, * only a real one or an honest gap. */ import type { AiAgentName } from './types.js'; /** * Parsed usage for one spawn. Every field is independently `undefined` when * that figure could not be found — a partial parse (tokens but no cost, or * vice versa) is expected and not an error. */ export interface AgentCost { readonly costUsd: number | undefined; readonly inputTokens: number | undefined; readonly outputTokens: number | undefined; readonly totalTokens: number | undefined; } /** * Extract token/cost usage from a spawn's `stdout` + `stderr`. `agent` is * accepted for a future per-CLI specialization (Codex and OpenCode may grow a * distinct machine-readable usage format), but today every agent runs through * the same tolerant JSON-then-text fallback chain: the GIST (a labeled number * near "tokens" / "cost", or an inline usage object) repeats across Claude, * Codex, and OpenCode alike. `totalTokens` is derived from `inputTokens` + * `outputTokens` when both are known and no explicit total was found. Never * throws; output with no usage signal at all returns every field * `undefined`. */ export declare function parseAgentCost(agent: AiAgentName, stdout: string, stderr: string): AgentCost; /** * Parse a captured numeric group, stripping thousands separators. Returns * `undefined` for a missing capture or a non-finite result rather than * guessing — the contract every `AgentCost` field relies on. */ export declare function parseNumber(raw: string | undefined): number | undefined; export declare function parseTotalAgentTokens(text: string, inputTokens: number | undefined, outputTokens: number | undefined): number | undefined;