# Autonomy Completion Invariants Implementation Plan

> **For agentic workers:** REQUIRED SUB-SKILL: Use /ship (recommended) or /executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.

**Goal:** Make autonomous runs recover known infrastructure failures, resume durable progress, and publish terminal truth.

**Architecture:** Repair existing Gate 0 classification, fixture isolation, and terminal report seams. Preserve SQLite lifecycle and existing retry/resume mechanisms.

**Tech Stack:** Bash, Node.js, node:test, SQLite journal, Git worktrees

---

## Wave Plan

| Wave | Tasks | Files touched | Safe to parallelize? |
|---|---|---|---|
| 1 | Task 1, Task 2 | `lib/gates.sh`, `lib/test-gates.sh`, `src/engine/gates.js`, gate tests; `src/daemon.js`, daemon tests | yes: no overlap |
| 2 | Task 3 | runtime/build/launcher validation only | single task |

### Task 1: Gate Infrastructure Classification

**Wave:** 1
**Blocks:** Task 3
**Blocked by:** —

**Files:**
- Modify: `lib/gates.sh` — classify exact harness infrastructure timeout evidence.
- Modify: `lib/test-gates.sh` — isolate fixture repositories from global Git hooks.
- Modify: `src/engine/gates.js` — preserve infrastructure classification through runner routing.
- Test: `src/test/engine-gates.test.js`
- Test: `lib/test-gates.sh`

**Contract:**
- Exact output containing `local-gate: parse-config timed out` produces `FAILCLASS=infra`.
- `gate-not-green-infra:<task>` maps to `gate-red-env` and never dispatches fixer.
- Gate fixtures without explicit hook use repository-local empty `core.hooksPath`.

**Behavior:**
- Retry through existing deterministic infrastructure rung.
- Preserve fail-closed behavior after retry exhaustion.
- Preserve code-failure fixer behavior.

**Acceptance:**
- Run: `node --test src/test/engine-gates.test.js && bash lib/test-gates.sh`
- Expected: PASS with zero warnings/failures.

- [ ] Write failing classification and fixture-isolation tests.
- [ ] Run tests and confirm expected failures.
- [ ] Implement minimal classification and isolation changes.
- [ ] Run acceptance check.

### Task 2: Terminal Report Freshness

**Wave:** 1
**Blocks:** Task 3
**Blocked by:** —

**Files:**
- Modify: `src/daemon.js` — refresh report for every terminal canonical scan.
- Test: `src/daemon.test.js`

**Contract:**
- Terminal scan overwrites any existing `<slug>-report.md` from latest canonical journal.
- Non-terminal scan does not publish terminal report.

**Behavior:**
- Existing stale/incomplete report cannot survive newer terminal state.
- Digest behavior remains unchanged.

**Acceptance:**
- Run: `node --test src/daemon.test.js`
- Expected: PASS including stale-report overwrite regression.

- [ ] Write failing stale-report test.
- [ ] Run test and confirm stale content remains before fix.
- [ ] Remove existence-based report suppression.
- [ ] Run acceptance check.

### Task 3: Resume and Runtime Completion Proof

**Wave:** 2
**Blocks:** —
**Blocked by:** Task 1, Task 2

**Files:**
- Modify only files required by runtime failures within Task 1 or Task 2 scope.

**Contract:**
- Existing resume integration proves landed tasks are not rerun and quarantined/skipped tasks resume.
- Full lint, typecheck, tests, production build, launcher provenance, and blocking run all pass.
- Actual launcher resolves rebuilt released bundle.

**Acceptance:**
- Run: `bash test/runner-integration.sh && make test && make build && bash test/engine-provenance-runtime.test.sh`
- Expected: zero failures/warnings; blocking autonomy plan reaches terminal success.

- [ ] Run resume regression.
- [ ] Run lint and typecheck targets discovered from project build configuration.
- [ ] Run full tests and production build.
- [ ] Verify `bin/runplan` selects rebuilt released bundle.
- [ ] Execute blocking runtime plan to terminal completion.
- [ ] Land through `ship.sh land` and re-probe launcher.
