SLOPSHOPPER

slopothon

Draws a SLOPOTHON banner above the prompt until the first prompt is sent

spinnerrowscommandprocess
v0.1.0MITupdated 2026-10-17binbandit/bin-stack/mods/slopothon
A shopper browsing a rack in a slop shop
Preview · a replayed session in a sandbox
claude · ~/work/app · slopothon
› fix the failing auth test and add an audit log call ⏺ Read(src/auth.ts) ⎿ Read 6 lines ⏺ Update(src/auth.ts) ⎿ Added 2 lines, removed 1 line ⏺ Bash(bun test) ⎿ 3 pass, 1 fail ● Done. refresh now rejects expired claims and logs an audit event. ✻ Worked for 42s · done 4:20 PM › /slopothon ▄▄▄▄▄▄ ▄▄ ▄▄▄▄▄▄ ▄▄▄▄▄▄ ▄▄▄▄▄▄ ▄▄▄▄▄▄ ▄▄ ▄▄ ▄▄▄▄▄▄ ▄▄ ▄▄ 01 // MODEL __________________ … ██▄▄▄▄ ██ ██ ██ ██▄▄██ ██ ██ ██ ██▄▄██ ██ ██ ██▀▄ ██ ⡔⠒⡄⡖⠒⡄⡆ ⡆⡔⠒⠂ ⣖⣒⠂ ⣖⣒⠂ … ▄▄▄▄██ ██▄▄▄▄ ██▄▄██ ██ ██▄▄██ ██ ██ ██ ██▄▄██ ██ ▀██ ⢇⣀⠇⡏⠉ ⢇⣀⠇⣈⣉⠆ ⢄⣀⠇⢠⡄ ⢄⣀⠇ … ONE MORE PROMPT ╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱ │││█▌║│█▌║│█▌║ BRANCH // feat/auth-refresh __ … + SESSION EEE- _ BUILD 2.1.289 ____________________________________________ スロップ・マラソン + … ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── › ? for shortcuts

Draws

Command output
▄▄▄▄▄▄ ▄▄ ▄▄▄▄▄▄ ▄▄▄▄▄▄ ▄▄▄▄▄▄ ▄▄▄▄▄▄ ▄▄ ▄▄ ▄▄▄▄▄▄ ▄▄ ▄▄ 01 // MODEL __________________ … ██▄▄▄▄ ██ ██ ██ ██▄▄██ ██ ██ ██ ██▄▄██ ██ ██ ██▀▄ ██ ⡔⠒⡄⡖⠒⡄⡆ ⡆⡔⠒⠂ ⣖⣒⠂ ⣖⣒⠂ … ▄▄▄▄██ ██▄▄▄▄ ██▄▄██ ██ ██▄▄██ ██ ██ ██ ██▄▄██ ██ ▀██ ⢇⣀⠇⡏⠉ ⢇⣀⠇⣈⣉⠆ ⢄⣀⠇⢠⡄ ⢄⣀⠇ … ONE MORE PROMPT ╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱ │││█▌║│█▌║│█▌║ BRANCH // feat/auth-refresh __ … + SESSION EEE- _ BUILD 2.1.289 ____________________________________________ スロップ・マラソン + …
README

bin-stack

A harness-agnostic agent skill stack.

Skills follow the Agent Skills format (SKILL.md + optional scripts/references/assets). One source of truth under skills/. Works with Cursor, Claude Code, Codex, and any other agent that discovers skills the standard way.

Inspired by stacks like pstack, but not locked to a single product.

Install

Via skills CLI

npx skills add binbandit/bin-stack

Pick specific skills:

npx skills add binbandit/bin-stack --skill file-pr --skill babysit-pr --skill arena --skill bro

Symlink a clone (one copy, every harness)

git clone https://github.com/binbandit/bin-stack.git ~/Developer/ai/bin-stack
cd ~/Developer/ai/bin-stack
./scripts/link-skills.sh

That links each skill directory into the harness roots you already have (~/.agents/skills, ~/.cursor/skills, ~/.claude/skills, ~/.codex/skills, …). Edit here; every harness sees the same files.

Skills

SkillWhen to use
file-prFile or update a concise pull request
babysit-prMonitor a PR through review bots and CI
arenaRun competing attempts, then graft the strongest ideas into one result
broRestate the last message in plain language
verifyProve a behavior change on the user surface with revision-bound evidence
reviewFilter adversarial findings by reachable failure and concrete evidence
anatomyBuild detailed, interactive isometric illustrations that explain technical ideas as physical machines

anatomy includes its rendering kit, reference guides, examples, and helper scripts. It needs Node.js 20.10+; browser checks also need Chrome or Chromium (set CHROME_PATH if it is not in a standard location). Build and capture the smallest example from the skill directory:

cd skills/anatomy
node examples/dial-indicator/build.mjs --light
node scripts/capture.mjs examples/dial-indicator/dial-indicator-light.html --out /tmp/anatomy-preview.png

See anatomy's setup and verification guide for the other script commands.

Mods

Claude Code mods: plugins of function hooks that change how Claude Code looks and behaves. They are Claude Code only.

ModWhat it does
glamour-darkDraws replies as rich markdown in glamour's dark style, one sentence per line
redact-secretsSwaps secrets for placeholders before Claude reads them or the session logs them; Write and Edit put the real values back
tool-linesDraws each tool call as one compact line; click a call to open its result, click it again to close it
ascii-spinnerSwaps the working line (verb, timer, tokens, effort, tip) for a one-row WEAVEworm rethreading synthsilk, in Sekiguchi colors
slopothonPaints a SLOPOTHON lockup over the Claude logo: block wordmark, a dot-matrix card naming the model and branch, and a livery strip with a tagline and barcode per session. Fullscreen ("tui": "fullscreen") only; it starts each session with a /slopothon row and the logo shows for ~130ms first. Type /slopothon to redraw it inline

Install specific mods at user scope (requires Claude Code on PATH and Python 3):

./scripts/install-mods.sh --list
./scripts/install-mods.sh glamour-dark tool-lines

The script validates every requested name before changing anything, adds mods/ as the bin-stack marketplace, and installs only the named mods. No arguments prints usage and exits without installing anything; --list lists available names without making changes. Duplicate names are installed once per invocation, and re-running an install is safe. Claude Code reads the mods in place from this clone, so an edit here applies on the next session or /reload-plugins.

Run the installer's isolated fixture tests with python3 -m unittest discover -s scripts/tests -v.

Layout

skills/
  file-pr/SKILL.md
  babysit-pr/SKILL.md
  arena/SKILL.md
  bro/SKILL.md
  verify/SKILL.md
  review/SKILL.md
  anatomy/        # SKILL.md, kit, references, examples, and helper scripts
mods/
  .claude-plugin/marketplace.json
  glamour-dark/
  redact-secrets/
  tool-lines/
  ascii-spinner/
  slopothon/
scripts/
  link-skills.sh   # optional: symlink into local harness skill roots
  install-mods.sh  # install named Claude Code mods

Canonical skills live in skills/. Harness-specific paths are adapters (symlinks or CLI installs), not forks of the content.

Authoring

  1. Add skills/<name>/SKILL.md with required name and description frontmatter.
  2. Keep name matching the directory. Lowercase, hyphens only.
  3. Put long reference material in references/; keep SKILL.md short enough to load on activation.
  4. Prefer harness-neutral wording. Call out Cursor / Claude / Codex only when a step truly differs.

See agentskills.io/specification.

License

MIT

The verify and review skills adapt selected pstack guidance by Lauren Tan at revision 9f451cf875ad1239912762f67741e8e5ba6ac0f1. Each skill bundles its provenance and the original MIT notice in LICENSE-pstack so attribution travels with individual skill installs.

The anatomy skill is imported from wheresryan22/anatomy at revision 689dcf966e63d92be10a5d593c6e19e10acd4422. Its source notes and original MIT license travel with individual skill installs.

Source 1 files
hooks/register.ts 422 lines
1import type { Elements, EngineInterface, Register, RenderNode, SessionMessage, TextProps } from 'claude-code'
2
3const VOLT = '#C8FF00'
4const BONE = '#E4E4DC'
5const INK = '#0A0A0A'
6const SIGNAL_PINK = '#FF2E88'
7
8const PLUGIN = 'slopothon'
9const COMMAND = 'slopothon'
10const BOOT_TEXT = 'SLOPOTHON'
11const SHOW_TEXT = 'SLOPOTHON banner'
12
13const WORDMARK = [
14  '▄▄▄▄▄▄ ▄▄     ▄▄▄▄▄▄ ▄▄▄▄▄▄ ▄▄▄▄▄▄ ▄▄▄▄▄▄ ▄▄  ▄▄ ▄▄▄▄▄▄ ▄▄   ▄▄',
15  '██▄▄▄▄ ██     ██  ██ ██▄▄██ ██  ██   ██   ██▄▄██ ██  ██ ██▀▄ ██',
16  '▄▄▄▄██ ██▄▄▄▄ ██▄▄██ ██     ██▄▄██   ██   ██  ██ ██▄▄██ ██  ▀██',
17]
18const WORDMARK_COLUMNS = WORDMARK[0]?.length ?? 0
19const LETTER_PITCH = 7
20const SLOP_COLUMNS = 'SLOP'.length * LETTER_PITCH
21const SPACED_SLOP = 'S L O P '
22const SPACED_OTHON = 'O T H O N'
23
24const TAGLINES = [
25  'SLOP IS A MARATHON, NOT A SPRINT',
26  'NO DIFF LEFT BEHIND',
27  'TOKENS IN, SLOP OUT',
28  'PROMPT. DIFF. REPEAT.',
29  "GREEN TESTS OR IT DIDN'T HAPPEN",
30  'READ THE DIFF BEFORE YOU SHIP',
31  'ONE MORE PROMPT',
32  'ALL GAS, SOME BRAKES',
33]
34const BARS = ['▌', '║', '│', '█']
35const BARCODE_COLUMNS = 14
36const KATAKANA = 'スロップ・マラソン'
37const NO_GIT = 'NO GIT'
38const COLUMN_GAP = '   '
39const CARD_COLUMNS = 30
40const DOT_MATRIX_PITCH = 3
41const PLATE_COLUMNS = WORDMARK_COLUMNS + COLUMN_GAP.length + CARD_COLUMNS
42const UNMEASURED_COLUMNS = 80
43
44const DOT_MATRIX_FONT: Record<string, string> = {
45  A: '.###.|#...#|#...#|#####|#...#|#...#|#...#',
46  B: '####.|#...#|#...#|####.|#...#|#...#|####.',
47  C: '.###.|#...#|#....|#....|#....|#...#|.###.',
48  D: '####.|#...#|#...#|#...#|#...#|#...#|####.',
49  E: '#####|#....|#....|####.|#....|#....|#####',
50  F: '#####|#....|#....|####.|#....|#....|#....',
51  G: '.###.|#...#|#....|#.###|#...#|#...#|.####',
52  H: '#...#|#...#|#...#|#####|#...#|#...#|#...#',
53  I: '.###.|..#..|..#..|..#..|..#..|..#..|.###.',
54  J: '..###|...#.|...#.|...#.|...#.|#..#.|.##..',
55  K: '#...#|#..#.|#.#..|##...|#.#..|#..#.|#...#',
56  L: '#....|#....|#....|#....|#....|#....|#####',
57  M: '#...#|##.##|#.#.#|#.#.#|#...#|#...#|#...#',
58  N: '#...#|#...#|##..#|#.#.#|#..##|#...#|#...#',
59  O: '.###.|#...#|#...#|#...#|#...#|#...#|.###.',
60  P: '####.|#...#|#...#|####.|#....|#....|#....',
61  Q: '.###.|#...#|#...#|#...#|#.#.#|#..#.|.##.#',
62  R: '####.|#...#|#...#|####.|#.#..|#..#.|#...#',
63  S: '.####|#....|#....|.###.|....#|....#|####.',
64  T: '#####|..#..|..#..|..#..|..#..|..#..|..#..',
65  U: '#...#|#...#|#...#|#...#|#...#|#...#|.###.',
66  V: '#...#|#...#|#...#|#...#|#...#|.#.#.|..#..',
67  W: '#...#|#...#|#...#|#.#.#|#.#.#|#.#.#|.#.#.',
68  X: '#...#|#...#|.#.#.|..#..|.#.#.|#...#|#...#',
69  Y: '#...#|#...#|.#.#.|..#..|..#..|..#..|..#..',
70  Z: '#####|....#|...#.|..#..|.#...|#....|#####',
71  '0': '.###.|#...#|#..##|#.#.#|##..#|#...#|.###.',
72  '1': '..#..|.##..|..#..|..#..|..#..|..#..|.###.',
73  '2': '.###.|#...#|....#|...#.|..#..|.#...|#####',
74  '3': '#####|...#.|..#..|...#.|....#|#...#|.###.',
75  '4': '...#.|..##.|.#.#.|#..#.|#####|...#.|...#.',
76  '5': '#####|#....|####.|....#|....#|#...#|.###.',
77  '6': '..##.|.#...|#....|####.|#...#|#...#|.###.',
78  '7': '#####|....#|...#.|..#..|.#...|.#...|.#...',
79  '8': '.###.|#...#|#...#|.###.|#...#|#...#|.###.',
80  '9': '.###.|#...#|#...#|.####|....#|...#.|.##..',
81  '.': '.....|.....|.....|.....|.....|.##..|.##..',
82  '-': '.....|.....|.....|#####|.....|.....|.....',
83  '/': '.....|....#|...#.|..#..|.#...|#....|.....',
84}
85const BRAILLE_DOTS = [
86  [0x01, 0x08],
87  [0x02, 0x10],
88  [0x04, 0x20],
89  [0x40, 0x80],
90]
91const BRAILLE_BLANK = 0x2800
92
93const ROWS_FROM_LOGO_TO_BOOT_ROW = 6
94const ROWS_PER_RECORD_ABOVE_BOOT_ROW = 2
95const ROWS_FROM_LOGO_TO_FIRST_PROMPT = 4
96const SLACK_ROWS = 3
97const TRANSCRIPT_HEAD_BYTES = 512 * 1024
98const CHAT_ENTRY_TYPES = new Set(['user', 'assistant', 'system'])
99const BOOT_RECORD_TEXT = `<command-name>/${COMMAND}</command-name>`
100
101type Run = { version: string; model: string; branch: string | undefined; id: string }
102type Notice = { text: string; command: string | null }
103type Style = Pick<TextProps, 'color' | 'backgroundColor' | 'bold' | 'dimColor'>
104type Span = { text: string; style?: Style }
105type Line = Span[]
106type TerminalElements = Elements['terminal']
107
108const DIM: Style = { dimColor: true }
109const MARK: Style = { color: SIGNAL_PINK }
110const PLAIN: Style = { color: BONE }
111
112type Anchor = { row: 'boot'; recordsAbove: number } | { row: 'first prompt'; id: string }
113type EntryKind = 'meta' | 'prompt' | 'boot' | 'command' | 'shell' | 'output' | 'reply'
114type TranscriptEntry = { uuid: string; parent: string | null; kind: EntryKind }
115
116let run: Run | undefined
117let anchor: Anchor | undefined
118let resumedAnchor: Anchor | undefined
119let isInteractive = false
120const notices = new Map<string, Notice>()
121
122const FAMILIES = 'fable|mythos|opus|sonnet|haiku'
123const FAMILY_THEN_VERSION = new RegExp(`(${FAMILIES})[-_ ]?(\\d{1,2})(?!\\d)(?:[-.](\\d{1,2})(?!\\d))?`)
124const VERSION_THEN_FAMILY = new RegExp(`claude-(\\d)(?:[-.](\\d))?-(${FAMILIES})`)
125const FAMILY_ONLY = new RegExp(`(${FAMILIES})`)
126const OPAQUE_BEDROCK_ARN = /^arn:aws[\w-]*:bedrock:/
127
128const versioned = (family: string, major: string, minor: string | undefined) =>
129  `${family.toUpperCase()} ${minor === undefined ? major : `${major}.${minor}`}`
130
131function modelLabel(model: string): string {
132  const routed = model.toLowerCase()
133  const id = routed.split('/').at(-1) ?? routed
134  const familyFirst = FAMILY_THEN_VERSION.exec(id)
135  if (familyFirst !== null) return versioned(familyFirst[1] ?? '', familyFirst[2] ?? '', familyFirst[3])
136  const versionFirst = VERSION_THEN_FAMILY.exec(id)
137  if (versionFirst !== null) return versioned(versionFirst[3] ?? '', versionFirst[1] ?? '', versionFirst[2])
138  const family = FAMILY_ONLY.exec(id)?.[1]
139  if (family !== undefined) return family.toUpperCase()
140  if (OPAQUE_BEDROCK_ARN.test(routed)) return 'BEDROCK'
141  const name = id
142    .replace(/\[.*\]$/, '')
143    .replace(/@.*$/, '')
144    .replace(/-v\d+(:\d+)?$/, '')
145    .replace(/^([a-z]+\.)+/, '')
146  return name.replace(/[^a-z0-9.\-/ ]/g, '-').toUpperCase()
147}
148
149async function currentBranch($: EngineInterface, cwd: string): Promise<string | undefined> {
150  const git = (...args: string[]) => $.process.run(['git', ...args], { cwd, timeoutMs: 2000 }).catch(() => undefined)
151  const branch = await git('symbolic-ref', '--short', '-q', 'HEAD')
152  if (branch?.exitCode === 0) return branch.stdout.trim()
153  const detached = await git('rev-parse', '--short', 'HEAD')
154  return detached?.exitCode === 0 ? `HEAD@${detached.stdout.trim()}` : undefined
155}
156
157const isRecord = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null
158
159function promptTextOf(content: unknown): string | undefined {
160  if (typeof content === 'string') return content
161  const first = Array.isArray(content) ? content.find(isRecord) : undefined
162  return first?.type === 'text' && typeof first.text === 'string' ? first.text : undefined
163}
164
165function userEntryKind(text: string | undefined): EntryKind {
166  if (text === undefined) return 'output'
167  if (text.startsWith(BOOT_RECORD_TEXT)) return 'boot'
168  if (text.startsWith('<command-name>')) return 'command'
169  if (text.startsWith('<bash-input>')) return 'shell'
170  if (/^\s*<(?:bash-|local-command)/.test(text)) return 'output'
171  return 'prompt'
172}
173
174function transcriptEntryOf(line: string): TranscriptEntry | undefined {
175  let value: unknown
176  try {
177    value = JSON.parse(line)
178  } catch {
179    return undefined
180  }
181  if (!isRecord(value) || typeof value.uuid !== 'string' || typeof value.type !== 'string' || !CHAT_ENTRY_TYPES.has(value.type)) return undefined
182  const parent = typeof value.parentUuid === 'string' ? value.parentUuid : null
183  if (value.isMeta === true) return { uuid: value.uuid, parent, kind: 'meta' }
184  if (value.type === 'system') return { uuid: value.uuid, parent, kind: 'output' }
185  if (value.type === 'assistant') return { uuid: value.uuid, parent, kind: 'reply' }
186  return { uuid: value.uuid, parent, kind: userEntryKind(isRecord(value.message) ? promptTextOf(value.message.content) : undefined) }
187}
188
189async function resumedAnchorOf($: EngineInterface, transcriptPath: string): Promise<Anchor | undefined> {
190  const head = await $.process.run(['head', '-c', String(TRANSCRIPT_HEAD_BYTES), transcriptPath], { timeoutMs: 2000 }).catch(() => undefined)
191  if (head?.exitCode !== 0) return undefined
192  const entries = head.stdout.split('\n').flatMap(line => transcriptEntryOf(line) ?? [])
193  const firstChildOf = new Map(entries.toReversed().flatMap(entry => (entry.parent === null ? [] : [[entry.parent, entry] as const])))
194  let recordsAbove = 0
195  for (let entry = entries.find(candidate => candidate.parent === null); entry !== undefined; entry = firstChildOf.get(entry.uuid)) {
196    if (entry.kind === 'boot') return { row: 'boot', recordsAbove }
197    if (entry.kind === 'prompt') return recordsAbove === 0 ? { row: 'first prompt', id: entry.uuid } : undefined
198    if (entry.kind === 'command') recordsAbove += 1
199    if (entry.kind === 'shell' || entry.kind === 'reply') return undefined
200  }
201  return undefined
202}
203
204const isCommandRecord = (message: SessionMessage) => message.text.startsWith('<command-name>/')
205
206const isBootRecord = (message: SessionMessage) => message.text.startsWith(BOOT_RECORD_TEXT)
207
208const isWide = (char: string) => /[\u3000-\u30ff]/.test(char)
209
210const cellsOf = (text: string) => [...text].reduce((sum, char) => sum + (isWide(char) ? 2 : 1), 0)
211
212const width = (line: Line) => line.reduce((sum, piece) => sum + cellsOf(piece.text), 0)
213
214const span = (text: string, style?: Style): Span => ({ text, style })
215
216const rule = (cells: number): Span => span('_'.repeat(Math.max(cells, 1)), DIM)
217
218const shortened = (text: string, cells: number) => (text.length <= cells ? text : `${text.slice(0, cells - 1)}…`)
219
220const runDigits = (id: string) => [...id.replace(/[^0-9a-f]/gi, '')].map(digit => Number.parseInt(digit, 16))
221
222const runCode = (id: string) => {
223  const hex = id.replace(/[^0-9a-f]/gi, '').toUpperCase()
224  return `${hex.slice(0, 4)}-${hex.slice(4, 8)}`
225}
226
227function dotMatrix(text: string): string[] {
228  const letters = [...text.toUpperCase()].slice(0, CARD_COLUMNS / DOT_MATRIX_PITCH)
229  const glyphs = letters.map(letter => DOT_MATRIX_FONT[letter]?.split('|') ?? [])
230  const isLit = (x: number, y: number) => glyphs[Math.floor(x / 6)]?.[y - 1]?.[x % 6] === '#'
231  return [0, 1].map(row =>
232    Array.from({ length: glyphs.length * DOT_MATRIX_PITCH }, (_, cell) => {
233      const dots = BRAILLE_DOTS.flatMap((pair, dy) => pair.filter((_, dx) => isLit(cell * 2 + dx, row * 4 + dy)))
234      return dots.length === 0 ? ' ' : String.fromCharCode(BRAILLE_BLANK + dots.reduce((sum, dot) => sum + dot, 0))
235    })
236      .join('')
237      .trimEnd(),
238  )
239}
240
241const wordmarkRow = (row: string): Line => [
242  span(row.slice(0, SLOP_COLUMNS), { color: VOLT }),
243  span(row.slice(SLOP_COLUMNS), { color: BONE }),
244]
245
246function tagStrip(id: string): Line {
247  const digits = runDigits(id)
248  const tagline = ` ${TAGLINES[(digits[0] ?? 0) % TAGLINES.length]} `
249  const barcode = Array.from({ length: BARCODE_COLUMNS }, (_, i) => BARS[(digits.at(-1 - i) ?? i) % BARS.length]).join('')
250  const hazard = '╱'.repeat(WORDMARK_COLUMNS - tagline.length - barcode.length - 2)
251  return [span(tagline, { color: INK, backgroundColor: VOLT, bold: true }), span(` ${hazard} `, MARK), span(barcode, DIM)]
252}
253
254function modelCard({ model, branch }: Run): Line[] {
255  const header = [span('01', { ...MARK, bold: true }), span(' // ', DIM), span('MODEL', PLAIN), span(' ')]
256  const branchLabel = [span('BRANCH', PLAIN), span(' // ', DIM)]
257  const branchName =
258    branch === undefined ? span(NO_GIT, DIM) : span(shortened(branch, CARD_COLUMNS - width(branchLabel) - 2), { ...PLAIN, bold: true })
259  const footer = [...branchLabel, branchName, span(' ')]
260  return [
261    [...header, rule(CARD_COLUMNS - width(header))],
262    ...dotMatrix(model).map(row => [span(row, { color: VOLT })]),
263    [...footer, rule(CARD_COLUMNS - width(footer))],
264  ]
265}
266
267function microLine({ id, version }: Run): Line {
268  const left = [span('+ ', MARK), span('SESSION ', DIM), span(runCode(id), PLAIN), span(' _ BUILD ', DIM), span(version, PLAIN), span(' ')]
269  const right = [span(` ${KATAKANA}`, DIM), span(' +', MARK)]
270  return [...left, rule(PLATE_COLUMNS - width(left) - width(right)), ...right]
271}
272
273const detailSpans = ({ model, branch, version }: Run): Line[] => [
274  [span('MODEL', PLAIN), span(' // ', DIM), span(model, { color: VOLT })],
275  [span('BRANCH', PLAIN), span(' // ', DIM), branch === undefined ? span(NO_GIT, DIM) : span(branch, { ...PLAIN, bold: true })],
276  [span('BUILD', PLAIN), span(' // ', DIM), span(version, DIM)],
277]
278
279function bannerLines(columns: number, current: Run | undefined): Line[] {
280  const wordmark = WORDMARK.map(wordmarkRow)
281  if (current === undefined) return wordmark
282  if (columns >= PLATE_COLUMNS) {
283    const card = modelCard(current)
284    const left = [...wordmark, tagStrip(current.id)]
285    return [...left.map((line, i) => [...line, span(COLUMN_GAP), ...(card[i] ?? [])]), microLine(current)]
286  }
287  if (columns >= WORDMARK_COLUMNS) {
288    const details = detailSpans(current).flatMap((line, i) => (i === 0 ? line : [span('   '), ...line]))
289    return [...wordmark, tagStrip(current.id), [span('+ ', MARK), ...details]]
290  }
291  const spacedName = [span(SPACED_SLOP, { color: VOLT, bold: true }), span(SPACED_OTHON, { color: BONE, bold: true })]
292  return [spacedName, ...detailSpans(current)]
293}
294
295function clipToColumns(line: Line, columns: number): Line {
296  let room = columns
297  const clipped: Line = []
298  for (const piece of line) {
299    let text = ''
300    for (const char of piece.text) {
301      if (cellsOf(char) > room) break
302      text += char
303      room -= cellsOf(char)
304    }
305    clipped.push({ ...piece, text })
306    if (text.length < piece.text.length) break
307  }
308  return [...clipped, span(' '.repeat(room))]
309}
310
311const drawLine = ({ Text }: TerminalElements, line: Line) =>
312  Text({ wrap: 'truncate-end', children: line.map(piece => Text({ ...piece.style, children: [piece.text] })) })
313
314const drawNotice = ({ Box, Text }: TerminalElements, { text, command }: Notice) =>
315  Box({
316    flexDirection: 'row',
317    children: [
318      Text({ dimColor: true, children: ['▎ '] }),
319      Text({ dimColor: true, children: [command === null ? text : `${text} ${command}`] }),
320    ],
321  })
322
323function coverOver(elements: TerminalElements, columns: number, rowsToLogo: number, below: RenderNode[]) {
324  const blank = (count: number): Line[] => Array.from({ length: count }, () => [])
325  const banner = bannerLines(columns, run)
326  const cover = [...blank(SLACK_ROWS), ...banner, ...blank(rowsToLogo - banner.length)]
327  return elements.Box({
328    flexDirection: 'column',
329    marginTop: -(SLACK_ROWS + rowsToLogo),
330    children: [...cover.map(line => drawLine(elements, clipToColumns(line, columns))), ...below],
331  })
332}
333
334const noticeRows = (elements: TerminalElements) => [...notices.values()].map(notice => drawNotice(elements, notice))
335
336async function settleBanner($: EngineInterface, cwd: string, start: 'startup' | 'clear' | 'resume', resumedId?: string) {
337  const branchRead = currentBranch($, cwd)
338  const [messages, settings, version, model, id] = await Promise.all([
339    $.session.messages(),
340    $.settings.read(),
341    $.session.version(),
342    $.session.model(),
343    resumedId ?? $.session.id(),
344    $.command.register({ name: COMMAND, description: 'Draw the SLOPOTHON banner' }),
345  ])
346  const bootIndex = messages.findIndex(isBootRecord)
347  const isBooting = isInteractive && start !== 'resume' && bootIndex === -1 && settings.tui === 'fullscreen' && (start === 'clear' || messages.length === 0)
348  const recordsAbove = bootIndex === -1 ? messages.length : bootIndex
349  const hasBanner = (isBooting || bootIndex !== -1) && messages.slice(0, recordsAbove).every(isCommandRecord)
350  const showRun = (branch: string | undefined) => {
351    run = { version: version.version, model: modelLabel(model), branch, id }
352    $.ui.invalidate('ui.render')
353  }
354  const isResumed = start === 'resume' || (messages.length > 0 && resumedAnchor !== undefined)
355  anchor = isResumed ? resumedAnchor : hasBanner ? { row: 'boot', recordsAbove } : undefined
356  showRun(undefined)
357  await Promise.all([isBooting ? $.command.run({ command: COMMAND }) : undefined, branchRead.then(showRun)])
358}
359
360export const register: Register = on => {
361  on('session.start', async ($, e, next) => {
362    isInteractive = e.isInteractive
363    await settleBanner($, e.cwd, 'startup')
364    return next(e)
365  })
366
367  on('classic.SessionStart', async ($, e, next) => {
368    const started = await next(e)
369    if (e.source === 'clear') {
370      resumedAnchor = undefined
371      await settleBanner($, e.cwd, 'clear')
372    }
373    if (e.source === 'resume') {
374      resumedAnchor = await resumedAnchorOf($, e.transcript_path)
375      await settleBanner($, e.cwd, 'resume', e.session_id)
376    }
377    return started
378  })
379
380  on('command.run', { command: COMMAND }, async ($, e) => {
381    if (e.origin.kind === 'plugin' && e.origin.name === PLUGIN) return { text: BOOT_TEXT }
382    const branch = await currentBranch($, await $.session.cwd())
383    if (run !== undefined) run = { ...run, branch }
384    return { text: SHOW_TEXT }
385  })
386
387  on('ui.render', { component: 'InfoNotice' }, ($, e, next) => {
388    if (e.surface !== 'terminal' || e.viewport?.isFullscreen !== true || anchor === undefined) return next(e)
389    if (!notices.has(e.requestId)) {
390      notices.set(e.requestId, { text: e.props.text, command: e.props.command })
391      $.ui.invalidate('ui.render')
392    }
393    const { Box } = $.ui.resolve(e)
394    return Box({})
395  })
396
397  on('ui.render', { component: 'CommandOutput', props: { command: COMMAND } }, ($, e, next) => {
398    if (e.surface !== 'terminal') return next(e)
399    if (e.props.text.endsWith(SHOW_TEXT)) {
400      const elements = $.ui.resolve(e)
401      const columns = e.viewport?.columns ?? UNMEASURED_COLUMNS
402      return elements.Box({
403        flexDirection: 'column',
404        children: bannerLines(columns, run).map(line => drawLine(elements, clipToColumns(line, columns))),
405      })
406    }
407    if (e.viewport?.isFullscreen !== true || !e.props.text.endsWith(BOOT_TEXT)) return next(e)
408    const elements = $.ui.resolve(e)
409    const recordsAbove = anchor?.row === 'boot' ? anchor.recordsAbove : 0
410    const rowsToLogo = ROWS_FROM_LOGO_TO_BOOT_ROW + ROWS_PER_RECORD_ABOVE_BOOT_ROW * recordsAbove
411    const emptyRow = elements.Text({ children: [' '] })
412    return coverOver(elements, e.viewport.columns, rowsToLogo, notices.size === 0 ? [emptyRow] : noticeRows(elements))
413  })
414
415  on('ui.render', { component: 'UserMessage' }, async ($, e, next) => {
416    const isFirstPrompt = anchor?.row === 'first prompt' && anchor.id === e.requestId
417    if (e.surface !== 'terminal' || e.viewport?.isFullscreen !== true || e.props.isExpanded || !isFirstPrompt) return next(e)
418    const elements = $.ui.resolve(e)
419    return coverOver(elements, e.viewport.columns, ROWS_FROM_LOGO_TO_FIRST_PROMPT, [...noticeRows(elements), await next(e)])
420  })
421}
422