{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "agent",
  "type": "registry:block",
  "title": "Agent block",
  "description": "A chat with an agent as one screen, from the first word to the deploy: the conversation, the thinking, a plan, a run of tool calls, an approval, the answer with its code and the composer. A scripted run plays every state without a model and waits for you at the approval.",
  "registryDependencies": [
    "https://littmd.vercel.app/r/litt.json",
    "https://littmd.vercel.app/r/agent-indicator.json",
    "https://littmd.vercel.app/r/composer.json",
    "https://littmd.vercel.app/r/file-changes.json",
    "https://littmd.vercel.app/r/icons.json",
    "https://littmd.vercel.app/r/log-view.json",
    "https://littmd.vercel.app/r/message.json",
    "https://littmd.vercel.app/r/motion.json",
    "https://littmd.vercel.app/r/plan.json",
    "https://littmd.vercel.app/r/run-list.json",
    "https://littmd.vercel.app/r/select.json",
    "https://littmd.vercel.app/r/sources.json",
    "https://littmd.vercel.app/r/thinking.json",
    "https://littmd.vercel.app/r/tool-call.json"
  ],
  "files": [
    {
      "path": "registry/litt/components/litt-blocks/agent.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n// @litt/agent 2026.11.08. What changed: https://littmd.vercel.app/changelog.md\n\n/**\n * Agent: a chat with an agent, from the first word to the deploy, beside the studio's other runs. A block: a whole\n * screen built from the litt parts, to copy and make your own.\n *\n * Litt, a studio's agent, fixes a failing build while you watch: the conversation, the thinking, a plan, a run of tool\n * calls that each open to what they found (a build's log as it streams, the web search's sources, the edit's file), an\n * approval, the answer with its citations, the review of the files Litt changed, the sources it cites, and the\n * composer. On a wide frame the studio's runs sit beside the chat, and the Halo row is read from the same moment of the\n * chat, so it says Needs you while the approval waits. The one accent fill is Allow while the approval waits, and Send\n * when there is something to send; Keep all is a raised block, because a review does not stop the agent.\n *\n * The run is a script (below), so every state of a turn shows without a model. Keeping or undoing a file is the\n * person's, not the script's: one decision per file, held in React state beside the script and shared by the edit call\n * and the review. To wire in your own agent, keep LittTurn and the layout, and replace useRun with your stream: a View\n * is what the chat shows at one moment.\n */\nimport { Fragment, useEffect, useMemo, useReducer, useState, type ReactNode } from \"react\";\nimport { AgentIndicator } from \"../litt/agent-indicator\";\nimport { Composer, FileChip } from \"../litt/composer\";\nimport { FileChanges, type FileChange, type FileDecision } from \"../litt/file-changes\";\nimport type { StepStatus } from \"../litt/icons\";\nimport { LogView, type LogLine } from \"../litt/log-view\";\nimport { Conversation, Message, MessageActions, MessageText } from \"../litt/message\";\nimport { Plan } from \"../litt/plan\";\nimport { RunList, type AgentRun } from \"../litt/run-list\";\nimport { Select } from \"../litt/select\";\nimport { Citation, SourceList, Sources, unlinkCitations, type Source } from \"../litt/sources\";\nimport { Thinking } from \"../litt/thinking\";\nimport { ToolApproval, ToolCall, ToolCallGroup, type ToolApprovalDecision, type ToolCallProps } from \"../litt/tool-call\";\nimport { useDevice } from \"../../lib/litt/motion\";\nimport { useMaterial } from \"../../lib/litt/motion/deal\";\n\n/* ---------------------------------------------------------------- the script\n\n   One timeline drives the whole run. A beat is a wait and a step of the story: after `ms`, `to` turns one view of the\n   chat into the next. The views are folded once, at load, so the chat at any moment is a pure function of the track and\n   a cursor. Nothing here is random and nothing reads the clock, so every load plays the same run. The Thinking clock\n   is the one thing that reads real time, because that is what a clock is.\n\n   The run has three tracks. \"run\" goes from the first message to the approval and stops there: the person decides.\n   Allow continues on the \"allow\" track and Deny on the \"deny\" track. The phone shows the end of \"allow\". */\n\ntype CallState = \"running\" | \"done\" | \"failed\" | \"stopped\";\n\ntype View = {\n  /** Words of the reasoning shown so far. */\n  thought: number;\n  thinking: boolean;\n  plan: boolean;\n  steps: StepStatus[];\n  /** One entry per tool call shown so far. */\n  calls: CallState[];\n  /** Lines the running call's log has written so far. A call that has ended shows all of its lines. */\n  lines: number;\n  approval: \"none\" | ToolApprovalDecision;\n  deploy: \"none\" | \"running\" | \"done\" | \"stopped\";\n  /** Words of the answer's two paragraphs, and whether the review of the changed files is in between them. */\n  words1: number;\n  review: boolean;\n  words2: number;\n  done: boolean;\n};\n\ntype Beat = { ms: number; to: (view: View) => View };\n\n/* ---- words */\n\n/** A run of the answer: words, a code span, or a citation of a source by its id. */\ntype Run = string | { code: string } | { cite: string };\n\n/** One token per word, one per code span and one per citation. A word keeps the space after it, so a join reads as the sentence. */\nconst tokens = (runs: Run[]): Run[] => runs.flatMap((r): Run[] => (typeof r === \"string\" ? (r.match(/\\s*\\S+\\s*/g) ?? []) : [r]));\nconst total = (paragraphs: Run[][]) => paragraphs.reduce((n, p) => n + tokens(p).length, 0);\n\n/** The first `count` tokens of some paragraphs, as the paragraphs they fall in. */\nfunction reveal(paragraphs: Run[][], count: number): Run[][] {\n  let left = count;\n  const out: Run[][] = [];\n  for (const paragraph of paragraphs) {\n    if (left <= 0) break;\n    const part = tokens(paragraph).slice(0, left);\n    left -= part.length;\n    out.push(part);\n  }\n  return out;\n}\n\n/** The ids the paragraphs cite, in the order they first cite them: a source's number is its place here. */\nconst citesIn = (paragraphs: Run[][]) => [...new Set(paragraphs.flat().flatMap((r) => (typeof r !== \"string\" && \"cite\" in r ? [r.cite] : [])))];\n\nfunction Runs({ runs }: { runs: Run[] }) {\n  return (\n    <>\n      {runs.map((r, i) =>\n        typeof r === \"string\" ? r : \"code\" in r ? <code key={i}>{r.code}</code> : <Citation key={i} source={r.cite} />,\n      )}\n    </>\n  );\n}\n\n/* ---- the story's words, logs, sources and files */\n\nconst ASK = \"The Halo site build is failing on main. Can you find out why and fix it?\";\n\nconst THOUGHT: Run[][] = [\n  [\"The screenshot shows the deploy failing on main, but the error is cut off. I need the build output to see what it could not find.\"],\n  [\"A missing font file is the likeliest cause. The studio dropped Inter for Geist, and a leftover import of the old package would break the build exactly this way.\"],\n  [\"I will read the layout, search the repo for any other fontsource imports, then run the build to confirm the error before I change anything.\"],\n];\n\nconst PLAN = [\n  \"Read the layout and its imports\",\n  \"Search for the old font package\",\n  \"Run the build and read the error\",\n  \"Fix the font and rebuild\",\n  \"Publish the fix to halo.studio\",\n];\n\nconst SEARCH_MATCHES = `1 match in 1 file\nsrc/app/layout.tsx:1  import \"@fontsource/inter/400.css\";`;\n\nconst BUILD_FAILED: LogLine[] = [\n  { time: \"0.0s\", text: \"> halo-site@1.4.0 build\" },\n  { time: \"0.0s\", text: \"> next build\" },\n  { time: \"0.4s\", text: \"▲ Next.js 15.1.0\" },\n  { time: \"0.6s\", text: \"Creating an optimized production build ...\" },\n  { time: \"6.1s\", level: \"error\", text: \"Failed to compile.\" },\n  { time: \"6.1s\", text: \"./src/app/layout.tsx\" },\n  { time: \"6.1s\", level: \"error\", text: \"Module not found: Can't resolve '@fontsource/inter/400.css'\" },\n  { time: \"6.4s\", level: \"error\", text: \"> Build failed because of webpack errors\" },\n];\n\nconst INSTALLED: LogLine[] = [\n  { time: \"2.9s\", text: \"added 1 package, and audited 318 packages in 3s\" },\n  { time: \"3.1s\", level: \"success\", text: \"found 0 vulnerabilities\" },\n];\n\nconst BUILD_PASSED: LogLine[] = [\n  { time: \"0.0s\", text: \"> halo-site@1.4.0 build\" },\n  { time: \"0.0s\", text: \"> next build\" },\n  { time: \"0.4s\", text: \"▲ Next.js 15.1.0\" },\n  { time: \"0.6s\", text: \"Creating an optimized production build ...\" },\n  { time: \"27.9s\", level: \"success\", text: \"✓ Compiled successfully\" },\n  { time: \"33.6s\", level: \"success\", text: \"✓ Linting and checking validity of types\" },\n  { time: \"35.1s\", level: \"success\", text: \"✓ Collecting page data\" },\n  { time: \"39.8s\", level: \"success\", text: \"✓ Generating static pages (14/14)\" },\n  { time: \"41.0s\", level: \"success\", text: \"✓ Finalizing page optimization\" },\n];\n\n/** What the web search found. The answer cites the first two; the list in the search call says the others are not cited. */\nconst FOUND: Source[] = [\n  {\n    id: \"next-font\",\n    title: \"Optimizing: Fonts\",\n    url: \"https://nextjs.org/docs/app/building-your-application/optimizing/fonts\",\n    passage: \"next/font will automatically optimize your fonts (including custom fonts) and remove external network requests for improved privacy and performance.\",\n    readAt: \"just now\",\n  },\n  {\n    id: \"geist\",\n    title: \"geist\",\n    url: \"https://www.npmjs.com/package/geist\",\n    passage: \"Import GeistSans from geist/font/sans and add its className to the html element of your root layout.\",\n    readAt: \"just now\",\n  },\n  {\n    id: \"vercel-font\",\n    title: \"Geist font\",\n    url: \"https://vercel.com/font\",\n    passage: \"Geist is a typeface made for developers and designers, embodying Vercel's design principles of simplicity, minimalism, and speed.\",\n    readAt: \"just now\",\n  },\n  {\n    id: \"fontsource\",\n    title: \"Geist Sans\",\n    url: \"https://fontsource.org/fonts/geist-sans\",\n    passage: \"Self-host the Geist Sans font in a neatly bundled npm package.\",\n    readAt: \"just now\",\n  },\n];\n\nconst LAYOUT_DIFF = `@@ -1,9 +1,9 @@\n-import \"@fontsource/inter/400.css\";\n+import { GeistSans } from \"geist/font/sans\";\n import \"./globals.css\";\n\n export default function RootLayout({ children }: { children: React.ReactNode }) {\n   return (\n-    <html lang=\"en\" className=\"font-inter\">\n+    <html lang=\"en\" className={GeistSans.className}>\n       <body>{children}</body>\n     </html>\n   );`;\n\nconst PACKAGE_DIFF = `@@ -11,6 +11,7 @@\n   \"dependencies\": {\n+    \"geist\": \"^1.3.1\",\n     \"next\": \"15.1.0\",\n     \"react\": \"19.0.0\",\n     \"react-dom\": \"19.0.0\"\n   },`;\n\nconst LAYOUT = \"src/app/layout.tsx\";\n\n/** What Litt changed, in the order to review it. The lockfile's diff is long, so it comes as counts only. */\nconst CHANGES: FileChange[] = [\n  { id: LAYOUT, path: LAYOUT, kind: \"modified\", diff: LAYOUT_DIFF },\n  { id: \"package.json\", path: \"package.json\", kind: \"modified\", diff: PACKAGE_DIFF },\n  { id: \"package-lock.json\", path: \"package-lock.json\", kind: \"modified\", added: 11, removed: 0 },\n];\n\n/** What opens under a call's row: text in the Output well, or a part with its own surface. */\ntype Shows =\n  | { kind: \"output\"; text: string }\n  | { kind: \"log\"; lines: LogLine[] }\n  | { kind: \"sources\"; sources: Source[] }\n  | { kind: \"edit\"; file: string };\n\ntype CallSpec = {\n  action: string;\n  doing: string;\n  target: string;\n  /** What the row reads when it is done. The demo compresses it: a call shows as running for `runs` ms. */\n  seconds: number;\n  runs: number;\n  /** The plan step the call belongs to. */\n  step: number;\n  fail?: boolean;\n  /** A few words on what it found or changed, once it has ended. */\n  result?: string;\n  shows?: Shows;\n};\n\nconst CALLS: CallSpec[] = [\n  { action: \"Read\", doing: \"Reading\", target: LAYOUT, seconds: 0.1, runs: 900, step: 0 },\n  { action: \"Searched\", doing: \"Searching\", target: '\"fontsource\"', seconds: 0.4, runs: 1000, step: 1, result: \"1 match\", shows: { kind: \"output\", text: SEARCH_MATCHES } },\n  { action: \"Ran\", doing: \"Running\", target: \"npm run build\", seconds: 6.4, runs: 1600, step: 2, fail: true, result: \"Exit 1\", shows: { kind: \"log\", lines: BUILD_FAILED } },\n  {\n    action: \"Searched the web\",\n    doing: \"Searching the web\",\n    target: '\"next.js geist font\"',\n    seconds: 1.2,\n    runs: 1200,\n    step: 3,\n    result: `${FOUND.length} sources`,\n    shows: { kind: \"sources\", sources: FOUND },\n  },\n  { action: \"Edited\", doing: \"Editing\", target: LAYOUT, seconds: 0.2, runs: 900, step: 3, result: \"+2 −2\", shows: { kind: \"edit\", file: LAYOUT } },\n  { action: \"Ran\", doing: \"Running\", target: \"npm install geist\", seconds: 3.1, runs: 1000, step: 3, result: \"Exit 0\", shows: { kind: \"log\", lines: INSTALLED } },\n  { action: \"Ran\", doing: \"Running\", target: \"npm run build\", seconds: 41, runs: 1800, step: 3, result: \"Exit 0\", shows: { kind: \"log\", lines: BUILD_PASSED } },\n];\n\nconst RUN_SECONDS = Math.round(CALLS.reduce((sum, c) => sum + c.seconds, 0));\n\nconst COMMAND = \"npm run deploy -- --prod\";\n\nconst WHAT_BROKE: Run[][] = [\n  [\n    \"The build failed because \",\n    { code: LAYOUT },\n    \" still imported Inter from \",\n    { code: \"@fontsource/inter\" },\n    \", a package the studio removed when it moved to Geist. Next.js loads a font through \",\n    { code: \"next/font\" },\n    \", which serves it from the site itself\",\n    { cite: \"next-font\" },\n    \", and the \",\n    { code: \"geist\" },\n    \" package ships Geist for it as \",\n    { code: \"GeistSans\" },\n    { cite: \"geist\" },\n    \". I installed \",\n    { code: \"geist\" },\n    \", pointed the layout at it and ran the build again.\",\n  ],\n];\nconst LIVE: Run[][] = [[\"The build passes and Halo is live again.\"]];\nconst LEFT: Run[][] = [[\"The build passes. I left the deploy to you: run \", { code: COMMAND }, \" when you are ready.\"]];\n\nconst REPLY = \"Understood. I will keep watching the Halo build on main and say here if it fails again.\";\n\n/* ---- what the answer cites */\n\nconst SOURCE = new Map(FOUND.map((s) => [s.id, s]));\nconst CITED = citesIn([...WHAT_BROKE, ...LIVE, ...LEFT]).map((id) => SOURCE.get(id)!);\n/** The turn's sources once k of them are cited, one array per k, so the numbering never changes under a reader. */\nconst CITED_SO_FAR = CITED.map((_, k) => CITED.slice(0, k)).concat([CITED]);\n\n/** The answer as markdown, the way a model writes it: a citation is a \"#cite-\" link. */\nconst markdown = (runs: Run[]) =>\n  runs.map((r) => (typeof r === \"string\" ? r : \"code\" in r ? \"`\" + r.code + \"`\" : `[${CITED.findIndex((s) => s.id === r.cite) + 1}](#cite-${r.cite})`)).join(\"\");\n\n/** What Copy puts on the clipboard: the answer with its \"#cite-\" links undone, and the sources as reference links, so a \"[1]\" pasted into markdown still leads somewhere. */\nconst copyText = (closing: Run[][]) =>\n  unlinkCitations([...WHAT_BROKE, ...closing].map(markdown).join(\"\\n\\n\")) + \"\\n\\n\" + CITED.map((s, i) => `[${i + 1}]: ${s.url} \"${s.title}\"`).join(\"\\n\");\nconst COPY_LIVE = copyText(LIVE);\nconst COPY_LEFT = copyText(LEFT);\n\n/* ---- the beats */\n\nconst WORD_MS = 55;\nconst THOUGHT_MS = 62;\n\nconst INITIAL: View = {\n  thought: 0,\n  thinking: true,\n  plan: false,\n  steps: PLAN.map(() => \"pending\"),\n  calls: [],\n  lines: 0,\n  approval: \"none\",\n  deploy: \"none\",\n  words1: 0,\n  review: false,\n  words2: 0,\n  done: false,\n};\n\ntype Counter = \"thought\" | \"lines\" | \"words1\" | \"words2\";\nconst bump = (key: Counter) => (view: View): View => ({ ...view, [key]: view[key] + 1 });\nconst stream = (count: number, key: Counter, ms: number): Beat[] => Array.from({ length: count }, () => ({ ms, to: bump(key) }));\nconst mark = (steps: StepStatus[], at: number, status: StepStatus) => steps.map((s, i) => (i === at ? status : s));\nconst lastOfStep = (i: number) => !CALLS.slice(i + 1).some((c) => c.step === CALLS[i]!.step);\nconst logOf = (call: CallSpec) => (call.shows?.kind === \"log\" ? call.shows.lines : []);\n\n/** Call `i` ends and the next one starts in the same beat, so a group is never open with nothing running in it. */\nconst advance = (i: number) => (view: View): View => {\n  let { calls, steps } = view;\n  if (i >= 0) {\n    const spec = CALLS[i]!;\n    calls = calls.map((c, j) => (j === i ? (spec.fail ? \"failed\" : \"done\") : c));\n    if (lastOfStep(i)) steps = mark(steps, spec.step, \"done\");\n  }\n  const next = CALLS[i + 1];\n  if (next) {\n    calls = [...calls, \"running\"];\n    steps = mark(steps, next.step, \"running\");\n  }\n  return { ...view, calls, steps, lines: 0 };\n};\n\n/** One call's beats: its log's lines arrive across its run, then it ends and the next one starts. */\nconst callBeats = (call: CallSpec, i: number): Beat[] => {\n  const gap = Math.round(call.runs / (logOf(call).length + 1));\n  return [...stream(logOf(call).length, \"lines\", gap), { ms: gap, to: advance(i) }];\n};\n\n/** The answer: the first paragraph word by word, the review, then the last paragraph word by word, then the end. */\nconst answer = (words2: number): Beat[] => [\n  { ms: 600, to: bump(\"words1\") },\n  ...stream(total(WHAT_BROKE) - 1, \"words1\", WORD_MS),\n  { ms: 350, to: (view) => ({ ...view, review: true }) },\n  { ms: 600, to: bump(\"words2\") },\n  ...stream(words2 - 1, \"words2\", WORD_MS),\n  { ms: 400, to: (view) => ({ ...view, done: true }) },\n];\n\nconst RUN: Beat[] = [\n  ...stream(total(THOUGHT), \"thought\", THOUGHT_MS),\n  { ms: 300, to: (view) => ({ ...view, thinking: false }) },\n  { ms: 500, to: (view) => ({ ...view, plan: true }) },\n  { ms: 500, to: advance(-1) },\n  ...CALLS.flatMap(callBeats),\n  { ms: 800, to: (view) => ({ ...view, approval: \"pending\", steps: mark(view.steps, 4, \"running\") }) },\n];\n\nconst ALLOW: Beat[] = [\n  { ms: 700, to: (view) => ({ ...view, deploy: \"running\" }) },\n  { ms: 1800, to: (view) => ({ ...view, deploy: \"done\", steps: mark(view.steps, 4, \"done\") }) },\n  ...answer(total(LIVE)),\n];\n\nconst DENY: Beat[] = [{ ms: 600, to: (view) => ({ ...view, steps: mark(view.steps, 4, \"skipped\") }) }, ...answer(total(LEFT))];\n\nconst fold = (start: View, beats: Beat[]): View[] => {\n  const views = [start];\n  for (const beat of beats) views.push(beat.to(views[views.length - 1]!));\n  return views;\n};\n\ntype Track = \"run\" | \"allow\" | \"deny\";\n\nconst RUN_VIEWS = fold(INITIAL, RUN);\nconst WAITING = RUN_VIEWS[RUN_VIEWS.length - 1]!;\nconst TRACKS: Record<Track, { beats: Beat[]; views: View[] }> = {\n  run: { beats: RUN, views: RUN_VIEWS },\n  allow: { beats: ALLOW, views: fold({ ...WAITING, approval: \"allowed\" }, ALLOW) },\n  deny: { beats: DENY, views: fold({ ...WAITING, approval: \"denied\" }, DENY) },\n};\nconst FINISHED = TRACKS.allow.views[TRACKS.allow.views.length - 1]!;\n\n/** Whole seconds the reasoning takes to stream, which is what its clock reads when it ends. */\nconst THOUGHT_SECONDS = Math.floor((total(THOUGHT) * THOUGHT_MS + 300) / 1000);\n\n/** What Stop leaves behind: the work in flight is marked as stopped, and nothing runs on. */\nconst halt = (view: View): View => ({\n  ...view,\n  thinking: false,\n  calls: view.calls.map((c) => (c === \"running\" ? \"stopped\" : c)),\n  steps: view.steps.map((s) => (s === \"running\" ? \"skipped\" : s)),\n  deploy: view.deploy === \"running\" ? \"stopped\" : view.deploy,\n});\n\n/* ---- the state machine: a track, a cursor into its beats, and whether the person pressed Stop */\n\ntype State = { track: Track; cursor: number; stopped: boolean };\ntype Action = { type: \"next\" } | { type: \"decide\"; track: \"allow\" | \"deny\" } | { type: \"stop\" };\n\nconst atEnd = (s: State) => s.cursor >= TRACKS[s.track].beats.length;\n\nfunction reduce(s: State, action: Action): State {\n  if (s.stopped) return s;\n  switch (action.type) {\n    case \"next\":\n      return atEnd(s) ? s : { ...s, cursor: s.cursor + 1 };\n    case \"decide\":\n      return s.track === \"run\" && atEnd(s) ? { track: action.track, cursor: 0, stopped: false } : s;\n    case \"stop\":\n      return atEnd(s) ? s : { ...s, stopped: true };\n  }\n}\n\n/** Plays the script. Each beat is one timer, and the cleanup clears it, so a replay or an unmount leaves nothing running. */\nfunction useRun() {\n  const [state, dispatch] = useReducer(reduce, { track: \"run\", cursor: 0, stopped: false });\n  useEffect(() => {\n    const beat = TRACKS[state.track].beats[state.cursor];\n    if (!beat || state.stopped) return;\n    const timer = window.setTimeout(() => dispatch({ type: \"next\" }), beat.ms);\n    return () => window.clearTimeout(timer);\n  }, [state.track, state.cursor, state.stopped]);\n\n  const view = TRACKS[state.track].views[state.cursor]!;\n  return {\n    view: state.stopped ? halt(view) : view,\n    stopped: state.stopped,\n    allow: () => dispatch({ type: \"decide\", track: \"allow\" }),\n    deny: () => dispatch({ type: \"decide\", track: \"deny\" }),\n    stop: () => dispatch({ type: \"stop\" }),\n  };\n}\n\n/* ---------------------------------------------------------------- the person's review\n\n   Keep and Undo are the person's, never the script's: one decision per file, beside the script. The edit call's row\n   and the review at the end read the same decisions, so keeping the layout in one shows it kept in the other. */\n\ntype Review = { changes: FileChange[]; decide?: (ids: string[], decision: FileDecision) => void };\n\n/** A finished chat's review: every file kept, and nothing left to press. */\nconst KEPT: Review = { changes: CHANGES.map((c): FileChange => ({ ...c, state: \"kept\" })) };\n\nfunction useReview(): Review {\n  const [decided, setDecided] = useState<Record<string, FileDecision>>({});\n  const changes = useMemo(() => CHANGES.map((c): FileChange => ({ ...c, state: decided[c.id] ?? \"pending\" })), [decided]);\n  const decide = (ids: string[], decision: FileDecision) =>\n    setDecided((all) => ({ ...all, ...Object.fromEntries(ids.map((id) => [id, decision])) }));\n  return { changes, decide };\n}\n\n/* ---------------------------------------------------------------- the studio's runs */\n\n/** The studio's other runs, newest change first. The Halo run joins them from the chat. */\nconst STUDIO: AgentRun[] = [\n  { id: \"case\", title: \"Write the Halo case study\", status: \"needs-you\", detail: \"Pick one of three intros\", updated: \"9m ago\" },\n  { id: \"framer\", title: \"Compress the Framer site images\", status: \"running\", detail: \"Step 3 of 5\", progress: 0.62, updated: \"4m ago\" },\n  { id: \"northwind\", title: \"Move the Northwind site\", status: \"failed\", detail: \"Step 4: font file missing\", updated: \"12m ago\" },\n  { id: \"cosmos\", title: \"Import the Cosmos catalog\", status: \"done\", detail: \"1,240 products\", updated: \"1h ago\" },\n  { id: \"atelier\", title: \"Rename the Atelier Nord pages\", status: \"stopped\", detail: \"At step 2 of 4\", updated: \"Yesterday\" },\n];\n\n/** The Halo run as a Run list row, read from the moment the chat shows: no state of its own, so the two never disagree. */\nfunction haloRun(view: View, stopped: boolean): AgentRun {\n  const row = { id: \"halo\", title: \"Fix the Halo build\", updated: \"now\" };\n  if (stopped) return { ...row, status: \"stopped\" };\n  if (view.done) return { ...row, status: \"done\", detail: view.approval === \"denied\" ? \"Deploy left to you\" : \"Live on halo.studio\" };\n  if (view.approval === \"pending\") return { ...row, status: \"needs-you\", detail: \"Approve npm run deploy\" };\n  if (!view.plan) return { ...row, status: \"running\", detail: \"Thinking\" };\n  const at = view.steps.findIndex((s) => s === \"running\" || s === \"pending\");\n  const settled = view.steps.filter((s) => s === \"done\" || s === \"skipped\").length;\n  return { ...row, status: \"running\", detail: at < 0 ? \"Writing the answer\" : `Step ${at + 1} of ${PLAN.length}`, progress: settled / PLAN.length };\n}\n\n/** The runs, with the Halo row the open one until the person opens another. */\nfunction Rail({ halo }: { halo: AgentRun }) {\n  const [open, setOpen] = useState(halo.id);\n  return <RunList runs={[halo, ...STUDIO]} selectedId={open} onSelect={(run) => setOpen(run.id)} />;\n}\n\n/**\n * The screen: the runs in a rail and the chat beside it. The rail shows only on a frame wide enough for both, read from\n * the frame (a container query) and never from the window alone, and never on a phone, whose frame can sit inside a\n * desktop page. It is 20rem, so the Halo row says \"Needs you · Approve npm run deploy\" without a cut.\n */\nfunction Studio({ halo, children }: { halo: AgentRun; children: ReactNode }) {\n  const { compact } = useDevice();\n  return (\n    <div className=\"@container h-full min-h-0 w-full min-w-0\">\n      <div className=\"flex h-full min-h-0 w-full min-w-0\">\n        {!compact && (\n          <div className=\"hidden w-80 shrink-0 overflow-y-auto border-r border-litt-line bg-litt-surface-1 p-2 @3xl:block\">\n            <Rail halo={halo} />\n          </div>\n        )}\n        <div className=\"flex h-full min-h-0 min-w-0 flex-1 flex-col\">{children}</div>\n      </div>\n    </div>\n  );\n}\n\n/* ---------------------------------------------------------------- the chat */\n\nconst MODELS = [\n  { value: \"fast\", label: \"Litt Fast\" },\n  { value: \"litt\", label: \"Litt\" },\n  { value: \"deep\", label: \"Litt Deep\" },\n];\n\n/** The model picker in the composer's toolbar. A finger gets a 44px trigger. */\nfunction ModelSelect() {\n  const { coarse } = useDevice();\n  return (\n    <div className=\"w-36\">\n      <Select aria-label=\"Model\" size={coarse ? \"md\" : \"sm\"} options={MODELS} defaultValue=\"litt\" />\n    </div>\n  );\n}\n\nconst CALL_STATUS = { running: \"running\", done: \"done\", failed: \"failed\", stopped: \"denied\" } as const;\n\n/**\n * What opens under a call's row. `written` is how many lines a call that has not ended (running, or stopped) has\n * written, and null once it ends: a log streams while the call runs, and everything else arrives when it ends.\n */\nfunction found(call: CallSpec, written: number | null, review: Review): Pick<ToolCallProps, \"output\" | \"details\"> {\n  const shows = call.shows;\n  const ended = written === null;\n  if (!shows) return {};\n  switch (shows.kind) {\n    case \"log\":\n      return { details: <LogView label={call.target} lines={ended ? shows.lines : shows.lines.slice(0, written)} height=\"12rem\" /> };\n    case \"output\":\n      return ended ? { output: shows.text } : {};\n    case \"sources\":\n      return ended ? { details: <SourceList sources={shows.sources} label=\"Search results\" hideLabel /> } : {};\n    case \"edit\":\n      return ended ? { details: <FileChanges changes={review.changes.filter((c) => c.id === shows.file)} onDecide={review.decide} summary={false} /> } : {};\n  }\n}\n\n/** What Litt did in this turn, from the plan to the answer. `frozen` is a chat that is already over. */\nfunction LittTurn({\n  view,\n  stopped,\n  frozen,\n  later,\n  review,\n  onAllow,\n  onDeny,\n  onRetry,\n}: {\n  view: View;\n  stopped: boolean;\n  frozen: boolean;\n  later: boolean;\n  review: Review;\n  onAllow?: () => void;\n  onDeny?: () => void;\n  onRetry?: () => void;\n}) {\n  const busy = !view.done && !stopped;\n  /* Under Device the Thinking row carries the agent indicator (worlds.md, decision 7). The run is thinking while this\n     row is active, so that is the phase; Press and Flat pass nothing and keep the clock alone. */\n  const device = useMaterial() === \"device\";\n  const running = view.calls.includes(\"running\");\n  const closing = view.approval === \"denied\" ? LEFT : LIVE;\n  const [p1] = reveal(WHAT_BROKE, view.words1);\n  const [p2] = reveal(closing, view.words2);\n  const cited = CITED_SO_FAR[citesIn([p1 ?? [], p2 ?? []]).length]!;\n  /* The reader's own open or close of a call, once they make one. Until then a log is open while it streams, and a\n     failed call stays open so its error can be read. */\n  const [chosen, setChosen] = useState<Record<number, boolean>>({});\n\n  return (\n    <Message\n      streaming={busy}\n      latest={!later}\n      error={stopped ? \"You stopped Litt before it finished.\" : undefined}\n      onRetry={onRetry}\n      actions={<MessageActions copyText={view.approval === \"denied\" ? COPY_LEFT : COPY_LIVE} onRetry={onRetry} />}\n    >\n      {/* The sources the answer has cited so far, numbered in the order it cites them, for the marks, the search's results and the list. */}\n      <Sources sources={cited}>\n        {/* One measure for every part, the prose's, so the rows end where the words do. */}\n        <div className=\"grid min-w-0 max-w-(--litt-measure) gap-3\">\n          <Thinking\n            active={view.thinking}\n            duration={frozen ? THOUGHT_SECONDS : undefined}\n            indicator={device ? <AgentIndicator phase=\"thinking\" paused={!view.thinking} /> : undefined}\n          >\n            {reveal(THOUGHT, view.thought).map((runs, i) => (\n              <p key={i}>\n                <Runs runs={runs} />\n              </p>\n            ))}\n          </Thinking>\n\n          {view.plan && (\n            <Plan\n              label=\"Fix the Halo build\"\n              steps={PLAN.map((label, i) => ({\n                id: String(i),\n                label,\n                status: view.steps[i]!,\n                detail: i === 4 && view.steps[i] === \"skipped\" && !stopped ? \"Left for you to run.\" : undefined,\n              }))}\n            />\n          )}\n\n          {view.calls.length > 0 && (\n            <ToolCallGroup\n              running={running}\n              summary={running ? \"Working on the build\" : \"Looked up Geist, fixed the layout and ran the build twice\"}\n              duration={running ? undefined : RUN_SECONDS}\n            >\n              {view.calls.map((state, i) => {\n                const call = CALLS[i]!;\n                const live = state === \"running\";\n                return (\n                  <ToolCall\n                    key={i}\n                    status={CALL_STATUS[state]}\n                    statusLabel={state === \"stopped\" ? \"Stopped\" : undefined}\n                    action={live ? call.doing : call.action}\n                    target={call.target}\n                    result={live ? undefined : call.result}\n                    duration={live ? undefined : call.seconds}\n                    {...found(call, live || state === \"stopped\" ? view.lines : null, review)}\n                    open={chosen[i] ?? (!frozen && ((live && call.shows?.kind === \"log\") || state === \"failed\"))}\n                    onOpenChange={(open) => setChosen((all) => ({ ...all, [i]: open }))}\n                  />\n                );\n              })}\n            </ToolCallGroup>\n          )}\n\n          {view.approval !== \"none\" && (\n            <div className=\"grid\">\n              <ToolApproval\n                command={COMMAND}\n                description=\"Publishes the Halo site to halo.studio.\"\n                decision={view.approval}\n                onAllow={onAllow}\n                onDeny={onDeny}\n              />\n              {view.deploy !== \"none\" && (\n                <ToolCall\n                  status={view.deploy === \"running\" ? \"running\" : view.deploy === \"stopped\" ? \"denied\" : \"done\"}\n                  statusLabel={view.deploy === \"stopped\" ? \"Stopped\" : undefined}\n                  action={view.deploy === \"done\" ? \"Published\" : \"Publishing\"}\n                  target=\"halo.studio\"\n                  duration={view.deploy === \"done\" ? 12 : undefined}\n                />\n              )}\n            </div>\n          )}\n\n          {p1 && (\n            <MessageText>\n              <p>\n                <Runs runs={p1} />\n              </p>\n            </MessageText>\n          )}\n          {view.review && <FileChanges changes={review.changes} onDecide={review.decide} />}\n          {p2 && (\n            <MessageText>\n              <p>\n                <Runs runs={p2} />\n              </p>\n            </MessageText>\n          )}\n          {view.done && <SourceList />}\n        </div>\n      </Sources>\n    </Message>\n  );\n}\n\n/** The composer at the foot, in the same centered column as the turns above it. */\nfunction Foot({ children }: { children: ReactNode }) {\n  return (\n    <div className=\"px-4 pb-4\">\n      <div className=\"mx-auto w-full max-w-[48rem]\">{children}</div>\n    </div>\n  );\n}\n\nexport type AgentChatProps = {\n  /** Show the chat already over, at the end of the run with Allow pressed and every file kept, with Send off. Nothing plays and nothing is left to decide. */\n  finished?: boolean;\n  /** Names the conversation's landmark. Change it when two chats share a page. */\n  label?: string;\n  /** Called by Retry on the answer. Remount the chat (a new key) to play the run again. */\n  onRestart?: () => void;\n};\n\n/**\n * The whole screen: on a wide frame the studio's runs in a rail, then the chat, the turns in a centered column and the\n * composer at the foot. It fills its box, so give that box a height (a full-height app pane, or a fixed-height frame);\n * the conversation scrolls inside it.\n */\nexport function AgentChat({ finished = false, label = \"Conversation with Litt\", onRestart }: AgentChatProps) {\n  return finished ? <FinishedChat label={label} /> : <LiveChat label={label} onRestart={onRestart} />;\n}\n\n/** Touch screens hide the conversation's scrollbar; a pointer keeps a stable gutter on both edges, so the column stays centered. */\nconst scrollbar = (coarse: boolean) => (coarse ? \"[&>[role=region]]:[scrollbar-width:none]\" : \"[&>[role=region]]:[scrollbar-gutter:stable_both-edges]\");\n\nfunction LiveChat({ label, onRestart }: { label: string; onRestart?: () => void }) {\n  const { view, stopped, allow, deny, stop } = useRun();\n  const review = useReview();\n  const { coarse } = useDevice();\n  const [asked, setAsked] = useState<string[]>([]);\n  const busy = !view.done && !stopped;\n  const waiting = view.approval === \"pending\";\n\n  return (\n    <Studio halo={haloRun(view, stopped)}>\n      <Conversation label={label} agentName=\"Litt\" busy={busy} className={\"flex-1 \" + scrollbar(coarse)}>\n        <Message from=\"user\" attachments={<FileChip name=\"halo-deploy-error.png\" size={217088} />}>\n          {ASK}\n        </Message>\n        <LittTurn\n          view={view}\n          stopped={stopped}\n          frozen={false}\n          later={asked.length > 0}\n          review={review}\n          onAllow={allow}\n          onDeny={deny}\n          onRetry={onRestart}\n        />\n        {asked.map((text, i) => (\n          <Fragment key={i}>\n            <Message from=\"user\">{text}</Message>\n            <Message latest={i === asked.length - 1} actions={<MessageActions copyText={REPLY} />}>\n              <MessageText>{REPLY}</MessageText>\n            </Message>\n          </Fragment>\n        ))}\n      </Conversation>\n      <Foot>\n        <Composer\n          label=\"Message Litt\"\n          placeholder=\"Message Litt\"\n          hint={waiting ? \"Send is off while Litt waits for your answer.\" : \"Litt can be wrong. Check what matters.\"}\n          streaming={busy && !waiting}\n          sendDisabled={waiting}\n          onStop={stop}\n          onSend={(text) => setAsked((all) => [...all, text])}\n          tools={<ModelSelect />}\n        />\n      </Foot>\n    </Studio>\n  );\n}\n\nfunction FinishedChat({ label }: { label: string }) {\n  const { coarse } = useDevice();\n  return (\n    <Studio halo={haloRun(FINISHED, false)}>\n      <Conversation label={label} agentName=\"Litt\" className={\"flex-1 \" + scrollbar(coarse)}>\n        <Message from=\"user\" attachments={<FileChip name=\"halo-deploy-error.png\" size={217088} />}>\n          {ASK}\n        </Message>\n        <LittTurn view={FINISHED} stopped={false} frozen later={false} review={KEPT} />\n      </Conversation>\n      <Foot>\n        <Composer label=\"Message Litt\" placeholder=\"Message Litt\" hint=\"A finished chat. Send is off in this picture.\" sendDisabled tools={<ModelSelect />} />\n      </Foot>\n    </Studio>\n  );\n}\n",
      "target": "components/litt-blocks/agent.tsx"
    }
  ],
  "docs": "Import AgentChat from components/litt-blocks/agent and give its box a height; the conversation scrolls inside it. The run is a script: to wire in your agent, keep LittTurn and the layout and replace useRun with your stream. See it live at https://littmd.vercel.app/#agent.",
  "meta": {
    "version": "2026.11.08",
    "released": "2026-11-08",
    "changelog": "https://littmd.vercel.app/changelog.md"
  }
}
