gsd-remix 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (554) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +939 -0
  3. package/README.zh-CN.md +876 -0
  4. package/agents/gsd-advisor-researcher.md +127 -0
  5. package/agents/gsd-ai-researcher.md +133 -0
  6. package/agents/gsd-assumptions-analyzer.md +105 -0
  7. package/agents/gsd-code-fixer.md +517 -0
  8. package/agents/gsd-code-reviewer.md +371 -0
  9. package/agents/gsd-codebase-mapper.md +781 -0
  10. package/agents/gsd-debug-session-manager.md +314 -0
  11. package/agents/gsd-debugger.md +1452 -0
  12. package/agents/gsd-doc-classifier.md +168 -0
  13. package/agents/gsd-doc-synthesizer.md +204 -0
  14. package/agents/gsd-doc-verifier.md +217 -0
  15. package/agents/gsd-doc-writer.md +615 -0
  16. package/agents/gsd-domain-researcher.md +153 -0
  17. package/agents/gsd-eval-auditor.md +191 -0
  18. package/agents/gsd-eval-planner.md +154 -0
  19. package/agents/gsd-executor.md +603 -0
  20. package/agents/gsd-framework-selector.md +160 -0
  21. package/agents/gsd-integration-checker.md +470 -0
  22. package/agents/gsd-intel-updater.md +334 -0
  23. package/agents/gsd-nyquist-auditor.md +203 -0
  24. package/agents/gsd-pattern-mapper.md +335 -0
  25. package/agents/gsd-phase-researcher.md +841 -0
  26. package/agents/gsd-plan-checker.md +978 -0
  27. package/agents/gsd-planner.md +1251 -0
  28. package/agents/gsd-project-researcher.md +677 -0
  29. package/agents/gsd-research-synthesizer.md +247 -0
  30. package/agents/gsd-roadmapper.md +688 -0
  31. package/agents/gsd-security-auditor.md +155 -0
  32. package/agents/gsd-ui-auditor.md +495 -0
  33. package/agents/gsd-ui-checker.md +309 -0
  34. package/agents/gsd-ui-researcher.md +380 -0
  35. package/agents/gsd-user-profiler.md +171 -0
  36. package/agents/gsd-verifier.md +830 -0
  37. package/bin/install.js +7062 -0
  38. package/commands/gsd/add-backlog.md +79 -0
  39. package/commands/gsd/add-phase.md +43 -0
  40. package/commands/gsd/add-tests.md +41 -0
  41. package/commands/gsd/add-todo.md +47 -0
  42. package/commands/gsd/ai-integration-phase.md +36 -0
  43. package/commands/gsd/analyze-dependencies.md +34 -0
  44. package/commands/gsd/audit-fix.md +33 -0
  45. package/commands/gsd/audit-milestone.md +36 -0
  46. package/commands/gsd/audit-uat.md +24 -0
  47. package/commands/gsd/autonomous.md +46 -0
  48. package/commands/gsd/check-todos.md +45 -0
  49. package/commands/gsd/cleanup.md +23 -0
  50. package/commands/gsd/code-review-fix.md +52 -0
  51. package/commands/gsd/code-review.md +55 -0
  52. package/commands/gsd/complete-milestone.md +136 -0
  53. package/commands/gsd/debug.md +263 -0
  54. package/commands/gsd/discuss-phase.md +69 -0
  55. package/commands/gsd/do.md +30 -0
  56. package/commands/gsd/docs-update.md +48 -0
  57. package/commands/gsd/eval-review.md +32 -0
  58. package/commands/gsd/execute-phase.md +63 -0
  59. package/commands/gsd/explore.md +27 -0
  60. package/commands/gsd/extract_learnings.md +22 -0
  61. package/commands/gsd/fast.md +30 -0
  62. package/commands/gsd/forensics.md +56 -0
  63. package/commands/gsd/from-gsd2.md +47 -0
  64. package/commands/gsd/graphify.md +201 -0
  65. package/commands/gsd/health.md +22 -0
  66. package/commands/gsd/help.md +24 -0
  67. package/commands/gsd/import.md +37 -0
  68. package/commands/gsd/inbox.md +38 -0
  69. package/commands/gsd/ingest-docs.md +42 -0
  70. package/commands/gsd/insert-phase.md +32 -0
  71. package/commands/gsd/intel.md +179 -0
  72. package/commands/gsd/join-discord.md +19 -0
  73. package/commands/gsd/list-phase-assumptions.md +46 -0
  74. package/commands/gsd/list-workspaces.md +19 -0
  75. package/commands/gsd/manager.md +40 -0
  76. package/commands/gsd/map-codebase.md +71 -0
  77. package/commands/gsd/milestone-summary.md +51 -0
  78. package/commands/gsd/new-milestone.md +44 -0
  79. package/commands/gsd/new-project.md +46 -0
  80. package/commands/gsd/new-workspace.md +44 -0
  81. package/commands/gsd/next.md +28 -0
  82. package/commands/gsd/note.md +34 -0
  83. package/commands/gsd/pause-work.md +38 -0
  84. package/commands/gsd/plan-milestone-gaps.md +34 -0
  85. package/commands/gsd/plan-phase.md +52 -0
  86. package/commands/gsd/plan-review-convergence.md +52 -0
  87. package/commands/gsd/plant-seed.md +28 -0
  88. package/commands/gsd/pr-branch.md +25 -0
  89. package/commands/gsd/profile-user.md +46 -0
  90. package/commands/gsd/progress.md +25 -0
  91. package/commands/gsd/quick.md +173 -0
  92. package/commands/gsd/reapply-patches.md +331 -0
  93. package/commands/gsd/remove-phase.md +31 -0
  94. package/commands/gsd/remove-workspace.md +26 -0
  95. package/commands/gsd/research-phase.md +195 -0
  96. package/commands/gsd/resume-work.md +40 -0
  97. package/commands/gsd/review-backlog.md +62 -0
  98. package/commands/gsd/review.md +40 -0
  99. package/commands/gsd/scan.md +26 -0
  100. package/commands/gsd/secure-phase.md +35 -0
  101. package/commands/gsd/session-report.md +19 -0
  102. package/commands/gsd/set-profile.md +12 -0
  103. package/commands/gsd/settings.md +36 -0
  104. package/commands/gsd/ship.md +23 -0
  105. package/commands/gsd/sketch-wrap-up.md +31 -0
  106. package/commands/gsd/sketch.md +49 -0
  107. package/commands/gsd/spec-phase.md +62 -0
  108. package/commands/gsd/spike-wrap-up.md +31 -0
  109. package/commands/gsd/spike.md +46 -0
  110. package/commands/gsd/stats.md +18 -0
  111. package/commands/gsd/sync-skills.md +19 -0
  112. package/commands/gsd/thread.md +227 -0
  113. package/commands/gsd/ui-phase.md +34 -0
  114. package/commands/gsd/ui-review.md +32 -0
  115. package/commands/gsd/ultraplan-phase.md +33 -0
  116. package/commands/gsd/undo.md +34 -0
  117. package/commands/gsd/update.md +37 -0
  118. package/commands/gsd/validate-phase.md +35 -0
  119. package/commands/gsd/verify-work.md +38 -0
  120. package/commands/gsd/workstreams.md +69 -0
  121. package/get-shit-done/bin/gsd-tools.cjs +1263 -0
  122. package/get-shit-done/bin/lib/artifacts.cjs +52 -0
  123. package/get-shit-done/bin/lib/audit.cjs +757 -0
  124. package/get-shit-done/bin/lib/commands.cjs +1023 -0
  125. package/get-shit-done/bin/lib/config-schema.cjs +79 -0
  126. package/get-shit-done/bin/lib/config.cjs +463 -0
  127. package/get-shit-done/bin/lib/core.cjs +1794 -0
  128. package/get-shit-done/bin/lib/docs.cjs +267 -0
  129. package/get-shit-done/bin/lib/frontmatter.cjs +379 -0
  130. package/get-shit-done/bin/lib/graphify.cjs +494 -0
  131. package/get-shit-done/bin/lib/gsd2-import.cjs +511 -0
  132. package/get-shit-done/bin/lib/init.cjs +1878 -0
  133. package/get-shit-done/bin/lib/intel.cjs +639 -0
  134. package/get-shit-done/bin/lib/learnings.cjs +378 -0
  135. package/get-shit-done/bin/lib/milestone.cjs +283 -0
  136. package/get-shit-done/bin/lib/model-profiles.cjs +71 -0
  137. package/get-shit-done/bin/lib/phase.cjs +1058 -0
  138. package/get-shit-done/bin/lib/profile-output.cjs +1080 -0
  139. package/get-shit-done/bin/lib/profile-pipeline.cjs +539 -0
  140. package/get-shit-done/bin/lib/roadmap.cjs +523 -0
  141. package/get-shit-done/bin/lib/schema-detect.cjs +238 -0
  142. package/get-shit-done/bin/lib/security.cjs +504 -0
  143. package/get-shit-done/bin/lib/state.cjs +1649 -0
  144. package/get-shit-done/bin/lib/template.cjs +226 -0
  145. package/get-shit-done/bin/lib/uat.cjs +288 -0
  146. package/get-shit-done/bin/lib/verify.cjs +1184 -0
  147. package/get-shit-done/bin/lib/workstream.cjs +495 -0
  148. package/get-shit-done/bin/repair-sdk.cjs +177 -0
  149. package/get-shit-done/contexts/dev.md +21 -0
  150. package/get-shit-done/contexts/research.md +22 -0
  151. package/get-shit-done/contexts/review.md +22 -0
  152. package/get-shit-done/references/agent-contracts.md +79 -0
  153. package/get-shit-done/references/ai-evals.md +156 -0
  154. package/get-shit-done/references/ai-frameworks.md +186 -0
  155. package/get-shit-done/references/artifact-types.md +131 -0
  156. package/get-shit-done/references/autonomous-smart-discuss.md +277 -0
  157. package/get-shit-done/references/checkpoints.md +808 -0
  158. package/get-shit-done/references/common-bug-patterns.md +114 -0
  159. package/get-shit-done/references/context-budget.md +49 -0
  160. package/get-shit-done/references/continuation-format.md +253 -0
  161. package/get-shit-done/references/debugger-philosophy.md +76 -0
  162. package/get-shit-done/references/decimal-phase-calculation.md +64 -0
  163. package/get-shit-done/references/doc-conflict-engine.md +91 -0
  164. package/get-shit-done/references/domain-probes.md +125 -0
  165. package/get-shit-done/references/executor-examples.md +110 -0
  166. package/get-shit-done/references/few-shot-examples/plan-checker.md +73 -0
  167. package/get-shit-done/references/few-shot-examples/verifier.md +109 -0
  168. package/get-shit-done/references/gate-prompts.md +100 -0
  169. package/get-shit-done/references/gates.md +70 -0
  170. package/get-shit-done/references/git-integration.md +295 -0
  171. package/get-shit-done/references/git-planning-commit.md +40 -0
  172. package/get-shit-done/references/ios-scaffold.md +123 -0
  173. package/get-shit-done/references/mandatory-initial-read.md +2 -0
  174. package/get-shit-done/references/model-profile-resolution.md +38 -0
  175. package/get-shit-done/references/model-profiles.md +145 -0
  176. package/get-shit-done/references/phase-argument-parsing.md +61 -0
  177. package/get-shit-done/references/planner-antipatterns.md +89 -0
  178. package/get-shit-done/references/planner-gap-closure.md +62 -0
  179. package/get-shit-done/references/planner-reviews.md +39 -0
  180. package/get-shit-done/references/planner-revision.md +87 -0
  181. package/get-shit-done/references/planner-source-audit.md +73 -0
  182. package/get-shit-done/references/planning-config.md +460 -0
  183. package/get-shit-done/references/project-skills-discovery.md +19 -0
  184. package/get-shit-done/references/questioning.md +162 -0
  185. package/get-shit-done/references/revision-loop.md +97 -0
  186. package/get-shit-done/references/sketch-interactivity.md +41 -0
  187. package/get-shit-done/references/sketch-theme-system.md +94 -0
  188. package/get-shit-done/references/sketch-tooling.md +45 -0
  189. package/get-shit-done/references/sketch-variant-patterns.md +81 -0
  190. package/get-shit-done/references/tdd.md +330 -0
  191. package/get-shit-done/references/thinking-models-debug.md +44 -0
  192. package/get-shit-done/references/thinking-models-execution.md +50 -0
  193. package/get-shit-done/references/thinking-models-planning.md +62 -0
  194. package/get-shit-done/references/thinking-models-research.md +50 -0
  195. package/get-shit-done/references/thinking-models-verification.md +55 -0
  196. package/get-shit-done/references/thinking-partner.md +96 -0
  197. package/get-shit-done/references/ui-brand.md +160 -0
  198. package/get-shit-done/references/universal-anti-patterns.md +63 -0
  199. package/get-shit-done/references/user-profiling.md +681 -0
  200. package/get-shit-done/references/verification-overrides.md +227 -0
  201. package/get-shit-done/references/verification-patterns.md +612 -0
  202. package/get-shit-done/references/workstream-flag.md +111 -0
  203. package/get-shit-done/templates/AI-SPEC.md +246 -0
  204. package/get-shit-done/templates/DEBUG.md +169 -0
  205. package/get-shit-done/templates/README.md +76 -0
  206. package/get-shit-done/templates/SECURITY.md +61 -0
  207. package/get-shit-done/templates/UAT.md +265 -0
  208. package/get-shit-done/templates/UI-SPEC.md +100 -0
  209. package/get-shit-done/templates/VALIDATION.md +76 -0
  210. package/get-shit-done/templates/claude-md.md +145 -0
  211. package/get-shit-done/templates/codebase/architecture.md +255 -0
  212. package/get-shit-done/templates/codebase/concerns.md +310 -0
  213. package/get-shit-done/templates/codebase/conventions.md +307 -0
  214. package/get-shit-done/templates/codebase/integrations.md +280 -0
  215. package/get-shit-done/templates/codebase/stack.md +186 -0
  216. package/get-shit-done/templates/codebase/structure.md +285 -0
  217. package/get-shit-done/templates/codebase/testing.md +480 -0
  218. package/get-shit-done/templates/config.json +56 -0
  219. package/get-shit-done/templates/context.md +352 -0
  220. package/get-shit-done/templates/continue-here.md +78 -0
  221. package/get-shit-done/templates/copilot-instructions.md +7 -0
  222. package/get-shit-done/templates/debug-subagent-prompt.md +91 -0
  223. package/get-shit-done/templates/dev-preferences.md +21 -0
  224. package/get-shit-done/templates/discovery.md +146 -0
  225. package/get-shit-done/templates/discussion-log.md +63 -0
  226. package/get-shit-done/templates/milestone-archive.md +123 -0
  227. package/get-shit-done/templates/milestone.md +115 -0
  228. package/get-shit-done/templates/phase-prompt.md +610 -0
  229. package/get-shit-done/templates/planner-subagent-prompt.md +117 -0
  230. package/get-shit-done/templates/project.md +186 -0
  231. package/get-shit-done/templates/requirements.md +231 -0
  232. package/get-shit-done/templates/research-project/ARCHITECTURE.md +204 -0
  233. package/get-shit-done/templates/research-project/FEATURES.md +147 -0
  234. package/get-shit-done/templates/research-project/PITFALLS.md +200 -0
  235. package/get-shit-done/templates/research-project/STACK.md +120 -0
  236. package/get-shit-done/templates/research-project/SUMMARY.md +170 -0
  237. package/get-shit-done/templates/research.md +592 -0
  238. package/get-shit-done/templates/retrospective.md +54 -0
  239. package/get-shit-done/templates/roadmap.md +202 -0
  240. package/get-shit-done/templates/spec.md +307 -0
  241. package/get-shit-done/templates/state.md +184 -0
  242. package/get-shit-done/templates/summary-complex.md +59 -0
  243. package/get-shit-done/templates/summary-minimal.md +41 -0
  244. package/get-shit-done/templates/summary-standard.md +48 -0
  245. package/get-shit-done/templates/summary.md +248 -0
  246. package/get-shit-done/templates/user-profile.md +146 -0
  247. package/get-shit-done/templates/user-setup.md +311 -0
  248. package/get-shit-done/templates/verification-report.md +322 -0
  249. package/get-shit-done/workflows/add-phase.md +112 -0
  250. package/get-shit-done/workflows/add-tests.md +354 -0
  251. package/get-shit-done/workflows/add-todo.md +160 -0
  252. package/get-shit-done/workflows/ai-integration-phase.md +284 -0
  253. package/get-shit-done/workflows/analyze-dependencies.md +96 -0
  254. package/get-shit-done/workflows/audit-fix.md +175 -0
  255. package/get-shit-done/workflows/audit-milestone.md +340 -0
  256. package/get-shit-done/workflows/audit-uat.md +109 -0
  257. package/get-shit-done/workflows/autonomous.md +789 -0
  258. package/get-shit-done/workflows/check-todos.md +179 -0
  259. package/get-shit-done/workflows/cleanup.md +154 -0
  260. package/get-shit-done/workflows/code-review-fix.md +497 -0
  261. package/get-shit-done/workflows/code-review.md +515 -0
  262. package/get-shit-done/workflows/complete-milestone.md +847 -0
  263. package/get-shit-done/workflows/diagnose-issues.md +238 -0
  264. package/get-shit-done/workflows/discovery-phase.md +291 -0
  265. package/get-shit-done/workflows/discuss-phase-assumptions.md +670 -0
  266. package/get-shit-done/workflows/discuss-phase-power.md +308 -0
  267. package/get-shit-done/workflows/discuss-phase.md +1378 -0
  268. package/get-shit-done/workflows/do.md +110 -0
  269. package/get-shit-done/workflows/docs-update.md +1155 -0
  270. package/get-shit-done/workflows/eval-review.md +155 -0
  271. package/get-shit-done/workflows/execute-phase.md +1677 -0
  272. package/get-shit-done/workflows/execute-plan.md +533 -0
  273. package/get-shit-done/workflows/explore.md +141 -0
  274. package/get-shit-done/workflows/extract_learnings.md +242 -0
  275. package/get-shit-done/workflows/fast.md +105 -0
  276. package/get-shit-done/workflows/forensics.md +265 -0
  277. package/get-shit-done/workflows/graduation.md +195 -0
  278. package/get-shit-done/workflows/health.md +314 -0
  279. package/get-shit-done/workflows/help.md +667 -0
  280. package/get-shit-done/workflows/import.md +246 -0
  281. package/get-shit-done/workflows/inbox.md +387 -0
  282. package/get-shit-done/workflows/ingest-docs.md +328 -0
  283. package/get-shit-done/workflows/insert-phase.md +130 -0
  284. package/get-shit-done/workflows/list-phase-assumptions.md +178 -0
  285. package/get-shit-done/workflows/list-workspaces.md +56 -0
  286. package/get-shit-done/workflows/manager.md +365 -0
  287. package/get-shit-done/workflows/map-codebase.md +393 -0
  288. package/get-shit-done/workflows/milestone-summary.md +223 -0
  289. package/get-shit-done/workflows/new-milestone.md +611 -0
  290. package/get-shit-done/workflows/new-project.md +1391 -0
  291. package/get-shit-done/workflows/new-workspace.md +239 -0
  292. package/get-shit-done/workflows/next.md +220 -0
  293. package/get-shit-done/workflows/node-repair.md +92 -0
  294. package/get-shit-done/workflows/note.md +158 -0
  295. package/get-shit-done/workflows/pause-work.md +243 -0
  296. package/get-shit-done/workflows/plan-milestone-gaps.md +273 -0
  297. package/get-shit-done/workflows/plan-phase.md +1349 -0
  298. package/get-shit-done/workflows/plan-review-convergence.md +254 -0
  299. package/get-shit-done/workflows/plant-seed.md +172 -0
  300. package/get-shit-done/workflows/pr-branch.md +157 -0
  301. package/get-shit-done/workflows/profile-user.md +452 -0
  302. package/get-shit-done/workflows/progress.md +619 -0
  303. package/get-shit-done/workflows/quick.md +970 -0
  304. package/get-shit-done/workflows/remove-phase.md +155 -0
  305. package/get-shit-done/workflows/remove-workspace.md +92 -0
  306. package/get-shit-done/workflows/research-phase.md +89 -0
  307. package/get-shit-done/workflows/resume-project.md +326 -0
  308. package/get-shit-done/workflows/review.md +344 -0
  309. package/get-shit-done/workflows/scan.md +102 -0
  310. package/get-shit-done/workflows/secure-phase.md +166 -0
  311. package/get-shit-done/workflows/session-report.md +146 -0
  312. package/get-shit-done/workflows/settings.md +319 -0
  313. package/get-shit-done/workflows/ship.md +302 -0
  314. package/get-shit-done/workflows/sketch-wrap-up.md +283 -0
  315. package/get-shit-done/workflows/sketch.md +286 -0
  316. package/get-shit-done/workflows/spec-phase.md +262 -0
  317. package/get-shit-done/workflows/spike-wrap-up.md +281 -0
  318. package/get-shit-done/workflows/spike.md +362 -0
  319. package/get-shit-done/workflows/stats.md +60 -0
  320. package/get-shit-done/workflows/sync-skills.md +182 -0
  321. package/get-shit-done/workflows/transition.md +693 -0
  322. package/get-shit-done/workflows/ui-phase.md +323 -0
  323. package/get-shit-done/workflows/ui-review.md +190 -0
  324. package/get-shit-done/workflows/ultraplan-phase.md +189 -0
  325. package/get-shit-done/workflows/undo.md +314 -0
  326. package/get-shit-done/workflows/update.md +587 -0
  327. package/get-shit-done/workflows/validate-phase.md +176 -0
  328. package/get-shit-done/workflows/verify-phase.md +465 -0
  329. package/get-shit-done/workflows/verify-work.md +740 -0
  330. package/hooks/dist/gsd-check-update-worker.js +108 -0
  331. package/hooks/dist/gsd-check-update.js +64 -0
  332. package/hooks/dist/gsd-context-monitor.js +192 -0
  333. package/hooks/dist/gsd-phase-boundary.sh +28 -0
  334. package/hooks/dist/gsd-prompt-guard.js +97 -0
  335. package/hooks/dist/gsd-read-guard.js +82 -0
  336. package/hooks/dist/gsd-read-injection-scanner.js +152 -0
  337. package/hooks/dist/gsd-session-state.sh +34 -0
  338. package/hooks/dist/gsd-statusline.js +293 -0
  339. package/hooks/dist/gsd-validate-commit.sh +48 -0
  340. package/hooks/dist/gsd-workflow-guard.js +94 -0
  341. package/hooks/gsd-check-update-worker.js +108 -0
  342. package/hooks/gsd-check-update.js +64 -0
  343. package/hooks/gsd-context-monitor.js +192 -0
  344. package/hooks/gsd-phase-boundary.sh +28 -0
  345. package/hooks/gsd-prompt-guard.js +97 -0
  346. package/hooks/gsd-read-guard.js +82 -0
  347. package/hooks/gsd-read-injection-scanner.js +152 -0
  348. package/hooks/gsd-session-state.sh +34 -0
  349. package/hooks/gsd-statusline.js +293 -0
  350. package/hooks/gsd-validate-commit.sh +48 -0
  351. package/hooks/gsd-workflow-guard.js +94 -0
  352. package/package.json +59 -0
  353. package/scripts/base64-scan.sh +262 -0
  354. package/scripts/build-hooks.js +95 -0
  355. package/scripts/gen-inventory-manifest.cjs +109 -0
  356. package/scripts/prompt-injection-scan.sh +201 -0
  357. package/scripts/run-tests.cjs +33 -0
  358. package/scripts/secret-scan.sh +227 -0
  359. package/sdk/package-lock.json +1998 -0
  360. package/sdk/package.json +52 -0
  361. package/sdk/prompts/agents/gsd-executor.md +110 -0
  362. package/sdk/prompts/agents/gsd-phase-researcher.md +158 -0
  363. package/sdk/prompts/agents/gsd-plan-checker.md +160 -0
  364. package/sdk/prompts/agents/gsd-planner.md +214 -0
  365. package/sdk/prompts/agents/gsd-project-researcher.md +323 -0
  366. package/sdk/prompts/agents/gsd-research-synthesizer.md +237 -0
  367. package/sdk/prompts/agents/gsd-roadmapper.md +670 -0
  368. package/sdk/prompts/agents/gsd-verifier.md +159 -0
  369. package/sdk/prompts/templates/project.md +186 -0
  370. package/sdk/prompts/templates/requirements.md +231 -0
  371. package/sdk/prompts/templates/research-project/ARCHITECTURE.md +204 -0
  372. package/sdk/prompts/templates/research-project/FEATURES.md +147 -0
  373. package/sdk/prompts/templates/research-project/PITFALLS.md +200 -0
  374. package/sdk/prompts/templates/research-project/STACK.md +120 -0
  375. package/sdk/prompts/templates/research-project/SUMMARY.md +170 -0
  376. package/sdk/prompts/templates/roadmap.md +202 -0
  377. package/sdk/prompts/templates/state.md +175 -0
  378. package/sdk/prompts/workflows/discuss-phase.md +126 -0
  379. package/sdk/prompts/workflows/execute-plan.md +106 -0
  380. package/sdk/prompts/workflows/plan-phase.md +84 -0
  381. package/sdk/prompts/workflows/research-phase.md +45 -0
  382. package/sdk/prompts/workflows/verify-phase.md +142 -0
  383. package/sdk/src/assembled-prompts.test.ts +349 -0
  384. package/sdk/src/cli-transport.test.ts +388 -0
  385. package/sdk/src/cli-transport.ts +130 -0
  386. package/sdk/src/cli.test.ts +383 -0
  387. package/sdk/src/cli.ts +670 -0
  388. package/sdk/src/config.test.ts +168 -0
  389. package/sdk/src/config.ts +177 -0
  390. package/sdk/src/context-engine.test.ts +295 -0
  391. package/sdk/src/context-engine.ts +170 -0
  392. package/sdk/src/context-truncation.test.ts +163 -0
  393. package/sdk/src/context-truncation.ts +233 -0
  394. package/sdk/src/e2e.integration.test.ts +178 -0
  395. package/sdk/src/errors.ts +72 -0
  396. package/sdk/src/event-stream.test.ts +661 -0
  397. package/sdk/src/event-stream.ts +441 -0
  398. package/sdk/src/failure-memory.test.ts +457 -0
  399. package/sdk/src/failure-memory.ts +1324 -0
  400. package/sdk/src/golden/capture.ts +95 -0
  401. package/sdk/src/golden/fixtures/generate-slug.golden.json +1 -0
  402. package/sdk/src/golden/fixtures/profile-sample-sessions/demo-project/sample.jsonl +3 -0
  403. package/sdk/src/golden/fixtures/summary-extract-sample.md +26 -0
  404. package/sdk/src/golden/fixtures/uat-render-checkpoint-sample.md +15 -0
  405. package/sdk/src/golden/golden-integration-covered.ts +30 -0
  406. package/sdk/src/golden/golden-mutation-covered.ts +7 -0
  407. package/sdk/src/golden/golden-policy.test.ts +8 -0
  408. package/sdk/src/golden/golden-policy.ts +112 -0
  409. package/sdk/src/golden/golden.integration.test.ts +373 -0
  410. package/sdk/src/golden/init-golden-normalize.ts +15 -0
  411. package/sdk/src/golden/read-only-golden-rows.ts +77 -0
  412. package/sdk/src/golden/read-only-parity.integration.test.ts +125 -0
  413. package/sdk/src/golden/registry-canonical-commands.ts +31 -0
  414. package/sdk/src/gsd-tools.test.ts +409 -0
  415. package/sdk/src/gsd-tools.ts +595 -0
  416. package/sdk/src/headless-prompts.test.ts +159 -0
  417. package/sdk/src/index.ts +333 -0
  418. package/sdk/src/init-e2e.integration.test.ts +136 -0
  419. package/sdk/src/init-runner.test.ts +783 -0
  420. package/sdk/src/init-runner.ts +735 -0
  421. package/sdk/src/lifecycle-e2e.integration.test.ts +258 -0
  422. package/sdk/src/logger.test.ts +149 -0
  423. package/sdk/src/logger.ts +113 -0
  424. package/sdk/src/milestone-runner.test.ts +421 -0
  425. package/sdk/src/phase-prompt.test.ts +538 -0
  426. package/sdk/src/phase-prompt.ts +264 -0
  427. package/sdk/src/phase-runner-types.test.ts +421 -0
  428. package/sdk/src/phase-runner.integration.test.ts +377 -0
  429. package/sdk/src/phase-runner.test.ts +2333 -0
  430. package/sdk/src/phase-runner.ts +1203 -0
  431. package/sdk/src/plan-parser.test.ts +528 -0
  432. package/sdk/src/plan-parser.ts +427 -0
  433. package/sdk/src/prompt-builder.test.ts +306 -0
  434. package/sdk/src/prompt-builder.ts +193 -0
  435. package/sdk/src/prompt-sanitizer.test.ts +260 -0
  436. package/sdk/src/prompt-sanitizer.ts +71 -0
  437. package/sdk/src/query/QUERY-HANDLERS.md +317 -0
  438. package/sdk/src/query/audit-open.ts +722 -0
  439. package/sdk/src/query/check-auto-mode.test.ts +77 -0
  440. package/sdk/src/query/check-auto-mode.ts +50 -0
  441. package/sdk/src/query/check-completion.test.ts +113 -0
  442. package/sdk/src/query/check-completion.ts +182 -0
  443. package/sdk/src/query/check-gates.test.ts +103 -0
  444. package/sdk/src/query/check-gates.ts +112 -0
  445. package/sdk/src/query/check-ship-ready.test.ts +77 -0
  446. package/sdk/src/query/check-ship-ready.ts +103 -0
  447. package/sdk/src/query/check-verification-status.test.ts +143 -0
  448. package/sdk/src/query/check-verification-status.ts +160 -0
  449. package/sdk/src/query/commit.test.ts +202 -0
  450. package/sdk/src/query/commit.ts +301 -0
  451. package/sdk/src/query/config-gates.test.ts +89 -0
  452. package/sdk/src/query/config-gates.ts +69 -0
  453. package/sdk/src/query/config-mutation.test.ts +365 -0
  454. package/sdk/src/query/config-mutation.ts +497 -0
  455. package/sdk/src/query/config-query.test.ts +161 -0
  456. package/sdk/src/query/config-query.ts +190 -0
  457. package/sdk/src/query/context-history.test.ts +165 -0
  458. package/sdk/src/query/context-history.ts +467 -0
  459. package/sdk/src/query/decomposed-handlers.test.ts +365 -0
  460. package/sdk/src/query/detect-custom-files.ts +97 -0
  461. package/sdk/src/query/detect-phase-type.test.ts +105 -0
  462. package/sdk/src/query/detect-phase-type.ts +141 -0
  463. package/sdk/src/query/docs-init.ts +257 -0
  464. package/sdk/src/query/failure-capture.ts +58 -0
  465. package/sdk/src/query/frontmatter-array.test.ts +14 -0
  466. package/sdk/src/query/frontmatter-mutation.test.ts +259 -0
  467. package/sdk/src/query/frontmatter-mutation.ts +343 -0
  468. package/sdk/src/query/frontmatter.test.ts +281 -0
  469. package/sdk/src/query/frontmatter.ts +397 -0
  470. package/sdk/src/query/helpers.test.ts +426 -0
  471. package/sdk/src/query/helpers.ts +482 -0
  472. package/sdk/src/query/index.ts +586 -0
  473. package/sdk/src/query/init-complex.test.ts +232 -0
  474. package/sdk/src/query/init-complex.ts +578 -0
  475. package/sdk/src/query/init.test.ts +522 -0
  476. package/sdk/src/query/init.ts +1046 -0
  477. package/sdk/src/query/intel.test.ts +90 -0
  478. package/sdk/src/query/intel.ts +404 -0
  479. package/sdk/src/query/normalize-query-command.test.ts +50 -0
  480. package/sdk/src/query/normalize-query-command.ts +56 -0
  481. package/sdk/src/query/phase-lifecycle.test.ts +1126 -0
  482. package/sdk/src/query/phase-lifecycle.ts +1799 -0
  483. package/sdk/src/query/phase-list-queries.test.ts +88 -0
  484. package/sdk/src/query/phase-list-queries.ts +152 -0
  485. package/sdk/src/query/phase-ready.test.ts +65 -0
  486. package/sdk/src/query/phase-ready.ts +158 -0
  487. package/sdk/src/query/phase.test.ts +307 -0
  488. package/sdk/src/query/phase.ts +340 -0
  489. package/sdk/src/query/pipeline.test.ts +169 -0
  490. package/sdk/src/query/pipeline.ts +243 -0
  491. package/sdk/src/query/plan-execution-route.test.ts +166 -0
  492. package/sdk/src/query/plan-execution-route.ts +209 -0
  493. package/sdk/src/query/plan-task-structure.test.ts +65 -0
  494. package/sdk/src/query/plan-task-structure.ts +63 -0
  495. package/sdk/src/query/profile-extract-messages.ts +247 -0
  496. package/sdk/src/query/profile-output.ts +908 -0
  497. package/sdk/src/query/profile-questionnaire-data.ts +181 -0
  498. package/sdk/src/query/profile-sample.ts +184 -0
  499. package/sdk/src/query/profile-scan-sessions.ts +174 -0
  500. package/sdk/src/query/profile.test.ts +74 -0
  501. package/sdk/src/query/profile.ts +337 -0
  502. package/sdk/src/query/progress.test.ts +156 -0
  503. package/sdk/src/query/progress.ts +566 -0
  504. package/sdk/src/query/registry.test.ts +216 -0
  505. package/sdk/src/query/registry.ts +174 -0
  506. package/sdk/src/query/requirements-extract-from-plans.test.ts +58 -0
  507. package/sdk/src/query/requirements-extract-from-plans.ts +86 -0
  508. package/sdk/src/query/roadmap-update-plan-progress.ts +132 -0
  509. package/sdk/src/query/roadmap.test.ts +359 -0
  510. package/sdk/src/query/roadmap.ts +591 -0
  511. package/sdk/src/query/route-next-action.test.ts +61 -0
  512. package/sdk/src/query/route-next-action.ts +345 -0
  513. package/sdk/src/query/runtime-health.ts +7 -0
  514. package/sdk/src/query/schema-detect.ts +189 -0
  515. package/sdk/src/query/skill-manifest.ts +214 -0
  516. package/sdk/src/query/skills.test.ts +80 -0
  517. package/sdk/src/query/skills.ts +62 -0
  518. package/sdk/src/query/state-mutation.test.ts +450 -0
  519. package/sdk/src/query/state-mutation.ts +1444 -0
  520. package/sdk/src/query/state-project-load.ts +109 -0
  521. package/sdk/src/query/state.test.ts +347 -0
  522. package/sdk/src/query/state.ts +397 -0
  523. package/sdk/src/query/summary.test.ts +95 -0
  524. package/sdk/src/query/summary.ts +296 -0
  525. package/sdk/src/query/template.test.ts +180 -0
  526. package/sdk/src/query/template.ts +242 -0
  527. package/sdk/src/query/uat.test.ts +77 -0
  528. package/sdk/src/query/uat.ts +314 -0
  529. package/sdk/src/query/utils.test.ts +82 -0
  530. package/sdk/src/query/utils.ts +92 -0
  531. package/sdk/src/query/validate.test.ts +656 -0
  532. package/sdk/src/query/validate.ts +807 -0
  533. package/sdk/src/query/verify.test.ts +414 -0
  534. package/sdk/src/query/verify.ts +645 -0
  535. package/sdk/src/query/websearch.test.ts +31 -0
  536. package/sdk/src/query/websearch.ts +82 -0
  537. package/sdk/src/query/workspace.test.ts +119 -0
  538. package/sdk/src/query/workspace.ts +131 -0
  539. package/sdk/src/query/workstream.test.ts +51 -0
  540. package/sdk/src/query/workstream.ts +434 -0
  541. package/sdk/src/research-gate.test.ts +190 -0
  542. package/sdk/src/research-gate.ts +94 -0
  543. package/sdk/src/runtime-health.test.ts +176 -0
  544. package/sdk/src/runtime-health.ts +387 -0
  545. package/sdk/src/session-runner.test.ts +98 -0
  546. package/sdk/src/session-runner.ts +299 -0
  547. package/sdk/src/tool-scoping.test.ts +160 -0
  548. package/sdk/src/tool-scoping.ts +61 -0
  549. package/sdk/src/types.ts +917 -0
  550. package/sdk/src/workstream-utils.ts +33 -0
  551. package/sdk/src/ws-flag.test.ts +285 -0
  552. package/sdk/src/ws-transport.test.ts +161 -0
  553. package/sdk/src/ws-transport.ts +93 -0
  554. package/sdk/tsconfig.json +20 -0
@@ -0,0 +1,1263 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * @deprecated The supported programmatic surface is `gsd-remix-sdk query` (SDK query registry)
5
+ * and the `@gsd-remix/sdk` package. This Node CLI remains the compatibility implementation
6
+ * for shell scripts and older workflows; prefer calling the SDK from agents and automation.
7
+ *
8
+ * GSD Tools — CLI utility for GSD workflow operations
9
+ *
10
+ * Replaces repetitive inline bash patterns across ~50 GSD command/workflow/agent files.
11
+ * Centralizes: config parsing, model resolution, phase lookup, git commits, summary verification.
12
+ *
13
+ * Usage: node gsd-tools.cjs <command> [args] [--raw] [--pick <field>]
14
+ *
15
+ * Atomic Commands:
16
+ * state load Load project config + state
17
+ * state json Output STATE.md frontmatter as JSON
18
+ * state update <field> <value> Update a STATE.md field
19
+ * state get [section] Get STATE.md content or section
20
+ * state patch --field val ... Batch update STATE.md fields
21
+ * state begin-phase --phase N --name S --plans C Update STATE.md for new phase start
22
+ * state signal-waiting --type T --question Q --options "A|B" --phase P Write WAITING.json signal
23
+ * state signal-resume Remove WAITING.json signal
24
+ * resolve-model <agent-type> Get model for agent based on profile
25
+ * find-phase <phase> Find phase directory by number
26
+ * commit <message> [--files f1 f2] [--no-verify] Commit planning docs
27
+ * commit-to-subrepo <msg> --files f1 f2 Route commits to sub-repos
28
+ * verify-summary <path> Verify a SUMMARY.md file
29
+ * generate-slug <text> Convert text to URL-safe slug
30
+ * current-timestamp [format] Get timestamp (full|date|filename)
31
+ * list-todos [area] Count and enumerate pending todos
32
+ * verify-path-exists <path> Check file/directory existence
33
+ * config-ensure-section Initialize .planning/config.json
34
+ * history-digest Aggregate all SUMMARY.md data
35
+ * summary-extract <path> [--fields] Extract structured data from SUMMARY.md
36
+ * state-snapshot Structured parse of STATE.md
37
+ * phase-plan-index <phase> Index plans with waves and status
38
+ * websearch <query> Search web via Brave API (if configured)
39
+ * [--limit N] [--freshness day|week|month]
40
+ *
41
+ * Phase Operations:
42
+ * phase next-decimal <phase> Calculate next decimal phase number
43
+ * phase add <description> [--id ID] Append new phase to roadmap + create dir
44
+ * phase insert <after> <description> Insert decimal phase after existing
45
+ * phase remove <phase> [--force] Remove phase, renumber all subsequent
46
+ * phase complete <phase> Mark phase done, update state + roadmap
47
+ *
48
+ * Roadmap Operations:
49
+ * roadmap get-phase <phase> Extract phase section from ROADMAP.md
50
+ * roadmap analyze Full roadmap parse with disk status
51
+ * roadmap update-plan-progress <N> Update progress table row from disk (PLAN vs SUMMARY counts)
52
+ * roadmap annotate-dependencies <N> Add wave dependency notes + cross-cutting constraints to ROADMAP.md
53
+ *
54
+ * Requirements Operations:
55
+ * requirements mark-complete <ids> Mark requirement IDs as complete in REQUIREMENTS.md
56
+ * Accepts: REQ-01,REQ-02 or REQ-01 REQ-02 or [REQ-01, REQ-02]
57
+ *
58
+ * Milestone Operations:
59
+ * milestone complete <version> Archive milestone, create MILESTONES.md
60
+ * [--name <name>]
61
+ * [--archive-phases] Move phase dirs to milestones/vX.Y-phases/
62
+ *
63
+ * Validation:
64
+ * validate consistency Check phase numbering, disk/roadmap sync
65
+ * validate health [--repair] Check .planning/ integrity, optionally repair
66
+ * validate agents Check GSD agent installation status
67
+ *
68
+ * Progress:
69
+ * progress [json|table|bar] Render progress in various formats
70
+ *
71
+ * Todos:
72
+ * todo complete <filename> Move todo from pending to completed
73
+ *
74
+ * UAT Audit:
75
+ * audit-uat Scan all phases for unresolved UAT/verification items
76
+ * uat render-checkpoint --file <path> Render the current UAT checkpoint block
77
+ *
78
+ * Open Artifact Audit:
79
+ * audit-open [--json] Scan all .planning/ artifact types for unresolved items
80
+ *
81
+ * Intel:
82
+ * intel query <term> Query intel files for a term
83
+ * intel status Show intel file freshness
84
+ * intel update Trigger intel refresh (returns agent spawn hint)
85
+ * intel diff Show changed intel entries since last snapshot
86
+ * intel snapshot Save current intel state as diff baseline
87
+ * intel patch-meta <file> Update _meta.updated_at in an intel file
88
+ * intel validate Validate intel file structure
89
+ * intel extract-exports <file> Extract exported symbols from a source file
90
+ *
91
+ * Scaffolding:
92
+ * scaffold context --phase <N> Create CONTEXT.md template
93
+ * scaffold uat --phase <N> Create UAT.md template
94
+ * scaffold verification --phase <N> Create VERIFICATION.md template
95
+ * scaffold phase-dir --phase <N> Create phase directory
96
+ * --name <name>
97
+ *
98
+ * Frontmatter CRUD:
99
+ * frontmatter get <file> [--field k] Extract frontmatter as JSON
100
+ * frontmatter set <file> --field k Update single frontmatter field
101
+ * --value jsonVal
102
+ * frontmatter merge <file> Merge JSON into frontmatter
103
+ * --data '{json}'
104
+ * frontmatter validate <file> Validate required fields
105
+ * --schema plan|summary|verification
106
+ *
107
+ * Verification Suite:
108
+ * verify plan-structure <file> Check PLAN.md structure + tasks
109
+ * verify phase-completeness <phase> Check all plans have summaries
110
+ * verify references <file> Check @-refs + paths resolve
111
+ * verify commits <h1> [h2] ... Batch verify commit hashes
112
+ * verify artifacts <plan-file> Check must_haves.artifacts
113
+ * verify key-links <plan-file> Check must_haves.key_links
114
+ * verify schema-drift <phase> [--skip] Detect schema file changes without push
115
+ *
116
+ * Template Fill:
117
+ * template fill summary --phase N Create pre-filled SUMMARY.md
118
+ * [--plan M] [--name "..."]
119
+ * [--fields '{json}']
120
+ * template fill plan --phase N Create pre-filled PLAN.md
121
+ * [--plan M] [--type execute|tdd]
122
+ * [--wave N] [--fields '{json}']
123
+ * template fill verification Create pre-filled VERIFICATION.md
124
+ * --phase N [--fields '{json}']
125
+ *
126
+ * State Progression:
127
+ * state advance-plan Increment plan counter
128
+ * state record-metric --phase N Record execution metrics
129
+ * --plan M --duration Xmin
130
+ * [--tasks N] [--files N]
131
+ * state update-progress Recalculate progress bar
132
+ * state add-decision --summary "..." Add decision to STATE.md
133
+ * [--phase N] [--rationale "..."]
134
+ * [--summary-file path] [--rationale-file path]
135
+ * state add-blocker --text "..." Add blocker
136
+ * [--text-file path]
137
+ * state resolve-blocker --text "..." Remove blocker
138
+ * state record-session Update session continuity
139
+ * --stopped-at "..."
140
+ * [--resume-file path]
141
+ *
142
+ * Compound Commands (workflow-specific initialization):
143
+ * init execute-phase <phase> All context for execute-phase workflow
144
+ * init plan-phase <phase> All context for plan-phase workflow
145
+ * init new-project All context for new-project workflow
146
+ * init new-milestone All context for new-milestone workflow
147
+ * init quick <description> All context for quick workflow
148
+ * init resume All context for resume-project workflow
149
+ * init verify-work <phase> All context for verify-work workflow
150
+ * init phase-op <phase> Generic phase operation context
151
+ * init todos [area] All context for todo workflows
152
+ * init milestone-op All context for milestone operations
153
+ * init map-codebase All context for map-codebase workflow
154
+ * init progress All context for progress workflow
155
+ *
156
+ * Documentation:
157
+ * docs-init Project context for docs-update workflow
158
+ *
159
+ * Learnings:
160
+ * learnings list List all global learnings (JSON)
161
+ * learnings query --tag <tag> Query learnings by tag
162
+ * learnings copy Copy from current project's LEARNINGS.md
163
+ * learnings prune --older-than <dur> Remove entries older than duration (e.g. 90d)
164
+ * learnings delete <id> Delete a learning by ID
165
+ *
166
+ * GSD-2 Migration:
167
+ * from-gsd2 [--path <dir>] [--force] [--dry-run]
168
+ * Import a GSD-2 (.gsd/) project back to GSD v1 (.planning/) format
169
+ */
170
+
171
+ const fs = require('fs');
172
+ const path = require('path');
173
+ const core = require('./lib/core.cjs');
174
+ const { error, findProjectRoot, getActiveWorkstream } = core;
175
+ const state = require('./lib/state.cjs');
176
+ const phase = require('./lib/phase.cjs');
177
+ const roadmap = require('./lib/roadmap.cjs');
178
+ const verify = require('./lib/verify.cjs');
179
+ const config = require('./lib/config.cjs');
180
+ const template = require('./lib/template.cjs');
181
+ const milestone = require('./lib/milestone.cjs');
182
+ const commands = require('./lib/commands.cjs');
183
+ const init = require('./lib/init.cjs');
184
+ const frontmatter = require('./lib/frontmatter.cjs');
185
+ const profilePipeline = require('./lib/profile-pipeline.cjs');
186
+ const profileOutput = require('./lib/profile-output.cjs');
187
+ const workstream = require('./lib/workstream.cjs');
188
+ const docs = require('./lib/docs.cjs');
189
+ const learnings = require('./lib/learnings.cjs');
190
+
191
+ // ─── Arg parsing helpers ──────────────────────────────────────────────────────
192
+
193
+ /**
194
+ * Extract named --flag <value> pairs from an args array.
195
+ * Returns an object mapping flag names to their values (null if absent).
196
+ * Flags listed in `booleanFlags` are treated as boolean (no value consumed).
197
+ *
198
+ * parseNamedArgs(args, 'phase', 'plan') → { phase: '3', plan: '1' }
199
+ * parseNamedArgs(args, [], ['amend', 'force']) → { amend: true, force: false }
200
+ */
201
+ function parseNamedArgs(args, valueFlags = [], booleanFlags = []) {
202
+ const result = {};
203
+ for (const flag of valueFlags) {
204
+ const idx = args.indexOf(`--${flag}`);
205
+ result[flag] = idx !== -1 && args[idx + 1] !== undefined && !args[idx + 1].startsWith('--')
206
+ ? args[idx + 1]
207
+ : null;
208
+ }
209
+ for (const flag of booleanFlags) {
210
+ result[flag] = args.includes(`--${flag}`);
211
+ }
212
+ return result;
213
+ }
214
+
215
+ /**
216
+ * Collect all tokens after --flag until the next --flag or end of args.
217
+ * Handles multi-word values like --name Foo Bar Version 1.
218
+ * Returns null if the flag is absent.
219
+ */
220
+ function parseMultiwordArg(args, flag) {
221
+ const idx = args.indexOf(`--${flag}`);
222
+ if (idx === -1) return null;
223
+ const tokens = [];
224
+ for (let i = idx + 1; i < args.length; i++) {
225
+ if (args[i].startsWith('--')) break;
226
+ tokens.push(args[i]);
227
+ }
228
+ return tokens.length > 0 ? tokens.join(' ') : null;
229
+ }
230
+
231
+ // ─── CLI Router ───────────────────────────────────────────────────────────────
232
+
233
+ async function main() {
234
+ const args = process.argv.slice(2);
235
+
236
+ // Optional cwd override for sandboxed subagents running outside project root.
237
+ let cwd = process.cwd();
238
+ const cwdEqArg = args.find(arg => arg.startsWith('--cwd='));
239
+ const cwdIdx = args.indexOf('--cwd');
240
+ if (cwdEqArg) {
241
+ const value = cwdEqArg.slice('--cwd='.length).trim();
242
+ if (!value) error('Missing value for --cwd');
243
+ args.splice(args.indexOf(cwdEqArg), 1);
244
+ cwd = path.resolve(value);
245
+ } else if (cwdIdx !== -1) {
246
+ const value = args[cwdIdx + 1];
247
+ if (!value || value.startsWith('--')) error('Missing value for --cwd');
248
+ args.splice(cwdIdx, 2);
249
+ cwd = path.resolve(value);
250
+ }
251
+
252
+ if (!fs.existsSync(cwd) || !fs.statSync(cwd).isDirectory()) {
253
+ error(`Invalid --cwd: ${cwd}`);
254
+ }
255
+
256
+ // Resolve worktree root: in a linked worktree, .planning/ lives in the main worktree.
257
+ // However, in monorepo worktrees where the subdirectory itself owns .planning/,
258
+ // skip worktree resolution — the CWD is already the correct project root.
259
+ const { resolveWorktreeRoot } = require('./lib/core.cjs');
260
+ if (!fs.existsSync(path.join(cwd, '.planning'))) {
261
+ const worktreeRoot = resolveWorktreeRoot(cwd);
262
+ if (worktreeRoot !== cwd) {
263
+ cwd = worktreeRoot;
264
+ }
265
+ }
266
+
267
+ // Optional workstream override for parallel milestone work.
268
+ // Priority: --ws flag > GSD_WORKSTREAM env var > session-scoped pointer > shared legacy pointer > null
269
+ const wsEqArg = args.find(arg => arg.startsWith('--ws='));
270
+ const wsIdx = args.indexOf('--ws');
271
+ let ws = null;
272
+ if (wsEqArg) {
273
+ ws = wsEqArg.slice('--ws='.length).trim();
274
+ if (!ws) error('Missing value for --ws');
275
+ args.splice(args.indexOf(wsEqArg), 1);
276
+ } else if (wsIdx !== -1) {
277
+ ws = args[wsIdx + 1];
278
+ if (!ws || ws.startsWith('--')) error('Missing value for --ws');
279
+ args.splice(wsIdx, 2);
280
+ } else if (process.env.GSD_WORKSTREAM) {
281
+ ws = process.env.GSD_WORKSTREAM.trim();
282
+ } else {
283
+ ws = getActiveWorkstream(cwd);
284
+ }
285
+ // Validate workstream name to prevent path traversal attacks.
286
+ if (ws && !/^[a-zA-Z0-9_-]+$/.test(ws)) {
287
+ error('Invalid workstream name: must be alphanumeric, hyphens, and underscores only');
288
+ }
289
+ // Set env var so all modules (planningDir, planningPaths) auto-resolve workstream paths
290
+ if (ws) {
291
+ process.env.GSD_WORKSTREAM = ws;
292
+ }
293
+
294
+ const rawIndex = args.indexOf('--raw');
295
+ const raw = rawIndex !== -1;
296
+ if (rawIndex !== -1) args.splice(rawIndex, 1);
297
+
298
+ // --pick <name>: extract a single field from JSON output (replaces jq dependency).
299
+ // Supports dot-notation (e.g., --pick workflow.research) and bracket notation
300
+ // for arrays (e.g., --pick directories[-1]).
301
+ const pickIdx = args.indexOf('--pick');
302
+ let pickField = null;
303
+ if (pickIdx !== -1) {
304
+ pickField = args[pickIdx + 1];
305
+ if (!pickField || pickField.startsWith('--')) error('Missing value for --pick');
306
+ args.splice(pickIdx, 2);
307
+ }
308
+
309
+ // --default <value>: for config-get, return this value instead of erroring
310
+ // when the key is absent. Allows workflows to express optional config reads
311
+ // without defensive `2>/dev/null || true` boilerplate (#1893).
312
+ const defaultIdx = args.indexOf('--default');
313
+ let defaultValue = undefined;
314
+ if (defaultIdx !== -1) {
315
+ defaultValue = args[defaultIdx + 1];
316
+ if (defaultValue === undefined) defaultValue = '';
317
+ args.splice(defaultIdx, 2);
318
+ }
319
+
320
+ const command = args[0];
321
+
322
+ if (!command) {
323
+ error('Usage: gsd-tools <command> [args] [--raw] [--pick <field>] [--cwd <path>] [--ws <name>]\nCommands: state, resolve-model, find-phase, commit, verify-summary, verify, frontmatter, template, generate-slug, current-timestamp, list-todos, verify-path-exists, config-ensure-section, config-new-project, init, workstream, docs-init');
324
+ }
325
+
326
+ // Reject flags that are never valid for any gsd-tools command. AI agents
327
+ // sometimes hallucinate --help or --version on tool invocations; silently
328
+ // ignoring them can cause destructive operations to proceed unchecked.
329
+ const NEVER_VALID_FLAGS = new Set(['-h', '--help', '-?', '--h', '--version', '-v', '--usage']);
330
+ for (const arg of args) {
331
+ if (NEVER_VALID_FLAGS.has(arg)) {
332
+ error(`Unknown flag: ${arg}\ngsd-tools does not accept help or version flags. Run "gsd-tools" with no arguments for usage.`);
333
+ }
334
+ }
335
+
336
+ // Multi-repo guard: resolve project root for commands that read/write .planning/.
337
+ // Skip for pure-utility commands that don't touch .planning/ to avoid unnecessary
338
+ // filesystem traversal on every invocation.
339
+ const SKIP_ROOT_RESOLUTION = new Set([
340
+ 'generate-slug', 'current-timestamp', 'verify-path-exists',
341
+ 'verify-summary', 'template', 'frontmatter', 'detect-custom-files',
342
+ ]);
343
+ if (!SKIP_ROOT_RESOLUTION.has(command)) {
344
+ cwd = findProjectRoot(cwd);
345
+ }
346
+
347
+ // When --pick is active, intercept stdout to extract the requested field.
348
+ if (pickField) {
349
+ const origWriteSync = fs.writeSync;
350
+ const chunks = [];
351
+ fs.writeSync = function (fd, data, ...rest) {
352
+ if (fd === 1) { chunks.push(String(data)); return; }
353
+ return origWriteSync.call(fs, fd, data, ...rest);
354
+ };
355
+ const cleanup = () => {
356
+ fs.writeSync = origWriteSync;
357
+ const captured = chunks.join('');
358
+ let jsonStr = captured;
359
+ if (jsonStr.startsWith('@file:')) {
360
+ jsonStr = fs.readFileSync(jsonStr.slice(6), 'utf-8');
361
+ }
362
+ try {
363
+ const obj = JSON.parse(jsonStr);
364
+ const value = extractField(obj, pickField);
365
+ const result = value === null || value === undefined ? '' : String(value);
366
+ origWriteSync.call(fs, 1, result);
367
+ } catch {
368
+ origWriteSync.call(fs, 1, captured);
369
+ }
370
+ };
371
+ try {
372
+ await runCommand(command, args, cwd, raw, defaultValue);
373
+ cleanup();
374
+ } catch (e) {
375
+ fs.writeSync = origWriteSync;
376
+ throw e;
377
+ }
378
+ return;
379
+ }
380
+
381
+ // Intercept stdout to transparently resolve @file: references (#1891).
382
+ // core.cjs output() writes @file:<path> when JSON > 50KB. The --pick path
383
+ // already resolves this, but the normal path wrote @file: to stdout, forcing
384
+ // every workflow to have a bash-specific `if [[ "$INIT" == @file:* ]]` check
385
+ // that breaks on PowerShell and other non-bash shells.
386
+ const origWriteSync2 = fs.writeSync;
387
+ const outChunks = [];
388
+ fs.writeSync = function (fd, data, ...rest) {
389
+ if (fd === 1) { outChunks.push(String(data)); return; }
390
+ return origWriteSync2.call(fs, fd, data, ...rest);
391
+ };
392
+ try {
393
+ await runCommand(command, args, cwd, raw, defaultValue);
394
+ } finally {
395
+ fs.writeSync = origWriteSync2;
396
+ }
397
+ let captured = outChunks.join('');
398
+ if (captured.startsWith('@file:')) {
399
+ captured = fs.readFileSync(captured.slice(6), 'utf-8');
400
+ }
401
+ origWriteSync2.call(fs, 1, captured);
402
+ }
403
+
404
+ /**
405
+ * Extract a field from an object using dot-notation and bracket syntax.
406
+ * Supports: 'field', 'parent.child', 'arr[-1]', 'arr[0]'
407
+ */
408
+ function extractField(obj, fieldPath) {
409
+ const parts = fieldPath.split('.');
410
+ let current = obj;
411
+ for (const part of parts) {
412
+ if (current === null || current === undefined) return undefined;
413
+ const bracketMatch = part.match(/^(.+?)\[(-?\d+)]$/);
414
+ if (bracketMatch) {
415
+ const key = bracketMatch[1];
416
+ const index = parseInt(bracketMatch[2], 10);
417
+ current = current[key];
418
+ if (!Array.isArray(current)) return undefined;
419
+ current = index < 0 ? current[current.length + index] : current[index];
420
+ } else {
421
+ current = current[part];
422
+ }
423
+ }
424
+ return current;
425
+ }
426
+
427
+ async function runCommand(command, args, cwd, raw, defaultValue) {
428
+ switch (command) {
429
+ case 'state': {
430
+ const subcommand = args[1];
431
+ if (subcommand === 'json') {
432
+ state.cmdStateJson(cwd, raw);
433
+ } else if (subcommand === 'update') {
434
+ state.cmdStateUpdate(cwd, args[2], args[3]);
435
+ } else if (subcommand === 'get') {
436
+ state.cmdStateGet(cwd, args[2], raw);
437
+ } else if (subcommand === 'patch') {
438
+ const patches = {};
439
+ for (let i = 2; i < args.length; i += 2) {
440
+ const key = args[i].replace(/^--/, '');
441
+ const value = args[i + 1];
442
+ if (key && value !== undefined) {
443
+ patches[key] = value;
444
+ }
445
+ }
446
+ state.cmdStatePatch(cwd, patches, raw);
447
+ } else if (subcommand === 'advance-plan') {
448
+ state.cmdStateAdvancePlan(cwd, raw);
449
+ } else if (subcommand === 'record-metric') {
450
+ const { phase: p, plan, duration, tasks, files } = parseNamedArgs(args, ['phase', 'plan', 'duration', 'tasks', 'files']);
451
+ state.cmdStateRecordMetric(cwd, { phase: p, plan, duration, tasks, files }, raw);
452
+ } else if (subcommand === 'update-progress') {
453
+ state.cmdStateUpdateProgress(cwd, raw);
454
+ } else if (subcommand === 'add-decision') {
455
+ const { phase: p, summary, 'summary-file': summary_file, rationale, 'rationale-file': rationale_file } = parseNamedArgs(args, ['phase', 'summary', 'summary-file', 'rationale', 'rationale-file']);
456
+ state.cmdStateAddDecision(cwd, { phase: p, summary, summary_file, rationale: rationale || '', rationale_file }, raw);
457
+ } else if (subcommand === 'add-blocker') {
458
+ const { text, 'text-file': text_file } = parseNamedArgs(args, ['text', 'text-file']);
459
+ state.cmdStateAddBlocker(cwd, { text, text_file }, raw);
460
+ } else if (subcommand === 'resolve-blocker') {
461
+ state.cmdStateResolveBlocker(cwd, parseNamedArgs(args, ['text']).text, raw);
462
+ } else if (subcommand === 'record-session') {
463
+ const { 'stopped-at': stopped_at, 'resume-file': resume_file } = parseNamedArgs(args, ['stopped-at', 'resume-file']);
464
+ state.cmdStateRecordSession(cwd, { stopped_at, resume_file: resume_file || 'None' }, raw);
465
+ } else if (subcommand === 'begin-phase') {
466
+ const { phase: p, name, plans } = parseNamedArgs(args, ['phase', 'name', 'plans']);
467
+ state.cmdStateBeginPhase(cwd, p, name, plans !== null ? parseInt(plans, 10) : null, raw);
468
+ } else if (subcommand === 'signal-waiting') {
469
+ const { type, question, options, phase: p } = parseNamedArgs(args, ['type', 'question', 'options', 'phase']);
470
+ state.cmdSignalWaiting(cwd, type, question, options, p, raw);
471
+ } else if (subcommand === 'signal-resume') {
472
+ state.cmdSignalResume(cwd, raw);
473
+ } else if (subcommand === 'planned-phase') {
474
+ const { phase: p, name, plans } = parseNamedArgs(args, ['phase', 'name', 'plans']);
475
+ state.cmdStatePlannedPhase(cwd, p, plans !== null ? parseInt(plans, 10) : null, raw);
476
+ } else if (subcommand === 'validate') {
477
+ state.cmdStateValidate(cwd, raw);
478
+ } else if (subcommand === 'sync') {
479
+ const { verify } = parseNamedArgs(args, [], ['verify']);
480
+ state.cmdStateSync(cwd, { verify }, raw);
481
+ } else if (subcommand === 'prune') {
482
+ const { 'keep-recent': keepRecent, 'dry-run': dryRun } = parseNamedArgs(args, ['keep-recent'], ['dry-run']);
483
+ state.cmdStatePrune(cwd, { keepRecent: keepRecent || '3', dryRun: !!dryRun }, raw);
484
+ } else {
485
+ state.cmdStateLoad(cwd, raw);
486
+ }
487
+ break;
488
+ }
489
+
490
+ case 'resolve-model': {
491
+ commands.cmdResolveModel(cwd, args[1], raw);
492
+ break;
493
+ }
494
+
495
+ case 'find-phase': {
496
+ phase.cmdFindPhase(cwd, args[1], raw);
497
+ break;
498
+ }
499
+
500
+ case 'commit': {
501
+ const amend = args.includes('--amend');
502
+ const noVerify = args.includes('--no-verify');
503
+ const filesIndex = args.indexOf('--files');
504
+ // Collect all positional args between command name and first flag,
505
+ // then join them — handles both quoted ("multi word msg") and
506
+ // unquoted (multi word msg) invocations from different shells
507
+ const endIndex = filesIndex !== -1 ? filesIndex : args.length;
508
+ const messageArgs = args.slice(1, endIndex).filter(a => !a.startsWith('--'));
509
+ const message = messageArgs.join(' ') || undefined;
510
+ const files = filesIndex !== -1 ? args.slice(filesIndex + 1).filter(a => !a.startsWith('--')) : [];
511
+ commands.cmdCommit(cwd, message, files, raw, amend, noVerify);
512
+ break;
513
+ }
514
+
515
+ case 'check-commit': {
516
+ commands.cmdCheckCommit(cwd, raw);
517
+ break;
518
+ }
519
+
520
+ case 'commit-to-subrepo': {
521
+ const message = args[1];
522
+ const filesIndex = args.indexOf('--files');
523
+ const files = filesIndex !== -1 ? args.slice(filesIndex + 1).filter(a => !a.startsWith('--')) : [];
524
+ commands.cmdCommitToSubrepo(cwd, message, files, raw);
525
+ break;
526
+ }
527
+
528
+ case 'verify-summary': {
529
+ const summaryPath = args[1];
530
+ const countIndex = args.indexOf('--check-count');
531
+ const checkCount = countIndex !== -1 ? parseInt(args[countIndex + 1], 10) : 2;
532
+ verify.cmdVerifySummary(cwd, summaryPath, checkCount, raw);
533
+ break;
534
+ }
535
+
536
+ case 'template': {
537
+ const subcommand = args[1];
538
+ if (subcommand === 'select') {
539
+ template.cmdTemplateSelect(cwd, args[2], raw);
540
+ } else if (subcommand === 'fill') {
541
+ const templateType = args[2];
542
+ const { phase, plan, name, type, wave, fields: fieldsRaw } = parseNamedArgs(args, ['phase', 'plan', 'name', 'type', 'wave', 'fields']);
543
+ let fields = {};
544
+ if (fieldsRaw) {
545
+ const { safeJsonParse } = require('./lib/security.cjs');
546
+ const result = safeJsonParse(fieldsRaw, { label: '--fields' });
547
+ if (!result.ok) error(result.error);
548
+ fields = result.value;
549
+ }
550
+ template.cmdTemplateFill(cwd, templateType, {
551
+ phase, plan, name, fields,
552
+ type: type || 'execute',
553
+ wave: wave || '1',
554
+ }, raw);
555
+ } else {
556
+ error('Unknown template subcommand. Available: select, fill');
557
+ }
558
+ break;
559
+ }
560
+
561
+ case 'frontmatter': {
562
+ const subcommand = args[1];
563
+ const file = args[2];
564
+ if (subcommand === 'get') {
565
+ frontmatter.cmdFrontmatterGet(cwd, file, parseNamedArgs(args, ['field']).field, raw);
566
+ } else if (subcommand === 'set') {
567
+ const { field, value } = parseNamedArgs(args, ['field', 'value']);
568
+ frontmatter.cmdFrontmatterSet(cwd, file, field, value !== null ? value : undefined, raw);
569
+ } else if (subcommand === 'merge') {
570
+ frontmatter.cmdFrontmatterMerge(cwd, file, parseNamedArgs(args, ['data']).data, raw);
571
+ } else if (subcommand === 'validate') {
572
+ frontmatter.cmdFrontmatterValidate(cwd, file, parseNamedArgs(args, ['schema']).schema, raw);
573
+ } else {
574
+ error('Unknown frontmatter subcommand. Available: get, set, merge, validate');
575
+ }
576
+ break;
577
+ }
578
+
579
+ case 'verify': {
580
+ const subcommand = args[1];
581
+ if (subcommand === 'plan-structure') {
582
+ verify.cmdVerifyPlanStructure(cwd, args[2], raw);
583
+ } else if (subcommand === 'phase-completeness') {
584
+ verify.cmdVerifyPhaseCompleteness(cwd, args[2], raw);
585
+ } else if (subcommand === 'references') {
586
+ verify.cmdVerifyReferences(cwd, args[2], raw);
587
+ } else if (subcommand === 'commits') {
588
+ verify.cmdVerifyCommits(cwd, args.slice(2), raw);
589
+ } else if (subcommand === 'artifacts') {
590
+ verify.cmdVerifyArtifacts(cwd, args[2], raw);
591
+ } else if (subcommand === 'key-links') {
592
+ verify.cmdVerifyKeyLinks(cwd, args[2], raw);
593
+ } else if (subcommand === 'schema-drift') {
594
+ const skipFlag = args.includes('--skip');
595
+ verify.cmdVerifySchemaDrift(cwd, args[2], skipFlag, raw);
596
+ } else {
597
+ error('Unknown verify subcommand. Available: plan-structure, phase-completeness, references, commits, artifacts, key-links, schema-drift');
598
+ }
599
+ break;
600
+ }
601
+
602
+ case 'generate-slug': {
603
+ commands.cmdGenerateSlug(args[1], raw);
604
+ break;
605
+ }
606
+
607
+ case 'current-timestamp': {
608
+ commands.cmdCurrentTimestamp(args[1] || 'full', raw);
609
+ break;
610
+ }
611
+
612
+ case 'list-todos': {
613
+ commands.cmdListTodos(cwd, args[1], raw);
614
+ break;
615
+ }
616
+
617
+ case 'verify-path-exists': {
618
+ commands.cmdVerifyPathExists(cwd, args[1], raw);
619
+ break;
620
+ }
621
+
622
+ case 'config-ensure-section': {
623
+ config.cmdConfigEnsureSection(cwd, raw);
624
+ break;
625
+ }
626
+
627
+ case 'config-set': {
628
+ config.cmdConfigSet(cwd, args[1], args[2], raw);
629
+ break;
630
+ }
631
+
632
+ case "config-set-model-profile": {
633
+ config.cmdConfigSetModelProfile(cwd, args[1], raw);
634
+ break;
635
+ }
636
+
637
+ case 'config-get': {
638
+ config.cmdConfigGet(cwd, args[1], raw, defaultValue);
639
+ break;
640
+ }
641
+
642
+ case 'config-new-project': {
643
+ config.cmdConfigNewProject(cwd, args[1], raw);
644
+ break;
645
+ }
646
+
647
+ case 'config-path': {
648
+ config.cmdConfigPath(cwd, raw);
649
+ break;
650
+ }
651
+
652
+ case 'agent-skills': {
653
+ init.cmdAgentSkills(cwd, args[1], raw);
654
+ break;
655
+ }
656
+
657
+ case 'skill-manifest': {
658
+ init.cmdSkillManifest(cwd, args, raw);
659
+ break;
660
+ }
661
+
662
+ case 'history-digest': {
663
+ commands.cmdHistoryDigest(cwd, raw);
664
+ break;
665
+ }
666
+
667
+ case 'phases': {
668
+ const subcommand = args[1];
669
+ if (subcommand === 'list') {
670
+ const typeIndex = args.indexOf('--type');
671
+ const phaseIndex = args.indexOf('--phase');
672
+ const options = {
673
+ type: typeIndex !== -1 ? args[typeIndex + 1] : null,
674
+ phase: phaseIndex !== -1 ? args[phaseIndex + 1] : null,
675
+ includeArchived: args.includes('--include-archived'),
676
+ };
677
+ phase.cmdPhasesList(cwd, options, raw);
678
+ } else if (subcommand === 'clear') {
679
+ milestone.cmdPhasesClear(cwd, raw, args.slice(2));
680
+ } else {
681
+ error('Unknown phases subcommand. Available: list, clear');
682
+ }
683
+ break;
684
+ }
685
+
686
+ case 'roadmap': {
687
+ const subcommand = args[1];
688
+ if (subcommand === 'get-phase') {
689
+ roadmap.cmdRoadmapGetPhase(cwd, args[2], raw);
690
+ } else if (subcommand === 'analyze') {
691
+ roadmap.cmdRoadmapAnalyze(cwd, raw);
692
+ } else if (subcommand === 'update-plan-progress') {
693
+ roadmap.cmdRoadmapUpdatePlanProgress(cwd, args[2], raw);
694
+ } else if (subcommand === 'annotate-dependencies') {
695
+ roadmap.cmdRoadmapAnnotateDependencies(cwd, args[2], raw);
696
+ } else {
697
+ error('Unknown roadmap subcommand. Available: get-phase, analyze, update-plan-progress, annotate-dependencies');
698
+ }
699
+ break;
700
+ }
701
+
702
+ case 'requirements': {
703
+ const subcommand = args[1];
704
+ if (subcommand === 'mark-complete') {
705
+ milestone.cmdRequirementsMarkComplete(cwd, args.slice(2), raw);
706
+ } else {
707
+ error('Unknown requirements subcommand. Available: mark-complete');
708
+ }
709
+ break;
710
+ }
711
+
712
+ case 'phase': {
713
+ const subcommand = args[1];
714
+ if (subcommand === 'next-decimal') {
715
+ phase.cmdPhaseNextDecimal(cwd, args[2], raw);
716
+ } else if (subcommand === 'add') {
717
+ const idIdx = args.indexOf('--id');
718
+ let customId = null;
719
+ const descArgs = [];
720
+ for (let i = 2; i < args.length; i++) {
721
+ if (args[i] === '--id' && i + 1 < args.length) {
722
+ customId = args[i + 1];
723
+ i++; // skip value
724
+ } else {
725
+ descArgs.push(args[i]);
726
+ }
727
+ }
728
+ phase.cmdPhaseAdd(cwd, descArgs.join(' '), raw, customId);
729
+ } else if (subcommand === 'add-batch') {
730
+ // Accepts JSON array of descriptions via --descriptions '[...]' or positional args
731
+ const descFlagIdx = args.indexOf('--descriptions');
732
+ let descriptions;
733
+ if (descFlagIdx !== -1 && args[descFlagIdx + 1]) {
734
+ try { descriptions = JSON.parse(args[descFlagIdx + 1]); } catch (e) { error('--descriptions must be a JSON array'); }
735
+ } else {
736
+ descriptions = args.slice(2).filter(a => a !== '--raw');
737
+ }
738
+ phase.cmdPhaseAddBatch(cwd, descriptions, raw);
739
+ } else if (subcommand === 'insert') {
740
+ phase.cmdPhaseInsert(cwd, args[2], args.slice(3).join(' '), raw);
741
+ } else if (subcommand === 'remove') {
742
+ const forceFlag = args.includes('--force');
743
+ phase.cmdPhaseRemove(cwd, args[2], { force: forceFlag }, raw);
744
+ } else if (subcommand === 'complete') {
745
+ phase.cmdPhaseComplete(cwd, args[2], raw);
746
+ } else {
747
+ error('Unknown phase subcommand. Available: next-decimal, add, add-batch, insert, remove, complete');
748
+ }
749
+ break;
750
+ }
751
+
752
+ case 'milestone': {
753
+ const subcommand = args[1];
754
+ if (subcommand === 'complete') {
755
+ const milestoneName = parseMultiwordArg(args, 'name');
756
+ const archivePhases = args.includes('--archive-phases');
757
+ milestone.cmdMilestoneComplete(cwd, args[2], { name: milestoneName, archivePhases }, raw);
758
+ } else {
759
+ error('Unknown milestone subcommand. Available: complete');
760
+ }
761
+ break;
762
+ }
763
+
764
+ case 'validate': {
765
+ const subcommand = args[1];
766
+ if (subcommand === 'consistency') {
767
+ verify.cmdValidateConsistency(cwd, raw);
768
+ } else if (subcommand === 'health') {
769
+ const repairFlag = args.includes('--repair');
770
+ const backfillFlag = args.includes('--backfill');
771
+ verify.cmdValidateHealth(cwd, { repair: repairFlag, backfill: backfillFlag }, raw);
772
+ } else if (subcommand === 'agents') {
773
+ verify.cmdValidateAgents(cwd, raw);
774
+ } else {
775
+ error('Unknown validate subcommand. Available: consistency, health, agents');
776
+ }
777
+ break;
778
+ }
779
+
780
+ case 'progress': {
781
+ const subcommand = args[1] || 'json';
782
+ commands.cmdProgressRender(cwd, subcommand, raw);
783
+ break;
784
+ }
785
+
786
+ case 'audit-uat': {
787
+ const uat = require('./lib/uat.cjs');
788
+ uat.cmdAuditUat(cwd, raw);
789
+ break;
790
+ }
791
+
792
+ case 'audit-open': {
793
+ const { auditOpenArtifacts, formatAuditReport } = require('./lib/audit.cjs');
794
+ const includeRaw = args.includes('--json');
795
+ const result = auditOpenArtifacts(cwd);
796
+ if (includeRaw) {
797
+ core.output(result, raw);
798
+ } else {
799
+ core.output(formatAuditReport(result), raw);
800
+ }
801
+ break;
802
+ }
803
+
804
+ case 'uat': {
805
+ const subcommand = args[1];
806
+ const uat = require('./lib/uat.cjs');
807
+ if (subcommand === 'render-checkpoint') {
808
+ const options = parseNamedArgs(args, ['file']);
809
+ uat.cmdRenderCheckpoint(cwd, options, raw);
810
+ } else {
811
+ error('Unknown uat subcommand. Available: render-checkpoint');
812
+ }
813
+ break;
814
+ }
815
+
816
+ case 'stats': {
817
+ const subcommand = args[1] || 'json';
818
+ commands.cmdStats(cwd, subcommand, raw);
819
+ break;
820
+ }
821
+
822
+ case 'todo': {
823
+ const subcommand = args[1];
824
+ if (subcommand === 'complete') {
825
+ commands.cmdTodoComplete(cwd, args[2], raw);
826
+ } else if (subcommand === 'match-phase') {
827
+ commands.cmdTodoMatchPhase(cwd, args[2], raw);
828
+ } else {
829
+ error('Unknown todo subcommand. Available: complete, match-phase');
830
+ }
831
+ break;
832
+ }
833
+
834
+ case 'scaffold': {
835
+ const scaffoldType = args[1];
836
+ const scaffoldOptions = {
837
+ phase: parseNamedArgs(args, ['phase']).phase,
838
+ name: parseMultiwordArg(args, 'name'),
839
+ };
840
+ commands.cmdScaffold(cwd, scaffoldType, scaffoldOptions, raw);
841
+ break;
842
+ }
843
+
844
+ case 'init': {
845
+ const workflow = args[1];
846
+ switch (workflow) {
847
+ case 'execute-phase': {
848
+ const { validate: epValidate, tdd: epTdd } = parseNamedArgs(args, [], ['validate', 'tdd']);
849
+ init.cmdInitExecutePhase(cwd, args[2], raw, { validate: epValidate, tdd: epTdd });
850
+ break;
851
+ }
852
+ case 'plan-phase': {
853
+ const { validate: ppValidate, tdd: ppTdd } = parseNamedArgs(args, [], ['validate', 'tdd']);
854
+ init.cmdInitPlanPhase(cwd, args[2], raw, { validate: ppValidate, tdd: ppTdd });
855
+ break;
856
+ }
857
+ case 'new-project':
858
+ init.cmdInitNewProject(cwd, raw);
859
+ break;
860
+ case 'new-milestone':
861
+ init.cmdInitNewMilestone(cwd, raw);
862
+ break;
863
+ case 'quick':
864
+ init.cmdInitQuick(cwd, args.slice(2).join(' '), raw);
865
+ break;
866
+ case 'resume':
867
+ init.cmdInitResume(cwd, raw);
868
+ break;
869
+ case 'verify-work':
870
+ init.cmdInitVerifyWork(cwd, args[2], raw);
871
+ break;
872
+ case 'phase-op':
873
+ init.cmdInitPhaseOp(cwd, args[2], raw);
874
+ break;
875
+ case 'todos':
876
+ init.cmdInitTodos(cwd, args[2], raw);
877
+ break;
878
+ case 'milestone-op':
879
+ init.cmdInitMilestoneOp(cwd, raw);
880
+ break;
881
+ case 'map-codebase':
882
+ init.cmdInitMapCodebase(cwd, raw);
883
+ break;
884
+ case 'progress':
885
+ init.cmdInitProgress(cwd, raw);
886
+ break;
887
+ case 'manager':
888
+ init.cmdInitManager(cwd, raw);
889
+ break;
890
+ case 'new-workspace':
891
+ init.cmdInitNewWorkspace(cwd, raw);
892
+ break;
893
+ case 'list-workspaces':
894
+ init.cmdInitListWorkspaces(cwd, raw);
895
+ break;
896
+ case 'remove-workspace':
897
+ init.cmdInitRemoveWorkspace(cwd, args[2], raw);
898
+ break;
899
+ default:
900
+ error(`Unknown init workflow: ${workflow}\nAvailable: execute-phase, plan-phase, new-project, new-milestone, quick, resume, verify-work, phase-op, todos, milestone-op, map-codebase, progress, manager, new-workspace, list-workspaces, remove-workspace`);
901
+ }
902
+ break;
903
+ }
904
+
905
+ case 'phase-plan-index': {
906
+ phase.cmdPhasePlanIndex(cwd, args[1], raw);
907
+ break;
908
+ }
909
+
910
+ case 'state-snapshot': {
911
+ state.cmdStateSnapshot(cwd, raw);
912
+ break;
913
+ }
914
+
915
+ case 'summary-extract': {
916
+ const summaryPath = args[1];
917
+ const fieldsIndex = args.indexOf('--fields');
918
+ const fields = fieldsIndex !== -1 ? args[fieldsIndex + 1].split(',') : null;
919
+ commands.cmdSummaryExtract(cwd, summaryPath, fields, raw);
920
+ break;
921
+ }
922
+
923
+ case 'websearch': {
924
+ const query = args[1];
925
+ const limitIdx = args.indexOf('--limit');
926
+ const freshnessIdx = args.indexOf('--freshness');
927
+ await commands.cmdWebsearch(query, {
928
+ limit: limitIdx !== -1 ? parseInt(args[limitIdx + 1], 10) : 10,
929
+ freshness: freshnessIdx !== -1 ? args[freshnessIdx + 1] : null,
930
+ }, raw);
931
+ break;
932
+ }
933
+
934
+ // ─── Profiling Pipeline ────────────────────────────────────────────────
935
+
936
+ case 'scan-sessions': {
937
+ const pathIdx = args.indexOf('--path');
938
+ const sessionsPath = pathIdx !== -1 ? args[pathIdx + 1] : null;
939
+ const verboseFlag = args.includes('--verbose');
940
+ const jsonFlag = args.includes('--json');
941
+ await profilePipeline.cmdScanSessions(sessionsPath, { verbose: verboseFlag, json: jsonFlag }, raw);
942
+ break;
943
+ }
944
+
945
+ case 'extract-messages': {
946
+ const sessionIdx = args.indexOf('--session');
947
+ const sessionId = sessionIdx !== -1 ? args[sessionIdx + 1] : null;
948
+ const limitIdx = args.indexOf('--limit');
949
+ const limit = limitIdx !== -1 ? parseInt(args[limitIdx + 1], 10) : null;
950
+ const pathIdx = args.indexOf('--path');
951
+ const sessionsPath = pathIdx !== -1 ? args[pathIdx + 1] : null;
952
+ const projectArg = args[1];
953
+ if (!projectArg || projectArg.startsWith('--')) {
954
+ error('Usage: gsd-tools extract-messages <project> [--session <id>] [--limit N] [--path <dir>]\nRun scan-sessions first to see available projects.');
955
+ }
956
+ await profilePipeline.cmdExtractMessages(projectArg, { sessionId, limit }, raw, sessionsPath);
957
+ break;
958
+ }
959
+
960
+ case 'profile-sample': {
961
+ const pathIdx = args.indexOf('--path');
962
+ const sessionsPath = pathIdx !== -1 ? args[pathIdx + 1] : null;
963
+ const limitIdx = args.indexOf('--limit');
964
+ const limit = limitIdx !== -1 ? parseInt(args[limitIdx + 1], 10) : 150;
965
+ const maxPerIdx = args.indexOf('--max-per-project');
966
+ const maxPerProject = maxPerIdx !== -1 ? parseInt(args[maxPerIdx + 1], 10) : null;
967
+ const maxCharsIdx = args.indexOf('--max-chars');
968
+ const maxChars = maxCharsIdx !== -1 ? parseInt(args[maxCharsIdx + 1], 10) : 500;
969
+ await profilePipeline.cmdProfileSample(sessionsPath, { limit, maxPerProject, maxChars }, raw);
970
+ break;
971
+ }
972
+
973
+ // ─── Profile Output ──────────────────────────────────────────────────
974
+
975
+ case 'write-profile': {
976
+ const inputIdx = args.indexOf('--input');
977
+ const inputPath = inputIdx !== -1 ? args[inputIdx + 1] : null;
978
+ if (!inputPath) error('--input <analysis-json-path> is required');
979
+ const outputIdx = args.indexOf('--output');
980
+ const outputPath = outputIdx !== -1 ? args[outputIdx + 1] : null;
981
+ profileOutput.cmdWriteProfile(cwd, { input: inputPath, output: outputPath }, raw);
982
+ break;
983
+ }
984
+
985
+ case 'profile-questionnaire': {
986
+ const answersIdx = args.indexOf('--answers');
987
+ const answers = answersIdx !== -1 ? args[answersIdx + 1] : null;
988
+ profileOutput.cmdProfileQuestionnaire({ answers }, raw);
989
+ break;
990
+ }
991
+
992
+ case 'generate-dev-preferences': {
993
+ const analysisIdx = args.indexOf('--analysis');
994
+ const analysisPath = analysisIdx !== -1 ? args[analysisIdx + 1] : null;
995
+ const outputIdx = args.indexOf('--output');
996
+ const outputPath = outputIdx !== -1 ? args[outputIdx + 1] : null;
997
+ const stackIdx = args.indexOf('--stack');
998
+ const stack = stackIdx !== -1 ? args[stackIdx + 1] : null;
999
+ profileOutput.cmdGenerateDevPreferences(cwd, { analysis: analysisPath, output: outputPath, stack }, raw);
1000
+ break;
1001
+ }
1002
+
1003
+ case 'generate-claude-profile': {
1004
+ const analysisIdx = args.indexOf('--analysis');
1005
+ const analysisPath = analysisIdx !== -1 ? args[analysisIdx + 1] : null;
1006
+ const outputIdx = args.indexOf('--output');
1007
+ const outputPath = outputIdx !== -1 ? args[outputIdx + 1] : null;
1008
+ const globalFlag = args.includes('--global');
1009
+ profileOutput.cmdGenerateClaudeProfile(cwd, { analysis: analysisPath, output: outputPath, global: globalFlag }, raw);
1010
+ break;
1011
+ }
1012
+
1013
+ case 'generate-claude-md': {
1014
+ const outputIdx = args.indexOf('--output');
1015
+ const outputPath = outputIdx !== -1 ? args[outputIdx + 1] : null;
1016
+ const autoFlag = args.includes('--auto');
1017
+ const forceFlag = args.includes('--force');
1018
+ profileOutput.cmdGenerateClaudeMd(cwd, { output: outputPath, auto: autoFlag, force: forceFlag }, raw);
1019
+ break;
1020
+ }
1021
+
1022
+ case 'workstream': {
1023
+ const subcommand = args[1];
1024
+ if (subcommand === 'create') {
1025
+ const migrateNameIdx = args.indexOf('--migrate-name');
1026
+ const noMigrate = args.includes('--no-migrate');
1027
+ workstream.cmdWorkstreamCreate(cwd, args[2], {
1028
+ migrate: !noMigrate,
1029
+ migrateName: migrateNameIdx !== -1 ? args[migrateNameIdx + 1] : null,
1030
+ }, raw);
1031
+ } else if (subcommand === 'list') {
1032
+ workstream.cmdWorkstreamList(cwd, raw);
1033
+ } else if (subcommand === 'status') {
1034
+ workstream.cmdWorkstreamStatus(cwd, args[2], raw);
1035
+ } else if (subcommand === 'complete') {
1036
+ workstream.cmdWorkstreamComplete(cwd, args[2], {}, raw);
1037
+ } else if (subcommand === 'set') {
1038
+ workstream.cmdWorkstreamSet(cwd, args[2], raw);
1039
+ } else if (subcommand === 'get') {
1040
+ workstream.cmdWorkstreamGet(cwd, raw);
1041
+ } else if (subcommand === 'progress') {
1042
+ workstream.cmdWorkstreamProgress(cwd, raw);
1043
+ } else {
1044
+ error('Unknown workstream subcommand. Available: create, list, status, complete, set, get, progress');
1045
+ }
1046
+ break;
1047
+ }
1048
+
1049
+ // ─── Intel ────────────────────────────────────────────────────────────
1050
+
1051
+ case 'intel': {
1052
+ const intel = require('./lib/intel.cjs');
1053
+ const subcommand = args[1];
1054
+ if (subcommand === 'query') {
1055
+ const term = args[2];
1056
+ if (!term) error('Usage: gsd-tools intel query <term>');
1057
+ const planningDir = path.join(cwd, '.planning');
1058
+ core.output(intel.intelQuery(term, planningDir), raw);
1059
+ } else if (subcommand === 'status') {
1060
+ const planningDir = path.join(cwd, '.planning');
1061
+ const status = intel.intelStatus(planningDir);
1062
+ if (!raw && status.files) {
1063
+ for (const file of Object.values(status.files)) {
1064
+ if (file.updated_at) {
1065
+ file.updated_at = core.timeAgo(new Date(file.updated_at));
1066
+ }
1067
+ }
1068
+ }
1069
+ core.output(status, raw);
1070
+ } else if (subcommand === 'diff') {
1071
+ const planningDir = path.join(cwd, '.planning');
1072
+ core.output(intel.intelDiff(planningDir), raw);
1073
+ } else if (subcommand === 'snapshot') {
1074
+ const planningDir = path.join(cwd, '.planning');
1075
+ core.output(intel.intelSnapshot(planningDir), raw);
1076
+ } else if (subcommand === 'patch-meta') {
1077
+ const filePath = args[2];
1078
+ if (!filePath) error('Usage: gsd-tools intel patch-meta <file-path>');
1079
+ core.output(intel.intelPatchMeta(path.resolve(cwd, filePath)), raw);
1080
+ } else if (subcommand === 'validate') {
1081
+ const planningDir = path.join(cwd, '.planning');
1082
+ core.output(intel.intelValidate(planningDir), raw);
1083
+ } else if (subcommand === 'extract-exports') {
1084
+ const filePath = args[2];
1085
+ if (!filePath) error('Usage: gsd-tools intel extract-exports <file-path>');
1086
+ core.output(intel.intelExtractExports(path.resolve(cwd, filePath)), raw);
1087
+ } else if (subcommand === 'update') {
1088
+ const planningDir = path.join(cwd, '.planning');
1089
+ core.output(intel.intelUpdate(planningDir), raw);
1090
+ } else {
1091
+ error('Unknown intel subcommand. Available: query, status, update, diff, snapshot, patch-meta, validate, extract-exports');
1092
+ }
1093
+ break;
1094
+ }
1095
+
1096
+ // ─── Graphify ──────────────────────────────────────────────────────────
1097
+
1098
+ case 'graphify': {
1099
+ const graphify = require('./lib/graphify.cjs');
1100
+ const subcommand = args[1];
1101
+ if (subcommand === 'query') {
1102
+ const term = args[2];
1103
+ if (!term) error('Usage: gsd-tools graphify query <term>');
1104
+ const budgetIdx = args.indexOf('--budget');
1105
+ const budget = budgetIdx !== -1 ? parseInt(args[budgetIdx + 1], 10) : null;
1106
+ core.output(graphify.graphifyQuery(cwd, term, { budget }), raw);
1107
+ } else if (subcommand === 'status') {
1108
+ core.output(graphify.graphifyStatus(cwd), raw);
1109
+ } else if (subcommand === 'diff') {
1110
+ core.output(graphify.graphifyDiff(cwd), raw);
1111
+ } else if (subcommand === 'build') {
1112
+ if (args[2] === 'snapshot') {
1113
+ core.output(graphify.writeSnapshot(cwd), raw);
1114
+ } else {
1115
+ core.output(graphify.graphifyBuild(cwd), raw);
1116
+ }
1117
+ } else {
1118
+ error('Unknown graphify subcommand. Available: build, query, status, diff');
1119
+ }
1120
+ break;
1121
+ }
1122
+
1123
+ // ─── Documentation ────────────────────────────────────────────────────
1124
+
1125
+ case 'docs-init': {
1126
+ docs.cmdDocsInit(cwd, raw);
1127
+ break;
1128
+ }
1129
+
1130
+ // ─── Learnings ─────────────────────────────────────────────────────────
1131
+
1132
+ case 'learnings': {
1133
+ const subcommand = args[1];
1134
+ if (subcommand === 'list') {
1135
+ learnings.cmdLearningsList(raw);
1136
+ } else if (subcommand === 'query') {
1137
+ const tagIdx = args.indexOf('--tag');
1138
+ const tag = tagIdx !== -1 ? args[tagIdx + 1] : null;
1139
+ if (!tag) error('Usage: gsd-tools learnings query --tag <tag>');
1140
+ learnings.cmdLearningsQuery(tag, raw);
1141
+ } else if (subcommand === 'copy') {
1142
+ learnings.cmdLearningsCopy(cwd, raw);
1143
+ } else if (subcommand === 'prune') {
1144
+ const olderIdx = args.indexOf('--older-than');
1145
+ const olderThan = olderIdx !== -1 ? args[olderIdx + 1] : null;
1146
+ if (!olderThan) error('Usage: gsd-tools learnings prune --older-than <duration>');
1147
+ learnings.cmdLearningsPrune(olderThan, raw);
1148
+ } else if (subcommand === 'delete') {
1149
+ const id = args[2];
1150
+ if (!id) error('Usage: gsd-tools learnings delete <id>');
1151
+ learnings.cmdLearningsDelete(id, raw);
1152
+ } else {
1153
+ error('Unknown learnings subcommand. Available: list, query, copy, prune, delete');
1154
+ }
1155
+ break;
1156
+ }
1157
+
1158
+ // ─── detect-custom-files ───────────────────────────────────────────────
1159
+ // Detect user-added files inside GSD-managed directories that are not
1160
+ // tracked in gsd-file-manifest.json. Used by the update workflow to back
1161
+ // up custom files before the installer wipes those directories.
1162
+ //
1163
+ // This replaces the fragile bash pattern:
1164
+ // MANIFEST_FILES=$(node -e "require('$RUNTIME_DIR/...')" 2>/dev/null)
1165
+ // ${filepath#$RUNTIME_DIR/} # unreliable path stripping
1166
+ // which silently returns CUSTOM_COUNT=0 when $RUNTIME_DIR is unset or
1167
+ // when the stripped path does not match the manifest key format (#1997).
1168
+
1169
+ case 'detect-custom-files': {
1170
+ const configDirIdx = args.indexOf('--config-dir');
1171
+ const configDir = configDirIdx !== -1 ? args[configDirIdx + 1] : null;
1172
+ if (!configDir) {
1173
+ error('Usage: gsd-tools detect-custom-files --config-dir <path>');
1174
+ }
1175
+ const resolvedConfigDir = path.resolve(configDir);
1176
+ if (!fs.existsSync(resolvedConfigDir)) {
1177
+ error(`Config directory not found: ${resolvedConfigDir}`);
1178
+ }
1179
+
1180
+ const manifestPath = path.join(resolvedConfigDir, 'gsd-file-manifest.json');
1181
+ if (!fs.existsSync(manifestPath)) {
1182
+ // No manifest — cannot determine what is custom. Return empty list
1183
+ // (same behaviour as saveLocalPatches in install.js when no manifest).
1184
+ const out = { custom_files: [], custom_count: 0, manifest_found: false };
1185
+ process.stdout.write(JSON.stringify(out, null, 2));
1186
+ break;
1187
+ }
1188
+
1189
+ let manifest;
1190
+ try {
1191
+ manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
1192
+ } catch {
1193
+ const out = { custom_files: [], custom_count: 0, manifest_found: false, error: 'manifest parse error' };
1194
+ process.stdout.write(JSON.stringify(out, null, 2));
1195
+ break;
1196
+ }
1197
+
1198
+ const manifestKeys = new Set(Object.keys(manifest.files || {}));
1199
+
1200
+ // GSD-managed directories to scan for user-added files.
1201
+ // These are the directories the installer wipes on update.
1202
+ const GSD_MANAGED_DIRS = [
1203
+ 'get-shit-done',
1204
+ 'agents',
1205
+ path.join('commands', 'gsd'),
1206
+ 'hooks',
1207
+ // OpenCode/Kilo flat command dir
1208
+ 'command',
1209
+ // Codex/Copilot skills dir
1210
+ 'skills',
1211
+ ];
1212
+
1213
+ function walkDir(dir, baseDir) {
1214
+ const results = [];
1215
+ if (!fs.existsSync(dir)) return results;
1216
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
1217
+ const fullPath = path.join(dir, entry.name);
1218
+ if (entry.isDirectory()) {
1219
+ results.push(...walkDir(fullPath, baseDir));
1220
+ } else {
1221
+ // Use forward slashes for cross-platform manifest key compatibility
1222
+ const relPath = path.relative(baseDir, fullPath).replace(/\\/g, '/');
1223
+ results.push(relPath);
1224
+ }
1225
+ }
1226
+ return results;
1227
+ }
1228
+
1229
+ const customFiles = [];
1230
+ for (const managedDir of GSD_MANAGED_DIRS) {
1231
+ const absDir = path.join(resolvedConfigDir, managedDir);
1232
+ if (!fs.existsSync(absDir)) continue;
1233
+ for (const relPath of walkDir(absDir, resolvedConfigDir)) {
1234
+ if (!manifestKeys.has(relPath)) {
1235
+ customFiles.push(relPath);
1236
+ }
1237
+ }
1238
+ }
1239
+
1240
+ const out = {
1241
+ custom_files: customFiles,
1242
+ custom_count: customFiles.length,
1243
+ manifest_found: true,
1244
+ manifest_version: manifest.version || null,
1245
+ };
1246
+ process.stdout.write(JSON.stringify(out, null, 2));
1247
+ break;
1248
+ }
1249
+
1250
+ // ─── GSD-2 Reverse Migration ───────────────────────────────────────────
1251
+
1252
+ case 'from-gsd2': {
1253
+ const gsd2Import = require('./lib/gsd2-import.cjs');
1254
+ gsd2Import.cmdFromGsd2(args.slice(1), cwd, raw);
1255
+ break;
1256
+ }
1257
+
1258
+ default:
1259
+ error(`Unknown command: ${command}`);
1260
+ }
1261
+ }
1262
+
1263
+ main();