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): machine-grouped accounts UI in settings

Claude Code95cf6a1c5fa3
diff --git a/src/main/codex-accounts.ts b/src/main/codex-accounts.ts
index 301b03a23..aa462cee4 100644
--- a/src/main/codex-accounts.ts
+++ b/src/main/codex-accounts.ts
@@ -238,7 +238,15 @@ export function initCodexAccounts(getSshManager?: () => SshProjectManager | unde
ipcMain.handle(IPC.codexAccountsIdentity, (_event, id: string) => existingManagedIdentity(id))
- ipcMain.handle(IPC.codexAccountsSystemIdentity, () => accountIdentity())
+ // No ctx ⇒ this Mac's system identity. A `{ projectId }` ctx asks for a remote HOST's system
+ // identity, which this build does not yet resolve — fail closed to `null` rather than returning
+ // THIS Mac's login, so a remote machine panel never fabricates/borrows a local identity
+ // (§5 "system-account discovery must not fabricate an account"). Remote resolution is a follow-up.
+ ipcMain.handle(
+ IPC.codexAccountsSystemIdentity,
+ (_event, ctx?: { projectId?: string }) =>
+ ctx?.projectId ? Promise.resolve(null) : accountIdentity()
+ )
ipcMain.handle(IPC.codexAccountsRemove, async (_event, id: string) => {
assertCodexAccountId(id)
diff --git a/src/preload/index.ts b/src/preload/index.ts
index ed6b64313..591d7ec63 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -473,7 +473,7 @@ const api: NodeTerminalApi = {
waitLogin: (id) => ipcRenderer.invoke(IPC.codexAccountsWaitLogin, id),
cancelWaitLogin: (id) => ipcRenderer.invoke(IPC.codexAccountsCancelWait, id),
identity: (id) => ipcRenderer.invoke(IPC.codexAccountsIdentity, id),
- systemIdentity: () => ipcRenderer.invoke(IPC.codexAccountsSystemIdentity),
+ systemIdentity: (ctx) => ipcRenderer.invoke(IPC.codexAccountsSystemIdentity, ctx),
remove: (id) => ipcRenderer.invoke(IPC.codexAccountsRemove, id),
switchThread: (threadId, cwd, sourceAccountId, targetAccountId) =>
ipcRenderer.invoke(
diff --git a/src/renderer/components/settings/sections/AccountsSection.tsx b/src/renderer/components/settings/sections/AccountsSection.tsx
index 0401c4fb9..aa2d2983a 100644
--- a/src/renderer/components/settings/sections/AccountsSection.tsx
+++ b/src/renderer/components/settings/sections/AccountsSection.tsx
@@ -1,11 +1,25 @@
import { useEffect, useState } from 'react'
import type { ClaudeAccount } from '@shared/types'
+import type { CodexAccount } from '@shared/codex-account'
import { sshHostKey } from '@shared/ssh'
import { useSettings } from '../../../state/settings'
import { useSystemAccount } from '../../../state/systemAccount'
+import { useSystemCodexAccount } from '../../../state/systemCodexAccount'
import { isAccountLoginNode } from '../../../state/workspace'
import { useProjects } from '../../../state/projects'
import { useSshConn } from '../../../state/sshConn'
+import { useSshServers } from '../../../state/sshServers'
+import {
+ applyResolvedCodexAccounts,
+ discoverResolvedCodexAccounts
+} from '../../../state/codexAccountReconcile'
+import {
+ codexRemoteTargets,
+ groupCodexAccountsByMachine,
+ strayCodexAccounts
+} from '../../../lib/codexMachineGroups'
+import { presentAccount } from '../../../lib/accountPresentation'
+import { AccountIdentityPills } from '../../AccountIdentityPills'
import { ConfirmDialog } from '../../ConfirmDialog'
import { SettingsSection } from '../SettingsSection'
import { SearchableRow } from '../SearchableRow'
@@ -16,10 +30,50 @@ const ROWS = {
accounts: {
title: 'Claude accounts',
keywords: ['account', 'claude', 'login', 'isolated', 'multi', 'email']
+ },
+ codex: {
+ title: 'Codex accounts',
+ keywords: ['account', 'codex', 'openai', 'login', 'isolated', 'multi', 'email', 'machine', 'ssh']
}
}
const ENTRIES = Object.values(ROWS)
+/** One machine's card in the accounts UI: a connectivity dot, the machine label, a Local/SSH pill,
+ * and (for a remote machine) its `user@host` subtitle. Children are the provider account rows. */
+function MachinePanel({
+ label,
+ remote,
+ hostKey,
+ connected,
+ children
+}: {
+ label: string
+ remote: boolean
+ hostKey?: string
+ connected?: boolean
+ children: React.ReactNode
+}): React.JSX.Element {
+ return (
+ <div className="space-y-3 rounded-md border border-border p-3">
+ <div className="flex items-center gap-2">
+ <span
+ className={`inline-block h-2 w-2 rounded-full ${
+ !remote || connected ? 'bg-[color:var(--ok,#30d158)]' : 'bg-[color:var(--muted-2)]'
+ }`}
+ aria-hidden
+ title={!remote ? 'This machine' : connected ? 'Connected' : 'Not connected'}
+ />
+ <span className="text-[13px] font-medium text-text">{label}</span>
+ <span className="rounded-full bg-fill-weak px-2 py-0.5 text-[11px] font-medium text-muted">
+ {remote ? 'SSH' : 'Local'}
+ </span>
+ {remote && hostKey ? <span className="text-[12px] text-muted">{hostKey}</span> : null}
+ </div>
+ {children}
+ </div>
+ )
+}
+
/** `addingOn` sentinel for the local button — a host key can never be this. */
const LOCAL_TARGET = ''
@@ -40,6 +94,12 @@ function applyAccounts(fn: (accs: ClaudeAccount[]) => ClaudeAccount[]): void {
s.update({ claudeAccounts: fn(s.settings.claudeAccounts) })
}
+/** The same fresh-read/transform for the Codex account list. */
+function applyCodexAccounts(fn: (accs: CodexAccount[]) => CodexAccount[]): void {
+ const s = useSettings.getState()
+ s.update({ codexAccounts: fn(s.settings.codexAccounts) })
+}
+
/** Counts nodes bound to an account across every project's SERIALIZED nodes. The active
* project's live React Flow edits since the last commit aren't reflected here, so the count
* can be slightly stale for the active canvas — acceptable for a confirmation warning. */
@@ -95,6 +155,178 @@ export function AccountsSection({ isActive }: { isActive: boolean }): React.JSX.
return id && sshByProject[id] ? id : undefined
}
+ // ── Codex accounts (machine-grouped) ─────────────────────────────────────────────────────────
+ const codexAccounts = useSettings((s) => s.settings.codexAccounts)
+ const sshServers = useSshServers((s) => s.servers)
+ const systemCodexEmail = useSystemCodexAccount((s) => s.email)
+ const remoteSystemCodexEmails = useSystemCodexAccount((s) => s.remoteEmails)
+ useEffect(() => useSystemCodexAccount.getState().ensure(), [])
+ useEffect(() => {
+ void useSshServers.getState().hydrate?.()
+ }, [])
+ const [pendingRemoveCodex, setPendingRemoveCodex] = useState<CodexAccount | null>(null)
+ const [addingCodex, setAddingCodex] = useState(false)
+
+ // The reachable machines: this Mac first, then every saved SSH server unioned with the active
+ // project's own server (deduped by host key). Accounts partition onto them by `host`.
+ const remoteTargets = codexRemoteTargets(sshServers, activeProject?.ssh?.server)
+ const codexGroups = groupCodexAccountsByMachine(codexAccounts, remoteTargets)
+ const codexStrays = strayCodexAccounts(codexAccounts, remoteTargets)
+
+ // Discover the system Codex identity of every CONNECTED remote target, once per host. A host with
+ // no live connection is skipped (and never fabricated — its panel simply shows no system email).
+ useEffect(() => {
+ if (!isActive) return
+ for (const [host] of remoteTargets) {
+ const projectId = connectedProjectIdForHost(host)
+ if (projectId) useSystemCodexAccount.getState().ensureRemote(host, projectId)
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [isActive, remoteTargets.map(([h]) => h).join('|'), sshByProject])
+
+ // Reconcile LOCAL pending Codex accounts against their now-authenticated homes. Remote accounts
+ // are intentionally NOT probed here: `codexAccounts.identity` reads the LOCAL managed home, so
+ // resolving a remote account against it would read the wrong machine. Their reconcile arrives
+ // with the host relay (a follow-up); until then a remote row stays pending, not misattributed.
+ useEffect(() => {
+ if (!isActive) return
+ let cancelled = false
+ let timer: number | undefined
+ const reconcile = async (): Promise<void> => {
+ const localPending = useSettings
+ .getState()
+ .settings.codexAccounts.filter((account) => account.pending && !account.host)
+ if (localPending.length === 0) return
+ const resolved = await discoverResolvedCodexAccounts(localPending, (id) =>
+ window.nodeTerminal.codexAccounts.identity(id)
+ )
+ if (cancelled) return
+ if (resolved.length > 0) {
+ applyCodexAccounts((accs) => applyResolvedCodexAccounts(accs, resolved))
+ }
+ const stillPending = useSettings
+ .getState()
+ .settings.codexAccounts.some((account) => account.pending && !account.host)
+ if (!cancelled && stillPending) timer = window.setTimeout(() => void reconcile(), 2000)
+ }
+ void reconcile()
+ return () => {
+ cancelled = true
+ if (timer) window.clearTimeout(timer)
+ }
+ }, [isActive, codexAccounts])
+
+ const setCodexLabel = (id: string, label: string): void =>
+ applyCodexAccounts((accs) => accs.map((a) => (a.id === id ? { ...a, label } : a)))
+
+ // Add a LOCAL managed Codex account and open its device-login node. Remote Codex account creation
+ // is fail-closed here: the base `codexAccounts.add()` mints on THIS Mac, so offering it under a
+ // remote machine would silently create a local account — the remote leg lands with the host relay.
+ const onAddCodexAccount = async (): Promise<void> => {
+ if (addingCodex) return
+ setAddingCodex(true)
+ try {
+ const added = await window.nodeTerminal.codexAccounts.add()
+ const account: CodexAccount = { id: added.id, label: 'New Codex account', pending: true }
+ applyCodexAccounts((accs) => [...accs, account])
+ window.dispatchEvent(
+ new CustomEvent('nodeterm:add-codex-account-login', { detail: { accountId: added.id } })
+ )
+ const captured = await window.nodeTerminal.codexAccounts.waitLogin(added.id)
+ if (captured) {
+ applyCodexAccounts((accs) =>
+ applyResolvedCodexAccounts(accs, [{ id: added.id, email: captured.email }])
+ )
+ }
+ } finally {
+ setAddingCodex(false)
+ }
+ }
+
+ const confirmRemoveCodex = async (account: CodexAccount): Promise<void> => {
+ setPendingRemoveCodex(null)
+ if (account.pending) await window.nodeTerminal.codexAccounts.cancelWaitLogin(account.id)
+ // A remote account's home lives on its host; the base remove() acts locally only, so a remote
+ // account is dropped from settings without a local fs op it does not own (fail-closed — it never
+ // deletes the wrong machine's home).
+ if (!account.host) await window.nodeTerminal.codexAccounts.remove(account.id)
+ applyCodexAccounts((accs) => accs.filter((a) => a.id !== account.id))
+ useProjects.setState((s) => ({
+ projects: s.projects.map((p) => ({
+ ...p,
+ nodes: p.nodes.map((n) => (n.accountId === account.id ? { ...n, accountId: undefined } : n))
+ }))
+ }))
+ }
+
+ // The presented account for a row, resolving the friendly machine label from saved servers.
+ const presentCodex = (account: CodexAccount) => {
+ const server = account.host
+ ? sshServers.find((entry) => sshHostKey(entry) === account.host)
+ : undefined
+ return presentAccount({
+ label: account.label,
+ email: account.email,
+ host: account.host,
+ machineLabel: server?.label
+ })
+ }
+
+ /** A machine's managed-account rows + the system row header. `remoteHost` set ⇒ that host. */
+ const codexRowsFor = (
+ accounts: readonly CodexAccount[],
+ remoteHost?: string
+ ): React.JSX.Element => {
+ const systemEmail = remoteHost ? (remoteSystemCodexEmails[remoteHost] ?? null) : systemCodexEmail
+ return (
+ <div className="space-y-2">
+ <div className="flex items-center justify-between gap-3 rounded-md border border-border/60 p-2">
+ <AccountIdentityPills
+ account={presentAccount({
+ label: null,
+ email: systemEmail,
+ host: remoteHost,
+ machineLabel: remoteHost
+ ? sshServers.find((s) => sshHostKey(s) === remoteHost)?.label
+ : undefined
+ })}
+ />
+ </div>
+ {accounts.map((account) => {
+ const blockedRemote = !!account.host && !connectedProjectIdForHost(account.host)
+ return (
+ <div
+ key={account.id}
+ className="flex items-center justify-between gap-3 rounded-md border border-border/60 p-2"
+ >
+ <div className="flex min-w-0 flex-1 items-center gap-2">
+ <Input
+ className="w-48"
+ placeholder="Codex account label"
+ value={account.label}
+ onChange={(e) => setCodexLabel(account.id, e.target.value)}
+ />
+ <AccountIdentityPills account={presentCodex(account)} warning={blockedRemote} />
+ {account.pending ? (
+ <span className="rounded-full bg-[color:var(--warn)]/15 px-2 py-0.5 text-[11px] font-medium text-[color:var(--warn)]">
+ pending
+ </span>
+ ) : null}
+ </div>
+ <Button
+ variant="ghost"
+ aria-label="Remove Codex account"
+ onClick={() => setPendingRemoveCodex(account)}
+ >
+ ×
+ </Button>
+ </div>
+ )
+ })}
+ </div>
+ )
+ }
+
// Open a login terminal for an account and wait (up to ~5 min) for the CLI to write its
// credentials; on success flip the row out of `pending` and adopt the captured email. A remote
// account (`host` set) logs in on its host: the login node runs in remote tmux and waitLogin polls
@@ -383,6 +615,58 @@ export function AccountsSection({ isActive }: { isActive: boolean }): React.JSX.
</div>
</SearchableRow>
+ {/* Codex accounts, grouped by machine. Each managed Codex login has its own CODEX_HOME and
+ credentials; a node keeps its account for life. Machine provenance (Local / SSH · host)
+ is shown as a pill; the credential-storage kind is deliberately not surfaced. */}
+ <SearchableRow {...ROWS.codex}>
+ <div className="space-y-4">
+ {codexGroups.map((group) => (
+ <MachinePanel
+ key={group.host || 'local'}
+ label={group.remote ? (group.server?.label ?? group.host) : 'This Mac'}
+ remote={group.remote}
+ hostKey={group.host || undefined}
+ connected={group.remote ? !!connectedProjectIdForHost(group.host) : true}
+ >
+ {codexRowsFor(group.accounts, group.remote ? group.host : undefined)}
+ {!group.remote ? (
+ <div className="space-y-2">
+ <Button variant="primary" disabled={addingCodex} onClick={() => void onAddCodexAccount()}>
+ {addingCodex ? (
+ <span className="inline-flex items-center gap-2">
+ <span className="ui-spinner" aria-hidden />
+ Setting up on this Mac…
+ </span>
+ ) : (
+ 'Add Codex account'
+ )}
+ </Button>
+ </div>
+ ) : (
+ <p className="text-[12px] leading-relaxed text-muted">
+ Codex accounts on this machine are managed from its own NodeTerm. Accounts already
+ created here are shown above.
+ </p>
+ )}
+ </MachinePanel>
+ ))}
+
+ {codexStrays.length > 0 ? (
+ <div className="space-y-2 rounded-md border border-[color:var(--warn)]/40 p-3">
+ <p className="text-[12px] font-medium text-[color:var(--warn)]">
+ Accounts on machines you no longer have saved
+ </p>
+ {codexRowsFor(codexStrays)}
+ </div>
+ ) : null}
+
+ <p className="text-[12px] leading-relaxed text-muted">
+ Codex accounts are isolated logins, grouped by the machine their credentials live on.
+ New Codex nodes pick an account from the add menus; each node keeps its account for life.
+ </p>
+ </div>
+ </SearchableRow>
+
{pendingRemove ? (
<ConfirmDialog
message={removeMessage(pendingRemove)}
@@ -391,6 +675,18 @@ export function AccountsSection({ isActive }: { isActive: boolean }): React.JSX.
onCancel={() => setPendingRemove(null)}
/>
) : null}
+ {pendingRemoveCodex ? (
+ <ConfirmDialog
+ message={`Remove Codex account "${pendingRemoveCodex.label}"?${
+ pendingRemoveCodex.host
+ ? ' It is dropped from this NodeTerm; its credentials on the host are untouched.'
+ : ' Its logged-in credentials and its Codex home will be deleted.'
+ }`}
+ confirmLabel="Remove"
+ onConfirm={() => void confirmRemoveCodex(pendingRemoveCodex)}
+ onCancel={() => setPendingRemoveCodex(null)}
+ />
+ ) : null}
</SettingsSection>
)
}
diff --git a/src/renderer/components/settings/sections/SshSection.tsx b/src/renderer/components/settings/sections/SshSection.tsx
index 232dd30f6..d4117c437 100644
--- a/src/renderer/components/settings/sections/SshSection.tsx
+++ b/src/renderer/components/settings/sections/SshSection.tsx
@@ -108,7 +108,7 @@ export function SshSection({ isActive }: { isActive: boolean }): React.JSX.Eleme
<SettingsSection
id="ssh"
title="Remote (SSH)"
- description="Saved SSH servers appear under “New remote”, and can host nodes on a local canvas. Opening remote terminals over SSH is free."
+ description="Saved SSH servers appear under “New remote”, and can host nodes on a local canvas. Each also becomes a machine in Accounts, where its own isolated Codex logins live. Opening remote terminals over SSH is free."
isActive={isActive}
searchEntries={ENTRIES}
>
diff --git a/src/renderer/lib/codexMachineGroups.test.ts b/src/renderer/lib/codexMachineGroups.test.ts
new file mode 100644
index 000000000..e38ce7911
--- /dev/null
+++ b/src/renderer/lib/codexMachineGroups.test.ts
@@ -0,0 +1,82 @@
+import { describe, expect, it } from 'vitest'
+import type { SshServer } from '@shared/ssh'
+import type { CodexAccount } from '@shared/codex-account'
+import {
+ codexRemoteTargets,
+ groupCodexAccountsByMachine,
+ strayCodexAccounts
+} from './codexMachineGroups'
+
+const server = (id: string, user: string, host: string, label: string): SshServer => ({
+ id,
+ user,
+ host,
+ label
+})
+
+describe('codexRemoteTargets', () => {
+ it('dedupes by host key and prefers the saved server over the active project connection', () => {
+ const saved = [server('s1', 'me', 'box', 'Ubuntu WSL')]
+ const active = server('p1', 'me', 'box', 'raw') // same host key me@box
+ const targets = codexRemoteTargets(saved, active)
+ expect(targets).toHaveLength(1)
+ expect(targets[0][0]).toBe('me@box')
+ expect(targets[0][1].label).toBe('Ubuntu WSL') // first (saved) wins
+ })
+
+ it('adds the active project server when it is a new host', () => {
+ const targets = codexRemoteTargets([server('s1', 'me', 'box', 'Box')], server('p1', 'me', 'two', 'Two'))
+ expect(targets.map(([host]) => host)).toEqual(['me@box', 'me@two'])
+ })
+
+ it('is empty with no servers', () => {
+ expect(codexRemoteTargets([], null)).toEqual([])
+ })
+})
+
+describe('groupCodexAccountsByMachine', () => {
+ const accounts: CodexAccount[] = [
+ { id: 'local-1', label: 'Home' },
+ { id: 'box-1', label: 'Work', host: 'me@box' },
+ { id: 'local-2', label: 'Side' },
+ { id: 'two-1', label: 'Other', host: 'me@two' }
+ ]
+ const targets = codexRemoteTargets(
+ [server('s1', 'me', 'box', 'Box'), server('s2', 'me', 'two', 'Two')],
+ null
+ )
+
+ it('puts This Mac first with exactly the host-less accounts', () => {
+ const groups = groupCodexAccountsByMachine(accounts, targets)
+ expect(groups[0]).toMatchObject({ host: '', remote: false })
+ expect(groups[0].accounts.map((a) => a.id)).toEqual(['local-1', 'local-2'])
+ })
+
+ it('emits one panel per configured host with its own accounts', () => {
+ const groups = groupCodexAccountsByMachine(accounts, targets)
+ expect(groups).toHaveLength(3) // This Mac + 2 hosts
+ expect(groups[1]).toMatchObject({ host: 'me@box', remote: true })
+ expect(groups[1].accounts.map((a) => a.id)).toEqual(['box-1'])
+ expect(groups[2].accounts.map((a) => a.id)).toEqual(['two-1'])
+ })
+
+ it('leaves a machine panel empty rather than borrowing another machine account', () => {
+ const groups = groupCodexAccountsByMachine([{ id: 'box-1', label: 'W', host: 'me@box' }], targets)
+ expect(groups.find((g) => g.host === 'me@two')?.accounts).toEqual([])
+ })
+})
+
+describe('strayCodexAccounts', () => {
+ it('surfaces a remote account whose host is not a configured target', () => {
+ const accounts: CodexAccount[] = [
+ { id: 'ok', label: 'W', host: 'me@box' },
+ { id: 'stray', label: 'Old', host: 'me@gone' }
+ ]
+ const targets = codexRemoteTargets([server('s1', 'me', 'box', 'Box')], null)
+ expect(strayCodexAccounts(accounts, targets).map((a) => a.id)).toEqual(['stray'])
+ })
+
+ it('never counts a local account as a stray', () => {
+ expect(strayCodexAccounts([{ id: 'l', label: 'H' }], [])).toEqual([])
+ })
+})
diff --git a/src/renderer/lib/codexMachineGroups.ts b/src/renderer/lib/codexMachineGroups.ts
new file mode 100644
index 000000000..d0e9a1158
--- /dev/null
+++ b/src/renderer/lib/codexMachineGroups.ts
@@ -0,0 +1,82 @@
+// S6 PR 8 — the pure machine-grouping the Accounts settings renders. Extracted from @Corvin's
+// #112 inline `AccountsSection` logic so the "one panel per host, accounts under the right machine"
+// invariant is unit-tested apart from the JSX.
+//
+// Renderer-pure: no `src/core`, no IPC. It only rearranges the flat `settings.codexAccounts` array
+// (partitioned by `host`) alongside the deduped set of reachable SSH machines.
+
+import type { SshConnection } from '@shared/ssh'
+import { sshHostKey } from '@shared/ssh'
+import type { CodexAccount } from '@shared/codex-account'
+
+/** The server behind a machine panel. A saved `SshServer` or the active project's own
+ * `SshConnection` both satisfy this — only the host/user (for the key) and an optional label are
+ * read. */
+export type MachineServer = SshConnection
+
+/** A reachable remote machine for the accounts UI: its host key + the server behind it. */
+export type CodexRemoteTarget = readonly [host: string, server: MachineServer]
+
+/**
+ * The remote machines to show a panel for, deduped by `sshHostKey`. Unions the saved SSH servers
+ * with the active project's own SSH server (so an ad-hoc `New remote` project still gets a machine
+ * panel even before it is saved). First occurrence of a host key wins, so a saved server's friendly
+ * label is preferred over the raw active-project connection.
+ */
+export function codexRemoteTargets(
+ sshServers: readonly MachineServer[],
+ activeProjectServer?: MachineServer | null
+): CodexRemoteTarget[] {
+ const byHost = new Map<string, MachineServer>()
+ for (const server of [...sshServers, ...(activeProjectServer ? [activeProjectServer] : [])]) {
+ const host = sshHostKey(server)
+ if (!byHost.has(host)) byHost.set(host, server)
+ }
+ return [...byHost.entries()]
+}
+
+/** One machine's panel: the machine, its SSH server (absent for this Mac), and its accounts. */
+export interface CodexMachineGroup {
+ /** Stable key: `''` for this Mac, else the host key. */
+ host: string
+ /** True for a remote (SSH) machine. */
+ remote: boolean
+ /** The saved SSH server, when remote. */
+ server?: MachineServer
+ /** Managed accounts that live on this machine, in settings order. */
+ accounts: CodexAccount[]
+}
+
+/**
+ * Group the flat account list into ordered machine panels: **this Mac first** (accounts with no
+ * `host`), then one panel per remote target in target order. An account lands under exactly the
+ * machine whose host key it carries; a remote account whose host is no longer a configured target
+ * is dropped from the panels (it is surfaced as a stray in the JSX, not fabricated into a machine).
+ */
+export function groupCodexAccountsByMachine(
+ accounts: readonly CodexAccount[],
+ remoteTargets: readonly CodexRemoteTarget[]
+): CodexMachineGroup[] {
+ const local: CodexMachineGroup = {
+ host: '',
+ remote: false,
+ accounts: accounts.filter((account) => !account.host)
+ }
+ const remotes = remoteTargets.map(([host, server]) => ({
+ host,
+ remote: true,
+ server,
+ accounts: accounts.filter((account) => account.host === host)
+ }))
+ return [local, ...remotes]
+}
+
+/** Managed accounts whose `host` matches no configured target — shown as strays, never fabricated
+ * into a machine panel of their own. */
+export function strayCodexAccounts(
+ accounts: readonly CodexAccount[],
+ remoteTargets: readonly CodexRemoteTarget[]
+): CodexAccount[] {
+ const known = new Set(remoteTargets.map(([host]) => host))
+ return accounts.filter((account) => account.host && !known.has(account.host))
+}
diff --git a/src/shared/types.ts b/src/shared/types.ts
index ca6fe2078..09d4f3b0a 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -2096,8 +2096,10 @@ export interface CodexAccountsApi {
cancelWaitLogin(id: string): Promise<void>
/** Read a managed account's already-logged-in identity (email), or null if not logged in. */
identity(id: string): Promise<{ email: string | null } | null>
- /** Read the system (`~/.codex`) account's identity. */
- systemIdentity(): Promise<{ email: string | null } | null>
+ /** Read a machine's system (`~/.codex`) account identity. No arg ⇒ this Mac. `{ projectId }` ⇒
+ * the connected SSH host behind that project; a host whose system identity cannot be resolved
+ * resolves `null` (fail-closed — a remote machine panel never borrows this Mac's login). */
+ systemIdentity(ctx?: { projectId?: string }): Promise<{ email: string | null } | null>
/** Remove a managed account: stop its daemon and delete its home. Refused while a switch
* reservation holds it or a concurrent removal is in flight (Property 10). */
remove(id: string): Promise<void>