Skip to content
joinery / docs

Overview

863 words ยท updated 6 hours agoinfrastructure/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
ScriptCommandWhat it's for
devpnpm devPicking which project to start, and installing the workspace first on a fresh clone
issue addpnpm issue:addPicking a project and label, then filing an issue with gh
issue pickpnpm issue:pickPicking an open issue off a project board, then branching off it and self-assigning
issue briefpnpm issue:briefPrinting an issue with its comments, blockers, decisions, projects and linked docs
shippnpm issue:shipPushing the current branch, opening or reusing its PR, arming auto-merge, then blocking on checks
ci-failurespnpm ci:failuresReporting a PR's failed checks, each Actions job cut to its error lines
worktreepnpm worktree:prepareCopying env files into a linked worktree and installing it the way CI does
env-syncpnpm env:syncKeeping each .env in its .env.example's order and comments, creating missing ones
workflowpnpm workflow:setup, workflow:sync, workflow:next, workflow:file, workflow:dropManaging a workflow project: set up, snapshot, list what's ready, file tickets, drop
brandpnpm brand:extract, brand:contrastReading a live site's brand, and checking a token file's contrast
driftpnpm docs:driftWarning when a changed project's docs look stale, and offering to file it
mappnpm docs:mapRendering the feature index, and asserting in CI that it's current
invariantspnpm invariants:checkThe repo rules every author is held to, run by hooks and CI
usagepnpm usage:flushMoving the runs every script records into the committed log; the pre-commit hook runs it
coverage-reportpnpm 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) from io.ts before the first one, with a hint naming the arguments that make the prompt unnecessary. pnpm issue:pick with 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.ts in 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/ with index.ts, main.ts, adapters/, domain/ and a README.md, a line in this package's scripts (pnpm --silent cli src/<name>/index.ts) and a row in the table above.
  • Every index.ts is the same five lines; only dev/index.ts differs, since it runs before pnpm install:
#!/usr/bin/env node
import { run } from "../shared/cli.ts";
import { main } from "./main.ts";

await run(main);
  • run owns exit codes: CancelledError exits 0, ExpectedError prints its message and exits 1, anything else prints a stack. Never call process.exit.
  • Code two scripts need moves to shared/. Scripts never import each other.
  • Entries run on plain node with type stripping, so internal imports use the .ts extension.
  • Real logic (parsers, diffs, formatting) goes in its own file with a spec; prompts and gh calls aren't unit-tested.
  • Don't name a folder coverage/ or types/: both are in ESLint's baseIgnores and would go unlinted.

Requirements

ScriptNeeds
issue/, ship/, drift/, workflow/, ci-failures/gh installed and logged in
ship/The repo's Allow auto-merge setting on
brand:extractPlaywright's Chromium and the network