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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(handoff): locators + buildHandoff orchestrator
enesb61c58d8056e
diff --git a/src/main/handoff/index.test.ts b/src/main/handoff/index.test.tsnew file mode 100644index 000000000..1b96e950a--- /dev/null+++ b/src/main/handoff/index.test.ts@@ -0,0 +1,10 @@+import { describe, it, expect } from 'vitest'+import { handoffFilename } from './index'++describe('handoffFilename', () => {+ it('builds a filesystem-safe handoff filename', () => {+ expect(handoffFilename('term_5', '2026-06-23T11-12-00-000Z')).toBe(+ 'handoff-term_5-2026-06-23T11-12-00-000Z.md'+ )+ })+})diff --git a/src/main/handoff/index.ts b/src/main/handoff/index.tsnew file mode 100644index 000000000..d09e78041--- /dev/null+++ b/src/main/handoff/index.ts@@ -0,0 +1,73 @@+// Cross-agent conversation transfer (main process). Locates the source agent's native+// transcript by sessionId, renders it to full Markdown, and writes a portable handoff file+// under <cwd>/.nodeterm/. No summarization; the entire transcript is dumped.+import fs from 'fs'+import os from 'os'+import path from 'path'+import { SESSION_ID_RE } from '../transcript-reader'+import { renderClaudeTranscript } from './render-claude'+import { renderCodexTranscript } from './render-codex'+import { renderGeminiTranscript } from './render-gemini'+import { locateClaude, locateCodex, locateGemini } from './locate'++export type HandoffResult = { filePath: string } | { error: string }++type Renderer = (raw: string) => string+type Locator = (sessionId: string) => Promise<string | undefined>++const RENDERERS: Record<string, Renderer> = {+ claude: renderClaudeTranscript,+ codex: renderCodexTranscript,+ gemini: renderGeminiTranscript+}++const LOCATORS: Record<string, Locator> = {+ claude: locateClaude,+ codex: locateCodex,+ gemini: locateGemini+}++/** Filesystem-safe handoff filename for a node + ISO-ish timestamp. */+export function handoffFilename(nodeId: string, ts: string): string {+ return `handoff-${nodeId}-${ts}.md`+}++export async function buildHandoff(opts: {+ sessionId: string+ agentId: string+ sourceNodeId: string+ cwd?: string+}): Promise<HandoffResult> {+ const { sessionId, agentId, sourceNodeId, cwd } = opts+ if (!sessionId || !SESSION_ID_RE.test(sessionId)) return { error: 'No valid session id to transfer.' }+ const render = RENDERERS[agentId]+ const locate = LOCATORS[agentId]+ if (!render || !locate) return { error: `Transfer is not supported from ${agentId}.` }++ const src = await locate(sessionId)+ if (!src) return { error: "Couldn't find the source conversation transcript." }++ let raw: string+ try {+ raw = await fs.promises.readFile(src, 'utf8')+ } catch {+ return { error: 'Failed to read the source transcript.' }+ }++ const body = render(raw)+ const ts = new Date().toISOString().replace(/[:.]/g, '-')+ const header =+ `# Conversation handoff\n\n` ++ `Source agent: ${agentId}\nSource session: ${sessionId}\n\n` ++ `This is the COMPLETE prior conversation, including all tool calls and outputs.\n\n---\n\n`++ const dir = path.join(cwd && cwd.length ? cwd : os.homedir(), '.nodeterm')+ const filePath = path.join(dir, handoffFilename(sourceNodeId, ts))+ try {+ await fs.promises.mkdir(dir, { recursive: true })+ await fs.promises.writeFile(filePath, header + body, 'utf8')+ } catch {+ return { error: 'Failed to write the handoff file.' }+ }+ return { filePath }+}diff --git a/src/main/handoff/locate.ts b/src/main/handoff/locate.tsnew file mode 100644index 000000000..14699e28d--- /dev/null+++ b/src/main/handoff/locate.ts@@ -0,0 +1,67 @@+// Per-agent transcript file locators. Each resolves an on-disk transcript path from the+// sessionId captured via hooks. Filesystem + home-dir access — main process only.+import fs from 'fs'+import os from 'os'+import path from 'path'+import { resolveTranscriptPath } from '../transcript-reader'++// claude: ~/.claude/projects/<proj>/<sessionId>.jsonl — already implemented (searches all+// project dirs for the exact <sessionId>.jsonl).+export function locateClaude(sessionId: string): Promise<string | undefined> {+ return resolveTranscriptPath(sessionId)+}++// codex: ~/.codex/sessions/YYYY/MM/DD/rollout-<ts>-<sessionId>.jsonl — walk the tree and+// match a .jsonl filename containing the sessionId.+export async function locateCodex(sessionId: string): Promise<string | undefined> {+ const root = path.join(os.homedir(), '.codex', 'sessions')+ const stack = [root]+ while (stack.length) {+ const dir = stack.pop() as string+ let entries: fs.Dirent[]+ try {+ entries = await fs.promises.readdir(dir, { withFileTypes: true })+ } catch {+ continue+ }+ for (const e of entries) {+ const p = path.join(dir, e.name)+ if (e.isDirectory()) stack.push(p)+ else if (e.isFile() && e.name.endsWith('.jsonl') && e.name.includes(sessionId)) return p+ }+ }+ return undefined+}++// gemini: ~/.gemini/tmp/<proj>/chats/session-*.jsonl — find the file whose first-line+// header sessionId equals the requested sessionId.+export async function locateGemini(sessionId: string): Promise<string | undefined> {+ const tmp = path.join(os.homedir(), '.gemini', 'tmp')+ let projects: string[]+ try {+ projects = await fs.promises.readdir(tmp)+ } catch {+ return undefined+ }+ for (const proj of projects) {+ const chats = path.join(tmp, proj, 'chats')+ let files: string[]+ try {+ files = await fs.promises.readdir(chats)+ } catch {+ continue+ }+ for (const f of files) {+ if (!f.endsWith('.jsonl')) continue+ const p = path.join(chats, f)+ try {+ const head = (await fs.promises.readFile(p, 'utf8')).split('\n', 1)[0]+ const o = JSON.parse(head) as { sessionId?: string }+ if (o.sessionId === sessionId) return p+ } catch {+ /* keep looking */+ }+ }+ }+ return undefined+}