@jokerized/getresearchdone 0.4.1

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 (711) hide show
  1. package/.claude-plugin/plugin.json +103 -0
  2. package/README.md +211 -0
  3. package/agents/grd-baseline-assessor.md +684 -0
  4. package/agents/grd-code-reviewer.md +300 -0
  5. package/agents/grd-codebase-mapper.md +355 -0
  6. package/agents/grd-critique-agent.md +119 -0
  7. package/agents/grd-debugger.md +519 -0
  8. package/agents/grd-deep-diver.md +737 -0
  9. package/agents/grd-eval-planner.md +913 -0
  10. package/agents/grd-eval-reporter.md +717 -0
  11. package/agents/grd-executor.md +683 -0
  12. package/agents/grd-feasibility-analyst.md +624 -0
  13. package/agents/grd-integration-checker.md +367 -0
  14. package/agents/grd-knowledge-miner.md +81 -0
  15. package/agents/grd-migrator.md +88 -0
  16. package/agents/grd-phase-researcher.md +697 -0
  17. package/agents/grd-plan-checker.md +443 -0
  18. package/agents/grd-planner.md +1532 -0
  19. package/agents/grd-product-owner.md +562 -0
  20. package/agents/grd-project-researcher.md +513 -0
  21. package/agents/grd-research-synthesizer.md +273 -0
  22. package/agents/grd-roadmapper.md +798 -0
  23. package/agents/grd-surveyor.md +566 -0
  24. package/agents/grd-verifier.md +893 -0
  25. package/bin/gd.js +4 -0
  26. package/bin/gd.ts +227 -0
  27. package/bin/grd-manifest.js +4 -0
  28. package/bin/grd-manifest.ts +286 -0
  29. package/bin/grd-mcp-server.js +4 -0
  30. package/bin/grd-mcp-server.ts +124 -0
  31. package/bin/grd-tools.js +4 -0
  32. package/bin/grd-tools.ts +2471 -0
  33. package/bin/postinstall.js +4 -0
  34. package/bin/postinstall.ts +80 -0
  35. package/commands/add-phase.md +123 -0
  36. package/commands/add-todo.md +87 -0
  37. package/commands/assess-baseline.md +289 -0
  38. package/commands/autopilot.md +100 -0
  39. package/commands/autoplan.md +55 -0
  40. package/commands/check-todos.md +87 -0
  41. package/commands/compare-methods.md +262 -0
  42. package/commands/complete-milestone.md +225 -0
  43. package/commands/debug.md +372 -0
  44. package/commands/deep-dive.md +288 -0
  45. package/commands/discover.md +281 -0
  46. package/commands/discuss-phase.md +188 -0
  47. package/commands/discuss.md +55 -0
  48. package/commands/eval-report.md +310 -0
  49. package/commands/evolve.md +79 -0
  50. package/commands/execute-phase.md +1017 -0
  51. package/commands/feasibility.md +292 -0
  52. package/commands/help.md +407 -0
  53. package/commands/init.md +1508 -0
  54. package/commands/insert-phase.md +113 -0
  55. package/commands/iterate.md +327 -0
  56. package/commands/list-phase-assumptions.md +217 -0
  57. package/commands/long-term-roadmap.md +202 -0
  58. package/commands/map-codebase.md +111 -0
  59. package/commands/migrate.md +159 -0
  60. package/commands/new-milestone.md +169 -0
  61. package/commands/pause-work.md +83 -0
  62. package/commands/plan-milestone-gaps.md +373 -0
  63. package/commands/plan-phase.md +655 -0
  64. package/commands/principles.md +328 -0
  65. package/commands/product-plan.md +319 -0
  66. package/commands/progress.md +481 -0
  67. package/commands/quick.md +167 -0
  68. package/commands/reapply-patches.md +154 -0
  69. package/commands/remove-phase.md +97 -0
  70. package/commands/requirement.md +96 -0
  71. package/commands/resume-project.md +113 -0
  72. package/commands/settings.md +1144 -0
  73. package/commands/survey.md +242 -0
  74. package/commands/sync.md +246 -0
  75. package/commands/tracker-setup.md +322 -0
  76. package/commands/update.md +202 -0
  77. package/commands/verify-phase.md +335 -0
  78. package/commands/verify-work.md +701 -0
  79. package/commands/wireup.md +29 -0
  80. package/dist/bin/gd.d.ts +3 -0
  81. package/dist/bin/gd.d.ts.map +1 -0
  82. package/dist/bin/gd.js +178 -0
  83. package/dist/bin/gd.js.map +1 -0
  84. package/dist/bin/grd-manifest.d.ts +3 -0
  85. package/dist/bin/grd-manifest.d.ts.map +1 -0
  86. package/dist/bin/grd-manifest.js +202 -0
  87. package/dist/bin/grd-manifest.js.map +1 -0
  88. package/dist/bin/grd-mcp-server.d.ts +3 -0
  89. package/dist/bin/grd-mcp-server.d.ts.map +1 -0
  90. package/dist/bin/grd-mcp-server.js +71 -0
  91. package/dist/bin/grd-mcp-server.js.map +1 -0
  92. package/dist/bin/grd-tools.d.ts +3 -0
  93. package/dist/bin/grd-tools.d.ts.map +1 -0
  94. package/dist/bin/grd-tools.js +1680 -0
  95. package/dist/bin/grd-tools.js.map +1 -0
  96. package/dist/bin/postinstall.d.ts +3 -0
  97. package/dist/bin/postinstall.d.ts.map +1 -0
  98. package/dist/bin/postinstall.js +61 -0
  99. package/dist/bin/postinstall.js.map +1 -0
  100. package/dist/lib/autopilot-milestone.d.ts +2 -0
  101. package/dist/lib/autopilot-milestone.d.ts.map +1 -0
  102. package/dist/lib/autopilot-milestone.js +94 -0
  103. package/dist/lib/autopilot-milestone.js.map +1 -0
  104. package/dist/lib/autopilot-pipeline.d.ts +2 -0
  105. package/dist/lib/autopilot-pipeline.d.ts.map +1 -0
  106. package/dist/lib/autopilot-pipeline.js +830 -0
  107. package/dist/lib/autopilot-pipeline.js.map +1 -0
  108. package/dist/lib/autopilot-waves.d.ts +2 -0
  109. package/dist/lib/autopilot-waves.d.ts.map +1 -0
  110. package/dist/lib/autopilot-waves.js +266 -0
  111. package/dist/lib/autopilot-waves.js.map +1 -0
  112. package/dist/lib/autopilot.d.ts +2 -0
  113. package/dist/lib/autopilot.d.ts.map +1 -0
  114. package/dist/lib/autopilot.js +1314 -0
  115. package/dist/lib/autopilot.js.map +1 -0
  116. package/dist/lib/autoplan.d.ts +2 -0
  117. package/dist/lib/autoplan.d.ts.map +1 -0
  118. package/dist/lib/autoplan.js +198 -0
  119. package/dist/lib/autoplan.js.map +1 -0
  120. package/dist/lib/autoresearch.d.ts +2 -0
  121. package/dist/lib/autoresearch.d.ts.map +1 -0
  122. package/dist/lib/autoresearch.js +626 -0
  123. package/dist/lib/autoresearch.js.map +1 -0
  124. package/dist/lib/backend.d.ts +2 -0
  125. package/dist/lib/backend.d.ts.map +1 -0
  126. package/dist/lib/backend.js +1036 -0
  127. package/dist/lib/backend.js.map +1 -0
  128. package/dist/lib/benchmark.d.ts +99 -0
  129. package/dist/lib/benchmark.d.ts.map +1 -0
  130. package/dist/lib/benchmark.js +278 -0
  131. package/dist/lib/benchmark.js.map +1 -0
  132. package/dist/lib/citations.d.ts +2 -0
  133. package/dist/lib/citations.d.ts.map +1 -0
  134. package/dist/lib/citations.js +642 -0
  135. package/dist/lib/citations.js.map +1 -0
  136. package/dist/lib/cleanup.d.ts +2 -0
  137. package/dist/lib/cleanup.d.ts.map +1 -0
  138. package/dist/lib/cleanup.js +1222 -0
  139. package/dist/lib/cleanup.js.map +1 -0
  140. package/dist/lib/cli/adapters.d.ts +10 -0
  141. package/dist/lib/cli/adapters.d.ts.map +1 -0
  142. package/dist/lib/cli/adapters.js +27 -0
  143. package/dist/lib/cli/adapters.js.map +1 -0
  144. package/dist/lib/cli/agent.d.ts +17 -0
  145. package/dist/lib/cli/agent.d.ts.map +1 -0
  146. package/dist/lib/cli/agent.js +53 -0
  147. package/dist/lib/cli/agent.js.map +1 -0
  148. package/dist/lib/cli/index.d.ts +21 -0
  149. package/dist/lib/cli/index.d.ts.map +1 -0
  150. package/dist/lib/cli/index.js +264 -0
  151. package/dist/lib/cli/index.js.map +1 -0
  152. package/dist/lib/cli/output.d.ts +20 -0
  153. package/dist/lib/cli/output.d.ts.map +1 -0
  154. package/dist/lib/cli/output.js +22 -0
  155. package/dist/lib/cli/output.js.map +1 -0
  156. package/dist/lib/cli/scan-dispatch.d.ts +9 -0
  157. package/dist/lib/cli/scan-dispatch.d.ts.map +1 -0
  158. package/dist/lib/cli/scan-dispatch.js +107 -0
  159. package/dist/lib/cli/scan-dispatch.js.map +1 -0
  160. package/dist/lib/cli/tools.d.ts +16 -0
  161. package/dist/lib/cli/tools.d.ts.map +1 -0
  162. package/dist/lib/cli/tools.js +168 -0
  163. package/dist/lib/cli/tools.js.map +1 -0
  164. package/dist/lib/commands/_dashboard-parsers.d.ts +2 -0
  165. package/dist/lib/commands/_dashboard-parsers.d.ts.map +1 -0
  166. package/dist/lib/commands/_dashboard-parsers.js +192 -0
  167. package/dist/lib/commands/_dashboard-parsers.js.map +1 -0
  168. package/dist/lib/commands/analysis.d.ts +2 -0
  169. package/dist/lib/commands/analysis.d.ts.map +1 -0
  170. package/dist/lib/commands/analysis.js +1418 -0
  171. package/dist/lib/commands/analysis.js.map +1 -0
  172. package/dist/lib/commands/assumptions.d.ts +2 -0
  173. package/dist/lib/commands/assumptions.d.ts.map +1 -0
  174. package/dist/lib/commands/assumptions.js +166 -0
  175. package/dist/lib/commands/assumptions.js.map +1 -0
  176. package/dist/lib/commands/blame.d.ts +2 -0
  177. package/dist/lib/commands/blame.d.ts.map +1 -0
  178. package/dist/lib/commands/blame.js +133 -0
  179. package/dist/lib/commands/blame.js.map +1 -0
  180. package/dist/lib/commands/budget.d.ts +2 -0
  181. package/dist/lib/commands/budget.d.ts.map +1 -0
  182. package/dist/lib/commands/budget.js +100 -0
  183. package/dist/lib/commands/budget.js.map +1 -0
  184. package/dist/lib/commands/check-plans.d.ts +2 -0
  185. package/dist/lib/commands/check-plans.d.ts.map +1 -0
  186. package/dist/lib/commands/check-plans.js +190 -0
  187. package/dist/lib/commands/check-plans.js.map +1 -0
  188. package/dist/lib/commands/config.d.ts +2 -0
  189. package/dist/lib/commands/config.d.ts.map +1 -0
  190. package/dist/lib/commands/config.js +188 -0
  191. package/dist/lib/commands/config.js.map +1 -0
  192. package/dist/lib/commands/dashboard.d.ts +2 -0
  193. package/dist/lib/commands/dashboard.d.ts.map +1 -0
  194. package/dist/lib/commands/dashboard.js +466 -0
  195. package/dist/lib/commands/dashboard.js.map +1 -0
  196. package/dist/lib/commands/estimate.d.ts +2 -0
  197. package/dist/lib/commands/estimate.d.ts.map +1 -0
  198. package/dist/lib/commands/estimate.js +148 -0
  199. package/dist/lib/commands/estimate.js.map +1 -0
  200. package/dist/lib/commands/eval-diff.d.ts +2 -0
  201. package/dist/lib/commands/eval-diff.d.ts.map +1 -0
  202. package/dist/lib/commands/eval-diff.js +213 -0
  203. package/dist/lib/commands/eval-diff.js.map +1 -0
  204. package/dist/lib/commands/freshness.d.ts +2 -0
  205. package/dist/lib/commands/freshness.d.ts.map +1 -0
  206. package/dist/lib/commands/freshness.js +163 -0
  207. package/dist/lib/commands/freshness.js.map +1 -0
  208. package/dist/lib/commands/health.d.ts +2 -0
  209. package/dist/lib/commands/health.d.ts.map +1 -0
  210. package/dist/lib/commands/health.js +435 -0
  211. package/dist/lib/commands/health.js.map +1 -0
  212. package/dist/lib/commands/index.d.ts +2 -0
  213. package/dist/lib/commands/index.d.ts.map +1 -0
  214. package/dist/lib/commands/index.js +128 -0
  215. package/dist/lib/commands/index.js.map +1 -0
  216. package/dist/lib/commands/install.d.ts +56 -0
  217. package/dist/lib/commands/install.d.ts.map +1 -0
  218. package/dist/lib/commands/install.js +214 -0
  219. package/dist/lib/commands/install.js.map +1 -0
  220. package/dist/lib/commands/knowhow-aggregator.d.ts +2 -0
  221. package/dist/lib/commands/knowhow-aggregator.d.ts.map +1 -0
  222. package/dist/lib/commands/knowhow-aggregator.js +279 -0
  223. package/dist/lib/commands/knowhow-aggregator.js.map +1 -0
  224. package/dist/lib/commands/knowledge-search.d.ts +2 -0
  225. package/dist/lib/commands/knowledge-search.d.ts.map +1 -0
  226. package/dist/lib/commands/knowledge-search.js +113 -0
  227. package/dist/lib/commands/knowledge-search.js.map +1 -0
  228. package/dist/lib/commands/long-term-roadmap.d.ts +2 -0
  229. package/dist/lib/commands/long-term-roadmap.d.ts.map +1 -0
  230. package/dist/lib/commands/long-term-roadmap.js +272 -0
  231. package/dist/lib/commands/long-term-roadmap.js.map +1 -0
  232. package/dist/lib/commands/patterns.d.ts +91 -0
  233. package/dist/lib/commands/patterns.d.ts.map +1 -0
  234. package/dist/lib/commands/patterns.js +391 -0
  235. package/dist/lib/commands/patterns.js.map +1 -0
  236. package/dist/lib/commands/phase-info.d.ts +2 -0
  237. package/dist/lib/commands/phase-info.d.ts.map +1 -0
  238. package/dist/lib/commands/phase-info.js +509 -0
  239. package/dist/lib/commands/phase-info.js.map +1 -0
  240. package/dist/lib/commands/plan-lint.d.ts +56 -0
  241. package/dist/lib/commands/plan-lint.d.ts.map +1 -0
  242. package/dist/lib/commands/plan-lint.js +481 -0
  243. package/dist/lib/commands/plan-lint.js.map +1 -0
  244. package/dist/lib/commands/plan-phase.d.ts +53 -0
  245. package/dist/lib/commands/plan-phase.d.ts.map +1 -0
  246. package/dist/lib/commands/plan-phase.js +288 -0
  247. package/dist/lib/commands/plan-phase.js.map +1 -0
  248. package/dist/lib/commands/progress.d.ts +2 -0
  249. package/dist/lib/commands/progress.d.ts.map +1 -0
  250. package/dist/lib/commands/progress.js +266 -0
  251. package/dist/lib/commands/progress.js.map +1 -0
  252. package/dist/lib/commands/quality.d.ts +2 -0
  253. package/dist/lib/commands/quality.d.ts.map +1 -0
  254. package/dist/lib/commands/quality.js +80 -0
  255. package/dist/lib/commands/quality.js.map +1 -0
  256. package/dist/lib/commands/rollback.d.ts +2 -0
  257. package/dist/lib/commands/rollback.d.ts.map +1 -0
  258. package/dist/lib/commands/rollback.js +145 -0
  259. package/dist/lib/commands/rollback.js.map +1 -0
  260. package/dist/lib/commands/scan.d.ts +25 -0
  261. package/dist/lib/commands/scan.d.ts.map +1 -0
  262. package/dist/lib/commands/scan.js +28 -0
  263. package/dist/lib/commands/scan.js.map +1 -0
  264. package/dist/lib/commands/search.d.ts +2 -0
  265. package/dist/lib/commands/search.d.ts.map +1 -0
  266. package/dist/lib/commands/search.js +212 -0
  267. package/dist/lib/commands/search.js.map +1 -0
  268. package/dist/lib/commands/select-candidate.d.ts +128 -0
  269. package/dist/lib/commands/select-candidate.d.ts.map +1 -0
  270. package/dist/lib/commands/select-candidate.js +518 -0
  271. package/dist/lib/commands/select-candidate.js.map +1 -0
  272. package/dist/lib/commands/singularity.d.ts +2 -0
  273. package/dist/lib/commands/singularity.d.ts.map +1 -0
  274. package/dist/lib/commands/singularity.js +185 -0
  275. package/dist/lib/commands/singularity.js.map +1 -0
  276. package/dist/lib/commands/slug-timestamp.d.ts +2 -0
  277. package/dist/lib/commands/slug-timestamp.d.ts.map +1 -0
  278. package/dist/lib/commands/slug-timestamp.js +54 -0
  279. package/dist/lib/commands/slug-timestamp.js.map +1 -0
  280. package/dist/lib/commands/tail.d.ts +2 -0
  281. package/dist/lib/commands/tail.d.ts.map +1 -0
  282. package/dist/lib/commands/tail.js +100 -0
  283. package/dist/lib/commands/tail.js.map +1 -0
  284. package/dist/lib/commands/todo.d.ts +2 -0
  285. package/dist/lib/commands/todo.d.ts.map +1 -0
  286. package/dist/lib/commands/todo.js +200 -0
  287. package/dist/lib/commands/todo.js.map +1 -0
  288. package/dist/lib/commands/watch.d.ts +2 -0
  289. package/dist/lib/commands/watch.d.ts.map +1 -0
  290. package/dist/lib/commands/watch.js +72 -0
  291. package/dist/lib/commands/watch.js.map +1 -0
  292. package/dist/lib/complexity.d.ts +55 -0
  293. package/dist/lib/complexity.d.ts.map +1 -0
  294. package/dist/lib/complexity.js +80 -0
  295. package/dist/lib/complexity.js.map +1 -0
  296. package/dist/lib/context/agents.d.ts +2 -0
  297. package/dist/lib/context/agents.d.ts.map +1 -0
  298. package/dist/lib/context/agents.js +344 -0
  299. package/dist/lib/context/agents.js.map +1 -0
  300. package/dist/lib/context/base.d.ts +2 -0
  301. package/dist/lib/context/base.d.ts.map +1 -0
  302. package/dist/lib/context/base.js +81 -0
  303. package/dist/lib/context/base.js.map +1 -0
  304. package/dist/lib/context/execute.d.ts +2 -0
  305. package/dist/lib/context/execute.d.ts.map +1 -0
  306. package/dist/lib/context/execute.js +753 -0
  307. package/dist/lib/context/execute.js.map +1 -0
  308. package/dist/lib/context/index.d.ts +2 -0
  309. package/dist/lib/context/index.d.ts.map +1 -0
  310. package/dist/lib/context/index.js +88 -0
  311. package/dist/lib/context/index.js.map +1 -0
  312. package/dist/lib/context/progress.d.ts +2 -0
  313. package/dist/lib/context/progress.d.ts.map +1 -0
  314. package/dist/lib/context/progress.js +178 -0
  315. package/dist/lib/context/progress.js.map +1 -0
  316. package/dist/lib/context/project.d.ts +2 -0
  317. package/dist/lib/context/project.d.ts.map +1 -0
  318. package/dist/lib/context/project.js +413 -0
  319. package/dist/lib/context/project.js.map +1 -0
  320. package/dist/lib/context/research.d.ts +2 -0
  321. package/dist/lib/context/research.d.ts.map +1 -0
  322. package/dist/lib/context/research.js +466 -0
  323. package/dist/lib/context/research.js.map +1 -0
  324. package/dist/lib/dead-ends.d.ts +28 -0
  325. package/dist/lib/dead-ends.d.ts.map +1 -0
  326. package/dist/lib/dead-ends.js +451 -0
  327. package/dist/lib/dead-ends.js.map +1 -0
  328. package/dist/lib/deps.d.ts +2 -0
  329. package/dist/lib/deps.d.ts.map +1 -0
  330. package/dist/lib/deps.js +630 -0
  331. package/dist/lib/deps.js.map +1 -0
  332. package/dist/lib/discussion.d.ts +2 -0
  333. package/dist/lib/discussion.d.ts.map +1 -0
  334. package/dist/lib/discussion.js +1041 -0
  335. package/dist/lib/discussion.js.map +1 -0
  336. package/dist/lib/drift.d.ts +36 -0
  337. package/dist/lib/drift.d.ts.map +1 -0
  338. package/dist/lib/drift.js +481 -0
  339. package/dist/lib/drift.js.map +1 -0
  340. package/dist/lib/evolve/_dimensions-features.d.ts +2 -0
  341. package/dist/lib/evolve/_dimensions-features.d.ts.map +1 -0
  342. package/dist/lib/evolve/_dimensions-features.js +369 -0
  343. package/dist/lib/evolve/_dimensions-features.js.map +1 -0
  344. package/dist/lib/evolve/_dimensions.d.ts +2 -0
  345. package/dist/lib/evolve/_dimensions.d.ts.map +1 -0
  346. package/dist/lib/evolve/_dimensions.js +358 -0
  347. package/dist/lib/evolve/_dimensions.js.map +1 -0
  348. package/dist/lib/evolve/_product-ideation.d.ts +2 -0
  349. package/dist/lib/evolve/_product-ideation.d.ts.map +1 -0
  350. package/dist/lib/evolve/_product-ideation.js +281 -0
  351. package/dist/lib/evolve/_product-ideation.js.map +1 -0
  352. package/dist/lib/evolve/_prompts.d.ts +2 -0
  353. package/dist/lib/evolve/_prompts.d.ts.map +1 -0
  354. package/dist/lib/evolve/_prompts.js +153 -0
  355. package/dist/lib/evolve/_prompts.js.map +1 -0
  356. package/dist/lib/evolve/cli.d.ts +2 -0
  357. package/dist/lib/evolve/cli.d.ts.map +1 -0
  358. package/dist/lib/evolve/cli.js +224 -0
  359. package/dist/lib/evolve/cli.js.map +1 -0
  360. package/dist/lib/evolve/discovery.d.ts +2 -0
  361. package/dist/lib/evolve/discovery.d.ts.map +1 -0
  362. package/dist/lib/evolve/discovery.js +391 -0
  363. package/dist/lib/evolve/discovery.js.map +1 -0
  364. package/dist/lib/evolve/index.d.ts +2 -0
  365. package/dist/lib/evolve/index.d.ts.map +1 -0
  366. package/dist/lib/evolve/index.js +88 -0
  367. package/dist/lib/evolve/index.js.map +1 -0
  368. package/dist/lib/evolve/orchestrator.d.ts +2 -0
  369. package/dist/lib/evolve/orchestrator.d.ts.map +1 -0
  370. package/dist/lib/evolve/orchestrator.js +851 -0
  371. package/dist/lib/evolve/orchestrator.js.map +1 -0
  372. package/dist/lib/evolve/scoring.d.ts +2 -0
  373. package/dist/lib/evolve/scoring.d.ts.map +1 -0
  374. package/dist/lib/evolve/scoring.js +118 -0
  375. package/dist/lib/evolve/scoring.js.map +1 -0
  376. package/dist/lib/evolve/state.d.ts +2 -0
  377. package/dist/lib/evolve/state.d.ts.map +1 -0
  378. package/dist/lib/evolve/state.js +264 -0
  379. package/dist/lib/evolve/state.js.map +1 -0
  380. package/dist/lib/evolve/types.d.ts +249 -0
  381. package/dist/lib/evolve/types.d.ts.map +1 -0
  382. package/dist/lib/evolve/types.js +3 -0
  383. package/dist/lib/evolve/types.js.map +1 -0
  384. package/dist/lib/frontmatter.d.ts +2 -0
  385. package/dist/lib/frontmatter.d.ts.map +1 -0
  386. package/dist/lib/frontmatter.js +513 -0
  387. package/dist/lib/frontmatter.js.map +1 -0
  388. package/dist/lib/gates.d.ts +2 -0
  389. package/dist/lib/gates.d.ts.map +1 -0
  390. package/dist/lib/gates.js +578 -0
  391. package/dist/lib/gates.js.map +1 -0
  392. package/dist/lib/genome.d.ts +10 -0
  393. package/dist/lib/genome.d.ts.map +1 -0
  394. package/dist/lib/genome.js +368 -0
  395. package/dist/lib/genome.js.map +1 -0
  396. package/dist/lib/got.d.ts +2 -0
  397. package/dist/lib/got.d.ts.map +1 -0
  398. package/dist/lib/got.js +280 -0
  399. package/dist/lib/got.js.map +1 -0
  400. package/dist/lib/invariants.d.ts +2 -0
  401. package/dist/lib/invariants.d.ts.map +1 -0
  402. package/dist/lib/invariants.js +298 -0
  403. package/dist/lib/invariants.js.map +1 -0
  404. package/dist/lib/knowledge.d.ts +2 -0
  405. package/dist/lib/knowledge.d.ts.map +1 -0
  406. package/dist/lib/knowledge.js +658 -0
  407. package/dist/lib/knowledge.js.map +1 -0
  408. package/dist/lib/long-term-roadmap.d.ts +2 -0
  409. package/dist/lib/long-term-roadmap.d.ts.map +1 -0
  410. package/dist/lib/long-term-roadmap.js +602 -0
  411. package/dist/lib/long-term-roadmap.js.map +1 -0
  412. package/dist/lib/markdown-split.d.ts +2 -0
  413. package/dist/lib/markdown-split.d.ts.map +1 -0
  414. package/dist/lib/markdown-split.js +199 -0
  415. package/dist/lib/markdown-split.js.map +1 -0
  416. package/dist/lib/mcp-server.d.ts +2 -0
  417. package/dist/lib/mcp-server.d.ts.map +1 -0
  418. package/dist/lib/mcp-server.js +2424 -0
  419. package/dist/lib/mcp-server.js.map +1 -0
  420. package/dist/lib/metrics.d.ts +16 -0
  421. package/dist/lib/metrics.d.ts.map +1 -0
  422. package/dist/lib/metrics.js +48 -0
  423. package/dist/lib/metrics.js.map +1 -0
  424. package/dist/lib/overstory.d.ts +2 -0
  425. package/dist/lib/overstory.d.ts.map +1 -0
  426. package/dist/lib/overstory.js +211 -0
  427. package/dist/lib/overstory.js.map +1 -0
  428. package/dist/lib/parallel.d.ts +2 -0
  429. package/dist/lib/parallel.d.ts.map +1 -0
  430. package/dist/lib/parallel.js +349 -0
  431. package/dist/lib/parallel.js.map +1 -0
  432. package/dist/lib/paths.d.ts +2 -0
  433. package/dist/lib/paths.d.ts.map +1 -0
  434. package/dist/lib/paths.js +254 -0
  435. package/dist/lib/paths.js.map +1 -0
  436. package/dist/lib/phase-complete-llm.d.ts +22 -0
  437. package/dist/lib/phase-complete-llm.d.ts.map +1 -0
  438. package/dist/lib/phase-complete-llm.js +331 -0
  439. package/dist/lib/phase-complete-llm.js.map +1 -0
  440. package/dist/lib/phase-complete.d.ts +46 -0
  441. package/dist/lib/phase-complete.d.ts.map +1 -0
  442. package/dist/lib/phase-complete.js +278 -0
  443. package/dist/lib/phase-complete.js.map +1 -0
  444. package/dist/lib/phase-io.d.ts +2 -0
  445. package/dist/lib/phase-io.d.ts.map +1 -0
  446. package/dist/lib/phase-io.js +126 -0
  447. package/dist/lib/phase-io.js.map +1 -0
  448. package/dist/lib/phase.d.ts +2 -0
  449. package/dist/lib/phase.d.ts.map +1 -0
  450. package/dist/lib/phase.js +1344 -0
  451. package/dist/lib/phase.js.map +1 -0
  452. package/dist/lib/plan-tournament.d.ts +63 -0
  453. package/dist/lib/plan-tournament.d.ts.map +1 -0
  454. package/dist/lib/plan-tournament.js +353 -0
  455. package/dist/lib/plan-tournament.js.map +1 -0
  456. package/dist/lib/refinement.d.ts +74 -0
  457. package/dist/lib/refinement.d.ts.map +1 -0
  458. package/dist/lib/refinement.js +283 -0
  459. package/dist/lib/refinement.js.map +1 -0
  460. package/dist/lib/requirements.d.ts +2 -0
  461. package/dist/lib/requirements.d.ts.map +1 -0
  462. package/dist/lib/requirements.js +355 -0
  463. package/dist/lib/requirements.js.map +1 -0
  464. package/dist/lib/research-bundle.d.ts +2 -0
  465. package/dist/lib/research-bundle.d.ts.map +1 -0
  466. package/dist/lib/research-bundle.js +246 -0
  467. package/dist/lib/research-bundle.js.map +1 -0
  468. package/dist/lib/roadmap.d.ts +2 -0
  469. package/dist/lib/roadmap.d.ts.map +1 -0
  470. package/dist/lib/roadmap.js +541 -0
  471. package/dist/lib/roadmap.js.map +1 -0
  472. package/dist/lib/sample.d.ts +16 -0
  473. package/dist/lib/sample.d.ts.map +1 -0
  474. package/dist/lib/sample.js +20 -0
  475. package/dist/lib/sample.js.map +1 -0
  476. package/dist/lib/scaffold.d.ts +2 -0
  477. package/dist/lib/scaffold.d.ts.map +1 -0
  478. package/dist/lib/scaffold.js +355 -0
  479. package/dist/lib/scaffold.js.map +1 -0
  480. package/dist/lib/scan/_utils.d.ts +11 -0
  481. package/dist/lib/scan/_utils.d.ts.map +1 -0
  482. package/dist/lib/scan/_utils.js +36 -0
  483. package/dist/lib/scan/_utils.js.map +1 -0
  484. package/dist/lib/scan/base64.d.ts +15 -0
  485. package/dist/lib/scan/base64.d.ts.map +1 -0
  486. package/dist/lib/scan/base64.js +66 -0
  487. package/dist/lib/scan/base64.js.map +1 -0
  488. package/dist/lib/scan/ignorefile.d.ts +30 -0
  489. package/dist/lib/scan/ignorefile.d.ts.map +1 -0
  490. package/dist/lib/scan/ignorefile.js +101 -0
  491. package/dist/lib/scan/ignorefile.js.map +1 -0
  492. package/dist/lib/scan/injection.d.ts +14 -0
  493. package/dist/lib/scan/injection.d.ts.map +1 -0
  494. package/dist/lib/scan/injection.js +39 -0
  495. package/dist/lib/scan/injection.js.map +1 -0
  496. package/dist/lib/scan/patterns.d.ts +17 -0
  497. package/dist/lib/scan/patterns.d.ts.map +1 -0
  498. package/dist/lib/scan/patterns.js +123 -0
  499. package/dist/lib/scan/patterns.js.map +1 -0
  500. package/dist/lib/scan/strip-markdown.d.ts +7 -0
  501. package/dist/lib/scan/strip-markdown.d.ts.map +1 -0
  502. package/dist/lib/scan/strip-markdown.js +38 -0
  503. package/dist/lib/scan/strip-markdown.js.map +1 -0
  504. package/dist/lib/scan/types.d.ts +23 -0
  505. package/dist/lib/scan/types.d.ts.map +1 -0
  506. package/dist/lib/scan/types.js +3 -0
  507. package/dist/lib/scan/types.js.map +1 -0
  508. package/dist/lib/scheduler-wait.d.ts +2 -0
  509. package/dist/lib/scheduler-wait.d.ts.map +1 -0
  510. package/dist/lib/scheduler-wait.js +59 -0
  511. package/dist/lib/scheduler-wait.js.map +1 -0
  512. package/dist/lib/scheduler.d.ts +254 -0
  513. package/dist/lib/scheduler.d.ts.map +1 -0
  514. package/dist/lib/scheduler.js +1147 -0
  515. package/dist/lib/scheduler.js.map +1 -0
  516. package/dist/lib/state.d.ts +2 -0
  517. package/dist/lib/state.d.ts.map +1 -0
  518. package/dist/lib/state.js +744 -0
  519. package/dist/lib/state.js.map +1 -0
  520. package/dist/lib/think.d.ts +18 -0
  521. package/dist/lib/think.d.ts.map +1 -0
  522. package/dist/lib/think.js +317 -0
  523. package/dist/lib/think.js.map +1 -0
  524. package/dist/lib/tracker.d.ts +2 -0
  525. package/dist/lib/tracker.d.ts.map +1 -0
  526. package/dist/lib/tracker.js +1121 -0
  527. package/dist/lib/tracker.js.map +1 -0
  528. package/dist/lib/types.d.ts +1514 -0
  529. package/dist/lib/types.d.ts.map +1 -0
  530. package/dist/lib/types.js +4 -0
  531. package/dist/lib/types.js.map +1 -0
  532. package/dist/lib/utils.d.ts +2 -0
  533. package/dist/lib/utils.d.ts.map +1 -0
  534. package/dist/lib/utils.js +1363 -0
  535. package/dist/lib/utils.js.map +1 -0
  536. package/dist/lib/verify.d.ts +2 -0
  537. package/dist/lib/verify.d.ts.map +1 -0
  538. package/dist/lib/verify.js +1153 -0
  539. package/dist/lib/verify.js.map +1 -0
  540. package/dist/lib/wireup/autofix.d.ts +2 -0
  541. package/dist/lib/wireup/autofix.d.ts.map +1 -0
  542. package/dist/lib/wireup/autofix.js +188 -0
  543. package/dist/lib/wireup/autofix.js.map +1 -0
  544. package/dist/lib/wireup/cli.d.ts +2 -0
  545. package/dist/lib/wireup/cli.d.ts.map +1 -0
  546. package/dist/lib/wireup/cli.js +194 -0
  547. package/dist/lib/wireup/cli.js.map +1 -0
  548. package/dist/lib/wireup/detection.d.ts +47 -0
  549. package/dist/lib/wireup/detection.d.ts.map +1 -0
  550. package/dist/lib/wireup/detection.js +410 -0
  551. package/dist/lib/wireup/detection.js.map +1 -0
  552. package/dist/lib/wireup/discovery.d.ts +2 -0
  553. package/dist/lib/wireup/discovery.d.ts.map +1 -0
  554. package/dist/lib/wireup/discovery.js +934 -0
  555. package/dist/lib/wireup/discovery.js.map +1 -0
  556. package/dist/lib/wireup/execution.d.ts +2 -0
  557. package/dist/lib/wireup/execution.d.ts.map +1 -0
  558. package/dist/lib/wireup/execution.js +573 -0
  559. package/dist/lib/wireup/execution.js.map +1 -0
  560. package/dist/lib/wireup/index.d.ts +2 -0
  561. package/dist/lib/wireup/index.d.ts.map +1 -0
  562. package/dist/lib/wireup/index.js +85 -0
  563. package/dist/lib/wireup/index.js.map +1 -0
  564. package/dist/lib/wireup/orchestrator.d.ts +2 -0
  565. package/dist/lib/wireup/orchestrator.d.ts.map +1 -0
  566. package/dist/lib/wireup/orchestrator.js +366 -0
  567. package/dist/lib/wireup/orchestrator.js.map +1 -0
  568. package/dist/lib/wireup/report.d.ts +47 -0
  569. package/dist/lib/wireup/report.d.ts.map +1 -0
  570. package/dist/lib/wireup/report.js +201 -0
  571. package/dist/lib/wireup/report.js.map +1 -0
  572. package/dist/lib/wireup/scenarios.d.ts +2 -0
  573. package/dist/lib/wireup/scenarios.d.ts.map +1 -0
  574. package/dist/lib/wireup/scenarios.js +516 -0
  575. package/dist/lib/wireup/scenarios.js.map +1 -0
  576. package/dist/lib/wireup/state.d.ts +2 -0
  577. package/dist/lib/wireup/state.d.ts.map +1 -0
  578. package/dist/lib/wireup/state.js +102 -0
  579. package/dist/lib/wireup/state.js.map +1 -0
  580. package/dist/lib/wireup/types.d.ts +376 -0
  581. package/dist/lib/wireup/types.d.ts.map +1 -0
  582. package/dist/lib/wireup/types.js +3 -0
  583. package/dist/lib/wireup/types.js.map +1 -0
  584. package/dist/lib/worktree.d.ts +2 -0
  585. package/dist/lib/worktree.d.ts.map +1 -0
  586. package/dist/lib/worktree.js +999 -0
  587. package/dist/lib/worktree.js.map +1 -0
  588. package/lib/autopilot-milestone.ts +136 -0
  589. package/lib/autopilot-pipeline.ts +1179 -0
  590. package/lib/autopilot-waves.ts +361 -0
  591. package/lib/autopilot.ts +1874 -0
  592. package/lib/autoplan.ts +280 -0
  593. package/lib/autoresearch.js +4 -0
  594. package/lib/autoresearch.ts +886 -0
  595. package/lib/backend.ts +1252 -0
  596. package/lib/benchmark.ts +341 -0
  597. package/lib/citations.ts +760 -0
  598. package/lib/cleanup.ts +1588 -0
  599. package/lib/cli/adapters.ts +41 -0
  600. package/lib/cli/agent.ts +83 -0
  601. package/lib/cli/index.ts +273 -0
  602. package/lib/cli/output.ts +33 -0
  603. package/lib/cli/scan-dispatch.ts +130 -0
  604. package/lib/cli/tools.ts +198 -0
  605. package/lib/commands/_dashboard-parsers.ts +275 -0
  606. package/lib/commands/analysis.ts +1851 -0
  607. package/lib/commands/assumptions.ts +232 -0
  608. package/lib/commands/blame.ts +174 -0
  609. package/lib/commands/budget.ts +148 -0
  610. package/lib/commands/check-plans.ts +233 -0
  611. package/lib/commands/config.ts +287 -0
  612. package/lib/commands/dashboard.ts +680 -0
  613. package/lib/commands/estimate.ts +204 -0
  614. package/lib/commands/eval-diff.ts +252 -0
  615. package/lib/commands/freshness.ts +213 -0
  616. package/lib/commands/health.ts +607 -0
  617. package/lib/commands/index.ts +266 -0
  618. package/lib/commands/install.ts +307 -0
  619. package/lib/commands/knowhow-aggregator.ts +345 -0
  620. package/lib/commands/knowledge-search.ts +153 -0
  621. package/lib/commands/long-term-roadmap.ts +390 -0
  622. package/lib/commands/patterns.ts +465 -0
  623. package/lib/commands/phase-info.ts +698 -0
  624. package/lib/commands/plan-lint.ts +546 -0
  625. package/lib/commands/plan-phase.ts +375 -0
  626. package/lib/commands/progress.ts +319 -0
  627. package/lib/commands/quality.ts +138 -0
  628. package/lib/commands/rollback.ts +195 -0
  629. package/lib/commands/scan.ts +72 -0
  630. package/lib/commands/search.ts +300 -0
  631. package/lib/commands/select-candidate.ts +687 -0
  632. package/lib/commands/singularity.ts +222 -0
  633. package/lib/commands/slug-timestamp.ts +74 -0
  634. package/lib/commands/tail.ts +129 -0
  635. package/lib/commands/todo.ts +273 -0
  636. package/lib/commands/watch.ts +80 -0
  637. package/lib/complexity.ts +117 -0
  638. package/lib/context/agents.ts +505 -0
  639. package/lib/context/base.ts +123 -0
  640. package/lib/context/execute.ts +977 -0
  641. package/lib/context/index.ts +110 -0
  642. package/lib/context/progress.ts +278 -0
  643. package/lib/context/project.ts +531 -0
  644. package/lib/context/research.ts +646 -0
  645. package/lib/dead-ends.ts +506 -0
  646. package/lib/deps.ts +773 -0
  647. package/lib/discussion.ts +1275 -0
  648. package/lib/drift.ts +519 -0
  649. package/lib/evolve/_dimensions-features.ts +525 -0
  650. package/lib/evolve/_dimensions.ts +511 -0
  651. package/lib/evolve/_product-ideation.ts +405 -0
  652. package/lib/evolve/_prompts.ts +178 -0
  653. package/lib/evolve/cli.ts +330 -0
  654. package/lib/evolve/discovery.ts +571 -0
  655. package/lib/evolve/index.ts +105 -0
  656. package/lib/evolve/orchestrator.ts +1139 -0
  657. package/lib/evolve/scoring.ts +167 -0
  658. package/lib/evolve/state.ts +330 -0
  659. package/lib/evolve/types.ts +290 -0
  660. package/lib/frontmatter.ts +615 -0
  661. package/lib/gates.ts +695 -0
  662. package/lib/genome.ts +402 -0
  663. package/lib/got.js +4 -0
  664. package/lib/got.ts +361 -0
  665. package/lib/invariants.ts +378 -0
  666. package/lib/knowledge.ts +768 -0
  667. package/lib/long-term-roadmap.ts +806 -0
  668. package/lib/markdown-split.ts +273 -0
  669. package/lib/mcp-server.ts +3292 -0
  670. package/lib/metrics.ts +49 -0
  671. package/lib/overstory.ts +270 -0
  672. package/lib/parallel.ts +570 -0
  673. package/lib/paths.ts +293 -0
  674. package/lib/phase-complete-llm.ts +376 -0
  675. package/lib/phase-complete.ts +366 -0
  676. package/lib/phase-io.ts +101 -0
  677. package/lib/phase.ts +1981 -0
  678. package/lib/plan-tournament.ts +426 -0
  679. package/lib/refinement.ts +349 -0
  680. package/lib/requirements.ts +469 -0
  681. package/lib/research-bundle.ts +300 -0
  682. package/lib/roadmap.ts +775 -0
  683. package/lib/scaffold.ts +480 -0
  684. package/lib/scan/_utils.ts +37 -0
  685. package/lib/scan/base64.ts +90 -0
  686. package/lib/scan/ignorefile.ts +109 -0
  687. package/lib/scan/injection.ts +67 -0
  688. package/lib/scan/patterns.ts +139 -0
  689. package/lib/scan/strip-markdown.ts +39 -0
  690. package/lib/scan/types.ts +28 -0
  691. package/lib/scheduler-wait.ts +58 -0
  692. package/lib/scheduler.ts +1370 -0
  693. package/lib/state.ts +1000 -0
  694. package/lib/think.ts +365 -0
  695. package/lib/tracker.ts +1591 -0
  696. package/lib/types.ts +1663 -0
  697. package/lib/utils.ts +1479 -0
  698. package/lib/verify.ts +1434 -0
  699. package/lib/wireup/autofix.ts +241 -0
  700. package/lib/wireup/cli.ts +278 -0
  701. package/lib/wireup/detection.ts +542 -0
  702. package/lib/wireup/discovery.ts +1063 -0
  703. package/lib/wireup/execution.ts +686 -0
  704. package/lib/wireup/index.ts +117 -0
  705. package/lib/wireup/orchestrator.ts +519 -0
  706. package/lib/wireup/report.ts +286 -0
  707. package/lib/wireup/scenarios.ts +616 -0
  708. package/lib/wireup/state.ts +139 -0
  709. package/lib/wireup/types.ts +436 -0
  710. package/lib/worktree.ts +1309 -0
  711. package/package.json +67 -0
@@ -0,0 +1,3292 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * GRD MCP Server -- Model Context Protocol server exposing all GRD CLI commands as MCP tools.
5
+ *
6
+ * Implements JSON-RPC 2.0 over stdio transport. Zero external runtime dependencies (Node.js built-ins only).
7
+ * All tool definitions are auto-generated from a declarative COMMAND_DESCRIPTORS table.
8
+ *
9
+ * Created in Phase 16 Plan 01 (MCP Server).
10
+ * Migrated to TypeScript in Phase 63 Plan 03.
11
+ */
12
+
13
+
14
+ // ─── Interfaces ──────────────────────────────────────────────────────────────
15
+
16
+ /** Parameter descriptor for an MCP tool */
17
+ interface ParamDescriptor {
18
+ name: string;
19
+ type: 'string' | 'number' | 'boolean' | 'array' | 'object';
20
+ required: boolean;
21
+ description: string;
22
+ }
23
+
24
+ /** Command descriptor mapping an MCP tool to its handler */
25
+ interface CommandDescriptor {
26
+ name: string;
27
+ description: string;
28
+ params: ParamDescriptor[];
29
+ execute: (cwd: string, args: Record<string, unknown>) => void | unknown;
30
+ }
31
+
32
+ /** Result from captureExecution/captureExecutionAsync */
33
+ interface CaptureResult {
34
+ stdout: string;
35
+ stderr: string;
36
+ exitCode: number;
37
+ }
38
+
39
+ /** MCP tool definition with JSON Schema */
40
+ interface McpToolDefinition {
41
+ name: string;
42
+ description: string;
43
+ inputSchema: {
44
+ type: 'object';
45
+ properties: Record<string, { type: string; description: string; items?: { type: string } }>;
46
+ required?: string[];
47
+ };
48
+ }
49
+
50
+ /** JSON-RPC 2.0 message */
51
+ interface JsonRpcMessage {
52
+ jsonrpc?: string;
53
+ method?: string;
54
+ id?: number | string | null;
55
+ params?: Record<string, unknown>;
56
+ }
57
+
58
+ /** JSON-RPC 2.0 response */
59
+ interface JsonRpcResponse {
60
+ jsonrpc: '2.0';
61
+ id: number | string | null;
62
+ result?: unknown;
63
+ error?: { code: number; message: string; data?: unknown };
64
+ }
65
+
66
+ /** MCP exit error thrown by intercepted process.exit */
67
+ interface McpExitError extends Error {
68
+ __MCP_EXIT__: true;
69
+ exitCode: number;
70
+ }
71
+
72
+ // ─── Imports from lib/ modules ──────────────────────────────────────────────
73
+
74
+ const {
75
+ cmdStateLoad,
76
+ cmdStateGet,
77
+ cmdStatePatch,
78
+ cmdStateUpdate,
79
+ cmdStateAdvancePlan,
80
+ cmdStateRecordMetric,
81
+ cmdStateUpdateProgress,
82
+ cmdStateAddDecision,
83
+ cmdStateAddBlocker,
84
+ cmdStateResolveBlocker,
85
+ cmdStateRecordSession,
86
+ cmdStateSnapshot,
87
+ }: {
88
+ cmdStateLoad: (cwd: string, raw: boolean) => void;
89
+ cmdStateGet: (cwd: string, section: string | undefined, raw: boolean) => void;
90
+ cmdStatePatch: (cwd: string, patches: Record<string, unknown>, raw: boolean) => void;
91
+ cmdStateUpdate: (cwd: string, field: string, value: string) => void;
92
+ cmdStateAdvancePlan: (cwd: string, raw: boolean) => void;
93
+ cmdStateRecordMetric: (cwd: string, opts: Record<string, unknown>, raw: boolean) => void;
94
+ cmdStateUpdateProgress: (cwd: string, raw: boolean) => void;
95
+ cmdStateAddDecision: (cwd: string, opts: Record<string, unknown>, raw: boolean) => void;
96
+ cmdStateAddBlocker: (cwd: string, text: string, raw: boolean) => void;
97
+ cmdStateResolveBlocker: (cwd: string, text: string, raw: boolean) => void;
98
+ cmdStateRecordSession: (cwd: string, opts: Record<string, unknown>, raw: boolean) => void;
99
+ cmdStateSnapshot: (cwd: string, raw: boolean) => void;
100
+ } = require('./state');
101
+
102
+ const {
103
+ cmdFrontmatterGet,
104
+ cmdFrontmatterSet,
105
+ cmdFrontmatterMerge,
106
+ cmdFrontmatterValidate,
107
+ }: {
108
+ cmdFrontmatterGet: (cwd: string, file: string, field: string | null, raw: boolean) => void;
109
+ cmdFrontmatterSet: (
110
+ cwd: string,
111
+ file: string,
112
+ field: string,
113
+ value: string,
114
+ raw: boolean
115
+ ) => void;
116
+ cmdFrontmatterMerge: (cwd: string, file: string, data: string, raw: boolean) => void;
117
+ cmdFrontmatterValidate: (cwd: string, file: string, schema: string | null, raw: boolean) => void;
118
+ } = require('./frontmatter');
119
+
120
+ const {
121
+ cmdRoadmapGetPhase,
122
+ cmdPhaseNextDecimal,
123
+ cmdRoadmapAnalyze,
124
+ }: {
125
+ cmdRoadmapGetPhase: (cwd: string, phase: string, raw: boolean) => void;
126
+ cmdPhaseNextDecimal: (cwd: string, phase: string, raw: boolean) => void;
127
+ cmdRoadmapAnalyze: (cwd: string, raw: boolean) => void;
128
+ } = require('./roadmap');
129
+ const {
130
+ cmdPhaseAnalyzeDeps,
131
+ }: {
132
+ cmdPhaseAnalyzeDeps: (cwd: string, raw: boolean) => void;
133
+ } = require('./deps');
134
+ const {
135
+ cmdAutopilot,
136
+ cmdInitAutopilot,
137
+ cmdMultiMilestoneAutopilot,
138
+ cmdInitMultiMilestoneAutopilot,
139
+ }: {
140
+ cmdAutopilot: (cwd: string, args: string[], raw: boolean) => void;
141
+ cmdInitAutopilot: (cwd: string, raw: boolean) => void;
142
+ cmdMultiMilestoneAutopilot: (cwd: string, args: string[], raw: boolean) => void;
143
+ cmdInitMultiMilestoneAutopilot: (cwd: string, raw: boolean) => void;
144
+ } = require('./autopilot');
145
+ const {
146
+ cmdAutoplan,
147
+ cmdInitAutoplan,
148
+ }: {
149
+ cmdAutoplan: (cwd: string, args: string[], raw: boolean) => Promise<void>;
150
+ cmdInitAutoplan: (cwd: string, raw: boolean) => void;
151
+ } = require('./autoplan');
152
+ const {
153
+ cmdEvolve,
154
+ cmdEvolveDiscover,
155
+ cmdEvolveState,
156
+ cmdEvolveAdvance,
157
+ cmdEvolveReset,
158
+ cmdInitEvolve,
159
+ }: {
160
+ cmdEvolve: (cwd: string, args: string[], raw: boolean) => unknown;
161
+ cmdEvolveDiscover: (cwd: string, args: string[], raw: boolean) => Promise<unknown>;
162
+ cmdEvolveState: (cwd: string, args: string[], raw: boolean) => void;
163
+ cmdEvolveAdvance: (cwd: string, args: string[], raw: boolean) => void;
164
+ cmdEvolveReset: (cwd: string, args: string[], raw: boolean) => void;
165
+ cmdInitEvolve: (cwd: string, raw: boolean) => void;
166
+ } = require('./evolve');
167
+ const {
168
+ cmdWireupDiscover,
169
+ cmdWireupRun,
170
+ cmdWireupState,
171
+ cmdWireupScenarios,
172
+ cmdWireupReport,
173
+ }: {
174
+ cmdWireupDiscover: (cwd: string, args: string[], raw: boolean) => unknown;
175
+ cmdWireupRun: (cwd: string, args: string[], raw: boolean) => Promise<unknown>;
176
+ cmdWireupState: (cwd: string, args: string[], raw: boolean) => void;
177
+ cmdWireupScenarios: (cwd: string, args: string[], raw: boolean) => void;
178
+ cmdWireupReport: (cwd: string, args: string[], raw: boolean) => void;
179
+ } = require('./wireup');
180
+
181
+ import type { BackendId, BackendAvailability, DiscussionResult, RunDiscussionOptions } from './types';
182
+
183
+ const {
184
+ runDiscussion,
185
+ listDiscussions,
186
+ readDiscussion,
187
+ }: {
188
+ runDiscussion: (
189
+ topic: string,
190
+ participants: BackendId[],
191
+ options?: RunDiscussionOptions
192
+ ) => DiscussionResult;
193
+ listDiscussions: (cwd: string, milestone?: string | null) => string[];
194
+ readDiscussion: (filename: string, cwd: string, milestone?: string | null) => string | null;
195
+ } = require('./discussion');
196
+
197
+ const {
198
+ detectAvailableBackends,
199
+ readConfig,
200
+ }: {
201
+ detectAvailableBackends: (cwd?: string) => Record<BackendId, BackendAvailability>;
202
+ readConfig: (cwd: string) => Record<string, unknown> | null;
203
+ } = require('./backend');
204
+ const {
205
+ splitMarkdown,
206
+ isIndexFile,
207
+ estimateTokens,
208
+ }: {
209
+ splitMarkdown: (
210
+ content: string,
211
+ opts: { threshold?: number; basename: string }
212
+ ) => {
213
+ split_performed: boolean;
214
+ reason?: string;
215
+ index_content?: string;
216
+ parts?: Array<{ filename: string; content: string }>;
217
+ };
218
+ isIndexFile: (content: string) => boolean;
219
+ estimateTokens: (content: string) => number;
220
+ } = require('./markdown-split');
221
+ const {
222
+ cmdInitExecuteParallel,
223
+ }: {
224
+ cmdInitExecuteParallel: (
225
+ cwd: string,
226
+ phases: string[],
227
+ includes: Set<string>,
228
+ raw: boolean
229
+ ) => void;
230
+ } = require('./parallel');
231
+ const {
232
+ cmdTemplateSelect,
233
+ cmdTemplateFill,
234
+ cmdScaffold,
235
+ }: {
236
+ cmdTemplateSelect: (cwd: string, type: string, raw: boolean) => void;
237
+ cmdTemplateFill: (
238
+ cwd: string,
239
+ template: string,
240
+ opts: Record<string, unknown>,
241
+ raw: boolean
242
+ ) => void;
243
+ cmdScaffold: (cwd: string, type: string, opts: Record<string, unknown>, raw: boolean) => void;
244
+ } = require('./scaffold');
245
+
246
+ const {
247
+ cmdVerifySummary,
248
+ cmdVerifyPlanStructure,
249
+ cmdVerifyPhaseCompleteness,
250
+ cmdVerifyReferences,
251
+ cmdVerifyCommits,
252
+ cmdVerifyArtifacts,
253
+ cmdVerifyKeyLinks,
254
+ }: {
255
+ cmdVerifySummary: (cwd: string, file: string, checkCount: number, raw: boolean) => void;
256
+ cmdVerifyPlanStructure: (cwd: string, file: string, raw: boolean) => void;
257
+ cmdVerifyPhaseCompleteness: (cwd: string, phase: string, raw: boolean) => void;
258
+ cmdVerifyReferences: (cwd: string, file: string, raw: boolean) => void;
259
+ cmdVerifyCommits: (cwd: string, hashes: string[], raw: boolean) => void;
260
+ cmdVerifyArtifacts: (cwd: string, file: string, raw: boolean) => void;
261
+ cmdVerifyKeyLinks: (cwd: string, file: string, raw: boolean) => void;
262
+ } = require('./verify');
263
+
264
+ const {
265
+ cmdPhasesList,
266
+ cmdPhaseAdd,
267
+ cmdPhaseInsert,
268
+ cmdPhaseRemove,
269
+ cmdPhaseComplete,
270
+ cmdMilestoneComplete,
271
+ cmdValidateConsistency,
272
+ }: {
273
+ cmdPhasesList: (cwd: string, opts: Record<string, unknown>, raw: boolean) => void;
274
+ cmdPhaseAdd: (cwd: string, description: string, raw: boolean, context?: string) => void;
275
+ cmdPhaseInsert: (cwd: string, phase: string, description: string, raw: boolean) => void;
276
+ cmdPhaseRemove: (cwd: string, phase: string, opts: Record<string, unknown>, raw: boolean) => void;
277
+ cmdPhaseComplete: (cwd: string, phase: string, raw: boolean, options?: Record<string, unknown>) => Promise<void>;
278
+ cmdMilestoneComplete: (
279
+ cwd: string,
280
+ version: string,
281
+ opts: Record<string, unknown>,
282
+ raw: boolean
283
+ ) => void;
284
+ cmdValidateConsistency: (cwd: string, raw: boolean) => void;
285
+ } = require('./phase');
286
+
287
+ const {
288
+ cmdTracker,
289
+ }: {
290
+ cmdTracker: (cwd: string, subcommand: string, args: string[] | unknown[], raw: boolean) => void;
291
+ } = require('./tracker');
292
+
293
+ const {
294
+ cmdWorktreeCreate,
295
+ cmdWorktreeRemove,
296
+ cmdWorktreeList,
297
+ cmdWorktreeRemoveStale,
298
+ cmdWorktreePushAndPR,
299
+ }: {
300
+ cmdWorktreeCreate: (cwd: string, opts: Record<string, unknown>, raw: boolean) => void;
301
+ cmdWorktreeRemove: (cwd: string, opts: Record<string, unknown>, raw: boolean) => void;
302
+ cmdWorktreeList: (cwd: string, raw: boolean) => void;
303
+ cmdWorktreeRemoveStale: (cwd: string, raw: boolean) => void;
304
+ cmdWorktreePushAndPR: (cwd: string, opts: Record<string, unknown>, raw: boolean) => void;
305
+ } = require('./worktree');
306
+
307
+ const {
308
+ cmdInitExecutePhase,
309
+ cmdInitPlanPhase,
310
+ cmdInitNewProject,
311
+ cmdInitNewMilestone,
312
+ cmdInitQuick,
313
+ cmdInitResume,
314
+ cmdInitVerifyWork,
315
+ cmdInitPhaseOp,
316
+ cmdInitTodos,
317
+ cmdInitMilestoneOp,
318
+ cmdInitMapCodebase,
319
+ cmdInitProgress,
320
+ cmdInitResearchWorkflow,
321
+ cmdInitPlanMilestoneGaps,
322
+ // Agent & operation workflows (from context/agents.ts)
323
+ cmdInitDebug,
324
+ cmdInitIntegrationCheck,
325
+ cmdInitMigrate,
326
+ cmdInitPlanCheck,
327
+ cmdInitExecutor,
328
+ cmdInitBaselineAssessor,
329
+ cmdInitCodeReviewer,
330
+ cmdInitCodebaseMapper,
331
+ cmdInitDebugger,
332
+ cmdInitDeepDiver,
333
+ cmdInitEvalPlanner,
334
+ cmdInitEvalReporter,
335
+ cmdInitFeasibilityAnalyst,
336
+ cmdInitIntegrationChecker,
337
+ cmdInitMigrator,
338
+ cmdInitPhaseResearcher,
339
+ cmdInitPlanChecker,
340
+ // Execute & plan workflows (from context/execute.ts)
341
+ cmdInitCodeReview,
342
+ cmdInitPhaseResearch,
343
+ // Research workflows (from context/research.ts)
344
+ cmdInitAssessBaseline,
345
+ cmdInitDeepDive,
346
+ cmdInitEvalPlan,
347
+ cmdInitEvalReport,
348
+ cmdInitFeasibility,
349
+ cmdInitProductOwner,
350
+ cmdInitProjectResearcher,
351
+ cmdInitResearchSynthesizer,
352
+ cmdInitRoadmapper,
353
+ cmdInitSurveyor,
354
+ cmdInitVerifier,
355
+ }: {
356
+ cmdInitExecutePhase: (cwd: string, phase: string, includes: Set<string>, raw: boolean) => void;
357
+ cmdInitPlanPhase: (cwd: string, phase: string, includes: Set<string>, raw: boolean) => void;
358
+ cmdInitNewProject: (cwd: string, raw: boolean) => void;
359
+ cmdInitNewMilestone: (cwd: string, raw: boolean) => void;
360
+ cmdInitQuick: (cwd: string, description: string, raw: boolean) => void;
361
+ cmdInitResume: (cwd: string, raw: boolean) => void;
362
+ cmdInitVerifyWork: (cwd: string, phase: string, raw: boolean) => void;
363
+ cmdInitPhaseOp: (cwd: string, phase: string, raw: boolean) => void;
364
+ cmdInitTodos: (cwd: string, area: string | undefined, raw: boolean) => void;
365
+ cmdInitMilestoneOp: (cwd: string, raw: boolean) => void;
366
+ cmdInitMapCodebase: (cwd: string, raw: boolean) => void;
367
+ cmdInitProgress: (cwd: string, includes: Set<string>, raw: boolean) => void;
368
+ cmdInitResearchWorkflow: (
369
+ cwd: string,
370
+ workflow: string,
371
+ topic: string,
372
+ includes: Set<string>,
373
+ raw: boolean
374
+ ) => void;
375
+ cmdInitPlanMilestoneGaps: (cwd: string, raw: boolean) => void;
376
+ // Agent & operation workflows
377
+ cmdInitDebug: (cwd: string, phase: string | null, raw: boolean) => void;
378
+ cmdInitIntegrationCheck: (cwd: string, phase: string | null, raw: boolean) => void;
379
+ cmdInitMigrate: (cwd: string, raw: boolean) => void;
380
+ cmdInitPlanCheck: (cwd: string, phase: string, raw: boolean) => void;
381
+ cmdInitExecutor: (cwd: string, phase: string, includes: Set<string>, raw: boolean) => void;
382
+ cmdInitBaselineAssessor: (cwd: string, raw: boolean) => void;
383
+ cmdInitCodeReviewer: (cwd: string, phase: string, raw: boolean) => void;
384
+ cmdInitCodebaseMapper: (cwd: string, raw: boolean) => void;
385
+ cmdInitDebugger: (cwd: string, phase: string | null, raw: boolean) => void;
386
+ cmdInitDeepDiver: (cwd: string, topic: string, raw: boolean) => void;
387
+ cmdInitEvalPlanner: (cwd: string, phase: string | null, raw: boolean) => void;
388
+ cmdInitEvalReporter: (cwd: string, phase: string | null, raw: boolean) => void;
389
+ cmdInitFeasibilityAnalyst: (cwd: string, topic: string, raw: boolean) => void;
390
+ cmdInitIntegrationChecker: (cwd: string, phase: string | null, raw: boolean) => void;
391
+ cmdInitMigrator: (cwd: string, raw: boolean) => void;
392
+ cmdInitPhaseResearcher: (cwd: string, phase: string, includes: Set<string>, raw: boolean) => void;
393
+ cmdInitPlanChecker: (cwd: string, phase: string, raw: boolean) => void;
394
+ // Execute & plan workflows
395
+ cmdInitCodeReview: (cwd: string, phase: string, raw: boolean) => void;
396
+ cmdInitPhaseResearch: (cwd: string, phase: string, includes: Set<string>, raw: boolean) => void;
397
+ // Research workflows
398
+ cmdInitAssessBaseline: (cwd: string, raw: boolean) => void;
399
+ cmdInitDeepDive: (cwd: string, topic: string, raw: boolean) => void;
400
+ cmdInitEvalPlan: (cwd: string, phase: string | null, raw: boolean) => void;
401
+ cmdInitEvalReport: (cwd: string, phase: string | null, raw: boolean) => void;
402
+ cmdInitFeasibility: (cwd: string, topic: string, raw: boolean) => void;
403
+ cmdInitProductOwner: (cwd: string, raw: boolean) => void;
404
+ cmdInitProjectResearcher: (cwd: string, topic: string, raw: boolean) => void;
405
+ cmdInitResearchSynthesizer: (cwd: string, raw: boolean) => void;
406
+ cmdInitRoadmapper: (cwd: string, raw: boolean) => void;
407
+ cmdInitSurveyor: (cwd: string, topic: string, raw: boolean) => void;
408
+ cmdInitVerifier: (cwd: string, phase: string | null, raw: boolean) => void;
409
+ } = require('./context');
410
+
411
+ const {
412
+ cmdGenerateSlug,
413
+ cmdCurrentTimestamp,
414
+ cmdListTodos,
415
+ cmdTodoComplete,
416
+ cmdVerifyPathExists,
417
+ cmdConfigEnsureSection,
418
+ cmdConfigSet,
419
+ cmdHistoryDigest,
420
+ cmdResolveModel,
421
+ cmdFindPhase,
422
+ cmdCommit,
423
+ cmdPhasePlanIndex,
424
+ cmdSummaryExtract,
425
+ cmdProgressRender,
426
+ cmdDashboard,
427
+ cmdPhaseDetail,
428
+ cmdHealth,
429
+ cmdDetectBackend,
430
+ cmdLongTermRoadmap,
431
+ cmdQualityAnalysis,
432
+ cmdRequirementGet,
433
+ cmdRequirementList,
434
+ cmdRequirementTraceability,
435
+ cmdRequirementUpdateStatus,
436
+ cmdSearch,
437
+ cmdCoverageReport,
438
+ cmdHealthCheck,
439
+ }: {
440
+ cmdGenerateSlug: (text: string, raw: boolean) => void;
441
+ cmdCurrentTimestamp: (format: string, raw: boolean) => void;
442
+ cmdListTodos: (cwd: string, area: string | undefined, raw: boolean) => void;
443
+ cmdTodoComplete: (cwd: string, filename: string, raw: boolean) => void;
444
+ cmdVerifyPathExists: (cwd: string, targetPath: string, raw: boolean) => void;
445
+ cmdConfigEnsureSection: (cwd: string, raw: boolean) => void;
446
+ cmdConfigSet: (cwd: string, key: string, value: string, raw: boolean) => void;
447
+ cmdHistoryDigest: (cwd: string, raw: boolean) => void;
448
+ cmdResolveModel: (cwd: string, agentType: string, raw: boolean) => void;
449
+ cmdFindPhase: (cwd: string, phase: string, raw: boolean) => void;
450
+ cmdCommit: (cwd: string, message: string, files: string[], raw: boolean, amend: boolean) => void;
451
+ cmdPhasePlanIndex: (cwd: string, phase: string, raw: boolean) => void;
452
+ cmdSummaryExtract: (cwd: string, file: string, fields: string[] | null, raw: boolean) => void;
453
+ cmdProgressRender: (cwd: string, format: string, raw: boolean) => void;
454
+ cmdDashboard: (cwd: string, raw: boolean) => void;
455
+ cmdPhaseDetail: (cwd: string, phase: string, raw: boolean) => void;
456
+ cmdHealth: (cwd: string, raw: boolean) => void;
457
+ cmdDetectBackend: (cwd: string, raw: boolean) => void;
458
+ cmdLongTermRoadmap: (cwd: string, subcommand: string, args: string[], raw: boolean) => void;
459
+ cmdQualityAnalysis: (cwd: string, args: string[], raw: boolean) => void;
460
+ cmdRequirementGet: (cwd: string, reqId: string, raw: boolean) => void;
461
+ cmdRequirementList: (cwd: string, opts: Record<string, unknown>, raw: boolean) => void;
462
+ cmdRequirementTraceability: (cwd: string, opts: Record<string, unknown>, raw: boolean) => void;
463
+ cmdRequirementUpdateStatus: (cwd: string, reqId: string, status: string, raw: boolean) => void;
464
+ cmdSearch: (cwd: string, query: string, raw: boolean) => void;
465
+ cmdCoverageReport: (cwd: string, opts: Record<string, unknown>, raw: boolean) => void;
466
+ cmdHealthCheck: (cwd: string, opts: Record<string, unknown>, raw: boolean) => void;
467
+ } = require('./commands');
468
+
469
+ // ─── Tool Descriptor Factory Functions ──────────────────────────────────────
470
+ //
471
+ // These factory functions reduce repetition in COMMAND_DESCRIPTORS for common
472
+ // command shapes. Each returns a full descriptor object.
473
+ //
474
+ // NOTE: COMMAND_DESCRIPTORS is defined in this file rather than a separate
475
+ // lib/mcp-descriptors.ts because every execute handler directly references
476
+ // imported cmd* functions at the top of this file. Extracting to a separate
477
+ // file would require moving all those imports too, which is tracked as future work.
478
+
479
+ /**
480
+ * Create a descriptor for a simple single-required-string-argument command.
481
+ */
482
+ function makeSimpleCommand(
483
+ name: string,
484
+ description: string,
485
+ argName: string,
486
+ argDescription: string,
487
+ handler: (cwd: string, argValue: string) => void | unknown
488
+ ): CommandDescriptor {
489
+ return {
490
+ name,
491
+ description,
492
+ params: [{ name: argName, type: 'string', required: true, description: argDescription }],
493
+ execute: (cwd: string, args: Record<string, unknown>) => handler(cwd, args[argName] as string),
494
+ };
495
+ }
496
+
497
+ /**
498
+ * Create a descriptor for a command that takes a single required 'phase' string argument.
499
+ */
500
+ function makePhaseCommand(
501
+ name: string,
502
+ description: string,
503
+ handler: (cwd: string, phase: string) => void | unknown
504
+ ): CommandDescriptor {
505
+ return makeSimpleCommand(name, description, 'phase', 'Phase number', handler);
506
+ }
507
+
508
+ /**
509
+ * Create a descriptor for a zero-argument state-reading/mutation command.
510
+ */
511
+ function makeStateCommand(
512
+ name: string,
513
+ description: string,
514
+ handler: (cwd: string) => void | unknown
515
+ ): CommandDescriptor {
516
+ return {
517
+ name,
518
+ description,
519
+ params: [],
520
+ execute: (cwd: string, _args: Record<string, unknown>) => handler(cwd),
521
+ };
522
+ }
523
+
524
+ // ─── Tool Descriptors ────────────────────────────────────────────────────────
525
+ //
526
+ // Each descriptor declares: name, description, params (with type, required, description).
527
+ // The buildToolDefinitions() function transforms these into MCP-format tool definitions.
528
+
529
+ const COMMAND_DESCRIPTORS: CommandDescriptor[] = [
530
+ // ── State commands ──
531
+ makeStateCommand('grd_state_load', 'Load full project config, state, and roadmap status', (cwd) =>
532
+ cmdStateLoad(cwd, false)
533
+ ),
534
+ {
535
+ name: 'grd_state_get',
536
+ description: 'Read a specific field or section from STATE.md',
537
+ params: [
538
+ {
539
+ name: 'section',
540
+ type: 'string',
541
+ required: false,
542
+ description: 'Field or section name to read',
543
+ },
544
+ ],
545
+ execute: (cwd: string, args: Record<string, unknown>) =>
546
+ cmdStateGet(cwd, (args.section as string) || undefined, false),
547
+ },
548
+ {
549
+ name: 'grd_state_patch',
550
+ description: 'Batch update STATE.md fields',
551
+ params: [
552
+ {
553
+ name: 'patches',
554
+ type: 'object',
555
+ required: true,
556
+ description: 'Object of field:value pairs to update',
557
+ },
558
+ ],
559
+ execute: (cwd: string, args: Record<string, unknown>) =>
560
+ cmdStatePatch(cwd, (args.patches as Record<string, unknown>) || {}, false),
561
+ },
562
+ {
563
+ name: 'grd_state_update',
564
+ description: 'Update a single STATE.md field',
565
+ params: [
566
+ { name: 'field', type: 'string', required: true, description: 'Field name to update' },
567
+ { name: 'value', type: 'string', required: true, description: 'New value for the field' },
568
+ ],
569
+ execute: (cwd: string, args: Record<string, unknown>) =>
570
+ cmdStateUpdate(cwd, args.field as string, args.value as string),
571
+ },
572
+ makeStateCommand(
573
+ 'grd_state_advance_plan',
574
+ 'Increment the current plan counter in STATE.md',
575
+ (cwd) => cmdStateAdvancePlan(cwd, false)
576
+ ),
577
+ {
578
+ name: 'grd_state_record_metric',
579
+ description: 'Record execution metrics (phase, plan, duration, tasks, files) to STATE.md',
580
+ params: [
581
+ { name: 'phase', type: 'string', required: true, description: 'Phase number' },
582
+ { name: 'plan', type: 'string', required: true, description: 'Plan number' },
583
+ { name: 'duration', type: 'string', required: true, description: 'Duration (e.g. "3min")' },
584
+ { name: 'tasks', type: 'string', required: false, description: 'Number of tasks' },
585
+ { name: 'files', type: 'string', required: false, description: 'Number of files modified' },
586
+ ],
587
+ execute: (cwd: string, args: Record<string, unknown>) =>
588
+ cmdStateRecordMetric(
589
+ cwd,
590
+ {
591
+ phase: args.phase,
592
+ plan: args.plan,
593
+ duration: args.duration,
594
+ tasks: (args.tasks as string) || null,
595
+ files: (args.files as string) || null,
596
+ },
597
+ false
598
+ ),
599
+ },
600
+ makeStateCommand('grd_state_update_progress', 'Recalculate progress bar from disk state', (cwd) =>
601
+ cmdStateUpdateProgress(cwd, false)
602
+ ),
603
+ {
604
+ name: 'grd_state_add_decision',
605
+ description: 'Add a decision to the Key Decisions table in STATE.md',
606
+ params: [
607
+ { name: 'summary', type: 'string', required: true, description: 'Decision summary text' },
608
+ {
609
+ name: 'phase',
610
+ type: 'string',
611
+ required: false,
612
+ description: 'Phase number for the decision',
613
+ },
614
+ {
615
+ name: 'rationale',
616
+ type: 'string',
617
+ required: false,
618
+ description: 'Rationale for the decision',
619
+ },
620
+ ],
621
+ execute: (cwd: string, args: Record<string, unknown>) =>
622
+ cmdStateAddDecision(
623
+ cwd,
624
+ {
625
+ summary: args.summary,
626
+ phase: (args.phase as string) || null,
627
+ rationale: (args.rationale as string) || '',
628
+ },
629
+ false
630
+ ),
631
+ },
632
+ {
633
+ name: 'grd_state_add_blocker',
634
+ description: 'Add a blocker to STATE.md',
635
+ params: [{ name: 'text', type: 'string', required: true, description: 'Blocker description' }],
636
+ execute: (cwd: string, args: Record<string, unknown>) =>
637
+ cmdStateAddBlocker(cwd, args.text as string, false),
638
+ },
639
+ {
640
+ name: 'grd_state_resolve_blocker',
641
+ description: 'Resolve a blocker in STATE.md',
642
+ params: [
643
+ { name: 'text', type: 'string', required: true, description: 'Blocker text to resolve' },
644
+ ],
645
+ execute: (cwd: string, args: Record<string, unknown>) =>
646
+ cmdStateResolveBlocker(cwd, args.text as string, false),
647
+ },
648
+ {
649
+ name: 'grd_state_record_session',
650
+ description: 'Update session continuity info in STATE.md',
651
+ params: [
652
+ {
653
+ name: 'stopped_at',
654
+ type: 'string',
655
+ required: true,
656
+ description: 'Where execution stopped',
657
+ },
658
+ { name: 'resume_file', type: 'string', required: false, description: 'File to resume from' },
659
+ ],
660
+ execute: (cwd: string, args: Record<string, unknown>) =>
661
+ cmdStateRecordSession(
662
+ cwd,
663
+ {
664
+ stopped_at: args.stopped_at,
665
+ resume_file: (args.resume_file as string) || 'None',
666
+ },
667
+ false
668
+ ),
669
+ },
670
+
671
+ // ── Top-level commands ──
672
+ {
673
+ name: 'grd_resolve_model',
674
+ description: 'Resolve the model name for a given agent type from project configuration',
675
+ params: [
676
+ {
677
+ name: 'agent_type',
678
+ type: 'string',
679
+ required: true,
680
+ description: 'Agent type key (e.g. grd-executor)',
681
+ },
682
+ ],
683
+ execute: (cwd: string, args: Record<string, unknown>) =>
684
+ cmdResolveModel(cwd, args.agent_type as string, false),
685
+ },
686
+ {
687
+ name: 'grd_find_phase',
688
+ description: 'Find a phase directory by number and list its plans and summaries',
689
+ params: [
690
+ { name: 'phase', type: 'string', required: true, description: 'Phase identifier to find' },
691
+ ],
692
+ execute: (cwd: string, args: Record<string, unknown>) =>
693
+ cmdFindPhase(cwd, args.phase as string, false),
694
+ },
695
+ {
696
+ name: 'grd_commit',
697
+ description: 'Create a git commit with specified files',
698
+ params: [
699
+ { name: 'message', type: 'string', required: true, description: 'Commit message' },
700
+ {
701
+ name: 'files',
702
+ type: 'array',
703
+ required: false,
704
+ description: 'File paths to stage (defaults to .planning/)',
705
+ },
706
+ { name: 'amend', type: 'boolean', required: false, description: 'Amend previous commit' },
707
+ ],
708
+ execute: (cwd: string, args: Record<string, unknown>) =>
709
+ cmdCommit(
710
+ cwd,
711
+ args.message as string,
712
+ (args.files as string[]) || [],
713
+ false,
714
+ (args.amend as boolean) || false
715
+ ),
716
+ },
717
+
718
+ // ── Verify commands ──
719
+ {
720
+ name: 'grd_verify_summary',
721
+ description: 'Verify a SUMMARY.md file structure and content',
722
+ params: [
723
+ { name: 'file', type: 'string', required: true, description: 'Path to the SUMMARY.md file' },
724
+ { name: 'check_count', type: 'number', required: false, description: 'Expected task count' },
725
+ ],
726
+ execute: (cwd: string, args: Record<string, unknown>) =>
727
+ cmdVerifySummary(cwd, args.file as string, (args.check_count as number) || 2, false),
728
+ },
729
+ makeSimpleCommand(
730
+ 'grd_verify_plan_structure',
731
+ 'Validate a PLAN.md file structure and frontmatter',
732
+ 'file',
733
+ 'Path to the PLAN.md file',
734
+ (cwd, file) => cmdVerifyPlanStructure(cwd, file, false)
735
+ ),
736
+ {
737
+ name: 'grd_verify_phase_completeness',
738
+ description: 'Check that all plans in a phase have corresponding summaries',
739
+ params: [
740
+ { name: 'phase', type: 'string', required: true, description: 'Phase number or directory' },
741
+ ],
742
+ execute: (cwd: string, args: Record<string, unknown>) =>
743
+ cmdVerifyPhaseCompleteness(cwd, args.phase as string, false),
744
+ },
745
+ {
746
+ name: 'grd_verify_references',
747
+ description: 'Validate @-references and file paths in a file',
748
+ params: [
749
+ { name: 'file', type: 'string', required: true, description: 'File to check references in' },
750
+ ],
751
+ execute: (cwd: string, args: Record<string, unknown>) =>
752
+ cmdVerifyReferences(cwd, args.file as string, false),
753
+ },
754
+ {
755
+ name: 'grd_verify_commits',
756
+ description: 'Batch verify that git commits exist',
757
+ params: [
758
+ {
759
+ name: 'hashes',
760
+ type: 'array',
761
+ required: true,
762
+ description: 'Array of git commit hashes to verify',
763
+ },
764
+ ],
765
+ execute: (cwd: string, args: Record<string, unknown>) =>
766
+ cmdVerifyCommits(cwd, (args.hashes as string[]) || [], false),
767
+ },
768
+ makeSimpleCommand(
769
+ 'grd_verify_artifacts',
770
+ 'Check that must_haves.artifacts from a plan file exist on disk',
771
+ 'file',
772
+ 'Path to the PLAN.md file',
773
+ (cwd, file) => cmdVerifyArtifacts(cwd, file, false)
774
+ ),
775
+ makeSimpleCommand(
776
+ 'grd_verify_key_links',
777
+ 'Validate must_haves.key_links patterns between source files',
778
+ 'file',
779
+ 'Path to the PLAN.md file',
780
+ (cwd, file) => cmdVerifyKeyLinks(cwd, file, false)
781
+ ),
782
+
783
+ // ── Template & Scaffold ──
784
+ {
785
+ name: 'grd_template_select',
786
+ description: 'Select the appropriate template for a given type',
787
+ params: [
788
+ {
789
+ name: 'type',
790
+ type: 'string',
791
+ required: true,
792
+ description: 'Template type (e.g. summary, plan)',
793
+ },
794
+ ],
795
+ execute: (cwd: string, args: Record<string, unknown>) =>
796
+ cmdTemplateSelect(cwd, args.type as string, false),
797
+ },
798
+ {
799
+ name: 'grd_template_fill',
800
+ description: 'Fill a template with provided values',
801
+ params: [
802
+ { name: 'template', type: 'string', required: true, description: 'Template path or type' },
803
+ { name: 'phase', type: 'string', required: false, description: 'Phase number' },
804
+ { name: 'plan', type: 'string', required: false, description: 'Plan number' },
805
+ { name: 'name', type: 'string', required: false, description: 'Plan or phase name' },
806
+ {
807
+ name: 'type',
808
+ type: 'string',
809
+ required: false,
810
+ description: 'Plan type (default: execute)',
811
+ },
812
+ { name: 'wave', type: 'string', required: false, description: 'Wave number (default: 1)' },
813
+ {
814
+ name: 'fields',
815
+ type: 'object',
816
+ required: false,
817
+ description: 'Additional template fields',
818
+ },
819
+ ],
820
+ execute: (cwd: string, args: Record<string, unknown>) =>
821
+ cmdTemplateFill(
822
+ cwd,
823
+ args.template as string,
824
+ {
825
+ phase: (args.phase as string) || null,
826
+ plan: (args.plan as string) || null,
827
+ name: (args.name as string) || null,
828
+ type: (args.type as string) || 'execute',
829
+ wave: (args.wave as string) || '1',
830
+ fields: (args.fields as Record<string, unknown>) || {},
831
+ },
832
+ false
833
+ ),
834
+ },
835
+ {
836
+ name: 'grd_scaffold',
837
+ description:
838
+ 'Scaffold project structures (context, uat, verification, phase-dir, research-dir, eval, baseline)',
839
+ params: [
840
+ { name: 'type', type: 'string', required: true, description: 'Scaffold type' },
841
+ { name: 'phase', type: 'string', required: false, description: 'Phase number' },
842
+ { name: 'name', type: 'string', required: false, description: 'Name for the scaffold' },
843
+ ],
844
+ execute: (cwd: string, args: Record<string, unknown>) =>
845
+ cmdScaffold(
846
+ cwd,
847
+ args.type as string,
848
+ {
849
+ phase: (args.phase as string) || null,
850
+ name: (args.name as string) || null,
851
+ },
852
+ false
853
+ ),
854
+ },
855
+
856
+ // ── Frontmatter ──
857
+ {
858
+ name: 'grd_frontmatter_get',
859
+ description: 'Get frontmatter from a markdown file',
860
+ params: [
861
+ { name: 'file', type: 'string', required: true, description: 'Markdown file path' },
862
+ { name: 'field', type: 'string', required: false, description: 'Specific field to extract' },
863
+ ],
864
+ execute: (cwd: string, args: Record<string, unknown>) =>
865
+ cmdFrontmatterGet(cwd, args.file as string, (args.field as string) || null, false),
866
+ },
867
+ {
868
+ name: 'grd_frontmatter_set',
869
+ description: 'Set a frontmatter field in a markdown file',
870
+ params: [
871
+ { name: 'file', type: 'string', required: true, description: 'Markdown file path' },
872
+ { name: 'field', type: 'string', required: true, description: 'Field name to set' },
873
+ { name: 'value', type: 'string', required: true, description: 'Value to set' },
874
+ ],
875
+ execute: (cwd: string, args: Record<string, unknown>) =>
876
+ cmdFrontmatterSet(
877
+ cwd,
878
+ args.file as string,
879
+ args.field as string,
880
+ args.value as string,
881
+ false
882
+ ),
883
+ },
884
+ {
885
+ name: 'grd_frontmatter_merge',
886
+ description: 'Merge data into frontmatter of a markdown file',
887
+ params: [
888
+ { name: 'file', type: 'string', required: true, description: 'Markdown file path' },
889
+ { name: 'data', type: 'string', required: true, description: 'JSON string of data to merge' },
890
+ ],
891
+ execute: (cwd: string, args: Record<string, unknown>) =>
892
+ cmdFrontmatterMerge(cwd, args.file as string, args.data as string, false),
893
+ },
894
+ {
895
+ name: 'grd_frontmatter_validate',
896
+ description: 'Validate frontmatter of a markdown file against a schema',
897
+ params: [
898
+ { name: 'file', type: 'string', required: true, description: 'Markdown file path' },
899
+ {
900
+ name: 'schema',
901
+ type: 'string',
902
+ required: false,
903
+ description: 'Schema name to validate against',
904
+ },
905
+ ],
906
+ execute: (cwd: string, args: Record<string, unknown>) =>
907
+ cmdFrontmatterValidate(cwd, args.file as string, (args.schema as string) || null, false),
908
+ },
909
+
910
+ // ── Utility commands ──
911
+ {
912
+ name: 'grd_generate_slug',
913
+ description: 'Generate a kebab-case slug from input text',
914
+ params: [
915
+ { name: 'text', type: 'string', required: true, description: 'Text to convert to slug' },
916
+ ],
917
+ execute: (_cwd: string, args: Record<string, unknown>) =>
918
+ cmdGenerateSlug(args.text as string, false),
919
+ },
920
+ {
921
+ name: 'grd_current_timestamp',
922
+ description: 'Output the current timestamp in the specified format',
923
+ params: [
924
+ {
925
+ name: 'format',
926
+ type: 'string',
927
+ required: false,
928
+ description: 'Format: date, filename, or full (default: full)',
929
+ },
930
+ ],
931
+ execute: (_cwd: string, args: Record<string, unknown>) =>
932
+ cmdCurrentTimestamp((args.format as string) || 'full', false),
933
+ },
934
+ {
935
+ name: 'grd_list_todos',
936
+ description: 'List pending todo files with optional area filter',
937
+ params: [
938
+ { name: 'area', type: 'string', required: false, description: 'Area filter (e.g. general)' },
939
+ ],
940
+ execute: (cwd: string, args: Record<string, unknown>) =>
941
+ cmdListTodos(cwd, (args.area as string) || undefined, false),
942
+ },
943
+ {
944
+ name: 'grd_todo_complete',
945
+ description: 'Mark a todo file as completed',
946
+ params: [
947
+ {
948
+ name: 'filename',
949
+ type: 'string',
950
+ required: true,
951
+ description: 'Todo filename to complete',
952
+ },
953
+ ],
954
+ execute: (cwd: string, args: Record<string, unknown>) =>
955
+ cmdTodoComplete(cwd, args.filename as string, false),
956
+ },
957
+ {
958
+ name: 'grd_verify_path_exists',
959
+ description: 'Check if a path exists in the project and report its type',
960
+ params: [
961
+ { name: 'path', type: 'string', required: true, description: 'Path to check for existence' },
962
+ ],
963
+ execute: (cwd: string, args: Record<string, unknown>) =>
964
+ cmdVerifyPathExists(cwd, args.path as string, false),
965
+ },
966
+ {
967
+ name: 'grd_config_ensure_section',
968
+ description: 'Ensure config.json exists with required sections',
969
+ params: [],
970
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdConfigEnsureSection(cwd, false),
971
+ },
972
+ {
973
+ name: 'grd_config_set',
974
+ description: 'Set a configuration value by dot-path key in config.json',
975
+ params: [
976
+ {
977
+ name: 'key',
978
+ type: 'string',
979
+ required: true,
980
+ description: 'Dot-notation key path (e.g. workflow.research)',
981
+ },
982
+ { name: 'value', type: 'string', required: true, description: 'Value to set' },
983
+ ],
984
+ execute: (cwd: string, args: Record<string, unknown>) =>
985
+ cmdConfigSet(cwd, args.key as string, args.value as string, false),
986
+ },
987
+ makeStateCommand(
988
+ 'grd_history_digest',
989
+ 'Aggregate metrics, decisions, and tech stack from all SUMMARY.md files',
990
+ (cwd) => cmdHistoryDigest(cwd, false)
991
+ ),
992
+
993
+ // ── Phases ──
994
+ {
995
+ name: 'grd_phases_list',
996
+ description: 'List all phases with optional type or phase filter',
997
+ params: [
998
+ { name: 'type', type: 'string', required: false, description: 'Filter by phase type' },
999
+ { name: 'phase', type: 'string', required: false, description: 'Filter by phase number' },
1000
+ ],
1001
+ execute: (cwd: string, args: Record<string, unknown>) =>
1002
+ cmdPhasesList(
1003
+ cwd,
1004
+ { type: (args.type as string) || null, phase: (args.phase as string) || null },
1005
+ false
1006
+ ),
1007
+ },
1008
+
1009
+ // ── Roadmap ──
1010
+ makePhaseCommand(
1011
+ 'grd_roadmap_get_phase',
1012
+ 'Get roadmap section for a specific phase',
1013
+ (cwd, phase) => cmdRoadmapGetPhase(cwd, phase, false)
1014
+ ),
1015
+ {
1016
+ name: 'grd_roadmap_analyze',
1017
+ description: 'Analyze roadmap structure and status',
1018
+ params: [],
1019
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdRoadmapAnalyze(cwd, false),
1020
+ },
1021
+
1022
+ // ── Phase operations ──
1023
+ makePhaseCommand(
1024
+ 'grd_phase_next_decimal',
1025
+ 'Get the next decimal phase number after a given phase',
1026
+ (cwd, phase) => cmdPhaseNextDecimal(cwd, phase, false)
1027
+ ),
1028
+ {
1029
+ name: 'grd_phase_add',
1030
+ description: 'Add a new phase to the roadmap',
1031
+ params: [
1032
+ { name: 'description', type: 'string', required: true, description: 'Phase description' },
1033
+ {
1034
+ name: 'context',
1035
+ type: 'string',
1036
+ required: false,
1037
+ description: 'Optional context text to capture in CONTEXT.md',
1038
+ },
1039
+ ],
1040
+ execute: (cwd: string, args: Record<string, unknown>) =>
1041
+ cmdPhaseAdd(cwd, args.description as string, false, args.context as string | undefined),
1042
+ },
1043
+ {
1044
+ name: 'grd_phase_insert',
1045
+ description: 'Insert a phase at a specific position in the roadmap',
1046
+ params: [
1047
+ { name: 'phase', type: 'string', required: true, description: 'Phase number to insert at' },
1048
+ { name: 'description', type: 'string', required: true, description: 'Phase description' },
1049
+ ],
1050
+ execute: (cwd: string, args: Record<string, unknown>) =>
1051
+ cmdPhaseInsert(cwd, args.phase as string, args.description as string, false),
1052
+ },
1053
+ {
1054
+ name: 'grd_phase_remove',
1055
+ description: 'Remove a phase from the roadmap',
1056
+ params: [
1057
+ { name: 'phase', type: 'string', required: true, description: 'Phase number to remove' },
1058
+ {
1059
+ name: 'force',
1060
+ type: 'boolean',
1061
+ required: false,
1062
+ description: 'Force removal even if phase has content',
1063
+ },
1064
+ ],
1065
+ execute: (cwd: string, args: Record<string, unknown>) =>
1066
+ cmdPhaseRemove(cwd, args.phase as string, { force: (args.force as boolean) || false }, false),
1067
+ },
1068
+ {
1069
+ name: 'grd_phase_complete',
1070
+ description: 'Mark a phase as complete',
1071
+ params: [{ name: 'phase', type: 'string', required: true, description: 'Phase number' }],
1072
+ execute: async (cwd: string, args: Record<string, unknown>) =>
1073
+ await cmdPhaseComplete(cwd, args.phase as string, false),
1074
+ },
1075
+ {
1076
+ name: 'grd_phase_analyze_deps',
1077
+ description: 'Analyze roadmap phase dependencies and identify parallel execution groups',
1078
+ params: [],
1079
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdPhaseAnalyzeDeps(cwd, false),
1080
+ },
1081
+
1082
+ // ── Milestone ──
1083
+ {
1084
+ name: 'grd_milestone_complete',
1085
+ description: 'Mark a milestone as complete and archive it',
1086
+ params: [
1087
+ {
1088
+ name: 'version',
1089
+ type: 'string',
1090
+ required: true,
1091
+ description: 'Milestone version (e.g. v1.0)',
1092
+ },
1093
+ { name: 'name', type: 'string', required: false, description: 'Milestone name' },
1094
+ ],
1095
+ execute: (cwd: string, args: Record<string, unknown>) =>
1096
+ cmdMilestoneComplete(
1097
+ cwd,
1098
+ args.version as string,
1099
+ { name: (args.name as string) || null },
1100
+ false
1101
+ ),
1102
+ },
1103
+
1104
+ // ── Validate ──
1105
+ {
1106
+ name: 'grd_validate_consistency',
1107
+ description: 'Validate phase numbering and disk/roadmap sync',
1108
+ params: [],
1109
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdValidateConsistency(cwd, false),
1110
+ },
1111
+
1112
+ // ── Progress ──
1113
+ {
1114
+ name: 'grd_progress',
1115
+ description: 'Render project progress in the specified format',
1116
+ params: [
1117
+ {
1118
+ name: 'format',
1119
+ type: 'string',
1120
+ required: false,
1121
+ description: 'Output format: json, table, or bar (default: json)',
1122
+ },
1123
+ ],
1124
+ execute: (cwd: string, args: Record<string, unknown>) =>
1125
+ cmdProgressRender(cwd, (args.format as string) || 'json', false),
1126
+ },
1127
+
1128
+ // ── Todo ──
1129
+ // (grd_todo_complete is already defined above under utility commands)
1130
+
1131
+ // ── Phase Plan Index ──
1132
+ makePhaseCommand(
1133
+ 'grd_phase_plan_index',
1134
+ 'Index plans in a phase with wave grouping and completion status',
1135
+ (cwd, phase) => cmdPhasePlanIndex(cwd, phase, false)
1136
+ ),
1137
+
1138
+ // ── State Snapshot ──
1139
+ makeStateCommand('grd_state_snapshot', 'Structured parse of STATE.md', (cwd) =>
1140
+ cmdStateSnapshot(cwd, false)
1141
+ ),
1142
+
1143
+ // ── Summary Extract ──
1144
+ {
1145
+ name: 'grd_summary_extract',
1146
+ description: 'Extract structured data from a SUMMARY.md file',
1147
+ params: [
1148
+ { name: 'file', type: 'string', required: true, description: 'Path to the SUMMARY.md file' },
1149
+ {
1150
+ name: 'fields',
1151
+ type: 'string',
1152
+ required: false,
1153
+ description: 'Comma-separated list of fields to extract',
1154
+ },
1155
+ ],
1156
+ execute: (cwd: string, args: Record<string, unknown>) =>
1157
+ cmdSummaryExtract(
1158
+ cwd,
1159
+ args.file as string,
1160
+ (args.fields as string) ? (args.fields as string).split(',') : null,
1161
+ false
1162
+ ),
1163
+ },
1164
+
1165
+ // ── Tracker (12 subcommands) ──
1166
+ {
1167
+ name: 'grd_tracker_get_config',
1168
+ description: 'Get tracker configuration',
1169
+ params: [],
1170
+ execute: (cwd: string, _args: Record<string, unknown>) =>
1171
+ cmdTracker(cwd, 'get-config', [], false),
1172
+ },
1173
+ {
1174
+ name: 'grd_tracker_sync_roadmap',
1175
+ description: 'Sync roadmap to issue tracker',
1176
+ params: [],
1177
+ execute: (cwd: string, _args: Record<string, unknown>) =>
1178
+ cmdTracker(cwd, 'sync-roadmap', [], false),
1179
+ },
1180
+ {
1181
+ name: 'grd_tracker_sync_phase',
1182
+ description: 'Sync a phase to issue tracker',
1183
+ params: [
1184
+ { name: 'phase', type: 'string', required: true, description: 'Phase number to sync' },
1185
+ ],
1186
+ execute: (cwd: string, args: Record<string, unknown>) =>
1187
+ cmdTracker(cwd, 'sync-phase', [args.phase as string], false),
1188
+ },
1189
+ {
1190
+ name: 'grd_tracker_update_status',
1191
+ description: 'Update phase status in tracker',
1192
+ params: [
1193
+ { name: 'phase', type: 'string', required: true, description: 'Phase number' },
1194
+ { name: 'status', type: 'string', required: true, description: 'New status' },
1195
+ ],
1196
+ execute: (cwd: string, args: Record<string, unknown>) =>
1197
+ cmdTracker(cwd, 'update-status', [args.phase as string, args.status as string], false),
1198
+ },
1199
+ {
1200
+ name: 'grd_tracker_add_comment',
1201
+ description: 'Add a comment to a phase issue in tracker',
1202
+ params: [
1203
+ { name: 'phase', type: 'string', required: true, description: 'Phase number' },
1204
+ {
1205
+ name: 'file',
1206
+ type: 'string',
1207
+ required: true,
1208
+ description: 'Path to file to post as comment',
1209
+ },
1210
+ ],
1211
+ execute: (cwd: string, args: Record<string, unknown>) =>
1212
+ cmdTracker(cwd, 'add-comment', [args.phase as string, args.file as string], false),
1213
+ },
1214
+ {
1215
+ name: 'grd_tracker_sync_status',
1216
+ description: 'Sync all phase statuses to tracker',
1217
+ params: [],
1218
+ execute: (cwd: string, _args: Record<string, unknown>) =>
1219
+ cmdTracker(cwd, 'sync-status', [], false),
1220
+ },
1221
+ {
1222
+ name: 'grd_tracker_schedule',
1223
+ description: 'Compute and display schedule for tracker sync',
1224
+ params: [],
1225
+ execute: (cwd: string, _args: Record<string, unknown>) =>
1226
+ cmdTracker(cwd, 'schedule', [], false),
1227
+ },
1228
+ {
1229
+ name: 'grd_tracker_prepare_reschedule',
1230
+ description: 'Prepare reschedule data for tracker',
1231
+ params: [],
1232
+ execute: (cwd: string, _args: Record<string, unknown>) =>
1233
+ cmdTracker(cwd, 'prepare-reschedule', [], false),
1234
+ },
1235
+ {
1236
+ name: 'grd_tracker_prepare_roadmap_sync',
1237
+ description: 'Prepare roadmap sync payload for tracker',
1238
+ params: [],
1239
+ execute: (cwd: string, _args: Record<string, unknown>) =>
1240
+ cmdTracker(cwd, 'prepare-roadmap-sync', [], false),
1241
+ },
1242
+ {
1243
+ name: 'grd_tracker_prepare_phase_sync',
1244
+ description: 'Prepare phase sync payload for tracker',
1245
+ params: [{ name: 'phase', type: 'string', required: true, description: 'Phase number' }],
1246
+ execute: (cwd: string, args: Record<string, unknown>) =>
1247
+ cmdTracker(cwd, 'prepare-phase-sync', [args.phase as string], false),
1248
+ },
1249
+ {
1250
+ name: 'grd_tracker_record_mapping',
1251
+ description: 'Record tracker mapping entry',
1252
+ params: [{ name: 'args', type: 'array', required: true, description: 'Mapping arguments' }],
1253
+ execute: (cwd: string, args: Record<string, unknown>) =>
1254
+ cmdTracker(cwd, 'record-mapping', (args.args as string[]) || [], false),
1255
+ },
1256
+ {
1257
+ name: 'grd_tracker_record_status',
1258
+ description: 'Record tracker status update',
1259
+ params: [{ name: 'args', type: 'array', required: true, description: 'Status arguments' }],
1260
+ execute: (cwd: string, args: Record<string, unknown>) =>
1261
+ cmdTracker(cwd, 'record-status', (args.args as string[]) || [], false),
1262
+ },
1263
+
1264
+ // ── Dashboard, Phase Detail, Health ──
1265
+ {
1266
+ name: 'grd_dashboard',
1267
+ description: 'Render full project dashboard with milestones, phases, plans, and timeline',
1268
+ params: [],
1269
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdDashboard(cwd, true),
1270
+ },
1271
+ {
1272
+ name: 'grd_phase_detail',
1273
+ description: 'Render detailed drill-down for a single phase',
1274
+ params: [{ name: 'phase', type: 'string', required: true, description: 'Phase number' }],
1275
+ execute: (cwd: string, args: Record<string, unknown>) =>
1276
+ cmdPhaseDetail(cwd, args.phase as string, true),
1277
+ },
1278
+ {
1279
+ name: 'grd_health',
1280
+ description:
1281
+ 'Display project health indicators including blockers, deferred validations, velocity, and risks',
1282
+ params: [],
1283
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdHealth(cwd, true),
1284
+ },
1285
+ {
1286
+ name: 'grd_detect_backend',
1287
+ description: 'Detect the current AI coding CLI backend and capabilities',
1288
+ params: [],
1289
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdDetectBackend(cwd, false),
1290
+ },
1291
+
1292
+ // ── Init workflows (21 total) ──
1293
+ {
1294
+ name: 'grd_init_execute_phase',
1295
+ description: 'Initialize context for execute-phase workflow',
1296
+ params: [
1297
+ { name: 'phase', type: 'string', required: true, description: 'Phase number' },
1298
+ {
1299
+ name: 'include',
1300
+ type: 'string',
1301
+ required: false,
1302
+ description: 'Comma-separated include items',
1303
+ },
1304
+ ],
1305
+ execute: (cwd: string, args: Record<string, unknown>) =>
1306
+ cmdInitExecutePhase(
1307
+ cwd,
1308
+ args.phase as string,
1309
+ new Set((args.include as string) ? (args.include as string).split(',') : []),
1310
+ false
1311
+ ),
1312
+ },
1313
+ {
1314
+ name: 'grd_init_execute_parallel',
1315
+ description:
1316
+ 'Initialize context for parallel multi-phase execution with independence validation',
1317
+ params: [
1318
+ {
1319
+ name: 'phases',
1320
+ type: 'string',
1321
+ required: true,
1322
+ description: 'Comma-separated phase numbers to execute in parallel (e.g., "27,29")',
1323
+ },
1324
+ {
1325
+ name: 'include',
1326
+ type: 'string',
1327
+ required: false,
1328
+ description: 'Comma-separated content sections to include (e.g., "state,config")',
1329
+ },
1330
+ ],
1331
+ execute: (cwd: string, args: Record<string, unknown>) => {
1332
+ const phases = ((args.phases as string) || '')
1333
+ .split(',')
1334
+ .map((p: string) => p.trim())
1335
+ .filter(Boolean);
1336
+ const includes = new Set(
1337
+ ((args.include as string) || '')
1338
+ .split(',')
1339
+ .map((s: string) => s.trim())
1340
+ .filter(Boolean)
1341
+ );
1342
+ cmdInitExecuteParallel(cwd, phases, includes, false);
1343
+ },
1344
+ },
1345
+ {
1346
+ name: 'grd_init_plan_phase',
1347
+ description: 'Initialize context for plan-phase workflow',
1348
+ params: [
1349
+ { name: 'phase', type: 'string', required: true, description: 'Phase number' },
1350
+ {
1351
+ name: 'include',
1352
+ type: 'string',
1353
+ required: false,
1354
+ description: 'Comma-separated include items',
1355
+ },
1356
+ ],
1357
+ execute: (cwd: string, args: Record<string, unknown>) =>
1358
+ cmdInitPlanPhase(
1359
+ cwd,
1360
+ args.phase as string,
1361
+ new Set((args.include as string) ? (args.include as string).split(',') : []),
1362
+ false
1363
+ ),
1364
+ },
1365
+ {
1366
+ name: 'grd_init_new_project',
1367
+ description: 'Initialize context for init workflow',
1368
+ params: [],
1369
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdInitNewProject(cwd, false),
1370
+ },
1371
+ {
1372
+ name: 'grd_init_new_milestone',
1373
+ description: 'Initialize context for new-milestone workflow',
1374
+ params: [],
1375
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdInitNewMilestone(cwd, false),
1376
+ },
1377
+ {
1378
+ name: 'grd_init_quick',
1379
+ description: 'Initialize context for quick workflow',
1380
+ params: [
1381
+ {
1382
+ name: 'description',
1383
+ type: 'string',
1384
+ required: false,
1385
+ description: 'Quick task description',
1386
+ },
1387
+ ],
1388
+ execute: (cwd: string, args: Record<string, unknown>) =>
1389
+ cmdInitQuick(cwd, (args.description as string) || '', false),
1390
+ },
1391
+ {
1392
+ name: 'grd_init_resume',
1393
+ description: 'Initialize context for resume workflow',
1394
+ params: [],
1395
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdInitResume(cwd, false),
1396
+ },
1397
+ {
1398
+ name: 'grd_init_verify_work',
1399
+ description: 'Initialize context for verify-work workflow',
1400
+ params: [{ name: 'phase', type: 'string', required: true, description: 'Phase number' }],
1401
+ execute: (cwd: string, args: Record<string, unknown>) =>
1402
+ cmdInitVerifyWork(cwd, args.phase as string, false),
1403
+ },
1404
+ {
1405
+ name: 'grd_init_phase_op',
1406
+ description: 'Initialize context for phase-op workflow',
1407
+ params: [{ name: 'phase', type: 'string', required: true, description: 'Phase number' }],
1408
+ execute: (cwd: string, args: Record<string, unknown>) =>
1409
+ cmdInitPhaseOp(cwd, args.phase as string, false),
1410
+ },
1411
+ {
1412
+ name: 'grd_init_todos',
1413
+ description: 'Initialize context for todos workflow',
1414
+ params: [{ name: 'area', type: 'string', required: false, description: 'Area filter' }],
1415
+ execute: (cwd: string, args: Record<string, unknown>) =>
1416
+ cmdInitTodos(cwd, (args.area as string) || undefined, false),
1417
+ },
1418
+ {
1419
+ name: 'grd_init_milestone_op',
1420
+ description: 'Initialize context for milestone-op workflow',
1421
+ params: [],
1422
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdInitMilestoneOp(cwd, false),
1423
+ },
1424
+ {
1425
+ name: 'grd_init_plan_milestone_gaps',
1426
+ description: 'Initialize context for plan-milestone-gaps workflow',
1427
+ params: [],
1428
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdInitPlanMilestoneGaps(cwd, false),
1429
+ },
1430
+ {
1431
+ name: 'grd_init_map_codebase',
1432
+ description: 'Initialize context for map-codebase workflow',
1433
+ params: [],
1434
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdInitMapCodebase(cwd, false),
1435
+ },
1436
+ {
1437
+ name: 'grd_init_progress',
1438
+ description: 'Initialize context for progress workflow',
1439
+ params: [
1440
+ {
1441
+ name: 'include',
1442
+ type: 'string',
1443
+ required: false,
1444
+ description: 'Comma-separated include items',
1445
+ },
1446
+ ],
1447
+ execute: (cwd: string, args: Record<string, unknown>) =>
1448
+ cmdInitProgress(
1449
+ cwd,
1450
+ new Set((args.include as string) ? (args.include as string).split(',') : []),
1451
+ false
1452
+ ),
1453
+ },
1454
+ {
1455
+ name: 'grd_init_survey',
1456
+ description: 'Initialize context for survey research workflow',
1457
+ params: [
1458
+ { name: 'topic', type: 'string', required: false, description: 'Survey topic' },
1459
+ {
1460
+ name: 'include',
1461
+ type: 'string',
1462
+ required: false,
1463
+ description: 'Comma-separated include items',
1464
+ },
1465
+ ],
1466
+ execute: (cwd: string, args: Record<string, unknown>) =>
1467
+ cmdInitResearchWorkflow(
1468
+ cwd,
1469
+ 'survey',
1470
+ (args.topic as string) || '',
1471
+ new Set((args.include as string) ? (args.include as string).split(',') : []),
1472
+ false
1473
+ ),
1474
+ },
1475
+ {
1476
+ name: 'grd_init_deep_dive',
1477
+ description: 'Initialize context for deep-dive research workflow',
1478
+ params: [
1479
+ { name: 'paper', type: 'string', required: false, description: 'Paper identifier' },
1480
+ {
1481
+ name: 'include',
1482
+ type: 'string',
1483
+ required: false,
1484
+ description: 'Comma-separated include items',
1485
+ },
1486
+ ],
1487
+ execute: (cwd: string, args: Record<string, unknown>) =>
1488
+ cmdInitResearchWorkflow(
1489
+ cwd,
1490
+ 'deep-dive',
1491
+ (args.paper as string) || '',
1492
+ new Set((args.include as string) ? (args.include as string).split(',') : []),
1493
+ false
1494
+ ),
1495
+ },
1496
+ {
1497
+ name: 'grd_init_feasibility',
1498
+ description: 'Initialize context for feasibility research workflow',
1499
+ params: [
1500
+ { name: 'approach', type: 'string', required: false, description: 'Approach description' },
1501
+ {
1502
+ name: 'include',
1503
+ type: 'string',
1504
+ required: false,
1505
+ description: 'Comma-separated include items',
1506
+ },
1507
+ ],
1508
+ execute: (cwd: string, args: Record<string, unknown>) =>
1509
+ cmdInitResearchWorkflow(
1510
+ cwd,
1511
+ 'feasibility',
1512
+ (args.approach as string) || '',
1513
+ new Set((args.include as string) ? (args.include as string).split(',') : []),
1514
+ false
1515
+ ),
1516
+ },
1517
+ {
1518
+ name: 'grd_init_eval_plan',
1519
+ description: 'Initialize context for eval-plan research workflow',
1520
+ params: [
1521
+ {
1522
+ name: 'description',
1523
+ type: 'string',
1524
+ required: false,
1525
+ description: 'Evaluation plan description',
1526
+ },
1527
+ {
1528
+ name: 'include',
1529
+ type: 'string',
1530
+ required: false,
1531
+ description: 'Comma-separated include items',
1532
+ },
1533
+ ],
1534
+ execute: (cwd: string, args: Record<string, unknown>) =>
1535
+ cmdInitResearchWorkflow(
1536
+ cwd,
1537
+ 'eval-plan',
1538
+ (args.description as string) || '',
1539
+ new Set((args.include as string) ? (args.include as string).split(',') : []),
1540
+ false
1541
+ ),
1542
+ },
1543
+ {
1544
+ name: 'grd_init_eval_report',
1545
+ description: 'Initialize context for eval-report research workflow',
1546
+ params: [
1547
+ {
1548
+ name: 'description',
1549
+ type: 'string',
1550
+ required: false,
1551
+ description: 'Evaluation report description',
1552
+ },
1553
+ {
1554
+ name: 'include',
1555
+ type: 'string',
1556
+ required: false,
1557
+ description: 'Comma-separated include items',
1558
+ },
1559
+ ],
1560
+ execute: (cwd: string, args: Record<string, unknown>) =>
1561
+ cmdInitResearchWorkflow(
1562
+ cwd,
1563
+ 'eval-report',
1564
+ (args.description as string) || '',
1565
+ new Set((args.include as string) ? (args.include as string).split(',') : []),
1566
+ false
1567
+ ),
1568
+ },
1569
+ {
1570
+ name: 'grd_init_assess_baseline',
1571
+ description: 'Initialize context for assess-baseline research workflow',
1572
+ params: [
1573
+ {
1574
+ name: 'description',
1575
+ type: 'string',
1576
+ required: false,
1577
+ description: 'Baseline assessment description',
1578
+ },
1579
+ {
1580
+ name: 'include',
1581
+ type: 'string',
1582
+ required: false,
1583
+ description: 'Comma-separated include items',
1584
+ },
1585
+ ],
1586
+ execute: (cwd: string, args: Record<string, unknown>) =>
1587
+ cmdInitResearchWorkflow(
1588
+ cwd,
1589
+ 'assess-baseline',
1590
+ (args.description as string) || '',
1591
+ new Set((args.include as string) ? (args.include as string).split(',') : []),
1592
+ false
1593
+ ),
1594
+ },
1595
+ {
1596
+ name: 'grd_init_product_plan',
1597
+ description: 'Initialize context for product-plan workflow',
1598
+ params: [
1599
+ {
1600
+ name: 'description',
1601
+ type: 'string',
1602
+ required: false,
1603
+ description: 'Product plan description',
1604
+ },
1605
+ {
1606
+ name: 'include',
1607
+ type: 'string',
1608
+ required: false,
1609
+ description: 'Comma-separated include items',
1610
+ },
1611
+ ],
1612
+ execute: (cwd: string, args: Record<string, unknown>) =>
1613
+ cmdInitResearchWorkflow(
1614
+ cwd,
1615
+ 'product-plan',
1616
+ (args.description as string) || '',
1617
+ new Set((args.include as string) ? (args.include as string).split(',') : []),
1618
+ false
1619
+ ),
1620
+ },
1621
+ {
1622
+ name: 'grd_init_iterate',
1623
+ description: 'Initialize context for iterate workflow',
1624
+ params: [
1625
+ {
1626
+ name: 'description',
1627
+ type: 'string',
1628
+ required: false,
1629
+ description: 'Iteration description',
1630
+ },
1631
+ {
1632
+ name: 'include',
1633
+ type: 'string',
1634
+ required: false,
1635
+ description: 'Comma-separated include items',
1636
+ },
1637
+ ],
1638
+ execute: (cwd: string, args: Record<string, unknown>) =>
1639
+ cmdInitResearchWorkflow(
1640
+ cwd,
1641
+ 'iterate',
1642
+ (args.description as string) || '',
1643
+ new Set((args.include as string) ? (args.include as string).split(',') : []),
1644
+ false
1645
+ ),
1646
+ },
1647
+
1648
+ // ── Agent & Operation Workflow Inits ──
1649
+ {
1650
+ name: 'grd_init_debug',
1651
+ description: 'Initialize debug context with phase info, debug files, and project state',
1652
+ params: [
1653
+ { name: 'phase', type: 'string', required: false, description: 'Optional phase number' },
1654
+ ],
1655
+ execute: (cwd: string, args: Record<string, unknown>) =>
1656
+ cmdInitDebug(cwd, (args.phase as string) || null, false),
1657
+ },
1658
+ {
1659
+ name: 'grd_init_debugger',
1660
+ description: 'Initialize grd-debugger agent context (alias for grd_init_debug)',
1661
+ params: [
1662
+ { name: 'phase', type: 'string', required: false, description: 'Optional phase number' },
1663
+ ],
1664
+ execute: (cwd: string, args: Record<string, unknown>) =>
1665
+ cmdInitDebugger(cwd, (args.phase as string) || null, false),
1666
+ },
1667
+ {
1668
+ name: 'grd_init_integration_check',
1669
+ description:
1670
+ 'Initialize integration-check context with phase inventory and deferred validations',
1671
+ params: [
1672
+ { name: 'phase', type: 'string', required: false, description: 'Optional phase number' },
1673
+ ],
1674
+ execute: (cwd: string, args: Record<string, unknown>) =>
1675
+ cmdInitIntegrationCheck(cwd, (args.phase as string) || null, false),
1676
+ },
1677
+ {
1678
+ name: 'grd_init_integration_checker',
1679
+ description:
1680
+ 'Initialize grd-integration-checker agent context (alias for grd_init_integration_check)',
1681
+ params: [
1682
+ { name: 'phase', type: 'string', required: false, description: 'Optional phase number' },
1683
+ ],
1684
+ execute: (cwd: string, args: Record<string, unknown>) =>
1685
+ cmdInitIntegrationChecker(cwd, (args.phase as string) || null, false),
1686
+ },
1687
+ {
1688
+ name: 'grd_init_migrate',
1689
+ description: 'Initialize migrate context with planning directory layout inventory',
1690
+ params: [],
1691
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdInitMigrate(cwd, false),
1692
+ },
1693
+ {
1694
+ name: 'grd_init_migrator',
1695
+ description: 'Initialize grd-migrator agent context (alias for grd_init_migrate)',
1696
+ params: [],
1697
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdInitMigrator(cwd, false),
1698
+ },
1699
+ {
1700
+ name: 'grd_init_plan_check',
1701
+ description: 'Initialize plan-check context with phase plan files and roadmap goal',
1702
+ params: [
1703
+ { name: 'phase', type: 'string', required: true, description: 'Phase number to check' },
1704
+ ],
1705
+ execute: (cwd: string, args: Record<string, unknown>) =>
1706
+ cmdInitPlanCheck(cwd, args.phase as string, false),
1707
+ },
1708
+ {
1709
+ name: 'grd_init_plan_checker',
1710
+ description: 'Initialize grd-plan-checker agent context (alias for grd_init_plan_check)',
1711
+ params: [
1712
+ { name: 'phase', type: 'string', required: true, description: 'Phase number to check' },
1713
+ ],
1714
+ execute: (cwd: string, args: Record<string, unknown>) =>
1715
+ cmdInitPlanChecker(cwd, args.phase as string, false),
1716
+ },
1717
+ {
1718
+ name: 'grd_init_executor',
1719
+ description: 'Initialize grd-executor agent context with phase plans, STATE, and ROADMAP',
1720
+ params: [
1721
+ { name: 'phase', type: 'string', required: true, description: 'Phase number' },
1722
+ {
1723
+ name: 'include',
1724
+ type: 'string',
1725
+ required: false,
1726
+ description: 'Comma-separated include items (state,roadmap)',
1727
+ },
1728
+ ],
1729
+ execute: (cwd: string, args: Record<string, unknown>) =>
1730
+ cmdInitExecutor(
1731
+ cwd,
1732
+ args.phase as string,
1733
+ new Set((args.include as string) ? (args.include as string).split(',') : []),
1734
+ false
1735
+ ),
1736
+ },
1737
+ {
1738
+ name: 'grd_init_code_review',
1739
+ description: 'Initialize code-review context for a phase',
1740
+ params: [{ name: 'phase', type: 'string', required: true, description: 'Phase number' }],
1741
+ execute: (cwd: string, args: Record<string, unknown>) =>
1742
+ cmdInitCodeReview(cwd, args.phase as string, false),
1743
+ },
1744
+ {
1745
+ name: 'grd_init_code_reviewer',
1746
+ description: 'Initialize grd-code-reviewer agent context (alias for grd_init_code_review)',
1747
+ params: [{ name: 'phase', type: 'string', required: true, description: 'Phase number' }],
1748
+ execute: (cwd: string, args: Record<string, unknown>) =>
1749
+ cmdInitCodeReviewer(cwd, args.phase as string, false),
1750
+ },
1751
+ {
1752
+ name: 'grd_init_phase_research',
1753
+ description: 'Initialize phase-research context with research files for a phase',
1754
+ params: [
1755
+ { name: 'phase', type: 'string', required: true, description: 'Phase number' },
1756
+ {
1757
+ name: 'include',
1758
+ type: 'string',
1759
+ required: false,
1760
+ description: 'Comma-separated include items',
1761
+ },
1762
+ ],
1763
+ execute: (cwd: string, args: Record<string, unknown>) =>
1764
+ cmdInitPhaseResearch(
1765
+ cwd,
1766
+ args.phase as string,
1767
+ new Set((args.include as string) ? (args.include as string).split(',') : []),
1768
+ false
1769
+ ),
1770
+ },
1771
+ {
1772
+ name: 'grd_init_phase_researcher',
1773
+ description:
1774
+ 'Initialize grd-phase-researcher agent context (alias for grd_init_phase_research)',
1775
+ params: [
1776
+ { name: 'phase', type: 'string', required: true, description: 'Phase number' },
1777
+ {
1778
+ name: 'include',
1779
+ type: 'string',
1780
+ required: false,
1781
+ description: 'Comma-separated include items',
1782
+ },
1783
+ ],
1784
+ execute: (cwd: string, args: Record<string, unknown>) =>
1785
+ cmdInitPhaseResearcher(
1786
+ cwd,
1787
+ args.phase as string,
1788
+ new Set((args.include as string) ? (args.include as string).split(',') : []),
1789
+ false
1790
+ ),
1791
+ },
1792
+ {
1793
+ name: 'grd_init_codebase_mapper',
1794
+ description: 'Initialize grd-codebase-mapper agent context (alias for grd_init_map_codebase)',
1795
+ params: [],
1796
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdInitCodebaseMapper(cwd, false),
1797
+ },
1798
+ // ── Research Agent Inits (direct functions) ──
1799
+ {
1800
+ name: 'grd_init_baseline_assessor',
1801
+ description:
1802
+ 'Initialize grd-baseline-assessor agent context with assessor model and eval config',
1803
+ params: [],
1804
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdInitBaselineAssessor(cwd, false),
1805
+ },
1806
+ {
1807
+ name: 'grd_init_deep_diver',
1808
+ description: 'Initialize grd-deep-diver agent context with topic, landscape, and papers info',
1809
+ params: [
1810
+ { name: 'topic', type: 'string', required: false, description: 'Paper or topic identifier' },
1811
+ ],
1812
+ execute: (cwd: string, args: Record<string, unknown>) =>
1813
+ cmdInitDeepDiver(cwd, (args.topic as string) || '', false),
1814
+ },
1815
+ {
1816
+ name: 'grd_init_eval_planner',
1817
+ description: 'Initialize grd-eval-planner agent context with phase info and eval config',
1818
+ params: [
1819
+ { name: 'phase', type: 'string', required: false, description: 'Optional phase number' },
1820
+ ],
1821
+ execute: (cwd: string, args: Record<string, unknown>) =>
1822
+ cmdInitEvalPlanner(cwd, (args.phase as string) || null, false),
1823
+ },
1824
+ {
1825
+ name: 'grd_init_eval_reporter',
1826
+ description:
1827
+ 'Initialize grd-eval-reporter agent context with phase plans, summaries, and eval config',
1828
+ params: [
1829
+ { name: 'phase', type: 'string', required: false, description: 'Optional phase number' },
1830
+ ],
1831
+ execute: (cwd: string, args: Record<string, unknown>) =>
1832
+ cmdInitEvalReporter(cwd, (args.phase as string) || null, false),
1833
+ },
1834
+ {
1835
+ name: 'grd_init_feasibility_analyst',
1836
+ description:
1837
+ 'Initialize grd-feasibility-analyst agent context with topic, deep dives, and research files',
1838
+ params: [
1839
+ {
1840
+ name: 'topic',
1841
+ type: 'string',
1842
+ required: false,
1843
+ description: 'Approach or topic to analyze',
1844
+ },
1845
+ ],
1846
+ execute: (cwd: string, args: Record<string, unknown>) =>
1847
+ cmdInitFeasibilityAnalyst(cwd, (args.topic as string) || '', false),
1848
+ },
1849
+ {
1850
+ name: 'grd_init_product_owner',
1851
+ description: 'Initialize grd-product-owner agent context with project docs and milestone info',
1852
+ params: [],
1853
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdInitProductOwner(cwd, false),
1854
+ },
1855
+ {
1856
+ name: 'grd_init_project_researcher',
1857
+ description:
1858
+ 'Initialize grd-project-researcher agent context with project docs and research landscape',
1859
+ params: [{ name: 'topic', type: 'string', required: false, description: 'Research topic' }],
1860
+ execute: (cwd: string, args: Record<string, unknown>) =>
1861
+ cmdInitProjectResearcher(cwd, (args.topic as string) || '', false),
1862
+ },
1863
+ {
1864
+ name: 'grd_init_research_synthesizer',
1865
+ description:
1866
+ 'Initialize grd-research-synthesizer agent context with deep dives and research files',
1867
+ params: [],
1868
+ execute: (cwd: string, _args: Record<string, unknown>) =>
1869
+ cmdInitResearchSynthesizer(cwd, false),
1870
+ },
1871
+ {
1872
+ name: 'grd_init_roadmapper',
1873
+ description: 'Initialize grd-roadmapper agent context with project docs and milestone info',
1874
+ params: [],
1875
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdInitRoadmapper(cwd, false),
1876
+ },
1877
+ {
1878
+ name: 'grd_init_surveyor',
1879
+ description:
1880
+ 'Initialize grd-surveyor agent context with landscape, papers, and research config',
1881
+ params: [{ name: 'topic', type: 'string', required: false, description: 'Survey topic' }],
1882
+ execute: (cwd: string, args: Record<string, unknown>) =>
1883
+ cmdInitSurveyor(cwd, (args.topic as string) || '', false),
1884
+ },
1885
+ {
1886
+ name: 'grd_init_verifier',
1887
+ description:
1888
+ 'Initialize grd-verifier agent context with phase plans, summaries, and eval config',
1889
+ params: [
1890
+ { name: 'phase', type: 'string', required: false, description: 'Optional phase number' },
1891
+ ],
1892
+ execute: (cwd: string, args: Record<string, unknown>) =>
1893
+ cmdInitVerifier(cwd, (args.phase as string) || null, false),
1894
+ },
1895
+ // Direct research function bindings (without the generic cmdInitResearchWorkflow wrapper)
1896
+ {
1897
+ name: 'grd_init_assess_baseline_direct',
1898
+ description:
1899
+ 'Initialize assess-baseline context directly (assessor model, eval config, artifact existence)',
1900
+ params: [],
1901
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdInitAssessBaseline(cwd, false),
1902
+ },
1903
+ {
1904
+ name: 'grd_init_deep_dive_direct',
1905
+ description:
1906
+ 'Initialize deep-dive context directly (deep-diver model, existing deep dives list)',
1907
+ params: [
1908
+ { name: 'topic', type: 'string', required: false, description: 'Paper or topic identifier' },
1909
+ ],
1910
+ execute: (cwd: string, args: Record<string, unknown>) =>
1911
+ cmdInitDeepDive(cwd, (args.topic as string) || '', false),
1912
+ },
1913
+ {
1914
+ name: 'grd_init_eval_plan_direct',
1915
+ description:
1916
+ 'Initialize eval-plan context directly (eval-planner model, phase info, eval config)',
1917
+ params: [
1918
+ { name: 'phase', type: 'string', required: false, description: 'Optional phase number' },
1919
+ ],
1920
+ execute: (cwd: string, args: Record<string, unknown>) =>
1921
+ cmdInitEvalPlan(cwd, (args.phase as string) || null, false),
1922
+ },
1923
+ {
1924
+ name: 'grd_init_eval_report_direct',
1925
+ description:
1926
+ 'Initialize eval-report context directly (eval-reporter model, phase plans, summaries)',
1927
+ params: [
1928
+ { name: 'phase', type: 'string', required: false, description: 'Optional phase number' },
1929
+ ],
1930
+ execute: (cwd: string, args: Record<string, unknown>) =>
1931
+ cmdInitEvalReport(cwd, (args.phase as string) || null, false),
1932
+ },
1933
+ {
1934
+ name: 'grd_init_feasibility_direct',
1935
+ description: 'Initialize feasibility context directly (feasibility model, topic, deep dives)',
1936
+ params: [
1937
+ {
1938
+ name: 'topic',
1939
+ type: 'string',
1940
+ required: false,
1941
+ description: 'Approach or topic to analyze',
1942
+ },
1943
+ ],
1944
+ execute: (cwd: string, args: Record<string, unknown>) =>
1945
+ cmdInitFeasibility(cwd, (args.topic as string) || '', false),
1946
+ },
1947
+
1948
+ // ── Long-Term Roadmap (12 subcommands) ──
1949
+ {
1950
+ name: 'grd_long_term_roadmap_list',
1951
+ description: 'List all LT milestones',
1952
+ params: [],
1953
+ execute: (cwd: string, _args: Record<string, unknown>) =>
1954
+ cmdLongTermRoadmap(cwd, 'list', [], false),
1955
+ },
1956
+ {
1957
+ name: 'grd_long_term_roadmap_add',
1958
+ description: 'Add a new LT milestone',
1959
+ params: [
1960
+ { name: 'name', type: 'string', required: true, description: 'LT milestone name' },
1961
+ { name: 'goal', type: 'string', required: true, description: 'LT milestone goal' },
1962
+ ],
1963
+ execute: (cwd: string, args: Record<string, unknown>) =>
1964
+ cmdLongTermRoadmap(
1965
+ cwd,
1966
+ 'add',
1967
+ ['--name', args.name as string, '--goal', args.goal as string],
1968
+ false
1969
+ ),
1970
+ },
1971
+ {
1972
+ name: 'grd_long_term_roadmap_remove',
1973
+ description: 'Remove an LT milestone (protected if shipped)',
1974
+ params: [
1975
+ { name: 'id', type: 'string', required: true, description: 'LT milestone ID (e.g. LT-2)' },
1976
+ ],
1977
+ execute: (cwd: string, args: Record<string, unknown>) =>
1978
+ cmdLongTermRoadmap(cwd, 'remove', ['--id', args.id as string], false),
1979
+ },
1980
+ {
1981
+ name: 'grd_long_term_roadmap_update',
1982
+ description: 'Update LT milestone fields (name, goal, status)',
1983
+ params: [
1984
+ { name: 'id', type: 'string', required: true, description: 'LT milestone ID' },
1985
+ { name: 'name', type: 'string', required: false, description: 'New name' },
1986
+ { name: 'goal', type: 'string', required: false, description: 'New goal' },
1987
+ {
1988
+ name: 'status',
1989
+ type: 'string',
1990
+ required: false,
1991
+ description: 'New status (completed/active/planned)',
1992
+ },
1993
+ ],
1994
+ execute: (cwd: string, args: Record<string, unknown>) => {
1995
+ const subArgs: string[] = ['--id', args.id as string];
1996
+ if (args.name) subArgs.push('--name', args.name as string);
1997
+ if (args.goal) subArgs.push('--goal', args.goal as string);
1998
+ if (args.status) subArgs.push('--status', args.status as string);
1999
+ return cmdLongTermRoadmap(cwd, 'update', subArgs, false);
2000
+ },
2001
+ },
2002
+ {
2003
+ name: 'grd_long_term_roadmap_link',
2004
+ description: 'Link a normal milestone to an LT milestone',
2005
+ params: [
2006
+ { name: 'id', type: 'string', required: true, description: 'LT milestone ID' },
2007
+ { name: 'version', type: 'string', required: true, description: 'Normal milestone version' },
2008
+ {
2009
+ name: 'note',
2010
+ type: 'string',
2011
+ required: false,
2012
+ description: 'Optional note (e.g. "planned")',
2013
+ },
2014
+ ],
2015
+ execute: (cwd: string, args: Record<string, unknown>) => {
2016
+ const subArgs: string[] = ['--id', args.id as string, '--version', args.version as string];
2017
+ if (args.note) subArgs.push('--note', args.note as string);
2018
+ return cmdLongTermRoadmap(cwd, 'link', subArgs, false);
2019
+ },
2020
+ },
2021
+ {
2022
+ name: 'grd_long_term_roadmap_unlink',
2023
+ description: 'Unlink a normal milestone from an LT milestone (protected if shipped)',
2024
+ params: [
2025
+ { name: 'id', type: 'string', required: true, description: 'LT milestone ID' },
2026
+ { name: 'version', type: 'string', required: true, description: 'Normal milestone version' },
2027
+ ],
2028
+ execute: (cwd: string, args: Record<string, unknown>) =>
2029
+ cmdLongTermRoadmap(
2030
+ cwd,
2031
+ 'unlink',
2032
+ ['--id', args.id as string, '--version', args.version as string],
2033
+ false
2034
+ ),
2035
+ },
2036
+ {
2037
+ name: 'grd_long_term_roadmap_init',
2038
+ description: 'Auto-group existing ROADMAP.md milestones into LT-1',
2039
+ params: [{ name: 'project', type: 'string', required: false, description: 'Project name' }],
2040
+ execute: (cwd: string, args: Record<string, unknown>) => {
2041
+ const subArgs: string[] = (args.project as string)
2042
+ ? ['--project', args.project as string]
2043
+ : [];
2044
+ return cmdLongTermRoadmap(cwd, 'init', subArgs, false);
2045
+ },
2046
+ },
2047
+ {
2048
+ name: 'grd_long_term_roadmap_display',
2049
+ description: 'Display the long-term roadmap in formatted text',
2050
+ params: [],
2051
+ execute: (cwd: string, _args: Record<string, unknown>) =>
2052
+ cmdLongTermRoadmap(cwd, 'display', [], false),
2053
+ },
2054
+ {
2055
+ name: 'grd_long_term_roadmap_parse',
2056
+ description: 'Parse the long-term roadmap file into structured data',
2057
+ params: [
2058
+ {
2059
+ name: 'file',
2060
+ type: 'string',
2061
+ required: false,
2062
+ description: 'Path to LONG-TERM-ROADMAP.md',
2063
+ },
2064
+ ],
2065
+ execute: (cwd: string, args: Record<string, unknown>) =>
2066
+ cmdLongTermRoadmap(cwd, 'parse', (args.file as string) ? [args.file as string] : [], false),
2067
+ },
2068
+ {
2069
+ name: 'grd_long_term_roadmap_validate',
2070
+ description: 'Validate the long-term roadmap structure',
2071
+ params: [
2072
+ {
2073
+ name: 'file',
2074
+ type: 'string',
2075
+ required: false,
2076
+ description: 'Path to LONG-TERM-ROADMAP.md',
2077
+ },
2078
+ ],
2079
+ execute: (cwd: string, args: Record<string, unknown>) =>
2080
+ cmdLongTermRoadmap(
2081
+ cwd,
2082
+ 'validate',
2083
+ (args.file as string) ? [args.file as string] : [],
2084
+ false
2085
+ ),
2086
+ },
2087
+ {
2088
+ name: 'grd_long_term_roadmap_refine',
2089
+ description: 'Output context for AI discussion of an LT milestone',
2090
+ params: [{ name: 'id', type: 'string', required: true, description: 'LT milestone ID' }],
2091
+ execute: (cwd: string, args: Record<string, unknown>) =>
2092
+ cmdLongTermRoadmap(cwd, 'refine', ['--id', args.id as string], false),
2093
+ },
2094
+ {
2095
+ name: 'grd_long_term_roadmap_history',
2096
+ description: 'Update refinement history in the long-term roadmap',
2097
+ params: [
2098
+ { name: 'action', type: 'string', required: true, description: 'History action' },
2099
+ { name: 'details', type: 'string', required: true, description: 'Action details' },
2100
+ ],
2101
+ execute: (cwd: string, args: Record<string, unknown>) =>
2102
+ cmdLongTermRoadmap(
2103
+ cwd,
2104
+ 'history',
2105
+ ['--action', args.action as string, '--details', args.details as string],
2106
+ false
2107
+ ),
2108
+ },
2109
+
2110
+ // ── Quality Analysis ──
2111
+ {
2112
+ name: 'grd_quality_analysis',
2113
+ description: 'Run quality analysis for a phase',
2114
+ params: [
2115
+ { name: 'phase', type: 'string', required: true, description: 'Phase number to analyze' },
2116
+ ],
2117
+ execute: (cwd: string, args: Record<string, unknown>) =>
2118
+ cmdQualityAnalysis(cwd, ['--phase', args.phase as string], false),
2119
+ },
2120
+
2121
+ // ── Requirement & Search commands ──
2122
+ {
2123
+ name: 'grd_requirement_get',
2124
+ description: 'Get a requirement by ID with status and phase from traceability matrix',
2125
+ params: [
2126
+ {
2127
+ name: 'req_id',
2128
+ type: 'string',
2129
+ required: true,
2130
+ description: 'Requirement ID (e.g. REQ-37)',
2131
+ },
2132
+ ],
2133
+ execute: (cwd: string, args: Record<string, unknown>) =>
2134
+ cmdRequirementGet(cwd, args.req_id as string, false),
2135
+ },
2136
+ {
2137
+ name: 'grd_requirement_list',
2138
+ description: 'List requirements with optional filters (phase, priority, status, category)',
2139
+ params: [
2140
+ { name: 'phase', type: 'string', required: false, description: 'Filter by phase number' },
2141
+ {
2142
+ name: 'priority',
2143
+ type: 'string',
2144
+ required: false,
2145
+ description: 'Filter by priority (e.g. P1, P2)',
2146
+ },
2147
+ {
2148
+ name: 'status',
2149
+ type: 'string',
2150
+ required: false,
2151
+ description: 'Filter by status (Pending, In Progress, Done, Deferred)',
2152
+ },
2153
+ { name: 'category', type: 'string', required: false, description: 'Filter by category' },
2154
+ {
2155
+ name: 'all',
2156
+ type: 'boolean',
2157
+ required: false,
2158
+ description: 'Include archived milestone requirements',
2159
+ },
2160
+ ],
2161
+ execute: (cwd: string, args: Record<string, unknown>) =>
2162
+ cmdRequirementList(
2163
+ cwd,
2164
+ {
2165
+ phase: (args.phase as string) || null,
2166
+ priority: (args.priority as string) || null,
2167
+ status: (args.status as string) || null,
2168
+ category: (args.category as string) || null,
2169
+ all: (args.all as boolean) || false,
2170
+ },
2171
+ false
2172
+ ),
2173
+ },
2174
+ {
2175
+ name: 'grd_requirement_traceability',
2176
+ description: 'Get the traceability matrix with optional phase filter',
2177
+ params: [
2178
+ { name: 'phase', type: 'string', required: false, description: 'Filter by phase number' },
2179
+ ],
2180
+ execute: (cwd: string, args: Record<string, unknown>) =>
2181
+ cmdRequirementTraceability(cwd, { phase: (args.phase as string) || null }, false),
2182
+ },
2183
+ {
2184
+ name: 'grd_requirement_update_status',
2185
+ description: 'Update the status of a requirement in the traceability matrix',
2186
+ params: [
2187
+ {
2188
+ name: 'req_id',
2189
+ type: 'string',
2190
+ required: true,
2191
+ description: 'Requirement ID (e.g. REQ-37)',
2192
+ },
2193
+ {
2194
+ name: 'status',
2195
+ type: 'string',
2196
+ required: true,
2197
+ description: 'New status (Pending, In Progress, Done, Deferred)',
2198
+ },
2199
+ ],
2200
+ execute: (cwd: string, args: Record<string, unknown>) =>
2201
+ cmdRequirementUpdateStatus(cwd, args.req_id as string, args.status as string, false),
2202
+ },
2203
+ {
2204
+ name: 'grd_search',
2205
+ description: 'Search across all .planning/ markdown files for a text query',
2206
+ params: [
2207
+ { name: 'query', type: 'string', required: true, description: 'Text query to search for' },
2208
+ ],
2209
+ execute: (cwd: string, args: Record<string, unknown>) =>
2210
+ cmdSearch(cwd, args.query as string, false),
2211
+ },
2212
+
2213
+ // ── Worktree commands ──
2214
+ {
2215
+ name: 'grd_worktree_create',
2216
+ description: 'Create a git worktree for isolated phase execution',
2217
+ params: [
2218
+ { name: 'phase', type: 'string', required: true, description: 'Phase number' },
2219
+ {
2220
+ name: 'milestone',
2221
+ type: 'string',
2222
+ required: false,
2223
+ description: 'Milestone version (defaults to current)',
2224
+ },
2225
+ { name: 'slug', type: 'string', required: false, description: 'Phase slug for branch name' },
2226
+ {
2227
+ name: 'start_point',
2228
+ type: 'string',
2229
+ required: false,
2230
+ description:
2231
+ 'Branch or commit to fork from (for stacked PRs). If omitted, forks from current HEAD.',
2232
+ },
2233
+ ],
2234
+ execute: (cwd: string, args: Record<string, unknown>) =>
2235
+ cmdWorktreeCreate(
2236
+ cwd,
2237
+ {
2238
+ phase: args.phase,
2239
+ milestone: (args.milestone as string) || null,
2240
+ slug: (args.slug as string) || null,
2241
+ startPoint: (args.start_point as string) || null,
2242
+ },
2243
+ false
2244
+ ),
2245
+ },
2246
+ {
2247
+ name: 'grd_worktree_remove',
2248
+ description: 'Remove a git worktree and clean up temp directory',
2249
+ params: [
2250
+ {
2251
+ name: 'phase',
2252
+ type: 'string',
2253
+ required: false,
2254
+ description: 'Phase number to remove worktree for',
2255
+ },
2256
+ { name: 'path', type: 'string', required: false, description: 'Direct path to worktree' },
2257
+ {
2258
+ name: 'stale',
2259
+ type: 'boolean',
2260
+ required: false,
2261
+ description: 'Remove all stale worktrees',
2262
+ },
2263
+ ],
2264
+ execute: (cwd: string, args: Record<string, unknown>) =>
2265
+ (args.stale as boolean)
2266
+ ? cmdWorktreeRemoveStale(cwd, false)
2267
+ : cmdWorktreeRemove(
2268
+ cwd,
2269
+ { phase: (args.phase as string) || null, path: (args.path as string) || null },
2270
+ false
2271
+ ),
2272
+ },
2273
+ {
2274
+ name: 'grd_worktree_list',
2275
+ description: 'List all active GRD worktrees',
2276
+ params: [],
2277
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdWorktreeList(cwd, false),
2278
+ },
2279
+ {
2280
+ name: 'grd_worktree_push_pr',
2281
+ description: 'Push worktree branch and create a PR targeting the base branch',
2282
+ params: [
2283
+ { name: 'phase', type: 'string', required: true, description: 'Phase number' },
2284
+ { name: 'milestone', type: 'string', required: false, description: 'Milestone version' },
2285
+ { name: 'title', type: 'string', required: false, description: 'PR title' },
2286
+ { name: 'body', type: 'string', required: false, description: 'PR body markdown' },
2287
+ { name: 'base', type: 'string', required: false, description: 'Base branch for PR' },
2288
+ ],
2289
+ execute: (cwd: string, args: Record<string, unknown>) =>
2290
+ cmdWorktreePushAndPR(
2291
+ cwd,
2292
+ {
2293
+ phase: args.phase,
2294
+ milestone: (args.milestone as string) || null,
2295
+ title: (args.title as string) || null,
2296
+ body: (args.body as string) || null,
2297
+ base: (args.base as string) || null,
2298
+ },
2299
+ false
2300
+ ),
2301
+ },
2302
+
2303
+ // ── Autopilot ──
2304
+ {
2305
+ name: 'grd_autopilot_run',
2306
+ description:
2307
+ 'Run autopilot to plan and execute multiple phases sequentially with fresh context per step',
2308
+ params: [
2309
+ {
2310
+ name: 'phase_from',
2311
+ type: 'string',
2312
+ required: false,
2313
+ description: 'Starting phase number (inclusive)',
2314
+ },
2315
+ {
2316
+ name: 'phase_to',
2317
+ type: 'string',
2318
+ required: false,
2319
+ description: 'Ending phase number (inclusive)',
2320
+ },
2321
+ {
2322
+ name: 'milestone',
2323
+ type: 'boolean',
2324
+ required: false,
2325
+ description: 'Run in milestone mode (default when no phase range given)',
2326
+ },
2327
+ {
2328
+ name: 'dry_run',
2329
+ type: 'boolean',
2330
+ required: false,
2331
+ description: 'Show plan without executing',
2332
+ },
2333
+ {
2334
+ name: 'skip_plan',
2335
+ type: 'boolean',
2336
+ required: false,
2337
+ description: 'Skip planning step',
2338
+ },
2339
+ {
2340
+ name: 'skip_execute',
2341
+ type: 'boolean',
2342
+ required: false,
2343
+ description: 'Skip execution step',
2344
+ },
2345
+ {
2346
+ name: 'timeout',
2347
+ type: 'number',
2348
+ required: false,
2349
+ description: 'Timeout per invocation in minutes (default: 30)',
2350
+ },
2351
+ {
2352
+ name: 'max_turns',
2353
+ type: 'number',
2354
+ required: false,
2355
+ description: 'Max turns per claude -p invocation',
2356
+ },
2357
+ {
2358
+ name: 'model',
2359
+ type: 'string',
2360
+ required: false,
2361
+ description: 'Model override for claude -p',
2362
+ },
2363
+ ],
2364
+ execute: (cwd: string, args: Record<string, unknown>) => {
2365
+ const cliArgs: string[] = [];
2366
+ if (args.phase_from) cliArgs.push('--phase-from', args.phase_from as string);
2367
+ if (args.phase_to) cliArgs.push('--phase-to', args.phase_to as string);
2368
+ if (args.milestone) cliArgs.push('--milestone');
2369
+ if (args.dry_run) cliArgs.push('--dry-run');
2370
+ if (args.skip_plan) cliArgs.push('--skip-plan');
2371
+ if (args.skip_execute) cliArgs.push('--skip-execute');
2372
+ if (args.timeout) cliArgs.push('--timeout', String(args.timeout));
2373
+ if (args.max_turns) cliArgs.push('--max-turns', String(args.max_turns));
2374
+ if (args.model) cliArgs.push('--model', args.model as string);
2375
+ return cmdAutopilot(cwd, cliArgs, false);
2376
+ },
2377
+ },
2378
+ {
2379
+ name: 'grd_autopilot_init',
2380
+ description: 'Get autopilot pre-flight context: phase range, config, claude availability',
2381
+ params: [],
2382
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdInitAutopilot(cwd, false),
2383
+ },
2384
+
2385
+ // ── Multi-Milestone Autopilot ──
2386
+ {
2387
+ name: 'grd_multi_milestone_autopilot_run',
2388
+ description:
2389
+ 'Plan and execute phases across multiple milestones autonomously, completing one milestone and starting the next',
2390
+ params: [
2391
+ {
2392
+ name: 'max_milestones',
2393
+ type: 'number',
2394
+ required: false,
2395
+ description: 'Maximum milestones to process (default: 10)',
2396
+ },
2397
+ {
2398
+ name: 'dry_run',
2399
+ type: 'boolean',
2400
+ required: false,
2401
+ description: 'Preview without executing',
2402
+ },
2403
+ {
2404
+ name: 'timeout',
2405
+ type: 'number',
2406
+ required: false,
2407
+ description: 'Per-subprocess timeout in minutes',
2408
+ },
2409
+ {
2410
+ name: 'max_turns',
2411
+ type: 'number',
2412
+ required: false,
2413
+ description: 'Max turns per subprocess',
2414
+ },
2415
+ {
2416
+ name: 'model',
2417
+ type: 'string',
2418
+ required: false,
2419
+ description: 'Model override',
2420
+ },
2421
+ {
2422
+ name: 'skip_plan',
2423
+ type: 'boolean',
2424
+ required: false,
2425
+ description: 'Skip planning step',
2426
+ },
2427
+ {
2428
+ name: 'skip_execute',
2429
+ type: 'boolean',
2430
+ required: false,
2431
+ description: 'Skip execution step',
2432
+ },
2433
+ ],
2434
+ execute: (cwd: string, args: Record<string, unknown>) => {
2435
+ const cliArgs: string[] = [];
2436
+ if (args.max_milestones) cliArgs.push('--max-milestones', String(args.max_milestones));
2437
+ if (args.dry_run) cliArgs.push('--dry-run');
2438
+ if (args.timeout) cliArgs.push('--timeout', String(args.timeout));
2439
+ if (args.max_turns) cliArgs.push('--max-turns', String(args.max_turns));
2440
+ if (args.model) cliArgs.push('--model', args.model as string);
2441
+ if (args.skip_plan) cliArgs.push('--skip-plan');
2442
+ if (args.skip_execute) cliArgs.push('--skip-execute');
2443
+ return cmdMultiMilestoneAutopilot(cwd, cliArgs, false);
2444
+ },
2445
+ },
2446
+ {
2447
+ name: 'grd_multi_milestone_autopilot_init',
2448
+ description:
2449
+ 'Pre-flight context for multi-milestone autopilot: LT roadmap state, milestone completion, next milestone',
2450
+ params: [],
2451
+ execute: (cwd: string, _args: Record<string, unknown>) =>
2452
+ cmdInitMultiMilestoneAutopilot(cwd, false),
2453
+ },
2454
+ // ── Autoplan ──
2455
+ {
2456
+ name: 'grd_autoplan_run',
2457
+ description:
2458
+ 'Automatically generate a milestone from evolve discovery results or fresh discovery',
2459
+ params: [
2460
+ {
2461
+ name: 'dry_run',
2462
+ type: 'boolean' as const,
2463
+ required: false,
2464
+ description: 'Preview the autoplan prompt without executing',
2465
+ },
2466
+ {
2467
+ name: 'timeout',
2468
+ type: 'number' as const,
2469
+ required: false,
2470
+ description: 'Subprocess timeout in minutes',
2471
+ },
2472
+ {
2473
+ name: 'max_turns',
2474
+ type: 'number' as const,
2475
+ required: false,
2476
+ description: 'Max turns for subprocess',
2477
+ },
2478
+ {
2479
+ name: 'model',
2480
+ type: 'string' as const,
2481
+ required: false,
2482
+ description: 'Model override',
2483
+ },
2484
+ {
2485
+ name: 'pick_pct',
2486
+ type: 'number' as const,
2487
+ required: false,
2488
+ description: 'Discovery pick percentage (default: 50)',
2489
+ },
2490
+ {
2491
+ name: 'name',
2492
+ type: 'string' as const,
2493
+ required: false,
2494
+ description: 'Override milestone name',
2495
+ },
2496
+ ],
2497
+ execute: (cwd: string, args: Record<string, unknown>) => {
2498
+ const cliArgs: string[] = [];
2499
+ if (args.dry_run) cliArgs.push('--dry-run');
2500
+ if (args.timeout) cliArgs.push('--timeout', String(args.timeout));
2501
+ if (args.max_turns) cliArgs.push('--max-turns', String(args.max_turns));
2502
+ if (args.model) cliArgs.push('--model', args.model as string);
2503
+ if (args.pick_pct) cliArgs.push('--pick-pct', String(args.pick_pct));
2504
+ if (args.name) cliArgs.push('--name', args.name as string);
2505
+ return cmdAutoplan(cwd, cliArgs, false);
2506
+ },
2507
+ },
2508
+ {
2509
+ name: 'grd_autoplan_init',
2510
+ description: 'Pre-flight context for autoplan: evolve state, current milestone, config',
2511
+ params: [],
2512
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdInitAutoplan(cwd, false),
2513
+ },
2514
+ // ── Evolve Orchestrator ──
2515
+ {
2516
+ name: 'grd_evolve_run',
2517
+ description: 'Run autonomous self-improvement loop with sonnet-tier models',
2518
+ params: [
2519
+ {
2520
+ name: 'iterations',
2521
+ type: 'number',
2522
+ description: 'Number of iterations to run (default: 1)',
2523
+ required: false,
2524
+ },
2525
+ {
2526
+ name: 'items',
2527
+ type: 'number',
2528
+ description: 'Work items per iteration (default: 5)',
2529
+ required: false,
2530
+ },
2531
+ {
2532
+ name: 'timeout',
2533
+ type: 'number',
2534
+ description: 'Timeout per subprocess in minutes',
2535
+ required: false,
2536
+ },
2537
+ {
2538
+ name: 'max_turns',
2539
+ type: 'number',
2540
+ description: 'Max turns per claude -p invocation',
2541
+ required: false,
2542
+ },
2543
+ {
2544
+ name: 'dry_run',
2545
+ type: 'boolean',
2546
+ description: 'Show plan without executing',
2547
+ required: false,
2548
+ },
2549
+ ],
2550
+ execute: async (cwd: string, args: Record<string, unknown>) => {
2551
+ const cliArgs: string[] = [];
2552
+ if (args.iterations) cliArgs.push('--iterations', String(args.iterations));
2553
+ if (args.items) cliArgs.push('--items', String(args.items));
2554
+ if (args.timeout) cliArgs.push('--timeout', String(args.timeout));
2555
+ if (args.max_turns) cliArgs.push('--max-turns', String(args.max_turns));
2556
+ if (args.dry_run) cliArgs.push('--dry-run');
2557
+ return cmdEvolve(cwd, cliArgs, false);
2558
+ },
2559
+ },
2560
+ // ── Evolve Engine ──
2561
+ {
2562
+ name: 'grd_evolve_discover',
2563
+ description:
2564
+ 'Discover work items for self-improvement across 8 dimensions (product-ideation, improve-features, new-features, productivity, quality, usability, consistency, stability) and select top priority items. Product ideation discovers creative feature ideas by analyzing PROJECT.md and the product roadmap.',
2565
+ params: [
2566
+ {
2567
+ name: 'count',
2568
+ type: 'number',
2569
+ required: false,
2570
+ description: 'Number of items to select (default: 5)',
2571
+ },
2572
+ ],
2573
+ execute: async (cwd: string, args: Record<string, unknown>) => {
2574
+ const cliArgs: string[] = [];
2575
+ if (args.count) cliArgs.push('--count', String(args.count));
2576
+ return await cmdEvolveDiscover(cwd, cliArgs, false);
2577
+ },
2578
+ },
2579
+ {
2580
+ name: 'grd_evolve_state',
2581
+ description:
2582
+ 'Read the current evolve iteration state file (selected items, remaining items, iteration history)',
2583
+ params: [],
2584
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdEvolveState(cwd, [], false),
2585
+ },
2586
+ {
2587
+ name: 'grd_evolve_advance',
2588
+ description:
2589
+ 'Advance to the next evolve iteration: carry over remaining items, merge bugfixes, increment counter',
2590
+ params: [],
2591
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdEvolveAdvance(cwd, [], false),
2592
+ },
2593
+ {
2594
+ name: 'grd_evolve_reset',
2595
+ description: 'Delete the evolve state file to start a fresh iteration',
2596
+ params: [],
2597
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdEvolveReset(cwd, [], false),
2598
+ },
2599
+ {
2600
+ name: 'grd_evolve_init',
2601
+ description:
2602
+ 'Get evolve pre-flight context: backend, models, existing evolve state, milestone info',
2603
+ params: [],
2604
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdInitEvolve(cwd, false),
2605
+ },
2606
+
2607
+ // -- Wireup Tools --
2608
+ {
2609
+ name: 'grd_wireup_discover',
2610
+ description: 'Discover unwired features in the project via filesystem analysis',
2611
+ params: [],
2612
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdWireupDiscover(cwd, [], false),
2613
+ },
2614
+ {
2615
+ name: 'grd_wireup_run',
2616
+ description:
2617
+ 'Run a full wireup iteration: discover, generate scenarios, execute, detect issues, report',
2618
+ params: [
2619
+ {
2620
+ name: 'target',
2621
+ type: 'string',
2622
+ required: false,
2623
+ description: 'Focus on a specific feature (function name or file path substring)',
2624
+ },
2625
+ {
2626
+ name: 'dry_run',
2627
+ type: 'boolean',
2628
+ required: false,
2629
+ description: 'Discover and generate scenarios without executing them',
2630
+ },
2631
+ ],
2632
+ execute: async (cwd: string, args: Record<string, unknown>) => {
2633
+ const cliArgs: string[] = [];
2634
+ if (args.target) cliArgs.push('--target', String(args.target));
2635
+ if (args.dry_run) cliArgs.push('--dry-run');
2636
+ return cmdWireupRun(cwd, cliArgs, false);
2637
+ },
2638
+ },
2639
+ {
2640
+ name: 'grd_wireup_state',
2641
+ description:
2642
+ 'Read the current wireup iteration state (features discovered, scenarios, fixes applied)',
2643
+ params: [],
2644
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdWireupState(cwd, [], false),
2645
+ },
2646
+ {
2647
+ name: 'grd_wireup_scenarios',
2648
+ description: 'List generated wireup scenarios for discovered features',
2649
+ params: [],
2650
+ execute: (cwd: string, _args: Record<string, unknown>) =>
2651
+ cmdWireupScenarios(cwd, [], false),
2652
+ },
2653
+ {
2654
+ name: 'grd_wireup_report',
2655
+ description:
2656
+ 'Get the latest wireup report with pass/fail results and issue summary',
2657
+ params: [],
2658
+ execute: (cwd: string, _args: Record<string, unknown>) => cmdWireupReport(cwd, [], false),
2659
+ },
2660
+
2661
+ // -- Discussion Tools --
2662
+ {
2663
+ name: 'grd_discussion_run',
2664
+ description:
2665
+ 'Run an ad-hoc multi-backend discussion on a topic. Dispatches to configured participants and synthesizes a final answer.',
2666
+ params: [
2667
+ {
2668
+ name: 'topic',
2669
+ type: 'string',
2670
+ required: true,
2671
+ description: 'The topic or question to discuss',
2672
+ },
2673
+ {
2674
+ name: 'participants',
2675
+ type: 'string',
2676
+ required: false,
2677
+ description: 'Comma-separated backend IDs to participate (e.g. "claude,gemini")',
2678
+ },
2679
+ {
2680
+ name: 'rounds',
2681
+ type: 'number',
2682
+ required: false,
2683
+ description: 'Number of discussion rounds (default: 2)',
2684
+ },
2685
+ {
2686
+ name: 'synthesizer',
2687
+ type: 'string',
2688
+ required: false,
2689
+ description: 'Backend to synthesize final answer (default: claude)',
2690
+ },
2691
+ ],
2692
+ execute: async (cwd: string, args: Record<string, unknown>) => {
2693
+ const topic = args.topic as string;
2694
+ const participantStr = args.participants as string | undefined;
2695
+ const participants: BackendId[] = participantStr
2696
+ ? (participantStr.split(',').map((s) => s.trim()).filter(Boolean) as BackendId[])
2697
+ : [];
2698
+ const result = await runDiscussion(topic, participants, {
2699
+ rounds: args.rounds as number | undefined,
2700
+ synthesizer: args.synthesizer as BackendId | undefined,
2701
+ cwd,
2702
+ });
2703
+ return JSON.stringify(result);
2704
+ },
2705
+ },
2706
+ {
2707
+ name: 'grd_discussion_config',
2708
+ description:
2709
+ 'Read discussion configuration from config.json — returns discussion settings and backend_roles',
2710
+ params: [],
2711
+ execute: (cwd: string, _args: Record<string, unknown>) => {
2712
+ const config = readConfig(cwd) ?? {};
2713
+ return JSON.stringify({
2714
+ discussion: (config.discussion as Record<string, unknown>) ?? {},
2715
+ backend_roles: (config.backend_roles as Record<string, unknown>) ?? {},
2716
+ });
2717
+ },
2718
+ },
2719
+ {
2720
+ name: 'grd_backends_available',
2721
+ description:
2722
+ 'List all available backends and their configured roles. Returns a map of backend availability and role assignments.',
2723
+ params: [],
2724
+ execute: (cwd: string, _args: Record<string, unknown>) => {
2725
+ const backends = detectAvailableBackends(cwd);
2726
+ const config = readConfig(cwd) ?? {};
2727
+ return JSON.stringify({
2728
+ backends,
2729
+ roles: (config.backend_roles as Record<string, unknown>) ?? {},
2730
+ });
2731
+ },
2732
+ },
2733
+ {
2734
+ name: 'grd_discussion_history',
2735
+ description:
2736
+ 'List or read discussion history. Without filename lists all discussions; with filename reads a specific discussion file.',
2737
+ params: [
2738
+ {
2739
+ name: 'filename',
2740
+ type: 'string',
2741
+ required: false,
2742
+ description: 'Specific discussion file to read (omit to list all)',
2743
+ },
2744
+ ],
2745
+ execute: (cwd: string, args: Record<string, unknown>) => {
2746
+ const filename = args.filename as string | undefined;
2747
+ if (filename) {
2748
+ const content = readDiscussion(filename, cwd);
2749
+ return JSON.stringify({ filename, content });
2750
+ }
2751
+ const files = listDiscussions(cwd);
2752
+ return JSON.stringify(files);
2753
+ },
2754
+ },
2755
+
2756
+ // ── Markdown Splitting ──
2757
+ {
2758
+ name: 'grd_markdown_split',
2759
+ description:
2760
+ 'Split a large markdown file into numbered partials with an index file. Returns split result with partial paths.',
2761
+ params: [
2762
+ {
2763
+ name: 'file',
2764
+ type: 'string',
2765
+ required: true,
2766
+ description: 'Path to markdown file to split (relative to project root)',
2767
+ },
2768
+ {
2769
+ name: 'threshold',
2770
+ type: 'number',
2771
+ required: false,
2772
+ description: 'Token threshold for splitting (default: 25000)',
2773
+ },
2774
+ ],
2775
+ execute: (cwd: string, args: Record<string, unknown>) => {
2776
+ const fs = require('fs');
2777
+ const path = require('path');
2778
+ const filePath: string = path.resolve(cwd, args.file as string);
2779
+ if (!fs.existsSync(filePath)) throw new Error(`File not found: ${filePath}`);
2780
+ const content: string = fs.readFileSync(filePath, 'utf-8');
2781
+ const basename: string = path.basename(filePath, '.md');
2782
+ const dir: string = path.dirname(filePath);
2783
+ const result = splitMarkdown(content, {
2784
+ threshold: args.threshold as number | undefined,
2785
+ basename,
2786
+ });
2787
+ if (!result.split_performed) {
2788
+ process.stdout.write(JSON.stringify({ split_performed: false, reason: result.reason }));
2789
+ return;
2790
+ }
2791
+ fs.writeFileSync(filePath, result.index_content, 'utf-8');
2792
+ const partials: string[] = [];
2793
+ for (const part of result.parts!) {
2794
+ const partPath: string = path.join(dir, part.filename);
2795
+ fs.writeFileSync(partPath, part.content, 'utf-8');
2796
+ partials.push(partPath);
2797
+ }
2798
+ process.stdout.write(
2799
+ JSON.stringify({
2800
+ split_performed: true,
2801
+ index_file: filePath,
2802
+ partials,
2803
+ part_count: result.parts!.length,
2804
+ })
2805
+ );
2806
+ },
2807
+ },
2808
+ {
2809
+ name: 'grd_markdown_check',
2810
+ description: 'Check if a markdown file is a GRD split index and estimate its token count.',
2811
+ params: [
2812
+ {
2813
+ name: 'file',
2814
+ type: 'string',
2815
+ required: true,
2816
+ description: 'Path to markdown file to check (relative to project root)',
2817
+ },
2818
+ ],
2819
+ execute: (cwd: string, args: Record<string, unknown>) => {
2820
+ const fs = require('fs');
2821
+ const path = require('path');
2822
+ const filePath: string = path.resolve(cwd, args.file as string);
2823
+ if (!fs.existsSync(filePath)) throw new Error(`File not found: ${filePath}`);
2824
+ const content: string = fs.readFileSync(filePath, 'utf-8');
2825
+ const tokens: number = estimateTokens(content);
2826
+ process.stdout.write(
2827
+ JSON.stringify({
2828
+ file: filePath,
2829
+ is_index: isIndexFile(content),
2830
+ estimated_tokens: tokens,
2831
+ exceeds_threshold: tokens > 25000,
2832
+ })
2833
+ );
2834
+ },
2835
+ },
2836
+
2837
+ // ── Coverage & Health ──
2838
+ {
2839
+ name: 'grd_coverage_report',
2840
+ description: 'Generate structured coverage report identifying lib/ modules below a threshold',
2841
+ params: [
2842
+ {
2843
+ name: 'threshold',
2844
+ type: 'number',
2845
+ required: false,
2846
+ description: 'Minimum line coverage percentage (default: 85)',
2847
+ },
2848
+ ],
2849
+ execute: (cwd: string, args: Record<string, unknown>) =>
2850
+ cmdCoverageReport(cwd, { threshold: (args.threshold as number) || 85 }, false),
2851
+ },
2852
+ {
2853
+ name: 'grd_health_check',
2854
+ description:
2855
+ 'Run comprehensive project health checks: tests, lint, format, consistency validation',
2856
+ params: [
2857
+ {
2858
+ name: 'fix',
2859
+ type: 'boolean',
2860
+ required: false,
2861
+ description: 'Whether to auto-fix lint and format issues (default: false)',
2862
+ },
2863
+ ],
2864
+ execute: (cwd: string, args: Record<string, unknown>) =>
2865
+ cmdHealthCheck(cwd, { fix: (args.fix as boolean) || false }, false),
2866
+ },
2867
+ ];
2868
+
2869
+ // ─── Tool Definition Builder ────────────────────────────────────────────────
2870
+
2871
+ /**
2872
+ * Transform COMMAND_DESCRIPTORS into MCP-format tool definitions with JSON Schema inputSchema.
2873
+ */
2874
+ function buildToolDefinitions(): McpToolDefinition[] {
2875
+ return COMMAND_DESCRIPTORS.map((desc) => {
2876
+ const properties: Record<
2877
+ string,
2878
+ { type: string; description: string; items?: { type: string } }
2879
+ > = {};
2880
+ const required: string[] = [];
2881
+
2882
+ for (const param of desc.params) {
2883
+ const prop: { type: string; description: string; items?: { type: string } } = {
2884
+ description: param.description,
2885
+ type: 'string',
2886
+ };
2887
+
2888
+ switch (param.type) {
2889
+ case 'string':
2890
+ prop.type = 'string';
2891
+ break;
2892
+ case 'number':
2893
+ prop.type = 'number';
2894
+ break;
2895
+ case 'boolean':
2896
+ prop.type = 'boolean';
2897
+ break;
2898
+ case 'array':
2899
+ prop.type = 'array';
2900
+ prop.items = { type: 'string' };
2901
+ break;
2902
+ case 'object':
2903
+ prop.type = 'object';
2904
+ break;
2905
+ default:
2906
+ prop.type = 'string';
2907
+ }
2908
+
2909
+ properties[param.name] = prop;
2910
+
2911
+ if (param.required) {
2912
+ required.push(param.name);
2913
+ }
2914
+ }
2915
+
2916
+ const inputSchema: McpToolDefinition['inputSchema'] = {
2917
+ type: 'object',
2918
+ properties,
2919
+ };
2920
+
2921
+ if (required.length > 0) {
2922
+ inputSchema.required = required;
2923
+ }
2924
+
2925
+ return {
2926
+ name: desc.name,
2927
+ description: desc.description,
2928
+ inputSchema,
2929
+ };
2930
+ });
2931
+ }
2932
+
2933
+ // ─── Output Capture ─────────────────────────────────────────────────────────
2934
+
2935
+ const EXIT_SENTINEL = '__MCP_EXEC_EXIT__';
2936
+
2937
+ /**
2938
+ * Execute a cmd* function while capturing stdout, stderr, and process.exit calls.
2939
+ *
2940
+ * The existing cmd* functions call output() which writes to stdout and calls process.exit(0),
2941
+ * or error() which writes to stderr and calls process.exit(1). We intercept these to capture
2942
+ * the output without actually exiting the process.
2943
+ * @param fn - The synchronous function to execute with captured output
2944
+ * @returns Captured stdout, stderr, and exit code from the executed function
2945
+ */
2946
+ function captureExecution(fn: () => void): CaptureResult {
2947
+ let stdout = '';
2948
+ let stderr = '';
2949
+ let exitCode = 0;
2950
+
2951
+ const origStdoutWrite = process.stdout.write;
2952
+ const origStderrWrite = process.stderr.write;
2953
+ const origExit = process.exit;
2954
+
2955
+ process.stdout.write = function (data: unknown): boolean {
2956
+ stdout += String(data);
2957
+ return true;
2958
+ } as typeof process.stdout.write;
2959
+
2960
+ process.stderr.write = function (data: unknown): boolean {
2961
+ stderr += String(data);
2962
+ return true;
2963
+ } as typeof process.stderr.write;
2964
+
2965
+ process.exit = function (code?: number): never {
2966
+ exitCode = code as number;
2967
+ const err = new Error(EXIT_SENTINEL) as unknown as McpExitError;
2968
+ (err as McpExitError).__MCP_EXIT__ = true;
2969
+ (err as McpExitError).exitCode = code as number;
2970
+ throw err;
2971
+ } as typeof process.exit;
2972
+
2973
+ try {
2974
+ fn();
2975
+ } catch (e) {
2976
+ if (e && (e as McpExitError).__MCP_EXIT__) {
2977
+ // Expected -- process.exit was intercepted
2978
+ } else {
2979
+ // Real error from the command
2980
+ process.stdout.write = origStdoutWrite;
2981
+ process.stderr.write = origStderrWrite;
2982
+ process.exit = origExit;
2983
+ throw e;
2984
+ }
2985
+ } finally {
2986
+ process.stdout.write = origStdoutWrite;
2987
+ process.stderr.write = origStderrWrite;
2988
+ process.exit = origExit;
2989
+ }
2990
+
2991
+ return { stdout, stderr, exitCode };
2992
+ }
2993
+
2994
+ /**
2995
+ * Async variant of captureExecution for async tool handlers.
2996
+ * Intercepts stdout/stderr/process.exit while awaiting the async function.
2997
+ */
2998
+ async function captureExecutionAsync(fn: () => void | Promise<void>): Promise<CaptureResult> {
2999
+ let stdout = '';
3000
+ let stderr = '';
3001
+ let exitCode = 0;
3002
+
3003
+ const origStdoutWrite = process.stdout.write;
3004
+ const origStderrWrite = process.stderr.write;
3005
+ const origExit = process.exit;
3006
+
3007
+ process.stdout.write = function (data: unknown): boolean {
3008
+ stdout += String(data);
3009
+ return true;
3010
+ } as typeof process.stdout.write;
3011
+
3012
+ process.stderr.write = function (data: unknown): boolean {
3013
+ stderr += String(data);
3014
+ return true;
3015
+ } as typeof process.stderr.write;
3016
+
3017
+ process.exit = function (code?: number): never {
3018
+ exitCode = code as number;
3019
+ const err = new Error(EXIT_SENTINEL) as unknown as McpExitError;
3020
+ (err as McpExitError).__MCP_EXIT__ = true;
3021
+ (err as McpExitError).exitCode = code as number;
3022
+ throw err;
3023
+ } as typeof process.exit;
3024
+
3025
+ try {
3026
+ await fn();
3027
+ } catch (e) {
3028
+ if (e && (e as McpExitError).__MCP_EXIT__) {
3029
+ // Expected -- process.exit was intercepted
3030
+ } else {
3031
+ process.stdout.write = origStdoutWrite;
3032
+ process.stderr.write = origStderrWrite;
3033
+ process.exit = origExit;
3034
+ throw e;
3035
+ }
3036
+ } finally {
3037
+ process.stdout.write = origStdoutWrite;
3038
+ process.stderr.write = origStderrWrite;
3039
+ process.exit = origExit;
3040
+ }
3041
+
3042
+ return { stdout, stderr, exitCode };
3043
+ }
3044
+
3045
+ // ─── MCP Server Class ──────────────────────────────────────────────────────
3046
+
3047
+ /**
3048
+ * MCP Server implementing JSON-RPC 2.0 protocol.
3049
+ *
3050
+ * Handles: initialize, notifications/initialized, tools/list, tools/call.
3051
+ * Dispatches tool calls to GRD lib/ functions via the COMMAND_DESCRIPTORS registry.
3052
+ */
3053
+ class McpServer {
3054
+ cwd: string;
3055
+ toolDefinitions: McpToolDefinition[];
3056
+ _initialized: boolean;
3057
+ _descriptorMap: Map<string, CommandDescriptor>;
3058
+
3059
+ constructor(options: { cwd?: string } = {}) {
3060
+ this.cwd = options.cwd || process.cwd();
3061
+ this.toolDefinitions = buildToolDefinitions();
3062
+ this._initialized = false;
3063
+
3064
+ // Build lookup map: toolName -> descriptor
3065
+ this._descriptorMap = new Map();
3066
+ for (const desc of COMMAND_DESCRIPTORS) {
3067
+ this._descriptorMap.set(desc.name, desc);
3068
+ }
3069
+ }
3070
+
3071
+ /**
3072
+ * Handle an incoming JSON-RPC 2.0 message and return a response (or null for notifications).
3073
+ */
3074
+ handleMessage(message: JsonRpcMessage): JsonRpcResponse | Promise<JsonRpcResponse> | null {
3075
+ // Validate basic JSON-RPC structure
3076
+ if (!message || typeof message !== 'object') {
3077
+ return this._errorResponse(null, -32600, 'Invalid Request');
3078
+ }
3079
+
3080
+ const { method, id, params } = message;
3081
+
3082
+ if (!method || typeof method !== 'string') {
3083
+ return this._errorResponse(id || null, -32600, 'Invalid Request');
3084
+ }
3085
+
3086
+ // Notifications (no id) -- no response expected
3087
+ if (id === undefined || id === null) {
3088
+ // Handle known notifications silently
3089
+ if (method === 'notifications/initialized') {
3090
+ this._initialized = true;
3091
+ }
3092
+ return null;
3093
+ }
3094
+
3095
+ // Request methods
3096
+ switch (method) {
3097
+ case 'initialize':
3098
+ return this._handleInitialize(id, params);
3099
+ case 'tools/list':
3100
+ return this._handleToolsList(id);
3101
+ case 'tools/call':
3102
+ return this._handleToolsCall(id, params);
3103
+ default:
3104
+ return this._errorResponse(id, -32601, 'Method not found');
3105
+ }
3106
+ }
3107
+
3108
+ /**
3109
+ * Handle initialize request -- return server capabilities and info.
3110
+ */
3111
+ _handleInitialize(id: number | string, _params?: Record<string, unknown>): JsonRpcResponse {
3112
+ return {
3113
+ jsonrpc: '2.0',
3114
+ id,
3115
+ result: {
3116
+ protocolVersion: '2024-11-05',
3117
+ capabilities: {
3118
+ tools: {},
3119
+ },
3120
+ serverInfo: {
3121
+ name: 'grd-mcp-server',
3122
+ version: '0.1.0',
3123
+ },
3124
+ },
3125
+ };
3126
+ }
3127
+
3128
+ /**
3129
+ * Handle tools/list request -- return all tool definitions.
3130
+ */
3131
+ _handleToolsList(id: number | string): JsonRpcResponse {
3132
+ return {
3133
+ jsonrpc: '2.0',
3134
+ id,
3135
+ result: {
3136
+ tools: this.toolDefinitions,
3137
+ },
3138
+ };
3139
+ }
3140
+
3141
+ /**
3142
+ * Handle tools/call request -- validate params, execute tool, return result.
3143
+ */
3144
+ _handleToolsCall(
3145
+ id: number | string,
3146
+ params?: Record<string, unknown>
3147
+ ): JsonRpcResponse | Promise<JsonRpcResponse> {
3148
+ if (!params || !params.name) {
3149
+ return this._errorResponse(id, -32602, 'Invalid params', { missing: ['name'] });
3150
+ }
3151
+
3152
+ const toolName = params.name as string;
3153
+ const toolArgs = (params.arguments as Record<string, unknown>) || {};
3154
+
3155
+ const descriptor = this._descriptorMap.get(toolName);
3156
+ if (!descriptor) {
3157
+ return this._errorResponse(id, -32601, 'Method not found', { tool: toolName });
3158
+ }
3159
+
3160
+ // Validate required params
3161
+ const missingParams: string[] = [];
3162
+ for (const param of descriptor.params) {
3163
+ if (param.required && (toolArgs[param.name] === undefined || toolArgs[param.name] === null)) {
3164
+ missingParams.push(param.name);
3165
+ }
3166
+ }
3167
+
3168
+ if (missingParams.length > 0) {
3169
+ return this._errorResponse(id, -32602, 'Invalid params', { missing: missingParams });
3170
+ }
3171
+
3172
+ // Execute the tool
3173
+ return this._executeTool(id, descriptor, toolArgs);
3174
+ }
3175
+
3176
+ /**
3177
+ * Execute a tool by calling its cmd* function with output capture.
3178
+ */
3179
+ _executeTool(
3180
+ id: number | string,
3181
+ descriptor: CommandDescriptor,
3182
+ args: Record<string, unknown>
3183
+ ): JsonRpcResponse | Promise<JsonRpcResponse> {
3184
+ // Async handlers (declared with async keyword) use async capture
3185
+ if (descriptor.execute.constructor.name === 'AsyncFunction') {
3186
+ return this._executeToolAsync(id, descriptor, args);
3187
+ }
3188
+
3189
+ try {
3190
+ const result = captureExecution(() => {
3191
+ descriptor.execute(this.cwd, args);
3192
+ });
3193
+
3194
+ return this._formatToolResult(id, result);
3195
+ } catch (e) {
3196
+ return this._errorResponse(id, -32603, 'Internal error', {
3197
+ error: (e as Error).message || String(e),
3198
+ });
3199
+ }
3200
+ }
3201
+
3202
+ /**
3203
+ * Async variant of _executeTool for async tool handlers.
3204
+ */
3205
+ async _executeToolAsync(
3206
+ id: number | string,
3207
+ descriptor: CommandDescriptor,
3208
+ args: Record<string, unknown>
3209
+ ): Promise<JsonRpcResponse> {
3210
+ try {
3211
+ const result = await captureExecutionAsync(() => {
3212
+ return descriptor.execute(this.cwd, args) as void | Promise<void>;
3213
+ });
3214
+ return this._formatToolResult(id, result);
3215
+ } catch (e) {
3216
+ return this._errorResponse(id, -32603, 'Internal error', {
3217
+ error: (e as Error).message || String(e),
3218
+ });
3219
+ }
3220
+ }
3221
+
3222
+ /**
3223
+ * Format captured execution result into a JSON-RPC response.
3224
+ */
3225
+ _formatToolResult(id: number | string, result: CaptureResult): JsonRpcResponse {
3226
+ if (result.exitCode !== 0) {
3227
+ return {
3228
+ jsonrpc: '2.0',
3229
+ id,
3230
+ result: {
3231
+ content: [
3232
+ {
3233
+ type: 'text',
3234
+ text: result.stderr || result.stdout || 'Command failed',
3235
+ },
3236
+ ],
3237
+ isError: true,
3238
+ },
3239
+ };
3240
+ }
3241
+
3242
+ let text: string = result.stdout;
3243
+ try {
3244
+ const parsed: unknown = JSON.parse(text);
3245
+ text = JSON.stringify(parsed, null, 2);
3246
+ } catch {
3247
+ // Not JSON -- use raw text
3248
+ }
3249
+
3250
+ return {
3251
+ jsonrpc: '2.0',
3252
+ id,
3253
+ result: {
3254
+ content: [
3255
+ {
3256
+ type: 'text',
3257
+ text,
3258
+ },
3259
+ ],
3260
+ },
3261
+ };
3262
+ }
3263
+
3264
+ /**
3265
+ * Build a JSON-RPC error response.
3266
+ */
3267
+ _errorResponse(
3268
+ id: number | string | null,
3269
+ code: number,
3270
+ message: string,
3271
+ data?: unknown
3272
+ ): JsonRpcResponse {
3273
+ const error: { code: number; message: string; data?: unknown } = { code, message };
3274
+ if (data) {
3275
+ error.data = data;
3276
+ }
3277
+ return {
3278
+ jsonrpc: '2.0',
3279
+ id,
3280
+ error,
3281
+ };
3282
+ }
3283
+ }
3284
+
3285
+ // ─── Exports ────────────────────────────────────────────────────────────────
3286
+
3287
+ module.exports = {
3288
+ McpServer,
3289
+ buildToolDefinitions,
3290
+ COMMAND_DESCRIPTORS,
3291
+ captureExecution,
3292
+ };