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(canvas-control): one-shot idle-gated discovery note per agent session

enesda14801395e5
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 90b9257b5..f8d691c28 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -157,7 +157,7 @@ import {
reconnectRelayTab,
type RelayTab,
} from '../session/relay-tab'
-import { buildBackgroundLinkMaps, buildContextLinkNote, buildLinkMap, buildNotePushMessage, classifyLink, type LinkEndpoint } from '../lib/noteLink'
+import { buildBackgroundLinkMaps, buildCanvasControlNote, buildContextLinkNote, buildLinkMap, buildNotePushMessage, classifyLink, shouldPushControlNote, type LinkEndpoint } from '../lib/noteLink'
import { useSettings } from '../state/settings'
import { activePermissionMode } from '../state/permissionMode'
import { useContextWindow } from '../state/contextWindow'
@@ -4847,6 +4847,20 @@ export function Canvas() {
// the turn didn't complete, so it isn't a loop iteration either.
cs.bumpLoop(e.nodeId, e.lastMessage) // count loop iterations + summary (no-op if not looping)
alert('finished', `${agentLabel} finished its turn.`)
+ // First completed turn of a controllable session → one-shot discovery note.
+ // Idle now, so the sendText (which submits) can't interrupt a turn; keyed by
+ // sessionId so a resume never repeats it. See buildCanvasControlNote.
+ const st = cs.byId[e.nodeId]
+ if (
+ shouldPushControlNote({
+ sessionId: st?.sessionId,
+ controlNoted: st?.controlNoted,
+ canControl: canControlCanvas(e.agentId)
+ })
+ ) {
+ cs.setControlNoted(e.nodeId, st!.sessionId!)
+ void api.pty.sendText(e.nodeId, buildCanvasControlNote(e.agentId))
+ }
}
if (e.state === 'blocked') alert('needs input', `${agentLabel} needs permission to continue.`)
else if (e.state === 'waiting') alert('needs input', `${agentLabel} is waiting for your response.`)
diff --git a/src/renderer/lib/noteLink.test.ts b/src/renderer/lib/noteLink.test.ts
index f7b785469..311671bf9 100644
--- a/src/renderer/lib/noteLink.test.ts
+++ b/src/renderer/lib/noteLink.test.ts
@@ -1,10 +1,12 @@
import { describe, it, expect } from 'vitest'
import {
buildBackgroundLinkMaps,
+ buildCanvasControlNote,
buildContextLinkNote,
buildLinkMap,
buildNotePushMessage,
- classifyLink
+ classifyLink,
+ shouldPushControlNote
} from './noteLink'
import type { CanvasNodeState } from '@shared/types'
@@ -127,6 +129,37 @@ describe('buildContextLinkNote', () => {
})
})
+describe('buildCanvasControlNote', () => {
+ it('points claude at the skill and self-defuses', () => {
+ const msg = buildCanvasControlNote('claude')
+ expect(msg).toContain('manage-nodeterm-canvas')
+ expect(msg).toContain('No action needed now')
+ expect(msg).not.toContain('\n') // pty.sendText submits — a newline would split the prompt
+ })
+ it('points codex/gemini at their global instructions section', () => {
+ const msg = buildCanvasControlNote('codex')
+ expect(msg).toContain('manage-nodeterm-canvas')
+ expect(msg).toContain('global agent instructions')
+ expect(msg).not.toContain('\n')
+ })
+})
+
+describe('shouldPushControlNote', () => {
+ it('pushes once per session for a controllable agent', () => {
+ expect(shouldPushControlNote({ sessionId: 's1', canControl: true })).toBe(true)
+ })
+ it('never re-pushes the same session', () => {
+ expect(shouldPushControlNote({ sessionId: 's1', controlNoted: 's1', canControl: true })).toBe(false)
+ })
+ it('pushes again for a NEW session of the same node', () => {
+ expect(shouldPushControlNote({ sessionId: 's2', controlNoted: 's1', canControl: true })).toBe(true)
+ })
+ it('skips non-controllable agents and unknown sessions', () => {
+ expect(shouldPushControlNote({ sessionId: 's1', canControl: false })).toBe(false)
+ expect(shouldPushControlNote({ canControl: true })).toBe(false)
+ })
+})
+
describe('buildBackgroundLinkMaps', () => {
const node = (over: Partial<CanvasNodeState>): CanvasNodeState =>
({
diff --git a/src/renderer/lib/noteLink.ts b/src/renderer/lib/noteLink.ts
index 020b8162c..a2b5604e9 100644
--- a/src/renderer/lib/noteLink.ts
+++ b/src/renderer/lib/noteLink.ts
@@ -63,6 +63,30 @@ export function buildContextLinkNote(
return `[nodeterm] You are now linked to "${otherTitle}". When you need its context (and only then) run: sh "${shimPath}" list — then summary | transcript | terminal --node <id>. Details are in the get-linked-context section of your global agent instructions. No action needed now — acknowledge briefly and do not run these commands yet.`
}
+/** One-shot discovery note: tells a canvas-controllable agent it can drive the canvas.
+ * Pushed on the session's FIRST completed turn (the node is idle then — pty.sendText
+ * appends Enter, so a mid-turn push would interrupt), once per sessionId. Model-agnostic
+ * on purpose: skill auto-triggering is Claude-Code behavior an alternative backend (GLM
+ * et al.) may never exercise, so the session is told directly. Same self-defusing tail
+ * as buildContextLinkNote — an agent that reads this as a task starts an unsolicited
+ * canvas reorganization. */
+export function buildCanvasControlNote(agentId: string | undefined): string {
+ if (!agentId || agentId === 'claude') {
+ return `[nodeterm] This session can control the nodeterm canvas: open agent/terminal nodes, spawn a team that divides up a task, create worktree groups, organize nodes. Use the manage-nodeterm-canvas skill when asked to parallelize, delegate or organize work. No action needed now — just acknowledge briefly.`
+ }
+ return `[nodeterm] This session can control the nodeterm canvas: open agent/terminal nodes, spawn a team that divides up a task, group and arrange nodes. See the "Managing the nodeterm canvas (manage-nodeterm-canvas)" section of your global agent instructions for the CLI. No action needed now — acknowledge briefly.`
+}
+
+/** Gate for the discovery push: controllable agent, session known, not yet noted for THIS
+ * session (a resumed session keeps its id → no re-push; a fresh session gets one). */
+export function shouldPushControlNote(s: {
+ sessionId?: string
+ controlNoted?: string
+ canControl: boolean
+}): boolean {
+ return s.canControl && !!s.sessionId && s.controlNoted !== s.sessionId
+}
+
export interface LinkNodeInfo {
id: string
title: string
diff --git a/src/renderer/state/agentStatus.persist.test.ts b/src/renderer/state/agentStatus.persist.test.ts
index 997f6bb8e..7af39dc91 100644
--- a/src/renderer/state/agentStatus.persist.test.ts
+++ b/src/renderer/state/agentStatus.persist.test.ts
@@ -48,6 +48,19 @@ describe('loop persistence (cron/schedule survive an app restart)', () => {
})
})
+ it('round-trips controlNoted (canvas-control discovery, once per session)', async () => {
+ const store = memStorage()
+ vi.stubGlobal('localStorage', store)
+ const { useAgentStatus } = await import('./agentStatus')
+ useAgentStatus.getState().setControlNoted('n4', 'sess-1')
+ const saved = JSON.parse(store.getItem('nodeterm.agentStatus')!)
+ expect(saved.n4.controlNoted).toBe('sess-1')
+ // A fresh module load restores it, so a restart never re-pushes the note.
+ vi.resetModules()
+ const reloaded = await import('./agentStatus')
+ expect(reloaded.useAgentStatus.getState().byId['n4']?.controlNoted).toBe('sess-1')
+ })
+
it('tolerates a persisted entry without loop (older format)', async () => {
vi.stubGlobal(
'localStorage',
diff --git a/src/renderer/state/agentStatus.ts b/src/renderer/state/agentStatus.ts
index 1d1de16d5..911a7ce58 100644
--- a/src/renderer/state/agentStatus.ts
+++ b/src/renderer/state/agentStatus.ts
@@ -45,6 +45,8 @@ export interface AgentNodeStatus {
session?: string
/** Claude session id (from hooks) — used to resume/branch the conversation. */
sessionId?: string
+ /** SessionId the one-shot canvas-control discovery note was already pushed for. */
+ controlNoted?: string
/** Set when running /loop, /schedule or /cron (heuristic); shown as a connected node. */
loop?: {
count: number
@@ -69,6 +71,8 @@ export interface AgentStatusStore {
sweepStaleWorking(staleMs?: number): void
setSession(id: string, session: string): void
setSessionId(id: string, sessionId: string): void
+ /** Record that the canvas-control discovery note went out for this session. */
+ setControlNoted(id: string, sessionId: string): void
markUnread(id: string): void
clearUnread(id: string): void
/** Start (active=true, resets) or stop a /loop, /schedule or /cron indicator. */
@@ -145,7 +149,12 @@ export function createAgentStatusSession(persistKey?: string): AgentStatusSessio
const data = JSON.parse(raw) as Record<string, Partial<AgentNodeStatus>>
const out: Record<string, AgentNodeStatus> = {}
for (const [id, v] of Object.entries(data)) {
- out[id] = { unread: !!v.unread, session: v.session, sessionId: v.sessionId }
+ out[id] = {
+ unread: !!v.unread,
+ session: v.session,
+ sessionId: v.sessionId,
+ controlNoted: v.controlNoted
+ }
// A recurring job (cron/schedule — and tmux keeps in-session loops alive too) outlives
// the app: restore its card. Minimal shape check so a corrupt entry can't break load.
if (v.loop && typeof v.loop === 'object' && v.loop.kind) {
@@ -170,8 +179,14 @@ export function createAgentStatusSession(persistKey?: string): AgentStatusSessio
try {
const out: Record<string, Partial<AgentNodeStatus>> = {}
for (const [id, v] of Object.entries(byId)) {
- if (v.unread || v.session || v.sessionId || v.loop) {
- out[id] = { unread: v.unread, session: v.session, sessionId: v.sessionId, loop: v.loop }
+ if (v.unread || v.session || v.sessionId || v.loop || v.controlNoted) {
+ out[id] = {
+ unread: v.unread,
+ session: v.session,
+ sessionId: v.sessionId,
+ loop: v.loop,
+ controlNoted: v.controlNoted
+ }
}
}
localStorage.setItem(persistKey, JSON.stringify(out))
@@ -248,6 +263,15 @@ export function createAgentStatusSession(persistKey?: string): AgentStatusSessio
return { byId }
}),
+ setControlNoted: (id, sessionId) =>
+ set((s) => {
+ const prev = s.byId[id] ?? EMPTY
+ if (prev.controlNoted === sessionId) return s
+ const byId = { ...s.byId, [id]: { ...prev, controlNoted: sessionId } }
+ save(byId)
+ return { byId }
+ }),
+
markUnread: (id) =>
set((s) => {
const prev = s.byId[id] ?? EMPTY