/** * Streaming edit preview strategies. * * Each edit mode owns a strategy that knows how to: * - collapse partial-JSON args to the subset safe to preview * (`extractCompleteEdits`), * - compute unified diff previews for the in-flight args * (`computeDiffPreview`), and * - render a text placeholder while no diff exists yet * (`renderStreamingFallback`). * * The shared renderer / `ToolExecutionComponent` consult the strategy via * the injected `editMode` rather than probing argument shape. */ import type { Theme } from "../modes/theme/theme"; import { type EditMode, resolveEditMode } from "../utils/edit-mode"; export interface PerFileDiffPreview { path: string; diff?: string; firstChangedLine?: number; error?: string; } export interface StreamingDiffContext { cwd: string; signal: AbortSignal; fuzzyThreshold?: number; allowFuzzy?: boolean; hashlineAutoDropPureInsertDuplicates?: boolean; /** * True while the tool's arguments are still streaming in. Strategies that * accept free-form text input (apply_patch, hashline) trim the trailing * partial line so per-character growth of an in-flight `+added` line does * not flicker in the preview. */ isStreaming?: boolean; } export interface EditStreamingStrategy { /** * Return the args restricted to edits that are "complete enough" to * compute a diff against. Strategies drop the trailing incomplete entry * when `partialJson` indicates its closing `}` hasn't arrived yet. */ extractCompleteEdits(args: Args, partialJson: string | undefined): Args; /** * Compute diff(s) for the given partial args. Returns `null` when args * do not yet carry enough structure to compute anything. */ computeDiffPreview(args: Args, ctx: StreamingDiffContext): Promise; /** * Rendered inline while the diff hasn't been computed yet (or when the * compute returned `null` because args are still too partial). */ renderStreamingFallback(args: Args, uiTheme: Theme): string; } /** * Given an edits array parsed from partial JSON, drop the last entry when the * corresponding object in `partialJson` does not yet end with a closed `}`. * * This guards against `partial-json` silently coercing truncated tails like * `"write":nu` / `"write":nul` into `{ write: null }`, which would make the * last entry render a spurious null-write error until the value finishes * streaming. */ export declare function dropIncompleteLastEdit(edits: readonly T[], partialJson: string | undefined, listKey: string): T[]; export declare const EDIT_MODE_STRATEGIES: Record>; export { resolveEditMode };