Rules for what an agent may do alone and what needs approval.
checkout-web
What the coding agent may do in this repository without asking.
Pushing to main always asks, whatever is set here.
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/kit/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 askingconst 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 }), }, }), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/rulesUsage
import type { Outcome } from "./ui/uicontext/components/domain/Outcome.ts"import { ToolRules, type ToolRule } from "./ui/uicontext/components/kit/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 backexport 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
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.
Support assistant rules
When an Ask first rule and an Allow rule both match, it asks.
Allow
2 / 10It does these without asking.
Reply in threads it was mentioned in
Added by Mira Patel · Nov 3
Add labels and priorities to new tickets
Added by Ben Okafor · Nov 20
Ask first
1 / 10It stops and asks someone before these.
Anything that spends money, including refunds and credits
Added by Ben Okafor · Oct 12
Recently held or stopped
Post the daily ticket summary to #support · Held for approval, 2 hours ago
Email every customer about the outage · Stopped by Ben
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/kit/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 constconst 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 adminconst 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.
Calendar
What the personal assistant may do with Ada's calendar.
Only Ada can change what her assistant may do.
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { ToolRules } from "./ui/uicontext/components/kit/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
ToolRulesComponent
Props
| Name | Type | Description |
|---|---|---|
agentId | string | This editor's id for agents, unique on the page: "rules-github" |
labelrequired | 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 |
rulesrequired | ToolRule[] | Each tool, with its mode or the mode it inherits |
canrequired | 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 |
|---|---|
ChoseModeasks first | Set a tool's mode (one of modes). Target: { id, mode } as in the snapshot. |
ClickedResetasks first | Stop setting a tool's mode here, so it inherits. Target: { id, mode }. |
PlainRulesComponent
Props
| Name | Type | Default | Description |
|---|---|---|---|
agentId | string | — | The id agents see this by; plain-rules:<label> when left out |
labelrequired | string | — | "Permission rules" |
description | string | — | A line under the heading: what these rules control |
listsrequired | 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 |
canrequired | 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 |
|---|---|
SubmittedRuleasks first | Add a rule, as a sentence, to a list. Target: { list, count } with the list's current rule count. |
ClickedRemoveasks first | Remove a rule. Target: { list, id, text } as in the snapshot. |
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.