<purpose>
Verify completed phase deliverables against plan must-haves (truths, artifacts, key links) and threat mitigations, producing a structured verification report.
</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-gate**: Evaluates the `VERIFICATION.md` file during the evidence truth gate check.
2. **Milestone transitions**: Required before archiving a completed milestone.
</downstream_awareness>

<scope_guardrail>
**CRITICAL: Objective verification.** Verification must rely on concrete runtime evidence. Do not claim verification passes based on doc summaries or code inspection alone where live execution is possible (mock detection rules apply).
</scope_guardrail>

<process>

<step name="initialize" priority="first">
Load phase details. Read `PLAN.md` and `SUMMARY.md` from the phase directory. Check for existing verification results.
</step>

<step name="verify_artifacts">
Scan the filesystem for all artifacts defined in the plan's frontmatter:
- Check that each file path exists.
- Verify files are non-empty and have non-zero size.
- Log LOC and file size metrics.
</step>

<step name="verify_truths">
Evaluate each truth statement in the plan frontmatter:
- Execute the specific tests or commands that demonstrate the behavior.
- Capture the stdout, test logs, or console output.
- Record the evidence level (L1 runtime output, L2 test trace, etc.).
</step>

<step name="verify_key_links">
Check defined relationships and pattern matching:
- Use grep or AST queries to confirm links (e.g. function call, event subscriber registration).
- Log the pattern match coordinates.
</step>

<step name="verify_threat_mitigations">
Check each threat mitigation defined in the plan's threat register. Validate that the mitigation component is implemented and covered by automated tests.
</step>

<step name="run_suite_verification">
Execute the full automated test suite to gather a final validation log. Capture the test pass rate and total runtime.
</step>

<step name="write_report">
Generate `${phase_dir}/${padded_phase}-VERIFICATION.md` using the standard `hm-verification` template:
- Mark PASS/FAIL for each must-have item.
- Attach specific run/test evidence logs.
- Document overall Pass/Fail verdict.
</step>

<step name="git_commit">
Stage and commit the generated `VERIFICATION.md` file atomically to git.
</step>

<step name="update_state">
Record verification status in `.planning/STATE.md` and commit.
</step>

</process>

<success_criteria>
- Every plan artifact, truth, and link verified.
- Concrete evidence logs attached to each verdict.
- STRIDE threat mitigations validated.
- `VERIFICATION.md` written and committed.
</success_criteria>
