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.

fix(terminal): resolve transcript by cwd and fix zoom/listener glitches

enes21c29d95157a
diff --git a/src/main/index.ts b/src/main/index.ts
index a63ddd50f..1c0d74f80 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -15,7 +15,12 @@ import { hookServer } from './agents/hook-server'
import { installManagedAgentHooks } from './agents/hooks'
import { createSubagentTail } from './subagent-tail'
import { createContextTail } from './context-tail'
-import { readTranscriptLines, resolveTranscriptPath, SESSION_ID_RE } from './transcript-reader'
+import {
+ readTranscriptLines,
+ resolveTranscriptPath,
+ transcriptPathForCwd,
+ SESSION_ID_RE
+} from './transcript-reader'
import { initBridge } from './bridge'
import { initTelemetry } from './telemetry'
import { initClaudeUsage } from './claude-usage'
@@ -249,11 +254,19 @@ 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) => {
- if (!SESSION_ID_RE.test(sessionId)) return []
- const p = contextTail.pathFor(sessionId) ?? (await resolveTranscriptPath(sessionId))
- return p ? readTranscriptLines(p) : []
- })
+ ipcMain.handle(
+ IPC.claudeReadTranscript,
+ async (_e, sessionId: string | undefined, cwd: string | undefined) => {
+ // Prefer the exact session path when a (valid) sessionId is known; otherwise fall
+ // back to the node's cwd, which is durable and doesn't need a live hook event.
+ let p: string | undefined
+ if (sessionId && SESSION_ID_RE.test(sessionId)) {
+ p = contextTail.pathFor(sessionId) ?? (await resolveTranscriptPath(sessionId))
+ }
+ if (!p && cwd) p = await transcriptPathForCwd(cwd)
+ 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
index 3429e5b2b..1210f5845 100644
--- a/src/main/transcript-reader.ts
+++ b/src/main/transcript-reader.ts
@@ -122,3 +122,34 @@ export async function resolveTranscriptPath(sessionId: string): Promise<string |
}
return undefined
}
+
+// Durable resolver by working directory: Claude stores a project's transcripts under
+// ~/.claude/projects/<cwd with every '/' and '.' replaced by '-'>/. We pick the most
+// recently modified .jsonl there — the node's active session. Unlike the sessionId path
+// this needs no live hook event, so the find-bar works even after a reload/restart or when
+// reattaching to a session this app instance didn't spawn. (Encoding leaves no '/', so it
+// can't traverse.) Limitation: multiple Claude nodes in the SAME cwd resolve to the same
+// newest transcript — the sessionId path above is preferred when known for that reason.
+export async function transcriptPathForCwd(cwd: string): Promise<string | undefined> {
+ if (!cwd) return undefined
+ const encoded = cwd.replace(/[/.]/g, '-')
+ const dir = path.join(os.homedir(), '.claude', 'projects', encoded)
+ let entries: string[]
+ try {
+ entries = await fs.promises.readdir(dir)
+ } catch {
+ return undefined
+ }
+ let newest: { path: string; mtime: number } | undefined
+ for (const e of entries) {
+ if (!e.endsWith('.jsonl')) continue
+ const p = path.join(dir, e)
+ try {
+ const st = await fs.promises.stat(p)
+ if (!newest || st.mtimeMs > newest.mtime) newest = { path: p, mtime: st.mtimeMs }
+ } catch {
+ /* skip */
+ }
+ }
+ return newest?.path
+}
diff --git a/src/preload/index.ts b/src/preload/index.ts
index 043521022..5b842b975 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -8,6 +8,28 @@ import type {
Workspace
} from '../shared/types'
+// Fan a single ipcRenderer listener per channel out to many renderer subscribers. Without
+// this, every node that subscribes (e.g. Cmd+M markdown toggle on each terminal/editor) adds
+// its own ipcRenderer listener, tripping Node's MaxListeners (>10) warning. Returns unsubscribe.
+function subscribe<A extends unknown[] = []>(channel: string) {
+ const listeners = new Set<(...args: A) => void>()
+ let handler: ((e: unknown, ...args: A) => void) | null = null
+ return (listener: (...args: A) => void): (() => void) => {
+ if (!handler) {
+ handler = (_e, ...args) => listeners.forEach((l) => l(...args))
+ ipcRenderer.on(channel, handler)
+ }
+ listeners.add(listener)
+ return () => {
+ listeners.delete(listener)
+ if (listeners.size === 0 && handler) {
+ ipcRenderer.removeListener(channel, handler)
+ handler = null
+ }
+ }
+ }
+}
+
const api: NodeTerminalApi = {
pty: {
create: (options: PtyCreateOptions) => ipcRenderer.invoke(IPC.ptyCreate, options),
@@ -144,7 +166,8 @@ const api: NodeTerminalApi = {
}
},
claude: {
- readTranscript: (sessionId) => ipcRenderer.invoke(IPC.claudeReadTranscript, sessionId)
+ readTranscript: (sessionId, cwd) =>
+ ipcRenderer.invoke(IPC.claudeReadTranscript, sessionId, cwd)
},
bridge: {
configPath: () => ipcRenderer.invoke(IPC.bridgeConfigPath),
@@ -155,16 +178,10 @@ const api: NodeTerminalApi = {
return () => ipcRenderer.removeListener(IPC.bridgeMessage, handler)
}
},
- onMarkdownToggle: (listener) => {
- const handler = () => listener()
- ipcRenderer.on(IPC.appToggleMarkdown, handler)
- return () => ipcRenderer.removeListener(IPC.appToggleMarkdown, handler)
- },
- onCloseNode: (listener) => {
- const handler = () => listener()
- ipcRenderer.on(IPC.appCloseNode, handler)
- return () => ipcRenderer.removeListener(IPC.appCloseNode, handler)
- },
+ // Per-node subscriptions (each terminal/editor listens) — multiplexed so they don't pile up
+ // ipcRenderer listeners and trip the MaxListeners warning.
+ onMarkdownToggle: subscribe(IPC.appToggleMarkdown),
+ onCloseNode: subscribe(IPC.appCloseNode),
closeWindow: () => ipcRenderer.send(IPC.appCloseWindow),
setBadgeCount: (count) => ipcRenderer.send(IPC.appSetBadge, count),
// Absolute path of a dropped/picked File (File.path was removed in Electron 30+).
diff --git a/src/renderer/lib/zoomModifier.ts b/src/renderer/lib/zoomModifier.ts
new file mode 100644
index 000000000..5f1605d07
--- /dev/null
+++ b/src/renderer/lib/zoomModifier.ts
@@ -0,0 +1,26 @@
+// Tracks whether a zoom modifier (Cmd/Ctrl) is currently held, via a single set of
+// capture-phase window listeners. Used by the terminal hover-guard so Cmd+wheel zooming over
+// a terminal doesn't dwell-focus (enter) the terminal — the canvas keeps zooming instead.
+let held = false
+let inited = false
+
+function ensure(): void {
+ if (inited) return
+ inited = true
+ const down = (e: KeyboardEvent) => {
+ if (e.key === 'Meta' || e.key === 'Control' || e.metaKey || e.ctrlKey) held = true
+ }
+ const up = (e: KeyboardEvent) => {
+ if (e.key === 'Meta' || e.key === 'Control') held = false
+ else if (!e.metaKey && !e.ctrlKey) held = false
+ }
+ window.addEventListener('keydown', down, true)
+ window.addEventListener('keyup', up, true)
+ window.addEventListener('blur', () => (held = false))
+}
+
+/** True while Cmd or Ctrl is currently pressed. */
+export function isZoomModifierHeld(): boolean {
+ ensure()
+ return held
+}
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index eb448dbd5..7b6630d92 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -19,6 +19,7 @@ import { NodeTags } from '../components/NodeTags'
import { Tooltip } from '../components/Tooltip'
import { useTerminalSearch } from '../terminal/useTerminalSearch'
import { ContextMeter } from '../components/ContextMeter'
+import { isZoomModifierHeld } from '../lib/zoomModifier'
import { useSettings } from '../state/settings'
import { useAgentStatus } from '../state/agentStatus'
import { useAgentNodes } from '../state/agentNodes'
@@ -87,6 +88,7 @@ export function TerminalNode({ id, data, selected }: NodeProps<CanvasNode>) {
const search = useTerminalSearch({
nodeId: id,
sessionId: status?.sessionId,
+ cwd: data.cwd as string | undefined,
searchTranscript: showUsage,
open: searchOpen,
readBuffer
@@ -287,12 +289,19 @@ export function TerminalNode({ id, data, selected }: NodeProps<CanvasNode>) {
// ---- hover guard: dwell before entering the terminal ----
const onBodyEnter = () => {
if (dwellRef.current) clearTimeout(dwellRef.current)
- dwellRef.current = setTimeout(() => {
+ const enter = () => {
+ // While Cmd/Ctrl is held the user is zooming the canvas — don't grab focus / enter the
+ // terminal; just keep checking until the modifier is released.
+ if (isZoomModifierHeld()) {
+ dwellRef.current = setTimeout(enter, 200)
+ return
+ }
setArmed(false)
termRef.current?.focus()
useAgentStatus.getState().setActive(id, true)
useAgentStatus.getState().clearUnread(id)
- }, panHoverDelay)
+ }
+ dwellRef.current = setTimeout(enter, panHoverDelay)
}
const onBodyLeave = () => {
if (dwellRef.current) clearTimeout(dwellRef.current)
diff --git a/src/renderer/terminal/useTerminalSearch.ts b/src/renderer/terminal/useTerminalSearch.ts
index 64d221046..549d4b777 100644
--- a/src/renderer/terminal/useTerminalSearch.ts
+++ b/src/renderer/terminal/useTerminalSearch.ts
@@ -10,6 +10,8 @@ export interface SearchSnippet {
interface Args {
nodeId: string
sessionId: string | undefined
+ /** The node's working directory — durable fallback for resolving the transcript. */
+ cwd: string | undefined
/** Whether this node has a readable Claude transcript (gated on hasUsage capability). */
searchTranscript: boolean
open: boolean
@@ -30,6 +32,7 @@ export interface TerminalSearch {
export function useTerminalSearch({
nodeId,
sessionId,
+ cwd,
searchTranscript,
open,
readBuffer
@@ -57,9 +60,14 @@ export function useTerminalSearch({
}
if (!captured) captured = readBuffer()
for (const t of captured.split('\n')) lines.push({ source: 'terminal', text: t })
- if (searchTranscript && sessionId) {
+ // Search the full Claude transcript for agent nodes. Resolved by sessionId when known,
+ // else by cwd (durable) — so it works even when no live hook event set the sessionId.
+ if (searchTranscript) {
try {
- const tr: TranscriptLine[] = await window.nodeTerminal.claude.readTranscript(sessionId)
+ const tr: TranscriptLine[] = await window.nodeTerminal.claude.readTranscript(
+ sessionId,
+ cwd
+ )
for (const l of tr) {
for (const t of l.text.split('\n')) lines.push({ source: 'claude', role: l.role, text: t })
}
@@ -73,7 +81,7 @@ export function useTerminalSearch({
cancelled = true
}
// readBuffer must be stable (useCallback in the caller) to avoid rebuilds.
- }, [open, nodeId, sessionId, searchTranscript, readBuffer])
+ }, [open, nodeId, sessionId, cwd, searchTranscript, readBuffer])
const matches = useMemo(() => {
const q = query.trim().toLowerCase()
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 72018340a..1de8b244b 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -482,8 +482,15 @@ export interface TranscriptLine {
}
export interface ClaudeApi {
- /** Reads a Claude session's full transcript as flat searchable lines ([] if unavailable). */
- readTranscript(sessionId: string): Promise<TranscriptLine[]>
+ /**
+ * Reads a Claude session's full transcript as flat searchable lines ([] if unavailable).
+ * Resolves by `sessionId` when known (exact); otherwise falls back to `cwd` (durable —
+ * the newest transcript under that project dir, no live hook event required).
+ */
+ readTranscript(
+ sessionId: string | undefined,
+ cwd: string | undefined
+ ): Promise<TranscriptLine[]>
}
export interface LicenseStatus {