Overview
infrastructure/scripts/README.md๐ค @joinery/scripts
The repo's CLI toolbox: dev startup, issue workflows, doc checks and repo gates. Nothing imports it; every script is run by hand, a hook or CI.
โ ๏ธ This is a mostly vibe-coded app, with low human intervention. Why: it's purely a DX tool. I do not have the resources to properly build and maintain this, so I went for the quick and easy shortcut.
One folder per script under src/, each with its own README. This one covers what they share.
Structure
Every script folder has the same four things:
index.ts the entry point. Hands its commands to run() and does nothing else
main.ts the command โ or one file per subcommand, named after it, the way issue/ has add + pick
adapters/ one file per boundary out: git.ts, gh.ts, nx.ts, files.ts, prompts.ts, io.ts
domain/ pure functions and their types. No fs, no subprocess, no clack, no process
| Script | Command | What it's for |
|---|---|---|
dev | pnpm dev | Picking which project to start, and installing the workspace first on a fresh clone |
issue add | pnpm issue:add | Picking a project and label, then filing an issue with gh |
issue pick | pnpm issue:pick | Picking an open issue off a project board, then branching off it and self-assigning |
issue brief | pnpm issue:brief | Printing an issue with its comments, blockers, decisions, projects and linked docs |
ship | pnpm issue:ship | Pushing the current branch, opening or reusing its PR, arming auto-merge, then blocking on checks |
ci-failures | pnpm ci:failures | Reporting a PR's failed checks, each Actions job cut to its error lines |
worktree | pnpm worktree:prepare | Copying env files into a linked worktree and installing it the way CI does |
env-sync | pnpm env:sync | Keeping each .env in its .env.example's order and comments, creating missing ones |
workflow | pnpm workflow:setup, workflow:sync, workflow:next, workflow:file, workflow:drop | Managing a workflow project: set up, snapshot, list what's ready, file tickets, drop |
brand | pnpm brand:extract, brand:contrast | Reading a live site's brand, and checking a token file's contrast |
drift | pnpm docs:drift | Warning when a changed project's docs look stale, and offering to file it |
map | pnpm docs:map | Rendering the feature index, and asserting in CI that it's current |
invariants | pnpm invariants:check | The repo rules every author is held to, run by hooks and CI |
usage | pnpm usage:flush | Moving the runs every script records into the committed log; the pre-commit hook runs it |
coverage-report | pnpm test:coverage (root) | Merging every project's coverage into one browsable HTML report |
Run by agents, not only by people
An agent's shell has no terminal, so isTTY is false and out prints plain lines. Two rules
follow for every script:
- A prompt never runs without a terminal. Call
requireTerminal(hint)fromio.tsbefore the first one, with a hint naming the arguments that make the prompt unnecessary.pnpm issue:pickwith no number fails that way at once; with a number it asks nothing. - A command that reports a failure exits 1.
Which way imports go
index.ts โ the command โ adapters/ โ domain/. Never back up, and never sideways into another
script's folder. One scoped exception: a command may import another command in the same folder,
which is what keeps add.ts calling pick.ts legal โ the alternative puts that prompt in the
dispatcher. shared/ is reachable from anywhere and reaches nothing.
- An adapter is named after the boundary it wraps, so
git.tsin several folders isn't duplication. - Every side effect lives in
adapters/.
eslint.pureDomain enforces the domain/
half; the rest is convention. 0004 has the
reasoning.
Adding a script
The scripts-new-script skill has the steps. The rules:
- A folder under
src/withindex.ts,main.ts,adapters/,domain/and aREADME.md, a line in this package'sscripts(pnpm --silent cli src/<name>/index.ts) and a row in the table above. - Every
index.tsis the same five lines; onlydev/index.tsdiffers, since it runs beforepnpm install:
#!/usr/bin/env node
import { run } from "../shared/cli.ts";
import { main } from "./main.ts";
await run(main);
runowns exit codes:CancelledErrorexits 0,ExpectedErrorprints its message and exits 1, anything else prints a stack. Never callprocess.exit.- Code two scripts need moves to
shared/. Scripts never import each other. - Entries run on plain
nodewith type stripping, so internal imports use the.tsextension. - Real logic (parsers, diffs, formatting) goes in its own file with a spec; prompts and
ghcalls aren't unit-tested. - Don't name a folder
coverage/ortypes/: both are in ESLint'sbaseIgnoresand would go unlinted.
Requirements
| Script | Needs |
|---|---|
issue/, ship/, drift/, workflow/, ci-failures/ | gh installed and logged in |
ship/ | The repo's Allow auto-merge setting on |
brand:extract | Playwright's Chromium and the network |