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(push): send the node's display title so alerts lead with it

enes082ad0f75104
diff --git a/src/core/push-notify.test.ts b/src/core/push-notify.test.ts
index bedbf1c47..c94ef6cf4 100644
--- a/src/core/push-notify.test.ts
+++ b/src/core/push-notify.test.ts
@@ -53,6 +53,7 @@ function baseDeps(over: Partial<PushNotifyDeps> = {}): PushNotifyDeps {
mobilePushNeedsYou: () => true,
mobilePushDone: () => true,
isPackaged: () => true,
+ getNodeTitle: () => undefined,
env: {},
fetchImpl: fetchMock as unknown as typeof fetch,
now: () => clock,
@@ -341,6 +342,64 @@ describe('createPushNotify', () => {
})
})
+ describe('nodeTitle enrichment', () => {
+ it('includes nodeTitle when the accessor resolves one', async () => {
+ const em = makeEmitter()
+ const h = createPushNotify(
+ baseDeps({ subscribe: em.subscribe, getNodeTitle: (id) => (id === 'a' ? 'Backend server' : undefined) })
+ )
+ em.emit(iev({ nodeId: 'a' }))
+ await vi.advanceTimersByTimeAsync(2000)
+ expect(bodyOf().events[0].nodeTitle).toBe('Backend server')
+ h.stop()
+ })
+
+ it('omits nodeTitle when the accessor returns undefined', async () => {
+ const em = makeEmitter()
+ const h = createPushNotify(baseDeps({ subscribe: em.subscribe, getNodeTitle: () => undefined }))
+ em.emit(iev({ nodeId: 'a' }))
+ await vi.advanceTimersByTimeAsync(2000)
+ expect(bodyOf().events[0]).not.toHaveProperty('nodeTitle')
+ h.stop()
+ })
+
+ it('omits nodeTitle when no accessor is wired at all', async () => {
+ const em = makeEmitter()
+ const h = createPushNotify(baseDeps({ subscribe: em.subscribe, getNodeTitle: undefined }))
+ em.emit(iev({ nodeId: 'a' }))
+ await vi.advanceTimersByTimeAsync(2000)
+ expect(bodyOf().events[0]).not.toHaveProperty('nodeTitle')
+ h.stop()
+ })
+
+ it('clips nodeTitle to 80 chars', async () => {
+ const em = makeEmitter()
+ const long = 'x'.repeat(200)
+ const h = createPushNotify(baseDeps({ subscribe: em.subscribe, getNodeTitle: () => long }))
+ em.emit(iev({ nodeId: 'a' }))
+ await vi.advanceTimersByTimeAsync(2000)
+ expect(bodyOf().events[0].nodeTitle).toBe('x'.repeat(80))
+ h.stop()
+ })
+
+ it('omits nodeTitle when the accessor throws (fail-open)', async () => {
+ const em = makeEmitter()
+ const h = createPushNotify(
+ baseDeps({
+ subscribe: em.subscribe,
+ getNodeTitle: () => {
+ throw new Error('boom')
+ }
+ })
+ )
+ em.emit(iev({ nodeId: 'a' }))
+ await vi.advanceTimersByTimeAsync(2000)
+ expect(fetchMock).toHaveBeenCalledTimes(1)
+ expect(bodyOf().events[0]).not.toHaveProperty('nodeTitle')
+ h.stop()
+ })
+ })
+
it('stop() unsubscribes so later events are ignored', async () => {
const em = makeEmitter()
const h = createPushNotify(baseDeps({ subscribe: em.subscribe }))
diff --git a/src/core/push-notify.ts b/src/core/push-notify.ts
index 215dda6ed..ac82281d6 100644
--- a/src/core/push-notify.ts
+++ b/src/core/push-notify.ts
@@ -23,6 +23,9 @@ const DEFAULT_THROTTLE_MS = 5000
// Max events per POST (backend contract: events[≤10]).
const MAX_EVENTS_PER_CALL = 10
const FETCH_TIMEOUT_MS = 8000
+// Backend contract cap for the optional per-event `nodeTitle` (the node's canvas/sidebar name,
+// rendered into the alert title as "<Needs you|Completed> — <nodeTitle>").
+const NODE_TITLE_MAX = 80
/** The standing relay host's identity, needed for the backend's (hostDeviceId, hostId-from-pubkey)
* auth. `hasPairedPhone` is what makes the service live at all — no paired phone ⇒ nowhere to fan
@@ -42,6 +45,10 @@ export interface PushNotifyEvent {
detail?: string
nodeId: string
agentId?: string
+ /** The node's human display title (canvas header / sessions sidebar name), clipped to 80 chars.
+ * Optional: the backend renders the alert title as "<Needs you|Completed> — <nodeTitle>" when
+ * present, and falls back to a generic title when absent. */
+ nodeTitle?: string
ts: number
}
@@ -58,6 +65,10 @@ export interface PushNotifyDeps {
mobilePushDone: () => boolean
/** `app.isPackaged` — dev never hits the prod API unless a local base is targeted. */
isPackaged: () => boolean
+ /** Resolve a node's human display title (canvas/sidebar name) for the push `nodeTitle`. In
+ * production this is `workspaceStore.getNodeTitle`. Optional / may return undefined — the field
+ * is then simply omitted from the payload. */
+ getNodeTitle?: (nodeId: string) => string | undefined
/** Override base URL. Defaults to `env.NODETERM_API_BASE || 'https://api.nodeterm.dev'`. */
apiBase?: string
/** Injectable env (DNT guards + local-dev base). Defaults to `process.env`. */
@@ -141,12 +152,20 @@ export function createPushNotify(deps: PushNotifyDeps): PushNotifyHandle {
// throttle). Recorded at accept time — a declined event costs no throttle window.
if (t - (lastPushAt.get(e.nodeId) ?? -Infinity) < throttleMs) return
lastPushAt.set(e.nodeId, t)
+ // Resolve the node's display title (fail-open: a throwing/absent accessor omits the field).
+ let nodeTitle: string | undefined
+ try {
+ nodeTitle = deps.getNodeTitle?.(e.nodeId)?.slice(0, NODE_TITLE_MAX) || undefined
+ } catch {
+ nodeTitle = undefined
+ }
buffer.push({
kind: e.kind,
title: e.title,
...(e.detail ? { detail: e.detail } : {}),
nodeId: e.nodeId,
...(e.agentId ? { agentId: e.agentId } : {}),
+ ...(nodeTitle ? { nodeTitle } : {}),
ts: e.ts
})
scheduleFlush()
diff --git a/src/core/workspace-store.ts b/src/core/workspace-store.ts
index 7af79db19..aaec252ff 100644
--- a/src/core/workspace-store.ts
+++ b/src/core/workspace-store.ts
@@ -4,7 +4,7 @@ import { IPC } from '../shared/ipc'
import { platform } from './platform'
import {
DEFAULT_PROJECT_ID, EMPTY_WORKSPACE,
- type Project, type Workspace, type WorkspaceV1
+ type CanvasNodeState, type Project, type Workspace, type WorkspaceV1
} from '../shared/types'
import {
PROJECT_DIR, PROJECT_FILE, fileToProject, projectToFile, sameProjectContent,
@@ -383,6 +383,48 @@ export class WorkspaceStore {
return new Set((e?.cache?.nodes ?? []).map((n) => n.id))
}
+ /**
+ * Resolve a node's human display title (what the canvas header / sessions sidebar shows) from the
+ * last-persisted workspace, across all three entry kinds: inline canvases (`e.project.nodes`), ssh
+ * caches (`e.cache.nodes`), and local folder refs (the last content we wrote to their
+ * `project.json`, held in `lastWritten`). Sync + in-memory (no disk read). Returns undefined when
+ * the node isn't found or carries no non-empty title.
+ *
+ * Chosen as the mobile-push `nodeTitle` source (over the agent-status mirror) because:
+ * - the mirror's `sessionTitle` field is declared but NEVER emitted by any normalizer — recording
+ * it would record nothing;
+ * - the OS-notification title is formatted in the RENDERER and reaches main already-composed
+ * (`app:notify`), so main keeps no nodeId→title map of its own;
+ * - the persisted node title here is the exact canvas/sidebar name and is refreshed on every
+ * debounced save (which commits the ACTIVE project's live nodes first — see Canvas `persist()`),
+ * so it lags a rename only by the save debounce. Freshness caveat: a brand-new node not yet
+ * saved, or a rename inside that debounce window, resolves to undefined and the field is simply
+ * omitted — acceptable for an optional alert-title enrichment.
+ */
+ getNodeTitle(nodeId: string): string | 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) {
+ const title = node.title?.trim()
+ return title ? title : undefined
+ }
+ }
+ return undefined
+ }
+
/** A throttled trailing mirror write was acked but later dropped (connection died inside the
* throttle window): re-owe it so the next save retries. Wired from makeRemoteWorkspaceIO. */
markUnmirrored(projectId: string): void {
diff --git a/src/main/index.ts b/src/main/index.ts
index a8536471c..a12268399 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -767,7 +767,10 @@ app.whenReady().then(async () => {
mobilePushEnabled: () => settingsStore.get().mobilePushEnabled !== false,
mobilePushNeedsYou: () => settingsStore.get().mobilePushNeedsYou !== false,
mobilePushDone: () => settingsStore.get().mobilePushDone !== false,
- isPackaged: () => app.isPackaged
+ isPackaged: () => app.isPackaged,
+ // The node's canvas/sidebar display title, so the phone can title the alert
+ // "<Needs you|Completed> — <nodeTitle>" (see workspace-store.getNodeTitle for the freshness note).
+ getNodeTitle: (nodeId) => workspaceStore.getNodeTitle(nodeId)
})
// And push each connected SSH project's slice of it onto its host
// (`~/.nodeterm/agent-status-<projectId>.json`): hook events tunnel from the host to THIS