A pane showing how many tokens the main conversation and each subagent consumed, in Vesuvius colors

Claude Code interface mods, collected in a private pompeitech marketplace. Just as frescoes decorated the walls of Pompeii's houses, these mods decorate Claude Code's interface.
affreschi/
├── .claude-plugin/marketplace.json # the list of mods
└── plugins/
└── <mod-name>/ # one folder (one plugin) per mod
├── .claude-plugin/plugin.json
├── hooks/
│ ├── hooks.json
│ ├── palette.ts # Vesuvius colors
│ └── register.tsx
├── types/index.d.ts # the mod's $.state contract, when it has one
└── tests/
plugins/<mod-name>/ with its files.plugins array in .claude-plugin/marketplace.json: { "name": "<mod-name>", "source": "./plugins/<mod-name>", "description": "..." }
claude plugin validate ./plugins/<mod-name>Load a mod for the current session only (it reloads when you save):
claude --plugin-dir ./plugins/<mod-name>
/plugin marketplace add pompeitech/affreschi
/plugin install <mod-name>@affreschi
| Mod | What it does | Where it shows |
|---|---|---|
vesuvius-theme | A spinner with a glowing crater and volcanic words, a stripe of color beside every tool call (magma while it runs, lava when it fails, ash once done), and the end-of-turn line as an eruption (▲ Erupted for 1m 4s) | Terminal; on the desktop, only the tool call rows |
agent-usage | /agent-usage opens a live pane (it polls every 2s while an agent runs) where every agent plays a character cast from its type or name: Pulcinella for the main conversation, the artist (beret and brush) for frontend and UI work, the nerd (glasses) for planners and architects, the explorer (head lamp), the reviewer (monocle), the guard (helmet) for security, the tester (lab mask) and the handyman (flat cap) for the rest; their eyes follow the status. In scena holds the main conversation, the agents at work and the ones that did something this turn; at the next prompt the finished ones move to the archivio, one row per role with count, tokens and failures (▸ opens it, svuota archivio clears it and keeps its tokens in the totals). Press a name for model, input/output/cache tokens, requests, tool calls and run time. Teammates and agents started before the mod loaded are listed too. The status line shows the subagents running, and a toast says what each one consumed when it finishes | Terminal and desktop |
pulcinella | The band above the prompt: Pulcinella in true pixel art: an SVG of 14×16 pixels in the desktop app, a compact 10×10 drawn two pixels to a character with half blocks (five lines) in the terminal (floppy hat, black half mask, pink cheeks, white blouse), animated two frames per mood (the hat sways and a hammer swings while a tool runs, he blinks at rest, a little z floats while he naps), beside the context window, read again after every model request: the tokens used, the headroom before compaction (vineyard green, then magma and lava past 60% and 85% of the threshold), an estimate of the turns left at the recent pace, the window split by category in one bar, and the largest categories as chips (hide/legend toggles them). details or /context-map opens a pane with every category's tokens and share, the auto-compact threshold, and what fills the window: memory files, MCP servers, custom agents, skills He frets when a command fails, cheers green tests, gasps at changes of 300+ lines, naps after ten quiet minutes, and his line in Neapolitan sits under the bar. His hat grows a pixel per level with the tokens you spend (1M, 10M, 50M, 200M), kept across sessions | Terminal and desktop |
maschere | /maschera opens a picker (or /maschera arlecchino puts one on at once) and Claude answers in that mask's voice: Pulcinella warm and ironic with a Neapolitan word now and then, Arlecchino as terse as it gets, Balanzone thorough with the reasons and trade-offs. Only the tone changes: the mask's section goes last in the system prompt and says every other instruction wins. The mask worn shows in the status line and is remembered for the next session | Terminal and desktop |
spaccanapoli | A row above the prompt with the git branch and its base, commits ahead and behind, files changed with lines added and removed (and a bar of the two), and the branch's PR from gh (open, draft, mergeable, conflicts). Changes made right on the base branch turn it into a red warning. Read again every 10s, after every tool that can change files and at the end of a turn; outside a repository it stays away. Next to pulcinella each keeps the other's band | Terminal and desktop |
golfo | /golfo opens Il Golfo: the last seven days as bars of cost and tokens, today and the priciest day picked out, and the week's cost by project, recorded across sessions (90 days kept). With a weeklyBudget set in the plugin's options, a bar shows how much of it is spent, and a toast warns at 80% and 100% | Terminal and desktop |
lazzarone | When Claude has been waiting on you for minutes (3 by default, in the plugin's options): a permission, a question, a plan to approve, or a turn of two minutes or more just finished, a system notification says what it waits for. One call per wait; answering or writing a prompt clears them | Terminal and desktop |
chiave | Counts, per project, the calls you approve by hand, as the rule that would allow them (Bash(npm run lint:*), WebFetch(domain:docs.github.com), an MCP tool), with a line under the permission dialog that keeps the tally. Past threshold approvals (3 by default) a toast says a rule is ready, and /chiave offers it: Consenti nel progetto writes it into .claude/settings.json, Solo per me into .claude/settings.local.json, Ignora never offers it again, togli takes an added rule back. Risky commands (rm, sudo, git push, curl, mv…) and chained or piped ones are never offered; a settings file that is not plain JSON is left alone | Terminal and desktop |
The colors live in each mod's hooks/palette.ts (a plugin cannot import another plugin's files, so each keeps a copy). They are placeholders, to be replaced with the Vesuvius design system's.
claude plugin validate ./plugins/<mod-name>
claude plugin test ./plugins/<mod-name>
npx -y @biomejs/biome@2.2.4 check plugins
Code follows the officina standards: Biome in StandardJS style (biome.json), braced blocks set off by blank lines, no as casts beyond as const (values the engine hands over as unknown are narrowed by checks), and failures logged to the debug log with $.ui.log(..., { to: 'debug' }), never swallowed.
hooks/register.tsx 710 lines1import type { AgentInfo, EngineInterface, ModelUsage, Register } from 'claude-code'
2import { atom, read, update } from 'claude-code'
3
4import type { AgentUsage, Cleared, Role } from '../types'
5import { ROLE_COLOR, ROLE_NAME, roleOf, SPRITE_WIDTH, type Sprite, spriteOf } from './cast'
6import { VESUVIUS } from './palette'
7
8const PANE = 'agent-usage'
9export const MAIN = 'main'
10// Dark text on a colored badge, whatever its color.
11const BADGE_TEXT = '#1A1A1A'
12// The empty part of a bar.
13const TRACK = '#3A3A3A'
14// Pulcinella's mask, and the white of his eyes and of every costume's props.
15const MASK = '#1A1A1A'
16const WHITE = '#F2EFE9'
17
18const agents = atom({ plugin: 'agent-usage', key: 'agents' } as const, [])
19const expanded = atom({ plugin: 'agent-usage', key: 'expanded' } as const, null)
20const costUsd = atom({ plugin: 'agent-usage', key: 'costUsd' } as const, null)
21const turn = atom({ plugin: 'agent-usage', key: 'turn' } as const, 0)
22const openGroup = atom({ plugin: 'agent-usage', key: 'openGroup' } as const, null)
23const NOTHING_CLEARED: Cleared = { tokens: 0, steps: 0 }
24const cleared = atom({ plugin: 'agent-usage', key: 'cleared' } as const, NOTHING_CLEARED)
25
26export function emptyUsage(
27 id: string,
28 label: string,
29 type: string,
30 lastTurn = 0,
31 lastActiveAt = 0
32): AgentUsage {
33 return {
34 lastTurn,
35 lastActiveAt,
36 id,
37 label,
38 type,
39 model: '',
40 status: 'running',
41 steps: 0,
42 tools: 0,
43 input: 0,
44 output: 0,
45 cacheRead: 0,
46 cacheWrite: 0,
47 durationMs: null
48 }
49}
50
51export function totalOf(a: AgentUsage): number {
52 return a.input + a.output + a.cacheRead + a.cacheWrite
53}
54
55export function formatTokens(n: number): string {
56 if (n >= 1_000_000) {
57 return `${(n / 1_000_000).toFixed(1)}M`
58 }
59
60 if (n >= 10_000) {
61 return `${Math.round(n / 1000)}k`
62 }
63
64 if (n >= 1000) {
65 return `${(n / 1000).toFixed(1)}k`
66 }
67
68 return String(n)
69}
70
71export function formatDuration(ms: number | null): string {
72 if (ms === null) {
73 return '—'
74 }
75
76 const s = Math.round(ms / 1000)
77
78 return s >= 60 ? `${Math.floor(s / 60)}m ${s % 60}s` : `${s}s`
79}
80
81export function shortModel(model: string): string {
82 return model.replace(/^claude-/, '').replace(/-\d{8}$/, '')
83}
84
85// Adds or changes one agent's row, creating it when it is new.
86export function upsert(
87 list: readonly AgentUsage[],
88 id: string,
89 change: (a: AgentUsage) => AgentUsage,
90 fallback: () => AgentUsage
91): AgentUsage[] {
92 const found = list.find(a => a.id === id)
93
94 return found === undefined
95 ? [...list, change(fallback())]
96 : list.map(a => (a.id === id ? change(a) : a))
97}
98
99export function addUsage(a: AgentUsage, usage: ModelUsage & { model?: string }): AgentUsage {
100 return {
101 ...a,
102 model: usage.model ?? a.model,
103 steps: a.steps + 1,
104 input: a.input + usage.input_tokens,
105 output: a.output + usage.output_tokens,
106 cacheRead: a.cacheRead + usage.cache_read_input_tokens,
107 cacheWrite: a.cacheWrite + usage.cache_creation_input_tokens
108 }
109}
110
111// The main conversation first, then the agents at work, then the rest, biggest first.
112export function sorted(list: readonly AgentUsage[]): AgentUsage[] {
113 const rank = (a: AgentUsage) => (a.id === MAIN ? 0 : isBusy(a) ? 1 : 2)
114
115 return list.toSorted((a, b) => rank(a) - rank(b) || totalOf(b) - totalOf(a))
116}
117
118const STATUS_GLYPH: Record<AgentUsage['status'], string> = {
119 pending: '◌',
120 running: '●',
121 waiting: '◐',
122 idle: '○',
123 completed: '✓',
124 failed: '✗',
125 killed: '✗'
126}
127
128const STATUS_LABEL: Record<AgentUsage['status'], string> = {
129 pending: 'starting',
130 running: 'working',
131 waiting: 'waiting',
132 idle: 'idle',
133 completed: 'done',
134 failed: 'failed',
135 killed: 'stopped'
136}
137
138const STATUS_COLOR: Record<AgentUsage['status'], string> = {
139 running: VESUVIUS.magma,
140 waiting: VESUVIUS.magma,
141 failed: VESUVIUS.lava,
142 killed: VESUVIUS.lava,
143 completed: VESUVIUS.vineyard,
144 pending: VESUVIUS.ash,
145 idle: VESUVIUS.ash
146}
147
148// A foreground Agent call's result, checked field by field: the agent it ran and how long,
149// when it completed; nothing for any other result.
150export function completedAgentOf(
151 result: unknown
152): { agentId: string; totalDurationMs: number | null } | undefined {
153 if (typeof result !== 'object' || result === null) {
154 return undefined
155 }
156
157 const status = 'status' in result ? result.status : undefined
158 const agentId = 'agentId' in result ? result.agentId : undefined
159 const duration = 'totalDurationMs' in result ? result.totalDurationMs : undefined
160
161 if (status !== 'completed' || typeof agentId !== 'string') {
162 return undefined
163 }
164
165 return { agentId, totalDurationMs: typeof duration === 'number' ? duration : null }
166}
167
168// How long a busy agent the engine no longer lists may stay quiet before it counts as finished.
169export const STALE_MS = 30_000
170
171// Polls since the module loaded: its own, so a reload starts it over.
172let polls = 0
173// How often the pane reads the agents again, so a background agent's progress shows live.
174const POLL_MS = 2000
175
176const mainRow = (): AgentUsage => ({
177 ...emptyUsage(MAIN, 'Main conversation', 'main'),
178 status: 'idle'
179})
180
181// A failure the mod lives through (a read it retries on the next beat, a band beneath that did
182// not draw) goes to the debug log, never silently away.
183function logFailure($: EngineInterface, what: string, error: unknown): void {
184 const reason = error instanceof Error ? error.message : String(error)
185 $.ui.log(`agent-usage: ${what} failed: ${reason}`, { to: 'debug' })
186}
187
188// Folds the engine's list of agents into the rows: each known row takes its status (a change of
189// status counts as activity in `currentTurn`), and an agent the hooks never saw (a teammate, one
190// spawned before the mod loaded) gets a row of its own, on stage only while it is busy. A busy
191// row the engine does not list, quiet for STALE_MS at `at`, has finished: an agent the engine
192// does not know is not working, and nothing else would ever settle its row.
193export function mergeKnown(
194 list: readonly AgentUsage[],
195 known: readonly AgentInfo[],
196 currentTurn = 0,
197 at = 0
198): AgentUsage[] {
199 const merged = list.map(a => {
200 const info = known.find(k => k.id === a.id)
201
202 if (info === undefined) {
203 const lastActiveAt = Number.isFinite(a.lastActiveAt) ? a.lastActiveAt : 0
204 const isStale = a.id !== MAIN && isBusy(a) && at - lastActiveAt >= STALE_MS
205
206 return isStale ? { ...a, status: 'completed' as const, lastTurn: currentTurn } : a
207 }
208
209 return {
210 ...a,
211 status: info.status,
212 label: a.label || info.description,
213 type: a.type || info.type,
214 lastTurn: info.status === a.status ? a.lastTurn : currentTurn
215 }
216 })
217 const unseen = known
218 .filter(k => !list.some(a => a.id === k.id))
219 .map(k => ({
220 ...emptyUsage(k.id, k.description || k.teammateId || '', k.type, -1),
221 status: k.status
222 }))
223
224 return [...merged, ...unseen]
225}
226
227// On stage: the main conversation, every agent at work, and the ones that did something this turn.
228// The rest wait in the archive.
229export function isOnStage(a: AgentUsage, currentTurn: number): boolean {
230 return a.id === MAIN || isBusy(a) || a.lastTurn >= currentTurn
231}
232
233export type Group = {
234 role: Role
235 agents: AgentUsage[]
236 tokens: number
237 failed: number
238 types: string[]
239}
240
241// The archive, one group per role, the biggest first.
242export function archiveOf(list: readonly AgentUsage[], currentTurn: number): Group[] {
243 const groups = new Map<Role, AgentUsage[]>()
244
245 for (const a of list) {
246 if (!isOnStage(a, currentTurn)) {
247 const role = roleOf(a, MAIN)
248 groups.set(role, [...(groups.get(role) ?? []), a])
249 }
250 }
251
252 return [...groups]
253 .map(([role, agents]) => ({
254 role,
255 agents,
256 tokens: agents.reduce((sum, a) => sum + totalOf(a), 0),
257 failed: agents.filter(a => a.status === 'failed' || a.status === 'killed').length,
258 types: [...new Set(agents.map(a => a.type).filter(t => t !== ''))]
259 }))
260 .toSorted((x, y) => y.tokens - x.tokens)
261}
262
263// Takes the archive off the list, keeping what it consumed in the totals.
264async function clearArchive($: EngineInterface): Promise<void> {
265 const now = await read($, turn)
266 const list = await read($, agents)
267 const archived = list.filter(a => !isOnStage(a, now))
268 const tokens = archived.reduce((sum, a) => sum + totalOf(a), 0)
269 const steps = archived.reduce((sum, a) => sum + a.steps, 0)
270 await update($, cleared, c => ({ tokens: c.tokens + tokens, steps: c.steps + steps }))
271 await update($, agents, l => l.filter(a => isOnStage(a, now)))
272 await update($, openGroup, () => null)
273}
274
275// A row that just did something: active in `currentTurn` at `at`, and a subagent at work again
276// if it had been set down as finished.
277export function touched(a: AgentUsage, currentTurn: number, at: number): AgentUsage {
278 const status = a.id === MAIN || isBusy(a) ? a.status : 'running'
279
280 return { ...a, status, lastTurn: currentTurn, lastActiveAt: at }
281}
282
283function isBusy(a: AgentUsage): boolean {
284 return a.status === 'running' || a.status === 'waiting' || a.status === 'pending'
285}
286
287// Reads the agents' status and cost from the engine, writing only what changed so the pane
288// redraws when something moved and not on every poll.
289async function refresh($: EngineInterface): Promise<void> {
290 const known = await $.agent.list().catch(error => {
291 logFailure($, 'listing the agents', error)
292
293 return []
294 })
295 const usage = await $.session.usage().catch(error => {
296 logFailure($, 'reading the cost', error)
297
298 return undefined
299 })
300 const list = await read($, agents)
301 const next = mergeKnown(list, known, await read($, turn), await $.clock.now())
302
303 if (JSON.stringify(next) !== JSON.stringify(list)) {
304 await update($, agents, () => next)
305 }
306
307 const cost = usage?.cost?.usd ?? null
308
309 if ((await read($, costUsd)) !== cost) {
310 await update($, costUsd, () => cost)
311 }
312}
313
314// One poll: every beat while an agent runs, every fifth when all are quiet.
315async function poll($: EngineInterface): Promise<void> {
316 polls += 1
317 const list = await read($, agents)
318
319 if (list.some(isBusy) || polls % 5 === 0) {
320 await refresh($)
321 await showStatus($)
322 }
323}
324
325// The status line while subagents run: how many, and what they consumed so far.
326async function showStatus($: EngineInterface): Promise<void> {
327 const list = await read($, agents)
328 const running = list.filter(
329 a => a.id !== MAIN && (a.status === 'running' || a.status === 'waiting')
330 )
331
332 if (running.length === 0) {
333 $.ui.status(undefined)
334
335 return
336 }
337
338 const tokens = running.reduce((sum, a) => sum + totalOf(a), 0)
339 $.ui.status(
340 `▲ ${running.length} ${running.length === 1 ? 'agent' : 'agents'} running · ${formatTokens(tokens)} tokens`
341 )
342}
343
344export const register: Register = on => {
345 on('session.start', async ($, e, next) => {
346 await $.command.register({
347 name: 'agent-usage',
348 description: 'Open the pane with the tokens each agent consumed',
349 immediate: true
350 })
351 $.clock.every(POLL_MS, () => {
352 poll($).catch(error => logFailure($, 'polling the agents', error))
353 })
354
355 return next(e)
356 })
357
358 on('command.run', { command: 'agent-usage' }, async $ => {
359 await refresh($)
360 await $.ui.open({ id: PANE, title: 'Agent usage', focus: true, closeOnEscape: true })
361
362 return {}
363 })
364
365 // Every prompt opens a turn: what finished in the last one moves to the archive.
366 on('prompt.submit', async ($, e, next) => {
367 await update($, turn, t => t + 1)
368
369 return next(e)
370 })
371
372 // A subagent starts: its row gets the task's description and type.
373 on('agent.spawn', async ($, e, next) => {
374 const result = await next(e)
375
376 if (result.agentId !== undefined) {
377 const id = result.agentId
378 const now = await read($, turn)
379 await update($, agents, list =>
380 upsert(
381 list,
382 id,
383 a => ({
384 ...a,
385 label: e.description,
386 type: e.subagentType,
387 model: result.model,
388 status: 'running',
389 lastTurn: now
390 }),
391 () => emptyUsage(id, e.description, e.subagentType, now)
392 )
393 )
394 await showStatus($)
395 }
396
397 return result
398 })
399
400 // Every model request, in the main loop or in a subagent's: its tokens go to that loop.
401 on('turn.step', async function* ($, e, next) {
402 const result = yield* next(e)
403 const usage = result.usage
404
405 if (usage !== null) {
406 const id = e.agentId ?? MAIN
407 const now = await read($, turn)
408 const at = await $.clock.now()
409 await update($, agents, list =>
410 upsert(
411 list,
412 id,
413 a => touched(addUsage(a, usage), now, at),
414 () => (id === MAIN ? mainRow() : emptyUsage(id, '', '', now, at))
415 )
416 )
417 await showStatus($)
418 }
419
420 return result
421 })
422
423 // Every tool call counts for the loop it runs in.
424 on('tool.call', async ($, e, next) => {
425 const id = e.agentId ?? MAIN
426 const now = await read($, turn)
427 const at = await $.clock.now()
428 await update($, agents, list =>
429 upsert(
430 list,
431 id,
432 a => touched({ ...a, tools: a.tools + 1 }, now, at),
433 () => (id === MAIN ? mainRow() : emptyUsage(id, '', '', now, at))
434 )
435 )
436
437 return next(e)
438 })
439
440 // A foreground subagent ends: its Agent call reports how long it ran.
441 on('tool.call', { tool: 'Agent' }, async ($, e, next) => {
442 const ran = await next(e)
443 const result = completedAgentOf(ran.result)
444
445 if (result !== undefined) {
446 const id = result.agentId
447 const now = await read($, turn)
448 const finished = (await read($, agents)).find(a => a.id === id)
449 await update($, agents, list =>
450 list.map(a =>
451 a.id === id
452 ? {
453 ...a,
454 status: 'completed' as const,
455 durationMs: result.totalDurationMs ?? a.durationMs,
456 lastTurn: now
457 }
458 : a
459 )
460 )
461
462 if (finished !== undefined) {
463 $.ui.toast(
464 `✓ ${finished.label || finished.type} · ${formatTokens(totalOf(finished))} tokens`
465 )
466 }
467
468 await showStatus($)
469 }
470
471 return ran
472 })
473
474 on('turn.complete', async ($, e, next) => {
475 const result = await next(e)
476 await refresh($)
477 await showStatus($)
478
479 return result
480 })
481
482 on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
483 const { Box, Text, Button } = $.ui.resolve(e)
484
485 // A failure while drawing shows in the pane itself, never as an empty pane.
486 try {
487 const list = await read($, agents)
488 const now = await read($, turn)
489 const open = await read($, expanded)
490 const group = await read($, openGroup)
491 const cost = await read($, costUsd)
492 const gone = await read($, cleared)
493 const grand = list.reduce((sum, a) => sum + totalOf(a), gone.tokens)
494 const requests = list.reduce((sum, a) => sum + a.steps, gone.steps)
495 const stage = sorted(list.filter(a => isOnStage(a, now)))
496 const archive = archiveOf(list, now)
497 const running = list.filter(a => a.id !== MAIN && isBusy(a))
498 const shareOf = (tokens: number) => (grand > 0 ? Math.round((tokens / grand) * 100) : 0)
499
500 // A number under its name: the details are made of these.
501 const tile = (label: string, value: string, color: string = 'text') => (
502 <Box flexDirection="column">
503 <Text color={VESUVIUS.ash}>{label}</Text>
504 <Text color={color} bold>
505 {value}
506 </Text>
507 </Box>
508 )
509
510 // A character, monospaced so its glyphs line up where the surface's font is proportional.
511 const figure = (sprite: Sprite, color: string) => (
512 <Box flexDirection="column" flexShrink={0}>
513 {sprite.map(row => (
514 <Text mono color={color}>
515 {row.map(run =>
516 run.tone === 'mask' ? (
517 <Text backgroundColor={MASK} color={WHITE}>
518 {run.text}
519 </Text>
520 ) : run.tone === 'prop' ? (
521 <Text color={WHITE}>{run.text}</Text>
522 ) : (
523 run.text
524 )
525 )}
526 </Text>
527 ))}
528 </Box>
529 )
530
531 // Bars are boxes sized in percent, never counted characters: a desktop pane draws text in
532 // a proportional font, where a row of block glyphs overflows.
533 const bar = (percent: number, color: string) => (
534 <Box flexDirection="row" height={1} backgroundColor={TRACK}>
535 <Box width={`${percent}%`} height={1} backgroundColor={color}>
536 <Text> </Text>
537 </Box>
538 </Box>
539 )
540
541 const header = (
542 <Box flexDirection="row" justifyContent="space-between">
543 <Text>
544 <Text color={VESUVIUS.lava}>◆</Text> <Text bold>Agent usage</Text>
545 {grand > 0 && (
546 <Text color={VESUVIUS.ash}>
547 {' '}
548 · {formatTokens(grand)} tokens
549 {cost !== null ? ' · ' : ''}
550 {cost !== null && <Text color={VESUVIUS.tuff}>${cost.toFixed(2)}</Text>} ·{' '}
551 {requests} {requests === 1 ? 'request' : 'requests'}
552 </Text>
553 )}
554 </Text>
555 {running.length > 0 ? (
556 <Text backgroundColor={VESUVIUS.magma} color={BADGE_TEXT} bold>
557 {` ${running.length} AL LAVORO `}
558 </Text>
559 ) : (
560 <Text color={VESUVIUS.ash}>idle</Text>
561 )}
562 </Box>
563 )
564
565 if (list.length === 0) {
566 return (
567 <Box flexDirection="column" rowGap={1}>
568 {header}
569 <Text color={VESUVIUS.ash}>No model requests yet.</Text>
570 </Box>
571 )
572 }
573
574 const actor = (a: AgentUsage) => {
575 const role = roleOf(a, MAIN)
576 const color = ROLE_COLOR[role]
577 const total = totalOf(a)
578 const share = shareOf(total)
579 const model = a.model ? shortModel(a.model) : ''
580 const when = a.status === 'completed' && a.id !== MAIN ? ' · this turn' : ''
581
582 return (
583 <Box flexDirection="column">
584 <Box flexDirection="row" columnGap={2}>
585 {figure(spriteOf(role, a.status), color)}
586 <Box flexDirection="column" flexGrow={1} justifyContent="flex-end">
587 <Box flexDirection="row" justifyContent="space-between">
588 {/* A Button takes a label only: the model sits beside it. */}
589 <Box flexDirection="row" columnGap={1}>
590 <Button
591 key={`agent-${a.id}`}
592 plain
593 label={a.label || a.type || a.id}
594 onPress={() => update($, expanded, x => (x === a.id ? null : a.id))}
595 />
596 <Text color={VESUVIUS.ash} wrap="truncate-end">
597 {model}
598 {a.type !== 'main' && a.type !== '' ? ` · ${a.type}` : ''}
599 </Text>
600 </Box>
601 <Text color={STATUS_COLOR[a.status]}>
602 {`${STATUS_GLYPH[a.status]} ${STATUS_LABEL[a.status]}${when}`}
603 </Text>
604 </Box>
605 {bar(total > 0 ? Math.max(1, share) : 0, color)}
606 <Box flexDirection="row" justifyContent="space-between" columnGap={2}>
607 <Text>
608 <Text bold>{formatTokens(total)}</Text>{' '}
609 <Text color={VESUVIUS.ash}>{`${share}%`}</Text>
610 </Text>
611 <Text color={VESUVIUS.ash} wrap="truncate-end">
612 {a.steps} {a.steps === 1 ? 'request' : 'requests'} · {a.tools} tool{' '}
613 {a.tools === 1 ? 'call' : 'calls'}
614 </Text>
615 </Box>
616 </Box>
617 </Box>
618 {a.id === open && (
619 <Box flexDirection="row" columnGap={4} marginTop={1} marginLeft={SPRITE_WIDTH + 2}>
620 {tile('INPUT', formatTokens(a.input), VESUVIUS.gulf)}
621 {tile('OUTPUT', formatTokens(a.output), VESUVIUS.vineyard)}
622 {tile('CACHE READ', formatTokens(a.cacheRead), VESUVIUS.sulfur)}
623 {tile('CACHE WRITE', formatTokens(a.cacheWrite), VESUVIUS.tuff)}
624 {tile('RAN', formatDuration(a.durationMs))}
625 </Box>
626 )}
627 </Box>
628 )
629 }
630
631 const shelf = (g: Group) => {
632 const color = ROLE_COLOR[g.role]
633 const [one, many] = ROLE_NAME[g.role]
634 const isOpen = g.role === group
635
636 return (
637 <Box flexDirection="column">
638 <Box flexDirection="row" columnGap={2} alignItems="center">
639 {figure(spriteOf(g.role, 'completed').slice(0, 2), color)}
640 <Box flexDirection="row" flexGrow={1} justifyContent="space-between" columnGap={2}>
641 <Box flexDirection="row" columnGap={1}>
642 <Button
643 key={`group-${g.role}`}
644 plain
645 label={`${g.agents.length === 1 ? one : many} ×${g.agents.length}`}
646 onPress={() => update($, openGroup, x => (x === g.role ? null : g.role))}
647 />
648 <Text color={VESUVIUS.ash} wrap="truncate-end">
649 {g.types.join(', ')}
650 {g.failed > 0 ? ' · ' : ''}
651 {g.failed > 0 && <Text color={VESUVIUS.lava}>{g.failed} failed</Text>}
652 </Text>
653 </Box>
654 <Text>
655 <Text bold>{formatTokens(g.tokens)}</Text>{' '}
656 <Text color={VESUVIUS.ash}>{`${shareOf(g.tokens)}% ${isOpen ? '▾' : '▸'}`}</Text>
657 </Text>
658 </Box>
659 </Box>
660 {isOpen &&
661 g.agents.map(a => (
662 <Box
663 flexDirection="row"
664 justifyContent="space-between"
665 marginLeft={SPRITE_WIDTH + 2}
666 >
667 <Text wrap="truncate-end">
668 <Text color={STATUS_COLOR[a.status]}>{STATUS_GLYPH[a.status]}</Text>{' '}
669 {a.label || a.type || a.id}
670 </Text>
671 <Text color={VESUVIUS.ash}>
672 {formatTokens(totalOf(a))} · {formatDuration(a.durationMs)}
673 </Text>
674 </Box>
675 ))}
676 </Box>
677 )
678 }
679
680 return (
681 <Box flexDirection="column" rowGap={1}>
682 {header}
683 <Text color={VESUVIUS.ash}>IN SCENA</Text>
684 <Box flexDirection="column" rowGap={1}>
685 {stage.map(actor)}
686 </Box>
687 {archive.length > 0 && (
688 <Box flexDirection="column">
689 <Text color={VESUVIUS.ash}>ARCHIVIO · finished in earlier turns</Text>
690 {archive.map(shelf)}
691 </Box>
692 )}
693 <Box flexDirection="row" justifyContent="space-between">
694 <Text color={VESUVIUS.ash}>click a name for details · ▸ opens a group</Text>
695 {archive.length > 0 && (
696 <Button key="clear" plain label="svuota archivio" onPress={() => clearArchive($)} />
697 )}
698 </Box>
699 </Box>
700 )
701 } catch (error) {
702 return (
703 <Text color={VESUVIUS.lava} wrap="wrap">
704 agent-usage could not draw: {error instanceof Error ? error.message : String(error)}
705 </Text>
706 )
707 }
708 })
709}
710hooks/cast.ts 142 lines1import type { AgentUsage, Role } from '../types'
2import { VESUVIUS } from './palette'
3
4// The cast: which character each agent plays, and how each one is drawn in each status.
5
6// One run of a sprite row: its text, and the part of the costume it is.
7// `body` takes the role's color, `prop` a contrasting one (a brush, a lamp, a lens),
8// `mask` is Pulcinella's black mask with his eyes on it.
9export type Tone = 'body' | 'prop' | 'mask'
10export type Run = { text: string; tone: Tone }
11export type Sprite = readonly (readonly Run[])[]
12
13// Every sprite row is this many cells wide, so the names beside them line up.
14export const SPRITE_WIDTH = 10
15
16export const ROLE_COLOR: Record<Role, string> = {
17 pulcinella: '#F2EFE9',
18 artist: VESUVIUS.lava,
19 nerd: VESUVIUS.gulf,
20 explorer: VESUVIUS.magma,
21 reviewer: VESUVIUS.vineyard,
22 guard: VESUVIUS.tuff,
23 tester: VESUVIUS.sulfur,
24 handyman: VESUVIUS.ash
25}
26
27// What the archive calls a group of them: one, and more than one.
28export const ROLE_NAME: Record<Role, readonly [string, string]> = {
29 pulcinella: ['Pulcinella', 'Pulcinella'],
30 artist: ['Artista', 'Artisti'],
31 nerd: ['Secchione', 'Secchioni'],
32 explorer: ['Esploratore', 'Esploratori'],
33 reviewer: ['Revisore', 'Revisori'],
34 guard: ['Guardia', 'Guardie'],
35 tester: ['Collaudatore', 'Collaudatori'],
36 handyman: ['Tuttofare', 'Tuttofare']
37}
38
39// The words that cast a role, tried in this order: a security reviewer is a guard first.
40const CASTING: readonly (readonly [Role, RegExp])[] = [
41 ['guard', /secur|audit|pentest|vuln/i],
42 ['reviewer', /review|critic|lint/i],
43 ['tester', /\btest|\bqa\b|e2e|playwright/i],
44 ['nerd', /plan|architect|design-doc|research|think|analy/i],
45 ['explorer', /explor|search|find|locat|scout/i],
46 ['artist', /front|\bui\b|\bux\b|design|css|style|react|interface|visual|figma/i]
47]
48
49function castBy(text: string): Role | undefined {
50 return CASTING.find(([, words]) => words.test(text))?.[0]
51}
52
53// The role an agent plays: from its type first and, when the type says nothing, from its name.
54export function roleOf(a: Pick<AgentUsage, 'id' | 'type' | 'label'>, mainId: string): Role {
55 if (a.id === mainId) {
56 return 'pulcinella'
57 }
58
59 return castBy(a.type) ?? castBy(a.label) ?? 'handyman'
60}
61
62const body = (text: string): Run => ({ text, tone: 'body' })
63const prop = (text: string): Run => ({ text, tone: 'prop' })
64
65// Pads a row with spaces to the sprite's width.
66function padded(row: readonly Run[]): Run[] {
67 const width = row.reduce((sum, run) => sum + [...run.text].length, 0)
68
69 return width >= SPRITE_WIDTH ? [...row] : [...row, body(' '.repeat(SPRITE_WIDTH - width))]
70}
71
72// The eyes behind the face, three cells: open while it works, half-moons once done,
73// crossed when it failed, lowered while it waits.
74const EYES: Record<AgentUsage['status'], string> = {
75 running: '███',
76 waiting: '███',
77 completed: '▀█▀',
78 failed: '▚█▞',
79 killed: '▚█▞',
80 pending: '▄█▄',
81 idle: '▄█▄'
82}
83
84// Pulcinella's eyes on his mask, two cells.
85const MASK_EYES: Record<AgentUsage['status'], string> = {
86 running: '••',
87 waiting: '••',
88 completed: '^^',
89 failed: '°°',
90 killed: '°°',
91 pending: '──',
92 idle: '──'
93}
94
95const isResting = (status: AgentUsage['status']): boolean =>
96 status === 'failed' || status === 'killed' || status === 'pending' || status === 'idle'
97
98// The character in a status: four rows, a hat (or nothing) over the face, the body and the feet.
99export function spriteOf(role: Role, status: AgentUsage['status']): Sprite {
100 const eyes = EYES[status]
101 const face = [body(` ▐▛${eyes}▜▌`)]
102 const torso = [body('▝▜█████▛▘')]
103 const feet = [body(isResting(status) ? ' ▝▝ ▘▘' : ' ▘▘ ▝▝')]
104 let rows: Run[][]
105
106 switch (role) {
107 case 'pulcinella':
108 rows = [
109 [body(' ▟▙')],
110 [body(' ▐██▌')],
111 [body(' ▐'), { text: ` ${MASK_EYES[status]} `, tone: 'mask' }, body('▌')],
112 [body(` ▝${status === 'failed' || status === 'killed' ? '~~' : '‿‿'}▘`)]
113 ]
114 break
115 case 'artist':
116 rows = [[body(' ▄▆▆▆▄ '), prop('╱')], face, torso, feet]
117 break
118 case 'nerd':
119 rows = [[], [body(' ▐'), prop('◘═█═◘'), body('▌')], torso, feet]
120 break
121 case 'explorer':
122 rows = [[body(' '), prop('◉'), body('▄▄▄')], face, torso, feet]
123 break
124 case 'reviewer':
125 rows = [[], [body(` ▐▛${eyes.slice(0, 2)}`), prop('◎'), body('▜▌'), prop('╲')], torso, feet]
126 break
127 case 'guard':
128 rows = [[body(' ▄▟███▙▄')], face, torso, feet]
129 break
130 case 'tester':
131 rows = [[], [body(' ▐'), prop('▇▇█▇▇'), body('▌')], torso, feet]
132 break
133 case 'handyman':
134 rows = [[body(' ▄▄▄▄▖')], face, torso, feet]
135 break
136 default:
137 return role satisfies never
138 }
139
140 return rows.map(padded)
141}
142hooks/palette.ts 22 lines1// Vesuvius palette (placeholder): replace the hex values with the design system's.
2// Every mod in affreschi keeps its own copy, because a plugin cannot import another plugin's files.
3export const VESUVIUS = {
4 lava: '#E4572E',
5 magma: '#F28C28',
6 sulfur: '#F2C14E',
7 tuff: '#C9B79C',
8 ash: '#8A8D91',
9 gulf: '#2E86AB',
10 vineyard: '#7A9E4E'
11} as const
12
13// The order categories take their colors in, warmest first.
14export const SEQUENCE = [
15 VESUVIUS.lava,
16 VESUVIUS.magma,
17 VESUVIUS.sulfur,
18 VESUVIUS.tuff,
19 VESUVIUS.gulf,
20 VESUVIUS.vineyard
21] as const
22types/index.d.ts 50 lines1// What one loop consumed: the main conversation, or one subagent.
2export type AgentUsage = {
3 id: string
4 label: string
5 type: string
6 model: string
7 status: 'running' | 'waiting' | 'idle' | 'completed' | 'failed' | 'killed' | 'pending'
8 steps: number
9 tools: number
10 input: number
11 output: number
12 cacheRead: number
13 cacheWrite: number
14 durationMs: number | null
15 // The turn it last did something in: busy, or touched in the current turn, it stays on stage.
16 lastTurn: number
17 // When it last made a model request or a tool call, in ms: a busy agent the engine no longer
18 // lists and that has been quiet for a while has finished.
19 lastActiveAt: number
20}
21
22// The character an agent plays, from its type or its name.
23export type Role =
24 | 'pulcinella'
25 | 'artist'
26 | 'nerd'
27 | 'explorer'
28 | 'reviewer'
29 | 'guard'
30 | 'tester'
31 | 'handyman'
32
33// What the archive's clear-out took off the list, still counted in the totals.
34export type Cleared = { tokens: number; steps: number }
35
36declare module 'claude-code' {
37 interface PluginState {
38 'agent-usage': {
39 agents: AgentUsage[]
40 expanded: string | null
41 costUsd: number | null
42 // The session's turn number, counted at every prompt.
43 turn: number
44 // The archive group shown open, by role.
45 openGroup: Role | null
46 cleared: Cleared
47 }
48 }
49}
50