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(transcript): resolve session names via the remote reader for ssh nodes

enes3fe642b66088
diff --git a/src/core/transcript-reader.test.ts b/src/core/transcript-reader.test.ts
index 41236c1eb..9d7d3289d 100644
--- a/src/core/transcript-reader.test.ts
+++ b/src/core/transcript-reader.test.ts
@@ -1,5 +1,11 @@
-import { describe, expect, it } from 'vitest'
-import { parseTranscriptLines, pickSessionName } from './transcript-reader'
+import fs from 'fs'
+import { afterEach, describe, expect, it, vi } from 'vitest'
+import {
+ parseTranscriptLines,
+ pickSessionName,
+ readSessionName,
+ setRemoteTranscriptReader
+} from './transcript-reader'
import type { TranscriptLine } from '../shared/types'
describe('pickSessionName', () => {
@@ -60,3 +66,38 @@ describe('parseTranscriptLines', () => {
expect(parseTranscriptLines(text)).toEqual(expected)
})
})
+
+// An SSH project's Claude runs on the remote host, so its transcript .jsonl lives on the remote
+// filesystem — the local scan can never find it. A registered remote reader (wired in main from
+// the hook-fed transcript path) is consulted FIRST, so `/rename` on a remote node reaches the
+// node title exactly like it does locally.
+describe('readSessionName — remote (SSH project) sessions', () => {
+ const sid = '11111111-2222-3333-4444-555555555555'
+ const custom = (t: string) => JSON.stringify({ type: 'custom-title', customTitle: t, sessionId: sid })
+
+ afterEach(() => setRemoteTranscriptReader(null))
+
+ it('reads the name from the remote transcript when the session is remote', async () => {
+ setRemoteTranscriptReader(async (id) =>
+ id === sid ? { text: [custom('Ship the relay fix')].join('\n') } : null
+ )
+ expect(await readSessionName(sid)).toBe('Ship the relay fix')
+ })
+
+ // A remote session is never in the local ~/.claude/projects, so scanning it is pure waste —
+ // and today's poll does exactly that every 4s, forever, for every SSH agent node.
+ it('does not scan the local transcript root for a known remote session', async () => {
+ const readdir = vi.spyOn(fs.promises, 'readdir')
+ setRemoteTranscriptReader(async () => ({ text: '' }))
+ expect(await readSessionName(sid)).toBeNull()
+ expect(readdir).not.toHaveBeenCalled()
+ readdir.mockRestore()
+ })
+
+ it('falls through to the local reader when the session is not remote', async () => {
+ setRemoteTranscriptReader(async () => null)
+ // No local transcript for this id either — the point is that it did not throw and the
+ // remote branch declined, leaving today's local behavior intact.
+ expect(await readSessionName(sid)).toBeNull()
+ })
+})
diff --git a/src/core/transcript-reader.ts b/src/core/transcript-reader.ts
index 29d84ab5f..c908dfd95 100644
--- a/src/core/transcript-reader.ts
+++ b/src/core/transcript-reader.ts
@@ -288,12 +288,35 @@ export function pickSessionName(text: string): string | null {
// title. Resolved STRICTLY by sessionId: the cwd is intentionally not a fallback here, because
// multiple Claude nodes in one folder would all resolve to the same newest transcript and adopt
// each other's names. Returns null until the node's own sessionId is known.
-const TITLE_TAIL_BYTES = 128 * 1024
+export const TITLE_TAIL_BYTES = 128 * 1024
+
+// An SSH project's agent runs on the REMOTE host, so its transcript lives on the remote
+// filesystem — `transcriptRoot()` is this machine's `$HOME` and can never resolve it. Main
+// registers a reader here (backed by the hook-fed remote transcript path + the project's
+// ControlMaster), mirroring the `setGitRemoteResolver` registry in remote-git.ts, so the reader
+// stays electron-free and this module keeps its signature. Returns null when `sessionId` is not
+// a live remote session, which is the signal to use the local path.
+export interface RemoteTranscriptTail {
+ text: string
+}
+let remoteReader: ((sessionId: string) => Promise<RemoteTranscriptTail | null>) | null = null
+export function setRemoteTranscriptReader(
+ fn: ((sessionId: string) => Promise<RemoteTranscriptTail | null>) | null
+): void {
+ remoteReader = fn
+}
+
export async function readSessionName(
sessionId: string,
accountId?: string
): Promise<string | null> {
if (!sessionId) return null
+ // Remote first: a remote session is never present under the local transcript root, so falling
+ // through to the local scan would be pure waste (the title poll runs every 4s per agent node).
+ if (remoteReader) {
+ const remote = await remoteReader(sessionId)
+ if (remote) return remote.text ? pickSessionName(remote.text) : null
+ }
// Stale cache entries are healed inside resolveTranscriptPath (access-checked per hit).
const p = await resolveTranscriptPath(sessionId, accountId)
if (!p) return null
diff --git a/src/main/index.ts b/src/main/index.ts
index 5b2fab993..cf074741d 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -26,6 +26,8 @@ import {
readTranscriptLines,
readChatMessages,
readSessionName,
+ setRemoteTranscriptReader,
+ TITLE_TAIL_BYTES,
resolveTranscriptPath,
transcriptPathForCwd,
parseTranscriptLines,
@@ -559,6 +561,16 @@ app.whenReady().then(async () => {
// search/chat read handlers (which receive only sessionId + cwd) read remotely without a
// nodeId. Only remote sessions are ever inserted, so local reads stay on the local reader.
const remoteTranscriptBySession = new Map<string, RemoteFileRef>()
+ // Route the session-name read (the node-title poll) through the same remote ref. An SSH
+ // project's agent runs on the remote host, so its transcript is NOT under the local
+ // `~/.claude/projects` — without this, `/rename` never reached the node title on remote nodes
+ // (and the poll re-scanned the local root every 4s for nothing). Returning null for an unknown
+ // sessionId keeps every local node on the local reader.
+ setRemoteTranscriptReader(async (sessionId) => {
+ const ref = remoteTranscriptBySession.get(sessionId)
+ if (!ref) return null
+ return { text: await remoteFile.readTail(ref, TITLE_TAIL_BYTES) }
+ })
// toolUseIds whose remote subagent file resolution was cancelled (PostToolUse / node close
// arrived before the file appeared) — checked by the async resolver to avoid a late track.
// Bounded by `remoteSubagentResolving`: a cancel flag is only added (and only matters) while a