/** * Patch application logic for the edit tool. * * Applies parsed diff hunks to file content using fuzzy matching * for robust handling of whitespace and formatting differences. */ import type { AgentToolResult } from "@oh-my-pi/pi-agent-core"; import * as z from "zod/v4"; import { type WritethroughCallback, type WritethroughDeferredHandle } from "../../lsp"; import type { ToolSession } from "../../tools"; import type { EditToolDetails, LspBatchRequest } from "../renderer"; export type Operation = "create" | "delete" | "update"; export interface PatchInput { path: string; op: Operation; rename?: string; diff?: string; } export interface FileSystem { exists(path: string): Promise; read(path: string): Promise; readBinary?: (path: string) => Promise; write(path: string, content: string): Promise; delete(path: string): Promise; mkdir(path: string): Promise; } interface FileChange { type: Operation; path: string; newPath?: string; oldContent?: string; newContent?: string; } export interface ApplyPatchResult { change: FileChange; warnings?: string[]; } export interface ApplyPatchOptions { cwd: string; dryRun?: boolean; fuzzyThreshold?: number; allowFuzzy?: boolean; fs?: FileSystem; } /** Default filesystem implementation using Bun APIs */ export declare const defaultFileSystem: FileSystem; /** * Apply a patch operation to the filesystem. */ export declare function applyPatch(input: PatchInput, options: ApplyPatchOptions): Promise; /** * Preview what changes a patch would make without applying it. */ export declare function previewPatch(input: PatchInput, options: ApplyPatchOptions): Promise; export declare function computePatchDiff(input: PatchInput, cwd: string, options?: { fuzzyThreshold?: number; allowFuzzy?: boolean; }): Promise<{ diff: string; firstChangedLine: number | undefined; } | { error: string; }>; export declare const patchEditEntrySchema: z.ZodObject<{ op: z.ZodOptional>; rename: z.ZodOptional; diff: z.ZodOptional; }, z.core.$strict>; export declare const patchEditSchema: z.ZodObject<{ path: z.ZodString; edits: z.ZodArray>; rename: z.ZodOptional; diff: z.ZodOptional; }, z.core.$strict>>; }, z.core.$strict>; export type PatchEditEntry = z.infer; export type PatchParams = z.infer; export interface ExecutePatchSingleOptions { session: ToolSession; path: string; params: PatchEditEntry; signal?: AbortSignal; batchRequest?: LspBatchRequest; allowFuzzy: boolean; fuzzyThreshold: number; writethrough: WritethroughCallback; beginDeferredDiagnosticsForPath: (path: string) => WritethroughDeferredHandle; } export declare function executePatchSingle(options: ExecutePatchSingleOptions): Promise>; export {};