diff --git a/.agents/scripts/launch.sh b/.agents/scripts/launch.sh new file mode 100755 index 0000000..bf51c11 --- /dev/null +++ b/.agents/scripts/launch.sh @@ -0,0 +1,129 @@ +#!/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 [--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. +agent=$(sed -n 's/.*\*\*Agent\*\*: `\([a-z-]*\)`.*/\1/p' "$plan" | head -1) +: "${agent:=astro-architect}" + +if [ -d "$dir" ]; then + echo "worktree $dir already exists — reusing it" +else + git worktree add "$dir" -b "$branch" "$base" +fi + +# npm ci only once task 01 has produced a package.json. Before that there is no +# toolchain to install, and no hooks to verify. +if [ -f "$dir/package.json" ]; then + ( cd "$dir" && npm ci --prefer-offline && .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 diff --git a/.gitignore b/.gitignore index da58ac1..450c2fd 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,6 @@ dist/ # the per-run captures and diffs are not. .agents/snapshots/after/ .agents/snapshots/diff/ + +# agent run logs +.agents/logs/