/**
 * codexUsageParser — line-wise, shape-validated token-usage extraction from
 * the `codex exec --json` event stream (token-audit-completeness spec).
 *
 * SECURITY / INJECTION POSTURE: usage parsing operates line-wise via
 * `JSON.parse` with TOP-LEVEL shape validation; substring/regex matching over
 * the raw stream is FORBIDDEN — model content embedded inside event string
 * fields is structurally incapable of matching a top-level parse. (The
 * key-substring pre-filter below only decides whether to ATTEMPT the parse —
 * it cannot extract values, so the injection rationale is untouched.)
 *
 * Two known event shapes, with an explicit precedence rule:
 *
 *  1. Protocol shape (AUTHORITATIVE when present):
 *       {"msg":{"type":"token_count","info":{"total_token_usage":{...}}}}
 *     (also matched under a `payload` key). CUMULATIVE — the last event wins
 *     within this shape. Verified against a real codex 0.136.0 rollout:
 *     `input_tokens` includes `cached_input_tokens`;
 *     `total_tokens = input_tokens + output_tokens`.
 *
 *  2. Thread-event shape (only when NO protocol event appeared):
 *       {"type":"turn.completed","usage":{...}}
 *     PER-TURN — summed across all `turn.completed` events.
 *
 * Never mixed in one accounting. When BOTH shapes appear in one stream, the
 * protocol total is recorded and a large divergence from the thread-event sum
 * emits the drift reason `shape-divergence` — a free consistency oracle
 * against partial-cadence drift (a CLI that keeps the shape but stops
 * emitting mid-stream).
 *
 * Token fields are clamped to non-negative finite integers; a protocol sample
 * whose `total_tokens` reconciliation fails is DROPPED, not recorded — and the
 * drop counts as zero-usage for the drift tripwire (`reconciliation-failed`),
 * so systematic reconciliation failure cannot recreate silent token-blindness.
 *
 * Mapping: tokensIn = input_tokens; tokensOut = output_tokens +
 * (reasoning_output_tokens iff total_tokens reconciliation shows they are
 * additive); tokensCached = cached_input_tokens (a subset of tokensIn).
 */
export interface CodexUsageSample {
    inputTokens: number;
    outputTokens: number;
    cachedTokens: number;
}
export type CodexUsageDriftReason = 'no-events' | 'empty-stream' | 'reconciliation-failed' | 'shape-divergence' | 'oversized-lines-discarded';
export interface CodexUsageFinalizeResult {
    /** Final recorded usage, or null when none survived validation. */
    usage: CodexUsageSample | null;
    /**
     * Drift reasons for the tripwire. Zero-usage reasons (no-events /
     * empty-stream / reconciliation-failed) only apply on a successful exit;
     * consistency reasons (shape-divergence / oversized-lines-discarded) are
     * reported whenever observed on a successful exit.
     */
    driftReasons: CodexUsageDriftReason[];
}
/**
 * Accumulates usage events from COMPLETE lines of a `codex exec --json`
 * stream. Line assembly (chunk boundaries, the carry-buffer cap) is the spawn
 * helper's job — this class assumes whole lines.
 */
export declare class CodexUsageAccumulator {
    private lastProtocol;
    private threadSum;
    private sawAnyLine;
    private oversizedDiscards;
    /** Feed one complete line from the event stream. Malformed lines are skipped. */
    feedLine(line: string): void;
    /**
     * Record that the spawn helper discarded an over-cap line unparsed. Usage
     * events are <1 KB so the cap cannot lose usage, but the discard is
     * surfaced to the drift tripwire.
     */
    noteOversizedDiscard(): void;
    /**
     * Finalize accounting. `success` = the call exited 0 (drift reasons are
     * only reported for successful calls — a failed call legitimately lacks
     * usage and is visible as an error row instead).
     */
    finalize(opts: {
        success: boolean;
    }): CodexUsageFinalizeResult;
}
//# sourceMappingURL=codexUsageParser.d.ts.map