/** * Line Tracing Module v3 * * Context-aware line tracing algorithm for attributing lines in committed code * to their original AI session. Walks backwards through snapshot chain to find * where each line was introduced. * * Key features: * - Context-aware matching (uses prev/next lines to disambiguate) * - Handles common collisions like `}`, `{`, empty lines * - Similarity-based fallback for fuzzy context matching */ import type { Snapshot, LineOrigin, LineContext } from "./types"; /** * Normalize line endings (CRLF -> LF) and split into lines */ export declare function splitLines(content: string): string[]; /** * Pre-built index for fast line lookups * Maps line content -> array of indices where that content appears */ type LineIndex = Map; /** * Trace a line's origin through the snapshot chain * Returns the session that introduced the line, or null if it existed before AI edits * * @param repoRoot - Repository root path * @param lineContent - The line content to trace * @param context - Surrounding lines for disambiguation * @param chain - Snapshot chain (oldest first) */ export declare function traceLineOrigin(repoRoot: string, lineContent: string, context: LineContext, chain: Snapshot[]): Promise; /** * Batch trace multiple lines from the same file * Uses pre-built indexes for O(1) line lookups instead of O(n) scans */ export declare function traceFileLines(repoRoot: string, lines: string[], chain: Snapshot[]): Promise; interface LineMatch { index: number; confidence: number; } /** * Find a line in the snapshot using context for disambiguation * Uses pre-built indexes for O(1) lookups */ export declare function findLineWithContextIndexed(target: string, context: LineContext, lines: string[], exactIndex: LineIndex, normalizedIndex: LineIndex): LineMatch | null; /** * Find a line in the snapshot using context for disambiguation * Legacy version without index (for single-use cases) */ export declare function findLineWithContext(target: string, context: LineContext, lines: string[]): LineMatch | null; /** * Compute similarity between two strings (0-1) * Uses a combination of normalized edit distance and token overlap */ export declare function similarity(a: string, b: string): number; /** * Aggregate line-level attributions into ranges */ export declare function aggregateToRanges(attributions: Array<{ line: number; sessionId: string | null; promptId?: number | null; }>): Array<{ startLine: number; endLine: number; sessionId: string | null; promptId?: number | null; }>; /** * Separate AI and human ranges */ export declare function separateRanges(ranges: Array<{ startLine: number; endLine: number; sessionId: string | null; promptId?: number | null; }>): { aiRanges: Array<{ startLine: number; endLine: number; sessionId: string; promptId?: number | null; }>; humanRanges: Array<{ startLine: number; endLine: number; }>; }; /** * Format ranges as compact string (e.g., "10-45,60-75") */ export declare function formatRanges(ranges: Array<{ startLine: number; endLine: number; }>): string; /** * Parse ranges from compact string */ export declare function parseRanges(str: string): Array<{ startLine: number; endLine: number; }>; /** * Build a map of sessionId -> files -> lines from traced results */ export declare function buildSessionMap(fileAttributions: Map>): Map>; /** * Build human ranges map from traced results */ export declare function buildHumanMap(fileAttributions: Map>): Map; export {};