From a22618dd0191102cac2817a89a75ae474cb25362 Mon Sep 17 00:00:00 2001 From: Yash Dewasthale Date: Fri, 24 Jul 2026 17:16:51 +0530 Subject: [PATCH] feat: bump supercode-cli version to 0.1.86 and enhance hallucination guard: - Updated version in package.json to 0.1.86. - Implemented a hallucination guard in the agent runner to detect when the model claims actions without making tool calls. - Added new rules in prompts for refactoring callbacks to async/await for better coding practices. --- apps/supercode-cli/server/package.json | 2 +- .../server/src/agent/prompts/build.txt | 2 ++ .../server/src/agent/prompts/general.txt | 2 ++ apps/supercode-cli/server/src/agent/runner.ts | 24 +++++++++++++++++++ .../server/src/cli/ai/chat/chat.ts | 4 ++-- 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/apps/supercode-cli/server/package.json b/apps/supercode-cli/server/package.json index b868667..ee0d8ab 100644 --- a/apps/supercode-cli/server/package.json +++ b/apps/supercode-cli/server/package.json @@ -1,6 +1,6 @@ { "name": "supercode-cli", - "version": "0.1.85", + "version": "0.1.86", "description": "AI-powered coding agent CLI", "main": "dist/main.js", "bin": { diff --git a/apps/supercode-cli/server/src/agent/prompts/build.txt b/apps/supercode-cli/server/src/agent/prompts/build.txt index 871dae8..d45ad8f 100644 --- a/apps/supercode-cli/server/src/agent/prompts/build.txt +++ b/apps/supercode-cli/server/src/agent/prompts/build.txt @@ -33,6 +33,8 @@ CRITICAL RULES: - **Self-heal after failures.** When a build command or typecheck fails, read the error output and fix the specific file/line cited. Don't re-scaffold from scratch. Don't guess — read the actual error. +- **When refactoring callbacks to async/await:** Remove ALL callback parameters and cb()/callback() calls. Use `return` for success values and let errors propagate naturally (or `throw`). The function signature must change from `(arg, cb)` to `(arg)`. Do NOT keep callbacks in any form — that defeats the purpose of async/await. + - **Complete the full task.** "Create a todo app" means: - Scaffold the project - Install dependencies diff --git a/apps/supercode-cli/server/src/agent/prompts/general.txt b/apps/supercode-cli/server/src/agent/prompts/general.txt index dcfdd0b..d91d564 100644 --- a/apps/supercode-cli/server/src/agent/prompts/general.txt +++ b/apps/supercode-cli/server/src/agent/prompts/general.txt @@ -18,6 +18,8 @@ Hard rules: - **Check tool output honestly:** A tool returning `{ success: true, data: ... }` does NOT mean the data is useful. Check the actual returned content. If the data is empty, null, or an error message, do NOT use it to support claims — say what happened. +- **When refactoring callbacks to async/await:** Remove ALL callback parameters and cb()/callback() calls. Use `return` for success values and let errors propagate naturally (or `throw`). The function signature must change from `(arg, cb)` to `(arg)`. + - **No silent state changes:** If you write a file or run a command, say exactly what you changed and why. The parent agent audits your work. - **Return structure:** When you finish, return a single summary in this shape (plain text, no markdown headers): diff --git a/apps/supercode-cli/server/src/agent/runner.ts b/apps/supercode-cli/server/src/agent/runner.ts index 3b1f73b..a132556 100644 --- a/apps/supercode-cli/server/src/agent/runner.ts +++ b/apps/supercode-cli/server/src/agent/runner.ts @@ -69,6 +69,9 @@ export async function runAgent( // Track tool call repetition — same tool + same args 3+ times signals a loop const toolCallHistory: Array<{ toolName: string; argsKey: string }> = [] let stopForRepetition = false + // Hallucination guard: detect when model claims actions but made zero tool calls + let lastStepHadToolCalls = false + let lastStepHadActionClaim = false const messages = buildMessages(opts) @@ -99,6 +102,20 @@ export async function runAgent( }], } } + // Hallucination guard: previous step claimed actions but made no tool calls + if (lastStepHadActionClaim) { + lastStepHadActionClaim = false + return { + messages: [{ + role: "system" as const, + content: + "SYSTEM NOTICE: Your previous response claimed to have made changes " + + "(e.g., wrote, edited, refactored) but you did not call any tools. " + + "Do not describe changes — actually execute them by calling the appropriate " + + "tool (edit_file, write_file, run_command, etc.). Then summarize what you did.", + }], + } + } if (seenStepResults.length === 0) return undefined const allEmpty = seenStepResults.every((r) => isEmptyToolResult(r.result)) if (!allEmpty) return undefined @@ -187,6 +204,13 @@ export async function runAgent( toolCallHistory.splice(0, toolCallHistory.length - 12) } } + // Track whether this step had tool calls for the hallucination guard + lastStepHadToolCalls = (event.toolCalls?.length ?? 0) > 0 + lastStepHadActionClaim = false + if (!lastStepHadToolCalls && event.text) { + const actionClaimRe = /\b(wrote|updated|added|created|ran|executed|fixed|refactored|removed|deleted|installed|modified|edited|applied|saved|generated|wired|hooked)\b/i + lastStepHadActionClaim = actionClaimRe.test(event.text) + } opts.onStepFinish?.(event) }, }) diff --git a/apps/supercode-cli/server/src/cli/ai/chat/chat.ts b/apps/supercode-cli/server/src/cli/ai/chat/chat.ts index 035eec1..bfdcca9 100644 --- a/apps/supercode-cli/server/src/cli/ai/chat/chat.ts +++ b/apps/supercode-cli/server/src/cli/ai/chat/chat.ts @@ -1157,7 +1157,7 @@ function renderInput() { const cols = process.stdout.columns || 80 const lines = atPicker.render(cols) for (const line of lines) { - process.stdout.write(line + "\n") + process.stdout.write("\r\n" + line) } atListLines = lines.length } @@ -1167,7 +1167,7 @@ function renderInput() { const ddLines = ddTracker.render(process.stdout.columns || 80) if (ddLines.length > 0) { for (const line of ddLines) { - process.stdout.write(line + "\n") + process.stdout.write("\r\n" + line) } ddListLines = ddLines.length }