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
@@ -45,14 +45,14 @@ When the user explicitly asks to re-validate, re-check, or re-run quality gates
45
45
  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.
46
46
  2. **Skip Phase 2** — no Code agent needed, user already made changes.
47
47
  3. **Detect FILES_CHANGED**: `git diff --name-only {base_branch}...HEAD`
48
- 4. **Run Phases 3-8** — full quality gate pipeline on detected changes.
48
+ 4. **Run Phases 3-8** — Simplify, Self-Review, Alignment, the one full Validate, QA Testing and the conditional Re-Validate, on the detected changes.
49
49
  5. **Proceed to Phase 10** (Create PR), **Phase 10b** (Evidence) and **Phase 11** (Report).
50
50
 
51
51
  If the user prompt does NOT match re-validation, proceed with the full pipeline below.
52
52
 
53
53
  ### Phase 1: Setup
54
54
 
55
- **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
55
+ **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
56
56
 
57
57
  Record the current branch name as `BASE_BRANCH` - this will be the PR target.
58
58
 
@@ -207,7 +207,7 @@ Accept the output only when it is exactly two lines: `exit=0` last and, before i
207
207
 
208
208
  The accepted line is the only source of these values: the script alone folds the committed `.devflow/project.json`, the personal `.devflow/config.json` and the machine manifest.
209
209
 
210
- **Resolve `REVIEW_PUBLICATION` per worktree:** take `REVIEW_PUBLICATION` from that worktree's settings line, with `{root}` the worktree's root — multi-worktree repos may resolve different values per worktree. The line already caps the personal choice at the team's (D-PUBLICATION-CEILING), so it is `off`, `auto` or `full`, and `off` when the line was unresolvable.
210
+ **Resolve `REVIEW_PUBLICATION` per worktree:** take `REVIEW_PUBLICATION` from that worktree's settings line — the line resolved above for `{root}`, the worktree's root, by the settings block when this run has not yet resolved that root; multi-worktree repos may resolve different values per worktree. The line already caps the personal choice at the team's (D-PUBLICATION-CEILING), so it is `off`, `auto` or `full`, and `off` when the line was unresolvable.
211
211
 
212
212
  **Evidence stub:** only when `EVIDENCE_POLICY` is `required`, a resolved `off` becomes `stub`, so a counts-only record still reaches the PR. `stub` is never a config value: the settings line never carries it.
213
213
 
@@ -216,6 +216,8 @@ Phase 10b passes the resolved value to `update-pr-evidence`, which decides what
216
216
 
217
217
  ### Load DECISIONS_CONTEXT
218
218
 
219
+ When the settings line says `LEARNING=off`, set `DECISIONS_CONTEXT` to `(none)` and skip this step, locating no ledger and reading no index.
220
+
219
221
  The decisions ledger belongs to the repository, not to one checkout: in a linked worktree it lives in the main worktree, and a session started in a subdirectory reads the copy at the repository root. Locate it with ONE git call, run from the start directory — `WORKTREE_PATH` if provided, otherwise cwd (`devflow:worktree-support`):
220
222
 
221
223
  ```bash
@@ -243,7 +245,7 @@ The index is one direct file read, written at render time by `render-decisions.c
243
245
 
244
246
  When `DECISIONS_CONTEXT` is not `(none)`, follow `devflow:apply-decisions` to scan the index, identify plausibly-relevant entries, Read full entry bodies on demand, and cite verbatim IDs in downstream agent prompts and reasoning.
245
247
 
246
- Pass to Code agent (Phase 2) and Scrutinize agent (Phase 5).
248
+ Pass `DECISIONS_CONTEXT` to Code agent (Phase 2) and Scrutinize agent (Phase 4).
247
249
 
248
250
  ### Load Feature Knowledge
249
251
 
@@ -273,22 +275,32 @@ Glob `{worktree}/.devflow/features/*/KNOWLEDGE.md`. For each file found, read on
273
275
 
274
276
  Match the current task area and description against each index line (or frontmatter `description` + `directories` on fallback). Select entries whose documented area overlaps the current task. This is a relevance judgment — prefer specificity over breadth.
275
277
 
276
- **Step 4 — Read selected KBs:**
278
+ **Step 4 — Read each selected KB's Rules:**
279
+
280
+ For each selected entry, `{kb}` is `{worktree}/.devflow/features/{slug}/KNOWLEDGE.md`:
277
281
 
278
- For each selected entry, read `{worktree}/.devflow/features/{slug}/KNOWLEDGE.md` in full. When the KB content contradicts the current code you observe, **trust the code** — the code is the freshness mechanism; the KB may lag behind.
282
+ 1. List its `##` headings with line numbers through Bash: `command grep -n '^## ' "{kb}"`. This only locates sections; the text of a KB comes from the Read view alone.
283
+ 2. Read the `## Rules` range (its line to the next heading) with the Read tool, using `offset` and `limit`, and choose the one to three bullets most relevant to the current task. The choice is yours, made per KB.
284
+ 3. If the KB has no `## Rules` section, choose one to three entries from its `## Anti-Patterns` or `## Gotchas` range the same way, and label them by that section's name instead of an ID.
279
285
 
280
- **Step 5 — Set FEATURE_KNOWLEDGE:**
286
+ When a KB contradicts the code you observe, **trust the code** — the code is the freshness mechanism; the KB may lag behind. A missing Rules section, a missing heading list and `(none)` are legitimate states, not errors.
281
287
 
282
- Concatenate the selected KNOWLEDGE.md files under slug headers:
288
+ **Step 5 — Set FEATURE_KNOWLEDGE and FEATURE_KNOWLEDGE_RULES:**
289
+
290
+ Write one block per selected KB. Paste each bullet verbatim from the Read view, never from a shell view. The path is relative to the checkout root; an agent resolves it under `WORKTREE_PATH` when one is provided.
283
291
 
284
292
  ```
285
293
  --- Feature knowledge: {slug} ---
286
- {full KNOWLEDGE.md content}
294
+ KB: .devflow/features/{slug}/KNOWLEDGE.md
295
+ Rules:
296
+ - **KB-AP-2** {bullet text, verbatim}
297
+ - **KB-INV-1** {bullet text, verbatim}
298
+ Headings: L5 Rules · L40 Overview · L62 Anti-Patterns · L118 Key Files
287
299
  ```
288
300
 
289
- If no KBs exist, no KBs are relevant, or `.devflow/features/` is absent, set `FEATURE_KNOWLEDGE` to `(none)`.
301
+ A KB with no Rules section labels its entries `Rules ({section name}):` and gives them no ID. `FEATURE_KNOWLEDGE` is these blocks; `FEATURE_KNOWLEDGE_RULES` is the same blocks without the `Headings:` line. Both come from this one selection, and each spawn names the variable its recipient takes. If no KBs exist, no KBs are relevant, or `.devflow/features/` is absent, set both to `(none)`.
290
302
 
291
- **One git call, then direct file reads — no `.cjs` script.** After resolving `{worktree}`, this step is 1 index read (or N frontmatter reads on fallback), bounded by KB count.
303
+ **One git call, then direct reads — no `.cjs` script.** After resolving `{worktree}`, this step is 1 index read (or N frontmatter reads on fallback), plus one heading listing and one Rules read per selected KB, bounded by KB count.
292
304
 
293
305
  ### Phase 2: Implement
294
306
 
@@ -313,7 +325,8 @@ Based on Setup context (plan document, issue body, or conversation context), use
313
325
 
314
326
  ```
315
327
  Agent(subagent_type="Code"):
316
- "TASK_ID: {task-id}
328
+ "OPERATION: implement
329
+ TASK_ID: {task-id}
317
330
  TASK_DESCRIPTION: {description}
318
331
  BASE_BRANCH: {base branch}
319
332
  EXECUTION_PLAN: {full plan from setup context}
@@ -334,12 +347,13 @@ PR_TEST_PLAN_BLOCK: {PR_TEST_PLAN_BLOCK from Phase 1 verbatim, or (none)}"
334
347
 
335
348
  **SEQUENTIAL_CODE_AGENTS** (for HIGH/CRITICAL context risk):
336
349
 
337
- Spawn Code agents one at a time, passing handoff summaries between phases:
350
+ 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:
338
351
 
339
352
  **Phase 1 Code agent:**
340
353
  ```
341
354
  Agent(subagent_type="Code"):
342
- "TASK_ID: {task-id}
355
+ "OPERATION: implement
356
+ TASK_ID: {task-id}
343
357
  TASK_DESCRIPTION: {phase 1 description}
344
358
  BASE_BRANCH: {base branch}
345
359
  EXECUTION_PLAN: {phase 1 steps}
@@ -359,7 +373,8 @@ HANDOFF_FILE: {worktree}/.devflow/docs/handoff-{branch_slug}.md"
359
373
  **Phase 2+ Code agents** (after prior phase completes):
360
374
  ```
361
375
  Agent(subagent_type="Code"):
362
- "TASK_ID: {task-id}
376
+ "OPERATION: implement
377
+ TASK_ID: {task-id}
363
378
  TASK_DESCRIPTION: {phase N description}
364
379
  BASE_BRANCH: {base branch}
365
380
  EXECUTION_PLAN: {phase N steps}
@@ -380,7 +395,7 @@ HANDOFF_REQUIRED: {true if not last phase}
380
395
  HANDOFF_FILE: {worktree}/.devflow/docs/handoff-{branch_slug}.md"
381
396
  ```
382
397
 
383
- **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).
398
+ **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).
384
399
 
385
400
  ---
386
401
 
@@ -390,7 +405,8 @@ Spawn multiple Code agents **in a single message**, each with independent subtas
390
405
 
391
406
  ```
392
407
  Agent(subagent_type="Code"): # Code agent 1
393
- "TASK_ID: {task-id}-part1
408
+ "OPERATION: implement
409
+ TASK_ID: {task-id}-part1
394
410
  TASK_DESCRIPTION: {independent subtask 1}
395
411
  BASE_BRANCH: {base branch}
396
412
  EXECUTION_PLAN: {subtask 1 steps}
@@ -405,7 +421,8 @@ ISSUE_NUMBER: {ISSUE_ID captured in Phase 1, or (none)}
405
421
  ISSUE_PR_LINK: {ISSUE_PR_LINK captured in Phase 1, or (none)}"
406
422
 
407
423
  Agent(subagent_type="Code"): # Code agent 2 (same message)
408
- "TASK_ID: {task-id}-part2
424
+ "OPERATION: implement
425
+ TASK_ID: {task-id}-part2
409
426
  TASK_DESCRIPTION: {independent subtask 2}
410
427
  BASE_BRANCH: {base branch}
411
428
  EXECUTION_PLAN: {subtask 2 steps}
@@ -426,110 +443,46 @@ ISSUE_PR_LINK: {ISSUE_PR_LINK captured in Phase 1, or (none)}"
426
443
  - Different files/modules with no imports between them
427
444
  - Each subtask is self-contained
428
445
 
429
- ### Phase 3: Validate
430
-
431
- **Produces:** VALIDATION_RESULT
432
- **Requires:** FILES_CHANGED
433
-
434
- After Code agent completes, spawn Validate agent to verify correctness:
435
-
436
- ```
437
- Agent(subagent_type="Validate"):
438
- "FILES_CHANGED: {list of files from Code agent output}
439
- VALIDATION_SCOPE: full
440
- Run build, typecheck, lint, test. Report pass/fail with failure details."
441
- ```
442
-
443
- **If FAIL:**
444
- 1. Extract failure details from Validate agent output
445
- 2. Increment `validation_retry_count`
446
- 3. If `validation_retry_count <= 2`:
447
- - Spawn Code agent with fix context:
448
- ```
449
- Agent(subagent_type="Code"):
450
- "TASK_ID: {task-id}
451
- TASK_DESCRIPTION: Fix validation failures
452
- OPERATION: validation-fix
453
- VALIDATION_FAILURES: {parsed failures from Validate agent}
454
- SCOPE: Fix only the listed failures, no other changes
455
- CREATE_PR: false
456
- ISSUE_NUMBER: {ISSUE_ID captured in Phase 1, or (none)}
457
- ISSUE_PR_LINK: {ISSUE_PR_LINK captured in Phase 1, or (none)}
458
- COMPLIANCE_FRAMEWORKS: {COMPLIANCE_FRAMEWORKS}"
459
- ```
460
- - Loop back to Phase 3 (re-validate)
461
- 4. If `validation_retry_count > 2`: Report failures to user and halt
462
-
463
- **If PASS:** append a `gate:validate` claim, then continue to Phase 4.
464
-
465
- **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:
466
-
467
- ```
468
- - gate:validate PASS sha:<head> by:validate
469
- - TP-<n> <PASS|FAIL|SKIP> sha:<head> by:test exit:<0-255>
470
- ```
471
-
472
- - `gate:validate` — after a Phase 3 or Phase 6 PASS.
473
- - `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.
474
- - 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.
475
-
476
- ### Phase 4: Simplify
446
+ ### Phase 3: Simplify
477
447
 
478
448
  **Produces:** SIMPLIFY_OUTPUT
479
449
  **Requires:** FILES_CHANGED
480
450
 
481
- After validation passes, spawn Simplify agent to polish the code:
451
+ After the Code agent completes, spawn Simplify agent to polish the code. The Phase 6 Validate covers its commits.
482
452
 
483
453
  ```
484
454
  Agent(subagent_type="Simplify"):
485
455
  "Simplify recently implemented code
486
456
  Task: {task description}
487
457
  FILES_CHANGED: {list of files from Code agent output}
488
- Focus on code modified by Code agent, apply project standards, enhance clarity"
458
+ Focus on code modified by Code agent, apply project standards, enhance clarity
459
+ Commit any improvements with a conventional-commit message."
489
460
  ```
490
461
 
491
- ### Phase 5: Self-Review
462
+ ### Phase 4: Self-Review
492
463
 
493
464
  **Produces:** SCRUTINIZE_OUTPUT
494
465
  **Requires:** FILES_CHANGED
495
466
 
496
- After Simplify agent completes, spawn Scrutinize agent as final quality gate:
467
+ After Simplify agent completes, spawn Scrutinize agent as the quality gate:
497
468
 
498
469
  ```
499
470
  Agent(subagent_type="Scrutinize"):
500
471
  "TASK_DESCRIPTION: {task description}
501
472
  FILES_CHANGED: {list of files from Code agent output}
502
473
  DECISIONS_CONTEXT: {decisions_context}
503
- FEATURE_KNOWLEDGE: {feature_knowledge}
474
+ FEATURE_KNOWLEDGE: {feature_knowledge_rules}
504
475
  Evaluate 9 pillars, fix P0/P1 issues, report status"
505
476
  ```
506
477
 
507
- If Scrutinize agent returns BLOCKED, report to user and halt.
508
-
509
- ### Phase 6: Re-Validate (if Scrutinize agent made changes)
510
-
511
- **Produces:** REVALIDATION_RESULT
512
- **Requires:** SCRUTINIZE_OUTPUT
513
-
514
- If Scrutinize agent made code changes (status: FIXED), spawn Validate agent to verify:
515
-
516
- ```
517
- Agent(subagent_type="Validate"):
518
- "FILES_CHANGED: {files modified by Scrutinize agent}
519
- VALIDATION_SCOPE: changed-only
520
- Verify Scrutinize agent's fixes didn't break anything."
521
- ```
522
-
523
- **If FAIL:** Report to user - Scrutinize agent broke tests, needs manual intervention.
524
-
525
- **If PASS:** append a `gate:validate` claim (Phase 3's **Evidence claims**), then continue to Phase 7.
478
+ 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.
526
479
 
527
- ### Phase 7: Alignment Check
480
+ ### Phase 5: Alignment Check
528
481
 
529
482
  **Produces:** ALIGNMENT_RESULT
530
483
  **Requires:** FILES_CHANGED, EXECUTION_PLAN
531
484
 
532
- After Scrutinize agent passes (and re-validation if needed), spawn Evaluate agent to validate alignment:
485
+ 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:
533
486
 
534
487
  ```
535
488
  Agent(subagent_type="Evaluate"):
@@ -537,11 +490,11 @@ Agent(subagent_type="Evaluate"):
537
490
  EXECUTION_PLAN: {execution plan from Phase 1}
538
491
  FILES_CHANGED: {list of files from Code agent output}
539
492
  ACCEPTANCE_CRITERIA: {extracted criteria if available}
540
- FEATURE_KNOWLEDGE: {feature_knowledge}
493
+ FEATURE_KNOWLEDGE: {feature_knowledge_rules}
541
494
  Validate alignment with request and plan. Report ALIGNED or MISALIGNED with details."
542
495
  ```
543
496
 
544
- **If ALIGNED:** Continue to Phase 8
497
+ **If ALIGNED:** Continue to Phase 6
545
498
 
546
499
  **If MISALIGNED:**
547
500
  1. Extract misalignment details from Evaluate agent output
@@ -550,32 +503,74 @@ Validate alignment with request and plan. Report ALIGNED or MISALIGNED with deta
550
503
  - Spawn Code agent to fix misalignments:
551
504
  ```
552
505
  Agent(subagent_type="Code"):
553
- "TASK_ID: {task-id}
506
+ "OPERATION: alignment-fix
507
+ TASK_ID: {task-id}
554
508
  TASK_DESCRIPTION: Fix alignment issues
555
- OPERATION: alignment-fix
556
509
  MISALIGNMENTS: {structured misalignments from Evaluate agent}
557
510
  SCOPE: Fix only the listed misalignments, no other changes
558
511
  CREATE_PR: false
512
+ DECISIONS_CONTEXT: {decisions_context}
559
513
  ISSUE_NUMBER: {ISSUE_ID captured in Phase 1, or (none)}
560
514
  ISSUE_PR_LINK: {ISSUE_PR_LINK captured in Phase 1, or (none)}
561
515
  COMPLIANCE_FRAMEWORKS: {COMPLIANCE_FRAMEWORKS}"
562
516
  ```
563
- - Spawn Validate agent to verify fix didn't break tests:
517
+ - Loop back to Phase 5 (re-check alignment). The fix is not validated here: the Phase 6 run covers it.
518
+ 4. If `alignment_fix_count > 2`: Report misalignments to user for decision
519
+
520
+ ### Phase 6: Validate
521
+
522
+ **Produces:** VALIDATION_RESULT, VALIDATED_HEAD
523
+ **Requires:** BASE_BRANCH
524
+
525
+ 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`):
526
+
527
+ ```
528
+ Agent(subagent_type="Validate"):
529
+ "FILES_CHANGED: {output of `git diff --name-only {base}...HEAD`}
530
+ VALIDATION_SCOPE: full
531
+ Run build, typecheck, lint, test. Report pass/fail with failure details."
532
+ ```
533
+
534
+ **If FAIL:**
535
+ 1. Extract failure details from Validate agent output
536
+ 2. Increment `validation_retry_count`
537
+ 3. If `validation_retry_count <= 2`:
538
+ - Spawn Code agent with fix context:
564
539
  ```
565
- Agent(subagent_type="Validate"):
566
- "FILES_CHANGED: {files modified by fix Code agent}
567
- VALIDATION_SCOPE: changed-only"
540
+ Agent(subagent_type="Code"):
541
+ "OPERATION: validation-fix
542
+ TASK_ID: {task-id}
543
+ TASK_DESCRIPTION: Fix validation failures
544
+ VALIDATION_FAILURES: {parsed failures from Validate agent}
545
+ SCOPE: Fix only the listed failures, no other changes
546
+ CREATE_PR: false
547
+ DECISIONS_CONTEXT: {decisions_context}
548
+ ISSUE_NUMBER: {ISSUE_ID captured in Phase 1, or (none)}
549
+ ISSUE_PR_LINK: {ISSUE_PR_LINK captured in Phase 1, or (none)}
550
+ COMPLIANCE_FRAMEWORKS: {COMPLIANCE_FRAMEWORKS}"
568
551
  ```
569
- - If Validate agent FAIL: Report to user
570
- - If Validate agent PASS: Loop back to Phase 7 (re-check alignment)
571
- 4. If `alignment_fix_count > 2`: Report misalignments to user for decision
552
+ - Loop back to Phase 6 (re-validate at the new HEAD, full scope)
553
+ 4. If `validation_retry_count > 2`: Report failures to user and halt
572
554
 
573
- ### Phase 8: QA Testing
555
+ **If PASS:** append a `gate:validate` claim, run `git rev-parse HEAD` and record the result as `VALIDATED_HEAD`, then continue to Phase 7.
556
+
557
+ **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:
558
+
559
+ ```
560
+ - gate:validate PASS sha:<head> by:validate
561
+ - TP-<n> <PASS|FAIL|SKIP> sha:<head> by:test exit:<0-255>
562
+ ```
563
+
564
+ - `gate:validate` — after a Phase 6 or Phase 8 PASS.
565
+ - `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.
566
+ - 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.
567
+
568
+ ### Phase 7: QA Testing
574
569
 
575
570
  **Produces:** QA_RESULT
576
- **Requires:** FILES_CHANGED, EXECUTION_PLAN, TEST_PLAN
571
+ **Requires:** FILES_CHANGED, EXECUTION_PLAN, TEST_PLAN, VALIDATED_HEAD
577
572
 
578
- After Evaluate agent passes, spawn Test agent for scenario-based acceptance testing:
573
+ After Phase 6 passes, spawn Test agent for scenario-based acceptance testing:
579
574
 
580
575
  ```
581
576
  Agent(subagent_type="Test"):
@@ -587,9 +582,9 @@ TEST_PLAN: {the TP lines of the evidence file's ## Test Plan section, or (none)}
587
582
  Design and execute scenario-based acceptance tests. Report PASS or FAIL with evidence."
588
583
  ```
589
584
 
590
- After every Test agent run — PASS or FAIL, first run or retry — append its TP claims (Phase 3's **Evidence claims**).
585
+ After every Test agent run — PASS or FAIL, first run or retry — append its TP claims (Phase 6's **Evidence claims**).
591
586
 
592
- **If PASS:** Continue to Phase 9
587
+ **If PASS:** Continue to Phase 8
593
588
 
594
589
  **If FAIL:**
595
590
  1. Extract failure details from Test agent output
@@ -598,25 +593,37 @@ After every Test agent run — PASS or FAIL, first run or retry — append its T
598
593
  - Spawn Code agent to fix QA failures:
599
594
  ```
600
595
  Agent(subagent_type="Code"):
601
- "TASK_ID: {task-id}
596
+ "OPERATION: qa-fix
597
+ TASK_ID: {task-id}
602
598
  TASK_DESCRIPTION: Fix QA test failures
603
- OPERATION: qa-fix
604
599
  QA_FAILURES: {structured failures from Test agent}
605
600
  SCOPE: Fix only the listed failures, no other changes
606
601
  CREATE_PR: false
602
+ DECISIONS_CONTEXT: {decisions_context}
607
603
  ISSUE_NUMBER: {ISSUE_ID captured in Phase 1, or (none)}
608
604
  ISSUE_PR_LINK: {ISSUE_PR_LINK captured in Phase 1, or (none)}
609
605
  COMPLIANCE_FRAMEWORKS: {COMPLIANCE_FRAMEWORKS}"
610
606
  ```
611
- - Spawn Validate agent to verify fix didn't break tests:
612
- ```
613
- Agent(subagent_type="Validate"):
614
- "FILES_CHANGED: {files modified by fix Code agent}
615
- VALIDATION_SCOPE: changed-only"
616
- ```
617
- - If Validate agent FAIL: Report to user
618
- - If Validate agent PASS: Loop back to Phase 8 (re-run Test agent)
619
- 4. If `qa_retry_count > 2`: Report QA failures to user for decision
607
+ - Loop back to Phase 7 (re-run Test agent). The fix is not validated here: Phase 8 covers it.
608
+ 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.
609
+
610
+ ### Phase 8: Re-Validate (only if a qa-fix committed)
611
+
612
+ **Produces:** REVALIDATION_RESULT
613
+ **Requires:** QA_RESULT, VALIDATED_HEAD
614
+
615
+ 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:
616
+
617
+ ```
618
+ Agent(subagent_type="Validate"):
619
+ "FILES_CHANGED: {output of `git diff --name-only VALIDATED_HEAD..HEAD`}
620
+ VALIDATION_SCOPE: changed-only
621
+ Verify the qa-fix commits did not break anything."
622
+ ```
623
+
624
+ **If FAIL:** Report the failures to user and halt.
625
+
626
+ **If PASS:** append a `gate:validate` claim (Phase 6's **Evidence claims**), then continue to Phase 9.
620
627
 
621
628
  ### Phase 9: CI Status Gate
622
629
 
@@ -625,14 +632,22 @@ After every Test agent run — PASS or FAIL, first run or retry — append its T
625
632
 
626
633
  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).
627
634
 
635
+ **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:
636
+
637
+ ```bash
638
+ git push origin HEAD; echo "exit=$?"
639
+ ```
640
+
641
+ `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`.
642
+
628
643
  <!-- PATTERN: ci-status-gate -->
629
- 1. Spawn `Agent(subagent_type="Git")` with `OPERATION: check-ci-status` and `PR_NUMBER` from PR_URL.
644
+ 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.
630
645
  2. **If PASSING** → proceed to Phase 10.
631
646
  3. **If NO_PR or NO_CI** → skip: "No PR/CI configured, skipping CI validation." Proceed to Phase 10.
632
- 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.
633
- 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.
634
- 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.
635
- 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.
647
+ 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.
648
+ 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.
649
+ 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.
650
+ 7. **Budget**: at most 3 waits and 2 fixes in all. When one is spent, report the current status and proceed.
636
651
  <!-- /PATTERN: ci-status-gate -->
637
652
 
638
653
  ### Phase 10: Create PR
@@ -646,9 +661,9 @@ Strategy-conditional: run when the PR already exists — **SINGLE_CODE_AGENT** a
646
661
 
647
662
  ```
648
663
  Agent(subagent_type="Code"):
649
- "TASK_ID: {task-id}
664
+ "OPERATION: pr-create
665
+ TASK_ID: {task-id}
650
666
  TASK_DESCRIPTION: Create the unified PR for the parallel implementation
651
- OPERATION: pr-create
652
667
  BASE_BRANCH: {base branch}
653
668
  CREATE_PR: true
654
669
  PR_DESCRIPTION_GUIDANCE: {pr_description_guidance}
@@ -698,7 +713,7 @@ Display completion summary with phase status, PR info, and next steps.
698
713
 
699
714
  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`.
700
715
 
701
- 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.
716
+ 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.
702
717
 
703
718
  If Phase 1 recorded an evidence exception, show its `## Evidence Exceptions` lines in the report.
704
719
 
@@ -712,24 +727,14 @@ git -C "{start}" rev-parse --show-toplevel
712
727
 
713
728
  and use its one-line output. If the command fails (outside a git repository), `{worktree}` is the start directory itself. All paths below are relative to `{worktree}`.
714
729
 
715
- **Step 1 — Check the opt-out gate, with `{root}` = `{worktree}`:**
716
-
717
- **Resolve the settings line** once per worktree root, reusing a line this run already resolved for the same root. `{root}` is the worktree the values are for — the repository root when the run has one worktree:
718
-
719
- ```bash
720
- node "$HOME/.devflow/scripts/resolve-settings.cjs" "{root}" 2>/dev/null; echo "exit=$?"
721
- ```
722
-
723
- Accept the output only when it is exactly two lines: `exit=0` last and, before it, one line of the form `TRACKER=<github|jira|linear> TRACKER_SOURCE=<project|personal|machine|default> TRACKER_WARN=<none|mismatch|invalid> SITE=<none|https://<host>> KEY=<none|<key>> REVIEW_PUBLICATION=<off|auto|full> COMPLIANCE=<off|generic|<id>[,<id>…]> MEMORY=<on|off> LEARNING=<on|off> KNOWLEDGE=<on|off>` — these fields, in this order, nothing else, where `<host>` is a lowercase dotted host name alone, `<key>` is 2–10 of `A-Z`, `0-9` and `_` starting with a letter, and each `<id>` is one of `gdpr`, `hipaa`, `pci-dss`, `soc2`, `iso-27001`, `sox`. **Anything else** (a non-zero exit, no line, extra text, or a missing, reordered or unlisted field or value) ⇒ use `TRACKER=github TRACKER_SOURCE=default TRACKER_WARN=invalid SITE=none KEY=none REVIEW_PUBLICATION=off COMPLIANCE=generic MEMORY=on LEARNING=on KNOWLEDGE=off` instead.
724
-
725
- The accepted line is the only source of these values: the script alone folds the committed `.devflow/project.json`, the personal `.devflow/config.json` and the machine manifest.
730
+ **Step 1 — Check the opt-out gate, with `{root}` = `{worktree}`:** take the settings line resolved above for that root, resolving it with the settings block when this run has not yet.
726
731
 
727
732
  If the settings line says `KNOWLEDGE=off`, skip write-back entirely. The machine switch (`devflow knowledge --disable`), the repository and the personal settings can each turn knowledge off, and none can turn it back on (D-FEATURES-NARROW-ONLY). The fail-closed line says `KNOWLEDGE=off` too, so an unresolvable line skips write-back.
728
733
 
729
734
  **Step 2 — Evaluate whether write-back is warranted:**
730
735
 
731
736
  Only proceed if **at least one** of these is true:
732
- - This workflow changed files in a directory that is documented by an existing feature knowledge base (a documented area changed).
737
+ - This workflow changed files in a directory that is documented by an existing feature knowledge base (a documented area changed). Knowledge bases are written through at that point, never on a background schedule.
733
738
  - This workflow surfaced durable, cross-cutting knowledge about a codebase area that would help future agents working in the same area — patterns, anti-patterns, integration points, gotchas not visible from a single file read.
734
739
 
735
740
  **Never spawn unconditionally.** If neither condition is met, skip write-back silently.
@@ -752,7 +757,7 @@ Write the knowledge base to:
752
757
  Then update the index cache by performing a read-modify-write on:
753
758
  {worktree}/.devflow/features/index.md
754
759
 
755
- Index line format: `- **{slug}** — {areas} — {Use-when description}`
760
+ Index line format: `- **{slug}** — {areas} — {Use-when description}` — at most 300 characters, the description at most 220; reword a longer one, never cut it.
756
761
 
757
762
  If the line for this slug already exists in index.md, replace it. If it does not exist, append it. If index.md does not exist, create it with just this line.
758
763
 
@@ -786,30 +791,30 @@ When the Knowledge agent reports `KB_COMMIT: skipped (detached HEAD)`, the files
786
791
  │ ├─ SEQUENTIAL_CODE_AGENTS (15%): N Code agents with handoff summaries
787
792
  │ └─ PARALLEL_CODE_AGENTS (5%): N Code agents in single message (rare)
788
793
  │
789
- ├─ Phase 3: Validate
790
- │ └─ Validate agent (build, typecheck, lint, test)
791
- │ └─ If FAIL: Code agent fix loop (max 2 retries) → re-validate
792
- │ └─ If PASS: gate:validate claim → evidence file
793
- │
794
- ├─ Phase 4: Simplify
794
+ ├─ Phase 3: Simplify
795
795
  │ └─ Simplify agent (refines code clarity and consistency)
796
796
  │
797
- ├─ Phase 5: Self-Review
798
- │ └─ Scrutinize agent (final quality gate, fixes P0/P1)
797
+ ├─ Phase 4: Self-Review
798
+ │ └─ Scrutinize agent (quality gate, fixes P0/P1; status PASS | FIXED | BLOCKED)
799
799
  │
800
- ├─ Phase 6: Re-Validate (if Scrutinize agent made changes)
801
- │ └─ Validate agent (verify Scrutinize agent fixes)
802
- │
803
- ├─ Phase 7: Alignment Check
800
+ ├─ Phase 5: Alignment Check
804
801
  │ └─ Evaluate agent (validates alignment - reports only, no fixes)
805
- │ └─ If MISALIGNED: Code agent fix loop (max 2 iterations) → Validate agent → re-check
802
+ │ └─ If MISALIGNED: Code agent fix loop (max 2 iterations) → re-check alignment
803
+ │
804
+ ├─ Phase 6: Validate (the one full-suite slot)
805
+ │ └─ Validate agent (build, typecheck, lint, test over the branch diff)
806
+ │ └─ If FAIL: Code agent fix loop (max 2 retries) → re-validate at the new HEAD
807
+ │ └─ If PASS: record VALIDATED_HEAD, gate:validate claim → evidence file
806
808
  │
807
- ├─ Phase 8: QA Testing
809
+ ├─ Phase 7: QA Testing
808
810
  │ └─ Test agent (scenario-based acceptance tests, TEST_PLAN) → one claim per TP row → evidence file
809
- │ └─ If FAIL: Code agent fix loop (max 2 retries) → Validate agent → re-test
811
+ │ └─ If FAIL: Code agent fix loop (max 2 retries) → re-test
812
+ │
813
+ ├─ Phase 8: Re-Validate (only if a qa-fix committed)
814
+ │ └─ Validate agent (changed-only over VALIDATED_HEAD..HEAD) → gate:validate claim
810
815
  │
811
816
  ├─ Phase 9: CI Status Gate (SINGLE_CODE_AGENT + SEQUENTIAL_CODE_AGENTS; skipped for PARALLEL_CODE_AGENTS)
812
- │ └─ Git agent (check-ci-status) → poll/fix cycle (10 polls + 2 fix budget)
817
+ │ └─ Push the branch, then ci-wait.cjs (inline, one wait ≤ 570 s) → Code agent on FAILING (3 waits + 2 fixes)
813
818
  │
814
819
  ├─ Phase 10: Create PR (if needed)
815
820
  │ └─ SINGLE_CODE_AGENT: already created by the Phase 2 Code agent
@@ -828,7 +833,7 @@ When the Knowledge agent reports `KB_COMMIT: skipped (detached HEAD)`, the files
828
833
 
829
834
  ## Principles
830
835
 
831
- 1. **Orchestration only** - Command spawns agents, never does work itself
836
+ 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
832
837
  2. **Plan-first** - Plan documents from `/plan` skip exploration/planning overhead entirely
833
838
  3. **Coherence-first** - Single Code agent produces more consistent code (default ~80% of tasks)
834
839
  4. **Agent ownership** - Each agent owns its output completely
@@ -838,7 +843,7 @@ When the Knowledge agent reports `KB_COMMIT: skipped (detached HEAD)`, the files
838
843
  8. **Strict delegation** - Never perform agent work in main session. "Spawn X" means call Agent tool with X, not do X's work yourself
839
844
  9. **Validate agent owns validation** - Never run `npm test`, `npm run build`, or similar in main session; always delegate to Validate agent
840
845
  10. **Code agent owns fixes** - Never implement fixes in main session; spawn Code agent for validation failures and alignment fixes
841
- 11. **Loop limits** - Max 2 validation retries, max 2 alignment fix iterations before escalating to user
846
+ 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
842
847
  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
843
848
 
844
849
  ## Error Handling