AI Plan
The plan of a run: a board whose cards move from to do to done, a winding route the agent face travels, and a draft list you drag to reorder before starting.
"use client"
import * as React from "react"
import {
ChevronLeft,
ChevronRight,
GripVertical,
Play,
Plus,
X,
} from "lucide-react"
import {
AiKitStyles,
AiStyle,
cx,
Face,
Mark,
Pill,
Roll,
type AiMood,
type AiShape,
type AiTone,
} from "@/lib/ai-kit"
const CSS = `
.aik-pl-board{--aik-r-shell:26px;--aik-rim:5px;width:min(100%,580px);container-type:inline-size}
.aik-pl-bcard{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px;padding:10px}
.aik-pl-col{display:grid;align-content:start;gap:8px;min-height:318px;padding:8px;border-radius:14px;background:var(--aik-sunk);box-shadow:inset 0 0 0 1px var(--aik-line)}
.aik-pl-colh{display:flex;align-items:center;gap:8px;height:28px;padding:0 6px;font-size:13px;font-weight:600}
.aik-pl-colh i{width:8px;height:8px;border-radius:50%;background:var(--aik-text-3)}
.aik-pl-col[data-c="doing"] .aik-pl-colh i{background:var(--aik-blue)}
.aik-pl-col[data-c="done"] .aik-pl-colh i{background:var(--aik-green)}
.aik-pl-colh .aik-roll{margin-left:auto;font:500 12.5px var(--aik-mono);color:var(--aik-text-3);font-variant-numeric:tabular-nums}
.aik-pl-item{position:relative;display:grid;gap:10px;padding:12px 12px 10px;border-radius:11px;background:var(--aik-card);box-shadow:var(--aik-sh-card);outline:none;will-change:transform}
.aik-pl-item:focus-visible{box-shadow:0 0 0 2px var(--aik-blue)}
.aik-pl-item > b{font-size:14px;line-height:19px;font-weight:500;transition:color var(--aik-d-panel)}
.aik-pl-col[data-c="done"] .aik-pl-item > b{color:var(--aik-text-2)}
.aik-pl-item > div{display:flex;align-items:center;gap:6px;min-height:22px;font-size:12px;color:var(--aik-text-3)}
.aik-pl-item em{margin-left:auto;font:12px var(--aik-mono);font-style:normal;color:var(--aik-text-3);transition:opacity var(--aik-d-state)}
.aik-pl-nav{position:absolute;right:8px;bottom:8px;display:flex;gap:2px;opacity:0;transition:opacity var(--aik-d-state)}
.aik-pl-item:hover .aik-pl-nav,.aik-pl-item:focus-within .aik-pl-nav,.aik-pl-item:focus-visible .aik-pl-nav{opacity:1}
.aik-pl-item:hover em,.aik-pl-item:focus-within em{opacity:0}
.aik-pl-nav button{display:grid;place-items:center;width:24px;height:24px;border-radius:7px;background:var(--aik-raised);color:var(--aik-text-2);transition:background var(--aik-d-state),transform var(--aik-d-press)}
.aik-pl-nav button:hover{color:var(--aik-text)}
.aik-pl-nav button:active{transform:scale(.92)}
.aik-pl-nav button:disabled{opacity:.35;pointer-events:none}
@container (max-width:470px){.aik-pl-bcard{grid-template-columns:minmax(0,1fr)}.aik-pl-col{min-height:0}}
.aik-pl-route{--aik-r-shell:26px;--aik-rim:5px;width:min(100%,580px);container-type:inline-size}
.aik-pl-rcard{display:grid;gap:4px;padding:10px 10px 12px}
.aik-pl-map{display:block;width:100%;height:auto;overflow:visible}
.aik-pl-road{fill:none;stroke:var(--aik-line-3);stroke-width:2.5;stroke-linecap:round;stroke-dasharray:1 9}
.aik-pl-gone{fill:none;stroke:var(--aik-blue);stroke-width:3;stroke-linecap:round;stroke-dasharray:100;transition:stroke-dashoffset 700ms var(--aik-ease-move)}
.aik-pl-stop{cursor:pointer;outline:none}
.aik-pl-stop circle{fill:var(--aik-card);stroke:var(--aik-line-3);stroke-width:2;transition:fill var(--aik-d-panel),stroke var(--aik-d-panel)}
.aik-pl-stop path{fill:none;stroke:var(--aik-on-fill);stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:14;stroke-dashoffset:14;transition:stroke-dashoffset 320ms var(--aik-ease-out) 380ms}
.aik-pl-stop[data-s="done"] circle{fill:var(--aik-green);stroke:var(--aik-green)}
.aik-pl-stop[data-s="done"] path{stroke-dashoffset:0}
.aik-pl-stop[data-s="now"] circle{stroke:var(--aik-blue);stroke-width:2.5}
.aik-pl-stop:focus-visible circle{stroke:var(--aik-blue);stroke-width:3.5}
.aik-pl-stop text{font:500 12px var(--aik-sans);fill:var(--aik-text-3);text-anchor:middle;transition:fill var(--aik-d-panel)}
.aik-pl-stop[data-s="now"] text{fill:var(--aik-text)}
.aik-pl-walker{transition:offset-distance 700ms var(--aik-ease-move)}
.aik-pl-walker foreignObject{overflow:visible}
.aik-pl-now{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:4px 12px;align-items:center;margin:0 6px;padding:14px 12px 14px 16px;border-radius:14px;background:var(--aik-sunk);box-shadow:inset 0 0 0 1px var(--aik-line)}
.aik-pl-now > div{display:grid;gap:2px;min-width:0;animation:aik-pop var(--aik-d-panel) var(--aik-ease-out) both}
.aik-pl-now b{font-size:16px;line-height:22px;font-weight:600;letter-spacing:-.01em}
.aik-pl-now p{font-size:13.5px;line-height:19px;color:var(--aik-text-2)}
.aik-pl-now > span{display:flex;gap:4px}
.aik-pl-ib{display:grid;place-items:center;width:34px;height:34px;border-radius:10px;background:var(--aik-card);box-shadow:var(--aik-sh-card);color:var(--aik-text-2);transition:color var(--aik-d-state),transform var(--aik-d-press) var(--aik-ease-out)}
.aik-pl-ib:hover{color:var(--aik-text)}
.aik-pl-ib:active{transform:scale(.94)}
.aik-pl-ib:disabled{opacity:.4;pointer-events:none}
@container (max-width:430px){.aik-pl-stop text{display:none}}
@media (prefers-reduced-motion: reduce){.aik-pl-gone,.aik-pl-walker,.aik-pl-stop path{transition:none}}
.aik-pl-draft{--aik-r-shell:26px;--aik-rim:5px;width:min(100%,540px);container-type:inline-size}
.aik-pl-dcard{display:grid}
.aik-pl-dhead{display:flex;align-items:center;gap:10px;height:52px;padding:0 14px 0 18px;border-bottom:1px solid var(--aik-line);font-size:15px;font-weight:600}
.aik-pl-dhead span:first-of-type{font:500 12.5px var(--aik-mono);color:var(--aik-text-3);font-variant-numeric:tabular-nums}
.aik-pl-dhead .aik-pill{margin-left:auto}
.aik-pl-rows{position:relative;padding:6px}
.aik-pl-row{position:relative;display:flex;align-items:center;gap:8px;height:44px;margin-bottom:4px;padding:0 8px 0 4px;border-radius:11px;background:var(--aik-card);font-size:15px;transform:translateY(calc(var(--shift,0)*48px));transition:transform 320ms var(--aik-ease-move),box-shadow var(--aik-d-state),background var(--aik-d-state)}
.aik-pl-row:last-child{margin-bottom:0}
.aik-pl-rows[data-settle] .aik-pl-row{transition:none!important}
.aik-pl-row:hover{background:var(--aik-raised)}
.aik-pl-row[data-lift]{z-index:3;background:var(--aik-card);box-shadow:var(--aik-sh-pop);transform:translateY(var(--dy,0px)) scale(1.02);transition:transform 480ms var(--aik-ease-move),box-shadow var(--aik-d-state)}
.aik-pl-row[data-lift="drag"]{transition:box-shadow var(--aik-d-state)}
.aik-pl-grip{display:grid;place-items:center;width:28px;height:32px;flex:none;border-radius:8px;color:var(--aik-text-3);cursor:grab;touch-action:none}
.aik-pl-grip:active{cursor:grabbing}
.aik-pl-grip:disabled{opacity:.35;cursor:default}
.aik-pl-num{display:grid;place-items:center;width:22px;height:22px;flex:none;border-radius:7px;background:var(--aik-raised);font:500 12px var(--aik-mono);color:var(--aik-text-2);font-variant-numeric:tabular-nums}
.aik-pl-row[data-lift] .aik-pl-num,.aik-pl-row:hover .aik-pl-num{background:var(--aik-sunk)}
.aik-pl-row > b{flex:1;min-width:0;font-weight:400;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.aik-pl-est{height:22px;padding:0 7px;border-radius:7px;display:inline-flex;align-items:center;font:12px var(--aik-mono);color:var(--aik-text-2);box-shadow:inset 0 0 0 1px var(--aik-line-2);white-space:nowrap}
.aik-pl-rm{display:grid;place-items:center;width:26px;height:26px;border-radius:8px;color:var(--aik-text-3);opacity:0;transition:opacity var(--aik-d-state),background var(--aik-d-state)}
.aik-pl-row:hover .aik-pl-rm,.aik-pl-rm:focus-visible{opacity:1}
.aik-pl-rm:hover{background:var(--aik-hover);color:var(--aik-text)}
.aik-pl-row[data-s="run"] > b{font-weight:500}
.aik-pl-add{display:flex;align-items:center;gap:10px;height:48px;padding:0 10px 0 16px;border-top:1px solid var(--aik-line);color:var(--aik-text-3)}
.aik-pl-add input{flex:1;min-width:0;height:100%;border:0;outline:0;background:none;font-size:15px;color:var(--aik-text)}
.aik-pl-add input::placeholder{color:var(--aik-text-3);opacity:1}
.aik .aik-pl-add input:focus-visible{outline:none}
.aik-pl-dfoot{display:flex;align-items:center;gap:12px;height:52px;padding:0 10px 0 18px;color:var(--aik-text-2);font-size:13px}
.aik-pl-dfoot .aik-roll{font:500 13px var(--aik-mono);color:var(--aik-text);font-variant-numeric:tabular-nums}
.aik-pl-dfoot .aik-btn{margin-left:auto;height:36px;padding:0 14px 0 12px;border-radius:11px;font-size:14px}
.aik-pl-run{display:inline-flex;align-items:center;gap:8px;margin-left:auto;font-size:14px;font-weight:500;color:var(--aik-text);animation:aik-in var(--aik-d-enter) var(--aik-ease-out) both}
@container (max-width:400px){.aik-pl-est{display:none}}
@media (prefers-reduced-motion: reduce){.aik-pl-row{transition:none!important}}
`
export type AiPlanColumn = "todo" | "doing" | "done"
export interface AiPlanCard {
id: string
title: string
column: AiPlanColumn
/** Who owns the card, shown with a small face. */
agent?: string
/** Face colour for the owner. */
tone?: AiTone | (string & {})
shape?: AiShape
/** A short estimate or duration, shown in mono. */
estimate?: string
}
export interface AiPlanBoardProps extends React.HTMLAttributes<HTMLDivElement> {
cards: AiPlanCard[]
/** Called when a card is moved by its buttons or the arrow keys. */
onMove?: (id: string, column: AiPlanColumn) => void
/** Column headings, in order. */
labels?: [string, string, string]
}
const COLUMNS: AiPlanColumn[] = ["todo", "doing", "done"]
/**
* A plan as a board. Cards travel between To do, Doing and Done on a FLIP
* transform whenever their column changes, by the agent or by hand.
*/
export function AiPlanBoard({
cards,
onMove,
labels = ["To do", "Doing", "Done"],
className,
...rest
}: AiPlanBoardProps) {
const nodes = React.useRef(new Map<string, HTMLElement>())
const rects = React.useRef(new Map<string, DOMRect>())
// FLIP: remember where each card was, and after a change animate it from there.
React.useLayoutEffect(() => {
const calm = window.matchMedia("(prefers-reduced-motion: reduce)").matches
nodes.current.forEach((node, id) => {
const next = node.getBoundingClientRect()
const prev = rects.current.get(id)
rects.current.set(id, next)
if (!prev || calm || node.getAnimations().length > 0) return
const dx = prev.left - next.left
const dy = prev.top - next.top
if (Math.abs(dx) < 1 && Math.abs(dy) < 1) return
node.animate(
[
{ transform: `translate(${dx}px, ${dy}px)`, zIndex: 4 },
{ transform: "none", zIndex: 4 },
],
{ duration: 560, easing: "cubic-bezier(.65,0,.15,1)" }
)
})
})
const shift = (card: AiPlanCard, delta: number) => {
const next = COLUMNS[COLUMNS.indexOf(card.column) + delta]
if (next) onMove?.(card.id, next)
}
return (
<div {...rest} className={cx("aik aik-pl-board", className)}>
<AiKitStyles />
<AiStyle id="ai-plan" css={CSS} />
<div className="aik-shell">
<div className="aik-surface aik-pl-bcard">
{COLUMNS.map((column, at) => {
const list = cards.filter((card) => card.column === column)
return (
<section
key={column}
className="aik-pl-col"
data-c={column}
aria-label={labels[at]}
>
<div className="aik-pl-colh">
<i />
{labels[at]}
<Roll>{String(list.length)}</Roll>
</div>
{list.map((card) => (
<div
key={card.id}
ref={(node) => {
if (node) nodes.current.set(card.id, node)
else nodes.current.delete(card.id)
}}
className="aik-pl-item"
role="group"
aria-label={`${card.title}, ${labels[at]}`}
tabIndex={0}
onKeyDown={(event) => {
if (event.key === "ArrowRight") shift(card, 1)
if (event.key === "ArrowLeft") shift(card, -1)
}}
>
<b>{card.title}</b>
<div>
{column === "done" ? (
<Mark status="done" />
) : (
<Face
size={20}
tone={card.tone ?? "blue"}
shape={card.shape ?? "orb"}
mood={column === "doing" ? "work" : "idle"}
/>
)}
{card.agent}
{card.estimate ? <em>{card.estimate}</em> : null}
</div>
<span className="aik-pl-nav">
<button
type="button"
aria-label="Move back"
disabled={column === "todo"}
tabIndex={-1}
onClick={() => shift(card, -1)}
>
<ChevronLeft size={14} />
</button>
<button
type="button"
aria-label="Move forward"
disabled={column === "done"}
tabIndex={-1}
onClick={() => shift(card, 1)}
>
<ChevronRight size={14} />
</button>
</span>
{column === "doing" ? (
<i className="aik-beam" data-on="" />
) : null}
</div>
))}
</section>
)
})}
</div>
</div>
</div>
)
}
export interface AiMilestone {
id: string
title: string
/** One line about the milestone, shown in the card under the map. */
note?: string
/** A short label under the node. Defaults to the title's first word. */
short?: string
}
export interface AiPlanRouteProps extends Omit<
React.HTMLAttributes<HTMLDivElement>,
"onSelect"
> {
milestones: AiMilestone[]
/** How many milestones are finished. The face stands at the next one. */
done: number
/** Called with a milestone's index from its node or the arrow buttons. */
onSelect?: (index: number) => void
/** Face colour: a named tone or any CSS colour. */
tone?: AiTone | (string & {})
shape?: AiShape
mood?: AiMood
}
const ROAD =
"M 34 176 C 104 176, 104 62, 176 62 S 256 170, 330 170 S 420 70, 488 52"
/**
* A plan as a route. The agent's face walks a winding path from milestone to
* milestone, and the stretch behind it draws in.
*/
export function AiPlanRoute({
milestones,
done,
onSelect,
tone = "blue",
shape = "blob",
mood,
className,
...rest
}: AiPlanRouteProps) {
const last = Math.max(milestones.length - 1, 1)
const finished = done >= milestones.length
const at = Math.min(Math.max(done, 0), milestones.length - 1)
const fraction = (index: number) => 3 + (index / last) * 94
const current = milestones[at]
const motion = (distance: number): React.CSSProperties => ({
offsetPath: `path("${ROAD}")`,
offsetDistance: `${distance}%`,
offsetRotate: "0deg",
})
return (
<div {...rest} className={cx("aik aik-pl-route", className)}>
<AiKitStyles />
<AiStyle id="ai-plan" css={CSS} />
<div className="aik-shell">
<div className="aik-surface aik-pl-rcard">
<svg
className="aik-pl-map"
viewBox="0 0 520 232"
role="group"
aria-label="Plan route"
>
<path className="aik-pl-road" d={ROAD} />
<path
className="aik-pl-gone"
d={ROAD}
pathLength={100}
style={{ strokeDashoffset: 100 - fraction(at) }}
/>
{milestones.map((milestone, index) => {
const state =
index < done ? "done" : index === at ? "now" : "todo"
return (
<g
key={milestone.id}
className="aik-pl-stop"
data-s={state}
style={motion(fraction(index))}
role="button"
tabIndex={0}
aria-label={`${milestone.title}: ${state}`}
onClick={() => onSelect?.(index)}
onKeyDown={(event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault()
onSelect?.(index)
}
}}
>
<circle
r="18"
style={{ fill: "transparent", stroke: "none" }}
/>
<circle r="11" />
<path d="M-4.5 0.4 L-1.4 3.4 L4.8 -3.4" />
<text y="32">
{milestone.short ?? milestone.title.split(" ")[0]}
</text>
</g>
)
})}
<g className="aik-pl-walker" style={motion(fraction(at))}>
<foreignObject x="-24" y="-66" width="48" height="48">
<Face
size={44}
tone={tone}
shape={shape}
mood={mood ?? (finished ? "happy" : "work")}
style={{ display: "block", margin: 2 }}
/>
</foreignObject>
</g>
</svg>
<div className="aik-pl-now" aria-live="polite">
<div key={finished ? "end" : current?.id}>
<span className="aik-label">
{finished
? "Arrived"
: `Stop ${at + 1} of ${milestones.length}`}
</span>
<b>{finished ? "Everything is shipped" : current?.title}</b>
{finished ? (
<p>All {milestones.length} milestones are behind you.</p>
) : current?.note ? (
<p>{current.note}</p>
) : null}
</div>
<span>
<button
type="button"
className="aik-pl-ib"
aria-label="Previous milestone"
disabled={done <= 0}
onClick={() => onSelect?.(Math.max(done - 1, 0))}
>
<ChevronLeft size={16} />
</button>
<button
type="button"
className="aik-pl-ib"
aria-label="Next milestone"
disabled={finished}
onClick={() => onSelect?.(done + 1)}
>
<ChevronRight size={16} />
</button>
</span>
</div>
</div>
</div>
</div>
)
}
export interface AiDraftStep {
id: string
title: string
/** Estimate in minutes. */
minutes?: number
}
export interface AiPlanDraftProps extends Omit<
React.HTMLAttributes<HTMLDivElement>,
"title"
> {
steps: AiDraftStep[]
/** Called with every id in the new order after a drag or a keyboard move. */
onReorder: (ids: string[]) => void
onRemove?: (id: string) => void
/** Called with the text of the add row on Enter. Hides the row when omitted. */
onAdd?: (title: string) => void
/** Controls the add row's text. Leave undefined to let it manage itself. */
addValue?: string
onAddValueChange?: (value: string) => void
onStart?: () => void
/** `running` locks the rows and turns the footer into a progress line. */
status?: "draft" | "running"
/** The step being worked on while running, counted from 0. */
runningIndex?: number
/** Lifts a row and holds it over another slot, for scripted demos. */
lift?: { id: string; to: number }
title?: string
}
const SLOT = 48
/**
* The plan before the run. Drag a row by its handle, or move it with the arrow
* keys; add and remove steps; the total follows. Start hands it to the agent.
*/
export function AiPlanDraft({
steps,
onReorder,
onRemove,
onAdd,
addValue,
onAddValueChange,
onStart,
status = "draft",
runningIndex = 0,
lift,
title = "Plan",
className,
...rest
}: AiPlanDraftProps) {
const [drag, setDrag] = React.useState<{
id: string
start: number
dy: number
} | null>(null)
const [ownAdd, setOwnAdd] = React.useState("")
const [said, setSaid] = React.useState("")
const running = status === "running"
const text = addValue ?? ownAdd
const setText = (value: string) => {
if (addValue === undefined) setOwnAdd(value)
onAddValueChange?.(value)
}
const ids = steps.map((step) => step.id)
const liftedId = drag?.id ?? lift?.id
const from = liftedId ? ids.indexOf(liftedId) : -1
const clamp = (index: number) =>
Math.min(Math.max(index, 0), steps.length - 1)
const to =
from < 0
? -1
: drag
? clamp(from + Math.round(drag.dy / SLOT))
: clamp(lift?.to ?? from)
const dy = drag ? drag.dy : (to - from) * SLOT
const move = (id: string, target: number) => {
const start = ids.indexOf(id)
const end = clamp(target)
if (start < 0 || start === end) return
const next = [...ids]
next.splice(start, 1)
next.splice(end, 0, id)
onReorder(next)
setSaid(`Moved to position ${end + 1} of ${steps.length}`)
}
const total = steps.reduce((sum, step) => sum + (step.minutes ?? 0), 0)
// When the order commits, rows land in their new slots with no transform left
// to animate, so transitions are held off for two frames to avoid a jump.
const list = React.useRef<HTMLOListElement>(null)
const order = ids.join("|")
React.useLayoutEffect(() => {
const node = list.current
if (!node) return
node.dataset.settle = ""
let inner = 0
const outer = requestAnimationFrame(() => {
inner = requestAnimationFrame(() => delete node.dataset.settle)
})
return () => {
cancelAnimationFrame(outer)
cancelAnimationFrame(inner)
}
}, [order])
return (
<div
{...rest}
className={cx("aik aik-pl-draft", className)}
data-s={status}
>
<AiKitStyles />
<AiStyle id="ai-plan" css={CSS} />
<div className="aik-shell">
<div className="aik-surface aik-pl-dcard">
<div className="aik-pl-dhead">
{title}
<span>{steps.length} steps</span>
<Pill status={running ? "run" : "todo"}>
<Roll>{running ? "Running" : "Draft"}</Roll>
</Pill>
</div>
<ol className="aik-pl-rows" ref={list}>
{steps.map((step, index) => {
const lifted = step.id === liftedId
let shift = 0
if (!lifted && from >= 0) {
if (from < to && index > from && index <= to) shift = -1
if (from > to && index >= to && index < from) shift = 1
}
const state = running
? index < runningIndex
? "done"
: index === runningIndex
? "run"
: "todo"
: undefined
return (
<li
key={step.id}
className="aik-pl-row"
data-lift={lifted ? (drag ? "drag" : "hold") : undefined}
data-s={state}
style={
{
"--shift": shift,
"--dy": `${dy}px`,
} as React.CSSProperties
}
>
<button
type="button"
className="aik-pl-grip"
aria-label={`Reorder ${step.title}. Use the arrow keys.`}
disabled={running}
onPointerDown={(event) => {
event.currentTarget.setPointerCapture(event.pointerId)
setDrag({ id: step.id, start: event.clientY, dy: 0 })
}}
onPointerMove={(event) => {
if (drag?.id === step.id)
setDrag({ ...drag, dy: event.clientY - drag.start })
}}
onPointerUp={() => {
if (drag?.id !== step.id) return
const target = to
setDrag(null)
move(step.id, target)
}}
onPointerCancel={() => setDrag(null)}
onKeyDown={(event) => {
if (event.key === "ArrowUp") {
event.preventDefault()
move(step.id, index - 1)
}
if (event.key === "ArrowDown") {
event.preventDefault()
move(step.id, index + 1)
}
}}
>
<GripVertical size={16} />
</button>
{state ? (
<Mark status={state} />
) : (
<span className="aik-pl-num">{index + 1}</span>
)}
<b className={state === "run" ? "aik-shimmer" : undefined}>
{step.title}
</b>
{step.minutes === undefined ? null : (
<span className="aik-pl-est">{step.minutes}m</span>
)}
{onRemove && !running ? (
<button
type="button"
className="aik-pl-rm"
aria-label={`Remove ${step.title}`}
onClick={() => onRemove(step.id)}
>
<X size={14} />
</button>
) : null}
</li>
)
})}
</ol>
{onAdd && !running ? (
<div className="aik-pl-add">
<Plus size={16} />
<input
value={text}
placeholder="Add a step"
aria-label="Add a step"
onChange={(event) => setText(event.target.value)}
onKeyDown={(event) => {
if (event.key === "Enter" && text.trim()) {
onAdd(text.trim())
setText("")
}
}}
/>
<kbd className="aik-kbd">⏎</kbd>
</div>
) : null}
<i className="aik-beam" data-on={running ? "" : undefined} />
</div>
<div className="aik-pl-dfoot">
About
<Roll>{`${total} min`}</Roll>
{running ? (
<span className="aik-pl-run" role="status">
<Mark status="run" />
Step {Math.min(runningIndex + 1, steps.length)} of {steps.length}
</span>
) : (
<button
type="button"
className="aik-btn pri"
disabled={steps.length === 0}
onClick={onStart}
>
<Play size={14} />
Start
</button>
)}
</div>
<span
aria-live="polite"
style={{
position: "absolute",
width: 1,
height: 1,
overflow: "hidden",
clipPath: "inset(50%)",
}}
>
{said}
</span>
</div>
</div>
)
}
Installation
One command adds ai-plan 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/ai-plan.json
ai-plan-demo
"use client"
import * as React from "react"
import { AiDemo } from "@/lib/ai-demo"
import { typeInto, useAiLoop, useIdleHands } from "@/lib/ai-kit"
import {
AiPlanBoard,
AiPlanDraft,
AiPlanRoute,
type AiDraftStep,
type AiMilestone,
type AiPlanCard,
type AiPlanColumn,
} from "@/registry/tween/ai-plan"
const realSleep = (ms: number) =>
new Promise<void>((resolve) => window.setTimeout(resolve, ms))
const CARDS: AiPlanCard[] = [
{
id: "read",
title: "Read the hero section",
column: "todo",
agent: "Mira",
estimate: "2m",
},
{
id: "reveal",
title: "Reuse text-skew-reveal",
column: "todo",
agent: "Mira",
estimate: "3m",
},
{
id: "write",
title: "Write the pricing section",
column: "todo",
agent: "Mira",
estimate: "8m",
},
{
id: "tests",
title: "Write 24 tests",
column: "todo",
agent: "Odo",
tone: "violet",
shape: "blob",
estimate: "6m",
},
{
id: "build",
title: "Rebuild the registry",
column: "todo",
agent: "Pim",
tone: "green",
shape: "leaf",
estimate: "2m",
},
]
function Board() {
const root = React.useRef<HTMLDivElement>(null)
const [hands, touch] = useIdleHands()
const [cards, setCards] = React.useState<AiPlanCard[]>(() =>
CARDS.map((card, index) => ({
...card,
column: index === 0 ? "done" : index === 1 ? "doing" : "todo",
}))
)
const move = (id: string, column: AiPlanColumn) =>
setCards((list) =>
list.map((card) => (card.id === id ? { ...card, column } : card))
)
useAiLoop(
root,
async ({ sleep }) => {
setCards(CARDS)
await sleep(1100)
const script: Array<[string, AiPlanColumn, number]> = [
["read", "doing", 1100],
["read", "done", 500],
["reveal", "doing", 700],
["tests", "doing", 1300],
["reveal", "done", 600],
["write", "doing", 1500],
["tests", "done", 900],
["write", "done", 500],
["build", "doing", 1400],
["build", "done", 2600],
]
for (const [id, column, hold] of script) {
move(id, column)
await sleep(hold)
}
},
{ gap: 500, enabled: !hands }
)
return (
<div
ref={root}
style={{ display: "grid", width: "min(100%, 580px)" }}
onPointerDown={touch}
onKeyDown={touch}
>
<AiPlanBoard cards={cards} onMove={move} />
</div>
)
}
const STOPS: AiMilestone[] = [
{
id: "read",
title: "Read the hero",
short: "Read",
note: "hero.tsx and the page layout, to see what is there.",
},
{
id: "pick",
title: "Pick the reveal",
short: "Pick",
note: "text-skew-reveal is installed already, so nothing new to add.",
},
{
id: "write",
title: "Write the section",
short: "Write",
note: "Pricing with a monthly and yearly toggle.",
},
{
id: "check",
title: "Check the types",
short: "Check",
note: "pnpm typecheck across 214 files.",
},
{
id: "ship",
title: "Ship the preview",
short: "Ship",
note: "Rebuild the registry and open a preview link.",
},
]
function Route() {
const root = React.useRef<HTMLDivElement>(null)
const [hands, touch] = useIdleHands()
const [done, setDone] = React.useState(2)
useAiLoop(
root,
async ({ sleep }) => {
setDone(0)
await sleep(1500)
for (let count = 1; count <= STOPS.length; count++) {
setDone(count)
await sleep(count === STOPS.length ? 2600 : 1700)
}
},
{ gap: 500, enabled: !hands, still: () => setDone(2) }
)
return (
<div
ref={root}
style={{ display: "grid", width: "min(100%, 580px)" }}
onPointerDown={touch}
onKeyDown={touch}
>
<AiPlanRoute milestones={STOPS} done={done} onSelect={setDone} />
</div>
)
}
const DRAFT: AiDraftStep[] = [
{ id: "read", title: "Read the hero section", minutes: 2 },
{ id: "write", title: "Write the pricing section", minutes: 8 },
{ id: "build", title: "Rebuild the registry", minutes: 2 },
{ id: "check", title: "Run the type check", minutes: 3 },
]
function Draft() {
const root = React.useRef<HTMLDivElement>(null)
const [hands, touch] = useIdleHands()
const [steps, setSteps] = React.useState(DRAFT)
const [lift, setLift] = React.useState<{ id: string; to: number }>()
const [add, setAdd] = React.useState("")
const [status, setStatus] = React.useState<"draft" | "running">("draft")
const [at, setAt] = React.useState(0)
const run = React.useRef(0)
const serial = React.useRef(0)
const reorder = (ids: string[]) =>
setSteps((list) =>
ids.flatMap((id) => list.filter((step) => step.id === id))
)
const append = (title: string) =>
setSteps((list) => [
...list,
{ id: `new-${++serial.current}`, title, minutes: 4 },
])
const go = React.useCallback(
async (
sleep: (ms: number) => Promise<void>,
mine: number,
count: number
) => {
setStatus("running")
for (let index = 0; index < count; index++) {
if (run.current !== mine) return
setAt(index)
await sleep(900)
}
if (run.current !== mine) return
setStatus("draft")
},
[]
)
useAiLoop(
root,
async ({ sleep }) => {
const mine = ++run.current
setStatus("draft")
setSteps(DRAFT)
setLift(undefined)
setAdd("")
await sleep(1300)
setLift({ id: "check", to: 3 })
await sleep(450)
setLift({ id: "check", to: 2 })
await sleep(800)
reorder(["read", "write", "check", "build"])
setLift(undefined)
await sleep(900)
await typeInto(setAdd, "Check contrast in dark mode", sleep, 30)
await sleep(400)
append("Check contrast in dark mode")
setAdd("")
await sleep(1300)
await go(sleep, mine, 5)
await sleep(700)
},
{ gap: 400, enabled: !hands }
)
return (
<div
ref={root}
style={{ display: "grid", width: "min(100%, 540px)" }}
onPointerDown={touch}
onKeyDown={touch}
>
<AiPlanDraft
title="Pricing section"
steps={steps}
onReorder={reorder}
onRemove={(id) =>
setSteps((list) => list.filter((step) => step.id !== id))
}
onAdd={append}
addValue={add}
onAddValueChange={setAdd}
lift={hands ? undefined : lift}
status={status}
runningIndex={at}
onStart={() => {
const mine = ++run.current
void go(realSleep, mine, steps.length)
}}
/>
</div>
)
}
export function AiPlanDemo({ only }: { only?: string }) {
return (
<AiDemo
only={only}
tabs={[
{ name: "Board", node: <Board /> },
{ name: "Route", node: <Route /> },
{ name: "Draft plan", node: <Draft /> },
]}
/>
)
}
Installation
Usage
import { AiPlanBoard, AiPlanDraft, AiPlanRoute } from "@/components/ui/ai-plan"const [steps, setSteps] = useState([
{ id: "read", title: "Read the hero section", minutes: 2 },
{ id: "write", title: "Write the pricing section", minutes: 8 },
])
<AiPlanDraft
title="Pricing section"
steps={steps}
onReorder={(ids) =>
setSteps((list) => ids.flatMap((id) => list.filter((step) => step.id === id)))
}
onAdd={(title) => setSteps((list) => [...list, { id: crypto.randomUUID(), title }])}
onRemove={(id) => setSteps((list) => list.filter((step) => step.id !== id))}
onStart={start}
/>Versions
AiPlanBoardis a three-column board. Whenever a card'scolumnchanges it travels to its new place on a FLIP transform, so the agent's progress reads as movement. Cards also move by hand with their buttons or the left and right arrow keys.AiPlanRouteis a winding route with a node per milestone. The agent's face walks the path asdonerises, the stretch behind it draws in, and a card names the current stop.AiPlanDraftis the plan before the run. Drag a row by its handle (it lifts while the others slide) or move it with the up and down arrow keys, add and remove steps, and watch the total follow. Start locks the rows and turns the footer into a progress line.
Props
AiPlanBoard
| Prop | Type | Default | Description |
|---|---|---|---|
cards | { id, title, column, agent?, tone?, shape?, estimate? }[] | column is todo, doing or done. | |
onMove | (id: string, column) => void | Called from a card's buttons or arrow keys. | |
labels | [string, string, string] | ["To do", "Doing", "Done"] | Column headings. |
AiPlanRoute
| Prop | Type | Default | Description |
|---|---|---|---|
milestones | { id, title, note?, short? }[] | The stops, in order. | |
done | number | How many are finished. The face stands at the next. | |
onSelect | (index: number) => void | Called from a node or the arrow buttons. | |
tone | tone or CSS colour | "blue" | Face colour. |
shape | face shape | "blob" | Face shape. |
AiPlanDraft
| Prop | Type | Default | Description |
|---|---|---|---|
steps | { id, title, minutes? }[] | The plan, in order. | |
onReorder | (ids: string[]) => void | Called with the new order after a drag or key move. | |
onAdd | (title: string) => void | Called on Enter in the add row. Omit to hide the row. | |
onRemove | (id: string) => void | Called from a row's remove button. | |
onStart | () => void | Called from Start. | |
status | "draft" | "running" | "draft" | Running locks the rows and shows progress. |
runningIndex | number | 0 | The step in progress while running. |
addValue | string | Controls the add row's text. | |
onAddValueChange | (value: string) => void | Called as the add row changes. | |
lift | { id: string; to: number } | Holds a row lifted over a slot, for scripted demos. | |
title | string | "Plan" | The heading. |