qfai 1.9.2 → 1.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/README.md +67 -6
  2. package/assets/init/.qfai/assistant/README.md +27 -0
  3. package/assets/init/.qfai/assistant/agents/acceptance-test-engineer.md +1 -0
  4. package/assets/init/.qfai/assistant/agents/backend-engineer.md +1 -0
  5. package/assets/init/.qfai/assistant/agents/completion-reviewer.md +29 -2
  6. package/assets/init/.qfai/assistant/agents/delivery-planner.md +17 -0
  7. package/assets/init/.qfai/assistant/agents/frontend-engineer.md +1 -0
  8. package/assets/init/.qfai/assistant/agents/implementation-reviewer.md +17 -0
  9. package/assets/init/.qfai/assistant/agents/orchestrator.md +2 -2
  10. package/assets/init/.qfai/assistant/agents/qa-gatekeeper.md +183 -5
  11. package/assets/init/.qfai/assistant/agents/test-design-analyst.md +22 -3
  12. package/assets/init/.qfai/assistant/catalog/cli-ux-guidelines.md +2 -2
  13. package/assets/init/.qfai/assistant/catalog/spec_required_files.json +2 -1
  14. package/assets/init/.qfai/assistant/catalog/test-layers-ci-lanes.md +60 -0
  15. package/assets/init/.qfai/assistant/catalog/test-layers.md +430 -13
  16. package/assets/init/.qfai/assistant/catalog/worklog-entry.schema.md +165 -0
  17. package/assets/init/.qfai/assistant/constitution/communication.md +1 -1
  18. package/assets/init/.qfai/assistant/constitution/constitution.md +1 -1
  19. package/assets/init/.qfai/assistant/constitution/drift-protocol.md +359 -10
  20. package/assets/init/.qfai/assistant/constitution/quality.md +35 -5
  21. package/assets/init/.qfai/assistant/constitution/requirements-decomposition.md +37 -0
  22. package/assets/init/.qfai/assistant/constitution/shared-skill-delegation-baseline.md +419 -8
  23. package/assets/init/.qfai/assistant/constitution/shared-skill-operating-baseline.md +122 -5
  24. package/assets/init/.qfai/assistant/constitution/workflow.md +53 -7
  25. package/assets/init/.qfai/assistant/manifest/agent-catalog.yml +439 -946
  26. package/assets/init/.qfai/assistant/manifest/agent-routing.yml +116 -4
  27. package/assets/init/.qfai/assistant/manifest/review-profiles.yml +9 -0
  28. package/assets/init/.qfai/assistant/process/migrations/v1.4.27-atdd-alignment.md +1 -1
  29. package/assets/init/.qfai/assistant/skills/qfai-atdd/SKILL.md +150 -53
  30. package/assets/init/.qfai/assistant/skills/qfai-atdd/references/credential-reuse.md +146 -0
  31. package/assets/init/.qfai/assistant/skills/qfai-atdd/references/red-provenance.md +456 -0
  32. package/assets/init/.qfai/assistant/skills/qfai-atdd/references/review-fix-rounds.md +128 -0
  33. package/assets/init/.qfai/assistant/skills/qfai-atdd/references/scaffolding.md +29 -0
  34. package/assets/init/.qfai/assistant/skills/qfai-atdd/references/shared-test-artifacts.md +96 -0
  35. package/assets/init/.qfai/assistant/skills/qfai-atdd/references/stale-manifest.md +34 -0
  36. package/assets/init/.qfai/assistant/skills/qfai-atdd/references/test-case-depth-checklist.md +52 -5
  37. package/assets/init/.qfai/assistant/skills/qfai-configure/SKILL.md +16 -8
  38. package/assets/init/.qfai/assistant/skills/qfai-discussion/SKILL.md +8 -4
  39. package/assets/init/.qfai/assistant/skills/qfai-discussion/references/design-md-brand-catalog.md +2 -2
  40. package/assets/init/.qfai/assistant/skills/qfai-discussion/references/discussion-completion-matrix.md +17 -7
  41. package/assets/init/.qfai/assistant/skills/qfai-discussion/references/rcp_footer.md +10 -4
  42. package/assets/init/.qfai/assistant/skills/qfai-discussion/references/review-cycle-playbook.md +5 -1
  43. package/assets/init/.qfai/assistant/skills/qfai-discussion/references/ui-bearing-playbook.md +4 -4
  44. package/assets/init/.qfai/assistant/skills/qfai-discussion/references/ui_ux/review_audit_playbook.md +1 -1
  45. package/assets/init/.qfai/assistant/skills/qfai-discussion/references/ui_ux/trend_scan_playbook.md +1 -1
  46. package/assets/init/.qfai/assistant/skills/qfai-discussion/references/ui_ux_best_practices.md +17 -7
  47. package/assets/init/.qfai/assistant/skills/qfai-discussion/templates/01_Context.md +1 -1
  48. package/assets/init/.qfai/assistant/skills/qfai-discussion/templates/02_Inception-Deck.md +1 -1
  49. package/assets/init/.qfai/assistant/skills/qfai-discussion/templates/03_Story-Workshop.md +11 -3
  50. package/assets/init/.qfai/assistant/skills/qfai-discussion/templates/05_Scope.md +5 -2
  51. package/assets/init/.qfai/assistant/skills/qfai-discussion/templates/07_NFR.md +1 -1
  52. package/assets/init/.qfai/assistant/skills/qfai-discussion/templates/09_Constraints.md +7 -4
  53. package/assets/init/.qfai/assistant/skills/qfai-discussion/templates/10_Policy.md +1 -1
  54. package/assets/init/.qfai/assistant/skills/qfai-discussion/templates/11_OQ-Register.md +1 -1
  55. package/assets/init/.qfai/assistant/skills/qfai-discussion/templates/12_OQ-Resolution-Log.md +1 -1
  56. package/assets/init/.qfai/assistant/skills/qfai-discussion/templates/14_Review-Request.md +14 -7
  57. package/assets/init/.qfai/assistant/skills/qfai-discussion/templates/99_delta.md +1 -1
  58. package/assets/init/.qfai/assistant/skills/qfai-discussion/templates/review/Rxx_reviewer.md +16 -7
  59. package/assets/init/.qfai/assistant/skills/qfai-discussion/templates/review/review_request.md +9 -6
  60. package/assets/init/.qfai/assistant/skills/qfai-discussion/templates/review/summary.json +2 -0
  61. package/assets/init/.qfai/assistant/skills/qfai-discussion/templates/uiux/40_screen_contracts.md +3 -2
  62. package/assets/init/.qfai/assistant/skills/qfai-discussion/templates/uiux/50_review_input_bundle.md +4 -2
  63. package/assets/init/.qfai/assistant/skills/qfai-implement/SKILL.md +252 -130
  64. package/assets/init/.qfai/assistant/skills/qfai-implement/references/change-request-reset.md +93 -0
  65. package/assets/init/.qfai/assistant/skills/qfai-implement/references/checkpoint-verification.md +210 -0
  66. package/assets/init/.qfai/assistant/skills/qfai-implement/references/cross-spec-ownership.md +73 -0
  67. package/assets/init/.qfai/assistant/skills/qfai-implement/references/evidence-revision.md +291 -0
  68. package/assets/init/.qfai/assistant/skills/qfai-implement/references/execution-ledger.md +389 -0
  69. package/assets/init/.qfai/assistant/skills/qfai-implement/references/final-checklist.md +28 -0
  70. package/assets/init/.qfai/assistant/skills/qfai-implement/references/finding-classification.md +49 -0
  71. package/assets/init/.qfai/assistant/skills/qfai-implement/references/ledger-preconditions.md +55 -0
  72. package/assets/init/.qfai/assistant/skills/qfai-implement/references/oracle-strength.md +81 -0
  73. package/assets/init/.qfai/assistant/skills/qfai-implement/references/parallelization-policy.md +235 -0
  74. package/assets/init/.qfai/assistant/skills/qfai-implement/references/red-admissibility.md +91 -0
  75. package/assets/init/.qfai/assistant/skills/qfai-implement/references/red-not-observable.md +112 -0
  76. package/assets/init/.qfai/assistant/skills/qfai-implement/references/relevant-test-suite.md +87 -0
  77. package/assets/init/.qfai/assistant/skills/qfai-implement/references/review-artifact-layout.md +44 -0
  78. package/assets/init/.qfai/assistant/skills/qfai-implement/references/round-evidence.md +118 -0
  79. package/assets/init/.qfai/assistant/skills/qfai-implement/references/selector-granularity.md +24 -0
  80. package/assets/init/.qfai/assistant/skills/qfai-implement/references/upstream-artifact-ordering.md +33 -0
  81. package/assets/init/.qfai/assistant/skills/qfai-implement/references/volume-policy.md +149 -0
  82. package/assets/init/.qfai/assistant/skills/qfai-prototyping/SKILL.md +35 -18
  83. package/assets/init/.qfai/assistant/skills/qfai-prototyping/references/evidence-requirements.md +1 -1
  84. package/assets/init/.qfai/assistant/skills/qfai-prototyping/references/generator-prompt.md +106 -7
  85. package/assets/init/.qfai/assistant/skills/qfai-prototyping/references/handoff.md +40 -11
  86. package/assets/init/.qfai/assistant/skills/qfai-prototyping/references/iteration-loop.md +48 -1
  87. package/assets/init/.qfai/assistant/skills/qfai-prototyping/templates/DESIGN.md.sample +6 -0
  88. package/assets/init/.qfai/assistant/skills/qfai-sdd/SKILL.md +87 -22
  89. package/assets/init/.qfai/assistant/skills/qfai-sdd/references/contract-artifact-rules.md +148 -0
  90. package/assets/init/.qfai/assistant/skills/qfai-sdd/references/rcp_footer.md +10 -4
  91. package/assets/init/.qfai/assistant/skills/qfai-sdd/references/review-cycle-playbook.md +5 -1
  92. package/assets/init/.qfai/assistant/skills/qfai-sdd/references/sdd-execution-playbook.md +4 -2
  93. package/assets/init/.qfai/assistant/skills/qfai-sdd/references/sdd-phase-checklists.md +18 -0
  94. package/assets/init/.qfai/assistant/skills/qfai-sdd/references/sdd-quality-gate.md +44 -3
  95. package/assets/init/.qfai/assistant/skills/qfai-sdd/references/sdd-triage.md +60 -7
  96. package/assets/init/.qfai/assistant/skills/qfai-sdd/references/spec-traceability-rules.md +171 -6
  97. package/assets/init/.qfai/assistant/skills/qfai-sdd/templates/change-request.md +125 -0
  98. package/assets/init/.qfai/assistant/skills/qfai-sdd/templates/contracts/db-contract.sample.sql +6 -0
  99. package/assets/init/.qfai/assistant/skills/qfai-sdd/templates/evidence/sdd-spec.md +92 -0
  100. package/assets/init/.qfai/assistant/skills/qfai-sdd/templates/specs/_policies/01_Objective.md +27 -0
  101. package/assets/init/.qfai/assistant/skills/qfai-sdd/templates/specs/_policies/02_Initiative.md +30 -0
  102. package/assets/init/.qfai/assistant/skills/qfai-sdd/templates/specs/_policies/05_Contracts.md +16 -6
  103. package/assets/init/.qfai/assistant/skills/qfai-sdd/templates/specs/_policies/06_Glossary.md +19 -0
  104. package/assets/init/.qfai/assistant/skills/qfai-sdd/templates/specs/_policies/07_Constraints.md +25 -0
  105. package/assets/init/.qfai/assistant/skills/qfai-sdd/templates/specs/_policies/08_Decisions.md +22 -2
  106. package/assets/init/.qfai/assistant/skills/qfai-sdd/templates/specs/_policies/11_Slice-Policy.md +37 -10
  107. package/assets/init/.qfai/assistant/skills/qfai-sdd/templates/specs/spec/02_User-stories.md +20 -0
  108. package/assets/init/.qfai/assistant/skills/qfai-sdd/templates/specs/spec/03_Acceptance-Criteria.md +19 -0
  109. package/assets/init/.qfai/assistant/skills/qfai-sdd/templates/specs/spec/04_Business-Rules.md +32 -3
  110. package/assets/init/.qfai/assistant/skills/qfai-sdd/templates/specs/spec/06_Test-Cases.md +56 -0
  111. package/assets/init/.qfai/assistant/skills/qfai-sdd/templates/specs/spec/07_Decisions.md +29 -2
  112. package/assets/init/.qfai/assistant/skills/qfai-sdd/templates/specs/spec/10_Plan.md +41 -0
  113. package/assets/init/.qfai/assistant/skills/qfai-sdd/templates/specs/spec/16_Traceability-ledger.md +58 -0
  114. package/assets/init/.qfai/assistant/skills/qfai-sdd/templates/specs/spec/tdd/test-list.md +56 -0
  115. package/assets/init/.qfai/assistant/skills/qfai-verify/SKILL.md +57 -102
  116. package/assets/init/.qfai/assistant/skills/qfai-verify/references/articles.md +24 -0
  117. package/assets/init/.qfai/assistant/skills/qfai-verify/references/context-load.md +22 -0
  118. package/assets/init/.qfai/assistant/skills/qfai-verify/references/verify-output-contract.md +48 -0
  119. package/assets/init/.qfai/assistant/skills/qfai-verify/templates/verify-evidence.md +48 -0
  120. package/assets/init/.qfai/assistant/skills/web-research/SKILL.md +25 -7
  121. package/assets/init/.qfai/waivers.yml +11 -5
  122. package/assets/init/root/.github/workflows/qfai-tests.yml +318 -0
  123. package/assets/init/root/.github/workflows/qfai-validate.yml +327 -24
  124. package/assets/init/root/DESIGN.md +6 -0
  125. package/assets/init/root/qfai.config.yaml +15 -12
  126. package/dist/cli/index.cjs +20646 -13620
  127. package/dist/cli/index.cjs.map +1 -1
  128. package/dist/cli/index.mjs +22101 -15061
  129. package/dist/cli/index.mjs.map +1 -1
  130. package/dist/index.cjs +13954 -8829
  131. package/dist/index.cjs.map +1 -1
  132. package/dist/index.d.cts +423 -14
  133. package/dist/index.d.ts +423 -14
  134. package/dist/index.mjs +9330 -4224
  135. package/dist/index.mjs.map +1 -1
  136. package/package.json +22 -19
@@ -48,34 +48,93 @@ routing:
48
48
  rerun_policy: changed-scope-dependents
49
49
  review_profile: default
50
50
 
51
+ # `parallel_groups` describes ROLE FAN-OUT within a phase, not item
52
+ # dispatch. An empty list means no roles run concurrently; it says
53
+ # nothing about item-level parallelism, which `qfai-implement/SKILL.md`
54
+ # `## Parallelization Policy` governs.
55
+ # `iteration` says how often a phase runs. `qfai-implement` drives the TDD
56
+ # micro-cycle one ledger row at a time, so `red`, `build` and `test` run once
57
+ # per row. Without this key the whole phase list read as a single pass over
58
+ # the batch, and the only slot `qa-gatekeeper` had was the terminal `review`
59
+ # phase — by which point production code exists and the RED state the
60
+ # gatekeeper is supposed to observe has been destroyed. The gate could then
61
+ # adjudicate nothing but the implementer's own written account, which is the
62
+ # self-attestation it exists to prevent.
51
63
  - skill: qfai-implement
52
64
  phases:
53
65
  - id: plan
66
+ iteration: per-invocation
54
67
  mandatory_agents: [delivery-planner, test-design-analyst]
55
68
  conditional_agents: []
56
69
  parallel_groups: []
57
70
  blocking_agents: [delivery-planner]
58
71
  rerun_policy: failed-agents-only
59
- - id: build
72
+ # The failing test exists and no production code does. This is the only
73
+ # window in which "watch it fail" is a first-hand observation, so the
74
+ # gatekeeper is mandatory AND blocking here: RED must be confirmed before
75
+ # the row is allowed to proceed to `build`.
76
+ - id: red
77
+ iteration: per-ledger-item
78
+ # `qa-gatekeeper` is **conditional**, not mandatory. `/qfai-atdd`
79
+ # invokes this phase for step 3a alone when a new route or export
80
+ # needs its seam before a RED can be taken — the row has no RED yet,
81
+ # which is the whole reason for the trip. Listed as mandatory, the
82
+ # gate had no assertion failure to judge and could only return
83
+ # REVISE, so `SKILL.md`'s "do not route `qa-gatekeeper` for a
84
+ # seam-only invocation" contradicted this manifest and the round trip
85
+ # stopped. It stays blocking: whenever a RED *is* submitted, its
86
+ # verdict decides.
60
87
  mandatory_agents: []
88
+ # The production owners are conditional here, not absent. Two steps
89
+ # in this phase touch production source before any RED exists, and
90
+ # the orchestrator may not implement (`SKILL.md` Orchestrator
91
+ # Protocol): step 3a's minimal seam, which a new-surface row needs
92
+ # before its failure is an assertion rather than a 404, and step 3c's
93
+ # falsifiability mutation for a handed-over row whose evidence is not
94
+ # written yet. Without them the phase had `qa-gatekeeper` alone and
95
+ # neither step had anyone to perform it.
96
+ conditional_agents: [qa-gatekeeper, frontend-engineer, backend-engineer]
97
+ parallel_groups: []
98
+ blocking_agents: [qa-gatekeeper]
99
+ # `changed-scope-dependents`: the gatekeeper's REVISE here is usually
100
+ # *about* the seam or the mutation — it touched code the row does not
101
+ # own, or the selector did not fail. Re-running only the agent that
102
+ # returned non-PASS re-judges an unchanged artifact and returns the
103
+ # same REVISE, so the row never leaves `red`. Whoever wrote the
104
+ # production edit has to be rerun with it.
105
+ rerun_policy: changed-scope-dependents
106
+ - id: build
107
+ iteration: per-ledger-item
108
+ mandatory_agents: [qa-gatekeeper]
61
109
  conditional_agents: [frontend-engineer, backend-engineer]
62
110
  parallel_groups:
63
111
  - [frontend-engineer, backend-engineer]
64
- blocking_agents: []
112
+ blocking_agents: [qa-gatekeeper]
65
113
  rerun_policy: changed-scope-dependents
66
114
  - id: test
115
+ iteration: per-ledger-item
67
116
  mandatory_agents: []
68
117
  conditional_agents: [acceptance-test-engineer, qa-strategist]
69
118
  parallel_groups: []
70
119
  blocking_agents: []
71
120
  rerun_policy: changed-scope-dependents
121
+ # Still per-item: the reviewers judge one row (or one T1 coherent group),
122
+ # never the whole ledger at once. `qa-gatekeeper` stays listed because the
123
+ # completion gate re-reads its verdicts here; its RED/GREEN observations
124
+ # were already made in `red` and `build`.
72
125
  - id: review
126
+ iteration: per-ledger-item
73
127
  mandatory_agents: [implementation-reviewer, qa-gatekeeper, completion-reviewer]
74
128
  conditional_agents: [product-surface-reviewer]
75
129
  parallel_groups: []
76
- blocking_agents: [qa-gatekeeper, completion-reviewer]
130
+ # `implementation-reviewer` is blocking, not advisory: it is item 8 of the
131
+ # unconditional 11-point gate in qfai-implement/SKILL.md, and every DONE
132
+ # rule in the skill and in shared-skill-delegation-baseline.md is phrased
133
+ # over *blocking* reviewers. Listing it as mandatory-only let an item
134
+ # reach `done` with the code-quality reviewer sitting at REVISE.
135
+ blocking_agents: [implementation-reviewer, qa-gatekeeper, completion-reviewer]
77
136
  rerun_policy: changed-scope-dependents
78
- review_profile: runtime-heavy
137
+ review_profile: implementation-heavy
79
138
 
80
139
  - skill: qfai-atdd
81
140
  phases:
@@ -85,6 +144,49 @@ routing:
85
144
  parallel_groups: []
86
145
  blocking_agents: [test-design-analyst]
87
146
  rerun_policy: failed-agents-only
147
+ # Stage gate P1b. `references/red-provenance.md` branch 1 requires
148
+ # `qa-gatekeeper` to confirm the RED *before any production code exists*,
149
+ # which is the same rule `qfai-implement` applies to its own rows — and
150
+ # there was no phase here to submit that to, so the instruction named a
151
+ # routing phase this skill did not have. It must sit before
152
+ # `implementation`: after the surfaces are built there is nothing left to
153
+ # watch fail.
154
+ - id: red
155
+ # `delivery-planner` is blocking here, ahead of `qa-gatekeeper`:
156
+ # `qfai-implement/SKILL.md` makes it the only authority on whether a
157
+ # selector covers a sufficient slice of its obligation, and requires a
158
+ # scope REVISE to be settled BEFORE the RED is submitted. Approving the
159
+ # RED first leaves the planner only "keep the PASS and open a new row",
160
+ # which cannot repair a handoff taken at the wrong granularity.
161
+ #
162
+ # `qa-gatekeeper` is **conditional**, not mandatory: it judges the rows
163
+ # that have evidence at this gate — the branch 1 ones. A branch 2 row's
164
+ # payload is its falsifiability trio, which by design does not exist
165
+ # until P4b, and the role stops when a row's evidence is missing. Listed
166
+ # as mandatory it therefore stopped a run whose rows are all branch 2
167
+ # before it could reach the P4b handoff that produces the trio: the gate
168
+ # blocked on the absence of something it is the reason for. It stays
169
+ # blocking — when it is routed, its verdict decides.
170
+ #
171
+ # `iteration: per-ledger-item`, matching this manifest's
172
+ # `qfai-implement` red phase. The default is `per-invocation`, which
173
+ # routes each agent once for the whole ledger — so
174
+ # `acceptance-test-engineer` would leave several deliberate REDs open at
175
+ # once and `qa-gatekeeper` would never see a row in its own RED state,
176
+ # neither of which is the one-row-at-a-time loop P1b/P1c require.
177
+ iteration: per-ledger-item
178
+ mandatory_agents: [delivery-planner, acceptance-test-engineer]
179
+ conditional_agents: [qa-gatekeeper]
180
+ parallel_groups: []
181
+ blocking_agents: [delivery-planner, qa-gatekeeper]
182
+ # `changed-scope-dependents`, not `failed-agents-only`: a
183
+ # `delivery-planner` REVISE here means the selector covers too little
184
+ # of its obligation, and the repair is `acceptance-test-engineer`
185
+ # splitting the test — then a fresh `qa-gatekeeper` verdict on the new
186
+ # RED. Re-running only the agent that failed would have the planner
187
+ # re-read an unchanged selector and return the same REVISE, or leave
188
+ # the previous gatekeeper PASS standing over a test that changed.
189
+ rerun_policy: changed-scope-dependents
88
190
  - id: implementation
89
191
  mandatory_agents: [acceptance-test-engineer]
90
192
  conditional_agents: []
@@ -176,3 +278,13 @@ routing:
176
278
  blocking_agents: [qa-gatekeeper, completion-reviewer]
177
279
  rerun_policy: changed-scope-dependents
178
280
  review_profile: runtime-heavy
281
+
282
+ # `rerun_policy` vocabulary (validated by `QFAI-AGENT-013`):
283
+ #
284
+ # - `failed-agents-only` re-run only the agents that did not return PASS
285
+ # - `changed-scope-dependents` re-run every agent whose inputs the change
286
+ # touched, including ones that passed
287
+ #
288
+ # The key was previously on all 23 phases, defined nowhere and read by nothing,
289
+ # so a typo in it was invisible. `constitution/drift-protocol.md` step 4 uses the
290
+ # same vocabulary when a Change Request names its rerun mode.
@@ -16,6 +16,15 @@ profiles:
16
16
  runtime-heavy:
17
17
  always_required: [completion-reviewer, qa-gatekeeper]
18
18
  conditional_required: [implementation-reviewer]
19
+ # `qfai-implement` makes `implementation-reviewer` PASS item 8 of its
20
+ # unconditional 11-point gate, so for that skill the code-quality review is
21
+ # always required and always blocking. It shares `runtime-heavy` with
22
+ # qfai-atdd / qfai-configure / qfai-verify, where the same reviewer is
23
+ # genuinely conditional — hence a profile of its own rather than widening
24
+ # runtime-heavy for all four.
25
+ implementation-heavy:
26
+ always_required: [completion-reviewer, qa-gatekeeper, implementation-reviewer]
27
+ conditional_required: []
19
28
 
20
29
  optional_modes:
21
30
  devils-advocate:
@@ -27,7 +27,7 @@
27
27
  - `tests/integration`
28
28
  4. Remove forbidden references (`TC` annotations in API/E2E tests).
29
29
  5. Re-run:
30
- - `qfai validate --fail-on error`
30
+ - `npx qfai validate --fail-on error`
31
31
 
32
32
  ## Legacy Compatibility
33
33
 
@@ -53,9 +53,11 @@ When unsure, read inputs in this order:
53
53
  - `.qfai/specs/<spec-id>/03_Acceptance-Criteria.md` (AC)
54
54
  - `.qfai/specs/<spec-id>/05_Examples.md` (EX)
55
55
  - `.qfai/specs/<spec-id>/06_Test-Cases.md` (TC)
56
+ - `.qfai/specs/<spec-id>/tdd/test-list.md` (the execution ledger — enumerate the `Layer = E2E` / `Layer = API` / `Layer = Integration` rows this run owes evidence for, with their `TDD-ID`, obligation column and `Selector`)
56
57
  - `.qfai/contracts/api/**` (CON-API)
58
+ - `.qfai/contracts/db/**` (CON-DB)
57
59
  - `.qfai/contracts/ui/**` and `.qfai/contracts/design/**` when the target spec is UI-bearing
58
- - P5: `.qfai/specs/<spec-id>/09_delta.md` (Decision Records; if no spec yet, state "not applicable")
60
+ - P5: `.qfai/specs/<spec-id>/07_Decisions.md` + `.qfai/specs/_policies/08_Decisions.md` (Decision Records, `DR-*`; if no spec yet, state "not applicable")
59
61
  - P6: legacy artifacts (optional only)
60
62
  - `.qfai/specs/<spec-id>/scenario.feature`
61
63
  - coverage ledger files
@@ -69,6 +71,7 @@ Do not read discussion-pack UI/UX sidecars. UI-bearing acceptance tests consume
69
71
  - `.qfai/specs/<spec-id>/03_Acceptance-Criteria.md`
70
72
  - `.qfai/specs/<spec-id>/05_Examples.md`
71
73
  - `.qfai/specs/<spec-id>/06_Test-Cases.md`
74
+ - `.qfai/specs/<spec-id>/tdd/test-list.md` — read, never written. A run that does not enumerate its `Layer = E2E` / `Layer = API` / `Layer = Integration` rows produces no `## Ledger rows advanced` entry for them, and `/qfai-implement` Phase Red step 3b then stops on a missing handoff.
72
75
  - Escalation Mode:
73
76
  - allowed only when `01_Spec.md` Escalation Hook signals ambiguity / conflict / missing constraint / trade-off
74
77
  - read only `.qfai/specs/_policies/01_Objective.md` and `.qfai/specs/_policies/08_Decisions.md`
@@ -91,7 +94,7 @@ Follow `.qfai/assistant/constitution/shared-skill-delegation-baseline.md`.
91
94
  ### Delegation Failure (Hard Stop)
92
95
 
93
96
  - No additional overrides.
94
- - Do not simulate roles. If the first required delegation fails, stop the stage and report remediation.
97
+ - Do not simulate roles. Classify the failure per the baseline taxonomy first: `unavailable` stops the stage with a remediation report; `saturated` uses the bounded retry branch and keeps the stage open.
95
98
 
96
99
  ## Work Orders Summary
97
100
 
@@ -111,9 +114,9 @@ Use the shared schema.
111
114
  - Follow `.qfai/assistant/constitution/shared-skill-delegation-baseline.md#reviewer-gate-baseline`.
112
115
  - Final completion gate MUST be delegated to an independent `completion-reviewer`.
113
116
  - ATDD-specific reviewer checks:
114
- - coverage obligations met: E2E covers `US`, Integration covers `TC`, API covers `CON-API`;
117
+ - coverage obligations met: E2E covers `US`, API covers `CON-API`, and every `TC` **that declares `L3`/`L4`/`L5` or no `Level`** is covered from the directory that `Level` routes to. `L1`/`Unit` and `L2`/`Component` owe nothing here (CRITICAL CONSTRAINTS): the ledger covers them. An existing L1/L2 annotation in `tests/integration/**` is not a violation — the validator declines to count it and declines to flag it — so do not require one to be added, and do not require an existing one to be removed;
115
118
  - Coverage Depth Matrix is reviewed and no unjustified `X` cells remain;
116
- - validation evidence exists and `qfai validate --profile atdd --fail-on error` passes;
119
+ - validation evidence exists and `npx qfai validate --profile atdd --fail-on error --spec <spec-id>` passes;
117
120
  - Drift Protocol is enforced;
118
121
  - test-layer policy is checked against `.qfai/assistant/catalog/test-layers.md`;
119
122
  - coverage floors and ratios are signals, not gates;
@@ -133,7 +136,7 @@ Use the shared template.
133
136
 
134
137
  Use the shared template.
135
138
 
136
- - Required field: `Status (PASS/REVISE)`.
139
+ - Required field: `Status (PASS/REVISE/PENDING)`. `PENDING` marks a gate that could not be run (see the baseline's reviewer-budget branch); it never counts as `PASS`.
137
140
 
138
141
  ## Stage 0 — Steering completion refresh (mandatory)
139
142
 
@@ -148,18 +151,44 @@ Follow `.qfai/assistant/constitution/shared-skill-operating-baseline.md#delta-re
148
151
  - Do NOT declare completion based on unit/component tests.
149
152
  - `10_Plan.md` is the primary How SSOT for execution phases.
150
153
  - If `10_Plan.md` is missing, stop and run owner planning flow before proceeding.
151
- - Completion gate is validation with zero errors (`qfai validate --profile atdd --fail-on error`).
154
+ - Completion gate is validation with zero errors **for this spec**: `npx qfai validate --profile atdd --fail-on error --spec <spec-id>`. The scope flag is not optional bookkeeping. This skill runs one spec per invocation, and unscoped it reports every other spec's `QFAI-ATDD-111` / `-112` obligations — findings this run cannot act on and must not be blocked by. A `--spec` run also writes `<report>/validate.spec-<id>.json` rather than the shared `validate.json`, so the JSON gate artifact is per spec, and an unknown or unparseable value fails the run (`QFAI-SCOPE-001` / `QFAI-SCOPE-002`) instead of silently widening back to the whole repository. **That is not the same as being parallel-safe.** `<report>/validate.log` and the run-log pointer are shared by every run, scoped or not, and nothing serializes them — so two stages running at once can leave that pointer naming the other one's run. Cite the per-run `<report>/run-*/` directory, or this spec's `validate.spec-<id>.json`, as the Validate Hard Gate evidence; do not cite `validate.log` from a run you shared with another stage.
155
+ - **`--spec` scopes the spec-owned rules only, and the gate still fails on the rest.** Every rule whose finding names a spec is scoped: `QFAI-ATDD-111` (US) and `QFAI-ATDD-112` (TC) by the specs they name, `QFAI-ATDD-101` / `-102` by the spec in the unknown token, `QFAI-ATDD-121` / `-122` / `-123` by the specs whose TCs are misplaced, and `D-SCAFFOLD-PLACEHOLDER` by the spec its skeleton belongs to. A scoped run reports all of those for the requested spec and drops a sibling's. What cannot be scoped **does** fail a scoped gate:
156
+ - `QFAI-ATDD-113` (`CON-API`) and `QFAI-ATDD-115` (`CON-DB`) are attributed to `.qfai/contracts/**`, which has no spec owner in the model;
157
+ - a reference, or a scaffold directory, naming a spec number no spec pack has, **and sitting where no spec owns it either**: `--spec` on that number is itself rejected, so nothing would report it otherwise. A file under the canonical `tests/<layer>/spec-NNNN/**` layout is owned by _that_ spec whatever its annotation says, so the same broken reference inside `tests/integration/spec-0002/**` belongs to `--spec 0002` and to no other run — reading it as a repo-wide blocker in a sibling run reports something that run cannot see;
158
+ - anything else reported against a repo-level path.
159
+
160
+ So a sibling spec's uncovered contract exits 1 on this spec's gate. That is a real limit, not a formality. When it happens: record the finding, its owning spec and why it is not this stage's work as a cross-spec obligation in this stage's evidence, and say so in the completion report — do **not** claim the gate passed, weaken the profile, lower `--fail-on`, or waive it. Closing them is the owning spec's next `/qfai-atdd` run. The repo-wide run belongs to `/qfai-verify`, at the end of the stage.
161
+
152
162
  - Coverage obligations are mandatory:
153
163
  - `tests/e2e/**` must cover all required `US-*`.
154
- - `tests/integration/**` must cover all required `TC-*`.
164
+ - Every `TC-*` must be covered from the directory its declared `Level` routes
165
+ to: `L3`/`Integration` -> `tests/integration/**`, `L4`/`API` ->
166
+ `tests/api/**`, `L5`/`E2E` -> `tests/e2e/**`. A TC with no declared `Level`
167
+ routes to `tests/integration/**`.
168
+ - **`L1`/`Unit` and `L2`/`Component` owe nothing here** — out of this skill's
169
+ scope, excluded from `QFAI-ATDD-112`, gated by `tdd/test-list.md` under
170
+ `/qfai-implement`, and named on every run by `QFAI-ATDD-117` (`info`). Do
171
+ not duplicate an L1/L2 annotation into `tests/integration/**` to quiet a
172
+ gate: that is the all-integration collapse `catalog/test-layers.md` lists as
173
+ an anti-pattern.
155
174
  - `tests/api/**` must cover all required `CON-API-*`.
156
- - Forbidden references:
157
- - `tests/api/**` must not contain `QFAI:SPEC-XXXX:TC-YYYY`.
158
- - `tests/e2e/**` must not contain `QFAI:SPEC-XXXX:TC-YYYY`.
175
+ - Forbidden references (a TC annotation outside its declared home):
176
+ `tests/api/**` and `tests/e2e/**` must not contain `QFAI:SPEC-XXXX:TC-YYYY`
177
+ unless that TC declares `Level` `L4`/`API` or `L5`/`E2E` respectively.
159
178
  - Unknown references (`US/TC/CON-API` not declared) must be treated as errors.
179
+ - **The E2E/API ledger rows this stage feeds are bound by `/qfai-implement`'s lifecycle.** See "Execution Ledger" below: a row advanced on none of the three RED-provenance forms is a lifecycle violation.
160
180
  - Floors/ratios are planning signals only, not gates.
161
181
  - Legacy `scenario.feature` or coverage ledgers may exist but are not mandatory inputs for completion.
162
- - Evidence file is required under `.qfai/evidence/` and must not be committed.
182
+ - Evidence file is required under `.qfai/evidence/`. Stage evidence is
183
+ **regenerable** and is not committed. **Governance records are different**:
184
+ Change Requests (`.qfai/decisions/CR-*.md`), durable decision records
185
+ (`.qfai/evidence/decisions/*.json`) and the **Coverage Depth Matrix**
186
+ (`.qfai/evidence/coverage-depth-<spec-id>.md`) are not regenerable and stay
187
+ in version control — the managed `.gitignore` block negates them for that
188
+ reason.
189
+ - **The matrix is a governance record, not a log**, so it is committed:
190
+ `.qfai/evidence/coverage-depth-<spec-id>.md`, one justification per `❌`
191
+ (`references/test-case-depth-checklist.md#where-the-matrix-lives`).
163
192
 
164
193
  ## Completion Contract (Shared)
165
194
 
@@ -168,12 +197,38 @@ Follow `.qfai/assistant/constitution/shared-skill-operating-baseline.md#gate-fai
168
197
 
169
198
  ## Goal
170
199
 
171
- Turn specs/contracts obligations (`US` / `TC` / `CON-API`) into runnable acceptance tests in this repository.
200
+ Turn specs/contracts obligations (`US` / `TC` / `CON-API` / `CON-DB`) into runnable acceptance tests in this repository.
201
+
202
+ ## Execution Ledger: the rows this skill feeds
203
+
204
+ `.qfai/specs/<spec-id>/tdd/test-list.md` is `/qfai-implement`'s execution
205
+ ledger, and `qfai-implement/SKILL.md` states the split: **`Layer = E2E`,
206
+ `Layer = API` and `Layer = Integration` rows are tracked there, but their tests
207
+ are authored here.** Integration is there because this skill's scope puts it
208
+ there: `QFAI-ATDD-112` covers every `L3` TC, and every TC with no declared
209
+ `Level`, from `tests/integration/**`, and P4 writes those tests. Self-owned,
210
+ they had `/qfai-implement` demand a fresh RED for a test already green here.
211
+
212
+ - **This skill does not write the ledger.** `/qfai-implement` owns the `Status` / `DR-ID` / `Evidence` cells of every row — one writer, as `constitution/drift-protocol.md` grants. This stage owes the **evidence those cells point at**, in `.qfai/evidence/atdd-<spec-id>.md`.
213
+ - **The lifecycle is `../qfai-implement/references/execution-ledger.md#allowed-transitions`**: forward-only from `todo`, and `todo -> red` requires an **admissible RED** observed before the code that makes it pass exists.
214
+ - **A fresh spec has none of these rows yet, and this stage cannot create them** — zero is a legitimate count, not "nothing to do": `references/red-provenance.md#a-spec-with-no-atdd-owned-rows`.
215
+ - **The stage order makes that a real question**: Work Orders build the surfaces a journey needs (P3, P4), so a journey written after them passes first run — an anomaly bound for `exception`, which then becomes the only reachable terminal state.
216
+
217
+ ### RED provenance for an ATDD-owned row (MUST)
218
+
219
+ **Read `references/red-provenance.md` before advancing any row.** It defines
220
+ three branches, in order — observed RED (stage gate **P1b**, before P2-P4 build
221
+ any surface), falsifiability when the surface is already there, and `exception`
222
+ with a `DR-*` when neither is available. Take the first that applies, record
223
+ which one, and put the evidence in `.qfai/evidence/atdd-<spec-id>.md` under
224
+ `## Ledger rows advanced` — `/qfai-implement` consumes that entry rather than
225
+ re-observing a RED. Branch 3 is the last resort: a stage that routes every row
226
+ to `exception` has recorded that it did not try branches 1 and 2.
172
227
 
173
228
  ## Scope (ATDD only)
174
229
 
175
- - In scope: E2E, API, Integration.
176
- - Out of scope: Unit and Component (`/qfai-implement`).
230
+ In scope: E2E, API, Integration. Out of scope: Unit and Component
231
+ (`/qfai-implement`). Tests that must sign in: `references/credential-reuse.md`.
177
232
 
178
233
  ## Non-goals
179
234
 
@@ -183,18 +238,16 @@ Turn specs/contracts obligations (`US` / `TC` / `CON-API`) into runnable accepta
183
238
  ## Mandatory Outputs
184
239
 
185
240
  1. Test Volume Estimate (signal table with evidence)
186
- 2. **Coverage Depth Matrix** (per spec; see `references/test-case-depth-checklist.md`)
187
- 3. Coverage obligations checklist (`US` / `TC` / `CON-API`)
188
- 4. Implemented tests per layer (E2E/API/Integration)
189
- 5. Reviewer notes (`PASS` or concrete rework list)
190
- 6. Evidence file: `.qfai/evidence/atdd-<spec-id>.md`
241
+ 2. **Coverage Depth Matrix**, written to `.qfai/evidence/coverage-depth-<spec-id>.md` (per spec; template and scoring in `references/test-case-depth-checklist.md`). Committed — see CRITICAL CONSTRAINTS.
242
+ 3. Coverage obligations checklist (`US` / `TC` / `CON-API`), and the implemented tests per layer (E2E/API/Integration)
243
+ 4. Reviewer notes (`PASS` or concrete rework list)
244
+ 5. Evidence file: `.qfai/evidence/atdd-<spec-id>.md`
191
245
 
192
246
  ## Volume Signals (mandatory, not gates)
193
247
 
194
- - E2E signal: number of required `US-*`
195
- - API signal: number of declared `CON-API-*`
196
- - Integration signal: number of required `TC-*`
197
- - When signals are low/high, propose options and recommendation; do not fail solely on signal values.
248
+ E2E = required `US-*`, API = declared `CON-API-*`, Integration = required `TC-*`.
249
+ When a signal is low or high, propose options and a recommendation; never fail
250
+ on a signal value alone.
198
251
 
199
252
  ### Estimator output table (required)
200
253
 
@@ -204,28 +257,45 @@ Turn specs/contracts obligations (`US` / `TC` / `CON-API`) into runnable accepta
204
257
  | API | #CON | API_s | API contracts | |
205
258
  | Integration | #TC | INT_s | test cases | |
206
259
 
260
+ ## Scaffolding
261
+
262
+ `npx qfai atdd scaffold --spec <spec-id>` bulk-emits one placeholder test per `TC-*` **this skill owns**, each carrying its `QFAI:SPEC-XXXX:TC-YYYY` annotation, into `tests/integration/<spec-id>/` — the directory `QFAI-ATDD-112` scans. It is idempotent. `L1`/`L2` and `L4`/`L5` TCs are skipped and named on stderr, and a skeleton left in placeholder shape escalates: `references/scaffolding.md`.
263
+
207
264
  ## Annotation obligations (mandatory)
208
265
 
209
266
  Every generated ATDD test MUST include QFAI annotations by layer:
210
267
 
211
- - `tests/e2e/**`: `QFAI:SPEC-XXXX:US-YYYY`
212
- - `tests/integration/**`: `QFAI:SPEC-XXXX:TC-YYYY`
213
- - `tests/api/**`: `QFAI:CON-API-XXXX`
268
+ - `tests/e2e/**`: `QFAI:SPEC-XXXX:US-YYYY` (plus `QFAI:SPEC-XXXX:TC-YYYY` for a TC that declares `Level` `L5`/`E2E`)
269
+ - `tests/integration/**`: `QFAI:SPEC-XXXX:TC-YYYY` (TCs declaring `L3`/`Integration`, and TCs with no declared `Level`)
270
+ - `tests/api/**`: `QFAI:CON-API-XXXX` (plus `QFAI:SPEC-XXXX:TC-YYYY` for a TC that declares `Level` `L4`/`API`)
271
+ - `tests/integration/**` also carries `QFAI:CON-DB-XXXX` for every declared DB
272
+ contract the slice exercises
214
273
 
215
274
  Notes:
216
275
 
276
+ - A TC's annotation belongs in exactly one directory — the one its declared `Level` routes to. Elsewhere it is both uncovered (`QFAI-ATDD-112`) and forbidden, symmetrically: one left behind in `tests/integration/**` after the TC moved to `L4`/`L5` is rejected by `QFAI-ATDD-123` just as an early one in `tests/api/**` is rejected by `QFAI-ATDD-121`.
217
277
  - AC annotations are optional in code.
218
278
  - `QFAI:CON-API-*` in E2E is not forbidden, but contract guarantee belongs to API tests.
219
279
 
220
280
  ## Success Criteria (Definition of Done)
221
281
 
222
282
  - All required `US` are covered by E2E tests.
223
- - All required `TC` are covered by integration tests.
283
+ - All required `TC` are covered from the directory their declared `Level` routes
284
+ to (`L3`/`Integration` -> `tests/integration/**`, `L4`/`API` ->
285
+ `tests/api/**`, `L5`/`E2E` -> `tests/e2e/**`, no declared `Level` ->
286
+ `tests/integration/**`). **`L1`/`Unit` and `L2`/`Component` are outside this
287
+ obligation** — the ledger covers them — so a spec whose TCs are all L1/L2 is
288
+ done here with no ATDD annotation at all. Duplicating a TC into a second layer
289
+ is a not-done condition, not extra credit.
224
290
  - All required `CON-API` are covered by API tests.
225
- - Validation passes: `qfai validate --profile atdd --fail-on error`.
291
+ - All required `CON-DB` are covered by integration tests (`QFAI-ATDD-115`); a contract
292
+ outside the current slice is deferred with `-- x-qfai-status: planned`, not left uncovered.
293
+ - Validation passes for this spec: `npx qfai validate --profile atdd --fail-on error --spec <spec-id>`.
226
294
  - Repository quality gates (format/lint/type/tests/pack) pass with evidence.
227
295
  - Evidence file exists and includes work orders + reviewer notes.
296
+ - Every ledger row this cycle advanced carries one of the three RED-provenance forms — an observed RED pair with its `Oracle proof`, the `Satisfied-by` + falsifiability trio, or a `DR-*` recording why neither was available — and `qa-gatekeeper` has accepted it. The third form is a valid _branch_, and it is **not a completion**: `exception` is a blocking output and needs a user-approved `TDDLIST-001` waiver, or the row is parked and the spec stays open (`references/red-provenance.md#branch-3-does-not-close-a-spec-on-its-own`).
228
297
  - Completion is approved by a reviewer who did not implement tests.
298
+ - **The P8 reviewer's `Audited evidence hash` is recomputed before completion is declared**, from the current stage evidence file and Coverage Depth Matrix, by the stage-review procedure that produced it (`.qfai/assistant/constitution/shared-skill-delegation-baseline.md#reviewer-response-template`); a mismatch means the evidence moved after the verdict. **Seal the P8 pack too**: when the last reviewer response lands, and before this stage writes its verdict, hash the pack this stage opened — `.qfai/review/review-<timestamp>/`, whole — by the same procedure, and record it **outside the pack** in the stage evidence file's `## Final status` as `Review pack:` (that path) and `Review pack seal:` (that hash). That section is the one part excluded from the P8 audit subject, so writing it there does not stale the verdict, and it exists even on a spec with no ATDD-owned rows — where there is no item evidence entry to hold the seal at all. At completion, recompute the seal over the recorded path and compare it with the **recorded** value — `../qfai-implement/references/evidence-revision.md` states that rule once and it applies here: `## Final status` is outside every audit subject and outside the working-tree revision, so an expected value read from the working tree could be rewritten in the same pass that edited the pack, and every recomputation would still agree, and check that `## Final status` says what that pack says. The recording and the recomputation must be two moments: a value computed from the pack at completion always matches itself whatever was edited in between, and the stage hash covers the evidence but not the verdict, so a `REVISE` edited to `PASS` in the response, the summary and the status together left every recomputation unchanged. On a spec with no ATDD-owned rows `/qfai-implement`'s gate item 10 never runs, so without this the stored hash was written by P8 and read by nobody — and the evidence tree is out of the working-tree revision, so a later edit moved nothing else either.
229
299
 
230
300
  ## Not-done criteria
231
301
 
@@ -234,6 +304,8 @@ Notes:
234
304
  - Tests exist but were never executed.
235
305
  - Validation evidence is missing or failing.
236
306
  - Coverage Depth Matrix is missing or contains unjustified ❌ cells (normal-path-only coverage is incomplete).
307
+ - A ledger row was advanced past `todo` with none of the three forms — no observed RED, no falsifiability evidence, and no `DR-*`.
308
+ - A row was sent to `exception` without a `DR-*` recording why **both** branches were unavailable. "The surface was built earlier in this cycle" is not such a reason.
237
309
 
238
310
  ## Failure handling (mandatory)
239
311
 
@@ -244,19 +316,17 @@ Notes:
244
316
 
245
317
  Create and update: `.qfai/evidence/atdd-<spec-id>.md`
246
318
 
247
- Required sections:
319
+ Required sections: the template below is the list. Two of them carry a contract
320
+ the heading cannot:
248
321
 
249
- - Objective
250
- - Inputs reviewed (files/paths)
251
- - Decisions made (with rationale)
252
- - Work performed (what changed, where)
253
- - Commands executed + key outputs
254
- - Test volume estimate
255
- - Coverage obligations checklist
256
- - Work Orders Summary
257
- - Execution logs
258
- - Gaps / Open risks
259
- - Final status (PASS/FAIL) + who confirmed
322
+ - **Ledger rows advanced** — an index table plus one `### TDD-NNNN` section per
323
+ row. Exactly one form per row, never both and never neither; the cell is an
324
+ anchor and the payload goes in the section
325
+ (`references/red-provenance.md#evidence-shape`).
326
+ - **Coverage Depth Matrix** — a link to
327
+ `.qfai/evidence/coverage-depth-<spec-id>.md` and the `✅`/`⚠️`/`❌` totals.
328
+ The matrix and its per-`❌` justifications live in that committed file;
329
+ restating them here would lose them.
260
330
 
261
331
  Template:
262
332
 
@@ -277,6 +347,15 @@ Template:
277
347
 
278
348
  ## Coverage obligations checklist
279
349
 
350
+ ## Ledger rows advanced
351
+
352
+ <!-- Index table + one `### TDD-NNNN` section per row:
353
+ `references/red-provenance.md#evidence-shape`. -->
354
+
355
+ ## Coverage Depth Matrix
356
+
357
+ See `.qfai/evidence/coverage-depth-<spec-id>.md` (committed). Totals: ✅ N / ⚠️ N / ❌ N.
358
+
280
359
  ## Work Orders Summary
281
360
 
282
361
  ## Execution logs
@@ -290,9 +369,7 @@ Template:
290
369
 
291
370
  - **Test Case Depth Analyst**: `test-design-analyst` evaluates test cases using `references/test-case-depth-checklist.md`, produces Coverage Depth Matrix, flags gaps in boundary/error/edge coverage.
292
371
  - Test Volume Estimator: compute US/TC/CON signals with evidence.
293
- - ATDD E2E Implementer: implement required `US` coverage.
294
- - ATDD API Implementer: implement required `CON-API` coverage.
295
- - ATDD Integration Implementer: implement required `TC` coverage.
372
+ - ATDD Implementers, one per layer: required `US` coverage in E2E, `CON-API` in API, `TC` in Integration.
296
373
  - Reviewer: validate coverage obligations + gate results + Coverage Depth Matrix (non-edit).
297
374
  - Runtime Gatekeeper: run suites and capture logs.
298
375
 
@@ -303,11 +380,29 @@ Template:
303
380
 
304
381
  ## Stage Gates (Do not skip)
305
382
 
306
- - P0: Plan and obligations checklist prepared.
307
- - P1: Layer assignment validated.
383
+ - P0: Plan and obligations checklist prepared. A project whose routing has no
384
+ `red` phase predates it: `references/red-provenance.md#a-project-without-the-red-phase`.
385
+ - P1: Layer assignment validated against `.qfai/assistant/catalog/test-layers.md#layer-derivation-procedure-normative`.
386
+ - P1b: **A branch is chosen for every row**, provisional until its handoff.
387
+ - P1c: **A branch 1 row is discharged in that loop** — write the test, take the
388
+ RED, `qa-gatekeeper` PASS, hand it to `/qfai-implement`, GREEN, checkpoint —
389
+ before the next branch-1 row's failing test is written, and before P2-P4 build
390
+ any surface. One loop per `TDD-ID`; the nested run is an item cycle, not a
391
+ completion gate (`references/red-provenance.md#what-the-nested-run-owes`).
392
+ - P1d: **Branch 3 rows are judged here, then handed over.** Route
393
+ `qa-gatekeeper` on the `DR-*` — the claim is that the obligation genuinely
394
+ cannot be observed — and hand the row over **with that PASS recorded**. P1b's
395
+ gatekeeper judges branch 1 only and `/qfai-implement`'s exception path writes
396
+ `todo -> exception` and stops, so without this a correct branch-3 row reached
397
+ a terminal status judged by nobody. `/qfai-implement` is the only writer of
398
+ `Status` / `DR-ID` / `Evidence`, so every branch needs a handoff; which goes
399
+ when: `references/red-provenance.md#which-stage-hands-a-row-over`.
308
400
  - P2: E2E implementation completed.
309
401
  - P3: API implementation completed.
310
402
  - P4: Integration implementation completed.
403
+ - P4b: **Branch 2 rows are handed over**, after P4 and before P6 — their mutation
404
+ needs the surface P2-P4 build, the trio is the row's RED payload, and that nested
405
+ run is an item cycle like P1c's (`references/red-provenance.md#what-the-nested-run-owes`).
311
406
  - P5: Validation gate passed.
312
407
  - P6: Runtime evidence captured.
313
408
  - P7: Repo quality gates passed.
@@ -321,9 +416,13 @@ Before declaring completion:
321
416
  2. Run:
322
417
 
323
418
  ```bash
324
- qfai validate --profile atdd --fail-on error
419
+ npx qfai validate --profile atdd --fail-on error --spec <spec-id>
325
420
  ```
326
421
 
422
+ `--spec` scopes the gate to the spec this invocation owns. Omitting it makes
423
+ the gate report obligations belonging to specs this run never touched, which
424
+ is how a spec with every obligation discharged still fails to close.
425
+
327
426
  3. Run repository standard gates:
328
427
  - format check
329
428
  - lint
@@ -343,11 +442,9 @@ If commands cannot be run due to environment limits, request user execution and
343
442
 
344
443
  ## DONE Declaration (Mandatory Output)
345
444
 
346
- When declaring DONE, include:
347
-
348
- - Referenced inputs (instructions/steering and spec delta)
349
- - DR-IDs referenced (or "none")
350
- - Confirmation that no rejected options were reintroduced (or RE-OPEN DR-IDs)
445
+ Include the referenced inputs (instructions/steering and spec delta), the DR-IDs
446
+ referenced (or "none"), and confirmation that no rejected options were
447
+ reintroduced (or the RE-OPEN DR-IDs).
351
448
 
352
449
  ## FINAL CHECKLIST (Check Last)
353
450
 
@@ -397,6 +494,6 @@ A skill MAY narrow the auto-decide bucket (drop entries) but MUST NOT widen it.
397
494
 
398
495
  project_memory:
399
496
 
400
- - Coverage obligations stay layer-pinned: tests/e2e/** must cover all required US; tests/integration/** all required TC; tests/api/\*\* all required CON-API.
401
- - Forbidden references guard the test-layer policy: tests/api/** must not carry QFAI:SPEC-XXXX:TC-YYYY annotations; tests/e2e/** likewise.
497
+ - Coverage obligations stay layer-pinned for US and CON-API: tests/e2e/** must cover all required US; tests/api/\*\* all required CON-API. Each TC declaring L3/L4/L5, or no Level, is covered from the directory that Level routes to (L3/Integration -> tests/integration/**, L4/API -> tests/api/\*\*, L5/E2E -> tests/e2e/\*\*; no declared Level -> tests/integration/\*\*). L1/Unit and L2/Component owe no ATDD annotation — tdd/test-list.md covers them. An existing one in tests/integration/\*\* is neither counted nor flagged, so do not require adding or removing it.
498
+ - Forbidden references guard the test-layer policy: a TC annotation outside its declared home is rejected — tests/api/** must not carry QFAI:SPEC-XXXX:TC-YYYY unless that TC declares L4/API, and tests/e2e/** likewise unless it declares L5/E2E.
402
499
  - Floor / ratio signals are planning hints, never gates; legacy scenario.feature / coverage ledger files remain optional inputs.