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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(agents): stop the codex/gemini meter and find bar reading claude's transcript
enesa5fa22409af1
diff --git a/src/core/claude-accounts-core.test.ts b/src/core/claude-accounts-core.test.tsindex b6fa58bae..05eb14e73 100644--- a/src/core/claude-accounts-core.test.ts+++ b/src/core/claude-accounts-core.test.ts@@ -172,6 +172,21 @@ describe('isSafeLocalTranscriptPath', () => {isSafeLocalTranscriptPath(`${home}/.codex/sessions/2026/07/26/rollout-2026-07-26T00-48-38-019f9b40.jsonl`, home, ud)).toBe(true)})+ it("honors a relocated codex home ($CODEX_HOME), and only that one", () => {+ // The shells pass `codexHome()` (core/usage/codex-usage.ts), which honors $CODEX_HOME. Without+ // this the jail fails CLOSED on a relocated codex — its meter would silently never fill, which+ // is the quiet failure mode, not a leak.+ const moved = '/opt/codex-home'+ expect(isSafeLocalTranscriptPath(`${moved}/sessions/2026/07/26/rollout-x.jsonl`, home, ud, moved)).toBe(true)+ expect(isSafeLocalTranscriptPath(`${moved}/sessions`, home, ud, moved)).toBe(true)+ // The relocated home REPLACES the default; it does not add to it.+ expect(isSafeLocalTranscriptPath(`${home}/.codex/sessions/x.jsonl`, home, ud, moved)).toBe(false)+ // …and the rest of the relocated home is still out of reach.+ expect(isSafeLocalTranscriptPath(`${moved}/auth.json`, home, ud, moved)).toBe(false)+ // Omitted / empty ⇒ the `<home>/.codex` default, exactly as before this parameter existed.+ expect(isSafeLocalTranscriptPath(`${home}/.codex/sessions/x.jsonl`, home, ud)).toBe(true)+ expect(isSafeLocalTranscriptPath(`${home}/.codex/sessions/x.jsonl`, home, ud, '')).toBe(true)+ })it('still refuses the rest of those agents\' config trees, and everything outside all roots', () => {// The widening is per-ROOT, not per-agent-home: the credential and settings files that sit// beside the transcripts stay out of reach.diff --git a/src/core/claude-accounts-core.ts b/src/core/claude-accounts-core.tsindex 50e7a36a1..71760c9fd 100644--- a/src/core/claude-accounts-core.ts+++ b/src/core/claude-accounts-core.ts@@ -63,16 +63,24 @@ export function transcriptRootFor(* - claude's system default `~/.claude/projects`,* - a managed account's `{userData}/claude-accounts/<accountId>/projects`,* - gemini's `~/.gemini/tmp` (its chats are `<project>/chats/session-*.jsonl`), and- * - codex's `~/.codex/sessions` (its rollouts are `YYYY/MM/DD/rollout-*.jsonl`).+ * - codex's `<codexHome>/sessions` (its rollouts are `YYYY/MM/DD/rollout-*.jsonl`).* For the account root the `<accountId>` segment is validated with `ACCOUNT_ID_RE` (dots barred,* so `..` can never sneak in) and the very next segment must be `projects` — a prefix match on* `{userData}/claude-accounts` alone is NOT enough (it would accept `…/claude-accounts/x/.ssh`).* `abs` must already be resolved/normalized by the caller (e.g. `path.resolve(tp)`).+ *+ * `codexHomeDir` is where codex keeps its state — `$CODEX_HOME` when the user has moved it, which+ * `core/usage/codex-usage.ts`'s `codexHome()` already resolves for the usage reader. Trailing and+ * optional, defaulting to `<homeDir>/.codex`, so every pre-existing caller is unchanged. It is a+ * PARAMETER rather than an env read because this module is pure path math: the shells own the env.+ * Getting it wrong fails CLOSED (a relocated codex home would silently never fill its meter, not+ * leak anything) — which is the quieter and therefore worse failure, hence the parameter.*/export function isSafeLocalTranscriptPath(abs: string,homeDir: string,- userDataPath: string+ userDataPath: string,+ codexHomeDir?: string): boolean {const legacyRoot = path.join(homeDir, '.claude', 'projects')if (abs === legacyRoot || abs.startsWith(legacyRoot + path.sep)) return true@@ -83,7 +91,7 @@ export function isSafeLocalTranscriptPath(// read at `~/.ssh/id_rsa`, and a home-wide allowance would hand that straight back.const geminiRoot = path.join(homeDir, '.gemini', 'tmp')if (abs === geminiRoot || abs.startsWith(geminiRoot + path.sep)) return true- const codexRoot = path.join(homeDir, '.codex', 'sessions')+ const codexRoot = path.join(codexHomeDir || path.join(homeDir, '.codex'), 'sessions')if (abs === codexRoot || abs.startsWith(codexRoot + path.sep)) return trueconst accountsRoot = path.join(userDataPath, 'claude-accounts')if (abs !== accountsRoot && !abs.startsWith(accountsRoot + path.sep)) return falsediff --git a/src/main/index.ts b/src/main/index.tsindex 65a6d8011..eb0b1ee2d 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -77,6 +77,7 @@ import { createSubagentTail } from '../core/subagent-tail'import { createContextTail, type TaskNotification } from '../core/context-tail'import { geminiContextParse } from '../core/gemini-session'import { codexContextParse } from '../core/codex-session'+import { codexHome } from '../core/usage/codex-usage'import { grokRawFields, isAsyncSubagentLaunch, type NormalizedAgentEvent } from '../shared/agents/normalize'import { grokSessionDir, grokSessionsDir } from '../core/agents/grok-paths'import { forgetGrokSession, rememberGrokSessionDir } from '../core/grok-session'@@ -1477,7 +1478,11 @@ app.whenReady().then(async () => {const safeTranscriptPath = (tp: string | undefined): string | undefined => {if (!tp) return undefinedconst abs = resolve(tp)- return isSafeLocalTranscriptPath(abs, homedir(), app.getPath('userData')) ? abs : undefined+ // codexHome() honors $CODEX_HOME — a relocated codex (the snap-codex case this project has hit+ // before) would otherwise fail the jail and its meter would silently never fill.+ return isSafeLocalTranscriptPath(abs, homedir(), app.getPath('userData'), codexHome())+ ? abs+ : undefined}// Remote analogue of safeTranscriptPath: a remote node's transcript_path is a remote absolute// path arriving over the reverse tunnel — a forged POST must not read an arbitrary remote file.diff --git a/src/renderer/components/ContextMeter.tsx b/src/renderer/components/ContextMeter.tsxindex ab1c0cb21..97bcdef42 100644--- a/src/renderer/components/ContextMeter.tsx+++ b/src/renderer/components/ContextMeter.tsx@@ -51,7 +51,10 @@ export function ContextMeter({ sessionId }: { sessionId: string | null }): JSX.E~{formatTokens(usage.usedTokens)} / {formatTokens(usage.windowTokens)} tokens</div><div className="ctx-popover__sub">- {usage.model ?? 'claude'} · Updated {formatTimeAgo(usage.updatedAt)}+ {/* No model read ⇒ say nothing. This used to fall back to the literal 'claude', which+ was harmless while the meter was claude-only and became a mislabel once codex and+ gemini joined USAGE_CAPABLE — a codex popover would have claimed to be claude. */}+ {usage.model ? `${usage.model} · ` : ''}Updated {formatTimeAgo(usage.updatedAt)}</div></div>)}diff --git a/src/renderer/components/kanban/ModalTerminal.tsx b/src/renderer/components/kanban/ModalTerminal.tsxindex 14af2c8d3..c3e0e35ae 100644--- a/src/renderer/components/kanban/ModalTerminal.tsx+++ b/src/renderer/components/kanban/ModalTerminal.tsx@@ -2,7 +2,7 @@ import { useCallback, useEffect, useRef, useState } from 'react'import { Terminal } from '@xterm/xterm'import { FitAddon } from '@xterm/addon-fit'import { SearchAddon } from '@xterm/addon-search'-import { hasUsage } from '@shared/agents/config'+import { readsClaudeTranscript } from '../../lib/transcriptGates'import { FindBar } from '../FindBar'import { useAgentStatus } from '../../state/agentStatus'import { useProjects } from '../../state/projects'@@ -102,7 +102,10 @@ export function ModalTerminal({ nodeId, spawn, searchOpen, onCloseSearch }: ModasessionId: agentSessionId,cwd: spawn.cwd,accountId: spawn.accountId,- searchTranscript: !!spawn.agentId && hasUsage(spawn.agentId),+ // MIRROR TerminalNode: the transcript index reads claude's JSONL through claude's resolver, so+ // it is gated on the claude-transcript fact, NOT on the context meter's `hasUsage` (which now+ // spans codex and gemini too) — see lib/transcriptGates.ts.+ searchTranscript: readsClaudeTranscript(spawn.agentId),open: searchOpen,readBuffer})diff --git a/src/renderer/lib/transcriptGates.test.ts b/src/renderer/lib/transcriptGates.test.tsnew file mode 100644index 000000000..6368d0324--- /dev/null+++ b/src/renderer/lib/transcriptGates.test.ts@@ -0,0 +1,37 @@+import { describe, expect, it } from 'vitest'+import { readsClaudeTranscript } from './transcriptGates'+import { hasUsage, type AgentId } from '@shared/agents/config'++describe('readsClaudeTranscript', () => {+ it('is true for claude, whose transcript our readers own', () => {+ expect(readsClaudeTranscript('claude')).toBe(true)+ })++ it('is false for every agent whose transcript is NOT claude-shaped', () => {+ for (const id of ['codex', 'gemini', 'grok', 'opencode'] as AgentId[]) {+ expect(readsClaudeTranscript(id)).toBe(false)+ }+ })++ it('is false for a custom agent and for no agent at all (a plain terminal)', () => {+ expect(readsClaudeTranscript('my-custom-agent' as AgentId)).toBe(false)+ expect(readsClaudeTranscript(undefined)).toBe(false)+ })++ it('does NOT follow the context meter — the regression this gate exists for', () => {+ // The bug: `context.ensure` and the find bar's transcript index were gated on `hasUsage`, so+ // joining codex/gemini to USAGE_CAPABLE silently pointed both at claude's `resolveTranscript`.+ // Its cwd fallback returns the newest CLAUDE transcript for the node's cwd, so a codex node+ // metered — and searched — an unrelated claude session.+ //+ // These two expectations must therefore DISAGREE for codex and gemini. If this gate is ever+ // wired back to `hasUsage`, the second one fails.+ for (const id of ['codex', 'gemini'] as AgentId[]) {+ expect(hasUsage(id)).toBe(true) // it has a meter (fed by its OWN tail, no resolver involved)+ expect(readsClaudeTranscript(id)).toBe(false) // …and still no claude-transcript read+ }+ // claude is the one agent for which both are true, which is why the shared gate went unnoticed.+ expect(hasUsage('claude')).toBe(true)+ expect(readsClaudeTranscript('claude')).toBe(true)+ })+})diff --git a/src/renderer/lib/transcriptGates.ts b/src/renderer/lib/transcriptGates.tsnew file mode 100644index 000000000..3a0d08aab--- /dev/null+++ b/src/renderer/lib/transcriptGates.ts@@ -0,0 +1,37 @@+import { canChat, type AgentId } from '@shared/agents/config'++/**+ * Does this node's conversation live in a file **claude's** transcript readers can locate and parse?+ *+ * This is the gate for every feature that goes through `core/transcript-ipc.ts`'s+ * `resolveTranscript` — today `context.ensure` (the context meter's mount-time rehydration) and the+ * find bar's transcript index (`claude.readTranscript`). It is deliberately NOT `hasUsage`.+ *+ * Those two used to share `hasUsage` with the context METER, back when all three were claude-only+ * and the distinction cost nothing. Then codex and gemini joined `USAGE_CAPABLE` (their own+ * transcripts state the numbers a meter needs) and the shared gate turned into a bug in both+ * features at once, because `resolveTranscript` has a **cwd fallback**: when the sessionId leg+ * misses — which it always does for a codex/gemini id, since no `<that id>.jsonl` exists under+ * `~/.claude/projects` — it returns *the newest claude transcript for that cwd*. So a codex node+ * would rehydrate its meter from a stranger's claude session (wrong numerator AND wrong+ * denominator, then flapping against the correct codex tail) and its find bar would present that+ * session's messages as its own hits. Even wired to the right file the reader would be wrong: it+ * parses claude's JSONL shape, which a codex rollout is not.+ *+ * `CHAT_CAPABLE` already states exactly the fact being asked for — "we can read and render this+ * agent's transcript ourselves" — so it is reused here rather than adding a fourth capability list+ * that would mean the same thing.+ *+ * The meter itself stays on `hasUsage` and spans three agents: it is fed by the per-agent context+ * tails in the shells (`geminiContextParse` / `codexContextParse`), which need no resolver because+ * the hook envelope hands them the path. The only thing a non-claude agent gives up here is the+ * mount-time HEAD START: its meter fills on the first hook event after mount instead of instantly.+ * Correct-but-later beats instant-but-borrowed-from-another-session.+ *+ * FOLLOW-UP (own task): per-agent rehydration. Making `context.ensure` work for codex/gemini means+ * teaching it to resolve THEIR transcripts (`handoff/locate.ts` already has `locateCodex` /+ * `locateGemini` by sessionId) and to route to the matching tail — a real feature, not a gate.+ */+export function readsClaudeTranscript(agentId: AgentId | undefined): boolean {+ return !!agentId && canChat(agentId)+}diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsxindex 46b70f82b..8577797d4 100644--- a/src/renderer/nodes/TerminalNode.tsx+++ b/src/renderer/nodes/TerminalNode.tsx@@ -93,6 +93,7 @@ import { useTerminalSearch } from '../terminal/useTerminalSearch'import { ContextMeter } from '../components/ContextMeter'import { isZoomModifierHeld } from '../lib/zoomModifier'import { isHidden } from '../lib/ui-visibility'+import { readsClaudeTranscript } from '../lib/transcriptGates'import { useSettings } from '../state/settings'import { useAgentStatus, inferInterruptAfterSettle } from '../state/agentStatus'import type { ClientId } from '@shared/presence'@@ -797,6 +798,10 @@ export function TerminalNode({const contextLinkCapable = !!agentId && canContextLink(agentId) // context-link tip wording only; handles render on all terminalsconst showUsage = !!agentId && hasUsage(agentId) // per-node context-window meterconst showChat = !!agentId && canChat(agentId) // Cmd+M opens a chat panel instead of markdown+ // Everything that reads the conversation through CLAUDE's transcript readers (`context.ensure`'s+ // mount-time meter rehydration, the find bar's transcript index) — deliberately NOT `showUsage`,+ // which now spans three agents. See lib/transcriptGates.ts for what sharing that gate broke.+ const claudeTranscript = readsClaudeTranscript(agentId)// The header 💬 now opens the board-log comments flyout (right side); ⌘M keeps the markdown/chat view.const [commentsOpen, setCommentsOpen] = useState(false)const canRenameNode = !!agentId && canRename(agentId) // title ⇄ session-name two-way sync@@ -847,11 +852,19 @@ export function TerminalNode({// Feed the context meter without waiting for a live hook event: after an app restart the// continuing tmux session is idle and emits no event, so the main-process tailer is never// re-fed. Re-runs if the sessionId changes (track is idempotent). cwd is a path fallback.+ //+ // CLAUDE ONLY (`claudeTranscript`, not `showUsage`). The handler resolves this sessionId through+ // claude's `resolveTranscript`, whose cwd fallback answers *the newest claude transcript for that+ // cwd* — for a codex/gemini node that is a stranger's session, tracked on the CLAUDE tail under+ // this node's session id, so its meter would show another agent's fill and then flap against the+ // correct tail. The cost of the gate: a codex/gemini meter fills on the first hook event after+ // mount instead of instantly. Their tails need no resolver (the hook envelope carries the path),+ // so nothing else is lost. Per-agent rehydration is a follow-up task — see transcriptGates.ts.useEffect(() => {const sid = status?.sessionId- if (showUsage && sid)+ if (claudeTranscript && sid)window.nodeTerminal.context.ensure(sid, (data.cwd as string) || undefined, data.accountId)- }, [showUsage, status?.sessionId, data.cwd, data.accountId])+ }, [claudeTranscript, status?.sessionId, data.cwd, data.accountId])const updateNodeInternals = useUpdateNodeInternals()const [searchOpen, setSearchOpen] = useState(false)@@ -936,7 +949,9 @@ export function TerminalNode({sessionId: status?.sessionId,cwd: data.cwd as string | undefined,accountId: data.accountId,- searchTranscript: showUsage,+ // The transcript index reads claude's JSONL through the same resolver, so it is gated on the+ // claude-transcript fact, NOT on the meter's `showUsage` — see lib/transcriptGates.ts.+ searchTranscript: claudeTranscript,open: searchOpen,readBuffer})diff --git a/src/renderer/terminal/useTerminalSearch.ts b/src/renderer/terminal/useTerminalSearch.tsindex 8316a56d8..025b32e6a 100644--- a/src/renderer/terminal/useTerminalSearch.ts+++ b/src/renderer/terminal/useTerminalSearch.ts@@ -15,7 +15,12 @@ interface Args {cwd: string | undefined/** Managed Claude account whose transcript root the search resolves against (default system). */accountId: string | undefined- /** Whether this node has a readable Claude transcript (gated on hasUsage capability). */+ /**+ * Whether this node has a readable CLAUDE transcript. Callers gate this on+ * `readsClaudeTranscript` (lib/transcriptGates.ts) — NOT on the context meter's `hasUsage`, which+ * spans codex and gemini, whose transcripts this reader cannot parse and whose resolver fallback+ * would hand it an unrelated claude session.+ */searchTranscript: booleanopen: boolean/** Fallback content source (live xterm buffer text) when tmux capture is unavailable. */diff --git a/src/server/agent-status.ts b/src/server/agent-status.tsindex 54b1a8cb3..b3fd9621a 100644--- a/src/server/agent-status.ts+++ b/src/server/agent-status.ts@@ -17,6 +17,7 @@ import { createSubagentTail, type SubagentTail } from '../core/subagent-tail'import { createContextTail, type ContextTail, type TaskNotification } from '../core/context-tail'import { geminiContextParse } from '../core/gemini-session'import { codexContextParse } from '../core/codex-session'+import { codexHome } from '../core/usage/codex-usage'import { setNodeTranscript } from '../core/context-link'import { isSafeLocalTranscriptPath } from '../core/claude-accounts-core'import { grokRawFields, isAsyncSubagentLaunch, type NormalizedAgentEvent } from '../shared/agents/normalize'@@ -148,7 +149,11 @@ export function wireAgentStatus(const safeTranscriptPath = (tp: string | undefined): string | undefined => {if (!tp) return undefinedconst abs = resolve(tp)- return isSafeLocalTranscriptPath(abs, homedir(), platform.userDataDir) ? abs : undefined+ // codexHome() honors $CODEX_HOME — a relocated codex (the snap-codex case this project has hit+ // before) would otherwise fail the jail and its meter would silently never fill.+ return isSafeLocalTranscriptPath(abs, homedir(), platform.userDataDir, codexHome())+ ? abs+ : undefined}const SUBAGENT_TOOLS = new Set(['Agent', 'Task'])