@bevel-software/platform-core-backend 0.13.6 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (456) hide show
  1. package/THIRD-PARTY-NOTICES.md +6 -6
  2. package/dist/core/catalog-cache-invalidation.d.ts +29 -0
  3. package/dist/core/catalog-cache-invalidation.d.ts.map +1 -0
  4. package/dist/core/catalog-cache-invalidation.js +71 -0
  5. package/dist/core/catalog-cache-invalidation.js.map +1 -0
  6. package/dist/core/create-core-server.d.ts.map +1 -1
  7. package/dist/core/create-core-server.js +101 -9
  8. package/dist/core/create-core-server.js.map +1 -1
  9. package/dist/core/create-core-services.d.ts +20 -1
  10. package/dist/core/create-core-services.d.ts.map +1 -1
  11. package/dist/core/create-core-services.js +105 -43
  12. package/dist/core/create-core-services.js.map +1 -1
  13. package/dist/core-config.d.ts.map +1 -1
  14. package/dist/core-config.js +12 -5
  15. package/dist/core-config.js.map +1 -1
  16. package/dist/modules/access/access-control.interface.d.ts +18 -6
  17. package/dist/modules/access/access-control.interface.d.ts.map +1 -1
  18. package/dist/modules/access/access-control.service.d.ts +26 -1
  19. package/dist/modules/access/access-control.service.d.ts.map +1 -1
  20. package/dist/modules/access/access-control.service.js +213 -71
  21. package/dist/modules/access/access-control.service.js.map +1 -1
  22. package/dist/modules/access/access.routes.d.ts.map +1 -1
  23. package/dist/modules/access/access.routes.js +59 -7
  24. package/dist/modules/access/access.routes.js.map +1 -1
  25. package/dist/modules/access-model/access-grammar.d.ts +51 -1
  26. package/dist/modules/access-model/access-grammar.d.ts.map +1 -1
  27. package/dist/modules/access-model/access-grammar.js +95 -1
  28. package/dist/modules/access-model/access-grammar.js.map +1 -1
  29. package/dist/modules/access-model/group-files.d.ts.map +1 -1
  30. package/dist/modules/access-model/group-files.js +4 -1
  31. package/dist/modules/access-model/group-files.js.map +1 -1
  32. package/dist/modules/access-model/kb-read-filter.d.ts +12 -0
  33. package/dist/modules/access-model/kb-read-filter.d.ts.map +1 -1
  34. package/dist/modules/access-model/kb-read-filter.js +15 -0
  35. package/dist/modules/access-model/kb-read-filter.js.map +1 -1
  36. package/dist/modules/access-model/plugin-principals.d.ts +49 -0
  37. package/dist/modules/access-model/plugin-principals.d.ts.map +1 -0
  38. package/dist/modules/access-model/plugin-principals.js +125 -0
  39. package/dist/modules/access-model/plugin-principals.js.map +1 -0
  40. package/dist/modules/connection-probe/connection-probe.contract.d.ts +43 -0
  41. package/dist/modules/connection-probe/connection-probe.contract.d.ts.map +1 -0
  42. package/dist/modules/connection-probe/connection-probe.contract.js +2 -0
  43. package/dist/modules/connection-probe/connection-probe.contract.js.map +1 -0
  44. package/dist/modules/connection-probe/connection-probe.service.d.ts +94 -0
  45. package/dist/modules/connection-probe/connection-probe.service.d.ts.map +1 -0
  46. package/dist/modules/connection-probe/connection-probe.service.js +684 -0
  47. package/dist/modules/connection-probe/connection-probe.service.js.map +1 -0
  48. package/dist/modules/connection-probe/index.d.ts +3 -0
  49. package/dist/modules/connection-probe/index.d.ts.map +1 -0
  50. package/dist/modules/connection-probe/index.js +3 -0
  51. package/dist/modules/connection-probe/index.js.map +1 -0
  52. package/dist/modules/database/core-schema.d.ts +326 -0
  53. package/dist/modules/database/core-schema.d.ts.map +1 -1
  54. package/dist/modules/database/core-schema.js +52 -0
  55. package/dist/modules/database/core-schema.js.map +1 -1
  56. package/dist/modules/diff/diff.routes.d.ts.map +1 -1
  57. package/dist/modules/diff/diff.routes.js +3 -5
  58. package/dist/modules/diff/diff.routes.js.map +1 -1
  59. package/dist/modules/kb-fs/mutex.d.ts +37 -0
  60. package/dist/modules/kb-fs/mutex.d.ts.map +1 -1
  61. package/dist/modules/kb-fs/mutex.js +48 -5
  62. package/dist/modules/kb-fs/mutex.js.map +1 -1
  63. package/dist/modules/kb-sync/index.d.ts +6 -0
  64. package/dist/modules/kb-sync/index.d.ts.map +1 -0
  65. package/dist/modules/kb-sync/index.js +5 -0
  66. package/dist/modules/kb-sync/index.js.map +1 -0
  67. package/dist/modules/kb-sync/kb-sync.interface.d.ts +77 -0
  68. package/dist/modules/kb-sync/kb-sync.interface.d.ts.map +1 -0
  69. package/dist/modules/kb-sync/kb-sync.interface.js +2 -0
  70. package/dist/modules/kb-sync/kb-sync.interface.js.map +1 -0
  71. package/dist/modules/kb-sync/kb-sync.routes.d.ts +70 -0
  72. package/dist/modules/kb-sync/kb-sync.routes.d.ts.map +1 -0
  73. package/dist/modules/kb-sync/kb-sync.routes.js +135 -0
  74. package/dist/modules/kb-sync/kb-sync.routes.js.map +1 -0
  75. package/dist/modules/kb-sync/kb-sync.service.d.ts +45 -0
  76. package/dist/modules/kb-sync/kb-sync.service.d.ts.map +1 -0
  77. package/dist/modules/kb-sync/kb-sync.service.js +183 -0
  78. package/dist/modules/kb-sync/kb-sync.service.js.map +1 -0
  79. package/dist/modules/kb-sync/sync-auth.d.ts +59 -0
  80. package/dist/modules/kb-sync/sync-auth.d.ts.map +1 -0
  81. package/dist/modules/kb-sync/sync-auth.js +62 -0
  82. package/dist/modules/kb-sync/sync-auth.js.map +1 -0
  83. package/dist/modules/kb-sync/sync-payload.d.ts +32 -0
  84. package/dist/modules/kb-sync/sync-payload.d.ts.map +1 -0
  85. package/dist/modules/kb-sync/sync-payload.js +105 -0
  86. package/dist/modules/kb-sync/sync-payload.js.map +1 -0
  87. package/dist/modules/marketplace/git-http.routes.d.ts +42 -0
  88. package/dist/modules/marketplace/git-http.routes.d.ts.map +1 -0
  89. package/dist/modules/marketplace/git-http.routes.js +190 -0
  90. package/dist/modules/marketplace/git-http.routes.js.map +1 -0
  91. package/dist/modules/marketplace/github-facade/github-facade-admin.routes.d.ts +23 -0
  92. package/dist/modules/marketplace/github-facade/github-facade-admin.routes.d.ts.map +1 -0
  93. package/dist/modules/marketplace/github-facade/github-facade-admin.routes.js +59 -0
  94. package/dist/modules/marketplace/github-facade/github-facade-admin.routes.js.map +1 -0
  95. package/dist/modules/marketplace/github-facade/github-facade-codes.store.d.ts +59 -0
  96. package/dist/modules/marketplace/github-facade/github-facade-codes.store.d.ts.map +1 -0
  97. package/dist/modules/marketplace/github-facade/github-facade-codes.store.js +96 -0
  98. package/dist/modules/marketplace/github-facade/github-facade-codes.store.js.map +1 -0
  99. package/dist/modules/marketplace/github-facade/github-facade-credentials.service.d.ts +99 -0
  100. package/dist/modules/marketplace/github-facade/github-facade-credentials.service.d.ts.map +1 -0
  101. package/dist/modules/marketplace/github-facade/github-facade-credentials.service.js +147 -0
  102. package/dist/modules/marketplace/github-facade/github-facade-credentials.service.js.map +1 -0
  103. package/dist/modules/marketplace/github-facade/github-facade.routes.d.ts +47 -0
  104. package/dist/modules/marketplace/github-facade/github-facade.routes.d.ts.map +1 -0
  105. package/dist/modules/marketplace/github-facade/github-facade.routes.js +228 -0
  106. package/dist/modules/marketplace/github-facade/github-facade.routes.js.map +1 -0
  107. package/dist/modules/marketplace/github-facade/github-facade.service.d.ts +109 -0
  108. package/dist/modules/marketplace/github-facade/github-facade.service.d.ts.map +1 -0
  109. package/dist/modules/marketplace/github-facade/github-facade.service.js +172 -0
  110. package/dist/modules/marketplace/github-facade/github-facade.service.js.map +1 -0
  111. package/dist/modules/marketplace/github-facade/index.d.ts +6 -0
  112. package/dist/modules/marketplace/github-facade/index.d.ts.map +1 -0
  113. package/dist/modules/marketplace/github-facade/index.js +6 -0
  114. package/dist/modules/marketplace/github-facade/index.js.map +1 -0
  115. package/dist/modules/marketplace/index.d.ts +4 -0
  116. package/dist/modules/marketplace/index.d.ts.map +1 -0
  117. package/dist/modules/marketplace/index.js +4 -0
  118. package/dist/modules/marketplace/index.js.map +1 -0
  119. package/dist/modules/marketplace/marketplace-repo.service.d.ts +122 -0
  120. package/dist/modules/marketplace/marketplace-repo.service.d.ts.map +1 -0
  121. package/dist/modules/marketplace/marketplace-repo.service.js +300 -0
  122. package/dist/modules/marketplace/marketplace-repo.service.js.map +1 -0
  123. package/dist/modules/mcp/oauth/bevel-oauth-provider.d.ts.map +1 -1
  124. package/dist/modules/mcp/oauth/bevel-oauth-provider.js +4 -0
  125. package/dist/modules/mcp/oauth/bevel-oauth-provider.js.map +1 -1
  126. package/dist/modules/mcp/oauth/oauth-consent.routes.d.ts +14 -8
  127. package/dist/modules/mcp/oauth/oauth-consent.routes.d.ts.map +1 -1
  128. package/dist/modules/mcp/oauth/oauth-consent.routes.js +13 -1
  129. package/dist/modules/mcp/oauth/oauth-consent.routes.js.map +1 -1
  130. package/dist/modules/mcp/oauth/oauth-state.d.ts +13 -2
  131. package/dist/modules/mcp/oauth/oauth-state.d.ts.map +1 -1
  132. package/dist/modules/mcp/oauth/oauth-state.js +3 -1
  133. package/dist/modules/mcp/oauth/oauth-state.js.map +1 -1
  134. package/dist/modules/plugins/compile/compile-marketplace.d.ts +97 -0
  135. package/dist/modules/plugins/compile/compile-marketplace.d.ts.map +1 -0
  136. package/dist/modules/plugins/compile/compile-marketplace.js +240 -0
  137. package/dist/modules/plugins/compile/compile-marketplace.js.map +1 -0
  138. package/dist/modules/plugins/compile/marketplace-compiler.service.d.ts +66 -0
  139. package/dist/modules/plugins/compile/marketplace-compiler.service.d.ts.map +1 -0
  140. package/dist/modules/plugins/compile/marketplace-compiler.service.js +132 -0
  141. package/dist/modules/plugins/compile/marketplace-compiler.service.js.map +1 -0
  142. package/dist/modules/plugins/discovery/bundle-dialect/bundle.source.d.ts +37 -0
  143. package/dist/modules/plugins/discovery/bundle-dialect/bundle.source.d.ts.map +1 -0
  144. package/dist/modules/plugins/discovery/bundle-dialect/bundle.source.js +135 -0
  145. package/dist/modules/plugins/discovery/bundle-dialect/bundle.source.js.map +1 -0
  146. package/dist/modules/plugins/discovery/bundle-dialect/registry.d.ts +45 -0
  147. package/dist/modules/plugins/discovery/bundle-dialect/registry.d.ts.map +1 -0
  148. package/dist/modules/plugins/discovery/bundle-dialect/registry.js +147 -0
  149. package/dist/modules/plugins/discovery/bundle-dialect/registry.js.map +1 -0
  150. package/dist/modules/plugins/discovery/kb-plugin-source.d.ts +37 -0
  151. package/dist/modules/plugins/discovery/kb-plugin-source.d.ts.map +1 -0
  152. package/dist/modules/plugins/discovery/kb-plugin-source.js +107 -0
  153. package/dist/modules/plugins/discovery/kb-plugin-source.js.map +1 -0
  154. package/dist/modules/plugins/discovery/native.source.d.ts +15 -0
  155. package/dist/modules/plugins/discovery/native.source.d.ts.map +1 -0
  156. package/dist/modules/plugins/discovery/native.source.js +102 -0
  157. package/dist/modules/plugins/discovery/native.source.js.map +1 -0
  158. package/dist/modules/plugins/discovery/plugin-source.d.ts +96 -0
  159. package/dist/modules/plugins/discovery/plugin-source.d.ts.map +1 -0
  160. package/dist/modules/plugins/discovery/plugin-source.js +2 -0
  161. package/dist/modules/plugins/discovery/plugin-source.js.map +1 -0
  162. package/dist/modules/plugins/index.d.ts +10 -1
  163. package/dist/modules/plugins/index.d.ts.map +1 -1
  164. package/dist/modules/plugins/index.js +8 -0
  165. package/dist/modules/plugins/index.js.map +1 -1
  166. package/dist/modules/plugins/plugin-links.d.ts +66 -0
  167. package/dist/modules/plugins/plugin-links.d.ts.map +1 -0
  168. package/dist/modules/plugins/plugin-links.js +160 -0
  169. package/dist/modules/plugins/plugin-links.js.map +1 -0
  170. package/dist/modules/plugins/plugin-links.service.d.ts +114 -0
  171. package/dist/modules/plugins/plugin-links.service.d.ts.map +1 -0
  172. package/dist/modules/plugins/plugin-links.service.js +304 -0
  173. package/dist/modules/plugins/plugin-links.service.js.map +1 -0
  174. package/dist/modules/plugins/plugin-provision.service.d.ts +39 -3
  175. package/dist/modules/plugins/plugin-provision.service.d.ts.map +1 -1
  176. package/dist/modules/plugins/plugin-provision.service.js +152 -52
  177. package/dist/modules/plugins/plugin-provision.service.js.map +1 -1
  178. package/dist/modules/plugins/plugin-rename.service.d.ts +69 -0
  179. package/dist/modules/plugins/plugin-rename.service.d.ts.map +1 -0
  180. package/dist/modules/plugins/plugin-rename.service.js +245 -0
  181. package/dist/modules/plugins/plugin-rename.service.js.map +1 -0
  182. package/dist/modules/plugins/plugins.contract.d.ts +27 -1
  183. package/dist/modules/plugins/plugins.contract.d.ts.map +1 -1
  184. package/dist/modules/plugins/plugins.routes.d.ts +7 -1
  185. package/dist/modules/plugins/plugins.routes.d.ts.map +1 -1
  186. package/dist/modules/plugins/plugins.routes.js +120 -12
  187. package/dist/modules/plugins/plugins.routes.js.map +1 -1
  188. package/dist/modules/plugins/plugins.service.d.ts +50 -3
  189. package/dist/modules/plugins/plugins.service.d.ts.map +1 -1
  190. package/dist/modules/plugins/plugins.service.js +108 -47
  191. package/dist/modules/plugins/plugins.service.js.map +1 -1
  192. package/dist/modules/secrets-vault/db-secrets-vault.service.js +1 -1
  193. package/dist/modules/secrets-vault/db-secrets-vault.service.js.map +1 -1
  194. package/dist/modules/secrets-vault/secrets-vault.routes.d.ts +6 -0
  195. package/dist/modules/secrets-vault/secrets-vault.routes.d.ts.map +1 -1
  196. package/dist/modules/secrets-vault/secrets-vault.routes.js +31 -1
  197. package/dist/modules/secrets-vault/secrets-vault.routes.js.map +1 -1
  198. package/dist/modules/settings/deployment-settings.service.d.ts +9 -0
  199. package/dist/modules/settings/deployment-settings.service.d.ts.map +1 -1
  200. package/dist/modules/settings/deployment-settings.service.js +82 -2
  201. package/dist/modules/settings/deployment-settings.service.js.map +1 -1
  202. package/dist/modules/settings/setup.routes.d.ts +26 -0
  203. package/dist/modules/settings/setup.routes.d.ts.map +1 -1
  204. package/dist/modules/settings/setup.routes.js +9 -1
  205. package/dist/modules/settings/setup.routes.js.map +1 -1
  206. package/dist/modules/skills/index.d.ts +1 -0
  207. package/dist/modules/skills/index.d.ts.map +1 -1
  208. package/dist/modules/skills/index.js +1 -0
  209. package/dist/modules/skills/index.js.map +1 -1
  210. package/dist/modules/skills/pending-skills.service.d.ts.map +1 -1
  211. package/dist/modules/skills/pending-skills.service.js +9 -4
  212. package/dist/modules/skills/pending-skills.service.js.map +1 -1
  213. package/dist/modules/skills/skill-access-requests.routes.d.ts +38 -0
  214. package/dist/modules/skills/skill-access-requests.routes.d.ts.map +1 -0
  215. package/dist/modules/skills/skill-access-requests.routes.js +168 -0
  216. package/dist/modules/skills/skill-access-requests.routes.js.map +1 -0
  217. package/dist/modules/skills/skills.contract.d.ts +31 -0
  218. package/dist/modules/skills/skills.contract.d.ts.map +1 -1
  219. package/dist/modules/skills/skills.routes.d.ts +28 -3
  220. package/dist/modules/skills/skills.routes.d.ts.map +1 -1
  221. package/dist/modules/skills/skills.routes.js +42 -3
  222. package/dist/modules/skills/skills.routes.js.map +1 -1
  223. package/dist/modules/skills/skills.service.d.ts +4 -0
  224. package/dist/modules/skills/skills.service.d.ts.map +1 -1
  225. package/dist/modules/skills/skills.service.js +83 -22
  226. package/dist/modules/skills/skills.service.js.map +1 -1
  227. package/dist/modules/tool-auth/external-api-key.interface.d.ts +18 -1
  228. package/dist/modules/tool-auth/external-api-key.interface.d.ts.map +1 -1
  229. package/dist/modules/tool-auth/external-api-key.interface.js +2 -1
  230. package/dist/modules/tool-auth/external-api-key.interface.js.map +1 -1
  231. package/dist/modules/tool-auth/external-api-key.service.d.ts +13 -4
  232. package/dist/modules/tool-auth/external-api-key.service.d.ts.map +1 -1
  233. package/dist/modules/tool-auth/external-api-key.service.js +26 -9
  234. package/dist/modules/tool-auth/external-api-key.service.js.map +1 -1
  235. package/dist/modules/tool-manuals/mcp-json-discovery.d.ts +36 -0
  236. package/dist/modules/tool-manuals/mcp-json-discovery.d.ts.map +1 -1
  237. package/dist/modules/tool-manuals/mcp-json-discovery.js +130 -83
  238. package/dist/modules/tool-manuals/mcp-json-discovery.js.map +1 -1
  239. package/dist/modules/tool-manuals/mcp-server-edit.service.d.ts.map +1 -1
  240. package/dist/modules/tool-manuals/mcp-server-edit.service.js +10 -4
  241. package/dist/modules/tool-manuals/mcp-server-edit.service.js.map +1 -1
  242. package/dist/modules/tool-manuals/tool-manuals.contract.d.ts +83 -0
  243. package/dist/modules/tool-manuals/tool-manuals.contract.d.ts.map +1 -1
  244. package/dist/modules/tool-manuals/tool-manuals.service.d.ts +15 -2
  245. package/dist/modules/tool-manuals/tool-manuals.service.d.ts.map +1 -1
  246. package/dist/modules/tool-manuals/tool-manuals.service.js +199 -38
  247. package/dist/modules/tool-manuals/tool-manuals.service.js.map +1 -1
  248. package/dist/modules/workflow/git/git.service.d.ts +58 -3
  249. package/dist/modules/workflow/git/git.service.d.ts.map +1 -1
  250. package/dist/modules/workflow/git/git.service.js +325 -60
  251. package/dist/modules/workflow/git/git.service.js.map +1 -1
  252. package/dist/modules/workflow/git/pull-request.service.d.ts +6 -0
  253. package/dist/modules/workflow/git/pull-request.service.d.ts.map +1 -1
  254. package/dist/modules/workflow/git/pull-request.service.js +8 -0
  255. package/dist/modules/workflow/git/pull-request.service.js.map +1 -1
  256. package/dist/modules/workflow/workflow.routes.d.ts +2 -1
  257. package/dist/modules/workflow/workflow.routes.d.ts.map +1 -1
  258. package/dist/modules/workflow/workflow.routes.js +98 -9
  259. package/dist/modules/workflow/workflow.routes.js.map +1 -1
  260. package/dist/modules/workflow/workflow.service.d.ts +133 -9
  261. package/dist/modules/workflow/workflow.service.d.ts.map +1 -1
  262. package/dist/modules/workflow/workflow.service.js +462 -52
  263. package/dist/modules/workflow/workflow.service.js.map +1 -1
  264. package/dist/modules/workspace/startup/steps/plugin-manifests.step.d.ts +35 -0
  265. package/dist/modules/workspace/startup/steps/plugin-manifests.step.d.ts.map +1 -0
  266. package/dist/modules/workspace/startup/steps/plugin-manifests.step.js +121 -0
  267. package/dist/modules/workspace/startup/steps/plugin-manifests.step.js.map +1 -0
  268. package/dist/modules/workspace/startup/steps/seed-tree.d.ts.map +1 -1
  269. package/dist/modules/workspace/startup/steps/seed-tree.js +46 -2
  270. package/dist/modules/workspace/startup/steps/seed-tree.js.map +1 -1
  271. package/dist/modules/workspace/startup/steps/template-files.step.d.ts.map +1 -1
  272. package/dist/modules/workspace/startup/steps/template-files.step.js +112 -25
  273. package/dist/modules/workspace/startup/steps/template-files.step.js.map +1 -1
  274. package/dist/modules/workspace/workspace.routes.d.ts.map +1 -1
  275. package/dist/modules/workspace/workspace.routes.js +11 -14
  276. package/dist/modules/workspace/workspace.routes.js.map +1 -1
  277. package/dist/modules/workspace/workspace.service.d.ts +38 -1
  278. package/dist/modules/workspace/workspace.service.d.ts.map +1 -1
  279. package/dist/modules/workspace/workspace.service.js +131 -20
  280. package/dist/modules/workspace/workspace.service.js.map +1 -1
  281. package/dist/shared/domain-errors.d.ts +20 -0
  282. package/dist/shared/domain-errors.d.ts.map +1 -1
  283. package/dist/shared/domain-errors.js +29 -0
  284. package/dist/shared/domain-errors.js.map +1 -1
  285. package/dist/shared/fs-errors.d.ts +8 -0
  286. package/dist/shared/fs-errors.d.ts.map +1 -0
  287. package/dist/shared/fs-errors.js +11 -0
  288. package/dist/shared/fs-errors.js.map +1 -0
  289. package/dist/shared/fs-walk.d.ts +20 -6
  290. package/dist/shared/fs-walk.d.ts.map +1 -1
  291. package/dist/shared/fs-walk.js +35 -27
  292. package/dist/shared/fs-walk.js.map +1 -1
  293. package/dist/shared/kb-walk.d.ts +52 -0
  294. package/dist/shared/kb-walk.d.ts.map +1 -0
  295. package/dist/shared/kb-walk.js +76 -0
  296. package/dist/shared/kb-walk.js.map +1 -0
  297. package/dist/shared/path-order.d.ts +18 -0
  298. package/dist/shared/path-order.d.ts.map +1 -0
  299. package/dist/shared/path-order.js +35 -0
  300. package/dist/shared/path-order.js.map +1 -0
  301. package/dist/shared/token-crypto.d.ts +17 -2
  302. package/dist/shared/token-crypto.d.ts.map +1 -1
  303. package/dist/shared/token-crypto.js +25 -8
  304. package/dist/shared/token-crypto.js.map +1 -1
  305. package/dist/shared/ttl-cache.d.ts +28 -1
  306. package/dist/shared/ttl-cache.d.ts.map +1 -1
  307. package/dist/shared/ttl-cache.js +33 -1
  308. package/dist/shared/ttl-cache.js.map +1 -1
  309. package/kb-template/.bevelignore +1 -1
  310. package/kb-template/AGENTS.md +95 -30
  311. package/kb-template/Skills/.gitkeep +0 -0
  312. package/migrations/0005_github_facade.sql +25 -0
  313. package/migrations/meta/0005_snapshot.json +1717 -0
  314. package/migrations/meta/_journal.json +7 -0
  315. package/package.json +6 -6
  316. package/src/__tests__/core-config.admin.test.ts +21 -0
  317. package/src/__tests__/kb-layout-config.test.ts +110 -0
  318. package/src/core/__tests__/catalog-cache-invalidation.test.ts +146 -0
  319. package/src/core/catalog-cache-invalidation.ts +92 -0
  320. package/src/core/create-core-server.ts +126 -7
  321. package/src/core/create-core-services.ts +173 -41
  322. package/src/core-config.ts +14 -7
  323. package/src/modules/access/__tests__/access-control.invalidate-race.test.ts +86 -0
  324. package/src/modules/access/__tests__/access-control.service.test.ts +19 -3
  325. package/src/modules/access/__tests__/access-plugin-principals.test.ts +368 -0
  326. package/src/modules/access/__tests__/groups-admin.service.test.ts +8 -0
  327. package/src/modules/access/access-control.interface.ts +20 -9
  328. package/src/modules/access/access-control.service.ts +240 -78
  329. package/src/modules/access/access.routes.ts +96 -14
  330. package/src/modules/access-model/__tests__/access-grammar.test.ts +18 -0
  331. package/src/modules/access-model/__tests__/plugin-token-canonical.test.ts +40 -0
  332. package/src/modules/access-model/access-grammar.ts +114 -2
  333. package/src/modules/access-model/group-files.ts +4 -0
  334. package/src/modules/access-model/kb-read-filter.ts +22 -0
  335. package/src/modules/access-model/plugin-principals.ts +137 -0
  336. package/src/modules/connection-probe/__tests__/connection-probe.service.test.ts +685 -0
  337. package/src/modules/connection-probe/connection-probe.contract.ts +44 -0
  338. package/src/modules/connection-probe/connection-probe.service.ts +734 -0
  339. package/src/modules/connection-probe/index.ts +2 -0
  340. package/src/modules/database/core-schema.ts +54 -0
  341. package/src/modules/diff/diff.routes.ts +9 -5
  342. package/src/modules/kb-fs/__tests__/mutex.test.ts +107 -0
  343. package/src/modules/kb-fs/mutex.ts +50 -5
  344. package/src/modules/kb-sync/__tests__/kb-sync.routes.test.ts +297 -0
  345. package/src/modules/kb-sync/__tests__/kb-sync.service.test.ts +295 -0
  346. package/src/modules/kb-sync/__tests__/sync-auth.test.ts +118 -0
  347. package/src/modules/kb-sync/__tests__/sync-payload.test.ts +148 -0
  348. package/src/modules/kb-sync/index.ts +19 -0
  349. package/src/modules/kb-sync/kb-sync.interface.ts +79 -0
  350. package/src/modules/kb-sync/kb-sync.routes.ts +197 -0
  351. package/src/modules/kb-sync/kb-sync.service.ts +201 -0
  352. package/src/modules/kb-sync/sync-auth.ts +118 -0
  353. package/src/modules/kb-sync/sync-payload.ts +143 -0
  354. package/src/modules/marketplace/__tests__/github-facade.test.ts +443 -0
  355. package/src/modules/marketplace/__tests__/marketplace-git.test.ts +179 -0
  356. package/src/modules/marketplace/git-http.routes.ts +193 -0
  357. package/src/modules/marketplace/github-facade/github-facade-admin.routes.ts +78 -0
  358. package/src/modules/marketplace/github-facade/github-facade-codes.store.ts +145 -0
  359. package/src/modules/marketplace/github-facade/github-facade-credentials.service.ts +208 -0
  360. package/src/modules/marketplace/github-facade/github-facade.routes.ts +268 -0
  361. package/src/modules/marketplace/github-facade/github-facade.service.ts +221 -0
  362. package/src/modules/marketplace/github-facade/index.ts +25 -0
  363. package/src/modules/marketplace/index.ts +3 -0
  364. package/src/modules/marketplace/marketplace-repo.service.ts +337 -0
  365. package/src/modules/mcp/oauth/bevel-oauth-provider.ts +3 -0
  366. package/src/modules/mcp/oauth/oauth-consent.routes.ts +24 -2
  367. package/src/modules/mcp/oauth/oauth-state.ts +15 -3
  368. package/src/modules/plugins/__tests__/bundle-dialect.e2e.test.ts +163 -0
  369. package/src/modules/plugins/__tests__/compile-marketplace.test.ts +294 -0
  370. package/src/modules/plugins/__tests__/plugin-index.service.test.ts +56 -12
  371. package/src/modules/plugins/__tests__/plugin-links.service.test.ts +287 -0
  372. package/src/modules/plugins/__tests__/plugin-provision.service.test.ts +205 -5
  373. package/src/modules/plugins/__tests__/plugin-rename.service.test.ts +394 -0
  374. package/src/modules/plugins/__tests__/plugins.routes.test.ts +80 -33
  375. package/src/modules/plugins/compile/compile-marketplace.ts +403 -0
  376. package/src/modules/plugins/compile/marketplace-compiler.service.ts +150 -0
  377. package/src/modules/plugins/discovery/__tests__/kb-plugin-source.test.ts +329 -0
  378. package/src/modules/plugins/discovery/bundle-dialect/bundle.source.ts +140 -0
  379. package/src/modules/plugins/discovery/bundle-dialect/registry.ts +175 -0
  380. package/src/modules/plugins/discovery/kb-plugin-source.ts +114 -0
  381. package/src/modules/plugins/discovery/native.source.ts +122 -0
  382. package/src/modules/plugins/discovery/plugin-source.ts +99 -0
  383. package/src/modules/plugins/index.ts +10 -0
  384. package/src/modules/plugins/plugin-links.service.ts +363 -0
  385. package/src/modules/plugins/plugin-links.ts +184 -0
  386. package/src/modules/plugins/plugin-provision.service.ts +160 -54
  387. package/src/modules/plugins/plugin-rename.service.ts +298 -0
  388. package/src/modules/plugins/plugins.contract.ts +28 -1
  389. package/src/modules/plugins/plugins.routes.ts +128 -11
  390. package/src/modules/plugins/plugins.service.ts +106 -53
  391. package/src/modules/secrets-vault/__tests__/connect-pending.route.test.ts +12 -0
  392. package/src/modules/secrets-vault/__tests__/oauth-return-to.route.test.ts +10 -3
  393. package/src/modules/secrets-vault/__tests__/tool-owner-gate.route.test.ts +26 -0
  394. package/src/modules/secrets-vault/db-secrets-vault.service.ts +1 -1
  395. package/src/modules/secrets-vault/secrets-vault.routes.ts +35 -1
  396. package/src/modules/settings/__tests__/deployment-settings.service.test.ts +57 -0
  397. package/src/modules/settings/__tests__/setup.routes.sync-status.test.ts +77 -0
  398. package/src/modules/settings/deployment-settings.service.ts +95 -2
  399. package/src/modules/settings/setup.routes.ts +24 -0
  400. package/src/modules/skills/__tests__/skill-access-requests.routes.test.ts +128 -0
  401. package/src/modules/skills/__tests__/skills.service.test.ts +85 -0
  402. package/src/modules/skills/index.ts +1 -0
  403. package/src/modules/skills/pending-skills.service.ts +7 -5
  404. package/src/modules/skills/skill-access-requests.routes.ts +199 -0
  405. package/src/modules/skills/skills.contract.ts +32 -0
  406. package/src/modules/skills/skills.routes.ts +59 -3
  407. package/src/modules/skills/skills.service.ts +84 -22
  408. package/src/modules/tool-auth/external-api-key.interface.ts +20 -1
  409. package/src/modules/tool-auth/external-api-key.service.ts +31 -13
  410. package/src/modules/tool-manuals/__tests__/mcp-json-discovery.test.ts +35 -1
  411. package/src/modules/tool-manuals/__tests__/tool-manuals.cli.test.ts +2 -0
  412. package/src/modules/tool-manuals/__tests__/tool-manuals.health-check.test.ts +104 -0
  413. package/src/modules/tool-manuals/__tests__/tool-manuals.service.test.ts +56 -0
  414. package/src/modules/tool-manuals/mcp-json-discovery.ts +154 -76
  415. package/src/modules/tool-manuals/mcp-server-edit.service.ts +13 -4
  416. package/src/modules/tool-manuals/tool-manuals.contract.ts +89 -0
  417. package/src/modules/tool-manuals/tool-manuals.service.ts +210 -37
  418. package/src/modules/workflow/__tests__/preserve-roles-yaml.test.ts +1 -1
  419. package/src/modules/workflow/__tests__/workflow.routes.history-read-gate.test.ts +139 -0
  420. package/src/modules/workflow/__tests__/workflow.service.branch-in-use.test.ts +337 -0
  421. package/src/modules/workflow/__tests__/workflow.service.commitFileWhileLocked.test.ts +1 -0
  422. package/src/modules/workflow/__tests__/workflow.service.deleted-branch-sweep.test.ts +7 -1
  423. package/src/modules/workflow/__tests__/workflow.service.facade.test.ts +97 -10
  424. package/src/modules/workflow/__tests__/workflow.service.releaseLock.test.ts +119 -2
  425. package/src/modules/workflow/__tests__/workflow.service.sync.test.ts +437 -0
  426. package/src/modules/workflow/git/__tests__/git.service.history-guards.test.ts +86 -0
  427. package/src/modules/workflow/git/__tests__/git.service.postMergePull.test.ts +3 -3
  428. package/src/modules/workflow/git/__tests__/git.service.pull.test.ts +47 -4
  429. package/src/modules/workflow/git/__tests__/git.service.syncFromRemote.test.ts +253 -0
  430. package/src/modules/workflow/git/git.service.ts +354 -63
  431. package/src/modules/workflow/git/pull-request.service.ts +9 -0
  432. package/src/modules/workflow/workflow.routes.ts +104 -4
  433. package/src/modules/workflow/workflow.service.ts +505 -64
  434. package/src/modules/workspace/__tests__/workspace.routes.read-gate.test.ts +6 -7
  435. package/src/modules/workspace/__tests__/workspace.service.list-cloned.test.ts +93 -0
  436. package/src/modules/workspace/__tests__/workspace.service.missing-branch.test.ts +28 -0
  437. package/src/modules/workspace/__tests__/workspace.service.read-filter.test.ts +42 -12
  438. package/src/modules/workspace/startup/steps/__tests__/steps.test.ts +219 -4
  439. package/src/modules/workspace/startup/steps/plugin-manifests.step.ts +129 -0
  440. package/src/modules/workspace/startup/steps/seed-tree.ts +44 -2
  441. package/src/modules/workspace/startup/steps/template-files.step.ts +131 -27
  442. package/src/modules/workspace/workspace.routes.ts +17 -21
  443. package/src/modules/workspace/workspace.service.ts +128 -19
  444. package/src/shared/__tests__/filename.test.ts +0 -0
  445. package/src/shared/__tests__/fs-walk.test.ts +22 -1
  446. package/src/shared/__tests__/kb-walk.test.ts +107 -0
  447. package/src/shared/__tests__/path-order.test.ts +24 -0
  448. package/src/shared/__tests__/token-crypto.test.ts +34 -0
  449. package/src/shared/__tests__/ttl-cache.test.ts +55 -0
  450. package/src/shared/domain-errors.ts +29 -0
  451. package/src/shared/fs-errors.ts +10 -0
  452. package/src/shared/fs-walk.ts +38 -23
  453. package/src/shared/kb-walk.ts +95 -0
  454. package/src/shared/path-order.ts +33 -0
  455. package/src/shared/token-crypto.ts +28 -10
  456. package/src/shared/ttl-cache.ts +33 -1
@@ -0,0 +1,147 @@
1
+ import { generateKeyPairSync, randomBytes, randomInt } from 'node:crypto';
2
+ import { and, eq } from 'drizzle-orm';
3
+ import { githubFacadeIdentity } from '../../database/schema.js';
4
+ const ROW_ID = 'default';
5
+ /**
6
+ * The database-backed store. Secrets are sealed with the deployment's secrets
7
+ * key, exactly as stored settings are; without that key there is nowhere safe
8
+ * to keep a client secret, so the store refuses rather than writing plaintext.
9
+ */
10
+ export class DbGitHubFacadeCredentialsStore {
11
+ db;
12
+ crypto;
13
+ constructor(db, crypto) {
14
+ this.db = db;
15
+ this.crypto = crypto;
16
+ }
17
+ async load() {
18
+ const [row] = await this.db
19
+ .select()
20
+ .from(githubFacadeIdentity)
21
+ .where(eq(githubFacadeIdentity.id, ROW_ID))
22
+ .limit(1);
23
+ if (!row)
24
+ return null;
25
+ const crypto = this.requireCrypto();
26
+ return {
27
+ appId: row.appId,
28
+ clientId: row.clientId,
29
+ clientSecret: crypto.decrypt(row.clientSecret),
30
+ webhookSecret: crypto.decrypt(row.webhookSecret),
31
+ privateKeyPem: crypto.decrypt(row.privateKeyPem),
32
+ publicKeyPem: row.publicKeyPem,
33
+ createdAt: row.createdAt,
34
+ rotatedAt: row.rotatedAt,
35
+ };
36
+ }
37
+ async createIfAbsent(creds) {
38
+ await this.db
39
+ .insert(githubFacadeIdentity)
40
+ .values({ id: ROW_ID, ...this.seal(creds) })
41
+ .onConflictDoNothing({ target: githubFacadeIdentity.id });
42
+ return this.stored('insert');
43
+ }
44
+ async replaceIfCurrent(expectedClientId, creds) {
45
+ await this.db
46
+ .update(githubFacadeIdentity)
47
+ .set(this.seal(creds))
48
+ .where(and(eq(githubFacadeIdentity.id, ROW_ID), eq(githubFacadeIdentity.clientId, expectedClientId)));
49
+ return this.stored('replace');
50
+ }
51
+ async stored(after) {
52
+ const row = await this.load();
53
+ if (!row)
54
+ throw new Error(`claude bridge credentials vanished between ${after} and read`);
55
+ return row;
56
+ }
57
+ seal(creds) {
58
+ const crypto = this.requireCrypto();
59
+ return {
60
+ appId: creds.appId,
61
+ clientId: creds.clientId,
62
+ clientSecret: crypto.encrypt(creds.clientSecret),
63
+ webhookSecret: crypto.encrypt(creds.webhookSecret),
64
+ privateKeyPem: crypto.encrypt(creds.privateKeyPem),
65
+ publicKeyPem: creds.publicKeyPem,
66
+ createdAt: creds.createdAt,
67
+ rotatedAt: creds.rotatedAt,
68
+ };
69
+ }
70
+ requireCrypto() {
71
+ if (!this.crypto) {
72
+ throw new GitHubFacadeUnavailableError('SECRETS_ENC_KEY is not set, so the Claude connection credentials cannot be stored.');
73
+ }
74
+ return this.crypto;
75
+ }
76
+ }
77
+ export class GitHubFacadeUnavailableError extends Error {
78
+ constructor(message) {
79
+ super(message);
80
+ this.name = 'GitHubFacadeUnavailableError';
81
+ }
82
+ }
83
+ /**
84
+ * Generates the credentials on first use and reads them from the store on
85
+ * every use after that. No in-process copy: the store is the one place the
86
+ * truth lives, whichever replica asks.
87
+ */
88
+ export class GitHubFacadeCredentialsService {
89
+ store;
90
+ constructor(store) {
91
+ this.store = store;
92
+ }
93
+ /** The credentials, generated on first use. */
94
+ async ensure() {
95
+ const existing = await this.store.load();
96
+ if (existing)
97
+ return existing;
98
+ return this.store.createIfAbsent(generateCredentials(null));
99
+ }
100
+ /**
101
+ * New credentials, all of them — replacing the set this call read, and
102
+ * returning whatever is stored afterwards. Every registration on the
103
+ * Claude side stops matching at once, which is the point of rotating: the
104
+ * Owner re-enters the new set, and connected users' tokens (connection
105
+ * keys) are untouched, since those are ours.
106
+ */
107
+ async rotate() {
108
+ const current = await this.ensure();
109
+ return this.store.replaceIfCurrent(current.clientId, generateCredentials(current.createdAt));
110
+ }
111
+ }
112
+ function generateCredentials(createdAt) {
113
+ // The shapes GitHub uses, because the form was built for them: a numeric
114
+ // app id, an `Iv1.`-prefixed client id, hex secrets, a PKCS#1 RSA key.
115
+ const { privateKey, publicKey } = generateKeyPairSync('rsa', {
116
+ modulusLength: 2048,
117
+ privateKeyEncoding: { type: 'pkcs1', format: 'pem' },
118
+ publicKeyEncoding: { type: 'spki', format: 'pem' },
119
+ });
120
+ return {
121
+ appId: String(randomInt(100_000, 999_999)),
122
+ clientId: `Iv1.${randomBytes(8).toString('hex')}`,
123
+ clientSecret: randomBytes(20).toString('hex'),
124
+ webhookSecret: randomBytes(16).toString('hex'),
125
+ privateKeyPem: privateKey,
126
+ publicKeyPem: publicKey,
127
+ createdAt: createdAt ?? new Date(),
128
+ rotatedAt: createdAt ? new Date() : null,
129
+ };
130
+ }
131
+ /** For tests: the row kept in memory, with the same conditional writes. */
132
+ export class MemoryGitHubFacadeCredentialsStore {
133
+ row = null;
134
+ async load() {
135
+ return this.row;
136
+ }
137
+ async createIfAbsent(creds) {
138
+ this.row ??= creds;
139
+ return this.row;
140
+ }
141
+ async replaceIfCurrent(expectedClientId, creds) {
142
+ if (this.row?.clientId === expectedClientId)
143
+ this.row = creds;
144
+ return this.row;
145
+ }
146
+ }
147
+ //# sourceMappingURL=github-facade-credentials.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-facade-credentials.service.js","sourceRoot":"","sources":["../../../../src/modules/marketplace/github-facade/github-facade-credentials.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAwDhE,MAAM,MAAM,GAAG,SAAS,CAAC;AAEzB;;;;GAIG;AACH,MAAM,OAAO,8BAA8B;IAEtB;IACA;IAFnB,YACmB,EAAY,EACZ,MAA0B;QAD1B,OAAE,GAAF,EAAE,CAAU;QACZ,WAAM,GAAN,MAAM,CAAoB;IAC1C,CAAC;IAEJ,KAAK,CAAC,IAAI;QACR,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,IAAI,CAAC,EAAE;aACxB,MAAM,EAAE;aACR,IAAI,CAAC,oBAAoB,CAAC;aAC1B,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;aAC1C,KAAK,CAAC,CAAC,CAAC,CAAC;QACZ,IAAI,CAAC,GAAG;YAAE,OAAO,IAAI,CAAC;QACtB,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QACpC,OAAO;YACL,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACtB,YAAY,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;YAC9C,aAAa,EAAE,MA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IAAI,CAAC,GAAG,KAAK,KAAK,CAAC;QACnB,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IACD,KAAK,CAAC,gBAAgB,CAAC,gBAAwB,EAAE,KAA8B;QAC7E,IAAI,IAAI,CAAC,GAAG,EAAE,QAAQ,KAAK,gBAAgB;YAAE,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC;QAC9D,OAAO,IAAI,CAAC,GAAI,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,47 @@
1
+ import express from 'express';
2
+ import '../../auth/auth.middleware.js';
3
+ import '../../tool-auth/external-api-key.interface.js';
4
+ import type { MarketplaceRepoService } from '../marketplace-repo.service.js';
5
+ import type { MarketplaceKeyResolver } from '../git-http.routes.js';
6
+ import { type GitHubFacade } from './github-facade.service.js';
7
+ export interface GitHubFacadeRoutesDeps {
8
+ facade: GitHubFacade;
9
+ keys: MarketplaceKeyResolver;
10
+ repo: MarketplaceRepoService;
11
+ /**
12
+ * The owner and name claude.ai derives from the marketplace URL people
13
+ * paste — the SAME URL Claude Code clones: `https://<host>/git/marketplace.git`
14
+ * reads as owner `git`, repository `marketplace`. One address for every
15
+ * Claude surface.
16
+ */
17
+ owner: string;
18
+ repoName: string;
19
+ /**
20
+ * The deployment's public address. Only its ORIGIN is ever emitted: a
21
+ * configured URL may carry userinfo or a path, and neither belongs in a
22
+ * body handed to a third party.
23
+ */
24
+ publicUrl: string;
25
+ }
26
+ /**
27
+ * The GitHub Enterprise surface a consumer (claude.ai, Cowork) talks to when
28
+ * a person adds this deployment's marketplace from their own settings —
29
+ * observed call for call against a lookalike host, and nothing beyond it:
30
+ *
31
+ * GET /login/oauth/authorize the "connect your account" redirect
32
+ * POST /login/oauth/access_token code → token (our client id + secret)
33
+ * GET /api/v3/repos/:owner/:repo repository metadata
34
+ * GET …/commits?per_page=1 the head commit — of THIS person's tree
35
+ * GET …/zipball/:ref that tree, zipped
36
+ *
37
+ * Mounted at the app root, ahead of the SPA and the `/api` JWT mounts: the
38
+ * first two are hit by a bare browser and by Anthropic's backend, the rest
39
+ * carry the person's token as a Bearer. The token is a connection key, so a
40
+ * revoked link fails here the same way it fails on the git remote.
41
+ *
42
+ * Errors are GitHub-shaped too (`{ message }`, and the OAuth error body on
43
+ * the token endpoint, in whichever encoding the client negotiated): the
44
+ * caller is a GitHub client and reads them as one.
45
+ */
46
+ export declare function createGitHubFacadeRoutes(deps: GitHubFacadeRoutesDeps): express.Router;
47
+ //# sourceMappingURL=github-facade.routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-facade.routes.d.ts","sourceRoot":"","sources":["../../../../src/modules/marketplace/github-facade/github-facade.routes.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,+BAA+B,CAAC;AACvC,OAAO,+CAA+C,CAAC;AACvD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAA4B,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAEzF,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,YAAY,CAAC;IACrB,IAAI,EAAE,sBAAsB,CAAC;IAC7B,IAAI,EAAE,sBAAsB,CAAC;IAC7B;;;;;OAKG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,MAAM,CAoIrF"}
@@ -0,0 +1,228 @@
1
+ import express from 'express';
2
+ import '../../auth/auth.middleware.js'; // Express Request.userId / userEmail augmentation
3
+ import '../../tool-auth/external-api-key.interface.js'; // Express Request augmentation (req.externalApiKeyId)
4
+ import { GitHubFacadeRequestError } from './github-facade.service.js';
5
+ /**
6
+ * The GitHub Enterprise surface a consumer (claude.ai, Cowork) talks to when
7
+ * a person adds this deployment's marketplace from their own settings —
8
+ * observed call for call against a lookalike host, and nothing beyond it:
9
+ *
10
+ * GET /login/oauth/authorize the "connect your account" redirect
11
+ * POST /login/oauth/access_token code → token (our client id + secret)
12
+ * GET /api/v3/repos/:owner/:repo repository metadata
13
+ * GET …/commits?per_page=1 the head commit — of THIS person's tree
14
+ * GET …/zipball/:ref that tree, zipped
15
+ *
16
+ * Mounted at the app root, ahead of the SPA and the `/api` JWT mounts: the
17
+ * first two are hit by a bare browser and by Anthropic's backend, the rest
18
+ * carry the person's token as a Bearer. The token is a connection key, so a
19
+ * revoked link fails here the same way it fails on the git remote.
20
+ *
21
+ * Errors are GitHub-shaped too (`{ message }`, and the OAuth error body on
22
+ * the token endpoint, in whichever encoding the client negotiated): the
23
+ * caller is a GitHub client and reads them as one.
24
+ */
25
+ export function createGitHubFacadeRoutes(deps) {
26
+ const router = express.Router();
27
+ const { facade, keys, repo, owner, repoName } = deps;
28
+ const origin = new URL(deps.publicUrl).origin;
29
+ const fullName = `${owner}/${repoName}`;
30
+ router.get('/login/oauth/authorize', async (req, res) => {
31
+ try {
32
+ res.redirect(302, await facade.authorizeRedirect(req.query));
33
+ }
34
+ catch (err) {
35
+ answerError(res, err);
36
+ }
37
+ });
38
+ // GitHub's token endpoint takes JSON or a form and answers in the shape
39
+ // `Accept` asks for — success and failure alike; claude.ai sends JSON and
40
+ // asks for JSON.
41
+ router.post('/login/oauth/access_token', express.json({ limit: '16kb' }), express.urlencoded({ extended: false, limit: '16kb' }), async (req, res) => {
42
+ try {
43
+ negotiated(req, res, 200, await facade.exchangeCode((req.body ?? {})));
44
+ }
45
+ catch (err) {
46
+ if (err instanceof GitHubFacadeRequestError) {
47
+ negotiated(req, res, err.status, { error: err.code, error_description: err.message });
48
+ return;
49
+ }
50
+ answerError(res, err);
51
+ }
52
+ });
53
+ // --- the REST API, as far as the observed contract goes ---------------------
54
+ const api = express.Router();
55
+ api.use(async (req, res, next) => {
56
+ const token = bearerOf(req);
57
+ if (!token || !keys.looksLikeExternalApiKey(token)) {
58
+ unauthorized(res);
59
+ return;
60
+ }
61
+ let resolved;
62
+ try {
63
+ resolved = await keys.verifyAndLoadToken(token);
64
+ }
65
+ catch (err) {
66
+ console.error('[github-facade] key verification failed:', err);
67
+ res.status(500).json({ message: 'Authentication backend unavailable' });
68
+ return;
69
+ }
70
+ if (!resolved) {
71
+ unauthorized(res);
72
+ return;
73
+ }
74
+ req.userId = resolved.user.id;
75
+ req.userEmail = resolved.user.email;
76
+ req.externalApiKeyId = resolved.tokenId;
77
+ next();
78
+ });
79
+ const isOurs = (req) => req.params.owner === owner && req.params.repo === repoName;
80
+ const notFound = (res) => res.status(404).json({ message: 'Not Found' });
81
+ api.get('/repos/:owner/:repo', (req, res) => {
82
+ if (!isOurs(req))
83
+ return void notFound(res);
84
+ res.json(repositoryBody(fullName, owner, repoName, origin));
85
+ });
86
+ api.get('/repos/:owner/:repo/commits', async (req, res) => {
87
+ if (!isOurs(req))
88
+ return void notFound(res);
89
+ try {
90
+ const { sha } = await repo.headFor({ id: req.userId, email: req.userEmail });
91
+ const commit = await repo.describeCommit(sha);
92
+ res.json([commitBody(commit, fullName, origin)]);
93
+ }
94
+ catch (err) {
95
+ answerError(res, err);
96
+ }
97
+ });
98
+ api.get('/repos/:owner/:repo/zipball/:ref', async (req, res) => {
99
+ if (!isOurs(req))
100
+ return void notFound(res);
101
+ try {
102
+ const { namespace, sha: head } = await repo.headFor({ id: req.userId, email: req.userEmail });
103
+ const ref = req.params.ref;
104
+ // Only THIS person's tree, at its head or a commit behind it: the object
105
+ // store is shared across everyone, so a sha alone must never be enough
106
+ // to read a tree compiled for someone else.
107
+ const sha = ref === 'HEAD' || ref === 'main' ? head : ref;
108
+ if (!(await repo.contains(namespace, sha)))
109
+ return void notFound(res);
110
+ res.status(200);
111
+ res.setHeader('Content-Type', 'application/zip');
112
+ res.setHeader('Content-Disposition', `attachment; filename=${owner}-${repoName}-${sha.slice(0, 7)}.zip`);
113
+ const archive = repo.archiveZip(sha, `${owner}-${repoName}-${sha.slice(0, 7)}`);
114
+ const stderr = [];
115
+ archive.stderr?.on('data', (chunk) => stderr.push(chunk));
116
+ const fail = (reason) => {
117
+ console.error(`[github-facade] zipball ${sha.slice(0, 7)} failed: ${reason}`);
118
+ // Headers are already out once the stream started; the only honest
119
+ // answer then is a cut connection, which the client sees as a failed
120
+ // download rather than a truncated archive it might unpack.
121
+ if (!res.headersSent)
122
+ res.status(500).json({ message: 'Archive failed' });
123
+ else
124
+ res.destroy();
125
+ };
126
+ archive.on('error', (err) => fail(err.message));
127
+ // A client that goes away mid-download must not leave git running —
128
+ // and that kill is the ONE signal exit that is not a failure: git dying
129
+ // to any other signal left a truncated archive on the wire.
130
+ let stopped = false;
131
+ const stop = () => {
132
+ if (archive.exitCode === null && !archive.killed) {
133
+ stopped = true;
134
+ archive.kill();
135
+ }
136
+ };
137
+ archive.on('close', (code, signal) => {
138
+ if (code === 0 || stopped)
139
+ return;
140
+ fail(`git archive exited ${code ?? `on ${signal}`}: ${Buffer.concat(stderr).toString().trim()}`);
141
+ });
142
+ req.on('aborted', stop);
143
+ res.on('close', stop);
144
+ archive.stdout.pipe(res);
145
+ }
146
+ catch (err) {
147
+ answerError(res, err);
148
+ }
149
+ });
150
+ api.use((_req, res) => notFound(res));
151
+ router.use('/api/v3', api);
152
+ return router;
153
+ }
154
+ function bearerOf(req) {
155
+ const header = req.headers.authorization;
156
+ if (!header)
157
+ return null;
158
+ const [scheme, ...rest] = header.split(' ');
159
+ if (!scheme || !/^(bearer|token)$/i.test(scheme))
160
+ return null;
161
+ return rest.join(' ').trim() || null;
162
+ }
163
+ function unauthorized(res) {
164
+ res.setHeader('WWW-Authenticate', 'Bearer realm="hexis-marketplace"');
165
+ res.status(401).json({ message: 'Bad credentials' });
166
+ }
167
+ /** The token endpoint's reply, in the encoding the client asked for. */
168
+ function negotiated(req, res, status, payload) {
169
+ const accept = req.headers.accept ?? '';
170
+ const wantsForm = accept.includes('application/x-www-form-urlencoded') && !accept.includes('json');
171
+ res.status(status);
172
+ if (wantsForm) {
173
+ res.type('application/x-www-form-urlencoded').send(new URLSearchParams(payload).toString());
174
+ return;
175
+ }
176
+ res.json(payload);
177
+ }
178
+ function answerError(res, err) {
179
+ if (err instanceof GitHubFacadeRequestError) {
180
+ res.status(err.status).json({ message: err.message });
181
+ return;
182
+ }
183
+ console.error('[github-facade]', err);
184
+ res.status(500).json({ message: 'Internal error' });
185
+ }
186
+ /** A repository as GitHub describes one — the fields a marketplace sync reads. */
187
+ function repositoryBody(fullName, owner, name, origin) {
188
+ const html = `${origin}/${fullName}`;
189
+ return {
190
+ id: 1,
191
+ node_id: 'R_hexis_marketplace',
192
+ name,
193
+ full_name: fullName,
194
+ private: true,
195
+ owner: { login: owner, id: 1, type: 'Organization' },
196
+ html_url: html,
197
+ description: 'The skills you may read, compiled as native plugins.',
198
+ fork: false,
199
+ url: `${origin}/api/v3/repos/${fullName}`,
200
+ clone_url: `${html}.git`,
201
+ default_branch: 'main',
202
+ visibility: 'private',
203
+ archived: false,
204
+ disabled: false,
205
+ permissions: { admin: false, maintain: false, push: false, triage: false, pull: true },
206
+ };
207
+ }
208
+ function commitBody(commit, fullName, origin) {
209
+ const base = `${origin}/api/v3/repos/${fullName}`;
210
+ const who = { name: commit.authorName, email: commit.authorEmail, date: commit.date };
211
+ return {
212
+ sha: commit.sha,
213
+ node_id: `C_${commit.sha}`,
214
+ commit: {
215
+ author: who,
216
+ committer: who,
217
+ message: commit.message,
218
+ tree: { sha: commit.tree, url: `${base}/git/trees/${commit.tree}` },
219
+ comment_count: 0,
220
+ },
221
+ url: `${base}/commits/${commit.sha}`,
222
+ html_url: `${origin}/${fullName}/commit/${commit.sha}`,
223
+ author: null,
224
+ committer: null,
225
+ parents: [],
226
+ };
227
+ }
228
+ //# sourceMappingURL=github-facade.routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-facade.routes.js","sourceRoot":"","sources":["../../../../src/modules/marketplace/github-facade/github-facade.routes.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,+BAA+B,CAAC,CAAC,kDAAkD;AAC1F,OAAO,+CAA+C,CAAC,CAAC,sDAAsD;AAG9G,OAAO,EAAE,wBAAwB,EAAqB,MAAM,4BAA4B,CAAC;AAsBzF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAA4B;IACnE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAChC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;IACrD,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC;IAC9C,MAAM,QAAQ,GAAG,GAAG,KAAK,IAAI,QAAQ,EAAE,CAAC;IAExC,MAAM,CAAC,GAAG,CAAC,wBAAwB,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;QACtD,IAAI,CAAC;YACH,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,MAAM,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAgC,CAAC,CAAC,CAAC;QAC1F,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACxB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,wEAAwE;IACxE,0EAA0E;IAC1E,iBAAiB;IACjB,MAAM,CAAC,IAAI,CACT,2BAA2B,EAC3B,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EAC/B,OAAO,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,C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AM,EAAE;YACN,MAAM,EAAE,GAAG;YACX,SAAS,EAAE,GAAG;YACd,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,IAAI,EAAE,EAAE,GAAG,EAAE,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,cAAc,MAAM,CAAC,IAAI,EAAE,EAAE;YACnE,aAAa,EAAE,CAAC;SACjB;QACD,GAAG,EAAE,GAAG,IAAI,YAAY,MAAM,CAAC,GAAG,EAAE;QACpC,QAAQ,EAAE,GAAG,MAAM,IAAI,QAAQ,WAAW,MAAM,CAAC,GAAG,EAAE;QACtD,MAAM,EAAE,IAAI;QACZ,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,EAAE;KACZ,CAAC;AACJ,CAAC"}
@@ -0,0 +1,109 @@
1
+ import type { MintedExternalApiKey } from '../../tool-auth/external-api-key.interface.js';
2
+ import { type McpAuthRequestState } from '../../mcp/oauth/oauth-state.js';
3
+ import type { GitHubFacadeCredentialsService } from './github-facade-credentials.service.js';
4
+ import type { GitHubFacadeCodeStore } from './github-facade-codes.store.js';
5
+ /**
6
+ * The KIND stored on a connection key minted through the facade, and the
7
+ * plaintext prefix that kind is minted with. `gho_` is what a GitHub OAuth
8
+ * token looks like — the shape a consumer expecting a GitHub Enterprise host
9
+ * accepts; the key is otherwise an ordinary connection key — hashed at rest,
10
+ * revocable from the person's external-agent page, accepted by every surface
11
+ * a connection key is. The kind, not the label, is what tells such a key
12
+ * apart: a label is the person's to edit.
13
+ */
14
+ export declare const GITHUB_LINK_KEY_KIND = "github-link";
15
+ export declare const GITHUB_LINK_KEY_PREFIX = "gho_";
16
+ /**
17
+ * A product that talks to this deployment as if it were a GitHub Enterprise
18
+ * Server. The facade itself is consumer-neutral — GitHub's OAuth pair and
19
+ * REST subset are the contract — and a consumer is the one thing that is not:
20
+ * where its callback lives (the only place a code may be sent), what the
21
+ * consent page calls it, and how the keys it holds are labelled for the
22
+ * person. Claude is the first; another product with a "connect your GitHub
23
+ * Enterprise" flow is one more entry, not one more module.
24
+ */
25
+ export interface GitHubFacadeConsumer {
26
+ id: string;
27
+ /** What the consent page says is asking. */
28
+ name: string;
29
+ /** Hostnames a redirect_uri may point at. */
30
+ redirectHosts: readonly string[];
31
+ /** The label on the connection keys minted for this consumer. */
32
+ keyLabel: string;
33
+ }
34
+ /** claude.ai and Cowork: the consumer this facade was built against. */
35
+ export declare const CLAUDE_CONSUMER: GitHubFacadeConsumer;
36
+ export interface GitHubFacadeKeyMinter {
37
+ mint(userId: string, label: string, options?: {
38
+ kind?: string;
39
+ }): Promise<MintedExternalApiKey>;
40
+ }
41
+ export interface GitHubFacadeDeps {
42
+ credentials: GitHubFacadeCredentialsService;
43
+ codes: GitHubFacadeCodeStore;
44
+ keys: GitHubFacadeKeyMinter;
45
+ /** Who may connect through the facade. */
46
+ consumers: readonly GitHubFacadeConsumer[];
47
+ /** HMAC secret for the signed authorize state — the same one the MCP flow uses. */
48
+ stateSecret: string;
49
+ /** SPA base URL — where the browser is sent to sign in and approve. */
50
+ publicFrontendUrl: string;
51
+ }
52
+ export declare class GitHubFacadeRequestError extends Error {
53
+ readonly status: number;
54
+ readonly code: string;
55
+ constructor(status: number, code: string, message: string);
56
+ }
57
+ /**
58
+ * The "connect your GitHub Enterprise account" flow, as a consumer such as claude.ai drives it
59
+ * against a GitHub Enterprise host — with hexis standing where GitHub would.
60
+ *
61
+ * 1. The browser lands on `/login/oauth/authorize?client_id&redirect_uri&state`.
62
+ * We check the client id is ours and the redirect goes to claude.ai,
63
+ * pack the request into the SAME signed state the MCP authorization
64
+ * flow uses, and send the browser to the SPA's `/connect` page — where a
65
+ * hexis session (or a sign-in) attaches a person to the request.
66
+ * 2. Finish on that page comes back through the consent routes with the
67
+ * state; {@link completeConsent} stores a one-time code bound to that
68
+ * person and returns the callback URL carrying it.
69
+ * 3. Anthropic's backend posts the code with our client id and secret to
70
+ * `/login/oauth/access_token`; {@link exchangeCode} turns it into a
71
+ * connection key for that person — the token every later fetch carries.
72
+ *
73
+ * Nothing here is remembered in the process: credentials and codes are read
74
+ * from their stores on every step, so the replica that issued a code and the
75
+ * replica that exchanges it need not be the same one.
76
+ */
77
+ export declare class GitHubFacade {
78
+ private readonly deps;
79
+ constructor(deps: GitHubFacadeDeps);
80
+ /** Where to send the browser for an authorize request, or a 4xx to answer with. */
81
+ authorizeRedirect(query: Record<string, unknown>): Promise<string>;
82
+ /** True when a verified state is one of ours (a GitHub-shaped link, not an MCP client). */
83
+ isFacadeRequest(st: McpAuthRequestState): boolean;
84
+ /** What the consent page should say is asking, for one of our states. */
85
+ clientNameFor(st: McpAuthRequestState): string;
86
+ /**
87
+ * The person approved on `/connect`: a one-time code for them, and the
88
+ * claude.ai callback to send the browser to. Supersedes any live code the
89
+ * same person already had for this client.
90
+ */
91
+ completeConsent(userId: string, st: McpAuthRequestState): Promise<{
92
+ redirectTo: string;
93
+ }>;
94
+ /**
95
+ * The token exchange. Client id and secret must be ours and the code live;
96
+ * every check runs BEFORE the code is spent, so a request that is wrong
97
+ * about something else (its redirect, say) can be corrected and retried.
98
+ * Spending is one conditional update in the store — the first exchange
99
+ * wins, on whichever replica, and only the winner mints.
100
+ */
101
+ exchangeCode(body: Record<string, unknown>): Promise<{
102
+ access_token: string;
103
+ token_type: 'bearer';
104
+ scope: '';
105
+ }>;
106
+ /** The consumer whose callback a redirect_uri is, or null — https only, host exactly. */
107
+ private consumerFor;
108
+ }
109
+ //# sourceMappingURL=github-facade.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-facade.service.d.ts","sourceRoot":"","sources":["../../../../src/modules/marketplace/github-facade/github-facade.service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+CAA+C,CAAC;AAC1F,OAAO,EAAmB,KAAK,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC3F,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,wCAAwC,CAAC;AAC7F,OAAO,KAAK,EAAE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