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
feat(canvas): choose per project which agent actions skip the confirm dialog (#1181)
priitkustalaee89eaaabeed
diff --git a/CLAUDE.md b/CLAUDE.mdindex f09d5fba6..d528cd02a 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -4465,7 +4465,19 @@ command-bearing opens; this does not add a human-confirm dialog or change mobileWaiving is not silence: every waived application raises the info strip through `waivedNotice`,which names the waiver that let it through — and, for the project scope, the PROJECT, since"this project" would point at whatever the user happens to be looking at — and every- per-project waiver is listed with a Revoke in Settings → Agents.+ per-project waiver is listed with a Revoke in Settings → Agents. **The per-project scope can+ also be set UP FRONT**, before any agent has asked: each project tab's ⌄ menu has an "Agents+ may, without asking" group with one toggle per `CONFIRM_WAIVABLE_VERBS` member (labels in+ `WAIVABLE_VERB_ACTIONS`). It writes the same `projects` map — the dialog grant, the toggle and+ the Settings revoke all go through ONE pure merge, `withProjectWaiver` (prune, set, sanitize) —+ so it is no new mechanism and nothing it does reaches `project.json`. **A row shows the+ EFFECTIVE answer, not the map entry**: `projectWaiverState` asks `decideControlConfirm` itself,+ with and without this project's grant, so an app-run, machine-wide or global-Bypass waiver shows+ as in effect, names itself (`otherWaiverHint`) and points at Settings → Agents — a row that read+ only the `projects` map promised "agents here ask you first" while the gate still skipped the+ dialog. Surfaces: Desktop only. It is hidden in the browser Server Edition+ (`isBrowserRuntime()`), whose headless control is gated by creator ownership and never by these+ waivers, and on a relay tab, whose confirms belong to that machine; mobile N/A.- **`bypassPermissions` needs TWO locks, and this is the trap to understand before touching it.**The permission mode is persisted to `.nodeterm/project.json`, which is **git-shared** — sokeying the waiver on the mode alone would let a repository the user CLONED silently disablediff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 9f4cc522f..c83e01bef 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -377,7 +377,11 @@ anything else. Board-level fields survive every transform — `pullLinks` is onefrom the start with "ask me again" selected, "don't ask again for agents in <project>"(machine-local, keyed by project id, pruned like `settings.sidebarCollapsedItems`) or "don't askagain in any project until nodeterm quits" (in-memory — not `settings.json`, not `localStorage`,- so quitting restores the gate). Hiding a reach behind a checkbox made it read as missing. The machine-WIDE waiver stays Settings-only, because that is+ so quitting restores the gate). Hiding a reach behind a checkbox made it read as missing. The+ per-project answer can also be given up front from the project tab's "Agents may, without asking"+ menu; it writes the same machine-local map through the same `withProjectWaiver`, never a second+ copy of the merge, and each row shows what the gate will actually do (`projectWaiverState`), so+ an app-run or global waiver is named rather than hidden behind an unchecked box. The machine-WIDE waiver stays Settings-only, because that isthe one a stray click in a dialog that appeared under the user's hands must not be able to grant.Offering only the app-run one was its own failure: it is not what a user who ticks "don't askagain" means, so the real choices were "be asked forever" or "turn it off everywhere". Two rulesdiff --git a/src/renderer/components/TabBar.test.tsx b/src/renderer/components/TabBar.test.tsxindex a0a1adb6d..8cb8d694b 100644--- a/src/renderer/components/TabBar.test.tsx+++ b/src/renderer/components/TabBar.test.tsx@@ -565,3 +565,130 @@ describe('TabBar location tooltip', () => {expect(tooltip()).toBeNull()})})++describe('TabBar caret menu — "Agents may, without asking" (per-project confirm waivers)', () => {+ let root: Root+ let host: HTMLElement+ let useSettings: typeof import('../state/settings').useSettings++ const menuButton = (label: string): HTMLButtonElement | undefined =>+ Array.from(document.querySelectorAll<HTMLButtonElement>('.tab-menu button')).find((b) =>+ // A group row's text carries its ▸ caret, an item row's a leading ✓ — match the label.+ (b.textContent ?? '').replace('▸', '').trim().endsWith(label)+ )+ const waivers = (): unknown => useSettings.getState().settings.controlConfirmWaivers++ async function mount(over: Partial<Project> = {}, seed?: unknown): Promise<void> {+ const { TabBar, useProjects } = await load()+ useSettings = (await import('../state/settings')).useSettings+ // update() schedules a coalesced save through the bridge; give it somewhere to land.+ ;(window as unknown as { nodeTerminal: unknown }).nodeTerminal = {+ settings: { save: vi.fn(async () => undefined) }+ }+ useSettings.setState((s) => ({+ settings: { ...s.settings, controlConfirmWaivers: seed as never }+ }))+ host = document.createElement('div')+ document.body.appendChild(host)+ useProjects.setState({ projects: [project(over)], activeProjectId: 'p1' })+ root = createRoot(host)+ await act(async () => {+ root.render(+ <TabBar+ onSwitch={vi.fn()}+ onReconnect={vi.fn()}+ onReorder={vi.fn()}+ onOpenWelcome={vi.fn()}+ onRename={vi.fn()}+ onSetFolder={vi.fn()}+ onCloseProject={vi.fn()}+ onRemoteAccess={vi.fn()}+ onSetDefaultAccount={vi.fn()}+ onSetDefaultPermissionMode={vi.fn()}+ onOpenProjectSettings={vi.fn()}+ />+ )+ })+ await click(host.querySelector<HTMLButtonElement>('.tab__caret')!)+ }++ afterEach(() => {+ act(() => root.unmount())+ host.remove()+ })++ it('asks by default: every row is unchecked until the user opts in', async () => {+ await mount()+ await click(menuButton('Agents may, without asking')!)+ for (const label of ['Close nodes', 'Type into terminals', 'Open or add projects']) {+ const row = menuButton(label)+ expect(row, label).toBeDefined()+ expect(row!.querySelector('.tab-menu__check')!.textContent).toBe('')+ }+ })++ it('waives close for THIS project only, machine-locally, and turns it back off', async () => {+ await mount()+ await click(menuButton('Agents may, without asking')!)+ await click(menuButton('Close nodes')!)+ // The same settings.json map the dialog's "Don't ask again for agents in …" writes.+ expect(waivers()).toEqual({ projects: { p1: ['close'] } })+ // The menu stays open so several rows can be set in one visit, and the row shows its state.+ expect(menuButton('Close nodes')!.querySelector('.tab-menu__check')!.textContent).toBe('✓')+ expect(menuButton('Type into terminals')!.querySelector('.tab-menu__check')!.textContent).toBe('')+ await click(menuButton('Close nodes')!)+ expect(waivers()).toEqual({})+ })++ it('shows a machine-wide waiver as on, but sends the user to Settings to change it', async () => {+ await mount({}, { always: ['close'] })+ await click(menuButton('Agents may, without asking')!)+ const row = menuButton('Close nodes')!+ expect(row.disabled).toBe(true)+ expect(row.title).toContain('Settings → Agents')+ expect(row.querySelector('.tab-menu__check')!.textContent).toBe('✓')+ })++ it('offers nothing on a relay tab — that machine owns its agents’ confirms', async () => {+ await mount({ remote: { peerId: 'x' } as never })+ expect(menuButton('Agents may, without asking')).toBeUndefined()+ })++ it('offers nothing in the browser Server Edition, where these waivers gate nothing', async () => {+ ;(await import('../bridge/runtime')).markBrowserRuntime()+ await mount()+ expect(menuButton('Agents may, without asking')).toBeUndefined()+ })++ it('shows an app-run waiver as in effect and never promises a dialog it would not raise', async () => {+ await mount()+ const { useControlConfirm } = await import('../state/controlConfirm')+ await act(async () => useControlConfirm.getState().waiveForSession('close'))+ await click(menuButton('Agents may, without asking')!)+ const row = menuButton('Close nodes')!+ expect(row.querySelector('.tab-menu__check')!.textContent).toBe('✓')+ expect(row.disabled).toBe(true)+ expect(row.title).toContain('until nodeterm quits')+ expect(row.title).not.toContain('ask you first')+ })++ it('under global Bypass, removing the project grant says the dialog still will not come', async () => {+ await mount({}, { projects: { p1: ['close'] }, bypassMode: true })+ await act(async () =>+ useSettings.setState((s) => ({+ settings: { ...s.settings, claudePermissionMode: 'bypassPermissions' }+ }))+ )+ await click(menuButton('Agents may, without asking')!)+ const row = menuButton('Close nodes')!+ expect(row.disabled).toBe(false)+ expect(row.title).toContain('Bypass')+ expect(row.title).not.toContain('Click to ask again')+ await click(row)+ // The project grant is gone, the gate still skips — and the row says why.+ expect(waivers()).toEqual({ bypassMode: true })+ const after = menuButton('Close nodes')!+ expect(after.querySelector('.tab-menu__check')!.textContent).toBe('✓')+ expect(after.disabled).toBe(true)+ })+})diff --git a/src/renderer/components/TabBar.tsx b/src/renderer/components/TabBar.tsxindex a6170b724..08007bf14 100644--- a/src/renderer/components/TabBar.tsx+++ b/src/renderer/components/TabBar.tsx@@ -26,6 +26,10 @@ import {import { bypassSandboxCaveat, permissionModeAgentsLabel } from '@shared/agents/approval-mode'import { codexApprovalCaps } from '@renderer/state/codexCli'import { PROJECT_NAME_MAX, clampProjectName } from '@shared/project-name'+import { CONFIRM_WAIVABLE_VERBS, WAIVABLE_VERB_ACTIONS, otherWaiverHint } from '@shared/control-confirm'+import { projectWaiverRow, setControlConfirmWaivedForProject } from '../state/controlConfirmGate'+import { useControlConfirm } from '../state/controlConfirm'+import { isBrowserRuntime } from '../bridge/runtime'interface TabBarProps {onSwitch: (id: string) => void@@ -136,6 +140,13 @@ export function TabBar({const [acctOpen, setAcctOpen] = useState(false)// Whether the caret menu's "Default permission mode" group is expanded (same idiom as acctOpen).const [modeOpen, setModeOpen] = useState(false)+ const [agentActsOpen, setAgentActsOpen] = useState(false)+ // Per-project agent confirm rows read the live gate (`projectWaiverRow`) at render. These+ // subscriptions are what re-render the menu when any input of that decision changes: the+ // persisted waivers, the app-run ones, and the global permission mode (`globalMode` below; a+ // project's own mode arrives with the projects store).+ useSettings((s) => s.settings.controlConfirmWaivers)+ useControlConfirm((s) => s.sessionWaived)const claudeAccounts = useSettings((s) => s.settings.claudeAccounts)// The mode a project without an override falls back to, shown in the "Use global (…)" entry.const globalMode = useSettings((s) => s.settings.claudePermissionMode)@@ -178,6 +189,7 @@ export function TabBar({setMenuPos(null)setAcctOpen(false)setModeOpen(false)+ setAgentActsOpen(false)}const openMenu = (id: string, anchor: HTMLElement) => {@@ -666,6 +678,59 @@ export function TabBar({))}</div>)}+ {+ // Agent canvas-control confirms, per project: the SAME machine-local waiver the+ // dialog's "Don't ask again for agents in …" grants (settings.json, never the+ // git-shared project.json), reachable before any dialog has appeared. ✓ means agents+ // in this project do it WITHOUT asking — the EFFECTIVE answer, read through the gate's+ // own table (`projectWaiverRow`), so an app-run, machine-wide or Bypass waiver shows+ // here too instead of the row promising a dialog that will not come.+ // Desktop only: in the browser Server Edition canvas control is headless and gated by+ // creator ownership, not by these waivers (@shared/control-confirm), so the rows would+ // change nothing. A relay tab is another machine's project and its confirms are that+ // machine's to waive.+ !menuProject.remote &&+ !isBrowserRuntime() && (+ <>+ <button+ className={`tab-menu__group${agentActsOpen ? ' open' : ''}`}+ onClick={() => setAgentActsOpen((v) => !v)}+ >+ Agents may, without asking+ <span className="tab-menu__caret">▸</span>+ </button>+ {agentActsOpen && (+ <div className="tab-menu__sub">+ {[...CONFIRM_WAIVABLE_VERBS].map((verb) => {+ const row = projectWaiverRow(verb, menuProject.id)+ // Another waiver still applies without this project's grant, so the row+ // cannot make agents ask again — name it and where it is revoked.+ const elsewhere = row.otherVia !== null+ return (+ <button+ key={verb}+ disabled={elsewhere && !row.granted}+ title={+ elsewhere+ ? otherWaiverHint(row.otherVia!)+ : row.granted+ ? `Agents in "${menuProject.name}" do this without a confirm dialog (this computer only). Click to ask again.`+ : `Agents in "${menuProject.name}" ask you first. Click to let them do this without asking (this computer only).`+ }+ onClick={() => {+ setControlConfirmWaivedForProject(verb, menuProject.id, !row.granted)+ }}+ >+ <span className="tab-menu__check">{row.skips ? '✓' : ''}</span>+ {WAIVABLE_VERB_ACTIONS[verb] ?? verb}+ </button>+ )+ })}+ </div>+ )}+ </>+ )+ }<buttononClick={() => {onOpenProjectSettings(menuProject.id)diff --git a/src/renderer/components/settings/sections/AgentsSection.tsx b/src/renderer/components/settings/sections/AgentsSection.tsxindex e43de29b2..918c2cf6d 100644--- a/src/renderer/components/settings/sections/AgentsSection.tsx+++ b/src/renderer/components/settings/sections/AgentsSection.tsx@@ -46,8 +46,8 @@ import { chipFor } from '../../../lib/keybindingOverrides'import { NODE_IDENTITY_STRICT_DATE } from '@shared/node-identity'import {CONFIRM_WAIVABLE_VERBS,- pruneControlConfirmWaivers,- sanitizeControlConfirmWaivers+ sanitizeControlConfirmWaivers,+ withProjectWaiver} from '@shared/control-confirm'import { useControlConfirm } from '../../../state/controlConfirm'import { SegmentedPill } from '@renderer/ui/SegmentedPill'@@ -382,18 +382,11 @@ export function AgentsSection({ isActive }: { isActive: boolean }): React.JSX.El})).filter((r) => r.name !== undefined).sort((a, b) => (a.name ?? '').localeCompare(b.name ?? ''))- /** Revoke one verb's per-project waiver. Prunes dead projects in the same write — this section- * is the only surface that ever sees the whole map, so it is the natural place to tidy it. */+ /** Revoke one verb's per-project waiver. Prunes dead projects in the same write, through the one+ * merge every per-project writer shares (`withProjectWaiver`). */const revokeProjectWaiver = (projectId: string, verb: string): void => {const live = new Set(allProjects.map((p) => p.id))- const pruned = pruneControlConfirmWaivers(waivers, live)- const rest = (pruned.projects?.[projectId] ?? []).filter((v) => v !== verb)- const projects = { ...(pruned.projects ?? {}) }- if (rest.length) projects[projectId] = rest- else delete projects[projectId]- update({- controlConfirmWaivers: sanitizeControlConfirmWaivers({ ...pruned, projects })- })+ update({ controlConfirmWaivers: withProjectWaiver(waivers, projectId, verb, false, live) })}const activeProjectId = useProjects((s) => s.activeProjectId)const activeProject = useProjects((s) => s.projects.find((p) => p.id === activeProjectId))@@ -690,10 +683,10 @@ export function AgentsSection({ isActive }: { isActive: boolean }): React.JSX.El<FieldRowlabel="Waived in these projects"// The rule this section exists for: every loosening stays visible and revocable. A- // per-project waiver is granted from a DIALOG, which is gone the moment it is- // answered — so without this row the grant would be permanent, invisible, and- // findable only by hand-editing settings.json.- description="You chose \u201cDon\u2019t ask again for agents in \u2026\u201d in an agent\u2019s dialog. These survive restarts, and apply only to agents running in the project named. A project you delete takes its waivers with it."+ // per-project waiver is granted from a DIALOG (gone the moment it is answered) or a+ // project tab's menu (one project at a time) — so this row is the one consolidated list+ // of grants across every project.+ description="You chose \u201cDon\u2019t ask again for agents in \u2026\u201d in an agent’s dialog, or switched it on in the project tab’s “Agents may, without asking” menu. These survive restarts, and apply only to agents running in the project named. A project you delete takes its waivers with it."control={<div className="flex flex-col items-end gap-2">{projectWaiverRows.map((row) =>diff --git a/src/renderer/state/controlConfirmGate.ts b/src/renderer/state/controlConfirmGate.tsindex 6e23323a7..9b6f42087 100644--- a/src/renderer/state/controlConfirmGate.ts+++ b/src/renderer/state/controlConfirmGate.ts@@ -1,8 +1,9 @@import {decideControlConfirm,isWaivableVerb,- pruneControlConfirmWaivers,+ projectWaiverState,sanitizeControlConfirmWaivers,+ withProjectWaiver,type ControlConfirmDecision,type ControlConfirmWaivers} from '@shared/control-confirm'@@ -66,8 +67,8 @@ export function controlConfirmDecision(* `live` is every project the store holds, closed ones included — a closed project is parked, not* gone.*- * The id being GRANTED survives the prune because the merge below happens after it, not because- * of any exemption inside it — which matters for a project that went away between the dialog+ * The id being GRANTED survives the prune because `withProjectWaiver` merges after pruning, not+ * because of any exemption inside it — which matters for a project that went away between the dialog* appearing and the user answering it: their answer is still honoured. (`pruneCollapsedItems` has* an explicit `keepKey` for this; here the write order already says it, and a second mechanism* saying the same thing would be one no test could turn red.)@@ -76,23 +77,53 @@ export function controlConfirmDecision(* report a waiver it did not get.*/export function waiveControlConfirmForProject(verb: string, projectId: string | undefined): boolean {+ return setControlConfirmWaivedForProject(verb, projectId, true)+}++/**+ * Turn one verb's per-project waiver on or off — what the project tab menu's toggle calls, and the+ * dialog grant above with `on = true`. The merge (prune, then set, then sanitize) is the pure+ * `withProjectWaiver`, shared with the revoke row in Settings → Agents.+ *+ * Returns false when nothing could change (an unwaivable verb, or no project).+ */+export function setControlConfirmWaivedForProject(+ verb: string,+ projectId: string | undefined,+ on: boolean+): boolean {if (!isWaivableVerb(verb) || !projectId) return false- const current = activeControlConfirmWaivers()const live = new Set(useProjects.getState().projects.map((p) => p.id))- const pruned = pruneControlConfirmWaivers(current, live)- const next = {- ...pruned,- projects: {- ...(pruned.projects ?? {}),- [projectId]: [...new Set([...(pruned.projects?.[projectId] ?? []), verb])]- }- }- // Sanitized on the way OUT as well as in: the write is the file, and every other writer of this- // key does the same, so a bug here cannot persist a shape the readers would then drop in silence.- useSettings.getState().update({ controlConfirmWaivers: sanitizeControlConfirmWaivers(next) })+ const next = withProjectWaiver(activeControlConfirmWaivers(), projectId, verb, on, live)+ useSettings.getState().update({ controlConfirmWaivers: next })return true}+/**+ * `projectWaiverState` bound to the live stores, for the project tab menu's per-project toggle.+ * The same inputs `controlConfirmDecision` weighs for a call acting on `projectId` — app-run+ * waivers, the persisted ones, and the permission mode WITH its source — so the row and the gate+ * cannot disagree. Callers that render it must also subscribe to those stores to re-render.+ */+export function projectWaiverRow(+ verb: string,+ projectId: string+): ReturnType<typeof projectWaiverState> {+ const { settings } = useSettings.getState()+ const { mode, source } = resolvePermissionModeWithSource(+ useProjects.getState().getProject(projectId),+ settings+ )+ return projectWaiverState({+ verb,+ projectId,+ sessionWaived: sessionWaivedVerbs(),+ persisted: activeControlConfirmWaivers(),+ permissionMode: mode,+ permissionModeSource: source+ })+}+/** The sanitized persisted waivers. `settings.json` is hand-editable, so this is the ONE read. */export function activeControlConfirmWaivers(): ControlConfirmWaivers {return sanitizeControlConfirmWaivers(useSettings.getState().settings.controlConfirmWaivers)diff --git a/src/shared/control-confirm.test.ts b/src/shared/control-confirm.test.tsindex 415175240..3cfa5ec1f 100644--- a/src/shared/control-confirm.test.ts+++ b/src/shared/control-confirm.test.ts@@ -8,6 +8,10 @@ import {expiredDialogNotice,isWaivableVerb,pruneControlConfirmWaivers,+ withProjectWaiver,+ WAIVABLE_VERB_ACTIONS,+ projectWaiverState,+ otherWaiverHint,sanitizeControlConfirmWaivers,waiveChoices,waivedNotice@@ -441,3 +445,97 @@ describe('waiveChoices — what the dialog offers, and what each choice promisesexpect(project.label).not.toContain('undefined')})})++describe('withProjectWaiver — the one write behind every per-project toggle', () => {+ const live = new Set(['p1', 'p2'])++ it('adds a verb to one project and leaves the rest of the waivers alone', () => {+ expect(withProjectWaiver({ always: ['write'] }, 'p1', 'close', true, live)).toEqual({+ always: ['write'],+ projects: { p1: ['close'] }+ })+ })++ it('removes a verb and drops the project key once it waives nothing', () => {+ const w = { projects: { p1: ['close', 'write'], p2: ['close'] } }+ expect(withProjectWaiver(w, 'p1', 'close', false, live)).toEqual({+ projects: { p1: ['write'], p2: ['close'] }+ })+ expect(withProjectWaiver(w, 'p2', 'close', false, live)).toEqual({+ projects: { p1: ['close', 'write'] }+ })+ })++ it('is idempotent and prunes projects that no longer exist', () => {+ const w = { projects: { gone: ['close'], p1: ['close'] } }+ expect(withProjectWaiver(w, 'p1', 'close', true, live)).toEqual({ projects: { p1: ['close'] } })+ })++ it('keeps the answer for the target even if that project vanished meanwhile', () => {+ expect(withProjectWaiver({}, 'late', 'close', true, live)).toEqual({ projects: { late: ['close'] } })+ })++ it('refuses an unwaivable verb or a missing project — nothing changes', () => {+ expect(withProjectWaiver({}, 'p1', 'settings', true, live)).toEqual({})+ expect(withProjectWaiver({}, undefined, 'close', true, live)).toEqual({})+ })++ it('has a menu label for every waivable verb', () => {+ for (const v of CONFIRM_WAIVABLE_VERBS) expect(WAIVABLE_VERB_ACTIONS[v], v).toBeTruthy()+ })+})++describe('projectWaiverState — what the per-project toggle may honestly show', () => {+ const base = { verb: 'close', projectId: 'p1' }++ it('asks by default', () => {+ expect(projectWaiverState(base)).toEqual({ granted: false, skips: false, otherVia: null })+ })++ it('reports the project grant, with nothing else in play', () => {+ expect(projectWaiverState({ ...base, persisted: { projects: { p1: ['close'] } } })).toEqual({+ granted: true,+ skips: true,+ otherVia: null+ })+ })++ it('names an app-run waiver that skips the dialog with or without the project grant', () => {+ const session = new Set(['close'])+ expect(projectWaiverState({ ...base, sessionWaived: session })).toEqual({+ granted: false,+ skips: true,+ otherVia: 'session'+ })+ // Removing the project grant would restore nothing — the row must not promise "ask again".+ expect(+ projectWaiverState({ ...base, sessionWaived: session, persisted: { projects: { p1: ['close'] } } })+ ).toEqual({ granted: true, skips: true, otherVia: 'session' })+ })++ it('names the machine-wide waiver', () => {+ expect(projectWaiverState({ ...base, persisted: { always: ['close'] } }).otherVia).toBe('always')+ })++ it('names global Bypass, but never a Bypass that came from the project file', () => {+ const bypass = { persisted: { bypassMode: true }, permissionMode: 'bypassPermissions' as const }+ expect(projectWaiverState({ ...base, ...bypass, permissionModeSource: 'global' }).otherVia).toBe('bypass')+ expect(projectWaiverState({ ...base, ...bypass, permissionModeSource: 'project' })).toEqual({+ granted: false,+ skips: false,+ otherVia: null+ })+ })++ it('never reports settings as waivable, whatever the file says', () => {+ expect(+ projectWaiverState({ ...base, verb: 'settings', persisted: { projects: { p1: ['settings'] } } })+ ).toEqual({ granted: false, skips: false, otherVia: null })+ })++ it('points every other waiver at the place it is revoked', () => {+ for (const via of ['session', 'always', 'bypass'] as const) {+ expect(otherWaiverHint(via)).toContain('Settings → Agents')+ }+ })+})diff --git a/src/shared/control-confirm.ts b/src/shared/control-confirm.tsindex a82221aa6..06fca010b 100644--- a/src/shared/control-confirm.ts+++ b/src/shared/control-confirm.ts@@ -103,7 +103,9 @@ export interface ControlConfirmWaivers {* forever" or "turn it off everywhere". A user who trusts the orchestrator in one repo should be* able to say exactly that, and this is the scope the DIALOG may therefore grant: it is bounded* by a project the user is looking at, revocable from Settings, and it cannot follow them into- * the repo where they do not trust it.+ * the repo where they do not trust it. The project tab's "Agents may, without asking" menu sets+ * the same entries up front, before any dialog has appeared; every writer goes through+ * `withProjectWaiver`.** SHAPE follows `settings.sidebarCollapsedItems`, the established per-project machine-local* state, PRUNING INCLUDED (`pruneControlConfirmWaivers`): settings.json is forever and project@@ -323,6 +325,81 @@ export function pruneControlConfirmWaivers(return out}+/**+ * Turn ONE verb's per-project waiver on or off — the single write every surface goes through: the+ * dialog's "Don't ask again for agents in …", the project tab menu's per-project toggle, and the+ * revoke row in Settings → Agents. One merge, so the three cannot drift apart on the prune or the+ * sanitize — the kind of drift this file exists to prevent.+ *+ * Prunes dead projects first (see `pruneControlConfirmWaivers`); the target project survives the+ * prune because the merge happens after it, so a project that went away while a dialog was open+ * still gets the answer the user gave. An unwaivable verb or a missing project id changes nothing.+ * The result is sanitized, so no writer can persist a shape the readers would then drop in silence.+ */+export function withProjectWaiver(+ waivers: ControlConfirmWaivers,+ projectId: string | undefined,+ verb: string,+ on: boolean,+ live: ReadonlySet<string>+): ControlConfirmWaivers {+ if (!projectId || !isWaivableVerb(verb)) return sanitizeControlConfirmWaivers(waivers)+ const pruned = pruneControlConfirmWaivers(waivers, live)+ const current = pruned.projects?.[projectId] ?? []+ const nextVerbs = on ? [...new Set([...current, verb])] : current.filter((v) => v !== verb)+ const projects = { ...(pruned.projects ?? {}) }+ if (nextVerbs.length) projects[projectId] = nextVerbs+ else delete projects[projectId]+ return sanitizeControlConfirmWaivers({ ...pruned, projects })+}++/**+ * What a per-project toggle (the project tab menu's "Agents may, without asking" row) can honestly+ * show for one verb: whether THIS project's waiver is granted, and whether the verb would still+ * skip its dialog WITHOUT that grant — because of the app-run, machine-wide or bypass waiver.+ *+ * Asked through `decideControlConfirm` itself, never re-derived: a row that read only the+ * `projects` map would promise "agents here ask you first" while an app-run waiver or the+ * global-Bypass lock still waives the dialog, and "click to ask again" when removing the project+ * grant restores nothing. `otherVia` is the waiver that would still apply, so the row can name it+ * and send the user to the control that revokes it (`otherWaiverHint`).+ */+export function projectWaiverState(+ input: Omit<Parameters<typeof decideControlConfirm>[0], 'projectId'> & { projectId: string }+): { granted: boolean; skips: boolean; otherVia: ConfirmWaiverVia | null } {+ const { verb, projectId, persisted } = input+ const granted = !!sanitizeControlConfirmWaivers(persisted).projects?.[projectId]?.includes(verb)+ const without = withProjectWaiver(persisted ?? {}, projectId, verb, false, new Set([projectId]))+ const otherVia = decideControlConfirm({ ...input, persisted: without }).via+ return { granted, skips: granted || otherVia !== null, otherVia }+}++/** Why a verb skips its dialog even without the project's own waiver — the tooltip on that row. */+export function otherWaiverHint(via: ConfirmWaiverVia): string {+ switch (via) {+ case 'session':+ return 'Waived in every project until nodeterm quits — revoke it in Settings → Agents.'+ case 'always':+ return 'Waived permanently in every project on this computer — change it in Settings → Agents.'+ case 'bypass':+ return 'Not asked while your global permission mode is Bypass and the Bypass waiver is on — Settings → Agents.'+ default:+ return 'Waived for this project.'+ }+}++/**+ * What each waivable verb lets an agent do, phrased for the project tab menu's per-project toggle+ * ("Agents may, without asking: Close nodes"). The menu iterates `CONFIRM_WAIVABLE_VERBS` and a+ * test asserts every member has a label here, so a verb joining that table cannot render as a+ * blank row.+ */+export const WAIVABLE_VERB_ACTIONS: Readonly<Record<string, string>> = {+ close: 'Close nodes',+ write: 'Type into terminals',+ 'open-project': 'Open or add projects'+}+/*** The user-visible line a dialog raises when it collects itself unanswered — ONE sentence for every* expiring dialog (`useExpiringDialog`), because a session that raises two differently-worded