Skip to content

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.

fix(agent) ein Nur-Lesen-Zug erfaehrt jetzt, was er noch darf

David7ac6e99554db
diff --git a/src/api/mcp/builtin-tools.ts b/src/api/mcp/builtin-tools.ts
index c2f5d473..58ba26fd 100644
--- a/src/api/mcp/builtin-tools.ts
+++ b/src/api/mcp/builtin-tools.ts
@@ -789,14 +789,14 @@ async function executeShellExecute(
const command = argString(args, 'command').trim()
if (!command) return 'shell_execute: `command` is required (or pass task: "status" | "list" | "kill").'
- const { rejectShellCommand, commandTimeoutMs, commandKind, isReadOnlyCommand } = await import(
+ const { rejectShellCommand, commandTimeoutMs, commandKind, isReadOnlyCommand, READ_ONLY_SHELL_HINT } = await import(
'../../lib/shell-command-classify'
)
// Read-only turn (/review …): the classifier is the gate now that the typed
// read-only inspectors are gone. Conservative on purpose: chained commands
// are refused outright, a read-only mode that can be talked around is none.
if (isReadOnlyShellTurn(run) && (args.background || !isReadOnlyCommand(command))) {
- return 'Refused: this turn is read-only (/review, Code-Review Mode or Plan mode). Only inspection commands run here: git status/log/diff/show/blame, ls, cat, pwd. One command, no chaining.'
+ return `Refused: this turn is read-only (/review, Code-Review Mode or Plan mode). ${READ_ONLY_SHELL_HINT}`
}
// The one refusal that stays hard after the merge: --no-verify on a commit.
diff --git a/src/lib/__tests__/agent-commands.test.ts b/src/lib/__tests__/agent-commands.test.ts
index bac8fb9f..d8fbb524 100644
--- a/src/lib/__tests__/agent-commands.test.ts
+++ b/src/lib/__tests__/agent-commands.test.ts
@@ -14,7 +14,8 @@ import {
loopPassSaysDone,
commandInScope,
} from '../agent-commands'
-import { MUTATING_TOOLS } from '../mutating-tools'
+import { MUTATING_TOOLS, allowedInReadOnlyTurn } from '../mutating-tools'
+import { READ_ONLY_SHELL_HINT, isReadOnlyCommand } from '../shell-command-classify'
import { readFileSync, readdirSync } from 'node:fs'
import { join } from 'node:path'
@@ -127,21 +128,48 @@ describe('AGENT_COMMANDS registry', () => {
}
})
- it('read-only commands never name a mutating tool in their template', () => {
- // The runner strips these tools for the turn, so a template that asks for
- // one would be instructing the model to reach for something that is gone.
+ it('read-only commands never name a tool the turn does not have', () => {
+ // Der Strip nimmt die mutierenden Werkzeuge, MIT EINER AUSNAHME:
+ // shell_execute bleibt, weil die frueheren Einzel-Inspektoren (git_status,
+ // git_log, git_diff) seit 2.6.6 darin stecken. Diese Ausnahme ist der
+ // Grund, warum die alte Fassung dieses Tests den Fehler mitgetragen hat:
+ // sie verlangte, dass KEIN mutierendes Werkzeug genannt wird, und der
+ // Vorspann sagte deshalb pauschal "no write or shell tools" -- was fuer
+ // shell_execute schlicht nicht stimmt. Gefragt ist nicht "mutierend",
+ // sondern "in diesem Zug nicht da".
for (const c of AGENT_COMMANDS.filter((c) => c.readOnly)) {
const text = c.build('x')
for (const tool of MUTATING_TOOLS) {
+ if (allowedInReadOnlyTurn(tool)) continue
expect(text, `${c.name} names ${tool}`).not.toContain(tool)
}
}
})
- it('read-only commands say up front that they cannot write or run', () => {
+ it('read-only commands say what they cannot do AND what they still can', () => {
for (const c of AGENT_COMMANDS.filter((c) => c.readOnly)) {
- expect(c.build('x')).toContain('no write or shell tools')
+ const text = c.build('x')
+ expect(text, `${c.name} verschweigt die Schreibsperre`).toContain('cannot write files')
+ expect(text, `${c.name} verschweigt die Befehlssperre`).toContain('cannot run arbitrary commands')
+ // Und der erlaubte Rest, woertlich so, wie der Executor ihn zulaesst.
+ expect(text, `${c.name} verschweigt die erlaubten Befehle`).toContain(READ_ONLY_SHELL_HINT)
+ }
+ })
+
+ it('der Vorspann verspricht genau die Befehle, die der Waechter auch durchlaesst', () => {
+ // Die Gegenprobe zum Test darueber: ein Satz, der eine Liste nennt, ist
+ // wertlos, wenn die Liste nicht stimmt. Jeder genannte Befehl muss durch
+ // isReadOnlyCommand kommen, und ein verketteter darf es nicht.
+ const liste = READ_ONLY_SHELL_HINT
+ .replace('Only inspection commands run here: ', '')
+ .replace('. One command, no chaining.', '')
+ .split(', ')
+ expect(liste.length).toBeGreaterThan(3)
+ for (const befehl of liste) {
+ expect(isReadOnlyCommand(befehl), `${befehl} wird versprochen, aber abgelehnt`).toBe(true)
}
+ // Trennkontrolle: derselbe Befehl mit Verkettung faellt.
+ expect(isReadOnlyCommand(`${liste[0]}; echo hi > x`)).toBe(false)
})
it('marks exactly the inspection commands read-only', () => {
diff --git a/src/lib/agent-commands.ts b/src/lib/agent-commands.ts
index 6e5a1213..5caf5a8d 100644
--- a/src/lib/agent-commands.ts
+++ b/src/lib/agent-commands.ts
@@ -20,6 +20,8 @@
* cleanly and the ChatInput autocomplete + the hooks share one source.
*/
+import { READ_ONLY_SHELL_HINT } from './shell-command-classify'
+
export interface AgentCommand {
/** Command word without the leading slash, e.g. "review". */
name: string
@@ -168,8 +170,25 @@ export function formatDuration(ms: number): string {
return m ? `${h}h ${m}m` : `${h}h`
}
-/** Read-only commands cannot run shell, so they must be told how to look. */
-const LOOK = 'Read the real code with file_read / file_list / file_search first — never answer from memory. You have no write or shell tools on this turn, so do not plan to use them.'
+/**
+ * Wie ein Nur-Lesen-Zug schauen darf, und zwar genau so weit, wie er es wirklich
+ * darf.
+ *
+ * Der zweite Satz stand bis zum 05.09.2026 als "You have no write or shell
+ * tools on this turn, so do not plan to use them". Seit dem 2.6.6-Werkzeugschnitt
+ * ist das falsch: `shell_execute` UEBERLEBT den Strip mit Absicht
+ * (`allowedInReadOnlyTurn`), weil die frueheren Einzelwerkzeuge git_status,
+ * git_log und git_diff darin aufgegangen sind, und der Executor laesst die
+ * Inspektionsbefehle durch. Ein `/review` ohne Argument prueft "the current
+ * uncommitted changes" und bekam gesagt, es duerfe genau das Werkzeug nicht
+ * anfassen, mit dem es diese Aenderungen ueberhaupt findet.
+ *
+ * Der erlaubte Teil kommt jetzt aus derselben Konstante wie die Ablehnung im
+ * Executor. Modell und Waechter koennen also nicht mehr auseinanderlaufen.
+ */
+const LOOK =
+ 'Read the real code with file_read / file_list / file_search first, never answer from memory. ' +
+ `You cannot write files on this turn, and you cannot run arbitrary commands. ${READ_ONLY_SHELL_HINT}`
export const AGENT_COMMANDS: AgentCommand[] = [
// ── Context ───────────────────────────────────────────────────────────
diff --git a/src/lib/shell-command-classify.ts b/src/lib/shell-command-classify.ts
index 5c967a02..9c33f922 100644
--- a/src/lib/shell-command-classify.ts
+++ b/src/lib/shell-command-classify.ts
@@ -68,6 +68,25 @@ const READ_ONLY_PREFIXES = [
'pwd',
]
+/**
+ * Was ein Nur-Lesen-Zug wirklich darf, in einem Satz.
+ *
+ * Drei Stellen mussten dasselbe wissen und wussten es getrennt: der Waechter
+ * hier, die Ablehnung im Executor und der Vorspann, den `/review` und
+ * Geschwister dem Modell schicken. Der Vorspann sagte am 05.09.2026 noch
+ * "you have no write or shell tools on this turn", was seit dem
+ * 2.6.6-Werkzeugschnitt schlicht falsch ist: `shell_execute` UEBERLEBT den
+ * Strip mit Absicht, weil die frueheren Einzelwerkzeuge (git_status, git_log,
+ * git_diff) darin aufgegangen sind. Ein `/review` der offenen Aenderungen
+ * bekam also gesagt, es duerfe genau das Werkzeug nicht anfassen, mit dem es
+ * die Aenderungen ueberhaupt findet.
+ *
+ * Deshalb steht der Satz jetzt an einer Stelle und wird zweimal gelesen. Wer
+ * die Liste oben aendert, aendert beides mit.
+ */
+export const READ_ONLY_SHELL_HINT =
+ `Only inspection commands run here: ${READ_ONLY_PREFIXES.join(', ')}. One command, no chaining.`
+
/**
* `git branch` is not a read: `git branch -D main` deletes a branch and
* `git branch foo` creates one, so it cannot live in READ_ONLY_PREFIXES,