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): extend canvas control to codex/gemini

enes1115717e7c7c
diff --git a/src/main/canvas-control-core.test.ts b/src/main/canvas-control-core.test.ts
index 7d94d8203..d784e107f 100644
--- a/src/main/canvas-control-core.test.ts
+++ b/src/main/canvas-control-core.test.ts
@@ -1,5 +1,10 @@
import { describe, it, expect } from 'vitest'
-import { parseControlRequest, isDestructiveVerb } from './canvas-control-core'
+import {
+ parseControlRequest,
+ isDestructiveVerb,
+ mergeCanvasControlBlock,
+ buildCanvasControlInstructions
+} from './canvas-control-core'
describe('parseControlRequest', () => {
it('accepts known verbs', () => {
@@ -86,6 +91,28 @@ describe('parseControlRequest', () => {
expect(isDestructiveVerb('rename')).toBe(false)
})
+ it('merges the canvas-control block idempotently, preserving other content', () => {
+ const block = buildCanvasControlInstructions('/tmp/nodeterm.sh')
+ const first = mergeCanvasControlBlock('# My own notes\n', block)
+ expect(first).toContain('# My own notes')
+ expect(first).toContain('nodeterm:manage-canvas:start')
+ expect(first).toContain('/tmp/nodeterm.sh')
+ // Re-merging (e.g. next app launch, updated verbs) replaces the block, not duplicates it.
+ const second = mergeCanvasControlBlock(first, buildCanvasControlInstructions('/new/nodeterm.sh'))
+ expect(second.match(/nodeterm:manage-canvas:start/g)).toHaveLength(1)
+ expect(second).toContain('/new/nodeterm.sh')
+ expect(second).not.toContain('/tmp/nodeterm.sh')
+ expect(second).toContain('# My own notes')
+ })
+
+ it('instructions cover the verb set and the confirm caveat', () => {
+ const body = buildCanvasControlInstructions('/tmp/nodeterm.sh')
+ for (const verb of ['list', 'open-agent', 'spawn-team', 'group', 'arrange', 'rename', 'write', 'close']) {
+ expect(body).toContain(verb)
+ }
+ expect(body.toLowerCase()).toContain('confirm')
+ })
+
it('spawn-team requires --team and none of the layout verbs are destructive', () => {
expect(parseControlRequest('spawn-team', {})).toEqual({ error: 'spawn-team requires --team <json>' })
expect(parseControlRequest('spawn-team', { team: '[]' })).toEqual({ verb: 'spawn-team', args: { team: '[]' } })
diff --git a/src/main/canvas-control-core.ts b/src/main/canvas-control-core.ts
index 0c1d04f7f..b84937655 100644
--- a/src/main/canvas-control-core.ts
+++ b/src/main/canvas-control-core.ts
@@ -78,6 +78,60 @@ export function parseControlRequest(
return { verb: v, args }
}
+// Codex/Gemini have no skill system — canvas-control is announced to them via a
+// marker-delimited block merged into ~/.codex/AGENTS.md / ~/.gemini/GEMINI.md (same
+// pattern as context-link's get-linked-context block, distinct markers).
+const CC_START = '<!-- nodeterm:manage-canvas:start -->'
+const CC_END = '<!-- nodeterm:manage-canvas:end -->'
+
+/** Idempotently merge the canvas-control block into a global instructions file.
+ * Everything outside the markers is preserved; an existing block is replaced. */
+export function mergeCanvasControlBlock(existing: string, block: string): string {
+ const full = `${CC_START}\n${block.trim()}\n${CC_END}`
+ const start = existing.indexOf(CC_START)
+ const end = existing.indexOf(CC_END)
+ if (start >= 0 && end > start) {
+ return existing.slice(0, start) + full + existing.slice(end + CC_END.length)
+ }
+ const sep = existing.trim() ? (existing.endsWith('\n') ? '\n' : '\n\n') : ''
+ return existing + sep + full + '\n'
+}
+
+/** The instructions body telling codex/gemini how to control the nodeterm canvas.
+ * Keep the verb list in sync with the skill template in canvas-control.ts. */
+export function buildCanvasControlInstructions(shimPath: string): string {
+ return [
+ '# Managing the nodeterm canvas (manage-nodeterm-canvas)',
+ '',
+ 'When you run inside a node on the nodeterm canvas, you can create and control other',
+ 'nodes (the CLI refuses outside a nodeterm session — do not retry there). Every node',
+ 'you open is connected to your node by an edge. Use this when the user asks you to open',
+ 'sessions/nodes, split work across agents, organize the canvas into groups, or show them',
+ 'an image/video/web page you produced.',
+ '',
+ '```sh',
+ `sh "${shimPath}" <verb> [args]`,
+ '```',
+ '',
+ 'Verbs:',
+ '- `list` — current nodes (id, kind, title). Start here when you need a node id.',
+ '- `open-terminal [--cwd P] [--cmd C]` — open a terminal node.',
+ '- `open-claude [--count N] [--cwd P] [--prompt T]` — open N Claude sessions.',
+ '- `open-agent --agent claude|codex|gemini|<custom-id> [--count N] [--cwd P] [--prompt T]` — open any agent CLI.',
+ '- `show-image <path>` / `show-video <path>` — open a media file as a node.',
+ '- `show-web (--url U | --file P.html | --html "<...>")` — open a web viewer.',
+ '- `open-browser --url U` — open a navigable browser node.',
+ '- `group --nodes <id,id> [--label L]` / `arrange --nodes <id,id> [--layout grid|row|column] [--cols N]` /',
+ ' `align --nodes <id,id> --edge left|right|top|bottom|hcenter|vcenter` — organize the canvas.',
+ '- `spawn-team --label L --team \'[{"title":"UI","prompt":"...","agent":"claude"}]\'` — one agent per',
+ ' role (max 8), arranged in a grid, wrapped in a labeled group, each connected to you.',
+ '- `branch --node <id>` — branch a Claude node\'s conversation (Claude nodes only).',
+ '- `rename --node <id> --title "New Name"` — rename any node (terminals, groups, stickies…).',
+ '- `write --node <id> --text "..."` / `close --node <id>` — type into / close a node.',
+ ' Both ask the user to confirm a dialog and may be denied.'
+ ].join('\n')
+}
+
// Standalone CLI written to disk by canvas-control.ts and run via Electron-as-Node.
// Self-contained (no deps), no backticks / ${} so it survives this template literal.
export const CONTROL_CLI_SCRIPT = `// nodeterm canvas-control CLI (auto-generated — do not edit).
diff --git a/src/main/canvas-control.ts b/src/main/canvas-control.ts
index 90f0885e0..293789dd2 100644
--- a/src/main/canvas-control.ts
+++ b/src/main/canvas-control.ts
@@ -1,12 +1,17 @@
-// Installs the outbound canvas-control CLI + a Claude skill describing it. Mirrors
+// Installs the outbound canvas-control CLI + per-agent discovery docs. Mirrors
// context-link.ts: a self-contained CLI (canvas-control-cli.mjs, run via Electron-as-Node
-// through nodeterm.sh) POSTs to the hook server's /control/* routes; the skill tells the
-// agent how + when to call it. The CLI no-ops unless NODETERM_CANVAS_CONTROL is set.
+// through nodeterm.sh) POSTs to the hook server's /control/* routes; a Claude skill /
+// codex-gemini instruction blocks tell the agent how + when to call it. The CLI no-ops
+// unless NODETERM_CANVAS_CONTROL is set.
import fs from 'fs'
import os from 'os'
import path from 'path'
import { app } from 'electron'
-import { CONTROL_CLI_SCRIPT } from './canvas-control-core'
+import {
+ CONTROL_CLI_SCRIPT,
+ buildCanvasControlInstructions,
+ mergeCanvasControlBlock
+} from './canvas-control-core'
function dir(): string {
return path.join(app.getPath('userData'), 'canvas-control')
@@ -109,10 +114,37 @@ export function installCanvasSkillInto(configDir: string): void {
}
}
+// Codex/Gemini have no skill system — merge the canvas-control block into their global
+// instruction files (marker-delimited, idempotent, other content preserved). Same pattern
+// as context-link's get-linked-context block. The CLI env-gate keeps the block inert in
+// the user's normal (non-nodeterm) codex/gemini sessions.
+function installAgentInstructions(): void {
+ const block = buildCanvasControlInstructions(shimPath())
+ const targets = [
+ path.join(os.homedir(), '.codex', 'AGENTS.md'),
+ path.join(os.homedir(), '.gemini', 'GEMINI.md')
+ ]
+ for (const p of targets) {
+ try {
+ let existing = ''
+ try {
+ existing = fs.readFileSync(p, 'utf8')
+ } catch {
+ /* new file */
+ }
+ fs.mkdirSync(path.dirname(p), { recursive: true })
+ fs.writeFileSync(p, mergeCanvasControlBlock(existing, block), 'utf8')
+ } catch (e) {
+ console.warn('[canvas-control] instructions install failed', p, e)
+ }
+ }
+}
+
export function initCanvasControl(): void {
try {
writeCliFiles()
installCanvasSkillInto(path.join(os.homedir(), '.claude'))
+ installAgentInstructions()
} catch (e) {
console.error('[canvas-control] setup failed', e)
}
diff --git a/src/shared/agents/config.control.test.ts b/src/shared/agents/config.control.test.ts
index be4a467a6..01d768323 100644
--- a/src/shared/agents/config.control.test.ts
+++ b/src/shared/agents/config.control.test.ts
@@ -2,10 +2,10 @@ import { describe, it, expect } from 'vitest'
import { canControlCanvas } from './config'
describe('canControlCanvas', () => {
- it('is true for claude only', () => {
+ it('is true for the three builtins, not custom agents', () => {
expect(canControlCanvas('claude')).toBe(true)
- expect(canControlCanvas('codex')).toBe(false)
- expect(canControlCanvas('gemini')).toBe(false)
+ expect(canControlCanvas('codex')).toBe(true)
+ expect(canControlCanvas('gemini')).toBe(true)
expect(canControlCanvas('custom:abc')).toBe(false)
})
})
diff --git a/src/shared/agents/config.ts b/src/shared/agents/config.ts
index c95aba316..8dd2e16b9 100644
--- a/src/shared/agents/config.ts
+++ b/src/shared/agents/config.ts
@@ -58,8 +58,10 @@ export const TRANSFER_SOURCE_CAPABLE = ['claude', 'codex', 'gemini'] as const
// Agents that support naming the session in two directions: they emit a session title we adopt
// into the node title, and accept `/rename <name>` to push a renamed node title back. Claude-only.
export const RENAME_CAPABLE = ['claude'] as const
-// Agents allowed to drive the canvas via the `nodeterm` CLI (open/show/write/close). Claude-only.
-export const CANVAS_CONTROL_CAPABLE = ['claude'] as const
+// Agents allowed to drive the canvas via the `nodeterm` CLI (open/show/write/close).
+// Discovery differs per agent: claude gets the manage-nodeterm-canvas skill, codex/gemini a
+// marker block in ~/.codex/AGENTS.md / ~/.gemini/GEMINI.md (see canvas-control.ts).
+export const CANVAS_CONTROL_CAPABLE = ['claude', 'codex', 'gemini'] as const
const includes = (list: readonly string[], id: AgentId): boolean => list.includes(id)