Refactor CLI input handling in cli.js to streamline the input structure and enhance the OpenAI call process. Introduce a new variable for previous response tracking and update file listing in list_files.js to return sorted file entries directly, improving output consistency.

This commit is contained in:
sebseb7
2025-08-12 04:14:42 +00:00
parent 324aea5775
commit 60e288454c
2 changed files with 17 additions and 17 deletions

32
cli.js
View File

@@ -6,7 +6,7 @@ import terminalKit from 'terminal-kit';
//npm install tiktoken
//csk-8jftdte6r6vf8fdvp9xkyek5t3jnc6jfhh93d3ewfcwxxvh9
import { promises as fs } from "node:fs";
import { promises as fs, unwatchFile } from "node:fs";
import { fileURLToPath } from "node:url";
import path from "node:path";
@@ -65,20 +65,20 @@ async function loadTools() {
);
return Object.fromEntries(toolEntries);
}
let counter = 0;
let previousResponseId;
while(true){
let counter = 0;
// Block for user input before kicking off the LLM loop
const userText = await askUserForInput();
await streamOnce(new OpenAI({ apiKey: process.env.OPENAI_API_KEY }), userText );
async function streamOnce(openai, userText) {
const toolsByFile = await loadTools();
let previousResponseId;
let input = [
{"role": "developer", "content": [ {
"type": "input_text","text": `You are an interactive CLI AI assistant. Follow the user's instructions.
const systemprompt = {"role": "developer", "content": [ {
"type": "input_text","text": `You are an interactive CLI AI assistant. Follow the user's instructions.
If a tool is available and relevant, plan to use it.
Tools:
@@ -87,15 +87,15 @@ patch_files - (zum anlegen, ändern und löschen von Dateien)
read_file - (nach zeilen)
ripgrep - suchmusater und dateimuster
websearch - eine Google Suche machen mit Schlüsselwörtern`
}] },
{"role": "user", "content": [ {"type": "input_text","text": userText } ]},
]
while(input.length > 0){
}]};
const input = [{"role": "user", "content": [ {"type": "input_text","text": userText } ]}];
do{
const call = {
model: 'gpt-5-mini',
input: input,
input: counter == 0 ? [systemprompt,...structuredClone(input)] : structuredClone(input),
text: { format: { type: 'text' }, verbosity: 'low' },
reasoning: { effort: 'minimal', summary: 'detailed' },
tools: Object.values(toolsByFile).map(t => t.def),
@@ -106,7 +106,7 @@ websearch - eine Google Suche machen mit Schlüsselwörtern`
console.log("\n\n\n\n\n------NEW OPENAI CALL-"+input.length+"-------------"
,"\n",counter++,"\n",'----INPUT-----------------'
,"\n",call.input.map(i => JSON.stringify(i)),"\n",
'--------CALL-------------',"\n");
'--------CALL-------------',call,"\n");
const stream = await openai.responses.stream(call);
stream.on('response.created', (event) => {
previousResponseId = event.response.id;
@@ -156,7 +156,7 @@ websearch - eine Google Suche machen mit Schlüsselwörtern`
});
await Array.fromAsync(stream);
input=[];
input.length = 0;
for (const call of functionCalls) {
//try {
@@ -171,7 +171,7 @@ websearch - eine Google Suche machen mit Schlüsselwörtern`
// console.error('Error in function call:', call.name, err);
//}
}
}
}while(input.length > 0)
//console.log('OPENAI STREAM FINISHED');
}

View File

@@ -173,7 +173,7 @@ export async function run(args) {
const files = await listEntriesRecursive(resolvedBase, chrootResolved, depth === -1 ? Infinity : depth, includeHidden);
return {
cwd,
files: JSON.stringify(files.sort((a, b) => a[0].localeCompare(b[0]))), // Sort for consistent output
files: files.sort((a, b) => a[0].localeCompare(b[0])), // Sort for consistent output
};
} catch (err) {
return { err: `Failed to list files: ${err?.message || String(err)}` };