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
fix(server): canvas control refuses by NAME, not by "control unavailable"
Claude Code623b09c2f358
diff --git a/docs/SERVER.md b/docs/SERVER.mdindex 133023f3c..3ddc7f3cb 100644--- a/docs/SERVER.md+++ b/docs/SERVER.md@@ -484,7 +484,13 @@ Consequences worth knowing:- The SDK **chat node** is still **deferred** — it is not wired into the server bridge.- **Canvas-control** (`agent:control`, the Claude-only `nodeterm` CLI verbs) is **not- wired** over the server.+ wired** over the server, and since the strict-verb work it says so **by name**:+ `/control/<verb>` answers HTTP 400 with `error: control-unsupported-on-this-edition`+ and a sentence containing the literal *"do not retry"*. The old generic+ `control unavailable` read to an agent like a transient outage, and an agent retries an+ outage. `browser` additionally names why it is **structural** rather than unimplemented —+ a browser node on this edition renders in the **viewer's own** browser tab, which this+ server has no debugger for, and never can. See `src/server/control-unsupported.ts`.- The **`ptyDestroy` tail-teardown** — *resolved in Phase 3c.* Phase 3b left this skipped(agent tails self-cleared only on `SessionEnd`, so a node closed *without* one left anidle file-tail); the server now untracks agent tails on node close, at desktop parity.@@ -510,7 +516,8 @@ desktop parity on agent-tail cleanup and first-connect behavior:and the app reloads on reopen, so first-load failure now behaves like a mid-session drop.**Still deferred** (unchanged from Phase 3b): the SDK **chat node**, **canvas-control**-(`agent:control` / the `nodeterm` CLI verbs), full **two-master flow-control coordination**+(`agent:control` / the `nodeterm` CLI verbs — now a *named, non-retryable* refusal rather+than a generic failure, see above), full **two-master flow-control coordination**(the server still re-asserts its WS backpressure pause on each send rather than co-managinga single actuator with the renderer), and the web folder picker's **hardcoded startdirectory**.diff --git a/src/core/agents/hook-server.ts b/src/core/agents/hook-server.tsindex c0df10798..ed17033ab 100644--- a/src/core/agents/hook-server.ts+++ b/src/core/agents/hook-server.ts@@ -472,9 +472,13 @@ class HookServer {// The POSIX-sh shim asks for text/plain: it has no JSON parser, so the server does the// rendering the Node CLI used to do client-side. Everything else keeps the JSON shape.if (wantsText) {+ // A FAILURE may now carry both: `error` is the machine-readable name a JSON client+ // keys on, `message` the sentence a human (or a language model) reads. The text+ // dialect has no fields, so it prefers the sentence and falls back to the name — which+ // is what every existing handler still sends, so this is inert for all of them.const text = result.ok? result.message ?? JSON.stringify(result.result ?? {})- : result.error ?? 'control request failed'+ : result.message ?? result.error ?? 'control request failed'res.writeHead(result.ok ? 200 : 400, { 'content-type': 'text/plain; charset=utf-8' })res.end(note ? `${note}\n${text}\n` : `${text}\n`)returndiff --git a/src/server/control-unsupported.test.ts b/src/server/control-unsupported.test.tsnew file mode 100644index 000000000..222256824--- /dev/null+++ b/src/server/control-unsupported.test.ts@@ -0,0 +1,155 @@+/**+ * The Server Edition's `/control/*` answer, proven on the wire.+ *+ * The defect being fixed is a WORDING one with a behavioural cost: `control unavailable` + HTTP 400+ * is indistinguishable from a transient outage, and a language model retries an outage. So the+ * assertions here are about what the caller can conclude — a stable machine name, and prose that+ * contains the literal "do not retry" — not merely about a status code.+ */+import { describe, it, expect, beforeAll, afterAll } from 'vitest'+import fs from 'fs'+import os from 'os'+import path from 'path'+import { initPlatform, resetPlatformForTests } from '../core/platform'+import { fakePlatform } from '../core/platform-fake'+import { hookServer } from '../core/agents/hook-server'+import { nodeAuthToken } from '../core/agents/node-auth-token'+import { STRICT_CONTROL_REFUSAL } from '../core/agents/node-identity-policy'+import {+ BROWSER_UNSUPPORTED_CLAUSE,+ CONTROL_UNSUPPORTED_ERROR,+ CONTROL_UNSUPPORTED_SENTENCE,+ controlUnsupportedMessage,+ serverEditionControlHandler+} from './control-unsupported'++const SECRET = Buffer.alloc(32, 7)+let dir = ''++function control(verb: string, nodeId: string, accept = 'text/plain', token?: string) {+ const headers: Record<string, string> = {+ 'X-Nodeterm-Hook-Token': hookServer.getToken(),+ 'content-type': 'application/x-www-form-urlencoded',+ accept+ }+ if (token) headers['X-Nodeterm-Node-Token'] = token+ return fetch(`http://127.0.0.1:${hookServer.getPort()}/control/${verb}`, {+ method: 'POST',+ headers,+ body: `nodeId=${encodeURIComponent(nodeId)}`+ })+}++beforeAll(async () => {+ dir = fs.mkdtempSync(path.join(os.tmpdir(), 'nodeterm-ctl-unsupported-'))+ resetPlatformForTests()+ initPlatform(fakePlatform({ userDataDir: dir }))+ await hookServer.start()+ hookServer.setNodeAuthSecret(SECRET)+ // The exact registration `src/server/index.ts` performs after `hookServer.start()`.+ hookServer.setControlHandler(serverEditionControlHandler)+})++afterAll(() => {+ hookServer.clearNodeAuthSecretForTests()+ hookServer.stop()+ resetPlatformForTests()+ fs.rmSync(dir, { recursive: true, force: true })+})++describe('the Server Edition refuses canvas control by name', () => {+ it('answers every verb with the same machine-readable error, in JSON', async () => {+ for (const verb of ['list', 'open-terminal', 'write']) {+ const res = await control(verb, 'n-1', 'application/json')+ expect(res.status, verb).toBe(400)+ const body = (await res.json()) as { ok: boolean; error: string; message: string }+ expect(body.ok, verb).toBe(false)+ // The name is EXACT and stable — this is the field a client is allowed to branch on.+ expect(body.error, verb).toBe(CONTROL_UNSUPPORTED_ERROR)+ expect(body.error, verb).not.toBe('control unavailable')+ }+ })++ it('tells a text/plain caller, in words, not to retry', async () => {+ // Verified, so the reply is the refusal alone: an unverified caller inside the warning window+ // gets the identity note prefixed on top, which is existing behaviour and not what is measured+ // here.+ const res = await control('open-terminal', 'n-2', 'text/plain', nodeAuthToken(SECRET, 'n-2'))+ expect(res.status).toBe(400)+ const text = await res.text()+ // The literal the whole change exists for.+ expect(text).toContain('do not retry')+ expect(text).toContain('permanent')+ // …and the name, because the text dialect carries no fields.+ expect(text).toContain(CONTROL_UNSUPPORTED_ERROR)+ expect(text).toContain(CONTROL_UNSUPPORTED_SENTENCE)+ // One line: the shim prints the body as-is.+ expect(text.trimEnd()).not.toContain('\n')+ })++ it('names WHY browser control is structural, not merely unimplemented', async () => {+ // `browser` is a strict verb, so it takes a verified identity even to be told no. That+ // ordering is correct — identity runs before the handler — and it is why this test presents a+ // token where the others do not.+ const res = await control('browser', 'n-3', 'text/plain', nodeAuthToken(SECRET, 'n-3'))+ expect(res.status).toBe(400)+ const text = await res.text()+ expect(text).toContain(CONTROL_UNSUPPORTED_ERROR)+ expect(text).toContain(BROWSER_UNSUPPORTED_CLAUSE)+ expect(text).toContain('renders in your own browser')+ })++ it('adds that clause to `browser` and to nothing else', () => {+ expect(controlUnsupportedMessage('browser')).toContain(BROWSER_UNSUPPORTED_CLAUSE)+ for (const verb of ['list', 'open-terminal', 'browsers', 'BROWSER']) {+ expect(controlUnsupportedMessage(verb), verb).not.toContain(BROWSER_UNSUPPORTED_CLAUSE)+ expect(controlUnsupportedMessage(verb), verb).toContain(CONTROL_UNSUPPORTED_ERROR)+ }+ })++ it('still refuses an unverified `browser` on IDENTITY, before the edition ever answers', async () => {+ // Order matters: the identity gate runs before the handler on both shells, so a tokenless+ // caller learns nothing about the edition. Neither answer is a retryable outage.+ const res = await control('browser', 'n-4')+ expect(res.status).toBe(403)+ expect((await res.text()).trim()).toBe(STRICT_CONTROL_REFUSAL)+ })++ it('never resolves ok — there is nothing on this host for a verb to act on', async () => {+ expect(await serverEditionControlHandler({ verb: 'list' })).toEqual({+ ok: false,+ error: CONTROL_UNSUPPORTED_ERROR,+ message: controlUnsupportedMessage('list')+ })+ })+})++describe('the Server Edition wires it at boot', () => {+ it('registers the refusing handler instead of leaving the null branch', () => {+ // A hook-server change made on one shell only has shipped wrong three times in this repo, and+ // the null branch is invisible until an agent hits it in production.+ const src = fs.readFileSync(path.resolve(__dirname, 'index.ts'), 'utf8')+ expect(src).toContain('setControlHandler(serverEditionControlHandler)')+ })+})++/**+ * The reply shape this refusal needed: a FAILURE may now carry a machine name in `error` and a+ * sentence in `message`, and the text dialect prefers the sentence. Every pre-existing handler+ * sends `error` alone, so the fallback is what they all still take — pinned here because a silent+ * change of dialect for every failing verb would be a much bigger deal than this feature.+ */+describe('a failing verb that carries only `error` is rendered exactly as before', () => {+ it('falls back to the error string in text, and keeps the JSON field', async () => {+ hookServer.setControlHandler(async () => ({ ok: false, error: 'boom' }))+ try {+ const text = await control('open-terminal', 'n-5', 'text/plain', nodeAuthToken(SECRET, 'n-5'))+ expect(text.status).toBe(400)+ expect((await text.text()).trim()).toBe('boom')+ const json = await control('open-terminal', 'n-6', 'application/json', nodeAuthToken(SECRET, 'n-6'))+ expect(await json.json()).toEqual({ ok: false, error: 'boom' })+ } finally {+ hookServer.setControlHandler(serverEditionControlHandler)+ }+ })+})diff --git a/src/server/control-unsupported.ts b/src/server/control-unsupported.tsnew file mode 100644index 000000000..b5f468022--- /dev/null+++ b/src/server/control-unsupported.ts@@ -0,0 +1,60 @@+/**+ * The Server Edition's answer to `/control/*`: a NAMED, permanent refusal.+ *+ * `src/server/index.ts` starts the same hook server as the desktop but never calls+ * `setControlHandler`, so every control verb fell through to the null branch's+ * `{ ok: false, error: 'control unavailable' }` → HTTP 400. That sentence reads to a language model+ * exactly like a transient outage, **and a model retries an outage** — so an agent on a headless+ * host burned its turns re-sending a request that can never succeed, and the operator saw a stream+ * of 400s with nothing naming the cause.+ *+ * Registering a refusing handler rather than leaving the branch null is deliberate: the refusal+ * then travels the same reply shape as every other verb (JSON gets a machine-readable `error`, the+ * POSIX-sh shim gets one printable line), and nobody has to special-case "unavailable" downstream.+ *+ * Shared with the agent-messaging plan by agreement — one string, one mechanism, every verb.+ */++/** The machine-readable name. Structured clients key on this, never on the prose. */+export const CONTROL_UNSUPPORTED_ERROR = 'control-unsupported-on-this-edition'++/**+ * The prose, which must say the thing a retrying model needs to hear IN WORDS: the literal+ * "do not retry". A refusal that only a status code distinguishes from an outage is not a refusal+ * an agent can act on.+ */+export const CONTROL_UNSUPPORTED_SENTENCE =+ 'Canvas control is not available on the nodeterm Server Edition. This is permanent on this ' ++ 'host, not a temporary failure — do not retry.'++/**+ * `browser` gets one extra clause naming WHY it is structural, so nobody files it as unimplemented+ * and nobody tries to implement it here. A browser node on this edition renders in the VIEWER's own+ * Chrome tab: there is no Electron, no `webContents`, no `<webview>` and no CDP on this host, and+ * the server has no debugger for a page in somebody else's browser and never can.+ */+export const BROWSER_UNSUPPORTED_CLAUSE =+ 'There is no browser control on this edition: a browser node here renders in your own browser ' ++ 'tab, which this server has no debugger for.'++/**+ * One line, always — control replies are rendered as a single line by the shim, and a multi-line+ * body buries whichever half the reader stops at. The machine name is repeated inside the prose so+ * the text/plain dialect (which carries no `error` field) still names the refusal.+ */+export function controlUnsupportedMessage(verb: string): string {+ const why = verb === 'browser' ? ` ${BROWSER_UNSUPPORTED_CLAUSE}` : ''+ return `${CONTROL_UNSUPPORTED_ERROR}: ${CONTROL_UNSUPPORTED_SENTENCE}${why}`+}++/**+ * What `src/server/index.ts` hands to `hookServer.setControlHandler`. Never resolves `ok: true`:+ * there is nothing on this host for a control verb to act on.+ */+export async function serverEditionControlHandler({ verb }: { verb: string }): Promise<{+ ok: false+ error: string+ message: string+}> {+ return { ok: false, error: CONTROL_UNSUPPORTED_ERROR, message: controlUnsupportedMessage(verb) }+}diff --git a/src/server/index.ts b/src/server/index.tsindex e93387c41..657cc3786 100644--- a/src/server/index.ts+++ b/src/server/index.ts@@ -23,6 +23,7 @@ import { DownloadTickets } from '../core/download-tickets'import { registerBoardLogHandlers, type BoardLogRoute } from '../core/board-log-handlers'import os from 'os'import { hookServer } from '../core/agents/hook-server'+import { serverEditionControlHandler } from './control-unsupported'import { loadOrCreateNodeAuthSecret } from '../core/agents/node-auth-secret'import { initNodeTokens, refreshNodeTokens } from '../core/agents/node-token-service'import {@@ -418,6 +419,10 @@ export async function startServer(}}await hookServer.start()+ // Canvas control does not exist on this edition, and saying so BY NAME is the whole point: the+ // null handler answered `control unavailable`, which reads to an agent like a transient outage,+ // and an agent retries an outage. See `control-unsupported.ts`.+ hookServer.setControlHandler(serverEditionControlHandler)// ---- Node identity (src/core/agents/node-auth-secret.ts) ------------------------------------// First time the Server Edition arms node identity. Headless Linux has no OS keychain, so the