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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (346) hide show
  1. package/THIRD-PARTY-NOTICES.md +2 -2
  2. package/package.json +3 -3
  3. package/src/core/CoreAppShell.tsx +16 -9
  4. package/src/core/__tests__/AppChrome.test.tsx +0 -3
  5. package/src/core/__tests__/events.test.ts +43 -0
  6. package/src/core/bootstrap.ts +11 -3
  7. package/src/core/events.ts +85 -3
  8. package/src/core/registry.ts +1 -1
  9. package/src/lib/__tests__/email.test.ts +44 -0
  10. package/src/lib/email.ts +37 -1
  11. package/src/modules/access/__tests__/ManageAccessDialog.add-row-picking.test.tsx +141 -0
  12. package/src/modules/access/__tests__/ManageAccessDialog.chip-truncation.test.tsx +204 -0
  13. package/src/modules/access/__tests__/ManageAccessDialog.download-read.test.tsx +234 -0
  14. package/src/modules/access/__tests__/ManageAccessDialog.edited-row-visible.test.tsx +160 -0
  15. package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +2 -2
  16. package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +166 -0
  17. package/src/modules/access/__tests__/ManageAccessDialog.restrict.test.tsx +510 -0
  18. package/src/modules/access/__tests__/ManageAccessDialog.row-menu-axes.test.tsx +299 -0
  19. package/src/modules/access/__tests__/ManageAccessDialog.row-menu-width.test.tsx +226 -0
  20. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +721 -126
  21. package/src/modules/access/__tests__/ManageAccessDialog.unknown-email.test.tsx +314 -0
  22. package/src/modules/access/__tests__/manage-access-affordance.test.ts +14 -0
  23. package/src/modules/access/__tests__/tailwindDeclarations.ts +210 -0
  24. package/src/modules/access/api.ts +140 -6
  25. package/src/modules/access/components/ManageAccessDialog.tsx +1299 -561
  26. package/src/modules/access/manage-access-affordance.ts +17 -0
  27. package/src/modules/admin/__tests__/AddMemberInput.test.tsx +297 -0
  28. package/src/modules/admin/__tests__/AdminRolesPage.capabilities.test.tsx +2 -2
  29. package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +189 -0
  30. package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +1 -1
  31. package/src/modules/admin/__tests__/ConnectionKeysPage.test.tsx +266 -0
  32. package/src/modules/admin/__tests__/DirectoryGroupsPage.suggest.test.tsx +182 -0
  33. package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +165 -14
  34. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +401 -4
  35. package/src/modules/admin/__tests__/group-members-path.test.ts +27 -0
  36. package/src/modules/admin/components/AddMemberInput.tsx +268 -0
  37. package/src/modules/admin/components/AdminRolesPage.tsx +97 -132
  38. package/src/modules/admin/components/ConnectionKeysPage.tsx +269 -0
  39. package/src/modules/admin/components/DirectoryGroupsPage.tsx +91 -39
  40. package/src/modules/admin/components/UserAccountsPage.tsx +271 -37
  41. package/src/modules/admin/components/connection-keys-grouping.ts +43 -0
  42. package/src/modules/admin/components/group-members-path.ts +32 -0
  43. package/src/modules/admin/services/connection-keys.api.ts +47 -0
  44. package/src/modules/admin/services/roles.api.ts +12 -1
  45. package/src/modules/auth/__tests__/AccountPage.test.tsx +50 -2
  46. package/src/modules/auth/components/AccountPage.tsx +73 -54
  47. package/src/modules/auth/components/LoginScreen.tsx +1 -0
  48. package/src/modules/auth/services/account.api.ts +78 -4
  49. package/src/modules/change-requests/__tests__/ChangeRequestDialog.access-rules.test.tsx +144 -0
  50. package/src/modules/change-requests/__tests__/ChangeRequestDialog.binary.test.tsx +422 -0
  51. package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +431 -0
  52. package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +193 -0
  53. package/src/modules/change-requests/__tests__/ChangeRequestDialog.initial-file.test.tsx +142 -0
  54. package/src/modules/change-requests/__tests__/ChangeRequestDialog.moved.test.tsx +202 -0
  55. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +205 -13
  56. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +271 -0
  57. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +208 -0
  58. package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +286 -0
  59. package/src/modules/change-requests/__tests__/propose.concurrent.test.ts +273 -0
  60. package/src/modules/change-requests/__tests__/readFailure.test.ts +122 -0
  61. package/src/modules/change-requests/__tests__/useCrFileDiffs.test.tsx +238 -0
  62. package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +56 -1
  63. package/src/modules/change-requests/__tests__/useForkPointFile.test.tsx +79 -0
  64. package/src/modules/change-requests/components/BranchFilePreview.tsx +357 -0
  65. package/src/modules/change-requests/components/ChangeBox.tsx +31 -2
  66. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +862 -72
  67. package/src/modules/change-requests/components/CrFileTree.tsx +74 -58
  68. package/src/modules/change-requests/components/FileChangeBoxes.tsx +19 -15
  69. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +41 -7
  70. package/src/modules/change-requests/hooks/useCrFileDiffs.ts +181 -23
  71. package/src/modules/change-requests/hooks/useFileOnBranch.ts +70 -7
  72. package/src/modules/change-requests/hooks/useForkPointFile.ts +77 -0
  73. package/src/modules/change-requests/services/change-requests.api.ts +57 -1
  74. package/src/modules/change-requests/services/denied-file.api.ts +53 -0
  75. package/src/modules/change-requests/services/propose.api.ts +97 -8
  76. package/src/modules/change-requests/utils/approval.ts +15 -0
  77. package/src/modules/change-requests/utils/author.ts +32 -0
  78. package/src/modules/change-requests/utils/readFailure.ts +110 -0
  79. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +20 -0
  80. package/src/modules/git/components/FileHistoryPanel.tsx +5 -0
  81. package/src/modules/git/components/PullRequestsForMe.tsx +51 -24
  82. package/src/modules/git/services/__tests__/error-messages.test.ts +29 -0
  83. package/src/modules/git/services/error-messages.ts +12 -0
  84. package/src/modules/git/services/pr-prompts.ts +5 -5
  85. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +401 -0
  86. package/src/modules/layout/__tests__/SidebarFooterGrid.test.tsx +286 -0
  87. package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +61 -0
  88. package/src/modules/layout/components/AppLayout.tsx +2 -0
  89. package/src/modules/layout/components/MobileChatLayout.tsx +4 -1
  90. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +4 -1
  91. package/src/modules/layout/components/SidebarFrame.tsx +108 -3
  92. package/src/modules/library/__tests__/AddToPluginDialog.test.tsx +171 -5
  93. package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +356 -0
  94. package/src/modules/library/__tests__/IntegrationsSetupReminder.test.tsx +60 -0
  95. package/src/modules/library/__tests__/LibraryCard.test.tsx +91 -10
  96. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +242 -107
  97. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +103 -98
  98. package/src/modules/library/__tests__/LinkSkillPanel.test.tsx +20 -5
  99. package/src/modules/library/__tests__/LockedPluginView.test.tsx +97 -7
  100. package/src/modules/library/__tests__/NewPluginDialog.test.tsx +13 -4
  101. package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +79 -3
  102. package/src/modules/library/__tests__/PersonalPluginPage.test.tsx +201 -0
  103. package/src/modules/library/__tests__/PluginExtras.test.tsx +100 -9
  104. package/src/modules/library/__tests__/PluginJoinRequests.test.tsx +60 -1
  105. package/src/modules/library/__tests__/PluginPage.test.tsx +258 -6
  106. package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +16 -56
  107. package/src/modules/library/__tests__/PluginsSidebar.test.tsx +155 -152
  108. package/src/modules/library/__tests__/PluginsSidebarMenu.test.tsx +16 -0
  109. package/src/modules/library/__tests__/SharedViaPlugins.test.tsx +106 -0
  110. package/src/modules/library/__tests__/SkillPage.test.tsx +386 -80
  111. package/src/modules/library/__tests__/SkillsTree.test.tsx +293 -4
  112. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +582 -71
  113. package/src/modules/library/__tests__/ToolPage.test.tsx +87 -4
  114. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +173 -26
  115. package/src/modules/library/__tests__/auth-harness.tsx +9 -9
  116. package/src/modules/library/__tests__/card-row-menu.test.tsx +320 -0
  117. package/src/modules/library/__tests__/library-data.mapping.test.tsx +98 -0
  118. package/src/modules/library/__tests__/library-data.stale.test.tsx +121 -28
  119. package/src/modules/library/__tests__/library-data.test.ts +7 -0
  120. package/src/modules/library/__tests__/library-paths.test.ts +47 -4
  121. package/src/modules/library/__tests__/link-membership.test.ts +13 -4
  122. package/src/modules/library/__tests__/name-with-badges.test.tsx +273 -0
  123. package/src/modules/library/__tests__/newSkillMarkdown.test.ts +30 -0
  124. package/src/modules/library/__tests__/owner-pill.test.tsx +357 -0
  125. package/src/modules/library/__tests__/pending-tools.test.tsx +400 -0
  126. package/src/modules/library/__tests__/plugin-entries.test.ts +122 -0
  127. package/src/modules/library/__tests__/plugin-summary.test.ts +36 -1
  128. package/src/modules/library/__tests__/status.test.ts +82 -2
  129. package/src/modules/library/__tests__/tools.api.test.ts +44 -1
  130. package/src/modules/library/components/AccessRequestsBanner.tsx +85 -47
  131. package/src/modules/library/components/AddDialogTabs.tsx +103 -0
  132. package/src/modules/library/components/AddToPluginDialog.tsx +74 -18
  133. package/src/modules/library/components/IntegrationsSetupReminder.tsx +59 -0
  134. package/src/modules/library/components/ItemActionsMenu.tsx +288 -0
  135. package/src/modules/library/components/LibraryCard.tsx +146 -45
  136. package/src/modules/library/components/LibraryLayout.tsx +119 -256
  137. package/src/modules/library/components/LibraryPage.tsx +172 -39
  138. package/src/modules/library/components/LinkSkillPanel.tsx +1 -3
  139. package/src/modules/library/components/LockedPluginView.tsx +62 -34
  140. package/src/modules/library/components/NameWithBadges.tsx +164 -0
  141. package/src/modules/library/components/NewPluginDialog.tsx +16 -2
  142. package/src/modules/library/components/PageActions.tsx +11 -9
  143. package/src/modules/library/components/{PendingSkillReview.tsx → PendingItemReview.tsx} +14 -7
  144. package/src/modules/library/components/PersonalAddDialog.tsx +68 -18
  145. package/src/modules/library/components/PersonalPluginPage.tsx +121 -22
  146. package/src/modules/library/components/PluginExtras.tsx +140 -17
  147. package/src/modules/library/components/PluginIndexRow.tsx +47 -12
  148. package/src/modules/library/components/PluginPage.tsx +157 -41
  149. package/src/modules/library/components/PluginRows.tsx +286 -0
  150. package/src/modules/library/components/PluginsSidebar.tsx +239 -263
  151. package/src/modules/library/components/PluginsSidebarMenu.tsx +26 -1
  152. package/src/modules/library/components/ShareButton.tsx +17 -0
  153. package/src/modules/library/components/SkillsTree.tsx +141 -28
  154. package/src/modules/library/components/TeamRoute.tsx +15 -0
  155. package/src/modules/library/components/__tests__/upload-notices-once-per-page.test.tsx +144 -0
  156. package/src/modules/library/components/plugin-page-parts.tsx +103 -17
  157. package/src/modules/library/components/skill-page/SharedViaPlugins.tsx +6 -12
  158. package/src/modules/library/components/skill-page/SkillFilePane.tsx +5 -0
  159. package/src/modules/library/components/skill-page/SkillPage.tsx +274 -122
  160. package/src/modules/library/components/tool-page/DeleteToolDialog.tsx +218 -0
  161. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +79 -178
  162. package/src/modules/library/components/tool-page/ToolPage.tsx +106 -16
  163. package/src/modules/library/components/tool-page/ToolVarRow.tsx +42 -41
  164. package/src/modules/library/hooks/__tests__/useLibraryData.test.ts +98 -0
  165. package/src/modules/library/hooks/useLibraryData.ts +92 -19
  166. package/src/modules/library/routes/LibraryRoutes.tsx +14 -11
  167. package/src/modules/library/routes/WorkspaceItemRoute.tsx +77 -27
  168. package/src/modules/library/routes/library-paths.ts +26 -28
  169. package/src/modules/library/services/library.api.ts +38 -20
  170. package/src/modules/library/services/plugins.api.ts +69 -8
  171. package/src/modules/library/services/teams.api.ts +15 -0
  172. package/src/modules/library/services/tools.api.ts +78 -0
  173. package/src/modules/library/state/library-data.tsx +170 -32
  174. package/src/modules/library/utils/personal-plugin.ts +13 -15
  175. package/src/modules/library/utils/plugin-entries.ts +134 -0
  176. package/src/modules/library/utils/plugin-summary.ts +75 -9
  177. package/src/modules/library/utils/status.ts +135 -33
  178. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +8 -1
  179. package/src/modules/onboarding/__tests__/onboarding.test.tsx +853 -760
  180. package/src/modules/onboarding/agent-clients.ts +55 -23
  181. package/src/modules/onboarding/components/ConnectAgentPill.tsx +5 -1
  182. package/src/modules/onboarding/components/WelcomePage.tsx +98 -62
  183. package/src/modules/pr/services/pr-merge.api.ts +2 -1
  184. package/src/modules/review/components/MarkdownDiffViewer.tsx +53 -8
  185. package/src/modules/review/components/ReviewPanel.tsx +15 -17
  186. package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +64 -0
  187. package/src/modules/review/components/__tests__/ReviewPanel.test.tsx +25 -1
  188. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +454 -117
  189. package/src/modules/secrets-vault/components/SecretsPage.tsx +48 -7
  190. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +84 -5
  191. package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +425 -0
  192. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +417 -82
  193. package/src/modules/secrets-vault/components/__tests__/ToolSecretsPanel.test.tsx +105 -0
  194. package/src/modules/secrets-vault/components/__tests__/connect-lists-what-the-banner-counted.test.tsx +407 -0
  195. package/src/modules/secrets-vault/probe/SavedKeyProbeResult.tsx +98 -0
  196. package/src/modules/secrets-vault/probe/__tests__/probe-verdict.test.ts +160 -0
  197. package/src/modules/secrets-vault/probe/probe-verdict.ts +108 -0
  198. package/src/modules/secrets-vault/probe/useSavedKeyProbe.ts +228 -0
  199. package/src/modules/secrets-vault/services/connect.api.ts +36 -5
  200. package/src/modules/secrets-vault/utils/connect-status.ts +98 -0
  201. package/src/modules/settings/components/ClaudeConnectionCard.tsx +9 -24
  202. package/src/modules/settings/components/ClaudeConnectionFields.tsx +23 -0
  203. package/src/modules/settings/components/DeploymentPage.tsx +10 -30
  204. package/src/modules/settings/components/MarketplaceSection.tsx +152 -0
  205. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +67 -4
  206. package/src/modules/settings/components/__tests__/MarketplaceSection.test.tsx +325 -0
  207. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +5 -5
  208. package/src/modules/settings/services/github-facade.api.ts +23 -0
  209. package/src/modules/settings/settings-nav-items.tsx +10 -2
  210. package/src/modules/setup/__tests__/setup.oidc.test.tsx +172 -0
  211. package/src/modules/setup/__tests__/setup.probe-refusal.test.tsx +123 -0
  212. package/src/modules/setup/__tests__/setup.test.tsx +497 -4
  213. package/src/modules/setup/__tests__/useSetupStatus.test.tsx +130 -0
  214. package/src/modules/setup/components/SetupGate.tsx +16 -16
  215. package/src/modules/setup/components/SetupScreen.tsx +521 -43
  216. package/src/modules/setup/hooks/useSetupStatus.ts +93 -0
  217. package/src/modules/setup/services/setup.api.ts +140 -3
  218. package/src/modules/setup/utils/__tests__/root-folders.test.ts +72 -0
  219. package/src/modules/setup/utils/root-folders.ts +46 -0
  220. package/src/modules/toolbar/assets/claude-setup/01-add-manually.webp +0 -0
  221. package/src/modules/toolbar/assets/claude-setup/02-add-configuration.webp +0 -0
  222. package/src/modules/toolbar/assets/claude-setup/03-connect-account.webp +0 -0
  223. package/src/modules/toolbar/assets/claude-setup/04-pick-instance.webp +0 -0
  224. package/src/modules/toolbar/assets/claude-setup/05-plugins-add.webp +0 -0
  225. package/src/modules/toolbar/assets/claude-setup/06-add-marketplace.webp +0 -0
  226. package/src/modules/toolbar/assets/claude-setup/07-paste-url-sync.webp +0 -0
  227. package/src/modules/toolbar/assets/claude-setup/08-install-plugins.webp +0 -0
  228. package/src/modules/toolbar/assets/claude-setup/09-select-repository.webp +0 -0
  229. package/src/modules/toolbar/assets/claude-setup/10-connector-not-added.webp +0 -0
  230. package/src/modules/toolbar/assets/claude-setup/11-add-custom-connector.webp +0 -0
  231. package/src/modules/toolbar/assets/claude-setup/README.md +68 -0
  232. package/src/modules/toolbar/components/AgentInstructionsCard.tsx +296 -0
  233. package/src/modules/toolbar/components/ClaudeMarketplaceCarousel.tsx +107 -0
  234. package/src/modules/toolbar/components/ClaudeRegistrationSteps.tsx +127 -0
  235. package/src/modules/toolbar/components/CoworkSetupSteps.tsx +100 -0
  236. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +177 -118
  237. package/src/modules/toolbar/components/ScreenshotStep.tsx +77 -0
  238. package/src/modules/toolbar/components/SetupCarousel.tsx +177 -0
  239. package/src/modules/toolbar/components/__tests__/AgentInstructionsCard.test.tsx +370 -0
  240. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +542 -42
  241. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +2 -2
  242. package/src/modules/toolbar/components/__tests__/claude-setup-shots.test.ts +104 -0
  243. package/src/modules/toolbar/components/claude-connector-slide.tsx +38 -0
  244. package/src/modules/toolbar/components/claude-setup-shots.ts +167 -0
  245. package/src/modules/toolbar/components/deployment-address.ts +29 -0
  246. package/src/modules/toolbar/components/setup-step-parts.tsx +35 -0
  247. package/src/modules/toolbar/services/__tests__/agent-instructions.api.test.ts +89 -0
  248. package/src/modules/toolbar/services/agent-instructions.api.ts +167 -0
  249. package/src/modules/toolbar/services/external-api-keys.api.ts +6 -0
  250. package/src/modules/workflow/state/ChangeRequestStaleBinder.tsx +43 -0
  251. package/src/modules/workflow/state/EventBusProvider.tsx +122 -11
  252. package/src/modules/workflow/state/__tests__/EventBusProvider.storage.test.tsx +87 -0
  253. package/src/modules/workflow/state/__tests__/EventBusProvider.watch.test.tsx +223 -0
  254. package/src/modules/workflow/state/event-bus.context.ts +10 -0
  255. package/src/modules/workspace/__tests__/testFixtures.ts +5 -3
  256. package/src/modules/workspace/components/FileExplorer.tsx +1295 -191
  257. package/src/modules/workspace/components/FileRoute.tsx +353 -36
  258. package/src/modules/workspace/components/FileViewer.tsx +166 -45
  259. package/src/modules/workspace/components/KbDocumentShell.tsx +50 -6
  260. package/src/modules/workspace/components/KbPageHeader.tsx +120 -55
  261. package/src/modules/workspace/components/TreeActionConfirm.tsx +350 -0
  262. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +2473 -129
  263. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +731 -18
  264. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +331 -12
  265. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +39 -0
  266. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +33 -20
  267. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +4 -5
  268. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +13 -4
  269. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +4 -3
  270. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +8 -14
  271. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +75 -16
  272. package/src/modules/workspace/components/renderers/KbImage.tsx +180 -0
  273. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +22 -6
  274. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +48 -22
  275. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +4 -5
  276. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +4 -3
  277. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +4 -3
  278. package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +12 -0
  279. package/src/modules/workspace/components/renderers/__tests__/DownloadFileButton.test.tsx +57 -9
  280. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.test.tsx +13 -1
  281. package/src/modules/workspace/components/renderers/__tests__/ImageRenderer.test.tsx +163 -0
  282. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +237 -0
  283. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +108 -14
  284. package/src/modules/workspace/components/renderers/__tests__/PptxRenderer.test.tsx +14 -1
  285. package/src/modules/workspace/components/renderers/__tests__/XlsxRenderer.test.tsx +16 -1
  286. package/src/modules/workspace/components/renderers/__tests__/rendererSelection.test.tsx +66 -1
  287. package/src/modules/workspace/components/renderers/index.ts +53 -2
  288. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +25 -4
  289. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +40 -0
  290. package/src/modules/workspace/hooks/__tests__/useImageRevision.test.tsx +174 -0
  291. package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +179 -1
  292. package/src/modules/workspace/hooks/__tests__/useWorkspaceImageResolver.test.tsx +122 -0
  293. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +892 -7
  294. package/src/modules/workspace/hooks/useImageRevision.ts +101 -0
  295. package/src/modules/workspace/hooks/useMergedWorkspaceTree.ts +22 -3
  296. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +55 -0
  297. package/src/modules/workspace/hooks/useWorkspaceState.ts +424 -66
  298. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +279 -3
  299. package/src/modules/workspace/routing/kb-routes.ts +206 -29
  300. package/src/modules/workspace/services/__tests__/workspace.api.test.ts +57 -1
  301. package/src/modules/workspace/services/workspace.api.ts +57 -4
  302. package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +343 -0
  303. package/src/modules/workspace/state/__tests__/upload-lands-where-it-was-dropped.test.tsx +158 -0
  304. package/src/modules/workspace/state/open-change-requests.tsx +100 -12
  305. package/src/modules/workspace/state/workspace.context.ts +125 -19
  306. package/src/modules/workspace/utils/__tests__/file-trace.test.ts +73 -0
  307. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +220 -6
  308. package/src/modules/workspace/utils/__tests__/pasteLink.test.ts +76 -0
  309. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +364 -0
  310. package/src/modules/workspace/utils/__tests__/uploadError.test.ts +35 -0
  311. package/src/modules/workspace/utils/file-trace.ts +50 -0
  312. package/src/modules/workspace/utils/fileTree.ts +112 -36
  313. package/src/modules/workspace/utils/frontmatter.ts +8 -4
  314. package/src/modules/workspace/utils/pasteLink.ts +90 -0
  315. package/src/modules/workspace/utils/treeConfirm.ts +338 -0
  316. package/src/modules/workspace/utils/uploadError.ts +29 -0
  317. package/src/shared/__tests__/marketplace-url.test.ts +6 -1
  318. package/src/shared/components/Button.tsx +16 -2
  319. package/src/shared/components/Dialog.tsx +27 -11
  320. package/src/shared/components/Menu.tsx +13 -1
  321. package/src/shared/components/PageShell.tsx +13 -8
  322. package/src/shared/components/__tests__/primitives.test.tsx +116 -2
  323. package/src/shared/components/__tests__/useFocusHandoff.test.tsx +192 -0
  324. package/src/shared/components/index.ts +2 -0
  325. package/src/shared/components/useDismissableMenu.ts +32 -10
  326. package/src/shared/components/useFocusHandoff.ts +51 -0
  327. package/src/shared/components/useLatestRef.ts +28 -0
  328. package/src/shared/markdown/Markdown.tsx +12 -3
  329. package/src/shared/markdown/__tests__/escapeSpacesInLinkDestinations.test.ts +39 -0
  330. package/src/shared/markdown/hrefs.ts +50 -0
  331. package/src/shared/marketplace-url.ts +33 -5
  332. package/src/shared/mcp/ChatGptInstallLink.tsx +3 -3
  333. package/src/shared/mcp/ConnectionInstructions.tsx +38 -27
  334. package/src/shared/mcp/__tests__/connect-snippets.test.ts +3 -3
  335. package/src/shared/mcp/connect-snippets.ts +14 -9
  336. package/src/shared/mcp/index.ts +1 -1
  337. package/src/shared/theme/__tests__/header-band.test.ts +197 -0
  338. package/src/shared/theme/header.ts +75 -0
  339. package/src/shared/theme/measure.ts +7 -4
  340. package/src/shared/theme/tokens.css +25 -0
  341. package/src/modules/library/__tests__/PluginsIndexPage.test.tsx +0 -363
  342. package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +0 -97
  343. package/src/modules/library/components/PluginsIndexPage.tsx +0 -270
  344. package/src/modules/update-check/__tests__/UpdateBanner.test.tsx +0 -126
  345. package/src/modules/update-check/components/UpdateBanner.tsx +0 -92
  346. package/src/modules/update-check/services/update-check.api.ts +0 -24
@@ -1,15 +1,27 @@
1
1
  import { useEffect, useRef, useState, type FormEvent } from 'react';
2
+ import {
3
+ DEFAULT_KB_LAYOUT,
4
+ agentsFilePointerSentence,
5
+ type KbLayout,
6
+ } from '@bevel-software/platform-shared';
2
7
  import { Banner, Button, Surface, TextField } from '../../../shared/components';
3
8
  import { tokenUsernameForHost } from '../utils/git-host';
9
+ import { isRootFolderSuggestion, rootFolderState, type RootFolderState } from '../utils/root-folders';
4
10
  import { copyToClipboard } from '../../../lib/clipboard';
11
+ import { MarketplaceSection } from '../../settings/components/MarketplaceSection';
5
12
  import {
6
13
  saveSettings,
7
14
  syncNow,
8
15
  syncOutcomeError,
9
16
  testConnection,
17
+ KbInitFailed,
18
+ testOidc,
10
19
  SettingsProblems,
11
20
  type ConnectionTest,
21
+ type KbInitFailure,
12
22
  type LastSync,
23
+ type OidcTest,
24
+ type OidcVerification,
13
25
  type SettingStatus,
14
26
  type SyncNowResult,
15
27
  type SyncStatus,
@@ -98,23 +110,31 @@ const FIELDS: Record<
98
110
  placeholder: 'A long random string',
99
111
  advanced: true,
100
112
  },
113
+ // The three roots are NOT under Advanced: a repository whose skills live in
114
+ // `skills/` connected fine, got an empty `Skills/` scaffolded beside it and
115
+ // imported nothing — a choice that has to be seen to be made.
101
116
  knowledgeBaseDir: {
102
117
  label: 'Knowledge folder',
103
118
  help: 'The top-level folder in the repository that holds the knowledge. Change it only to read a repository laid out by someone else.',
104
119
  placeholder: 'KnowledgeBase',
105
- advanced: true,
106
120
  },
107
121
  skillsDir: {
108
122
  label: 'Skills folder',
109
- help: 'The top-level folder that holds shared skills. The three folder names must differ.',
123
+ help: 'The top-level folder that holds shared skills. The three folder names must differ. Case matters: skills and Skills are different folders.',
110
124
  placeholder: 'Skills',
111
- advanced: true,
112
125
  },
113
126
  pluginsDir: {
114
127
  label: 'Plugins folder',
115
128
  help: 'The top-level folder that holds plugins. The three folder names must differ.',
116
129
  placeholder: 'Plugins',
117
- advanced: true,
130
+ },
131
+ // Beside the folders, and not under Advanced, for the same reason they are
132
+ // not: a repository that already has an `AGENTS.md` of its own loses it to
133
+ // the platform's on the first boot unless this is answered first.
134
+ agentsFile: {
135
+ label: 'Agent guide file',
136
+ help: 'The file the platform writes its own guide to, at the top of the repository. Change it if your repository already has an AGENTS.md you want to keep — that file then stays yours, and the platform never writes to it. Must end in .md.',
137
+ placeholder: 'AGENTS.md',
118
138
  },
119
139
  defaultBranch: {
120
140
  label: 'Main branch',
@@ -179,6 +199,50 @@ const REQUIRED_KEYS = ['kbRepoUrl', 'gitToken', 'defaultBranch', 'protectedBranc
179
199
  */
180
200
  const CONNECTION_KEYS = ['kbRepoUrl', 'gitToken', 'gitUsername'];
181
201
 
202
+ /**
203
+ * The answers the sign-in check proves. Editing one invalidates its result on
204
+ * screen; the scopes, the button text and the allowed domains are not among
205
+ * them, and the server never re-checks a save that changes only those.
206
+ */
207
+ const OIDC_KEYS = ['oidcIssuerUrl', 'oidcClientId', 'oidcClientSecret'];
208
+
209
+ /** How the configuration in effect is labelled, in both variants. */
210
+ const OIDC_VERIFICATION_LABEL: Record<OidcVerification, string> = {
211
+ verified: 'Verified',
212
+ unverified: 'Unverified — sign in once to confirm',
213
+ 'not-configured': 'Not configured',
214
+ unrecordable: 'Not recorded — set SECRETS_ENC_KEY to keep verification',
215
+ };
216
+
217
+ /** The three root folder fields, checked against the repository's listing. */
218
+ const ROOT_FOLDER_KEYS = ['knowledgeBaseDir', 'skillsDir', 'pluginsDir'] as const;
219
+ const isRootFolderKey = (key: string): key is (typeof ROOT_FOLDER_KEYS)[number] =>
220
+ (ROOT_FOLDER_KEYS as readonly string[]).includes(key);
221
+
222
+ /**
223
+ * The knowledge-base LAYOUT fields — the three folders and the agent guide's
224
+ * file name — which render together, under the connection test whose listing
225
+ * the folders are checked against, rather than with the connection fields
226
+ * above it.
227
+ */
228
+ const LAYOUT_KEYS: readonly (keyof KbLayout)[] = [...ROOT_FOLDER_KEYS, 'agentsFile'];
229
+ const isLayoutKey = (key: string): boolean => (LAYOUT_KEYS as readonly string[]).includes(key);
230
+
231
+ /**
232
+ * The consent that rides along with a renamed guide: keep the platform's
233
+ * one-sentence pointer in the customer's own `AGENTS.md`. Not a text field, so
234
+ * it has no {@link FIELDS} entry and is drawn by hand under the name it
235
+ * belongs to.
236
+ */
237
+ const AGENTS_LINK_KEY = 'agentsFileLink';
238
+
239
+ /** How a near-miss folder differs from the configured name, as the warning words it. */
240
+ const VARIANT_DIFFERENCE: Record<Extract<RootFolderState, { kind: 'variant' }>['difference'], string> = {
241
+ case: 'differs only by case',
242
+ 'trailing-s': 'differs only by a trailing s',
243
+ 'case-and-trailing-s': 'differs by case and a trailing s',
244
+ };
245
+
182
246
  /** The blocks, in the order they are worked through. */
183
247
  const SECTIONS: { id: SettingStatus['section']; title: string; blurb: string }[] = [
184
248
  {
@@ -197,7 +261,16 @@ const SECTIONS: { id: SettingStatus['section']; title: string; blurb: string }[]
197
261
 
198
262
  interface Props {
199
263
  settings: SettingStatus[];
200
- /** Re-read the status after a save, so the gate can let the app through. */
264
+ /**
265
+ * Re-read the status after a save, so the gate can let the app through.
266
+ *
267
+ * The host must let only its LATEST read land (`SetupGate` and
268
+ * `DeploymentPage` both read through `useSetupStatus`, which does): each
269
+ * fresh `kbInit` replaces the failure on
270
+ * screen, so an earlier read answering late — the refresh after a failed
271
+ * save, landing after a retry that succeeded — would otherwise put the
272
+ * cleared failure back.
273
+ */
201
274
  onSaved(): void;
202
275
  /**
203
276
  * Where the screen is standing. `setup` (the default) is the first-run
@@ -213,6 +286,14 @@ interface Props {
213
286
  * calls, and what the last call did. Absent on a build without the module.
214
287
  */
215
288
  sync?: SyncStatus;
289
+ /**
290
+ * A standing knowledge-base initialization failure, from the status
291
+ * endpoint — so the banner is there when the screen is opened, not only
292
+ * right after the save that failed.
293
+ */
294
+ kbInit?: KbInitFailure;
295
+ /** Whether the single sign-on configuration in effect is proven. Absent from an older server. */
296
+ oidcVerification?: OidcVerification;
216
297
  }
217
298
 
218
299
  /**
@@ -231,8 +312,43 @@ interface Props {
231
312
  * silently outranking the infrastructure config someone is reviewing in a
232
313
  * repo, which is the same rule the server enforces.
233
314
  */
234
- export function SetupScreen({ settings, onSaved, variant = 'setup', sync }: Props) {
315
+ /** Two reports of the same initialization failure (a status read builds a new object each time). */
316
+ function sameFailure(a: KbInitFailure, b: KbInitFailure): boolean {
317
+ return a.kind === b.kind && a.cause === b.cause;
318
+ }
319
+
320
+ export function SetupScreen({ settings, onSaved, variant = 'setup', sync, kbInit, oidcVerification }: Props) {
235
321
  const [draft, setDraft] = useState<Record<string, string>>({});
322
+ /**
323
+ * The initialization failure on screen: the status endpoint's, until a save
324
+ * or a retry from this screen answers more recently. A fresh status read
325
+ * (a new `kbInit` from the host) takes over again — adjusted during render
326
+ * rather than in an effect, so the stale banner never paints. That a fresh
327
+ * prop really is the latest read is the host's promise (see `onSaved`), and
328
+ * each retry or save that clears the failure here also asks for that read.
329
+ */
330
+ const [initFailure, setInitFailure] = useState<KbInitFailure | null>(kbInit ?? null);
331
+ const [seenKbInit, setSeenKbInit] = useState(kbInit);
332
+ /**
333
+ * The failure a save or retry from THIS screen has just seen cleared, until a
334
+ * status read agrees. A read that went out before the retry — the refresh
335
+ * after the failed save — can still answer after it, reporting that same
336
+ * failure as standing; this screen knows better, so the stale copy is not
337
+ * shown. The guard lifts on the first read without a failure, and never
338
+ * hides a DIFFERENT failure: that is news, whenever it arrives.
339
+ */
340
+ const [clearedFailure, setClearedFailure] = useState<KbInitFailure | null>(null);
341
+ if (kbInit !== seenKbInit) {
342
+ setSeenKbInit(kbInit);
343
+ if (!kbInit) {
344
+ setClearedFailure(null);
345
+ setInitFailure(null);
346
+ } else if (!(clearedFailure && sameFailure(kbInit, clearedFailure))) {
347
+ setClearedFailure(null);
348
+ setInitFailure(kbInit);
349
+ }
350
+ }
351
+ const [retrying, setRetrying] = useState(false);
236
352
  const [syncing, setSyncing] = useState(false);
237
353
  /** What the last "Sync now" from THIS page came back with (a failure to ask is `error`). */
238
354
  const [syncResult, setSyncResult] = useState<SyncNowResult | null>(null);
@@ -255,6 +371,25 @@ export function SetupScreen({ settings, onSaved, variant = 'setup', sync }: Prop
255
371
  * shown as if it were about the new ones.
256
372
  */
257
373
  const connectionEpoch = useRef(0);
374
+ const [oidcTest, setOidcTest] = useState<OidcTest | null>(null);
375
+ const [oidcTesting, setOidcTesting] = useState(false);
376
+ /** The same staleness guard as {@link connectionEpoch}, for the sign-in answers. */
377
+ const oidcEpoch = useRef(0);
378
+ /**
379
+ * A verification state newer than the one the host last passed in — what a
380
+ * save or a test just answered. Dropped for good the moment the host passes
381
+ * in anything new (its own refresh supersedes it, even one that comes back
382
+ * to the value it replaced) and when a sign-in field is edited.
383
+ */
384
+ const [latest, setLatest] = useState<OidcVerification | null>(null);
385
+ const [hostVerification, setHostVerification] = useState(oidcVerification);
386
+ if (hostVerification !== oidcVerification) {
387
+ // Adjusting state to a changed prop during render, rather than in an
388
+ // effect: React re-renders at once, before anything stale is painted.
389
+ setHostVerification(oidcVerification);
390
+ setLatest(null);
391
+ }
392
+ const verification = latest ?? oidcVerification;
258
393
 
259
394
  /**
260
395
  * What a field would save as, given a set of typed answers: what is in them,
@@ -283,6 +418,25 @@ export function SetupScreen({ settings, onSaved, variant = 'setup', sync }: Prop
283
418
  return typed !== (settings.find((s) => s.key === key)?.value ?? '').trim();
284
419
  };
285
420
 
421
+ /**
422
+ * Something typed that a save would actually store. The retry sends an EMPTY
423
+ * save — pressed now, it would re-run against the stored values while a
424
+ * corrected token sits unsaved in the form — so it waits, and Save (which
425
+ * retries too) is the way to try with the new values. Judged like the
426
+ * connection gate above — an edit put back changes nothing — and a token
427
+ * username that is just what an address answers (the one typed, or the one
428
+ * stored) is not an edit of its own: typing the address fills it in, and once
429
+ * the address is put back or cleared, nothing the admin did is left unsaved.
430
+ */
431
+ const answeredUsernames = [draft.kbRepoUrl, settings.find((s) => s.key === 'kbRepoUrl')?.value].map(
432
+ (address) => (address ? tokenUsernameForHost(address)?.username : undefined),
433
+ );
434
+ const draftChanged = Object.keys(draft).some(
435
+ (key) =>
436
+ !(key === 'gitUsername' && answeredUsernames.includes(draft.gitUsername)) &&
437
+ connectionKeyChanged(key),
438
+ );
439
+
286
440
  /**
287
441
  * Whether THIS save has to stand behind the repository connection.
288
442
  *
@@ -311,6 +465,8 @@ export function SetupScreen({ settings, onSaved, variant = 'setup', sync }: Prop
311
465
  * reader has already changed.
312
466
  */
313
467
  const connectionRejected = mustProveConnection && test?.ok === false;
468
+ /** Of those, the host let the token read but not write — a different fix. */
469
+ const connectionReadOnly = connectionRejected && test?.outcome === 'read-only';
314
470
 
315
471
  function set(key: string, value: string) {
316
472
  setDraft((d) => {
@@ -333,6 +489,12 @@ export function SetupScreen({ settings, onSaved, variant = 'setup', sync }: Prop
333
489
  delete next[key];
334
490
  return next;
335
491
  });
492
+ if (OIDC_KEYS.includes(key)) {
493
+ oidcEpoch.current++;
494
+ setOidcTest(null);
495
+ // A test's "Verified" was about the values before this edit.
496
+ setLatest(null);
497
+ }
336
498
  if (CONNECTION_KEYS.includes(key)) {
337
499
  // Any in-flight test is now asking about values that are gone; the epoch
338
500
  // bump makes its answer land as stale rather than as evidence.
@@ -433,6 +595,94 @@ export function SetupScreen({ settings, onSaved, variant = 'setup', sync }: Prop
433
595
  }
434
596
  }
435
597
 
598
+ /**
599
+ * "Test sign-in configuration": the check a save runs, on the values typed
600
+ * (the server falls back to those in effect). Nothing is saved.
601
+ */
602
+ async function runOidcTest() {
603
+ setOidcTesting(true);
604
+ setError(null);
605
+ const epoch = oidcEpoch.current;
606
+ const fields = Object.fromEntries(Object.entries(draft).filter(([key]) => OIDC_KEYS.includes(key)));
607
+ try {
608
+ const result = await testOidc(fields);
609
+ if (epoch !== oidcEpoch.current) return;
610
+ setOidcTest(result);
611
+ if (result.oidcVerification) setLatest(result.oidcVerification);
612
+ } catch (err) {
613
+ if (epoch === oidcEpoch.current) {
614
+ setOidcTest({ ok: false, error: err instanceof Error ? err.message : 'Could not test the sign-in configuration.' });
615
+ }
616
+ } finally {
617
+ setOidcTesting(false);
618
+ }
619
+ }
620
+
621
+ /** What a sign-in test came back with, in words. */
622
+ function describeOidcTest(result: OidcTest): string {
623
+ switch (result.outcome) {
624
+ case 'verified':
625
+ return 'Verified. The provider accepted the application ID and secret.';
626
+ case 'issuer-verified':
627
+ return 'The provider address is a sign-in provider. Enter the application ID and secret to check them too.';
628
+ default:
629
+ return result.error ?? 'The sign-in configuration could not be checked.';
630
+ }
631
+ }
632
+
633
+ /**
634
+ * The test button, its answer and the verification label: beside the
635
+ * provider fields, or on its own when every one of them is set by the
636
+ * environment.
637
+ */
638
+ function renderOidcPanel() {
639
+ return (
640
+ <Surface tone="sunken" radius="md" className="p-4">
641
+ {verification && (
642
+ <p className="mb-3 text-detail text-ink-muted">
643
+ Status:{' '}
644
+ <span
645
+ data-testid="oidc-verification"
646
+ className={`font-medium ${
647
+ verification === 'verified'
648
+ ? 'text-ok'
649
+ : verification === 'unverified'
650
+ ? 'text-wait'
651
+ : 'text-ink-faint'
652
+ }`}
653
+ >
654
+ {OIDC_VERIFICATION_LABEL[verification]}
655
+ </span>
656
+ </p>
657
+ )}
658
+ <div className="flex flex-wrap items-center gap-3">
659
+ <Button
660
+ type="button"
661
+ variant="outline"
662
+ size="sm"
663
+ onClick={() => void runOidcTest()}
664
+ disabled={oidcTesting || saving}
665
+ >
666
+ {oidcTesting ? 'Checking…' : 'Test sign-in configuration'}
667
+ </Button>
668
+ <span className="text-meta text-ink-faint">
669
+ Checks the provider address, then the application ID and secret, with the provider.
670
+ </span>
671
+ </div>
672
+ {oidcTest && (
673
+ <p
674
+ role="status"
675
+ className={`mt-3 text-detail ${
676
+ oidcTest.ok ? 'text-ok' : oidcTest.outcome === 'unverified' ? 'text-wait' : 'text-danger'
677
+ }`}
678
+ >
679
+ {describeOidcTest(oidcTest)}
680
+ </p>
681
+ )}
682
+ </Surface>
683
+ );
684
+ }
685
+
436
686
  async function runSync() {
437
687
  setSyncing(true);
438
688
  setSyncResult(null);
@@ -515,9 +765,48 @@ export function SetupScreen({ settings, onSaved, variant = 'setup', sync }: Prop
515
765
  );
516
766
  }
517
767
 
768
+ /**
769
+ * Re-run the knowledge-base initialization. No endpoint of its own: any save
770
+ * while the failure stands re-runs the phase, and an EMPTY one changes no
771
+ * setting — so nothing has to be typed again, and the server's one-save-at-a-
772
+ * time chain covers this exactly as it covers the form.
773
+ */
774
+ async function retryInitialization() {
775
+ if (retrying || saving || draftChanged) return;
776
+ setRetrying(true);
777
+ setError(null);
778
+ try {
779
+ const result = await saveSettings({});
780
+ setClearedFailure(initFailure);
781
+ setInitFailure(null);
782
+ if (result.awaitingRestart) {
783
+ setNeedsRestart(true);
784
+ // As after a save: the settings page still wants fresh status, or its
785
+ // host keeps the failure this retry just cleared.
786
+ if (variant === 'settings') onSaved();
787
+ return;
788
+ }
789
+ if (result.complete && variant === 'setup') {
790
+ // The same full reload the completing save does, for the same reason:
791
+ // the browser's branch model predates the app it is about to open.
792
+ window.location.reload();
793
+ return;
794
+ }
795
+ onSaved();
796
+ } catch (err) {
797
+ if (err instanceof KbInitFailed) {
798
+ setClearedFailure(null);
799
+ setInitFailure(err.kbInit);
800
+ } else setError(err instanceof Error ? err.message : 'Could not retry the initialization.');
801
+ } finally {
802
+ setRetrying(false);
803
+ }
804
+ }
805
+
518
806
  async function submit(e: FormEvent) {
519
807
  e.preventDefault();
520
- if (saving) return;
808
+ // A save during a sign-in check would clear the draft the check is about.
809
+ if (saving || retrying || oidcTesting) return;
521
810
  setSaving(true);
522
811
  setError(null);
523
812
  setProblems({});
@@ -554,11 +843,15 @@ export function SetupScreen({ settings, onSaved, variant = 'setup', sync }: Prop
554
843
  setTesting(true);
555
844
  await probe();
556
845
  setTesting(false);
846
+ // Includes a probe the server REFUSED (a 4xx comes back as a
847
+ // rejection, not a throw) — that is an answer about these values.
557
848
  if (proven && !proven.ok) {
558
849
  setError(
559
- variant === 'setup'
560
- ? 'Not saved. Nothing behind this screen works until the repository answers, and it did not — fix the connection above and test it again.'
561
- : 'Not saved. The repository did not answer with those details — fix the connection above and test it again.',
850
+ proven.outcome === 'read-only'
851
+ ? 'Not saved. The token can read the repository but cannot write to it — grant it write access and test again.'
852
+ : variant === 'setup'
853
+ ? 'Not saved. Nothing behind this screen works until the repository answers, and it did not — fix the connection above and test it again.'
854
+ : 'Not saved. The repository did not answer with those details — fix the connection above and test it again.',
562
855
  );
563
856
  return;
564
857
  }
@@ -571,13 +864,19 @@ export function SetupScreen({ settings, onSaved, variant = 'setup', sync }: Prop
571
864
  // above fills the same fields from the same answer.
572
865
  if (
573
866
  !probed &&
867
+ // No address, nothing to look a branch up in.
868
+ !!resolvedIn(payload, 'kbRepoUrl') &&
574
869
  (!resolvedIn(payload, 'defaultBranch') || !resolvedIn(payload, 'protectedBranches'))
575
870
  ) {
576
871
  await probe();
577
872
  }
578
873
  const result = await saveSettings(payload);
874
+ // A save while a failure stands re-ran the initialization, and it held.
875
+ setClearedFailure(initFailure);
876
+ setInitFailure(null);
579
877
  setRestartRequired(result.restartRequired);
580
878
  setDraft({});
879
+ if (result.oidcVerification) setLatest(result.oidcVerification);
581
880
  // A save can succeed and STILL leave the deployment unusable: a blank
582
881
  // field means "leave it alone", not "this is wrong", so the server
583
882
  // accepts a batch that answers only some of what it needs. Saying so is
@@ -611,8 +910,24 @@ export function SetupScreen({ settings, onSaved, variant = 'setup', sync }: Prop
611
910
  }
612
911
  onSaved();
613
912
  } catch (err) {
614
- if (err instanceof SettingsProblems) setProblems(err.problems);
615
- else setError(err instanceof Error ? err.message : 'Could not save these settings.');
913
+ if (err instanceof SettingsProblems) {
914
+ setProblems(err.problems);
915
+ // A problem about a field this form does not render — the server's
916
+ // connection check blaming a token the environment supplies, say —
917
+ // would otherwise vanish, leaving a save that failed silently.
918
+ const unshown = Object.entries(err.problems).filter(
919
+ ([key]) => !editable.some((s) => s.key === key),
920
+ );
921
+ if (unshown.length > 0) setError(unshown.map(([, message]) => message).join(' '));
922
+ } else if (err instanceof KbInitFailed) {
923
+ // The values ARE stored — only the initialization failed. The form
924
+ // shows what was saved, and the banner says what to fix and retries
925
+ // without asking for any of it again.
926
+ setClearedFailure(null);
927
+ setInitFailure(err.kbInit);
928
+ setDraft({});
929
+ onSaved();
930
+ } else setError(err instanceof Error ? err.message : 'Could not save these settings.');
616
931
  } finally {
617
932
  setSaving(false);
618
933
  // The page scrolls now, and every message lands at the top of it while
@@ -631,11 +946,93 @@ export function SetupScreen({ settings, onSaved, variant = 'setup', sync }: Prop
631
946
  */
632
947
  const remoteBranches = test?.ok ? (test.branches ?? []) : [];
633
948
 
949
+ /**
950
+ * The top-level folders the connection test found, or null when there is
951
+ * nothing to judge the root fields against: no test yet, a failed one, a
952
+ * listing that did not come back — or an EMPTY repository, whose one message
953
+ * already says everything will be set up, and three "will be created" notes
954
+ * beneath it would only repeat that.
955
+ */
956
+ const remoteRootFolders =
957
+ test?.ok && !test.empty && Array.isArray(test.rootFolders) ? test.rootFolders : null;
958
+
959
+ /**
960
+ * What the repository holds for one root field, as it would save now. Judged
961
+ * live against the listing — the listing describes the repository, not the
962
+ * field, so correcting the name to the one suggested says "found" at once.
963
+ * Never a problem that blocks the save: an admin may mean to create the
964
+ * folder, or to rename the old one later.
965
+ */
966
+ function renderRootFolderState(key: keyof KbLayout) {
967
+ if (!remoteRootFolders) return null;
968
+ const name = resolved(key) || DEFAULT_KB_LAYOUT[key];
969
+ const state = rootFolderState(name, remoteRootFolders);
970
+ const folder = (value: string) => <code className="font-mono">{value}</code>;
971
+ return (
972
+ <p id={`${key}-repo-state`} className={`mt-1 text-meta ${state.kind === 'variant' ? 'text-wait' : 'text-ok'}`}>
973
+ {state.kind === 'found' && <>{folder(name)} found in the repository.</>}
974
+ {state.kind === 'missing' && (
975
+ <>{folder(name)} is not in the repository yet — it will be created.</>
976
+ )}
977
+ {state.kind === 'variant' && (
978
+ <>
979
+ Not found — the repository has {folder(state.candidate)} (
980
+ {VARIANT_DIFFERENCE[state.difference]}): set
981
+ this field to {folder(state.candidate)} or rename the folder.
982
+ </>
983
+ )}
984
+ </p>
985
+ );
986
+ }
987
+
988
+ /**
989
+ * Under the guide's name, once it is no longer `AGENTS.md`: the exact
990
+ * sentence the platform would add to the customer's own `AGENTS.md`, and the
991
+ * consent to keep it there.
992
+ *
993
+ * Shown ONLY while the name differs, because that is the only time there is
994
+ * anything to point at — under the default name the guide IS `AGENTS.md`.
995
+ * The sentence is rendered by the same helper the server appends with, so
996
+ * what the admin reads here is what lands in their file, character for
997
+ * character.
998
+ */
999
+ function renderAgentsFileLink() {
1000
+ const name = resolved('agentsFile') || DEFAULT_KB_LAYOUT.agentsFile;
1001
+ if (name === DEFAULT_KB_LAYOUT.agentsFile) return null;
1002
+ // Unset means on: the server reads an unanswered setting the same way.
1003
+ const on = (draft[AGENTS_LINK_KEY] ?? settings.find((s) => s.key === AGENTS_LINK_KEY)?.value ?? 'true') !== 'false';
1004
+ return (
1005
+ <div className="mt-2 space-y-2" data-testid="agents-file-link">
1006
+ <label className="flex cursor-pointer select-none items-start gap-2 text-detail text-ink">
1007
+ <input
1008
+ type="checkbox"
1009
+ className="mt-0.5"
1010
+ checked={on}
1011
+ onChange={(e) => set(AGENTS_LINK_KEY, e.target.checked ? 'true' : 'false')}
1012
+ />
1013
+ <span>Keep a pointer to {name} in your own AGENTS.md</span>
1014
+ </label>
1015
+ <CopyValue value={agentsFilePointerSentence(name)} label="Copy the pointer sentence" />
1016
+ <p className="text-meta text-ink-faint">
1017
+ While this is ticked, every start looks for “{name}” in your AGENTS.md and adds the
1018
+ sentence at the end when it is not there — in your own words counts too. Nothing is added
1019
+ if you have no AGENTS.md, and no file is ever created for it. Untick it to stop.
1020
+ </p>
1021
+ </div>
1022
+ );
1023
+ }
1024
+
634
1025
  function renderField(setting: SettingStatus) {
635
1026
  const copy = FIELDS[setting.key];
636
1027
  if (!copy) return null;
637
1028
  const isBranchField = setting.key === 'defaultBranch' || setting.key === 'protectedBranches';
638
- const listId = isBranchField && remoteBranches.length > 0 ? `${setting.key}-options` : undefined;
1029
+ const isFolderField = isRootFolderKey(setting.key);
1030
+ const suggestions = isBranchField
1031
+ ? remoteBranches
1032
+ : isFolderField
1033
+ ? (remoteRootFolders ?? []).filter(isRootFolderSuggestion)
1034
+ : [];
1035
+ const listId = suggestions.length > 0 ? `${setting.key}-options` : undefined;
639
1036
  return (
640
1037
  <div key={setting.key}>
641
1038
  <label className="block space-y-1.5">
@@ -657,12 +1054,14 @@ export function SetupScreen({ settings, onSaved, variant = 'setup', sync }: Prop
657
1054
  </label>
658
1055
  {listId && (
659
1056
  <datalist id={listId}>
660
- {remoteBranches.map((b) => (
1057
+ {suggestions.map((b) => (
661
1058
  <option key={b} value={b} />
662
1059
  ))}
663
1060
  </datalist>
664
1061
  )}
665
1062
  <p className="mt-1 text-meta text-ink-faint">{copy.help}</p>
1063
+ {isRootFolderKey(setting.key) && renderRootFolderState(setting.key)}
1064
+ {setting.key === 'agentsFile' && renderAgentsFileLink()}
666
1065
  {setting.key === 'kbSyncSecret' && renderSyncPanel()}
667
1066
  {/* Only AFTER setup: on first run there is nothing yet to lose, so
668
1067
  the caution would be noise. Once a deployment is live, this field
@@ -705,6 +1104,31 @@ export function SetupScreen({ settings, onSaved, variant = 'setup', sync }: Prop
705
1104
  )}
706
1105
 
707
1106
  <div ref={noticeRef}>
1107
+ {/* Saved, but the knowledge base behind the gate was never set up.
1108
+ The cause is the server's classified sentence — what to fix, not
1109
+ what git said — and the retry needs nothing re-entered. */}
1110
+ {initFailure && (
1111
+ <Banner tone="danger" role="alert" className="mt-6" data-testid="kb-init-failure">
1112
+ <p className="font-semibold">Saved, but the knowledge base could not be initialized</p>
1113
+ <p className="mt-1">{initFailure.cause}</p>
1114
+ {draftChanged && (
1115
+ <p className="mt-1">
1116
+ The form has unsaved changes — saving them retries the initialization with them.
1117
+ </p>
1118
+ )}
1119
+ <Button
1120
+ type="button"
1121
+ variant="outline"
1122
+ size="sm"
1123
+ className="mt-3"
1124
+ onClick={() => void retryInitialization()}
1125
+ disabled={retrying || saving || testing || draftChanged}
1126
+ >
1127
+ {retrying ? 'Initializing…' : 'Retry initialization'}
1128
+ </Button>
1129
+ </Banner>
1130
+ )}
1131
+
708
1132
  {error && (
709
1133
  <Banner tone="danger" role="alert" className="mt-6">
710
1134
  {error}
@@ -741,7 +1165,10 @@ export function SetupScreen({ settings, onSaved, variant = 'setup', sync }: Prop
741
1165
  </Banner>
742
1166
  )}
743
1167
 
744
- <form onSubmit={submit} className="mt-8 space-y-10">
1168
+ {/* Named so its submit button can sit outside it, below the
1169
+ Marketplace section: the button is the last thing on the page, but
1170
+ Marketplace is deliberately not part of this form (see below). */}
1171
+ <form id="setup-settings-form" onSubmit={submit} className="mt-8 space-y-10">
745
1172
  {SECTIONS.map((section) => {
746
1173
  const fields = editable.filter((s) => s.section === section.id);
747
1174
  // A section whose every field comes from the environment has
@@ -776,7 +1203,21 @@ export function SetupScreen({ settings, onSaved, variant = 'setup', sync }: Prop
776
1203
  </p>
777
1204
  )}
778
1205
  </div>
779
- {fields.filter((f) => !FIELDS[f.key]?.advanced).map((f) => renderField(f))}
1206
+ {fields
1207
+ .filter(
1208
+ (f) =>
1209
+ !FIELDS[f.key]?.advanced &&
1210
+ !isLayoutKey(f.key) &&
1211
+ (section.id !== 'sign-in' || OIDC_KEYS.includes(f.key)),
1212
+ )
1213
+ .map((f) => renderField(f))}
1214
+
1215
+ {/* Directly under the three answers it proves. */}
1216
+ {section.id === 'sign-in' && renderOidcPanel()}
1217
+ {section.id === 'sign-in' &&
1218
+ fields
1219
+ .filter((f) => !FIELDS[f.key]?.advanced && !OIDC_KEYS.includes(f.key))
1220
+ .map((f) => renderField(f))}
780
1221
 
781
1222
  {/* Immediately under the two fields it proves, and above the
782
1223
  Advanced block it fills in — the middle of the sequence
@@ -795,13 +1236,13 @@ export function SetupScreen({ settings, onSaved, variant = 'setup', sync }: Prop
795
1236
  // Also while SAVING: a save may be asking the remote
796
1237
  // itself, and a second test racing it would overwrite
797
1238
  // both the result and the versions derived from it.
798
- disabled={testing || saving}
1239
+ disabled={testing || saving || retrying}
799
1240
  >
800
1241
  {testing ? 'Checking…' : 'Test connection'}
801
1242
  </Button>
802
1243
  <span className="text-meta text-ink-faint">
803
- Checks the address and token against the host, and fills in the versions
804
- below.
1244
+ Checks the address and token against the host, looks for the folders below,
1245
+ and fills in the versions.
805
1246
  </span>
806
1247
  </div>
807
1248
  {test && (
@@ -821,6 +1262,13 @@ export function SetupScreen({ settings, onSaved, variant = 'setup', sync }: Prop
821
1262
  </Surface>
822
1263
  )}
823
1264
 
1265
+ {/* The layout: the three root folders and the agent guide's
1266
+ file name, in the main section, directly under the test
1267
+ whose listing the folders are checked against — the
1268
+ connection fields above it stay next to the button that
1269
+ proves them. */}
1270
+ {fields.filter((f) => isLayoutKey(f.key)).map((f) => renderField(f))}
1271
+
824
1272
  {/* Everything a normal setup never touches, out of the way but
825
1273
  not hidden: a self-hosted git server does need the token
826
1274
  username, and a provider with unusual scopes does need
@@ -882,33 +1330,63 @@ export function SetupScreen({ settings, onSaved, variant = 'setup', sync }: Prop
882
1330
  </Surface>
883
1331
  )}
884
1332
 
885
- {/* A rejected connection stops here rather than at the far side of
886
- it. Saving these answers would finish setup — the server checks
887
- that they are present, not that they work — and open the app onto
888
- a repository it cannot reach, which reads as a broken product
889
- rather than a wrong token. */}
890
- <div className="flex flex-wrap items-center gap-3">
891
- <Button
892
- type="submit"
893
- variant="primary"
894
- disabled={saving || testing || connectionRejected}
895
- // Described by the refusal, so a reader who lands on a button
896
- // that will not move is told why rather than left guessing.
897
- aria-describedby={connectionRejected ? 'connection-refusal' : undefined}
898
- >
899
- {saving ? 'Saving…' : 'Save and continue'}
900
- </Button>
901
- {connectionRejected && (
902
- // Not a live region: the test panel above already announced the
903
- // host's own words, and the save banner announces a blocked
904
- // attempt. This is the label for a button that will not move.
905
- <span id="connection-refusal" className="text-meta text-danger">
906
- The repository turned that connection down. Fix it above and test again.
907
- </span>
1333
+ {/* Every sign-in setting from the environment: the section above
1334
+ does not render, but whether that configuration works is still
1335
+ the admin's to see and to test. */}
1336
+ {editable.every((s) => s.section !== 'sign-in') &&
1337
+ verification &&
1338
+ verification !== 'not-configured' && (
1339
+ <Surface as="section" tone="surface" radius="lg" elevation="card" className="p-6 space-y-4">
1340
+ <h2 className="text-title font-semibold text-ink">Single sign-on</h2>
1341
+ {renderOidcPanel()}
1342
+ </Surface>
908
1343
  )}
909
- </div>
910
1344
  </form>
911
1345
 
1346
+ {/* Outside the form: nothing in it is saved by "Save and continue",
1347
+ and on first run it is optional — the gate never waits on it. The
1348
+ same section in both variants, so first run and Deployment
1349
+ settings cannot drift. */}
1350
+ <MarketplaceSection variant={variant} />
1351
+
1352
+ {/* The submit button lives HERE, after Marketplace, though it belongs
1353
+ to the form above — `form=` is what lets those two facts hold at
1354
+ once. It is the last thing on the page because a reader should
1355
+ meet every section, Marketplace included, before the control that
1356
+ leaves the screen; when it sat above Marketplace, the page looked
1357
+ finished while a section was still below it.
1358
+
1359
+ A rejected connection stops here rather than at the far side of
1360
+ it. Saving these answers would finish setup — the server checks
1361
+ that they are present, not that they work — and open the app onto
1362
+ a repository it cannot reach, which reads as a broken product
1363
+ rather than a wrong token. */}
1364
+ <div className="mt-10 flex flex-wrap items-center justify-end gap-3">
1365
+ {connectionRejected && (
1366
+ // Before the button in the DOM so the reason is read first, and
1367
+ // so `justify-end` leaves the button itself at the right edge.
1368
+ // Not a live region: the test panel above already announced the
1369
+ // host's own words, and the save banner announces a blocked
1370
+ // attempt. This is the label for a button that will not move.
1371
+ <span id="connection-refusal" className="text-meta text-danger">
1372
+ {connectionReadOnly
1373
+ ? 'That token can read the repository but cannot write to it. Grant write access and test again.'
1374
+ : 'The repository turned that connection down. Fix it above and test again.'}
1375
+ </span>
1376
+ )}
1377
+ <Button
1378
+ type="submit"
1379
+ form="setup-settings-form"
1380
+ variant="primary"
1381
+ disabled={saving || testing || retrying || oidcTesting || connectionRejected}
1382
+ // Described by the refusal, so a reader who lands on a button
1383
+ // that will not move is told why rather than left guessing.
1384
+ aria-describedby={connectionRejected ? 'connection-refusal' : undefined}
1385
+ >
1386
+ {saving ? 'Saving…' : 'Save and continue'}
1387
+ </Button>
1388
+ </div>
1389
+
912
1390
  {fromEnv.length > 0 && (
913
1391
  <Surface tone="sunken" radius="md" className="mt-10 p-4">
914
1392
  <h2 className="text-label font-semibold uppercase text-ink-faint">