Captain UI

Approval

An agent asks before it acts. Enter approves, Esc denies, the scope slides between once and always, and anything dangerous needs a hold.

npx shadcn@latest add @captain/approval
Pro
Ran pnpm test billingalways in this repo

Run pnpm db:reset on staging?

Migration 0042 stopped halfway. Atlas wants a clean schema before it retries.

Drops and reseeds 31 tables on staging-eu. The last backup is from 06:40 today.

$ pnpm db:reset --env staging --seed fixtures/billing

Run pnpm lint --fix in billing-service?

Formats the 14 files in #482 before review.

Usage

import { Approval } from "@/components/ui/approval"

<Approval
  dangerous
  title={<>Run <code>pnpm db:reset</code> on staging?</>}
  effect="Drops and reseeds 31 tables on staging-eu."
  command="pnpm db:reset --env staging"
  onDecision={({ approved, scope }) => agent.reply(approved, scope)}
/>

Props

PropTypeDefaultWhat it does
titleReactNodeThe question. Inline <code> is set as code.
commandstringThe exact command or call, shown in a code well.
reasonReactNodeWhy the agent wants it.
effectReactNodeWhat it will do. Set in the danger colour when dangerous.
dangerousbooleanApprove becomes a hold, and always-allow is not offered.
alwaysLabelReactNodeOffers a once / always choice, e.g. Always for pnpm lint.
holdDurationnumber1400Hold length in ms for dangerous actions.
onDecision({ approved, scope }) => voidCalled once. The card then collapses to one line.
autoFocusbooleantrueFocus on mount so Enter and Esc work at once.
resolvedLabel(decision) => ReactNodeText for the collapsed line.

Keyboard

Enter
Approve
Esc
Deny
Space or Enter (hold)
Approve a dangerous action
← →
Once or always

Accessibility

  • A labelled group: the question is the label, reason and effect are the description.
  • Dangerous requests focus the hold button, so a held Enter or Space approves and a tap cannot.
  • The scope is a radiogroup with arrow keys. The outcome is announced as status.