<purpose>
Sequentially execute implementation waves defined in `PLAN.md`, enforcing TDD (Test-Driven Development), atomic commits, and full-suite regression checks.
</purpose>

<required_reading>
@.opencode/references/hm-coordination-contracts.md
@.opencode/references/hm-dual-signal-completion.md
</required_reading>

<downstream_awareness>
Outputs generated by this workflow are consumed by:
1. **hm-verify**: Uses the modified code, run logs, and completed tasks to verify phase deliverables.
2. **hm-gate**: Evaluates the codebase state and test results during quality gate audits.
</downstream_awareness>

<scope_guardrail>
**CRITICAL: Atomic focus.** Focus execution strictly on the active task. Do not make unrelated file modifications or bundle multiple tasks into a single commit.
</scope_guardrail>

<process>

<step name="initialize" priority="first">
Load phase details. Read `PLAN.md` and check active wave status. Verify that the previous wave (if any) is fully complete.
</step>

<step name="execute_wave">
Process tasks in the current wave sequentially.
For each task, execute the TDD loop:
1. **Red**: Write/update tests demonstrating the expected behavior and run them to confirm they fail.
2. **Green**: Write the minimal code changes necessary to make the tests pass.
3. **Refactor**: Clean up implementation details while keeping tests green.
</step>

<step name="task_validation">
Verify the task meets its defined completion criteria. Run the specific automated tests for the task's files.
</step>

<step name="atomic_commit">
Stage only the files modified for the current task.
Commit the changes using a meaningful message:
```bash
git commit -m "feat(phase-{{phase}}): implement task {{task_name}} - {{summary}}"
```
Do not bundle multiple tasks into a single commit. Every commit must pass typechecks and tests.
</step>

<step name="regression_check">
Once all tasks in a wave are complete, run the full project test suite (`npm run test`) to verify that no regressions were introduced.
If regressions occur, roll back or troubleshoot immediately using `hm-debug`.
</step>

<step name="advance_wave">
Record wave completion. Advance to the next wave in the plan. Repeat the loop until all waves are complete.
</step>

<step name="write_summary">
Generate `${phase_dir}/${padded_phase}-SUMMARY.md` documenting what was shipped, list of modified files, and test outputs.
</step>

<step name="complete_execution">
Commit `SUMMARY.md` atomically, update the session tracker state in `.planning/STATE.md`, and notify that execution is complete.
</step>

</process>

<success_criteria>
- All plan waves executed in correct dependency order.
- TDD cycle strictly followed.
- Atomic commits created for every single task.
- Full test suite passes without regressions.
- `SUMMARY.md` created and committed.
</success_criteria>
