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(project): per-project capability switches, off by default, validated === true

Claude Code2ec2d3fed7f3
diff --git a/src/core/workspace-files.test.ts b/src/core/workspace-files.test.ts
index 1fa5eaec5..6a27d125c 100644
--- a/src/core/workspace-files.test.ts
+++ b/src/core/workspace-files.test.ts
@@ -64,6 +64,28 @@ describe('projectToFile / fileToProject round-trip', () => {
})
})
+describe('per-project capability fields in the shared file', () => {
+ it('a capability round-trips through projectToFile/fileToProject, and a non-literal-true does not', () => {
+ const p = project({ agentBrowserControl: true })
+ expect(projectToFile(p, 1, 'ts').agentBrowserControl).toBe(true)
+ const baseFile = projectToFile(project(), 1, 'ts')
+ expect(fileToProject({ ...baseFile, agentBrowserControl: true }, { id: 'x' }).agentBrowserControl).toBe(
+ true
+ )
+ // A hand-edited/hostile file carrying "true" (the string), 1 or {} is OFF — the field simply
+ // does not survive the read. projectCapabilityEnabled would answer false either way; this pins
+ // that the sanitisation happens at the FILE boundary, not only at the consumption site.
+ expect(
+ fileToProject({ ...baseFile, agentBrowserControl: 'true' } as never, { id: 'x' }).agentBrowserControl
+ ).toBeUndefined()
+ })
+ it('an off capability adds no bytes to the committed file', () => {
+ const f = projectToFile(project(), 1, 'ts')
+ expect('agentBrowserControl' in f).toBe(false)
+ expect(serializeProjectFile(f)).not.toContain('agentBrowserControl')
+ })
+})
+
describe('sameProjectContent', () => {
it('ignores rev and savedAt, sees node changes', () => {
const a = projectToFile(project(), 1, '2026-01-01T00:00:00.000Z')
diff --git a/src/core/workspace-files.ts b/src/core/workspace-files.ts
index a91dd444c..37022bf3e 100644
--- a/src/core/workspace-files.ts
+++ b/src/core/workspace-files.ts
@@ -8,6 +8,7 @@ import {
type LocalNodeExecMap
} from '../shared/node-exec'
import type { BridgeLink, CanvasNodeState, Project, ProjectKanban, Viewport, Workspace } from '../shared/types'
+import { projectCapabilityFields, readProjectCapabilities } from '../shared/project-capabilities'
export const PROJECT_DIR = '.nodeterm'
export const PROJECT_FILE = 'project.json'
@@ -66,6 +67,12 @@ export interface ProjectFileV1 {
*/
defaultAccountId?: string
defaultPermissionMode?: AgentPermissionMode
+ /**
+ * Per-project capability switch (see @shared/project-capabilities): deliberately IN the
+ * git-shared file — the team shares the policy — which is exactly why reads are strict
+ * (`readProjectCapabilities`, literal `true` only) and why the switch alone grants nothing.
+ */
+ agentBrowserControl?: boolean
dinoHighScore?: number
kanban?: ProjectKanban
}
@@ -182,6 +189,10 @@ export function projectToFile(
...(p.bridges ? { bridges: p.bridges } : {}),
...(p.ropes ? { ropes: p.ropes } : {}),
...(p.defaultPermissionMode ? { defaultPermissionMode: p.defaultPermissionMode } : {}),
+ // Strict-normalised (literal true only, known keys only) and omitted when off — an off
+ // capability adds no bytes to the committed file. `capabilityAck` is deliberately NOT here:
+ // the acknowledgment is machine-local (IndexEntryV3.capabilityAck) and must never travel.
+ ...projectCapabilityFields(p),
...(p.dinoHighScore ? { dinoHighScore: p.dinoHighScore } : {}),
...(p.kanban ? { kanban: p.kanban } : {})
}
@@ -239,6 +250,9 @@ export function fileToProject(
...(f.ropes ? { ropes: f.ropes } : {}),
...(defaultAccountId ? { defaultAccountId } : {}),
...(f.defaultPermissionMode ? { defaultPermissionMode: f.defaultPermissionMode } : {}),
+ // The file is hostile input: only a literal `true` under a known key survives the read
+ // (readProjectCapabilities). `"true"`, 1, {} et al. vanish here, at the boundary.
+ ...readProjectCapabilities(f),
...(f.dinoHighScore ? { dinoHighScore: f.dinoHighScore } : {}),
...(validKanban(f.kanban) ? { kanban: f.kanban } : {}),
...(base.cwd ? { cwd: base.cwd } : {}),
diff --git a/src/shared/project-capabilities.test.ts b/src/shared/project-capabilities.test.ts
new file mode 100644
index 000000000..c07e9f242
--- /dev/null
+++ b/src/shared/project-capabilities.test.ts
@@ -0,0 +1,57 @@
+import { describe, it, expect } from 'vitest'
+import {
+ PROJECT_CAPABILITIES,
+ PROJECT_CAPABILITY_COPY,
+ projectCapabilityEnabled,
+ readProjectCapabilities,
+ projectCapabilityFields
+} from './project-capabilities'
+
+describe('projectCapabilityEnabled is STRICT', () => {
+ it('true enables', () => {
+ expect(projectCapabilityEnabled({ agentBrowserControl: true }, 'agentBrowserControl')).toBe(true)
+ })
+ it.each([undefined, false, null, 0, 1, 'true', 'yes', {}, [], 'false'])(
+ 'everything else is OFF (%j) — project.json is hostile input, not a truthiness exercise',
+ (v) => {
+ expect(projectCapabilityEnabled({ agentBrowserControl: v } as never, 'agentBrowserControl')).toBe(false)
+ }
+ )
+ it('an absent project is off, never a throw', () => {
+ expect(projectCapabilityEnabled(undefined, 'agentBrowserControl')).toBe(false)
+ expect(projectCapabilityEnabled(null, 'agentBrowserControl')).toBe(false)
+ })
+})
+
+describe('readProjectCapabilities normalises whatever the file carried', () => {
+ it('keeps only literal true, and only known keys', () => {
+ expect(readProjectCapabilities({ agentBrowserControl: 'true', nope: true })).toEqual({})
+ expect(readProjectCapabilities({ agentBrowserControl: true })).toEqual({ agentBrowserControl: true })
+ expect(readProjectCapabilities({ agentBrowserControl: true, nope: true })).toEqual({
+ agentBrowserControl: true
+ })
+ })
+ it('survives a non-object file', () => {
+ expect(readProjectCapabilities(null)).toEqual({})
+ expect(readProjectCapabilities('x')).toEqual({})
+ expect(readProjectCapabilities(undefined)).toEqual({})
+ })
+})
+
+describe('projectCapabilityFields — the spread projectToFile uses', () => {
+ it('omits an off capability entirely (no bytes, no git churn) and survives null', () => {
+ expect(projectCapabilityFields({ agentBrowserControl: false })).toEqual({})
+ expect(projectCapabilityFields(null)).toEqual({})
+ expect(projectCapabilityFields({ agentBrowserControl: true })).toEqual({ agentBrowserControl: true })
+ })
+})
+
+describe('every capability has copy, and the copy says what travels', () => {
+ it.each(PROJECT_CAPABILITIES)('%s has label, description and cloneWarning', (cap) => {
+ const c = PROJECT_CAPABILITY_COPY[cap]
+ expect(c.label.length).toBeGreaterThan(0)
+ expect(c.description.length).toBeGreaterThan(0)
+ // The same wording class as TabBar's bypassPermissions title: the two git-shared grants read alike.
+ expect(c.cloneWarning).toContain('.nodeterm/project.json')
+ })
+})
diff --git a/src/shared/project-capabilities.ts b/src/shared/project-capabilities.ts
new file mode 100644
index 000000000..951333087
--- /dev/null
+++ b/src/shared/project-capabilities.ts
@@ -0,0 +1,80 @@
+/**
+ * Per-project capability switches — the FIRST of their kind in nodeterm.
+ *
+ * Before this file, `Project` carried exactly two policy fields (defaultAccountId,
+ * defaultPermissionMode) and there was no per-project settings surface at all. Browser control
+ * needed one and agent-to-agent messaging needs the same one, so the mechanism lives here ONCE:
+ * the key set, the copy, the strict read, and the file round-trip. Adding a capability is a line in
+ * PROJECT_CAPABILITIES plus an entry in PROJECT_CAPABILITY_COPY — no persistence code changes and,
+ * critically, no second clone-notice implementation (see core/project-capability-consent.ts).
+ *
+ * THESE FIELDS LIVE IN .nodeterm/project.json, WHICH IS GIT-SHARED. That is a hazard to be handled,
+ * not noted: a hostile cloned repo ships `agentBrowserControl: true` and the clone's first agent
+ * turn would otherwise hold the capability. Two things make that survivable and BOTH are required:
+ *
+ * 1. The switch alone grants nothing. Every capability must additionally require state this app
+ * run built and never persisted (browser control: the in-memory ownership ledger; a cloned
+ * project.json cannot pre-populate it, and `Project.ropes` — which IS persisted and git-shared —
+ * is deliberately never consulted for ownership).
+ * 2. First use in a project the user has not personally switched on raises a one-time notice,
+ * recorded MACHINE-LOCALLY (IndexEntryV3.capabilityAck), never in project.json.
+ *
+ * If (2) is ever dropped as friction, this field must move to a machine-local store. That is the
+ * trigger, written down where the decision is, not only in the design doc.
+ */
+export type ProjectCapability = 'agentBrowserControl'
+// Agent-to-agent messaging adds 'agentMessaging' here (its plan's PR 6 Task 6.1).
+
+export const PROJECT_CAPABILITIES: readonly ProjectCapability[] = ['agentBrowserControl'] as const
+
+export interface ProjectCapabilityCopy {
+ label: string
+ description: string
+ /** Shown wherever the switch is set AND in the clone notice. Same wording class as TabBar's
+ * bypassPermissions title, so the two git-shared grants read alike. */
+ cloneWarning: string
+}
+
+export const PROJECT_CAPABILITY_COPY: Record<ProjectCapability, ProjectCapabilityCopy> = {
+ agentBrowserControl: {
+ label: 'Let agents drive browser nodes they open',
+ description:
+ 'Agents in this project can navigate, read, click and type in browser nodes THEY opened — ' +
+ 'never in browser nodes you opened. Any page an agent reads can try to steer it: a page can ' +
+ 'contain instructions, and the same agent can navigate anywhere and type anywhere. Nodes an ' +
+ 'agent opens use their own logged-out session, separate from your own browsing. A badge on ' +
+ 'the node shows when one is being driven, with a Stop button.',
+ cloneWarning:
+ 'This setting is saved in the project file (.nodeterm/project.json), so if you commit it, ' +
+ 'everyone who clones the repo gets it too.'
+ }
+}
+
+/** Is this capability on for this project? STRICT `=== true`: .nodeterm/project.json is hostile
+ * input — git-shared, hand-editable, auto-adopted (@shared/node-exec) — so `"true"`, `1` and `{}`
+ * are off. Every consumption site goes through this function; a bare `if (project.x)` is a bug.
+ * (`project-capabilities.test.ts` fails on any of those values enabling.) */
+export function projectCapabilityEnabled(
+ p: Partial<Record<ProjectCapability, unknown>> | undefined | null,
+ cap: ProjectCapability
+): boolean {
+ return p?.[cap] === true
+}
+
+/** The capability half of a ProjectFileV1, normalised: known keys only, literal `true` only. */
+export function readProjectCapabilities(f: unknown): Partial<Record<ProjectCapability, true>> {
+ const out: Partial<Record<ProjectCapability, true>> = {}
+ if (!f || typeof f !== 'object') return out
+ for (const cap of PROJECT_CAPABILITIES) {
+ if ((f as Record<string, unknown>)[cap] === true) out[cap] = true
+ }
+ return out
+}
+
+/** The spread `projectToFile` uses. Absent keys are omitted, so an off capability adds no bytes to
+ * the committed file and no churn to anyone's git diff. */
+export function projectCapabilityFields(
+ p: Partial<Record<ProjectCapability, unknown>> | undefined | null
+): Partial<Record<ProjectCapability, true>> {
+ return readProjectCapabilities(p ?? {})
+}
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 5db434d96..839dc560d 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -468,6 +468,20 @@ export interface Project {
/** Permission mode for new Claude TERMINAL (CLI) sessions in this project. SDK chat nodes are
* not covered — the chat driver still runs in `default`. Unset = use the global setting. */
defaultPermissionMode?: AgentPermissionMode
+ /**
+ * Per-project capability switch: agents may drive browser nodes THEY opened in this project.
+ * GIT-SHARED (rides .nodeterm/project.json) and therefore hostile input — read it ONLY through
+ * `projectCapabilityEnabled` (@shared/project-capabilities, strict `=== true`); the switch alone
+ * grants nothing (see that module's header for the two required halves).
+ */
+ agentBrowserControl?: boolean
+ /**
+ * MACHINE-LOCAL record that this machine's user has seen (or personally set) each capability
+ * switch — the "once per project ever" half of the clone notice. Persisted on
+ * `IndexEntryV3.capabilityAck`, NEVER written into the shared project file
+ * (workspace-files.test.ts / capability-notice tests pin that the file bytes are unchanged).
+ */
+ capabilityAck?: Partial<Record<import('./project-capabilities').ProjectCapability, true>>
/** Best dino-game score in this project — new dino nodes seed from it, so the record survives closing the node. */
dinoHighScore?: number
/** Kanban task board — shared via .nodeterm/project.json like nodes. */