While Claude works, Clawd acts out the spinner's -ing word above the prompt, and the tool that is running

A Claude Code mod: while Claude works, Clawd walks onto a little stage above the prompt and acts out what is going on — the spinner's -ing word (Sautéing, Pondering, *Herding*…) — then puts on a show of 32 scenes, a new one every 15 seconds, with little Clawds along for the ride.

Three scenes at the real frame rate, about 16 s in all (a real turn changes scene every 15 s). Every frame is the mod's own output, rendered by tools/.
Bash types, Read/Grep/Glob think, Edit/Write sketch, Agent herds sheep, Web* checks the weather, TodoWrite/Skill juggles, MCP tools cast spells, anything else is hammered at the forge./clawd pets, feeds or waves at Clawd, or chats with it, even mid-turn (see below)./clawd.| Scene | Spinner words (some of them) |
|---|---|
| think | Pondering, Musing, Clauding, Noodling, Ruminating |
| chalk | Deciphering, Elucidating, Philosophising, Deliberating, Reasoning |
| cook / bake / brew | Sautéing, Simmering, Whisking / Baking, Kneading / Brewing, Percolating |
| walk / run / moonwalk | Moseying, Wandering / Scampering, Galloping / Moonwalking |
| herd | Herding, Wrangling, Mustering |
| spin | Spinning, Churning, Reticulating, Combobulating |
| magic / levitate | Conjuring, Manifesting, Transmuting / Levitating, Hyperspacing |
| hatch / grow | Hatching, Incubating / Sprouting, Germinating |
| forge / compute | Forging, Crafting, Creating / Computing, Crunching, Synthesizing |
| dance / disco | Vibing, Jitterbugging, Jamming / Boogieing, Grooving — under a spinning mirror ball |
| juggle / honk | Juggling / Honking, Booping |
| sketch / weather / thunder | Sketching, Doodling / Misting, Billowing / Thundering |
| dig / flow | Burrowing, Spelunking / Flowing, Undulating |
| shift | Beaming, Shifting, Dodging — calls out 閃身步 top to bottom, then flashes across the stage leaving fading afterimages |
| kick / skate / campfire | Kicking, Dribbling / Skating, Gliding / Kindling, Smoldering — no built-in word matches these yet, so they mostly turn up in the rotation |
/clawd runs at once, even while Claude is working, and never interrupts the turn:

Clawd's answer here is an example; in a session it comes from Haiku.
| You type | Clawd |
|---|---|
/clawd pet | purrs, with hearts floating up |
/clawd feed | catches a cookie and munches it |
/clawd wave (or hi, hello) | waves back |
/clawd dance | dances under the disco ball |
/clawd shift (or 閃身步) | calls out 閃身步 and flash-steps across the stage, afterimages trailing |
/clawd <anything else> | answers in a speech bubble |
Actions are free and instant. Anything else is a chat: Clawd ponders for a moment, then answers in a sentence or two, in your language, knowing what Claude is up to right now. The answer comes from Haiku (one small haiku call per message, on your usage) and shows only in Clawd's bubble: it is not written to the transcript, so Claude's own conversation never sees it. Each message stands alone; Clawd does not remember earlier ones. Between turns Clawd steps out for the reaction and leaves again after it.
閃身步, the flash step, is a martial-arts dodge: a burst of speed that carries the fighter aside so fast the eye catches only afterimages. Clawd does it as a proper move, name first:
閃
身 ▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓ ▐▛███▛▌
步 ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▝▜█████▙▖
▓▓ ▓▓ ▓▓ ▓▓
< HONK! > is shouted, while Clawd looks the way it is about to go.Then it calls the move again and flashes back the other way, about three seconds a pass. /clawd shift or /clawd 閃身步 plays it at once, from the call; as a scene it comes with the spinner word Beaming, and in the rotation. It needs a terminal font that draws CJK characters two columns wide, as nearly all do.
Requires a Claude Code build with function-hook mods (claude plugin validate knows hooks.json modules). Developed and tested on Claude Code 2.1.296.
Clawd shows in claude in any terminal (including an editor's terminal and the JetBrains plugin) and in the Code tab of the Desktop app. The VS Code chat panel, claude -p and cloud sessions draw no mod interface, so Clawd does not show there.
From this repository as a marketplace:
/plugin marketplace add BrianHuang813/clawd-actor
/plugin install clawd-actor@clawd-actor
/reload-plugins
Or straight from a clone, for one session:
git clone https://github.com/BrianHuang813/clawd-actor
claude --plugin-dir ./clawd-actor
When a newer version is out, a notice says so a couple of seconds after Claude Code starts: the mod compares its own version with the one on main once a session (one small request to GitHub; nothing is shown when offline or up to date).
Run /clawd-actor:update, or just ask Claude to update clawd-actor. Either way Claude refreshes this marketplace and updates the plugin with Claude Code's own plugin manager, tells you the version it went from and to and sums up what is new, and /reload-plugins loads it. However it was updated, the first session on a new version says so in a notice, with the release's headline and a link to the release notes. By hand, the same is:
claude plugin marketplace update clawd-actor
claude plugin update clawd-actor@clawd-actor
A clone run with --plugin-dir updates with git pull.
The stage is drawn in the AbovePrompt band. The hook always calls next(e) and stacks what the mods beneath it draw under the stage, so other band mods keep showing. It hands them the band's rows less the ones the stage and bubble take, so together they still fit without scrolling, and when the band is too short for the stage Clawd stays out. A band mod that answers without calling next(e) hides everything beneath it — if Clawd never shows up, look for one.
ui.render on Spinner only observes: it remembers the word and mode and lets the engine draw the spinner as usual.tool.call notes the tool in flight and forgets it when the call returns./clawd is registered immediate, so it runs mid-turn. Its command.run hook returns no text (nothing for the transcript or the model); it sets a reaction the band plays over the show. A chat calls $.model.complete from a one-shot timer, so the prompt never waits on the model. hooks/chat.ts holds the parsing, Clawd's persona and the speech bubble.session.start, advances a frame counter in $.state every 140 ms while a turn runs; the band reads it, which subscribes it to redraws. A timer started inside a turn.start hook does not outlive that dispatch, which is why it lives in session.start.isWorking prop.hooks/scenes.ts is pure: a 5-row grid of cells (the top one for hats), a scene per name, a costume per dressed-up scene drawn over Clawd wherever it stands, sceneAt() choosing an act's scene, hold() keeping it for the whole act, and frameRows() turning the grid into coloured runs.session.start sets a one-shot timer that, two seconds later, reads the version in the installed plugin.json, fetches the one on main, and toasts when main's is newer. skills/update/SKILL.md is the /clawd-actor:update skill that runs the update.Bug reports, ideas and new scenes are welcome: see CONTRIBUTING.md for how to report a bug, run Clawd from a clone, test a change, regenerate the GIFs and send a pull request.
Clawd is Claude Code's mascot; the sprite follows the one on Claude Code's welcome screen. This is a fan-made mod, not affiliated with or endorsed by Anthropic.
hooks/register.tsx 215 lines1import { atom, read, update } from 'claude-code'
2import type { EngineInterface as Engine, Register } from 'claude-code'
3
4import { bubble, clean, holdFrames, parseClawd, persona, HELP } from './chat'
5import { ACT_FRAMES, FRAME_MS, frameRows, H, hold, type Mode, type Shown } from './scenes'
6
7const MAX_STAGE = 60 // widest the wander roams, however wide the terminal
8const frame = atom({ plugin: 'clawd-actor', key: 'frame' } as const, 0)
9// The turn's show, kept in $.state too: a hot reload (/reload-plugins) loses module variables, not state
10const show = atom({ plugin: 'clawd-actor', key: 'show' } as const, { isTurnRunning: false, turnBase: 0, seed: -1, played: 0 })
11
12// The spinner's word, read while it draws. State cannot be written during a render,
13// so it lives here; the frame timer's redraws pick it up.
14let word = 'Thinking'
15let mode: Mode = 'thinking'
16let isTurnRunning = false
17let turnBase = 0 // the frame the turn started on: acts count from it
18let seed = 0 // shuffles the session's rotation of scenes
19let played = 0 // rotation acts earlier turns got through
20let shown: Shown | undefined // the scene on stage, held for its act
21// What /clawd set going: a scene played over the show from frame `from`, and what Clawd says, for `left` more frames
22let reaction: { scene: string; say?: string; left: number; from: number } | undefined
23let asked = 0 // /clawd commands so far: a reply to any but the latest is dropped
24const running: { id: string; tool: string }[] = [] // tools in flight, newest last
25
26const REACT_FRAMES = Math.round(6000 / FRAME_MS) // how long a /clawd action plays
27const WAIT_FRAMES = Math.round(15_000 / FRAME_MS) // the most Clawd ponders before a reply
28const UPDATE_CHECK_MS = 2000 // after start-up settles, so the toast is seen
29const LATEST = 'https://raw.githubusercontent.com/BrianHuang813/clawd-actor/main/.claude-plugin/plugin.json'
30const RELEASES = 'https://github.com/BrianHuang813/clawd-actor/releases'
31const RELEASE_API = 'https://api.github.com/repos/BrianHuang813/clawd-actor/releases/tags/v'
32
33/** Whether dotted version `a` is past `b`, part by part (1.10.0 is past 1.9.2). */
34export const isNewer = (a: string, b: string) => {
35 const [x, y] = [a, b].map(v => v.split('.').map(Number))
36 const i = x.findIndex((n, k) => n !== (y[k] ?? 0))
37 return i >= 0 && x[i] > (y[i] ?? 0)
38}
39
40/** A release's headline, "lighter frames" from "clawd-actor 0.5.1 — lighter frames"; '' when GitHub cannot say. */
41const headline = async ($: Engine, version: string) => {
42 try {
43 const res = await $.http.fetch(RELEASE_API + version)
44 return (res.ok && String(JSON.parse(res.text).name ?? '').split(' — ')[1]) || ''
45 } catch {
46 return ''
47 }
48}
49
50/**
51 * Once a session: the first one after an update says what is new; any other, if main carries a
52 * newer version than this install, says so and how to update.
53 */
54const checkForUpdate = async ($: Engine) => {
55 try {
56 const mine = JSON.parse(String(await $.fs.read(`${$.plugin.root}/.claude-plugin/plugin.json`))).version
57 const seen = await $.store.get('version') // the version the last session ran
58 if (seen !== mine) await $.store.set('version', mine)
59 if (typeof seen === 'string' && isNewer(mine, seen)) {
60 const what = await headline($, mine)
61 $.ui.toast(`clawd-actor updated to ${mine}${what ? `: ${what}` : ''}. What's new: ${RELEASES}`, { timeoutMs: 15_000 })
62 return
63 }
64 const res = await $.http.fetch(LATEST)
65 const latest = res.ok ? JSON.parse(res.text).version : undefined
66 if (latest && isNewer(latest, mine))
67 $.ui.toast(`clawd-actor ${latest} is out (you have ${mine}): run /clawd-actor:update`, { timeoutMs: 15_000 })
68 } catch {
69 // offline, or the fetch is refused by policy: the check is a courtesy, the next session tries again
70 }
71}
72
73/** Writes the turn's show through to $.state, for the module a reload brings in. */
74const keep = ($: Engine) => update($, show, () => ({ isTurnRunning, turnBase, seed, played }))
75
76/** Moves the show on a frame, which redraws the band. */
77const tick = ($: Engine) => update($, frame, f => f + 1)
78
79/** Plays `scene` from its start over the show for `frames` frames, Clawd saying `say`; redraws at once, even between turns. */
80const react = async ($: Engine, scene: string, say?: string, frames = REACT_FRAMES) => {
81 reaction = { scene, say, left: frames, from: (await read($, frame)) + 1 }
82 return tick($)
83}
84
85/** What Claude is up to, for Clawd's system prompt. */
86const status = () => {
87 if (!isTurnRunning) return 'Claude is idle, waiting for the user.'
88 const tool = running[running.length - 1]?.tool
89 return `Claude is working (the spinner says "${word}"${tool ? `, the ${tool} tool is running` : ''}); you are acting out the "${shown?.scene ?? 'think'}" scene.`
90}
91
92/** Asks Haiku for Clawd's answer and puts it in the bubble; Claude's own conversation never sees either side. */
93const reply = async ($: Engine, text: string, now: string, id: number) => {
94 let say = 'Hmm, my words got lost on the way. Try again?'
95 try {
96 const r = await $.model.complete({ model: 'haiku', system: persona(now), prompt: text, maxTokens: 150, timeoutMs: 15_000 })
97 if (r.isAnswered && clean(r.text)) say = clean(r.text)
98 } catch {
99 // the engine would not send it (a blocked model, say): Clawd still answers, with the line above
100 }
101 if (id === asked) await react($, 'say', say, holdFrames(say)) // else a newer /clawd took the stage meanwhile
102}
103
104export const register: Register = on => {
105 // A timer must start where work may outlive the dispatch: session.start (fires again on reload).
106 // It ticks all session long but only writes, and so redraws, while a turn runs.
107 on('session.start', async ($, e, next) => {
108 const r = await next(e)
109 // a reload mid-turn picks the show up where it was; a new session starts one
110 ;({ isTurnRunning, turnBase, seed, played } = await read($, show))
111 if (seed < 0) {
112 seed = Math.floor(await $.clock.now()) % 9973
113 await keep($)
114 }
115 $.clock.after(UPDATE_CHECK_MS, () => checkForUpdate($)) // on a timer: the session never waits on the network
116 $.clock.every(FRAME_MS, () => {
117 const isReacting = reaction !== undefined
118 if (reaction && --reaction.left <= 0) reaction = undefined
119 // a reaction redraws between turns too, one last time as it ends so the stage goes
120 return isTurnRunning || isReacting ? tick($) : undefined
121 })
122 // last, so the timers run whatever happens here; immediate: /clawd runs mid-turn instead of waiting
123 await $.command.register({ name: 'clawd', description: 'Pet, feed or wave at Clawd, or say something to it', argumentHint: '[pet|feed|wave|dance|shift|message]', immediate: true })
124 return r
125 })
126
127 // Answers in Clawd's bubble only: no transcript line, so nothing of it reaches Claude
128 on('command.run', { command: 'clawd' }, async ($, e) => {
129 const id = ++asked
130 const ask = parseClawd(e.args)
131 if ('help' in ask) await react($, 'wave', HELP)
132 else if ('action' in ask) await react($, ask.action)
133 else {
134 await react($, 'ponder', '· · ·', WAIT_FRAMES)
135 const now = status()
136 $.clock.after(1, () => reply($, ask.chat, now, id)) // on a timer: the prompt never waits on the model
137 }
138 return {}
139 })
140
141 on('turn.start', async ($, e, next) => {
142 isTurnRunning = true
143 turnBase = await read($, frame)
144 running.length = 0
145 await keep($)
146 return next(e)
147 })
148
149 // While a tool runs Clawd acts it out; back to the rotation once it returns
150 on('tool.call', async ($, e, next) => {
151 running.push({ id: e.tool_use_id, tool: e.tool })
152 try {
153 return await next(e)
154 } finally {
155 const i = running.findIndex(r => r.id === e.tool_use_id)
156 if (i >= 0) running.splice(i, 1)
157 }
158 })
159
160 on('turn.complete', async ($, e, next) => {
161 if (e.agentId) return next(e) // a subagent's turn (a workflow's agents too): the main turn runs on
162 isTurnRunning = false
163 played += Math.floor(((await read($, frame)) - turnBase) / ACT_FRAMES) // acts after the opener
164 await keep($)
165 return next(e)
166 })
167
168 // Observe only: remember what the spinner says, let the engine draw it as usual
169 on('ui.render', { component: 'Spinner' }, ($, e, next) => {
170 word = e.props.message ?? e.props.word
171 mode = e.props.mode
172 return next(e)
173 })
174
175 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
176 // read before any early return: the engine tracks the atoms a render reads and redelivers on
177 // their writes — a gated return that reads nothing unregisters the frame dependency, and the
178 // band would never redraw on its own again (the whole-turn blackout)
179 const t = await read($, frame)
180 // isWorking is the engine's own word on whether a turn runs — but not the turn itself: a
181 // command's busy blink (a /reload-plugins, a plugin hot-reload's repaint) turns it on with no
182 // turn started, and the band would flash Clawd for the one frame before the command ends.
183 // isTurnRunning follows the turn; a /clawd reaction plays past both.
184 if (e.props.hasSurvey || ((!e.props.isWorking || !isTurnRunning) && !reaction) || e.props.maxRows < H) return next(e)
185
186 const width = Math.min(e.props.bodyColumns, MAX_STAGE)
187 // the bubble needs its two border rows besides the text: left out when the band has no room for one line
188 const room = Math.min(3, e.props.maxRows - H - 2)
189 const said = reaction?.say && room > 0 ? bubble(reaction.say, width, room) : []
190 // keep whatever other band mods draw here, in the rows Clawd leaves them
191 const below = await next({ ...e, props: { ...e.props, maxRows: e.props.maxRows - H - said.length } })
192
193 const { Box, Text } = $.ui.resolve(e)
194 shown = hold(shown, turnBase, { word, mode, tick: t - turnBase, seed, played, tool: running[running.length - 1]?.tool })
195 // a reaction counts its own frames, so a move like shift opens on its first one
196 const rows = reaction ? frameRows(word, mode, Math.max(0, t - reaction.from), width, reaction.scene) : frameRows(word, mode, t, width, shown.scene)
197
198 return (
199 <Box flexDirection="column">
200 {said.map(line => (
201 <Text color="white">{line}</Text>
202 ))}
203 <Box flexDirection="column" height={H}>
204 {rows.map(runs => (
205 <Text>
206 {runs.map(r => (r.color ? <Text color={r.color} backgroundColor={r.bg}>{r.text}</Text> : r.text))}
207 </Text>
208 ))}
209 </Box>
210 {below}
211 </Box>
212 )
213 })
214}
215hooks/chat.ts 80 lines1// /clawd: what the person said, how Clawd answers, and the speech bubble it answers in.
2// Pure functions only, like scenes.ts.
3
4import { FRAME_MS } from './scenes.ts'
5
6/** `/clawd <word>` actions: free and instant, no model call. Each names the scene it plays. */
7export const ACTIONS: Record<string, string> = { pet: 'pet', feed: 'feed', wave: 'wave', hi: 'wave', hello: 'wave', dance: 'disco', shift: 'shift', 閃身步: 'shift' }
8export const HELP = 'Try /clawd pet, feed, wave, dance or shift, or just say something to me!'
9const MAX_ASK = 500 // characters of a message passed on to the model
10const MAX_LINES = 3 // of text in the bubble
11
12export type Ask = { help: true } | { action: string } | { chat: string }
13
14/** A lone action word plays that action; anything else is a chat message. */
15export const parseClawd = (args: string): Ask => {
16 const text = args.trim()
17 if (!text) return { help: true }
18 const word = text.toLowerCase()
19 const action = Object.hasOwn(ACTIONS, word) ? ACTIONS[word] : undefined // not what every object inherits
20 return action ? { action } : { chat: text.slice(0, MAX_ASK) }
21}
22
23/** The text with control characters (escape sequences included) and runs of whitespace made single spaces. */
24export const clean = (text: string) => text.replace(/[\u0000-\u001f\u007f-\u009f]+/g, ' ').replace(/\s+/g, ' ').trim()
25
26// Characters a terminal draws two columns wide: CJK, Hangul, full-width forms
27const WIDE = /[ᄀ-ᅟ⺀-가-힣豈-︰-﹏-⦆¢-₩]/
28// and none: combining marks (an accent typed apart, Thai and Hindi vowel marks) sit on the character before
29const ZERO = /[\p{Mn}\p{Me}]/u
30/** Columns the text takes on a terminal. */
31export const cells = (text: string) => [...text].reduce((n, ch) => n + (ZERO.test(ch) ? 0 : WIDE.test(ch) ? 2 : 1), 0)
32
33/** Words, single wide characters (which may break anywhere) and spaces, in order. */
34const tokens = (text: string) => text.match(new RegExp(`${WIDE.source}|[^\\s${WIDE.source.slice(1, -1)}]+|\\s+`, 'g')) ?? []
35
36/** Wraps `text` into at most `maxLines` lines of `width` columns, the last ending in … when it runs over. */
37const wrap = (text: string, width: number, maxLines: number) => {
38 const lines: string[] = []
39 let line = ''
40 for (const token of tokens(text)) {
41 if (/^\s+$/.test(token)) {
42 if (line) line += ' '
43 continue
44 }
45 // a word wider than a whole line is cut to fit
46 const word = cells(token) > width ? [...token].slice(0, width - 1).join('') + '…' : token
47 if (cells(line + word) > width) {
48 lines.push(line.trimEnd())
49 line = word
50 } else line += word
51 }
52 if (line.trim()) lines.push(line.trimEnd())
53 if (lines.length <= maxLines) return lines
54 const last = [...lines[maxLines - 1]]
55 while (cells(last.join('')) > width - 1) last.pop()
56 return [...lines.slice(0, maxLines - 1), last.join('') + '…']
57}
58
59/** The speech bubble Clawd says `text` in: a box `width` columns wide at most, its tail pointing down. */
60export const bubble = (text: string, width: number, maxLines = MAX_LINES): string[] => {
61 const lines = wrap(clean(text), Math.max(8, width - 6), maxLines)
62 const w = Math.max(4, ...lines.map(cells))
63 const pad = (l: string) => l + ' '.repeat(w - cells(l))
64 return [`╭${'─'.repeat(w + 2)}╮`, ...lines.map(l => `│ ${pad(l)} │`), `╰───┬${'─'.repeat(w - 2)}╯`]
65}
66
67/** Frames a reply stays up: long enough to read, 5 to 15 seconds. */
68export const holdFrames = (text: string) => Math.round(Math.min(15_000, 5_000 + cells(text) * 60) / FRAME_MS)
69
70/** Clawd's system prompt; `status` says what Claude is doing right now. */
71export const persona = (status: string) =>
72 [
73 "You are Clawd, Claude Code's small orange pixel-art mascot. You live on a little stage above the",
74 "user's prompt and act out what Claude is doing. Answer the user in one or two short sentences",
75 '(25 words at most): warm, playful, a little silly. Plain text only: no markdown, no emoji.',
76 "Answer in the user's language. You cannot do tasks or run anything: when asked for real work,",
77 'say cheerfully that Claude is the one for that.',
78 `Right now: ${status}`,
79 ].join('\n')
80hooks/scenes.ts 768 lines1// Clawd's stage: a width x H grid of cells. Every scene draws Clawd plus props for one frame,
2// then the whole frame wanders left and right across the stage. The top row is kept for what Clawd
3// wears on its head: scenes draw from the row below it, so a hat still shows when Clawd hops.
4// Pure functions only, so the frames can be checked without the engine.
5
6export const W = 40 // default stage width; the band passes its own
7export const H = 5
8const HEAD = 1 // rows above scene row 0: the hat row
9export const ORANGE = '#D77757'
10const SHADE = '#B35A3E' // the side turned away, as the official animation shades it
11const INK = '#1E1E1E' // eye colour where an eye is drawn on top of the body
12const PURPLE = '#A374F5'
13
14export type Cell = { ch: string; color?: string; bg?: string }
15export type Grid = Cell[][]
16
17// One empty cell shared by the whole grid: it is only ever replaced, never changed
18const SPACE: Cell = { ch: ' ' }
19const blank = (width: number): Grid => Array.from({ length: H }, () => Array(width).fill(SPACE))
20
21/** Paints `s` at (x, y), moved along by the wander; spaces are transparent so props can overlap Clawd's gaps. */
22const put = (g: Grid, x: number, y: number, s: string, color?: string, bg?: string) => {
23 const row = g[y + HEAD]
24 if (!row) return
25 ;[...s].forEach((ch, i) => {
26 const cx = x + stride.dx + i
27 if (ch !== ' ' && cx >= 0 && cx < row.length) row[cx] = bg ? { ch, color, bg } : { ch, color }
28 })
29}
30/** Paints `s` top to bottom from (x, y), a character a row; each is a wide one taking two cells, the second left empty. */
31const tall = (g: Grid, x: number, y: number, s: string, color?: string) => {
32 const cx = x + stride.dx
33 ;[...s].forEach((ch, i) => {
34 const row = g[y + HEAD + i]
35 if (row && cx >= 0 && cx + 1 < row.length) [row[cx], row[cx + 1]] = [{ ch, color }, { ch: '', color }]
36 })
37}
38/** Recolours what is already drawn at (x, y), keeping the glyph. */
39const tint = (g: Grid, x: number, y: number, color: string) => {
40 const c = g[y + HEAD]?.[x + stride.dx]
41 if (c && c.ch !== ' ') c.color = color
42}
43
44// Clawd, 9 columns x 3 rows, as the welcome banner draws it.
45// smile is drawn as blink with two ^ eyes laid over it (see clawd()).
46const TOP = { open: ' ▐▛███▜▌ ', blink: ' ▐█████▌ ', smile: ' ▐█████▌ ', left: ' ▐▜███▜▌ ', right: ' ▐▛███▛▌ ' }
47const MID = { down: '▝▜█████▛▘', up: '▗▟█████▙▖', left: '▗▟█████▛▘', right: '▝▜█████▙▖', flat: '▟███████▙' }
48const LEGS = { stand: ' ▘▘ ▝▝ ', a: ' ▘ ▘▝ ▝ ', b: ' ▘ ▘ ▝ ▝ ', curl: ' ▘▝ ▘▝ ', tuck: ' ' }
49
50type Pose = {
51 x?: number
52 /** 1 hops a row up, -1 squashes a row down (legs out of sight, body spread) */
53 lift?: -1 | 0 | 1
54 eyes?: keyof typeof TOP
55 arms?: keyof typeof MID
56 legs?: keyof typeof LEGS
57 /** which side has turned away from us; the body sways between them on its own */
58 shade?: 'left' | 'right' | 'none'
59 color?: string
60}
61
62// What the wander is doing this frame, `dx` columns along; scenes read it through clawd() and put() so every pose walks along
63const STILL = { dx: 0, moving: false, hop: false, squash: false, dir: 1 }
64const stride = { ...STILL, width: W }
65
66/**
67 * The face when a scene leaves it alone: mostly content ^ ^ eyes, a look around,
68 * a blink or a double blink; while travelling it looks the way it goes.
69 */
70const face = (t: number): keyof typeof TOP => {
71 if (stride.moving) return t % 20 === 0 ? 'blink' : stride.dir > 0 ? 'right' : 'left'
72 const p = t % 56
73 if (p < 14) return p === 7 ? 'blink' : 'open'
74 if (p < 36) return 'smile'
75 if (p < 40) return 'left'
76 if (p < 44) return 'right'
77 return p === 49 || p === 51 ? 'blink' : 'open'
78}
79/** A slow sway: turn one way, face front, turn the other way. */
80const sway = (t: number): NonNullable<Pose['shade']> => {
81 if (stride.moving) return stride.dir > 0 ? 'left' : 'right'
82 const p = t % 16
83 return p < 6 ? 'left' : p < 8 ? 'none' : p < 14 ? 'right' : 'none'
84}
85/** Columns a travelling scene may roam: the stage less Clawd and its trailing props. */
86const roam = (extra: number) => Math.max(4, stride.width - 11 - extra)
87
88const clawd = (g: Grid, t: number, pose: Pose = {}) => {
89 const x = pose.x ?? 2
90 const lift = pose.lift ?? (stride.hop ? 1 : stride.squash ? -1 : 0)
91 const y = 1 - lift
92 const eyes = pose.eyes ?? face(t)
93 const swing = t % 2 === 0 ? 'left' : 'right'
94 const color = pose.color ?? ORANGE
95 const shade = pose.shade ?? sway(t)
96 const costume = color === ORANGE ? wearing : undefined
97 put(g, x, y, TOP[eyes], color)
98 if (eyes === 'smile') {
99 // the happy closed eyes: dark arcs sitting on the body
100 put(g, x + 2, y, '^', INK, color)
101 put(g, x + 6, y, '^', INK, color)
102 }
103 put(g, x, y + 1, MID[lift < 0 ? 'flat' : costume?.arms ?? pose.arms ?? (stride.moving ? swing : 'down')], color)
104 const legs = pose.legs ?? (stride.moving ? walkLegs(t) : shade === 'none' ? 'curl' : 'stand')
105 put(g, x, y + 2, LEGS[legs], color)
106 // turned a little: the far edge of the body falls into shadow
107 if (color === ORANGE && shade !== 'none') {
108 const [top, mid] = shade === 'left' ? [x + 1, x] : [x + 7, x + 8]
109 tint(g, top, y, SHADE)
110 tint(g, mid, y + 1, SHADE)
111 tint(g, shade === 'left' ? x + 1 : x + 7, y + 1, SHADE)
112 }
113 costume?.dress(g, x, y)
114}
115
116// A little Clawd, 5 columns x 2 rows, standing on the ground (or a row up when it hops)
117const MINI_TOP = { open: '▗▛█▜▖', blink: '▗███▖', left: '▗▜█▜▖', right: '▗▛█▛▖' }
118// second row: the top halves close under the eyes, the bottom halves are the legs (out, or tucked in mid-step)
119const MINI_LEGS = { a: '▝▛▀▜▘', b: '▝▜▀▛▘' }
120const MINI_COLORS = ['#6FA8DC', '#E8C547', '#7BC67E', '#E88AB5'] // blue, yellow, green, pink
121const mini = (g: Grid, x: number, color: string, { lift = 0, eyes = 'open', legs = 'a' }: { lift?: number; eyes?: keyof typeof MINI_TOP; legs?: keyof typeof MINI_LEGS } = {}) => {
122 put(g, x, 2 - lift, MINI_TOP[eyes], color)
123 put(g, x, 3 - lift, MINI_LEGS[legs], color)
124}
125
126/** Back-and-forth position over `span` columns. */
127const pingPong = (t: number, span: number) => {
128 const p = t % (span * 2)
129 return p < span ? p : span * 2 - p
130}
131const walkLegs = (t: number): keyof typeof LEGS => (t % 2 === 0 ? 'a' : 'b')
132/** Which way a pingPong(t, span) is heading. */
133const goingRight = (t: number, span: number) => t % (span * 2) < span
134/** Looks and turns toward `right`, with a blink now and then. */
135const facing = (t: number, right: boolean): Pose => ({
136 eyes: t % 20 === 0 ? 'blink' : right ? 'right' : 'left',
137 shade: right ? 'left' : 'right',
138})
139const pick = <T,>(xs: readonly T[], t: number) => xs[t % xs.length]
140
141// ---- Costumes: some scenes dress Clawd for the part. Drawn over Clawd at its x and head row y, so they hop along ----
142
143type Costume = { dress: (g: Grid, x: number, y: number) => void; arms?: keyof typeof MID }
144let wearing: Costume | undefined // the costume this frame's scene puts on the orange Clawd
145
146const HAT = '#3A3A42' // charcoal, not black: a black hat would vanish on a dark terminal
147const HAT_BAND = '#8E8E99'
148const LENS = PURPLE
149const JERSEY = '#3D7BD9'
150const PERM = '#8C62B0'
151// Which quarters of a cell each block fills: a (top left), b (top right), c (bottom left), d (bottom right)
152const QUARTERS: Record<string, string> = { '▘': 'a', '▝': 'b', '▖': 'c', '▗': 'd', '▀': 'ab', '▄': 'cd', '▌': 'ac', '▐': 'bd', '▛': 'abc', '▜': 'abd', '▙': 'acd', '▟': 'bcd', '█': 'abcd' }
153
154/** A hat brim over the top half of each cell from x, keeping the bottom half as drawn, so the eyes peek out under it. */
155const brow = (g: Grid, x: number, y: number, n: number) => {
156 const row = g[y + HEAD]
157 for (let i = 0; i < n; i++) {
158 const c = row?.[x + stride.dx + i]
159 if (!c) continue
160 const q = QUARTERS[c.ch] ?? '' // ^ happy eyes: shut under the brim
161 const [ll, lr] = [q.includes('c'), q.includes('d')]
162 // a cell takes two colours: where only one bottom quarter is drawn, the hat's fills the other (an eye in shadow)
163 row[x + stride.dx + i] = ll && lr ? { ch: '▀', color: HAT, bg: c.bg ?? c.color } : ll || lr ? { ch: ll ? '▖' : '▗', color: c.color, bg: HAT } : { ch: '▀', color: HAT }
164 }
165}
166
167const COSTUMES: Record<string, Costume> = {
168 // detective: a fedora with a band, its brim over the brow, and a magnifying glass held out in the right hand
169 think: {
170 arms: 'right',
171 dress: (g, x, y) => {
172 put(g, x + 3, y - 1, '▃▃▃▃▃', HAT_BAND, HAT)
173 brow(g, x + 1, y, 7)
174 put(g, x, y, '▝', HAT)
175 put(g, x + 8, y, '▀▖', HAT) // the brim tips down on the right
176 put(g, x + 9, y + 1, '▄', LENS) // the handle, from the hand
177 put(g, x + 10, y, '▗▖', LENS)
178 put(g, x + 10, y + 1, '▚▞', LENS)
179 },
180 },
181 // footballer: a blue number 10 shirt and a white headband
182 kick: {
183 dress: (g, x, y) => {
184 for (let i = 0; i < 9; i++) tint(g, x + i, y + 1, JERSEY)
185 put(g, x + 3, y + 1, '10', 'white', JERSEY)
186 put(g, x + 1, y - 1, '▗▄▄▄▄▄▖', 'white')
187 },
188 },
189 // astronaut: a glass helmet close round the head, the face left clear, and an oxygen tank on its back
190 levitate: {
191 dress: (g, x, y) => {
192 put(g, x, y - 1, '▗▄▄▄▄▄▄▄▖', 'white')
193 put(g, x, y, '▐', 'white')
194 put(g, x + 8, y, '▌', 'white')
195 put(g, x - 2, y + 1, '▐█', GRAY)
196 },
197 },
198}
199// homemaker, at the stove and the oven alike: a big curly perm and a white apron with a heart pocket
200const HOMEMAKER: Costume = {
201 dress: (g, x, y) => {
202 put(g, x - 1, y - 1, '▗▟█▙▟█▙▟█▙▖', PERM)
203 put(g, x - 1, y, '▐█▌', PERM)
204 put(g, x + 7, y, '▐█▌', PERM)
205 put(g, x - 1, y + 1, '▝▘', PERM)
206 put(g, x + 8, y + 1, '▝▘', PERM)
207 put(g, x + 2, y + 1, '▄▄▄▄▄', 'white', ORANGE)
208 put(g, x + 4, y + 1, '♥', MINI_COLORS[3], 'white')
209 put(g, x + 3, y + 2, '▀▀▀', 'white')
210 },
211}
212COSTUMES.cook = HOMEMAKER
213COSTUMES.bake = HOMEMAKER
214Object.assign(COSTUMES, {
215 // wizard: a tall pointed hat and a long white beard
216 magic: {
217 dress: (g, x, y) => {
218 put(g, x, y - 1, '▁▁▃▆█▆▃▁▁', '#5B4FCF')
219 put(g, x + 3, y + 1, '▜█▛', 'white', ORANGE)
220 },
221 },
222 // cowboy: a hat with its brim curled up at both ends and a dent in the crown, a red neckerchief
223 herd: {
224 dress: (g, x, y) => {
225 put(g, x, y - 1, '▙▄▟█▇█▙▄▟', '#A0703C')
226 put(g, x + 3, y + 1, '▀█▀', 'red', ORANGE)
227 },
228 },
229 // painter: a beret tipped to one side and a palette in the other hand
230 sketch: {
231 dress: (g, x, y) => {
232 put(g, x + 2, y - 1, '▗▄▟▄▄▄▖', '#D04848')
233 put(g, x - 2, y + 1, '∙', '#56B6C2', WOOD)
234 put(g, x - 1, y + 1, '∙', '#E5C07B', WOOD)
235 },
236 },
237 // professor: a mortarboard, its tassel hanging down beside the head
238 chalk: {
239 dress: (g, x, y) => {
240 put(g, x, y - 1, '▀▀█████▀▀', HAT)
241 put(g, x + 8, y, '▌', 'yellow')
242 },
243 },
244 // DJ: headphones, the band over the head and a cup on each side
245 disco: {
246 dress: (g, x, y) => {
247 put(g, x, y - 1, '▗▄▄▄▄▄▄▄▖', 'white')
248 put(g, x, y, '█', 'magenta')
249 put(g, x + 8, y, '█', 'magenta')
250 },
251 },
252 // clown: a red nose, tufts of blue hair on both sides and a frilled collar
253 juggle: {
254 dress: (g, x, y) => {
255 put(g, x + 4, y, '●', 'red', ORANGE)
256 put(g, x - 1, y - 1, '▗▄', 'cyan')
257 put(g, x + 8, y - 1, '▄▖', 'cyan')
258 put(g, x - 1, y, '▐█', 'cyan')
259 put(g, x + 8, y, '█▌', 'cyan')
260 ;['yellow', 'magenta', 'cyan', 'magenta', 'yellow'].forEach((c, i) => put(g, x + 2 + i, y + 1, '▀', c, ORANGE))
261 },
262 },
263} satisfies Record<string, Costume>)
264export const DRESSED = Object.keys(COSTUMES)
265
266type Scene = (g: Grid, t: number) => void
267
268const GRAY = 'gray'
269const BOARD = '#2E4A3B'
270const WOOD = '#8B5A2B'
271// What Clawd works out on the blackboard, two lines a go (8 columns each)
272const LESSONS: [string, string][] = [['a+b=c', 'x^2+1=y'], ['f(x)=?', ' = 42'], ['1+1=2', 'Q.E.D.'], ['if (ok)', ' ship!']]
273const scenes: Record<string, Scene> = {
274 idle: (g, t) => {
275 // a little hop, then it lands with a squash and settles
276 const p = t % 24
277 clawd(g, t, { lift: p === 10 ? 1 : p === 11 || p === 12 ? -1 : 0, eyes: p >= 9 && p <= 16 ? 'smile' : undefined })
278 // a little one copies the hop a beat late
279 mini(g, 12, MINI_COLORS[0], { lift: p === 12 ? 1 : 0, eyes: p % 12 === 5 ? 'blink' : 'left' })
280 },
281
282 think: (g, t) => {
283 clawd(g, t, { arms: t % 16 < 8 ? 'down' : 'right' })
284 const bubble = ['·', '· ∘', '· ∘ ○', '· ∘ ○ ?', '· ∘ ○ !'][Math.floor(t / 3) % 5]
285 put(g, 11, 0, bubble, GRAY)
286 },
287
288 cook: (g, t) => {
289 clawd(g, t, { arms: t % 4 < 2 ? 'left' : 'right' }) // stirring
290 put(g, 12, 1, pick([' ~ ', ' ~ ≈ ', '≈ ~ ≈', ' ≈ ~ '], t), GRAY)
291 put(g, 12, 2, '▄▄▄▄▄', 'white')
292 put(g, 12, 3, '▀███▀', 'white')
293 put(g, 11, 2, t % 4 < 2 ? '\\' : '|', 'yellow') // spoon
294 },
295
296 bake: (g, t) => {
297 clawd(g, t, { arms: t % 10 < 5 ? 'right' : 'down' })
298 put(g, 12, 1, '┌────┐', 'white')
299 put(g, 12, 2, '│ │', 'white')
300 put(g, 13, 2, pick(['▒░▒░', '░▒░▒'], t), 'red')
301 put(g, 12, 3, '└────┘', 'white')
302 put(g, 14, 0, pick(['~', ' ~', '~ ~'], Math.floor(t / 2)), GRAY)
303 },
304
305 brew: (g, t) => {
306 clawd(g, t, { arms: 'right' })
307 put(g, 12, 1, pick([' ≈ ', '≈ ', ' ≈'], Math.floor(t / 2)), GRAY)
308 put(g, 12, 2, '╭─╮╮', 'white')
309 put(g, 12, 3, '╰─╯ ', 'white')
310 put(g, 13, 2, '▀', 'yellow')
311 },
312
313 walk: (g, t) => {
314 // two little ones in a row behind it; at the end they all about-face, so the little ones lead the way back
315 const right = goingRight(t, roam(12))
316 const x = 13 + pingPong(t, roam(12))
317 clawd(g, t, { x, legs: walkLegs(t), arms: t % 2 ? 'left' : 'right', ...facing(t, right) })
318 const eyes = right ? 'right' : 'left'
319 mini(g, x - 6, MINI_COLORS[1], { eyes, legs: t % 2 ? 'a' : 'b' })
320 mini(g, x - 12, MINI_COLORS[2], { eyes, legs: t % 2 ? 'b' : 'a' })
321 },
322
323 run: (g, t) => {
324 const x = 1 + pingPong(t * 2, roam(0))
325 const right = goingRight(t * 2, roam(0))
326 clawd(g, t, { x, legs: walkLegs(t), lift: t % 4 === 0 ? 1 : 0, arms: t % 2 ? 'left' : 'right', ...facing(t, right) })
327 put(g, right ? x - 2 : x + 10, 2, '≡', GRAY) // speed lines, behind
328 },
329
330 moonwalk: (g, t) => {
331 const x = 1 + roam(3) - pingPong(t, roam(3))
332 // gliding backwards: it faces the other way from where it goes
333 clawd(g, t, { x, legs: walkLegs(t), arms: 'right', ...facing(t, goingRight(t, roam(3))) })
334 put(g, x + 10, 0, pick(['♪', ' ♫', '♪ ♫'], t), 'cyan')
335 },
336
337 herd: (g, t) => {
338 const x = 1 + pingPong(t, roam(7))
339 clawd(g, t, { x, legs: walkLegs(t), arms: 'up', ...facing(t, goingRight(t, roam(7))) })
340 put(g, x + (goingRight(t, roam(7)) ? 11 : -6), 3, pick(['o o o', ' o o o', 'o o o'], t), 'white') // the flock
341 },
342
343 spin: (g, t) => {
344 clawd(g, t, { x: 2 + (t % 2), arms: pick(['left', 'up', 'right', 'down'] as const, t) })
345 put(g, 12, 0, t % 2 ? '↻' : '↺', 'cyan')
346 put(g, 0, 2, pick(['(', ' ', ')', ' '], t), GRAY)
347 },
348
349 magic: (g, t) => {
350 clawd(g, t, { arms: 'up', lift: t % 8 < 4 ? 1 : 0 })
351 const sparks = ['✦', '✧', '⋆', '✶', '·']
352 for (let i = 0; i < 5; i++) put(g, 11 + ((i * 3 + t) % 9), (i + t) % 3, pick(sparks, t + i), pick(['magenta', 'cyan', 'yellow'], i + t))
353 },
354
355 levitate: (g, t) => {
356 clawd(g, t, { lift: 1, legs: 'tuck', arms: 'up' })
357 put(g, 3, 3, pick(['· ✧ ·', '✧ · ✧'], t), 'cyan')
358 },
359
360 hatch: (g, t) => {
361 // the egg wobbles and cracks, bursts, and a baby Clawd stands in the shell, then hops out beside it
362 const p = t % 48
363 const baby = MINI_COLORS[Math.floor(t / 48) % MINI_COLORS.length]
364 const hatched = p >= 26
365 clawd(g, t, { arms: 'right', lift: p === 27 ? 1 : 0, eyes: hatched ? 'smile' : t % 12 === 0 ? 'blink' : 'right', shade: 'left' })
366 if (!hatched) {
367 const wobble = p >= 6 && p < 24 ? [0, 1, 0, -1][t % 4] : 0
368 put(g, 13 + wobble, 2, p < 12 ? '▗▄▖' : p < 18 ? '▗╱▖' : p < 24 ? '▗╳▖' : '✧ ✧', 'white')
369 put(g, 13 + wobble, 3, '▝▀▘', 'white')
370 if (p >= 24) put(g, 12, 1, '✦ ✦', 'yellow')
371 return
372 }
373 put(g, 13, 3, '▝▀▘', 'white') // the bottom half of the shell stays behind
374 const eyes = p % 7 === 0 ? 'blink' : 'left' // looking up at the big one
375 if (p < 34) mini(g, 12, baby, { lift: 1, eyes })
376 else if (p === 34) mini(g, 14, baby, { lift: 2, eyes })
377 else mini(g, 17, baby, { eyes, lift: p === 40 || p === 42 ? 1 : 0 })
378 },
379
380 grow: (g, t) => {
381 clawd(g, t, { arms: 'right' })
382 const h = Math.floor(t / 4) % 4
383 for (let i = 0; i < h; i++) put(g, 13, 3 - i, i === h - 1 ? '❀' : '│', i === h - 1 ? 'magenta' : 'green')
384 put(g, 12, 3, '▁▁▁', 'yellow')
385 },
386
387 forge: (g, t) => {
388 const hit = t % 4 === 0
389 clawd(g, t, { arms: hit ? 'right' : 'up' })
390 put(g, 11, hit ? 2 : 0, hit ? '╾' : '╤', 'white') // hammer
391 put(g, 12, 3, '▀▀█▀▀', 'white')
392 if (hit) put(g, 12, 1, pick(['* ✶', '✶ *'], t), 'yellow')
393 },
394
395 compute: (g, t) => {
396 clawd(g, t, { arms: t % 2 ? 'left' : 'right' })
397 for (let row = 1; row <= 3; row++) {
398 const bits = Array.from({ length: 8 }, (_, i) => (((i + 1) * 7 + t * (row + 2)) % 3 === 0 ? '1' : '0')).join('')
399 put(g, 12, row, bits, 'green')
400 }
401 },
402
403 type: (g, t) => {
404 clawd(g, t, { arms: t % 2 ? 'left' : 'right' })
405 const keys = '▤▤▤▤▤▤'
406 put(g, 12, 3, keys, GRAY)
407 put(g, 12 + (t % keys.length), 3, '▣', 'white')
408 },
409
410 talk: (g, t) => {
411 clawd(g, t, { arms: t % 6 < 3 ? 'right' : 'down' })
412 put(g, 12, 1, pick(['‹ . ›', '‹ .. ›', '‹ ... ›'], t), 'white')
413 },
414
415 dance: (g, t) => {
416 clawd(g, t, { lift: t % 2 ? 1 : 0, arms: t % 4 < 2 ? 'left' : 'right', legs: walkLegs(t), eyes: t % 16 < 10 ? 'smile' : 'open', shade: t % 4 < 2 ? 'left' : 'right' })
417 put(g, 12, 0, pick(['♪', '♪ ♫', ' ♫ ♪', '♫'], t), 'cyan')
418 // two backup dancers, bouncing on the off-beat
419 mini(g, 12, MINI_COLORS[3], { lift: t % 2 ? 0 : 1, eyes: 'right', legs: t % 4 < 2 ? 'a' : 'b' })
420 mini(g, 18, MINI_COLORS[0], { lift: t % 2 ? 0 : 1, eyes: 'left', legs: t % 4 < 2 ? 'b' : 'a' })
421 },
422
423 disco: (g, t) => {
424 // under a spinning mirror ball: the floor flashes, beams glint around the ball, Clawd and a little one dance
425 const lights = ['magenta', 'cyan', 'yellow', '#7BC67E']
426 for (let i = 0; i < 13; i++) put(g, i * 2, 3, '▁▁', pick(lights, i + Math.floor(t / 2)))
427 const beat = t % 4 < 2
428 clawd(g, t, { lift: beat ? 1 : 0, arms: pick(['up', 'right', 'up', 'left'] as const, Math.floor(t / 2)), eyes: t % 16 < 12 ? 'smile' : 'open', shade: beat ? 'left' : 'right' })
429 mini(g, 20, MINI_COLORS[3], { lift: beat ? 0 : 1, eyes: 'left', legs: beat ? 'a' : 'b' })
430 put(g, 15, 0, pick(['◐', '◓', '◑', '◒'], t), 'white') // the ball
431 // glints, all right of column 11 so none lands on Clawd
432 const glints: [number, number][] = [[13, 0], [17, 0], [12, 1], [18, 1], [14, 2], [16, 1], [12, 2], [18, 2]]
433 for (let k = 0; k < 3; k++) {
434 const [x, y] = glints[(t + k * 3) % glints.length]
435 put(g, x, y, pick(['✦', '✧', '·'], t + k), pick(lights, t + k))
436 }
437 },
438
439 juggle: (g, t) => {
440 clawd(g, t, { arms: t % 2 ? 'left' : 'right', lift: 0 }) // no hop: the balls on row 0 would land on its face
441 // left hand → over the head → right hand and back; row 1 only beside the body
442 const arc: [number, number][] = [[-1, 1], [1, 0], [4, 0], [7, 0], [9, 1], [7, 0], [4, 0], [1, 0]]
443 for (let b = 0; b < 3; b++) {
444 const [dx, y] = arc[(t + b * 3) % arc.length]
445 put(g, 2 + dx, y, 'o', pick(['red', 'yellow', 'cyan'], b))
446 }
447 },
448
449 honk: (g, t) => {
450 clawd(g, t, { arms: 'up', lift: t % 6 < 2 ? 1 : 0 })
451 if (t % 6 < 4) put(g, 12, 1, '< HONK! >', 'yellow')
452 },
453
454 sketch: (g, t) => {
455 clawd(g, t, { arms: t % 2 ? 'right' : 'down' })
456 put(g, 12, 1, '┌──────┐', 'white')
457 put(g, 12, 2, `│${'╱╲'.repeat(3).slice(0, (t % 7))}`.padEnd(7) + '│', 'white')
458 put(g, 12, 3, '└──────┘', 'white')
459 },
460
461 chalk: (g, t) => {
462 // the board stays put; Clawd writes, walks back to admire it, walks up again and wipes it
463 const BX = 16 // board columns 16-25, Clawd writes from 10 columns to its left
464 const p = t % 48
465 const [l1, l2] = pick(LESSONS, Math.floor(t / 48))
466 const wipe = (from: number, to: number) => {
467 for (let y = from + HEAD; y < 3 + HEAD; y++) for (let x = BX; x < Math.min(to, g[y].length); x++) g[y][x] = { ch: ' ', color: 'white', bg: BOARD }
468 }
469 wipe(0, BX + 10)
470 put(g, BX, 3, '▀▀▀▀▀▀▀▀▀▀', WOOD) // chalk tray
471 const n = p < 24 ? p : l1.length + l2.length
472 put(g, BX + 1, 1, l1.slice(0, n), 'white', BOARD)
473 put(g, BX + 1, 2, l2.slice(0, Math.max(0, n - l1.length)), 'white', BOARD)
474 const home = BX - 10
475 if (p < 24) {
476 // scribbling: the hand bobs, chalk taps the board
477 clawd(g, t, { x: home, eyes: t % 12 === 0 ? 'blink' : 'right', arms: t % 2 ? 'right' : 'down', shade: 'left' })
478 put(g, BX - 1, 1 + (t % 2), '·', 'white')
479 } else if (p < 28) {
480 // backs away, still looking at the board
481 clawd(g, t, { x: home - (p - 23), eyes: 'right', legs: walkLegs(t), shade: 'left' })
482 } else if (p < 36) {
483 // admires the work
484 clawd(g, t, { x: home - 4, eyes: p === 28 ? 'open' : 'smile', arms: 'down', lift: p === 31 ? 1 : 0, shade: 'none' })
485 } else if (p < 40) {
486 clawd(g, t, { x: home - 3 + (p - 36), legs: walkLegs(t), ...facing(t, true) })
487 } else {
488 // wipes left to right
489 const ex = BX + (p - 40) * 2
490 wipe(1, Math.min(ex, BX + 10))
491 put(g, Math.min(ex, BX + 8), 1, '▆▆', WOOD, BOARD)
492 clawd(g, t, { x: home, eyes: 'right', arms: t % 2 ? 'right' : 'down', shade: 'left' })
493 }
494 },
495
496 weather: (g, t) => {
497 clawd(g, t, { eyes: 'open', arms: 'up' })
498 // the cloud hangs beside it, so the rain never falls on its face
499 put(g, 12, 0, '☁☁☁', 'white')
500 for (let y = 1; y < H - HEAD; y++) put(g, 12 + ((t + y) % 3), y, '╵', 'cyan')
501 },
502
503 thunder: (g, t) => {
504 clawd(g, t, { arms: t % 4 === 0 ? 'up' : 'down', lift: t % 4 === 0 ? 1 : 0 })
505 put(g, 12, 0, '☁☁', GRAY)
506 if (t % 4 === 0) put(g, 13, 1, 'ϟ', 'yellow')
507 },
508
509 dig: (g, t) => {
510 // tunnels along the ground at a third of walking pace, dirt flying out behind
511 const x = 1 + pingPong(Math.floor(t / 3), roam(2))
512 const soil = '▒▓▒░▓▒▒░▓▒▓░'
513 put(g, 0, 3, Array.from({ length: stride.width }, (_, i) => soil[i % soil.length]).join(''), 'yellow')
514 clawd(g, t, { x, lift: 0, arms: t % 2 ? 'left' : 'right', legs: 'tuck' })
515 put(g, x - 2, 2, pick(['· ', ' ∙', '∙·'], t), 'yellow')
516 },
517
518 kick: (g, t) => {
519 const p = t % 14 // 0-3 wind up, 3 kick, 4-7 ball flies, 7+ celebrate
520 const kicking = p === 3
521 clawd(g, t, { arms: p >= 7 ? 'up' : kicking ? 'right' : 'down', legs: kicking ? 'b' : undefined, lift: p >= 7 && p % 2 ? 1 : 0 })
522 put(g, 18, 1, '┌─', 'white') // goal
523 put(g, 18, 2, '│#', 'white')
524 put(g, 18, 3, '│#', 'white')
525 const bx = p < 4 ? 11 : Math.min(19, 11 + (p - 3) * 2)
526 put(g, bx, p >= 4 && p <= 6 ? 2 : 3, '●', 'white')
527 if (p >= 7) put(g, 12, 0, 'GOAL!', 'yellow')
528 },
529
530 skate: (g, t) => {
531 // glides across the ice on one blade then the other, arms out for balance, frost trailing behind
532 const span = roam(2)
533 const x = 1 + pingPong(t, span)
534 const right = goingRight(t, span)
535 put(g, 0, 3, '─'.repeat(stride.width), 'cyan') // the rink
536 const legs = Math.floor(t / 2) % 2 ? 'a' : 'b'
537 clawd(g, t, { x, lift: 1, arms: t % 8 < 4 ? 'up' : right ? 'right' : 'left', legs, ...facing(t, right) })
538 // a solid blade right under each foot, so it reads apart from the thin ice line
539 put(g, x + 1, 3, '▀▀▀', 'white')
540 put(g, x + 5, 3, '▀▀▀', 'white')
541 put(g, right ? x - 3 : x + 10, 2, pick(['· ', ' · ', ' ·'], t), 'white')
542 },
543
544 campfire: (g, t) => {
545 // two Clawds sit still on either side of the fire, gazing in: a slow blink now and then,
546 // a hand held out to the warmth; only the fire and the eyes move.
547 // With room to spare a little one sits on each outer side, blinking out of step with the big ones.
548 const o = stride.width >= 37 ? 4 : 0
549 const warm = t % 20 < 12
550 // eyes close happily while the hands are warm
551 const eyes = t % 30 < 2 ? 'blink' : warm ? 'smile' : 'open'
552 clawd(g, t, { x: 2 + o, eyes, arms: warm ? 'right' : 'down' })
553 clawd(g, t, { x: 18 + o, eyes, arms: warm ? 'left' : 'down', color: PURPLE })
554 if (o) {
555 mini(g, 0, MINI_COLORS[1], { eyes: t % 30 === 11 || t % 30 === 13 ? 'blink' : 'right' })
556 mini(g, 32, MINI_COLORS[3], { eyes: t % 30 >= 20 && t % 30 < 22 ? 'blink' : 'left' })
557 }
558 put(g, 13 + o, 0, pick([' ·', ' ˙ ', '· ', ' ', ' · '], Math.floor(t / 2)), 'yellow') // sparks
559 put(g, 13 + o, 1, pick([' ▲ ', '▴▲ ', ' ▲▴', ' ▴ '], t), 'yellow')
560 put(g, 13 + o, 2, pick(['▟█▙', '▟▙▙', '▟█▟', '▙█▙'], t), 'red')
561 put(g, 14 + o, 2, '▒', 'yellow') // the hot core
562 put(g, 12 + o, 3, '═╳═╳═', '#8B5A2B') // logs
563 },
564
565 shift: (g, t) => {
566 // 閃身步: calls the move's name, a character at a time, top to bottom behind it, then flashes across
567 // the stage in three frames, leaving afterimages that fade; then the same back the other way
568 const q = t % 22
569 const right = t % 44 < 22
570 const [home, end] = right ? [3, stride.width - 12] : [stride.width - 12, 3]
571 const dir = right ? 1 : -1
572 const at = [home, home + Math.round((end - home) / 3), home + Math.round(((end - home) * 2) / 3)]
573 if (q < 14) tall(g, right ? home - 3 : home + 10, 0, '閃身步'.slice(0, 1 + Math.floor(q / 3)), 'yellow')
574 // an afterimage where it stood each dash frame, darker and thinner as it fades
575 for (let k = 0; k < 3; k++) {
576 const age = q - 12 - k
577 if (age < 0 || age >= 6) continue
578 const [ink, color] = age < 2 ? ['▓', SHADE] : age < 4 ? ['▒', '#8A4A35'] : ['░', '#5E3D33']
579 put(g, at[k], 1, ` ${ink.repeat(7)} `, color)
580 put(g, at[k], 2, ink.repeat(9), color)
581 put(g, at[k], 3, ` ${ink}${ink} ${ink}${ink} `, color)
582 }
583 const eyes = right ? 'right' : 'left'
584 if (q < 12) clawd(g, t, { x: home, ...facing(t, right), arms: q < 6 ? 'down' : 'up' }) // the stance
585 else if (q < 14) clawd(g, t, { x: at[q - 11], eyes, arms: right ? 'right' : 'left', legs: 'tuck', shade: right ? 'left' : 'right' })
586 else if (q < 16) clawd(g, t, { x: q === 14 ? end + dir : end, eyes, lift: -1 }) // lands sliding, with a squash
587 else clawd(g, t, { x: end, eyes: 'smile', arms: q < 19 ? 'up' : 'down', lift: q === 17 ? 1 : 0, shade: 'none' })
588 },
589
590 flow: (g, t) => {
591 clawd(g, t, { lift: t % 6 < 3 ? 1 : 0 })
592 const wave = '∿~'
593 put(g, 0, 3, Array.from({ length: 16 }, (_, i) => wave[(i + t) % 2]).join(''), 'cyan')
594 },
595}
596
597// Reactions to /clawd: played over the show for a few seconds, never part of the rotation
598const reactions: Record<string, Scene> = {
599 pet: (g, t) => {
600 // purrs under the hand: happy eyes, a little bounce, hearts floating up
601 clawd(g, t, { eyes: 'smile', arms: t % 6 < 3 ? 'up' : 'down', lift: t % 8 === 0 ? 1 : 0, shade: 'none' })
602 for (let k = 0; k < 2; k++) {
603 const p = (t + k * 3) % 6
604 put(g, 11 + k * 3 + (p % 2), 2 - Math.floor(p / 2), '♥', pick(['red', 'magenta'], k))
605 }
606 },
607
608 feed: (g, t) => {
609 // a cookie rolls in, gets munched, crumbs fall
610 const p = t % 16
611 const eating = p >= 6
612 clawd(g, t, { eyes: eating ? 'smile' : 'right', arms: eating ? (t % 2 ? 'left' : 'right') : 'down', shade: eating ? 'none' : 'left' })
613 if (!eating) put(g, 21 - p * 2, 2, '●', 'yellow')
614 else {
615 put(g, 11, 2 + (p % 2), pick(['·', '∙'], t), 'yellow') // crumbs
616 if (p < 12) put(g, 12, 1, pick(['nom', 'nom nom'], Math.floor(t / 2)), 'white')
617 }
618 },
619
620 // chatting: it stands still under its speech bubble, thinking, then talking with its hands
621 ponder: scenes.think,
622 say: (g, t) => clawd(g, t, { arms: pick(['down', 'right', 'down', 'left'] as const, Math.floor(t / 3)), eyes: t % 18 === 0 ? 'blink' : 'open', shade: 'none' }),
623
624 wave: (g, t) => {
625 // waves hello with both arms
626 clawd(g, t, { eyes: t % 12 < 9 ? 'smile' : 'open', arms: t % 4 < 2 ? 'up' : 'down', shade: 'none' })
627 put(g, 11, 1, pick([')', ' )', ' )'], t), 'white')
628 put(g, 12, 0, 'hi!', 'yellow')
629 },
630}
631export const REACTION_NAMES = Object.keys(reactions)
632
633// Spinner word → scene, by stem; the first match wins
634const VERBS: [RegExp, string][] = [
635 [/moonwalk/, 'moonwalk'],
636 [/shift|beam|dodg|sidestep|evad|evasi|flit/, 'shift'],
637 [/campfir|bonfir|kindl|smolder|smoulder|stok|crackl|flicker|glow|fire/, 'campfire'],
638 [/skat|glid|slid|skid|coast/, 'skate'],
639 [/kick|dribbl|scor|punt|volley|soccer|footbal/, 'kick'],
640 [/levitat|hyperspac/, 'levitate'],
641 [/thunder/, 'thunder'],
642 [/honk|boop|hullaballoo|shenanigan|tomfool|razzle/, 'honk'],
643 [/juggl/, 'juggle'],
644 [/sketch|doodl|draw/, 'sketch'],
645 [/deciph|elucidat|philosoph|pontificat|deliberat|determin|reason|theoriz|theoris|hypothes|deduc|formulat|scribbl|jott|lectur|teach|explain/, 'chalk'],
646 [/bak|proof|leaven|knead|frost|roast/, 'bake'],
647 [/brew|percolat|ferment|steep/, 'brew'],
648 [/cook|simmer|stew|saut|marinat|flamb|julienn|season|garnish|zest|blanch|carameli|drizzl|whisk|concoct|infus|temper|boil|fry/, 'cook'],
649 [/herd|wrangl|muster/, 'herd'],
650 [/scamper|scurr|skedaddl|gallop|hustl|catapult|swoop|pounc|zoom|dash/, 'run'],
651 [/mosey|schlep|putter|wander|meander|perambul|gallivant|stroll|waddl|lollygag|dilly|zigzag|scuttl/, 'walk'],
652 [/spin|churn|whirr|swirl|whirlpool|twist|reticulat|orbit|cascad|topsy|wibbl|combobul|coalesc|smoosh/, 'spin'],
653 [/conjur|manifest|transmut|transfigur|enchant|prestidig|metamorph|quantum|warp|sublimat|ioniz|crystalli|channel|alchem/, 'magic'],
654 [/hatch|incubat|nest|roost/, 'hatch'],
655 [/germinat|sprout|pollinat|photosynth|cultivat|propagat|unfurl|symbiot|bloom|nucleat/, 'grow'],
656 [/disco|funk|boogi|groov|fiesta|shindig|soiree/, 'disco'],
657 [/vib|jitterbug|shimm|sock|bebop|frolic|choreograph|harmoni|orchestrat|compos|improvis|jam/, 'dance'],
658 [/calculat|comput|crunch|process|infer|synthesi|analy|hash|gitif|quantif/, 'compute'],
659 [/forg|craft|build|construct|tinker|form|creat|generat|actualiz|accomplish|action|effect|embellish|bootstrap|doing|work/, 'forge'],
660 [/mist|nebuli|evaporat|billow|gust|precipitat|cloud/, 'weather'],
661 [/burrow|spelunk|slither|dig/, 'dig'],
662 [/flow|ebb|osmos|undulat|wav/, 'flow'],
663 [/ponder|mus|mull|ruminat|cogitat|cerebrat|consider|contemplat|think|puzzl|envision|imagin|ideat|perus|bloviat|befuddl|flummox|noodl|claud/, 'think'],
664]
665
666export type Mode = 'requesting' | 'responding' | 'thinking' | 'tool-input' | 'tool-use'
667
668/** Which scene a spinner word acts out; an unknown word falls back to what the turn is doing. */
669export const sceneFor = (word: string, mode: Mode) => {
670 const w = word.toLowerCase().replace(/[^a-z]/g, '')
671 const hit = VERBS.find(([re]) => re.test(w))
672 if (hit) return hit[1]
673 return mode === 'tool-use' || mode === 'tool-input' ? 'type' : mode === 'responding' ? 'talk' : mode === 'thinking' ? 'think' : 'idle'
674}
675
676// Only scenes whose extras belong to Clawd (a bubble, notes, sparks) wander; the rest travel on their own
677// or stand by a pot, a board, an anvil… that must stay put while Clawd works at it
678export const WANDERS = new Set(['idle', 'think', 'talk', 'dance', 'juggle', 'honk', 'levitate', 'magic', 'spin'])
679const PROPS_WIDTH = 23 // the widest scene's Clawd plus props, from column 0 (dance with its backup dancers)
680const PAUSE = 10 // frames spent standing at each end
681
682/** Where the wander puts the frame: stroll right, pause, stroll left, pause; a hop at each turn. */
683export const wander = (t: number, width: number) => {
684 const span = Math.max(0, Math.min(width - PROPS_WIDTH, 30))
685 if (span === 0) return STILL
686 const period = 2 * (span + PAUSE)
687 const p = t % period
688 // each end: hop, land with a squash for two frames, then stand
689 const atEnd = (q: number) => ({ moving: false, hop: q === 0, squash: q === 1 || q === 2 })
690 if (p < span) return { dx: p, moving: true, hop: false, squash: false, dir: 1 }
691 if (p < span + PAUSE) return { dx: span, ...atEnd(p - span), dir: 1 }
692 if (p < 2 * span + PAUSE) return { dx: 2 * span + PAUSE - p, moving: true, hop: false, squash: false, dir: -1 }
693 return { dx: 0, ...atEnd(p - 2 * span - PAUSE), dir: -1 }
694}
695
696/** One frame of the stage, as rows of same-colour runs; `dressed` false leaves the scene's costume off. */
697export const frameRows = (word: string, mode: Mode, t: number, width: number = W, scene?: string, dressed = true) => {
698 const name = scene ?? sceneFor(word, mode)
699 Object.assign(stride, WANDERS.has(name) ? wander(t, width) : STILL, { width })
700 wearing = dressed ? COSTUMES[name] : undefined
701 const g = blank(width)
702 ;(scenes[name] ?? reactions[name] ?? scenes.idle)(g, t)
703 return g.map(row => {
704 const runs: { text: string; color?: string; bg?: string }[] = []
705 for (const c of row) {
706 const last = runs[runs.length - 1]
707 if (last && last.color === c.color && last.bg === c.bg) last.text += c.ch
708 else runs.push({ text: c.ch, color: c.color, bg: c.bg })
709 }
710 return runs
711 })
712}
713
714export const SCENE_NAMES = Object.keys(scenes)
715
716// ---- Which scene plays when: a running tool first, else the spinner word's act, then a rotation ----
717
718/** A running tool's scene, by tool name; any other tool hammers away. */
719const TOOL_SCENES: [RegExp, string][] = [
720 [/^(Bash|PowerShell|Monitor)$/, 'type'],
721 [/^(Read|Grep|Glob|LS)$/, 'think'],
722 [/^(Edit|Write|MultiEdit|NotebookEdit)$/, 'sketch'],
723 [/^(Agent|Task|SendMessage)$/, 'herd'],
724 [/^Web/, 'weather'],
725 [/^(TodoWrite|Skill|ToolSearch)$/, 'juggle'],
726 [/^mcp__/, 'magic'],
727]
728export const sceneForTool = (tool: string) => TOOL_SCENES.find(([re]) => re.test(tool))?.[1] ?? 'forge'
729
730export const FRAME_MS = 140
731export const ACT_MS = 15_000 // each act runs a quarter of a minute
732export const ACT_FRAMES = Math.round(ACT_MS / FRAME_MS)
733const ROTATION = SCENE_NAMES.filter(n => n !== 'idle' && n !== 'type' && n !== 'talk')
734const STEP = [7, 5, 3, 11, 13].find(k => ROTATION.length % k !== 0) ?? 1 // coprime with the length, so it visits all
735
736/**
737 * `played`: rotation acts earlier turns of the session got through, so the rotation picks up where it left off;
738 * `prev`: the scene the act before this one showed
739 */
740export type Cue = { word: string; mode: Mode; tick: number; seed: number; tool?: string; played?: number; prev?: string }
741
742/**
743 * The scene for this frame of a turn. Act 0 opens on the running tool, else the spinner word;
744 * every later act steps through the rotation in an order the session's seed shuffles
745 * (a step coprime with the list's length visits all), whatever tool runs, skipping the opener.
746 */
747export const sceneAt = ({ word, mode, tick, seed, tool, played = 0, prev }: Cue) => {
748 const act = Math.floor(Math.max(0, tick) / ACT_FRAMES)
749 if (act === 0) return tool ? sceneForTool(tool) : sceneFor(word, mode)
750 const n = ROTATION.length
751 const i = seed + (played + act - 1) * STEP
752 // the next one along is neither of its neighbours, as the step is not ±1
753 return ROTATION[i % n] === prev ? ROTATION[(i + 1) % n] : ROTATION[i % n]
754}
755
756export type Shown = { turn: number; act: number; scene: string }
757
758/**
759 * The scene on stage: picked at an act's first frame and held for the whole act, whatever the
760 * tool, the spinner word or the mode do meanwhile. `turn` tells the turns apart (its first frame).
761 */
762export const hold = (shown: Shown | undefined, turn: number, cue: Cue): Shown => {
763 const act = Math.floor(Math.max(0, cue.tick) / ACT_FRAMES)
764 const same = shown?.turn === turn
765 if (same && shown.act === act) return shown
766 return { turn, act, scene: sceneAt({ ...cue, prev: same ? shown.scene : undefined }) }
767}
768types/index.d.ts 10 lines1export type Frame = number
2/** The turn's show, which a hot reload keeps: whether a turn runs, the frame it started on, the rotation's seed and acts played. */
3export type Show = { isTurnRunning: boolean; turnBase: number; seed: number; played: number }
4
5declare module 'claude-code' {
6 interface PluginState {
7 'clawd-actor': { frame: Frame; show: Show }
8 }
9}
10