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(context-link): read opencode transcripts via 'opencode export' (SQLite-safe)
enes6e0e5cfc8bf5
diff --git a/src/core/context-link-core.test.ts b/src/core/context-link-core.test.tsindex 163e5d4d4..4c3c99abc 100644--- a/src/core/context-link-core.test.ts+++ b/src/core/context-link-core.test.ts@@ -67,6 +67,23 @@ describe('buildLinkDoc agent field', () => {})})+describe('buildLinkDoc sessionId field', () => {+ it('copies sessionId onto the entry (opencode exports by id); notes get none', () => {+ const doc = buildLinkDoc(+ 'node-A',+ [+ { id: 'node-O', title: 'O', cwd: '', agentId: 'opencode', sessionId: 'ses_1' },+ { id: 'node-B', title: 'B', cwd: '', agentId: 'codex' },+ { id: 'note-1', title: 'N', note: 'txt' }+ ],+ { transcriptOf: () => '', tmuxBin: null, tmuxSocket: 's' }+ )+ expect(doc.links[0].sessionId).toBe('ses_1')+ expect(doc.links[1].sessionId).toBeUndefined()+ expect(doc.links[2].sessionId).toBeUndefined()+ })+})+describe('resolveLinkTranscript', () => {const locators = {claude: async (sid: string, acct?: string) => `/c/${acct ?? 'default'}/${sid}.jsonl`,diff --git a/src/core/context-link-core.ts b/src/core/context-link-core.tsindex 410087e46..86566dd01 100644--- a/src/core/context-link-core.ts+++ b/src/core/context-link-core.ts@@ -83,8 +83,10 @@ export interface LinkDocEntry {cwd: stringtranscriptPath: stringtmux: string- /** Which agent CLI produced the transcript ('claude' | 'codex' | 'gemini') — selects the parser. */+ /** Which agent CLI produced the transcript ('claude' | 'codex' | 'gemini' | 'opencode') — selects the parser. */agent?: string+ /** Provider session id — opencode has no transcript file, so the CLI exports it by id. */+ sessionId?: string/** Present when this entry is a sticky note: its text. Note entries have no transcript/terminal. */note?: string}@@ -113,6 +115,7 @@ export function buildLinkDoc(tmux: isNote ? '' : sessionName(n.id)}if (!isNote && n.agentId) entry.agent = n.agentId+ if (!isNote && n.sessionId) entry.sessionId = n.sessionIdif (isNote) entry.note = n.notereturn entry}),@@ -239,6 +242,40 @@ function linesFromGeminiFile(buf) {return res}+// opencode >=1.18 stores sessions in SQLite — never parse its disk. The CLI exports a+// session as JSON: 'opencode export <sessionID>'. Shape read defensively: a messages array+// whose items carry role + parts[] (text / tool) or a plain content string.+function linesFromOpencodeExport(node) {+ if (!node.sessionId) { out('"' + node.title + '" has no session id yet.'); return [] }+ var raw+ try {+ raw = execFileSync('opencode', ['export', String(node.sessionId)], { encoding: 'utf-8', stdio: ['ignore', 'pipe', 'ignore'] })+ } catch (e) { out('Could not export "' + node.title + '" session (is opencode installed?).'); return [] }+ var o+ try { o = JSON.parse(raw) } catch (e) { out('Unreadable opencode export for "' + node.title + '".'); return [] }+ var msgs = Array.isArray(o) ? o : (o && (o.messages || (o.data && o.data.messages))) || []+ var res = []+ msgs.forEach(function (m) {+ if (!m) return+ var role = (m.role || (m.info && m.info.role)) === 'user' ? 'user' : 'assistant'+ var parts = m.parts || (Array.isArray(m.content) ? m.content : null)+ if (typeof m.content === 'string' && m.content) { res.push(role + ': ' + m.content); return }+ if (!Array.isArray(parts)) return+ parts.forEach(function (c) {+ if (!c) return+ if (typeof c.text === 'string' && c.text && (c.type === 'text' || !c.type)) res.push(role + ': ' + c.text)+ else if (c.type === 'tool' || c.type === 'tool_use' || c.tool) {+ var name = c.tool || c.name || 'tool'+ var input = c.state && c.state.input ? c.state.input : c.input+ var a = input && (input.command || input.filePath || input.file_path || input.pattern || input.description)+ res.push(' $ ' + name + (typeof a === 'string' ? ' ' + a.slice(0, 200) : ''))+ }+ })+ })+ if (!res.length) out('"' + node.title + '" export contained no readable messages.')+ return res+}+// Parse one transcript JSONL line into 0..n display strings.function linesFrom(raw) {var o@@ -265,6 +302,8 @@ function linesFrom(raw) {}function readTranscript(node) {+ // opencode has no transcript file (SQLite) — export by session id before any path resolution.+ if (node.agent === 'opencode') return linesFromOpencodeExport(node)var p = resolveTranscript(node)if (!p) { out('"' + node.title + '" has no conversation transcript yet.'); return [] }var bufdiff --git a/src/core/context-link.cli.test.ts b/src/core/context-link.cli.test.tsindex 5195e5a33..0927daee4 100644--- a/src/core/context-link.cli.test.ts+++ b/src/core/context-link.cli.test.ts@@ -1,15 +1,35 @@import { describe, it, expect, beforeAll, afterAll } from 'vitest'import { execFileSync } from 'node:child_process'-import { mkdtempSync, writeFileSync, rmSync } from 'node:fs'+import { mkdtempSync, writeFileSync, rmSync, chmodSync } from 'node:fs'import { tmpdir } from 'node:os'import { join } from 'node:path'import { CLI_SCRIPT } from './context-link-core'let dir: string+let binDir: stringbeforeAll(() => {dir = mkdtempSync(join(tmpdir(), 'ctxlink-'))writeFileSync(join(dir, 'context-cli.mjs'), CLI_SCRIPT)+ // A fake `opencode` on PATH: `opencode export <id>` prints a session-export JSON blob.+ // opencode stores sessions in SQLite, so the CLI shells out to `opencode export` instead+ // of reading a file — we stub that binary to return a fixture payload.+ binDir = mkdtempSync(join(tmpdir(), 'ctxlink-bin-'))+ const opencodeExport = JSON.stringify({+ messages: [+ { role: 'user', parts: [{ type: 'text', text: 'add rerank' }] },+ {+ role: 'assistant',+ parts: [+ { type: 'text', text: 'done, added rerank.ts' },+ { type: 'tool', tool: 'bash', state: { input: { command: 'npm test' } } }+ ]+ }+ ]+ })+ writeFileSync(join(binDir, 'export.json'), opencodeExport)+ writeFileSync(join(binDir, 'opencode'), `#!/bin/sh\ncat "${join(binDir, 'export.json')}"\n`)+ chmodSync(join(binDir, 'opencode'), 0o755)const transcript = [JSON.stringify({ type: 'user', message: { content: 'deploy the app' } }),JSON.stringify({@@ -55,6 +75,8 @@ beforeAll(() => {{ id: 'node-X', title: 'Coder', cwd: '', transcriptPath: join(dir, 'codex.jsonl'), tmux: 'nt-node-X', agent: 'codex' },{ id: 'node-G', title: 'Gem', cwd: '', transcriptPath: join(dir, 'gemini.jsonl'), tmux: 'nt-node-G', agent: 'gemini' },{ id: 'node-Y', title: 'ColdCoder', cwd: '/nowhere', transcriptPath: '', tmux: 'nt-node-Y', agent: 'codex' },+ { id: 'node-O', title: 'OpenCoder', cwd: '', transcriptPath: '', tmux: 'nt-node-O', agent: 'opencode', sessionId: 'ses_abc' },+ { id: 'node-O2', title: 'NoSession', cwd: '', transcriptPath: '', tmux: 'nt-node-O2', agent: 'opencode' },{ id: 'note-1', title: 'Deploy notes', cwd: '', transcriptPath: '', tmux: '', note: 'use the staging key' }],tmuxBin: null,@@ -63,12 +85,15 @@ beforeAll(() => {)})-afterAll(() => rmSync(dir, { recursive: true, force: true }))+afterAll(() => {+ rmSync(dir, { recursive: true, force: true })+ rmSync(binDir, { recursive: true, force: true })+})function run(nodeId: string, args: string[]): string {return execFileSync(process.execPath, [join(dir, 'context-cli.mjs'), ...args], {encoding: 'utf-8',- env: { ...process.env, NODETERM_NODE_ID: nodeId }+ env: { ...process.env, NODETERM_NODE_ID: nodeId, PATH: `${binDir}:${process.env.PATH ?? ''}` }})}@@ -131,4 +156,14 @@ describe('context-cli', () => {const out = run('node-A', ['summary', '--node', 'node-Y'])expect(out).toContain('no conversation transcript yet')})+ it('renders an opencode transcript via `opencode export`', () => {+ const out = run('node-A', ['transcript', '--node', 'node-O'])+ expect(out).toContain('user: add rerank')+ expect(out).toContain('assistant: done, added rerank.ts')+ expect(out).toContain('$ bash npm test')+ })+ it('opencode without a session id reports friendly, does not throw', () => {+ const out = run('node-A', ['summary', '--node', 'node-O2'])+ expect(out).toContain('has no session id yet')+ })})