#!/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 four 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 [--base ref] [--cli codex|agy|mm|oc] [--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 <&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