export interface CompactHistoryEvent { readonly schemaVersion: 1; readonly ts: string; readonly target: 'main' | 'sub-agent' | 'worker'; /** * The profile the run used. `eager` is the canonical name of the * earlier-firing profile; `partial` is its legacy alias and is still * accepted so an old row keeps parsing; `aggressive` predates both. */ readonly mode: 'standard' | 'partial' | 'aggressive' | 'eager'; readonly ide: string; readonly pathway: string; readonly beforeRatio: number; readonly redLine: boolean; readonly ok: boolean; readonly checkpointPath: string; readonly dispatchMessage: string; /** * dispatch divided by. `beforeRatio * windowTokens` is the token point * peaks-loop asked the harness to compact at. */ readonly windowTokens?: number | null; /** Which layer produced `windowTokens` (env-override | harness-env | config | model-heuristic | default). */ readonly windowSource?: string | null; /** * `dispatch` — peaks-loop asked for a compact (every row written before * this slice is implicitly one of these). `observed` — a later probe * MEASURED the ratio after a dispatched compact, proving one landed. */ readonly kind?: 'dispatch' | 'observed'; /** `observed` rows only: the measured post-compact ratio. */ readonly afterRatio?: number; /** * compaction — `manual` (a user ran `/compact`) or `auto` (the harness's own * window fired). Written only by the `PostCompact` hook path, which is the * only path a harness reports it on. * * OPTIONAL, AND ABSENT MEANS "NOT REPORTED" — never "manual", never "auto". * `PostCompact`'s payload schema is truncated in the retrievable docs, so a * payload without the field is an expected input, not an error; the whole * reason this column exists is that "has this machine ever auto-compacted?" * has no answer today, and a defaulted value would answer it falsely. * Rows that predate the slice omit it, exactly like `windowTokens` / `kind`. */ readonly trigger?: 'manual' | 'auto'; } /** * One dispatch paired with the measurement that followed it — the * intent-vs-observed record for the harness auto-compact window. * * Why a pair and not a number: the slice that owns this instrument could not * run a real Claude Code session, and the harness's own documentation gives * the env var as a WINDOW, not a trigger point, so "a window of X makes the * harness fire at Y%" has no documented answer. Fabricating Y would be worse * than not having it. Recording the intent (`requested*`) next to whatever * the next real session actually measures (`observed*`) is the honest * substitute: after one real session the gap becomes a measured fact. */ export interface WindowCalibrationPair { readonly dispatchedAt: string; readonly windowTokens: number | null; readonly windowSource: string | null; /** The ratio at which peaks-loop asked. */ readonly requestedRatio: number; /** `requestedRatio * windowTokens` — token point asked for; null with no window. */ readonly requestedTokens: number | null; /** Measured ratio of the first `observed` row after this dispatch. */ readonly observedRatio: number | null; readonly observedTokens: number | null; /** * `observedTokens - requestedTokens`. Negative = the harness compacted * BEFORE the point peaks-loop asked for (which is the harness's own * trigger firing early). Null while unmeasured. */ readonly driftTokens: number | null; readonly measured: boolean; } export interface WindowCalibration { readonly pairs: ReadonlyArray; /** Dispatches with no following measurement yet. */ readonly unmeasured: number; /** The window in force on the most recent dispatch, for a one-line read. */ readonly lastWindowTokens: number | null; } /** * Pair each dispatched compact with the measurement that followed it. Pure; * tolerates a file written by an earlier release (no `windowTokens`, no * `kind`) — those rows produce a pair with a null window rather than an * error, because the history file is append-only and never rewritten. */ export declare function computeWindowCalibration(events: ReadonlyArray): WindowCalibration; export type CompactHistoryReadResult = { readonly kind: 'file-missing'; readonly path: string; } | { readonly kind: 'empty'; readonly path: string; } | { readonly kind: 'ok'; readonly path: string; readonly events: ReadonlyArray; readonly parseErrors: ReadonlyArray<{ readonly line: number; readonly raw: string; }>; }; export declare function readCompactHistory(input: { readonly projectRoot: string; readonly sessionId: string; }): CompactHistoryReadResult; export interface CompactHistorySummary { readonly totalCompacts: number; readonly lastTs: string | null; readonly lastBeforeRatio: number | null; readonly lastRedLine: boolean; readonly redLineCount: number; readonly failedCount: number; } export declare function summarizeCompactHistory(events: ReadonlyArray): CompactHistorySummary;