/** * Trust-calibrated context economy — re-read measurement (item 4 of * `add-trust-calibrated-context-economy`). * * Pure, deterministic extraction of the "re-read economy" signals from a headless * agent transcript (`claude -p --output-format stream-json`), so the bench harness * (`scripts/bench-agent.ts`) can report — honestly, per repo tier — how much * re-derivation openlore actually removes: * * - `fileReadOps` — how many times the agent re-read source (Read/Grep/cat/…) * to derive a fact. The thing a grounding certificate lets * it skip. WITHOUT − WITH = re-reads avoided. * - `fileReadTokens` — the tokens those reads loaded into the model (≈ len/4). * WITHOUT − WITH = the token delta the lever is responsible * for — the rent openlore is supposed to subtract. * - `certifiedFacts` — `verifiedCurrent: true` facts openlore handed the agent * (the "permission to not re-read" markers). WITH-arm only. * * Lives in `src/` (not `scripts/`) purely so CI's `vitest run src` covers it; the * benchmark is the only consumer. No product code depends on it. */ /** A normalized agent tool invocation (transport-shape stripped). */ export interface NormToolUse { id: string; name: string; input: Record; } /** A normalized tool result, flattened to plain text. */ export interface NormToolResult { toolUseId: string; text: string; } export interface AgentTranscript { toolUses: NormToolUse[]; toolResults: NormToolResult[]; } /** The terminal result event — mirrors the legacy single-object `--output-format json`. */ export interface AgentResultEnvelope { freshInputTokens: number; cacheReadTokens: number; outputTokens: number; costUsd: number; numTurns: number; durationMs: number; answer: string; } export interface RereadMetrics { fileReadOps: number; fileReadTokens: number; certifiedFacts: number; } /** ~bytes/4 token heuristic — the same approximation the tool-surface figures use. */ export declare function estimateTokens(text: string): number; /** * Classify a tool invocation for the re-read economy. * - `source-read`: the agent reads/searches source to derive a fact (Read, Grep, or * a shell read like cat/sed/head/tail/less/grep/rg/awk) — what a certificate replaces. * - `openlore`: an openlore MCP tool (its conclusions are what the agent reads instead). * - `other`: writes, task tools, etc. — irrelevant to the re-read lever. * * The Bash classifier is a deliberate heuristic, not a shell parser. It catches a reader * at line start (incl. indented / multi-line commands via the `m` flag) or after a * pipe/and/semicolon/`do`/`xargs`, tolerating an env-var-assignment or `sudo` prefix. * Two residual biases are accepted and roughly offset: (a) a reader fed by a pipe * (`npm build | grep err`) consumes the prior command's stdout, not source, yet counts as * a source-read (over-count); (b) `Read`/`Grep` are classified by tool name alone — the * `file_path` is not inspected, so reading a non-source file (e.g. a `.md` or an openlore * artifact) also counts. Both are small relative to the per-task read volume; the metric * is a directional measurement, not an exact accounting. */ export declare function classifyToolUse(name: string, input: Record): 'source-read' | 'openlore' | 'other'; /** Count `verifiedCurrent: true` markers in an openlore result payload (regex-robust to shape). */ export declare function countVerifiedCurrent(text: string): number; /** * Parse the agent's stdout into a normalized transcript + terminal result. Accepts * BOTH `--output-format stream-json` (newline-delimited events) and the legacy * single-object `--output-format json` (result only, no transcript) — so switching * the harness to stream-json is robust and the result/usage extraction is unchanged. * Malformed lines are skipped; nothing throws. */ export declare function parseAgentOutput(raw: string): { transcript: AgentTranscript; result?: AgentResultEnvelope; }; /** * Compute the re-read economy from a normalized transcript. Deterministic: counts * source-read tool uses, sums the tokens their results loaded, and counts the * verified-current certificates openlore returned. */ export declare function analyzeAgentTranscript(t: AgentTranscript): RereadMetrics; //# sourceMappingURL=transcript-metrics.d.ts.map