@bevel-software/platform-core-frontend 0.15.1 → 0.20.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 (347) hide show
  1. package/THIRD-PARTY-NOTICES.md +2 -2
  2. package/package.json +3 -3
  3. package/src/core/CoreAppShell.tsx +20 -9
  4. package/src/core/__tests__/AppChrome.test.tsx +0 -3
  5. package/src/core/__tests__/events.test.ts +43 -0
  6. package/src/core/bootstrap.ts +11 -3
  7. package/src/core/events.ts +85 -3
  8. package/src/core/registry.ts +1 -1
  9. package/src/lib/__tests__/email.test.ts +44 -0
  10. package/src/lib/email.ts +37 -1
  11. package/src/modules/access/__tests__/ManageAccessDialog.add-row-picking.test.tsx +141 -0
  12. package/src/modules/access/__tests__/ManageAccessDialog.chip-truncation.test.tsx +204 -0
  13. package/src/modules/access/__tests__/ManageAccessDialog.download-read.test.tsx +234 -0
  14. package/src/modules/access/__tests__/ManageAccessDialog.edited-row-visible.test.tsx +160 -0
  15. package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +2 -2
  16. package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +166 -0
  17. package/src/modules/access/__tests__/ManageAccessDialog.restrict.test.tsx +510 -0
  18. package/src/modules/access/__tests__/ManageAccessDialog.row-menu-axes.test.tsx +299 -0
  19. package/src/modules/access/__tests__/ManageAccessDialog.row-menu-width.test.tsx +226 -0
  20. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +721 -126
  21. package/src/modules/access/__tests__/ManageAccessDialog.unknown-email.test.tsx +314 -0
  22. package/src/modules/access/__tests__/manage-access-affordance.test.ts +14 -0
  23. package/src/modules/access/__tests__/tailwindDeclarations.ts +210 -0
  24. package/src/modules/access/api.ts +140 -6
  25. package/src/modules/access/components/ManageAccessDialog.tsx +1299 -561
  26. package/src/modules/access/manage-access-affordance.ts +17 -0
  27. package/src/modules/admin/__tests__/AddMemberInput.test.tsx +297 -0
  28. package/src/modules/admin/__tests__/AdminRolesPage.capabilities.test.tsx +2 -2
  29. package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +189 -0
  30. package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +1 -1
  31. package/src/modules/admin/__tests__/DirectoryGroupsPage.suggest.test.tsx +182 -0
  32. package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +165 -14
  33. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +401 -4
  34. package/src/modules/admin/__tests__/group-members-path.test.ts +27 -0
  35. package/src/modules/admin/components/AddMemberInput.tsx +268 -0
  36. package/src/modules/admin/components/AdminRolesPage.tsx +97 -132
  37. package/src/modules/admin/components/DirectoryGroupsPage.tsx +91 -39
  38. package/src/modules/admin/components/UserAccountsPage.tsx +271 -37
  39. package/src/modules/admin/components/group-members-path.ts +32 -0
  40. package/src/modules/admin/services/roles.api.ts +12 -1
  41. package/src/modules/audit/__tests__/AuditLogPage.test.tsx +312 -0
  42. package/src/modules/audit/components/AuditEventsPanel.tsx +319 -0
  43. package/src/modules/audit/components/AuditLogPage.tsx +373 -0
  44. package/src/modules/audit/components/principal-grouping.ts +49 -0
  45. package/src/modules/audit/services/audit.api.ts +98 -0
  46. package/src/modules/auth/__tests__/AccountPage.test.tsx +50 -2
  47. package/src/modules/auth/components/AccountPage.tsx +73 -54
  48. package/src/modules/auth/components/LoginScreen.tsx +1 -0
  49. package/src/modules/auth/services/account.api.ts +78 -4
  50. package/src/modules/change-requests/__tests__/ChangeRequestDialog.access-rules.test.tsx +144 -0
  51. package/src/modules/change-requests/__tests__/ChangeRequestDialog.binary.test.tsx +422 -0
  52. package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +431 -0
  53. package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +193 -0
  54. package/src/modules/change-requests/__tests__/ChangeRequestDialog.initial-file.test.tsx +142 -0
  55. package/src/modules/change-requests/__tests__/ChangeRequestDialog.moved.test.tsx +202 -0
  56. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +205 -13
  57. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +271 -0
  58. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +208 -0
  59. package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +286 -0
  60. package/src/modules/change-requests/__tests__/propose.concurrent.test.ts +273 -0
  61. package/src/modules/change-requests/__tests__/readFailure.test.ts +122 -0
  62. package/src/modules/change-requests/__tests__/useCrFileDiffs.test.tsx +238 -0
  63. package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +56 -1
  64. package/src/modules/change-requests/__tests__/useForkPointFile.test.tsx +79 -0
  65. package/src/modules/change-requests/components/BranchFilePreview.tsx +357 -0
  66. package/src/modules/change-requests/components/ChangeBox.tsx +31 -2
  67. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +862 -72
  68. package/src/modules/change-requests/components/CrFileTree.tsx +74 -58
  69. package/src/modules/change-requests/components/FileChangeBoxes.tsx +19 -15
  70. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +41 -7
  71. package/src/modules/change-requests/hooks/useCrFileDiffs.ts +181 -23
  72. package/src/modules/change-requests/hooks/useFileOnBranch.ts +70 -7
  73. package/src/modules/change-requests/hooks/useForkPointFile.ts +77 -0
  74. package/src/modules/change-requests/services/change-requests.api.ts +57 -1
  75. package/src/modules/change-requests/services/denied-file.api.ts +53 -0
  76. package/src/modules/change-requests/services/propose.api.ts +97 -8
  77. package/src/modules/change-requests/utils/approval.ts +15 -0
  78. package/src/modules/change-requests/utils/author.ts +32 -0
  79. package/src/modules/change-requests/utils/readFailure.ts +110 -0
  80. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +20 -0
  81. package/src/modules/git/components/FileHistoryPanel.tsx +5 -0
  82. package/src/modules/git/components/PullRequestsForMe.tsx +51 -24
  83. package/src/modules/git/services/__tests__/error-messages.test.ts +29 -0
  84. package/src/modules/git/services/error-messages.ts +12 -0
  85. package/src/modules/git/services/pr-prompts.ts +5 -5
  86. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +401 -0
  87. package/src/modules/layout/__tests__/SidebarFooterGrid.test.tsx +286 -0
  88. package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +61 -0
  89. package/src/modules/layout/components/AppLayout.tsx +2 -0
  90. package/src/modules/layout/components/MobileChatLayout.tsx +4 -1
  91. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +4 -1
  92. package/src/modules/layout/components/SidebarFrame.tsx +108 -3
  93. package/src/modules/library/__tests__/AddToPluginDialog.test.tsx +171 -5
  94. package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +356 -0
  95. package/src/modules/library/__tests__/IntegrationsSetupReminder.test.tsx +60 -0
  96. package/src/modules/library/__tests__/LibraryCard.test.tsx +91 -10
  97. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +242 -107
  98. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +103 -98
  99. package/src/modules/library/__tests__/LinkSkillPanel.test.tsx +20 -5
  100. package/src/modules/library/__tests__/LockedPluginView.test.tsx +97 -7
  101. package/src/modules/library/__tests__/NewPluginDialog.test.tsx +13 -4
  102. package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +79 -3
  103. package/src/modules/library/__tests__/PersonalPluginPage.test.tsx +201 -0
  104. package/src/modules/library/__tests__/PluginExtras.test.tsx +100 -9
  105. package/src/modules/library/__tests__/PluginJoinRequests.test.tsx +60 -1
  106. package/src/modules/library/__tests__/PluginPage.test.tsx +258 -6
  107. package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +16 -56
  108. package/src/modules/library/__tests__/PluginsSidebar.test.tsx +155 -152
  109. package/src/modules/library/__tests__/PluginsSidebarMenu.test.tsx +16 -0
  110. package/src/modules/library/__tests__/SharedViaPlugins.test.tsx +106 -0
  111. package/src/modules/library/__tests__/SkillPage.test.tsx +386 -80
  112. package/src/modules/library/__tests__/SkillsTree.test.tsx +293 -4
  113. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +582 -71
  114. package/src/modules/library/__tests__/ToolPage.test.tsx +87 -4
  115. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +173 -26
  116. package/src/modules/library/__tests__/auth-harness.tsx +9 -9
  117. package/src/modules/library/__tests__/card-row-menu.test.tsx +320 -0
  118. package/src/modules/library/__tests__/library-data.mapping.test.tsx +98 -0
  119. package/src/modules/library/__tests__/library-data.stale.test.tsx +121 -28
  120. package/src/modules/library/__tests__/library-data.test.ts +7 -0
  121. package/src/modules/library/__tests__/library-paths.test.ts +47 -4
  122. package/src/modules/library/__tests__/link-membership.test.ts +13 -4
  123. package/src/modules/library/__tests__/name-with-badges.test.tsx +273 -0
  124. package/src/modules/library/__tests__/newSkillMarkdown.test.ts +30 -0
  125. package/src/modules/library/__tests__/owner-pill.test.tsx +357 -0
  126. package/src/modules/library/__tests__/pending-tools.test.tsx +400 -0
  127. package/src/modules/library/__tests__/plugin-entries.test.ts +122 -0
  128. package/src/modules/library/__tests__/plugin-summary.test.ts +36 -1
  129. package/src/modules/library/__tests__/status.test.ts +82 -2
  130. package/src/modules/library/__tests__/tools.api.test.ts +44 -1
  131. package/src/modules/library/components/AccessRequestsBanner.tsx +85 -47
  132. package/src/modules/library/components/AddDialogTabs.tsx +103 -0
  133. package/src/modules/library/components/AddToPluginDialog.tsx +74 -18
  134. package/src/modules/library/components/IntegrationsSetupReminder.tsx +59 -0
  135. package/src/modules/library/components/ItemActionsMenu.tsx +288 -0
  136. package/src/modules/library/components/LibraryCard.tsx +146 -45
  137. package/src/modules/library/components/LibraryLayout.tsx +119 -256
  138. package/src/modules/library/components/LibraryPage.tsx +172 -39
  139. package/src/modules/library/components/LinkSkillPanel.tsx +1 -3
  140. package/src/modules/library/components/LockedPluginView.tsx +62 -34
  141. package/src/modules/library/components/NameWithBadges.tsx +164 -0
  142. package/src/modules/library/components/NewPluginDialog.tsx +16 -2
  143. package/src/modules/library/components/PageActions.tsx +11 -9
  144. package/src/modules/library/components/{PendingSkillReview.tsx → PendingItemReview.tsx} +14 -7
  145. package/src/modules/library/components/PersonalAddDialog.tsx +68 -18
  146. package/src/modules/library/components/PersonalPluginPage.tsx +121 -22
  147. package/src/modules/library/components/PluginExtras.tsx +140 -17
  148. package/src/modules/library/components/PluginIndexRow.tsx +47 -12
  149. package/src/modules/library/components/PluginPage.tsx +157 -41
  150. package/src/modules/library/components/PluginRows.tsx +286 -0
  151. package/src/modules/library/components/PluginsSidebar.tsx +239 -263
  152. package/src/modules/library/components/PluginsSidebarMenu.tsx +26 -1
  153. package/src/modules/library/components/ShareButton.tsx +17 -0
  154. package/src/modules/library/components/SkillsTree.tsx +141 -28
  155. package/src/modules/library/components/TeamRoute.tsx +15 -0
  156. package/src/modules/library/components/__tests__/upload-notices-once-per-page.test.tsx +144 -0
  157. package/src/modules/library/components/plugin-page-parts.tsx +103 -17
  158. package/src/modules/library/components/skill-page/SharedViaPlugins.tsx +6 -12
  159. package/src/modules/library/components/skill-page/SkillFilePane.tsx +5 -0
  160. package/src/modules/library/components/skill-page/SkillPage.tsx +274 -122
  161. package/src/modules/library/components/tool-page/DeleteToolDialog.tsx +218 -0
  162. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +79 -178
  163. package/src/modules/library/components/tool-page/ToolPage.tsx +106 -16
  164. package/src/modules/library/components/tool-page/ToolVarRow.tsx +42 -41
  165. package/src/modules/library/hooks/__tests__/useLibraryData.test.ts +98 -0
  166. package/src/modules/library/hooks/useLibraryData.ts +92 -19
  167. package/src/modules/library/routes/LibraryRoutes.tsx +14 -11
  168. package/src/modules/library/routes/WorkspaceItemRoute.tsx +77 -27
  169. package/src/modules/library/routes/library-paths.ts +26 -28
  170. package/src/modules/library/services/library.api.ts +38 -20
  171. package/src/modules/library/services/plugins.api.ts +69 -8
  172. package/src/modules/library/services/teams.api.ts +15 -0
  173. package/src/modules/library/services/tools.api.ts +78 -0
  174. package/src/modules/library/state/library-data.tsx +170 -32
  175. package/src/modules/library/utils/personal-plugin.ts +13 -15
  176. package/src/modules/library/utils/plugin-entries.ts +134 -0
  177. package/src/modules/library/utils/plugin-summary.ts +75 -9
  178. package/src/modules/library/utils/status.ts +135 -33
  179. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +8 -1
  180. package/src/modules/onboarding/__tests__/onboarding.test.tsx +853 -760
  181. package/src/modules/onboarding/agent-clients.ts +55 -23
  182. package/src/modules/onboarding/components/ConnectAgentPill.tsx +5 -1
  183. package/src/modules/onboarding/components/WelcomePage.tsx +98 -62
  184. package/src/modules/pr/services/pr-merge.api.ts +2 -1
  185. package/src/modules/review/components/MarkdownDiffViewer.tsx +53 -8
  186. package/src/modules/review/components/ReviewPanel.tsx +15 -17
  187. package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +64 -0
  188. package/src/modules/review/components/__tests__/ReviewPanel.test.tsx +25 -1
  189. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +454 -117
  190. package/src/modules/secrets-vault/components/SecretsPage.tsx +48 -7
  191. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +84 -5
  192. package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +425 -0
  193. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +417 -82
  194. package/src/modules/secrets-vault/components/__tests__/ToolSecretsPanel.test.tsx +105 -0
  195. package/src/modules/secrets-vault/components/__tests__/connect-lists-what-the-banner-counted.test.tsx +407 -0
  196. package/src/modules/secrets-vault/probe/SavedKeyProbeResult.tsx +98 -0
  197. package/src/modules/secrets-vault/probe/__tests__/probe-verdict.test.ts +160 -0
  198. package/src/modules/secrets-vault/probe/probe-verdict.ts +108 -0
  199. package/src/modules/secrets-vault/probe/useSavedKeyProbe.ts +228 -0
  200. package/src/modules/secrets-vault/services/connect.api.ts +36 -5
  201. package/src/modules/secrets-vault/utils/connect-status.ts +98 -0
  202. package/src/modules/settings/components/ClaudeConnectionCard.tsx +9 -24
  203. package/src/modules/settings/components/ClaudeConnectionFields.tsx +23 -0
  204. package/src/modules/settings/components/DeploymentPage.tsx +10 -30
  205. package/src/modules/settings/components/MarketplaceSection.tsx +152 -0
  206. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +67 -4
  207. package/src/modules/settings/components/__tests__/MarketplaceSection.test.tsx +325 -0
  208. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +7 -6
  209. package/src/modules/settings/services/github-facade.api.ts +23 -0
  210. package/src/modules/settings/settings-nav-items.tsx +13 -3
  211. package/src/modules/setup/__tests__/setup.oidc.test.tsx +172 -0
  212. package/src/modules/setup/__tests__/setup.probe-refusal.test.tsx +123 -0
  213. package/src/modules/setup/__tests__/setup.test.tsx +497 -4
  214. package/src/modules/setup/__tests__/useSetupStatus.test.tsx +130 -0
  215. package/src/modules/setup/components/SetupGate.tsx +16 -16
  216. package/src/modules/setup/components/SetupScreen.tsx +532 -43
  217. package/src/modules/setup/hooks/useSetupStatus.ts +93 -0
  218. package/src/modules/setup/services/setup.api.ts +141 -4
  219. package/src/modules/setup/utils/__tests__/root-folders.test.ts +72 -0
  220. package/src/modules/setup/utils/root-folders.ts +46 -0
  221. package/src/modules/toolbar/assets/claude-setup/01-add-manually.webp +0 -0
  222. package/src/modules/toolbar/assets/claude-setup/02-add-configuration.webp +0 -0
  223. package/src/modules/toolbar/assets/claude-setup/03-connect-account.webp +0 -0
  224. package/src/modules/toolbar/assets/claude-setup/04-pick-instance.webp +0 -0
  225. package/src/modules/toolbar/assets/claude-setup/05-plugins-add.webp +0 -0
  226. package/src/modules/toolbar/assets/claude-setup/06-add-marketplace.webp +0 -0
  227. package/src/modules/toolbar/assets/claude-setup/07-paste-url-sync.webp +0 -0
  228. package/src/modules/toolbar/assets/claude-setup/08-install-plugins.webp +0 -0
  229. package/src/modules/toolbar/assets/claude-setup/09-select-repository.webp +0 -0
  230. package/src/modules/toolbar/assets/claude-setup/10-connector-not-added.webp +0 -0
  231. package/src/modules/toolbar/assets/claude-setup/11-add-custom-connector.webp +0 -0
  232. package/src/modules/toolbar/assets/claude-setup/README.md +68 -0
  233. package/src/modules/toolbar/components/AgentInstructionsCard.tsx +296 -0
  234. package/src/modules/toolbar/components/ClaudeMarketplaceCarousel.tsx +107 -0
  235. package/src/modules/toolbar/components/ClaudeRegistrationSteps.tsx +127 -0
  236. package/src/modules/toolbar/components/CoworkSetupSteps.tsx +100 -0
  237. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +177 -118
  238. package/src/modules/toolbar/components/ScreenshotStep.tsx +77 -0
  239. package/src/modules/toolbar/components/SetupCarousel.tsx +177 -0
  240. package/src/modules/toolbar/components/__tests__/AgentInstructionsCard.test.tsx +370 -0
  241. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +542 -42
  242. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +2 -2
  243. package/src/modules/toolbar/components/__tests__/claude-setup-shots.test.ts +104 -0
  244. package/src/modules/toolbar/components/claude-connector-slide.tsx +38 -0
  245. package/src/modules/toolbar/components/claude-setup-shots.ts +167 -0
  246. package/src/modules/toolbar/components/deployment-address.ts +29 -0
  247. package/src/modules/toolbar/components/setup-step-parts.tsx +35 -0
  248. package/src/modules/toolbar/services/__tests__/agent-instructions.api.test.ts +89 -0
  249. package/src/modules/toolbar/services/agent-instructions.api.ts +167 -0
  250. package/src/modules/toolbar/services/external-api-keys.api.ts +8 -0
  251. package/src/modules/workflow/state/ChangeRequestStaleBinder.tsx +43 -0
  252. package/src/modules/workflow/state/EventBusProvider.tsx +122 -11
  253. package/src/modules/workflow/state/__tests__/EventBusProvider.storage.test.tsx +87 -0
  254. package/src/modules/workflow/state/__tests__/EventBusProvider.watch.test.tsx +223 -0
  255. package/src/modules/workflow/state/event-bus.context.ts +10 -0
  256. package/src/modules/workspace/__tests__/testFixtures.ts +5 -3
  257. package/src/modules/workspace/components/FileExplorer.tsx +1295 -191
  258. package/src/modules/workspace/components/FileRoute.tsx +353 -36
  259. package/src/modules/workspace/components/FileViewer.tsx +172 -46
  260. package/src/modules/workspace/components/KbDocumentShell.tsx +50 -6
  261. package/src/modules/workspace/components/KbPageHeader.tsx +120 -55
  262. package/src/modules/workspace/components/TreeActionConfirm.tsx +350 -0
  263. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +2533 -129
  264. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +731 -18
  265. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +381 -12
  266. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +39 -0
  267. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +33 -20
  268. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +4 -5
  269. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +13 -4
  270. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +4 -3
  271. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +8 -14
  272. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +75 -16
  273. package/src/modules/workspace/components/renderers/KbImage.tsx +180 -0
  274. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +22 -6
  275. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +48 -22
  276. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +4 -5
  277. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +4 -3
  278. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +4 -3
  279. package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +12 -0
  280. package/src/modules/workspace/components/renderers/__tests__/DownloadFileButton.test.tsx +57 -9
  281. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.test.tsx +13 -1
  282. package/src/modules/workspace/components/renderers/__tests__/ImageRenderer.test.tsx +163 -0
  283. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +237 -0
  284. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +108 -14
  285. package/src/modules/workspace/components/renderers/__tests__/PptxRenderer.test.tsx +14 -1
  286. package/src/modules/workspace/components/renderers/__tests__/XlsxRenderer.test.tsx +16 -1
  287. package/src/modules/workspace/components/renderers/__tests__/rendererSelection.test.tsx +66 -1
  288. package/src/modules/workspace/components/renderers/index.ts +53 -2
  289. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +25 -4
  290. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +40 -0
  291. package/src/modules/workspace/hooks/__tests__/useImageRevision.test.tsx +174 -0
  292. package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +179 -1
  293. package/src/modules/workspace/hooks/__tests__/useWorkspaceImageResolver.test.tsx +122 -0
  294. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +892 -7
  295. package/src/modules/workspace/hooks/useImageRevision.ts +101 -0
  296. package/src/modules/workspace/hooks/useMergedWorkspaceTree.ts +22 -3
  297. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +55 -0
  298. package/src/modules/workspace/hooks/useWorkspaceState.ts +424 -66
  299. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +279 -3
  300. package/src/modules/workspace/routing/kb-routes.ts +206 -29
  301. package/src/modules/workspace/services/__tests__/workspace.api.test.ts +134 -1
  302. package/src/modules/workspace/services/workspace.api.ts +57 -4
  303. package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +343 -0
  304. package/src/modules/workspace/state/__tests__/upload-lands-where-it-was-dropped.test.tsx +158 -0
  305. package/src/modules/workspace/state/open-change-requests.tsx +100 -12
  306. package/src/modules/workspace/state/workspace.context.ts +125 -19
  307. package/src/modules/workspace/utils/__tests__/file-trace.test.ts +73 -0
  308. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +220 -6
  309. package/src/modules/workspace/utils/__tests__/pasteLink.test.ts +76 -0
  310. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +364 -0
  311. package/src/modules/workspace/utils/__tests__/uploadError.test.ts +35 -0
  312. package/src/modules/workspace/utils/file-trace.ts +50 -0
  313. package/src/modules/workspace/utils/fileTree.ts +112 -36
  314. package/src/modules/workspace/utils/frontmatter.ts +8 -4
  315. package/src/modules/workspace/utils/pasteLink.ts +90 -0
  316. package/src/modules/workspace/utils/treeConfirm.ts +338 -0
  317. package/src/modules/workspace/utils/uploadError.ts +29 -0
  318. package/src/shared/__tests__/marketplace-url.test.ts +6 -1
  319. package/src/shared/components/Button.tsx +16 -2
  320. package/src/shared/components/Dialog.tsx +27 -11
  321. package/src/shared/components/Menu.tsx +13 -1
  322. package/src/shared/components/PageShell.tsx +13 -8
  323. package/src/shared/components/__tests__/primitives.test.tsx +116 -2
  324. package/src/shared/components/__tests__/useFocusHandoff.test.tsx +192 -0
  325. package/src/shared/components/index.ts +2 -0
  326. package/src/shared/components/useDismissableMenu.ts +32 -10
  327. package/src/shared/components/useFocusHandoff.ts +51 -0
  328. package/src/shared/components/useLatestRef.ts +28 -0
  329. package/src/shared/markdown/Markdown.tsx +12 -3
  330. package/src/shared/markdown/__tests__/escapeSpacesInLinkDestinations.test.ts +39 -0
  331. package/src/shared/markdown/hrefs.ts +50 -0
  332. package/src/shared/marketplace-url.ts +33 -5
  333. package/src/shared/mcp/ChatGptInstallLink.tsx +3 -3
  334. package/src/shared/mcp/ConnectionInstructions.tsx +38 -27
  335. package/src/shared/mcp/__tests__/connect-snippets.test.ts +3 -3
  336. package/src/shared/mcp/connect-snippets.ts +14 -9
  337. package/src/shared/mcp/index.ts +1 -1
  338. package/src/shared/theme/__tests__/header-band.test.ts +197 -0
  339. package/src/shared/theme/header.ts +75 -0
  340. package/src/shared/theme/measure.ts +7 -4
  341. package/src/shared/theme/tokens.css +25 -0
  342. package/src/modules/library/__tests__/PluginsIndexPage.test.tsx +0 -363
  343. package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +0 -97
  344. package/src/modules/library/components/PluginsIndexPage.tsx +0 -270
  345. package/src/modules/update-check/__tests__/UpdateBanner.test.tsx +0 -126
  346. package/src/modules/update-check/components/UpdateBanner.tsx +0 -92
  347. package/src/modules/update-check/services/update-check.api.ts +0 -24
@@ -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,13 +190,33 @@ interface UseWorkspaceStateReturn extends WorkspaceContextValue {
99
190
 
100
191
  export function useWorkspaceState(): UseWorkspaceStateReturn {
101
192
  const [workspaceId, setWorkspaceId] = useState<string | null>(null);
102
- const [bootstrapError, setBootstrapError] = useState<{ branch: string; status: number } | 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);
103
209
  const [kbDirName, setKbDirName] = useState<string | null>(null);
104
210
  const [fileTree, setFileTree] = useState<FileTreeEntry | null>(null);
105
211
  const [openTabs, setOpenTabs] = useState<OpenTab[]>([]);
106
212
  const [activeTabPath, setActiveTabPath] = useState<string | null>(null);
107
- const [uploadError, setUploadError] = useState<UploadError | null>(null);
108
- 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);
109
220
  const [isUploading, setIsUploading] = useState(false);
110
221
  // Who is signed in — the suggestion-routed upload needs an author for the
111
222
  // branch name and the change request. Read nullable (not `useAuth`, which
@@ -120,6 +231,15 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
120
231
  // Monotonic token so a slow `addTab` whose response arrives after a newer add
121
232
  // doesn't clobber the newer state.
122
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);
123
243
  // Tracks the (workspaceId, persistenceBranch) key we've successfully hydrated
124
244
  // for. Auto-persist effect won't write until hydrate has run for the current
125
245
  // key — avoids overwriting localStorage with `[]` before the restore lands.
@@ -142,11 +262,46 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
142
262
  // persistenceBranch as a ref too, so hydrateTabs reads the latest value
143
263
  // even when setPersistenceBranch was called in the same render.
144
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);
145
272
  useEffect(() => { openTabsRef.current = openTabs; }, [openTabs]);
146
273
  useEffect(() => { activeTabPathRef.current = activeTabPath; }, [activeTabPath]);
147
274
  useEffect(() => { fileTreeRef.current = fileTree; }, [fileTree]);
148
275
  useEffect(() => { persistenceBranchRef.current = persistenceBranch; }, [persistenceBranch]);
149
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
+
150
305
  const setPersistenceBranch = useCallback((branch: string | null) => {
151
306
  persistenceBranchRef.current = branch;
152
307
  setPersistenceBranchState(branch);
@@ -168,30 +323,53 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
168
323
  const branch = persistenceBranch ?? undefined;
169
324
  let cancelled = false;
170
325
  (async () => {
326
+ traceFiles('bootstrap:start', { branch: branch ?? null, attempt: bootstrapAttempt });
171
327
  try {
172
328
  const { workspace, fileTree: tree } = await getOrCreateWorkspace(branch);
329
+ traceFiles('bootstrap:ok', { branch: branch ?? null, workspaceId: workspace.id, cancelled });
173
330
  if (cancelled) return;
174
- setWorkspaceId(workspace.id);
331
+ adoptWorkspace(workspace.id, workspaceBranchOf(workspace.id, branch));
175
332
  setKbDirName(workspace.kbDirName);
176
333
  setFileTree(tree);
177
334
  setBootstrapError(null);
178
335
  } catch (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
+ });
179
342
  if (cancelled) return;
180
343
  console.error('Failed to bootstrap workspace:', err);
181
344
  // Surfaced, not just logged: a bootstrap that fails leaves
182
345
  // `workspaceId` where it was, and the route waiting on it needs to
183
- // know why — a branch the host deleted (410) has its own screen.
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.
184
351
  // No persistence branch means the server bootstrapped the DEFAULT
185
352
  // branch, so that is the branch this failure is about — an empty
186
353
  // name would never match the URL a route is on.
187
354
  setBootstrapError({
188
355
  branch: branch ?? DEFAULT_BRANCH,
189
356
  status: err instanceof WorkspaceApiError ? err.status : 0,
357
+ message: err instanceof Error ? err.message : String(err),
190
358
  });
191
359
  }
192
360
  })();
193
361
  return () => { cancelled = true; };
194
- }, [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
+ }, []);
195
373
 
196
374
  const refreshFileTree = useCallback(async () => {
197
375
  if (!workspaceId) return null;
@@ -234,11 +412,19 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
234
412
  // null-content guard renders an empty/loading state until content arrives.
235
413
  if (tab.content === null && workspaceId) {
236
414
  const path = tab.path;
237
- 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;
238
423
  setOpenTabs((prev) => prev.map((t) => (
239
424
  t.path === path ? { ...t, content, savedContent: content } : t
240
425
  )));
241
426
  }).catch((err) => {
427
+ if (workspaceIdRef.current !== readFrom) return;
242
428
  if (
243
429
  err instanceof WorkspaceApiError &&
244
430
  (err.status === 404 || err.status === 403)
@@ -258,12 +444,25 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
258
444
  // on dirty state — opening more tabs never discards work.
259
445
  const existing = openTabsRef.current.find((t) => t.path === relativePath);
260
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;
261
454
  activateTab(existing);
262
455
  return true;
263
456
  }
264
457
  const requestId = ++addRequestIdRef.current;
265
458
  try {
266
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
+ }
267
466
  const isLatest = requestId === addRequestIdRef.current;
268
467
  // Re-check dedup in case of races during the await.
269
468
  const stillExisting = openTabsRef.current.find((t) => t.path === relativePath);
@@ -289,7 +488,9 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
289
488
  return true;
290
489
  } catch (err) {
291
490
  // Drop stale errors silently — the user already navigated to a newer
292
- // 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;
293
494
  if (requestId !== addRequestIdRef.current) return false;
294
495
  // A 403 (read-restricted deep-link / id-link) throws like any other
295
496
  // failure: NO tab is created for a file the user can't read — the route
@@ -344,18 +545,35 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
344
545
  const hydrateTabs = useCallback(async (
345
546
  paths: string[],
346
547
  activePath: string | null,
347
- ): Promise<{ surviving: string[]; dropped: string[]; denied: string[] }> => {
348
- 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;
349
561
  // Deduplicate while preserving order.
350
562
  const uniqPaths = paths.filter((p, i) => paths.indexOf(p) === i);
351
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
+
352
572
  if (uniqPaths.length === 0) {
353
573
  setOpenTabs([]);
354
574
  setActiveTabPath(null);
355
- hydratedKeyRef.current = persistenceBranchRef.current
356
- ? `${workspaceId}.${persistenceBranchRef.current}`
357
- : null;
358
- return { surviving: [], dropped: [], denied: [] };
575
+ hydratedKeyRef.current = hydratedKey;
576
+ return { surviving: [], dropped: [], denied: [], superseded: false };
359
577
  }
360
578
 
361
579
  // Fetch every path in parallel. 404s are silently dropped (file no longer
@@ -365,6 +583,16 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
365
583
  // access message instead of "file not found". Other errors throw so the
366
584
  // caller can show "file-load-failed".
367
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;
368
596
  const survivors: OpenTab[] = [];
369
597
  const surviving: string[] = [];
370
598
  const dropped: string[] = [];
@@ -395,17 +623,36 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
395
623
  }
396
624
  }
397
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
+
398
647
  setOpenTabs(survivors);
399
648
  // Activate `activePath` if it survived; else last surviving path; else null.
400
649
  const requested = activePath && survivors.some((t) => t.path === activePath)
401
650
  ? activePath
402
651
  : (survivors[survivors.length - 1]?.path ?? null);
403
652
  setActiveTabPath(requested);
404
- hydratedKeyRef.current = persistenceBranchRef.current
405
- ? `${workspaceId}.${persistenceBranchRef.current}`
406
- : null;
407
- return { surviving, dropped, denied };
408
- }, [workspaceId]);
653
+ hydratedKeyRef.current = hydratedKey;
654
+ return { surviving, dropped, denied, superseded: false };
655
+ }, [workspaceId, workspaceBranch]);
409
656
 
410
657
  // ── Renderer value bridge → active tab.content ────────────────────────────
411
658
 
@@ -485,8 +732,24 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
485
732
  bumpFs();
486
733
  }, [workspaceId, refreshFileTree, bumpFs]);
487
734
 
488
- const clearUploadError = useCallback(() => setUploadError(null), []);
489
- 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
+ }, []);
490
753
 
491
754
  // Pending overlay: files/dirs the user dropped but whose server commits
492
755
  // haven't echoed back yet. The ref holds the mutable working set the
@@ -534,6 +797,15 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
534
797
  * free-for-all, and paths outside the KB are the user's own workspace.
535
798
  * (The branch is recovered from the workspace id, which is the encoded
536
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.
537
809
  */
538
810
  const resolveSuggestionRouting = useCallback(
539
811
  async (targetDirectory: string): Promise<KnowledgeSuggestionTarget | null> => {
@@ -544,6 +816,9 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
544
816
  const repoRelative = targetDirectory.slice(prefix.length);
545
817
  if (!repoRelative) return null;
546
818
  const access = await fetchFileAccess(workspaceId, repoRelative);
819
+ if (access.canRead === false && repoRelative.includes('/')) {
820
+ throw new UnreadableUploadTargetError(repoRelative);
821
+ }
547
822
  if (access.canWrite) return null;
548
823
  return ensureKnowledgeSuggestionWorkspace(authUser);
549
824
  },
@@ -551,9 +826,49 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
551
826
  );
552
827
 
553
828
  const activeUploadsRef = useRef(0);
554
- 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
+ ) => {
555
839
  if (!workspaceId) return;
556
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
+
557
872
  // ── Suggestion routing ──
558
873
  // An upload into a KB folder the caller may NOT write neither fails nor
559
874
  // forces its way in: it lands on their personal suggestions branch and
@@ -563,10 +878,24 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
563
878
  // upload normally: the backend's write gate stays the authority and
564
879
  // refuses with its own words.
565
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;
566
884
  try {
567
885
  suggestion = await resolveSuggestionRouting(targetDirectory);
568
886
  } catch (err) {
569
- 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);
570
899
  }
571
900
  const uploadWorkspaceId = suggestion?.workspaceId ?? workspaceId;
572
901
  // No optimistic tree overlay for a suggestion-routed upload: the files
@@ -577,20 +906,6 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
577
906
  const suggestionPrefix = suggestion ? `${suggestion.kbDirName}/` : null;
578
907
  /** Repo-relative paths of the files that LANDED on the suggestions branch. */
579
908
  const suggestedRepoPaths: string[] = [];
580
- // Pin the workspace at dispatch time. A folder upload can take seconds;
581
- // if the user switches branches mid-flight, the trailing state
582
- // mutations (setUploadError / setIsUploading / setFileTree via
583
- // refreshFileTree / clearPendingMatching) would clobber the new
584
- // branch's UI with old-branch results. `isCurrent()` gates every
585
- // post-await mutation; the workspaceId reset effect above already
586
- // clears the optimistic refs the moment the switch happens.
587
- const dispatchWorkspaceId = workspaceId;
588
- const isCurrent = () => workspaceIdRef.current === dispatchWorkspaceId;
589
-
590
- setUploadError(null);
591
- setUploadNotice(null);
592
- activeUploadsRef.current += 1;
593
- setIsUploading(true);
594
909
 
595
910
  // Batch mode collapses N per-file pushes into one end-of-burst push
596
911
  // via `POST /flush` — mirrors the recursive folder-delete batch.
@@ -620,7 +935,7 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
620
935
  let uploaded = 0;
621
936
  let total: number | null = null;
622
937
  let abort = false;
623
- let firstError: { filename: string; reason: string } | null = null;
938
+ let firstError: UploadError | null = null;
624
939
  // Tracks whether any deferred `createDirectory` (empty-dir preservation)
625
940
  // commits landed. Without this, a folder drop containing only empty
626
941
  // subdirectories would skip `flushBatch` (`uploaded === 0`) and leave
@@ -634,7 +949,14 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
634
949
  const recordError = (filename: string, err: unknown) => {
635
950
  if (firstError) return;
636
951
  const reason = err instanceof Error ? err.message : 'Upload failed';
637
- 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 };
638
960
  abort = true;
639
961
  };
640
962
 
@@ -712,6 +1034,14 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
712
1034
  };
713
1035
 
714
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
+ }
715
1045
  if (input.kind === 'files') {
716
1046
  const files = input.files.filter((f) => !isUploadNoise(f.name));
717
1047
  total = files.length;
@@ -803,10 +1133,17 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
803
1133
  }
804
1134
  window.dispatchEvent(new Event(PR_STALE_EVENT));
805
1135
  if (isCurrent()) {
806
- setUploadNotice(
807
- "You can't write to that folder, so the upload became a suggestion: " +
808
- 'it is now a change request for the folder’s owners to review.',
809
- );
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
+ }));
810
1147
  }
811
1148
  } catch (err) {
812
1149
  recordError('change request', err);
@@ -824,9 +1161,12 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
824
1161
  // they already left. The workspace-change effect already reset the
825
1162
  // optimistic overlays.
826
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);
827
1167
  if (isCurrent()) {
828
1168
  if (firstError) {
829
- setUploadError(firstError);
1169
+ setUploadErrors((current) => withBanner(current, uploadTarget, firstError));
830
1170
  // Drop any pending overlay entries that didn't make it — files
831
1171
  // we already uploaded successfully are removed inside uploadOne.
832
1172
  clearPendingMatching(() => true);
@@ -835,6 +1175,11 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
835
1175
  const stillRunning = activeUploadsRef.current > 0;
836
1176
  setIsUploading(stillRunning);
837
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);
838
1183
 
839
1184
  // One final refresh to reconcile the server tree with whatever
840
1185
  // committed, then clear pending overlay entries whose real
@@ -858,7 +1203,7 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
858
1203
  }, [
859
1204
  workspaceId, refreshFileTree, bumpFs,
860
1205
  addPending, removePending, clearPendingMatching,
861
- resolveSuggestionRouting, authUser,
1206
+ resolveSuggestionRouting, authUser, clearProgressNotice,
862
1207
  ]);
863
1208
 
864
1209
  const deleteEntry = useCallback(async (relativePath: string) => {
@@ -883,7 +1228,7 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
883
1228
  const dirty = toClose.filter((t) => t.isDirty);
884
1229
  if (dirty.length > 0) {
885
1230
  const confirmed = window.confirm(UNSAVED_TABS_BULK_WARNING(dirty.map((t) => basename(t.path))));
886
- if (!confirmed) return;
1231
+ if (!confirmed) return false;
887
1232
  }
888
1233
  // Optimistic tree removal. A folder delete on the server takes 2-3s
889
1234
  // (N per-file commits batched into one push) — without optimism the
@@ -1136,22 +1481,27 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
1136
1481
  // When the user switches branches, the previously-hydrated key no longer
1137
1482
  // applies. Clear the marker so the auto-persist effect waits for a fresh
1138
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.
1139
1489
  useEffect(() => {
1140
- if (!workspaceId || !persistenceBranch) {
1490
+ if (!workspaceId || !workspaceBranch) {
1141
1491
  hydratedKeyRef.current = null;
1142
1492
  return;
1143
1493
  }
1144
- const key = `${workspaceId}.${persistenceBranch}`;
1494
+ const key = `${workspaceId}.${workspaceBranch}`;
1145
1495
  if (hydratedKeyRef.current !== key) {
1146
1496
  hydratedKeyRef.current = null;
1147
1497
  }
1148
- }, [workspaceId, persistenceBranch]);
1498
+ }, [workspaceId, workspaceBranch]);
1149
1499
 
1150
1500
  // ── Auto-persist tabs to localStorage (debounced) ─────────────────────────
1151
1501
 
1152
1502
  useEffect(() => {
1153
- if (!workspaceId || !persistenceBranch) return;
1154
- const key = `${workspaceId}.${persistenceBranch}`;
1503
+ if (!workspaceId || !workspaceBranch) return;
1504
+ const key = `${workspaceId}.${workspaceBranch}`;
1155
1505
  if (hydratedKeyRef.current !== key) return;
1156
1506
 
1157
1507
  const handle = window.setTimeout(() => {
@@ -1160,13 +1510,13 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
1160
1510
  paths: openTabs.map((t) => t.path),
1161
1511
  activePath: activeTabPath,
1162
1512
  };
1163
- localStorage.setItem(tabsKey(workspaceId, persistenceBranch), JSON.stringify(payload));
1513
+ localStorage.setItem(tabsKey(workspaceId, workspaceBranch), JSON.stringify(payload));
1164
1514
  } catch (err) {
1165
1515
  console.warn('Failed to persist tabs:', err);
1166
1516
  }
1167
1517
  }, PERSIST_DEBOUNCE_MS);
1168
1518
  return () => window.clearTimeout(handle);
1169
- }, [openTabs, activeTabPath, workspaceId, persistenceBranch]);
1519
+ }, [openTabs, activeTabPath, workspaceId, workspaceBranch]);
1170
1520
 
1171
1521
  const deleteWorkspace = useCallback(async () => {
1172
1522
  if (!workspaceId) return;
@@ -1179,13 +1529,13 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
1179
1529
  // swaps the user onto a different branch after a delete.
1180
1530
  const branch = persistenceBranchRef.current ?? undefined;
1181
1531
  const { workspace, fileTree: tree } = await getOrCreateWorkspace(branch);
1182
- setWorkspaceId(workspace.id);
1532
+ adoptWorkspace(workspace.id, workspaceBranchOf(workspace.id, branch));
1183
1533
  setKbDirName(workspace.kbDirName);
1184
1534
  setFileTree(tree);
1185
1535
  } catch (err) {
1186
1536
  console.error('Failed to delete workspace:', err);
1187
1537
  }
1188
- }, [workspaceId, closeAllTabs]);
1538
+ }, [workspaceId, closeAllTabs, adoptWorkspace]);
1189
1539
 
1190
1540
  // ── Live updates: react to other users' / agent's edits ───────────────────
1191
1541
  //
@@ -1214,13 +1564,11 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
1214
1564
  // The bus only delivers workspace-scoped events for the currently
1215
1565
  // focused workspace (set by `EventBusFocusBinder`), so the workspace
1216
1566
  // filter on the handler is belt-and-braces.
1217
- // Track the current workspaceId in a ref so the async readFile handler
1218
- // below can detect a workspace switch that happened after it was
1219
- // subscribed but before its fetch resolved — otherwise a stale resolve
1220
- // would call `setOpenTabs` on the new workspace's tabs, replacing the
1221
- // wrong file's content with bytes from the old branch.
1222
- const workspaceIdRef = useRef<string | null>(workspaceId);
1223
- 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.
1224
1572
 
1225
1573
  // Reset the optimistic-overlay state on workspace switch. Without this,
1226
1574
  // pending entries from a partly-uploaded folder on branch A linger in
@@ -1235,6 +1583,14 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
1235
1583
  pendingDeletePathsRef.current = new Set();
1236
1584
  // eslint-disable-next-line react-hooks/set-state-in-effect
1237
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);
1238
1594
  }, [workspaceId]);
1239
1595
 
1240
1596
  const bus = useEventBus();
@@ -1385,6 +1741,8 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
1385
1741
  kbDirName,
1386
1742
  fileTree,
1387
1743
  bootstrapError,
1744
+ workspaceBranch,
1745
+ retryBootstrap,
1388
1746
  openTabs,
1389
1747
  activeTab,
1390
1748
  dirtyTabFilenames,
@@ -1396,8 +1754,8 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
1396
1754
  setHasUnsavedFileChanges,
1397
1755
  setActiveTabContent,
1398
1756
  fsRevision,
1399
- uploadError,
1400
- uploadNotice,
1757
+ uploadErrors,
1758
+ uploadNotices,
1401
1759
  clearUploadNotice,
1402
1760
  isUploading,
1403
1761
  uploadProgress,
@@ -1426,9 +1784,9 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
1426
1784
  setPersistenceBranch,
1427
1785
  deleteWorkspace,
1428
1786
  }), [
1429
- workspaceId, kbDirName, fileTree, bootstrapError, openTabs, activeTab, dirtyTabFilenames,
1787
+ workspaceId, kbDirName, fileTree, bootstrapError, workspaceBranch, retryBootstrap, openTabs, activeTab, dirtyTabFilenames,
1430
1788
  openFilePath, openFileContent, openFileSavedContent, hasUnsavedFileChanges, pendingFileContent,
1431
- setHasUnsavedFileChanges, setActiveTabContent, fsRevision, uploadError, uploadNotice, clearUploadNotice, isUploading, uploadProgress, pendingUploads, refreshFileTree, bumpFs,
1789
+ setHasUnsavedFileChanges, setActiveTabContent, fsRevision, uploadErrors, uploadNotices, clearUploadNotice, isUploading, uploadProgress, pendingUploads, refreshFileTree, bumpFs,
1432
1790
  addTab, closeTab, activateTab, reorderTab, closeAllTabs, hydrateTabs,
1433
1791
  createFile, createDirectory, unzipHere, uploadFiles, dispatchUpload, clearUploadError,
1434
1792
  deleteEntry, moveEntry, saveFile, reloadTabFromDisk,