Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(gemini): stop the default permission mode auto-approving gemini's edits

enesd20b5e419062
diff --git a/docs/gemini-agent.md b/docs/gemini-agent.md
index 331bf47d4..0ff7f25a9 100644
--- a/docs/gemini-agent.md
+++ b/docs/gemini-agent.md
@@ -32,7 +32,7 @@ is the price of adding the next agent to the same list.
| `USAGE_CAPABLE` (the per-node context meter) | **joined this branch** | BOTH numbers, from gemini's own transcript: a used count and a **trustworthy** window. Used = the newest turn line's `tokens.input` (`core/gemini-session.ts`). The window is the harder half, and the reason gemini could join at all is that its CLI states a **family rule with a catch-all default**, not a per-model table — so `geminiWindowFor` mirrors `tokenLimit()` and an unheard-of model still gets the right answer (§4). Plus a *third* thing that is easy to miss: **joining this list turns on more than the meter** — see the warning under the table. |
| `TITLE_READ_CAPABLE` | **joined this branch** (the list was created for it) | A read leg that resolves a session's own name **without searching another agent's tree** (`pickGeminiTitle` over the transcript path the context tail already tracks), and one routing rule for the readers: `readAgentSessionName` in `core/agent-session-name.ts`, serving the desktop IPC handler *and* both shells' session-name sweeps. This list exists **because of gemini**: it names its own sessions but cannot be told a name, so the read and write legs had to split (§6). |
| `RENAME_CAPABLE` | **deliberately NOT joined** | There is no rename command to write to. Gemini's session commands are `/chat` (an alias for `/resume`) with `debug | delete | list | resume | save | share` (`bundle/docs/reference/commands.md:52-100`), where `save <tag>` is a tagged **checkpoint**, not a title. One list for both legs would light the rename UI on a node where the write silently does nothing. **Invariant** (pinned in `config.capabilities.test.ts`): every `RENAME_CAPABLE` agent is also `TITLE_READ_CAPABLE`, never the reverse. |
-| `PERMISSION_MODE_CAPABLE` | **joined this branch** | A per-agent **translation**, because gemini does not share claude's flag spelling: `--approval-mode default\|auto_edit\|yolo\|plan` (`gemini --help`, 0.54.4) against our `manual\|auto\|acceptEdits\|plan\|bypassPermissions`. The table is `GEMINI_MODES` in `src/shared/agents/approval-mode.ts`; §5 has the mapping and its one honest wart. |
+| `PERMISSION_MODE_CAPABLE` | **joined this branch** | A per-agent **translation**, because gemini does not share claude's flag spelling: `--approval-mode default\|auto_edit\|yolo\|plan` (`gemini --help`, 0.54.4) against our `manual\|auto\|acceptEdits\|plan\|bypassPermissions`. The table is `GEMINI_MODES` in `src/shared/agents/approval-mode.ts`; §5 has the mapping and the one mode — `auto`, which is also the DEFAULT — gemini has no word for. |
| `CONTEXT_LINK_CAPABLE` | **joined** (pre-branch) | A parser for gemini's event-sourced chat format plus a locator by sessionId (`handoff/locate.ts`'s `locateGemini`), and a discovery route — the marker block merged into `~/.gemini/GEMINI.md`. |
| `TRANSFER_SOURCE_CAPABLE` | **joined** (pre-branch) | The same native-transcript reader cross-agent transfer needs. |
| `CANVAS_CONTROL_CAPABLE` | **joined** (pre-branch) | The marker block in `~/.gemini/GEMINI.md` (gemini gets no skill — that is claude's discovery mechanism, which grok borrows). Membership is what sets `NODETERM_CANVAS_CONTROL` in the session env. |
@@ -226,7 +226,7 @@ transcript is on the host, while the server has no SSH-project manager and so ha
---
-## 5. Permission mode: `--approval-mode`, and the collapse we cannot express
+## 5. Permission mode: `--approval-mode`, and the mode gemini has no word for
`activePermissionMode(agentId)` resolves the project override, else `settings.claudePermissionMode`
(the persisted key keeps its name — renaming it would silently reset every existing user's choice).
@@ -239,19 +239,32 @@ lands is decided one layer up by `createAgentNode`, and for gemini it goes **las
| nodeterm mode | label | gemini flag | note |
|---|---|---|---|
| `manual` | Ask each time | *(none)* | gemini's own `default` is documented as "prompt for approval", which is exactly what the label promises — so no flag reproduces it, as it does for claude |
-| `auto` | Auto | `--approval-mode auto_edit` | **collapses** — see below |
+| `auto` | Auto | *(none)* | **no equivalent** — see below |
| `acceptEdits` | Accept edits | `--approval-mode auto_edit` | the direct equivalent ("auto-approve edit tools") |
| `plan` | Plan | `--approval-mode plan` | "read-only mode" |
| `bypassPermissions` | Bypass all | `--approval-mode yolo` | "auto-approve all tools" |
-**The honest wart: `auto` and `acceptEdits` both emit `auto_edit`, and there is no third value to
-reach for.** Gemini's vocabulary is exactly those four, so unlike codex — where a mode that could not
-be expressed was given `untrusted` — there is no other flag that means "approve everything except the
-dangerous bits". `modeSupported('gemini', 'auto')` is therefore **true** and both dropdown entries
-land on one runtime policy. This is documented in the source comment and **deliberately not papered
-over**: `unsupportedModesNote()` can only say "cannot express", never "collapses onto another mode",
-so the derived copy has no vocabulary for this case yet. Giving it one is a mechanism change, not a
-mapping fix.
+**`auto` emits no flag, and that is the whole reason this section exists.** `auto` is
+`DEFAULT_PERMISSION_MODE`, so this row decides what an **untouched install** launches gemini with.
+Gemini's vocabulary is exactly those four values, and none of them means "approve most things but
+NOT edits" — the nearest, `auto_edit`, is "auto-approve edit tools", i.e. the opposite end of the one
+axis our `auto` is about. The first version of this table mapped `auto → auto_edit` anyway, and the
+consequence was concrete: **every existing gemini node would have started auto-approving file edits
+on upgrade, with no notice.** Before gemini joined `PERMISSION_MODE_CAPABLE` it always launched bare
+(= gemini's `default` = *prompt for approval*), and `modeSupported('gemini','auto')` would have
+answered `true`, so `unsupportedModesNote()` would not have admitted it either — a silent widening of
+permissions dressed as a translation. So `auto` is **absent from `GEMINI_MODES`**,
+`modeSupported('gemini','auto')` is **false**, and the launch is the bare pre-branch command. This is
+the branch's own rule applied to gemini instead of exempted from it: a mode the CLI cannot express
+emits no flag, never a substituted nearest match (the same reason codex's `plan` and `acceptEdits`
+emit nothing). The cost is that `auto` and `manual` land on the same gemini policy — but that policy
+is the *prompting* one, which is the safe direction, and the derived copy now says it out loud:
+
+> Auto has no Gemini equivalent, so Gemini sessions start in Gemini's own default.
+
+Pinned by `approval-mode.test.ts` ("emits NO flag for `auto`, the default mode, rather than
+auto-approving edits"), which asserts the flags, `modeSupported`, the composed command line, and that
+the note names gemini and the mode.
**Gemini does NOT inherit claude's `auto` version gate.** That gate exists because Claude Code
< 2.1.71 *exits 1* on `--permission-mode auto`, and it is fed by a `claude --version` probe (local, or
@@ -265,9 +278,14 @@ reason. **An agent needing its own gate adds one beside claude's.**
JSON (`settings.json` / `project.json`) and end up interpolated into a shell command line (tmux
`send-keys`), so the mode is **re-validated at the interpolation site** — `isPermissionMode` at the
top of `approvalFlags`, mirroring `permissionModeFlag`. The type proves nothing. Without that guard a
-forged `constructor` satisfies `mode in table` on a plain object and hands back a **Function**, which
-would have been stringified onto the `send-keys` line. An unrecognized mode yields the bare, safe
-command.
+forged `constructor` indexes a plain-object table and hands back a **Function**, which would have been
+stringified onto the `send-keys` line. An unrecognized mode yields the bare, safe command. The same
+hole exists on the **agent id** (`AgentId` is open — custom agents carry user-typed ids), which is why
+`dialectFor` looks its record up through `Object.hasOwn` too, and why flag + vocabulary are ONE record
+per agent (`APPROVAL_DIALECTS`): the previous shape was a `tableFor` ternary plus a `flagFor` ternary
+whose `else` branch was codex's flag, so a third agent added to the table and forgotten in the flag
+would have emitted `--ask-for-approval <a gemini-style value>` — a failed launch from an edit that
+looks complete.
`--sandbox` is deliberately untouched: it is a separate axis, and folding it in would widen
filesystem access invisibly.
@@ -387,8 +405,11 @@ one stray keystroke.
Self-healing, and still strictly better than the pre-branch stuck RUNNING, but gemini has no idle
rescue notification the way grok might. Measure it: deny a tool live and watch whether the badge
clears (§9 item 5).
-2. **`auto` and `acceptEdits` are indistinguishable at launch** (§5) and the derived UI copy cannot
- say so. Not a mapping bug — a missing vocabulary in `unsupportedModesNote()`.
+2. **`auto` and `manual` are indistinguishable at launch** (§5): gemini has no value for `auto`, so
+ both emit no flag and land on gemini's own prompting `default`. Closed as far as honesty goes —
+ `modeSupported` is false and the derived copy says so — but the dropdown still offers two entries
+ that do the same thing on gemini. Only a gemini-side "approve non-edit tools" value could
+ separate them.
3. **The resumed-transcript title path is composed, not captured** (§6). Fail-safe by construction:
wrong ⇒ `null`, never a wrong name. Closing it needs one real resumed transcript.
4. **A remote (SSH) gemini node has no meter and no title.** The tails deliberately never track a
@@ -462,8 +483,10 @@ Title
Modes + restart
13. Launch each mode from Settings → Agents and confirm the emitted flag: manual ⇒ NO flag,
- auto and acceptEdits ⇒ auto_edit (both — this is the documented collapse), plan ⇒ plan,
- bypassPermissions ⇒ yolo. Check a session really STARTS in it, not just that the flag parses.
+ **auto ⇒ NO flag** (§5 — the one that matters, since `auto` is the default: a gemini session
+ started with the setting untouched must PROMPT before an edit, not auto-approve it),
+ acceptEdits ⇒ auto_edit, plan ⇒ plan, bypassPermissions ⇒ yolo. Check a session really STARTS in
+ it, not just that the flag parses.
14. On a machine with NO claude installed, does an `auto` gemini launch still carry its flag?
(claude's version gate must not touch gemini.)
15. "Restart agent (resume)" on an idle gemini node: does it /quit, wait for the shell, and resume
diff --git a/src/shared/agents/approval-mode.test.ts b/src/shared/agents/approval-mode.test.ts
index 17e963dfc..c749816fb 100644
--- a/src/shared/agents/approval-mode.test.ts
+++ b/src/shared/agents/approval-mode.test.ts
@@ -5,7 +5,8 @@ import {
modeSupported,
permissionModeAgentIds,
permissionModeAgentsLabel,
- unsupportedModesNote
+ unsupportedModesNote,
+ withPermissionMode
} from './approval-mode'
import {
ALL_PERMISSION_MODES,
@@ -33,12 +34,36 @@ describe('approvalFlags — gemini', () => {
expect(approvalFlags('gemini', 'plan')).toEqual(['--approval-mode', 'plan'])
expect(approvalFlags('gemini', 'acceptEdits')).toEqual(['--approval-mode', 'auto_edit'])
expect(approvalFlags('gemini', 'bypassPermissions')).toEqual(['--approval-mode', 'yolo'])
- // gemini has no all-tools-but-not-yolo mode; auto_edit is the nearest and is documented as such.
- expect(approvalFlags('gemini', 'auto')).toEqual(['--approval-mode', 'auto_edit'])
})
- it('supports all five', () => {
- for (const m of ALL_PERMISSION_MODES) expect(modeSupported('gemini', m), m).toBe(true)
+ /**
+ * The one that matters most, because `auto` is `DEFAULT_PERMISSION_MODE`: it decides what an
+ * UNTOUCHED install launches gemini with.
+ *
+ * gemini's vocabulary is `default|auto_edit|yolo|plan` and none of those means "approve most
+ * things but not edits". The nearest, `auto_edit`, is "auto-approve edit tools" — the opposite end
+ * of the axis our `auto` is about. Mapping it would have turned every existing gemini node into an
+ * auto-approve-edits session on upgrade, silently: gemini launched BARE before it joined
+ * PERMISSION_MODE_CAPABLE (bare = gemini's `default` = prompt for approval), and `modeSupported`
+ * would have said `true`, so the derived copy would not have admitted it either.
+ */
+ it('emits NO flag for `auto`, the default mode, rather than auto-approving edits', () => {
+ expect(approvalFlags('gemini', 'auto')).toEqual([])
+ expect(modeSupported('gemini', 'auto')).toBe(false)
+ // Same command line gemini launched with before it joined the capable list.
+ expect(withPermissionMode('gemini', 'gemini', 'auto')).toBe('gemini')
+ // ...and it must not quietly become the acceptEdits value.
+ expect(approvalFlags('gemini', 'auto')).not.toEqual(approvalFlags('gemini', 'acceptEdits'))
+ // The derived copy has to say so, naming gemini and the mode.
+ const note = unsupportedModesNote()
+ expect(note).toContain('Gemini')
+ expect(note).toContain(PERMISSION_MODE_LABELS.auto)
+ expect(note).toContain("Gemini sessions start in Gemini's own default")
+ })
+
+ it('supports the four gemini has a value for', () => {
+ for (const m of ALL_PERMISSION_MODES)
+ expect(modeSupported('gemini', m), m).toBe(m !== 'auto')
})
it('only ever emits a value gemini --help lists', () => {
@@ -153,15 +178,17 @@ describe('UI copy derived from the mapping', () => {
expect(caveat).not.toContain('Claude')
})
- it('admits codex’s two gaps, and names no agent that has none', () => {
+ it('admits each gap once, with number agreement, and names no agent that has none', () => {
const note = unsupportedModesNote()
- expect(note).toContain('Plan')
- expect(note).toContain('Accept edits')
- expect(note).toContain('Codex')
- // Number agreement: "Codex sessions start in Codex's own default", never "in its own default".
+ // codex: two gaps → plural verb.
+ expect(note).toContain('Accept edits and Plan have no Codex equivalent')
+ // gemini: one gap → singular verb. Both sentences in one string, one per agent.
+ expect(note).toContain('Auto has no Gemini equivalent')
+ // Number agreement on the possessive too: "Codex sessions start in Codex's own default",
+ // never "in its own default".
expect(note).toContain("Codex's own default")
- // gemini expresses all five, so it must never appear in a sentence about missing modes.
- expect(note).not.toContain('Gemini')
+ expect(note).toContain("Gemini's own default")
+ // claude and grok express all five, so neither may appear in a sentence about missing modes.
expect(note).not.toContain('Claude Code')
expect(note).not.toContain('Grok')
})
diff --git a/src/shared/agents/approval-mode.ts b/src/shared/agents/approval-mode.ts
index 7cd27c350..d48f12af4 100644
--- a/src/shared/agents/approval-mode.ts
+++ b/src/shared/agents/approval-mode.ts
@@ -1,10 +1,11 @@
// Per-agent translation of nodeterm's permission mode into the agent's own approval flag.
//
// claude and grok share one spelling and one vocabulary, which is why they needed no mapping at all
-// until now. gemini and codex each have their own — and codex's is NARROWER than ours, which is the
-// interesting case: our five modes do not fit `untrusted|on-request|never`, so the modes codex
-// cannot express emit NO flag (its own default) rather than a nearest match. A silent substitution
-// would show the user "Plan" while codex ran in on-request.
+// until now. gemini and codex each have their own, and BOTH are narrower than ours — which is the
+// interesting case: our five modes fit neither `default|auto_edit|yolo|plan` nor
+// `untrusted|on-request|never`, so a mode the CLI cannot express emits NO flag (its own default)
+// rather than a nearest match. A silent substitution would show the user "Plan" while codex ran in
+// on-request, or "Auto" while gemini auto-approved every file edit.
//
// Measured: `gemini --help` (0.54.4) and `codex --help` (0.146.0). `--sandbox` is deliberately not
// touched: it is a separate axis (read-only | workspace-write | danger-full-access), and folding
@@ -23,14 +24,30 @@ import {
type BuiltinAgentId
} from './config'
+/** One agent's approval dialect: the flag it spells, and the values it accepts. ONE fact per agent —
+ * a flag and a table maintained separately is how a third agent added to the table silently emits
+ * the second agent's flag. */
+interface ApprovalDialect {
+ flag: string
+ modes: Partial<Record<AgentPermissionMode, string>>
+}
+
const GEMINI_MODES: Partial<Record<AgentPermissionMode, string>> = {
plan: 'plan',
acceptEdits: 'auto_edit',
- bypassPermissions: 'yolo',
- // gemini has no "approve everything except the dangerous bits" mode; auto_edit is the nearest,
- // and it is the same direction claude's acceptEdits points.
- auto: 'auto_edit'
+ bypassPermissions: 'yolo'
// `manual` → gemini's own `default`, i.e. NO flag, exactly as it is for claude.
+ //
+ // `auto` is ABSENT ON PURPOSE, and it is the one absence worth explaining, because `auto` is
+ // `DEFAULT_PERMISSION_MODE` — so this decides what an untouched install launches gemini with.
+ // gemini's vocabulary is exactly `default|auto_edit|yolo|plan`; none of those means "approve most
+ // things but NOT edits", which is what our `auto` promises. The nearest value, `auto_edit`, is
+ // documented as "auto-approve edit tools" — the opposite end of the one axis the user cares
+ // about. Mapping `auto → auto_edit` would therefore have made every existing gemini node start
+ // auto-approving file edits on upgrade, silently: before gemini joined PERMISSION_MODE_CAPABLE it
+ // always launched bare (= `default` = prompt for approval), and `modeSupported` would have
+ // answered `true`, so the derived copy would not have admitted it either. No flag is the honest
+ // answer and reproduces the pre-branch launch exactly. See `unsupportedModesNote`.
}
const CODEX_MODES: Partial<Record<AgentPermissionMode, string>> = {
@@ -52,11 +69,24 @@ const CODEX_MODES: Partial<Record<AgentPermissionMode, string>> = {
// absent ON PURPOSE — see modeSupported.
}
-const tableFor = (agentId: AgentId): Partial<Record<AgentPermissionMode, string>> | null =>
- agentId === 'gemini' ? GEMINI_MODES : agentId === 'codex' ? CODEX_MODES : null
+/**
+ * The agents that need a translation, flag and vocabulary together.
+ *
+ * These two used to be separate lookups — a `tableFor` ternary and a `flagFor` ternary whose `else`
+ * branch was codex's flag. A third agent added to the table and forgotten in the flag would then
+ * have emitted `--ask-for-approval <its own value>`: a wrong flag carrying a right value, i.e. a
+ * failed launch, from an edit that looks complete. One record makes that impossible to express.
+ *
+ * Looked up through `Object.hasOwn`, not `[agentId]`: `AgentId` is OPEN (custom agents carry
+ * user-typed ids), so a plain-object index answers `'constructor'` with a Function.
+ */
+const APPROVAL_DIALECTS: Partial<Record<AgentId, ApprovalDialect>> = {
+ gemini: { flag: '--approval-mode', modes: GEMINI_MODES },
+ codex: { flag: '--ask-for-approval', modes: CODEX_MODES }
+}
-const flagFor = (agentId: AgentId): string =>
- agentId === 'gemini' ? '--approval-mode' : '--ask-for-approval'
+const dialectFor = (agentId: AgentId): ApprovalDialect | null =>
+ Object.hasOwn(APPROVAL_DIALECTS, agentId) ? APPROVAL_DIALECTS[agentId] ?? null : null
/** Can this agent actually start in this mode? `false` means the launch omits the flag and the
* agent uses its own default — surfaced in the UI so the user is not misled. */
@@ -68,8 +98,8 @@ export function modeSupported(agentId: AgentId, mode: AgentPermissionMode): bool
// default does not. Either way the promise holds; an agent whose CLI could offer neither would
// need this early return revisited.
if (mode === 'manual') return hasPermissionMode(agentId)
- const table = tableFor(agentId)
- if (table) return mode in table
+ const dialect = dialectFor(agentId)
+ if (dialect) return Object.hasOwn(dialect.modes, mode)
return hasPermissionMode(agentId)
}
@@ -79,15 +109,15 @@ export function modeSupported(agentId: AgentId, mode: AgentPermissionMode): bool
* The mode is re-validated at the top for the same reason `permissionModeFlag` does it: the value
* comes from hand-editable, git-shared JSON (settings.json / project.json) and is interpolated into
* a shell command line, so its TYPE proves nothing. Without the guard, a forged `constructor`
- * satisfies `mode in table` on a plain object and hands back a Function — one that would have been
- * stringified onto a tmux `send-keys` line.
+ * indexes a plain-object table and hands back a Function — one that would have been stringified
+ * onto a tmux `send-keys` line. (`dialectFor` closes the same hole on the agent id.)
*/
export function approvalFlags(agentId: AgentId, mode: AgentPermissionMode): string[] {
if (!isPermissionMode(mode)) return []
- const table = tableFor(agentId)
- if (table) {
- const value = table[mode]
- return value ? [flagFor(agentId), value] : []
+ const dialect = dialectFor(agentId)
+ if (dialect) {
+ const value = dialect.modes[mode]
+ return value ? [dialect.flag, value] : []
}
// claude + grok keep their exact historical spelling, validated at the interpolation site.
return hasPermissionMode(agentId) ? permissionModeFlag(mode) : []
diff --git a/src/shared/agents/config.ts b/src/shared/agents/config.ts
index b83b16c5f..c54c3e1e6 100644
--- a/src/shared/agents/config.ts
+++ b/src/shared/agents/config.ts
@@ -151,10 +151,13 @@ export const CANVAS_CONTROL_CAPABLE = ['claude', 'codex', 'gemini', 'opencode',
// (`--ask-for-approval untrusted|on-request|never`) each spell it their own way, so membership here
// is only half the story — the translation lives in ./approval-mode.ts.
//
-// Membership does NOT mean every mode applies: codex's vocabulary is NARROWER than ours (no plan,
-// no edit-specific mode), and those modes emit NO flag rather than a substituted nearest match.
+// Membership does NOT mean every mode applies: BOTH new vocabularies are narrower than ours — codex
+// has no plan and no edit-specific mode, and gemini has nothing meaning "approve most things but not
+// edits", i.e. no `auto`. Those modes emit NO flag rather than a substituted nearest match.
// `modeSupported` is what the UI asks so the user is told, instead of being shown "Plan" while
-// codex runs in on-request.
+// codex runs in on-request, or "Auto" while gemini auto-approves every edit. That last one is not
+// hypothetical: `auto` is DEFAULT_PERMISSION_MODE, so mapping it to gemini's `auto_edit` would have
+// switched auto-approve-edits on for every existing gemini node at upgrade time, silently.
//
// NOTE: the `auto` VERSION GATE is claude's alone — see activePermissionMode in
// renderer/state/permissionMode.ts. grok has accepted every mode we emit since 1.0.0, its first