/** * Semantic cache — snapshot, persist, and diff agent-state documents * using MinHash signatures for approximate similarity. * * Flow: * 1. takeSnapshot() — hash + sign every tracked file, persist to .tmp/cache/ * 2. computeSemanticDelta() — compare two snapshots, emit per-file + per-section deltas * 3. checkDriftBudget() — gate: is the delta within acceptable bounds? * * Integration points: * • scan_workspace_delta (coarse gate) runs first, flags changed files * • semantic cache runs only on files flagged changed * • drift report feeds skeptic/ops via status events */ export interface MinHashParams { num_permutations: number; shingle_size: number; seed: number; } export interface FileSignature { content_hash: string; size: number; signature: number[]; sections: SectionSignature[]; } export interface SectionSignature { heading: string; line_start: number; line_end: number; content_hash: string; signature: number[]; } export interface SemanticSnapshot { version: 1; snapshot_id: string; timestamp: string; minhash_params: MinHashParams; tracked_dirs: string[]; file_count: number; total_size: number; files: Record; } export type FileChangeStatus = "unchanged" | "modified" | "added" | "deleted"; export interface SectionChange { heading: string; status: FileChangeStatus; similarity: number; diff_summary?: string; } export interface FileDelta { status: FileChangeStatus; file_similarity: number; size_before: number; size_after: number; growth_pct: number; section_changes: SectionChange[]; } export interface DriftBudgetConfig { max_growth_pct: number; max_churn_pct: number; max_new_files: number; max_deleted_files: number; } export interface DriftBudgetResult { passed: boolean; actual_growth_pct: number; actual_churn_pct: number; new_files: number; deleted_files: number; violations: string[]; } export interface SemanticDelta { version: 1; before_snapshot: string; after_snapshot: string; timestamp: string; summary: { unchanged_files: number; modified_files: number; added_files: number; deleted_files: number; total_section_changes: number; }; drift_budget?: DriftBudgetResult; files: Record; } export interface TakeSnapshotInput { snapshot_id: string; tracked_dirs?: string[]; shingle_size?: number; num_permutations?: number; seed?: number; /** Only snapshot these specific files (overrides tracked_dirs scan). */ files?: string[]; } /** * Snapshot current state of all tracked files into semantic cache. * Computes content hashes + MinHash signatures at file and section level. */ export declare function takeSnapshot(input: TakeSnapshotInput): SemanticSnapshot; export declare function loadSnapshot(snapshotId: string): SemanticSnapshot | undefined; export declare function listSnapshots(): string[]; export interface ComputeDeltaInput { before: string | SemanticSnapshot; after: string | SemanticSnapshot; /** Include surgical token diff for modified sections (more expensive). */ include_diffs?: boolean; /** Drift budget config. */ drift_budget?: DriftBudgetConfig; } /** * Compare two snapshots and produce a semantic delta. * For markdown files: section-level alignment via DP. * For all files: file-level MinHash similarity. */ export declare function computeSemanticDelta(input: ComputeDeltaInput): SemanticDelta; /** * Pre-cycle: take a "before" snapshot. * Returns the snapshot ID for use in post-cycle comparison. */ export declare function preCycleSnapshot(cycleId: string, trackedDirs?: string[]): SemanticSnapshot; /** * Post-cycle: take an "after" snapshot and compute the delta. */ export declare function postCycleSnapshot(cycleId: string, trackedDirs?: string[], driftBudget?: DriftBudgetConfig, includeDiffs?: boolean): { snapshot: SemanticSnapshot; delta: SemanticDelta; }; export interface RewriteTarget { file: string; type: "full" | "section"; /** For section targets: heading text for ast-grep/heading search. */ heading?: string; /** Line range (0-based) of the affected section. */ line_start?: number; line_end?: number; /** Similarity to old version. */ similarity: number; } /** * Extract rewrite targets from a semantic delta. * Returns only modified or added targets — nothing for unchanged/deleted. * For code files: full-file target (use ast-grep node targeting externally). * For markdown: section-level targets with heading/line ranges. */ export declare function extractRewriteTargets(delta: SemanticDelta): RewriteTarget[]; //# sourceMappingURL=semantic-cache.d.ts.map