@bevel-software/platform-core-frontend 0.14.0 → 0.19.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 (360) hide show
  1. package/THIRD-PARTY-NOTICES.md +2 -2
  2. package/package.json +3 -3
  3. package/src/core/CoreAppShell.tsx +34 -26
  4. package/src/core/__tests__/AppChrome.test.tsx +0 -3
  5. package/src/core/__tests__/bootstrap.test.ts +33 -1
  6. package/src/core/__tests__/events.test.ts +43 -0
  7. package/src/core/bootstrap.ts +38 -1
  8. package/src/core/events.ts +85 -3
  9. package/src/core/registry.ts +1 -1
  10. package/src/lib/__tests__/api.test.ts +38 -0
  11. package/src/lib/__tests__/email.test.ts +44 -0
  12. package/src/lib/api.ts +19 -2
  13. package/src/lib/email.ts +37 -1
  14. package/src/lib/utils.ts +2 -0
  15. package/src/modules/access/__tests__/ManageAccessDialog.add-row-picking.test.tsx +141 -0
  16. package/src/modules/access/__tests__/ManageAccessDialog.chip-truncation.test.tsx +204 -0
  17. package/src/modules/access/__tests__/ManageAccessDialog.download-read.test.tsx +234 -0
  18. package/src/modules/access/__tests__/ManageAccessDialog.edited-row-visible.test.tsx +160 -0
  19. package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +2 -2
  20. package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +166 -0
  21. package/src/modules/access/__tests__/ManageAccessDialog.restrict.test.tsx +510 -0
  22. package/src/modules/access/__tests__/ManageAccessDialog.row-menu-axes.test.tsx +299 -0
  23. package/src/modules/access/__tests__/ManageAccessDialog.row-menu-width.test.tsx +226 -0
  24. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +781 -76
  25. package/src/modules/access/__tests__/ManageAccessDialog.unknown-email.test.tsx +314 -0
  26. package/src/modules/access/__tests__/manage-access-affordance.test.ts +14 -0
  27. package/src/modules/access/__tests__/plugin-token.test.ts +21 -0
  28. package/src/modules/access/__tests__/tailwindDeclarations.ts +210 -0
  29. package/src/modules/access/api.ts +192 -10
  30. package/src/modules/access/components/ManageAccessDialog.tsx +1337 -570
  31. package/src/modules/access/manage-access-affordance.ts +17 -0
  32. package/src/modules/admin/__tests__/AddMemberInput.test.tsx +297 -0
  33. package/src/modules/admin/__tests__/AdminRolesPage.capabilities.test.tsx +2 -2
  34. package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +189 -0
  35. package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +1 -1
  36. package/src/modules/admin/__tests__/ConnectionKeysPage.test.tsx +266 -0
  37. package/src/modules/admin/__tests__/DirectoryGroupsPage.suggest.test.tsx +182 -0
  38. package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +165 -14
  39. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +401 -4
  40. package/src/modules/admin/__tests__/group-members-path.test.ts +27 -0
  41. package/src/modules/admin/components/AddMemberInput.tsx +268 -0
  42. package/src/modules/admin/components/AdminRolesPage.tsx +97 -132
  43. package/src/modules/admin/components/ConnectionKeysPage.tsx +269 -0
  44. package/src/modules/admin/components/DirectoryGroupsPage.tsx +91 -39
  45. package/src/modules/admin/components/UserAccountsPage.tsx +271 -37
  46. package/src/modules/admin/components/connection-keys-grouping.ts +43 -0
  47. package/src/modules/admin/components/group-members-path.ts +32 -0
  48. package/src/modules/admin/services/connection-keys.api.ts +47 -0
  49. package/src/modules/admin/services/roles.api.ts +12 -1
  50. package/src/modules/auth/__tests__/AccountPage.test.tsx +50 -2
  51. package/src/modules/auth/components/AccountPage.tsx +73 -54
  52. package/src/modules/auth/components/LoginScreen.tsx +1 -0
  53. package/src/modules/auth/services/account.api.ts +78 -4
  54. package/src/modules/change-requests/__tests__/ChangeRequestDialog.access-rules.test.tsx +144 -0
  55. package/src/modules/change-requests/__tests__/ChangeRequestDialog.binary.test.tsx +422 -0
  56. package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +431 -0
  57. package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +193 -0
  58. package/src/modules/change-requests/__tests__/ChangeRequestDialog.initial-file.test.tsx +142 -0
  59. package/src/modules/change-requests/__tests__/ChangeRequestDialog.moved.test.tsx +202 -0
  60. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +205 -13
  61. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +271 -0
  62. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +208 -0
  63. package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +286 -0
  64. package/src/modules/change-requests/__tests__/propose.concurrent.test.ts +273 -0
  65. package/src/modules/change-requests/__tests__/readFailure.test.ts +122 -0
  66. package/src/modules/change-requests/__tests__/useCrFileDiffs.test.tsx +238 -0
  67. package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +56 -1
  68. package/src/modules/change-requests/__tests__/useForkPointFile.test.tsx +79 -0
  69. package/src/modules/change-requests/components/BranchFilePreview.tsx +357 -0
  70. package/src/modules/change-requests/components/ChangeBox.tsx +31 -2
  71. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +862 -72
  72. package/src/modules/change-requests/components/CrFileTree.tsx +74 -58
  73. package/src/modules/change-requests/components/FileChangeBoxes.tsx +19 -15
  74. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +41 -7
  75. package/src/modules/change-requests/hooks/useCrFileDiffs.ts +181 -23
  76. package/src/modules/change-requests/hooks/useFileOnBranch.ts +70 -7
  77. package/src/modules/change-requests/hooks/useForkPointFile.ts +77 -0
  78. package/src/modules/change-requests/services/change-requests.api.ts +57 -1
  79. package/src/modules/change-requests/services/denied-file.api.ts +53 -0
  80. package/src/modules/change-requests/services/propose.api.ts +97 -8
  81. package/src/modules/change-requests/utils/approval.ts +15 -0
  82. package/src/modules/change-requests/utils/author.ts +32 -0
  83. package/src/modules/change-requests/utils/readFailure.ts +110 -0
  84. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +20 -0
  85. package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +65 -1
  86. package/src/modules/git/components/FileHistoryPanel.tsx +5 -0
  87. package/src/modules/git/components/GitSyncFailedBanner.tsx +68 -5
  88. package/src/modules/git/components/PullRequestsForMe.tsx +51 -24
  89. package/src/modules/git/services/__tests__/error-messages.test.ts +29 -0
  90. package/src/modules/git/services/error-messages.ts +12 -0
  91. package/src/modules/git/services/pr-prompts.ts +5 -5
  92. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +401 -0
  93. package/src/modules/layout/__tests__/SidebarFooterGrid.test.tsx +286 -0
  94. package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +61 -0
  95. package/src/modules/layout/components/AppLayout.tsx +2 -0
  96. package/src/modules/layout/components/MobileChatLayout.tsx +4 -1
  97. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +4 -1
  98. package/src/modules/layout/components/SidebarFrame.tsx +109 -4
  99. package/src/modules/library/__tests__/AddToPluginDialog.test.tsx +171 -5
  100. package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +356 -0
  101. package/src/modules/library/__tests__/IntegrationsSetupReminder.test.tsx +60 -0
  102. package/src/modules/library/__tests__/LibraryCard.test.tsx +91 -10
  103. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +242 -107
  104. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +104 -99
  105. package/src/modules/library/__tests__/LinkSkillPanel.test.tsx +136 -0
  106. package/src/modules/library/__tests__/LockedPluginView.test.tsx +103 -7
  107. package/src/modules/library/__tests__/NewPluginDialog.test.tsx +18 -8
  108. package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +79 -3
  109. package/src/modules/library/__tests__/PersonalPluginPage.test.tsx +201 -0
  110. package/src/modules/library/__tests__/PluginExtras.test.tsx +115 -9
  111. package/src/modules/library/__tests__/PluginJoinRequests.test.tsx +60 -1
  112. package/src/modules/library/__tests__/PluginPage.test.tsx +453 -7
  113. package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +17 -57
  114. package/src/modules/library/__tests__/PluginsSidebar.test.tsx +161 -97
  115. package/src/modules/library/__tests__/PluginsSidebarMenu.test.tsx +16 -0
  116. package/src/modules/library/__tests__/SharedViaPlugins.test.tsx +106 -0
  117. package/src/modules/library/__tests__/SkillPage.test.tsx +391 -78
  118. package/src/modules/library/__tests__/SkillsTree.test.tsx +461 -0
  119. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +582 -71
  120. package/src/modules/library/__tests__/ToolPage.test.tsx +94 -4
  121. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +279 -21
  122. package/src/modules/library/__tests__/auth-harness.tsx +9 -9
  123. package/src/modules/library/__tests__/card-row-menu.test.tsx +320 -0
  124. package/src/modules/library/__tests__/library-data.mapping.test.tsx +98 -0
  125. package/src/modules/library/__tests__/library-data.stale.test.tsx +183 -0
  126. package/src/modules/library/__tests__/library-data.test.ts +7 -0
  127. package/src/modules/library/__tests__/library-paths.test.ts +75 -0
  128. package/src/modules/library/__tests__/link-membership.test.ts +129 -0
  129. package/src/modules/library/__tests__/name-with-badges.test.tsx +273 -0
  130. package/src/modules/library/__tests__/newSkillMarkdown.test.ts +30 -0
  131. package/src/modules/library/__tests__/owner-pill.test.tsx +357 -0
  132. package/src/modules/library/__tests__/pending-tools.test.tsx +400 -0
  133. package/src/modules/library/__tests__/plugin-entries.test.ts +122 -0
  134. package/src/modules/library/__tests__/plugin-summary.test.ts +67 -0
  135. package/src/modules/library/__tests__/status.test.ts +82 -2
  136. package/src/modules/library/__tests__/tools.api.test.ts +44 -1
  137. package/src/modules/library/__tests__/useJoinRequests.test.tsx +46 -0
  138. package/src/modules/library/components/AccessRequestsBanner.tsx +85 -47
  139. package/src/modules/library/components/AddDialogTabs.tsx +103 -0
  140. package/src/modules/library/components/AddToPluginDialog.tsx +107 -18
  141. package/src/modules/library/components/IntegrationsSetupReminder.tsx +59 -0
  142. package/src/modules/library/components/ItemActionsMenu.tsx +288 -0
  143. package/src/modules/library/components/LibraryCard.tsx +149 -34
  144. package/src/modules/library/components/LibraryLayout.tsx +120 -247
  145. package/src/modules/library/components/LibraryPage.tsx +172 -39
  146. package/src/modules/library/components/LinkSkillPanel.tsx +169 -0
  147. package/src/modules/library/components/LockedPluginView.tsx +63 -35
  148. package/src/modules/library/components/NameWithBadges.tsx +164 -0
  149. package/src/modules/library/components/NewPluginDialog.tsx +19 -5
  150. package/src/modules/library/components/PageActions.tsx +31 -9
  151. package/src/modules/library/components/{PendingSkillReview.tsx → PendingItemReview.tsx} +14 -7
  152. package/src/modules/library/components/PersonalAddDialog.tsx +68 -18
  153. package/src/modules/library/components/PersonalPluginPage.tsx +123 -23
  154. package/src/modules/library/components/PluginExtras.tsx +143 -18
  155. package/src/modules/library/components/PluginIndexRow.tsx +47 -12
  156. package/src/modules/library/components/PluginPage.tsx +234 -38
  157. package/src/modules/library/components/PluginRows.tsx +286 -0
  158. package/src/modules/library/components/PluginsSidebar.tsx +271 -238
  159. package/src/modules/library/components/PluginsSidebarMenu.tsx +26 -1
  160. package/src/modules/library/components/RenamePluginDialog.tsx +136 -0
  161. package/src/modules/library/components/ShareButton.tsx +17 -0
  162. package/src/modules/library/components/SkillsTree.tsx +204 -0
  163. package/src/modules/library/components/StatusDot.tsx +1 -0
  164. package/src/modules/library/components/TeamRoute.tsx +15 -0
  165. package/src/modules/library/components/__tests__/upload-notices-once-per-page.test.tsx +144 -0
  166. package/src/modules/library/components/plugin-page-parts.tsx +132 -23
  167. package/src/modules/library/components/skill-page/SharedViaPlugins.tsx +212 -0
  168. package/src/modules/library/components/skill-page/SkillFilePane.tsx +5 -0
  169. package/src/modules/library/components/skill-page/SkillPage.tsx +337 -121
  170. package/src/modules/library/components/tool-page/DeleteToolDialog.tsx +218 -0
  171. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +79 -178
  172. package/src/modules/library/components/tool-page/ToolPage.tsx +116 -17
  173. package/src/modules/library/components/tool-page/ToolVarRow.tsx +42 -41
  174. package/src/modules/library/hooks/__tests__/useLibraryData.test.ts +98 -0
  175. package/src/modules/library/hooks/useJoinRequests.ts +48 -18
  176. package/src/modules/library/hooks/useLibraryData.ts +92 -19
  177. package/src/modules/library/routes/LibraryRoutes.tsx +14 -11
  178. package/src/modules/library/routes/WorkspaceItemRoute.tsx +229 -82
  179. package/src/modules/library/routes/library-paths.ts +46 -35
  180. package/src/modules/library/services/library.api.ts +89 -17
  181. package/src/modules/library/services/plugins.api.ts +161 -9
  182. package/src/modules/library/services/teams.api.ts +15 -0
  183. package/src/modules/library/services/tools.api.ts +78 -0
  184. package/src/modules/library/state/library-data.tsx +268 -37
  185. package/src/modules/library/utils/personal-plugin.ts +13 -15
  186. package/src/modules/library/utils/plugin-entries.ts +134 -0
  187. package/src/modules/library/utils/plugin-summary.ts +102 -0
  188. package/src/modules/library/utils/status.ts +204 -35
  189. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +11 -3
  190. package/src/modules/onboarding/__tests__/onboarding.test.tsx +853 -760
  191. package/src/modules/onboarding/agent-clients.ts +55 -23
  192. package/src/modules/onboarding/components/ConnectAgentPill.tsx +5 -1
  193. package/src/modules/onboarding/components/WelcomePage.tsx +98 -62
  194. package/src/modules/pr/services/pr-merge.api.ts +2 -1
  195. package/src/modules/review/components/MarkdownDiffViewer.tsx +53 -8
  196. package/src/modules/review/components/ReviewPanel.tsx +15 -17
  197. package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +64 -0
  198. package/src/modules/review/components/__tests__/ReviewPanel.test.tsx +25 -1
  199. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +454 -117
  200. package/src/modules/secrets-vault/components/SecretsPage.tsx +48 -7
  201. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +84 -5
  202. package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +425 -0
  203. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +417 -82
  204. package/src/modules/secrets-vault/components/__tests__/ToolSecretsPanel.test.tsx +105 -0
  205. package/src/modules/secrets-vault/components/__tests__/connect-lists-what-the-banner-counted.test.tsx +407 -0
  206. package/src/modules/secrets-vault/probe/SavedKeyProbeResult.tsx +98 -0
  207. package/src/modules/secrets-vault/probe/__tests__/probe-verdict.test.ts +160 -0
  208. package/src/modules/secrets-vault/probe/probe-verdict.ts +108 -0
  209. package/src/modules/secrets-vault/probe/useSavedKeyProbe.ts +228 -0
  210. package/src/modules/secrets-vault/services/connect.api.ts +36 -5
  211. package/src/modules/secrets-vault/utils/connect-status.ts +98 -0
  212. package/src/modules/settings/components/ClaudeConnectionCard.tsx +154 -0
  213. package/src/modules/settings/components/ClaudeConnectionFields.tsx +23 -0
  214. package/src/modules/settings/components/DeploymentPage.tsx +16 -22
  215. package/src/modules/settings/components/MarketplaceSection.tsx +152 -0
  216. package/src/modules/settings/components/__tests__/ClaudeConnectionCard.test.tsx +63 -0
  217. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +74 -1
  218. package/src/modules/settings/components/__tests__/MarketplaceSection.test.tsx +325 -0
  219. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +5 -5
  220. package/src/modules/settings/services/github-facade.api.ts +66 -0
  221. package/src/modules/settings/settings-nav-items.tsx +10 -2
  222. package/src/modules/setup/__tests__/setup.oidc.test.tsx +172 -0
  223. package/src/modules/setup/__tests__/setup.probe-refusal.test.tsx +123 -0
  224. package/src/modules/setup/__tests__/setup.test.tsx +615 -4
  225. package/src/modules/setup/__tests__/useSetupStatus.test.tsx +130 -0
  226. package/src/modules/setup/components/SetupGate.tsx +16 -16
  227. package/src/modules/setup/components/SetupScreen.tsx +711 -40
  228. package/src/modules/setup/hooks/useSetupStatus.ts +93 -0
  229. package/src/modules/setup/services/setup.api.ts +218 -3
  230. package/src/modules/setup/utils/__tests__/root-folders.test.ts +72 -0
  231. package/src/modules/setup/utils/root-folders.ts +46 -0
  232. package/src/modules/toolbar/assets/claude-setup/01-add-manually.webp +0 -0
  233. package/src/modules/toolbar/assets/claude-setup/02-add-configuration.webp +0 -0
  234. package/src/modules/toolbar/assets/claude-setup/03-connect-account.webp +0 -0
  235. package/src/modules/toolbar/assets/claude-setup/04-pick-instance.webp +0 -0
  236. package/src/modules/toolbar/assets/claude-setup/05-plugins-add.webp +0 -0
  237. package/src/modules/toolbar/assets/claude-setup/06-add-marketplace.webp +0 -0
  238. package/src/modules/toolbar/assets/claude-setup/07-paste-url-sync.webp +0 -0
  239. package/src/modules/toolbar/assets/claude-setup/08-install-plugins.webp +0 -0
  240. package/src/modules/toolbar/assets/claude-setup/09-select-repository.webp +0 -0
  241. package/src/modules/toolbar/assets/claude-setup/10-connector-not-added.webp +0 -0
  242. package/src/modules/toolbar/assets/claude-setup/11-add-custom-connector.webp +0 -0
  243. package/src/modules/toolbar/assets/claude-setup/README.md +68 -0
  244. package/src/modules/toolbar/components/AgentInstructionsCard.tsx +296 -0
  245. package/src/modules/toolbar/components/ClaudeMarketplaceCarousel.tsx +107 -0
  246. package/src/modules/toolbar/components/ClaudeRegistrationSteps.tsx +127 -0
  247. package/src/modules/toolbar/components/CoworkSetupSteps.tsx +100 -0
  248. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +395 -124
  249. package/src/modules/toolbar/components/ScreenshotStep.tsx +77 -0
  250. package/src/modules/toolbar/components/SetupCarousel.tsx +177 -0
  251. package/src/modules/toolbar/components/__tests__/AgentInstructionsCard.test.tsx +370 -0
  252. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +659 -36
  253. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +2 -2
  254. package/src/modules/toolbar/components/__tests__/claude-setup-shots.test.ts +104 -0
  255. package/src/modules/toolbar/components/claude-connector-slide.tsx +38 -0
  256. package/src/modules/toolbar/components/claude-setup-shots.ts +167 -0
  257. package/src/modules/toolbar/components/deployment-address.ts +29 -0
  258. package/src/modules/toolbar/components/setup-step-parts.tsx +35 -0
  259. package/src/modules/toolbar/services/__tests__/agent-instructions.api.test.ts +89 -0
  260. package/src/modules/toolbar/services/agent-instructions.api.ts +167 -0
  261. package/src/modules/toolbar/services/external-api-keys.api.ts +8 -0
  262. package/src/modules/workflow/state/ChangeRequestStaleBinder.tsx +43 -0
  263. package/src/modules/workflow/state/EventBusProvider.tsx +122 -11
  264. package/src/modules/workflow/state/__tests__/EventBusProvider.storage.test.tsx +87 -0
  265. package/src/modules/workflow/state/__tests__/EventBusProvider.watch.test.tsx +223 -0
  266. package/src/modules/workflow/state/event-bus.context.ts +10 -0
  267. package/src/modules/workspace/__tests__/testFixtures.ts +6 -3
  268. package/src/modules/workspace/components/FileExplorer.tsx +1527 -367
  269. package/src/modules/workspace/components/FileRoute.tsx +376 -22
  270. package/src/modules/workspace/components/FileViewer.tsx +166 -45
  271. package/src/modules/workspace/components/KbDocumentShell.tsx +50 -6
  272. package/src/modules/workspace/components/KbPageHeader.tsx +120 -55
  273. package/src/modules/workspace/components/TreeActionConfirm.tsx +350 -0
  274. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +2473 -129
  275. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +768 -16
  276. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +332 -12
  277. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +39 -0
  278. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +33 -20
  279. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +4 -5
  280. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +13 -4
  281. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +4 -3
  282. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +8 -14
  283. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +75 -16
  284. package/src/modules/workspace/components/renderers/KbImage.tsx +180 -0
  285. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +22 -6
  286. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +48 -22
  287. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +4 -5
  288. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +4 -3
  289. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +4 -3
  290. package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +12 -0
  291. package/src/modules/workspace/components/renderers/__tests__/DownloadFileButton.test.tsx +57 -9
  292. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.test.tsx +13 -1
  293. package/src/modules/workspace/components/renderers/__tests__/ImageRenderer.test.tsx +163 -0
  294. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +237 -0
  295. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +108 -14
  296. package/src/modules/workspace/components/renderers/__tests__/PptxRenderer.test.tsx +14 -1
  297. package/src/modules/workspace/components/renderers/__tests__/XlsxRenderer.test.tsx +16 -1
  298. package/src/modules/workspace/components/renderers/__tests__/rendererSelection.test.tsx +66 -1
  299. package/src/modules/workspace/components/renderers/index.ts +53 -2
  300. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +25 -4
  301. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +40 -0
  302. package/src/modules/workspace/hooks/__tests__/useImageRevision.test.tsx +174 -0
  303. package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +179 -1
  304. package/src/modules/workspace/hooks/__tests__/useWorkspaceImageResolver.test.tsx +122 -0
  305. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +892 -7
  306. package/src/modules/workspace/hooks/useImageRevision.ts +101 -0
  307. package/src/modules/workspace/hooks/useMergedWorkspaceTree.ts +89 -0
  308. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +55 -0
  309. package/src/modules/workspace/hooks/useWorkspaceState.ts +438 -66
  310. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +279 -3
  311. package/src/modules/workspace/routing/kb-routes.ts +207 -30
  312. package/src/modules/workspace/services/__tests__/workspace.api.test.ts +57 -1
  313. package/src/modules/workspace/services/workspace.api.ts +57 -4
  314. package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +343 -0
  315. package/src/modules/workspace/state/__tests__/upload-lands-where-it-was-dropped.test.tsx +158 -0
  316. package/src/modules/workspace/state/open-change-requests.tsx +100 -12
  317. package/src/modules/workspace/state/workspace.context.ts +130 -16
  318. package/src/modules/workspace/utils/__tests__/file-trace.test.ts +73 -0
  319. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +234 -5
  320. package/src/modules/workspace/utils/__tests__/pasteLink.test.ts +76 -0
  321. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +364 -0
  322. package/src/modules/workspace/utils/__tests__/uploadError.test.ts +35 -0
  323. package/src/modules/workspace/utils/file-trace.ts +50 -0
  324. package/src/modules/workspace/utils/fileTree.ts +126 -52
  325. package/src/modules/workspace/utils/frontmatter.ts +8 -4
  326. package/src/modules/workspace/utils/pasteLink.ts +90 -0
  327. package/src/modules/workspace/utils/treeConfirm.ts +338 -0
  328. package/src/modules/workspace/utils/uploadError.ts +29 -0
  329. package/src/shared/__tests__/marketplace-url.test.ts +59 -0
  330. package/src/shared/components/Badge.tsx +3 -1
  331. package/src/shared/components/Banner.tsx +5 -1
  332. package/src/shared/components/Button.tsx +16 -2
  333. package/src/shared/components/Dialog.tsx +27 -11
  334. package/src/shared/components/Menu.tsx +13 -1
  335. package/src/shared/components/PageShell.tsx +13 -8
  336. package/src/shared/components/__tests__/primitives.test.tsx +116 -2
  337. package/src/shared/components/__tests__/useFocusHandoff.test.tsx +192 -0
  338. package/src/shared/components/index.ts +2 -0
  339. package/src/shared/components/useDismissableMenu.ts +32 -10
  340. package/src/shared/components/useFocusHandoff.ts +51 -0
  341. package/src/shared/components/useLatestRef.ts +28 -0
  342. package/src/shared/markdown/Markdown.tsx +12 -3
  343. package/src/shared/markdown/__tests__/escapeSpacesInLinkDestinations.test.ts +39 -0
  344. package/src/shared/markdown/hrefs.ts +50 -0
  345. package/src/shared/marketplace-url.ts +118 -0
  346. package/src/shared/mcp/ChatGptInstallLink.tsx +3 -3
  347. package/src/shared/mcp/ConnectionInstructions.tsx +38 -27
  348. package/src/shared/mcp/__tests__/connect-snippets.test.ts +3 -3
  349. package/src/shared/mcp/connect-snippets.ts +14 -9
  350. package/src/shared/mcp/index.ts +1 -1
  351. package/src/shared/theme/__tests__/header-band.test.ts +197 -0
  352. package/src/shared/theme/header.ts +75 -0
  353. package/src/shared/theme/measure.ts +7 -4
  354. package/src/shared/theme/tokens.css +34 -0
  355. package/src/modules/library/__tests__/PluginsIndexPage.test.tsx +0 -363
  356. package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +0 -97
  357. package/src/modules/library/components/PluginsIndexPage.tsx +0 -265
  358. package/src/modules/update-check/__tests__/UpdateBanner.test.tsx +0 -126
  359. package/src/modules/update-check/components/UpdateBanner.tsx +0 -92
  360. package/src/modules/update-check/services/update-check.api.ts +0 -24
@@ -1,5 +1,5 @@
1
1
  import { useState, useCallback, useContext, useEffect, useMemo, useRef } from 'react';
2
- import { isProtectedBranch, type FileTreeEntry } from '@bevel-software/platform-shared';
2
+ import { DEFAULT_BRANCH, isProtectedBranch, type FileTreeEntry } from '@bevel-software/platform-shared';
3
3
  import { useEventBus, canonicalizeWorkspaceId } from '../../workflow/state/event-bus.context';
4
4
  import { AuthContext } from '../../auth/state/auth.context';
5
5
  import { fetchFileAccess } from '../../access/api';
@@ -10,12 +10,16 @@ import {
10
10
  } from '../../change-requests/services/propose.api';
11
11
  import { PR_STALE_EVENT, SUGGESTIONS_OPTIMISTIC_EVENT } from '../../../core/events';
12
12
  import type {
13
+ HydrateResult,
13
14
  OpenTab,
14
15
  PendingEntry,
15
16
  UploadError,
16
17
  UploadInput,
18
+ UploadNotice,
19
+ UploadTarget,
17
20
  WorkspaceContextValue,
18
21
  } from '../state/workspace.context';
22
+ import { KNOWLEDGE_UPLOAD_TARGET } from '../state/workspace.context';
19
23
  import {
20
24
  getOrCreateWorkspace,
21
25
  listFiles,
@@ -33,6 +37,7 @@ import {
33
37
  import { contentChanged } from '../utils/diff';
34
38
  import { isUploadNoise, walkEntries, type DroppedItem } from '../utils/readDroppedEntries';
35
39
  import { tabsKey, type PersistedTabState } from '../utils/tab-persistence';
40
+ import { traceFiles } from '../utils/file-trace';
36
41
 
37
42
  const PERSIST_DEBOUNCE_MS = 200;
38
43
  // Bounded concurrency cap for upload requests. The server serializes git
@@ -50,6 +55,22 @@ function basename(path: string): string {
50
55
  return i >= 0 ? path.slice(i + 1) : path;
51
56
  }
52
57
 
58
+ /**
59
+ * Which branch a workspace IS, read off the workspace itself rather than off
60
+ * whatever we happened to ask for. `WorkspaceInfo.id` is
61
+ * `encodeURIComponent(branch)` and documents the decode as the supported way
62
+ * to recover the branch without a round-trip — so the answer travels with the
63
+ * id, and the pair can never come apart mid-switch. `requested` is only the
64
+ * fallback for a malformed id.
65
+ */
66
+ function workspaceBranchOf(workspaceId: string, requested: string | undefined): string {
67
+ try {
68
+ return decodeURIComponent(workspaceId);
69
+ } catch {
70
+ return requested ?? DEFAULT_BRANCH;
71
+ }
72
+ }
73
+
53
74
  /**
54
75
  * Return a copy of the tree with the entry at `targetPath` (and any
55
76
  * descendants beneath it) removed. Used by `deleteEntry`'s optimistic
@@ -92,6 +113,76 @@ function collectPaths(root: FileTreeEntry): Set<string> {
92
113
  return out;
93
114
  }
94
115
 
116
+ /** The last segment of a workspace path — what the user calls the file. */
117
+ function fileNameOf(path: string): string {
118
+ const name = path.split('/').filter(Boolean).pop();
119
+ return name ?? path;
120
+ }
121
+
122
+ /**
123
+ * The upload's target is a folder the caller cannot read. Raised by the
124
+ * suggestion routing so the drop is refused up front, in the server's own
125
+ * words, instead of being carried to the suggestions branch where the same
126
+ * read-before-write gate would refuse every file one by one.
127
+ */
128
+ class UnreadableUploadTargetError extends Error {
129
+ readonly folder: string;
130
+ constructor(folder: string) {
131
+ super(
132
+ `You don't have read access to "${folder}"; only what you can read can be created, changed or removed.`,
133
+ );
134
+ this.name = 'UnreadableUploadTargetError';
135
+ this.folder = folder;
136
+ }
137
+ }
138
+
139
+ /**
140
+ * What the progress notice calls this drop: one file by name, several by
141
+ * count, and the folder it is going into. Read off the INPUT rather than the
142
+ * walk, because the walk has not started yet — saying something on the first
143
+ * tick is the whole point.
144
+ */
145
+ function describeUpload(input: UploadInput, targetDirectory: string): string {
146
+ const what = describeUploaded(input);
147
+ const where = targetDirectory ? fileNameOf(targetDirectory) : null;
148
+ return where ? `${what} to ${where}` : what;
149
+ }
150
+
151
+ /** The dropped things alone — one by name, several by count — for a banner that names them. */
152
+ function describeUploaded(input: UploadInput): string {
153
+ if (input.kind === 'files') {
154
+ return input.files.length === 1 ? input.files[0]!.name : `${input.files.length} files`;
155
+ }
156
+ if (input.kind === 'paths') {
157
+ return input.items.length === 1
158
+ ? fileNameOf(input.items[0]!.relativePath)
159
+ : `${input.items.length} files`;
160
+ }
161
+ return input.entries.length === 1
162
+ ? input.entries[0]!.name || 'the dropped item'
163
+ : `${input.entries.length} items`;
164
+ }
165
+
166
+ const EMPTY_ERRORS: ReadonlyMap<UploadTarget, UploadError> = new Map();
167
+ const EMPTY_NOTICES: ReadonlyMap<UploadTarget, UploadNotice> = new Map();
168
+
169
+ /**
170
+ * Set or remove one tree's upload banner, leaving every other tree's alone.
171
+ * Returns the map unchanged when there was nothing to remove, so a dispatch
172
+ * into a tree with no banner doesn't re-render the ones that have.
173
+ */
174
+ function withBanner<V>(
175
+ current: ReadonlyMap<UploadTarget, V>,
176
+ target: UploadTarget,
177
+ value: V | null,
178
+ ): ReadonlyMap<UploadTarget, V> {
179
+ if (value === null && !current.has(target)) return current;
180
+ const next = new Map(current);
181
+ if (value === null) next.delete(target);
182
+ else next.set(target, value);
183
+ return next;
184
+ }
185
+
95
186
  interface UseWorkspaceStateReturn extends WorkspaceContextValue {
96
187
  setPersistenceBranch: (branch: string | null) => void;
97
188
  deleteWorkspace: () => Promise<void>;
@@ -99,12 +190,33 @@ interface UseWorkspaceStateReturn extends WorkspaceContextValue {
99
190
 
100
191
  export function useWorkspaceState(): UseWorkspaceStateReturn {
101
192
  const [workspaceId, setWorkspaceId] = useState<string | null>(null);
193
+ /**
194
+ * The branch the CURRENT `workspaceId` actually is (see
195
+ * {@link workspaceBranchOf}). Not the same thing as `persistenceBranch`,
196
+ * which is the branch we've asked for and may still be bootstrapping. Every
197
+ * key that has to say "these tabs came from that branch" is built from this
198
+ * one, paired with the `workspaceId` of the same render, so a switch can
199
+ * never write one branch's tabs under another branch's name.
200
+ */
201
+ const [workspaceBranch, setWorkspaceBranch] = useState<string | null>(null);
202
+ const [bootstrapError, setBootstrapError] = useState<
203
+ { branch: string; status: number; message: string } | null
204
+ >(null);
205
+ // Bumped by `retryBootstrap`. A dependency of the bootstrap effect, so a
206
+ // retry re-runs it for the SAME persistenceBranch (which a plain state set
207
+ // would not, the value being unchanged).
208
+ const [bootstrapAttempt, setBootstrapAttempt] = useState(0);
102
209
  const [kbDirName, setKbDirName] = useState<string | null>(null);
103
210
  const [fileTree, setFileTree] = useState<FileTreeEntry | null>(null);
104
211
  const [openTabs, setOpenTabs] = useState<OpenTab[]>([]);
105
212
  const [activeTabPath, setActiveTabPath] = useState<string | null>(null);
106
- const [uploadError, setUploadError] = useState<UploadError | null>(null);
107
- const [uploadNotice, setUploadNotice] = useState<string | null>(null);
213
+ // Upload banners are per-TREE, not per-workspace: the Library sidebar shows
214
+ // two upload targets at once, and with a single slot each the second drop's
215
+ // notice replaced the first's — and the first upload to settle cleared the
216
+ // second's. Either way one of the two drops went silent, which is the whole
217
+ // failure this module exists to prevent. See `withBanner`.
218
+ const [uploadErrors, setUploadErrors] = useState<ReadonlyMap<UploadTarget, UploadError>>(EMPTY_ERRORS);
219
+ const [uploadNotices, setUploadNotices] = useState<ReadonlyMap<UploadTarget, UploadNotice>>(EMPTY_NOTICES);
108
220
  const [isUploading, setIsUploading] = useState(false);
109
221
  // Who is signed in — the suggestion-routed upload needs an author for the
110
222
  // branch name and the change request. Read nullable (not `useAuth`, which
@@ -119,6 +231,15 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
119
231
  // Monotonic token so a slow `addTab` whose response arrives after a newer add
120
232
  // doesn't clobber the newer state.
121
233
  const addRequestIdRef = useRef(0);
234
+ // A SECOND token, for hydrations only. "Which file should be active" and
235
+ // "which restore owns the tab strip" are different questions, and sharing one
236
+ // counter conflated them: an ordinary `addTab` starting mid-hydration made
237
+ // the hydration look superseded, so it dropped the branch's whole restored
238
+ // tab list on the floor AND left `hydratedKeyRef` unset, which silently
239
+ // disables persistence for that branch until the next switch. Only a NEWER
240
+ // hydration (or the workspace moving) may retire a hydration's claim on the
241
+ // strip; a newer open only outranks it for activation.
242
+ const hydrateRequestIdRef = useRef(0);
122
243
  // Tracks the (workspaceId, persistenceBranch) key we've successfully hydrated
123
244
  // for. Auto-persist effect won't write until hydrate has run for the current
124
245
  // key — avoids overwriting localStorage with `[]` before the restore lands.
@@ -141,11 +262,46 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
141
262
  // persistenceBranch as a ref too, so hydrateTabs reads the latest value
142
263
  // even when setPersistenceBranch was called in the same render.
143
264
  const persistenceBranchRef = useRef<string | null>(persistenceBranch);
265
+ /**
266
+ * The live `workspaceId`, for the reads that resolve AFTER the workspace
267
+ * moved on. A read started against branch A's workspace must not write its
268
+ * bytes into branch B's tab strip: every tab mutation below compares the
269
+ * workspaceId it was started with against this before touching state.
270
+ */
271
+ const workspaceIdRef = useRef<string | null>(workspaceId);
144
272
  useEffect(() => { openTabsRef.current = openTabs; }, [openTabs]);
145
273
  useEffect(() => { activeTabPathRef.current = activeTabPath; }, [activeTabPath]);
146
274
  useEffect(() => { fileTreeRef.current = fileTree; }, [fileTree]);
147
275
  useEffect(() => { persistenceBranchRef.current = persistenceBranch; }, [persistenceBranch]);
148
276
 
277
+ /**
278
+ * The one place `workspaceId` moves. The ref is advanced in the same tick as
279
+ * the state, not in an effect: child effects (FileRoute's hydrate) run before
280
+ * this component's own effects, so an effect-synced ref would still read the
281
+ * PREVIOUS workspace on the very render that introduced the new one.
282
+ */
283
+ const adoptWorkspace = useCallback((id: string, branch: string) => {
284
+ // A different workspace IS a different branch, and every open tab holds
285
+ // bytes read from the one being left. The strip starts empty for the new
286
+ // branch rather than waiting for its restore to replace it: a restore
287
+ // overtaken by a click MERGES into the strip instead of replacing it, and
288
+ // merged with a strip that still held the old branch's tabs it carried
289
+ // them over — shown on the new branch with the old branch's text, and
290
+ // persisted under the new branch's key. Refs move with the state for the
291
+ // same reason `workspaceIdRef` does: the reads resolving next consult
292
+ // them. Nothing typed is lost — a switch is refused while any tab is dirty
293
+ // (`FileRoute`), and `deleteWorkspace` closes every tab before it re-adopts.
294
+ if (workspaceIdRef.current !== null && workspaceIdRef.current !== id) {
295
+ openTabsRef.current = [];
296
+ activeTabPathRef.current = null;
297
+ setOpenTabs([]);
298
+ setActiveTabPath(null);
299
+ }
300
+ workspaceIdRef.current = id;
301
+ setWorkspaceId(id);
302
+ setWorkspaceBranch(branch);
303
+ }, []);
304
+
149
305
  const setPersistenceBranch = useCallback((branch: string | null) => {
150
306
  persistenceBranchRef.current = branch;
151
307
  setPersistenceBranchState(branch);
@@ -167,18 +323,53 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
167
323
  const branch = persistenceBranch ?? undefined;
168
324
  let cancelled = false;
169
325
  (async () => {
326
+ traceFiles('bootstrap:start', { branch: branch ?? null, attempt: bootstrapAttempt });
170
327
  try {
171
328
  const { workspace, fileTree: tree } = await getOrCreateWorkspace(branch);
329
+ traceFiles('bootstrap:ok', { branch: branch ?? null, workspaceId: workspace.id, cancelled });
172
330
  if (cancelled) return;
173
- setWorkspaceId(workspace.id);
331
+ adoptWorkspace(workspace.id, workspaceBranchOf(workspace.id, branch));
174
332
  setKbDirName(workspace.kbDirName);
175
333
  setFileTree(tree);
334
+ setBootstrapError(null);
176
335
  } catch (err) {
177
- if (!cancelled) console.error('Failed to bootstrap workspace:', err);
336
+ traceFiles('bootstrap:failed', {
337
+ branch: branch ?? null,
338
+ status: err instanceof WorkspaceApiError ? err.status : null,
339
+ message: err instanceof Error ? err.message : String(err),
340
+ cancelled,
341
+ });
342
+ if (cancelled) return;
343
+ console.error('Failed to bootstrap workspace:', err);
344
+ // Surfaced, not just logged: a bootstrap that fails leaves
345
+ // `workspaceId` where it was, and the route waiting on it needs to
346
+ // know why — a branch the host deleted (410) and a branch that never
347
+ // existed (404) each have their own screen, and every other status
348
+ // gets a named failure with a Retry. The message rides along so the
349
+ // screen can say what actually failed instead of only which branch
350
+ // it was.
351
+ // No persistence branch means the server bootstrapped the DEFAULT
352
+ // branch, so that is the branch this failure is about — an empty
353
+ // name would never match the URL a route is on.
354
+ setBootstrapError({
355
+ branch: branch ?? DEFAULT_BRANCH,
356
+ status: err instanceof WorkspaceApiError ? err.status : 0,
357
+ message: err instanceof Error ? err.message : String(err),
358
+ });
178
359
  }
179
360
  })();
180
361
  return () => { cancelled = true; };
181
- }, [persistenceBranch]);
362
+ }, [persistenceBranch, bootstrapAttempt, adoptWorkspace]);
363
+
364
+ /**
365
+ * Re-run the bootstrap for the branch we're already asking for. The one
366
+ * recovery from a failed `GET /api/workspace` that doesn't need a page
367
+ * reload — the Retry on the file page's bootstrap-failure screen calls it.
368
+ */
369
+ const retryBootstrap = useCallback(() => {
370
+ setBootstrapError(null);
371
+ setBootstrapAttempt((n) => n + 1);
372
+ }, []);
182
373
 
183
374
  const refreshFileTree = useCallback(async () => {
184
375
  if (!workspaceId) return null;
@@ -221,11 +412,19 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
221
412
  // null-content guard renders an empty/loading state until content arrives.
222
413
  if (tab.content === null && workspaceId) {
223
414
  const path = tab.path;
224
- readFile(workspaceId, path).then((content) => {
415
+ // The same guard the eager refetch and `addTab` carry: a switch while
416
+ // this read is in flight clears the strip, and a tab of the SAME path
417
+ // may already be open on the new branch. Its answer — bytes, a 404 or a
418
+ // 403 — is about the branch that was left, so it must neither overwrite
419
+ // that tab nor close it.
420
+ const readFrom = workspaceId;
421
+ readFile(readFrom, path).then((content) => {
422
+ if (workspaceIdRef.current !== readFrom) return;
225
423
  setOpenTabs((prev) => prev.map((t) => (
226
424
  t.path === path ? { ...t, content, savedContent: content } : t
227
425
  )));
228
426
  }).catch((err) => {
427
+ if (workspaceIdRef.current !== readFrom) return;
229
428
  if (
230
429
  err instanceof WorkspaceApiError &&
231
430
  (err.status === 404 || err.status === 403)
@@ -245,12 +444,25 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
245
444
  // on dirty state — opening more tabs never discards work.
246
445
  const existing = openTabsRef.current.find((t) => t.path === relativePath);
247
446
  if (existing) {
447
+ // Claim the "latest open" token even though there is nothing to fetch.
448
+ // Without it, an OLDER addTab still in flight counted as the latest when
449
+ // it landed and activated ITS file — so a burst of tree clicks ending on
450
+ // an already-open tab left the screen on some other file while the URL
451
+ // named this one, for good. Opening a tab is the newest intent whether or
452
+ // not it costs a read.
453
+ ++addRequestIdRef.current;
248
454
  activateTab(existing);
249
455
  return true;
250
456
  }
251
457
  const requestId = ++addRequestIdRef.current;
252
458
  try {
253
459
  const content = await readFile(workspaceId, relativePath);
460
+ // A read that outlived its workspace belongs to another branch's tab
461
+ // strip; drop it rather than splicing those bytes into this one.
462
+ if (workspaceIdRef.current !== workspaceId) {
463
+ traceFiles('add-tab:stale-workspace', { path: relativePath, readFrom: workspaceId, now: workspaceIdRef.current });
464
+ return false;
465
+ }
254
466
  const isLatest = requestId === addRequestIdRef.current;
255
467
  // Re-check dedup in case of races during the await.
256
468
  const stillExisting = openTabsRef.current.find((t) => t.path === relativePath);
@@ -276,7 +488,9 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
276
488
  return true;
277
489
  } catch (err) {
278
490
  // Drop stale errors silently — the user already navigated to a newer
279
- // tab, surfacing the older error would be confusing.
491
+ // tab, or the workspace moved to another branch; surfacing the older
492
+ // error would be confusing.
493
+ if (workspaceIdRef.current !== workspaceId) return false;
280
494
  if (requestId !== addRequestIdRef.current) return false;
281
495
  // A 403 (read-restricted deep-link / id-link) throws like any other
282
496
  // failure: NO tab is created for a file the user can't read — the route
@@ -331,18 +545,35 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
331
545
  const hydrateTabs = useCallback(async (
332
546
  paths: string[],
333
547
  activePath: string | null,
334
- ): Promise<{ surviving: string[]; dropped: string[]; denied: string[] }> => {
335
- if (!workspaceId) return { surviving: [], dropped: paths.slice(), denied: [] };
548
+ ): Promise<HydrateResult> => {
549
+ // No workspace, nothing read, nothing owned: `superseded` so the caller
550
+ // doesn't record a restore that never happened.
551
+ if (!workspaceId) {
552
+ return { surviving: [], dropped: paths.slice(), denied: [], superseded: true };
553
+ }
554
+ // The key these tabs belong to, pinned from THIS render's (workspaceId,
555
+ // workspaceBranch) pair — the two always move together, so the key can
556
+ // never cross one branch's workspace with another branch's name. It used
557
+ // to be built from `persistenceBranchRef` at settle time, which is the
558
+ // branch being switched TO, and that is exactly how a key like
559
+ // `bevel.tabs.main.someone/draft` got written mid-switch.
560
+ const hydratedKey = workspaceBranch ? `${workspaceId}.${workspaceBranch}` : null;
336
561
  // Deduplicate while preserving order.
337
562
  const uniqPaths = paths.filter((p, i) => paths.indexOf(p) === i);
338
563
 
564
+ // Two claims, two tokens. `addRequestIdRef` says "this is the newest thing
565
+ // the user asked to have ACTIVE" — a hydration and an open compete for
566
+ // that, and whichever started last wins when they settle out of order.
567
+ // `hydrateRequestIdRef` says "this restore owns the tab strip", which only
568
+ // another restore can take away.
569
+ const requestId = ++addRequestIdRef.current;
570
+ const hydrateId = ++hydrateRequestIdRef.current;
571
+
339
572
  if (uniqPaths.length === 0) {
340
573
  setOpenTabs([]);
341
574
  setActiveTabPath(null);
342
- hydratedKeyRef.current = persistenceBranchRef.current
343
- ? `${workspaceId}.${persistenceBranchRef.current}`
344
- : null;
345
- return { surviving: [], dropped: [], denied: [] };
575
+ hydratedKeyRef.current = hydratedKey;
576
+ return { surviving: [], dropped: [], denied: [], superseded: false };
346
577
  }
347
578
 
348
579
  // Fetch every path in parallel. 404s are silently dropped (file no longer
@@ -352,6 +583,16 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
352
583
  // access message instead of "file not found". Other errors throw so the
353
584
  // caller can show "file-load-failed".
354
585
  const results = await Promise.allSettled(uniqPaths.map((p) => readFile(workspaceId, p)));
586
+ // The strip is no longer this hydration's to write: the workspace moved to
587
+ // another branch, or a newer restore started while these reads were in
588
+ // flight. Report what we read so the caller can still classify its
589
+ // deeplink, but touch nothing — and tell the caller, so it doesn't record
590
+ // a hydration that never landed.
591
+ const superseded =
592
+ workspaceIdRef.current !== workspaceId || hydrateId !== hydrateRequestIdRef.current;
593
+ // A newer `addTab` started meanwhile. It owns the ACTIVE tab, not the
594
+ // strip: its file still has to sit alongside the restored ones.
595
+ const outranked = requestId !== addRequestIdRef.current;
355
596
  const survivors: OpenTab[] = [];
356
597
  const surviving: string[] = [];
357
598
  const dropped: string[] = [];
@@ -382,17 +623,36 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
382
623
  }
383
624
  }
384
625
 
626
+ if (superseded) {
627
+ traceFiles('hydrate:superseded', { readFrom: workspaceId, now: workspaceIdRef.current, surviving });
628
+ return { surviving, dropped, denied, superseded: true };
629
+ }
630
+
631
+ if (outranked) {
632
+ // Merge instead of replace: the newer open's tab stays (it may not even
633
+ // be in `prev` yet — `addTab` appends with its own race-safe setter, so
634
+ // it lands on top of this list), and the restored tabs join it in their
635
+ // persisted order. Activation is left alone; the newer open is the
636
+ // user's latest intent and has already claimed it.
637
+ traceFiles('hydrate:outranked-by-open', { readFrom: workspaceId, surviving });
638
+ const restored = new Set(surviving);
639
+ setOpenTabs((prev) => [...survivors, ...prev.filter((t) => !restored.has(t.path))]);
640
+ // Still a completed restore for this key: the strip now holds this
641
+ // branch's tabs, so persistence may resume. Leaving the marker unset was
642
+ // what stopped this branch's tabs from ever being written again.
643
+ hydratedKeyRef.current = hydratedKey;
644
+ return { surviving, dropped, denied, superseded: false };
645
+ }
646
+
385
647
  setOpenTabs(survivors);
386
648
  // Activate `activePath` if it survived; else last surviving path; else null.
387
649
  const requested = activePath && survivors.some((t) => t.path === activePath)
388
650
  ? activePath
389
651
  : (survivors[survivors.length - 1]?.path ?? null);
390
652
  setActiveTabPath(requested);
391
- hydratedKeyRef.current = persistenceBranchRef.current
392
- ? `${workspaceId}.${persistenceBranchRef.current}`
393
- : null;
394
- return { surviving, dropped, denied };
395
- }, [workspaceId]);
653
+ hydratedKeyRef.current = hydratedKey;
654
+ return { surviving, dropped, denied, superseded: false };
655
+ }, [workspaceId, workspaceBranch]);
396
656
 
397
657
  // ── Renderer value bridge → active tab.content ────────────────────────────
398
658
 
@@ -472,8 +732,24 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
472
732
  bumpFs();
473
733
  }, [workspaceId, refreshFileTree, bumpFs]);
474
734
 
475
- const clearUploadError = useCallback(() => setUploadError(null), []);
476
- const clearUploadNotice = useCallback(() => setUploadNotice(null), []);
735
+ const clearUploadError = useCallback(
736
+ (target: UploadTarget) => setUploadErrors((current) => withBanner(current, target, null)),
737
+ [],
738
+ );
739
+ const clearUploadNotice = useCallback(
740
+ (target: UploadTarget) => setUploadNotices((current) => withBanner(current, target, null)),
741
+ [],
742
+ );
743
+ /**
744
+ * Retire a tree's "this is happening" notice without touching a RESULT that
745
+ * has already replaced it — a suggestion notice stays until the user
746
+ * dismisses it.
747
+ */
748
+ const clearProgressNotice = useCallback((target: UploadTarget) => {
749
+ setUploadNotices((current) => (
750
+ current.get(target)?.kind === 'progress' ? withBanner(current, target, null) : current
751
+ ));
752
+ }, []);
477
753
 
478
754
  // Pending overlay: files/dirs the user dropped but whose server commits
479
755
  // haven't echoed back yet. The ref holds the mutable working set the
@@ -521,6 +797,15 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
521
797
  * free-for-all, and paths outside the KB are the user's own workspace.
522
798
  * (The branch is recovered from the workspace id, which is the encoded
523
799
  * branch name for every branch workspace.)
800
+ *
801
+ * A folder the caller cannot READ is not routed anywhere: it throws
802
+ * `UnreadableUploadTargetError`, and the drop is refused up front. The
803
+ * server's read-before-write gate would refuse the same files on the
804
+ * suggestions branch, one by one, after provisioning it. Only a definite
805
+ * "no" refuses — an answer without the field falls through to the server,
806
+ * as an unanswerable question does. A folder directly under a root is left
807
+ * to the server too: a folder drop there starts a new folder, which is the
808
+ * one place the gate lets a person who cannot read the root create.
524
809
  */
525
810
  const resolveSuggestionRouting = useCallback(
526
811
  async (targetDirectory: string): Promise<KnowledgeSuggestionTarget | null> => {
@@ -531,6 +816,9 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
531
816
  const repoRelative = targetDirectory.slice(prefix.length);
532
817
  if (!repoRelative) return null;
533
818
  const access = await fetchFileAccess(workspaceId, repoRelative);
819
+ if (access.canRead === false && repoRelative.includes('/')) {
820
+ throw new UnreadableUploadTargetError(repoRelative);
821
+ }
534
822
  if (access.canWrite) return null;
535
823
  return ensureKnowledgeSuggestionWorkspace(authUser);
536
824
  },
@@ -538,9 +826,49 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
538
826
  );
539
827
 
540
828
  const activeUploadsRef = useRef(0);
541
- const dispatchUpload = useCallback(async (input: UploadInput, targetDirectory: string) => {
829
+ // How many dispatches are still running INTO EACH TREE. A progress notice
830
+ // belongs to its tree, not to the dispatch that raised it: the one that
831
+ // settles first must not pull the notice out from under a sibling drop into
832
+ // the same tree that is still waiting on its routing round-trip.
833
+ const activeUploadsByTargetRef = useRef(new Map<UploadTarget, number>());
834
+ const dispatchUpload = useCallback(async (
835
+ input: UploadInput,
836
+ targetDirectory: string,
837
+ uploadTarget: UploadTarget = KNOWLEDGE_UPLOAD_TARGET,
838
+ ) => {
542
839
  if (!workspaceId) return;
543
840
 
841
+ // Pin the workspace at dispatch time. A folder upload can take seconds;
842
+ // if the user switches branches mid-flight, the trailing state
843
+ // mutations (setUploadErrors / setIsUploading / setFileTree via
844
+ // refreshFileTree / clearPendingMatching) would clobber the new
845
+ // branch's UI with old-branch results. `isCurrent()` gates every
846
+ // post-await mutation; the workspaceId reset effect above already
847
+ // clears the optimistic refs the moment the switch happens.
848
+ const dispatchWorkspaceId = workspaceId;
849
+ const isCurrent = () => workspaceIdRef.current === dispatchWorkspaceId;
850
+
851
+ // ── Say something on the FIRST tick ──
852
+ // Everything below this point can take seconds, and the first
853
+ // suggestion-routed upload of a session takes the longest of all: the ACL
854
+ // read, then a branch created on the server and a workspace cloned for
855
+ // it, then the change request opened. None of that draws a row — a
856
+ // suggestion-routed upload deliberately has no optimistic overlay — so
857
+ // until this notice existed the user dropped a file and watched nothing
858
+ // whatsoever happen, which is indistinguishable from a dead drop target.
859
+ // The SECOND upload finds the branch, the workspace and the request all
860
+ // there and answers at once, which is why the report was "the first
861
+ // showed nothing, the second showed the notice".
862
+ setUploadErrors((current) => withBanner(current, uploadTarget, null));
863
+ setUploadNotices((current) => withBanner(current, uploadTarget, {
864
+ kind: 'progress',
865
+ message: `Adding ${describeUpload(input, targetDirectory)}…`,
866
+ }));
867
+ activeUploadsRef.current += 1;
868
+ const activeHere = activeUploadsByTargetRef.current;
869
+ activeHere.set(uploadTarget, (activeHere.get(uploadTarget) ?? 0) + 1);
870
+ setIsUploading(true);
871
+
544
872
  // ── Suggestion routing ──
545
873
  // An upload into a KB folder the caller may NOT write neither fails nor
546
874
  // forces its way in: it lands on their personal suggestions branch and
@@ -550,10 +878,24 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
550
878
  // upload normally: the backend's write gate stays the authority and
551
879
  // refuses with its own words.
552
880
  let suggestion: KnowledgeSuggestionTarget | null = null;
881
+ // A target the caller cannot read: refused below, before any byte moves,
882
+ // with the server's own sentence in the banner.
883
+ let unreadableTarget: UnreadableUploadTargetError | null = null;
553
884
  try {
554
885
  suggestion = await resolveSuggestionRouting(targetDirectory);
555
886
  } catch (err) {
556
- console.warn('[workspace] suggestion routing check failed:', err);
887
+ if (err instanceof UnreadableUploadTargetError) unreadableTarget = err;
888
+ else console.warn('[workspace] suggestion routing check failed:', err);
889
+ }
890
+ // An ordinary upload says what it is doing with ROWS — the optimistic
891
+ // overlay below puts them in the tree within the frame. The progress
892
+ // notice was only covering the wait for this answer, so it goes now
893
+ // rather than flashing over the rows for the length of the upload.
894
+ // Only when this is the only drop this tree is waiting on: a sibling
895
+ // upload into the same tree may still be mid-routing, and its progress
896
+ // notice is the only thing it has to show.
897
+ if (!suggestion && isCurrent() && (activeHere.get(uploadTarget) ?? 0) <= 1) {
898
+ clearProgressNotice(uploadTarget);
557
899
  }
558
900
  const uploadWorkspaceId = suggestion?.workspaceId ?? workspaceId;
559
901
  // No optimistic tree overlay for a suggestion-routed upload: the files
@@ -564,20 +906,6 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
564
906
  const suggestionPrefix = suggestion ? `${suggestion.kbDirName}/` : null;
565
907
  /** Repo-relative paths of the files that LANDED on the suggestions branch. */
566
908
  const suggestedRepoPaths: string[] = [];
567
- // Pin the workspace at dispatch time. A folder upload can take seconds;
568
- // if the user switches branches mid-flight, the trailing state
569
- // mutations (setUploadError / setIsUploading / setFileTree via
570
- // refreshFileTree / clearPendingMatching) would clobber the new
571
- // branch's UI with old-branch results. `isCurrent()` gates every
572
- // post-await mutation; the workspaceId reset effect above already
573
- // clears the optimistic refs the moment the switch happens.
574
- const dispatchWorkspaceId = workspaceId;
575
- const isCurrent = () => workspaceIdRef.current === dispatchWorkspaceId;
576
-
577
- setUploadError(null);
578
- setUploadNotice(null);
579
- activeUploadsRef.current += 1;
580
- setIsUploading(true);
581
909
 
582
910
  // Batch mode collapses N per-file pushes into one end-of-burst push
583
911
  // via `POST /flush` — mirrors the recursive folder-delete batch.
@@ -607,7 +935,7 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
607
935
  let uploaded = 0;
608
936
  let total: number | null = null;
609
937
  let abort = false;
610
- let firstError: { filename: string; reason: string } | null = null;
938
+ let firstError: UploadError | null = null;
611
939
  // Tracks whether any deferred `createDirectory` (empty-dir preservation)
612
940
  // commits landed. Without this, a folder drop containing only empty
613
941
  // subdirectories would skip `flushBatch` (`uploaded === 0`) and leave
@@ -621,7 +949,14 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
621
949
  const recordError = (filename: string, err: unknown) => {
622
950
  if (firstError) return;
623
951
  const reason = err instanceof Error ? err.message : 'Upload failed';
624
- firstError = { filename, reason };
952
+ // The status, not the wording, decides what we tell the user to do
953
+ // next: the backend is free to rephrase "you can't write here" without
954
+ // the banner quietly starting to give the wrong advice.
955
+ const status = err instanceof WorkspaceApiError ? err.status : undefined;
956
+ // The NAME, not the workspace path: the banner's first line is what the
957
+ // user dropped. A path is what produced "Couldn't add knowledge-base/K…"
958
+ // — a line so long the reason behind it never fitted on screen.
959
+ firstError = { filename: fileNameOf(filename), reason, status };
625
960
  abort = true;
626
961
  };
627
962
 
@@ -699,6 +1034,14 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
699
1034
  };
700
1035
 
701
1036
  try {
1037
+ // Refused before any byte moves: the banner carries the server's own
1038
+ // sentence and the 403 its gate would have answered, so the next-step
1039
+ // advice is the same one a refused single file gets. The `finally`
1040
+ // below shows it and settles the counters.
1041
+ if (unreadableTarget) {
1042
+ firstError = { filename: describeUploaded(input), reason: unreadableTarget.message, status: 403 };
1043
+ return;
1044
+ }
702
1045
  if (input.kind === 'files') {
703
1046
  const files = input.files.filter((f) => !isUploadNoise(f.name));
704
1047
  total = files.length;
@@ -790,10 +1133,17 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
790
1133
  }
791
1134
  window.dispatchEvent(new Event(PR_STALE_EVENT));
792
1135
  if (isCurrent()) {
793
- setUploadNotice(
794
- "You can't write to that folder, so the upload became a suggestion: " +
795
- 'it is now a change request for the folder’s owners to review.',
796
- );
1136
+ setUploadNotices((current) => withBanner(current, uploadTarget, {
1137
+ kind: 'suggestion',
1138
+ message:
1139
+ "You can't write to that folder, so the upload became a suggestion: " +
1140
+ 'it is now a change request for the folder’s owners to review. ' +
1141
+ // Where the undo is. Without this sentence the notice says a
1142
+ // thing happened and nothing about reversing it, and the
1143
+ // accent-coloured row it produces says nothing either — which
1144
+ // is how an accidental upload came to read as permanent.
1145
+ 'To take it back, right-click the file and choose Withdraw suggestion.',
1146
+ }));
797
1147
  }
798
1148
  } catch (err) {
799
1149
  recordError('change request', err);
@@ -811,9 +1161,12 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
811
1161
  // they already left. The workspace-change effect already reset the
812
1162
  // optimistic overlays.
813
1163
  activeUploadsRef.current = Math.max(0, activeUploadsRef.current - 1);
1164
+ const remainingHere = Math.max(0, (activeHere.get(uploadTarget) ?? 1) - 1);
1165
+ if (remainingHere === 0) activeHere.delete(uploadTarget);
1166
+ else activeHere.set(uploadTarget, remainingHere);
814
1167
  if (isCurrent()) {
815
1168
  if (firstError) {
816
- setUploadError(firstError);
1169
+ setUploadErrors((current) => withBanner(current, uploadTarget, firstError));
817
1170
  // Drop any pending overlay entries that didn't make it — files
818
1171
  // we already uploaded successfully are removed inside uploadOne.
819
1172
  clearPendingMatching(() => true);
@@ -822,6 +1175,11 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
822
1175
  const stillRunning = activeUploadsRef.current > 0;
823
1176
  setIsUploading(stillRunning);
824
1177
  if (!stillRunning) setUploadProgress(null);
1178
+ // A progress notice has nothing left to report once this tree has no
1179
+ // upload in flight, and one left behind would sit there forever. The
1180
+ // suggestion notice is a RESULT, and stays until dismissed. Scoped to
1181
+ // THIS tree so a drop settling in one never blanks another's news.
1182
+ if (remainingHere === 0) clearProgressNotice(uploadTarget);
825
1183
 
826
1184
  // One final refresh to reconcile the server tree with whatever
827
1185
  // committed, then clear pending overlay entries whose real
@@ -845,7 +1203,7 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
845
1203
  }, [
846
1204
  workspaceId, refreshFileTree, bumpFs,
847
1205
  addPending, removePending, clearPendingMatching,
848
- resolveSuggestionRouting, authUser,
1206
+ resolveSuggestionRouting, authUser, clearProgressNotice,
849
1207
  ]);
850
1208
 
851
1209
  const deleteEntry = useCallback(async (relativePath: string) => {
@@ -870,7 +1228,7 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
870
1228
  const dirty = toClose.filter((t) => t.isDirty);
871
1229
  if (dirty.length > 0) {
872
1230
  const confirmed = window.confirm(UNSAVED_TABS_BULK_WARNING(dirty.map((t) => basename(t.path))));
873
- if (!confirmed) return;
1231
+ if (!confirmed) return false;
874
1232
  }
875
1233
  // Optimistic tree removal. A folder delete on the server takes 2-3s
876
1234
  // (N per-file commits batched into one push) — without optimism the
@@ -1123,22 +1481,27 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
1123
1481
  // When the user switches branches, the previously-hydrated key no longer
1124
1482
  // applies. Clear the marker so the auto-persist effect waits for a fresh
1125
1483
  // `hydrateTabs` call before writing localStorage for the new branch.
1484
+ //
1485
+ // Keyed on `workspaceBranch` — the branch the workspace IS — not on
1486
+ // `persistenceBranch`, the branch we're heading for. The two differ for the
1487
+ // whole length of a switch, and keying on the destination is what let the
1488
+ // old branch's tabs be persisted under the new branch's name.
1126
1489
  useEffect(() => {
1127
- if (!workspaceId || !persistenceBranch) {
1490
+ if (!workspaceId || !workspaceBranch) {
1128
1491
  hydratedKeyRef.current = null;
1129
1492
  return;
1130
1493
  }
1131
- const key = `${workspaceId}.${persistenceBranch}`;
1494
+ const key = `${workspaceId}.${workspaceBranch}`;
1132
1495
  if (hydratedKeyRef.current !== key) {
1133
1496
  hydratedKeyRef.current = null;
1134
1497
  }
1135
- }, [workspaceId, persistenceBranch]);
1498
+ }, [workspaceId, workspaceBranch]);
1136
1499
 
1137
1500
  // ── Auto-persist tabs to localStorage (debounced) ─────────────────────────
1138
1501
 
1139
1502
  useEffect(() => {
1140
- if (!workspaceId || !persistenceBranch) return;
1141
- const key = `${workspaceId}.${persistenceBranch}`;
1503
+ if (!workspaceId || !workspaceBranch) return;
1504
+ const key = `${workspaceId}.${workspaceBranch}`;
1142
1505
  if (hydratedKeyRef.current !== key) return;
1143
1506
 
1144
1507
  const handle = window.setTimeout(() => {
@@ -1147,13 +1510,13 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
1147
1510
  paths: openTabs.map((t) => t.path),
1148
1511
  activePath: activeTabPath,
1149
1512
  };
1150
- localStorage.setItem(tabsKey(workspaceId, persistenceBranch), JSON.stringify(payload));
1513
+ localStorage.setItem(tabsKey(workspaceId, workspaceBranch), JSON.stringify(payload));
1151
1514
  } catch (err) {
1152
1515
  console.warn('Failed to persist tabs:', err);
1153
1516
  }
1154
1517
  }, PERSIST_DEBOUNCE_MS);
1155
1518
  return () => window.clearTimeout(handle);
1156
- }, [openTabs, activeTabPath, workspaceId, persistenceBranch]);
1519
+ }, [openTabs, activeTabPath, workspaceId, workspaceBranch]);
1157
1520
 
1158
1521
  const deleteWorkspace = useCallback(async () => {
1159
1522
  if (!workspaceId) return;
@@ -1166,13 +1529,13 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
1166
1529
  // swaps the user onto a different branch after a delete.
1167
1530
  const branch = persistenceBranchRef.current ?? undefined;
1168
1531
  const { workspace, fileTree: tree } = await getOrCreateWorkspace(branch);
1169
- setWorkspaceId(workspace.id);
1532
+ adoptWorkspace(workspace.id, workspaceBranchOf(workspace.id, branch));
1170
1533
  setKbDirName(workspace.kbDirName);
1171
1534
  setFileTree(tree);
1172
1535
  } catch (err) {
1173
1536
  console.error('Failed to delete workspace:', err);
1174
1537
  }
1175
- }, [workspaceId, closeAllTabs]);
1538
+ }, [workspaceId, closeAllTabs, adoptWorkspace]);
1176
1539
 
1177
1540
  // ── Live updates: react to other users' / agent's edits ───────────────────
1178
1541
  //
@@ -1201,13 +1564,11 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
1201
1564
  // The bus only delivers workspace-scoped events for the currently
1202
1565
  // focused workspace (set by `EventBusFocusBinder`), so the workspace
1203
1566
  // filter on the handler is belt-and-braces.
1204
- // Track the current workspaceId in a ref so the async readFile handler
1205
- // below can detect a workspace switch that happened after it was
1206
- // subscribed but before its fetch resolved — otherwise a stale resolve
1207
- // would call `setOpenTabs` on the new workspace's tabs, replacing the
1208
- // wrong file's content with bytes from the old branch.
1209
- const workspaceIdRef = useRef<string | null>(workspaceId);
1210
- useEffect(() => { workspaceIdRef.current = workspaceId; }, [workspaceId]);
1567
+ // The async readFile handler below detects a workspace switch that happened
1568
+ // after it was subscribed but before its fetch resolved via `workspaceIdRef`
1569
+ // (declared with the other refs above, advanced by `adoptWorkspace`) —
1570
+ // otherwise a stale resolve would call `setOpenTabs` on the new workspace's
1571
+ // tabs, replacing the wrong file's content with bytes from the old branch.
1211
1572
 
1212
1573
  // Reset the optimistic-overlay state on workspace switch. Without this,
1213
1574
  // pending entries from a partly-uploaded folder on branch A linger in
@@ -1222,6 +1583,14 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
1222
1583
  pendingDeletePathsRef.current = new Set();
1223
1584
  // eslint-disable-next-line react-hooks/set-state-in-effect
1224
1585
  setPendingUploads(new Map());
1586
+ // The banners go with them. An upload still routing when the user
1587
+ // switches workspaces skips its own cleanup (`isCurrent()` is false by
1588
+ // the time it settles, and rightly so — its result belongs to the branch
1589
+ // it was dispatched from), so its "Adding …" notice would otherwise sit
1590
+ // over the new tree forever, describing a drop into a branch the user has
1591
+ // left. Same for an error banner about a file in the old branch.
1592
+ setUploadNotices(EMPTY_NOTICES);
1593
+ setUploadErrors(EMPTY_ERRORS);
1225
1594
  }, [workspaceId]);
1226
1595
 
1227
1596
  const bus = useEventBus();
@@ -1371,6 +1740,9 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
1371
1740
  workspaceId,
1372
1741
  kbDirName,
1373
1742
  fileTree,
1743
+ bootstrapError,
1744
+ workspaceBranch,
1745
+ retryBootstrap,
1374
1746
  openTabs,
1375
1747
  activeTab,
1376
1748
  dirtyTabFilenames,
@@ -1382,8 +1754,8 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
1382
1754
  setHasUnsavedFileChanges,
1383
1755
  setActiveTabContent,
1384
1756
  fsRevision,
1385
- uploadError,
1386
- uploadNotice,
1757
+ uploadErrors,
1758
+ uploadNotices,
1387
1759
  clearUploadNotice,
1388
1760
  isUploading,
1389
1761
  uploadProgress,
@@ -1412,9 +1784,9 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
1412
1784
  setPersistenceBranch,
1413
1785
  deleteWorkspace,
1414
1786
  }), [
1415
- workspaceId, kbDirName, fileTree, openTabs, activeTab, dirtyTabFilenames,
1787
+ workspaceId, kbDirName, fileTree, bootstrapError, workspaceBranch, retryBootstrap, openTabs, activeTab, dirtyTabFilenames,
1416
1788
  openFilePath, openFileContent, openFileSavedContent, hasUnsavedFileChanges, pendingFileContent,
1417
- setHasUnsavedFileChanges, setActiveTabContent, fsRevision, uploadError, uploadNotice, clearUploadNotice, isUploading, uploadProgress, pendingUploads, refreshFileTree, bumpFs,
1789
+ setHasUnsavedFileChanges, setActiveTabContent, fsRevision, uploadErrors, uploadNotices, clearUploadNotice, isUploading, uploadProgress, pendingUploads, refreshFileTree, bumpFs,
1418
1790
  addTab, closeTab, activateTab, reorderTab, closeAllTabs, hydrateTabs,
1419
1791
  createFile, createDirectory, unzipHere, uploadFiles, dispatchUpload, clearUploadError,
1420
1792
  deleteEntry, moveEntry, saveFile, reloadTabFromDisk,