# Crew RPG The agents you dispatch show up as heroes of a tiny pixel-art RPG. A panel at the bottom of the sidebar lists them grouped by session, and a Watch button opens a battlefield tab where each session's agents fight a boss together, with a status card per hero showing how much of their 5 hour and weekly quota is left. When nothing is dispatched, the heroes sit around a campfire. ![Crew RPG](preview.png) The interface comes in English and Traditional Chinese; this recipe quotes the English texts, and `i18n.js` has both. The mod folder is `mods/herdr-crew-rpg/` and the code refers to itself by that name (`mods/herdr-crew-rpg/...` image paths, `mod: "herdr-crew-rpg"`); rename all of them together if you rename the folder. ## What you see **Sidebar panel** (a block in the sidebar column, full sidebar width, 90px minimum height). Top to bottom: 1. Header, 36px: the label `Crew` (11.5px, semibold, `dim`) and the number of agents (11px, `dim`) on the left; on the right a `Watch` button (`觀看`), 26px tall, radius 8, `raised` fill, 1px `border`, an eye icon and the text in `accent`; hovering fills with `hover` and turns the border `accent`. 2. A scrolling list, one group per session. The group header is 28px: a chevron (11px), a 7px status dot, the session name (13px, medium, `foreground`) and the number of agents on the right (12px, `dim`). Dot colour: `blocked` if any agent is waiting for an answer, else `working` if any is working, else `done` if all are done, else `idle`. 3. Under each header, one card per agent: 8px padding, a 1px `border` line below, radius 8. Left, a 36px face avatar (radius 8). Right, top to bottom: the tool name (13px, medium) then the age (12px, `dim`: `Now`, `N min` or `N h`), a 7px status dot, a send icon and a close icon (each 20 by 24px, icons 13px, `muted`); the task text (13px, `muted`); an `Output` row (a 10px chevron and the text `Output`, 12px, `dim`, 20px tall, radius 4, `raised` fill on hover) that opens to the agent's last 3 lines of terminal output (12px monospace, `dim`), and is missing when nothing is left after the filtering described under Built from; model and effort chips (20px tall, radius 4, `raised` fill, `muted` text). Leads are prefixed `Lead `. Under a lead, its workers are nested cards on `canvas`; agents without a lead sit under the heading `Dispatched directly` when the group also has leads. 4. A `Quota` block (border on top, 16px side padding) with a `Hide`, `Summary` or `Detail` switch. Summary is one row per provider with a 14px provider icon and three monospace columns: percent used of the 5 hour window, percent used of the weekly window, and the number of reset credits; values at 90% or more turn `blocked`. Detail is a 240px scrolling list per provider and model with a bar and a reset time per window. Below 160px of sidebar width only a `»` button is drawn, which restores the sidebar. **Battlefield tab** (one pane, `props.view = "house"`): 1. A 42px header with one tab per session (28px tall, radius 8, `raised` fill when selected, a status dot, the session name) and, on the right, `N in battle, M attacking` for the selected session. 2. The scene: a 1376x768 background picture scaled to fit, radius 12, never wider than 1500px or narrower than 320px. Its size is chosen so the scene plus the card row exactly fill the pane height without a scrollbar. The boss stands in the middle, heroes stand on six fixed seats, three on each side facing the boss. 3. Above each hero a speech bubble (13px, `foreground`, radius 12, `background` fill, 1px border in the hero's status colour) with the task text, and a small `▾` pointing at the hero. Bubbles stay inside the scene. 4. Below the scene one status card per hero in a single row, never wrapped: radius 12, `canvas` fill, 1px `border`, a 56px face avatar, the provider name (13px, medium) with the state word in the status colour, and two bars: `HP` in `done` (`blocked` below 20) and `MP` in `accent`, each with its number (12px). Cards are equal width up to 260px; below 190px the state word becomes a coloured dot before the name. **Camp** (no agents anywhere): the same background with a campfire in the middle (three flame frames, a soft glow) and one hero per provider you use, seated closest to the fire first, left and right alternating, all in the resting pose, with a status card row below. Providers you use are those with quota data or an installed command (see Built from). Before any quota has loaded, six heroes without cards sit there. ## How it behaves Statuses come from Herdr's agent state. A terminal with no agent state (a plain program) counts as working. | Status | Sidebar dot | Hero pose | Bubble border | | --- | --- | --- | --- | | working | `working`, pulsing between 0.4 and 1 opacity every 1.8s | attack, alternating two frames every 600ms | `working` | | blocked | `blocked` | help (kneeling, arm raised) | `blocked` | | done | `done` | victory fist; after 2 minutes it becomes resting | `done`, then `idle` | | idle or ended | `idle` | resting with a coffee cup | `idle` | - **Click a card or a hero:** `terminal.peek` on that agent's terminal. Ended agents are not clickable. - **Click a speech bubble:** brings that hero and bubble to the front; click again to put it back. - **Send icon:** opens an input under the card (placeholder `Type a message for the team member`, or `...for the lead`); Enter or `Send` runs `hc send ` and shows `Sending`, then `Sent` or `Failed to send` for 3 seconds. `Cancel` closes it. Reviewers have no send icon. - **Output row:** a click opens or closes the output; closed by default (`OUTPUT_OPEN_BY_DEFAULT` in `main.js`), and the state lives only for the current run. The click does not peek the terminal. - **Close icon:** first click turns it into a `Confirm stop` text button in `blocked`; a second click within 3 seconds runs `terminal.kill`; otherwise it goes back. - **Group header click:** folds or unfolds the group. The folded set survives restarts. - **Watch button:** selects the existing battlefield tab, or opens a new one named `Crew`. - **Quota switch:** opens a popup menu with Hide, Summary, Detail; the choice is remembered. - **Battlefield:** every 600ms the beat advances. On odd beats each attacking hero spawns one damage number over the boss (random 120 to 1999, or 3000 to 9998 with 12% chance, drawn bigger), which pops to 1.5x, then rises and drifts sideways along an arc for 1.1 seconds and fades. The boss flashes white (`hurt`) on those beats while anyone is attacking. When every agent of a session is done or ended and at least one is done, the boss lies down (`down`). When that session starts working again, the boss is replaced by the next one in the order dragon, golem, lich, minotaur, beholder, preferring ones no other session is using. - **Ended terminals** disappear from Herdr's list; the hero stays in place for 10 minutes, labelled `Done`, in the victory pose for the first 2 minutes and resting after that, then leaves. If there are more than six agents, ended ones leave first and a line says how many are not shown. - **Hero assignment:** per session, each agent gets the hero of its tool (claude mage, codex warrior, agy and gemini archer, grok rogue, ollama cleric, cursor lancer) unless another agent in the session already has it, then the first free one of cleric, lancer, warrior, mage, archer, rogue. The choice is stored, so the sidebar avatar and the battlefield hero always match and never change while the agent lives. - **HP and MP:** HP is 100 minus the percent used of the provider's 5 hour window, MP is 100 minus the percent used of its weekly (or monthly) window. A provider without that window shows 100. If the weekly window is used up, HP is 0 too. Gemini uses only the windows whose key starts with `Gemini`. ## Built from Files, all in `mods/herdr-crew-rpg/`: - `mod.json`: `{ "place": "none", "title": "Crew" }`. - `main.js`: the view `Crew` (sidebar panel, quota block and the popup menu when `props().role === "menu"`). When `props().view === "house"` it creates a `House` instead and only refreshes quota. - `house.js`: the `House` (tabs, camp, quota cards) and `Field` (one session's scene) classes, `sessionOf`, `assignHeroes`, `statusOf`. - `quota.py`: prints `{"now", "providers": [...]}`, each provider `{id, name, windows: [{key, pct, resets_at, rolled}], age, stale, note?, noquota?, plan?, reset_credits?}`. Run by `main.js` through `exec("python3", ["-I", appHome() + "/mods/herdr-crew-rpg/quota.py"])` every 60 seconds. - `config.json`: `{ "language": "auto", "cursorQuota": false }`. - `output.js`: `cleanOutput(text, maxLines)`. It collapses every run of whitespace to one space (TUI footers pad lines with long runs of spaces), keeps lines that have a letter or digit and do not start with `[hc]`, drops the lines that match the `NOISE` patterns, and returns the last `maxLines` joined by newlines. The patterns were collected from real Claude Code and Codex screens: input prompts (lines starting with `›` or `❯`), spinner and timing lines (starting with `✻ ✽ ✢ ✶ ✳ ✺ ✹ ✸ · *`), `⏵` permission mode lines, Codex's `• Working (`, `for shortcuts`, `f2 to view`, `esc to interrupt`, `ctrl+x to`, `shift+tab`, `Tip:`, status lines (containing `│`, progress bar glyphs, `current ○`, `weekly ●`, `cache ●`, `Model: ... Ctx:`, ` · `), update notices, `Press up|esc|enter` and `+ Show details`. - `i18n.js`: every interface text in `zh-TW` and `en` (about 59 keys each, some are functions that take parameters such as `{ n }`), `tr(key, params)` to look one up, `noteText(note)` for the failure codes from `quota.py`, and `resolveLanguage()`. The language is `config.json`'s `language` when it is `zh-TW` or `en`. When it is `auto` (the default, also for a missing or broken file), on macOS it runs `defaults read -g AppleLanguages` and takes the first entry, elsewhere it reads `LC_ALL` or `LANG` through `sh -c`; `zh-Hant`, `zh-TW`, `zh-HK` and `zh-MO` give Traditional Chinese, anything else English. The result is stored in the shared key `herdr-crew-rpg.language`, so the next start draws the right language at once; before anything is known it is English. Both views re-check every 60 seconds together with the quota refresh. - Icons: `calendar.svg clock.svg reset.svg send.svg close.svg eye.svg check.svg chevron-down.svg chevron-right.svg review.svg` (24px viewBox, stroke `currentColor`; `check.svg` marks the selected quota mode in the popup menu, `review.svg` is the provider icon of reviewers). - `house/rpg/`: the pictures. `background.png` (1376x768); `boss--.png` for five bosses; `-.png` and `-l` mirrored copies for six heroes; `avatar-.png` (128x128); `camp-0|1|2.png` and `camp-glow.png`; `num-n-0..9.png`, `num-c-0..9.png` (28x36 damage digits, normal and critical). Sizes of each boss and hero are tabled in `house.js` (`BOSSES`, `HEROES`) and must match the files. - `house/campfire.py`, `house/numbers.py`: draw the campfire and the digits. Run with `python3 -I`. `house/ASSETS.md` has the prompts for every generated picture. Layout: one block in the sidebar column, under the spaces list: ```json { "id": "agents", "type": "block", "content": { "mod": "herdr-crew-rpg" }, "size": { "weight": 1 }, "min": 90 } ``` The sidebar column needs the id `sidebar` (the `»` button resizes it with `layout.resize`). `herdr` functions used: `hc`, `exec`, `appHome`, `run`, `terminals`, `theme`, `layout`, `settings`, `shared`, `setShared`, `window`, `props`, `openOverlay`, `closeOverlay`, `panes`, `spaces`. Commands run: `terminal.peek`, `terminal.kill`, `tab.new {name: "Crew", mod: "herdr-crew-rpg", props: {view: "house"}}`, `tab.select`, `layout.resize`. `hc` calls: `hc read --lines 0` every 5 seconds, run through `cleanOutput(text, 3)` from `output.js`, and `hc send`. From `gpui-kit` and `gpui-base`: `View`, `div`, `svg`, `image`, `v_flex`, `h_flex`, `InputState`, `Input`, `Button`. Which terminals: `terminals()` filtered to `labels.crew === "1"`. Other labels: `crew.role` (`lead`, `worker` default, `reviewer`), `crew.tool`, `crew.task`, `crew.model`, `crew.effort`. The session of an agent is the first ancestor, following `parent`, that does not have `crew=1`; its name is its `where` label, else the last part of its folder. Colours are theme tokens from `theme()`: `background canvas chrome raised hover border foreground muted dim accent working blocked done idle`. Quota sources in `quota.py` (cached 5 minutes in `~/.cache/agent-crew`, a provider that fails is left with empty windows): - Claude: `/tmp/claude/statusline-usage-cache.json` (`five_hour`, `seven_day` with `utilization` and `resets_at`), written by a Claude Code status line script, not by this mod. - Codex: JSON-RPC to `codex app-server` (`initialize`, `initialized`, `account/rateLimits/read`); falls back to the last `rate_limits` in `~/.codex/sessions/*/*/*/*.jsonl`. - agy: `agy -p /quota --output-format json`, groups Gemini, Claude and GPT, and Gemini 4 Argon, each with 5h and weekly buckets. - Grok: JSON-RPC to `grok agent stdio` (`initialize`, `_x.ai/billing`), one weekly pool. - Ollama and Cursor: detected only (`ollama` command; `/Applications/Cursor.app`, `~/.cursor` or `cursor-agent`), returned with `noquota: true`, which hides them from the Quota block but gives them a camp hero. With `cursorQuota: true` Cursor instead reads the keychain item `cursor-access-token` with `security find-generic-password -w` and posts `{}` with a bearer token to `https://api2.cursor.sh/aiserver.v1.DashboardService/GetCurrentPeriodUsage`, using `planUsage.totalPercentUsed`, `billingCycleStart` and `billingCycleEnd`; a cycle of 8 days or less is the weekly window, otherwise monthly. Failure is cached for 30 minutes. Shared store keys written: `herdr-crew-rpg.folded`, `herdr-crew-rpg.heroes`, `herdr-crew-rpg.quota.mode`, `herdr-crew-rpg.language`, and `sidebar.width`, `sidebar.collapsed` by the narrow-rail button. ## Watch out - The mod does nothing visible for agents until their terminals carry `crew=1`. The author's own dispatcher sets the labels; without one, label terminals yourself with `hc run --label crew=1 --label crew.tool=... --label "crew.task=..."`. - Reading `/tmp/claude/statusline-usage-cache.json` only works if a status line script keeps that file. Without it Claude has empty windows, so its hero shows 100 and 100. - Tell the person before adding: the mod runs `python3`, `hc`, `codex`, `agy`, `grok` and `security` (Cursor, opt-in), reads files outside its folder (above), writes `~/.cache/agent-crew`, and can kill a terminal. - `house/numbers.py` shadows the standard library `numbers` module for any Python started inside that folder; run it as `python3 -I numbers.py` (and `campfire.py` likewise), otherwise numpy fails to import. - Rebuilding the pictures from the prompts will not give the same faces; keep the shipped files unless you want a different cast. The sprite sheets are cut out with a flat `#FF00FF` background, and image models drift towards pinker magentas, so a key colour tolerance is needed. - The scene size is computed from the pane size, with the card row height estimated at 88px; if you change the card layout, change `CARD_H` too, or a scrollbar appears. - The output filter is a list of patterns for the footers of the agents the author uses (Claude Code with a custom status line, Codex). Another agent's footer lines will show up as output until a pattern for them is added to `NOISE` in `output.js`; keep each pattern specific, because a pattern that is too loose hides real output. - A view that fails to re-render keeps showing the last good frame without an entry in `herdr-app status`; always look at the picture, not only `herdr-app check`. - Many hot reloads in one app session can end in `out of memory` errors from the mod runtime; restarting the Herdr window clears it. - Herdr has no language setting and mod code has no `Intl`, `navigator` or `process.env` locale, so the mod picks the language itself (see Built from). A new language is one more block in `i18n.js` whose keys match `en`, nothing else needs to change. - Window labels from `quota.py` are language neutral keys (`5h`, `7d`, `30d`, `period`, or `-5h` and `-weekly` for agy) and failure reasons are codes such as `cursor.http:401`; `main.js` turns them into words. Do not put display text in `quota.py`. ## Done when 1. `herdr-app check ~/.config/herdr-app/mods/herdr-crew-rpg` passes and `herdr-app status` shows no errors. 2. With no terminal labelled `crew=1`, the `Crew` tab shows a campfire, no boss, and one hero and one status card per provider you use. 3. After `hc run --bg --name t1 --label crew=1 --label crew.tool=ollama --label "crew.task=Test" -- sleep 60`, the sidebar shows a group named after the terminal that ran the command, with one card whose dot is orange and pulsing, and the battlefield shows a boss and an attacking cleric with damage numbers rising from the boss. 4. Starting a second terminal from a different parent shows a second group and a second tab, with a different boss. 5. Clicking a group header hides its cards and the dot and count remain; the state is the same after restarting the app. 6. Clicking the close icon changes it to `Confirm stop`; waiting 3 seconds restores it; clicking twice kills the terminal and the hero keeps the victory pose with `Done` on the battlefield. 7. With `hc ls` showing two Ollama agents in one session, the sidebar avatars are the cleric and the lancer, the same as the two heroes on the battlefield. 8. Setting a provider's weekly window to 100 percent used shows HP 0 and MP 0 on its card; a provider with no windows shows 100 and 100. 9. Setting `"language": "en"` in `config.json` turns the texts English within a minute, `"zh-TW"` turns them Traditional Chinese, and `"auto"` follows the system language. 10. Making the window shorter shrinks the scene so the card row stays visible without a scrollbar and the six cards stay on one row. 11. Open the `Output` row of a Codex or Claude Code agent: it shows what the agent said or did, and none of the `? for shortcuts`, `⏵⏵ bypass permissions`, status line or prompt lines; an agent whose screen has only such lines has no `Output` row.