@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,271 @@
1
+ <purpose>
2
+ Find pending ideas related to a selected anchor idea using multi-signal scoring. Uses the CLI's Jaccard tag overlap scoring as a first pass, then applies AI-powered semantic similarity and implementation overlap analysis informed by project context. Results are displayed grouped by match level (HIGH/MEDIUM/LOW) with per-idea reasoning. The user can select ideas from results and flow directly into consolidation.
3
+ </purpose>
4
+
5
+ <context_tier>planning</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 planning-tier context files:
15
+
16
+ ```bash
17
+ TIER_FILES=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" context load-tier planning --raw 2>/dev/null)
18
+ ```
19
+ </step>
20
+
21
+ <step name="parse_arguments">
22
+ Parse `$ARGUMENTS` for the anchor idea ID and optional flags.
23
+
24
+ - Extract a single numeric positional argument as the anchor idea ID (e.g., `/dgs:find-related-ideas 42` -> anchor_id=42)
25
+ - Check for `--threshold` flag (high|medium|low). If not provided, default to `medium`.
26
+
27
+ **If no ID provided**, list pending ideas and prompt for selection:
28
+
29
+ ```bash
30
+ PENDING=$(node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs ideas list --state pending --raw)
31
+ ```
32
+
33
+ Parse the JSON `ideas` array.
34
+
35
+ **If empty:**
36
+ ```
37
+ No pending ideas found. Run /dgs:add-idea to capture ideas first.
38
+ ```
39
+ Exit workflow.
40
+
41
+ **If fewer than 2 pending ideas:**
42
+ ```
43
+ Only 1 pending idea found. Finding related ideas requires at least 2 pending ideas.
44
+ ```
45
+ Exit workflow.
46
+
47
+ **If ideas exist:** Display them as a numbered list showing ID, title, and tags:
48
+
49
+ ```
50
+ ## Pending Ideas
51
+
52
+ | # | ID | Title | Tags |
53
+ |---|-----|-------|------|
54
+ | 1 | 001 | Add retry logic | api, reliability |
55
+ | 2 | 003 | Handle timeouts | api |
56
+ | 3 | 017 | Circuit breaker | api, reliability |
57
+ ```
58
+
59
+ Use AskUserQuestion: "Which idea would you like to find related ideas for? (enter a single ID, e.g. 42)"
60
+
61
+ Parse response into the anchor idea ID.
62
+ </step>
63
+
64
+ <step name="get_tag_overlap_scores">
65
+ Call the CLI to get algorithmic tag overlap scores:
66
+
67
+ ```bash
68
+ SCORES=$(node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs ideas find-related --id ${ANCHOR_ID} --threshold low --raw)
69
+ ```
70
+
71
+ Use `--threshold low` here to get ALL matches (including low). The workflow will apply the user's threshold after AI scoring.
72
+
73
+ Parse the JSON result. Extract the `anchor` object and `results` array.
74
+
75
+ The `anchor` object contains:
76
+ - `id`, `title`, `tags`, `body`, `notes`, `discussion_log`, `research_log`
77
+
78
+ Each result in the `results` array contains:
79
+ - `id`, `title`, `tags`, `match_level`, `ratio`, `shared_tags`, `body`, `notes`, `discussion_log`, `research_log`
80
+
81
+ **If results is empty:**
82
+ ```
83
+ No ideas with tag overlap found for #${ANCHOR_ID}: "${anchor.title}".
84
+ No related ideas to display.
85
+ ```
86
+ Exit workflow.
87
+
88
+ **Load anchor idea docs:**
89
+
90
+ Derive the anchor idea's docs directory from its file path:
91
+ ```bash
92
+ ANCHOR_PATH=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" ideas list --raw 2>/dev/null | jq -r --arg id "${ANCHOR_ID}" '.ideas[] | select(.id == ($id | tonumber)) | .path // empty')
93
+ ANCHOR_DOCS_DIR="$(dirname "${ANCHOR_PATH}")/docs"
94
+ ```
95
+
96
+ If the docs/ directory exists, load supporting documents:
97
+ - **Text files** (.md, .txt, .json, .yaml, .yml): Read using the Read tool.
98
+ - **Image files** (.png, .jpg, .jpeg, .gif, .svg, .webp): Read using the Read tool directly for multimodal context. Cap at 3 images for the anchor (scoring context does not need all images).
99
+ - **PDF files** (.pdf): Prefer .txt sidecar (same directory, same basename with .txt extension). If sidecar exists, read it. If no sidecar, read up to 3 pages via Read tool with `pages` parameter.
100
+ - **Other files**: Skip silently.
101
+
102
+ If docs/ directory does not exist: silent skip -- no docs is normal, do not mention it.
103
+ If any file is unreadable: skip silently.
104
+
105
+ Store loaded docs as `anchorDocs` for use in the scoring step.
106
+ </step>
107
+
108
+ <step name="load_project_context">
109
+ Load project context files to inform AI scoring.
110
+
111
+ ```bash
112
+ # Check for codebase docs
113
+ ls ${codebase_dir}/*.md 2>/dev/null
114
+ # Check for product docs
115
+ ls ${project_root}/docs/product/*.md 2>/dev/null
116
+ ```
117
+
118
+ Where `codebase_dir` is `.planning/codebase` (or the project-specific path if in multi-project mode) and `project_root` is the repo root.
119
+
120
+ Read available context files. Prioritise:
121
+ 1. `ARCHITECTURE.md` -- system structure and module boundaries
122
+ 2. `STACK.md` -- technology choices
123
+ 3. Other codebase docs that describe system areas
124
+
125
+ These give the AI understanding of the project's technology and structure for assessing implementation overlap.
126
+
127
+ **If no codebase or product docs exist**, proceed without them. The AI can still assess semantic similarity from idea content alone, and can infer implementation overlap from idea descriptions.
128
+ </step>
129
+
130
+ <step name="ai_score_relatedness">
131
+ For each candidate idea from the tag overlap results, perform two additional AI assessments.
132
+
133
+ Read the anchor's body and each candidate's body (available from the CLI results which include `body`, `notes`, `discussion_log`, `research_log` fields).
134
+
135
+ **Load candidate idea docs for richer scoring:**
136
+
137
+ For each candidate idea, before evaluating it, check for the candidate's docs/ directory:
138
+ ```bash
139
+ CANDIDATE_PATH=$(echo "${result}" | jq -r '.path // empty')
140
+ CANDIDATE_DOCS_DIR="$(dirname "${CANDIDATE_PATH}")/docs"
141
+ ```
142
+
143
+ If the docs/ directory exists, load supporting documents with a lighter approach to manage context budget:
144
+ - **Text files** (.md, .txt) only -- skip images for candidates to stay within context budget. Cap at 2 text docs per candidate.
145
+ - **PDF files**: sidecar preferred, fallback to 3 pages. Cap at 1 PDF per candidate.
146
+ - **Other files**: Skip silently.
147
+ - Missing docs/: silent skip. Unreadable files: skip silently.
148
+
149
+ **Context budget cap:** Track total loaded files across all candidates. If total loaded context exceeds 20 files across all candidates, stop loading additional candidate docs and score remaining candidates from body/notes/logs only. This prevents context overflow while enriching scoring for the highest tag-overlap matches (processed first).
150
+
151
+ For each candidate, evaluate:
152
+
153
+ **1. Semantic similarity** (do the ideas describe the same or overlapping problem/solution space?):
154
+ - Consider: Are they solving the same problem? Complementary problems? Different aspects of the same feature?
155
+ - Look at body content, notes, discussion logs, research logs, and loaded docs (anchor docs in `anchorDocs`, candidate docs if loaded)
156
+ - Anchor docs may reveal full scope via diagrams, screenshots, or reference material that body text alone does not capture
157
+ - Score: HIGH / MEDIUM / LOW / NONE
158
+
159
+ **2. Implementation overlap** (would implementing these ideas touch the same code/systems?):
160
+ - Using project context (codebase docs) and any architecture diagrams or technical docs from anchor/candidate docs/, assess whether both ideas would modify the same files, modules, or subsystems
161
+ - If no project context available, infer from idea descriptions (e.g., both mention "API endpoints" = likely overlap)
162
+ - Score: HIGH / MEDIUM / LOW / NONE
163
+
164
+ Do not penalize candidates without docs/ -- absence of docs is normal and should not affect scoring. If a candidate has no docs/, score based on body, notes, and logs alone (existing behavior).
165
+
166
+ **Combine the three signals** (tag_overlap from CLI, semantic_similarity, implementation_overlap) into a final `composite_level`:
167
+ - If ANY signal is HIGH -> composite = HIGH
168
+ - If 2+ signals are MEDIUM -> composite = HIGH
169
+ - If ANY signal is MEDIUM -> composite = MEDIUM
170
+ - If ANY signal is LOW -> composite = LOW
171
+ - Otherwise -> composite = NONE
172
+
173
+ **Generate a `reasoning` string** for each candidate explaining WHY it is related (1-2 sentences referencing the specific signals that contributed). Examples:
174
+ - "Both address API failure modes; would modify the same HTTP client module"
175
+ - "Directly complementary -- circuit breaker is the implementation pattern for the anchor's resilience goal"
176
+ - "Similar problem space (API reliability) but focused on client-side retries vs server-side resilience"
177
+ </step>
178
+
179
+ <step name="apply_threshold_and_group">
180
+ Apply the user's `--threshold` flag to filter the AI-scored results:
181
+ - `--threshold high` -> only composite HIGH
182
+ - `--threshold medium` (default) -> HIGH + MEDIUM
183
+ - `--threshold low` -> HIGH + MEDIUM + LOW
184
+
185
+ Remove any results with composite_level = NONE.
186
+
187
+ Group surviving results by composite match level (HIGH first, then MEDIUM, then LOW).
188
+
189
+ Within each group, sort by the tag overlap ratio descending (as a secondary sort within the same composite level).
190
+ </step>
191
+
192
+ <step name="display_results">
193
+ Display results grouped by match level:
194
+
195
+ ```
196
+ ## Related Ideas for #${ANCHOR_ID}: "${anchor_title}"
197
+
198
+ ### HIGH Match (N ideas)
199
+
200
+ | ID | Title | Tags | Reasoning |
201
+ |----|-------|------|-----------|
202
+ | 003 | Handle timeouts | api, reliability | Both address API failure modes; would modify the same HTTP client module |
203
+ | 017 | Circuit breaker | api, error-handling | Directly complementary -- circuit breaker is the implementation pattern for #42's resilience goal |
204
+
205
+ ### MEDIUM Match (N ideas)
206
+
207
+ | ID | Title | Tags | Reasoning |
208
+ |----|-------|------|-----------|
209
+ | 008 | Add retry logic | api | Similar problem space (API reliability) but focused on client-side retries vs server-side resilience |
210
+
211
+ ### Summary
212
+ Found N related ideas: X high, Y medium, Z low matches
213
+ Threshold: ${threshold} (showing ${what_is_shown})
214
+ ```
215
+
216
+ If no results survive the threshold, display:
217
+ ```
218
+ No ideas found matching threshold '${threshold}'. Try `--threshold low` to see all matches.
219
+ ```
220
+ And exit workflow.
221
+ </step>
222
+
223
+ <step name="offer_consolidation">
224
+ After displaying results, offer to flow into consolidation.
225
+
226
+ Use AskUserQuestion:
227
+ - question: "Would you like to consolidate any of these ideas with #${ANCHOR_ID}?\n- Enter idea IDs to consolidate (comma-separated, e.g. 3,17)\n- Type 'no' to skip"
228
+
229
+ **If user enters IDs:**
230
+ Build the full list of IDs to consolidate: anchor ID + selected IDs.
231
+
232
+ Execute the consolidation inline by following the steps defined in `deliver-great-systems/workflows/consolidate-ideas.md`:
233
+ 1. Validate all selected IDs exist and are in pending state
234
+ 2. Load full source content for all ideas (anchor + selected)
235
+ 3. AI synthesise a coherent body capturing combined intent
236
+ 4. Generate a title (or use --title if provided)
237
+ 5. Merge tags (deduplicated union)
238
+ 6. Merge discussion logs with `[from #ID]` attribution, chronologically ordered
239
+ 7. Merge research logs with `[from #ID]` attribution, chronologically ordered
240
+ 8. Merge notes with source attribution
241
+ 9. Present synthesised idea for user review (approve/edit/cancel)
242
+ 10. Execute via CLI: `node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs ideas consolidate --ids "${ids_csv}" --title "${title}" --body "${body}" --tags "${tags}" [--discussion "${discussion}"] [--research "${research}"] --raw`
243
+ 11. Display confirmation output
244
+
245
+ This satisfies the requirement that discovery flows directly into consolidation without requiring a separate command. The consolidate-ideas workflow already handles all synthesis logic; follow its steps directly rather than re-implementing them.
246
+
247
+ **Fallback** (only if context window is nearly exhausted): tell the user to run `/dgs:consolidate-ideas ${ANCHOR_ID} ${selected_ids}` and provide the exact command, explaining that a fresh context is needed.
248
+
249
+ **If user types 'no':**
250
+ ```
251
+ Discovery complete. Run `/dgs:consolidate-ideas <ids>` anytime to merge ideas.
252
+ ```
253
+ End workflow.
254
+ </step>
255
+
256
+ </process>
257
+
258
+ <success_criteria>
259
+ - [ ] Anchor idea parsed from arguments or selected interactively
260
+ - [ ] --threshold flag parsed (default: medium)
261
+ - [ ] Tag overlap scores retrieved from CLI via `ideas find-related`
262
+ - [ ] Project context files loaded when available (codebase/, docs/product/)
263
+ - [ ] Semantic similarity scored for each candidate (HIGH/MEDIUM/LOW/NONE)
264
+ - [ ] Implementation overlap scored for each candidate (HIGH/MEDIUM/LOW/NONE)
265
+ - [ ] Three signals combined into composite match level
266
+ - [ ] Results filtered by user's threshold
267
+ - [ ] Results displayed grouped by HIGH/MEDIUM/LOW with per-idea reasoning
268
+ - [ ] User offered option to flow into consolidation with selected ideas
269
+ - [ ] Consolidation executed inline following consolidate-ideas workflow steps
270
+ - [ ] Fallback command provided if context window is exhausted
271
+ </success_criteria>
@@ -0,0 +1,173 @@
1
+ <purpose>
2
+ Validate planning directory integrity and report actionable issues. Checks for missing files, invalid configurations, inconsistent state, and orphaned plans. Optionally repairs auto-fixable issues.
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_args">
24
+ **Parse arguments:**
25
+
26
+ Check if `--repair` flag is present in the command arguments.
27
+
28
+ ```
29
+ REPAIR_FLAG=""
30
+ if arguments contain "--repair"; then
31
+ REPAIR_FLAG="--repair"
32
+ fi
33
+ ```
34
+ </step>
35
+
36
+ <step name="run_health_check">
37
+ **Run health validation:**
38
+
39
+ ```bash
40
+ node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" validate health $REPAIR_FLAG
41
+ ```
42
+
43
+ Parse JSON output:
44
+ - `status`: "healthy" | "degraded" | "broken"
45
+ - `errors[]`: Critical issues (code, message, fix, repairable)
46
+ - `warnings[]`: Non-critical issues
47
+ - `info[]`: Informational notes
48
+ - `repairable_count`: Number of auto-fixable issues
49
+ - `repairs_performed[]`: Actions taken if --repair was used
50
+ </step>
51
+
52
+ <step name="format_output">
53
+ **Format and display results:**
54
+
55
+ ```
56
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
57
+ DGS Health Check
58
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
59
+
60
+ Status: HEALTHY | DEGRADED | BROKEN
61
+ Errors: N | Warnings: N | Info: N
62
+ ```
63
+
64
+ **If repairs were performed:**
65
+ ```
66
+ ## Repairs Performed
67
+
68
+ - ✓ config.json: Created with defaults
69
+ - ✓ STATE.md: Regenerated from roadmap
70
+ ```
71
+
72
+ **If errors exist:**
73
+ ```
74
+ ## Errors
75
+
76
+ - [E001] config.json: JSON parse error at line 5
77
+ Fix: Run /dgs:health --repair to reset to defaults
78
+
79
+ - [E002] PROJECT.md not found
80
+ Fix: Run /dgs:new-project to create
81
+ ```
82
+
83
+ **If warnings exist:**
84
+ ```
85
+ ## Warnings
86
+
87
+ - [W001] STATE.md references phase 5, but only phases 1-3 exist
88
+ Fix: Run /dgs:health --repair to regenerate
89
+
90
+ - [W005] Phase directory "1-setup" doesn't follow NN-name format
91
+ Fix: Rename to match pattern (e.g., 01-setup)
92
+ ```
93
+
94
+ **If info exists:**
95
+ ```
96
+ ## Info
97
+
98
+ - [I001] 02-implementation/02-01-PLAN.md has no SUMMARY.md
99
+ Note: May be in progress
100
+ ```
101
+
102
+ **Footer (if repairable issues exist and --repair was NOT used):**
103
+ ```
104
+ ---
105
+ N issues can be auto-repaired. Run: /dgs:health --repair
106
+ ```
107
+ </step>
108
+
109
+ <step name="offer_repair">
110
+ **If repairable issues exist and --repair was NOT used:**
111
+
112
+ Ask user if they want to run repairs:
113
+
114
+ ```
115
+ Would you like to run /dgs:health --repair to fix N issues automatically?
116
+ ```
117
+
118
+ If yes, re-run with --repair flag and display results.
119
+ </step>
120
+
121
+ <step name="verify_repairs">
122
+ **If repairs were performed:**
123
+
124
+ Re-run health check without --repair to confirm issues are resolved:
125
+
126
+ ```bash
127
+ node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" validate health
128
+ ```
129
+
130
+ Report final status.
131
+ </step>
132
+
133
+ </process>
134
+
135
+ <error_codes>
136
+
137
+ | Code | Severity | Description | Repairable |
138
+ |------|----------|-------------|------------|
139
+ | E001 | error | Planning directory not found | No |
140
+ | E002 | error | PROJECT.md not found | No |
141
+ | E003 | error | ROADMAP.md not found | No |
142
+ | E004 | error | STATE.md not found | Yes |
143
+ | E005 | error | config.json parse error | Yes |
144
+ | W001 | warning | PROJECT.md missing required section | No |
145
+ | W002 | warning | STATE.md references invalid phase | Yes |
146
+ | W003 | warning | config.json not found | Yes |
147
+ | W004 | warning | config.json invalid field value | No |
148
+ | W005 | warning | Phase directory naming mismatch | No |
149
+ | W006 | warning | Phase in ROADMAP but no directory | No |
150
+ | W007 | warning | Phase on disk but not in ROADMAP | No |
151
+ | W008 | warning | config.json: workflow.nyquist_validation absent (defaults to enabled but agents may skip) | Yes |
152
+ | W009 | warning | Phase has Validation Architecture in RESEARCH.md but no VALIDATION.md | No |
153
+ | W010 | warning | Repo unreachable (directory not found) | No |
154
+ | I001 | info | Plan without SUMMARY (may be in progress) | No |
155
+ | I002 | info | All repos reachable | No |
156
+
157
+ </error_codes>
158
+
159
+ <repair_actions>
160
+
161
+ | Action | Effect | Risk |
162
+ |--------|--------|------|
163
+ | createConfig | Create config.json with defaults | None |
164
+ | resetConfig | Delete + recreate config.json | Loses custom settings |
165
+ | regenerateState | Create STATE.md from ROADMAP structure | Loses session history |
166
+ | addNyquistKey | Add workflow.nyquist_validation: true to config.json | None — matches existing default |
167
+
168
+ **Not repairable (too risky):**
169
+ - PROJECT.md, ROADMAP.md content
170
+ - Phase directory renaming
171
+ - Orphaned plan cleanup
172
+
173
+ </repair_actions>