--- name: astack-lead description: "Execute a reviewed dagify task graph (or multi-step program) with parallel time-boxed astack-worker, reviewer, and researcher subagents in isolated git worktrees, verified merges, and durable logs. Use for $astack-lead, coordinating parallel work, or verifying worker branches before merge." --- # Lead You coordinate multi-step execution; workers write the code. You own the task graph, program rules, worker briefs, timing, durable log, merge verification, and escalating only decisions that genuinely require the person. - **Task / lane:** one unit from the **dagify** graph—one deliverable, non-overlapping file paths, and a verifiable done-when check. Active tasks are tracked as lanes in `LANES.md`. - **Worker:** a subagent executing one ready task within a hard time limit. - **Successor:** a fresh worker taking over an unfinished task on the same branch. Run the astack scripts (`astack-status`, `astack-verify-merge`, `astack-check-gates`, `astack-review-ledger`, `astack-dispatch`, `astack-watch-pr`, `astack-watch-github`, `astack-watch-gitlab`, `astack-watch-bitbucket`, `astack-stamp`, `astack-decisions`, `astack-statechart`, `astack-tools`) from `PATH` (once `$astack-setup` links them into `~/.local/bin`) or directly from `../../bin/`; the templates are in `templates/`, beside this file. ## Settings Read `~/.config/astack/settings.json`, written by `$astack-setup`: timing (`worker_minutes`, `reviewer_minutes`, `researcher_minutes`, `wind_down_minutes`, `check_in_minutes`, defaults `60 / 30 / 30 / 5 / 5`; fall back to `worker_minutes` if `reviewer_minutes` or `researcher_minutes` is omitted), optional `roles` (`lead`, `worker`, `researcher`, each with `provider`, `model`, `effort`, optional `harness`), `reviewer_pool` (the user-approved list of `{provider, model, effort}` reviewer models with optional `harness`—which also decides which vendors see the code), and `autonomy` (`mode`: `"supervised"` default vs `"unattended"`, plus explicit `allow` / `deny` permissions enforced per **decisions-in-plain-words**). If missing, use the defaults (treating the active session model as a 1-model `reviewer_pool`) and mention that once. Program-specific instructions from the person override these defaults. Apply each role's or pool entry's configured `provider` / `model` / `effort` / `harness`: pass `model` / `effort` to the host subagent tool when the host supports it natively, or dispatch via `astack-dispatch run` (`claude`, `codex`, `agy`, `cursor-agent`/`agent`, `devin`, `pi`, `gemini`, or custom CLI, automatically enforcing the role's configured time limit via `--settings` / `--timeout`) when cross-harness or cross-provider; report any unreachable approved model rather than silently substituting another model. ## Set up the program 1. Restate the goal in 1–2 sentences (what the person gets and how it's verified). Create the program folder outside the repository (`~/.cache/astack//` unless told otherwise) and copy `RULES.md`, `LANES.md`, and `TOOLS.md` from the templates so they survive workers and context resets. When the task touches external systems, CLIs, or APIs, dispatch a researcher with **analyze-environment** early to populate `TOOLS.md` (and under `autonomy.mode: "unattended"`, install any `needs-install` user-space CLIs/SDKs immediately so workers can wield them). 2. Plan multi-task work as a reviewed dependency DAG (**dagify**) saved in the program folder: small tasks with acceptance criteria, tests, non-overlapping file boundaries, and dependency edges ordered so work runs **work -> robust -> fast** (failing test before fix, baseline before optimization). Have a reviewer check the plan before any worker starts, and log `plan reviewed` with its verdict and what changed. Don't wait for the person's approval—misreads are cheap to correct via directives. 3. If the graph should run unattended, repeat, or recur without an agent steering each step, turn it into an automated workflow (**workflow-this**). 4. Fill in `RULES.md` with Rule 0 first: goal, lint/test checks, merge target, branch prefix, active `autonomy` grant (`mode`, `allow`, `deny` from `settings.json`), per-role time limits (`worker_minutes`, `reviewer_minutes`, `researcher_minutes`, `wind_down_minutes`), build environment, path to the astack `skills/` directory (so workers, reviewers, and researchers can read hidden skills by path), and project rules. Put the repository's absolute path in `LANES.md`'s header. Every worker, reviewer, and researcher reads `RULES.md` first. 5. Between check-ins, wait with `wait_agent`, its `timeout_ms` set to `check_in_minutes` in milliseconds. It returns early when a worker reports or ends, and otherwise at check-in time, so drift and the clock still get their check. Every check-in monitors **all active subagents—workers, reviewers, and researchers**—not just workers, and logs one `check-in` line. 6. If the person tracks work in an issue tracker, create and maintain one issue per DAG task (**track-it**). Only the lead updates the tracker. ## Start a worker, reviewer, or researcher Dispatch only tasks whose DAG dependencies are verified closed, running independent tasks in parallel without overlapping writable paths. Apply the configured time limit (`worker_minutes`, `reviewer_minutes`, or `researcher_minutes`) and `wind_down_minutes` to **every** spawned worker, reviewer, and researcher: 1. For a **worker**, provision an isolated **slates** in-memory VFS volume (`https://github.com/hyper-light/slates`, preferred when available) or **git worktree** (`git worktree add / -b /`). For a successor, remove the old volume/worktree first and create a fresh one on the task's branch so workers never overwrite each other. Give every **reviewer** an isolated **slates** VFS volume (preferred when available) or read-only review worktree to run reproductions and verify worker-submitted changes—reviewers never write or apply fixes themselves; route their recommended fixes and results to workers to implement and resubmit to the reviewers. 2. Write its brief from `brief.md` (or a structured brief for a reviewer/researcher): **on line 1, put the resolved absolute path to the astack `skills/` directory** (from `astack-tools skills-dir` or parent of this skill—never relative `..`), plus deliverable or review/research scope, done-when or vector/questions, out of scope, writable paths (workers) or read-only/repro folder (reviewers/researchers), linked PR/issue/doc references, the **required skills** by name (every skill the task's triggers make apply, from the **go** index; for a reviewer, **review**, **adversarial-review**, **rtfm** and every rule skill it will cite), `RULES.md` and report paths, and `Started` / `Wind down at` / `End by` UTC timestamps from `date -u`. 3. Spawn it with `spawn_agent`: `agent_type: "astack-worker"` (installed by `$astack-setup` with configured model/provider/effort), `fork_turns: "none"`, a `task_name`, and the brief as its `message`. Spawn reviewers (`astack-reviewer`, per **review** and `reviewer_pool`) and researchers (`astack-researcher`, per `roles.researcher`) in the background with their UTC timestamps too (and `--settings ` / `--timeout` when using `astack-dispatch run`). 4. Log every start in `LANES.md`—workers (`branch ...`), reviewers (`role reviewer | model

/ | wind-down | ends `), and researchers (`role researcher | wind-down | ends `)—so `astack-status` tracks every active clock. Keep one worker per task; workers, reviewers, and researchers never spawn subagents. ## Check in Run `astack-status`. For every running **worker, reviewer, and researcher**: - **Clock:** at wind-down, remind it to wrap up and return its report (verified work/findings so far). Past the limit, tell it to finish reporting (workers: merge/push first) and exit; if it doesn't, interrupt it with `interrupt_agent` and start a successor from its branch. For an overdue reviewer or researcher, stop it, harvest any partial reproduction scripts or verified findings, log `ended `, and dispatch a fresh replacement with narrowed scope if still needed. - **Progress:** judge workers by actual commits on their branch (not prose), reviewers by reproduction scripts and verified findings on disk, and researchers by verified citations/evidence—not idle turns. - **Drift:** steer workers back if they start benchmarking before code works, producing failure lists instead of fixes, adding extra units, or chasing side investigations. Steer reviewers back if they touch code under review, speculate without running code, ignore coding rules/linked context, or emit lazy questions instead of checking the repo/PR. Steer researchers back if they edit files or rabbit-hole outside the brief's questions. Don't message agents just to ask how it's going—check their branch, artifacts, and `astack-status` clock instead. ## Steer Write one short, self-contained message: stop X, do Y, because Z. Send it into the worker's running turn with `followup_task`, and log it as a directive, or its successor never sees it. (Use the same mechanism for running reviewers and researchers.) Never steer to expand scope. ## When a worker ends 1. Read its report, losses first. Send back one with no `SKILLS READ` line, or one that cites a skill it doesn't list. 2. **Log `verified ` for every merge, with the `astack-verify-merge` and `astack-check-gates` results; never write `closed ` without it.** **Always run vectored **review**; scale test scope and reviewer count to risk:** verify every claimed branch/merge with `astack-verify-merge ` (or `astack-check-gates ..`) and inspect the done-when evidence, then run vectored **review** (`astack-review-ledger`) before landing **any** worker lane—never land code without a reviewer. For low-risk, isolated lanes, start with **one** reviewer (on a non-worker model when `reviewer_pool` allows) plus touched lint/tests (running the full suite on target after merges). For medium/high-risk changes (shared interfaces, concurrency, persistence, auth/security, or large diffs), or whenever shipping via PRs or gating downstream tasks, cut vectors by risk (adding a `seams` vector via **blast-radius** when sliced), start each risky vector with **at least two** blind reviewers on different approved models from `reviewer_pool` with no cap, prove overlaps by fix-equivalence, count only proven blocking bugs in `astack-review-ledger`'s observable-class saturation check (or empirically calibrated clean sweep), save the internal coverage map to the program folder and `LANES.md`, and run broader/full checks **before** landing (**watch-pr**). For bug fixes (and **bugbash** runs), pass the initial bug report, all fetched linked documentation/issues, the shrunk repro, and all **rejected theories (`decided:` entries) plus failed fix approaches/attempts** to the post-fix reviewers, instruct them to verify the fix with **prove-it**, and summarize and attach that proof and evidence to any PR generated for the fix (**watch-pr**). If a risky vector's review runs out of approved models before saturating (`landing_blocked: true`), **hold landing** and escalate a plain-language decision to the person (proven blocking bugs found, estimated remaining blocking bugs of similar detectability with range, and the choice to approve more models or accept the risk). Treat reports as unverified claims until checked. 3. **Conditional rebase, `git range-diff`, verdict carry-over, and takeover credit:** rebase/merge target only when target moved (so untested code would otherwise land). After any rebase, run `astack-watch-pr patch-id-check --before .. --after ..HEAD --json` (which runs both `git patch-id --stable` and `git range-diff` to confirm no commit or behavior was dropped and no old behavior was brought back); carry a prior passing review/test verdict only when `carry_verdict` is `true` and incoming target commits do not overlap the change's **blast-radius**—otherwise re-verify. When finishing, rebasing, or grafting another contributor's branch/PR, preserve original git authorship (`--author`) or `Co-authored-by: Name ` trailers and confirm with `astack-watch-pr authorship-check`. 4. **Countersign any gate change; reject gate gaming:** no worker may loosen a gate unilaterally. Pass the last verified target commit to `astack-verify-merge --base --strict-gates` (or `astack-check-gates ..`) so the check compares trees strictly against the verified target without relying on worker commit messages (on merge commits without `--base`, `astack-verify-merge` audits every parent side and fails closed). Pair this structural tripwire with **review** for semantic test weakenings. Any relaxation of a check, threshold, or done-when requires your explicit countersign logged in both `RULES.md` (`## Revisions`) and `LANES.md` with reason and evidence. If a worker games a gate, reject/revert the change, reset the task contract (tighten the brief and acceptance criteria), and dispatch a fresh successor. If a gate itself is genuinely wrong or broken, fix it in its own dedicated task/change rather than weakening it inside feature work. 5. Log the end event and each reported decision, **rejected theory**, and **failed fix approach/attempt** as a `decided:` line in `LANES.md` (queryable via `astack-decisions` and passed to post-fix reviewers and successors so dead ends aren't repeated). After verified bug fixes, **bugbash** runs, or multi-attempt lanes, run **make-it-stick** to turn verified fixes, rejected theories, and failed fix approaches into scoped `LESSONS.md` entries, dispatching a fresh worker (plus **review**) for any code-level structural guard. Run post-review **cleanup** (and verify **no-leaked-secrets** on the diff/tree) so finished worktrees/ephemeral Slates VFS volumes, stray debug captures (`_DEBUG_.`), and scratch artifacts don't linger. If the done-when holds, close the task/lane and dispatch newly unblocked DAG tasks; otherwise start a successor immediately. 6. Log side findings (one line each). Turn a finding into a new task only if it blocks progress or the person asks for it. 7. When a vectored review runs, log `ledger:` with `astack-review-ledger`'s state after each reviewer. If the pool can't meet the saturation check, say so as a choice for the person. 8. Filter anything under `NEEDS THE PERSON` through the Decisions rules below before asking; escalate only what survives. Run full test suites, end-to-end checks, and competitor benchmarks yourself on the target branch after merges. Only turn failures into new tasks once confirmed on a real scenario and narrowed with **find-it** (or run a lead **bugbash** for complex or high-impact bugs). ## Successors Keep the same task, deliverable, and scope. Build the successor's brief from the original brief, every directive since (the person's words verbatim), the previous worker's full report, and the task's branch and head SHA. Always launch a fresh worker rather than resuming an old one so directives aren't lost. If repeated successors fail, the task is too big—re-plan and split it (**dagify**), logging why. ## The lane log `LANES.md` is the program's durable memory: append one line per event using the formats in its header, never rewrite history. The astack hook stamps each line with the time as it is saved, once the person trusts it in `/hooks`; until then, run `astack-stamp ` after each append. Never write a time from memory. Use `astack-decisions` to query past `decided:` and `person:` lines before revisiting questions. If `RULES.md` changes, record a revision line in `LANES.md` and notify every running worker. ## Decisions - Explore, research (**research-this**, **analyze-environment**), prototype (**play-with-me**), and benchmark (**ab-test**) to settle technical choices without unnecessary interruptions. Workers settle task-local decisions; you settle cross-task choices the same way and log every decision as a `decided:` line with its evidence. - **Honor `autonomy` without unnecessary pauses:** read-only and dry-run external probes are always allowed. When `autonomy.mode` is `"unattended"`, execute every action in `autonomy.allow` (opening/updating PRs, pushing feature branches, out-of-directory work, user-space CLI/tool installs, PR-watch loops) directly without asking confirmation—never pause on an already-authorized action. - Before escalating to the person, check earlier decisions (`astack-decisions`), the repository, external docs, `TOOLS.md`, and whether an A/B test, prototype, or user-space tool install can settle it. - Escalate only what none of those can resolve: the exact human-only step of actions only the person can take (interactive login/SSO/MFA after discovering, installing, and cataloging the tool in `TOOLS.md`; `sudo`/root installs; spending money), trade-offs of functionality or durability proven unavoidable after **research-this**, or mutating/irreversible actions in `autonomy.deny` or outside the active grant. - Ask outright, as a plain choice with your pick (**decisions-in-plain-words**), in your reply (or with `request_user_input` in Plan mode), and keep working on everything else. - Never ask for confirmation, re-ask approval already given, or ask about retries, flakes, machines, merge mechanics, or whether to keep going. - Log the person's answers verbatim and forward them to affected workers. An answer that changes a rule is a `RULES.md` change: edit it first, log `rules rev:`, then forward. ## Report Use plain language, losses first: proven high-signal issues and what didn't land and why, what landed (verified SHAs), status of each task in the DAG, key decisions made and their evidence, and any open questions waiting on the person. Never leak internal harness/astack state or vectored-review bookkeeping (single-model reviewer pool, `reviewer_pool` size, `settings.json` defaults, pool exhaustion labels, coverage-map paths, which or how many reviewer models ran, vector-assignment bookkeeping, worktree paths, or capture–recapture formulas) into user-facing replies or `"Open Items"` lists; reserve open items strictly for genuine product, engineering-risk, or human-only decisions/actions. If a risky change hasn't converged, frame it plainly in terms of code risk (proven bugs found, likely remaining blocking bugs with range, and whether to approve deeper verification or accept the risk). Before posting any review comment to a PR for human review (e.g., GitHub), run **leave-feedback** and spin up an independent reviewer agent to audit the comment for clarity, actionability, surrounding-context verification, and zero leaked internal thinking or bare SHAs. Name any of these steps that didn't run (plan review, check-ins, `verified` lines, ledger, `RULES.md` revisions) as a loss. Referenced skills: `dagify` (`../dagify/SKILL.md`), `decisions-in-plain-words` (`../decisions-in-plain-words/SKILL.md`), `analyze-environment` (`../analyze-environment/SKILL.md`), `workflow-this` (`../workflow-this/SKILL.md`), `track-it` (`../track-it/SKILL.md`), `slates` (`../slates/SKILL.md`), `go` (`../astack-go/SKILL.md`), `review` (`../astack-review/SKILL.md`), `adversarial-review` (`../adversarial-review/SKILL.md`), `rtfm` (`../rtfm/SKILL.md`), `blast-radius` (`../blast-radius/SKILL.md`), `watch-pr` (`../watch-pr/SKILL.md`), `bugbash` (`../bugbash/SKILL.md`), `prove-it` (`../prove-it/SKILL.md`), `make-it-stick` (`../make-it-stick/SKILL.md`), `cleanup` (`../cleanup/SKILL.md`), `no-leaked-secrets` (`../no-leaked-secrets/SKILL.md`), `find-it` (`../find-it/SKILL.md`), `research-this` (`../research-this/SKILL.md`), `play-with-me` (`../play-with-me/SKILL.md`), `ab-test` (`../ab-test/SKILL.md`), `leave-feedback` (`../leave-feedback/SKILL.md`). Read any cited skill file before acting when its trigger applies.