@ktpartners/dgs-platform 2.9.0 → 3.3.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 (166) hide show
  1. package/CHANGELOG.md +197 -0
  2. package/README.md +34 -2
  3. package/agents/dgs-executor.md +124 -3
  4. package/agents/dgs-idea-researcher.md +447 -0
  5. package/agents/dgs-plan-checker.md +61 -3
  6. package/agents/dgs-planner.md +51 -8
  7. package/bin/install.js +44 -0
  8. package/commands/dgs/abandon-quick.md +28 -0
  9. package/commands/dgs/add-tests.md +2 -2
  10. package/commands/dgs/audit-milestone.md +4 -3
  11. package/commands/dgs/capture-principle.md +11 -11
  12. package/commands/dgs/cleanup.md +2 -2
  13. package/commands/dgs/complete-milestone.md +11 -11
  14. package/commands/dgs/complete-quick.md +28 -0
  15. package/commands/dgs/create-milestone-job.md +2 -2
  16. package/commands/dgs/debug.md +3 -3
  17. package/commands/dgs/develop-idea.md +1 -1
  18. package/commands/dgs/diff-report.md +124 -0
  19. package/commands/dgs/fast.md +3 -1
  20. package/commands/dgs/health.md +1 -1
  21. package/commands/dgs/map-codebase.md +6 -6
  22. package/commands/dgs/new-milestone.md +5 -5
  23. package/commands/dgs/new-project.md +8 -21
  24. package/commands/dgs/package-scan.md +43 -0
  25. package/commands/dgs/plan-milestone-gaps.md +1 -1
  26. package/commands/dgs/progress.md +3 -3
  27. package/commands/dgs/quick-abandon.md +8 -0
  28. package/commands/dgs/quick-complete.md +8 -0
  29. package/commands/dgs/quick.md +10 -3
  30. package/commands/dgs/research-idea.md +3 -2
  31. package/commands/dgs/research-phase.md +3 -3
  32. package/commands/dgs/switch-project.md +14 -1
  33. package/commands/dgs/write-spec.md +3 -3
  34. package/deliver-great-systems/bin/dgs-tools.cjs +401 -32
  35. package/deliver-great-systems/bin/lib/audit-tolerance.cjs +77 -0
  36. package/deliver-great-systems/bin/lib/audit-tolerance.test.cjs +101 -0
  37. package/deliver-great-systems/bin/lib/commands.cjs +626 -46
  38. package/deliver-great-systems/bin/lib/commands.test.cjs +451 -0
  39. package/deliver-great-systems/bin/lib/commit-verify.test.cjs +236 -0
  40. package/deliver-great-systems/bin/lib/config.cjs +80 -6
  41. package/deliver-great-systems/bin/lib/config.test.cjs +309 -0
  42. package/deliver-great-systems/bin/lib/context.cjs +120 -0
  43. package/deliver-great-systems/bin/lib/core.cjs +35 -14
  44. package/deliver-great-systems/bin/lib/core.test.cjs +79 -1
  45. package/deliver-great-systems/bin/lib/execution.cjs +49 -17
  46. package/deliver-great-systems/bin/lib/fast-routing.cjs +199 -0
  47. package/deliver-great-systems/bin/lib/fast-routing.test.cjs +108 -0
  48. package/deliver-great-systems/bin/lib/final-commit-precondition.test.cjs +87 -0
  49. package/deliver-great-systems/bin/lib/fixtures/package-scan/bundler-audit-gemfile.json +21 -0
  50. package/deliver-great-systems/bin/lib/fixtures/package-scan/gate-parity-expected.md +186 -0
  51. package/deliver-great-systems/bin/lib/fixtures/package-scan/gate-parity-runresult.json +235 -0
  52. package/deliver-great-systems/bin/lib/fixtures/package-scan/govulncheck-import.json +3 -0
  53. package/deliver-great-systems/bin/lib/fixtures/package-scan/npm-audit-v10.json +37 -0
  54. package/deliver-great-systems/bin/lib/fixtures/package-scan/osv-clean.json +3 -0
  55. package/deliver-great-systems/bin/lib/fixtures/package-scan/osv-vulns.json +77 -0
  56. package/deliver-great-systems/bin/lib/fixtures/package-scan/pip-audit-requirements.json +28 -0
  57. package/deliver-great-systems/bin/lib/fixtures/package-scan/snyk-lodash.json +30 -0
  58. package/deliver-great-systems/bin/lib/fixtures/package-scan/snyk-workspaces.json +55 -0
  59. package/deliver-great-systems/bin/lib/flat-migration.test.cjs +396 -0
  60. package/deliver-great-systems/bin/lib/frontmatter.cjs +1 -1
  61. package/deliver-great-systems/bin/lib/governance.cjs +211 -0
  62. package/deliver-great-systems/bin/lib/governance.test.cjs +339 -0
  63. package/deliver-great-systems/bin/lib/health-untracked-phase.test.cjs +269 -0
  64. package/deliver-great-systems/bin/lib/ideas.cjs +206 -91
  65. package/deliver-great-systems/bin/lib/ideas.test.cjs +244 -1
  66. package/deliver-great-systems/bin/lib/init.cjs +357 -61
  67. package/deliver-great-systems/bin/lib/init.test.cjs +625 -8
  68. package/deliver-great-systems/bin/lib/jobs.cjs +131 -25
  69. package/deliver-great-systems/bin/lib/jobs.test.cjs +193 -74
  70. package/deliver-great-systems/bin/lib/migration.cjs +409 -1
  71. package/deliver-great-systems/bin/lib/migration.test.cjs +158 -1
  72. package/deliver-great-systems/bin/lib/milestone.cjs +154 -31
  73. package/deliver-great-systems/bin/lib/milestone.test.cjs +203 -0
  74. package/deliver-great-systems/bin/lib/package-adapters.cjs +530 -0
  75. package/deliver-great-systems/bin/lib/package-adapters.test.cjs +618 -0
  76. package/deliver-great-systems/bin/lib/package-ecosystems.cjs +350 -0
  77. package/deliver-great-systems/bin/lib/package-ecosystems.test.cjs +348 -0
  78. package/deliver-great-systems/bin/lib/package-runner.cjs +199 -0
  79. package/deliver-great-systems/bin/lib/package-runner.test.cjs +198 -0
  80. package/deliver-great-systems/bin/lib/package-scan-provenance.cjs +56 -0
  81. package/deliver-great-systems/bin/lib/package-scan-provenance.test.cjs +103 -0
  82. package/deliver-great-systems/bin/lib/package-scan-report.cjs +1140 -0
  83. package/deliver-great-systems/bin/lib/package-scan-report.test.cjs +1963 -0
  84. package/deliver-great-systems/bin/lib/package-scan-skill.cjs +96 -0
  85. package/deliver-great-systems/bin/lib/package-scan-skill.test.cjs +136 -0
  86. package/deliver-great-systems/bin/lib/package-scan.cjs +919 -0
  87. package/deliver-great-systems/bin/lib/package-scan.test.cjs +2147 -0
  88. package/deliver-great-systems/bin/lib/phase.cjs +146 -3
  89. package/deliver-great-systems/bin/lib/phase.test.cjs +420 -0
  90. package/deliver-great-systems/bin/lib/plan-number-validity.test.cjs +48 -0
  91. package/deliver-great-systems/bin/lib/projects.cjs +65 -10
  92. package/deliver-great-systems/bin/lib/projects.test.cjs +198 -2
  93. package/deliver-great-systems/bin/lib/quick.cjs +739 -0
  94. package/deliver-great-systems/bin/lib/quick.test.cjs +730 -0
  95. package/deliver-great-systems/bin/lib/repos.cjs +37 -13
  96. package/deliver-great-systems/bin/lib/review.cjs +1821 -0
  97. package/deliver-great-systems/bin/lib/roadmap.cjs +34 -13
  98. package/deliver-great-systems/bin/lib/specs.cjs +3 -81
  99. package/deliver-great-systems/bin/lib/state-transition-gate.test.cjs +160 -0
  100. package/deliver-great-systems/bin/lib/state.cjs +147 -55
  101. package/deliver-great-systems/bin/lib/summary-frontmatter.cjs +54 -0
  102. package/deliver-great-systems/bin/lib/summary-frontmatter.test.cjs +78 -0
  103. package/deliver-great-systems/bin/lib/sweep-scope.test.cjs +263 -0
  104. package/deliver-great-systems/bin/lib/sync.cjs +75 -0
  105. package/deliver-great-systems/bin/lib/verify.cjs +198 -7
  106. package/deliver-great-systems/bin/lib/verify.test.cjs +82 -0
  107. package/deliver-great-systems/bin/lib/wave-0-template-rename.test.cjs +40 -0
  108. package/deliver-great-systems/bin/lib/worktrees.cjs +790 -0
  109. package/deliver-great-systems/bin/lib/worktrees.test.cjs +963 -0
  110. package/deliver-great-systems/references/agent-step-reliability.md +60 -0
  111. package/deliver-great-systems/references/conflict-resolution.md +4 -0
  112. package/deliver-great-systems/references/context-tiers.md +4 -0
  113. package/deliver-great-systems/references/package-scan-config.md +151 -0
  114. package/deliver-great-systems/references/questioning.md +0 -30
  115. package/deliver-great-systems/references/spec-review-loop.md +1 -2
  116. package/deliver-great-systems/references/workflow-conventions.md +29 -0
  117. package/deliver-great-systems/skills/dgs-tests/package-scan.md +44 -0
  118. package/deliver-great-systems/templates/REVIEW.md +35 -0
  119. package/deliver-great-systems/templates/VALIDATION.md +1 -1
  120. package/deliver-great-systems/templates/claude-md.md +27 -0
  121. package/deliver-great-systems/templates/package-scan-report.md +108 -0
  122. package/deliver-great-systems/templates/project.md +6 -170
  123. package/deliver-great-systems/templates/summary.md +3 -1
  124. package/deliver-great-systems/workflows/abandon-quick.md +89 -0
  125. package/deliver-great-systems/workflows/add-idea.md +3 -3
  126. package/deliver-great-systems/workflows/add-phase.md +5 -0
  127. package/deliver-great-systems/workflows/add-tests.md +14 -0
  128. package/deliver-great-systems/workflows/add-todo.md +1 -0
  129. package/deliver-great-systems/workflows/approve-spec.md +25 -4
  130. package/deliver-great-systems/workflows/audit-milestone.md +66 -10
  131. package/deliver-great-systems/workflows/audit-phase.md +15 -5
  132. package/deliver-great-systems/workflows/cancel-job.md +2 -2
  133. package/deliver-great-systems/workflows/check-todos.md +2 -3
  134. package/deliver-great-systems/workflows/codereview.md +103 -9
  135. package/deliver-great-systems/workflows/complete-milestone.md +218 -24
  136. package/deliver-great-systems/workflows/complete-quick.md +106 -0
  137. package/deliver-great-systems/workflows/consolidate-ideas.md +1 -1
  138. package/deliver-great-systems/workflows/create-milestone-job.md +4 -4
  139. package/deliver-great-systems/workflows/develop-idea.md +11 -11
  140. package/deliver-great-systems/workflows/diagnose-issues.md +14 -0
  141. package/deliver-great-systems/workflows/discuss-idea.md +1 -1
  142. package/deliver-great-systems/workflows/discuss-phase.md +3 -2
  143. package/deliver-great-systems/workflows/execute-phase.md +209 -33
  144. package/deliver-great-systems/workflows/execute-plan.md +22 -22
  145. package/deliver-great-systems/workflows/help.md +53 -20
  146. package/deliver-great-systems/workflows/import-spec.md +65 -7
  147. package/deliver-great-systems/workflows/init-product.md +45 -167
  148. package/deliver-great-systems/workflows/new-milestone.md +140 -33
  149. package/deliver-great-systems/workflows/new-project.md +60 -331
  150. package/deliver-great-systems/workflows/package-scan.md +59 -0
  151. package/deliver-great-systems/workflows/plan-phase.md +79 -1
  152. package/deliver-great-systems/workflows/progress-all.md +133 -0
  153. package/deliver-great-systems/workflows/quick-abandon.md +89 -0
  154. package/deliver-great-systems/workflows/quick-complete.md +106 -0
  155. package/deliver-great-systems/workflows/quick.md +328 -26
  156. package/deliver-great-systems/workflows/refine-spec.md +1 -1
  157. package/deliver-great-systems/workflows/research-idea.md +77 -139
  158. package/deliver-great-systems/workflows/resume-project.md +2 -2
  159. package/deliver-great-systems/workflows/run-job.md +29 -43
  160. package/deliver-great-systems/workflows/settings.md +13 -77
  161. package/deliver-great-systems/workflows/validate-phase.md +39 -1
  162. package/deliver-great-systems/workflows/verify-work.md +14 -0
  163. package/deliver-great-systems/workflows/write-spec.md +11 -13
  164. package/hooks/dist/dgs-enforce-discipline.js +196 -0
  165. package/package.json +1 -1
  166. package/scripts/build-hooks.js +1 -0
@@ -9,7 +9,10 @@ Multi-agent code review that runs 3 passes of 3 parallel agents each (9 total re
9
9
  - PLAN: plan number
10
10
  - PLAN_PATH: path to the PLAN.md file
11
11
  - PHASE_DIR: phase directory path
12
+ - CODE_REPO_PATH: absolute path to the code repo where task commits live. All git commands in this workflow MUST run against this repo via `git -C "${CODE_REPO_PATH}"`, because the spawned subagent inherits the orchestrator's cwd (the planning repo), not the code repo.
12
13
  - DIFF_REF: git ref range for the code diff (from first task commit to HEAD)
14
+ - PROJECT_ROOT: project root directory path (e.g., projects/gsd). Passed by execute-phase. Used to resolve project-scoped context files.
15
+ - PLANNING_ROOT: planning root directory path (git repo root). Passed by execute-phase. Used as fallback for product-level context files.
13
16
  </inputs>
14
17
 
15
18
  <process>
@@ -18,7 +21,7 @@ Multi-agent code review that runs 3 passes of 3 parallel agents each (9 total re
18
21
  Compute the diff from the plan's task commits.
19
22
 
20
23
  ```bash
21
- FIRST_TASK_COMMIT=$(git log --oneline --grep="feat(${PHASE}-${PLAN}):" --grep="fix(${PHASE}-${PLAN}):" --grep="test(${PHASE}-${PLAN}):" --grep="refactor(${PHASE}-${PLAN}):" --reverse | head -1 | cut -d' ' -f1)
24
+ FIRST_TASK_COMMIT=$(git -C "${CODE_REPO_PATH}" log --oneline --grep="feat(${PHASE}-${PLAN}):" --grep="fix(${PHASE}-${PLAN}):" --grep="test(${PHASE}-${PLAN}):" --grep="refactor(${PHASE}-${PLAN}):" --reverse | head -1 | cut -d' ' -f1)
22
25
  ```
23
26
 
24
27
  If FIRST_TASK_COMMIT is empty, exit with message: "No task commits found for ${PHASE}-${PLAN}, skipping code review."
@@ -26,13 +29,13 @@ If FIRST_TASK_COMMIT is empty, exit with message: "No task commits found for ${P
26
29
  Otherwise, compute the full diff:
27
30
 
28
31
  ```bash
29
- REVIEW_DIFF=$(git diff ${FIRST_TASK_COMMIT}^..HEAD)
32
+ REVIEW_DIFF=$(git -C "${CODE_REPO_PATH}" diff ${FIRST_TASK_COMMIT}^..HEAD)
30
33
  ```
31
34
 
32
35
  Store REVIEW_DIFF for use by all review agents. Also store the file list:
33
36
 
34
37
  ```bash
35
- CHANGED_FILES=$(git diff --name-only ${FIRST_TASK_COMMIT}^..HEAD)
38
+ CHANGED_FILES=$(git -C "${CODE_REPO_PATH}" diff --name-only ${FIRST_TASK_COMMIT}^..HEAD)
36
39
  ```
37
40
 
38
41
  Display:
@@ -43,11 +46,77 @@ Reviewing ${PHASE}-${PLAN} changes:
43
46
  ```
44
47
  </step>
45
48
 
49
+ <step name="load_context">
50
+ Load project context files for domain-specific review. These files provide architecture rules, coding conventions, and design principles that the review agents use to catch project-specific violations alongside generic code quality issues.
51
+
52
+ If PROJECT_ROOT is empty or not provided, skip the entire step silently (backward compatibility for codereview spawned without PROJECT_ROOT).
53
+
54
+ **Context files (in truncation priority order -- first truncated = least valuable):**
55
+ 1. `codebase/ARCHITECTURE.md` -- auto-generated codebase structure overview
56
+ 2. `codebase/CONVENTIONS.md` -- auto-generated naming/import/error handling patterns
57
+ 3. `docs/product/ARCHITECTURE.md` -- hand-written target architecture and domain rules
58
+ 4. `docs/product/DESIGN-PRINCIPLES.md` -- hand-written design principles and lessons learned
59
+
60
+ **Path resolution (dual-path fallback):**
61
+ For each file, try two paths in order:
62
+ 1. `${PROJECT_ROOT}/<file>` (v2 project-scoped path)
63
+ 2. `${PLANNING_ROOT}/<file>` (v1 product-level / synthesized fallback)
64
+
65
+ Use the Read tool to load each file. If Read returns an error (file not found), silently skip that file. Do NOT error or warn for individual missing files.
66
+
67
+ **Build PROJECT_CONTEXT:**
68
+ For each successfully loaded file, prepend a header line:
69
+ ```
70
+ --- {filename} ({byte_count} bytes) ---
71
+ {file_content}
72
+ ```
73
+
74
+ Concatenate all loaded file contents into a single `PROJECT_CONTEXT` variable.
75
+
76
+ **Size guard:**
77
+ After loading all files, measure total byte length of PROJECT_CONTEXT.
78
+
79
+ If total exceeds 51200 bytes (~50KB):
80
+ - Truncate files in priority order (ARCHITECTURE.md from codebase/ first, then CONVENTIONS.md from codebase/, then docs/product/ARCHITECTURE.md, then docs/product/DESIGN-PRINCIPLES.md last)
81
+ - For each truncated file, cut to fit within the remaining budget and append: `\n[Truncated from {original_bytes} bytes to {truncated_bytes} bytes]`
82
+ - After truncation, log a warning:
83
+ ```
84
+ ⚠ Project context truncated to ~50KB:
85
+ {filename}: truncated from {original} to {truncated} bytes
86
+ ```
87
+
88
+ **Logging:**
89
+ Display which context files were loaded:
90
+
91
+ When at least one file found:
92
+ ```
93
+ Project context loaded:
94
+ codebase/ARCHITECTURE.md: {N} bytes
95
+ codebase/CONVENTIONS.md: {N} bytes (or "not found")
96
+ docs/product/ARCHITECTURE.md: {N} bytes (or "not found")
97
+ docs/product/DESIGN-PRINCIPLES.md: {N} bytes (or "not found")
98
+ Total: {N} bytes
99
+ ```
100
+
101
+ When no files found:
102
+ ```
103
+ Project context: no context files found (skipped)
104
+ ```
105
+ </step>
106
+
46
107
  <step name="pass_1_foundational">
47
108
  **Pass 1: Foundational Review** -- Spawn 3 parallel Task() subagents.
48
109
 
49
110
  Each agent receives REVIEW_DIFF and CHANGED_FILES as input context.
50
111
 
112
+ If PROJECT_CONTEXT is non-empty, also provide it to each agent wrapped in tags:
113
+
114
+ <project_context>
115
+ {PROJECT_CONTEXT}
116
+ </project_context>
117
+
118
+ If PROJECT_CONTEXT is empty (no context files found), omit the <project_context> block entirely -- agents receive the same prompt as before this feature was added.
119
+
51
120
  **Agent 1A: Correctness and Security**
52
121
 
53
122
  Review REVIEW_DIFF for:
@@ -57,6 +126,7 @@ Review REVIEW_DIFF for:
57
126
  - Auth bypass, missing authorization checks
58
127
  - Secret exposure (hardcoded keys, tokens, passwords)
59
128
  - Race conditions, deadlocks
129
+ - Violations of domain-specific rules from PROJECT_CONTEXT (if provided): architecture constraints, module boundary contracts, security policies declared in project docs
60
130
  - Memory leaks, resource cleanup
61
131
 
62
132
  Output: Structured findings list with fields:
@@ -81,7 +151,7 @@ Review REVIEW_DIFF against the plan's `<context>` file patterns for:
81
151
  - Type safety (any usage, missing types, loose generics)
82
152
  - Consistency with existing codebase patterns
83
153
 
84
- If a codebase/ map exists at ${project_root}/codebase/, reference CONVENTIONS.md for established patterns.
154
+ Reference the project conventions and patterns from PROJECT_CONTEXT (if provided) when evaluating naming, import patterns, error handling, and code organization. Flag deviations from the project's established conventions documented in PROJECT_CONTEXT.
85
155
 
86
156
  Output: Structured findings list with fields:
87
157
  - id: "1B-{N}"
@@ -113,6 +183,14 @@ Output: Structured findings list with fields:
113
183
 
114
184
  Each agent receives REVIEW_DIFF, CHANGED_FILES, and all Pass 1 findings as input context.
115
185
 
186
+ If PROJECT_CONTEXT is non-empty, also provide it to each agent wrapped in tags:
187
+
188
+ <project_context>
189
+ {PROJECT_CONTEXT}
190
+ </project_context>
191
+
192
+ If PROJECT_CONTEXT is empty (no context files found), omit the <project_context> block entirely -- agents receive the same prompt as before this feature was added.
193
+
116
194
  **Agent 2A: Fix Verification**
117
195
 
118
196
  For each auto-fixable finding from Pass 1 (severity medium or low with a clear fix), propose a concrete code change.
@@ -174,6 +252,14 @@ Output: Structured findings list with fields:
174
252
 
175
253
  Each agent receives REVIEW_DIFF, CHANGED_FILES, and all findings from Pass 1 and Pass 2 as input context.
176
254
 
255
+ If PROJECT_CONTEXT is non-empty, also provide it to each agent wrapped in tags:
256
+
257
+ <project_context>
258
+ {PROJECT_CONTEXT}
259
+ </project_context>
260
+
261
+ If PROJECT_CONTEXT is empty (no context files found), omit the <project_context> block entirely -- agents receive the same prompt as before this feature was added.
262
+
177
263
  **Agent 3A: Fresh Eyes**
178
264
 
179
265
  Re-read REVIEW_DIFF without bias from prior findings. Identify anything missed by the previous 6 agents. Focus on:
@@ -181,6 +267,7 @@ Re-read REVIEW_DIFF without bias from prior findings. Identify anything missed b
181
267
  - Edge cases in business logic
182
268
  - Assumptions that may not hold in production
183
269
  - Missing error messages or unhelpful error messages
270
+ - Violations of design principles stated in PROJECT_CONTEXT (if provided) that previous agents may have missed — compare implementation choices against documented principles and architectural decisions
184
271
 
185
272
  Output: Net-new findings only (deduplicated against all prior findings). Use fields:
186
273
  - id: "3A-{N}"
@@ -367,8 +454,8 @@ Take the proposed fixes from Agent 2A.
367
454
  4. Stage all successful fixes and commit:
368
455
 
369
456
  ```bash
370
- git add [fixed files]
371
- git commit -m "fix(${PHASE}-${PLAN}): codereview auto-fixes
457
+ git -C "${CODE_REPO_PATH}" add [fixed files]
458
+ git -C "${CODE_REPO_PATH}" commit -m "fix(${PHASE}-${PLAN}): codereview auto-fixes
372
459
 
373
460
  - [list each fix applied, one per bullet]
374
461
 
@@ -409,15 +496,22 @@ No fixes qualified for auto-application (all findings were critical/high severit
409
496
 
410
497
  Update the frontmatter: set `stats.auto_fixed` to `{FIXES_APPLIED}`.
411
498
 
412
- Include CODEREVIEW.md in the auto-fix commit by adding it to the staged files:
499
+ **Do NOT include CODEREVIEW.md in the auto-fix commit.** CODEREVIEW.md lives in the planning repo under `${PHASE_DIR}`, while the auto-fix commit lives in the code repo. `git -C "${CODE_REPO_PATH}" add ${CODEREVIEW_PATH}` would fail because `${CODEREVIEW_PATH}` is not inside `${CODE_REPO_PATH}`. CODEREVIEW.md will be picked up by the amend-metadata-commit at the bottom of the execute-phase codereview gate (which commits it in the planning repo).
500
+
501
+ For the auto-fix commit, stage only the code-repo files:
413
502
 
414
- Change the existing `git add [fixed files]` to also include CODEREVIEW.md:
415
503
  ```bash
416
- git add [fixed files] ${CODEREVIEW_PATH}
504
+ git -C "${CODE_REPO_PATH}" add [fixed files]
505
+ git -C "${CODE_REPO_PATH}" commit -m "fix(${PHASE}-${PLAN}): codereview auto-fixes
506
+
507
+ - [list each fix applied, one per bullet]
508
+
509
+ Co-Authored-By: Claude Code Review <noreply@anthropic.com>"
417
510
  ```
418
511
 
419
512
  If no auto-fixes were applied (commit skipped), commit CODEREVIEW.md alone:
420
513
  ```bash
514
+ # CODEREVIEW.md lives in the planning repo under ${PHASE_DIR}. This commit intentionally runs in the inherited (planning) cwd — do NOT use git -C "${CODE_REPO_PATH}" here.
421
515
  git add ${CODEREVIEW_PATH}
422
516
  git commit -m "docs(${PHASE}-${PLAN}): codereview report
423
517
 
@@ -25,8 +25,8 @@ Read these AFTER running the initialize step, not before.
25
25
 
26
26
  When a milestone completes:
27
27
 
28
- 1. Extract full milestone details to `${project_root}/milestones/v[X.Y]-ROADMAP.md`
29
- 2. Archive requirements to `${project_root}/milestones/v[X.Y]-REQUIREMENTS.md`
28
+ 1. Extract full milestone details to `milestones/v[X.Y]-ROADMAP.md`
29
+ 2. Archive requirements to `milestones/v[X.Y]-REQUIREMENTS.md`
30
30
  3. Update ROADMAP.md — replace milestone details with one-line summary
31
31
  4. Delete REQUIREMENTS.md (fresh one for next milestone)
32
32
  5. Perform full PROJECT.md evolution review
@@ -50,7 +50,7 @@ Load project context and resolve paths:
50
50
  INIT=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" init milestone-op)
51
51
  ```
52
52
 
53
- Parse JSON for: `commit_docs`, `state_path`, `roadmap_path`, `project_path`, `requirements_path`, `phases_dir`, `archive_dir`, `project_root`, `phase_count`, `completed_phases`, `all_phases_complete`.
53
+ Parse JSON for: `commit_docs`, `state_path`, `roadmap_path`, `project_path`, `requirements_path`, `phases_dir`, `archive_dir`, `project_root`, `phase_count`, `completed_phases`, `all_phases_complete`, `milestone_slug`, `milestone_version`, `milestone_name`.
54
54
 
55
55
  **Load verification tier context:**
56
56
 
@@ -65,6 +65,22 @@ Detect `JOB_MODE`:
65
65
  - Check if `<job-mode>silent</job-mode>` is present in the invoking context
66
66
  - Store as `JOB_MODE = true/false`
67
67
 
68
+ **Manual-only enforcement (CMP-01):**
69
+
70
+ If `JOB_MODE` is true OR `--auto` flag is present OR `--non-interactive` flag is present:
71
+
72
+ ```
73
+ ╔══════════════════════════════════════════════════════════════╗
74
+ ║ ERROR ║
75
+ ╚══════════════════════════════════════════════════════════════╝
76
+
77
+ complete-milestone cannot run in automated/job mode.
78
+ Milestone completion requires manual oversight for conflict resolution.
79
+
80
+ **To fix:** Run `/dgs:complete-milestone` interactively.
81
+ ```
82
+ **STOP.** Do not proceed. Exit the workflow.
83
+
68
84
  </step>
69
85
 
70
86
  <step name="verify_readiness">
@@ -124,6 +140,24 @@ MUST present 3 options:
124
140
 
125
141
  If user selects "Proceed anyway": note incomplete requirements in MILESTONES.md under `### Known Gaps` with REQ-IDs and descriptions.
126
142
 
143
+ **REVIEW.md existence check:**
144
+
145
+ ```bash
146
+ REVIEW_PATH="${project_root}/../milestones/${milestone_version}-REVIEW.md"
147
+ if [ ! -f "$REVIEW_PATH" ]; then
148
+ # Also check archive directory
149
+ REVIEW_PATH="${archive_dir}/${milestone_version}-REVIEW.md"
150
+ fi
151
+ ```
152
+
153
+ If REVIEW.md does not exist at either path:
154
+
155
+ ```
156
+ Warning: REVIEW.md not found — run `dgs-tools jobs generate-review` before sharing with reviewers
157
+ ```
158
+
159
+ This is a warning only — REVIEW.md absence does NOT block milestone completion. The report is supplementary context for four-eyes reviewers and can be generated after completion if needed.
160
+
127
161
  <config-check>
128
162
 
129
163
  ```bash
@@ -169,6 +203,177 @@ Wait for confirmation.
169
203
 
170
204
  </step>
171
205
 
206
+ <step name="rebase_and_merge_code_repos">
207
+
208
+ **Skip if:** No REPOS.md exists or no code repos registered. Log: `No code repos — skipping rebase and merge.`
209
+
210
+ **Check for active worktree:**
211
+
212
+ ```bash
213
+ WORKTREE_LIST=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" worktrees list 2>/dev/null)
214
+ ```
215
+
216
+ Parse JSON. Find entry matching `milestone_slug`. If no worktree found:
217
+
218
+ <!-- LEGACY: One-time migration path for users upgrading mid-milestone.
219
+ This code path handles milestones started with the old branching model.
220
+ Can be removed in a future version once all users have upgraded. -->
221
+
222
+ **Legacy branch detection (mid-milestone upgrade):**
223
+
224
+ Before skipping code repo merge, check if a milestone branch exists in the main checkout without a worktree entry. This handles users who upgraded to the worktree model mid-milestone.
225
+
226
+ ```bash
227
+ # Check for legacy milestone branches in each registered code repo
228
+ REPO_NAMES=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" repos list --names-only 2>/dev/null)
229
+ for REPO in $REPO_NAMES; do
230
+ REPO_PATH=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" repos resolve-path "$REPO" 2>/dev/null)
231
+ LEGACY_BRANCH=$(git -C "$REPO_PATH" branch --list "dgs/*${MILESTONE_SLUG}*" "milestone/${MILESTONE_SLUG}" "*-${MILESTONE_SLUG}" 2>/dev/null | head -1 | tr -d '* ')
232
+ done
233
+ ```
234
+
235
+ **If legacy branch found in any repo:**
236
+
237
+ Display: `Legacy milestone detected — merging without worktree.`
238
+
239
+ For each repo with a legacy branch:
240
+ 1. Ensure on base branch: `git -C "$REPO_PATH" checkout ${BASE_BRANCH}`
241
+ 2. Pull latest: `git -C "$REPO_PATH" pull --ff-only origin ${BASE_BRANCH}`
242
+ 3. Rebase milestone branch: `git -C "$REPO_PATH" rebase ${BASE_BRANCH} ${LEGACY_BRANCH}`
243
+ - If conflicts: abort rebase and show manual instructions (same pattern as worktree flow)
244
+ 4. Fast-forward merge: `git -C "$REPO_PATH" merge --ff-only ${LEGACY_BRANCH}`
245
+ 5. Delete legacy branch: `git -C "$REPO_PATH" branch -d ${LEGACY_BRANCH}`
246
+ 6. Push: `git -C "$REPO_PATH" push origin ${BASE_BRANCH}`
247
+ 7. Skip worktree cleanup (no worktree exists)
248
+
249
+ Continue to gather_stats (skip the worktree-based merge flow below).
250
+
251
+ **If no legacy branch found either:**
252
+
253
+ ```
254
+ No milestone worktree or legacy branch found for '${MILESTONE_SLUG}'.
255
+ No code repo merge needed — continuing with planning repo completion.
256
+ ```
257
+ Skip to gather_stats.
258
+
259
+ **If worktree found:**
260
+
261
+ Display banner:
262
+ ```
263
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
264
+ DGS ► MERGING CODE REPOS
265
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
266
+ ```
267
+
268
+ **For each code repo in REPOS.md (sequentially):**
269
+
270
+ ```bash
271
+ REPO_NAMES=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" repos list --names-only 2>/dev/null)
272
+ ```
273
+
274
+ For each repo name:
275
+
276
+ 1. **Check if repo is in the worktree state.** If not, skip (repo may not have been part of this milestone).
277
+
278
+ 2. **Check if already merged.** The milestone branch may have already been merged for this repo in a prior run. Check if the branch still exists:
279
+ ```bash
280
+ BRANCH_EXISTS=$(git -C "${MAIN_CHECKOUT}" branch --list "milestone/${MILESTONE_SLUG}" 2>/dev/null)
281
+ ```
282
+ If branch does not exist, log `${REPO_NAME}: Already merged (branch deleted). Skipping.` and continue to next repo.
283
+
284
+ 3. **Run rebaseAndMerge:**
285
+ ```bash
286
+ MERGE_RESULT=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" worktrees rebase-and-merge "${MILESTONE_SLUG}" --repo "${REPO_NAME}")
287
+ ```
288
+
289
+ 4. **Handle rebaseAndMerge result:**
290
+
291
+ **If `success: true`:**
292
+ ```
293
+ ✓ ${REPO_NAME}: Rebased and merged to ${BASE_BRANCH}
294
+ ```
295
+ Continue to next repo.
296
+
297
+ **If `conflicted: true`:**
298
+ Display the `manualInstructions` from the result:
299
+
300
+ ```
301
+ ╔══════════════════════════════════════════════════════════════╗
302
+ ║ CHECKPOINT: Action Required ║
303
+ ╚══════════════════════════════════════════════════════════════╝
304
+
305
+ Rebase conflict in ${REPO_NAME}. Automatic resolution failed.
306
+
307
+ ${MANUAL_INSTRUCTIONS}
308
+
309
+ ──────────────────────────────────────────────────────────────
310
+ → After resolving conflicts, re-run: /dgs:complete-milestone
311
+ ──────────────────────────────────────────────────────────────
312
+ ```
313
+ **STOP.** Do not proceed to the next repo or to archival. The user must resolve conflicts manually and re-run.
314
+
315
+ **If `success: false` (non-conflict error):**
316
+ ```
317
+ ╔══════════════════════════════════════════════════════════════╗
318
+ ║ ERROR ║
319
+ ╚══════════════════════════════════════════════════════════════╝
320
+
321
+ Merge failed for ${REPO_NAME}: ${ERROR}
322
+
323
+ **To fix:** Check the worktree state and re-run /dgs:complete-milestone
324
+ ```
325
+ **STOP.**
326
+
327
+ **After all repos merged successfully:**
328
+
329
+ 5. **Clean up worktree:**
330
+ ```bash
331
+ node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" worktrees remove "${MILESTONE_SLUG}"
332
+ ```
333
+
334
+ This removes:
335
+ - All worktree directories for this milestone
336
+ - Git worktree registrations
337
+ - Milestone branches
338
+ - active_context cleared to null
339
+
340
+ ```
341
+ ✓ Worktree cleanup complete for milestone '${MILESTONE_SLUG}'
342
+ ✓ Active context cleared
343
+ ```
344
+
345
+ 6. **Continue to mark_planning_repo_complete.**
346
+
347
+ </step>
348
+
349
+ <step name="mark_planning_repo_complete">
350
+
351
+ **Guard:** This step only runs after ALL code repos have successfully merged in the rebase_and_merge_code_repos step. The sequential stop-on-failure behavior ensures that if any repo fails, the workflow stops before reaching this step.
352
+
353
+ Mark the planning repo's STATE.md as milestone-complete, commit, and push:
354
+
355
+ ```
356
+ Marking milestone complete in planning repo...
357
+ ```
358
+
359
+ ```bash
360
+ MARK_RESULT=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" state mark-milestone-complete --raw 2>&1)
361
+ ```
362
+
363
+ Parse the result. If successful:
364
+
365
+ ```bash
366
+ node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" commit "docs(state): mark milestone ${MILESTONE_NAME} complete" --push --files "${STATE_PATH}"
367
+ ```
368
+
369
+ ```
370
+ ✓ Planning repo marked complete and pushed.
371
+ ```
372
+
373
+ If mark-milestone-complete fails, log a warning but continue to gather_stats (non-critical for the merge flow).
374
+
375
+ </step>
376
+
172
377
  <step name="gather_stats">
173
378
 
174
379
  Calculate milestone statistics:
@@ -416,41 +621,30 @@ Update `${roadmap_path}` — group completed milestone phases:
416
621
  **Delegate archival to dgs-tools:**
417
622
 
418
623
  ```bash
419
- ARCHIVE=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" milestone complete "v[X.Y]" --name "[Milestone Name]")
624
+ ARCHIVE=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" milestone complete "v[X.Y]" --name "[Milestone Name]" --archive-phases)
420
625
  ```
421
626
 
422
627
  The CLI handles:
423
- - Creating `${project_root}/milestones/` directory
628
+ - Creating `milestones/` directory (planning root)
424
629
  - Archiving ROADMAP.md to `milestones/v[X.Y]-ROADMAP.md`
425
630
  - Archiving REQUIREMENTS.md to `milestones/v[X.Y]-REQUIREMENTS.md` with archive header
426
631
  - Moving audit file to milestones if it exists
427
632
  - Creating/appending MILESTONES.md entry with accomplishments from SUMMARY.md files
428
633
  - Updating STATE.md (status, last activity)
634
+ - Moving milestone phase directories to `milestones/v[X.Y]-phases/` (planning root)
635
+ - Moving completed quick task directories to `milestones/v[X.Y]-quick/` (those with SUMMARY.md)
429
636
 
430
637
  Extract from result: `version`, `date`, `phases`, `plans`, `tasks`, `accomplishments`, `archived`.
431
638
 
432
- Verify: `✅ Milestone archived to ${project_root}/milestones/`
639
+ Verify: `✅ Milestone archived to milestones/`
433
640
 
434
- **If `JOB_MODE` is true:**
435
- - Log: `[AUTO-RESOLVE] Skipping phase archival in job mode`
436
- - Keep phases in place (select "Skip" path automatically)
437
- - Skip the AskUserQuestion below
438
-
439
- **If `JOB_MODE` is false (default):**
641
+ Verify `archived.phases` is `true` in the result. If false, error: "Phase archival failed — check ${phases_dir} and milestones/ directory."
440
642
 
441
- **Phase archival (optional):** After archival completes, ask the user:
643
+ Verify: `✅ Phase directories archived to milestones/v[X.Y]-phases/`
442
644
 
443
- AskUserQuestion(header="Archive Phases", question="Archive phase directories to milestones/?", options: "Yes move to milestones/v[X.Y]-phases/" | "Skip keep phases in place")
444
-
445
- If "Yes": move phase directories to the milestone archive:
446
- ```bash
447
- mkdir -p ${project_root}/milestones/v[X.Y]-phases
448
- # For each phase directory in ${phases_dir}/:
449
- mv ${phases_dir}/{phase-dir} ${project_root}/milestones/v[X.Y]-phases/
450
- ```
451
- Verify: `✅ Phase directories archived to ${project_root}/milestones/v[X.Y]-phases/`
645
+ Verify `archived.quick` is `true` in the result if completed quick tasks existed. If false but quick dirs were expected, warn: "Quick archival returned false -- check projects/{project}/quick/ directory."
452
646
 
453
- If "Skip": Phase directories remain in `${phases_dir}/` as raw execution history. Use `/dgs:cleanup` later to archive retroactively.
647
+ Verify: `completed quick directories archived to milestones/v[X.Y]-quick/`
454
648
 
455
649
  After archival, the AI still handles:
456
650
  - Reorganizing ROADMAP.md with milestone grouping (requires judgment)
@@ -1211,7 +1405,7 @@ git push origin v[X.Y]
1211
1405
  Commit milestone completion.
1212
1406
 
1213
1407
  ```bash
1214
- node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" commit "chore: complete v[X.Y] milestone" --push --files ${project_root}/milestones/v[X.Y]-ROADMAP.md ${project_root}/milestones/v[X.Y]-REQUIREMENTS.md ${project_root}/v[X.Y]-MILESTONE-AUDIT.md ${project_root}/MILESTONES.md ${project_path} ${state_path}
1408
+ node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" commit "chore: complete v[X.Y] milestone" --push --files milestones/v[X.Y]-ROADMAP.md milestones/v[X.Y]-REQUIREMENTS.md milestones/v[X.Y]-MILESTONE-AUDIT.md MILESTONES.md ${project_path} ${state_path}
1215
1409
  ```
1216
1410
  ```
1217
1411
 
@@ -0,0 +1,106 @@
1
+ <purpose>
2
+ Complete the active product-level quick task: rebase onto base_branch, fast-forward merge, push to remote, and clean up the worktree. Uses the shared rebaseAndMerge() flow from worktrees.cjs.
3
+
4
+ This workflow is only valid for product-level quicks. If the user is working in a milestone context, displays a clear error directing them to complete-milestone instead.
5
+ </purpose>
6
+
7
+ <context_tier>none</context_tier>
8
+
9
+ <process>
10
+
11
+ **Step 1: Generate inline review summary**
12
+
13
+ Before rebase-and-merge, generate a review report while the quick branch still exists with original commits.
14
+
15
+ ```bash
16
+ REVIEW_RESULT=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" quick generate-review --raw 2>&1)
17
+ REVIEW_EXIT=$?
18
+ ```
19
+
20
+ **If generation succeeds** (`REVIEW_EXIT` is 0):
21
+
22
+ Parse JSON output for the summary:
23
+ ```bash
24
+ REVIEW_PATH=$(echo "$REVIEW_RESULT" | jq -r '.relativePath // empty')
25
+ REVIEW_COMMITS=$(echo "$REVIEW_RESULT" | jq -r '.stats.commits // 0')
26
+ REVIEW_FILES=$(echo "$REVIEW_RESULT" | jq -r '.stats.filesChanged // 0')
27
+ REVIEW_RISKS=$(echo "$REVIEW_RESULT" | jq -r '.stats.riskFlags // 0')
28
+ ```
29
+
30
+ Display the stats banner:
31
+ ```
32
+ Review: ${REVIEW_PATH} (${REVIEW_COMMITS} commits, ${REVIEW_FILES} files${REVIEW_RISKS > 0 ? ", ${REVIEW_RISKS} risk flags" : ""})
33
+ ```
34
+
35
+ **If fast-forward detected** (output contains `"fastForward": true`):
36
+
37
+ Display: `No code changes detected -- review not generated.`
38
+
39
+ **If generation fails** (`REVIEW_EXIT` is non-zero):
40
+
41
+ Log warning and continue -- do NOT block task completion:
42
+ ```
43
+ Warning: Review generation failed. Continuing with completion.
44
+ ```
45
+
46
+ Review generation failure is non-fatal. The quick task will still complete normally.
47
+
48
+ **Step 2: Validate and execute complete-quick**
49
+
50
+ Call the complete-quick CLI command which validates the active quick and executes the full flow:
51
+
52
+ ```bash
53
+ RESULT=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" complete-quick 2>&1)
54
+ EXIT_CODE=$?
55
+ ```
56
+
57
+ **If exit code is non-zero** (error):
58
+
59
+ Check if error contains "No active product-level quick":
60
+ ```
61
+ ╔══════════════════════════════════════════════════════════════╗
62
+ ║ ERROR ║
63
+ ╚══════════════════════════════════════════════════════════════╝
64
+
65
+ No active product-level quick to complete.
66
+
67
+ If working in a milestone context, changes merge with the milestone.
68
+ Use: /dgs:complete-milestone
69
+
70
+ If you abandoned the quick, the worktree was already removed.
71
+ ```
72
+ End workflow.
73
+
74
+ For other errors (including rebase conflicts), display the error message.
75
+ If the error contains manual resolution instructions, display them verbatim, then:
76
+ ```
77
+ After resolving conflicts manually, re-run:
78
+
79
+ /dgs:complete-quick
80
+ ```
81
+ End workflow.
82
+
83
+ **Step 3: Display success**
84
+
85
+ Parse JSON result from RESULT.
86
+
87
+ ```
88
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
89
+ DGS ► QUICK COMPLETE ✓
90
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
91
+
92
+ Quick '${slug}' merged to main (${commits} commits).
93
+ Worktree cleaned up. Pushed to origin.
94
+ ```
95
+
96
+ </process>
97
+
98
+ <success_criteria>
99
+ - [ ] Review summary generated before rebase-and-merge (or warning logged on failure)
100
+ - [ ] Active product-level quick validated
101
+ - [ ] Rebase-before-merge flow executed via rebaseAndMerge()
102
+ - [ ] Worktree and branch cleaned up
103
+ - [ ] active_context cleared
104
+ - [ ] Success message includes commit count
105
+ - [ ] Conflict case shows manual resolution instructions
106
+ </success_criteria>
@@ -307,7 +307,7 @@ Write multi-line parameters (body, discussion, research) to temporary files usin
307
307
  {
308
308
  "id": 5,
309
309
  "filename": "005-improve-api-resilience.md",
310
- "path": "ideas/pending/005-improve-api-resilience.md",
310
+ "path": "ideas/005-improve-api-resilience.md",
311
311
  "title": "Improve API resilience",
312
312
  "consolidated_from": ["001", "003", "017"],
313
313
  "moved_files": [
@@ -24,7 +24,7 @@ Use `TIER_FILES` JSON `files` array for project context (PROJECT.md, STATE.md, c
24
24
  Parse `$ARGUMENTS` to extract version and flags.
25
25
 
26
26
  - **Version:** First non-flag argument (e.g., `v6`, `v6.0`). If omitted, auto-detection happens in the preview step.
27
- - **--no-check flag:** If present, omit audit-milestone and complete-milestone steps from the generated job.
27
+ - **--no-check flag:** If present, omit the audit-milestone step from the generated job.
28
28
 
29
29
  ```bash
30
30
  # Pseudocode for argument parsing:
@@ -97,7 +97,7 @@ Present in this format:
97
97
  5. execute-phase 52
98
98
  6. verify-work 52
99
99
  ...
100
- N. complete-milestone v6.0
100
+ N. audit-milestone v6.0
101
101
 
102
102
  Create this job? (yes/no)
103
103
  ```
@@ -123,13 +123,13 @@ node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs jobs create-milestone VER
123
123
  2. Commit the job file:
124
124
 
125
125
  ```bash
126
- node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs commit "docs(50): create milestone job {version}" --files jobs/pending/milestone-{version}.md
126
+ node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs commit "docs(50): create milestone job {version}" --files jobs/milestone-{version}.md
127
127
  ```
128
128
 
129
129
  3. Display success and next steps:
130
130
 
131
131
  ```
132
- Job created: jobs/pending/milestone-{version}.md
132
+ Job created: jobs/milestone-{version}.md
133
133
 
134
134
  ---
135
135