/** * Semantic hashing engine — pure algorithms, zero I/O. * * Ported from the Jups.tr notebook diff UI: the "golden logic" of * shingling + MinHash + Jaccard + DP alignment + surgical token diff, * hardened for server-side use with deterministic seeds. * * Design decisions: * • Deterministic PRNG for MinHash permutations — same seed always * produces the same signature, safe for cross-cycle cache comparison. * • Section-aware chunking so markdown files get per-heading signatures. * • Surgical token diff only fires on *modified* pairs (never on * unchanged or added/deleted) to keep cost proportional to change. */ export interface DiffOp { /** -1 = deletion, 0 = equal, 1 = insertion */ type: -1 | 0 | 1; text: string; } export interface MarkdownSection { heading: string; /** 0-based inclusive */ lineStart: number; /** 0-based inclusive */ lineEnd: number; content: string; } export interface AlignedPair { type: "MATCH" | "MODIFIED" | "INSERT" | "DELETE"; left: MarkdownSection | null; right: MarkdownSection | null; similarity: number; } /** * Character k-shingles for approximate set similarity. * Normalises whitespace so formatting changes don't dominate. */ export declare function getShingles(text: string, k?: number): Set; export declare function calculateJaccard(setA: Set, setB: Set): number; export declare class MinHash { readonly numPermutations: number; private readonly prime; private readonly maxHash; private readonly permuteFuncs; /** * @param numPermutations Hash function count (default 128) * @param seed Deterministic seed — MUST be constant across runs * for cached signatures to remain comparable. */ constructor(numPermutations?: number, seed?: number); /** djb2 string → uint32 */ private hashString; /** Compute a MinHash signature for a set of shingles. */ computeSignature(shingles: Set): number[]; /** Estimate Jaccard similarity from two signatures. */ estimateSimilarity(sigA: number[], sigB: number[]): number; } /** * Split a markdown document into sections at heading boundaries. * A section runs from one heading to the next (or EOF). * Content before the first heading is labelled "(preamble)". */ export declare function splitMarkdownSections(text: string): MarkdownSection[]; /** * Align two ordered sequences of sections using similarity-based DP. * Uses MinHash estimated similarity with a configurable threshold * (default 0.4 for sections which are more granular than whole files). * * Returns an ordered list of aligned pairs. */ export declare function alignSections(leftSections: MarkdownSection[], rightSections: MarkdownSection[], mh: MinHash, similarityThreshold?: number, shingleSize?: number): AlignedPair[]; /** * Tokenize preserving whitespace and punctuation boundaries, * then LCS-align tokens for a precise word-level diff. * Only call on MODIFIED pairs — unnecessary for MATCH/INSERT/DELETE. */ export declare function surgicalTokenDiff(text1: string, text2: string): DiffOp[]; /** * Render a DiffOp[] into a compact text summary suitable for agent * consumption: lines prefixed with ` `, `+`, `-`. */ export declare function renderDiffSummary(ops: DiffOp[]): string; //# sourceMappingURL=semantic-hash.d.ts.map