(tool: { name: string; arg: string })
| 23 | * (replace_all, append), or when the inputs are too large to diff cheaply. |
| 24 | */ |
| 25 | export function buildEditDiffLines(tool: { name: string; arg: string }): DiffViewLine[] | null { |
| 26 | const kind = normalizeToolName(tool.name); |
| 27 | if (kind !== 'edit' && kind !== 'write') return null; |
| 28 | const d = parseArg(tool.arg); |
| 29 | if (!d) return null; |
| 30 | if (kind === 'edit') { |
| 31 | if (d.replace_all === true) return null; |
| 32 | const before = typeof d.old_string === 'string' ? d.old_string : undefined; |
| 33 | const after = typeof d.new_string === 'string' ? d.new_string : undefined; |
| 34 | if (before === undefined || after === undefined) return null; |
| 35 | return buildDiffLines(before, after); |
| 36 | } |
| 37 | // Write only reports the new content (and whether it appended); the client |
| 38 | // cannot tell a new file from an overwrite of an existing one. A from-empty |
| 39 | // diff would show an overwrite as "all additions, no deletions", which is |
| 40 | // misleading — so fall back to the tool output for every Write. |
| 41 | return null; |
| 42 | } |
| 43 | |
| 44 | /** Pull the file path out of an Edit/Write tool call's input, if present. */ |
| 45 | export function extractEditPath(arg: string): string | undefined { |
no test coverage detected