@bevel-software/platform-core-backend 0.7.5 → 0.9.0

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 (282) hide show
  1. package/LICENSE +202 -202
  2. package/THIRD-PARTY-NOTICES.md +428 -454
  3. package/dist/core/core-ports.d.ts +8 -1
  4. package/dist/core/core-ports.d.ts.map +1 -1
  5. package/dist/core/core-ports.js.map +1 -1
  6. package/dist/core/create-core-server.d.ts.map +1 -1
  7. package/dist/core/create-core-server.js +75 -18
  8. package/dist/core/create-core-server.js.map +1 -1
  9. package/dist/core/create-core-services.d.ts +12 -5
  10. package/dist/core/create-core-services.d.ts.map +1 -1
  11. package/dist/core/create-core-services.js +69 -36
  12. package/dist/core/create-core-services.js.map +1 -1
  13. package/dist/modules/access/access-control.interface.d.ts +8 -7
  14. package/dist/modules/access/access-control.interface.d.ts.map +1 -1
  15. package/dist/modules/access/access-control.service.d.ts +1 -1
  16. package/dist/modules/access/access-control.service.d.ts.map +1 -1
  17. package/dist/modules/access/access-control.service.js +6 -6
  18. package/dist/modules/access/access-control.service.js.map +1 -1
  19. package/dist/modules/access/access-declarations.d.ts +5 -5
  20. package/dist/modules/access/access-declarations.js +3 -3
  21. package/dist/modules/access/access-mutation.service.d.ts +3 -3
  22. package/dist/modules/access/access-mutation.service.d.ts.map +1 -1
  23. package/dist/modules/access/access-mutation.service.js +3 -3
  24. package/dist/modules/access/access-mutation.service.js.map +1 -1
  25. package/dist/modules/access/access-splice.js +4 -4
  26. package/dist/modules/access/access-splice.js.map +1 -1
  27. package/dist/modules/access/access.routes.d.ts +3 -1
  28. package/dist/modules/access/access.routes.d.ts.map +1 -1
  29. package/dist/modules/access/access.routes.js +22 -20
  30. package/dist/modules/access/access.routes.js.map +1 -1
  31. package/dist/modules/access/creator-access.d.ts +2 -2
  32. package/dist/modules/access/creator-access.js +5 -5
  33. package/dist/modules/access/creator-access.js.map +1 -1
  34. package/dist/modules/access/render-roles-yaml.d.ts +22 -0
  35. package/dist/modules/access/render-roles-yaml.d.ts.map +1 -0
  36. package/dist/modules/access/render-roles-yaml.js +56 -0
  37. package/dist/modules/access/render-roles-yaml.js.map +1 -0
  38. package/dist/modules/access/roles-admin.service.d.ts +33 -5
  39. package/dist/modules/access/roles-admin.service.d.ts.map +1 -1
  40. package/dist/modules/access/roles-admin.service.js +44 -19
  41. package/dist/modules/access/roles-admin.service.js.map +1 -1
  42. package/dist/modules/code-mode/code-mode-names.d.ts +5 -13
  43. package/dist/modules/code-mode/code-mode-names.d.ts.map +1 -1
  44. package/dist/modules/code-mode/code-mode-names.js +5 -27
  45. package/dist/modules/code-mode/code-mode-names.js.map +1 -1
  46. package/dist/modules/code-mode/code-mode.tool.d.ts.map +1 -1
  47. package/dist/modules/code-mode/code-mode.tool.js +29 -7
  48. package/dist/modules/code-mode/code-mode.tool.js.map +1 -1
  49. package/dist/modules/mcp/mcp.service.d.ts +11 -52
  50. package/dist/modules/mcp/mcp.service.d.ts.map +1 -1
  51. package/dist/modules/mcp/mcp.service.js +33 -395
  52. package/dist/modules/mcp/mcp.service.js.map +1 -1
  53. package/dist/modules/plugins/index.d.ts +7 -0
  54. package/dist/modules/plugins/index.d.ts.map +1 -0
  55. package/dist/modules/plugins/index.js +6 -0
  56. package/dist/modules/plugins/index.js.map +1 -0
  57. package/dist/modules/plugins/join-proposals.d.ts +53 -0
  58. package/dist/modules/plugins/join-proposals.d.ts.map +1 -0
  59. package/dist/modules/plugins/join-proposals.js +67 -0
  60. package/dist/modules/plugins/join-proposals.js.map +1 -0
  61. package/dist/modules/plugins/join-requests.service.d.ts +81 -0
  62. package/dist/modules/plugins/join-requests.service.d.ts.map +1 -0
  63. package/dist/modules/plugins/join-requests.service.js +135 -0
  64. package/dist/modules/plugins/join-requests.service.js.map +1 -0
  65. package/dist/modules/plugins/plugin-provision.service.d.ts +134 -0
  66. package/dist/modules/plugins/plugin-provision.service.d.ts.map +1 -0
  67. package/dist/modules/plugins/plugin-provision.service.js +344 -0
  68. package/dist/modules/plugins/plugin-provision.service.js.map +1 -0
  69. package/dist/modules/plugins/plugins.contract.d.ts +106 -0
  70. package/dist/modules/plugins/plugins.contract.d.ts.map +1 -0
  71. package/dist/modules/plugins/plugins.contract.js +36 -0
  72. package/dist/modules/plugins/plugins.contract.js.map +1 -0
  73. package/dist/modules/plugins/plugins.routes.d.ts +42 -0
  74. package/dist/modules/plugins/plugins.routes.d.ts.map +1 -0
  75. package/dist/modules/plugins/plugins.routes.js +379 -0
  76. package/dist/modules/plugins/plugins.routes.js.map +1 -0
  77. package/dist/modules/plugins/plugins.service.d.ts +60 -0
  78. package/dist/modules/plugins/plugins.service.d.ts.map +1 -0
  79. package/dist/modules/plugins/plugins.service.js +172 -0
  80. package/dist/modules/plugins/plugins.service.js.map +1 -0
  81. package/dist/modules/settings/setup.routes.d.ts +10 -1
  82. package/dist/modules/settings/setup.routes.d.ts.map +1 -1
  83. package/dist/modules/settings/setup.routes.js +111 -6
  84. package/dist/modules/settings/setup.routes.js.map +1 -1
  85. package/dist/modules/skills/pending-skills.service.d.ts +2 -2
  86. package/dist/modules/skills/pending-skills.service.js +7 -7
  87. package/dist/modules/skills/pending-skills.service.js.map +1 -1
  88. package/dist/modules/skills/skills.contract.d.ts +4 -4
  89. package/dist/modules/skills/skills.contract.d.ts.map +1 -1
  90. package/dist/modules/skills/skills.contract.js +1 -1
  91. package/dist/modules/skills/skills.service.js +5 -5
  92. package/dist/modules/skills/skills.service.js.map +1 -1
  93. package/dist/modules/tool-manuals/mcp-json-discovery.d.ts +65 -0
  94. package/dist/modules/tool-manuals/mcp-json-discovery.d.ts.map +1 -0
  95. package/dist/modules/tool-manuals/mcp-json-discovery.js +276 -0
  96. package/dist/modules/tool-manuals/mcp-json-discovery.js.map +1 -0
  97. package/dist/modules/tool-manuals/mcp-server-edit.service.d.ts +92 -0
  98. package/dist/modules/tool-manuals/mcp-server-edit.service.d.ts.map +1 -0
  99. package/dist/modules/tool-manuals/mcp-server-edit.service.js +328 -0
  100. package/dist/modules/tool-manuals/mcp-server-edit.service.js.map +1 -0
  101. package/dist/modules/tool-manuals/tool-manuals.contract.d.ts +38 -12
  102. package/dist/modules/tool-manuals/tool-manuals.contract.d.ts.map +1 -1
  103. package/dist/modules/tool-manuals/tool-manuals.contract.js +1 -1
  104. package/dist/modules/tool-manuals/tool-manuals.routes.d.ts +13 -2
  105. package/dist/modules/tool-manuals/tool-manuals.routes.d.ts.map +1 -1
  106. package/dist/modules/tool-manuals/tool-manuals.routes.js +233 -2
  107. package/dist/modules/tool-manuals/tool-manuals.routes.js.map +1 -1
  108. package/dist/modules/tool-manuals/tool-manuals.service.d.ts.map +1 -1
  109. package/dist/modules/tool-manuals/tool-manuals.service.js +74 -37
  110. package/dist/modules/tool-manuals/tool-manuals.service.js.map +1 -1
  111. package/dist/modules/tool-manuals/tool-manuals.tools.js +6 -3
  112. package/dist/modules/tool-manuals/tool-manuals.tools.js.map +1 -1
  113. package/dist/modules/workflow/git/git.service.js +2 -2
  114. package/dist/modules/workflow/git/git.service.js.map +1 -1
  115. package/dist/modules/workspace/kb-seed.service.d.ts +2 -2
  116. package/dist/modules/workspace/kb-seed.service.d.ts.map +1 -1
  117. package/dist/modules/workspace/kb-seed.service.js +43 -10
  118. package/dist/modules/workspace/kb-seed.service.js.map +1 -1
  119. package/dist/modules/workspace/plugins-migration.d.ts +50 -0
  120. package/dist/modules/workspace/plugins-migration.d.ts.map +1 -0
  121. package/dist/modules/workspace/plugins-migration.js +379 -0
  122. package/dist/modules/workspace/plugins-migration.js.map +1 -0
  123. package/dist/modules/workspace/startup/kb-git.d.ts +23 -0
  124. package/dist/modules/workspace/startup/kb-git.d.ts.map +1 -0
  125. package/dist/modules/workspace/startup/kb-git.js +86 -0
  126. package/dist/modules/workspace/startup/kb-git.js.map +1 -0
  127. package/dist/modules/workspace/startup/kb-startup-runner.d.ts +74 -0
  128. package/dist/modules/workspace/startup/kb-startup-runner.d.ts.map +1 -0
  129. package/dist/modules/workspace/startup/kb-startup-runner.js +528 -0
  130. package/dist/modules/workspace/startup/kb-startup-runner.js.map +1 -0
  131. package/dist/modules/workspace/startup/on-server-start.d.ts +105 -0
  132. package/dist/modules/workspace/startup/on-server-start.d.ts.map +1 -0
  133. package/dist/modules/workspace/startup/on-server-start.js +21 -0
  134. package/dist/modules/workspace/startup/on-server-start.js.map +1 -0
  135. package/dist/modules/workspace/startup/steps/groups-to-plugins.step.d.ts +46 -0
  136. package/dist/modules/workspace/startup/steps/groups-to-plugins.step.d.ts.map +1 -0
  137. package/dist/modules/workspace/startup/steps/groups-to-plugins.step.js +492 -0
  138. package/dist/modules/workspace/startup/steps/groups-to-plugins.step.js.map +1 -0
  139. package/dist/modules/workspace/startup/steps/roles-yaml.step.d.ts +23 -0
  140. package/dist/modules/workspace/startup/steps/roles-yaml.step.d.ts.map +1 -0
  141. package/dist/modules/workspace/startup/steps/roles-yaml.step.js +69 -0
  142. package/dist/modules/workspace/startup/steps/roles-yaml.step.js.map +1 -0
  143. package/dist/modules/workspace/startup/steps/seed-tree.d.ts +17 -0
  144. package/dist/modules/workspace/startup/steps/seed-tree.d.ts.map +1 -0
  145. package/dist/modules/workspace/startup/steps/seed-tree.js +109 -0
  146. package/dist/modules/workspace/startup/steps/seed-tree.js.map +1 -0
  147. package/dist/modules/workspace/startup/steps/template-files.step.d.ts +103 -0
  148. package/dist/modules/workspace/startup/steps/template-files.step.d.ts.map +1 -0
  149. package/dist/modules/workspace/startup/steps/template-files.step.js +337 -0
  150. package/dist/modules/workspace/startup/steps/template-files.step.js.map +1 -0
  151. package/dist/modules/workspace/workspace.routes.js +3 -3
  152. package/dist/modules/workspace/workspace.routes.js.map +1 -1
  153. package/dist/modules/workspace/workspace.service.d.ts +0 -9
  154. package/dist/modules/workspace/workspace.service.d.ts.map +1 -1
  155. package/dist/modules/workspace/workspace.service.js +2 -30
  156. package/dist/modules/workspace/workspace.service.js.map +1 -1
  157. package/dist/shared/kb-layout.test.js +3 -3
  158. package/dist/shared/kb-layout.test.js.map +1 -1
  159. package/dist/shared/utcp-namespace.d.ts +6 -27
  160. package/dist/shared/utcp-namespace.d.ts.map +1 -1
  161. package/dist/shared/utcp-namespace.js +6 -63
  162. package/dist/shared/utcp-namespace.js.map +1 -1
  163. package/dist/shared/variable-refs.d.ts +42 -0
  164. package/dist/shared/variable-refs.d.ts.map +1 -0
  165. package/dist/shared/variable-refs.js +60 -0
  166. package/dist/shared/variable-refs.js.map +1 -0
  167. package/kb-template/.bevelignore +1 -1
  168. package/kb-template/AGENTS.md +88 -35
  169. package/kb-template/KnowledgeBase/How to get started.md +10 -10
  170. package/kb-template/access.md +36 -36
  171. package/kb-template/gitignore.template +16 -0
  172. package/migrations/meta/0000_snapshot.json +1479 -1479
  173. package/package.json +5 -4
  174. package/src/assets.ts +25 -25
  175. package/src/core/core-ports.ts +113 -106
  176. package/src/core/create-core-server.ts +85 -20
  177. package/src/core/create-core-services.ts +83 -42
  178. package/src/index.ts +69 -69
  179. package/src/modules/access/__tests__/access-control.atref-batch.test.ts +98 -98
  180. package/src/modules/access/__tests__/access-declarations.test.ts +28 -28
  181. package/src/modules/access/__tests__/access-md-format.test.ts +18 -18
  182. package/src/modules/access/__tests__/access-mutation.service.test.ts +5 -5
  183. package/src/modules/access/__tests__/access-splice.test.ts +2 -2
  184. package/src/modules/access/__tests__/access.routes.overrides.test.ts +16 -16
  185. package/src/modules/access/__tests__/grant-sources.test.ts +12 -12
  186. package/src/modules/access/__tests__/roles-admin.service.test.ts +36 -2
  187. package/src/modules/access/access-control.interface.ts +8 -7
  188. package/src/modules/access/access-control.service.ts +7 -7
  189. package/src/modules/access/access-declarations.ts +5 -5
  190. package/src/modules/access/access-mutation.service.ts +3 -3
  191. package/src/modules/access/access-splice.ts +4 -4
  192. package/src/modules/access/access.routes.ts +23 -20
  193. package/src/modules/access/creator-access.ts +5 -5
  194. package/src/modules/access/render-roles-yaml.ts +65 -0
  195. package/src/modules/access/roles-admin.service.ts +45 -16
  196. package/src/modules/admin/admin-access.routes.ts +29 -29
  197. package/src/modules/auth/__tests__/auth.routes.test.ts +91 -91
  198. package/src/modules/auth/__tests__/rate-limit.test.ts +36 -36
  199. package/src/modules/auth/rate-limit.ts +45 -45
  200. package/src/modules/code-mode/__tests__/code-mode.tool.test.ts +67 -0
  201. package/src/modules/code-mode/code-mode-names.ts +10 -36
  202. package/src/modules/code-mode/code-mode.tool.ts +27 -7
  203. package/src/modules/database/connection.ts +15 -15
  204. package/src/modules/database/schema.ts +11 -11
  205. package/src/modules/diff/__tests__/diff.routes.rejectPathsLocked.test.ts +150 -150
  206. package/src/modules/mcp/mcp.service.ts +57 -435
  207. package/src/modules/{groups → plugins}/__tests__/join-proposals.test.ts +1 -1
  208. package/src/modules/{groups → plugins}/__tests__/join-requests.service.test.ts +7 -7
  209. package/src/modules/{groups/__tests__/group-index.service.test.ts → plugins/__tests__/plugin-index.service.test.ts} +41 -41
  210. package/src/modules/plugins/__tests__/plugin-provision.service.test.ts +312 -0
  211. package/src/modules/{groups/__tests__/groups.routes.test.ts → plugins/__tests__/plugins.routes.test.ts} +100 -100
  212. package/src/modules/plugins/index.ts +17 -0
  213. package/src/modules/{groups → plugins}/join-proposals.ts +2 -2
  214. package/src/modules/{groups → plugins}/join-requests.service.ts +8 -8
  215. package/src/modules/{groups/group-provision.service.ts → plugins/plugin-provision.service.ts} +139 -69
  216. package/src/modules/{groups/groups.contract.ts → plugins/plugins.contract.ts} +26 -26
  217. package/src/modules/{groups/groups.routes.ts → plugins/plugins.routes.ts} +102 -102
  218. package/src/modules/{groups/groups.service.ts → plugins/plugins.service.ts} +43 -43
  219. package/src/modules/secrets-vault/__tests__/tool-owner-gate.route.test.ts +143 -143
  220. package/src/modules/settings/__tests__/setup.routes.test.ts +124 -3
  221. package/src/modules/settings/setup.routes.ts +112 -5
  222. package/src/modules/skills/__tests__/pending-skills.service.test.ts +14 -14
  223. package/src/modules/skills/__tests__/skills.service.test.ts +13 -13
  224. package/src/modules/skills/pending-skills.service.ts +7 -7
  225. package/src/modules/skills/skills.contract.ts +4 -4
  226. package/src/modules/skills/skills.service.ts +5 -5
  227. package/src/modules/tool-auth/llm-usage-meter.ts +19 -19
  228. package/src/modules/tool-manuals/__tests__/mcp-json-discovery.test.ts +198 -0
  229. package/src/modules/tool-manuals/__tests__/mcp-server-edit.service.test.ts +346 -0
  230. package/src/modules/tool-manuals/__tests__/tool-manuals.archive.route.test.ts +101 -0
  231. package/src/modules/tool-manuals/__tests__/tool-manuals.detail.route.test.ts +3 -3
  232. package/src/modules/tool-manuals/__tests__/tool-manuals.mcp-oauth.test.ts +2 -2
  233. package/src/modules/tool-manuals/__tests__/tool-manuals.service.test.ts +27 -27
  234. package/src/modules/tool-manuals/__tests__/tool-manuals.tools.test.ts +3 -3
  235. package/src/modules/tool-manuals/mcp-json-discovery.ts +328 -0
  236. package/src/modules/tool-manuals/mcp-server-edit.service.ts +434 -0
  237. package/src/modules/tool-manuals/tool-manuals.contract.ts +35 -12
  238. package/src/modules/tool-manuals/tool-manuals.routes.ts +222 -1
  239. package/src/modules/tool-manuals/tool-manuals.service.ts +82 -42
  240. package/src/modules/tool-manuals/tool-manuals.tools.ts +6 -3
  241. package/src/modules/workflow/__tests__/workflow.service.facade.test.ts +1 -1
  242. package/src/modules/workflow/git/__tests__/branch-name.test.ts +3 -3
  243. package/src/modules/workflow/git/__tests__/git.service.accessGating.test.ts +3 -3
  244. package/src/modules/workflow/git/__tests__/git.service.commitFile.test.ts +13 -8
  245. package/src/modules/workflow/git/__tests__/git.service.deleteBranch.test.ts +1 -1
  246. package/src/modules/workflow/git/__tests__/pull-request.service.test.ts +1 -1
  247. package/src/modules/workflow/git/git.service.ts +2 -2
  248. package/src/modules/workflow/review-workflow/__tests__/approval-states.test.ts +1 -1
  249. package/src/modules/workflow/review-workflow/__tests__/cancel-pr.test.ts +1 -1
  250. package/src/modules/workflow/workflow-hooks.ts +101 -101
  251. package/src/modules/workspace/__tests__/session-ontology.gate.test.ts +237 -237
  252. package/src/modules/workspace/__tests__/workspace.routes.create-grant.test.ts +236 -236
  253. package/src/modules/workspace/__tests__/workspace.routes.delete.test.ts +179 -179
  254. package/src/modules/workspace/__tests__/workspace.routes.download.test.ts +320 -320
  255. package/src/modules/workspace/__tests__/workspace.routes.read-gate.test.ts +337 -337
  256. package/src/modules/workspace/__tests__/workspace.service.test.ts +27 -0
  257. package/src/modules/workspace/bevel-ignore.ts +66 -66
  258. package/src/modules/workspace/session-sink.ts +25 -25
  259. package/src/modules/workspace/startup/__tests__/kb-startup-runner.test.ts +495 -0
  260. package/src/modules/workspace/startup/kb-git.ts +94 -0
  261. package/src/modules/workspace/startup/kb-startup-runner.ts +597 -0
  262. package/src/modules/workspace/startup/on-server-start.ts +97 -0
  263. package/src/modules/workspace/startup/steps/__tests__/steps.test.ts +636 -0
  264. package/src/modules/workspace/startup/steps/groups-to-plugins.step.ts +561 -0
  265. package/src/modules/workspace/startup/steps/roles-yaml.step.ts +71 -0
  266. package/src/modules/workspace/startup/steps/seed-tree.ts +115 -0
  267. package/src/modules/workspace/startup/steps/template-files.step.ts +360 -0
  268. package/src/modules/workspace/workspace.routes.ts +3 -3
  269. package/src/modules/workspace/workspace.service.ts +2 -35
  270. package/src/modules/workspace/workspace.tools.ts +922 -922
  271. package/src/shared/__tests__/join-request.test.ts +13 -13
  272. package/src/shared/__tests__/kb-layout.plugin.test.ts +45 -0
  273. package/src/shared/kb-layout.test.ts +3 -3
  274. package/src/shared/utcp-namespace.ts +10 -68
  275. package/src/shared/variable-refs.ts +64 -0
  276. package/src/modules/groups/__tests__/group-provision.service.test.ts +0 -247
  277. package/src/modules/groups/index.ts +0 -17
  278. package/src/modules/workspace/__tests__/kb-seed.service.test.ts +0 -444
  279. package/src/modules/workspace/kb-seed.interface.ts +0 -36
  280. package/src/modules/workspace/kb-seed.service.ts +0 -555
  281. package/src/shared/__tests__/kb-layout.group.test.ts +0 -45
  282. /package/kb-template/{Groups → Plugins}/.gitkeep +0 -0
@@ -0,0 +1,53 @@
1
+ import { type Verb } from '../access/access-control.service.js';
2
+ /**
3
+ * What a join branch is PROPOSING, relative to the default branch.
4
+ *
5
+ * A join request is a change request whose branch edits one plugin's
6
+ * `access.md`. Rather than treating that change request as an all-or-nothing
7
+ * merge, the plugin's managers see its individual proposals — "grant Ali read",
8
+ * "grant GTM Team write" — and answer them one at a time. Approving a proposal
9
+ * writes THAT ONE grant onto the default branch through the ordinary access
10
+ * mutation path; the branch is never merged, so nothing else it happens to
11
+ * contain can ride along, and a change request naming five people can be
12
+ * answered with two yeses and three ignores.
13
+ *
14
+ * A proposal is any (principal, verb) GRANT the branch's copy of the file
15
+ * carries that the default branch's copy does not. Deliberately:
16
+ *
17
+ * - grants only. A `deny` entry is not something to "accept", and a branch
18
+ * that REMOVES an existing grant proposes nothing — it is a revocation,
19
+ * which is not what this surface is for. Both are simply invisible here,
20
+ * and both leave the branch as a normal change request in the review UI.
21
+ * - every verb, not just `read`. A branch asking for `write` must be visible
22
+ * AS a write request rather than hiding behind "asked to join"; and the
23
+ * subset test that retires a request has to cover everything the file can
24
+ * express, or a request proposing `write` would never settle.
25
+ *
26
+ * When the list comes back EMPTY the branch adds nothing the default branch
27
+ * does not already grant — its proposals have all been accepted (or were
28
+ * never anything) — and the change request has no reason to stay open.
29
+ */
30
+ export interface JoinProposal {
31
+ verb: Verb;
32
+ /** Canonical identity — lowercased email, or canonical role name. */
33
+ id: string;
34
+ principal: {
35
+ kind: 'user';
36
+ email: string;
37
+ displayName: string;
38
+ } | {
39
+ kind: 'role';
40
+ role: string;
41
+ };
42
+ /** How to name this principal in the UI. */
43
+ label: string;
44
+ }
45
+ /**
46
+ * The grants `branchText` adds over `defaultText` — the proposals a manager
47
+ * can accept. Empty ⇒ the branch's rules are a subset of the default's.
48
+ *
49
+ * `path` is only used to label parse errors; both texts are the same file at
50
+ * two refs.
51
+ */
52
+ export declare function pendingProposals(branchText: string | null, defaultText: string | null, path: string): JoinProposal[];
53
+ //# sourceMappingURL=join-proposals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"join-proposals.d.ts","sourceRoot":"","sources":["../../../src/modules/plugins/join-proposals.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,IAAI,EACV,MAAM,qCAAqC,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,IAAI,CAAC;IACX,qEAAqE;IACrE,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EACL;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,GACpD;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACnC,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;CACf;AAgCD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,MAAM,GAAG,IAAI,EACzB,WAAW,EAAE,MAAM,GAAG,IAAI,EAC1B,IAAI,EAAE,MAAM,GACX,YAAY,EAAE,CA0BhB"}
@@ -0,0 +1,67 @@
1
+ import { KNOWN_VERBS, parseAccessFile, } from '../access/access-control.service.js';
2
+ /** Canonical identity of an entry, for set comparison across the two files. */
3
+ function identityOf(entry) {
4
+ return entry.kind === 'user' ? `user:${entry.email}` : `role:${entry.role}`;
5
+ }
6
+ /**
7
+ * Folder rules from one copy of an `access.md`, per verb, grants only.
8
+ *
9
+ * A file that fails to parse yields NO grants. On the branch side that means
10
+ * a malformed proposal offers nothing to accept (fail-closed). On the default
11
+ * side it means every branch grant looks incoming — which is the safe
12
+ * direction too: the manager is shown proposals to consider rather than
13
+ * having them silently swallowed by an unreadable baseline.
14
+ */
15
+ function grantsByVerb(text, path) {
16
+ const out = new Map();
17
+ for (const verb of KNOWN_VERBS)
18
+ out.set(verb, new Map());
19
+ if (text === null)
20
+ return out;
21
+ const parsed = parseAccessFile(text, path);
22
+ if (!parsed.ok)
23
+ return out;
24
+ for (const verb of KNOWN_VERBS) {
25
+ const byId = out.get(verb);
26
+ for (const entry of parsed.file.entries[verb]) {
27
+ if (entry.deny)
28
+ continue;
29
+ byId.set(identityOf(entry), entry);
30
+ }
31
+ }
32
+ return out;
33
+ }
34
+ /**
35
+ * The grants `branchText` adds over `defaultText` — the proposals a manager
36
+ * can accept. Empty ⇒ the branch's rules are a subset of the default's.
37
+ *
38
+ * `path` is only used to label parse errors; both texts are the same file at
39
+ * two refs.
40
+ */
41
+ export function pendingProposals(branchText, defaultText, path) {
42
+ const branch = grantsByVerb(branchText, path);
43
+ const base = grantsByVerb(defaultText, path);
44
+ const out = [];
45
+ for (const verb of KNOWN_VERBS) {
46
+ const baseIds = base.get(verb);
47
+ for (const [id, entry] of branch.get(verb)) {
48
+ if (baseIds.has(id))
49
+ continue;
50
+ out.push(entry.kind === 'user'
51
+ ? {
52
+ verb,
53
+ id,
54
+ principal: { kind: 'user', email: entry.email, displayName: entry.displayName },
55
+ label: entry.displayName,
56
+ }
57
+ : {
58
+ verb,
59
+ id,
60
+ principal: { kind: 'role', role: entry.displayRole },
61
+ label: entry.displayRole,
62
+ });
63
+ }
64
+ }
65
+ return out;
66
+ }
67
+ //# sourceMappingURL=join-proposals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"join-proposals.js","sourceRoot":"","sources":["../../../src/modules/plugins/join-proposals.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,eAAe,GAGhB,MAAM,qCAAqC,CAAC;AAyC7C,+EAA+E;AAC/E,SAAS,UAAU,CAAC,KAAkB;IACpC,OAAO,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,QAAQ,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;AAC9E,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,YAAY,CAAC,IAAmB,EA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CAAC,GAAG,CAAC,EAAE,CAAC;gBAAE,SAAS;YAC9B,GAAG,CAAC,IAAI,CACN,KAAK,CAAC,IAAI,KAAK,MAAM;gBACnB,CAAC,CAAC;oBACE,IAAI;oBACJ,EAAE;oBACF,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE;oBAC/E,KAAK,EAAE,KAAK,CAAC,WAAW;iBACzB;gBACH,CAAC,CAAC;oBACE,IAAI;oBACJ,EAAE;oBACF,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,WAAW,EAAE;oBACpD,KAAK,EAAE,KAAK,CAAC,WAAW;iBACzB,CACN,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,81 @@
1
+ import { type AuthUser, type ChangeRequest, type IWorkflowService } from '@bevel-software/platform-shared';
2
+ import { type WorkspaceService } from '../workspace/workspace.service.js';
3
+ import { type JoinProposal } from './join-proposals.js';
4
+ /** One open join change request, with what it still proposes. */
5
+ export interface JoinRequest {
6
+ number: number;
7
+ branch: string;
8
+ requesterName: string;
9
+ createdAt: string;
10
+ /** Grants the branch adds over the default branch. Never empty (see below). */
11
+ proposals: JoinProposal[];
12
+ }
13
+ /**
14
+ * Join requests as PROPOSALS, and the reconciliation that retires them.
15
+ *
16
+ * The lifecycle has no state of its own — it is derived, every time, from two
17
+ * copies of one file:
18
+ *
19
+ * open the branch's `access.md` grants something the default's does not
20
+ * settled it does not
21
+ *
22
+ * so "approve" is not an operation on the request at all. A manager grants a
23
+ * principal through the ordinary access path (the same lock + commit every
24
+ * other access edit uses, gated the same way), the default branch gains that
25
+ * entry, and the proposal stops being pending because the diff no longer
26
+ * contains it. When the last one goes, the change request has nothing left to
27
+ * say and is rejected, its branch deleted.
28
+ *
29
+ * That reconciliation runs LAZILY on every listing as well as on demand, so a
30
+ * grant made anywhere — this banner, the Manage-access dialog, a hand edit —
31
+ * settles the request that asked for it. Nothing has to remember to.
32
+ */
33
+ export declare class JoinRequestsService {
34
+ private readonly workspaceService;
35
+ private readonly workflow;
36
+ constructor(workspaceService: WorkspaceService, workflow: IWorkflowService);
37
+ /**
38
+ * Open join requests for `plugin`, each carrying only its still-pending
39
+ * proposals. Requests with none left are reconciled away (rejected, branch
40
+ * deleted) and omitted.
41
+ *
42
+ * `actor` is who the reconciliation acts as — a manager of the plugin, since
43
+ * rejecting a change request requires write on everything it touches.
44
+ */
45
+ list(plugin: string, folder: string, crs: ChangeRequest[], actor: AuthUser): Promise<JoinRequest[]>;
46
+ /**
47
+ * Re-check ONE request and settle it if nothing is pending. Returns whether
48
+ * it was settled. Called right after a grant so the banner updates in the
49
+ * same round-trip instead of waiting for the next listing.
50
+ */
51
+ reconcile(plugin: string, folder: string, cr: ChangeRequest, actor: AuthUser): Promise<boolean>;
52
+ /**
53
+ * Close a request whose proposals have all landed, and delete its branch.
54
+ *
55
+ * Rejecting rather than merging is the point: the grants are already on the
56
+ * default branch, so merging would replay a diff that is now empty of
57
+ * meaning while dragging along anything else the branch carries. The branch
58
+ * goes too — it exists only to hold a proposal that no longer exists.
59
+ *
60
+ * Best-effort by contract: this runs inside a listing, and a request that
61
+ * cannot be closed right now must not take the listing down with it. The
62
+ * next pass tries again.
63
+ */
64
+ private settle;
65
+ /**
66
+ * The file at one branch, or null when it is absent/unreadable there.
67
+ *
68
+ * Every read runs against the DEFAULT branch's clone at `origin/<branch>`,
69
+ * so one workspace answers for every request and a join branch never needs
70
+ * a clone of its own. `readFileAtRef` takes a REPO-relative path (the KB
71
+ * dir is the repo root there).
72
+ */
73
+ private readAt;
74
+ /**
75
+ * Refresh remote-tracking refs before reading them. Throttled inside, and
76
+ * best-effort: a request pushed seconds ago is worth one fetch, but a fetch
77
+ * failure must degrade to "read what we have" rather than empty the list.
78
+ */
79
+ private refresh;
80
+ }
81
+ //# sourceMappingURL=join-requests.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"join-requests.service.d.ts","sourceRoot":"","sources":["../../../src/modules/plugins/join-requests.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACtB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAwB,KAAK,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAChG,OAAO,EAAoB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE1E,iEAAiE;AACjE,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,+EAA+E;IAC/E,SAAS,EAAE,YAAY,EAAE,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,mBAAmB;IAE5B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBADR,gBAAgB,EAAE,gBAAgB,EAClC,QAAQ,EAAE,gBAAgB;IAG7C;;;;;;;OAOG;IACG,IAAI,CACR,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,aAAa,EAAE,EACpB,KAAK,EAAE,QAAQ,GACd,OAAO,CAAC,WAAW,EAAE,CAAC;IA2BzB;;;;OAIG;IACG,SAAS,CACb,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,aAAa,EACjB,KAAK,EAAE,QAAQ,GACd,OAAO,CAAC,OAAO,CAAC;IAcnB;;;;;;;;;;;OAWG;YACW,MAAM;IAgCpB;;;;;;;OAOG;YACW,MAAM;IAYpB;;;;OAIG;YACW,OAAO;CAKtB"}
@@ -0,0 +1,135 @@
1
+ import { DEFAULT_BRANCH, isJoinBranchFor, } from '@bevel-software/platform-shared';
2
+ import { workspaceIdForBranch } from '../workspace/workspace.service.js';
3
+ import { pendingProposals } from './join-proposals.js';
4
+ /**
5
+ * Join requests as PROPOSALS, and the reconciliation that retires them.
6
+ *
7
+ * The lifecycle has no state of its own — it is derived, every time, from two
8
+ * copies of one file:
9
+ *
10
+ * open the branch's `access.md` grants something the default's does not
11
+ * settled it does not
12
+ *
13
+ * so "approve" is not an operation on the request at all. A manager grants a
14
+ * principal through the ordinary access path (the same lock + commit every
15
+ * other access edit uses, gated the same way), the default branch gains that
16
+ * entry, and the proposal stops being pending because the diff no longer
17
+ * contains it. When the last one goes, the change request has nothing left to
18
+ * say and is rejected, its branch deleted.
19
+ *
20
+ * That reconciliation runs LAZILY on every listing as well as on demand, so a
21
+ * grant made anywhere — this banner, the Manage-access dialog, a hand edit —
22
+ * settles the request that asked for it. Nothing has to remember to.
23
+ */
24
+ export class JoinRequestsService {
25
+ workspaceService;
26
+ workflow;
27
+ constructor(workspaceService, workflow) {
28
+ this.workspaceService = workspaceService;
29
+ this.workflow = workflow;
30
+ }
31
+ /**
32
+ * Open join requests for `plugin`, each carrying only its still-pending
33
+ * proposals. Requests with none left are reconciled away (rejected, branch
34
+ * deleted) and omitted.
35
+ *
36
+ * `actor` is who the reconciliation acts as — a manager of the plugin, since
37
+ * rejecting a change request requires write on everything it touches.
38
+ */
39
+ async list(plugin, folder, crs, actor) {
40
+ await this.refresh();
41
+ const accessPath = `${folder}/access.md`;
42
+ const baseText = await this.readAt(DEFAULT_BRANCH, accessPath);
43
+ const out = [];
44
+ for (const cr of crs) {
45
+ if (cr.state !== 'open' || !isJoinBranchFor(cr.branch, plugin))
46
+ continue;
47
+ const proposals = pendingProposals(await this.readAt(cr.branch, accessPath), baseText, accessPath);
48
+ if (proposals.length === 0) {
49
+ await this.settle(cr, actor);
50
+ continue;
51
+ }
52
+ out.push({
53
+ number: cr.number,
54
+ branch: cr.branch,
55
+ requesterName: cr.appAuthor?.name ?? 'Someone',
56
+ createdAt: cr.createdAt,
57
+ proposals,
58
+ });
59
+ }
60
+ return out.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
61
+ }
62
+ /**
63
+ * Re-check ONE request and settle it if nothing is pending. Returns whether
64
+ * it was settled. Called right after a grant so the banner updates in the
65
+ * same round-trip instead of waiting for the next listing.
66
+ */
67
+ async reconcile(plugin, folder, cr, actor) {
68
+ if (cr.state !== 'open' || !isJoinBranchFor(cr.branch, plugin))
69
+ return false;
70
+ await this.refresh();
71
+ const accessPath = `${folder}/access.md`;
72
+ const proposals = pendingProposals(await this.readAt(cr.branch, accessPath), await this.readAt(DEFAULT_BRANCH, accessPath), accessPath);
73
+ if (proposals.length > 0)
74
+ return false;
75
+ await this.settle(cr, actor);
76
+ return true;
77
+ }
78
+ /**
79
+ * Close a request whose proposals have all landed, and delete its branch.
80
+ *
81
+ * Rejecting rather than merging is the point: the grants are already on the
82
+ * default branch, so merging would replay a diff that is now empty of
83
+ * meaning while dragging along anything else the branch carries. The branch
84
+ * goes too — it exists only to hold a proposal that no longer exists.
85
+ *
86
+ * Best-effort by contract: this runs inside a listing, and a request that
87
+ * cannot be closed right now must not take the listing down with it. The
88
+ * next pass tries again.
89
+ */
90
+ async settle(cr, actor) {
91
+ const wsId = workspaceIdForBranch(DEFAULT_BRANCH);
92
+ try {
93
+ await this.workflow.rejectChangeRequest(cr.number, actor, cr.state, cr.authorId ?? null, cr.base, wsId);
94
+ }
95
+ catch (err) {
96
+ console.warn(`[plugins] could not close settled join request #${cr.number}: ${err instanceof Error ? err.message : String(err)}`);
97
+ return;
98
+ }
99
+ try {
100
+ await this.workflow.deleteBranch(wsId, cr.branch, actor);
101
+ }
102
+ catch (err) {
103
+ // The request is closed either way; a leftover branch is cosmetic and
104
+ // the author can still delete it themselves.
105
+ console.warn(`[plugins] closed join request #${cr.number} but could not delete "${cr.branch}": ${err instanceof Error ? err.message : String(err)}`);
106
+ }
107
+ }
108
+ /**
109
+ * The file at one branch, or null when it is absent/unreadable there.
110
+ *
111
+ * Every read runs against the DEFAULT branch's clone at `origin/<branch>`,
112
+ * so one workspace answers for every request and a join branch never needs
113
+ * a clone of its own. `readFileAtRef` takes a REPO-relative path (the KB
114
+ * dir is the repo root there).
115
+ */
116
+ async readAt(branch, repoRelPath) {
117
+ try {
118
+ return await this.workspaceService.readFileAtRef(workspaceIdForBranch(DEFAULT_BRANCH), `origin/${branch}`, repoRelPath);
119
+ }
120
+ catch {
121
+ return null;
122
+ }
123
+ }
124
+ /**
125
+ * Refresh remote-tracking refs before reading them. Throttled inside, and
126
+ * best-effort: a request pushed seconds ago is worth one fetch, but a fetch
127
+ * failure must degrade to "read what we have" rather than empty the list.
128
+ */
129
+ async refresh() {
130
+ await this.workspaceService
131
+ .ensureRemotesFetched(workspaceIdForBranch(DEFAULT_BRANCH))
132
+ .catch(() => undefined);
133
+ }
134
+ }
135
+ //# sourceMappingURL=join-requests.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"join-requests.service.js","sourceRoot":"","sources":["../../../src/modules/plugins/join-requests.service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,eAAe,GAIhB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAyB,MAAM,mCAAmC,CAAC;AAChG,OAAO,EAAE,gBAAgB,EAAqB,MAAM,qBAAqB,CAAC;AAY1E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,mBAAmB;IAEX;IACA;IAFnB,YACmB,gBAAkC,EAClC,QAA0B;QAD1B,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,aAAQ,GAAR,QAAQ,CAAkB;IAC1C,CAAC;IAEJ;;;;;;;OAOG;IACH,KAAK,CAAC,IAAI,CACR,MAAc,EACd,MAAc,EACd,GAAoB,EACpB,KAAe;QAEf,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QACrB,MAAM,UAAU,GAAG,GAAG,MAAM,YAAY,CAAC;QACzC,MAAM,QAAQ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E,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CACjD,EAAE,CACH,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACK,KAAK,CAAC,MAAM,CAAC,MAAc,EAAE,WAAmB;QACtD,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,gBAAgB,CAAC,aAAa,CAC9C,oBAAoB,CAAC,cAAc,CAAC,EACpC,UAAU,MAAM,EAAE,EAClB,WAAW,CACZ,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED;;;;OAIG;IACK,KAAK,CAAC,OAAO;QACnB,MAAM,IAAI,CAAC,gBAAgB;aACxB,oBAAoB,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC;aAC1D,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC5B,CAAC;CACF"}
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Plugin provisioning — the ONE privileged door for bringing a `Plugins/<name>/`
3
+ * folder into existence, and (via {@link PluginProvisionService.deletePlugin})
4
+ * for taking one back out of it.
5
+ *
6
+ * Creating a plugin is the single operation the access model cannot govern
7
+ * from inside: the folder that will carry the rules does not exist yet, and
8
+ * the root's own rule (`write: Admin`) says no. The old answer was a
9
+ * carve-out inside the generic write gate — every write path could claim an
10
+ * unused name under `Plugins/`, and the gate had to re-derive "is this that
11
+ * one blessed case?" on every check. This service replaces that: the generic
12
+ * gate is uniformly strict again, and the privilege lives here, named,
13
+ * behind its own endpoint.
14
+ *
15
+ * What a provision IS: one exclusive write of the new folder's `access.md`
16
+ * (flag `wx`, so two concurrent creators race for the fs, not for the
17
+ * overwrite), then one SYNCHRONOUS commit+push. Synchronous on purpose — the
18
+ * write gate reads rules at HEAD, so a creation whose access.md were still
19
+ * sitting in the async commit queue would 403 the very next thing its
20
+ * creator does (writing the first skill into it).
21
+ *
22
+ * Two shapes, two templates:
23
+ *
24
+ * - A NAMED plugin: discoverable by design. The access.md's own frontmatter
25
+ * reads `everyone` — anyone may open the FILE, see the plugin listed, and
26
+ * ask to join — while the BODY (the folder's actual rules) names only
27
+ * the creator under read, write and owner.
28
+ * - A PERSONAL folder (`personal-<user-id>`): private by design. No
29
+ * frontmatter grant at all, so nobody else can even see it exists; the
30
+ * body names its owner. Created lazily (ensure semantics) on the first
31
+ * personal skill.
32
+ */
33
+ import { type AuthUser } from '@bevel-software/platform-shared';
34
+ import type { WorkspaceService } from '../workspace/workspace.service.js';
35
+ import type { IAccessControl } from '../access/access-control.interface.js';
36
+ /** Commit machinery the provision rides — the pending-commit pipeline, run inline. */
37
+ export interface ProvisionCommitDriver {
38
+ runPendingCommit(workspaceId: string, branch: string, targetPath: string, user: AuthUser, opts?: {
39
+ systemAuthorized?: boolean;
40
+ }): Promise<void>;
41
+ }
42
+ export interface ProvisionedPlugin {
43
+ /** The folder name under `Plugins/` (not the full path). */
44
+ folder: string;
45
+ /** False when an ensure found the folder already there. */
46
+ created: boolean;
47
+ }
48
+ /** A refusal the route can pass through: message + HTTP status. */
49
+ export declare class PluginProvisionError extends Error {
50
+ readonly status: number;
51
+ constructor(message: string, status: number);
52
+ }
53
+ export declare class PluginProvisionService {
54
+ private readonly workspaceService;
55
+ private readonly commits;
56
+ private readonly accessControl;
57
+ private readonly kbDirName;
58
+ private readonly events?;
59
+ /**
60
+ * Serialises creations and deletions by MANIFEST SLUG
61
+ * (`pluginManifestName(name)`). The wx write arbitrates same-path races,
62
+ * but the identity the collision checks defend is the slug: case-variants
63
+ * (`GTM`/`gtm`) and distinct spellings (`Sales Team`/`Sales-Team`) all
64
+ * derive the same key, so no two requests that would publish one manifest
65
+ * name can hold the lock at once.
66
+ */
67
+ private readonly creations;
68
+ constructor(workspaceService: WorkspaceService, commits: ProvisionCommitDriver, accessControl: IAccessControl, kbDirName: string, events?: {
69
+ emit(event: {
70
+ kind: "fs-tree-changed";
71
+ workspaceId: string;
72
+ branch: string;
73
+ }): void;
74
+ } | undefined);
75
+ /**
76
+ * Create `Plugins/<name>/` for `user`. Throws `PluginProvisionError` 422 on a
77
+ * name the filesystem or the model cannot carry, 409 when the name is taken
78
+ * (case-insensitively — the workspaces live on case-insensitive
79
+ * filesystems too, where `GTM` and `gtm` are one folder).
80
+ */
81
+ createPlugin(user: AuthUser, rawName: string): Promise<ProvisionedPlugin>;
82
+ /**
83
+ * Ensure the caller's personal folder exists — idempotent, keyed to the
84
+ * stable user id. Returns `created: false` when it is already there.
85
+ */
86
+ ensurePersonalPlugin(user: AuthUser): Promise<ProvisionedPlugin>;
87
+ /**
88
+ * Delete `Plugins/<name>/` — the whole folder, its skills and tools
89
+ * included, in ONE commit. MECHANISM only: the route owns the
90
+ * authorization (the caller must hold the `owner` verb on the folder;
91
+ * this service never re-derives it), exactly as `createPlugin` leaves
92
+ * "any signed-in user" to its endpoint.
93
+ *
94
+ * Shape mirrors a provision run in reverse, with the same failure
95
+ * contract: the folder is PARKED (renamed to a dot-prefixed sibling the
96
+ * scanners ignore) rather than removed, the deletion is committed
97
+ * synchronously, and only a landed commit lets the parked bytes go. A
98
+ * refused commit renames the folder back, so a failed delete leaves the
99
+ * plugin exactly as it was — never half-gone on disk while origin still
100
+ * carries it.
101
+ *
102
+ * Serialised on the same slug-keyed lock creations use, so a delete can
103
+ * never interleave with a re-creation of the same name (the key derives
104
+ * from the name, so both spell it identically).
105
+ */
106
+ deletePlugin(user: AuthUser, rawName: string): Promise<void>;
107
+ /** The taken name (in its on-disk casing) colliding with `name`, or null. */
108
+ private existingFolder;
109
+ /** An existing PLUGIN FOLDER whose derived manifest name equals `name`'s, or null. */
110
+ private manifestNameTwin;
111
+ private provision;
112
+ private readyWorkspaceId;
113
+ }
114
+ /**
115
+ * A named plugin's access.md: discoverable file (frontmatter `read: everyone`
116
+ * — anyone may see the plugin listed and ask to join), creator-run folder
117
+ * (body read/write/owner name the creator). The `read: []` placeholder makes
118
+ * the body parse as rules from the first byte, so every later splice targets
119
+ * the body rather than the frontmatter.
120
+ */
121
+ export declare function pluginAccessMd(creator: {
122
+ name: string;
123
+ email: string;
124
+ }): string;
125
+ /**
126
+ * A personal folder's access.md: PRIVATE — no frontmatter grant, so the
127
+ * folder is invisible to everyone but its owner; the body names the owner
128
+ * under read, write and owner.
129
+ */
130
+ export declare function personalAccessMd(creator: {
131
+ name: string;
132
+ email: string;
133
+ }): string;
134
+ //# sourceMappingURL=plugin-provision.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-provision.service.d.ts","sourceRoot":"","sources":["../../../src/modules/plugins/plugin-provision.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAKH,OAAO,EASL,KAAK,QAAQ,EACd,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAK5E,sFAAsF;AACtF,MAAM,WAAW,qBAAqB;IACpC,gBAAgB,CACd,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,QAAQ,EACd,IAAI,CAAC,EAAE;QAAE,gBAAgB,CAAC,EAAE,OAAO,CAAA;KAAE,GACpC,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,4DAA4D;IAC5D,MAAM,EAAE,MAAM,CAAC;IACf,2DAA2D;IAC3D,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,mEAAmE;AACnE,qBAAa,oBAAqB,SAAQ,KAAK;IAG3C,QAAQ,CAAC,MAAM,EAAE,MAAM;gBADvB,OAAO,EAAE,MAAM,EACN,MAAM,EAAE,MAAM;CAK1B;AAED,qBAAa,sBAAsB;IAY/B,OAAO,CAAC,QAAQ,CA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