( item: ToolItem, descriptor: AgentActivityDescriptor, )
| 32 | const SHIKI_REMOVE_RE = /\s*\/\/\s*\[!code\s*--\]\s*$/; |
| 33 | |
| 34 | export function buildFileEditDiff( |
| 35 | item: ToolItem, |
| 36 | descriptor: AgentActivityDescriptor, |
| 37 | ): FileEditDiff | null { |
| 38 | if (descriptor.renderClass !== "file-edit") { |
| 39 | return null; |
| 40 | } |
| 41 | |
| 42 | const resultText = getResultText(item.result); |
| 43 | const path = |
| 44 | getToolString(item.args, ["path", "file", "file_path", "target_file"]) ?? |
| 45 | descriptor.object ?? |
| 46 | descriptor.preview ?? |
| 47 | getDiffPath(resultText); |
| 48 | |
| 49 | if (!path) { |
| 50 | return null; |
| 51 | } |
| 52 | |
| 53 | const lines = getDiffLines(resultText); |
| 54 | const stats = getDiffStats(resultText, lines); |
| 55 | if (!stats) { |
| 56 | return null; |
| 57 | } |
| 58 | |
| 59 | return { |
| 60 | path, |
| 61 | filename: basename(path), |
| 62 | additions: stats.additions, |
| 63 | deletions: stats.deletions, |
| 64 | lines, |
| 65 | }; |
| 66 | } |
| 67 | |
| 68 | function getResultText(result: string): string { |
| 69 | const parsed = parseToolResultValue(result); |
no test coverage detected