Agent Lanes
A live timeline with one lane per agent: tasks grow towards a now line, hand-offs are drawn between lanes and approvals sit right on the block that needs them.
"use client"
import * as React from "react"
import { Check, Sparkles, TriangleAlert } from "lucide-react"
import {
AiKitStyles,
AiStyle,
BrandIcon,
BrandStack,
cx,
Face,
Roll,
type AiMood,
type AiShape,
type AiStatus,
type AiTone,
} from "@/lib/ai-kit"
export interface LaneAgent {
id: string
name: string
model: string
/** Brand mark beside the model. */
vendor?: string
tone: AiTone
shape?: AiShape
}
export interface LaneTask {
id: string
agent: string
title: string
/** Minutes on the run's clock. `end` left out means it is still running. */
start: number
end?: number
tools?: readonly string[]
status: AiStatus
}
export interface LaneHandoff {
from: string
to: string
}
export interface AgentLanesProps {
agents: readonly LaneAgent[]
tasks: readonly LaneTask[]
handoffs?: readonly LaneHandoff[]
/** The run's clock, in minutes. The view ends here. */
now: number
/** How many minutes the view shows. */
span?: number
onApprove?: (taskId: string) => void
className?: string
}
const CSS = `
.aik-ln{--lw:220px;--lh:76px;width:min(100%,1060px);container-type:inline-size}
.aik-ln-card{--aik-r-shell:24px;--aik-rim:5px}
.aik-ln-in{padding:0 0 6px}
.aik-ln-head{display:flex;align-items:center;gap:14px;padding:18px 22px 16px;font-size:15px;border-bottom:1px solid var(--aik-line)}
.aik-ln-head b{font-weight:600;font-size:16px}
.aik-ln-head svg{color:var(--aik-blue)}
.aik-ln-count{display:inline-flex;align-items:center;gap:7px;color:var(--aik-text-2);font-variant-numeric:tabular-nums}
.aik-ln-count i{width:7px;height:7px;border-radius:50%;background:var(--aik-blue)}
.aik-ln-count[data-k="ask"]{color:var(--aik-amber)}.aik-ln-count[data-k="ask"] i{background:var(--aik-amber)}
.aik-ln-range{margin-left:auto;height:30px;display:inline-flex;align-items:center;padding:0 11px;border-radius:9px;background:var(--aik-raised);font-size:13.5px;color:var(--aik-text-2)}
.aik-ln-grid{display:grid;grid-template-columns:var(--lw) minmax(0,1fr);padding:0 22px 0 18px}
.aik-ln-axis{position:relative;height:40px;grid-column:2}
.aik-ln-tick{position:absolute;top:13px;translate:-50% 0;font:12.5px var(--aik-mono);color:var(--aik-text-3);white-space:nowrap;font-variant-numeric:tabular-nums}
.aik-ln-now{position:absolute;right:0;top:9px;height:22px;padding:0 7px;display:inline-flex;align-items:center;border-radius:6px;font:500 12.5px var(--aik-sans);color:var(--aik-blue);background:color-mix(in oklab,var(--aik-blue) 16%,transparent)}
.aik-ln-who{display:flex;align-items:center;gap:12px;height:var(--lh);min-width:0}
.aik-ln-who > span:last-child{display:grid;min-width:0;line-height:19px}
.aik-ln-who b{display:flex;align-items:center;gap:7px;font-weight:600;font-size:15px;white-space:nowrap}
.aik-ln-who small{display:flex;align-items:center;gap:5px;font-size:13px;color:var(--aik-text-3);white-space:nowrap}
.aik-ln-tag{height:21px;padding:0 7px;display:inline-flex;align-items:center;border-radius:6px;font:500 12px var(--aik-sans);background:var(--aik-raised);color:var(--aik-text-3)}
.aik-ln-tag[data-k="ask"]{background:color-mix(in oklab,var(--aik-amber) 16%,transparent);color:var(--aik-amber)}
.aik-ln-tile{display:grid;place-items:center;width:42px;height:42px;flex:none;border-radius:13px;background:color-mix(in oklab,var(--c) 12%,var(--aik-card));box-shadow:inset 0 0 0 1px color-mix(in oklab,var(--c) 24%,transparent)}
.aik-ln-track{position:relative;height:var(--lh);border-top:1px solid var(--aik-line);overflow:hidden}
.aik-ln-track:first-of-type{border-top:0}
.aik-ln-body{position:relative}
.aik-ln-body{-webkit-mask:linear-gradient(90deg,transparent,#000 28px);mask:linear-gradient(90deg,transparent,#000 28px)}
.aik-ln-gl{position:absolute;top:0;bottom:0;width:1px;background:var(--aik-line);pointer-events:none}
.aik-ln-slide{position:absolute;inset:0;transition:transform var(--aik-ln-tick,600ms) linear;will-change:transform}
.aik-ln-slide[data-jump]{transition:none}
.aik-ln-epoch{position:absolute;inset:0;animation:aik-ln-fade 420ms var(--aik-ease-out) both}
@keyframes aik-ln-fade{from{opacity:0}}
.aik-ln-move{transition:transform var(--aik-ln-tick,600ms) linear}
.aik-ln-slide[data-jump] .aik-ln-move{transition:none}
.aik-ln-wrap{position:absolute;inset:0;pointer-events:none}
.aik-ln-label{position:absolute;inset:0;display:flex;align-items:center;gap:9px;padding:0 10px 0 9px;min-width:0;pointer-events:none}
.aik-ln-label > span{overflow:hidden;text-overflow:ellipsis;min-width:0}
.aik-ln-block[data-s="ask"] .aik-ln-label{padding-right:132px}
.aik-ln-end{position:absolute;inset:0;display:flex;align-items:center;justify-content:flex-end;padding-right:8px;pointer-events:none}
.aik-ln-end > *{pointer-events:auto}
.aik-ln-endbar{position:absolute;right:0;top:0;bottom:0;width:3px;border-radius:2px;background:var(--c);box-shadow:0 0 12px var(--c);animation:aik-ln-edge 1.2s ease-in-out infinite}
.aik-ln-block .aik-brand-stack{flex:none}
.aik-ln-svg{position:absolute;inset:0;width:100%;height:100%;overflow:visible;pointer-events:none}
.aik-ln-svg path{fill:none;stroke:var(--aik-text-3);stroke-width:1.5;stroke-dasharray:3 4;vector-effect:non-scaling-stroke;opacity:.9}
.aik-ln-svg path[data-live]{stroke:var(--aik-blue);stroke-dasharray:4 4;animation:aik-ln-march .6s linear infinite}
@keyframes aik-ln-march{to{stroke-dashoffset:-16}}
.aik-ln-block{position:absolute;top:13px;bottom:13px;border-radius:11px;min-width:30px;overflow:hidden;white-space:nowrap;font-size:14.5px;font-weight:500;
color:var(--aik-text-2);background:var(--aik-raised);box-shadow:inset 0 0 0 1px var(--aik-line);transition:background var(--aik-d-panel),color var(--aik-d-panel),box-shadow var(--aik-d-panel);animation:aik-ln-in 480ms var(--aik-ease-soft) both}
.aik-ln-block[data-s="run"]{color:color-mix(in oklab,var(--c) 70%,var(--aik-text));background:linear-gradient(90deg,color-mix(in oklab,var(--c) 10%,var(--aik-card)),color-mix(in oklab,var(--c) 24%,var(--aik-card)));box-shadow:inset 0 0 0 1px color-mix(in oklab,var(--c) 36%,transparent)}
.aik-ln-block[data-s="run"]::before{content:"";position:absolute;inset:0;background:linear-gradient(90deg,transparent,color-mix(in oklab,var(--c) 22%,transparent),transparent);translate:-100% 0;animation:aik-ln-sheen 2.4s var(--aik-ease-move) infinite}
.aik-ln-block[data-s="ask"]{color:var(--aik-amber);background:color-mix(in oklab,var(--aik-amber) 13%,var(--aik-card));box-shadow:inset 0 0 0 1px color-mix(in oklab,var(--aik-amber) 34%,transparent)}
.aik-ln-block[data-s="fail"]{color:var(--aik-red);background:color-mix(in oklab,var(--aik-red) 14%,var(--aik-card));box-shadow:inset 0 0 0 1px color-mix(in oklab,var(--aik-red) 30%,transparent)}
.aik-ln-block[data-s="done"]{color:var(--aik-text-2)}
.aik-ln-ask{display:inline-flex;align-items:center;gap:6px;height:28px;padding:0 10px;border-radius:8px;font-size:13px;font-weight:600;color:var(--aik-amber);background:var(--aik-card);box-shadow:inset 0 0 0 1px color-mix(in oklab,var(--aik-amber) 40%,transparent);transition:background var(--aik-d-state),transform var(--aik-d-press)}
.aik-ln-ask:hover{background:color-mix(in oklab,var(--aik-amber) 14%,var(--aik-card))}
.aik-ln-ask:active{transform:scale(.95)}
.aik-ln-ask .aik-ln-ok{display:none}
.aik-ln-ask:hover .aik-ln-ok,.aik-ln-ask:focus-visible .aik-ln-ok{display:inline}
.aik-ln-ask:hover .aik-ln-wait,.aik-ln-ask:focus-visible .aik-ln-wait{display:none}
.aik-ln-line{position:absolute;top:0;bottom:0;right:0;width:1.5px;background:var(--aik-blue);opacity:.8}
@keyframes aik-ln-in{from{opacity:0;clip-path:inset(0 100% 0 0 round 11px)}}
@keyframes aik-ln-edge{50%{opacity:.45}}
@keyframes aik-ln-sheen{60%,100%{translate:100% 0}}
@container (max-width:640px){
.aik-ln{--lw:58px;--lh:68px}
.aik-ln-who > span:last-child{display:none}
.aik-ln-head{flex-wrap:wrap;gap:8px 12px;padding:16px}
.aik-ln-range{display:none}
.aik-ln-grid{padding:0 12px 0 10px}
.aik-ln-block{font-size:13.5px}
.aik-ln-tick:nth-child(even),.aik-ln-tick[data-near]{display:none}
}
@media (prefers-reduced-motion:reduce){.aik-ln-block,.aik-ln-block::before,.aik-ln-endbar,.aik-ln-svg path,.aik-ln-epoch{animation:none}.aik-ln-slide,.aik-ln-move{transition:none}}
`
const MOOD: Record<AiStatus, AiMood> = {
todo: "sleep",
run: "work",
ask: "needs",
done: "happy",
fail: "oops",
}
/**
* Where every agent is right now: one lane per agent on a live clock, tasks
* growing into the now line, dashed hand-offs between lanes and approvals on
* the block that needs them. Hover Needs you to approve in place.
*/
export function AgentLanes({
agents,
tasks,
handoffs = [],
now,
span = 30,
onApprove,
className,
}: AgentLanesProps) {
const from = now - span
// Fixed ticks relative to now (−25m … −5m): their labels never change and
// never slide under the "now" chip. Only the work moves.
const ticks: number[] = []
for (let rel = Math.floor((span - 1) / 5) * 5; rel >= 5; rel -= 5)
ticks.push(rel)
const tickX = (rel: number) => ((span - rel) / span) * 100
// Blocks sit on a layer in fixed clock coordinates measured from an origin,
// and the layer slides left with a transform as the clock runs. Nothing
// animates width or left. When the clock goes back (a demo restart) the
// origin resets without a transition and the layer fades in.
const origin = React.useRef<number | null>(null)
const last = React.useRef(now)
const [epoch, setEpoch] = React.useState(0)
const jumped = now < last.current
if (origin.current === null || jumped) origin.current = from
React.useEffect(() => {
if (now < last.current) setEpoch((e) => e + 1)
last.current = now
}, [now])
const O = origin.current
const ax = (t: number) => ((t - O) / span) * 100
const shift = ((from - O) / span) * 100
const laneOf = new Map(agents.map((agent, i) => [agent.id, i]))
const byId = new Map(tasks.map((task) => [task.id, task]))
const running = tasks.filter((t) => t.status === "run").length
const asking = tasks.filter((t) => t.status === "ask").length
const stateOf = (agentId: string): AiStatus => {
const mine = tasks.filter((t) => t.agent === agentId)
if (mine.some((t) => t.status === "ask")) return "ask"
if (mine.some((t) => t.status === "run")) return "run"
return mine.length ? "done" : "todo"
}
return (
<div className={cx("aik aik-ln", className)}>
<AiKitStyles />
<AiStyle id="agent-lanes" css={CSS} />
<div className="aik-shell aik-ln-card">
<div className="aik-surface aik-ln-in">
<div className="aik-ln-head">
<Sparkles size={18} aria-hidden="true" />
<b>Agents</b>
<span className="aik-ln-count">
<i />
<Roll>{`${running} running`}</Roll>
</span>
{asking ? (
<span className="aik-ln-count" data-k="ask">
<i />
<Roll>{`${asking} needs you`}</Roll>
</span>
) : null}
<span className="aik-ln-range">Last {span}m</span>
</div>
<div className="aik-ln-grid">
<div />
<div className="aik-ln-axis" aria-hidden="true">
{ticks.map((rel) => (
<span
key={rel}
className="aik-ln-tick"
data-near={rel <= 5 ? "" : undefined}
style={{ left: `${tickX(rel)}%` }}
>
−{rel}m
</span>
))}
<span className="aik-ln-now">now</span>
</div>
<div>
{agents.map((agent) => {
const state = stateOf(agent.id)
return (
<div
key={agent.id}
className="aik-ln-who"
style={
{
"--c": `var(--aik-f-${agent.tone})`,
} as React.CSSProperties
}
>
<span className="aik-ln-tile">
<Face
mood={MOOD[state]}
shape={agent.shape ?? "squircle"}
tone={agent.tone}
size={28}
/>
</span>
<span>
<b>
{agent.name}
{state === "ask" ? (
<span className="aik-ln-tag" data-k="ask">
Needs you
</span>
) : state === "done" || state === "todo" ? (
<span className="aik-ln-tag">Idle</span>
) : null}
</b>
<small>
{agent.vendor ? (
<BrandIcon
name={agent.vendor}
tint="brand"
size={12}
/>
) : null}
{agent.model}
</small>
</span>
</div>
)
})}
</div>
<div className="aik-ln-body">
{ticks.map((rel) => (
<i
key={rel}
className="aik-ln-gl"
style={{ left: `${tickX(rel)}%` }}
aria-hidden="true"
/>
))}
<div
className="aik-ln-slide"
data-jump={jumped ? "" : undefined}
style={{ transform: `translateX(${-shift}%)` }}
>
<svg
className="aik-ln-svg"
viewBox={`0 0 100 ${agents.length * 76}`}
preserveAspectRatio="none"
aria-hidden="true"
>
{handoffs.map((h) => {
const a = byId.get(h.from)
const b = byId.get(h.to)
if (!a || !b) return null
const x1 = ax(a.end ?? now)
const x2 = ax(b.start)
const y1 = (laneOf.get(a.agent) ?? 0) * 76 + 38
const y2 = (laneOf.get(b.agent) ?? 0) * 76 + 38
const mx = (x1 + x2) / 2
return (
<path
key={h.from + h.to}
data-live={b.status === "run" ? "" : undefined}
d={`M${x1} ${y1}C${mx} ${y1} ${mx} ${y2} ${x2} ${y2}`}
/>
)
})}
</svg>
</div>
{agents.map((agent) => (
<div key={agent.id} className="aik-ln-track">
<div
className="aik-ln-slide"
data-jump={jumped ? "" : undefined}
style={{ transform: `translateX(${-shift}%)` }}
>
<div key={epoch} className="aik-ln-epoch">
{tasks
.filter((task) => task.agent === agent.id)
.map((task) => {
const live = task.end === undefined
if (!live && (task.end ?? 0) < from - 1) return null
// A live block runs two spans long and the track
// clips it at the now edge, so it "grows" for free as
// the layer slides. Its label stays readable at the
// left edge and its end cap rides the now line, both
// moved with transforms.
const length = live
? span * 2
: (task.end ?? now) - task.start
const lead = Math.max(0, from - task.start) / length
const seen = Math.min(1, (now - task.start) / length)
return (
<div
key={task.id}
className="aik-ln-block"
data-s={task.status}
style={
{
left: `${ax(task.start)}%`,
width: `calc(${(length / span) * 100}% - ${live ? 0 : 4}px)`,
"--c": `var(--aik-f-${agent.tone})`,
} as React.CSSProperties
}
>
<div
className="aik-ln-wrap aik-ln-move"
style={{
transform: `translateX(${lead * 100}%)`,
}}
>
<div
className="aik-ln-label"
style={{
// Only the part of the block in view: from
// the left edge (lead) to now or its end.
right: "auto",
width: `${Math.max(0, (live ? seen : 1) - lead) * 100}%`,
}}
>
{task.status === "fail" ? (
<TriangleAlert
size={15}
aria-hidden="true"
/>
) : task.tools?.length ? (
<BrandStack names={task.tools} size={20} />
) : null}
<span>{task.title}</span>
</div>
</div>
{live ? (
<div
className="aik-ln-end aik-ln-move"
style={{
transform: `translateX(${(seen - 1) * 100}%)`,
}}
>
{task.status === "ask" ? (
<button
type="button"
className="aik-ln-ask"
onClick={() => onApprove?.(task.id)}
aria-label={`Approve ${task.title}`}
>
<span className="aik-ln-wait">
<TriangleAlert
size={13}
aria-hidden="true"
/>{" "}
Needs you
</span>
<span className="aik-ln-ok">
<Check size={14} aria-hidden="true" />{" "}
Approve
</span>
</button>
) : null}
{task.status === "run" ? (
<i
className="aik-ln-endbar"
aria-hidden="true"
/>
) : null}
</div>
) : null}
</div>
)
})}
</div>
</div>
<span className="aik-ln-line" aria-hidden="true" />
</div>
))}
</div>
</div>
</div>
</div>
</div>
)
}
Installation
One command adds agent-lanes 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-lanes.json