/** * Agent-cost visibility ledger (spec §21; fable_handoff B10 "telemetry * usage-count sourcing", the long-open metering-ledger design task). * * Scope is deliberately VISIBILITY ONLY: `es agents run` executes on the * customer's own model API key (D-4 customer-CI), so the model vendor bills * them directly and nothing here feeds our billing. Charter AD-9 and the D-5 * pricing recommendation both forbid usage-based billing — this ledger * answers "what did governance cost us, per repo/agent", nothing more. * * The agent command is vendor-neutral, so usage capture is best-effort with * two supported shapes (first match wins): * 1. An `ES_AGENT_USAGE: {...json...}` line anywhere in the agent's stdout * — the documented vendor-neutral contract any wrapper can emit. * 2. Claude Code CLI `--output-format json` output (total_cost_usd + * usage.input_tokens/output_tokens). * Anything else records source 'none' (an unmetered run is still a run — * duration and outcome always land in the ledger). */ export interface AgentUsage { input_tokens: number | null; output_tokens: number | null; total_cost_usd: number | null; model: string | null; source: 'es-usage-line' | 'agent-json' | 'none'; } export interface AgentCostRecord { recorded_at: string; repository: string | null; base: string; head_sha: string; agent_id: string; domain: string; outcome: 'produced' | 'failed'; duration_ms: number | null; usage: AgentUsage; } export declare const NO_USAGE: AgentUsage; export declare function agentCostLedgerPath(cwd: string): string; /** * Best-effort usage extraction from agent stdout. Untrusted input: every * parse failure degrades to NO_USAGE, never throws, and values are bounded * to finite non-negatives. */ export declare function extractAgentUsage(stdout: string): AgentUsage; /** Append records to the local ledger. Best-effort: a ledger write must * never fail an agents run, so errors are reported, not thrown. */ export declare function appendAgentCosts(cwd: string, records: readonly AgentCostRecord[]): boolean; /** Read the ledger, skipping unparseable lines (fail-soft — a corrupt line * must not hide the rest of the history). */ export declare function readAgentCosts(cwd: string): AgentCostRecord[]; export interface AgentCostSummaryRow { agent_id: string; runs: number; produced: number; failed: number; input_tokens: number; output_tokens: number; cost_usd: number; /** Runs whose agent command reported no usage — cost above is a floor. */ unmetered_runs: number; } export interface AgentCostSummary { rows: AgentCostSummaryRow[]; totals: Omit; first_recorded_at: string | null; last_recorded_at: string | null; } /** Pure aggregation. Unmetered runs count toward runs but not tokens/cost — * summaries state the floor honestly rather than inventing numbers. */ export declare function summarizeAgentCosts(records: readonly AgentCostRecord[], options?: { sinceIso?: string; }): AgentCostSummary; //# sourceMappingURL=agent-costs.d.ts.map