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(project): a declined capability can never become a silent grant, and dismissal is not an answer
Claude Code64b2e63d3cff
diff --git a/src/core/project-capability-consent.test.ts b/src/core/project-capability-consent.test.tsindex a54cea1a4..2808118ce 100644--- a/src/core/project-capability-consent.test.ts+++ b/src/core/project-capability-consent.test.ts@@ -3,6 +3,7 @@ import type { Project } from '../shared/types'import {needsCapabilityNotice,projectCapabilityGranted,+ projectCapabilityGrantedFor,recordCapabilityAck} from './project-capability-consent'import * as shared from '../shared/project-capability-consent'@@ -19,52 +20,113 @@ const baseProject: Project = {describe('needsCapabilityNotice', () => {const cap = 'agentBrowserControl' as constit('off in the file ⇒ never a notice', () => {- expect(needsCapabilityNotice({ capability: cap, enabledInFile: false, acknowledged: false })).toBe(false)+ expect(needsCapabilityNotice({ capability: cap, enabledInFile: false, answer: undefined })).toBe(false)+ expect(needsCapabilityNotice({ capability: cap, enabledInFile: false, answer: 'declined' })).toBe(false)})- it('on in the file and never acknowledged ON THIS MACHINE ⇒ notice', () => {- expect(needsCapabilityNotice({ capability: cap, enabledInFile: true, acknowledged: false })).toBe(true)+ it('on in the file and never answered ON THIS MACHINE ⇒ notice', () => {+ expect(needsCapabilityNotice({ capability: cap, enabledInFile: true, answer: undefined })).toBe(true)})- it('on and acknowledged ⇒ silent forever after', () => {- expect(needsCapabilityNotice({ capability: cap, enabledInFile: true, acknowledged: true })).toBe(false)+ it('on and KEPT ⇒ silent thereafter', () => {+ expect(needsCapabilityNotice({ capability: cap, enabledInFile: true, answer: 'kept' })).toBe(false)+ })+ it('on and previously DECLINED ⇒ a NEW notice — the file re-arrived against a recorded no', () => {+ // C1 (PR #213 review): "Turn it off" deletes the field only in this working copy; a+ // `git checkout`/pull restores the hostile `true` and the watcher re-reads it. A recorded+ // decline must produce a fresh notice, never silence.+ expect(needsCapabilityNotice({ capability: cap, enabledInFile: true, answer: 'declined' })).toBe(true)})})-describe('projectCapabilityGranted — a pending notice is a refusal, not a grant', () => {+describe('projectCapabilityGranted — only an explicit KEPT grants', () => {const cap = 'agentBrowserControl' as constit('a switch that is on but unanswered grants nothing', () => {// This is what the ledger (browser PR 4) and messagingEnabled (messaging PR 6) consult: the// window between a hostile clone's `agentBrowserControl: true` arriving and the user answering- // the notice must be a refusal. Deleting the `acknowledged` condition makes this red.- expect(projectCapabilityGranted({ capability: cap, enabledInFile: true, acknowledged: false })).toBe(false)+ // the notice must be a refusal. Deleting the answer condition makes this red.+ expect(projectCapabilityGranted({ capability: cap, enabledInFile: true, answer: undefined })).toBe(false)+ })+ it('a DECLINED switch grants nothing even when the file says true again', () => {+ // C1's grant leg: decline → hostile true re-arrives → the standing "no" must refuse. An ack+ // that does not carry the answer cannot express this; treating any answer as consent is the+ // exact mutation this test exists to catch.+ expect(projectCapabilityGranted({ capability: cap, enabledInFile: true, answer: 'declined' })).toBe(false)+ })+ it('off in the file grants nothing, whatever was answered', () => {+ expect(projectCapabilityGranted({ capability: cap, enabledInFile: false, answer: 'kept' })).toBe(false)+ })+ it('on and kept is the one granting combination', () => {+ expect(projectCapabilityGranted({ capability: cap, enabledInFile: true, answer: 'kept' })).toBe(true)+ })+})++describe('projectCapabilityGrantedFor — the ONE consumer-facing wiring (PR 4 ledger, PR 6 messagingEnabled)', () => {+ const cap = 'agentBrowserControl' as const+ it('derives both halves from the project and refuses every non-granting shape', () => {+ expect(projectCapabilityGrantedFor(undefined, cap)).toBe(false)+ expect(projectCapabilityGrantedFor({ ...baseProject }, cap)).toBe(false)+ // pending notice (hostile clone window)+ expect(projectCapabilityGrantedFor({ ...baseProject, agentBrowserControl: true }, cap)).toBe(false)+ // recorded decline + re-arrived true+ expect(+ projectCapabilityGrantedFor(+ { ...baseProject, agentBrowserControl: true, capabilityAck: { [cap]: 'declined' } },+ cap+ )+ ).toBe(false)+ // non-literal-true file value never grants, answer or no answer+ expect(+ projectCapabilityGrantedFor(+ { ...baseProject, agentBrowserControl: 'true', capabilityAck: { [cap]: 'kept' } } as never,+ cap+ )+ ).toBe(false)})- it('off in the file grants nothing, acknowledged or not', () => {- expect(projectCapabilityGranted({ capability: cap, enabledInFile: false, acknowledged: true })).toBe(false)+ it('grants exactly for literal true + kept', () => {+ expect(+ projectCapabilityGrantedFor(+ { ...baseProject, agentBrowserControl: true, capabilityAck: { [cap]: 'kept' } },+ cap+ )+ ).toBe(true)})- it('on and acknowledged is the one granting combination', () => {- expect(projectCapabilityGranted({ capability: cap, enabledInFile: true, acknowledged: true })).toBe(true)+ it('ignores a prototype-inherited flag or answer — own properties only', () => {+ // M-1 (PR #213 review): unreachable from JSON.parse, but in-process objects can inherit.+ const inheritedFlag = Object.create({ agentBrowserControl: true }) as Project+ expect(projectCapabilityGrantedFor({ ...baseProject, ...inheritedFlag, capabilityAck: { [cap]: 'kept' } }, cap)).toBe(false)+ const proto = Object.create({ agentBrowserControl: true, capabilityAck: { [cap]: 'kept' } }) as Project+ expect(projectCapabilityGrantedFor(proto, cap)).toBe(false)})})-describe('the acknowledgment is MACHINE-LOCAL', () => {- it('recordCapabilityAck writes to the index entry, never to the project file', () => {- const e = recordCapabilityAck({ id: 'p1', name: 'p', color: '#fff' } as IndexEntryV3, 'agentBrowserControl')- expect(e.capabilityAck).toEqual({ agentBrowserControl: true })+describe('the acknowledgment is MACHINE-LOCAL and carries the answer', () => {+ it('recordCapabilityAck writes the given answer to the index entry, never to the project file', () => {+ const kept = recordCapabilityAck({ id: 'p1', name: 'p', color: '#fff' } as IndexEntryV3, 'agentBrowserControl', 'kept')+ expect(kept.capabilityAck).toEqual({ agentBrowserControl: 'kept' })+ const declined = recordCapabilityAck({ id: 'p1', name: 'p', color: '#fff' } as IndexEntryV3, 'agentBrowserControl', 'declined')+ expect(declined.capabilityAck).toEqual({ agentBrowserControl: 'declined' })// The shared file must not learn about it: projectToFile writes only the capability FIELDS.- expect(Object.keys(projectToFile({ ...baseProject, agentBrowserControl: true }, 1, 't', 'l')))- .not.toContain('capabilityAck')+ // The project here CARRIES an ack (M-3: an ack-less input could never catch a leak).+ const file = projectToFile(+ { ...baseProject, agentBrowserControl: true, capabilityAck: { agentBrowserControl: 'kept' } },+ 1,+ 't',+ 'l'+ )+ expect(Object.keys(file)).not.toContain('capabilityAck')+ expect(JSON.stringify(file)).not.toContain('capabilityAck')})- it('does not mutate its input and keeps earlier acks', () => {+ it('a later answer overwrites an earlier one, without mutating the input', () => {const before: IndexEntryV3 = {id: 'p1',name: 'p',color: '#fff',- capabilityAck: { agentBrowserControl: true }+ capabilityAck: { agentBrowserControl: 'declined' }}- const after = recordCapabilityAck(before, 'agentBrowserControl')+ const after = recordCapabilityAck(before, 'agentBrowserControl', 'kept')expect(after).not.toBe(before)- expect(before.capabilityAck).toEqual({ agentBrowserControl: true })- expect(after.capabilityAck).toEqual({ agentBrowserControl: true })+ expect(before.capabilityAck).toEqual({ agentBrowserControl: 'declined' })+ expect(after.capabilityAck).toEqual({ agentBrowserControl: 'kept' })})it('a SECOND WORKTREE of the same repo notifies again', () => {@@ -72,20 +134,20 @@ describe('the acknowledgment is MACHINE-LOCAL', () => {// reset --hard), and workspace-files.ts is explicit that the index entry id is the only// authority for project identity. A second folder is a second entry, hence a second notice —// which is correct: it is a different working copy the user has not vetted.- const a = recordCapabilityAck({ id: 'p1', name: 'p', color: '#fff' } as IndexEntryV3, 'agentBrowserControl')- const b = { id: 'p2', name: 'p', color: '#fff' } // same repo, second worktree, fresh entry+ const a = recordCapabilityAck({ id: 'p1', name: 'p', color: '#fff' } as IndexEntryV3, 'agentBrowserControl', 'kept')+ const b: IndexEntryV3 = { id: 'p2', name: 'p', color: '#fff' } // same repo, second worktree, fresh entryexpect(needsCapabilityNotice({capability: 'agentBrowserControl',enabledInFile: true,- acknowledged: !!a.capabilityAck?.agentBrowserControl+ answer: a.capabilityAck?.agentBrowserControl})).toBe(false)expect(needsCapabilityNotice({capability: 'agentBrowserControl',enabledInFile: true,- acknowledged: !!(b as IndexEntryV3).capabilityAck?.agentBrowserControl+ answer: b.capabilityAck?.agentBrowserControl})).toBe(true)})@@ -99,5 +161,6 @@ describe('one decider, two consumers', () => {expect(needsCapabilityNotice).toBe(shared.needsCapabilityNotice)expect(recordCapabilityAck).toBe(shared.recordCapabilityAck)expect(projectCapabilityGranted).toBe(shared.projectCapabilityGranted)+ expect(projectCapabilityGrantedFor).toBe(shared.projectCapabilityGrantedFor)})})diff --git a/src/core/project-capability-consent.ts b/src/core/project-capability-consent.tsindex 9f1aaac1f..78ceae6c1 100644--- a/src/core/project-capability-consent.ts+++ b/src/core/project-capability-consent.ts@@ -6,9 +6,12 @@* `project-capability-consent.test.ts` pins that both paths are the same function objects.*/export {+ capabilityAnswerOf,needsCapabilityNotice,projectCapabilityGranted,+ projectCapabilityGrantedFor,recordCapabilityAck,type CapabilityAckMap,+ type CapabilityAnswer,type CapabilityConsentState} from '../shared/project-capability-consent'diff --git a/src/core/workspace-files.test.ts b/src/core/workspace-files.test.tsindex c58db6369..ff33f7237 100644--- a/src/core/workspace-files.test.ts+++ b/src/core/workspace-files.test.ts@@ -85,20 +85,20 @@ describe('per-project capability fields in the shared file', () => {expect(serializeProjectFile(f)).not.toContain('agentBrowserControl')})it('the ack is machine-local: index entry carries it, the shared file never does', () => {- const p = project({ cwd: '/a/foo', agentBrowserControl: true, capabilityAck: { agentBrowserControl: true } })+ const p = project({ cwd: '/a/foo', agentBrowserControl: true, capabilityAck: { agentBrowserControl: 'kept' as const } })const { index, files } = splitWorkspace({ version: 2, activeProjectId: 'p1', projects: [p] },() => 1,'2026-08-15T00:00:00.000Z')- expect(index.entries[0].capabilityAck).toEqual({ agentBrowserControl: true })+ expect(index.entries[0].capabilityAck).toEqual({ agentBrowserControl: 'kept' })expect(serializeProjectFile(files.get('/a/foo')!)).not.toContain('capabilityAck')// Load: the ack comes from the entry; a file-borne `capabilityAck` (forgery — a repo carrying// its own consent) is never read.- const restored = fileToProject(files.get('/a/foo')!, { id: 'p1', cwd: '/a/foo', capabilityAck: { agentBrowserControl: true } })- expect(restored.capabilityAck).toEqual({ agentBrowserControl: true })+ const restored = fileToProject(files.get('/a/foo')!, { id: 'p1', cwd: '/a/foo', capabilityAck: { agentBrowserControl: 'kept' as const } })+ expect(restored.capabilityAck).toEqual({ agentBrowserControl: 'kept' })const forged = fileToProject(- { ...files.get('/a/foo')!, capabilityAck: { agentBrowserControl: true } } as never,+ { ...files.get('/a/foo')!, capabilityAck: { agentBrowserControl: 'kept' as const } } as never,{ id: 'p1', cwd: '/a/foo' })expect(forged.capabilityAck).toBeUndefined()diff --git a/src/renderer/components/CapabilityNotice.tsx b/src/renderer/components/CapabilityNotice.tsxindex 455fb9b98..da66f5e7d 100644--- a/src/renderer/components/CapabilityNotice.tsx+++ b/src/renderer/components/CapabilityNotice.tsx@@ -1,18 +1,21 @@+import { useState } from 'react'import { useProjects } from '../state/projects'import type { Project } from '@shared/types'import {PROJECT_CAPABILITIES,PROJECT_CAPABILITY_COPY,- projectCapabilityEnabled,+ projectCapabilityFlagInFile,type ProjectCapability} from '@shared/project-capabilities'-import { needsCapabilityNotice } from '@shared/project-capability-consent'+import { capabilityAnswerOf, needsCapabilityNotice } from '@shared/project-capability-consent'import { ConfirmDialog } from './ConfirmDialog'/*** The first capability whose git-shared switch is on for this project while this machine's user- * has never answered for it. Pure and per-capability so agent messaging's switch (its PR 6) gets- * this dialog by adding a copy entry — there is nothing per-feature below.+ * has not KEPT it — never answered, or previously DECLINED and the file's `true` re-arrived via+ * git (C1: a recorded "no" makes a re-appearing switch a new event, not a settled one). Pure and+ * per-capability so agent messaging's switch (its PR 6) gets this dialog by adding a copy entry —+ * there is nothing per-feature below.*/export function pendingCapabilityNotice(p: Project | undefined): ProjectCapability | null {if (!p) return null@@ -20,8 +23,8 @@ export function pendingCapabilityNotice(p: Project | undefined): ProjectCapabiliconst pending = needsCapabilityNotice({capability: cap,// Strict read: a hand-edited "true"/1/{} is off, so it can never raise (or need) a notice.- enabledInFile: projectCapabilityEnabled(p, cap),- acknowledged: p.capabilityAck?.[cap] === true+ enabledInFile: projectCapabilityFlagInFile(p, cap),+ answer: capabilityAnswerOf(p, cap)})if (pending) return cap}@@ -35,15 +38,19 @@ export function pendingCapabilityNotice(p: Project | undefined): ProjectCapabili* - It exists because a capability switch is git-shared: a teammate (or a stranger's repo) can* commit `agentBrowserControl: true`, and the user who cloned it was never asked. The warning* at the point of SETTING (Settings → Agents) cannot reach them; this dialog can.- * - CLICK-ONLY (`enterConfirms={false}` — confirm-key.ts's rule for dialogs the user did not- * open): it was raised by a FILE, and an Enter aimed at a terminal must not answer it.- * capability-notice.test.tsx "is CLICK-ONLY" fails if this prop is dropped.- * - Once per project EVER, proven by persistence, not by session state: the answer lands in- * `Project.capabilityAck` → `IndexEntryV3.capabilityAck` (machine-local), never in the shared- * file — "a second open does not re-notify" and workspace-files.test.ts pin both halves.- * - While it is unanswered the capability GRANTS NOTHING: every consumer reads- * `projectCapabilityGranted`, which refuses a pending notice ("does not grant while- * unanswered"). This component never needs to race anyone.+ * - ONLY THE TWO BUTTONS ARE ANSWERS (PR #213 review, I1). "Keep it on" records 'kept'; "Turn it+ * off" records 'declined' and sheds the field. Escape, an overlay misclick, and a keystroke+ * aimed at a terminal are NON-answers: `enterConfirms={false}` blocks the window-listener path,+ * `autoFocusButtons={false}` means no button holds focus for a native Enter/Space to activate,+ * and `onDismiss` closes the dialog for this app session without recording anything — it+ * re-shows on the next launch (capability-notice.test.tsx "dismissal is not an answer").+ * - The answers are machine-local and carry WHICH answer was given: `Project.capabilityAck` →+ * `IndexEntryV3.capabilityAck`, never the shared file. 'kept' silences the notice for this+ * entry forever; 'declined' + a re-arriving `true` re-notices AND stays refused (C1) — a+ * routine `git checkout` restoring the hostile flag can never convert a "no" into a grant.+ * - While it is unanswered (or declined) the capability GRANTS NOTHING: every consumer reads+ * `projectCapabilityGrantedFor`, which requires the recorded 'kept' ("does not grant while+ * unanswered", "a DECLINED switch grants nothing even when the file says true again").** Renders against the ACTIVE project (the project-load path re-evaluates it on every switch), so* a background project's hostile file cannot pop a dialog about a canvas the user is not looking@@ -54,9 +61,13 @@ export function CapabilityNotice(): React.JSX.Element | null {const projects = useProjects((s) => s.projects)const setProjectCapability = useProjects((s) => s.setProjectCapability)const recordProjectCapabilityAck = useProjects((s) => s.recordProjectCapabilityAck)+ // Dismissed-this-session (Escape / overlay click): hides the dialog without recording an+ // answer, so it re-shows next launch. Component state, not the store — a dismissal is exactly+ // the thing that must NOT persist.+ const [dismissed, setDismissed] = useState<ReadonlySet<string>>(new Set())const project = projects.find((p) => p.id === activeProjectId)const cap = project ? pendingCapabilityNotice(project) : null- if (!project || !cap) return null+ if (!project || !cap || dismissed.has(`${project.id}:${cap}`)) return nullconst copy = PROJECT_CAPABILITY_COPY[cap]return (<ConfirmDialog@@ -69,18 +80,24 @@ export function CapabilityNotice(): React.JSX.Element | null {message={`The project "${project.name}" arrived with "${copy.label}" already switched on — it came from the project file, not from you. Keep it on?`}confirmLabel="Keep it on"cancelLabel="Turn it off"- // "Keep it on" is the grant, so it carries the danger styling and — per ConfirmDialog's- // rule — never the autofocus; Escape and the overlay click take the safe "Turn it off" path.+ // "Keep it on" is the grant, so it carries the danger styling; and NO button takes focus+ // (autoFocusButtons={false}) — this dialog appears under the user's hands, and a native+ // Enter/Space on an autofocused button would be an answer they never aimed here.dangerenterConfirms={false}- onConfirm={() => recordProjectCapabilityAck(project.id, cap)}+ autoFocusButtons={false}+ onConfirm={() => recordProjectCapabilityAck(project.id, cap, 'kept')}onCancel={() => {- // Answered too: the ack makes "once per project ever" true for this entry, and clearing- // the field means the capability stays a refusal (and the file sheds the stranger's grant- // on the next save this user makes).- recordProjectCapabilityAck(project.id, cap)+ // The explicit decline: records 'declined' AND sheds the stranger's grant from the file+ // on the next save. The recorded 'declined' is what keeps a re-arriving `true` refused+ // and re-noticed instead of silently granted (C1).setProjectCapability(project.id, cap, false)}}+ onDismiss={() => {+ // NOT an answer: no ack, no field change — the capability stays refused (no 'kept') and+ // the notice returns next launch.+ setDismissed((s) => new Set(s).add(`${project.id}:${cap}`))+ }}/>)}diff --git a/src/renderer/components/ConfirmDialog.tsx b/src/renderer/components/ConfirmDialog.tsxindex 82d67bce2..a6dba5206 100644--- a/src/renderer/components/ConfirmDialog.tsx+++ b/src/renderer/components/ConfirmDialog.tsx@@ -25,8 +25,25 @@ interface ConfirmDialogProps {* Escape still cancels either way.*/enterConfirms?: boolean+ /**+ * When false, NEITHER button takes `autoFocus`. Default true (historical behavior). Pass false+ * for a dialog that appears under the user's hands (the capability clone notice): `autoFocus`+ * steals focus from whatever they were typing in, and their next Enter/Space then NATIVELY+ * activates the focused button — a path `enterConfirms`/confirm-key never sees, because the+ * browser's default button activation is not the window keydown listener (PR #213 review, I1).+ */+ autoFocusButtons?: booleanonConfirm: () => voidonCancel: () => void+ /**+ * When provided, Escape and an overlay click call THIS instead of `onCancel`, and the cancel+ * button remains the only path to `onCancel`. For a dialog where cancel is itself a recorded+ * ANSWER (the capability clone notice's "Turn it off"), a stray Escape aimed at a terminal or a+ * misclick outside the box must be a non-answer — close for now, decide nothing — not a+ * consent-recording cancel (PR #213 review, I1). Absent = historical behavior (dismissal+ * cancels).+ */+ onDismiss?: () => void}/**@@ -44,9 +61,13 @@ export function ConfirmDialog({alert = false,option,enterConfirms = true,+ autoFocusButtons = true,onConfirm,- onCancel+ onCancel,+ onDismiss}: ConfirmDialogProps) {+ // Escape / overlay-click land here: the caller's dismiss channel when it has one, else cancel.+ const dismiss = onDismiss ?? onCancel// An alert has nothing destructive to warn about and nothing to cancel; anything else keeps the// historical destructive defaults ("Delete", danger styling, focus parked on the safe button).const danger = dangerProp ?? !alert@@ -82,14 +103,14 @@ export function ConfirmDialog({if (!action) returne.preventDefault()if (action === 'confirm') onConfirm()- else onCancel()+ else dismiss()}window.addEventListener('keydown', onKey)return () => window.removeEventListener('keydown', onKey)- }, [id, enterConfirms, onConfirm, onCancel])+ }, [id, enterConfirms, onConfirm, dismiss])return createPortal(- <div className="confirm-overlay" onClick={onCancel}>+ <div className="confirm-overlay" onClick={dismiss}><div className="confirm" ref={boxRef} onClick={(e) => e.stopPropagation()}>{body}<p className="confirm__msg">{message}</p>@@ -108,13 +129,13 @@ export function ConfirmDialog({(or Space) into a deletion. On a danger dialog the safe button is the focused one; on aharmless one the primary action may keep it. */}{!alert && (- <button className="confirm__btn" autoFocus={danger} onClick={onCancel}>+ <button className="confirm__btn" autoFocus={autoFocusButtons && danger} onClick={onCancel}>{cancelLabel}</button>)}<buttonclassName={`confirm__btn${danger ? ' danger' : ' primary'}`}- autoFocus={!danger}+ autoFocus={autoFocusButtons && !danger}onClick={onConfirm}>{confirmText}diff --git a/src/renderer/components/capability-notice.test.tsx b/src/renderer/components/capability-notice.test.tsxindex bb09785ac..a009554b0 100644--- a/src/renderer/components/capability-notice.test.tsx+++ b/src/renderer/components/capability-notice.test.tsx@@ -1,20 +1,25 @@// @vitest-environment jsdom//-// THE one thing standing between a hostile project.json and a grant (PR 3 Task 3.4): a cloned repo-// can arrive with `agentBrowserControl: true` already in its git-shared file. The notice must-// - appear on the project whose switch is on and whose machine-local entry holds no ack,+// THE one thing standing between a hostile project.json and a grant (PR 3 Task 3.4 + PR #213+// review fixes C1/I1): a cloned repo can arrive with `agentBrowserControl: true` already in its+// git-shared file. The notice must+// - appear on the project whose switch is on and whose machine-local entry holds no KEPT answer,// - name the project and what the switch permits (the capability's own copy, not a paraphrase),-// - be CLICK-ONLY (it was raised by a file, not by the user — confirm-key.ts's enterConfirms rule),-// - record the answer machine-locally (Project.capabilityAck → IndexEntryV3.capabilityAck; the-// shared file's bytes are pinned unchanged by workspace-files.test.ts "the ack is machine-local"-// and project-capability-consent.test.ts — the renderer cannot import src/core to re-assert it),-// - never grant while unanswered: projectCapabilityGranted is false until the click.+// - accept ONLY the two buttons as answers: Enter never confirms, Escape/overlay dismissal+// records NOTHING and re-shows next launch, and no button holds focus for a native Enter/Space+// to activate (I1),+// - record WHICH answer was given ('kept'/'declined') machine-locally (Project.capabilityAck →+// IndexEntryV3.capabilityAck; the shared file's bytes are pinned unchanged by+// workspace-files.test.ts "the ack is machine-local" — the renderer cannot import src/core to+// re-assert it),+// - never grant while unanswered or declined: a declined switch whose hostile `true` re-arrives+// via git is refused AND re-noticed, never silently granted (C1).import { describe, it, expect, beforeEach, afterEach } from 'vitest'import { act } from 'react'import { createRoot, type Root } from 'react-dom/client'import type { Project } from '@shared/types'-import { PROJECT_CAPABILITY_COPY, projectCapabilityEnabled } from '@shared/project-capabilities'-import { projectCapabilityGranted } from '@shared/project-capability-consent'+import { PROJECT_CAPABILITY_COPY } from '@shared/project-capabilities'+import { projectCapabilityGrantedFor } from '@shared/project-capability-consent'import { useProjects } from '../state/projects'import { CONFIRM_ARM_MS } from './confirm-key'import { CapabilityNotice } from './CapabilityNotice'@@ -59,14 +64,9 @@ function button(label: string): HTMLButtonElement {return el!}-/** The grantedness the ledger/messaging wiring would compute from the live store, per call. */+/** The grantedness the ledger/messaging wiring computes from the live store, per call. */function grantedNow(): boolean {- const p = useProjects.getState().getProject('p1')- return projectCapabilityGranted({- capability: cap,- enabledInFile: projectCapabilityEnabled(p, cap),- acknowledged: p?.capabilityAck?.[cap] === true- })+ return projectCapabilityGrantedFor(useProjects.getState().getProject('p1'), cap)}beforeEach(() => {@@ -83,7 +83,7 @@ afterEach(() => {})describe('the one-time clone notice', () => {- it('renders for an on-in-file, never-acknowledged project, naming the project and the grant', () => {+ it('renders for an on-in-file, never-answered project, naming the project and the grant', () => {mount()expect(dialog()).toBeTruthy()const text = dialog()!.textContent ?? ''@@ -108,32 +108,94 @@ describe('the one-time clone notice', () => {expect(useProjects.getState().getProject('p1')?.capabilityAck).toBeUndefined()})+ it('holds focus on NO button, so a native Enter/Space mid-typing cannot answer it (I1)', () => {+ // The real-browser hole: autoFocus would steal focus from whatever the user was typing in,+ // and their next Enter/Space would NATIVELY activate the focused button — a path the window+ // keydown listener (and enterConfirms) never sees. With autoFocusButtons={false} nothing in+ // the dialog takes focus, so there is no button for that keystroke to land on.+ const typing = document.createElement('input')+ document.body.appendChild(typing)+ typing.focus()+ mount()+ expect(dialog()).toBeTruthy()+ expect(document.activeElement).toBe(typing)+ for (const b of document.querySelectorAll('.confirm button')) {+ expect(document.activeElement).not.toBe(b)+ }+ typing.remove()+ })+it('does not grant while unanswered — the switch alone is not consent', () => {mount()expect(grantedNow()).toBe(false)})- it('"Keep it on": records the machine-local ack, leaves the shared field untouched, then grants', () => {+ it('"Keep it on": records the machine-local KEPT, leaves the shared field untouched, then grants', () => {mount()act(() => button('Keep it on').click())const p = useProjects.getState().getProject('p1')!- expect(p.capabilityAck).toEqual({ [cap]: true })+ expect(p.capabilityAck).toEqual({ [cap]: 'kept' })expect(p[cap]).toBe(true) // the git-shared half did not change — no bytes moved in the fileexpect(grantedNow()).toBe(true)expect(dialog()).toBeNull()})- it('"Turn it off": clears the field, records the answer, and still grants nothing', () => {+ it('"Turn it off": clears the field, records DECLINED, and still grants nothing', () => {mount()act(() => button('Turn it off').click())const p = useProjects.getState().getProject('p1')!expect(p[cap]).toBeUndefined()- expect(p.capabilityAck).toEqual({ [cap]: true })+ expect(p.capabilityAck).toEqual({ [cap]: 'declined' })expect(grantedNow()).toBe(false)expect(dialog()).toBeNull()})- it('a second open does not re-notify — the ack is once per project ever', () => {+ it('C1: a declined switch whose hostile true RE-ARRIVES is refused AND re-noticed — never a silent grant', () => {+ mount()+ act(() => button('Turn it off').click())+ unmount()+ // The user's field-deletion was only an uncommitted diff. A `git checkout`/pull restores the+ // hostile `true`; the watcher's re-read rebuilds the project from the file with the+ // machine-local ack threaded back in from the index entry — exactly this shape:+ act(() => {+ useProjects+ .getState()+ .replaceProject(project({ [cap]: true, capabilityAck: { [cap]: 'declined' } }))+ })+ expect(grantedNow()).toBe(false) // the standing "no" refuses; the bare-bit ack would grant here+ mount()+ expect(dialog()).toBeTruthy() // and the user is told AGAIN — a new notice, not silence+ })++ it('Escape is a NON-answer: nothing recorded, nothing granted, and the notice returns next launch (I1)', () => {+ mount()+ act(() => {+ window.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }))+ })+ expect(dialog()).toBeNull() // closed for this session…+ const p = useProjects.getState().getProject('p1')!+ expect(p.capabilityAck).toBeUndefined() // …but no answer was recorded+ expect(p[cap]).toBe(true) // and the user's working copy was not silently edited+ expect(grantedNow()).toBe(false)+ unmount()+ mount() // next launch+ expect(dialog()).toBeTruthy()+ })++ it('an overlay misclick is a NON-answer too (I1)', () => {+ mount()+ act(() => {+ document.querySelector<HTMLElement>('.confirm-overlay')!.click()+ })+ expect(dialog()).toBeNull()+ expect(useProjects.getState().getProject('p1')?.capabilityAck).toBeUndefined()+ expect(grantedNow()).toBe(false)+ unmount()+ mount()+ expect(dialog()).toBeTruthy()+ })++ it('a second open does not re-notify after an explicit KEEP — answered is answered', () => {mount()act(() => button('Keep it on').click())unmount()@@ -141,7 +203,7 @@ describe('the one-time clone notice', () => {expect(dialog()).toBeNull()})- it('never appears for a switch the user set personally — the setter is its own acknowledgment', () => {+ it('never appears for a switch the user set personally — the setter records its own KEPT', () => {useProjects.setState({ projects: [project()], activeProjectId: 'p1' })useProjects.getState().setProjectCapability('p1', cap, true)mount()diff --git a/src/renderer/components/settings/agents-capabilities.test.tsx b/src/renderer/components/settings/agents-capabilities.test.tsxindex c7839b1ea..f79c23d5c 100644--- a/src/renderer/components/settings/agents-capabilities.test.tsx+++ b/src/renderer/components/settings/agents-capabilities.test.tsx@@ -11,9 +11,9 @@ import type { Project } from '@shared/types'import {PROJECT_CAPABILITIES,PROJECT_CAPABILITY_COPY,- projectCapabilityEnabled+ projectCapabilityFlagInFile} from '@shared/project-capabilities'-import { projectCapabilityGranted } from '@shared/project-capability-consent'+import { projectCapabilityGrantedFor } from '@shared/project-capability-consent'import { useProjects } from '../../state/projects'import { AgentsSection } from './sections/AgentsSection'@@ -79,10 +79,10 @@ describe('per-project capability rows, generated from PROJECT_CAPABILITIES', ()mount()act(() => capSwitch(PROJECT_CAPABILITY_COPY[cap].label).click())const p = useProjects.getState().getProject('p1')!- expect(p[cap]).toBe(true) // === true, not "true"/1 — projectCapabilityEnabled is strict- // Setting it yourself is its own acknowledgment: no clone notice for the user's own switch.- expect(p.capabilityAck?.[cap]).toBe(true)- expect(projectCapabilityEnabled(p, cap)).toBe(true)+ expect(p[cap]).toBe(true) // === true, not "true"/1 — projectCapabilityFlagInFile is strict+ // Setting it yourself records its own KEPT: no clone notice for the user's own switch.+ expect(p.capabilityAck?.[cap]).toBe('kept')+ expect(projectCapabilityFlagInFile(p, cap)).toBe(true)})@@ -92,7 +92,11 @@ describe('per-project capability rows, generated from PROJECT_CAPABILITIES', ()useProjects.getState().setProjectCapability('p1', cap, true)mount()act(() => capSwitch(PROJECT_CAPABILITY_COPY[cap].label).click())- expect(useProjects.getState().getProject('p1')![cap]).toBeUndefined()+ const p = useProjects.getState().getProject('p1')!+ expect(p[cap]).toBeUndefined()+ // …and records DECLINED (PR #213 C1/M-2): if a teammate re-commits `true`, the project is+ // re-noticed and refused instead of silently re-granted through the old consent.+ expect(p.capabilityAck?.[cap]).toBe('declined')})@@ -102,14 +106,8 @@ describe('per-project capability rows, generated from PROJECT_CAPABILITIES', ()// the refusal immediately — no lease-start snapshot may answer for it.const cap = PROJECT_CAPABILITIES[0]useProjects.getState().setProjectCapability('p1', cap, true)- const grantedNow = (): boolean => {- const p = useProjects.getState().getProject('p1')- return projectCapabilityGranted({- capability: cap,- enabledInFile: projectCapabilityEnabled(p, cap),- acknowledged: p?.capabilityAck?.[cap] === true- })- }+ const grantedNow = (): boolean =>+ projectCapabilityGrantedFor(useProjects.getState().getProject('p1'), cap)expect(grantedNow()).toBe(true)mount()act(() => capSwitch(PROJECT_CAPABILITY_COPY[cap].label).click())diff --git a/src/renderer/components/settings/sections/AgentsSection.tsx b/src/renderer/components/settings/sections/AgentsSection.tsxindex 30687e6f5..af2972b13 100644--- a/src/renderer/components/settings/sections/AgentsSection.tsx+++ b/src/renderer/components/settings/sections/AgentsSection.tsx@@ -4,7 +4,7 @@ import { useProjects } from '../../../state/projects'import {PROJECT_CAPABILITIES,PROJECT_CAPABILITY_COPY,- projectCapabilityEnabled+ projectCapabilityFlagInFile} from '@shared/project-capabilities'import {isAgentEnabled,@@ -330,7 +330,10 @@ export function AgentsSection({ isActive }: { isActive: boolean }): React.JSX.Eldescription={`${PROJECT_CAPABILITY_COPY[cap].description} ${PROJECT_CAPABILITY_COPY[cap].cloneWarning}`}control={<Switch- checked={projectCapabilityEnabled(activeProject, cap)}+ // The raw FILE FLAG is the right thing for a settings switch to display — it+ // mirrors what is written in .nodeterm/project.json. It is NEVER the grant check:+ // grants require the machine-local 'kept' too (projectCapabilityGrantedFor).+ checked={projectCapabilityFlagInFile(activeProject, cap)}ariaLabel={title}disabled={!activeProject}onChange={(on) => {diff --git a/src/renderer/state/projects.ts b/src/renderer/state/projects.tsindex 6835337c5..edcb95e0e 100644--- a/src/renderer/state/projects.ts+++ b/src/renderer/state/projects.ts@@ -11,7 +11,7 @@ import type {} from '@shared/types'import { collisionSeed, derivedProjectId } from '@shared/project-id'import type { ProjectCapability } from '@shared/project-capabilities'-import { recordCapabilityAck } from '@shared/project-capability-consent'+import { recordCapabilityAck, type CapabilityAnswer } from '@shared/project-capability-consent'import { applyCanvasMutation, createProject, reorderGroupWithinParent } from './workspace'interface ProjectsState {@@ -70,17 +70,18 @@ interface ProjectsState {setProjectDefaultPermissionMode(id: string, mode: AgentPermissionMode | undefined): void/*** THE strict per-project capability setter (@shared/project-capabilities). `on` writes the- * literal `true` the validators accept AND records the machine-local ack — setting a switch- * yourself is its own acknowledgment, so the clone notice never fires on your own decision.- * `off` deletes the field outright (an off capability adds no bytes to the shared file); the- * ack, once earned, stays. */+ * literal `true` the validators accept AND records this machine's 'kept' answer — setting a+ * switch yourself is its own consent, so the clone notice never fires on your own decision.+ * `off` deletes the field outright (an off capability adds no bytes to the shared file) AND+ * records 'declined': if a teammate's (or a hostile) `true` re-arrives via git, the capability+ * is refused and re-noticed rather than silently re-granted (PR #213 C1/M-2). */setProjectCapability(id: string, cap: ProjectCapability, on: boolean): void/**- * Records this machine's answer to the one-time clone notice. MACHINE-LOCAL by construction:- * `Project.capabilityAck` rides `IndexEntryV3.capabilityAck` through splitWorkspace on the next- * save and is never written into .nodeterm/project.json (workspace-files.test.ts pins the file- * bytes; capability-notice.test.tsx pins this path). */- recordProjectCapabilityAck(id: string, cap: ProjectCapability): void+ * Records this machine's ANSWER ('kept' | 'declined') to the one-time clone notice.+ * MACHINE-LOCAL by construction: `Project.capabilityAck` rides `IndexEntryV3.capabilityAck`+ * through splitWorkspace on the next save and is never written into .nodeterm/project.json+ * (workspace-files.test.ts pins the file bytes; capability-notice.test.tsx pins this path). */+ recordProjectCapabilityAck(id: string, cap: ProjectCapability, answer: CapabilityAnswer): void/** Raises the project's dino high score (never lowers it). */setDinoHighScore(id: string, score: number): void/** Replaces the project's kanban board (the UI computes the next board via lib/kanban). */@@ -352,17 +353,19 @@ export const useProjects = create<ProjectsState>((set, get) => ({set((s) => ({projects: s.projects.map((p) => {if (p.id !== id) return p- if (on) return recordCapabilityAck({ ...p, [cap]: true }, cap)+ if (on) return recordCapabilityAck({ ...p, [cap]: true }, cap, 'kept')const next = { ...p }delete next[cap]- return next+ // 'declined', not silence: the deletion lives only in this working copy, so a re-arriving+ // `true` (teammate commit, git checkout) must re-notice instead of meeting a bare ack.+ return recordCapabilityAck(next, cap, 'declined')})}))},- recordProjectCapabilityAck(id, cap) {+ recordProjectCapabilityAck(id, cap, answer) {set((s) => ({- projects: s.projects.map((p) => (p.id === id ? recordCapabilityAck(p, cap) : p))+ projects: s.projects.map((p) => (p.id === id ? recordCapabilityAck(p, cap, answer) : p))}))},diff --git a/src/shared/project-capabilities.test.ts b/src/shared/project-capabilities.test.tsindex c07e9f242..3e6fc9614 100644--- a/src/shared/project-capabilities.test.ts+++ b/src/shared/project-capabilities.test.ts@@ -2,24 +2,29 @@ import { describe, it, expect } from 'vitest'import {PROJECT_CAPABILITIES,PROJECT_CAPABILITY_COPY,- projectCapabilityEnabled,+ projectCapabilityFlagInFile,readProjectCapabilities,projectCapabilityFields} from './project-capabilities'-describe('projectCapabilityEnabled is STRICT', () => {+describe('projectCapabilityFlagInFile is STRICT (and NEVER a grant check — see project-capability-consent)', () => {it('true enables', () => {- expect(projectCapabilityEnabled({ agentBrowserControl: true }, 'agentBrowserControl')).toBe(true)+ expect(projectCapabilityFlagInFile({ 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)+ expect(projectCapabilityFlagInFile({ 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)+ expect(projectCapabilityFlagInFile(undefined, 'agentBrowserControl')).toBe(false)+ expect(projectCapabilityFlagInFile(null, 'agentBrowserControl')).toBe(false)+ })+ it('a prototype-inherited true is OFF — own properties only (M-1)', () => {+ const inherited = Object.create({ agentBrowserControl: true }) as Record<string, unknown>+ expect(projectCapabilityFlagInFile(inherited, 'agentBrowserControl')).toBe(false)+ expect(readProjectCapabilities(inherited)).toEqual({})})})diff --git a/src/shared/project-capabilities.ts b/src/shared/project-capabilities.tsindex 951333087..e581bb7da 100644--- a/src/shared/project-capabilities.ts+++ b/src/shared/project-capabilities.ts@@ -50,23 +50,38 @@ export const PROJECT_CAPABILITY_COPY: Record<ProjectCapability, ProjectCapabilit}}-/** 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(+/**+ * Is the capability's raw switch set in this project's shared file? STRICT `=== true`, own+ * properties only: .nodeterm/project.json is hostile input — git-shared, hand-editable,+ * auto-adopted (@shared/node-exec) — so `"true"`, `1`, `{}` and a prototype-inherited `true` are+ * all off (`project-capabilities.test.ts` fails on any of them enabling).+ *+ * NEVER A GRANT CHECK (PR #213 review, I2). This reads the FILE BIT only and knows nothing of the+ * clone notice: during the pending-notice window — and after a recorded decline — it answers+ * `true` while the capability must refuse. It exists for exactly two kinds of caller: display (a+ * Settings switch showing the file's state) and the notice decider's `enabledInFile` input.+ * Grants go through `projectCapabilityGrantedFor` (@shared/project-capability-consent), pinned by+ * project-capability-consent.test.ts "a switch that is on but unanswered grants nothing".+ */+export function projectCapabilityFlagInFile(p: Partial<Record<ProjectCapability, unknown>> | undefined | null,cap: ProjectCapability): boolean {- return p?.[cap] === true+ if (!p || !Object.prototype.hasOwnProperty.call(p, cap)) return false+ return p[cap] === true}-/** The capability half of a ProjectFileV1, normalised: known keys only, literal `true` only. */+/** The capability half of a ProjectFileV1, normalised: known keys only, literal `true` only,+ * own properties only (M-1: no consent inherited through a prototype chain). */export function readProjectCapabilities(f: unknown): Partial<Record<ProjectCapability, true>> {const out: Partial<Record<ProjectCapability, true>> = {}if (!f || typeof f !== 'object') return outfor (const cap of PROJECT_CAPABILITIES) {- if ((f as Record<string, unknown>)[cap] === true) out[cap] = true+ if (+ Object.prototype.hasOwnProperty.call(f, cap) &&+ (f as Record<string, unknown>)[cap] === true+ )+ out[cap] = true}return out}diff --git a/src/shared/project-capability-consent.ts b/src/shared/project-capability-consent.tsindex b44e85783..134c1e10a 100644--- a/src/shared/project-capability-consent.ts+++ b/src/shared/project-capability-consent.ts@@ -10,50 +10,105 @@* entry is the only authority for project identity), never in the shared file; a second worktree* of the same repo is a second entry, hence a second notice, on purpose.*+ * THE ACK CARRIES THE ANSWER, not just the fact of one (PR #213 review, C1). "Turn it off" can+ * only delete the field from THIS working copy — the hostile `true` survives in git and a routine+ * `git checkout`/pull restores it. If the ack were a bare bit, that restored `true` would meet a+ * standing acknowledgment and grant silently to a user who explicitly said no. So:+ * - `'kept'` — explicit consent; enabled+kept is the ONE granting combination.+ * - `'declined'` — explicit refusal; if the file's `true` ever re-arrives it is refused AND a+ * NEW notice is raised (never silence, never a grant without a fresh "keep").+ * - absent — never answered (or dismissed without answering — dismissal is not an answer);+ * enabled+absent is a pending notice and a refusal.+ * Each rule is pinned by `project-capability-consent.test.ts`.+ ** Lives in `src/shared` for the same reason as `safe-id.ts`: the renderer raises the dialog and may* not import `src/core`; `core/project-capability-consent.ts` re-exports these for main/core* callers, and its test pins that the two paths are the same function objects.*/-import type { ProjectCapability } from './project-capabilities'+import {+ projectCapabilityFlagInFile,+ type ProjectCapability+} from './project-capabilities'++/** What this machine's user answered when told about a capability switch. */+export type CapabilityAnswer = 'kept' | 'declined'-/** The machine-local ack record, keyed like the capability fields but never written to the shared- * project file (`projectToFile` does not know this shape exists — pinned by the consent test). */-export type CapabilityAckMap = Partial<Record<ProjectCapability, true>>+/** The machine-local answer record, keyed like the capability fields but never written to the+ * shared project file (`projectToFile` does not know this shape exists — pinned by the consent+ * test with an ack-carrying project as input). */+export type CapabilityAckMap = Partial<Record<ProjectCapability, CapabilityAnswer>>export interface CapabilityConsentState {capability: ProjectCapability- /** The strict read of the shared file's switch (`projectCapabilityEnabled` — literal true only). */+ /** The strict read of the shared file's switch (`projectCapabilityFlagInFile` — literal true+ * only). NEVER a grant by itself. */enabledInFile: boolean- /** Has THIS MACHINE's user answered the notice for this project entry (or personally set the- * switch, which is its own acknowledgment)? */- acknowledged: boolean+ /** This machine's recorded answer for this project entry, if any. */+ answer: CapabilityAnswer | undefined}-/** On in the file + never acknowledged on this machine ⇒ notice. Everything else is silence:- * off needs no warning, and an answered notice is answered forever (per index entry). */+/** On in the file + not explicitly KEPT on this machine ⇒ notice. That covers both the+ * never-answered clone window and the re-arrival of a `true` the user declined (C1): a recorded+ * "no" makes a re-appearing switch a NEW event to be told about, not a settled one. Off needs no+ * warning, whatever was answered. */export function needsCapabilityNotice(s: CapabilityConsentState): boolean {- return s.enabledInFile === true && s.acknowledged !== true+ return s.enabledInFile === true && s.answer !== 'kept'}/**- * May the capability act RIGHT NOW? A pending notice is a refusal, not a grant: the window between- * a hostile clone's `agentBrowserControl: true` arriving and the user answering the notice must- * refuse (`project-capability-consent.test.ts` — "a switch that is on but unanswered grants- * nothing"). This is the predicate the browser ledger's admission check (PR 4) and messaging's- * `messagingEnabled` wiring (PR 6) consult per call — never cached at lease start.+ * May the capability act RIGHT NOW? Only `enabledInFile && answer === 'kept'`: a pending notice is+ * a refusal, and a recorded DECLINE is a refusal even when the hostile `true` re-arrives via git+ * (`project-capability-consent.test.ts` — "a switch that is on but unanswered grants nothing",+ * "a DECLINED switch grants nothing even when the file says true again"). This is the predicate+ * the browser ledger's admission check (PR 4) and messaging's `messagingEnabled` wiring (PR 6)+ * consult per call — never cached at lease start.*/export function projectCapabilityGranted(s: CapabilityConsentState): boolean {- return s.enabledInFile === true && !needsCapabilityNotice(s)+ return s.enabledInFile === true && s.answer === 'kept'}/**- * Returns `entry` with the capability acknowledged — a new object, input untouched. Works on any+ * THE consumer-facing grant check: derives both halves (strict file flag, own-property answer)+ * from a Project-shaped object, so a consumer cannot pick the raw file flag by mistake (PR #213+ * review, I2). PR 6 wires `messagingEnabled(projectId)` as+ * `projectCapabilityGrantedFor(getProject(projectId), 'agentMessaging')` — one call, nothing else.+ */+export function projectCapabilityGrantedFor(+ p:+ | (Partial<Record<ProjectCapability, unknown>> & { capabilityAck?: CapabilityAckMap })+ | undefined+ | null,+ cap: ProjectCapability+): boolean {+ return projectCapabilityGranted({+ capability: cap,+ enabledInFile: projectCapabilityFlagInFile(p, cap),+ answer: capabilityAnswerOf(p, cap)+ })+}++/** This machine's recorded answer, own properties only (M-1: an in-process object must not inherit+ * consent through its prototype; JSON never produces one, but callers are not only JSON). */+export function capabilityAnswerOf(+ p: { capabilityAck?: CapabilityAckMap } | undefined | null,+ cap: ProjectCapability+): CapabilityAnswer | undefined {+ const ack = p?.capabilityAck+ if (!ack || !Object.prototype.hasOwnProperty.call(ack, cap)) return undefined+ const v = ack[cap]+ return v === 'kept' || v === 'declined' ? v : undefined+}++/**+ * Returns `entry` with the capability answered — a new object, input untouched; a later answer+ * overwrites an earlier one (decline → later explicit keep must win, and vice versa). Works on any* entry-shaped record (`IndexEntryV3` in main, the renderer's `Project` mirror of the same- * machine-local field) so both sides record the ack through the one function.+ * machine-local field) so both sides record the answer through the one function.*/export function recordCapabilityAck<E extends { capabilityAck?: CapabilityAckMap }>(entry: E,- cap: ProjectCapability+ cap: ProjectCapability,+ answer: CapabilityAnswer): E {- return { ...entry, capabilityAck: { ...entry.capabilityAck, [cap]: true } }+ return { ...entry, capabilityAck: { ...entry.capabilityAck, [cap]: answer } }}diff --git a/src/shared/types.ts b/src/shared/types.tsindex 965373d2b..502e367f7 100644--- a/src/shared/types.ts+++ b/src/shared/types.ts@@ -471,18 +471,21 @@ export interface Project {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).+ * GIT-SHARED (rides .nodeterm/project.json) and therefore hostile input — the raw bit is read+ * ONLY through `projectCapabilityFlagInFile` (@shared/project-capabilities, strict `=== true`,+ * own-property), and it is NEVER a grant by itself: grants go through+ * `projectCapabilityGrantedFor` (@shared/project-capability-consent), which also requires this+ * machine's recorded 'kept' answer below.*/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+ * MACHINE-LOCAL record of what this machine's user ANSWERED for each capability switch —+ * 'kept' or 'declined', not a bare bit, because a declined switch whose hostile `true`+ * re-arrives via git must be refused and re-noticed, never silently granted (PR #213 C1).+ * 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>>+ capabilityAck?: import('./project-capability-consent').CapabilityAckMap/** 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. */