| 51 | } |
| 52 | |
| 53 | function createTempFilesForModify( |
| 54 | currentContent: string, |
| 55 | proposedContent: string, |
| 56 | file_path: string, |
| 57 | ): { oldPath: string; newPath: string } { |
| 58 | const tempDir = os.tmpdir(); |
| 59 | const diffDir = path.join(tempDir, 'anus-cli-tool-modify-diffs'); |
| 60 | |
| 61 | if (!fs.existsSync(diffDir)) { |
| 62 | fs.mkdirSync(diffDir, { recursive: true }); |
| 63 | } |
| 64 | |
| 65 | const ext = path.extname(file_path); |
| 66 | const fileName = path.basename(file_path, ext); |
| 67 | const timestamp = Date.now(); |
| 68 | const tempOldPath = path.join( |
| 69 | diffDir, |
| 70 | `anus-cli-modify-${fileName}-old-${timestamp}${ext}`, |
| 71 | ); |
| 72 | const tempNewPath = path.join( |
| 73 | diffDir, |
| 74 | `anus-cli-modify-${fileName}-new-${timestamp}${ext}`, |
| 75 | ); |
| 76 | |
| 77 | fs.writeFileSync(tempOldPath, currentContent, 'utf8'); |
| 78 | fs.writeFileSync(tempNewPath, proposedContent, 'utf8'); |
| 79 | |
| 80 | return { oldPath: tempOldPath, newPath: tempNewPath }; |
| 81 | } |
| 82 | |
| 83 | function getUpdatedParams<ToolParams>( |
| 84 | tmpOldPath: string, |