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(handoff): full Claude transcript renderer + format helpers

enes9a8b27f92ff8
diff --git a/src/main/handoff/format.ts b/src/main/handoff/format.ts
new file mode 100644
index 000000000..35a06062f
--- /dev/null
+++ b/src/main/handoff/format.ts
@@ -0,0 +1,34 @@
+// Shared rendering helpers for cross-agent handoff transcript renderers. Pure (no fs).
+
+/** Full text of a content value: a string as-is, an array of blocks joined, an object as
+ * JSON. Never truncates — handoff requires the complete content. Non-text blocks fall back
+ * to their JSON so nothing is silently dropped. */
+export function blockText(content: unknown): string {
+ if (typeof content === 'string') return content
+ if (Array.isArray(content)) {
+ return content
+ .map((c) => {
+ if (typeof c === 'string') return c
+ if (c && typeof c === 'object') {
+ const o = c as Record<string, unknown>
+ if (typeof o.text === 'string') return o.text
+ return JSON.stringify(o)
+ }
+ return String(c)
+ })
+ .join('\n')
+ }
+ if (content && typeof content === 'object') return JSON.stringify(content)
+ return ''
+}
+
+/** A pretty-printed, ```json-fenced block for tool inputs and unknown blocks. */
+export function fenceJson(v: unknown): string {
+ let s: string
+ try {
+ s = JSON.stringify(v, null, 2)
+ } catch {
+ s = String(v)
+ }
+ return '```json\n' + s + '\n```'
+}
diff --git a/src/main/handoff/render-claude.test.ts b/src/main/handoff/render-claude.test.ts
new file mode 100644
index 000000000..46866b0ac
--- /dev/null
+++ b/src/main/handoff/render-claude.test.ts
@@ -0,0 +1,28 @@
+import { describe, it, expect } from 'vitest'
+import { renderClaudeTranscript } from './render-claude'
+
+const FIXTURE = [
+ '{"type":"last-prompt","leafUuid":"x","sessionId":"s"}',
+ '{"type":"user","message":{"role":"user","content":"hello there"}}',
+ '{"type":"assistant","message":{"role":"assistant","content":[{"type":"text","text":"hi back"},{"type":"tool_use","name":"Read","input":{"file_path":"/a.ts"}}]}}',
+ '{"type":"user","message":{"content":[{"type":"tool_result","content":[{"type":"text","text":"LINE1\\nLINE2"}]}]}}'
+].join('\n')
+
+describe('renderClaudeTranscript', () => {
+ it('renders all turns, tool calls, and full tool output in order', () => {
+ const md = renderClaudeTranscript(FIXTURE)
+ expect(md).toContain('## User\n\nhello there')
+ expect(md).toContain('## Assistant\n\nhi back')
+ expect(md).toContain('Tool call: Read')
+ expect(md).toContain('/a.ts')
+ expect(md).toContain('Tool result')
+ expect(md).toContain('LINE1')
+ expect(md).toContain('LINE2') // no truncation of tool output
+ expect(md.indexOf('hello there')).toBeLessThan(md.indexOf('hi back'))
+ })
+
+ it('skips metadata lines and tolerates malformed JSON', () => {
+ const md = renderClaudeTranscript('{"type":"mode","mode":"normal"}\nnot json\n')
+ expect(md).toBe('')
+ })
+})
diff --git a/src/main/handoff/render-claude.ts b/src/main/handoff/render-claude.ts
new file mode 100644
index 000000000..817fb9c66
--- /dev/null
+++ b/src/main/handoff/render-claude.ts
@@ -0,0 +1,46 @@
+// Renders a Claude Code session .jsonl (~/.claude/projects/<proj>/<sessionId>.jsonl) to full
+// Markdown. Each line is a JSON object; only `user`/`assistant` message lines carry content
+// (other lines are metadata: last-prompt, mode, summary, …). No size cap, no summarization.
+import { blockText, fenceJson } from './format'
+
+interface ClaudeLine {
+ type?: string
+ message?: { role?: string; content?: unknown }
+}
+
+export function renderClaudeTranscript(raw: string): string {
+ const out: string[] = []
+ for (const line of raw.split('\n')) {
+ const t = line.trim()
+ if (!t) continue
+ let o: ClaudeLine
+ try {
+ o = JSON.parse(t)
+ } catch {
+ continue
+ }
+ if (o.type !== 'user' && o.type !== 'assistant') continue
+ const role = o.type === 'assistant' ? 'Assistant' : 'User'
+ const content = o.message?.content
+ if (typeof content === 'string') {
+ if (content) out.push(`## ${role}\n\n${content}`)
+ continue
+ }
+ if (!Array.isArray(content)) continue
+ for (const c of content as Array<Record<string, unknown>>) {
+ const ct = c.type
+ if (ct === 'text' && typeof c.text === 'string') {
+ out.push(`## ${role}\n\n${c.text}`)
+ } else if (ct === 'thinking' && typeof c.thinking === 'string') {
+ out.push(`## ${role} (thinking)\n\n${c.thinking}`)
+ } else if (ct === 'tool_use') {
+ out.push(`### Tool call: ${String(c.name ?? 'tool')}\n\n${fenceJson(c.input)}`)
+ } else if (ct === 'tool_result') {
+ out.push('### Tool result\n\n```\n' + blockText(c.content) + '\n```')
+ } else {
+ out.push(`### ${role} block (${String(ct ?? 'unknown')})\n\n${fenceJson(c)}`)
+ }
+ }
+ }
+ return out.join('\n\n')
+}