@bevel-software/platform-core-frontend 0.14.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (360) hide show
  1. package/THIRD-PARTY-NOTICES.md +2 -2
  2. package/package.json +3 -3
  3. package/src/core/CoreAppShell.tsx +34 -26
  4. package/src/core/__tests__/AppChrome.test.tsx +0 -3
  5. package/src/core/__tests__/bootstrap.test.ts +33 -1
  6. package/src/core/__tests__/events.test.ts +43 -0
  7. package/src/core/bootstrap.ts +38 -1
  8. package/src/core/events.ts +85 -3
  9. package/src/core/registry.ts +1 -1
  10. package/src/lib/__tests__/api.test.ts +38 -0
  11. package/src/lib/__tests__/email.test.ts +44 -0
  12. package/src/lib/api.ts +19 -2
  13. package/src/lib/email.ts +37 -1
  14. package/src/lib/utils.ts +2 -0
  15. package/src/modules/access/__tests__/ManageAccessDialog.add-row-picking.test.tsx +141 -0
  16. package/src/modules/access/__tests__/ManageAccessDialog.chip-truncation.test.tsx +204 -0
  17. package/src/modules/access/__tests__/ManageAccessDialog.download-read.test.tsx +234 -0
  18. package/src/modules/access/__tests__/ManageAccessDialog.edited-row-visible.test.tsx +160 -0
  19. package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +2 -2
  20. package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +166 -0
  21. package/src/modules/access/__tests__/ManageAccessDialog.restrict.test.tsx +510 -0
  22. package/src/modules/access/__tests__/ManageAccessDialog.row-menu-axes.test.tsx +299 -0
  23. package/src/modules/access/__tests__/ManageAccessDialog.row-menu-width.test.tsx +226 -0
  24. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +781 -76
  25. package/src/modules/access/__tests__/ManageAccessDialog.unknown-email.test.tsx +314 -0
  26. package/src/modules/access/__tests__/manage-access-affordance.test.ts +14 -0
  27. package/src/modules/access/__tests__/plugin-token.test.ts +21 -0
  28. package/src/modules/access/__tests__/tailwindDeclarations.ts +210 -0
  29. package/src/modules/access/api.ts +192 -10
  30. package/src/modules/access/components/ManageAccessDialog.tsx +1337 -570
  31. package/src/modules/access/manage-access-affordance.ts +17 -0
  32. package/src/modules/admin/__tests__/AddMemberInput.test.tsx +297 -0
  33. package/src/modules/admin/__tests__/AdminRolesPage.capabilities.test.tsx +2 -2
  34. package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +189 -0
  35. package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +1 -1
  36. package/src/modules/admin/__tests__/ConnectionKeysPage.test.tsx +266 -0
  37. package/src/modules/admin/__tests__/DirectoryGroupsPage.suggest.test.tsx +182 -0
  38. package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +165 -14
  39. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +401 -4
  40. package/src/modules/admin/__tests__/group-members-path.test.ts +27 -0
  41. package/src/modules/admin/components/AddMemberInput.tsx +268 -0
  42. package/src/modules/admin/components/AdminRolesPage.tsx +97 -132
  43. package/src/modules/admin/components/ConnectionKeysPage.tsx +269 -0
  44. package/src/modules/admin/components/DirectoryGroupsPage.tsx +91 -39
  45. package/src/modules/admin/components/UserAccountsPage.tsx +271 -37
  46. package/src/modules/admin/components/connection-keys-grouping.ts +43 -0
  47. package/src/modules/admin/components/group-members-path.ts +32 -0
  48. package/src/modules/admin/services/connection-keys.api.ts +47 -0
  49. package/src/modules/admin/services/roles.api.ts +12 -1
  50. package/src/modules/auth/__tests__/AccountPage.test.tsx +50 -2
  51. package/src/modules/auth/components/AccountPage.tsx +73 -54
  52. package/src/modules/auth/components/LoginScreen.tsx +1 -0
  53. package/src/modules/auth/services/account.api.ts +78 -4
  54. package/src/modules/change-requests/__tests__/ChangeRequestDialog.access-rules.test.tsx +144 -0
  55. package/src/modules/change-requests/__tests__/ChangeRequestDialog.binary.test.tsx +422 -0
  56. package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +431 -0
  57. package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +193 -0
  58. package/src/modules/change-requests/__tests__/ChangeRequestDialog.initial-file.test.tsx +142 -0
  59. package/src/modules/change-requests/__tests__/ChangeRequestDialog.moved.test.tsx +202 -0
  60. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +205 -13
  61. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +271 -0
  62. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +208 -0
  63. package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +286 -0
  64. package/src/modules/change-requests/__tests__/propose.concurrent.test.ts +273 -0
  65. package/src/modules/change-requests/__tests__/readFailure.test.ts +122 -0
  66. package/src/modules/change-requests/__tests__/useCrFileDiffs.test.tsx +238 -0
  67. package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +56 -1
  68. package/src/modules/change-requests/__tests__/useForkPointFile.test.tsx +79 -0
  69. package/src/modules/change-requests/components/BranchFilePreview.tsx +357 -0
  70. package/src/modules/change-requests/components/ChangeBox.tsx +31 -2
  71. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +862 -72
  72. package/src/modules/change-requests/components/CrFileTree.tsx +74 -58
  73. package/src/modules/change-requests/components/FileChangeBoxes.tsx +19 -15
  74. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +41 -7
  75. package/src/modules/change-requests/hooks/useCrFileDiffs.ts +181 -23
  76. package/src/modules/change-requests/hooks/useFileOnBranch.ts +70 -7
  77. package/src/modules/change-requests/hooks/useForkPointFile.ts +77 -0
  78. package/src/modules/change-requests/services/change-requests.api.ts +57 -1
  79. package/src/modules/change-requests/services/denied-file.api.ts +53 -0
  80. package/src/modules/change-requests/services/propose.api.ts +97 -8
  81. package/src/modules/change-requests/utils/approval.ts +15 -0
  82. package/src/modules/change-requests/utils/author.ts +32 -0
  83. package/src/modules/change-requests/utils/readFailure.ts +110 -0
  84. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +20 -0
  85. package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +65 -1
  86. package/src/modules/git/components/FileHistoryPanel.tsx +5 -0
  87. package/src/modules/git/components/GitSyncFailedBanner.tsx +68 -5
  88. package/src/modules/git/components/PullRequestsForMe.tsx +51 -24
  89. package/src/modules/git/services/__tests__/error-messages.test.ts +29 -0
  90. package/src/modules/git/services/error-messages.ts +12 -0
  91. package/src/modules/git/services/pr-prompts.ts +5 -5
  92. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +401 -0
  93. package/src/modules/layout/__tests__/SidebarFooterGrid.test.tsx +286 -0
  94. package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +61 -0
  95. package/src/modules/layout/components/AppLayout.tsx +2 -0
  96. package/src/modules/layout/components/MobileChatLayout.tsx +4 -1
  97. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +4 -1
  98. package/src/modules/layout/components/SidebarFrame.tsx +109 -4
  99. package/src/modules/library/__tests__/AddToPluginDialog.test.tsx +171 -5
  100. package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +356 -0
  101. package/src/modules/library/__tests__/IntegrationsSetupReminder.test.tsx +60 -0
  102. package/src/modules/library/__tests__/LibraryCard.test.tsx +91 -10
  103. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +242 -107
  104. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +104 -99
  105. package/src/modules/library/__tests__/LinkSkillPanel.test.tsx +136 -0
  106. package/src/modules/library/__tests__/LockedPluginView.test.tsx +103 -7
  107. package/src/modules/library/__tests__/NewPluginDialog.test.tsx +18 -8
  108. package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +79 -3
  109. package/src/modules/library/__tests__/PersonalPluginPage.test.tsx +201 -0
  110. package/src/modules/library/__tests__/PluginExtras.test.tsx +115 -9
  111. package/src/modules/library/__tests__/PluginJoinRequests.test.tsx +60 -1
  112. package/src/modules/library/__tests__/PluginPage.test.tsx +453 -7
  113. package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +17 -57
  114. package/src/modules/library/__tests__/PluginsSidebar.test.tsx +161 -97
  115. package/src/modules/library/__tests__/PluginsSidebarMenu.test.tsx +16 -0
  116. package/src/modules/library/__tests__/SharedViaPlugins.test.tsx +106 -0
  117. package/src/modules/library/__tests__/SkillPage.test.tsx +391 -78
  118. package/src/modules/library/__tests__/SkillsTree.test.tsx +461 -0
  119. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +582 -71
  120. package/src/modules/library/__tests__/ToolPage.test.tsx +94 -4
  121. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +279 -21
  122. package/src/modules/library/__tests__/auth-harness.tsx +9 -9
  123. package/src/modules/library/__tests__/card-row-menu.test.tsx +320 -0
  124. package/src/modules/library/__tests__/library-data.mapping.test.tsx +98 -0
  125. package/src/modules/library/__tests__/library-data.stale.test.tsx +183 -0
  126. package/src/modules/library/__tests__/library-data.test.ts +7 -0
  127. package/src/modules/library/__tests__/library-paths.test.ts +75 -0
  128. package/src/modules/library/__tests__/link-membership.test.ts +129 -0
  129. package/src/modules/library/__tests__/name-with-badges.test.tsx +273 -0
  130. package/src/modules/library/__tests__/newSkillMarkdown.test.ts +30 -0
  131. package/src/modules/library/__tests__/owner-pill.test.tsx +357 -0
  132. package/src/modules/library/__tests__/pending-tools.test.tsx +400 -0
  133. package/src/modules/library/__tests__/plugin-entries.test.ts +122 -0
  134. package/src/modules/library/__tests__/plugin-summary.test.ts +67 -0
  135. package/src/modules/library/__tests__/status.test.ts +82 -2
  136. package/src/modules/library/__tests__/tools.api.test.ts +44 -1
  137. package/src/modules/library/__tests__/useJoinRequests.test.tsx +46 -0
  138. package/src/modules/library/components/AccessRequestsBanner.tsx +85 -47
  139. package/src/modules/library/components/AddDialogTabs.tsx +103 -0
  140. package/src/modules/library/components/AddToPluginDialog.tsx +107 -18
  141. package/src/modules/library/components/IntegrationsSetupReminder.tsx +59 -0
  142. package/src/modules/library/components/ItemActionsMenu.tsx +288 -0
  143. package/src/modules/library/components/LibraryCard.tsx +149 -34
  144. package/src/modules/library/components/LibraryLayout.tsx +120 -247
  145. package/src/modules/library/components/LibraryPage.tsx +172 -39
  146. package/src/modules/library/components/LinkSkillPanel.tsx +169 -0
  147. package/src/modules/library/components/LockedPluginView.tsx +63 -35
  148. package/src/modules/library/components/NameWithBadges.tsx +164 -0
  149. package/src/modules/library/components/NewPluginDialog.tsx +19 -5
  150. package/src/modules/library/components/PageActions.tsx +31 -9
  151. package/src/modules/library/components/{PendingSkillReview.tsx → PendingItemReview.tsx} +14 -7
  152. package/src/modules/library/components/PersonalAddDialog.tsx +68 -18
  153. package/src/modules/library/components/PersonalPluginPage.tsx +123 -23
  154. package/src/modules/library/components/PluginExtras.tsx +143 -18
  155. package/src/modules/library/components/PluginIndexRow.tsx +47 -12
  156. package/src/modules/library/components/PluginPage.tsx +234 -38
  157. package/src/modules/library/components/PluginRows.tsx +286 -0
  158. package/src/modules/library/components/PluginsSidebar.tsx +271 -238
  159. package/src/modules/library/components/PluginsSidebarMenu.tsx +26 -1
  160. package/src/modules/library/components/RenamePluginDialog.tsx +136 -0
  161. package/src/modules/library/components/ShareButton.tsx +17 -0
  162. package/src/modules/library/components/SkillsTree.tsx +204 -0
  163. package/src/modules/library/components/StatusDot.tsx +1 -0
  164. package/src/modules/library/components/TeamRoute.tsx +15 -0
  165. package/src/modules/library/components/__tests__/upload-notices-once-per-page.test.tsx +144 -0
  166. package/src/modules/library/components/plugin-page-parts.tsx +132 -23
  167. package/src/modules/library/components/skill-page/SharedViaPlugins.tsx +212 -0
  168. package/src/modules/library/components/skill-page/SkillFilePane.tsx +5 -0
  169. package/src/modules/library/components/skill-page/SkillPage.tsx +337 -121
  170. package/src/modules/library/components/tool-page/DeleteToolDialog.tsx +218 -0
  171. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +79 -178
  172. package/src/modules/library/components/tool-page/ToolPage.tsx +116 -17
  173. package/src/modules/library/components/tool-page/ToolVarRow.tsx +42 -41
  174. package/src/modules/library/hooks/__tests__/useLibraryData.test.ts +98 -0
  175. package/src/modules/library/hooks/useJoinRequests.ts +48 -18
  176. package/src/modules/library/hooks/useLibraryData.ts +92 -19
  177. package/src/modules/library/routes/LibraryRoutes.tsx +14 -11
  178. package/src/modules/library/routes/WorkspaceItemRoute.tsx +229 -82
  179. package/src/modules/library/routes/library-paths.ts +46 -35
  180. package/src/modules/library/services/library.api.ts +89 -17
  181. package/src/modules/library/services/plugins.api.ts +161 -9
  182. package/src/modules/library/services/teams.api.ts +15 -0
  183. package/src/modules/library/services/tools.api.ts +78 -0
  184. package/src/modules/library/state/library-data.tsx +268 -37
  185. package/src/modules/library/utils/personal-plugin.ts +13 -15
  186. package/src/modules/library/utils/plugin-entries.ts +134 -0
  187. package/src/modules/library/utils/plugin-summary.ts +102 -0
  188. package/src/modules/library/utils/status.ts +204 -35
  189. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +11 -3
  190. package/src/modules/onboarding/__tests__/onboarding.test.tsx +853 -760
  191. package/src/modules/onboarding/agent-clients.ts +55 -23
  192. package/src/modules/onboarding/components/ConnectAgentPill.tsx +5 -1
  193. package/src/modules/onboarding/components/WelcomePage.tsx +98 -62
  194. package/src/modules/pr/services/pr-merge.api.ts +2 -1
  195. package/src/modules/review/components/MarkdownDiffViewer.tsx +53 -8
  196. package/src/modules/review/components/ReviewPanel.tsx +15 -17
  197. package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +64 -0
  198. package/src/modules/review/components/__tests__/ReviewPanel.test.tsx +25 -1
  199. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +454 -117
  200. package/src/modules/secrets-vault/components/SecretsPage.tsx +48 -7
  201. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +84 -5
  202. package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +425 -0
  203. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +417 -82
  204. package/src/modules/secrets-vault/components/__tests__/ToolSecretsPanel.test.tsx +105 -0
  205. package/src/modules/secrets-vault/components/__tests__/connect-lists-what-the-banner-counted.test.tsx +407 -0
  206. package/src/modules/secrets-vault/probe/SavedKeyProbeResult.tsx +98 -0
  207. package/src/modules/secrets-vault/probe/__tests__/probe-verdict.test.ts +160 -0
  208. package/src/modules/secrets-vault/probe/probe-verdict.ts +108 -0
  209. package/src/modules/secrets-vault/probe/useSavedKeyProbe.ts +228 -0
  210. package/src/modules/secrets-vault/services/connect.api.ts +36 -5
  211. package/src/modules/secrets-vault/utils/connect-status.ts +98 -0
  212. package/src/modules/settings/components/ClaudeConnectionCard.tsx +154 -0
  213. package/src/modules/settings/components/ClaudeConnectionFields.tsx +23 -0
  214. package/src/modules/settings/components/DeploymentPage.tsx +16 -22
  215. package/src/modules/settings/components/MarketplaceSection.tsx +152 -0
  216. package/src/modules/settings/components/__tests__/ClaudeConnectionCard.test.tsx +63 -0
  217. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +74 -1
  218. package/src/modules/settings/components/__tests__/MarketplaceSection.test.tsx +325 -0
  219. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +5 -5
  220. package/src/modules/settings/services/github-facade.api.ts +66 -0
  221. package/src/modules/settings/settings-nav-items.tsx +10 -2
  222. package/src/modules/setup/__tests__/setup.oidc.test.tsx +172 -0
  223. package/src/modules/setup/__tests__/setup.probe-refusal.test.tsx +123 -0
  224. package/src/modules/setup/__tests__/setup.test.tsx +615 -4
  225. package/src/modules/setup/__tests__/useSetupStatus.test.tsx +130 -0
  226. package/src/modules/setup/components/SetupGate.tsx +16 -16
  227. package/src/modules/setup/components/SetupScreen.tsx +711 -40
  228. package/src/modules/setup/hooks/useSetupStatus.ts +93 -0
  229. package/src/modules/setup/services/setup.api.ts +218 -3
  230. package/src/modules/setup/utils/__tests__/root-folders.test.ts +72 -0
  231. package/src/modules/setup/utils/root-folders.ts +46 -0
  232. package/src/modules/toolbar/assets/claude-setup/01-add-manually.webp +0 -0
  233. package/src/modules/toolbar/assets/claude-setup/02-add-configuration.webp +0 -0
  234. package/src/modules/toolbar/assets/claude-setup/03-connect-account.webp +0 -0
  235. package/src/modules/toolbar/assets/claude-setup/04-pick-instance.webp +0 -0
  236. package/src/modules/toolbar/assets/claude-setup/05-plugins-add.webp +0 -0
  237. package/src/modules/toolbar/assets/claude-setup/06-add-marketplace.webp +0 -0
  238. package/src/modules/toolbar/assets/claude-setup/07-paste-url-sync.webp +0 -0
  239. package/src/modules/toolbar/assets/claude-setup/08-install-plugins.webp +0 -0
  240. package/src/modules/toolbar/assets/claude-setup/09-select-repository.webp +0 -0
  241. package/src/modules/toolbar/assets/claude-setup/10-connector-not-added.webp +0 -0
  242. package/src/modules/toolbar/assets/claude-setup/11-add-custom-connector.webp +0 -0
  243. package/src/modules/toolbar/assets/claude-setup/README.md +68 -0
  244. package/src/modules/toolbar/components/AgentInstructionsCard.tsx +296 -0
  245. package/src/modules/toolbar/components/ClaudeMarketplaceCarousel.tsx +107 -0
  246. package/src/modules/toolbar/components/ClaudeRegistrationSteps.tsx +127 -0
  247. package/src/modules/toolbar/components/CoworkSetupSteps.tsx +100 -0
  248. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +395 -124
  249. package/src/modules/toolbar/components/ScreenshotStep.tsx +77 -0
  250. package/src/modules/toolbar/components/SetupCarousel.tsx +177 -0
  251. package/src/modules/toolbar/components/__tests__/AgentInstructionsCard.test.tsx +370 -0
  252. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +659 -36
  253. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +2 -2
  254. package/src/modules/toolbar/components/__tests__/claude-setup-shots.test.ts +104 -0
  255. package/src/modules/toolbar/components/claude-connector-slide.tsx +38 -0
  256. package/src/modules/toolbar/components/claude-setup-shots.ts +167 -0
  257. package/src/modules/toolbar/components/deployment-address.ts +29 -0
  258. package/src/modules/toolbar/components/setup-step-parts.tsx +35 -0
  259. package/src/modules/toolbar/services/__tests__/agent-instructions.api.test.ts +89 -0
  260. package/src/modules/toolbar/services/agent-instructions.api.ts +167 -0
  261. package/src/modules/toolbar/services/external-api-keys.api.ts +8 -0
  262. package/src/modules/workflow/state/ChangeRequestStaleBinder.tsx +43 -0
  263. package/src/modules/workflow/state/EventBusProvider.tsx +122 -11
  264. package/src/modules/workflow/state/__tests__/EventBusProvider.storage.test.tsx +87 -0
  265. package/src/modules/workflow/state/__tests__/EventBusProvider.watch.test.tsx +223 -0
  266. package/src/modules/workflow/state/event-bus.context.ts +10 -0
  267. package/src/modules/workspace/__tests__/testFixtures.ts +6 -3
  268. package/src/modules/workspace/components/FileExplorer.tsx +1527 -367
  269. package/src/modules/workspace/components/FileRoute.tsx +376 -22
  270. package/src/modules/workspace/components/FileViewer.tsx +166 -45
  271. package/src/modules/workspace/components/KbDocumentShell.tsx +50 -6
  272. package/src/modules/workspace/components/KbPageHeader.tsx +120 -55
  273. package/src/modules/workspace/components/TreeActionConfirm.tsx +350 -0
  274. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +2473 -129
  275. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +768 -16
  276. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +332 -12
  277. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +39 -0
  278. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +33 -20
  279. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +4 -5
  280. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +13 -4
  281. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +4 -3
  282. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +8 -14
  283. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +75 -16
  284. package/src/modules/workspace/components/renderers/KbImage.tsx +180 -0
  285. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +22 -6
  286. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +48 -22
  287. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +4 -5
  288. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +4 -3
  289. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +4 -3
  290. package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +12 -0
  291. package/src/modules/workspace/components/renderers/__tests__/DownloadFileButton.test.tsx +57 -9
  292. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.test.tsx +13 -1
  293. package/src/modules/workspace/components/renderers/__tests__/ImageRenderer.test.tsx +163 -0
  294. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +237 -0
  295. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +108 -14
  296. package/src/modules/workspace/components/renderers/__tests__/PptxRenderer.test.tsx +14 -1
  297. package/src/modules/workspace/components/renderers/__tests__/XlsxRenderer.test.tsx +16 -1
  298. package/src/modules/workspace/components/renderers/__tests__/rendererSelection.test.tsx +66 -1
  299. package/src/modules/workspace/components/renderers/index.ts +53 -2
  300. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +25 -4
  301. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +40 -0
  302. package/src/modules/workspace/hooks/__tests__/useImageRevision.test.tsx +174 -0
  303. package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +179 -1
  304. package/src/modules/workspace/hooks/__tests__/useWorkspaceImageResolver.test.tsx +122 -0
  305. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +892 -7
  306. package/src/modules/workspace/hooks/useImageRevision.ts +101 -0
  307. package/src/modules/workspace/hooks/useMergedWorkspaceTree.ts +89 -0
  308. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +55 -0
  309. package/src/modules/workspace/hooks/useWorkspaceState.ts +438 -66
  310. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +279 -3
  311. package/src/modules/workspace/routing/kb-routes.ts +207 -30
  312. package/src/modules/workspace/services/__tests__/workspace.api.test.ts +57 -1
  313. package/src/modules/workspace/services/workspace.api.ts +57 -4
  314. package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +343 -0
  315. package/src/modules/workspace/state/__tests__/upload-lands-where-it-was-dropped.test.tsx +158 -0
  316. package/src/modules/workspace/state/open-change-requests.tsx +100 -12
  317. package/src/modules/workspace/state/workspace.context.ts +130 -16
  318. package/src/modules/workspace/utils/__tests__/file-trace.test.ts +73 -0
  319. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +234 -5
  320. package/src/modules/workspace/utils/__tests__/pasteLink.test.ts +76 -0
  321. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +364 -0
  322. package/src/modules/workspace/utils/__tests__/uploadError.test.ts +35 -0
  323. package/src/modules/workspace/utils/file-trace.ts +50 -0
  324. package/src/modules/workspace/utils/fileTree.ts +126 -52
  325. package/src/modules/workspace/utils/frontmatter.ts +8 -4
  326. package/src/modules/workspace/utils/pasteLink.ts +90 -0
  327. package/src/modules/workspace/utils/treeConfirm.ts +338 -0
  328. package/src/modules/workspace/utils/uploadError.ts +29 -0
  329. package/src/shared/__tests__/marketplace-url.test.ts +59 -0
  330. package/src/shared/components/Badge.tsx +3 -1
  331. package/src/shared/components/Banner.tsx +5 -1
  332. package/src/shared/components/Button.tsx +16 -2
  333. package/src/shared/components/Dialog.tsx +27 -11
  334. package/src/shared/components/Menu.tsx +13 -1
  335. package/src/shared/components/PageShell.tsx +13 -8
  336. package/src/shared/components/__tests__/primitives.test.tsx +116 -2
  337. package/src/shared/components/__tests__/useFocusHandoff.test.tsx +192 -0
  338. package/src/shared/components/index.ts +2 -0
  339. package/src/shared/components/useDismissableMenu.ts +32 -10
  340. package/src/shared/components/useFocusHandoff.ts +51 -0
  341. package/src/shared/components/useLatestRef.ts +28 -0
  342. package/src/shared/markdown/Markdown.tsx +12 -3
  343. package/src/shared/markdown/__tests__/escapeSpacesInLinkDestinations.test.ts +39 -0
  344. package/src/shared/markdown/hrefs.ts +50 -0
  345. package/src/shared/marketplace-url.ts +118 -0
  346. package/src/shared/mcp/ChatGptInstallLink.tsx +3 -3
  347. package/src/shared/mcp/ConnectionInstructions.tsx +38 -27
  348. package/src/shared/mcp/__tests__/connect-snippets.test.ts +3 -3
  349. package/src/shared/mcp/connect-snippets.ts +14 -9
  350. package/src/shared/mcp/index.ts +1 -1
  351. package/src/shared/theme/__tests__/header-band.test.ts +197 -0
  352. package/src/shared/theme/header.ts +75 -0
  353. package/src/shared/theme/measure.ts +7 -4
  354. package/src/shared/theme/tokens.css +34 -0
  355. package/src/modules/library/__tests__/PluginsIndexPage.test.tsx +0 -363
  356. package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +0 -97
  357. package/src/modules/library/components/PluginsIndexPage.tsx +0 -265
  358. package/src/modules/update-check/__tests__/UpdateBanner.test.tsx +0 -126
  359. package/src/modules/update-check/components/UpdateBanner.tsx +0 -92
  360. package/src/modules/update-check/services/update-check.api.ts +0 -24
@@ -1,7 +1,8 @@
1
1
  import { createContext, useCallback, useContext, useState } from 'react';
2
2
  import { Download } from 'lucide-react';
3
3
  import { Button } from '../../../../shared/components';
4
- import { useWorkspace } from '../../state/workspace.context';
4
+ import { useRendererWorkspaceId } from './rendererWorkspace';
5
+ import { rawFileUrl } from '../../services/workspace.api';
5
6
  import { downloadViaBlob } from './downloadFile';
6
7
 
7
8
  /**
@@ -27,12 +28,20 @@ export const CanDownloadContext = createContext<boolean | null>(null);
27
28
  export function DownloadFileButton({
28
29
  filePath,
29
30
  size = 'tiny',
31
+ label = 'Download',
30
32
  }: {
31
33
  filePath: string;
32
34
  /** `sm` where the download is the page's main affordance (pptx outline). */
33
35
  size?: 'tiny' | 'sm';
36
+ /**
37
+ * What the button says. `Download` beside a rendering that is already on
38
+ * screen; the change-request dialog names the VERSION instead ("Download
39
+ * the proposed file"), because there the bytes are the only thing on offer
40
+ * and which branch they come from is the whole question.
41
+ */
42
+ label?: string;
34
43
  }) {
35
- const { workspaceId } = useWorkspace();
44
+ const workspaceId = useRendererWorkspaceId();
36
45
  const canDownload = useContext(CanDownloadContext);
37
46
  const [busy, setBusy] = useState(false);
38
47
  const [error, setError] = useState<string | null>(null);
@@ -44,7 +53,7 @@ export function DownloadFileButton({
44
53
  setError(null);
45
54
  try {
46
55
  const outcome = await downloadViaBlob(
47
- `/api/workspace/${workspaceId}/file/raw?path=${encodeURIComponent(filePath)}&download=1`,
56
+ rawFileUrl(workspaceId, filePath, { download: true }),
48
57
  fileName,
49
58
  );
50
59
  if (!outcome.ok) {
@@ -81,7 +90,7 @@ export function DownloadFileButton({
81
90
  : `Download ${fileName}`
82
91
  }
83
92
  >
84
- {busy ? 'Downloading…' : 'Download'}
93
+ {busy ? 'Downloading…' : label}
85
94
  </Button>
86
95
  </span>
87
96
  );
@@ -1,7 +1,8 @@
1
1
  import { useEffect, useMemo, useRef, useState } from 'react';
2
2
  import { Check, Copy, ExternalLink, Mail, Paperclip } from 'lucide-react';
3
- import { useWorkspace } from '../../state/workspace.context';
3
+ import { useRendererWorkspaceId } from './rendererWorkspace';
4
4
  import { authFetch } from '../../../../lib/api';
5
+ import { rawFileUrl } from '../../services/workspace.api';
5
6
  import { copyToClipboard } from '../../../../lib/clipboard';
6
7
  import { DownloadFileButton } from './DownloadFileButton';
7
8
  import { MAX_EMAIL_BYTES, attachmentLine, type EmailMessageView } from './emailMessage';
@@ -38,7 +39,7 @@ import type { FileRendererProps } from './types';
38
39
  * ignores `onSave` / `onValueChange` / `readOnly`.
39
40
  */
40
41
  export function EmailRenderer({ filePath }: FileRendererProps) {
41
- const { workspaceId } = useWorkspace();
42
+ const workspaceId = useRendererWorkspaceId();
42
43
  const [view, setView] = useState<EmailMessageView | null>(null);
43
44
  // The sender's own markup, made safe to show. Rebuilt only when the message
44
45
  // changes — the sanitize + inline pass walks the whole body.
@@ -60,7 +61,7 @@ export function EmailRenderer({ filePath }: FileRendererProps) {
60
61
  (async () => {
61
62
  try {
62
63
  const res = await authFetch(
63
- `/api/workspace/${workspaceId}/file/raw?path=${encodeURIComponent(filePath)}`,
64
+ rawFileUrl(workspaceId, filePath),
64
65
  { signal: controller.signal },
65
66
  );
66
67
  if (cancelled) return;
@@ -1,6 +1,6 @@
1
1
  import { useState, useCallback, useEffect, useRef } from 'react';
2
2
  import { Pencil, Eye, RotateCw } from 'lucide-react';
3
- import { useFileNav, KB_ROUTE_PREFIX, resolveRelativePath } from '../../routing/kb-routes';
3
+ import { useFileNav } from '../../routing/kb-routes';
4
4
  import type { FileRendererProps, RendererSaveState } from './types';
5
5
  import { buildSandboxedHtml, sanitizeAgentHtml } from './htmlSandbox';
6
6
 
@@ -14,7 +14,7 @@ export function HtmlRenderer({
14
14
  onSaveStateChange,
15
15
  readOnly = false,
16
16
  }: FileRendererProps) {
17
- const { openFile } = useFileNav();
17
+ const { openLink } = useFileNav();
18
18
  const [mode, setMode] = useState<'preview' | 'edit'>('preview');
19
19
  const [value, setValue] = useState(content);
20
20
  const [savedValue, setSavedValue] = useState(savedContent ?? content);
@@ -82,10 +82,10 @@ export function HtmlRenderer({
82
82
  // Navigation bridge: agent HTML deep-links into the KB by calling
83
83
  // `window.bevel.openNode(href)` or clicking an `<a>` whose href points at a
84
84
  // node — both post a `bevel.navigate` message (the iframe sandbox can't
85
- // navigate the host window itself). We resolve the href the same way the
86
- // markdown renderer does (absolute `/workspace/…` URLs pass through; relative
87
- // `.md` paths resolve against this file) and route it through the in-app
88
- // navigation so the URL reflects what's on screen.
85
+ // navigate the host window itself). `openLink` resolves the href the same
86
+ // way the markdown renderer does (absolute `/workspace/…` URLs keep their
87
+ // branch; relative paths resolve against this file) and routes it through
88
+ // the in-app navigation so the URL reflects what's on screen.
89
89
  useEffect(() => {
90
90
  function onNavMessage(event: MessageEvent) {
91
91
  const iframeWin = iframeRef.current?.contentWindow;
@@ -94,17 +94,11 @@ export function HtmlRenderer({
94
94
  if (!msg || typeof msg !== 'object' || msg.type !== 'bevel.navigate') return;
95
95
  const href = typeof msg.href === 'string' ? msg.href : null;
96
96
  if (!href) return;
97
- if (href.startsWith(`${KB_ROUTE_PREFIX}/`)) {
98
- openFile(href);
99
- return;
100
- }
101
- let decoded = href;
102
- try { decoded = decodeURIComponent(href); } catch { /* leave as-is */ }
103
- openFile(resolveRelativePath(filePath, decoded));
97
+ openLink(href, filePath);
104
98
  }
105
99
  window.addEventListener('message', onNavMessage);
106
100
  return () => window.removeEventListener('message', onNavMessage);
107
- }, [openFile, filePath]);
101
+ }, [openLink, filePath]);
108
102
 
109
103
  const save = useCallback(async (): Promise<boolean> => {
110
104
  if (readOnly || value === savedValue) return true;
@@ -1,36 +1,95 @@
1
1
  import { useState, useEffect } from 'react';
2
- import { useWorkspace } from '../../state/workspace.context';
2
+ import { Button } from '../../../../shared/components';
3
+ import { useRendererWorkspaceId } from './rendererWorkspace';
4
+ import { useImageRevision } from '../../hooks/useImageRevision';
3
5
  import { authFetch } from '../../../../lib/api';
6
+ import { rawFileUrl } from '../../services/workspace.api';
4
7
  import type { FileRendererProps } from './types';
5
8
 
9
+ /** How the read of one image ended. */
10
+ interface ImageRead {
11
+ objectUrl: string | null;
12
+ /**
13
+ * A failed read, NAMED. A non-ok response used to return silently, leaving
14
+ * the pane on "Loading image…" for as long as anyone cared to watch — which
15
+ * is the shape a 403 on a restricted file takes, and a 404 on a path the
16
+ * workspace's branch does not have (the change-request pane reads someone
17
+ * else's branch, where a file may well be absent).
18
+ */
19
+ error: string | null;
20
+ }
21
+
22
+ const NOT_READ: ImageRead = { objectUrl: null, error: null };
23
+
6
24
  export function ImageRenderer({ filePath }: FileRendererProps) {
7
- const { workspaceId } = useWorkspace();
8
- const [objectUrl, setObjectUrl] = useState<string | null>(null);
25
+ const workspaceId = useRendererWorkspaceId();
26
+ /**
27
+ * A replaced picture reaches an open pane. The `<img>` tags the markdown
28
+ * pipeline emits already carry this revision (`useWorkspaceImageResolver`);
29
+ * the whole-file image view was the one image on the page that stayed stale
30
+ * until a reload — including the change-request pane, which reads a branch
31
+ * its author may still be pushing to while a reviewer looks at it.
32
+ */
33
+ const revision = useImageRevision(workspaceId);
34
+ // Blob and failure in ONE value, so the cleanup that drops the old blob
35
+ // drops the old failure with it — a second `useState` would need a reset in
36
+ // the effect body, which costs a cascading render on every path change.
37
+ const [read, setRead] = useState<ImageRead>(NOT_READ);
38
+ /**
39
+ * Bumped by Try again, and a dependency of the read below — which is the
40
+ * whole mechanism. A failure whose `workspaceId`, path and revision are all
41
+ * unchanged has nothing to re-trigger the effect, so a dropped connection or
42
+ * a 502 was terminal until the pane remounted; a reviewer with a dialog open
43
+ * had no way back to the picture. Automatic recovery on a path or revision
44
+ * change is untouched: those change the deps by themselves.
45
+ */
46
+ const [attempt, setAttempt] = useState(0);
9
47
 
10
48
  useEffect(() => {
11
49
  if (!workspaceId) return;
12
50
 
13
51
  let revoked = false;
14
52
  (async () => {
15
- const res = await authFetch(
16
- `/api/workspace/${workspaceId}/file/raw?path=${encodeURIComponent(filePath)}`,
17
- );
18
- if (!res.ok || revoked) return;
19
- const blob = await res.blob();
20
- if (revoked) return;
21
- setObjectUrl(URL.createObjectURL(blob));
53
+ try {
54
+ const res = await authFetch(rawFileUrl(workspaceId, filePath, { version: revision }));
55
+ if (revoked) return;
56
+ if (!res.ok) {
57
+ setRead({ objectUrl: null, error: `Couldn't load this image (HTTP ${res.status}).` });
58
+ return;
59
+ }
60
+ const blob = await res.blob();
61
+ if (revoked) return;
62
+ setRead({ objectUrl: URL.createObjectURL(blob), error: null });
63
+ } catch {
64
+ if (!revoked) setRead({ objectUrl: null, error: "Couldn't load this image." });
65
+ }
22
66
  })();
23
67
 
24
68
  return () => {
25
69
  revoked = true;
26
- setObjectUrl((prev) => {
27
- if (prev) URL.revokeObjectURL(prev);
28
- return null;
70
+ setRead((prev) => {
71
+ if (prev.objectUrl) URL.revokeObjectURL(prev.objectUrl);
72
+ // `prev` back when there is nothing to clear, so React bails out of
73
+ // the render rather than seeing a fresh object with the same fields.
74
+ return prev === NOT_READ ? prev : NOT_READ;
29
75
  });
30
76
  };
31
- }, [workspaceId, filePath]);
77
+ }, [workspaceId, filePath, revision, attempt]);
78
+
79
+ if (read.error) {
80
+ return (
81
+ <div className="flex h-full flex-col items-center justify-center gap-3 p-4">
82
+ <p role="alert" className="text-detail text-danger">
83
+ {read.error}
84
+ </p>
85
+ <Button variant="outline" size="tiny" onClick={() => setAttempt((n) => n + 1)}>
86
+ Try again
87
+ </Button>
88
+ </div>
89
+ );
90
+ }
32
91
 
33
- if (!objectUrl) {
92
+ if (!read.objectUrl) {
34
93
  return (
35
94
  <div className="flex items-center justify-center h-full text-ink-muted text-sm">
36
95
  Loading image...
@@ -41,7 +100,7 @@ export function ImageRenderer({ filePath }: FileRendererProps) {
41
100
  return (
42
101
  <div className="flex items-center justify-center h-full overflow-auto">
43
102
  <img
44
- src={objectUrl}
103
+ src={read.objectUrl}
45
104
  alt={filePath}
46
105
  className="max-w-full max-h-full object-contain rounded-xs"
47
106
  />
@@ -0,0 +1,180 @@
1
+ import { useState, type HTMLAttributes, type ImgHTMLAttributes } from 'react';
2
+ import { ImageOff } from 'lucide-react';
3
+ import { isExternalHref } from '../../../../shared/markdown/hrefs';
4
+
5
+ /**
6
+ * What a surface knows about an image `src` the page cannot serve as written.
7
+ * Returned by `resolveImage` in `useKbMarkdownComponents`.
8
+ */
9
+ export type KbImageSource =
10
+ /** Serve these bytes; `path` names the workspace file if they fail to load. */
11
+ | { src: string; path: string }
12
+ /** Do not fetch. Show the placeholder with `note`, naming `path`. */
13
+ | { src: null; path: string; note: string };
14
+
15
+ /**
16
+ * Turns the `src` an author wrote (`./assets/x.png`, `/workspace/<b>/<p>`)
17
+ * into a source the browser can load, or says why it will not be loaded.
18
+ * `null` means the resolver could not place the path at all (no workspace
19
+ * yet); the placeholder then names the raw src.
20
+ */
21
+ export type KbImageResolver = (src: string) => KbImageSource | null;
22
+
23
+ const NO_SOURCE_NOTE =
24
+ 'This image has no usable source. Inline data: images are not supported; save the file under ./assets/ and link it.';
25
+
26
+ const PLACEHOLDER_CLASS =
27
+ 'inline-flex max-w-full items-center gap-1.5 rounded-sm border border-dashed border-line-strong bg-sunken px-2 py-1 align-middle text-xs text-ink-muted';
28
+
29
+ /**
30
+ * What a placeholder inherits from the image it stands in for: the attributes
31
+ * that tie the image to the DOCUMENT, never the ones that draw it or name it.
32
+ * Its `id`, so a link to the figure still lands; `aria-describedby`, so a
33
+ * caption still describes it; its language and direction. `width`, `height`,
34
+ * `align` and the rest size a picture that is not there. `aria-label` and
35
+ * `aria-labelledby` stay behind: the placeholder's NAME must say the picture
36
+ * is missing, and `aria-labelledby` outranks the `aria-label` we set, so
37
+ * inheriting it would name the placeholder after the caption instead. The
38
+ * sanitizer keeps no other ARIA attribute on an image (hast-util-sanitize's
39
+ * `aria` list), so nothing that hides an element can arrive.
40
+ */
41
+ const INHERITED_ATTRIBUTES = new Set(['id', 'lang', 'dir', 'aria-describedby']);
42
+
43
+ function inheritedAttributes(rest: ImgHTMLAttributes<HTMLImageElement>): HTMLAttributes<HTMLElement> {
44
+ const inherited: Record<string, unknown> = {};
45
+ for (const [name, value] of Object.entries(rest)) {
46
+ if (INHERITED_ATTRIBUTES.has(name)) inherited[name] = value;
47
+ }
48
+ return inherited;
49
+ }
50
+
51
+ /**
52
+ * What an image leaves behind when there is nothing to show. A `role="img"`
53
+ * whose accessible name is the note, so a screen reader hears what a sighted
54
+ * reader sees; the alt text stays, so the author's description is not lost
55
+ * with the picture. A span, not a div: an image sits inside a paragraph, and
56
+ * a block there is invalid markup.
57
+ *
58
+ * With `onRetry` it is a button. The one failure nothing else clears is a
59
+ * load error on a URL that does not change (a network blip, a 403 that lifts,
60
+ * a file fixed on disk with no event), and the reader is the one who knows it
61
+ * is worth another try; retrying on our own would loop error → image → error.
62
+ *
63
+ * The author's attributes come first, so ours hold.
64
+ */
65
+ function ImagePlaceholder({
66
+ alt,
67
+ note,
68
+ onRetry,
69
+ attributes = {},
70
+ }: {
71
+ alt?: string;
72
+ note: string;
73
+ onRetry?: () => void;
74
+ attributes?: HTMLAttributes<HTMLElement>;
75
+ }) {
76
+ const label = alt ? `${alt}. ${note}` : note;
77
+ const body = (
78
+ <>
79
+ <ImageOff size={14} aria-hidden="true" className="shrink-0" />
80
+ <span className="min-w-0 break-words">
81
+ {alt ? <span className="text-ink">{alt} </span> : null}
82
+ {note}
83
+ {onRetry ? <span className="ml-1.5 text-accent">Retry</span> : null}
84
+ </span>
85
+ </>
86
+ );
87
+ if (onRetry) {
88
+ return (
89
+ <button
90
+ {...attributes}
91
+ type="button"
92
+ onClick={onRetry}
93
+ aria-label={`${label}. Retry`}
94
+ title="Try loading the image again"
95
+ className={`${PLACEHOLDER_CLASS} cursor-pointer hover:text-ink`}
96
+ >
97
+ {body}
98
+ </button>
99
+ );
100
+ }
101
+ return (
102
+ <span {...attributes} role="img" aria-label={label} title={note} className={PLACEHOLDER_CLASS}>
103
+ {body}
104
+ </span>
105
+ );
106
+ }
107
+
108
+ /**
109
+ * The six inputs an image can arrive with, and what each renders:
110
+ *
111
+ * src resolver → rendered
112
+ * ───────────────────────── ─────────── ──────────────────────────────────────────
113
+ * http(s)://… or //… any <img src as-is>
114
+ * '' (stripped: was data:) any placeholder: no usable source
115
+ * ./assets/x.png none <img src as-is> (the embed, as before)
116
+ * ./assets/x.png {src, path} <img src=raw-file URL>; on error the
117
+ * placeholder "Couldn't load image: <path>",
118
+ * with Retry
119
+ * ./assets/x.png {src: null} placeholder with the resolver's note
120
+ * ./assets/x.png null placeholder "Couldn't load image: <src>"
121
+ *
122
+ * The sanitizer removes a `data:` src before this runs, so the empty-src case
123
+ * cannot know the cause and says what to do instead. A native `<img>` error
124
+ * carries no HTTP status, so a failure says "couldn't load", never "not found".
125
+ *
126
+ * The failure state is keyed by the resolved src: an author who fixes the
127
+ * link, or a teammate who uploads the missing file (which bumps the revision
128
+ * in the URL), sees the image without a reload; the same URL is tried again
129
+ * on request. Every attribute the sanitizer let through reaches the element
130
+ * (`id`, `align`, `aria-*`; `srcset` and `class` never survive it), and a
131
+ * placeholder keeps the ones that place the image in the document (see
132
+ * `inheritedAttributes`). Every
133
+ * `<img>` carries `loading="lazy"` (thirty screenshots on a Loop export must
134
+ * not all fetch at once) and `referrerPolicy="no-referrer"` (an external image
135
+ * host learns nothing about which page of the knowledge base cited it).
136
+ */
137
+ export function KbImage({
138
+ src,
139
+ alt,
140
+ title,
141
+ resolve,
142
+ ...rest
143
+ }: ImgHTMLAttributes<HTMLImageElement> & { resolve?: KbImageResolver }) {
144
+ const [failedSrc, setFailedSrc] = useState<string | null>(null);
145
+ const attributes = inheritedAttributes(rest);
146
+ if (!src) return <ImagePlaceholder alt={alt} note={NO_SOURCE_NOTE} attributes={attributes} />;
147
+ // Ours come after the author's, so they hold on every image.
148
+ const shared = {
149
+ ...rest,
150
+ alt,
151
+ title,
152
+ loading: 'lazy' as const,
153
+ referrerPolicy: 'no-referrer' as const,
154
+ };
155
+ if (!resolve || isExternalHref(src)) return <img src={src} {...shared} />;
156
+ const resolved = resolve(src);
157
+ if (!resolved) {
158
+ return <ImagePlaceholder alt={alt} note={`Couldn't load image: ${src}`} attributes={attributes} />;
159
+ }
160
+ if (resolved.src === null) {
161
+ return (
162
+ <ImagePlaceholder
163
+ alt={alt}
164
+ note={`${resolved.note}: ${resolved.path}`}
165
+ attributes={attributes}
166
+ />
167
+ );
168
+ }
169
+ if (failedSrc === resolved.src) {
170
+ return (
171
+ <ImagePlaceholder
172
+ alt={alt}
173
+ note={`Couldn't load image: ${resolved.path}`}
174
+ onRetry={() => setFailedSrc(null)}
175
+ attributes={attributes}
176
+ />
177
+ );
178
+ }
179
+ return <img src={resolved.src} {...shared} onError={() => setFailedSrc(resolved.src)} />;
180
+ }
@@ -1,11 +1,12 @@
1
1
  import { useMemo, type Ref } from 'react';
2
- import Markdown from 'react-markdown';
2
+ import Markdown, { defaultUrlTransform } from 'react-markdown';
3
3
  import { parseFrontmatter, labelFor } from '../../utils/frontmatter';
4
4
  import { escapeSpacesInLinkDestinations } from '../../../../shared/markdown/Markdown';
5
5
  import {
6
6
  KB_REMARK_PLUGINS,
7
7
  KB_REHYPE_PLUGINS,
8
8
  useKbMarkdownComponents,
9
+ type KbImageResolver,
9
10
  } from './kbMarkdownPipeline';
10
11
 
11
12
  // A frontmatter value that is a single markdown link, e.g.
@@ -20,6 +21,12 @@ const FRONTMATTER_LINK_RE = /^\[([^\]]+)\]\(<?([^)>]+)>?\)$/;
20
21
  * `nodeType`) renders as a clickable link; everything else is plain text.
21
22
  * `onOpenFile` receives the raw href — the caller decides how to resolve and
22
23
  * open it (in-workspace navigation, or a new tab for the embed).
24
+ *
25
+ * The panel never goes through the markdown pipeline, so it applies the
26
+ * pipeline's URL policy itself: a destination react-markdown would refuse in
27
+ * the body (`javascript:`, or a bare `Notes: today.md`, which reads as a
28
+ * scheme; `./Notes: today.md` does not) is refused here too and the value
29
+ * stays text. One rule for a link, wherever it sits in the file.
23
30
  */
24
31
  function FrontmatterValue({
25
32
  value,
@@ -29,8 +36,9 @@ function FrontmatterValue({
29
36
  onOpenFile: (href: string) => void;
30
37
  }) {
31
38
  const match = value.match(FRONTMATTER_LINK_RE);
32
- if (match) {
33
- const [, label, href] = match;
39
+ const href = match ? defaultUrlTransform(match[2]) : '';
40
+ if (match && href) {
41
+ const label = match[1];
34
42
  return (
35
43
  <a
36
44
  href={href}
@@ -100,6 +108,13 @@ interface KbMarkdownViewProps {
100
108
  * rehype-slug anchor id. Omit it (e.g. in the embed) to hide the buttons.
101
109
  */
102
110
  headingLink?: (slug: string) => string;
111
+ /**
112
+ * Resolves a workspace image `src` (`./assets/x.png`) to the URL that serves
113
+ * it, or to the reason it will not be shown. The caller knows the workspace
114
+ * and the file this document is; the view does not. Omit it (the embed) and
115
+ * images render as plain `<img>` tags. See `KbImage` in the pipeline.
116
+ */
117
+ resolveImage?: KbImageResolver;
103
118
  /** Optional container ref (used by the file viewer for deep-link scroll). */
104
119
  containerRef?: Ref<HTMLDivElement>;
105
120
  /**
@@ -124,14 +139,15 @@ interface KbMarkdownViewProps {
124
139
  * frontmatter panel, with navigation injected via `onOpenFile` so it carries no
125
140
  * dependency on workspace routing or context.
126
141
  */
127
- export function KbMarkdownView({ source, onOpenFile, onOpenNodeId, headingLink, containerRef, scroll = true, className }: KbMarkdownViewProps) {
142
+ export function KbMarkdownView({ source, onOpenFile, onOpenNodeId, headingLink, resolveImage, containerRef, scroll = true, className }: KbMarkdownViewProps) {
128
143
  const { data: frontmatter, body } = useMemo(() => parseFrontmatter(source), [source]);
129
144
  // CommonMark rejects unescaped spaces in link destinations, so a KB link like
130
145
  // `[Foo](Some File.md)` would render as plain text. Wrap space-bearing
131
- // destinations in `<...>` so links to files with spaces resolve.
146
+ // destinations in `<...>` so links to files with spaces resolve. The same
147
+ // rule covers an image's `![alt](Some Shot.png)` tail.
132
148
  const normalizedBody = useMemo(() => escapeSpacesInLinkDestinations(body), [body]);
133
149
 
134
- const components = useKbMarkdownComponents({ onOpenFile, onOpenNodeId, headingLink });
150
+ const components = useKbMarkdownComponents({ onOpenFile, onOpenNodeId, headingLink, resolveImage });
135
151
 
136
152
  return (
137
153
  <div
@@ -1,4 +1,4 @@
1
- import { useState, useCallback, useEffect, useRef } from 'react';
1
+ import { useState, useCallback, useContext, useEffect, useRef } from 'react';
2
2
  import { useLocation } from 'react-router-dom';
3
3
  import { KbMarkdownView } from './KbMarkdownView';
4
4
  import { useAutoGrowTextarea } from '../../hooks/useAutoGrowTextarea';
@@ -6,9 +6,11 @@ import {
6
6
  useFileNav,
7
7
  useNodeIdNav,
8
8
  useCanonicalFileUrl,
9
- KB_ROUTE_PREFIX,
10
- resolveRelativePath,
11
9
  } from '../../routing/kb-routes';
10
+ import { useRendererWorkspaceId } from './rendererWorkspace';
11
+ import { WorkspaceContext } from '../../state/workspace.context';
12
+ import { markdownLinkForPaste } from '../../utils/pasteLink';
13
+ import { useWorkspaceImageResolver } from '../../hooks/useWorkspaceImageResolver';
12
14
  import type { FileRendererProps, RendererSaveState } from './types';
13
15
 
14
16
  /** Decode a URL hash (`#some%20slug`) to its bare slug, tolerating bad escapes. */
@@ -60,9 +62,9 @@ export function MarkdownRenderer({
60
62
  onSaveStateChange,
61
63
  readOnly = false,
62
64
  }: FileRendererProps) {
63
- // openFile here is the navigating version: clicking a markdown link to a file
65
+ // openLink here is the navigating version: clicking a markdown link to a file
64
66
  // updates the URL so the route reflects what's on screen.
65
- const { openFile } = useFileNav();
67
+ const { openLink } = useFileNav();
66
68
  // Shared id-link resolver (resolve-id → openFile, heading preserved) — same
67
69
  // implementation the chat citation renderer uses.
68
70
  const { openNodeId } = useNodeIdNav();
@@ -137,9 +139,6 @@ export function MarkdownRenderer({
137
139
  return () => cancelAnimationFrame(raf);
138
140
  }, [location.hash, filePath, value, readOnly]);
139
141
 
140
- // Navigate to a workspace file referenced by a relative link. react-markdown
141
- // percent-encodes spaces in hrefs (`Some%20File.md`), so decode before
142
- // resolving or the path won't match a real file.
143
142
  // Citation deep-link for a heading: the node's canonical URL (its id URL when
144
143
  // it's a node, else the path URL) plus the heading's `#slug`. Matches the "copy
145
144
  // link to this file" affordance, scoped to a section. Falls back to the current
@@ -151,23 +150,23 @@ export function MarkdownRenderer({
151
150
  [canonicalFileUrl, location.pathname],
152
151
  );
153
152
 
153
+ // A link out of the page, resolved against this file by `openLink`: decoded
154
+ // (react-markdown percent-encodes the spaces in `Some File.md`), absolute
155
+ // citation URLs keeping their own branch. The same grammar every other
156
+ // rendered-document surface uses.
154
157
  const handleFileLink = useCallback(
155
- (href: string) => {
156
- // Absolute workspace citation URLs (`/workspace/<branch>/<path>`, e.g. the
157
- // links the agent emits) carry their own branch and are resolved by
158
- // `openFile` directly. Never run them through `resolveRelativePath` — that
159
- // would treat them as relative to the current file and mangle the path.
160
- if (href.startsWith(`${KB_ROUTE_PREFIX}/`)) {
161
- openFile(href);
162
- return;
163
- }
164
- let decoded = href;
165
- try { decoded = decodeURIComponent(href); } catch { /* leave as-is */ }
166
- openFile(resolveRelativePath(filePath, decoded));
167
- },
168
- [openFile, filePath],
158
+ (href: string) => openLink(href, filePath),
159
+ [openLink, filePath],
169
160
  );
170
161
 
162
+ // An image in the page: the same grammar, but the bytes come from this
163
+ // workspace's raw file route (a plain `<img>` authenticates through the
164
+ // bevel_token cookie), and the URL carries the workspace's image revision,
165
+ // which changes when a teammate replaces a file, so an open tab shows the
166
+ // new picture.
167
+ const workspaceId = useRendererWorkspaceId();
168
+ const resolveImage = useWorkspaceImageResolver(workspaceId, filePath);
169
+
171
170
  const save = useCallback(async (): Promise<boolean> => {
172
171
  if (readOnly || value === savedValue) return true;
173
172
  setSaveState('saving');
@@ -193,6 +192,31 @@ export function MarkdownRenderer({
193
192
  onValueChange?.(next);
194
193
  }, [onValueChange]);
195
194
 
195
+ // Pasting a bare workspace path (what Copy path gives) or a URL makes a
196
+ // link, so nobody has to know `[]()` to link a page. Anything else pastes
197
+ // as it always did. Read optionally, so paste adds no workspace-provider
198
+ // requirement of its own; without a `kbDirName` a path pastes as text.
199
+ const kbDirName = useContext(WorkspaceContext)?.kbDirName ?? null;
200
+ const handlePaste = useCallback((e: React.ClipboardEvent<HTMLTextAreaElement>) => {
201
+ const el = e.currentTarget;
202
+ const { selectionStart: start, selectionEnd: end } = el;
203
+ const link = markdownLinkForPaste(
204
+ e.clipboardData.getData('text/plain'),
205
+ kbDirName,
206
+ el.value.slice(start, end),
207
+ );
208
+ if (link === null) return;
209
+ e.preventDefault();
210
+ // `insertText` keeps the paste on the browser's undo stack and fires the
211
+ // usual change; where it is unavailable, splice the buffer directly.
212
+ if (typeof document.execCommand === 'function' && document.execCommand('insertText', false, link)) return;
213
+ const next = el.value.slice(0, start) + link + el.value.slice(end);
214
+ setValue(next);
215
+ onValueChange?.(next);
216
+ const caret = start + link.length;
217
+ requestAnimationFrame(() => textareaRef.current?.setSelectionRange(caret, caret));
218
+ }, [kbDirName, onValueChange]);
219
+
196
220
  const handleKeyDown = useCallback((e: React.KeyboardEvent) => {
197
221
  if ((e.ctrlKey || e.metaKey) && e.key === 's') {
198
222
  e.preventDefault();
@@ -241,6 +265,7 @@ export function MarkdownRenderer({
241
265
  onOpenFile={handleFileLink}
242
266
  onOpenNodeId={openNodeId}
243
267
  headingLink={headingLink}
268
+ resolveImage={resolveImage}
244
269
  containerRef={scrollContainerRef}
245
270
  // The document column scrolls; this view does not. See the prop's
246
271
  // docstring — the embed and the library dialog keep the default.
@@ -256,6 +281,7 @@ export function MarkdownRenderer({
256
281
  value={value}
257
282
  onChange={handleChange}
258
283
  onKeyDown={handleKeyDown}
284
+ onPaste={handlePaste}
259
285
  spellCheck={false}
260
286
  autoFocus
261
287
  />
@@ -4,8 +4,9 @@ import { getDocument, GlobalWorkerOptions } from 'pdfjs-dist';
4
4
  import type { PDFDocumentLoadingTask, PDFDocumentProxy, PDFPageProxy } from 'pdfjs-dist';
5
5
  import pdfWorkerUrl from 'pdfjs-dist/build/pdf.worker.min.mjs?url';
6
6
  import { Button } from '../../../../shared/components';
7
- import { useWorkspace } from '../../state/workspace.context';
7
+ import { useRendererWorkspaceId } from './rendererWorkspace';
8
8
  import { authFetch } from '../../../../lib/api';
9
+ import { rawFileUrl } from '../../services/workspace.api';
9
10
  import { DownloadFileButton } from './DownloadFileButton';
10
11
  import type { FileRendererProps } from './types';
11
12
 
@@ -35,7 +36,7 @@ GlobalWorkerOptions.workerSrc = pdfWorkerUrl;
35
36
  * `onSave` / `onValueChange` / `readOnly`.
36
37
  */
37
38
  export function PdfRenderer({ filePath }: FileRendererProps) {
38
- const { workspaceId } = useWorkspace();
39
+ const workspaceId = useRendererWorkspaceId();
39
40
  const [doc, setDoc] = useState<PDFDocumentProxy | null>(null);
40
41
  const [pageNumber, setPageNumber] = useState(1);
41
42
  const [error, setError] = useState<string | null>(null);
@@ -76,9 +77,7 @@ export function PdfRenderer({ filePath }: FileRendererProps) {
76
77
  let loadingTask: PDFDocumentLoadingTask | null = null;
77
78
  (async () => {
78
79
  try {
79
- const res = await authFetch(
80
- `/api/workspace/${workspaceId}/file/raw?path=${encodeURIComponent(filePath)}`,
81
- );
80
+ const res = await authFetch(rawFileUrl(workspaceId, filePath));
82
81
  if (cancelled) return;
83
82
  if (!res.ok) {
84
83
  setError(`Failed to load PDF (HTTP ${res.status})`);