(filePath: string, content: string)
| 308 | return t1; |
| 309 | } |
| 310 | async function loadRejectionDiff(filePath: string, content: string): Promise<RejectionDiffData> { |
| 311 | try { |
| 312 | const fullFilePath = isAbsolute(filePath) ? filePath : resolve(getCwd(), filePath); |
| 313 | const handle = await openForScan(fullFilePath); |
| 314 | if (handle === null) return { |
| 315 | type: 'create' |
| 316 | }; |
| 317 | let oldContent: string | null; |
| 318 | try { |
| 319 | oldContent = await readCapped(handle); |
| 320 | } finally { |
| 321 | await handle.close(); |
| 322 | } |
| 323 | // File exceeds MAX_SCAN_BYTES — fall back to the create view rather than |
| 324 | // OOMing on a diff of a multi-GB file. |
| 325 | if (oldContent === null) return { |
| 326 | type: 'create' |
| 327 | }; |
| 328 | const patch = getPatchForDisplay({ |
| 329 | filePath, |
| 330 | fileContents: oldContent, |
| 331 | edits: [{ |
| 332 | old_string: oldContent, |
| 333 | new_string: content, |
| 334 | replace_all: false |
| 335 | }] |
| 336 | }); |
| 337 | return { |
| 338 | type: 'update', |
| 339 | patch, |
| 340 | oldContent |
| 341 | }; |
| 342 | } catch (e) { |
| 343 | // User may have manually applied the change while the diff was shown. |
| 344 | logError(e as Error); |
| 345 | return { |
| 346 | type: 'error' |
| 347 | }; |
| 348 | } |
| 349 | } |
| 350 | export function renderToolUseErrorMessage(result: ToolResultBlockParam['content'], { |
| 351 | verbose |
| 352 | }: { |
no test coverage detected