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
fix(codex): review round 1 — pin server arming to production, disclose SE surface
Claude Codea9a42d8c8772
diff --git a/src/main/codex-accounts.switch.test.ts b/src/main/codex-accounts.switch.test.tsindex 0fe73610d..14ec80de0 100644--- a/src/main/codex-accounts.switch.test.ts+++ b/src/main/codex-accounts.switch.test.ts@@ -123,6 +123,29 @@ describe('Codex same-machine switch — three-phase, owner-authorized (Propertieexpect(readThread).toHaveBeenCalled()})+ it('refuses to finish a switch that was never committed (committed-gate, Property 5)', async () => {+ // A reservation is planned but NOT committed (the atomic hardlink never ran). Finishing it would+ // release the reservation as if the copy had succeeded — the renderer then recycles the node+ // onto a target that has no rollout. finishSwitch must refuse until commit ran.+ const owner = makeSender(1)+ const res = (await call(IPC.codexAccountsSwitchThread, owner, THREAD, '/work', SOURCE, TARGET)) as {+ rollbackToken?: string+ }+ // MUTATION: drop `!pending?.committed` in finishSwitch ⇒ this stops throwing ⇒ red.+ expect(() => call(IPC.codexAccountsFinishSwitch, owner, res.rollbackToken)).toThrow(+ /was not committed/+ )+ // The target still has NO rollout — nothing was published by a premature finish.+ const targetPath = path.join(+ codexAccountHome(userDataDir, TARGET),+ 'sessions',+ '2026',+ '08',+ `rollout-${THREAD}.jsonl`+ )+ expect(() => statSync(targetPath)).toThrow()+ })+it('a non-owner WebContents cannot commit or finish the switch', async () => {const owner = makeSender(1)const attacker = makeSender(2)diff --git a/src/main/codex-accounts.test.ts b/src/main/codex-accounts.test.tsindex 8857f2811..b30d1d4f8 100644--- a/src/main/codex-accounts.test.ts+++ b/src/main/codex-accounts.test.ts@@ -26,7 +26,8 @@ vi.mock('../core/codex-session-name', () => ({readCodexAccountAt: (..._a: any[]) => readAccount()}))vi.mock('../core/pty-manager', () => ({ findInLoginPath: vi.fn(async () => null) }))-vi.mock('./codex-relay-daemon', () => ({ ensureCodexRelayRoot: vi.fn() }))+const ensureRelayRoot = vi.fn()+vi.mock('./codex-relay-daemon', () => ({ ensureCodexRelayRoot: ensureRelayRoot }))import { IPC } from '../shared/ipc'import { fakePlatform } from '../core/platform-fake'@@ -39,6 +40,7 @@ const call = (channel: string, ...args: any[]) => h.handlers[channel]({ sender }beforeEach(async () => {h.handlers = {}+ ensureRelayRoot.mockClear()readAccount.mockReset().mockResolvedValue({ email: '[email protected]' })userDataDir = mkdtempSync(path.join(os.tmpdir(), 'nodeterm-codex-acct-'))systemHome = mkdtempSync(path.join(os.tmpdir(), 'nodeterm-codex-sys-'))@@ -61,6 +63,12 @@ afterEach(async () => {})describe('Codex local account lifecycle (Task 5.1)', () => {+ it('ensures the ~/.nodeterm relay root at boot (carried PR-4 obligation)', () => {+ // initCodexAccounts ran in beforeEach; the boot-time call to ensureCodexRelayRoot is asserted+ // here (not just the function itself) so removing the call site would red this.+ expect(ensureRelayRoot).toHaveBeenCalled()+ })+it('add mints a 0700 home and symlinks the shared, non-secret runtime assets', async () => {const { id, home } = (await call(IPC.codexAccountsAdd)) as { id: string; home: string }expect(id).toMatch(/^[0-9a-f-]{36}$/)diff --git a/src/main/codex-accounts.ts b/src/main/codex-accounts.tsindex 1345bf223..301b03a23 100644--- a/src/main/codex-accounts.ts+++ b/src/main/codex-accounts.ts@@ -167,6 +167,25 @@ async function existingManagedIdentity(id: string): Promise<{ email: string | nu}/**+ * THREE SURFACES (global-constraint 5), stated explicitly:+ *+ * - **Desktop (Electron)** — the full feature. This module registers its IPC over `electron`'s+ * `ipcMain`, and owner-authorization keys off `event.sender.id` (a WebContents). `src/main/+ * index.ts` is the ONLY caller.+ * - **Server Edition (headless / an SSH host)** — this IPC surface is deliberately **N/A** here,+ * and PR 5 does NOT wire it. The verbs are `ipcMain.handle` + WebContents-owner semantics, which+ * the headless CorePlatform bridge does not provide, so `startServer` never calls+ * `initCodexAccounts`. This is not a silent gap: managed Codex logins **on an SSH host** are+ * driven by the DESKTOP over SSH / `RemoteHooks` (the remote account-add / device-login / import+ * legs), which is **PR 6's** work — the host runs the relay + import, not its own copy of this+ * IPC. The Server Edition still arms the codex identity *record secret* (src/server/+ * node-identity-arm.ts) so records sign; it just does not host the account-management verbs.+ * **PR 6 obligation:** if the remote leg needs SE-side handlers, PR 6 wires them through the+ * server bridge — PR 5 intentionally left that unbuilt. Nothing in PR 5 assumes an SE IPC+ * surface exists.+ * - **Mobile (phone)** — never originates an add/switch/copy; it drives via relay→IPC and reads+ * state. No mint here.+ ** @param getSshManager Lazily resolves the SSH project manager (created after this init in* index.ts). Only the local→SSH transfer SOURCE leg uses it today; local account ops never do.*/diff --git a/src/server/codex-identity-boot.test.ts b/src/server/codex-identity-boot.test.tsindex 526f56f9f..f6b3df1cf 100644--- a/src/server/codex-identity-boot.test.ts+++ b/src/server/codex-identity-boot.test.ts@@ -5,11 +5,12 @@* ownership record threw "NodeTerm Codex identity authentication is unavailable" the moment it* tried to sign — the record layer was dead on every headless host.*- * The invariant pinned here: run the EXACT boot sequence src/server/index.ts runs after- * `hookServer.start()`, and a managed-account resolve signs + round-trips instead of throwing.- * MUTATION (recorded in the PR body): delete the `setCodexThreadIdentityAuthSecret(secret)` line in- * src/server/index.ts (equivalently, drop it from the boot sequence below) → this suite goes red- * because `writeCodexThreadIdentity` for a managed account throws "unavailable".+ * This drives the REAL production arming function `armServerNodeIdentity` (the exact code+ * `startServer` awaits in its node-identity try block), NOT a re-implementation of the boot+ * sequence — constraint 8 forbids a structural test that would pass the real defect.+ * MUTATION (recorded in the PR body): delete `setCodexThreadIdentityAuthSecret(nodeAuthSecret)` from+ * src/server/node-identity-arm.ts → this suite goes red because `writeCodexThreadIdentity` for a+ * managed account throws "unavailable". (Confirmed: the mutation now REDS the shipped path.)*/import { describe, it, expect, beforeEach, afterEach } from 'vitest'import fs from 'fs'@@ -17,20 +18,28 @@ import os from 'os'import path from 'path'import { initPlatform, resetPlatformForTests } from '../core/platform'import { fakePlatform } from '../core/platform-fake'-import { loadOrCreateNodeAuthSecret, resetNodeAuthSecretForTests } from '../core/agents/node-auth-secret'+import { resetNodeAuthSecretForTests } from '../core/agents/node-auth-secret'import {- setCodexThreadIdentityAuthSecret,resetCodexThreadIdentityAuthSecret,codexThreadIdentityAvailable,writeCodexThreadIdentity,resolveCodexThreadNodeIdentity,codexThreadIdentityRoot} from '../core/codex-identity-proxy'+import { armServerNodeIdentity } from './node-identity-arm'let dir = ''+/** A hook-server stand-in capturing the node secret the real arming hands it. */+const hookServer = {+ received: null as Uint8Array | null,+ setNodeAuthSecret(secret: Uint8Array) {+ this.received = secret+ }+}beforeEach(() => {dir = fs.mkdtempSync(path.join(os.tmpdir(), 'nodeterm-server-codex-ident-'))+ hookServer.received = nullresetPlatformForTests()resetNodeAuthSecretForTests()resetCodexThreadIdentityAuthSecret()@@ -46,17 +55,18 @@ afterEach(() => {})describe('Server Edition arms the Codex identity secret on boot', () => {- it('a managed-account record signs + resolves after the boot sequence, instead of throwing unavailable', async () => {+ it('a managed-account record signs + resolves after the REAL boot arming, instead of throwing unavailable', async () => {// Before arming: the record layer is dead.expect(codexThreadIdentityAvailable()).toBe(false)expect(() =>writeCodexThreadIdentity('thread-a', 'node-1', '/hook', undefined, 'managed-account')).toThrow(/identity authentication is unavailable/)- // The EXACT boot sequence src/server/index.ts runs after hookServer.start().- const secret = await loadOrCreateNodeAuthSecret()- setCodexThreadIdentityAuthSecret(secret)+ // Drive the REAL production arming `startServer` runs (no persisted canvases needed here).+ await armServerNodeIdentity(hookServer, () => [])+ // The node secret was armed too (both legs of the shipped function ran).+ expect(hookServer.received?.byteLength).toBe(32)expect(codexThreadIdentityAvailable()).toBe(true)// A MANAGED account (non-empty accountId) — the case that threw on a headless host — now signsdiff --git a/src/server/index.ts b/src/server/index.tsindex 6eebc1997..ff0eee5ea 100644--- a/src/server/index.ts+++ b/src/server/index.ts@@ -37,9 +37,8 @@ import { registerLogHandlers } from '../core/log-handlers'import os from 'os'import { hookServer } from '../core/agents/hook-server'import { serverEditionControlHandler } from './control-unsupported'-import { loadOrCreateNodeAuthSecret } from '../core/agents/node-auth-secret'-import { setCodexThreadIdentityAuthSecret } from '../core/codex-identity-proxy'-import { initNodeTokens, refreshNodeTokens } from '../core/agents/node-token-service'+import { refreshNodeTokens } from '../core/agents/node-token-service'+import { armServerNodeIdentity } from './node-identity-arm'import {writePendingAnswerLocal,startPendingSweep,@@ -477,20 +476,12 @@ export async function startServer(// arming the secret, and a headless host in legacy mode is where it is most likely to be needed.hookServer.setIdentityStrictOverride(() => settingsStore.get().hookIdentityStrict)try {- const nodeAuthSecret = await loadOrCreateNodeAuthSecret()- hookServer.setNodeAuthSecret(nodeAuthSecret)- // S6 (Decision 1, carried from PR 2 review): arm the SAME secret for the Codex thread→node→- // account identity records so a MANAGED Codex account on a headless host can sign/verify its- // ownership records instead of throwing "identity authentication is unavailable". This is the- // both-shells half of the secret: desktop arms it in src/main/index.ts, and the Server Edition- // — which runs the managed-account + relay + switch protocol just as the desktop does — must- // arm it here too, or every managed-account resolve throws. The shared-app-server DEGRADE- // (Codex nodes launch bare, no launcher on PATH) is a SEPARATE, deliberate scope decision and- // is unaffected: this only makes the record layer able to sign.- setCodexThreadIdentityAuthSecret(nodeAuthSecret)- // Materialise a token file for every persisted node so an already-running session becomes- // verified at its next hook event with no restart. No-ops into legacy mode without a secret.- initNodeTokens({ canvases: () => workspaceStore.persistedCanvases() })+ // The whole node-identity arming (node secret + the S6 Codex record secret + node tokens) lives+ // in one REAL production function so the boot test can drive the shipped path rather than a+ // re-implementation of it (constraint 8). It arms `setCodexThreadIdentityAuthSecret` with the+ // same secret so a MANAGED Codex account on a headless host signs/verifies its ownership records+ // instead of throwing "identity authentication is unavailable" (Decision 1, both-shells).+ await armServerNodeIdentity(hookServer, () => workspaceStore.persistedCanvases())} catch (error) {console.warn('[node-identity] no secret — hook identity unavailable, running legacy', error)}diff --git a/src/server/node-identity-arm.ts b/src/server/node-identity-arm.tsnew file mode 100644index 000000000..87993f2d0--- /dev/null+++ b/src/server/node-identity-arm.ts@@ -0,0 +1,32 @@+// The Server Edition's boot-time node-identity arming, extracted from `startServer` so it is REAL+// production code a test can drive directly (constraint 8: the pin must exercise the shipped path,+// not a re-implementation of it). Headless Linux has no OS keychain, so the secret is raw 0600 bytes+// (node-auth-key.bin); the loader handles the at-rest format. Fail-open/loud is the CALLER's job —+// this throws if the secret can't be loaded, and `startServer` catches it into legacy mode.+import { loadOrCreateNodeAuthSecret } from '../core/agents/node-auth-secret'+import { setCodexThreadIdentityAuthSecret } from '../core/codex-identity-proxy'+import { initNodeTokens } from '../core/agents/node-token-service'++type Canvases = Parameters<typeof initNodeTokens>[0]['canvases']++/**+ * Arm node identity for the Server Edition: load/create the raw node-auth secret, hand it to the+ * hook server, arm the Codex thread→node→account record secret with the SAME secret (S6 Decision 1,+ * the both-shells half — desktop arms its twin in src/main/index.ts), and materialise a token file+ * for every persisted node. `startServer` awaits this inside its fail-open try; the codex boot test+ * drives this exact function so deleting the codex arming below REDS the pin.+ */+export async function armServerNodeIdentity(+ hookServer: { setNodeAuthSecret(secret: Uint8Array): void },+ canvases: Canvases+): Promise<void> {+ const nodeAuthSecret = await loadOrCreateNodeAuthSecret()+ hookServer.setNodeAuthSecret(nodeAuthSecret)+ // Managed Codex accounts on a headless host can then sign/verify their ownership records instead+ // of throwing "identity authentication is unavailable". Orthogonal to the shared-app-server+ // degrade (Codex nodes still launch bare here); this only makes the record layer able to sign.+ setCodexThreadIdentityAuthSecret(nodeAuthSecret)+ // Already-running sessions become verified at their next hook event with no restart. No-ops into+ // legacy mode without a secret.+ initNodeTokens({ canvases })+}