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(context-link): keep background projects' links alive; defuse the connect note

enesc93c4e7325be
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 8221f4ef2..8028925ff 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -132,7 +132,7 @@ import {
import { relativeTime } from '../lib/relativeTime'
import { AgentIcon } from '../lib/agentIcons'
import { branchClaudeSession } from '../lib/claudeBranch'
-import { buildContextLinkNote, buildLinkMap, buildNotePushMessage, classifyLink, type LinkEndpoint } from '../lib/noteLink'
+import { buildBackgroundLinkMaps, buildContextLinkNote, buildLinkMap, buildNotePushMessage, classifyLink, type LinkEndpoint } from '../lib/noteLink'
import { useSettings } from '../state/settings'
import { activePermissionMode } from '../state/permissionMode'
import { useRemoteHosting } from '../state/remoteHosting'
@@ -1583,7 +1583,14 @@ export function Canvas() {
accountId: sticky ? undefined : ((n?.data.accountId as string) || undefined)
}
}
- const map = buildLinkMap(valid, infoOf)
+ // Merge in the link maps of every OTHER project (from their serialized nodes + bridges):
+ // main clears all link files before writing the pushed map, so pushing only the active
+ // project's map would sever the links of background projects whose agents keep running.
+ const { projects, activeProjectId } = useProjects.getState()
+ const map = {
+ ...buildBackgroundLinkMaps(projects, activeProjectId, (id) => useAgentStatus.getState().byId[id]?.sessionId),
+ ...buildLinkMap(valid, infoOf)
+ }
const t = setTimeout(() => void window.nodeTerminal.contextLink.setLinks(map), 150)
return () => clearTimeout(t)
// linkSessionSig is read only as an effect trigger — infoOf re-reads sessionIds via getState().
diff --git a/src/renderer/lib/noteLink.test.ts b/src/renderer/lib/noteLink.test.ts
index 6879570ab..f7b785469 100644
--- a/src/renderer/lib/noteLink.test.ts
+++ b/src/renderer/lib/noteLink.test.ts
@@ -1,5 +1,12 @@
import { describe, it, expect } from 'vitest'
-import { buildContextLinkNote, buildLinkMap, buildNotePushMessage, classifyLink } from './noteLink'
+import {
+ buildBackgroundLinkMaps,
+ buildContextLinkNote,
+ buildLinkMap,
+ buildNotePushMessage,
+ classifyLink
+} from './noteLink'
+import type { CanvasNodeState } from '@shared/types'
const term = (contextCapable = false) => ({ kind: 'terminal', contextCapable })
const sticky = () => ({ kind: 'sticky', contextCapable: false })
@@ -98,10 +105,10 @@ describe('buildLinkMap agent identity', () => {
})
describe('buildContextLinkNote', () => {
- it('claude gets the skill wording (unchanged legacy text)', () => {
- expect(buildContextLinkNote('claude', 'Builder', '/x/context.sh')).toBe(
- '[nodeterm] You are now linked to "Builder". Use the get-linked-context skill to read its context when you need it.'
- )
+ it('claude gets the skill wording', () => {
+ const msg = buildContextLinkNote('claude', 'Builder', '/x/context.sh')
+ expect(msg).toContain('[nodeterm] You are now linked to "Builder"')
+ expect(msg).toContain('get-linked-context skill')
})
it('codex/gemini get the inline CLI command, single line', () => {
const msg = buildContextLinkNote('codex', 'Builder', '/x/context.sh')
@@ -109,6 +116,84 @@ describe('buildContextLinkNote', () => {
expect(msg).toContain('Builder')
expect(msg).not.toContain('\n')
})
+ it('every variant says the note is informational — no action now', () => {
+ // The message is injected + submitted as a prompt, so an agent that reads it as a task
+ // launches an unsolicited investigation (observed with gemini). It must self-defuse.
+ for (const agent of [undefined, 'claude', 'codex', 'gemini']) {
+ const msg = buildContextLinkNote(agent, 'Builder', '/x/context.sh')
+ expect(msg, `agent=${agent}`).toMatch(/[Nn]o action/)
+ expect(msg, `agent=${agent}`).not.toContain('\n')
+ }
+ })
+})
+
+describe('buildBackgroundLinkMaps', () => {
+ const node = (over: Partial<CanvasNodeState>): CanvasNodeState =>
+ ({
+ id: 'x',
+ kind: 'terminal',
+ position: { x: 0, y: 0 },
+ size: { width: 1, height: 1 },
+ title: '',
+ color: '',
+ group: null,
+ ...over
+ }) as CanvasNodeState
+ const projects = [
+ {
+ id: 'p-active',
+ nodes: [node({ id: 'a1', agentId: 'claude' }), node({ id: 'a2', agentId: 'codex' })],
+ bridges: [{ id: 'e0', source: 'a1', target: 'a2' }]
+ },
+ {
+ id: 'p-bg',
+ nodes: [
+ node({ id: 'b1', title: 'Fitness', cwd: '/fit', agentId: 'claude', accountId: 'acct-1' }),
+ node({ id: 'b2', title: 'Gem', cwd: '/fit', agentId: 'gemini' }),
+ node({ id: 'b3', kind: 'sticky', title: 'Note', text: 'remember this' })
+ ],
+ bridges: [
+ { id: 'e1', source: 'b1', target: 'b2' },
+ { id: 'e2', source: 'b3', target: 'b1' }
+ ]
+ },
+ { id: 'p-nolinks', nodes: [node({ id: 'c1' })], bridges: [] }
+ ]
+
+ it('maps every project except the active one (React Flow owns that live)', () => {
+ const map = buildBackgroundLinkMaps(projects, 'p-active', () => undefined)
+ expect(map['a1']).toBeUndefined()
+ expect(map['a2']).toBeUndefined()
+ expect(map['b1']).toBeDefined()
+ expect(map['b2']).toEqual([
+ { id: 'b1', title: 'Fitness', cwd: '/fit', agentId: 'claude', accountId: 'acct-1' }
+ ])
+ })
+ it('serialized stickies map one-way with their text', () => {
+ const map = buildBackgroundLinkMaps(projects, 'p-active', () => undefined)
+ expect(map['b1']).toContainEqual({ id: 'b3', title: 'Note', note: 'remember this' })
+ expect(map['b3']).toBeUndefined()
+ })
+ it('threads sessionIds from the callback', () => {
+ const map = buildBackgroundLinkMaps(projects, 'p-active', (id) =>
+ id === 'b2' ? 'sess-b2' : undefined
+ )
+ expect(map['b1']).toContainEqual({
+ id: 'b2',
+ title: 'Gem',
+ cwd: '/fit',
+ agentId: 'gemini',
+ sessionId: 'sess-b2'
+ })
+ })
+ it('drops edges whose endpoints are gone from the serialized nodes', () => {
+ const map = buildBackgroundLinkMaps(
+ [{ id: 'p', nodes: [node({ id: 'z1' })], bridges: [{ id: 'e', source: 'z1', target: 'gone' }] }],
+ null,
+ () => undefined
+ )
+ expect(map).toEqual({})
+ })
})
describe('buildNotePushMessage per-agent wording', () => {
diff --git a/src/renderer/lib/noteLink.ts b/src/renderer/lib/noteLink.ts
index 87ea205b7..020b8162c 100644
--- a/src/renderer/lib/noteLink.ts
+++ b/src/renderer/lib/noteLink.ts
@@ -2,7 +2,7 @@
// agent nodes vs. note link between a sticky and a terminal), build the one-shot push
// message a note link injects into an agent session, and build the link map pushed to main.
// Kept free of React/store imports so the connection matrix is unit-testable.
-import type { ContextLinkInfo, ContextLinkMap } from '@shared/types'
+import type { BridgeLink, CanvasNodeState, ContextLinkInfo, ContextLinkMap } from '@shared/types'
export interface LinkEndpoint {
/** React Flow node type: 'terminal' | 'sticky' | 'editor' | … */
@@ -54,10 +54,13 @@ export function buildContextLinkNote(
otherTitle: string,
shimPath: string
): string {
+ // Both variants must self-defuse: the note is injected + submitted as a prompt, and an
+ // agent that reads it as a task launches an unsolicited investigation of the linked node
+ // (observed with gemini). "No action needed" keeps it a notification.
if (!agentId || agentId === 'claude') {
- return `[nodeterm] You are now linked to "${otherTitle}". Use the get-linked-context skill to read its context when you need it.`
+ return `[nodeterm] You are now linked to "${otherTitle}". Use the get-linked-context skill to read its context when you need it. No action needed now — just acknowledge briefly.`
}
- return `[nodeterm] You are now linked to "${otherTitle}". To read its context run: sh "${shimPath}" list — then summary | transcript | terminal --node <id>. Details are in the get-linked-context section of your global agent instructions.`
+ return `[nodeterm] You are now linked to "${otherTitle}". When you need its context (and only then) run: sh "${shimPath}" list — then summary | transcript | terminal --node <id>. Details are in the get-linked-context section of your global agent instructions. No action needed now — acknowledge briefly and do not run these commands yet.`
}
export interface LinkNodeInfo {
@@ -104,3 +107,40 @@ export function buildLinkMap(
}
return map
}
+
+/**
+ * Link maps for every project EXCEPT the active one, built from the projects store's
+ * serialized nodes + bridges. The active project's map is built live from React Flow; this
+ * covers the rest, because main's writeLinkFiles clears ALL link files before writing the
+ * pushed map — pushing only the active project's map deleted the link files of background
+ * projects whose tmux sessions (and agents mid-task) were still running.
+ * Node ids are globally unique across projects, so the maps merge without collisions.
+ */
+export function buildBackgroundLinkMaps(
+ projects: Array<{ id: string; nodes: CanvasNodeState[]; bridges?: BridgeLink[] }>,
+ activeProjectId: string | null,
+ sessionIdOf: (nodeId: string) => string | undefined
+): ContextLinkMap {
+ const map: ContextLinkMap = {}
+ for (const p of projects) {
+ if (p.id === activeProjectId || !p.bridges?.length) continue
+ const byId = new Map(p.nodes.map((n) => [n.id, n]))
+ const edges = p.bridges.filter((e) => byId.has(e.source) && byId.has(e.target))
+ const infoOf = (id: string): LinkNodeInfo => {
+ const n = byId.get(id)!
+ const sticky = n.kind === 'sticky'
+ return {
+ id,
+ title: n.title || id,
+ cwd: n.cwd ?? '',
+ note: sticky ? (n.text ?? '') : undefined,
+ sticky,
+ agentId: sticky ? undefined : n.agentId,
+ sessionId: !sticky && n.agentId ? sessionIdOf(id) : undefined,
+ accountId: sticky ? undefined : n.accountId
+ }
+ }
+ Object.assign(map, buildLinkMap(edges, infoOf))
+ }
+ return map
+}