# Handoff flow

Work moving between agents and tools: a handoff runs along the wire between two cards and lands as light that crosses the receiver, changing it as it passes. Cells or Aurora, in Color, Single or Grey.

Tier: pro. Type: component. Category: ai. Tags: agent, run, trace, motion.

## Install

```bash
npx shadcn@latest add @pixilui-pro/handoff-flow
```

One-time setup: add the registry to `components.json`:

```json
{
  "registries": {
    "@pixilui": "https://pixilui.com/r/{name}.json",
    "@pixilui-pro": {
      "url": "https://pixilui.com/r/pro/{name}.json",
      "headers": { "Authorization": "Bearer ${PIXILUI_TOKEN}" }
    }
  }
}
```

Pro items need a license. Create a token on https://pixilui.com/account and set `PIXILUI_TOKEN` in `.env.local`; the CLI sends it as a bearer header.

Files: `components/pixilui/handoff-flow.tsx`.

## Preview

Live preview: https://pixilui.com/components/handoff-flow

Knobs:

- `look`: `aurora`, `cells`
- `tone`: `color`, `single`, `grey`

Signature: A comet leaves the planner's port slowly, lands with a slight overshoot, and the soft glim crosses the coder's card, turning it to Running as it passes.

Styles: `lively` (default), `quiet`, set with `data-style` on <html>. The item reads the style through the foundation; it needs no prop.

## Code

Pro source is available to license holders.

## Usage

When to use:

- An agent team at work: the lead hands off to a researcher and a writer, and each card changes as the work lands on it.
- A run graph, a stream of requests into models, or a trace of steps that draws on as each one finishes.
- Any place the motion should say where work went: the cards stay yours, the flow is the layer under them.

When not to use:

- One element's own moment (a send, a success, a failure): use Aurora light.
- A list of steps with no movement between parts: use the run timeline or the reasoning trail.
- Decoration: every handoff stands for work that moved.

```tsx
import { useRef } from "react";
import { AgentAvatar, type AgentAvatarColor, type AgentAvatarShape, type AgentAvatarState } from "@/components/pixilui/agent-avatar";
import { AgentStatus, type AgentStatusState } from "@/components/pixilui/agent-status";
import { HandoffFlow, HandoffFlowNode, useHandoffFlowSimulation, type HandoffFlowHandle } from "@/components/pixilui/handoff-flow";

// The first option of each knob is the demo's default; the docs preview starts there.
export const knobs = {
  look: ["aurora", "cells"],
  tone: ["color", "single", "grey"],
} as const;

const AVATAR: Record<string, AgentAvatarState> = { queued: "idle", running: "writing", done: "done" };

function Card({ node, name, role, color, shape, status, words }: { node: string; name: string; role: string; color: AgentAvatarColor; shape: AgentAvatarShape; status: AgentStatusState; words: string }) {
  return (
    <HandoffFlowNode node={node} className="grid gap-3 rounded-control bg-surface-muted p-3.5">
      <div className="flex min-w-0 items-center gap-2.5">
        <AgentAvatar family="pixel" shape={shape} color={color} state={AVATAR[status] ?? "idle"} size={32} name={name} />
        <div className="grid min-w-0">
          <b className="truncate type-label font-medium text-foreground">{name}</b>
          <span className="truncate type-caption text-muted">{role}</span>
        </div>
      </div>
      <div className="flex min-h-6 items-center justify-between gap-2.5">
        <span data-flow-words className="truncate type-caption text-secondary">{words}</span>
        <span data-flow-status>
          <AgentStatus state={status} size="sm" />
        </span>
      </div>
    </HandoffFlowNode>
  );
}

/** The reference page's relay piece: a planner hands a task to a coder along the wire, and the coder takes it as the light crosses its card. */
export default function HandoffFlowDemo({ look = "aurora", tone = "color" }: KnobValues<typeof knobs>) {
  const flow = useRef<HandoffFlowHandle>(null);
  const nodes = useHandoffFlowSimulation(flow);
  const coder = nodes.coder ?? { status: "queued", words: "Waiting for work" };
  return (
    <div className="w-full max-w-xl rounded-panel bg-surface p-8 elevation-raised">
      <HandoffFlow ref={flow} look={look} tone={tone} wires={[{ id: "handoff", from: "planner", to: "coder", fam: "code" }]} className="grid min-h-48 grid-cols-[minmax(0,13.5rem)_minmax(0,13.5rem)] items-center justify-between gap-12 max-sm:grid-cols-1 max-sm:ps-7">
        <Card node="planner" name="Planner" role="Hands off" color="violet" shape="cloud" status="running" words="Planning" />
        <Card node="coder" name="Coder" role="Takes the task" color="cyan" shape="block" status={coder.status as AgentStatusState} words={coder.words} />
      </HandoffFlow>
    </div>
  );
}
```

## Examples

None.

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `wires` | `HandoffFlowWire[]` | `[]` | The wires between nodes. |
| `look` | `RelayLook` | `"cells"` | Cells (the activity mark's cells, a dithered wave) or Aurora (grey wires with one burst of color, a soft glim). |
| `tone` | `RelayTone` | `"color"` | Color, Single (one hue per meaning) or Grey (silver light; failures stay red). |
| `strength` | `RelayStrength` | `"soft"` | Aurora's strength: soft (the flow) or full (Aurora light). |
| `paused` | `boolean` |  | Pauses the shared clock (every flow and Aurora light on the page). |
| `speed` | `number` |  | Runs the shared clock slower or faster (0.25 is the reference page's Slow). |
| `children` | `React.ReactNode` |  | The nodes (HandoffFlowNode) and anything else on the stage. |

Also accepts every native `<div>` attribute, and a ref to it.

## Keyboard

- `Tab`: Moves through the cards' own controls; the light takes no focus and no pointer.

## Accessibility

- Every canvas is aria-hidden and takes no pointer events: a screen reader hears each card's own words and status, never the light.
- Changes the light carries are real DOM changes on the cards (the status, the words), fired as the light passes them.
- Reduced motion (the OS setting, or data-reduced on <html>) removes every moving light: handoffs set the wire's level at once and arrivals run their changes at once.

## Motion

- A handoff runs 380ms plus the wire's length at 760px a second, on cubic-bezier(.36, 0, .27, 1.17): it leaves slowly and lands with a slight overshoot, squeezing into the port.
- Cells: a dithered wave in the receiver's family crosses the card in 1050ms. Aurora soft: a blurred glim with a curved front crosses in 1250ms and fades as it goes.
- Words change with the locked blur swap; a working card keeps a faint held tint (Aurora). One shared clock runs every flow, so paused and speed hold them together.

## Responsive

- The stage is yours: lay the nodes out with grid or flex; wires follow every layout change, read each frame.

## Performance

- One canvas per stage and one per arrival, one shared requestAnimationFrame clock that rests when nothing moves; no canvas filters per frame, soft light in 1x buffers.

## Notes for AI

- <HandoffFlow ref={flow} look="aurora" wires={[{ id: "t1", from: "lead", to: "coder", fam: "code" }]}> with <HandoffFlowNode node="lead"> cards inside; then await flow.current.send("t1") and flow.current.land("coder", { fam: "code", swaps }).
- Swaps fire as the light reaches an element: { el: "[data-flow-status]", run } (a selector inside the node, or an element). Put your state changes in run so the card changes under the light.
- Families: think, find, make, code, wait, done, fail, holo, idle. Grey tone keeps fail red. Single uses the activity mark's own tones.
- hold(node, true) keeps the soft held light on a working card in Aurora; set(wire, { level }) greys a wire again; breathe(wire, true) runs a swell while its receiver works; drawOn(wire) draws a trace.
- handoffFlowRoute is the reference page's route (ports at each card's vertical middle); pass route on a wire for your own.
- useHandoffFlowSimulation(ref) plays the planner to coder handoff and returns each node's status and words for your cards.
- The engine is aurora-light's relay (relayArrive, relayLayer, relayClock); Toast and Aurora light share its clock.

## Related

- [Aurora light](https://pixilui.com/components/aurora-light/markdown): Soft light for an element's moment, in our glass colors: the glim crosses a card when work arrives, the rim blooms out of what you pressed and holds while the agent works, the ring pops for a moment that matters.
- [Agent status](https://pixilui.com/components/agent-status/markdown): A run's live state in a pill, queued, running, waiting on you, done, failed or stopped, that fills as it goes and closes into its result.
- [Agent avatar](https://pixilui.com/components/agent-avatar/markdown): The agent's face in four looks, 3D plush, glass orb, flat shape or pixel, in any color, acting out its work: it searches with a magnifier, reads, scribbles, asks and hops when it's done.
