Autonomy Dial
How much an agent may do alone: a three-stop dial, its real actions gliding between “runs on its own” and “asks you first”, and a lock on what always asks.
"use client"
import * as React from "react"
import { Lock, LockOpen, OctagonAlert, TriangleAlert } from "lucide-react"
import {
AiKitStyles,
AiStyle,
BrandIcon,
cx,
Face,
type AiShape,
type AiTone,
} from "@/lib/ai-kit"
export type AutonomyRisk = "safe" | "risky" | "destructive"
export interface AutonomyAction {
id: string
label: string
/** Brand mark for the tool the action uses. */
brand: string
risk: AutonomyRisk
}
export interface AutonomyDialProps {
agent: { name: string; tone: AiTone; shape?: AiShape }
/** The stops of the dial, from most careful to most free. */
stops?: readonly string[]
/** Index of the active stop. */
level: number
onLevelChange?: (level: number) => void
actions: readonly AutonomyAction[]
/** Actions the person pinned to always ask, on top of the destructive ones. */
pinned?: readonly string[]
onPin?: (id: string) => void
className?: string
}
const CSS = `
.aik-ad{--aik-r-shell:26px;--aik-rim:5px;width:min(100%,640px);container-type:inline-size}
.aik-ad-card{display:grid}
.aik-ad-head{display:flex;align-items:center;gap:14px;padding:20px 22px 18px}
.aik-ad-who b{display:block;font-size:17px;line-height:22px;font-weight:600}
.aik-ad-who span{font-size:14px;color:var(--aik-text-2)}
.aik-ad-head .aik-ad-say{margin-left:auto;font:500 12.5px var(--aik-mono);color:var(--aik-text-3);text-align:right;white-space:nowrap}
.aik-ad-dial{position:relative;display:grid;grid-template-columns:repeat(var(--n),1fr);margin:0 22px;padding:4px;border-radius:14px;background:var(--aik-sunk);box-shadow:inset 0 0 0 1px var(--aik-line)}
.aik-ad-thumb{position:absolute;top:4px;bottom:4px;left:4px;width:calc((100% - 8px)/var(--n));border-radius:10px;background:var(--aik-card);box-shadow:var(--aik-sh-card);transform:translateX(calc(var(--at)*100%));transition:transform var(--aik-d-move) var(--aik-ease-move)}
.aik-ad-thumb::after{content:"";position:absolute;left:18%;right:18%;bottom:-1px;height:2px;border-radius:2px;background:var(--c);box-shadow:0 0 12px var(--c);transition:background var(--aik-d-panel),box-shadow var(--aik-d-panel)}
.aik-ad-dial button{position:relative;height:40px;border-radius:10px;font-weight:600;font-size:14px;color:var(--aik-text-3);transition:color var(--aik-d-state)}
.aik-ad-dial button[aria-checked="true"]{color:var(--aik-text)}
.aik-ad-dial button:hover{color:var(--aik-text)}
.aik-ad-list{position:relative;display:grid;padding:14px 12px 12px;margin-top:16px;border-top:1px solid var(--aik-line)}
.aik-ad-sec{display:flex;align-items:center;gap:8px;height:34px;padding:0 10px;margin-top:6px;font-size:13.5px;color:var(--aik-text-3)}
.aik-ad-sec b{display:inline-grid;place-items:center;min-width:22px;height:22px;padding:0 6px;border-radius:7px;font:600 12px var(--aik-mono);color:var(--aik-text-2);box-shadow:inset 0 0 0 1px var(--aik-line-2)}
.aik-ad-sec i{width:7px;height:7px;border-radius:50%;background:var(--c)}
.aik-ad-row{display:flex;align-items:center;gap:13px;min-height:50px;padding:0 10px;border-radius:12px;font-size:15px;transition:background var(--aik-d-state)}
.aik-ad-row:hover{background:var(--aik-hover)}
.aik-ad-row[data-moved]{background:color-mix(in oklab,var(--c) 10%,var(--aik-card))}
.aik-ad-brand{display:grid;place-items:center;width:30px;height:30px;border-radius:9px;background:var(--aik-card);box-shadow:inset 0 0 0 1px var(--aik-line-2);flex:none}
.aik-ad-tag{display:inline-flex;align-items:center;gap:5px;height:24px;padding:0 8px;border-radius:8px;font-weight:500;font-size:12.5px;color:var(--c);background:color-mix(in oklab,var(--c) 14%,transparent);white-space:nowrap}
.aik-ad-tag[data-r="risky"]{--c:var(--aik-amber)}.aik-ad-tag[data-r="destructive"]{--c:var(--aik-red)}
.aik-ad-lock{margin-left:auto;display:grid;place-items:center;width:32px;height:32px;border-radius:9px;color:var(--aik-text-3);transition:background var(--aik-d-state),color var(--aik-d-state),transform var(--aik-d-press)}
.aik-ad-lock:hover{background:var(--aik-raised);color:var(--aik-text)}
.aik-ad-lock:active{transform:scale(.9)}
.aik-ad-lock[data-on]{color:var(--aik-text)}
.aik-ad-lock:disabled{cursor:default;color:var(--aik-text-2);background:none}
.aik-ad-lock svg{transition:transform var(--aik-d-panel) var(--aik-ease-soft)}
.aik-ad-lock[data-on] svg{animation:aik-ad-latch 380ms var(--aik-ease-soft)}
.aik-ad-empty{padding:6px 10px 10px;font-size:14px;color:var(--aik-text-3)}
@keyframes aik-ad-latch{40%{transform:translateY(2px) scale(.9)}}
@container (max-width:430px){.aik-ad-head .aik-ad-say{display:none}.aik-ad-dial button{font-size:12.5px}.aik-ad-tag span{display:none}}
@media (prefers-reduced-motion: reduce){.aik-ad-thumb{transition:none}}
`
const LEVEL_TONE = ["var(--aik-amber)", "var(--aik-blue)", "var(--aik-green)"]
/** Which actions run alone at a given stop. Destructive and pinned ones always ask. */
function runsAlone(
action: AutonomyAction,
level: number,
pinned: readonly string[]
) {
if (action.risk === "destructive" || pinned.includes(action.id)) return false
if (level <= 0) return false
if (level === 1) return action.risk === "safe"
return true
}
/**
* How much an agent may do on its own: a three-stop dial, and its real
* actions gliding between "Runs on its own" and "Asks you first" as the dial
* moves. Destructive actions are locked to asking; pin any other one with its lock.
*/
export function AutonomyDial({
agent,
stops = ["Always ask", "If risky", "Full auto"],
level,
onLevelChange,
actions,
pinned = [],
onPin,
className,
}: AutonomyDialProps) {
const list = React.useRef<HTMLDivElement>(null)
const last = React.useRef(new Map<string, number>())
const prev = React.useRef(new Map<string, boolean>())
const [moved, setMoved] = React.useState<string[]>([])
const own = actions.filter((a) => runsAlone(a, level, pinned))
const ask = actions.filter((a) => !runsAlone(a, level, pinned))
// FLIP: rows that change section glide from where they were.
React.useLayoutEffect(() => {
const root = list.current
if (!root) return
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches
const changed: string[] = []
// Rows, section headings and the empty line all glide, so nothing a
// moving row passes jumps into place underneath it.
root.querySelectorAll<HTMLElement>("[data-key]").forEach((el) => {
const key = el.dataset.key!
const top = el.offsetTop
const before = last.current.get(key)
const isRow = el.dataset.alone !== undefined
if (isRow) {
const alone = el.dataset.alone === "1"
if (prev.current.has(key) && prev.current.get(key) !== alone)
changed.push(key)
prev.current.set(key, alone)
}
if (before === undefined && !isRow && last.current.size && !reduce) {
// A heading or empty line that just appeared fades in.
el.animate([{ opacity: 0 }, { opacity: 1 }], {
duration: 320,
delay: 200,
easing: "cubic-bezier(.25,1,.5,1)",
fill: "backwards",
})
}
if (before !== undefined && !reduce) {
const dy = before - top
if (Math.abs(dy) > 1) {
const crossing = isRow && changed.includes(key)
if (crossing) {
el.style.position = "relative"
el.style.zIndex = "2"
}
const anim = el.animate(
[{ transform: `translateY(${dy}px)` }, { transform: "none" }],
{ duration: 520, easing: "cubic-bezier(.65,0,.15,1)" }
)
if (crossing)
anim.onfinish = anim.oncancel = () => {
el.style.position = ""
el.style.zIndex = ""
}
}
}
last.current.set(key, top)
})
if (changed.length) setMoved(changed)
}, [level, pinned])
React.useEffect(() => {
if (!moved.length) return
const id = window.setTimeout(() => setMoved([]), 900)
return () => window.clearTimeout(id)
}, [moved])
const row = (action: AutonomyAction, alone: boolean) => {
const locked = action.risk === "destructive"
const pin = pinned.includes(action.id)
return (
<div
key={action.id}
data-key={action.id}
data-alone={alone ? "1" : "0"}
data-moved={moved.includes(action.id) ? "" : undefined}
className="aik-ad-row"
style={
{
"--c": alone ? "var(--aik-green)" : "var(--aik-amber)",
} as React.CSSProperties
}
>
<span className="aik-ad-brand">
<BrandIcon name={action.brand} tint="brand" size={17} />
</span>
<span>{action.label}</span>
{action.risk !== "safe" ? (
<span className="aik-ad-tag" data-r={action.risk}>
{locked ? <OctagonAlert size={13} /> : <TriangleAlert size={13} />}
<span>{locked ? "Destructive" : "Risky"}</span>
</span>
) : null}
<button
type="button"
className="aik-ad-lock"
data-on={locked || pin ? "" : undefined}
disabled={locked}
aria-pressed={locked || pin}
aria-label={
locked
? `${action.label} always asks`
: pin
? `Let ${action.label} follow the dial`
: `Always ask before ${action.label}`
}
onClick={() => onPin?.(action.id)}
>
{locked || pin ? <Lock size={16} /> : <LockOpen size={16} />}
</button>
</div>
)
}
return (
<div className={cx("aik aik-ad aik-shell", className)}>
<AiKitStyles />
<AiStyle id="autonomy-dial" css={CSS} />
<div className="aik-surface aik-ad-card">
<div className="aik-ad-head">
<Face
mood={level === 2 ? "work" : level === 1 ? "idle" : "listen"}
shape={agent.shape ?? "arch"}
tone={agent.tone}
size={42}
/>
<span className="aik-ad-who">
<b>{agent.name}</b>
<span>What it may do without asking you</span>
</span>
<span className="aik-ad-say">
{own.length} of {actions.length} alone
</span>
</div>
<div
className="aik-ad-dial"
role="radiogroup"
aria-label="Autonomy"
style={
{
"--n": stops.length,
"--at": level,
"--c": LEVEL_TONE[level] ?? "var(--aik-blue)",
} as React.CSSProperties
}
onKeyDown={(event) => {
if (event.key === "ArrowRight")
onLevelChange?.(Math.min(stops.length - 1, level + 1))
if (event.key === "ArrowLeft")
onLevelChange?.(Math.max(0, level - 1))
}}
>
<span className="aik-ad-thumb" aria-hidden="true" />
{stops.map((stop, i) => (
<button
key={stop}
type="button"
role="radio"
aria-checked={i === level}
tabIndex={i === level ? 0 : -1}
onClick={() => onLevelChange?.(i)}
>
{stop}
</button>
))}
</div>
<div className="aik-ad-list" ref={list}>
<div
className="aik-ad-sec"
data-key="sec-own"
style={{ "--c": "var(--aik-green)" } as React.CSSProperties}
>
<i />
Runs on its own <b>{own.length}</b>
</div>
{own.length ? (
own.map((a) => row(a, true))
) : (
<p className="aik-ad-empty" data-key="empty">
Nothing yet. It asks before every action.
</p>
)}
<div
className="aik-ad-sec"
data-key="sec-ask"
style={{ "--c": "var(--aik-amber)" } as React.CSSProperties}
>
<i />
Asks you first <b>{ask.length}</b>
</div>
{ask.map((a) => row(a, false))}
</div>
</div>
</div>
)
}
Installation
One command adds autonomy-dial and the shared AI Kit layer it is built on (tokens, faces, marks and brand icons). No animation library, light and dark built in.
$npx shadcn@latest add https://tweenui.dev/r/autonomy-dial.json