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(accounts): read an account color as a string before trimming it

Uri Bloch47e81b624379
diff --git a/CLAUDE.md b/CLAUDE.md
index 135f08f3f..01b6026a5 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -1241,7 +1241,10 @@ else, and its context links must keep classifying across restarts).
`data.accountId`, so the color and the binding cannot drift. Applied **at creation** and baked
into `data.color` like any other node color: a hand-picked node color is never overwritten and
editing the account later repaints nothing. Unset / stale id / non-claude agent ⇒ the agent's
- color, unchanged.
+ color, unchanged. The value is **re-validated as a string** at the read: `claudeAccounts` comes
+ out of a hand-editable settings.json that nothing checks field-by-field on load, and a
+ `"color": 123` would throw on `.trim()` INSIDE `createAgentNode` — stopping every new node
+ under that account from opening, with nothing pointing back at the edited file.
- **Env injection** — `pty-manager` sets `CLAUDE_CONFIG_DIR` in the spawn env AND as a tmux `-e`
(local); for a remote node it emits an **absolute-path** remote tmux `-e` built from the
connection-cached `remoteHome` (skipped **fail-open** if home is unresolved). `AUTH_ENV_STRIP`
diff --git a/src/renderer/state/workspace.account-color.test.ts b/src/renderer/state/workspace.account-color.test.ts
index 27352e86a..c63ebec03 100644
--- a/src/renderer/state/workspace.account-color.test.ts
+++ b/src/renderer/state/workspace.account-color.test.ts
@@ -43,6 +43,15 @@ describe('accountNodeColor', () => {
it('is undefined for a blank color — an empty string must not paint a node transparent', () => {
expect(accountNodeColor('a3', [account('a3', ' ')])).toBeUndefined()
})
+
+ // settings.json is hand-editable and nothing validates `claudeAccounts` field-by-field on load,
+ // so a non-string `color` reaches this helper as-is. `.trim()` on it throws — and this runs
+ // inside createAgentNode, so the throw would stop EVERY new node under that account from
+ // opening, with nothing pointing back at the edited file.
+ it('is undefined for a non-string color — a hand-edited settings.json must not break node creation', () => {
+ const bad = { id: 'a4', label: 'a4', createdAt: 0, color: 123 } as unknown as ClaudeAccount
+ expect(accountNodeColor('a4', [bad])).toBeUndefined()
+ })
})
describe('createAgentNode — account default color', () => {
diff --git a/src/shared/agents/account-color.ts b/src/shared/agents/account-color.ts
index 07eddcc58..ce0c21150 100644
--- a/src/shared/agents/account-color.ts
+++ b/src/shared/agents/account-color.ts
@@ -1,10 +1,21 @@
import type { ClaudeAccount } from '../types'
+/**
+ * The default node color a managed Claude account carries, or undefined for "use the agent's own".
+ *
+ * `typeof` first, not just optional chaining: `claudeAccounts` comes out of a hand-editable
+ * settings.json that nothing validates field-by-field on load (`mergeSettings` merges, it does not
+ * check), so a `"color": 123` arrives here verbatim — and `.trim()` on it throws inside
+ * `createAgentNode`, i.e. every new node under that account stops opening with nothing pointing
+ * back at the edited file. Same discipline as `appendProjectNode`'s account-id guard.
+ * A whitespace-only color is unset too: an empty `data.color` renders a node transparent.
+ */
export function accountNodeColor(
accountId: string | undefined,
accounts: ClaudeAccount[]
): string | undefined {
if (!accountId) return undefined
- const color = accounts.find((a) => a.id === accountId)?.color?.trim()
- return color || undefined
+ const color = accounts.find((a) => a.id === accountId)?.color
+ if (typeof color !== 'string') return undefined
+ return color.trim() || undefined
}