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.

feat(gemini): adopt gemini's own session title, and split reading a title from renaming one

enes05fc6cfb6ec6
diff --git a/docs/grok-agent.md b/docs/grok-agent.md
index a5ad7f332..aff3b9de7 100644
--- a/docs/grok-agent.md
+++ b/docs/grok-agent.md
@@ -29,7 +29,7 @@ is the cost of adding the next agent to the same list.
|---|---|---|
| `AGENT_HOOK_TARGETS` | **joined** | Five things: a pure normalizer for grok's dialect (`normalizeGrok`, `src/shared/agents/normalize.ts`); a subscription list restricted to the events `normalizeGrok` actually maps — nine of the fourteen grok documents (`GROK_HOOK_EVENTS`, `src/shared/agents/hook-events.ts`); an installer able to write a **per-event matcher**, which meant widening the shared installer's event type to `ManagedHookEvent` (`core/agents/hooks/install-helper.ts`); one definition of grok's path algebra (`core/agents/grok-paths.ts`); and a raw-listener branch in **both** shells (`src/main/index.ts`, `src/server/agent-status.ts`) to derive the session directory, because grok's envelope carries no transcript path. |
| `RESUMABLE_AGENTS` | **joined** (pre-branch) | `resumeCommand('grok', id)` → `grok --resume <id>`, and a session id that reaches the renderer — which it does, off every hook payload. |
-| `RENAME_CAPABLE` | **joined** | 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 two readers — `readAgentSessionName` in `core/agent-session-name.ts`, serving the desktop IPC handler *and* both shells' session-name sweeps. 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. |
+| `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`) — that is the whole membership requirement. 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. |
| `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. Do not confuse this with grok *billing* usage — see the note below. |
diff --git a/src/core/agent-session-name.test.ts b/src/core/agent-session-name.test.ts
index 0efdbc9a2..df24930fa 100644
--- a/src/core/agent-session-name.test.ts
+++ b/src/core/agent-session-name.test.ts
@@ -36,4 +36,56 @@ describe('readAgentSessionName', () => {
expect(await readAgentSessionName('', undefined, 'grok')).toBeNull()
expect(await readAgentSessionName('')).toBeNull()
})
+
+ // The gemini leg. Neither reader may ever search the other's tree: claude's resolver SCANS
+ // ~/.claude/projects on a cache miss, so an unrouted gemini node would pay that scan on every
+ // poll (4s per node, then 15s) for a guaranteed null.
+ it("routes a gemini session to its own transcript, via the tail's path", async () => {
+ const p = path.join(root, 'session-gem.jsonl')
+ // The shape the fixture measures: the name is the `update_topic` tool call's `args.title`.
+ writeFileSync(
+ p,
+ JSON.stringify({
+ id: 'm1',
+ type: 'gemini',
+ toolCalls: [{ id: 'update_topic__a', name: 'update_topic', args: { title: 'Verifying Test Environment' } }]
+ }) + '\n'
+ )
+ const asked: string[] = []
+ const name = await readAgentSessionName('gem1', undefined, 'gemini', {
+ geminiPathFor: (id) => (asked.push(id), id === 'gem1' ? p : undefined)
+ })
+ expect(name).toBe('Verifying Test Environment')
+ expect(asked).toEqual(['gem1'])
+ })
+
+ it('answers null for a gemini session no hook has been seen for', async () => {
+ // `pathFor` is fed only by hook POSTs. No path = nothing to read, and null is the honest
+ // answer — never a fall-through to claude's reader, which would scan for a foreign id.
+ expect(
+ await readAgentSessionName('gem-unknown', undefined, 'gemini', { geminiPathFor: () => undefined })
+ ).toBeNull()
+ // No deps at all (the Server Edition before its tail exists, or any pre-gemini caller).
+ expect(await readAgentSessionName('gem-unknown', undefined, 'gemini')).toBeNull()
+ })
+
+ it('answers null when the gemini transcript cannot be read, without throwing', async () => {
+ expect(
+ await readAgentSessionName('gem2', undefined, 'gemini', {
+ geminiPathFor: () => path.join(root, 'does-not-exist.jsonl')
+ })
+ ).toBeNull()
+ })
+
+ it("never asks gemini's path resolver for another agent's session", async () => {
+ const asked: string[] = []
+ const geminiPathFor = (id: string): undefined => {
+ asked.push(id)
+ return undefined
+ }
+ await readAgentSessionName('shared-id', undefined, 'claude', { geminiPathFor })
+ await readAgentSessionName('shared-id', undefined, 'grok', { geminiPathFor })
+ await readAgentSessionName('shared-id', undefined, undefined, { geminiPathFor })
+ expect(asked).toEqual([])
+ })
})
diff --git a/src/core/agent-session-name.ts b/src/core/agent-session-name.ts
index aa9676336..c9e0e24ed 100644
--- a/src/core/agent-session-name.ts
+++ b/src/core/agent-session-name.ts
@@ -1,35 +1,73 @@
-// ONE routing rule for "what is this session's own display name?" — the `/rename` name a node title
-// adopts, per agent.
+// ONE routing rule for "what is this session's own display name?" — the name a node title adopts,
+// per agent. This is the READ leg (`TITLE_READ_CAPABLE`); the WRITE leg (`/rename <name>`, gated by
+// `RENAME_CAPABLE`) is a separate, smaller list, because gemini names its own sessions but has no
+// command to rename one.
//
// It exists as its own module because the rule has THREE consumers already (the desktop's
// `IPC.ptyReadSessionName` handler for the mounted node's poll, and the session-name sweep that
// refreshes the agent-status mirror in BOTH shells), and a routing rule kept in three places is the
-// exact drift this branch has been bitten by twice. Neither reader may ever search the other's tree:
+// exact drift this branch has been bitten by twice. No reader may ever search another's tree:
// claude → a transcript `.jsonl` under `~/.claude/projects` (or a managed account's root)
// grok → `summary.json` in the session directory a hook told us about (core/grok-session.ts)
+// gemini → its own transcript `.jsonl`, at the path the context tail already tracks, read for the
+// `update_topic` tool call that carries the name (core/gemini-session.ts)
// Anything else has no readable session name; the claude reader answers null for it, which is what
// every pre-grok caller already got.
-import { readSessionName } from './transcript-reader'
+import { readSessionName, readSmallTail, TITLE_TAIL_BYTES } from './transcript-reader'
import { readGrokSessionName } from './grok-session'
+import { pickGeminiTitle } from './gemini-session'
+
+/**
+ * Per-agent associations this router cannot own itself, injected by the shell.
+ *
+ * grok's leg needs none (its sessionId → directory map lives in core, fed by the shells' raw hook
+ * listeners); gemini's path authority is the CONTEXT TAIL, which each shell creates, so it arrives
+ * here as a function rather than as a core singleton.
+ */
+export interface AgentSessionNameDeps {
+ /**
+ * sessionId → that gemini session's transcript path, i.e. `geminiContextTail.pathFor`. Fed only
+ * by hook POSTs, so `undefined` for a session no hook has been seen for — and for a REMOTE (SSH)
+ * gemini node, whose transcript is on the host and which the tails deliberately never track
+ * (metering the local disk would report the wrong machine). Both mean "no name", which is
+ * honest: the node keeps its own title.
+ */
+ geminiPathFor?: (sessionId: string) => string | undefined
+}
+
+/** The gemini leg. Its transcript carries a model-generated name that it rewrites as the
+ * conversation develops. Read-only — gemini has no rename command, so this never round-trips.
+ * Bounded tail read, the same cap claude's title read uses. */
+async function readGeminiSessionName(
+ sessionId: string,
+ pathFor?: (id: string) => string | undefined
+): Promise<string | null> {
+ const p = pathFor?.(sessionId)
+ if (!p) return null
+ const tail = await readSmallTail(p, TITLE_TAIL_BYTES)
+ return tail ? pickGeminiTitle(tail) : null
+}
/**
* The session's display name, or null when it cannot be resolved.
*
* `agentId` is TRAILING and optional so every pre-grok caller is unchanged — omitted means claude's
* transcript reader, the only reader that existed. `accountId` is claude's (managed accounts are
- * Claude-only), and grok ignores it.
+ * Claude-only), and the other legs ignore it. `deps` is likewise trailing: a caller with no gemini
+ * association simply gets null for gemini nodes.
*
* Routing MATTERS beyond correctness: claude's resolver scans `~/.claude/projects` when its cache
- * misses, and a grok session id can never be found there — so an unrouted grok node would pay that
- * scan on every poll, forever, for a guaranteed null.
+ * misses, and a grok or gemini session id can never be found there — so an unrouted node would pay
+ * that scan on every poll, forever, for a guaranteed null.
*/
export function readAgentSessionName(
sessionId: string,
accountId?: string,
- agentId?: string
+ agentId?: string,
+ deps?: AgentSessionNameDeps
): Promise<string | null> {
if (!sessionId) return Promise.resolve(null)
- return agentId === 'grok'
- ? readGrokSessionName(sessionId)
- : readSessionName(sessionId, accountId)
+ if (agentId === 'grok') return readGrokSessionName(sessionId)
+ if (agentId === 'gemini') return readGeminiSessionName(sessionId, deps?.geminiPathFor)
+ return readSessionName(sessionId, accountId)
}
diff --git a/src/core/gemini-session.test.ts b/src/core/gemini-session.test.ts
index 46c987c68..35fbf0537 100644
--- a/src/core/gemini-session.test.ts
+++ b/src/core/gemini-session.test.ts
@@ -128,4 +128,64 @@ describe('pickGeminiTitle', () => {
expect(pickGeminiTitle('nonsense')).toBeNull()
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).
+ //
+ // 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.
+ const line = JSON.stringify({
+ $set: {
+ messages: [
+ { id: 'a', type: 'user', content: [{ text: 'test' }] },
+ {
+ id: 'b',
+ type: 'gemini',
+ toolCalls: [{ id: 'update_topic__a', name: 'update_topic', args: { title: 'Resumed Topic' } }]
+ }
+ ],
+ lastUpdated: '2026-08-09T10:48:49.538Z'
+ }
+ })
+ expect(pickGeminiTitle(line)).toBe('Resumed 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({
+ $set: {
+ messages: [
+ {
+ id: 'b',
+ type: 'gemini',
+ toolCalls: [{ name: 'update_topic', args: { title: 'Old Topic' } }]
+ }
+ ]
+ }
+ })
+ const fresh = JSON.stringify({
+ id: 'c',
+ type: 'gemini',
+ toolCalls: [{ name: 'update_topic', args: { title: 'New Topic' } }]
+ })
+ expect(pickGeminiTitle(`${replay}\n${fresh}`)).toBe('New Topic')
+ })
+
+ it('ignores a nested title-shaped arg on some other tool', () => {
+ const line = JSON.stringify({
+ $set: {
+ messages: [
+ { id: 'b', type: 'gemini', toolCalls: [{ name: 'write_file', args: { title: 'not a name' } }] }
+ ]
+ }
+ })
+ expect(pickGeminiTitle(line)).toBeNull()
+ })
})
diff --git a/src/core/gemini-session.ts b/src/core/gemini-session.ts
index ac463cc66..ac940dbe0 100644
--- a/src/core/gemini-session.ts
+++ b/src/core/gemini-session.ts
@@ -94,30 +94,66 @@ export function pickGeminiTokens(transcript: string | string[]): AgentUsage | nu
return r ? { usedTokens: r.used, windowTokens: r.window } : null
}
+/** One transcript message, as far as the title reader cares: it may carry tool calls. */
+interface GeminiMessage {
+ toolCalls?: unknown
+}
+
+/** The newest `update_topic` title among a line's tool calls, or null. Last call wins within a
+ * line: a line can hold several, and the newest is the name. Matched on the tool NAME so a
+ * `title` argument belonging to some other tool can never be mistaken for the session's name. */
+function titleFromToolCalls(calls: unknown): string | null {
+ if (!Array.isArray(calls)) return null
+ for (let i = calls.length - 1; i >= 0; i--) {
+ const c = calls[i] as { name?: unknown; args?: { title?: unknown } } | null
+ if (!c || c.name !== 'update_topic') continue
+ const title = c.args?.title
+ if (typeof title === 'string' && title.trim()) return title.trim()
+ }
+ return null
+}
+
/**
- * The latest session title gemini has given the conversation.
+ * The latest session title gemini has given the conversation — what the node title adopts
+ * (`TITLE_READ_CAPABLE`, routed in core/agent-session-name.ts).
*
* It is NOT a top-level transcript field — verified against the captured fixture, where no line
* parses to an object with a `title`. Gemini names the conversation through its own `update_topic`
* tool, so the name lives in that tool call's arguments:
* "toolCalls":[{"name":"update_topic","args":{"title":"Test Environment Verified", …}}]
- * (`__fixtures__/gemini/session.jsonl` line 22). Matched on the tool NAME so a `title` argument
- * belonging to some other tool can never be mistaken for the session's name.
+ * (`__fixtures__/gemini/session.jsonl` line 22).
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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.
*
- * Read-only: gemini has no rename command, so nothing pushes a node title back the other way —
- * which is why gemini is in neither `RENAME_CAPABLE` nor any list yet. NOTHING CONSUMES THIS TODAY;
- * it lives here because both gemini readers share this file.
+ * 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
+ * NOT in RENAME_CAPABLE.
*/
export function pickGeminiTitle(transcript: string | string[]): string | null {
return latestJsonLineWhere(transcript, '"title"', (o) => {
- const calls = o.toolCalls
- if (!Array.isArray(calls)) return null
- // Last call wins within a line: a line can hold several tool calls, and the newest is the name.
- for (let i = calls.length - 1; i >= 0; i--) {
- const c = calls[i] as { name?: unknown; args?: { title?: unknown } } | null
- if (!c || c.name !== 'update_topic') continue
- const title = c.args?.title
- if (typeof title === 'string' && title.trim()) return title.trim()
+ const top = titleFromToolCalls(o.toolCalls)
+ if (top) return top
+ // The resume replay. `$set` also carries plain `{lastUpdated}` lines, which have no messages.
+ const set = o.$set as { messages?: unknown } | undefined
+ const messages = set && typeof set === 'object' ? set.messages : undefined
+ if (!Array.isArray(messages)) return null
+ for (let i = messages.length - 1; i >= 0; i--) {
+ const hit = titleFromToolCalls((messages[i] as GeminiMessage | null)?.toolCalls)
+ if (hit) return hit
}
return null
})
diff --git a/src/core/session-name-sweep.test.ts b/src/core/session-name-sweep.test.ts
index fb1b1e781..ed7c76efa 100644
--- a/src/core/session-name-sweep.test.ts
+++ b/src/core/session-name-sweep.test.ts
@@ -7,7 +7,8 @@ function deps(
names?: Record<string, string | null>
nodes?: Record<string, { accountId?: string; titleAuto?: boolean }>
throwFor?: string
- /** The real `supports` is RENAME_CAPABLE, which now holds grok too. */
+ /** The real `supports` is TITLE_READ_CAPABLE (claude, grok, gemini) — the READ list, since the
+ * sweep only reads names. */
supportsGrok?: boolean
} = {}
) {
diff --git a/src/core/session-name-sweep.ts b/src/core/session-name-sweep.ts
index 8c8d73ddc..e10cebbe4 100644
--- a/src/core/session-name-sweep.ts
+++ b/src/core/session-name-sweep.ts
@@ -30,14 +30,17 @@ export interface SessionNameSweepDeps {
* means the user named this node by hand, so its session name is not what should be shown. */
node: (nodeId: string) => { accountId?: string; titleAuto?: boolean } | undefined
/** Resolves the agent's own session name, local or remote — `core/agent-session-name.ts`, which
- * routes per agent (claude reads a transcript, grok its session metadata). `agentId` is trailing
- * and optional so a resolver that only knows claude still satisfies the type. It is not optional
- * in PRACTICE: without it a grok entry would be resolved by claude's reader, which scans
- * `~/.claude/projects` for an id that can never be there — once a minute, per node, forever. */
+ * routes per agent (claude reads a transcript, grok its session metadata, gemini its own
+ * transcript). `agentId` is trailing and optional so a resolver that only knows claude still
+ * satisfies the type. It is not optional in PRACTICE: without it a grok entry would be resolved
+ * by claude's reader, which scans `~/.claude/projects` for an id that can never be there — once a
+ * minute, per node, forever. */
resolve: (sessionId: string, accountId?: string, agentId?: string) => Promise<string | null>
/** Publish a changed name into the mirror. */
publish: (nodeId: string, name: string) => void
- /** Which agents carry a resolvable session name (RENAME_CAPABLE — claude and grok). */
+ /** Which agents carry a READABLE session name — `TITLE_READ_CAPABLE` (claude, grok, gemini), not
+ * `RENAME_CAPABLE`. This sweep only ever READS a name and publishes it; nothing here pushes one
+ * back, so gating it on the write capability would silently skip gemini's nodes. */
supports: (agentId?: string) => boolean
}
diff --git a/src/core/transcript-reader.ts b/src/core/transcript-reader.ts
index 1f204e391..fb9bfd39c 100644
--- a/src/core/transcript-reader.ts
+++ b/src/core/transcript-reader.ts
@@ -241,7 +241,11 @@ export async function resolveTranscriptPath(
// Read only the last `cap` bytes of a file as UTF-8 (whole file if smaller). Drops the partial
// leading line on a capped read. Cheaper than readCappedTail for tiny scans (session title).
-async function readSmallTail(filePath: string, cap: number): Promise<string | undefined> {
+//
+// Exported for the OTHER title readers routed by core/agent-session-name.ts (gemini's), which need
+// the identical bounded read of a different agent's transcript. It is a byte-level file helper and
+// knows nothing about claude's layout — the storage-specific parsing stays in each agent's module.
+export async function readSmallTail(filePath: string, cap: number): Promise<string | undefined> {
try {
const stat = await fs.promises.stat(filePath)
if (stat.size <= cap) return await fs.promises.readFile(filePath, 'utf8')
diff --git a/src/main/index.ts b/src/main/index.ts
index eb0b1ee2d..99e761ff6 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -1,7 +1,7 @@
import { join, resolve, posix } from 'path'
import { startSessionNameSweep, displayNodeTitle } from '../core/session-name-sweep'
-import { readAgentSessionName } from '../core/agent-session-name'
-import { canRename, type AgentId } from '@shared/agents/config'
+import { readAgentSessionName, type AgentSessionNameDeps } from '../core/agent-session-name'
+import { canReadTitle, type AgentId } from '@shared/agents/config'
import { readFile } from 'fs/promises'
import { homedir, hostname } from 'os'
import { randomUUID } from 'crypto'
@@ -559,14 +559,24 @@ app.whenReady().then(async () => {
ptyManager.captureSession(persistKey, full)
)
+ // Gemini's title read needs the transcript path its own context tail already tracks (nothing
+ // scans for it). That tail is created further down with the rest of the hook plumbing, so the
+ // association is resolved LAZILY — the same pattern as the remote-file readers down there, and
+ // safe for the same reason: it is only ever dereferenced from an IPC call or the sweep's timer,
+ // long after init. `pathFor` answers undefined for a session no hook has been seen for, and for a
+ // remote (SSH) gemini node, which the tails deliberately never track — both mean "no name".
+ const agentSessionNameDeps: AgentSessionNameDeps = {
+ geminiPathFor: (sessionId) => geminiContextTail.pathFor(sessionId)
+ }
+
// The reader is selected by the NODE's agent (core/agent-session-name.ts — the one copy of that
- // rule, shared with the sweep below and with the Server Edition), so neither reader ever searches
- // the other's tree. `agentId` is a TRAILING optional argument, so every pre-grok caller resolves
+ // rule, shared with the sweep below and with the Server Edition), so no reader ever searches
+ // another's tree. `agentId` is a TRAILING optional argument, so every pre-grok caller resolves
// through the claude reader unchanged.
corePlatform.handle(
IPC.ptyReadSessionName,
(sessionId: string, accountId?: string, agentId?: string) =>
- readAgentSessionName(sessionId ?? '', accountId, agentId)
+ readAgentSessionName(sessionId ?? '', accountId, agentId, agentSessionNameDeps)
)
ipcMain.on(IPC.appCloseWindow, () => BrowserWindow.getFocusedWindow()?.close())
@@ -870,12 +880,15 @@ app.whenReady().then(async () => {
const n = workspaceStore.getNode(nodeId)
return n ? { accountId: n.accountId, titleAuto: n.titleAuto } : undefined
},
- // Same router the IPC handler above uses — the sweep sees every RENAME_CAPABLE agent, so
- // resolving a grok node through claude's reader would scan ~/.claude/projects once a minute
- // for an id that can never be there.
- resolve: readAgentSessionName,
+ // Same router the IPC handler above uses — the sweep sees every TITLE_READ_CAPABLE agent, so
+ // resolving a grok or gemini node through claude's reader would scan ~/.claude/projects once a
+ // minute for an id that can never be there.
+ resolve: (sessionId, accountId, agentId) =>
+ readAgentSessionName(sessionId, accountId, agentId, agentSessionNameDeps),
publish: setNodeSessionName,
- supports: (agentId) => !!agentId && canRename(agentId as AgentId)
+ // The READ list, not RENAME_CAPABLE: this sweep only reads names and publishes them into the
+ // mirror (the phone's lists), so gating it on the write leg would skip gemini's nodes.
+ supports: (agentId) => !!agentId && canReadTitle(agentId as AgentId)
})
// macOS Notch HUD (docs/notch-hud.md): walking agent mascots by the notch. darwin + setting only;
// reads the same agent-status seams the mirror does. Live-toggled via settings below.
diff --git a/src/renderer/bridge/ws-bridge.ts b/src/renderer/bridge/ws-bridge.ts
index 6bdec1968..3658e91b5 100644
--- a/src/renderer/bridge/ws-bridge.ts
+++ b/src/renderer/bridge/ws-bridge.ts
@@ -230,10 +230,13 @@ export function buildRealApi(
paneCommand: (persistKey) =>
client.request(IPC.ptyPaneCommand, persistKey).catch(() => null) as Promise<string | null>,
// No server handler — the session-name poll degrades to no adopted name. A PRE-EXISTING gap,
- // not a grok one: `IPC.ptyReadSessionName` has never been registered server-side, so claude's
- // read leg is equally stubbed here (the write leg works on both surfaces — it goes through
- // pty.sendText). Fixing it means moving the routing into core and registering it from both
- // shells, exactly as `core/transcript-ipc.ts` did for the ⌘M transcript channels.
+ // and not any one agent's: `IPC.ptyReadSessionName` has never been registered server-side, so
+ // claude's, grok's and gemini's read legs are equally stubbed here (the write leg works on both
+ // surfaces — it goes through pty.sendText). The routing itself is already in core
+ // (`core/agent-session-name.ts`) and the server already threads gemini's path association into
+ // its session-name SWEEP, which is what keeps the phone's names correct; only this per-node poll
+ // is missing. Fixing it means registering the channel from both shells, exactly as
+ // `core/transcript-ipc.ts` did for the ⌘M transcript channels.
readSessionName: () => Promise.resolve(''),
onData: (sessionId, listener) =>
client.subscribe(IPC.ptyData(sessionId), listener as Listener),
diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsx
index 8577797d4..020bf9d50 100644
--- a/src/renderer/nodes/TerminalNode.tsx
+++ b/src/renderer/nodes/TerminalNode.tsx
@@ -106,7 +106,7 @@ import { useWorktrees } from '../state/worktrees'
import { isRemoteSessionNode } from '@shared/worktree'
import { useSession, useActiveSessionPresence } from '../session/session'
import { accountChipLabel, COLLAPSED_HEIGHT, NODE_COLORS, type CanvasNode } from '../state/workspace'
-import { hasHooks, canRecur, canContextLink, hasUsage, canChat, canResume, canRename, createdAgentId, resumeCommand, withPermissionMode, agentConfig } from '@shared/agents/config'
+import { hasHooks, canRecur, canContextLink, hasUsage, canChat, canResume, canRename, canReadTitle, createdAgentId, resumeCommand, withPermissionMode, agentConfig } from '@shared/agents/config'
import { ensureActivePermissionMode } from '../state/permissionMode'
import { buildSshArgs, type SshConnection } from '@shared/ssh'
import { hintLabel } from '@shared/platform-utils'
@@ -804,7 +804,10 @@ export function TerminalNode({
const claudeTranscript = readsClaudeTranscript(agentId)
// The header 💬 now opens the board-log comments flyout (right side); ⌘M keeps the markdown/chat view.
const [commentsOpen, setCommentsOpen] = useState(false)
- const canRenameNode = !!agentId && canRename(agentId) // title ⇄ session-name two-way sync
+ const canRenameNode = !!agentId && canRename(agentId) // WRITE leg: push `/rename <name>` back
+ // READ leg: adopt the agent's own session name into the title. A superset of canRenameNode —
+ // gemini names its own sessions but has no rename command, so it polls and never pushes.
+ const canReadTitleNode = !!agentId && canReadTitle(agentId)
const agentLabel = (agentId ? agentConfig(agentId) : undefined)?.label ?? 'Agent'
// Keep the listener's mirrors current every render.
@@ -2857,11 +2860,13 @@ export function TerminalNode({
// shows up after a resume. Resolved strictly by THIS node's sessionId — we do NOT sync until it's
// known, otherwise same-folder nodes would adopt whichever session wrote last. Polls only while
// the title still auto-tracks the session (titleAuto) and stops once the user renames by hand.
- // Gated on canRenameNode (RENAME_CAPABLE). `agentId` rides along so main picks the right reader:
- // claude's transcript .jsonl vs grok's summary.json. It is resolved at node creation and immutable
- // thereafter — same as `data.accountId` beside it — so neither belongs in the dep array.
+ // Gated on canReadTitleNode (TITLE_READ_CAPABLE), NOT on canRenameNode: reading a session's name
+ // and being able to set one are different capabilities, and gemini has only the first. `agentId`
+ // rides along so main picks the right reader: claude's transcript .jsonl vs grok's summary.json vs
+ // gemini's update_topic tool call. It is resolved at node creation and immutable thereafter —
+ // same as `data.accountId` beside it — so neither belongs in the dep array.
useEffect(() => {
- if (!canRenameNode || data.titleAuto === false) return
+ if (!canReadTitleNode || data.titleAuto === false) return
const sid = status?.sessionId ?? ''
if (!sid) return
let cancelled = false
@@ -2893,7 +2898,7 @@ export function TerminalNode({
cancelled = true
if (timer) clearTimeout(timer)
}
- }, [id, canRenameNode, status?.sessionId, data.titleAuto, updateNodeData])
+ }, [id, canReadTitleNode, status?.sessionId, data.titleAuto, updateNodeData])
// Cmd/Ctrl+M toggles markdown view of this terminal's output (only when hovered).
useEffect(() => {
diff --git a/src/renderer/nodes/title-gate.test.ts b/src/renderer/nodes/title-gate.test.ts
new file mode 100644
index 000000000..1ebc6a564
--- /dev/null
+++ b/src/renderer/nodes/title-gate.test.ts
@@ -0,0 +1,63 @@
+// A guard over the TWO title gates, because the split is the whole point of the title lists.
+//
+// Reading a session's own name (`TITLE_READ_CAPABLE` — claude, grok, gemini) and PUSHING a name into
+// a session (`RENAME_CAPABLE` — claude, grok) are different capabilities. Gating the poll on the
+// write list costs gemini the title it names itself; gating a push on the read list types
+// `/rename <name>` into a CLI that has no such command, in front of the user, on every rename.
+//
+// Neither `TerminalNode.tsx` nor `Canvas.tsx` is unit-rendered anywhere in this repo, so there is no
+// behavioural test to catch either mistake — these are asserted over the SOURCE TEXT, the same
+// technique `core/no-electron.test.ts` uses for the shell boundary. If a refactor moves a gate, the
+// invariant is what matters: the poll reads, the push writes.
+import { describe, it, expect } from 'vitest'
+import fs from 'fs'
+import path from 'path'
+
+const read = (rel: string): string => fs.readFileSync(path.join(__dirname, '..', rel), 'utf8')
+const terminalNode = read('nodes/TerminalNode.tsx')
+const canvas = read('canvas/Canvas.tsx')
+const sessionRename = read('lib/sessionRename.ts')
+
+describe('session-name title gates', () => {
+ it('the node-title poll is gated on the READ capability', () => {
+ // The effect that adopts the agent's own session name into data.title.
+ expect(terminalNode).toContain('const canReadTitleNode = !!agentId && canReadTitle(agentId)')
+ expect(terminalNode).toContain('if (!canReadTitleNode || data.titleAuto === false) return')
+ // The pre-split gate must be gone from that effect — with it, a gemini node never polls.
+ expect(terminalNode).not.toContain('if (!canRenameNode || data.titleAuto === false) return')
+ })
+
+ it('the `/rename` push is gated on the WRITE capability', () => {
+ const pushes = terminalNode
+ .split('\n')
+ .filter((l) => l.includes('/rename ') && l.includes('sendText'))
+ expect(pushes.length).toBe(1)
+ expect(pushes[0]).toContain('canRenameNode')
+ })
+
+ it('no rename-WRITE site gates on the read capability', () => {
+ // These three files hold every push of a node title into a live session (the node header /
+ // ✦ AI-name funnel, the canvas-control `rename` verb, `renameSession`, and the pane-probing
+ // helper they all use). None of them may ever consult the READ list: an agent that names its
+ // own sessions does not necessarily accept a rename.
+ // TerminalNode's own push is covered by the test above (it holds both gates, so a
+ // whole-file scan would say nothing); these are the files that hold ONLY write paths.
+ for (const [name, src] of [
+ ['Canvas.tsx', canvas],
+ ['lib/sessionRename.ts', sessionRename]
+ ] as const) {
+ expect(src.includes('canReadTitle'), name).toBe(false)
+ }
+ })
+
+ it('every canvas rename push sits behind a canRename guard', () => {
+ const lines = canvas.split('\n')
+ const calls = lines.map((l, i) => [l, i] as const).filter(([l]) => l.includes('pushSessionRename('))
+ expect(calls.length).toBeGreaterThan(0)
+ for (const [line, i] of calls) {
+ // The guard is an `if (agentId && canRename(agentId) && …)` a few lines above the call.
+ const window = lines.slice(Math.max(0, i - 8), i + 1).join('\n')
+ expect(window.includes('canRename('), `${i + 1}: ${line.trim()}`).toBe(true)
+ }
+ })
+})
diff --git a/src/server/agent-status.ts b/src/server/agent-status.ts
index b3fd9621a..f9361b261 100644
--- a/src/server/agent-status.ts
+++ b/src/server/agent-status.ts
@@ -46,13 +46,14 @@ export interface WireAgentStatusOptions {
*
* Does NOT call `hookServer.start()` — the boot step owns starting the server.
*
- * Returns its context tail so the boot step can give the transcript read channels the same
- * hook-fed path authority the desktop gives them (`registerTranscriptIpc`).
+ * Returns its context tails so the boot step can give the readers the same hook-fed path authority
+ * the desktop gives them: claude's for the transcript read channels (`registerTranscriptIpc`), and
+ * gemini's for the session-name router, whose gemini leg reads the transcript at that path.
*/
export function wireAgentStatus(
platform: ServerPlatform,
opts: WireAgentStatusOptions = {}
-): { contextTail: ContextTail } {
+): { contextTail: ContextTail; geminiContextTail: ContextTail } {
const hooks = opts.hooks ?? hookServer
// nodeId → the agent session id of whichever hook-capable CLI runs in that node (claude's, and
// since the grok branch below, grok's)
@@ -285,5 +286,5 @@ export function wireAgentStatus(
platform.on(IPC.ptyDestroy, (nodeId: string) => releaseNodeTails(nodeId))
platform.on(IPC.ptyRecycle, (nodeId: string) => releaseNodeTails(nodeId))
- return { contextTail }
+ return { contextTail, geminiContextTail }
}
diff --git a/src/server/index.ts b/src/server/index.ts
index 6952b9684..2fe7d4d46 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -1,7 +1,7 @@
import fs from 'fs'
import { readAgentSessionName } from '../core/agent-session-name'
import { startSessionNameSweep, displayNodeTitle } from '../core/session-name-sweep'
-import { canRename, type AgentId } from '@shared/agents/config'
+import { canReadTitle, type AgentId } from '@shared/agents/config'
import path from 'path'
import http from 'http'
@@ -260,9 +260,17 @@ export async function startServer(
// The per-agent router (core/agent-session-name.ts), same as the desktop's sweep and its
// ptyReadSessionName handler: a grok node's name is in its session metadata, and resolving it
// through claude's reader would scan ~/.claude/projects once a minute for a guaranteed miss.
- resolve: readAgentSessionName,
+ // Gemini's leg needs the transcript path its context tail tracks; that tail is created by
+ // `wireAgentStatus` below, so it is dereferenced lazily — the sweep's first pass is 5s after
+ // boot, long after wiring.
+ resolve: (sessionId, accountId, agentId) =>
+ readAgentSessionName(sessionId, accountId, agentId, {
+ geminiPathFor: (id) => geminiContextTail.pathFor(id)
+ }),
publish: setNodeSessionName,
- supports: (agentId) => !!agentId && canRename(agentId as AgentId)
+ // The READ list, not RENAME_CAPABLE: the sweep only reads names and publishes them into the
+ // mirror the phone reads, so gating it on the write leg would skip gemini's nodes.
+ supports: (agentId) => !!agentId && canReadTitle(agentId as AgentId)
})
// Advertise launch settings to the mobile companion through the mirror (same provider the
// desktop wires in src/main/index.ts). No SSH push exists server-side, so only the local
@@ -293,7 +301,7 @@ export async function startServer(
// missing/corrupt file simply yields no block.
const installMeta = readInstallMeta(config.dataDir)
setMirrorServerProvider(() => installMeta)
- const { contextTail } = wireAgentStatus(platform)
+ const { contextTail, geminiContextTail } = wireAgentStatus(platform)
// The ⌘M chat view + the find-bar's transcript index. Registered HERE rather than with the rest
// of the handlers because the hook-fed path authority is the tail created just above. No remote
// leg: the Server Edition runs ON the host whose transcripts it reads, so local resolution is
diff --git a/src/shared/agents/config.capabilities.test.ts b/src/shared/agents/config.capabilities.test.ts
index 86c616bf2..0843fe8a4 100644
--- a/src/shared/agents/config.capabilities.test.ts
+++ b/src/shared/agents/config.capabilities.test.ts
@@ -6,6 +6,7 @@ import {
canChat,
canContextLink,
canControlCanvas,
+ canReadTitle,
canRecur,
canRename,
canResume,
@@ -14,7 +15,8 @@ import {
createdAgentId,
hasHooks,
hasPermissionMode,
- hasUsage
+ hasUsage,
+ RENAME_CAPABLE
} from './config'
describe('CONTEXT_LINK_CAPABLE', () => {
@@ -44,7 +46,7 @@ describe('opencode capabilities', () => {
expect(canControlCanvas('opencode')).toBe(true)
})
it('stays out of the claude-only capability lists', () => {
- for (const can of [canSubagent, canRecur, canBranch, hasUsage, canChat, canTransferFrom, canRename, hasPermissionMode]) {
+ for (const can of [canSubagent, canRecur, canBranch, hasUsage, canChat, canTransferFrom, canRename, canReadTitle, hasPermissionMode]) {
expect(can('opencode')).toBe(false)
}
})
@@ -131,3 +133,39 @@ describe('grok capabilities', () => {
expect(canSubagent('grok')).toBe(false)
})
})
+
+/**
+ * Reading a session name and PUSHING one back are different capabilities, and gemini has only the
+ * first: its transcript carries a model-generated name (the `update_topic` tool's `args.title`,
+ * measured in `core/__fixtures__/gemini/session.jsonl`), but its command set
+ * (`/chat list|save|resume|delete|share`, measured on 0.54.4) has no rename — `save <tag>` is a
+ * tagged checkpoint. One list for both would light the rename UI on a node where it does nothing.
+ */
+describe('title read vs rename write', () => {
+ it('gemini can be read but never written', () => {
+ expect(canReadTitle('gemini')).toBe(true)
+ expect(canRename('gemini')).toBe(false)
+ })
+
+ it('claude and grok do both', () => {
+ for (const id of ['claude', 'grok'] as const) {
+ expect(canReadTitle(id), id).toBe(true)
+ expect(canRename(id), id).toBe(true)
+ }
+ })
+
+ it('every rename-capable agent is also title-readable — the write leg needs the read leg to settle', () => {
+ for (const id of RENAME_CAPABLE) expect(canReadTitle(id), id).toBe(true)
+ })
+
+ it('codex claims neither, for want of evidence', () => {
+ // Its slash-command set was not enumerable from the CLI, so neither leg has a measured basis.
+ expect(canReadTitle('codex')).toBe(false)
+ expect(canRename('codex')).toBe(false)
+ })
+
+ it('a custom agent claims neither', () => {
+ expect(canReadTitle('custom:abc')).toBe(false)
+ expect(canRename('custom:abc')).toBe(false)
+ })
+})
diff --git a/src/shared/agents/config.ts b/src/shared/agents/config.ts
index 518d979f3..f6a08dc6e 100644
--- a/src/shared/agents/config.ts
+++ b/src/shared/agents/config.ts
@@ -109,12 +109,28 @@ export const USAGE_CAPABLE = ['claude', 'codex', 'gemini'] as const
export const CHAT_CAPABLE = ['claude'] as const
// Agents whose native transcript we can read + render for cross-agent transfer.
export const TRANSFER_SOURCE_CAPABLE = ['claude', 'codex', 'gemini'] as const
-// Agents that support naming the session in two directions: they emit a session title we adopt
-// into the node title, and accept `/rename <name>` to push a renamed node title back. Read legs are
-// per-agent (claude: the transcript .jsonl; grok: its session summary.json — see
-// core/grok-session.ts, routed at the readSessionName IPC handler); the write leg is the same
-// literal `/rename <name>` for both, which grok also accepts as `/title`.
+// Agents that accept a node title being PUSHED back into the session — the write leg only. The
+// write is the same literal `/rename <name>` for both, which grok also accepts as `/title`.
+// The READ leg is TITLE_READ_CAPABLE below, which is a superset: an agent can name its own session
+// without offering any way to rename it (gemini). Read legs are per-agent (claude: the transcript
+// .jsonl; grok: its session summary.json; gemini: its update_topic tool call), routed once in
+// core/agent-session-name.ts.
export const RENAME_CAPABLE = ['claude', 'grok'] as const
+// Agents whose OWN session name we can READ and adopt into the node title.
+//
+// Separate from RENAME_CAPABLE because the two directions are separate facts, and gemini has only
+// this one: it writes a model-generated name into its transcript (the `update_topic` tool's
+// `args.title` — core/gemini-session.ts) but has no command to SET one. Its session commands are
+// `/chat list|save|resume|delete|share` (measured on 0.54.4), where `save <tag>` is a tagged
+// checkpoint, not a title — so one list for both legs would light the rename UI on a node where
+// the write silently does nothing.
+//
+// INVARIANT (pinned in config.capabilities.test.ts): every RENAME_CAPABLE agent is also here. The
+// write leg pushes a name and the read leg is what confirms it settled.
+//
+// codex is in NEITHER: its slash-command set could not be enumerated from the CLI, so neither leg
+// has a measured basis — and a guess here costs a wrong node title, not a missing one.
+export const TITLE_READ_CAPABLE = ['claude', 'grok', 'gemini'] as const
// Agents allowed to drive the canvas via the `nodeterm` CLI (open/show/write/close).
// Discovery differs per agent: claude gets the manage-nodeterm-canvas skill; codex/gemini/
// opencode a marker block in ~/.codex/AGENTS.md / ~/.gemini/GEMINI.md /
@@ -151,6 +167,7 @@ export const hasUsage = (id: AgentId): boolean => includes(USAGE_CAPABLE, id)
export const canChat = (id: AgentId): boolean => includes(CHAT_CAPABLE, id)
export const canTransferFrom = (id: AgentId): boolean => includes(TRANSFER_SOURCE_CAPABLE, id)
export const canRename = (id: AgentId): boolean => includes(RENAME_CAPABLE, id)
+export const canReadTitle = (id: AgentId): boolean => includes(TITLE_READ_CAPABLE, id)
export const canControlCanvas = (id: AgentId): boolean => includes(CANVAS_CONTROL_CAPABLE, id)
export const hasPermissionMode = (id: AgentId): boolean => includes(PERMISSION_MODE_CAPABLE, id)