@bevel-software/platform-core-frontend 0.4.1 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (327) hide show
  1. package/THIRD-PARTY-NOTICES.md +5366 -0
  2. package/package.json +7 -4
  3. package/src/core/CoreAppShell.tsx +195 -56
  4. package/src/core/__tests__/AppChrome.test.tsx +125 -0
  5. package/src/core/__tests__/ShellRoutes.test.tsx +37 -2
  6. package/src/core/__tests__/bootstrap.test.ts +63 -0
  7. package/src/core/bootstrap.ts +73 -0
  8. package/src/core/events.ts +12 -0
  9. package/src/core/registry.ts +58 -9
  10. package/src/index.css +100 -11
  11. package/src/index.ts +24 -23
  12. package/src/lib/utils.ts +93 -117
  13. package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +281 -0
  14. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +166 -1
  15. package/src/modules/access/api.ts +49 -0
  16. package/src/modules/access/components/ManageAccessDialog.tsx +786 -481
  17. package/src/modules/access/hooks/useFileAccess.ts +1 -1
  18. package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +86 -0
  19. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +17 -1
  20. package/src/modules/admin/__tests__/admin.unread.test.tsx +61 -0
  21. package/src/modules/admin/components/AdminRolesPage.tsx +44 -38
  22. package/src/modules/admin/components/RolesCorruptedBanner.tsx +11 -10
  23. package/src/modules/admin/components/UserAccountsPage.tsx +36 -28
  24. package/src/modules/admin/state/admin.context.tsx +15 -6
  25. package/src/modules/auth/components/AccountPage.tsx +11 -11
  26. package/src/modules/auth/components/LoginScreen.tsx +12 -12
  27. package/src/modules/auth/services/sso.ts +47 -1
  28. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +277 -0
  29. package/src/modules/change-requests/__tests__/author.test.ts +48 -0
  30. package/src/modules/change-requests/__tests__/conflict.test.ts +73 -0
  31. package/src/modules/change-requests/__tests__/diff.test.ts +134 -0
  32. package/src/modules/change-requests/__tests__/propose.test.ts +93 -0
  33. package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +72 -0
  34. package/src/modules/change-requests/change-requests.css +22 -0
  35. package/src/modules/change-requests/components/ChangeBox.tsx +277 -0
  36. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +713 -0
  37. package/src/modules/change-requests/components/ConflictHelp.tsx +47 -0
  38. package/src/modules/change-requests/components/CrFileTree.tsx +398 -0
  39. package/src/modules/change-requests/components/FileChangeBoxes.tsx +168 -0
  40. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +236 -0
  41. package/src/modules/change-requests/hooks/useCrFileDiffs.ts +79 -0
  42. package/src/modules/change-requests/hooks/useFileOnBranch.ts +80 -0
  43. package/src/modules/change-requests/services/change-requests.api.ts +45 -0
  44. package/src/modules/change-requests/services/propose.api.ts +162 -0
  45. package/src/modules/change-requests/utils/author.ts +47 -0
  46. package/src/modules/change-requests/utils/conflict.ts +38 -0
  47. package/src/modules/change-requests/utils/diff.ts +80 -0
  48. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +27 -18
  49. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +36 -83
  50. package/src/modules/git/__tests__/PullNeededBanner.test.tsx +5 -5
  51. package/src/modules/git/__tests__/PullRequestsForMe.test.tsx +147 -0
  52. package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +2 -8
  53. package/src/modules/git/components/BranchSwitcher.tsx +68 -31
  54. package/src/modules/git/components/DiffView.tsx +4 -4
  55. package/src/modules/git/components/FileComparisonPanel.tsx +20 -20
  56. package/src/modules/git/components/FileHistoryPanel.tsx +71 -107
  57. package/src/modules/git/components/PullNeededBanner.tsx +6 -13
  58. package/src/modules/git/components/PullRequestsForMe.tsx +71 -36
  59. package/src/modules/git/components/UnifiedDiffView.tsx +4 -4
  60. package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +2 -2
  61. package/src/modules/git/hooks/useGitState.ts +15 -14
  62. package/src/modules/git/services/__tests__/error-messages.test.ts +4 -4
  63. package/src/modules/git/services/error-messages.ts +7 -7
  64. package/src/modules/git/services/git.api.ts +17 -11
  65. package/src/modules/git/services/pr-prompts.ts +2 -2
  66. package/src/modules/git/state/git.context.ts +10 -1
  67. package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +224 -0
  68. package/src/modules/layout/__tests__/SidebarToggle.test.tsx +242 -0
  69. package/src/modules/layout/__tests__/breakpoints.test.ts +56 -0
  70. package/src/modules/layout/breakpoints.ts +6 -0
  71. package/src/modules/layout/components/AppLayout.tsx +17 -5
  72. package/src/modules/layout/components/DemoBanner.tsx +10 -1
  73. package/src/modules/layout/components/MaintenanceOverlay.tsx +3 -3
  74. package/src/modules/layout/components/MobileChatLayout.tsx +31 -26
  75. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +59 -24
  76. package/src/modules/layout/components/SidebarFrame.tsx +317 -0
  77. package/src/modules/layout/components/SidebarToggle.tsx +86 -0
  78. package/src/modules/layout/components/SlideOverlay.tsx +1 -1
  79. package/src/modules/layout/components/__tests__/MobileChatLayout.test.tsx +40 -2
  80. package/src/modules/layout/components/__tests__/ResizableThreePaneLayout.test.tsx +19 -3
  81. package/src/modules/layout/state/sidebar.ts +200 -0
  82. package/src/modules/library/__tests__/AddToGroupDialog.test.tsx +313 -0
  83. package/src/modules/library/__tests__/ChangeRequestDock.test.tsx +84 -0
  84. package/src/modules/library/__tests__/GroupJoinRequests.test.tsx +178 -0
  85. package/src/modules/library/__tests__/GroupPage.test.tsx +479 -0
  86. package/src/modules/library/__tests__/GroupsIndexPage.test.tsx +283 -0
  87. package/src/modules/library/__tests__/GroupsSidebar.contextmenu.test.tsx +175 -0
  88. package/src/modules/library/__tests__/GroupsSidebar.locked.test.tsx +96 -0
  89. package/src/modules/library/__tests__/GroupsSidebar.test.tsx +142 -0
  90. package/src/modules/library/__tests__/GroupsSidebarMenu.test.tsx +142 -0
  91. package/src/modules/library/__tests__/LibraryCard.test.tsx +149 -0
  92. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +378 -0
  93. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +347 -0
  94. package/src/modules/library/__tests__/LockedGroupView.test.tsx +203 -0
  95. package/src/modules/library/__tests__/NewGroupDialog.test.tsx +114 -0
  96. package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +177 -0
  97. package/src/modules/library/__tests__/SkillPage.test.tsx +1063 -0
  98. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +259 -0
  99. package/src/modules/library/__tests__/ToolLogo.test.tsx +63 -0
  100. package/src/modules/library/__tests__/ToolPage.test.tsx +315 -0
  101. package/src/modules/library/__tests__/ToolSharePanel.test.tsx +36 -0
  102. package/src/modules/library/__tests__/ToolVarRow.test.tsx +260 -0
  103. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +197 -0
  104. package/src/modules/library/__tests__/auth-harness.tsx +37 -0
  105. package/src/modules/library/__tests__/oauth-fragment.test.ts +48 -0
  106. package/src/modules/library/__tests__/status.test.ts +113 -20
  107. package/src/modules/library/__tests__/useSkillDetail.test.tsx +102 -0
  108. package/src/modules/library/__tests__/useToolPage.test.tsx +146 -0
  109. package/src/modules/library/components/AccessRequestsBanner.tsx +101 -0
  110. package/src/modules/library/components/AddToGroupDialog.tsx +115 -0
  111. package/src/modules/library/components/ChangeRequestDock.tsx +52 -28
  112. package/src/modules/library/components/DeleteGroupDialog.tsx +87 -0
  113. package/src/modules/library/components/GroupIndexRow.tsx +63 -0
  114. package/src/modules/library/components/GroupJoinRequests.tsx +56 -0
  115. package/src/modules/library/components/GroupPage.tsx +373 -0
  116. package/src/modules/library/components/GroupsIndexPage.tsx +222 -0
  117. package/src/modules/library/components/GroupsSidebar.tsx +338 -0
  118. package/src/modules/library/components/GroupsSidebarMenu.tsx +160 -0
  119. package/src/modules/library/components/LibraryCard.tsx +123 -102
  120. package/src/modules/library/components/LibraryLayout.tsx +344 -0
  121. package/src/modules/library/components/LibraryPage.tsx +111 -227
  122. package/src/modules/library/components/LockGlyph.tsx +31 -0
  123. package/src/modules/library/components/LockedGroupView.tsx +159 -0
  124. package/src/modules/library/components/ManagedGroupRequests.tsx +70 -0
  125. package/src/modules/library/components/NewGroupDialog.tsx +112 -0
  126. package/src/modules/library/components/NewSkillPanel.tsx +151 -0
  127. package/src/modules/library/components/PageActions.tsx +156 -0
  128. package/src/modules/library/components/PendingSkillReview.tsx +63 -0
  129. package/src/modules/library/components/PersonalAddDialog.tsx +88 -0
  130. package/src/modules/library/components/PersonalGroupPage.tsx +125 -0
  131. package/src/modules/library/components/StatusDot.tsx +25 -0
  132. package/src/modules/library/components/ToolLogo.tsx +171 -0
  133. package/src/modules/library/components/group-page-parts.tsx +419 -0
  134. package/src/modules/library/components/skill-page/SkillFileEditor.tsx +134 -0
  135. package/src/modules/library/components/skill-page/SkillFilePane.tsx +117 -0
  136. package/src/modules/library/components/skill-page/SkillFileTabs.tsx +112 -0
  137. package/src/modules/library/components/skill-page/SkillPage.tsx +673 -0
  138. package/src/modules/library/components/skill-page/tab-ids.ts +33 -0
  139. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +175 -0
  140. package/src/modules/library/components/tool-page/ToolPage.tsx +228 -0
  141. package/src/modules/library/components/tool-page/ToolSharePanel.tsx +45 -0
  142. package/src/modules/library/components/tool-page/ToolVarRow.tsx +289 -0
  143. package/src/modules/library/hooks/useJoinRequests.ts +114 -0
  144. package/src/modules/library/hooks/useLibraryData.ts +134 -119
  145. package/src/modules/library/hooks/useSkillDetail.ts +119 -74
  146. package/src/modules/library/hooks/useToolPage.ts +145 -0
  147. package/src/modules/library/library.css +33 -245
  148. package/src/modules/library/routes/LibraryRoutes.tsx +134 -0
  149. package/src/modules/library/routes/WorkspaceItemRoute.tsx +74 -0
  150. package/src/modules/library/routes/library-paths.ts +191 -0
  151. package/src/modules/library/services/groups.api.ts +189 -0
  152. package/src/modules/library/services/library.api.ts +291 -164
  153. package/src/modules/library/services/tools.api.ts +60 -0
  154. package/src/modules/library/state/library-context.ts +22 -0
  155. package/src/modules/library/state/library-data.tsx +223 -0
  156. package/src/modules/library/state/toast.context.ts +32 -0
  157. package/src/modules/library/state/toast.tsx +84 -42
  158. package/src/modules/library/utils/clipboard.ts +33 -0
  159. package/src/modules/library/utils/group-summary.ts +68 -0
  160. package/src/modules/library/utils/names.ts +30 -0
  161. package/src/modules/library/utils/navigate-external.ts +15 -0
  162. package/src/modules/library/utils/oauth-fragment.ts +32 -0
  163. package/src/modules/library/utils/personal-group.ts +36 -0
  164. package/src/modules/library/utils/status.ts +108 -25
  165. package/src/modules/library/utils/toast-duration.ts +16 -0
  166. package/src/modules/onboarding/__tests__/onboarding.test.tsx +533 -0
  167. package/src/modules/onboarding/agent-clients.ts +48 -0
  168. package/src/modules/onboarding/components/ConnectAgentPill.tsx +133 -0
  169. package/src/modules/onboarding/components/RootLanding.tsx +54 -0
  170. package/src/modules/onboarding/components/WelcomePage.tsx +364 -0
  171. package/src/modules/onboarding/paths.ts +9 -0
  172. package/src/modules/onboarding/state/onboarding.ts +191 -0
  173. package/src/modules/pr/components/OpenChangeRequestDialog.tsx +10 -10
  174. package/src/modules/pr/services/pr-approvals.api.ts +19 -0
  175. package/src/modules/pr/services/pr-cancel.api.ts +11 -0
  176. package/src/modules/review/components/BinaryChangePlaceholder.tsx +3 -3
  177. package/src/modules/review/components/DiffViewer.tsx +4 -4
  178. package/src/modules/review/components/MarkdownDiffViewer.tsx +84 -26
  179. package/src/modules/review/components/ReviewFileRow.tsx +10 -10
  180. package/src/modules/review/components/ReviewPanel.tsx +49 -17
  181. package/src/modules/review/components/ReviewPanelSurface.tsx +1 -1
  182. package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +122 -0
  183. package/src/modules/review/hooks/__tests__/useReviewState.test.ts +1 -1
  184. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +273 -171
  185. package/src/modules/secrets-vault/components/SecretsPage.tsx +147 -110
  186. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +109 -92
  187. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +35 -4
  188. package/src/modules/secrets-vault/services/connect.api.ts +24 -3
  189. package/src/modules/settings/components/DeploymentPage.tsx +90 -0
  190. package/src/modules/settings/components/SettingsLayout.tsx +135 -0
  191. package/src/modules/settings/components/SettingsNav.tsx +114 -0
  192. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +110 -0
  193. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +249 -0
  194. package/src/modules/settings/settings-nav-items.tsx +166 -0
  195. package/src/modules/setup/__tests__/setup.test.tsx +540 -0
  196. package/src/modules/setup/components/SetupGate.tsx +67 -0
  197. package/src/modules/setup/components/SetupScreen.tsx +573 -0
  198. package/src/modules/setup/services/setup.api.ts +106 -0
  199. package/src/modules/setup/utils/git-host.ts +34 -0
  200. package/src/modules/toolbar/components/AppSwitcher.tsx +38 -15
  201. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +50 -50
  202. package/src/modules/toolbar/components/ProfileMenu.tsx +294 -0
  203. package/src/modules/toolbar/components/Toolbar.tsx +56 -54
  204. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +176 -122
  205. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +252 -77
  206. package/src/modules/tools/ToolsExplorerPage.tsx +45 -40
  207. package/src/modules/workspace/__tests__/design-system-parity.test.ts +133 -0
  208. package/src/modules/workspace/__tests__/testFixtures.ts +2 -0
  209. package/src/modules/workspace/components/EditorTabs.tsx +82 -50
  210. package/src/modules/workspace/components/FileExplorer.tsx +413 -189
  211. package/src/modules/workspace/components/FilePaneCard.tsx +53 -0
  212. package/src/modules/workspace/components/FileRoute.tsx +89 -84
  213. package/src/modules/workspace/components/FileViewer.tsx +700 -294
  214. package/src/modules/workspace/components/KbDocumentShell.tsx +138 -0
  215. package/src/modules/workspace/components/KbFileRail.tsx +128 -0
  216. package/src/modules/workspace/components/KbPageHeader.tsx +390 -0
  217. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +87 -3
  218. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +293 -39
  219. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +1 -16
  220. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +462 -44
  221. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +84 -0
  222. package/src/modules/workspace/components/__tests__/KbFileRail.test.tsx +83 -0
  223. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +192 -0
  224. package/src/modules/workspace/components/renderers/CopyAnchorButton.tsx +64 -0
  225. package/src/modules/workspace/components/renderers/CsvRenderer.tsx +8 -8
  226. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +18 -9
  227. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +14 -14
  228. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +2 -2
  229. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +31 -165
  230. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +18 -5
  231. package/src/modules/workspace/components/renderers/MermaidDiagram.tsx +27 -10
  232. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +2 -2
  233. package/src/modules/workspace/components/renderers/TextRenderer.tsx +11 -5
  234. package/src/modules/workspace/components/renderers/ToolForm.tsx +24 -24
  235. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +27 -27
  236. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -11
  237. package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +66 -0
  238. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +17 -1
  239. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +1 -1
  240. package/src/modules/workspace/components/renderers/__tests__/MermaidDiagram.test.tsx +58 -0
  241. package/src/modules/workspace/components/renderers/__tests__/lazyRenderer.test.tsx +68 -0
  242. package/src/modules/workspace/components/renderers/__tests__/rendererLayout.test.ts +64 -0
  243. package/src/modules/workspace/components/renderers/__tests__/sanitizeDocxHtml.test.ts +0 -0
  244. package/src/modules/workspace/components/renderers/chunk-boundary.tsx +71 -0
  245. package/src/modules/workspace/components/renderers/index.ts +78 -2
  246. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +241 -0
  247. package/src/modules/workspace/components/renderers/lazyRenderer.tsx +59 -0
  248. package/src/modules/workspace/components/renderers/sanitizeDocxHtml.ts +91 -0
  249. package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +59 -0
  250. package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +237 -0
  251. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +185 -0
  252. package/src/modules/workspace/hooks/useAutoGrowTextarea.ts +30 -0
  253. package/src/modules/workspace/hooks/useLastCommit.ts +66 -0
  254. package/src/modules/workspace/hooks/useLinksOut.ts +56 -0
  255. package/src/modules/workspace/hooks/useOpenChangeRequests.ts +20 -0
  256. package/src/modules/workspace/hooks/useWorkspaceState.ts +123 -14
  257. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +1 -1
  258. package/src/modules/workspace/services/workspace.api.ts +9 -2
  259. package/src/modules/workspace/state/open-change-requests.context.ts +35 -0
  260. package/src/modules/workspace/state/open-change-requests.tsx +185 -0
  261. package/src/modules/workspace/state/workspace.context.ts +9 -0
  262. package/src/modules/workspace/utils/__tests__/diff.test.ts +87 -0
  263. package/src/modules/workspace/utils/diff.ts +130 -53
  264. package/src/modules/workspace/utils/fileTree.ts +7 -4
  265. package/src/modules/workspace/workspace.css +28 -0
  266. package/src/shared/components/Badge.tsx +62 -0
  267. package/src/shared/components/Banner.tsx +58 -0
  268. package/src/shared/components/Button.tsx +90 -0
  269. package/src/shared/components/Dialog.tsx +6 -6
  270. package/src/shared/components/Field.tsx +45 -0
  271. package/src/shared/components/IconButton.tsx +74 -0
  272. package/src/shared/components/ListRow.tsx +96 -0
  273. package/src/shared/components/Menu.tsx +88 -0
  274. package/src/shared/components/PageShell.tsx +8 -5
  275. package/src/shared/components/Surface.tsx +86 -0
  276. package/src/shared/components/__tests__/primitives.test.tsx +333 -0
  277. package/src/shared/components/index.ts +48 -0
  278. package/src/shared/components/useDismissableMenu.ts +71 -0
  279. package/src/shared/theme/__tests__/accent-contrast.test.ts +84 -0
  280. package/src/shared/theme/index.css +12 -0
  281. package/src/shared/theme/measure.ts +64 -0
  282. package/src/shared/theme/shadows.css +34 -0
  283. package/src/shared/theme/tokens.css +193 -0
  284. package/src/test-setup.ts +9 -0
  285. package/src/modules/access/components/AccessRestrictedBanner.tsx +0 -31
  286. package/src/modules/access/components/NodeOwnersBanner.tsx +0 -30
  287. package/src/modules/git/__tests__/ProtectedBranchBanner.test.tsx +0 -82
  288. package/src/modules/git/components/ProtectedBranchBanner.tsx +0 -42
  289. package/src/modules/library/__tests__/DetailDialog.test.tsx +0 -200
  290. package/src/modules/library/__tests__/diff.test.ts +0 -62
  291. package/src/modules/library/__tests__/loadout.test.tsx +0 -72
  292. package/src/modules/library/components/CompareView.tsx +0 -357
  293. package/src/modules/library/components/DetailDialog.tsx +0 -566
  294. package/src/modules/library/components/GearIcon.tsx +0 -12
  295. package/src/modules/library/components/LoadoutSidebar.tsx +0 -156
  296. package/src/modules/library/components/StatusGem.tsx +0 -21
  297. package/src/modules/library/components/SuggestChange.tsx +0 -171
  298. package/src/modules/library/components/particles.ts +0 -50
  299. package/src/modules/library/state/loadout.tsx +0 -129
  300. package/src/modules/library/utils/diff.ts +0 -102
  301. package/src/modules/pr/__tests__/PrApprovalBadge.test.tsx +0 -93
  302. package/src/modules/pr/__tests__/PrCancelButton.test.tsx +0 -158
  303. package/src/modules/pr/__tests__/PrCancelConfirmDialog.test.tsx +0 -44
  304. package/src/modules/pr/__tests__/PrMergeButton.test.tsx +0 -360
  305. package/src/modules/pr/__tests__/bucketize-comments.test.ts +0 -85
  306. package/src/modules/pr/__tests__/parsePatch.test.ts +0 -104
  307. package/src/modules/pr/__tests__/usePrViewerState.test.ts +0 -72
  308. package/src/modules/pr/components/PrApprovalBadge.tsx +0 -80
  309. package/src/modules/pr/components/PrCancelButton.tsx +0 -99
  310. package/src/modules/pr/components/PrCancelConfirmDialog.tsx +0 -119
  311. package/src/modules/pr/components/PrCommentComposer.tsx +0 -92
  312. package/src/modules/pr/components/PrCommentThread.tsx +0 -168
  313. package/src/modules/pr/components/PrCommentsPanel.tsx +0 -143
  314. package/src/modules/pr/components/PrDiffPane.tsx +0 -425
  315. package/src/modules/pr/components/PrFileRow.tsx +0 -164
  316. package/src/modules/pr/components/PrFilesList.tsx +0 -53
  317. package/src/modules/pr/components/PrHeader.tsx +0 -45
  318. package/src/modules/pr/components/PrHeaderOverflowMenu.tsx +0 -58
  319. package/src/modules/pr/components/PrMergeButton.tsx +0 -268
  320. package/src/modules/pr/components/PrMergeConfirmDialog.tsx +0 -112
  321. package/src/modules/pr/components/PrRefreshFromTargetButton.tsx +0 -110
  322. package/src/modules/pr/components/PrViewer.tsx +0 -364
  323. package/src/modules/pr/hooks/usePrViewerState.ts +0 -150
  324. package/src/modules/pr/state/pr-viewer.context.ts +0 -34
  325. package/src/modules/pr/utils/bucketize-comments.ts +0 -55
  326. package/src/modules/pr/utils/parsePatch.ts +0 -57
  327. package/src/modules/toolbar/components/AdminMenu.tsx +0 -271
@@ -0,0 +1,289 @@
1
+ import { useEffect, useRef, useState, type ReactNode } from 'react';
2
+ import { Badge, Button, ListRow, TextField } from '../../../../shared/components';
3
+ import { startToolOAuth } from '../../../secrets-vault/services/connect.api';
4
+ import {
5
+ deleteAdminVar,
6
+ setAdminVar,
7
+ setOAuthClientSecret,
8
+ setUserVar,
9
+ type ToolVarStatus,
10
+ } from '../../../secrets-vault/services/tool-secrets.api';
11
+ import { navigateExternal } from '../../utils/navigate-external';
12
+
13
+ /**
14
+ * One `${VAR}` a tool declares, and the single next action for it.
15
+ *
16
+ * The matrix below is the whole point of this component. A variable is
17
+ * described by five orthogonal-looking flags (`scope`, `oauth`,
18
+ * `adminConfigured`, `userConfigured`, `authorized`/`needsReauth`) plus the
19
+ * caller's `canWrite`, and the naive rendering of that is a row with four
20
+ * competing controls on it. The rules that collapse it to ONE affordance:
21
+ *
22
+ * - `adminConfigured` is OVERLOADED. On a typed variable it means "a shared
23
+ * value exists". On an OAuth variable it means "the owner finished the
24
+ * provider setup" — nothing about the caller's own sign-in. Reading it as
25
+ * "already handled" on an OAuth row would hide the Sign in button.
26
+ * - `oauth-auto` NEVER gets a client-secret affordance. Its client was
27
+ * auto-registered by PKCE dynamic registration and has no secret; saving one
28
+ * would clobber the discovered provider row and break sign-in for everyone.
29
+ * - Whose problem is it? A user-scope gap is the caller's to fix and always
30
+ * shows an action. An admin-scope gap is the OWNER's, so a non-writer sees a
31
+ * chip that explains the state and no button they can't act on.
32
+ *
33
+ * Secret values are write-only throughout: `type="password"`, held in local
34
+ * state, cleared on save or cancel. Nothing here ever reads a stored value.
35
+ */
36
+
37
+ export interface ToolVarRowProps {
38
+ slug: string;
39
+ variable: ToolVarStatus;
40
+ /** The caller may set this tool's shared (owner-side) secrets. */
41
+ canWrite: boolean;
42
+ setupKind: 'open' | 'oauth-auto' | 'oauth-manual' | null;
43
+ /** Where the OAuth round-trip should land — a bare path, no fragment. */
44
+ returnTo: string;
45
+ /**
46
+ * Bumped by the section's banner to open this row's editor from a distance
47
+ * ("Add key" up top is the same act as "Add key" on the row). Monotonic
48
+ * counter rather than a boolean so pressing the banner twice re-opens a row
49
+ * the user has since cancelled.
50
+ */
51
+ editSignal?: number;
52
+ onChanged(): void;
53
+ onError(message: string): void;
54
+ }
55
+
56
+ type Editor = 'value' | 'client-secret' | null;
57
+
58
+ export function ToolVarRow({
59
+ slug,
60
+ variable,
61
+ canWrite,
62
+ setupKind,
63
+ returnTo,
64
+ editSignal,
65
+ onChanged,
66
+ onError,
67
+ }: ToolVarRowProps) {
68
+ const [editor, setEditor] = useState<Editor>(null);
69
+ const [value, setValue] = useState('');
70
+ const [busy, setBusy] = useState(false);
71
+ const rootRef = useRef<HTMLDivElement>(null);
72
+
73
+ const label = variable.label ?? variable.name;
74
+
75
+ // Opening from a distance is a PROP CHANGE, not an event, so the editor state
76
+ // is adjusted during render against the previous signal — React's documented
77
+ // pattern for deriving state from a changed prop. It used to be an effect,
78
+ // which set state after paint: one frame of the row rendered closed, and the
79
+ // synchronous setState in an effect body is what `set-state-in-effect` flags.
80
+ // `seenSignal` starts undefined rather than at `editSignal` so a row that
81
+ // MOUNTS with a signal already on it still opens, as the effect version did.
82
+ const [seenSignal, setSeenSignal] = useState<number | undefined>(undefined);
83
+ if (editSignal !== seenSignal) {
84
+ setSeenSignal(editSignal);
85
+ if (editSignal) {
86
+ setValue('');
87
+ setEditor('value');
88
+ }
89
+ }
90
+
91
+ // The scroll stays an effect: it is a real DOM side effect and has to happen
92
+ // after the editor it scrolls to has been committed. The banner's button
93
+ // targets exactly one row; scrolling brings the editor to where the click
94
+ // happened conceptually — "fix THIS".
95
+ useEffect(() => {
96
+ if (!editSignal) return;
97
+ rootRef.current?.scrollIntoView({ block: 'center', behavior: 'smooth' });
98
+ }, [editSignal]);
99
+
100
+ function open(next: Exclude<Editor, null>) {
101
+ setValue('');
102
+ setEditor(next);
103
+ }
104
+
105
+ function close() {
106
+ setValue('');
107
+ setEditor(null);
108
+ }
109
+
110
+ /** Every write funnels through here so busy/close/report is identical. */
111
+ async function run(action: () => Promise<void>) {
112
+ setBusy(true);
113
+ try {
114
+ await action();
115
+ close();
116
+ onChanged();
117
+ } catch (err) {
118
+ onError(err instanceof Error ? err.message : String(err));
119
+ } finally {
120
+ setBusy(false);
121
+ }
122
+ }
123
+
124
+ async function signIn() {
125
+ setBusy(true);
126
+ try {
127
+ const url = await startToolOAuth(slug, variable.name, { returnTo });
128
+ navigateExternal(url);
129
+ } catch (err) {
130
+ onError(err instanceof Error ? err.message : String(err));
131
+ setBusy(false);
132
+ }
133
+ // On success the browser is leaving; leaving `busy` set keeps the button
134
+ // from being clicked twice during the redirect.
135
+ }
136
+
137
+ const meta: ReactNode[] = [];
138
+ let description: string;
139
+
140
+ if (variable.oauth) {
141
+ // An OAuth client secret only exists for a MANUALLY declared provider.
142
+ const mayEditClientSecret = canWrite && setupKind !== 'oauth-auto';
143
+
144
+ if (variable.authorized && !variable.needsReauth) {
145
+ description = 'Each person sets their own';
146
+ meta.push(
147
+ <Badge key="chip" tone="ok">
148
+ Connected
149
+ </Badge>,
150
+ );
151
+ if (mayEditClientSecret) {
152
+ meta.push(
153
+ <Button key="secret" size="tiny" variant="quiet" onClick={() => open('client-secret')}>
154
+ Replace client secret
155
+ </Button>,
156
+ );
157
+ }
158
+ } else if (variable.authorized) {
159
+ description = 'Each person sets their own';
160
+ meta.push(
161
+ <Button key="reauth" size="sm" disabled={busy} onClick={() => void signIn()}>
162
+ Sign in again
163
+ </Button>,
164
+ );
165
+ } else if (variable.adminConfigured) {
166
+ description = 'Each person sets their own';
167
+ meta.push(
168
+ <Button key="signin" size="sm" disabled={busy} onClick={() => void signIn()}>
169
+ Sign in
170
+ </Button>,
171
+ );
172
+ } else {
173
+ // The owner hasn't declared the provider (or hasn't set its secret), so
174
+ // there is nothing for anyone to sign in to yet.
175
+ description = "The tool owner hasn't finished the sign-in setup yet.";
176
+ if (mayEditClientSecret) {
177
+ meta.push(
178
+ <Button key="secret" size="tiny" onClick={() => open('client-secret')}>
179
+ Set client secret
180
+ </Button>,
181
+ );
182
+ } else {
183
+ meta.push(
184
+ <Badge key="chip" tone="neutral">
185
+ Not set
186
+ </Badge>,
187
+ );
188
+ }
189
+ }
190
+ } else if (variable.scope === 'admin') {
191
+ if (variable.adminConfigured) {
192
+ description = 'One value for the whole team. Already handled';
193
+ meta.push(
194
+ <Badge key="chip" tone="ok">
195
+ Set by an Admin
196
+ </Badge>,
197
+ );
198
+ if (canWrite) {
199
+ meta.push(
200
+ <Button key="replace" size="tiny" variant="quiet" onClick={() => open('value')}>
201
+ Replace
202
+ </Button>,
203
+ <Button
204
+ key="remove"
205
+ size="tiny"
206
+ variant="quiet"
207
+ disabled={busy}
208
+ onClick={() => void run(() => deleteAdminVar(slug, variable.name))}
209
+ >
210
+ Remove
211
+ </Button>,
212
+ );
213
+ }
214
+ } else {
215
+ // No "— already handled" here: the chip right next to it says the
216
+ // opposite, and the prototype's single string contradicts itself once
217
+ // the value is missing.
218
+ description = 'One value for the whole team';
219
+ if (canWrite) {
220
+ meta.push(
221
+ <Button key="set" size="tiny" onClick={() => open('value')}>
222
+ Set key
223
+ </Button>,
224
+ );
225
+ } else {
226
+ meta.push(
227
+ <Badge key="chip" tone="neutral">
228
+ Not set
229
+ </Badge>,
230
+ );
231
+ }
232
+ }
233
+ } else {
234
+ description = 'Each person sets their own';
235
+ if (variable.userConfigured) {
236
+ meta.push(
237
+ <Badge key="chip" tone="ok">
238
+ Connected
239
+ </Badge>,
240
+ );
241
+ } else {
242
+ meta.push(
243
+ <Button key="add" size="sm" onClick={() => open('value')}>
244
+ Add key
245
+ </Button>,
246
+ );
247
+ }
248
+ }
249
+
250
+ const isClientSecret = editor === 'client-secret';
251
+ const save = () => {
252
+ const secret = value;
253
+ if (isClientSecret) {
254
+ return run(() => setOAuthClientSecret(slug, variable.name, secret));
255
+ }
256
+ return run(() =>
257
+ variable.scope === 'admin'
258
+ ? setAdminVar(slug, variable.name, secret)
259
+ : setUserVar(slug, variable.name, secret),
260
+ );
261
+ };
262
+
263
+ return (
264
+ <div ref={rootRef} className="flex flex-col gap-1.5">
265
+ <ListRow density="row" label={label} description={description} meta={meta} />
266
+
267
+ {editor && (
268
+ <div className="flex items-center gap-2 rounded-lg border border-line bg-surface px-3.5 py-3">
269
+ <TextField
270
+ type="password"
271
+ className="flex-1"
272
+ autoComplete="off"
273
+ aria-label={
274
+ isClientSecret ? `Client secret for ${variable.name}` : `Value for ${variable.name}`
275
+ }
276
+ value={value}
277
+ onChange={(e) => setValue(e.target.value)}
278
+ />
279
+ <Button variant="primary" size="sm" disabled={busy || !value} onClick={() => void save()}>
280
+ Save
281
+ </Button>
282
+ <Button variant="quiet" size="sm" disabled={busy} onClick={close}>
283
+ Cancel
284
+ </Button>
285
+ </div>
286
+ )}
287
+ </div>
288
+ );
289
+ }
@@ -0,0 +1,114 @@
1
+ import { useCallback, useEffect, useState } from 'react';
2
+ import { DEFAULT_BRANCH } from '@bevel-software/platform-shared';
3
+ import { grantAccess } from '../../access/api';
4
+ import { cancelPullRequest } from '../../pr/services/pr-cancel.api';
5
+ import {
6
+ listJoinRequests,
7
+ reconcileJoinRequest,
8
+ type JoinProposal,
9
+ type JoinRequest,
10
+ } from '../services/groups.api';
11
+ import { useLibraryToast } from '../state/toast.context';
12
+
13
+ /**
14
+ * The join requests one group's managers can answer, and the two ways to
15
+ * answer them.
16
+ *
17
+ * ACCEPTING IS A GRANT, NOT A MERGE. A proposal is "give this principal this
18
+ * verb on the group folder", so accepting it calls the ordinary access-grant
19
+ * API — the same endpoint the Manage-access dialog uses, with the same gate,
20
+ * lock and commit. The request's branch is never merged, so nothing else it
21
+ * carries can ride in on an approval, and a request naming five people can be
22
+ * answered with two yeses and three ignores.
23
+ *
24
+ * The request then retires ITSELF: it is open exactly while its `access.md`
25
+ * grants something the default branch does not, so once the accepted grant
26
+ * lands the diff is empty and the server closes it and deletes the branch.
27
+ * `reconcile` just asks for that check immediately instead of waiting for the
28
+ * next listing (which does it too).
29
+ *
30
+ * Fetching is unconditional and degrades to `[]` — the endpoint answers `[]`
31
+ * to non-managers rather than 403, so "am I a manager here" stays a question
32
+ * only the server answers.
33
+ */
34
+ export interface JoinRequestsState {
35
+ requests: JoinRequest[];
36
+ /** Grant one proposal, then settle the request if that was the last one. */
37
+ accept(request: JoinRequest, proposal: JoinProposal): Promise<void>;
38
+ /** Decline the whole request — reject the change request. */
39
+ decline(request: JoinRequest): Promise<void>;
40
+ reload(): void;
41
+ }
42
+
43
+ export function useJoinRequests(group: string, folder: string | null): JoinRequestsState {
44
+ const [requests, setRequests] = useState<JoinRequest[]>([]);
45
+ const [revision, setRevision] = useState(0);
46
+ const toast = useLibraryToast();
47
+
48
+ useEffect(() => {
49
+ let cancelled = false;
50
+ listJoinRequests(group)
51
+ .then((rows) => {
52
+ if (!cancelled) setRequests(rows);
53
+ })
54
+ .catch(() => {
55
+ // Silent: a manager surface that fails must not put an error banner in
56
+ // front of somebody who came to read a skill.
57
+ });
58
+ return () => {
59
+ cancelled = true;
60
+ };
61
+ }, [group, revision]);
62
+
63
+ const reload = useCallback(() => setRevision((r) => r + 1), []);
64
+
65
+ const accept = useCallback(
66
+ async (request: JoinRequest, proposal: JoinProposal) => {
67
+ if (!folder) return;
68
+ try {
69
+ await grantAccess(encodeURIComponent(DEFAULT_BRANCH), {
70
+ path: folder,
71
+ kind: 'folder',
72
+ verb: proposal.verb,
73
+ principal: proposal.principal,
74
+ });
75
+ } catch (err) {
76
+ toast(err instanceof Error ? err.message : "Couldn't grant that: try again.", 'danger');
77
+ setRevision((r) => r + 1);
78
+ return;
79
+ }
80
+ // Drop the accepted proposal locally so the row goes immediately; the
81
+ // refetch below is what makes it true.
82
+ setRequests((rows) =>
83
+ rows.map((r) =>
84
+ r.number === request.number
85
+ ? {
86
+ ...r,
87
+ proposals: r.proposals.filter(
88
+ (p) => !(p.id === proposal.id && p.verb === proposal.verb),
89
+ ),
90
+ }
91
+ : r,
92
+ ),
93
+ );
94
+ toast(`${proposal.label} now has ${proposal.verb} access.`);
95
+ await reconcileJoinRequest(group, request.number).catch(() => false);
96
+ setRevision((r) => r + 1);
97
+ },
98
+ [folder, group, toast],
99
+ );
100
+
101
+ const decline = useCallback(
102
+ async (request: JoinRequest) => {
103
+ try {
104
+ await cancelPullRequest(request.number);
105
+ } catch {
106
+ toast("Couldn't dismiss that: try again.", 'danger');
107
+ }
108
+ setRevision((r) => r + 1);
109
+ },
110
+ [toast],
111
+ );
112
+
113
+ return { requests, accept, decline, reload };
114
+ }
@@ -1,119 +1,134 @@
1
- import { useCallback, useEffect, useState } from 'react';
2
- import type { PullRequestSummary } from '@bevel-software/platform-shared';
3
- import { fetchFileAccessBatch } from '../../access/api';
4
- import { listToolSecrets, type ToolSecrets } from '../../secrets-vault/services/tool-secrets.api';
5
- import {
6
- DEFAULT_WORKSPACE_ID,
7
- getSkill,
8
- listMyChangeRequests,
9
- listOpenChangeRequests,
10
- listSkills,
11
- type LibrarySkillSummary,
12
- } from '../services/library.api';
13
-
14
- /**
15
- * All the list-level data the Library gallery needs, loaded in parallel:
16
- *
17
- * - skills — `GET /api/skills` (default-branch catalog, canRead-filtered)
18
- * - tools — `GET /api/secrets/tools` (variables + per-user config status
19
- * + per-tool `canWrite`)
20
- * - ownership — "owned by me" = write access on the skill's `SKILL.md`
21
- * (`POST /workspace/:id/access/batch` on the default-branch
22
- * workspace); tools reuse the `canWrite` the secrets route
23
- * already computes
24
- * - change requests — all open + the caller's own, for the review layer
25
- *
26
- * Non-critical failures degrade to empty sets rather than blocking the page —
27
- * only the skills+tools pair failing surfaces as a load error.
28
- */
29
- export interface LibraryData {
30
- loading: boolean;
31
- error: string | null;
32
- skills: LibrarySkillSummary[];
33
- tools: ToolSecrets[];
34
- /** Skill names (folder ids) whose SKILL.md the caller can write. */
35
- ownedSkills: Set<string>;
36
- /**
37
- * Per-skill `allowed-tools` frontmatter (name → entries), used to derive
38
- * which integrations a skill needs. Loaded via one `getSkill` per catalog
39
- * entry — the browser skill surface has no bulk endpoint for frontmatter.
40
- */
41
- allowedToolsBySkill: Map<string, string[]>;
42
- /** Open change requests, all authors. */
43
- crs: PullRequestSummary[];
44
- /** Numbers of the caller's own change requests. */
45
- myCrNumbers: Set<number>;
46
- reload(): void;
47
- }
48
-
49
- export function useLibraryData(): LibraryData {
50
- const [state, setState] = useState<Omit<LibraryData, 'reload'>>({
51
- loading: true,
52
- error: null,
53
- skills: [],
54
- tools: [],
55
- ownedSkills: new Set(),
56
- allowedToolsBySkill: new Map(),
57
- crs: [],
58
- myCrNumbers: new Set(),
59
- });
60
- const [revision, setRevision] = useState(0);
61
-
62
- useEffect(() => {
63
- let cancelled = false;
64
- setState((s) => ({ ...s, loading: true, error: null }));
65
-
66
- (async () => {
67
- const [skills, tools] = await Promise.all([listSkills(), listToolSecrets()]);
68
-
69
- const [ownership, crs, mine, details] = await Promise.all([
70
- skills.length
71
- ? fetchFileAccessBatch(
72
- DEFAULT_WORKSPACE_ID,
73
- skills.map((s) => `${s.path}/SKILL.md`),
74
- ).catch(() => ({ results: {} as Record<string, boolean> }))
75
- : Promise.resolve({ results: {} as Record<string, boolean> }),
76
- listOpenChangeRequests().catch(() => [] as PullRequestSummary[]),
77
- listMyChangeRequests().catch(() => [] as PullRequestSummary[]),
78
- Promise.all(
79
- skills.map(
80
- (s): Promise<[string, string[]]> =>
81
- getSkill(s.name)
82
- .then((d): [string, string[]] => [s.name, d.allowedTools ?? []])
83
- .catch((): [string, string[]] => [s.name, []]),
84
- ),
85
- ),
86
- ]);
87
-
88
- if (cancelled) return;
89
- const ownedSkills = new Set(
90
- skills.filter((s) => ownership.results[`${s.path}/SKILL.md`] === true).map((s) => s.name),
91
- );
92
- setState({
93
- loading: false,
94
- error: null,
95
- skills,
96
- tools,
97
- ownedSkills,
98
- allowedToolsBySkill: new Map(details),
99
- crs: crs.filter((c) => c.state === 'open'),
100
- myCrNumbers: new Set(mine.map((c) => c.number)),
101
- });
102
- })().catch((err) => {
103
- if (cancelled) return;
104
- setState((s) => ({
105
- ...s,
106
- loading: false,
107
- error: err instanceof Error ? err.message : "Couldn't load the library.",
108
- }));
109
- });
110
-
111
- return () => {
112
- cancelled = true;
113
- };
114
- }, [revision]);
115
-
116
- const reload = useCallback(() => setRevision((r) => r + 1), []);
117
-
118
- return { ...state, reload };
119
- }
1
+ import { useCallback, useEffect, useState } from 'react';
2
+ import type { PullRequestSummary } from '@bevel-software/platform-shared';
3
+ import { fetchFileAccessBatch } from '../../access/api';
4
+ import { listToolSecrets, type ToolSecrets } from '../../secrets-vault/services/tool-secrets.api';
5
+ import {
6
+ defaultWorkspaceId,
7
+ getSkill,
8
+ listPendingSkills,
9
+ listSkills,
10
+ type LibrarySkillSummary,
11
+ type PendingSkillSummary,
12
+ } from '../services/library.api';
13
+ import {
14
+ listMyChangeRequests,
15
+ listOpenChangeRequests,
16
+ } from '../../change-requests/services/change-requests.api';
17
+
18
+ /**
19
+ * All the list-level data the Library gallery needs, loaded in parallel:
20
+ *
21
+ * - skills — `GET /api/skills` (default-branch catalog, canRead-filtered)
22
+ * - tools — `GET /api/secrets/tools` (variables + per-user config status
23
+ * + per-tool `canWrite`)
24
+ * - ownership — "owned by me" = write access on the skill's `SKILL.md`
25
+ * (`POST /workspace/:id/access/batch` on the default-branch
26
+ * workspace); tools reuse the `canWrite` the secrets route
27
+ * already computes
28
+ * - change requests — all open + the caller's own, for the review layer
29
+ * - pending skills — `GET /api/skills/pending`, the skills that exist only on
30
+ * an open change request's branch (author + approvers only)
31
+ *
32
+ * Non-critical failures degrade to empty sets rather than blocking the page —
33
+ * only the skills+tools pair failing surfaces as a load error.
34
+ */
35
+ export interface LibraryData {
36
+ loading: boolean;
37
+ error: string | null;
38
+ skills: LibrarySkillSummary[];
39
+ /**
40
+ * Proposed skills, not yet released. Kept SEPARATE from `skills` all the way
41
+ * up to the gallery: everything downstream of `skills` treats an entry as a
42
+ * thing that exists and can be opened, and a proposal is neither.
43
+ */
44
+ pendingSkills: PendingSkillSummary[];
45
+ tools: ToolSecrets[];
46
+ /** Skill names (folder ids) whose SKILL.md the caller can write. */
47
+ ownedSkills: Set<string>;
48
+ /**
49
+ * Per-skill `allowed-tools` frontmatter (name → entries), used to derive
50
+ * which integrations a skill needs. Loaded via one `getSkill` per catalog
51
+ * entry — the browser skill surface has no bulk endpoint for frontmatter.
52
+ */
53
+ allowedToolsBySkill: Map<string, string[]>;
54
+ /** Open change requests, all authors. */
55
+ crs: PullRequestSummary[];
56
+ /** Numbers of the caller's own change requests. */
57
+ myCrNumbers: Set<number>;
58
+ reload(): void;
59
+ }
60
+
61
+ export function useLibraryData(): LibraryData {
62
+ const [state, setState] = useState<Omit<LibraryData, 'reload'>>({
63
+ loading: true,
64
+ error: null,
65
+ skills: [],
66
+ pendingSkills: [],
67
+ tools: [],
68
+ ownedSkills: new Set(),
69
+ allowedToolsBySkill: new Map(),
70
+ crs: [],
71
+ myCrNumbers: new Set(),
72
+ });
73
+ const [revision, setRevision] = useState(0);
74
+
75
+ useEffect(() => {
76
+ let cancelled = false;
77
+ setState((s) => ({ ...s, loading: true, error: null }));
78
+
79
+ (async () => {
80
+ const [skills, tools] = await Promise.all([listSkills(), listToolSecrets()]);
81
+
82
+ const [ownership, crs, mine, pending, details] = await Promise.all([
83
+ skills.length
84
+ ? fetchFileAccessBatch(
85
+ defaultWorkspaceId(),
86
+ skills.map((s) => `${s.path}/SKILL.md`),
87
+ ).catch(() => ({ results: {} as Record<string, boolean> }))
88
+ : Promise.resolve({ results: {} as Record<string, boolean> }),
89
+ listOpenChangeRequests().catch(() => [] as PullRequestSummary[]),
90
+ listMyChangeRequests().catch(() => [] as PullRequestSummary[]),
91
+ listPendingSkills().catch(() => [] as PendingSkillSummary[]),
92
+ Promise.all(
93
+ skills.map(
94
+ (s): Promise<[string, string[]]> =>
95
+ getSkill(s.name)
96
+ .then((d): [string, string[]] => [s.name, d.allowedTools ?? []])
97
+ .catch((): [string, string[]] => [s.name, []]),
98
+ ),
99
+ ),
100
+ ]);
101
+
102
+ if (cancelled) return;
103
+ const ownedSkills = new Set(
104
+ skills.filter((s) => ownership.results[`${s.path}/SKILL.md`] === true).map((s) => s.name),
105
+ );
106
+ setState({
107
+ loading: false,
108
+ error: null,
109
+ skills,
110
+ pendingSkills: pending,
111
+ tools,
112
+ ownedSkills,
113
+ allowedToolsBySkill: new Map(details),
114
+ crs: crs.filter((c) => c.state === 'open'),
115
+ myCrNumbers: new Set(mine.map((c) => c.number)),
116
+ });
117
+ })().catch((err) => {
118
+ if (cancelled) return;
119
+ setState((s) => ({
120
+ ...s,
121
+ loading: false,
122
+ error: err instanceof Error ? err.message : "Couldn't load the library.",
123
+ }));
124
+ });
125
+
126
+ return () => {
127
+ cancelled = true;
128
+ };
129
+ }, [revision]);
130
+
131
+ const reload = useCallback(() => setRevision((r) => r + 1), []);
132
+
133
+ return { ...state, reload };
134
+ }