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.

fix(agents): make the session-name sweep's read gate core's own default

enesb2334194b9e2
diff --git a/src/core/session-name-sweep.test.ts b/src/core/session-name-sweep.test.ts
index ed7c76efa..aacf1f063 100644
--- a/src/core/session-name-sweep.test.ts
+++ b/src/core/session-name-sweep.test.ts
@@ -116,3 +116,69 @@ describe('sweepSessionNames', () => {
expect(published).toEqual([['good', 'still works']])
})
})
+
+/**
+ * The `supports` gate is core's own default, not something each shell states.
+ *
+ * It used to be passed identically by `src/main/index.ts` and `src/server/index.ts`, and a wrong
+ * copy is INVISIBLE: swap the read list for the write one and every gemini node is skipped, so the
+ * agent-status mirror — and the phone that reads it — never sees a gemini session name, with the
+ * whole suite still green (nothing exercises a shell's wiring). Hence the default lives here, and
+ * these tests pass NO `supports` at all so they exercise the real rule.
+ */
+describe('the default supports gate (TITLE_READ_CAPABLE)', () => {
+ const sweepWithDefaultGate = async (
+ entries: SweepEntry[]
+ ): Promise<{ published: [string, string][]; asked: string[] }> => {
+ const published: [string, string][] = []
+ const asked: string[] = []
+ await sweepSessionNames({
+ entries: () => entries,
+ node: () => undefined,
+ resolve: async (sessionId) => (asked.push(sessionId), `name of ${sessionId}`),
+ publish: (nodeId, name) => published.push([nodeId, name])
+ // no `supports` — the point of these tests
+ })
+ return { published, asked }
+ }
+
+ it('sweeps every agent whose session name we can READ', async () => {
+ // gemini is the reason the lists split: it names its own sessions (its transcript's
+ // `update_topic` title) but has no rename command, so it is read-only — and read is all the
+ // sweep ever does. On the write list it would be skipped here and the phone would show a stale
+ // node title forever.
+ const { published, asked } = await sweepWithDefaultGate([
+ { nodeId: 'c', sessionId: 'cs', agentId: 'claude' },
+ { nodeId: 'g', sessionId: 'gs', agentId: 'grok' },
+ { nodeId: 'm', sessionId: 'ms', agentId: 'gemini' }
+ ])
+ expect(asked).toEqual(['cs', 'gs', 'ms'])
+ expect(published).toEqual([
+ ['c', 'name of cs'],
+ ['g', 'name of gs'],
+ ['m', 'name of ms']
+ ])
+ })
+
+ it('never asks about an agent whose name we cannot read', async () => {
+ // codex is in neither list (its command set was not enumerable, so neither leg has a measured
+ // basis) and a custom agent has no reader at all. Asking anyway would send them through
+ // claude's resolver, which SCANS ~/.claude/projects for an id that can never be there.
+ const { published, asked } = await sweepWithDefaultGate([
+ { nodeId: 'x', sessionId: 'xs', agentId: 'codex' },
+ { nodeId: 'y', sessionId: 'ys', agentId: 'custom:mine' },
+ { nodeId: 'z', sessionId: 'zs' }
+ ])
+ expect(asked).toEqual([])
+ expect(published).toEqual([])
+ })
+
+ it('is still injectable, so a caller with a narrower set can say so', async () => {
+ const { d, published } = deps([{ nodeId: 'm', sessionId: 'ms', agentId: 'gemini' }], {
+ names: { ms: 'gemini named it' }
+ })
+ // The helper's `supports` is claude-only, and it wins over the default.
+ expect(await sweepSessionNames(d)).toBe(0)
+ expect(published).toEqual([])
+ })
+})
diff --git a/src/core/session-name-sweep.ts b/src/core/session-name-sweep.ts
index e10cebbe4..e6bdd18e4 100644
--- a/src/core/session-name-sweep.ts
+++ b/src/core/session-name-sweep.ts
@@ -13,6 +13,17 @@
//
// Everything is injected: no fs, no electron, no timers of its own beyond the interval, so the
// scheduling and the skip rules are unit-testable.
+import { canReadTitle, type AgentId } from '@shared/agents/config'
+
+/**
+ * The default `supports`: `TITLE_READ_CAPABLE` (claude, grok, gemini), NOT `RENAME_CAPABLE`.
+ *
+ * The sweep only ever READS a name and publishes it into the mirror; nothing here pushes one back,
+ * so the read list is the right gate — gating on the write leg would skip gemini, which names its
+ * own sessions but has no rename command.
+ */
+export const supportsTitleRead = (agentId?: string): boolean =>
+ !!agentId && canReadTitle(agentId as AgentId)
/** One node the sweep may refresh. */
export interface SweepEntry {
@@ -38,10 +49,19 @@ export interface SessionNameSweepDeps {
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 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
+ /**
+ * Which agents carry a READABLE session name. **Optional, and you almost certainly want the
+ * default** (`supportsTitleRead` below) — it is the rule, not a shell's opinion of it.
+ *
+ * It lives here because the two shells were passing the same predicate and a wrong one is
+ * INVISIBLE: swap it for `canRename` and every gemini node is skipped, so the agent-status
+ * mirror (and the phone reading it) never sees a gemini session name — with a green test suite,
+ * since nothing exercises a shell's wiring. That is the same duplicated-gate drift this branch
+ * has already paid for three times (the remote installer's event lists, the grok raw-listener
+ * block, this). Still injectable: the unit tests narrow it, and a caller with a genuinely
+ * different set can pass its own.
+ */
+ supports?: (agentId?: string) => boolean
}
/**
@@ -51,8 +71,9 @@ export interface SessionNameSweepDeps {
*/
export async function sweepSessionNames(deps: SessionNameSweepDeps): Promise<number> {
let changed = 0
+ const supports = deps.supports ?? supportsTitleRead
for (const e of deps.entries()) {
- if (!e.sessionId || !deps.supports(e.agentId)) continue
+ if (!e.sessionId || !supports(e.agentId)) continue
// A hand-renamed node keeps its name — the same rule the canvas poll applies (`titleAuto`).
const node = deps.node(e.nodeId)
if (node?.titleAuto === false) continue
diff --git a/src/main/index.ts b/src/main/index.ts
index 99e761ff6..2356efca5 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -1,7 +1,6 @@
import { join, resolve, posix } from 'path'
import { startSessionNameSweep, displayNodeTitle } from '../core/session-name-sweep'
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'
@@ -560,13 +559,20 @@ app.whenReady().then(async () => {
)
// 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".
+ // scans for it). That tail is created ~600 lines below with the rest of the hook plumbing, while
+ // this deps object is consumed by the ptyReadSessionName handler just under here and by the
+ // session-name sweep further down — so the association is held in a `let` that the tail's
+ // creation assigns, NOT closed over as a `const` declared later. The difference matters: closing
+ // over the later `const` makes an early call a TDZ **ReferenceError**, and `TerminalNode`'s poll
+ // does not catch its `readSessionName` rejection — one throw kills that node's poll chain for the
+ // whole mount. A poll CAN fire early: `sessionId` is persisted in localStorage, so a cold
+ // relaunch has one before any hook arrives. Undefined-until-assigned degrades instead: no path,
+ // no name, next tick tries again. `pathFor` likewise answers undefined for a session no hook has
+ // been seen for and for a remote (SSH) gemini node, which the tails deliberately never track —
+ // all of which mean "no name", never a throw.
+ let geminiTranscriptPathFor: ((sessionId: string) => string | undefined) | undefined
const agentSessionNameDeps: AgentSessionNameDeps = {
- geminiPathFor: (sessionId) => geminiContextTail.pathFor(sessionId)
+ geminiPathFor: (sessionId) => geminiTranscriptPathFor?.(sessionId)
}
// The reader is selected by the NODE's agent (core/agent-session-name.ts — the one copy of that
@@ -885,10 +891,11 @@ app.whenReady().then(async () => {
// minute for an id that can never be there.
resolve: (sessionId, accountId, agentId) =>
readAgentSessionName(sessionId, accountId, agentId, agentSessionNameDeps),
- publish: setNodeSessionName,
- // 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)
+ publish: setNodeSessionName
+ // `supports` is deliberately NOT passed: the rule (TITLE_READ_CAPABLE, since the sweep only
+ // READS a name) is core's default, `supportsTitleRead`. A copy here would be a second place to
+ // get it wrong, and getting it wrong is invisible — the wrong list silently skips an agent's
+ // nodes with every test still green.
})
// 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.
@@ -1169,6 +1176,9 @@ app.whenReady().then(async () => {
// onTaskNotification/onToolResult: both are claude transcript features (subagent cards, the
// declined-ask rescue), and neither agent is in SUBAGENT_CAPABLE.
const geminiContextTail = createContextTail(pushContextUpdate, { parse: geminiContextParse })
+ // Hand the gemini session-name reader its path authority (declared above the handlers that use
+ // it, assigned here where the tail exists).
+ geminiTranscriptPathFor = (sessionId) => geminiContextTail.pathFor(sessionId)
const codexContextTail = createContextTail(pushContextUpdate, { parse: codexContextParse })
// Remote (SSH-project) counterparts: a node whose pty runs on a remote host has its Claude
// transcript on that host, so its meter / subagent transcript / search must read over the
diff --git a/src/server/index.ts b/src/server/index.ts
index 2fe7d4d46..fd950867e 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -1,7 +1,6 @@
import fs from 'fs'
import { readAgentSessionName } from '../core/agent-session-name'
import { startSessionNameSweep, displayNodeTitle } from '../core/session-name-sweep'
-import { canReadTitle, type AgentId } from '@shared/agents/config'
import path from 'path'
import http from 'http'
@@ -267,10 +266,9 @@ export async function startServer(
readAgentSessionName(sessionId, accountId, agentId, {
geminiPathFor: (id) => geminiContextTail.pathFor(id)
}),
- publish: setNodeSessionName,
- // 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)
+ publish: setNodeSessionName
+ // No `supports`: core's `supportsTitleRead` (TITLE_READ_CAPABLE) is the rule, and duplicating
+ // it here is how the two shells drift — see the note in core/session-name-sweep.ts.
})
// 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