Update CLI interrogation command for improved file handling and output clarity. Enhance error logging in patch_files.js by integrating chalk for better visibility of patch errors and refining path resolution logic for file updates.

This commit is contained in:
sebseb7
2025-08-21 08:33:00 +00:00
parent 7fb261a3b7
commit 131a45e305
2 changed files with 8 additions and 4 deletions

View File

@@ -1,5 +1,7 @@
#!/usr/bin/env node
import chalk from 'chalk';
const desc = `
This is a custom utility that makes it more convenient to add, remove, move, or edit code files. 'apply_patch' effectively allows you to execute a diff/patch against a file,
but the format of the diff specification is unique to this task, so pay careful attention to these instructions.
@@ -612,10 +614,11 @@ function _get_updated_file(text, action, path) {
function patch_to_commit(patch, orig, chroot = null) {
const commit = new Commit();
for (const [path, action] of Object.entries(patch.actions)) {
const resolvedPath = resolvePath(chroot, path);
if (action.type === ActionType.DELETE) {
commit.changes[path] = new FileChange(
ActionType.DELETE,
orig[path],
orig[resolvedPath],
null,
null
);
@@ -630,11 +633,11 @@ function patch_to_commit(patch, orig, chroot = null) {
null
);
} else if (action.type === ActionType.UPDATE) {
const new_content = _get_updated_file(orig[path], action, path);
const new_content = _get_updated_file(orig[resolvedPath], action, path);
const move_path = action.move_path ? unresolvePath(chroot, action.move_path) : null;
commit.changes[path] = new FileChange(
ActionType.UPDATE,
orig[path],
orig[resolvedPath],
new_content,
move_path
);
@@ -824,6 +827,7 @@ export async function run(args) {
);
return result;
} catch (error) {
console.log(chalk.red('Patch error:'),error);
return `Patch error: ${error.message}`
}
}