@bonesofspring/ai-rules 0.2.51 → 0.2.53

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 (376) hide show
  1. package/CHANGELOG.md +92 -0
  2. package/README.md +27 -3
  3. package/bin/cli.js +565 -61
  4. package/bin/lib/ai-local-drift.js +55 -14
  5. package/bin/lib/engine-scripts.js +10 -0
  6. package/bin/lib/mcp/clients.js +168 -0
  7. package/bin/lib/mcp/credentials.js +298 -0
  8. package/bin/lib/mcp/doctor.js +394 -0
  9. package/bin/lib/mcp/prompt.js +115 -0
  10. package/bin/lib/mcp/registry.js +170 -0
  11. package/bin/lib/mcp/run.js +123 -0
  12. package/bin/lib/merged-config.js +45 -0
  13. package/bin/lib/seed-ai-local-team.js +23 -7
  14. package/bin/lib/tool-installs.js +27 -0
  15. package/bin/mavis-install.js +2 -0
  16. package/bin/opencode-install.js +2 -0
  17. package/docs/LOCAL-OVERLAY.md +1 -1
  18. package/docs/MCP-SETUP.md +62 -0
  19. package/docs/PRESET-CONTRIBUTION.md +14 -10
  20. package/docs/TEAM-DB.md +173 -0
  21. package/docs/openapi/team-db.v1.json +5085 -0
  22. package/mcp/gitlab.mjs +123 -0
  23. package/mcp/lib/envfile.mjs +126 -0
  24. package/mcp/lib/yandex.mjs +384 -0
  25. package/mcp/yandex-mcp-proxy.mjs +155 -0
  26. package/mcp/yandex-token-refresh.mjs +65 -0
  27. package/package.json +18 -1
  28. package/presets/_shared/ai-local/scripts/manifest.mjs +112 -3
  29. package/presets/_shared/ai-local/scripts/rule-improver.mjs +428 -91
  30. package/presets/_shared/ai-local/scripts/run.mjs +22 -4
  31. package/presets/_shared/ai-local/scripts/signals.mjs +4 -1
  32. package/presets/_shared/ai-local/scripts/team-db-api.mjs +1275 -0
  33. package/presets/_shared/ai-local/scripts/team-db-dashboard.mjs +1067 -0
  34. package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +1301 -0
  35. package/presets/_shared/ai-local/scripts/team-db-project.mjs +1506 -0
  36. package/presets/_shared/ai-local/scripts/team-db-schema.mjs +831 -0
  37. package/presets/_shared/ai-local/scripts/team-db.mjs +251 -0
  38. package/presets/_shared/core/meta/preset-pr-checklist.md +1 -1
  39. package/presets/_shared/core/quality/interactive-questions.md +8 -8
  40. package/presets/_shared/hooks/chain-team-phases.sh.tmpl +109 -0
  41. package/presets/claude/android-kotlin/agents/code-reviewer.md +1 -0
  42. package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +109 -0
  43. package/presets/claude/android-kotlin/rules/tooling-and-review/interactive-questions.md +8 -8
  44. package/presets/claude/android-kotlin/rules/tooling-and-review/language-policy.md +1 -1
  45. package/presets/claude/android-kotlin/rules/tooling-and-review/preset-pr-checklist.md +1 -1
  46. package/presets/claude/android-kotlin/team/README.md +10 -0
  47. package/presets/claude/go/agents/code-reviewer.md +1 -0
  48. package/presets/claude/go/hooks/chain-team-phases.sh +109 -0
  49. package/presets/claude/go/rules/tooling-and-review/interactive-questions.md +8 -8
  50. package/presets/claude/go/rules/tooling-and-review/language-policy.md +1 -1
  51. package/presets/claude/go/rules/tooling-and-review/preset-pr-checklist.md +1 -1
  52. package/presets/claude/go/team/README.md +10 -0
  53. package/presets/claude/ios-swift/agents/code-reviewer.md +1 -0
  54. package/presets/claude/ios-swift/hooks/chain-team-phases.sh +109 -0
  55. package/presets/claude/ios-swift/rules/tooling-and-review/interactive-questions.md +8 -8
  56. package/presets/claude/ios-swift/rules/tooling-and-review/language-policy.md +1 -1
  57. package/presets/claude/ios-swift/rules/tooling-and-review/post-change-build.md +1 -1
  58. package/presets/claude/ios-swift/rules/tooling-and-review/preset-pr-checklist.md +1 -1
  59. package/presets/claude/ios-swift/team/README.md +10 -0
  60. package/presets/claude/java/agents/code-reviewer.md +1 -0
  61. package/presets/claude/java/hooks/chain-team-phases.sh +109 -0
  62. package/presets/claude/java/rules/tooling-and-review/interactive-questions.md +8 -8
  63. package/presets/claude/java/rules/tooling-and-review/language-policy.md +1 -1
  64. package/presets/claude/java/rules/tooling-and-review/preset-pr-checklist.md +1 -1
  65. package/presets/claude/java/team/README.md +10 -0
  66. package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +109 -0
  67. package/presets/claude/mcp-ts/rules/tooling-and-review/interactive-questions.md +8 -8
  68. package/presets/claude/mcp-ts/rules/tooling-and-review/language-policy.md +1 -1
  69. package/presets/claude/mcp-ts/rules/tooling-and-review/preset-pr-checklist.md +1 -1
  70. package/presets/claude/mcp-ts/team/README.md +10 -0
  71. package/presets/claude/next/MCP.md +7 -0
  72. package/presets/claude/next/README.md +1 -1
  73. package/presets/claude/next/REPO_AGENTS.md +1 -1
  74. package/presets/claude/next/agents/README.md +3 -3
  75. package/presets/claude/next/agents/build-verifier.md +9 -3
  76. package/presets/claude/next/agents/code-reviewer.md +2 -1
  77. package/presets/claude/next/agents/codebase-analyzer.md +1 -1
  78. package/presets/claude/next/agents/feature-developer.md +18 -8
  79. package/presets/claude/next/agents/openspec-author.md +1 -1
  80. package/presets/claude/next/agents/playwright-test-generator.md +22 -68
  81. package/presets/claude/next/agents/playwright-test-healer.md +27 -54
  82. package/presets/claude/next/agents/playwright-test-planner.md +18 -51
  83. package/presets/claude/next/agents/task-analyst.md +25 -9
  84. package/presets/claude/next/agents/task-router.md +1 -1
  85. package/presets/claude/next/agents/tech-writer.md +1 -1
  86. package/presets/claude/next/hooks/chain-team-phases.sh +109 -0
  87. package/presets/claude/next/mcp.json +3 -3
  88. package/presets/claude/next/rules/anti-hallucination/react-next-anti-hallucination.md +1 -1
  89. package/presets/claude/next/rules/architecture/layer-barrel-exports.md +1 -1
  90. package/presets/claude/next/rules/architecture/reference-features.md +1 -1
  91. package/presets/claude/next/rules/stack/navigation-router-ui.md +1 -1
  92. package/presets/claude/next/rules/stack/navigation-router.md +14 -0
  93. package/presets/claude/next/rules/stack/next-app-core.md +19 -17
  94. package/presets/claude/next/rules/stack/next-app-router.md +5 -17
  95. package/presets/claude/next/rules/stack/next-static-export.md +1 -1
  96. package/presets/claude/next/rules/tooling-and-review/interactive-questions.md +8 -8
  97. package/presets/claude/next/rules/tooling-and-review/language-policy.md +1 -1
  98. package/presets/claude/next/rules/tooling-and-review/post-change-lint.md +1 -1
  99. package/presets/claude/next/rules/tooling-and-review/preset-pr-checklist.md +1 -1
  100. package/presets/claude/next/rules/tooling-and-review/preset-token-budget.md +1 -1
  101. package/presets/claude/next/rules/tooling-and-review/security-next.md +28 -3
  102. package/presets/claude/next/rules/ui-and-accessibility/css-property-order.md +1 -1
  103. package/presets/claude/next/rules/ui-and-accessibility/design-tokens-binding.md +4 -4
  104. package/presets/claude/next/rules/ui-and-accessibility/forms-validation.md +2 -2
  105. package/presets/claude/next/team/README.md +21 -0
  106. package/presets/claude/next/team/fixtures/feature-with-figma-url.json +10 -0
  107. package/presets/claude/next/team/fixtures/feature-with-ux-no-figma.json +10 -0
  108. package/presets/claude/next/team/fixtures/mockup-review-standalone.json +9 -0
  109. package/presets/claude/next/team/fixtures/ux-design-standalone.json +9 -0
  110. package/presets/claude/nuxt/agents/code-reviewer.md +1 -0
  111. package/presets/claude/nuxt/hooks/chain-team-phases.sh +109 -0
  112. package/presets/claude/nuxt/rules/architecture/layer-barrel-exports.md +1 -1
  113. package/presets/claude/nuxt/rules/stack/navigation-router-ui.md +1 -1
  114. package/presets/claude/nuxt/rules/tooling-and-review/interactive-questions.md +8 -8
  115. package/presets/claude/nuxt/rules/tooling-and-review/language-policy.md +1 -1
  116. package/presets/claude/nuxt/rules/tooling-and-review/post-change-lint.md +1 -1
  117. package/presets/claude/nuxt/rules/tooling-and-review/preset-pr-checklist.md +1 -1
  118. package/presets/claude/nuxt/team/README.md +10 -0
  119. package/presets/claude/php-hexagonal/agents/code-reviewer.md +1 -0
  120. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +109 -0
  121. package/presets/claude/php-hexagonal/rules/tooling-and-review/interactive-questions.md +8 -8
  122. package/presets/claude/php-hexagonal/rules/tooling-and-review/language-policy.md +1 -1
  123. package/presets/claude/php-hexagonal/rules/tooling-and-review/preset-pr-checklist.md +1 -1
  124. package/presets/claude/php-hexagonal/team/README.md +10 -0
  125. package/presets/claude/php-laravel/agents/code-reviewer.md +1 -0
  126. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +109 -0
  127. package/presets/claude/php-laravel/rules/tooling-and-review/interactive-questions.md +8 -8
  128. package/presets/claude/php-laravel/rules/tooling-and-review/language-policy.md +1 -1
  129. package/presets/claude/php-laravel/rules/tooling-and-review/preset-pr-checklist.md +1 -1
  130. package/presets/claude/php-laravel/team/README.md +10 -0
  131. package/presets/claude/svelte/agents/code-reviewer.md +1 -0
  132. package/presets/claude/svelte/hooks/chain-team-phases.sh +109 -0
  133. package/presets/claude/svelte/rules/architecture/layer-barrel-exports.md +1 -1
  134. package/presets/claude/svelte/rules/tooling-and-review/interactive-questions.md +8 -8
  135. package/presets/claude/svelte/rules/tooling-and-review/language-policy.md +1 -1
  136. package/presets/claude/svelte/rules/tooling-and-review/post-change-lint.md +1 -1
  137. package/presets/claude/svelte/rules/tooling-and-review/preset-pr-checklist.md +1 -1
  138. package/presets/claude/svelte/team/README.md +10 -0
  139. package/presets/cursor/android-kotlin/agents/code-reviewer.md +1 -0
  140. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +109 -0
  141. package/presets/cursor/android-kotlin/rules/README.md +1 -0
  142. package/presets/cursor/android-kotlin/rules/agent-team-orchestrator.mdc +3 -3
  143. package/presets/cursor/android-kotlin/rules/interactive-questions.mdc +8 -8
  144. package/presets/cursor/android-kotlin/rules/preset-pr-checklist.mdc +1 -1
  145. package/presets/cursor/android-kotlin/team/README.md +10 -0
  146. package/presets/cursor/go/agents/code-reviewer.md +1 -0
  147. package/presets/cursor/go/hooks/chain-team-phases.sh +109 -0
  148. package/presets/cursor/go/rules/agent-team-orchestrator.mdc +2 -2
  149. package/presets/cursor/go/rules/interactive-questions.mdc +8 -8
  150. package/presets/cursor/go/rules/preset-pr-checklist.mdc +1 -1
  151. package/presets/cursor/go/team/README.md +10 -0
  152. package/presets/cursor/ios-swift/agents/code-reviewer.md +1 -0
  153. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +109 -0
  154. package/presets/cursor/ios-swift/rules/README.md +1 -0
  155. package/presets/cursor/ios-swift/rules/agent-team-orchestrator.mdc +3 -3
  156. package/presets/cursor/ios-swift/rules/interactive-questions.mdc +8 -8
  157. package/presets/cursor/ios-swift/rules/preset-pr-checklist.mdc +1 -1
  158. package/presets/cursor/ios-swift/team/README.md +10 -0
  159. package/presets/cursor/java/agents/code-reviewer.md +1 -0
  160. package/presets/cursor/java/hooks/chain-team-phases.sh +109 -0
  161. package/presets/cursor/java/rules/agent-team-orchestrator.mdc +2 -2
  162. package/presets/cursor/java/rules/interactive-questions.mdc +8 -8
  163. package/presets/cursor/java/rules/preset-pr-checklist.mdc +1 -1
  164. package/presets/cursor/java/team/README.md +10 -0
  165. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +109 -0
  166. package/presets/cursor/mcp-ts/rules/agent-team-orchestrator.mdc +2 -2
  167. package/presets/cursor/mcp-ts/rules/interactive-questions.mdc +8 -8
  168. package/presets/cursor/mcp-ts/rules/preset-pr-checklist.mdc +1 -1
  169. package/presets/cursor/mcp-ts/team/README.md +10 -0
  170. package/presets/cursor/next/MCP.md +14 -0
  171. package/presets/cursor/next/REPO_AGENTS.md +1 -1
  172. package/presets/cursor/next/agents/code-reviewer.md +1 -0
  173. package/presets/cursor/next/agents/playwright-test-healer.md +1 -0
  174. package/presets/cursor/next/ai-local/rules-library/router-pages.md +5 -5
  175. package/presets/cursor/next/hooks/chain-team-phases.sh +109 -0
  176. package/presets/cursor/next/mcp.json +3 -3
  177. package/presets/cursor/next/rules/README.md +1 -1
  178. package/presets/cursor/next/rules/agent-team-orchestrator.mdc +1 -1
  179. package/presets/cursor/next/rules/css-property-order-stylelint.mdc +1 -1
  180. package/presets/cursor/next/rules/design-tokens-binding.mdc +4 -4
  181. package/presets/cursor/next/rules/forms-validation.mdc +2 -2
  182. package/presets/cursor/next/rules/interactive-questions.mdc +8 -8
  183. package/presets/cursor/next/rules/navigation-router-stack.mdc +14 -1
  184. package/presets/cursor/next/rules/next-app-core.mdc +19 -17
  185. package/presets/cursor/next/rules/next-app-router.mdc +5 -17
  186. package/presets/cursor/next/rules/next-static-export.mdc +1 -1
  187. package/presets/cursor/next/rules/preset-pr-checklist.mdc +1 -1
  188. package/presets/cursor/next/rules/preset-token-budget.mdc +1 -1
  189. package/presets/cursor/next/rules/react-next-anti-hallucination.mdc +1 -1
  190. package/presets/cursor/next/rules/reference-features.mdc +1 -1
  191. package/presets/cursor/next/rules/security-next.mdc +28 -3
  192. package/presets/cursor/next/team/README.md +21 -0
  193. package/presets/cursor/next/team/fixtures/feature-with-figma-url.json +10 -0
  194. package/presets/cursor/next/team/fixtures/feature-with-ux-no-figma.json +10 -0
  195. package/presets/cursor/next/team/fixtures/mockup-review-standalone.json +9 -0
  196. package/presets/cursor/next/team/fixtures/ux-design-standalone.json +9 -0
  197. package/presets/cursor/nuxt/agents/code-reviewer.md +1 -0
  198. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +109 -0
  199. package/presets/cursor/nuxt/rules/agent-team-orchestrator.mdc +1 -1
  200. package/presets/cursor/nuxt/rules/interactive-questions.mdc +8 -8
  201. package/presets/cursor/nuxt/rules/preset-pr-checklist.mdc +1 -1
  202. package/presets/cursor/nuxt/team/README.md +10 -0
  203. package/presets/cursor/php-hexagonal/agents/code-reviewer.md +1 -0
  204. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +109 -0
  205. package/presets/cursor/php-hexagonal/rules/agent-team-orchestrator.mdc +2 -2
  206. package/presets/cursor/php-hexagonal/rules/interactive-questions.mdc +8 -8
  207. package/presets/cursor/php-hexagonal/rules/preset-pr-checklist.mdc +1 -1
  208. package/presets/cursor/php-hexagonal/team/README.md +10 -0
  209. package/presets/cursor/php-laravel/agents/code-reviewer.md +1 -0
  210. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +109 -0
  211. package/presets/cursor/php-laravel/rules/agent-team-orchestrator.mdc +2 -2
  212. package/presets/cursor/php-laravel/rules/interactive-questions.mdc +8 -8
  213. package/presets/cursor/php-laravel/rules/preset-pr-checklist.mdc +1 -1
  214. package/presets/cursor/php-laravel/team/README.md +10 -0
  215. package/presets/cursor/svelte/agents/code-reviewer.md +1 -0
  216. package/presets/cursor/svelte/hooks/chain-team-phases.sh +109 -0
  217. package/presets/cursor/svelte/rules/agent-team-orchestrator.mdc +1 -1
  218. package/presets/cursor/svelte/rules/interactive-questions.mdc +8 -8
  219. package/presets/cursor/svelte/rules/preset-pr-checklist.mdc +1 -1
  220. package/presets/cursor/svelte/team/README.md +10 -0
  221. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  222. package/presets/mavis/android-kotlin/agents/code-reviewer.md +1 -0
  223. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +109 -0
  224. package/presets/mavis/android-kotlin/rules/interactive-questions.md +8 -8
  225. package/presets/mavis/android-kotlin/rules/preset-pr-checklist.md +1 -1
  226. package/presets/mavis/android-kotlin/team/README.md +10 -0
  227. package/presets/mavis/go/adapter-map.json +1 -1
  228. package/presets/mavis/go/agents/code-reviewer.md +1 -0
  229. package/presets/mavis/go/hooks/chain-team-phases.sh +109 -0
  230. package/presets/mavis/go/rules/interactive-questions.md +8 -8
  231. package/presets/mavis/go/rules/preset-pr-checklist.md +1 -1
  232. package/presets/mavis/go/team/README.md +10 -0
  233. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  234. package/presets/mavis/ios-swift/agents/code-reviewer.md +1 -0
  235. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +109 -0
  236. package/presets/mavis/ios-swift/rules/interactive-questions.md +8 -8
  237. package/presets/mavis/ios-swift/rules/preset-pr-checklist.md +1 -1
  238. package/presets/mavis/ios-swift/team/README.md +10 -0
  239. package/presets/mavis/java/adapter-map.json +1 -1
  240. package/presets/mavis/java/agents/code-reviewer.md +1 -0
  241. package/presets/mavis/java/hooks/chain-team-phases.sh +109 -0
  242. package/presets/mavis/java/rules/interactive-questions.md +8 -8
  243. package/presets/mavis/java/rules/preset-pr-checklist.md +1 -1
  244. package/presets/mavis/java/team/README.md +10 -0
  245. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  246. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +109 -0
  247. package/presets/mavis/mcp-ts/rules/interactive-questions.md +8 -8
  248. package/presets/mavis/mcp-ts/rules/preset-pr-checklist.md +1 -1
  249. package/presets/mavis/mcp-ts/team/README.md +10 -0
  250. package/presets/mavis/next/MCP.md +14 -0
  251. package/presets/mavis/next/REPO_AGENTS.md +1 -1
  252. package/presets/mavis/next/adapter-map.json +1 -1
  253. package/presets/mavis/next/agents/code-reviewer.md +1 -0
  254. package/presets/mavis/next/agents/playwright-test-healer.md +1 -0
  255. package/presets/mavis/next/ai-local/rules-library/router-pages.md +5 -5
  256. package/presets/mavis/next/hooks/chain-team-phases.sh +109 -0
  257. package/presets/mavis/next/mcp.json +3 -3
  258. package/presets/mavis/next/rules/css-property-order-stylelint.md +1 -1
  259. package/presets/mavis/next/rules/design-tokens-binding.md +4 -4
  260. package/presets/mavis/next/rules/forms-validation.md +2 -2
  261. package/presets/mavis/next/rules/interactive-questions.md +8 -8
  262. package/presets/mavis/next/rules/navigation-router-stack.md +12 -0
  263. package/presets/mavis/next/rules/next-app-core.md +18 -17
  264. package/presets/mavis/next/rules/next-app-router.md +4 -17
  265. package/presets/mavis/next/rules/next-static-export.md +1 -1
  266. package/presets/mavis/next/rules/preset-pr-checklist.md +1 -1
  267. package/presets/mavis/next/rules/react-next-anti-hallucination.md +1 -1
  268. package/presets/mavis/next/rules/reference-features.md +1 -1
  269. package/presets/mavis/next/rules/security-next.md +24 -3
  270. package/presets/mavis/next/team/README.md +21 -0
  271. package/presets/mavis/next/team/fixtures/feature-with-figma-url.json +10 -0
  272. package/presets/mavis/next/team/fixtures/feature-with-ux-no-figma.json +10 -0
  273. package/presets/mavis/next/team/fixtures/mockup-review-standalone.json +9 -0
  274. package/presets/mavis/next/team/fixtures/ux-design-standalone.json +9 -0
  275. package/presets/mavis/nuxt/adapter-map.json +1 -1
  276. package/presets/mavis/nuxt/agents/code-reviewer.md +1 -0
  277. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +109 -0
  278. package/presets/mavis/nuxt/rules/interactive-questions.md +8 -8
  279. package/presets/mavis/nuxt/rules/preset-pr-checklist.md +1 -1
  280. package/presets/mavis/nuxt/team/README.md +10 -0
  281. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  282. package/presets/mavis/php-hexagonal/agents/code-reviewer.md +1 -0
  283. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +109 -0
  284. package/presets/mavis/php-hexagonal/rules/interactive-questions.md +8 -8
  285. package/presets/mavis/php-hexagonal/rules/preset-pr-checklist.md +1 -1
  286. package/presets/mavis/php-hexagonal/team/README.md +10 -0
  287. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  288. package/presets/mavis/php-laravel/agents/code-reviewer.md +1 -0
  289. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +109 -0
  290. package/presets/mavis/php-laravel/rules/interactive-questions.md +8 -8
  291. package/presets/mavis/php-laravel/rules/preset-pr-checklist.md +1 -1
  292. package/presets/mavis/php-laravel/team/README.md +10 -0
  293. package/presets/mavis/svelte/adapter-map.json +1 -1
  294. package/presets/mavis/svelte/agents/code-reviewer.md +1 -0
  295. package/presets/mavis/svelte/hooks/chain-team-phases.sh +109 -0
  296. package/presets/mavis/svelte/rules/interactive-questions.md +8 -8
  297. package/presets/mavis/svelte/rules/preset-pr-checklist.md +1 -1
  298. package/presets/mavis/svelte/team/README.md +10 -0
  299. package/presets/opencode/android-kotlin/adapter-map.json +1 -1
  300. package/presets/opencode/android-kotlin/agents/code-reviewer.md +1 -0
  301. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +109 -0
  302. package/presets/opencode/android-kotlin/rules/interactive-questions.md +8 -8
  303. package/presets/opencode/android-kotlin/rules/preset-pr-checklist.md +1 -1
  304. package/presets/opencode/android-kotlin/team/README.md +10 -0
  305. package/presets/opencode/go/adapter-map.json +1 -1
  306. package/presets/opencode/go/agents/code-reviewer.md +1 -0
  307. package/presets/opencode/go/hooks/chain-team-phases.sh +109 -0
  308. package/presets/opencode/go/rules/interactive-questions.md +8 -8
  309. package/presets/opencode/go/rules/preset-pr-checklist.md +1 -1
  310. package/presets/opencode/go/team/README.md +10 -0
  311. package/presets/opencode/ios-swift/adapter-map.json +1 -1
  312. package/presets/opencode/ios-swift/agents/code-reviewer.md +1 -0
  313. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +109 -0
  314. package/presets/opencode/ios-swift/rules/interactive-questions.md +8 -8
  315. package/presets/opencode/ios-swift/rules/preset-pr-checklist.md +1 -1
  316. package/presets/opencode/ios-swift/team/README.md +10 -0
  317. package/presets/opencode/java/adapter-map.json +1 -1
  318. package/presets/opencode/java/agents/code-reviewer.md +1 -0
  319. package/presets/opencode/java/hooks/chain-team-phases.sh +109 -0
  320. package/presets/opencode/java/rules/interactive-questions.md +8 -8
  321. package/presets/opencode/java/rules/preset-pr-checklist.md +1 -1
  322. package/presets/opencode/java/team/README.md +10 -0
  323. package/presets/opencode/mcp-ts/adapter-map.json +1 -1
  324. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +109 -0
  325. package/presets/opencode/mcp-ts/rules/interactive-questions.md +8 -8
  326. package/presets/opencode/mcp-ts/rules/preset-pr-checklist.md +1 -1
  327. package/presets/opencode/mcp-ts/team/README.md +10 -0
  328. package/presets/opencode/next/MCP.md +14 -0
  329. package/presets/opencode/next/REPO_AGENTS.md +1 -1
  330. package/presets/opencode/next/adapter-map.json +1 -1
  331. package/presets/opencode/next/agents/code-reviewer.md +1 -0
  332. package/presets/opencode/next/agents/playwright-test-healer.md +1 -0
  333. package/presets/opencode/next/ai-local/rules-library/router-pages.md +5 -5
  334. package/presets/opencode/next/hooks/chain-team-phases.sh +109 -0
  335. package/presets/opencode/next/opencode.json +3 -3
  336. package/presets/opencode/next/rules/css-property-order-stylelint.md +1 -1
  337. package/presets/opencode/next/rules/design-tokens-binding.md +4 -4
  338. package/presets/opencode/next/rules/forms-validation.md +2 -2
  339. package/presets/opencode/next/rules/interactive-questions.md +8 -8
  340. package/presets/opencode/next/rules/navigation-router-stack.md +12 -0
  341. package/presets/opencode/next/rules/next-app-core.md +18 -17
  342. package/presets/opencode/next/rules/next-app-router.md +4 -17
  343. package/presets/opencode/next/rules/next-static-export.md +1 -1
  344. package/presets/opencode/next/rules/preset-pr-checklist.md +1 -1
  345. package/presets/opencode/next/rules/react-next-anti-hallucination.md +1 -1
  346. package/presets/opencode/next/rules/reference-features.md +1 -1
  347. package/presets/opencode/next/rules/security-next.md +24 -3
  348. package/presets/opencode/next/team/README.md +21 -0
  349. package/presets/opencode/next/team/fixtures/feature-with-figma-url.json +10 -0
  350. package/presets/opencode/next/team/fixtures/feature-with-ux-no-figma.json +10 -0
  351. package/presets/opencode/next/team/fixtures/mockup-review-standalone.json +9 -0
  352. package/presets/opencode/next/team/fixtures/ux-design-standalone.json +9 -0
  353. package/presets/opencode/nuxt/adapter-map.json +1 -1
  354. package/presets/opencode/nuxt/agents/code-reviewer.md +1 -0
  355. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +109 -0
  356. package/presets/opencode/nuxt/rules/interactive-questions.md +8 -8
  357. package/presets/opencode/nuxt/rules/preset-pr-checklist.md +1 -1
  358. package/presets/opencode/nuxt/team/README.md +10 -0
  359. package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
  360. package/presets/opencode/php-hexagonal/agents/code-reviewer.md +1 -0
  361. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +109 -0
  362. package/presets/opencode/php-hexagonal/rules/interactive-questions.md +8 -8
  363. package/presets/opencode/php-hexagonal/rules/preset-pr-checklist.md +1 -1
  364. package/presets/opencode/php-hexagonal/team/README.md +10 -0
  365. package/presets/opencode/php-laravel/adapter-map.json +1 -1
  366. package/presets/opencode/php-laravel/agents/code-reviewer.md +1 -0
  367. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +109 -0
  368. package/presets/opencode/php-laravel/rules/interactive-questions.md +8 -8
  369. package/presets/opencode/php-laravel/rules/preset-pr-checklist.md +1 -1
  370. package/presets/opencode/php-laravel/team/README.md +10 -0
  371. package/presets/opencode/svelte/adapter-map.json +1 -1
  372. package/presets/opencode/svelte/agents/code-reviewer.md +1 -0
  373. package/presets/opencode/svelte/hooks/chain-team-phases.sh +109 -0
  374. package/presets/opencode/svelte/rules/interactive-questions.md +8 -8
  375. package/presets/opencode/svelte/rules/preset-pr-checklist.md +1 -1
  376. package/presets/opencode/svelte/team/README.md +10 -0
@@ -0,0 +1,394 @@
1
+ /**
2
+ * `ai-rules mcp doctor`: four areas per server (runtime, registration,
3
+ * credentials, upstream), one next command per failing check, no token output.
4
+ * Reads the client configs and the credential files directly — no state file.
5
+ */
6
+ const fs = require('fs');
7
+ const path = require('path');
8
+ const { spawnSync } = require('child_process');
9
+ const { resolveManagedPath } = require('../safe-path');
10
+ const { isPlainObject } = require('../fs-utils');
11
+ const { TOOL_INSTALL_MARKERS } = require('../tool-installs');
12
+ const { assertNodeFloor, resolveProjectRootDetailed } = require('./run');
13
+ const { detectClientIds, readClientConfig } = require('./clients');
14
+ const { checkIgnored, CREDENTIALS_REL, CONFIG_REL } = require('./credentials');
15
+ const { ownsEntry, registeredPin, tokenFinding } = require('./registry');
16
+
17
+ const AREAS = ['runtime', 'registration', 'credentials', 'upstream'];
18
+
19
+ function oneLine(text) {
20
+ return String(text).replace(/\s+/g, ' ').trim();
21
+ }
22
+
23
+ let npxCached = null;
24
+
25
+ function npxResolves() {
26
+ if (npxCached !== null) {
27
+ return npxCached;
28
+ }
29
+ const npx = process.platform === 'win32' ? 'npx.cmd' : 'npx';
30
+ if (spawnSync(npx, ['--version'], { stdio: 'ignore' }).status === 0) {
31
+ npxCached = true;
32
+ return npxCached;
33
+ }
34
+ const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
35
+ npxCached = spawnSync(npm, ['--version'], { stdio: 'ignore' }).status === 0;
36
+ return npxCached;
37
+ }
38
+
39
+ function firstWith(statuses, status) {
40
+ return statuses.find((entry) => entry.status === status);
41
+ }
42
+
43
+ function unwrap(statuses) {
44
+ const status = firstWith(statuses, 'fail')
45
+ ?? firstWith(statuses, 'warn')
46
+ ?? firstWith(statuses, 'skipped')
47
+ ?? statuses[0]
48
+ ?? { status: 'ok', detail: 'ok' };
49
+ return {
50
+ status: status.status,
51
+ detail: statuses.map((entry) => entry.detail).filter(Boolean).join('; '),
52
+ next: status.next,
53
+ kind: status.kind,
54
+ };
55
+ }
56
+
57
+ async function checkGitlabCredentials(cwd, envfile) {
58
+ const abs = resolveManagedPath(cwd, CREDENTIALS_REL);
59
+ const fail = (detail) => ({ status: 'fail', detail, next: 'ai-rules mcp setup gitlab' });
60
+ if (!abs || !fs.existsSync(abs)) {
61
+ return fail(`${CREDENTIALS_REL} is missing`);
62
+ }
63
+ const values = envfile.readEnvFile(abs);
64
+ if (!values.GITLAB_URL || !values.GITLAB_TOKEN) {
65
+ return fail(`${CREDENTIALS_REL} needs GITLAB_URL and GITLAB_TOKEN`);
66
+ }
67
+ if (process.platform !== 'win32') {
68
+ const mode = fs.statSync(abs).mode & 0o777;
69
+ if (mode !== 0o600) {
70
+ return fail(`mode 0${mode.toString(8)} is not 0600`);
71
+ }
72
+ }
73
+ const ignored = checkIgnored(cwd, CREDENTIALS_REL);
74
+ if (ignored.status === 'fail') {
75
+ return fail(`${CREDENTIALS_REL} is not ignored`);
76
+ }
77
+ return {
78
+ status: ignored.status === 'warn' ? 'warn' : 'ok',
79
+ detail: process.platform === 'win32' ? '0600 (not checked on win32)' : '0600, ignored',
80
+ };
81
+ }
82
+
83
+ async function checkGitlabUpstream(url, token) {
84
+ const host = (() => {
85
+ try {
86
+ return new URL(url).host;
87
+ } catch {
88
+ return url;
89
+ }
90
+ })();
91
+ try {
92
+ const response = await fetch(`${url}/api/v4/user`, {
93
+ headers: { 'PRIVATE-TOKEN': token },
94
+ signal: AbortSignal.timeout(15_000),
95
+ });
96
+ if (response.status === 200) {
97
+ return { status: 'ok', detail: 'GET /api/v4/user → 200' };
98
+ }
99
+ if (response.status === 401) {
100
+ return { status: 'fail', detail: 'GET /api/v4/user → 401', next: 'ai-rules mcp setup gitlab' };
101
+ }
102
+ return {
103
+ status: 'fail',
104
+ detail: `GET /api/v4/user → ${response.status}`,
105
+ next: `check network access to ${host}`,
106
+ };
107
+ } catch {
108
+ return { status: 'fail', detail: 'GET /api/v4/user failed', next: `check network access to ${host}` };
109
+ }
110
+ }
111
+
112
+ async function checkRegistration(server, cwd, version) {
113
+ const clients = detectClientIds(cwd, TOOL_INSTALL_MARKERS);
114
+ if (clients.length === 0) {
115
+ return { status: 'warn', detail: 'no MCP client detected', next: null };
116
+ }
117
+ const statuses = [];
118
+
119
+ for (const id of clients) {
120
+ const file = {
121
+ cursor: '.cursor/mcp.json',
122
+ claude: '.mcp.json',
123
+ mavis: '.mavis/mcp.json',
124
+ opencode: 'opencode.json',
125
+ }[id];
126
+ const key = id === 'opencode' ? 'mcp' : 'mcpServers';
127
+ const shape = id === 'opencode' ? 'local' : 'object';
128
+ const next = `ai-rules mcp add ${server.provider} --tools ${id}`;
129
+ let config;
130
+ try {
131
+ config = readClientConfig(cwd, { id, file, key, shape });
132
+ } catch (error) {
133
+ statuses.push({
134
+ status: 'fail',
135
+ detail: `${id}: ${error instanceof Error ? error.message : String(error)}`,
136
+ next,
137
+ });
138
+ continue;
139
+ }
140
+ if (config.existing === null) {
141
+ statuses.push({ status: 'fail', detail: `${id}: ${file} is missing`, next });
142
+ continue;
143
+ }
144
+ const entry = isPlainObject(config.existing[key]) ? config.existing[key][server.id] : undefined;
145
+ if (entry === undefined) {
146
+ statuses.push({ status: 'fail', detail: `${id}: no "${server.id}" entry`, next });
147
+ continue;
148
+ }
149
+ if (!ownsEntry(entry)) {
150
+ statuses.push({ status: 'fail', detail: `${id}: "${server.id}" is not an ai-rules entry`, next });
151
+ continue;
152
+ }
153
+ const pin = registeredPin(entry);
154
+ if (pin !== version) {
155
+ statuses.push({ status: 'warn', detail: `${id}: pin ${pin} != ${version}`, next: `ai-rules mcp add ${server.provider}` });
156
+ continue;
157
+ }
158
+ const finding = tokenFinding(entry);
159
+ if (finding) {
160
+ statuses.push({ status: 'fail', detail: `${id}: token-looking ${finding} under our id`, next });
161
+ continue;
162
+ }
163
+ statuses.push({ status: 'ok', detail: `${id}: ${pin}` });
164
+ }
165
+
166
+ return unwrap(statuses);
167
+ }
168
+
169
+ /** Shared Yandex credential state: one `yc` probe for both servers. */
170
+ async function checkYandexCredentials(cwd, options, yandex) {
171
+ let config;
172
+ try {
173
+ config = yandex.loadYandexConfig({ root: cwd });
174
+ } catch {
175
+ return {
176
+ check: { status: 'fail', detail: 'YANDEX_ORG_ID is not set', next: 'ai-rules mcp setup yandex' },
177
+ config: null,
178
+ token: null,
179
+ };
180
+ }
181
+
182
+ const ycBin = options.ycBin || config.ycBin;
183
+ if (!yandex.ycAvailable(ycBin)) {
184
+ return {
185
+ check: {
186
+ status: 'fail',
187
+ detail: 'yc not found',
188
+ next: 'install the Yandex Cloud CLI (https://yandex.cloud/en/docs/cli/operations/install-cli)',
189
+ },
190
+ config: null,
191
+ token: null,
192
+ };
193
+ }
194
+
195
+ if (checkIgnored(cwd, CONFIG_REL).status === 'fail') {
196
+ return {
197
+ check: { status: 'fail', detail: `${CONFIG_REL} is not ignored`, next: 'ai-rules mcp setup yandex' },
198
+ config: null,
199
+ token: null,
200
+ };
201
+ }
202
+
203
+ try {
204
+ const { token } = await yandex.fetchToken({ interactive: false, ycBin, noProxy: config.noProxy });
205
+ return {
206
+ check: { status: 'ok', detail: `organization ${config.orgId}, yc found` },
207
+ config,
208
+ token,
209
+ };
210
+ } catch (error) {
211
+ const name = error instanceof Error ? error.name : '';
212
+ if (name === 'YcSpawnError') {
213
+ return {
214
+ check: {
215
+ status: 'fail',
216
+ detail: 'yc not found',
217
+ next: 'install the Yandex Cloud CLI (https://yandex.cloud/en/docs/cli/operations/install-cli)',
218
+ },
219
+ config: null,
220
+ token: null,
221
+ };
222
+ }
223
+ return {
224
+ check: {
225
+ status: 'fail',
226
+ detail: error instanceof Error ? oneLine(error.message) : 'yc iam create-token failed',
227
+ next: 'ai-rules mcp refresh yandex',
228
+ },
229
+ config,
230
+ token: null,
231
+ };
232
+ }
233
+ }
234
+
235
+ async function checkYandexUpstream(server, config, token, yandex) {
236
+ const url = yandex.resolveTarget(server.argv[0]);
237
+ try {
238
+ await yandex.postJsonRpc({
239
+ url,
240
+ token,
241
+ orgId: config.orgId,
242
+ protocolVersion: '2024-11-05',
243
+ message: {
244
+ jsonrpc: '2.0',
245
+ id: 1,
246
+ method: 'initialize',
247
+ params: {
248
+ protocolVersion: '2024-11-05',
249
+ capabilities: {},
250
+ clientInfo: { name: 'ai-rules-doctor', version: '1.0.0' },
251
+ },
252
+ },
253
+ });
254
+ return { status: 'ok', detail: 'POST initialize → 2xx' };
255
+ } catch (error) {
256
+ if (error instanceof Error && error.name === 'UnauthorizedError') {
257
+ return {
258
+ status: 'fail',
259
+ kind: 'yandex-session',
260
+ detail: 'POST initialize → 401',
261
+ next: 'ai-rules mcp refresh yandex',
262
+ };
263
+ }
264
+ const message = error instanceof Error ? error.message : String(error);
265
+ if (/organization/i.test(message)) {
266
+ return { status: 'fail', detail: 'upstream rejected the organization id', next: 'ai-rules mcp setup yandex' };
267
+ }
268
+ return { status: 'fail', detail: oneLine(message), next: 'check NO_PROXY / network' };
269
+ }
270
+ }
271
+
272
+ function checkRuntime(server, cwd, packageRoot, version) {
273
+ const statuses = [];
274
+ if (assertNodeFloor(process.versions.node, 20)) {
275
+ statuses.push({ status: 'ok', detail: `node ${process.versions.node}` });
276
+ } else {
277
+ statuses.push({ status: 'fail', detail: `node ${process.versions.node}`, next: 'install Node 20 LTS or newer' });
278
+ }
279
+ statuses.push(
280
+ npxResolves()
281
+ ? { status: 'ok', detail: 'npx found' }
282
+ : { status: 'fail', detail: 'npx not found', next: 'install Node.js 20+ (npm/npx)' },
283
+ );
284
+ statuses.push(
285
+ fs.existsSync(path.join(packageRoot, server.entry))
286
+ ? { status: 'ok', detail: server.entry }
287
+ : { status: 'fail', detail: `missing ${server.entry}`, next: `reinstall @bonesofspring/ai-rules@${version}` },
288
+ );
289
+
290
+ try {
291
+ const resolved = resolveProjectRootDetailed({ cwd });
292
+ const rel = path.relative(cwd, resolved.root) || '.';
293
+ if (resolved.source === 'cwd') {
294
+ statuses.push({ status: 'warn', detail: `root ${rel} (no project marker; using cwd)` });
295
+ } else {
296
+ statuses.push({
297
+ status: 'ok',
298
+ detail: `root ${rel}${resolved.source === 'env' ? ' (AI_RULES_PROJECT_ROOT)' : ''}`,
299
+ });
300
+ }
301
+ } catch (error) {
302
+ statuses.push({
303
+ status: 'fail',
304
+ detail: oneLine(error instanceof Error ? error.message : String(error)),
305
+ next: error instanceof Error && error.next ? error.next : 'start the client from the repository root or set AI_RULES_PROJECT_ROOT',
306
+ });
307
+ }
308
+
309
+ return { check: unwrap(statuses), ready: !statuses.some((entry) => entry.status === 'fail') };
310
+ }
311
+
312
+ /**
313
+ * @returns {Promise<{ servers: object[], exitCode: 0|1|2 }>}
314
+ */
315
+ async function runDoctor({ cwd, provider, packageRoot, version, envfile, yandex, options = {} }) {
316
+ const { serversFor } = require('./registry');
317
+ const servers = [];
318
+ const failures = [];
319
+
320
+ const gitlabAbs = resolveManagedPath(cwd, CREDENTIALS_REL);
321
+ const gitlabValues = gitlabAbs && fs.existsSync(gitlabAbs) ? envfile.readEnvFile(gitlabAbs) : {};
322
+ const yandexState = provider === 'gitlab'
323
+ ? null
324
+ : await checkYandexCredentials(cwd, options, yandex);
325
+
326
+ for (const server of serversFor(provider)) {
327
+ const checks = {};
328
+ const nexts = [];
329
+ const put = (area, check) => {
330
+ checks[area] = { status: check.status, detail: check.detail };
331
+ if (check.next) {
332
+ nexts.push(check.next);
333
+ }
334
+ if (check.status === 'fail') {
335
+ failures.push({ server: server.id, area, kind: check.kind ?? 'other', next: check.next });
336
+ }
337
+ };
338
+
339
+ const runtime = checkRuntime(server, cwd, packageRoot, version);
340
+ put('runtime', runtime.check);
341
+
342
+ if (!runtime.ready) {
343
+ for (const area of ['registration', 'credentials', 'upstream']) {
344
+ checks[area] = { status: 'skipped', detail: 'runtime not ready' };
345
+ }
346
+ servers.push({
347
+ id: server.id,
348
+ checks,
349
+ next: nexts[0] ?? null,
350
+ nexts,
351
+ ready: false,
352
+ });
353
+ continue;
354
+ }
355
+
356
+ put('registration', await checkRegistration(server, cwd, version));
357
+
358
+ if (server.provider === 'gitlab') {
359
+ const credentials = await checkGitlabCredentials(cwd, envfile);
360
+ put('credentials', credentials);
361
+ if (credentials.status === 'fail') {
362
+ checks.upstream = { status: 'skipped', detail: 'credentials not ready' };
363
+ } else {
364
+ put('upstream', await checkGitlabUpstream(gitlabValues.GITLAB_URL, gitlabValues.GITLAB_TOKEN));
365
+ }
366
+ } else {
367
+ put('credentials', yandexState.check);
368
+ if (yandexState.check.status === 'fail' || !yandexState.token) {
369
+ checks.upstream = { status: 'skipped', detail: 'credentials not ready' };
370
+ } else {
371
+ put('upstream', await checkYandexUpstream(server, yandexState.config, yandexState.token, yandex));
372
+ }
373
+ }
374
+
375
+ servers.push({
376
+ id: server.id,
377
+ checks: Object.fromEntries(AREAS.map((area) => [area, checks[area]])),
378
+ next: nexts[0] ?? null,
379
+ nexts,
380
+ ready: AREAS.every((area) => ['ok', 'warn'].includes(checks[area].status)),
381
+ });
382
+ }
383
+
384
+ const hardFailures = failures.filter((entry) => entry.status !== 'warn');
385
+ const exitCode = hardFailures.length === 0
386
+ ? 0
387
+ : hardFailures.every((entry) => entry.kind === 'yandex-session')
388
+ ? 2
389
+ : 1;
390
+
391
+ return { servers, exitCode };
392
+ }
393
+
394
+ module.exports = { runDoctor, AREAS };
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Interactive input for `ai-rules mcp setup`.
3
+ *
4
+ * `readSecret` never echoes: a TTY uses a readline interface whose output is a
5
+ * muted writer, so the terminal driver receives no character; a pipe is read as
6
+ * one plain line. `stty` is not used (Windows parity).
7
+ */
8
+ const readline = require('node:readline');
9
+ const { Writable } = require('node:stream');
10
+
11
+ let pipedReader = null;
12
+ let pipedClosed = false;
13
+ const pipedLines = [];
14
+ const pipedWaiters = [];
15
+
16
+ function settlePiped(line) {
17
+ const waiter = pipedWaiters.shift();
18
+ if (waiter) {
19
+ waiter(line);
20
+ } else {
21
+ pipedLines.push(line);
22
+ }
23
+ }
24
+
25
+ function ensurePipedReader() {
26
+ if (pipedReader) {
27
+ return;
28
+ }
29
+ pipedReader = readline.createInterface({ input: process.stdin, terminal: false });
30
+ pipedReader.on('line', (line) => settlePiped(line));
31
+ pipedReader.on('close', () => {
32
+ pipedClosed = true;
33
+ while (pipedWaiters.length > 0) {
34
+ pipedWaiters.shift()('');
35
+ }
36
+ });
37
+ }
38
+
39
+ /** One line from a pipe; concurrent/sequential reads queue instead of competing for stdin. */
40
+ function readPipedLine() {
41
+ ensurePipedReader();
42
+ if (pipedLines.length > 0) {
43
+ return Promise.resolve(pipedLines.shift());
44
+ }
45
+ if (pipedClosed) {
46
+ return Promise.resolve('');
47
+ }
48
+ return new Promise((resolve) => pipedWaiters.push(resolve));
49
+ }
50
+
51
+ function readTtyLine(secret) {
52
+ return new Promise((resolve) => {
53
+ const muted = new Writable({
54
+ write(chunk, encoding, callback) {
55
+ callback();
56
+ },
57
+ });
58
+ muted.columns = 80;
59
+ const rl = readline.createInterface({
60
+ input: process.stdin,
61
+ output: secret ? muted : process.stderr,
62
+ terminal: true,
63
+ });
64
+ let settled = false;
65
+
66
+ rl.once('line', (line) => {
67
+ settled = true;
68
+ rl.close();
69
+ if (secret) {
70
+ process.stderr.write('\n');
71
+ }
72
+ resolve(line);
73
+ });
74
+
75
+ rl.once('SIGINT', () => {
76
+ process.stderr.write('\n');
77
+ rl.close();
78
+ resolve('');
79
+ });
80
+
81
+ rl.once('close', () => {
82
+ if (!settled) {
83
+ resolve('');
84
+ }
85
+ });
86
+ });
87
+ }
88
+
89
+ function readLine(secret) {
90
+ return process.stdin.isTTY ? readTtyLine(secret) : readPipedLine();
91
+ }
92
+
93
+ /** Plain prompt (non-secret); `defaultValue` is returned for an empty line. */
94
+ async function ask(question, { defaultValue } = {}) {
95
+ const suffix = defaultValue === undefined || defaultValue === '' ? '' : ` [${defaultValue}]`;
96
+ process.stderr.write(`${question}${suffix}: `);
97
+ const line = await readLine(false);
98
+ if (!process.stdin.isTTY) {
99
+ process.stderr.write('\n');
100
+ }
101
+ const value = line.trim();
102
+ return value === '' && defaultValue !== undefined ? defaultValue : value;
103
+ }
104
+
105
+ /** Hidden prompt for a token; the typed bytes are never echoed or logged. */
106
+ async function readSecret(question) {
107
+ process.stderr.write(`${question}: `);
108
+ const line = await readLine(true);
109
+ if (!process.stdin.isTTY) {
110
+ process.stderr.write('\n');
111
+ }
112
+ return line.trim();
113
+ }
114
+
115
+ module.exports = { ask, readSecret };
@@ -0,0 +1,170 @@
1
+ /**
2
+ * One logical MCP server registry, rendered into each client's native schema.
3
+ *
4
+ * Slugs are the `ai-rules mcp run <slug>` argument; ids are the keys the four
5
+ * client configs already use. Ownership lives in the entry itself — no state
6
+ * file — so a fresh clone can answer "which entries are ours?".
7
+ */
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+ const { isPlainObject } = require('../fs-utils');
11
+
12
+ const PACKAGE_NAME = '@bonesofspring/ai-rules';
13
+ const PIN_RE = /^@bonesofspring\/ai-rules@(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/;
14
+
15
+ const SERVERS = [
16
+ { id: 'gitlab', slug: 'gitlab', provider: 'gitlab', entry: 'mcp/gitlab.mjs', argv: [] },
17
+ {
18
+ id: 'yandex tracker',
19
+ slug: 'yandex-tracker',
20
+ provider: 'yandex',
21
+ entry: 'mcp/yandex-mcp-proxy.mjs',
22
+ argv: ['tracker'],
23
+ },
24
+ {
25
+ id: 'yandex wiki',
26
+ slug: 'yandex-wiki',
27
+ provider: 'yandex',
28
+ entry: 'mcp/yandex-mcp-proxy.mjs',
29
+ argv: ['wiki'],
30
+ },
31
+ ];
32
+
33
+ const CLIENTS = [
34
+ { id: 'cursor', root: '.cursor', file: '.cursor/mcp.json', key: 'mcpServers', shape: 'object' },
35
+ { id: 'claude', root: '.claude', file: '.mcp.json', key: 'mcpServers', shape: 'object' },
36
+ { id: 'mavis', root: '.mavis', file: '.mavis/mcp.json', key: 'mcpServers', shape: 'object' },
37
+ { id: 'opencode', root: '.opencode', file: 'opencode.json', key: 'mcp', shape: 'local' },
38
+ ];
39
+
40
+ const CLIENT_IDS = CLIENTS.map((client) => client.id);
41
+
42
+ function serversFor(provider) {
43
+ return provider === 'all' ? SERVERS.slice() : SERVERS.filter((server) => server.provider === provider);
44
+ }
45
+
46
+ function serverBySlug(slug) {
47
+ return SERVERS.find((server) => server.slug === slug) || null;
48
+ }
49
+
50
+ function clientById(id) {
51
+ return CLIENTS.find((client) => client.id === id) || null;
52
+ }
53
+
54
+ function argsFor(server, version) {
55
+ return ['-y', `${PACKAGE_NAME}@${version}`, 'mcp', 'run', server.slug];
56
+ }
57
+
58
+ function renderEntry(client, server, version) {
59
+ const args = argsFor(server, version);
60
+ if (client.shape === 'local') {
61
+ return { type: 'local', command: ['npx', ...args] };
62
+ }
63
+ return { command: 'npx', args };
64
+ }
65
+
66
+ /** Normalize the two client shapes to one argv array; null for anything else. */
67
+ function entryArgv(entry) {
68
+ if (!isPlainObject(entry)) {
69
+ return null;
70
+ }
71
+ if (entry.type === 'local' && Array.isArray(entry.command)) {
72
+ return entry.command.filter((item) => typeof item === 'string');
73
+ }
74
+ if (typeof entry.command === 'string' && Array.isArray(entry.args)) {
75
+ return [entry.command, ...entry.args.filter((item) => typeof item === 'string')];
76
+ }
77
+ return null;
78
+ }
79
+
80
+ /** The ownership proof, stored in the entry: `npx -y @bonesofspring/ai-rules@<exact> mcp run <slug>`. */
81
+ function ownsEntry(entry) {
82
+ const argv = entryArgv(entry);
83
+ if (!argv) {
84
+ return false;
85
+ }
86
+ return (
87
+ argv[0] === 'npx'
88
+ && argv[1] === '-y'
89
+ && typeof argv[2] === 'string'
90
+ && PIN_RE.test(argv[2])
91
+ && argv[3] === 'mcp'
92
+ && argv[4] === 'run'
93
+ );
94
+ }
95
+
96
+ function registeredPin(entry) {
97
+ const argv = entryArgv(entry);
98
+ const match = argv && typeof argv[2] === 'string' ? PIN_RE.exec(argv[2]) : null;
99
+ return match ? match[1] : null;
100
+ }
101
+
102
+ function registeredSlug(entry) {
103
+ const argv = entryArgv(entry);
104
+ return argv ? argv[5] ?? null : null;
105
+ }
106
+
107
+ /** Migration window: the pre-pack `node scripts/*-mcp.mjs` entries. */
108
+ function isLegacyEntry(entry, server) {
109
+ const argv = entryArgv(entry);
110
+ if (!argv) {
111
+ return false;
112
+ }
113
+ const joined = argv.join(' ');
114
+ if (server.provider === 'gitlab') {
115
+ return joined.includes('gitlab-mcp.mjs');
116
+ }
117
+ return joined.includes('yandex-mcp-proxy.mjs');
118
+ }
119
+
120
+ const SECRET_KEY_RE = /(TOKEN|SECRET|PASSWORD|PRIVATE|AUTH)/i;
121
+ const SECRET_VALUE_RE = /(glpat-|PRIVATE KEY|Bearer\s+\S)/;
122
+
123
+ /** Name of a token-looking key under our id, or null. Never returns the value. */
124
+ function tokenFinding(entry) {
125
+ if (!isPlainObject(entry)) {
126
+ return null;
127
+ }
128
+ for (const blockName of ['env', 'headers', 'environment']) {
129
+ const block = entry[blockName];
130
+ if (!isPlainObject(block)) {
131
+ continue;
132
+ }
133
+ for (const [key, value] of Object.entries(block)) {
134
+ const stringValue = typeof value === 'string' ? value : '';
135
+ if (SECRET_KEY_RE.test(key) || SECRET_VALUE_RE.test(stringValue)) {
136
+ return `${blockName}.${key}`;
137
+ }
138
+ }
139
+ }
140
+ return null;
141
+ }
142
+
143
+ /** `present` = an install marker exists or the client's MCP config exists. */
144
+ function clientPresent(cwd, client, markers) {
145
+ if (fs.existsSync(path.join(cwd, client.file))) {
146
+ return true;
147
+ }
148
+ const markerRels = markers[client.root] || [];
149
+ return markerRels.some((rel) => fs.existsSync(path.join(cwd, rel)));
150
+ }
151
+
152
+ module.exports = {
153
+ PACKAGE_NAME,
154
+ PIN_RE,
155
+ SERVERS,
156
+ CLIENTS,
157
+ CLIENT_IDS,
158
+ serversFor,
159
+ serverBySlug,
160
+ clientById,
161
+ argsFor,
162
+ renderEntry,
163
+ entryArgv,
164
+ ownsEntry,
165
+ registeredPin,
166
+ registeredSlug,
167
+ isLegacyEntry,
168
+ tokenFinding,
169
+ clientPresent,
170
+ };