# Agent Permissions

> Rules for what an agent may do alone and what needs approval.

Page: https://uicontext.com/docs/components/agent-permissions

Group: Agents.

## When to use

Rules for what an agent may do alone and what needs approval. Use [Permission Sheet](https://uicontext.com/docs/components/permission-sheet.md) instead when you set an agent's access per app.

## Usage

```ts
import type { Outcome } from "./ui/uicontext/components/domain/Outcome.ts"
import { ToolRules, type ToolRule } from "./ui/uicontext/components/Rules.ts"

const Message = UiSchema.TaggedEnum({
	RequestedToolMode: { id: Schema.String, mode: Schema.String },
	RequestedToolReset: { id: Schema.String },
})

// your app saves each change, answers with an outcome per tool id, and passes the new rules back
export const AgentToolRules = (
	h: Html.H<typeof Message.Type>,
	rules: ReadonlyArray<ToolRule>,
	outcomes: ReadonlyArray<Outcome>,
) =>
	ToolRules(h, {
		props: { label: "Tools", rules, outcomes, can: ["edit"] },
		onEmit: {
			RequestedMode: ({ id, mode }) => Message.RequestedToolMode({ id, mode }),
			RequestedReset: ({ id }) => Message.RequestedToolReset({ id }),
		},
	})
```

## Examples

Each example is a complete file. Its imports point where the CLI installs the source.

### A coding agent's tools

Each tool asks first, is allowed, or is blocked. Rows say where an inherited mode comes from, and a locked row says why. Try allowing Delete branches: the server refuses.

```ts title="src/demo.ts" source="www/src/examples/agent-permissions/demo.ts"
import { Command, UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Effect, Schema } from "effect"
import { Outcome, accepted, pending, refused } from "./ui/uicontext/components/domain/Outcome.ts"
import { ToolRule, ToolRules } from "./ui/uicontext/components/Rules.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"

const styles = stylex.create({
	frame: { inlineSize: "min(100%, 44rem)" },
})

// What a coding agent may do with the code host and the shell, set for one repository. The
// organization asks before opening pull requests, and blocks force pushes outright.
const tools: ReadonlyArray<ToolRule> = [
	{ id: "read-code", name: "Read code and history", description: "Files, commits and blame", mode: "allow" },
	{ id: "read-issues", name: "Read issues", mode: "allow" },
	{ id: "comment", name: "Comment on issues and pull requests", mode: "allow", inherited: { mode: "ask", from: "Organization" } },
	{ id: "branch", name: "Create branches", mode: "allow" },
	{ id: "push", name: "Push to its own branches", mode: "allow" },
	{ id: "open-pr", name: "Open pull requests", inherited: { mode: "ask", from: "Organization" } },
	{ id: "merge", name: "Merge pull requests", mode: "ask" },
	{ id: "force-push", name: "Force push", mode: "block", lockedReason: "Blocked by your organization" },
	{ id: "delete-branch", name: "Delete branches", mode: "ask" },
	{ id: "install", name: "Install dependencies", mode: "allow", unavailable: { block: "Sessions need it to set up" } },
	{ id: "run-tests", name: "Run tests", mode: "allow" },
	{ id: "network", name: "Reach the internet", description: "Package registries are always allowed", mode: "ask" },
	{ id: "secrets", name: "Read repository secrets", mode: "block" },
]

const Message = UiSchema.TaggedEnum({
	RequestedToolMode: { id: Schema.String, mode: Schema.String },
	RequestedToolReset: { id: Schema.String },
	CompletedSave: { id: Schema.String, mode: Schema.NullOr(Schema.String) },
})

// stands in for the server: it saves in 600ms, but only admins may let the agent delete branches
// or read secrets without asking
const SaveRule = Command.make("Example.SaveRule", { args: { id: Schema.String, mode: Schema.NullOr(Schema.String) } }, ({ id, mode }) =>
	Effect.sleep("600 millis").pipe(Effect.as(Message.CompletedSave({ id, mode }))),
)
const adminOnly = new Set(["delete-branch", "secrets"])

export const RepositoryRules = Html.component({
	name: "RepositoryRules",
	model: Schema.Struct({ tools: Schema.Array(ToolRule), outcomes: Schema.Array(Outcome) }),
	message: Message,
}).make({
	init: () => ({ tools, outcomes: [] }),
	update: {
		RequestedToolMode: ($, { id, mode }) =>
			$.evolve({ outcomes: (all) => [...all.filter((o) => o.request !== id), pending(id)] }).run(SaveRule.make({ id, mode })),
		RequestedToolReset: ($, { id }) =>
			$.evolve({ outcomes: (all) => [...all.filter((o) => o.request !== id), pending(id)] }).run(SaveRule.make({ id, mode: null })),
		CompletedSave: ($, { id, mode }) => {
			const others = $.model.outcomes.filter((o) => o.request !== id)
			if (mode === "allow" && adminOnly.has(id)) {
				return $.evolve({ outcomes: [...others, refused(id, "Only admins can let the agent do this without asking.")] })
			}
			return $.evolve({
				outcomes: [...others, accepted(id)],
				tools: (all) =>
					all.map((t) => {
						if (t.id !== id) return t
						const { mode: _, ...rest } = t
						return mode === null ? rest : { ...rest, mode }
					}),
			})
		},
	},
	view: (h, model) =>
		h.div.attrs(sx(styles.frame)).children(
			ToolRules(h, {
				props: {
					agentId: "rules-repository",
					label: "checkout-web",
					description: "What the coding agent may do in this repository without asking.",
					rules: model.tools,
					can: ["edit"],
					outcomes: model.outcomes,
					note: "Pushing to main always asks, whatever is set here.",
				},
				onEmit: {
					RequestedMode: ({ id, mode }) => Message.RequestedToolMode({ id, mode }),
					RequestedReset: ({ id }) => Message.RequestedToolReset({ id }),
				},
			}),
		),
})
```

### Rules in your words

Sentences in Allow and Ask first lists. A new rule shows at once while it saves; a refused one comes back to edit. Ctrl+Enter adds, Escape cancels.

```ts title="src/in-your-words.ts" source="www/src/examples/agent-permissions/in-your-words.ts"
import { Command, UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Effect, Schema } from "effect"
import { Outcome, accepted, pending, refused } from "./ui/uicontext/components/domain/Outcome.ts"
import { PlainRules, RuleList } from "./ui/uicontext/components/Rules.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"

const styles = stylex.create({
	frame: { inlineSize: "min(100%, 48rem)" },
})

const mira = { id: "mira", name: "Mira Patel", kind: "person" } as const
const ben = { id: "ben", name: "Ben Okafor", kind: "person" } as const

// A team assistant's rules in plain words, for the support channel.
const lists: ReadonlyArray<RuleList> = [
	{
		id: "allow",
		label: "Allow",
		description: "It does these without asking.",
		limit: 10,
		placeholder: "Reply to customers in threads it was asked into",
		rules: [
			{ id: "a1", text: "Reply in threads it was mentioned in", actor: mira, at: "2026-11-03T12:00:00Z" },
			{ id: "a2", text: "Add labels and priorities to new tickets", actor: ben, at: "2026-11-20T12:00:00Z" },
		],
	},
	{
		id: "ask",
		label: "Ask first",
		description: "It stops and asks someone before these.",
		limit: 10,
		placeholder: "Refund more than $200",
		rules: [{ id: "k1", text: "Anything that spends money, including refunds and credits", actor: ben, at: "2026-10-12T12:00:00Z" }],
	},
]

const Message = UiSchema.TaggedEnum({
	RequestedAddRule: { list: Schema.String, text: Schema.String },
	RequestedRemoveRule: { list: Schema.String, id: Schema.String },
	CompletedAdd: { list: Schema.String, text: Schema.String },
	CompletedRemove: { list: Schema.String, id: Schema.String },
})

// stands in for the server: a save takes 700ms, and rules that reach every customer need an admin
const SaveAdd = Command.make("Example.SaveAdd", { args: { list: Schema.String, text: Schema.String } }, ({ list, text }) =>
	Effect.sleep("700 millis").pipe(Effect.as(Message.CompletedAdd({ list, text }))),
)
const SaveRemove = Command.make("Example.SaveRemove", { args: { list: Schema.String, id: Schema.String } }, ({ list, id }) =>
	Effect.sleep("700 millis").pipe(Effect.as(Message.CompletedRemove({ list, id }))),
)

export const SupportRules = Html.component({
	name: "SupportRules",
	model: Schema.Struct({ lists: Schema.Array(RuleList), outcomes: Schema.Array(Outcome), next: Schema.Number }),
	message: Message,
}).make({
	init: () => ({ lists, outcomes: [], next: 1 }),
	update: {
		RequestedAddRule: ($, { list, text }) =>
			$.evolve({ outcomes: (all) => [...all.filter((o) => o.request !== list), pending(list)] }).run(SaveAdd.make({ list, text })),
		CompletedAdd: ($, { list, text }) => {
			const others = $.model.outcomes.filter((o) => o.request !== list)
			if (/\b(every|all) customers?\b/iu.test(text)) {
				return $.evolve({ outcomes: [...others, refused(list, "Rules that reach every customer need an admin. Ask Ben, or narrow the rule.")] })
			}
			return $.evolve({
				outcomes: [...others, accepted(list)],
				next: (n) => n + 1,
				lists: (all) =>
					all.map((l) =>
						l.id === list
							? { ...l, rules: [...l.rules, { id: `new-${$.model.next}`, text, actor: mira, at: "2026-12-01T12:00:00Z" }] }
							: l,
					),
			})
		},
		RequestedRemoveRule: ($, { list, id }) =>
			$.evolve({ outcomes: (all) => [...all.filter((o) => o.request !== id), pending(id)] }).run(SaveRemove.make({ list, id })),
		CompletedRemove: ($, { list, id }) =>
			$.evolve({
				outcomes: (all) => all.filter((o) => o.request !== id),
				lists: (all) => all.map((l) => (l.id === list ? { ...l, rules: l.rules.filter((r) => r.id !== id) } : l)),
			}),
	},
	view: (h, model) =>
		h.div.attrs(sx(styles.frame)).children(
			PlainRules(h, {
				props: {
					agentId: "rules-support",
					label: "Support assistant rules",
					precedence: "When an Ask first rule and an Allow rule both match, it asks.",
					lists: model.lists,
					outcomes: model.outcomes,
					timeZone: "UTC",
					recent: [
						{
							id: "c1",
							text: "Post the daily ticket summary to #support",
							result: "Held for approval, 2 hours ago",
							list: "allow",
							suggestion: "Post the daily ticket summary to #support",
						},
						{ id: "c2", text: "Email every customer about the outage", result: "Stopped by Ben", list: "ask" },
					],
					can: ["edit"],
				},
				onEmit: {
					RequestedAdd: ({ list, text }) => Message.RequestedAddRule({ list, text }),
					RequestedRemove: ({ list, id }) => Message.RequestedRemoveRule({ list, id }),
				},
			}),
		),
})
```

### Read-only

Someone who can't change the rules still sees every mode, and why they can't change it.

```ts title="src/read-only.ts" source="www/src/examples/agent-permissions/read-only.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { ToolRules } from "./ui/uicontext/components/Rules.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"

const styles = stylex.create({
	frame: { inlineSize: "min(100%, 44rem)" },
})

export const CalendarRulesReadOnly = <M>(h: Html.H<M>) =>
	h.div.attrs(sx(styles.frame)).children(
		ToolRules(h, {
			props: {
				agentId: "rules-calendar-read-only",
				label: "Calendar",
				description: "What the personal assistant may do with Ada's calendar.",
				rules: [
					{ id: "read", name: "Read events", mode: "allow" },
					{ id: "create", name: "Create events", mode: "allow" },
					{ id: "accept", name: "Accept invitations", mode: "ask" },
					{ id: "cancel", name: "Cancel events with other people", mode: "block", inherited: { mode: "ask", from: "Workspace" } },
				],
				can: [],
				readOnlyReason: "Only Ada can change what her assistant may do.",
			},
			onEmit: { RequestedMode: () => undefined, RequestedReset: () => undefined },
		}),
	)
```

## API reference

### ToolRules (component)

**Props**

| Name | Type | Description |
| --- | --- | --- |
| `agentId` | `string` | This editor's id for agents, unique on the page: "rules-github" |
| `label` (required) | `string` | "Tools", "GitHub server" |
| `description` | `string` | A line under the heading: what these rules control |
| `modes` | `RuleMode[]` | The modes a tool can be in; Ask first, Allow and Block by default |
| `rules` (required) | `ToolRule[]` | Each tool, with its mode or the mode it inherits |
| `can` (required) | `Can(["edit"])` | What the viewer may do: "edit" changes modes |
| `readOnlyReason` | `string` | Why the viewer can't edit, shown instead of the controls |
| `note` | `string` | What still asks no matter what: "Sending money always asks." |
| `outcomes` | `Outcome[]` | The app's answers to requests, one per request; the request id is the rule's id (`RequestedMode`, `RequestedReset`). A pending rule is busy; the newest refusal shows its reason. |

**Events**

| Event | Payload | Description |
| --- | --- | --- |
| `RequestedMode` | `{ id: string; mode: string }` | The person picked a mode for a tool |
| `RequestedReset` | `{ id: string }` | Stop setting a mode here and inherit |

**Agent actions**

| Action | Description |
| --- | --- |
| `ChoseMode` (asks first) | Set a tool's mode (one of modes). Target: { id, mode } as in the snapshot. |
| `ClickedReset` (asks first) | Stop setting a tool's mode here, so it inherits. Target: { id, mode }. |

### PlainRules (component)

**Props**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `agentId` | `string` | — | The id agents see this by; `plain-rules:<label>` when left out |
| `label` (required) | `string` | — | "Permission rules" |
| `description` | `string` | — | A line under the heading: what these rules control |
| `lists` (required) | `RuleList[]` | — | The lists of rules in plain words, such as Allow, Ask first and Never |
| `maxLength` | `number` | `000` | Longest rule, in characters; 1,000 by default |
| `precedence` | `string` | — | Which list wins when two match: "Ask first wins over Allow." |
| `recent` | `RuleCase[]` | — | Recent held or stopped actions, to write a rule from |
| `can` (required) | `Can(["edit"])` | — | What the viewer may do: "edit" adds and removes rules |
| `readOnlyReason` | `string` | — | Why the viewer can't edit, shown instead of the controls |
| `outcomes` | `Outcome[]` | — | The app's answers to requests, one per request; the request id is the list's id for `RequestedAdd` and the rule's id for `RequestedRemove`. A pending rule is busy; the newest refusal shows its reason. |
| `locale` | `string` | — | For the dates rules were added |
| `timeZone` | `string` | — | The time zone for the dates rules were added; the reader's own when left out |

**Events**

| Event | Payload | Description |
| --- | --- | --- |
| `RequestedAdd` | `{ list: string; text: string }` | The person wrote a new rule into a list |
| `RequestedRemove` | `{ list: string; id: string }` | The person removed a rule |

**Agent actions**

| Action | Description |
| --- | --- |
| `SubmittedRule` (asks first) | Add a rule, as a sentence, to a list. Target: { list, count } with the list's current rule count. |
| `ClickedRemove` (asks first) | Remove a rule. Target: { list, id, text } as in the snapshot. |

## Keyboard and accessibility

- Each tool is a fieldset whose modes are radio buttons; a mode that can't be chosen says why, read as its description.
- A read-only list says why above it, and a refused change is announced.
- Plain-language rules are a list with a labelled field to add one, and each Remove button names its rule. Agents must name the rule or tool they change.

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/agent-permissions
```

With npm: `npx shadcn@latest add checkfu/uicontext/agent-permissions`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/agent-permissions`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/agent-permissions`.

It writes these files:

- `src/ui/uicontext/components/Button.ts`
- `src/ui/uicontext/components/FormControls.ts`
- `src/ui/uicontext/components/IconStroke.ts`
- `src/ui/uicontext/components/Rules.ts`
- `src/ui/uicontext/components/ShowText.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/agent/Agent.ts`
- `src/ui/uicontext/components/button.stylex.ts`
- `src/ui/uicontext/components/domain/Actor.ts`
- `src/ui/uicontext/components/domain/Format.ts`
- `src/ui/uicontext/components/domain/Outcome.ts`
- `src/ui/uicontext/components/domain/Permission.ts`
- `src/ui/uicontext/components/domain/Time.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`
- `src/ui/uicontext/components/variants.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/Rules.ts](https://github.com/checkfu/uicontext/blob/main/src/Rules.ts)

## Related

- [Agent Tools](https://uicontext.com/docs/components/agent-tools.md) (`agent-tools`): Lets agents in the browser read the page and act through the same controls people use.
- [Tool Confirmation](https://uicontext.com/docs/components/tool-confirmation.md) (`tool-confirmation`): Asks a person to confirm before an agent's action changes anything.
- [Prompt Template](https://uicontext.com/docs/components/prompt-template.md) (`prompt-template`): Write a prompt with {{variables}} the app fills in: they stand out, unknown ones are flagged, and a preview shows it with samples.
- [Agent Settings](https://uicontext.com/docs/components/agent-settings.md) (`agent-settings`): Edit an agent's name, instructions, tools and model.
- [Computer](https://uicontext.com/docs/components/computer.md) (`computer`): The machine an agent works on: a live view of its screen, full size or as a thumbnail with Take over, and its browser with tabs and an address bar.
- [Persona Avatar](https://uicontext.com/docs/components/persona-avatar.md) (`persona-avatar`): An agent's face: a shape and a color with eyes that move with what it's doing.
