@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
@@ -0,0 +1,77 @@
1
+ import { SHOT_HEIGHT, SHOT_WIDTH, type Shot } from './claude-setup-shots';
2
+
3
+ /**
4
+ * A setup screenshot with the control to click boxed in red.
5
+ *
6
+ * The box is drawn HERE, over the image, not burned into the file: a
7
+ * re-shot screen then costs a new file and nothing else, the outline stays
8
+ * sharp at any column width, and one shot can carry two of them (the
9
+ * credential form and the button that saves it).
10
+ *
11
+ * It is `aria-hidden` on purpose. A screen reader gets the same instruction
12
+ * from `alt`, which names the control, so the box is decoration rather than
13
+ * the only carrier of "click this".
14
+ *
15
+ * The frame links to the file so a reader can open it full size: a button
16
+ * label in a 1400px screenshot is small once it is scaled into this column.
17
+ *
18
+ * `border-danger` is the design system's only red. It reads as a callout
19
+ * here rather than an error, which is the one thing a red rectangle over a
20
+ * screenshot can mean.
21
+ *
22
+ * `width`/`height` come from the shot when it declares them: the nine window
23
+ * shots share one shape, the connector shots are a panel and a dialog and do
24
+ * not. They only reserve the right box before the bytes land — the image is
25
+ * `w-full h-auto` either way — but reserving the wrong one is what makes the
26
+ * page jump.
27
+ *
28
+ * A shot marked `illustration` gets a line under the frame saying it is a
29
+ * drawing rather than a capture. It is visible text, not a `title`: the
30
+ * reader it is for is the one holding their own Claude beside the picture,
31
+ * and they need to be told before they conclude they are on the wrong
32
+ * screen.
33
+ */
34
+ export function ScreenshotStep({ shot }: { shot: Shot }) {
35
+ const frame = (
36
+ <a
37
+ href={shot.src}
38
+ target="_blank"
39
+ rel="noopener noreferrer"
40
+ title="Open this screenshot full size"
41
+ className="relative block overflow-hidden rounded-md border border-line"
42
+ >
43
+ <img
44
+ src={shot.src}
45
+ alt={shot.alt}
46
+ loading="lazy"
47
+ decoding="async"
48
+ width={shot.width ?? SHOT_WIDTH}
49
+ height={shot.height ?? SHOT_HEIGHT}
50
+ className="block h-auto w-full"
51
+ />
52
+ {shot.boxes.map((b) => (
53
+ <span
54
+ key={`${b.x}-${b.y}`}
55
+ aria-hidden="true"
56
+ className="absolute rounded-xs border-2 border-danger"
57
+ style={{ left: `${b.x}%`, top: `${b.y}%`, width: `${b.w}%`, height: `${b.h}%` }}
58
+ />
59
+ ))}
60
+ </a>
61
+ );
62
+
63
+ if (!shot.illustration) return frame;
64
+
65
+ // The note goes OUTSIDE the anchor. The boxes are positioned against that
66
+ // element, so a line of text inside it would make every percentage refer
67
+ // to a taller box than the image and slide the callouts up the screen.
68
+ return (
69
+ <div className="space-y-1">
70
+ {frame}
71
+ <p className="text-meta leading-snug text-ink-faint">
72
+ Illustration, not a capture: this is drawn to the screen's layout, so the detail on your
73
+ Claude may differ. The instruction above names the row and the control to look for.
74
+ </p>
75
+ </div>
76
+ );
77
+ }
@@ -0,0 +1,177 @@
1
+ import { useState, type KeyboardEvent, type ReactNode } from 'react';
2
+ import { Check, ChevronLeft, ChevronRight, RotateCcw } from 'lucide-react';
3
+ import { Button } from '../../../shared/components';
4
+ import { ScreenshotStep } from './ScreenshotStep';
5
+ import type { Shot } from './claude-setup-shots';
6
+
7
+ export interface CarouselSlide {
8
+ /** The word in the progress strip. Short, because five or six share a row. */
9
+ shortLabel: string;
10
+ /** The half of the setup this slide belongs to, named in the eyebrow. */
11
+ stage: string;
12
+ title: string;
13
+ instruction: ReactNode;
14
+ /**
15
+ * Usually one. The connector slide is two, because it is one action across
16
+ * a list and the dialog it opens; splitting it would put the check that it
17
+ * worked on a different slide from the button that does it.
18
+ */
19
+ shots: Shot[];
20
+ /**
21
+ * Anything that belongs to this slide and is not a screenshot — today only
22
+ * the generated credentials, on the Add-configuration slide. An ELEMENT,
23
+ * not a component: creating it costs nothing, and it is mounted only while
24
+ * its own slide is the active one, which is what keeps a client secret out
25
+ * of the DOM of the five slides that do not ask for it.
26
+ */
27
+ extra?: ReactNode;
28
+ }
29
+
30
+ /**
31
+ * One decision at a time, for both Claude setup routes: the personal one on
32
+ * External agent access and the admin's registration steps in Deployment
33
+ * settings. ONE shell, so the two cannot drift into different keyboard
34
+ * handling or a different idea of where "Review again" lives.
35
+ *
36
+ * Only the active slide is mounted. That is what keeps nine full-size
37
+ * screenshots from becoming a very long page, and it is also the rule the
38
+ * credentials rely on.
39
+ */
40
+ export function SetupCarousel({ label, slides }: { label: string; slides: CarouselSlide[] }) {
41
+ const [current, setCurrent] = useState(0);
42
+ const active = slides[current];
43
+ const atStart = current === 0;
44
+ const atEnd = current === slides.length - 1;
45
+
46
+ function handleKeys(event: KeyboardEvent<HTMLElement>) {
47
+ if (event.target instanceof HTMLInputElement || event.target instanceof HTMLTextAreaElement) {
48
+ return;
49
+ }
50
+ const last = slides.length - 1;
51
+ const next =
52
+ event.key === 'ArrowLeft'
53
+ ? Math.max(0, current - 1)
54
+ : event.key === 'ArrowRight'
55
+ ? Math.min(last, current + 1)
56
+ : event.key === 'Home'
57
+ ? 0
58
+ : event.key === 'End'
59
+ ? last
60
+ : current;
61
+ // Only a key that actually moves the carousel is ours to swallow. Left on
62
+ // the first slide, Right on the last, Home at the start and End at the
63
+ // end change nothing here, so they stay with the browser — a reader who
64
+ // tabbed onto a screenshot link keeps the default scroll rather than
65
+ // finding those keys dead inside the section.
66
+ if (next === current) return;
67
+ event.preventDefault();
68
+ setCurrent(next);
69
+ }
70
+
71
+ return (
72
+ <section
73
+ aria-label={label}
74
+ aria-roledescription="carousel"
75
+ onKeyDown={handleKeys}
76
+ className="overflow-hidden rounded-xl border border-line bg-surface"
77
+ >
78
+ {/* The column count is the slide count, so a route with six steps does
79
+ not have to remember to change a `grid-cols-5` somewhere else. */}
80
+ <nav
81
+ aria-label="Setup progress"
82
+ className="grid border-b border-line"
83
+ style={{ gridTemplateColumns: `repeat(${slides.length}, minmax(0, 1fr))` }}
84
+ >
85
+ {slides.map((item, index) => {
86
+ const complete = index < current;
87
+ const selected = index === current;
88
+ return (
89
+ <button
90
+ key={item.shortLabel}
91
+ type="button"
92
+ aria-label={`Go to step ${index + 1}: ${item.shortLabel}`}
93
+ aria-current={selected ? 'step' : undefined}
94
+ onClick={() => setCurrent(index)}
95
+ className={`flex min-w-0 items-center justify-center gap-1.5 border-r border-line px-1.5 py-2 text-meta transition-colors last:border-r-0 hover:bg-hover focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ink-muted ${
96
+ selected ? 'bg-sunken font-medium text-ink' : 'text-ink-muted'
97
+ }`}
98
+ >
99
+ <span
100
+ aria-hidden="true"
101
+ className={`flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-micro ${
102
+ selected
103
+ ? 'bg-accent text-white'
104
+ : complete
105
+ ? 'bg-ok-soft text-ok'
106
+ : 'bg-sunken text-ink-faint'
107
+ }`}
108
+ >
109
+ {complete ? <Check size={11} strokeWidth={2.5} /> : index + 1}
110
+ </span>
111
+ <span className="hidden truncate min-[640px]:inline">{item.shortLabel}</span>
112
+ </button>
113
+ );
114
+ })}
115
+ </nav>
116
+
117
+ {/* Live, because moving between slides never moves focus: the reader
118
+ stays on Next or on a progress button while the title, instruction
119
+ and screenshot underneath them all change. The eyebrow inside names
120
+ the new position, so the footer counter does not repeat it. */}
121
+ <div
122
+ role="group"
123
+ aria-roledescription="slide"
124
+ aria-live="polite"
125
+ aria-label={`Step ${current + 1} of ${slides.length}: ${active.title}`}
126
+ >
127
+ <div className="space-y-1.5 border-b border-line px-3 py-3 sm:px-4">
128
+ <div className="text-label uppercase text-accent">
129
+ Step {current + 1} of {slides.length} · {active.stage}
130
+ </div>
131
+ <h3 className="text-head font-medium text-ink">{active.title}</h3>
132
+ <p className="max-w-4xl text-detail leading-relaxed text-ink-muted">
133
+ {active.instruction}
134
+ </p>
135
+ {active.extra}
136
+ </div>
137
+
138
+ <div className="space-y-2 bg-sunken p-2 sm:p-3">
139
+ {active.shots.map((shot) => (
140
+ <ScreenshotStep key={shot.src} shot={shot} />
141
+ ))}
142
+ </div>
143
+ </div>
144
+
145
+ <div className="flex items-center justify-between gap-3 border-t border-line px-3 py-2.5 sm:px-4">
146
+ <Button
147
+ variant="quiet"
148
+ size="sm"
149
+ leadingIcon={<ChevronLeft size={14} />}
150
+ disabled={atStart}
151
+ onClick={() => setCurrent((step) => Math.max(0, step - 1))}
152
+ >
153
+ Back
154
+ </Button>
155
+ <span className="text-meta text-ink-faint">
156
+ {current + 1} / {slides.length}
157
+ </span>
158
+ {/* One control that relabels itself, rather than two behind a
159
+ ternary. Same rendered result — React reconciles same-type
160
+ siblings in place, so either way the reader who pressed Next to
161
+ reach the end keeps focus on it — but here that is the structure
162
+ rather than a property of the reconciler, and a later `key` or an
163
+ extra wrapper cannot quietly unmount the button under their
164
+ focus. Losing it would take the arrow keys with it: this section
165
+ is what handles them. */}
166
+ <Button
167
+ variant={atEnd ? 'outline' : 'primary'}
168
+ size="sm"
169
+ trailingIcon={atEnd ? <RotateCcw size={13} /> : <ChevronRight size={14} />}
170
+ onClick={() => setCurrent((step) => (step === slides.length - 1 ? 0 : step + 1))}
171
+ >
172
+ {atEnd ? 'Review again' : 'Next'}
173
+ </Button>
174
+ </div>
175
+ </section>
176
+ );
177
+ }
@@ -0,0 +1,370 @@
1
+ import { StrictMode } from 'react';
2
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
3
+ import { render, screen, waitFor } from '@testing-library/react';
4
+ import userEvent from '@testing-library/user-event';
5
+ import { MemoryRouter } from 'react-router-dom';
6
+ import { configureBranchModel } from '@bevel-software/platform-shared';
7
+ import { AgentInstructionsCard } from '../AgentInstructionsCard';
8
+ import { AdminContext, type AdminContextValue } from '../../../admin/state/admin.context';
9
+ import { WorkspaceContext, type WorkspaceContextValue } from '../../../workspace/state/workspace.context';
10
+ import type { AgentInstructions } from '../../services/agent-instructions.api';
11
+
12
+ /**
13
+ * The card shows what the server SENDS, organised around what the admin can
14
+ * change: their description with its count, the fixed platform message
15
+ * folded away, and no repository/file-format implementation copy. The Edit
16
+ * action belongs to admins, and only once the KB dir name is known.
17
+ */
18
+
19
+ const { fetchMock, fetchEditableMock, saveMock } = vi.hoisted(() => ({
20
+ fetchMock: vi.fn(),
21
+ fetchEditableMock: vi.fn(),
22
+ saveMock: vi.fn(),
23
+ }));
24
+
25
+ vi.mock('../../services/agent-instructions.api', async (importOriginal) => ({
26
+ ...(await importOriginal<typeof import('../../services/agent-instructions.api')>()),
27
+ fetchAgentInstructions: fetchMock,
28
+ fetchEditableAgentDescription: fetchEditableMock,
29
+ saveAgentDescription: saveMock,
30
+ }));
31
+
32
+ const nonAdmin: AdminContextValue = {
33
+ isAdmin: false,
34
+ unreadCount: 0,
35
+ lastSeen: null,
36
+ markSeen: vi.fn(),
37
+ refresh: vi.fn(),
38
+ rolesConfigCorrupted: false,
39
+ rolesConfigErrors: [],
40
+ runRolesRecovery: vi.fn(),
41
+ };
42
+ const asAdmin: AdminContextValue = { ...nonAdmin, isAdmin: true };
43
+
44
+ const HEADER = "Hexis is this organisation's knowledge base.";
45
+ const LINE = "This organisation's knowledge base. Search it before answering from memory.";
46
+
47
+ const composed = (over: Partial<AgentInstructions> = {}): AgentInstructions => ({
48
+ instructions: `${HEADER}\n\nAcme builds solar farms.\n\n## What is where\n\n- Projects/`,
49
+ header: HEADER,
50
+ preamble: 'Acme builds solar farms.\n\n## What is where\n\n- Projects/',
51
+ toolPrefix: `${LINE} Acme builds solar farms.`,
52
+ toolPrefixLine: LINE,
53
+ truncated: false,
54
+ preambleChars: 1240,
55
+ toolPrefixTruncated: false,
56
+ toolPrefixChars: 212,
57
+ unterminatedComment: false,
58
+ ...over,
59
+ });
60
+
61
+ function mount(
62
+ opts: { admin?: AdminContextValue | null; kbDirName?: string | null | 'no-provider'; strict?: boolean } = {},
63
+ ) {
64
+ const admin = opts.admin === undefined ? nonAdmin : opts.admin;
65
+ const kb = opts.kbDirName === undefined ? 'knowledge-base' : opts.kbDirName;
66
+ let tree = <AgentInstructionsCard />;
67
+ if (kb !== 'no-provider') {
68
+ tree = (
69
+ <WorkspaceContext.Provider value={{ kbDirName: kb } as unknown as WorkspaceContextValue}>{tree}</WorkspaceContext.Provider>
70
+ );
71
+ }
72
+ if (admin !== null) tree = <AdminContext.Provider value={admin}>{tree}</AdminContext.Provider>;
73
+ tree = <MemoryRouter>{tree}</MemoryRouter>;
74
+ // The app mounts under StrictMode, so the load effect is set up, torn down
75
+ // and set up again on the SAME card. Anything the teardown disarms has to
76
+ // be re-armed on the way back in.
77
+ return render(opts.strict ? <StrictMode>{tree}</StrictMode> : tree);
78
+ }
79
+
80
+ beforeEach(() => {
81
+ configureBranchModel({ defaultBranch: 'target-company-state', protectedBranches: ['current-company-state', 'target-company-state'] });
82
+ fetchMock.mockReset();
83
+ fetchMock.mockResolvedValue(composed());
84
+ fetchEditableMock.mockReset();
85
+ fetchEditableMock.mockResolvedValue({
86
+ workspaceId: 'target-company-state',
87
+ source: '<!-- private starter notes -->\n',
88
+ description: '',
89
+ });
90
+ saveMock.mockReset();
91
+ saveMock.mockResolvedValue(undefined);
92
+ });
93
+
94
+ describe('the description', () => {
95
+ it('centres the admin\'s description, with its count, and folds the platform message away', async () => {
96
+ mount();
97
+ expect(await screen.findByRole('heading', { name: 'Your description' })).toBeInTheDocument();
98
+ expect(screen.getByTestId('preamble-count')).toHaveTextContent('1,240 / 6,000 characters');
99
+ const description = screen.getByTestId('description-text');
100
+ expect(description).toHaveTextContent('Acme builds solar farms.');
101
+ expect(description).not.toHaveTextContent(HEADER); // the fixed part is not mixed into the admin's
102
+ // The platform message is there, closed, and not editable.
103
+ const drawer = screen.getByText('Platform message (fixed, sent first)');
104
+ expect(drawer.tagName).toBe('SUMMARY');
105
+ expect((drawer.closest('details') as HTMLDetailsElement).open).toBe(false);
106
+ expect(screen.getByTestId('header-text')).toHaveTextContent(HEADER);
107
+ // Says that access does not gate it.
108
+ expect(screen.getByText(/whatever it may read/)).toBeInTheDocument();
109
+ expect(screen.queryByRole('alert')).toBeNull();
110
+ });
111
+
112
+ it('still lands under StrictMode, whose teardown and second setup run on the same card', async () => {
113
+ mount({ strict: true });
114
+ expect(await screen.findByTestId('description-text')).toHaveTextContent('Acme builds solar farms.');
115
+ });
116
+
117
+ it('explains an empty description instead of showing an empty box', async () => {
118
+ fetchMock.mockResolvedValue(composed({ preamble: '', preambleChars: 0, toolPrefix: LINE, toolPrefixChars: LINE.length }));
119
+ mount();
120
+ expect(await screen.findByTestId('description-empty')).toHaveTextContent('platform message only');
121
+ expect(screen.queryByTestId('description-text')).toBeNull();
122
+ expect(screen.getByTestId('preamble-count')).toHaveTextContent('0 / 6,000 characters');
123
+ });
124
+ });
125
+
126
+ describe('the Edit action', () => {
127
+ it('is offered to admins as an inline action, not a link to another page', async () => {
128
+ mount({ admin: asAdmin });
129
+ const edit = await screen.findByRole('button', { name: /Edit description/ });
130
+ expect(edit.tagName).toBe('BUTTON');
131
+ expect(screen.queryByRole('link', { name: /Edit description/ })).toBeNull();
132
+ expect(screen.queryByText(/mcp-description\.md at the repository root/)).toBeNull();
133
+ expect(screen.queryByText(/first paragraph is automatically reused/)).toBeNull();
134
+ });
135
+
136
+ it('edits and saves the description in place, then refreshes the preview', async () => {
137
+ const empty = composed({ preamble: '', preambleChars: 0, toolPrefix: LINE, toolPrefixChars: LINE.length });
138
+ const saved = composed({
139
+ preamble: 'Acme builds solar farms.',
140
+ preambleChars: 'Acme builds solar farms.'.length,
141
+ toolPrefix: `${LINE} Acme builds solar farms.`,
142
+ toolPrefixChars: `${LINE} Acme builds solar farms.`.length,
143
+ });
144
+ fetchMock.mockResolvedValueOnce(empty).mockResolvedValueOnce(saved);
145
+ const user = userEvent.setup();
146
+ mount({ admin: asAdmin });
147
+
148
+ await user.click(await screen.findByRole('button', { name: 'Edit description' }));
149
+ const editor = await screen.findByRole('textbox', { name: 'Your description' });
150
+ expect(editor).toHaveValue('');
151
+ expect(editor).toHaveAttribute('rows', '1');
152
+ expect(editor.className).toContain('[field-sizing:content]');
153
+ expect(editor.className).not.toContain('min-h-40');
154
+ expect(fetchEditableMock).toHaveBeenCalledWith('knowledge-base');
155
+
156
+ await user.type(editor, 'Acme builds solar farms.');
157
+ expect(screen.getByTestId('preamble-count')).toHaveTextContent('24 / 6,000 characters');
158
+ await user.click(screen.getByRole('button', { name: 'Save description' }));
159
+
160
+ await waitFor(() => {
161
+ expect(saveMock).toHaveBeenCalledWith(
162
+ 'target-company-state',
163
+ 'knowledge-base',
164
+ '<!-- private starter notes -->\n',
165
+ 'Acme builds solar farms.',
166
+ );
167
+ });
168
+ expect(await screen.findByTestId('description-text')).toHaveTextContent('Acme builds solar farms.');
169
+ expect(screen.queryByRole('textbox', { name: 'Your description' })).toBeNull();
170
+ });
171
+
172
+ it('keeps the post-save preview when the initial load answers after it', async () => {
173
+ // The initial request is still in flight while the admin edits and saves.
174
+ // Its response arrives last and must land nowhere: the page would
175
+ // otherwise show the pre-save text as though the save had not happened.
176
+ const before = composed({ preamble: 'Before.', preambleChars: 6 });
177
+ const after = composed({ preamble: 'After.', preambleChars: 5 });
178
+ let releaseInitialLoad: () => void = () => {};
179
+ const initialLoad = new Promise<AgentInstructions>((resolve) => {
180
+ releaseInitialLoad = () => resolve(before);
181
+ });
182
+ fetchMock.mockReturnValueOnce(initialLoad).mockResolvedValueOnce(after);
183
+ fetchEditableMock.mockResolvedValue({
184
+ workspaceId: 'target-company-state',
185
+ source: 'Before.',
186
+ description: 'Before.',
187
+ });
188
+ const user = userEvent.setup();
189
+ mount({ admin: asAdmin });
190
+
191
+ await user.click(await screen.findByRole('button', { name: 'Edit description' }));
192
+ const editor = await screen.findByRole('textbox', { name: 'Your description' });
193
+ await user.clear(editor);
194
+ await user.type(editor, 'After.');
195
+ await user.click(screen.getByRole('button', { name: 'Save description' }));
196
+
197
+ expect(await screen.findByTestId('description-text')).toHaveTextContent('After.');
198
+ releaseInitialLoad();
199
+ await waitFor(() => expect(fetchMock).toHaveBeenCalledTimes(2));
200
+ expect(screen.getByTestId('description-text')).toHaveTextContent('After.');
201
+ });
202
+
203
+ it('keeps the inline editor open and shows the save error', async () => {
204
+ fetchEditableMock.mockResolvedValue({
205
+ workspaceId: 'target-company-state',
206
+ source: 'Before.',
207
+ description: 'Before.',
208
+ });
209
+ saveMock.mockRejectedValue(new Error('File is locked by Ada.'));
210
+ const user = userEvent.setup();
211
+ mount({ admin: asAdmin });
212
+
213
+ await user.click(await screen.findByRole('button', { name: 'Edit description' }));
214
+ const editor = await screen.findByRole('textbox', { name: 'Your description' });
215
+ await user.clear(editor);
216
+ await user.type(editor, 'After.');
217
+ await user.click(screen.getByRole('button', { name: 'Save description' }));
218
+
219
+ expect(await screen.findByRole('alert')).toHaveTextContent('File is locked by Ada.');
220
+ expect(screen.getByRole('textbox', { name: 'Your description' })).toHaveValue('After.');
221
+ });
222
+
223
+ it('still opens the editor when the composed preview could not load', async () => {
224
+ fetchMock.mockRejectedValue(new Error('Preview unavailable.'));
225
+ fetchEditableMock.mockResolvedValue({
226
+ workspaceId: 'target-company-state',
227
+ source: 'Editable source.',
228
+ description: 'Editable source.',
229
+ });
230
+ const user = userEvent.setup();
231
+ mount({ admin: asAdmin });
232
+
233
+ expect(await screen.findByRole('alert')).toHaveTextContent('Preview unavailable.');
234
+ await user.click(screen.getByRole('button', { name: 'Edit description' }));
235
+
236
+ expect(await screen.findByRole('textbox', { name: 'Your description' })).toHaveValue('Editable source.');
237
+ });
238
+
239
+ it('is withheld from non-admins without exposing repository implementation details', async () => {
240
+ mount({ admin: nonAdmin });
241
+ await screen.findByRole('heading', { name: 'Your description' });
242
+ expect(screen.queryByRole('button', { name: /Edit/ })).toBeNull();
243
+ expect(screen.queryByText(/mcp-description\.md at the repository root/)).toBeNull();
244
+ });
245
+
246
+ it('waits for the KB dir name: no edit action with a missing save path, ever', async () => {
247
+ mount({ admin: asAdmin, kbDirName: null });
248
+ await screen.findByRole('heading', { name: 'Your description' });
249
+ expect(screen.queryByRole('button', { name: /Edit/ })).toBeNull();
250
+ });
251
+
252
+ it('offers no edit action for an empty KB dir name either — a button that could not save', async () => {
253
+ mount({ admin: asAdmin, kbDirName: '' });
254
+ await screen.findByRole('heading', { name: 'Your description' });
255
+ expect(screen.queryByRole('button', { name: /Edit/ })).toBeNull();
256
+ });
257
+
258
+ it('tolerates absent providers: no admin context and no workspace context still render the card', async () => {
259
+ mount({ admin: null, kbDirName: 'no-provider' });
260
+ expect(await screen.findByRole('heading', { name: 'Your description' })).toBeInTheDocument();
261
+ expect(screen.queryByRole('button', { name: /Edit/ })).toBeNull();
262
+ });
263
+ });
264
+
265
+ describe('warnings', () => {
266
+ it('warns when the description is over its cap, with the count over the cap', async () => {
267
+ fetchMock.mockResolvedValue(composed({ truncated: true, preambleChars: 7350 }));
268
+ mount();
269
+ const alert = await screen.findByRole('alert');
270
+ expect(alert).toHaveTextContent('agents receive only the first 6,000 characters');
271
+ expect(screen.getByTestId('preamble-count')).toHaveTextContent('7,350 / 6,000 characters');
272
+ });
273
+
274
+ it('warns about an open comment and, for an admin, names the action on THIS page', async () => {
275
+ // The file is hidden from the tree by this change, so "close it in
276
+ // mcp-description.md" would be a repair the admin cannot reach.
277
+ fetchMock.mockResolvedValue(composed({ unterminatedComment: true }));
278
+ mount({ admin: asAdmin });
279
+ const alert = await screen.findByRole('alert');
280
+ expect(alert).toHaveTextContent('A comment is left open');
281
+ expect(alert).toHaveTextContent('withheld from agents');
282
+ expect(alert).toHaveTextContent('Open the editor and save');
283
+ expect(alert).not.toHaveTextContent('mcp-description.md');
284
+ });
285
+
286
+ it('tells a non-admin who can fix it', async () => {
287
+ fetchMock.mockResolvedValue(composed({ unterminatedComment: true }));
288
+ mount({ admin: nonAdmin });
289
+ const alert = await screen.findByRole('alert');
290
+ expect(alert).toHaveTextContent('An admin can close it from this page');
291
+ });
292
+
293
+ it('warns when the tool-description channel is cutting the first paragraph', async () => {
294
+ // The composer still cuts the prefix at its own cap and still reports it;
295
+ // dropping the short-version preview must not drop the only signal.
296
+ fetchMock.mockResolvedValue(composed({ toolPrefixTruncated: true, toolPrefixChars: 415 }));
297
+ mount();
298
+ const alert = await screen.findByRole('alert');
299
+ // The count is the FIXED LINE plus the paragraph, so the warning must not
300
+ // blame the paragraph alone: a 225-character paragraph trips a 300 cap.
301
+ expect(alert).toHaveTextContent('The fixed line and your first paragraph');
302
+ expect(alert).toHaveTextContent('together they are over');
303
+ expect(alert).toHaveTextContent('300-character');
304
+ expect(alert).toHaveTextContent('415');
305
+ // Names WHO is affected, so an admin can tell whether this matters to
306
+ // their deployment rather than guessing what "ignores the handshake" means.
307
+ expect(alert).toHaveTextContent('claude.ai on the web, the Agent SDK and Cline');
308
+ expect(alert).toHaveTextContent('Claude Code, Claude Desktop and Cursor');
309
+ expect(alert).toHaveTextContent('Shorten the first paragraph');
310
+ });
311
+
312
+ it('lets an admin save a file whose only problem is the hidden open comment', async () => {
313
+ // Save used to be disabled while the VISIBLE text was unchanged, so the
314
+ // one repair for an open comment was unreachable.
315
+ fetchEditableMock.mockResolvedValue({
316
+ workspaceId: 'target-company-state',
317
+ source: 'Public text.\n<!-- a note that was never closed',
318
+ description: 'Public text.',
319
+ });
320
+ const user = userEvent.setup();
321
+ mount({ admin: asAdmin });
322
+
323
+ await user.click(await screen.findByRole('button', { name: 'Edit description' }));
324
+ await screen.findByRole('textbox', { name: 'Your description' });
325
+ const save = screen.getByRole('button', { name: 'Save and close the comment' });
326
+ expect(save).toBeEnabled();
327
+
328
+ await user.click(save);
329
+
330
+ await waitFor(() => {
331
+ expect(saveMock).toHaveBeenCalledWith(
332
+ 'target-company-state',
333
+ 'knowledge-base',
334
+ 'Public text.\n<!-- a note that was never closed',
335
+ 'Public text.',
336
+ );
337
+ });
338
+ });
339
+
340
+ it('keeps Save disabled when there is genuinely nothing to save', async () => {
341
+ fetchEditableMock.mockResolvedValue({
342
+ workspaceId: 'target-company-state',
343
+ source: 'Public text.',
344
+ description: 'Public text.',
345
+ });
346
+ const user = userEvent.setup();
347
+ mount({ admin: asAdmin });
348
+
349
+ await user.click(await screen.findByRole('button', { name: 'Edit description' }));
350
+ await screen.findByRole('textbox', { name: 'Your description' });
351
+ expect(screen.getByRole('button', { name: 'Save description' })).toBeDisabled();
352
+ });
353
+
354
+ it('shows each warning only when flagged', async () => {
355
+ fetchMock.mockResolvedValue(composed({ truncated: true, unterminatedComment: true }));
356
+ mount();
357
+ const alerts = await screen.findAllByRole('alert');
358
+ expect(alerts).toHaveLength(2);
359
+ });
360
+ });
361
+
362
+ describe('a failed fetch', () => {
363
+ it('shows an inline message and nothing else breaks', async () => {
364
+ fetchMock.mockRejectedValue(new Error('boom'));
365
+ mount();
366
+ expect(await screen.findByRole('alert')).toHaveTextContent('boom');
367
+ expect(screen.getByRole('heading', { name: 'What agents are told about this knowledge base' })).toBeInTheDocument();
368
+ expect(screen.queryByRole('heading', { name: 'Your description' })).toBeNull();
369
+ });
370
+ });