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
feat(agent-status): publish the agent's session name host-side, so every reader sees a /rename
enesc54366fafc56
diff --git a/src/core/agent-status-mirror.ts b/src/core/agent-status-mirror.tsindex 99f9c41a3..d5eb5dae0 100644--- a/src/core/agent-status-mirror.ts+++ b/src/core/agent-status-mirror.ts@@ -40,6 +40,10 @@ export interface MirrorEntry {state?: AgentStateagentId?: AgentIdsessionId?: string+ /** The agent's own session name (the `/rename` name, read from its transcript) — published by+ * the session-name sweep so a reader with no canvas (the phone) sees the CURRENT name, not+ * whatever the node title was when it was last open. Absent until resolved. */+ name?: string/*** When the state was last asserted (freshness). Drives the done-holdoff and the expiry* sweep — refreshed by every state/session reduction (incl. same-state working from tool@@ -75,7 +79,17 @@ export interface MirrorSettings {export interface MirrorFile {v: 1updatedAt: number- nodes: Record<string, { state?: AgentState; agentId?: AgentId; sessionId?: string; updatedAt: number }>+ nodes: Record<+ string,+ {+ state?: AgentState+ agentId?: AgentId+ sessionId?: string+ /** The agent's own session name (see MirrorEntry.name). Absent until resolved. */+ name?: string+ updatedAt: number+ }+ >/** Host-level launch settings (permission mode, managed accounts). Additive/optional: absent* on old files and whenever no settings provider is wired — the file shape is then byte-for-byte* identical to before this block existed. */@@ -364,7 +378,13 @@ export function buildFile(if (now - e.updatedAt > expireMs) continue// Undefined fields drop out of JSON.stringify — an idle node keeps agentId/sessionId// without a `state` key.- out.nodes[id] = { state: e.state, agentId: e.agentId, sessionId: e.sessionId, updatedAt: e.updatedAt }+ out.nodes[id] = {+ state: e.state,+ agentId: e.agentId,+ sessionId: e.sessionId,+ ...(e.name ? { name: e.name } : {}),+ updatedAt: e.updatedAt+ }}if (settings) out.settings = settingsif (usage) out.usage = usage@@ -943,7 +963,13 @@ function loadPersisted(file: string): void {if (!e || typeof e !== 'object') continueconst updatedAt = typeof e.updatedAt === 'number' ? e.updatedAt : 0if (now - updatedAt > EXPIRE_MS) continue- state.set(id, { state: e.state, agentId: e.agentId, sessionId: e.sessionId, updatedAt })+ state.set(id, {+ state: e.state,+ agentId: e.agentId,+ sessionId: e.sessionId,+ ...(e.name ? { name: e.name } : {}),+ updatedAt+ })}}// Inbox feed — restore verbatim (already capped + carries `resolved` flags) so the@@ -1324,6 +1350,35 @@ export function clearNode(nodeId: string): void {* working-state focus that slipped the renderer gate — fires no seam and schedules no write). Pure* apart from the seam + write; `now` is Date.now for parity with the rest of the module.*/+/**+ * Publish a node's resolved session name into the mirror (the session-name sweep's only writer).+ * A no-op when nothing changed or the node is unknown — the sweep asks for the entries first, so+ * an unknown id here just means it went away mid-pass. Never touches `updatedAt`: this is not a+ * state assertion, and bumping it would defeat the freshness/expiry rules.+ */+export function setNodeSessionName(nodeId: string, name: string): boolean {+ const e = state.get(nodeId)+ if (!e || !name || e.name === name) return false+ state.set(nodeId, { ...e, name })+ scheduleWrite()+ return true+}++/** The entries the session-name sweep walks: id + what it needs to resolve and dedupe. */+export function sessionNameSweepEntries(): {+ nodeId: string+ sessionId?: string+ agentId?: string+ name?: string+}[] {+ return [...state].map(([nodeId, e]) => ({+ nodeId,+ sessionId: e.sessionId,+ agentId: e.agentId,+ name: e.name+ }))+}+export function ackDone(nodeId: string): void {if (!nodeId) returnlet latest: InboxEvent | undefineddiff --git a/src/core/session-name-sweep.test.ts b/src/core/session-name-sweep.test.tsnew file mode 100644index 000000000..9c5586358--- /dev/null+++ b/src/core/session-name-sweep.test.ts@@ -0,0 +1,89 @@+import { describe, it, expect, vi } from 'vitest'+import { sweepSessionNames, type SweepEntry } from './session-name-sweep'++function deps(+ entries: SweepEntry[],+ opts: {+ names?: Record<string, string | null>+ nodes?: Record<string, { accountId?: string; titleAuto?: boolean }>+ throwFor?: string+ } = {}+) {+ const published: [string, string][] = []+ const resolve = vi.fn(async (sessionId: string) => {+ if (opts.throwFor === sessionId) throw new Error('transient')+ return opts.names?.[sessionId] ?? null+ })+ return {+ published,+ resolve,+ d: {+ entries: () => entries,+ node: (id: string) => opts.nodes?.[id],+ resolve,+ publish: (nodeId: string, name: string) => published.push([nodeId, name]),+ supports: (agentId?: string) => agentId === 'claude'+ }+ }+}++describe('sweepSessionNames', () => {+ it('publishes a changed name for a node no canvas has mounted', async () => {+ const { d, published } = deps([{ nodeId: 'n1', sessionId: 's1', agentId: 'claude', name: 'old' }], {+ names: { s1: 'mac-release-rerun-notarization' }+ })+ expect(await sweepSessionNames(d)).toBe(1)+ expect(published).toEqual([['n1', 'mac-release-rerun-notarization']])+ })++ it('writes nothing when the name is unchanged or unresolvable', async () => {+ const { d, published } = deps(+ [+ { nodeId: 'same', sessionId: 's1', agentId: 'claude', name: 'Ship it' },+ { nodeId: 'unknown', sessionId: 's2', agentId: 'claude' }+ ],+ { names: { s1: 'Ship it', s2: null } }+ )+ expect(await sweepSessionNames(d)).toBe(0)+ expect(published).toEqual([])+ })++ it('leaves a hand-renamed node alone (titleAuto false)', async () => {+ const { d, published } = deps([{ nodeId: 'n1', sessionId: 's1', agentId: 'claude' }], {+ names: { s1: 'the session name' },+ nodes: { n1: { titleAuto: false } }+ })+ expect(await sweepSessionNames(d)).toBe(0)+ expect(published).toEqual([])+ })++ it('skips agents that have no session name, and nodes with no session', async () => {+ const { d, resolve } = deps([+ { nodeId: 'codex', sessionId: 's1', agentId: 'codex' },+ { nodeId: 'nosession', agentId: 'claude' }+ ])+ expect(await sweepSessionNames(d)).toBe(0)+ expect(resolve).not.toHaveBeenCalled()+ })++ it('passes the node account through — managed accounts scope the transcript root', async () => {+ const { d, resolve } = deps([{ nodeId: 'n1', sessionId: 's1', agentId: 'claude' }], {+ names: { s1: 'x' },+ nodes: { n1: { accountId: 'acct-2' } }+ })+ await sweepSessionNames(d)+ expect(resolve).toHaveBeenCalledWith('s1', 'acct-2')+ })++ it('one failing read never stops the pass', async () => {+ const { d, published } = deps(+ [+ { nodeId: 'bad', sessionId: 'boom', agentId: 'claude' },+ { nodeId: 'good', sessionId: 's2', agentId: 'claude' }+ ],+ { names: { s2: 'still works' }, throwFor: 'boom' }+ )+ expect(await sweepSessionNames(d)).toBe(1)+ expect(published).toEqual([['good', 'still works']])+ })+})diff --git a/src/core/session-name-sweep.ts b/src/core/session-name-sweep.tsnew file mode 100644index 000000000..3915ca3dd--- /dev/null+++ b/src/core/session-name-sweep.ts@@ -0,0 +1,87 @@+// Keep every agent node's SESSION NAME fresh in the agent-status mirror — including the nodes+// nobody is looking at.+//+// The desktop already syncs an agent's own session name (the `/rename` name, read from the+// transcript) into the node title, but that poll lives in the mounted TerminalNode: it runs only+// for the ACTIVE project's nodes, in a running desktop UI. Every other node keeps whatever name it+// had when it was last open — and the phone lists ALL of them, so a `/rename` simply never reached+// it (field report: "iPhone'da isimler /rename'den sonra güncellenmiyor").+//+// This sweep runs where the mirror is written (desktop main AND the headless Server Edition), so+// the name is correct with no UI open at all. It only PUBLISHES into the mirror — it never touches+// the workspace file, so the canvas's own title behavior is unchanged.+//+// 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.++/** One node the sweep may refresh. */+export interface SweepEntry {+ nodeId: string+ sessionId?: string+ agentId?: string+ /** The last name we published for this node, so an unchanged read costs no write. */+ name?: string+}++export interface SessionNameSweepDeps {+ /** The mirror's current entries. */+ entries: () => SweepEntry[]+ /** The node's persisted record — `accountId` scopes the transcript root; `titleAuto === false`+ * 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+ /** `readSessionName` — resolves the agent's own session name, local or remote. */+ resolve: (sessionId: string, accountId?: 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 today). */+ supports: (agentId?: string) => boolean+}++/**+ * One pass. Returns the number of names published (0 = nothing changed), which is what the caller+ * uses to decide whether to schedule a mirror write. Never throws: a resolver failure for one node+ * must not stop the rest.+ */+export async function sweepSessionNames(deps: SessionNameSweepDeps): Promise<number> {+ let changed = 0+ for (const e of deps.entries()) {+ if (!e.sessionId || !deps.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+ let name: string | null = null+ try {+ name = await deps.resolve(e.sessionId, node?.accountId)+ } catch {+ continue // transient read failure — try again next pass+ }+ if (!name || name === e.name) continue+ deps.publish(e.nodeId, name)+ changed+++ }+ return changed+}++/** How often the sweep runs. A session is named once early and renamed rarely; this is a+ * background correctness pass, not a live feed (the mounted node still polls at 4s/15s). */+export const SESSION_NAME_SWEEP_MS = 60_000++/** Start the periodic sweep. Returns a stop function; the timer is unref'd (never holds the app). */+export function startSessionNameSweep(+ deps: SessionNameSweepDeps & { onChanged?: () => void; intervalMs?: number }+): () => void {+ const run = (): void => {+ void sweepSessionNames(deps).then((n) => {+ if (n > 0) deps.onChanged?.()+ })+ }+ const timer = setInterval(run, deps.intervalMs ?? SESSION_NAME_SWEEP_MS)+ timer.unref?.()+ // One pass shortly after boot, so a restart doesn't wait a whole interval to correct itself.+ const first = setTimeout(run, 5_000)+ first.unref?.()+ return () => {+ clearInterval(timer)+ clearTimeout(first)+ }+}diff --git a/src/core/workspace-store.ts b/src/core/workspace-store.tsindex 219fa6a18..cdf86ec0e 100644--- a/src/core/workspace-store.ts+++ b/src/core/workspace-store.ts@@ -424,6 +424,33 @@ export class WorkspaceStore {* saved, or a rename inside that debounce window, resolves to undefined and the field is simply* omitted — acceptable for an optional alert-title enrichment.*/+ /**+ * The persisted node record for a node id (first project that has it), or undefined. The+ * session-name sweep needs more than the title — `accountId` (managed Claude accounts scope the+ * transcript root) and `titleAuto` (a hand-renamed node must not be overwritten). Same scan as+ * `getNodeTitle`, which now delegates here.+ */+ getNode(nodeId: string): CanvasNodeState | undefined {+ for (const e of this.index?.entries ?? []) {+ let nodes: CanvasNodeState[] | undefined+ if (e.project) nodes = e.project.nodes+ else if (e.cache) nodes = e.cache.nodes+ else if (e.cwd) {+ const raw = this.lastWritten.get(projectFilePath(e.cwd))+ if (raw) {+ try {+ nodes = (JSON.parse(raw) as ProjectFileV1).nodes+ } catch {+ // Corrupt cached content: skip this entry, keep scanning the others.+ }+ }+ }+ const node = nodes?.find((n) => n.id === nodeId)+ if (node) return node+ }+ return undefined+ }+getNodeTitle(nodeId: string): string | undefined {for (const e of this.index?.entries ?? []) {let nodes: CanvasNodeState[] | undefineddiff --git a/src/main/index.ts b/src/main/index.tsindex bd8bfa342..8ef8f2857 100644--- a/src/main/index.ts+++ b/src/main/index.ts@@ -1,4 +1,7 @@import { join, resolve, posix } from 'path'+import { startSessionNameSweep } from '../core/session-name-sweep'+import { readSessionName as readSessionNameForSweep } from '../core/transcript-reader'+import { canRename, type AgentId } from '@shared/agents/config'import { readFile } from 'fs/promises'import { homedir, hostname } from 'os'import { randomUUID } from 'crypto'@@ -50,7 +53,9 @@ import {onNodeStateChange,onNodeNowChange,isEventUnresolved,- type MirrorSettings+ type MirrorSettings,+ setNodeSessionName,+ sessionNameSweepEntries} from '../core/agent-status-mirror'import { createPushNotify, createLiveUpdatePush } from '../core/push-notify'import { createGrantsAccessor } from '../core/push-grants'@@ -764,6 +769,19 @@ app.whenReady().then(async () => {})// Mirror live agent status to <userData>/agent-status.json for the external mobile host agent.initAgentStatusMirror()++ // Keep every agent node's session name fresh in the mirror — including nodes no canvas has+ // mounted (the phone lists them all; see core/session-name-sweep.ts).+ startSessionNameSweep({+ entries: sessionNameSweepEntries,+ node: (nodeId) => {+ const n = workspaceStore.getNode(nodeId)+ return n ? { accountId: n.accountId, titleAuto: n.titleAuto } : undefined+ },+ resolve: (sessionId, accountId) => readSessionNameForSweep(sessionId, accountId),+ publish: setNodeSessionName,+ supports: (agentId) => !!agentId && canRename(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/server/index.ts b/src/server/index.tsindex 9aa6b1711..0b2d9c4da 100644--- a/src/server/index.ts+++ b/src/server/index.ts@@ -1,4 +1,7 @@import fs from 'fs'+import { readSessionName } from '../core/transcript-reader'+import { startSessionNameSweep } from '../core/session-name-sweep'+import { canRename, type AgentId } from '@shared/agents/config'import path from 'path'import http from 'http'@@ -36,7 +39,9 @@ import {onNodeStateChange,onNodeNowChange,type MirrorSettings,- type MirrorServer+ type MirrorServer,+ setNodeSessionName,+ sessionNameSweepEntries} from '../core/agent-status-mirror'import { createPushNotify, createLiveUpdatePush } from '../core/push-notify'import { createGrantsAccessor } from '../core/push-grants'@@ -225,6 +230,19 @@ export async function startServer(// scripts → start the loopback hook server. The hook server binds its own port independent of// the main HTTP server below.initAgentStatusMirror()++ // Keep every agent node's session name fresh in the mirror — including nodes no canvas has+ // mounted (the phone lists them all; see core/session-name-sweep.ts).+ startSessionNameSweep({+ entries: sessionNameSweepEntries,+ node: (nodeId) => {+ const n = workspaceStore.getNode(nodeId)+ return n ? { accountId: n.accountId, titleAuto: n.titleAuto } : undefined+ },+ resolve: (sessionId, accountId) => readSessionName(sessionId, accountId),+ publish: setNodeSessionName,+ supports: (agentId) => !!agentId && canRename(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// provider applies. The provider is consulted at every flush (heartbeat ≤60s), so a settings