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.

feat(context-link): per-agent transcript resolution via handoff locators

enesd6d2a2c1e8bb
diff --git a/src/main/context-link-core.test.ts b/src/main/context-link-core.test.ts
index 3e7851fb1..43f041de3 100644
--- a/src/main/context-link-core.test.ts
+++ b/src/main/context-link-core.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
-import { buildLinkDoc, setNodeTranscript, transcriptPathOf } from './context-link-core'
+import { buildLinkDoc, resolveLinkTranscript, setNodeTranscript, transcriptPathOf } from './context-link-core'
describe('buildLinkDoc', () => {
it('enriches each link with tmux name, injected transcript path, and cwd', () => {
@@ -45,6 +45,70 @@ describe('buildLinkDoc', () => {
})
})
+describe('buildLinkDoc agent field', () => {
+ it('copies agentId onto the entry; notes get none', () => {
+ const doc = buildLinkDoc(
+ 'node-A',
+ [
+ { id: 'node-B', title: 'B', cwd: '', agentId: 'codex' },
+ { id: 'note-1', title: 'N', note: 'txt' }
+ ],
+ { transcriptOf: () => '', tmuxBin: null, tmuxSocket: 's' }
+ )
+ expect(doc.links[0].agent).toBe('codex')
+ expect(doc.links[1].agent).toBeUndefined()
+ })
+})
+
+describe('resolveLinkTranscript', () => {
+ const locators = {
+ claude: async (sid: string, acct?: string) => `/c/${acct ?? 'default'}/${sid}.jsonl`,
+ codex: async (sid: string) => `/x/${sid}.jsonl`,
+ gemini: async (sid: string) => `/g/${sid}.jsonl`
+ }
+ it('claude prefers the hook-fed path', async () => {
+ const p = await resolveLinkTranscript(
+ { id: 'n1', title: 'T', agentId: 'claude', sessionId: 's1' },
+ { hooked: () => '/hooked.jsonl', locators }
+ )
+ expect(p).toBe('/hooked.jsonl')
+ })
+ it('claude falls back to the locator with accountId when hooks have nothing', async () => {
+ const p = await resolveLinkTranscript(
+ { id: 'n1', title: 'T', agentId: 'claude', sessionId: 's1', accountId: 'a1' },
+ { hooked: () => '', locators }
+ )
+ expect(p).toBe('/c/a1/s1.jsonl')
+ })
+ it('a legacy entry without agentId behaves like claude', async () => {
+ const p = await resolveLinkTranscript(
+ { id: 'n1', title: 'T' },
+ { hooked: () => '/hooked.jsonl', locators }
+ )
+ expect(p).toBe('/hooked.jsonl')
+ })
+ it('codex and gemini resolve via their locator by sessionId', async () => {
+ expect(
+ await resolveLinkTranscript({ id: 'n', title: 'T', agentId: 'codex', sessionId: 's2' }, { hooked: () => '/hooked', locators })
+ ).toBe('/x/s2.jsonl')
+ expect(
+ await resolveLinkTranscript({ id: 'n', title: 'T', agentId: 'gemini', sessionId: 's3' }, { hooked: () => '/hooked', locators })
+ ).toBe('/g/s3.jsonl')
+ })
+ it('resolves empty on: note entries, missing sessionId, unknown agent, locator throw', async () => {
+ const base = { hooked: () => '', locators }
+ expect(await resolveLinkTranscript({ id: 'n', title: 'T', note: 'x' }, base)).toBe('')
+ expect(await resolveLinkTranscript({ id: 'n', title: 'T', agentId: 'codex' }, base)).toBe('')
+ expect(await resolveLinkTranscript({ id: 'n', title: 'T', agentId: 'custom:x', sessionId: 's' }, base)).toBe('')
+ expect(
+ await resolveLinkTranscript(
+ { id: 'n', title: 'T', agentId: 'codex', sessionId: 's' },
+ { hooked: () => '', locators: { codex: async () => { throw new Error('boom') } } }
+ )
+ ).toBe('')
+ })
+})
+
describe('setNodeTranscript / transcriptPathOf', () => {
it('stores and returns the transcript path by node id', () => {
setNodeTranscript('n1', 'sess', '/path/one.jsonl')
diff --git a/src/main/context-link-core.ts b/src/main/context-link-core.ts
index 88eccb7bf..f1be0a506 100644
--- a/src/main/context-link-core.ts
+++ b/src/main/context-link-core.ts
@@ -13,12 +13,41 @@ export function transcriptPathOf(nodeId: string): string {
return nodeTranscript.get(nodeId) ?? ''
}
+export type TranscriptLocator = (sessionId: string, accountId?: string) => Promise<string | undefined>
+
+/**
+ * Resolve one link entry's transcript path. Claude (and legacy entries without an
+ * agentId) prefer the hook-fed path; every agent falls back to its locator by
+ * sessionId. Notes, unknown agents, and locator errors resolve to '' (fail open —
+ * the CLI prints a clear "no transcript yet" message).
+ */
+export async function resolveLinkTranscript(
+ link: { id: string; title?: string; agentId?: string; sessionId?: string; accountId?: string; note?: string },
+ deps: { hooked: (id: string) => string; locators: Record<string, TranscriptLocator> }
+): Promise<string> {
+ if (link.note != null) return ''
+ const agent = link.agentId ?? 'claude'
+ if (agent === 'claude') {
+ const hooked = deps.hooked(link.id)
+ if (hooked) return hooked
+ }
+ const locate = deps.locators[agent]
+ if (!locate || !link.sessionId) return ''
+ try {
+ return (await locate(link.sessionId, link.accountId)) ?? ''
+ } catch {
+ return ''
+ }
+}
+
export interface LinkDocEntry {
id: string
title: string
cwd: string
transcriptPath: string
tmux: string
+ /** Which agent CLI produced the transcript ('claude' | 'codex' | 'gemini') — selects the parser. */
+ agent?: string
/** Present when this entry is a sticky note: its text. Note entries have no transcript/terminal. */
note?: string
}
@@ -46,6 +75,7 @@ export function buildLinkDoc(
transcriptPath: isNote ? '' : ctx.transcriptOf(n.id),
tmux: isNote ? '' : sessionName(n.id)
}
+ if (!isNote && n.agentId) entry.agent = n.agentId
if (isNote) entry.note = n.note
return entry
}),
diff --git a/src/main/context-link.ts b/src/main/context-link.ts
index 69e34f2ab..88f8b7a8d 100644
--- a/src/main/context-link.ts
+++ b/src/main/context-link.ts
@@ -15,7 +15,8 @@ import { IPC } from '../shared/ipc'
import type { ContextLinkMap } from '../shared/types'
import { type PtyManager } from './pty-manager'
import { TMUX_SOCKET } from './tmux-naming'
-import { CLI_SCRIPT, buildLinkDoc, transcriptPathOf } from './context-link-core'
+import { CLI_SCRIPT, buildLinkDoc, resolveLinkTranscript, transcriptPathOf } from './context-link-core'
+import { locateClaude, locateCodex, locateGemini } from './handoff/locate'
export { setNodeTranscript } from './context-link-core'
@@ -92,6 +93,8 @@ to read — do not retry.
let pty: PtyManager | undefined
+const LINK_LOCATORS = { claude: locateClaude, codex: locateCodex, gemini: locateGemini }
+
// Write one enriched link file per node id present in the map. Removed links should not
// linger, so we clear stale per-node files first. Async fs throughout — this runs on edge
// changes and scales with node/link count, and sync I/O here sits on the main event loop.
@@ -105,9 +108,18 @@ async function writeLinkFiles(map: ContextLinkMap): Promise<void> {
} catch {
/* dir may not exist yet */
}
+ // Resolve each linked node's transcript once (hook-fed for claude, locator-by-sessionId
+ // for codex/gemini), so buildLinkDoc stays pure and sync.
+ const resolved = new Map<string, string>()
+ for (const links of Object.values(map)) {
+ for (const n of links) {
+ if (n.note != null || resolved.has(n.id)) continue
+ resolved.set(n.id, await resolveLinkTranscript(n, { hooked: transcriptPathOf, locators: LINK_LOCATORS }))
+ }
+ }
for (const [nodeId, links] of Object.entries(map)) {
const doc = buildLinkDoc(nodeId, links, {
- transcriptOf: transcriptPathOf,
+ transcriptOf: (id) => resolved.get(id) ?? '',
tmuxBin: bin,
tmuxSocket: TMUX_SOCKET
})