Agent status
One glyph for what an agent is doing: a flatline at rest, thoughts in orbit, a live waveform while it works, a question when it needs you, a check, a cross. Its three strokes travel between them, so a change of state is one motion, never an icon swap.
npx shadcn@latest add https://uimaxxer.com/r/agent-status.jsonPasskeysAgents
Agents
IdleNo run yetThinkingReading the failing testWorkingEditing billing/invoice.tsWaiting for youWants to run pnpm db:resetDoneMerged #482 into mainFailedHealth check timed out
"use client";
// uimaxxer · Agent status, MIT. Idea: one glyph whose three strokes travel between six drawn states (a flatline at rest, orbiting thoughts, a live waveform while it works, a question for you, a check, a cross), so a change of state is one motion, never an icon swap. Delight: the working waveform flattens into the idle line, and bends into the question mark when the agent needs you.
import { AnimatePresence, animate, motion, useAnimationFrame, useMotionValue, useReducedMotion, useTransform, type MotionValue } from "motion/react";
import { useEffect, useRef } from "react";
import { EASE, cx } from "@/registry/captain/ui/captain";
export type AgentState = "idle" | "thinking" | "working" | "waiting" | "done" | "failed";
export const AGENT_STATES: AgentState[] = ["idle", "thinking", "working", "waiting", "done", "failed"];
type P = [number, number];
/** Three strokes, each M + two cubics = 7 points. Every state uses the same shape of data, so any state can morph into any other. */
type Glyph = [P[], P[], P[]];
const line = (a: P, b: P): P[] => {
const at = (t: number): P => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t];
return [a, at(1 / 6), at(2 / 6), at(3 / 6), at(4 / 6), at(5 / 6), b];
};
const dot = (p: P): P[] => Array.from({ length: 7 }, () => [p[0], p[1]] as P);
const poly = (pts: P[]): P[] => pts;
/** Working: a live signal across the glyph, its swing growing toward the pen. Sampled points serve as the cubic handles, which keeps it smooth. */
function wave(phase: number): Glyph {
const at = (x: number): P => {
const u = (x - 4.5) / 15;
return [x, 12 + Math.sin(u * Math.PI * 2.2 - phase) * (1.2 + 3.3 * u)];
};
const xs = (a: number, b: number) => Array.from({ length: 7 }, (_, i) => at(a + ((b - a) * i) / 6));
return [xs(4.5, 12), xs(12, 19.5), dot(at(19.5))];
}
/** Thinking: three thoughts orbiting a centre, never the typing dots. */
function orbit(angle: number): Glyph {
const p = (k: number): P => [12 + Math.cos(angle + (k * Math.PI * 2) / 3) * 5.6, 12 + Math.sin(angle + (k * Math.PI * 2) / 3) * 5.6];
return [dot(p(0)), dot(p(1)), dot(p(2))];
}
const GLYPHS: Record<AgentState, Glyph> = {
// A flatline, the same span the waveform runs across, so work settles into rest.
idle: [line([4.5, 12], [12, 12]), line([12, 12], [19.5, 12]), line([8, 12], [16, 12])],
thinking: orbit(-Math.PI / 2),
working: wave(0),
// A question for you: the hook and its point.
waiting: [
poly([[8.25, 9], [8.25, 6.9], [9.9, 5.25], [12, 5.25], [14.1, 5.25], [15.75, 6.9], [15.75, 9]]),
poly([[15.75, 9], [15.75, 11.4], [12, 11.6], [12, 14], [12, 14], [12, 14], [12, 14]]),
dot([12, 18.4]),
],
// The third stroke hides along a line, so only real points ever swell into dots.
done: [line([5.5, 12.5], [9.75, 16.75]), line([9.75, 16.75], [18.5, 7.25]), line([12, 14.3], [16, 9.9])],
failed: [line([7, 7], [17, 17]), line([17, 7], [7, 17]), line([9, 9], [15, 15])],
};
const live = (s: AgentState, w: number): Glyph | null => (s === "working" ? wave(w * 4.2) : s === "thinking" ? orbit(-Math.PI / 2 + w * 2.4) : null);
/** Colour per state, as theme variables. */
export const AGENT_TONE: Record<AgentState, string> = {
idle: "var(--captain-ink-3)",
thinking: "var(--captain-ink-2)",
working: "var(--captain-accent)",
waiting: "var(--captain-warning)",
done: "var(--captain-success)",
failed: "var(--captain-danger)",
};
export const AGENT_LABEL: Record<AgentState, string> = {
idle: "Idle",
thinking: "Thinking",
working: "Working",
waiting: "Waiting for you",
done: "Done",
failed: "Failed",
};
const flat = (g: Glyph) => g.flat().flat();
/** One stroke as a path, s = 0, 1 or 2. */
function toD(n: number[], s: number) {
const o = s * 14;
const v = (i: number) => (n[o + i] ?? 0).toFixed(2);
return `M${v(0)} ${v(1)}C${v(2)} ${v(3)} ${v(4)} ${v(5)} ${v(6)} ${v(7)}C${v(8)} ${v(9)} ${v(10)} ${v(11)} ${v(12)} ${v(13)}`;
}
/** How far a stroke reaches, so a stroke shrinking to a point can swell into a dot that reads at 20px. */
function reach(n: number[], s: number) {
const o = s * 14;
let m = 0;
for (let i = 2; i < 14; i += 2) m = Math.max(m, Math.hypot((n[o + i] ?? 0) - (n[o] ?? 0), (n[o + i + 1] ?? 0) - (n[o + 1] ?? 0)));
return m;
}
type AgentStatusProps = {
state: AgentState;
/** Override the quiet label; pass null to hide it (then aria-label still says the state). */
label?: string | null;
size?: number;
/** Hold the glyph part-way to another state (amount 0 to 1), for example under a finger. It follows 1:1; remove it and the strokes spring the rest of the way to `state`. */
toward?: { state: AgentState; amount: number };
className?: string;
};
export function AgentStatus({ state, label, size = 18, toward, className }: AgentStatusProps) {
const reduce = useReducedMotion();
const from = useRef(flat(GLYPHS[state]));
const cur = useRef(flat(GLYPHS[state]));
const to = useRef(flat(GLYPHS[state]));
const side = useRef(flat(GLYPHS[toward?.state ?? state]));
const t = useMotionValue(1);
const blend = useMotionValue(toward?.amount ?? 0);
const clock = useMotionValue(0);
const target = useRef(state);
target.current = state;
const d = useTransform([t, clock, blend], ([p, w, b]: number[]) => {
const a = from.current;
// Working and thinking are alive: the strokes head for where the moving glyph is now, not a frozen frame.
const moving = live(target.current, w as number);
const z = moving ? flat(moving) : to.current;
const n = z.map((x, i) => (a[i] ?? x) + (x - (a[i] ?? x)) * (p as number));
// Part-way to another state: every point sits that fraction of its journey.
if (b) for (let i = 0; i < n.length; i++) n[i] = n[i]! + ((side.current[i] ?? n[i]!) - n[i]!) * (b as number);
cur.current = n;
return n;
});
const held = toward !== undefined;
useEffect(() => {
if (toward) {
// 1:1: no spring while held.
from.current = to.current = flat(GLYPHS[state]);
side.current = flat(GLYPHS[toward.state]);
t.jump(1);
blend.set(toward.amount);
return;
}
// Retarget from wherever the strokes are now, so a change mid-morph never jumps.
from.current = cur.current;
to.current = flat(GLYPHS[state]);
blend.jump(0);
t.jump(0);
const a = animate(t, 1, reduce ? { duration: 0 } : { type: "spring", stiffness: 380, damping: 30, mass: 0.8 });
return () => a.stop();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [state, held, toward?.state, toward?.amount, reduce]);
useAnimationFrame((time) => {
if (reduce) return;
if (state === "working" || state === "thinking") clock.set(time / 1000);
});
const amount = toward?.amount ?? 0;
const near = toward && amount >= 0.5 ? toward.state : state;
const text = label === undefined ? AGENT_LABEL[near] : label;
// Colour belongs to a state, so it changes once, at the halfway point, rather than mixing into mud.
const color = AGENT_TONE[near];
return (
<span role="status" aria-label={text ?? AGENT_LABEL[near]} className={cx("inline-flex items-center gap-2", className)}>
<motion.svg
width={size}
height={size}
viewBox="0 0 24 24"
aria-hidden="true"
className="shrink-0 overflow-visible transition-colors duration-200"
style={{ color }}
>
{[0, 1, 2].map((k) => (
<Stroke key={k} n={d} k={k} width={size > 64 ? 2 : 2.25} />
))}
</motion.svg>
{text !== null ? (
<span className="relative inline-grid text-[13.5px] text-ink-2">
<AnimatePresence mode="popLayout" initial={false}>
<motion.span
key={text}
className="col-start-1 row-start-1 whitespace-nowrap"
initial={{ opacity: 0, y: reduce ? 0 : 5 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: reduce ? 0 : -5 }}
transition={{ duration: 0.2, ease: EASE }}
>
{text}
</motion.span>
</AnimatePresence>
</span>
) : null}
</span>
);
}
function Stroke({ n, k, width }: { n: MotionValue<number[]>; k: number; width: number }) {
const path = useTransform(n, (v) => toD(v, k));
// A point grows to 1.7 times the line weight; anything longer than two units is a plain line.
const w = useTransform(n, (v) => width * (1 + 0.7 * Math.max(0, 1 - reach(v, k) / 2)));
return <motion.path d={path} fill="none" stroke="currentColor" strokeWidth={w} strokeLinecap="round" strokeLinejoin="round" />;
}Usage
import { AgentStatus } from "@/components/ui/agent-status"
<AgentStatus state={run.state} />Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| state | "idle" | "thinking" | "working" | "waiting" | "done" | "failed" | Change it any time, even mid-morph: the strokes retarget from where they are. | |
| label | string | null | Overrides the quiet label. null hides it; the state is still announced. | |
| size | number | 18 | Glyph size in px. |
| toward | { state; amount } | Hold the glyph part-way to another state, amount 0 to 1, for example under a finger. Remove it and the strokes spring the rest of the way. |
Accessibility
- role=status with the state as its accessible name, so changes are announced politely.
- Colour is never the only signal: every state has its own shape.
- Under reduced motion the shape changes at once and nothing spins or bobs.
- The demo's state track is a slider: arrows step through states, Home and End jump to the ends.