Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-ui): read an absent capability ceiling as the empty set
Andy Pavia8a08bfd4b87e
diff --git a/control-ui/components/HookInstallForm/index.tsx b/control-ui/components/HookInstallForm/index.tsxindex 85ac944ea..3c807ae19 100644--- a/control-ui/components/HookInstallForm/index.tsx+++ b/control-ui/components/HookInstallForm/index.tsx@@ -33,13 +33,20 @@ const STEP_DETAILS = [] as const// A Host's guardrails.capabilityCeiling bounds which capabilities a hook may be-// granted. spec is typed AnyRecord in lib/api, so read it defensively and keep-// only the four known capability values.+// granted. An absent ceiling is the empty set, not "unbounded": the install+// route reads it as `capabilityCeiling ?? []` and rejects anything requested+// against it, so granting must narrow to nothing here for the same Host.+//+// `null` means "no agent resolved yet" and is the one case that must not+// narrow, so the author's seed survives the load rather than being cleared+// before the selected Host has arrived. spec is typed AnyRecord in lib/api, so+// read it defensively and keep only the four known capability values.function hostCapabilityCeiling(host: HostResource | undefined): HookCapability[] | null {- const guardrails = (host?.spec as { guardrails?: { capabilityCeiling?: unknown } } | undefined)+ if (!host) return null+ const guardrails = (host.spec as { guardrails?: { capabilityCeiling?: unknown } } | undefined)?.guardrailsconst ceiling = guardrails?.capabilityCeiling- if (!Array.isArray(ceiling)) return null+ if (!Array.isArray(ceiling)) return []return ceiling.filter((c): c is HookCapability =>ALL_HOOK_CAPABILITIES.includes(c as HookCapability))@@ -145,8 +152,8 @@ export function HookInstallForm({ entry, onCancel, onInstalled }: HookInstallFor)const ceiling = useMemo(() => hostCapabilityCeiling(selectedHost), [selectedHost])- // When the target agent declares a ceiling, drop any selected capability that- // is no longer allowed for the newly selected host.+ // Drop any selected capability the newly selected agent does not allow. A+ // null ceiling is the not-yet-resolved agent, which narrows nothing.useEffect(() => {if (!ceiling) returnsetCapabilities(prev => {@@ -155,6 +162,23 @@ export function HookInstallForm({ entry, onCancel, onInstalled }: HookInstallFor})}, [ceiling])+ // What is ticked, then what the agent permits — the second sentence applies+ // whether or not the author declared anything, so it is appended rather than+ // chosen between. An agent with no ceiling can grant nothing, so say that+ // plainly instead of pointing at a ceiling it does not have.+ const capabilitiesDescription = [+ declaredCapabilities.length > 0+ ? "Pre-selected from what the hook's author says it needs. Removing one does not stop the install — the hook runs without that power."+ : 'Grant only the capabilities this hook needs.',+ ceiling === null+ ? ''+ : ceiling.length === 0+ ? 'This agent has no capability ceiling, so no capability can be granted until one is set on the agent.'+ : "Only the capabilities within this agent's capability ceiling can be granted.",+ ]+ .filter(Boolean)+ .join(' ')+// Declared capabilities the hook will not get — either the operator unticked// them or the agent's ceiling forbids them. Either way the hook is installed// less capable than its author says it needs.@@ -390,13 +414,7 @@ export function HookInstallForm({ entry, onCancel, onInstalled }: HookInstallForsingle decision, and fail mode below is constrained by it. */}<fieldset className="cu-form-section__group"><legend className="cu-form-section__subheading">Capabilities</legend>- <p className="cu-form-section__description">- {declaredCapabilities.length > 0- ? "Pre-selected from what the hook's author says it needs. Removing one does not stop the install — the hook runs without that power."- : ceiling- ? "Only the capabilities within this agent's capability ceiling can be granted."- : 'Grant only the capabilities this hook needs.'}- </p>+ <p className="cu-form-section__description">{capabilitiesDescription}</p>{HOOK_CAPABILITY_OPTIONS.map(option => {const outsideCeiling = !!ceiling && !ceiling.includes(option.value)const declared = declaredCapabilities.includes(option.value)diff --git a/control-ui/components/__tests__/HookInstallForm.test.tsx b/control-ui/components/__tests__/HookInstallForm.test.tsxindex 9cdc2dd8d..882cafe10 100644--- a/control-ui/components/__tests__/HookInstallForm.test.tsx+++ b/control-ui/components/__tests__/HookInstallForm.test.tsx@@ -25,11 +25,18 @@ function entryWith(hookMeta: Record<string, unknown>): RegistryEntry {} as unknown as RegistryEntry}-/** A Host whose guardrails ceiling allows `ceiling`, or none when null. */+/**+ * A Host whose guardrails ceiling allows `ceiling`. `null` writes no ceiling at+ * all, which the install route reads as the empty set — an agent that permits+ * nothing, not one that permits everything.+ */function host(name: string, ceiling: string[] | null) {return { metadata: { name }, spec: ceiling ? { guardrails: { capabilityCeiling: ceiling } } : {} }}+/** A ceiling that permits every capability, so a test can isolate the seeding. */+const ALL_CAPABILITIES = ['may_deny', 'may_rewrite', 'may_substitute_result', 'may_add_context']+function render(ui: React.ReactNode) {return rtlRender(<ToastProvider>{ui}</ToastProvider>)}@@ -57,7 +64,9 @@ afterEach(cleanup)beforeEach(() => {vi.clearAllMocks()vi.mocked(api.getRegistryCredentialSchema).mockResolvedValue({ keys: [] } as never)- vi.mocked(api.getHosts).mockResolvedValue({ items: [host('agent-a', null)] } as never)+ vi.mocked(api.getHosts).mockResolvedValue({+ items: [host('agent-a', ALL_CAPABILITIES)],+ } as never)})const noop = () => undefined@@ -179,6 +188,25 @@ describe('HookInstallForm — declaration never escapes the ceiling', () => {expect(screen.getByText(/needs may_deny to function/i)).toBeInTheDocument()})+ it('grants nothing on an agent with no ceiling, matching the install route', async () => {+ // control-api reads a missing capabilityCeiling as [] and 403s anything+ // requested against it, so a seeded tick here would submit a request the+ // server is certain to reject.+ vi.mocked(api.getHosts).mockResolvedValue({ items: [host('agent-a', null)] } as never)+ render(+ <HookInstallForm+ entry={entryWith({ requiredCapabilities: ['may_rewrite'] })}+ onCancel={noop}+ onInstalled={noop}+ />+ )+ await openAdvanced()+ await waitFor(() => expect(capabilityBox('May rewrite')).toBeDisabled())+ expect(capabilityBox('May rewrite').checked).toBe(false)+ expect(screen.getByText(/no capability can be granted/i)).toBeInTheDocument()+ expect(screen.getByText(/needs may_rewrite to function/i)).toBeInTheDocument()+ })+it('a declared may_deny still forces fail closed, as a manual tick does', async () => {render(<HookInstallFormdiff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex accdf57c0..2c6910463 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.451",+ "version": "0.1.452","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.451",+ "version": "0.1.452","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/llm-providers": "file:../packages/llm-providers",diff --git a/control-ui/package.json b/control-ui/package.jsonindex 1efd79c00..24b4ddf96 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.451",+ "version": "0.1.452","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",