@ktpartners/dgs-platform 2.6.2

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 (256) hide show
  1. package/LICENSE +38 -0
  2. package/README.md +851 -0
  3. package/agents/dgs-codebase-cross-analyzer.md +183 -0
  4. package/agents/dgs-codebase-mapper.md +782 -0
  5. package/agents/dgs-codebase-synthesizer.md +156 -0
  6. package/agents/dgs-debugger.md +1256 -0
  7. package/agents/dgs-executor.md +550 -0
  8. package/agents/dgs-integration-checker.md +481 -0
  9. package/agents/dgs-nyquist-auditor.md +178 -0
  10. package/agents/dgs-phase-researcher.md +563 -0
  11. package/agents/dgs-phase-verifier.md +450 -0
  12. package/agents/dgs-plan-checker.md +708 -0
  13. package/agents/dgs-planner.md +1324 -0
  14. package/agents/dgs-project-researcher.md +631 -0
  15. package/agents/dgs-research-synthesizer.md +249 -0
  16. package/agents/dgs-roadmapper.md +652 -0
  17. package/agents/dgs-verifier.md +607 -0
  18. package/bin/install.js +2073 -0
  19. package/commands/dgs/add-doc.md +45 -0
  20. package/commands/dgs/add-idea.md +38 -0
  21. package/commands/dgs/add-phase.md +43 -0
  22. package/commands/dgs/add-repo.md +54 -0
  23. package/commands/dgs/add-tests.md +41 -0
  24. package/commands/dgs/add-todo.md +47 -0
  25. package/commands/dgs/approve-spec.md +38 -0
  26. package/commands/dgs/audit-milestone.md +36 -0
  27. package/commands/dgs/audit-phase.md +37 -0
  28. package/commands/dgs/cancel-job.md +23 -0
  29. package/commands/dgs/capture-principle.md +143 -0
  30. package/commands/dgs/check-todos.md +45 -0
  31. package/commands/dgs/cleanup.md +18 -0
  32. package/commands/dgs/complete-milestone.md +136 -0
  33. package/commands/dgs/complete-project.md +70 -0
  34. package/commands/dgs/consolidate-ideas.md +50 -0
  35. package/commands/dgs/create-milestone-job.md +37 -0
  36. package/commands/dgs/debug.md +164 -0
  37. package/commands/dgs/develop-idea.md +53 -0
  38. package/commands/dgs/discuss-idea.md +41 -0
  39. package/commands/dgs/discuss-phase.md +83 -0
  40. package/commands/dgs/execute-phase.md +41 -0
  41. package/commands/dgs/fast.md +38 -0
  42. package/commands/dgs/find-related-ideas.md +43 -0
  43. package/commands/dgs/health.md +28 -0
  44. package/commands/dgs/help.md +22 -0
  45. package/commands/dgs/import-spec.md +36 -0
  46. package/commands/dgs/init-product.md +28 -0
  47. package/commands/dgs/insert-phase.md +32 -0
  48. package/commands/dgs/join-discord.md +18 -0
  49. package/commands/dgs/list-docs.md +40 -0
  50. package/commands/dgs/list-ideas.md +42 -0
  51. package/commands/dgs/list-jobs.md +22 -0
  52. package/commands/dgs/list-phase-assumptions.md +46 -0
  53. package/commands/dgs/list-projects.md +57 -0
  54. package/commands/dgs/list-specs.md +40 -0
  55. package/commands/dgs/map-codebase.md +92 -0
  56. package/commands/dgs/new-milestone.md +44 -0
  57. package/commands/dgs/new-project.md +42 -0
  58. package/commands/dgs/node-repair.md +26 -0
  59. package/commands/dgs/overlap-check.md +20 -0
  60. package/commands/dgs/pause-work.md +38 -0
  61. package/commands/dgs/plan-milestone-gaps.md +34 -0
  62. package/commands/dgs/plan-phase.md +44 -0
  63. package/commands/dgs/progress.md +24 -0
  64. package/commands/dgs/quick.md +41 -0
  65. package/commands/dgs/reactivate-project.md +70 -0
  66. package/commands/dgs/reapply-patches.md +110 -0
  67. package/commands/dgs/refine-spec.md +38 -0
  68. package/commands/dgs/reject-idea.md +43 -0
  69. package/commands/dgs/remove-doc.md +44 -0
  70. package/commands/dgs/remove-phase.md +31 -0
  71. package/commands/dgs/remove-repo.md +69 -0
  72. package/commands/dgs/research-idea.md +43 -0
  73. package/commands/dgs/research-phase.md +189 -0
  74. package/commands/dgs/restore-idea.md +45 -0
  75. package/commands/dgs/resume-work.md +40 -0
  76. package/commands/dgs/rollback-job.md +24 -0
  77. package/commands/dgs/run-job.md +35 -0
  78. package/commands/dgs/search.md +40 -0
  79. package/commands/dgs/set-profile.md +34 -0
  80. package/commands/dgs/settings.md +38 -0
  81. package/commands/dgs/switch-project.md +58 -0
  82. package/commands/dgs/undo-consolidation.md +42 -0
  83. package/commands/dgs/update-idea.md +44 -0
  84. package/commands/dgs/update.md +37 -0
  85. package/commands/dgs/validate-phase.md +35 -0
  86. package/commands/dgs/verify-work.md +39 -0
  87. package/commands/dgs/write-spec.md +49 -0
  88. package/deliver-great-systems/.planning/phases/09-backend-wiring-and-error-handling/09-01-SUMMARY.md +84 -0
  89. package/deliver-great-systems/.planning/phases/09-backend-wiring-and-error-handling/09-02-SUMMARY.md +86 -0
  90. package/deliver-great-systems/.planning/phases/10-v1-to-v2-migration-flow/10-01-SUMMARY.md +85 -0
  91. package/deliver-great-systems/bin/dgs-tools.cjs +1444 -0
  92. package/deliver-great-systems/bin/lib/auto-test.cjs +1365 -0
  93. package/deliver-great-systems/bin/lib/commands.cjs +570 -0
  94. package/deliver-great-systems/bin/lib/config.cjs +417 -0
  95. package/deliver-great-systems/bin/lib/conflict-agent.cjs +1063 -0
  96. package/deliver-great-systems/bin/lib/conflict-agent.test.cjs +554 -0
  97. package/deliver-great-systems/bin/lib/context.cjs +929 -0
  98. package/deliver-great-systems/bin/lib/context.test.cjs +693 -0
  99. package/deliver-great-systems/bin/lib/core.cjs +744 -0
  100. package/deliver-great-systems/bin/lib/core.test.cjs +822 -0
  101. package/deliver-great-systems/bin/lib/docs.cjs +919 -0
  102. package/deliver-great-systems/bin/lib/docs.test.cjs +211 -0
  103. package/deliver-great-systems/bin/lib/execution.cjs +705 -0
  104. package/deliver-great-systems/bin/lib/execution.test.cjs +1472 -0
  105. package/deliver-great-systems/bin/lib/frontmatter.cjs +324 -0
  106. package/deliver-great-systems/bin/lib/ideas.cjs +1406 -0
  107. package/deliver-great-systems/bin/lib/ideas.test.cjs +1417 -0
  108. package/deliver-great-systems/bin/lib/identity.cjs +125 -0
  109. package/deliver-great-systems/bin/lib/init.cjs +1114 -0
  110. package/deliver-great-systems/bin/lib/init.test.cjs +1271 -0
  111. package/deliver-great-systems/bin/lib/jobs.cjs +2015 -0
  112. package/deliver-great-systems/bin/lib/jobs.test.cjs +2619 -0
  113. package/deliver-great-systems/bin/lib/merge-conflicts.cjs +654 -0
  114. package/deliver-great-systems/bin/lib/merge-conflicts.test.cjs +370 -0
  115. package/deliver-great-systems/bin/lib/migration.cjs +352 -0
  116. package/deliver-great-systems/bin/lib/migration.test.cjs +582 -0
  117. package/deliver-great-systems/bin/lib/milestone.cjs +243 -0
  118. package/deliver-great-systems/bin/lib/overlap.cjs +437 -0
  119. package/deliver-great-systems/bin/lib/overlap.test.cjs +747 -0
  120. package/deliver-great-systems/bin/lib/path-audit.test.cjs +384 -0
  121. package/deliver-great-systems/bin/lib/paths.cjs +144 -0
  122. package/deliver-great-systems/bin/lib/paths.test.cjs +486 -0
  123. package/deliver-great-systems/bin/lib/phase.cjs +910 -0
  124. package/deliver-great-systems/bin/lib/projects.cjs +691 -0
  125. package/deliver-great-systems/bin/lib/projects.test.cjs +871 -0
  126. package/deliver-great-systems/bin/lib/repos.cjs +1432 -0
  127. package/deliver-great-systems/bin/lib/repos.test.cjs +1882 -0
  128. package/deliver-great-systems/bin/lib/roadmap.cjs +305 -0
  129. package/deliver-great-systems/bin/lib/search.cjs +570 -0
  130. package/deliver-great-systems/bin/lib/specs.cjs +1303 -0
  131. package/deliver-great-systems/bin/lib/state.cjs +893 -0
  132. package/deliver-great-systems/bin/lib/template.cjs +228 -0
  133. package/deliver-great-systems/bin/lib/test-helpers.cjs +291 -0
  134. package/deliver-great-systems/bin/lib/verify.cjs +796 -0
  135. package/deliver-great-systems/references/checkpoints.md +776 -0
  136. package/deliver-great-systems/references/conflict-resolution.md +66 -0
  137. package/deliver-great-systems/references/context-tiers.md +166 -0
  138. package/deliver-great-systems/references/continuation-format.md +249 -0
  139. package/deliver-great-systems/references/decimal-phase-calculation.md +67 -0
  140. package/deliver-great-systems/references/git-integration.md +250 -0
  141. package/deliver-great-systems/references/git-planning-commit.md +40 -0
  142. package/deliver-great-systems/references/model-profile-resolution.md +36 -0
  143. package/deliver-great-systems/references/model-profiles.md +95 -0
  144. package/deliver-great-systems/references/phase-argument-parsing.md +61 -0
  145. package/deliver-great-systems/references/planning-config.md +224 -0
  146. package/deliver-great-systems/references/questioning.md +162 -0
  147. package/deliver-great-systems/references/spec-review-loop.md +177 -0
  148. package/deliver-great-systems/references/tdd.md +265 -0
  149. package/deliver-great-systems/references/ui-brand.md +160 -0
  150. package/deliver-great-systems/references/verification-patterns.md +612 -0
  151. package/deliver-great-systems/templates/DEBUG.md +166 -0
  152. package/deliver-great-systems/templates/UAT.md +251 -0
  153. package/deliver-great-systems/templates/VALIDATION.md +95 -0
  154. package/deliver-great-systems/templates/claude-md.md +74 -0
  155. package/deliver-great-systems/templates/codebase/architecture.md +257 -0
  156. package/deliver-great-systems/templates/codebase/concerns.md +312 -0
  157. package/deliver-great-systems/templates/codebase/conventions.md +309 -0
  158. package/deliver-great-systems/templates/codebase/integrations.md +282 -0
  159. package/deliver-great-systems/templates/codebase/stack.md +188 -0
  160. package/deliver-great-systems/templates/codebase/structure.md +287 -0
  161. package/deliver-great-systems/templates/codebase/testing.md +482 -0
  162. package/deliver-great-systems/templates/config.json +38 -0
  163. package/deliver-great-systems/templates/context.md +354 -0
  164. package/deliver-great-systems/templates/continue-here.md +80 -0
  165. package/deliver-great-systems/templates/debug-subagent-prompt.md +93 -0
  166. package/deliver-great-systems/templates/discovery.md +148 -0
  167. package/deliver-great-systems/templates/milestone-archive.md +125 -0
  168. package/deliver-great-systems/templates/milestone.md +117 -0
  169. package/deliver-great-systems/templates/phase-prompt.md +615 -0
  170. package/deliver-great-systems/templates/planner-subagent-prompt.md +119 -0
  171. package/deliver-great-systems/templates/project.md +186 -0
  172. package/deliver-great-systems/templates/requirements.md +233 -0
  173. package/deliver-great-systems/templates/research-project/ARCHITECTURE.md +206 -0
  174. package/deliver-great-systems/templates/research-project/FEATURES.md +149 -0
  175. package/deliver-great-systems/templates/research-project/PITFALLS.md +202 -0
  176. package/deliver-great-systems/templates/research-project/STACK.md +122 -0
  177. package/deliver-great-systems/templates/research-project/SUMMARY.md +172 -0
  178. package/deliver-great-systems/templates/research.md +554 -0
  179. package/deliver-great-systems/templates/retrospective.md +54 -0
  180. package/deliver-great-systems/templates/roadmap.md +204 -0
  181. package/deliver-great-systems/templates/state.md +178 -0
  182. package/deliver-great-systems/templates/summary-complex.md +59 -0
  183. package/deliver-great-systems/templates/summary-minimal.md +41 -0
  184. package/deliver-great-systems/templates/summary-standard.md +48 -0
  185. package/deliver-great-systems/templates/summary.md +253 -0
  186. package/deliver-great-systems/templates/user-setup.md +313 -0
  187. package/deliver-great-systems/templates/verification-report.md +324 -0
  188. package/deliver-great-systems/workflows/add-doc.md +151 -0
  189. package/deliver-great-systems/workflows/add-idea.md +96 -0
  190. package/deliver-great-systems/workflows/add-phase.md +120 -0
  191. package/deliver-great-systems/workflows/add-tests.md +359 -0
  192. package/deliver-great-systems/workflows/add-todo.md +162 -0
  193. package/deliver-great-systems/workflows/approve-spec.md +194 -0
  194. package/deliver-great-systems/workflows/audit-milestone.md +364 -0
  195. package/deliver-great-systems/workflows/audit-phase.md +462 -0
  196. package/deliver-great-systems/workflows/cancel-job.md +108 -0
  197. package/deliver-great-systems/workflows/check-todos.md +181 -0
  198. package/deliver-great-systems/workflows/cleanup.md +247 -0
  199. package/deliver-great-systems/workflows/codereview.md +526 -0
  200. package/deliver-great-systems/workflows/complete-milestone.md +1298 -0
  201. package/deliver-great-systems/workflows/consolidate-ideas.md +365 -0
  202. package/deliver-great-systems/workflows/create-milestone-job.md +177 -0
  203. package/deliver-great-systems/workflows/develop-idea.md +544 -0
  204. package/deliver-great-systems/workflows/diagnose-issues.md +231 -0
  205. package/deliver-great-systems/workflows/discovery-phase.md +301 -0
  206. package/deliver-great-systems/workflows/discuss-idea.md +263 -0
  207. package/deliver-great-systems/workflows/discuss-phase.md +733 -0
  208. package/deliver-great-systems/workflows/execute-phase.md +571 -0
  209. package/deliver-great-systems/workflows/execute-plan.md +592 -0
  210. package/deliver-great-systems/workflows/find-related-ideas.md +271 -0
  211. package/deliver-great-systems/workflows/health.md +173 -0
  212. package/deliver-great-systems/workflows/help.md +997 -0
  213. package/deliver-great-systems/workflows/import-spec.md +381 -0
  214. package/deliver-great-systems/workflows/init-product.md +767 -0
  215. package/deliver-great-systems/workflows/insert-phase.md +138 -0
  216. package/deliver-great-systems/workflows/list-docs.md +119 -0
  217. package/deliver-great-systems/workflows/list-ideas.md +154 -0
  218. package/deliver-great-systems/workflows/list-jobs.md +89 -0
  219. package/deliver-great-systems/workflows/list-phase-assumptions.md +192 -0
  220. package/deliver-great-systems/workflows/list-specs.md +101 -0
  221. package/deliver-great-systems/workflows/map-codebase.md +621 -0
  222. package/deliver-great-systems/workflows/new-milestone.md +591 -0
  223. package/deliver-great-systems/workflows/new-project.md +1113 -0
  224. package/deliver-great-systems/workflows/node-repair.md +94 -0
  225. package/deliver-great-systems/workflows/overlap-check.md +86 -0
  226. package/deliver-great-systems/workflows/pause-work.md +134 -0
  227. package/deliver-great-systems/workflows/plan-milestone-gaps.md +306 -0
  228. package/deliver-great-systems/workflows/plan-phase.md +698 -0
  229. package/deliver-great-systems/workflows/progress.md +386 -0
  230. package/deliver-great-systems/workflows/quick.md +845 -0
  231. package/deliver-great-systems/workflows/refine-spec.md +275 -0
  232. package/deliver-great-systems/workflows/reject-idea.md +109 -0
  233. package/deliver-great-systems/workflows/remove-doc.md +117 -0
  234. package/deliver-great-systems/workflows/remove-phase.md +163 -0
  235. package/deliver-great-systems/workflows/research-idea.md +325 -0
  236. package/deliver-great-systems/workflows/research-phase.md +81 -0
  237. package/deliver-great-systems/workflows/restore-idea.md +101 -0
  238. package/deliver-great-systems/workflows/resume-project.md +311 -0
  239. package/deliver-great-systems/workflows/rollback-job.md +130 -0
  240. package/deliver-great-systems/workflows/run-job.md +498 -0
  241. package/deliver-great-systems/workflows/search.md +130 -0
  242. package/deliver-great-systems/workflows/set-profile.md +83 -0
  243. package/deliver-great-systems/workflows/settings.md +470 -0
  244. package/deliver-great-systems/workflows/transition.md +563 -0
  245. package/deliver-great-systems/workflows/undo-consolidation.md +155 -0
  246. package/deliver-great-systems/workflows/update-idea.md +157 -0
  247. package/deliver-great-systems/workflows/update.md +242 -0
  248. package/deliver-great-systems/workflows/validate-phase.md +177 -0
  249. package/deliver-great-systems/workflows/verify-phase.md +253 -0
  250. package/deliver-great-systems/workflows/verify-work.md +671 -0
  251. package/deliver-great-systems/workflows/write-spec.md +450 -0
  252. package/hooks/dist/dgs-check-update.js +62 -0
  253. package/hooks/dist/dgs-context-monitor.js +141 -0
  254. package/hooks/dist/dgs-statusline.js +115 -0
  255. package/package.json +60 -0
  256. package/scripts/build-hooks.js +43 -0
@@ -0,0 +1,462 @@
1
+ <purpose>
2
+ Audit a completed phase through automated test execution and structural verification. Produces a phase-level audit report that confirms deliverables exist, are wired correctly, and pass their test suite. Mirrors the audit-milestone pattern but scoped to a single phase.
3
+
4
+ verify-work = manual UAT (human tests interactively)
5
+ audit-phase = automated inspection (tests + structural verification)
6
+ audit-milestone = cross-phase integration audit (milestone level)
7
+ </purpose>
8
+
9
+ <context_tier>execution</context_tier>
10
+
11
+ <philosophy>
12
+ **Trust the code, not the SUMMARY.**
13
+
14
+ A completed task is not a verified deliverable. Code can be written without being wired in. An API route can exist without being called. A component can render without importing its data source. Audit-phase verifies the connections, not just the existence.
15
+
16
+ Two independent verification layers:
17
+ 1. **Test execution** — run the actual test suite and task-level verify commands
18
+ 2. **Structural inspection** — cross-reference PLAN.md with what's on disk (files, exports, wiring)
19
+
20
+ Both must pass for a phase to be considered clean.
21
+ </philosophy>
22
+
23
+ <process>
24
+
25
+ <step name="initialize" priority="first">
26
+ Parse arguments and load phase context:
27
+
28
+ ```bash
29
+ INIT=$(node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs init audit-phase "${PHASE_ARG}")
30
+ ```
31
+
32
+ Parse JSON for: `planner_model`, `checker_model`, `commit_docs`, `phase_found`, `phase_dir`, `phase_number`, `phase_name`, `has_verification`, `dgs_mode`, `author`.
33
+
34
+ **Load execution tier context:**
35
+
36
+ ```bash
37
+ TIER_FILES=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" context load-tier execution --phase "${PHASE_ARG}" --raw 2>/dev/null)
38
+ ```
39
+
40
+ **Flag Detection:**
41
+
42
+ 1. Check if `$ARGUMENTS` contains `--rerun-failed`. If yes, set `RERUN_FAILED_MODE = true` and strip from `$ARGUMENTS`.
43
+
44
+ **v2 Multi-Repo Detection:**
45
+
46
+ If `dgs_mode` is `v2`, load repo context:
47
+
48
+ ```bash
49
+ REPOS_MD=$(node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs repos list --raw 2>/dev/null)
50
+ ```
51
+
52
+ Parse JSON for the list of registered repos with paths.
53
+
54
+ **Resolve test execution directory (v2 only):**
55
+
56
+ If `dgs_mode` is `v2` and repos were detected from REPOS_MD:
57
+
58
+ 1. Parse REPOS_MD JSON for the list of repos (each has `name` and `path`)
59
+ 2. If exactly 1 repo registered: use its `path` as `TEST_CWD`
60
+ 3. If multiple repos: check PLAN.md files in the phase for `<repos>` tags. Use the first repo name found, look up its path from REPOS_MD. If no `<repos>` tag found, use the first registered repo's path.
61
+ 4. Resolve `TEST_CWD` to an absolute path: if the repo path is relative (starts with `../`), resolve it relative to `process.cwd()` / the current working directory.
62
+ 5. Set `CWD_FLAG` to `--cwd "${TEST_CWD}"` if TEST_CWD was determined, otherwise set to empty string.
63
+
64
+ If `dgs_mode` is NOT `v2` or no repos detected: set `CWD_FLAG` to empty string (single-repo, no override needed).
65
+
66
+ ```
67
+ {If CWD_FLAG is set:}
68
+ Test execution directory: ${TEST_CWD} (from REPOS.md)
69
+ ```
70
+ </step>
71
+
72
+ <step name="run_tests">
73
+ **Layer 1: Test Execution**
74
+
75
+ Collect and run automated test commands for this phase.
76
+
77
+ ```bash
78
+ COLLECT=$(node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs auto-test collect "${PHASE_ARG}" ${CWD_FLAG} --raw 2>/dev/null)
79
+ ```
80
+
81
+ Parse JSON result. If `empty` is true: note "No automated tests available" and proceed to structural verification (tests are not required — structural verification still runs).
82
+
83
+ Otherwise, display collected commands:
84
+
85
+ ```
86
+ ## Audit Phase {N}: Test Execution
87
+
88
+ ### Collected Commands
89
+ {grouped by source: VALIDATION.md / PLAN.md}
90
+ ---
91
+ Collected {total} test commands ({from_validation} from VALIDATION.md, {from_plans} from PLAN.md)
92
+ ```
93
+
94
+ Execute the test suite:
95
+
96
+ ```bash
97
+ RUN_RESULT=$(node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs auto-test run "${PHASE_ARG}" --timeout 30000 ${CWD_FLAG} --raw 2>/dev/null)
98
+ ```
99
+
100
+ Parse and display results:
101
+
102
+ ```
103
+ ## Test Results: Phase {N}
104
+
105
+ | # | Command | Result | Duration | Type |
106
+ |---|---------|--------|----------|------|
107
+ | 1 | npm test | PASS | 2.3s | - |
108
+ | 2 | node --test tests/foo.test.cjs | FAIL | 0.8s | code |
109
+
110
+ ---
111
+ **Summary:** {passed}/{total} passed, {failed} failed, {timed_out} timed out, {suspects} suspect, {skipped_covered} skipped (covered)
112
+ ```
113
+
114
+ Generate the UAT file for test results:
115
+
116
+ ```bash
117
+ MAP_RESULT=$(node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs auto-test map "${PHASE_ARG}" --timeout 30000 ${CWD_FLAG} --raw 2>/dev/null)
118
+ ```
119
+
120
+ Parse for: `uat_path`, `log_path`, `summary`, `manual_count`, `status`.
121
+
122
+ **RERUN_FAILED_MODE:**
123
+
124
+ If `RERUN_FAILED_MODE` is true, instead of running the full suite:
125
+
126
+ ```bash
127
+ RERUN_RESULT=$(node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs auto-test rerun "${PHASE_ARG}" ${CWD_FLAG} --raw 2>/dev/null)
128
+ ```
129
+
130
+ Parse for: `rerun_count`, `all_passed`, `status`, `uat_path`, `log_path`, `summary`.
131
+
132
+ If `rerun_count` is 0: note "No failed tests to rerun" and proceed to structural verification.
133
+
134
+ Display rerun results, then proceed to structural verification as normal.
135
+ </step>
136
+
137
+ <step name="structural_verification">
138
+ **Layer 2: Structural Verification (Phase Verifier)**
139
+
140
+ After test execution (or if no tests were available), spawn the dgs-phase-verifier agent to inspect the actual deliverables against the plan.
141
+
142
+ Build prior phase context:
143
+
144
+ ```bash
145
+ # Collect prior phase summaries for upstream dependency checking
146
+ PRIOR_SUMMARIES=$(find "${phase_dir}/../" -name "*-SUMMARY.md" -not -path "*/${phase_number}-*" 2>/dev/null | sort)
147
+ ```
148
+
149
+ Spawn the structural verifier:
150
+
151
+ ```
152
+ Task(
153
+ prompt="""
154
+ <structural_verification>
155
+
156
+ **Phase:** {phase_number} — {phase_name}
157
+ **Phase directory:** {phase_dir}
158
+
159
+ <files_to_read>
160
+ {For each PLAN.md in phase_dir:}
161
+ - {phase_dir}/{plan_file}
162
+ {For each SUMMARY.md in phase_dir:}
163
+ - {phase_dir}/{summary_file}
164
+ {For each prior phase SUMMARY.md (max 5 most recent):}
165
+ - {prior_summary_path}
166
+ </files_to_read>
167
+
168
+ {If dgs_mode is v2 and repos detected:}
169
+ <repo_context>
170
+ Repo Paths (from REPOS.md):
171
+ {For each repo:}
172
+ name: {repo_name}, path: {repo_path}
173
+ </repo_context>
174
+ {End if}
175
+
176
+ Verify that Phase {phase_number}'s deliverables:
177
+ 1. All planned files exist and have substance (not stubs)
178
+ 2. Expected exports are present in the actual files
179
+ 3. must_have artifacts and key_links are satisfied
180
+ 4. Upstream dependencies from prior phases are actually wired in the code
181
+ 5. No critical anti-patterns (TODOs, empty catch blocks, stubs)
182
+
183
+ Return your structured verification report.
184
+
185
+ </structural_verification>
186
+ """,
187
+ subagent_type="dgs-phase-verifier",
188
+ model="{checker_model}",
189
+ description="Structural verify Phase {phase_number}"
190
+ )
191
+ ```
192
+
193
+ Parse the structural verification result. The verifier returns a structured report with a `gaps:` YAML section.
194
+ </step>
195
+
196
+ <step name="merge_results">
197
+ **Merge structural gaps into the UAT file:**
198
+
199
+ Parse the structural verifier's response. The verifier returns a structured report with a `gaps:` YAML section and optionally an `anti_patterns:` YAML section.
200
+
201
+ **Gap Type Mapping (verifier output to UAT entry):**
202
+
203
+ | Verifier gap.type | UAT truth | gap_type |
204
+ |-------------------|-----------|----------|
205
+ | missing_file | "File {planned} exists" | structural |
206
+ | missing_export | "File {file} exports {export}" | structural |
207
+ | unwired_dependency | "{dependency} wired in {expected_in}" | structural |
208
+ | stub_file | "File {file} has substance (not stub)" | structural |
209
+ | broken_key_link | "{from} connected to {to}" | structural |
210
+ | missing_must_have_artifact | "must_have artifact {artifact} satisfied" | structural |
211
+
212
+ For each structural gap (severity >= major) returned by the verifier:
213
+
214
+ 1. Create a new test entry in the UAT file's ## Tests section:
215
+ ```
216
+ ### {next_test_number}. [STRUCTURAL] {gap description derived from type mapping above}
217
+ expected: {truth from mapping table}
218
+ result: issue
219
+ reported: "{detail from verifier}"
220
+ severity: {severity from verifier}
221
+ source: structural_verification
222
+ ```
223
+
224
+ 2. Append to the ## Gaps section in UAT YAML format:
225
+ ```yaml
226
+ - truth: "{truth from mapping table}"
227
+ status: failed
228
+ reason: "Structural verification: {detail}"
229
+ severity: {severity}
230
+ test: {test_number}
231
+ gap_type: structural
232
+ artifacts: []
233
+ missing: []
234
+ ```
235
+
236
+ Each gap entry MUST include all fields required by the diagnosis pipeline: `truth`, `status`, `reason`, `severity`, `test`, `gap_type`, `artifacts`, `missing`.
237
+
238
+ **Anti-pattern handling:**
239
+
240
+ Anti-patterns (severity: minor) from the verifier are:
241
+ - Recorded as test entries (`### N. [STRUCTURAL] ...`) with severity: minor and source: structural_verification
242
+ - Included in the `total` count in the ## Summary section
243
+ - NOT included in the `issues` count (since they do not trigger diagnosis)
244
+ - NOT added to the ## Gaps section
245
+ - They do not affect status determination
246
+
247
+ **Count update logic (after appending structural entries):**
248
+
249
+ ```
250
+ 1. Read current total from ## Summary section
251
+ 2. structural_gap_count = number of gaps with severity >= major (blocker + major)
252
+ 3. anti_pattern_count = number of anti-patterns (severity: minor)
253
+ 4. Add (structural_gap_count + anti_pattern_count) to total
254
+ 5. Add structural_gap_count to issues (anti-patterns excluded)
255
+ 6. If issues > 0: set frontmatter status to 'gaps_found'
256
+ 7. If issues == 0: keep frontmatter status as-is (passed or passed with human_needed)
257
+ ```
258
+
259
+ **Compute combined status:**
260
+
261
+ ```
262
+ test_failures = (test execution failure count, 0 if no tests available)
263
+ structural_gaps = (structural verification gap count, excluding minor anti-patterns)
264
+ total_gaps = test_failures + structural_gaps
265
+
266
+ If total_gaps == 0 and manual_count == 0:
267
+ status = 'passed'
268
+ Else if total_gaps == 0 and manual_count > 0:
269
+ status = 'passed' (with human_needed flag)
270
+ Else:
271
+ status = 'gaps_found'
272
+ ```
273
+
274
+ **Structural re-check in RERUN_FAILED_MODE:**
275
+
276
+ When `RERUN_FAILED_MODE` is true, the structural verifier also reruns, but only checks the specific gaps that were previously identified (not a full re-scan). Pass the previous structural gap list to the verifier so it can re-check only those items. Include the previous UAT file path in the verifier spawn prompt so it can extract the structural gap entries and verify whether they are now resolved.
277
+
278
+ **Commit the UAT file:**
279
+
280
+ ```bash
281
+ node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs commit "[AUDIT] audit(${PHASE_ARG}): ${test_failures} test failures, ${structural_gaps} structural gaps" --files "${uat_path}" "${log_path}"
282
+ ```
283
+ </step>
284
+
285
+ <step name="diagnose_gaps">
286
+ **If gaps found, diagnose and plan fixes:**
287
+
288
+ This mirrors the verify-work diagnosis pipeline. When `status == 'gaps_found'`, proceed through the same diagnosis flow:
289
+
290
+ ```
291
+ ---
292
+ **{total_gaps} gap(s) found** ({test_failures} test failures, {structural_gaps} structural gaps). Initiating automatic diagnosis...
293
+ ```
294
+
295
+ **Step A: Diagnose Issues**
296
+
297
+ - Load diagnose-issues workflow
298
+ - Follow @~/.claude/deliver-great-systems/workflows/diagnose-issues.md
299
+ - Spawn parallel debug agents for each gap
300
+ - Debug agents receive enriched context: test failures get stderr/exit codes, structural gaps get the verifier's specific findings (missing files, unwired dependencies, broken key_links)
301
+ - Collect root causes
302
+ - Update UAT.md with root causes
303
+
304
+ **Step B: Plan Gap Closure**
305
+
306
+ Spawn dgs-planner in --gaps mode:
307
+
308
+ ```
309
+ Task(
310
+ prompt="""
311
+ <planning_context>
312
+
313
+ **Phase:** {phase_number}
314
+ **Mode:** gap_closure
315
+
316
+ <files_to_read>
317
+ - {phase_dir}/{phase_num}-UAT.md (UAT with diagnoses)
318
+ - ${state_path} (Project State)
319
+ - ${roadmap_path} (Roadmap)
320
+ </files_to_read>
321
+
322
+ </planning_context>
323
+
324
+ <repo_context>
325
+ <!-- v2 only: include if dgs_mode is v2 and repos were detected -->
326
+ **Repos touched by this phase:**
327
+ | Repo | Path | Stack |
328
+ |------|------|-------|
329
+ | {repo} | {path} | {detected stack} |
330
+ </repo_context>
331
+
332
+ <downstream_consumer>
333
+ Output consumed by /dgs:execute-phase
334
+ Plans must be executable prompts.
335
+ </downstream_consumer>
336
+ """,
337
+ subagent_type="dgs-planner",
338
+ model="{planner_model}",
339
+ description="Plan gap fixes for Phase {phase}"
340
+ )
341
+ ```
342
+
343
+ **Step C: Verify Gap Plans**
344
+
345
+ Spawn dgs-plan-checker:
346
+
347
+ ```
348
+ Task(
349
+ prompt="""
350
+ <verification_context>
351
+
352
+ **Phase:** {phase_number}
353
+ **Phase Goal:** Close diagnosed gaps from phase audit
354
+
355
+ <files_to_read>
356
+ - {phase_dir}/*-PLAN.md (Plans to verify)
357
+ </files_to_read>
358
+
359
+ </verification_context>
360
+
361
+ <expected_output>
362
+ Return one of:
363
+ - ## VERIFICATION PASSED — all checks pass
364
+ - ## ISSUES FOUND — structured issue list
365
+ </expected_output>
366
+ """,
367
+ subagent_type="dgs-plan-checker",
368
+ model="{checker_model}",
369
+ description="Verify Phase {phase} fix plans"
370
+ )
371
+ ```
372
+
373
+ **Step D: Revision Loop**
374
+
375
+ Iterate planner <-> checker until plans pass (max 3 iterations). Same logic as verify-work's revision_loop step.
376
+
377
+ After plans are verified, update UAT status to `diagnosed` and proceed to present_results.
378
+ </step>
379
+
380
+ <step name="present_results">
381
+ **Present audit results and next steps:**
382
+
383
+ ```
384
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
385
+ DGS ► PHASE AUDIT COMPLETE
386
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
387
+
388
+ ## Audit Results: Phase {N} — {Name}
389
+
390
+ | Metric | Count |
391
+ |--------|-------|
392
+ | Tests Passed | {passed} |
393
+ | Tests Failed | {test_failures} |
394
+ | Structural Gaps | {structural_gaps} |
395
+ | Human Needed | {manual_count} |
396
+
397
+ Status: {status}
398
+ UAT file: {uat_path}
399
+ ```
400
+
401
+ **Branch based on status:**
402
+
403
+ {If status == 'passed' and manual_count == 0:}
404
+ ```
405
+ ---
406
+ Phase {N} audit passed. All tests pass. Structural verification clean. Ready for next phase.
407
+ ```
408
+ Stop here.
409
+
410
+ {If status == 'passed' and manual_count > 0:}
411
+ ```
412
+ ---
413
+ Phase {N} audit passed. **{manual_count} verification(s) require human review.**
414
+ Run `/dgs:verify-work {phase}` interactively to complete manual checks.
415
+ ```
416
+ Stop here.
417
+
418
+ {If status == 'gaps_found' and diagnosis completed:}
419
+ ```
420
+ ---
421
+ **{total_gaps} gap(s) diagnosed, {M} fix plan(s) created.**
422
+
423
+ | Gap | Root Cause | Fix Plan |
424
+ |-----|------------|----------|
425
+ | {truth 1} | {root_cause} | {phase}-04 |
426
+ | {truth 2} | {root_cause} | {phase}-04 |
427
+
428
+ Status: diagnosed — fix plans ready for execution.
429
+ ```
430
+
431
+ In a job context, the job orchestrator reads the `diagnosed` status and dynamically inserts `execute-phase --gaps-only` and `audit-phase --rerun-failed` steps. In interactive mode:
432
+
433
+ ```
434
+ ## ▶ Next Up
435
+
436
+ **Execute fixes** — run fix plans
437
+
438
+ `/clear` then `/dgs:execute-phase {phase} --gaps-only`
439
+ Then re-audit: `/dgs:audit-phase {phase} --rerun-failed`
440
+ ```
441
+
442
+ Stop here.
443
+ </step>
444
+
445
+ </process>
446
+
447
+ <success_criteria>
448
+ - [ ] Phase context loaded (init, phase_dir, mode)
449
+ - [ ] Test commands collected from VALIDATION.md and PLAN.md sources
450
+ - [ ] Tests executed with results captured (pass/fail/timeout)
451
+ - [ ] Test results mapped to UAT file format
452
+ - [ ] Structural verifier spawned after test execution
453
+ - [ ] Structural gaps merged into UAT file alongside test results
454
+ - [ ] Combined status reflects both test failures AND structural gaps
455
+ - [ ] If gaps found: parallel debug agents diagnose root causes
456
+ - [ ] If gaps found: dgs-planner creates fix plans (gap_closure mode)
457
+ - [ ] If gaps found: dgs-plan-checker verifies fix plans
458
+ - [ ] If gaps found: revision loop until plans pass (max 3 iterations)
459
+ - [ ] UAT file committed with audit results
460
+ - [ ] Clear status signal for job orchestrator (passed / diagnosed)
461
+ - [ ] If --rerun-failed: only re-runs previously failed tests + structural re-check
462
+ </success_criteria>
@@ -0,0 +1,108 @@
1
+ <purpose>
2
+ Cancel an in-progress job, resetting it to pending for re-execution. After cancellation, generates a job summary documenting the partial progress.
3
+ </purpose>
4
+
5
+ <context_tier>lite</context_tier>
6
+
7
+ <required_reading>
8
+ Read all files referenced by the invoking prompt's execution_context before starting.
9
+ </required_reading>
10
+
11
+ <process>
12
+
13
+ <step name="load_context" priority="first">
14
+ Load project context via tier system:
15
+
16
+ ```bash
17
+ TIER_FILES=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" context load-tier lite --raw 2>/dev/null)
18
+ ```
19
+
20
+ Use `TIER_FILES` JSON `files` array for project context (PROJECT.md, STATE.md, config.json).
21
+ </step>
22
+
23
+ <step name="parse_arguments">
24
+ Extract version from `$ARGUMENTS`.
25
+
26
+ ```
27
+ VERSION = first argument from $ARGUMENTS
28
+ ```
29
+
30
+ **If no version provided:**
31
+ ```
32
+ Error: Version argument required. Usage: /dgs:cancel-job <version>
33
+ ```
34
+ </step>
35
+
36
+ <step name="cancel_job">
37
+ Run the cancel-job CLI command:
38
+
39
+ ```bash
40
+ RESULT=$(node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs jobs cancel-job "$VERSION")
41
+ ```
42
+
43
+ Parse the JSON result. The response contains:
44
+ ```json
45
+ {
46
+ "cancelled": true,
47
+ "version": "v6.0",
48
+ "steps_reset": 2,
49
+ "path": "jobs/pending/milestone-v6.0.md"
50
+ }
51
+ ```
52
+
53
+ Or on error:
54
+ ```json
55
+ {
56
+ "cancelled": false,
57
+ "reason": "not_found" | "not_in_progress",
58
+ "version": "v6.0"
59
+ }
60
+ ```
61
+ </step>
62
+
63
+ <step name="display_result">
64
+ Display the result based on the response:
65
+
66
+ **If `cancelled: true`:**
67
+ ```
68
+ Job {version} cancelled. {steps_reset} in-progress step(s) reset. Job moved to pending/ -- re-run with /dgs:run-job {version}
69
+ ```
70
+
71
+ **If `reason: 'not_found'`:**
72
+ ```
73
+ No job found for version {version}. Run /dgs:list-jobs to see available jobs.
74
+ ```
75
+
76
+ **If `reason: 'not_in_progress'`:**
77
+ ```
78
+ Job {version} is not in progress. Only in-progress jobs can be cancelled.
79
+ ```
80
+
81
+ No confirmation prompt -- cancel is not destructive per CONTEXT.md decisions.
82
+ </step>
83
+
84
+ <step name="generate_summary">
85
+ After a successful cancellation, generate and write a job summary:
86
+
87
+ ```bash
88
+ SUMMARY=$(node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs jobs generate-summary "$VERSION")
89
+ ```
90
+
91
+ Parse the result. If `found: true`, write the `content` field to the path returned in the result using the Write tool.
92
+
93
+ Display:
94
+ ```
95
+ Job summary written to {path from result}
96
+ ```
97
+ </step>
98
+
99
+ </process>
100
+
101
+ <success_criteria>
102
+ - [ ] Version extracted from arguments with error on missing
103
+ - [ ] Cancel operation via `dgs-tools.cjs jobs cancel-job` CLI call
104
+ - [ ] Success displays reset count and next-step hint
105
+ - [ ] Not-found and not-in-progress errors display helpful messages
106
+ - [ ] Job summary generated after successful cancellation
107
+ - [ ] No confirmation prompt required
108
+ </success_criteria>