@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
@@ -127,11 +127,18 @@ function decide({ consumer, base, template, source }) {
127
127
  * detected instead of silently rewritten as v1.
128
128
  */
129
129
  function readRecord(recordPath) {
130
+ let raw;
131
+ try {
132
+ raw = fs.readFileSync(recordPath, 'utf8');
133
+ } catch (error) {
134
+ if (error && error.code === 'ENOENT') return null;
135
+ return { unreadable: true, error: error && error.message ? error.message : 'unreadable' };
136
+ }
130
137
  let parsed;
131
138
  try {
132
- parsed = JSON.parse(fs.readFileSync(recordPath, 'utf8'));
133
- } catch {
134
- return null;
139
+ parsed = JSON.parse(raw);
140
+ } catch (error) {
141
+ return { unreadable: true, error: error && error.message ? error.message : 'invalid JSON' };
135
142
  }
136
143
  if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
137
144
  return null;
@@ -167,9 +174,9 @@ function sortKeys(object) {
167
174
  }
168
175
 
169
176
  /**
170
- * Merge the rels the seed just wrote into the previous record. A rel the seed
171
- * rewrote keeps its original `source`: attribution follows the first tool that
172
- * wrote the file, so a second tool's run cannot re-source another preset's rel.
177
+ * Merge the rels the seed just wrote into the previous record. Attribution
178
+ * follows the first tool that wrote the file. A later tool's bytes do not
179
+ * replace that base: `source` and the stored digests stay put.
173
180
  *
174
181
  * @param {{ previous?: { files: Record<string, BaseEntry> } | null, packageVersion: string, source: string, written: Array<{ rel: string } & Digest> }} input
175
182
  */
@@ -181,6 +188,17 @@ function buildRecord({ previous, packageVersion, source, written }) {
181
188
  }
182
189
  for (const item of written) {
183
190
  const prior = files[item.rel];
191
+ // A second tool may re-seed a missing file. Those bytes stay off this
192
+ // record so they cannot become the owning tool's base without a drift row.
193
+ if (prior && prior.source !== source) {
194
+ // team/** is refreshed every run. Everything else in `written` was
195
+ // created because the destination was absent, so these bytes belong
196
+ // to this tool. Leaving the old source would call that recreate an edit.
197
+ if (!item.rel.startsWith('.ai.local/team/')) {
198
+ files[item.rel] = { sha256: item.sha256, normSha256: item.normSha256, source };
199
+ }
200
+ continue;
201
+ }
184
202
  files[item.rel] = {
185
203
  sha256: item.sha256,
186
204
  normSha256: item.normSha256,
@@ -223,8 +241,16 @@ function collectOutcomes({ cwd, record, templates, source }) {
223
241
  return rows;
224
242
  }
225
243
 
226
- /** `/` → `__`; the result never ends in `.md`, so the overlay probe cannot load it. */
244
+ /**
245
+ * Injective sink name. `/` becomes `__` and `_` becomes `_u`, so `a/b` and
246
+ * `a__b` do not share a file. Callers append `.diff` / `.template-new`.
247
+ */
227
248
  function sinkEntryName(rel) {
249
+ return rel.replace(/[_/]/g, (char) => (char === '/' ? '__' : '_u'));
250
+ }
251
+
252
+ /** Name written before the encoding distinguished `_` from `/`. */
253
+ function legacySinkEntryName(rel) {
228
254
  return rel.replace(/\//g, '__');
229
255
  }
230
256
 
@@ -394,12 +420,16 @@ function actionableOutcomes(cwd, outcomes) {
394
420
  */
395
421
  function clearSink(cwd, rels, trackFile) {
396
422
  for (const rel of rels) {
397
- const name = sinkEntryName(rel);
398
- for (const suffix of ['.diff', '.template-new']) {
399
- const dest = path.join(cwd, SINK_REL, `${name}${suffix}`);
400
- if (!fs.existsSync(dest)) continue;
401
- if (trackFile) trackFile(dest, path.join(SINK_REL, `${name}${suffix}`));
402
- fs.rmSync(dest, { force: true });
423
+ const names = [sinkEntryName(rel)];
424
+ const legacy = legacySinkEntryName(rel);
425
+ if (legacy !== names[0]) names.push(legacy);
426
+ for (const name of names) {
427
+ for (const suffix of ['.diff', '.template-new']) {
428
+ const dest = path.join(cwd, SINK_REL, `${name}${suffix}`);
429
+ if (!fs.existsSync(dest)) continue;
430
+ if (trackFile) trackFile(dest, path.join(SINK_REL, `${name}${suffix}`));
431
+ fs.rmSync(dest, { force: true });
432
+ }
403
433
  }
404
434
  }
405
435
  }
@@ -574,7 +604,7 @@ function flushAllAiLocalDriftSummaries() {
574
604
  * record write goes through the caller's transaction writer, so a later failure
575
605
  * removes it again.
576
606
  */
577
- function runTemplateDrift({ cwd, written, templates, source, packageVersion, mergeAiLocal, writeFile, trackFile }) {
607
+ function runTemplateDrift({ cwd, written, templates, source, packageVersion, mergeAiLocal, checkAiLocal, writeFile, trackFile }) {
578
608
  if (!writeFile || !source || !templates) {
579
609
  return;
580
610
  }
@@ -591,6 +621,10 @@ function runTemplateDrift({ cwd, written, templates, source, packageVersion, mer
591
621
  }
592
622
 
593
623
  const previous = readRecord(recordPath);
624
+ if (previous && previous.unreadable) {
625
+ warn(`${RECORD_REL} is unreadable (${previous.error}); skipped .ai.local template record and merge`);
626
+ return;
627
+ }
594
628
  if (previous && previous.schemaVersion > RECORD_SCHEMA_VERSION) {
595
629
  warn(
596
630
  `${RECORD_REL} declares schemaVersion ${previous.schemaVersion}, newer than this CLI `
@@ -608,6 +642,13 @@ function runTemplateDrift({ cwd, written, templates, source, packageVersion, mer
608
642
  const record = buildRecord({ previous, packageVersion, source, written: seedWritten });
609
643
 
610
644
  const outcomes = collectOutcomes({ cwd, record, templates: templateMap, source });
645
+ if (checkAiLocal) {
646
+ for (const row of outcomes) {
647
+ if (row.outcome === 'noop') continue;
648
+ console.log(`check ${row.outcome} ${row.rel}`);
649
+ }
650
+ return;
651
+ }
611
652
  // One rel, one count, one proposal. A later pass adopts the rel when its
612
653
  // template already matches, and does not add the file again.
613
654
  const { rows: actionable, adoptUpgrades } = actionableOutcomes(cwd, outcomes);
@@ -10,6 +10,10 @@
10
10
  * `manifest.mjs` is the deterministic writer for
11
11
  * `.ai.local/team/tasks/<slug>/artifact-manifest.json`; producers call it
12
12
  * instead of patching the JSON, which is a whole-file merge target.
13
+ *
14
+ * The six `team-db*.mjs` modules are the rebuildable SQLite projection and its
15
+ * read-only dashboard. `team-db.mjs` is the CLI; the others are loaded by it on
16
+ * demand, so a runtime without `node:sqlite` never imports them.
13
17
  */
14
18
  const ENGINE_SCRIPTS = [
15
19
  'run.mjs',
@@ -19,6 +23,12 @@ const ENGINE_SCRIPTS = [
19
23
  'derive-gate-signals.mjs',
20
24
  'efficacy-oracle.mjs',
21
25
  'manifest.mjs',
26
+ 'team-db.mjs',
27
+ 'team-db-schema.mjs',
28
+ 'team-db-project.mjs',
29
+ 'team-db-api.mjs',
30
+ 'team-db-openapi.mjs',
31
+ 'team-db-dashboard.mjs',
22
32
  ];
23
33
 
24
34
  /** Preset-root-relative directory holding the engine source of truth. */
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Client registration for the MCP pack.
3
+ *
4
+ * One logical registry (registry.js), four native renderings. Everything is
5
+ * validated before the first write, a second run is byte-identical (the text
6
+ * guard keeps the mtime), and an entry is ours only when it carries the exact
7
+ * ownership argv — no state file, no absolute path, no token.
8
+ */
9
+ const fs = require('fs');
10
+ const path = require('path');
11
+ const { assertSafeDest } = require('../safe-path');
12
+ const { createInstallTransaction, isPlainObject, readMergeableJson, runStamp } = require('../fs-utils');
13
+ const {
14
+ CLIENT_IDS,
15
+ clientById,
16
+ clientPresent,
17
+ isLegacyEntry,
18
+ ownsEntry,
19
+ renderEntry,
20
+ } = require('./registry');
21
+
22
+ function detectClientIds(cwd, markers) {
23
+ return CLIENT_IDS.filter((id) => clientPresent(cwd, clientById(id), markers));
24
+ }
25
+
26
+ /**
27
+ * @returns {{ clients: object[], warnings: string[] }} Explicit `--tools` may name
28
+ * an undetected client (the user may be about to install it) but says so.
29
+ */
30
+ function selectClients({ cwd, tools, markers }) {
31
+ const warnings = [];
32
+ if (tools && tools.length > 0) {
33
+ const clients = tools.map((id) => clientById(id));
34
+ for (const client of clients) {
35
+ if (!clientPresent(cwd, client, markers)) {
36
+ warnings.push(`${client.id} is not installed here; registered anyway`);
37
+ }
38
+ }
39
+ return { clients, warnings };
40
+ }
41
+ return {
42
+ clients: detectClientIds(cwd, markers).map((id) => clientById(id)),
43
+ warnings,
44
+ };
45
+ }
46
+
47
+ function seedDocument(client) {
48
+ if (client.shape === 'local') {
49
+ return { $schema: 'https://opencode.ai/config.json', [client.key]: {} };
50
+ }
51
+ return { [client.key]: {} };
52
+ }
53
+
54
+ function readClientConfig(cwd, client) {
55
+ const rel = client.file;
56
+ const abs = assertSafeDest(cwd, path.join(cwd, rel), rel);
57
+ const existing = readMergeableJson(abs, rel, client.key);
58
+ const text = existing === null ? null : fs.readFileSync(abs, 'utf8');
59
+ return { rel, abs, existing, text };
60
+ }
61
+
62
+ function planClient({ cwd, client, servers, version, replace }) {
63
+ const { rel, abs, existing, text } = readClientConfig(cwd, client);
64
+ const doc = existing === null ? seedDocument(client) : structuredClone(existing);
65
+ if (!isPlainObject(doc[client.key])) {
66
+ doc[client.key] = {};
67
+ }
68
+
69
+ const warnings = [];
70
+ for (const server of servers) {
71
+ const current = doc[client.key][server.id];
72
+ if (current === undefined || ownsEntry(current) || isLegacyEntry(current, server)) {
73
+ doc[client.key][server.id] = renderEntry(client, server, version);
74
+ continue;
75
+ }
76
+ if (replace) {
77
+ doc[client.key][server.id] = renderEntry(client, server, version);
78
+ continue;
79
+ }
80
+ warnings.push(`${client.id} "${server.id}" is a custom entry; left untouched`);
81
+ }
82
+
83
+ const nextText = `${JSON.stringify(doc, null, 2)}\n`;
84
+ return { client, rel, abs, text, nextText, changed: nextText !== text, warnings };
85
+ }
86
+
87
+ /** Validate every target, then write only the files whose text changed. */
88
+ function registerServers({ cwd, clients, servers, version, replace = false }) {
89
+ const plans = clients.map((client) => planClient({ cwd, client, servers, version, replace }));
90
+ const changed = [];
91
+ if (plans.some((plan) => plan.changed)) {
92
+ const tx = createInstallTransaction(cwd, path.join(cwd, '.ai-rules', '.rollback', runStamp()));
93
+ for (const plan of plans) {
94
+ if (plan.changed) {
95
+ tx.writeFile(plan.abs, plan.nextText, plan.rel);
96
+ changed.push(plan.rel);
97
+ }
98
+ }
99
+ tx.commit();
100
+ }
101
+ return { changed, warnings: plans.flatMap((plan) => plan.warnings) };
102
+ }
103
+
104
+ function planRemoval({ cwd, client, servers }) {
105
+ const { rel, abs, existing, text } = readClientConfig(cwd, client);
106
+ if (existing === null) {
107
+ return null;
108
+ }
109
+ const doc = structuredClone(existing);
110
+ if (!isPlainObject(doc[client.key])) {
111
+ return null;
112
+ }
113
+
114
+ const warnings = [];
115
+ const removed = [];
116
+ for (const server of servers) {
117
+ const current = doc[client.key][server.id];
118
+ if (current === undefined) {
119
+ continue;
120
+ }
121
+ if (ownsEntry(current) || isLegacyEntry(current, server)) {
122
+ delete doc[client.key][server.id];
123
+ removed.push(server.id);
124
+ continue;
125
+ }
126
+ warnings.push(`${client.id} "${server.id}" is a custom entry; left untouched`);
127
+ }
128
+
129
+ const nextText = `${JSON.stringify(doc, null, 2)}\n`;
130
+ return {
131
+ client,
132
+ rel,
133
+ abs,
134
+ nextText,
135
+ changed: removed.length > 0 && nextText !== text,
136
+ removed,
137
+ warnings,
138
+ };
139
+ }
140
+
141
+ /** Delete only entries whose ownership argv proves they are ours; never the file. */
142
+ function removeServers({ cwd, clients, servers }) {
143
+ const plans = clients.map((client) => planRemoval({ cwd, client, servers })).filter(Boolean);
144
+ const changed = [];
145
+ const removed = [];
146
+ if (plans.some((plan) => plan.changed)) {
147
+ const tx = createInstallTransaction(cwd, path.join(cwd, '.ai-rules', '.rollback', runStamp()));
148
+ for (const plan of plans) {
149
+ if (plan.changed) {
150
+ tx.writeFile(plan.abs, plan.nextText, plan.rel);
151
+ changed.push(plan.rel);
152
+ }
153
+ }
154
+ tx.commit();
155
+ }
156
+ for (const plan of plans) {
157
+ removed.push(...plan.removed);
158
+ }
159
+ return { changed, removed, warnings: plans.flatMap((plan) => plan.warnings) };
160
+ }
161
+
162
+ module.exports = {
163
+ detectClientIds,
164
+ selectClients,
165
+ readClientConfig,
166
+ registerServers,
167
+ removeServers,
168
+ };
@@ -0,0 +1,298 @@
1
+ /**
2
+ * Provider credential setup for the MCP pack.
3
+ *
4
+ * GitLab: URL + token, validated with `GET <url>/api/v4/user` before the write,
5
+ * stored in `.ai-rules/mcp/credentials.env` (0600) inside a self-ignoring dir.
6
+ * Yandex: `yc` detection and one `yc iam create-token` proof; only non-secret
7
+ * settings are written to `.ai-rules/mcp/config.env`. No token is ever stored.
8
+ *
9
+ * Both commands never write the legacy root `.env.gitlab` / `.env.yandex`.
10
+ */
11
+ const fs = require('fs');
12
+ const path = require('path');
13
+ const { spawnSync } = require('child_process');
14
+ const { assertSafeDest, resolveManagedPath } = require('../safe-path');
15
+ const { createInstallTransaction, runStamp } = require('../fs-utils');
16
+ const { readSecret, ask } = require('./prompt');
17
+
18
+ const CREDENTIALS_REL = '.ai-rules/mcp/credentials.env';
19
+ const CONFIG_REL = '.ai-rules/mcp/config.env';
20
+ const IGNORE_REL = '.ai-rules/.gitignore';
21
+ const IGNORE_TEXT = [
22
+ '# Local ai-rules state (MCP credentials, install snapshots).',
23
+ '# Never commit.',
24
+ '*',
25
+ '',
26
+ ].join('\n');
27
+
28
+ function writeFile(cwd, rel, content, mode) {
29
+ const abs = assertSafeDest(cwd, path.join(cwd, rel), rel);
30
+ const tx = createInstallTransaction(cwd, path.join(cwd, '.ai-rules', '.rollback', runStamp()));
31
+ tx.writeFile(abs, content, rel);
32
+ // rename keeps the temp file's mode; chmod makes the guarantee umask-independent.
33
+ fs.chmodSync(abs, mode);
34
+ tx.commit();
35
+ return abs;
36
+ }
37
+
38
+ /** Self-ignoring `.ai-rules/` (same mechanism as `.rollback/.gitignore`). Never overwrites. */
39
+ function ensureAiRulesIgnored(cwd) {
40
+ const ignoreAbs = path.join(cwd, IGNORE_REL);
41
+ if (fs.existsSync(ignoreAbs)) {
42
+ return false;
43
+ }
44
+ assertSafeDest(cwd, path.join(cwd, '.ai-rules'), '.ai-rules');
45
+ fs.mkdirSync(path.join(cwd, '.ai-rules'), { recursive: true });
46
+ fs.writeFileSync(ignoreAbs, IGNORE_TEXT);
47
+ return true;
48
+ }
49
+
50
+ /**
51
+ * `git check-ignore -q` is the sound probe: exit 0 = ignored, exit 1 = not
52
+ * ignored. `-v` also exits 0 for a negated pattern, which would report an
53
+ * untracked credential file as ignored.
54
+ * @returns {{ status: 'ok' | 'warn' | 'fail', detail: string }}
55
+ */
56
+ function checkIgnored(cwd, rel) {
57
+ const inside = spawnSync('git', ['rev-parse', '--is-inside-work-tree'], {
58
+ cwd,
59
+ encoding: 'utf8',
60
+ });
61
+ if (inside.status !== 0 || inside.stdout.trim() !== 'true') {
62
+ return { status: 'warn', detail: 'not a git repository; ignore rule not provable here' };
63
+ }
64
+ const result = spawnSync('git', ['check-ignore', '-q', rel], { cwd, encoding: 'utf8' });
65
+ if (result.status === 0) {
66
+ return { status: 'ok', detail: 'ignored' };
67
+ }
68
+ if (result.status === 1) {
69
+ return { status: 'fail', detail: 'git check-ignore: not ignored' };
70
+ }
71
+ const stderr = String(result.stderr ?? '').replace(/\s+/g, ' ').trim();
72
+ return {
73
+ status: 'fail',
74
+ detail: stderr ? `git check-ignore failed: ${stderr}` : `git check-ignore failed (exit ${result.status})`,
75
+ };
76
+ }
77
+
78
+ function normalizeGitlabUrl(value) {
79
+ const trimmed = String(value ?? '').trim();
80
+ if (trimmed === '') {
81
+ return { url: null, reason: 'empty' };
82
+ }
83
+ const stripped = trimmed.replace(/\/+$/, '');
84
+ let parsed;
85
+ try {
86
+ parsed = new URL(stripped);
87
+ } catch {
88
+ return { url: null, reason: 'not a URL' };
89
+ }
90
+ if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
91
+ return { url: null, reason: 'not http(s)' };
92
+ }
93
+ return { url: stripped, reason: parsed.protocol === 'https:' ? null : 'not-https' };
94
+ }
95
+
96
+ function readCredentials(cwd, envfile) {
97
+ const abs = resolveManagedPath(cwd, CREDENTIALS_REL);
98
+ return abs ? envfile.readEnvFile(abs) : {};
99
+ }
100
+
101
+ async function validateGitlabToken(url, token) {
102
+ let response;
103
+ try {
104
+ response = await fetch(`${url}/api/v4/user`, {
105
+ headers: { 'PRIVATE-TOKEN': token },
106
+ signal: AbortSignal.timeout(15_000),
107
+ });
108
+ } catch {
109
+ return { ok: false, status: 'network', detail: 'instance not reachable' };
110
+ }
111
+ if (response.status === 200) {
112
+ let username = null;
113
+ try {
114
+ const body = await response.json();
115
+ username = typeof body?.username === 'string' ? body.username : null;
116
+ } catch {
117
+ username = null;
118
+ }
119
+ return { ok: true, status: 200, username };
120
+ }
121
+ return { ok: false, status: response.status, detail: `token rejected (${response.status})` };
122
+ }
123
+
124
+ /** @returns {Promise<object>} `{ ok, detail, next?, warnings }` */
125
+ async function setupGitlab({ cwd, options = {}, io = {}, envfile }) {
126
+ const existing = readCredentials(cwd, envfile);
127
+ const warnings = [];
128
+ const prefillUrl = existing.GITLAB_URL ?? '';
129
+
130
+ let urlValue;
131
+ if (options.url) {
132
+ urlValue = options.url;
133
+ } else if (options.yes) {
134
+ if (!prefillUrl) {
135
+ return { ok: false, detail: '--yes requires --url <https-url> or an existing credentials file', next: 'ai-rules mcp setup gitlab --url <https-url>' };
136
+ }
137
+ urlValue = prefillUrl;
138
+ } else {
139
+ urlValue = await (io.ask || ask)('GitLab instance URL', { defaultValue: prefillUrl });
140
+ }
141
+
142
+ const normalized = normalizeGitlabUrl(urlValue);
143
+ if (!normalized.url) {
144
+ return { ok: false, detail: `GitLab URL ${normalized.reason}`, next: 'ai-rules mcp setup gitlab --url <https-url>' };
145
+ }
146
+ if (normalized.reason === 'not-https') {
147
+ warnings.push('not https — the token is sent in clear text');
148
+ }
149
+
150
+ let token;
151
+ if (options.yes) {
152
+ if (process.stdin.isTTY) {
153
+ return { ok: false, detail: '--yes reads the token from stdin; pipe it or run without --yes', next: 'ai-rules mcp setup gitlab' };
154
+ }
155
+ token = (await (io.readSecret || readSecret)('GitLab token')).trim();
156
+ } else {
157
+ token = (await (io.readSecret || readSecret)('GitLab token')).trim();
158
+ }
159
+ if (token === '') {
160
+ return { ok: false, detail: 'a GitLab token is required', next: 'ai-rules mcp setup gitlab' };
161
+ }
162
+
163
+ const validation = await validateGitlabToken(normalized.url, token);
164
+ if (!validation.ok) {
165
+ return {
166
+ ok: false,
167
+ detail: validation.status === 'network' ? validation.detail : `token rejected (${validation.status})`,
168
+ next: 'ai-rules mcp setup gitlab',
169
+ warnings,
170
+ };
171
+ }
172
+
173
+ writeFile(
174
+ cwd,
175
+ CREDENTIALS_REL,
176
+ [
177
+ '# GitLab MCP credentials — written by @bonesofspring/ai-rules. Never commit.',
178
+ `GITLAB_URL=${normalized.url}`,
179
+ `GITLAB_TOKEN=${token}`,
180
+ '',
181
+ ].join('\n'),
182
+ 0o600,
183
+ );
184
+ ensureAiRulesIgnored(cwd);
185
+ const ignored = checkIgnored(cwd, CREDENTIALS_REL);
186
+ if (ignored.status === 'fail') {
187
+ return {
188
+ ok: false,
189
+ detail: `${CREDENTIALS_REL} is not ignored`,
190
+ next: 'ai-rules mcp setup gitlab',
191
+ warnings,
192
+ };
193
+ }
194
+
195
+ const legacy = envfile.readEnvFile(path.join(cwd, '.env.gitlab'));
196
+ if (typeof legacy.GITLAB_TOKEN === 'string' && legacy.GITLAB_TOKEN !== '' && legacy.GITLAB_TOKEN !== token) {
197
+ warnings.push('.env.gitlab still holds a different token; rotate it too');
198
+ }
199
+
200
+ return {
201
+ ok: true,
202
+ username: validation.username,
203
+ detail: validation.username ? `token valid for ${validation.username} — saved to ${CREDENTIALS_REL} (0600, ignored)` : `saved to ${CREDENTIALS_REL} (0600, ignored)`,
204
+ warnings,
205
+ };
206
+ }
207
+
208
+ async function setupYandex({ cwd, options = {}, io = {}, yandex, envfile }) {
209
+ const existingAbs = resolveManagedPath(cwd, CONFIG_REL);
210
+ const existing = existingAbs ? envfile.readEnvFile(existingAbs) : {};
211
+ const warnings = [];
212
+
213
+ let orgId = options.orgId || existing.YANDEX_ORG_ID || '';
214
+ if (!orgId) {
215
+ if (options.yes) {
216
+ return { ok: false, detail: '--yes requires --org-id <id>', next: 'ai-rules mcp setup yandex --org-id <id>' };
217
+ }
218
+ orgId = await (io.ask || ask)('Yandex organization id');
219
+ }
220
+ if (!orgId) {
221
+ return { ok: false, detail: 'YANDEX_ORG_ID is required', next: 'ai-rules mcp setup yandex --org-id <id>' };
222
+ }
223
+
224
+ const ycBin = options.ycBin || process.env.YC_BIN || existing.YC_BIN || yandex.DEFAULT_YC_BIN;
225
+ if (!yandex.ycAvailable(ycBin)) {
226
+ return {
227
+ ok: false,
228
+ kind: 'runtime',
229
+ detail: 'yc not found',
230
+ next: 'install the Yandex Cloud CLI (https://yandex.cloud/en/docs/cli/operations/install-cli)',
231
+ };
232
+ }
233
+
234
+ const noProxy = existing.NO_PROXY || process.env.NO_PROXY || yandex.DEFAULT_NO_PROXY;
235
+ try {
236
+ await yandex.fetchToken({ interactive: true, ycBin, noProxy });
237
+ } catch (error) {
238
+ const name = error instanceof Error ? error.name : '';
239
+ if (name === 'YcSpawnError') {
240
+ return {
241
+ ok: false,
242
+ kind: 'runtime',
243
+ detail: 'yc not found',
244
+ next: 'install the Yandex Cloud CLI (https://yandex.cloud/en/docs/cli/operations/install-cli)',
245
+ };
246
+ }
247
+ return {
248
+ ok: false,
249
+ detail: 'yc iam create-token did not return a token',
250
+ next: 'yc init --federation-id <id>',
251
+ };
252
+ }
253
+
254
+ const lines = [
255
+ '# Yandex MCP settings — written by @bonesofspring/ai-rules. No token is stored here.',
256
+ `YANDEX_ORG_ID=${orgId}`,
257
+ `NO_PROXY=${noProxy}`,
258
+ ];
259
+ const federationId = existing.YANDEX_FEDERATION_ID;
260
+ if (federationId) {
261
+ lines.push(`YANDEX_FEDERATION_ID=${federationId}`);
262
+ }
263
+ if (options.ycBin || existing.YC_BIN) {
264
+ lines.push(`YC_BIN=${options.ycBin || existing.YC_BIN}`);
265
+ }
266
+ lines.push('');
267
+
268
+ writeFile(cwd, CONFIG_REL, lines.join('\n'), 0o644);
269
+ ensureAiRulesIgnored(cwd);
270
+
271
+ return { ok: true, detail: `organization ${orgId} saved to ${CONFIG_REL} (0644, ignored)`, warnings };
272
+ }
273
+
274
+ /** `mcp remove --purge`: credentials and config only, never `.ai-rules/.gitignore`. */
275
+ function purgeCredentials(cwd) {
276
+ const removed = [];
277
+ for (const rel of [CREDENTIALS_REL, CONFIG_REL]) {
278
+ const abs = resolveManagedPath(cwd, rel);
279
+ if (abs && fs.existsSync(abs)) {
280
+ fs.unlinkSync(abs);
281
+ removed.push(rel);
282
+ }
283
+ }
284
+ return removed;
285
+ }
286
+
287
+ module.exports = {
288
+ CREDENTIALS_REL,
289
+ CONFIG_REL,
290
+ IGNORE_REL,
291
+ ensureAiRulesIgnored,
292
+ checkIgnored,
293
+ normalizeGitlabUrl,
294
+ readCredentials,
295
+ setupGitlab,
296
+ setupYandex,
297
+ purgeCredentials,
298
+ };