coder-agent 2.8.3 → 2.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.js +8 -0
- package/dist/tools.js +11 -4
- package/package.json +1 -1
package/dist/agent.js
CHANGED
|
@@ -783,6 +783,14 @@ export class Agent {
|
|
|
783
783
|
let args = {};
|
|
784
784
|
try {
|
|
785
785
|
args = JSON.parse(toolCall.function.arguments);
|
|
786
|
+
if (args && typeof args === "object") {
|
|
787
|
+
if (args.filepath && !args.file_path)
|
|
788
|
+
args.file_path = args.filepath;
|
|
789
|
+
if (args.path && !args.file_path)
|
|
790
|
+
args.file_path = args.path;
|
|
791
|
+
if (args.dirpath && !args.dir_path)
|
|
792
|
+
args.dir_path = args.dirpath;
|
|
793
|
+
}
|
|
786
794
|
}
|
|
787
795
|
catch { }
|
|
788
796
|
// Render tool execution card
|
package/dist/tools.js
CHANGED
|
@@ -423,15 +423,22 @@ export async function patch_file({ file_path, target_code, replacement_code }) {
|
|
|
423
423
|
}
|
|
424
424
|
const targetPath = normalizeFilePath(file_path);
|
|
425
425
|
const content = await fs.readFile(targetPath, "utf-8");
|
|
426
|
-
|
|
426
|
+
// Normalize all line endings to LF (\n) for comparison and patching
|
|
427
|
+
const normalizedContent = content.replace(/\r\n/g, "\n");
|
|
428
|
+
const normalizedTarget = target_code.replace(/\r\n/g, "\n");
|
|
429
|
+
const normalizedReplacement = replacement_code.replace(/\r\n/g, "\n");
|
|
430
|
+
if (!normalizedContent.includes(normalizedTarget)) {
|
|
427
431
|
return `ERROR: Target code not found in file ${file_path}. Please verify target content.`;
|
|
428
432
|
}
|
|
429
|
-
const occurrences =
|
|
433
|
+
const occurrences = normalizedContent.split(normalizedTarget).length - 1;
|
|
430
434
|
if (occurrences > 1) {
|
|
431
435
|
return `ERROR: Target code matches ${occurrences} times in file ${file_path}. Please provide more unique context to target the exact edit.`;
|
|
432
436
|
}
|
|
433
|
-
const
|
|
434
|
-
|
|
437
|
+
const newNormalizedContent = normalizedContent.replace(normalizedTarget, normalizedReplacement);
|
|
438
|
+
// Restore original CRLF line endings if the original file had them
|
|
439
|
+
const hasCrlf = content.includes("\r\n");
|
|
440
|
+
const finalContent = hasCrlf ? newNormalizedContent.replace(/\n/g, "\r\n") : newNormalizedContent;
|
|
441
|
+
await fs.writeFile(targetPath, finalContent, "utf-8");
|
|
435
442
|
return `✓ Patched file ${file_path} successfully.`;
|
|
436
443
|
}
|
|
437
444
|
catch (e) {
|