@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,621 @@
1
+ <purpose>
2
+ Orchestrate parallel codebase mapper agents to analyze registered repos and produce per-repo structured documents in ${codebase_dir}/<repo-name>/, then synthesize unified top-level files at ${codebase_dir}/.
3
+
4
+ Supports two modes:
5
+ - **Refresh mode** (default): Clears all per-repo subdirectories and unified files, then remaps everything from scratch.
6
+ - **Update mode** (`--only <repo-name>`): Clears only the targeted repo's subdirectory, re-maps it, then regenerates all unified files.
7
+
8
+ Each agent has fresh context, explores a specific focus area for a specific repo, and **writes documents directly**. The orchestrator only receives confirmation + line counts, then writes a summary.
9
+
10
+ Output: ${codebase_dir}/<repo-name>/ folders, each with 7 structured documents about that repo's codebase state, plus 7 unified top-level files synthesized from per-repo content, plus CROSS-REPO.md with cross-repo comparison tables (when 2+ repos).
11
+ </purpose>
12
+
13
+ <context_tier>planning</context_tier>
14
+
15
+ <philosophy>
16
+ **Why dedicated mapper agents:**
17
+ - Fresh context per domain (no token contamination)
18
+ - Agents write documents directly (no context transfer back to orchestrator)
19
+ - Orchestrator only summarizes what was created (minimal context usage)
20
+ - Faster execution (agents run simultaneously across all repos)
21
+
22
+ **Document quality over length:**
23
+ Include enough detail to be useful as reference. Prioritize practical examples (especially code patterns) over arbitrary brevity.
24
+
25
+ **Always include file paths:**
26
+ Documents are reference material for Claude when planning/executing. Always include actual file paths formatted with backticks: `src/services/user.ts`.
27
+ </philosophy>
28
+
29
+ <process>
30
+
31
+ <step name="init_context" priority="first">
32
+ Load codebase mapping context:
33
+
34
+ ```bash
35
+ INIT=$(node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs init map-codebase)
36
+ ```
37
+
38
+ If `--only <repo-name>` was passed to the slash command, forward it:
39
+
40
+ ```bash
41
+ INIT=$(node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs init map-codebase --only <repo-name>)
42
+ ```
43
+
44
+ Extract from init JSON: `mapper_model`, `commit_docs`, `codebase_dir`, `existing_maps`, `has_maps`, `codebase_dir_exists`, `multi_repo`, `repos`, `valid_repos`, `repo_errors`, `existing_repo_maps`, `mode`, `only_repo`.
45
+
46
+ Load planning-tier context files:
47
+
48
+ ```bash
49
+ TIER_FILES=$(node "$HOME/.claude/deliver-great-systems/bin/dgs-tools.cjs" context load-tier planning --raw 2>/dev/null)
50
+ ```
51
+
52
+ **Mode determination:**
53
+ - `mode === "refresh"`: Default. Clear everything, remap all repos.
54
+ - `mode === "update"`: `--only` was used. Clear and remap only the targeted repo, then regenerate unified files.
55
+ </step>
56
+
57
+ <step name="validate_repos" priority="high">
58
+ Check multi-repo readiness from init JSON.
59
+
60
+ **If `multi_repo` is false** (no valid repos registered):
61
+
62
+ ```
63
+ No repos registered — skipping codebase mapping. Run /dgs:add-repo to register your first repo.
64
+ ```
65
+
66
+ This is a clean exit, not an error. In job mode (non-interactive), report `SUCCESS` — this step succeeds with no changes. End workflow.
67
+
68
+ **If `repo_errors` is non-empty:**
69
+
70
+ Show warnings for invalid repos but continue with valid ones:
71
+ ```
72
+ Warning: Some repos could not be validated:
73
+ [List each error from repo_errors]
74
+
75
+ Proceeding with valid repos: [List valid_repos]
76
+ ```
77
+
78
+ **If ALL repos are invalid** (valid_repos is empty but REPOS.md had entries):
79
+
80
+ ```
81
+ No repos registered. Run /dgs:add-repo to register your first repo.
82
+ ```
83
+
84
+ End workflow.
85
+
86
+ Continue to check_existing.
87
+ </step>
88
+
89
+ <step name="check_existing">
90
+ **Mode-aware cleanup.** Codebase docs are regeneratable data, so deletion requires no confirmation.
91
+
92
+ **Refresh mode (mode === "refresh"):**
93
+ - Delete any existing flat codebase docs (top-level .md files in ${codebase_dir}/) silently
94
+ - Delete any existing per-repo subdirectories in ${codebase_dir}/ silently
95
+
96
+ **Update mode (mode === "update", only_repo is set):**
97
+ - Delete ONLY the targeted repo's subdirectory: `rm -rf ${codebase_dir}/${only_repo}/`
98
+ - Do NOT delete other repos' subdirectories
99
+ - Do NOT delete unified top-level files (they will be regenerated after mapping)
100
+
101
+ Continue to create_structure.
102
+ </step>
103
+
104
+ <step name="create_structure">
105
+ Create per-repo subdirectories in ${codebase_dir}/:
106
+
107
+ **Refresh mode:**
108
+
109
+ ```bash
110
+ # Delete any existing flat codebase docs (migration from old layout)
111
+ rm -f ${codebase_dir}/*.md 2>/dev/null
112
+
113
+ # Delete any existing per-repo subdirectories
114
+ rm -rf ${codebase_dir}/*/ 2>/dev/null
115
+
116
+ # Create per-repo subdirectories for all valid repos
117
+ for repo in ${valid_repos}; do
118
+ mkdir -p ${codebase_dir}/${repo}
119
+ done
120
+ ```
121
+
122
+ **Update mode:**
123
+
124
+ ```bash
125
+ # Delete only the targeted repo's subdirectory
126
+ rm -rf ${codebase_dir}/${only_repo}/ 2>/dev/null
127
+
128
+ # Create directory for the targeted repo
129
+ mkdir -p ${codebase_dir}/${only_repo}
130
+ ```
131
+
132
+ Each repo subdirectory will contain all 7 documents:
133
+ - STACK.md (from tech mapper)
134
+ - INTEGRATIONS.md (from tech mapper)
135
+ - ARCHITECTURE.md (from arch mapper)
136
+ - STRUCTURE.md (from arch mapper)
137
+ - CONVENTIONS.md (from quality mapper)
138
+ - TESTING.md (from quality mapper)
139
+ - CONCERNS.md (from concerns mapper)
140
+
141
+ Continue to spawn_agents.
142
+ </step>
143
+
144
+ <step name="spawn_agents">
145
+ Spawn 4 parallel dgs-codebase-mapper agents **per repo**. All agents across all repos run in parallel (all spawned with `run_in_background=true`).
146
+
147
+ Use Task tool with `subagent_type="dgs-codebase-mapper"`, `model="{mapper_model}"`, and `run_in_background=true`.
148
+
149
+ **CRITICAL:** Use the dedicated `dgs-codebase-mapper` agent, NOT `Explore`. The mapper agent writes documents directly.
150
+
151
+ **Refresh mode:** Spawn agents for all repos in `repos` array.
152
+
153
+ **Update mode:** Spawn agents only for the targeted repo. Show: `Updating ${only_repo}...`
154
+
155
+ **For each repo in `repos` array:**
156
+
157
+ Show: `Mapping ${repo.name}...`
158
+
159
+ Spawn 4 agents for this repo. Each agent's prompt includes `repo_path` and `repo_name` so it knows WHERE to explore and WHERE to write:
160
+
161
+ **Agent: Tech Focus (per repo)**
162
+
163
+ ```
164
+ Task(
165
+ subagent_type="dgs-codebase-mapper",
166
+ model="{mapper_model}",
167
+ run_in_background=true,
168
+ description="Map ${repo.name} tech stack",
169
+ prompt="Focus: tech
170
+ repo_path: ${repo.path}
171
+ repo_name: ${repo.name}
172
+
173
+ Analyze the codebase at ${repo.path} for technology stack and external integrations.
174
+
175
+ Write these documents to ${codebase_dir}/${repo.name}/:
176
+ - STACK.md - Languages, runtime, frameworks, dependencies, configuration
177
+ - INTEGRATIONS.md - External APIs, databases, auth providers, webhooks
178
+
179
+ Explore ${repo.path} thoroughly. Write documents directly using templates. Return confirmation only."
180
+ )
181
+ ```
182
+
183
+ **Agent: Architecture Focus (per repo)**
184
+
185
+ ```
186
+ Task(
187
+ subagent_type="dgs-codebase-mapper",
188
+ model="{mapper_model}",
189
+ run_in_background=true,
190
+ description="Map ${repo.name} architecture",
191
+ prompt="Focus: arch
192
+ repo_path: ${repo.path}
193
+ repo_name: ${repo.name}
194
+
195
+ Analyze the codebase at ${repo.path} for architecture and directory structure.
196
+
197
+ Write these documents to ${codebase_dir}/${repo.name}/:
198
+ - ARCHITECTURE.md - Pattern, layers, data flow, abstractions, entry points
199
+ - STRUCTURE.md - Directory layout, key locations, naming conventions
200
+
201
+ Explore ${repo.path} thoroughly. Write documents directly using templates. Return confirmation only."
202
+ )
203
+ ```
204
+
205
+ **Agent: Quality Focus (per repo)**
206
+
207
+ ```
208
+ Task(
209
+ subagent_type="dgs-codebase-mapper",
210
+ model="{mapper_model}",
211
+ run_in_background=true,
212
+ description="Map ${repo.name} conventions",
213
+ prompt="Focus: quality
214
+ repo_path: ${repo.path}
215
+ repo_name: ${repo.name}
216
+
217
+ Analyze the codebase at ${repo.path} for coding conventions and testing patterns.
218
+
219
+ Write these documents to ${codebase_dir}/${repo.name}/:
220
+ - CONVENTIONS.md - Code style, naming, patterns, error handling
221
+ - TESTING.md - Framework, structure, mocking, coverage
222
+
223
+ Explore ${repo.path} thoroughly. Write documents directly using templates. Return confirmation only."
224
+ )
225
+ ```
226
+
227
+ **Agent: Concerns Focus (per repo)**
228
+
229
+ ```
230
+ Task(
231
+ subagent_type="dgs-codebase-mapper",
232
+ model="{mapper_model}",
233
+ run_in_background=true,
234
+ description="Map ${repo.name} concerns",
235
+ prompt="Focus: concerns
236
+ repo_path: ${repo.path}
237
+ repo_name: ${repo.name}
238
+
239
+ Analyze the codebase at ${repo.path} for technical debt, known issues, and areas of concern.
240
+
241
+ Write this document to ${codebase_dir}/${repo.name}/:
242
+ - CONCERNS.md - Tech debt, bugs, security, performance, fragile areas
243
+
244
+ Explore ${repo.path} thoroughly. Write document directly using template. Return confirmation only."
245
+ )
246
+ ```
247
+
248
+ Continue to collect_confirmations.
249
+ </step>
250
+
251
+ <step name="collect_confirmations">
252
+ Wait for all agents across all repos to complete.
253
+
254
+ Read each agent's output to collect confirmations.
255
+
256
+ Track per-repo success/failure in a `results` map: `{ repo_name: "success" | "failed" }`.
257
+
258
+ For each repo, as all 4 of its agents complete:
259
+ - If all agents succeeded: mark repo as `"success"`, show: `Done: ${repo.name}`
260
+ - If any agent failed or repo path was inaccessible: mark repo as `"failed"`, show: `Failed: ${repo.name} -- [error reason]`
261
+
262
+ Continue with remaining repos regardless of individual failures.
263
+
264
+ **Expected confirmation format from each agent:**
265
+ ```
266
+ ## Mapping Complete
267
+
268
+ **Focus:** {focus}
269
+ **Documents written:**
270
+ - `${codebase_dir}/${repo.name}/{DOC1}.md` ({N} lines)
271
+ - `${codebase_dir}/${repo.name}/{DOC2}.md` ({N} lines)
272
+
273
+ Ready for orchestrator summary.
274
+ ```
275
+
276
+ If any agent failed, note the failure and continue with successful documents.
277
+
278
+ Continue to verify_output.
279
+ </step>
280
+
281
+ <step name="verify_output">
282
+ Verify all documents created successfully for each repo:
283
+
284
+ ```bash
285
+ for repo in ${valid_repos}; do
286
+ echo "--- ${repo} ---"
287
+ ls -la ${codebase_dir}/${repo}/
288
+ wc -l ${codebase_dir}/${repo}/*.md
289
+ done
290
+ ```
291
+
292
+ **Verification checklist (per repo):**
293
+ - All 7 documents exist
294
+ - No empty documents (each should have >20 lines)
295
+
296
+ If any documents missing or empty, note which agents may have failed.
297
+
298
+ Continue to synthesize_unified.
299
+ </step>
300
+
301
+ <step name="synthesize_unified">
302
+ Synthesize unified top-level codebase files from per-repo content.
303
+
304
+ **If ALL repos failed:** Skip synthesis entirely. Show: `All repos failed. No unified files generated.` Continue to offer_next.
305
+
306
+ **Determine repo list for synthesis:**
307
+ - **Refresh mode:** Use all successful repos from the results map.
308
+ - **Update mode:** Use ALL repos that have per-repo subdirectories (not just the one being updated). The synthesizer needs content from all repos to produce complete unified files.
309
+
310
+ ```bash
311
+ # Build list of repos with content for synthesis
312
+ SYNTH_REPOS=""
313
+ for dir in ${codebase_dir}/*/; do
314
+ REPO_NAME=$(basename "$dir")
315
+ SYNTH_REPOS="$SYNTH_REPOS $REPO_NAME"
316
+ done
317
+ ```
318
+
319
+ Show: `Synthesizing unified codebase files...`
320
+
321
+ Spawn 7 parallel dgs-codebase-synthesizer agents (one per document type), all with `run_in_background=true`. Each agent produces one unified top-level file.
322
+
323
+ **Document types:** ARCHITECTURE, STACK, STRUCTURE, CONVENTIONS, TESTING, INTEGRATIONS, CONCERNS
324
+
325
+ **For each doc_type, spawn:**
326
+
327
+ ```
328
+ Task(
329
+ subagent_type="dgs-codebase-synthesizer",
330
+ model="{mapper_model}",
331
+ run_in_background=true,
332
+ description="Synthesize unified ${doc_type}",
333
+ prompt="doc_type: ${doc_type}
334
+ codebase_dir: ${codebase_dir}
335
+ repo_names: ${JSON.stringify(synth_repos)}
336
+
337
+ Read per-repo ${doc_type}.md files from each repo subdirectory in ${codebase_dir}/ and synthesize a unified ${codebase_dir}/${doc_type}.md.
338
+
339
+ Include provenance header, conditional cross-repo summary (multi-repo only), and labeled repo sections. Return confirmation only."
340
+ )
341
+ ```
342
+
343
+ Wait for all 7 agents to complete.
344
+
345
+ Verify all 7 unified files exist:
346
+
347
+ ```bash
348
+ for doc in ARCHITECTURE STACK STRUCTURE CONVENTIONS TESTING INTEGRATIONS CONCERNS; do
349
+ test -f ${codebase_dir}/${doc}.md && echo "OK: ${doc}.md" || echo "MISSING: ${doc}.md"
350
+ done
351
+ ```
352
+
353
+ Show: `Unified files generated.`
354
+
355
+ Continue to generate_cross_repo.
356
+ </step>
357
+
358
+ <step name="generate_cross_repo">
359
+ Generate CROSS-REPO.md with cross-repo analysis (comparison tables for shared dependencies, API boundaries, common/divergent patterns).
360
+
361
+ **Guard check:** If `synth_repos` has fewer than 2 repos, skip this step entirely. Delete any existing CROSS-REPO.md left from a previous multi-repo run:
362
+
363
+ ```bash
364
+ rm -f ${codebase_dir}/CROSS-REPO.md
365
+ ```
366
+
367
+ **If 2+ repos:** Spawn a single cross-analyzer agent (NOT parallel -- it needs cross-repo context):
368
+
369
+ ```
370
+ Task(
371
+ subagent_type="dgs-codebase-cross-analyzer",
372
+ model="{mapper_model}",
373
+ description="Generate cross-repo analysis",
374
+ prompt="codebase_dir: ${codebase_dir}
375
+ repo_names: ${JSON.stringify(synth_repos)}
376
+
377
+ Read per-repo documents from each ${codebase_dir}/<repo>/ subdirectory.
378
+ Compare across repos to identify:
379
+ 1. Shared dependencies (exact package matches from STACK.md)
380
+ 2. API boundaries (from ARCHITECTURE.md and INTEGRATIONS.md)
381
+ 3. Common patterns (from CONVENTIONS.md, ARCHITECTURE.md, TESTING.md)
382
+ 4. Divergent patterns (same sources, items that differ)
383
+
384
+ Write ${codebase_dir}/CROSS-REPO.md with comparison tables.
385
+ Do NOT explore repo paths directly. Work only from per-repo maps."
386
+ )
387
+ ```
388
+
389
+ Wait for agent to complete. Show: `Cross-repo analysis generated.`
390
+
391
+ Continue to verify_compatibility.
392
+ </step>
393
+
394
+ <step name="verify_compatibility">
395
+ Verify that unified files are compatible with all consumer workflows (write-spec, refine-spec, import-spec, new-project, plan-phase, find-related-ideas, execute-plan). These consumers expect files at `${codebase_dir}/*.md` -- either by exact path (e.g., `${codebase_dir}/ARCHITECTURE.md`) or by glob (e.g., `ls ${codebase_dir}/*.md`).
396
+
397
+ **1. Check all 7 unified files exist:**
398
+
399
+ ```bash
400
+ EXPECTED="ARCHITECTURE CONCERNS CONVENTIONS INTEGRATIONS STACK STRUCTURE TESTING"
401
+ MISSING=""
402
+ for doc in $EXPECTED; do
403
+ test -f ${codebase_dir}/${doc}.md || MISSING="$MISSING $doc"
404
+ done
405
+ if [ -n "$MISSING" ]; then
406
+ echo "WARNING: Missing unified files:$MISSING"
407
+ fi
408
+ ```
409
+
410
+ **2. Check provenance headers:**
411
+
412
+ Each unified file must have a provenance comment on the first line (written by the synthesizer agent):
413
+
414
+ ```bash
415
+ for doc in ${codebase_dir}/*.md; do
416
+ head -1 "$doc" | grep -q "Synthesized:" || echo "WARNING: $doc missing provenance header"
417
+ done
418
+ ```
419
+
420
+ **3. Check minimum viable content:**
421
+
422
+ Each unified file should have meaningful content (>10 lines):
423
+
424
+ ```bash
425
+ for doc in ${codebase_dir}/*.md; do
426
+ LINES=$(wc -l < "$doc")
427
+ [ "$LINES" -lt 10 ] && echo "WARNING: $doc only has $LINES lines"
428
+ done
429
+ ```
430
+
431
+ **4. Check CROSS-REPO.md (conditional):**
432
+
433
+ If 2+ repos were mapped (synth_repos has 2+ entries), verify CROSS-REPO.md exists:
434
+
435
+ ```bash
436
+ # Verify CROSS-REPO.md exists when 2+ repos were mapped
437
+ if [ ${#synth_repos[@]} -ge 2 ]; then
438
+ test -f ${codebase_dir}/CROSS-REPO.md || echo "WARNING: CROSS-REPO.md missing (expected for multi-repo)"
439
+ fi
440
+ ```
441
+
442
+ If any warnings were emitted, log them but continue -- these are non-blocking warnings that help diagnose synthesis issues.
443
+
444
+ Continue to scan_for_secrets.
445
+ </step>
446
+
447
+ <step name="scan_for_secrets">
448
+ **CRITICAL SECURITY CHECK:** Scan output files for accidentally leaked secrets before committing.
449
+
450
+ Silent when clean -- only produces output if potential secrets are detected. Warn-only in all modes (never halts the workflow).
451
+
452
+ ```
453
+ Secret pattern categories:
454
+ - API keys: OpenAI (sk-), Stripe (sk_live_, sk_test_)
455
+ - Platform tokens: GitHub (ghp_, gho_), GitLab (glpat-), Slack (xox)
456
+ - Cloud credentials: AWS access keys (AKIA)
457
+ - Cryptographic: Private keys (BEGIN PRIVATE KEY), JWTs (eyJ)
458
+ - Connection strings: PostgreSQL, MongoDB, MySQL, Redis, AMQP with embedded credentials
459
+ - Hardcoded secrets: Password assignments with 8+ char values
460
+ ```
461
+
462
+ ```bash
463
+ # Build comprehensive secret detection pattern
464
+ SECRET_PATTERN='(sk-[a-zA-Z0-9]{20,}|sk_live_[a-zA-Z0-9]+|sk_test_[a-zA-Z0-9]+|ghp_[a-zA-Z0-9]{36}|gho_[a-zA-Z0-9]{36}|glpat-[a-zA-Z0-9_-]+|AKIA[A-Z0-9]{16}|xox[baprs]-[a-zA-Z0-9-]+|-----BEGIN.*PRIVATE KEY|eyJ[a-zA-Z0-9_-]+\.eyJ[a-zA-Z0-9_-]+\.|postgresql://[^:]+:[^@]+@|mongodb(\+srv)?://[^:]+:[^@]+@|mysql://[^:]+:[^@]+@|redis://:[^@]+@|amqp://[^:]+:[^@]+@|[pP]assword\s*[:=]\s*['"'"'"][^'"'"'"]{8,})'
465
+
466
+ SECRETS_OUTPUT=""
467
+
468
+ # Determine which repos to scan based on mode
469
+ # Refresh mode: scan all valid_repos
470
+ # Update mode: scan only the targeted repo
471
+ if [ "${mode}" = "update" ]; then
472
+ repos_to_scan="${only_repo}"
473
+ else
474
+ repos_to_scan="${valid_repos}"
475
+ fi
476
+
477
+ # Scan per-repo files
478
+ for repo in ${repos_to_scan}; do
479
+ FOUND=$(grep -nE "$SECRET_PATTERN" ${codebase_dir}/${repo}/*.md 2>/dev/null || true)
480
+ if [ -n "$FOUND" ]; then
481
+ SECRETS_OUTPUT="${SECRETS_OUTPUT}\n--- ${repo} ---\n${FOUND}"
482
+ fi
483
+ done
484
+
485
+ # Scan unified top-level files (always, regardless of mode)
486
+ FOUND=$(grep -nE "$SECRET_PATTERN" ${codebase_dir}/*.md 2>/dev/null || true)
487
+ if [ -n "$FOUND" ]; then
488
+ SECRETS_OUTPUT="${SECRETS_OUTPUT}\n--- unified ---\n${FOUND}"
489
+ fi
490
+
491
+ # Only show output if secrets found (silent when clean)
492
+ if [ -n "$SECRETS_OUTPUT" ]; then
493
+ echo "WARNING: Potential secrets detected in codebase files:"
494
+ echo -e "$SECRETS_OUTPUT"
495
+ echo ""
496
+ echo "Review these files before committing. Secrets are left as-is -- review and redact manually if needed."
497
+ fi
498
+ ```
499
+
500
+ **Behavior (all modes):**
501
+ - If secrets found: show warning with file + line numbers, continue to commit
502
+ - If no secrets found: produce no output (silent when clean)
503
+ - Never halts the workflow
504
+
505
+ Continue to commit_codebase_map.
506
+ </step>
507
+
508
+ <step name="commit_codebase_map">
509
+ Commit the codebase maps for all repos:
510
+
511
+ ```bash
512
+ node ~/.claude/deliver-great-systems/bin/dgs-tools.cjs commit "docs: map codebase for registered repos" --files ${codebase_dir}/
513
+ ```
514
+
515
+ Continue to offer_next.
516
+ </step>
517
+
518
+ <step name="offer_next">
519
+ Present completion summary and next steps.
520
+
521
+ **Mapping summary (before file listing):**
522
+
523
+ ```
524
+ Mapping summary:
525
+ - Mode: [refresh | update (only_repo)]
526
+ - Repos mapped: N of M
527
+ [For each repo: success_mark repo-name or fail_mark repo-name (reason)]
528
+ ```
529
+
530
+ Use checkmarks for success and X marks for failure.
531
+
532
+ **Get line counts per repo and unified files:**
533
+ ```bash
534
+ for repo in ${valid_repos}; do
535
+ echo "--- ${repo} ---"
536
+ wc -l ${codebase_dir}/${repo}/*.md
537
+ done
538
+ echo "--- Unified ---"
539
+ wc -l ${codebase_dir}/*.md
540
+ ```
541
+
542
+ **Output format:**
543
+
544
+ ```
545
+ Codebase mapping complete.
546
+
547
+ Mapping summary:
548
+ - Mode: [refresh | update (only_repo)]
549
+ - Repos mapped: N of M
550
+ [For each repo: checkmark/X repo-name]
551
+
552
+ [For each repo:]
553
+ ${repo.name} (${codebase_dir}/${repo.name}/):
554
+ - STACK.md ([N] lines) - Technologies and dependencies
555
+ - ARCHITECTURE.md ([N] lines) - System design and patterns
556
+ - STRUCTURE.md ([N] lines) - Directory layout and organization
557
+ - CONVENTIONS.md ([N] lines) - Code style and patterns
558
+ - TESTING.md ([N] lines) - Test structure and practices
559
+ - INTEGRATIONS.md ([N] lines) - External services and APIs
560
+ - CONCERNS.md ([N] lines) - Technical debt and issues
561
+
562
+ Unified files (${codebase_dir}/):
563
+ - ARCHITECTURE.md ([N] lines) - Synthesized architecture across all repos
564
+ - STACK.md ([N] lines) - Synthesized technology stack across all repos
565
+ - STRUCTURE.md ([N] lines) - Synthesized codebase structure across all repos
566
+ - CONVENTIONS.md ([N] lines) - Synthesized coding conventions across all repos
567
+ - TESTING.md ([N] lines) - Synthesized testing patterns across all repos
568
+ - INTEGRATIONS.md ([N] lines) - Synthesized external integrations across all repos
569
+ - CONCERNS.md ([N] lines) - Synthesized codebase concerns across all repos
570
+
571
+ [If CROSS-REPO.md exists (2+ repos):]
572
+ Cross-repo analysis (${codebase_dir}/):
573
+ - CROSS-REPO.md ([N] lines) - Shared dependencies, API boundaries, pattern comparison
574
+
575
+ ---
576
+
577
+ ## Next Up
578
+
579
+ **Initialize project** — use codebase context for planning
580
+
581
+ `/dgs:new-project`
582
+
583
+ <sub>`/clear` first -> fresh context window</sub>
584
+
585
+ ---
586
+
587
+ **Also available:**
588
+ - Re-run mapping: `/dgs:map-codebase`
589
+ - Update a single repo: `/dgs:map-codebase --only <repo-name>`
590
+ - Review specific repo: `cat ${codebase_dir}/<repo>/STACK.md`
591
+ - Review unified files: `cat ${codebase_dir}/ARCHITECTURE.md`
592
+ - Review cross-repo analysis: `cat ${codebase_dir}/CROSS-REPO.md`
593
+ - Edit any document before proceeding
594
+
595
+ ---
596
+ ```
597
+
598
+ End workflow.
599
+ </step>
600
+
601
+ </process>
602
+
603
+ <success_criteria>
604
+ - Per-repo subdirectories created at ${codebase_dir}/<repo-name>/
605
+ - 4 parallel dgs-codebase-mapper agents spawned per repo with run_in_background=true
606
+ - Agents explore repo_path (not planning repo) and write documents directly
607
+ - Read agent output files to collect per-repo confirmations
608
+ - All 7 codebase documents exist per repo
609
+ - Per-repo progress announcements shown
610
+ - 7 parallel dgs-codebase-synthesizer agents produce unified top-level files
611
+ - All 7 unified files exist at ${codebase_dir}/*.md
612
+ - Compatibility verification checks file existence, provenance headers, and minimum content
613
+ - Secret scanning covers both per-repo and unified files
614
+ - Commit captures all codebase content (per-repo and unified)
615
+ - Clear completion summary with per-repo and unified file line counts
616
+ - User offered clear next steps in DGS style
617
+ - Error handling: failed repos skipped, remaining repos continue
618
+ - End-of-run summary with success/fail counts
619
+ - Mode-aware cleanup (refresh wipes all, update wipes only target repo)
620
+ - Cross-repo analysis generated for 2+ repos (CROSS-REPO.md)
621
+ </success_criteria>