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
feat(chat): serve codex rollouts through chat:read-transcript
review0c5444781485
diff --git a/src/core/transcript-ipc.codex.test.ts b/src/core/transcript-ipc.codex.test.tsnew file mode 100644index 000000000..86146c00f--- /dev/null+++ b/src/core/transcript-ipc.codex.test.ts@@ -0,0 +1,217 @@+// The ⌘M read for a CODEX node (`chat:read-transcript`, and the phone's `chat.page` through the same+// `readChatTranscript`). What these pin: a codex node is served from its own rollout — local or on+// its SSH host — and NEVER through claude's resolver (whose cwd fallback answers with a stranger's+// session) nor from this machine's disk when the node is remote.+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'+import fs from 'fs'+import os from 'os'+import path from 'path'+import { fakePlatform } from './platform-fake'+import { initPlatform, resetPlatformForTests } from './platform'+import { readChatTranscript, registerTranscriptIpc, type RemoteTranscriptPage, type TranscriptIpcDeps } from './transcript-ipc'+import { resetCodexRolloutCacheForTests } from './codex-chat'+import { setCustomAgentBaseResolver } from '../shared/agents/config'+import { IPC } from '../shared/ipc'+import type { ChatTranscriptResult } from '../shared/types'+import { CHAT_PAGE_DEFAULT_BYTES } from '../shared/chat-page'+import {+ CODEX_SID,+ assistantText,+ functionCall,+ functionOutput,+ rollout,+ turnContext,+ userMessageItem+} from './codex-rollout-fake'++const CWD = '/srv/demo'+let home: string+let f: ReturnType<typeof fakePlatform>+let savedCodexHome: string | undefined++beforeEach(() => {+ home = fs.mkdtempSync(path.join(os.tmpdir(), 'nt-transcript-codex-'))+ vi.spyOn(os, 'homedir').mockReturnValue(home)+ savedCodexHome = process.env.CODEX_HOME+ delete process.env.CODEX_HOME+ f = fakePlatform()+ initPlatform(f)+ resetCodexRolloutCacheForTests()+})+afterEach(() => {+ vi.restoreAllMocks()+ resetPlatformForTests()+ setCustomAgentBaseResolver(null)+ if (savedCodexHome === undefined) delete process.env.CODEX_HOME+ else process.env.CODEX_HOME = savedCodexHome+ fs.rmSync(home, { recursive: true, force: true })+})++const writeRollout = (body: string, id = CODEX_SID): string => {+ const dir = path.join(home, '.codex', 'sessions', '2026', '09', '24')+ fs.mkdirSync(dir, { recursive: true })+ const p = path.join(dir, `rollout-2026-09-24T09-00-00-${id}.jsonl`)+ fs.writeFileSync(p, body)+ return p+}+/** A claude transcript in the node's cwd — the stranger claude's cwd fallback would hand over. */+const writeClaudeStranger = (): string => {+ const dir = path.join(home, '.claude', 'projects', '-srv-demo')+ fs.mkdirSync(dir, { recursive: true })+ const p = path.join(dir, '46b36ce2-dd77-4f5e-a89e-4a0e831e83df.jsonl')+ fs.writeFileSync(p, JSON.stringify({ type: 'user', message: { content: 'STRANGER' } }) + '\n')+ return p+}+const BODY = rollout([+ turnContext('gpt-5.6-sol', 'medium'),+ userMessageItem(['fix the build']),+ functionCall('call_1', 'exec_command', { cmd: 'npm test' }),+ functionOutput('call_1', 'Output:\n3 passed'),+ assistantText('Fixed.')+])+/** `page` null = the legacy unpaged read (a default parameter would swallow an explicit undefined). */+const read = (q: Parameters<typeof readChatTranscript>[0], page: unknown = {}, deps: TranscriptIpcDeps = {}) =>+ readChatTranscript({ cwd: CWD, nodeId: 'n1', agentId: 'codex', ...q }, page, deps)++describe('readChatTranscript — codex, local', () => {+ it('serves the node\'s rollout as a paged ChatPage', async () => {+ writeRollout(BODY)+ const res = await read({ sessionId: CODEX_SID })+ expect(res.found).toBe(true)+ expect(res.olderCursor).toBeNull()+ expect(res.unmatchedResults).toEqual([])+ expect(res.model).toBe('gpt-5.6-sol')+ expect(res.effort).toBe('medium')+ expect(res.messages.map((m) => m.role)).toEqual(['user', 'assistant', 'assistant'])+ expect(res.messages[1].parts[0]).toEqual({ kind: 'tool', name: 'exec_command', arg: 'npm test', id: 'call_1', result: '3 passed' })+ expect(res.messages.every((m) => typeof m.key === 'number')).toBe(true)+ })++ it('NEVER reaches claude\'s resolver: no rollout ⇒ not found, even with a claude transcript in the cwd', async () => {+ writeClaudeStranger()+ const claudeHook = writeClaudeStranger()+ const res = await read({ sessionId: CODEX_SID }, {}, { pathFor: () => claudeHook })+ expect(res).toEqual({ messages: [], found: false, olderCursor: null, unmatchedResults: [] })+ const legacy = await read({ sessionId: CODEX_SID }, null, { pathFor: () => claudeHook })+ expect(legacy).toEqual({ messages: [], found: false })+ })++ it('never answers with ANOTHER codex session', async () => {+ writeRollout(BODY, '01a0c9f4-2b7e-7c31-9d52-5e8a1f3b6c99')+ expect((await read({ sessionId: CODEX_SID })).found).toBe(false)+ expect((await read({ sessionId: undefined })).found).toBe(false)+ })++ it('uses the codex tail\'s hook-fed path, never claude\'s', async () => {+ const hooked = path.join(home, 'hooked', `rollout-2026-09-24T09-00-00-${CODEX_SID}.jsonl`)+ fs.mkdirSync(path.dirname(hooked), { recursive: true })+ fs.writeFileSync(hooked, rollout([assistantText('from the hook path')]))+ const res = await read({ sessionId: CODEX_SID }, {}, { codexPathFor: () => hooked })+ expect(res.messages[0].parts[0]).toMatchObject({ text: 'from the hook path' })+ })++ it('pages back through older windows with byte-offset keys', async () => {+ const turns = []+ for (let i = 0; i < 400; i++) turns.push(userMessageItem([`q${i} ` + 'x'.repeat(900)]), assistantText(`a${i}`))+ writeRollout(rollout(turns))+ const tail = await read({ sessionId: CODEX_SID }, { maxBytes: CHAT_PAGE_DEFAULT_BYTES })+ expect(tail.olderCursor).toBeGreaterThan(0)+ const older = await read({ sessionId: CODEX_SID }, { before: tail.olderCursor, maxBytes: CHAT_PAGE_DEFAULT_BYTES })+ expect(Math.max(...older.messages.map((m) => m.key!))).toBeLessThan(tail.olderCursor!)+ expect(older.messages.at(-1)!.key! < tail.messages[0].key!).toBe(true)+ })++ it('GROWS a window that holds no complete line instead of dropping the record', async () => {+ writeRollout(rollout([assistantText('before'), userMessageItem(['big ' + 'y'.repeat(300_000)])]))+ const res = await read({ sessionId: CODEX_SID }, { maxBytes: 64 * 1024 })+ expect(res.messages.at(-1)!.parts[0]).toMatchObject({ kind: 'text' })+ expect(JSON.stringify(res.messages.at(-1))).toContain('big yyy')+ })++ it('the unpaged (legacy) read answers {messages, found} with no keys', async () => {+ writeRollout(BODY)+ const res = await read({ sessionId: CODEX_SID }, null)+ expect(Object.keys(res).sort()).toEqual(['found', 'messages'])+ expect(res.found).toBe(true)+ expect(res.messages.every((m) => m.key === undefined)).toBe(true)+ })++ it('a custom agent whose base harness is codex is read as codex', async () => {+ writeRollout(BODY)+ writeClaudeStranger()+ setCustomAgentBaseResolver((id) => (id === 'custom:cx' ? 'codex' : undefined))+ const res = await read({ sessionId: CODEX_SID, agentId: 'custom:cx' })+ expect(res.found).toBe(true)+ expect(res.messages[0].parts[0]).toMatchObject({ text: 'fix the build' })+ })+})++describe('readChatTranscript — codex, remote', () => {+ const remoteBody = Buffer.from(rollout([userMessageItem(['on the host']), assistantText('hello from the host')]))+ const hostPage = (): TranscriptIpcDeps['readRemoteCodexPage'] =>+ vi.fn(async (_q, page): Promise<RemoteTranscriptPage> => {+ const end = page.before ?? remoteBody.length+ const windowStart = Math.max(0, end - page.maxBytes)+ const start = windowStart > 0 ? windowStart - 1 : 0+ return { ok: true, data: remoteBody.subarray(start, end), start }+ })++ it('reads the HOST\'s rollout, never the local one of the same id', async () => {+ writeRollout(rollout([assistantText('LOCAL — wrong machine')]))+ const readRemoteCodexPage = hostPage()+ const res = await read({ sessionId: CODEX_SID, remoteOnly: true }, {}, { readRemoteCodexPage })+ expect(res.found).toBe(true)+ expect(JSON.stringify(res.messages)).toContain('hello from the host')+ expect(JSON.stringify(res.messages)).not.toContain('LOCAL')+ })++ it('never takes claude\'s remote leg for a codex node', async () => {+ const readRemotePage = vi.fn(async () => ({ ok: true as const, data: Buffer.from('{}'), start: 0 }))+ await read({ sessionId: CODEX_SID }, {}, { readRemotePage, readRemoteCodexPage: hostPage() })+ await read({ sessionId: CODEX_SID }, {}, { readRemotePage })+ expect(readRemotePage).not.toHaveBeenCalled()+ })++ it('a host that could not be read is UNREADABLE; a clean miss is not found', async () => {+ writeRollout(BODY)+ const failed = await read({ sessionId: CODEX_SID }, {}, { readRemoteCodexPage: async () => ({ ok: false }) })+ expect(failed).toMatchObject({ found: false, unreadable: true, messages: [] })+ const absent = await read({ sessionId: CODEX_SID }, {}, { readRemoteCodexPage: async () => ({ ok: false, absent: true }) })+ expect(absent).toEqual({ messages: [], found: false, olderCursor: null, unmatchedResults: [] })+ })++ it('a known-remote node the remote leg cannot place is unreadable — this machine\'s disk is never read', async () => {+ writeRollout(BODY)+ const paged = await read({ sessionId: CODEX_SID, remoteOnly: true }, {}, { readRemoteCodexPage: async () => null })+ expect(paged).toMatchObject({ found: false, unreadable: true, messages: [] })+ const noLeg = await read({ sessionId: CODEX_SID, remoteOnly: true })+ expect(noLeg).toMatchObject({ found: false, unreadable: true, messages: [] })+ const legacy = await read({ sessionId: CODEX_SID, remoteOnly: true }, null)+ expect(legacy).toEqual({ messages: [], found: false })+ })++ it('a growth re-read that fails is a failed read, never a local fallback', async () => {+ writeRollout(BODY)+ let calls = 0+ const readRemoteCodexPage = async (_q: unknown, page: { before: number | null; maxBytes: number }): Promise<RemoteTranscriptPage | null> => {+ calls+++ if (calls > 1) return null+ const big = Buffer.from('x'.repeat(200_000) + '\n')+ return { ok: true, data: big.subarray(big.length - page.maxBytes - 1), start: big.length - page.maxBytes - 1 }+ }+ const res = await read({ sessionId: CODEX_SID }, { maxBytes: 64 * 1024 }, { readRemoteCodexPage })+ expect(res).toMatchObject({ found: false, unreadable: true })+ })+})++describe('registerTranscriptIpc — codex node', () => {+ const chat = (nodeId: string) =>+ f.handlers[IPC.chatReadTranscript](CODEX_SID, CWD, undefined, nodeId, 'codex', {}) as Promise<ChatTranscriptResult>++ it('the shell\'s own record of a remote node forces remote-only', async () => {+ writeRollout(BODY)+ registerTranscriptIpc({ isRemoteNode: (id) => id === 'remote-node' })+ expect(await chat('remote-node')).toMatchObject({ found: false, unreadable: true })+ expect((await chat('local-node')).found).toBe(true)+ })+})diff --git a/src/core/transcript-ipc.ts b/src/core/transcript-ipc.tsindex a58b6a080..fda0f09e9 100644--- a/src/core/transcript-ipc.ts+++ b/src/core/transcript-ipc.ts@@ -15,11 +15,14 @@ import type { ChatTranscriptResult, TranscriptLine, TranscriptPresence } from '.import { CHAT_PAGE_MAX_BYTES, normalizeChatPage, type ChatTranscriptPage } from '../shared/chat-page'import { platform } from './platform'import { chatMessagesFromGrok } from './grok-chat'+import { chatMessagesFromCodex, locateCodexRollout, parseCodexChatWindow } from './codex-chat'import { locateGrok } from './handoff/locate'+import { capabilityAgentId } from '../shared/agents/config'import {parseChatMessages,parseChatWindow,parseTranscriptLines,+ type ChatWindowParse,readChatWindow,readCappedTail,readChatMessages,@@ -78,6 +81,20 @@ export interface TranscriptIpcDeps {* (the Server Edition — it runs ON the host) = no node is remote, which is correct there.*/isRemoteNode?(nodeId: string): boolean+ /**+ * The rollout path the CODEX context tail learned from a hook for this session (the `pathFor` above+ * is CLAUDE's tail and must never answer for a codex id). A hint only: `locateCodexRollout` uses it+ * when its file name names this very thread and it exists. Both shells wire it.+ */+ codexPathFor?(sessionId: string): string | undefined+ /**+ * ONE page of a REMOTE codex node's rollout, located ON the host under the node's own account home+ * and read with the same ranged read claude's remote leg uses. Same conventions as+ * `readRemotePage`: `null` = not a remote node; `{ok:false}` = remote and unreadable (terminal —+ * never this machine's disk); `{ok:false, absent:true}` = the host looked and has no such rollout.+ * Electron-only; the Server Edition runs on the host it reads.+ */+ readRemoteCodexPage?(q: TranscriptQuery, page: ChatTranscriptPage): Promise<RemoteTranscriptPage | null>}export type RemoteTranscriptPage = { ok: true; data: Buffer; start: number } | { ok: false; absent?: true }@@ -108,12 +125,13 @@ type WindowRead = (page: ChatTranscriptPage) => Promise<{ data: Buffer; start: nasync function parseGrowingWindow(page: ChatTranscriptPage,first: { data: Buffer; start: number },- read: WindowRead+ read: WindowRead,+ parse: (buf: Buffer, bufStart: number) => ChatWindowParse = parseChatWindow): Promise<ChatTranscriptResult> {let w = firstlet maxBytes = page.maxBytesfor (;;) {- const { noCompleteLine, ...parsed } = parseChatWindow(w.data, w.start)+ const { noCompleteLine, ...parsed } = parse(w.data, w.start)if (!noCompleteLine || w.start === 0 || maxBytes >= CHAT_PAGE_MAX_BYTES) return { found: true, ...parsed }maxBytes = Math.min(CHAT_PAGE_MAX_BYTES, maxBytes * CHAT_PAGE_GROWTH)const next = await read({ before: page.before, maxBytes })@@ -174,6 +192,42 @@ async function readChatPage(return parseGrowingWindow(page, w, async (pg) => (await readChatWindow(p, pg)) ?? null)}+/**+ * A paged read of a CODEX node's rollout — `readChatPage`'s shape with codex's own locator and parser+ * (a rollout is append-only JSONL, so it pages by byte offset exactly like claude's transcript).+ * Nothing claude-shaped runs: not `resolveTranscript` (its cwd fallback answers with the newest+ * CLAUDE session in the directory), not claude's remote leg (it locates a claude file on the host).+ * Remote first and terminal, as everywhere: a remote node is read on its host or not at all.+ */+async function readCodexChatPage(+ q: TranscriptQuery,+ page: ChatTranscriptPage,+ deps: TranscriptIpcDeps+): Promise<ChatTranscriptResult> {+ const readRemote = deps.readRemoteCodexPage+ if (readRemote) {+ const remote = await readRemote(q, page)+ if (remote !== null) {+ if (!remote.ok) return remote.absent ? notFoundPage() : unreadablePage()+ return parseGrowingWindow(+ page,+ remote,+ async (p) => {+ const r = await readRemote(q, p)+ return r && r.ok ? r : null+ },+ parseCodexChatWindow+ )+ }+ }+ if (q.remoteOnly) return unreadablePage()+ const p = await locateCodexRollout({ sessionId: q.sessionId, accountId: q.accountId }, deps.codexPathFor)+ if (!p) return notFoundPage()+ const w = await readChatWindow(p, page)+ if (!w) return notFoundPage()+ return parseGrowingWindow(page, w, async (pg) => (await readChatWindow(p, pg)) ?? null, parseCodexChatWindow)+}+/*** Resolve a session's transcript path: the exact session file when a (valid) sessionId is known,* else the node's cwd — durable, and needing no live hook event. `accountId` scopes BOTH legs to@@ -238,6 +292,18 @@ export async function readChatTranscript(? { messages: [], found: false, ...paging }: { messages: chatMessagesFromGrok(buf), found: true, ...paging }}+ // Codex — the builtin or a custom agent whose base harness it is — is routed BEFORE the claude+ // path for the same reason as grok: a codex thread id never resolves under claude's tree, and the+ // cwd fallback would then answer with somebody else's claude session.+ if (agentId && capabilityAgentId(agentId) === 'codex') {+ if (page) return readCodexChatPage({ sessionId, cwd, accountId, nodeId, ...(remoteOnly ? { remoteOnly } : {}) }, page, deps)+ // The unpaged (legacy) read has no live caller — the ⌘M panel and the phone always page — so it+ // is served locally or not at all, like grok's: a remote node's rollout is on its host.+ if (remoteOnly) return { messages: [], found: false }+ const cp = await locateCodexRollout({ sessionId, accountId }, deps.codexPathFor)+ const text = cp ? await readCappedTail(cp) : undefined+ return text === undefined ? { messages: [], found: false } : { messages: chatMessagesFromCodex(text), found: true }+ }if (page) return readChatPage({ sessionId, cwd, accountId, nodeId, ...(remoteOnly ? { remoteOnly } : {}) }, page, deps)const remote = deps.readRemote ? await deps.readRemote({ sessionId, cwd, accountId, nodeId }) : null// A resolved-but-unreadable remote file is NOT "no conversation yet" — the read failed