A box above the prompt that always says what the agent is doing right now, alive with color and motion: an animated status glyph, a glowing jellyfish on the…

See what Claude Code is doing at every step, in plain English, live, and in color.
Agent Pulse is a fork of Tzafrir Rehan's whats-agent-doing 0.4.3 (MIT, see LICENSE), imported with its history, so the original commits keep their author. Everything that makes the box useful is Tzafrir's: the plain-English step names, the command descriptions in place of flags, the timers, the history behind the triangle, the agent rows. This fork adds color, motion and small charts on top, on the terminal and on the desktop app's Code tab, and a jellyfish.
| Thinking | Running a tool | Writing the reply | Waiting for you | Idle |
|---|---|---|---|---|
The turn so far, as the timeline strip draws it:
The box above the prompt names the step Claude is on and how long it has been on it. Click ▸ (or focus the band with ctrl+x tab and press Enter) to see every step it has taken. This is the original's behaviour, unchanged; its README has the full table of states.
╭─────────────────────────────────────────────────────────────────
│ ▸ ⠹ ❯ Find the commit that broke fixed-amount coupons ▃ · 1m 48s
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
│ ├─ ⠼ Find callers of applyCoupon › Searching for "applyCoupon("
│ └─ ⠧ Check the coupon tests › Reading coupon.test.ts 33s
╰─────────────────────────────────────────────────────────────────
Every effect carries meaning: nothing moves just to be busy.
| Addition | What it tells you | Terminal | Desktop |
|---|---|---|---|
| Status glyph | Claude is working, and on what kind of step | a spinner per phase: ◐◓◑◒ reading, ∘○◎● thinking, ⣀⣤⣶⣿ writing, braille for tools | the jellyfish acts out the phase |
| Jellyfish | The same, at a glance | bobs, pulses, swings its tentacles; bubbles while thinking, ink while writing, a ! or ? while it waits on you, asleep when idle | |
| Breathing border | You are needed: an approval or a question | the border fades in and out | the glow breathes yellow |
| Flash | A call just finished, and how | the border flashes green ✓, red ✗ or yellow ⊘ | a halo ring |
| Sparkle | The turn is done | ✦ ✧ after the timer | stars around the jellyfish |
| Timer heat | A step is taking long | amber after 30 s, orange after 2 min, red after 5 min | same |
| Tool glyphs | Which tool runs | ◧ Read, ✎ Edit, ✚ Write, ❯ shell, ⌕ Grep, ⌁ web, ◆ agent, ⧉ MCP | same |
| Agent rows | Who is doing what | ├─ └─ tree lines, a color and a spinner per agent | same, a color per agent |
| Timeline strip | Where the turn's time went | colored ━ per phase, under the headline | an SVG strip |
| Duration bars | Which step was slow | ▏▎▍▌▋▊▉█ per history row | SVG bars |
| Meters | How much is being written | ▁▂▃▄▅▆▇█ for the reply's words or a call's size | same |
| Hover cards | The whole label, when the window cuts it | rest the pointer on a row | same |
| Chime | Claude started waiting for your approval | opt-in | opt-in |
| Above the question | Claude asked you something: the dialog covers the band | a still copy of the headline and agents above the question | same |
In /config, type Animation to find the three rows:
| Setting | Values | Default |
|---|---|---|
| Animation | off: still, but with the colors and charts. subtle: the status glyph, the flash, the jellyfish's swim. full: adds the breathing border, bubbles, ink and sparkles | subtle |
| Palette | ember: Claude's warm orange range, each phase shading from one color into a second. claude: follows your theme. neon: glowing deep-sea colors, shading the same way. mono: color only for what needs you | ember |
| Sound | off, or approval: a soft chime when Claude starts waiting for your approval | off |
A change reloads the mod at once; the box keeps its history. On the desktop, the jellyfish also stops moving when your system asks for reduced motion.
Uninstall whats-agent-doing first, or you will see two boxes:
claude plugin uninstall whats-agent-doing@tzafrir
Then, in Claude Code:
/plugin marketplace add afterever/claude-mods
/plugin install agent-pulse@afterever-mods
Or from your shell:
claude plugin marketplace add afterever/claude-mods
claude plugin install agent-pulse@afterever-mods
Requirements: Claude Code in a terminal, or in the desktop app's Code tab. The plugin is a mod, written with Claude Code's function hooks, which are early access: they load only where function hooks are enabled, and their API may change between releases. Hooks are not loaded in Claude chat or Cowork.
$.state) and nothing else: no files, no network, no processes, no storage across sessions. claude plugin validate lists every call it makes: $.agent.list, $.audio.play, $.clock, $.state and $.ui.sounds/chime.wav), generated for it.Load the plugin from a clone; the session reloads it as you edit:
claude --plugin-dir agent-pulse
claude plugin validate agent-pulse
claude plugin test agent-pulse
The desktop app starts its own sessions, so there the folder goes in CLAUDE_CODE_PLUGIN_DIRS (in the env block of ~/.claude/settings.json) instead of a flag.
| File | What it does |
|---|---|
hooks/register.tsx | The hooks, as in the original, plus the settings, the timeline, the flourishes and the chime; it hands the drawing to draw.tsx |
hooks/draw.tsx | The box: one renderer for the terminal, one for the desktop and every surface that draws SVG |
hooks/pulse.tsx | The terminal's animations, each a fixed-width Client on its own frame clock: the spinner and the sparkle |
hooks/jelly.ts | SVG for the desktop: the jellyfish, the strip and the bars, animated by CSS |
hooks/palette.ts | The palettes, timer heat, per-agent colors |
hooks/glyphs.ts | Tool glyphs, spinners, meters and bars |
hooks/activity-of.ts | Turns a tool call, whole or still streaming, into its short label (the original's) |
hooks/text.ts | Printable labels, thought snippets, word counts, sizes, durations (the original's) |
types/index.d.ts | The $.state contract |
tests/register.test.tsx | The original's tests: a whole turn state by state, the history, hostile labels, approvals, agents |
tests/pulse.test.tsx | Every animation level on both surfaces, the flash, the breath, the sparkle, the jellyfish's stable source |
DESIGN.md | Why each addition is built the way it is, and what was turned down |
MIT. Copyright (c) 2026 Tzafrir Rehan, and afterever for the Agent Pulse changes.
hooks/register.tsx 970 lines1import { atom, read, update } from 'claude-code'
2import type { AgentInfo, EngineInterface, Register, Timer, TurnCompleteReason, TurnStepChunk } from 'claude-code'
3
4import type {
5 ActivityAgent,
6 ActivityBeat,
7 ActivityEntry,
8 ActivityNow,
9 ActivityOutcome,
10 ActivityTimeline,
11} from '../types'
12import { activityOf, partialArgsOf } from './activity-of'
13import { drawDesktop, drawQuestion, drawTerminal } from './draw'
14import type { PulseOf, View } from './draw'
15import { meterOf } from './glyphs'
16import { levelOf, paletteOf } from './palette'
17import type { Level } from './palette'
18import { clip, durationOf, oneLine, plural, sizeOf, thoughtOf, wordsAdded } from './text'
19
20const IDLE: ActivityNow = {
21 phase: 'idle',
22 label: 'Idle, waiting for your prompt',
23 sinceMs: 0,
24}
25
26const MAX_HISTORY = 100
27const MAX_THOUGHT_CHARS = 70
28const MAX_THOUGHT_BUFFER = 2000
29const MAX_INPUT_HEAD = 4000
30const LARGE_INPUT_CHARS = 1024
31const MAX_SEGMENTS = 200
32const STREAM_THROTTLE_MS = 250
33const TICK_MS = 1000
34const BREATH_TICK_MS = 125
35const FLASH_MS = 380
36const FULL_REPLY_WORDS = 800
37const FULL_INPUT_CHARS = 64 * 1024
38const CHIME = 'sounds/chime.wav'
39
40const now = atom({ plugin: 'agent-pulse', key: 'now' } as const, IDLE)
41
42const history = atom(
43 { plugin: 'agent-pulse', key: 'history' } as const,
44 [] as readonly ActivityEntry[],
45)
46
47const team = atom(
48 { plugin: 'agent-pulse', key: 'agents' } as const,
49 [] as readonly ActivityAgent[],
50)
51
52const isExpanded = atom(
53 { plugin: 'agent-pulse', key: 'isExpanded' } as const,
54 false,
55)
56
57const timeline = atom(
58 { plugin: 'agent-pulse', key: 'timeline' } as const,
59 { segments: [], open: null } as ActivityTimeline,
60)
61
62const beat = atom(
63 { plugin: 'agent-pulse', key: 'beat' } as const,
64 null as ActivityBeat | null,
65)
66
67/** What the model is doing in the main loop, between and around tool calls. */
68type ModelPhase = 'idle' | 'requesting' | 'thinking' | 'writing' | 'composing' | 'compacting'
69
70/** A main-loop tool call in flight. */
71type Call = {
72 tool: string
73 label: string
74 startMs: number
75 isAwaitingApproval: boolean
76}
77
78/**
79 * A subagent at work, from its spawn (or its first call, when the spawn came
80 * before a reload) to its stop. `toolUseId` names the Agent call that started
81 * it; `activeMs` is when it last did something.
82 */
83type Agent = {
84 name: string
85 label: string
86 startMs: number
87 activeMs: number
88 toolUseId: string | null
89 isBackground: boolean
90}
91
92/**
93 * The module's live view of the session, from which the headline is drawn:
94 * started over on a reload, while the headline and history in `$.state` stay.
95 */
96type Live = {
97 calls: Map<string, Call>
98 agents: Map<string, Agent>
99 agentNames: Map<string, string>
100 described: Map<string, string>
101 phase: ModelPhase
102 phaseStartMs: number
103 turnStartMs: number | null
104 turnActions: number
105 isFirstRequest: boolean
106 resultsToReview: number
107 thought: string
108 thoughtWords: number
109 isThoughtInWord: boolean
110 replyWords: number
111 isReplyInWord: boolean
112 composing: { tool: string; head: string; chars: number } | null
113 lastAction: string | null
114 lastTurn: string | null
115 lastPublishMs: number
116 trailing: Timer | null
117 isSweeping: boolean
118 ticker: Timer | null
119 /** The redraws of a breathing border while Claude waits on the person. */
120 breath: Timer | null
121 beats: number
122 level: Level
123 isChiming: boolean
124}
125
126/**
127 * Registers Agent Pulse: a box above the prompt naming what Claude is doing
128 * right now, and, behind its triangle, what it has done; alive with color
129 * and motion as far as `options.animation` lets it.
130 *
131 * The model's own stream (`turn.step`) says whether it is reading, thinking
132 * (the thought's latest sentence), writing the reply or composing a tool's
133 * input; `tool.call` says which tool runs, `classic.PermissionRequest` when
134 * one waits for approval, and a subagent's calls show under its Agent call.
135 *
136 * @param on the engine's registrar
137 * @param options the `userConfig` values: `animation`, `palette`, `sound`
138 */
139export const register: Register = (on, options) => {
140 const level = levelOf(options['animation'])
141 const palette = paletteOf(options['palette'])
142 const look = { level, palette }
143 const live: Live = {
144 calls: new Map(),
145 agents: new Map(),
146 agentNames: new Map(),
147 described: new Map(),
148 phase: 'idle',
149 phaseStartMs: 0,
150 turnStartMs: null,
151 turnActions: 0,
152 isFirstRequest: false,
153 resultsToReview: 0,
154 thought: '',
155 thoughtWords: 0,
156 isThoughtInWord: false,
157 replyWords: 0,
158 isReplyInWord: false,
159 composing: null,
160 lastAction: null,
161 lastTurn: null,
162 lastPublishMs: 0,
163 trailing: null,
164 isSweeping: false,
165 ticker: null,
166 breath: null,
167 beats: 0,
168 level,
169 isChiming: options['sound'] === 'approval',
170 }
171
172 on('session.start', async ($, e, next) => {
173 const result = await next(e)
174
175 await publish($, live)
176
177 return result
178 })
179
180 on('turn.start', async ($, e, next) => {
181 if (live.turnStartMs !== null) {
182 return next(e)
183 }
184
185 live.turnStartMs = await $.clock.now()
186 live.turnActions = 0
187 live.isFirstRequest = true
188 live.resultsToReview = 0
189 live.lastAction = null
190 live.calls.clear()
191 await update($, timeline, () => ({ segments: [], open: null }))
192
193 const prompt = oneLine(e.text)
194
195 if (prompt !== '') {
196 await remember($, { kind: 'turn', label: clip(prompt, 60), durationMs: null, outcome: 'ok' })
197 }
198
199 await enter($, live, 'requesting')
200
201 keepTicking($, live)
202 await publish($, live)
203
204 return next(e)
205 })
206
207 on('turn.step', async function* ($, e, next) {
208 if (e.agentId !== undefined) {
209 return yield* next(e)
210 }
211
212 await enter($, live, 'requesting')
213 await publish($, live)
214
215 try {
216 for await (const chunk of next(e)) {
217 await follow($, live, chunk)
218 yield chunk
219 }
220 } finally {
221 live.isFirstRequest = false
222 live.composing = null
223 await enter($, live, 'requesting')
224 await publish($, live)
225 }
226 })
227
228 on('tool.call', async ($, e, next) => {
229 const label = activityOf(e.tool, e as unknown as Record<string, unknown>)
230
231 if (e.agentId !== undefined) {
232 const agent = await agentOf($, live, e.agentId)
233
234 // Kept after the call: the agent's last action stands while it thinks.
235 agent.label = label
236 agent.activeMs = await $.clock.now()
237 await publish($, live, false)
238
239 try {
240 return await next(e)
241 } finally {
242 agent.label = label
243 await publish($, live, false)
244 }
245 }
246
247 const startMs = await $.clock.now()
248
249 live.calls.set(e.tool_use_id, { tool: e.tool, label, startMs, isAwaitingApproval: false })
250 live.lastAction = label
251 live.turnActions += 1
252 await publish($, live)
253
254 let outcome: ActivityOutcome = 'interrupted'
255
256 try {
257 const result = await next(e)
258
259 outcome = result.deny !== undefined ? 'denied' : result.isError ? 'error' : 'ok'
260
261 if (isAgentTool(e.tool)) {
262 const args = e as unknown as Record<string, unknown>
263 const handle = args['name']
264 const description = args['description']
265
266 // A named agent runs as a teammate, which the engine lists by the
267 // call's `name`; the call's `description` is what to show for it.
268 if (typeof handle === 'string' && typeof description === 'string' && oneLine(description) !== '') {
269 live.described.set(handle, description)
270 void sweep($, live)
271 }
272
273 await launched($, live, result.result, description)
274 }
275
276 return result
277 } finally {
278 live.calls.delete(e.tool_use_id)
279 live.resultsToReview += 1
280
281 await remember($, {
282 kind: 'tool',
283 label,
284 durationMs: (await $.clock.now()) - startMs,
285 outcome,
286 tool: e.tool,
287 })
288
289 await pulseBeat($, live, 'flash', outcome)
290 await publish($, live)
291 }
292 })
293
294 on('classic.PermissionRequest', async ($, e, next) => {
295 if (e.agent_id !== undefined) {
296 const agent = await agentOf($, live, e.agent_id)
297
298 agent.label = `Waiting for your approval: ${agent.label}`
299 } else {
300 const waiting = [...live.calls.values()]
301 .reverse()
302 .find(call => call.tool === e.tool_name && !call.isAwaitingApproval)
303
304 if (waiting) {
305 waiting.isAwaitingApproval = true
306 }
307 }
308
309 if (live.isChiming) {
310 // A chime is a nicety: no sound device, or a refused play, changes nothing.
311 $.audio.play({ asset: CHIME }).catch(() => {})
312 }
313
314 await publish($, live)
315
316 return next(e)
317 })
318
319 // The run-in-background pill shows only under a call that is running, so
320 // its drawing means the person has answered the approval it waited on.
321 on('ui.render', { component: 'ToolProgress' }, ($, e, next) => {
322 const call = live.calls.get(e.props.tool_use_id)
323
324 if (call?.isAwaitingApproval) {
325 call.isAwaitingApproval = false
326 $.clock.after(0, () => void publish($, live))
327 }
328
329 return next(e)
330 })
331
332 on('agent.spawn', async ($, e, next) => {
333 const result = await next(e)
334
335 if (result.agentId !== undefined) {
336 const startMs = await $.clock.now()
337 const name = e.description || e.name || 'Agent'
338
339 live.agentNames.set(result.agentId, name)
340 live.agents.set(result.agentId, {
341 name,
342 label: 'Getting started',
343 startMs,
344 activeMs: startMs,
345 toolUseId: e.tool_use_id,
346 isBackground: e.background,
347 })
348 keepTicking($, live)
349 await publish($, live)
350 }
351
352 return result
353 })
354
355 on('classic.SubagentStop', async ($, e, next) => {
356 await finish($, live, e.agent_id, 'ok')
357
358 return next(e)
359 })
360
361 on('classic.PreCompact', async ($, e, next) => {
362 await enter($, live, 'compacting')
363 await publish($, live)
364
365 return next(e)
366 })
367
368 on('classic.PostCompact', async ($, e, next) => {
369 const durationMs = (await $.clock.now()) - live.phaseStartMs
370
371 live.phase = live.turnStartMs === null ? 'idle' : 'requesting'
372 await remember($, { kind: 'compact', label: 'Compacted the conversation', durationMs, outcome: 'ok' })
373 await publish($, live)
374
375 return next(e)
376 })
377
378 on('turn.complete', async ($, e, next) => {
379 if (e.agentId !== undefined) {
380 await finish($, live, e.agentId, outcomeOf(e.reason))
381
382 return next(e)
383 }
384
385 if (live.turnStartMs === null) {
386 return next(e)
387 }
388
389 const durationMs = (await $.clock.now()) - live.turnStartMs
390 const took = durationOf(durationMs)
391
392 const [label, outcome]: [string, ActivityOutcome] =
393 e.reason === 'aborted'
394 ? [`interrupted after ${took}`, 'interrupted']
395 : e.reason === 'error'
396 ? [`stopped on an error after ${took}`, 'error']
397 : e.reason === 'refusal'
398 ? ['declined the request', 'denied']
399 : [`done in ${took}, ${plural(live.turnActions, 'action')}`, 'ok']
400
401 await enter($, live, 'idle')
402 await remember($, { kind: 'end', label: capitalized(label), durationMs, outcome })
403
404 live.lastTurn = label
405 live.turnStartMs = null
406 live.calls.clear()
407 await pulseBeat($, live, 'done', outcome)
408
409 keepTicking($, live)
410 await publish($, live)
411
412 return next(e)
413 })
414
415 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
416 if (e.props.hasSurvey) {
417 return next(e)
418 }
419
420 // The band is one site for every plugin: what the plugins beneath draw
421 // stays, under the box, so another mod's band is never hidden.
422 const below = await next(e)
423 const view = await viewOf($, look, e.props.maxRows, e.props.bodyColumns)
424
425 if (e.surface === 'terminal') {
426 const ui = $.ui.resolve(e)
427 const { Client } = ui
428 const pulse: PulseOf = (key, props, width) => (
429 <Client key={key} module="./pulse.tsx" props={props} width={width} height={1} />
430 )
431
432 return drawTerminal(ui, view, pulse, below)
433 }
434
435 return drawDesktop($.ui.resolve(e), view, below)
436 })
437
438 // The question dialog takes the prompt's place and covers the band, so the
439 // box draws a still copy of itself above the dialog while it is open.
440 on('ui.render', { component: 'AskUserQuestion' }, async ($, e, next) => {
441 const dialog = await next(e)
442
443 return drawQuestion($.ui.resolve(e), await viewOf($, look, 12, 40), dialog)
444 })
445}
446
447/** Everything a drawing reads, at the size its site gives it. */
448async function viewOf(
449 $: EngineInterface,
450 look: Pick<View, 'level' | 'palette'>,
451 maxRows: number,
452 bodyColumns: number,
453): Promise<View> {
454 return {
455 headline: await read($, now),
456 entries: await read($, history),
457 working: await read($, team),
458 timeline: await read($, timeline),
459 beat: await read($, beat),
460 isOpen: await read($, isExpanded),
461 nowMs: await $.clock.now(),
462 maxRows,
463 bodyColumns,
464 ...look,
465 onToggle: () => void update($, isExpanded, open => !open),
466 }
467}
468
469/** The headline as the live view has it. */
470function current(live: Live): ActivityNow {
471 if (live.phase === 'compacting') {
472 return { phase: 'compacting', label: 'Compacting the conversation', sinceMs: live.phaseStartMs }
473 }
474
475 const open = [...live.calls.entries()]
476 const [newestId, newest] = open.at(-1) ?? []
477
478 if (newestId !== undefined && newest !== undefined) {
479 const more = open.length > 1 ? ` (+${open.length - 1} more)` : ''
480
481 if (newest.isAwaitingApproval) {
482 return {
483 phase: 'approval',
484 label: `Waiting for your approval: ${newest.label}${more}`,
485 sinceMs: newest.startMs,
486 tool: newest.tool,
487 }
488 }
489
490 if (newest.tool === 'AskUserQuestion') {
491 return { phase: 'question', label: newest.label, sinceMs: newest.startMs }
492 }
493
494 const inner = isAgentTool(newest.tool) ? agentUnder(live, newestId)?.label : undefined
495
496 return inner === undefined
497 ? { phase: 'tool', label: `${newest.label}${more}`, sinceMs: newest.startMs, tool: newest.tool }
498 : { phase: 'agent', label: `${newest.label} › ${inner}${more}`, sinceMs: newest.startMs, tool: newest.tool }
499 }
500
501 if (live.phase === 'idle' && live.agents.size > 0) {
502 // Between turns, background agents may still be at work.
503 const working = [...live.agents.values()]
504 const sinceMs = Math.min(...working.map(agent => agent.startMs))
505 const busiest = working.reduce((a, b) => (b.activeMs > a.activeMs ? b : a))
506
507 return {
508 phase: 'agent',
509 label: working.length === 1
510 ? `${busiest.name} › ${busiest.label}`
511 : `${plural(working.length, 'agent')} working`,
512 sinceMs,
513 }
514 }
515
516 const sinceMs = live.phaseStartMs
517
518 switch (live.phase) {
519 case 'requesting':
520 return {
521 phase: 'requesting',
522 label: live.isFirstRequest
523 ? 'Reading your prompt'
524 : live.resultsToReview > 0
525 ? `Reviewing the results of ${plural(live.resultsToReview, 'action')}`
526 : 'Waiting for the model',
527 sinceMs,
528 }
529 case 'thinking': {
530 // With no thought text to quote, the last action stands, the dot
531 // turned to thinking's color; before any, the prompt is what it reads.
532 const snippet = thoughtOf(live.thought, MAX_THOUGHT_CHARS)
533 const label = snippet ? `Thinking: ${snippet}` : standingLabel(live)
534
535 return { phase: 'thinking', label, sinceMs }
536 }
537 case 'writing':
538 return {
539 phase: 'writing',
540 label: `Writing the reply · ${plural(live.replyWords, 'word')}`,
541 sinceMs,
542 ...meterField(meterOf(live.replyWords, FULL_REPLY_WORDS)),
543 }
544 case 'composing': {
545 // A call is named once its input says what it does: a file tool by
546 // its path, a command by its description, which streams after the
547 // command itself. Until then the last action stands.
548 const { composing } = live
549 const args = composing ? partialArgsOf(composing.head) : {}
550 const isDescribed = composing !== null && (isShellTool(composing.tool)
551 ? typeof args['description'] === 'string'
552 : Object.keys(args).length > 0)
553
554 if (!composing || !isDescribed) {
555 return { phase: 'composing', label: standingLabel(live), sinceMs }
556 }
557
558 const size = composing.chars >= LARGE_INPUT_CHARS ? ` · ${sizeOf(composing.chars)}` : ''
559
560 return {
561 phase: 'composing',
562 label: `${activityOf(composing.tool, args)}${size}`,
563 sinceMs,
564 tool: composing.tool,
565 ...meterField(meterOf(composing.chars, FULL_INPUT_CHARS)),
566 }
567 }
568 case 'idle':
569 return live.lastTurn === null
570 ? IDLE
571 : { ...IDLE, label: `Idle · last turn ${live.lastTurn}` }
572 }
573}
574
575/** A meter field for the headline, left out while there is nothing to meter. */
576function meterField(meter: string): { meter?: string } {
577 return meter === '' ? {} : { meter }
578}
579
580/**
581 * Writes the headline. A streaming update (`isUrgent` false) lands at most
582 * every STREAM_THROTTLE_MS, the last one held on a timer.
583 */
584async function publish($: EngineInterface, live: Live, isUrgent = true): Promise<void> {
585 const nowMs = await $.clock.now()
586
587 if (!isUrgent && nowMs - live.lastPublishMs < STREAM_THROTTLE_MS) {
588 live.trailing ??= $.clock.after(STREAM_THROTTLE_MS, () => {
589 live.trailing = null
590 void publish($, live)
591 })
592
593 return
594 }
595
596 live.lastPublishMs = nowMs
597 const headline = current(live)
598 const working = [...live.agents.values()].map(agent => ({
599 name: agent.name,
600 label: agent.label,
601 sinceMs: agent.startMs,
602 }))
603
604 await update($, now, () => headline)
605 await update($, team, () => working)
606 await follows($, live, headline, nowMs)
607 keepBreathing($, live, headline)
608}
609
610/**
611 * Carries the headline's phase into the turn's timeline: a new phase closes
612 * the running segment and opens its own; the turn's end closes the last.
613 */
614async function follows($: EngineInterface, live: Live, headline: ActivityNow, nowMs: number): Promise<void> {
615 const isTurn = live.turnStartMs !== null
616
617 await update($, timeline, line => {
618 const { open } = line
619
620 if (isTurn ? open?.phase === headline.phase : open === null) {
621 return line
622 }
623
624 const segments = open === null
625 ? line.segments
626 : [...line.segments, { phase: open.phase, ms: Math.max(0, nowMs - open.sinceMs) }].slice(-MAX_SEGMENTS)
627
628 return { segments, open: isTurn ? { phase: headline.phase, sinceMs: nowMs } : null }
629 })
630}
631
632/**
633 * Redraws the box eight times a second while Claude waits on the person at
634 * full animation, so its border breathes; stops when the wait ends.
635 */
636function keepBreathing($: EngineInterface, live: Live, headline: ActivityNow): void {
637 const isWaiting = live.level === 'full' && (headline.phase === 'approval' || headline.phase === 'question')
638
639 if (isWaiting && live.breath === null) {
640 live.breath = $.clock.every(BREATH_TICK_MS, () => $.ui.invalidate('ui.render'))
641 } else if (!isWaiting && live.breath !== null) {
642 live.breath.cancel()
643 live.breath = null
644 }
645}
646
647/**
648 * Marks a moment worth a flourish: a call's end flashes the border, a turn's
649 * end sparkles. The flash is redrawn away once it has shown.
650 */
651async function pulseBeat(
652 $: EngineInterface,
653 live: Live,
654 kind: ActivityBeat['kind'],
655 outcome: ActivityOutcome,
656): Promise<void> {
657 if (live.level === 'off') {
658 return
659 }
660
661 live.beats += 1
662 const beatOf: ActivityBeat = { id: live.beats, kind, outcome, atMs: await $.clock.now() }
663
664 await update($, beat, () => beatOf)
665
666 if (kind === 'flash') {
667 $.clock.after(FLASH_MS, () => $.ui.invalidate('ui.render'))
668 }
669}
670
671/** The agent at work under `agentId`, taken up if its spawn came before a reload. */
672async function agentOf($: EngineInterface, live: Live, agentId: string): Promise<Agent> {
673 const known = live.agents.get(agentId)
674
675 if (known) {
676 return known
677 }
678
679 const startMs = await $.clock.now()
680 const agent: Agent = {
681 name: live.agentNames.get(agentId) ?? 'Agent',
682 label: 'Getting started',
683 startMs,
684 activeMs: startMs,
685 toolUseId: null,
686 isBackground: true,
687 }
688
689 live.agents.set(agentId, agent)
690 keepTicking($, live)
691
692 return agent
693}
694
695/**
696 * Lets an agent go. A background agent's run is recorded in the history; a
697 * foreground one's is its Agent call's row.
698 */
699async function finish(
700 $: EngineInterface,
701 live: Live,
702 agentId: string,
703 outcome: ActivityOutcome,
704): Promise<void> {
705 const agent = live.agents.get(agentId)
706
707 if (!agent) {
708 return
709 }
710
711 live.agents.delete(agentId)
712
713 if (agent.isBackground) {
714 await remember($, {
715 kind: 'tool',
716 label: `Agent: ${agent.name}`,
717 durationMs: (await $.clock.now()) - agent.startMs,
718 outcome,
719 tool: 'Agent',
720 })
721 }
722
723 keepTicking($, live)
724 await publish($, live)
725}
726
727/**
728 * Names agents first met by their calls, and lets go of agents the engine
729 * lists as no longer running, in case their stop never reached the box.
730 */
731async function sweep($: EngineInterface, live: Live): Promise<void> {
732 if (live.agents.size === 0 || live.isSweeping) {
733 return
734 }
735
736 live.isSweeping = true
737
738 try {
739 await sweepListed($, live, await $.agent.list())
740 } catch {
741 // The list is a backstop; the box keeps going without it.
742 } finally {
743 live.isSweeping = false
744 }
745}
746
747async function sweepListed($: EngineInterface, live: Live, listed: readonly AgentInfo[]): Promise<void> {
748 const statuses = new Map(listed.map(info => [info.id, info.status]))
749 let isRenamed = false
750
751 for (const [agentId, agent] of [...live.agents.entries()]) {
752 const status = statuses.get(agentId)
753
754 // An agent first met by its calls is named once the engine lists it.
755 if (!live.agentNames.has(agentId)) {
756 const handle = listed.find(info => info.id === agentId)?.name
757 const described = handle === undefined ? undefined : live.described.get(handle)
758
759 if (described !== undefined) {
760 live.agentNames.set(agentId, described)
761 }
762
763 const name = described ?? handle
764
765 if (name !== undefined && name !== agent.name) {
766 agent.name = name
767 isRenamed = true
768 }
769 }
770
771 if (status !== undefined && status !== 'running') {
772 await finish($, live, agentId, status === 'completed' ? 'ok' : status === 'failed' ? 'error' : 'interrupted')
773 }
774 }
775
776 if (isRenamed) {
777 await publish($, live)
778 }
779}
780
781/**
782 * Keeps the elapsed time ticking while a turn runs or an agent works, and
783 * stops it once neither does.
784 */
785function keepTicking($: EngineInterface, live: Live): void {
786 const isBusy = live.turnStartMs !== null || live.agents.size > 0
787
788 if (isBusy && live.ticker === null) {
789 live.ticker = $.clock.every(TICK_MS, () => {
790 $.ui.invalidate('ui.render')
791 void sweep($, live)
792 })
793 } else if (!isBusy && live.ticker !== null) {
794 live.ticker.cancel()
795 live.ticker = null
796 }
797}
798
799async function remember($: EngineInterface, entry: ActivityEntry): Promise<void> {
800 await update($, history, entries => [...entries, entry].slice(-MAX_HISTORY))
801}
802
803/** Enters a model phase, recording the thinking or reply block it closes. */
804async function enter($: EngineInterface, live: Live, next: ModelPhase): Promise<void> {
805 if (next === live.phase) {
806 return
807 }
808
809 const nowMs = await $.clock.now()
810 const durationMs = nowMs - live.phaseStartMs
811
812 if (live.phase === 'thinking') {
813 const words = live.thoughtWords
814
815 await remember($, {
816 kind: 'thought',
817 label: words > 0 ? `Thought (${plural(words, 'word')})` : 'Thought',
818 durationMs,
819 outcome: 'ok',
820 })
821 }
822
823 if (live.phase === 'writing' && live.replyWords > 0) {
824 await remember($, {
825 kind: 'reply',
826 label: `Wrote the reply (${plural(live.replyWords, 'word')})`,
827 durationMs,
828 outcome: 'ok',
829 })
830 }
831
832 if (next === 'thinking') {
833 live.thought = ''
834 live.thoughtWords = 0
835 live.isThoughtInWord = false
836 }
837
838 if (next === 'writing') {
839 live.replyWords = 0
840 live.isReplyInWord = false
841 }
842
843 live.phase = next
844 live.phaseStartMs = nowMs
845}
846
847/** Follows one chunk of the main loop's response. */
848async function follow($: EngineInterface, live: Live, chunk: TurnStepChunk): Promise<void> {
849 switch (chunk.kind) {
850 case 'thinking': {
851 const isNew = live.phase !== 'thinking'
852
853 await enter($, live, 'thinking')
854 live.resultsToReview = 0
855 const { added, isInWord } = wordsAdded(chunk.text, live.isThoughtInWord)
856
857 live.thought = (live.thought + chunk.text).slice(-MAX_THOUGHT_BUFFER)
858 live.thoughtWords += added
859 live.isThoughtInWord = isInWord
860 await publish($, live, isNew)
861
862 return
863 }
864 case 'text': {
865 const isNew = live.phase !== 'writing'
866
867 await enter($, live, 'writing')
868 live.resultsToReview = 0
869 const { added, isInWord } = wordsAdded(chunk.text, live.isReplyInWord)
870
871 live.replyWords += added
872 live.isReplyInWord = isInWord
873 await publish($, live, isNew)
874
875 return
876 }
877 case 'tool':
878 await enter($, live, 'composing')
879 live.resultsToReview = 0
880 live.composing = { tool: chunk.name, head: '', chars: 0 }
881 await publish($, live)
882
883 return
884 case 'input': {
885 const { composing } = live
886
887 if (composing) {
888 composing.chars += chunk.json.length
889
890 if (composing.head.length < MAX_INPUT_HEAD) {
891 composing.head += chunk.json
892 }
893
894 await publish($, live, false)
895 }
896
897 return
898 }
899 }
900}
901
902/**
903 * What the box keeps saying while Claude thinks or writes a call it cannot
904 * name yet: the turn's last action, or the prompt before there is one.
905 */
906function standingLabel(live: Live): string {
907 return live.lastAction ?? 'Reading your prompt'
908}
909
910/**
911 * Names a background agent by the Agent call that launched it: the call's
912 * short `description`, keyed by the id its result carries (the result's own
913 * `description` can hold the whole prompt). Its own calls may already have
914 * shown it.
915 */
916async function launched(
917 $: EngineInterface,
918 live: Live,
919 result: unknown,
920 asked: unknown,
921): Promise<void> {
922 if (typeof result !== 'object' || result === null) {
923 return
924 }
925
926 const { agentId, description, status } = result as Record<string, unknown>
927
928 if (typeof agentId !== 'string' || status !== 'async_launched') {
929 return
930 }
931
932 const name = [asked, description].find(
933 (text): text is string => typeof text === 'string' && oneLine(text) !== '',
934 )
935
936 if (name === undefined) {
937 return
938 }
939
940 const agent = await agentOf($, live, agentId)
941
942 live.agentNames.set(agentId, name)
943 agent.name = name
944 await publish($, live)
945}
946
947/** The agent an Agent call started, or the one that last did something. */
948function agentUnder(live: Live, toolUseId: string): Agent | undefined {
949 const working = [...live.agents.values()]
950
951 return working.find(agent => agent.toolUseId === toolUseId)
952 ?? working.reduce<Agent | undefined>((a, b) => (a === undefined || b.activeMs > a.activeMs ? b : a), undefined)
953}
954
955function outcomeOf(reason: TurnCompleteReason): ActivityOutcome {
956 return reason === 'aborted' ? 'interrupted' : reason === 'error' ? 'error' : reason === 'refusal' ? 'denied' : 'ok'
957}
958
959function isShellTool(tool: string): boolean {
960 return tool === 'Bash' || tool === 'PowerShell'
961}
962
963function isAgentTool(tool: string): boolean {
964 return tool === 'Agent' || tool === 'Task'
965}
966
967function capitalized(text: string): string {
968 return text.charAt(0).toUpperCase() + text.slice(1)
969}
970hooks/activity-of.ts 97 lines1import { clip, oneLine } from './text'
2
3const MAX_DETAIL_CHARS = 60
4
5/**
6 * Says in a few words what a tool call is doing, for Agent Pulse.
7 *
8 * @param tool the tool's name; a string, as the declared names are only the
9 * tools of the build that wrote the types (Grep and Glob are on some only)
10 * @param args the call's arguments, whole or as far as they have streamed
11 * @returns a short label such as `Reading register.tsx`
12 */
13export function activityOf(tool: string, args: Record<string, unknown>): string {
14 const arg = (key: string): string => {
15 const value = args[key]
16
17 return typeof value === 'string' ? clip(oneLine(value), MAX_DETAIL_CHARS) : ''
18 }
19
20 const file = (key: string): string => baseName(arg(key))
21
22 switch (tool) {
23 case 'Bash':
24 case 'PowerShell':
25 return arg('description') || `Running ${arg('command')}`
26 case 'Read':
27 return `Reading ${file('file_path')}`
28 case 'Edit':
29 return `Editing ${file('file_path')}`
30 case 'Write':
31 return `Writing ${file('file_path')}`
32 case 'NotebookEdit':
33 return `Editing ${file('notebook_path')}`
34 case 'Grep':
35 return `Searching for "${arg('pattern')}"`
36 case 'Glob':
37 return `Finding files ${arg('pattern')}`
38 case 'WebFetch':
39 return `Fetching ${hostOf(arg('url'))}`
40 case 'WebSearch':
41 return `Searching the web for "${arg('query')}"`
42 case 'Agent':
43 case 'Task':
44 return `Running an agent: ${arg('description')}`
45 case 'TodoWrite':
46 return 'Updating the todo list'
47 case 'AskUserQuestion':
48 return 'Waiting for your answer'
49 case 'Skill':
50 return `Using the ${arg('skill')} skill`
51 }
52
53 if (tool.startsWith('mcp__')) {
54 const [, server = '', name = ''] = tool.split('__')
55
56 return `Using ${server}: ${name}`
57 }
58
59 return `Using ${tool}`
60}
61
62/**
63 * The string arguments a tool call's input has streamed so far, read from
64 * its partial JSON: enough to name the file or command before it is whole.
65 */
66export function partialArgsOf(json: string): Record<string, unknown> {
67 const args: Record<string, unknown> = {}
68
69 for (const match of json.matchAll(/"([a-z_]+)"\s*:\s*"((?:[^"\\]|\\.)*)/g)) {
70 const [, key = '', raw = ''] = match
71
72 args[key] ??= unescaped(raw)
73 }
74
75 return args
76}
77
78function unescaped(raw: string): string {
79 try {
80 return JSON.parse(`"${raw}"`) as string
81 } catch {
82 return raw
83 }
84}
85
86function baseName(path: string): string {
87 return path.split(/[\\/]/).pop() || path
88}
89
90function hostOf(url: string): string {
91 try {
92 return new URL(url).host
93 } catch {
94 return url
95 }
96}
97hooks/draw.tsx 559 lines1import type { Elements, RenderElement } from 'claude-code'
2
3import type { ActivityAgent, ActivityBeat, ActivityEntry, ActivityNow, ActivityOutcome, ActivityPhase, ActivityTimeline } from '../types'
4import { barOf, SPINNERS, toolGlyphOf } from './glyphs'
5import { barSvg, jellySvg, stripSvg } from './jelly'
6import type { Level, Palette } from './palette'
7import { agentColorOf, heatOf, mix, shadeOf, shimmerOf } from './palette'
8import type { PulseProps } from './pulse'
9import { durationOf, plural, printable } from './text'
10
11const MAX_HISTORY_ROWS = 12
12const MAX_LABEL_CHARS = 120
13const MAX_CARD_CHARS = 400
14const CARD_FROM_CHARS = 40
15const MAX_AGENT_NAME_CHARS = 40
16const MAX_AGENT_ROWS = 6
17const FLASH_MS = 360
18const SPARKLE_MS = 2000
19const BREATH_MS = 1400
20const HISTORY_BAR_CELLS = 6
21/** Above the question dialog every line counts toward its 12 rows, a row per 40 columns. */
22const QUESTION_LABEL_CHARS = 38
23const QUESTION_AGENT_ROWS = 3
24
25/** Everything a drawing reads, gathered once by the `AbovePrompt` hook. */
26export type View = {
27 headline: ActivityNow
28 entries: readonly ActivityEntry[]
29 working: readonly ActivityAgent[]
30 timeline: ActivityTimeline
31 beat: ActivityBeat | null
32 isOpen: boolean
33 nowMs: number
34 maxRows: number
35 bodyColumns: number
36 level: Level
37 palette: Palette
38 onToggle: () => void
39}
40
41/** Draws one of `pulse.tsx`'s animations: made in the hooks module, which names it. */
42export type PulseOf = (key: string, props: PulseProps, width: number) => RenderElement
43
44type WebElements = Pick<Elements['desktop'], 'Box' | 'Text' | 'Button' | 'Svg'>
45
46const OUTCOME_MARKS: Record<ActivityOutcome, string> = {
47 ok: '✓',
48 error: '✗',
49 denied: '⊘',
50 interrupted: '■',
51}
52
53/** A kind's mark, in its phase's color, or the text's color with none. */
54const KIND_MARKS: Partial<Record<ActivityEntry['kind'], { mark: string; phase: ActivityPhase | null }>> = {
55 turn: { mark: '›', phase: null },
56 reply: { mark: '✎', phase: 'writing' },
57 compact: { mark: '⇣', phase: 'compacting' },
58}
59
60/** What both surfaces lay out the same way: which agents and rows show. */
61function layoutOf(v: View) {
62 // One agent the headline names; more, or one beside the main loop's
63 // work, get a row each.
64 const isTeamListed = v.working.length > 1 || (v.working.length === 1 && v.headline.phase !== 'agent')
65 const listed = isTeamListed ? v.working.slice(-MAX_AGENT_ROWS) : []
66 const unlisted = isTeamListed ? v.working.length - listed.length : 0
67 const teamRows = listed.length + (unlisted > 0 ? 1 : 0)
68 const strip = stripOf(v)
69 const rows = Math.min(MAX_HISTORY_ROWS, Math.max(1, v.maxRows - 4 - teamRows - (strip.length > 0 ? 1 : 0)))
70 const shown = v.entries.slice(-rows)
71 const hidden = v.entries.length - shown.length
72 const maxMs = Math.max(1, ...shown.filter(hasBar).map(entry => entry.durationMs ?? 0))
73
74 return { listed, unlisted, shown, hidden, maxMs, strip }
75}
76
77/** The turn's segments with the running one closed at now; none when idle and closed. */
78function stripOf(v: View): { phase: ActivityPhase; ms: number; isOpen: boolean }[] {
79 const isWorking = v.headline.phase !== 'idle'
80
81 if (!isWorking && !v.isOpen) {
82 return []
83 }
84
85 const segments = v.timeline.segments.map(s => ({ ...s, isOpen: false }))
86 const { open } = v.timeline
87
88 if (open !== null) {
89 segments.push({ phase: open.phase, ms: Math.max(1, v.nowMs - open.sinceMs), isOpen: true })
90 }
91
92 return segments
93}
94
95function hasBar(entry: ActivityEntry): boolean {
96 return entry.durationMs !== null && entry.kind !== 'turn' && entry.kind !== 'end'
97}
98
99function markOf(v: View, entry: ActivityEntry): { mark: string; color: string } {
100 if (entry.kind === 'thought') {
101 return { mark: '∴', color: v.palette.phase.thinking }
102 }
103
104 const kind = KIND_MARKS[entry.kind]
105
106 if (kind !== undefined) {
107 return { mark: kind.mark, color: kind.phase === null ? 'text' : v.palette.phase[kind.phase] }
108 }
109
110 return { mark: OUTCOME_MARKS[entry.outcome], color: v.palette.outcome[entry.outcome] }
111}
112
113/** The border's color: a call's flash, the breath of a wait, or the phase. */
114function borderOf(v: View): string {
115 const { phase, sinceMs } = v.headline
116 const { beat, palette, level, nowMs } = v
117
118 if (level !== 'off' && beat?.kind === 'flash' && nowMs - beat.atMs < FLASH_MS) {
119 return palette.outcomeHex[beat.outcome]
120 }
121
122 if (level === 'full' && (phase === 'approval' || phase === 'question')) {
123 const wave = (Math.sin(((nowMs - sinceMs) / BREATH_MS) * 2 * Math.PI) + 1) / 2
124
125 // From a dimmed glow up to the bright core: a hue shift as well as a breath.
126 return mix(mix(palette.glow[phase], '#000000', 0.6), palette.hex[phase], wave)
127 }
128
129 return phase === 'idle' ? 'inactive' : palette.phase[phase]
130}
131
132function elapsedOf(v: View): { text: string; color: string | undefined } {
133 if (v.headline.phase === 'idle') {
134 return { text: '', color: undefined }
135 }
136
137 const ms = v.nowMs - v.headline.sinceMs
138
139 return { text: ` · ${durationOf(ms)}`, color: heatOf(v.palette, ms) }
140}
141
142/** The status glyph and the sparkle, for the terminal. */
143function terminalMarks(v: View, Text: Elements['terminal']['Text'], pulse: PulseOf) {
144 const { phase } = v.headline
145 const isWorking = phase !== 'idle'
146 const color = v.palette.phase[phase]
147 const spinner = SPINNERS[phase]
148
149 const glyph = v.level === 'off' || !isWorking
150 ? <Text color={color}>{isWorking ? '●' : '○'}</Text>
151 : pulse(`glyph-${phase}`, { kind: 'spin', frames: [...spinner.frames], ms: spinner.ms, colors: shimmerOf(v.palette, phase) }, 1)
152
153 const { beat } = v
154 const sparkle = v.level === 'full' && beat?.kind === 'done' && v.nowMs - beat.atMs < SPARKLE_MS
155 ? [pulse(`sparkle-${beat.id}`, { kind: 'sparkle', colors: [...v.palette.sparkle] }, 4)]
156 : []
157
158 return { glyph, sparkle }
159}
160
161/**
162 * The box on the terminal: block characters for the charts, and `Client`s
163 * of fixed width for what moves.
164 */
165export function drawTerminal(ui: Elements['terminal'], v: View, pulse: PulseOf, below: RenderElement): RenderElement {
166 const { Box, Text, Button } = ui
167 const { headline, palette } = v
168 const { listed, unlisted, shown, hidden, maxMs, strip } = layoutOf(v)
169 const { glyph, sparkle } = terminalMarks(v, Text, pulse)
170 const elapsed = elapsedOf(v)
171 const label = printable(headline.label, MAX_LABEL_CHARS)
172 const toolGlyph = toolGlyphOf(headline.tool)
173
174 const stripRow = strip.length > 0
175 ? [
176 <Box key="strip" flexDirection="row">
177 <Text dimColor>{' '}</Text>
178 {stripCells(strip, Math.max(10, Math.min(48, v.bodyColumns - 12))).flatMap((run, i) => stripRun(Text, palette, run, i))}
179 </Box>,
180 ]
181 : []
182
183 const agentRows = listed.map((agent, i) => {
184 const color = agentColorOf(palette, agent.name)
185 const isLast = i === listed.length - 1 && unlisted === 0
186 const mark = v.level === 'off'
187 ? <Text color={color}>◆</Text>
188 : pulse(`agent-glyph-${i}`, { kind: 'spin', frames: [...SPINNERS.agent.frames], ms: SPINNERS.agent.ms, colors: [color] }, 1)
189
190 return (
191 <Box key={`agent-${i}`} flexDirection="row">
192 <Box flexShrink={0}>
193 <Text dimColor>{isLast ? '└─ ' : '├─ '}</Text>
194 {mark}
195 <Text> </Text>
196 </Box>
197 <Text bold color={color} wrap="truncate-end">{printable(agent.name, MAX_AGENT_NAME_CHARS)}</Text>
198 <Text wrap="truncate-end">{` › ${printable(agent.label, MAX_LABEL_CHARS)}`}</Text>
199 <Box flexShrink={0}>
200 <Text color={heatOf(palette, v.nowMs - agent.sinceMs)} dimColor={heatOf(palette, v.nowMs - agent.sinceMs) === undefined}>
201 {` ${durationOf(v.nowMs - agent.sinceMs)}`}
202 </Text>
203 </Box>
204 </Box>
205 )
206 })
207
208 const moreAgents = unlisted > 0 ? [<Text dimColor>{`└─ … ${plural(unlisted, 'more agent')}`}</Text>] : []
209 const teamBox = agentRows.length > 0
210 ? [<Box key="agents" flexDirection="column">{agentRows}{moreAgents}</Box>]
211 : []
212
213 const historyRows = shown.map((entry, i) => {
214 const { mark, color } = markOf(v, entry)
215 const isQuiet = entry.kind === 'thought' || entry.kind === 'end'
216 const took = entry.durationMs === null ? '' : ` ${durationOf(entry.durationMs)}`
217 const bar = hasBar(entry) ? ` ${barOf((entry.durationMs ?? 0) / maxMs, HISTORY_BAR_CELLS)}` : ''
218 const glyphOfTool = toolGlyphOf(entry.tool)
219 const full = printable(entry.label, MAX_CARD_CHARS)
220
221 return (
222 <Box key={`row-${i}`} flexDirection="row" hover={{ scope: `row-${i}` }}>
223 <Box flexShrink={0}>
224 <Text color={color}>{`${mark} `}</Text>
225 {glyphOfTool === '' ? [] : [<Text color={palette.phase.tool}>{`${glyphOfTool} `}</Text>]}
226 </Box>
227 <Text bold={entry.kind === 'turn'} dimColor={isQuiet} wrap="truncate-end">
228 {printable(entry.label, MAX_LABEL_CHARS)}
229 </Text>
230 <Box flexShrink={0}>
231 <Text dimColor>{took}</Text>
232 <Text color={color} dimColor>{bar}</Text>
233 </Box>
234 {full.length > CARD_FROM_CHARS ? [card(Box, Text, `row-${i}`, full, color)] : []}
235 </Box>
236 )
237 })
238
239 const earlier = hidden > 0 ? [<Text dimColor>{`… ${hidden} earlier`}</Text>] : []
240 const empty = v.entries.length === 0 ? [<Text dimColor>No actions yet</Text>] : []
241 const body = v.isOpen
242 ? [<Box key="history" flexDirection="column" marginTop={1}>{earlier}{historyRows}{empty}</Box>]
243 : []
244
245 const fullLabel = printable(headline.label, MAX_CARD_CHARS)
246
247 return (
248 <Box flexDirection="column">
249 <Box flexDirection="column" borderStyle="round" borderColor={borderOf(v)} paddingX={1} alignSelf="flex-start">
250 <Box key="activity" flexDirection="row" hover={{ scope: 'headline' }}>
251 <Button key="toggle" plain label={v.isOpen ? '▾' : '▸'} onPress={v.onToggle} />
252 {/* On a narrow screen only the label gives way: the rest would wrap. */}
253 <Box flexShrink={0}>
254 <Text> </Text>
255 {glyph}
256 <Text> </Text>
257 {toolGlyph === '' ? [] : [<Text color={palette.phase[headline.phase]}>{`${toolGlyph} `}</Text>]}
258 </Box>
259 <Text wrap="truncate-end">{label}</Text>
260 <Box flexShrink={0}>
261 {headline.meter === undefined ? [] : [<Text color={palette.phase[headline.phase]}>{` ${headline.meter}`}</Text>]}
262 <Text color={elapsed.color} dimColor={elapsed.color === undefined}>{elapsed.text}</Text>
263 {sparkle}
264 </Box>
265 </Box>
266 {fullLabel.length > CARD_FROM_CHARS ? [card(Box, Text, 'headline', fullLabel, borderOf(v))] : []}
267 {stripRow}
268 {teamBox}
269 {body}
270 </Box>
271 {below}
272 </Box>
273 )
274}
275
276/**
277 * The whole of a long label, shown while the pointer rests on its row: an
278 * absolute Box, so its showing moves nothing.
279 */
280function card(
281 Box: Elements['terminal']['Box'] | WebElements['Box'],
282 Text: Elements['terminal']['Text'] | WebElements['Text'],
283 scope: string,
284 text: string,
285 color: string,
286): RenderElement {
287 return (
288 <Box
289 key={`card-${scope}`}
290 position="absolute"
291 top={1}
292 left={2}
293 display="none"
294 hover={{ scope, display: 'flex' }}
295 borderStyle="round"
296 borderColor={color}
297 backgroundColor="inverseText"
298 paddingX={1}
299 >
300 <Text>{text}</Text>
301 </Box>
302 )
303}
304
305/**
306 * One run of the terminal's strip: a `Text` for a flat palette, or a cell
307 * each shading from the phase's core to its glow.
308 */
309function stripRun(
310 Text: Elements['terminal']['Text'],
311 palette: Palette,
312 run: { phase: ActivityPhase; cells: number },
313 i: number,
314): RenderElement[] {
315 if (palette.hex[run.phase] === palette.glow[run.phase]) {
316 return [<Text key={`strip-${i}`} color={palette.phase[run.phase]}>{'━'.repeat(run.cells)}</Text>]
317 }
318
319 return Array.from({ length: run.cells }, (_, cell) => (
320 <Text key={`strip-${i}-${cell}`} color={shadeOf(palette, run.phase, run.cells === 1 ? 0 : cell / (run.cells - 1))}>━</Text>
321 ))
322}
323
324/**
325 * The strip as runs of cells: each cell takes the phase at its middle in
326 * time, and neighbours of one phase join into one run.
327 */
328function stripCells(
329 segments: readonly { phase: ActivityPhase; ms: number }[],
330 width: number,
331): { phase: ActivityPhase; cells: number }[] {
332 const total = segments.reduce((sum, s) => sum + s.ms, 0)
333 const runs: { phase: ActivityPhase; cells: number }[] = []
334
335 if (total <= 0) {
336 return runs
337 }
338
339 for (let cell = 0; cell < width; cell++) {
340 const at = ((cell + 0.5) / width) * total
341 let passed = 0
342 const segment = segments.find(s => (passed += s.ms) >= at) ?? segments.at(-1)
343
344 if (segment === undefined) {
345 continue
346 }
347
348 const last = runs.at(-1)
349
350 if (last?.phase === segment.phase) {
351 last.cells += 1
352 } else {
353 runs.push({ phase: segment.phase, cells: 1 })
354 }
355 }
356
357 return runs
358}
359
360/**
361 * The box on the desktop (and every surface that draws `Svg`): the jellyfish
362 * beside the headline, and SVG for the strip and the bars.
363 */
364export function drawDesktop(ui: WebElements, v: View, below: RenderElement): RenderElement {
365 const { Box, Text, Button, Svg } = ui
366 const { headline, palette, beat } = v
367 const { phase } = headline
368 const { listed, unlisted, shown, hidden, maxMs, strip } = layoutOf(v)
369 const elapsed = elapsedOf(v)
370 const toolGlyph = toolGlyphOf(headline.tool)
371 const width = Math.max(140, Math.min(480, v.bodyColumns * 8 - 200))
372
373 // A beat belongs to the phase it happened in, so its one-shot plays once.
374 const halo = beat?.kind === 'flash' && beat.atMs >= headline.sinceMs
375 ? { id: beat.id, color: palette.outcomeHex[beat.outcome] }
376 : null
377 const sparkle = beat?.kind === 'done' && phase === 'idle'
378 ? { id: beat.id, color: palette.sparkle[3] ?? palette.hex.writing }
379 : null
380
381 const jelly = jellySvg({ phase, level: v.level, color: palette.hex[phase], glow: palette.glow[phase], halo, sparkle, size: 44 })
382
383 const stripRow = strip.length > 0
384 ? [<Svg key="strip" source={stripSvg(strip, p => palette.hex[p], width, v.level, p => palette.glow[p])} alt={`The turn so far: ${stripAlt(strip)}`} width={width} height={6} />]
385 : []
386
387 const agentRows = listed.map((agent, i) => {
388 const color = agentColorOf(palette, agent.name)
389 const isLast = i === listed.length - 1 && unlisted === 0
390 const heat = heatOf(palette, v.nowMs - agent.sinceMs)
391
392 return (
393 <Box key={`agent-${i}`} flexDirection="row">
394 <Box flexShrink={0}>
395 <Text dimColor>{isLast ? '└─ ' : '├─ '}</Text>
396 <Text color={color}>◆ </Text>
397 </Box>
398 <Text weight="semibold" color={color} wrap="truncate-end">{printable(agent.name, MAX_AGENT_NAME_CHARS)}</Text>
399 <Text wrap="truncate-end">{` › ${printable(agent.label, MAX_LABEL_CHARS)}`}</Text>
400 <Box flexShrink={0}>
401 <Text tabular color={heat} dimColor={heat === undefined}>{` ${durationOf(v.nowMs - agent.sinceMs)}`}</Text>
402 </Box>
403 </Box>
404 )
405 })
406
407 const moreAgents = unlisted > 0 ? [<Text dimColor>{`└─ … ${plural(unlisted, 'more agent')}`}</Text>] : []
408 const teamBox = agentRows.length > 0
409 ? [<Box key="agents" flexDirection="column">{agentRows}{moreAgents}</Box>]
410 : []
411
412 const historyRows = shown.map((entry, i) => {
413 const { mark, color } = markOf(v, entry)
414 const isQuiet = entry.kind === 'thought' || entry.kind === 'end'
415 const took = entry.durationMs === null ? '' : ` ${durationOf(entry.durationMs)}`
416 const glyphOfTool = toolGlyphOf(entry.tool)
417 const share = (entry.durationMs ?? 0) / maxMs
418 const full = printable(entry.label, MAX_CARD_CHARS)
419
420 return (
421 <Box key={`row-${i}`} flexDirection="row" alignItems="center" gap={1} hover={{ scope: `row-${i}` }}>
422 <Box flexShrink={0}>
423 <Text color={color}>{mark}</Text>
424 {glyphOfTool === '' ? [] : [<Text color={palette.phase.tool}>{` ${glyphOfTool}`}</Text>]}
425 </Box>
426 <Text weight={entry.kind === 'turn' ? 'semibold' : 'regular'} dimColor={isQuiet} wrap="truncate-end">
427 {printable(entry.label, MAX_LABEL_CHARS)}
428 </Text>
429 <Box flexShrink={0} flexDirection="row" alignItems="center" gap={1}>
430 <Text tabular dimColor>{took}</Text>
431 {hasBar(entry)
432 ? [<Svg key={`bar-${i}`} source={barSvg(share, colorHexOf(v, entry), 48)} alt={`${Math.round(share * 100)}% of the longest`} width={48} height={6} />]
433 : []}
434 </Box>
435 {full.length > CARD_FROM_CHARS ? [card(Box, Text, `row-${i}`, full, color)] : []}
436 </Box>
437 )
438 })
439
440 const earlier = hidden > 0 ? [<Text dimColor>{`… ${hidden} earlier`}</Text>] : []
441 const empty = v.entries.length === 0 ? [<Text dimColor>No actions yet</Text>] : []
442 const body = v.isOpen
443 ? [<Box key="history" flexDirection="column" marginTop={1}>{earlier}{historyRows}{empty}</Box>]
444 : []
445
446 const fullLabel = printable(headline.label, MAX_CARD_CHARS)
447
448 return (
449 <Box flexDirection="column">
450 <Box flexDirection="row" alignItems="center" gap={1} borderStyle="round" borderColor={borderOf(v)} paddingX={1} alignSelf="flex-start">
451 <Svg key="jelly" source={jelly} alt={`Claude is ${phaseWords(phase)}`} width={44} height={44} />
452 <Box flexDirection="column" flexShrink={1} gap={0}>
453 <Box key="activity" flexDirection="row" alignItems="center" hover={{ scope: 'headline' }}>
454 <Button key="toggle" plain label={v.isOpen ? '▾' : '▸'} onPress={v.onToggle} />
455 <Box flexShrink={0}>
456 <Text> </Text>
457 {toolGlyph === '' ? [] : [<Text color={palette.phase[phase]}>{`${toolGlyph} `}</Text>]}
458 </Box>
459 <Text wrap="truncate-end">{printable(headline.label, MAX_LABEL_CHARS)}</Text>
460 <Box flexShrink={0}>
461 {headline.meter === undefined ? [] : [<Text color={palette.phase[phase]}>{` ${headline.meter}`}</Text>]}
462 <Text tabular color={elapsed.color} dimColor={elapsed.color === undefined}>{elapsed.text}</Text>
463 </Box>
464 </Box>
465 {fullLabel.length > CARD_FROM_CHARS ? [card(Box, Text, 'headline', fullLabel, borderOf(v))] : []}
466 {stripRow}
467 {teamBox}
468 {body}
469 </Box>
470 </Box>
471 {below}
472 </Box>
473 )
474}
475
476function colorHexOf(v: View, entry: ActivityEntry): string {
477 return entry.kind === 'thought'
478 ? v.palette.hex.thinking
479 : entry.kind === 'reply'
480 ? v.palette.hex.writing
481 : v.palette.outcomeHex[entry.outcome]
482}
483
484function stripAlt(strip: readonly { phase: ActivityPhase; ms: number }[]): string {
485 return strip.map(s => `${phaseWords(s.phase)} ${durationOf(s.ms)}`).join(', ')
486}
487
488function phaseWords(phase: ActivityPhase): string {
489 switch (phase) {
490 case 'idle':
491 return 'idle'
492 case 'requesting':
493 return 'reading'
494 case 'thinking':
495 return 'thinking'
496 case 'writing':
497 return 'writing the reply'
498 case 'composing':
499 return 'writing a tool call'
500 case 'tool':
501 return 'running a tool'
502 case 'agent':
503 return 'running an agent'
504 case 'approval':
505 return 'waiting for your approval'
506 case 'question':
507 return 'waiting for your answer'
508 case 'compacting':
509 return 'compacting'
510 }
511}
512
513/**
514 * The box while the AskUserQuestion dialog holds the prompt: a still copy
515 * of the headline and the agents at work, above the engine's dialog, which
516 * stands once with nothing below it.
517 *
518 * That site takes no `Client`, no size, place or hover, and 12 rows on the
519 * terminal (a row per 40 columns of text), so each line is cut to fit one row.
520 */
521export function drawQuestion(ui: Pick<WebElements, 'Box' | 'Text'>, v: View, dialog: RenderElement): RenderElement {
522 const { Box, Text } = ui
523 const { headline, palette } = v
524 const { phase } = headline
525 const listed = v.working.slice(-QUESTION_AGENT_ROWS)
526 const unlisted = v.working.length - listed.length
527 const elapsed = elapsedOf(v)
528
529 const agentRows = listed.map((agent, i) => {
530 const color = agentColorOf(palette, agent.name)
531 const isLast = i === listed.length - 1 && unlisted === 0
532
533 return (
534 <Text key={`agent-${i}`}>
535 <Text dimColor>{isLast ? '└─ ' : '├─ '}</Text>
536 <Text color={color}>{'◆ '}</Text>
537 {printable(`${agent.name} › ${agent.label}`, QUESTION_LABEL_CHARS - 5)}
538 </Text>
539 )
540 })
541
542 const moreAgents = unlisted > 0 ? [<Text dimColor>{`└─ … ${plural(unlisted, 'more agent')}`}</Text>] : []
543
544 return (
545 <Box flexDirection="column">
546 <Box key="activity" flexDirection="column" borderStyle="round" borderColor={borderOf(v)} paddingX={1} alignSelf="flex-start">
547 <Text>
548 <Text color={palette.phase[phase]}>{phase === 'idle' ? '○ ' : '● '}</Text>
549 {printable(headline.label, QUESTION_LABEL_CHARS - 12)}
550 <Text color={elapsed.color} dimColor={elapsed.color === undefined}>{elapsed.text}</Text>
551 </Text>
552 {agentRows}
553 {moreAgents}
554 </Box>
555 {dialog}
556 </Box>
557 )
558}
559hooks/glyphs.ts 93 lines1import type { ActivityPhase } from '../types'
2
3/** A one-cell mark per tool, Unicode symbols that keep the box aligned. */
4export function toolGlyphOf(tool: string | undefined): string {
5 if (tool === undefined) {
6 return ''
7 }
8
9 if (tool.startsWith('mcp__')) {
10 return '⧉'
11 }
12
13 switch (tool) {
14 case 'Read':
15 return '◧'
16 case 'Edit':
17 case 'NotebookEdit':
18 return '✎'
19 case 'Write':
20 return '✚'
21 case 'Bash':
22 case 'PowerShell':
23 return '❯'
24 case 'Grep':
25 return '⌕'
26 case 'Glob':
27 return '✱'
28 case 'WebFetch':
29 case 'WebSearch':
30 return '⌁'
31 case 'Agent':
32 case 'Task':
33 return '◆'
34 case 'TodoWrite':
35 return '☰'
36 case 'AskUserQuestion':
37 return '?'
38 case 'Skill':
39 return '✦'
40 default:
41 return '•'
42 }
43}
44
45/** A spinner: its frames, one cell each, and how long each shows. */
46export type Spinner = { frames: readonly string[]; ms: number }
47
48const BRAILLE: Spinner = { frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'], ms: 80 }
49
50/** The status glyph's animation in each phase; idle stands still. */
51export const SPINNERS: Record<ActivityPhase, Spinner> = {
52 idle: { frames: ['○'], ms: 1000 },
53 requesting: { frames: ['◐', '◓', '◑', '◒'], ms: 140 },
54 thinking: { frames: ['·', '∘', '○', '◎', '●', '◎', '○', '∘'], ms: 130 },
55 writing: { frames: ['⣀', '⣄', '⣤', '⣦', '⣶', '⣷', '⣿', '⣷', '⣶', '⣦', '⣤', '⣄'], ms: 90 },
56 composing: { frames: ['▖', '▘', '▝', '▗'], ms: 110 },
57 tool: BRAILLE,
58 agent: BRAILLE,
59 approval: { frames: ['●', '◉', '○', '◉'], ms: 260 },
60 question: { frames: ['?', '?', ' ', '?'], ms: 260 },
61 compacting: { frames: ['⣿', '⣶', '⣤', '⣀', '⣤', '⣶'], ms: 150 },
62}
63
64const LEVELS = ['▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'] as const
65
66/**
67 * A one-cell meter on a log scale: `▁` for a little, `█` from `full` on.
68 *
69 * @param amount the count so far (words, characters)
70 * @param full the count that fills it
71 */
72export function meterOf(amount: number, full: number): string {
73 if (amount <= 0) {
74 return ''
75 }
76
77 const share = Math.log1p(amount) / Math.log1p(full)
78
79 return LEVELS[Math.min(LEVELS.length - 1, Math.floor(share * LEVELS.length))] ?? '█'
80}
81
82const EIGHTHS = ['', '▏', '▎', '▍', '▌', '▋', '▊', '▉'] as const
83
84/**
85 * A bar `width` cells wide at most, filled to `share` in eighths of a cell;
86 * anything above nothing shows at least a sliver.
87 */
88export function barOf(share: number, width: number): string {
89 const eighths = Math.max(share > 0 ? 1 : 0, Math.round(Math.min(1, Math.max(0, share)) * width * 8))
90
91 return '█'.repeat(Math.floor(eighths / 8)) + EIGHTHS[eighths % 8]
92}
93hooks/palette.ts 254 lines1import type { ActivityOutcome, ActivityPhase } from '../types'
2
3/** How much the box moves: `userConfig.animation`. */
4export type Level = 'off' | 'subtle' | 'full'
5
6export type PaletteName = 'ember' | 'claude' | 'neon' | 'mono'
7
8/**
9 * The colors one palette paints with. `phase` and `outcome` are what `Text`
10 * and borders take, theme keys where one means the same, so they follow the
11 * person's theme; `hex` is the same color as a hex string, for what mixes or
12 * draws in SVG.
13 */
14export type Palette = {
15 phase: Record<ActivityPhase, string>
16 hex: Record<ActivityPhase, string>
17 /**
18 * Each phase's second stop, hex: what its color shades toward across the
19 * strip, cycles toward on the spinner and breathes from on the border. The
20 * same as `hex` in a flat palette.
21 */
22 glow: Record<ActivityPhase, string>
23 outcome: Record<ActivityOutcome, string>
24 outcomeHex: Record<ActivityOutcome, string>
25 /** The colors the turn-end sparkle cycles through. */
26 sparkle: readonly string[]
27 /** Amber, orange, red: a step that runs past 30 s, 2 min, 5 min. */
28 heat: readonly [string, string, string]
29 /** One color per subagent, picked by its name. */
30 agents: readonly string[]
31}
32
33const CLAUDE_HEX: Record<ActivityPhase, string> = {
34 idle: '#8a8a8a',
35 requesting: '#8fa8f8',
36 thinking: '#c084fc',
37 writing: '#4eba65',
38 composing: '#47a8e5',
39 tool: '#d97757',
40 agent: '#2ec4b6',
41 approval: '#ffc107',
42 question: '#ffc107',
43 compacting: '#48968c',
44}
45
46const EMBER_HEX: Record<ActivityPhase, string> = {
47 idle: '#857a74',
48 requesting: '#f2b8a0',
49 thinking: '#c6a4ec',
50 writing: '#f6c177',
51 composing: '#ee9aa4',
52 tool: '#d97757',
53 agent: '#8cc7b5',
54 approval: '#ffcf5c',
55 question: '#ffcf5c',
56 compacting: '#9fa8e0',
57}
58
59const EMBER_GLOW: Record<ActivityPhase, string> = {
60 idle: '#9a8f88',
61 requesting: '#e8957a',
62 thinking: '#e7a3c8',
63 writing: '#f2a98a',
64 composing: '#d98fbf',
65 tool: '#f3a97c',
66 agent: '#b6d99a',
67 approval: '#ffb347',
68 question: '#ffb347',
69 compacting: '#c79bd9',
70}
71
72/** Bioluminescent: cool sea colors, with warm amber kept for what needs you. */
73const NEON_HEX: Record<ActivityPhase, string> = {
74 idle: '#5b6785',
75 requesting: '#7aa2ff',
76 thinking: '#c4a1ff',
77 writing: '#5eead4',
78 composing: '#38bdf8',
79 tool: '#22e5f0',
80 agent: '#4ade80',
81 approval: '#ffd166',
82 question: '#ffd166',
83 compacting: '#8b93f8',
84}
85
86const NEON_GLOW: Record<ActivityPhase, string> = {
87 idle: '#6f7a99',
88 requesting: '#b39dff',
89 thinking: '#ff8ad8',
90 writing: '#7dd3fc',
91 composing: '#818cf8',
92 tool: '#6ef0c8',
93 agent: '#bef264',
94 approval: '#ff9f6e',
95 question: '#ff9f6e',
96 compacting: '#c79bf2',
97}
98
99const MONO_HEX: Record<ActivityPhase, string> = {
100 idle: '#7a7a7a',
101 requesting: '#b8b8b8',
102 thinking: '#b8b8b8',
103 writing: '#b8b8b8',
104 composing: '#b8b8b8',
105 tool: '#d0d0d0',
106 agent: '#d0d0d0',
107 approval: '#ffc107',
108 question: '#ffc107',
109 compacting: '#b8b8b8',
110}
111
112const OUTCOME_HEX: Record<ActivityOutcome, string> = {
113 ok: '#4eba65',
114 error: '#ff6b80',
115 denied: '#ffc107',
116 interrupted: '#8a8a8a',
117}
118
119const OUTCOME_THEME: Record<ActivityOutcome, string> = {
120 ok: 'success',
121 error: 'error',
122 denied: 'warning',
123 interrupted: 'inactive',
124}
125
126const EMBER_OUTCOME: Record<ActivityOutcome, string> = { ok: '#8fd694', error: '#ff6b6b', denied: '#ffcf5c', interrupted: '#857a74' }
127const NEON_OUTCOME: Record<ActivityOutcome, string> = { ok: '#4ade80', error: '#ff5c7a', denied: '#ffd166', interrupted: '#6f7a99' }
128
129/** Steps on the spinner's color cycle, core to glow and back. */
130const SHIMMER_STEPS = 12
131
132const PALETTES: Record<PaletteName, Palette> = {
133 ember: {
134 phase: EMBER_HEX,
135 hex: EMBER_HEX,
136 glow: EMBER_GLOW,
137 outcome: EMBER_OUTCOME,
138 outcomeHex: EMBER_OUTCOME,
139 sparkle: ['#d97757', '#e8957a', '#f3a97c', '#f6c177', '#ffe3b0', '#f6c177', '#f3a97c', '#e8957a'],
140 heat: ['#f6d36b', '#ff9a4d', '#ff5c5c'],
141 agents: ['#8cc7b5', '#f2b8a0', '#c6a4ec', '#f6c177', '#ee9aa4', '#9fc7e8'],
142 },
143 claude: {
144 phase: {
145 idle: 'inactive',
146 requesting: 'suggestion',
147 thinking: CLAUDE_HEX.thinking,
148 writing: 'success',
149 composing: 'ide',
150 tool: 'claude',
151 agent: CLAUDE_HEX.agent,
152 approval: 'warning',
153 question: 'warning',
154 compacting: 'planMode',
155 },
156 hex: CLAUDE_HEX,
157 glow: CLAUDE_HEX,
158 outcome: OUTCOME_THEME,
159 outcomeHex: OUTCOME_HEX,
160 sparkle: ['#d97757', '#e48a66', '#f0a47f', '#fbc8a8', '#ffe6d5', '#fbc8a8', '#f0a47f', '#e48a66'],
161 heat: ['#e0af68', '#ff9e64', 'error'],
162 agents: ['#2ec4b6', '#f4a261', '#a78bfa', '#60a5fa', '#f472b6', '#84cc16'],
163 },
164 neon: {
165 phase: NEON_HEX,
166 hex: NEON_HEX,
167 glow: NEON_GLOW,
168 outcome: NEON_OUTCOME,
169 outcomeHex: NEON_OUTCOME,
170 sparkle: ['#22e5f0', '#5eead4', '#7dd3fc', '#b39dff', '#ff8ad8', '#c4a1ff', '#7aa2ff', '#38bdf8'],
171 heat: ['#ffd166', '#ff9f6e', '#ff5c7a'],
172 agents: ['#5eead4', '#ff8ad8', '#bef264', '#ffd166', '#b39dff', '#7dd3fc'],
173 },
174 mono: {
175 phase: {
176 idle: 'inactive',
177 requesting: 'text',
178 thinking: 'text',
179 writing: 'text',
180 composing: 'text',
181 tool: 'text',
182 agent: 'text',
183 approval: 'warning',
184 question: 'warning',
185 compacting: 'text',
186 },
187 hex: MONO_HEX,
188 glow: MONO_HEX,
189 outcome: OUTCOME_THEME,
190 outcomeHex: OUTCOME_HEX,
191 sparkle: ['#6e6e6e', '#8a8a8a', '#a8a8a8', '#c8c8c8', '#e8e8e8', '#c8c8c8', '#a8a8a8', '#8a8a8a'],
192 heat: ['warning', 'warning', 'error'],
193 agents: ['#d0d0d0', '#a8a8a8', '#e8e8e8', '#8a8a8a'],
194 },
195}
196
197export function paletteOf(name: unknown): Palette {
198 return PALETTES[name === 'claude' || name === 'neon' || name === 'mono' ? name : 'ember']
199}
200
201/**
202 * A phase's color `t` of the way from its core to its glow. A flat palette
203 * keeps its own color, which may be a theme key.
204 */
205export function shadeOf(palette: Palette, phase: ActivityPhase, t: number): string {
206 const core = palette.hex[phase]
207 const glow = palette.glow[phase]
208
209 return core === glow ? palette.phase[phase] : mix(core, glow, t)
210}
211
212/** The spinner's colors, one per frame: core to glow and back, or the one color of a flat palette. */
213export function shimmerOf(palette: Palette, phase: ActivityPhase): string[] {
214 if (palette.hex[phase] === palette.glow[phase]) {
215 return [palette.phase[phase]]
216 }
217
218 return Array.from({ length: SHIMMER_STEPS }, (_, i) => shadeOf(palette, phase, (1 - Math.cos((i / SHIMMER_STEPS) * 2 * Math.PI)) / 2))
219}
220
221export function levelOf(value: unknown): Level {
222 return value === 'off' || value === 'full' ? value : 'subtle'
223}
224
225/**
226 * The color a step's timer takes as it runs long, or `undefined` while it is
227 * young (drawn dim).
228 */
229export function heatOf(palette: Palette, ms: number): string | undefined {
230 return ms >= 300_000 ? palette.heat[2] : ms >= 120_000 ? palette.heat[1] : ms >= 30_000 ? palette.heat[0] : undefined
231}
232
233/** One color per agent, the same each time its name comes up. */
234export function agentColorOf(palette: Palette, name: string): string {
235 let hash = 0
236
237 for (const char of name) {
238 hash = (hash * 31 + char.charCodeAt(0)) | 0
239 }
240
241 return palette.agents[Math.abs(hash) % palette.agents.length] ?? palette.hex.agent
242}
243
244/**
245 * Mixes two hex colors, `t` 0 being `a` and 1 being `b`.
246 */
247export function mix(a: string, b: string, t: number): string {
248 const channels = (hex: string) => [1, 3, 5].map(i => parseInt(hex.slice(i, i + 2), 16))
249 const [from, to] = [channels(a), channels(b)]
250 const k = Math.min(1, Math.max(0, t))
251
252 return `#${from.map((c, i) => Math.round(c + ((to[i] ?? c) - c) * k).toString(16).padStart(2, '0')).join('')}`
253}
254hooks/text.ts 99 lines1/** Collapses runs of whitespace, newlines included, to single spaces. */
2export function oneLine(text: string): string {
3 return text.replace(/\s+/g, ' ').trim()
4}
5
6/** Cuts `text` to `max` characters, marking the cut with an ellipsis. */
7export function clip(text: string, max: number): string {
8 return text.length > max ? `${text.slice(0, max - 1)}…` : text
9}
10
11/**
12 * The sentence Claude is thinking right now: the tail of the thought so far,
13 * with the sentence before it when the current one has barely started.
14 *
15 * @param thought the thinking block's text so far
16 * @param max the longest snippet, cut from the front
17 */
18export function thoughtOf(thought: string, max: number): string {
19 const flat = oneLine(thought.replace(/[*_`#>]/g, ''))
20
21 if (flat === '') {
22 return ''
23 }
24
25 const sentences = flat.split(/(?<=[.!?:])\s+/)
26 const last = sentences.at(-1) ?? ''
27 const before = sentences.at(-2)
28 const tail = last.length < 25 && before !== undefined ? `${before} ${last}` : last
29
30 return tail.length > max ? `…${tail.slice(-(max - 1))}` : tail
31}
32
33export function wordsIn(text: string): number {
34 return text.split(/\s+/).filter(Boolean).length
35}
36
37export function plural(count: number, word: string): string {
38 return `${count} ${word}${count === 1 ? '' : 's'}`
39}
40
41/** `840 B`, `2.3 KB`, `1.1 MB`. */
42export function sizeOf(chars: number): string {
43 if (chars < 1024) {
44 return `${chars} B`
45 }
46
47 if (chars < 1024 * 1024) {
48 return `${(chars / 1024).toFixed(1)} KB`
49 }
50
51 return `${(chars / 1024 / 1024).toFixed(1)} MB`
52}
53
54/** `0.4s` under ten seconds, `12s` under a minute, `3m 05s` after. */
55export function durationOf(ms: number): string {
56 const seconds = Math.max(0, ms) / 1000
57
58 if (seconds < 10) {
59 return `${seconds.toFixed(1)}s`
60 }
61
62 if (seconds < 60) {
63 return `${Math.floor(seconds)}s`
64 }
65
66 const minutes = Math.floor(seconds / 60)
67 const rest = Math.floor(seconds % 60)
68
69 return `${minutes}m ${String(rest).padStart(2, '0')}s`
70}
71
72/**
73 * A label safe to draw: control, format and line-separator characters out
74 * (the engine refuses a drawing holding one), whitespace collapsed, and cut
75 * to `max`. Labels carry paths, commands and thoughts the model wrote.
76 */
77export function printable(text: string, max: number): string {
78 const spaced = text.replace(/[\p{Cc}\p{Zl}\p{Zp}]/gu, ' ').replace(/\p{Cf}/gu, '')
79
80 return clip(oneLine(spaced), max)
81}
82
83/**
84 * Counts the words a streamed chunk adds, carrying whether the text so far
85 * ends inside a word, so a reply is never counted again from its start.
86 *
87 * @param chunk the newly streamed text
88 * @param isInWord whether the text before it ended inside a word
89 */
90export function wordsAdded(chunk: string, isInWord: boolean): { added: number; isInWord: boolean } {
91 const words = chunk.match(/\S+/g)?.length ?? 0
92 const continues = isInWord && /^\S/.test(chunk)
93
94 return {
95 added: continues ? words - 1 : words,
96 isInWord: chunk === '' ? isInWord : /\S$/.test(chunk),
97 }
98}
99hooks/pulse.tsx 64 lines1import type { ClientModule } from 'claude-code'
2
3/**
4 * The terminal's animations, one `Client` region each, all a fixed width so
5 * the box's layout never moves under them:
6 *
7 * - `spin`: the status glyph, cycling `frames` every `ms`, and `colors`
8 * alongside them (one color holds still)
9 * - `sparkle`: a short burst of stars after a turn ends, then nothing
10 *
11 * Each runs on the surface's frame clock; the hooks never run per frame. A
12 * new phase or a new beat is a new `key`, so a new instance with its own
13 * clock.
14 */
15export type PulseProps =
16 | { kind: 'spin'; frames: string[]; ms: number; colors: string[] }
17 | { kind: 'sparkle'; colors: string[] }
18
19type PulseState = { frame: number }
20
21const SPARKLE_FRAMES = [' ✦ ', ' ✧ ✦', '✦ ✧ ', ' ⋆ ✧', ' · ', ' '] as const
22const SPARKLE_MS = 260
23
24const Pulse: ClientModule<PulseProps, PulseState> = (props, surface) => {
25 const { Text } = surface.elements
26
27 if (surface.state === undefined) {
28 let frame = 0
29 const ms = props.kind === 'sparkle' ? SPARKLE_MS : props.ms
30
31 const stop = surface.every(ms, () => {
32 frame += 1
33
34 // The sparkle plays once, then rests on its blank last frame.
35 if (props.kind === 'sparkle' && frame >= SPARKLE_FRAMES.length - 1) {
36 stop()
37 }
38
39 surface.setState({ frame })
40 })
41 }
42
43 const frame = surface.state?.frame ?? 0
44
45 switch (props.kind) {
46 case 'spin':
47 return <Text color={props.colors[frame % props.colors.length]}>{props.frames[frame % props.frames.length] ?? ' '}</Text>
48 case 'sparkle': {
49 const cells = SPARKLE_FRAMES[Math.min(frame, SPARKLE_FRAMES.length - 1)] ?? ' '
50 const n = props.colors.length
51
52 return (
53 <Text>
54 {[...cells].map((char, i) => (
55 <Text color={props.colors[(i + frame) % n]}>{char}</Text>
56 ))}
57 </Text>
58 )
59 }
60 }
61}
62
63export default Pulse
64hooks/jelly.ts 235 lines1import type { ActivityPhase } from '../types'
2import type { Level } from './palette'
3import { mix } from './palette'
4
5/**
6 * SVG for the desktop: the jellyfish, the timeline strip and the history's
7 * duration bars. Each is a whole document for `Svg`'s `source`, animated by
8 * CSS in its own `<style>`, so the browser runs the loop and the mod draws
9 * only when the state changes.
10 *
11 * A source that changes restarts its animations, so nothing here carries the
12 * time: a one-shot (the halo, the sparkle) carries its beat's id instead.
13 */
14
15const REDUCED = '@media (prefers-reduced-motion: reduce){*{animation:none!important}}'
16
17/** How the jellyfish moves in each phase, as CSS durations in seconds. */
18type Gait = { bob: number; pulse: number; swing: number }
19
20const GAITS: Record<ActivityPhase, Gait> = {
21 idle: { bob: 4.2, pulse: 0, swing: 3.6 },
22 requesting: { bob: 1.6, pulse: 2.2, swing: 1.8 },
23 thinking: { bob: 3, pulse: 2.4, swing: 2.6 },
24 writing: { bob: 2, pulse: 1.4, swing: 1.4 },
25 composing: { bob: 1.8, pulse: 1.2, swing: 0.45 },
26 tool: { bob: 1.4, pulse: 0.9, swing: 0.9 },
27 agent: { bob: 1.4, pulse: 0.9, swing: 0.9 },
28 approval: { bob: 2.4, pulse: 2, swing: 2 },
29 question: { bob: 2.4, pulse: 2, swing: 2 },
30 compacting: { bob: 3, pulse: 0, swing: 1.6 },
31}
32
33export type JellyArgs = {
34 phase: ActivityPhase
35 level: Level
36 /** The phase's color, hex. */
37 color: string
38 /** The phase's second stop, hex: the bell's sheen and the tentacles' tips. `color` when left out. */
39 glow?: string
40 /** A call that ended in this phase: its id and outcome color, hex. */
41 halo: { id: number; color: string } | null
42 /** A turn that just ended: its id. */
43 sparkle: { id: number; color: string } | null
44 size: number
45}
46
47/** The jellyfish acting out `phase`, as an SVG document. */
48export function jellySvg(args: JellyArgs): string {
49 const { phase, level, color, halo, sparkle, size } = args
50 const glow = args.glow ?? color
51 const gait = GAITS[phase]
52 const isIdle = phase === 'idle'
53 const isWaiting = phase === 'approval' || phase === 'question'
54 const isFull = level === 'full'
55 const light = mix(glow, '#ffffff', 0.45)
56 const deep = mix(color, '#000000', 0.25)
57
58 const css: string[] = [
59 '.body{transform-box:fill-box;transform-origin:50% 0}',
60 '.bell{transform-box:fill-box;transform-origin:50% 100%}',
61 '.tent{transform-box:fill-box;transform-origin:50% 0}',
62 '.halo,.star{transform-box:fill-box;transform-origin:50% 50%}',
63 ]
64
65 if (level !== 'off') {
66 css.push(
67 `.body{animation:bob ${gait.bob}s ease-in-out infinite}`,
68 '@keyframes bob{0%,100%{transform:translateY(0)}50%{transform:translateY(-1.6px)}}',
69 `.tent{animation:swing ${gait.swing}s ease-in-out infinite}`,
70 '.t2{animation-delay:-.3s}.t3{animation-delay:-.6s}.t4{animation-delay:-.9s}',
71 '@keyframes swing{0%,100%{transform:rotate(-7deg)}50%{transform:rotate(7deg)}}',
72 )
73
74 if (gait.pulse > 0) {
75 css.push(
76 `.bell{animation:pulse ${gait.pulse}s ease-in-out infinite}`,
77 '@keyframes pulse{0%,100%{transform:scale(1,1)}35%{transform:scale(1.07,.9)}}',
78 )
79 }
80
81 if (phase === 'compacting') {
82 css.push(
83 '.bell{animation:squish 1.6s ease-in-out infinite alternate}',
84 '@keyframes squish{from{transform:scale(1,1)}to{transform:scale(1.16,.84)}}',
85 )
86 }
87
88 css.push(
89 `.glow{animation:breathe ${isWaiting ? 1.4 : 3.2}s ease-in-out infinite}`,
90 `@keyframes breathe{0%,100%{opacity:${isIdle ? 0.15 : 0.3}}50%{opacity:${isWaiting ? 1 : isIdle ? 0.3 : 0.65}}}`,
91 '.halo{animation:halo .8s ease-out 1 forwards}',
92 '@keyframes halo{from{transform:scale(.55);opacity:1}to{transform:scale(1.5);opacity:0}}',
93 )
94 }
95
96 if (isFull) {
97 css.push(
98 '.bub{animation:rise 2.4s ease-in infinite;opacity:0}.b2{animation-delay:-.8s}.b3{animation-delay:-1.6s}',
99 '@keyframes rise{0%{transform:translateY(0);opacity:0}25%{opacity:.9}100%{transform:translateY(-12px);opacity:0}}',
100 '.ink{animation:ink 1.2s ease-in-out infinite;opacity:0}.i2{animation-delay:.2s}.i3{animation-delay:.4s}',
101 '@keyframes ink{0%,100%{opacity:0}50%{opacity:.9}}',
102 '.z{animation:zz 3s ease-in-out infinite;opacity:0}',
103 '@keyframes zz{0%{transform:translate(0,0);opacity:0}40%{opacity:.8}100%{transform:translate(3px,-8px);opacity:0}}',
104 '.star{animation:twinkle 1.6s ease-in-out 1 forwards;opacity:0}.s2{animation-delay:.15s}.s3{animation-delay:.3s}.s4{animation-delay:.45s}',
105 '@keyframes twinkle{0%{transform:scale(0) rotate(0);opacity:0}40%{transform:scale(1.2) rotate(60deg);opacity:1}100%{transform:scale(0) rotate(120deg);opacity:0}}',
106 )
107 }
108
109 const eyes = isIdle
110 ? '<path d="M18.6 18.4q1.4 1.1 2.8 0M26.6 18.4q1.4 1.1 2.8 0" stroke="#2b2b3a" stroke-width="1.1" fill="none" stroke-linecap="round"/>'
111 : isWaiting
112 ? '<circle cx="20" cy="18" r="2.3" fill="#2b2b3a"/><circle cx="28" cy="18" r="2.3" fill="#2b2b3a"/>'
113 + '<circle cx="20.8" cy="17.2" r=".8" fill="#fff"/><circle cx="28.8" cy="17.2" r=".8" fill="#fff"/>'
114 : `<circle cx="20" cy="${phase === 'requesting' ? 17.3 : 18}" r="1.6" fill="#2b2b3a"/>`
115 + `<circle cx="28" cy="${phase === 'requesting' ? 17.3 : 18}" r="1.6" fill="#2b2b3a"/>`
116 + '<circle cx="20.5" cy="17.4" r=".55" fill="#fff"/><circle cx="28.5" cy="17.4" r=".55" fill="#fff"/>'
117
118 const extras: string[] = []
119
120 if (isFull && phase === 'thinking') {
121 extras.push(
122 `<circle class="bub b1" cx="36" cy="14" r="1.4" fill="none" stroke="${light}" stroke-width=".8"/>`,
123 `<circle class="bub b2" cx="39" cy="12" r="1" fill="none" stroke="${light}" stroke-width=".7"/>`,
124 `<circle class="bub b3" cx="34" cy="10" r=".8" fill="none" stroke="${light}" stroke-width=".6"/>`,
125 )
126 }
127
128 if (isFull && phase === 'writing') {
129 extras.push(
130 `<circle class="ink i1" cx="39" cy="31" r="1.1" fill="${color}"/>`,
131 `<circle class="ink i2" cx="42" cy="34" r=".9" fill="${color}"/>`,
132 `<circle class="ink i3" cx="45" cy="37" r=".7" fill="${color}"/>`,
133 )
134 }
135
136 if (isFull && isIdle) {
137 extras.push(`<text class="z" x="35" y="11" font-size="6" font-family="sans-serif" fill="${light}">z</text>`)
138 }
139
140 if (isWaiting) {
141 extras.push(
142 `<text x="37" y="11" font-size="9" font-weight="700" font-family="sans-serif" fill="${color}">${phase === 'approval' ? '!' : '?'}</text>`,
143 )
144 }
145
146 if (halo && level !== 'off') {
147 extras.push(`<circle class="halo" data-beat="${halo.id}" cx="24" cy="20" r="14" fill="none" stroke="${halo.color}" stroke-width="1.6"/>`)
148 }
149
150 if (sparkle && isFull) {
151 const star = (x: number, y: number, n: number) =>
152 `<path class="star s${n}" d="M${x} ${y - 3}L${x + 0.8} ${y - 0.8}L${x + 3} ${y}L${x + 0.8} ${y + 0.8}L${x} ${y + 3}L${x - 0.8} ${y + 0.8}L${x - 3} ${y}L${x - 0.8} ${y - 0.8}Z" fill="${sparkle.color}"/>`
153
154 extras.push(`<g data-beat="${sparkle.id}">${star(8, 9, 1)}${star(40, 7, 2)}${star(42, 28, 3)}${star(6, 30, 4)}</g>`)
155 }
156
157 const tentacles = [14.5, 20, 28, 33.5]
158 .map((x, i) => `<path class="tent t${i + 1}" d="M${x} 23q-2 5 0 9q2 4 0 8" stroke="url(#t)" stroke-width="1.6" fill="none" stroke-linecap="round" opacity=".85"/>`)
159 .join('')
160
161 return `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 48 48">`
162 + `<style>${css.join('')}${REDUCED}</style>`
163 + '<defs>'
164 + `<radialGradient id="g" cx="50%" cy="45%" r="50%"><stop offset="0" stop-color="${color}" stop-opacity=".9"/><stop offset="1" stop-color="${glow}" stop-opacity="0"/></radialGradient>`
165 + `<linearGradient id="b" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="${light}"/><stop offset="1" stop-color="${color}"/></linearGradient>`
166 + `<linearGradient id="t" gradientUnits="userSpaceOnUse" x1="0" y1="23" x2="0" y2="40"><stop offset="0" stop-color="${color}"/><stop offset="1" stop-color="${glow}"/></linearGradient>`
167 + '</defs>'
168 + `<circle class="glow" cx="24" cy="21" r="22" fill="url(#g)" opacity="${isIdle ? 0.15 : 0.45}"/>`
169 + `<g${isIdle ? ' opacity=".6" transform="translate(0 2)"' : ''}><g class="body">`
170 + tentacles
171 + '<g class="bell">'
172 + `<path d="M9.5 23C9.5 9.5 38.5 9.5 38.5 23Q35 26 31.5 23Q27.75 26 24 23Q20.25 26 16.5 23Q13 26 9.5 23Z" fill="url(#b)" stroke="${deep}" stroke-width=".7"/>`
173 + '<ellipse cx="17.5" cy="14.5" rx="3" ry="1.8" fill="#fff" opacity=".45" transform="rotate(-20 17.5 14.5)"/>'
174 + eyes
175 + '<circle cx="16.6" cy="20.6" r="1.5" fill="#ff8fa3" opacity=".5"/><circle cx="31.4" cy="20.6" r="1.5" fill="#ff8fa3" opacity=".5"/>'
176 + (isWaiting
177 ? '<ellipse cx="24" cy="21" rx="1" ry="1.2" fill="#2b2b3a"/>'
178 : '<path d="M22.6 20.6q1.4 1.2 2.8 0" stroke="#2b2b3a" stroke-width=".9" fill="none" stroke-linecap="round"/>')
179 + '</g></g></g>'
180 + extras.join('')
181 + '</svg>'
182}
183
184/**
185 * The turn's phases as one rounded strip of colored segments, each as wide
186 * as its share of the turn, the running one breathing. With `glowOf`, a
187 * segment whose phase has a second stop shades from one to the other.
188 */
189export function stripSvg(
190 segments: readonly { phase: ActivityPhase; ms: number; isOpen: boolean }[],
191 hexOf: (phase: ActivityPhase) => string,
192 width: number,
193 level: Level,
194 glowOf: (phase: ActivityPhase) => string = hexOf,
195): string {
196 const height = 6
197 const total = segments.reduce((sum, s) => sum + s.ms, 0) || 1
198 const shades: string[] = []
199 let x = 0
200
201 const rects = segments.map((s, i) => {
202 const w = Math.max(1.5, (s.ms / total) * width)
203 const [core, glow] = [hexOf(s.phase), glowOf(s.phase)]
204 let fill = core
205
206 if (glow !== core) {
207 shades.push(`<linearGradient id="s${i}"><stop offset="0" stop-color="${core}"/><stop offset="1" stop-color="${glow}"/></linearGradient>`)
208 fill = `url(#s${i})`
209 }
210
211 const rect = `<rect${s.isOpen && level !== 'off' ? ' class="live"' : ''} x="${x.toFixed(1)}" y="0" width="${w.toFixed(1)}" height="${height}" fill="${fill}"/>`
212
213 x += w
214
215 return rect
216 })
217
218 return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">`
219 + `<style>.live{animation:live 1s ease-in-out infinite}@keyframes live{0%,100%{opacity:1}50%{opacity:.45}}${REDUCED}</style>`
220 + (shades.length > 0 ? `<defs>${shades.join('')}</defs>` : '')
221 + `<clipPath id="c"><rect width="${width}" height="${height}" rx="3"/></clipPath>`
222 + `<g clip-path="url(#c)"><rect width="${width}" height="${height}" fill="#8a8a8a" opacity=".15"/>${rects.join('')}</g>`
223 + '</svg>'
224}
225
226/** One history row's duration as a short rounded bar. */
227export function barSvg(share: number, color: string, width: number): string {
228 const w = Math.max(2, Math.min(1, share) * width)
229
230 return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="6" viewBox="0 0 ${width} 6">`
231 + `<rect width="${width}" height="6" rx="3" fill="#8a8a8a" opacity=".15"/>`
232 + `<rect width="${w.toFixed(1)}" height="6" rx="3" fill="${color}" opacity=".85"/>`
233 + '</svg>'
234}
235types/index.d.ts 86 lines1/**
2 * What the box says Claude is doing: `idle` between turns, a model phase
3 * (`requesting`, `thinking`, `writing`, `composing`), a tool phase (`tool`,
4 * `agent`, `approval`, `question`), or `compacting`.
5 */
6export type ActivityPhase =
7 | 'idle'
8 | 'requesting'
9 | 'thinking'
10 | 'writing'
11 | 'composing'
12 | 'tool'
13 | 'agent'
14 | 'approval'
15 | 'question'
16 | 'compacting'
17
18/** The box's headline: the phase, its words, and when it began. */
19export type ActivityNow = {
20 phase: ActivityPhase
21 label: string
22 sinceMs: number
23 /** The tool at work or being written, for its glyph. */
24 tool?: string
25 /** A one-cell meter of the reply's words or the call's size. */
26 meter?: string
27}
28
29/**
30 * The phases of a turn in order, for the timeline strip: the closed ones
31 * with how long each took, and the one running since `open.sinceMs`.
32 */
33export type ActivityTimeline = {
34 segments: readonly { phase: ActivityPhase; ms: number }[]
35 open: { phase: ActivityPhase; sinceMs: number } | null
36}
37
38/**
39 * The last moment worth a flourish: a call that ended (`flash`) or a turn
40 * that did (`done`). `id` counts up, so each plays once.
41 */
42export type ActivityBeat = {
43 id: number
44 kind: 'flash' | 'done'
45 outcome: ActivityOutcome
46 atMs: number
47}
48
49/**
50 * A subagent at work: what it was asked to do, its latest action, and when
51 * it started.
52 */
53export type ActivityAgent = {
54 name: string
55 label: string
56 sinceMs: number
57}
58
59export type ActivityOutcome = 'ok' | 'error' | 'denied' | 'interrupted'
60
61/**
62 * One row of the expanded box: a prompt that started a turn, a stretch of
63 * thinking, a reply, a tool call, a compaction, or how a turn ended.
64 */
65export type ActivityEntry = {
66 kind: 'turn' | 'thought' | 'reply' | 'tool' | 'compact' | 'end'
67 label: string
68 durationMs: number | null
69 outcome: ActivityOutcome
70 /** A tool call's tool, for its glyph. */
71 tool?: string
72}
73
74declare module 'claude-code' {
75 interface PluginState {
76 'agent-pulse': {
77 now: ActivityNow
78 history: readonly ActivityEntry[]
79 agents: readonly ActivityAgent[]
80 isExpanded: boolean
81 timeline: ActivityTimeline
82 beat: ActivityBeat | null
83 }
84 }
85}
86