/** * A minimal unified-diff parser (git's `diff --git` dialect) — just enough structure for the * detectors in this module: per-file hunks, each line typed context/add/remove and carrying its * line number in whichever image it belongs to. * * Deliberately narrow: this is not a general patch-apply library. It accepts the shape `git diff` * / `git format-patch` produce and refuses (throws `DiffParseError`) rather than guess on anything * else — the same "refuse, don't mangle" rule `documents.ts` and `openai-request.ts` follow * elsewhere in this repo. */ export type DiffLineKind = "context" | "add" | "remove"; export interface DiffLine { readonly kind: DiffLineKind; /** Line content, WITHOUT the leading `+`/`-`/` ` marker and without a trailing newline. */ readonly content: string; /** 1-based line number in the pre-image; undefined for an added line. */ readonly oldLine: number | undefined; /** 1-based line number in the post-image; undefined for a removed line. */ readonly newLine: number | undefined; /** Index of this line's raw (marker-included) text in the diff's full line array. The * auto-repair pass edits/removes raw lines by this index rather than re-deriving offsets — the * ONE place the diff's own text layout is exposed outside this parser. */ readonly rawIndex: number; } export interface DiffHunk { readonly oldStart: number; readonly oldLines: number; readonly newStart: number; readonly newLines: number; readonly lines: readonly DiffLine[]; /** Raw-line index of this hunk's `@@ ... @@` header. */ readonly headerRawIndex: number; /** Raw-line index one past this hunk's last body line — `[headerRawIndex, endRawIndex)` is the * whole hunk, header included, safe to delete as a unit. */ readonly endRawIndex: number; } export interface DiffFile { /** Pre-image path (`a/...` with the prefix stripped), or null for a newly created file. */ readonly oldPath: string | null; /** Post-image path (`b/...` with the prefix stripped), or null for a deleted file. */ readonly newPath: string | null; readonly isNew: boolean; readonly isDeleted: boolean; readonly hunks: readonly DiffHunk[]; } export declare class DiffParseError extends Error { } /** * Parse a unified diff into per-file hunks. * * Accepts multiple `diff --git` sections. Each file section must open with a `diff --git a/X b/Y` * line; `---`/`+++`/`@@` lines follow standard git conventions. A file section with no hunks * (e.g. a pure rename or mode change) is skipped — there is nothing here for a line-level * detector to look at. */ export declare function parseUnifiedDiff(text: string): readonly DiffFile[]; /** The path a detector should report findings under — the post-image path, falling back to the * pre-image path for a deletion (which carries no post-image). */ export declare function reportedPath(file: DiffFile): string;