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(search): main-process Claude transcript reader + claude.readTranscript IPC

enes521b89658a28
diff --git a/src/main/context-tail.ts b/src/main/context-tail.ts
index 6303934e0..e7b4a7a57 100644
--- a/src/main/context-tail.ts
+++ b/src/main/context-tail.ts
@@ -25,6 +25,8 @@ interface Tracked {
export interface ContextTail {
track(sessionId: string | undefined, transcriptPath: string | undefined): void
untrack(sessionId: string | undefined): void
+ /** The transcript path currently tracked for a session, if any. */
+ pathFor(sessionId: string | undefined): string | undefined
}
export function createContextTail(win: BrowserWindow): ContextTail {
@@ -147,6 +149,10 @@ export function createContextTail(win: BrowserWindow): ContextTail {
clearInterval(timer)
timer = null
}
+ },
+ pathFor(sessionId) {
+ if (!sessionId) return undefined
+ return sessions.get(sessionId)?.path
}
}
}
diff --git a/src/main/index.ts b/src/main/index.ts
index ef3bdae5d..c5ebebf81 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -15,6 +15,7 @@ import { hookServer } from './agents/hook-server'
import { installManagedAgentHooks } from './agents/hooks'
import { createSubagentTail } from './subagent-tail'
import { createContextTail } from './context-tail'
+import { readTranscriptLines, resolveTranscriptPath } from './transcript-reader'
import { initBridge } from './bridge'
import { initTelemetry } from './telemetry'
import { initClaudeUsage } from './claude-usage'
@@ -243,6 +244,10 @@ app.whenReady().then(async () => {
// which need the raw transcript_path the NormalizedAgentEvent intentionally drops.
const subagentTail = createSubagentTail(win)
const contextTail = createContextTail(win)
+ ipcMain.handle(IPC.claudeReadTranscript, async (_e, sessionId: string) => {
+ const p = contextTail.pathFor(sessionId) ?? (await resolveTranscriptPath(sessionId))
+ return p ? readTranscriptLines(p) : []
+ })
installManagedAgentHooks()
hookServer.setListener((e) => {
if (!win.isDestroyed()) win.webContents.send(IPC.agentStatus, e)
diff --git a/src/main/transcript-reader.ts b/src/main/transcript-reader.ts
new file mode 100644
index 000000000..83f0bddb3
--- /dev/null
+++ b/src/main/transcript-reader.ts
@@ -0,0 +1,119 @@
+// Reads a Claude session's transcript .jsonl into flat, searchable lines. Read-only and
+// local. Mirrors subagent-tail.ts's extraction shape but returns {role, text} per content
+// block (instead of a single formatted string) so the renderer can tag matches by role.
+import fs from 'fs'
+import os from 'os'
+import path from 'path'
+import type { TranscriptLine } from '../shared/types'
+
+// Only read the last ~5 MB of a transcript so a very large session can't block the main
+// process. The older head is dropped silently (search is most useful on recent context).
+const READ_CAP_BYTES = 5 * 1024 * 1024
+
+function textOf(content: unknown): string {
+ if (typeof content === 'string') return content
+ if (Array.isArray(content)) {
+ return (content as Array<{ type?: string; text?: string }>)
+ .map((c) => (c?.type === 'text' ? c.text ?? '' : ''))
+ .filter(Boolean)
+ .join('\n')
+ }
+ return ''
+}
+
+function summarizeResult(content: unknown): string {
+ return textOf(content).split('\n').slice(0, 3).join(' ').slice(0, 500)
+}
+
+function toolArg(input: unknown): string {
+ if (!input || typeof input !== 'object') return ''
+ const o = input as Record<string, unknown>
+ const v = o.command ?? o.file_path ?? o.path ?? o.pattern ?? o.description ?? o.prompt
+ return typeof v === 'string' ? v.slice(0, 200) : ''
+}
+
+// Extract 0..n searchable lines from one raw transcript JSONL line.
+function linesFrom(raw: string): TranscriptLine[] {
+ let o: { type?: string; message?: { content?: unknown } }
+ try {
+ o = JSON.parse(raw)
+ } catch {
+ return []
+ }
+ const content = o.message?.content
+ const out: TranscriptLine[] = []
+ if (o.type === 'assistant' && Array.isArray(content)) {
+ for (const c of content as Array<{ type?: string; text?: string; name?: string; input?: unknown }>) {
+ if (c.type === 'text' && c.text) out.push({ role: 'assistant', text: c.text })
+ else if (c.type === 'tool_use') {
+ const arg = toolArg(c.input)
+ out.push({ role: 'tool', text: `$ ${c.name ?? 'tool'}${arg ? ` ${arg}` : ''}` })
+ }
+ }
+ } else if (o.type === 'user' && Array.isArray(content)) {
+ for (const c of content as Array<{ type?: string; text?: string; content?: unknown }>) {
+ if (c.type === 'text' && c.text) out.push({ role: 'user', text: c.text })
+ else if (c.type === 'tool_result') {
+ const s = summarizeResult(c.content)
+ if (s) out.push({ role: 'tool', text: s })
+ }
+ }
+ } else if (o.type === 'user' && typeof content === 'string') {
+ out.push({ role: 'user', text: content })
+ }
+ return out
+}
+
+export async function readTranscriptLines(filePath: string): Promise<TranscriptLine[]> {
+ let buf: string
+ try {
+ const stat = await fs.promises.stat(filePath)
+ if (stat.size > READ_CAP_BYTES) {
+ const fd = await fs.promises.open(filePath, 'r')
+ try {
+ const start = stat.size - READ_CAP_BYTES
+ const { buffer } = await fd.read({
+ position: start,
+ length: READ_CAP_BYTES,
+ buffer: Buffer.alloc(READ_CAP_BYTES)
+ })
+ buf = buffer.toString('utf8')
+ } finally {
+ await fd.close()
+ }
+ const nl = buf.indexOf('\n') // drop the first (partial) line
+ if (nl >= 0) buf = buf.slice(nl + 1)
+ } else {
+ buf = await fs.promises.readFile(filePath, 'utf8')
+ }
+ } catch {
+ return []
+ }
+ const lines: TranscriptLine[] = []
+ for (const raw of buf.split('\n')) {
+ if (raw.trim()) lines.push(...linesFrom(raw))
+ }
+ return lines
+}
+
+// Fallback when context-tail isn't tracking the session (e.g. resumed after restart):
+// find <sessionId>.jsonl anywhere under ~/.claude/projects/*.
+export async function resolveTranscriptPath(sessionId: string): Promise<string | undefined> {
+ const root = path.join(os.homedir(), '.claude', 'projects')
+ let dirs: string[]
+ try {
+ dirs = await fs.promises.readdir(root)
+ } catch {
+ return undefined
+ }
+ for (const d of dirs) {
+ const p = path.join(root, d, `${sessionId}.jsonl`)
+ try {
+ await fs.promises.access(p)
+ return p
+ } catch {
+ /* keep looking */
+ }
+ }
+ return undefined
+}
diff --git a/src/preload/index.ts b/src/preload/index.ts
index 5e9abe53f..96ca9c449 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -128,6 +128,9 @@ const api: NodeTerminalApi = {
return () => ipcRenderer.removeListener(IPC.contextUpdate, handler)
}
},
+ claude: {
+ readTranscript: (sessionId) => ipcRenderer.invoke(IPC.claudeReadTranscript, sessionId)
+ },
bridge: {
configPath: () => ipcRenderer.invoke(IPC.bridgeConfigPath),
setTopology: (topology) => ipcRenderer.invoke(IPC.bridgeSetTopology, topology),
diff --git a/src/shared/ipc.ts b/src/shared/ipc.ts
index 4e90b2847..f4d8f9269 100644
--- a/src/shared/ipc.ts
+++ b/src/shared/ipc.ts
@@ -10,6 +10,7 @@ export const IPC = {
ptyGenerateName: 'pty:generate-name',
ptyCapture: 'pty:capture',
ptySendText: 'pty:send-text',
+ claudeReadTranscript: 'claude:read-transcript',
appToggleMarkdown: 'app:toggle-markdown',
appCloseNode: 'app:close-node',
appCloseWindow: 'app:close-window',
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 89b9a41a2..9d86df973 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -460,6 +460,17 @@ export interface ContextApi {
onUpdate(listener: (usage: ContextWindowUsage) => void): () => void
}
+/** One searchable line extracted from a Claude session transcript. */
+export interface TranscriptLine {
+ role: 'user' | 'assistant' | 'tool'
+ text: string
+}
+
+export interface ClaudeApi {
+ /** Reads a Claude session's full transcript as flat searchable lines ([] if unavailable). */
+ readTranscript(sessionId: string): Promise<TranscriptLine[]>
+}
+
export interface NodeTerminalApi {
pty: PtyApi
workspace: WorkspaceApi
@@ -474,6 +485,7 @@ export interface NodeTerminalApi {
bridge: BridgeApi
usage: UsageApi
context: ContextApi
+ claude: ClaudeApi
/** Fires when the user presses Cmd/Ctrl+M (toggle markdown view). Returns unsubscribe. */
onMarkdownToggle(listener: () => void): () => void
/** Fires when the user presses Cmd/Ctrl+W (close selected node). Returns unsubscribe. */