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(renderer): a live-link row is judged by its node's project; a closed relay tab is never named

review627bcf5279a8
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index ad469c024..58f5cf8ca 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -247,8 +247,7 @@ import { startWatchLinkSync, useWatchLinks } from '../state/watchLinks'
import { noticeText } from '../lib/liveLink'
import {
liveLinkCommands,
- liveLinkMenuRow,
- liveLinkNodeFor,
+ liveLinkMenuItemsFor,
liveLinkPrepare,
openLiveLink,
stopAllConfirm,
@@ -3583,19 +3582,16 @@ export function Canvas() {
const liveLinkMenuItems = useCallback(
(nodeId: string, projectId?: string): MenuItem[] => {
const store = useProjects.getState()
- const pid = projectId ?? store.activeProjectId
- if (!pid) return []
- return liveLinkMenuRow({
- node: liveLinkNodeFor({
- nodeId,
- projectId: pid,
- activeProjectId: store.activeProjectId,
- live: nodesRef.current,
- stored: store.getProject(pid)?.nodes
- }),
- projectId: pid,
+ // The composition (which project, which node, whose facts) is lib/liveLinkEntry's, where it is
+ // behaviour-tested: the facts are the NODE's project's, never the active tab's (D2/M1).
+ return liveLinkMenuItemsFor({
+ nodeId,
+ projectId,
+ activeProjectId: store.activeProjectId,
+ live: nodesRef.current,
+ stored: (pid) => store.getProject(pid)?.nodes,
hidden: useSettings.getState().settings.hiddenNodeMenuItems,
- facts: liveLinkFacts(pid),
+ facts: liveLinkFacts,
icon: <IconBroadcast />,
open: openLiveLinkFor
})
diff --git a/src/renderer/canvas/live-link-wiring.test.ts b/src/renderer/canvas/live-link-wiring.test.ts
index db8a6f73c..2bdf42c03 100644
--- a/src/renderer/canvas/live-link-wiring.test.ts
+++ b/src/renderer/canvas/live-link-wiring.test.ts
@@ -75,6 +75,13 @@ describe('Canvas live-link wiring', () => {
expect(cmds.slice(0, 400)).toContain('serverEdition: isBrowserRuntime(),')
})
+ it("D2/M1: the row is composed by the lib with the facts FUNCTION (the node's project's facts)", () => {
+ const items = callback('liveLinkMenuItems')
+ expect(items).toContain('liveLinkMenuItemsFor({')
+ expect(items).toContain('facts: liveLinkFacts,')
+ expect(items).toContain('projectId,')
+ })
+
it('one row builder, declared before selectionItems and listed in its deps (H15)', () => {
const builder = src.indexOf('const liveLinkMenuItems = useCallback(')
const selection = src.indexOf('const selectionItems = useCallback(')
diff --git a/src/renderer/components/settings/sections/LiveLinksSection.test.tsx b/src/renderer/components/settings/sections/LiveLinksSection.test.tsx
index 1bbe570f8..6c3985075 100644
--- a/src/renderer/components/settings/sections/LiveLinksSection.test.tsx
+++ b/src/renderer/components/settings/sections/LiveLinksSection.test.tsx
@@ -154,6 +154,24 @@ describe('LiveLinksSection', () => {
expect(host.innerHTML).not.toContain('SECRET')
})
+ // D2/M2: closing a relay tab unbinds its session, so its source reads LOCAL — but it is still the
+ // other machine's canvas, and its copy of a git-shared node id is not this machine's node.
+ it("never names a CLOSED relay tab's project for this machine's link", () => {
+ act(() =>
+ useProjects.setState({
+ projects: [
+ { id: 'p-peer', name: 'PeerProject', closed: true, remote: true, nodes: [{ id: 'n1', kind: 'terminal', title: 'theirs' }] },
+ { id: 'p-mine', name: 'Mine', closed: true, nodes: [{ id: 'n1', kind: 'terminal', title: 'build' }] }
+ ]
+ } as never)
+ )
+ render()
+ setLinks([link()])
+ const row = host.querySelector<HTMLElement>('.live-settings__row')!
+ expect(row.textContent).toContain('Mine (closed)')
+ expect(row.textContent).not.toContain('PeerProject')
+ })
+
it('Copy copies the URL', () => {
render()
setLinks([link()])
diff --git a/src/renderer/components/settings/sections/LiveLinksSection.tsx b/src/renderer/components/settings/sections/LiveLinksSection.tsx
index 6b27e06f2..ec1d48009 100644
--- a/src/renderer/components/settings/sections/LiveLinksSection.tsx
+++ b/src/renderer/components/settings/sections/LiveLinksSection.tsx
@@ -35,11 +35,17 @@ const ENTRIES = Object.values(ROWS)
* Which project a link's node is in, as the row names it (H11): an open project on THIS machine
* first, else a closed one (a closed project keeps its sessions running, so its links run too),
* else "not in an open project". A project bound to a relay session is another machine's canvas —
- * a node there with the same id is not the node this machine's link broadcasts (R57).
+ * a node there with the same id is not the node this machine's link broadcasts (R57). A CLOSED relay
+ * tab no longer has a session (closing it unbinds the project, so its source reads as the local one),
+ * which is why `remote` — the relay tab's own mark — is checked too (D2/M2).
*/
export function liveLinkProjectLabel(projects: readonly Project[], nodeId: string): string {
const holders = projects.filter(
- (p) => Array.isArray(p.nodes) && p.nodes.some((n) => n?.id === nodeId) && showsLiveLinks(projectSessionSource(p.id))
+ (p) =>
+ !p.remote &&
+ Array.isArray(p.nodes) &&
+ p.nodes.some((n) => n?.id === nodeId) &&
+ showsLiveLinks(projectSessionSource(p.id))
)
const open = holders.find((p) => !p.closed)
if (open) return open.name
diff --git a/src/renderer/lib/liveLinkEntry.test.tsx b/src/renderer/lib/liveLinkEntry.test.tsx
index ee500e84d..d821c4b12 100644
--- a/src/renderer/lib/liveLinkEntry.test.tsx
+++ b/src/renderer/lib/liveLinkEntry.test.tsx
@@ -3,6 +3,7 @@
import { describe, it, expect, vi } from 'vitest'
import {
liveLinkCommands,
+ liveLinkMenuItemsFor,
liveLinkMenuRow,
liveLinkNodeFor,
liveLinkPrepare,
@@ -173,6 +174,48 @@ describe('liveLinkNodeFor (R49)', () => {
})
})
+// D2/M1: the composition Canvas calls for every surface. With a LOCAL tab on screen, a non-active
+// RELAY project's sidebar row (or Omni lane card) must be judged by THAT project's session.
+describe('liveLinkMenuItemsFor (D2/M1)', () => {
+ const stored: Record<string, { id: string; kind: string; title: string }[]> = {
+ 'p-relay': [{ id: 'n9', kind: 'terminal', title: 'theirs' }],
+ 'p-local': [{ id: 'n1', kind: 'terminal', title: 'ours' }]
+ }
+ const factsOf = (projectId: string): LiveLinkAvailabilityFacts =>
+ facts({ source: projectId === 'p-relay' ? 'relay' : 'local' })
+ const compose = (over: Partial<Parameters<typeof liveLinkMenuItemsFor>[0]>) =>
+ liveLinkMenuItemsFor({
+ nodeId: 'n9',
+ projectId: 'p-relay',
+ activeProjectId: 'p-local',
+ live: [{ id: 'n1', type: 'terminal', data: { title: 'ours' } }],
+ stored: (pid) => stored[pid],
+ hidden: [],
+ facts: factsOf,
+ icon: null,
+ open: vi.fn(),
+ ...over
+ })
+
+ it("a non-active relay project's node is judged by ITS session, not the active local tab's", () => {
+ const open = vi.fn()
+ const rows = compose({ open })
+ expect(rows).toHaveLength(1)
+ expect(rows[0]).toMatchObject({ disabled: true, hint: RELAY })
+ ;(rows[0] as { onClick: () => void }).onClick()
+ expect(open).toHaveBeenCalledWith({ nodeId: 'n9', title: 'theirs', projectId: 'p-relay' })
+ })
+
+ it('no project given: the active one, read from the live canvas', () => {
+ const open = vi.fn()
+ const rows = compose({ nodeId: 'n1', projectId: undefined, open })
+ expect(rows[0]).toMatchObject({ disabled: false })
+ ;(rows[0] as { onClick: () => void }).onClick()
+ expect(open).toHaveBeenCalledWith({ nodeId: 'n1', title: 'ours', projectId: 'p-local' })
+ expect(compose({ projectId: undefined, activeProjectId: null })).toEqual([])
+ })
+})
+
describe('liveLinkPrepare (R47)', () => {
it('nothing to save: no save, no refusal', async () => {
const save = vi.fn(async () => true)
diff --git a/src/renderer/lib/liveLinkEntry.tsx b/src/renderer/lib/liveLinkEntry.tsx
index fcae60e1c..a653e9615 100644
--- a/src/renderer/lib/liveLinkEntry.tsx
+++ b/src/renderer/lib/liveLinkEntry.tsx
@@ -134,6 +134,42 @@ export function liveLinkMenuRow(o: {
]
}
+/**
+ * The menu row for one node, composed (D2/M1): which project the node is in (the caller's, else the
+ * active one), where to read the node (live canvas or stored copy), and the availability facts — of
+ * THAT project, never the active one. A non-active relay project's sidebar row or Omni lane card was
+ * judged by the active LOCAL tab's facts, and showed an enabled row the opener then refused.
+ */
+export function liveLinkMenuItemsFor(o: {
+ nodeId: string
+ /** The node's own project; absent = the active one (the canvas node menu). */
+ projectId?: string
+ activeProjectId: string | null
+ live: readonly { id: string; type?: string; data?: { title?: unknown } }[]
+ stored: (projectId: string) => readonly { id: string; kind?: string; title?: unknown }[] | undefined
+ hidden: readonly string[]
+ facts: (projectId: string) => LiveLinkAvailabilityFacts
+ icon: ReactNode
+ open: (target: LiveLinkTarget) => void
+}): MenuItem[] {
+ const pid = o.projectId ?? o.activeProjectId
+ if (!pid) return []
+ return liveLinkMenuRow({
+ node: liveLinkNodeFor({
+ nodeId: o.nodeId,
+ projectId: pid,
+ activeProjectId: o.activeProjectId,
+ live: o.live,
+ stored: o.stored(pid)
+ }),
+ projectId: pid,
+ hidden: o.hidden,
+ facts: o.facts(pid),
+ icon: o.icon,
+ open: o.open
+ })
+}
+
/**
* R47: before a create, publish pending canvas edits — a node opened seconds ago is not in the
* saved project core checks, and would answer `node-missing`. The existing rule for "publish before