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.

Merge origin/feat/chat-view-opencode into feat/chat-view-agents

review22158d5a42e9
diff --cc CLAUDE.md
index b2851ff0e,64b355494..a3a3fc5c1
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@@ -1738,9 -1738,8 +1738,10 @@@ else, and its context links must keep c
`PERMISSION_MODE_CAPABLE`, `MODEL_SWITCH_CAPABLE`, with helpers (`hasHooks`,
`canBranch`, `canContextLink`, `canChat`, `canRename`, `canReadTitle`, `hasPermissionMode`, …).
Branch stays **Claude-only** purely by being in only `BRANCH_CAPABLE`. The ⌘M **ChatPanel**
- transcript view (`CHAT_CAPABLE` / `canChat`) is **claude + grok + gemini + codex + copilot** since
- 2026-09: grok's `chat_history.jsonl`, gemini's session file, codex's rollout and copilot's
- `events.jsonl` each get their own reader, and `chat:read-transcript` routes by agent. That list had
- transcript view (`CHAT_CAPABLE` / `canChat`) is **claude + grok + opencode** since 2026-09: grok's
- `chat_history.jsonl` gets its own reader, and `chat:read-transcript` routes by agent. That list had
++ transcript view (`CHAT_CAPABLE` / `canChat`) is **claude + grok + gemini + codex + copilot +
++ opencode** since 2026-09: grok's `chat_history.jsonl`, gemini's session file, codex's rollout,
++ copilot's `events.jsonl` and opencode's `opencode export` document each get their own reader, and
++ `chat:read-transcript` routes by agent. That list had
to be SPLIT to do it — `CHAT_CAPABLE` carried two facts that coincided while claude was its only
member ("we can render this" and "claude's resolver can locate and parse this file"), and the
second now lives in `CLAUDE_TRANSCRIPT_READABLE` (claude only). Merging them back is a
@@@ -1907,38 -1873,38 +1908,70 @@@
cost before the backgrounding. Full picture,
limits (permission prompt and ESC fire no hook) and the device checklist:
**`docs/antigravity-agent.md`**.
+ **No conversation view, and that is deliberate** (not in `CHAT_CAPABLE`): ⌘M shows the rendered
+ terminal output, and the phone's Chat screen answers `unsupported`. The
+ LOCATION is measured: every hook payload names `transcriptPath`, which is
+ `~/.gemini/antigravity-cli/brain/<conversationId>/.system_generated/logs/transcript_full.jsonl`,
+ keyed by the id `normalizeAntigravity` already records as `sessionId`. The RECORD SHAPES were never
+ captured; the 1.2.12 binary only describes them in prose. Four facts a parser needs are unknown:
+ the `tool_calls` element keys, how a tool result links back to its call, the serialized enum
+ spelling, and whether a line is rewritten when its step's status changes, which decides between
+ claude's paged read and grok's single capped read. A parser built from that prose would be a rule-14
+ wrong guess, so none ships, not even unwired. The capture recipe is §7.1 and §8.1 of the doc, using
+ `scripts/agy-transcript-shape.mjs`, which dumps shapes and never text. When it lands: locate
+ strictly by id (`brain/` holds every conversation on the machine), and have a remote node answer
+ `remoteOnly` → unreadable like gemini.
+- **Codex in the ⌘M chat view** (2026-09-28; the desktop panel, the kanban card modal, the phone's
+ `chat.page`). `core/codex-chat.ts` reads the rollout with codex's own rules, never claude's
+ resolver. It takes USER text from the UI stream only: `event_msg/user_message` (legacy, ≤ 0.146) or
+ an `item_completed` `UserMessage` (paginated, ≥ 0.151). Model-side `role:user` messages also carry
+ injected context (AGENTS.md, `<environment_context>`, image wrappers), so they are never read.
+ Assistant text and tools come from `response_item`, correlated by `call_id`. The UI copies
+ (`agent_message`, `AgentMessage`) and reasoning are skipped. Failed and interrupted turns become
+ `[error] …` / `[turn aborted…]` notes. A tool result drops codex's `… Output:` preamble. The rollout
+ is append-only, so it pages by byte offset like claude. The locator matches a WHOLE-uuid thread id
+ (`CODEX_THREAD_ID_RE`), because a uuid's last group passes `SESSION_ID_RE` and suffix-matches
+ another thread's file. It searches only the node's own account home, and uses the codex tail's hook
+ path only as a checked hint. An SSH node is read on its host (`main/remote-codex-chat-page.ts`,
+ through the same resolvers as its remote meter) or not at all. Because codex announces no session
+ end, a chat send first asks the kernel (`renderer/lib/chatPaneGate.ts`, `isAgentPane`). After a
+ `/quit` the store still reads `done`, and the message would otherwise run in the shell. **Not
+ supported:** images in prompts, reasoning summaries, the composer's model/effort labels (the
+ `/model` picker is measured for claude only), plan/question answer cards (codex never sets
+ `held`), and a closed REMOTE session's transcript. Record rules and fixtures:
+ `src/shared/chat-fixtures/codex/`.
+ - **opencode in the ⌘M chat view** (2026-09-28, opencode 1.18.25 measured) — opencode has NO
+ transcript file (SQLite since 1.18; that database also holds its account tokens and is never
+ opened), so `readChatTranscript` routes `capabilityAgentId(agentId) === 'opencode'` to
+ `core/opencode-chat.ts`, which runs `opencode export <sessionId>` (argv only, no flag an older
+ yargs-strict CLI might refuse) and parses the one JSON document into claude's `ChatMessage` shape:
+ user/assistant text, tool chips (arg by an opencode key order, result = 3 lines / 500 units,
+ `Error: …` on a failed call), `[name] message` for an errored turn, compaction/subtask chips,
+ `at` from `time.created`, `model`/`effort` from the newest assistant's `modelID`/`variant`.
+ Reasoning, `synthetic`/`ignored` text, file/agent parts and step bookkeeping are dropped;
+ unmappable shapes are skipped and counted. **One page, always** (`olderCursor: null`): there are
+ no byte offsets to page by. The page honours the caller's `maxBytes` (the phone asks 256 KB),
+ grows ×4 up to 5 MB like claude's reader when it holds no whole message, and shows a newest
+ message larger than 5 MB TRUNCATED (with a note) rather than as an empty conversation. Refusals: no/unsafe session id runs
+ nothing (a bare `opencode export` opens a picker over the NEWEST sessions — someone else's); an
+ export whose `info.id` is another session is `unreadable`; only `Session not found: <id>` with
+ exit 1 and empty stdout is a clean miss. **Remote (SSH) nodes are refused** (`unreadable`, no
+ export runs) — their sessions are in the host's database and there is no remote leg yet; the
+ panel's copy names both causes an opencode `unreadable` can have. One export costs 1.0–1.7 s and
+ ~320 MB, so `createOpencodeExportGate` runs at most one per session (a caller arriving mid-run
+ gets a FRESH export) and two in total; the panel's hook-driven refreshes are marked
+ `page.background` and spaced ≥ 5 s per session, while an open / ↻ / Retry is immediate (and wakes
+ a sleeping background one). A **change gate** in front of it `stat`s (never opens) opencode's
+ `opencode*.db` + `-wal` in `$XDG_DATA_HOME/opencode` (else `~/.local/share/opencode`, opencode's
+ own xdg-basedir rule) BEFORE exporting, and an unchanged fingerprint answers from a 4-session LRU
+ of parsed exports; no db file found, or `OPENCODE_DB` set, means no caching. The export runs with
+ `cwd: os.tmpdir()` (from a repo cwd opencode writes `<repo>/.git/opencode`; sessions resolve by
+ global id). **It inherits the APP's `process.env`, not the node's shell env**: a user who
+ relocates opencode's data via `XDG_DATA_HOME` / `OPENCODE_*` only in their shell rc gets
+ "Session not found" — an honest miss, not a bug in the reader. Plan/question answer
+ cards stay claude-only (no `body`/`questions` on opencode's `question` tool). Desktop and Server
+ Edition both serve it (core handler); the phone gets it over the relay `chat.page` for free.
+ Fixtures + the exact rules for the iOS port: `src/shared/chat-fixtures/opencode/README.md`.
- **Gemini + codex parity** (2026-08-09) — brought both up to grok's level in the lists above. Unlike
grok, **both CLIs are installed** and gemini **ships its own hook reference**
(`/usr/lib/node_modules/@google/gemini-cli/bundle/docs/hooks/reference.md`), so almost every fact is
diff --cc docs/mobile-chat-view.md
index e4f0fd2e2,c5fbfe969..67ee76f5c
--- a/docs/mobile-chat-view.md
+++ b/docs/mobile-chat-view.md
@@@ -103,7 -103,7 +103,7 @@@ as `hostBridge.chat` in `main/index.ts`
| verb | params | reply | does |
|---|---|---|---|
- | `chat.page` | `{nodeId, before?, maxBytes?}` | `{page: ChatPage}` | Only for agents with a chat view — `canChat(capabilityAgentId(agent))` (claude, grok, gemini, codex, and custom agents whose base harness is one of them; codex is read by its own reader, `src/core/codex-chat.ts`, locally and on an SSH host — fixtures and the record rules in `src/shared/chat-fixtures/codex/`); anything else is refused before any read. `readChatTranscript` with the ⌘M panel's own deps (paged ALWAYS — an absent page is the default 256 KB tail; grok unpaged) + `model`/`effort`, `version: 1`. Session id: the RENDERER's agent-status id first (what ⌘M reads — after a desktop restart a hook-fed id lives only there), then the mirror's, then the node's minted id; the fallbacks apply only when the renderer does not answer within 3 s or knows none. **Remote (SSH-project) nodes are read REMOTE-ONLY** (`remoteOnly`): over the live pty's ControlMaster, else the node's PROJECT's master (an idle tab / any node after a restart has no pty), and never from this machine's disk — a remote node with no reachable master, or a host that did not answer, is `Could not read the transcript.`, not an empty page. The host-side locate is TRI-STATE (`locateRemoteTranscriptRef`, `src/main/remote-transcript-page.ts`): a CLEAN MISS (the host looked and has no such file, or there is no session id to look for) is `found:false`, and only a failure to ask (no master, no resolved home, a failed ssh, a path outside the jail, a failed ranged read) is the error. For REMOTE nodes the desktop ⌘M panel follows the same remote-only rule and the same absent-vs-unreadable split (same deps): its IPC handler decides remoteness from the shell's own records (`isRemoteNode` — live remote pty or `workspaceStore.sshProjectIdForNode`, never a renderer flag) and applies `remoteOnly` to the paged read, the legacy unpaged read, the find-bar index and the presence probe (`unknown`); it shows `unreadable` as "Couldn't read the transcript." (a remote grok node is read on its host too — `core/remote-grok-chat.ts`, whole-file and unpaged, with the same absent-vs-unreadable split; a remote node of an agent with no remote reader — `CHAT_LOCAL_ONLY` — as "not supported yet"). LOCAL nodes on ⌘M are unchanged — the renderer still sends the cwd, so claude's cwd fallback still applies there; the cwd-only-when-remote rule below is the phone path's. The cwd rides ONLY for a remote node with a known id (the host-side locate needs it); locally a known-but-dead id must not fall back to the cwd's newest transcript (another node's), and with no id at all ⇒ `found:false`. `found:false` therefore always means "looked, and there is no transcript". The reply's `page.sessionId` is exactly the id that read used (absent when none was resolved); the phone should PREFER it over the mirror's `sessionId` as the page's thread identity — the mirror lags — every 4 s on SSH, up to ~30 s on relay (`projects.list` off-LAN) — so right after `/clear` or a resume it still names the old session while the page already comes from the new transcript, and merging by byte `key` across the two would splice threads. `sessionId` is present on a `found:false` page too (an id was resolved, its transcript is missing — e.g. a fresh session that has not written yet): a new id on such a page alone is NOT a confirmed thread switch, so the phone must not clear the thread on it. Additive field: `version` stays 1, and an older desktop simply omits it (fall back to the mirror). |
-| `chat.page` | `{nodeId, before?, maxBytes?}` | `{page: ChatPage}` | Only for agents with a chat view — `canChat(capabilityAgentId(agent))` (claude, grok, and custom agents whose base harness is one of them); anything else is refused before any read. `readChatTranscript` with the ⌘M panel's own deps (paged ALWAYS — an absent page is the default 256 KB tail; grok unpaged) + `model`/`effort`, `version: 1`. Session id: the RENDERER's agent-status id first (what ⌘M reads — after a desktop restart a hook-fed id lives only there), then the mirror's, then the node's minted id; the fallbacks apply only when the renderer does not answer within 3 s or knows none. **Remote (SSH-project) nodes are read REMOTE-ONLY** (`remoteOnly`): over the live pty's ControlMaster, else the node's PROJECT's master (an idle tab / any node after a restart has no pty), and never from this machine's disk — a remote node with no reachable master, or a host that did not answer, is `Could not read the transcript.`, not an empty page. The host-side locate is TRI-STATE (`locateRemoteTranscriptRef`, `src/main/remote-transcript-page.ts`): a CLEAN MISS (the host looked and has no such file, or there is no session id to look for) is `found:false`, and only a failure to ask (no master, no resolved home, a failed ssh, a path outside the jail, a failed ranged read) is the error. For REMOTE nodes the desktop ⌘M panel follows the same remote-only rule and the same absent-vs-unreadable split (same deps): its IPC handler decides remoteness from the shell's own records (`isRemoteNode` — live remote pty or `workspaceStore.sshProjectIdForNode`, never a renderer flag) and applies `remoteOnly` to the paged read, the legacy unpaged read, the find-bar index and the presence probe (`unknown`); it shows `unreadable` as "Couldn't read the transcript." (a remote grok node, which has no remote reader, as "not supported yet"). LOCAL nodes on ⌘M are unchanged — the renderer still sends the cwd, so claude's cwd fallback still applies there; the cwd-only-when-remote rule below is the phone path's. The cwd rides ONLY for a remote node with a known id (the host-side locate needs it); locally a known-but-dead id must not fall back to the cwd's newest transcript (another node's), and with no id at all ⇒ `found:false`. `found:false` therefore always means "looked, and there is no transcript". The reply's `page.sessionId` is exactly the id that read used (absent when none was resolved); the phone should PREFER it over the mirror's `sessionId` as the page's thread identity — the mirror lags — every 4 s on SSH, up to ~30 s on relay (`projects.list` off-LAN) — so right after `/clear` or a resume it still names the old session while the page already comes from the new transcript, and merging by byte `key` across the two would splice threads. `sessionId` is present on a `found:false` page too (an id was resolved, its transcript is missing — e.g. a fresh session that has not written yet): a new id on such a page alone is NOT a confirmed thread switch, so the phone must not clear the thread on it. Additive field: `version` stays 1, and an older desktop simply omits it (fall back to the mirror). |
++| `chat.page` | `{nodeId, before?, maxBytes?}` | `{page: ChatPage}` | Only for agents with a chat view — `canChat(capabilityAgentId(agent))` (claude, grok, gemini, codex, copilot, opencode, and custom agents whose base harness is one of them; codex is read by its own reader, `src/core/codex-chat.ts`, locally and on an SSH host — fixtures and the record rules in `src/shared/chat-fixtures/codex/`); anything else is refused before any read. `readChatTranscript` with the ⌘M panel's own deps (paged ALWAYS — an absent page is the default 256 KB tail; grok unpaged) + `model`/`effort`, `version: 1`. Session id: the RENDERER's agent-status id first (what ⌘M reads — after a desktop restart a hook-fed id lives only there), then the mirror's, then the node's minted id; the fallbacks apply only when the renderer does not answer within 3 s or knows none. **Remote (SSH-project) nodes are read REMOTE-ONLY** (`remoteOnly`): over the live pty's ControlMaster, else the node's PROJECT's master (an idle tab / any node after a restart has no pty), and never from this machine's disk — a remote node with no reachable master, or a host that did not answer, is `Could not read the transcript.`, not an empty page. The host-side locate is TRI-STATE (`locateRemoteTranscriptRef`, `src/main/remote-transcript-page.ts`): a CLEAN MISS (the host looked and has no such file, or there is no session id to look for) is `found:false`, and only a failure to ask (no master, no resolved home, a failed ssh, a path outside the jail, a failed ranged read) is the error. For REMOTE nodes the desktop ⌘M panel follows the same remote-only rule and the same absent-vs-unreadable split (same deps): its IPC handler decides remoteness from the shell's own records (`isRemoteNode` — live remote pty or `workspaceStore.sshProjectIdForNode`, never a renderer flag) and applies `remoteOnly` to the paged read, the legacy unpaged read, the find-bar index and the presence probe (`unknown`); it shows `unreadable` as "Couldn't read the transcript." (a remote grok node is read on its host too — `core/remote-grok-chat.ts`, whole-file and unpaged, with the same absent-vs-unreadable split; a remote node of an agent with no remote reader — `CHAT_LOCAL_ONLY` — as "not supported yet"). LOCAL nodes on ⌘M are unchanged — the renderer still sends the cwd, so claude's cwd fallback still applies there; the cwd-only-when-remote rule below is the phone path's. The cwd rides ONLY for a remote node with a known id (the host-side locate needs it); locally a known-but-dead id must not fall back to the cwd's newest transcript (another node's), and with no id at all ⇒ `found:false`. `found:false` therefore always means "looked, and there is no transcript". The reply's `page.sessionId` is exactly the id that read used (absent when none was resolved); the phone should PREFER it over the mirror's `sessionId` as the page's thread identity — the mirror lags — every 4 s on SSH, up to ~30 s on relay (`projects.list` off-LAN) — so right after `/clear` or a resume it still names the old session while the page already comes from the new transcript, and merging by byte `key` across the two would splice threads. `sessionId` is present on a `found:false` page too (an id was resolved, its transcript is missing — e.g. a fresh session that has not written yet): a new id on such a page alone is NOT a confirmed thread switch, so the phone must not clear the thread on it. Additive field: `version` stays 1, and an older desktop simply omits it (fall back to the mirror). |
| `chat.status` | `{nodeId}` | `{status: ChatStatus}` | the renderer's agent-status entry (`state` null = unknown, `held`, hibernated/paused/dropped/sessionEnded) + `structuredAnswers` = the held ticket is in main's structured-ticket ledger (script revision ≥ 5) + the host mirror's `hostRefuses`/`refusal` + `version: 1`. |
| `chat.send` | `{nodeId, text}` | `ChatSendOutcome` = `{result, reason?}` | text capped at 64000 UTF-16 units RAW, then ESC + C0/C1 stripped (`\n`, `\t` kept; `sanitizeChatText`); refused FIRST (`reason` `working`/`dialog`) when the host's mirror says the agent is working / waiting / blocked or holds a question or approval ticket (renderer state is transient after a reload); refused `busy` while another send to the same node is still in flight (held until that send SETTLES, capped at 30 s); then the renderer runs the ⌘M composer's gate at send time (`chatSendRefusal` = `agentProcessInPane` + state ∈ {done, unknown} → its own kind as `reason`) plus "no held request" (`dialog`), then `pty.sendText`. `'sent'` only for `sendText === true`; a paste the pane refused is `refused`/`failed`. |
| `agent.answer` | `{nodeId, pendingId, answer}` | `{ok: boolean}` | `answerHeldPermission` with the node's own I/O (local fs, or the SSH project's ControlMaster — the same `heldPermissionIoFor` the desktop answer path uses): validated against the pending request file, structured-ticket gated, no `setMode auto`. The `pendingId` must belong to THIS node — one of the mirror's approval tickets for it, or the renderer's `held.pendingId` (plans / questions) — else `{ok:false}` with no I/O and no answered event. Success emits the same optimistic "answered" event. |
@@@ -204,7 -204,7 +204,7 @@@ its own, so the agent-status mirror's `
## 4. Screen & interaction (iOS)
- **Entry**: a **Chat | Terminal** switch in the session screen's top bar; default Chat for
-- chat-capable agents (claude, grok), last choice remembered per node. Tapping an Inbox question /
++ chat-capable agents (`CHAT_CAPABLE`), last choice remembered per node. Tapping an Inbox question /
approval opens that session in Chat.
- **Thread**: user messages right-aligned in a neutral bubble; assistant unbubbled full-width. Markdown
via **MarkdownUI** (`gonzalezreal/swift-markdown-ui`, the one new dependency — `AttributedString
diff --cc src/core/transcript-ipc.ts
index 75793226e,09dd06c70..8e216725b
--- a/src/core/transcript-ipc.ts
+++ b/src/core/transcript-ipc.ts
@@@ -12,20 -12,12 +12,21 @@@
import fsp from 'node:fs/promises'
import { IPC } from '../shared/ipc'
import type { ChatTranscriptResult, TranscriptLine, TranscriptPresence } from '../shared/types'
-import { CHAT_PAGE_MAX_BYTES, normalizeChatPage, type ChatTranscriptPage } from '../shared/chat-page'
+import {
+ CHAT_PAGE_MAX_BYTES,
+ GROK_AMBIGUOUS_SESSION_MESSAGE,
+ normalizeChatPage,
+ type ChatTranscriptPage
+} from '../shared/chat-page'
import { platform } from './platform'
-import { chatMessagesFromGrok } from './grok-chat'
+import { parseGrokChat } from './grok-chat'
+import type { RemoteGrokChat } from './remote-grok-chat'
+import { readGeminiChatTranscript } from './gemini-chat'
+import { chatMessagesFromCodex, locateCodexRollout, parseCodexChatWindow } from './codex-chat'
+import { chatMessagesFromCopilot, locateCopilotTranscript, parseCopilotChatWindow } from './copilot-chat'
+ import { readOpencodeChat, type OpencodeExportRun } from './opencode-chat'
-import { capabilityAgentId } from '../shared/agents/config'
import { locateGrok } from './handoff/locate'
+import { capabilityAgentId } from '../shared/agents/config'
import {
parseChatMessages,
parseChatWindow,
@@@ -89,28 -80,9 +90,31 @@@ export interface TranscriptIpcDeps
* (the Server Edition — it runs ON the host) = no node is remote, which is correct there.
*/
isRemoteNode?(nodeId: string): boolean
+ /**
+ * A REMOTE grok node's conversation, read ON the host (`createReadRemoteGrokChat`). `null` = not
+ * a remote session (take the local path); `{ok:false}` = it IS remote and the host could not be
+ * read; `{ok:false, absent:true}` = the host looked and has no such session. Grok's own leg —
+ * claude's `readRemotePage` tails a claude file and must never answer for a grok node.
+ * Electron-only, like the other remote legs.
+ */
+ readRemoteGrok?(q: TranscriptQuery, opts?: { maxBytes?: number }): Promise<RemoteGrokChat | null>
+ /**
+ * 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>
+ /** `opencode export <id>` for an opencode node's chat read. A test seam: absent = the real,
+ * bounded and gated CLI call (`defaultOpencodeExport`) — both shells run it on their own host. */
+ opencodeExport?: OpencodeExportRun
}
export type RemoteTranscriptPage = { ok: true; data: Buffer; start: number } | { ok: false; absent?: true }
@@@ -378,30 -227,30 +382,38 @@@ export async function readChatTranscrip
// Routed by agent BEFORE anything claude-shaped runs. `resolveTranscript` below falls back to
// the newest claude transcript for the cwd when its sessionId leg misses, and a grok id always
// misses — so reaching that fallback with a grok node would answer with a stranger's
- // conversation. The remote leg is claude-only too (its reader tails claude's file), so a grok
- // node is served locally or not at all rather than being handed the wrong host's claude log.
- if (agentId === 'grok') {
- // Grok is read locally only — a remote grok node's history is on the host.
- if (remoteOnly) return page ? unreadablePage() : { messages: [], found: false }
- const gp = sessionId ? await locateGrok(sessionId) : undefined
- // Grok does NOT page: its history is small and its reader has no byte-offset keys, so a
- // paged request gets the whole (capped) read with `olderCursor: null` — "nothing older to
- // fetch" — and no carried results. Keys are absent; the panel falls back to its own.
- const paging = page ? { olderCursor: null, unmatchedResults: [] } : {}
- if (!gp) return { messages: [], found: false, ...paging }
- const buf = await readCappedTail(gp)
- return buf === undefined
- ? { messages: [], found: false, ...paging }
- : { messages: chatMessagesFromGrok(buf), found: true, ...paging }
+ // conversation. Resolved through the base harness, so a custom agent built on grok (which the
+ // panel and the phone admit via `canChat`) is routed here too instead of into that fallback.
+ if (agentId !== undefined && capabilityAgentId(agentId) === 'grok') {
+ return readGrokChat({ sessionId, cwd, accountId, nodeId, ...(remoteOnly ? { remoteOnly } : {}) }, page, deps)
+ }
+ // Gemini, routed through the base harness so a custom agent built on it (which the relay serves)
+ // reads gemini's file too. Its own locator, keyed strictly on the session id in the file header —
+ // never claude's resolver, never a cwd — and local-only (`CHAT_LOCAL_ONLY`).
+ if (agentId && capabilityAgentId(agentId) === 'gemini') return readGeminiChatTranscript({ sessionId, remoteOnly }, page)
+ // 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 }
}
- // opencode has no transcript file — its sessions live in a database read through
+ // Copilot, by its base harness (a custom agent built on it reads the same journal). Before
+ // anything claude-shaped, for the same reason as grok and codex. Local-only (`CHAT_LOCAL_ONLY`).
+ if (agentId && capabilityAgentId(agentId) === 'copilot') return readCopilotChat(sessionId, remoteOnly, page)
++ // Opencode has no transcript file — its sessions live in a database read through
+ // `opencode export <id>` — so it must never reach claude's resolver below (whose cwd fallback
+ // would answer with a stranger's session). Routed through the base harness, so a custom agent
+ // built on opencode reads as opencode. Local only: a remote node is refused inside, before
+ // anything runs. See core/opencode-chat.ts.
+ if (agentId && capabilityAgentId(agentId) === 'opencode') {
+ return readOpencodeChat({ sessionId, remoteOnly }, page, deps.opencodeExport)
+ }
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
diff --cc src/main/remote/host-chat.test.ts
index b4fecf476,add304ee5..89d298040
--- a/src/main/remote/host-chat.test.ts
+++ b/src/main/remote/host-chat.test.ts
@@@ -80,16 -81,38 +81,49 @@@ describe('host-chat page', () =>
setCustomAgentBaseResolver(null)
}
})
+ it('serves gemini, handing its OWN agent id to the reader (which routes it off claude\'s resolver)', async () => {
+ const d = deps({ lookupNode: () => ({ agentId: 'gemini', sessionId: 'sid-1' }) })
+ expect(await createHostChat(d).page('n1', {})).toMatchObject({ version: 1 })
+ expect(d.readTranscript).toHaveBeenCalledWith(expect.objectContaining({ agentId: 'gemini', sessionId: 'sid-1' }), {})
+ })
+ it('serves a codex node, passing its own agent id so core routes it to the codex reader', async () => {
+ const d = deps({ lookupNode: () => ({ cwd: '/srv/app', agentId: 'codex', sessionId: 'sid-1', remote: true }) })
+ expect(await createHostChat(d).page('n1', {})).toMatchObject({ version: 1 })
+ expect(d.readTranscript).toHaveBeenCalledWith(expect.objectContaining({ agentId: 'codex', remoteOnly: true }), {})
+ })
+ it('serves an opencode node through the REAL reader: its own export locally, refused remote', async () => {
+ // The phone gets opencode for free once the desktop parses it: `page` gates on canChat, and the
+ // real `readChatTranscript` routes opencode to `opencode export <id>` (core/opencode-chat.ts).
+ const SID = 'ses_0a1b2c3d4ffeSynthetic000001'
+ const stdout = JSON.stringify({
+ info: { id: SID },
+ messages: [{ info: { id: 'msg_1', sessionID: SID, role: 'user', time: { created: 1 } }, parts: [{ type: 'text', text: 'hi from opencode' }] }]
+ })
+ const opencodeExport = vi.fn(async () => ({ ok: true as const, stdout }))
+ const real = (q: ChatReadQuery, rawPage: unknown) => readChatTranscript(q, rawPage, { opencodeExport })
+ const local = deps({
+ lookupNode: () => ({ cwd: '/srv/app', agentId: 'opencode', sessionId: SID }),
+ readTranscript: vi.fn(real),
+ renderer: { ...deps().renderer, session: vi.fn(async () => ({ sessionId: SID })) }
+ })
+ expect(await createHostChat(local).page('n1', {})).toMatchObject({
+ version: 1,
+ sessionId: SID,
+ found: true,
+ olderCursor: null,
+ messages: [{ role: 'user', parts: [{ kind: 'text', text: 'hi from opencode' }] }]
+ })
- expect(opencodeExport).toHaveBeenCalledWith(SID)
++ // A relay page is a user-driven read, never a background refresh (the export gate spaces those).
++ expect(opencodeExport).toHaveBeenCalledWith(SID, { background: false })
+ opencodeExport.mockClear()
+ const remote = deps({
+ lookupNode: () => ({ cwd: '/srv/app', agentId: 'opencode', sessionId: SID, remote: true }),
+ readTranscript: vi.fn(real),
+ renderer: { ...deps().renderer, session: vi.fn(async () => ({ sessionId: SID })) }
+ })
+ await expect(createHostChat(remote).page('n1', {})).rejects.toThrow('Could not read the transcript.')
+ expect(opencodeExport).not.toHaveBeenCalled()
+ })
it('an absent page is the default paged tail, not the legacy read', async () => {
const d = deps()
await createHostChat(d).page('n1', undefined)
diff --cc src/renderer/nodes/ChatPanel.tsx
index b8a255936,2f5e243a8..152e92931
--- a/src/renderer/nodes/ChatPanel.tsx
+++ b/src/renderer/nodes/ChatPanel.tsx
@@@ -24,7 -22,7 +24,7 @@@ import { GROK_AMBIGUOUS_SESSION_MESSAGE
import { Spinner } from '../components/Spinner'
import { CHAT_LIVE_RELOAD_MIN_MS, CHAT_OPTIMISTIC_WORKING_MS, chatActivity, planLiveReload } from '../lib/chatLive'
import { sentCommand } from '@shared/chat-command'
- import { chatReadsLocalOnly } from '@shared/agents/config'
-import { capabilityAgentId } from '@shared/agents/config'
++import { capabilityAgentId, chatReadsLocalOnly } from '@shared/agents/config'
import { ChatLoadingStatus } from './ChatPanelFallback'
import { answerCardState, answerRebindPending, rebindRetryDelay, type BoundAnswerCard } from '../lib/chatAnswer'
import { AnswerControlsUpdating, PlanAnswerControls, QuestionAnswerControls } from './ChatAnswerControls'
@@@ -87,19 -85,28 +87,30 @@@ interface ChatPanelProps
* initial `[]` because nothing caught the rejection, and a failed resolution was indistinguishable
* from a session nobody has spoken to. They need different words — and two of them are retryable.
*/
- type LoadState = 'loading' | 'ok' | 'missing' | 'unsupported' | 'remoteUnsupported' | 'ambiguous' | 'error'
-type LoadState = 'loading' | 'ok' | 'missing' | 'unsupported' | 'remoteUnsupported' | 'exportError' | 'error'
++type LoadState = 'loading' | 'ok' | 'missing' | 'unsupported' | 'remoteUnsupported' | 'ambiguous' | 'exportError' | 'error'
/**
- * An `unreadable` read of a GROK node can only be the remote case: core's grok leg is local-only
- * and answers a remote grok node (`remoteOnly`) with `unreadable` before touching anything, while
- * its local reader never sets the flag. So the agent alone names it — no renderer-side remoteness
- * guess, and no new field on the wire (the phone contract keeps `unreadable`). `=== 'grok'`
- * exactly, mirroring core's routing (`readChatTranscript` routes only the builtin id to grok's
- * reader). Retry cannot heal it, so it must not read as a transient failure.
+ * An `unreadable` read of a LOCAL-ONLY reader's node (`CHAT_LOCAL_ONLY` — agents with no remote
+ * leg) can only be the remote case: core's leg for those agents answers a remote node (`remoteOnly`)
+ * with `unreadable` before touching anything, while their local readers never set the flag. So the
+ * agent alone names it — no renderer-side remoteness guess, and no new field on the wire (the phone
+ * contract keeps `unreadable`). Retry cannot heal it, so it must not read as a transient failure.
+ * Grok is NOT in that list: its remote node is read on the host (`core/remote-grok-chat.ts`), so a
+ * grok `unreadable` is a real, retryable failure.
*/
-const remoteGrokUnreadable = (agentId: string | undefined): boolean => agentId === 'grok'
+const remoteReaderUnsupported = (agentId: string | undefined): boolean => !!agentId && chatReadsLocalOnly(agentId)
+ /**
+ * An `unreadable` read of an OPENCODE node has two causes and nothing on the wire tells them apart:
+ * a local `opencode export` that failed (Retry heals it) and a remote node core refuses before
+ * running anything (it never heals). So its copy names both instead of guessing — and never blames
+ * an unreachable host for a local failure. Through the base harness, mirroring core's routing
+ * (`readChatTranscript` routes `capabilityAgentId(...) === 'opencode'` to `opencode-chat.ts`).
++ * That ambiguity is why opencode is NOT in `CHAT_LOCAL_ONLY` even though it has no remote leg.
+ */
+ const opencodeUnreadable = (agentId: string | undefined): boolean =>
+ !!agentId && capabilityAgentId(agentId) === 'opencode'
+
const isUnsupported = (e: unknown): boolean =>
!!e && typeof e === 'object' && (e as { code?: string }).code === E_UNSUPPORTED
@@@ -120,14 -126,11 +131,18 @@@ const EMPTY_TEXT: Record<LoadState, { t
title: "Transcripts can't be read on this surface.",
detail: 'Open this session on the desktop app to read its conversation.'
},
- remoteUnsupported: { title: "Reading a remote Grok session's transcript isn't supported yet." },
+ // `{agent}` is the node's own agent label (`agentLabel` below) — the case spans several agents.
+ remoteUnsupported: { title: "Reading a remote {agent} session's transcript isn't supported yet." },
+ // A remote grok id that names two sessions on the host: a fixed fact, like `unsupported` — so,
+ // like it, no Retry (waiting cannot change which file is this node's).
+ ambiguous: {
+ title: GROK_AMBIGUOUS_SESSION_MESSAGE,
+ detail: 'nodeterm will not guess which one belongs to this node.'
+ },
+ exportError: {
+ title: "Couldn't read this opencode session.",
+ detail: "opencode export failed on this machine — Retry once it works. A session on a remote host can't be read here yet."
+ },
error: {
title: "Couldn't read the transcript.",
detail: "The agent's host may not be reachable — Retry once it is."
@@@ -350,7 -356,15 +368,15 @@@ export function ChatPanel(
setThread(emptyThread(identity))
// A read that FAILED (the host did not answer, a remote node with no reachable master)
// is not "no transcript": it gets the error copy, and ↻ is the way out.
- setLoadState(!res.unreadable ? 'missing' : remoteReaderUnsupported(agentId) ? 'remoteUnsupported' : 'error')
+ setLoadState(
+ !res.unreadable
+ ? 'missing'
- : remoteGrokUnreadable(agentId)
++ : remoteReaderUnsupported(agentId)
+ ? 'remoteUnsupported'
+ : opencodeUnreadable(agentId)
+ ? 'exportError'
+ : 'error'
+ )
setHeldRead({ identity, pendingId: heldAtStart })
settleHeldReload(heldAtStart)
return
diff --cc src/shared/agents/config.ts
index 4082dd8a0,b8cdad729..0ea95f66a
--- a/src/shared/agents/config.ts
+++ b/src/shared/agents/config.ts
@@@ -297,21 -294,9 +297,25 @@@ export const USAGE_CAPABLE = ['claude'
// conversation in its find bar and rehydrate its meter from it. That exact bug already happened once
// with codex and gemini; transcriptGates.ts documents it.
//
+// gemini joined in 2026-09 with its own reader (`core/gemini-chat.ts`): its session file is an upsert
+// log, not claude's shape, and it is located strictly by the session id in the file's header.
+// codex joined 2026-09-28 with its own reader (core/codex-chat.ts: the rollout's UI stream for what
+// the user typed, the model stream for answers and tools), local and over SSH.
+// copilot joined 2026-09 with its own leaf, `core/copilot-chat.ts`: `<COPILOT_HOME>/session-state/
+// <id>/events.jsonl`, located strictly by session id and routed there before anything claude-shaped
+// (`readChatTranscript`). Like the others it is NOT in CLAUDE_TRANSCRIPT_READABLE below.
- export const CHAT_CAPABLE = ['claude', 'grok', 'gemini', 'codex', 'copilot'] as const
+ // opencode joined 2026-09-28: it has no transcript file at all (SQLite since 1.18), so its chat is
+ // read through `opencode export <id>` (core/opencode-chat.ts) and it stays out of the list below.
-export const CHAT_CAPABLE = ['claude', 'grok', 'opencode'] as const
++export const CHAT_CAPABLE = ['claude', 'grok', 'gemini', 'codex', 'copilot', 'opencode'] as const
+// CHAT_CAPABLE agents whose reader has NO remote leg: a remote (SSH) node's session lives on its
+// host, so core answers `unreadable` before touching anything — and the local reader never sets that
+// flag (copilot maps a failed local read to not-found for exactly this reason). So an unreadable read
+// of one of these can only mean "remote, unsupported", and the ⌘M panel names it from the agent
+// alone rather than offering a Retry that can never succeed. grok and codex are NOT here: their
+// remote nodes are read on the host (`core/remote-grok-chat.ts`, `main/remote-codex-chat-page.ts`).
++// opencode has no remote leg either but is NOT here: its `unreadable` also means a failed LOCAL
++// `opencode export`, which Retry heals — the panel gives it its own copy (`exportError`) instead.
+export const CHAT_LOCAL_ONLY = ['gemini', 'copilot'] as const
// Agents whose transcript CLAUDE's own resolver can locate and parse — the gate for everything that
// goes through `resolveTranscript` (the find bar's index, the meter's mount-time rehydration).
//
diff --cc src/shared/chat-fixtures/README.md
index 89caeb4d0,69de81d91..f78f201d9
--- a/src/shared/chat-fixtures/README.md
+++ b/src/shared/chat-fixtures/README.md
@@@ -158,113 -158,10 +158,123 @@@ Most inputs are a few KB. Three inputs
construction) and `huge-last-line` (~1.1 MB). Their filler is deterministic lorem ipsum, and the
base64 image is generated by a seeded generator.
+## Other agents
+
+Each agent with its own reader keeps its fixtures in a subdirectory with its own README, generated
+by its own test; the pager and step format are the ones above.
+
+- `codex/` — codex rollouts (`src/core/codex-chat.ts`, `src/core/codex-chat-fixtures.test.ts`).
+- `gemini/` — gemini session files (`src/core/gemini-chat.ts`), one capped page; see its README.
+- `grok/` — grok `chat_history.jsonl` (`src/core/grok-chat.ts`), one capped page; see its README.
++- `opencode/` — synthetic `opencode export` documents (`src/core/opencode-chat.ts`), one page;
++ see `opencode/README.md` and the "opencode" section below.
+- `copilot/` — copilot session journals (`src/core/copilot-chat.ts`); its rules are the "Copilot"
+ section below.
+
+## Copilot (`copilot/`)
+
+The same contract for GitHub Copilot CLI's reader (`src/core/copilot-chat.ts`). Its session journal
+is `<COPILOT_HOME>/session-state/<sessionId>/events.jsonl` (`COPILOT_HOME` defaults to
+`~/.copilot`; the snap package writes under `~/snap/copilot-cli/common/.copilot`), one session
+event per line in the envelope `{type, data, [agentId], id, timestamp, parentId}`. The record
+shapes were **measured** on copilot 1.0.88 (a real CLI run in BYOK mode against a local fake model,
+so every byte of content was synthetic) and cross-checked against the CLI's own
+`schemas/session-events.schema.json`. The inputs here are synthetic too.
+
+```sh
+UPDATE_CHAT_FIXTURES=1 npx vitest run src/core/copilot-chat-fixtures.test.ts
+```
+
+| path | what it is |
+|---|---|
+| `copilot/inputs/<name>.jsonl` | A synthetic copilot session journal. |
+| `copilot/expected/<name>.pages.json` | The page sequence, in exactly the format of the claude set above. |
+
+**The pager and the window rules are the claude ones, byte for byte** (256 KiB tail, 512 KiB older
+pages, ×4 growth to 5 MiB, one lookbehind byte, `olderCursor`, `noCompleteLine`): the journal is
+append-only JSONL (compaction APPENDS `session.compaction_*` events; measured), so core reuses
+`parseChatWindow` and `parseGrowingWindow` with copilot's record parser. `key` is the line's
+absolute byte offset, a tool part's `id` is the call id, both only on a paged read.
+
+### Record rules (the Swift port must replicate this exactly)
+
+`parseCopilotRecords`, applied to each complete line in order:
+
+1. A blank line is ignored. A line that is not JSON, not a JSON object, has no string `type` or no
+ object `data` is skipped (and counted in the reader's diagnostic `skipped`, which is never on the
+ wire).
+2. **Sub-agent events are dropped**, by the CLI's own test: a non-empty string `agentId` on the
+ envelope, OR a non-empty string `data.agentId`, OR a non-empty string `data.parentToolCallId`.
+ A sub-agent's turns belong to the `task` call whose result the main thread already shows.
+3. `at` = `Date.parse(timestamp)` in epoch ms when the envelope's `timestamp` is a parseable
+ non-empty string, else absent.
+4. `user.message`: `data.content` must be a string (else skipped). It becomes
+ `{role:"user", parts:[{kind:"text", text: content}]}` (verbatim, untrimmed) only when
+ `content.trim()` is non-empty AND the source is one copilot's own timeline shows: `data.source`
+ absent, `null`, `"user"`, or a string starting with `command-`, `schedule-` or `autopilot-`. Any
+ other source (`skill-*` injections, `agent-*` inter-agent prompts, a non-string) is hidden.
+ `transformedContent` (the model-facing text with injected datetime/instructions) and
+ `attachments` are never read.
+5. `assistant.message`: `data.content` (absent or `null` = `""`) must be a string and
+ `data.toolRequests` (absent or `null` = `[]`) an array, else the record is skipped. On a paged
+ read, `model` is set to `data.model` when it is a string of 1..100 UTF-16 units and CLEARED
+ otherwise, for every main-thread `assistant.message` (so the newest one decides, even one that
+ yields no parts; never carried forward). Parts, in order: a text part when `content.trim()` is
+ non-empty (text verbatim); then per request, which must be an object with non-empty string
+ `name` and `toolCallId` (else that one request is skipped): `{kind:"tool", name, arg}`, plus
+ `id: toolCallId` when paged. Pushed as an assistant message only when it has parts.
+ `reasoningText`, `reasoningOpaque`, `encryptedContent` and the `assistant.reasoning` event are
+ never read.
+6. **The `arg` rule:** `arguments` a string (a `custom` tool such as `apply_patch`) → its first 200
+ UTF-16 units. A plain object → the first of `command`, `path`, `file_path`, `pattern`, `url`,
+ `query`, `description`, `prompt`, `skill`, `question`, `intent` whose value is a NON-EMPTY
+ STRING (a non-string under an earlier key does not stop the search), first 200 units, untrimmed.
+ Anything else → `""`.
+7. `tool.user_requested` (a tool the USER ran, `!cmd` shell mode being a `bash` call): non-empty
+ string `toolName` and `toolCallId` required (else skipped). With `toolName === "bash"` and a
+ string `arguments.command`: `{kind:"tool", name:"!", arg: command.trim().slice(0, 200)}` — the
+ claude `!` line's shape. Otherwise `{kind:"tool", name: toolName, arg: <arg rule>}`. `id` when
+ paged. Pushed as its own assistant message. (Schema-derived: `-p` mode cannot produce it, so
+ this shape was not captured from a live run.)
+8. `tool.execution_complete`: non-empty string `toolCallId` required (else skipped). With
+ `error` = `data.error.message` if a string else `""`, and `content` = `data.result.content` if
+ a string else `""`: the text is `"Error: " + error` when `data.success !== true` and `error` is
+ non-empty, else `content`. `result` = that text split on `\n`, the first three lines joined by a
+ space, the first 500 UTF-16 units (claude's `summarizeResult`). An empty result sets nothing.
+ Otherwise it is set on the tool part registered under that call id (a later completion
+ overwrites; a later registration of the same id replaces the earlier part as the target); with
+ no such part, a paged read carries it in `unmatchedResults` (JS `Map` order: first insertion
+ wins the position, a later one the value).
+9. `session.error` / `session.warning` / `session.info`: `data.message` must be a string (else
+ skipped); pushed as an assistant text part `"Error: "` / `"Warning: "` / `"Info: "` + message —
+ the same three notices copilot's own chat adapter (ACP) emits.
+10. Every other type yields nothing and is not counted: `session.start`/`resume`/`shutdown`,
+ `system.message` (the ~44 KB system prompt), turn boundaries, permissions, hooks,
+ `abort`, compaction, model/mode/plan changes, `system.notification`, `skill.invoked`,
+ `subagent.*`, `session.binary_asset`, `tool.execution_start`, and any type a newer CLI adds.
+11. `effort` is never set: copilot records no per-response effort.
+
+| fixture | pins |
+|---|---|
+| `plain-turns` | Prompts and markdown answers, non-ASCII, two assistant messages in one turn, a resume and a model change in between (the second model wins); the system prompt and all bookkeeping yield nothing. |
+| `tools` | Nine tool calls: the arg rule per tool (`bash`→command, `view`/`create`/`edit`→path, `grep`→pattern, `sql`→query before description, `apply_patch`'s raw string, `read_bash`→`""`, a 200-unit cap), a denied call's `Error:` result, a >3-line result, a 500-unit cap, an empty result (no key), and a failure with no error message falling back to its content. |
+| `tools-cross-page` | A call in the older page, its completion in the tail: the tail carries it in `unmatchedResults`, the older page has the tool part with its `id` and no `result`. |
+| `subagent` | A `task` call with a sub-agent's full event run (envelope `agentId`, its own prompt, messages, tool calls and model): only the `task` part and its result reach the thread. |
+| `notices` | `session.error` / `session.warning` / `session.info` rendered; `abort`, compaction, notifications, skill bodies, context/plan/mode changes, hooks, binary assets and an unknown type rendered as nothing. |
+| `hidden-prompts` | Which `source` values show a prompt, and that blank prompts, the empty autopilot continuation and attachments add nothing. |
+| `reasoning` | No reasoning, on the event or on a message; a reasoning-only message and a whitespace-only message yield nothing. |
+| `model` | The newest main-thread message's model; a newer sub-agent message does not count. |
+| `model-absent` | The newest main-thread message states no model: the key is absent (not carried forward). |
+| `model-utf16` | 50 × U+1F9EA (exactly 100 UTF-16 units) is kept. |
+| `model-over-cap` | 101 units: absent. |
+| `user-requested` | A user `!` bash command (`name:"!"`, trimmed arg) and a user-requested `view`, each with its result. |
+| `malformed` | Thirteen unreadable or ill-shaped lines, plus a good message holding two bad tool requests, between good ones: the good ones render, and a bad tool request costs only itself. |
+| `huge-last-line` | A tool result carrying an image for the model (~300 KB) is the last line: the tail grows past 256 KiB and the result still attaches. |
++
+ ## opencode
+
+ `opencode/` holds the fixtures for the opencode reader (`src/core/opencode-chat.ts`): synthetic
+ `opencode export` documents and the parse + page the desktop serves for each. opencode has no
+ transcript file (SQLite since 1.18), so a read is ONE page (`olderCursor: null`). Its rules and
+ layout are in `opencode/README.md`; regenerate with
+ `UPDATE_CHAT_FIXTURES=1 npx vitest run src/core/opencode-chat.fixtures.test.ts`.
diff --cc src/shared/chat-page.ts
index 66e210db3,e4185ceac..79e986a40
--- a/src/shared/chat-page.ts
+++ b/src/shared/chat-page.ts
@@@ -51,20 -57,6 +57,21 @@@ export function normalizeChatPage(page
if (typeof maxBytes === 'number' && Number.isFinite(maxBytes)) {
m = Math.min(CHAT_PAGE_MAX_BYTES, Math.max(CHAT_PAGE_MIN_BYTES, Math.floor(maxBytes)))
}
- return { before: b, maxBytes: m }
+ const { background } = page as { background?: unknown }
+ return background === true ? { before: b, maxBytes: m, background: true } : { before: b, maxBytes: m }
}
+
+/**
+ * What a grok chat read says when its session id names MORE than one session on an SSH host
+ * (`core/remote-grok-chat.ts` refuses to pick one). It travels as a REJECTION's message — the
+ * result shape is a locked wire format, and over Electron IPC a rejection keeps only its message
+ * (wrapped in Electron's own prefix, the `code` dropped) — so it is matched by substring. Retry can
+ * never fix it, which is why it is not `unreadable`.
+ */
+export const GROK_AMBIGUOUS_SESSION_MESSAGE = 'This session id matches more than one grok session on the host.'
+
+/** Is `e` the rejection carrying `GROK_AMBIGUOUS_SESSION_MESSAGE` (Electron-wrapped or not)? */
+export function isGrokAmbiguousSessionError(e: unknown): boolean {
+ const m = e && typeof e === 'object' ? (e as { message?: unknown }).message : undefined
+ return typeof m === 'string' && m.includes(GROK_AMBIGUOUS_SESSION_MESSAGE)
+}