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 Gemini transcript renderer

enesdeb881b63193
diff --git a/src/main/handoff/render-gemini.test.ts b/src/main/handoff/render-gemini.test.ts
new file mode 100644
index 000000000..d4ccf65a0
--- /dev/null
+++ b/src/main/handoff/render-gemini.test.ts
@@ -0,0 +1,20 @@
+import { describe, it, expect } from 'vitest'
+import { renderGeminiTranscript } from './render-gemini'
+
+const FIXTURE = [
+ '{"sessionId":"2b5a774c-6d8a-4d9e-80e8-d14a00997a2c","projectHash":"abc","kind":"main"}',
+ '{"$set":{"messages":[{"id":"a","type":"user","content":[{"text":"<session_context>setup</session_context>"}]}]}}',
+ '{"id":"b","type":"user","content":[{"text":"how are you ?"}]}',
+ '{"id":"c","type":"gemini","content":[{"text":"I am well."}]}'
+].join('\n')
+
+describe('renderGeminiTranscript', () => {
+ it('reconstructs messages from $set baseline + bare appends, in order', () => {
+ const md = renderGeminiTranscript(FIXTURE)
+ expect(md).toContain('session_context')
+ expect(md).toContain('## User\n\nhow are you ?')
+ expect(md).toContain('## Assistant\n\nI am well.')
+ expect(md.indexOf('how are you ?')).toBeLessThan(md.indexOf('I am well.'))
+ expect(md).not.toContain('projectHash')
+ })
+})
diff --git a/src/main/handoff/render-gemini.ts b/src/main/handoff/render-gemini.ts
new file mode 100644
index 000000000..fe2fa0ae1
--- /dev/null
+++ b/src/main/handoff/render-gemini.ts
@@ -0,0 +1,52 @@
+// Renders a Gemini CLI chat .jsonl (~/.gemini/tmp/<proj>/chats/session-*.jsonl) to full
+// Markdown. The file is event-sourced: a header line, then `$set`/`$push` mutations on a
+// `messages` array and/or bare appended message objects. We replay them, then render. No
+// size cap, no summarization.
+import { blockText } from './format'
+
+interface GeminiMsg {
+ type?: string
+ content?: unknown
+ [k: string]: unknown
+}
+
+export function renderGeminiTranscript(raw: string): string {
+ let messages: GeminiMsg[] = []
+ for (const line of raw.split('\n')) {
+ const t = line.trim()
+ if (!t) continue
+ let o: Record<string, unknown>
+ try {
+ o = JSON.parse(t)
+ } catch {
+ continue
+ }
+ if (o.$set && typeof o.$set === 'object') {
+ const m = (o.$set as Record<string, unknown>).messages
+ if (Array.isArray(m)) messages = m as GeminiMsg[]
+ continue
+ }
+ if (o.$push && typeof o.$push === 'object') {
+ const m = (o.$push as Record<string, unknown>).messages
+ if (Array.isArray(m)) messages.push(...(m as GeminiMsg[]))
+ else if (m && typeof m === 'object') messages.push(m as GeminiMsg)
+ continue
+ }
+ // Bare appended message line (has content, no session header marker).
+ if (o.content !== undefined && o.sessionId === undefined) {
+ messages.push(o as GeminiMsg)
+ }
+ // Header line ({sessionId, projectHash, kind}) and anything else: skip.
+ }
+ const out: string[] = []
+ for (const m of messages) {
+ const role =
+ m.type === 'user'
+ ? 'User'
+ : m.type === 'gemini' || m.type === 'model'
+ ? 'Assistant'
+ : `Message (${String(m.type ?? 'unknown')})`
+ out.push(`## ${role}\n\n${blockText(m.content)}`)
+ }
+ return out.join('\n\n')
+}