# Factory adoption — execution plan (attended orchestration, NOT runplan)

audience: AI coding agents first.

Decision (user, 2026-08-03): NOT unattended runplan — no trusted observability yet, history of quota loops. Execution: **sonnet orchestrator subagent** dispatches implementation to cursor composer via the fail-closed dispatcher; per-phase review `cdx exec gpt-5.6-sol` medium; fixes `cdx exec gpt-5.6-terra` medium. Main session (Fable) supervises, lands, releases.

TARGET IS THE LIVE ENGINE: `modules/harness/v2` (flat layout, origin/main). `modules/harness/src` is dead parked WIP — any task or diff touching it is a verification FAILURE.

Specs (authoritative, re-anchored to live engine 2026-08-03): `modules/harness/spec/factory/SPEC-P1-CONTRACTS.md`, `SPEC-P2-OBSERVABILITY.md`, `SPEC-P3-CHAINS-SEAMS.md`. Porting reference: `modules/harness/reference/sssf/`.

## Hard safety bounds — ENFORCED BY SCRIPT, not prose

ALL cursor dispatches via `modules/harness/tools/factory-dispatch.sh` (NEVER ca.sh raw). Ledger `~/wt-factory/.factory-ledger.jsonl`; refusals: exit 10 task budget (max 2/task), 11 repeat failure signature, 12 global cap (30). Dispatch timeout `--timeout 1500`. `cdx exec` wrapped `timeout 2400`, max 2 review + 2 fix rounds/phase. No polling/sleep loops. Orchestrator never edits source itself. Any bound tripped → report + STOP (a stopped run with a report is success; a loop is the one unacceptable outcome).

## Workspace

`~/wt-factory` exists: branch `factory/adoption` off origin/main, specs at commit `4a2acfa5`. Refresh specs from `<SPEC_SHA>` (supplied in dispatch): `git -C ~/wt-factory checkout <SPEC_SHA> -- docs/plans/2026-08-03-factory-execution-plan.md modules/harness/spec/factory modules/harness/reference/sssf modules/harness/tools/factory-dispatch.sh` + commit. SHORT path mandatory (cursor phantom-tree bug); never /tmp (sqlite/pnpm).
Model: `ca.sh --health` then `--list-models` → exact composer-2.5 id; absent/unhealthy → STOP.

## Verification per task (deterministic, in ~/wt-factory)

- Engine: `node modules/harness/v2/test/index.js`
- Collector: `bun run --cwd collector typecheck && (cd collector && bun test)`
- Web: `pnpm --filter web typecheck && pnpm --filter web build && pnpm --filter web test` (slopgate via repo hooks on commit; a finding = verification failure)
- Any diff under `modules/harness/src/` = automatic FAIL.
- Fail → ONE fix dispatch (bound). Still red → task `blocked`.

## Phases + tasks

Footer F on every dispatch prompt:
```
F: Constraints: match the live modules/harness/v2 style (CommonJS, flat layout), no new runtime dependencies, zero reasoning comments.
Never touch modules/harness/src (dead WIP). Write tests in the same change; run <verify-cmd> yourself until green.
Do not touch files outside the listed scope. Do not commit — leave the tree dirty.
End with exactly one JSON line: {"status":"done","summary":"...","changed_files":[...]}
```

### P0 — baseline (codex, once)

`timeout 2400 cdx exec -m gpt-5.6-sol -c model_reasoning_effort=low "Aggregate overdeck harness run history: registry ~/.harness/history/v2/runs (plus legacy ~/.harness/v2/runs if present); per-run journals are NDJSON at <repo>/runstate/v2/<slug>/<runId>/events.ndjson and archived under ~/.harness/history/v2/artifacts — discover via registry records, do not guess. Produce docs/plans/factory-baseline-report.md in ~/wt-factory: total runs, success %, failureClass distribution, attempts-per-task p50/p95, cost where present, top 5 loop offenders (most provider invocations on one task). Numbers only."`

### P1 — budget + journal contracts (SPEC-P1)

- T-A `task-budget`: B1 per-task dispatch budget in `v2/journal.js` (ledger projection) + admission in `v2/run.js` + `budget.exhausted` kind + changing-fingerprint loop fixture. Scope: `v2/journal.js`, `v2/run.js`, `v2/test/`.
- T-B `journal-schema`: B2 `spec/journal-events.schema.json` (generated from live kind grep) + `openJournal` enforcement + meta-test. Scope: `spec/journal-events.schema.json`, `v2/journal.js`, `v2/test/`.

### P2 — observability (SPEC-P2)

- T-C split into two sequential ledgered tasks (each own slug, normal 2-dispatch budget, default timeout — narrowed scope fits it):
  - T-C1 `attempt-records`: attemptId + kinds `attempt.prompt`/`attempt.reply`/`attempt.usage` + artifact persistence (256KB tail-truncated) + schema declarations + tests. Emission at dispatch start/end only, no timer. Scope: `v2/dispatch.js`, `v2/quality.js`, `v2/journal.js`, schema, `v2/test/`.
  - T-C2 `attempt-liveness`: `attempt.heartbeat` 60s timer + `attempt.activity` end-rollup + schema + tests incl. timer cleanup on dispatch end/kill; builds on T-C1 plumbing. Scope: `v2/dispatch.js`, `v2/journal.js`, schema, `v2/test/`.
- T-D `attempts-api`: O2 `/runs/:id/attempts` + artifact serving, path-validated. Scope: `v2/control-api.js`, `v2/test/`.
- T-E `collector-liveness`: O4 staleness/heartbeat/alarm fields. Scope: `collector/src/adapters/harness.ts` + test.
- T-F split into three ledgered tasks (each own slug, normal 2-dispatch budget, `--timeout 2700` — web verify includes `pnpm --filter web build`), Footer F + only the O3 slice relevant to each:
  - T-F1 `plans-attempt-drawer-core`: reusable attempt-timeline + attempt-drawer components (prompt collapsed, reply, verdict, usage-or-"unmetered", activity counters, failureClass) + tests.
  - T-F2 `plans-autopsy-burn`: autopsy strip + burn panel (warning ≥3 attempts; alarmed at fingerprint×2 or budget ≥75%) + tests, composing T-F1 components.
  - T-F3 `plans-gallery-wiring`: wire into PlansContent/panel-data, gallery registration, both themes, honest "not captured", full web verify green.

Timeout policy: default `--timeout 1500`; only T-F1/T-F2/T-F3 use 2700 (web verify includes build). Two rc-124s on one task trip the ledger repeat-failure refusal (exit 11) — correct: mark task blocked, never re-slug to evade it.

### P3 — audit + chains (SPEC-P3, order A1→A2→T1; T2 gated)

- T-G `seam-audit`: A1 via `timeout 2400 cdx exec -m gpt-5.6-sol -c model_reasoning_effort=medium` (audit prompt from SPEC-P3 A1; output SEAM-AUDIT.md). Orchestrator commits the audit file.
- T-H `seam-fixes`: A2 — one cursor dispatch per CONFIRMED finding (each its own --task slug, normal bounds).
- T-I `scout-chain`: T1 scout binary. Scope: `v2/bin/scout.js`, `v2/test/`.
- T-J `quick-chain`: GATED — STOP before this task and report; it needs a green supervised full-engine run first.

### Per-phase review loop (after phase tasks verified + committed)

1. `timeout 2400 cdx exec -m gpt-5.6-sol -c model_reasoning_effort=medium "Review git diff origin/main..factory/adoption in ~/wt-factory against modules/harness/spec/factory/<spec>. Find contract violations, missed spec items, silent-pass paths, test gaps, any touch of modules/harness/src. Findings with file:line + severity blocker/major/minor."`
2. Blockers/majors → `timeout 2400 cdx exec -m gpt-5.6-terra -c model_reasoning_effort=medium "<findings> — fix in ~/wt-factory, run <verify-cmd>, leave tree dirty"` → orchestrator verifies + commits.
3. One re-review round max. Residual blockers → phase `blocked`, report.

## Final report (orchestrator → main session)

Per task: status, dispatches used, verify result, commit sha. Per phase: findings/fixed/residual. Global: ledger totals, wall time, bounds tripped, stop point + why. Main session then: inspection, land, harness release bump from landable checkout (memory `harness-release-bump-writes-version`), arm.
