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.

feat(codex): the per-node account picker for new Codex nodes

Claude Code8e933062a325
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 48fdfa23d..4947404f4 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -405,6 +405,10 @@ import {
ungroupNodes,
type CanvasNode
} from '../state/workspace'
+import { codexAccountSelectable } from './codex-account-switch'
+import { resolveNewCodexNodeAccount } from './codex-account-ops'
+import type { CodexAccount } from '@shared/codex-account'
+import { useSystemCodexAccount } from '../state/systemCodexAccount'
import { toKanbanSession } from './toKanbanSession'
const isMac = /Mac/i.test(navigator.platform || navigator.userAgent)
@@ -3548,6 +3552,18 @@ export function Canvas() {
// the "System account" entry with it.
useEffect(() => useSystemAccount.getState().ensure(), [])
+ // The connected SSH project whose host owns a remote account, or undefined when no matching
+ // project is currently connected (live ControlMaster in useSshConn). The fail-closed Codex
+ // account gates (`codexAccountSelectable`) refuse a remote account without one, so it can never
+ // run against the LOCAL login. Mirrors AccountsSection's helper of the same name.
+ const connectedProjectIdForHost = useCallback((host?: string): string | undefined => {
+ if (!host) return undefined
+ const conn = useSshConn.getState().byProject
+ return useProjects
+ .getState()
+ .projects.find((p) => p.ssh && sshHostKey(p.ssh.server) === host && conn[p.id])?.id
+ }, [])
+
const addAgentNode = useCallback(
(
agentId: AgentId,
@@ -3558,13 +3574,37 @@ export function Canvas() {
) => {
const project = useProjects.getState().getProject(activeProjectId)
const cwd = cwdForNewNodeIn(groupId) ?? project?.cwd
- // Funnel through resolveNewNodeAccount so the project default applies even without an
- // explicit pick. The factory drops the account for non-claude agents.
- const account = resolveNewNodeAccount(
- accountId,
- project,
- useSettings.getState().settings.claudeAccounts
- )
+ // Codex accounts (S6) resolve through their OWN fail-closed gate: an explicitly picked account
+ // that is missing/hostile/unconnected is REFUSED here rather than silently downgraded to the
+ // system login (Property 4). Claude keeps its project-default-aware resolver. The factory
+ // stamps the id only for the claude/codex builtins.
+ let account: string | undefined
+ if (agentId === 'codex') {
+ const decision = resolveNewCodexNodeAccount(
+ accountId,
+ useSettings.getState().settings.codexAccounts,
+ connectedProjectIdForHost
+ )
+ if (!decision.create) {
+ setNotice({
+ kind: 'error',
+ text:
+ decision.reason === 'no-connection'
+ ? 'That Codex account lives on a host that is not connected — connect its SSH project first.'
+ : 'That Codex account is no longer available. Nothing was created.'
+ })
+ return
+ }
+ account = decision.accountId
+ } else {
+ // Funnel through resolveNewNodeAccount so the project default applies even without an
+ // explicit pick. The factory drops the account for non-claude agents.
+ account = resolveNewNodeAccount(
+ accountId,
+ project,
+ useSettings.getState().settings.claudeAccounts
+ )
+ }
setNodes((ns) => {
const node = createAgentNode(
agentId,
@@ -3580,7 +3620,15 @@ export function Canvas() {
})
markDirty()
},
- [setNodes, markDirty, activeProjectId, emptyNodePos, cwdForNewNodeIn, parentInto]
+ [
+ setNodes,
+ markDirty,
+ activeProjectId,
+ emptyNodePos,
+ cwdForNewNodeIn,
+ parentInto,
+ connectedProjectIdForHost
+ ]
)
// "Spawn a team…" (issue #78): the dialog collects the task; this opens ONE conductor node
@@ -5708,6 +5756,18 @@ export function Canvas() {
// where this host's accounts come from — local accounts are correctly invisible here, and
// a bare flat entry read as "multi-account is broken on SSH".
const accountsHint = sshAccountsHint(project, accounts)
+ // Codex accounts (S6 §3.4): the accounts belonging to THIS project's machine — local accounts
+ // for a local project, this host's accounts for an SSH project — mirroring accountsForProject.
+ const codexHostKey = project?.ssh ? sshHostKey(project.ssh.server) : undefined
+ const codexAccountsHere = useSettings
+ .getState()
+ .settings.codexAccounts.filter(
+ (a) => !a.pending && (codexHostKey ? a.host === codexHostKey : !a.host)
+ )
+ const codexSystemLabel = systemAccountDisplay(
+ undefined,
+ useSystemCodexAccount.getState().email
+ )
return [
...BUILTIN_AGENT_IDS.filter((aid) => !disabled.includes(aid)).map((aid): MenuItem => {
// Claude gets an account picker submenu when ≥1 account exists; System = project
@@ -5743,6 +5803,42 @@ export function Canvas() {
]
}
}
+ // Codex gets its own account picker submenu when ≥1 managed account lives on this
+ // project's machine (S6 §3.4). Every managed row is gated through `codexAccountSelectable`
+ // — a missing/hostile/unconnected account renders DISABLED, so the fail-closed refusal is
+ // enforced before the click, and again in `addAgentNode` (the UI is not the boundary).
+ if (aid === 'codex' && codexAccountsHere.length > 0) {
+ return {
+ type: 'submenu',
+ label: `New ${AGENT_CONFIG[aid].label}`,
+ icon: <AgentIcon agentId={aid} />,
+ children: [
+ {
+ label: codexSystemLabel,
+ icon: <AgentIcon agentId="codex" />,
+ onClick: () => addAgentNode('codex', at, groupId)
+ },
+ ...codexAccountsHere.map((a): MenuItem => {
+ const sel = codexAccountSelectable(
+ a.id,
+ codexAccountsHere,
+ connectedProjectIdForHost
+ )
+ return {
+ label: a.label,
+ icon: <AgentIcon agentId="codex" />,
+ disabled: !sel.ok,
+ hint: sel.ok
+ ? undefined
+ : sel.reason === 'no-connection'
+ ? 'This account lives on a host that is not connected — connect its SSH project first.'
+ : 'This account is no longer available.',
+ onClick: () => addAgentNode('codex', at, groupId, a.id)
+ }
+ })
+ ]
+ }
+ }
return {
label: `New ${AGENT_CONFIG[aid].label}`,
icon: <AgentIcon agentId={aid} />,
@@ -5761,7 +5857,7 @@ export function Canvas() {
)
]
},
- [addAgentNode]
+ [addAgentNode, connectedProjectIdForHost]
)
const groupItems = useCallback(
diff --git a/src/renderer/canvas/codex-account-ops.test.ts b/src/renderer/canvas/codex-account-ops.test.ts
new file mode 100644
index 000000000..dcdced996
--- /dev/null
+++ b/src/renderer/canvas/codex-account-ops.test.ts
@@ -0,0 +1,54 @@
+import { describe, expect, it } from 'vitest'
+import type { CodexAccount } from '@shared/codex-account'
+import { resolveNewCodexNodeAccount } from './codex-account-ops'
+
+const local: CodexAccount = { id: 'account-a', label: 'Work' }
+const remote: CodexAccount = { id: 'account-r', label: 'Box', host: 'u@box' }
+const accounts = [local, remote]
+const connected = (host: string): string | undefined => (host === 'u@box' ? 'proj-1' : undefined)
+const noConnection = (): undefined => undefined
+
+describe('resolveNewCodexNodeAccount (fail-closed New Codex picker — §3.4 / Property 4)', () => {
+ it('creates on the system account when nothing is picked', () => {
+ expect(resolveNewCodexNodeAccount(undefined, accounts, noConnection)).toEqual({
+ create: true,
+ accountId: undefined
+ })
+ expect(resolveNewCodexNodeAccount('', accounts, noConnection)).toEqual({
+ create: true,
+ accountId: undefined
+ })
+ })
+
+ it('creates on a present local managed account', () => {
+ expect(resolveNewCodexNodeAccount('account-a', accounts, noConnection)).toEqual({
+ create: true,
+ accountId: 'account-a'
+ })
+ })
+
+ it('REFUSES an explicitly picked MISSING account — no silent substitution to system', () => {
+ // MUTATION PIN: if a refused selection fell back to `{ create: true, accountId: undefined }`
+ // (the system login) instead of refusing, this goes green — a missing pick would silently bind
+ // the system account. Must stay red.
+ expect(resolveNewCodexNodeAccount('account-gone', accounts, connected)).toEqual({
+ create: false,
+ reason: 'unavailable'
+ })
+ })
+
+ it('REFUSES a hostile (path-escaping) id even when a matching row is present', () => {
+ const hostile: CodexAccount = { id: '../escape', label: 'evil' }
+ expect(resolveNewCodexNodeAccount('../escape', [...accounts, hostile], connected)).toEqual({
+ create: false,
+ reason: 'unavailable'
+ })
+ })
+
+ it('REFUSES a remote account whose host is not connected — never binds it locally', () => {
+ expect(resolveNewCodexNodeAccount('account-r', accounts, noConnection)).toEqual({
+ create: false,
+ reason: 'no-connection'
+ })
+ })
+})
diff --git a/src/renderer/canvas/codex-account-ops.ts b/src/renderer/canvas/codex-account-ops.ts
new file mode 100644
index 000000000..2d7da9e73
--- /dev/null
+++ b/src/renderer/canvas/codex-account-ops.ts
@@ -0,0 +1,37 @@
+// S6 PR 8.5 — the two USER-FACING trigger surfaces for machine-scoped Codex accounts, wired on top
+// of PR 8's fail-closed guards (`codex-account-switch.ts`). NOTHING here is the security boundary:
+// owner-authorization and the atomic exposure live MAIN-SIDE (PR 5's three-phase switch), and the
+// account-validity gate is `codexAccountSelectable`. These pure decisions are the renderer's own
+// fail-closed refusals so the two UI surfaces can never ORIGINATE an unauthorized or fail-open op:
+// 1. `resolveNewCodexNodeAccount` — the "New Codex node" account picker (§3.4). An explicitly
+// picked account that is MISSING / hostile / unconnected is REFUSED, never silently swapped for
+// the system login.
+
+import type { CodexAccount } from '@shared/codex-account'
+import { codexAccountSelectable } from './codex-account-switch'
+
+/** The picker's verdict for a NEW Codex node. `create: false` carries the same fail-closed reason
+ * `codexAccountSelectable` produced — the node is NOT created, and never with another account. */
+export type CodexCreateDecision =
+ | { create: true; accountId: string | undefined }
+ | { create: false; reason: 'unavailable' | 'no-connection' }
+
+/**
+ * Fail-closed account resolution for a NEW Codex node (surface §3.4). An empty/undefined selection
+ * is the SYSTEM account (`~/.codex`), always creatable. Any explicit id is routed through
+ * `codexAccountSelectable`; a missing, hostile, or (remote) unconnected pick is REFUSED — the caller
+ * must NOT fall back to the system login or any other account (Property 4, Decision 2).
+ */
+export function resolveNewCodexNodeAccount(
+ explicit: string | undefined,
+ accounts: readonly CodexAccount[],
+ connectedProjectIdForHost: (host: string) => string | undefined
+): CodexCreateDecision {
+ // The system account (no id) always lives on this machine — nothing to miss, nothing to connect.
+ if (!explicit) return { create: true, accountId: undefined }
+ const selectable = codexAccountSelectable(explicit, accounts, connectedProjectIdForHost)
+ // A refused selection is NEVER downgraded to the system account — that silent substitution is the
+ // exact fail-open Property 4 forbids. Refuse the creation and let the UI say why.
+ if (!selectable.ok) return { create: false, reason: selectable.reason }
+ return { create: true, accountId: explicit }
+}
diff --git a/src/renderer/state/workspace.test.ts b/src/renderer/state/workspace.test.ts
index 11b13d31a..d05b25dbb 100644
--- a/src/renderer/state/workspace.test.ts
+++ b/src/renderer/state/workspace.test.ts
@@ -556,8 +556,13 @@ describe('accountId on Claude node factories', () => {
const node = createAgentNode('claude', 0, undefined, undefined, undefined, undefined, 'a1')
expect(node.data.accountId).toBe('a1')
})
- it('does not stamp accountId onto a non-Claude agent node', () => {
+ it('stamps accountId onto a Codex agent node (S6 per-node account picker)', () => {
const node = createAgentNode('codex', 0, undefined, undefined, undefined, undefined, 'a1')
+ expect(node.data.accountId).toBe('a1')
+ })
+ it('does not stamp accountId onto a non-account agent node', () => {
+ // Accounts bind to the Claude/Codex builtins only — another agent never carries one.
+ const node = createAgentNode('gemini', 0, undefined, undefined, undefined, undefined, 'a1')
expect(node.data.accountId).toBeUndefined()
})
it('omits accountId when none is given', () => {
diff --git a/src/renderer/state/workspace.ts b/src/renderer/state/workspace.ts
index 0d225ef37..37de9653c 100644
--- a/src/renderer/state/workspace.ts
+++ b/src/renderer/state/workspace.ts
@@ -471,9 +471,12 @@ export function createAgentNode(
group: null,
tags: [],
agentId,
- // Accounts are inherently Claude-only — never stamp one onto another agent's node. A custom
- // agent inheriting claude is still its own agent; account binding stays claude-the-builtin.
- ...(accountId && agentId === 'claude' ? { accountId } : {}),
+ // Managed accounts bind to the builtin Claude and Codex agents (S6) — never to another
+ // builtin, and never to a custom agent even when it inherits one of those bases. A custom
+ // agent inheriting claude/codex is still its own agent; account binding stays with the
+ // builtin the account picker offered it for. The Codex spawn side honours `data.accountId`
+ // (resolveCodexSessionScope), the same field Claude uses.
+ ...(accountId && (agentId === 'claude' || agentId === 'codex') ? { accountId } : {}),
// Persisted alongside the node (unlike initialCommand, which is consumed on first open), so
// a cold restore months later still knows which conversation this node owns.
...(mintedSessionId ? { agentSessionId: mintedSessionId } : {}),