@ai-coders/context 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (581) hide show
  1. package/README.md +125 -68
  2. package/dist/commands/export.d.ts +4 -0
  3. package/dist/commands/export.d.ts.map +1 -0
  4. package/dist/commands/export.js +39 -0
  5. package/dist/commands/export.js.map +1 -0
  6. package/dist/commands/fill.d.ts +13 -0
  7. package/dist/commands/fill.d.ts.map +1 -0
  8. package/dist/commands/fill.js +65 -0
  9. package/dist/commands/fill.js.map +1 -0
  10. package/dist/commands/index.d.ts +29 -0
  11. package/dist/commands/index.d.ts.map +1 -0
  12. package/dist/commands/index.js +74 -0
  13. package/dist/commands/index.js.map +1 -0
  14. package/dist/commands/init.d.ts +12 -0
  15. package/dist/commands/init.d.ts.map +1 -0
  16. package/dist/commands/init.js +64 -0
  17. package/dist/commands/init.js.map +1 -0
  18. package/dist/commands/mcp.d.ts +4 -0
  19. package/dist/commands/mcp.d.ts.map +1 -0
  20. package/dist/commands/mcp.js +92 -0
  21. package/dist/commands/mcp.js.map +1 -0
  22. package/dist/commands/plan.d.ts +9 -0
  23. package/dist/commands/plan.d.ts.map +1 -0
  24. package/dist/commands/plan.js +126 -0
  25. package/dist/commands/plan.js.map +1 -0
  26. package/dist/commands/report.d.ts +4 -0
  27. package/dist/commands/report.d.ts.map +1 -0
  28. package/dist/commands/report.js +36 -0
  29. package/dist/commands/report.js.map +1 -0
  30. package/dist/commands/serve.d.ts +4 -0
  31. package/dist/commands/serve.d.ts.map +1 -0
  32. package/dist/commands/serve.js +29 -0
  33. package/dist/commands/serve.js.map +1 -0
  34. package/dist/commands/skill.d.ts +4 -0
  35. package/dist/commands/skill.d.ts.map +1 -0
  36. package/dist/commands/skill.js +217 -0
  37. package/dist/commands/skill.js.map +1 -0
  38. package/dist/commands/start.d.ts +4 -0
  39. package/dist/commands/start.d.ts.map +1 -0
  40. package/dist/commands/start.js +56 -0
  41. package/dist/commands/start.js.map +1 -0
  42. package/dist/commands/sync.d.ts +9 -0
  43. package/dist/commands/sync.d.ts.map +1 -0
  44. package/dist/commands/sync.js +134 -0
  45. package/dist/commands/sync.js.map +1 -0
  46. package/dist/commands/types.d.ts +17 -0
  47. package/dist/commands/types.d.ts.map +1 -0
  48. package/dist/commands/types.js +3 -0
  49. package/dist/commands/types.js.map +1 -0
  50. package/dist/commands/update.d.ts +4 -0
  51. package/dist/commands/update.d.ts.map +1 -0
  52. package/dist/commands/update.js +111 -0
  53. package/dist/commands/update.js.map +1 -0
  54. package/dist/commands/workflow.d.ts +4 -0
  55. package/dist/commands/workflow.d.ts.map +1 -0
  56. package/dist/commands/workflow.js +171 -0
  57. package/dist/commands/workflow.js.map +1 -0
  58. package/dist/generators/agents/agentGenerator.d.ts +2 -0
  59. package/dist/generators/agents/agentGenerator.d.ts.map +1 -1
  60. package/dist/generators/agents/agentGenerator.js +46 -2
  61. package/dist/generators/agents/agentGenerator.js.map +1 -1
  62. package/dist/generators/agents/templates/index.d.ts +0 -1
  63. package/dist/generators/agents/templates/index.d.ts.map +1 -1
  64. package/dist/generators/agents/templates/index.js +1 -3
  65. package/dist/generators/agents/templates/index.js.map +1 -1
  66. package/dist/generators/agents/templates/playbookTemplate.d.ts.map +1 -1
  67. package/dist/generators/agents/templates/playbookTemplate.js +11 -0
  68. package/dist/generators/agents/templates/playbookTemplate.js.map +1 -1
  69. package/dist/generators/documentation/documentationGenerator.d.ts +2 -1
  70. package/dist/generators/documentation/documentationGenerator.d.ts.map +1 -1
  71. package/dist/generators/documentation/documentationGenerator.js +53 -34
  72. package/dist/generators/documentation/documentationGenerator.js.map +1 -1
  73. package/dist/generators/documentation/templates/apiReferenceTemplate.d.ts.map +1 -1
  74. package/dist/generators/documentation/templates/apiReferenceTemplate.js +11 -0
  75. package/dist/generators/documentation/templates/apiReferenceTemplate.js.map +1 -1
  76. package/dist/generators/documentation/templates/architectureTemplate.d.ts +11 -0
  77. package/dist/generators/documentation/templates/architectureTemplate.d.ts.map +1 -1
  78. package/dist/generators/documentation/templates/architectureTemplate.js.map +1 -1
  79. package/dist/generators/documentation/templates/dataFlowTemplate.d.ts.map +1 -1
  80. package/dist/generators/documentation/templates/dataFlowTemplate.js +11 -0
  81. package/dist/generators/documentation/templates/dataFlowTemplate.js.map +1 -1
  82. package/dist/generators/documentation/templates/developmentWorkflowTemplate.d.ts.map +1 -1
  83. package/dist/generators/documentation/templates/developmentWorkflowTemplate.js +11 -0
  84. package/dist/generators/documentation/templates/developmentWorkflowTemplate.js.map +1 -1
  85. package/dist/generators/documentation/templates/glossaryTemplate.d.ts.map +1 -1
  86. package/dist/generators/documentation/templates/glossaryTemplate.js.map +1 -1
  87. package/dist/generators/documentation/templates/index.d.ts +0 -12
  88. package/dist/generators/documentation/templates/index.d.ts.map +1 -1
  89. package/dist/generators/documentation/templates/index.js +1 -25
  90. package/dist/generators/documentation/templates/index.js.map +1 -1
  91. package/dist/generators/documentation/templates/migrationTemplate.d.ts.map +1 -1
  92. package/dist/generators/documentation/templates/migrationTemplate.js +11 -0
  93. package/dist/generators/documentation/templates/migrationTemplate.js.map +1 -1
  94. package/dist/generators/documentation/templates/onboardingTemplate.d.ts.map +1 -1
  95. package/dist/generators/documentation/templates/onboardingTemplate.js +11 -0
  96. package/dist/generators/documentation/templates/onboardingTemplate.js.map +1 -1
  97. package/dist/generators/documentation/templates/projectOverviewTemplate.d.ts.map +1 -1
  98. package/dist/generators/documentation/templates/projectOverviewTemplate.js +11 -0
  99. package/dist/generators/documentation/templates/projectOverviewTemplate.js.map +1 -1
  100. package/dist/generators/documentation/templates/securityTemplate.d.ts.map +1 -1
  101. package/dist/generators/documentation/templates/securityTemplate.js +11 -0
  102. package/dist/generators/documentation/templates/securityTemplate.js.map +1 -1
  103. package/dist/generators/documentation/templates/testingTemplate.d.ts.map +1 -1
  104. package/dist/generators/documentation/templates/testingTemplate.js +11 -0
  105. package/dist/generators/documentation/templates/testingTemplate.js.map +1 -1
  106. package/dist/generators/documentation/templates/toolingTemplate.d.ts.map +1 -1
  107. package/dist/generators/documentation/templates/toolingTemplate.js +11 -0
  108. package/dist/generators/documentation/templates/toolingTemplate.js.map +1 -1
  109. package/dist/generators/documentation/templates/troubleshootingTemplate.d.ts.map +1 -1
  110. package/dist/generators/documentation/templates/troubleshootingTemplate.js +11 -0
  111. package/dist/generators/documentation/templates/troubleshootingTemplate.js.map +1 -1
  112. package/dist/generators/plans/templates/planTemplate.d.ts +11 -0
  113. package/dist/generators/plans/templates/planTemplate.d.ts.map +1 -1
  114. package/dist/generators/plans/templates/planTemplate.js.map +1 -1
  115. package/dist/generators/shared/index.d.ts +1 -0
  116. package/dist/generators/shared/index.d.ts.map +1 -1
  117. package/dist/generators/shared/index.js +16 -0
  118. package/dist/generators/shared/index.js.map +1 -1
  119. package/dist/generators/shared/scaffoldStructures.d.ts +13 -0
  120. package/dist/generators/shared/scaffoldStructures.d.ts.map +1 -0
  121. package/dist/generators/shared/scaffoldStructures.js +30 -0
  122. package/dist/generators/shared/scaffoldStructures.js.map +1 -0
  123. package/dist/generators/shared/structures/agents/definitions.d.ts +18 -0
  124. package/dist/generators/shared/structures/agents/definitions.d.ts.map +1 -0
  125. package/dist/generators/shared/structures/agents/definitions.js +22 -0
  126. package/dist/generators/shared/structures/agents/definitions.js.map +1 -0
  127. package/dist/generators/shared/structures/agents/factory.d.ts +9 -0
  128. package/dist/generators/shared/structures/agents/factory.d.ts.map +1 -0
  129. package/dist/generators/shared/structures/agents/factory.js +112 -0
  130. package/dist/generators/shared/structures/agents/factory.js.map +1 -0
  131. package/dist/generators/shared/structures/agents/index.d.ts +6 -0
  132. package/dist/generators/shared/structures/agents/index.d.ts.map +1 -0
  133. package/dist/generators/shared/structures/agents/index.js +24 -0
  134. package/dist/generators/shared/structures/agents/index.js.map +1 -0
  135. package/dist/generators/shared/structures/documentation/apiReference.d.ts +3 -0
  136. package/dist/generators/shared/structures/documentation/apiReference.d.ts.map +1 -0
  137. package/dist/generators/shared/structures/documentation/apiReference.js +100 -0
  138. package/dist/generators/shared/structures/documentation/apiReference.js.map +1 -0
  139. package/dist/generators/shared/structures/documentation/architecture.d.ts +3 -0
  140. package/dist/generators/shared/structures/documentation/architecture.d.ts.map +1 -0
  141. package/dist/generators/shared/structures/documentation/architecture.js +121 -0
  142. package/dist/generators/shared/structures/documentation/architecture.js.map +1 -0
  143. package/dist/generators/shared/structures/documentation/dataFlow.d.ts +3 -0
  144. package/dist/generators/shared/structures/documentation/dataFlow.d.ts.map +1 -0
  145. package/dist/generators/shared/structures/documentation/dataFlow.js +72 -0
  146. package/dist/generators/shared/structures/documentation/dataFlow.js.map +1 -0
  147. package/dist/generators/shared/structures/documentation/glossary.d.ts +3 -0
  148. package/dist/generators/shared/structures/documentation/glossary.d.ts.map +1 -0
  149. package/dist/generators/shared/structures/documentation/glossary.js +71 -0
  150. package/dist/generators/shared/structures/documentation/glossary.js.map +1 -0
  151. package/dist/generators/shared/structures/documentation/index.d.ts +16 -0
  152. package/dist/generators/shared/structures/documentation/index.d.ts.map +1 -0
  153. package/dist/generators/shared/structures/documentation/index.js +31 -0
  154. package/dist/generators/shared/structures/documentation/index.js.map +1 -0
  155. package/dist/generators/shared/structures/documentation/migration.d.ts +3 -0
  156. package/dist/generators/shared/structures/documentation/migration.d.ts.map +1 -0
  157. package/dist/generators/shared/structures/documentation/migration.js +113 -0
  158. package/dist/generators/shared/structures/documentation/migration.js.map +1 -0
  159. package/dist/generators/shared/structures/documentation/onboarding.d.ts +3 -0
  160. package/dist/generators/shared/structures/documentation/onboarding.d.ts.map +1 -0
  161. package/dist/generators/shared/structures/documentation/onboarding.js +99 -0
  162. package/dist/generators/shared/structures/documentation/onboarding.js.map +1 -0
  163. package/dist/generators/shared/structures/documentation/projectOverview.d.ts +3 -0
  164. package/dist/generators/shared/structures/documentation/projectOverview.d.ts.map +1 -0
  165. package/dist/generators/shared/structures/documentation/projectOverview.js +115 -0
  166. package/dist/generators/shared/structures/documentation/projectOverview.js.map +1 -0
  167. package/dist/generators/shared/structures/documentation/security.d.ts +3 -0
  168. package/dist/generators/shared/structures/documentation/security.d.ts.map +1 -0
  169. package/dist/generators/shared/structures/documentation/security.js +55 -0
  170. package/dist/generators/shared/structures/documentation/security.js.map +1 -0
  171. package/dist/generators/shared/structures/documentation/testing.d.ts +3 -0
  172. package/dist/generators/shared/structures/documentation/testing.d.ts.map +1 -0
  173. package/dist/generators/shared/structures/documentation/testing.js +57 -0
  174. package/dist/generators/shared/structures/documentation/testing.js.map +1 -0
  175. package/dist/generators/shared/structures/documentation/tooling.d.ts +3 -0
  176. package/dist/generators/shared/structures/documentation/tooling.d.ts.map +1 -0
  177. package/dist/generators/shared/structures/documentation/tooling.js +55 -0
  178. package/dist/generators/shared/structures/documentation/tooling.js.map +1 -0
  179. package/dist/generators/shared/structures/documentation/troubleshooting.d.ts +3 -0
  180. package/dist/generators/shared/structures/documentation/troubleshooting.d.ts.map +1 -0
  181. package/dist/generators/shared/structures/documentation/troubleshooting.js +91 -0
  182. package/dist/generators/shared/structures/documentation/troubleshooting.js.map +1 -0
  183. package/dist/generators/shared/structures/documentation/workflow.d.ts +3 -0
  184. package/dist/generators/shared/structures/documentation/workflow.d.ts.map +1 -0
  185. package/dist/generators/shared/structures/documentation/workflow.js +56 -0
  186. package/dist/generators/shared/structures/documentation/workflow.js.map +1 -0
  187. package/dist/generators/shared/structures/index.d.ts +15 -0
  188. package/dist/generators/shared/structures/index.d.ts.map +1 -0
  189. package/dist/generators/shared/structures/index.js +37 -0
  190. package/dist/generators/shared/structures/index.js.map +1 -0
  191. package/dist/generators/shared/structures/plans/index.d.ts +5 -0
  192. package/dist/generators/shared/structures/plans/index.d.ts.map +1 -0
  193. package/dist/generators/shared/structures/plans/index.js +9 -0
  194. package/dist/generators/shared/structures/plans/index.js.map +1 -0
  195. package/dist/generators/shared/structures/plans/planStructure.d.ts +6 -0
  196. package/dist/generators/shared/structures/plans/planStructure.d.ts.map +1 -0
  197. package/dist/generators/shared/structures/plans/planStructure.js +65 -0
  198. package/dist/generators/shared/structures/plans/planStructure.js.map +1 -0
  199. package/dist/generators/shared/structures/registry.d.ts +18 -0
  200. package/dist/generators/shared/structures/registry.d.ts.map +1 -0
  201. package/dist/generators/shared/structures/registry.js +104 -0
  202. package/dist/generators/shared/structures/registry.js.map +1 -0
  203. package/dist/generators/shared/structures/serialization.d.ts +15 -0
  204. package/dist/generators/shared/structures/serialization.d.ts.map +1 -0
  205. package/dist/generators/shared/structures/serialization.js +119 -0
  206. package/dist/generators/shared/structures/serialization.js.map +1 -0
  207. package/dist/generators/shared/structures/skills/definitions.d.ts +14 -0
  208. package/dist/generators/shared/structures/skills/definitions.d.ts.map +1 -0
  209. package/dist/generators/shared/structures/skills/definitions.js +18 -0
  210. package/dist/generators/shared/structures/skills/definitions.js.map +1 -0
  211. package/dist/generators/shared/structures/skills/factory.d.ts +9 -0
  212. package/dist/generators/shared/structures/skills/factory.d.ts.map +1 -0
  213. package/dist/generators/shared/structures/skills/factory.js +56 -0
  214. package/dist/generators/shared/structures/skills/factory.js.map +1 -0
  215. package/dist/generators/shared/structures/skills/index.d.ts +6 -0
  216. package/dist/generators/shared/structures/skills/index.d.ts.map +1 -0
  217. package/dist/generators/shared/structures/skills/index.js +20 -0
  218. package/dist/generators/shared/structures/skills/index.js.map +1 -0
  219. package/dist/generators/shared/structures/types.d.ts +59 -0
  220. package/dist/generators/shared/structures/types.d.ts.map +1 -0
  221. package/dist/generators/shared/structures/types.js +6 -0
  222. package/dist/generators/shared/structures/types.js.map +1 -0
  223. package/dist/generators/shared/structures/validation.d.ts +13 -0
  224. package/dist/generators/shared/structures/validation.d.ts.map +1 -0
  225. package/dist/generators/shared/structures/validation.js +51 -0
  226. package/dist/generators/shared/structures/validation.js.map +1 -0
  227. package/dist/generators/skills/skillGenerator.d.ts +5 -0
  228. package/dist/generators/skills/skillGenerator.d.ts.map +1 -1
  229. package/dist/generators/skills/skillGenerator.js +26 -17
  230. package/dist/generators/skills/skillGenerator.js.map +1 -1
  231. package/dist/generators/skills/templates/skillTemplate.d.ts +10 -0
  232. package/dist/generators/skills/templates/skillTemplate.d.ts.map +1 -1
  233. package/dist/generators/skills/templates/skillTemplate.js +10 -0
  234. package/dist/generators/skills/templates/skillTemplate.js.map +1 -1
  235. package/dist/index.d.ts.map +1 -1
  236. package/dist/index.js +203 -5
  237. package/dist/index.js.map +1 -1
  238. package/dist/prompts/defaults.d.ts +5 -0
  239. package/dist/prompts/defaults.d.ts.map +1 -1
  240. package/dist/prompts/defaults.js +44 -1
  241. package/dist/prompts/defaults.js.map +1 -1
  242. package/dist/services/ai/agents/documentationAgent.d.ts +2 -0
  243. package/dist/services/ai/agents/documentationAgent.d.ts.map +1 -1
  244. package/dist/services/ai/agents/documentationAgent.js +33 -9
  245. package/dist/services/ai/agents/documentationAgent.js.map +1 -1
  246. package/dist/services/ai/agents/playbookAgent.d.ts +2 -0
  247. package/dist/services/ai/agents/playbookAgent.d.ts.map +1 -1
  248. package/dist/services/ai/agents/playbookAgent.js +44 -19
  249. package/dist/services/ai/agents/playbookAgent.js.map +1 -1
  250. package/dist/services/ai/agents/skillAgent.d.ts +2 -0
  251. package/dist/services/ai/agents/skillAgent.d.ts.map +1 -1
  252. package/dist/services/ai/agents/skillAgent.js +54 -22
  253. package/dist/services/ai/agents/skillAgent.js.map +1 -1
  254. package/dist/services/ai/schemas.d.ts +138 -9
  255. package/dist/services/ai/schemas.d.ts.map +1 -1
  256. package/dist/services/ai/schemas.js +70 -5
  257. package/dist/services/ai/schemas.js.map +1 -1
  258. package/dist/services/ai/toolRegistry.d.ts.map +1 -1
  259. package/dist/services/ai/toolRegistry.js +25 -17
  260. package/dist/services/ai/toolRegistry.js.map +1 -1
  261. package/dist/services/ai/tools/checkScaffoldingTool.d.ts.map +1 -1
  262. package/dist/services/ai/tools/checkScaffoldingTool.js +4 -1
  263. package/dist/services/ai/tools/checkScaffoldingTool.js.map +1 -1
  264. package/dist/services/ai/tools/fillScaffoldingTool.d.ts +24 -9
  265. package/dist/services/ai/tools/fillScaffoldingTool.d.ts.map +1 -1
  266. package/dist/services/ai/tools/fillScaffoldingTool.js +46 -130
  267. package/dist/services/ai/tools/fillScaffoldingTool.js.map +1 -1
  268. package/dist/services/ai/tools/getCodebaseMapTool.d.ts +1 -1
  269. package/dist/services/ai/tools/getCodebaseMapTool.d.ts.map +1 -1
  270. package/dist/services/ai/tools/getCodebaseMapTool.js +4 -1
  271. package/dist/services/ai/tools/getCodebaseMapTool.js.map +1 -1
  272. package/dist/services/ai/tools/index.d.ts +1 -1
  273. package/dist/services/ai/tools/index.d.ts.map +1 -1
  274. package/dist/services/ai/tools/index.js +3 -1
  275. package/dist/services/ai/tools/index.js.map +1 -1
  276. package/dist/services/ai/tools/initializeContextTool.d.ts +109 -7
  277. package/dist/services/ai/tools/initializeContextTool.d.ts.map +1 -1
  278. package/dist/services/ai/tools/initializeContextTool.js +282 -17
  279. package/dist/services/ai/tools/initializeContextTool.js.map +1 -1
  280. package/dist/services/ai/tools/scaffoldPlanTool.d.ts +17 -1
  281. package/dist/services/ai/tools/scaffoldPlanTool.d.ts.map +1 -1
  282. package/dist/services/ai/tools/scaffoldPlanTool.js +94 -5
  283. package/dist/services/ai/tools/scaffoldPlanTool.js.map +1 -1
  284. package/dist/services/ai/tools/toolFactory.d.ts +35 -0
  285. package/dist/services/ai/tools/toolFactory.d.ts.map +1 -0
  286. package/dist/services/ai/tools/toolFactory.js +20 -0
  287. package/dist/services/ai/tools/toolFactory.js.map +1 -0
  288. package/dist/services/export/contextExportService.d.ts +45 -0
  289. package/dist/services/export/contextExportService.d.ts.map +1 -0
  290. package/dist/services/export/contextExportService.js +161 -0
  291. package/dist/services/export/contextExportService.js.map +1 -0
  292. package/dist/services/export/exportRulesService.d.ts +15 -1
  293. package/dist/services/export/exportRulesService.d.ts.map +1 -1
  294. package/dist/services/export/exportRulesService.js +100 -36
  295. package/dist/services/export/exportRulesService.js.map +1 -1
  296. package/dist/services/export/index.d.ts +2 -0
  297. package/dist/services/export/index.d.ts.map +1 -1
  298. package/dist/services/export/index.js +3 -1
  299. package/dist/services/export/index.js.map +1 -1
  300. package/dist/services/export/skillExportService.d.ts +6 -1
  301. package/dist/services/export/skillExportService.d.ts.map +1 -1
  302. package/dist/services/export/skillExportService.js +46 -22
  303. package/dist/services/export/skillExportService.js.map +1 -1
  304. package/dist/services/fill/fillService.d.ts.map +1 -1
  305. package/dist/services/fill/fillService.js +30 -3
  306. package/dist/services/fill/fillService.js.map +1 -1
  307. package/dist/services/fill/skillFillService.d.ts.map +1 -1
  308. package/dist/services/fill/skillFillService.js +8 -1
  309. package/dist/services/fill/skillFillService.js.map +1 -1
  310. package/dist/services/import/presets.d.ts +12 -0
  311. package/dist/services/import/presets.d.ts.map +1 -1
  312. package/dist/services/import/presets.js +32 -152
  313. package/dist/services/import/presets.js.map +1 -1
  314. package/dist/services/init/initService.d.ts +1 -0
  315. package/dist/services/init/initService.d.ts.map +1 -1
  316. package/dist/services/init/initService.js +42 -9
  317. package/dist/services/init/initService.js.map +1 -1
  318. package/dist/services/mcp/actionLogger.d.ts +19 -0
  319. package/dist/services/mcp/actionLogger.d.ts.map +1 -0
  320. package/dist/services/mcp/actionLogger.js +128 -0
  321. package/dist/services/mcp/actionLogger.js.map +1 -0
  322. package/dist/services/mcp/gateway/agent.d.ts +17 -0
  323. package/dist/services/mcp/gateway/agent.d.ts.map +1 -0
  324. package/dist/services/mcp/gateway/agent.js +147 -0
  325. package/dist/services/mcp/gateway/agent.js.map +1 -0
  326. package/dist/services/mcp/gateway/context.d.ts +21 -0
  327. package/dist/services/mcp/gateway/context.d.ts.map +1 -0
  328. package/dist/services/mcp/gateway/context.js +249 -0
  329. package/dist/services/mcp/gateway/context.js.map +1 -0
  330. package/dist/services/mcp/gateway/explore.d.ts +16 -0
  331. package/dist/services/mcp/gateway/explore.d.ts.map +1 -0
  332. package/dist/services/mcp/gateway/explore.js +60 -0
  333. package/dist/services/mcp/gateway/explore.js.map +1 -0
  334. package/dist/services/mcp/gateway/index.d.ts +24 -0
  335. package/dist/services/mcp/gateway/index.d.ts.map +1 -0
  336. package/dist/services/mcp/gateway/index.js +53 -0
  337. package/dist/services/mcp/gateway/index.js.map +1 -0
  338. package/dist/services/mcp/gateway/metrics.d.ts +56 -0
  339. package/dist/services/mcp/gateway/metrics.d.ts.map +1 -0
  340. package/dist/services/mcp/gateway/metrics.js +153 -0
  341. package/dist/services/mcp/gateway/metrics.js.map +1 -0
  342. package/dist/services/mcp/gateway/plan.d.ts +18 -0
  343. package/dist/services/mcp/gateway/plan.d.ts.map +1 -0
  344. package/dist/services/mcp/gateway/plan.js +273 -0
  345. package/dist/services/mcp/gateway/plan.js.map +1 -0
  346. package/dist/services/mcp/gateway/project.d.ts +16 -0
  347. package/dist/services/mcp/gateway/project.d.ts.map +1 -0
  348. package/dist/services/mcp/gateway/project.js +149 -0
  349. package/dist/services/mcp/gateway/project.js.map +1 -0
  350. package/dist/services/mcp/gateway/projectReport.d.ts +20 -0
  351. package/dist/services/mcp/gateway/projectReport.d.ts.map +1 -0
  352. package/dist/services/mcp/gateway/projectReport.js +61 -0
  353. package/dist/services/mcp/gateway/projectReport.js.map +1 -0
  354. package/dist/services/mcp/gateway/projectSetup.d.ts +29 -0
  355. package/dist/services/mcp/gateway/projectSetup.d.ts.map +1 -0
  356. package/dist/services/mcp/gateway/projectSetup.js +141 -0
  357. package/dist/services/mcp/gateway/projectSetup.js.map +1 -0
  358. package/dist/services/mcp/gateway/response.d.ts +45 -0
  359. package/dist/services/mcp/gateway/response.d.ts.map +1 -0
  360. package/dist/services/mcp/gateway/response.js +111 -0
  361. package/dist/services/mcp/gateway/response.js.map +1 -0
  362. package/dist/services/mcp/gateway/shared.d.ts +38 -0
  363. package/dist/services/mcp/gateway/shared.d.ts.map +1 -0
  364. package/dist/services/mcp/gateway/shared.js +39 -0
  365. package/dist/services/mcp/gateway/shared.js.map +1 -0
  366. package/dist/services/mcp/gateway/skill.d.ts +17 -0
  367. package/dist/services/mcp/gateway/skill.d.ts.map +1 -0
  368. package/dist/services/mcp/gateway/skill.js +323 -0
  369. package/dist/services/mcp/gateway/skill.js.map +1 -0
  370. package/dist/services/mcp/gateway/sync.d.ts +17 -0
  371. package/dist/services/mcp/gateway/sync.d.ts.map +1 -0
  372. package/dist/services/mcp/gateway/sync.js +219 -0
  373. package/dist/services/mcp/gateway/sync.js.map +1 -0
  374. package/dist/services/mcp/gateway/types.d.ts +116 -0
  375. package/dist/services/mcp/gateway/types.d.ts.map +1 -0
  376. package/dist/services/mcp/gateway/types.js +12 -0
  377. package/dist/services/mcp/gateway/types.js.map +1 -0
  378. package/dist/services/mcp/gateway/workflow.d.ts +18 -0
  379. package/dist/services/mcp/gateway/workflow.d.ts.map +1 -0
  380. package/dist/services/mcp/gateway/workflow.js +317 -0
  381. package/dist/services/mcp/gateway/workflow.js.map +1 -0
  382. package/dist/services/mcp/gateway/workflowAdvance.d.ts +25 -0
  383. package/dist/services/mcp/gateway/workflowAdvance.d.ts.map +1 -0
  384. package/dist/services/mcp/gateway/workflowAdvance.js +133 -0
  385. package/dist/services/mcp/gateway/workflowAdvance.js.map +1 -0
  386. package/dist/services/mcp/gateway/workflowInit.d.ts +28 -0
  387. package/dist/services/mcp/gateway/workflowInit.d.ts.map +1 -0
  388. package/dist/services/mcp/gateway/workflowInit.js +213 -0
  389. package/dist/services/mcp/gateway/workflowInit.js.map +1 -0
  390. package/dist/services/mcp/gateway/workflowManage.d.ts +31 -0
  391. package/dist/services/mcp/gateway/workflowManage.d.ts.map +1 -0
  392. package/dist/services/mcp/gateway/workflowManage.js +222 -0
  393. package/dist/services/mcp/gateway/workflowManage.js.map +1 -0
  394. package/dist/services/mcp/gateway/workflowStatus.d.ts +17 -0
  395. package/dist/services/mcp/gateway/workflowStatus.d.ts.map +1 -0
  396. package/dist/services/mcp/gateway/workflowStatus.js +91 -0
  397. package/dist/services/mcp/gateway/workflowStatus.js.map +1 -0
  398. package/dist/services/mcp/gatewayTools.d.ts +15 -0
  399. package/dist/services/mcp/gatewayTools.d.ts.map +1 -0
  400. package/dist/services/mcp/gatewayTools.js +38 -0
  401. package/dist/services/mcp/gatewayTools.js.map +1 -0
  402. package/dist/services/mcp/index.d.ts +7 -0
  403. package/dist/services/mcp/index.d.ts.map +1 -1
  404. package/dist/services/mcp/index.js +22 -1
  405. package/dist/services/mcp/index.js.map +1 -1
  406. package/dist/services/mcp/mcpInstallService.d.ts +56 -0
  407. package/dist/services/mcp/mcpInstallService.d.ts.map +1 -0
  408. package/dist/services/mcp/mcpInstallService.js +549 -0
  409. package/dist/services/mcp/mcpInstallService.js.map +1 -0
  410. package/dist/services/mcp/mcpServer.d.ts +45 -19
  411. package/dist/services/mcp/mcpServer.d.ts.map +1 -1
  412. package/dist/services/mcp/mcpServer.js +637 -1696
  413. package/dist/services/mcp/mcpServer.js.map +1 -1
  414. package/dist/services/passthrough/protocol.d.ts +4 -4
  415. package/dist/services/qa/index.d.ts +9 -0
  416. package/dist/services/qa/index.d.ts.map +1 -0
  417. package/dist/services/qa/index.js +15 -0
  418. package/dist/services/qa/index.js.map +1 -0
  419. package/dist/services/qa/patternInferer.d.ts +41 -0
  420. package/dist/services/qa/patternInferer.d.ts.map +1 -0
  421. package/dist/services/qa/patternInferer.js +366 -0
  422. package/dist/services/qa/patternInferer.js.map +1 -0
  423. package/dist/services/qa/qaService.d.ts +107 -0
  424. package/dist/services/qa/qaService.d.ts.map +1 -0
  425. package/dist/services/qa/qaService.js +874 -0
  426. package/dist/services/qa/qaService.js.map +1 -0
  427. package/dist/services/qa/topicDetector.d.ts +54 -0
  428. package/dist/services/qa/topicDetector.d.ts.map +1 -0
  429. package/dist/services/qa/topicDetector.js +306 -0
  430. package/dist/services/qa/topicDetector.js.map +1 -0
  431. package/dist/services/quickSync/quickSyncService.d.ts.map +1 -1
  432. package/dist/services/quickSync/quickSyncService.js +6 -10
  433. package/dist/services/quickSync/quickSyncService.js.map +1 -1
  434. package/dist/services/reverseSync/importSkillsService.d.ts +47 -0
  435. package/dist/services/reverseSync/importSkillsService.d.ts.map +1 -0
  436. package/dist/services/reverseSync/importSkillsService.js +362 -0
  437. package/dist/services/reverseSync/importSkillsService.js.map +1 -0
  438. package/dist/services/reverseSync/index.d.ts +12 -0
  439. package/dist/services/reverseSync/index.d.ts.map +1 -0
  440. package/dist/services/reverseSync/index.js +49 -0
  441. package/dist/services/reverseSync/index.js.map +1 -0
  442. package/dist/services/reverseSync/presets.d.ts +51 -0
  443. package/dist/services/reverseSync/presets.d.ts.map +1 -0
  444. package/dist/services/reverseSync/presets.js +77 -0
  445. package/dist/services/reverseSync/presets.js.map +1 -0
  446. package/dist/services/reverseSync/reverseQuickSyncService.d.ts +37 -0
  447. package/dist/services/reverseSync/reverseQuickSyncService.d.ts.map +1 -0
  448. package/dist/services/reverseSync/reverseQuickSyncService.js +265 -0
  449. package/dist/services/reverseSync/reverseQuickSyncService.js.map +1 -0
  450. package/dist/services/reverseSync/skillsDetector.d.ts +36 -0
  451. package/dist/services/reverseSync/skillsDetector.d.ts.map +1 -0
  452. package/dist/services/reverseSync/skillsDetector.js +287 -0
  453. package/dist/services/reverseSync/skillsDetector.js.map +1 -0
  454. package/dist/services/reverseSync/toolDetector.d.ts +36 -0
  455. package/dist/services/reverseSync/toolDetector.d.ts.map +1 -0
  456. package/dist/services/reverseSync/toolDetector.js +174 -0
  457. package/dist/services/reverseSync/toolDetector.js.map +1 -0
  458. package/dist/services/reverseSync/types.d.ts +203 -0
  459. package/dist/services/reverseSync/types.d.ts.map +1 -0
  460. package/dist/services/reverseSync/types.js +9 -0
  461. package/dist/services/reverseSync/types.js.map +1 -0
  462. package/dist/services/semantic/codebaseAnalyzer.d.ts +23 -1
  463. package/dist/services/semantic/codebaseAnalyzer.d.ts.map +1 -1
  464. package/dist/services/semantic/codebaseAnalyzer.js +531 -0
  465. package/dist/services/semantic/codebaseAnalyzer.js.map +1 -1
  466. package/dist/services/semantic/contextBuilder.d.ts.map +1 -1
  467. package/dist/services/semantic/contextBuilder.js +23 -8
  468. package/dist/services/semantic/contextBuilder.js.map +1 -1
  469. package/dist/services/semantic/types.d.ts +50 -0
  470. package/dist/services/semantic/types.d.ts.map +1 -1
  471. package/dist/services/semantic/types.js.map +1 -1
  472. package/dist/services/shared/contentTypeRegistry.d.ts +66 -0
  473. package/dist/services/shared/contentTypeRegistry.d.ts.map +1 -0
  474. package/dist/services/shared/contentTypeRegistry.js +113 -0
  475. package/dist/services/shared/contentTypeRegistry.js.map +1 -0
  476. package/dist/services/shared/contextRootResolver.d.ts +57 -0
  477. package/dist/services/shared/contextRootResolver.d.ts.map +1 -0
  478. package/dist/services/shared/contextRootResolver.js +102 -0
  479. package/dist/services/shared/contextRootResolver.js.map +1 -0
  480. package/dist/services/shared/index.d.ts +4 -1
  481. package/dist/services/shared/index.d.ts.map +1 -1
  482. package/dist/services/shared/index.js +39 -1
  483. package/dist/services/shared/index.js.map +1 -1
  484. package/dist/services/shared/pathHelpers.d.ts +15 -1
  485. package/dist/services/shared/pathHelpers.d.ts.map +1 -1
  486. package/dist/services/shared/pathHelpers.js +26 -1
  487. package/dist/services/shared/pathHelpers.js.map +1 -1
  488. package/dist/services/shared/toolRegistry.d.ts +135 -0
  489. package/dist/services/shared/toolRegistry.d.ts.map +1 -0
  490. package/dist/services/shared/toolRegistry.js +515 -0
  491. package/dist/services/shared/toolRegistry.js.map +1 -0
  492. package/dist/services/stack/scaffoldFilter.d.ts +1 -1
  493. package/dist/services/sync/presets.d.ts +3 -0
  494. package/dist/services/sync/presets.d.ts.map +1 -1
  495. package/dist/services/sync/presets.js +20 -32
  496. package/dist/services/sync/presets.js.map +1 -1
  497. package/dist/services/sync/syncService.d.ts +8 -0
  498. package/dist/services/sync/syncService.d.ts.map +1 -1
  499. package/dist/services/sync/syncService.js +21 -2
  500. package/dist/services/sync/syncService.js.map +1 -1
  501. package/dist/services/sync/types.d.ts +1 -1
  502. package/dist/services/sync/types.d.ts.map +1 -1
  503. package/dist/services/tools/index.d.ts +95 -0
  504. package/dist/services/tools/index.d.ts.map +1 -0
  505. package/dist/services/tools/index.js +236 -0
  506. package/dist/services/tools/index.js.map +1 -0
  507. package/dist/services/workflow/workflowService.d.ts +57 -4
  508. package/dist/services/workflow/workflowService.d.ts.map +1 -1
  509. package/dist/services/workflow/workflowService.js +79 -6
  510. package/dist/services/workflow/workflowService.js.map +1 -1
  511. package/dist/types/scaffoldFrontmatter.d.ts +145 -0
  512. package/dist/types/scaffoldFrontmatter.d.ts.map +1 -0
  513. package/dist/types/scaffoldFrontmatter.js +172 -0
  514. package/dist/types/scaffoldFrontmatter.js.map +1 -0
  515. package/dist/utils/cliUI.d.ts +1 -1
  516. package/dist/utils/cliUI.d.ts.map +1 -1
  517. package/dist/utils/cliUI.js +4 -1
  518. package/dist/utils/cliUI.js.map +1 -1
  519. package/dist/utils/frontMatter.d.ts +48 -0
  520. package/dist/utils/frontMatter.d.ts.map +1 -1
  521. package/dist/utils/frontMatter.js +135 -0
  522. package/dist/utils/frontMatter.js.map +1 -1
  523. package/dist/utils/gitService.d.ts +26 -0
  524. package/dist/utils/gitService.d.ts.map +1 -1
  525. package/dist/utils/gitService.js +96 -0
  526. package/dist/utils/gitService.js.map +1 -1
  527. package/dist/utils/i18n.d.ts +43 -2
  528. package/dist/utils/i18n.d.ts.map +1 -1
  529. package/dist/utils/i18n.js +96 -6
  530. package/dist/utils/i18n.js.map +1 -1
  531. package/dist/utils/prompts/index.d.ts +4 -0
  532. package/dist/utils/prompts/index.d.ts.map +1 -1
  533. package/dist/utils/prompts/index.js +15 -0
  534. package/dist/utils/prompts/index.js.map +1 -1
  535. package/dist/workflow/errors.d.ts +48 -0
  536. package/dist/workflow/errors.d.ts.map +1 -0
  537. package/dist/workflow/errors.js +52 -0
  538. package/dist/workflow/errors.js.map +1 -0
  539. package/dist/workflow/gates/gateChecker.d.ts +93 -0
  540. package/dist/workflow/gates/gateChecker.d.ts.map +1 -0
  541. package/dist/workflow/gates/gateChecker.js +197 -0
  542. package/dist/workflow/gates/gateChecker.js.map +1 -0
  543. package/dist/workflow/gates/index.d.ts +7 -0
  544. package/dist/workflow/gates/index.d.ts.map +1 -0
  545. package/dist/workflow/gates/index.js +13 -0
  546. package/dist/workflow/gates/index.js.map +1 -0
  547. package/dist/workflow/index.d.ts +4 -2
  548. package/dist/workflow/index.d.ts.map +1 -1
  549. package/dist/workflow/index.js +14 -3
  550. package/dist/workflow/index.js.map +1 -1
  551. package/dist/workflow/orchestrator.d.ts +94 -5
  552. package/dist/workflow/orchestrator.d.ts.map +1 -1
  553. package/dist/workflow/orchestrator.js +300 -11
  554. package/dist/workflow/orchestrator.js.map +1 -1
  555. package/dist/workflow/plans/planLinker.d.ts +79 -3
  556. package/dist/workflow/plans/planLinker.d.ts.map +1 -1
  557. package/dist/workflow/plans/planLinker.js +522 -3
  558. package/dist/workflow/plans/planLinker.js.map +1 -1
  559. package/dist/workflow/plans/types.d.ts +64 -0
  560. package/dist/workflow/plans/types.d.ts.map +1 -1
  561. package/dist/workflow/roles.d.ts +6 -0
  562. package/dist/workflow/roles.d.ts.map +1 -1
  563. package/dist/workflow/roles.js +6 -0
  564. package/dist/workflow/roles.js.map +1 -1
  565. package/dist/workflow/scaling.d.ts +1 -0
  566. package/dist/workflow/scaling.d.ts.map +1 -1
  567. package/dist/workflow/scaling.js +8 -17
  568. package/dist/workflow/scaling.js.map +1 -1
  569. package/dist/workflow/status/statusManager.d.ts +54 -1
  570. package/dist/workflow/status/statusManager.d.ts.map +1 -1
  571. package/dist/workflow/status/statusManager.js +539 -9
  572. package/dist/workflow/status/statusManager.js.map +1 -1
  573. package/dist/workflow/status/templates.d.ts +14 -5
  574. package/dist/workflow/status/templates.d.ts.map +1 -1
  575. package/dist/workflow/status/templates.js +55 -41
  576. package/dist/workflow/status/templates.js.map +1 -1
  577. package/dist/workflow/types.d.ts +138 -2
  578. package/dist/workflow/types.d.ts.map +1 -1
  579. package/dist/workflow/types.js +0 -1
  580. package/dist/workflow/types.js.map +1 -1
  581. package/package.json +1 -1
@@ -2,1206 +2,504 @@
2
2
  /**
3
3
  * MCP Server - Model Context Protocol server for Claude Code integration
4
4
  *
5
- * Exposes code analysis tools and semantic context as MCP resources.
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.AIContextMCPServer = void 0;
9
- exports.startMCPServer = startMCPServer;
10
- const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
11
- const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
12
- const zod_1 = require("zod");
13
- const tools_1 = require("../ai/tools");
14
- const toolRegistry_1 = require("../ai/toolRegistry");
15
- const contextBuilder_1 = require("../semantic/contextBuilder");
16
- const version_1 = require("../../version");
17
- const providerFactory_1 = require("../ai/providerFactory");
18
- const workflow_1 = require("../workflow");
19
- // Default model for MCP tools that require LLM
20
- const DEFAULT_MODEL = providerFactory_1.DEFAULT_MODELS.google || 'gemini-3-flash-preview';
21
- const start_1 = require("../start");
22
- const report_1 = require("../report");
23
- const export_1 = require("../export");
24
- const stack_1 = require("../stack");
25
- const workflow_2 = require("../../workflow");
26
- class AIContextMCPServer {
27
- constructor(options = {}) {
28
- this.transport = null;
29
- this.options = {
30
- name: 'ai-context',
31
- verbose: false,
32
- ...options
33
- };
34
- this.server = new mcp_js_1.McpServer({
35
- name: this.options.name,
36
- version: version_1.VERSION
37
- });
38
- this.contextBuilder = new contextBuilder_1.SemanticContextBuilder();
39
- this.registerTools();
40
- this.registerResources();
41
- }
42
- /**
43
- * Register code analysis tools
44
- */
45
- registerTools() {
46
- // readFile tool
47
- this.server.registerTool('readFile', {
48
- description: (0, toolRegistry_1.getToolDescription)('readFile'),
49
- inputSchema: {
50
- filePath: zod_1.z.string().describe('Absolute or relative path to the file to read'),
51
- encoding: zod_1.z.enum(['utf-8', 'ascii', 'binary']).default('utf-8').optional()
52
- }
53
- }, async ({ filePath, encoding }) => {
54
- const result = await tools_1.readFileTool.execute({ filePath, encoding }, { toolCallId: '', messages: [] });
55
- return {
56
- content: [{
57
- type: 'text',
58
- text: JSON.stringify(result, null, 2)
59
- }]
60
- };
61
- });
62
- // listFiles tool
63
- this.server.registerTool('listFiles', {
64
- description: (0, toolRegistry_1.getToolDescription)('listFiles'),
65
- inputSchema: {
66
- pattern: zod_1.z.string().describe('Glob pattern to match files (e.g., "**/*.ts")'),
67
- cwd: zod_1.z.string().optional().describe('Working directory for the glob pattern'),
68
- ignore: zod_1.z.array(zod_1.z.string()).optional().describe('Patterns to ignore')
69
- }
70
- }, async ({ pattern, cwd, ignore }) => {
71
- const result = await tools_1.listFilesTool.execute({ pattern, cwd: cwd || this.options.repoPath, ignore }, { toolCallId: '', messages: [] });
72
- return {
73
- content: [{
74
- type: 'text',
75
- text: JSON.stringify(result, null, 2)
76
- }]
77
- };
78
- });
79
- // analyzeSymbols tool
80
- this.server.registerTool('analyzeSymbols', {
81
- description: (0, toolRegistry_1.getToolDescription)('analyzeSymbols'),
82
- inputSchema: {
83
- filePath: zod_1.z.string().describe('Path to the file to analyze'),
84
- symbolTypes: zod_1.z.array(zod_1.z.enum(['class', 'interface', 'function', 'type', 'enum']))
85
- .optional()
86
- .describe('Types of symbols to extract')
87
- }
88
- }, async ({ filePath, symbolTypes }) => {
89
- const result = await tools_1.analyzeSymbolsTool.execute({ filePath, symbolTypes }, { toolCallId: '', messages: [] });
90
- return {
91
- content: [{
92
- type: 'text',
93
- text: JSON.stringify(result, null, 2)
94
- }]
95
- };
96
- });
97
- // getFileStructure tool
98
- this.server.registerTool('getFileStructure', {
99
- description: (0, toolRegistry_1.getToolDescription)('getFileStructure'),
100
- inputSchema: {
101
- rootPath: zod_1.z.string().describe('Root path of the repository'),
102
- maxDepth: zod_1.z.number().optional().default(3).describe('Maximum directory depth'),
103
- includePatterns: zod_1.z.array(zod_1.z.string()).optional()
104
- }
105
- }, async ({ rootPath, maxDepth, includePatterns }) => {
106
- const result = await tools_1.getFileStructureTool.execute({ rootPath: rootPath || this.options.repoPath || '.', maxDepth, includePatterns }, { toolCallId: '', messages: [] });
107
- return {
108
- content: [{
109
- type: 'text',
110
- text: JSON.stringify(result, null, 2)
111
- }]
112
- };
113
- });
114
- // searchCode tool
115
- this.server.registerTool('searchCode', {
116
- description: (0, toolRegistry_1.getToolDescription)('searchCode'),
117
- inputSchema: {
118
- pattern: zod_1.z.string().describe('Regex pattern to search for'),
119
- fileGlob: zod_1.z.string().optional().describe('Glob pattern to filter files'),
120
- maxResults: zod_1.z.number().optional().default(50),
121
- cwd: zod_1.z.string().optional().describe('Working directory for the search')
122
- }
123
- }, async ({ pattern, fileGlob, maxResults, cwd }) => {
124
- const result = await tools_1.searchCodeTool.execute({
125
- pattern,
126
- fileGlob,
127
- maxResults,
128
- cwd: cwd || this.options.repoPath
129
- }, { toolCallId: '', messages: [] });
130
- return {
131
- content: [{
132
- type: 'text',
133
- text: JSON.stringify(result, null, 2)
134
- }]
135
- };
136
- });
137
- // buildSemanticContext tool - higher-level context building
138
- this.server.registerTool('buildSemanticContext', {
139
- description: (0, toolRegistry_1.getToolDescription)('buildSemanticContext'),
140
- inputSchema: {
141
- repoPath: zod_1.z.string().describe('Path to the repository'),
142
- contextType: zod_1.z.enum(['documentation', 'playbook', 'plan', 'compact'])
143
- .default('compact')
144
- .describe('Type of context to build'),
145
- targetFile: zod_1.z.string().optional().describe('Optional target file for focused context'),
146
- options: zod_1.z.object({
147
- useLSP: zod_1.z.boolean().optional(),
148
- maxContextLength: zod_1.z.number().optional(),
149
- includeDocumentation: zod_1.z.boolean().optional(),
150
- includeSignatures: zod_1.z.boolean().optional()
151
- }).optional()
152
- }
153
- }, async ({ repoPath, contextType, targetFile, options }) => {
154
- const isLocalBuilder = !!options;
155
- const builder = isLocalBuilder
156
- ? new contextBuilder_1.SemanticContextBuilder(options)
157
- : this.contextBuilder;
158
- try {
159
- let context;
160
- const resolvedPath = repoPath || this.options.repoPath || '.';
161
- switch (contextType) {
162
- case 'documentation':
163
- context = await builder.buildDocumentationContext(resolvedPath, targetFile);
164
- break;
165
- case 'playbook':
166
- context = await builder.buildPlaybookContext(resolvedPath, targetFile || 'generic');
167
- break;
168
- case 'plan':
169
- context = await builder.buildPlanContext(resolvedPath, targetFile);
170
- break;
171
- case 'compact':
172
- default:
173
- context = await builder.buildCompactContext(resolvedPath);
174
- break;
175
- }
176
- return {
177
- content: [{
178
- type: 'text',
179
- text: context
180
- }]
181
- };
182
- }
183
- finally {
184
- if (isLocalBuilder) {
185
- await builder.shutdown();
186
- }
187
- }
188
- });
189
- // checkScaffolding tool
190
- this.server.registerTool('checkScaffolding', {
191
- description: (0, toolRegistry_1.getToolDescription)('checkScaffolding'),
192
- inputSchema: {
193
- repoPath: zod_1.z.string().optional().describe('Repository path to check (defaults to cwd)')
194
- }
195
- }, async ({ repoPath }) => {
196
- const result = await tools_1.checkScaffoldingTool.execute({ repoPath: repoPath || this.options.repoPath }, { toolCallId: '', messages: [] });
197
- return {
198
- content: [{
199
- type: 'text',
200
- text: JSON.stringify(result, null, 2)
201
- }]
202
- };
203
- });
204
- // initializeContext tool
205
- this.server.registerTool('initializeContext', {
206
- description: (0, toolRegistry_1.getToolDescription)('initializeContext', true),
207
- inputSchema: {
208
- repoPath: zod_1.z.string().describe('Repository path to initialize'),
209
- type: zod_1.z.enum(['docs', 'agents', 'both']).default('both').optional()
210
- .describe('Type of scaffolding to create'),
211
- outputDir: zod_1.z.string().optional().describe('Output directory (default: ./.context)'),
212
- semantic: zod_1.z.boolean().default(true).optional()
213
- .describe('Enable semantic analysis for richer templates'),
214
- include: zod_1.z.array(zod_1.z.string()).optional().describe('Include patterns'),
215
- exclude: zod_1.z.array(zod_1.z.string()).optional().describe('Exclude patterns')
216
- }
217
- }, async ({ repoPath, type, outputDir, semantic, include, exclude }) => {
218
- const result = await tools_1.initializeContextTool.execute({
219
- repoPath: repoPath || this.options.repoPath || process.cwd(),
220
- type,
221
- outputDir,
222
- semantic,
223
- include,
224
- exclude
225
- }, { toolCallId: '', messages: [] });
226
- return {
227
- content: [{
228
- type: 'text',
229
- text: JSON.stringify(result, null, 2)
230
- }]
231
- };
232
- });
233
- // scaffoldPlan tool
234
- this.server.registerTool('scaffoldPlan', {
235
- description: (0, toolRegistry_1.getToolDescription)('scaffoldPlan'),
236
- inputSchema: {
237
- planName: zod_1.z.string().describe('Name of the plan (will be slugified)'),
238
- repoPath: zod_1.z.string().optional().describe('Repository path'),
239
- outputDir: zod_1.z.string().optional().describe('Output directory'),
240
- title: zod_1.z.string().optional().describe('Plan title (defaults to formatted planName)'),
241
- summary: zod_1.z.string().optional().describe('Plan summary/goal'),
242
- semantic: zod_1.z.boolean().default(true).optional().describe('Enable semantic analysis')
243
- }
244
- }, async ({ planName, repoPath, outputDir, title, summary, semantic }) => {
245
- const result = await tools_1.scaffoldPlanTool.execute({
246
- planName,
247
- repoPath: repoPath || this.options.repoPath || process.cwd(),
248
- outputDir,
249
- title,
250
- summary,
251
- semantic
252
- }, { toolCallId: '', messages: [] });
253
- return {
254
- content: [{
255
- type: 'text',
256
- text: JSON.stringify(result, null, 2)
257
- }]
258
- };
259
- });
260
- // fillScaffolding tool (with pagination)
261
- this.server.registerTool('fillScaffolding', {
262
- description: (0, toolRegistry_1.getToolDescription)('fillScaffolding', true),
263
- inputSchema: {
264
- repoPath: zod_1.z.string().describe('Repository path'),
265
- outputDir: zod_1.z.string().optional().describe('Scaffold directory (default: ./.context)'),
266
- target: zod_1.z.enum(['docs', 'agents', 'plans', 'all']).default('all').optional()
267
- .describe('Which scaffolding to fill'),
268
- offset: zod_1.z.number().optional().describe('Skip first N files (for pagination)'),
269
- limit: zod_1.z.number().optional().describe('Max files to return (default: 3, use 0 for all)')
270
- }
271
- }, async ({ repoPath, outputDir, target, offset, limit }) => {
272
- const result = await tools_1.fillScaffoldingTool.execute({
273
- repoPath: repoPath || this.options.repoPath || process.cwd(),
274
- outputDir,
275
- target,
276
- offset,
277
- limit
278
- }, { toolCallId: '', messages: [] });
279
- return {
280
- content: [{
281
- type: 'text',
282
- text: JSON.stringify(result, null, 2)
283
- }]
284
- };
285
- });
286
- // listFilesToFill tool - lightweight listing without content
287
- this.server.registerTool('listFilesToFill', {
288
- description: (0, toolRegistry_1.getToolDescription)('listFilesToFill', true),
289
- inputSchema: {
290
- repoPath: zod_1.z.string().describe('Repository path'),
291
- outputDir: zod_1.z.string().optional().describe('Scaffold directory (default: ./.context)'),
292
- target: zod_1.z.enum(['docs', 'agents', 'plans', 'all']).default('all').optional()
293
- .describe('Which scaffolding to list')
294
- }
295
- }, async ({ repoPath, outputDir, target }) => {
296
- const result = await tools_1.listFilesToFillTool.execute({
297
- repoPath: repoPath || this.options.repoPath || process.cwd(),
298
- outputDir,
299
- target
300
- }, { toolCallId: '', messages: [] });
301
- return {
302
- content: [{
303
- type: 'text',
304
- text: JSON.stringify(result, null, 2)
305
- }]
306
- };
307
- });
308
- // fillSingleFile tool - process one file at a time
309
- this.server.registerTool('fillSingleFile', {
310
- description: (0, toolRegistry_1.getToolDescription)('fillSingleFile', true),
311
- inputSchema: {
312
- repoPath: zod_1.z.string().describe('Repository path'),
313
- filePath: zod_1.z.string().describe('Absolute path to the scaffold file to fill')
314
- }
315
- }, async ({ repoPath, filePath }) => {
316
- const result = await tools_1.fillSingleFileTool.execute({
317
- repoPath: repoPath || this.options.repoPath || process.cwd(),
318
- filePath
319
- }, { toolCallId: '', messages: [] });
320
- return {
321
- content: [{
322
- type: 'text',
323
- text: JSON.stringify(result, null, 2)
324
- }]
325
- };
326
- });
327
- // getCodebaseMap tool - retrieve sections of the codebase map JSON
328
- this.server.registerTool('getCodebaseMap', {
329
- description: (0, toolRegistry_1.getToolDescription)('getCodebaseMap', true),
330
- inputSchema: {
331
- repoPath: zod_1.z.string().optional().describe('Repository path (defaults to cwd)'),
332
- section: zod_1.z.enum([
333
- 'all',
334
- 'stack',
335
- 'structure',
336
- 'architecture',
337
- 'symbols',
338
- 'symbols.classes',
339
- 'symbols.interfaces',
340
- 'symbols.functions',
341
- 'symbols.types',
342
- 'symbols.enums',
343
- 'publicAPI',
344
- 'dependencies',
345
- 'stats'
346
- ]).default('all').optional()
347
- .describe('Section of the codebase map to retrieve. Use specific sections to reduce token usage.')
348
- }
349
- }, async ({ repoPath, section }) => {
350
- const result = await tools_1.getCodebaseMapTool.execute({
351
- repoPath: repoPath || this.options.repoPath || process.cwd(),
352
- section
353
- }, { toolCallId: '', messages: [] });
354
- return {
355
- content: [{
356
- type: 'text',
357
- text: JSON.stringify(result, null, 2)
358
- }]
359
- };
360
- });
361
- this.log('Registered 13 tools');
362
- // Register PREVC workflow tools
363
- this.registerWorkflowTools();
364
- }
365
- /**
366
- * Register PREVC workflow tools
367
- */
368
- registerWorkflowTools() {
369
- const repoPath = this.options.repoPath || process.cwd();
370
- // workflowInit - Initialize a PREVC workflow
371
- this.server.registerTool('workflowInit', {
372
- description: 'Initialize a PREVC workflow with automatic scale detection. PREVC = Planejamento, Revisão, Execução, Validação, Confirmação.',
373
- inputSchema: {
374
- name: zod_1.z.string().describe('Name of the project/feature'),
375
- description: zod_1.z.string().optional().describe('Description for scale detection'),
376
- scale: zod_1.z.enum(['QUICK', 'SMALL', 'MEDIUM', 'LARGE', 'ENTERPRISE']).optional()
377
- .describe('Project scale (auto-detected if not provided)')
378
- }
379
- }, async ({ name, description, scale }) => {
380
- try {
381
- const service = new workflow_1.WorkflowService(repoPath);
382
- const status = await service.init({
383
- name,
384
- description,
385
- scale: scale,
386
- });
387
- return {
388
- content: [{
389
- type: 'text',
390
- text: JSON.stringify({
391
- success: true,
392
- message: `Workflow initialized: ${name}`,
393
- scale: (0, workflow_2.getScaleName)(status.project.scale),
394
- currentPhase: status.project.current_phase,
395
- phases: Object.keys(status.phases).filter((p) => status.phases[p].status !== 'skipped'),
396
- }, null, 2)
397
- }]
398
- };
399
- }
400
- catch (error) {
401
- return {
402
- content: [{
403
- type: 'text',
404
- text: JSON.stringify({
405
- success: false,
406
- error: error instanceof Error ? error.message : String(error)
407
- }, null, 2)
408
- }]
409
- };
410
- }
411
- });
412
- // workflowStatus - Get current workflow status
413
- this.server.registerTool('workflowStatus', {
414
- description: 'Get the current status of the PREVC workflow including phases, roles, and progress.',
415
- inputSchema: {}
416
- }, async () => {
417
- try {
418
- const service = new workflow_1.WorkflowService(repoPath);
419
- if (!(await service.hasWorkflow())) {
420
- return {
421
- content: [{
422
- type: 'text',
423
- text: JSON.stringify({
424
- success: false,
425
- error: 'No workflow found. Run workflowInit first.'
426
- }, null, 2)
427
- }]
428
- };
429
- }
430
- const summary = await service.getSummary();
431
- const status = await service.getStatus();
432
- return {
433
- content: [{
434
- type: 'text',
435
- text: JSON.stringify({
436
- success: true,
437
- name: summary.name,
438
- scale: (0, workflow_2.getScaleName)(summary.scale),
439
- currentPhase: {
440
- code: summary.currentPhase,
441
- name: workflow_2.PHASE_NAMES_EN[summary.currentPhase],
442
- },
443
- progress: summary.progress,
444
- isComplete: summary.isComplete,
445
- phases: status.phases,
446
- roles: status.roles,
447
- }, null, 2)
448
- }]
449
- };
450
- }
451
- catch (error) {
452
- return {
453
- content: [{
454
- type: 'text',
455
- text: JSON.stringify({
456
- success: false,
457
- error: error instanceof Error ? error.message : String(error)
458
- }, null, 2)
459
- }]
460
- };
461
- }
462
- });
463
- // workflowAdvance - Advance to the next phase
464
- this.server.registerTool('workflowAdvance', {
465
- description: 'Complete the current phase and advance to the next phase in the PREVC workflow.',
466
- inputSchema: {
467
- outputs: zod_1.z.array(zod_1.z.string()).optional()
468
- .describe('List of artifact paths generated in the current phase')
469
- }
470
- }, async ({ outputs }) => {
471
- try {
472
- const service = new workflow_1.WorkflowService(repoPath);
473
- if (!(await service.hasWorkflow())) {
474
- return {
475
- content: [{
476
- type: 'text',
477
- text: JSON.stringify({
478
- success: false,
479
- error: 'No workflow found. Run workflowInit first.'
480
- }, null, 2)
481
- }]
482
- };
483
- }
484
- const nextPhase = await service.advance(outputs);
485
- if (nextPhase) {
486
- return {
487
- content: [{
488
- type: 'text',
489
- text: JSON.stringify({
490
- success: true,
491
- message: `Advanced to ${workflow_2.PHASE_NAMES_EN[nextPhase]} phase`,
492
- nextPhase: {
493
- code: nextPhase,
494
- name: workflow_2.PHASE_NAMES_EN[nextPhase],
495
- }
496
- }, null, 2)
497
- }]
498
- };
499
- }
500
- else {
501
- return {
502
- content: [{
503
- type: 'text',
504
- text: JSON.stringify({
505
- success: true,
506
- message: 'Workflow completed!',
507
- isComplete: true
508
- }, null, 2)
509
- }]
510
- };
511
- }
512
- }
513
- catch (error) {
514
- return {
515
- content: [{
516
- type: 'text',
517
- text: JSON.stringify({
518
- success: false,
519
- error: error instanceof Error ? error.message : String(error)
520
- }, null, 2)
521
- }]
522
- };
523
- }
524
- });
525
- // workflowHandoff - Handoff between roles
526
- this.server.registerTool('workflowHandoff', {
527
- description: 'Perform a handoff from one role to another within the PREVC workflow.',
528
- inputSchema: {
529
- from: zod_1.z.enum(workflow_2.PREVC_ROLES)
530
- .describe('Role handing off'),
531
- to: zod_1.z.enum(workflow_2.PREVC_ROLES)
532
- .describe('Role receiving handoff'),
533
- artifacts: zod_1.z.array(zod_1.z.string()).describe('Artifacts being handed off')
534
- }
535
- }, async ({ from, to, artifacts }) => {
536
- try {
537
- const service = new workflow_1.WorkflowService(repoPath);
538
- if (!(await service.hasWorkflow())) {
539
- return {
540
- content: [{
541
- type: 'text',
542
- text: JSON.stringify({
543
- success: false,
544
- error: 'No workflow found. Run workflowInit first.'
545
- }, null, 2)
546
- }]
547
- };
548
- }
549
- await service.handoff(from, to, artifacts);
550
- return {
551
- content: [{
552
- type: 'text',
553
- text: JSON.stringify({
554
- success: true,
555
- message: `Handoff complete: ${workflow_2.ROLE_DISPLAY_NAMES[from]} → ${workflow_2.ROLE_DISPLAY_NAMES[to]}`,
556
- from: { role: from, displayName: workflow_2.ROLE_DISPLAY_NAMES[from] },
557
- to: { role: to, displayName: workflow_2.ROLE_DISPLAY_NAMES[to] },
558
- artifacts
559
- }, null, 2)
560
- }]
561
- };
562
- }
563
- catch (error) {
564
- return {
565
- content: [{
566
- type: 'text',
567
- text: JSON.stringify({
568
- success: false,
569
- error: error instanceof Error ? error.message : String(error)
570
- }, null, 2)
571
- }]
572
- };
573
- }
574
- });
575
- // workflowCollaborate - Start a collaboration session
576
- this.server.registerTool('workflowCollaborate', {
577
- description: 'Start a multi-role collaboration session for complex decisions or brainstorming.',
578
- inputSchema: {
579
- topic: zod_1.z.string().describe('Topic for the collaboration session'),
580
- participants: zod_1.z.array(zod_1.z.enum(workflow_2.PREVC_ROLES))
581
- .optional()
582
- .describe('Roles to participate (auto-selected if not provided)')
583
- }
584
- }, async ({ topic, participants }) => {
585
- try {
586
- const service = new workflow_1.WorkflowService(repoPath);
587
- const session = await service.startCollaboration(topic, participants);
588
- const status = session.getStatus();
589
- return {
590
- content: [{
591
- type: 'text',
592
- text: JSON.stringify({
593
- success: true,
594
- message: `Collaboration session started: ${topic}`,
595
- sessionId: status.id,
596
- topic: status.topic,
597
- participants: status.participants.map((p) => ({
598
- role: p,
599
- displayName: workflow_2.ROLE_DISPLAY_NAMES[p],
600
- })),
601
- }, null, 2)
602
- }]
603
- };
604
- }
605
- catch (error) {
606
- return {
607
- content: [{
608
- type: 'text',
609
- text: JSON.stringify({
610
- success: false,
611
- error: error instanceof Error ? error.message : String(error)
612
- }, null, 2)
613
- }]
614
- };
615
- }
616
- });
617
- // workflowCreateDoc - Create a document for the current phase
618
- this.server.registerTool('workflowCreateDoc', {
619
- description: 'Create a document template for the current phase of the PREVC workflow.',
620
- inputSchema: {
621
- type: zod_1.z.enum(['prd', 'tech-spec', 'architecture', 'adr', 'test-plan', 'changelog'])
622
- .describe('Type of document to create'),
623
- name: zod_1.z.string().describe('Name/title for the document')
624
- }
625
- }, async ({ type, name }) => {
626
- try {
627
- const service = new workflow_1.WorkflowService(repoPath);
628
- if (!(await service.hasWorkflow())) {
629
- return {
630
- content: [{
631
- type: 'text',
632
- text: JSON.stringify({
633
- success: false,
634
- error: 'No workflow found. Run workflowInit first.'
635
- }, null, 2)
636
- }]
637
- };
638
- }
639
- // For now, return the document path that should be created
640
- const docPath = `.context/workflow/docs/${type}-${name.toLowerCase().replace(/\s+/g, '-')}.md`;
641
- return {
642
- content: [{
643
- type: 'text',
644
- text: JSON.stringify({
645
- success: true,
646
- message: `Document template ready: ${type}`,
647
- documentType: type,
648
- suggestedPath: docPath,
649
- name,
650
- }, null, 2)
651
- }]
652
- };
653
- }
654
- catch (error) {
655
- return {
656
- content: [{
657
- type: 'text',
658
- text: JSON.stringify({
659
- success: false,
660
- error: error instanceof Error ? error.message : String(error)
661
- }, null, 2)
662
- }]
663
- };
664
- }
665
- });
666
- this.log('Registered 6 workflow tools');
667
- // Register extended workflow tools (start, report, export, stack detection)
668
- this.registerExtendedWorkflowTools();
669
- }
670
- /**
671
- * Register extended workflow tools (start, report, export, stack detection)
672
- */
673
- registerExtendedWorkflowTools() {
674
- const repoPath = this.options.repoPath || process.cwd();
675
- // projectStart - Unified start command
676
- this.server.registerTool('projectStart', {
677
- description: 'Start a new project with unified setup: scaffolding + context fill + workflow initialization. Supports workflow templates (hotfix, feature, mvp).',
678
- inputSchema: {
679
- featureName: zod_1.z.string().describe('Feature/project name'),
680
- template: zod_1.z.enum(['hotfix', 'feature', 'mvp', 'auto']).optional()
681
- .describe('Workflow template (hotfix=quick fix, feature=standard, mvp=complete)'),
682
- skipFill: zod_1.z.boolean().optional().describe('Skip AI-assisted context filling'),
683
- skipWorkflow: zod_1.z.boolean().optional().describe('Skip workflow initialization'),
684
- }
685
- }, async ({ featureName, template, skipFill, skipWorkflow }) => {
686
- try {
687
- const startService = new start_1.StartService({
688
- ui: {
689
- displayOutput: () => { },
690
- displaySuccess: () => { },
691
- displayError: () => { },
692
- displayInfo: () => { },
693
- displayWarning: () => { },
694
- startSpinner: () => { },
695
- stopSpinner: () => { },
696
- updateSpinner: () => { },
697
- prompt: async () => '',
698
- confirm: async () => true,
699
- },
700
- t: (key) => key,
701
- version: version_1.VERSION,
702
- defaultModel: 'claude-3-5-sonnet-20241022',
703
- });
704
- const result = await startService.run(repoPath, {
705
- featureName,
706
- template: template,
707
- skipFill,
708
- skipWorkflow,
709
- });
710
- return {
711
- content: [{
712
- type: 'text',
713
- text: JSON.stringify({
714
- success: result.workflowStarted || result.initialized,
715
- initialized: result.initialized,
716
- filled: result.filled,
717
- workflowStarted: result.workflowStarted,
718
- scale: result.scale ? (0, workflow_2.getScaleName)(result.scale) : null,
719
- featureName: result.featureName,
720
- stack: result.stackDetected ? {
721
- primaryLanguage: result.stackDetected.primaryLanguage,
722
- frameworks: result.stackDetected.frameworks,
723
- } : null,
724
- }, null, 2)
725
- }]
726
- };
727
- }
728
- catch (error) {
729
- return {
730
- content: [{
731
- type: 'text',
732
- text: JSON.stringify({
733
- success: false,
734
- error: error instanceof Error ? error.message : String(error)
735
- }, null, 2)
736
- }]
737
- };
738
- }
739
- });
740
- // projectReport - Generate visual reports
741
- this.server.registerTool('projectReport', {
742
- description: 'Generate a visual progress report for the current PREVC workflow. Shows phases, roles, deliverables, and a visual dashboard.',
743
- inputSchema: {
744
- format: zod_1.z.enum(['json', 'markdown', 'dashboard']).default('dashboard').optional()
745
- .describe('Output format: json (raw data), markdown (formatted), dashboard (visual)'),
746
- includeStack: zod_1.z.boolean().optional().describe('Include technology stack info'),
747
- }
748
- }, async ({ format, includeStack }) => {
749
- try {
750
- const reportService = new report_1.ReportService({
751
- ui: {
752
- displayOutput: () => { },
753
- displaySuccess: () => { },
754
- displayError: () => { },
755
- displayInfo: () => { },
756
- displayWarning: () => { },
757
- startSpinner: () => { },
758
- stopSpinner: () => { },
759
- updateSpinner: () => { },
760
- },
761
- t: (key) => key,
762
- version: version_1.VERSION,
763
- });
764
- const report = await reportService.generate(repoPath, { includeStack });
765
- let output;
766
- if (format === 'json') {
767
- output = JSON.stringify(report, null, 2);
768
- }
769
- else if (format === 'dashboard') {
770
- output = reportService.generateVisualDashboard(report);
771
- }
772
- else {
773
- // Markdown format - use visual dashboard as fallback
774
- output = reportService.generateVisualDashboard(report);
775
- }
776
- return {
777
- content: [{
778
- type: 'text',
779
- text: output
780
- }]
781
- };
782
- }
783
- catch (error) {
784
- return {
785
- content: [{
786
- type: 'text',
787
- text: JSON.stringify({
788
- success: false,
789
- error: error instanceof Error ? error.message : String(error)
790
- }, null, 2)
791
- }]
792
- };
793
- }
794
- });
795
- // exportRules - Export rules to AI tools
796
- this.server.registerTool('exportRules', {
797
- description: 'Export context rules to AI tool directories (Cursor, Claude, GitHub Copilot, Windsurf, Cline, Aider, Codex). Bidirectional rules sync.',
798
- inputSchema: {
799
- preset: zod_1.z.enum(['cursor', 'claude', 'github', 'windsurf', 'cline', 'aider', 'codex', 'all']).default('all')
800
- .describe('Target AI tool preset or "all" for all supported tools'),
801
- force: zod_1.z.boolean().optional().describe('Overwrite existing files'),
802
- dryRun: zod_1.z.boolean().optional().describe('Preview changes without writing'),
803
- }
804
- }, async ({ preset, force, dryRun }) => {
805
- try {
806
- const exportService = new export_1.ExportRulesService({
807
- ui: {
808
- displayOutput: () => { },
809
- displaySuccess: () => { },
810
- displayError: () => { },
811
- displayInfo: () => { },
812
- displayWarning: () => { },
813
- startSpinner: () => { },
814
- stopSpinner: () => { },
815
- updateSpinner: () => { },
816
- },
817
- t: (key) => key,
818
- version: version_1.VERSION,
819
- });
820
- const result = await exportService.run(repoPath, { preset, force, dryRun });
821
- return {
822
- content: [{
823
- type: 'text',
824
- text: JSON.stringify({
825
- success: true,
826
- filesCreated: result.filesCreated,
827
- filesSkipped: result.filesSkipped,
828
- filesFailed: result.filesFailed,
829
- targets: result.targets,
830
- errors: result.errors,
831
- dryRun: dryRun || false,
832
- }, null, 2)
833
- }]
834
- };
835
- }
836
- catch (error) {
837
- return {
838
- content: [{
839
- type: 'text',
840
- text: JSON.stringify({
841
- success: false,
842
- error: error instanceof Error ? error.message : String(error)
843
- }, null, 2)
844
- }]
845
- };
846
- }
847
- });
848
- // detectStack - Detect project technology stack
849
- this.server.registerTool('detectStack', {
850
- description: 'Detect the project technology stack including languages, frameworks, build tools, and test frameworks. Useful for intelligent defaults.',
851
- inputSchema: {}
852
- }, async () => {
853
- try {
854
- const detector = new stack_1.StackDetector();
855
- const stackInfo = await detector.detect(repoPath);
856
- return {
857
- content: [{
858
- type: 'text',
859
- text: JSON.stringify({
860
- success: true,
861
- stack: stackInfo,
862
- }, null, 2)
863
- }]
864
- };
865
- }
866
- catch (error) {
867
- return {
868
- content: [{
869
- type: 'text',
870
- text: JSON.stringify({
871
- success: false,
872
- error: error instanceof Error ? error.message : String(error)
873
- }, null, 2)
874
- }]
875
- };
876
- }
877
- });
878
- this.log('Registered 4 extended workflow tools');
879
- // Register plan-workflow integration tools
880
- this.registerPlanTools();
881
- }
882
- /**
883
- * Register plan-workflow integration tools
884
- */
885
- registerPlanTools() {
886
- const repoPath = this.options.repoPath || process.cwd();
887
- // linkPlan - Link a plan to the current workflow
888
- this.server.registerTool('linkPlan', {
889
- description: 'Link an implementation plan to the current PREVC workflow. Plans provide detailed steps mapped to workflow phases.',
890
- inputSchema: {
891
- planSlug: zod_1.z.string().describe('Plan slug/identifier (filename without .md)'),
892
- }
893
- }, async ({ planSlug }) => {
894
- try {
895
- const linker = (0, workflow_2.createPlanLinker)(repoPath);
896
- const ref = await linker.linkPlan(planSlug);
897
- if (!ref) {
898
- return {
899
- content: [{
900
- type: 'text',
901
- text: JSON.stringify({
902
- success: false,
903
- error: `Plan not found: ${planSlug}`,
904
- }, null, 2)
905
- }]
906
- };
907
- }
908
- return {
909
- content: [{
910
- type: 'text',
911
- text: JSON.stringify({
912
- success: true,
913
- plan: ref,
914
- }, null, 2)
915
- }]
916
- };
917
- }
918
- catch (error) {
919
- return {
920
- content: [{
921
- type: 'text',
922
- text: JSON.stringify({
923
- success: false,
924
- error: error instanceof Error ? error.message : String(error)
925
- }, null, 2)
926
- }]
927
- };
928
- }
929
- });
930
- // getLinkedPlans - Get all plans linked to the workflow
931
- this.server.registerTool('getLinkedPlans', {
932
- description: 'Get all implementation plans linked to the current PREVC workflow.',
933
- inputSchema: {}
934
- }, async () => {
935
- try {
936
- const linker = (0, workflow_2.createPlanLinker)(repoPath);
937
- const plans = await linker.getLinkedPlans();
938
- return {
939
- content: [{
940
- type: 'text',
941
- text: JSON.stringify({
942
- success: true,
943
- plans,
944
- }, null, 2)
945
- }]
946
- };
947
- }
948
- catch (error) {
949
- return {
950
- content: [{
951
- type: 'text',
952
- text: JSON.stringify({
953
- success: false,
954
- error: error instanceof Error ? error.message : String(error)
955
- }, null, 2)
956
- }]
957
- };
958
- }
959
- });
960
- // getPlanDetails - Get detailed plan with PREVC mapping
961
- this.server.registerTool('getPlanDetails', {
962
- description: 'Get detailed plan information including phases mapped to PREVC, agents, and documentation.',
963
- inputSchema: {
964
- planSlug: zod_1.z.string().describe('Plan slug/identifier'),
965
- }
966
- }, async ({ planSlug }) => {
967
- try {
968
- const linker = (0, workflow_2.createPlanLinker)(repoPath);
969
- const plan = await linker.getLinkedPlan(planSlug);
970
- if (!plan) {
971
- return {
972
- content: [{
973
- type: 'text',
974
- text: JSON.stringify({
975
- success: false,
976
- error: `Plan not found or not linked: ${planSlug}`,
977
- }, null, 2)
978
- }]
979
- };
980
- }
981
- return {
982
- content: [{
983
- type: 'text',
984
- text: JSON.stringify({
985
- success: true,
986
- plan: {
987
- ...plan,
988
- phasesWithPrevc: plan.phases.map(p => ({
989
- ...p,
990
- prevcPhaseName: workflow_2.PHASE_NAMES_EN[p.prevcPhase],
991
- })),
992
- },
993
- }, null, 2)
994
- }]
995
- };
996
- }
997
- catch (error) {
998
- return {
999
- content: [{
1000
- type: 'text',
1001
- text: JSON.stringify({
1002
- success: false,
1003
- error: error instanceof Error ? error.message : String(error)
1004
- }, null, 2)
1005
- }]
1006
- };
1007
- }
1008
- });
1009
- // getPlansForPhase - Get plans relevant to current PREVC phase
1010
- this.server.registerTool('getPlansForPhase', {
1011
- description: 'Get all plans that have work items for a specific PREVC phase.',
1012
- inputSchema: {
1013
- phase: zod_1.z.enum(['P', 'R', 'E', 'V', 'C']).describe('PREVC phase'),
1014
- }
1015
- }, async ({ phase }) => {
1016
- try {
1017
- const linker = (0, workflow_2.createPlanLinker)(repoPath);
1018
- const plans = await linker.getPlansForPhase(phase);
1019
- return {
1020
- content: [{
1021
- type: 'text',
1022
- text: JSON.stringify({
1023
- success: true,
1024
- phase,
1025
- phaseName: workflow_2.PHASE_NAMES_EN[phase],
1026
- plans: plans.map(p => ({
1027
- slug: p.ref.slug,
1028
- title: p.ref.title,
1029
- phasesInThisPrevc: p.phases
1030
- .filter(ph => ph.prevcPhase === phase)
1031
- .map(ph => ({ id: ph.id, name: ph.name, status: ph.status })),
1032
- hasPendingWork: linker.hasPendingWorkForPhase(p, phase),
1033
- })),
1034
- }, null, 2)
1035
- }]
1036
- };
1037
- }
1038
- catch (error) {
1039
- return {
1040
- content: [{
1041
- type: 'text',
1042
- text: JSON.stringify({
1043
- success: false,
1044
- error: error instanceof Error ? error.message : String(error)
1045
- }, null, 2)
1046
- }]
1047
- };
1048
- }
1049
- });
1050
- // updatePlanPhase - Update plan phase status
1051
- this.server.registerTool('updatePlanPhase', {
1052
- description: 'Update the status of a plan phase (syncs with PREVC workflow tracking).',
1053
- inputSchema: {
1054
- planSlug: zod_1.z.string().describe('Plan slug/identifier'),
1055
- phaseId: zod_1.z.string().describe('Phase ID within the plan (e.g., "phase-1")'),
1056
- status: zod_1.z.enum(['pending', 'in_progress', 'completed', 'skipped']).describe('New status'),
1057
- }
1058
- }, async ({ planSlug, phaseId, status }) => {
1059
- try {
1060
- const linker = (0, workflow_2.createPlanLinker)(repoPath);
1061
- const success = await linker.updatePlanPhase(planSlug, phaseId, status);
1062
- return {
1063
- content: [{
1064
- type: 'text',
1065
- text: JSON.stringify({
1066
- success,
1067
- planSlug,
1068
- phaseId,
1069
- status,
1070
- }, null, 2)
1071
- }]
1072
- };
1073
- }
1074
- catch (error) {
1075
- return {
1076
- content: [{
1077
- type: 'text',
1078
- text: JSON.stringify({
1079
- success: false,
1080
- error: error instanceof Error ? error.message : String(error)
1081
- }, null, 2)
1082
- }]
1083
- };
1084
- }
1085
- });
1086
- // recordDecision - Record a decision in a plan
1087
- this.server.registerTool('recordDecision', {
1088
- description: 'Record a decision made during plan execution. Decisions are tracked and can be referenced later.',
1089
- inputSchema: {
1090
- planSlug: zod_1.z.string().describe('Plan slug/identifier'),
1091
- title: zod_1.z.string().describe('Decision title'),
1092
- description: zod_1.z.string().describe('Decision description and rationale'),
1093
- phase: zod_1.z.enum(['P', 'R', 'E', 'V', 'C']).optional().describe('Related PREVC phase'),
1094
- alternatives: zod_1.z.array(zod_1.z.string()).optional().describe('Alternatives that were considered'),
1095
- }
1096
- }, async ({ planSlug, title, description, phase, alternatives }) => {
1097
- try {
1098
- const linker = (0, workflow_2.createPlanLinker)(repoPath);
1099
- const decision = await linker.recordDecision(planSlug, {
1100
- title,
1101
- description,
1102
- phase: phase,
1103
- alternatives,
1104
- status: 'accepted',
1105
- });
1106
- return {
1107
- content: [{
1108
- type: 'text',
1109
- text: JSON.stringify({
1110
- success: true,
1111
- decision,
1112
- }, null, 2)
1113
- }]
1114
- };
1115
- }
1116
- catch (error) {
1117
- return {
1118
- content: [{
1119
- type: 'text',
1120
- text: JSON.stringify({
1121
- success: false,
1122
- error: error instanceof Error ? error.message : String(error)
1123
- }, null, 2)
1124
- }]
1125
- };
1126
- }
1127
- });
1128
- // discoverAgents - Discover all available agents (built-in + custom)
1129
- this.server.registerTool('discoverAgents', {
1130
- description: 'Discover all available agents including custom ones. Scans .context/agents/ for custom agent playbooks.',
1131
- inputSchema: {}
1132
- }, async () => {
1133
- try {
1134
- const linker = (0, workflow_2.createPlanLinker)(repoPath);
1135
- const agents = await linker.discoverAgents();
1136
- const builtIn = agents.filter(a => !a.isCustom);
1137
- const custom = agents.filter(a => a.isCustom);
1138
- return {
1139
- content: [{
1140
- type: 'text',
1141
- text: JSON.stringify({
1142
- success: true,
1143
- totalAgents: agents.length,
1144
- builtInCount: builtIn.length,
1145
- customCount: custom.length,
1146
- agents: {
1147
- builtIn: builtIn.map(a => a.type),
1148
- custom: custom.map(a => ({ type: a.type, path: a.path })),
1149
- },
1150
- }, null, 2)
1151
- }]
1152
- };
1153
- }
1154
- catch (error) {
1155
- return {
1156
- content: [{
1157
- type: 'text',
1158
- text: JSON.stringify({
1159
- success: false,
1160
- error: error instanceof Error ? error.message : String(error)
1161
- }, null, 2)
1162
- }]
1163
- };
1164
- }
5
+ * Exposes 9 tools (5 consolidated gateways + 4 dedicated workflow tools) for
6
+ * reduced context and simpler tool selection for AI agents.
7
+ *
8
+ * Simplified workflow: context init → fillSingle → workflow-init
9
+ */
10
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ var desc = Object.getOwnPropertyDescriptor(m, k);
13
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
14
+ desc = { enumerable: true, get: function() { return m[k]; } };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }) : (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ o[k2] = m[k];
20
+ }));
21
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
22
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
23
+ }) : function(o, v) {
24
+ o["default"] = v;
25
+ });
26
+ var __importStar = (this && this.__importStar) || (function () {
27
+ var ownKeys = function(o) {
28
+ ownKeys = Object.getOwnPropertyNames || function (o) {
29
+ var ar = [];
30
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
31
+ return ar;
32
+ };
33
+ return ownKeys(o);
34
+ };
35
+ return function (mod) {
36
+ if (mod && mod.__esModule) return mod;
37
+ var result = {};
38
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
39
+ __setModuleDefault(result, mod);
40
+ return result;
41
+ };
42
+ })();
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.AIContextMCPServer = void 0;
45
+ exports.startMCPServer = startMCPServer;
46
+ const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
47
+ const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
48
+ const zod_1 = require("zod");
49
+ const path = __importStar(require("path"));
50
+ const fs = __importStar(require("fs-extra"));
51
+ const tools_1 = require("../ai/tools");
52
+ const contextBuilder_1 = require("../semantic/contextBuilder");
53
+ const version_1 = require("../../version");
54
+ const workflow_1 = require("../workflow");
55
+ const actionLogger_1 = require("./actionLogger");
56
+ const workflow_2 = require("../../workflow");
57
+ const gatewayTools_1 = require("./gatewayTools");
58
+ class AIContextMCPServer {
59
+ constructor(options = {}) {
60
+ this.transport = null;
61
+ this.initialRepoPath = null;
62
+ this.cachedRepoPath = null;
63
+ this.options = {
64
+ name: 'ai-context',
65
+ verbose: false,
66
+ ...options
67
+ };
68
+ this.server = new mcp_js_1.McpServer({
69
+ name: this.options.name,
70
+ version: version_1.VERSION
1165
71
  });
1166
- // getAgentInfo - Get detailed info about a specific agent
1167
- this.server.registerTool('getAgentInfo', {
1168
- description: 'Get detailed information about a specific agent (built-in or custom). Returns path, existence status, title, and description.',
72
+ // Support dependency injection for testing, with default fallback
73
+ this.contextBuilder = options.contextBuilder ?? new contextBuilder_1.SemanticContextBuilder();
74
+ // Initialize and cache the correct repo path
75
+ void this.initializeRepoPath();
76
+ this.registerGatewayTools();
77
+ this.registerResources();
78
+ }
79
+ /**
80
+ * Register tools: 5 consolidated gateways + 4 dedicated workflow tools
81
+ * Total: 9 tools for clear entry points and reduced AI cognitive load
82
+ *
83
+ * Project tools removed - use context({ action: "init" }) + workflow-init instead
84
+ *
85
+ * NOTE: repoPath is now determined dynamically via getRepoPath() at runtime,
86
+ * which uses smart initialization and client path caching.
87
+ */
88
+ registerGatewayTools() {
89
+ const wrap = (toolName, handler) => this.wrapWithActionLogging(toolName, handler);
90
+ // Gateway 1: explore - File and code exploration
91
+ this.server.registerTool('explore', {
92
+ description: `File and code exploration. Actions:
93
+ - read: Read file contents (params: filePath, encoding?)
94
+ - list: List files matching pattern (params: pattern, cwd?, ignore?)
95
+ - analyze: Analyze symbols in a file (params: filePath, symbolTypes?)
96
+ - search: Search code with regex (params: pattern, fileGlob?, maxResults?, cwd?)
97
+ - getStructure: Get directory structure (params: rootPath?, maxDepth?, includePatterns?)`,
98
+ inputSchema: {
99
+ action: zod_1.z.enum(['read', 'list', 'analyze', 'search', 'getStructure'])
100
+ .describe('Action to perform'),
101
+ filePath: zod_1.z.string().optional()
102
+ .describe('(read, analyze) File path to read or analyze'),
103
+ pattern: zod_1.z.string().optional()
104
+ .describe('(list, search) Glob pattern for list, regex pattern for search'),
105
+ cwd: zod_1.z.string().optional()
106
+ .describe('(list, search) Working directory'),
107
+ encoding: zod_1.z.enum(['utf-8', 'ascii', 'binary']).optional()
108
+ .describe('(read) File encoding'),
109
+ ignore: zod_1.z.array(zod_1.z.string()).optional()
110
+ .describe('(list) Patterns to ignore'),
111
+ symbolTypes: zod_1.z.array(zod_1.z.enum(['class', 'interface', 'function', 'type', 'enum'])).optional()
112
+ .describe('(analyze) Types of symbols to extract'),
113
+ fileGlob: zod_1.z.string().optional()
114
+ .describe('(search) Glob pattern to filter files'),
115
+ maxResults: zod_1.z.number().optional()
116
+ .describe('(search) Maximum results to return'),
117
+ rootPath: zod_1.z.string().optional()
118
+ .describe('(getStructure) Root path for structure'),
119
+ maxDepth: zod_1.z.number().optional()
120
+ .describe('(getStructure) Maximum directory depth'),
121
+ includePatterns: zod_1.z.array(zod_1.z.string()).optional()
122
+ .describe('(getStructure) Include patterns'),
123
+ }
124
+ }, wrap('explore', async (params) => {
125
+ // explore uses cwd for file operations, not repoPath for context resolution
126
+ return (0, gatewayTools_1.handleExplore)(params, { repoPath: this.getRepoPath() });
127
+ }));
128
+ // Gateway 2: context - Context scaffolding and semantic context
129
+ this.server.registerTool('context', {
130
+ description: `Context scaffolding and semantic context. Actions:
131
+ - check: Check if .context scaffolding exists (params: repoPath?)
132
+ - init: Initialize .context scaffolding (params: repoPath?, type?, outputDir?, semantic?, autoFill?, skipContentGeneration?)
133
+ - fill: Fill scaffolding with AI content (params: repoPath?, outputDir?, target?, offset?, limit?)
134
+ - fillSingle: Fill a single scaffold file (params: repoPath?, filePath)
135
+ - listToFill: List files that need filling (params: repoPath?, outputDir?, target?)
136
+ - getMap: Get codebase map section (params: repoPath?, section?)
137
+ - buildSemantic: Build semantic context (params: repoPath?, contextType?, targetFile?, options?)
138
+ - scaffoldPlan: Create a plan template (params: planName, repoPath?, title?, summary?, autoFill?)
139
+
140
+ **Important:** Agents should provide repoPath on the FIRST call, then it will be cached:
141
+ 1. First call: context({ action: "check", repoPath: "/path/to/project" })
142
+ 2. Subsequent calls can omit repoPath - it will use cached value from step 1
143
+ 3. After context init, call fillSingle for each pending file
144
+ 4. Call workflow-init to enable PREVC workflow (unless trivial change)`,
145
+ inputSchema: {
146
+ action: zod_1.z.enum(['check', 'init', 'fill', 'fillSingle', 'listToFill', 'getMap', 'buildSemantic', 'scaffoldPlan'])
147
+ .describe('Action to perform'),
148
+ repoPath: zod_1.z.string().optional()
149
+ .describe('Repository path (defaults to cwd)'),
150
+ outputDir: zod_1.z.string().optional()
151
+ .describe('Output directory (default: ./.context)'),
152
+ type: zod_1.z.enum(['docs', 'agents', 'both']).optional()
153
+ .describe('(init) Type of scaffolding to create'),
154
+ semantic: zod_1.z.boolean().optional()
155
+ .describe('(init, scaffoldPlan) Enable semantic analysis'),
156
+ include: zod_1.z.array(zod_1.z.string()).optional()
157
+ .describe('(init) Include patterns'),
158
+ exclude: zod_1.z.array(zod_1.z.string()).optional()
159
+ .describe('(init) Exclude patterns'),
160
+ autoFill: zod_1.z.boolean().optional()
161
+ .describe('(init, scaffoldPlan) Auto-fill with codebase content'),
162
+ skipContentGeneration: zod_1.z.boolean().optional()
163
+ .describe('(init) Skip pre-generating content'),
164
+ target: zod_1.z.enum(['docs', 'agents', 'plans', 'all']).optional()
165
+ .describe('(fill, listToFill) Which scaffolding to target'),
166
+ offset: zod_1.z.number().optional()
167
+ .describe('(fill) Skip first N files'),
168
+ limit: zod_1.z.number().optional()
169
+ .describe('(fill) Max files to return'),
170
+ filePath: zod_1.z.string().optional()
171
+ .describe('(fillSingle) Absolute path to scaffold file'),
172
+ section: zod_1.z.enum([
173
+ 'all', 'stack', 'structure', 'architecture', 'symbols',
174
+ 'symbols.classes', 'symbols.interfaces', 'symbols.functions',
175
+ 'symbols.types', 'symbols.enums', 'publicAPI', 'dependencies', 'stats'
176
+ ]).optional()
177
+ .describe('(getMap) Section to retrieve'),
178
+ contextType: zod_1.z.enum(['documentation', 'playbook', 'plan', 'compact']).optional()
179
+ .describe('(buildSemantic) Type of context to build'),
180
+ targetFile: zod_1.z.string().optional()
181
+ .describe('(buildSemantic) Target file for focused context'),
182
+ options: zod_1.z.object({
183
+ useLSP: zod_1.z.boolean().optional(),
184
+ maxContextLength: zod_1.z.number().optional(),
185
+ includeDocumentation: zod_1.z.boolean().optional(),
186
+ includeSignatures: zod_1.z.boolean().optional()
187
+ }).optional()
188
+ .describe('(buildSemantic) Builder options'),
189
+ planName: zod_1.z.string().optional()
190
+ .describe('(scaffoldPlan) Name of the plan'),
191
+ title: zod_1.z.string().optional()
192
+ .describe('(scaffoldPlan) Plan title'),
193
+ summary: zod_1.z.string().optional()
194
+ .describe('(scaffoldPlan) Plan summary/goal'),
195
+ }
196
+ }, wrap('context', async (params) => {
197
+ return (0, gatewayTools_1.handleContext)(params, { repoPath: this.getRepoPath(params.repoPath), contextBuilder: this.contextBuilder });
198
+ }));
199
+ // Dedicated Workflow Tools (split from consolidated workflow gateway)
200
+ // Tool 3a: workflow-init - Initialize PREVC workflow
201
+ this.server.registerTool('workflow-init', {
202
+ description: `Initialize a PREVC workflow for structured development.
203
+
204
+ **What it does:**
205
+ - Creates .context/workflow/ folder (automatically, if it doesn't exist)
206
+ - Initializes workflow status file with phase tracking
207
+ - Detects project scale and configures gates
208
+ - Sets up PREVC phases (Plan → Review → Execute → Verify → Complete)
209
+
210
+ **Prerequisites:**
211
+ - .context/ folder must exist (use context with action "init" first)
212
+ - Scaffolding files should be filled (use context with action "fillSingle")
213
+
214
+ **When to use:**
215
+ - Starting a new feature or bug fix after scaffolding is set up
216
+ - Need structured, phase-gated development
217
+ - Working on non-trivial changes
218
+
219
+ **Don't use if:**
220
+ - Making trivial changes (typo fixes, single-line edits)
221
+ - Just exploring/researching code
222
+ - User explicitly wants to skip workflow`,
223
+ inputSchema: {
224
+ name: zod_1.z.string().describe('Workflow/feature name (required)'),
225
+ description: zod_1.z.string().optional()
226
+ .describe('Task description for scale detection'),
227
+ scale: zod_1.z.enum(['QUICK', 'SMALL', 'MEDIUM', 'LARGE']).optional()
228
+ .describe(`Project scale - AI should evaluate based on task characteristics:
229
+
230
+ SCALE EVALUATION CRITERIA:
231
+ • QUICK: Single file changes, bug fixes, typos (~5 min)
232
+ - Phases: E → V only
233
+ - Example: "Fix typo in button text"
234
+
235
+ • SMALL: Simple features, no architecture changes (~15 min)
236
+ - Phases: P → E → V
237
+ - Example: "Add email validation to form"
238
+
239
+ • MEDIUM: Regular features with design decisions (~30 min)
240
+ - Phases: P → R → E → V
241
+ - Example: "Implement user profile page"
242
+
243
+ • LARGE: Complex features, systems, compliance (~1+ hour)
244
+ - Phases: P → R → E → V → C (full workflow)
245
+ - Examples: "Build OAuth system", "Add GDPR compliance"
246
+
247
+ GUIDANCE:
248
+ - Analyze task complexity, architectural impact, and review needs
249
+ - Use LARGE for security/compliance requirements
250
+ - When uncertain, prefer MEDIUM
251
+ - Omit scale only if unable to evaluate (auto-detect fallback)`),
252
+ autonomous: zod_1.z.boolean().optional()
253
+ .describe('Skip all workflow gates (default: scale-dependent)'),
254
+ require_plan: zod_1.z.boolean().optional()
255
+ .describe('Require plan before P→R'),
256
+ require_approval: zod_1.z.boolean().optional()
257
+ .describe('Require approval before R→E'),
258
+ archive_previous: zod_1.z.boolean().optional()
259
+ .describe('Archive existing workflow'),
260
+ }
261
+ }, wrap('workflow-init', async (params) => {
262
+ return (0, gatewayTools_1.handleWorkflowInit)(params, { repoPath: this.getRepoPath(params.repoPath) });
263
+ }));
264
+ // Tool 3b: workflow-status - Get current workflow status
265
+ this.server.registerTool('workflow-status', {
266
+ description: `Get current PREVC workflow status including phase, gates, and linked plans.
267
+
268
+ Returns: Current phase, all phase statuses, gate settings, linked plans, agent activity.`,
269
+ inputSchema: {
270
+ // No required parameters
271
+ }
272
+ }, wrap('workflow-status', async (params) => {
273
+ return (0, gatewayTools_1.handleWorkflowStatus)(params, { repoPath: this.getRepoPath(params.repoPath) });
274
+ }));
275
+ // Tool 3c: workflow-advance - Advance to next phase
276
+ this.server.registerTool('workflow-advance', {
277
+ description: `Advance workflow to the next PREVC phase (P→R→E→V→C).
278
+
279
+ Enforces gates:
280
+ - P→R: Requires plan if require_plan=true
281
+ - R→E: Requires approval if require_approval=true
282
+
283
+ Use force=true to bypass gates, or use workflow-manage({ action: 'setAutonomous' }).`,
1169
284
  inputSchema: {
1170
- agentType: zod_1.z.string().describe('Agent type/identifier (e.g., "code-reviewer" or "agente-de-marketing")'),
1171
- }
1172
- }, async ({ agentType }) => {
1173
- try {
1174
- const linker = (0, workflow_2.createPlanLinker)(repoPath);
1175
- const info = await linker.getAgentInfo(agentType);
1176
- return {
1177
- content: [{
1178
- type: 'text',
1179
- text: JSON.stringify({
1180
- success: true,
1181
- agent: info,
1182
- }, null, 2)
1183
- }]
1184
- };
1185
- }
1186
- catch (error) {
1187
- return {
1188
- content: [{
1189
- type: 'text',
1190
- text: JSON.stringify({
1191
- success: false,
1192
- error: error instanceof Error ? error.message : String(error)
1193
- }, null, 2)
1194
- }]
1195
- };
1196
- }
1197
- });
1198
- this.log('Registered 8 plan-workflow tools');
285
+ outputs: zod_1.z.array(zod_1.z.string()).optional()
286
+ .describe('Artifact paths produced in current phase'),
287
+ force: zod_1.z.boolean().optional()
288
+ .describe('Force advancement even if gates block'),
289
+ }
290
+ }, wrap('workflow-advance', async (params) => {
291
+ return (0, gatewayTools_1.handleWorkflowAdvance)(params, { repoPath: this.getRepoPath(params.repoPath) });
292
+ }));
293
+ // Tool 3d: workflow-manage - Manage workflow operations
294
+ this.server.registerTool('workflow-manage', {
295
+ description: `Manage workflow operations: handoffs, collaboration, documents, gates, approvals.
296
+
297
+ Actions:
298
+ - handoff: Transfer work between agents (params: from, to, artifacts)
299
+ - collaborate: Start collaboration session (params: topic, participants?)
300
+ - createDoc: Create workflow document (params: type, docName)
301
+ - getGates: Check gate status
302
+ - approvePlan: Approve linked plan (params: planSlug?, approver?, notes?)
303
+ - setAutonomous: Toggle autonomous mode (params: enabled, reason?)`,
304
+ inputSchema: {
305
+ action: zod_1.z.enum(['handoff', 'collaborate', 'createDoc', 'getGates', 'approvePlan', 'setAutonomous'])
306
+ .describe('Action to perform'),
307
+ from: zod_1.z.string().optional()
308
+ .describe('(handoff) Agent handing off (e.g., feature-developer)'),
309
+ to: zod_1.z.string().optional()
310
+ .describe('(handoff) Agent receiving (e.g., code-reviewer)'),
311
+ artifacts: zod_1.z.array(zod_1.z.string()).optional()
312
+ .describe('(handoff) Artifacts to hand off'),
313
+ topic: zod_1.z.string().optional()
314
+ .describe('(collaborate) Collaboration topic'),
315
+ participants: zod_1.z.array(zod_1.z.enum(workflow_2.PREVC_ROLES)).optional()
316
+ .describe('(collaborate) Participating roles'),
317
+ type: zod_1.z.enum(['prd', 'tech-spec', 'architecture', 'adr', 'test-plan', 'changelog']).optional()
318
+ .describe('(createDoc) Document type'),
319
+ docName: zod_1.z.string().optional()
320
+ .describe('(createDoc) Document name'),
321
+ planSlug: zod_1.z.string().optional()
322
+ .describe('(approvePlan) Plan to approve'),
323
+ approver: zod_1.z.enum(workflow_2.PREVC_ROLES).optional()
324
+ .describe('(approvePlan) Approving role'),
325
+ notes: zod_1.z.string().optional()
326
+ .describe('(approvePlan) Approval notes'),
327
+ enabled: zod_1.z.boolean().optional()
328
+ .describe('(setAutonomous) Enable/disable'),
329
+ reason: zod_1.z.string().optional()
330
+ .describe('(setAutonomous) Reason for change'),
331
+ }
332
+ }, wrap('workflow-manage', async (params) => {
333
+ return (0, gatewayTools_1.handleWorkflowManage)(params, { repoPath: this.getRepoPath(params.repoPath) });
334
+ }));
335
+ // Gateway 5: sync - Import/export synchronization
336
+ this.server.registerTool('sync', {
337
+ description: `Import/export synchronization with AI tools. Actions:
338
+ - exportRules: Export rules to AI tools (params: preset?, force?, dryRun?)
339
+ - exportDocs: Export docs to AI tools (params: preset?, indexMode?, force?, dryRun?)
340
+ - exportAgents: Export agents to AI tools (params: preset?, mode?, force?, dryRun?)
341
+ - exportContext: Export all context (params: preset?, skipDocs?, skipAgents?, skipSkills?, docsIndexMode?, agentMode?, force?, dryRun?)
342
+ - exportSkills: Export skills to AI tools (params: preset?, includeBuiltIn?, force?)
343
+ - reverseSync: Import from AI tools to .context/ (params: skipRules?, skipAgents?, skipSkills?, mergeStrategy?, dryRun?, force?, addMetadata?)
344
+ - importDocs: Import docs from AI tools (params: autoDetect?, force?, dryRun?)
345
+ - importAgents: Import agents from AI tools (params: autoDetect?, force?, dryRun?)
346
+ - importSkills: Import skills from AI tools (params: autoDetect?, mergeStrategy?, force?, dryRun?)`,
347
+ inputSchema: {
348
+ action: zod_1.z.enum(['exportRules', 'exportDocs', 'exportAgents', 'exportContext', 'exportSkills', 'reverseSync', 'importDocs', 'importAgents', 'importSkills'])
349
+ .describe('Action to perform'),
350
+ preset: zod_1.z.string().optional()
351
+ .describe('Target AI tool preset'),
352
+ force: zod_1.z.boolean().optional()
353
+ .describe('Overwrite existing files'),
354
+ dryRun: zod_1.z.boolean().optional()
355
+ .describe('Preview without writing'),
356
+ indexMode: zod_1.z.enum(['readme', 'all']).optional()
357
+ .describe('(exportDocs) Index mode'),
358
+ mode: zod_1.z.enum(['symlink', 'markdown']).optional()
359
+ .describe('(exportAgents) Sync mode'),
360
+ skipDocs: zod_1.z.boolean().optional()
361
+ .describe('(exportContext) Skip docs'),
362
+ skipAgents: zod_1.z.boolean().optional()
363
+ .describe('(exportContext, reverseSync) Skip agents'),
364
+ skipSkills: zod_1.z.boolean().optional()
365
+ .describe('(exportContext, reverseSync) Skip skills'),
366
+ skipRules: zod_1.z.boolean().optional()
367
+ .describe('(reverseSync) Skip rules'),
368
+ docsIndexMode: zod_1.z.enum(['readme', 'all']).optional()
369
+ .describe('(exportContext) Docs index mode'),
370
+ agentMode: zod_1.z.enum(['symlink', 'markdown']).optional()
371
+ .describe('(exportContext) Agent sync mode'),
372
+ includeBuiltInSkills: zod_1.z.boolean().optional()
373
+ .describe('(exportContext) Include built-in skills'),
374
+ includeBuiltIn: zod_1.z.boolean().optional()
375
+ .describe('(exportSkills) Include built-in skills'),
376
+ mergeStrategy: zod_1.z.enum(['skip', 'overwrite', 'merge', 'rename']).optional()
377
+ .describe('(reverseSync, importSkills) Conflict handling'),
378
+ autoDetect: zod_1.z.boolean().optional()
379
+ .describe('(import*) Auto-detect files'),
380
+ addMetadata: zod_1.z.boolean().optional()
381
+ .describe('(reverseSync) Add frontmatter metadata'),
382
+ repoPath: zod_1.z.string().optional()
383
+ .describe('Repository path'),
384
+ }
385
+ }, wrap('sync', async (params) => {
386
+ return (0, gatewayTools_1.handleSync)(params, { repoPath: this.getRepoPath(params.repoPath) });
387
+ }));
388
+ // Gateway 6: plan - Plan management and execution tracking
389
+ this.server.registerTool('plan', {
390
+ description: `Plan management and execution tracking. Actions:
391
+ - link: Link plan to workflow (params: planSlug)
392
+ - getLinked: Get all linked plans
393
+ - getDetails: Get detailed plan info (params: planSlug)
394
+ - getForPhase: Get plans for PREVC phase (params: phase)
395
+ - updatePhase: Update plan phase status (params: planSlug, phaseId, status)
396
+ - recordDecision: Record a decision (params: planSlug, title, description, phase?, alternatives?)
397
+ - updateStep: Update step status (params: planSlug, phaseId, stepIndex, status, output?, notes?)
398
+ - getStatus: Get plan execution status (params: planSlug)
399
+ - syncMarkdown: Sync tracking to markdown (params: planSlug)
400
+ - commitPhase: Create git commit for completed phase (params: planSlug, phaseId, coAuthor?, stagePatterns?, dryRun?)`,
401
+ inputSchema: {
402
+ action: zod_1.z.enum(['link', 'getLinked', 'getDetails', 'getForPhase', 'updatePhase', 'recordDecision', 'updateStep', 'getStatus', 'syncMarkdown', 'commitPhase'])
403
+ .describe('Action to perform'),
404
+ planSlug: zod_1.z.string().optional()
405
+ .describe('Plan slug/identifier'),
406
+ phaseId: zod_1.z.string().optional()
407
+ .describe('(updatePhase, updateStep, commitPhase) Phase ID'),
408
+ status: zod_1.z.enum(['pending', 'in_progress', 'completed', 'skipped']).optional()
409
+ .describe('(updatePhase, updateStep) New status'),
410
+ phase: zod_1.z.enum(['P', 'R', 'E', 'V', 'C']).optional()
411
+ .describe('(getForPhase, recordDecision) PREVC phase'),
412
+ title: zod_1.z.string().optional()
413
+ .describe('(recordDecision) Decision title'),
414
+ description: zod_1.z.string().optional()
415
+ .describe('(recordDecision) Decision description'),
416
+ alternatives: zod_1.z.array(zod_1.z.string()).optional()
417
+ .describe('(recordDecision) Considered alternatives'),
418
+ stepIndex: zod_1.z.number().optional()
419
+ .describe('(updateStep) Step number (1-based)'),
420
+ output: zod_1.z.string().optional()
421
+ .describe('(updateStep) Step output artifact'),
422
+ notes: zod_1.z.string().optional()
423
+ .describe('(updateStep) Execution notes'),
424
+ coAuthor: zod_1.z.string().optional()
425
+ .describe('(commitPhase) Agent name for Co-Authored-By footer'),
426
+ stagePatterns: zod_1.z.array(zod_1.z.string()).optional()
427
+ .describe('(commitPhase) Patterns for files to stage (default: [".context/**"])'),
428
+ dryRun: zod_1.z.boolean().optional()
429
+ .describe('(commitPhase) Preview without committing'),
430
+ }
431
+ }, wrap('plan', async (params) => {
432
+ return (0, gatewayTools_1.handlePlan)(params, { repoPath: this.getRepoPath() });
433
+ }));
434
+ // Gateway 7: agent - Agent orchestration and discovery
435
+ this.server.registerTool('agent', {
436
+ description: `Agent orchestration and discovery. Actions:
437
+ - discover: Discover all agents (built-in + custom)
438
+ - getInfo: Get agent details (params: agentType)
439
+ - orchestrate: Select agents for task/phase/role (params: task?, phase?, role?)
440
+ - getSequence: Get agent handoff sequence (params: task, includeReview?, phases?)
441
+ - getDocs: Get agent documentation (params: agent)
442
+ - getPhaseDocs: Get phase documentation (params: phase)
443
+ - listTypes: List all agent types`,
444
+ inputSchema: {
445
+ action: zod_1.z.enum(['discover', 'getInfo', 'orchestrate', 'getSequence', 'getDocs', 'getPhaseDocs', 'listTypes'])
446
+ .describe('Action to perform'),
447
+ agentType: zod_1.z.string().optional()
448
+ .describe('(getInfo) Agent type identifier'),
449
+ task: zod_1.z.string().optional()
450
+ .describe('(orchestrate, getSequence) Task description'),
451
+ phase: zod_1.z.enum(['P', 'R', 'E', 'V', 'C']).optional()
452
+ .describe('(orchestrate, getPhaseDocs) PREVC phase'),
453
+ role: zod_1.z.enum(workflow_2.PREVC_ROLES).optional()
454
+ .describe('(orchestrate) PREVC role'),
455
+ includeReview: zod_1.z.boolean().optional()
456
+ .describe('(getSequence) Include code review'),
457
+ phases: zod_1.z.array(zod_1.z.enum(['P', 'R', 'E', 'V', 'C'])).optional()
458
+ .describe('(getSequence) Phases to include'),
459
+ agent: zod_1.z.enum(workflow_2.AGENT_TYPES).optional()
460
+ .describe('(getDocs) Agent type for docs'),
461
+ }
462
+ }, wrap('agent', async (params) => {
463
+ return (0, gatewayTools_1.handleAgent)(params, { repoPath: this.getRepoPath() });
464
+ }));
465
+ // Gateway 8: skill - Skill management
466
+ this.server.registerTool('skill', {
467
+ description: `Skill management for on-demand expertise. Actions:
468
+ - list: List all skills (params: includeContent?)
469
+ - getContent: Get skill content (params: skillSlug)
470
+ - getForPhase: Get skills for PREVC phase (params: phase)
471
+ - scaffold: Generate skill files (params: skills?, force?)
472
+ - export: Export skills to AI tools (params: preset?, includeBuiltIn?, force?)
473
+ - fill: Fill skills with codebase content (params: skills?, force?)`,
474
+ inputSchema: {
475
+ action: zod_1.z.enum(['list', 'getContent', 'getForPhase', 'scaffold', 'export', 'fill'])
476
+ .describe('Action to perform'),
477
+ skillSlug: zod_1.z.string().optional()
478
+ .describe('(getContent) Skill identifier'),
479
+ phase: zod_1.z.enum(['P', 'R', 'E', 'V', 'C']).optional()
480
+ .describe('(getForPhase) PREVC phase'),
481
+ skills: zod_1.z.array(zod_1.z.string()).optional()
482
+ .describe('(scaffold, fill) Specific skills to process'),
483
+ includeContent: zod_1.z.boolean().optional()
484
+ .describe('(list) Include full content'),
485
+ includeBuiltIn: zod_1.z.boolean().optional()
486
+ .describe('(export, fill) Include built-in skills'),
487
+ preset: zod_1.z.enum(['claude', 'gemini', 'codex', 'antigravity', 'all']).optional()
488
+ .describe('(export) Target AI tool'),
489
+ force: zod_1.z.boolean().optional()
490
+ .describe('(scaffold, export) Overwrite existing'),
491
+ }
492
+ }, wrap('skill', async (params) => {
493
+ return (0, gatewayTools_1.handleSkill)(params, { repoPath: this.getRepoPath() });
494
+ }));
495
+ this.log('Registered 9 tools (5 consolidated gateways + 4 dedicated workflow tools)');
1199
496
  }
1200
497
  /**
1201
498
  * Register semantic context resources
499
+ * Uses initialRepoPath if found, otherwise process.cwd()
1202
500
  */
1203
501
  registerResources() {
1204
- const repoPath = this.options.repoPath || process.cwd();
502
+ const repoPath = this.initialRepoPath ?? process.cwd();
1205
503
  // Register context resources as templates with URI patterns
1206
504
  this.server.registerResource('codebase-context', `context://codebase/{contextType}`, {
1207
505
  description: 'Semantic context for the codebase. Use contextType: documentation, playbook, plan, or compact',
@@ -1255,14 +553,13 @@ class AIContextMCPServer {
1255
553
  this.log('Registered 2 resource templates');
1256
554
  // Register PREVC workflow resources
1257
555
  this.registerWorkflowResources();
1258
- // Register orchestration tools
1259
- this.registerOrchestrationTools();
1260
556
  }
1261
557
  /**
1262
558
  * Register PREVC workflow resources
559
+ * Uses initialRepoPath if found, otherwise process.cwd()
1263
560
  */
1264
561
  registerWorkflowResources() {
1265
- const repoPath = this.options.repoPath || process.cwd();
562
+ const repoPath = this.initialRepoPath ?? process.cwd();
1266
563
  // workflow://status - Current workflow status
1267
564
  this.server.registerResource('workflow-status', 'workflow://status', {
1268
565
  description: 'Current PREVC workflow status including phases, roles, and progress',
@@ -1312,517 +609,161 @@ class AIContextMCPServer {
1312
609
  this.log('Registered 1 workflow resource');
1313
610
  }
1314
611
  /**
1315
- * Register agent orchestration tools
612
+ * Initialize repo path with smart detection and caching
613
+ *
614
+ * Strategy:
615
+ * 1. If explicit options.repoPath provided, try to find project root from there
616
+ * 2. Otherwise search upward from process.cwd() for .context or .git
617
+ * 3. Set as initialRepoPath if found (for resources)
618
+ * 4. First valid repoPath from client gets cached for all subsequent tool calls
619
+ * 5. Fallback to process.cwd() if nothing found (allows flexible MCP usage)
1316
620
  */
1317
- registerOrchestrationTools() {
1318
- // orchestrateAgents - Select agents for a task, phase, or role
1319
- this.server.registerTool('orchestrateAgents', {
1320
- description: 'Select appropriate agents based on task description, PREVC phase, or role. Returns recommended agents with their descriptions and relevant documentation.',
1321
- inputSchema: {
1322
- task: zod_1.z.string().optional().describe('Task description for intelligent agent selection'),
1323
- phase: zod_1.z.enum(['P', 'R', 'E', 'V', 'C']).optional().describe('PREVC phase to get agents for'),
1324
- role: zod_1.z.enum(workflow_2.PREVC_ROLES).optional().describe('PREVC role to get agents for'),
1325
- },
1326
- }, async ({ task, phase, role }) => {
1327
- try {
1328
- let agents = [];
1329
- let source = '';
1330
- if (task) {
1331
- agents = workflow_2.agentOrchestrator.selectAgentsByTask(task);
1332
- source = `task: "${task}"`;
1333
- }
1334
- else if (phase) {
1335
- agents = workflow_2.agentOrchestrator.getAgentsForPhase(phase);
1336
- source = `phase: ${phase} (${workflow_2.PHASE_NAMES_EN[phase]})`;
1337
- }
1338
- else if (role) {
1339
- agents = workflow_2.agentOrchestrator.getAgentsForRole(role);
1340
- source = `role: ${workflow_2.ROLE_DISPLAY_NAMES[role]}`;
1341
- }
1342
- else {
1343
- return {
1344
- content: [{ type: 'text', text: 'Error: Provide task, phase, or role parameter' }],
1345
- };
1346
- }
1347
- const agentDetails = agents.map((agent) => ({
1348
- type: agent,
1349
- description: workflow_2.agentOrchestrator.getAgentDescription(agent),
1350
- docs: workflow_2.documentLinker.getDocPathsForAgent(agent),
1351
- }));
1352
- return {
1353
- content: [{
1354
- type: 'text',
1355
- text: JSON.stringify({
1356
- source,
1357
- agents: agentDetails,
1358
- count: agents.length,
1359
- }, null, 2),
1360
- }],
1361
- };
1362
- }
1363
- catch (error) {
1364
- return {
1365
- content: [{
1366
- type: 'text',
1367
- text: `Error: ${error instanceof Error ? error.message : String(error)}`,
1368
- }],
1369
- };
1370
- }
1371
- });
1372
- // getAgentSequence - Get recommended agent sequence for a task
1373
- this.server.registerTool('getAgentSequence', {
1374
- description: 'Get recommended sequence of agents for a task, including handoff order. Useful for planning multi-agent workflows.',
1375
- inputSchema: {
1376
- task: zod_1.z.string().describe('Task description'),
1377
- includeReview: zod_1.z.boolean().optional().describe('Include code review in sequence (default: true)'),
1378
- phases: zod_1.z.array(zod_1.z.enum(['P', 'R', 'E', 'V', 'C'])).optional().describe('PREVC phases to include (for phase-based sequencing)'),
1379
- },
1380
- }, async ({ task, includeReview, phases }) => {
1381
- try {
1382
- let sequence;
1383
- if (phases && phases.length > 0) {
1384
- sequence = workflow_2.agentOrchestrator.getAgentHandoffSequence(phases);
1385
- }
1386
- else {
1387
- sequence = workflow_2.agentOrchestrator.getTaskAgentSequence(task, includeReview !== false);
1388
- }
1389
- const sequenceDetails = sequence.map((agent, index) => ({
1390
- order: index + 1,
1391
- agent,
1392
- description: workflow_2.agentOrchestrator.getAgentDescription(agent),
1393
- primaryDoc: workflow_2.documentLinker.getPrimaryDocForAgent(agent)?.path || null,
1394
- }));
1395
- return {
1396
- content: [{
1397
- type: 'text',
1398
- text: JSON.stringify({
1399
- task,
1400
- sequence: sequenceDetails,
1401
- totalAgents: sequence.length,
1402
- }, null, 2),
1403
- }],
1404
- };
1405
- }
1406
- catch (error) {
1407
- return {
1408
- content: [{
1409
- type: 'text',
1410
- text: `Error: ${error instanceof Error ? error.message : String(error)}`,
1411
- }],
1412
- };
1413
- }
1414
- });
1415
- // getAgentDocs - Get documentation relevant to an agent
1416
- this.server.registerTool('getAgentDocs', {
1417
- description: 'Get documentation guides relevant to a specific agent type. Helps agents find the right context.',
1418
- inputSchema: {
1419
- agent: zod_1.z.enum(workflow_2.AGENT_TYPES).describe('Agent type to get documentation for'),
1420
- },
1421
- }, async ({ agent }) => {
1422
- try {
1423
- if (!workflow_2.agentOrchestrator.isValidAgentType(agent)) {
1424
- return {
1425
- content: [{
1426
- type: 'text',
1427
- text: `Error: Invalid agent type "${agent}". Valid types: ${workflow_2.AGENT_TYPES.join(', ')}`,
1428
- }],
1429
- };
1430
- }
1431
- const docs = workflow_2.documentLinker.getDocsForAgent(agent);
1432
- const agentDesc = workflow_2.agentOrchestrator.getAgentDescription(agent);
1433
- return {
1434
- content: [{
1435
- type: 'text',
1436
- text: JSON.stringify({
1437
- agent,
1438
- description: agentDesc,
1439
- documentation: docs.map((doc) => ({
1440
- type: doc.type,
1441
- title: doc.title,
1442
- path: doc.path,
1443
- description: doc.description,
1444
- })),
1445
- }, null, 2),
1446
- }],
1447
- };
1448
- }
1449
- catch (error) {
1450
- return {
1451
- content: [{
1452
- type: 'text',
1453
- text: `Error: ${error instanceof Error ? error.message : String(error)}`,
1454
- }],
1455
- };
1456
- }
1457
- });
1458
- // getPhaseDocs - Get documentation for a PREVC phase
1459
- this.server.registerTool('getPhaseDocs', {
1460
- description: 'Get documentation relevant to a PREVC workflow phase. Helps understand what documentation is needed at each phase.',
1461
- inputSchema: {
1462
- phase: zod_1.z.enum(['P', 'R', 'E', 'V', 'C']).describe('PREVC phase (P=Planning, R=Review, E=Execution, V=Validation, C=Confirmation)'),
1463
- },
1464
- }, async ({ phase }) => {
1465
- try {
1466
- const docs = workflow_2.documentLinker.getDocsForPhase(phase);
1467
- const agents = workflow_2.agentOrchestrator.getAgentsForPhase(phase);
1468
- return {
1469
- content: [{
1470
- type: 'text',
1471
- text: JSON.stringify({
1472
- phase,
1473
- phaseName: workflow_2.PHASE_NAMES_EN[phase],
1474
- documentation: docs.map((doc) => ({
1475
- type: doc.type,
1476
- title: doc.title,
1477
- path: doc.path,
1478
- description: doc.description,
1479
- })),
1480
- recommendedAgents: agents.map((agent) => ({
1481
- type: agent,
1482
- description: workflow_2.agentOrchestrator.getAgentDescription(agent),
1483
- })),
1484
- }, null, 2),
1485
- }],
1486
- };
1487
- }
1488
- catch (error) {
1489
- return {
1490
- content: [{
1491
- type: 'text',
1492
- text: `Error: ${error instanceof Error ? error.message : String(error)}`,
1493
- }],
1494
- };
1495
- }
1496
- });
1497
- // listAgentTypes - List all available agent types
1498
- this.server.registerTool('listAgentTypes', {
1499
- description: 'List all available agent types with their descriptions. Use this to understand what agents are available.',
1500
- inputSchema: {},
1501
- }, async () => {
1502
- const agents = workflow_2.agentOrchestrator.getAllAgentTypes().map((agent) => ({
1503
- type: agent,
1504
- description: workflow_2.agentOrchestrator.getAgentDescription(agent),
1505
- primaryDoc: workflow_2.documentLinker.getPrimaryDocForAgent(agent)?.title || null,
1506
- }));
1507
- return {
1508
- content: [{
1509
- type: 'text',
1510
- text: JSON.stringify({
1511
- agents,
1512
- total: agents.length,
1513
- }, null, 2),
1514
- }],
1515
- };
1516
- });
1517
- this.log('Registered 5 orchestration tools');
1518
- // Register skill tools
1519
- this.registerSkillTools();
621
+ async initializeRepoPath() {
622
+ const startPath = this.options.repoPath || process.cwd();
623
+ const foundRoot = await this.findProjectRoot(startPath);
624
+ if (foundRoot) {
625
+ this.initialRepoPath = path.resolve(foundRoot);
626
+ this.log(`Server initialized with project root: ${this.initialRepoPath}`);
627
+ }
628
+ else {
629
+ // No project found - will use process.cwd() as fallback
630
+ // This allows flexible MCP server usage without strict project detection
631
+ this.initialRepoPath = null;
632
+ this.log(`No project root found. Will use process.cwd() or first valid client-provided path.`);
633
+ }
1520
634
  }
1521
635
  /**
1522
- * Register skill tools for on-demand expertise
636
+ * Find project root by searching upward for .context or .git
1523
637
  */
1524
- registerSkillTools() {
1525
- const repoPath = this.options.repoPath || process.cwd();
1526
- // Import skill registry
1527
- const { createSkillRegistry, BUILT_IN_SKILLS, SKILL_TO_PHASES } = require('../../workflow/skills');
1528
- // listSkills - List all available skills
1529
- this.server.registerTool('listSkills', {
1530
- description: 'List all available skills (built-in + custom). Skills are on-demand expertise for specific tasks.',
1531
- inputSchema: {
1532
- includeContent: zod_1.z.boolean().optional().describe('Include full skill content in response'),
1533
- }
1534
- }, async ({ includeContent }) => {
1535
- try {
1536
- const registry = createSkillRegistry(repoPath);
1537
- const discovered = await registry.discoverAll();
1538
- const format = (skill) => ({
1539
- slug: skill.slug,
1540
- name: skill.metadata.name,
1541
- description: skill.metadata.description,
1542
- phases: skill.metadata.phases || [],
1543
- isBuiltIn: skill.isBuiltIn,
1544
- ...(includeContent ? { content: skill.content } : {}),
1545
- });
1546
- return {
1547
- content: [{
1548
- type: 'text',
1549
- text: JSON.stringify({
1550
- success: true,
1551
- totalSkills: discovered.all.length,
1552
- builtInCount: discovered.builtIn.length,
1553
- customCount: discovered.custom.length,
1554
- skills: {
1555
- builtIn: discovered.builtIn.map(format),
1556
- custom: discovered.custom.map(format),
1557
- },
1558
- }, null, 2)
1559
- }]
1560
- };
1561
- }
1562
- catch (error) {
1563
- return {
1564
- content: [{
1565
- type: 'text',
1566
- text: JSON.stringify({
1567
- success: false,
1568
- error: error instanceof Error ? error.message : String(error)
1569
- }, null, 2)
1570
- }]
1571
- };
1572
- }
1573
- });
1574
- // getSkillContent - Get full content of a specific skill
1575
- this.server.registerTool('getSkillContent', {
1576
- description: 'Get the full content of a skill by slug. Returns the SKILL.md content with instructions.',
1577
- inputSchema: {
1578
- skillSlug: zod_1.z.string().describe('Skill slug/identifier (e.g., "commit-message", "pr-review")'),
1579
- }
1580
- }, async ({ skillSlug }) => {
1581
- try {
1582
- const registry = createSkillRegistry(repoPath);
1583
- const content = await registry.getSkillContent(skillSlug);
1584
- if (!content) {
1585
- return {
1586
- content: [{
1587
- type: 'text',
1588
- text: JSON.stringify({
1589
- success: false,
1590
- error: `Skill not found: ${skillSlug}`,
1591
- availableSkills: BUILT_IN_SKILLS,
1592
- }, null, 2)
1593
- }]
1594
- };
1595
- }
1596
- const skill = await registry.getSkillMetadata(skillSlug);
1597
- return {
1598
- content: [{
1599
- type: 'text',
1600
- text: JSON.stringify({
1601
- success: true,
1602
- skill: {
1603
- slug: skillSlug,
1604
- name: skill?.metadata.name,
1605
- description: skill?.metadata.description,
1606
- phases: skill?.metadata.phases,
1607
- isBuiltIn: skill?.isBuiltIn,
1608
- },
1609
- content,
1610
- }, null, 2)
1611
- }]
1612
- };
1613
- }
1614
- catch (error) {
1615
- return {
1616
- content: [{
1617
- type: 'text',
1618
- text: JSON.stringify({
1619
- success: false,
1620
- error: error instanceof Error ? error.message : String(error)
1621
- }, null, 2)
1622
- }]
1623
- };
1624
- }
1625
- });
1626
- // getSkillsForPhase - Get skills relevant to a PREVC phase
1627
- this.server.registerTool('getSkillsForPhase', {
1628
- description: 'Get all skills relevant to a specific PREVC phase. Useful for knowing which skills to activate during workflow execution.',
1629
- inputSchema: {
1630
- phase: zod_1.z.enum(['P', 'R', 'E', 'V', 'C']).describe('PREVC phase'),
1631
- }
1632
- }, async ({ phase }) => {
1633
- try {
1634
- const registry = createSkillRegistry(repoPath);
1635
- const skills = await registry.getSkillsForPhase(phase);
1636
- return {
1637
- content: [{
1638
- type: 'text',
1639
- text: JSON.stringify({
1640
- success: true,
1641
- phase,
1642
- phaseName: workflow_2.PHASE_NAMES_EN[phase],
1643
- skills: skills.map((s) => ({
1644
- slug: s.slug,
1645
- name: s.metadata.name,
1646
- description: s.metadata.description,
1647
- isBuiltIn: s.isBuiltIn,
1648
- })),
1649
- count: skills.length,
1650
- }, null, 2)
1651
- }]
1652
- };
1653
- }
1654
- catch (error) {
1655
- return {
1656
- content: [{
1657
- type: 'text',
1658
- text: JSON.stringify({
1659
- success: false,
1660
- error: error instanceof Error ? error.message : String(error)
1661
- }, null, 2)
1662
- }]
1663
- };
1664
- }
1665
- });
1666
- // scaffoldSkills - Generate skill files
1667
- this.server.registerTool('scaffoldSkills', {
1668
- description: 'Scaffold skill files in .context/skills/. Creates SKILL.md files for built-in or custom skills.',
1669
- inputSchema: {
1670
- skills: zod_1.z.array(zod_1.z.string()).optional().describe('Specific skills to scaffold (default: all built-in)'),
1671
- force: zod_1.z.boolean().optional().describe('Overwrite existing skill files'),
1672
- }
1673
- }, async ({ skills, force }) => {
638
+ async findProjectRoot(startPath) {
639
+ let currentPath = path.resolve(startPath);
640
+ const root = path.parse(currentPath).root;
641
+ // Search upward for .context or .git
642
+ while (currentPath !== root) {
643
+ if (await fs.pathExists(path.join(currentPath, '.context')) ||
644
+ await fs.pathExists(path.join(currentPath, '.git'))) {
645
+ return currentPath;
646
+ }
647
+ currentPath = path.dirname(currentPath);
648
+ }
649
+ // Not found
650
+ return null;
651
+ }
652
+ /**
653
+ * Cache a valid repoPath from client
654
+ * Only cache if it contains .context and we haven't cached yet
655
+ */
656
+ cacheRepoPathIfValid(repoPath) {
657
+ if (this.cachedRepoPath) {
658
+ return; // Already cached
659
+ }
660
+ const contextPath = path.join(repoPath, '.context');
661
+ if (fs.existsSync(contextPath)) {
662
+ this.cachedRepoPath = path.resolve(repoPath);
663
+ process.stderr.write(`[mcp] ✓ Cached repoPath for this session: ${this.cachedRepoPath}\n`);
664
+ this.log(`Cached valid repoPath: ${this.cachedRepoPath}`);
665
+ }
666
+ }
667
+ /**
668
+ * Get the effective repo path for a tool call
669
+ * Priority: 1) explicit param, 2) cached path, 3) initial path, 4) process.cwd()
670
+ */
671
+ getRepoPath(paramsRepoPath) {
672
+ if (paramsRepoPath) {
673
+ const resolved = path.resolve(paramsRepoPath);
674
+ this.cacheRepoPathIfValid(resolved);
675
+ return resolved;
676
+ }
677
+ if (this.cachedRepoPath) {
678
+ this.log(`Using cached repoPath: ${this.cachedRepoPath}`);
679
+ return this.cachedRepoPath;
680
+ }
681
+ if (this.initialRepoPath) {
682
+ this.log(`Using initial repoPath: ${this.initialRepoPath}`);
683
+ return this.initialRepoPath;
684
+ }
685
+ // Fallback to current working directory
686
+ const cwd = process.cwd();
687
+ this.log(`Using fallback cwd: ${cwd}`);
688
+ return cwd;
689
+ }
690
+ wrapWithActionLogging(toolName, handler) {
691
+ return async (params) => {
692
+ const resolvedRepoPath = this.getRepoPath(params?.repoPath);
693
+ const action = typeof params?.action === 'string'
694
+ ? params.action
695
+ : toolName;
1674
696
  try {
1675
- const { createSkillGenerator } = require('../../generators/skills');
1676
- const generator = createSkillGenerator({ repoPath });
1677
- const result = await generator.generate({ skills, force });
1678
- return {
1679
- content: [{
1680
- type: 'text',
1681
- text: JSON.stringify({
1682
- success: true,
1683
- skillsDir: result.skillsDir,
1684
- generated: result.generatedSkills,
1685
- skipped: result.skippedSkills,
1686
- indexPath: result.indexPath,
1687
- }, null, 2)
1688
- }]
1689
- };
697
+ const response = await handler(params);
698
+ await this.logToolResponse(resolvedRepoPath, toolName, action, params, response);
699
+ return response;
1690
700
  }
1691
701
  catch (error) {
1692
- return {
1693
- content: [{
1694
- type: 'text',
1695
- text: JSON.stringify({
1696
- success: false,
1697
- error: error instanceof Error ? error.message : String(error)
1698
- }, null, 2)
1699
- }]
1700
- };
702
+ await this.logToolError(resolvedRepoPath, toolName, action, params, error);
703
+ throw error;
1701
704
  }
705
+ };
706
+ }
707
+ async logToolResponse(repoPath, toolName, action, params, response) {
708
+ const payload = this.parseResponsePayload(response);
709
+ const success = typeof payload?.success === 'boolean'
710
+ ? payload.success
711
+ : !response.isError;
712
+ const errorMessage = typeof payload?.error === 'string' ? payload.error : undefined;
713
+ const resultSummary = payload ? this.buildResultSummary(payload) : undefined;
714
+ await (0, actionLogger_1.logMcpAction)(repoPath, {
715
+ tool: toolName,
716
+ action,
717
+ status: success ? 'success' : 'error',
718
+ details: {
719
+ params,
720
+ ...(resultSummary ? { result: resultSummary } : {}),
721
+ },
722
+ ...(success ? {} : { error: errorMessage || 'Tool reported failure' }),
1702
723
  });
1703
- // exportSkills - Export skills to AI tool directories
1704
- this.server.registerTool('exportSkills', {
1705
- description: 'Export skills to AI tool directories (Claude Code, Gemini CLI, Codex). Copies skills to .claude/skills/, .gemini/skills/, etc.',
1706
- inputSchema: {
1707
- preset: zod_1.z.enum(['claude', 'gemini', 'codex', 'all']).default('all')
1708
- .describe('Target AI tool or "all" for all supported tools'),
1709
- includeBuiltIn: zod_1.z.boolean().optional().describe('Include built-in skills even if not scaffolded'),
1710
- force: zod_1.z.boolean().optional().describe('Overwrite existing files'),
1711
- }
1712
- }, async ({ preset, includeBuiltIn, force }) => {
1713
- try {
1714
- const { SkillExportService } = require('../export/skillExportService');
1715
- const exportService = new SkillExportService({
1716
- ui: {
1717
- displayOutput: () => { },
1718
- displaySuccess: () => { },
1719
- displayError: () => { },
1720
- displayWarning: () => { },
1721
- startSpinner: () => { },
1722
- stopSpinner: () => { },
1723
- updateSpinner: () => { },
1724
- },
1725
- t: (key) => key,
1726
- version: version_1.VERSION,
1727
- });
1728
- const result = await exportService.run(repoPath, {
1729
- preset,
1730
- includeBuiltIn,
1731
- force,
1732
- });
1733
- return {
1734
- content: [{
1735
- type: 'text',
1736
- text: JSON.stringify({
1737
- success: result.filesCreated > 0,
1738
- targets: result.targets,
1739
- skillsExported: result.skillsExported,
1740
- filesCreated: result.filesCreated,
1741
- filesSkipped: result.filesSkipped,
1742
- }, null, 2)
1743
- }]
1744
- };
1745
- }
1746
- catch (error) {
1747
- return {
1748
- content: [{
1749
- type: 'text',
1750
- text: JSON.stringify({
1751
- success: false,
1752
- error: error instanceof Error ? error.message : String(error)
1753
- }, null, 2)
1754
- }]
1755
- };
1756
- }
724
+ }
725
+ async logToolError(repoPath, toolName, action, params, error) {
726
+ const message = error instanceof Error ? error.message : String(error);
727
+ await (0, actionLogger_1.logMcpAction)(repoPath, {
728
+ tool: toolName,
729
+ action,
730
+ status: 'error',
731
+ details: { params },
732
+ error: message,
1757
733
  });
1758
- // fillSkills - Fill/personalize skill files with AI
1759
- this.server.registerTool('fillSkills', {
1760
- description: 'Fill/personalize skill files using AI analysis of the codebase. Reads docs and agents for context.',
1761
- inputSchema: {
1762
- skills: zod_1.z.array(zod_1.z.string()).optional().describe('Specific skills to fill (default: all scaffolded)'),
1763
- force: zod_1.z.boolean().optional().describe('Overwrite existing content'),
1764
- useSemanticContext: zod_1.z.boolean().default(true).optional().describe('Use semantic context mode (more token efficient)'),
1765
- useLsp: zod_1.z.boolean().optional().describe('Enable LSP for deeper analysis'),
1766
- }
1767
- }, async ({ skills, force, useSemanticContext, useLsp }) => {
1768
- try {
1769
- const { SkillFillService } = require('../fill/skillFillService');
1770
- const skillFillService = new SkillFillService({
1771
- ui: {
1772
- displayWelcome: () => { },
1773
- displayProjectInfo: () => { },
1774
- displayStep: () => { },
1775
- displaySuccess: () => { },
1776
- displayError: () => { },
1777
- displayWarning: () => { },
1778
- displayInfo: () => { },
1779
- startSpinner: () => { },
1780
- stopSpinner: () => { },
1781
- updateSpinner: () => { },
1782
- createAgentCallbacks: () => ({
1783
- onAgentStart: () => { },
1784
- onAgentStep: () => { },
1785
- onAgentComplete: () => { },
1786
- onToolCall: () => { },
1787
- onToolResult: () => { },
1788
- }),
1789
- },
1790
- t: (key) => key,
1791
- version: version_1.VERSION,
1792
- defaultModel: DEFAULT_MODEL,
1793
- });
1794
- const result = await skillFillService.run(repoPath, {
1795
- skills,
1796
- force,
1797
- semantic: useSemanticContext ?? true,
1798
- useLsp,
1799
- });
1800
- return {
1801
- content: [{
1802
- type: 'text',
1803
- text: JSON.stringify({
1804
- success: true,
1805
- filled: result.filled,
1806
- skipped: result.skipped,
1807
- failed: result.failed,
1808
- model: result.model,
1809
- }, null, 2)
1810
- }]
1811
- };
1812
- }
1813
- catch (error) {
1814
- return {
1815
- content: [{
1816
- type: 'text',
1817
- text: JSON.stringify({
1818
- success: false,
1819
- error: error instanceof Error ? error.message : String(error)
1820
- }, null, 2)
1821
- }]
1822
- };
734
+ }
735
+ parseResponsePayload(response) {
736
+ const text = response.content?.[0]?.text;
737
+ if (!text)
738
+ return null;
739
+ try {
740
+ const parsed = JSON.parse(text);
741
+ return parsed && typeof parsed === 'object' ? parsed : null;
742
+ }
743
+ catch {
744
+ return null;
745
+ }
746
+ }
747
+ buildResultSummary(payload) {
748
+ const summaryKeys = [
749
+ 'success',
750
+ 'message',
751
+ 'currentPhase',
752
+ 'nextPhase',
753
+ 'phase',
754
+ 'scale',
755
+ 'planSlug',
756
+ 'count',
757
+ 'total',
758
+ 'status',
759
+ ];
760
+ const summary = {};
761
+ for (const key of summaryKeys) {
762
+ if (key in payload) {
763
+ summary[key] = payload[key];
1823
764
  }
1824
- });
1825
- this.log('Registered 6 skill tools');
765
+ }
766
+ return Object.keys(summary).length > 0 ? summary : null;
1826
767
  }
1827
768
  /**
1828
769
  * Start the MCP server with stdio transport