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(transcript-index): service, search IPC, preload bridge

enesad7c9ce79c07
diff --git a/src/main/index.ts b/src/main/index.ts
index 8e021e56a..9d69806c9 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -32,6 +32,7 @@ import { childArgs } from './remote-ssh/control-master'
import { posixQuote } from '../shared/ssh'
import { buildHandoff } from './handoff'
import { initContextLink, setNodeTranscript } from './context-link'
+import { initTranscriptIndex, searchTranscripts } from './transcript-index'
import { initTelemetry } from './telemetry'
import { initClaudeUsage } from './claude-usage'
import { initLicense } from './license'
@@ -388,6 +389,9 @@ app.whenReady().then(async () => {
return p ? readChatMessages(p) : []
}
)
+
+ initTranscriptIndex()
+ ipcMain.handle(IPC.transcriptSearch, (_e, query: string) => searchTranscripts(query))
// Populate the context meter without a live hook event: the renderer calls this on mount
// (the continuing session may be idle after a restart). Track under the sessionId (the key
// the meter looks up); cwd is only a path fallback. contextTail.track reads immediately and
diff --git a/src/main/transcript-index-core.ts b/src/main/transcript-index-core.ts
index 2b1cd5a90..9a66ee56e 100644
--- a/src/main/transcript-index-core.ts
+++ b/src/main/transcript-index-core.ts
@@ -2,8 +2,11 @@
// JSONL text, build snippets, and rank sessions by a query. No filesystem access — the
// service layer (transcript-index.ts) reads files and calls these. Reuses the same JSONL
// parser as the single-session reader so indexed text stays consistent with the find-bar.
+import type { TranscriptHit } from '../shared/types'
import { parseTranscriptLines } from './transcript-reader'
+export type { TranscriptHit }
+
export const INDEX_TEXT_CAP_BYTES = 200 * 1024
export interface TranscriptIndexEntry {
@@ -15,15 +18,6 @@ export interface TranscriptIndexEntry {
text: string
}
-export interface TranscriptHit {
- sessionId: string
- title: string
- snippet: string
- cwd: string
- projectLabel: string
- mtime: number
-}
-
// Read `cwd` from the first JSONL line that carries it (every Claude line does); reliable,
// unlike decoding the dashed directory name.
function firstCwd(rawText: string): string {
diff --git a/src/main/transcript-index.ts b/src/main/transcript-index.ts
new file mode 100644
index 000000000..60c37a1ce
--- /dev/null
+++ b/src/main/transcript-index.ts
@@ -0,0 +1,136 @@
+// Background index of all Claude session transcripts under ~/.claude/projects. Built on
+// launch + refreshed every 5 min, incrementally by mtime, and persisted to userData so a
+// relaunch doesn't cold re-scan. Search runs in-memory over the index. Read-only and local.
+import fs from 'fs'
+import os from 'os'
+import path from 'path'
+import { app } from 'electron'
+import { SESSION_ID_RE } from './transcript-reader'
+import {
+ extractEntryFields,
+ planRefresh,
+ searchEntries,
+ type ScanFile,
+ type TranscriptIndexEntry,
+ type TranscriptHit
+} from './transcript-index-core'
+
+export const TRANSCRIPT_INDEX_REFRESH_MS = 5 * 60 * 1000
+const READ_CAP_BYTES = 5 * 1024 * 1024 // mirror transcript-reader: never read more than the tail
+
+let entries: TranscriptIndexEntry[] = []
+let timer: NodeJS.Timeout | undefined
+
+function indexFilePath(): string {
+ return path.join(app.getPath('userData'), 'transcript-index.json')
+}
+
+function projectsRoot(): string {
+ return path.join(os.homedir(), '.claude', 'projects')
+}
+
+// Walk ~/.claude/projects/*/ for <sessionId>.jsonl, returning {sessionId, path, mtime}.
+async function scanTranscripts(): Promise<ScanFile[]> {
+ const root = projectsRoot()
+ const out: ScanFile[] = []
+ let dirs: string[]
+ try {
+ dirs = await fs.promises.readdir(root)
+ } catch {
+ return out
+ }
+ for (const d of dirs) {
+ let files: string[]
+ try {
+ files = await fs.promises.readdir(path.join(root, d))
+ } catch {
+ continue
+ }
+ for (const f of files) {
+ if (!f.endsWith('.jsonl')) continue
+ const sessionId = f.slice(0, -'.jsonl'.length)
+ if (!SESSION_ID_RE.test(sessionId)) continue
+ const p = path.join(root, d, f)
+ try {
+ const st = await fs.promises.stat(p)
+ out.push({ sessionId, transcriptPath: p, mtime: Math.floor(st.mtimeMs) })
+ } catch {
+ /* skip */
+ }
+ }
+ }
+ return out
+}
+
+async function readTail(filePath: string): Promise<string> {
+ try {
+ const st = await fs.promises.stat(filePath)
+ if (st.size > READ_CAP_BYTES) {
+ const fd = await fs.promises.open(filePath, 'r')
+ try {
+ const { buffer } = await fd.read({
+ position: st.size - READ_CAP_BYTES,
+ length: READ_CAP_BYTES,
+ buffer: Buffer.alloc(READ_CAP_BYTES)
+ })
+ const s = buffer.toString('utf8')
+ const nl = s.indexOf('\n')
+ return nl >= 0 ? s.slice(nl + 1) : s
+ } finally {
+ await fd.close()
+ }
+ }
+ return await fs.promises.readFile(filePath, 'utf8')
+ } catch {
+ return ''
+ }
+}
+
+function loadPersisted(): TranscriptIndexEntry[] {
+ try {
+ const raw = fs.readFileSync(indexFilePath(), 'utf8')
+ const data = JSON.parse(raw)
+ return Array.isArray(data) ? (data as TranscriptIndexEntry[]) : []
+ } catch {
+ return []
+ }
+}
+
+function persist(): void {
+ try {
+ fs.writeFileSync(indexFilePath(), JSON.stringify(entries), 'utf8')
+ } catch {
+ /* best-effort */
+ }
+}
+
+async function refresh(): Promise<void> {
+ const scan = await scanTranscripts()
+ const { toRead, keep } = planRefresh(entries, scan)
+ const fresh: TranscriptIndexEntry[] = [...keep]
+ for (const f of toRead) {
+ const text = await readTail(f.transcriptPath)
+ const { cwd, title, text: body } = extractEntryFields(text)
+ fresh.push({
+ sessionId: f.sessionId,
+ transcriptPath: f.transcriptPath,
+ cwd,
+ mtime: f.mtime,
+ title,
+ text: body
+ })
+ }
+ entries = fresh
+ persist()
+}
+
+export function searchTranscripts(query: string): TranscriptHit[] {
+ return searchEntries(entries, query)
+}
+
+export function initTranscriptIndex(): void {
+ entries = loadPersisted()
+ void refresh()
+ timer = setInterval(() => void refresh(), TRANSCRIPT_INDEX_REFRESH_MS)
+ if (timer.unref) timer.unref()
+}
diff --git a/src/preload/index.ts b/src/preload/index.ts
index 4ea451e45..15d76cebd 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -241,6 +241,9 @@ const api: NodeTerminalApi = {
readTranscript: (sessionId, cwd) =>
ipcRenderer.invoke(IPC.chatReadTranscript, sessionId, cwd)
},
+ transcripts: {
+ search: (query: string) => ipcRenderer.invoke(IPC.transcriptSearch, query)
+ },
remoteHost: {
start: () => ipcRenderer.invoke(IPC.remoteHostStart),
stop: () => ipcRenderer.invoke(IPC.remoteHostStop),