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
docs(agents): correct four false claims, and retire the gemini "resume replay" story
enes890ebb4a23f7
diff --git a/docs/gemini-agent.md b/docs/gemini-agent.mdindex 0ff7f25a9..c2daa7aba 100644--- a/docs/gemini-agent.md+++ b/docs/gemini-agent.md@@ -163,13 +163,27 @@ claude's `~/.claude/projects`, a managed account's `{userData}/claude-accounts/<predicate exists precisely so a forgery cannot reach `~/.ssh/id_rsa`, and a home-wide allowancehands that straight back.-The transcript is **event-sourced**, which shapes both readers below: a line is an append, and a-**resume replays the prior history into a single `{"$set":{"messages":[…]}}` line**. Both readers-therefore scan **backwards** for the newest line that parses to something they accept+The transcript is **event-sourced**: a line is an append, and metadata changes arrive as+`{"$set":{…}}` records that a reader folds over the ones before them. One of those records is+`{"$set":{"messages":[…]}}` — an in-session **history sync**: when gemini has to rewrite the+conversation it holds in memory (a tool result patched onto an earlier call, say), it writes the whole+array in one record, and its own reader CLEARS what it had and takes that array as the history+(`chunk-TYAF55F7.js:285852-285857` writes it, `:285303-285335` reads it). It is routine and has+nothing to do with resume — the never-resumed capture has one at line 2.++Both readers therefore scan **backwards** for the newest line that parses to something they accept(`latestJsonLineWhere` in `core/gemini-session.ts`, shared with `codex-session.ts`), with the needleas a cheap pre-filter only — a line can mention a key deep inside without carrying it at the toplevel, and gemini's `$set` line is exactly that case.+**What a resume actually does** (measured in the same bundle, 0.54.4): it **appends to the same+file** and writes exactly one record, `{"$set":{"sessionId":…}}` (`:285453`). Nothing is replayed.+The one branch that does re-write history is the legacy `.json` → `.jsonl` **migration**+(`:285430-285450`), and even that appends each message as its own ordinary line, not as a+`$set.messages` array. This matters because an earlier version of this document — and of+`pickGeminiTitle`'s docblock — described the `$set.messages` walk as *the resume mechanism*; it is+not. See §6.+---## 4. The context meter: `tokens.input`, and gemini's own `tokenLimit()`@@ -310,15 +324,22 @@ never be mistaken for the session's name, and takes the **last** call within a lseveral; the newest is the name). Ordering across lines is right for free: the backward scan takes thenewest matching line.-**Two places, because of resume.** A resumed session replays its history into one-`{"$set":{"messages":[…]}}` line, so a title set *before* the resume is nested in that line's messages-rather than appearing as a top-level tool call — and the first, top-level-only version of this reader-answered `null` for the whole resumed session, which is precisely the case the read leg exists for (a-resume is when the OSC title is gone). So `$set.messages` is searched as a fallback, newest message-first. **Provenance, stated honestly:** `$set.messages` being an array of ordinary message objects is-measured (fixture line 2) and a message carrying `toolCalls[].args.title` is measured (line 22); the-**combination** is composed from the two, not captured from a real resume. If gemini nests differently-this degrades to `null` — the node keeps its own title — never to a wrong name.+**Two places, and NOT because of resume.** The reader also walks `$set.messages`, and the reason+recorded here originally was wrong: it said a resume replays the prior history into that record, so a+pre-resume title would only be found nested inside it. Measured in gemini 0.54.4's bundle, a resume+**appends to the same file** and writes only `{"$set":{"sessionId":…}}` (`:285453`) — §3. A title set+before the resume is therefore still sitting in the file as a top-level `update_topic` line, and the+backward scan finds it with no fallback at all.++What `$set.messages` really is: an **in-session history sync** gemini writes whenever it rewrites the+conversation it holds in memory (`:285852-285857`), which its own reader treats as replacing the+history (`:285303-285335`). Since that record can be the newest thing in the file and does carry+messages, a title inside it is a title the session currently believes in — so the walk is kept as+**defence**, not as the resume path. It costs nothing (the needle pre-filter means non-`$set` lines+never reach it) and it cannot invent a name: it matches only `update_topic`, and a top-level line+after the sync still wins by the backward scan. Provenance is now plain — both shapes it walks are+measured in the capture (`$set.messages` at fixture line 2, `toolCalls[].args.title` at line 5); what+was composed was the *story*, not the shapes.The read is a **bounded tail** (`readSmallTail(p, TITLE_TAIL_BYTES)`, the same cap claude's title readuses) of the path **the context tail already tracks**. Nothing scans. That path authority is created@@ -410,22 +431,37 @@ one stray keystroke.`modeSupported` is false and the derived copy says so — but the dropdown still offers two entriesthat do the same thing on gemini. Only a gemini-side "approve non-edit tools" value couldseparate them.-3. **The resumed-transcript title path is composed, not captured** (§6). Fail-safe by construction:- wrong ⇒ `null`, never a wrong name. Closing it needs one real resumed transcript.+3. **CLOSED, in the opposite direction** — the `$set.messages` walk was documented as *the resume+ mechanism* and listed here as unverified. Measured in gemini 0.54.4's bundle: a resume **appends to+ the same file** and writes only `{"$set":{"sessionId":…}}` (`chunk-TYAF55F7.js:285453`), so nothing+ is replayed and a pre-resume title is still a top-level `update_topic` line. `$set.messages` is a+ routine in-session history sync (`:285852-285857`), which is why the never-resumed capture has one+ at line 2. The CODE is unchanged — the walk is harmless, free and defensive — but the story is+ fixed in §3, §6 and `pickGeminiTitle`'s docblock, and the checklist item that told a tester to+ capture "the resumed transcript's `$set` shape" is gone: there is no such shape to capture.+4. **`gemini --resume <id>` is FATAL when the id does not resolve** — measured here: exit **42**,+ `Error resuming session: Invalid session identifier "…"` (and, from a directory with no chats at+ all, `No previous sessions found for this project`), so a cold-restore relaunch whose transcript+ has been deleted, or whose node runs in a different cwd than the one gemini indexed, dies instead+ of degrading to a bare `gemini`. Not fixed here (the resume command is shared with claude/codex and+ the fallback belongs in the restore path, not in a docs pass).4. **A remote (SSH) gemini node has no meter and no title.** The tails deliberately never track aremote node's transcript — metering the local disk would report the wrong machine — and`geminiPathFor` then answers `undefined`, which reads as "no name". Honest, but a real asymmetry:claude's leg handles remote via `setRemoteTranscriptReader` and a remote-jailed path.-5. **The search button's tooltip still keys on the meter.** `TerminalNode.tsx:3234` reads- `showUsage ? 'Search terminal + conversation' : 'Search this terminal'`, so a gemini/codex node- promises a conversation search whose transcript leg is now off. One word (`claudeTranscript`) fixes- it; recorded here rather than fixed in a docs commit.+5. **FIXED** — the search button's tooltip keyed on `showUsage`, so a gemini/codex node offered+ "Search terminal + conversation" while its transcript leg was gated off. It now keys on+ `claudeTranscript`, and the guard below covers the label too.6. **Nothing tests the call sites of `readsClaudeTranscript`, behaviourally.** No test in this reporenders `TerminalNode` or `Canvas`, so the gates are pinned by a source-text guard- (`src/renderer/nodes/title-gate.test.ts`, in the style of `no-electron.test.ts`) — three of its six- mutations are caught by identifier matching, not behaviour. Its `toContain` on a 6000-line file also- dumps unrelated source as the failure diff, and its "Canvas.tsx must never mention `canReadTitle`"- clause would false-positive on a future legitimate read there.+ (`src/renderer/nodes/title-gate.test.ts`, in the style of `no-electron.test.ts`), which now covers+ the CLAUDE-TRANSCRIPT gates as well as the two title gates — `context.ensure`, the find bar's+ `searchTranscript`, the tooltip, and the inverse mistake of narrowing the meter itself. Each was+ verified by mutation. The residual weakness is the technique's: it matches identifiers, not+ behaviour, so a rename that keeps the words satisfies it. The transcript assertions are scoped to+ the matching LINE (so a failure names the site instead of dumping 6000 lines as its diff); the+ older title assertions still `toContain` over the whole file, and the "Canvas.tsx must never+ mention `canReadTitle`" clause would still false-positive on a future legitimate read there.7. **`codexHome()` returns `$CODEX_HOME` unresolved**, so a `~/…` or relative value still misses thejail — pre-existing, and identical to `codex-usage.ts`'s own behaviour. It fails **closed** (themeter silently never fills), which is the quieter and therefore worse failure.@@ -476,9 +512,10 @@ Context meterTitle10. Let gemini name the conversation (it calls update_topic on its own), then check the node titleadopts it — and that a HAND rename stops the poll overwriting it (titleAuto=false).-11. RESUME that session (`gemini --resume <id>`) and check the title survives. This is §8.3: if the- title goes blank until gemini renames again, capture the resumed transcript's first line and- fix pickGeminiTitle's $set shape against it.+11. RESUME that session (`gemini --resume <id>`) and check the title survives. It should, with no+ $set walk involved: a resume appends to the SAME file (§3, §8.3), so the pre-resume top-level+ `update_topic` line is still the newest one. (The item that used to sit here — "capture the+ resumed transcript's $set shape" — is gone: measured, there is no such shape.)12. Confirm there is no rename affordance offered on a gemini node.Modes + restart@@ -487,8 +524,9 @@ Modes + restartstarted with the setting untouched must PROMPT before an edit, not auto-approve it),acceptEdits ⇒ auto_edit, plan ⇒ plan, bypassPermissions ⇒ yolo. Check a session really STARTS init, not just that the flag parses.-14. On a machine with NO claude installed, does an `auto` gemini launch still carry its flag?- (claude's version gate must not touch gemini.)+14. On a machine with NO claude installed, launch gemini in `acceptEdits`: the `--approval-mode+ auto_edit` flag must still be emitted (claude's version gate must not touch gemini). `auto` is+ not the probe for this any more — it emits no flag on any machine (§5).15. "Restart agent (resume)" on an idle gemini node: does it /quit, wait for the shell, and resumethe SAME conversation? Is it refused while the node is RUNNING or NEEDS YOU? Is the historystill there afterwards (i.e. `--delete` was never typed)?diff --git a/docs/grok-agent.md b/docs/grok-agent.mdindex e46f176be..c33f9ab12 100644--- a/docs/grok-agent.md+++ b/docs/grok-agent.md@@ -9,8 +9,10 @@ completion notifications, the notch capsule, kanban cards, the phone mirror —`hasHooks('grok')` became true. Each further capability is one membership-list edit plus the oneleaf that list gates.-> Sibling documents: **`docs/gemini-agent.md`** is the same write-up for gemini (and carries the-> codex `--ask-for-approval` mapping), and the distilled rules both branches produced are the+> Sibling documents: **`docs/gemini-agent.md`** is the same write-up for gemini. There is no+> per-agent document for codex; its `--ask-for-approval` mapping and the reasoning behind every value+> live in **`src/shared/agents/approval-mode.ts`** (`CODEX_MODES`) and its test. The distilled rules+> both branches produced are the> **"Adding a new agent"** section of `CLAUDE.md`. Rows below that name another agent were> re-verified against `src/shared/agents/config.ts` on 2026-08-09; verify them there, not against> either document, when they matter.@@ -38,7 +40,7 @@ is the cost of adding the next agent to the same list.| `RENAME_CAPABLE` + `TITLE_READ_CAPABLE` | **joined both** | A **read** leg that resolves a session's own name *without searching* (`core/grok-session.ts`, keyed off the hook-fed `sessionId → session dir` map), a **write** leg byte-identical to claude's (`/rename <name>` typed into the pane via `pty.sendText`; grok also accepts `/title`), and one routing rule for the readers — `readAgentSessionName` in `core/agent-session-name.ts`, serving the desktop IPC handler *and* both shells' session-name sweeps. The list SPLIT in two after the grok branch (2026-08-09): `TITLE_READ_CAPABLE` is the read leg and `RENAME_CAPABLE` the write leg, because **gemini** names its own sessions but has no rename command. Grok is in both, so nothing about its behaviour changed — but a future agent must pick per leg, and every `RENAME_CAPABLE` member must also be `TITLE_READ_CAPABLE` (pinned in `config.capabilities.test.ts`). Routing is not cosmetic: claude's resolver scans `~/.claude/projects` on a cache miss, so an unrouted grok node paid that scan on every poll for a guaranteed null — a mounted node polls every **4 s** until the name first resolves and **15 s** after (`TerminalNode.tsx`), and the mirror's own `SESSION_NAME_SWEEP_MS` sweep adds one pass a minute. || `PERMISSION_MODE_CAPABLE` | **joined** | Grok shares claude's flag **spelling** and value vocabulary (`--permission-mode auto\|plan\|acceptEdits\|bypassPermissions`; our `manual` = no flag = grok's own `default`), which is why *its* membership needed no translation. Two things had to change around it: claude's `auto` **version gate** had to become agent-scoped (`activePermissionMode(agentId)`, `renderer/state/permissionMode.ts`), and the flag had to be emitted **before** grok's `--`. See §6. **Sharing the spelling is no longer what membership means:** the list is now `claude, grok, gemini, codex` (2026-08-09) and the last two spell it their own way (`--approval-mode`, `--ask-for-approval`), translated per agent in `src/shared/agents/approval-mode.ts` — which is also where `withPermissionMode` now lives, moved one layer up to break a `config ↔ approval-mode` cycle. || `CANVAS_CONTROL_CAPABLE` | **joined** | Nothing new to install: grok scans `~/.claude/skills` by default for Claude Code compatibility, which is exactly where `manage-nodeterm-canvas` is already written (locally, and on an SSH host by `RemoteHooks.installCanvasControl`). Membership is what sets `NODETERM_CANVAS_CONTROL=1` in the session env — `hook-server.buildPtyEnv` locally, `remoteHookEnvArgs` remotely, both through the single `canControlCanvas` predicate — i.e. what makes the sh+curl shim anything other than a no-op. **Unverified:** `grok inspect --json` was never run (§8). |-| `USAGE_CAPABLE` (the per-node context meter) | **not joined** | Needs a real `signals.json` yielding **both** a used-token count **and** the window total. A percentage against a guessed denominator is a wrong number presented as a fact, so no total ⇒ no meter. Task 5 of the plan stops at its capture step. (For reference, the list is now `claude, codex, gemini` — grok is the only builtin outside it. Codex states its own denominator in its rollout; gemini's comes from its model id through `geminiWindowFor`, mirroring the CLI's own `tokenLimit`. See `docs/gemini-agent.md` §4 — and note that **joining this list also switches on two features that read CLAUDE's transcript**, which is a trap grok will hit too: `docs/gemini-agent.md` §1.) Do not confuse this with grok *billing* usage — see the note below. |+| `USAGE_CAPABLE` (the per-node context meter) | **not joined** | Needs a real `signals.json` yielding **both** a used-token count **and** the window total. A percentage against a guessed denominator is a wrong number presented as a fact, so no total ⇒ no meter. Task 5 of the plan stops at its capture step. (For reference, the list is now `claude, codex, gemini`; grok and **opencode** are the two builtins outside it. Codex states its own denominator in its rollout; gemini's comes from its model id through `geminiWindowFor`, mirroring the CLI's own `tokenLimit`. See `docs/gemini-agent.md` §4 — and note that **joining this list also switches on two features that read CLAUDE's transcript**, which is a trap grok will hit too: `docs/gemini-agent.md` §1.) Do not confuse this with grok *billing* usage — see the note below. || `CONTEXT_LINK_CAPABLE` | **not joined** | Needs a parser for `updates.jsonl` pinned by a real fixture, plus a locator in `core/context-link.ts`. Task 10 stops at its capture step. (For reference, this list is `claude, codex, gemini, opencode` — grok is the only builtin outside it.) || `SUBAGENT_CAPABLE` | **not joined** | Needs the `spawn_subagent` `PreToolUse`/`PostToolUse` payload fields, including whatever marks a **background** launch. Task 11 stops at its capture step. || `BRANCH_CAPABLE` | not joined | Branch sends claude's `/branch` and resumes by claude's session id; grok has no counterpart. |@@ -328,7 +330,7 @@ ai-name / comments).| Context meter | **not implemented for grok** (§1) | the meter itself IS wired server-side (both shells create the per-agent tails — it is codex and gemini that use them, `docs/gemini-agent.md` §4); grok simply has no numbers to feed it on either surface | idem || Managed accounts | **deliberately N/A** — accounts are a claude config-dir mechanism. `createAgentNode` never stamps an `accountId` onto a non-claude node, and `CLAUDE_CONFIG_DIR` is irrelevant to `~/.grok/hooks`. A grok node in a managed-account project must still report status (checklist 7) | idem | idem || Brand logo | the **official** xAI mark, INLINED in `agentIcons.tsx` as `GrokMark` rather than shipped as an asset — it is a single monochrome path, so `fill="currentColor"` inherits the label colour and is correct in both themes. The other four marks are multi-colour and stay `<img src>` assets, where `currentColor` cannot inherit | same component, for free | the phone draws its own icons — **follow-up owed** |-| Working indicator | the **brand mark, breathing** — no critter. `AgentMascot` renders the same `GrokMark` the menus use, pulsing with a `currentColor` drop-shadow bloom, and the notch strip builds the identical glyph from `lib/grokMark.ts` (`createGrokMarkSvg`), so one agent is never two things on two surfaces | **N/A** — no notch there; the canvas badge indicator works | the phone has its own SwiftUI renderer |+| Working indicator | the **brand mark, breathing** — no critter. Since 2026-08-09 this is a THREE-agent mechanism (grok, gemini, opencode) driven by one pure decision, `brandPulsePlan` in `lib/brandPulse.ts`, with a thin renderer per surface: `BrandPulse` for the React badge (`AgentMascot` no longer imports `GrokMark`) and `workingMascot` for the notch strip. Grok is the only `kind: 'inline'` case — its mark is a single monochrome path from `lib/grokMark.ts` (`createGrokMarkSvg` in the HUD) pulsing with a `currentColor` drop-shadow bloom; the other marks are multi-colour assets whose bloom takes the label colour instead of their own ink. One decision, so an agent is never two things on two surfaces. See docs/mascot-sprites.md | **N/A** — no notch there; the canvas badge indicator works | the phone has its own SwiftUI renderer || Fullscreen TUI setting | **N/A** — grok runs full-screen by default, so `claude-tui.ts` has no grok analogue | idem | idem || Deterministic hook-reply approvals (phone Approve/Deny) | **claude-only** — `pty-manager` arms `NODETERM_PERM_WAIT_SECS` only for claude, and grok does not subscribe `PermissionRequest` at all | idem | a grok node's approvals are not answerable from the phone || Kanban card + card modal | badges and the 💬 comments panel work (derived from the same nodes and the same status store); the meter row has nothing to show for grok | same | the iOS board is a separate read/move mirror |diff --git a/docs/mascot-sprites.md b/docs/mascot-sprites.mdindex f64c5e3ae..ef5278850 100644--- a/docs/mascot-sprites.md+++ b/docs/mascot-sprites.md@@ -28,24 +28,40 @@ Quadrant char → (UL, UR, LL, LR) sub-pixel bits:- **Walk**: frame index = `floor(t × 2.5) % 2` (≈ 2.5 steps/s).- **Bob**: vertical offset alternates with the frame (±0.5–1.5 px scaled to render size).-## Grok — the brand mark, breathing (no critter)--Grok has **no sprite**. It had an original quadrant critter first; standing next to two real-mascots it read as neither, so the working indicator became the glyph grok actually has — its-official mark, pulsing with a bloom instead of walking.--- Geometry + path: `src/renderer/lib/grokMark.ts`, shared by the React badge (`AgentMascot` via- `GrokMark`) and the notch HUD, which builds DOM imperatively (`createGrokMarkSvg`). One source, so- the two surfaces cannot show different marks.-- The mark is a single monochrome path painted in `currentColor`, and the **bloom is a drop-shadow of- that same colour**. That is what makes it theme-correct with no ink of its own: light-on-dark in- the dark theme and on the notch's black capsule, dark-on-light in the light theme. A fixed glow- colour would have vanished into one of the two backgrounds — the trap the retired sprite had to- solve with a measured mid-tone.-- Two shadows, tight + wide (`0 0 1px` + `0 0 4px`): the tight one keeps the thin diagonal strokes- from washing out at 13–16 px, the wide one is the glow.+## Grok, gemini and opencode — the brand mark, breathing (no critter)++These three have **no sprite**. Grok had an original quadrant critter first; standing next to two+real mascots it read as neither, so the working indicator became the glyph the agent actually has —+its official mark, pulsing with a bloom instead of walking. gemini and opencode then joined the same+mechanism (2026-08-09): they had been falling through to the plain dot, which says "something is+happening" but not *who*.++- The DECISION is the pure `brandPulsePlan` in `src/renderer/lib/brandPulse.ts` — deliberately+ React-free, because it has two consumers with nothing in common: the React canvas badge+ (`AgentMascot` → `BrandPulse` in `lib/agentIcons.tsx`) and the notch HUD, which builds DOM+ imperatively (`workingMascot` in `hud/main.ts`). One decision, two thin renderers, so an agent is+ never two things on two surfaces. `AgentMascot` no longer imports `GrokMark` at all.+- **Two kinds of mark**, which is the whole reason the plan has a `kind`:+ - `inline` — **grok only**: a single monochrome path from `src/renderer/lib/grokMark.ts`+ (`createGrokMarkSvg` for the HUD), painted in `currentColor`.+ - `asset` — claude, codex, gemini, opencode: multi-colour SVGs carrying their own fills, loaded as+ an `<img src>` / `background-image`, so `currentColor` has nothing to inherit there. (claude and+ codex have their own sprite art and reach the pulse only through menus, not the badge.)+- The **bloom is a drop-shadow of the element's `color`**, which is exactly right for a monochrome+ mark and approximate for the assets: gemini's gradient mark blooms in the label colour, not its own+ ink. Accepted — the halo reads as a glow either way, and per-mark bloom colours would mean an ink+ table. For grok it is what makes the mark theme-correct with no ink of its own: light-on-dark in the+ dark theme and on the notch's black capsule, dark-on-light in the light theme. A fixed glow colour+ would have vanished into one of the two backgrounds — the trap the retired sprite had to solve with+ a measured mid-tone.+- Two shadows, tight + wide (`0 0 1px` + `0 0 4px`): the tight one keeps thin strokes from washing out+ at 13–16 px, the wide one is the glow.- `prefers-reduced-motion` freezes it at the LIT end of the cycle, so a working node reads as awakerather than dimmed.+- The HUD paints its mark as a CSS `background-image` and **must** quote the URL+ (`brandPulseBackground`): Vite inlines these small SVGs as data URIs carrying literal `'` and, for+ three of the four, literal `(`/`)`, so an unquoted `url(…)` terminates early and the declaration is+ dropped — an empty box, silently.## Codex pet (spritesheet asset)diff --git a/src/core/gemini-session.test.ts b/src/core/gemini-session.test.tsindex 4518b0628..f0429ba4f 100644--- a/src/core/gemini-session.test.ts+++ b/src/core/gemini-session.test.ts@@ -55,8 +55,8 @@ describe('pickGeminiTokens', () => {})it('ignores a line that merely CONTAINS "tokens" without a top-level tokens object', () => {- // The transcript's `$set` replay line (fixture line 2) is exactly this shape: it mentions the- // word but carries no top-level counts, so the scan must keep walking backwards.+ // The transcript's `$set` history-sync line (fixture line 2) is exactly this shape: it mentions+ // the word but carries no top-level counts, so the scan must keep walking backwards.const text = [JSON.stringify({ tokens: { input: 42, total: 42 }, model: 'gemini-2.5-pro' }),JSON.stringify({ $set: { messages: [{ note: 'mentions tokens but has none' }] } })@@ -141,17 +141,16 @@ describe('pickGeminiTitle', () => {expect(pickGeminiTitle('')).toBeNull()})- it("finds a title replayed inside a resumed session's `$set` history", () => {- // A RESUME writes its whole prior history into one `{"$set":{"messages":[…]}}` line, so a- // title set before the resume is NESTED there rather than sitting at the top level — and a- // top-level-only reader answers null for the entire resumed session (the case the node-title- // poll cares about most, since a resume is exactly when the OSC title is gone).+ it('finds a title carried inside a `$set.messages` history sync', () => {+ // `$set.messages` is an IN-SESSION history sync: gemini writes the whole array when it rewrites+ // the conversation it holds in memory (bundle chunk-TYAF55F7.js:285852-285857) and reads that+ // array as REPLACING the history (:285303-285335). It is NOT a resume replay — measured on+ // 0.54.4, `--resume` appends to the same file and writes only `{"$set":{"sessionId":…}}`+ // (:285453). The walk is kept as defence: such a record can be the newest line in the file, and+ // a title inside it is one the session currently believes in.//- // Shape provenance: `$set.messages` being an array of ordinary message objects is measured- // (fixture line 2), and a `gemini` message carrying `toolCalls[].args.title` is measured- // (fixture line 22). The COMBINATION is composed from those two, not captured from a real- // resume — if gemini's resume turns out to nest differently, this degrades to the old- // behaviour (null → the node keeps its own title), never to a wrong name.+ // Both shapes are measured in the fixture: `$set.messages` as an array of ordinary message+ // objects (line 2), and a `gemini` message carrying `toolCalls[].args.title` (line 5).const line = JSON.stringify({$set: {messages: [@@ -159,19 +158,19 @@ describe('pickGeminiTitle', () => {{id: 'b',type: 'gemini',- toolCalls: [{ id: 'update_topic__a', name: 'update_topic', args: { title: 'Resumed Topic' } }]+ toolCalls: [{ id: 'update_topic__a', name: 'update_topic', args: { title: 'Synced Topic' } }]}],lastUpdated: '2026-08-09T10:48:49.538Z'}})- expect(pickGeminiTitle(line)).toBe('Resumed Topic')+ expect(pickGeminiTitle(line)).toBe('Synced Topic')})- it('prefers a top-level title over one replayed in the same file', () => {- // The replay line is written when the session resumes, so anything top-level AFTER it is- // newer. The backward scan gives that for free; this pins it.- const replay = JSON.stringify({+ it('prefers a top-level title over one carried in an earlier sync record', () => {+ // A sync record states the history as of the moment it was written, so anything top-level AFTER+ // it is newer. The backward scan gives that for free; this pins it.+ const synced = JSON.stringify({$set: {messages: [{@@ -187,7 +186,7 @@ describe('pickGeminiTitle', () => {type: 'gemini',toolCalls: [{ name: 'update_topic', args: { title: 'New Topic' } }]})- expect(pickGeminiTitle(`${replay}\n${fresh}`)).toBe('New Topic')+ expect(pickGeminiTitle(`${synced}\n${fresh}`)).toBe('New Topic')})it('ignores a nested title-shaped arg on some other tool', () => {diff --git a/src/core/gemini-session.ts b/src/core/gemini-session.tsindex ce76c3f94..752070728 100644--- a/src/core/gemini-session.ts+++ b/src/core/gemini-session.ts@@ -123,21 +123,25 @@ function titleFromToolCalls(calls: unknown): string | null {* "toolCalls":[{"name":"update_topic","args":{"title":"Test Environment Verified", …}}]* (`__fixtures__/gemini/session.jsonl` line 5).*- * TWO PLACES, because of RESUME. A resumed session replays its prior history into a single- * `{"$set":{"messages":[…]}}` line, so a title set before the resume is NESTED in that line's- * messages rather than appearing as a top-level tool call — and a top-level-only reader (this- * function's first version) answered null for the whole resumed session, which is exactly the case- * the read leg exists for (a resume is when the OSC title is gone). So the `$set.messages` history- * is searched as a fallback, newest message first.+ * TWO PLACES, and NOT because of RESUME. `$set.messages` is also walked, but the reason first+ * written here was wrong, and is corrected on the record rather than quietly deleted: a resume does+ * not replay history. Measured in gemini 0.54.4's bundle, `--resume` APPENDS to the same file and+ * writes exactly one record, `{"$set":{"sessionId":…}}` (`chunk-TYAF55F7.js:285453`); the only branch+ * that re-writes messages is the legacy `.json` → `.jsonl` migration, and it appends each one as an+ * ordinary line (`:285430-285450`). So a title set before a resume is still a top-level+ * `update_topic` line, which the backward scan finds unaided.*- * Shape provenance for that fallback: `$set.messages` being an array of ordinary message objects is- * MEASURED (fixture line 2) and a `gemini` message carrying `toolCalls[].args.title` is MEASURED- * (line 22); the COMBINATION is composed from the two, not captured from a real resume. If gemini's- * resume nests differently this degrades to null — the node then keeps its own title until gemini- * writes a new top-level `update_topic` — never to a wrong name.+ * What `$set.messages` actually is: an in-session HISTORY SYNC, written whenever gemini rewrites the+ * conversation it holds in memory (`:285852-285857`) and read by gemini itself as REPLACING the+ * history (`:285303-285335`). The never-resumed fixture carries one at line 2. Since that record can+ * be the newest line in the file and does carry messages, a title inside it is one the session+ * currently believes in — so the walk stays, as DEFENCE rather than as a resume path. It is free (the+ * `"title"` needle keeps every line without one out of it), it matches only `update_topic`, and it+ * cannot invent a name. Both shapes it walks are measured in the fixture (`$set.messages` at line 2,+ * `toolCalls[].args.title` at line 5).*- * Ordering is right for free: the backward line scan takes the NEWEST matching line, and a replay- * line is written when the session resumes, so any top-level title after it wins.+ * Ordering is right for free: the backward line scan takes the NEWEST matching line, so a top-level+ * title written after a history sync wins over one nested inside it.** Read-only: gemini has no rename command (`/chat save <tag>` is a checkpoint, not a title), so* nothing pushes a node title back the other way — gemini is in TITLE_READ_CAPABLE and deliberately@@ -147,7 +151,8 @@ export function pickGeminiTitle(transcript: string | string[]): string | null {return latestJsonLineWhere(transcript, '"title"', (o) => {const top = titleFromToolCalls(o.toolCalls)if (top) return top- // The resume replay. `$set` also carries plain `{lastUpdated}` lines, which have no messages.+ // The in-session history sync (NOT a resume replay — see the docblock). `$set` also carries+ // plain `{lastUpdated}` / `{sessionId}` records, which have no messages.const set = o.$set as { messages?: unknown } | undefinedconst messages = set && typeof set === 'object' ? set.messages : undefinedif (!Array.isArray(messages)) return null