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): an SSH pane's config dir is never offered for local linking

freshjuicez9f14c2064e1a
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 207f98c7c..b04676332 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -154,6 +154,7 @@ import {
type AddHandlers
} from '../lib/addMenuSpec'
import { planSetProjectFolder } from '../lib/setProjectFolder'
+import { observationIsRemote, type ObservationOrigin } from '../lib/accountChip'
import { transferConversationItems } from '../lib/transferItems'
import { reopenVariants } from '../lib/reopenVariants'
import { modelsForAgent } from '@shared/agents/model-gateway'
@@ -11029,13 +11030,41 @@ export function Canvas() {
const t = (s ?? '').replace(/\s+/g, ' ').trim()
return t.length <= max ? t : `${t.slice(0, max - 1)}…`
}
+ /**
+ * Where the node a hook event names actually lives — the two facts `observationIsRemote`
+ * needs. Read through `.getState()` rather than closed over, because this effect has `[]`
+ * deps and must see the CURRENT projects, not the ones that existed at mount.
+ *
+ * The active project's nodes come from React Flow (the single live source of truth for those);
+ * every other project answers from its serialized nodes, which carry `ssh`/`sshRemoteTmux` at
+ * the same names, so `isRemoteSessionNode` reads both. A node in NO project returns
+ * `undefined`, which `observationIsRemote` deliberately treats as remote.
+ */
+ const originOf = (nodeId: string): ObservationOrigin | undefined => {
+ const { projects, activeProjectId: activeId } = useProjects.getState()
+ const live = nodesRef.current.find((n) => n.id === nodeId)
+ if (live) {
+ const active = projects.find((p) => p.id === activeId)
+ return { node: live.data, projectIsSsh: !!active?.ssh }
+ }
+ const owner = projects.find((p) => p.nodes.some((n) => n.id === nodeId))
+ if (!owner) return undefined
+ return { node: owner.nodes.find((n) => n.id === nodeId), projectIsSsh: !!owner.ssh }
+ }
return api.onAgentStatus((e: NormalizedAgentEvent) => {
const cs = useAgentStatus.getState()
if (e.sessionId) cs.setSessionId(e.nodeId, e.sessionId)
- // Which Claude account the posting session is ACTUALLY on (hook-derived label, D3). Captured
+ // Which Claude account the posting session is ACTUALLY on — a hook-derived LABEL, captured
// off any event that carries one, exactly like `sessionId` above: a plain terminal running
// `CLAUDE_CONFIG_DIR=~/.claude-2 claude` announces its identity nowhere else.
- if (e.account) cs.setAccount(e.nodeId, e.account)
+ //
+ // The `remote` flag is stamped HERE and nowhere else. The classifier in core is deliberately
+ // host-agnostic — two of its rules exist precisely to name a REMOTE dir — and core holds only
+ // the hook payload, which never says which machine posted it. This listener is the first
+ // layer that can ask, because it can reach the node and the project that owns it, and a dir
+ // that names another machine's filesystem must not reach any LOCAL affordance (see
+ // `observationIsRemote` and the consumers in lib/accountChip.ts).
+ if (e.account) cs.setAccount(e.nodeId, { ...e.account, remote: observationIsRemote(originOf(e.nodeId)) })
const agentLabel = agentConfig(e.agentId)?.label ?? 'Agent'
// "<folder> — Claude finished" + last assistant message as the body.
const alert = (statusText: string, fallbackBody: string, sound: 'done' | 'needsYou') => {
diff --git a/src/renderer/components/settings/sections/AccountsSection.link.test.tsx b/src/renderer/components/settings/sections/AccountsSection.link.test.tsx
index 20a6c6eea..546465a24 100644
--- a/src/renderer/components/settings/sections/AccountsSection.link.test.tsx
+++ b/src/renderer/components/settings/sections/AccountsSection.link.test.tsx
@@ -179,6 +179,19 @@ describe('AccountsSection — detected config dirs', () => {
root.unmount()
})
+ it('never lists a dir an SSH node reported — Link would stat the wrong machine', () => {
+ // The section's Link button calls `claudeAccounts.link`, which `stat`s and writes where the
+ // CORE runs. A dir an SSH-project pane reported lives on its HOST, and with the same username
+ // on both machines it spells a path that exists here too — a different directory entirely.
+ useAgentStatus.setState({
+ byId: { n1: { unread: false, account: observed({ remote: true }) } }
+ })
+ const { host, root } = renderSection()
+ expect(host.textContent).not.toContain('Detected config dirs')
+ expect(byLabel(host, `Link ${CLAUDE_2}`)).toBeUndefined()
+ root.unmount()
+ })
+
it('renders nothing when every observed dir is already known', () => {
useAgentStatus.setState({
byId: {
diff --git a/src/renderer/lib/accountChip.test.ts b/src/renderer/lib/accountChip.test.ts
index 92eb9adcb..34d4b2c84 100644
--- a/src/renderer/lib/accountChip.test.ts
+++ b/src/renderer/lib/accountChip.test.ts
@@ -4,6 +4,7 @@ import {
accountChipFor,
accountKey,
configDirLabel,
+ observationIsRemote,
distinctAccountKeys,
effectiveAccountId,
hasMultipleAccountKeys,
@@ -32,7 +33,7 @@ const system = observed()
const managed = observed({ configDir: '/data/claude-accounts/a1', accountId: 'a1' })
const unlinked = observed({ configDir: '/home/me/.claude-2', accountId: null, known: false })
-describe('effectiveAccountId (D5)', () => {
+describe('effectiveAccountId (which account a node’s readers use)', () => {
it('prefers the node\u2019s own account over the observed one', () => {
// Launch identity is what the env actually injected; an observation cannot outrank it.
expect(effectiveAccountId('a1', managed)).toBe('a1')
@@ -52,7 +53,7 @@ describe('effectiveAccountId (D5)', () => {
})
})
-describe('accountKey (D6)', () => {
+describe('accountKey (the identity a node counts as)', () => {
it('keys the system account as "sys" only when it is actually observed', () => {
expect(accountKey(undefined, system)).toBe(SYSTEM_ACCOUNT_KEY)
// Unobserved is NOT the system account: a plain shell nobody ran claude in must not count as
@@ -131,7 +132,7 @@ describe('configDirLabel', () => {
})
})
-describe('accountChipFor (D6 visibility, D7 unlinked naming)', () => {
+describe('accountChipFor (chip visibility, and naming an unlinked dir)', () => {
const accounts = [acct(), acct({ id: 'a2', label: 'personal', email: undefined, configDir: '/home/me/.claude-2' })]
it('shows no chip for a system node while one identity is in play', () => {
@@ -424,3 +425,109 @@ describe('unlinking flows through every reader of the observation', () => {
})
})
})
+
+// ── A pane on an SSH host reports a dir on the HOST's filesystem ───────────────────────────────
+// The hook server's classifier is host-agnostic on purpose (two of its rules exist to name a
+// remote dir), and core cannot tell which machine posted — so the renderer stamps `remote` at the
+// one point the label enters the store, and every LOCAL affordance below must refuse it. The dirs
+// here deliberately spell the SAME absolute path on both machines: that is the ordinary case
+// whenever the two share a username, not a corner one.
+describe('a REMOTE observation is never treated as a dir on this machine', () => {
+ const remoteUnlinked = observed({ configDir: '/home/me/.claude-2', known: false, remote: true })
+
+ it('never offers an SSH node’s unknown dir for linking', () => {
+ // The named test. Settings → Accounts spends this list on `claudeAccounts.link`, which
+ // `stat`s and writes where the CORE runs — so a Link button here either errors on a path that
+ // is absent locally or, worse, silently adopts a different directory of the same name.
+ expect(unlinkedConfigDirs({ n1: { account: remoteUnlinked } })).toEqual([])
+ // …while the identical dir seen on a LOCAL pane is still a candidate, so this narrows exactly
+ // one thing and nothing else.
+ expect(unlinkedConfigDirs({ n1: { account: unlinked } })).toEqual(['/home/me/.claude-2'])
+ })
+
+ it('tells the user what the dir is instead of pointing at a Link it cannot perform', () => {
+ const accounts: ClaudeAccount[] = []
+ const chip = accountChipFor({ observed: remoteUnlinked, accounts, multiple: true })
+ expect(chip?.kind).toBe('unlinked') // the chip stays: naming what a session runs as is true
+ expect(chip?.short).toBe('.claude-2') // …by the same path rule as a local one
+ expect(chip?.tooltip).toContain('/home/me/.claude-2')
+ expect(chip?.tooltip).toContain('remote host')
+ expect(chip?.tooltip).not.toContain('Settings')
+ // The LOCAL wording is byte-identical to before the flag existed.
+ expect(accountChipFor({ observed: unlinked, accounts, multiple: true })?.tooltip).toBe(
+ 'Unlinked Claude config dir /home/me/.claude-2 — link it in Settings → Accounts'
+ )
+ })
+
+ it('is never matched against a local account that happens to hold the same path', () => {
+ // `ClaudeAccount.configDir` is written by `claudeAccounts.link`, a LOCAL adoption, so this
+ // account's `/home/me/.claude-2` is a directory on THIS machine. Matching the host's dir to it
+ // would label the remote pane with a local identity — and `effectiveAccountId` would then aim
+ // the local transcript / session-name / usage readers at that account's dir.
+ const localLink = acct({ id: 'lnk', label: 'second', email: undefined, configDir: '/home/me/.claude-2' })
+ expect(resolveObserved(remoteUnlinked, [localLink])).toBe(remoteUnlinked)
+ expect(effectiveAccountId(undefined, remoteUnlinked, [localLink])).toBeUndefined()
+ // The local pane on the same path still upgrades — the refusal is about remoteness, not the
+ // path, so linking has not been broken for the case it exists for.
+ expect(resolveObserved(unlinked, [localLink])?.accountId).toBe('lnk')
+ })
+
+ it('does not dir-match on the fallback path either, when the observed id has gone away', () => {
+ // `resolveObserved`'s other direction: a known id that no longer exists falls back to its dir.
+ // A remote one must degrade to the bare dir rather than re-home on a local account.
+ const goneRemote = observed({ configDir: '/home/me/.claude-2', accountId: 'old', known: true, remote: true })
+ const localLink = acct({ id: 'lnk', configDir: '/home/me/.claude-2' })
+ expect(resolveObserved(goneRemote, [localLink])).toEqual({ ...goneRemote, accountId: null, known: false })
+ })
+
+ it('still resolves a MANAGED REMOTE account — the thing that must not regress', () => {
+ // The classifier's managed-remote rule (`~/.nodeterm/claude-accounts/<id>`) reports a real id
+ // with `known: true`, and a remote account is in the account list with `host` set. That route
+ // is ID-based, never path-based, so the refusal above cannot reach it.
+ const remoteAcct = acct({ id: 'r1', label: '[email protected]', host: '[email protected]' })
+ const managedRemote = observed({
+ configDir: '/home/me/.nodeterm/claude-accounts/r1',
+ accountId: 'r1',
+ known: true,
+ remote: true
+ })
+ expect(resolveObserved(managedRemote, [remoteAcct])).toBe(managedRemote)
+ expect(effectiveAccountId(undefined, managedRemote, [remoteAcct])).toBe('r1')
+ expect(accountKey(undefined, managedRemote, [remoteAcct])).toBe('r1')
+ expect(accountChipFor({ observed: managedRemote, accounts: [remoteAcct], multiple: false })?.kind).toBe(
+ 'managed'
+ )
+ // …and it is never a Link candidate, because it is a known account.
+ expect(unlinkedConfigDirs({ n1: { account: managedRemote } }, [remoteAcct])).toEqual([])
+ })
+
+ it('leaves the host’s own system account reading the system root', () => {
+ const remoteSystem = observed({ configDir: '/home/me/.claude', accountId: null, known: true, remote: true })
+ expect(effectiveAccountId(undefined, remoteSystem, [acct()])).toBeUndefined()
+ expect(accountKey(undefined, remoteSystem)).toBe(SYSTEM_ACCOUNT_KEY)
+ })
+})
+
+describe('observationIsRemote (which machine the observed dir is on)', () => {
+ it('asks the node and the project, and either one is enough', () => {
+ // `data.ssh` / `data.sshRemoteTmux` is the precise answer…
+ expect(observationIsRemote({ node: { ssh: { host: 'h' } }, projectIsSsh: false })).toBe(true)
+ expect(observationIsRemote({ node: { sshRemoteTmux: true }, projectIsSsh: false })).toBe(true)
+ // …but a node created before its project's ControlMaster came up carries neither yet, so the
+ // project has to answer for it.
+ expect(observationIsRemote({ node: {}, projectIsSsh: true })).toBe(true)
+ expect(observationIsRemote({ node: undefined, projectIsSsh: true })).toBe(true)
+ })
+
+ it('is false for an ordinary local node — the byte-identical case', () => {
+ expect(observationIsRemote({ node: {}, projectIsSsh: false })).toBe(false)
+ expect(observationIsRemote({ node: { ssh: undefined }, projectIsSsh: false })).toBe(false)
+ })
+
+ it('treats a node it cannot place as REMOTE', () => {
+ // Hook events for a node id no canvas holds — a tmux session outliving the node that named it.
+ // A wrong `false` puts a Link button on a directory that is not here; a wrong `true` costs one
+ // withheld offer. Only one of those two guesses is destructive, so it is the one not made.
+ expect(observationIsRemote(undefined)).toBe(true)
+ })
+})
diff --git a/src/renderer/lib/accountChip.ts b/src/renderer/lib/accountChip.ts
index 3b448682a..6192ccdc4 100644
--- a/src/renderer/lib/accountChip.ts
+++ b/src/renderer/lib/accountChip.ts
@@ -1,9 +1,9 @@
import type { ClaudeAccount, ObservedClaudeAccount } from '@shared/types'
+import { isRemoteSessionNode } from '@shared/worktree'
import { accountChipLabel, systemAccountDisplay } from '../state/workspace'
/**
- * Per-node Claude account labelling — the pure half of the account chip (plan §5 WP-B.2,
- * decisions D5–D7).
+ * Per-node Claude account labelling — the pure half of the account chip.
*
* A node's account has TWO possible sources and they routinely disagree:
* - `data.accountId` — the managed/linked account the node was CREATED with. Immutable, and the
@@ -76,6 +76,38 @@ export function configDirsMatch(a: string | undefined | null, b: string | undefi
return !!left && left === normalizeConfigDirForCompare(b)
}
+/** The two facts about the node an observation arrived for, as the renderer can see them. */
+export interface ObservationOrigin {
+ /** The node itself — the live React Flow `node.data` for the active project, or the serialized
+ * `CanvasNodeState` for any other. Both carry `ssh` / `sshRemoteTmux`. */
+ node?: { ssh?: unknown; sshRemoteTmux?: unknown }
+ /** Does the project that owns the node run on an SSH host? */
+ projectIsSsh: boolean
+}
+
+/**
+ * Is this observation's filesystem on ANOTHER machine? (`ObservedClaudeAccount.remote`)
+ *
+ * Two independent claims are OR-ed, and both are needed. `isRemoteSessionNode` asks the node
+ * (`data.ssh` / `data.sshRemoteTmux` — never `data.remote`, a field nothing on a canvas node
+ * sets), which is the precise answer; but a node created before its project's ControlMaster came
+ * up does not carry those yet, so the project's own SSH-ness has to answer for it. Same shape as
+ * `session-memory-service.ts`'s two claims of remoteness, for the same reason: a source that says
+ * "no" while momentarily uninformed would publish another machine's dir as this one's.
+ *
+ * **`undefined` — we cannot say whose node this is — is REMOTE.** Every consumer of the flag
+ * degrades a remote observation to "show the label, offer nothing local", while a wrong `false`
+ * puts a Link button on a directory that does not exist here: the failure the flag was added to
+ * stop. Guessing local is the only guess with a destructive outcome, so it is the guess not made.
+ * The case is narrow — hook events for a node id no canvas holds, i.e. a tmux session outliving
+ * the node that named it — and a stored observation captured while the node DID exist keeps the
+ * `remote: false` it was captured with, so nothing already detected is retracted by this.
+ */
+export function observationIsRemote(origin: ObservationOrigin | undefined): boolean {
+ if (!origin) return true
+ return origin.projectIsSsh || isRemoteSessionNode(origin.node)
+}
+
/**
* Re-resolve an observation against the CURRENT account list.
*
@@ -96,36 +128,60 @@ export function configDirsMatch(a: string | undefined | null, b: string | undefi
* The system account (`known` with `accountId: null`) is never touched: it has no record to lose.
* `data.accountId` is likewise untouched — a NODE created under a removed account still reads
* "Unknown account", which is correct: that binding really is dangling.
+ *
+ * **A REMOTE observation is never dir-matched against a local account** (`observed.remote`), in
+ * either direction. `ClaudeAccount.configDir` is set only by `claudeAccounts.link`, which is a
+ * LOCAL adoption — the path it stores names a directory on this machine — while a remote pane's
+ * dir names one on its host, and `~/.claude-2` on a server and `~/.claude-2` here spell the same
+ * string whenever the two machines share a username, which is the ordinary case rather than a
+ * corner. Matching them would label the remote pane with a local account's identity, and
+ * `effectiveAccountId` would then hand that id to the LOCAL transcript, session-name and usage
+ * readers. Managed-remote observations are unaffected: they arrive `known: true` carrying a real
+ * `accountId` (classifier rule 2, `~/.nodeterm/claude-accounts/<id>`), and the id-based branch
+ * above resolves them against the account list without ever looking at a path.
*/
export function resolveObserved(
observed: ObservedClaudeAccount | undefined,
accounts: readonly ClaudeAccount[] = []
): ObservedClaudeAccount | undefined {
if (!observed) return observed
+ // A dir on another machine may never be matched against a local account's dir; the id-based
+ // resolution below it is safe for both, because an id is not a path.
+ const dirMatchable = !observed.remote
if (observed.known) {
if (!observed.accountId) return observed // the system default — nothing to lose
if (accounts.some((a) => a.id === observed.accountId)) return observed
// The id is gone (unlinked/removed since the observation). Fall back to the dir — unless there
// is none, in which case there is nothing better to say than the id we already have.
if (!observed.configDir) return observed
- const relinked = accounts.find((a) => configDirsMatch(a.configDir, observed.configDir))
+ const relinked = dirMatchable
+ ? accounts.find((a) => configDirsMatch(a.configDir, observed.configDir))
+ : undefined
return relinked
? { ...observed, accountId: relinked.id, known: true }
: { ...observed, accountId: null, known: false }
}
- if (!observed.configDir) return observed
+ if (!observed.configDir || !dirMatchable) return observed
const match = accounts.find((a) => configDirsMatch(a.configDir, observed.configDir))
return match ? { ...observed, accountId: match.id, known: true } : observed
}
/**
- * D5 — the account a node's READERS (transcript root, session name, context meter, ⌘M chat) must
- * use: the node's own account when it has one, else whatever the session was observed running as.
+ * The account a node's READERS (transcript root, session name, context meter, ⌘M chat) must use:
+ * the node's own account when it has one, else whatever the session was observed running as.
*
* `known` is what makes the observed id meaningful: an unrecognised config dir reports
* `accountId: null`, and must resolve to `undefined` (→ the system account's readers) rather than
* to some other account's transcripts. Deliberately NOT used for spawn/env — launch identity stays
* creation-time.
+ *
+ * A REMOTE observation needs no branch of its own here, because `resolveObserved` already refuses
+ * to dir-match one: an unlinked remote dir stays `known: false` and yields `undefined`, so a
+ * remote pane can never hand a LOCAL account's id to the local transcript / session-name / usage
+ * readers. What it can still yield is an id from the two ID-based routes, and both are right — a
+ * managed-remote account (`~/.nodeterm/claude-accounts/<id>`) is a real record whose reads are
+ * scoped by that id on whichever host runs them, and the host's own system `~/.claude` yields
+ * `undefined`, which is the system root on either machine.
*/
export function effectiveAccountId(
dataAccountId?: string,
@@ -141,7 +197,7 @@ export function effectiveAccountId(
}
/**
- * D6 — the identity key a node counts as, for "is more than one account in play?".
+ * The identity key a node counts as, for "is more than one account in play?".
*
* - `<accountId>` — a managed or linked account (from the node, or observed);
* - `'sys'` — the system default (`~/.claude`), which has no id of its own;
@@ -150,6 +206,18 @@ export function effectiveAccountId(
* - `null` — nothing is known about this node's account. NOT a key: an unobserved plain
* terminal must not count as a second identity (it would put a chip on every
* system pane the moment one shell was opened), and it gets no chip.
+ *
+ * A REMOTE observation keys exactly like a local one, deliberately. The key is an opaque identity
+ * token — it is never spent on a filesystem action and, since `resolveObserved` refuses to
+ * dir-match a remote observation, it can no longer be produced by mistaking a host's dir for a
+ * local account's. The residual is a COLLISION: a host's `/home/u/.claude-2` and this machine's
+ * `/home/u/.claude-2`, both unlinked, key the same and count as one identity. That is accepted,
+ * not overlooked. It costs at most one chip — `multiple` is the only consumer, and it gates the
+ * chip on SYSTEM panes alone, so the two dirs themselves still chip (with different tooltips) —
+ * which is this module's standing failure direction: one chip fewer, never a wrong one. The
+ * alternative, a second key dialect for remote dirs, would mean the chip has to parse two shapes
+ * to recover a path, and one resolution feeding chip + keys + detected list is the invariant that
+ * keeps them from disagreeing.
*/
export function accountKey(
dataAccountId?: string,
@@ -168,7 +236,7 @@ export function accountKey(
}
/** The distinct account keys across a set of nodes (see `accountKey`); unknown nodes contribute
- * nothing. `size >= 2` is D6's "there's multiple". */
+ * nothing. `size >= 2` is what the chip means by "more than one identity is in play". */
export function distinctAccountKeys(
entries: Iterable<{ dataAccountId?: string; observed?: ObservedClaudeAccount }>,
accounts: readonly ClaudeAccount[] = []
@@ -191,7 +259,8 @@ export function distinctAccountKeys(
*
* The store only knows OBSERVED accounts, so other nodes' creation-time `data.accountId` is not
* counted — a managed node that has never posted a hook is invisible here. That is the cheap,
- * store-only reading of D6 and it fails in the safe direction: one chip fewer, never a wrong one.
+ * store-only reading of "how many identities" and it fails in the safe direction: one chip fewer,
+ * never a wrong one.
*/
export function hasMultipleAccountKeys(
byId: Record<string, { account?: ObservedClaudeAccount }>,
@@ -211,7 +280,7 @@ export function hasMultipleAccountKeys(
/**
* The config dirs seen running on this core that nodeterm has no account for — Settings →
- * Accounts lists these as one-click "Link" candidates (D7).
+ * Accounts lists these as one-click "Link" candidates.
*
* Derived from OBSERVATIONS only: a dir gets in here because a session posted a hook from it, so
* the list is a record of what actually ran, and nothing here reads the filesystem (a forged POST
@@ -221,6 +290,14 @@ export function hasMultipleAccountKeys(
* never be both "belongs to an account" (chipped as linked) and "detected" (offered for linking),
* in either direction: linking removes it from this list at once, and unlinking puts it back at
* once, with no hook event in between.
+ *
+ * **A REMOTE observation is skipped** (`observed.remote`). This list is a list of LINK candidates,
+ * and Settings → Accounts spends it on `claudeAccounts.link`, which `stat`s and writes on the
+ * machine the core runs on. A dir an SSH-project pane reported lives on its HOST, so the button
+ * would `stat` a path that is either absent here (an error the user cannot act on) or — with the
+ * same username on both machines, the ordinary case — a DIFFERENT directory of the same name,
+ * silently adopting the wrong account. The dir is still shown on the pane's own chip: naming what
+ * a session runs as is a true statement wherever it runs; only the local offer is withdrawn.
*/
export function unlinkedConfigDirs(
byId: Record<string, { account?: ObservedClaudeAccount }>,
@@ -228,6 +305,7 @@ export function unlinkedConfigDirs(
): string[] {
const dirs = new Set<string>()
for (const entry of Object.values(byId)) {
+ if (entry.account?.remote) continue
const a = resolveObserved(entry.account, accounts)
if (!a || a.known || !a.configDir) continue
dirs.add(a.configDir)
@@ -253,7 +331,8 @@ function shortAccountLabel(label: string): string {
}
/**
- * Last segment of a config dir path, for an unlinked dir's chip (D7 — named by path, never read).
+ * Last segment of a config dir path, for an unlinked dir's chip: such a dir is named by its path
+ * and never read, so its last segment is the only name there is.
*
* The owning filesystem is NOT known here: the dir string comes from a hook that may have run on
* this machine, on an SSH host, or on Windows. So the separator is picked from the SHAPE of the
@@ -276,7 +355,7 @@ export function configDirLabel(configDir: string): string {
/**
* The chip for one node, or `null` for no chip.
*
- * D6 visibility: a node that is NOT on the system account always gets a chip (it is the exception
+ * Visibility: a node that is NOT on the system account always gets a chip (it is the exception
* the user needs to see), and system nodes get one only when `multiple` — i.e. when at least two
* identities are in play, so two panes side by side are always told apart.
*/
@@ -295,7 +374,7 @@ export function accountChipFor({
systemLabel?: string
/** The detected `~/.claude` login email (`state/systemAccount`), when known. */
systemEmail?: string | null
- /** D6: are ≥ 2 distinct account keys in play on this core? (`hasMultipleAccountKeys`) */
+ /** Are ≥ 2 distinct account keys in play on this core? (`hasMultipleAccountKeys`) */
multiple?: boolean
}): AccountChipInfo | null {
// Resolved against the CURRENT list: linking a detected dir must repaint every chip on it
@@ -315,12 +394,18 @@ export function accountChipFor({
}
}
if (key.startsWith('ext:')) {
- // D7: named by its path and NEVER read. The tooltip is the whole affordance — it says what the
- // dir is and where to turn it into a real account.
+ // An unlinked dir is named by its path and NEVER read (no `stat`, no open — a forged POST must
+ // not make us touch the filesystem). The tooltip is the whole affordance, so it must not point
+ // anywhere the user cannot go: Settings → Accounts links a dir on the machine the core runs
+ // on, which is not the machine a REMOTE pane's dir is on. The chip itself stays either way —
+ // naming what the session runs as is true wherever it runs — and the remote wording says whose
+ // filesystem the path belongs to instead of offering an impossible action.
const dir = key.slice('ext:'.length)
return {
short: shortAccountLabel(configDirLabel(dir)),
- tooltip: `Unlinked Claude config dir ${dir} — link it in Settings → Accounts`,
+ tooltip: observed?.remote
+ ? `Claude config dir ${dir} on the remote host — not a config dir on this machine`
+ : `Unlinked Claude config dir ${dir} — link it in Settings → Accounts`,
kind: 'unlinked'
}
}
diff --git a/src/renderer/state/agentStatus.persist.test.ts b/src/renderer/state/agentStatus.persist.test.ts
index 2cb65217d..50ebfb931 100644
--- a/src/renderer/state/agentStatus.persist.test.ts
+++ b/src/renderer/state/agentStatus.persist.test.ts
@@ -413,6 +413,40 @@ describe('observed Claude account persistence (a plain terminal knows it nowhere
expect(reloaded.useAgentStatus.getState().byId['n1']?.account).toEqual(claude2)
})
+ it('round-trips `remote` — losing it would put a Link button back on a host\u2019s dir', async () => {
+ // The loader rebuilds the account object field by field, so a field it forgets is dropped
+ // silently — and this one's absence reads as LOCAL, which is the exact state the flag exists
+ // to prevent (`unlinkedConfigDirs` would offer the dir again, `resolveObserved` would match it
+ // against a local account of the same path).
+ const store = memStorage()
+ vi.stubGlobal('localStorage', store)
+ const { useAgentStatus } = await import('./agentStatus')
+ useAgentStatus.getState().setAccount('n1', { ...claude2, remote: true })
+ expect(JSON.parse(store.getItem('nodeterm.agentStatus')!).n1.account.remote).toBe(true)
+
+ vi.resetModules()
+ vi.stubGlobal(
+ 'localStorage',
+ memStorage({ 'nodeterm.agentStatus': store.getItem('nodeterm.agentStatus')! })
+ )
+ const reloaded = await import('./agentStatus')
+ expect(reloaded.useAgentStatus.getState().byId['n1']?.account?.remote).toBe(true)
+ })
+
+ it('hydrates a pre-flag entry byte-identically — absent stays absent, never `false`', async () => {
+ vi.stubGlobal(
+ 'localStorage',
+ memStorage({
+ 'nodeterm.agentStatus': JSON.stringify({
+ n5: { unread: false, account: { configDir: '/home/me/.claude-2', accountId: null, known: false } }
+ })
+ })
+ )
+ const { useAgentStatus } = await import('./agentStatus')
+ expect(useAgentStatus.getState().byId['n5']?.account).toEqual(claude2)
+ expect('remote' in (useAgentStatus.getState().byId['n5']!.account as object)).toBe(false)
+ })
+
it('is the ONLY durable field an account-only entry needs to survive', async () => {
// `save` skips entries carrying nothing durable — an observed account on an otherwise blank
// node (no unread, no session id, no agent) has to be enough to keep the entry.
diff --git a/src/renderer/state/agentStatus.ts b/src/renderer/state/agentStatus.ts
index ab2c47c26..88378c0d7 100644
--- a/src/renderer/state/agentStatus.ts
+++ b/src/renderer/state/agentStatus.ts
@@ -327,7 +327,14 @@ export function createAgentStatusSession(
out[id].account = {
configDir: v.account.configDir,
accountId: typeof v.account.accountId === 'string' ? v.account.accountId : null,
- known: v.account.known
+ known: v.account.known,
+ // `remote` MUST round-trip. This loader rebuilds the object field by field, so a field
+ // it forgets is silently dropped — and for this one the dropped value reads as LOCAL,
+ // which puts a Link button back on an SSH host's config dir at the first reload and
+ // matches it against local accounts again. The absent-is-local default is only correct
+ // for an entry written before the field existed, where nothing remote was ever
+ // recorded; a `false` is not stored, so those entries hydrate byte-identically.
+ ...(v.account.remote ? { remote: true } : {})
}
}
// Only when set: an absent flag stays absent, so an entry saved before this field
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 06977fc72..c5a068f1c 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -1206,6 +1206,23 @@ export interface ObservedClaudeAccount {
configDir: string
accountId: string | null
known: boolean
+ /**
+ * The observation came from a session whose FILESYSTEM IS ON ANOTHER MACHINE (an SSH-project
+ * pane), so every LOCAL affordance — offering the dir for linking, matching it against a local
+ * account's `configDir` — must refuse it. `~/.claude-2` on a host and `~/.claude-2` here are
+ * different directories that spell the same string, and the same username on both machines is
+ * the common case, not the exotic one.
+ *
+ * It is NOT set by the classifier: `classifyClaudeConfigDir` is deliberately host-agnostic (its
+ * managed-remote and basename-`.claude` rules exist precisely to name a REMOTE dir) and core
+ * holds only the payload, which says nothing about which machine posted it. The RENDERER is the
+ * only layer that knows a node's project and `data.ssh`, so the flag is attached there, once, at
+ * the point the label enters the store.
+ *
+ * Optional and trailing: an observation without it is a local one, which is what every
+ * observation was before the field existed.
+ */
+ remote?: boolean
}
export interface SpeechSettings {