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(session): one remote-project predicate for the spawn refusal; pin the card modal's owner reads

review3ce2b159b82b
diff --git a/src/renderer/components/kanban/ModalTerminal.tsx b/src/renderer/components/kanban/ModalTerminal.tsx
index 76060199f..189846e99 100644
--- a/src/renderer/components/kanban/ModalTerminal.tsx
+++ b/src/renderer/components/kanban/ModalTerminal.tsx
@@ -20,7 +20,7 @@ import { focusXtermUnlessCovered, useMdModeFocus } from '../../terminal/useMdMod
import { FindBar } from '../FindBar'
import { useAgentStatus } from '../../state/agentStatus'
import { useProjects } from '../../state/projects'
-import { useSession } from '../../session/session'
+import { isRemoteProjectId, useSession } from '../../session/session'
import { REMOTE_PROJECT_SPAWN_REFUSAL, spawnBelongsElsewhere, useOwningProjectId } from '../../session/owning-project'
import { isHostedReadOnly } from '../../state/hostedTeams'
import { useSettings } from '../../state/settings'
@@ -506,9 +506,10 @@ export function ModalTerminal({
// MIRROR TerminalNode: a node of a REMOTE project (a relay / hosted team tab) under a session
// that is not a relay session would create the host's node id on THIS desktop's core. The
// board mounts the modal under the card's project session (`ProjectSessionScope`), so this
- // is the defensive half: start nothing, before any SSH resolve.
+ // is the defensive half: start nothing, before any SSH resolve. `isRemoteProjectId` is
+ // sessionForProject's own rule, so a tab the store deleted still counts.
const owner = owningProjectRef.current
- if (spawnBelongsElsewhere(useProjects.getState().getProject(owner ?? ''), session.source)) {
+ if (spawnBelongsElsewhere(isRemoteProjectId(owner ?? ''), session.source)) {
term.write(
`\r\n\x1b[90m${REMOTE_PROJECT_SPAWN_REFUSAL}\x1b[0m\r\n`
)
diff --git a/src/renderer/components/kanban/cardModalSession.test.tsx b/src/renderer/components/kanban/cardModalSession.test.tsx
index df087b26e..bd7c7fb8b 100644
--- a/src/renderer/components/kanban/cardModalSession.test.tsx
+++ b/src/renderer/components/kanban/cardModalSession.test.tsx
@@ -167,7 +167,8 @@ describe('both terminals refuse to spawn locally for a remote project (F2c)', ()
expect(src).toContain('const owningProject = useOwningProjectId()')
expect(src).toContain('owningProjectRef.current = owningProject')
const noSpawn = src.indexOf('if (noSpawn) return')
- const ask = src.indexOf('spawnBelongsElsewhere(', noSpawn)
+ // The ONE remote-project rule (session.ts), never a store-only `getProject(...)?.remote` read.
+ const ask = src.indexOf("spawnBelongsElsewhere(isRemoteProjectId(owningProjectRef.current ?? ''), session.source)", noSpawn)
const refusal = src.indexOf(REFUSAL, ask)
const resolve = src.indexOf('await resolveSshRemote(', noSpawn)
const create = src.indexOf('transport\n .create({', noSpawn)
@@ -177,13 +178,14 @@ describe('both terminals refuse to spawn locally for a remote project (F2c)', ()
expect(resolve).toBeGreaterThan(refusal)
expect(create).toBeGreaterThan(resolve)
expect(src).toContain('ownerProjectId: sshProjectId ?? owningProjectRef.current ?? useProjects.getState().activeProjectId')
+ expect(src).not.toMatch(/spawnBelongsElsewhere\(useProjects/)
})
it('ModalTerminal asks spawnBelongsElsewhere before its SSH resolve and its create', () => {
const src = read('ModalTerminal.tsx')
expect(src).toContain('const owningProject = useOwningProjectId()')
expect(src).toContain('owningProjectRef.current = owningProject')
- const ask = src.indexOf('spawnBelongsElsewhere(')
+ const ask = src.indexOf("spawnBelongsElsewhere(isRemoteProjectId(owner ?? ''), session.source)")
const refusal = src.indexOf(REFUSAL, ask)
const resolve = src.indexOf('await resolveSshRemote(', ask)
const create = src.indexOf('const res = await transport.create({', ask)
@@ -195,6 +197,7 @@ describe('both terminals refuse to spawn locally for a remote project (F2c)', ()
expect(src).toContain('const owner = owningProjectRef.current')
expect(src).toContain(': (owner ?? useProjects.getState().activeProjectId)')
expect(src).toContain('ownerProjectId: projectId,')
+ expect(src).not.toMatch(/spawnBelongsElsewhere\(useProjects/)
})
it('ModalTerminal gates the SSH dial on session.source like TerminalNode\'s dialsSsh', () => {
diff --git a/src/renderer/components/kanban/cardOwnerProject.test.tsx b/src/renderer/components/kanban/cardOwnerProject.test.tsx
new file mode 100644
index 000000000..1bc3b13bd
--- /dev/null
+++ b/src/renderer/components/kanban/cardOwnerProject.test.tsx
@@ -0,0 +1,161 @@
+// @vitest-environment jsdom
+//
+// The card modal's Pull requests section and metadata strip must read the CARD's project, not the
+// active one. On the Omni board a lane's card modal runs under the lane project's
+// ProjectSessionScope while another project is active; both components key their reads on
+// `useOwningProjectId() ?? activeProjectId`. A revert to `activeProjectId` alone made the Pull
+// requests section show the ACTIVE project's pull requests and auto-move target, so an Unlink wrote
+// the wrong project's PR number as a tombstone into the lane's board, and made the Members picker
+// offer the active project's board-log authors. Each test renders the REAL component under a real
+// ProjectSessionScope for a lane project that is not the active one (the pattern of
+// boardLogPanelSession.test.tsx).
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { act } from 'react'
+import { createRoot, type Root } from 'react-dom/client'
+import type { BoardLogEntry, NodeTerminalApi, Project, ProjectKanban } from '@shared/types'
+import type { GitHubPullBoard } from '@shared/github-pull-status'
+import { cardAssignees, cardMeta } from '@shared/kanban-labels'
+import { readPullLinks } from '@shared/kanban-pull-links'
+import { CardPullRequests, PULL_LINK_SSH_REASON } from './CardPullRequests'
+import { CardMetaBar } from './CardMetaBar'
+import type { KanbanSession } from './KanbanView'
+import { useBoardLog } from '../../state/boardLog'
+import { useGitHubIssues } from '../../state/githubIssues'
+import { useProjects } from '../../state/projects'
+import { useSettings } from '../../state/settings'
+import { ProjectSessionScope } from '../../session/owning-project'
+import {
+ createSession,
+ resetSessionsForTest,
+ SessionProvider,
+ setActiveSession,
+ type WorkspaceSession
+} from '../../session/session'
+
+const ACTIVE = 'p-active'
+const LANE = 'p-lane'
+const SSH = { server: { host: 'h', user: 'u' } as never, remoteCwd: '~' }
+
+const project = (id: string, ssh = false): Project =>
+ ({ id, name: id, color: '#7aa2f7', viewport: { x: 0, y: 0, zoom: 1 }, nodes: [], ...(ssh ? { ssh: SSH } : {}) }) as unknown as Project
+
+const board: ProjectKanban = {
+ columns: [{ id: 'doing', title: 'Doing', color: '#fff' }, { id: 'done', title: 'Done', color: '#fff' }],
+ assignments: [],
+ github: { columnMappings: [], repository: 'o/r' }
+}
+
+const session = (over: Partial<KanbanSession> = {}): KanbanSession => ({
+ id: 'n-lane', title: 'Agent', color: '#fff', kind: 'terminal', spawn: {}, worktreeBranch: 'feat/x', ...over
+})
+
+// Both projects have an open PR from the SAME branch name, so only the project decides which shows.
+const pullBoard = (number: number): GitHubPullBoard => ({
+ repository: 'o/r',
+ pulls: [{ number, lifecycle: 'open', headRefName: 'feat/x', headRefOid: 'a'.repeat(40), ci: 'passed', merge: 'ready', closes: [] }],
+ observedAt: 1, stale: false, access: { ci: true, merge: true }, undecided: false, truncated: false
+})
+
+const author = (name: string, color: string): BoardLogEntry =>
+ ({ id: `e-${name}`, ts: 1, author: { name, color }, nodeId: 'n-lane', kind: 'comment', text: 'hi' })
+
+let root: Root | null = null
+let host: HTMLElement
+let local: WorkspaceSession
+
+beforeEach(() => {
+ vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
+ resetSessionsForTest()
+ local = createSession('local', {} as NodeTerminalApi, 'This computer')
+ setActiveSession(local.id)
+ useProjects.setState({ projects: [project(ACTIVE), project(LANE)], activeProjectId: ACTIVE } as never)
+ useGitHubIssues.setState({
+ projects: { [ACTIVE]: { pullBoard: pullBoard(99) } as never, [LANE]: { pullBoard: pullBoard(12) } as never }
+ })
+ useSettings.setState({
+ settings: {
+ ...useSettings.getState().settings,
+ kanbanPullAutoMove: {
+ projects: { [ACTIVE]: { columnId: 'doing', armedAt: 1 }, [LANE]: { columnId: 'done', armedAt: 1 } }
+ }
+ }
+ })
+ useBoardLog.setState({
+ entriesByProject: { [ACTIVE]: [author('Active Author', '#aa0000')], [LANE]: [author('Lane Author', '#00aa00')] },
+ unsupportedByProject: {},
+ errorByProject: {}
+ } as never)
+})
+afterEach(() => {
+ if (root) act(() => root!.unmount())
+ root = null
+ host?.remove()
+ document.body.innerHTML = ''
+ resetSessionsForTest()
+ vi.unstubAllGlobals()
+})
+
+/** Under App's LOCAL provider, as both boards are; the modal is scoped to the lane's project. */
+function renderInLane(child: React.ReactNode): void {
+ host = document.createElement('div')
+ document.body.appendChild(host)
+ root = createRoot(host)
+ act(() => {
+ root!.render(
+ <SessionProvider session={local}>
+ <ProjectSessionScope projectId={LANE}>{child}</ProjectSessionScope>
+ </SessionProvider>
+ )
+ })
+}
+
+const button = (text: string): HTMLButtonElement =>
+ [...host.querySelectorAll('button')].find((b) => b.textContent?.includes(text)) as HTMLButtonElement
+
+describe('CardPullRequests reads the card project, not the active one', () => {
+ it('lists the lane project\'s pull requests and unlinks the lane\'s PR number', () => {
+ const onChange = vi.fn()
+ renderInLane(<CardPullRequests session={session()} board={board} onChangeBoard={onChange} />)
+ expect(host.textContent).toContain('PR #12')
+ expect(host.textContent).not.toContain('PR #99')
+ act(() => button('Unlink').click())
+ const next = onChange.mock.calls[0][0] as ProjectKanban
+ expect(readPullLinks(next).unlinked).toEqual([{ nodeId: 'n-lane', pull: 12 }])
+ })
+
+ it('offers the lane project\'s auto-move target column', () => {
+ const onChange = vi.fn()
+ renderInLane(<CardPullRequests session={session()} board={board} onChangeBoard={onChange} />)
+ expect(host.textContent).toContain('Move this card to “Done” when its pull requests merge')
+ expect(host.textContent).not.toContain('“Doing”')
+ const optOut = host.querySelector<HTMLInputElement>('input[type="checkbox"]')!
+ act(() => optOut.click())
+ expect(readPullLinks(onChange.mock.calls[0][0] as ProjectKanban).noAutoMove).toEqual(['n-lane'])
+ })
+
+ it('takes the SSH flag from the lane project', () => {
+ useProjects.setState({ projects: [project(ACTIVE), project(LANE, true)] } as never)
+ renderInLane(<CardPullRequests session={session()} board={board} onChangeBoard={vi.fn()} />)
+ expect(host.textContent).toContain(PULL_LINK_SSH_REASON)
+ })
+
+ it('an SSH active project does not hide a local lane\'s links', () => {
+ useProjects.setState({ projects: [project(ACTIVE, true), project(LANE)] } as never)
+ renderInLane(<CardPullRequests session={session()} board={board} onChangeBoard={vi.fn()} />)
+ expect(host.textContent).not.toContain(PULL_LINK_SSH_REASON)
+ expect(host.textContent).toContain('PR #12')
+ })
+})
+
+describe('CardMetaBar reads the card project\'s board log, not the active one', () => {
+ it('offers the lane project\'s board-log authors and assigns the one picked', () => {
+ const onChange = vi.fn()
+ renderInLane(<CardMetaBar nodeId="n-lane" board={board} onChange={onChange} />)
+ act(() => (host.querySelector('button[title="Assign a member"]') as HTMLButtonElement).click())
+ expect(host.textContent).toContain('Lane Author')
+ expect(host.textContent).not.toContain('Active Author')
+ act(() => button('Lane Author').click())
+ const next = onChange.mock.calls[0][0] as ProjectKanban
+ expect(cardAssignees(cardMeta(next, 'n-lane')).map((a) => a.name)).toEqual(['Lane Author'])
+ })
+})
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index 3dd05b2f0..d6a28d0ac 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -295,7 +295,7 @@ import { useSshConn } from '../state/sshConn'
import { useWorktrees } from '../state/worktrees'
import { isRemoteSessionNode } from '@shared/worktree'
import { RunBar } from './RunBar'
-import { useSession, useActiveSessionPresence } from '../session/session'
+import { isRemoteProjectId, useSession, useActiveSessionPresence } from '../session/session'
import { isHostedReadOnly, useHostedReadOnly } from '../state/hostedTeams'
import { isBrowserRuntime } from '../bridge/runtime'
import { liveLinkUnavailable } from '../lib/liveLinkEntry'
@@ -1342,12 +1342,16 @@ export function TerminalNode({
}, [api])
// The ACTIVE project's presence — where our focus/blur casts go. It follows the active project,
// not this node's provider: Canvas keys the node subtree's SessionProvider on the project React
- // Flow's STORE holds (`useFlowStoreOwner`), which flips one commit after the active id. A node
- // mounts once the store holds its project, and by then that project is the active one, so the
- // value captured by the once-mounted lifecycle effect below is the presence of the core this node
- // runs on: a relay tab reports focus over the relay core, a local tab hits `defaultPresence`
- // (byte-identical to before). Render-time reads may briefly see the incoming project's presence
- // while an outgoing node waits to unmount.
+ // Flow's STORE holds (`useFlowStoreOwner`), which flips one commit after the active id. Usually a
+ // node mounts once its project is the active one, so the value the once-mounted lifecycle effect
+ // below captures is the presence of the core this node runs on: a relay tab reports focus over the
+ // relay core, a local tab hits `defaultPresence` (byte-identical to before). NOT always: when the
+ // last team tab closes, the welcome screen sets the active project to null while the store still
+ // holds the team project's nodes, and in a rapid A→B→C switch the store can hold B while C is
+ // active. In those windows this node's `useSession()` (its own core) and this presence (the active
+ // project's) can point at different cores. The effect is negligible today: those nodes cannot be
+ // focused (the welcome screen covers them; B's nodes unmount once C lands). Reading this node's
+ // own session's presence instead is a follow-up.
const presence = useActiveSessionPresence()
/**
* THIS node's agent-status store, for the memory levers that must not kill live work — resolved
@@ -3584,7 +3588,8 @@ export function TerminalNode({
// session — this desktop's own core — would create the host's node id HERE. Canvas keys the
// subtree on the project React Flow's store holds, and an unbound remote tab resolves to the
// offline relay session, so this is the last line: start nothing, before any SSH resolve.
- if (spawnBelongsElsewhere(useProjects.getState().getProject(owningProjectRef.current ?? ''), session.source)) {
+ // `isRemoteProjectId` is sessionForProject's own rule, so a tab the store deleted still counts.
+ if (spawnBelongsElsewhere(isRemoteProjectId(owningProjectRef.current ?? ''), session.source)) {
term.write(
`\r\n\x1b[90m${REMOTE_PROJECT_SPAWN_REFUSAL}\x1b[0m\r\n`
)
diff --git a/src/renderer/session/owning-project.test.ts b/src/renderer/session/owning-project.test.ts
index 68df128de..1326a65b3 100644
--- a/src/renderer/session/owning-project.test.ts
+++ b/src/renderer/session/owning-project.test.ts
@@ -1,28 +1,65 @@
-import { describe, expect, it } from 'vitest'
+// @vitest-environment jsdom
+import { afterEach, beforeEach, describe, expect, it } from 'vitest'
+import type { NodeTerminalApi, Project } from '@shared/types'
import { spawnBelongsElsewhere } from './owning-project'
+import { bindProjectToSession, createSession, disposeSession, isRemoteProjectId, resetSessionsForTest } from './session'
+import { useProjects } from '../state/projects'
// The create-time half of bug F's defense (F2c): a node of a REMOTE project (a hosted team / relay
// tab) that finds itself under a session which is not a relay session must start nothing — that
// session is this desktop's own core, and the node id belongs to the host.
describe('spawnBelongsElsewhere', () => {
it('a remote project under a non-relay session belongs elsewhere', () => {
- expect(spawnBelongsElsewhere({ remote: true }, 'local')).toBe(true)
- expect(spawnBelongsElsewhere({ remote: true }, 'server')).toBe(true)
+ expect(spawnBelongsElsewhere(true, 'local')).toBe(true)
+ expect(spawnBelongsElsewhere(true, 'server')).toBe(true)
})
it('a remote project under a relay session is where it belongs', () => {
- expect(spawnBelongsElsewhere({ remote: true }, 'relay')).toBe(false)
+ expect(spawnBelongsElsewhere(true, 'relay')).toBe(false)
})
- it('a local project never belongs elsewhere, whatever the session', () => {
- expect(spawnBelongsElsewhere({}, 'local')).toBe(false)
- expect(spawnBelongsElsewhere({ remote: false }, 'local')).toBe(false)
- expect(spawnBelongsElsewhere({}, 'relay')).toBe(false)
- expect(spawnBelongsElsewhere({}, 'server')).toBe(false)
+ it('a project that is not remote never belongs elsewhere, whatever the session', () => {
+ expect(spawnBelongsElsewhere(false, 'local')).toBe(false)
+ expect(spawnBelongsElsewhere(false, 'relay')).toBe(false)
+ expect(spawnBelongsElsewhere(false, 'server')).toBe(false)
+ })
+})
+
+// The question the terminals ask before it: `isRemoteProjectId` is the same rule
+// `sessionForProject`'s unbound branch uses, so a tab the store has deleted still reads as remote
+// (a store-only `getProject(id)?.remote` read answered false for it).
+const TEAM = 'project-team'
+const LOCAL = 'project-local'
+const project = (id: string, remote = false): Project =>
+ ({ id, name: id, color: '#888', viewport: { x: 0, y: 0, zoom: 1 }, nodes: [], ...(remote ? { remote: true } : {}) }) as unknown as Project
+
+describe('isRemoteProjectId', () => {
+ beforeEach(() => {
+ resetSessionsForTest()
+ useProjects.setState({ projects: [project(TEAM, true), project(LOCAL)], activeProjectId: LOCAL } as never)
+ })
+ afterEach(() => resetSessionsForTest())
+
+ it('answers the store while the store holds the project', () => {
+ expect(isRemoteProjectId(TEAM)).toBe(true)
+ expect(isRemoteProjectId(LOCAL)).toBe(false)
+ })
+
+ it('a remote tab the store has since deleted stays remote once it was bound while remote', () => {
+ const relay = createSession('relay', {} as NodeTerminalApi, 'Team')
+ bindProjectToSession(TEAM, relay.id)
+ disposeSession(relay.id)
+ useProjects.setState({ projects: [project(LOCAL)] } as never)
+ expect(isRemoteProjectId(TEAM)).toBe(true)
+ // The terminals' composed question: refused under this desktop's own session.
+ expect(spawnBelongsElsewhere(isRemoteProjectId(TEAM), 'local')).toBe(true)
})
- it('an unknown project is not evidence of anything', () => {
- expect(spawnBelongsElsewhere(undefined, 'local')).toBe(false)
- expect(spawnBelongsElsewhere(undefined, 'relay')).toBe(false)
+ it('an id the store never held as remote, and no project at all, are not evidence of anything', () => {
+ expect(isRemoteProjectId('project-never-seen')).toBe(false)
+ expect(isRemoteProjectId('')).toBe(false)
+ expect(spawnBelongsElsewhere(isRemoteProjectId(''), 'local')).toBe(false)
+ // A local project's own id is never remote, so its terminals are byte-identical.
+ expect(spawnBelongsElsewhere(isRemoteProjectId(LOCAL), 'local')).toBe(false)
})
})
diff --git a/src/renderer/session/owning-project.ts b/src/renderer/session/owning-project.ts
index 4ebbc50e1..dc796cbff 100644
--- a/src/renderer/session/owning-project.ts
+++ b/src/renderer/session/owning-project.ts
@@ -8,10 +8,11 @@ import { SessionProvider, sessionForProject, type SessionSource } from './sessio
* `null` = not known: outside any provider, or before React Flow has held a project.
*
* It exists beside the SessionProvider because a session alone cannot say whether a node is in
- * the right place. An unbound remote project resolves to the offline relay session, whose calls
- * all reject — but a node of a remote project that ends up under a LOCAL session anyway (a provider
- * keyed on the wrong project, a surface mounted outside any project's provider) would create its
- * host-side id on this core. The terminal asks `spawnBelongsElsewhere` with this id before it spawns.
+ * the right place. An unbound remote project resolves to the offline relay session, whose
+ * core-bound calls reject — but a node of a remote project that ends up under a LOCAL session
+ * anyway (a provider keyed on the wrong project, a surface mounted outside any project's provider)
+ * would create its host-side id on this core. The terminal asks
+ * `spawnBelongsElsewhere(isRemoteProjectId(<this id>), session.source)` before it spawns.
*/
export const OwningProjectContext = createContext<string | null>(null)
@@ -25,13 +26,17 @@ export const REMOTE_PROJECT_SPAWN_REFUSAL =
'[this terminal belongs to a remote project that is not connected here — nothing was started on this machine]'
/**
- * True when a spawn for a node of `project` would land on the wrong core: the project lives on
- * another machine (`remote`, a hosted team / relay tab) but the session the node runs under is not
- * a relay session — it is this desktop's own core. The caller must then start nothing.
- * An unknown project (undefined) is not evidence of anything and answers false.
+ * True when a spawn for a node of a project would land on the wrong core: the project lives on
+ * another machine (`projectIsRemote`, a hosted team / relay tab) but the session the node runs
+ * under is not a relay session — it is this desktop's own core. The caller must then start nothing.
+ *
+ * Pure on purpose. Callers pass `isRemoteProjectId(<owning project id>)` (session.ts) — the same
+ * rule `sessionForProject` uses, so a tab the projects store has deleted still reads as remote
+ * here. An unknown project ('' or an id never held as remote) answers false there, which is not
+ * evidence of anything.
*/
-export function spawnBelongsElsewhere(project: { remote?: boolean } | undefined, source: SessionSource): boolean {
- return !!project?.remote && source !== 'relay'
+export function spawnBelongsElsewhere(projectIsRemote: boolean, source: SessionSource): boolean {
+ return projectIsRemote && source !== 'relay'
}
/**
diff --git a/src/renderer/session/session.ts b/src/renderer/session/session.ts
index 4b2e78c26..8b9fb9b8c 100644
--- a/src/renderer/session/session.ts
+++ b/src/renderer/session/session.ts
@@ -299,14 +299,26 @@ export function sessionForProject(projectId: string): WorkspaceSession {
return off ? off.session : localOrActiveSession()
}
-/** The offline session's entry when `projectId` is a REMOTE project — `remote` in the projects
- * store, or (once the store no longer holds it) bound while it was (`KNOWN_REMOTE`) — the one rule
- * `sessionForProject` and `presenceForProject` share. The caller has already found no live binding.
- * `null` for any other id, or when no offline factory is registered. */
-function offlineForUnboundRemote(projectId: string): Entry | null {
- if (!projectId) return null
+/** True when `projectId` names a REMOTE project (a relay / hosted team tab): `remote` in the
+ * projects store, or, once the store no longer holds it, bound to a session while it was
+ * (`KNOWN_REMOTE`). The store's own answer wins whenever it still holds the project. '' (no
+ * project, the welcome screen) and an id the store never held as remote answer false.
+ *
+ * The ONE remote-project rule: `sessionForProject`'s unbound branch (via `offlineForUnboundRemote`)
+ * and the terminals' spawn refusal (`spawnBelongsElsewhere(isRemoteProjectId(owner), …)` in
+ * TerminalNode / ModalTerminal) both ask it, so they cannot disagree about a tab the store has
+ * deleted. */
+export function isRemoteProjectId(projectId: string): boolean {
+ if (!projectId) return false
const stored = useProjects.getState().getProject(projectId)
- if (!(stored ? stored.remote : KNOWN_REMOTE.has(projectId))) return null
+ return stored ? !!stored.remote : KNOWN_REMOTE.has(projectId)
+}
+
+/** The offline session's entry when `projectId` is a REMOTE project (`isRemoteProjectId`) — the
+ * rule `sessionForProject` and `presenceForProject` share. The caller has already found no live
+ * binding. `null` for any other id, or when no offline factory is registered. */
+function offlineForUnboundRemote(projectId: string): Entry | null {
+ if (!isRemoteProjectId(projectId)) return null
return offlineEntry()
}