/** * Aider's `replace_part_with_missing_leading_whitespace` (~10k stars between * aider/devon/codemcp/qwen-coder use this exact pattern). Models very often * mess up leading whitespace — uniformly across both old_text and new_text. * Strategy: * 1. Outdent old/new uniformly by the smallest leading-whitespace count * across all non-blank lines (handles "model included some but not all"). * 2. Scan the file for a window where every line matches when stripped AND * the file's actual leading prefix is uniform across non-blank lines. * 3. Re-apply that uniform file-prefix to every non-blank line of new_text * before substituting. * * Returns the rewritten file content on success, null when no unique match. */ export declare function applyMissingLeadingWhitespace(working: string, old: string, next: string): string | null; /** * Aider-style `...` elision matching: when `old_text` contains lines that are * just `...`, treat them as "skip whatever's here" placeholders. The model * writes: * * old: function foo() { * ... * return bar; * } * new: function foo() { * ... * return baz; * } * * We split both `old` and `next` on the `...` lines, then anchor the bookend * pieces in `working` (greedy, in order). The elided middle from `working` is * preserved verbatim and stitched in between the new bookends. Returns the * rewritten buffer on success, null when: * - `old` has no `...` lines (caller should try other strategies) * - piece counts differ between `old` and `next` (ambiguous elision) * - any piece is empty (means dots at start/end or adjacent — too risky) * - any old piece doesn't appear in `working` after the previous one * * Greedy first-match-then-forward. We DO NOT support `replace_all` with * elision — `...` is intrinsically a single edit. */ export declare function applyDotdotdots(working: string, old: string, next: string): string | null; /** * Models often add spurious leading blank line(s) to `old_text` (e.g. when * copying a code block out of fenced markdown). Aider noticed this back at * its issue #25. Strips ALL consecutive leading blank/whitespace-only lines so * the caller can retry the match — one strip wasn't enough when a model prepends * several blank lines combined with other drift. Returns null when there is no * leading blank line, so callers can cheaply skip the retry. */ export declare function stripLeadingBlankLine(text: string): string | null; /** * Symmetric to `stripLeadingBlankLine`: strips ALL trailing blank/whitespace-only * lines. Models commonly append a stray newline or blank line to `old_text` * (e.g. a trailing newline left in when copying a block). Returns null when * there is no trailing blank line. */ export declare function stripTrailingBlankLine(text: string): string | null; /** * Strip spurious blank lines from BOTH edges of `old_text`. Returns null when * neither edge had a blank line (so callers can cheaply skip the retry). */ export declare function stripBlankEdges(text: string): string | null; /** * Find text in content, trying exact match first then fuzzy. */ export declare function fuzzyFindText(content: string, oldText: string): { found: boolean; index: number; matchLength: number; usedFuzzy: boolean; }; /** * Count occurrences of oldText in content (exact first, then fuzzy). */ export declare function countOccurrences(content: string, oldText: string): number; /** * When old_text isn't found, locate up to `maxResults` lines in `content` with * the highest token-overlap to the first non-empty line of `oldText` and * return ±contextLines around each as numbered snippets, joined by `---`. * Returns null if there's no plausible match (no shared tokens at all). * Cuts retry loops by showing the model what's actually in the file at the * expected location(s) — multiple results help disambiguate when several * regions look similar (e.g. repeated function bodies). */ export interface ClosestSnippet { snippet: string; topLine: number; } export declare function findClosestSnippet(content: string, oldText: string, contextLines?: number, maxResults?: number): ClosestSnippet | null; /** * Locate every occurrence of `text` in `content` and return the 1-indexed line * number plus a trimmed preview of that line. Tries exact first, then the same * fuzzy normalization as `countOccurrences` so the line numbers match what the * caller saw in `countOccurrences`. Capped at `max` so error messages stay * compact when a token like `}` matches dozens of times. */ export declare function findOccurrenceLines(content: string, text: string, max?: number): { line: number; preview: string; }[]; /** * Generate a unified diff string. */ export declare function generateDiff(oldContent: string, newContent: string, filePath: string): string; //# sourceMappingURL=edit-diff.d.ts.map