SLOPSHOPPER

arcade

The Claude Code Arcade: pixel games above the prompt, played by your work (an invading octopus, a duck hunt, Bug Command, which you can play along with, Dario…

panebandguardcommandtoastprompt
★ 5v0.11.4MITupdated 2026-10-26mutlumehmet/claude-plugins/plugins/arcade
A shopper browsing a rack in a slop shop
Preview · a replayed session in a sandbox
claude · ~/work/app · arcade
│ ┃ Arcade ✕ › fix the failing auth╭────────────────────────────────────────────╮ │ ┃ ● Octo Invader ★ a pixel octopus smashes a │ arcade │ │ ┃ Duck Hunt ☆ your commits shoot the duc ⏺ Read(src/auth.ts) │ Arcade: Octo Invader is your game. ▶ under │ │ ┃ Bug Command ☆ bugs fall on six cities; c ⎿ Read 6 lines │ it tries the next one, ☰ lists all 10 and │ │ ┃ Dario ☆ a side scroller: tool call ⏺ Update(src/auth.ts) │ sets the game new terminals start with (or │ │ ┃ Block Town ☆ your agents build a block ⎿ Added 2 lines, re╰────────────────────────────────────────────╯ │ ┃ Dragon Lair ☆ a pixel dragon that breath ⏺ Bash(bun test) ╭────────────────────────────────────────────╮ │ ┃ Jackpot ☆ a slot machine: every fini ⎿ 3 pass, 1 fail │ arcade │ │ ┃ Outlaw ☆ an Atari duel: you against │ 🐙 Push! The octopus pulls a plane out of │ │ ┃ Tama ☆ a Tamagotchi your work fee ● Done. refresh now re│ the sky │ │ ┃ Tetris ☆ Tetris where Claude's tool ╰────────────────────────────────────────────╯ │ ┃ ✻ Worked for 42s · done 4:20 PM │ ┃ ⟳ Check for an Arcade update │ ┃ A name plays it here. ☆ makes it the game › /arcade │ ┃ new terminals start with. Esc closes. ⎿ arcade: Arcade menu open: pick a game, ☆ makes it your default. │ │ ▶ next game ☰ all games and your default ◀ Octo Invader ▶ ☰ ⟳ ▄▄▄▄ Lv 1 ⌂ 0 ✈ 0 ⚒ 9 ▄██████████▄ ██████████████ ⟨Claude Code's own drawing⟩ ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── › ? for shortcuts

Draws

Band
▶ next game ☰ all games and your default ◀ Octo Invader ▶ ☰ ⟳ ▄▄▄▄ Lv 1 ⌂ 0 ✈ 0 ⚒ 9 ▄██████████▄ ██████████████ ⟨Claude Code's own drawing⟩
Pane · Arcade
● Octo Invader ★ a pixel octopus smashes a city while Claud Duck Hunt ☆ your commits shoot the ducks, failed tools Bug Command ☆ bugs fall on six cities; click the sky to Dario ☆ a side scroller: tool calls bring coins, b Block Town ☆ your agents build a block town, a castle o Dragon Lair ☆ a pixel dragon that breathes fire when you Jackpot ☆ a slot machine: every finished turn pulls Outlaw ☆ an Atari duel: you against the bugs Tama ☆ a Tamagotchi your work feeds Tetris ☆ Tetris where Claude's tools drop the piece ⟳ Check for an Arcade update A name plays it here. ☆ makes it the game new terminals start with. Esc closes.
README

arcade

The Claude Code Arcade: pixel games in the line above the prompt, played by your work. Every tool call, commit, merge and failed test moves the game on. Part of claude-plugins.

Contents: Quick start · The games · Switching games · Game guides · Moments · Tuning the moments · Scores · What it reads and does · Install · Known gaps

Octo Invader in a terminal: a pixel octopus smashes a city above the prompt while Claude edits, commits and merges

Quick start

Type these at the Claude Code prompt, then pick a scope (user is the usual one). There is nothing to set up.

/plugin marketplace add mutlumehmet/claude-plugins
/plugin install arcade@mehmetmutlu

Octo Invader starts by itself, and the first time a short notice says where the controls are. Then just work: the game plays along. Above the game sit small buttons:

ButtonWhat it does
◀ ▶The previous or next game, in this terminal
☰The game menu: every game with a line about it. A name plays it here, ☆ makes it your default
☆ make defaultShows once this terminal plays a game other than your default; makes it the game every new terminal starts with
⟳Checks for a new Arcade version and installs it (the same as /plugin update arcade@mehmetmutlu), then puts /reload-plugins in the prompt for you. When a newer version is out it lights up as a yellow ● ⟳ update 0.x.y

Updates: Claude Code does not update plugins from this marketplace on its own unless you turn it on (/plugin, Marketplaces, mehmetmutlu, Enable auto-update). Without that, press ⟳ now and then, or type /arcade update. So you hear about it, each new terminal looks once for a newer version (it reads the version number in this repository's plugin.json on GitHub, nothing else). When one is out, ⟳ turns into a yellow ● ⟳ update 0.x.y and a notice says so, once per version. It never installs anything until you press it, and never checks again while the terminal is open. /arcade update check off stops the look, on brings it back.

The games

<table> <tr><td> <b>Octo Invader</b> <code>/arcade octopus</code>: a pixel octopus smashes a city the full width of the line while Claude edits<br> <img src="../../docs/images/octo-invader.gif" width="800" alt="Octo Invader strip"> </td></tr> <tr><td> <b>Duck Hunt</b> <code>/arcade duck</code>: your moments shoot the ducks down, failed tools let them fly away<br> <img src="../../docs/images/duck-hunt.gif" width="800" alt="Duck Hunt strip"> </td></tr> <tr><td> <b>Bug Command</b> <code>/arcade bugs</code>: bugs fall on six cities; Claude's tools shoot them down, and you can click the sky to fire too<br> <img src="../../docs/images/bug-command.gif" width="800" alt="Bug Command strip"> </td></tr> <tr><td> <b>Dario</b> <code>/arcade dario</code>: a side scroller; tool calls bring ? blocks and coins, a failed tool sends a bug<br> <img src="../../docs/images/dario.gif" width="800" alt="Dario strip"> </td></tr> <tr><td> <b>Block Town</b> <code>/arcade town</code>: your agents build a medieval town in blocks; big moments raise a castle<br> <img src="../../docs/images/block-town.gif" width="800" alt="Block Town strip"> </td></tr> <tr><td> <img src="../../docs/images/arcade-hero.gif" width="400" align="right" alt="The five small games: dragon, slot machine, duel, Tamagotchi, Tetris"> Five small games at the right of the line:<br> <b>Dragon Lair</b> <code>/arcade dragon</code>: a pixel dragon that breathes fire when you ship<br> <b>Jackpot</b> <code>/arcade jackpot</code>: a slot machine; every finished turn pulls the lever<br> <b>Outlaw</b> <code>/arcade outlaw</code>: an Atari duel; you fire at the good moments, the bug when a tool fails<br> <b>Tama</b> <code>/arcade tama</code>: a Tamagotchi your work feeds, or it packs its bags<br> <b>Tetris</b> <code>/arcade tetris</code>: Claude's tools drop the pieces </td></tr> </table>

Switching games

The buttons above do the everyday switching. Everything else is a word after /arcade, and each Claude Code config directory (an account) keeps its own choice.

CommandWhat it does
/arcadeOpens the game menu (in claude -p, lists the games instead)
/arcade duckPlays Duck Hunt in this terminal; other terminals and your default stay as they are
/arcade default duckMakes Duck Hunt the game every new terminal starts with, and plays it here
/arcade nextThe next game in this terminal
/arcade random, rotate, all, offHow new terminals pick: one at random, the next one in turn, every game at once, or none. /arcade default <game> goes back to one fixed game
/arcade pool dragon tetrisPicks only from these games (for random, rotate and all)
/arcade hideClears this terminal; /arcade next brings a game back
/arcade updateChecks for a new Arcade version and installs it, like ⟳
/arcade update check offStops the look for a new version when a terminal opens (on brings it back)
/arcade helpThe setting, which games this terminal shows, and these commands

A game that is not shown keeps playing and keeps its score for this terminal; it only stops drawing and stays quiet. A game's own command (/dragon, /duck and the rest) shows its score and plays its practice moves.

Game guides

What each game does with your work, its score line and its practice moves.

Octo Invader (octopus)

A pixel octopus invades a city that runs the full width of the line above the prompt. It acts out what Claude is doing, Godzilla style, and pulls planes out of the sky when something worth celebrating happens.

octo-invader in a terminal: Claude reads, edits, commits and merges while the octopus walks the streets, smashes a building, pulls a plane out of the sky and takes the city

The strip on its own, as the mod draws it:

The octopus strip: a city the width of the terminal, buildings toppled, a plane downed, a flag on the rubble

Both GIFs are drawn by the mod's own code from a scripted session (a read, an edit, a web search, a commit, a merge); the window around the strip is a mock up of a terminal.

  • While Claude works the octopus shows it: it hops when you send a message, hovers over the rooftops while Claude thinks, walks the streets on its tentacles while a file is read, hunts about with a ? while Claude searches, and takes to the sky for web and MCP tools.
  • Edits and shell commands are demolition: it walks up to the nearest building and pounds it down a storey at a time until it falls with a CRASH!. Fallen buildings rise again after about 45 seconds, so the city never runs out.
  • Each subagent is a baby octopus that swims behind it in a line, paddles faster as the subagent works, and swims home when it finishes (or sinks when it fails).
  • A failed tool leaves it dazed with stars over its head; two minutes of quiet and it curls up asleep.
  • Moments: a small one is a squirt of ink, a medium one a plane snatched out of the sky and thrown down (BOOM!), a big one a RAMPAGE! through the streets, and a merge, release, deploy, streak or record ends with a flag on the rubble and THE CITY IS MINE.
  • The score sits at the right end of the strip: Lv 3 ⌂ 12 ✈ 4 ⚒ 140 (level, buildings toppled, planes downed, tool calls).
  • /octopus shows the score; /octopus ink, plane, rampage and conquer show off each size.

Duck Hunt (duck)

A marsh the full width of the line above the prompt, with the grass along the bottom, a tree, a dog and ducks. Your work does the shooting.

Duck Hunt in a terminal: a test fails and the dog laughs, the tests go green for a double, a commit shoots a duck, a merge is a perfect round

The strip on its own, as the mod draws it:

The Duck Hunt strip: a marsh the width of the terminal, the dog in the grass, ducks flushed and shot down

Both GIFs are drawn by the Arcade's own code from a scripted session (a read, a failing test, an edit, passing tests, a commit, a merge); the window around the strip is a mock up of a terminal.

  • While Claude works the dog sniffs along the grass, faster while a tool runs, and now and then flushes a duck that flaps across the sky.
  • Moments: a small one is a shot (a flash of the crosshair), a medium one shoots a duck down and the dog pops up from the grass holding it, a big one is a double (DOUBLE!, the dog holds two), and a merge, release, deploy, streak or record is a PERFECT! round with feathers everywhere.
  • A failed tool lets the duck in the air get away (FLY AWAY), and the dog comes up laughing. Two minutes of quiet and the dog lies down asleep.
  • Rounds: every ten ducks down is a new round (ROUND 3).
  • The score sits at the right end of the strip: R 2 ▼ 14 ↗ 3 ⚒ 140 (round, ducks down, ducks that got away, tool calls).
  • /duck shows the score; /duck shot, hunt, double, perfect and flyaway are practice that counts nothing.

Bug Command (bugs)

Six cities and three silos along the bottom of the line above the prompt, the full width of it. Bugs fall on the cities; Claude's work fires the counter missiles, and you can fire too. The one Arcade game you can play along with while you wait.

Bug Command in a terminal: a failed test drops a fast bug and you click the sky to shoot it down, a bug gets through and a city falls, the tests going green fire a salvo that rebuilds it, and a commit is a sure hit

The strip on its own, as the mod draws it:

The Bug Command strip: six cities and three silos the width of the terminal, red bug trails, blue counter missiles, blasts, and the mouse pointer firing

Both GIFs are drawn by the Arcade's own code from a scripted session (a read, a failing test, an edit, passing tests, a commit), with the mouse clicks played into the sky's own pointer handler; the window around the strip is a mock up of a terminal.

  • While Claude works a bug falls now and then, a red trail from the top towards a city. A failed tool drops a fast one (INCOMING).
  • Every finished tool call fires a shot from the nearest silo at the lowest bug; most of them hit. A blast takes out every bug inside it, and each bug it takes out blasts too.
  • Moments: a small one is a shot (or a flare in an empty sky), a medium one a sure hit, a big one a salvo at every bug in the sky that also rebuilds a fallen city (BONUS CITY).
  • A bug that gets through ruins its city. When every city has fallen it is THE END, and new cities go up.
  • You can shoot: click anywhere in the sky and the nearest silo fires there. After a click the sky has the keyboard: the arrows move the crosshair (with shift, faster), space or Enter fires at it, and 1, 2, 3 fire from the left, middle or right silo. A silo you fire from greys out for a moment. Esc hands the keyboard back to the prompt.
  • The score sits at the right end of the strip: ✸ 14 ☞ 5 ✝ 2 ⚒ 140 ⌂ 6 (bugs shot down, the ones you shot yourself, cities lost, tool calls, cities standing).
  • /bugs shows the score and the controls; /bugs flare, shot and salvo are practice that counts nothing, and /bugs incoming drops a practice bug to shoot at.

Dario (dario)

A side scrolling course the full width of the line above the prompt, with a ground of bricks, clouds, bushes and pipes. Dario runs while Claude works; you only watch.

Dario in a terminal: tool calls bring ? blocks and coins, a failing test sends a bug that knocks into Dario, green tests are a course clear at the flag pole, a commit stomps a bug and a merge is a world clear with fireworks

The strip on its own, as the mod draws it:

The Dario strip: a brick ground the width of the terminal, Dario running, ? blocks, a bug, pipes and the flag pole

Both GIFs are drawn by the Arcade's own code from a scripted session (a read, a search, a failing test, an edit, passing tests, a commit, a merge); the window around the strip is a mock up of a terminal.

  • While Claude works the course scrolls by, fastest while a tool runs, and Dario jumps the pipes on its way. Two minutes of quiet and he sits down for a nap.
  • Every finished tool call brings a ? block: Dario jumps, bumps it and a coin flies out. With two blocks already waiting, the coin comes straight away.
  • A failed tool sends a bug walking in, and it knocks into Dario (OUCH).
  • Moments: a small one is a hop and a sparkle, a medium one a bug stomped flat, a big one a flag pole: Dario slides down it for a COURSE CLEAR! and the next course. A merge, release, deploy, streak or record is a WORLD CLEAR! with fireworks.
  • The score sits at the right end of the strip: 1-3 ◎ 34 ✪ 5 ✗ 2 ⚒ 140 (world and course, coins, bugs stomped, knocks, tool calls). Every hundred coins is a 1UP.
  • /dario shows the score; /dario coin, ouch, stomp, clear and world are practice that counts nothing.

Block Town (town)

A town in blocks, seen from the side, the full width of the line above the prompt: grass, dirt and stone, then houses, farms, a well, towers and a grove of trees. Your agents build it while they work, and it grows for as long as the terminal is open, so a glance in the middle of a long session shows how much got done.

Block Town in a terminal: the main agent and a helper villager build a house, a farm and a grove while sheep, a pig and chickens wander between them, a failing test brings a creeper, green tests raise part of the castle, a commit finishes a house and a merge builds the castle

The strip on its own, as the mod draws it:

The Block Town strip: grass, dirt and stone the width of the terminal, houses, a farm with a sheep and a pig, chickens, trees and a finished castle

Both GIFs are drawn by the Arcade's own code from a scripted session (edits and reads with a subagent helping, a failing test, edits, passing tests, a commit, a merge); the window around the strip is a mock up of a terminal.

  • Every tool call lays blocks on the building going up (two, an edit or a write three), from the bottom row up, with scaffolding at its corners. The main agent's villager does it; each subagent sends a helper villager of its own colour, who goes home once that subagent is quiet.
  • Animals live in the town as it earns them: a sheep and a pig for every finished farm, a chicken for every house, a cow for every hall, as many as the band has room for. They wander in front of the town and graze on open grass between the buildings, run from a creeper, and lie down when the town sleeps. They come from the buildings, so nothing about them is saved.
  • A failed tool brings a creeper that walks up to a building, flashes and blows a hole in it (BOOM); the villagers build it back before starting anything new.
  • Moments: a small one plants a tree (trees grow as the work goes on, sapling to full tree; once the grove is full, they grow faster instead), a medium one finishes the building going up (HOUSE BUILT), a big one raises a third of the castle at the right end of the band (THE CASTLE GROWS), and a merge, release, deploy, streak or record raises the rest at once (CASTLE BUILT!, fireworks).
  • When the band is full the oldest building is torn down and built again, a house as a two storey hall.
  • The score sits at the right end of the strip: Village ▦ 309 ⌂ 2 ♣ 5 ♜ 1 ⚒ 27 (the town's size from camp, hamlet, village and town to city, blocks laid, houses, trees, castles, tool calls). Two minutes of quiet and the villagers go indoors.
  • One town per terminal: every terminal builds its own town, starting from an empty field, and it keeps growing while the town is not shown.
  • /town shows the score; /town build, tree, finish, castle and creeper are practice that counts nothing. /town reset starts over: it asks first, and only /town reset yes within a minute clears this terminal's town and its score.

Dragon Lair (dragon)

A small one colour pixel dragon that lives at the right end of the line above the prompt. It acts out what Claude is doing and breathes fire when something worth celebrating happens.

  • While Claude works the dragon shows it: it hops when you send a message, raises its head while Claude thinks, bends over the page while a file is read, paces while a file is edited, beats its wings for shell commands and takes off for web and MCP tools.
  • Each subagent hatches from an egg as a small dragon that flies beside it, flaps faster as the subagent works, and flies home when it finishes (or falls when it fails).
  • A failed tool drops its head; two minutes of quiet and it falls asleep.
  • Moments: a small one is a puff of smoke, a medium one a breath of fire, a big one a blaze, and a merge, release, deploy, streak or record a roar.
  • Gold builds up with every moment while the terminal is open. Under the dragon: Lv 3 ◆ 55 ★ 9 ⚒ 58 (level, gold, wins, tool calls).
  • /dragon shows the hoard; /dragon puff, fire, blaze and roar show off each size.

Jackpot (jackpot)

A pixel slot machine at the right end of the line above the prompt. Every finished turn pulls the lever; the moments worth celebrating earn golden spins with better odds.

  • Every finished turn pulls the lever once. Reels blur, stop one by one and bounce as they lock.
  • Medium moments queue one golden spin, big moments three: better odds, double pay, never a loss.
  • Five clean turns in a row (no tool error) raise the multiplier by one, up to ×5; a failed tool resets it.
  • Payouts: three 7s pay 100 chips, three dragons 50, diamonds 25, bells 15, stars 10, cherries 8; a cherry pair 3, any other pair 2. A jackpot strobes the cabinet and spills coins.
  • Under the machine: ◉ 2967 ×1 ▲ 2 ✦ 0 ♛ 1 (chips, multiplier, clean streak, golden spins waiting, jackpots).
  • /jackpot shows the rules and stats; /jackpot spin, golden and demo are practice spins that pay nothing.

Outlaw (outlaw)

A one colour Atari Outlaw duel at the right end of the line above the prompt. Your gunslinger fires at the moments worth celebrating, the bug fires back when a tool fails.

  • Medium moments are one shot for your gunslinger, big moments three. A failed tool is a shot for the bug.
  • A hit is aimed at eye level and clears the cactus; a miss is from the hip and takes a chunk out of the cactus, which grows back between duels.
  • Between duels the two pace, shift their weight and tip their hats, a tumbleweed rolls by and a vulture circles; while Claude thinks they stand with a hand on the gun.
  • Under the duel: YOU 7 : 3 BUGS ▲ 4 ★ 6 (score, your run of hits, your best run).
  • /outlaw shows the score and rules; /outlaw draw is a practice duel.

Tama (tama)

A classic Tamagotchi in a small LCD at the right end of the line above the prompt. It lives in real time while the terminal is open, and your work is what feeds it. A new terminal starts with a new egg.

  • It hatches from an egg after three finished turns, then grows from baby to child to teen to adult over real days. The adult it becomes depends on how it was raised: hard working, a rascal, or well fed.
  • Hunger drops every 20 minutes and joy every hour, in real time. Every finished turn is a meal.
  • Medium moments cheer it up a little, big moments a lot (hearts float up).
  • A failed tool leaves a mess; five clean turns in a row tidy one away. Three messes, or an empty stomach, and it falls ill.
  • Left hungry for twelve hours it packs its bags and leaves an egg behind. It never dies.
  • At night (23:00 to 07:00 local time) it sleeps.
  • Under the LCD: ♨ ▮▮▮▯ ♥ ▮▮▯▯ ✧ ▮▮▮▮ (food, joy, clean).
  • /tama says how it is doing; /tama feed, play and clean are hand care, a few times a day.

Tetris (tetris)

A classic falling-piece Tetris in a small handheld screen at the right end of the line above the prompt. Claude's tools drop the pieces; nobody knows what comes next.

  • Every tool Claude runs drops a piece; a simple placement AI picks where it lands. The next piece is never shown.
  • A full row clears, with the classic scoring (40, 100, 300 or 1200 for one to four rows, times the level). Every ten rows is a level.
  • A failed tool pushes up a garbage row with one gap in it.
  • Medium moments clear one row from the bottom, big moments three.
  • When the stack reaches the lid the game ends, the well empties and a new game starts. The best score stays until the terminal closes.
  • Under the screen: ▤ 35 ◆ 4250 Lv 3 (rows, score, level).
  • /tetris shows the score and rules; /tetris drop adds pieces, /tetris clear clears a row.

Moments

The Arcade spots the moments once and hands each one to every game, coding or not.

SizeMoments
SmallA finished turn, a file saved, every 10th tool call in a turn
MediumA commit, a push, a pull request opened, tests passing, any skill run, a subagent finished, a plan approved, an MCP tool that sends, creates, posts or publishes, a long document written, praise in your message
BigA merge, a release (gh release create, npm publish), a production deploy (vercel --prod, netlify deploy --prod, fly deploy and others), tests back to green after failing, a deliverable made (PDF, DOCX, XLSX, PPTX, images), a published page, a finished task list of three or more, a marathon turn (10 minutes, 30 tools, no errors), three subagents done in one turn, a 3, 7, 30 or 100 day streak, the 100th, 1,000th or 10,000th tool call

A commit that says "nothing to commit" or a push that says "Everything up-to-date" counts for nothing. Tool calls inside subagents do not count; their finishing does.

Tuning the moments

All optional, and none of it is asked at install. /arcade moments shows what is set; /arcade moments <key> <value> sets one and /arcade moments <key> none clears it. Kept per Claude Code config directory.

KeyWhat it is forExample
big_skillsSkills whose run is a big moment (every other skill is medium)/arcade moments big_skills release-notes, publish-report
quiet_skillsSkills that celebrate nothing/arcade moments quiet_skills commit
big_commandsA regular expression of shell commands whose success is big/arcade moments big_commands make ship
medium_commandsA regular expression of shell commands whose success is medium/arcade moments medium_commands terraform apply
praise_wordsExtra words that count as praise, on top of the built-in list (thanks, great, perfect and a few in other languages)/arcade moments praise_words nice one, cheers

Upgrading from 0.9.0 or earlier: those versions kept the game choice and these keys as plugin settings (pluginConfigs in settings.json). The Arcade no longer declares them, so set them again with the commands above.

Scores

Every game starts from zero in each terminal: the score, Block Town's town and Tama's pet belong to that terminal and last until it closes. Two terminals play two separate games. Nothing is saved between sessions; a reload of the pl

Source 3 files
hooks/arcade.jsx 5719 lines
1// Built by scripts/build.sh from src/ with esbuild@0.25.10. Do not edit: edit src/ and rebuild.
2// src/arcade.tsx
3import { atom as atom12, read as read12, update as update11 } from "claude-code";
4
5// src/games/dragon-lair.tsx
6import { atom as atom2, read as read2, update } from "claude-code";
7
8// src/games/dragon-sprite.ts
9const DRAGON_WIDTH = 26;
10const PIXEL_ROWS = 10;
11const BASE = 2;
12const BODY = {
13  x: 7,
14  y: 4,
15  frames: {
16    still: ["..#########", "############", "..##########"],
17    breathe: ["..#########", ".###########", "..##########"]
18  }
19};
20const WING = {
21  x: 6,
22  y: -2,
23  frames: {
24    up: ["#.......", "##......", "######..", ".#.#.##.", "..#.#.##", "...#####"],
25    mid: ["........", "........", "#.......", ".######.", "..#.#.##", "...#####"],
26    down: ["........", "........", "........", "........", ".######.", "#.#.#.##"]
27  }
28};
29const HEAD = {
30  x: 16,
31  y: 0,
32  frames: {
33    look: ["...#.#....", "..######..", ".##.######", ".##...###.", "##........"],
34    blink: ["...#.#....", "..######..", ".#########", ".##...###.", "##........"],
35    up: ["...#.#....", "..##.###..", ".#########", ".##...###.", "##........"],
36    open: ["...#.#....", "..######..", ".##.######", ".##.......", "##....###."],
37    droop: ["..........", "...#.#....", "..######..", ".##.######", "##....###."],
38    doze: ["..........", "...#.#....", "..######..", ".#########", "##....###."]
39  }
40};
41const TAIL = {
42  x: 0,
43  y: 3,
44  frames: {
45    low: ["#........", "##.......", ".##......", "..#####.."],
46    high: ["##.......", "#........", "##.......", ".######.."],
47    flat: [".........", ".........", "###......", "..#####.."]
48  }
49};
50const LEGS = {
51  x: 8,
52  y: 7,
53  frames: {
54    stand: ["##.##..##.##"],
55    stepA: ["#..##...#..##"],
56    stepB: ["##..#...##..#"],
57    tuck: ["............"]
58  }
59};
60const MOUTH = { x: 26, y: BASE + 2 };
61const NOSTRIL = { x: 25, y: BASE + 2 };
62const EYE = { x: 19, y: BASE + 2 };
63function draw(ink2, columns, pose2, dx = 0, dy = 0) {
64  const put5 = (part, frame10) => {
65    const rows = part.frames[frame10] ?? Object.values(part.frames)[0] ?? [];
66    rows.forEach((row, y) => {
67      for (let x = 0; x < row.length; x++) {
68        if (row[x] !== "#") continue;
69        const px = part.x + x + dx;
70        const py = BASE + part.y + y + dy;
71        if (px >= 0 && px < columns && py >= 0 && py < PIXEL_ROWS) ink2[py * columns + px] = 1;
72      }
73    });
74  };
75  put5(TAIL, pose2.tail);
76  put5(BODY, pose2.body);
77  put5(LEGS, pose2.legs);
78  put5(WING, pose2.wing);
79  put5(HEAD, pose2.head);
80}
81const BABY = {
82  up: [".#....", "#.#...", ".###.#", "..####", "..#..."],
83  down: ["......", "....#.", ".####.", "#.###.", "..#..."]
84};
85function drawBaby(ink2, columns, x, y, frame10) {
86  BABY[frame10].forEach((row, dy) => {
87    for (let dx = 0; dx < row.length; dx++) {
88      if (row[dx] !== "#") continue;
89      const px = Math.round(x) + dx;
90      const py = Math.round(y) + dy;
91      if (px >= 0 && px < columns && py >= 0 && py < PIXEL_ROWS) ink2[py * columns + px] = 1;
92    }
93  });
94}
95
96// src/cells.ts
97const DEFAULT = 16777216;
98const B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
99function words(cells) {
100  const clean = cells.replace(/=+$/, "");
101  const bytes = new Uint8Array(Math.floor(clean.length * 3 / 4));
102  let o = 0;
103  for (let i = 0; i < clean.length; i += 4) {
104    const n = B64.indexOf(clean[i]) << 18 | B64.indexOf(clean[i + 1] ?? "A") << 12 | B64.indexOf(clean[i + 2] ?? "A") << 6 | B64.indexOf(clean[i + 3] ?? "A");
105    if (o < bytes.length) bytes[o++] = n >> 16 & 255;
106    if (o < bytes.length) bytes[o++] = n >> 8 & 255;
107    if (o < bytes.length) bytes[o++] = n & 255;
108  }
109  return new Uint32Array(bytes.buffer, 0, Math.floor(bytes.length / 4));
110}
111const CELL_W = 6;
112const CELL_H = 12;
113const hex = (c) => `#${(c & 16777215).toString(16).padStart(6, "0")}`;
114const escape = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
115function framePaths(columns, rows, cells) {
116  const w = words(cells);
117  const half = CELL_H / 2;
118  const runs = /* @__PURE__ */ new Map();
119  const glyphs = [];
120  const rowsOfPixels = [];
121  for (let y = 0; y < rows; y++) {
122    const top = [];
123    const bottom = [];
124    for (let x = 0; x < columns; x++) {
125      const i = (y * columns + x) * 3;
126      const ch = w[i] ?? 32;
127      const fg = w[i + 1] ?? DEFAULT;
128      const bg = w[i + 2] ?? DEFAULT;
129      const back = bg === DEFAULT ? null : bg;
130      if (ch === 9608) {
131        top.push(fg);
132        bottom.push(fg);
133      } else if (ch === 9600) {
134        top.push(fg);
135        bottom.push(back);
136      } else if (ch === 9604) {
137        top.push(back);
138        bottom.push(fg);
139      } else {
140        top.push(back);
141        bottom.push(back);
142        if (ch !== 32) {
143          const ink2 = fg === DEFAULT ? 'class="d"' : `fill="${hex(fg)}"`;
144          glyphs.push(`<text x="${x * CELL_W + CELL_W / 2}" y="${y * CELL_H + CELL_H - 2}" ${ink2}>${escape(String.fromCodePoint(ch))}</text>`);
145        }
146      }
147    }
148    rowsOfPixels.push(top, bottom);
149  }
150  rowsOfPixels.forEach((row, py) => {
151    let x = 0;
152    while (x < row.length) {
153      const c = row[x];
154      let end = x + 1;
155      while (end < row.length && row[end] === c) end++;
156      if (c !== null && c !== void 0) {
157        const list2 = runs.get(c) ?? [];
158        list2.push(`M${x * CELL_W} ${py * half}h${(end - x) * CELL_W}v${half}h-${(end - x) * CELL_W}z`);
159        runs.set(c, list2);
160      }
161      x = end;
162    }
163  });
164  const paths = [...runs].map(([c, d]) => c === DEFAULT ? `<path class="d" d="${d.join("")}"/>` : `<path fill="${hex(c)}" d="${d.join("")}"/>`);
165  return paths.join("") + glyphs.join("");
166}
167const BUDGET = 12e4;
168const OVERSIZE = 2;
169function flipbook(columns, rows, pages) {
170  const W5 = columns * CELL_W;
171  const H3 = rows * CELL_H;
172  const head = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W5} ${H3}" width="${W5 * OVERSIZE}" height="${H3 * OVERSIZE}" shape-rendering="crispEdges"><style>.d{fill:#3d3d3a}@media (prefers-color-scheme:dark){.d{fill:#e8e6dc}}text{font:${CELL_H - 2}px ui-monospace,Menlo,monospace;text-anchor:middle}.p{visibility:hidden}@keyframes on{from,to{visibility:visible}}`;
173  let list2 = pages.length > 0 ? pages : [{ paths: "", ms: 66 }];
174  for (; ; ) {
175    const ids = /* @__PURE__ */ new Map();
176    for (const p of list2) if (!ids.has(p.paths)) ids.set(p.paths, ids.size);
177    let at = 0;
178    const css = list2.map((p, i) => {
179      const isLast = i === list2.length - 1;
180      const rule = `.f${i}{animation:on ${Math.round(p.ms)}ms step-end ${Math.round(at)}ms ${isLast ? "forwards" : "1"}}`;
181      at += p.ms;
182      return rule;
183    }).join("");
184    const defs = [...ids].map(([paths, id]) => `<g id="u${id}">${paths}</g>`).join("");
185    const body = list2.map((p, i) => `<use href="#u${ids.get(p.paths)}" class="p f${i}"/>`).join("");
186    const svg = `${head}${css}</style><defs>${defs}</defs>${body}</svg>`;
187    if (svg.length <= BUDGET || list2.length === 1) return svg;
188    const fewer = [];
189    list2.forEach((p, i) => {
190      if (i % 2 === 0 || i === list2.length - 1) fewer.push({ ...p });
191      else fewer[fewer.length - 1].ms += p.ms;
192    });
193    list2 = fewer;
194  }
195}
196
197// src/pixels.tsx
198const drawsGames = (surface) => surface === "terminal" || surface === "desktop";
199const sites = /* @__PURE__ */ new Map();
200const pending = /* @__PURE__ */ new Map();
201const BOOK_MS = 1e3;
202const FRAME_MS = 66;
203const onDesktop = () => [...sites.values()].includes("desktop");
204function startFlipbooks($) {
205  $.clock.every(BOOK_MS, () => {
206    const isNew = (f) => f.pages.length > 1 || f.pages.length === 1 && f.pages[0].paths !== f.shown;
207    if (onDesktop() && [...pending.values()].some(isNew)) $.ui.invalidate("ui.render");
208  });
209}
210function redrawDesktop($) {
211  if (onDesktop()) $.ui.invalidate("ui.render");
212}
213function pixels($, e, g) {
214  sites.set(e.requestId, e.surface);
215  if (e.surface === "terminal") {
216    const { Raster } = $.ui.resolve(e);
217    return <Raster key={g.key} columns={g.columns} rows={g.rows} cells={g.cells} />;
218  }
219  if (e.surface === "desktop") {
220    const { Svg } = $.ui.resolve(e);
221    const kept = pending.get(g.key);
222    const pages = kept && kept.size === g.cells.length && kept.pages.length > 0 ? kept.pages : [{ paths: framePaths(g.columns, g.rows, g.cells), ms: FRAME_MS }];
223    pending.set(g.key, { size: g.cells.length, columns: g.columns, rows: g.rows, pages: [], lastCells: "", shown: pages[pages.length - 1].paths });
224    const source = flipbook(g.columns, g.rows, pages);
225    return <Svg key={g.key} alt={g.alt} source={source} />;
226  }
227  return null;
228}
229function repaint($, args) {
230  if (sites.get(args.requestId) === "desktop") {
231    const kept = pending.get(args.key);
232    if (!kept || kept.size !== args.cells.length) return Promise.resolve({});
233    const last2 = kept.pages[kept.pages.length - 1];
234    if (last2 && args.cells === kept.lastCells) last2.ms += FRAME_MS;
235    else {
236      kept.pages.push({ paths: framePaths(kept.columns, kept.rows, args.cells), ms: FRAME_MS });
237      kept.lastCells = args.cells;
238    }
239    if (kept.pages.length > 45) kept.pages.splice(0, kept.pages.length - 45);
240    return Promise.resolve({});
241  }
242  return $.ui.blit(args);
243}
244
245// src/shown.ts
246import { atom, read } from "claude-code";
247const shown = atom({ plugin: "arcade", key: "shown" }, []);
248async function isShown($, id) {
249  return (await read($, shown)).includes(id);
250}
251
252// src/games/dragon-lair.tsx
253const ID = "dragon";
254const RASTER = "dragon";
255const ROWS = PIXEL_ROWS / 2;
256const COLUMNS = DRAGON_WIDTH + 9;
257const FPS_MS = 66;
258const INK = 16777216;
259const NONE = 16777216;
260const hoard = atom2({ plugin: "arcade", key: "dragonHoard" }, { gold: 0, meals: 0, feats: 0 });
261const mood = atom2({ plugin: "arcade", key: "dragonMood" }, "idle");
262const feat = atom2({ plugin: "arcade", key: "dragonFeat" }, "");
263async function notify($, text) {
264  if (!!await isShown($, ID)) $.ui.toast(text);
265}
266const SHOW_FRAMES = { puff: 20, breath: 32, blaze: 48, roar: 72 };
267function workOf(tool11) {
268  if (tool11 === "Read") return "read";
269  if (tool11 === "Grep" || tool11 === "Glob" || tool11 === "LSP") return "search";
270  if (tool11 === "Edit" || tool11 === "Write" || tool11 === "NotebookEdit") return "edit";
271  if (tool11 === "WebFetch" || tool11 === "WebSearch" || tool11.startsWith("mcp__")) return "web";
272  if (tool11 === "Agent" || tool11 === "Task") return "agent";
273  return "bash";
274}
275const SLOTS = [
276  { x: 28, y: 0 },
277  { x: 28, y: 5 },
278  { x: 0, y: 0 }
279];
280const HOME = { x: 18, y: 0 };
281const sim = {
282  t: 0,
283  lastActivity: 0,
284  isTurn: false,
285  working: [],
286  show: null,
287  sadUntil: -1,
288  alertUntil: -1,
289  levelUntil: -1,
290  level: 1,
291  particles: [],
292  dx: 0,
293  dy: 0,
294  requestId: null,
295  isBlitting: false,
296  mood: "idle",
297  babies: []
298};
299const rand = (a, b) => a + Math.random() * (b - a);
300const pick = (list2) => list2[Math.floor(Math.random() * list2.length)];
301const levelOf = (gold) => Math.floor(Math.sqrt(gold / 10)) + 1;
302const every = (n) => sim.t % n === 0;
303const cycle = (frames, n) => frames[Math.floor(sim.t / n) % frames.length];
304function activity() {
305  const { t } = sim;
306  if (sim.show && t < sim.show.until) return sim.show.kind;
307  if (t < sim.sadUntil) return "sad";
308  if (t < sim.alertUntil) return "alert";
309  const last2 = sim.working[sim.working.length - 1];
310  if (last2) return last2.work;
311  if (sim.isTurn) return "think";
312  if (t - sim.lastActivity > 120 * 1e3 / FPS_MS) return "sleep";
313  return "idle";
314}
315function moodOf(a) {
316  if (a === "puff" || a === "breath" || a === "blaze" || a === "roar") return "fire";
317  if (a === "sad" || a === "sleep" || a === "idle") return a;
318  return "work";
319}
320const statsLine = (stash) => `Lv ${levelOf(stash.gold)}  \u25C6 ${stash.gold}  \u2605 ${stash.feats}  \u2692 ${stash.meals}`;
321const centred = (text) => " ".repeat(Math.max(0, Math.floor((DRAGON_WIDTH - text.length) / 2))) + text;
322const showLeft = () => sim.show ? sim.show.until - sim.t : 0;
323function pose(a) {
324  const isBlink = sim.t % 55 < 2;
325  const fast = ["up", "mid", "down", "mid"];
326  switch (a) {
327    case "sleep":
328      return { body: cycle(["still", "breathe"], 20), wing: "down", head: "doze", tail: "flat", legs: "stand" };
329    case "sad":
330      return { body: "still", wing: "down", head: "droop", tail: "flat", legs: "stand" };
331    case "alert":
332      return { body: "still", wing: sim.alertUntil - sim.t > 8 ? "up" : "mid", head: "look", tail: "high", legs: lift(a) < 0 ? "tuck" : "stand" };
333    case "think":
334      return { body: cycle(["still", "breathe"], 12), wing: "down", head: isBlink ? "blink" : "up", tail: cycle(["low", "high"], 12), legs: "stand" };
335    case "read":
336      return { body: "still", wing: "down", head: isBlink ? "doze" : "droop", tail: "low", legs: "stand" };
337    case "search":
338      return { body: "still", wing: "mid", head: cycle(["look", "up"], 5), tail: cycle(["low", "high"], 5), legs: "stand" };
339    case "edit":
340      return { body: "still", wing: "down", head: "look", tail: cycle(["low", "high"], 3), legs: cycle(["stepA", "stand", "stepB", "stand"], 2) };
341    case "bash":
342      return { body: "still", wing: cycle(["up", "down"], 2), head: cycle(["look", "blink"], 6), tail: cycle(["low", "high"], 2), legs: "stand" };
343    case "web":
344      return { body: "still", wing: cycle(fast, 2), head: "look", tail: "flat", legs: "tuck" };
345    case "agent":
346      return { body: "still", wing: "mid", head: "droop", tail: "low", legs: "stand" };
347    case "idle": {
348      const isStretch = sim.t % 120 < 14;
349      return {
350        body: cycle(["still", "breathe"], 25),
351        wing: isStretch ? cycle(["mid", "up"], 7) : "down",
352        head: isBlink ? "blink" : "look",
353        tail: cycle(["low", "high"], 18),
354        legs: "stand"
355      };
356    }
357    default:
358      return {
359        body: "still",
360        wing: cycle(a === "puff" ? ["up", "mid"] : fast, a === "roar" ? 2 : 3),
361        head: a !== "puff" || showLeft() > 12 ? "open" : "look",
362        tail: "high",
363        legs: a === "roar" ? cycle(["stepA", "stepB"], 3) : "stand"
364      };
365  }
366}
367function lift(a) {
368  if (a === "alert") {
369    const left = sim.alertUntil - sim.t;
370    return left > 12 ? -1 : left > 6 ? -2 : left > 4 ? -1 : 0;
371  }
372  if (a === "web") return cycle([-2, -2, -1, -1], 2);
373  if (a === "roar") return cycle([0, -1], 3);
374  return 0;
375}
376function shift(a) {
377  if (a === "edit") return cycle([0, 1, 2, 1], 3);
378  if (a === "search") return cycle([0, 1], 6);
379  return 0;
380}
381const glyph = (x, y, ch, life, vx = 0, vy = 0) => sim.particles.push({ x, y, vx, vy, age: 0, life, ch });
382const pixel = (x, y, vx, vy, life, wave = 0) => sim.particles.push({ x, y, vx, vy, age: 0, life, wave });
383function flame(count, reach) {
384  for (let i = 0; i < count; i++) {
385    pixel(MOUTH.x + sim.dx, MOUTH.y + sim.dy + rand(0, 1.4), rand(0.8, 1.6), rand(-0.15, 0.25), Math.floor(rand(reach * 0.5, reach)), rand(0, 6));
386  }
387}
388function step(a) {
389  stepBabies();
390  sim.dx = shift(a);
391  sim.dy = lift(a);
392  const top = DRAGON_WIDTH + 1;
393  switch (a) {
394    case "puff":
395      if (showLeft() > 12) flame(1, 3);
396      if (every(6)) pixel(NOSTRIL.x, NOSTRIL.y - 1, rand(0.1, 0.3), -0.2, 8);
397      if (showLeft() === SHOW_FRAMES.puff - 1) glyph(top, 0, "\u2713", 18);
398      break;
399    case "breath":
400      flame(2, 7);
401      break;
402    case "blaze":
403      flame(3, 8);
404      if (every(3)) glyph(rand(top, COLUMNS), rand(0, PIXEL_ROWS), pick(["*", "+", "\u2726"]), 5);
405      break;
406    case "roar":
407      flame(4, 8);
408      if (every(2)) glyph(rand(0, COLUMNS), rand(0, PIXEL_ROWS), pick(["*", "+", "\u2726", "."]), 6);
409      if (every(8)) "ROAR".split("").forEach((ch, i) => glyph(top + i, 0, ch, 5));
410      break;
411    case "sad":
412      if (every(10)) pixel(EYE.x, EYE.y + 2, 0, 0.25, 8);
413      break;
414    case "think":
415      if (every(8)) {
416        const k = Math.floor(sim.t / 8) % 3;
417        glyph(14 + k * 2, 0, [".", "o", "O"][k], 8);
418      }
419      break;
420    case "read":
421      if (every(3)) glyph(top - 1, 8, cycle(["=", "-", "="], 3), 3);
422      break;
423    case "search":
424      if (every(12)) glyph(23 + sim.dx, 0, "?", 12);
425      break;
426    case "edit":
427      if (every(2)) pixel(rand(8, 20) + sim.dx, PIXEL_ROWS - 1, rand(-0.5, 0.5), -0.25, 3);
428      break;
429    case "bash":
430      if (every(9)) pixel(NOSTRIL.x, NOSTRIL.y - 1, 0.25, -0.2, 6);
431      break;
432    case "web":
433      if (every(2)) glyph(rand(0, 6), rand(0, PIXEL_ROWS), "~", 6, -0.5, 0);
434      break;
435    case "sleep":
436      if (every(24)) glyph(top - 3, 1, pick(["z", "Z"]), 30, 0.12, -0.04);
437      break;
438    case "idle":
439      if (every(140)) pixel(NOSTRIL.x + 1, NOSTRIL.y - 1, 0.2, -0.15, 7);
440      break;
441  }
442  if (sim.t < sim.levelUntil && every(6)) {
443    `LV${sim.level}`.split("").forEach((ch, i) => glyph(top + 3 + i, 1, ch, 6));
444    glyph(rand(top, COLUMNS), rand(0, PIXEL_ROWS), "\u2726", 4);
445  }
446  for (const p of sim.particles) {
447    p.x += p.vx;
448    p.y += p.vy + (p.wave ? Math.sin((sim.t + p.wave) / 1.5) * 0.25 : 0);
449    p.age += 1;
450  }
451  sim.particles = sim.particles.filter((p) => p.age < p.life && p.x >= 0 && p.x < COLUMNS && p.y >= 0 && p.y < PIXEL_ROWS);
452}
453function freeSlot() {
454  for (let i = 0; i < SLOTS.length; i++) {
455    if (!sim.babies.some((b) => b.slot === i && b.state !== "home" && b.state !== "fall")) return i;
456  }
457  return -1;
458}
459function hatch(key, description, type, id, isNew = true) {
460  if (sim.babies.some((b) => b.key === key || id !== void 0 && b.id === id)) return;
461  sim.babies.push({ key, id, description, type, state: isNew ? "egg" : "fly", since: sim.t, slot: freeSlot(), lastTool: -100, y: 0 });
462}
463function stepBabies() {
464  for (const b of sim.babies) {
465    const age2 = sim.t - b.since;
466    if (b.state === "egg" && age2 >= 20) {
467      b.state = "fly";
468      b.since = sim.t;
469      glyph(slotOf(b).x + 2, slotOf(b).y + 2, "\u2726", 4);
470    }
471    if (b.state === "fall") b.y += 0.6;
472  }
473  sim.babies = sim.babies.filter((b) => {
474    if (b.state === "home" && sim.t - b.since >= 14) {
475      glyph(HOME.x, HOME.y, "\u2726", 6);
476      return false;
477    }
478    return !(b.state === "fall" && b.y > PIXEL_ROWS);
479  });
480  for (const b of sim.babies) if (b.slot < 0 && b.state === "fly") b.slot = freeSlot();
481}
482const slotOf = (b) => SLOTS[b.slot] ?? SLOTS[0];
483function drawBabies(ink2, W5) {
484  let hidden = 0;
485  for (const b of sim.babies) {
486    if (b.slot < 0) {
487      hidden += 1;
488      continue;
489    }
490    const at = slotOf(b);
491    const age2 = sim.t - b.since;
492    if (b.state === "egg") {
493      const rock = age2 > 8 ? cycle([0, 1, 0, -1], 2) : 0;
494      const ex = at.x + 2 + rock;
495      const ey = at.y + 1;
496      [".#.", "###", "###"].forEach(
497        (row, dy) => [...row].forEach((c, dx) => {
498          if (c !== "#" || age2 > 15 && dx === 1 && dy === 1) return;
499          const x = ex + dx;
500          const y = ey + dy;
501          if (x >= 0 && x < W5 && y >= 0 && y < PIXEL_ROWS) ink2[y * W5 + x] = 1;
502        })
503      );
504      continue;
505    }
506    const isBusy = sim.t - b.lastTool < 15;
507    const frame10 = cycle(["up", "down"], isBusy ? 2 : 4);
508    if (b.state === "home") {
509      const k = Math.min(1, age2 / 14);
510      drawBaby(ink2, W5, at.x + (HOME.x - at.x) * k, at.y + (HOME.y - at.y) * k, frame10);
511      continue;
512    }
513    if (b.state === "fall") {
514      drawBaby(ink2, W5, at.x, at.y + b.y, "down");
515      continue;
516    }
517    const bob = cycle(at.y === 0 ? [0, 0, 1, 1] : [0, 0, -1, -1], isBusy ? 2 : 5);
518    drawBaby(ink2, W5, at.x, at.y + bob, frame10);
519  }
520  if (hidden > 0) glyph(W5 - 2, 8, `+${Math.min(9, hidden)}`.slice(-1), 2);
521}
522function frame(a) {
523  const W5 = COLUMNS;
524  const ink2 = new Uint8Array(W5 * PIXEL_ROWS);
525  const over = /* @__PURE__ */ new Map();
526  draw(ink2, W5, pose(a), shift(a), lift(a));
527  drawBabies(ink2, W5);
528  for (const p of sim.particles) {
529    const x = Math.round(p.x);
530    const y = Math.round(p.y);
531    if (x < 0 || x >= W5 || y < 0 || y >= PIXEL_ROWS) continue;
532    if (p.ch) {
533      over.set(Math.floor(y / 2) * W5 + x, p.ch);
534      continue;
535    }
536    if (p.age / p.life > 0.7 && (x + sim.t) % 2 === 0) continue;
537    ink2[y * W5 + x] = 1;
538  }
539  const words2 = new Uint32Array(W5 * ROWS * 3);
540  for (let cy = 0; cy < ROWS; cy++) {
541    for (let cx = 0; cx < W5; cx++) {
542      const i = (cy * W5 + cx) * 3;
543      const top = ink2[cy * 2 * W5 + cx] === 1;
544      const bottom = ink2[(cy * 2 + 1) * W5 + cx] === 1;
545      const ch = over.get(cy * W5 + cx);
546      words2[i] = ch ? ch.codePointAt(0) : top && bottom ? 9608 : top ? 9600 : bottom ? 9604 : 32;
547      words2[i + 1] = INK;
548      words2[i + 2] = NONE;
549    }
550  }
551  return base64(new Uint8Array(words2.buffer));
552}
553const B642 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
554function base64(bytes) {
555  let out = "";
556  let i = 0;
557  for (; i + 2 < bytes.length; i += 3) {
558    const n = bytes[i] << 16 | bytes[i + 1] << 8 | bytes[i + 2];
559    out += B642[n >> 18 & 63] + B642[n >> 12 & 63] + B642[n >> 6 & 63] + B642[n & 63];
560  }
561  const rest = bytes.length - i;
562  if (rest === 1) {
563    const n = bytes[i] << 16;
564    out += B642[n >> 18 & 63] + B642[n >> 12 & 63] + "==";
565  } else if (rest === 2) {
566    const n = bytes[i] << 16 | bytes[i + 1] << 8;
567    out += B642[n >> 18 & 63] + B642[n >> 12 & 63] + B642[n >> 6 & 63] + "=";
568  }
569  return out;
570}
571async function celebrate($, label, gold, show, isQuiet = false) {
572  sim.show = { kind: show, until: sim.t + SHOW_FRAMES[show] };
573  sim.lastActivity = sim.t;
574  const before = levelOf((await read2($, hoard)).gold);
575  const next = await update($, hoard, (old) => ({ ...old, gold: old.gold + gold, feats: old.feats + 1 }));
576  const after = levelOf(next.gold);
577  await update($, feat, () => `${label}: +${gold} gold`);
578  if (after > before) {
579    sim.level = after;
580    sim.levelUntil = sim.show.until + 45;
581    void notify($, `\u{1F525} ${label}! +${gold} gold. The dragon grows to level ${after}!`);
582  } else if (!isQuiet) {
583    void notify($, `\u{1F525} ${label}! The dragon hoards +${gold} gold`);
584  }
585}
586const ROARS = /* @__PURE__ */ new Set(["merge", "release", "deploy", "streak", "record", "squad"]);
587async function onMilestone($, tier, kind, label) {
588  if (tier === "small") await celebrate($, label, 1, "puff", true);
589  else if (tier === "medium") await celebrate($, label, 5, "breath");
590  else if (ROARS.has(kind)) await celebrate($, label, 50, "roar");
591  else await celebrate($, label, 25, "blaze");
592}
593async function celebrateMoments($, found) {
594  for (const m of found) await onMilestone($, m.tier, m.kind, m.label);
595}
596const start = async ($, e, next) => {
597  await $.command.register({
598    name: "dragon",
599    description: 'The dragon above the prompt: its hoard. "/dragon puff|fire|blaze|roar" to show off.'
600  });
601  $.clock.every(FPS_MS, () => {
602    sim.t += 1;
603    const a = activity();
604    const m = moodOf(a);
605    if (m !== sim.mood) {
606      sim.mood = m;
607      void update($, mood, () => m);
608    }
609    const requestId = sim.requestId;
610    if (requestId === null) return;
611    step(a);
612    if (sim.isBlitting) return;
613    sim.isBlitting = true;
614    void repaint($, { requestId, key: RASTER, cells: frame(a) }).then((r) => {
615      if (r.deny !== void 0) sim.requestId = null;
616    }).finally(() => {
617      sim.isBlitting = false;
618    });
619  });
620  $.clock.every(1e3, () => {
621    void $.agent.list().then(
622      async (agents) => {
623        for (const b of sim.babies) {
624          if (b.id === void 0) {
625            const match = agents.find(
626              (a) => a.description === b.description && a.type === b.type && !sim.babies.some((o) => o.id === a.id)
627            );
628            if (match) b.id = match.id;
629          }
630        }
631        for (const a of agents) {
632          const isLive = a.status === "pending" || a.status === "running" || a.status === "waiting";
633          if (isLive && !sim.babies.some((b) => b.id === a.id)) hatch(`agent:${a.id}`, a.description, a.type, a.id);
634        }
635        for (const b of sim.babies) {
636          if (b.state !== "egg" && b.state !== "fly") continue;
637          const a = agents.find((x) => x.id === b.id);
638          const isGone = a === void 0 && sim.t - b.since > 30 * 1e3 / FPS_MS;
639          if (a?.status === "completed" || a?.status === "idle" || isGone) {
640            b.state = "home";
641            b.since = sim.t;
642            const fed = await update($, hoard, (old) => ({ ...old, gold: old.gold + 2 }));
643          } else if (a?.status === "failed" || a?.status === "killed") {
644            b.state = "fall";
645            b.since = sim.t;
646            b.y = 0;
647            sim.sadUntil = sim.t + 15;
648          }
649        }
650      },
651      () => void 0
652    );
653  });
654  return next(e);
655};
656const command = async ($, e) => {
657  const arg = (e.args ?? "").trim();
658  const practice = { puff: "puff", fire: "breath", blaze: "blaze", roar: "roar" };
659  const show = practice[arg];
660  if (show) {
661    await celebrate($, "Practice", 1, show);
662    return { text: "The dragon breathes fire." };
663  }
664  const last2 = await read2($, feat);
665  return { text: `${statsLine(await read2($, hoard))}${last2 ? `
666Last win: ${last2}` : ""}` };
667};
668const prompt = async ($, e, next) => {
669  sim.isTurn = true;
670  sim.alertUntil = sim.t + 15;
671  sim.lastActivity = sim.t;
672  const ran = await next(e);
673  return ran;
674};
675const turn = async ($, e, next) => {
676  sim.isTurn = false;
677  sim.lastActivity = sim.t;
678  const ran = await next(e);
679  return ran;
680};
681const tool = async ($, e, next) => {
682  if (e.agentId !== void 0) {
683    const baby = sim.babies.find((b) => b.id === e.agentId);
684    if (baby) baby.lastTool = sim.t;
685    return next(e);
686  }
687  const job = { id: e.tool_use_id, work: workOf(String(e.tool)) };
688  sim.working.push(job);
689  sim.lastActivity = sim.t;
690  const ran = await next(e).finally(() => {
691    sim.working = sim.working.filter((w) => w !== job);
692    sim.lastActivity = sim.t;
693  });
694  if (ran.deny !== void 0) return ran;
695  const snack = await update($, hoard, (old) => ({ ...old, meals: old.meals + 1 }));
696  if (ran.isError === true) {
697    sim.sadUntil = sim.t + 30;
698    return ran;
699  }
700  return ran;
701};
702const render = async ($, e, next) => {
703  const below = await next(e);
704  if (!drawsGames(e.surface) || e.props.hasSurvey || !await isShown($, ID)) {
705    sim.requestId = null;
706    return below;
707  }
708  const { Box, Text } = $.ui.resolve(e);
709  sim.requestId = e.requestId;
710  const stash = await read2($, hoard);
711  sim.level = levelOf(stash.gold);
712  return <Box flexDirection="row" alignItems="flex-end">
713      <Box flexGrow={1} flexDirection="column">
714        {below ?? null}
715      </Box>
716      <Box flexDirection="column" flexShrink={0} minWidth={COLUMNS}>
717        {pixels($, e, { key: RASTER, columns: COLUMNS, rows: ROWS, cells: frame(activity()), alt: "Dragon Lair" })}
718        <Text key="stats" dimColor wrap="truncate">
719          {centred(statsLine(stash))}
720        </Text>
721      </Box>
722    </Box>;
723};
724async function reset($) {
725  await update($, hoard, () => hoard.initial);
726  await update($, feat, () => "");
727  sim.level = 1;
728}
729const game = { id: ID, title: "Dragon Lair" };
730
731// src/games/duck-hunt.tsx
732import { read as read3, update as update2, atom as atom3 } from "claude-code";
733const ID2 = "duck";
734const RASTER2 = "marsh";
735const ROWS2 = 8;
736const PH = ROWS2 * 2;
737const FPS_MS2 = 66;
738const MIN_COLUMNS = 24;
739const MAX_COLUMNS = 512;
740const SLEEP_AFTER = 2 * 60 * 1e3 / FPS_MS2;
741const INK2 = 16777216;
742const NONE2 = 16777216;
743const EMPTY = 4294967295;
744const GRASS = 4170573;
745const GRASS_DARK = 2849335;
746const TREE = 2849335;
747const TRUNK = 9132587;
748const DOG = 13141834;
749const DOG_DARK = 8014372;
750const DUCK = 9132587;
751const DUCK_HEAD = 3050327;
752const BEAK = 16756736;
753const SHOT = 14692657;
754const GREY = 9079434;
755const FEATHER = [16777215, 14272416, 9132587];
756const GROUND = PH - 3;
757const SKY_BOTTOM = GROUND - 4;
758const score = atom3({ plugin: "arcade", key: "duckScore" }, { hits: 0, escaped: 0, tools: 0 });
759const feat2 = atom3({ plugin: "arcade", key: "duckFeat" }, "");
760async function notify2($, text) {
761  if (await isShown($, ID2)) $.ui.toast(text);
762}
763const DUCK_UP = [".##.....", "..##..##", ".#######", "..####.."];
764const DUCK_DOWN = ["......##", ".#######", "..####..", "..##...."];
765const DUCK_HEAD_PIXELS = [[6, 0], [7, 0], [6, 1]];
766const DUCK_FALL = ["..#..#..", "..####..", ".######.", "..#..#.."];
767const DUCK_HIT = [".#....#.", ".######.", "..####..", "..#..#.."];
768const DOG_WALK = [
769  ["......##.", ".....####", "#...####.", "#######..", ".######..", ".#.#..#.#"],
770  ["......##.", ".....####", "#...####.", "#######..", ".######..", "#..#.#..#"]
771];
772const DOG_UP = ["..#####..", ".##.#.##.", ".#######.", "..#...#..", "..#####..", "...###..."];
773const DOG_LAUGH = ["..#####..", ".##.#.##.", ".#######.", "..#.#.#..", "..#####..", "...###..."];
774const DOG_SLEEP = [".........", ".........", ".........", "....##...", "#.######.", "########."];
775const SHOW_FRAMES2 = { shot: 18, hunt: 110, double: 140, perfect: 170 };
776const sim2 = {
777  t: 0,
778  W: 0,
779  requestId: null,
780  isBlitting: false,
781  isTurn: false,
782  working: 0,
783  lastActivity: 0,
784  show: null,
785  ducks: [],
786  particles: [],
787  banner: null,
788  dogX: 4,
789  dogFace: 1,
790  // The dog behind the grass, holding up what fell: 0 nothing, 1 or 2 ducks, -1 laughing.
791  catch: null,
792  laughUntil: -1,
793  crosshair: null,
794  nextDuck: 60,
795  gain: { hits: 0, escaped: 0 },
796  stats: "",
797  tree: 0,
798  round: 1
799};
800const rand2 = (a, b) => a + Math.random() * (b - a);
801const pick2 = (list2) => list2[Math.floor(Math.random() * list2.length)];
802const clamp = (v, a, b) => Math.max(a, Math.min(b, v));
803const roundOf = (hits) => Math.floor(hits / 10) + 1;
804function fit(W5) {
805  if (W5 === sim2.W) return;
806  sim2.W = W5;
807  sim2.tree = Math.max(2, Math.floor(W5 * 0.72));
808  sim2.dogX = clamp(sim2.dogX, 0, W5 - 10);
809  sim2.ducks = sim2.ducks.filter((d) => d.x < W5);
810}
811function banner(text, color, frames) {
812  sim2.banner = { text, color, until: sim2.t + frames };
813}
814const glyph2 = (x, y, ch, life, color) => sim2.particles.push({ x, y, vx: 0, vy: 0, age: 0, life, color, ch });
815function feathers(x, y) {
816  for (let i = 0; i < 6; i++) {
817    sim2.particles.push({ x, y, vx: rand2(-0.6, 0.6), vy: rand2(-0.6, 0.1), age: 0, life: Math.floor(rand2(10, 22)), color: pick2(FEATHER), gravity: 0.04 });
818  }
819}
820function launch(isGame) {
821  const x = clamp(Math.floor(rand2(4, sim2.W - 12)), 0, Math.max(0, sim2.W - 9));
822  const duck = { x, y: SKY_BOTTOM, vx: pick2([-1, 1]) * rand2(0.5, 0.9), vy: -rand2(0.25, 0.45), state: "fly", since: sim2.t, isGame };
823  sim2.ducks.push(duck);
824  return duck;
825}
826function target() {
827  return sim2.ducks.find((d) => d.state === "fly") ?? launch(true);
828}
829function shoot(duck, counts = true) {
830  if (counts) duck.isGame = true;
831  duck.state = "hit";
832  duck.since = sim2.t;
833  sim2.crosshair = { x: Math.round(duck.x + 3), y: Math.round(duck.y + 1), until: sim2.t + 10 };
834  feathers(duck.x + 4, duck.y + 1);
835}
836function stepDucks() {
837  for (const d of sim2.ducks) {
838    const age2 = sim2.t - d.since;
839    if (d.state === "fly") {
840      d.x += d.vx;
841      d.y += d.vy;
842      if (d.x < 0 || d.x > sim2.W - 9) d.vx = -d.vx;
843      if (d.y < 0 || d.y > SKY_BOTTOM) d.vy = -d.vy;
844      if (Math.random() < 0.02) d.vy = -d.vy;
845      if (age2 > 260) d.state = "away";
846    } else if (d.state === "hit" && age2 > 8) {
847      d.state = "fall";
848      d.since = sim2.t;
849    } else if (d.state === "fall") {
850      d.y += 0.7;
851      if (d.y >= GROUND) {
852        d.y = PH;
853        const caught = sim2.catch && sim2.t - sim2.catch.since < 10 ? sim2.catch.ducks + 1 : 1;
854        sim2.catch = { ducks: Math.min(2, caught), x: clamp(Math.round(d.x), 0, sim2.W - 9), since: sim2.t };
855        if (d.isGame) sim2.gain.hits += 1;
856      }
857    } else if (d.state === "away") {
858      d.y -= 0.8;
859      d.x += d.vx;
860    }
861  }
862  sim2.ducks = sim2.ducks.filter((d) => d.y > -5 && d.y < PH && d.x > -9 && d.x < sim2.W + 1);
863}
864function flyAway(isPractice) {
865  const duck = sim2.ducks.find((d) => d.state === "fly");
866  if (duck) {
867    duck.state = "away";
868    duck.since = sim2.t;
869    if (!isPractice) sim2.gain.escaped += 1;
870    banner("FLY AWAY", GREY, 30);
871  }
872  sim2.laughUntil = sim2.t + 40;
873}
874function step2() {
875  sim2.t += 1;
876  const show = sim2.show && sim2.t < sim2.show.until ? sim2.show : null;
877  const age2 = show ? SHOW_FRAMES2[show.kind] - (show.until - sim2.t) : 0;
878  if (show) {
879    if (show.kind === "shot" && age2 === 1) {
880      const duck = sim2.ducks.find((d) => d.state === "fly");
881      if (duck) shoot(duck, false);
882      else {
883        const x = Math.floor(rand2(4, sim2.W - 8));
884        sim2.crosshair = { x, y: Math.floor(rand2(2, SKY_BOTTOM)), until: sim2.t + 6 };
885        glyph2(x, Math.floor(rand2(0, 4)), "*", 6, SHOT);
886      }
887    }
888    if (show.kind === "hunt" && age2 === 1) target();
889    if (show.kind === "hunt" && age2 === 25) shoot(target());
890    if ((show.kind === "double" || show.kind === "perfect") && age2 === 1) {
891      launch(true);
892      launch(true);
893    }
894    if ((show.kind === "double" || show.kind === "perfect") && (age2 === 25 || age2 === 35)) shoot(target());
895    if (show.kind === "double" && age2 === 40) banner("DOUBLE!", SHOT, 50);
896    if (show.kind === "perfect" && age2 === 40) banner("PERFECT!", BEAK, 70);
897    if (show.kind === "perfect" && age2 > 40 && age2 % 6 === 0) feathers(rand2(2, sim2.W - 2), rand2(0, 6));
898  }
899  const isAsleep = !sim2.isTurn && sim2.working === 0 && sim2.t - sim2.lastActivity > SLEEP_AFTER;
900  if (!isAsleep && !sim2.catch && sim2.laughUntil < sim2.t) {
901    const speed2 = sim2.working > 0 ? 0.5 : sim2.isTurn ? 0.3 : 0.1;
902    sim2.dogX += sim2.dogFace * speed2;
903    if (sim2.dogX < 0 || sim2.dogX > sim2.W - 10) sim2.dogFace = -sim2.dogFace;
904  }
905  if ((sim2.isTurn || sim2.working > 0) && !show && sim2.t >= sim2.nextDuck && !sim2.ducks.some((d) => d.state === "fly")) {
906    launch(false);
907    sim2.nextDuck = sim2.t + Math.floor(rand2(90, 200));
908  }
909  stepDucks();
910  if (sim2.catch && sim2.t - sim2.catch.since > 45) sim2.catch = null;
911  for (const p of sim2.particles) {
912    p.age += 1;
913    p.x += p.vx;
914    p.y += p.vy;
915    p.vy += p.gravity ?? 0;
916  }
917  sim2.particles = sim2.particles.filter((p) => p.age < p.life && p.x >= 0 && p.x < sim2.W && p.y >= 0 && p.y < PH);
918  return isAsleep;
919}
920function put(buf, x, y, color) {
921  x = Math.round(x);
922  y = Math.round(y);
923  if (x < 0 || x >= sim2.W || y < 0 || y >= PH) return;
924  buf[y * sim2.W + x] = color;
925}
926function mask(buf, rows, x, y, color, isFlipped = false) {
927  rows.forEach((row, dy) => {
928    const w = row.length;
929    for (let dx = 0; dx < w; dx++) {
930      if (row[isFlipped ? w - 1 - dx : dx] === "#") put(buf, x + dx, y + dy, color);
931    }
932  });
933}
934function drawDuck(buf, d) {
935  const isLeft = d.vx < 0;
936  if (d.state === "hit") return mask(buf, DUCK_HIT, d.x, d.y, DUCK, isLeft);
937  if (d.state === "fall") return mask(buf, DUCK_FALL, d.x, d.y, DUCK, isLeft);
938  const isUp = Math.floor(sim2.t / 4) % 2 === 0;
939  mask(buf, isUp ? DUCK_UP : DUCK_DOWN, d.x, d.y, DUCK, isLeft);
940  for (const [hx, hy] of DUCK_HEAD_PIXELS) put(buf, isLeft ? d.x + 7 - hx : d.x + hx, d.y + hy, DUCK_HEAD);
941  put(buf, isLeft ? d.x - 1 : d.x + 8, d.y + (isUp ? 1 : 0), BEAK);
942}
943function drawScene(buf) {
944  const tx = sim2.tree;
945  for (let y = GROUND - 7; y < GROUND; y++) {
946    const half = y < GROUND - 4 ? 3 - Math.abs(GROUND - 6 - y) : 0;
947    for (let dx = -half; dx <= half; dx++) put(buf, tx + dx, y, TREE);
948  }
949  for (let y = GROUND - 4; y < GROUND; y++) put(buf, tx, y, TRUNK);
950  for (let x = 0; x < sim2.W; x++) {
951    for (let y = GROUND; y < PH; y++) put(buf, x, y, GRASS);
952    if (x * 7 % 5 < 2) put(buf, x, GROUND - 1, GRASS_DARK);
953  }
954}
955function drawDog(buf, isAsleep) {
956  if (sim2.catch) {
957    const rise = Math.min(7, Math.floor((sim2.t - sim2.catch.since) / 2));
958    const y2 = PH - 1 - rise;
959    mask(buf, DOG_UP, sim2.catch.x, y2, DOG);
960    for (let i = 0; i < sim2.catch.ducks; i++) mask(buf, DUCK_FALL, sim2.catch.x + (i === 0 ? -3 : 5), y2 - 3, DUCK);
961    return;
962  }
963  if (sim2.laughUntil > sim2.t) {
964    const bob = Math.floor(sim2.t / 3) % 2;
965    mask(buf, DOG_LAUGH, sim2.dogX, PH - 8 + bob, DOG);
966    return;
967  }
968  const y = GROUND - 5;
969  if (isAsleep) {
970    mask(buf, DOG_SLEEP, sim2.dogX, y, DOG);
971    return;
972  }
973  const legs = DOG_WALK[Math.floor(sim2.t / 4) % 2];
974  mask(buf, legs, sim2.dogX, y, DOG, sim2.dogFace < 0);
975  put(buf, sim2.dogFace < 0 ? sim2.dogX + 2 : sim2.dogX + 6, y, DOG_DARK);
976}
977const statsLine2 = (s) => `R ${roundOf(s.hits)}  \u25BC ${s.hits}  \u2197 ${s.escaped}  \u2692 ${s.tools}`;
978function frame2(isAsleep, stats) {
979  const W5 = sim2.W;
980  const buf = new Uint32Array(W5 * PH).fill(EMPTY);
981  const over = /* @__PURE__ */ new Map();
982  const text = (x, row, s, color) => [...s].forEach((ch, i) => {
983    if (x + i >= 0 && x + i < W5) over.set(row * W5 + x + i, { ch, color });
984  });
985  for (const d of sim2.ducks) drawDuck(buf, d);
986  const isBehind = sim2.catch !== null || sim2.laughUntil > sim2.t;
987  if (isBehind) drawDog(buf, isAsleep);
988  drawScene(buf);
989  if (!isBehind) drawDog(buf, isAsleep);
990  if (sim2.crosshair && sim2.t < sim2.crosshair.until) {
991    const { x, y } = sim2.crosshair;
992    for (const [dx, dy] of [[-2, 0], [2, 0], [0, -2], [0, 2], [-1, 0], [1, 0], [0, -1], [0, 1]]) put(buf, x + dx, y + dy, SHOT);
993  }
994  if (isAsleep) text(Math.round(sim2.dogX) + 9, Math.floor((GROUND - 4) / 2), "z", GREY);
995  for (const p of sim2.particles) {
996    if (p.ch) text(Math.round(p.x), Math.floor(Math.round(p.y) / 2), p.ch, p.color);
997    else put(buf, p.x, p.y, p.color);
998  }
999  text(W5 - stats.length - 1, 0, stats, GREY);
1000  if (sim2.banner && sim2.t < sim2.banner.until && (sim2.banner.until - sim2.t) % 8 > 1) {
1001    text(Math.floor((W5 - sim2.banner.text.length) / 2), 1, sim2.banner.text, sim2.banner.color);
1002  }
1003  const words2 = new Uint32Array(W5 * ROWS2 * 3);
1004  for (let cy = 0; cy < ROWS2; cy++) {
1005    for (let cx = 0; cx < W5; cx++) {
1006      const i = (cy * W5 + cx) * 3;
1007      const top = buf[cy * 2 * W5 + cx];
1008      const bottom = buf[(cy * 2 + 1) * W5 + cx];
1009      const g = over.get(cy * W5 + cx);
1010      if (g) {
1011        words2[i] = g.ch.codePointAt(0);
1012        words2[i + 1] = g.color;
1013        words2[i + 2] = NONE2;
1014      } else if (top === EMPTY && bottom === EMPTY) {
1015        words2[i] = 32;
1016        words2[i + 1] = INK2;
1017        words2[i + 2] = NONE2;
1018      } else if (top === bottom) {
1019        words2[i] = 9608;
1020        words2[i + 1] = top;
1021        words2[i + 2] = NONE2;
1022      } else if (bottom === EMPTY) {
1023        words2[i] = 9600;
1024        words2[i + 1] = top;
1025        words2[i + 2] = NONE2;
1026      } else if (top === EMPTY) {
1027        words2[i] = 9604;
1028        words2[i + 1] = bottom;
1029        words2[i + 2] = NONE2;
1030      } else {
1031        words2[i] = 9600;
1032        words2[i + 1] = top;
1033        words2[i + 2] = bottom;
1034      }
1035    }
1036  }
1037  return base642(new Uint8Array(words2.buffer));
1038}
1039const B643 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1040function base642(bytes) {
1041  let out = "";
1042  let i = 0;
1043  for (; i + 2 < bytes.length; i += 3) {
1044    const n = bytes[i] << 16 | bytes[i + 1] << 8 | bytes[i + 2];
1045    out += B643[n >> 18 & 63] + B643[n >> 12 & 63] + B643[n >> 6 & 63] + B643[n & 63];
1046  }
1047  const rest = bytes.length - i;
1048  if (rest === 1) {
1049    const n = bytes[i] << 16;
1050    out += B643[n >> 18 & 63] + B643[n >> 12 & 63] + "==";
1051  } else if (rest === 2) {
1052    const n = bytes[i] << 16 | bytes[i + 1] << 8;
1053    out += B643[n >> 18 & 63] + B643[n >> 12 & 63] + B643[n >> 6 & 63] + "=";
1054  }
1055  return out;
1056}
1057async function save($, change2) {
1058  const next = await update2($, score, change2);
1059  sim2.stats = statsLine2(next);
1060  return next;
1061}
1062const RANK = { shot: 0, hunt: 1, double: 2, perfect: 3 };
1063async function celebrate2($, label, show, isQuiet = false) {
1064  const running = sim2.show && sim2.t < sim2.show.until ? sim2.show.kind : null;
1065  if (running === null || RANK[show] >= RANK[running]) sim2.show = { kind: show, until: sim2.t + SHOW_FRAMES2[show] };
1066  sim2.lastActivity = sim2.t;
1067  const what = { shot: "a shot", hunt: "a duck down", double: "a double", perfect: "a perfect round" };
1068  await update2($, feat2, () => `${label}: ${what[show]}`);
1069  if (!isQuiet) {
1070    const say2 = {
1071      shot: "Bang",
1072      hunt: "Got one",
1073      double: "Two in one round",
1074      perfect: "Perfect"
1075    };
1076    void notify2($, `\u{1F986} ${label}! ${say2[show]}!`);
1077  }
1078}
1079const PERFECT = /* @__PURE__ */ new Set(["merge", "release", "deploy", "streak", "record", "squad"]);
1080async function onMilestone2($, tier, kind, label) {
1081  if (tier === "small") await celebrate2($, label, "shot", true);
1082  else if (tier === "medium") await celebrate2($, label, "hunt");
1083  else if (PERFECT.has(kind)) await celebrate2($, label, "perfect");
1084  else await celebrate2($, label, "double");
1085}
1086async function celebrateMoments2($, found) {
1087  for (const m of found) await onMilestone2($, m.tier, m.kind, m.label);
1088}
1089const start2 = async ($, e, next) => {
1090  const s = await read3($, score);
1091  sim2.stats = statsLine2(s);
1092  sim2.round = roundOf(s.hits);
1093  await $.command.register({
1094    name: "duck",
1095    description: 'The duck hunt above the prompt: the score. "/duck shot|hunt|double|perfect|flyaway" to show off.'
1096  });
1097  $.clock.every(FPS_MS2, () => {
1098    const requestId = sim2.requestId;
1099    if (sim2.gain.hits > 0 || sim2.gain.escaped > 0) {
1100      const gain = sim2.gain;
1101      sim2.gain = { hits: 0, escaped: 0 };
1102      void save($, (old) => ({ ...old, hits: old.hits + gain.hits, escaped: old.escaped + gain.escaped })).then((s2) => {
1103        const round = roundOf(s2.hits);
1104        if (round > sim2.round) {
1105          sim2.round = round;
1106          banner(`ROUND ${round}`, BEAK, 60);
1107          void notify2($, `\u{1F986} Round ${round}: ${s2.hits} ducks down.`);
1108        }
1109      });
1110    }
1111    if (requestId === null || sim2.W === 0) return;
1112    const isAsleep = step2();
1113    if (sim2.isBlitting) return;
1114    sim2.isBlitting = true;
1115    void repaint($, { requestId, key: RASTER2, cells: frame2(isAsleep, sim2.stats), columns: sim2.W }).then((r) => {
1116      if (r.deny !== void 0) sim2.requestId = null;
1117    }).finally(() => {
1118      sim2.isBlitting = false;
1119    });
1120  });
1121  return next(e);
1122};
1123const command2 = async ($, e) => {
1124  const arg = (e.args ?? "").trim();
1125  const practice = { shot: "shot", hunt: "hunt", double: "double", perfect: "perfect" };
1126  const show = practice[arg];
1127  if (show) {
1128    await celebrate2($, "Practice", show, true);
1129    return { text: "Practice: nothing counts." };
1130  }
1131  if (arg === "flyaway") {
1132    flyAway(true);
1133    return { text: "The duck gets away, and the dog laughs." };
1134  }
1135  const last2 = await read3($, feat2);
1136  return {
1137    text: `${statsLine2(await read3($, score))}${last2 ? `
1138Last win: ${last2}` : ""}
1139A medium moment (a commit, a skill, a sent message) shoots a duck down, a big one (a merge, a deploy, a finished task list) shoots two; a failed tool lets one get away. R is the round (ten ducks each), \u25BC ducks down, \u2197 ducks that got away, \u2692 tool calls.`
1140  };
1141};
1142const prompt2 = async ($, e, next) => {
1143  sim2.isTurn = true;
1144  sim2.lastActivity = sim2.t;
1145  return next(e);
1146};
1147const turn2 = async ($, e, next) => {
1148  if (e.agentId === void 0) sim2.isTurn = false;
1149  sim2.lastActivity = sim2.t;
1150  return next(e);
1151};
1152const tool2 = async ($, e, next) => {
1153  if (e.agentId !== void 0) return next(e);
1154  sim2.working += 1;
1155  sim2.lastActivity = sim2.t;
1156  const ran = await next(e).finally(() => {
1157    sim2.working = Math.max(0, sim2.working - 1);
1158    sim2.lastActivity = sim2.t;
1159  });
1160  if (ran.deny !== void 0) return ran;
1161  const counted = await update2($, score, (old) => ({ ...old, tools: old.tools + 1 }));
1162  sim2.stats = statsLine2(counted);
1163  if (ran.isError === true) flyAway(false);
1164  return ran;
1165};
1166const render2 = async ($, e, next) => {
1167  const below = await next(e);
1168  if (!drawsGames(e.surface) || e.props.hasSurvey || !await isShown($, ID2)) {
1169    sim2.requestId = null;
1170    return below;
1171  }
1172  const { Box } = $.ui.resolve(e);
1173  fit(clamp(e.props.bodyColumns, MIN_COLUMNS, MAX_COLUMNS));
1174  sim2.requestId = e.requestId;
1175  sim2.stats = statsLine2(await read3($, score));
1176  return <Box flexDirection="column">
1177      {pixels($, e, { key: RASTER2, columns: sim2.W, rows: ROWS2, cells: frame2(false, sim2.stats), alt: "Duck Hunt" })}
1178      {below ?? null}
1179    </Box>;
1180};
1181async function reset2($) {
1182  const next = await update2($, score, () => score.initial);
1183  sim2.stats = statsLine2(next);
1184  sim2.round = 1;
1185  await update2($, feat2, () => "");
1186}
1187const game2 = { id: ID2, title: "Duck Hunt" };
1188
1189// src/games/jackpot.tsx
1190import { atom as atom4, read as read4, update as update3 } from "claude-code";
1191
1192// src/games/jackpot-symbols.ts
1193const PALETTE = {
1194  R: 16726862,
1195  r: 11735594,
1196  Y: 16765773,
1197  y: 13211164,
1198  G: 5034109,
1199  g: 2328394,
1200  C: 6281471,
hooks/bug-sky.js 401 lines
1// Built by scripts/build.sh from src/clients/ with esbuild@0.25.10. Do not edit: edit src/ and rebuild.
2// src/clients/bug-sky.tsx
3var ROWS = 8;
4var PH = ROWS * 2;
5var TICK_MS = 66;
6var GROUND = PH - 1;
7var CITY_TOP = PH - 4;
8var SKY_FLOOR = CITY_TOP - 1;
9var CITIES = 6;
10var SHOT_SPEED = 1.8;
11var COOLDOWN = 5;
12var SAND = "#c2a14d";
13var SILO = "#d9a441";
14var CITY = "#4dabf7";
15var RUBBLE = "#6b6b6b";
16var BUG_TRAIL = "#a8323e";
17var BUG_HEAD = "#ff6b6b";
18var SHOT_TRAIL = "#4c6ef5";
19var SHOT_HEAD = "#ffffff";
20var CROSS = "#69db7c";
21var GREY = "#8a8a8a";
22var GOLD = "#ffd43b";
23var BLAST = ["#ffffff", "#ffd43b", "#ff922b", "#f06595", "#cc5de8"];
24var rand = (a, b) => a + Math.random() * (b - a);
25var clamp = (v, a, b) => Math.max(a, Math.min(b, v));
26function layout(W) {
27  const silos = [2, Math.floor(W / 2), W - 3];
28  const xs = [];
29  for (const [a, b] of [[silos[0], silos[1]], [silos[1], silos[2]]]) {
30    for (let i = 1; i <= 3; i++) xs.push(Math.round(a + (b - a) * i / 4) - 2);
31  }
32  return { silos, cityX: xs };
33}
34function create(props) {
35  const W = Math.max(24, props.columns);
36  const standing = clamp(props.cities, 0, CITIES);
37  return {
38    t: 0,
39    W,
40    seen: props.events.reduce((m, e) => Math.max(m, e.id), 0),
41    cities: Array.from({ length: CITIES }, (_, i) => i < standing || standing === 0),
42    silos: layout(W).silos,
43    cooldown: [0, 0, 0],
44    bugs: [],
45    shots: [],
46    blasts: [],
47    plans: [],
48    banner: null,
49    cross: { x: Math.floor(W / 2), y: 4 },
50    hasFired: false,
51    nextBug: 40,
52    endAt: -1,
53    gain: { kills: 0, mine: 0, lost: 0, ends: 0, cities: standing === 0 ? CITIES : standing },
54    props
55  };
56}
57var cityX = (s, i) => layout(s.W).cityX[i];
58function banner(s, text, color, frames) {
59  s.banner = { text, color, until: s.t + frames };
60}
61function dropBug(s, isReal, fast = false) {
62  const alive = s.cities.map((c, i) => c ? i : -1).filter((i) => i >= 0);
63  if (alive.length === 0) return;
64  const target = alive[Math.floor(Math.random() * alive.length)];
65  const x0 = rand(1, s.W - 2);
66  const tx = cityX(s, target) + 2;
67  const frames = fast ? rand(70, 100) : rand(130, 200);
68  const vy = (SKY_FLOOR + 2) / frames;
69  s.bugs.push({ x0, y0: 0, x: x0, y: 0, vx: (tx - x0) / frames, vy, target, isReal });
70}
71function nearestSilo(s, x) {
72  let best = -1;
73  for (let i = 0; i < s.silos.length; i++) {
74    if (s.cooldown[i] > 0) continue;
75    if (best < 0 || Math.abs(s.silos[i] - x) < Math.abs(s.silos[best] - x)) best = i;
76  }
77  return best;
78}
79function fire(s, tx, ty, owner, isMiss = false, silo = nearestSilo(s, tx)) {
80  if (silo < 0) return false;
81  const sx = s.silos[silo];
82  s.cooldown[silo] = owner === "you" ? COOLDOWN : 0;
83  s.shots.push({ x0: sx, y0: SKY_FLOOR + 1, x: sx, y: SKY_FLOOR + 1, tx: clamp(tx, 0, s.W - 1), ty: clamp(ty, 0, SKY_FLOOR), owner, isMiss });
84  return true;
85}
86function autoShot(s, bug, owner, isMiss) {
87  const silo = s.silos.reduce((b, x, i) => Math.abs(x - bug.x) < Math.abs(s.silos[b] - bug.x) ? i : b, 0);
88  let tx = bug.x;
89  let ty = bug.y;
90  for (let k = 0; k < 3; k++) {
91    const frames = Math.hypot(tx - s.silos[silo], ty - (SKY_FLOOR + 1)) / SHOT_SPEED;
92    tx = bug.x + bug.vx * frames;
93    ty = bug.y + bug.vy * frames;
94  }
95  if (isMiss) tx += (Math.random() < 0.5 ? -1 : 1) * rand(6, 9);
96  fire(s, tx, ty, owner, isMiss, silo);
97}
98var lowest = (s) => s.bugs.reduce((b, x) => b === void 0 || x.y > b.y ? x : b, void 0);
99function play(s, e) {
100  const owner = e.practice ? "practice" : "auto";
101  if (e.kind === "tool") {
102    const bug = lowest(s);
103    if (bug) autoShot(s, bug, owner, Math.random() < 0.4);
104  } else if (e.kind === "fail") {
105    dropBug(s, !e.practice, true);
106    banner(s, "INCOMING", BUG_HEAD, 30);
107  } else if (e.kind === "small") {
108    const bug = lowest(s);
109    if (bug) autoShot(s, bug, owner, false);
110    else s.blasts.push({ x: rand(4, s.W - 4), y: rand(2, 7), age: 0, max: 2, owner: "practice" });
111  } else if (e.kind === "medium") {
112    if (s.bugs.length === 0) dropBug(s, !e.practice);
113    s.plans.push({ at: s.t + 20, kind: "sure", owner });
114  } else {
115    if (s.bugs.length === 0) {
116      dropBug(s, !e.practice);
117      dropBug(s, !e.practice);
118    }
119    s.plans.push({ at: s.t + 20, kind: "salvo", owner });
120    const ruined = s.cities.findIndex((c) => !c);
121    if (ruined >= 0 && !e.practice) {
122      s.cities[ruined] = true;
123      s.gain.cities = s.cities.filter(Boolean).length;
124      banner(s, "BONUS CITY", GOLD, 60);
125    } else banner(s, "SKY CLEAR!", GOLD, 60);
126  }
127}
128function step(s) {
129  s.t += 1;
130  for (let i = 0; i < s.cooldown.length; i++) s.cooldown[i] = Math.max(0, s.cooldown[i] - 1);
131  for (const p of s.plans.filter((p2) => p2.at <= s.t)) {
132    if (p.kind === "sure") {
133      const bug = lowest(s);
134      if (bug) autoShot(s, bug, p.owner, false);
135    } else for (const bug of s.bugs) autoShot(s, bug, p.owner, false);
136  }
137  s.plans = s.plans.filter((p) => p.at > s.t);
138  if (s.props.working && s.endAt < 0 && s.t >= s.nextBug && s.bugs.length < 3) {
139    dropBug(s, true);
140    s.nextBug = s.t + Math.floor(rand(120, 260));
141  }
142  for (const shot of s.shots) {
143    const dx = shot.tx - shot.x;
144    const dy = shot.ty - shot.y;
145    const d = Math.hypot(dx, dy);
146    if (d <= SHOT_SPEED) {
147      shot.x = shot.tx;
148      shot.y = shot.ty;
149      s.blasts.push({ x: shot.tx, y: shot.ty, age: 0, max: 3, owner: shot.owner });
150    } else {
151      shot.x += dx / d * SHOT_SPEED;
152      shot.y += dy / d * SHOT_SPEED;
153    }
154  }
155  s.shots = s.shots.filter((shot) => shot.x !== shot.tx || shot.y !== shot.ty);
156  for (const bug of s.bugs) {
157    bug.x += bug.vx;
158    bug.y += bug.vy;
159  }
160  for (const b of s.blasts) b.age += 1;
161  const radius = (b) => {
162    const r = [1, 1, 2, 2, 3, 3, 3, 3, 2, 2, 1][b.age] ?? 0;
163    return Math.min(r, b.max);
164  };
165  const chained = [];
166  s.bugs = s.bugs.filter((bug) => {
167    const hit = s.blasts.find((b) => radius(b) > 0 && Math.hypot(bug.x - b.x, bug.y - b.y) <= radius(b) + 0.5);
168    if (!hit) return true;
169    chained.push({ x: bug.x, y: bug.y, age: 0, max: 2, owner: hit.owner });
170    if (bug.isReal && hit.owner !== "practice") {
171      s.gain.kills += 1;
172      if (hit.owner === "you") s.gain.mine += 1;
173    }
174    return false;
175  });
176  s.blasts = [...s.blasts.filter((b) => b.age < 11), ...chained];
177  s.bugs = s.bugs.filter((bug) => {
178    if (bug.y < SKY_FLOOR + 1) return true;
179    s.blasts.push({ x: bug.x, y: SKY_FLOOR + 1, age: 0, max: 3, owner: "practice" });
180    if (bug.isReal && s.cities[bug.target]) {
181      s.cities[bug.target] = false;
182      s.gain.lost += 1;
183      s.gain.cities = s.cities.filter(Boolean).length;
184    }
185    return false;
186  });
187  if (s.endAt < 0 && s.cities.every((c) => !c)) {
188    s.endAt = s.t + 60;
189    s.bugs = [];
190    s.gain.ends += 1;
191    banner(s, "THE END", BUG_HEAD, 60);
192  }
193  if (s.endAt >= 0 && s.t >= s.endAt) {
194    s.endAt = -1;
195    s.cities = s.cities.map(() => true);
196    s.gain.cities = CITIES;
197    banner(s, "NEW CITIES", CITY, 40);
198  }
199}
200var isBusy = (s) => s.bugs.length > 0 || s.shots.length > 0 || s.blasts.length > 0 || s.plans.length > 0 || s.endAt >= 0 || s.banner !== null && s.t < s.banner.until;
201var CITY_SHAPES = [
202  [".#.#.", "#####", "#####"],
203  ["..#..", ".###.", "#####"],
204  ["#..#.", "##.##", "#####"]
205];
206function paint(s) {
207  const W = s.W;
208  const px = new Array(W * PH).fill(null);
209  const put = (x, y, c) => {
210    x = Math.round(x);
211    y = Math.round(y);
212    if (x >= 0 && x < W && y >= 0 && y < PH) px[y * W + x] = c;
213  };
214  const line = (x0, y0, x1, y1, c) => {
215    const n = Math.max(1, Math.ceil(Math.max(Math.abs(x1 - x0), Math.abs(y1 - y0))));
216    for (let i = 0; i <= n; i++) put(x0 + (x1 - x0) * i / n, y0 + (y1 - y0) * i / n, c);
217  };
218  const glyphs = /* @__PURE__ */ new Map();
219  const text = (x, row, str, color) => [...str].forEach((ch, i) => {
220    if (x + i >= 0 && x + i < W && row >= 0 && row < ROWS) glyphs.set(row * W + x + i, { ch, color });
221  });
222  for (let x = 0; x < W; x++) put(x, GROUND, SAND);
223  s.cities.forEach((alive, i) => {
224    const x = cityX(s, i);
225    if (alive) {
226      CITY_SHAPES[i % CITY_SHAPES.length].forEach((row, dy) => {
227        for (let dx = 0; dx < 5; dx++) if (row[dx] === "#") put(x + dx, CITY_TOP + dy, CITY);
228      });
229    } else for (let dx = 0; dx < 5; dx += 2) put(x + dx, GROUND - 1, RUBBLE);
230  });
231  for (const [i, sx] of s.silos.entries()) {
232    for (let dx = -2; dx <= 2; dx++) put(sx + dx, GROUND - 1, SILO);
233    for (let dx = -1; dx <= 1; dx++) put(sx + dx, GROUND - 2, s.cooldown[i] > 0 ? GREY : SILO);
234  }
235  for (const bug of s.bugs) {
236    line(bug.x0, bug.y0, bug.x, bug.y, BUG_TRAIL);
237    put(bug.x, bug.y, s.t % 6 < 3 ? BUG_HEAD : SHOT_HEAD);
238  }
239  for (const shot of s.shots) {
240    line(shot.x0, shot.y0, shot.x, shot.y, SHOT_TRAIL);
241    put(shot.x, shot.y, SHOT_HEAD);
242    if (shot.owner === "you") put(shot.tx, shot.ty, CROSS);
243  }
244  for (const b of s.blasts) {
245    const r = Math.min([1, 1, 2, 2, 3, 3, 3, 3, 2, 2, 1][b.age] ?? 0, b.max);
246    const c = BLAST[(b.age + Math.round(b.x)) % BLAST.length];
247    for (let dy = -r; dy <= r; dy++) for (let dx = -r; dx <= r; dx++) if (dx * dx + dy * dy <= r * r + 1) put(b.x + dx, b.y + dy, c);
248  }
249  const { x: cx, y: cy } = s.cross;
250  for (const [dx, dy] of [[-1, 0], [1, 0], [0, -1], [0, 1]]) put(cx + dx, cy + dy, CROSS);
251  const standing = s.cities.filter(Boolean).length;
252  const stats = `${s.props.stats}  \u2302 ${standing}`;
253  text(W - stats.length - 1, 0, stats, GREY);
254  if (!s.hasFired && s.bugs.some((b) => b.isReal)) text(1, 0, "click to fire", GREY);
255  if (s.banner && s.t < s.banner.until && (s.banner.until - s.t) % 8 > 1) {
256    text(Math.floor((W - s.banner.text.length) / 2), 1, s.banner.text, s.banner.color);
257  }
258  return { px, glyphs, W };
259}
260function draw(s, el) {
261  const { Box, Text } = el;
262  const { px, glyphs, W } = paint(s);
263  const rows = [];
264  for (let row = 0; row < ROWS; row++) {
265    const runs = [];
266    let run = "";
267    let look = "";
268    let fg;
269    let bg;
270    const flush = () => {
271      if (run) runs.push(/* @__PURE__ */ h(Text, { ...fg ? { color: fg } : {}, ...bg ? { backgroundColor: bg } : {} }, run));
272      run = "";
273    };
274    for (let x = 0; x < W; x++) {
275      const g = glyphs.get(row * W + x);
276      const top = px[row * 2 * W + x] ?? null;
277      const bottom = px[(row * 2 + 1) * W + x] ?? null;
278      let ch;
279      let f;
280      let b;
281      if (g) [ch, f, b] = [g.ch, g.color, void 0];
282      else if (top === null && bottom === null) [ch, f, b] = [" ", void 0, void 0];
283      else if (top === bottom) [ch, f, b] = ["\u2588", top, void 0];
284      else if (bottom === null) [ch, f, b] = ["\u2580", top, void 0];
285      else if (top === null) [ch, f, b] = ["\u2584", bottom, void 0];
286      else [ch, f, b] = ["\u2580", top, bottom];
287      const next = `${f ?? ""}|${b ?? ""}`;
288      if (next !== look) {
289        flush();
290        look = next;
291        fg = f;
292        bg = b;
293      }
294      run += ch;
295    }
296    flush();
297    rows.push(/* @__PURE__ */ h(Box, { flexDirection: "row" }, runs));
298  }
299  return /* @__PURE__ */ h(Box, { flexDirection: "column" }, rows);
300}
301var BugSky = (props, surface) => {
302  if (surface.state === void 0) {
303    const sky2 = create(props);
304    const redraw = () => surface.setState({ sky: sky2, frame: sky2.t });
305    let posted = props.cities;
306    const post = () => {
307      const g = sky2.gain;
308      if (g.kills + g.mine + g.lost + g.ends === 0 && g.cities === posted) return;
309      surface.post({ ...g });
310      posted = g.cities;
311      sky2.gain = { kills: 0, mine: 0, lost: 0, ends: 0, cities: g.cities };
312    };
313    surface.every(TICK_MS, () => {
314      for (const e of sky2.props.events) {
315        if (e.id <= sky2.seen) continue;
316        sky2.seen = e.id;
317        play(sky2, e);
318      }
319      const wasBusy = isBusy(sky2);
320      step(sky2);
321      post();
322      if (wasBusy || isBusy(sky2)) redraw();
323    });
324    surface.onPointer((e) => {
325      const y = e.fine ? Math.floor(e.fine.y * 2) : e.y * 2 + 1;
326      sky2.cross = { x: clamp(e.x, 0, sky2.W - 1), y: clamp(y, 0, SKY_FLOOR) };
327      if (e.type === "down" && e.button === "left" && fire(sky2, sky2.cross.x, sky2.cross.y, "you")) sky2.hasFired = true;
328      redraw();
329    });
330    surface.onKey((e) => {
331      const move = { left: [-2, 0], right: [2, 0], up: [0, -1], down: [0, 1] };
332      const m = move[e.key];
333      if (m) sky2.cross = { x: clamp(sky2.cross.x + m[0] * (e.shift ? 4 : 1), 0, sky2.W - 1), y: clamp(sky2.cross.y + m[1], 0, SKY_FLOOR) };
334      else if (e.key === " " || e.key === "return") {
335        if (fire(sky2, sky2.cross.x, sky2.cross.y, "you")) sky2.hasFired = true;
336      } else if (e.key === "1" || e.key === "2" || e.key === "3") {
337        if (fire(sky2, sky2.cross.x, sky2.cross.y, "you", false, sky2.cooldown[Number(e.key) - 1] === 0 ? Number(e.key) - 1 : -1)) sky2.hasFired = true;
338      } else return;
339      redraw();
340    });
341    surface.setState({ sky: sky2, frame: 0 });
342    return draw(sky2, surface.elements);
343  }
344  const sky = surface.state.sky;
345  sky.props = props;
346  const W = Math.max(24, surface.columns || props.columns);
347  if (W !== sky.W) {
348    sky.W = W;
349    sky.silos = layout(W).silos;
350    sky.cross.x = clamp(sky.cross.x, 0, W - 1);
351  }
352  return draw(sky, surface.elements);
353};
354var ink = (c) => parseInt(c.slice(1), 16);
355var PLAIN = 16777216;
356function skyCells(s) {
357  const { px, glyphs, W } = paint(s);
358  const words = new Uint32Array(W * ROWS * 3);
359  for (let row = 0; row < ROWS; row++) {
360    for (let x = 0; x < W; x++) {
361      const i = (row * W + x) * 3;
362      const g = glyphs.get(row * W + x);
363      const top = px[row * 2 * W + x] ?? null;
364      const bottom = px[(row * 2 + 1) * W + x] ?? null;
365      if (g) [words[i], words[i + 1], words[i + 2]] = [g.ch.codePointAt(0), ink(g.color), PLAIN];
366      else if (top === null && bottom === null) [words[i], words[i + 1], words[i + 2]] = [32, PLAIN, PLAIN];
367      else if (top === bottom) [words[i], words[i + 1], words[i + 2]] = [9608, ink(top), PLAIN];
368      else if (bottom === null) [words[i], words[i + 1], words[i + 2]] = [9600, ink(top), PLAIN];
369      else if (top === null) [words[i], words[i + 1], words[i + 2]] = [9604, ink(bottom), PLAIN];
370      else [words[i], words[i + 1], words[i + 2]] = [9600, ink(top), ink(bottom)];
371    }
372  }
373  return encode(new Uint8Array(words.buffer));
374}
375var B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
376function encode(bytes) {
377  let out = "";
378  let i = 0;
379  for (; i + 2 < bytes.length; i += 3) {
380    const n = bytes[i] << 16 | bytes[i + 1] << 8 | bytes[i + 2];
381    out += B64[n >> 18 & 63] + B64[n >> 12 & 63] + B64[n >> 6 & 63] + B64[n & 63];
382  }
383  const rest = bytes.length - i;
384  if (rest === 1) {
385    const n = bytes[i] << 16;
386    out += B64[n >> 18 & 63] + B64[n >> 12 & 63] + "==";
387  } else if (rest === 2) {
388    const n = bytes[i] << 16 | bytes[i + 1] << 8;
389    out += B64[n >> 18 & 63] + B64[n >> 12 & 63] + B64[n >> 6 & 63] + "=";
390  }
391  return out;
392}
393var bug_sky_default = BugSky;
394export {
395  create,
396  bug_sky_default as default,
397  play,
398  skyCells,
399  step
400};
401
types/index.d.ts 104 lines
1// dragon-lair
2export type Hoard = { gold: number; meals: number; feats: number }
3export type DragonMood = 'idle' | 'work' | 'sad' | 'sleep' | 'fire'
4
5// jackpot
6export type Bank = {
7  chips: number
8  spins: number
9  jackpots: number
10  best: number
11  streak: number
12}
13
14// outlaw
15export type OutlawScore = { you: number; bugs: number; streak: number; best: number }
16
17// tama
18export type Stage = 'egg' | 'baby' | 'child' | 'teen' | 'worker' | 'rascal' | 'chubby'
19
20export type Pet = {
21  stage: Stage
22  // Epoch milliseconds: when it hatched, and when hunger and joy last ticked down.
23  born: number
24  hungerAt: number
25  joyAt: number
26  hunger: number
27  joy: number
28  poops: number
29  // Since when hunger has sat at 0; it leaves after twelve hours of it.
30  starvingSince: number
31  eggTurns: number
32  turns: number
33  wins: number
34  errors: number
35  cleanRun: number
36  generation: number
37  // Hand care left today, and which day that is (YYYY-MM-DD).
38  careDay: string
39  careLeft: number
40}
41
42// tetris
43export type Tally = { score: number; lines: number; best: number; games: number }
44
45// octo-invader
46export type OctoScore = { xp: number; toppled: number; planes: number; tools: number }
47export type OctoMood = 'idle' | 'work' | 'sad' | 'sleep' | 'rampage'
48// duck-hunt
49export type DuckScore = { hits: number; escaped: number; tools: number }
50// bug-command
51// dario
52// block-town
53export type TownScore = { blocks: number; houses: number; trees: number; castles: number; creepers: number; tools: number }
54export type TownPlot = {
55  kind: 'house' | 'bighouse' | 'farm' | 'well' | 'tower' | 'castle' | 'tree'
56  x: number
57  progress: number
58  wasDone: boolean
59  plantedAt?: number
60}
61export type DarioScore = { coins: number; stomps: number; hits: number; clears: number; tools: number }
62export type BugsScore = { kills: number; mine: number; lost: number; ends: number; cities: number; tools: number }
63export type BugsFeed = {
64  events: { id: number; kind: 'tool' | 'fail' | 'small' | 'medium' | 'big'; practice: boolean }[]
65  next: number
66  working: boolean
67}
68
69declare module 'claude-code' {
70  interface PluginState {
71    arcade: {
72      // Which games this session shows, and the setting they were picked for.
73      shown: readonly string[]
74      pickedFor: string
75      // The game new terminals start with ('' unless fixed), and whether the first sessions' hint shows.
76      defaultGame: string
77      hint: boolean
78      // A newer Arcade version found on GitHub at this session's start ('' when none).
79      latest: string
80      dragonHoard: Hoard
81      dragonMood: DragonMood
82      dragonFeat: string
83      jackpotBank: Bank
84      jackpotGolden: number
85      jackpotLast: string
86      outlawScore: OutlawScore
87      tamaPet: Pet
88      tetrisTally: Tally
89      octopusScore: OctoScore
90      octopusMood: OctoMood
91      octopusFeat: string
92      duckScore: DuckScore
93      duckFeat: string
94      bugsScore: BugsScore
95      bugsFeed: BugsFeed
96      bugsFeat: string
97      darioScore: DarioScore
98      darioFeat: string
99      townScore: TownScore
100      townFeat: string
101    }
102  }
103}
104