/** * src/engine/ledger.ts — hash-only, body-free delegation ledger (node/fs). * * Ported/adapted from the ZOB harness `tools-delegation/helpers.ts` ledger * helpers: `DELEGATION_LEDGER_RAW_KEYS`, `bodyFreeDelegationLedgerEntry`, * `appendLedgerFile`, `delegationLedgerMeta`. The ledger is I1 hash-only: * every persisted entry has `bodyStored:false` and replaces raw-body keys * (`body|prompt|task|output|stderr|error|errorMessage|errors|gateErrors`) * with `Hashes` (sha-256) + `Count`. * * The ledger dir is injectable (default `/.pi/logs/runs`), so tests * write to a temp dir and never touch the real `.pi/logs/runs`. * * Zero @earendil-works/* imports; uses only node:fs and node:path. */ import type { DelegationRunMode, DelegationRunSource } from "./runs.js"; /** Raw-body keys that must never be persisted to a ledger entry. */ export declare const DELEGATION_LEDGER_RAW_KEYS: Set; /** * Recursively strip raw-body keys from an entry, replacing each STRING (or * string-array) body with `Hashes` (sha-256 of each string body) + * `Count`. Non-string scalars under a body-like key (numbers/booleans, * e.g. the `usage.output` token counter) are NOT bodies — they persist * as-is so ledger `end` usage totals stay honest (P3). Always appends * `bodyStored:false`, `promptBodiesStored:false`, `outputBodiesStored:false`. * Never mutates the input. */ export declare function bodyFreeDelegationLedgerEntry(entry: Record): Record; export interface AppendLedgerOptions { /** Override the ledger directory (default `/.pi/logs/runs`). */ dir?: string; /** Inject a clock for deterministic test file names / timestamps. */ now?: () => Date; } /** * Append one body-free ledger entry as a JSONL line to * `/.jsonl` (day = UTC YYYY-MM-DD). The dir is injectable via * `options.dir`; the default is `/.pi/logs/runs`. The persisted * line is `{...bodyFree(entry), timestamp: ISO}`. */ export declare function appendLedgerFile(repoRoot: string, entry: Record, options?: AppendLedgerOptions): void; /** Metadata prefix identifying a delegation ledger entry's source and mode. */ export declare function delegationLedgerMeta(source: DelegationRunSource, parentToolCallId: string | undefined, delegationMode: DelegationRunMode, index?: number): Record; /** * True when a ledger entry still contains a raw-body VALUE (string or array) * under a body-like key. Numeric/boolean scalars (counters such as * usage.output) are not bodies and do not flip this (P3). */ export declare function hasRawBodyKey(value: Record): boolean;