@braidhq/server 0.1.0 → 0.2.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 (385) hide show
  1. package/README.md +134 -106
  2. package/dist/app.d.ts +7 -15
  3. package/dist/app.d.ts.map +1 -1
  4. package/dist/app.js +72 -45
  5. package/dist/app.js.map +1 -1
  6. package/dist/authMode.d.ts +39 -0
  7. package/dist/authMode.d.ts.map +1 -0
  8. package/dist/authMode.js +50 -0
  9. package/dist/authMode.js.map +1 -0
  10. package/dist/composeApp.d.ts +79 -0
  11. package/dist/composeApp.d.ts.map +1 -0
  12. package/dist/composeApp.js +136 -0
  13. package/dist/composeApp.js.map +1 -0
  14. package/dist/composeFsApp.d.ts +27 -0
  15. package/dist/composeFsApp.d.ts.map +1 -0
  16. package/dist/{composeFs.js → composeFsApp.js} +118 -125
  17. package/dist/composeFsApp.js.map +1 -0
  18. package/dist/index.d.ts +3 -2
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +3 -2
  21. package/dist/index.js.map +1 -1
  22. package/dist/infrastructure/_shared/env.d.ts +10 -0
  23. package/dist/infrastructure/_shared/env.d.ts.map +1 -0
  24. package/dist/infrastructure/{env.js → _shared/env.js} +5 -6
  25. package/dist/infrastructure/_shared/env.js.map +1 -0
  26. package/dist/infrastructure/_shared/frontmatter.d.ts +13 -0
  27. package/dist/infrastructure/_shared/frontmatter.d.ts.map +1 -0
  28. package/dist/infrastructure/{fs → _shared}/frontmatter.js +5 -5
  29. package/dist/infrastructure/_shared/frontmatter.js.map +1 -0
  30. package/dist/infrastructure/_shared/jsonFileStore.d.ts.map +1 -0
  31. package/dist/infrastructure/_shared/jsonFileStore.js.map +1 -0
  32. package/dist/infrastructure/{fs → _shared}/paths.d.ts +17 -10
  33. package/dist/infrastructure/_shared/paths.d.ts.map +1 -0
  34. package/dist/infrastructure/{fs → _shared}/paths.js +27 -20
  35. package/dist/infrastructure/_shared/paths.js.map +1 -0
  36. package/dist/infrastructure/auth/AccessPolicy.d.ts +33 -58
  37. package/dist/infrastructure/auth/AccessPolicy.d.ts.map +1 -1
  38. package/dist/infrastructure/auth/AccessPolicy.js +35 -42
  39. package/dist/infrastructure/auth/AccessPolicy.js.map +1 -1
  40. package/dist/infrastructure/auth/SessionStore.d.ts +22 -12
  41. package/dist/infrastructure/auth/SessionStore.d.ts.map +1 -1
  42. package/dist/infrastructure/auth/SessionStore.js +15 -18
  43. package/dist/infrastructure/auth/SessionStore.js.map +1 -1
  44. package/dist/infrastructure/batch/FsBatchPlanRepository.d.ts +79 -0
  45. package/dist/infrastructure/batch/FsBatchPlanRepository.d.ts.map +1 -0
  46. package/dist/infrastructure/{fs → batch}/FsBatchPlanRepository.js +1 -1
  47. package/dist/infrastructure/batch/FsBatchPlanRepository.js.map +1 -0
  48. package/dist/infrastructure/history/GitWorkspaceHistory.d.ts.map +1 -0
  49. package/dist/infrastructure/{git → history}/GitWorkspaceHistory.js +31 -24
  50. package/dist/infrastructure/history/GitWorkspaceHistory.js.map +1 -0
  51. package/dist/infrastructure/history/commitMessage.d.ts.map +1 -0
  52. package/dist/infrastructure/history/commitMessage.js +90 -0
  53. package/dist/infrastructure/history/commitMessage.js.map +1 -0
  54. package/dist/infrastructure/hitl/FsClarificationRepository.d.ts +13 -0
  55. package/dist/infrastructure/hitl/FsClarificationRepository.d.ts.map +1 -0
  56. package/dist/infrastructure/{fs/FsClarifyTicketRepository.js → hitl/FsClarificationRepository.js} +15 -15
  57. package/dist/infrastructure/hitl/FsClarificationRepository.js.map +1 -0
  58. package/dist/infrastructure/hitl/FsProposalRepository.d.ts.map +1 -0
  59. package/dist/infrastructure/{fs → hitl}/FsProposalRepository.js +7 -8
  60. package/dist/infrastructure/hitl/FsProposalRepository.js.map +1 -0
  61. package/dist/infrastructure/hitl/StatusedJsonStore.d.ts +30 -0
  62. package/dist/infrastructure/hitl/StatusedJsonStore.d.ts.map +1 -0
  63. package/dist/infrastructure/{fs/FsStatusedJsonRepository.js → hitl/StatusedJsonStore.js} +3 -3
  64. package/dist/infrastructure/hitl/StatusedJsonStore.js.map +1 -0
  65. package/dist/infrastructure/model/FsModelSerializer.d.ts +96 -0
  66. package/dist/infrastructure/model/FsModelSerializer.d.ts.map +1 -0
  67. package/dist/infrastructure/{fs/FsGraphSerializer.js → model/FsModelSerializer.js} +11 -11
  68. package/dist/infrastructure/model/FsModelSerializer.js.map +1 -0
  69. package/dist/infrastructure/oauth/GoogleOAuth.d.ts +20 -38
  70. package/dist/infrastructure/oauth/GoogleOAuth.d.ts.map +1 -1
  71. package/dist/infrastructure/oauth/GoogleOAuth.js +21 -22
  72. package/dist/infrastructure/oauth/GoogleOAuth.js.map +1 -1
  73. package/dist/infrastructure/reactor/FsReactorCycleRepository.d.ts +29 -0
  74. package/dist/infrastructure/reactor/FsReactorCycleRepository.d.ts.map +1 -0
  75. package/dist/infrastructure/reactor/FsReactorCycleRepository.js +94 -0
  76. package/dist/infrastructure/reactor/FsReactorCycleRepository.js.map +1 -0
  77. package/dist/infrastructure/secrets/SecretStore.d.ts +11 -14
  78. package/dist/infrastructure/secrets/SecretStore.d.ts.map +1 -1
  79. package/dist/infrastructure/secrets/SecretStore.js +4 -4
  80. package/dist/infrastructure/secrets/SecretStore.js.map +1 -1
  81. package/dist/infrastructure/{fs → skill}/FsRunRepository.d.ts +5 -3
  82. package/dist/infrastructure/skill/FsRunRepository.d.ts.map +1 -0
  83. package/dist/infrastructure/{fs → skill}/FsRunRepository.js +11 -9
  84. package/dist/infrastructure/skill/FsRunRepository.js.map +1 -0
  85. package/dist/infrastructure/{fs → skill}/FsSkillRegistry.d.ts +4 -13
  86. package/dist/infrastructure/skill/FsSkillRegistry.d.ts.map +1 -0
  87. package/dist/infrastructure/{fs → skill}/FsSkillRegistry.js +28 -20
  88. package/dist/infrastructure/skill/FsSkillRegistry.js.map +1 -0
  89. package/dist/infrastructure/skill/SubprocessSkillRunner.d.ts +52 -0
  90. package/dist/infrastructure/skill/SubprocessSkillRunner.d.ts.map +1 -0
  91. package/dist/infrastructure/{agent → skill}/SubprocessSkillRunner.js +107 -55
  92. package/dist/infrastructure/skill/SubprocessSkillRunner.js.map +1 -0
  93. package/dist/infrastructure/skill/asyncQueue.d.ts +20 -0
  94. package/dist/infrastructure/skill/asyncQueue.d.ts.map +1 -0
  95. package/dist/infrastructure/{agent → skill}/asyncQueue.js +2 -3
  96. package/dist/infrastructure/{agent → skill}/asyncQueue.js.map +1 -1
  97. package/dist/infrastructure/skill/lineBuffer.d.ts +15 -0
  98. package/dist/infrastructure/skill/lineBuffer.d.ts.map +1 -0
  99. package/dist/infrastructure/{agent/streamJsonParser.js → skill/lineBuffer.js} +5 -17
  100. package/dist/infrastructure/skill/lineBuffer.js.map +1 -0
  101. package/dist/infrastructure/skill/orphanReaper.d.ts +20 -0
  102. package/dist/infrastructure/skill/orphanReaper.d.ts.map +1 -0
  103. package/dist/infrastructure/{orphanReaper.js → skill/orphanReaper.js} +7 -5
  104. package/dist/infrastructure/skill/orphanReaper.js.map +1 -0
  105. package/dist/infrastructure/skill/subprocessEventStream.d.ts +16 -0
  106. package/dist/infrastructure/skill/subprocessEventStream.d.ts.map +1 -0
  107. package/dist/infrastructure/skill/subprocessEventStream.js +29 -0
  108. package/dist/infrastructure/skill/subprocessEventStream.js.map +1 -0
  109. package/dist/infrastructure/source/FsSourceUnitDigest.d.ts +19 -0
  110. package/dist/infrastructure/source/FsSourceUnitDigest.d.ts.map +1 -0
  111. package/dist/infrastructure/{fs → source}/FsSourceUnitDigest.js +9 -9
  112. package/dist/infrastructure/source/FsSourceUnitDigest.js.map +1 -0
  113. package/dist/infrastructure/source/FsSourceUnitObservationRepository.d.ts +31 -0
  114. package/dist/infrastructure/source/FsSourceUnitObservationRepository.d.ts.map +1 -0
  115. package/dist/infrastructure/{fs/FsSourceUnitStateRepository.js → source/FsSourceUnitObservationRepository.js} +18 -17
  116. package/dist/infrastructure/source/FsSourceUnitObservationRepository.js.map +1 -0
  117. package/dist/infrastructure/{fs → source}/intentScan.d.ts +4 -0
  118. package/dist/infrastructure/source/intentScan.d.ts.map +1 -0
  119. package/dist/infrastructure/{fs → source}/intentScan.js +18 -16
  120. package/dist/infrastructure/source/intentScan.js.map +1 -0
  121. package/dist/infrastructure/users/UserDirectoryFromRegistry.d.ts +2 -2
  122. package/dist/infrastructure/users/UserDirectoryFromRegistry.js +2 -2
  123. package/dist/infrastructure/users/UserRegistryFile.d.ts +4 -5
  124. package/dist/infrastructure/users/UserRegistryFile.d.ts.map +1 -1
  125. package/dist/infrastructure/users/UserRegistryFile.js +6 -8
  126. package/dist/infrastructure/users/UserRegistryFile.js.map +1 -1
  127. package/dist/infrastructure/users/ensureWorkspaceOwners.d.ts +9 -6
  128. package/dist/infrastructure/users/ensureWorkspaceOwners.d.ts.map +1 -1
  129. package/dist/infrastructure/users/ensureWorkspaceOwners.js +10 -7
  130. package/dist/infrastructure/users/ensureWorkspaceOwners.js.map +1 -1
  131. package/dist/infrastructure/workspace/FsWorkspaceRepository.d.ts.map +1 -0
  132. package/dist/infrastructure/{fs → workspace}/FsWorkspaceRepository.js +7 -6
  133. package/dist/infrastructure/workspace/FsWorkspaceRepository.js.map +1 -0
  134. package/dist/infrastructure/workspace/WorkspaceDiscovery.d.ts +18 -0
  135. package/dist/infrastructure/workspace/WorkspaceDiscovery.d.ts.map +1 -0
  136. package/dist/infrastructure/{fs → workspace}/WorkspaceDiscovery.js +15 -11
  137. package/dist/infrastructure/workspace/WorkspaceDiscovery.js.map +1 -0
  138. package/dist/infrastructure/{fs → workspace}/WorkspaceRegistryFile.d.ts +10 -9
  139. package/dist/infrastructure/workspace/WorkspaceRegistryFile.d.ts.map +1 -0
  140. package/dist/infrastructure/{fs → workspace}/WorkspaceRegistryFile.js +15 -17
  141. package/dist/infrastructure/workspace/WorkspaceRegistryFile.js.map +1 -0
  142. package/dist/infrastructure/workspace/productManifestWriter.d.ts +24 -0
  143. package/dist/infrastructure/workspace/productManifestWriter.d.ts.map +1 -0
  144. package/dist/infrastructure/{fs → workspace}/productManifestWriter.js +14 -26
  145. package/dist/infrastructure/workspace/productManifestWriter.js.map +1 -0
  146. package/dist/middleware/auth.d.ts +27 -17
  147. package/dist/middleware/auth.d.ts.map +1 -1
  148. package/dist/middleware/auth.js +59 -53
  149. package/dist/middleware/auth.js.map +1 -1
  150. package/dist/middleware/cors.d.ts.map +1 -1
  151. package/dist/middleware/cors.js +4 -1
  152. package/dist/middleware/cors.js.map +1 -1
  153. package/dist/middleware/error.d.ts.map +1 -1
  154. package/dist/middleware/error.js +15 -13
  155. package/dist/middleware/error.js.map +1 -1
  156. package/dist/middleware/workspaceAccess.d.ts +23 -19
  157. package/dist/middleware/workspaceAccess.d.ts.map +1 -1
  158. package/dist/middleware/workspaceAccess.js +31 -26
  159. package/dist/middleware/workspaceAccess.js.map +1 -1
  160. package/dist/policy/CapabilityCheck.d.ts +5 -5
  161. package/dist/policy/PermissionRegistry.d.ts +11 -9
  162. package/dist/policy/PermissionRegistry.d.ts.map +1 -1
  163. package/dist/policy/PermissionRegistry.js +10 -8
  164. package/dist/policy/PermissionRegistry.js.map +1 -1
  165. package/dist/policy/ViewerContext.d.ts +13 -11
  166. package/dist/policy/ViewerContext.d.ts.map +1 -1
  167. package/dist/policy/checks.d.ts +9 -9
  168. package/dist/policy/checks.d.ts.map +1 -1
  169. package/dist/policy/checks.js +14 -11
  170. package/dist/policy/checks.js.map +1 -1
  171. package/dist/policy/defaultRegistry.d.ts +3 -4
  172. package/dist/policy/defaultRegistry.d.ts.map +1 -1
  173. package/dist/policy/defaultRegistry.js +3 -4
  174. package/dist/policy/defaultRegistry.js.map +1 -1
  175. package/dist/policy/index.d.ts +2 -2
  176. package/dist/policy/index.d.ts.map +1 -1
  177. package/dist/policy/index.js +1 -1
  178. package/dist/policy/index.js.map +1 -1
  179. package/dist/policy/resolveViewer.d.ts +9 -9
  180. package/dist/policy/resolveViewer.js +9 -9
  181. package/dist/routes/_shared.d.ts +93 -153
  182. package/dist/routes/_shared.d.ts.map +1 -1
  183. package/dist/routes/_shared.js +9 -5
  184. package/dist/routes/_shared.js.map +1 -1
  185. package/dist/routes/admin.d.ts +1 -1
  186. package/dist/routes/admin.d.ts.map +1 -1
  187. package/dist/routes/admin.js +13 -12
  188. package/dist/routes/admin.js.map +1 -1
  189. package/dist/routes/auth.d.ts +12 -10
  190. package/dist/routes/auth.d.ts.map +1 -1
  191. package/dist/routes/auth.js +32 -34
  192. package/dist/routes/auth.js.map +1 -1
  193. package/dist/routes/clarifications.d.ts +8 -0
  194. package/dist/routes/clarifications.d.ts.map +1 -0
  195. package/dist/routes/clarifications.js +243 -0
  196. package/dist/routes/clarifications.js.map +1 -0
  197. package/dist/routes/edges.d.ts.map +1 -1
  198. package/dist/routes/edges.js +2 -6
  199. package/dist/routes/edges.js.map +1 -1
  200. package/dist/routes/history.d.ts.map +1 -1
  201. package/dist/routes/history.js +12 -10
  202. package/dist/routes/history.js.map +1 -1
  203. package/dist/routes/nodes.d.ts.map +1 -1
  204. package/dist/routes/nodes.js +4 -8
  205. package/dist/routes/nodes.js.map +1 -1
  206. package/dist/routes/oauth.d.ts +6 -7
  207. package/dist/routes/oauth.d.ts.map +1 -1
  208. package/dist/routes/oauth.js +6 -7
  209. package/dist/routes/oauth.js.map +1 -1
  210. package/dist/routes/proposals.d.ts +2 -2
  211. package/dist/routes/proposals.d.ts.map +1 -1
  212. package/dist/routes/proposals.js +30 -28
  213. package/dist/routes/proposals.js.map +1 -1
  214. package/dist/routes/reactorCycles.d.ts +7 -0
  215. package/dist/routes/reactorCycles.d.ts.map +1 -0
  216. package/dist/routes/reactorCycles.js +60 -0
  217. package/dist/routes/reactorCycles.js.map +1 -0
  218. package/dist/routes/runs.d.ts.map +1 -1
  219. package/dist/routes/runs.js +22 -19
  220. package/dist/routes/runs.js.map +1 -1
  221. package/dist/routes/skillInputOptions.d.ts +2 -2
  222. package/dist/routes/skillInputOptions.d.ts.map +1 -1
  223. package/dist/routes/skillInputOptions.js +43 -45
  224. package/dist/routes/skillInputOptions.js.map +1 -1
  225. package/dist/routes/skills.d.ts +19 -1
  226. package/dist/routes/skills.d.ts.map +1 -1
  227. package/dist/routes/skills.js +139 -7
  228. package/dist/routes/skills.js.map +1 -1
  229. package/dist/routes/sourceLoaders.d.ts.map +1 -1
  230. package/dist/routes/sourceLoaders.js +1 -0
  231. package/dist/routes/sourceLoaders.js.map +1 -1
  232. package/dist/routes/sourceUnitObservations.d.ts +20 -0
  233. package/dist/routes/sourceUnitObservations.d.ts.map +1 -0
  234. package/dist/routes/sourceUnitObservations.js +80 -0
  235. package/dist/routes/sourceUnitObservations.js.map +1 -0
  236. package/dist/routes/sourceWebhooks.d.ts +26 -0
  237. package/dist/routes/sourceWebhooks.d.ts.map +1 -0
  238. package/dist/routes/sourceWebhooks.js +301 -0
  239. package/dist/routes/sourceWebhooks.js.map +1 -0
  240. package/dist/routes/users.d.ts +0 -2
  241. package/dist/routes/users.d.ts.map +1 -1
  242. package/dist/routes/users.js +15 -33
  243. package/dist/routes/users.js.map +1 -1
  244. package/dist/routes/workspaceEvents.d.ts +5 -4
  245. package/dist/routes/workspaceEvents.d.ts.map +1 -1
  246. package/dist/routes/workspaceEvents.js +7 -6
  247. package/dist/routes/workspaceEvents.js.map +1 -1
  248. package/dist/routes/workspaceMembers.d.ts +1 -1
  249. package/dist/routes/workspaceMembers.d.ts.map +1 -1
  250. package/dist/routes/workspaceMembers.js +2 -2
  251. package/dist/routes/workspaceMembers.js.map +1 -1
  252. package/dist/routes/workspaces.d.ts +21 -10
  253. package/dist/routes/workspaces.d.ts.map +1 -1
  254. package/dist/routes/workspaces.js +97 -69
  255. package/dist/routes/workspaces.js.map +1 -1
  256. package/dist/server.js +6 -70
  257. package/dist/server.js.map +1 -1
  258. package/dist/startServer.d.ts +17 -0
  259. package/dist/startServer.d.ts.map +1 -0
  260. package/dist/startServer.js +81 -0
  261. package/dist/startServer.js.map +1 -0
  262. package/dist/startup.d.ts +28 -0
  263. package/dist/startup.d.ts.map +1 -0
  264. package/dist/startup.js +94 -0
  265. package/dist/startup.js.map +1 -0
  266. package/package.json +9 -9
  267. package/dist/composeFs.d.ts +0 -55
  268. package/dist/composeFs.d.ts.map +0 -1
  269. package/dist/composeFs.js.map +0 -1
  270. package/dist/composition.d.ts +0 -133
  271. package/dist/composition.d.ts.map +0 -1
  272. package/dist/composition.js +0 -113
  273. package/dist/composition.js.map +0 -1
  274. package/dist/infrastructure/agent/SubprocessSkillRunner.d.ts +0 -75
  275. package/dist/infrastructure/agent/SubprocessSkillRunner.d.ts.map +0 -1
  276. package/dist/infrastructure/agent/SubprocessSkillRunner.js.map +0 -1
  277. package/dist/infrastructure/agent/asyncQueue.d.ts +0 -22
  278. package/dist/infrastructure/agent/asyncQueue.d.ts.map +0 -1
  279. package/dist/infrastructure/agent/mcpConfig.d.ts +0 -38
  280. package/dist/infrastructure/agent/mcpConfig.d.ts.map +0 -1
  281. package/dist/infrastructure/agent/mcpConfig.js +0 -55
  282. package/dist/infrastructure/agent/mcpConfig.js.map +0 -1
  283. package/dist/infrastructure/agent/streamJsonParser.d.ts +0 -20
  284. package/dist/infrastructure/agent/streamJsonParser.d.ts.map +0 -1
  285. package/dist/infrastructure/agent/streamJsonParser.js.map +0 -1
  286. package/dist/infrastructure/agent/subprocessEventStream.d.ts +0 -26
  287. package/dist/infrastructure/agent/subprocessEventStream.d.ts.map +0 -1
  288. package/dist/infrastructure/agent/subprocessEventStream.js +0 -112
  289. package/dist/infrastructure/agent/subprocessEventStream.js.map +0 -1
  290. package/dist/infrastructure/auth/ensureApprovedEmails.d.ts +0 -16
  291. package/dist/infrastructure/auth/ensureApprovedEmails.d.ts.map +0 -1
  292. package/dist/infrastructure/auth/ensureApprovedEmails.js +0 -20
  293. package/dist/infrastructure/auth/ensureApprovedEmails.js.map +0 -1
  294. package/dist/infrastructure/env.d.ts +0 -11
  295. package/dist/infrastructure/env.d.ts.map +0 -1
  296. package/dist/infrastructure/env.js.map +0 -1
  297. package/dist/infrastructure/fs/FsBatchPlanRepository.d.ts +0 -300
  298. package/dist/infrastructure/fs/FsBatchPlanRepository.d.ts.map +0 -1
  299. package/dist/infrastructure/fs/FsBatchPlanRepository.js.map +0 -1
  300. package/dist/infrastructure/fs/FsClarifyTicketRepository.d.ts +0 -13
  301. package/dist/infrastructure/fs/FsClarifyTicketRepository.d.ts.map +0 -1
  302. package/dist/infrastructure/fs/FsClarifyTicketRepository.js.map +0 -1
  303. package/dist/infrastructure/fs/FsDecisionRepository.d.ts +0 -13
  304. package/dist/infrastructure/fs/FsDecisionRepository.d.ts.map +0 -1
  305. package/dist/infrastructure/fs/FsDecisionRepository.js +0 -56
  306. package/dist/infrastructure/fs/FsDecisionRepository.js.map +0 -1
  307. package/dist/infrastructure/fs/FsGraphSerializer.d.ts +0 -629
  308. package/dist/infrastructure/fs/FsGraphSerializer.d.ts.map +0 -1
  309. package/dist/infrastructure/fs/FsGraphSerializer.js.map +0 -1
  310. package/dist/infrastructure/fs/FsProposalRepository.d.ts.map +0 -1
  311. package/dist/infrastructure/fs/FsProposalRepository.js.map +0 -1
  312. package/dist/infrastructure/fs/FsRunRepository.d.ts.map +0 -1
  313. package/dist/infrastructure/fs/FsRunRepository.js.map +0 -1
  314. package/dist/infrastructure/fs/FsSkillRegistry.d.ts.map +0 -1
  315. package/dist/infrastructure/fs/FsSkillRegistry.js.map +0 -1
  316. package/dist/infrastructure/fs/FsSourceUnitDigest.d.ts +0 -19
  317. package/dist/infrastructure/fs/FsSourceUnitDigest.d.ts.map +0 -1
  318. package/dist/infrastructure/fs/FsSourceUnitDigest.js.map +0 -1
  319. package/dist/infrastructure/fs/FsSourceUnitStateRepository.d.ts +0 -30
  320. package/dist/infrastructure/fs/FsSourceUnitStateRepository.d.ts.map +0 -1
  321. package/dist/infrastructure/fs/FsSourceUnitStateRepository.js.map +0 -1
  322. package/dist/infrastructure/fs/FsStatusedJsonRepository.d.ts +0 -35
  323. package/dist/infrastructure/fs/FsStatusedJsonRepository.d.ts.map +0 -1
  324. package/dist/infrastructure/fs/FsStatusedJsonRepository.js.map +0 -1
  325. package/dist/infrastructure/fs/FsWorkspaceRepository.d.ts.map +0 -1
  326. package/dist/infrastructure/fs/FsWorkspaceRepository.js.map +0 -1
  327. package/dist/infrastructure/fs/WorkspaceDiscovery.d.ts +0 -15
  328. package/dist/infrastructure/fs/WorkspaceDiscovery.d.ts.map +0 -1
  329. package/dist/infrastructure/fs/WorkspaceDiscovery.js.map +0 -1
  330. package/dist/infrastructure/fs/WorkspaceRegistryFile.d.ts.map +0 -1
  331. package/dist/infrastructure/fs/WorkspaceRegistryFile.js.map +0 -1
  332. package/dist/infrastructure/fs/frontmatter.d.ts +0 -13
  333. package/dist/infrastructure/fs/frontmatter.d.ts.map +0 -1
  334. package/dist/infrastructure/fs/frontmatter.js.map +0 -1
  335. package/dist/infrastructure/fs/intentScan.d.ts.map +0 -1
  336. package/dist/infrastructure/fs/intentScan.js.map +0 -1
  337. package/dist/infrastructure/fs/jsonFileStore.d.ts.map +0 -1
  338. package/dist/infrastructure/fs/jsonFileStore.js.map +0 -1
  339. package/dist/infrastructure/fs/paths.d.ts.map +0 -1
  340. package/dist/infrastructure/fs/paths.js.map +0 -1
  341. package/dist/infrastructure/fs/productManifestWriter.d.ts +0 -22
  342. package/dist/infrastructure/fs/productManifestWriter.d.ts.map +0 -1
  343. package/dist/infrastructure/fs/productManifestWriter.js.map +0 -1
  344. package/dist/infrastructure/git/GitWorkspaceHistory.d.ts.map +0 -1
  345. package/dist/infrastructure/git/GitWorkspaceHistory.js.map +0 -1
  346. package/dist/infrastructure/git/commitMessage.d.ts.map +0 -1
  347. package/dist/infrastructure/git/commitMessage.js +0 -71
  348. package/dist/infrastructure/git/commitMessage.js.map +0 -1
  349. package/dist/infrastructure/orphanReaper.d.ts +0 -18
  350. package/dist/infrastructure/orphanReaper.d.ts.map +0 -1
  351. package/dist/infrastructure/orphanReaper.js.map +0 -1
  352. package/dist/infrastructure/users/ensureLocalUser.d.ts +0 -15
  353. package/dist/infrastructure/users/ensureLocalUser.d.ts.map +0 -1
  354. package/dist/infrastructure/users/ensureLocalUser.js +0 -38
  355. package/dist/infrastructure/users/ensureLocalUser.js.map +0 -1
  356. package/dist/middleware/requireAdmin.d.ts +0 -10
  357. package/dist/middleware/requireAdmin.d.ts.map +0 -1
  358. package/dist/middleware/requireAdmin.js +0 -24
  359. package/dist/middleware/requireAdmin.js.map +0 -1
  360. package/dist/middleware/userId.d.ts +0 -16
  361. package/dist/middleware/userId.d.ts.map +0 -1
  362. package/dist/middleware/userId.js +0 -27
  363. package/dist/middleware/userId.js.map +0 -1
  364. package/dist/policy/Capability.d.ts +0 -12
  365. package/dist/policy/Capability.d.ts.map +0 -1
  366. package/dist/policy/Capability.js +0 -31
  367. package/dist/policy/Capability.js.map +0 -1
  368. package/dist/routes/clarify.d.ts +0 -9
  369. package/dist/routes/clarify.d.ts.map +0 -1
  370. package/dist/routes/clarify.js +0 -274
  371. package/dist/routes/clarify.js.map +0 -1
  372. package/dist/routes/decisions.d.ts +0 -7
  373. package/dist/routes/decisions.d.ts.map +0 -1
  374. package/dist/routes/decisions.js +0 -68
  375. package/dist/routes/decisions.js.map +0 -1
  376. package/dist/routes/sourceUnitStates.d.ts +0 -7
  377. package/dist/routes/sourceUnitStates.d.ts.map +0 -1
  378. package/dist/routes/sourceUnitStates.js +0 -45
  379. package/dist/routes/sourceUnitStates.js.map +0 -1
  380. /package/dist/infrastructure/{fs → _shared}/jsonFileStore.d.ts +0 -0
  381. /package/dist/infrastructure/{fs → _shared}/jsonFileStore.js +0 -0
  382. /package/dist/infrastructure/{git → history}/GitWorkspaceHistory.d.ts +0 -0
  383. /package/dist/infrastructure/{git → history}/commitMessage.d.ts +0 -0
  384. /package/dist/infrastructure/{fs → hitl}/FsProposalRepository.d.ts +0 -0
  385. /package/dist/infrastructure/{fs → workspace}/FsWorkspaceRepository.d.ts +0 -0
@@ -2,15 +2,18 @@ import { readdir, stat } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
3
  import { createLogger } from '@braidhq/core';
4
4
  /**
5
- * Walk `<workspacesRoot>/*` and register every subdirectory that owns a
6
- * `PRODUCT.md` with the WorkspaceService. Idempotent: already-registered
7
- * workspaces are a no-op against the FS registry. Run on server boot so
8
- * CLI-created / hand-copied workspaces surface in Studio without an
9
- * explicit `register` step.
5
+ * Walk `<workspacesRoot>/*` and register with the WorkspaceService,
6
+ * every subdirectory that owns a `PRODUCT.md`.
7
+ * It is idempotent,
8
+ * an already-registered workspace is a no-op against the FS registry.
9
+ * We run it on server boot,
10
+ * so CLI-created or hand-copied workspaces surface in Studio,
11
+ * without any explicit `register` step.
10
12
  *
11
- * Errors per-entry (corrupt PRODUCT.md, permissions) are logged and
12
- * skipped; the server must still come up so the user can fix the
13
- * outlier and re-boot.
13
+ * A per-entry error, a corrupt PRODUCT.md or bad permissions,
14
+ * is logged and skipped.
15
+ * The server must still come up,
16
+ * so the user can fix the outlier and re-boot.
14
17
  */
15
18
  export async function discoverCanonicalWorkspaces(workspacesRoot, workspaceService) {
16
19
  const log = createLogger('server').child({ mod: 'workspace-discovery' });
@@ -19,9 +22,10 @@ export async function discoverCanonicalWorkspaces(workspacesRoot, workspaceServi
19
22
  entries = await readdir(workspacesRoot);
20
23
  }
21
24
  catch (err) {
22
- // ENOENT on first boot is expected; the dir is created lazily by
23
- // the first scaffold. Other errors (permissions, etc.) we log and
24
- // continue. Server must still come up.
25
+ // ENOENT on first boot is expected,
26
+ // the dir is created lazily by the first scaffold.
27
+ // Any other error, such as bad permissions, we log and continue.
28
+ // The server still boots.
25
29
  if (err.code !== 'ENOENT')
26
30
  log.warn({ err, workspacesRoot }, 'failed to read workspaces root');
27
31
  return;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WorkspaceDiscovery.js","sourceRoot":"","sources":["../../../src/infrastructure/workspace/WorkspaceDiscovery.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA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QACxC,CAAC;QACD,OAAO,GAAG,EAAE,CAAC;YACX,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,mCAAmC,CAAC,CAAA;QAClE,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -1,9 +1,9 @@
1
1
  import type { AbsolutePath, UserId, WorkspaceMember, WorkspaceRole } from '@braidhq/schema';
2
2
  /**
3
3
  * Persists the list of registered workspace rootPaths to a JSON file.
4
- * Default location is `${BRAID_HOME}/workspaces.json` (set by the caller).
5
- * Acts as the source of truth across server restarts — the in-memory
6
- * `FsWorkspaceRepository` cache is rebuilt from this file on cold start.
4
+ * Default location is `${BRAID_HOME}/workspaces.json`, set by the caller.
5
+ * Acts as the source of truth across server restarts,
6
+ * the in-memory `FsWorkspaceRepository` cache rebuilds from it on cold start.
7
7
  */
8
8
  export declare class WorkspaceRegistryFile {
9
9
  private readonly filePath;
@@ -13,8 +13,8 @@ export declare class WorkspaceRegistryFile {
13
13
  remove(rootPath: AbsolutePath): Promise<void>;
14
14
  listMembers(rootPath: AbsolutePath): Promise<WorkspaceMember[]>;
15
15
  /**
16
- * All entries with their members in one read. Lets admin views invert
17
- * to user workspaces without N+1 reads of workspaces.json.
16
+ * All entries with their members in one read. An admin view can then,
17
+ * invert to a user-to-workspaces map, with no N+1 reads of the file.
18
18
  */
19
19
  listAllWithMembers(): Promise<ReadonlyArray<{
20
20
  rootPath: AbsolutePath;
@@ -28,10 +28,11 @@ export declare class WorkspaceRegistryFile {
28
28
  }): Promise<WorkspaceMember>;
29
29
  removeMember(rootPath: AbsolutePath, userId: UserId): Promise<void>;
30
30
  /**
31
- * Demote the current owner to maintainer + promote `newOwnerId` to
32
- * owner in one atomic write. Throws if `newOwnerId` isn't a maintainer
33
- * of this workspace (we don't auto-add the caller should add them
34
- * first if needed).
31
+ * In one atomic write, demote the current owner to maintainer,
32
+ * and promote `newOwnerId` to owner.
33
+ * If the target is not yet a maintainer here, this throws.
34
+ * We never auto-add the target,
35
+ * so the caller must add them first when that is needed.
35
36
  */
36
37
  transferOwnership(rootPath: AbsolutePath, newOwnerId: UserId): Promise<void>;
37
38
  private requireEntry;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WorkspaceRegistryFile.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/workspace/WorkspaceRegistryFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AA2B3F;;;;;GAKG;AACH,qBAAa,qBAAqB;IACpB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,MAAM;IAEvC,IAAI,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IAK/B,GAAG,CAAC,QAAQ,EAAE,YAAY,EAAE,YAAY,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAW1E,MAAM,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ7C,WAAW,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAKrE;;;OAGG;IACG,kBAAkB,IAAI,OAAO,CAAC,aAAa,CAAC;QAAE,QAAQ,EAAE,YAAY,CAAC;QAAC,OAAO,EAAE,SAAS,eAAe,EAAE,CAAA;KAAE,CAAC,CAAC;IAK7G,SAAS,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;IAKvF,SAAS,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAazE,YAAY,CAChB,QAAQ,EAAE,YAAY,EACtB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE;QAAE,IAAI,CAAC,EAAE,aAAa,CAAC;QAAC,cAAc,CAAC,EAAE,eAAe,CAAC,gBAAgB,CAAC,CAAA;KAAE,GAClF,OAAO,CAAC,eAAe,CAAC;IAoBrB,YAAY,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAczE;;;;;;OAMG;IACG,iBAAiB,CAAC,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAiBpE,YAAY;YAQZ,IAAI;YAgBJ,KAAK;CAIpB"}
@@ -3,14 +3,11 @@ import { dirname } from 'node:path';
3
3
  import { NotFoundError, ValidationError } from '@braidhq/core';
4
4
  import { AbsolutePath as AbsolutePathSchema, WorkspaceMember as WorkspaceMemberSchema, } from '@braidhq/schema';
5
5
  import { z } from 'zod';
6
- /**
7
- * The registry stores a per-workspace `members[]` list alongside
8
- * `rootPath`. Old shapes (pre-Phase-C, with only `rootPath`) are
9
- * accepted by `.default([])` and lazily upgraded the next time we
10
- * write `ensureLocalOwner` in `composeFs` seeds `local-user` as
11
- * owner so the single-tenant install keeps working without manual
12
- * migration.
13
- */
6
+ // The registry stores a per-workspace `members[]` list alongside `rootPath`.
7
+ // Old shapes carrying only `rootPath` are accepted by `.default([])`,
8
+ // then lazily upgraded on the next write.
9
+ // `ensureWorkspaceOwners` in `composeFsApp` seeds the default owner,
10
+ // so the single-tenant install keeps working without any manual migration.
14
11
  const RegistryEntry = z.object({
15
12
  rootPath: AbsolutePathSchema,
16
13
  members: z.array(WorkspaceMemberSchema).default([]),
@@ -20,9 +17,9 @@ const RegistryContent = z.object({
20
17
  });
21
18
  /**
22
19
  * Persists the list of registered workspace rootPaths to a JSON file.
23
- * Default location is `${BRAID_HOME}/workspaces.json` (set by the caller).
24
- * Acts as the source of truth across server restarts — the in-memory
25
- * `FsWorkspaceRepository` cache is rebuilt from this file on cold start.
20
+ * Default location is `${BRAID_HOME}/workspaces.json`, set by the caller.
21
+ * Acts as the source of truth across server restarts,
22
+ * the in-memory `FsWorkspaceRepository` cache rebuilds from it on cold start.
26
23
  */
27
24
  export class WorkspaceRegistryFile {
28
25
  filePath;
@@ -55,8 +52,8 @@ export class WorkspaceRegistryFile {
55
52
  return entry.members;
56
53
  }
57
54
  /**
58
- * All entries with their members in one read. Lets admin views invert
59
- * to user workspaces without N+1 reads of workspaces.json.
55
+ * All entries with their members in one read. An admin view can then,
56
+ * invert to a user-to-workspaces map, with no N+1 reads of the file.
60
57
  */
61
58
  async listAllWithMembers() {
62
59
  const content = await this.read();
@@ -111,10 +108,11 @@ export class WorkspaceRegistryFile {
111
108
  await this.write(content);
112
109
  }
113
110
  /**
114
- * Demote the current owner to maintainer + promote `newOwnerId` to
115
- * owner in one atomic write. Throws if `newOwnerId` isn't a maintainer
116
- * of this workspace (we don't auto-add the caller should add them
117
- * first if needed).
111
+ * In one atomic write, demote the current owner to maintainer,
112
+ * and promote `newOwnerId` to owner.
113
+ * If the target is not yet a maintainer here, this throws.
114
+ * We never auto-add the target,
115
+ * so the caller must add them first when that is needed.
118
116
  */
119
117
  async transferOwnership(rootPath, newOwnerId) {
120
118
  const content = await this.read();
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WorkspaceRegistryFile.js","sourceRoot":"","sources":["../../../src/infrastructure/workspace/WorkspaceRegistryFile.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC9D,OAAO,EACL,YAAY,IAAI,kBAAkB,EAClC,eAAe,IAAI,qBAAqB,GACzC,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,6EAA6E;AAC7E,sEAAsE;AACtE,0CAA0C;AAC1C,qEAAqE;AACrE,2EAA2E;AAC3E,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC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,QAAQ,kBAAkB,CAAC,CAAA;QACtE,OAAO,KAAK,CAAA;IACd,CAAC;IAEO,KAAK,CAAC,IAAI;QAChB,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;YAClD,MAAM,MAAM,GAAG,eAAe,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;YACzD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,MAAM,IAAI,eAAe,CAAC,kCAAkC,IAAI,CAAC,QAAQ,MAAM,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YACxG,CAAC;YACD,OAAO,MAAM,CAAC,IAAI,CAAA;QACpB,CAAC;QACD,OAAO,KAAK,EAAE,CAAC;YACb,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;gBACpD,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,CAAA;YAC3B,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,KAAK,CAAC,OAAwB;QAC1C,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QACxD,MAAM,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAClF,CAAC;CACF"}
@@ -0,0 +1,24 @@
1
+ import type { ProductManifest, ProductManifestCreate } from '@braidhq/schema';
2
+ /**
3
+ * Take a user-provided `ProductManifestCreate` and fill in the structure,
4
+ * such as the storage block, so the result is a complete `ProductManifest`,
5
+ * that Zod will accept.
6
+ * Throws if the user's own input is inconsistent.
7
+ */
8
+ export declare function fillManifestDefaults(draft: ProductManifestCreate): ProductManifest;
9
+ /**
10
+ * Render a `ProductManifest` as YAML-frontmatter markdown,
11
+ * then write it to `<workspaceRoot>/PRODUCT.md`.
12
+ * A missing parent directory is created first,
13
+ * and an existing PRODUCT.md is overwritten.
14
+ */
15
+ export declare function writeProductManifest(workspaceRoot: string, manifest: ProductManifest, bodyTitle?: string): Promise<string>;
16
+ /**
17
+ * Replace the YAML frontmatter of an existing PRODUCT.md,
18
+ * preserving the markdown body underneath.
19
+ * Workspace mutation endpoints call this,
20
+ * so user prose below the frontmatter survives an update.
21
+ * The file must exist, otherwise this throws.
22
+ */
23
+ export declare function updateProductManifest(workspaceRoot: string, manifest: ProductManifest): Promise<string>;
24
+ //# sourceMappingURL=productManifestWriter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"productManifestWriter.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/workspace/productManifestWriter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,qBAAqB,EAGtB,MAAM,iBAAiB,CAAA;AAcxB;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,qBAAqB,GAAG,eAAe,CAWlF;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAShI;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAQ7G"}
@@ -2,29 +2,17 @@ import { mkdir, readFile, writeFile } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
3
  import { OntologyId, ProductManifest as ProductManifestSchema } from '@braidhq/schema';
4
4
  import { stringify as stringifyYaml } from 'yaml';
5
- import { parseMarkdownFrontmatter } from './frontmatter.js';
5
+ import { parseMarkdownFrontmatter } from '../_shared/frontmatter.js';
6
6
  const FRONTMATTER_DELIMITER = '---';
7
- const DEFAULT_AGENT_BINDING = {
8
- id: 'claude-default',
9
- kind: 'claude-code',
10
- model: 'opus',
11
- effort: 'high',
12
- extraArgs: [],
13
- env: {},
14
- };
15
- const DEFAULT_AGENTS = {
16
- default: 'claude-default',
17
- tasks: {},
18
- };
19
7
  const DEFAULT_STORAGE = {
20
8
  kind: 'kuzu',
21
9
  config: {},
22
10
  };
23
11
  /**
24
- * Take a user-provided `ProductManifestDraft` and fill in the structural
25
- * blocks (agent / storage) so the result is a valid, complete
26
- * `ProductManifest` Zod will accept. Throws if the user's input itself is
27
- * inconsistent.
12
+ * Take a user-provided `ProductManifestCreate` and fill in the structure,
13
+ * such as the storage block, so the result is a complete `ProductManifest`,
14
+ * that Zod will accept.
15
+ * Throws if the user's own input is inconsistent.
28
16
  */
29
17
  export function fillManifestDefaults(draft) {
30
18
  const manifest = {
@@ -34,16 +22,15 @@ export function fillManifestDefaults(draft) {
34
22
  ontologyId: draft.ontologyId ?? OntologyId.parse('ddd'),
35
23
  sources: draft.sources,
36
24
  mcpServers: draft.mcpServers,
37
- agents: draft.agents ?? DEFAULT_AGENTS,
38
- agentBindings: draft.agentBindings ?? [DEFAULT_AGENT_BINDING],
39
25
  storage: draft.storage ?? DEFAULT_STORAGE,
40
26
  };
41
27
  return ProductManifestSchema.parse(manifest);
42
28
  }
43
29
  /**
44
- * Render a `ProductManifest` as YAML-frontmatter markdown and write it
45
- * to `<workspaceRoot>/PRODUCT.md`. The parent directory is created if
46
- * missing; an existing PRODUCT.md is overwritten.
30
+ * Render a `ProductManifest` as YAML-frontmatter markdown,
31
+ * then write it to `<workspaceRoot>/PRODUCT.md`.
32
+ * A missing parent directory is created first,
33
+ * and an existing PRODUCT.md is overwritten.
47
34
  */
48
35
  export async function writeProductManifest(workspaceRoot, manifest, bodyTitle) {
49
36
  await mkdir(workspaceRoot, { recursive: true });
@@ -56,10 +43,11 @@ export async function writeProductManifest(workspaceRoot, manifest, bodyTitle) {
56
43
  return path;
57
44
  }
58
45
  /**
59
- * Replace the YAML frontmatter of an existing PRODUCT.md while preserving the
60
- * markdown body underneath. Used by workspace mutation endpoints so user-written
61
- * prose (e.g. project notes added below the frontmatter) survives a manifest
62
- * update. The file must exist; throws otherwise.
46
+ * Replace the YAML frontmatter of an existing PRODUCT.md,
47
+ * preserving the markdown body underneath.
48
+ * Workspace mutation endpoints call this,
49
+ * so user prose below the frontmatter survives an update.
50
+ * The file must exist, otherwise this throws.
63
51
  */
64
52
  export async function updateProductManifest(workspaceRoot, manifest) {
65
53
  const path = join(workspaceRoot, 'PRODUCT.md');
@@ -0,0 +1 @@
1
+ {"version":3,"file":"productManifestWriter.js","sourceRoot":"","sources":["../../../src/infrastructure/workspace/productManifestWriter.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,eAAe,IAAI,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AACtF,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,MAAM,CAAA;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAA;AAEpE,MAAM,qBAAqB,GAAG,KAAK,CAAA;AAEnC,MAAM,eAAe,GAAsB;IACzC,IAAI,EAAE,MAAqB;IAC3B,MAAM,EAAE,EAAE;CACX,CAAA;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAA4B;IAC/D,MAAM,QAAQ,GAAG;QACf,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,OAAO;QACjC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAChE,UAA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,IAAI,GAAG,aAAa,CAAC,QAAQ,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAA;IACzE,MAAM,OAAO,GAAG,GAAG,qBAAqB,KAAK,IAAI,KAAK,qBAAqB,KAAK,IAAI,EAAE,CAAA;IACtF,MAAM,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACvC,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -1,29 +1,39 @@
1
- import type { MiddlewareHandler } from 'hono';
1
+ import type { UserId as UserIdType } from '@braidhq/schema';
2
+ import type { Context, MiddlewareHandler } from 'hono';
2
3
  import type { SessionStore } from '../infrastructure/auth/SessionStore.js';
4
+ declare module 'hono' {
5
+ interface ContextVariableMap {
6
+ userId: UserIdType;
7
+ }
8
+ }
3
9
  export interface AuthMiddlewareOptions {
4
- readonly sessionStore: SessionStore;
5
- /**
6
- * When true, skip the Bearer check and let `userIdMiddleware`'s
7
- * fallback (local-user via env / header) take over. The Tauri
8
- * embedded sidecar sets this so the local install keeps working
9
- * without an OAuth round trip; a remote deployment leaves it false
10
- * so anonymous traffic is rejected.
11
- *
12
- * Resolution: explicit option > `BRAID_LOCAL_TRUST=true` env var.
13
- * Defaults to `false` when neither is set — composeFs flips this
14
- * to `true` for local development.
15
- */
16
- readonly localTrust?: boolean;
10
+ readonly sessionStore?: SessionStore;
11
+ readonly requireAuth: boolean;
12
+ readonly defaultPrincipal: UserIdType | null;
17
13
  }
18
14
  /**
19
- * Pull a Bearer token off the request, or return `undefined` if the
20
- * header is missing / malformed. Route handlers use this to forward the
21
- * caller's identity to spawned skill subprocesses without re-parsing.
15
+ * Pull a Bearer token off the request,
16
+ * returning `undefined` when the header is missing or malformed.
17
+ * Route handlers use this to forward the caller's identity,
18
+ * reaching spawned skill subprocesses without reparsing.
22
19
  */
23
20
  export declare function extractBearerToken(context: {
24
21
  req: {
25
22
  header: (name: string) => string | undefined;
26
23
  };
27
24
  }): string | undefined;
25
+ /**
26
+ * Establish the caller's identity, and gate when auth is enforced.
27
+ * The single place a request's `userId` is resolved.
28
+ *
29
+ * Under local trust, identity comes from `X-Braid-User`, else the default
30
+ * principal, on every path so public routes like `/auth/whoami` see the caller.
31
+ * Nothing is rejected.
32
+ *
33
+ * When auth is enforced, identity comes only from a valid Bearer session, and a
34
+ * missing or invalid token on a non-public route is a 401. The header is never
35
+ * read here, so it cannot impersonate an authenticated caller.
36
+ */
28
37
  export declare function authMiddleware(options: AuthMiddlewareOptions): MiddlewareHandler;
38
+ export declare function getUserId(context: Context): UserIdType;
29
39
  //# sourceMappingURL=auth.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/middleware/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAmB1E,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAA;IACnC;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAC9B;AAUD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE;IAAE,GAAG,EAAE;QAAE,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAA;KAAE,CAAA;CAAE,GAAG,MAAM,GAAG,SAAS,CAMzH;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,iBAAiB,CAoDhF"}
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/middleware/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAI1E,OAAO,QAAQ,MAAM,CAAC;IACpB,UAAU,kBAAkB;QAC1B,MAAM,EAAE,UAAU,CAAA;KACnB;CACF;AAoBD,MAAM,WAAW,qBAAqB;IAEpC,QAAQ,CAAC,YAAY,CAAC,EAAE,YAAY,CAAA;IAEpC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAA;IAE7B,QAAQ,CAAC,gBAAgB,EAAE,UAAU,GAAG,IAAI,CAAA;CAC7C;AAWD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE;IAAE,GAAG,EAAE;QAAE,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAA;KAAE,CAAA;CAAE,GAAG,MAAM,GAAG,SAAS,CAMzH;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,iBAAiB,CAkChF;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,CAEtD"}
@@ -1,30 +1,34 @@
1
- import process from 'node:process';
2
- import { parseBoolEnv } from '../infrastructure/env.js';
3
- /**
4
- * Routes the auth middleware never gates. Anonymous access is required
5
- * here, otherwise the login flow itself becomes impossible to bootstrap.
6
- *
7
- * Path prefixes (not exact match) so `/auth/google/start`,
8
- * `/auth/google/callback`, `/auth/whoami` all flow through without a
9
- * token. `/health` stays open so platform probes don't need a token.
10
- * `/openapi.json` matches the broad industry convention that OpenAPI
11
- * descriptions are publicly readable (Swagger UI, codegen, MCP gateways
12
- * default to fetching them without auth). It only documents shape, not
13
- * data, so leaking it to anonymous callers is safe.
14
- */
15
- const PUBLIC_EXACT = new Set(['/openapi.json']);
16
- const PUBLIC_PREFIXES = ['/auth/', '/health'];
17
- // EventSource (browser SSE) cannot send custom Authorization headers, so
18
- // for live-update endpoints we additionally accept a `?token=...` query
19
- // parameter and treat it identically to a Bearer token. Limited to paths
20
- // ending in `/events` so this lenient path doesn't apply to mutating routes.
1
+ import { UnauthorizedError } from '@braidhq/core';
2
+ import { UserId } from '@braidhq/schema';
3
+ // Routes the auth middleware never gates,
4
+ // since bootstrapping the login flow needs anonymous access.
5
+ // `/openapi.json` follows the convention that OpenAPI reads publicly,
6
+ // honored by Swagger UI, codegen, and MCP gateways.
7
+ // It documents shape and not data, so exposing it to anonymous callers is safe.
8
+ const PUBLIC_EXACT_PATHS = new Set(['/openapi.json']);
9
+ // Each `/webhooks/<provider>/` prefix is anonymous,
10
+ // because the provider authenticates via a per-source HMAC,
11
+ // checked inside the handler rather than via a Bearer token.
12
+ // Listing providers one by one, rather than the broad `/webhooks/`,
13
+ // keeps a future admin or metrics webhook from inheriting the bypass.
14
+ const PUBLIC_PATH_PREFIXES = ['/auth/', '/health', '/webhooks/github/'];
15
+ // Header naming the caller under local trust, a dev and multi-persona convenience.
16
+ // Read only when auth is not enforced, never on an authenticated deployment,
17
+ // so it can never impersonate a caller behind real auth.
18
+ const USER_HEADER = 'X-Braid-User';
19
+ // EventSource (browser SSE) cannot send custom Authorization headers,
20
+ // so live-update endpoints also accept a `token` query parameter,
21
+ // treated as a Bearer token.
22
+ // Limited to paths ending in `/events`,
23
+ // so the lenient path never applies to mutating routes.
21
24
  function isSseEventsPath(path) {
22
25
  return path.endsWith('/events');
23
26
  }
24
27
  /**
25
- * Pull a Bearer token off the request, or return `undefined` if the
26
- * header is missing / malformed. Route handlers use this to forward the
27
- * caller's identity to spawned skill subprocesses without re-parsing.
28
+ * Pull a Bearer token off the request,
29
+ * returning `undefined` when the header is missing or malformed.
30
+ * Route handlers use this to forward the caller's identity,
31
+ * reaching spawned skill subprocesses without reparsing.
28
32
  */
29
33
  export function extractBearerToken(context) {
30
34
  const header = context.req.header('Authorization');
@@ -33,49 +37,51 @@ export function extractBearerToken(context) {
33
37
  const token = header.slice('Bearer '.length).trim();
34
38
  return token.length > 0 ? token : undefined;
35
39
  }
40
+ /**
41
+ * Establish the caller's identity, and gate when auth is enforced.
42
+ * The single place a request's `userId` is resolved.
43
+ *
44
+ * Under local trust, identity comes from `X-Braid-User`, else the default
45
+ * principal, on every path so public routes like `/auth/whoami` see the caller.
46
+ * Nothing is rejected.
47
+ *
48
+ * When auth is enforced, identity comes only from a valid Bearer session, and a
49
+ * missing or invalid token on a non-public route is a 401. The header is never
50
+ * read here, so it cannot impersonate an authenticated caller.
51
+ */
36
52
  export function authMiddleware(options) {
37
- const localTrust = options.localTrust ?? parseBoolEnv(process.env.BRAID_LOCAL_TRUST, false);
38
53
  return async (context, next) => {
39
54
  const path = context.req.path;
40
- if (PUBLIC_EXACT.has(path) || PUBLIC_PREFIXES.some(prefix => path.startsWith(prefix))) {
55
+ if (!options.requireAuth) {
56
+ const header = context.req.header(USER_HEADER);
57
+ const fromHeader = header && header.length > 0 ? UserId.parse(header) : null;
58
+ const resolved = fromHeader ?? options.defaultPrincipal;
59
+ if (resolved)
60
+ context.set('userId', resolved);
41
61
  await next();
42
62
  return undefined;
43
63
  }
44
- if (localTrust) {
45
- // The downstream `userIdMiddleware` will stamp `local-user` (or
46
- // honour an explicit `X-Braid-User` header for multi-persona
47
- // dev). The auth layer has no opinion here.
64
+ // Public routes bootstrap the login flow, so pass them through ungated,
65
+ // and without reading the header, they must never carry a caller.
66
+ if (PUBLIC_EXACT_PATHS.has(path) || PUBLIC_PATH_PREFIXES.some(prefix => path.startsWith(prefix))) {
48
67
  await next();
49
68
  return undefined;
50
69
  }
51
- const header = context.req.header('Authorization');
52
- let token = header?.startsWith('Bearer ') ? header.slice('Bearer '.length).trim() : null;
53
- // Fall back to a query-param token for SSE endpoints only.
54
- if (!token && isSseEventsPath(path)) {
55
- const queryToken = context.req.query('token');
56
- if (queryToken)
57
- token = queryToken;
58
- }
59
- if (!token) {
60
- return context.json({
61
- type: 'about:blank',
62
- title: 'Unauthorized',
63
- status: 401,
64
- detail: 'Missing or invalid Authorization header. Sign in to continue.',
65
- }, 401, { 'Content-Type': 'application/problem+json' });
66
- }
70
+ let token = extractBearerToken(context);
71
+ if (!token && isSseEventsPath(path))
72
+ token = context.req.query('token') || undefined;
73
+ if (!token)
74
+ throw new UnauthorizedError('Missing or invalid Authorization header. Sign in to continue.');
75
+ // The composition root always wires sessionStore alongside requireAuth.
67
76
  const session = await options.sessionStore.resolve(token);
68
- if (!session) {
69
- return context.json({
70
- type: 'about:blank',
71
- title: 'Unauthorized',
72
- status: 401,
73
- detail: 'Session expired or revoked. Sign in again.',
74
- }, 401, { 'Content-Type': 'application/problem+json' });
75
- }
77
+ if (!session)
78
+ throw new UnauthorizedError('Session expired or revoked. Sign in again.');
76
79
  context.set('userId', session.userId);
77
80
  await next();
78
81
  return undefined;
79
82
  };
80
83
  }
84
+ export function getUserId(context) {
85
+ return context.get('userId');
86
+ }
81
87
  //# sourceMappingURL=auth.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/middleware/auth.ts"],"names":[],"mappings":"AAEA,OAAO,OAAO,MAAM,cAAc,CAAA;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAEvD;;;;;;;;;;;GAWG;AACH,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,eAAe,CAAC,CAAC,CAAA;AAC/C,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;AAkB7C,yEAAyE;AACzE,wEAAwE;AACxE,yEAAyE;AACzE,6EAA6E;AAC7E,SAAS,eAAe,CAAC,IAAY;IACnC,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;AACjC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAkE;IACnG,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC,CAAA;IAClD,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC;QA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["../../src/middleware/cors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AAQ7C,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAC5C;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,WAAgB,GAAG,iBAAiB,CAkB3E"}
1
+ {"version":3,"file":"cors.d.ts","sourceRoot":"","sources":["../../src/middleware/cors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AAW7C,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAC5C;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,WAAgB,GAAG,iBAAiB,CAkB3E"}
@@ -1,6 +1,9 @@
1
+ // Vite dev (5173) and preview (4173) ports, on both loopback hostnames,
2
+ // which browsers treat as distinct origins.
1
3
  const DEFAULT_DEV_ORIGINS = [
2
- 'http://localhost:5173',
3
4
  'http://localhost:4173',
5
+ 'http://localhost:5173',
6
+ 'http://127.0.0.1:4173',
4
7
  'http://127.0.0.1:5173',
5
8
  ];
6
9
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"cors.js","sourceRoot":"","sources":["../../src/middleware/cors.ts"],"names":[],"mappings":"AAEA,MAAM,mBAAmB,GAAG;IAC1B,uBAAuB;IACvB,uBAAuB;IACvB,uBAAuB;CACxB,CAAA;AAMD;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,UAAuB,EAAE;IACtD,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,cAAc,IAAI,mBAAmB,CAAC,CAAA;IACtE,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QAC7B,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,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,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YAClC,OAAO,CAAC,MAAM,CAAC,6BAA6B,EAAE,MAAM,CAAC,CAAA;YACrD,OAAO,CAAC,MAAM,CAAC,kCAAkC,EAAE,MAAM,CAAC,CAAA;YAC1D,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;QAClC,CAAC;QACD,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YACrC,OAAO,CAAC,MAAM,CAAC,8BAA8B,EAAE,wCAAwC,CAAC,CAAA;YACxF,OAAO,CAAC,MAAM,CAAC,8BAA8B,EAAE,2CAA2C,CAAC,CAAA;YAC3F,OAAO,CAAC,MAAM,CAAC,wBAAwB,EAAE,OAAO,CAAC,CAAA;YACjD,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;QAChC,CAAC;QACD,MAAM,IAAI,EAAE,CAAA;QACZ,OAAO,SAAS,CAAA;IAClB,CAAC,CAAA;AACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/middleware/error.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AA+CxC,eAAO,MAAM,YAAY,EAAE,YAkB1B,CAAA"}
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/middleware/error.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AA4CxC,eAAO,MAAM,YAAY,EAAE,YAkB1B,CAAA"}
@@ -1,20 +1,22 @@
1
- import { BraidError, ConflictError, NotFoundError, ValidationError, } from '@braidhq/core';
1
+ import { BraidError, ValidationError } from '@braidhq/core';
2
2
  import { ZodError } from 'zod';
3
3
  const PROBLEM_BASE_URL = 'https://braid.dev/errors';
4
- function statusFor(error) {
5
- if (error instanceof ValidationError)
6
- return 400;
7
- if (error instanceof NotFoundError)
8
- return 404;
9
- if (error instanceof ConflictError)
10
- return 409;
11
- return 500;
12
- }
4
+ // The HTTP status per error code, keyed by the closed BraidErrorCode enum,
5
+ // so a new code fails to compile until it is mapped here.
6
+ const STATUS_BY_CODE = {
7
+ 'BRAID-VALIDATION': 400,
8
+ 'BRAID-UNAUTHORIZED': 401,
9
+ 'BRAID-NOT-FOUND': 404,
10
+ 'BRAID-CONFLICT': 409,
11
+ 'BRAID-FORBIDDEN': 403,
12
+ 'BRAID-UNAVAILABLE': 503,
13
+ 'BRAID-INTERNAL': 500,
14
+ };
13
15
  function problemFromBraidError(error) {
14
16
  const problem = {
15
17
  type: `${PROBLEM_BASE_URL}/${error.code.toLowerCase()}`,
16
18
  title: error.name,
17
- status: statusFor(error),
19
+ status: STATUS_BY_CODE[error.code],
18
20
  code: error.code,
19
21
  detail: error.message,
20
22
  };
@@ -24,10 +26,10 @@ function problemFromBraidError(error) {
24
26
  }
25
27
  function problemFromZodError(error) {
26
28
  return {
27
- type: `${PROBLEM_BASE_URL}/braid-val`,
29
+ type: `${PROBLEM_BASE_URL}/braid-validation`,
28
30
  title: 'ValidationError',
29
31
  status: 400,
30
- code: 'BRAID-VAL',
32
+ code: 'BRAID-VALIDATION',
31
33
  detail: error.issues.map(issue => `${issue.path.join('.')}: ${issue.message}`).join('; '),
32
34
  };
33
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/middleware/error.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,UAAU,EACV,aAAa,EACb,aAAa,EACb,eAAe,GAChB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAA;AAE9B,MAAM,gBAAgB,GAAG,0BAA0B,CAAA;AAEnD,SAAS,SAAS,CAAC,KAAiB;IAClC,IAAI,KAAK,YAAY,eAAe;QAClC,OAAO,GAAG,CAAA;IACZ,IAAI,KAAK,YAAY,aAAa;QAChC,O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