Refactor path handling in patch_files.js to use user-specified paths for action keys, improving consistency and error messaging. Update CLI to replace commented-out test cases with a new interrogation command in German for business website creation, enhancing functionality.

This commit is contained in:
sebseb7
2025-08-14 11:01:55 +00:00
parent 9974a78394
commit 3c6bf7184c
2 changed files with 20 additions and 19 deletions

View File

@@ -21,9 +21,10 @@ modelDialog.on('reasoningUpdate', (output) => {
(async ()=>{
const output = await modelDialog.interrogate('Can you remember "seven" ?');
console.log(output.output,JSON.stringify(output.reasoning,null,2));
const output2 = await modelDialog.interrogate('read a file that is what you remebered plus 1 as a word with txt ending, check that file.');
//const output = await modelDialog.interrogate('Can you remember "seven" ?');
//console.log(output.output,JSON.stringify(output.reasoning,null,2));
//const output2 = await modelDialog.interrogate('read a file that is what you remebered plus 1 as a word with txt ending, check that file.');
const output2 = await modelDialog.interrogate('Ersttelle eine beispiel business webseite für acme mit react und webpack. Lege die Dateien in /demo an');
console.log('final output:',output2.output);
console.log('reasoning:',output2.reasoning);
console.log('Tokens:',output2.inputTokens,output2.cachedTokens,output2.outputTokens);

View File

@@ -238,9 +238,9 @@ class Parser {
if (path) {
// Resolve path with chroot
const resolvedPath = resolvePath(this.chroot, path);
if (resolvedPath in this.patch.actions) {
throw new DiffError(`Duplicate update for file: ${resolvedPath}`);
// Use user-specified path as the key to avoid double-resolving later
if (path in this.patch.actions) {
throw new DiffError(`Duplicate update for file: ${path}`);
}
const move_to = this.read_str("*** Move to: ");
if (!(resolvedPath in this.current_files)) {
@@ -248,8 +248,8 @@ class Parser {
}
const text = this.current_files[resolvedPath];
const action = this._parse_update_file(text);
action.move_path = move_to ? resolvePath(this.chroot, move_to) : null;
this.patch.actions[resolvedPath] = action;
action.move_path = move_to ? move_to : null;
this.patch.actions[path] = action;
continue;
}
@@ -258,14 +258,13 @@ class Parser {
if (path) {
// Resolve path with chroot
const resolvedPath = resolvePath(this.chroot, path);
if (resolvedPath in this.patch.actions) {
throw new DiffError(`Duplicate delete for file: ${resolvedPath}`);
if (path in this.patch.actions) {
throw new DiffError(`Duplicate delete for file: ${path}`);
}
if (!(resolvedPath in this.current_files)) {
throw new DiffError(`Delete File Error - missing file: ${resolvedPath}`);
throw new DiffError(`Delete File Error - missing file: ${path}`);
}
this.patch.actions[resolvedPath] = new PatchAction(ActionType.DELETE);
this.patch.actions[path] = new PatchAction(ActionType.DELETE);
continue;
}
@@ -274,14 +273,13 @@ class Parser {
if (path) {
// Resolve path with chroot
const resolvedPath = resolvePath(this.chroot, path);
if (resolvedPath in this.patch.actions) {
throw new DiffError(`Duplicate add for file: ${resolvedPath}`);
if (path in this.patch.actions) {
throw new DiffError(`Duplicate add for file: ${path}`);
}
if (resolvedPath in this.current_files) {
throw new DiffError(`Add File Error - file already exists: ${resolvedPath}`);
throw new DiffError(`Add File Error - file already exists: ${path}`);
}
this.patch.actions[resolvedPath] = this._parse_add_file();
this.patch.actions[path] = this._parse_add_file();
continue;
}
@@ -370,7 +368,9 @@ class Parser {
if (!s.startsWith("+")) {
throw new DiffError(`Invalid Add File line (missing '+'): ${s}`);
}
lines.push(s.substring(1)); // strip leading '+'
// Strip leading '+' and ignore a single optional space immediately after '+'
const content = s.substring(1).replace(/^ /, "");
lines.push(content);
}
return new PatchAction(ActionType.ADD, lines.join("\n"));
}