/** Contracts-core compaction family (0.2.5 plan 025 Task 1 split). * Moved verbatim from contracts-core.ts; public surface unchanged behind the barrel. */ import type { ErrorInfo } from "./content.js"; import type { SessionEntry } from "./session.js"; export interface CompactionStrategy { readonly name: string; compact(context: CompactionContext): Promise | CompactionResult; readonly metadata?: Readonly>; } export interface CompactionContext { readonly sessionId: string; readonly entries: readonly SessionEntry[]; readonly keepRecentEntries?: number; readonly trigger?: "manual" | "auto" | string; readonly secrets?: readonly (string | undefined)[]; readonly metadata?: Readonly>; readonly signal?: AbortSignal; } export interface CompactionResult { readonly summary: string; readonly entries?: readonly SessionEntry[]; readonly metadata?: Readonly>; } /** Inputs a compaction trigger decides on. Estimates and ids only — never raw payloads. */ export interface CompactionTriggerContext { readonly sessionId: string; readonly entryCount: number; readonly estimatedInputTokens: number; readonly inputCapTokens: number; readonly metadata?: Readonly>; readonly signal?: AbortSignal; } /** Host-programmable compact-when gate (plan 074 C11). Omitted → `thresholdEntries` only. */ export type CompactionTrigger = { readonly type: "threshold_entries"; readonly entries: number; } | { readonly type: "input_ratio"; readonly ratio: number; } | { readonly type: "custom"; readonly shouldCompact: (context: CompactionTriggerContext) => boolean | Promise; }; /** Validate a host trigger at config time, so an unknown `type` fails at create (C11). */ export declare function assertCompactionTrigger(trigger: CompactionTrigger): CompactionTrigger; export interface CompactionOptions { readonly strategy?: CompactionStrategy; readonly thresholdEntries?: number; /** Replaces the `thresholdEntries` gate when set; omitted keeps today's entry-count gate. */ readonly trigger?: CompactionTrigger; readonly keepRecentEntries?: number; readonly maxSummaryChars?: number; readonly secrets?: readonly (string | undefined)[]; readonly metadata?: Readonly>; readonly signal?: AbortSignal; } /** Legacy gates a compaction decision can fall back to when no `trigger` is configured. */ export interface ResolveShouldCompactOptions { /** Host trigger; when set it replaces the legacy gates below. */ readonly trigger?: CompactionTrigger; /** Session gate: compact when the branch holds more than this many entries. */ readonly thresholdEntries?: number; /** Attach-loop gate: compact when the estimated input is at or above this many tokens. */ readonly compactAfterTokens?: number; } /** Everything a compaction decision reads. Estimates only — never raw payloads. */ export interface ResolveShouldCompactInput { readonly sessionId: string; readonly entryCount: number; /** Estimated tokens of the would-be input; called at most once, and only when a ratio or custom trigger reads it. */ readonly estimateInputTokens: () => number; /** Resolved input cap (the attention compiler's `resolveInputCap`); called at most once, and only when a ratio or custom trigger reads it. */ readonly resolveInputCapTokens: () => number; readonly metadata?: Readonly>; readonly signal?: AbortSignal; /** Receives the failure behind a fail-closed `false`. */ readonly onError?: (error: unknown) => void; } /** * The single compact-when decision used by `autoCompact` and by host attach loops that gate their * own post-run compaction (plan 074 C11). * * Precedence: an explicit `trigger` replaces the legacy gates. Only the token gates below a `trigger` * replace are lazy — a `threshold_entries` trigger, or a `custom` callback that only reads counts, * never pays for the token estimate or the input cap. * * Failure policy: a malformed trigger throws (`assertCompactionTrigger`, config error), while a * throwing `custom.shouldCompact` — including a callback that reads an unresolvable cap — decides * `false` and reports through `onError`, so a host bug can never compact on a guess. */ export declare function resolveShouldCompact(options: ResolveShouldCompactOptions, input: ResolveShouldCompactInput): Promise; export interface CompactionMiddlewarePayload { readonly context: CompactionContext; readonly result: CompactionResult; } export interface CompactionEntryData { readonly throughEntryId?: string; readonly keepEntryIds?: readonly string[]; readonly strategy?: string; readonly trigger?: "manual" | "auto" | string; } export interface RetryPolicy { readonly name: string; decide(context: RetryContext): Promise | RetryDecision; readonly metadata?: Readonly>; } export interface RetryContext { readonly sessionId: string; readonly runId: string; readonly attempt: number; readonly error: ErrorInfo; readonly metadata?: Readonly>; readonly signal?: AbortSignal; } export interface RetryDecision { readonly retry: boolean; readonly delayMs?: number; readonly metadata?: Readonly>; } export interface RetryOptions { readonly policy?: RetryPolicy; readonly maxAttempts?: number; readonly baseDelayMs?: number; readonly maxDelayMs?: number; readonly secrets?: readonly (string | undefined)[]; readonly metadata?: Readonly>; } export interface RetryMiddlewarePayload { readonly context: RetryContext; readonly decision: RetryDecision; }