# Agent Screen

A live view of the screen an agent is working on, with its cursor.

Watch an agent work: a framed capture of its screen with the agent's cursor and a recording badge. Pass the capture as `src`; without one the frame draws a neutral placeholder window from tokens. The cursor glides to each new position on a transform (it jumps under reduced motion), the frame carries a text alternative, and every change of state is announced through a role=status region.

Kind: block · Category: Agent · Status: beta · Targets: React, Vue, Svelte

## Add

```bash
npx fndn add agent-screen
```

It writes the folder `agent-screen/` into the project's ui folder (`index.ts`, `agent-screen.tsx`, `AgentScreen.vue`, `AgentScreen.svelte`, `agent-screen.recipe.ts`), and what it is built from: [Spinner](/components/spinner.md), [Button](/components/button.md), [Tooltip](/components/tooltip.md), [Dialog](/components/dialog.md). First time: [Installation](/installation.md).

## Usage

```tsx
import { AgentScreen } from "@/components/ui/agent-screen";
```

```vue
import { AgentScreen } from "@/components/ui/agent-screen";
```

```svelte
import { AgentScreen } from "$lib/components/ui/agent-screen";
```

## Parts

In the DOM the root carries `data-slot="agent-screen"` and each part `data-slot="agent-screen-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `figure` | `agent-screen` |  | data-state=loading\|live\|idle, data-recording |
| `frame` | `div` | `agent-screen-frame` |  | role=img with the text alternative (alt, else the label); 16:10, clips its layers |
| `media` | `img` | `agent-screen-media` | optional | The capture (src), covering the frame; alt is empty, the frame names it |
| `placeholder` | `span` | `agent-screen-placeholder` | optional | Neutral window drawn from tokens when there is no src |
| `chrome` | `span` | `agent-screen-chrome` |  | Placeholder title bar |
| `page` | `span` | `agent-screen-page` |  | Placeholder content |
| `line` | `span` | `agent-screen-line` | repeats |  |
| `cursor` | `span` | `agent-screen-cursor` |  | Layer as large as the frame, translated by --fndn-agent-screen-cursor ("x%, y%"); holds the pointer icon at its top-left |
| `loading` | `span` | `agent-screen-loading` |  | Spinner and text, shown while data-state=loading |
| `loading-text` | `span` | `agent-screen-loading-text` |  |  |
| `rec` | `span` | `agent-screen-rec` |  | Recording badge, shown with data-recording |
| `rec-dot` | `span` | `agent-screen-rec-dot` |  | Pulsing dot (opacity loop) |
| `label` | `figcaption` | `agent-screen-label` |  | Visible caption; truncates, full text in title |
| `status` | `span` | `agent-screen-status` |  | role=status, sr-only: "<label>: Live, Recording" |
| `expand` | `button` | `agent-screen-expand` | optional | expandable: a Button (outline, xs, square, rounded) on the frame's bottom end corner, with our tooltip (labels.expand) and aria-haspopup=dialog; opens the viewer Marked data-agent-screen="expand". |
| `viewer` | `div` | `agent-screen-viewer` | optional | expandable: the body of our dialog (size lg, title = the label): the same frame, larger, with the root's data-state and data-recording. |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `state` | `"loading" \| "live" \| "idle"` | `"live"` | loading: connecting (spinner). live: the agent works; its cursor shows. idle: the screen stays, the cursor hides. |
| `cursor` | `object` |  | { x, y } in percent of the screen, clamped to 0–100. Set on the cursor layer as "x%, y%". Defaults to { x: 42, y: 53 }. |
| `recording` | `boolean` | `false` | Shows the REC badge and adds "Recording" to the status. |
| `label` | `string` | `"Agent's screen"` | Caption under the frame; also starts the status text. |
| `alt` | `string` |  | Text alternative of the frame. Defaults to the label; describe the capture when you pass src. |
| `src` | `string` |  | Image URL of the agent's screen. Without it the placeholder is drawn. |
| `labels` | `object` |  | Status words, badge and button: loading, live, idle, recording, rec, expand. |
| `expandable` | `boolean` | `false` | Adds a button with a tooltip on the frame's corner that opens the screen larger in our dialog. |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## States

`loading`, `live`, `idle`, `recording`

## Keyboard and accessibility

Role: figure with an img frame and a status region.

Keyboard:

- The screen itself takes no focus
- expandable: Tab reaches the expand button; Enter / Space open the viewer dialog (focus moves into it); Escape or the close button close it and focus returns to the button

Notes:

- The frame is role=img with an accessible name; pass alt to describe a real capture.
- Changes of state and recording are announced through role=status; the cursor's moves are not announced.
- expandable: the button is named (labels.expand) and shows our tooltip; the viewer is our dialog, named by the label, with its focus trap, Escape and focus return.

## Motion

- cursor: transform over duration.slow with easing.in-out-strong (on-screen travel); under reduced motion it jumps, the show/hide fade stays
- cursor show/hide and connecting overlay: opacity over duration.base
- REC badge: opacity + scale from motion.popup-scale out of its top right corner (where it is pinned) over duration.popup with easing.out-strong; leaves over duration.fast
- REC dot: opacity loop (1.1s), kept under reduced motion
- viewer: our dialog's motion (scale from motion.popup-scale and the scrim fade); the cursor glides in the viewer too

## Tokens

`color.inset`, `color.surface`, `color.line`, `color.line-strong`, `color.field`, `color.red`, `color.orange`, `color.green`, `color.accent-tint`, `color.ink`, `color.ink-2`, `color.ink-3`, `color.on-accent`, `shadow.card`, `radius.window`, `radius.pill`, `text.2xs`, `text.xs`, `text.sm`, `duration.fast`, `duration.base`, `duration.popup`, `duration.slow`, `easing.in-out-strong`, `easing.out-strong`, `motion.popup-scale`

## Dependencies

- [Spinner](/components/spinner.md)
- [Button](/components/button.md)
- [Tooltip](/components/tooltip.md)
- [Dialog](/components/dialog.md)

## Examples

### Watch the agent issue a refund

React · `live.tsx`

```tsx
import { useEffect, useState, type ComponentProps } from "react";
import { AgentScreen } from "@/components/ui/agent-screen";

type Props = ComponentProps<typeof AgentScreen>;

const initial: Props = {
  label: "Issuing the Kestrel Logistics refund",
  cursor: { x: 42, y: 53 },
};

/* each step waits `after` ms, then merges its props over the current ones */
const timeline: { after: number; props: Partial<Props> }[] = [
  { after: 900, props: { cursor: { x: 72, y: 30 } } },
  { after: 1100, props: { cursor: { x: 26, y: 68 } } },
  { after: 1100, props: { cursor: { x: 58, y: 44 } } },
  { after: 800, props: { recording: true } },
];

export default function Live() {
  const [props, setProps] = useState(initial);
  useEffect(() => {
    let i = 0, timer = 0;
    const next = () => {
      const step = timeline[i++];
      if (step) timer = window.setTimeout(() => { setProps((p) => ({ ...p, ...step.props })); next(); }, step.after);
    };
    next();
    return () => clearTimeout(timer);
  }, []);
  return <AgentScreen {...props} />;
}
```

Vue · `live.vue`

```vue
<script setup lang="ts">
import { onBeforeUnmount, onMounted, shallowRef } from "vue";
import { AgentScreen } from "@/components/ui/agent-screen";

const initial = {
  label: "Issuing the Kestrel Logistics refund",
  cursor: { x: 42, y: 53 },
};

/* each step waits `after` ms, then merges its props over the current ones */
const timeline: { after: number; props: Record<string, unknown> }[] = [
  { after: 900, props: { cursor: { x: 72, y: 30 } } },
  { after: 1100, props: { cursor: { x: 26, y: 68 } } },
  { after: 1100, props: { cursor: { x: 58, y: 44 } } },
  { after: 800, props: { recording: true } },
];

const props = shallowRef<Record<string, unknown>>({ ...initial });
let timer = 0;
onMounted(() => {
  let i = 0;
  const next = () => {
    const step = timeline[i++];
    if (step) timer = window.setTimeout(() => { props.value = { ...props.value, ...step.props }; next(); }, step.after);
  };
  next();
});
onBeforeUnmount(() => clearTimeout(timer));
</script>

<template>
  <AgentScreen v-bind="props" />
</template>
```

Svelte · `live.svelte`

```svelte
<script lang="ts">
  import { onMount, type ComponentProps } from "svelte";
  import { AgentScreen } from "$lib/components/ui/agent-screen";

  type Props = ComponentProps<typeof AgentScreen>;

  const initial: Props = {
    label: "Issuing the Kestrel Logistics refund",
    cursor: { x: 42, y: 53 },
  };

  /* each step waits `after` ms, then merges its props over the current ones */
  const timeline: { after: number; props: Partial<Props> }[] = [
    { after: 900, props: { cursor: { x: 72, y: 30 } } },
    { after: 1100, props: { cursor: { x: 26, y: 68 } } },
    { after: 1100, props: { cursor: { x: 58, y: 44 } } },
    { after: 800, props: { recording: true } },
  ];

  let props: Props = $state.raw({ ...initial });
  onMount(() => {
    let i = 0, timer = 0;
    const next = () => {
      const step = timeline[i++];
      if (step) timer = window.setTimeout(() => { props = { ...props, ...step.props }; next(); }, step.after);
    };
    next();
    return () => clearTimeout(timer);
  });
</script>

<AgentScreen {...props} />
```

### Recording a bug reproduction

React · `recording.tsx`

```tsx
import { AgentScreen } from "@/components/ui/agent-screen";

export default function Recording() {
  return (
    <AgentScreen
      label="Reproducing HAR-482: double booking in Safari"
      cursor={{ x: 68, y: 30 }}
      recording
    />
  );
}
```

Vue · `recording.vue`

```vue
<script setup lang="ts">
import { AgentScreen } from "@/components/ui/agent-screen";
</script>

<template>
  <AgentScreen
    label="Reproducing HAR-482: double booking in Safari"
    :cursor="{ x: 68, y: 30 }"
    recording
  />
</template>
```

Svelte · `recording.svelte`

```svelte
<script lang="ts">
  import { AgentScreen } from "$lib/components/ui/agent-screen";
</script>

<AgentScreen
  label="Reproducing HAR-482: double booking in Safari"
  cursor={{ x: 68, y: 30 }}
  recording
/>
```

### Connecting to the agent's browser

React · `loading.tsx`

```tsx
import { AgentScreen } from "@/components/ui/agent-screen";

export default function Loading() {
  return <AgentScreen state="loading" label="Opening the Harbor admin" />;
}
```

Vue · `loading.vue`

```vue
<script setup lang="ts">
import { AgentScreen } from "@/components/ui/agent-screen";
</script>

<template>
  <AgentScreen state="loading" label="Opening the Harbor admin" />
</template>
```

Svelte · `loading.svelte`

```svelte
<script lang="ts">
  import { AgentScreen } from "$lib/components/ui/agent-screen";
</script>

<AgentScreen state="loading" label="Opening the Harbor admin" />
```

### Final screenshot after the run

React · `image.tsx`

```tsx
import { AgentScreen } from "@/components/ui/agent-screen";

/* the last capture from the agent's browser session (any image URL) */
const screenshot =
  "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 200'%3E%3Crect width='320' height='200' fill='%23f8fafc'/%3E%3Crect width='320' height='16' fill='%23e2e8f0'/%3E%3Ccircle cx='9' cy='8' r='2.5' fill='%23f87171'/%3E%3Ccircle cx='17' cy='8' r='2.5' fill='%23fbbf24'/%3E%3Ccircle cx='25' cy='8' r='2.5' fill='%234ade80'/%3E%3Crect x='60' y='4' width='200' height='8' rx='4' fill='%23fff'/%3E%3Crect y='16' width='72' height='184' fill='%23f1f5f9'/%3E%3Crect x='10' y='28' width='40' height='6' rx='3' fill='%2364748b'/%3E%3Crect x='10' y='46' width='48' height='5' rx='2.5' fill='%23cbd5e1'/%3E%3Crect x='6' y='58' width='60' height='13' rx='3' fill='%23dbeafe'/%3E%3Crect x='10' y='62' width='40' height='5' rx='2.5' fill='%233b82f6'/%3E%3Crect x='10' y='80' width='44' height='5' rx='2.5' fill='%23cbd5e1'/%3E%3Crect x='10' y='96' width='36' height='5' rx='2.5' fill='%23cbd5e1'/%3E%3Crect x='88' y='28' width='96' height='8' rx='3' fill='%23334155'/%3E%3Crect x='250' y='25' width='54' height='14' rx='4' fill='%233b82f6'/%3E%3Crect x='88' y='46' width='216' height='14' fill='%23f1f5f9'/%3E%3Crect x='88' y='64' width='216' height='19' fill='%23fff'/%3E%3Crect x='96' y='71' width='36' height='5' rx='2' fill='%2394a3b8'/%3E%3Crect x='164' y='71' width='34' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='214' y='71' width='28' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='262' y='69' width='30' height='9' rx='4.5' fill='%2316a34a' fill-opacity='.18'/%3E%3Crect x='267' y='72' width='20' height='3' rx='1.5' fill='%2316a34a'/%3E%3Crect x='88' y='84' width='216' height='19' fill='%23fff'/%3E%3Crect x='96' y='91' width='43' height='5' rx='2' fill='%2394a3b8'/%3E%3Crect x='164' y='91' width='34' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='214' y='91' width='28' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='262' y='89' width='30' height='9' rx='4.5' fill='%2316a34a' fill-opacity='.18'/%3E%3Crect x='267' y='92' width='20' height='3' rx='1.5' fill='%2316a34a'/%3E%3Crect x='88' y='104' width='216' height='19' fill='%23fff'/%3E%3Crect x='96' y='111' width='50' height='5' rx='2' fill='%2394a3b8'/%3E%3Crect x='164' y='111' width='34' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='214' y='111' width='28' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='262' y='109' width='30' height='9' rx='4.5' fill='%23d97706' fill-opacity='.18'/%3E%3Crect x='267' y='112' width='20' height='3' rx='1.5' fill='%23d97706'/%3E%3Crect x='88' y='124' width='216' height='19' fill='%23fff'/%3E%3Crect x='96' y='131' width='57' height='5' rx='2' fill='%2394a3b8'/%3E%3Crect x='164' y='131' width='34' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='214' y='131' width='28' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='262' y='129' width='30' height='9' rx='4.5' fill='%2316a34a' fill-opacity='.18'/%3E%3Crect x='267' y='132' width='20' height='3' rx='1.5' fill='%2316a34a'/%3E%3Crect x='88' y='144' width='216' height='19' fill='%23fff'/%3E%3Crect x='96' y='151' width='42' height='5' rx='2' fill='%2394a3b8'/%3E%3Crect x='164' y='151' width='34' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='214' y='151' width='28' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='262' y='149' width='30' height='9' rx='4.5' fill='%23dc2626' fill-opacity='.18'/%3E%3Crect x='267' y='152' width='20' height='3' rx='1.5' fill='%23dc2626'/%3E%3Crect x='88' y='164' width='216' height='19' fill='%23fff'/%3E%3Crect x='96' y='171' width='49' height='5' rx='2' fill='%2394a3b8'/%3E%3Crect x='164' y='171' width='34' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='214' y='171' width='28' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='262' y='169' width='30' height='9' rx='4.5' fill='%2316a34a' fill-opacity='.18'/%3E%3Crect x='267' y='172' width='20' height='3' rx='1.5' fill='%2316a34a'/%3E%3C/svg%3E";

export default function Image() {
  return (
    <AgentScreen
      state="idle"
      label="Juniper Health bookings, after the run"
      alt="Bookings list for Juniper Health with six rows, one cancelled"
      src={screenshot}
    />
  );
}
```

Vue · `image.vue`

```vue
<script setup lang="ts">
import { AgentScreen } from "@/components/ui/agent-screen";

/* the last capture from the agent's browser session (any image URL) */
const screenshot =
  "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 200'%3E%3Crect width='320' height='200' fill='%23f8fafc'/%3E%3Crect width='320' height='16' fill='%23e2e8f0'/%3E%3Ccircle cx='9' cy='8' r='2.5' fill='%23f87171'/%3E%3Ccircle cx='17' cy='8' r='2.5' fill='%23fbbf24'/%3E%3Ccircle cx='25' cy='8' r='2.5' fill='%234ade80'/%3E%3Crect x='60' y='4' width='200' height='8' rx='4' fill='%23fff'/%3E%3Crect y='16' width='72' height='184' fill='%23f1f5f9'/%3E%3Crect x='10' y='28' width='40' height='6' rx='3' fill='%2364748b'/%3E%3Crect x='10' y='46' width='48' height='5' rx='2.5' fill='%23cbd5e1'/%3E%3Crect x='6' y='58' width='60' height='13' rx='3' fill='%23dbeafe'/%3E%3Crect x='10' y='62' width='40' height='5' rx='2.5' fill='%233b82f6'/%3E%3Crect x='10' y='80' width='44' height='5' rx='2.5' fill='%23cbd5e1'/%3E%3Crect x='10' y='96' width='36' height='5' rx='2.5' fill='%23cbd5e1'/%3E%3Crect x='88' y='28' width='96' height='8' rx='3' fill='%23334155'/%3E%3Crect x='250' y='25' width='54' height='14' rx='4' fill='%233b82f6'/%3E%3Crect x='88' y='46' width='216' height='14' fill='%23f1f5f9'/%3E%3Crect x='88' y='64' width='216' height='19' fill='%23fff'/%3E%3Crect x='96' y='71' width='36' height='5' rx='2' fill='%2394a3b8'/%3E%3Crect x='164' y='71' width='34' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='214' y='71' width='28' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='262' y='69' width='30' height='9' rx='4.5' fill='%2316a34a' fill-opacity='.18'/%3E%3Crect x='267' y='72' width='20' height='3' rx='1.5' fill='%2316a34a'/%3E%3Crect x='88' y='84' width='216' height='19' fill='%23fff'/%3E%3Crect x='96' y='91' width='43' height='5' rx='2' fill='%2394a3b8'/%3E%3Crect x='164' y='91' width='34' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='214' y='91' width='28' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='262' y='89' width='30' height='9' rx='4.5' fill='%2316a34a' fill-opacity='.18'/%3E%3Crect x='267' y='92' width='20' height='3' rx='1.5' fill='%2316a34a'/%3E%3Crect x='88' y='104' width='216' height='19' fill='%23fff'/%3E%3Crect x='96' y='111' width='50' height='5' rx='2' fill='%2394a3b8'/%3E%3Crect x='164' y='111' width='34' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='214' y='111' width='28' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='262' y='109' width='30' height='9' rx='4.5' fill='%23d97706' fill-opacity='.18'/%3E%3Crect x='267' y='112' width='20' height='3' rx='1.5' fill='%23d97706'/%3E%3Crect x='88' y='124' width='216' height='19' fill='%23fff'/%3E%3Crect x='96' y='131' width='57' height='5' rx='2' fill='%2394a3b8'/%3E%3Crect x='164' y='131' width='34' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='214' y='131' width='28' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='262' y='129' width='30' height='9' rx='4.5' fill='%2316a34a' fill-opacity='.18'/%3E%3Crect x='267' y='132' width='20' height='3' rx='1.5' fill='%2316a34a'/%3E%3Crect x='88' y='144' width='216' height='19' fill='%23fff'/%3E%3Crect x='96' y='151' width='42' height='5' rx='2' fill='%2394a3b8'/%3E%3Crect x='164' y='151' width='34' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='214' y='151' width='28' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='262' y='149' width='30' height='9' rx='4.5' fill='%23dc2626' fill-opacity='.18'/%3E%3Crect x='267' y='152' width='20' height='3' rx='1.5' fill='%23dc2626'/%3E%3Crect x='88' y='164' width='216' height='19' fill='%23fff'/%3E%3Crect x='96' y='171' width='49' height='5' rx='2' fill='%2394a3b8'/%3E%3Crect x='164' y='171' width='34' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='214' y='171' width='28' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='262' y='169' width='30' height='9' rx='4.5' fill='%2316a34a' fill-opacity='.18'/%3E%3Crect x='267' y='172' width='20' height='3' rx='1.5' fill='%2316a34a'/%3E%3C/svg%3E";
</script>

<template>
  <AgentScreen
    state="idle"
    label="Juniper Health bookings, after the run"
    alt="Bookings list for Juniper Health with six rows, one cancelled"
    :src="screenshot"
  />
</template>
```

Svelte · `image.svelte`

```svelte
<script lang="ts">
  import { AgentScreen } from "$lib/components/ui/agent-screen";

  /* the last capture from the agent's browser session (any image URL) */
  const screenshot =
    "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 200'%3E%3Crect width='320' height='200' fill='%23f8fafc'/%3E%3Crect width='320' height='16' fill='%23e2e8f0'/%3E%3Ccircle cx='9' cy='8' r='2.5' fill='%23f87171'/%3E%3Ccircle cx='17' cy='8' r='2.5' fill='%23fbbf24'/%3E%3Ccircle cx='25' cy='8' r='2.5' fill='%234ade80'/%3E%3Crect x='60' y='4' width='200' height='8' rx='4' fill='%23fff'/%3E%3Crect y='16' width='72' height='184' fill='%23f1f5f9'/%3E%3Crect x='10' y='28' width='40' height='6' rx='3' fill='%2364748b'/%3E%3Crect x='10' y='46' width='48' height='5' rx='2.5' fill='%23cbd5e1'/%3E%3Crect x='6' y='58' width='60' height='13' rx='3' fill='%23dbeafe'/%3E%3Crect x='10' y='62' width='40' height='5' rx='2.5' fill='%233b82f6'/%3E%3Crect x='10' y='80' width='44' height='5' rx='2.5' fill='%23cbd5e1'/%3E%3Crect x='10' y='96' width='36' height='5' rx='2.5' fill='%23cbd5e1'/%3E%3Crect x='88' y='28' width='96' height='8' rx='3' fill='%23334155'/%3E%3Crect x='250' y='25' width='54' height='14' rx='4' fill='%233b82f6'/%3E%3Crect x='88' y='46' width='216' height='14' fill='%23f1f5f9'/%3E%3Crect x='88' y='64' width='216' height='19' fill='%23fff'/%3E%3Crect x='96' y='71' width='36' height='5' rx='2' fill='%2394a3b8'/%3E%3Crect x='164' y='71' width='34' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='214' y='71' width='28' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='262' y='69' width='30' height='9' rx='4.5' fill='%2316a34a' fill-opacity='.18'/%3E%3Crect x='267' y='72' width='20' height='3' rx='1.5' fill='%2316a34a'/%3E%3Crect x='88' y='84' width='216' height='19' fill='%23fff'/%3E%3Crect x='96' y='91' width='43' height='5' rx='2' fill='%2394a3b8'/%3E%3Crect x='164' y='91' width='34' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='214' y='91' width='28' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='262' y='89' width='30' height='9' rx='4.5' fill='%2316a34a' fill-opacity='.18'/%3E%3Crect x='267' y='92' width='20' height='3' rx='1.5' fill='%2316a34a'/%3E%3Crect x='88' y='104' width='216' height='19' fill='%23fff'/%3E%3Crect x='96' y='111' width='50' height='5' rx='2' fill='%2394a3b8'/%3E%3Crect x='164' y='111' width='34' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='214' y='111' width='28' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='262' y='109' width='30' height='9' rx='4.5' fill='%23d97706' fill-opacity='.18'/%3E%3Crect x='267' y='112' width='20' height='3' rx='1.5' fill='%23d97706'/%3E%3Crect x='88' y='124' width='216' height='19' fill='%23fff'/%3E%3Crect x='96' y='131' width='57' height='5' rx='2' fill='%2394a3b8'/%3E%3Crect x='164' y='131' width='34' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='214' y='131' width='28' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='262' y='129' width='30' height='9' rx='4.5' fill='%2316a34a' fill-opacity='.18'/%3E%3Crect x='267' y='132' width='20' height='3' rx='1.5' fill='%2316a34a'/%3E%3Crect x='88' y='144' width='216' height='19' fill='%23fff'/%3E%3Crect x='96' y='151' width='42' height='5' rx='2' fill='%2394a3b8'/%3E%3Crect x='164' y='151' width='34' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='214' y='151' width='28' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='262' y='149' width='30' height='9' rx='4.5' fill='%23dc2626' fill-opacity='.18'/%3E%3Crect x='267' y='152' width='20' height='3' rx='1.5' fill='%23dc2626'/%3E%3Crect x='88' y='164' width='216' height='19' fill='%23fff'/%3E%3Crect x='96' y='171' width='49' height='5' rx='2' fill='%2394a3b8'/%3E%3Crect x='164' y='171' width='34' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='214' y='171' width='28' height='5' rx='2' fill='%23cbd5e1'/%3E%3Crect x='262' y='169' width='30' height='9' rx='4.5' fill='%2316a34a' fill-opacity='.18'/%3E%3Crect x='267' y='172' width='20' height='3' rx='1.5' fill='%2316a34a'/%3E%3C/svg%3E";
</script>

<AgentScreen
  state="idle"
  label="Juniper Health bookings, after the run"
  alt="Bookings list for Juniper Health with six rows, one cancelled"
  src={screenshot}
/>
```

### Open the screen larger

React · `expandable.tsx`

```tsx
import { AgentScreen } from "@/components/ui/agent-screen";

export default function Expandable() {
  return (
    <AgentScreen
      label="Issuing the Kestrel Logistics refund"
      cursor={{ x: 58, y: 44 }}
      recording
      expandable
    />
  );
}
```

Vue · `expandable.vue`

```vue
<script setup lang="ts">
import { AgentScreen } from "@/components/ui/agent-screen";
</script>

<template>
  <AgentScreen
    label="Issuing the Kestrel Logistics refund"
    :cursor="{ x: 58, y: 44 }"
    recording
    expandable
  />
</template>
```

Svelte · `expandable.svelte`

```svelte
<script lang="ts">
  import { AgentScreen } from "$lib/components/ui/agent-screen";
</script>

<AgentScreen
  label="Issuing the Kestrel Logistics refund"
  cursor={{ x: 58, y: 44 }}
  recording
  expandable
/>
```

## Recipe

`agent-screen.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";

/* agent-screen — a framed capture of the agent's screen with its cursor and a recording badge.
 * The capture is an <img> when the host has one, else a neutral placeholder window drawn here
 * from tokens. The cursor layer is as large as the frame, so translating it by "x%, y%" puts its
 * top-left corner (the pointer's tip) at that point of the screen: a transform, never left/top.
 * The screen's coordinates are physical, so the cursor and the placeholder stay left-to-right.
 *
 * State and recording are variants of the frame's layers: the frame is rendered once and shown in
 * both the card and the viewer. The expand button is marked data-agent-screen="expand".
 * expandable: the real Button (outline, xs, square, rounded) with the real Tooltip sits on the
 * frame's bottom end corner (the frame and the button share the first grid cell) and opens the
 * real Dialog, whose body holds the viewer: the same frame, larger. The connecting spinner is the
 * real Spinner.
 *
 * Motion (`docs motion`), all here but the pulse's @keyframes:
 *   cursor    travels on transform at duration.slow easing.in-out-strong: the cursor is a pointer
 *             travelling across the screen, so it eases in and out like a hand moving a mouse, not
 *             like a UI element arriving; it fades (base) when it hides. Reduced motion: it jumps,
 *             the fade stays.
 *   loading   the connecting layer fades (base)
 *   rec       the badge pops in (popup, from scale.popup) and leaves faster (fast)
 *   pulse     the badge's dot: opacity only, so it keeps pulsing under reduced motion */

export const agentScreen = tv({
  slots: {
    /* the frame has no intrinsic width, so the root states one and shrinks in narrow containers */
    base: "relative grid gap-2.5 w-[340px] max-w-full min-w-0 m-0",
    frame: [
      "[grid-area:1/1] relative aspect-[16/10] overflow-hidden isolate rounded-window bg-inset shadow-card",
      "forced-colors:[outline:1px_solid_CanvasText]",
    ],
    media: "absolute inset-0 block size-full object-cover",
    /* placeholder: a neutral browser window */
    placeholder: "absolute inset-0 flex flex-col [direction:ltr] bg-surface",
    chrome: [
      "relative shrink-0 h-6 border-b border-line",
      "[background:radial-gradient(circle_at_12px_50%,var(--fndn-red)_3px,transparent_3.5px),radial-gradient(circle_at_22px_50%,var(--fndn-orange)_3px,transparent_3.5px),radial-gradient(circle_at_32px_50%,var(--fndn-green)_3px,transparent_3.5px),var(--fndn-inset)]",
      "after:content-[''] after:absolute after:top-[7px] after:bottom-[7px] after:start-12 after:end-[28%] after:rounded-pill after:bg-field",
    ],
    page: "flex flex-col gap-2.5 px-3 py-3.5",
    line: [
      "flex items-center gap-2 h-[18px]",
      "before:content-[''] before:shrink-0 before:size-[18px] before:rounded-[50%] before:bg-accent-tint",
      "after:content-[''] after:w-[46%] after:h-1.5 after:rounded-pill after:bg-line-strong",
      "first:after:w-[58%] nth-3:after:w-[34%] nth-4:after:w-[50%]",
    ],
    /* travels on transform; hidden while connecting and when the agent is idle */
    cursor: [
      "absolute inset-0 z-1 [direction:ltr] pointer-events-none",
      "[transform:translate(var(--fndn-agent-screen-cursor,42%,53%))]",
      /* fndn-check-ok: the cursor is a pointer travelling between targets, the move easing's own case */
      "motion-opacity-base motion-also-[transform_var(--fndn-duration-slow)_var(--fndn-easing-in-out-strong)] motion-reduce:[--fndn-m-also:initial]",
      "[&>[data-slot=icon]]:block [&>[data-slot=icon]]:-mt-0.5 [&>[data-slot=icon]]:-ms-[3px] [&>[data-slot=icon]]:text-[20px] [&>[data-slot=icon]]:text-ink",
      "[&>[data-slot=icon]]:[filter:drop-shadow(0_0_1px_var(--fndn-surface))_drop-shadow(0_1px_1.5px_var(--fndn-ink-3))]",
    ],
    /* connecting */
    loading: [
      "absolute inset-0 z-2 flex flex-col items-center justify-center gap-2.5 p-3 bg-inset",
      "opacity-0 invisible motion-opacity-base motion-also-[visibility_var(--fndn-duration-base)]",
    ],
    loadingText: "max-w-full overflow-hidden text-ellipsis whitespace-nowrap text-xs font-medium text-ink-2",
    /* recording badge: pops in from its own top right corner (where it is pinned), leaves faster than it came. The screen is
     * physical (left-to-right in every page direction), and the placeholder window's three dots
     * sit at its top left, so the badge takes the right corner, over the empty end of the title bar
     * (a physical side on purpose, so written as the property) */
    rec: [
      "absolute z-3 top-2 [right:--spacing(2)] inline-flex items-center gap-[5px] h-5 ps-1.5 pe-2 rounded-pill bg-red",
      "text-2xs font-semibold leading-none tracking-[0.04em] whitespace-nowrap text-on-accent",
      "origin-top-right opacity-0 invisible [transform:scale(var(--fndn-motion-popup-scale))] motion-opacity-fast-out motion-transform-fast-out motion-also-[visibility_var(--fndn-duration-fast)]",
      "forced-colors:[forced-color-adjust:none] forced-colors:bg-[Mark] forced-colors:text-[MarkText]",
    ],
    recDot: "shrink-0 size-[7px] rounded-[50%] bg-current animate-[fndn-agent-screen-pulse_1.1s_ease_infinite_alternate]",
    /* the caption takes its direction from its own first letter, so a name in the other script
     * keeps its ellipsis at its own end */
    label: "min-w-0 px-0.5 overflow-hidden text-ellipsis whitespace-nowrap text-sm font-medium text-ink [unicode-bidi:plaintext]",
    status: "sr-only",
    /* added to the Button: the frame's bottom end corner, above the frame's layers */
    expand: "[grid-area:1/1] [align-self:end] [justify-self:end] z-1 m-2",
    /* the viewer, in the Dialog (size lg) */
    viewer: "pb-4",
  },
  variants: {
    state: {
      loading: { cursor: "opacity-0", loading: "opacity-100 visible" },
      live: {},
      idle: { cursor: "opacity-0" },
    },
    recording: {
      true: { rec: "opacity-100 visible [transform:none] motion-opacity-popup motion-transform-popup motion-also-[visibility_var(--fndn-duration-popup)]" },
    },
    /* on the placeholder the badge sits in the 24px title bar, centred on the dots' line */
    placeholder: {
      true: { rec: "top-0.5" },
    },
    /* in the viewer the frame is as large as the window allows without scrolling */
    inViewer: {
      true: { frame: "w-[min(100%,(100dvh_-_160px)*16/10)] mx-auto" },
    },
  },
  defaultVariants: { state: "live" },
});

export type AgentScreenRecipeProps = VariantProps<typeof agentScreen>;
```
