Files
ai-for-dummies/.agents/scripts/launch.sh
T
Marcos Paulo 48c31dc1b3 build: migrate from npm to pnpm
Ten git worktrees each carried their own 225 MB node_modules (1.1 GB across
five) and paid 11s per `npm ci`. pnpm hardlinks from a shared store: the same
five worktrees cost ~250 MB total, and a fresh install is 4s.

What changed beyond the mechanical rename:

- `overrides` moved to `pnpm-workspace.yaml`. pnpm 11 does not read the `pnpm`
  field in package.json *or* npm's top-level `overrides`, and it fails silently
  — the vite/defu/language-server pins would have quietly stopped applying.
- Build scripts are blocked by default in pnpm; esbuild and sharp are allowed
  explicitly via `allowBuilds` (renamed from `onlyBuiltDependencies` in 11).
- `packageManager` + `engines` pin the toolchain.
- gate.sh rejects a package-lock.json/yarn.lock/bun.lock outright, so an agent
  running `npm install` out of habit fails loudly instead of building a second,
  divergent dependency tree.
- CI bootstraps pnpm with `npm install --global pnpm@11.25.0` rather than
  corepack (unbundled as of Node 25) or pnpm/action-setup (this self-hosted
  act-runner has never run a job; fetching a third-party action is not
  something to discover on the first one).

Two pre-existing CI bugs fixed while in the file:

- the gate installed with `npm install --package-lock=false`, which discarded
  the lockfile the previous session had just fixed.
- the visual-regression step imported `playwright`, which is not a dependency,
  and `visual-regression.mjs` has no compare mode anyway — in CI it overwrote
  its own baselines and passed unconditionally. Removed with a comment; it
  comes back when it can diff.

The `publish` job is now manual (`workflow_dispatch`). During the migration
dist/ holds three HTML files against the live pages branch's ten, so publishing
on every push to main would take the site down to a stub. Restore at task 20.

HANDOVER.md's incident log still says npm where it describes what happened at
the time; that is history, not a missed rename.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-05 04:29:42 +00:00

133 lines
4.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Launch one refactor task in its own worktree, on the CLI its brief routes it to.
#
# .agents/scripts/launch.sh 01 scaffold
# .agents/scripts/launch.sh 02 tokens --base refactor/task-01-scaffold
# .agents/scripts/launch.sh 07 primitives --cli mm --fg
#
# Routing comes from plans/astro-refactor/MODEL-ROUTING.md. Override with --cli.
# All three CLIs are launched with their permission prompts disabled: these run
# unattended inside a worktree, and a blocked edit or bash call just hangs.
set -euo pipefail
cd "$(git rev-parse --show-toplevel)"
number=${1:?usage: launch.sh <task-number> <slug> [--base ref] [--cli codex|agy|mm] [--fg]}
slug=${2:?slug, e.g. scaffold}
shift 2
base="main"
cli=""
foreground=0
while [ $# -gt 0 ]; do
case "$1" in
--base) base=$2; shift 2 ;;
--cli) cli=$2; shift 2 ;;
--fg) foreground=1; shift ;;
*) echo "unknown flag: $1" >&2; exit 2 ;;
esac
done
# Model routing. Codex takes the long iterate-until-green loops, Gemini the two
# tasks that need whole-corpus context plus visual judgement, MiniMax the rest.
if [ -z "$cli" ]; then
case "$number" in
01|03|15|16|19) cli=codex ;;
02|18) cli=agy ;;
*) cli=mm ;;
esac
fi
dir="../af-task-${number}"
branch="refactor/task-${number}-${slug}"
plan="plans/astro-refactor/task-${number}-${slug}.md"
log="$(pwd)/.agents/logs/task-${number}-${slug}.log"
[ -f "$plan" ] || { echo "no plan at $plan — check the number and slug" >&2; exit 1; }
mkdir -p .agents/logs
# The brief names its own agent; pull it out so the prompt can point at the file.
# [a-z0-9-] not [a-z-]: content-i18n-migrator has digits in it.
agent=$(sed -n 's/.*\*\*Agent\*\*: `\([a-z0-9-]*\)`.*/\1/p' "$plan" | head -1)
[ -n "$agent" ] || { echo "could not read the agent name out of $plan" >&2; exit 1; }
[ -f ".agents/agents/${agent}.md" ] || { echo "no such agent: .agents/agents/${agent}.md" >&2; exit 1; }
if [ -d "$dir" ]; then
echo "worktree $dir already exists — reusing it"
else
git worktree add "$dir" -b "$branch" "$base"
fi
# pnpm install works only once task 01 has produced a lockfile. The pre-existing root
# package.json carries two scripts and no dependencies, so before task 01 there
# is no toolchain to install and no hooks to verify.
if [ -f "$dir/pnpm-lock.yaml" ]; then
( cd "$dir" && pnpm install --frozen-lockfile && .agents/scripts/verify-hooks.sh )
fi
prompt=$(cat <<PROMPT
You are the \`${agent}\` specialist on the ai-for-dummies Astro refactor.
You are working alone in the git worktree at $(cd "$dir" && pwd), on branch ${branch}.
Read these, in this order, before you write anything:
1. AGENTS.md — project entry point and the "never touch" list
2. .agents/agents/${agent}.md — your role, what you own, what you must not do
3. ${plan} — your task brief: scope, steps, done-when, do-not
4. every file the brief and your agent definition tell you to read
(.agents/context/*, .agents/rules/*, .agents/skills/*, .agents/checklists/*)
Then do the task. Rules that override your own judgement:
- Stay inside the scope in the brief. Do not do work belonging to another task.
- Honour every "Do not" line in the brief and in your agent definition.
- The site must look and read exactly as it does today. This is a refactor,
not a redesign. If you find something that looks like a bug in the current
design, write it down in the final report — do not fix it.
- Never delete or weaken an assertion in scripts/verify.mjs to make a suite
green. Only the verification-engineer may reduce assertion count, with a
written reason per removal.
- Commit as you go with conventional-commit messages. The commit-msg and
pre-commit hooks are live; if a hook rejects you, fix the cause, never
bypass with --no-verify.
- Work through the done-when checklist at the end and actually run each check.
Finish by printing: what you changed, which done-when boxes are genuinely
ticked, which are not and why, and anything the next task needs to know.
PROMPT
)
echo "task : ${number} ${slug}"
echo "agent : ${agent}"
echo "cli : ${cli}"
echo "worktree: ${dir} (branch ${branch}, from ${base})"
echo "log : ${log}"
echo
run() {
case "$cli" in
codex)
codex exec --dangerously-bypass-approvals-and-sandbox --skip-git-repo-check \
-C "$dir" "$prompt"
;;
agy)
( cd "$dir" && agy --dangerously-skip-permissions \
--model gemini-3.1-pro-high --print-timeout 4h -p "$prompt" )
;;
mm)
( cd "$dir" && mm --dangerously-skip-permissions \
--model opus -p "$prompt" )
;;
*) echo "unknown cli: $cli" >&2; exit 2 ;;
esac
}
if [ "$foreground" = 1 ]; then
run 2>&1 | tee "$log"
else
export cli dir prompt
nohup bash -c "$(declare -f run); run" >"$log" 2>&1 &
echo "launched in background, pid $!"
echo "follow: tail -f $log"
fi