Skip to content
Back to skills

Auto Build Loop

ASecurity

Autonomous build driver after SDD spec approval: phase-scoped headless build sessions, driver-owned commits, cross-provider review gates, milestone pauses, and fail-closed escalation — under explicit opt-in autonomy profiles.

  • 10 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 23, 2026
ai-agentsgoshellbashrailstestinggitapibackend

Works with

  • terminal
  • cli
  • api

Security analysis

A100/100

Scanned November 23, 2026

npx -y skills add gosha70/code-copilot-team --skill auto-build-loop --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Auto Build Loop?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Auto Build Loop
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/gosha70-auto-build-loop/badge)](https://www.skillsdirectory.com/skills/gosha70-auto-build-loop)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: auto-build-loop
description: "Autonomous build driver after SDD spec approval: phase-scoped headless build sessions, driver-owned commits, cross-provider review gates, milestone pauses, and fail-closed escalation — under explicit opt-in autonomy profiles."
---

# Auto-Build Loop (Autonomous Build After Spec Approval)

Once a feature's SDD bundle is approved, `scripts/auto-build-loop.sh` runs the
build loop unattended. The driver lives OUTSIDE any copilot session (the phase
workflow mandates a fresh session per phase): it starts headless build
sessions, runs tests, commits, submits each phase to cross-provider review,
re-checks origin alignment, and pauses for humans only at milestones or
breakers. Design: `specs/auto-build-loop/design.md`.

## Autonomy Profiles (explicit opt-in — no silent gate bypass)

| Gate (phase-workflow step) | advisory | pr | merge |
|---|---|---|---|
| Manual testing (6) | deferred to milestone checkpoint | deferred to milestone | deferred to milestone |
| Commit gate (8) | auto-commit, local only, isolated branch | auto-commit | auto-commit |
| Wait-for-approval (9) | auto-advance; hard pause at milestones | same | same |
| Origin gate exit >= 2 (10) | **always escalate to human** | **always escalate** | **always escalate** |
| Peer review (11) | driver-run, gating, driver verifies PASS | same | same; CI is GitHub's gate, not the driver's |
| Push / PR / merge | never / never / never | auto / auto / never | auto / auto / gated auto |

All three attended profiles — `advisory`, `pr`, and `merge` — are
implemented. The fourth profile, `unattended` (#191 policy core, #193
admission), must be declared in `automation.json` itself
(`schema_version: 2`, explicit `caps.*`, validated by
`scripts/validate-automation-config.sh`; never via
`--profile`/`CCT_AUTOBUILD_PROFILE` override) and must pass **admission
control** before anything runs: `validate-spec.sh --unattended
--feature-id <id> --config <effective-config>` proves a finalized
`specs/<id>/verification.yaml` (generated by
`scripts/generate-verification-draft.sh`, author-finalized) covers
every `FR-N` with executable verifiers, every `statement_sha`
recomputes clean against `spec.md`, governance holds (approved plan,
origin gate ≤1), and `test.command` passes on the base ref (run in a
throwaway worktree of HEAD — uncommitted and gitignored files are
absent there, so commit what the suite needs, add a bootstrap step, or
opt out with `CCT_ADMISSION_TEST_IN_PLACE=1`). A refusal is an un-admitted exit-1 preflight
error naming every failing check; an admitted run executes unattended.
See "Terminal outcomes" below for how its breakers dispatch.

### `merge` profile specifics

`merge` does everything `pr` does, then arms a **gated, GitHub-native**
auto-merge at finalize (the driver never merges locally):

- `merge.enabled` (default **false**) is the final switch. When false, `merge`
  behaves exactly like `pr` — the PR is opened, nothing is merged.
- With `enabled: true` and `merge.require_branch_protection` (default true),
  the driver verifies the base branch is protected
  (`gh api repos/{owner}/{repo}/branches/{base}/protection`) and parks
  (`merge_blocked`) if it is not.
- It then runs `gh pr merge <n> --auto --<merge.method>` (default `squash`);
  GitHub performs the merge only once the branch-protection required checks
  pass — including the review gate's `External review on record`, which
  the owner sets by labelling the PR `reviewed` after reading its head
  (`.github/workflows/review-gate.yml`), so an armed auto-merge still waits
  for a human — CI is enforced by branch protection, not by this driver, which
  never polls CI and never force-merges. (`merge.require_green_ci` used to
  appear in the template; it was never read by anything and was removed in
  the merge-profile cleanup, 2026-10-29. A legacy config still carrying it validates unchanged.)
- The arm is idempotent (ledger `pr.auto_merge_armed`, else `gh pr view
  --json autoMergeRequest`); resume never re-arms. A `merge_blocked` park
  resolves once branch protection exists (or `merge.enabled` is flipped).

### `pr` profile specifics

- **`gh` preflight**: `gh auth status` (via `$CCT_GH_BIN`, default `gh`) must
  succeed — checked only when the profile can push. `advisory` never invokes
  `gh`.
- **Branch push**: after each phase gate the driver runs a plain
  `git push -u <branch.remote> <branch>` (no `--force` code path anywhere),
  refusing to push `master`/`main` or the base branch — so milestone pauses
  are inspectable remotely.
- **PR create/update**: at finalize the driver composes a deterministic PR
  body, runs `pre-pr-check.sh` (close-keyword + body/title audit), then
  `gh pr create` exactly once — recording `pr.number`/`pr.url` in the ledger.
  Re-runs and `--resume` adopt an existing **open** PR (the ledger's, if it
  is still open; else `gh pr list --head <branch> --state open`) and
  `gh pr edit --title --body-file` it after the same audit, so a
  hand-opened PR gets the configured title and close marker. A ledger PR
  that was closed by hand is journaled `pr_stale` and a new PR is created;
  a merged one parks `pr_error`. A closed PR on the branch is never
  adopted. The driver never merges.
- **Close target**: config `pr.closes` (a list), else the spec's `origin:`
  issue number; missing → parks `pr_config`. The PR body carries one
  `Closes #N` line per target, since GitHub links closing keywords only from
  the body and commit messages; the title gets a `(Closes #N)` marker for the
  first. After `gh pr create` or `gh pr edit` the driver reads
  `closingIssuesReferences` (three tries, `CCT_PR_CLOSES_RETRY_SEC` apart,
  default 2) and parks `pr_error` unless it equals the close targets (#471).
  A PR into a base other than the repository's default branch only warns:
  GitHub links closing keywords on the default branch alone. Optional
  `pr.title` overrides the title prefix.
- **WIP-push-on-escalation**: parking under `pr`/`merge` pushes the feature
  branch (best-effort — a push failure is journaled and never blocks the
  park); `advisory` parks locally only.

## Invocation

```bash
scripts/auto-build-loop.sh <feature-id> \
    [--profile advisory|pr|merge|unattended] [--config <path>] \
    [--resume] [--dry-run] [--max-phases N] [--start-phase N]
# Exit: 0 done (landed) | 3 milestone-paused | 4 escalated/parked
#       | 6 terminated_policy (terminal) | 1 usage/preflight
```

Config lives at `specs/<feature-id>/automation.json` (template:
`shared/templates/sdd/automation-template.json`; scaffold with `/auto-build`).
Reviewers are a list with `specialization`, `scope`, and `gating` fields,
resolved through `~/.cct/providers.toml`. The panel is **one
gating reviewer + N advisory (non-gating) reviewers**:

- The single `gating: true` reviewer drives the review round loop and decides
  PASS/FAIL/breaker (exactly one gating reviewer is allowed; more is an error).
- Each `gating: false` reviewer runs per phase as **advisory** — in an
  isolated review dir (via `CCT_REVIEW_DIR`/`CCT_REVIEW_COLLAB_DIR`, so the
  gating state is never touched). Its findings are folded into the fix-session
  prompt (tagged by specialization) but never block PASS or trigger a round.
- Preflight health-checks the whole panel: the gating reviewer down parks the
  run; an advisory reviewer down is a warning and that lens is skipped.
- Advisory reviewers are consulted only when a gating FAIL triggers a fix; a
  clean gating PASS ends the phase. All reviewer outputs are archived per
  phase (`phase-N/review/` gating, `phase-N/review-advisory/<provider>/`).

## The loop, per phase

1. **Preflight** (first run): plan.md `status: approved`, `validate-spec.sh`
   passes, origin gate exit <= 1, targeted provider health
   (`providers-health.sh --provider <gating-reviewer>`), clean worktree, then
   base-ref resolve → feature-branch create/checkout → refuse to proceed on
   `master`/`main`.
2. **Build**: fresh `claude -p` session scoped to one `## US<n>:` group from
   tasks.md (`--permission-mode acceptEdits`, `CCT_PEER_REVIEW_ENABLED=false`
   — the driver owns the review gate). One `--resume` continuation on
   `error_max_turns`, then park.
3. **Test**: driver runs `test.command`; failures get bounded fix sessions
   (`build.max_fix_sessions_per_phase`), then park. After the last phase a
   landing test gate runs `test.command` once more on the final head before
   any push or PR; a failure parks `test_failure` with `parked_head` (#403).
4. **Commit**: the DRIVER commits (`feat(<id>): phase N — <title>
   [auto-build]`); sessions never commit. Empty diff parks (`git_anomaly`).
5. **Review**: driver initializes `.cct/review/state.json` and invokes
   `review-round-runner.sh` with `CCT_REVIEW_BASE_REF=<phase-base>` so the
   whole phase diff is reviewed. FAIL → fix session + driver commit +
   `commit_ref` injection into `fixed` dispositions → re-review. BREAKER →
   park. PASS → driver hard gate (verdict PASS, no un-approved bypass,
   `blocking_findings_open: 0`), archive `.cct/review/` into the ledger, and
   write the phase's review record to
   `specs/<id>/collaboration/build-review-phase-<n>.md`.
6. **Phase gate**: origin re-check (exit >= 2 or stale → park), commit the
   collaboration artifact + `automation-summary.md` update.
7. **Milestone** (every `milestone_every` phases or `<!-- milestone -->`
   marker in tasks.md): write a checkpoint into `automation-summary.md`,
   exit 3. Resume requires an `approved-by:` line under the checkpoint —
   the driver commits that sign-off itself on `--resume`.

## Ledger (file-backed, machine-local)

`.cct/auto-build/<feature-id>/` — `state.json` (single source of truth:
status, per-phase commits/reviews, caps, totals), `events.jsonl` (append-only
transitions), `config.snapshot.json`, `phase-N/` artifacts (prompts, raw
result JSON, test logs, archived review), `escalations/esc-<n>.json`.
Durable human-facing output goes to `specs/<feature-id>/automation-summary.md`
and `specs/<feature-id>/collaboration/` (committed).

## Notification

`notify.command` (config; `CCT_AUTOBUILD_NOTIFY_CMD` overrides) fires on every
park, milestone pause, and run completion with placeholders `{feature_id}
{reason} {phase} {status} {summary}`. Values are substituted as quoted
env-var references — they never enter the command string, so spaces/quotes
cannot inject shell syntax. Notification failure is journaled
(`notify_failed`) and never blocks parking; the ledger is the durable record.

## Escalation & resume playbook

Every breaker parks fail-closed (exit 4) with an escalation record naming the
reason. There is no proceed-anyway path and no bypass flag: `--resume`
re-derives resolution from human-produced artifacts, per reason:

| Reason | Human action | `--resume` detects |
|---|---|---|
| `review_breaker` | `/review-decide approve\|reject\|retry` in a session (works for runner breakers AND driver fix-exhaustion — the driver writes `breaker-tripped.json` for its own breakers) | `decision.json`: approve → single-use, phase-scoped bypass accepted by the PASS gate; reject → run `aborted`; retry → review loop re-entered on the live state (attempt/round numbering preserved) |
| `origin_gate` | rescope / restart / document divergence — the driver NEVER picks for you | `check-origin-alignment.sh` exit <= 1 (fresh aligned record or committed `origin-divergence.md`) |
| `test_failure` / `build_session_error` / `git_anomaly` | fix manually, commit | clean worktree AND `test.command` green |
| `provider_unavailable` | fix providers.toml or the provider service | targeted health (`--provider` chain) passes |
| `cap_exceeded` | raise `caps.*` / `phases.max_phases` in `automation.json` | refreshed caps no longer exceeded (wall-clock guard restarts on resume) |
| `hill_chart_error` | repair `hill.json` (restore it from git or re-add the scope), commit | the phase re-enters at the hill gate |
| `pr_config` | set `pr.closes` in `automation.json` (commit it) or add an `issue:` to `plan.md` | a close target is derivable |
| `pr_precheck` / `pr_error` | fix what the log names (a stray close keyword, a closed or merged PR, linked issues that differ from the targets) | the PR step re-runs at finalize and re-gates |
| `merge_blocked` | enable branch protection on the base, or change `merge.*` | the snapshot's merge block is refreshed and auto-merge re-armed |

Unresolved: `--resume` prints exactly what is still needed and exits 1 with
no side effects. On resolution the escalation is marked `resolved`, journaled,
and a `resumed` notification fires. `review_breaker` parking leaves
`.cct/review/` in place — `/review-decide` operates on that live state.

**milestone-paused** (exit 3, not an escalation): manual-test + retro, add
`approved-by: <name> <date>` under the checkpoint, rerun with `--resume`
(the driver commits the sign-off itself).

## Terminal outcomes & metering (#191, increment A of #190)

Every run now records an explicit ledger `outcome`:

| Outcome | Exit | Meaning | Resumable? |
|---|---|---|---|
| `landed` | 0 | all phases done, review-verified | n/a |
| *(parked)* | 4 | attended breaker — human resolves, `--resume` | yes (playbook above) |
| `terminated_policy` | 6 | **unattended** breaker — the system deliberately stopped at a defined safety/quality/budget boundary | **conditionally** — `--resume` continues at the review step for `provider_unavailable`, `review_breaker` and `review_inconclusive`, provided the phase's build commit is still the branch head (#190 D2). Every other reason, and a moved head, still needs a fresh run. See `docs/auto-build.md` in the repository. |
| `failed` | 1/5 | the control system itself broke (usage/preflight/supervisor caps) | fix the environment |

Under `unattended`, every breaker that would park instead becomes a
policy termination: `termination.json` + a mandatory `triage-report.md`
in the ledger, then best-effort commit/push artifacts via the existing
precheck-respecting paths — attempted only when the driver owns the
checkout, every skip journaled, prechecks never weakened (an
unusable/unauthenticated `gh` downgrades the push/PR capabilities with a
journaled `capability_downgrade`, never blocks the termination).
`terminated_policy` is not a success and not a failure of the control
system. `scripts/cooldown-supervisor.sh` treats exit 6 as terminal —
never cooled down, relaunched, or reclassified, even when the output
contains a usage-limit phrase.

**Cost metering (FR-7: a $100 cap means $100).** Review rounds debit
the same `caps.cost_usd` as build/fix sessions. Measured cost travels
**out-of-band only** (#193): the runner exports `CCT_REVIEW_COST_FILE`
per invocation and reads a non-negative `total_cost_usd` from it — the
file is written by the provider ADAPTER process
(`provider-adapters/ollama.sh` reports honest local-$0; the
openai-compatible adapter writes only when it can derive real USD; cli
commands may opt in via the env var; note that for a `cli` provider
whose command is itself an agentic, tool-capable model, the
process-vs-text boundary is only as strong as that command's own
sandboxing). The reviewer's TEXT can never be
a measurement channel — a forged "measured $0" would suppress the
estimate and a forged negative would credit the budget. Anything
unmeasured is debited as a conservative estimate
(`unattended.budget.estimate_usd_per_invocation`, default $2) into
`totals.cost_estimated_usd` — flagged `estimated: true` in the journal,
no separate allowance; the cap check runs on the combined total.
Estimates are active under `unattended` always (disabling them there is
a preflight error: unmeterable-and-unestimable) and for attended configs
that opt in via an `unattended.budget` block; estimates are inactive for
v1 configs. **Measured** review costs, however, debit the cap on every
profile: a reviewer backend that genuinely reports cost now counts
against `caps.cost_usd` where it was silently free before — attended
runs with cost-reporting reviewers reach the cap sooner, honestly.

## Safety rails (hard-coded)

Default-on caps (max phases 8, review rounds 5, fix sessions 3/phase,
wall-clock 4h, cost $25); `advisory` cannot push even on escalation; no
`--force` code path; commits refused on `master`/`main` and pushes refused
to `master`/`main`/the base branch; sessions run with
`acceptEdits` so PreToolUse protect hooks stay active; origin escalations are
clearable only by human-authored artifacts.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.