@bevel-software/platform-core-frontend 0.15.1 → 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 (346) hide show
  1. package/THIRD-PARTY-NOTICES.md +2 -2
  2. package/package.json +3 -3
  3. package/src/core/CoreAppShell.tsx +16 -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__/ConnectionKeysPage.test.tsx +266 -0
  32. package/src/modules/admin/__tests__/DirectoryGroupsPage.suggest.test.tsx +182 -0
  33. package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +165 -14
  34. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +401 -4
  35. package/src/modules/admin/__tests__/group-members-path.test.ts +27 -0
  36. package/src/modules/admin/components/AddMemberInput.tsx +268 -0
  37. package/src/modules/admin/components/AdminRolesPage.tsx +97 -132
  38. package/src/modules/admin/components/ConnectionKeysPage.tsx +269 -0
  39. package/src/modules/admin/components/DirectoryGroupsPage.tsx +91 -39
  40. package/src/modules/admin/components/UserAccountsPage.tsx +271 -37
  41. package/src/modules/admin/components/connection-keys-grouping.ts +43 -0
  42. package/src/modules/admin/components/group-members-path.ts +32 -0
  43. package/src/modules/admin/services/connection-keys.api.ts +47 -0
  44. package/src/modules/admin/services/roles.api.ts +12 -1
  45. package/src/modules/auth/__tests__/AccountPage.test.tsx +50 -2
  46. package/src/modules/auth/components/AccountPage.tsx +73 -54
  47. package/src/modules/auth/components/LoginScreen.tsx +1 -0
  48. package/src/modules/auth/services/account.api.ts +78 -4
  49. package/src/modules/change-requests/__tests__/ChangeRequestDialog.access-rules.test.tsx +144 -0
  50. package/src/modules/change-requests/__tests__/ChangeRequestDialog.binary.test.tsx +422 -0
  51. package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +431 -0
  52. package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +193 -0
  53. package/src/modules/change-requests/__tests__/ChangeRequestDialog.initial-file.test.tsx +142 -0
  54. package/src/modules/change-requests/__tests__/ChangeRequestDialog.moved.test.tsx +202 -0
  55. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +205 -13
  56. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +271 -0
  57. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +208 -0
  58. package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +286 -0
  59. package/src/modules/change-requests/__tests__/propose.concurrent.test.ts +273 -0
  60. package/src/modules/change-requests/__tests__/readFailure.test.ts +122 -0
  61. package/src/modules/change-requests/__tests__/useCrFileDiffs.test.tsx +238 -0
  62. package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +56 -1
  63. package/src/modules/change-requests/__tests__/useForkPointFile.test.tsx +79 -0
  64. package/src/modules/change-requests/components/BranchFilePreview.tsx +357 -0
  65. package/src/modules/change-requests/components/ChangeBox.tsx +31 -2
  66. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +862 -72
  67. package/src/modules/change-requests/components/CrFileTree.tsx +74 -58
  68. package/src/modules/change-requests/components/FileChangeBoxes.tsx +19 -15
  69. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +41 -7
  70. package/src/modules/change-requests/hooks/useCrFileDiffs.ts +181 -23
  71. package/src/modules/change-requests/hooks/useFileOnBranch.ts +70 -7
  72. package/src/modules/change-requests/hooks/useForkPointFile.ts +77 -0
  73. package/src/modules/change-requests/services/change-requests.api.ts +57 -1
  74. package/src/modules/change-requests/services/denied-file.api.ts +53 -0
  75. package/src/modules/change-requests/services/propose.api.ts +97 -8
  76. package/src/modules/change-requests/utils/approval.ts +15 -0
  77. package/src/modules/change-requests/utils/author.ts +32 -0
  78. package/src/modules/change-requests/utils/readFailure.ts +110 -0
  79. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +20 -0
  80. package/src/modules/git/components/FileHistoryPanel.tsx +5 -0
  81. package/src/modules/git/components/PullRequestsForMe.tsx +51 -24
  82. package/src/modules/git/services/__tests__/error-messages.test.ts +29 -0
  83. package/src/modules/git/services/error-messages.ts +12 -0
  84. package/src/modules/git/services/pr-prompts.ts +5 -5
  85. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +401 -0
  86. package/src/modules/layout/__tests__/SidebarFooterGrid.test.tsx +286 -0
  87. package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +61 -0
  88. package/src/modules/layout/components/AppLayout.tsx +2 -0
  89. package/src/modules/layout/components/MobileChatLayout.tsx +4 -1
  90. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +4 -1
  91. package/src/modules/layout/components/SidebarFrame.tsx +108 -3
  92. package/src/modules/library/__tests__/AddToPluginDialog.test.tsx +171 -5
  93. package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +356 -0
  94. package/src/modules/library/__tests__/IntegrationsSetupReminder.test.tsx +60 -0
  95. package/src/modules/library/__tests__/LibraryCard.test.tsx +91 -10
  96. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +242 -107
  97. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +103 -98
  98. package/src/modules/library/__tests__/LinkSkillPanel.test.tsx +20 -5
  99. package/src/modules/library/__tests__/LockedPluginView.test.tsx +97 -7
  100. package/src/modules/library/__tests__/NewPluginDialog.test.tsx +13 -4
  101. package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +79 -3
  102. package/src/modules/library/__tests__/PersonalPluginPage.test.tsx +201 -0
  103. package/src/modules/library/__tests__/PluginExtras.test.tsx +100 -9
  104. package/src/modules/library/__tests__/PluginJoinRequests.test.tsx +60 -1
  105. package/src/modules/library/__tests__/PluginPage.test.tsx +258 -6
  106. package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +16 -56
  107. package/src/modules/library/__tests__/PluginsSidebar.test.tsx +155 -152
  108. package/src/modules/library/__tests__/PluginsSidebarMenu.test.tsx +16 -0
  109. package/src/modules/library/__tests__/SharedViaPlugins.test.tsx +106 -0
  110. package/src/modules/library/__tests__/SkillPage.test.tsx +386 -80
  111. package/src/modules/library/__tests__/SkillsTree.test.tsx +293 -4
  112. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +582 -71
  113. package/src/modules/library/__tests__/ToolPage.test.tsx +87 -4
  114. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +173 -26
  115. package/src/modules/library/__tests__/auth-harness.tsx +9 -9
  116. package/src/modules/library/__tests__/card-row-menu.test.tsx +320 -0
  117. package/src/modules/library/__tests__/library-data.mapping.test.tsx +98 -0
  118. package/src/modules/library/__tests__/library-data.stale.test.tsx +121 -28
  119. package/src/modules/library/__tests__/library-data.test.ts +7 -0
  120. package/src/modules/library/__tests__/library-paths.test.ts +47 -4
  121. package/src/modules/library/__tests__/link-membership.test.ts +13 -4
  122. package/src/modules/library/__tests__/name-with-badges.test.tsx +273 -0
  123. package/src/modules/library/__tests__/newSkillMarkdown.test.ts +30 -0
  124. package/src/modules/library/__tests__/owner-pill.test.tsx +357 -0
  125. package/src/modules/library/__tests__/pending-tools.test.tsx +400 -0
  126. package/src/modules/library/__tests__/plugin-entries.test.ts +122 -0
  127. package/src/modules/library/__tests__/plugin-summary.test.ts +36 -1
  128. package/src/modules/library/__tests__/status.test.ts +82 -2
  129. package/src/modules/library/__tests__/tools.api.test.ts +44 -1
  130. package/src/modules/library/components/AccessRequestsBanner.tsx +85 -47
  131. package/src/modules/library/components/AddDialogTabs.tsx +103 -0
  132. package/src/modules/library/components/AddToPluginDialog.tsx +74 -18
  133. package/src/modules/library/components/IntegrationsSetupReminder.tsx +59 -0
  134. package/src/modules/library/components/ItemActionsMenu.tsx +288 -0
  135. package/src/modules/library/components/LibraryCard.tsx +146 -45
  136. package/src/modules/library/components/LibraryLayout.tsx +119 -256
  137. package/src/modules/library/components/LibraryPage.tsx +172 -39
  138. package/src/modules/library/components/LinkSkillPanel.tsx +1 -3
  139. package/src/modules/library/components/LockedPluginView.tsx +62 -34
  140. package/src/modules/library/components/NameWithBadges.tsx +164 -0
  141. package/src/modules/library/components/NewPluginDialog.tsx +16 -2
  142. package/src/modules/library/components/PageActions.tsx +11 -9
  143. package/src/modules/library/components/{PendingSkillReview.tsx → PendingItemReview.tsx} +14 -7
  144. package/src/modules/library/components/PersonalAddDialog.tsx +68 -18
  145. package/src/modules/library/components/PersonalPluginPage.tsx +121 -22
  146. package/src/modules/library/components/PluginExtras.tsx +140 -17
  147. package/src/modules/library/components/PluginIndexRow.tsx +47 -12
  148. package/src/modules/library/components/PluginPage.tsx +157 -41
  149. package/src/modules/library/components/PluginRows.tsx +286 -0
  150. package/src/modules/library/components/PluginsSidebar.tsx +239 -263
  151. package/src/modules/library/components/PluginsSidebarMenu.tsx +26 -1
  152. package/src/modules/library/components/ShareButton.tsx +17 -0
  153. package/src/modules/library/components/SkillsTree.tsx +141 -28
  154. package/src/modules/library/components/TeamRoute.tsx +15 -0
  155. package/src/modules/library/components/__tests__/upload-notices-once-per-page.test.tsx +144 -0
  156. package/src/modules/library/components/plugin-page-parts.tsx +103 -17
  157. package/src/modules/library/components/skill-page/SharedViaPlugins.tsx +6 -12
  158. package/src/modules/library/components/skill-page/SkillFilePane.tsx +5 -0
  159. package/src/modules/library/components/skill-page/SkillPage.tsx +274 -122
  160. package/src/modules/library/components/tool-page/DeleteToolDialog.tsx +218 -0
  161. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +79 -178
  162. package/src/modules/library/components/tool-page/ToolPage.tsx +106 -16
  163. package/src/modules/library/components/tool-page/ToolVarRow.tsx +42 -41
  164. package/src/modules/library/hooks/__tests__/useLibraryData.test.ts +98 -0
  165. package/src/modules/library/hooks/useLibraryData.ts +92 -19
  166. package/src/modules/library/routes/LibraryRoutes.tsx +14 -11
  167. package/src/modules/library/routes/WorkspaceItemRoute.tsx +77 -27
  168. package/src/modules/library/routes/library-paths.ts +26 -28
  169. package/src/modules/library/services/library.api.ts +38 -20
  170. package/src/modules/library/services/plugins.api.ts +69 -8
  171. package/src/modules/library/services/teams.api.ts +15 -0
  172. package/src/modules/library/services/tools.api.ts +78 -0
  173. package/src/modules/library/state/library-data.tsx +170 -32
  174. package/src/modules/library/utils/personal-plugin.ts +13 -15
  175. package/src/modules/library/utils/plugin-entries.ts +134 -0
  176. package/src/modules/library/utils/plugin-summary.ts +75 -9
  177. package/src/modules/library/utils/status.ts +135 -33
  178. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +8 -1
  179. package/src/modules/onboarding/__tests__/onboarding.test.tsx +853 -760
  180. package/src/modules/onboarding/agent-clients.ts +55 -23
  181. package/src/modules/onboarding/components/ConnectAgentPill.tsx +5 -1
  182. package/src/modules/onboarding/components/WelcomePage.tsx +98 -62
  183. package/src/modules/pr/services/pr-merge.api.ts +2 -1
  184. package/src/modules/review/components/MarkdownDiffViewer.tsx +53 -8
  185. package/src/modules/review/components/ReviewPanel.tsx +15 -17
  186. package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +64 -0
  187. package/src/modules/review/components/__tests__/ReviewPanel.test.tsx +25 -1
  188. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +454 -117
  189. package/src/modules/secrets-vault/components/SecretsPage.tsx +48 -7
  190. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +84 -5
  191. package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +425 -0
  192. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +417 -82
  193. package/src/modules/secrets-vault/components/__tests__/ToolSecretsPanel.test.tsx +105 -0
  194. package/src/modules/secrets-vault/components/__tests__/connect-lists-what-the-banner-counted.test.tsx +407 -0
  195. package/src/modules/secrets-vault/probe/SavedKeyProbeResult.tsx +98 -0
  196. package/src/modules/secrets-vault/probe/__tests__/probe-verdict.test.ts +160 -0
  197. package/src/modules/secrets-vault/probe/probe-verdict.ts +108 -0
  198. package/src/modules/secrets-vault/probe/useSavedKeyProbe.ts +228 -0
  199. package/src/modules/secrets-vault/services/connect.api.ts +36 -5
  200. package/src/modules/secrets-vault/utils/connect-status.ts +98 -0
  201. package/src/modules/settings/components/ClaudeConnectionCard.tsx +9 -24
  202. package/src/modules/settings/components/ClaudeConnectionFields.tsx +23 -0
  203. package/src/modules/settings/components/DeploymentPage.tsx +10 -30
  204. package/src/modules/settings/components/MarketplaceSection.tsx +152 -0
  205. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +67 -4
  206. package/src/modules/settings/components/__tests__/MarketplaceSection.test.tsx +325 -0
  207. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +5 -5
  208. package/src/modules/settings/services/github-facade.api.ts +23 -0
  209. package/src/modules/settings/settings-nav-items.tsx +10 -2
  210. package/src/modules/setup/__tests__/setup.oidc.test.tsx +172 -0
  211. package/src/modules/setup/__tests__/setup.probe-refusal.test.tsx +123 -0
  212. package/src/modules/setup/__tests__/setup.test.tsx +497 -4
  213. package/src/modules/setup/__tests__/useSetupStatus.test.tsx +130 -0
  214. package/src/modules/setup/components/SetupGate.tsx +16 -16
  215. package/src/modules/setup/components/SetupScreen.tsx +521 -43
  216. package/src/modules/setup/hooks/useSetupStatus.ts +93 -0
  217. package/src/modules/setup/services/setup.api.ts +140 -3
  218. package/src/modules/setup/utils/__tests__/root-folders.test.ts +72 -0
  219. package/src/modules/setup/utils/root-folders.ts +46 -0
  220. package/src/modules/toolbar/assets/claude-setup/01-add-manually.webp +0 -0
  221. package/src/modules/toolbar/assets/claude-setup/02-add-configuration.webp +0 -0
  222. package/src/modules/toolbar/assets/claude-setup/03-connect-account.webp +0 -0
  223. package/src/modules/toolbar/assets/claude-setup/04-pick-instance.webp +0 -0
  224. package/src/modules/toolbar/assets/claude-setup/05-plugins-add.webp +0 -0
  225. package/src/modules/toolbar/assets/claude-setup/06-add-marketplace.webp +0 -0
  226. package/src/modules/toolbar/assets/claude-setup/07-paste-url-sync.webp +0 -0
  227. package/src/modules/toolbar/assets/claude-setup/08-install-plugins.webp +0 -0
  228. package/src/modules/toolbar/assets/claude-setup/09-select-repository.webp +0 -0
  229. package/src/modules/toolbar/assets/claude-setup/10-connector-not-added.webp +0 -0
  230. package/src/modules/toolbar/assets/claude-setup/11-add-custom-connector.webp +0 -0
  231. package/src/modules/toolbar/assets/claude-setup/README.md +68 -0
  232. package/src/modules/toolbar/components/AgentInstructionsCard.tsx +296 -0
  233. package/src/modules/toolbar/components/ClaudeMarketplaceCarousel.tsx +107 -0
  234. package/src/modules/toolbar/components/ClaudeRegistrationSteps.tsx +127 -0
  235. package/src/modules/toolbar/components/CoworkSetupSteps.tsx +100 -0
  236. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +177 -118
  237. package/src/modules/toolbar/components/ScreenshotStep.tsx +77 -0
  238. package/src/modules/toolbar/components/SetupCarousel.tsx +177 -0
  239. package/src/modules/toolbar/components/__tests__/AgentInstructionsCard.test.tsx +370 -0
  240. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +542 -42
  241. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +2 -2
  242. package/src/modules/toolbar/components/__tests__/claude-setup-shots.test.ts +104 -0
  243. package/src/modules/toolbar/components/claude-connector-slide.tsx +38 -0
  244. package/src/modules/toolbar/components/claude-setup-shots.ts +167 -0
  245. package/src/modules/toolbar/components/deployment-address.ts +29 -0
  246. package/src/modules/toolbar/components/setup-step-parts.tsx +35 -0
  247. package/src/modules/toolbar/services/__tests__/agent-instructions.api.test.ts +89 -0
  248. package/src/modules/toolbar/services/agent-instructions.api.ts +167 -0
  249. package/src/modules/toolbar/services/external-api-keys.api.ts +6 -0
  250. package/src/modules/workflow/state/ChangeRequestStaleBinder.tsx +43 -0
  251. package/src/modules/workflow/state/EventBusProvider.tsx +122 -11
  252. package/src/modules/workflow/state/__tests__/EventBusProvider.storage.test.tsx +87 -0
  253. package/src/modules/workflow/state/__tests__/EventBusProvider.watch.test.tsx +223 -0
  254. package/src/modules/workflow/state/event-bus.context.ts +10 -0
  255. package/src/modules/workspace/__tests__/testFixtures.ts +5 -3
  256. package/src/modules/workspace/components/FileExplorer.tsx +1295 -191
  257. package/src/modules/workspace/components/FileRoute.tsx +353 -36
  258. package/src/modules/workspace/components/FileViewer.tsx +166 -45
  259. package/src/modules/workspace/components/KbDocumentShell.tsx +50 -6
  260. package/src/modules/workspace/components/KbPageHeader.tsx +120 -55
  261. package/src/modules/workspace/components/TreeActionConfirm.tsx +350 -0
  262. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +2473 -129
  263. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +731 -18
  264. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +331 -12
  265. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +39 -0
  266. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +33 -20
  267. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +4 -5
  268. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +13 -4
  269. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +4 -3
  270. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +8 -14
  271. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +75 -16
  272. package/src/modules/workspace/components/renderers/KbImage.tsx +180 -0
  273. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +22 -6
  274. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +48 -22
  275. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +4 -5
  276. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +4 -3
  277. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +4 -3
  278. package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +12 -0
  279. package/src/modules/workspace/components/renderers/__tests__/DownloadFileButton.test.tsx +57 -9
  280. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.test.tsx +13 -1
  281. package/src/modules/workspace/components/renderers/__tests__/ImageRenderer.test.tsx +163 -0
  282. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +237 -0
  283. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +108 -14
  284. package/src/modules/workspace/components/renderers/__tests__/PptxRenderer.test.tsx +14 -1
  285. package/src/modules/workspace/components/renderers/__tests__/XlsxRenderer.test.tsx +16 -1
  286. package/src/modules/workspace/components/renderers/__tests__/rendererSelection.test.tsx +66 -1
  287. package/src/modules/workspace/components/renderers/index.ts +53 -2
  288. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +25 -4
  289. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +40 -0
  290. package/src/modules/workspace/hooks/__tests__/useImageRevision.test.tsx +174 -0
  291. package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +179 -1
  292. package/src/modules/workspace/hooks/__tests__/useWorkspaceImageResolver.test.tsx +122 -0
  293. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +892 -7
  294. package/src/modules/workspace/hooks/useImageRevision.ts +101 -0
  295. package/src/modules/workspace/hooks/useMergedWorkspaceTree.ts +22 -3
  296. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +55 -0
  297. package/src/modules/workspace/hooks/useWorkspaceState.ts +424 -66
  298. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +279 -3
  299. package/src/modules/workspace/routing/kb-routes.ts +206 -29
  300. package/src/modules/workspace/services/__tests__/workspace.api.test.ts +57 -1
  301. package/src/modules/workspace/services/workspace.api.ts +57 -4
  302. package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +343 -0
  303. package/src/modules/workspace/state/__tests__/upload-lands-where-it-was-dropped.test.tsx +158 -0
  304. package/src/modules/workspace/state/open-change-requests.tsx +100 -12
  305. package/src/modules/workspace/state/workspace.context.ts +125 -19
  306. package/src/modules/workspace/utils/__tests__/file-trace.test.ts +73 -0
  307. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +220 -6
  308. package/src/modules/workspace/utils/__tests__/pasteLink.test.ts +76 -0
  309. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +364 -0
  310. package/src/modules/workspace/utils/__tests__/uploadError.test.ts +35 -0
  311. package/src/modules/workspace/utils/file-trace.ts +50 -0
  312. package/src/modules/workspace/utils/fileTree.ts +112 -36
  313. package/src/modules/workspace/utils/frontmatter.ts +8 -4
  314. package/src/modules/workspace/utils/pasteLink.ts +90 -0
  315. package/src/modules/workspace/utils/treeConfirm.ts +338 -0
  316. package/src/modules/workspace/utils/uploadError.ts +29 -0
  317. package/src/shared/__tests__/marketplace-url.test.ts +6 -1
  318. package/src/shared/components/Button.tsx +16 -2
  319. package/src/shared/components/Dialog.tsx +27 -11
  320. package/src/shared/components/Menu.tsx +13 -1
  321. package/src/shared/components/PageShell.tsx +13 -8
  322. package/src/shared/components/__tests__/primitives.test.tsx +116 -2
  323. package/src/shared/components/__tests__/useFocusHandoff.test.tsx +192 -0
  324. package/src/shared/components/index.ts +2 -0
  325. package/src/shared/components/useDismissableMenu.ts +32 -10
  326. package/src/shared/components/useFocusHandoff.ts +51 -0
  327. package/src/shared/components/useLatestRef.ts +28 -0
  328. package/src/shared/markdown/Markdown.tsx +12 -3
  329. package/src/shared/markdown/__tests__/escapeSpacesInLinkDestinations.test.ts +39 -0
  330. package/src/shared/markdown/hrefs.ts +50 -0
  331. package/src/shared/marketplace-url.ts +33 -5
  332. package/src/shared/mcp/ChatGptInstallLink.tsx +3 -3
  333. package/src/shared/mcp/ConnectionInstructions.tsx +38 -27
  334. package/src/shared/mcp/__tests__/connect-snippets.test.ts +3 -3
  335. package/src/shared/mcp/connect-snippets.ts +14 -9
  336. package/src/shared/mcp/index.ts +1 -1
  337. package/src/shared/theme/__tests__/header-band.test.ts +197 -0
  338. package/src/shared/theme/header.ts +75 -0
  339. package/src/shared/theme/measure.ts +7 -4
  340. package/src/shared/theme/tokens.css +25 -0
  341. package/src/modules/library/__tests__/PluginsIndexPage.test.tsx +0 -363
  342. package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +0 -97
  343. package/src/modules/library/components/PluginsIndexPage.tsx +0 -270
  344. package/src/modules/update-check/__tests__/UpdateBanner.test.tsx +0 -126
  345. package/src/modules/update-check/components/UpdateBanner.tsx +0 -92
  346. package/src/modules/update-check/services/update-check.api.ts +0 -24
@@ -3,12 +3,15 @@ import { renderHook } from '@testing-library/react';
3
3
  import { GitContext, type GitContextValue } from '../../../git/state/git.context';
4
4
  import { WorkspaceContext } from '../../state/workspace.context';
5
5
  import { makeWorkspaceFixture } from '../../__tests__/testFixtures';
6
- import { useFileNav } from '../kb-routes';
6
+ import { useFileNav, resolveKbHref } from '../kb-routes';
7
7
 
8
- // Capture what openFile navigates to.
8
+ // Capture what openFile navigates to, and stand in for the URL it reads the
9
+ // branch out of.
9
10
  const navigateMock = vi.hoisted(() => vi.fn());
11
+ const routerMock = vi.hoisted(() => ({ pathname: '/' }));
10
12
  vi.mock('react-router-dom', () => ({
11
13
  useNavigate: () => navigateMock,
14
+ useLocation: () => ({ pathname: routerMock.pathname, search: '', hash: '', state: null, key: 'k' }),
12
15
  }));
13
16
 
14
17
  function gitOnBranch(branch: string): GitContextValue {
@@ -30,7 +33,17 @@ function gitOnBranch(branch: string): GitContextValue {
30
33
  };
31
34
  }
32
35
 
33
- function renderNav(branch: string, kbDirName: string | null = 'knowledge-base') {
36
+ /**
37
+ * `branch` is what git status reports; `pathname` is the URL the app is on.
38
+ * They agree except mid-switch, which is what the switch tests below exercise.
39
+ * Default: a URL outside `/workspace`, so the status is the only branch there is.
40
+ */
41
+ function renderNav(
42
+ branch: string,
43
+ kbDirName: string | null = 'knowledge-base',
44
+ pathname = '/',
45
+ ) {
46
+ routerMock.pathname = pathname;
34
47
  return renderHook(() => useFileNav(), {
35
48
  wrapper: ({ children }) => (
36
49
  <GitContext.Provider value={gitOnBranch(branch)}>
@@ -122,3 +135,266 @@ describe('useFileNav.openFile', () => {
122
135
  );
123
136
  });
124
137
  });
138
+
139
+ /**
140
+ * The one grammar for a link or image destination. Link handlers and image
141
+ * resolvers both go through it, so a case here is a case for every surface.
142
+ */
143
+ describe('resolveKbHref', () => {
144
+ const opts = { basePath: 'knowledge-base/Knowledge/Sub/Foo.md', kbDirName: 'knowledge-base' };
145
+
146
+ it('classifies an http(s) URL as external', () => {
147
+ expect(resolveKbHref('https://example.com/a.png', opts)).toEqual({ kind: 'external' });
148
+ expect(resolveKbHref('http://example.com/x.md', opts)).toEqual({ kind: 'external' });
149
+ });
150
+
151
+ it('classifies a protocol-relative URL as external', () => {
152
+ expect(resolveKbHref('//cdn.example.com/a.png', opts)).toEqual({ kind: 'external' });
153
+ });
154
+
155
+ it('parses an absolute app URL into its own branch, path and anchor', () => {
156
+ expect(
157
+ resolveKbHref('/workspace/target-company-state/knowledge-base/GTM/Bundle.md#status', opts),
158
+ ).toEqual({
159
+ kind: 'workspace',
160
+ branch: 'target-company-state',
161
+ path: 'knowledge-base/GTM/Bundle.md',
162
+ hash: '#status',
163
+ });
164
+ });
165
+
166
+ it('repairs a junk segment before the kbDirName in an absolute URL, and decodes the branch', () => {
167
+ expect(
168
+ resolveKbHref('/workspace/alice%2Fdraft/bevel-process-of-truth/knowledge-base/x.md', opts),
169
+ ).toEqual({ kind: 'workspace', branch: 'alice/draft', path: 'knowledge-base/x.md', hash: '' });
170
+ });
171
+
172
+ it('resolves a relative destination against the base file, keeping the anchor', () => {
173
+ expect(resolveKbHref('../NodeTypes/Process.md#goal', opts)).toEqual({
174
+ kind: 'workspace',
175
+ branch: null,
176
+ path: 'knowledge-base/Knowledge/NodeTypes/Process.md',
177
+ hash: '#goal',
178
+ });
179
+ expect(resolveKbHref('./assets/shot.png', opts)).toEqual({
180
+ kind: 'workspace',
181
+ branch: null,
182
+ path: 'knowledge-base/Knowledge/Sub/assets/shot.png',
183
+ hash: '',
184
+ });
185
+ });
186
+
187
+ it('anchors a root-relative destination at the workspace root', () => {
188
+ expect(resolveKbHref('/knowledge-base/assets/x.png', opts)).toMatchObject({
189
+ kind: 'workspace',
190
+ path: 'knowledge-base/assets/x.png',
191
+ });
192
+ });
193
+
194
+ it('decodes percent-escapes, and leaves a malformed one as written', () => {
195
+ expect(resolveKbHref('Some%20File.md', opts)).toMatchObject({
196
+ path: 'knowledge-base/Knowledge/Sub/Some File.md',
197
+ });
198
+ expect(resolveKbHref('100%.md', opts)).toMatchObject({
199
+ path: 'knowledge-base/Knowledge/Sub/100%.md',
200
+ });
201
+ });
202
+
203
+ // Any scheme is external, not only the web ones: an app's own (`sms:`,
204
+ // `geo:`, `x-devonthink-item:`) names no workspace file either. A bare
205
+ // colon-name would read as a scheme too, but both sanitizers drop an href
206
+ // with a scheme they do not know before the pipeline sees it; a path with a
207
+ // segment before the colon is still a path.
208
+ it('classifies any scheme as external, and keeps a colon inside a path segment', () => {
209
+ for (const href of ['sms:555', 'geo:0,0', 'about:config', 'x-devonthink-item://abc']) {
210
+ expect(resolveKbHref(href, opts)).toEqual({ kind: 'external' });
211
+ }
212
+ expect(resolveKbHref('./Notes: today.md', opts)).toMatchObject({
213
+ kind: 'workspace',
214
+ path: 'knowledge-base/Knowledge/Sub/Notes: today.md',
215
+ });
216
+ });
217
+
218
+ it('returns null for an empty destination', () => {
219
+ expect(resolveKbHref('', opts)).toBeNull();
220
+ });
221
+
222
+ // Without a same-document row the empty location falls through to
223
+ // `resolveRelativePath`, which drops the file segment off the base path: a
224
+ // reader clicking a section link lands on the folder listing instead of
225
+ // scrolling down the page they are on.
226
+ it('resolves a bare anchor to the file it sits in, not to its parent folder', () => {
227
+ expect(resolveKbHref('#overview', opts)).toEqual({
228
+ kind: 'workspace',
229
+ branch: null,
230
+ path: 'knowledge-base/Knowledge/Sub/Foo.md',
231
+ hash: '#overview',
232
+ });
233
+ });
234
+
235
+ // The junk-segment repair exists for a LINK a model may have mangled. An
236
+ // image src is a path an author wrote, and the repair rewrites any path
237
+ // whose later segment happens to equal the KB dir — so on a correctly
238
+ // authored `./assets/knowledge-base/shot.png` it truncates a real path into
239
+ // a 404 and the reader gets a placeholder where a picture belongs.
240
+ it('leaves a path alone when the repair is off, even one with a kbDirName segment in it', () => {
241
+ // A skill's own file, holding a picture in a folder the author happened to
242
+ // name after the KB dir.
243
+ const inSkill = { basePath: 'Skills/deploy/SKILL.md', kbDirName: 'knowledge-base' };
244
+ const href = './assets/knowledge-base/shot.png';
245
+ expect(resolveKbHref(href, { ...inSkill, repairMangledPath: false })).toEqual({
246
+ kind: 'workspace',
247
+ branch: null,
248
+ path: 'Skills/deploy/assets/knowledge-base/shot.png',
249
+ hash: '',
250
+ });
251
+ // The SAME destination with the repair on: everything before the later
252
+ // `knowledge-base` segment is dropped and the picture 404s. Right for a
253
+ // citation link a model mangled, wrong for a path its author wrote.
254
+ expect(resolveKbHref(href, inSkill)).toEqual({
255
+ kind: 'workspace',
256
+ branch: null,
257
+ path: 'knowledge-base/shot.png',
258
+ hash: '',
259
+ });
260
+ });
261
+
262
+ it('leaves an absolute URL path alone when the repair is off', () => {
263
+ const href = '/workspace/main/assets/knowledge-base/shot.png';
264
+ expect(resolveKbHref(href, { ...opts, repairMangledPath: false })).toEqual({
265
+ kind: 'workspace',
266
+ branch: 'main',
267
+ path: 'assets/knowledge-base/shot.png',
268
+ hash: '',
269
+ });
270
+ });
271
+ });
272
+
273
+ describe('useFileNav.openLink', () => {
274
+ it('opens a relative link on the current branch, decoded and resolved against the file it sits in', () => {
275
+ navigateMock.mockClear();
276
+ const { result } = renderNav('alice/draft');
277
+ result.current.openLink('Some%20File.md#goal', 'knowledge-base/Knowledge/Foo.md');
278
+ expect(navigateMock).toHaveBeenCalledWith(
279
+ '/workspace/alice%2Fdraft/knowledge-base/Knowledge/Some%20File.md#goal',
280
+ );
281
+ });
282
+
283
+ // The branch rule: a link keeps the branch its URL names.
284
+ it('keeps the branch of an absolute app URL', () => {
285
+ navigateMock.mockClear();
286
+ const { result } = renderNav('alice/draft');
287
+ result.current.openLink(
288
+ '/workspace/target-company-state/knowledge-base/x.md',
289
+ 'knowledge-base/Knowledge/Foo.md',
290
+ );
291
+ expect(navigateMock).toHaveBeenCalledWith('/workspace/target-company-state/knowledge-base/x.md');
292
+ });
293
+
294
+ // Every caller reaches `openLink` by CANCELLING the browser's navigation
295
+ // first — the HTML sandbox `preventDefault`s each anchor and posts the href
296
+ // up, the frontmatter panel does the same. So "leave it to the browser" is
297
+ // not deference here, it is a dead click.
298
+ it('opens an external link in a new tab rather than dropping it', () => {
299
+ navigateMock.mockClear();
300
+ const open = vi.spyOn(window, 'open').mockReturnValue(null);
301
+ const { result } = renderNav('alice/draft');
302
+ result.current.openLink('https://example.com/x.md', 'knowledge-base/Knowledge/Foo.md');
303
+ expect(open).toHaveBeenCalledWith('https://example.com/x.md', '_blank', 'noopener,noreferrer');
304
+ expect(navigateMock).not.toHaveBeenCalled();
305
+ open.mockRestore();
306
+ });
307
+
308
+ it('opens a mailto: link, which is external and openable', () => {
309
+ const open = vi.spyOn(window, 'open').mockReturnValue(null);
310
+ const { result } = renderNav('alice/draft');
311
+ result.current.openLink('mailto:a@b.com', 'knowledge-base/Knowledge/Foo.md');
312
+ expect(open).toHaveBeenCalledWith('mailto:a@b.com', '_blank', 'noopener,noreferrer');
313
+ open.mockRestore();
314
+ });
315
+
316
+ // `window.open('javascript:…')` runs the script in a document that inherits
317
+ // THIS page's origin. Agent HTML can call `bevel.navigate(anyString)`
318
+ // directly, so the bridge is reachable with a string no sanitizer saw — the
319
+ // allowlist is what keeps the sandbox a sandbox.
320
+ it('refuses to open a javascript: destination, so the HTML sandbox stays sealed', () => {
321
+ navigateMock.mockClear();
322
+ const open = vi.spyOn(window, 'open').mockReturnValue(null);
323
+ const { result } = renderNav('alice/draft');
324
+ result.current.openLink('javascript:alert(1)', 'knowledge-base/Knowledge/Foo.md');
325
+ expect(open).not.toHaveBeenCalled();
326
+ expect(navigateMock).not.toHaveBeenCalled();
327
+ open.mockRestore();
328
+ });
329
+
330
+ it('refuses a data: destination too', () => {
331
+ const open = vi.spyOn(window, 'open').mockReturnValue(null);
332
+ const { result } = renderNav('alice/draft');
333
+ result.current.openLink('data:text/html,<script>x</script>', 'knowledge-base/Knowledge/Foo.md');
334
+ expect(open).not.toHaveBeenCalled();
335
+ open.mockRestore();
336
+ });
337
+
338
+ // A section link is a scroll, not a navigation to somewhere else.
339
+ it('keeps a same-document anchor on the file it sits in', () => {
340
+ navigateMock.mockClear();
341
+ const { result } = renderNav('alice/draft');
342
+ result.current.openLink('#overview', 'knowledge-base/Knowledge/Foo.md');
343
+ expect(navigateMock).toHaveBeenCalledWith(
344
+ '/workspace/alice%2Fdraft/knowledge-base/Knowledge/Foo.md#overview',
345
+ );
346
+ });
347
+ });
348
+
349
+ /**
350
+ * A tree click during a branch switch. `git.status.branch` reports the branch
351
+ * being LEFT until the destination workspace bootstraps and answers, so a
352
+ * click built from it landed the user back on the branch they were leaving —
353
+ * the switch appearing to undo itself. The URL is the authority for which
354
+ * branch is on screen, so the click follows it.
355
+ */
356
+ describe('useFileNav: which branch a click lands on', () => {
357
+ it('opens on the branch the URL is switching TO, not the one git status still reports', () => {
358
+ navigateMock.mockClear();
359
+ const { result } = renderNav(
360
+ 'alice/draft',
361
+ 'knowledge-base',
362
+ '/workspace/target-company-state/knowledge-base/Knowledge/Old.md',
363
+ );
364
+ result.current.openFile('knowledge-base/Knowledge/New.md');
365
+ expect(navigateMock).toHaveBeenCalledWith(
366
+ '/workspace/target-company-state/knowledge-base/Knowledge/New.md',
367
+ );
368
+ });
369
+
370
+ it('decodes the URL branch exactly once — the pathname is still encoded', () => {
371
+ navigateMock.mockClear();
372
+ // `alice%2Fdraft` would prove nothing: decoding it twice gives the same
373
+ // `alice/draft` as decoding it once. This segment survives a second decode
374
+ // visibly — once gives `alice%25`, which re-encodes to the URL below;
375
+ // twice gives `alice%`, which re-encodes to `/workspace/alice%25/…`.
376
+ const { result } = renderNav('main', 'knowledge-base', '/workspace/alice%2525/Knowledge/Old.md');
377
+ result.current.openFile('Knowledge/New.md');
378
+ expect(navigateMock).toHaveBeenCalledWith('/workspace/alice%2525/Knowledge/New.md');
379
+ });
380
+
381
+ it('a relative link during the same switch also follows the URL branch', () => {
382
+ navigateMock.mockClear();
383
+ const { result } = renderNav(
384
+ 'alice/draft',
385
+ 'knowledge-base',
386
+ '/workspace/target-company-state/knowledge-base/Knowledge/Old.md',
387
+ );
388
+ result.current.openLink('./New.md', 'knowledge-base/Knowledge/Old.md');
389
+ expect(navigateMock).toHaveBeenCalledWith(
390
+ '/workspace/target-company-state/knowledge-base/Knowledge/New.md',
391
+ );
392
+ });
393
+
394
+ it('falls back to git status off a workspace route, where the URL names no branch', () => {
395
+ navigateMock.mockClear();
396
+ const { result } = renderNav('alice/draft', 'knowledge-base', '/library/skills');
397
+ result.current.openFile('Knowledge/New.md');
398
+ expect(navigateMock).toHaveBeenCalledWith('/workspace/alice%2Fdraft/Knowledge/New.md');
399
+ });
400
+ });
@@ -1,11 +1,26 @@
1
1
  import { useCallback, useEffect, useState } from 'react';
2
- import { useNavigate } from 'react-router-dom';
2
+ import { useLocation, useNavigate } from 'react-router-dom';
3
3
  import { useGit } from '../../git/state/git.context';
4
4
  import { useWorkspace } from '../state/workspace.context';
5
5
  import { authFetch } from '../../../lib/api';
6
+ import { isExternalHref, isOpenableExternalHref } from '../../../shared/markdown/hrefs';
6
7
 
7
8
  export const KB_ROUTE_PREFIX = '/workspace';
8
9
 
10
+ /**
11
+ * The open change request, in the URL. A proposed row opens the shared
12
+ * change-request dialog AT the file that was clicked, and both halves of
13
+ * that — which request, which file — live in the query so a reload (or a
14
+ * pasted link) lands on the same file of the same request.
15
+ *
16
+ * `CR_FILE_PARAM` is WORKSPACE-relative — the same path space as the route's
17
+ * own segments and as every path the tree holds, so the row that was clicked
18
+ * and the query that records it are the one string. The dialog speaks
19
+ * repo-relative and the conversion happens where it is handed over, once.
20
+ */
21
+ export const CR_PARAM = 'cr';
22
+ export const CR_FILE_PARAM = 'file';
23
+
9
24
  /**
10
25
  * Matches an id-link destination: a bare frontmatter id (`bdl-cpb-service-terms`,
11
26
  * or a snake_case tool/skill id like `my_tool`), optionally followed by a heading
@@ -174,46 +189,208 @@ export function resolveRelativePath(basePath: string, relative: string): string
174
189
  return parts.join('/');
175
190
  }
176
191
 
192
+ /**
193
+ * A link destination as written in a knowledge page, classified and resolved.
194
+ */
195
+ export type KbHref =
196
+ | { kind: 'external' }
197
+ | { kind: 'workspace'; branch: string | null; path: string; hash: string };
198
+
199
+ /**
200
+ * The grammar of a link or image destination, as one function. `basePath` is
201
+ * the file the link sits in; `kbDirName` drives the junk-segment repair.
202
+ *
203
+ * href kind branch path hash
204
+ * ────────────────────────────────────── ───────── ──────── ──────────────────── ──────
205
+ * https://x.y/z, mailto:a@b, tel:… external
206
+ * //cdn.x.y/z (protocol-relative) external
207
+ * /workspace/<b>/<p>#h (absolute app) workspace <b> <p>, junk stripped #h
208
+ * /workspace/<b> workspace <b> ''
209
+ * ../NodeTypes/Process.md#goal workspace null resolved vs basePath #goal
210
+ * /KB/x.png (root-relative) workspace null KB/x.png
211
+ * #overview (same document) workspace null basePath #overview
212
+ * '' (empty) null
213
+ *
214
+ * Percent-escapes are decoded (react-markdown encodes the spaces in a
215
+ * destination; the file on disk has real spaces); a malformed escape is left
216
+ * as-is, the tolerance `safeDecode` has always given the URL form. `branch` is
217
+ * null for a relative link: the caller supplies the branch it is standing on.
218
+ *
219
+ * `repairMangledPath` runs {@link stripJunkBeforeKbDir} on the result. It is on
220
+ * for a LINK, which may have been written by a model that mangled the path,
221
+ * and off for an IMAGE, which was not: the repair rewrites any path whose
222
+ * later segment happens to equal `kbDirName`, so on an image source it
223
+ * truncates a correctly-authored `./assets/knowledge-base/shot.png` down to
224
+ * `knowledge-base/shot.png` and the reader gets a placeholder where a picture
225
+ * belongs. Same reasoning as `openWorkspacePath` below: a destination nobody
226
+ * garbled needs no repair, and applying one can only find the wrong file.
227
+ *
228
+ * THE BRANCH RULE. A link handler navigates with the URL's branch, as
229
+ * `openFile` always has: an absolute citation URL names the branch the cited
230
+ * node lives on. An IMAGE resolver takes the path and ignores the branch: the
231
+ * bytes come from the workspace the page is rendered from, so a cross-branch
232
+ * image URL shows that tree's copy, or the placeholder when there is none.
233
+ * Serving bytes at another branch is the `?ref=` item in TODOS.md.
234
+ */
235
+ export function resolveKbHref(
236
+ href: string,
237
+ {
238
+ basePath,
239
+ kbDirName,
240
+ repairMangledPath = true,
241
+ }: { basePath: string; kbDirName: string | null; repairMangledPath?: boolean },
242
+ ): KbHref | null {
243
+ if (!href) return null;
244
+ if (isExternalHref(href)) return { kind: 'external' };
245
+ const hashIdx = href.indexOf('#');
246
+ const hash = hashIdx >= 0 ? href.slice(hashIdx) : '';
247
+ const location = hashIdx >= 0 ? href.slice(0, hashIdx) : href;
248
+ const repair = (path: string) => (repairMangledPath ? stripJunkBeforeKbDir(path, kbDirName) : path);
249
+ // Same document: `#overview` names a heading in the file the link sits in,
250
+ // not a destination to resolve. Without this row an empty location falls
251
+ // through to `resolveRelativePath`, which drops the file segment off
252
+ // `basePath` and hands the caller the PARENT DIRECTORY — a reader who
253
+ // clicked a section link lands on a folder listing.
254
+ if (!location) return { kind: 'workspace', branch: null, path: basePath, hash };
255
+ if (location.startsWith(`${KB_ROUTE_PREFIX}/`)) {
256
+ const rest = location.slice(KB_ROUTE_PREFIX.length + 1);
257
+ const slashIdx = rest.indexOf('/');
258
+ if (slashIdx < 0) return { kind: 'workspace', branch: safeDecode(rest), path: '', hash };
259
+ return {
260
+ kind: 'workspace',
261
+ branch: safeDecode(rest.slice(0, slashIdx)),
262
+ path: repair(safeDecode(rest.slice(slashIdx + 1))),
263
+ hash,
264
+ };
265
+ }
266
+ return {
267
+ kind: 'workspace',
268
+ branch: null,
269
+ path: repair(resolveRelativePath(basePath, safeDecode(location))),
270
+ hash,
271
+ };
272
+ }
273
+
274
+ /**
275
+ * Open an external destination in a new tab, the one way this app does it.
276
+ * Returns whether it opened, so a caller that resolved a `{ kind: 'external' }`
277
+ * can hand the href over and stop. See {@link isOpenableExternalHref} for why
278
+ * this is an allowlist and not a straight `window.open`.
279
+ */
280
+ export function openExternalHref(href: string): boolean {
281
+ if (!isOpenableExternalHref(href)) return false;
282
+ // Both flags, for different holes: `noopener` severs `window.opener` so the
283
+ // opened page cannot reach back into this one, and `noreferrer` withholds
284
+ // the `Referer` header, which would otherwise carry the workspace URL — a
285
+ // branch name and a file path — to the destination. The markdown pipeline's
286
+ // body links already ship `rel="noopener noreferrer"`; this is the same
287
+ // policy on the scripted path.
288
+ window.open(href, '_blank', 'noopener,noreferrer');
289
+ return true;
290
+ }
291
+
292
+ /**
293
+ * The branch segment of a `/workspace/<branch>/…` pathname, decoded, or null
294
+ * when this location is not a workspace URL. The pathname from the router is
295
+ * still percent-encoded (unlike `useParams`, which decodes for you), so this
296
+ * decodes exactly once. A malformed escape (a name ending in a bare `%`)
297
+ * throws out of `decodeURIComponent`; the raw segment is the honest fallback.
298
+ */
299
+ export function branchFromPathname(pathname: string): string | null {
300
+ if (!pathname.startsWith(`${KB_ROUTE_PREFIX}/`)) return null;
301
+ const segment = pathname.slice(KB_ROUTE_PREFIX.length + 1).split('/')[0];
302
+ return segment ? safeDecode(segment) : null;
303
+ }
304
+
177
305
  export function useFileNav() {
178
306
  const navigate = useNavigate();
307
+ const location = useLocation();
179
308
  const git = useGit();
180
309
  const { kbDirName } = useWorkspace();
181
- const branch = git.status?.branch ?? null;
310
+ // The URL's branch first, the git status second. During a branch switch the
311
+ // status still reports the branch being LEFT — it only catches up once the
312
+ // destination workspace has bootstrapped and answered — so building a click
313
+ // target from it sent the user back to the branch they were leaving, which
314
+ // read as the switch undoing itself. The URL is the app's authority for
315
+ // which branch is on screen (`FileRoute` bootstraps to match it), so a click
316
+ // lands on the branch being switched TO. Off a workspace route there is no
317
+ // branch in the URL and the status is the only answer there is.
318
+ const branch = branchFromPathname(location.pathname) ?? git.status?.branch ?? null;
182
319
 
183
320
  const openFile = useCallback(
184
321
  (pathOrUrl: string) => {
185
- // Split off a trailing heading anchor (`…/Node.md#goal`) so it survives as
186
- // a real URL fragment. Without this, `kbFileUrl` would percent-encode the
187
- // `#` into the path (`Node.md%23goal`) and the deep-link scroll would never
188
- // fire. The fragment is preserved verbatim and re-appended after the
189
- // canonical file URL is built.
322
+ // Absolute workspace URLs (`/workspace/<branch>/<path>`) carry their own
323
+ // branch, which is never overridden with the current one. `resolveKbHref`
324
+ // parses out the branch and path segments and the route is rebuilt via
325
+ // kbFileUrl so encoding is canonical regardless of how the caller
326
+ // produced the URL (literal spaces, mixed encoding, etc.). FileRoute
327
+ // handles the actual git checkout if the URL's branch differs from the
328
+ // current one.
329
+ if (pathOrUrl.startsWith(`${KB_ROUTE_PREFIX}/`)) {
330
+ const target = resolveKbHref(pathOrUrl, { basePath: '', kbDirName });
331
+ if (target?.kind !== 'workspace' || target.branch === null) return;
332
+ navigate(kbFileUrl(target.branch, target.path) + target.hash);
333
+ return;
334
+ }
335
+ // A workspace path the caller has already resolved. Split off a trailing
336
+ // heading anchor (`…/Node.md#goal`) so it survives as a real URL
337
+ // fragment: otherwise `kbFileUrl` would percent-encode the `#` into the
338
+ // path (`Node.md%23goal`) and the deep-link scroll would never fire. Not
339
+ // decoded: this is a path, and a `%` in it is a character in a name.
190
340
  const hashIdx = pathOrUrl.indexOf('#');
191
341
  const hash = hashIdx >= 0 ? pathOrUrl.slice(hashIdx) : '';
192
342
  const path = hashIdx >= 0 ? pathOrUrl.slice(0, hashIdx) : pathOrUrl;
343
+ if (!branch) return;
344
+ navigate(kbFileUrl(branch, stripJunkBeforeKbDir(path, kbDirName)) + hash);
345
+ },
346
+ [branch, kbDirName, navigate],
347
+ );
193
348
 
194
- // Absolute workspace URLs (`/workspace/<branch>/<path>`) carry their
195
- // own branch — never override with the current branch. Parse out the
196
- // branch + path segments and re-route via kbFileUrl so encoding is
197
- // canonical regardless of how the caller produced the URL (literal
198
- // spaces, mixed encoding, etc.). FileRoute handles the actual git
199
- // checkout if the URL's branch differs from the current one.
200
- if (path.startsWith(`${KB_ROUTE_PREFIX}/`)) {
201
- const rest = path.slice(KB_ROUTE_PREFIX.length + 1);
202
- const slashIdx = rest.indexOf('/');
203
- if (slashIdx < 0) {
204
- navigate(kbFileUrl(safeDecode(rest)) + hash);
205
- } else {
206
- navigate(
207
- kbFileUrl(
208
- safeDecode(rest.slice(0, slashIdx)),
209
- stripJunkBeforeKbDir(safeDecode(rest.slice(slashIdx + 1)), kbDirName),
210
- ) + hash,
211
- );
212
- }
349
+ /**
350
+ * Follow a link DESTINATION out of a rendered document: the href as the
351
+ * author wrote it (or as react-markdown encoded it), resolved against
352
+ * `basePath`, the file the link sits in. The one entry for the markdown,
353
+ * HTML and review-diff link handlers, which used to resolve by hand and had
354
+ * drifted (one decoded, one did not). An absolute app URL keeps its own
355
+ * branch; a relative one opens on the branch you are standing on. See
356
+ * {@link resolveKbHref}.
357
+ *
358
+ * AN EXTERNAL LINK IS OPENED HERE TOO, in a new tab. It used to be dropped
359
+ * on the floor — "not ours to open" — which is true of a link the browser
360
+ * still owns, and false of every link that reaches this function. Callers
361
+ * reach it by CANCELLING the browser's own navigation first, and once the
362
+ * default is cancelled, returning without navigating is not deference, it
363
+ * is a dead click. Two surfaces do that:
364
+ *
365
+ * - The frontmatter panel, for a link-valued field.
366
+ * - Agent HTML, via `bevel.navigate(href)` from its own inline script.
367
+ * NOT via an anchor: `sanitizeAgentHtml` strips an `href` that
368
+ * `isInternalNodeLink` rejects, which is every scheme-bearing URL, so
369
+ * an external anchor loses its href before the nav bridge ever sees
370
+ * it. The scripted call is the reachable path, and it is why the
371
+ * allowlist below is load-bearing rather than belt-and-braces: that
372
+ * argument is an arbitrary string no sanitizer inspected.
373
+ *
374
+ * (A markdown BODY link never arrives here: the pipeline renders an
375
+ * external destination as a plain `target="_blank"` anchor and the browser
376
+ * handles it.)
377
+ *
378
+ * `noopener,noreferrer` severs `window.opener` and withholds the workspace
379
+ * URL as a `Referer`, and the scheme allowlist is what keeps the sandbox
380
+ * sealed — see {@link isOpenableExternalHref}. A destination that is
381
+ * external but not openable stays a no-op, as it was.
382
+ */
383
+ const openLink = useCallback(
384
+ (href: string, basePath: string) => {
385
+ const target = resolveKbHref(href, { basePath, kbDirName });
386
+ if (target?.kind === 'external') {
387
+ openExternalHref(href);
213
388
  return;
214
389
  }
215
- if (!branch) return;
216
- navigate(kbFileUrl(branch, stripJunkBeforeKbDir(path, kbDirName)) + hash);
390
+ if (target?.kind !== 'workspace') return;
391
+ const onBranch = target.branch ?? branch;
392
+ if (!onBranch) return;
393
+ navigate(kbFileUrl(onBranch, target.path) + target.hash);
217
394
  },
218
395
  [branch, kbDirName, navigate],
219
396
  );
@@ -245,7 +422,7 @@ export function useFileNav() {
245
422
  navigate(kbFileUrl(branch));
246
423
  }, [branch, navigate]);
247
424
 
248
- return { openFile, openWorkspacePath, closeFile };
425
+ return { openFile, openLink, openWorkspacePath, closeFile };
249
426
  }
250
427
 
251
428
  /**
@@ -6,7 +6,7 @@ vi.mock('../../../../lib/api', () => ({
6
6
  authFetch: vi.fn(),
7
7
  }));
8
8
 
9
- import { uploadFile, createDirectory, WorkspaceApiError } from '../workspace.api';
9
+ import { uploadFile, createDirectory, rawFileUrl, writeFile, WorkspaceApiError } from '../workspace.api';
10
10
  import { authFetch } from '../../../../lib/api';
11
11
 
12
12
  const mockedFetch = vi.mocked(authFetch);
@@ -70,3 +70,59 @@ describe('workspace.api write surface error handling', () => {
70
70
  });
71
71
  });
72
72
  });
73
+
74
+ /** The one builder every raw-route consumer shares, so its shape is pinned once. */
75
+ describe('rawFileUrl', () => {
76
+ it('encodes the path as one query value, so spaces, # and ? in a name round-trip', () => {
77
+ expect(rawFileUrl('ws-1', 'Knowledge/Some File #1?.png')).toBe(
78
+ '/api/workspace/ws-1/file/raw?path=Knowledge%2FSome%20File%20%231%3F.png',
79
+ );
80
+ });
81
+
82
+ it('uses the workspace id verbatim: it is already the encoded branch', () => {
83
+ expect(rawFileUrl('alice%2Fdraft', 'a.png')).toBe('/api/workspace/alice%2Fdraft/file/raw?path=a.png');
84
+ });
85
+
86
+ it('adds the download flag on request', () => {
87
+ expect(rawFileUrl('ws-1', 'a.png', { download: true })).toBe(
88
+ '/api/workspace/ws-1/file/raw?path=a.png&download=1',
89
+ );
90
+ });
91
+
92
+ it('adds a version only once there is one, so an unchanged file keeps a cacheable URL', () => {
93
+ expect(rawFileUrl('ws-1', 'a.png', { version: 0 })).toBe('/api/workspace/ws-1/file/raw?path=a.png');
94
+ expect(rawFileUrl('ws-1', 'a.png', { version: 3 })).toBe('/api/workspace/ws-1/file/raw?path=a.png&v=3');
95
+ });
96
+ });
97
+
98
+ describe('writeFile', () => {
99
+ beforeEach(() => mockedFetch.mockReset());
100
+
101
+ it('hands back the save-time skill warnings, and nothing when there are none', async () => {
102
+ const warning = { entry: 'hubspot.serch', message: 'not a tool', suggestion: 'hubspot.search' };
103
+ mockedFetch.mockResolvedValueOnce({
104
+ ok: true,
105
+ status: 200,
106
+ json: async () => ({ status: 'written', warnings: [warning] }),
107
+ } as unknown as Response);
108
+ await expect(writeFile('ws', 'kb/Plugins/a/SKILL.md', 'x')).resolves.toEqual({ warnings: [warning] });
109
+
110
+ // The usual answer: a body with no `warnings` key at all.
111
+ mockedFetch.mockResolvedValueOnce({
112
+ ok: true,
113
+ status: 200,
114
+ json: async () => ({ status: 'written' }),
115
+ } as unknown as Response);
116
+ await expect(writeFile('ws', 'kb/Plugins/a/SKILL.md', 'x')).resolves.toEqual({});
117
+
118
+ // A backend built before the check existed answers with no body worth reading.
119
+ mockedFetch.mockResolvedValueOnce({
120
+ ok: true,
121
+ status: 200,
122
+ json: async () => {
123
+ throw new SyntaxError('no body');
124
+ },
125
+ } as unknown as Response);
126
+ await expect(writeFile('ws', 'kb/notes.md', 'x')).resolves.toEqual({});
127
+ });
128
+ });