/** * Context continuity: durable, structured state around native adapter * compaction. Harnery does not decide when a adapter compacts. It records * context telemetry when the adapter exposes it, checkpoints external work * state before compaction, and renders a verified recovery briefing after it. */ import type { Adapter } from "../adapter.js"; export declare const CONTEXT_SCHEMA_VERSION: 1; export declare const MAX_CAPSULE_BYTES: number; export type ContextSampleSource = "hook" | "native_event" | "result" | "transcript" | "estimate"; export type ContextSampleConfidence = "exact" | "reported" | "estimated"; export type ContextPhase = "observing" | "checkpointed" | "recovered" | "degraded"; export type CheckpointReason = "manual" | "pressure" | "pre_compact" | "session_end"; export interface ContextSample { session_id: string; adapter: Adapter; model?: string; used_tokens?: number; window_tokens?: number; used_percent?: number; source: ContextSampleSource; confidence: ContextSampleConfidence; observed_at: string; } export interface ContextContinuityState { schema_version: typeof CONTEXT_SCHEMA_VERSION; session_id: string; instance_id: string; phase: ContextPhase; generation: number; latest_capsule?: string; latest_context?: ContextSample; updated_at: string; recovered_at?: string; compaction_completed_at?: string; degraded_reason?: string; } export interface RepoSnapshot { cwd: string; root?: string; branch?: string; head?: string; dirty_paths: string[]; dirty_paths_truncated?: boolean; } export interface ContinuityCapsule { schema_version: typeof CONTEXT_SCHEMA_VERSION; capsule_id: string; generation: number; created_at: string; reason: CheckpointReason; session: { session_id: string; instance_id: string; adapter: Adapter; model?: string; }; context?: ContextSample; work: { task?: string; continuation_note?: string; files_held: string[]; files_held_truncated?: boolean; }; repo: RepoSnapshot; } export interface ExtractContextSampleOptions { sessionId: string; adapter: Adapter; model?: string; source?: ContextSampleSource; confidence?: ContextSampleConfidence; observedAt?: string; } export interface CheckpointContextInput { sessionId: string; instanceId: string; adapter: Adapter; cwd: string; reason: CheckpointReason; model?: string; continuationNote?: string; } export interface CheckpointContextResult { capsule: ContinuityCapsule; path: string; state: ContextContinuityState; reused: boolean; } export interface RecoverContextResult { state: ContextContinuityState; capsule: ContinuityCapsule | null; briefing: string; recovered: boolean; } export interface PreparedContextRecovery { state: ContextContinuityState; capsule: ContinuityCapsule; briefing: string; } /** Parse the context-window shapes exposed by current adapter hook/status data. */ export declare function extractContextSample(payload: Record, options: ExtractContextSampleOptions): ContextSample | null; /** Persist a latest context sample. Identical measurements are a no-op. */ export declare function recordContextSample(coordRoot: string, instanceId: string, sample: ContextSample): { state: ContextContinuityState; changed: boolean; }; /** * Snapshot external work state. Repeated PreCompact events reuse the existing * checkpoint until a matching recovery completes; manual checkpoints always * create a new generation. */ export declare function checkpointContext(coordRoot: string, input: CheckpointContextInput): CheckpointContextResult; /** Prepare a briefing without claiming that a adapter has accepted it yet. */ export declare function prepareContextRecovery(coordRoot: string, input: { sessionId: string; instanceId: string; cwd: string; }): PreparedContextRecovery | null; /** Advance continuity only after the adapter context channel accepted the briefing. */ export declare function completeContextRecovery(coordRoot: string, input: { sessionId: string; instanceId: string; }): ContextContinuityState; /** Record that the adapter, rather than Harnery, reported compaction complete. */ export declare function markContextCompactionCompleted(coordRoot: string, input: { sessionId: string; instanceId: string; observedAt?: string; }): ContextContinuityState; /** Convenience API for callers whose injection is synchronous and guaranteed. */ export declare function recoverContext(coordRoot: string, input: { sessionId: string; instanceId: string; cwd: string; }): RecoverContextResult; export declare function readContextState(coordRoot: string, sessionId: string): ContextContinuityState | null; export declare function readLatestCapsule(coordRoot: string, sessionId: string): ContinuityCapsule | null; export declare function renderRecoveryBriefing(capsule: ContinuityCapsule, liveRepo: RepoSnapshot): string; export declare function snapshotRepo(cwd: string): RepoSnapshot; //# sourceMappingURL=index.d.ts.map