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(settings): per-project capability rows, rendered from the capability list

Claude Code665f2f916bad
diff --git a/src/renderer/components/settings/agents-capabilities.test.tsx b/src/renderer/components/settings/agents-capabilities.test.tsx
new file mode 100644
index 000000000..c7839b1ea
--- /dev/null
+++ b/src/renderer/components/settings/agents-capabilities.test.tsx
@@ -0,0 +1,127 @@
+// @vitest-environment jsdom
+//
+// Settings → Agents: the per-project capability rows are GENERATED from PROJECT_CAPABILITIES.
+// Every assertion below iterates the array rather than naming rows: a capability added to the
+// union without a rendered row (the hand-written-list failure this repo has already documented)
+// fails here, and agent messaging's row (its PR 6) must appear by adding a copy entry only.
+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
+import { act } from 'react'
+import { createRoot, type Root } from 'react-dom/client'
+import type { Project } from '@shared/types'
+import {
+ PROJECT_CAPABILITIES,
+ PROJECT_CAPABILITY_COPY,
+ projectCapabilityEnabled
+} from '@shared/project-capabilities'
+import { projectCapabilityGranted } from '@shared/project-capability-consent'
+import { useProjects } from '../../state/projects'
+import { AgentsSection } from './sections/AgentsSection'
+
+;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
+
+const project = (over: Partial<Project> = {}): Project => ({
+ id: 'p1',
+ name: 'my-canvas',
+ color: '#7aa2f7',
+ viewport: { x: 0, y: 0, zoom: 1 },
+ nodes: [],
+ ...over
+})
+
+let root: Root
+let host: HTMLElement
+
+function mount(): void {
+ host = document.createElement('div')
+ document.body.appendChild(host)
+ root = createRoot(host)
+ act(() => root.render(<AgentsSection isActive />))
+}
+
+function capSwitch(label: string): HTMLElement {
+ const el = host.querySelector<HTMLElement>(`[role="switch"][aria-label="${label}"]`)
+ expect(el, `a rendered switch for "${label}"`).toBeTruthy()
+ return el!
+}
+
+beforeEach(() => {
+ ;(window as unknown as { nodeTerminal: unknown }).nodeTerminal = {
+ settings: { save: vi.fn(async () => undefined) },
+ claude: { cliCaps: vi.fn(async () => null) }
+ }
+ useProjects.setState({ projects: [project()], activeProjectId: 'p1', reloadNonce: 0 })
+})
+
+afterEach(() => {
+ act(() => root.unmount())
+ host.remove()
+ useProjects.setState({ projects: [], activeProjectId: '' })
+})
+
+describe('per-project capability rows, generated from PROJECT_CAPABILITIES', () => {
+ it('renders one row per capability, naming the active project, the grant and what travels', () => {
+ mount()
+ const text = host.textContent ?? ''
+ for (const cap of PROJECT_CAPABILITIES) {
+ const copy = PROJECT_CAPABILITY_COPY[cap]
+ capSwitch(copy.label)
+ expect(text).toContain(copy.description)
+ // The same "this is in the project file" sentence the clone notice shows: the two
+ // git-shared grants read alike wherever the switch is set.
+ expect(text).toContain(copy.cloneWarning)
+ }
+ expect(text).toContain('my-canvas')
+ })
+
+ it.each([...PROJECT_CAPABILITIES])(
+ 'toggling %s on writes the literal true the strict validators accept, plus this machine’s ack',
+ (cap) => {
+ 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)
+ }
+ )
+
+ it.each([...PROJECT_CAPABILITIES])(
+ 'toggling %s off deletes the field outright — no bytes, and never a stored false',
+ (cap) => {
+ useProjects.getState().setProjectCapability('p1', cap, true)
+ mount()
+ act(() => capSwitch(PROJECT_CAPABILITY_COPY[cap].label).click())
+ expect(useProjects.getState().getProject('p1')![cap]).toBeUndefined()
+ }
+ )
+
+ it('turning a capability off takes effect LIVE: every read consults the store, nothing caches', () => {
+ // PR 6 Task 6.4 depends on this shape: the browser ledger / messagingEnabled read the switch
+ // per call. Simulate two consecutive calls around an off-toggle and require the second to see
+ // 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
+ })
+ }
+ expect(grantedNow()).toBe(true)
+ mount()
+ act(() => capSwitch(PROJECT_CAPABILITY_COPY[cap].label).click())
+ expect(grantedNow()).toBe(false)
+ })
+
+ it('with no project open the switch is disabled — a capability needs a project to belong to', () => {
+ useProjects.setState({ projects: [], activeProjectId: '' })
+ mount()
+ for (const cap of PROJECT_CAPABILITIES) {
+ const el = capSwitch(PROJECT_CAPABILITY_COPY[cap].label)
+ expect(el.getAttribute('aria-disabled') === 'true' || el.hasAttribute('disabled')).toBe(true)
+ }
+ })
+})
diff --git a/src/renderer/components/settings/sections/AgentsSection.tsx b/src/renderer/components/settings/sections/AgentsSection.tsx
index 377ed6bda..30687e6f5 100644
--- a/src/renderer/components/settings/sections/AgentsSection.tsx
+++ b/src/renderer/components/settings/sections/AgentsSection.tsx
@@ -1,5 +1,11 @@
import { useEffect, useState } from 'react'
import { useSettings } from '../../../state/settings'
+import { useProjects } from '../../../state/projects'
+import {
+ PROJECT_CAPABILITIES,
+ PROJECT_CAPABILITY_COPY,
+ projectCapabilityEnabled
+} from '@shared/project-capabilities'
import {
isAgentEnabled,
setAgentEnabled,
@@ -94,7 +100,26 @@ const ROWS = {
]
}
}
-const ENTRIES = Object.values(ROWS)
+/**
+ * The per-project capability rows are GENERATED from PROJECT_CAPABILITIES — search registry
+ * included. A hand-written row list that happens to match the union is the documented
+ * claims-ahead-of-mechanism failure: agent messaging's row (its PR 6) must appear by adding a copy
+ * entry, and agents-capabilities.test.tsx iterates the array so a capability without a row is red.
+ */
+const CAPABILITY_ROWS = PROJECT_CAPABILITIES.map((cap) => ({
+ cap,
+ title: PROJECT_CAPABILITY_COPY[cap].label,
+ keywords: [
+ 'project',
+ 'capability',
+ 'permission',
+ ...PROJECT_CAPABILITY_COPY[cap].label.toLowerCase().split(/\s+/)
+ ]
+}))
+const ENTRIES = [
+ ...Object.values(ROWS),
+ ...CAPABILITY_ROWS.map(({ title, keywords }) => ({ title, keywords }))
+]
/**
* Every fact in this sentence is DERIVED from the per-agent mapping (`@shared/agents/approval-mode`):
@@ -149,6 +174,13 @@ function identityValue(choice: IdentityChoice): boolean | undefined {
export function AgentsSection({ isActive }: { isActive: boolean }): React.JSX.Element {
const settings = useSettings((s) => s.settings)
const update = useSettings((s) => s.update)
+ // Per-project capability rows act on the ACTIVE project. Subscribed (not getState()) so an
+ // off-toggle re-renders immediately — and consumers read the switch per call from the store,
+ // never from a snapshot taken when a lease started (agents-capabilities.test.tsx "takes effect
+ // LIVE"; browser PR 4 / messaging PR 6 rely on that shape).
+ const activeProjectId = useProjects((s) => s.activeProjectId)
+ const activeProject = useProjects((s) => s.projects.find((p) => p.id === activeProjectId))
+ const setProjectCapability = useProjects((s) => s.setProjectCapability)
const rows: { id: AgentId; label: string; isBuiltin: boolean }[] = [
...BUILTIN_AGENT_IDS.map((id) => ({ id, label: AGENT_CONFIG[id].label, isBuiltin: true })),
...settings.customAgents.map((c) => ({ id: c.id, label: c.label || c.id, isBuiltin: false }))
@@ -283,6 +315,35 @@ export function AgentsSection({ isActive }: { isActive: boolean }): React.JSX.El
}
/>
</SearchableRow>
+ {CAPABILITY_ROWS.map(({ cap, title, keywords }) => (
+ <SearchableRow key={cap} title={title} keywords={keywords}>
+ <FieldRow
+ label={title}
+ note={
+ activeProject
+ ? `Applies to the active project: ${activeProject.name}.`
+ : 'Open a project to change this — the switch belongs to a project, not to the app.'
+ }
+ // The description carries the capability's own copy AND its cloneWarning — the same
+ // "this is in the project file" sentence the clone notice shows, so the two git-shared
+ // grants read alike wherever they appear (pinned by agents-capabilities.test.tsx).
+ description={`${PROJECT_CAPABILITY_COPY[cap].description} ${PROJECT_CAPABILITY_COPY[cap].cloneWarning}`}
+ control={
+ <Switch
+ checked={projectCapabilityEnabled(activeProject, cap)}
+ ariaLabel={title}
+ disabled={!activeProject}
+ onChange={(on) => {
+ // The ONE strict setter: literal `true` on, field deleted on off. Writing the
+ // value any other way (a string, a stored false) is the bug the validators
+ // exist to refuse.
+ if (activeProject) setProjectCapability(activeProject.id, cap, on)
+ }}
+ />
+ }
+ />
+ </SearchableRow>
+ ))}
<SearchableRow {...ROWS.hibernation}>
<FieldRow
label="Hibernate idle agents"
diff --git a/src/renderer/ui/Switch.tsx b/src/renderer/ui/Switch.tsx
index 701d8cc15..ffa656f5f 100644
--- a/src/renderer/ui/Switch.tsx
+++ b/src/renderer/ui/Switch.tsx
@@ -3,11 +3,15 @@ import { cn } from './cn'
export function Switch({
checked,
onChange,
- ariaLabel
+ ariaLabel,
+ disabled = false
}: {
checked: boolean
onChange: (v: boolean) => void
ariaLabel?: string
+ /** Renders inert (native `disabled` + aria): for a switch whose subject does not currently
+ * exist, e.g. a per-project capability while no project is open. */
+ disabled?: boolean
}): React.JSX.Element {
return (
<button
@@ -15,9 +19,12 @@ export function Switch({
role="switch"
aria-checked={checked}
aria-label={ariaLabel}
+ disabled={disabled}
+ aria-disabled={disabled || undefined}
onClick={() => onChange(!checked)}
className={cn(
- 'relative box-border block h-[24px] w-[42px] shrink-0 cursor-pointer rounded-full border-0 p-0 outline-none transition-colors duration-200',
+ 'relative box-border block h-[24px] w-[42px] shrink-0 rounded-full border-0 p-0 outline-none transition-colors duration-200',
+ disabled ? 'cursor-not-allowed opacity-50' : 'cursor-pointer',
checked ? 'bg-accent' : 'bg-fill'
)}
>