Agent Monitor
One agent at work as a compact card: the current step with a clock and the bill so far, finished steps with each tool's logo, and the exact command when it needs your OK.
"use client"
import * as React from "react"
import {
ArrowUpRight,
Check,
ChevronsDownUp,
ChevronsUpDown,
Pause,
Play,
ShieldAlert,
X,
} from "lucide-react"
import {
AiKitStyles,
AiStyle,
BrandIcon,
BrandTile,
cx,
Face,
Roll,
type AiShape,
type AiTone,
} from "@/lib/ai-kit"
export type MonitorStatus = "run" | "ask" | "paused" | "done"
export interface MonitorStep {
id: string
brand: string
text: string
/** How long it took, e.g. "1.7s". */
took: string
}
export interface AgentMonitorProps {
agent: {
name: string
model: string
vendor?: string
tone: AiTone
shape?: AiShape
}
/** What the agent was asked to do, shown under its name. */
task: string
status: MonitorStatus
/** Cost so far in dollars. */
cost: number
current?: { brand: string; text: string; seconds: number }
/** Finished steps, newest first. */
steps: readonly MonitorStep[]
/** Steps done and total, for the progress bar and counter. */
at: number
total: number
/** The exact command waiting for your OK, when status is "ask". */
approval?: { command: string; reason: string }
expanded?: boolean
onExpanded?: (open: boolean) => void
onPause?: () => void
onCancel?: () => void
onApprove?: () => void
onDeny?: () => void
className?: string
}
const CSS = `
.aik-mo{--aik-r-shell:26px;--aik-rim:6px;width:min(100%,600px);container-type:inline-size}
.aik-mo-in{display:grid;grid-template-columns:minmax(0,1fr);gap:12px;padding:16px}
.aik-mo-head{display:flex;align-items:center;gap:12px;min-width:0}
.aik-mo-tile{display:grid;place-items:center;width:46px;height:46px;flex:none;border-radius:14px;background:color-mix(in oklab,var(--c) 14%,var(--aik-card));box-shadow:inset 0 0 0 1px color-mix(in oklab,var(--c) 28%,transparent)}
.aik-mo-id{display:grid;min-width:0;line-height:20px}
.aik-mo-id b{font-size:16px;font-weight:600;display:flex;align-items:center;gap:6px;min-width:0;white-space:nowrap}
.aik-mo-id b > span{overflow:hidden;text-overflow:ellipsis}
.aik-mo-id > span{font-size:13.5px;color:var(--aik-text-3);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.aik-mo-cost{margin-left:auto;font:500 15px var(--aik-mono);font-variant-numeric:tabular-nums}
.aik-mo-state{display:inline-flex;align-items:center;gap:7px;height:28px;padding:0 10px;border-radius:9px;font-size:13px;font-weight:500;color:var(--k);background:color-mix(in oklab,var(--k) 14%,transparent);white-space:nowrap}
.aik-mo-state i{width:7px;height:7px;border-radius:2px;background:currentColor}
.aik-mo-state[data-s="run"] i{animation:aik-mo-blink 1.2s ease-in-out infinite}
.aik-mo-tog{display:grid;place-items:center;width:30px;height:30px;border-radius:9px;color:var(--aik-text-3)}
.aik-mo-tog:hover{background:var(--aik-hover);color:var(--aik-text)}
.aik-mo-now{position:relative;display:flex;align-items:center;gap:12px;height:56px;padding:0 16px 0 9px;border-radius:15px;background:var(--aik-sunk);box-shadow:inset 0 0 0 1px var(--aik-line);overflow:hidden}
.aik-mo-now::after{content:"";position:absolute;top:0;bottom:0;left:-45%;width:45%;background:linear-gradient(100deg,transparent,color-mix(in oklab,var(--c) 16%,transparent),transparent);animation:aik-mo-sheen 2.4s var(--aik-ease-move) infinite;pointer-events:none;will-change:transform}
.aik-mo[data-s="paused"] .aik-mo-now::after,.aik-mo[data-s="done"] .aik-mo-now::after{animation:none;opacity:0}
.aik-mo-now .aik-roll{flex:1;min-width:0;font-size:15.5px;font-weight:500}
.aik-mo-clock{font:500 14px var(--aik-mono);color:var(--aik-text-2);font-variant-numeric:tabular-nums}
.aik-mo-bar{display:grid;grid-template-columns:repeat(var(--n),1fr);gap:4px}
.aik-mo-bar i{position:relative;height:6px;border-radius:3px;background:var(--aik-line-2);overflow:hidden;transition:background 500ms var(--aik-ease-out)}
.aik-mo-bar i[data-on]{background:var(--aik-text-2)}
.aik-mo-bar i[data-now]{background:color-mix(in oklab,var(--c) 45%,var(--aik-line-2))}
.aik-mo-bar i[data-now]::after{content:"";position:absolute;top:0;bottom:0;left:-60%;width:60%;border-radius:inherit;background:linear-gradient(90deg,transparent,var(--c),transparent);animation:aik-mo-run 1.4s var(--aik-ease-move) infinite;will-change:transform}
.aik-mo-fold{overflow:hidden;height:0}
.aik-mo-fold[data-open]{height:auto}
.aik-mo-fold > div{opacity:0;translate:0 -6px;transition:opacity var(--aik-d-state) var(--aik-ease-out),translate var(--aik-d-panel) var(--aik-ease-out)}
.aik-mo-fold[data-open] > div{opacity:1;translate:0 0;transition-delay:80ms}
.aik-mo-askin{display:grid;gap:10px;padding:14px;border-radius:15px;background:color-mix(in oklab,var(--aik-amber) 8%,var(--aik-card));box-shadow:inset 0 0 0 1px color-mix(in oklab,var(--aik-amber) 34%,transparent)}
.aik-mo-askin p{display:flex;align-items:center;gap:8px;font-size:14px;color:var(--aik-amber);font-weight:500}
.aik-mo-askin pre{margin:0;padding:10px 12px;border-radius:10px;background:var(--aik-sunk);font-size:13px;line-height:19px;white-space:pre-wrap;overflow-wrap:anywhere}
.aik-mo-askin pre span{color:var(--aik-text-3);user-select:none}
.aik-mo-askin > div{display:flex;justify-content:flex-end;gap:8px}
.aik-mo-log{display:grid;grid-template-columns:minmax(0,1fr);gap:6px}
.aik-mo-slot{height:46px;border-radius:13px;box-shadow:inset 0 0 0 1px var(--aik-line);background:repeating-linear-gradient(135deg,transparent 0 7px,var(--aik-line) 7px 8px);opacity:.55}
.aik-mo-step{display:flex;align-items:center;gap:11px;height:46px;padding:0 14px 0 8px;border-radius:13px;background:var(--aik-sunk);font-size:14.5px;transition:opacity 420ms var(--aik-ease-out);animation:aik-mo-in 460ms var(--aik-ease-soft) both}
.aik-mo-step > span:not(.aik-brand-tile){flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.aik-mo-step em{font:13px var(--aik-mono);font-style:normal;color:var(--aik-text-3)}
.aik-mo-step:nth-child(n+2){opacity:.75}
.aik-mo-step:nth-child(n+3){opacity:.5}
.aik-mo-foot{display:flex;align-items:center;gap:6px}
.aik-mo-foot .aik-btn{height:34px}
.aik-mo-foot > span{margin-left:auto;font:13.5px var(--aik-mono);color:var(--aik-text-3)}
.aik-mo-foot a{display:inline-flex;align-items:center;gap:4px;height:34px;padding:0 8px;border-radius:9px;font-size:14px;color:var(--aik-text-2);text-decoration:none}
.aik-mo-foot a:hover{background:var(--aik-hover);color:var(--aik-text)}
@keyframes aik-mo-blink{50%{opacity:.3}}
@keyframes aik-mo-sheen{from{transform:translateX(0)}to{transform:translateX(330%)}}
@keyframes aik-mo-run{from{transform:translateX(0)}to{transform:translateX(270%)}}
@keyframes aik-mo-in{from{opacity:0;transform:translateY(-10px) scale(.98)}}
@container (max-width:440px){
.aik-mo-cost{display:none}
.aik-mo-foot > span{display:none}
.aik-mo-in{padding:12px}
.aik-mo-tile{width:40px;height:40px;border-radius:12px}
.aik-mo-state{width:28px;padding:0;justify-content:center}
.aik-mo-state .aik-roll{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}
.aik-mo-now{gap:10px;padding:0 12px 0 8px}
.aik-mo-now .aik-roll{font-size:14.5px}
}
@media (prefers-reduced-motion: reduce){.aik-mo-now::after,.aik-mo-bar i[data-now]::after,.aik-mo-step,.aik-mo-state i{animation:none}.aik-mo-fold > div{transition:none}}
`
const STATE: Record<MonitorStatus, { label: string; k: string }> = {
run: { label: "Running", k: "var(--aik-blue)" },
ask: { label: "Needs your OK", k: "var(--aik-amber)" },
paused: { label: "Paused", k: "var(--aik-text-3)" },
done: { label: "Done", k: "var(--aik-green)" },
}
function clock(s: number) {
return `${Math.floor(s / 60)}:${String(Math.floor(s % 60)).padStart(2, "0")}`
}
/**
* Opens and shuts a panel by animating its measured height, with the content
* fading in a beat later, so the card grows in one move instead of jumping.
*/
function Fold({
open,
children,
}: {
open: boolean
children: React.ReactNode
}) {
const ref = React.useRef<HTMLDivElement>(null)
const first = React.useRef(true)
React.useLayoutEffect(() => {
const el = ref.current
if (!el) return
if (first.current) {
first.current = false
return
}
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return
el.getAnimations().forEach((a) => a.cancel())
const full = el.scrollHeight
el.animate(
[{ height: `${open ? 0 : full}px` }, { height: `${open ? full : 0}px` }],
{ duration: 420, easing: "cubic-bezier(.65,0,.15,1)" }
)
}, [open])
return (
<div ref={ref} className="aik-mo-fold" data-open={open ? "" : undefined}>
{children}
</div>
)
}
/** Slides rows that moved (a new step landed on top) from their old place. */
function useRowGlide(key: string) {
const box = React.useRef<HTMLDivElement>(null)
const last = React.useRef(new Map<string, number>())
React.useLayoutEffect(() => {
const el = box.current
if (!el) return
const still = window.matchMedia("(prefers-reduced-motion: reduce)").matches
const next = new Map<string, number>()
for (const row of el.querySelectorAll<HTMLElement>("[data-key]")) {
const id = row.dataset.key ?? ""
next.set(id, row.offsetTop)
const was = last.current.get(id)
if (was === undefined || still || was === row.offsetTop) continue
row.animate(
[
{ transform: `translateY(${was - row.offsetTop}px)` },
{ transform: "none" },
],
{ duration: 460, easing: "cubic-bezier(.32,.72,0,1)" }
)
}
last.current = next
}, [key])
return box
}
/**
* One agent at work as a compact card: the step it is on with a clock and the
* bill so far, the finished steps with each tool's logo, and the exact command
* it wants to run when it needs your OK.
*/
export function AgentMonitor({
agent,
task,
status,
cost,
current,
steps,
at,
total,
approval,
expanded = true,
onExpanded,
onPause,
onCancel,
onApprove,
onDeny,
className,
}: AgentMonitorProps) {
const st = STATE[status]
const shown = steps.slice(0, 3)
const rows = useRowGlide(shown.map((step) => step.id).join())
return (
<div
className={cx("aik aik-mo aik-shell", className)}
data-s={status}
style={{ "--c": `var(--aik-f-${agent.tone})` } as React.CSSProperties}
>
<AiKitStyles />
<AiStyle id="agent-monitor" css={CSS} />
<div className="aik-surface aik-mo-in">
<span
className="aik-beam"
data-on={status === "run" ? "" : undefined}
style={
{
"--aik-beam-c": `var(--aik-f-${agent.tone})`,
animation: "aik-beam 2.6s linear infinite",
} as React.CSSProperties
}
/>
<div className="aik-mo-head">
<span className="aik-mo-tile">
<Face
mood={
status === "run"
? "work"
: status === "ask"
? "needs"
: status === "done"
? "happy"
: "sleep"
}
shape={agent.shape ?? "blob"}
tone={agent.tone}
size={32}
/>
</span>
<span className="aik-mo-id">
<b>
<span>{agent.name}</span>
{agent.vendor ? (
<BrandIcon name={agent.vendor} tint="brand" size={13} />
) : null}
</b>
<span>
{agent.model} · {task}
</span>
</span>
<span className="aik-mo-cost" aria-label="Cost so far">
<Roll>{`$${cost.toFixed(3)}`}</Roll>
</span>
<span
className="aik-mo-state"
data-s={status}
style={{ "--k": st.k } as React.CSSProperties}
>
<i aria-hidden="true" />
<Roll>{st.label}</Roll>
</span>
<button
type="button"
className="aik-mo-tog"
aria-label={
expanded ? "Hide finished steps" : "Show finished steps"
}
onClick={() => onExpanded?.(!expanded)}
>
{expanded ? (
<ChevronsDownUp size={16} />
) : (
<ChevronsUpDown size={16} />
)}
</button>
</div>
{current ? (
<div className="aik-mo-now">
<BrandTile name={current.brand} size={36} />
<Roll>{current.text}</Roll>
<span className="aik-mo-clock">{clock(current.seconds)}</span>
</div>
) : null}
<div
className="aik-mo-bar"
style={{ "--n": total } as React.CSSProperties}
aria-label={`Step ${at} of ${total}`}
>
{Array.from({ length: total }, (_, i) => (
<i
key={i}
data-on={i < at ? "" : undefined}
data-now={i === at && status === "run" ? "" : undefined}
/>
))}
</div>
<Fold open={status === "ask" && !!approval}>
<div>
{approval ? (
<div className="aik-mo-askin">
<p>
<ShieldAlert size={16} aria-hidden="true" />
{approval.reason}
</p>
<pre className="aik-mono">
<span>$ </span>
{approval.command}
</pre>
<div>
<button
type="button"
className="aik-btn line"
onClick={onDeny}
>
<X size={14} aria-hidden="true" /> Deny
</button>
<button
type="button"
className="aik-btn pri"
onClick={onApprove}
>
<Check size={14} aria-hidden="true" /> Run it
</button>
</div>
</div>
) : null}
</div>
</Fold>
<Fold open={expanded}>
<div ref={rows} className="aik-mo-log">
{shown.map((step) => (
<div key={step.id} data-key={step.id} className="aik-mo-step">
<BrandTile name={step.brand} size={30} />
<span>{step.text}</span>
<em>{step.took}</em>
</div>
))}
{/* Empty slots keep the card one height while the log fills. */}
{Array.from({ length: 3 - shown.length }, (_, i) => (
<span
key={`slot-${i}`}
className="aik-mo-slot"
aria-hidden="true"
/>
))}
</div>
</Fold>
<div className="aik-mo-foot">
<button
type="button"
className="aik-btn"
onClick={onPause}
disabled={status === "done"}
>
{status === "paused" ? (
<Play size={14} aria-hidden="true" />
) : (
<Pause size={14} aria-hidden="true" />
)}
{status === "paused" ? "Resume" : "Pause"}
</button>
<button
type="button"
className="aik-btn line"
onClick={onCancel}
disabled={status === "done"}
>
<X size={14} aria-hidden="true" /> Cancel
</button>
<span>
<Roll>{`${at}/${total}`}</Roll>
</span>
<a href="#log" onClick={(e) => e.preventDefault()}>
Log <ArrowUpRight size={14} aria-hidden="true" />
</a>
</div>
</div>
</div>
)
}
Installation
One command adds agent-monitor 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/agent-monitor.json