Loop Tasks Driver
Drive a Compozy techspec to completion as a self-healing continue loop: each
iteration detects the current phase, runs exactly one phase action,
writes memory, updates state.yaml, and prints the iteration summary —
then continues at detect unless the outcome is an evidence-backed external
blocker or Phase E. A failed command stays inside the current phase action:
diagnose, repair, and rerun it before writing iteration state. Filesystem state
still resumes cleanly if the session ends mid-loop.
The loop is a five-phase state machine:
| Phase |
Action |
Executor |
| 0 |
bootstrap |
orchestrator |
| B |
one task or slice + verify + checkpoint commit |
orchestrator, or herdr frontend worker |
| C |
qa_report, then qa_execution |
Fable 5 herdr worker, then orchestrator |
| D |
deep-review rounds until SHIP + checkpoint commit per round |
orchestrator |
| E |
done-signature |
orchestrator |
Compatible with ~/dev/ai/codex-loop-plugin goal mode; the plugin itself
is never modified. Prefer in-session continue over waiting for a
Stop→restart — restarts are a resume safety net, not the driver.
Inputs
<slug> — directory name under .compozy/tasks/.
<goal_text> — verbatim [[CODEX_LOOP goal="..."]] text or the manual
reason for the run. Captured once at bootstrap into
state.yaml.goal_signature.
--frontend <claude|cursor> — optional. Selects the frontend worker agent
and activates the herdr frontend lane for the whole loop. Captured once at
bootstrap into state.yaml.frontend_agent; when absent, every task runs
locally. Syntax examples in references/goal-header-template.md.
- A pre-authored
.compozy/tasks/<slug>/_techspec.md. Without it, bootstrap
stops with a blocker.
Helper scripts
Bundled under .agents/skills/cy-loop-tasks/scripts/ — stdlib-only
Python 3.11+, no network, no model calls. Invoke by the explicit repo-root
paths shown in the workflow steps.
| Script |
Role |
Phase |
_state_io.py |
private strict state codec (imported, not invoked) |
all state helpers |
init-state.py |
bootstrap (mutating once) |
0 |
detect-phase.py |
read-only |
every iteration |
update-state.py |
mutating |
every iteration |
commit-checkpoint.py |
mutating (git commit) |
B, D |
test_scripts.py |
read-only self-test |
skill maintenance only |
Herdr delegation lanes
Two lanes dispatch work to herdr worker TUIs. Before any dispatch, read
references/herdr-delegation.md in full and activate the
herdr-orchestration skill it builds on.
- Frontend lane (Phase B) — active only when
state.frontend_agent is
set. While active, every frontend task or slice is dispatched to the
selected worker (claude → Claude Code Opus at xhigh effort, cursor →
cursor-agent --yolo --model grok-4.5); the orchestrator session stays in
orchestration mode and never implements frontend work itself.
- QA-report lane (Phase C) — always active.
qa_report is produced by a
Claude Fable 5 worker (claude --permission-mode auto --model claude-fable-5), launched direct — never plan-first. The orchestrator runs
qa_execution itself.
Workflow
Each iteration is one detect → phase action → memory → state →
summary cycle. After a completed (non-blocked) summary that is not
Phase E, continue at Step 1 in the same turn — do not end the
session between rounds.
If any command, gate, worker, or artifact check fails during a phase action,
read references/recovery-loop.md in full immediately and run its repair loop.
Do not write final iteration state or print the summary for an intermediate
failure.
Step 1 — Detect.
- Print
pwd and confirm the working directory is the repo root (the
directory containing .compozy/tasks/). On mismatch, locate that root,
change into it, and confirm again; block only when the task tree is absent.
- Activate
cy-workflow-memory so its protocol is loaded for later use
(once per session is enough; re-activate only if context was dropped).
- Run
python3 .agents/skills/cy-loop-tasks/scripts/detect-phase.py <slug>.
The printed line decides the whole iteration; the output catalog and
entry/exit conditions are in references/phase-transitions.md.
Done when: detect-phase emitted exactly one supported phase/action line and
the matching branch below is selected.
Step 2 — Run exactly one phase branch.
Phase 0 — Bootstrap
- Confirm
.compozy/tasks/<slug>/_techspec.md exists. Missing → scaffold
memory/MEMORY.md from references/memory-protocol.md, record the
blocker under ## Open Risks, print the iteration summary with
outcome=blocked, and stop (state.yaml does not exist yet, so there is
no update-state call).
- Run
python3 .agents/skills/cy-loop-tasks/scripts/init-state.py <slug> --goal "<goal_text>",
adding --frontend <claude|cursor> when the invocation text carries the
parameter. Mode auto-detects: tasks when _tasks.md plus at least one
task_*.md exist, else free.
- Activate
cy-spec-preflight for the phase the next iteration enters
(tasks, or task-body when a single concrete file is next).
- Scaffold
.compozy/tasks/<slug>/memory/MEMORY.md with the canonical
sections from references/memory-protocol.md.
- Run
python3 .agents/skills/cy-loop-tasks/scripts/update-state.py <slug> --phase 0 --action "bootstrap (mode=<mode>)" --outcome completed --memory-written "memory/MEMORY.md".
Done when: state.yaml exists and memory/MEMORY.md has the canonical
sections.
Phase B mode=tasks — execute one task
- Take the task printed by detect-phase (
task=<stem>). Read
.compozy/tasks/<slug>/<stem>.md and confirm frontmatter status: is
pending or in_progress. Frontmatter wins — on drift, reconcile with
update-state.py <slug> --task-completed <stem> for already-finished
tasks or --reconcile-tasks for a late-authored graph, then re-run
detect-phase.
- Activate
cy-spec-preflight in task-body mode for the picked file.
- Resolve the shared and current memory paths from
references/memory-protocol.md and pass them into the lane that executes
the work.
- Frontend lane — when detect-phase printed
lane=frontend agent=<x>:
dispatch the task to that worker per references/herdr-delegation.md.
The worker owns implementation, memory updates, scoped validation, and
cy-final-verify evidence. It never commits. Skip step 5.
- Local lane — activate
cy-execute-task on the picked file with
auto-commit disabled. Run the task's scoped validation, then
cy-final-verify. Skip any per-task peer-review step the task
file requests — that review is Phase D (see Critical Rules).
- Confirm memory is updated (written locally, or verified from the worker)
and that
cy-final-verify evidence is PASS before any state flip. For the
frontend lane, verify the worker's evidence instead of re-running verify.
- Run
python3 .agents/skills/cy-loop-tasks/scripts/update-state.py <slug> --phase B --task-completed <stem> --action "executed <stem>" --outcome completed --memory-written "memory/<stem>.md,memory/MEMORY.md" --verify-pass.
- Run
python3 .agents/skills/cy-loop-tasks/scripts/commit-checkpoint.py <slug> --task <stem>.
Stdout is a commit SHA or SKIP: no changes; copy it into the iteration
summary. On exit 1, enter the repair loop and retry the normal checkpoint
after its root cause is fixed. Never bypass the hook with --no-verify.
Done when: task frontmatter, memory, state.yaml, and the checkpoint result
all reflect the same completed task.
Phase B mode=free — execute one slice
- Re-read
_techspec.md deliverables and acceptance in full; compare
against state.progress.checklist[].
- Pick the smallest coherent slice (≤ ~4 hours) that advances at least one
acceptance criterion; capture its text exactly.
- Run
python3 .agents/skills/cy-loop-tasks/scripts/update-state.py <slug> --add-progress "<slice text>" --action "slice picked" --outcome completed.
- Re-read
state.yaml; the current memory file is
memory/free-iter-<NNN>.md, <NNN> = the new checklist entry's
iteration, zero-padded to three digits.
- Frontend lane — when
state.frontend_agent is set AND the slice's
owned paths are exclusively frontend surfaces (classification in
references/herdr-delegation.md): dispatch per that reference. The
worker owns implementation, memory updates, scoped validation, and
cy-final-verify evidence; it never commits. Skip step 6.
- Local lane — implement the slice, record decisions and learnings in
the current memory file, run scoped validation, then
cy-final-verify.
- Confirm memory is updated and
cy-final-verify evidence is PASS. For the
frontend lane, verify the worker's evidence instead of re-running verify.
- Acceptance self-check: when every techspec criterion has a completed
checklist entry, add
--deliverables-complete to the step 9 call.
- Run
python3 .agents/skills/cy-loop-tasks/scripts/update-state.py <slug> --phase B --complete-progress "<slice text>" [--deliverables-complete] --action "slice <text>" --outcome completed --memory-written "memory/free-iter-<NNN>.md,memory/MEMORY.md" --verify-pass.
- Run
python3 .agents/skills/cy-loop-tasks/scripts/commit-checkpoint.py <slug> --slice "<slice text>"
with the exact step 3 text — same SKIP / exit-1 semantics as mode=tasks
step 8.
Done when: the slice's checklist entry is completed and the checkpoint
result is recorded.
Phase C — QA
Run only the printed action.
qa_report — dispatched, never authored locally:
- When release-grade runtime scope needs a lab and no active
bootstrap-manifest.json exists, activate the project's QA bootstrap
skill first (e.g. agh-qa-bootstrap in AGH) when installed.
- Dispatch the Fable 5 worker per
references/herdr-delegation.md
(QA-report lane). The worker activates qa-report with
qa-docs-path=docs/qa and updates journey flows, docs/qa/scenarios/
files, and cycle charters.
- Verify the worker evidence (each reported artifact exists, no worker
commit), then run
python3 .agents/skills/cy-loop-tasks/scripts/update-state.py <slug> --phase C --qa-report-done --action "qa-report produced" --outcome completed --memory-written "memory/qa-report.md,memory/MEMORY.md".
qa_execution — local:
- Activate
qa-execution with qa-docs-path=docs/qa; it writes the dated
run report at docs/qa/reports/<YYYY-MM-DD>-<slug>.md and updates
scenario-file verdicts.
- When the report is "not ready" or a Blocks-Completion/Data-Loss bug is
open, keep the Phase C action open: repair every in-scope bug, rerun the
affected QA, and repeat
qa-execution through the recovery loop. Do not
set --qa-execution-done on an intermediate report.
- Once the report is ready, run
python3 .agents/skills/cy-loop-tasks/scripts/update-state.py <slug> --phase C --qa-execution-done --action "qa-execution produced" --outcome completed --memory-written "memory/qa-execution.md,memory/MEMORY.md" --verify-pass.
mode=tasks addition: when the printed QA action corresponds to the pending QA
task file, flip that task's frontmatter status: to completed and add
--task-completed <stem> to the same update-state call so tasks.pending
drains.
Done when: the printed QA artifact exists on disk and its flag is recorded in
state.yaml.
Phase D — peer-review rounds until SHIP
One round per iteration; detect-phase re-emits peer_review until the
verdict is SHIP on a verify-PASS tree. Enter this phase only after every
Phase B task or slice is complete and both QA flags are true.
- Activate
deep-review for the round number printed by detect-phase,
scoped to the loop's full diff: --base = the ref the loop started from
when known (default main), --spec .compozy/tasks/<slug> (contract
conformance), --subagent codex (cross-LLM reviewer lane — the
implementing model never solely reviews its own work). Later rounds ride
deep-review's incremental state; never pass --full mid-loop.
- The loop is the deciding authority over the round: remediate every
confirmed finding and every nitpick from the round's review.md in this
same iteration, then re-run the project verification gate. The round's
verdict is the SHIP/FIX_BEFORE_SHIP/REWORK value in review.md/state.json.
- Update
memory/peer-review.md (a ## Round <N> section per round), then
run python3 .agents/skills/cy-loop-tasks/scripts/update-state.py <slug> --phase D --review-round-done <SHIP|FIX_BEFORE_SHIP|REWORK> --action "peer-review round <N> (<verdict>)" --outcome completed --memory-written "memory/peer-review.md,memory/MEMORY.md" --verify-pass.
The call uses --verify-pass: a failed post-remediation gate stays inside
the repair loop, and a SHIP verdict on a failing tree is void.
- Run
python3 .agents/skills/cy-loop-tasks/scripts/commit-checkpoint.py <slug> --review-round <N>
— same SKIP / exit-1 semantics as Phase B.
Done when: the round's review.md exists with a verdict, every confirmed
finding and nitpick from it is remediated (or the verdict was SHIP), and
state.yaml records the round.
Phase E — done
- Run a final
cy-final-verify and confirm state.verify.last_status=PASS.
A regression enters the repair loop and Phase E remains open until the
fresh gate passes; skip the done-signature while repairing.
- Walk the Phase E section of
references/checklist.md; every box must
pass.
- Print the iteration summary block from
assets/iteration-summary.template.md with phase_out=E and checkpoint
field n/a (phase != B/D).
- Print the literal contents of
assets/done-signature.txt on its own line
— the codex-loop goal-check confirmation scans for it.
- Stop — Phase E is the only successful terminal.
Done when: the Phase E checklist passes, the iteration summary is printed,
and the done-signature is the final output line.
Step 3 — Self-audit, summarize, then continue.
- Walk
references/checklist.md for the phase just executed; every box must
pass before summarizing.
- Print the iteration summary block from
assets/iteration-summary.template.md (Phase E already printed it and
adds only the done-signature line).
- Continue gate: stop only when
phase_out=E or the external-blocker
criteria in references/recovery-loop.md are proven and
outcome=blocked. Otherwise re-enter Step 1 immediately — the summary
marks the round; it does not end the session.
Done when: the phase checklist passes, its summary is printed, and control
either returned to Step 1 or stopped at a permitted terminal.
Memory protocol
Memory goes through the cy-workflow-memory skill — the exact paths per
phase are in references/memory-protocol.md. Update memory before
flipping any tracking field.
Goal-mode integration
The canonical [[CODEX_LOOP ...]] header, the manual invocation text, and
--frontend syntax live in references/goal-header-template.md.
Critical Rules
- One phase action per iteration; repair failures inside that action, then
continue at detect until Phase E or a proven external blocker — never
idle between rounds waiting for a restart or re-invocation.
state.yaml mutates only through init-state.py and update-state.py;
hand-edits void resume guarantees. There is no top-level current_phase —
detect-phase.py derives it from durable state and filesystem truth every
run.
- Frontmatter
status: on task_NN.md is the source of truth; reconcile
state.yaml when they disagree.
- Memory updates precede status flips. Always.
- Frontend lane:
state.frontend_agent set → herdr dispatch is the only way
frontend work gets implemented; null → every task runs locally. Workers are
interactive TUIs launched via rtk herdr agent start — a pane streaming
raw JSON is a broken headless delegation: interrupt and relaunch per
references/herdr-delegation.md.
qa_report is always produced by the Fable 5 worker; qa_execution always
runs locally.
- Every Phase B task or slice runs scoped validation then
cy-final-verify
before its checkpoint commit. A FAIL opens the repair loop; only the final
PASS closes the phase action.
- Peer review (
deep-review) runs only in Phase D. Per-task peer-review
instructions inside task files or specs are superseded by this loop's phase
machine — note "deferred to Phase D" in the task memory and move on.
- Phase D repeats in consecutive rounds until SHIP; every non-SHIP round
remediates all blockers and nits before the next round starts.
- Checkpoint commits (Phases B and D) belong to the orchestrator:
cy-execute-task runs with auto-commit disabled, and every worker packet
forbids committing. The checkpoint captures code, memory, task frontmatter,
the master tasks file, and the advanced state.yaml in one atomic,
restorable snapshot.
- Phase E requires
qa.report_done=true, qa.execution_done=true,
review.ship=true, and verify.last_status=PASS.
- Do not regenerate the loop's input graph with
cy-create-tasks,
cy-create-techspec, cy-tasks-tail-qa-pair, or cy-web-docs-impact.
The only exception is a repository-mandated two-touch corrective TechSpec:
activate its required spec skills, let the loop decide choices already
bounded by the current goal/contract, persist the corrective design, and
continue without replacing the original task graph.
Error Handling
- Any failure — read
references/recovery-loop.md in full and execute it
before mutating iteration state. Failed commands are repair work, not
blockers. Use outcome=blocked only after its external-blocker test passes.
_techspec.md missing at bootstrap — record the blocker in
memory/MEMORY.md ## Open Risks, print the iteration summary with
outcome=blocked, stop. No update-state call: state.yaml does not exist
yet.
- Mode disagreement —
init-state.py exits 4 when --mode contradicts
the filesystem. Reconcile by adding/removing _tasks.md before bootstrap,
or run update-state.py <slug> --reconcile-tasks when the task graph was
authored after a free-mode bootstrap.
state.yaml parse failure — detect-phase.py exits 1 with the parse
error on stderr. Diagnose the malformed writer or interrupted write from
evidence and repair it without discarding unrelated worktree changes.
commit-checkpoint.py exit 1 — repair the hook or commit failure and
retry normally. If the repair changes tracked source after the last PASS,
rerun cy-final-verify before retrying. SKIP: no changes is success.
- Worker launch or delegation failure — the pane shows raw JSON instead
of a TUI banner,
rtk herdr agent list stays unknown, or the status wait
times out with no progress: interrupt
(rtk herdr pane send-keys <pane_id> ctrl+c) and relaunch once via
rtk herdr agent start; if it fails again, diagnose and repair the worker
environment through the recovery loop.
- Delegated run lacks PASS evidence or artifacts, or committed anyway —
keep the phase open, recover the missing evidence or rerun the lane, and do
not advance. A worker commit is a contract breach that requires preserving
the worker's work and repairing checkpoint ownership before continuing.
- Invalid peer-review round (missing or malformed review artifacts, or no
verdict) — the round does not count; follow
deep-review error handling
and re-run it.
- Two-touch rule — on the third corrective touch, replace patching with
the structural redesign required by the repository, validate it, and
continue. It becomes a blocker only when that redesign needs an external
product decision or authority unavailable to the loop.
- External blocker proven — record the evidence and exhausted alternatives
in memory, call
update-state.py with --verify-fail --blocker <text> --outcome blocked,
print the summary, and stop without the done-signature.
1---2name: cy-loop-tasks-33description: Task-graph execution loop for Compozy specs — self-healing checkpoint driver that ships a techspec end to end by executing its authored task graph (_tasks.md + task_NN.md), one atomic commit per Phase B task, QA, then deep-review peer-review rounds until SHIP. Use for continuous codex-loop goal runs over a .compozy/tasks/<slug> whose work is decomposed into task files, or with --frontend to delegate frontend tasks to herdr workers. Do not use for one-off tasks, PRD/TechSpec authoring, or a slug with spec documents but no task graph (use cy-implement-spec).4---56# Loop Tasks Driver78Drive a Compozy techspec to completion as a **self-healing continue** loop: each9iteration detects the current phase, runs exactly one phase action,10writes memory, updates `state.yaml`, and prints the iteration summary —11then **continues** at detect unless the outcome is an evidence-backed external12blocker or Phase E. A failed command stays inside the current phase action:13diagnose, repair, and rerun it before writing iteration state. Filesystem state14still resumes cleanly if the session ends mid-loop.1516The loop is a five-phase state machine:1718| Phase | Action | Executor |19|-------|--------|----------|20| 0 | bootstrap | orchestrator |21| B | one task or slice + verify + checkpoint commit | orchestrator, or herdr frontend worker |22| C | `qa_report`, then `qa_execution` | Fable 5 herdr worker, then orchestrator |23| D | `deep-review` rounds until SHIP + checkpoint commit per round | orchestrator |24| E | done-signature | orchestrator |2526Compatible with `~/dev/ai/codex-loop-plugin` goal mode; the plugin itself27is never modified. Prefer in-session **continue** over waiting for a28Stop→restart — restarts are a resume safety net, not the driver.2930## Inputs3132- `<slug>` — directory name under `.compozy/tasks/`.33- `<goal_text>` — verbatim `[[CODEX_LOOP goal="..."]]` text or the manual34 reason for the run. Captured once at bootstrap into35 `state.yaml.goal_signature`.36- `--frontend <claude|cursor>` — optional. Selects the frontend worker agent37 and activates the herdr frontend lane for the whole loop. Captured once at38 bootstrap into `state.yaml.frontend_agent`; when absent, every task runs39 locally. Syntax examples in `references/goal-header-template.md`.40- A pre-authored `.compozy/tasks/<slug>/_techspec.md`. Without it, bootstrap41 stops with a blocker.4243## Helper scripts4445Bundled under `.agents/skills/cy-loop-tasks/scripts/` — stdlib-only46Python 3.11+, no network, no model calls. Invoke by the explicit repo-root47paths shown in the workflow steps.4849| Script | Role | Phase |50|--------|------|-------|51| `_state_io.py` | private strict state codec (imported, not invoked) | all state helpers |52| `init-state.py` | bootstrap (mutating once) | 0 |53| `detect-phase.py` | read-only | every iteration |54| `update-state.py` | mutating | every iteration |55| `commit-checkpoint.py` | mutating (git commit) | B, D |56| `test_scripts.py` | read-only self-test | skill maintenance only |5758## Herdr delegation lanes5960Two lanes dispatch work to herdr worker TUIs. Before any dispatch, read61`references/herdr-delegation.md` in full and activate the62`herdr-orchestration` skill it builds on.6364- **Frontend lane (Phase B)** — active only when `state.frontend_agent` is65 set. While active, every frontend task or slice is dispatched to the66 selected worker (`claude` → Claude Code Opus at xhigh effort, `cursor` →67 `cursor-agent --yolo --model grok-4.5`); the orchestrator session stays in68 orchestration mode and never implements frontend work itself.69- **QA-report lane (Phase C)** — always active. `qa_report` is produced by a70 Claude Fable 5 worker (`claude --permission-mode auto --model71 claude-fable-5`), launched direct — never plan-first. The orchestrator runs72 `qa_execution` itself.7374## Workflow7576Each **iteration** is one detect → phase action → memory → state →77summary cycle. After a completed (non-blocked) summary that is not78Phase E, **continue** at Step 1 in the same turn — do not end the79session between rounds.8081If any command, gate, worker, or artifact check fails during a phase action,82read `references/recovery-loop.md` in full immediately and run its repair loop.83Do not write final iteration state or print the summary for an intermediate84failure.8586**Step 1 — Detect.**87881. Print `pwd` and confirm the working directory is the repo root (the89 directory containing `.compozy/tasks/`). On mismatch, locate that root,90 change into it, and confirm again; block only when the task tree is absent.912. Activate `cy-workflow-memory` so its protocol is loaded for later use92 (once per session is enough; re-activate only if context was dropped).933. Run `python3 .agents/skills/cy-loop-tasks/scripts/detect-phase.py <slug>`.94 The printed line decides the whole iteration; the output catalog and95 entry/exit conditions are in `references/phase-transitions.md`.9697Done when: detect-phase emitted exactly one supported phase/action line and98the matching branch below is selected.99100**Step 2 — Run exactly one phase branch.**101102### Phase 0 — Bootstrap1031041. Confirm `.compozy/tasks/<slug>/_techspec.md` exists. Missing → scaffold105 `memory/MEMORY.md` from `references/memory-protocol.md`, record the106 blocker under `## Open Risks`, print the iteration summary with107 `outcome=blocked`, and stop (`state.yaml` does not exist yet, so there is108 no update-state call).1092. Run `python3 .agents/skills/cy-loop-tasks/scripts/init-state.py <slug> --goal "<goal_text>"`,110 adding `--frontend <claude|cursor>` when the invocation text carries the111 parameter. Mode auto-detects: `tasks` when `_tasks.md` plus at least one112 `task_*.md` exist, else `free`.1133. Activate `cy-spec-preflight` for the phase the next iteration enters114 (`tasks`, or `task-body` when a single concrete file is next).1154. Scaffold `.compozy/tasks/<slug>/memory/MEMORY.md` with the canonical116 sections from `references/memory-protocol.md`.1175. Run `python3 .agents/skills/cy-loop-tasks/scripts/update-state.py <slug> --phase 0 --action "bootstrap (mode=<mode>)" --outcome completed --memory-written "memory/MEMORY.md"`.118119Done when: `state.yaml` exists and `memory/MEMORY.md` has the canonical120sections.121122### Phase B mode=tasks — execute one task1231241. Take the task printed by detect-phase (`task=<stem>`). Read125 `.compozy/tasks/<slug>/<stem>.md` and confirm frontmatter `status:` is126 `pending` or `in_progress`. Frontmatter wins — on drift, reconcile with127 `update-state.py <slug> --task-completed <stem>` for already-finished128 tasks or `--reconcile-tasks` for a late-authored graph, then re-run129 detect-phase.1302. Activate `cy-spec-preflight` in `task-body` mode for the picked file.1313. Resolve the shared and current memory paths from132 `references/memory-protocol.md` and pass them into the lane that executes133 the work.1344. **Frontend lane** — when detect-phase printed `lane=frontend agent=<x>`:135 dispatch the task to that worker per `references/herdr-delegation.md`.136 The worker owns implementation, memory updates, scoped validation, and137 `cy-final-verify` evidence. It never commits. Skip step 5.1385. **Local lane** — activate `cy-execute-task` on the picked file with139 auto-commit disabled. Run the task's scoped validation, then140 `cy-final-verify`. Skip any per-task peer-review step the task141 file requests — that review is Phase D (see Critical Rules).1426. Confirm memory is updated (written locally, or verified from the worker)143 and that `cy-final-verify` evidence is PASS before any state flip. For the144 frontend lane, verify the worker's evidence instead of re-running verify.1457. Run `python3 .agents/skills/cy-loop-tasks/scripts/update-state.py <slug> --phase B --task-completed <stem> --action "executed <stem>" --outcome completed --memory-written "memory/<stem>.md,memory/MEMORY.md" --verify-pass`.1468. Run `python3 .agents/skills/cy-loop-tasks/scripts/commit-checkpoint.py <slug> --task <stem>`.147 Stdout is a commit SHA or `SKIP: no changes`; copy it into the iteration148 summary. On exit 1, enter the repair loop and retry the normal checkpoint149 after its root cause is fixed. Never bypass the hook with `--no-verify`.150151Done when: task frontmatter, memory, `state.yaml`, and the checkpoint result152all reflect the same completed task.153154### Phase B mode=free — execute one slice1551561. Re-read `_techspec.md` deliverables and acceptance in full; compare157 against `state.progress.checklist[]`.1582. Pick the smallest coherent slice (≤ ~4 hours) that advances at least one159 acceptance criterion; capture its text exactly.1603. Run `python3 .agents/skills/cy-loop-tasks/scripts/update-state.py <slug> --add-progress "<slice text>" --action "slice picked" --outcome completed`.1614. Re-read `state.yaml`; the current memory file is162 `memory/free-iter-<NNN>.md`, `<NNN>` = the new checklist entry's163 `iteration`, zero-padded to three digits.1645. **Frontend lane** — when `state.frontend_agent` is set AND the slice's165 owned paths are exclusively frontend surfaces (classification in166 `references/herdr-delegation.md`): dispatch per that reference. The167 worker owns implementation, memory updates, scoped validation, and168 `cy-final-verify` evidence; it never commits. Skip step 6.1696. **Local lane** — implement the slice, record decisions and learnings in170 the current memory file, run scoped validation, then `cy-final-verify`.1717. Confirm memory is updated and `cy-final-verify` evidence is PASS. For the172 frontend lane, verify the worker's evidence instead of re-running verify.1738. Acceptance self-check: when every techspec criterion has a completed174 checklist entry, add `--deliverables-complete` to the step 9 call.1759. Run `python3 .agents/skills/cy-loop-tasks/scripts/update-state.py <slug> --phase B --complete-progress "<slice text>" [--deliverables-complete] --action "slice <text>" --outcome completed --memory-written "memory/free-iter-<NNN>.md,memory/MEMORY.md" --verify-pass`.17610. Run `python3 .agents/skills/cy-loop-tasks/scripts/commit-checkpoint.py <slug> --slice "<slice text>"`177 with the exact step 3 text — same SKIP / exit-1 semantics as mode=tasks178 step 8.179180Done when: the slice's checklist entry is `completed` and the checkpoint181result is recorded.182183### Phase C — QA184185Run only the printed action.186187`qa_report` — dispatched, never authored locally:1881891. When release-grade runtime scope needs a lab and no active190 `bootstrap-manifest.json` exists, activate the project's QA bootstrap191 skill first (e.g. `agh-qa-bootstrap` in AGH) when installed.1922. Dispatch the Fable 5 worker per `references/herdr-delegation.md`193 (QA-report lane). The worker activates `qa-report` with194 `qa-docs-path=docs/qa` and updates journey flows, `docs/qa/scenarios/`195 files, and cycle charters.1963. Verify the worker evidence (each reported artifact exists, no worker197 commit), then run `python3 .agents/skills/cy-loop-tasks/scripts/update-state.py <slug> --phase C --qa-report-done --action "qa-report produced" --outcome completed --memory-written "memory/qa-report.md,memory/MEMORY.md"`.198199`qa_execution` — local:2002011. Activate `qa-execution` with `qa-docs-path=docs/qa`; it writes the dated202 run report at `docs/qa/reports/<YYYY-MM-DD>-<slug>.md` and updates203 scenario-file verdicts.2042. When the report is "not ready" or a Blocks-Completion/Data-Loss bug is205 open, keep the Phase C action open: repair every in-scope bug, rerun the206 affected QA, and repeat `qa-execution` through the recovery loop. Do not207 set `--qa-execution-done` on an intermediate report.2083. Once the report is ready, run `python3 .agents/skills/cy-loop-tasks/scripts/update-state.py <slug> --phase C --qa-execution-done --action "qa-execution produced" --outcome completed --memory-written "memory/qa-execution.md,memory/MEMORY.md" --verify-pass`.209210mode=tasks addition: when the printed QA action corresponds to the pending QA211task file, flip that task's frontmatter `status:` to `completed` and add212`--task-completed <stem>` to the same update-state call so `tasks.pending`213drains.214215Done when: the printed QA artifact exists on disk and its flag is recorded in216`state.yaml`.217218### Phase D — peer-review rounds until SHIP219220One round per iteration; detect-phase re-emits `peer_review` until the221verdict is SHIP on a verify-PASS tree. Enter this phase only after every222Phase B task or slice is complete and both QA flags are true.2232241. Activate `deep-review` for the round number printed by detect-phase,225 scoped to the loop's full diff: `--base` = the ref the loop started from226 when known (default `main`), `--spec .compozy/tasks/<slug>` (contract227 conformance), `--subagent codex` (cross-LLM reviewer lane — the228 implementing model never solely reviews its own work). Later rounds ride229 deep-review's incremental state; never pass `--full` mid-loop.2302. The loop is the deciding authority over the round: remediate **every231 confirmed finding and every nitpick** from the round's review.md in this232 same iteration, then re-run the project verification gate. The round's233 verdict is the SHIP/FIX_BEFORE_SHIP/REWORK value in review.md/state.json.2343. Update `memory/peer-review.md` (a `## Round <N>` section per round), then235 run `python3 .agents/skills/cy-loop-tasks/scripts/update-state.py <slug> --phase D --review-round-done <SHIP|FIX_BEFORE_SHIP|REWORK> --action "peer-review round <N> (<verdict>)" --outcome completed --memory-written "memory/peer-review.md,memory/MEMORY.md" --verify-pass`.236 The call uses `--verify-pass`: a failed post-remediation gate stays inside237 the repair loop, and a SHIP verdict on a failing tree is void.2384. Run `python3 .agents/skills/cy-loop-tasks/scripts/commit-checkpoint.py <slug> --review-round <N>`239 — same SKIP / exit-1 semantics as Phase B.240241Done when: the round's review.md exists with a verdict, every confirmed242finding and nitpick from it is remediated (or the verdict was SHIP), and243`state.yaml` records the round.244245### Phase E — done2462471. Run a final `cy-final-verify` and confirm `state.verify.last_status=PASS`.248 A regression enters the repair loop and Phase E remains open until the249 fresh gate passes; skip the done-signature while repairing.2502. Walk the Phase E section of `references/checklist.md`; every box must251 pass.2523. Print the iteration summary block from253 `assets/iteration-summary.template.md` with `phase_out=E` and checkpoint254 field `n/a (phase != B/D)`.2554. Print the literal contents of `assets/done-signature.txt` on its own line256 — the codex-loop goal-check confirmation scans for it.2575. Stop — Phase E is the only successful terminal.258259Done when: the Phase E checklist passes, the iteration summary is printed,260and the done-signature is the final output line.261262**Step 3 — Self-audit, summarize, then continue.**2632641. Walk `references/checklist.md` for the phase just executed; every box must265 pass before summarizing.2662. Print the iteration summary block from267 `assets/iteration-summary.template.md` (Phase E already printed it and268 adds only the done-signature line).2693. **Continue gate:** stop only when `phase_out=E` or the external-blocker270 criteria in `references/recovery-loop.md` are proven and271 `outcome=blocked`. Otherwise re-enter Step 1 immediately — the summary272 marks the round; it does not end the session.273274Done when: the phase checklist passes, its summary is printed, and control275either returned to Step 1 or stopped at a permitted terminal.276277## Memory protocol278279Memory goes through the `cy-workflow-memory` skill — the exact paths per280phase are in `references/memory-protocol.md`. Update memory **before**281flipping any tracking field.282283## Goal-mode integration284285The canonical `[[CODEX_LOOP ...]]` header, the manual invocation text, and286`--frontend` syntax live in `references/goal-header-template.md`.287288## Critical Rules289290- One phase action per iteration; repair failures inside that action, then291 **continue** at detect until Phase E or a proven external blocker — never292 idle between rounds waiting for a restart or re-invocation.293- `state.yaml` mutates only through `init-state.py` and `update-state.py`;294 hand-edits void resume guarantees. There is no top-level `current_phase` —295 `detect-phase.py` derives it from durable state and filesystem truth every296 run.297- Frontmatter `status:` on `task_NN.md` is the source of truth; reconcile298 `state.yaml` when they disagree.299- Memory updates precede status flips. Always.300- Frontend lane: `state.frontend_agent` set → herdr dispatch is the only way301 frontend work gets implemented; null → every task runs locally. Workers are302 interactive TUIs launched via `rtk herdr agent start` — a pane streaming303 raw JSON is a broken headless delegation: interrupt and relaunch per304 `references/herdr-delegation.md`.305- `qa_report` is always produced by the Fable 5 worker; `qa_execution` always306 runs locally.307- Every Phase B task or slice runs scoped validation then `cy-final-verify`308 before its checkpoint commit. A FAIL opens the repair loop; only the final309 PASS closes the phase action.310- Peer review (`deep-review`) runs only in Phase D. Per-task peer-review311 instructions inside task files or specs are superseded by this loop's phase312 machine — note "deferred to Phase D" in the task memory and move on.313- Phase D repeats in consecutive rounds until SHIP; every non-SHIP round314 remediates all blockers and nits before the next round starts.315- Checkpoint commits (Phases B and D) belong to the orchestrator:316 `cy-execute-task` runs with auto-commit disabled, and every worker packet317 forbids committing. The checkpoint captures code, memory, task frontmatter,318 the master tasks file, and the advanced `state.yaml` in one atomic,319 restorable snapshot.320- Phase E requires `qa.report_done=true`, `qa.execution_done=true`,321 `review.ship=true`, and `verify.last_status=PASS`.322- Do not regenerate the loop's input graph with `cy-create-tasks`,323 `cy-create-techspec`, `cy-tasks-tail-qa-pair`, or `cy-web-docs-impact`.324 The only exception is a repository-mandated two-touch corrective TechSpec:325 activate its required spec skills, let the loop decide choices already326 bounded by the current goal/contract, persist the corrective design, and327 continue without replacing the original task graph.328329## Error Handling330331- **Any failure** — read `references/recovery-loop.md` in full and execute it332 before mutating iteration state. Failed commands are repair work, not333 blockers. Use `outcome=blocked` only after its external-blocker test passes.334- **`_techspec.md` missing at bootstrap** — record the blocker in335 `memory/MEMORY.md` `## Open Risks`, print the iteration summary with336 `outcome=blocked`, stop. No update-state call: `state.yaml` does not exist337 yet.338- **Mode disagreement** — `init-state.py` exits 4 when `--mode` contradicts339 the filesystem. Reconcile by adding/removing `_tasks.md` before bootstrap,340 or run `update-state.py <slug> --reconcile-tasks` when the task graph was341 authored after a free-mode bootstrap.342- **`state.yaml` parse failure** — `detect-phase.py` exits 1 with the parse343 error on stderr. Diagnose the malformed writer or interrupted write from344 evidence and repair it without discarding unrelated worktree changes.345- **`commit-checkpoint.py` exit 1** — repair the hook or commit failure and346 retry normally. If the repair changes tracked source after the last PASS,347 rerun `cy-final-verify` before retrying. `SKIP: no changes` is success.348- **Worker launch or delegation failure** — the pane shows raw JSON instead349 of a TUI banner, `rtk herdr agent list` stays `unknown`, or the status wait350 times out with no progress: interrupt351 (`rtk herdr pane send-keys <pane_id> ctrl+c`) and relaunch once via352 `rtk herdr agent start`; if it fails again, diagnose and repair the worker353 environment through the recovery loop.354- **Delegated run lacks PASS evidence or artifacts, or committed anyway** —355 keep the phase open, recover the missing evidence or rerun the lane, and do356 not advance. A worker commit is a contract breach that requires preserving357 the worker's work and repairing checkpoint ownership before continuing.358- **Invalid peer-review round** (missing or malformed review artifacts, or no359 verdict) — the round does not count; follow `deep-review` error handling360 and re-run it.361- **Two-touch rule** — on the third corrective touch, replace patching with362 the structural redesign required by the repository, validate it, and363 continue. It becomes a blocker only when that redesign needs an external364 product decision or authority unavailable to the loop.365- **External blocker proven** — record the evidence and exhausted alternatives366 in memory, call `update-state.py` with `--verify-fail --blocker <text> --outcome blocked`,367 print the summary, and stop without the done-signature.