The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(persona B3): ein Befehl neben task:"status" laeuft, statt garantiert zu scheitern
Claudee7f24ad8a4ff
diff --git a/src/api/mcp/__tests__/shell-falle-task-status.test.ts b/src/api/mcp/__tests__/shell-falle-task-status.test.tsnew file mode 100644index 00000000..0b19b18b--- /dev/null+++ b/src/api/mcp/__tests__/shell-falle-task-status.test.ts@@ -0,0 +1,93 @@+/**+ * Ein Aufruf, der alles dabei hat, um zu laufen, darf nicht am Beiwerk scheitern.+ *+ * Persona-Lauf vom 03.09.2026, `llama3.2:3b`. Auftrag: die macOS-Version ueber+ * `shell_execute` herausfinden. Das Modell schickte in 3 von 3 Anlaeufen:+ *+ * {"cwd":".","shell":"bash","task":"status",+ * "command":"sw_vers -productVersion","timeout":600000}+ *+ * Antwort des Werkzeugs: `shell_execute: task "status" needs a task_id.` — der+ * Befehl lief nie. Danach nannte der Assistent `10.15` als Ausgabe. Der+ * wirkliche Wert war `26.3.1`: frei erfunden und als Befehlsausgabe verkauft.+ *+ * `task` waehlt eine Nebenhandlung (list/status/kill) an einem HINTERGRUND-Lauf+ * aus. Kleine Modelle fuellen das Feld wie jedes andere Schema-Feld mit — und+ * `status` ohne `task_id` ist ein garantierter Fehlschlag, waehrend daneben ein+ * vollstaendiger Befehl steht. Diese Kombination hat genau eine sinnvolle+ * Lesart, und die fuehrt das Werkzeug jetzt aus.+ *+ * Was NICHT gelockert wird: mit `task_id` bleibt `status`/`kill` die Abfrage+ * am Hintergrundlauf, und ohne Befehl bleibt der Fehlschlag ein Fehlschlag.+ *+ * Run: npx vitest run src/api/mcp/__tests__/shell-falle-task-status.test.ts+ */+import { describe, it, expect, vi, beforeEach } from 'vitest'++const backendCalls: { cmd: string; body: Record<string, unknown> }[] = []++vi.mock('../../backend', () => ({+ backendCall: vi.fn(async (cmd: string, body: Record<string, unknown>) => {+ backendCalls.push({ cmd, body })+ if (cmd === 'shell_execute') return { stdout: '26.3.1\n', stderr: '', exitCode: 0 }+ if (cmd === 'shell_task_status') return { id: 't-1', state: 'running', output: '' }+ if (cmd === 'shell_task_kill') return { id: 't-1', state: 'killed' }+ return { ok: true }+ }),+ fetchExternal: vi.fn(async () => ''),+}))+vi.mock('../../agents/sub-agent', () => ({+ DELEGATE_TASK_TOOL_DEF: { name: 'delegate_task', description: '', category: 'system', inputSchema: {} },+ buildDelegateExecutor: () => async () => 'stub',+}))+vi.mock('../../../lib/workflow-engine', () => ({ WorkflowEngine: class {} }))++import { registerBuiltinTools } from '../builtin-tools'+import { ToolRegistry } from '../tool-registry'++const registry = new ToolRegistry()+registerBuiltinTools(registry)++const shell = (args: Record<string, unknown>) => registry.execute('shell_execute', args)++beforeEach(() => { backendCalls.length = 0 })++describe('shell_execute: task neben einem fertigen Befehl', () => {+ it('fuehrt den Befehl der Persona aus, statt am task_id zu scheitern', async () => {+ const out = await shell({+ cwd: '.', shell: 'bash', task: 'status',+ command: 'sw_vers -productVersion', timeout: 600000,+ })+ expect(out).toContain('26.3.1')+ expect(out).not.toContain('needs a task_id')+ // Der Punkt ist nicht der Wortlaut, sondern dass wirklich etwas lief.+ expect(backendCalls.map((c) => c.cmd)).toContain('shell_execute')+ expect(backendCalls.find((c) => c.cmd === 'shell_execute')?.body.command)+ .toBe('sw_vers -productVersion')+ })++ it('dasselbe fuer kill', async () => {+ const out = await shell({ task: 'kill', command: 'echo hallo' })+ expect(out).not.toContain('needs a task_id')+ expect(backendCalls.map((c) => c.cmd)).toContain('shell_execute')+ })++ it('mit task_id bleibt es die Abfrage am Hintergrundlauf', async () => {+ // Sonst haette die Lockerung die eigentliche Funktion aufgefressen.+ await shell({ task: 'status', task_id: 't-1', command: 'echo hallo' })+ expect(backendCalls.map((c) => c.cmd)).toContain('shell_task_status')+ expect(backendCalls.map((c) => c.cmd)).not.toContain('shell_execute')+ })++ it('ohne Befehl bleibt der Fehlschlag ein Fehlschlag', async () => {+ const out = await shell({ task: 'status' })+ expect(out).toContain('task_id')+ expect(backendCalls).toEqual([])+ })++ it('ein leerer Befehl zaehlt nicht als Befehl', async () => {+ const out = await shell({ task: 'status', command: ' ' })+ expect(out).toContain('task_id')+ expect(backendCalls).toEqual([])+ })+})diff --git a/src/api/mcp/builtin-tools.ts b/src/api/mcp/builtin-tools.tsindex ce9e216e..c2f5d473 100644--- a/src/api/mcp/builtin-tools.ts+++ b/src/api/mcp/builtin-tools.ts@@ -766,12 +766,24 @@ async function executeShellExecute(const task = argString(args, 'task')if (task === 'list') return executeShellTaskList()if (task === 'status' || task === 'kill') {- if (task === 'kill' && isReadOnlyShellTurn(run)) {- return 'Refused: this turn is read-only (/review, Code-Review Mode or Plan mode); killing a task changes state.'- }const id = argString(args, 'task_id', 'id')- if (!id) return `shell_execute: task "${task}" needs a task_id.`- return task === 'status' ? executeShellTaskStatus({ id }) : executeShellTaskKill({ id })+ // Die Falle, die eine Persona am 03.09.2026 dreimal von drei Malen+ // ausgeloest hat: `llama3.2:3b` fuellte `task: "status"` wie jedes andere+ // Schema-Feld mit, waehrend daneben ein vollstaendiger Befehl stand —+ // `{"task":"status","command":"sw_vers -productVersion"}`. Ohne `task_id`+ // ist das ein garantierter Fehlschlag, und danach erfand das Modell die+ // Ausgabe. Diese Kombination hat genau eine sinnvolle Lesart: der Befehl+ // soll laufen. Mit `task_id` bleibt es die Abfrage am Hintergrundlauf, und+ // ohne Befehl bleibt der Fehlschlag stehen.+ if (!id && argString(args, 'command').trim()) {+ // faellt durch zur normalen Ausfuehrung unten+ } else {+ if (task === 'kill' && isReadOnlyShellTurn(run)) {+ return 'Refused: this turn is read-only (/review, Code-Review Mode or Plan mode); killing a task changes state.'+ }+ if (!id) return `shell_execute: task "${task}" needs a task_id (it comes from a background start). To run a command instead, drop \`task\` and pass \`command\`.`+ return task === 'status' ? executeShellTaskStatus({ id }) : executeShellTaskKill({ id })+ }}const command = argString(args, 'command').trim()diff --git a/src/hooks/useAgentChat.ts b/src/hooks/useAgentChat.tsindex 8a516821..bcec19af 100644--- a/src/hooks/useAgentChat.ts+++ b/src/hooks/useAgentChat.ts@@ -74,6 +74,7 @@ import { applyStoredCompaction } from '../lib/compact-summary'import { newestCompaction, maybeAutoCompact } from '../lib/run-compact-command'import { generateEmbeddings } from '../api/rag'import { truncateToolResult } from '../lib/truncate-tool-result'+import { toolFailureNote } from '../lib/tool-failure-note'import { toolCallCapMs, raceWithToolTimeout, SHELL_EXECUTE_DEFAULT_TIMEOUT_MS } from '../lib/tool-timeout'import { AgentLoopGuard } from '../lib/agent-loop-guard'import { budgetFromSettings } from '../api/agents/budget'@@ -2014,7 +2015,12 @@ export function useAgentChat() {// chars, big models get 60k (~15k tokens) so one giant tool result// can never ride along verbatim in every following request via// compaction's KEEP_RECENT window (225k-token prompts, 2026-07-26).- return truncateToolResult(text, settings.smallModelMode ? 1500 : 60000)+ // Die Notiz haengt NACH dem Kuerzen dran, sonst schneidet ein+ // langes Fehlerprotokoll sie gerade dann weg, wenn sie gebraucht wird.+ return (+ truncateToolResult(text, settings.smallModelMode ? 1500 : 60000) ++ toolFailureNote(r.status)+ )}// After a successful image/video gen, nudge a NATURAL closing comment so// the model doesn't silently loop another generation (David 2026-06-04).diff --git a/src/lib/__tests__/tool-failure-note.test.ts b/src/lib/__tests__/tool-failure-note.test.tsnew file mode 100644index 00000000..a3d9c128--- /dev/null+++ b/src/lib/__tests__/tool-failure-note.test.ts@@ -0,0 +1,50 @@+/**+ * Nach einem gescheiterten Werkzeug soll das Modell nicht raten.+ *+ * Siehe den Kopf von `tool-failure-note.ts` fuer die beiden Persona-Faelle vom+ * 03.09.2026 (erfundene Betriebssystemversion, erfundener Name mit erfundener+ * Quelle).+ *+ * Run: npx vitest run src/lib/__tests__/tool-failure-note.test.ts+ */+import { describe, it, expect } from 'vitest'+import { readFileSync } from 'node:fs'+import { join } from 'node:path'+import { toolFailureNote } from '../tool-failure-note'++describe('toolFailureNote', () => {+ it('sagt nach einem Fehlschlag ausdruecklich, dass es keine Ausgabe gibt', () => {+ const n = toolFailureNote('failed')+ expect(n).toMatch(/did NOT run/)+ expect(n).toMatch(/[Dd]o not state or guess/)+ })++ it('schweigt, wenn alles gut ging', () => {+ for (const s of ['completed', 'cached', 'running', 'pending']) {+ expect(toolFailureNote(s)).toBe('')+ }+ })++ it('schweigt bei einer Ablehnung — die hat schon ihren eigenen Satz', () => {+ // 'User rejected this action. Try a different approach.' steht bereits in+ // der Historie; ein zweiter Satz davor waere nur Laerm.+ expect(toolFailureNote('rejected')).toBe('')+ })++ it('die Notiz haengt wirklich an der Historie, nicht nur an dieser Datei', () => {+ // Ohne diesen Riegel waere die Funktion oben Dekoration: sie muss an der+ // Stelle stehen, an der die Werkzeugantwort in die Nachrichten geht.+ const hook = readFileSync(join(process.cwd(), 'src/hooks/useAgentChat.ts'), 'utf-8')+ expect(hook).toContain('toolFailureNote(r.status)')+ })++ it('sie steht NACH dem Kuerzen', () => {+ // Sonst schneidet ein langes Fehlerprotokoll genau den Satz weg, der+ // gebraucht wird. Gemessen an einem Ergebnis, das die Kappe reisst.+ const hook = readFileSync(join(process.cwd(), 'src/hooks/useAgentChat.ts'), 'utf-8')+ const kuerzen = hook.indexOf('truncateToolResult(text,')+ const notiz = hook.indexOf('toolFailureNote(r.status)')+ expect(kuerzen).toBeGreaterThan(-1)+ expect(notiz).toBeGreaterThan(kuerzen)+ })+})diff --git a/src/lib/tool-failure-note.ts b/src/lib/tool-failure-note.tsnew file mode 100644index 00000000..3bd3695e--- /dev/null+++ b/src/lib/tool-failure-note.ts@@ -0,0 +1,32 @@+// Was das Modell zu sehen bekommt, wenn ein Werkzeug NICHT gelaufen ist.+//+// Persona-Lauf vom 03.09.2026, `llama3.2:3b`, zwei Faelle derselben Sorte:+//+// • `shell_execute` brach mit `task "status" needs a task_id` ab — der+// Befehl lief nie. Der Assistent nannte trotzdem `10.15` als+// Betriebssystemversion. Richtig waere `26.3.1` gewesen.+// • `web_search` lieferte fuenf Trefferlisten ohne Antwort. Der Assistent+// erfand einen Namen UND schob eine Wikipedia-Seite als Beleg unter, die+// er nie geoeffnet hatte.+//+// Ihr Satz dazu: sie merkt es nur, wenn sie die Werkzeugkarte aufklappt und+// den Fehler selbst liest. Genau deshalb steht hier ein Satz mehr in der+// Historie: der Fehltext allein ("needs a task_id") sagt einem kleinen Modell+// nicht, dass es jetzt NICHT raten soll.+//+// Vorbild ist D#81: nach einer fehlgeschlagenen Bildgenerierung wurde die+// „liegt auf dem Schirm"-Notiz weggelassen, weil genau sie das Modell dazu+// brachte, ein Bild anzukuendigen, das es nie gab. Dasselbe Prinzip, andere+// Richtung.+//+// GRENZE, ehrlich: dass der Satz ANKOMMT, ist pruefbar und geprueft. Ob ein+// 3B-Modell daraufhin wirklich aufhoert zu erfinden, ist es nicht — das+// entscheidet das Modell.++/** Der Zusatz fuer einen Werkzeuglauf, der nicht geliefert hat. Leer, wenn alles gut ging. */+export function toolFailureNote(status: string): string {+ // 'rejected' hat schon einen eigenen, staerkeren Satz ("User rejected this+ // action") — ein zweiter davor waere nur Laerm.+ if (status !== 'failed' && status !== 'error' && status !== 'timeout') return ''+ return '\n\nThis tool did NOT run, so there is no output. Do not state or guess what it would have returned. Either call it again with corrected arguments, or tell the user plainly that this step failed.'+}