devflow-kit 3.2.0 → 3.4.0

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 (188) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +1 -1
  3. package/dist/agents/code.md +330 -0
  4. package/{src/assets → dist}/agents/design.md +11 -1
  5. package/{src/assets → dist}/agents/diagnose.md +17 -13
  6. package/dist/agents/git.md +29 -56
  7. package/{src/assets → dist}/agents/knowledge.md +8 -5
  8. package/{src/assets → dist}/agents/research.md +21 -2
  9. package/{src/assets → dist}/agents/review.md +18 -7
  10. package/{src/assets → dist}/agents/scrutinize.md +35 -11
  11. package/dist/agents/skim.md +148 -0
  12. package/{src/assets → dist}/agents/triage.md +8 -2
  13. package/dist/cli/commands/init.js +62 -0
  14. package/dist/cli/commands/learning.js +63 -8
  15. package/dist/cli/commands/uninstall.js +42 -1
  16. package/dist/commands/bug-analysis.md +30 -8
  17. package/dist/commands/code-review.md +142 -61
  18. package/dist/commands/debug.md +15 -13
  19. package/dist/commands/dynamic-build.md +176 -130
  20. package/dist/commands/dynamic-plan.md +31 -19
  21. package/dist/commands/dynamic-profile.md +27 -13
  22. package/dist/commands/dynamic-tickets.md +28 -14
  23. package/dist/commands/explore.md +16 -14
  24. package/dist/commands/implement.md +163 -158
  25. package/dist/commands/plan.md +37 -24
  26. package/dist/commands/release.md +69 -4
  27. package/dist/commands/research.md +33 -11
  28. package/dist/commands/resolve.md +61 -47
  29. package/dist/commands/self-review.md +50 -32
  30. package/dist/core/agent-models.js +53 -7
  31. package/dist/core/assets.js +55 -10
  32. package/dist/core/claude-md-audit.js +190 -0
  33. package/dist/core/feature-switch.js +20 -1
  34. package/dist/core/flags.js +28 -0
  35. package/dist/core/fs-atomic.js +8 -3
  36. package/dist/core/learning-tuning-config.js +8 -0
  37. package/dist/core/learning-variants.js +213 -0
  38. package/dist/core/manifest.js +62 -0
  39. package/dist/core/mds-variants.js +38 -1
  40. package/dist/core/plugins.js +78 -11
  41. package/{src/assets → dist/learning-off}/agents/code.md +77 -28
  42. package/dist/learning-off/agents/design.md +119 -0
  43. package/dist/learning-off/agents/diagnose.md +210 -0
  44. package/dist/learning-off/agents/knowledge.md +90 -0
  45. package/dist/learning-off/agents/research.md +149 -0
  46. package/dist/learning-off/agents/review.md +228 -0
  47. package/dist/learning-off/agents/scrutinize.md +117 -0
  48. package/{src/assets → dist/learning-off}/agents/skim.md +5 -10
  49. package/dist/learning-off/agents/triage.md +163 -0
  50. package/dist/learning-off/commands/bug-analysis.md +420 -0
  51. package/dist/learning-off/commands/code-review.md +525 -0
  52. package/dist/learning-off/commands/debug.md +294 -0
  53. package/dist/learning-off/commands/dynamic-build.md +1255 -0
  54. package/dist/learning-off/commands/dynamic-plan.md +424 -0
  55. package/dist/learning-off/commands/dynamic-profile.md +214 -0
  56. package/dist/learning-off/commands/dynamic-tickets.md +632 -0
  57. package/dist/learning-off/commands/explore.md +210 -0
  58. package/dist/learning-off/commands/implement.md +808 -0
  59. package/dist/learning-off/commands/plan.md +664 -0
  60. package/dist/learning-off/commands/release.md +310 -0
  61. package/dist/learning-off/commands/research.md +222 -0
  62. package/dist/learning-off/commands/resolve.md +837 -0
  63. package/dist/learning-off/commands/self-review.md +266 -0
  64. package/dist/skills/git/references/tracker/_contract.md +33 -0
  65. package/dist/skills/git/references/tracker/github/fetch-issue.md +2 -0
  66. package/dist/skills/git/references/tracker/github/fetch-issues-batch.md +2 -0
  67. package/dist/skills/git/references/tracker/github/gather-release-evidence.md +5 -1
  68. package/dist/skills/git/references/tracker/github/post-wave-report.md +2 -0
  69. package/dist/skills/git/references/tracker/github/setup-task.md +12 -0
  70. package/dist/skills/git/references/tracker/jira/associate-release.md +1 -1
  71. package/dist/skills/git/references/tracker/jira/fetch-issue.md +2 -0
  72. package/dist/skills/git/references/tracker/jira/fetch-issues-batch.md +2 -0
  73. package/dist/skills/git/references/tracker/jira/gather-release-evidence.md +5 -1
  74. package/dist/skills/git/references/tracker/jira/post-wave-report.md +2 -0
  75. package/dist/skills/git/references/tracker/jira/setup-task.md +14 -2
  76. package/dist/skills/git/references/tracker/linear/associate-release.md +1 -1
  77. package/dist/skills/git/references/tracker/linear/fetch-issue.md +2 -0
  78. package/dist/skills/git/references/tracker/linear/fetch-issues-batch.md +2 -0
  79. package/dist/skills/git/references/tracker/linear/gather-release-evidence.md +5 -1
  80. package/dist/skills/git/references/tracker/linear/post-wave-report.md +2 -0
  81. package/dist/skills/git/references/tracker/linear/setup-task.md +14 -2
  82. package/dist/targets/claude-code/installer.js +72 -36
  83. package/dist/targets/claude-code/language-stamp.js +185 -0
  84. package/dist/targets/claude-code/learning-install.js +489 -0
  85. package/package.json +1 -1
  86. package/src/assets/agents/code.mds +339 -0
  87. package/src/assets/agents/design.mds +149 -0
  88. package/src/assets/agents/diagnose.mds +225 -0
  89. package/src/assets/agents/evaluate.md +12 -25
  90. package/src/assets/agents/git.mds +29 -56
  91. package/src/assets/agents/knowledge.mds +125 -0
  92. package/src/assets/agents/learning.md +4 -6
  93. package/src/assets/agents/research.mds +176 -0
  94. package/src/assets/agents/review.mds +286 -0
  95. package/src/assets/agents/scrutinize.mds +132 -0
  96. package/src/assets/agents/simplify.md +20 -0
  97. package/src/assets/agents/skim.mds +161 -0
  98. package/src/assets/agents/synthesize.md +12 -0
  99. package/src/assets/agents/test.md +2 -2
  100. package/src/assets/agents/triage.mds +194 -0
  101. package/src/assets/agents/validate.md +15 -8
  102. package/src/assets/commands/_partials/_compliance.mds +5 -4
  103. package/src/assets/commands/_partials/_decisions.mds +31 -0
  104. package/src/assets/commands/_partials/_engine.mds +29 -24
  105. package/src/assets/commands/_partials/_knowledge.mds +26 -13
  106. package/src/assets/commands/_partials/_plan_contract.mds +1 -1
  107. package/src/assets/commands/_partials/_preamble.mds +33 -9
  108. package/src/assets/commands/_partials/_publication.mds +5 -4
  109. package/src/assets/commands/_partials/_settings.mds +13 -5
  110. package/src/assets/commands/_partials/_wave.mds +16 -6
  111. package/src/assets/commands/bug-analysis.mds +24 -2
  112. package/src/assets/commands/code-review.mds +148 -45
  113. package/src/assets/commands/debug.mds +17 -1
  114. package/src/assets/commands/dynamic-build.mds +144 -65
  115. package/src/assets/commands/dynamic-plan.mds +36 -6
  116. package/src/assets/commands/dynamic-profile.mds +9 -1
  117. package/src/assets/commands/dynamic-tickets.mds +16 -2
  118. package/src/assets/commands/explore.mds +27 -1
  119. package/src/assets/commands/implement.mds +171 -138
  120. package/src/assets/commands/plan.mds +47 -8
  121. package/src/assets/commands/{release.md → release.mds} +27 -24
  122. package/src/assets/commands/research.mds +28 -4
  123. package/src/assets/commands/resolve.mds +69 -17
  124. package/src/assets/commands/self-review.mds +43 -13
  125. package/src/assets/mds/tracker/_common.mds +1 -1
  126. package/src/assets/mds/tracker/_contract.mds +72 -0
  127. package/src/assets/mds/tracker/_github.mds +13 -2
  128. package/src/assets/mds/tracker/_jira.mds +17 -5
  129. package/src/assets/mds/tracker/_linear.mds +17 -5
  130. package/src/assets/mds/tracker/_mcp.mds +2 -2
  131. package/src/assets/mds/tracker/_steps.mds +97 -0
  132. package/src/assets/rules/context-economy.md +10 -0
  133. package/src/assets/rules/go.md +1 -0
  134. package/src/assets/rules/java.md +1 -0
  135. package/src/assets/rules/python.md +1 -0
  136. package/src/assets/rules/rust.md +1 -0
  137. package/src/assets/rules/typescript.md +1 -0
  138. package/src/assets/scripts/ci-wait.cjs +636 -0
  139. package/src/assets/scripts/claude-md-audit.cjs +611 -0
  140. package/src/assets/scripts/hooks/assets/orchestrator-charter.md +2 -3
  141. package/src/assets/scripts/hooks/background-memory-update +290 -9
  142. package/src/assets/scripts/hooks/json-helper.cjs +13 -5
  143. package/src/assets/scripts/hooks/json-parse +34 -10
  144. package/src/assets/scripts/hooks/session-start-context +315 -7
  145. package/src/assets/scripts/release-trace.cjs +27 -10
  146. package/src/assets/skills/accessibility/SKILL.md +1 -1
  147. package/src/assets/skills/apply-decisions/SKILL.md +12 -82
  148. package/src/assets/skills/apply-feature-knowledge/SKILL.md +9 -43
  149. package/src/assets/skills/architecture/SKILL.md +1 -1
  150. package/src/assets/skills/boundary-validation/SKILL.md +1 -1
  151. package/src/assets/skills/complexity/SKILL.md +1 -1
  152. package/src/assets/skills/compliance/SKILL.md +1 -1
  153. package/src/assets/skills/consistency/SKILL.md +1 -1
  154. package/src/assets/skills/database/SKILL.md +1 -1
  155. package/src/assets/skills/dependencies/SKILL.md +1 -1
  156. package/src/assets/skills/dependency-research/SKILL.md +3 -6
  157. package/src/assets/skills/design-review/SKILL.md +1 -1
  158. package/src/assets/skills/docs-framework/SKILL.md +1 -1
  159. package/src/assets/skills/documentation/SKILL.md +1 -1
  160. package/src/assets/skills/feature-knowledge/SKILL.md +43 -12
  161. package/src/assets/skills/gap-analysis/SKILL.md +1 -1
  162. package/src/assets/skills/git/SKILL.md +1 -1
  163. package/src/assets/skills/go/SKILL.md +1 -1
  164. package/src/assets/skills/java/SKILL.md +1 -1
  165. package/src/assets/skills/patterns/SKILL.md +1 -1
  166. package/src/assets/skills/performance/SKILL.md +1 -1
  167. package/src/assets/skills/python/SKILL.md +1 -1
  168. package/src/assets/skills/qa/SKILL.md +1 -3
  169. package/src/assets/skills/quality-gates/SKILL.md +10 -13
  170. package/src/assets/skills/quality-gates/references/report-template.md +20 -20
  171. package/src/assets/skills/react/SKILL.md +1 -1
  172. package/src/assets/skills/regression/SKILL.md +1 -1
  173. package/src/assets/skills/reliability/SKILL.md +1 -1
  174. package/src/assets/skills/research-codebase/SKILL.md +1 -1
  175. package/src/assets/skills/research-competitor/SKILL.md +1 -1
  176. package/src/assets/skills/research-external/SKILL.md +1 -1
  177. package/src/assets/skills/research-technology/SKILL.md +1 -1
  178. package/src/assets/skills/review-methodology/SKILL.md +1 -1
  179. package/src/assets/skills/rust/SKILL.md +1 -1
  180. package/src/assets/skills/security/SKILL.md +1 -1
  181. package/src/assets/skills/software-design/SKILL.md +1 -1
  182. package/src/assets/skills/test-driven-development/SKILL.md +9 -29
  183. package/src/assets/skills/testing/SKILL.md +1 -1
  184. package/src/assets/skills/typescript/SKILL.md +1 -1
  185. package/src/assets/skills/ui-design/SKILL.md +1 -1
  186. package/src/assets/skills/worktree-support/SKILL.md +3 -55
  187. package/src/assets/skills/worktree-support/references/discovery.md +48 -0
  188. package/src/assets/skills/worktree-support/references/roots.md +2 -2
@@ -4,6 +4,7 @@ output-dir: dist/commands
4
4
  ---
5
5
  @import { knowledge_writeback } from "./_partials/_knowledge.mds"
6
6
  @import { decisions_load } from "./_partials/_decisions.mds"
7
+ @import "./_partials/_settings.mds" as settings
7
8
  # Explore Command
8
9
 
9
10
  Explore a codebase area by spawning parallel agents for flow tracing, dependency mapping, and pattern analysis. Findings are synthesized into structured output with file:line references, with optional feature knowledge created as a byproduct.
@@ -31,21 +32,34 @@ $ARGUMENTS
31
32
 
32
33
  ## Phases
33
34
 
35
+ <!-- learning:on -->
34
36
  ### Phase 1: Load Decisions (Orchestrator-Local)
37
+ <!-- learning:off -->
38
+ ### Phase 1: Resolve Settings
39
+ <!-- learning:end -->
35
40
 
41
+ <!-- learning:on -->
36
42
  **Produces:** DECISIONS_CONTEXT
37
43
 
38
- {{decisions_load()}}
44
+ <!-- learning:end -->
45
+ {{settings.settings_resolve()}}
39
46
 
47
+ {{decisions_load()}}
48
+ <!-- learning:on -->
40
49
  The orchestrator uses `DECISIONS_CONTEXT` locally when framing exploration — prior decisions and pitfalls suggest specific areas to investigate. Follow `devflow:apply-decisions` to Read full entry bodies on demand. **Do NOT pass `DECISIONS_CONTEXT` to Explore sub-agents** — decisions context stays in the orchestrator, not in the investigation workers.
41
50
 
51
+ <!-- learning:end -->
42
52
  **No up-front feature knowledge load** — explore investigation workers read code directly to avoid confirmation bias. Feature knowledge is only created as a write-back at the end, after exploration is complete.
43
53
 
44
54
  ### Phase 2: Orient
45
55
 
46
56
  **Produces:** ORIENT_OUTPUT
47
57
 
58
+ <!-- learning:on -->
59
+ Spawn `Agent(subagent_type="Skim")` with `LEARNING` from the settings line, to get codebase overview relevant to the exploration question:
60
+ <!-- learning:off -->
48
61
  Spawn `Agent(subagent_type="Skim")` to get codebase overview relevant to the exploration question:
62
+ <!-- learning:end -->
49
63
 
50
64
  - File structure and module boundaries in the target area
51
65
  - Entry points and key abstractions
@@ -91,7 +105,11 @@ Present findings to user. Use AskUserQuestion to offer focused follow-up explora
91
105
 
92
106
  ### Phase 6: Suggest Feature Knowledge Creation (Conditional)
93
107
 
108
+ <!-- learning:on -->
94
109
  **Requires:** MERGED_FINDINGS, DECISIONS_CONTEXT
110
+ <!-- learning:off -->
111
+ **Requires:** MERGED_FINDINGS
112
+ <!-- learning:end -->
95
113
  **Produces:** FEATURE_KNOWLEDGE_STATUS (created | skipped)
96
114
 
97
115
  1. Check if matching feature knowledge already exists by reading `{worktree}/.devflow/features/index.md` (or globbing frontmatter if absent). If covered → skip
@@ -125,7 +143,11 @@ Structured exploration findings with concrete code references:
125
143
  ```
126
144
  /explore (orchestrator)
127
145
  │
146
+ <!-- learning:on -->
128
147
  ├─ Phase 1: Load Decisions (Orchestrator-Local)
148
+ <!-- learning:off -->
149
+ ├─ Phase 1: Resolve Settings
150
+ <!-- learning:end -->
129
151
  │
130
152
  ├─ Phase 2: Orient
131
153
  │ └─ Skim agent (codebase overview)
@@ -146,7 +168,11 @@ Structured exploration findings with concrete code references:
146
168
 
147
169
  1. **Structure over browsing** - Every claim must cite file:line references
148
170
  2. **Parallel execution** - All explorers run simultaneously for speed
171
+ <!-- learning:on -->
149
172
  3. **Knowledge-informed** - Prior decisions guide where to look; NO pre-loaded feature knowledge in sub-agents (avoids confirmation bias)
173
+ <!-- learning:off -->
174
+ 3. **Knowledge-informed** - NO pre-loaded feature knowledge in sub-agents (avoids confirmation bias)
175
+ <!-- learning:end -->
150
176
  4. **User-driven depth** - Present findings, then offer drill-down into specific areas
151
177
 
152
178
  ## Error Handling
@@ -10,6 +10,7 @@ output-dir: dist/commands
10
10
  @import { test_plan_line } from "./_partials/_plan_contract.mds"
11
11
  @import { publication_gate } from "./_partials/_publication.mds"
12
12
  @import "./_partials/_compliance.mds" as compliance
13
+ @import "./_partials/_settings.mds" as settings
13
14
  # Implement Command
14
15
 
15
16
  Orchestrate a single task through implementation by spawning specialized agents. The orchestrator only spawns agents and passes context - all work is done by agents.
@@ -50,14 +51,18 @@ When the user explicitly asks to re-validate, re-check, or re-run quality gates
50
51
  1. **Branch safety check**: If on a protected branch (main, master, develop, etc.), run Phase 1 to create/switch to a work branch. If already on a work branch, skip Phase 1.
51
52
  2. **Skip Phase 2** — no Code agent needed, user already made changes.
52
53
  3. **Detect FILES_CHANGED**: `git diff --name-only {base_branch}...HEAD`
53
- 4. **Run Phases 3-8** — full quality gate pipeline on detected changes.
54
+ 4. **Run Phases 3-8** — Simplify, Self-Review, Alignment, the one full Validate, QA Testing and the conditional Re-Validate, on the detected changes.
54
55
  5. **Proceed to Phase 10** (Create PR), **Phase 10b** (Evidence) and **Phase 11** (Report).
55
56
 
56
57
  If the user prompt does NOT match re-validation, proceed with the full pipeline below.
57
58
 
58
59
  ### Phase 1: Setup
59
60
 
60
- **Produces:** TASK_ID, BASE_BRANCH, EXECUTION_PLAN, DECISIONS_CONTEXT, FEATURE_KNOWLEDGE, PR_DESCRIPTION_GUIDANCE, ISSUE_NUMBER, EVIDENCE_POLICY, ISSUE_REQUIRED, APPLY_CONVENTIONS, REQUIRE_NON_AUTHOR_APPROVAL, PR_EXCEPTIONS, TEST_PLAN, EVIDENCE_FILE, PR_TEST_PLAN_BLOCK, REVIEW_PUBLICATION
61
+ <!-- learning:on -->
62
+ **Produces:** TASK_ID, BASE_BRANCH, EXECUTION_PLAN, DECISIONS_CONTEXT, FEATURE_KNOWLEDGE, FEATURE_KNOWLEDGE_RULES, PR_DESCRIPTION_GUIDANCE, ISSUE_NUMBER, EVIDENCE_POLICY, ISSUE_REQUIRED, APPLY_CONVENTIONS, REQUIRE_NON_AUTHOR_APPROVAL, PR_EXCEPTIONS, TEST_PLAN, EVIDENCE_FILE, PR_TEST_PLAN_BLOCK, REVIEW_PUBLICATION
63
+ <!-- learning:off -->
64
+ **Produces:** TASK_ID, BASE_BRANCH, EXECUTION_PLAN, FEATURE_KNOWLEDGE, FEATURE_KNOWLEDGE_RULES, PR_DESCRIPTION_GUIDANCE, ISSUE_NUMBER, EVIDENCE_POLICY, ISSUE_REQUIRED, APPLY_CONVENTIONS, REQUIRE_NON_AUTHOR_APPROVAL, PR_EXCEPTIONS, TEST_PLAN, EVIDENCE_FILE, PR_TEST_PLAN_BLOCK, REVIEW_PUBLICATION
65
+ <!-- learning:end -->
61
66
 
62
67
  Record the current branch name as `BASE_BRANCH` - this will be the PR target.
63
68
 
@@ -167,13 +172,16 @@ node "$HOME/.devflow/scripts/verify-evidence.cjs" render --plan "{worktree}/.dev
167
172
 
168
173
  - `EVIDENCE_FILE` — `{worktree}/.devflow/docs/evidence-{branch_slug}.md`, its `## Evidence Exceptions` section now a byte copy of `PR_EXCEPTIONS` (absent when that is `(none)`).
169
174
 
175
+ {{settings.settings_resolve()}}
176
+
170
177
  {{publication_gate()}}
171
178
  Phase 10b passes the resolved value to `update-pr-evidence`, which decides what each value means for the evidence comment. From the same line: {{compliance.compliance_frameworks()}} Pass it to every Code spawn.
172
179
 
173
180
  {{decisions_load()}}
181
+ <!-- learning:on -->
182
+ Pass `DECISIONS_CONTEXT` to Code agent (Phase 2) and Scrutinize agent (Phase 4).
174
183
 
175
- Pass to Code agent (Phase 2) and Scrutinize agent (Phase 5).
176
-
184
+ <!-- learning:end -->
177
185
  {{knowledge_load()}}
178
186
 
179
187
  ### Phase 2: Implement
@@ -199,7 +207,8 @@ Based on Setup context (plan document, issue body, or conversation context), use
199
207
 
200
208
  ```
201
209
  Agent(subagent_type="Code"):
202
- "TASK_ID: {task-id}
210
+ "OPERATION: implement
211
+ TASK_ID: {task-id}
203
212
  TASK_DESCRIPTION: {description}
204
213
  BASE_BRANCH: {base branch}
205
214
  EXECUTION_PLAN: {full plan from setup context}
@@ -207,7 +216,9 @@ PATTERNS: {patterns from plan document or empty}
207
216
  CREATE_PR: true
208
217
  DOMAIN: {detected domain or 'fullstack'}
209
218
  FEATURE_KNOWLEDGE: {feature_knowledge}
219
+ <!-- learning:on -->
210
220
  DECISIONS_CONTEXT: {decisions_context}
221
+ <!-- learning:end -->
211
222
  COMPLIANCE_FRAMEWORKS: {COMPLIANCE_FRAMEWORKS}
212
223
  PR_DESCRIPTION_GUIDANCE: {pr_description_guidance}
213
224
  ISSUE_NUMBER: {ISSUE_ID captured in Phase 1, or (none)}
@@ -220,12 +231,13 @@ PR_TEST_PLAN_BLOCK: {PR_TEST_PLAN_BLOCK from Phase 1 verbatim, or (none)}"
220
231
 
221
232
  **SEQUENTIAL_CODE_AGENTS** (for HIGH/CRITICAL context risk):
222
233
 
223
- Spawn Code agents one at a time, passing handoff summaries between phases:
234
+ Spawn Code agents one at a time. Each appends its own phase section to the handoff file, and the next reads only the section before it:
224
235
 
225
236
  **Phase 1 Code agent:**
226
237
  ```
227
238
  Agent(subagent_type="Code"):
228
- "TASK_ID: {task-id}
239
+ "OPERATION: implement
240
+ TASK_ID: {task-id}
229
241
  TASK_DESCRIPTION: {phase 1 description}
230
242
  BASE_BRANCH: {base branch}
231
243
  EXECUTION_PLAN: {phase 1 steps}
@@ -233,7 +245,9 @@ PATTERNS: {patterns from plan document or empty}
233
245
  CREATE_PR: false
234
246
  DOMAIN: {phase 1 domain, e.g., 'backend'}
235
247
  FEATURE_KNOWLEDGE: {feature_knowledge}
248
+ <!-- learning:on -->
236
249
  DECISIONS_CONTEXT: {decisions_context}
250
+ <!-- learning:end -->
237
251
  COMPLIANCE_FRAMEWORKS: {COMPLIANCE_FRAMEWORKS}
238
252
  PR_DESCRIPTION_GUIDANCE: {pr_description_guidance}
239
253
  ISSUE_NUMBER: {ISSUE_ID captured in Phase 1, or (none)}
@@ -245,7 +259,8 @@ HANDOFF_FILE: {worktree}/.devflow/docs/handoff-{branch_slug}.md"
245
259
  **Phase 2+ Code agents** (after prior phase completes):
246
260
  ```
247
261
  Agent(subagent_type="Code"):
248
- "TASK_ID: {task-id}
262
+ "OPERATION: implement
263
+ TASK_ID: {task-id}
249
264
  TASK_DESCRIPTION: {phase N description}
250
265
  BASE_BRANCH: {base branch}
251
266
  EXECUTION_PLAN: {phase N steps}
@@ -255,7 +270,9 @@ DOMAIN: {phase N domain, e.g., 'frontend'}
255
270
  PRIOR_PHASE_SUMMARY: {summary from previous Code agent}
256
271
  FILES_FROM_PRIOR_PHASE: {list of files created}
257
272
  FEATURE_KNOWLEDGE: {feature_knowledge}
273
+ <!-- learning:on -->
258
274
  DECISIONS_CONTEXT: {decisions_context}
275
+ <!-- learning:end -->
259
276
  COMPLIANCE_FRAMEWORKS: {COMPLIANCE_FRAMEWORKS}
260
277
  PR_DESCRIPTION_GUIDANCE: {pr_description_guidance}
261
278
  ISSUE_NUMBER: {ISSUE_ID captured in Phase 1, or (none)}
@@ -266,7 +283,7 @@ HANDOFF_REQUIRED: {true if not last phase}
266
283
  HANDOFF_FILE: {worktree}/.devflow/docs/handoff-{branch_slug}.md"
267
284
  ```
268
285
 
269
- **Handoff Protocol**: Each sequential Code agent receives the prior Code agent's implementation summary via PRIOR_PHASE_SUMMARY and FILES_FROM_PRIOR_PHASE. The Code agent's built-in branch orientation step handles git log scanning, file reading, and pattern discovery automatically. After each Code agent with HANDOFF_REQUIRED=true completes, write its phase summary to `{worktree}/.devflow/docs/handoff-{branch_slug}.md` using the Write tool (survives context compaction), keeping any `## Evidence Exceptions` section byte-identical. Delete `{worktree}/.devflow/docs/handoff-{branch_slug}.md` once the PR exists — after the final Code agent, which creates it, completes (cleanup).
286
+ **Handoff Protocol**: Each sequential Code agent receives the prior Code agent's implementation summary via PRIOR_PHASE_SUMMARY and FILES_FROM_PRIOR_PHASE. The Code agent's built-in branch orientation step handles git log scanning, file reading, and pattern discovery automatically. Each Code agent with HANDOFF_REQUIRED=true appends its own `## Phase {N} Implementation Summary` section, at most 8,192 bytes, to `{worktree}/.devflow/docs/handoff-{branch_slug}.md` (survives context compaction), never rewriting an earlier section and keeping any `## Evidence Exceptions` section byte-identical; the next Code agent reads only the section of the phase immediately before its own through HANDOFF_FILE. The orchestrator writes no phase section. Delete `{worktree}/.devflow/docs/handoff-{branch_slug}.md` once the PR exists — after the final Code agent, which creates it, completes (cleanup).
270
287
 
271
288
  ---
272
289
 
@@ -276,7 +293,8 @@ Spawn multiple Code agents **in a single message**, each with independent subtas
276
293
 
277
294
  ```
278
295
  Agent(subagent_type="Code"): # Code agent 1
279
- "TASK_ID: {task-id}-part1
296
+ "OPERATION: implement
297
+ TASK_ID: {task-id}-part1
280
298
  TASK_DESCRIPTION: {independent subtask 1}
281
299
  BASE_BRANCH: {base branch}
282
300
  EXECUTION_PLAN: {subtask 1 steps}
@@ -284,14 +302,17 @@ PATTERNS: {patterns}
284
302
  CREATE_PR: false
285
303
  DOMAIN: {subtask 1 domain}
286
304
  FEATURE_KNOWLEDGE: {feature_knowledge}
305
+ <!-- learning:on -->
287
306
  DECISIONS_CONTEXT: {decisions_context}
307
+ <!-- learning:end -->
288
308
  COMPLIANCE_FRAMEWORKS: {COMPLIANCE_FRAMEWORKS}
289
309
  PR_DESCRIPTION_GUIDANCE: {pr_description_guidance}
290
310
  ISSUE_NUMBER: {ISSUE_ID captured in Phase 1, or (none)}
291
311
  ISSUE_PR_LINK: {ISSUE_PR_LINK captured in Phase 1, or (none)}"
292
312
 
293
313
  Agent(subagent_type="Code"): # Code agent 2 (same message)
294
- "TASK_ID: {task-id}-part2
314
+ "OPERATION: implement
315
+ TASK_ID: {task-id}-part2
295
316
  TASK_DESCRIPTION: {independent subtask 2}
296
317
  BASE_BRANCH: {base branch}
297
318
  EXECUTION_PLAN: {subtask 2 steps}
@@ -299,7 +320,9 @@ PATTERNS: {patterns}
299
320
  CREATE_PR: false
300
321
  DOMAIN: {subtask 2 domain}
301
322
  FEATURE_KNOWLEDGE: {feature_knowledge}
323
+ <!-- learning:on -->
302
324
  DECISIONS_CONTEXT: {decisions_context}
325
+ <!-- learning:end -->
303
326
  COMPLIANCE_FRAMEWORKS: {COMPLIANCE_FRAMEWORKS}
304
327
  PR_DESCRIPTION_GUIDANCE: {pr_description_guidance}
305
328
  ISSUE_NUMBER: {ISSUE_ID captured in Phase 1, or (none)}
@@ -312,110 +335,48 @@ ISSUE_PR_LINK: {ISSUE_PR_LINK captured in Phase 1, or (none)}"
312
335
  - Different files/modules with no imports between them
313
336
  - Each subtask is self-contained
314
337
 
315
- ### Phase 3: Validate
316
-
317
- **Produces:** VALIDATION_RESULT
318
- **Requires:** FILES_CHANGED
319
-
320
- After Code agent completes, spawn Validate agent to verify correctness:
321
-
322
- ```
323
- Agent(subagent_type="Validate"):
324
- "FILES_CHANGED: {list of files from Code agent output}
325
- VALIDATION_SCOPE: full
326
- Run build, typecheck, lint, test. Report pass/fail with failure details."
327
- ```
328
-
329
- **If FAIL:**
330
- 1. Extract failure details from Validate agent output
331
- 2. Increment `validation_retry_count`
332
- 3. If `validation_retry_count <= 2`:
333
- - Spawn Code agent with fix context:
334
- ```
335
- Agent(subagent_type="Code"):
336
- "TASK_ID: {task-id}
337
- TASK_DESCRIPTION: Fix validation failures
338
- OPERATION: validation-fix
339
- VALIDATION_FAILURES: {parsed failures from Validate agent}
340
- SCOPE: Fix only the listed failures, no other changes
341
- CREATE_PR: false
342
- ISSUE_NUMBER: {ISSUE_ID captured in Phase 1, or (none)}
343
- ISSUE_PR_LINK: {ISSUE_PR_LINK captured in Phase 1, or (none)}
344
- COMPLIANCE_FRAMEWORKS: {COMPLIANCE_FRAMEWORKS}"
345
- ```
346
- - Loop back to Phase 3 (re-validate)
347
- 4. If `validation_retry_count > 2`: Report failures to user and halt
348
-
349
- **If PASS:** append a `gate:validate` claim, then continue to Phase 4.
350
-
351
- **Evidence claims** are lines appended to the `## Claims` section of `EVIDENCE_FILE` — the file's last section, created when absent. Append only: never edit or remove a claim; the last valid one per target wins. Each line takes exactly one of these shapes, where `<head>` is the 40-hex `HEAD:` the agent's report shows:
352
-
353
- ```
354
- - gate:validate PASS sha:<head> by:validate
355
- - TP-<n> <PASS|FAIL|SKIP> sha:<head> by:test exit:<0-255>
356
- ```
357
-
358
- - `gate:validate` — after a Phase 3 or Phase 6 PASS.
359
- - `TP-<n>` — after every Phase 8 run, one line per `### Test Plan Evidence` row whose TP is in `TEST_PLAN`, with the row's outcome; the line ends at `by:test` when the row's Exit is not a number from 0 to 255.
360
- - Append nothing from a report whose `HEAD:` is not a single 40-hex SHA — a reported before/after change included — and say so in the Phase 11 report.
361
-
362
- ### Phase 4: Simplify
338
+ ### Phase 3: Simplify
363
339
 
364
340
  **Produces:** SIMPLIFY_OUTPUT
365
341
  **Requires:** FILES_CHANGED
366
342
 
367
- After validation passes, spawn Simplify agent to polish the code:
343
+ After the Code agent completes, spawn Simplify agent to polish the code. The Phase 6 Validate covers its commits.
368
344
 
369
345
  ```
370
346
  Agent(subagent_type="Simplify"):
371
347
  "Simplify recently implemented code
372
348
  Task: {task description}
373
349
  FILES_CHANGED: {list of files from Code agent output}
374
- Focus on code modified by Code agent, apply project standards, enhance clarity"
350
+ Focus on code modified by Code agent, apply project standards, enhance clarity
351
+ Commit any improvements with a conventional-commit message."
375
352
  ```
376
353
 
377
- ### Phase 5: Self-Review
354
+ ### Phase 4: Self-Review
378
355
 
379
356
  **Produces:** SCRUTINIZE_OUTPUT
380
357
  **Requires:** FILES_CHANGED
381
358
 
382
- After Simplify agent completes, spawn Scrutinize agent as final quality gate:
359
+ After Simplify agent completes, spawn Scrutinize agent as the quality gate:
383
360
 
384
361
  ```
385
362
  Agent(subagent_type="Scrutinize"):
386
363
  "TASK_DESCRIPTION: {task description}
387
364
  FILES_CHANGED: {list of files from Code agent output}
365
+ <!-- learning:on -->
388
366
  DECISIONS_CONTEXT: {decisions_context}
389
- FEATURE_KNOWLEDGE: {feature_knowledge}
367
+ <!-- learning:end -->
368
+ FEATURE_KNOWLEDGE: {feature_knowledge_rules}
390
369
  Evaluate 9 pillars, fix P0/P1 issues, report status"
391
370
  ```
392
371
 
393
- If Scrutinize agent returns BLOCKED, report to user and halt.
394
-
395
- ### Phase 6: Re-Validate (if Scrutinize agent made changes)
396
-
397
- **Produces:** REVALIDATION_RESULT
398
- **Requires:** SCRUTINIZE_OUTPUT
399
-
400
- If Scrutinize agent made code changes (status: FIXED), spawn Validate agent to verify:
401
-
402
- ```
403
- Agent(subagent_type="Validate"):
404
- "FILES_CHANGED: {files modified by Scrutinize agent}
405
- VALIDATION_SCOPE: changed-only
406
- Verify Scrutinize agent's fixes didn't break anything."
407
- ```
408
-
409
- **If FAIL:** Report to user - Scrutinize agent broke tests, needs manual intervention.
410
-
411
- **If PASS:** append a `gate:validate` claim (Phase 3's **Evidence claims**), then continue to Phase 7.
372
+ Scrutinize agent reports `### Status: PASS | FIXED | BLOCKED`. **If BLOCKED:** report to user and halt. **If PASS or FIXED:** continue to Phase 5. A FIXED status commits fixes and starts no Validate of its own: the Phase 6 run covers them.
412
373
 
413
- ### Phase 7: Alignment Check
374
+ ### Phase 5: Alignment Check
414
375
 
415
376
  **Produces:** ALIGNMENT_RESULT
416
377
  **Requires:** FILES_CHANGED, EXECUTION_PLAN
417
378
 
418
- After Scrutinize agent passes (and re-validation if needed), spawn Evaluate agent to validate alignment:
379
+ After Scrutinize agent passes, spawn Evaluate agent to validate alignment. Evaluate agent receives `FEATURE_KNOWLEDGE_RULES` as acceptance context only; pattern and anti-pattern judgments belong to Scrutinize agent:
419
380
 
420
381
  ```
421
382
  Agent(subagent_type="Evaluate"):
@@ -423,11 +384,11 @@ Agent(subagent_type="Evaluate"):
423
384
  EXECUTION_PLAN: {execution plan from Phase 1}
424
385
  FILES_CHANGED: {list of files from Code agent output}
425
386
  ACCEPTANCE_CRITERIA: {extracted criteria if available}
426
- FEATURE_KNOWLEDGE: {feature_knowledge}
387
+ FEATURE_KNOWLEDGE: {feature_knowledge_rules}
427
388
  Validate alignment with request and plan. Report ALIGNED or MISALIGNED with details."
428
389
  ```
429
390
 
430
- **If ALIGNED:** Continue to Phase 8
391
+ **If ALIGNED:** Continue to Phase 6
431
392
 
432
393
  **If MISALIGNED:**
433
394
  1. Extract misalignment details from Evaluate agent output
@@ -436,32 +397,78 @@ Validate alignment with request and plan. Report ALIGNED or MISALIGNED with deta
436
397
  - Spawn Code agent to fix misalignments:
437
398
  ```
438
399
  Agent(subagent_type="Code"):
439
- "TASK_ID: {task-id}
400
+ "OPERATION: alignment-fix
401
+ TASK_ID: {task-id}
440
402
  TASK_DESCRIPTION: Fix alignment issues
441
- OPERATION: alignment-fix
442
403
  MISALIGNMENTS: {structured misalignments from Evaluate agent}
443
404
  SCOPE: Fix only the listed misalignments, no other changes
444
405
  CREATE_PR: false
406
+ <!-- learning:on -->
407
+ DECISIONS_CONTEXT: {decisions_context}
408
+ <!-- learning:end -->
445
409
  ISSUE_NUMBER: {ISSUE_ID captured in Phase 1, or (none)}
446
410
  ISSUE_PR_LINK: {ISSUE_PR_LINK captured in Phase 1, or (none)}
447
411
  COMPLIANCE_FRAMEWORKS: {COMPLIANCE_FRAMEWORKS}"
448
412
  ```
449
- - Spawn Validate agent to verify fix didn't break tests:
413
+ - Loop back to Phase 5 (re-check alignment). The fix is not validated here: the Phase 6 run covers it.
414
+ 4. If `alignment_fix_count > 2`: Report misalignments to user for decision
415
+
416
+ ### Phase 6: Validate
417
+
418
+ **Produces:** VALIDATION_RESULT, VALIDATED_HEAD
419
+ **Requires:** BASE_BRANCH
420
+
421
+ Validate takes the one full-suite slot, after every commit it must cover: Code, Simplify, Scrutinize and the alignment fixes. After Evaluate agent passes, spawn Validate agent. `FILES_CHANGED` is the branch diff, because the Code agent's own list misses the Simplify, Scrutinize and fix commits (`{base}` is `BASE_BRANCH`):
422
+
423
+ ```
424
+ Agent(subagent_type="Validate"):
425
+ "FILES_CHANGED: {output of `git diff --name-only {base}...HEAD`}
426
+ VALIDATION_SCOPE: full
427
+ Run build, typecheck, lint, test. Report pass/fail with failure details."
428
+ ```
429
+
430
+ **If FAIL:**
431
+ 1. Extract failure details from Validate agent output
432
+ 2. Increment `validation_retry_count`
433
+ 3. If `validation_retry_count <= 2`:
434
+ - Spawn Code agent with fix context:
450
435
  ```
451
- Agent(subagent_type="Validate"):
452
- "FILES_CHANGED: {files modified by fix Code agent}
453
- VALIDATION_SCOPE: changed-only"
436
+ Agent(subagent_type="Code"):
437
+ "OPERATION: validation-fix
438
+ TASK_ID: {task-id}
439
+ TASK_DESCRIPTION: Fix validation failures
440
+ VALIDATION_FAILURES: {parsed failures from Validate agent}
441
+ SCOPE: Fix only the listed failures, no other changes
442
+ CREATE_PR: false
443
+ <!-- learning:on -->
444
+ DECISIONS_CONTEXT: {decisions_context}
445
+ <!-- learning:end -->
446
+ ISSUE_NUMBER: {ISSUE_ID captured in Phase 1, or (none)}
447
+ ISSUE_PR_LINK: {ISSUE_PR_LINK captured in Phase 1, or (none)}
448
+ COMPLIANCE_FRAMEWORKS: {COMPLIANCE_FRAMEWORKS}"
454
449
  ```
455
- - If Validate agent FAIL: Report to user
456
- - If Validate agent PASS: Loop back to Phase 7 (re-check alignment)
457
- 4. If `alignment_fix_count > 2`: Report misalignments to user for decision
450
+ - Loop back to Phase 6 (re-validate at the new HEAD, full scope)
451
+ 4. If `validation_retry_count > 2`: Report failures to user and halt
452
+
453
+ **If PASS:** append a `gate:validate` claim, run `git rev-parse HEAD` and record the result as `VALIDATED_HEAD`, then continue to Phase 7.
458
454
 
459
- ### Phase 8: QA Testing
455
+ **Evidence claims** are lines appended to the `## Claims` section of `EVIDENCE_FILE` — the file's last section, created when absent. Append only: never edit or remove a claim; the last valid one per target wins. Each line takes exactly one of these shapes, where `<head>` is the 40-hex `HEAD:` the agent's report shows:
456
+
457
+ ```
458
+ - gate:validate PASS sha:<head> by:validate
459
+ - TP-<n> <PASS|FAIL|SKIP> sha:<head> by:test exit:<0-255>
460
+ ```
461
+
462
+ - `gate:validate` — after a Phase 6 or Phase 8 PASS.
463
+ - `TP-<n>` — after every Phase 7 run, one line per `### Test Plan Evidence` row whose TP is in `TEST_PLAN`, with the row's outcome; the line ends at `by:test` when the row's Exit is not a number from 0 to 255.
464
+ - Append nothing from a report whose `HEAD:` is not a single 40-hex SHA — a reported before/after change included — and say so in the Phase 11 report.
465
+
466
+ ### Phase 7: QA Testing
460
467
 
461
468
  **Produces:** QA_RESULT
462
- **Requires:** FILES_CHANGED, EXECUTION_PLAN, TEST_PLAN
469
+ **Requires:** FILES_CHANGED, EXECUTION_PLAN, TEST_PLAN, VALIDATED_HEAD
463
470
 
464
- After Evaluate agent passes, spawn Test agent for scenario-based acceptance testing:
471
+ After Phase 6 passes, spawn Test agent for scenario-based acceptance testing:
465
472
 
466
473
  ```
467
474
  Agent(subagent_type="Test"):
@@ -473,9 +480,9 @@ TEST_PLAN: {the TP lines of the evidence file's ## Test Plan section, or (none)}
473
480
  Design and execute scenario-based acceptance tests. Report PASS or FAIL with evidence."
474
481
  ```
475
482
 
476
- After every Test agent run — PASS or FAIL, first run or retry — append its TP claims (Phase 3's **Evidence claims**).
483
+ After every Test agent run — PASS or FAIL, first run or retry — append its TP claims (Phase 6's **Evidence claims**).
477
484
 
478
- **If PASS:** Continue to Phase 9
485
+ **If PASS:** Continue to Phase 8
479
486
 
480
487
  **If FAIL:**
481
488
  1. Extract failure details from Test agent output
@@ -484,25 +491,39 @@ After every Test agent run — PASS or FAIL, first run or retry — append its T
484
491
  - Spawn Code agent to fix QA failures:
485
492
  ```
486
493
  Agent(subagent_type="Code"):
487
- "TASK_ID: {task-id}
494
+ "OPERATION: qa-fix
495
+ TASK_ID: {task-id}
488
496
  TASK_DESCRIPTION: Fix QA test failures
489
- OPERATION: qa-fix
490
497
  QA_FAILURES: {structured failures from Test agent}
491
498
  SCOPE: Fix only the listed failures, no other changes
492
499
  CREATE_PR: false
500
+ <!-- learning:on -->
501
+ DECISIONS_CONTEXT: {decisions_context}
502
+ <!-- learning:end -->
493
503
  ISSUE_NUMBER: {ISSUE_ID captured in Phase 1, or (none)}
494
504
  ISSUE_PR_LINK: {ISSUE_PR_LINK captured in Phase 1, or (none)}
495
505
  COMPLIANCE_FRAMEWORKS: {COMPLIANCE_FRAMEWORKS}"
496
506
  ```
497
- - Spawn Validate agent to verify fix didn't break tests:
498
- ```
499
- Agent(subagent_type="Validate"):
500
- "FILES_CHANGED: {files modified by fix Code agent}
501
- VALIDATION_SCOPE: changed-only"
502
- ```
503
- - If Validate agent FAIL: Report to user
504
- - If Validate agent PASS: Loop back to Phase 8 (re-run Test agent)
505
- 4. If `qa_retry_count > 2`: Report QA failures to user for decision
507
+ - Loop back to Phase 7 (re-run Test agent). The fix is not validated here: Phase 8 covers it.
508
+ 4. If `qa_retry_count > 2`: Report QA failures to user for decision. The run stops at the report (Phase 11), so Phases 8 and 9 do not run.
509
+
510
+ ### Phase 8: Re-Validate (only if a qa-fix committed)
511
+
512
+ **Produces:** REVALIDATION_RESULT
513
+ **Requires:** QA_RESULT, VALIDATED_HEAD
514
+
515
+ Run this phase only if a qa-fix committed (`git rev-parse HEAD` differs from `VALIDATED_HEAD`); otherwise skip it and continue to Phase 9. Spawn Validate agent over what changed since the Phase 6 run:
516
+
517
+ ```
518
+ Agent(subagent_type="Validate"):
519
+ "FILES_CHANGED: {output of `git diff --name-only VALIDATED_HEAD..HEAD`}
520
+ VALIDATION_SCOPE: changed-only
521
+ Verify the qa-fix commits did not break anything."
522
+ ```
523
+
524
+ **If FAIL:** Report the failures to user and halt.
525
+
526
+ **If PASS:** append a `gate:validate` claim (Phase 6's **Evidence claims**), then continue to Phase 9.
506
527
 
507
528
  ### Phase 9: CI Status Gate
508
529
 
@@ -511,14 +532,26 @@ After every Test agent run — PASS or FAIL, first run or retry — append its T
511
532
 
512
533
  Strategy-conditional: run when the PR already exists — **SINGLE_CODE_AGENT** and **SEQUENTIAL_CODE_AGENTS** (the Phase 2 Code agent with `CREATE_PR: true` creates it); skip for **PARALLEL_CODE_AGENTS** (its unified PR is created in Phase 10).
513
534
 
535
+ **Push first, outside the gate block.** The gate reads CI for the pushed head, and the Simplify, Scrutinize and fix commits reach the PR only by a push. Push once — never force, and no retry:
536
+
537
+ ```bash
538
+ git push origin HEAD; echo "exit=$?"
539
+ ```
540
+
541
+ `exit=0` continues to the gate. Any other result, a rejected non-fast-forward push included, records `TRACEABILITY: DEGRADED (ci push failed)` for the Phase 11 report, reports "CI status unknown — verify manually before merging" and proceeds to Phase 10 without waiting. `PR_NUMBER` is the number in `PR_URL`.
542
+
514
543
  <!-- PATTERN: ci-status-gate -->
515
- 1. Spawn `Agent(subagent_type="Git")` with `OPERATION: check-ci-status` and `PR_NUMBER` from PR_URL.
544
+ 1. Wait: run `cd {worktree} && HEAD_SHA=$(git rev-parse HEAD) && node "$HOME/.devflow/scripts/ci-wait.cjs" --pr {PR_NUMBER} --head "$HEAD_SHA"` through the Bash tool with `timeout: 600000`. Each run is one wait of at most 570 seconds and prints one line, `CI <STATUS> pr=… head=… failing=… pending=… waited=…` (INDETERMINATE adds `reason=…`). A missing or unparseable line, a status outside the six below, or a non-zero exit is INDETERMINATE.
516
545
  2. **If PASSING** → proceed to Phase 10.
517
546
  3. **If NO_PR or NO_CI** → skip: "No PR/CI configured, skipping CI validation." Proceed to Phase 10.
518
- 4. **If PENDING** → poll every 60 seconds (global budget, see step 7). Re-spawn Git agent each poll. If PASSING → proceed. If still PENDING after budget exhausted → report "CI still running — verify manually before merging" and proceed.
519
- 5. **If INDETERMINATE** → poll as PENDING within the same budget. If still INDETERMINATE after budget exhausted → report "CI status unknown — verify manually before merging" and proceed.
520
- 6. **If FAILING** → report failing checks. Spawn `Agent(subagent_type="Code")` with `COMPLIANCE_FRAMEWORKS` to fix CI failures based on check names and failure context. After fix, push and re-check. Max 2 fix attempts. If still failing → report failures and proceed.
521
- 7. **Total budget**: max 10 polls and max 2 fix attempts across all check/fix cycles combined. If budget exhausted, report current status and proceed.
547
+ 4. **If PENDING** and fewer than 3 waits have run → wait again (step 1). After the third wait → report "CI still running — verify manually before merging" and proceed.
548
+ 5. **If INDETERMINATE** and fewer than 3 waits have run → wait again (step 1). After the third wait → report "CI status unknown — verify manually before merging" and proceed.
549
+ <!-- learning:on -->
550
+ 6. **If FAILING** and fewer than 2 fixes have run → report the failing checks from the line. Spawn `Agent(subagent_type="Code")` whose prompt opens with `OPERATION: ci-fix`, with `COMPLIANCE_FRAMEWORKS`, `CI_FAILURES`, `DECISIONS_CONTEXT` and `PUSH: false`; `CI_FAILURES` holds the failing-check names from the line and nothing else, because the Code agent fetches the full names and reads the logs itself and this command reads none. After a fix, push with the command above and, if a wait remains, wait again (step 1); a failed push records `TRACEABILITY: DEGRADED (ci push failed)`, reports "CI status unknown — verify manually before merging" and stops waiting. After the second fix still FAILING → report the failing checks and proceed.
551
+ <!-- learning:off -->
552
+ 6. **If FAILING** and fewer than 2 fixes have run → report the failing checks from the line. Spawn `Agent(subagent_type="Code")` whose prompt opens with `OPERATION: ci-fix`, with `COMPLIANCE_FRAMEWORKS`, `CI_FAILURES` and `PUSH: false`; `CI_FAILURES` holds the failing-check names from the line and nothing else, because the Code agent fetches the full names and reads the logs itself and this command reads none. After a fix, push with the command above and, if a wait remains, wait again (step 1); a failed push records `TRACEABILITY: DEGRADED (ci push failed)`, reports "CI status unknown — verify manually before merging" and stops waiting. After the second fix still FAILING → report the failing checks and proceed.
553
+ <!-- learning:end -->
554
+ 7. **Budget**: at most 3 waits and 2 fixes in all. When one is spent, report the current status and proceed.
522
555
  <!-- /PATTERN: ci-status-gate -->
523
556
 
524
557
  ### Phase 10: Create PR
@@ -532,9 +565,9 @@ Strategy-conditional: run when the PR already exists — **SINGLE_CODE_AGENT** a
532
565
 
533
566
  ```
534
567
  Agent(subagent_type="Code"):
535
- "TASK_ID: {task-id}
568
+ "OPERATION: pr-create
569
+ TASK_ID: {task-id}
536
570
  TASK_DESCRIPTION: Create the unified PR for the parallel implementation
537
- OPERATION: pr-create
538
571
  BASE_BRANCH: {base branch}
539
572
  CREATE_PR: true
540
573
  PR_DESCRIPTION_GUIDANCE: {pr_description_guidance}
@@ -584,7 +617,7 @@ Display completion summary with phase status, PR info, and next steps.
584
617
 
585
618
  Show the test plan's evidence from Phase 10b: `Test plan: {VERIFIED-CI + ATTESTED-LOCAL}/{total} verified (VERIFIED-CI {n}, ATTESTED-LOCAL {n})`, read from the `EVIDENCE` line and never inferred, then its `**Body**:` / `**Comment**:` line verbatim. Without an `EVIDENCE` line, show `Test plan: evidence unavailable`; with no test plan, `Test plan: missing`.
586
619
 
587
- If any Git agent output emitted `TRACEABILITY: DEGRADED ({reason})` lines during the run, or Phase 10b's push recorded one, surface them verbatim in the report under a `### Traceability` subsection so the user can act on them.
620
+ If any Git agent output emitted `TRACEABILITY: DEGRADED ({reason})` lines during the run, or Phase 9's push or Phase 10b's push recorded one, surface them verbatim in the report under a `### Traceability` subsection so the user can act on them.
588
621
 
589
622
  If Phase 1 recorded an evidence exception, show its `## Evidence Exceptions` lines in the report.
590
623
 
@@ -609,30 +642,30 @@ If Phase 1 recorded an evidence exception, show its `## Evidence Exceptions` lin
609
642
  │ ├─ SEQUENTIAL_CODE_AGENTS (15%): N Code agents with handoff summaries
610
643
  │ └─ PARALLEL_CODE_AGENTS (5%): N Code agents in single message (rare)
611
644
  │
612
- ├─ Phase 3: Validate
613
- │ └─ Validate agent (build, typecheck, lint, test)
614
- │ └─ If FAIL: Code agent fix loop (max 2 retries) → re-validate
615
- │ └─ If PASS: gate:validate claim → evidence file
616
- │
617
- ├─ Phase 4: Simplify
645
+ ├─ Phase 3: Simplify
618
646
  │ └─ Simplify agent (refines code clarity and consistency)
619
647
  │
620
- ├─ Phase 5: Self-Review
621
- │ └─ Scrutinize agent (final quality gate, fixes P0/P1)
648
+ ├─ Phase 4: Self-Review
649
+ │ └─ Scrutinize agent (quality gate, fixes P0/P1; status PASS | FIXED | BLOCKED)
622
650
  │
623
- ├─ Phase 6: Re-Validate (if Scrutinize agent made changes)
624
- │ └─ Validate agent (verify Scrutinize agent fixes)
625
- │
626
- ├─ Phase 7: Alignment Check
651
+ ├─ Phase 5: Alignment Check
627
652
  │ └─ Evaluate agent (validates alignment - reports only, no fixes)
628
- │ └─ If MISALIGNED: Code agent fix loop (max 2 iterations) → Validate agent → re-check
653
+ │ └─ If MISALIGNED: Code agent fix loop (max 2 iterations) → re-check alignment
654
+ │
655
+ ├─ Phase 6: Validate (the one full-suite slot)
656
+ │ └─ Validate agent (build, typecheck, lint, test over the branch diff)
657
+ │ └─ If FAIL: Code agent fix loop (max 2 retries) → re-validate at the new HEAD
658
+ │ └─ If PASS: record VALIDATED_HEAD, gate:validate claim → evidence file
629
659
  │
630
- ├─ Phase 8: QA Testing
660
+ ├─ Phase 7: QA Testing
631
661
  │ └─ Test agent (scenario-based acceptance tests, TEST_PLAN) → one claim per TP row → evidence file
632
- │ └─ If FAIL: Code agent fix loop (max 2 retries) → Validate agent → re-test
662
+ │ └─ If FAIL: Code agent fix loop (max 2 retries) → re-test
663
+ │
664
+ ├─ Phase 8: Re-Validate (only if a qa-fix committed)
665
+ │ └─ Validate agent (changed-only over VALIDATED_HEAD..HEAD) → gate:validate claim
633
666
  │
634
667
  ├─ Phase 9: CI Status Gate (SINGLE_CODE_AGENT + SEQUENTIAL_CODE_AGENTS; skipped for PARALLEL_CODE_AGENTS)
635
- │ └─ Git agent (check-ci-status) → poll/fix cycle (10 polls + 2 fix budget)
668
+ │ └─ Push the branch, then ci-wait.cjs (inline, one wait ≤ 570 s) → Code agent on FAILING (3 waits + 2 fixes)
636
669
  │
637
670
  ├─ Phase 10: Create PR (if needed)
638
671
  │ └─ SINGLE_CODE_AGENT: already created by the Phase 2 Code agent
@@ -651,7 +684,7 @@ If Phase 1 recorded an evidence exception, show its `## Evidence Exceptions` lin
651
684
 
652
685
  ## Principles
653
686
 
654
- 1. **Orchestration only** - Command spawns agents, never does work itself
687
+ 1. **Orchestration only** - Command spawns agents, never does work itself; the inline calls are the bounded plumbing the charter allows: the Phase 9 and Phase 10b pushes, the Phase 9 ci-wait call and the evidence script checks
655
688
  2. **Plan-first** - Plan documents from `/plan` skip exploration/planning overhead entirely
656
689
  3. **Coherence-first** - Single Code agent produces more consistent code (default ~80% of tasks)
657
690
  4. **Agent ownership** - Each agent owns its output completely
@@ -661,7 +694,7 @@ If Phase 1 recorded an evidence exception, show its `## Evidence Exceptions` lin
661
694
  8. **Strict delegation** - Never perform agent work in main session. "Spawn X" means call Agent tool with X, not do X's work yourself
662
695
  9. **Validate agent owns validation** - Never run `npm test`, `npm run build`, or similar in main session; always delegate to Validate agent
663
696
  10. **Code agent owns fixes** - Never implement fixes in main session; spawn Code agent for validation failures and alignment fixes
664
- 11. **Loop limits** - Max 2 validation retries, max 2 alignment fix iterations before escalating to user
697
+ 11. **Loop limits** - Max 2 validation retries, max 2 alignment fix iterations, max 2 QA retries before escalating to user; the CI gate allows at most 3 waits and 2 fixes
665
698
  12. **CI awareness** - CI status is checked before merge for SINGLE_CODE_AGENT and SEQUENTIAL_CODE_AGENTS, whose PR exists from Phase 2; skipped for PARALLEL_CODE_AGENTS, whose PR is created in Phase 10; test-plan evidence (Phase 10b) is recorded under every strategy once the PR exists
666
699
 
667
700
  ## Error Handling