@bonesofspring/ai-rules 0.2.57 → 0.2.60

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 (289) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +41 -3
  3. package/bin/cli.js +399 -27
  4. package/bin/lib/engine-scripts.js +3 -0
  5. package/bin/lib/mcp/catalog.js +97 -0
  6. package/bin/lib/mcp/clients.js +35 -2
  7. package/bin/lib/mcp/credentials.js +85 -1
  8. package/bin/lib/mcp/doctor.js +93 -17
  9. package/bin/lib/mcp/registry.js +10 -4
  10. package/bin/lib/seed-ai-local-team.js +8 -5
  11. package/docs/MCP-CATALOG.md +56 -0
  12. package/docs/MCP-SETUP.md +38 -6
  13. package/docs/PRESET-CONTRIBUTION.md +1 -0
  14. package/mcp/github-proxy.mjs +133 -0
  15. package/mcp/lib/github.mjs +187 -0
  16. package/mcp/lib/streamable-http.mjs +185 -0
  17. package/mcp/lib/yandex.mjs +16 -137
  18. package/package.json +3 -1
  19. package/presets/_shared/ai-local/scripts/check-write-scope.mjs +212 -0
  20. package/presets/_shared/ai-local/scripts/rule-improver.mjs +343 -50
  21. package/presets/_shared/ai-local/scripts/run.mjs +122 -3
  22. package/presets/_shared/core/agent-team/agent-team-orchestrator.md +12 -0
  23. package/presets/_shared/core/review/code-review-mr.md +10 -0
  24. package/presets/_shared/hooks/chain-team-phases.sh.tmpl +143 -1
  25. package/presets/claude/android-kotlin/commands/update.md +1 -0
  26. package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +143 -1
  27. package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  28. package/presets/claude/android-kotlin/rules/tooling-and-review/code-review.md +10 -0
  29. package/presets/claude/go/commands/update.md +1 -0
  30. package/presets/claude/go/hooks/chain-team-phases.sh +143 -1
  31. package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  32. package/presets/claude/go/rules/tooling-and-review/code-review.md +10 -0
  33. package/presets/claude/ios-swift/commands/update.md +1 -0
  34. package/presets/claude/ios-swift/hooks/chain-team-phases.sh +143 -1
  35. package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  36. package/presets/claude/ios-swift/rules/tooling-and-review/code-review.md +10 -0
  37. package/presets/claude/java/commands/update.md +1 -0
  38. package/presets/claude/java/hooks/chain-team-phases.sh +143 -1
  39. package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  40. package/presets/claude/java/rules/tooling-and-review/code-review.md +10 -0
  41. package/presets/claude/mcp-ts/commands/update.md +1 -0
  42. package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +143 -1
  43. package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  44. package/presets/claude/mcp-ts/rules/tooling-and-review/code-review.md +10 -0
  45. package/presets/claude/mol/commands/update.md +1 -0
  46. package/presets/claude/mol/hooks/chain-team-phases.sh +143 -1
  47. package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  48. package/presets/claude/mol/rules/tooling-and-review/code-review-mr.md +10 -0
  49. package/presets/claude/next/agents/build-verifier.md +2 -0
  50. package/presets/claude/next/agents/code-reviewer.md +8 -0
  51. package/presets/claude/next/commands/task-continue.md +3 -1
  52. package/presets/claude/next/commands/update.md +1 -0
  53. package/presets/claude/next/hooks/chain-team-phases.sh +143 -1
  54. package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  55. package/presets/claude/next/rules/tooling-and-review/code-review-mr.md +10 -0
  56. package/presets/claude/nuxt/commands/update.md +1 -0
  57. package/presets/claude/nuxt/hooks/chain-team-phases.sh +143 -1
  58. package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  59. package/presets/claude/nuxt/rules/tooling-and-review/code-review-mr.md +10 -0
  60. package/presets/claude/php-hexagonal/commands/update.md +1 -0
  61. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +143 -1
  62. package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  63. package/presets/claude/php-hexagonal/rules/tooling-and-review/code-review.md +10 -0
  64. package/presets/claude/php-laravel/commands/update.md +1 -0
  65. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +143 -1
  66. package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  67. package/presets/claude/php-laravel/rules/tooling-and-review/code-review.md +10 -0
  68. package/presets/claude/svelte/commands/update.md +1 -0
  69. package/presets/claude/svelte/hooks/chain-team-phases.sh +143 -1
  70. package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  71. package/presets/claude/svelte/rules/tooling-and-review/code-review-mr.md +10 -0
  72. package/presets/cursor/android-kotlin/commands/update.md +1 -0
  73. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +143 -1
  74. package/presets/cursor/android-kotlin/rules/code-review-mr.mdc +10 -0
  75. package/presets/cursor/go/commands/update.md +1 -0
  76. package/presets/cursor/go/hooks/chain-team-phases.sh +143 -1
  77. package/presets/cursor/go/rules/code-review-mr.mdc +10 -0
  78. package/presets/cursor/ios-swift/commands/update.md +1 -0
  79. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +143 -1
  80. package/presets/cursor/ios-swift/rules/code-review-mr.mdc +10 -0
  81. package/presets/cursor/java/commands/update.md +1 -0
  82. package/presets/cursor/java/hooks/chain-team-phases.sh +143 -1
  83. package/presets/cursor/java/rules/code-review-mr.mdc +10 -0
  84. package/presets/cursor/mcp-ts/commands/update.md +1 -0
  85. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +143 -1
  86. package/presets/cursor/mcp-ts/rules/code-review-mr.mdc +10 -0
  87. package/presets/cursor/mol/MCP.md +4 -3
  88. package/presets/cursor/mol/commands/update.md +1 -0
  89. package/presets/cursor/mol/hooks/chain-team-phases.sh +143 -1
  90. package/presets/cursor/mol/rules/code-review-mr.mdc +10 -0
  91. package/presets/cursor/next/MCP.md +4 -3
  92. package/presets/cursor/next/agents/build-verifier.md +2 -0
  93. package/presets/cursor/next/agents/code-reviewer.md +8 -0
  94. package/presets/cursor/next/commands/task-continue.md +3 -1
  95. package/presets/cursor/next/commands/update.md +1 -0
  96. package/presets/cursor/next/hooks/chain-team-phases.sh +143 -1
  97. package/presets/cursor/next/rules/code-review-mr.mdc +10 -0
  98. package/presets/cursor/nuxt/commands/update.md +1 -0
  99. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +143 -1
  100. package/presets/cursor/nuxt/rules/code-review-mr.mdc +10 -0
  101. package/presets/cursor/php-hexagonal/commands/update.md +1 -0
  102. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +143 -1
  103. package/presets/cursor/php-hexagonal/rules/code-review-mr.mdc +10 -0
  104. package/presets/cursor/php-laravel/commands/update.md +1 -0
  105. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +143 -1
  106. package/presets/cursor/php-laravel/rules/code-review-mr.mdc +10 -0
  107. package/presets/cursor/svelte/commands/update.md +1 -0
  108. package/presets/cursor/svelte/hooks/chain-team-phases.sh +143 -1
  109. package/presets/cursor/svelte/rules/code-review-mr.mdc +10 -0
  110. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  111. package/presets/mavis/android-kotlin/commands/update.md +1 -0
  112. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +143 -1
  113. package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +12 -0
  114. package/presets/mavis/android-kotlin/rules/code-review-mr.md +10 -0
  115. package/presets/mavis/go/adapter-map.json +1 -1
  116. package/presets/mavis/go/commands/update.md +1 -0
  117. package/presets/mavis/go/hooks/chain-team-phases.sh +143 -1
  118. package/presets/mavis/go/rules/agent-team-orchestrator.md +12 -0
  119. package/presets/mavis/go/rules/code-review-mr.md +10 -0
  120. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  121. package/presets/mavis/ios-swift/commands/update.md +1 -0
  122. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +143 -1
  123. package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +12 -0
  124. package/presets/mavis/ios-swift/rules/code-review-mr.md +10 -0
  125. package/presets/mavis/java/adapter-map.json +1 -1
  126. package/presets/mavis/java/commands/update.md +1 -0
  127. package/presets/mavis/java/hooks/chain-team-phases.sh +143 -1
  128. package/presets/mavis/java/rules/agent-team-orchestrator.md +12 -0
  129. package/presets/mavis/java/rules/code-review-mr.md +10 -0
  130. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  131. package/presets/mavis/mcp-ts/commands/update.md +1 -0
  132. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +143 -1
  133. package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +12 -0
  134. package/presets/mavis/mcp-ts/rules/code-review-mr.md +10 -0
  135. package/presets/mavis/mol/MCP.md +4 -3
  136. package/presets/mavis/mol/adapter-map.json +1 -1
  137. package/presets/mavis/mol/commands/update.md +1 -0
  138. package/presets/mavis/mol/hooks/chain-team-phases.sh +143 -1
  139. package/presets/mavis/mol/rules/agent-team-orchestrator.md +12 -0
  140. package/presets/mavis/mol/rules/code-review-mr.md +10 -0
  141. package/presets/mavis/next/MCP.md +4 -3
  142. package/presets/mavis/next/adapter-map.json +1 -1
  143. package/presets/mavis/next/agents/build-verifier.md +2 -0
  144. package/presets/mavis/next/agents/code-reviewer.md +8 -0
  145. package/presets/mavis/next/commands/task-continue.md +3 -1
  146. package/presets/mavis/next/commands/update.md +1 -0
  147. package/presets/mavis/next/hooks/chain-team-phases.sh +143 -1
  148. package/presets/mavis/next/rules/agent-team-orchestrator.md +12 -0
  149. package/presets/mavis/next/rules/code-review-mr.md +10 -0
  150. package/presets/mavis/nuxt/adapter-map.json +1 -1
  151. package/presets/mavis/nuxt/commands/update.md +1 -0
  152. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +143 -1
  153. package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +12 -0
  154. package/presets/mavis/nuxt/rules/code-review-mr.md +10 -0
  155. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  156. package/presets/mavis/php-hexagonal/commands/update.md +1 -0
  157. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +143 -1
  158. package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +12 -0
  159. package/presets/mavis/php-hexagonal/rules/code-review-mr.md +10 -0
  160. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  161. package/presets/mavis/php-laravel/commands/update.md +1 -0
  162. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +143 -1
  163. package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +12 -0
  164. package/presets/mavis/php-laravel/rules/code-review-mr.md +10 -0
  165. package/presets/mavis/svelte/adapter-map.json +1 -1
  166. package/presets/mavis/svelte/commands/update.md +1 -0
  167. package/presets/mavis/svelte/hooks/chain-team-phases.sh +143 -1
  168. package/presets/mavis/svelte/rules/agent-team-orchestrator.md +12 -0
  169. package/presets/mavis/svelte/rules/code-review-mr.md +10 -0
  170. package/presets/opencode/android-kotlin/adapter-map.json +1 -1
  171. package/presets/opencode/android-kotlin/commands/update.md +1 -0
  172. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +143 -1
  173. package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +12 -0
  174. package/presets/opencode/android-kotlin/rules/code-review-mr.md +10 -0
  175. package/presets/opencode/go/adapter-map.json +1 -1
  176. package/presets/opencode/go/commands/update.md +1 -0
  177. package/presets/opencode/go/hooks/chain-team-phases.sh +143 -1
  178. package/presets/opencode/go/rules/agent-team-orchestrator.md +12 -0
  179. package/presets/opencode/go/rules/code-review-mr.md +10 -0
  180. package/presets/opencode/ios-swift/adapter-map.json +1 -1
  181. package/presets/opencode/ios-swift/commands/update.md +1 -0
  182. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +143 -1
  183. package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +12 -0
  184. package/presets/opencode/ios-swift/rules/code-review-mr.md +10 -0
  185. package/presets/opencode/java/adapter-map.json +1 -1
  186. package/presets/opencode/java/commands/update.md +1 -0
  187. package/presets/opencode/java/hooks/chain-team-phases.sh +143 -1
  188. package/presets/opencode/java/rules/agent-team-orchestrator.md +12 -0
  189. package/presets/opencode/java/rules/code-review-mr.md +10 -0
  190. package/presets/opencode/mcp-ts/adapter-map.json +1 -1
  191. package/presets/opencode/mcp-ts/commands/update.md +1 -0
  192. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +143 -1
  193. package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +12 -0
  194. package/presets/opencode/mcp-ts/rules/code-review-mr.md +10 -0
  195. package/presets/opencode/mol/MCP.md +4 -3
  196. package/presets/opencode/mol/adapter-map.json +1 -1
  197. package/presets/opencode/mol/commands/update.md +1 -0
  198. package/presets/opencode/mol/hooks/chain-team-phases.sh +143 -1
  199. package/presets/opencode/mol/rules/agent-team-orchestrator.md +12 -0
  200. package/presets/opencode/mol/rules/code-review-mr.md +10 -0
  201. package/presets/opencode/next/MCP.md +4 -3
  202. package/presets/opencode/next/adapter-map.json +1 -1
  203. package/presets/opencode/next/agents/build-verifier.md +2 -0
  204. package/presets/opencode/next/agents/code-reviewer.md +8 -0
  205. package/presets/opencode/next/commands/task-continue.md +3 -1
  206. package/presets/opencode/next/commands/update.md +1 -0
  207. package/presets/opencode/next/hooks/chain-team-phases.sh +143 -1
  208. package/presets/opencode/next/rules/agent-team-orchestrator.md +12 -0
  209. package/presets/opencode/next/rules/code-review-mr.md +10 -0
  210. package/presets/opencode/nuxt/adapter-map.json +1 -1
  211. package/presets/opencode/nuxt/commands/update.md +1 -0
  212. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +143 -1
  213. package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +12 -0
  214. package/presets/opencode/nuxt/rules/code-review-mr.md +10 -0
  215. package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
  216. package/presets/opencode/php-hexagonal/commands/update.md +1 -0
  217. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +143 -1
  218. package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +12 -0
  219. package/presets/opencode/php-hexagonal/rules/code-review-mr.md +10 -0
  220. package/presets/opencode/php-laravel/adapter-map.json +1 -1
  221. package/presets/opencode/php-laravel/commands/update.md +1 -0
  222. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +143 -1
  223. package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +12 -0
  224. package/presets/opencode/php-laravel/rules/code-review-mr.md +10 -0
  225. package/presets/opencode/svelte/adapter-map.json +1 -1
  226. package/presets/opencode/svelte/commands/update.md +1 -0
  227. package/presets/opencode/svelte/hooks/chain-team-phases.sh +143 -1
  228. package/presets/opencode/svelte/rules/agent-team-orchestrator.md +12 -0
  229. package/presets/opencode/svelte/rules/code-review-mr.md +10 -0
  230. package/presets/zcode/android-kotlin/adapter-map.json +1 -1
  231. package/presets/zcode/android-kotlin/commands/update.md +1 -0
  232. package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +143 -1
  233. package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +12 -0
  234. package/presets/zcode/android-kotlin/rules/code-review-mr.md +10 -0
  235. package/presets/zcode/go/adapter-map.json +1 -1
  236. package/presets/zcode/go/commands/update.md +1 -0
  237. package/presets/zcode/go/hooks/chain-team-phases.sh +143 -1
  238. package/presets/zcode/go/rules/agent-team-orchestrator.md +12 -0
  239. package/presets/zcode/go/rules/code-review-mr.md +10 -0
  240. package/presets/zcode/ios-swift/adapter-map.json +1 -1
  241. package/presets/zcode/ios-swift/commands/update.md +1 -0
  242. package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +143 -1
  243. package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +12 -0
  244. package/presets/zcode/ios-swift/rules/code-review-mr.md +10 -0
  245. package/presets/zcode/java/adapter-map.json +1 -1
  246. package/presets/zcode/java/commands/update.md +1 -0
  247. package/presets/zcode/java/hooks/chain-team-phases.sh +143 -1
  248. package/presets/zcode/java/rules/agent-team-orchestrator.md +12 -0
  249. package/presets/zcode/java/rules/code-review-mr.md +10 -0
  250. package/presets/zcode/mcp-ts/adapter-map.json +1 -1
  251. package/presets/zcode/mcp-ts/commands/update.md +1 -0
  252. package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +143 -1
  253. package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +12 -0
  254. package/presets/zcode/mcp-ts/rules/code-review-mr.md +10 -0
  255. package/presets/zcode/mol/MCP.md +4 -3
  256. package/presets/zcode/mol/adapter-map.json +1 -1
  257. package/presets/zcode/mol/commands/update.md +1 -0
  258. package/presets/zcode/mol/hooks/chain-team-phases.sh +143 -1
  259. package/presets/zcode/mol/rules/agent-team-orchestrator.md +12 -0
  260. package/presets/zcode/mol/rules/code-review-mr.md +10 -0
  261. package/presets/zcode/next/MCP.md +4 -3
  262. package/presets/zcode/next/adapter-map.json +1 -1
  263. package/presets/zcode/next/agents/build-verifier.md +2 -0
  264. package/presets/zcode/next/agents/code-reviewer.md +8 -0
  265. package/presets/zcode/next/commands/task-continue.md +3 -1
  266. package/presets/zcode/next/commands/update.md +1 -0
  267. package/presets/zcode/next/hooks/chain-team-phases.sh +143 -1
  268. package/presets/zcode/next/rules/agent-team-orchestrator.md +12 -0
  269. package/presets/zcode/next/rules/code-review-mr.md +10 -0
  270. package/presets/zcode/nuxt/adapter-map.json +1 -1
  271. package/presets/zcode/nuxt/commands/update.md +1 -0
  272. package/presets/zcode/nuxt/hooks/chain-team-phases.sh +143 -1
  273. package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +12 -0
  274. package/presets/zcode/nuxt/rules/code-review-mr.md +10 -0
  275. package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
  276. package/presets/zcode/php-hexagonal/commands/update.md +1 -0
  277. package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +143 -1
  278. package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +12 -0
  279. package/presets/zcode/php-hexagonal/rules/code-review-mr.md +10 -0
  280. package/presets/zcode/php-laravel/adapter-map.json +1 -1
  281. package/presets/zcode/php-laravel/commands/update.md +1 -0
  282. package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +143 -1
  283. package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +12 -0
  284. package/presets/zcode/php-laravel/rules/code-review-mr.md +10 -0
  285. package/presets/zcode/svelte/adapter-map.json +1 -1
  286. package/presets/zcode/svelte/commands/update.md +1 -0
  287. package/presets/zcode/svelte/hooks/chain-team-phases.sh +143 -1
  288. package/presets/zcode/svelte/rules/agent-team-orchestrator.md +12 -0
  289. package/presets/zcode/svelte/rules/code-review-mr.md +10 -0
@@ -0,0 +1,133 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * GitHub MCP server (stdio JSON-RPC 2.0 ↔ streamable HTTP).
4
+ *
5
+ * The client starts this through `npx -y @bonesofspring/ai-rules@<version> mcp
6
+ * run github`. It forwards every JSON-RPC message to the official remote GitHub
7
+ * MCP server with the token from `.env.github` (or the shell), so no token ever
8
+ * reaches a client config or an argv.
9
+ */
10
+ import { createInterface } from 'node:readline';
11
+ import run from '../bin/lib/mcp/run.js';
12
+ import { ConfigError } from './lib/envfile.mjs';
13
+ import { loadGitHubConfig, printEnv } from './lib/github.mjs';
14
+ import { HttpStatusError, TransportError, postStreamable } from './lib/streamable-http.mjs';
15
+
16
+ const { resolveProjectRoot } = run;
17
+
18
+ let config;
19
+ let sessionId;
20
+ let protocolVersion;
21
+
22
+ function write(message) {
23
+ process.stdout.write(`${JSON.stringify(message)}\n`);
24
+ }
25
+
26
+ function fail(id, code, message) {
27
+ write({ jsonrpc: '2.0', id, error: { code, message } });
28
+ }
29
+
30
+ async function relay(message) {
31
+ const isInitialize = message.method === 'initialize';
32
+
33
+ const result = await postStreamable({
34
+ url: config.mcpUrl,
35
+ headers: { Authorization: `Bearer ${config.token}` },
36
+ sessionId,
37
+ protocolVersion: isInitialize ? undefined : protocolVersion,
38
+ message,
39
+ });
40
+
41
+ if (result.sessionId) {
42
+ sessionId = result.sessionId;
43
+ }
44
+
45
+ if (isInitialize) {
46
+ const negotiated = result.messages.find((entry) => entry && entry.result)?.result?.protocolVersion;
47
+ protocolVersion = typeof negotiated === 'string' ? negotiated : undefined;
48
+ }
49
+
50
+ return result.messages;
51
+ }
52
+
53
+ async function handle(message) {
54
+ const { id, method } = message;
55
+
56
+ if (method === undefined) {
57
+ return;
58
+ }
59
+
60
+ try {
61
+ const messages = await relay(message);
62
+
63
+ if (id === undefined) {
64
+ return; // notification — no response expected
65
+ }
66
+
67
+ for (const emitted of messages) {
68
+ write(emitted);
69
+ }
70
+ } catch (error) {
71
+ if (id === undefined) {
72
+ return;
73
+ }
74
+
75
+ if (error instanceof HttpStatusError) {
76
+ fail(id, -32603, `GitHub MCP server → HTTP ${error.status}`);
77
+ return;
78
+ }
79
+
80
+ if (error instanceof TransportError) {
81
+ fail(id, -32603, `GitHub MCP server is unreachable: ${error.reason}`);
82
+ return;
83
+ }
84
+
85
+ fail(id, -32603, error instanceof Error ? error.message : String(error));
86
+ }
87
+ }
88
+
89
+ function main() {
90
+ config = loadGitHubConfig({ root: resolveProjectRoot() });
91
+
92
+ if (process.argv.includes('--print-env')) {
93
+ printEnv(config);
94
+ return;
95
+ }
96
+
97
+ const reader = createInterface({ input: process.stdin, crlfDelay: Infinity });
98
+ let chain = Promise.resolve();
99
+
100
+ reader.on('line', (line) => {
101
+ const trimmed = line.trim();
102
+
103
+ if (!trimmed) {
104
+ return;
105
+ }
106
+
107
+ let message;
108
+
109
+ try {
110
+ message = JSON.parse(trimmed);
111
+ } catch {
112
+ fail(null, -32700, 'Parse error');
113
+ return;
114
+ }
115
+
116
+ chain = chain.then(() => handle(message)).catch(() => undefined);
117
+ });
118
+
119
+ reader.on('close', () => {
120
+ chain.then(() => process.exit(0));
121
+ });
122
+ }
123
+
124
+ try {
125
+ main();
126
+ } catch (error) {
127
+ const message = error instanceof Error ? error.message : String(error);
128
+ process.stderr.write(`${message}\n`);
129
+ if (error instanceof ConfigError) {
130
+ process.stderr.write('next: add GITHUB_TOKEN to .env.github and reconnect the MCP server\n');
131
+ }
132
+ process.exit(1);
133
+ }
@@ -0,0 +1,187 @@
1
+ /**
2
+ * GitHub MCP support: the official remote GitHub MCP server over streamable HTTP.
3
+ *
4
+ * The package never writes a GitHub token. The token is read from the shell
5
+ * environment or from the project's `.env.github` (`GITHUB_TOKEN` /
6
+ * `GITHUB_PERSONAL_ACCESS_TOKEN`). Both endpoints are overridable
7
+ * (`GITHUB_MCP_URL`, `GITHUB_API_URL`) so a stub or an enterprise relay can
8
+ * be used instead of the public endpoints.
9
+ */
10
+ import { existsSync } from 'node:fs';
11
+ import { join } from 'node:path';
12
+ import run from '../../bin/lib/mcp/run.js';
13
+ import { ConfigError, readEnvFile } from './envfile.mjs';
14
+ import { HttpStatusError, TransportError, postStreamable } from './streamable-http.mjs';
15
+
16
+ const { resolveProjectRoot } = run;
17
+
18
+ export const CREDENTIALS_FILE = '.env.github';
19
+ export const DEFAULT_MCP_URL = 'https://api.githubcopilot.com/mcp/';
20
+ export const DEFAULT_API_URL = 'https://api.github.com';
21
+
22
+ const TOKEN_KEYS = ['GITHUB_TOKEN', 'GITHUB_PERSONAL_ACCESS_TOKEN'];
23
+ const MCP_URL_KEY = 'GITHUB_MCP_URL';
24
+ const API_URL_KEY = 'GITHUB_API_URL';
25
+
26
+ /** The shell environment wins over the file; the first key wins inside each. */
27
+ function firstToken(env, fileValues) {
28
+ for (const key of TOKEN_KEYS) {
29
+ const value = env[key];
30
+ if (typeof value === 'string' && value.trim() !== '') {
31
+ return { value: value.trim(), key, origin: 'the environment' };
32
+ }
33
+ }
34
+ for (const key of TOKEN_KEYS) {
35
+ const value = fileValues[key];
36
+ if (typeof value === 'string' && value.trim() !== '') {
37
+ return { value: value.trim(), key, origin: CREDENTIALS_FILE };
38
+ }
39
+ }
40
+ return null;
41
+ }
42
+
43
+ function firstUrl(env, fileValues, key, fallback) {
44
+ for (const source of [env[key], fileValues[key]]) {
45
+ if (typeof source === 'string' && source.trim() !== '') {
46
+ return source.trim();
47
+ }
48
+ }
49
+ return fallback;
50
+ }
51
+
52
+ /**
53
+ * Resolve the GitHub MCP configuration for a project.
54
+ *
55
+ * @param {object} [options]
56
+ * @param {NodeJS.ProcessEnv} [options.env]
57
+ * @param {string} [options.root] Project root; the credentials file is read there.
58
+ * @returns {{ token: string | null, tokenKey: string | null, tokenOrigin: string | null, credentialsPath: string, hasCredentialsFile: boolean, fileHasToken: boolean, mcpUrl: string, apiUrl: string }}
59
+ */
60
+ export function resolveGithubConfig({ env = process.env, root = resolveProjectRoot() } = {}) {
61
+ const credentialsPath = join(root, CREDENTIALS_FILE);
62
+ const fileValues = readEnvFile(credentialsPath);
63
+ const token = firstToken(env, fileValues);
64
+ const fileToken = firstToken({}, fileValues);
65
+
66
+ return {
67
+ token: token?.value ?? null,
68
+ tokenKey: token?.key ?? null,
69
+ tokenOrigin: token?.origin ?? null,
70
+ credentialsPath,
71
+ hasCredentialsFile: existsSync(credentialsPath),
72
+ // A secret at rest: the file holds a token even when the shell shadows it.
73
+ fileHasToken: Boolean(fileToken),
74
+ mcpUrl: firstUrl(env, fileValues, MCP_URL_KEY, DEFAULT_MCP_URL),
75
+ apiUrl: firstUrl(env, fileValues, API_URL_KEY, DEFAULT_API_URL),
76
+ };
77
+ }
78
+
79
+ /**
80
+ * Same as {@link resolveGithubConfig}, but a missing token is an error.
81
+ *
82
+ * @returns {{ token: string, tokenKey: string, tokenOrigin: string, credentialsPath: string, hasCredentialsFile: boolean, fileHasToken: boolean, mcpUrl: string, apiUrl: string }}
83
+ */
84
+ export function loadGitHubConfig(options = {}) {
85
+ const config = resolveGithubConfig(options);
86
+
87
+ if (!config.token) {
88
+ throw new ConfigError(
89
+ `GITHUB_TOKEN is not set. Add GITHUB_TOKEN to ${CREDENTIALS_FILE} or export it in the shell.`,
90
+ );
91
+ }
92
+
93
+ return config;
94
+ }
95
+
96
+ /** `--print-env` is a masked mapping: the token value never reaches stdout. */
97
+ export function printEnv(config) {
98
+ process.stdout.write('GITHUB_TOKEN=***\n');
99
+ process.stdout.write(`GITHUB_MCP_URL=${config.mcpUrl}\n`);
100
+ process.stdout.write(`GITHUB_API_URL=${config.apiUrl}\n`);
101
+ }
102
+
103
+ /**
104
+ * Check the token against the GitHub REST API.
105
+ *
106
+ * @returns {Promise<{ ok: boolean, status: number, detail: string, login?: string }>}
107
+ */
108
+ export async function verifyGithubToken({ token, apiUrl = DEFAULT_API_URL, timeoutMs = 15_000 } = {}) {
109
+ let response;
110
+
111
+ try {
112
+ response = await fetch(`${apiUrl.replace(/\/+$/, '')}/user`, {
113
+ headers: {
114
+ Authorization: `Bearer ${token}`,
115
+ Accept: 'application/vnd.github+json',
116
+ 'User-Agent': 'ai-rules-mcp',
117
+ },
118
+ signal: AbortSignal.timeout(timeoutMs),
119
+ });
120
+ } catch {
121
+ return { ok: false, status: 0, detail: 'the GitHub API is not reachable' };
122
+ }
123
+
124
+ if (response.status === 200) {
125
+ let login = null;
126
+ try {
127
+ const body = await response.json();
128
+ login = typeof body?.login === 'string' ? body.login : null;
129
+ } catch {
130
+ login = null;
131
+ }
132
+ return {
133
+ ok: true,
134
+ status: 200,
135
+ detail: login ? `token valid for ${login}` : 'token valid',
136
+ login,
137
+ };
138
+ }
139
+
140
+ if (response.status === 401 || response.status === 403) {
141
+ return { ok: false, status: response.status, detail: `token rejected (${response.status})` };
142
+ }
143
+
144
+ return { ok: false, status: response.status, detail: `GET /user → ${response.status}` };
145
+ }
146
+
147
+ /**
148
+ * Open an MCP session against the GitHub MCP server and report whether the
149
+ * endpoint and the token are both usable.
150
+ *
151
+ * @returns {Promise<{ ok: boolean, status: number, detail: string }>}
152
+ */
153
+ export async function probeGithubUpstream({ token, mcpUrl = DEFAULT_MCP_URL, timeoutMs = 30_000 } = {}) {
154
+ const message = {
155
+ jsonrpc: '2.0',
156
+ id: 1,
157
+ method: 'initialize',
158
+ params: {
159
+ protocolVersion: '2025-06-18',
160
+ capabilities: {},
161
+ clientInfo: { name: 'ai-rules-doctor', version: '1.0.0' },
162
+ },
163
+ };
164
+
165
+ try {
166
+ const result = await postStreamable({
167
+ url: mcpUrl,
168
+ headers: { Authorization: `Bearer ${token}`, 'User-Agent': 'ai-rules-mcp' },
169
+ message,
170
+ timeoutMs,
171
+ });
172
+
173
+ const initialized = result.messages.find((entry) => entry && entry.id === 1 && entry.result);
174
+ if (initialized) {
175
+ return { ok: true, status: 200, detail: 'initialize → 200' };
176
+ }
177
+ return { ok: false, status: 200, detail: 'initialize → no result' };
178
+ } catch (error) {
179
+ if (error instanceof HttpStatusError) {
180
+ return { ok: false, status: error.status, detail: `initialize → HTTP ${error.status}` };
181
+ }
182
+ if (error instanceof TransportError) {
183
+ return { ok: false, status: 0, detail: `initialize failed: ${error.reason}` };
184
+ }
185
+ throw error;
186
+ }
187
+ }
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Shared MCP streamable-HTTP transport.
3
+ *
4
+ * One POST per JSON-RPC message; the response is either a JSON body or an SSE
5
+ * stream. Providers own the headers, the session, the error wording and the
6
+ * token redaction — this module owns the wire format only.
7
+ */
8
+
9
+ /** The server answered with a non-2xx status. */
10
+ export class HttpStatusError extends Error {
11
+ constructor(status, detail) {
12
+ super(`HTTP ${status}`);
13
+ this.name = 'HttpStatusError';
14
+ this.status = status;
15
+ this.detail = detail ?? '';
16
+ }
17
+ }
18
+
19
+ /** The request never reached the server (DNS, TLS, timeout, refused). */
20
+ export class TransportError extends Error {
21
+ constructor(reason) {
22
+ super(reason);
23
+ this.name = 'TransportError';
24
+ this.reason = reason;
25
+ }
26
+ }
27
+
28
+ export function readSessionId(response) {
29
+ return response.headers.get('Mcp-Session-Id') ?? response.headers.get('mcp-session-id') ?? undefined;
30
+ }
31
+
32
+ export async function safeText(response) {
33
+ try {
34
+ return await response.text();
35
+ } catch {
36
+ return null;
37
+ }
38
+ }
39
+
40
+ export function truncate(text, limit = 1000) {
41
+ return text.length > limit ? `${text.slice(0, limit)}…` : text;
42
+ }
43
+
44
+ /** A JSON body carries one message or a batch; both become a message list. */
45
+ export async function readJsonMessage(response) {
46
+ const text = await safeText(response);
47
+ if (!text) {
48
+ return [];
49
+ }
50
+ try {
51
+ const parsed = JSON.parse(text);
52
+ return Array.isArray(parsed) ? parsed : [parsed];
53
+ } catch {
54
+ return [];
55
+ }
56
+ }
57
+
58
+ export async function readSseMessages(response) {
59
+ const reader = response.body.getReader();
60
+ const decoder = new TextDecoder();
61
+ const messages = [];
62
+ let buffer = '';
63
+ let dataLines = [];
64
+
65
+ const flush = () => {
66
+ if (dataLines.length === 0) {
67
+ return;
68
+ }
69
+
70
+ const data = dataLines.join('\n');
71
+ dataLines = [];
72
+
73
+ try {
74
+ messages.push(JSON.parse(data));
75
+ } catch {
76
+ // Skip non-JSON SSE payloads (keep-alive comments, partial events).
77
+ }
78
+ };
79
+
80
+ while (true) {
81
+ const { done, value } = await reader.read();
82
+
83
+ if (done) {
84
+ break;
85
+ }
86
+
87
+ buffer += decoder.decode(value, { stream: true });
88
+
89
+ const lines = buffer.split(/\r?\n/);
90
+ buffer = lines.pop() ?? '';
91
+
92
+ for (const rawLine of lines) {
93
+ const line = rawLine.trim();
94
+
95
+ if (line === '') {
96
+ flush();
97
+ continue;
98
+ }
99
+
100
+ if (line.startsWith(':')) {
101
+ continue;
102
+ }
103
+
104
+ if (line.startsWith('data:')) {
105
+ dataLines.push(line.slice(5).trimStart());
106
+ }
107
+ }
108
+ }
109
+
110
+ if (buffer.trim() !== '') {
111
+ const line = buffer.trim();
112
+
113
+ if (line.startsWith('data:')) {
114
+ dataLines.push(line.slice(5).trimStart());
115
+ }
116
+ }
117
+
118
+ flush();
119
+
120
+ return messages;
121
+ }
122
+
123
+ /**
124
+ * Forward one JSON-RPC message and return the messages the server sent back.
125
+ *
126
+ * @param {object} options
127
+ * @param {string} options.url
128
+ * @param {Record<string, string>} [options.headers]
129
+ * @param {string} [options.sessionId]
130
+ * @param {string} [options.protocolVersion]
131
+ * @param {object} options.message
132
+ * @param {number} [options.timeoutMs]
133
+ * @returns {Promise<{ sessionId: string | undefined, messages: object[] }>}
134
+ */
135
+ export async function postStreamable({
136
+ url,
137
+ headers = {},
138
+ sessionId,
139
+ protocolVersion,
140
+ message,
141
+ timeoutMs = 120_000,
142
+ }) {
143
+ const requestHeaders = {
144
+ 'Content-Type': 'application/json',
145
+ Accept: 'application/json, text/event-stream',
146
+ ...headers,
147
+ };
148
+
149
+ if (sessionId) {
150
+ requestHeaders['Mcp-Session-Id'] = sessionId;
151
+ }
152
+
153
+ if (protocolVersion) {
154
+ requestHeaders['MCP-Protocol-Version'] = protocolVersion;
155
+ }
156
+
157
+ let response;
158
+
159
+ try {
160
+ response = await fetch(url, {
161
+ method: 'POST',
162
+ headers: requestHeaders,
163
+ body: JSON.stringify(message),
164
+ signal: AbortSignal.timeout(timeoutMs),
165
+ });
166
+ } catch (error) {
167
+ throw new TransportError(error instanceof Error ? error.message : String(error));
168
+ }
169
+
170
+ if (response.status === 202 || response.status === 204) {
171
+ return { sessionId: readSessionId(response), messages: [] };
172
+ }
173
+
174
+ if (!response.ok) {
175
+ throw new HttpStatusError(response.status, await safeText(response));
176
+ }
177
+
178
+ const nextSessionId = readSessionId(response);
179
+ const contentType = response.headers.get('content-type') ?? '';
180
+ const messages = contentType.includes('text/event-stream')
181
+ ? await readSseMessages(response)
182
+ : await readJsonMessage(response);
183
+
184
+ return { sessionId: nextSessionId, messages };
185
+ }
@@ -13,6 +13,7 @@ import { spawn } from 'node:child_process';
13
13
  import { delimiter, join } from 'node:path';
14
14
  import run from '../../bin/lib/mcp/run.js';
15
15
  import { ConfigError, loadEnvStack, redactToken } from './envfile.mjs';
16
+ import { HttpStatusError, TransportError, postStreamable, truncate } from './streamable-http.mjs';
16
17
 
17
18
  const { resolveProjectRoot } = run;
18
19
 
@@ -226,101 +227,6 @@ export async function fetchToken({
226
227
  return { token };
227
228
  }
228
229
 
229
- function readSessionId(response) {
230
- return response.headers.get('Mcp-Session-Id') ?? response.headers.get('mcp-session-id') ?? undefined;
231
- }
232
-
233
- async function safeText(response) {
234
- try {
235
- return await response.text();
236
- } catch {
237
- return null;
238
- }
239
- }
240
-
241
- function truncate(text, limit = 1000) {
242
- return text.length > limit ? `${text.slice(0, limit)}…` : text;
243
- }
244
-
245
- async function readJsonMessage(response) {
246
- const text = await safeText(response);
247
-
248
- if (!text) {
249
- return [];
250
- }
251
-
252
- try {
253
- return [JSON.parse(text)];
254
- } catch {
255
- return [];
256
- }
257
- }
258
-
259
- async function readSseMessages(response) {
260
- const reader = response.body.getReader();
261
- const decoder = new TextDecoder();
262
- const messages = [];
263
- let buffer = '';
264
- let dataLines = [];
265
-
266
- const flush = () => {
267
- if (dataLines.length === 0) {
268
- return;
269
- }
270
-
271
- const data = dataLines.join('\n');
272
- dataLines = [];
273
-
274
- try {
275
- messages.push(JSON.parse(data));
276
- } catch {
277
- // Skip non-JSON SSE payloads (keep-alive comments, partial events).
278
- }
279
- };
280
-
281
- while (true) {
282
- const { done, value } = await reader.read();
283
-
284
- if (done) {
285
- break;
286
- }
287
-
288
- buffer += decoder.decode(value, { stream: true });
289
-
290
- const lines = buffer.split(/\r?\n/);
291
- buffer = lines.pop() ?? '';
292
-
293
- for (const rawLine of lines) {
294
- const line = rawLine.trim();
295
-
296
- if (line === '') {
297
- flush();
298
- continue;
299
- }
300
-
301
- if (line.startsWith(':')) {
302
- continue;
303
- }
304
-
305
- if (line.startsWith('data:')) {
306
- dataLines.push(line.slice(5).trimStart());
307
- }
308
- }
309
- }
310
-
311
- if (buffer.trim() !== '') {
312
- const line = buffer.trim();
313
-
314
- if (line.startsWith('data:')) {
315
- dataLines.push(line.slice(5).trimStart());
316
- }
317
- }
318
-
319
- flush();
320
-
321
- return messages;
322
- }
323
-
324
230
  /**
325
231
  * Forward one JSON-RPC message to the upstream MCP endpoint. Returns the
326
232
  * JSON-RPC message(s) to re-emit on stdout (empty for notifications/202/204)
@@ -329,56 +235,29 @@ async function readSseMessages(response) {
329
235
  */
330
236
  export async function postJsonRpc({ url, token, orgId, sessionId, protocolVersion, message }) {
331
237
  const headers = {
332
- 'Content-Type': 'application/json',
333
- Accept: 'application/json, text/event-stream',
334
238
  Authorization: `Bearer ${token}`,
335
239
  'X-Cloud-Org-ID': orgId,
336
240
  };
337
241
 
338
- if (sessionId) {
339
- headers['Mcp-Session-Id'] = sessionId;
340
- }
341
-
342
- // MCP streamable-HTTP requires the protocol version header on initialize.
343
- if (protocolVersion) {
344
- headers['MCP-Protocol-Version'] = protocolVersion;
345
- }
346
-
347
- let response;
348
-
349
242
  try {
350
- response = await fetch(url, {
351
- method: 'POST',
352
- headers,
353
- body: JSON.stringify(message),
354
- signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
355
- });
356
- } catch (error) {
357
- const reason = error instanceof Error ? error.message : String(error);
358
- throw new UpstreamError(`POST ${url} failed: ${redactToken(reason, token)}`);
359
- }
360
-
361
- if (response.status === 401) {
362
- throw new UnauthorizedError('HTTP 401');
363
- }
243
+ const result = await postStreamable({ url, headers, sessionId, protocolVersion, message, timeoutMs: REQUEST_TIMEOUT_MS });
364
244
 
365
- if (response.status === 202 || response.status === 204) {
366
- return { sessionId: readSessionId(response), messages: [] };
367
- }
245
+ return result;
246
+ } catch (error) {
247
+ if (error instanceof TransportError) {
248
+ throw new UpstreamError(`POST ${url} failed: ${redactToken(error.reason, token)}`);
249
+ }
368
250
 
369
- if (!response.ok) {
370
- const detail = await safeText(response);
371
- throw new UpstreamError(
372
- `POST ${url} → HTTP ${response.status}: ${truncate(redactToken(detail ?? '', token))}`,
373
- );
374
- }
251
+ if (error instanceof HttpStatusError) {
252
+ if (error.status === 401) {
253
+ throw new UnauthorizedError('HTTP 401');
254
+ }
375
255
 
376
- const nextSessionId = readSessionId(response);
377
- const contentType = response.headers.get('content-type') ?? '';
256
+ throw new UpstreamError(
257
+ `POST ${url} → HTTP ${error.status}: ${truncate(redactToken(error.detail ?? '', token))}`,
258
+ );
259
+ }
378
260
 
379
- if (contentType.includes('text/event-stream')) {
380
- return { sessionId: nextSessionId, messages: await readSseMessages(response) };
261
+ throw error;
381
262
  }
382
-
383
- return { sessionId: nextSessionId, messages: await readJsonMessage(response) };
384
263
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonesofspring/ai-rules",
3
- "version": "0.2.57",
3
+ "version": "0.2.60",
4
4
  "description": "Presets of Cursor, Claude, Mavis, OpenCode, and ZCode rules/commands for Revy Ross personal use",
5
5
  "license": "MIT",
6
6
  "author": "Revy Ross",
@@ -29,6 +29,7 @@
29
29
  "mcp",
30
30
  "docs",
31
31
  "presets",
32
+ "presets/_shared/ai-local/scripts/check-write-scope.mjs",
32
33
  "scripts/check-product-specs.sh",
33
34
  "scripts/aggregate-agent-task-metrics.mjs",
34
35
  "scripts/close-agent-task-human-gate.mjs"
@@ -77,6 +78,7 @@
77
78
  "test:cli-init-clean": "node scripts/test-cli-init-clean.mjs",
78
79
  "test:cli-update": "node scripts/test-cli-update.mjs",
79
80
  "test:cli-mcp-registration": "node scripts/test-cli-mcp-registration.mjs",
81
+ "test:cli-mcp-catalog": "node scripts/test-cli-mcp-catalog.mjs",
80
82
  "test:mcp-pack-tarball": "node scripts/test-mcp-pack-tarball.mjs",
81
83
  "test:chain-coverage": "node scripts/test-chain-team-phases-coverage.mjs",
82
84
  "test:agent-task-metrics-hooks": "node scripts/test-agent-task-metrics-hooks.mjs",