@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,381 @@
1
+ <purpose>
2
+ Import an external document and convert it into a structured 9-section PRD using AI-powered restructuring. Reads the source file, transforms its content into standard PRD sections with full content preservation, and presents the result for user review with revision support. This is the core conversion pipeline for the `/dgs:import-spec` command.
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="initialize" priority="first">
14
+ Load planning context:
15
+
16
+ ```bash
17
+ INIT=$(node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs init milestone-op)
18
+ ```
19
+
20
+ Extract: `project_root`, `config_path` as needed by the workflow.
21
+
22
+ Load planning-tier context files:
23
+
24
+ ```bash
25
+ TIER_FILES=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" context load-tier planning --raw 2>/dev/null)
26
+ ```
27
+ </step>
28
+
29
+ <step name="parse_arguments">
30
+ Extract the file path and optional flags from `$ARGUMENTS`.
31
+
32
+ **File path extraction:**
33
+ - The first positional argument (before any `--` flags) is the file path.
34
+ - If no file path is provided, display an error and stop:
35
+ ```
36
+ Usage: /dgs:import-spec <file-path> [--ideas IDEA-1 IDEA-2 ...]
37
+ ```
38
+ - The file path may be absolute or relative to the current working directory.
39
+ - Store the resolved path as `FILE_PATH`.
40
+
41
+ **Ideas flag parsing:**
42
+ - Scan `$ARGUMENTS` for the `--ideas` flag.
43
+ - If `--ideas` is present with no IDs after it (no arguments follow, or the next argument is another flag starting with `--`), display an error and stop:
44
+ ```
45
+ --ideas requires at least one idea ID. Usage: --ideas IDEA-1 IDEA-2
46
+ ```
47
+ - If `--ideas` is present with IDs, collect all arguments after `--ideas` (space-separated, e.g., `--ideas IDEA-1 IDEA-3 IDEA-7`) as the `IDEA_IDS` list. Stop collecting when another `--` flag is encountered or arguments end.
48
+ - The IDs may be in formats like `IDEA-1`, `IDEA-3`, `1`, `3` -- normalize by extracting the numeric portion.
49
+ - If `--ideas` is not present, set `IDEA_IDS` to empty.
50
+ </step>
51
+
52
+ <step name="validate_ideas">
53
+ Only runs if `IDEA_IDS` is non-empty. If `IDEA_IDS` is empty, skip this step entirely.
54
+
55
+ **Validate all idea IDs upfront before conversion starts:**
56
+
57
+ 1. Run:
58
+ ```bash
59
+ node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs ideas list --raw
60
+ ```
61
+ 2. Parse the JSON output to get the list of all ideas (the `ideas` array).
62
+ 3. For each idea ID in `IDEA_IDS`:
63
+ - Extract the numeric portion (e.g., `IDEA-3` becomes `3`, `42` stays `42`).
64
+ - Check if any idea in the returned list has an `id` field matching that number.
65
+ - If no match is found, add the ID to an `INVALID_IDS` list.
66
+ 4. If `INVALID_IDS` is non-empty, display an error and stop:
67
+ ```
68
+ Invalid idea IDs: IDEA-99, IDEA-42. Run /dgs:list-ideas to see available ideas.
69
+ ```
70
+ 5. If all IDs are valid, store:
71
+ - `IDEA_FILENAMES`: comma-separated idea filenames for passing to `specs create --source-ideas` (e.g., `001-my-idea.md,003-other-idea.md`). Extract the `filename` field from each matching idea.
72
+ - `IDEA_DISPLAY`: list of `IDEA-{id} ({title})` strings for display during review (e.g., `IDEA-1 (Phase 0 Foundation Infrastructure)`).
73
+ </step>
74
+
75
+ <step name="read_source">
76
+ Use the Read tool to read the file at `FILE_PATH`.
77
+
78
+ **Error handling:**
79
+ - If the file does not exist, display: `File not found: <FILE_PATH>` and stop execution.
80
+ - If the file cannot be read (permissions, binary, etc.), display: `Cannot read file: <FILE_PATH>` and stop execution.
81
+
82
+ **Processing:**
83
+ - Store the full file content as `SOURCE_CONTENT`.
84
+ - Extract the filename (without directory path) as `SOURCE_FILENAME`.
85
+ - Handle both absolute paths and relative paths (resolve relative paths against the current working directory).
86
+
87
+ **Frontmatter handling:**
88
+ - If the source file has YAML frontmatter (delimited by `---`), extract any useful metadata from it (title, status, author, date, tags, etc.) and store separately.
89
+ - Strip the raw frontmatter block from the content before passing to conversion -- the frontmatter metadata will be used to inform the conversion but should not appear as raw YAML in the output.
90
+ - If no frontmatter is present, proceed with the full content as-is.
91
+ </step>
92
+
93
+ <step name="check_duplicate">
94
+ Check if any existing spec already references the same source filename. This step runs after `read_source` (which sets `SOURCE_FILENAME`) and before `load_context`.
95
+
96
+ 1. Run:
97
+ ```bash
98
+ node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs specs list --raw
99
+ ```
100
+ 2. Parse the JSON output to get the list of all specs.
101
+ 3. For each spec, check if it has a `source_document` field.
102
+ 4. If `source_document` is present, extract the filename portion (the last path segment, e.g., `specs/spec-foo/docs/my-doc.md` becomes `my-doc.md`).
103
+ 5. Compare against `SOURCE_FILENAME` (the filename being imported, already set by `read_source`).
104
+ 6. If a match is found, display a warning:
105
+ ```
106
+ Warning: Spec "{existing-spec-title}" (ID: {existing-id}) was already imported from a file named "{filename}". Proceeding will create a second spec from this source.
107
+ ```
108
+ 7. Use AskUserQuestion: `Continue with import? (yes/no)`
109
+ - If the user responds "no" or "cancel", display `Import cancelled.` and stop execution.
110
+ - If the user responds "yes" or any other input, proceed to the next step.
111
+ 8. If no duplicate is found, proceed silently.
112
+ </step>
113
+
114
+ <step name="load_context">
115
+ Load project context to inform the conversion. Two context sources are checked, each with a different loading strategy. When neither source exists, the workflow proceeds silently with empty context -- the conversion step never mentions whether context was available.
116
+
117
+ **1. Codebase context (selective loading):**
118
+
119
+ ```bash
120
+ ls ${project_root}/codebase/*.md 2>/dev/null
121
+ ```
122
+
123
+ - If the directory does not exist or contains no `.md` files, set `CODEBASE_CONTEXT` to empty and proceed silently.
124
+ - If files are found, read the first ~20 lines of each file using the Read tool (with `limit: 20`) to extract its title and purpose.
125
+ - Score each file's relevance against `SOURCE_CONTENT`:
126
+ - **Broadly relevant** (almost always load): files about Architecture, Stack, Structure -- these inform any conversion.
127
+ - **Conditionally relevant** (load only if source mentions the domain): files about Testing, Integrations, Conventions, Concerns, Security, Performance -- load only if keywords from the file's topic appear in `SOURCE_CONTENT`.
128
+ - Use keyword overlap between the codebase file's title/purpose and the source document's content to decide relevance.
129
+ - Load the full content of relevant files (typically 2-4 files; use judgment to balance thoroughness against token budget).
130
+ - Concatenate the loaded file contents and store as `CODEBASE_CONTEXT`.
131
+
132
+ **2. Product docs (load all):**
133
+
134
+ ```bash
135
+ ls ${project_root}/docs/product/*.md 2>/dev/null
136
+ ```
137
+
138
+ - If the directory does not exist or contains no `.md` files, set `PRODUCT_CONTEXT` to empty and proceed silently.
139
+ - If files are found, read every `.md` file using the Read tool.
140
+ - Concatenate all file contents and store as `PRODUCT_CONTEXT`.
141
+
142
+ **Silent fallback:** When both `CODEBASE_CONTEXT` and `PRODUCT_CONTEXT` are empty, proceed to `convert_to_prd` without any warning or output change. The conversion produces the same output as it would without this step.
143
+ </step>
144
+
145
+ <step name="convert_to_prd">
146
+ This is the core AI conversion step. Restructure `SOURCE_CONTENT` into a 9-section PRD.
147
+
148
+ **Context incorporation:** If `CODEBASE_CONTEXT` or `PRODUCT_CONTEXT` were loaded by the previous step, use them to inform the conversion throughout. Codebase context grounds Implementation Notes in real files and patterns; product context aligns goals and architecture with the broader product vision. When context is available, weave it naturally into the relevant sections -- do not mention whether context was or was not available in the output. When context is empty, produce the same quality output using inference alone.
149
+
150
+ **Auto-generate a spec title** from the source content. The title should capture the core topic or feature described in the document. Store as `SPEC_TITLE`.
151
+
152
+ **Produce a PRD with these exact 9 sections in this order:**
153
+
154
+ 1. `## Problem Statement` -- Extract or infer the core problem the source document addresses. If the source does not have an explicit problem statement, synthesise one from the goals, requirements, and context described.
155
+
156
+ 2. `## Goals` -- Concrete goals derived from the source. Each goal should be specific and actionable. If the source lists objectives, outcomes, or success criteria, translate them into goals.
157
+
158
+ 3. `## Non-Goals` -- Explicit boundaries on what this spec does NOT cover. Derive from what the source deliberately excludes or marks as out of scope. If the source is silent on non-goals, infer likely non-goals from the problem domain and flag each with "(inferred)".
159
+
160
+ 4. `## User Stories` -- User stories in "As a [user], I want [X] so that [Y]" format. Derive from the source's requirements, features, or described workflows. Each distinct capability should have its own user story.
161
+
162
+ 5. `## Requirements` -- All requirements organised by priority:
163
+ - `### P0 -- Must Have` -- Core requirements that are essential for the feature to function.
164
+ - `### P1 -- Nice-to-Have` -- Important but not blocking requirements.
165
+ - `### P2 -- Future Considerations` -- Items explicitly deferred or mentioned as future work.
166
+ - **Every individual requirement, acceptance criterion, and behavioural detail from the source MUST appear in the appropriate priority tier.** If the source has numbered requirements (e.g., REQ-01, FR-3), each must be carried across with its original identifier preserved.
167
+ - **Priority classification rules based on explicit language signals:**
168
+ - **P0:** "must", "critical", "required", "essential", "mandatory", "shall" -> P0
169
+ - **P1:** "should", "important", "ideally", "recommended", "expected" -> P1
170
+ - **P2:** "could", "nice to have", "nice-to-have", "future", "later", "eventually", "out of scope for now" -> P2
171
+ - **When no explicit priority language exists** in the source for a requirement, default it to P1.
172
+ - **Always normalise the source document's own priority scheme to P0/P1/P2.** For example: High/Medium/Low -> P0/P1/P2; Critical/Major/Minor -> P0/P1/P2; Tier 1/Tier 2/Tier 3 -> P0/P1/P2.
173
+ - **Honest classification:** Classify based on language signals regardless of the resulting distribution. It is acceptable if most requirements end up in the same tier (e.g., all P1). Do not artificially redistribute to achieve balance.
174
+
175
+ 6. `## Success Metrics` -- Measurable outcomes that indicate the feature is working correctly. Derive from the source's acceptance criteria, KPIs, or success definitions. If the source lacks explicit metrics, infer reasonable ones from the goals and requirements.
176
+
177
+ 7. `## Open Questions` -- Flag three types of issues in one section:
178
+ - **Missing details:** Information the source document does not address that would be needed for implementation. Flag with "(missing detail)".
179
+ - **Contradictions:** Places where the source document contradicts itself or gives conflicting guidance. Flag with "(contradiction)".
180
+ - **Ambiguous language:** Statements that could be interpreted multiple ways, where the intended meaning affects implementation. Flag with "(ambiguous)".
181
+ - Also include questions or unknowns explicitly raised in the source document itself.
182
+ - **Suggested answers:** For each question, include a brief suggested answer -- a reasonable default Claude would use if the question is not addressed. Format as: "Suggested: [proposed answer]".
183
+ - **Context-informed questions:** When `CODEBASE_CONTEXT` is available, generate questions that surface gaps between the source document and the existing codebase (e.g., "This spec mentions caching but the codebase has no caching layer -- should a new caching module be introduced?"). When `PRODUCT_CONTEXT` is available, flag misalignments with product direction.
184
+ - Quantity is at Claude's discretion -- calibrate based on spec complexity and ambiguity level. A simple, clear spec may have 2-3 questions; a complex, ambiguous one may have 8-10.
185
+
186
+ 8. `## Timeline Considerations` -- Dependencies, sequencing, phasing, and any timeline-related information from the source. If the source describes phases, milestones, or ordering constraints, capture them here. If the source has no timeline information, note key dependencies and suggest a logical ordering.
187
+
188
+ 9. `## Implementation Notes` -- Technical details, architecture notes, code examples, CLI signatures, file path references, API contracts, data models, and any other implementation-specific content from the source. Preserve technical details verbatim where possible. If the source contains code snippets, include them in fenced code blocks.
189
+ - **Codebase grounding (when `CODEBASE_CONTEXT` is available):** Reference specific files from the codebase (e.g., "Update `bin/dgs-tools.cjs`", "Add new module to `deliver-great-systems/bin/lib/`"). Reference established patterns (e.g., "Follow the existing subagent spawning pattern used in plan-phase", "Use the CommonJS module pattern from `lib/*.cjs`"). Blend file-level and pattern-level references naturally -- do not attribute which notes came from codebase context vs inference.
190
+ - **Product alignment (when `PRODUCT_CONTEXT` is available):** Use product-level knowledge to inform architectural suggestions. If product docs describe a target architecture, align Implementation Notes with it. If product docs define conventions or constraints, reflect those in the implementation guidance.
191
+ - **When neither context is available:** Still produce Implementation Notes using generic suggestions inferred from the source document's content and domain. The section should always be substantive.
192
+
193
+ **Critical conversion rules:**
194
+ - This is a RESTRUCTURING, not a summarisation. Every detail, requirement, acceptance criterion, example, edge case, and technical note from the original MUST appear in the converted output.
195
+ - When content maps to multiple PRD sections, duplicate it in both sections rather than choosing one.
196
+ - Non-text elements (images, diagrams) referenced by path in the source should be noted as "[Referenced: <filename>]" in the relevant sections.
197
+ - Infer aggressively for sections where the source has no explicit content -- fill in Non-Goals, Success Metrics, Open Questions, and Timeline Considerations based on what the source implies and what is missing.
198
+ - Always fully restructure even if the source is already close to PRD format -- this ensures consistent formatting and enrichment.
199
+ - If source frontmatter metadata was extracted (title, status, etc.), use it to inform the conversion but do not include it as a separate section.
200
+
201
+ Store the full converted PRD as `CONVERTED_PRD`.
202
+ </step>
203
+
204
+ <step name="present_and_review">
205
+ Present the converted PRD for user review and handle the review loop.
206
+
207
+ **Compute the slug and attachment path for display:**
208
+ 1. Generate the slug from `SPEC_TITLE`: lowercase, replace non-alphanumeric characters with hyphens, trim leading/trailing hyphens.
209
+ 2. Compute the slugified source filename: take `SOURCE_FILENAME`, lowercase it, replace non-alphanumeric characters (except dots) with hyphens, trim leading/trailing hyphens, preserve file extension. This matches `docs.slugifyFilename()` behaviour.
210
+ 3. Compute the attachment path: `specs/spec-{slug}/docs/{slugified-source-filename}` (relative to the planning root).
211
+
212
+ **Display the conversion result:**
213
+
214
+ ```
215
+ ## Converted: {SPEC_TITLE}
216
+
217
+ {CONVERTED_PRD}
218
+
219
+ ---
220
+ Original: will be saved to ${project_root}/{attachment_path}
221
+ {If IDEA_IDS is non-empty: "Linking to: " followed by comma-separated IDEA_DISPLAY entries, e.g., "Linking to: IDEA-1 (Phase 0 Foundation Infrastructure), IDEA-3 (Other Idea)"}
222
+
223
+ **Review options:**
224
+ - **save** -- Save as draft spec
225
+ - **edit** -- Describe changes to apply
226
+ - **regenerate** -- Start fresh conversion (with optional guidance)
227
+ - **cancel** -- Abort the import
228
+ ```
229
+
230
+ **Use AskUserQuestion** to get the user's choice.
231
+
232
+ **Handle each action:**
233
+
234
+ **If "save":**
235
+ 1. Generate the slug from `SPEC_TITLE` (lowercase, replace non-alphanumeric with hyphens, trim leading/trailing hyphens).
236
+ 2. Check if `${project_root}/specs/spec-{slug}.md` already exists. If it does, use AskUserQuestion to prompt: `A spec with slug '{slug}' already exists. Enter a new title:` -- then regenerate the slug from the new title and re-check. Loop until no conflict.
237
+ 3. Compute the slugified source filename: take `SOURCE_FILENAME`, lowercase it, replace non-alphanumeric chars (except dots) with hyphens, trim leading/trailing hyphens, preserve file extension. This matches `docs.slugifyFilename()` behaviour.
238
+ 4. Compute the attachment path: `specs/spec-{slug}/docs/{slugified-source-filename}` (relative to the planning root).
239
+ 5. Call specs create (with --source-ideas when ideas are linked):
240
+ ```bash
241
+ # When IDEA_FILENAMES is non-empty:
242
+ node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs specs create --title "{SPEC_TITLE}" --body "{CONVERTED_PRD}" --source-document "{attachment_path}" --source-ideas "{IDEA_FILENAMES}"
243
+
244
+ # When IDEA_FILENAMES is empty (no --ideas flag was provided):
245
+ node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs specs create --title "{SPEC_TITLE}" --body "{CONVERTED_PRD}" --source-document "{attachment_path}"
246
+ ```
247
+ The `--source-ideas` value is the comma-separated list of idea filenames from `IDEA_FILENAMES` (e.g., `001-my-idea.md,003-other-idea.md`).
248
+ Parse the JSON result to get `id`, `filename`, `path`.
249
+ 6. Add the initial Refinement Log entry:
250
+ ```bash
251
+ node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs specs add-log-entry --id "$id" --date "$(date +%Y-%m-%d)" --version "1.0" --action Created --summary "Imported from $SOURCE_FILENAME via /dgs:import-spec"
252
+ ```
253
+ 7. Call docs add to copy the original source document:
254
+ ```bash
255
+ node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs docs add --source "{FILE_PATH}" --scope spec --scope-id "{id}"
256
+ ```
257
+ This copies the file (not moves), slugifies the filename, and updates INDEX.md automatically.
258
+ 8. Construct the commit message and auto-commit all import artifacts:
259
+
260
+ **Commit message format:** `specs: import {id} - {title} (from {original-filename})`
261
+ - `{id}` is the spec ID from the specs create result (e.g., `SPEC-005`).
262
+ - `{title}` is `SPEC_TITLE`, truncated to 50 characters with ellipsis if longer. Truncation: if title length > 50, take first 47 characters + `...`.
263
+ - `{original-filename}` is `SOURCE_FILENAME` (the original filename, not slugified).
264
+
265
+ **Execute the commit:**
266
+ ```bash
267
+ node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs commit "specs: import {id} - {title} (from {original-filename})" --files ${project_root}/specs/spec-{slug}.md ${project_root}/{attachment_path} ${project_root}/specs/spec-{slug}/docs/INDEX.md ${project_root}/specs/spec-{slug}/docs/.names.json
268
+ ```
269
+ The `dgs-tools.cjs commit` helper with `--files` stages only the specified files and commits them. This ensures other unstaged/uncommitted changes in the working tree are not included. The `.names.json` file is included because `docs add` creates it as internal metadata for INDEX rebuilds.
270
+
271
+ **Handle commit failure:**
272
+ If the commit command fails (non-zero exit code):
273
+ - Do NOT undo the save (files remain on disk).
274
+ - Display: `Git commit failed: {error message}. Files have been saved but not committed. You can commit manually.`
275
+ - Do NOT stop execution -- continue to display post-save feedback.
276
+ - Set `COMMIT_FAILED = true` for use in the post-save feedback display.
277
+
278
+ 9. Display post-save feedback:
279
+
280
+ **On successful commit:**
281
+ ```
282
+ Spec created:
283
+ ID: {id}
284
+ Title: {SPEC_TITLE}
285
+ Status: draft
286
+ File: ${project_root}/{filename path from specs create result}
287
+ Source: ${project_root}/{attachment_path}
288
+ Committed: specs: import {id} - {title} (from {original-filename})
289
+ {If IDEA_IDS is non-empty: "Linked ideas: IDEA-1, IDEA-3 (unchanged state)"}
290
+
291
+ Next steps:
292
+ - Review and refine the draft with /dgs:review-spec
293
+ ```
294
+
295
+ **On commit failure (COMMIT_FAILED is true):**
296
+ ```
297
+ Spec created:
298
+ ID: {id}
299
+ Title: {SPEC_TITLE}
300
+ Status: draft
301
+ File: ${project_root}/{filename path from specs create result}
302
+ Source: ${project_root}/{attachment_path}
303
+ {If IDEA_IDS is non-empty: "Linked ideas: IDEA-1, IDEA-3 (unchanged state)"}
304
+
305
+ Next steps:
306
+ - Review and refine the draft with /dgs:review-spec
307
+ - Commit the new spec and source document to version control
308
+ ```
309
+ 10. Stop execution.
310
+
311
+ **If "cancel":**
312
+ Display: `Import cancelled.`
313
+ Stop execution.
314
+
315
+ **If "edit":**
316
+ 1. Use AskUserQuestion: `What changes would you like to make?`
317
+ 2. Read the user's free-text description of desired changes.
318
+ 3. Re-run the AI conversion (the convert_to_prd step logic), incorporating the user's edit instructions as additional guidance overlaid on the original `SOURCE_CONTENT`. The edit request should modify the existing `CONVERTED_PRD` -- it is a targeted revision, not a fresh conversion. The feedback may request changes to:
319
+ - Section content (e.g., "move X from P1 to P0")
320
+ - Missing details (e.g., "add a user story about admin access")
321
+ - Tone or framing (e.g., "make the problem statement more specific")
322
+ - Title changes (e.g., "rename to X")
323
+ - Any other adjustments
324
+ 4. Update `CONVERTED_PRD` and `SPEC_TITLE` (if the edit affects the title).
325
+ 5. Recompute the slug and attachment path from the updated `SPEC_TITLE`.
326
+ 6. Re-display the full spec with the same review options. Continue the loop.
327
+
328
+ **If "regenerate":**
329
+ 1. Use AskUserQuestion: `Any guidance for the regeneration? (press enter to skip)`
330
+ 2. If the user provides guidance, store it. If empty/enter, proceed without guidance.
331
+ 3. Re-run the full conversion from scratch (the convert_to_prd step logic) using `SOURCE_CONTENT` plus any guidance. This is a fresh conversion, not a patch.
332
+ 4. Update `CONVERTED_PRD` and `SPEC_TITLE`.
333
+ 5. Recompute the slug and attachment path from the updated `SPEC_TITLE`.
334
+ 6. Re-display the full spec with the same review options. Continue the loop.
335
+
336
+ **Any other input:** Treat as an edit request (per convention -- non-standard input is treated as revision feedback). Proceed as if they chose "edit" with the input as feedback.
337
+
338
+ **No limit on iterations** -- the user can edit/regenerate as many times as they want until they save or cancel.
339
+ </step>
340
+
341
+ </process>
342
+
343
+ <success_criteria>
344
+ - [ ] File path argument is parsed from $ARGUMENTS
345
+ - [ ] Missing file path produces clear usage error
346
+ - [ ] Non-existent file produces "File not found" error
347
+ - [ ] Unreadable file produces "Cannot read file" error
348
+ - [ ] Source file content is read and stored
349
+ - [ ] YAML frontmatter is stripped from source before conversion (if present)
350
+ - [ ] --ideas flag parsed from arguments with error on empty IDs
351
+ - [ ] All idea IDs validated upfront via ideas list with clear error for invalid IDs
352
+ - [ ] Duplicate import detection warns when another spec references the same source filename
353
+ - [ ] Codebase context selectively loaded based on relevance scoring (when ${project_root}/codebase/ exists)
354
+ - [ ] Product docs unconditionally loaded (when ${project_root}/docs/product/ exists)
355
+ - [ ] Missing context directories produce no warnings or output changes
356
+ - [ ] Conversion produces all 9 PRD sections in correct order
357
+ - [ ] Every detail from source appears in converted output (restructuring, not summarisation)
358
+ - [ ] Non-goals are inferred when source is silent (flagged as inferred)
359
+ - [ ] Open questions flag missing details, contradictions, and ambiguous language with suggested answers
360
+ - [ ] Requirements use explicit language signal mapping (must/critical -> P0, should/important -> P1, could/nice-to-have -> P2) with P1 default
361
+ - [ ] Requirements preserve original identifiers if numbered in source
362
+ - [ ] Implementation Notes reference real files and patterns when codebase context available
363
+ - [ ] Spec title is auto-generated from source content
364
+ - [ ] Full converted PRD is displayed for review with attachment path shown
365
+ - [ ] Linked ideas displayed in review when --ideas provided
366
+ - [ ] Four review actions available: save, edit, regenerate, cancel
367
+ - [ ] Save creates draft spec via specs create with source_document field populated
368
+ - [ ] Save passes --source-ideas to specs create when ideas are linked
369
+ - [ ] Save copies original source file to spec docs via docs add (handles slugified filename and INDEX.md)
370
+ - [ ] Save produces atomic git commit of spec file, attachment, INDEX.md, and .names.json via dgs-tools.cjs commit --files
371
+ - [ ] Commit message follows format: specs: import {id} - {title} (from {original-filename}) with 50-char title truncation
372
+ - [ ] Commit failure is non-fatal: files preserved, error reported, execution continues
373
+ - [ ] Post-save feedback shows commit confirmation and linked ideas (unchanged state)
374
+ - [ ] Edit collects natural language feedback via AskUserQuestion and re-runs targeted conversion
375
+ - [ ] Regenerate asks for optional guidance and re-runs full conversion from scratch
376
+ - [ ] Slug conflict prompts user for new title via AskUserQuestion
377
+ - [ ] Cancel option stops with clear message
378
+ - [ ] Non-standard review input treated as edit feedback
379
+ - [ ] Unlimited edit/regenerate revision rounds supported
380
+ - [ ] source_document field written to spec YAML frontmatter on save
381
+ </success_criteria>