# Activity log

A docket of what an agent did: thoughts, actions, questions, responses and errors, each timed. Questions waiting on you are highlighted.

- Category: Agents
- Docs: https://bevel-ui.vercel.app/components/activity-log
- Import from: `@/components/ui/activity-log`

## Install

```bash
npx shadcn@latest add @bevel/activity-log
```

npm dependencies (installed by the CLI): `cn`.

## Anatomy

```tsx
<ActivityLog aria-label="Agent activity">
  <ActivityLogTitle />
  <ActivityLogEntries>
    <ActivityLogEntry kind="action" time="14:02" />
  </ActivityLogEntries>
</ActivityLog>
```

## Parts

| Part | Renders | Description |
| --- | --- | --- |
| `ActivityLog` | section | The docket page. Give it an aria-label. |
| `ActivityLogEntries` | div (log) | A live log: new entries are announced politely. Scrolls past --activity-log-height and follows new entries only while you're at the bottom. |
| `ActivityLogEntry` | div | kind: thought, action, question, response or error (shown in words), time and dateTime. Entries added later print in. |

## Example: Two agents on a matter

Entries arrive as the agents work. Who acted is a plain Name tag.

```tsx
"use client"

import * as React from "react"
import {
  ActivityLog,
  ActivityLogEntries,
  ActivityLogEntry,
  ActivityLogTitle,
  type ActivityLogKind,
} from "@/components/ui/activity-log"
import { NameTag, NameTagName } from "@/components/ui/name-tag"

type Entry = { kind: ActivityLogKind; agent: string; text: string }

const script: Entry[] = [
  { kind: "thought", agent: "Research", text: "The notice clause is probably in section 9." },
  { kind: "action", agent: "Research", text: "Opened lease.pdf, page 14." },
  { kind: "response", agent: "Research", text: "Found three notice clauses." },
  { kind: "action", agent: "Drafting", text: "Started a redline of clause 9.2." },
  { kind: "question", agent: "Drafting", text: "Should email count as written notice?" },
  { kind: "error", agent: "Research", text: "Couldn't open schedule-b.pdf: it's password protected." },
  { kind: "response", agent: "Drafting", text: "Redline ready for review." },
]

/** Two agents working a matter. Entries arrive as they happen. */
export function ActivityLogAgent() {
  const [count, setCount] = React.useState(2)

  React.useEffect(() => {
    if (count >= script.length) return
    const timer = setTimeout(() => setCount((c) => c + 1), 1400)
    return () => clearTimeout(timer)
  }, [count])

  return (
    <div className="flex w-full max-w-xl flex-col items-center gap-4">
      <ActivityLog aria-label="Matter activity">
        <ActivityLogTitle>Harbor Street lease</ActivityLogTitle>
        <ActivityLogEntries>
          {script.slice(0, count).map((entry, i) => (
            <ActivityLogEntry key={i} kind={entry.kind} time={`14:${String(2 + i).padStart(2, "0")}`}>
              <NameTag variant="plain">
                <NameTagName>{entry.agent}</NameTagName>
              </NameTag>
              <span>{entry.text}</span>
            </ActivityLogEntry>
          ))}
        </ActivityLogEntries>
      </ActivityLog>
      <button
        type="button"
        disabled={count < script.length}
        onClick={() => setCount(0)}
        className="h-9 rounded-md border px-3 text-sm font-medium hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none disabled:opacity-50"
      >
        Replay
      </button>
    </div>
  )
}
```
