Clawd, Claude Code's mascot, animated above the prompt: blinks while idle, walks while working, cheers when a turn is done

Clawd, Claude Code's mascot, animated at the left of the mod band above the prompt. The pixels and colors are the ones Claude Code itself draws him with (its built-in mods guide), painted as Raster cells in the terminal and a crisp Svg on desktop, VS Code and mobile.
..CCCCCCCCCCCCC..
..CCCCCCCCCCCCC..
..CCCECCCCCCCEC.. C body #d77757
..CCCECCCCCCCEC.. E eyes #141414
CCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCC
..CCCCCCCCCCCCC..
..CCCCCCCCCCCCC..
..C.C.......C.C..
..C.C.......C.C..
<img src="docs/sheets/term-click-jump.svg" alt="Clawd jumping"> <img src="docs/sheets/term-click-spin.svg" alt="Clawd spinning"> <img src="docs/sheets/term-click-waddle.svg" alt="Clawd waddling out and back"> <img src="docs/sheets/pixel-working.svg" alt="Pixel Clawd working"> <img src="docs/sheets/pixel-happy.svg" alt="Pixel Clawd happy"> <img src="docs/sheets/term-cue-perm.svg" alt="Clawd waiting for you"> <img src="docs/sheets/term-cue-flag.svg" alt="Clawd planting a flag after a commit"> <img src="docs/sheets/term-cue-fireworks.svg" alt="Clawd with fireworks after a long task">
Previews are generated from the mod's frame data. Every animation, frame by frame: docs/SPRITES.md. Design board sources: docs/board.
/plugin install buddy --marketplace katipally/modz
Update, then restart your sessions (more in the main README):
claude plugin marketplace update modz
claude plugin update buddy@modz
Clawd acts out what the agent is doing:
| What he does | When |
|---|---|
| types, code lines scroll, arms alternate | an ordinary Bash command |
| progress bar fills, foot taps | tests run (npm test, pytest, ...) |
| a commit dot hops along a branch | a git command |
| a package drops into a box | npm install, pip install, brew install, ... |
| gears turn, he cranks | build, tsc, make, ... |
| swings a hammer, sparks fly | Edit, Write or NotebookEdit runs |
| a lens slides across, his eyes follow | Read, Grep or Glob runs |
| signal waves grow | WebFetch or WebSearch runs |
| little helpers hop beside him | an Agent (subagent) runs |
| ticks a checklist | TodoWrite or a task tool runs |
a ? bounces, his hand is up | he is asking you a question |
| a plug clicks into a socket | an MCP tool runs |
| waves a wand, sparkles | a skill runs |
| ponders, a bulb lights | entering or leaving plan mode |
| paces, looks around, a bubble rises | thinking, no tool running |
| hops with arms up, sparks fly | a turn finished |
eyes shut, flails, a red ! flashes | a turn was stopped or errored |
stretches, yawns, then sits down and z rises | 2 minutes with nothing happening |
| blinks, wiggles an arm, glances both ways, hops, waves hello | idle |
Click him and he plays one of 14 animations: jump, look, spin, peekaboo, drop, wink, boop, tap, sneeze, turn, coin-hop, skip, waddle or peek. They come from a shuffled deck, so every one plays before any repeats and never the same one twice in a row. Clicks during an animation are ignored. (Terminal only; the pixel version keeps one hop.)
Reactions. Some moments take over his whole look for a while, in the terminal and as pixels. The most urgent wins when two overlap (waiting on you first, then faults, then one-shots, then long states):
| Reaction | When |
|---|---|
waiting (perm) | a permission prompt is open on you, until that tool call ends |
| error | a tool failed (a test run has its own below) |
tests passed or failed (pass, fail) | a test command ends (npm test, pytest, cargo test, claude plugin test, ...) |
| compacting | the context is being compacted |
rate limited (limit) | a rate limit hit 100%, or a turn stopped on one |
subagents (agents) | subagents the main agent spawned are still running (shows clones and the count, also after the main turn ended) |
| coffee | one tool has run for 30 seconds |
big read (bigfile) | a Read of 500 or more lines |
| offline | a turn ended with an error that is not a rate limit |
| flag | a git commit, git push or gh pr create went through |
| hello | a fresh session with an empty transcript |
| fireworks | a turn that ran 5 minutes or more finished |
Each one, frame by frame, with the exact trigger: docs/SPRITES.md.
On top of his mood, three things can bother him (idle or working):
| What he does | When |
|---|---|
| sweat runs down his side | any limit or the context is at 85% or more |
| a clock hand turns beside him | one tool has run for 10 seconds (delegating does not count) |
| snow drifts down and he shivers | the prompt cache has gone cold (needs the cache-timer mod) |
Everything he holds stays inside his own box, so the band never changes size. The frames never redraw the band:
⌨ typing, ✎ editing, ⌕ reading, ◎ browsing, ⚑ delegating, ☑ planning, ◔ testing, ◆ git, ↓ installing, ▤ building, ? asking, ↯ connecting, ✦ casting, ◇ drafting). Only thinking paces on his feet. He sits in a box of nine cells by three rows, and a frame may push him down or sideways inside it, which clips him: that is how he hides, peeks and walks out of sight without the band ever changing size. He runs as a Client region on his own clock, so only his cells repaint. Clicks need the fullscreen terminal ("tui": "fullscreen").Styles: /buddy skin classic | ink | mint | sky | berry | gold (classic is Clawd's own color; the choice is remembered).
Only the main agent's turns and tools move him; subagents' own tools do not. The one exception is the agents reaction, which shows while subagents the main agent spawned are still running.
hooks/register.tsx 328 lines1import { atom, read, update } from 'claude-code'
2import type { AgentStatus, Register, BoxProps, ElementConstructor, EngineInterface, RenderElement, RenderNode, SessionContextUsage, SessionRateLimit, Timer } from 'claude-code'
3
4import type { Activity, Cue, Mood, Playing, Signals, Strain } from '../types'
5import { FRAME_MS, H, LOOP, PIXEL_CUES, PX, SKINS, toSvg, W } from './clawd'
6import { playMs } from './clawd-cues'
7
8// Which prop Clawd picks up for which tool the main agent runs; any other tool keeps him thinking.
9const TOOL_PROPS: Record<string, Activity> = {
10 Edit: 'hammer',
11 Write: 'hammer',
12 NotebookEdit: 'hammer',
13 Read: 'magnify',
14 Grep: 'magnify',
15 Glob: 'magnify',
16 WebFetch: 'web',
17 WebSearch: 'web',
18 Agent: 'agents',
19 TodoWrite: 'notes',
20 TaskCreate: 'notes',
21 TaskUpdate: 'notes',
22 AskUserQuestion: 'ask',
23 Skill: 'skill',
24 EnterPlanMode: 'plan',
25 ExitPlanMode: 'plan',
26}
27// A Bash command is typing unless it is clearly one of these jobs.
28const BASH_JOBS: [RegExp, Activity][] = [
29 [/^\s*git\b/, 'git'],
30 [/\b(test|pytest|jest|vitest|mocha)\b/, 'test'],
31 [/\b(npm|pnpm|yarn|bun|pip3?|brew|apt(-get)?|cargo|gem) (install|add|i|ci)\b/, 'install'],
32 [/\b(build|tsc|make|compile|webpack|gradle|mvn)\b/, 'build'],
33]
34const activityOf = (tool: string, command: string): Activity | undefined =>
35 tool === 'Bash' ? BASH_JOBS.find(([re]) => re.test(command))?.[1] ?? 'laptop' : tool.startsWith('mcp__') ? 'mcp' : TOOL_PROPS[tool]
36const ASLEEP_AFTER_MS = 120_000
37const DROWSY_MS = LOOP.drowsy * FRAME_MS.drowsy
38// Where each mood goes on its own and after how long: a turn's mood settles to idle, a long idle yawns and then dozes.
39const SETTLE: Partial<Record<Mood, [Mood, number]>> = {
40 happy: ['idle', 2400],
41 oops: ['idle', 1200],
42 idle: ['drowsy', ASLEEP_AFTER_MS - DROWSY_MS],
43 drowsy: ['asleep', DROWSY_MS],
44}
45// A subagent whose turn.complete never comes is dropped once the engine stops listing it as live.
46const AGENT_SWEEP_MS = 15_000
47const LIVE: AgentStatus[] = ['pending', 'running', 'waiting']
48// He sweats from 85% of any limit, checks a clock when one tool has run SLOW_MS and sips coffee at LONG_MS.
49const HOT_PERCENT = 85
50const SLOW_MS = 10_000
51const LONG_MS = 30_000
52const STAGES = [['slow', SLOW_MS], ['long', LONG_MS]] as const
53// A read of this many lines is a big file; a turn this long ends in fireworks.
54const BIG_FILE_LINES = 500
55const BIG_TURN_MS = 300_000
56// A commit, a push or a pull request is a flag, unless it only rehearsed.
57const FLAG_JOB = /\bgit\s+(commit|push)\b|\bgh\s+pr\s+create\b/
58// A test run ends in a verdict; any other tool that fails ends in an error.
59const TEST_RUN = /\b(npm|pnpm|yarn|bun)( run)? test\b|\b(pytest|jest|vitest|mocha|phpunit|rspec)\b|\b(go|cargo|mvn|gradle|dotnet|deno|swift|flutter) test\b|\bclaude plugin test\b/
60// The request count falling by half is how a compaction shows where session.compact does not run.
61const COMPACT_MIN_STEPS = 6
62
63const mood = atom({ plugin: 'buddy', key: 'mood' } as const, 'idle')
64const activity = atom({ plugin: 'buddy', key: 'activity' } as const, 'think')
65const skin = atom({ plugin: 'buddy', key: 'skin' } as const, 'classic')
66const signals = atom({ plugin: 'buddy', key: 'signals' } as const, { hot: false, slow: 0, long: 0, waiting: [], compacting: 0, limited: false, agents: [], steps: 0 })
67const playing = atom({ plugin: 'buddy', key: 'cue' } as const, null)
68// The cache-timer mod owns these; without it the cache is simply never cold.
69const cacheLast = atom({ plugin: 'cache-timer', key: 'last' } as const, null)
70const cacheTtl = atom({ plugin: 'cache-timer', key: 'ttlMin' } as const, 60)
71
72// What takes over his look, most urgent first: waiting on you, then a fault, then a one-shot, then a long state.
73const RANK: Record<Cue, number> = {
74 perm: 0, error: 1, offline: 1, limit: 1,
75 pass: 2, fail: 2, flag: 2, hello: 2, fireworks: 2,
76 compact: 3, agents: 3, coffee: 3, bigfile: 3,
77}
78// Cues that last as long as their cause; subagents only show while the main chat is not in a turn.
79const STICKY: [Cue, (s: Signals, m: Mood) => boolean][] = [
80 ['perm', s => s.waiting.length > 0],
81 ['limit', s => s.limited],
82 ['compact', s => s.compacting > 0],
83 ['coffee', s => s.long > 0],
84 ['agents', (s, m) => s.agents.length > 0 && (m === 'idle' || m === 'asleep')],
85]
86const pickCue = (s: Signals, m: Mood, one: Playing): Cue | null =>
87 [...(one ? [one.name] : []), ...STICKY.filter(([, on]) => on(s, m)).map(([cue]) => cue)].reduce<Cue | null>((best, cue) => (best === null || RANK[cue] < RANK[best] ? cue : best), null)
88
89const isHot = (context: SessionContextUsage, limits: SessionRateLimit[]) =>
90 [context.percent, ...limits.map(l => l.percentUsed)].some(p => p !== undefined && p >= HOT_PERCENT)
91
92// Every modz mod places its tile in one shared band: a lead column (the bot), then a column of tiles, then an optional
93// right column. A column with no tiles is not drawn, and columns wrap under each other when the width runs out.
94const BAND = 'modz-band'
95const SLOTS: Record<string, 'lead' | 'left' | 'right'> = {
96 buddy: 'lead',
97 'usage-limits': 'left',
98 'cache-timer': 'left',
99 'model-info': 'left',
100 orchestrator: 'left',
101}
102const ORDER = Object.keys(SLOTS)
103const keyOf = (n: RenderNode) => (typeof n !== 'string' && n.type === 'Box' ? String(n.props?.key ?? '') : '')
104const rank = (n: RenderNode) => {
105 const i = ORDER.indexOf(keyOf(n))
106 return i < 0 ? ORDER.length : i
107}
108const pack = (Box: ElementConstructor<BoxProps>, below: RenderElement, tile: RenderElement) => {
109 const isEmpty = below.type === 'Box' && !below.children?.length
110 const tiles = keyOf(below) === BAND
111 ? (below.type === 'Box' ? below.children ?? [] : []).flatMap(col => (typeof col !== 'string' && col.type === 'Box' ? col.children ?? [] : [col]))
112 : isEmpty ? [] : [below]
113 const all = [...tiles, tile].sort((a, b) => rank(a) - rank(b))
114 const [lead, left, right] = (['lead', 'left', 'right'] as const).map(slot => all.filter(n => (SLOTS[keyOf(n)] ?? 'left') === slot))
115 return (
116 <Box key={BAND} flexDirection="row" flexWrap="wrap" columnGap={3}>
117 {lead!.length > 0 && <Box key="modz-lead" flexDirection="column" justifyContent="center">{lead}</Box>}
118 {left!.length > 0 && <Box key="modz-left" flexDirection="column" flexGrow={right!.length > 0 ? 1 : 0}>{left}</Box>}
119 {right!.length > 0 && <Box key="modz-right" flexDirection="column" alignItems="flex-end">{right}</Box>}
120 </Box>
121 )
122}
123
124// The band redraws only when the mood or the prop changes; the frames themselves play inside Clawd's own region.
125let settle: Timer | undefined
126
127const become = async ($: EngineInterface, next: Mood) => {
128 settle?.cancel()
129 await update($, mood, () => next)
130 const step = SETTLE[next]
131 if (step) settle = $.clock.after(step[1], () => void become($, step[0]))
132}
133
134// The tracked subagents change only here, so the sweep runs exactly while there are some.
135let sweep: Timer | undefined
136const setAgents = async ($: EngineInterface, change: (ids: string[]) => string[]) => {
137 await update($, signals, s => ({ ...s, agents: change(s.agents) }))
138 const { agents } = await read($, signals)
139 if (agents.length === 0) {
140 sweep?.cancel()
141 sweep = undefined
142 } else sweep ??= $.clock.every(AGENT_SWEEP_MS, async () => {
143 const live = await $.agent.list().then(list => new Set(list.filter(a => LIVE.includes(a.status)).map(a => a.id)), () => undefined)
144 if (live) await setAgents($, ids => ids.filter(id => live.has(id)))
145 })
146}
147
148// A one-shot cue ends itself after its frames, and only one more urgent than the one playing may cut in.
149let cueEnd: Timer | undefined
150const play = async ($: EngineInterface, name: Cue, hash = '') => {
151 const now = await read($, playing)
152 if (now && RANK[name] > RANK[now.name]) return
153 cueEnd?.cancel()
154 await update($, playing, () => ({ name, hash }))
155 cueEnd = $.clock.after(playMs(name), () => void update($, playing, () => null))
156}
157
158const setCompacting = ($: EngineInterface, by: 1 | -1) => update($, signals, s => ({ ...s, compacting: s.compacting + by }))
159type Ran = { deny?: string; isError?: true; result?: unknown }
160const verdictOf = (tool: string, command: string, ran?: Ran): Cue | undefined => {
161 if (ran?.deny !== undefined || (ran?.result as { backgroundTaskId?: string } | null | undefined)?.backgroundTaskId) return undefined
162 const isFailed = ran === undefined || ran.isError === true
163 return tool === 'Bash' && TEST_RUN.test(command) ? (isFailed ? 'fail' : 'pass') : isFailed ? 'error' : undefined
164}
165// A read that came back long, or a commit that went through; a commit prints "[main 1a2b3c4] subject", which gives the hash.
166const noteOf = (tool: string, command: string, ran?: Ran): { cue: Cue; hash?: string } | undefined => {
167 const out = ran?.result as { stdout?: string; file?: { numLines?: number }; backgroundTaskId?: string } | null | undefined
168 if (!out || ran?.deny !== undefined || ran?.isError || out.backgroundTaskId) return undefined
169 if (tool === 'Read' && (out.file?.numLines ?? 0) >= BIG_FILE_LINES) return { cue: 'bigfile' }
170 if (tool === 'Bash' && FLAG_JOB.test(command) && !command.includes('--dry-run')) return { cue: 'flag', hash: out.stdout?.match(/\[[^\]]* ([0-9a-f]{7,})\]/)?.[1] }
171 return undefined
172}
173const moodAfter = (e: { isAborted: boolean; reason: string }): Mood => (e.isAborted || e.reason === 'error' ? 'oops' : 'happy')
174
175export const register: Register = on => {
176 on('session.start', async ($, e, next) => {
177 await $.command.register({ name: 'buddy', description: 'Change how Clawd looks', argumentHint: `skin ${Object.keys(SKINS).join(' | ')}` })
178 const saved = (await $.store.get('skin')) as string | undefined
179 if (saved && saved in SKINS) await update($, skin, () => saved)
180 await become($, 'idle')
181 const started = await next(e)
182 // /clear sends no session.start, so this is a launch; a transcript that already holds messages is a resume. The session binds around next(e).
183 if (await $.session.messages().then(m => m.length === 0, () => false)) await play($, 'hello')
184 return started
185 })
186
187 on('command.run', { command: 'buddy' }, async ($, e) => {
188 const [word, name = ''] = e.args.trim().split(/\s+/)
189 if (word !== 'skin' || !(name in SKINS)) return { text: `Usage: /buddy skin ${Object.keys(SKINS).join(' | ')}` }
190 await update($, skin, () => name)
191 await $.store.set('skin', name)
192 return { text: `Clawd is now ${name}.` }
193 })
194
195 on('turn.start', async ($, e, next) => {
196 await update($, activity, () => 'think' as Activity)
197 await become($, 'working')
198 return next(e)
199 })
200
201 on('session.end', async ($, e, next) => {
202 if (e.reason === 'clear' || e.reason === 'resume') {
203 await update($, signals, s => ({ ...s, steps: 0, waiting: [] }))
204 await setAgents($, () => [])
205 }
206 return next(e)
207 })
208
209 on('session.measure', async ($, e, next) => {
210 await update($, signals, s => ({ ...s, hot: isHot(e.context, e.rateLimits), limited: e.rateLimits.some(l => l.percentUsed >= 100) }))
211 return next(e)
212 })
213
214 // Classic hooks do not run where an organization manages Claude Code; there the limit shows from session.measure alone.
215 on('classic.StopFailure', async ($, e, next) => {
216 if (e.error === 'rate_limit') await update($, signals, s => ({ ...s, limited: true }))
217 return next(e)
218 }).catch(($, e, next) => next(e))
219
220 on('session.compact', async ($, e, next) => {
221 if (e.trigger === 'precompute' || e.agentId !== undefined) return next(e)
222 await setCompacting($, 1)
223 try {
224 return await next(e)
225 } finally {
226 await setCompacting($, -1)
227 await update($, signals, s => ({ ...s, steps: 0 }))
228 }
229 }).catch(($, e, next) => next(e))
230
231 // Runs wherever session.compact does not: the request carries far fewer messages than the one before.
232 on('turn.step', async function* ($, e, next) {
233 if (e.agentId === undefined) {
234 const { steps } = await read($, signals)
235 if (steps >= COMPACT_MIN_STEPS && e.messageCount < steps / 2) {
236 await setCompacting($, 1)
237 $.clock.after(playMs('compact'), () => void setCompacting($, -1))
238 }
239 if (steps !== e.messageCount) await update($, signals, s => ({ ...s, steps: e.messageCount }))
240 }
241 return yield* next(e)
242 })
243
244 on('agent.spawn', async ($, e, next) => {
245 const ran = await next(e)
246 if (ran.agentId && e.parentAgentId === undefined && !e.workflow) await setAgents($, ids => [...ids, ran.agentId!])
247 return ran
248 }).catch(($, e, next) => next(e))
249
250 // An ask with nobody else to put it to is a dialog open on the person; it stays until the call ends.
251 on('tool.check', async ($, e, next) => {
252 const verdict = await next(e)
253 if (verdict.decision === 'ask' && verdict.decider === undefined && e.tool_use_id) await update($, signals, s => ({ ...s, waiting: [...s.waiting, e.tool_use_id!] }))
254 return verdict
255 }).catch(($, e, next) => next(e))
256
257 on('tool.call', async ($, e, next) => {
258 const isMain = e.agentId === undefined
259 const command = 'command' in e ? String(e.command) : ''
260 const prop = isMain ? activityOf(e.tool, command) : undefined
261 if (prop) await update($, activity, () => prop)
262 // Delegating is long by design, so only other tools count as slow or long.
263 const passed = { slow: false, long: false }
264 const watches = isMain && e.tool !== 'Agent'
265 ? STAGES.map(([key, ms]) => $.clock.after(ms, async () => {
266 passed[key] = true
267 await update($, signals, s => ({ ...s, [key]: s[key] + 1 }))
268 }))
269 : []
270 let ran: Awaited<ReturnType<typeof next>> | undefined
271 try {
272 ran = await next(e)
273 return ran
274 } finally {
275 for (const w of watches) w.cancel()
276 for (const [key] of STAGES) if (passed[key]) await update($, signals, s => ({ ...s, [key]: s[key] - 1 }))
277 if (prop) await update($, activity, () => 'think' as Activity)
278 if (e.tool_use_id && (await read($, signals)).waiting.includes(e.tool_use_id)) await update($, signals, s => ({ ...s, waiting: s.waiting.filter(id => id !== e.tool_use_id) }))
279 const verdict = isMain ? verdictOf(e.tool, command, ran) : undefined
280 const note = isMain && !verdict ? noteOf(e.tool, command, ran) : undefined
281 if (verdict) await play($, verdict)
282 else if (note) await play($, note.cue, note.hash)
283 }
284 })
285
286 on('turn.complete', async ($, e, next) => {
287 if (e.agentId === undefined) {
288 await update($, signals, s => ({ ...s, waiting: [], limited: e.reason === 'answer' ? false : s.limited }))
289 const isBig = e.reason === 'answer' && e.durationMs >= BIG_TURN_MS
290 await become($, isBig ? 'idle' : moodAfter(e))
291 // The engine names no error kind here: an error with no rate limit showing is taken for the network.
292 if (e.reason === 'error' && !(await read($, signals)).limited) await play($, 'offline')
293 if (e.reason === 'answer') {
294 if ((await read($, playing))?.name === 'offline') {
295 cueEnd?.cancel()
296 await update($, playing, () => null)
297 }
298 if (isBig) await play($, 'fireworks')
299 }
300 } else if ((await read($, signals)).agents.includes(e.agentId)) {
301 await setAgents($, ids => ids.filter(id => id !== e.agentId))
302 if ((await read($, signals)).agents.length === 0 && (await read($, mood)) !== 'working') await become($, moodAfter(e))
303 }
304 return next(e)
305 })
306
307 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
308 const below = await next(e)
309 if (e.props.hasSurvey) return below
310 const elements = $.ui.resolve(e)
311 const { Box } = elements
312 const [m, act, s, sig, one, last, ttl] = await Promise.all([read($, mood), read($, activity), read($, skin), read($, signals), read($, playing), read($, cacheLast), read($, cacheTtl)])
313 const isCold = last !== null && Date.now() > last.at + ttl * 60_000
314 const strain: Strain = sig.hot ? 'hot' : sig.slow > 0 ? 'slow' : isCold ? 'cold' : 'none'
315 const isStill = (await $.settings.read()).prefersReducedMotion === true
316 const cue = pickCue(sig, m, one)
317 // The terminal runs Clawd as a Client on its own clock; elsewhere he is one Svg that animates itself.
318 const art = e.surface === 'terminal' && 'Client' in elements
319 ? <elements.Client key="clawd" module="./clawd-term.tsx" props={{ mood: m, activity: act, skin: s, isStill, strain, cue, clones: sig.agents.length, hash: one?.hash ?? '' }} />
320 : 'Svg' in elements
321 ? <elements.Svg source={toSvg(m, act, SKINS[s] ?? SKINS.classic!, isStill, strain, cue && { name: cue, clones: sig.agents.length })} alt={`Clawd, ${cue ? PIXEL_CUES[cue].say : m}`} width={W * PX} height={H * PX} isInteractive={!isStill} />
322 : null
323 if (!art) return below
324
325 return pack(Box, below, <Box key="buddy">{art}</Box>)
326 })
327}
328hooks/clawd.ts 485 lines1import type { Activity, Cue, Mood, Strain } from '../types'
2
3// Clawd exactly as Claude Code draws him (its built-in mods guide's CLAWD_POSES): C body, E eye, . nothing.
4const CLAWD = [
5 '..CCCCCCCCCCCCC..',
6 '..CCCCCCCCCCCCC..',
7 '..CCCECCCCCCCEC..',
8 '..CCCECCCCCCCEC..',
9 'CCCCCCCCCCCCCCCCC',
10 'CCCCCCCCCCCCCCCCC',
11 '..CCCCCCCCCCCCC..',
12 '..CCCCCCCCCCCCC..',
13 '..C.C.......C.C..',
14 '..C.C.......C.C..',
15]
16const EYE_ROWS = [2, 3]
17const EYE_COLS = [5, 13]
18const ARM_ROWS = [4, 5]
19const ARM_COLS = { left: [0, 1], right: [15, 16] }
20const LEG_ROW = 9
21const LEGS = { outer: [2, 14], inner: [4, 12] }
22
23// Two rows above him for hats, hearts and antennas, and a column each side for the head shake.
24// Everything he holds stays inside this box, so the tile never changes size.
25const TOP = 2
26const LEFT = 1
27export const W = LEFT + CLAWD[0]!.length + 1
28export const H = TOP + CLAWD.length
29
30// Props share Clawd's pixel style; each letter is one palette color, C is the body.
31export const PALETTE: Record<string, number> = {
32 E: 0x141414, // eyes
33 G: 0x3a3a40, // dark metal
34 g: 0xb8bcc4, // light metal
35 b: 0x7aa2f7, // screen glow
36 W: 0xffffff,
37 w: 0x8b5a2b, // wood
38 y: 0xf5c542,
39 r: 0xe5484d,
40 n: 0x5fd38d,
41 N: 0x5a6fd6, // nightcap
42}
43export const SKINS: Record<string, number> = {
44 classic: 0xd77757,
45 ink: 0xe8e6e3,
46 mint: 0x7fd1ae,
47 sky: 0x7aa2f7,
48 berry: 0xe07ab0,
49 gold: 0xe5c07b,
50}
51
52const LAPTOP = ['GGGGGGGGG', 'GGGGgGGGG', 'GGGGGGGGG', '.ggggggggggg']
53const LENS = ['.GG.', 'GbbG', 'GbbG', '.GG.']
54const PAPER = ['WWWWW', 'WGGGW', 'WWWWW', 'WGGGW', 'WWWWW']
55const MINI = ['CCC', 'C.C']
56const HEART = ['rr.rr', '.rrr.']
57const CROWN = ['y.y.y', 'yyyyy']
58const NIGHTCAP = ['....NNNN.', '.NNNNNNNNW']
59const CONFETTI = ['y', 'r', 'n', 'b', 'W']
60
61// How fast each mood plays, and how many frames make one loop of it.
62export const FRAME_MS: Record<Mood, number> = { idle: 300, drowsy: 450, working: 200, happy: 160, oops: 90, asleep: 900, loved: 140 }
63export const LOOP: Record<Mood, number> = { idle: 40, drowsy: 8, working: 8, happy: 8, oops: 8, asleep: 3, loved: 10 }
64
65export type Gesture = 'none' | 'blink' | 'look-left' | 'look-right' | 'wave' | 'wiggle-left' | 'wiggle-right' | 'hop'
66
67// Idle Clawd blinks, wiggles an arm, glances both ways, hops and waves once per loop, at uneven beats so it never feels mechanical.
68// Beat 0 is always still, which is the frame he holds when motion is off.
69export const idleGesture = (f: number): Gesture => {
70 const beat = f % LOOP.idle
71 if (beat === 7 || beat === 23 || beat === 25) return 'blink'
72 if (beat === 3) return 'wiggle-left'
73 if (beat === 4) return 'wiggle-right'
74 if (beat === 19) return 'hop'
75 if (beat >= 12 && beat < 16) return 'look-left'
76 if (beat >= 28 && beat < 32) return 'look-right'
77 if (beat >= 34 && beat < 38) return 'wave'
78 return 'none'
79}
80
81// A pixel is empty (undefined) or a palette letter.
82export type Pixels = (string | undefined)[][]
83
84const blank = (): Pixels => Array.from({ length: H }, () => Array<string | undefined>(W).fill(undefined))
85
86const put = (canvas: Pixels, x: number, y: number, c: string) => {
87 if (y >= 0 && y < H && x >= 0 && x < W) canvas[y]![x] = c
88}
89
90const stamp = (canvas: Pixels, art: string[], x: number, y: number) =>
91 art.forEach((row, dy) => [...row].forEach((c, dx) => c !== '.' && put(canvas, x + dx, y + dy, c)))
92
93// One frame: Clawd's pose for the mood, then what he holds or wears for what the agent is doing.
94// The pixel Clawd has one prop per kind of tool; the newer kinds of work borrow the closest one.
95const PIXEL_PROP: Record<Activity, Activity> = {
96 think: 'think', laptop: 'laptop', hammer: 'hammer', magnify: 'magnify', notes: 'notes', web: 'web', agents: 'agents',
97 test: 'laptop', git: 'laptop', install: 'laptop', build: 'hammer', ask: 'think', mcp: 'web', skill: 'notes', plan: 'think',
98}
99
100export const draw = (m: Mood, activity: Activity, f: number, strain: Strain = 'none'): Pixels => {
101 const act = PIXEL_PROP[activity]
102 const g = m === 'idle' ? idleGesture(f) : 'none'
103 const isWorking = m === 'working'
104 const body = CLAWD.map(r => [...r])
105 // Drowsy is one slow yawn: eyes sag, he stretches with arms up and eyes shut, then slumps toward sleep in his nightcap.
106 const yawn = m === 'drowsy' ? f % LOOP.drowsy : -1
107 const isStretch = yawn >= 2 && yawn < 5
108 const isSlump = yawn >= 6
109 const isShut = m === 'asleep' || m === 'oops' || g === 'blink' || isStretch || yawn === 7
110 const isSquint = m === 'happy' || m === 'loved' || (yawn >= 0 && !isShut)
111 // Over a laptop or a page he looks down; otherwise he glances where the gesture or the work points.
112 const isDown = isWorking && (act === 'laptop' || act === 'notes')
113 const shift = g === 'look-left' ? -1 : g === 'look-right' || (isWorking && !isDown) ? 1 : 0
114 for (const col of EYE_COLS) {
115 for (const row of EYE_ROWS) body[row]![col] = 'C'
116 if (isShut) continue
117 for (const row of isSquint || isDown ? [EYE_ROWS[1]!] : EYE_ROWS) body[row]![col + shift] = 'E'
118 }
119 const raise = (cols: number[]) => {
120 for (const col of cols) {
121 for (const row of ARM_ROWS) body[row]![col] = '.'
122 for (const row of EYE_ROWS) body[row]![col] = 'C'
123 }
124 }
125 const isBounce = (m === 'happy' || m === 'loved') && f % 2 === 0
126 if (isBounce || isStretch || g === 'hop') raise([...ARM_COLS.left, ...ARM_COLS.right])
127 if (g === 'wiggle-left') raise(ARM_COLS.left)
128 if (g === 'wave' && f % 2 === 0 || g === 'wiggle-right') raise(ARM_COLS.right)
129 if (isWorking && act === 'hammer' && f % 4 < 2) raise(ARM_COLS.right)
130 if (isWorking && act === 'think') for (const col of f % 2 === 0 ? LEGS.inner : LEGS.outer) body[LEG_ROW]![col] = '.'
131 if (m === 'asleep' || isSlump) for (const col of [...LEGS.inner, ...LEGS.outer]) body[LEG_ROW]![col] = '.'
132
133 const ox = LEFT + (m === 'oops' ? (f % 2 === 0 ? -1 : 1) : 0)
134 const oy = TOP + ((m === 'happy' || m === 'loved') && f % 2 === 1 ? 1 : m === 'asleep' || isSlump ? 1 : isStretch || g === 'hop' ? -1 : 0)
135 const canvas = blank()
136 stamp(canvas, body.map(r => r.join('')), ox, oy)
137
138 if (isWorking && act === 'laptop') {
139 // Typing: the lid faces us, his arms tap the keys in turn and the screen's glow flickers on the lid's edge.
140 stamp(canvas, LAPTOP, ox + 3, oy + 6)
141 put(canvas, ox + (f % 2 === 0 ? 1 : 15), oy + 6, 'C')
142 if (f % 3 !== 0) put(canvas, ox + 4 + (f % 7), oy + 5, 'b')
143 }
144 if (isWorking && act === 'hammer') {
145 if (f % 4 < 2) {
146 put(canvas, ox + 16, oy + 1, 'w')
147 put(canvas, ox + 16, oy, 'w')
148 stamp(canvas, ['GGG', 'GGG'], ox + 15, oy - 2)
149 } else {
150 put(canvas, ox + 17, oy + 5, 'w')
151 put(canvas, ox + 17, oy + 6, 'w')
152 stamp(canvas, ['GG', 'GG'], ox + 16, oy + 7)
153 if (f % 4 === 2) put(canvas, ox + 15, oy + 9, 'y')
154 }
155 }
156 if (isWorking && act === 'magnify') {
157 // The lens drifts over his right eye, which looks bigger behind the glass.
158 const bob = f % 4 < 2 ? 0 : 1
159 stamp(canvas, LENS, ox + 11, oy + 1 + bob)
160 stamp(canvas, ['EE', 'EE'], ox + 12, oy + 2 + bob)
161 put(canvas, ox + 15, oy + 5 + bob, 'w')
162 }
163 if (isWorking && act === 'notes') {
164 stamp(canvas, PAPER, ox + 6, oy + 5)
165 // Ticks land on the page's lines one by one.
166 if (f % 3 >= 1) put(canvas, ox + 7, oy + 6, 'n')
167 if (f % 3 >= 2) put(canvas, ox + 7, oy + 8, 'n')
168 }
169 if (isWorking && act === 'web') {
170 put(canvas, ox + 8, oy - 1, 'G')
171 put(canvas, ox + 8, oy - 2, f % 2 === 0 ? 'r' : 'y')
172 if (f % 4 < 2) {
173 put(canvas, ox + 6, oy - 2, 'b')
174 put(canvas, ox + 10, oy - 2, 'b')
175 } else {
176 put(canvas, ox + 5, oy - 1, 'b')
177 put(canvas, ox + 11, oy - 1, 'b')
178 }
179 }
180 if (isWorking && act === 'agents') {
181 // Little helpers hop beside his head while subagents run.
182 stamp(canvas, MINI, ox, oy - 2 + (f % 2))
183 stamp(canvas, MINI, ox + 14, oy - 1 - (f % 2))
184 }
185 if (isWorking && act === 'think') {
186 const bubbles: [number, number][] = [[ox + 13, oy - 1], [ox + 15, oy - 2], [ox + 17, oy - 2]]
187 bubbles.slice(0, (f % 4) + 1).forEach(([x, y]) => put(canvas, x, y, 'W'))
188 }
189 if (m === 'happy') {
190 stamp(canvas, CROWN, ox + 6, oy - 2)
191 for (let k = 0; k < 6; k++) {
192 const x = (f * 5 + k * 7) % W
193 const y = (f + k * 3) % H
194 if (canvas[y]![x] === undefined) put(canvas, x, y, CONFETTI[k % CONFETTI.length]!)
195 }
196 }
197 if (m === 'loved') stamp(canvas, HEART, ox + 6, oy - 2)
198 if (m === 'asleep' || isSlump) stamp(canvas, NIGHTCAP, ox + 3, oy - 2)
199 if (m === 'oops') put(canvas, ox + 15, oy + 1 + (f % 2), 'b')
200 if (m === 'idle' || isWorking) {
201 const free = (x: number, y: number, c: string) => canvas[y]?.[x] === undefined && put(canvas, x, y, c)
202 // Sweat runs down his left side, snow drifts down his right, a clock hand turns above his shoulder.
203 if (strain === 'hot') for (const dy of [0, 1]) free(ox, oy + (f % 4) + dy, 'b')
204 if (strain === 'cold') {
205 free(ox + 16, oy + (f % 4), 'W')
206 free(ox + 17, oy + ((f + 2) % 4), 'W')
207 }
208 if (strain === 'slow') {
209 stamp(canvas, ['ggg', 'gWg', 'ggg'], ox + 15, oy - 2)
210 const [hx, hy] = [[1, 0], [2, 1], [1, 2], [0, 1]][f % 4]!
211 put(canvas, ox + 15 + hx!, oy - 2 + hy!, 'r')
212 }
213 }
214 return canvas
215}
216
217// A cue replaces his whole pose: the same Clawd bent, raised or seated, with what he holds or what moves around him.
218// His row list picks which of his rows to draw (repeating one stretches him, skipping one squashes him) and bend
219// widens (1) or narrows (-1) everything above his legs. His body is always anchored to the bottom of the box.
220type Pose = { c: Pixels; ox: number; oy: number }
221const ALL_ROWS = CLAWD.map((_, i) => i)
222const BOTH = [...ARM_COLS.left, ...ARM_COLS.right]
223const pose = ({ dx = 0, dy = 0, rows = ALL_ROWS, bend = 0 }: { dx?: number; dy?: number; rows?: number[]; bend?: -1 | 0 | 1 } = {}): Pose => {
224 const base = draw('idle', 'think', 0)
225 const oy = H - rows.length + dy
226 const c = blank()
227 rows.forEach((src, i) => {
228 const row = base[TOP + src]!
229 for (let x = 0; x < W; x++) {
230 const [l, px, r] = [row[x - 1], row[x], row[x + 1]]
231 const v = src >= LEG_ROW - 1 || bend === 0 ? px : bend > 0 ? px ?? (l || r ? 'C' : undefined) : l && px && r ? px : undefined
232 if (v) put(c, x + dx, oy + i, v)
233 }
234 })
235 return { c, ox: LEFT + dx, oy }
236}
237const wipe = (c: Pixels, x: number, y: number) => {
238 if (c[y]) c[y]![x] = undefined
239}
240const eyes = ({ c, ox, oy }: Pose, how: 'shut' | 'down' | 'left' | 'right' | 'x') => {
241 for (const col of EYE_COLS) {
242 for (const row of EYE_ROWS) put(c, ox + col, oy + row, 'C')
243 if (how === 'x') stamp(c, ['E.E', '.E.', 'E.E'], ox + col - 1, oy + EYE_ROWS[0]! - 1)
244 else if (how !== 'shut') for (const row of how === 'down' ? [EYE_ROWS[1]!] : EYE_ROWS) put(c, ox + col + (how === 'left' ? -1 : how === 'right' ? 1 : 0), oy + row, 'E')
245 }
246}
247const raise = ({ c, ox, oy }: Pose, cols: number[]) => {
248 for (const col of cols) {
249 for (const row of ARM_ROWS) wipe(c, ox + col, oy + row)
250 for (const row of EYE_ROWS) put(c, ox + col, oy + row, 'C')
251 }
252}
253const tap = ({ c, ox, oy }: Pose, f: number) => {
254 for (const col of f % 2 === 0 ? LEGS.inner : LEGS.outer) wipe(c, ox + col, oy + LEG_ROW)
255}
256
257const QUESTION = ['yyy', '..y', '.y.', '...', '.y.']
258const BANG = ['r', 'r', '.', 'r']
259const SMOKE: [number, number][] = [[13, -1], [14, -2], [12, -2], [14, -1]]
260const CHECK = ['..n', 'n.n', '.n.']
261const CROSS = ['r.r', '.r.', 'r.r']
262const TALL = [0, 1, 1, 2, 3, 4, 5, 6, 7, 7, 8, 9]
263const SQUASH = [0, 2, 3, 4, 5, 7, 8, 9]
264const SQUEEZE: [number[], -1 | 0 | 1, number][] = [
265 [ALL_ROWS, 0, 0], [ALL_ROWS, 0, 1], [ALL_ROWS, 0, 1], [ALL_ROWS, -1, 1], [TALL, -1, 1], [SQUASH, 1, 1], [ALL_ROWS, -1, 1], [ALL_ROWS, 0, 0], [ALL_ROWS, 0, 0],
266]
267const DIGITS = ['yyy/y.y/y.y/y.y/yyy', '.y./yy./.y./.y./yyy', 'yyy/..y/yyy/y../yyy', 'yyy/..y/yyy/..y/yyy', 'y.y/y.y/yyy/..y/..y', 'yyy/y../yyy/..y/yyy', 'yyy/y../yyy/y.y/yyy', 'yyy/..y/..y/.y./.y.', 'yyy/y.y/yyy/y.y/yyy', 'yyy/y.y/yyy/..y/yyy']
268const AGENTS_SHOWN = 3
269const MUG = ['ww.', 'www', 'ww.']
270const PAGE_LINES = [4, 2, 5, 1, 4, 3, 5, 2]
271const CLOUD = ['..ggggggg..', '.ggggggggg.']
272const RAIN_COLS = [3, 7, 10, 15]
273const BURST = [
274 ['...o....', '..oWo...', '...o....', '........'],
275 ['.o.o.o..', '.ooWoo..', '.o.o.o..', '...o....'],
276 ['o..o..o.', '.o...o..', 'o.....o.', '...o....'],
277 ['o.....o.', '........', 'o.....o.', '........'],
278]
279const FLAG_DY = [0, 1, 1, 0, 0, -1, 1, 0, 0, 0]
280const FLAG_POLE = [0, 2, 5, 8, 10, 10, 10, 10, 10, 10]
281const FLAG_CHEER = [4, 5, 7, 8]
282const FIREWORK_DY = [0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0]
283
284// One volley is a rocket up the box's edge, then an eight-by-four burst across the corner that opens and fades; he only dips, never rises, so the rows above his head stay clear; g counts frames
285// since it left. It is drawn behind him, on empty pixels only, so his head, eyes and arms are never covered.
286const fire = (c: Pixels, isRight: boolean, g: number, color: string) => {
287 const spark = (x: number, y: number, v: string) => {
288 const col = isRight ? W - 1 - x : x
289 if (c[y]?.[col] === undefined) put(c, col, y, v)
290 }
291 if (g >= 0 && g < 2) {
292 spark(0, 4 - g, color)
293 spark(0, 5 - g, 'W')
294 } else if (g >= 2 && g < 6) BURST[g - 2]!.forEach((row, y) => [...row].forEach((v, x) => v !== '.' && spark(x, y, v === 'o' ? color : v)))
295}
296
297// ms and n match the terminal's cue, rest is the frame shown when motion is off, say names it for a screen reader.
298export const PIXEL_CUES: Record<Cue, { ms: number; n: number; rest: number; say: string; art: (f: number, clones: number) => Pixels }> = {
299 perm: {
300 ms: 180, n: 6, rest: 0, say: 'waiting for you',
301 art: f => {
302 const p = pose()
303 raise(p, ARM_COLS.left)
304 tap(p, f)
305 stamp(p.c, QUESTION, p.ox + 15, f % 2)
306 return p.c
307 },
308 },
309 error: {
310 ms: 170, n: 9, rest: 6, say: 'error',
311 art: f => {
312 const p = pose({ dx: [0, 0, 1, -1, 1, 0, 0, 0, 0][f]!, dy: f === 1 ? 1 : 0 })
313 if (f > 0) eyes(p, 'x')
314 for (const [x, y] of SMOKE.slice(0, [0, 1, 2, 3, 4, 2, 0, 0, 0][f]!)) put(p.c, p.ox + x, p.oy + y, 'g')
315 if (f >= 4) stamp(p.c, BANG, W - 1, TOP)
316 return p.c
317 },
318 },
319 pass: {
320 ms: 190, n: 8, rest: 3, say: 'tests passed',
321 art: f => {
322 const p = pose({ dy: [1, -1, 0, 0, -1, 0, 0, 0][f]! })
323 if (f > 0) {
324 raise(p, f === 1 ? ARM_COLS.right : BOTH)
325 stamp(p.c, CHECK, p.ox + 15, p.oy - 1)
326 }
327 return p.c
328 },
329 },
330 fail: {
331 ms: 190, n: 8, rest: 2, say: 'tests failed',
332 art: f => {
333 const p = pose({ dx: [0, -1, 1, -1, 1, 0, 0, 0][f]!, dy: 1 })
334 eyes(p, f >= 5 ? 'shut' : 'down')
335 raise(p, ARM_COLS.right)
336 stamp(p.c, CROSS, p.ox + 15, p.oy - 1)
337 return p.c
338 },
339 },
340 compact: {
341 ms: 120, n: 9, rest: 3, say: 'compacting',
342 art: f => {
343 const [rows, bend, gap] = SQUEEZE[f]!
344 const { c } = pose({ rows, bend })
345 stamp(c, ['b.', 'bb', 'b.'], gap, 8)
346 stamp(c, ['.b', 'bb', '.b'], W - 2 - gap, 8)
347 return c
348 },
349 },
350 limit: {
351 ms: 300, n: 8, rest: 3, say: 'rate limited',
352 art: f => {
353 const p = pose({ rows: ALL_ROWS.slice(0, LEG_ROW) })
354 eyes(p, f % 2 ? 'shut' : 'down')
355 stamp(p.c, ['ggg', `g${f < 5 ? 'y' : '.'}g`, f < 7 ? '.y.' : '.g.', `g${f >= 3 ? 'y' : '.'}g`, 'ggg'], p.ox + 15, 1)
356 return p.c
357 },
358 },
359 agents: {
360 ms: 200, n: 4, rest: 1, say: 'subagents running',
361 art: (f, clones) => {
362 const p = pose()
363 if (f === 1) raise(p, BOTH)
364 for (let i = 0; i < Math.min(clones, AGENTS_SHOWN); i++) stamp(p.c, [MINI[0]!, (f + i) % 2 ? '.C.' : MINI[1]!], p.ox + 3 + i * 4, 0)
365 stamp(p.c, DIGITS[Math.min(clones, 9)]!.split('/'), p.ox + 15, 1)
366 return p.c
367 },
368 },
369 coffee: {
370 ms: 250, n: 8, rest: 0, say: 'on a long tool run',
371 art: f => {
372 const p = pose()
373 const lift = [0, 0, 1, 2, 2, 1, 0, 0][f]!
374 if (lift === 2) eyes(p, 'shut')
375 const top = p.oy + 4 - lift
376 stamp(p.c, MUG, p.ox + 15, top)
377 put(p.c, p.ox + 15 + (f % 2), top - 1, 'g')
378 put(p.c, p.ox + 16 - (f % 2), top - 2, 'g')
379 return p.c
380 },
381 },
382 bigfile: {
383 ms: 125, n: 24, rest: 0, say: 'reading a big file',
384 art: f => {
385 const p = pose()
386 const [first, step] = [Math.floor(f / 4), f % 4]
387 eyes(p, step === 3 ? 'left' : 'right')
388 const [a, b] = [0, 1].map(i => PAGE_LINES[(first + i) % PAGE_LINES.length]!) as [number, number]
389 const done = step < 3 ? Math.ceil((b * (step + 1)) / 3) : b
390 const line = (len: number, read = 0) => `W${'n'.repeat(read)}${'G'.repeat(len - read)}${'W'.repeat(5 - len)}W`
391 stamp(p.c, ['WWWWWWW', line(a), 'WWWWWWW', line(b, done), 'WWWWWWW'], p.ox + 5, p.oy + 5)
392 return p.c
393 },
394 },
395 offline: {
396 ms: 160, n: 8, rest: 0, say: 'offline',
397 art: f => {
398 const p = pose()
399 if (f % 4 === 3) eyes(p, 'shut')
400 stamp(p.c, CLOUD, p.ox + 4, 0)
401 RAIN_COLS.forEach((x, k) => put(p.c, p.ox + x, p.oy + ((f + k) % 4), 'b'))
402 if (f === 6) stamp(p.c, ['.y', 'yy', 'y.'], p.ox + 7, p.oy)
403 return p.c
404 },
405 },
406 flag: {
407 ms: 150, n: 10, rest: 9, say: 'planting a flag',
408 art: f => {
409 const p = pose({ dy: FLAG_DY[f]! })
410 if (FLAG_CHEER.includes(f)) raise(p, BOTH)
411 for (let i = 0; i < FLAG_POLE[f]!; i++) put(p.c, W - 1, H - 1 - i, 'w')
412 if (FLAG_POLE[f] === 10) stamp(p.c, ['rr', 'rr'], W - 3, TOP)
413 return p.c
414 },
415 },
416 hello: {
417 ms: 100, n: 18, rest: 12, say: 'saying hello',
418 art: f => {
419 const p = pose({ dx: f < 5 ? -1 : 0 })
420 if (f < 10) {
421 tap(p, f)
422 eyes(p, 'right')
423 } else if (f < 16) {
424 const isWave = f % 2 === 0
425 if (isWave) raise(p, ARM_COLS.right)
426 stamp(p.c, ['WWW', `W${isWave ? 'y' : 'G'}W`, 'WWW'], p.ox + 15, 0)
427 }
428 return p.c
429 },
430 },
431 fireworks: {
432 ms: 130, n: 12, rest: 5, say: 'celebrating',
433 art: f => {
434 const p = pose({ dy: FIREWORK_DY[f]! })
435 if (f > 1 && f < 11) raise(p, BOTH)
436 fire(p.c, true, f, 'y')
437 fire(p.c, false, f - 1, 'r')
438 fire(p.c, true, f - 6, 'b')
439 fire(p.c, false, f - 6, 'n')
440 return p.c
441 },
442 },
443}
444
445export const colorOf = (c: string | undefined, body: number) => (c === undefined ? undefined : c === 'C' ? body : PALETTE[c])
446
447export const hex = (c: number) => `#${c.toString(16).padStart(6, '0')}`
448
449// Each run of same-colored pixels in a row becomes one rect, which keeps a whole loop of frames small.
450export const PX = 4
451const rectsOf = (px: Pixels, body: number) =>
452 px.flatMap((row, y) => {
453 const runs: string[] = []
454 for (let x = 0; x < W;) {
455 const color = colorOf(row[x], body)
456 let end = x + 1
457 while (end < W && colorOf(row[end], body) === color) end++
458 if (color !== undefined) runs.push(`<rect x="${x * PX}" y="${y * PX}" width="${(end - x) * PX}" height="${PX}" fill="${hex(color)}"/>`)
459 x = end
460 }
461 return runs
462 }).join('')
463
464// The desktop's Clawd is one Svg that animates itself: each distinct frame is a group shown for its slice of the
465// loop, so the page never swaps the picture. A click on him plays the loved jump with a heart, all inside the Svg.
466// A cue loops its own frames in place of his mood's; with motion off it holds its rest frame.
467export const toSvg = (m: Mood, act: Activity, body: number, isStill: boolean, strain: Strain = 'none', cue: { name: Cue; clones: number } | null = null) => {
468 const spec = cue && PIXEL_CUES[cue.name]
469 const n = isStill ? 1 : spec?.n ?? LOOP[m]
470 const frames = Array.from({ length: n }, (_, f) => rectsOf(spec ? spec.art(isStill ? spec.rest : f, cue!.clones) : draw(m, act, f, strain), body))
471 const spans: { rects: string; from: number; to: number }[] = []
472 frames.forEach((rects, f) => {
473 const last = spans.at(-1)
474 if (last?.rects === rects) last.to = f + 1
475 else spans.push({ rects, from: f, to: f + 1 })
476 })
477 const dur = (n * (spec?.ms ?? FRAME_MS[m])) / 1000
478 const groups = spans.length === 1
479 ? `<g>${spans[0]!.rects}</g>`
480 : spans.map(s => `<g opacity="0">${s.rects}<animate attributeName="opacity" calcMode="discrete" dur="${dur}s" repeatCount="indefinite" keyTimes="0;${s.from / n};${s.to / n}" values="0;1;0"/></g>`).join('')
481 const loved = rectsOf(draw('loved', act, 0), body)
482 const tap = isStill ? '' : `<g opacity="0">${loved}<set attributeName="opacity" to="1" begin="hit.click" dur="0.9s"/><animateTransform attributeName="transform" type="translate" values="0 0;0 -8;0 0;0 -4;0 0" begin="hit.click" dur="0.9s"/></g><animate href="#mood" attributeName="opacity" values="0;0" begin="hit.click" dur="0.9s"/>`
483 return `<svg xmlns="http://www.w3.org/2000/svg" width="${W * PX}" height="${H * PX}" shape-rendering="crispEdges"><g id="mood">${groups}</g>${tap}<rect id="hit" width="${W * PX}" height="${H * PX}" fill="transparent" style="cursor:pointer"/></svg>`
484}
485hooks/clawd-cues.ts 205 lines1import type { Cue } from '../types'
2import { AIR, BODY, CHEER, COLS, FEET, HEAD, marksOf, place, ROWS, SHUT, STAND } from './clawd-moves'
3import type { Frame, Sprite } from './clawd-moves'
4
5// A cue is Clawd's whole look for a state: his sprite in the middle, a column of cells on each side, and pins drawn over him.
6// Every cell is one character, so a cue never leaves the box of its two columns and nine cells.
7export type Tint = number | 'body'
8export type Seg = [text: string, tint?: Tint]
9export type Col = (Seg[] | '')[]
10export type Pin = [row: number, col: number, text: string, tint: number]
11export type CueFrame = Frame & { left?: Col; right?: Col; pins?: Pin[] }
12export type Cell = { ch: string; tint?: Tint; isDim?: boolean }
13type Ctx = { clones: number; hash: string }
14export type CueDef = { ms: number; lw: number; rw: number; tint: number; rest: number; frames: (ctx: Ctx) => CueFrame[] }
15
16const GREY = 0xb8bcc4
17const AMBER = 0xf5c542
18const GREEN = 0x5fd38d
19const RED = 0xff6b6b
20const BLUE = 0x7aa2f7
21const CYAN = 0x9ad0ff
22const PINK = 0xe07ab0
23const ORANGE = 0xf0883e
24const PURPLE = 0xc792ea
25const MINT = 0x7fd1ae
26const DIM = 0x7d7d85
27const BROWN = 0xc8935a
28const CLOUD = 0x9aa0aa
29
30const SKIN = 'body'
31const t = (text: string, tint?: Tint): Seg => [text, tint]
32const frame = (rows: Sprite, extra: Omit<CueFrame, 'rows'> = {}): CueFrame => ({ rows, ...extra })
33const crouch = (rows: Sprite, extra: Omit<CueFrame, 'rows'> = {}) => frame(rows, { offset: 1, dust: true, ...extra })
34
35// Waiting on you: an arm up and a ? bouncing beside it.
36const ASK_UP: Col = [[t('▗', SKIN), t(' ?', PINK)], [t('▐', SKIN)], '']
37const ASK_MID: Col = [[t('▗', SKIN)], [t('▐', SKIN), t(' ?', PINK)], '']
38const asking = (feet: string, head: string, right: Col) => frame([head, BODY.left, feet], { right })
39const PERM = [
40 asking(FEET.tapLeft, HEAD.open, ASK_MID), asking(FEET.tapLeft, HEAD.open, ASK_UP), asking(FEET.tapRight, HEAD.open, ASK_UP),
41 asking(FEET.tapRight, HEAD.open, ASK_MID), asking(FEET.tapLeft, HEAD.right, ASK_MID), asking(FEET.tapRight, HEAD.right, ASK_UP),
42]
43
44// Tool error: x eyes over the head cells, a smoke puff, then a red ! that holds.
45const X_EYES: Pin[] = [[0, 3, 'x', RED], [0, 5, 'x', RED]]
46const dead = (extra: Omit<CueFrame, 'rows'>, right: Col) => frame(STAND, { pins: X_EYES, right, ...extra })
47const ERROR = [
48 frame(STAND),
49 dead({ offset: 1, dust: true }, ['', '', [t(' ∘', GREY)]]),
50 dead({ x: 1 }, ['', [t(' ○', GREY)], '']),
51 dead({ x: -1 }, [[t(' ◯', GREY)], [t(' ○', GREY)], '']),
52 dead({ x: 1 }, [[t(' ◯', GREY)], [t(' !', RED)], '']),
53 dead({}, [[t(' ◌', GREY)], [t(' !', RED)], '']),
54 dead({}, ['', [t(' !', RED)], '']),
55 dead({}, ['', [t(' !', RED)], '']),
56 dead({}, ['', [t(' !', RED)], '']),
57]
58
59// Test verdict: a hop and a check, or a droop and a cross, on a little sign.
60const sign = (mark: string, tint: number): Col => [[t(' ┌─┐', GREY)], [t(' │', GREY), t(mark, tint), t('│', GREY)], [t(' └┬┘', GREY)]]
61const SLUMP: Sprite = [HEAD.down, BODY.rest, FEET.stand]
62const ticked = (rows: Sprite) => frame(rows, { right: sign('✔', GREEN) })
63const PASS = [crouch(STAND), ticked(AIR), ticked(CHEER), ticked(CHEER), ticked(AIR), ticked(CHEER), ticked(CHEER), ticked(CHEER)]
64const crossed = (rows: Sprite, x = 0) => frame(rows, { x, right: sign('✘', RED) })
65const FAIL = [crossed(SLUMP), crossed(SLUMP, -1), crossed(SLUMP, 1), crossed(SLUMP, -1), crossed(SLUMP, 1), crossed(SHUT), crossed(SHUT), crossed(SHUT)]
66
67// Compacting: arrows close in on him, he pinches tall, then springs wide.
68const PINCH: Sprite = [' ▐▛█▜▌ ', ' ▝▜███▛▘ ', ' ▘▘ ▝▝ ']
69const PINCH_TALL: Sprite = [' ▐█▌ ', ' ▝▜█▛▘ ', ' ▘ ▝ ']
70const SQUASH: Sprite = [' ', '▐▛█████▜▌', ' ▀▀▀▀▀▀▀ ']
71const squeeze = (gap: number, rows: Sprite) => frame(rows, { left: ['', [t(' '.repeat(gap) + '▶', CYAN)], ''], right: ['', [t(' '.repeat(3 - gap) + '◀', CYAN)], ''] })
72const COMPACT = [
73 squeeze(0, STAND), squeeze(1, STAND), squeeze(2, STAND), squeeze(3, PINCH), squeeze(3, PINCH_TALL),
74 squeeze(2, SQUASH), squeeze(1, PINCH), squeeze(0, STAND), squeeze(0, STAND),
75]
76
77// Rate limited: he sits and waits while the sand runs out.
78const SAND_TOP = ['▀▀▀', '▀▀▀', '▀▀ ', ' ▀▀', ' ▀ ', ' ▀ ', ' ·', ' ']
79const SAND_LOW = ['▁▁▁', '▁▁▁', '▂▂▂', '▂▂▂', '▃▃▃', '▃▃▃', '▄▄▄', '▄▄▄']
80const LIMIT = SAND_TOP.map((top, i) =>
81 frame([i % 2 ? HEAD.shut : HEAD.down, BODY.rest, FEET.sit], { right: [[t(` ${top}`, AMBER)], [t(i < 7 ? ' ┊' : ' ', AMBER)], [t(` ${SAND_LOW[i]}`, AMBER)]] }))
82
83// Subagents busy: one tiny clone per running subagent, at most three drawn, the real number beside them.
84const clonePair = (slot: number, shown: number, isPop: boolean) => (slot < shown ? t('▟▙', PINK) : slot === shown && isPop ? t(' ✦', AMBER) : t(' ', PINK))
85const clones = (shown: number, count: number, isPop: boolean) => frame([HEAD.open, isPop ? BODY.both : BODY.rest, FEET.stand], {
86 right: [[t(` ×${count}`, PINK)], [t(' ', PINK), clonePair(2, shown, isPop), t(' ', PINK), clonePair(1, shown, isPop)], [t(' ', PINK), clonePair(0, shown, isPop)]],
87})
88const AGENTS_SHOWN = 3
89
90// Long tool run: he sips coffee while the steam curls.
91const cup = (pad: number, steam: string, head: string) => frame([head, BODY.right, FEET.stand], {
92 right: [[t(' '.repeat(pad + 1) + steam, GREY)], [t(' '.repeat(pad) + '╭─╮)', BROWN)], [t(' '.repeat(pad) + '╰─╯', BROWN)]],
93})
94const COFFEE = [
95 cup(2, '∿', HEAD.open), cup(2, '~', HEAD.open), cup(1, '∿', HEAD.open), cup(0, '~', HEAD.shut),
96 cup(0, '∿', HEAD.shut), cup(1, '~', HEAD.open), cup(2, '∿', HEAD.open), cup(2, '~', HEAD.shut),
97]
98
99// Reading a big file: his eyes sweep a line, snap back, and the page scrolls.
100const BARS = ['▬▬▬▬▬', '▬▬▬', '▬▬▬▬▬▬▬', '▬▬', '▬▬▬▬▬▬', '▬▬▬▬', '▬▬▬▬▬▬▬▬', '▬▬▬']
101const scan = (f: number) => {
102 const first = Math.floor(f / 4)
103 const step = f % 4
104 const bar = (i: number) => BARS[(first + i) % BARS.length]!
105 const current = bar(1)
106 const read = step < 3 ? Math.ceil((current.length * (step + 1)) / 3) : current.length
107 return frame([step === 3 ? HEAD.left : HEAD.right, BODY.rest, FEET.stand], {
108 right: [[t(` ${bar(0)}`, DIM)], [t('▸ ', MINT), t(current.slice(0, read), MINT), t(current.slice(read), DIM)], [t(` ${bar(2)}`, DIM)]],
109 })
110}
111const BIG_FILE = Array.from({ length: 24 }, (_, f) => scan(f))
112
113// Offline: a private rain cloud with a lightning flash.
114const RAIN = [' ╷ ╷ ', ' ╷ ╷ ╷ ', ' ╵ ╵ ', ' ╵ ╵ ╵ ']
115const OFFLINE = Array.from({ length: 8 }, (_, f) => frame([f % 4 === 3 ? HEAD.shut : HEAD.right, BODY.rest, FEET.stand], {
116 right: [[t(' ▗██▖', CLOUD)], f === 6 ? [t(' ▟█', CLOUD), t('↯', AMBER), t('█▙', CLOUD)] : [t(' ▟███▙', CLOUD)], [t(RAIN[f % 4]!, BLUE)]],
117}))
118
119// Plants a flag: the pole goes up, the flag opens and the short hash types in beside it.
120const flagged = (pole: number, hasFlag: boolean, hash: string): Col => [
121 hasFlag ? [t(' ⚑', ORANGE)] : '',
122 pole >= 2 ? [t(' ┃', ORANGE), t(hash && ` ${hash}`, GREY)] : '',
123 pole >= 1 ? [t(' ┃', ORANGE)] : '',
124]
125const flag = (hash: string) => [
126 frame(STAND), crouch(SHUT, { right: flagged(1, false, '') }), crouch(STAND, { right: flagged(2, false, '') }), frame(STAND, { right: flagged(2, true, '') }),
127 frame(CHEER, { right: flagged(2, true, hash.slice(0, 2)) }), frame(AIR, { right: flagged(2, true, hash.slice(0, 4)) }),
128 crouch(STAND, { right: flagged(2, true, hash) }), frame(CHEER, { right: flagged(2, true, hash) }), frame(CHEER, { right: flagged(2, true, hash) }),
129 frame(STAND, { right: flagged(2, true, hash) }),
130]
131
132// Hello: he walks in from the left edge on the real walk frames, waves and says hi.
133const HELLO = [
134 ...[-8, -6, -4, -2, 0].flatMap(x => [frame([HEAD.right, BODY.rest, FEET.tapLeft], { x }), frame([HEAD.right, BODY.rest, FEET.tapRight], { x })]),
135 ...[BODY.right, BODY.left, BODY.right, BODY.left, BODY.right, BODY.left].map((body, i) => frame([HEAD.open, body, FEET.stand], { right: [[t(i % 2 ? ' hi!' : ' hi', AMBER)], '', ''] })),
136 frame(STAND), frame(STAND),
137]
138
139// Big finish: two volleys of fireworks, then a cheer.
140const burstRight = (step: number, tint: number): Col =>
141 [[' ', ' ✦ ', ' '], [' · ', ' · ✦ · ', ' · '], ['· ✧ ·', '✧ ✦ ✧', '· ✧ ·'], ['· ·', ' ', '· ·']][step]!.map(row => [t(` ${row}`, tint)])
142const burstLeft = (step: number, tint: number): Col =>
143 [[' ', ' ✦ ', ' '], [' · ', ' ·✦· ', ' · '], ['· ·', ' ✧ ', '· ·'], [' ', '· ·', ' ']][step]!.map(row => [t(row, tint)])
144const rocket = (row: number, text: string, tint: number): Col => [0, 1, 2].map(r => (r === row ? [t(text, tint)] : ''))
145const show = (rows: Sprite, right: Col | undefined, left: Col | undefined, extra: Omit<CueFrame, 'rows'> = {}) => frame(rows, { right, left, ...extra })
146const FIREWORKS = [
147 show(STAND, rocket(2, ' ╷', AMBER), undefined),
148 show(STAND, rocket(1, ' ╷', AMBER), rocket(2, ' ╷', PINK), { offset: 1, dust: true }),
149 show(AIR, rocket(0, ' ╷', AMBER), rocket(1, ' ╷', PINK)),
150 show(CHEER, burstRight(0, AMBER), rocket(0, ' ╷', PINK)),
151 show(AIR, burstRight(1, AMBER), burstLeft(0, PINK)),
152 show(CHEER, burstRight(2, AMBER), burstLeft(1, PINK)),
153 show(CHEER, burstRight(3, AMBER), burstLeft(2, PINK)),
154 show(AIR, undefined, burstLeft(3, PINK)),
155 show(CHEER, burstRight(0, PURPLE), burstLeft(0, MINT)),
156 show(CHEER, burstRight(1, PURPLE), burstLeft(1, MINT)),
157 show(CHEER, burstRight(2, PURPLE), burstLeft(2, MINT)),
158 show(STAND, burstRight(3, PURPLE), burstLeft(3, MINT)),
159]
160
161// `ms` is one frame, `lw` and `rw` the width of the columns, `rest` the frame shown when motion is off.
162export const CUES: Record<Cue, CueDef> = {
163 perm: { ms: 180, lw: 0, rw: 8, tint: PINK, rest: 0, frames: () => PERM },
164 error: { ms: 170, lw: 0, rw: 8, tint: GREY, rest: 6, frames: () => ERROR },
165 pass: { ms: 190, lw: 0, rw: 8, tint: GREY, rest: 3, frames: () => PASS },
166 fail: { ms: 190, lw: 0, rw: 8, tint: GREY, rest: 2, frames: () => FAIL },
167 compact: { ms: 120, lw: 4, rw: 4, tint: CYAN, rest: 3, frames: () => COMPACT },
168 limit: { ms: 300, lw: 0, rw: 5, tint: AMBER, rest: 3, frames: () => LIMIT },
169 agents: {
170 ms: 200, lw: 0, rw: 9, tint: PINK, rest: 1,
171 frames: ({ clones: count }) => [false, true, false, false].map(isPop => clones(Math.min(count, AGENTS_SHOWN), count, isPop)),
172 },
173 coffee: { ms: 250, lw: 0, rw: 7, tint: GREY, rest: 0, frames: () => COFFEE },
174 bigfile: { ms: 125, lw: 0, rw: 10, tint: DIM, rest: 0, frames: () => BIG_FILE },
175 offline: { ms: 160, lw: 0, rw: 8, tint: CLOUD, rest: 0, frames: () => OFFLINE },
176 flag: { ms: 150, lw: 0, rw: 10, tint: ORANGE, rest: 9, frames: ({ hash }) => flag(hash) },
177 hello: { ms: 100, lw: 0, rw: 6, tint: AMBER, rest: 12, frames: () => HELLO },
178 fireworks: { ms: 130, lw: 5, rw: 9, tint: AMBER, rest: 5, frames: () => FIREWORKS },
179}
180
181// A one-shot plays its frames once; these stay up for longer, because what they say outlasts one pass.
182const HOLD_MS: Partial<Record<Cue, number>> = { offline: 20_000, bigfile: 3_000 }
183export const playMs = (cue: Cue) => HOLD_MS[cue] ?? CUES[cue].frames({ clones: 1, hash: '' }).length * CUES[cue].ms
184
185const cellsOf = (col: Col[number] | undefined, width: number, tint: number): Cell[] => {
186 const cells = (col || []).flatMap(([text, own]) => [...text].map(ch => ({ ch, tint: own ?? tint })))
187 return Array.from({ length: width }, (_, i) => cells[i] ?? { ch: ' ', tint })
188}
189
190// The three rows of a frame as cells: left column, sprite, right column. A pin sits over the sprite where he stands now.
191export const cueRows = (def: CueDef, fr: CueFrame): Cell[][] => {
192 const sprite = place(fr)
193 const marks = marksOf(fr)
194 const lead = Math.max(def.lw, 1)
195 return Array.from({ length: ROWS }, (_, r) => {
196 const body: Cell[] = [...sprite[r]!].map(ch => ({ ch, tint: SKIN }))
197 for (const m of marks) if (m.row === r) [...m.text].forEach((ch, i) => void (body[m.col + i] = { ch, isDim: true }))
198 for (const [row, col, ch, tint] of fr.pins ?? []) {
199 const c = col + (fr.x ?? 0)
200 if (row + (fr.offset ?? 0) === r && c >= 0 && c < COLS) body[c] = { ch, tint }
201 }
202 return [...cellsOf(fr.left?.[r], lead, def.tint), ...body, ...cellsOf(fr.right?.[r], def.rw, def.tint)]
203 })
204}
205hooks/clawd-term.tsx 199 lines1import type { ClientModule } from 'claude-code'
2
3import type { Activity, Cue, Mood, Scene, Strain } from '../types'
4import { FRAME_MS, hex, idleGesture, LOOP, SKINS } from './clawd'
5import { CUES, cueRows } from './clawd-cues'
6import type { Cell } from './clawd-cues'
7import { BODY, CLICK_MS, CLICKS, dealClicks, FEET, HEAD, marksOf, place } from './clawd-moves'
8import type { Frame, Mark, Sprite } from './clawd-moves'
9
10// `scene` is refreshed on every draw so the one ticker always plays the latest mood.
11type Local = { scene: Scene; frame: number; elapsed: number; click?: { name: string; step: number }; deck: string[]; last?: string; cue: Cue | null; mood: Mood }
12
13const TICK_MS = 30
14const PROP_W = 5
15
16// What he is doing reads beside him: a glyph in its own color and a word.
17const DOING: Record<Activity, { glyph: string; word: string; color: number }> = {
18 think: { glyph: '…', word: 'thinking', color: 0xb8bcc4 },
19 laptop: { glyph: '⌨', word: 'typing', color: 0x7aa2f7 },
20 hammer: { glyph: '✎', word: 'editing', color: 0xf5c542 },
21 magnify: { glyph: '⌕', word: 'reading', color: 0x7fd1ae },
22 web: { glyph: '◎', word: 'browsing', color: 0x7aa2f7 },
23 agents: { glyph: '⚑', word: 'delegating', color: 0xe07ab0 },
24 notes: { glyph: '☑', word: 'planning', color: 0x5fd38d },
25 test: { glyph: '◔', word: 'testing', color: 0x5fd38d },
26 git: { glyph: '◆', word: 'git', color: 0xf0883e },
27 install: { glyph: '↓', word: 'installing', color: 0x7fd1ae },
28 build: { glyph: '▤', word: 'building', color: 0xf5c542 },
29 ask: { glyph: '?', word: 'asking', color: 0xe07ab0 },
30 mcp: { glyph: '↯', word: 'connecting', color: 0x7aa2f7 },
31 skill: { glyph: '✦', word: 'casting', color: 0xc792ea },
32 plan: { glyph: '◇', word: 'drafting', color: 0xb8bcc4 },
33}
34
35// One frame: the sprite, the prop beside him (one cell per row, PROP_W wide) and the prop's color.
36type Look = Frame & { prop: string[]; tint: number }
37
38const GREY = 0xb8bcc4
39const GOLD = 0xf5c542
40const RED = 0xe5484d
41const at = (row: number, text: string) => [0, 1, 2].map(r => (r === row ? text : ''))
42const look = (head: string, body: string, feet: string, prop: string[], tint: number, extra: Omit<Frame, 'rows'> = {}): Look => ({ rows: [head, body, feet], prop, tint, ...extra })
43const SPARKS = ['✦', '✧', '⋆', '·']
44const ARC = ['◜', '◠', '◝', '◞', '◡', '◟']
45const arc = (i: number) => ARC[((i % ARC.length) + ARC.length) % ARC.length]!
46const alternate = (f: number, a: string, b: string, every = 1) => (Math.floor(f / every) % 2 === 0 ? a : b)
47
48// Each kind of work owns its motion. He only paces while thinking, so stepping never stands in for a prop.
49const WORK: Record<Activity, (f: number) => Look> = {
50 think: f => look(alternate(f, HEAD.left, HEAD.right, 4), BODY.rest, f % 2 ? FEET.step : FEET.stand, at(2 - Math.min(f % 4, 2), ['·', '∘', '○', '◯'][f % 4]!), DOING.think.color),
51 laptop: f => look(HEAD.down, alternate(f, BODY.right, BODY.left), FEET.desk, [0, 1, 2].map(r => '▬'.repeat((f + 2 * r) % 4)), DOING.laptop.color),
52 hammer: f => look(HEAD.open, f % 4 < 2 ? BODY.right : BODY.rest, FEET.stand, f % 4 < 2 ? ['▀█▀', ' █', ''] : ['', ' █', `▄█▄${f % 4 === 2 ? '✦' : '·'}`], DOING.hammer.color, f % 4 === 2 ? { offset: 1, dust: true } : {}),
53 magnify: f => look(alternate(f, HEAD.left, HEAD.right, 3), BODY.rest, FEET.stand, f % 4 < 2 ? ['◎', ' ╲', ''] : ['', '◎', ' ╲'], DOING.magnify.color),
54 web: f => look(HEAD.open, f % 4 < 2 ? BODY.both : BODY.rest, FEET.stand, at(0, `·${')'.repeat(f % 4)}`), DOING.web.color),
55 agents: f => look(HEAD.open, alternate(f, BODY.both, BODY.rest), FEET.stand, f % 2 ? ['', ' ▟▙', '▟▙'] : ['', '▟▙', ' ▟▙'], DOING.agents.color),
56 notes: f => look(HEAD.down, alternate(f, BODY.right, BODY.rest), FEET.stand, [0, 1, 2].map(r => (r < f % 4 ? '☑' : '☐')), DOING.notes.color),
57 test: f => look(HEAD.open, BODY.rest, alternate(f, FEET.tapLeft, FEET.tapRight), at(1, `${'▰'.repeat(f % 6)}${'▱'.repeat(5 - (f % 6))}`), DOING.test.color),
58 git: f => look(HEAD.open, alternate(f, BODY.right, BODY.rest, 2), FEET.stand, at(1, [0, 1, 2].map(i => (i === f % 3 ? '●' : '○')).join('─')), DOING.git.color),
59 install: f => look(HEAD.open, f % 3 === 2 ? BODY.both : BODY.rest, FEET.stand, [0, 1, 2].map(r => (r === 2 ? (f % 3 === 2 ? '╰▣╯' : '╰ ╯') : r === f % 3 ? ' ▣' : '')), DOING.install.color),
60 build: f => look(HEAD.down, alternate(f, BODY.left, BODY.right), FEET.stand, at(1, `${arc(f)} ${arc(-f)}`), DOING.build.color),
61 ask: f => look(HEAD.open, BODY.right, alternate(f, FEET.tapLeft, FEET.tapRight, 2), at(0, f % 2 ? ' ?' : '?'), DOING.ask.color),
62 mcp: f => look(HEAD.open, alternate(f, BODY.both, BODY.rest, 2), FEET.stand, at(1, ['─┤ ├─', '─┤↯├─', '─┤↯├─', '─┤ ├─'][f % 4]!), DOING.mcp.color),
63 skill: f => look(HEAD.open, BODY.right, FEET.stand, [0, 1, 2].map(r => (r === f % 3 ? ` ${SPARKS[f % SPARKS.length]}` : r === (f + 1) % 3 ? '⋆' : '')), DOING.skill.color),
64 plan: f => look(alternate(f, HEAD.left, HEAD.right, 4), BODY.rest, FEET.stand, at(0, f % 4 === 3 ? '◉' : '○'), DOING.plan.color),
65}
66
67// Idle blinks, wiggles an arm, glances both ways, hops and waves one arm with a greeting at uneven beats; the other moods are one loop each.
68const moodLook = (m: Mood, act: Activity, f: number): Look => {
69 switch (m) {
70 case 'working':
71 return WORK[act](f)
72 case 'happy': {
73 const beat = f % 4
74 const sparks = [0, 1, 2].map(r => `${' '.repeat(r % 2)}${SPARKS[(f + r) % SPARKS.length]}`)
75 return beat === 0 ? look(HEAD.open, BODY.rest, FEET.stand, sparks, GOLD, { offset: 1, dust: true })
76 : look(HEAD.open, BODY.both, beat === 3 ? FEET.stand : FEET.none, sparks, GOLD)
77 }
78 case 'drowsy': {
79 const beat = f % LOOP.drowsy
80 const isStretch = beat >= 2 && beat < 5
81 const isSlump = beat >= 6
82 return look(isStretch || beat === 7 ? HEAD.shut : HEAD.down, isStretch ? BODY.both : BODY.rest, isSlump ? FEET.sit : FEET.stand, at(isStretch ? 1 : 2, isStretch ? 'aah' : isSlump ? 'z' : ''), GREY)
83 }
84 case 'asleep':
85 return look(HEAD.shut, BODY.rest, FEET.sit, at(2 - (f % 3), f % 3 ? 'Z' : 'z'), GREY)
86 case 'oops':
87 return f % 2 ? look(HEAD.shut, BODY.rest, FEET.stand, at(0, ''), RED, { offset: 1, dust: true }) : look(HEAD.shut, BODY.both, FEET.stand, at(0, '!'), RED)
88 default: {
89 const g = idleGesture(f)
90 const head = g === 'blink' ? HEAD.shut : g === 'look-left' ? HEAD.left : g === 'look-right' ? HEAD.right : HEAD.open
91 const body = g === 'hop' ? BODY.both : g === 'wiggle-left' ? BODY.left : g === 'wiggle-right' || (g === 'wave' && f % 2 === 0) ? BODY.right : BODY.rest
92 return look(head, body, g === 'hop' ? FEET.none : FEET.stand, at(0, g === 'wave' ? 'hi!' : ''), GREY, g === 'hop' ? { shadow: true } : {})
93 }
94 }
95}
96
97// A strain shows in the cell left of him, one row at a time: sweat falls, snow falls, a clock hand turns.
98const STRAIN: Record<Exclude<Strain, 'none'>, { cells: string[]; color: number; row: (f: number) => number }> = {
99 hot: { cells: ['°'], color: 0x7aa2f7, row: f => f % 3 },
100 cold: { cells: ['*'], color: 0x9ad0ff, row: f => (f + 1) % 3 },
101 slow: { cells: ['◴', '◷', '◶', '◵'], color: GOLD, row: () => 0 },
102}
103
104// A row's cells, each marked dim where dust or a shadow was drawn over it, grouped into runs of one look.
105const runsOf = (row: string, r: number, marks: Mark[]) => {
106 const cells = [...row].map(ch => ({ ch, isDim: false }))
107 for (const m of marks) if (m.row === r) [...m.text].forEach((ch, i) => void (cells[m.col + i] = { ch, isDim: true }))
108 return cells.reduce<{ text: string; isDim: boolean }[]>((runs, c) => {
109 const last = runs.at(-1)
110 return last?.isDim === c.isDim ? (last.text += c.ch, runs) : [...runs, { text: c.ch, isDim: c.isDim }]
111 }, [])
112}
113
114// Cells grouped into runs of one look, so a row is a few Texts and not one per character.
115const cellRuns = (row: Cell[]) =>
116 row.reduce<{ text: string; tint: Cell['tint']; isDim: boolean }[]>((runs, c) => {
117 const last = runs.at(-1)
118 const isDim = c.isDim === true
119 return last && last.tint === c.tint && last.isDim === isDim ? (last.text += c.ch, runs) : [...runs, { text: c.ch, tint: c.tint, isDim }]
120 }, [])
121
122const Clawd: ClientModule<Scene, Local> = (scene, surface) => {
123 const { Box, Text } = surface.elements
124 const isFirst = surface.state === undefined
125 const live: Local = surface.state ?? { scene, frame: 0, elapsed: 0, deck: [], cue: scene.cue, mood: scene.mood }
126 live.scene = scene
127 // A cue always opens on its first frame, and so does his yawn, which plays once from start to slump.
128 if (live.cue !== scene.cue || (live.mood !== scene.mood && scene.mood === 'drowsy')) Object.assign(live, { cue: scene.cue, frame: 0, elapsed: 0 })
129 live.mood = scene.mood
130
131 if (isFirst) {
132 surface.setState(live)
133 surface.every(TICK_MS, () => {
134 const cur = surface.state!
135 const frames = cur.click ? CLICKS[cur.click.name]! : undefined
136 if (cur.scene.isStill && !frames) return
137 const elapsed = cur.elapsed + TICK_MS
138 if (elapsed < (frames ? CLICK_MS : cur.scene.cue ? CUES[cur.scene.cue].ms : FRAME_MS[cur.scene.mood])) return void (cur.elapsed = elapsed)
139 const step = (cur.click?.step ?? 0) + 1
140 surface.setState({ ...cur, frame: cur.frame + 1, elapsed: 0, click: cur.click && step < frames!.length ? { ...cur.click, step } : undefined })
141 })
142 // Each click plays the next animation from a shuffled deck, so he never does the same one twice in a row.
143 surface.onPointer(e => {
144 const cur = surface.state!
145 if (e.type !== 'down' || cur.click || cur.scene.isStill || cur.scene.cue) return
146 const deck = cur.deck.length ? cur.deck : dealClicks(cur.last)
147 const [name, ...rest] = deck
148 surface.setState({ ...cur, click: { name: name!, step: 0 }, deck: rest, last: name, elapsed: 0 })
149 })
150 }
151
152 const f = live.frame
153 const body = hex(SKINS[scene.skin] ?? SKINS.classic!)
154 const cue = scene.cue ? CUES[scene.cue] : undefined
155 if (cue) {
156 const frames = cue.frames(scene)
157 const rows = cueRows(cue, frames[(scene.isStill ? cue.rest : live.frame) % frames.length]!)
158 return (
159 <Box flexDirection="column">
160 {rows.map(row => (
161 <Text>{cellRuns(row).map(run => <Text color={run.tint === undefined ? undefined : run.tint === 'body' ? body : hex(run.tint)} dimColor={run.isDim}>{run.text}</Text>)}</Text>
162 ))}
163 </Box>
164 )
165 }
166 const isClick = live.click !== undefined
167 const strain = !isClick && (scene.mood === 'idle' || scene.mood === 'working') && scene.strain !== 'none' ? STRAIN[scene.strain] : undefined
168 const l: Look = isClick ? { ...CLICKS[live.click!.name]![live.click!.step]!, prop: [], tint: GREY } : moodLook(scene.mood, scene.activity, f)
169 const shift = strain && scene.strain === 'cold' ? f % 2 : 0
170 const rows: Sprite = place({ ...l, x: (l.x ?? 0) + shift })
171 const marks = marksOf(l)
172 const doing = !isClick && scene.mood === 'working' ? DOING[scene.activity] : undefined
173
174 return (
175 <Box flexDirection="row" columnGap={1}>
176 <Box flexDirection="column">
177 {rows.map((row, r) => (
178 <Text>
179 <Text color={strain ? hex(strain.color) : undefined}>{strain && strain.row(f) === r ? strain.cells[f % strain.cells.length] : ' '}</Text>
180 {runsOf(row, r, marks).map(run => <Text color={run.isDim ? undefined : body} dimColor={run.isDim}>{run.text}</Text>)}
181 <Text> </Text>
182 </Text>
183 ))}
184 </Box>
185 <Box flexDirection="column">
186 {[0, 1, 2].map(r => (
187 <Text>
188 <Text color={hex(l.tint)}>{(l.prop[r] ?? '').padEnd(PROP_W)}</Text>
189 {r === 1 && doing && <Text color={hex(doing.color)}>{doing.glyph} {doing.word}</Text>}
190 {r === 1 && doing && scene.clones > 0 && <Text color={hex(DOING.agents.color)}> ×{scene.clones}</Text>}
191 </Text>
192 ))}
193 </Box>
194 </Box>
195 )
196}
197
198export default Clawd
199hooks/clawd-moves.ts 114 lines1// Clawd in the terminal is three rows of nine cells. A frame may push him down or sideways inside that box,
2// which clips him, so one sprite can hop, hide, peek and walk out of sight without the box ever changing size.
3export const ROWS = 3
4export const COLS = 9
5
6export type Sprite = [head: string, body: string, feet: string]
7
8export const HEAD = {
9 open: ' ▐▛███▜▌ ',
10 shut: ' ▐█████▌ ',
11 down: ' ▐▙███▟▌ ',
12 left: ' ▐▜███▜▌ ',
13 right: ' ▐▛███▛▌ ',
14 wink: ' ▐▛████▌ ',
15}
16export const BODY = { rest: '▝▜█████▛▘', both: '▗▟█████▙▖', left: '▗▟█████▛▘', right: '▝▜█████▙▖' }
17export const FEET = {
18 stand: ' ▘▘ ▝▝ ',
19 step: ' ▝▝ ▘▘ ',
20 sit: ' ▀▀ ▀▀ ',
21 none: ' ',
22 desk: ' ▄▄▄▄▄▄▄ ',
23 tapLeft: ' ▘▘ ',
24 tapRight: ' ▝▝ ',
25}
26
27export const STAND: Sprite = [HEAD.open, BODY.rest, FEET.stand]
28export const CHEER: Sprite = [HEAD.open, BODY.both, FEET.stand]
29export const AIR: Sprite = [HEAD.open, BODY.both, FEET.none]
30const LEFT: Sprite = [HEAD.left, BODY.rest, FEET.stand]
31const RIGHT: Sprite = [HEAD.right, BODY.rest, FEET.stand]
32const UP: Sprite = [HEAD.down, BODY.rest, FEET.stand]
33export const SHUT: Sprite = [HEAD.shut, BODY.rest, FEET.stand]
34const WINK: Sprite = [HEAD.wink, BODY.rest, FEET.stand]
35
36// Turning around, front to back and round again: each step is a little narrower than the last.
37const THREE_QUARTERS: Sprite = [' ▐█▛██▌ ', ' ▝▜████▛▘', ' ▘▘ ▝▝ ']
38const EDGE: Sprite = [' ▐██▌ ', ' ▝███▘ ', ' ▝▝ ']
39const BACK: Sprite = [HEAD.shut, BODY.rest, FEET.stand]
40const THREE_QUARTERS_LEFT: Sprite = [' ▐██▜█▌ ', '▝▜████▛▘ ', ' ▘▘ ▝▝ ']
41const TURNAROUND = [STAND, THREE_QUARTERS, EDGE, BACK, EDGE, THREE_QUARTERS_LEFT, STAND]
42
43// `dust` puffs on both sides of a crouch, `shadow` is the ground under a hop.
44export type Frame = { rows: Sprite; offset?: number; x?: number; dust?: boolean; shadow?: boolean }
45export type Mark = { row: number; col: number; text: string }
46
47const blankRow = ' '.repeat(COLS)
48const shiftRow = (row: string, x: number) =>
49 x >= 0 ? (' '.repeat(Math.min(x, COLS)) + row).slice(0, COLS) : (row + ' '.repeat(Math.min(-x, COLS))).slice(Math.min(-x, COLS))
50
51// The sprite moved down by `offset` rows and right by `x` cells, whatever leaves the box is cut off.
52export const place = ({ rows, offset = 0, x = 0 }: Frame): Sprite => rows.map((_, r) => shiftRow(rows[r - offset] ?? blankRow, x)) as Sprite
53
54export const marksOf = ({ offset = 0, dust, shadow }: Frame): Mark[] => [
55 ...(dust && offset > 0 ? [{ row: ROWS - 1, col: 0, text: '·' }, { row: ROWS - 1, col: COLS - 1, text: '·' }] : []),
56 ...(shadow ? [{ row: ROWS - 1, col: 3, text: '▁▁▁' }] : []),
57]
58
59const hold = (rows: Sprite, n = 1, extra: Omit<Frame, 'rows'> = {}): Frame[] => Array.from({ length: n }, () => ({ rows, ...extra }))
60const crouch = (rows: Sprite = STAND, n = 2) => hold(rows, n, { offset: 1, dust: true })
61const blink = [...hold(SHUT), ...hold(STAND)]
62const turning = (n = 1, extra: Omit<Frame, 'rows'> = {}) => TURNAROUND.flatMap(rows => hold(rows, n, extra))
63const hops = (xs: number[]) => xs.flatMap(x => [...hold(AIR, 1, { x }), ...hold(STAND, 1, { x, offset: 1, dust: true })])
64const walk = (xs: number[], look: Sprite) =>
65 xs.flatMap((x, i) => hold([look[0], look[1], i % 2 === 0 ? FEET.tapLeft : FEET.tapRight], 2, { x }))
66
67export const CLICK_MS = 70
68
69// What a click plays, one by name, each frame lasting CLICK_MS. Every one ends back on STAND.
70export const CLICKS: Record<string, Frame[]> = {
71 jump: [...crouch(), ...hold(AIR, 3), ...crouch(STAND, 1), ...hold(AIR, 2), ...crouch(), ...hold(CHEER, 2), ...hold(STAND)],
72 look: [...hold(RIGHT, 5), ...hold(LEFT, 5), ...hold(UP, 4), ...hold(STAND, 2)],
73 spin: [...turning(), ...turning(), ...hold(CHEER, 2), ...hold(STAND)],
74 peekaboo: [
75 ...hold(STAND, 1, { offset: ROWS }), ...hold(STAND, 3, { offset: 2 }), ...hold(RIGHT, 3, { offset: 2 }),
76 ...hold(LEFT, 3, { offset: 2 }), ...hold(STAND, 2, { offset: 2 }), ...hold(STAND, 1, { offset: 1 }), ...hold(CHEER, 3), ...blink,
77 ],
78 drop: [
79 ...hold(CHEER, 1, { offset: -ROWS }), ...hold(CHEER, 1, { offset: -2 }), ...hold(CHEER, 1, { offset: -1 }),
80 ...crouch(), ...hold(AIR, 1), ...crouch(STAND, 1), ...hold(CHEER, 3), ...blink,
81 ],
82 wink: [...hold(WINK, 8), ...hold(STAND, 2), ...hold(WINK, 3), ...hold(STAND)],
83 boop: [...crouch(SHUT, 3), ...hold(LEFT, 6), ...hold(STAND, 2), ...blink],
84 tap: [
85 ...[2, 2, 2, 2, 1, 1].flatMap((n, i) => hold([HEAD.open, BODY.rest, i % 2 === 0 ? FEET.tapLeft : FEET.tapRight], n)),
86 ...hold(UP, 2), ...hold(CHEER, 2), ...hold(STAND),
87 ],
88 sneeze: [
89 ...hold([HEAD.shut, BODY.both, FEET.stand], 4), ...crouch(SHUT, 2),
90 ...[1, -1, 1, -1].flatMap(x => hold(SHUT, 1, { x })), ...hold(STAND, 2), ...blink,
91 ],
92 turn: [...turning(2), ...hold(STAND)],
93 'coin-hop': [
94 ...crouch(), ...TURNAROUND.slice(1, -1).flatMap(([head, body]) => hold([head, body, FEET.none], 1, { shadow: true })), ...hold(AIR, 1, { shadow: true }),
95 ...crouch(STAND, 1), ...hold(CHEER, 4), ...hold(STAND),
96 ],
97 skip: [...hops([3, 6, COLS]), ...hops([-6, -3]), ...hold(CHEER, 2), ...hold(STAND)],
98 waddle: [...walk([-2, -4, -6, -COLS], LEFT), ...hold(STAND, 3, { x: -COLS }), ...walk([COLS - 2, 6, 4, 2, 1, 0], LEFT), ...hold(STAND, 2), ...blink],
99 peek: [
100 ...walk([-3, -6, -COLS], LEFT), ...hold(RIGHT, 3, { x: -COLS }), ...hold(RIGHT, 4, { x: -6 }), ...hold(RIGHT, 2, { x: -COLS }),
101 ...hold(CHEER, 4, { x: -5 }), ...walk([-3, -1, 0], RIGHT), ...hold(STAND, 2),
102 ],
103}
104
105// Every click is played once before any repeats, and a new round never opens with the one just played.
106export const dealClicks = (last?: string, random: () => number = Math.random): string[] => {
107 const deck = Object.keys(CLICKS)
108 for (let i = deck.length - 1; i > 0; i--) {
109 const j = Math.floor(random() * (i + 1))
110 ;[deck[i], deck[j]] = [deck[j]!, deck[i]!]
111 }
112 return deck[0] === last ? [...deck.slice(1), deck[0]!] : deck
113}
114types/index.d.ts 28 lines1export type Mood = 'idle' | 'drowsy' | 'working' | 'happy' | 'oops' | 'asleep' | 'loved'
2
3export type Activity =
4 | 'think' | 'laptop' | 'hammer' | 'magnify' | 'notes' | 'web' | 'agents'
5 | 'test' | 'git' | 'install' | 'build' | 'ask' | 'mcp' | 'skill' | 'plan'
6
7// What is bothering him on top of his mood: usage near a limit, a cold cache, or a tool that has run a long time.
8export type Strain = 'none' | 'hot' | 'cold' | 'slow'
9
10// A state that takes over his whole look: sticky ones last while their cause does (perm, compact, coffee, agents,
11// limit), the rest play once (error, pass, fail, bigfile, flag, hello, fireworks, offline).
12export type Cue = 'perm' | 'error' | 'pass' | 'fail' | 'compact' | 'limit' | 'agents' | 'coffee' | 'bigfile' | 'offline' | 'flag' | 'hello' | 'fireworks'
13
14export type Scene = { mood: Mood; activity: Activity; skin: string; isStill: boolean; strain: Strain; cue: Cue | null; clones: number; hash: string }
15
16// slow and long count tools past the clock and coffee thresholds; waiting holds the tool calls with a permission prompt open,
17// agents the subagents the main chat sent that still run, steps the message count of the last main request.
18export type Signals = { hot: boolean; slow: number; long: number; waiting: string[]; compacting: number; limited: boolean; agents: string[]; steps: number }
19
20export type Playing = { name: Cue; hash: string } | null
21
22declare module 'claude-code' {
23 interface PluginState {
24 buddy: { mood: Mood; activity: Activity; skin: string; signals: Signals; cue: Playing }
25 'cache-timer': { last: { at: number; read: number; write: number; fresh: number } | null; now: number; ttlMin: number; twinkle: number }
26 }
27}
28