Agent Steering
Steer an agent mid-run: type a note, queue it for the next step or send it now, and watch it slide out of the queue into the plan when the agent picks it up.
"use client"
import * as React from "react"
import {
ArrowUp,
Check,
CornerDownLeft,
Pause,
Play,
X,
Zap,
} from "lucide-react"
import {
AiKitStyles,
AiStyle,
BrandIcon,
cx,
Face,
Roll,
type AiMood,
type AiShape,
type AiTone,
} from "@/lib/ai-kit"
export interface SteerStep {
id: string
label: string
status: "todo" | "run" | "done" | "cut"
time?: string
/** Added by you while the agent was working. */
fromYou?: boolean
}
export interface SteerNote {
id: string
text: string
}
export interface AgentSteeringProps {
title: string
model: string
vendor?: string
tone?: AiTone
shape?: AiShape
state: "running" | "paused" | "done"
elapsed: string
steps: readonly SteerStep[]
/** Notes queued for the next step. */
queue: readonly SteerNote[]
/** A queued note on its way into the plan. */
leaving?: string | null
draft: string
onDraft: (value: string) => void
/** Enter: queue the draft for the next step. */
onQueue: (text: string) => void
/** ⌘ Enter, or "Now" on a queued note: interrupt with it right away. */
onInterrupt: (text: string, noteId?: string) => void
onDrop?: (noteId: string) => void
onPause?: () => void
className?: string
}
const CSS = `
.aik-st{--aik-r-shell:26px;--aik-rim:6px;width:min(100%,740px);container-type:inline-size;--c:var(--aik-f-blue)}
.aik-st-card{display:grid;grid-template-columns:minmax(0,1fr);overflow:hidden}
.aik-st-head{display:flex;align-items:center;gap:13px;padding:18px 20px;border-bottom:1px solid var(--aik-line)}
.aik-st-head > div{display:grid;grid-template-columns:minmax(0,1fr);min-width:0;flex:1}
.aik-st-head b{font-size:16px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.aik-st-head small{display:flex;align-items:center;gap:6px;min-width:0;overflow:hidden;font-size:13px;color:var(--aik-text-3);white-space:nowrap}
.aik-st-head small > *{flex:none}
.aik-st-head small > :last-child{flex:0 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis}
.aik-st-head > :not(div){flex:none}
.aik-st-state{display:inline-flex;align-items:center;gap:8px;font-size:14px;color:var(--aik-text-2);font-variant-numeric:tabular-nums;white-space:nowrap}
.aik-st-state i{width:9px;height:9px;border-radius:50%;background:var(--c);box-shadow:0 0 0 4px color-mix(in oklab,var(--c) 22%,transparent);animation:aik-st-ping 1.6s ease-in-out infinite}
.aik-st[data-state="paused"] .aik-st-state i{background:var(--aik-amber);box-shadow:0 0 0 4px color-mix(in oklab,var(--aik-amber) 22%,transparent);animation:none}
.aik-st[data-state="done"] .aik-st-state i{background:var(--aik-green);box-shadow:none;animation:none}
.aik-st-steps{display:grid;padding:12px 20px 14px}
.aik-st-step{position:relative;display:grid;grid-template-columns:24px minmax(0,1fr) auto;align-items:center;gap:14px;min-height:46px;font-size:15px;border-radius:10px;transition:color var(--aik-d-panel)}
.aik-st-step + .aik-st-step::before{content:"";position:absolute;left:11.25px;top:-12px;height:24px;width:1.5px;background:var(--aik-line-2)}
.aik-st-step[data-s="todo"]{color:var(--aik-text-3)}
.aik-st-step[data-s="done"]{color:var(--aik-text-2)}
.aik-st-step[data-s="cut"]{color:var(--aik-text-3)}
.aik-st-step[data-s="cut"] .aik-st-lbl{text-decoration:line-through;text-decoration-color:var(--aik-text-3)}
.aik-st-dot{position:relative;z-index:1;display:grid;place-items:center;width:24px;height:24px;border-radius:50%;background:var(--aik-card)}
.aik-st-step[data-s="todo"] .aik-st-dot{border:1.5px dashed var(--aik-line-3)}
.aik-st-step[data-s="done"] .aik-st-dot{background:var(--c);color:var(--aik-on-fill);animation:aik-st-pop 420ms var(--aik-ease-out)}
.aik-st-step[data-s="cut"] .aik-st-dot{border:1.5px solid var(--aik-amber);color:var(--aik-amber)}
.aik-st-step[data-s="run"] .aik-st-dot::after{content:"";position:absolute;inset:0;border-radius:50%;border:2px solid color-mix(in oklab,var(--c) 22%,transparent);border-top-color:var(--c);animation:aik-spin .85s linear infinite}
.aik-st-lbl{display:flex;align-items:center;gap:8px;min-width:0}
.aik-st-lbl > span{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.aik-st-step[data-s="run"] .aik-st-lbl > span{font-weight:500}
.aik-st-you{flex:none;display:inline-flex;align-items:center;height:22px;padding:0 7px;border-radius:6px;font-size:12px;font-weight:500;color:var(--c);background:color-mix(in oklab,var(--c) 14%,transparent)}
.aik-st-cut{flex:none;font-size:12px;color:var(--aik-amber)}
.aik-st-time{font:13px var(--aik-mono);color:var(--aik-text-3);font-variant-numeric:tabular-nums}
.aik-st-step[data-fresh]{animation:aik-st-land 640ms var(--aik-ease-soft) both}
.aik-st-step[data-fresh]::after{content:"";position:absolute;inset:0 -8px;border-radius:10px;pointer-events:none;background:linear-gradient(90deg,transparent,color-mix(in oklab,var(--c) 22%,transparent),transparent) 0 0/50% 100% no-repeat;animation:aik-st-sweep 900ms var(--aik-ease-out) 200ms both}
.aik-st-q{display:grid;grid-template-columns:minmax(0,1fr);gap:10px;padding:14px 20px 16px;border-top:1px solid var(--aik-line);background:var(--aik-sunk)}
.aik-st-qh{display:flex;align-items:center;gap:8px;font:600 11.5px var(--aik-sans);letter-spacing:.08em;text-transform:uppercase;color:var(--aik-text-3)}
.aik-st-qh span{display:inline-grid;place-items:center;min-width:20px;height:20px;padding:0 5px;border-radius:6px;background:var(--aik-raised);letter-spacing:0;font-variant-numeric:tabular-nums;color:var(--aik-text-2)}
.aik-st-note-wrap{transition:opacity 360ms var(--aik-ease-out),transform 520ms var(--aik-ease-move)}
.aik-st-note-wrap[data-leaving]{opacity:0;transform:translateY(-28px) scale(.97)}
.aik-st-note{display:flex;align-items:center;gap:12px;min-height:48px;padding:0 8px 0 14px;border-radius:12px;background:var(--aik-card);box-shadow:var(--aik-sh-card);font-size:15px;animation:aik-st-in 420ms var(--aik-ease-soft) both}
.aik-st-note::before{content:"";width:3px;align-self:stretch;margin:12px 0;border-radius:2px;background:var(--c)}
.aik-st-note p{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.aik-st-empty{display:flex;align-items:center;min-height:48px;padding:0 2px;font-size:14px;color:var(--aik-text-3);animation:aik-st-fade 360ms var(--aik-ease-out) both}
@keyframes aik-st-fade{from{opacity:0}}
.aik-st-compose{display:grid;grid-template-columns:minmax(0,1fr);gap:10px;padding:14px 20px 16px;border-top:1px solid var(--aik-line)}
.aik-st-field{display:flex;align-items:center;gap:8px;height:52px;padding:0 8px 0 16px;border-radius:14px;background:var(--aik-sunk);box-shadow:inset 0 0 0 1px var(--aik-line-2);transition:box-shadow var(--aik-d-state)}
.aik-st-field:focus-within{box-shadow:inset 0 0 0 1.5px color-mix(in oklab,var(--c) 70%,transparent)}
.aik-st-field input{flex:1;min-width:0;height:100%;border:0;outline:0;background:none;font-size:15px}
.aik-st-field input::placeholder{color:var(--aik-text-3)}
.aik-st-send{display:grid;place-items:center;width:36px;height:36px;border-radius:10px;background:var(--aik-raised);color:var(--aik-text-3);transition:background var(--aik-d-state),color var(--aik-d-state),transform var(--aik-d-press)}
.aik-st-send[data-on]{background:var(--aik-pri);color:var(--aik-pri-ink)}
.aik-st-send:active{transform:scale(.92)}
.aik-st-hints{display:flex;gap:18px;flex-wrap:wrap;font-size:13px;color:var(--aik-text-3)}
.aik-st-hints span{display:inline-flex;align-items:center;gap:6px}
@keyframes aik-st-ping{50%{box-shadow:0 0 0 7px color-mix(in oklab,var(--c) 6%,transparent)}}
@keyframes aik-st-pop{from{transform:scale(.6)}}
@keyframes aik-st-in{from{opacity:0;transform:translateY(10px)}}
@keyframes aik-st-land{from{opacity:0;transform:translateY(46px) scale(.98)}}
@keyframes aik-st-sweep{from{background-position:-60% 0}to{background-position:220% 0}}
@container (max-width:460px){.aik-st-head,.aik-st-steps,.aik-st-q,.aik-st-compose{padding-left:14px;padding-right:14px}.aik-st-state span{display:none}.aik-st-hints span:last-child{display:none}}
@media (prefers-reduced-motion: reduce){.aik-st-step[data-fresh],.aik-st-step[data-fresh]::after,.aik-st-note{animation:none}}
`
/**
* Rows and panels that move because a note landed or left glide to their new
* place (FLIP: measure, invert with a transform, play); no height animates.
*/
function useFlip(ref: React.RefObject<HTMLElement | null>, selector: string) {
const last = React.useRef(new Map<Element, number>())
React.useLayoutEffect(() => {
const root = ref.current
if (!root) return
const still = window.matchMedia("(prefers-reduced-motion: reduce)").matches
const next = new Map<Element, number>()
root.querySelectorAll<HTMLElement>(selector).forEach((el) => {
const top = el.offsetTop
next.set(el, top)
const prev = last.current.get(el)
if (!still && prev !== undefined && Math.abs(prev - top) > 0.5) {
el.animate(
[{ transform: `translateY(${prev - top}px)` }, { transform: "none" }],
{ duration: 480, easing: "cubic-bezier(.65,0,.15,1)" }
)
}
})
last.current = next
})
}
/**
* Steer an agent while it works. Queue a note for the next step and watch it
* slide out of the queue into the plan when the agent picks it up, or send it
* with ⌘ Enter to interrupt right away.
*/
export function AgentSteering({
title,
model,
vendor,
tone = "blue",
shape = "leaf",
state,
elapsed,
steps,
queue,
leaving,
draft,
onDraft,
onQueue,
onInterrupt,
onDrop,
onPause,
className,
}: AgentSteeringProps) {
const at = steps.findIndex((s) => s.status === "run")
const doneCount = steps.filter((s) => s.status === "done").length
const mood: AiMood =
state === "done"
? "happy"
: state === "paused"
? "sleep"
: leaving
? "listen"
: "work"
const card = React.useRef<HTMLDivElement>(null)
useFlip(card, ".aik-st-step, .aik-st-q, .aik-st-compose")
const seen = React.useRef<Set<string> | null>(null)
if (seen.current === null) seen.current = new Set(steps.map((s) => s.id))
const fresh = steps.filter((s) => !seen.current!.has(s.id)).map((s) => s.id)
React.useEffect(() => {
const id = window.setTimeout(
() => fresh.forEach((f) => seen.current!.add(f)),
1200
)
return () => window.clearTimeout(id)
})
const submit = (now: boolean) => {
const text = draft.trim()
if (!text) return
if (now) onInterrupt(text)
else onQueue(text)
}
return (
<div
className={cx("aik aik-st aik-shell", className)}
data-state={state}
style={{ "--c": `var(--aik-f-${tone})` } as React.CSSProperties}
>
<AiKitStyles />
<AiStyle id="agent-steering" css={CSS} />
<div ref={card} className="aik-surface aik-st-card">
<div className="aik-st-head">
<Face mood={mood} shape={shape} tone={tone} size={40} />
<div>
<b>{title}</b>
<small>
{vendor ? (
<BrandIcon name={vendor} tint="brand" size={13} />
) : null}
{model} ·{" "}
<Roll>
{state === "done"
? "All steps done"
: `Step ${Math.max(at, doneCount) + 1} of ${steps.length}`}
</Roll>
</small>
</div>
<span className="aik-st-state">
<i aria-hidden="true" />
<span>
<Roll>
{state === "running"
? "Running"
: state === "paused"
? "Paused"
: "Done"}
</Roll>{" "}
· {elapsed}
</span>
</span>
{onPause && state !== "done" ? (
<button
type="button"
className="aik-btn line icon"
onClick={onPause}
aria-label={state === "paused" ? "Resume" : "Pause"}
>
{state === "paused" ? <Play size={15} /> : <Pause size={15} />}
</button>
) : null}
</div>
<ol className="aik-st-steps">
{steps.map((step) => (
<li
key={step.id}
className="aik-st-step"
data-s={step.status}
data-fresh={fresh.includes(step.id) ? "" : undefined}
>
<span className="aik-st-dot" aria-hidden="true">
{step.status === "done" ? (
<Check size={14} strokeWidth={3} />
) : step.status === "cut" ? (
<X size={12} strokeWidth={3} />
) : null}
</span>
<span className="aik-st-lbl">
<span>{step.label}</span>
{step.fromYou ? (
<span className="aik-st-you">From you</span>
) : null}
{step.status === "cut" ? (
<span className="aik-st-cut">Interrupted</span>
) : null}
</span>
<span className="aik-st-time">{step.time}</span>
</li>
))}
</ol>
<div className="aik-st-q">
<p className="aik-st-qh">
Queued for the next step{" "}
<span>
<Roll>{String(queue.length)}</Roll>
</span>
</p>
{queue.length ? (
queue.map((note) => (
<div
key={note.id}
className="aik-st-note-wrap"
data-leaving={leaving === note.id ? "" : undefined}
>
<div>
<div className="aik-st-note">
<p>{note.text}</p>
<button
type="button"
className="aik-btn ghost sm"
onClick={() => onInterrupt(note.text, note.id)}
>
<Zap size={14} aria-hidden="true" /> Now
</button>
{onDrop ? (
<button
type="button"
className="aik-btn ghost sm icon"
onClick={() => onDrop(note.id)}
aria-label="Remove note"
>
<X size={14} />
</button>
) : null}
</div>
</div>
</div>
))
) : (
<p className="aik-st-empty">
Nothing queued. Notes you add land here first.
</p>
)}
</div>
<div className="aik-st-compose">
<form
className="aik-st-field"
onSubmit={(event) => {
event.preventDefault()
submit(false)
}}
>
<input
value={draft}
onChange={(event) => onDraft(event.target.value)}
onKeyDown={(event) => {
if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
event.preventDefault()
submit(true)
}
}}
placeholder="Steer the agent…"
aria-label="Steer the agent"
/>
<button
type="submit"
className="aik-st-send"
data-on={draft.trim() ? "" : undefined}
aria-label="Queue note"
>
<ArrowUp size={17} />
</button>
</form>
<p className="aik-st-hints">
<span>
<kbd className="aik-kbd">
<CornerDownLeft size={10} />
</kbd>{" "}
next step
</span>
<span>
<kbd className="aik-kbd">⌘</kbd>
<kbd className="aik-kbd">
<CornerDownLeft size={10} />
</kbd>{" "}
interrupt now
</span>
</p>
</div>
</div>
</div>
)
}
Installation
One command adds agent-steering 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-steering.json