@bevel-software/platform-core-backend 0.14.0 → 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 (385) 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 +99 -8
  8. package/dist/core/create-core-server.js.map +1 -1
  9. package/dist/core/create-core-services.d.ts +18 -1
  10. package/dist/core/create-core-services.d.ts.map +1 -1
  11. package/dist/core/create-core-services.js +96 -43
  12. package/dist/core/create-core-services.js.map +1 -1
  13. package/dist/modules/access/access-control.interface.d.ts +18 -6
  14. package/dist/modules/access/access-control.interface.d.ts.map +1 -1
  15. package/dist/modules/access/access-control.service.d.ts +26 -1
  16. package/dist/modules/access/access-control.service.d.ts.map +1 -1
  17. package/dist/modules/access/access-control.service.js +213 -71
  18. package/dist/modules/access/access-control.service.js.map +1 -1
  19. package/dist/modules/access/access.routes.d.ts.map +1 -1
  20. package/dist/modules/access/access.routes.js +59 -7
  21. package/dist/modules/access/access.routes.js.map +1 -1
  22. package/dist/modules/access-model/access-grammar.d.ts +51 -1
  23. package/dist/modules/access-model/access-grammar.d.ts.map +1 -1
  24. package/dist/modules/access-model/access-grammar.js +95 -1
  25. package/dist/modules/access-model/access-grammar.js.map +1 -1
  26. package/dist/modules/access-model/group-files.d.ts.map +1 -1
  27. package/dist/modules/access-model/group-files.js +4 -1
  28. package/dist/modules/access-model/group-files.js.map +1 -1
  29. package/dist/modules/access-model/plugin-principals.d.ts +49 -0
  30. package/dist/modules/access-model/plugin-principals.d.ts.map +1 -0
  31. package/dist/modules/access-model/plugin-principals.js +125 -0
  32. package/dist/modules/access-model/plugin-principals.js.map +1 -0
  33. package/dist/modules/database/core-schema.d.ts +326 -0
  34. package/dist/modules/database/core-schema.d.ts.map +1 -1
  35. package/dist/modules/database/core-schema.js +52 -0
  36. package/dist/modules/database/core-schema.js.map +1 -1
  37. package/dist/modules/kb-sync/index.d.ts +6 -0
  38. package/dist/modules/kb-sync/index.d.ts.map +1 -0
  39. package/dist/modules/kb-sync/index.js +5 -0
  40. package/dist/modules/kb-sync/index.js.map +1 -0
  41. package/dist/modules/kb-sync/kb-sync.interface.d.ts +77 -0
  42. package/dist/modules/kb-sync/kb-sync.interface.d.ts.map +1 -0
  43. package/dist/modules/kb-sync/kb-sync.interface.js +2 -0
  44. package/dist/modules/kb-sync/kb-sync.interface.js.map +1 -0
  45. package/dist/modules/kb-sync/kb-sync.routes.d.ts +70 -0
  46. package/dist/modules/kb-sync/kb-sync.routes.d.ts.map +1 -0
  47. package/dist/modules/kb-sync/kb-sync.routes.js +135 -0
  48. package/dist/modules/kb-sync/kb-sync.routes.js.map +1 -0
  49. package/dist/modules/kb-sync/kb-sync.service.d.ts +45 -0
  50. package/dist/modules/kb-sync/kb-sync.service.d.ts.map +1 -0
  51. package/dist/modules/kb-sync/kb-sync.service.js +183 -0
  52. package/dist/modules/kb-sync/kb-sync.service.js.map +1 -0
  53. package/dist/modules/kb-sync/sync-auth.d.ts +59 -0
  54. package/dist/modules/kb-sync/sync-auth.d.ts.map +1 -0
  55. package/dist/modules/kb-sync/sync-auth.js +62 -0
  56. package/dist/modules/kb-sync/sync-auth.js.map +1 -0
  57. package/dist/modules/kb-sync/sync-payload.d.ts +32 -0
  58. package/dist/modules/kb-sync/sync-payload.d.ts.map +1 -0
  59. package/dist/modules/kb-sync/sync-payload.js +105 -0
  60. package/dist/modules/kb-sync/sync-payload.js.map +1 -0
  61. package/dist/modules/marketplace/git-http.routes.d.ts +42 -0
  62. package/dist/modules/marketplace/git-http.routes.d.ts.map +1 -0
  63. package/dist/modules/marketplace/git-http.routes.js +190 -0
  64. package/dist/modules/marketplace/git-http.routes.js.map +1 -0
  65. package/dist/modules/marketplace/github-facade/github-facade-admin.routes.d.ts +23 -0
  66. package/dist/modules/marketplace/github-facade/github-facade-admin.routes.d.ts.map +1 -0
  67. package/dist/modules/marketplace/github-facade/github-facade-admin.routes.js +59 -0
  68. package/dist/modules/marketplace/github-facade/github-facade-admin.routes.js.map +1 -0
  69. package/dist/modules/marketplace/github-facade/github-facade-codes.store.d.ts +59 -0
  70. package/dist/modules/marketplace/github-facade/github-facade-codes.store.d.ts.map +1 -0
  71. package/dist/modules/marketplace/github-facade/github-facade-codes.store.js +96 -0
  72. package/dist/modules/marketplace/github-facade/github-facade-codes.store.js.map +1 -0
  73. package/dist/modules/marketplace/github-facade/github-facade-credentials.service.d.ts +99 -0
  74. package/dist/modules/marketplace/github-facade/github-facade-credentials.service.d.ts.map +1 -0
  75. package/dist/modules/marketplace/github-facade/github-facade-credentials.service.js +147 -0
  76. package/dist/modules/marketplace/github-facade/github-facade-credentials.service.js.map +1 -0
  77. package/dist/modules/marketplace/github-facade/github-facade.routes.d.ts +47 -0
  78. package/dist/modules/marketplace/github-facade/github-facade.routes.d.ts.map +1 -0
  79. package/dist/modules/marketplace/github-facade/github-facade.routes.js +228 -0
  80. package/dist/modules/marketplace/github-facade/github-facade.routes.js.map +1 -0
  81. package/dist/modules/marketplace/github-facade/github-facade.service.d.ts +109 -0
  82. package/dist/modules/marketplace/github-facade/github-facade.service.d.ts.map +1 -0
  83. package/dist/modules/marketplace/github-facade/github-facade.service.js +172 -0
  84. package/dist/modules/marketplace/github-facade/github-facade.service.js.map +1 -0
  85. package/dist/modules/marketplace/github-facade/index.d.ts +6 -0
  86. package/dist/modules/marketplace/github-facade/index.d.ts.map +1 -0
  87. package/dist/modules/marketplace/github-facade/index.js +6 -0
  88. package/dist/modules/marketplace/github-facade/index.js.map +1 -0
  89. package/dist/modules/marketplace/index.d.ts +4 -0
  90. package/dist/modules/marketplace/index.d.ts.map +1 -0
  91. package/dist/modules/marketplace/index.js +4 -0
  92. package/dist/modules/marketplace/index.js.map +1 -0
  93. package/dist/modules/marketplace/marketplace-repo.service.d.ts +122 -0
  94. package/dist/modules/marketplace/marketplace-repo.service.d.ts.map +1 -0
  95. package/dist/modules/marketplace/marketplace-repo.service.js +300 -0
  96. package/dist/modules/marketplace/marketplace-repo.service.js.map +1 -0
  97. package/dist/modules/mcp/oauth/bevel-oauth-provider.d.ts.map +1 -1
  98. package/dist/modules/mcp/oauth/bevel-oauth-provider.js +4 -0
  99. package/dist/modules/mcp/oauth/bevel-oauth-provider.js.map +1 -1
  100. package/dist/modules/mcp/oauth/oauth-consent.routes.d.ts +14 -8
  101. package/dist/modules/mcp/oauth/oauth-consent.routes.d.ts.map +1 -1
  102. package/dist/modules/mcp/oauth/oauth-consent.routes.js +13 -1
  103. package/dist/modules/mcp/oauth/oauth-consent.routes.js.map +1 -1
  104. package/dist/modules/mcp/oauth/oauth-state.d.ts +13 -2
  105. package/dist/modules/mcp/oauth/oauth-state.d.ts.map +1 -1
  106. package/dist/modules/mcp/oauth/oauth-state.js +3 -1
  107. package/dist/modules/mcp/oauth/oauth-state.js.map +1 -1
  108. package/dist/modules/plugins/compile/compile-marketplace.d.ts +97 -0
  109. package/dist/modules/plugins/compile/compile-marketplace.d.ts.map +1 -0
  110. package/dist/modules/plugins/compile/compile-marketplace.js +240 -0
  111. package/dist/modules/plugins/compile/compile-marketplace.js.map +1 -0
  112. package/dist/modules/plugins/compile/marketplace-compiler.service.d.ts +66 -0
  113. package/dist/modules/plugins/compile/marketplace-compiler.service.d.ts.map +1 -0
  114. package/dist/modules/plugins/compile/marketplace-compiler.service.js +132 -0
  115. package/dist/modules/plugins/compile/marketplace-compiler.service.js.map +1 -0
  116. package/dist/modules/plugins/discovery/bundle-dialect/bundle.source.d.ts +37 -0
  117. package/dist/modules/plugins/discovery/bundle-dialect/bundle.source.d.ts.map +1 -0
  118. package/dist/modules/plugins/discovery/bundle-dialect/bundle.source.js +135 -0
  119. package/dist/modules/plugins/discovery/bundle-dialect/bundle.source.js.map +1 -0
  120. package/dist/modules/plugins/discovery/bundle-dialect/registry.d.ts +45 -0
  121. package/dist/modules/plugins/discovery/bundle-dialect/registry.d.ts.map +1 -0
  122. package/dist/modules/plugins/discovery/bundle-dialect/registry.js +147 -0
  123. package/dist/modules/plugins/discovery/bundle-dialect/registry.js.map +1 -0
  124. package/dist/modules/plugins/discovery/kb-plugin-source.d.ts +37 -0
  125. package/dist/modules/plugins/discovery/kb-plugin-source.d.ts.map +1 -0
  126. package/dist/modules/plugins/discovery/kb-plugin-source.js +107 -0
  127. package/dist/modules/plugins/discovery/kb-plugin-source.js.map +1 -0
  128. package/dist/modules/plugins/discovery/native.source.d.ts +15 -0
  129. package/dist/modules/plugins/discovery/native.source.d.ts.map +1 -0
  130. package/dist/modules/plugins/discovery/native.source.js +102 -0
  131. package/dist/modules/plugins/discovery/native.source.js.map +1 -0
  132. package/dist/modules/plugins/discovery/plugin-source.d.ts +96 -0
  133. package/dist/modules/plugins/discovery/plugin-source.d.ts.map +1 -0
  134. package/dist/modules/plugins/discovery/plugin-source.js +2 -0
  135. package/dist/modules/plugins/discovery/plugin-source.js.map +1 -0
  136. package/dist/modules/plugins/index.d.ts +10 -1
  137. package/dist/modules/plugins/index.d.ts.map +1 -1
  138. package/dist/modules/plugins/index.js +8 -0
  139. package/dist/modules/plugins/index.js.map +1 -1
  140. package/dist/modules/plugins/plugin-links.d.ts +66 -0
  141. package/dist/modules/plugins/plugin-links.d.ts.map +1 -0
  142. package/dist/modules/plugins/plugin-links.js +160 -0
  143. package/dist/modules/plugins/plugin-links.js.map +1 -0
  144. package/dist/modules/plugins/plugin-links.service.d.ts +114 -0
  145. package/dist/modules/plugins/plugin-links.service.d.ts.map +1 -0
  146. package/dist/modules/plugins/plugin-links.service.js +304 -0
  147. package/dist/modules/plugins/plugin-links.service.js.map +1 -0
  148. package/dist/modules/plugins/plugin-provision.service.d.ts +39 -3
  149. package/dist/modules/plugins/plugin-provision.service.d.ts.map +1 -1
  150. package/dist/modules/plugins/plugin-provision.service.js +152 -52
  151. package/dist/modules/plugins/plugin-provision.service.js.map +1 -1
  152. package/dist/modules/plugins/plugin-rename.service.d.ts +69 -0
  153. package/dist/modules/plugins/plugin-rename.service.d.ts.map +1 -0
  154. package/dist/modules/plugins/plugin-rename.service.js +245 -0
  155. package/dist/modules/plugins/plugin-rename.service.js.map +1 -0
  156. package/dist/modules/plugins/plugins.contract.d.ts +27 -1
  157. package/dist/modules/plugins/plugins.contract.d.ts.map +1 -1
  158. package/dist/modules/plugins/plugins.routes.d.ts +7 -1
  159. package/dist/modules/plugins/plugins.routes.d.ts.map +1 -1
  160. package/dist/modules/plugins/plugins.routes.js +120 -12
  161. package/dist/modules/plugins/plugins.routes.js.map +1 -1
  162. package/dist/modules/plugins/plugins.service.d.ts +50 -3
  163. package/dist/modules/plugins/plugins.service.d.ts.map +1 -1
  164. package/dist/modules/plugins/plugins.service.js +108 -47
  165. package/dist/modules/plugins/plugins.service.js.map +1 -1
  166. package/dist/modules/settings/deployment-settings.service.d.ts +9 -0
  167. package/dist/modules/settings/deployment-settings.service.d.ts.map +1 -1
  168. package/dist/modules/settings/deployment-settings.service.js +82 -2
  169. package/dist/modules/settings/deployment-settings.service.js.map +1 -1
  170. package/dist/modules/settings/setup.routes.d.ts +26 -0
  171. package/dist/modules/settings/setup.routes.d.ts.map +1 -1
  172. package/dist/modules/settings/setup.routes.js +9 -1
  173. package/dist/modules/settings/setup.routes.js.map +1 -1
  174. package/dist/modules/skills/index.d.ts +1 -0
  175. package/dist/modules/skills/index.d.ts.map +1 -1
  176. package/dist/modules/skills/index.js +1 -0
  177. package/dist/modules/skills/index.js.map +1 -1
  178. package/dist/modules/skills/pending-skills.service.d.ts.map +1 -1
  179. package/dist/modules/skills/pending-skills.service.js +9 -4
  180. package/dist/modules/skills/pending-skills.service.js.map +1 -1
  181. package/dist/modules/skills/skill-access-requests.routes.d.ts +38 -0
  182. package/dist/modules/skills/skill-access-requests.routes.d.ts.map +1 -0
  183. package/dist/modules/skills/skill-access-requests.routes.js +168 -0
  184. package/dist/modules/skills/skill-access-requests.routes.js.map +1 -0
  185. package/dist/modules/skills/skills.contract.d.ts +31 -0
  186. package/dist/modules/skills/skills.contract.d.ts.map +1 -1
  187. package/dist/modules/skills/skills.routes.d.ts +28 -3
  188. package/dist/modules/skills/skills.routes.d.ts.map +1 -1
  189. package/dist/modules/skills/skills.routes.js +42 -3
  190. package/dist/modules/skills/skills.routes.js.map +1 -1
  191. package/dist/modules/skills/skills.service.d.ts +4 -0
  192. package/dist/modules/skills/skills.service.d.ts.map +1 -1
  193. package/dist/modules/skills/skills.service.js +83 -22
  194. package/dist/modules/skills/skills.service.js.map +1 -1
  195. package/dist/modules/tool-auth/external-api-key.interface.d.ts +18 -1
  196. package/dist/modules/tool-auth/external-api-key.interface.d.ts.map +1 -1
  197. package/dist/modules/tool-auth/external-api-key.interface.js +2 -1
  198. package/dist/modules/tool-auth/external-api-key.interface.js.map +1 -1
  199. package/dist/modules/tool-auth/external-api-key.service.d.ts +13 -4
  200. package/dist/modules/tool-auth/external-api-key.service.d.ts.map +1 -1
  201. package/dist/modules/tool-auth/external-api-key.service.js +26 -9
  202. package/dist/modules/tool-auth/external-api-key.service.js.map +1 -1
  203. package/dist/modules/tool-manuals/mcp-json-discovery.d.ts +36 -0
  204. package/dist/modules/tool-manuals/mcp-json-discovery.d.ts.map +1 -1
  205. package/dist/modules/tool-manuals/mcp-json-discovery.js +130 -92
  206. package/dist/modules/tool-manuals/mcp-json-discovery.js.map +1 -1
  207. package/dist/modules/tool-manuals/tool-manuals.service.d.ts +6 -1
  208. package/dist/modules/tool-manuals/tool-manuals.service.d.ts.map +1 -1
  209. package/dist/modules/tool-manuals/tool-manuals.service.js +18 -25
  210. package/dist/modules/tool-manuals/tool-manuals.service.js.map +1 -1
  211. package/dist/modules/workflow/git/git.service.d.ts +40 -2
  212. package/dist/modules/workflow/git/git.service.d.ts.map +1 -1
  213. package/dist/modules/workflow/git/git.service.js +227 -54
  214. package/dist/modules/workflow/git/git.service.js.map +1 -1
  215. package/dist/modules/workflow/git/pull-request.service.d.ts +6 -0
  216. package/dist/modules/workflow/git/pull-request.service.d.ts.map +1 -1
  217. package/dist/modules/workflow/git/pull-request.service.js +8 -0
  218. package/dist/modules/workflow/git/pull-request.service.js.map +1 -1
  219. package/dist/modules/workflow/workflow.service.d.ts +52 -1
  220. package/dist/modules/workflow/workflow.service.d.ts.map +1 -1
  221. package/dist/modules/workflow/workflow.service.js +242 -9
  222. package/dist/modules/workflow/workflow.service.js.map +1 -1
  223. package/dist/modules/workspace/startup/steps/plugin-manifests.step.d.ts +35 -0
  224. package/dist/modules/workspace/startup/steps/plugin-manifests.step.d.ts.map +1 -0
  225. package/dist/modules/workspace/startup/steps/plugin-manifests.step.js +121 -0
  226. package/dist/modules/workspace/startup/steps/plugin-manifests.step.js.map +1 -0
  227. package/dist/modules/workspace/startup/steps/seed-tree.d.ts.map +1 -1
  228. package/dist/modules/workspace/startup/steps/seed-tree.js +46 -2
  229. package/dist/modules/workspace/startup/steps/seed-tree.js.map +1 -1
  230. package/dist/modules/workspace/startup/steps/template-files.step.d.ts.map +1 -1
  231. package/dist/modules/workspace/startup/steps/template-files.step.js +112 -25
  232. package/dist/modules/workspace/startup/steps/template-files.step.js.map +1 -1
  233. package/dist/modules/workspace/workspace.routes.d.ts.map +1 -1
  234. package/dist/modules/workspace/workspace.routes.js +9 -9
  235. package/dist/modules/workspace/workspace.routes.js.map +1 -1
  236. package/dist/modules/workspace/workspace.service.d.ts +33 -0
  237. package/dist/modules/workspace/workspace.service.d.ts.map +1 -1
  238. package/dist/modules/workspace/workspace.service.js +110 -16
  239. package/dist/modules/workspace/workspace.service.js.map +1 -1
  240. package/dist/shared/domain-errors.d.ts +20 -0
  241. package/dist/shared/domain-errors.d.ts.map +1 -1
  242. package/dist/shared/domain-errors.js +29 -0
  243. package/dist/shared/domain-errors.js.map +1 -1
  244. package/dist/shared/fs-errors.d.ts +8 -0
  245. package/dist/shared/fs-errors.d.ts.map +1 -0
  246. package/dist/shared/fs-errors.js +11 -0
  247. package/dist/shared/fs-errors.js.map +1 -0
  248. package/dist/shared/fs-walk.d.ts +20 -6
  249. package/dist/shared/fs-walk.d.ts.map +1 -1
  250. package/dist/shared/fs-walk.js +35 -27
  251. package/dist/shared/fs-walk.js.map +1 -1
  252. package/dist/shared/kb-walk.d.ts +52 -0
  253. package/dist/shared/kb-walk.d.ts.map +1 -0
  254. package/dist/shared/kb-walk.js +76 -0
  255. package/dist/shared/kb-walk.js.map +1 -0
  256. package/dist/shared/path-order.d.ts +18 -0
  257. package/dist/shared/path-order.d.ts.map +1 -0
  258. package/dist/shared/path-order.js +35 -0
  259. package/dist/shared/path-order.js.map +1 -0
  260. package/dist/shared/ttl-cache.d.ts +28 -1
  261. package/dist/shared/ttl-cache.d.ts.map +1 -1
  262. package/dist/shared/ttl-cache.js +33 -1
  263. package/dist/shared/ttl-cache.js.map +1 -1
  264. package/kb-template/.bevelignore +1 -1
  265. package/kb-template/AGENTS.md +95 -30
  266. package/kb-template/Skills/.gitkeep +0 -0
  267. package/migrations/0005_github_facade.sql +25 -0
  268. package/migrations/meta/0005_snapshot.json +1717 -0
  269. package/migrations/meta/_journal.json +7 -0
  270. package/package.json +6 -6
  271. package/src/__tests__/kb-layout-config.test.ts +110 -0
  272. package/src/core/__tests__/catalog-cache-invalidation.test.ts +146 -0
  273. package/src/core/catalog-cache-invalidation.ts +92 -0
  274. package/src/core/create-core-server.ts +123 -7
  275. package/src/core/create-core-services.ts +162 -41
  276. package/src/modules/access/__tests__/access-control.invalidate-race.test.ts +86 -0
  277. package/src/modules/access/__tests__/access-control.service.test.ts +19 -3
  278. package/src/modules/access/__tests__/access-plugin-principals.test.ts +368 -0
  279. package/src/modules/access/__tests__/groups-admin.service.test.ts +8 -0
  280. package/src/modules/access/access-control.interface.ts +20 -9
  281. package/src/modules/access/access-control.service.ts +240 -78
  282. package/src/modules/access/access.routes.ts +96 -14
  283. package/src/modules/access-model/__tests__/access-grammar.test.ts +18 -0
  284. package/src/modules/access-model/__tests__/plugin-token-canonical.test.ts +40 -0
  285. package/src/modules/access-model/access-grammar.ts +114 -2
  286. package/src/modules/access-model/group-files.ts +4 -0
  287. package/src/modules/access-model/plugin-principals.ts +137 -0
  288. package/src/modules/database/core-schema.ts +54 -0
  289. package/src/modules/kb-sync/__tests__/kb-sync.routes.test.ts +297 -0
  290. package/src/modules/kb-sync/__tests__/kb-sync.service.test.ts +295 -0
  291. package/src/modules/kb-sync/__tests__/sync-auth.test.ts +118 -0
  292. package/src/modules/kb-sync/__tests__/sync-payload.test.ts +148 -0
  293. package/src/modules/kb-sync/index.ts +19 -0
  294. package/src/modules/kb-sync/kb-sync.interface.ts +79 -0
  295. package/src/modules/kb-sync/kb-sync.routes.ts +197 -0
  296. package/src/modules/kb-sync/kb-sync.service.ts +201 -0
  297. package/src/modules/kb-sync/sync-auth.ts +118 -0
  298. package/src/modules/kb-sync/sync-payload.ts +143 -0
  299. package/src/modules/marketplace/__tests__/github-facade.test.ts +443 -0
  300. package/src/modules/marketplace/__tests__/marketplace-git.test.ts +179 -0
  301. package/src/modules/marketplace/git-http.routes.ts +193 -0
  302. package/src/modules/marketplace/github-facade/github-facade-admin.routes.ts +78 -0
  303. package/src/modules/marketplace/github-facade/github-facade-codes.store.ts +145 -0
  304. package/src/modules/marketplace/github-facade/github-facade-credentials.service.ts +208 -0
  305. package/src/modules/marketplace/github-facade/github-facade.routes.ts +268 -0
  306. package/src/modules/marketplace/github-facade/github-facade.service.ts +221 -0
  307. package/src/modules/marketplace/github-facade/index.ts +25 -0
  308. package/src/modules/marketplace/index.ts +3 -0
  309. package/src/modules/marketplace/marketplace-repo.service.ts +337 -0
  310. package/src/modules/mcp/oauth/bevel-oauth-provider.ts +3 -0
  311. package/src/modules/mcp/oauth/oauth-consent.routes.ts +24 -2
  312. package/src/modules/mcp/oauth/oauth-state.ts +15 -3
  313. package/src/modules/plugins/__tests__/bundle-dialect.e2e.test.ts +163 -0
  314. package/src/modules/plugins/__tests__/compile-marketplace.test.ts +294 -0
  315. package/src/modules/plugins/__tests__/plugin-index.service.test.ts +56 -12
  316. package/src/modules/plugins/__tests__/plugin-links.service.test.ts +287 -0
  317. package/src/modules/plugins/__tests__/plugin-provision.service.test.ts +205 -5
  318. package/src/modules/plugins/__tests__/plugin-rename.service.test.ts +394 -0
  319. package/src/modules/plugins/__tests__/plugins.routes.test.ts +80 -33
  320. package/src/modules/plugins/compile/compile-marketplace.ts +403 -0
  321. package/src/modules/plugins/compile/marketplace-compiler.service.ts +150 -0
  322. package/src/modules/plugins/discovery/__tests__/kb-plugin-source.test.ts +329 -0
  323. package/src/modules/plugins/discovery/bundle-dialect/bundle.source.ts +140 -0
  324. package/src/modules/plugins/discovery/bundle-dialect/registry.ts +175 -0
  325. package/src/modules/plugins/discovery/kb-plugin-source.ts +114 -0
  326. package/src/modules/plugins/discovery/native.source.ts +122 -0
  327. package/src/modules/plugins/discovery/plugin-source.ts +99 -0
  328. package/src/modules/plugins/index.ts +10 -0
  329. package/src/modules/plugins/plugin-links.service.ts +363 -0
  330. package/src/modules/plugins/plugin-links.ts +184 -0
  331. package/src/modules/plugins/plugin-provision.service.ts +160 -54
  332. package/src/modules/plugins/plugin-rename.service.ts +298 -0
  333. package/src/modules/plugins/plugins.contract.ts +28 -1
  334. package/src/modules/plugins/plugins.routes.ts +128 -11
  335. package/src/modules/plugins/plugins.service.ts +106 -53
  336. package/src/modules/settings/__tests__/deployment-settings.service.test.ts +57 -0
  337. package/src/modules/settings/__tests__/setup.routes.sync-status.test.ts +77 -0
  338. package/src/modules/settings/deployment-settings.service.ts +95 -2
  339. package/src/modules/settings/setup.routes.ts +24 -0
  340. package/src/modules/skills/__tests__/skill-access-requests.routes.test.ts +128 -0
  341. package/src/modules/skills/__tests__/skills.service.test.ts +85 -0
  342. package/src/modules/skills/index.ts +1 -0
  343. package/src/modules/skills/pending-skills.service.ts +7 -5
  344. package/src/modules/skills/skill-access-requests.routes.ts +199 -0
  345. package/src/modules/skills/skills.contract.ts +32 -0
  346. package/src/modules/skills/skills.routes.ts +59 -3
  347. package/src/modules/skills/skills.service.ts +84 -22
  348. package/src/modules/tool-auth/external-api-key.interface.ts +20 -1
  349. package/src/modules/tool-auth/external-api-key.service.ts +31 -13
  350. package/src/modules/tool-manuals/__tests__/mcp-json-discovery.test.ts +24 -1
  351. package/src/modules/tool-manuals/__tests__/tool-manuals.cli.test.ts +2 -0
  352. package/src/modules/tool-manuals/mcp-json-discovery.ts +154 -88
  353. package/src/modules/tool-manuals/tool-manuals.service.ts +14 -23
  354. package/src/modules/workflow/__tests__/preserve-roles-yaml.test.ts +1 -1
  355. package/src/modules/workflow/__tests__/workflow.service.commitFileWhileLocked.test.ts +1 -0
  356. package/src/modules/workflow/__tests__/workflow.service.facade.test.ts +2 -2
  357. package/src/modules/workflow/__tests__/workflow.service.releaseLock.test.ts +119 -2
  358. package/src/modules/workflow/__tests__/workflow.service.sync.test.ts +437 -0
  359. package/src/modules/workflow/git/__tests__/git.service.postMergePull.test.ts +3 -3
  360. package/src/modules/workflow/git/__tests__/git.service.pull.test.ts +47 -4
  361. package/src/modules/workflow/git/__tests__/git.service.syncFromRemote.test.ts +253 -0
  362. package/src/modules/workflow/git/git.service.ts +239 -56
  363. package/src/modules/workflow/git/pull-request.service.ts +9 -0
  364. package/src/modules/workflow/workflow.service.ts +260 -9
  365. package/src/modules/workspace/__tests__/workspace.routes.read-gate.test.ts +6 -7
  366. package/src/modules/workspace/__tests__/workspace.service.list-cloned.test.ts +93 -0
  367. package/src/modules/workspace/__tests__/workspace.service.missing-branch.test.ts +28 -0
  368. package/src/modules/workspace/__tests__/workspace.service.read-filter.test.ts +42 -12
  369. package/src/modules/workspace/startup/steps/__tests__/steps.test.ts +219 -4
  370. package/src/modules/workspace/startup/steps/plugin-manifests.step.ts +129 -0
  371. package/src/modules/workspace/startup/steps/seed-tree.ts +44 -2
  372. package/src/modules/workspace/startup/steps/template-files.step.ts +131 -27
  373. package/src/modules/workspace/workspace.routes.ts +9 -17
  374. package/src/modules/workspace/workspace.service.ts +107 -16
  375. package/src/shared/__tests__/filename.test.ts +0 -0
  376. package/src/shared/__tests__/fs-walk.test.ts +22 -1
  377. package/src/shared/__tests__/kb-walk.test.ts +107 -0
  378. package/src/shared/__tests__/path-order.test.ts +24 -0
  379. package/src/shared/__tests__/ttl-cache.test.ts +55 -0
  380. package/src/shared/domain-errors.ts +29 -0
  381. package/src/shared/fs-errors.ts +10 -0
  382. package/src/shared/fs-walk.ts +38 -23
  383. package/src/shared/kb-walk.ts +95 -0
  384. package/src/shared/path-order.ts +33 -0
  385. package/src/shared/ttl-cache.ts +33 -1
@@ -0,0 +1,201 @@
1
+ import type { BranchSyncOutcome } from '@bevel-software/platform-shared';
2
+ import { sanitizeError } from '../workflow/sanitize-error.js';
3
+ import type {
4
+ IKbSyncService,
5
+ LastSync,
6
+ SyncRequest,
7
+ SyncResult,
8
+ SyncWorkflowPort,
9
+ SyncWorkspacePort,
10
+ } from './kb-sync.interface.js';
11
+
12
+ /**
13
+ * Runs remote syncs one at a time and folds everything that arrives
14
+ * mid-run into ONE follow-up.
15
+ *
16
+ * Why coalesce: a git host fires several hooks for one event — Azure DevOps
17
+ * sends a push, a PR-updated and a PR-merged within a second of each other —
18
+ * and each would otherwise queue behind the workspace mutex to pull the same
19
+ * tree again. The follow-up pulls the union of every request that arrived
20
+ * during the run (an "all" absorbs the rest).
21
+ *
22
+ * But each caller is answered for the branches IT asked about. The endpoint
23
+ * promises to fail exactly when the caller's branch is not in sync; a hook
24
+ * for branch A answered with branch B's conflict would fail the wrong
25
+ * subscription — and a host that disables subscriptions after repeated
26
+ * failures would disable the wrong one.
27
+ *
28
+ * Branches are pulled sequentially. N is small (only cloned branches count),
29
+ * the per-clone mutex serialises them anyway, and one slow origin round-trip
30
+ * at a time keeps the process calm during a burst.
31
+ */
32
+ export class KbSyncService implements IKbSyncService {
33
+ private inFlight: Promise<unknown> | null = null;
34
+ /** Everyone who arrived mid-run, each with what they asked for. */
35
+ private waiters: Array<{
36
+ branches: string[] | 'all';
37
+ by: string | undefined;
38
+ resolve: (r: SyncResult) => void;
39
+ reject: (e: unknown) => void;
40
+ }> = [];
41
+ private last: LastSync | null = null;
42
+
43
+ constructor(
44
+ private readonly workflow: SyncWorkflowPort,
45
+ private readonly workspaces: SyncWorkspacePort,
46
+ private readonly now: () => number = () => Date.now(),
47
+ ) {}
48
+
49
+ lastSync(): LastSync | null {
50
+ return this.last;
51
+ }
52
+
53
+ sync(request: SyncRequest): Promise<SyncResult> {
54
+ if (!this.inFlight) return this.start(request);
55
+ return new Promise<SyncResult>((resolve, reject) => {
56
+ // Copied on entry: the caller keeps its array, and a caller that reuses
57
+ // or edits it before the follow-up runs must not change what is pulled
58
+ // or what it is answered for.
59
+ const branches = request.branches === 'all' ? 'all' : [...request.branches];
60
+ this.waiters.push({ branches, by: request.by, resolve, reject });
61
+ });
62
+ }
63
+
64
+ private start(request: SyncRequest): Promise<SyncResult> {
65
+ const run = this.run(request);
66
+ this.inFlight = run.catch(() => undefined).finally(() => {
67
+ this.inFlight = null;
68
+ this.drain();
69
+ });
70
+ return run;
71
+ }
72
+
73
+ /**
74
+ * Run ONE follow-up for everyone who arrived during the last run: the union
75
+ * of their branches, then each waiter answered from its own share of the
76
+ * result — never from another caller's branches.
77
+ */
78
+ private drain(): void {
79
+ if (this.waiters.length === 0) return;
80
+ const waiters = this.waiters;
81
+ this.waiters = [];
82
+
83
+ const union = new Set<string>();
84
+ let all = false;
85
+ const by = new Set<string>();
86
+ for (const w of waiters) {
87
+ if (w.branches === 'all') all = true;
88
+ else for (const b of w.branches) union.add(b);
89
+ if (w.by) by.add(w.by);
90
+ }
91
+ const request: SyncRequest = {
92
+ branches: all ? 'all' : [...union],
93
+ by: by.size > 0 ? [...by].join(', ') : undefined,
94
+ };
95
+ this.start(request).then(
96
+ (result) => {
97
+ for (const w of waiters) w.resolve(KbSyncService.subsetFor(result, w.branches));
98
+ },
99
+ (err) => {
100
+ for (const w of waiters) w.reject(err);
101
+ },
102
+ );
103
+ }
104
+
105
+ /** The part of a union run that answers one caller: its branches, and its status over them. */
106
+ private static subsetFor(result: SyncResult, branches: string[] | 'all'): SyncResult {
107
+ if (branches === 'all') return result;
108
+ const wanted = new Set(branches);
109
+ const results = result.results.filter((r) => wanted.has(r.branch));
110
+ return {
111
+ status: KbSyncService.statusOf(results),
112
+ results,
113
+ changeRequests: result.changeRequests,
114
+ };
115
+ }
116
+
117
+ private static statusOf(results: BranchSyncOutcome[]): SyncResult['status'] {
118
+ const clean = results.every(
119
+ (r) =>
120
+ r.outcome === 'updated' ||
121
+ r.outcome === 'up-to-date' ||
122
+ r.outcome === 'not-cloned' ||
123
+ r.outcome === 'remote-gone',
124
+ );
125
+ return clean ? 'synced' : 'partial';
126
+ }
127
+
128
+ private async run(request: SyncRequest): Promise<SyncResult> {
129
+ const known = await this.workspaces.listClonedWorkspaces();
130
+ const byBranch = new Map(known.map((w) => [w.branch, w.id]));
131
+
132
+ const targets: Array<{ branch: string; id: string | null }> =
133
+ request.branches === 'all'
134
+ ? known.map((w) => ({ branch: w.branch, id: w.id }))
135
+ : request.branches.map((branch) => ({ branch, id: byBranch.get(branch) ?? null }));
136
+
137
+ const unreadable = new Map(known.filter((w) => w.unreadable).map((w) => [w.branch, w.unreadable!]));
138
+
139
+ const results: BranchSyncOutcome[] = [];
140
+ for (const { branch, id } of targets) {
141
+ if (id === null) {
142
+ results.push({ branch, outcome: 'not-cloned' });
143
+ continue;
144
+ }
145
+ const cannotRead = unreadable.get(branch);
146
+ if (cannotRead) {
147
+ results.push({ branch, outcome: 'error', error: cannotRead });
148
+ continue;
149
+ }
150
+ let outcome: BranchSyncOutcome;
151
+ try {
152
+ outcome = await this.workflow.syncWorkspaceFromRemote(id);
153
+ } catch (err) {
154
+ // The workflow step promises outcomes, not throws — but one broken
155
+ // clone must never take the other branches, the sweep, or every
156
+ // coalesced caller down with it, so the promise is enforced here too.
157
+ const message = sanitizeError(err);
158
+ console.error(`[sync] unexpected failure syncing "${branch}": ${message}`);
159
+ outcome = { branch, outcome: 'error', error: message };
160
+ }
161
+ results.push(outcome);
162
+ if (outcome.outcome === 'remote-gone') {
163
+ // The host deleted the branch. Left in place, the stale clone would
164
+ // fail its fetch on every following full sync — and a webhook host
165
+ // disables a subscription that keeps failing. The workflow retires it
166
+ // under the branch-lifecycle lock, after asking origin again, so a
167
+ // branch recreated since the pull keeps its clone. Best-effort.
168
+ try {
169
+ const removed = await this.workflow.retireRemoteGoneClone(id);
170
+ if (removed) console.log(`[sync] removed the clone of "${branch}" — deleted on the host`);
171
+ else console.log(`[sync] kept the clone of "${branch}" — it is back on the host, or already gone`);
172
+ } catch (err) {
173
+ console.warn(`[sync] could not remove the clone of "${branch}":`, sanitizeError(err));
174
+ }
175
+ }
176
+ }
177
+
178
+ // The host may have deleted a branch (an ADO PR completed with "delete
179
+ // source branch"); the existing sweep closes the Hexis request that
180
+ // pointed at it. Best-effort — it fails safe by closing nothing.
181
+ let closedDeletedBranch = 0;
182
+ try {
183
+ closedDeletedBranch = await this.workflow.closeChangeRequestsWithDeletedBranches();
184
+ } catch (err) {
185
+ console.warn('[sync] deleted-branch sweep failed:', err instanceof Error ? err.message : err);
186
+ }
187
+
188
+ const result: SyncResult = {
189
+ status: KbSyncService.statusOf(results),
190
+ results,
191
+ changeRequests: { closedDeletedBranch },
192
+ };
193
+ this.last = {
194
+ at: this.now(),
195
+ by: request.by ?? 'unknown',
196
+ status: result.status,
197
+ results: [...results],
198
+ };
199
+ return result;
200
+ }
201
+ }
@@ -0,0 +1,118 @@
1
+ import { createHmac } from 'node:crypto';
2
+ import { timingSafeStringEqual } from '../auth/password-hash.js';
3
+
4
+ /**
5
+ * Who may call `POST /api/sync`, decided from the request's credentials.
6
+ *
7
+ * Framework-agnostic on purpose (the route hands in plain strings and the
8
+ * raw body) so the rule is one function with one test, not something spread
9
+ * across middleware.
10
+ *
11
+ * Four credentials are accepted, because the callers cannot all speak the
12
+ * same one:
13
+ *
14
+ * bearer `Authorization: Bearer <secret>` — ADO Web Hooks and
15
+ * any pipeline can set a header.
16
+ * gitlab-token `X-Gitlab-Token: <secret>` — what GitLab sends.
17
+ * github-signature `X-Hub-Signature-256: sha256=<hmac of the raw body>` —
18
+ * GitHub and Gitea cannot set headers, only sign.
19
+ * admin-session a browser JWT whose user is an admin, so a "Sync now"
20
+ * button and a curl with your own session both work while
21
+ * the hook is being wired up.
22
+ *
23
+ * Every comparison is constant-time. The secret never travels in the URL.
24
+ */
25
+ export type SyncCredential =
26
+ | { kind: 'bearer' | 'gitlab-token' | 'github-signature' }
27
+ | { kind: 'admin-session'; email: string };
28
+
29
+ export type SyncAuthResult =
30
+ | { ok: true; credential: SyncCredential }
31
+ | { ok: false; status: 401 | 503; message: string };
32
+
33
+ export interface SyncAuthInput {
34
+ /** The configured secret, or empty when none is set. */
35
+ secret: string;
36
+ authorization?: string;
37
+ gitlabToken?: string;
38
+ hubSignature?: string;
39
+ /** The request body exactly as received — the HMAC is over these bytes. */
40
+ rawBody?: Buffer;
41
+ }
42
+
43
+ export interface SyncSessionVerifier {
44
+ /** Resolve a browser JWT to its email, or null when it is not one. */
45
+ verifyJwt(token: string): { email: string } | null;
46
+ isAdmin(email: string): Promise<boolean>;
47
+ }
48
+
49
+ const NO_SECRET =
50
+ 'No sync secret is configured. Set KB_SYNC_SECRET (or the setup screen’s sync secret), ' +
51
+ 'or call this endpoint with an administrator session.';
52
+
53
+ /**
54
+ * Shortest secret the endpoint will honour. The setup screen enforces the
55
+ * same floor on save; this is the boundary that also covers a secret set
56
+ * through the environment, which no validator ever sees.
57
+ */
58
+ export const MIN_SYNC_SECRET_LENGTH = 16;
59
+
60
+ const SECRET_TOO_SHORT =
61
+ `The configured sync secret is shorter than ${MIN_SYNC_SECRET_LENGTH} characters and is not ` +
62
+ 'accepted. Set a longer KB_SYNC_SECRET, or call this endpoint with an administrator session.';
63
+
64
+ function signatureMatches(secret: string, rawBody: Buffer, header: string): boolean {
65
+ const [scheme, hex] = header.split('=', 2);
66
+ if (scheme !== 'sha256' || !hex) return false;
67
+ const expected = createHmac('sha256', secret).update(rawBody).digest('hex');
68
+ return timingSafeStringEqual(expected, hex.toLowerCase());
69
+ }
70
+
71
+ export async function verifySyncCredential(
72
+ input: SyncAuthInput,
73
+ session: SyncSessionVerifier,
74
+ ): Promise<SyncAuthResult> {
75
+ const configured = input.secret.trim();
76
+ // A too-short secret is treated as absent for matching purposes and named
77
+ // as the problem below, so a one-character deployment secret can never be
78
+ // what lets a caller in.
79
+ const usable = configured.length >= MIN_SYNC_SECRET_LENGTH;
80
+ const secret = usable ? configured : '';
81
+ const bearer = input.authorization?.startsWith('Bearer ')
82
+ ? input.authorization.slice('Bearer '.length).trim()
83
+ : '';
84
+
85
+ // A shared secret presented in any of its three shapes.
86
+ if (secret) {
87
+ if (bearer && timingSafeStringEqual(bearer, secret)) {
88
+ return { ok: true, credential: { kind: 'bearer' } };
89
+ }
90
+ if (input.gitlabToken && timingSafeStringEqual(input.gitlabToken.trim(), secret)) {
91
+ return { ok: true, credential: { kind: 'gitlab-token' } };
92
+ }
93
+ if (input.hubSignature && input.rawBody && signatureMatches(secret, input.rawBody, input.hubSignature.trim())) {
94
+ return { ok: true, credential: { kind: 'github-signature' } };
95
+ }
96
+ }
97
+
98
+ // An admin's own session, carried as the bearer. Checked after the secret
99
+ // so a secret that happens to parse as a JWT is never mistaken for one.
100
+ if (bearer) {
101
+ const claim = session.verifyJwt(bearer);
102
+ if (claim && (await session.isAdmin(claim.email))) {
103
+ return { ok: true, credential: { kind: 'admin-session', email: claim.email } };
104
+ }
105
+ }
106
+
107
+ // Nothing matched. Say WHY when the reason is the deployment's, not the
108
+ // caller's: a hook pointed at an unconfigured endpoint should read "set
109
+ // the secret", not "wrong secret".
110
+ if (!secret && (bearer || input.gitlabToken || input.hubSignature)) {
111
+ return { ok: false, status: 503, message: configured ? SECRET_TOO_SHORT : NO_SECRET };
112
+ }
113
+ return {
114
+ ok: false,
115
+ status: 401,
116
+ message: 'A valid sync secret or an administrator session is required.',
117
+ };
118
+ }
@@ -0,0 +1,143 @@
1
+ import { assertValidBranchName } from '../kb-fs/branch-name.js';
2
+
3
+ /**
4
+ * Turn whatever a caller POSTed to `/api/sync` into the branches to sync.
5
+ *
6
+ * Pure: no IO, no throwing on foreign shapes. The endpoint is meant to be
7
+ * pointed at by a webhook subscription whose payload the operator does not
8
+ * control, so an unrecognised body must degrade to "sync everything" — the
9
+ * safe answer, and the one an empty pipeline call gets too — never to a 400
10
+ * that makes the host disable the subscription.
11
+ *
12
+ * Recognised shapes:
13
+ *
14
+ * explicit `{ "branches": ["main", "ali/x"] }`
15
+ * azure-devops `eventType: git.push` → `resource.refUpdates[].name`
16
+ * `eventType: git.pullrequest.*` → `resource.targetRefName`
17
+ * and `resource.sourceRefName`
18
+ * github/gitea `{ "ref": "refs/heads/main" }` (push)
19
+ * gitlab `{ "object_kind": "push", "ref": "refs/heads/main" }`
20
+ *
21
+ * Only `refs/heads/*` refs count; a tag push names nothing to sync. A branch
22
+ * name git would refuse is dropped from a provider payload (the host
23
+ * produced it, nothing we can do) but reported for an explicit body, where
24
+ * it is the caller's mistake to fix.
25
+ */
26
+ export type SyncPayloadSource = 'explicit' | 'azure-devops' | 'github' | 'gitlab' | 'none';
27
+
28
+ export interface ParsedSyncPayload {
29
+ source: SyncPayloadSource;
30
+ branches: string[] | 'all';
31
+ /** Explicit-body names git would refuse. Empty for every other source. */
32
+ invalid: string[];
33
+ }
34
+
35
+ const HEADS = 'refs/heads/';
36
+
37
+ function isRecord(v: unknown): v is Record<string, unknown> {
38
+ return typeof v === 'object' && v !== null && !Array.isArray(v);
39
+ }
40
+
41
+ function branchFromRef(ref: unknown): string | null {
42
+ if (typeof ref !== 'string' || !ref.startsWith(HEADS)) return null;
43
+ const name = ref.slice(HEADS.length);
44
+ return isValidBranch(name) ? name : null;
45
+ }
46
+
47
+ function isValidBranch(name: string): boolean {
48
+ try {
49
+ assertValidBranchName(name);
50
+ return true;
51
+ } catch {
52
+ return false;
53
+ }
54
+ }
55
+
56
+ function unique(names: string[]): string[] {
57
+ return [...new Set(names)];
58
+ }
59
+
60
+ /**
61
+ * How an invalid explicit entry is echoed back. Only primitives are
62
+ * stringified: `String(obj)` on a JSON object carrying `"toString": 1` throws
63
+ * ("Cannot convert object to primitive value"), which would turn a caller's
64
+ * bad body into our 500.
65
+ */
66
+ function describeInvalid(entry: unknown): string {
67
+ if (entry === null) return 'null';
68
+ switch (typeof entry) {
69
+ case 'string':
70
+ return entry.trim() === '' ? '(empty)' : entry;
71
+ case 'number':
72
+ case 'boolean':
73
+ case 'bigint':
74
+ return String(entry);
75
+ default:
76
+ return Array.isArray(entry) ? '(array)' : '(object)';
77
+ }
78
+ }
79
+
80
+ export function parseSyncPayload(body: unknown): ParsedSyncPayload {
81
+ if (!isRecord(body)) return { source: 'none', branches: 'all', invalid: [] };
82
+
83
+ if ('branches' in body) {
84
+ const raw = body.branches;
85
+ if (!Array.isArray(raw)) return { source: 'explicit', branches: 'all', invalid: [] };
86
+ const valid: string[] = [];
87
+ const invalid: string[] = [];
88
+ for (const entry of raw) {
89
+ if (typeof entry !== 'string' || !entry.trim()) {
90
+ invalid.push(describeInvalid(entry));
91
+ continue;
92
+ }
93
+ const name = entry.trim();
94
+ (isValidBranch(name) ? valid : invalid).push(name);
95
+ }
96
+ return { source: 'explicit', branches: unique(valid), invalid };
97
+ }
98
+
99
+ // Azure DevOps service hook. `eventType` names the event; the branches sit
100
+ // under `resource` in a per-event shape.
101
+ const eventType = body.eventType;
102
+ if (typeof eventType === 'string' && isRecord(body.resource)) {
103
+ const resource = body.resource;
104
+ if (eventType === 'git.push') {
105
+ const updates = Array.isArray(resource.refUpdates) ? resource.refUpdates : [];
106
+ // A DELETION (new object id all zeros) names its branch too: syncing it
107
+ // is what finds the branch gone and retires the stale clone, instead of
108
+ // leaving it to fail on some unrelated full sync later.
109
+ const branches = updates
110
+ .map((u) => (isRecord(u) ? branchFromRef(u.name) : null))
111
+ .filter((b): b is string => b !== null);
112
+ return { source: 'azure-devops', branches: unique(branches), invalid: [] };
113
+ }
114
+ if (eventType.startsWith('git.pullrequest.')) {
115
+ const branches = [branchFromRef(resource.targetRefName), branchFromRef(resource.sourceRefName)]
116
+ .filter((b): b is string => b !== null);
117
+ return { source: 'azure-devops', branches: unique(branches), invalid: [] };
118
+ }
119
+ }
120
+
121
+ // GitLab events all carry `object_kind`. Only a push (or a tag push, which
122
+ // names no branch) is a statement about a ref; anything else with a stray
123
+ // `ref` — a merge request, a pipeline — is not, and takes the "everything"
124
+ // fallback rather than being read as a push of that ref.
125
+ if (typeof body.object_kind === 'string') {
126
+ if (body.object_kind !== 'push' && body.object_kind !== 'tag_push') {
127
+ return { source: 'none', branches: 'all', invalid: [] };
128
+ }
129
+ // A deletion (a push to the null sha) names its branch like any push: the
130
+ // sync finds it gone and retires the clone.
131
+ const branch = branchFromRef(body.ref);
132
+ return { source: 'gitlab', branches: branch ? [branch] : [], invalid: [] };
133
+ }
134
+
135
+ // GitHub / Gitea push: `ref` at the top level, no `object_kind`. A deletion
136
+ // (`deleted: true`) names its branch like any push, for the same reason.
137
+ if (typeof body.ref === 'string') {
138
+ const branch = branchFromRef(body.ref);
139
+ return { source: 'github', branches: branch ? [branch] : [], invalid: [] };
140
+ }
141
+
142
+ return { source: 'none', branches: 'all', invalid: [] };
143
+ }