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.

fix(control): DESTRUCTIVE actually gates something now

Claude Code8c484259b35c
diff --git a/src/main/canvas-control-core.ts b/src/main/canvas-control-core.ts
index 831ee5333..252a92a6c 100644
--- a/src/main/canvas-control-core.ts
+++ b/src/main/canvas-control-core.ts
@@ -61,11 +61,22 @@ const VERBS: ControlVerb[] = [
'assign'
]
-const DESTRUCTIVE: ReadonlySet<ControlVerb> = new Set(['write', 'close'])
-
-export function isDestructiveVerb(verb: ControlVerb): boolean {
- return DESTRUCTIVE.has(verb)
-}
+/**
+ * The confirm-gated set. It MOVED to `src/shared/control-verbs.ts` and is re-exported here so
+ * main-side callers read the same one the gate does.
+ *
+ * WHERE IT IS ENFORCED: `Canvas.tsx`'s `switch (verb)` — `case 'write'` and `case 'close'` read
+ * `isDestructiveVerb(verb)` before their `confirmBusy()` refusal. That is the only consumer, and
+ * until it existed this set gated nothing at all: it lived in `src/main`, which the renderer
+ * cannot import, so the actual confirm was hand-written per case and adding a verb to the set
+ * changed no behaviour — while `TOLERANT_CONTROL_VERBS`' doc comment, `hook-server.ts`'s
+ * `buildPtyEnv` note and `docs/node-identity.md` (twice, including invariant 6) all told a reader
+ * it was what decided.
+ *
+ * A verb that needs gating is added to the shared set, not by hand-writing a third confirm block;
+ * `src/renderer/canvas/control-destructive.test.ts` fails if the two disagree again.
+ */
+export { isDestructiveVerb, DESTRUCTIVE_VERBS } from '../shared/control-verbs'
/** Validate a raw (verb, args) pair into a ControlCommand, or return an { error }. */
export function parseControlRequest(
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index ac3948427..0f7d1af40 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -315,6 +315,10 @@ import { createCanvasOrder, createReconnectWatch, type CanvasOrder } from '@shar
import { createMutationGuard } from '@shared/canvas-mutations'
import { chordHeld, isHoldChord, isModifierEventKey, matchesShortcut } from '@shared/shortcut'
+// The dispatch below is the CONSUMER of the confirm-gated set. Before this import the set named
+// write/close as "the confirm-gated pair" from inside `src/main` — which this project cannot see —
+// while the gating lived in two hand-written blocks here, so the set decided nothing.
+import { isDestructiveVerb } from '@shared/control-verbs'
import { canvasSyncTarget } from './collab-sync'
import {
applyCanvasMutation,
@@ -6964,7 +6968,13 @@ export function Canvas() {
// mounted on top of a destructive one (the worktree-removal confirm) turned an Enter
// aimed at THIS harmless prompt into a deletion. `confirmBusy` covers every confirm
// state, not just `confirm`. Reject instead.
- if (confirmBusy()) {
+ //
+ // `isDestructiveVerb` is read here rather than assumed: the set is the authority on
+ // which verbs are confirm-gated, and until this line it was a security-shaped constant
+ // that gated nothing — every reader of invariant 6 or TOLERANT_CONTROL_VERBS' doc
+ // comment believed adding a verb to it gated that verb. Reading it is what makes the
+ // set true.
+ if (isDestructiveVerb(verb) && confirmBusy()) {
reply({ ok: false, error: 'a confirmation is already pending — try again' })
return
}
@@ -6996,8 +7006,9 @@ export function Canvas() {
return
}
// One confirm dialog at a time (see `write`): reject rather than orphan a pending one —
- // or stack this one over a destructive dialog the user then cannot see.
- if (confirmBusy()) {
+ // or stack this one over a destructive dialog the user then cannot see. Gated on the
+ // shared set for the same reason `write` is.
+ if (isDestructiveVerb(verb) && confirmBusy()) {
reply({ ok: false, error: 'a confirmation is already pending — try again' })
return
}
diff --git a/src/renderer/canvas/control-destructive.test.ts b/src/renderer/canvas/control-destructive.test.ts
new file mode 100644
index 000000000..4a55a15bb
--- /dev/null
+++ b/src/renderer/canvas/control-destructive.test.ts
@@ -0,0 +1,57 @@
+import { describe, it, expect } from 'vitest'
+import { readFileSync } from 'node:fs'
+import { isDestructiveVerb, DESTRUCTIVE_VERBS } from '@shared/control-verbs'
+
+/**
+ * A STRUCTURAL test on purpose.
+ *
+ * `DESTRUCTIVE` / `isDestructiveVerb` named `write` and `close` as "the confirm-gated set" and was
+ * imported by nothing but its own unit test — it could not be anything else, because it lived in
+ * `src/main` and the gate is in the renderer, which cannot import from there. The live gate was a
+ * hand-written `if (confirmBusy())` inside each of the two `switch (verb)` cases, so the SET gated
+ * nothing: adding a verb to it changed no behaviour, while `TOLERANT_CONTROL_VERBS`' doc comment,
+ * `hook-server.ts`'s `buildPtyEnv` note and `docs/node-identity.md` (twice, including invariant 6)
+ * all tell a reader that the set is what decides.
+ *
+ * The dispatch now reads the set. There is no unit seam to assert that through — the switch lives
+ * inside a 7000-line React component's IPC listener — and the failure mode being pinned is exactly
+ * "a reader trusts the constant", which is a property of the SOURCE. So the source is the subject.
+ */
+const src = readFileSync(new URL('./Canvas.tsx', import.meta.url), 'utf8')
+
+/** The body of one `case '<verb>': {` in the control dispatch, up to the next case label. */
+function caseBody(verb: string): string {
+ const start = src.indexOf(`case '${verb}': {`)
+ if (start === -1) return ''
+ const rest = src.slice(start + verb.length + 10)
+ const end = rest.search(/\n {10}case '/)
+ return end === -1 ? rest : rest.slice(0, end)
+}
+
+describe('destructive verbs are confirm-gated through the shared set', () => {
+ it('the dispatch imports the set rather than restating it', () => {
+ expect(src).toMatch(/import \{[^}]*isDestructiveVerb[^}]*\} from '@shared\/control-verbs'/)
+ })
+
+ for (const verb of ['write', 'close'] as const) {
+ it(`${verb} reaches its confirm through isDestructiveVerb`, () => {
+ expect(isDestructiveVerb(verb)).toBe(true)
+ const body = caseBody(verb)
+ expect(body).not.toBe('')
+ // The guard CALL, not a hardcoded truth: adding a verb to the set must change behaviour.
+ expect(body).toMatch(/isDestructiveVerb\(verb\) && confirmBusy\(\)/)
+ // …and no leftover bare gate beside it, which would make the set decorative again.
+ expect(body).not.toMatch(/\bif \(confirmBusy\(\)\)/)
+ expect(body).toContain('setConfirm({')
+ })
+ }
+
+ it('no OTHER verb is silently confirm-gated behind the set', () => {
+ // Every `isDestructiveVerb(verb)` in the dispatch must sit in a case the set actually holds.
+ // If a third case ever grows one, either the set or the dispatch is wrong — say so here rather
+ // than let the two drift apart the way the constant and the switch already did once.
+ const labels = [...src.matchAll(/\n {10}case '([a-z-]+)': \{/g)].map((m) => m[1])
+ const gated = labels.filter((v) => /isDestructiveVerb\(verb\)/.test(caseBody(v)))
+ expect(new Set(gated)).toEqual(new Set(DESTRUCTIVE_VERBS))
+ })
+})
diff --git a/src/shared/control-verbs.ts b/src/shared/control-verbs.ts
new file mode 100644
index 000000000..ad021fe40
--- /dev/null
+++ b/src/shared/control-verbs.ts
@@ -0,0 +1,28 @@
+// The control verbs that must not act until a human has said yes in a dialog.
+//
+// IN `src/shared` BECAUSE IT HAS TWO SIDES, and that is the whole point of this file existing.
+// The set was defined in `src/main/canvas-control-core.ts` and the gate it describes lives in the
+// renderer (`Canvas.tsx`'s `switch (verb)`), which cannot import from `src/main` — `tsconfig.web`
+// includes only `src/renderer`, `src/shared` and the preload types. So the set stayed a
+// security-shaped constant imported by nothing but its own unit test, while
+// `TOLERANT_CONTROL_VERBS`' doc comment, `hook-server.ts`'s `buildPtyEnv` note and
+// `docs/node-identity.md` (twice, including invariant 6) all described it as "the confirm-gated
+// set". It described the dispatch; it did not decide it. Adding a verb to it changed nothing.
+//
+// Here, both sides can read the same set, so adding a verb GATES that verb.
+//
+// Typed on `string`, not `ControlVerb`: that type belongs to the main-side verb model, which is
+// exactly what the renderer cannot see, and the renderer's dispatch receives a raw `verb: string`
+// off IPC anyway. `canvas-control-core.ts` re-exports this so main-side callers are unchanged.
+
+export const DESTRUCTIVE_VERBS: ReadonlySet<string> = new Set(['write', 'close'])
+
+/**
+ * Is this verb one the human must confirm before it acts?
+ *
+ * `open-terminal --cmd` is deliberately NOT in the set and never was; the 2026-08-13 argv-leak
+ * writeup in `docs/node-identity.md` is the record of what that costs when the bearer leaks.
+ */
+export function isDestructiveVerb(verb: string): boolean {
+ return DESTRUCTIVE_VERBS.has(verb)
+}