/** * Surgical Code Editing * * LLM-driven code editing with layered matching that recovers from * trailing whitespace, indentation mismatch, and CRLF/LF differences. * * Supports replace, delete, insert (before/after/start/end), and range modes. * * Pure transform (`applyEdits`) + file wrapper (`editFile`) with atomic writes. */ export interface Edit { /** Text to find. Required for replace, delete, insert before/after. */ old?: string; /** Replacement text. Required for replace mode. */ new?: string; /** Replace/delete/insert ALL occurrences. Default false. */ all?: boolean; /** Delete the matched text (sugar for new: ""). */ delete?: boolean; /** Insert position. "before"/"after" use old as anchor. "start"/"end" target file boundaries. */ insert?: "before" | "after" | "start" | "end"; /** Content to insert or range replacement. Required for insert and range modes. */ content?: string; /** Start boundary for range replacement (inclusive). */ from?: string; /** End boundary for range replacement (inclusive). */ to?: string; } export interface EditChange { /** 1-based line where the change starts. */ line: number; /** Lines removed. */ removed: number; /** Lines added. */ added: number; } export interface EditResult { /** Resulting content after edits. */ content: string; /** Total number of replacements applied. */ applied: number; /** Per-replacement details in document order. */ changes: EditChange[]; } export declare class EditError extends Error { readonly editIndex: number; readonly detail?: { closest?: string; line?: number; context?: string[]; } | undefined; constructor(message: string, editIndex: number, detail?: { closest?: string; line?: number; context?: string[]; } | undefined); } /** * Apply edits to a source string. Pure function, no I/O. * * Mode detection (by field presence, precedence: range > insert > delete > replace): * - Range: `from` + `to` + `content` — replace block between markers (inclusive) * - Insert before/after: `old` + `insert` + `content` — insert relative to anchor * - Insert start/end: `insert` + `content` — prepend/append to file * - Delete: `old` + `delete: true` — remove matched text * - Replace: `old` + `new` — find and replace * * Matching strategy per anchor (in order): * 1. Exact byte match * 2. Line-normalized (trailing whitespace stripped) * 3. Indent-adjusted (leading whitespace baseline stripped, new indentation adjusted) * * Multi-edit: all matches resolved against original source, * validated for overlap, applied bottom-to-top. * * @throws EditError on match failure, validation error, or overlapping edits */ export declare function applyEdits(source: string, edits: Edit[]): EditResult; /** * Edit a file on disk. Reads, applies edits, writes atomically (temp + rename). */ export declare function editFile(path: string, edits: Edit[]): Promise; //# sourceMappingURL=edit.d.ts.map