@bevel-software/platform-core-frontend 0.4.1 → 0.5.1

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 (327) hide show
  1. package/THIRD-PARTY-NOTICES.md +5366 -0
  2. package/package.json +7 -4
  3. package/src/core/CoreAppShell.tsx +195 -56
  4. package/src/core/__tests__/AppChrome.test.tsx +125 -0
  5. package/src/core/__tests__/ShellRoutes.test.tsx +37 -2
  6. package/src/core/__tests__/bootstrap.test.ts +63 -0
  7. package/src/core/bootstrap.ts +73 -0
  8. package/src/core/events.ts +12 -0
  9. package/src/core/registry.ts +58 -9
  10. package/src/index.css +100 -11
  11. package/src/index.ts +24 -23
  12. package/src/lib/utils.ts +93 -117
  13. package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +281 -0
  14. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +166 -1
  15. package/src/modules/access/api.ts +49 -0
  16. package/src/modules/access/components/ManageAccessDialog.tsx +786 -481
  17. package/src/modules/access/hooks/useFileAccess.ts +1 -1
  18. package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +86 -0
  19. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +17 -1
  20. package/src/modules/admin/__tests__/admin.unread.test.tsx +61 -0
  21. package/src/modules/admin/components/AdminRolesPage.tsx +44 -38
  22. package/src/modules/admin/components/RolesCorruptedBanner.tsx +11 -10
  23. package/src/modules/admin/components/UserAccountsPage.tsx +36 -28
  24. package/src/modules/admin/state/admin.context.tsx +15 -6
  25. package/src/modules/auth/components/AccountPage.tsx +11 -11
  26. package/src/modules/auth/components/LoginScreen.tsx +12 -12
  27. package/src/modules/auth/services/sso.ts +47 -1
  28. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +277 -0
  29. package/src/modules/change-requests/__tests__/author.test.ts +48 -0
  30. package/src/modules/change-requests/__tests__/conflict.test.ts +73 -0
  31. package/src/modules/change-requests/__tests__/diff.test.ts +134 -0
  32. package/src/modules/change-requests/__tests__/propose.test.ts +93 -0
  33. package/src/modules/change-requests/__tests__/useFileOnBranch.test.tsx +72 -0
  34. package/src/modules/change-requests/change-requests.css +22 -0
  35. package/src/modules/change-requests/components/ChangeBox.tsx +277 -0
  36. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +713 -0
  37. package/src/modules/change-requests/components/ConflictHelp.tsx +47 -0
  38. package/src/modules/change-requests/components/CrFileTree.tsx +398 -0
  39. package/src/modules/change-requests/components/FileChangeBoxes.tsx +168 -0
  40. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +236 -0
  41. package/src/modules/change-requests/hooks/useCrFileDiffs.ts +79 -0
  42. package/src/modules/change-requests/hooks/useFileOnBranch.ts +80 -0
  43. package/src/modules/change-requests/services/change-requests.api.ts +45 -0
  44. package/src/modules/change-requests/services/propose.api.ts +162 -0
  45. package/src/modules/change-requests/utils/author.ts +47 -0
  46. package/src/modules/change-requests/utils/conflict.ts +38 -0
  47. package/src/modules/change-requests/utils/diff.ts +80 -0
  48. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +27 -18
  49. package/src/modules/git/__tests__/FileHistoryPanel.test.tsx +36 -83
  50. package/src/modules/git/__tests__/PullNeededBanner.test.tsx +5 -5
  51. package/src/modules/git/__tests__/PullRequestsForMe.test.tsx +147 -0
  52. package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +2 -8
  53. package/src/modules/git/components/BranchSwitcher.tsx +68 -31
  54. package/src/modules/git/components/DiffView.tsx +4 -4
  55. package/src/modules/git/components/FileComparisonPanel.tsx +20 -20
  56. package/src/modules/git/components/FileHistoryPanel.tsx +71 -107
  57. package/src/modules/git/components/PullNeededBanner.tsx +6 -13
  58. package/src/modules/git/components/PullRequestsForMe.tsx +71 -36
  59. package/src/modules/git/components/UnifiedDiffView.tsx +4 -4
  60. package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +2 -2
  61. package/src/modules/git/hooks/useGitState.ts +15 -14
  62. package/src/modules/git/services/__tests__/error-messages.test.ts +4 -4
  63. package/src/modules/git/services/error-messages.ts +7 -7
  64. package/src/modules/git/services/git.api.ts +17 -11
  65. package/src/modules/git/services/pr-prompts.ts +2 -2
  66. package/src/modules/git/state/git.context.ts +10 -1
  67. package/src/modules/layout/__tests__/SidebarFrameResponsive.test.tsx +224 -0
  68. package/src/modules/layout/__tests__/SidebarToggle.test.tsx +242 -0
  69. package/src/modules/layout/__tests__/breakpoints.test.ts +56 -0
  70. package/src/modules/layout/breakpoints.ts +6 -0
  71. package/src/modules/layout/components/AppLayout.tsx +17 -5
  72. package/src/modules/layout/components/DemoBanner.tsx +10 -1
  73. package/src/modules/layout/components/MaintenanceOverlay.tsx +3 -3
  74. package/src/modules/layout/components/MobileChatLayout.tsx +31 -26
  75. package/src/modules/layout/components/ResizableThreePaneLayout.tsx +59 -24
  76. package/src/modules/layout/components/SidebarFrame.tsx +317 -0
  77. package/src/modules/layout/components/SidebarToggle.tsx +86 -0
  78. package/src/modules/layout/components/SlideOverlay.tsx +1 -1
  79. package/src/modules/layout/components/__tests__/MobileChatLayout.test.tsx +40 -2
  80. package/src/modules/layout/components/__tests__/ResizableThreePaneLayout.test.tsx +19 -3
  81. package/src/modules/layout/state/sidebar.ts +200 -0
  82. package/src/modules/library/__tests__/AddToGroupDialog.test.tsx +313 -0
  83. package/src/modules/library/__tests__/ChangeRequestDock.test.tsx +84 -0
  84. package/src/modules/library/__tests__/GroupJoinRequests.test.tsx +178 -0
  85. package/src/modules/library/__tests__/GroupPage.test.tsx +479 -0
  86. package/src/modules/library/__tests__/GroupsIndexPage.test.tsx +283 -0
  87. package/src/modules/library/__tests__/GroupsSidebar.contextmenu.test.tsx +175 -0
  88. package/src/modules/library/__tests__/GroupsSidebar.locked.test.tsx +96 -0
  89. package/src/modules/library/__tests__/GroupsSidebar.test.tsx +142 -0
  90. package/src/modules/library/__tests__/GroupsSidebarMenu.test.tsx +142 -0
  91. package/src/modules/library/__tests__/LibraryCard.test.tsx +149 -0
  92. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +378 -0
  93. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +347 -0
  94. package/src/modules/library/__tests__/LockedGroupView.test.tsx +203 -0
  95. package/src/modules/library/__tests__/NewGroupDialog.test.tsx +114 -0
  96. package/src/modules/library/__tests__/PersonalAddDialog.test.tsx +177 -0
  97. package/src/modules/library/__tests__/SkillPage.test.tsx +1063 -0
  98. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +259 -0
  99. package/src/modules/library/__tests__/ToolLogo.test.tsx +63 -0
  100. package/src/modules/library/__tests__/ToolPage.test.tsx +315 -0
  101. package/src/modules/library/__tests__/ToolSharePanel.test.tsx +36 -0
  102. package/src/modules/library/__tests__/ToolVarRow.test.tsx +260 -0
  103. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +197 -0
  104. package/src/modules/library/__tests__/auth-harness.tsx +37 -0
  105. package/src/modules/library/__tests__/oauth-fragment.test.ts +48 -0
  106. package/src/modules/library/__tests__/status.test.ts +113 -20
  107. package/src/modules/library/__tests__/useSkillDetail.test.tsx +102 -0
  108. package/src/modules/library/__tests__/useToolPage.test.tsx +146 -0
  109. package/src/modules/library/components/AccessRequestsBanner.tsx +101 -0
  110. package/src/modules/library/components/AddToGroupDialog.tsx +115 -0
  111. package/src/modules/library/components/ChangeRequestDock.tsx +52 -28
  112. package/src/modules/library/components/DeleteGroupDialog.tsx +87 -0
  113. package/src/modules/library/components/GroupIndexRow.tsx +63 -0
  114. package/src/modules/library/components/GroupJoinRequests.tsx +56 -0
  115. package/src/modules/library/components/GroupPage.tsx +373 -0
  116. package/src/modules/library/components/GroupsIndexPage.tsx +222 -0
  117. package/src/modules/library/components/GroupsSidebar.tsx +338 -0
  118. package/src/modules/library/components/GroupsSidebarMenu.tsx +160 -0
  119. package/src/modules/library/components/LibraryCard.tsx +123 -102
  120. package/src/modules/library/components/LibraryLayout.tsx +344 -0
  121. package/src/modules/library/components/LibraryPage.tsx +111 -227
  122. package/src/modules/library/components/LockGlyph.tsx +31 -0
  123. package/src/modules/library/components/LockedGroupView.tsx +159 -0
  124. package/src/modules/library/components/ManagedGroupRequests.tsx +70 -0
  125. package/src/modules/library/components/NewGroupDialog.tsx +112 -0
  126. package/src/modules/library/components/NewSkillPanel.tsx +151 -0
  127. package/src/modules/library/components/PageActions.tsx +156 -0
  128. package/src/modules/library/components/PendingSkillReview.tsx +63 -0
  129. package/src/modules/library/components/PersonalAddDialog.tsx +88 -0
  130. package/src/modules/library/components/PersonalGroupPage.tsx +125 -0
  131. package/src/modules/library/components/StatusDot.tsx +25 -0
  132. package/src/modules/library/components/ToolLogo.tsx +171 -0
  133. package/src/modules/library/components/group-page-parts.tsx +419 -0
  134. package/src/modules/library/components/skill-page/SkillFileEditor.tsx +134 -0
  135. package/src/modules/library/components/skill-page/SkillFilePane.tsx +117 -0
  136. package/src/modules/library/components/skill-page/SkillFileTabs.tsx +112 -0
  137. package/src/modules/library/components/skill-page/SkillPage.tsx +673 -0
  138. package/src/modules/library/components/skill-page/tab-ids.ts +33 -0
  139. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +175 -0
  140. package/src/modules/library/components/tool-page/ToolPage.tsx +228 -0
  141. package/src/modules/library/components/tool-page/ToolSharePanel.tsx +45 -0
  142. package/src/modules/library/components/tool-page/ToolVarRow.tsx +289 -0
  143. package/src/modules/library/hooks/useJoinRequests.ts +114 -0
  144. package/src/modules/library/hooks/useLibraryData.ts +134 -119
  145. package/src/modules/library/hooks/useSkillDetail.ts +119 -74
  146. package/src/modules/library/hooks/useToolPage.ts +145 -0
  147. package/src/modules/library/library.css +33 -245
  148. package/src/modules/library/routes/LibraryRoutes.tsx +134 -0
  149. package/src/modules/library/routes/WorkspaceItemRoute.tsx +74 -0
  150. package/src/modules/library/routes/library-paths.ts +191 -0
  151. package/src/modules/library/services/groups.api.ts +189 -0
  152. package/src/modules/library/services/library.api.ts +291 -164
  153. package/src/modules/library/services/tools.api.ts +60 -0
  154. package/src/modules/library/state/library-context.ts +22 -0
  155. package/src/modules/library/state/library-data.tsx +223 -0
  156. package/src/modules/library/state/toast.context.ts +32 -0
  157. package/src/modules/library/state/toast.tsx +84 -42
  158. package/src/modules/library/utils/clipboard.ts +33 -0
  159. package/src/modules/library/utils/group-summary.ts +68 -0
  160. package/src/modules/library/utils/names.ts +30 -0
  161. package/src/modules/library/utils/navigate-external.ts +15 -0
  162. package/src/modules/library/utils/oauth-fragment.ts +32 -0
  163. package/src/modules/library/utils/personal-group.ts +36 -0
  164. package/src/modules/library/utils/status.ts +108 -25
  165. package/src/modules/library/utils/toast-duration.ts +16 -0
  166. package/src/modules/onboarding/__tests__/onboarding.test.tsx +533 -0
  167. package/src/modules/onboarding/agent-clients.ts +48 -0
  168. package/src/modules/onboarding/components/ConnectAgentPill.tsx +133 -0
  169. package/src/modules/onboarding/components/RootLanding.tsx +54 -0
  170. package/src/modules/onboarding/components/WelcomePage.tsx +364 -0
  171. package/src/modules/onboarding/paths.ts +9 -0
  172. package/src/modules/onboarding/state/onboarding.ts +191 -0
  173. package/src/modules/pr/components/OpenChangeRequestDialog.tsx +10 -10
  174. package/src/modules/pr/services/pr-approvals.api.ts +19 -0
  175. package/src/modules/pr/services/pr-cancel.api.ts +11 -0
  176. package/src/modules/review/components/BinaryChangePlaceholder.tsx +3 -3
  177. package/src/modules/review/components/DiffViewer.tsx +4 -4
  178. package/src/modules/review/components/MarkdownDiffViewer.tsx +84 -26
  179. package/src/modules/review/components/ReviewFileRow.tsx +10 -10
  180. package/src/modules/review/components/ReviewPanel.tsx +49 -17
  181. package/src/modules/review/components/ReviewPanelSurface.tsx +1 -1
  182. package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +122 -0
  183. package/src/modules/review/hooks/__tests__/useReviewState.test.ts +1 -1
  184. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +273 -171
  185. package/src/modules/secrets-vault/components/SecretsPage.tsx +147 -110
  186. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +109 -92
  187. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +35 -4
  188. package/src/modules/secrets-vault/services/connect.api.ts +24 -3
  189. package/src/modules/settings/components/DeploymentPage.tsx +90 -0
  190. package/src/modules/settings/components/SettingsLayout.tsx +135 -0
  191. package/src/modules/settings/components/SettingsNav.tsx +114 -0
  192. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +110 -0
  193. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +249 -0
  194. package/src/modules/settings/settings-nav-items.tsx +166 -0
  195. package/src/modules/setup/__tests__/setup.test.tsx +540 -0
  196. package/src/modules/setup/components/SetupGate.tsx +67 -0
  197. package/src/modules/setup/components/SetupScreen.tsx +573 -0
  198. package/src/modules/setup/services/setup.api.ts +106 -0
  199. package/src/modules/setup/utils/git-host.ts +34 -0
  200. package/src/modules/toolbar/components/AppSwitcher.tsx +38 -15
  201. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +50 -50
  202. package/src/modules/toolbar/components/ProfileMenu.tsx +294 -0
  203. package/src/modules/toolbar/components/Toolbar.tsx +56 -54
  204. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +176 -122
  205. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +252 -77
  206. package/src/modules/tools/ToolsExplorerPage.tsx +45 -40
  207. package/src/modules/workspace/__tests__/design-system-parity.test.ts +133 -0
  208. package/src/modules/workspace/__tests__/testFixtures.ts +2 -0
  209. package/src/modules/workspace/components/EditorTabs.tsx +82 -50
  210. package/src/modules/workspace/components/FileExplorer.tsx +413 -189
  211. package/src/modules/workspace/components/FilePaneCard.tsx +53 -0
  212. package/src/modules/workspace/components/FileRoute.tsx +89 -84
  213. package/src/modules/workspace/components/FileViewer.tsx +700 -294
  214. package/src/modules/workspace/components/KbDocumentShell.tsx +138 -0
  215. package/src/modules/workspace/components/KbFileRail.tsx +128 -0
  216. package/src/modules/workspace/components/KbPageHeader.tsx +390 -0
  217. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +87 -3
  218. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +293 -39
  219. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +1 -16
  220. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +462 -44
  221. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +84 -0
  222. package/src/modules/workspace/components/__tests__/KbFileRail.test.tsx +83 -0
  223. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +192 -0
  224. package/src/modules/workspace/components/renderers/CopyAnchorButton.tsx +64 -0
  225. package/src/modules/workspace/components/renderers/CsvRenderer.tsx +8 -8
  226. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +18 -9
  227. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +14 -14
  228. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +2 -2
  229. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +31 -165
  230. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +18 -5
  231. package/src/modules/workspace/components/renderers/MermaidDiagram.tsx +27 -10
  232. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +2 -2
  233. package/src/modules/workspace/components/renderers/TextRenderer.tsx +11 -5
  234. package/src/modules/workspace/components/renderers/ToolForm.tsx +24 -24
  235. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +27 -27
  236. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -11
  237. package/src/modules/workspace/components/renderers/__tests__/DocxRenderer.test.tsx +66 -0
  238. package/src/modules/workspace/components/renderers/__tests__/KbMarkdownView.test.tsx +17 -1
  239. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +1 -1
  240. package/src/modules/workspace/components/renderers/__tests__/MermaidDiagram.test.tsx +58 -0
  241. package/src/modules/workspace/components/renderers/__tests__/lazyRenderer.test.tsx +68 -0
  242. package/src/modules/workspace/components/renderers/__tests__/rendererLayout.test.ts +64 -0
  243. package/src/modules/workspace/components/renderers/__tests__/sanitizeDocxHtml.test.ts +0 -0
  244. package/src/modules/workspace/components/renderers/chunk-boundary.tsx +71 -0
  245. package/src/modules/workspace/components/renderers/index.ts +78 -2
  246. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +241 -0
  247. package/src/modules/workspace/components/renderers/lazyRenderer.tsx +59 -0
  248. package/src/modules/workspace/components/renderers/sanitizeDocxHtml.ts +91 -0
  249. package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +59 -0
  250. package/src/modules/workspace/hooks/__tests__/useOpenChangeRequests.test.tsx +237 -0
  251. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +185 -0
  252. package/src/modules/workspace/hooks/useAutoGrowTextarea.ts +30 -0
  253. package/src/modules/workspace/hooks/useLastCommit.ts +66 -0
  254. package/src/modules/workspace/hooks/useLinksOut.ts +56 -0
  255. package/src/modules/workspace/hooks/useOpenChangeRequests.ts +20 -0
  256. package/src/modules/workspace/hooks/useWorkspaceState.ts +123 -14
  257. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +1 -1
  258. package/src/modules/workspace/services/workspace.api.ts +9 -2
  259. package/src/modules/workspace/state/open-change-requests.context.ts +35 -0
  260. package/src/modules/workspace/state/open-change-requests.tsx +185 -0
  261. package/src/modules/workspace/state/workspace.context.ts +9 -0
  262. package/src/modules/workspace/utils/__tests__/diff.test.ts +87 -0
  263. package/src/modules/workspace/utils/diff.ts +130 -53
  264. package/src/modules/workspace/utils/fileTree.ts +7 -4
  265. package/src/modules/workspace/workspace.css +28 -0
  266. package/src/shared/components/Badge.tsx +62 -0
  267. package/src/shared/components/Banner.tsx +58 -0
  268. package/src/shared/components/Button.tsx +90 -0
  269. package/src/shared/components/Dialog.tsx +6 -6
  270. package/src/shared/components/Field.tsx +45 -0
  271. package/src/shared/components/IconButton.tsx +74 -0
  272. package/src/shared/components/ListRow.tsx +96 -0
  273. package/src/shared/components/Menu.tsx +88 -0
  274. package/src/shared/components/PageShell.tsx +8 -5
  275. package/src/shared/components/Surface.tsx +86 -0
  276. package/src/shared/components/__tests__/primitives.test.tsx +333 -0
  277. package/src/shared/components/index.ts +48 -0
  278. package/src/shared/components/useDismissableMenu.ts +71 -0
  279. package/src/shared/theme/__tests__/accent-contrast.test.ts +84 -0
  280. package/src/shared/theme/index.css +12 -0
  281. package/src/shared/theme/measure.ts +64 -0
  282. package/src/shared/theme/shadows.css +34 -0
  283. package/src/shared/theme/tokens.css +193 -0
  284. package/src/test-setup.ts +9 -0
  285. package/src/modules/access/components/AccessRestrictedBanner.tsx +0 -31
  286. package/src/modules/access/components/NodeOwnersBanner.tsx +0 -30
  287. package/src/modules/git/__tests__/ProtectedBranchBanner.test.tsx +0 -82
  288. package/src/modules/git/components/ProtectedBranchBanner.tsx +0 -42
  289. package/src/modules/library/__tests__/DetailDialog.test.tsx +0 -200
  290. package/src/modules/library/__tests__/diff.test.ts +0 -62
  291. package/src/modules/library/__tests__/loadout.test.tsx +0 -72
  292. package/src/modules/library/components/CompareView.tsx +0 -357
  293. package/src/modules/library/components/DetailDialog.tsx +0 -566
  294. package/src/modules/library/components/GearIcon.tsx +0 -12
  295. package/src/modules/library/components/LoadoutSidebar.tsx +0 -156
  296. package/src/modules/library/components/StatusGem.tsx +0 -21
  297. package/src/modules/library/components/SuggestChange.tsx +0 -171
  298. package/src/modules/library/components/particles.ts +0 -50
  299. package/src/modules/library/state/loadout.tsx +0 -129
  300. package/src/modules/library/utils/diff.ts +0 -102
  301. package/src/modules/pr/__tests__/PrApprovalBadge.test.tsx +0 -93
  302. package/src/modules/pr/__tests__/PrCancelButton.test.tsx +0 -158
  303. package/src/modules/pr/__tests__/PrCancelConfirmDialog.test.tsx +0 -44
  304. package/src/modules/pr/__tests__/PrMergeButton.test.tsx +0 -360
  305. package/src/modules/pr/__tests__/bucketize-comments.test.ts +0 -85
  306. package/src/modules/pr/__tests__/parsePatch.test.ts +0 -104
  307. package/src/modules/pr/__tests__/usePrViewerState.test.ts +0 -72
  308. package/src/modules/pr/components/PrApprovalBadge.tsx +0 -80
  309. package/src/modules/pr/components/PrCancelButton.tsx +0 -99
  310. package/src/modules/pr/components/PrCancelConfirmDialog.tsx +0 -119
  311. package/src/modules/pr/components/PrCommentComposer.tsx +0 -92
  312. package/src/modules/pr/components/PrCommentThread.tsx +0 -168
  313. package/src/modules/pr/components/PrCommentsPanel.tsx +0 -143
  314. package/src/modules/pr/components/PrDiffPane.tsx +0 -425
  315. package/src/modules/pr/components/PrFileRow.tsx +0 -164
  316. package/src/modules/pr/components/PrFilesList.tsx +0 -53
  317. package/src/modules/pr/components/PrHeader.tsx +0 -45
  318. package/src/modules/pr/components/PrHeaderOverflowMenu.tsx +0 -58
  319. package/src/modules/pr/components/PrMergeButton.tsx +0 -268
  320. package/src/modules/pr/components/PrMergeConfirmDialog.tsx +0 -112
  321. package/src/modules/pr/components/PrRefreshFromTargetButton.tsx +0 -110
  322. package/src/modules/pr/components/PrViewer.tsx +0 -364
  323. package/src/modules/pr/hooks/usePrViewerState.ts +0 -150
  324. package/src/modules/pr/state/pr-viewer.context.ts +0 -34
  325. package/src/modules/pr/utils/bucketize-comments.ts +0 -55
  326. package/src/modules/pr/utils/parsePatch.ts +0 -57
  327. package/src/modules/toolbar/components/AdminMenu.tsx +0 -271
@@ -0,0 +1,573 @@
1
+ import { useRef, useState, type FormEvent } from 'react';
2
+ import { Banner, Button, Surface, TextField } from '../../../shared/components';
3
+ import { tokenUsernameForHost } from '../utils/git-host';
4
+ import {
5
+ saveSettings,
6
+ testConnection,
7
+ SettingsProblems,
8
+ type ConnectionTest,
9
+ type SettingStatus,
10
+ } from '../services/setup.api';
11
+
12
+ /** Copy for each setting: what it is, in the words of someone who has to fill it in. */
13
+ const FIELDS: Record<
14
+ string,
15
+ { label: string; help: string; placeholder?: string; advanced?: boolean }
16
+ > = {
17
+ kbRepoUrl: {
18
+ label: 'Repository address',
19
+ help: 'Where your knowledge, skills and tools are stored. Copy the address from your repository page: GitHub, GitLab, Bitbucket and Azure DevOps all work. A brand-new empty repository is fine.',
20
+ placeholder: 'https://github.com/acme/knowledge-base.git',
21
+ },
22
+ gitToken: {
23
+ label: 'Access token',
24
+ help: 'Lets this deployment read and write that repository. Create one in your git provider with read and write access to it. Stored encrypted, and never shown again.',
25
+ placeholder: 'Paste the token',
26
+ },
27
+ gitUsername: {
28
+ // NOT a person's username — the previous label said "Token username" and
29
+ // people read it as their own account. It is a fixed string each host
30
+ // expects beside a token, so it is filled in automatically and only
31
+ // surfaces under Advanced for hosts we cannot recognise.
32
+ label: 'Token username',
33
+ help: 'A fixed value the git host expects next to the token, not your account name. Filled in automatically for known hosts; only change it for a self-hosted server.',
34
+ placeholder: 'x-access-token',
35
+ advanced: true,
36
+ },
37
+ kbDirName: {
38
+ label: 'Folder name',
39
+ help: 'What the repository folder is called inside each workspace. Cosmetic; leave it as it is.',
40
+ placeholder: 'knowledge-base',
41
+ advanced: true,
42
+ },
43
+ defaultBranch: {
44
+ label: 'Main branch',
45
+ help: 'The version everyone sees. Filled in from your repository when you test the connection.',
46
+ placeholder: 'main',
47
+ advanced: true,
48
+ },
49
+ protectedBranches: {
50
+ label: 'Branches that need approval',
51
+ help: 'Nobody can change these directly; edits arrive as a request someone approves. Separate several with commas. The main branch has to be one of them.',
52
+ placeholder: 'main',
53
+ advanced: true,
54
+ },
55
+ oidcIssuerUrl: {
56
+ label: 'Provider address',
57
+ help: 'From your identity provider. Entra, Okta, Google Workspace, Auth0 and others all publish one.',
58
+ placeholder: 'https://login.microsoftonline.com/<tenant>/v2.0',
59
+ },
60
+ oidcClientId: {
61
+ label: 'Application ID',
62
+ help: 'From the application you registered with the provider.',
63
+ },
64
+ oidcClientSecret: {
65
+ label: 'Application secret',
66
+ help: 'Issued alongside the application ID. Stored encrypted, and never shown again.',
67
+ },
68
+ oidcScopes: {
69
+ label: 'Scopes',
70
+ help: 'Leave blank unless your provider asked for something specific.',
71
+ placeholder: 'openid profile email',
72
+ advanced: true,
73
+ },
74
+ oidcProviderLabel: {
75
+ label: 'Sign-in button text',
76
+ help: 'What the button on the sign-in page says.',
77
+ placeholder: 'Single sign-on',
78
+ advanced: true,
79
+ },
80
+ allowedEmailDomains: {
81
+ label: 'Allowed email domains',
82
+ help: 'Only people with an address at these domains can sign in this way. Separate several with commas. Leave blank to allow any address: safe with a provider that only serves your organisation, risky with one that does not.',
83
+ placeholder: 'example.com',
84
+ },
85
+ };
86
+
87
+ /**
88
+ * What the deployment cannot start without — the same four the server's
89
+ * `isComplete` checks. Named here so a save that lands but leaves setup
90
+ * unfinished can say WHICH answer is still missing, rather than returning a
91
+ * blank form and letting the reader guess.
92
+ */
93
+ const REQUIRED_KEYS = ['kbRepoUrl', 'gitToken', 'defaultBranch', 'protectedBranches'];
94
+
95
+ /** The blocks, in the order they are worked through. */
96
+ const SECTIONS: { id: SettingStatus['section']; title: string; blurb: string }[] = [
97
+ {
98
+ id: 'knowledge-base',
99
+ title: 'Knowledge, skills & tools',
100
+ blurb:
101
+ 'Where everything lives, together in one git repository: knowledge, skills and tools. Connect one (an empty repository is fine, it will be set up for you) and test it; the rest fills itself in.',
102
+ },
103
+ {
104
+ id: 'sign-in',
105
+ title: 'Single sign-on',
106
+ blurb:
107
+ 'Optional, and you can add it later. Lets people sign in with the account they already have instead of a password.',
108
+ },
109
+ ];
110
+
111
+ interface Props {
112
+ settings: SettingStatus[];
113
+ /** Re-read the status after a save, so the gate can let the app through. */
114
+ onSaved(): void;
115
+ /**
116
+ * Where the screen is standing. `setup` (the default) is the first-run
117
+ * gate: full-page chrome, its own heading. `settings` is the SAME form
118
+ * embedded in the admin Deployment page — the host owns the chrome and the
119
+ * words around it, so the wrapper and heading stay out of the way. One
120
+ * component on purpose: the fields, the env-lock rule, the connection test
121
+ * and the restart banners must never drift between first run and later.
122
+ */
123
+ variant?: 'setup' | 'settings';
124
+ }
125
+
126
+ /**
127
+ * First-run setup: the one screen standing between a fresh deployment and a
128
+ * working one.
129
+ *
130
+ * WHY IT EXISTS AT ALL. Every value here used to be an environment variable
131
+ * that had to be right before the server would start — which meant the first
132
+ * feedback on a wrong token was a failed clone some minutes later, in a log.
133
+ * A form can do the thing an environment variable never can: ask the remote
134
+ * whether the answer is right, and say which part was wrong.
135
+ *
136
+ * WHAT IT DOES NOT DO. It never displays a stored secret, and it does not let
137
+ * anyone overwrite a value the environment supplies — those fields render as
138
+ * locked, naming the variable to change instead. That keeps a browser from
139
+ * silently outranking the infrastructure config someone is reviewing in a
140
+ * repo, which is the same rule the server enforces.
141
+ */
142
+ export function SetupScreen({ settings, onSaved, variant = 'setup' }: Props) {
143
+ const [draft, setDraft] = useState<Record<string, string>>({});
144
+ const [problems, setProblems] = useState<Record<string, string>>({});
145
+ const [error, setError] = useState<string | null>(null);
146
+ const [test, setTest] = useState<ConnectionTest | null>(null);
147
+ const [testing, setTesting] = useState(false);
148
+ const [saving, setSaving] = useState(false);
149
+ const [restartRequired, setRestartRequired] = useState(false);
150
+ /** Required answers still missing after a save that otherwise succeeded. */
151
+ const [stillMissing, setStillMissing] = useState<string[]>([]);
152
+ /** Answered, yet this process is still running on the old branch model. */
153
+ const [needsRestart, setNeedsRestart] = useState(false);
154
+ const noticeRef = useRef<HTMLDivElement>(null);
155
+
156
+ /** What a field would save as: what was typed, else what is already stored. */
157
+ const resolved = (key: string) =>
158
+ (draft[key] ?? settings.find((s) => s.key === key)?.value ?? '').trim();
159
+
160
+ const editable = settings.filter((s) => s.source !== 'env');
161
+ const fromEnv = settings.filter((s) => s.source === 'env');
162
+
163
+ function set(key: string, value: string) {
164
+ setDraft((d) => {
165
+ const next = { ...d, [key]: value };
166
+ // Typing the repository address answers the token-username question, so
167
+ // it is not asked. Only filled while the operator has not set one
168
+ // themselves — a self-hosted server they typed a value for must not be
169
+ // overwritten by a guess from its domain.
170
+ if (key === 'kbRepoUrl' && !d.gitUsername) {
171
+ const known = tokenUsernameForHost(value);
172
+ if (known) next.gitUsername = known.username;
173
+ }
174
+ return next;
175
+ });
176
+ // The message described the old value; keeping it beside a new one would
177
+ // be a complaint about something the reader already fixed.
178
+ setProblems((current) => {
179
+ if (!(key in current)) return current;
180
+ const next = { ...current };
181
+ delete next[key];
182
+ return next;
183
+ });
184
+ setTest(null);
185
+ }
186
+
187
+ async function runTest() {
188
+ setTesting(true);
189
+ setError(null);
190
+ try {
191
+ const result = await testConnection(draft);
192
+ setTest(result);
193
+ // The repository has just said what it calls its trunk and which
194
+ // branches it has. Filling those in beats asking someone to remember —
195
+ // and beats the silent failure of a name that is one character off.
196
+ // Only into fields nobody has typed in.
197
+ // Prefer what the remote calls its trunk. Not every host advertises it —
198
+ // older servers answer `ls-remote` without the symref line — so fall back
199
+ // to the conventional names before the first branch it did list. Leaving
200
+ // these blank is the one way a save can succeed and still not finish
201
+ // setup, which is worth a guess the reader can see and correct.
202
+ const suggested =
203
+ result.defaultBranch ||
204
+ ['main', 'master', 'trunk'].find((name) => result.branches?.includes(name)) ||
205
+ result.branches?.[0] ||
206
+ // An EMPTY repository has no branch to report, but it will be seeded
207
+ // with whatever is configured here, so the conventional name is the
208
+ // right suggestion. Suggesting nothing was the one way "Connected"
209
+ // could still end, silently, in a save that did not finish setup.
210
+ (result.empty ? 'main' : null);
211
+ if (result.ok && suggested) {
212
+ setDraft((d) => ({
213
+ ...d,
214
+ defaultBranch: d.defaultBranch || suggested,
215
+ protectedBranches: d.protectedBranches || suggested,
216
+ }));
217
+ }
218
+ } catch (err) {
219
+ setError(err instanceof Error ? err.message : 'Could not test the connection.');
220
+ } finally {
221
+ setTesting(false);
222
+ }
223
+ }
224
+
225
+ /**
226
+ * Ask the repository which branch to use, for someone who pressed Save
227
+ * without pressing Test. They have supplied everything they can be expected
228
+ * to know; a branch name is something we can look up, so refusing over it
229
+ * asks a question with a knowable answer. Only when the lookup ALSO comes
230
+ * back empty is the message worth showing.
231
+ */
232
+ async function deriveVersions(): Promise<Record<string, string> | null> {
233
+ try {
234
+ const result = await testConnection(draft);
235
+ if (!result.ok) return null;
236
+ const suggested =
237
+ result.defaultBranch ||
238
+ ['main', 'master', 'trunk'].find((name) => result.branches?.includes(name)) ||
239
+ result.branches?.[0] ||
240
+ // Same empty-repository rule as the visible test button above.
241
+ (result.empty ? 'main' : undefined);
242
+ if (!suggested) return null;
243
+ setTest(result);
244
+ const derived: Record<string, string> = {};
245
+ if (!resolved('defaultBranch')) derived.defaultBranch = suggested;
246
+ if (!resolved('protectedBranches')) derived.protectedBranches = suggested;
247
+ setDraft((d) => ({ ...d, ...derived }));
248
+ return derived;
249
+ } catch {
250
+ // The save carries on and the server says what is missing — a failed
251
+ // lookup is not itself an error the reader can act on.
252
+ return null;
253
+ }
254
+ }
255
+
256
+ async function submit(e: FormEvent) {
257
+ e.preventDefault();
258
+ if (saving) return;
259
+ setSaving(true);
260
+ setError(null);
261
+ setProblems({});
262
+ try {
263
+ let payload = draft;
264
+ if (!resolved('defaultBranch') || !resolved('protectedBranches')) {
265
+ const derived = await deriveVersions();
266
+ if (derived) payload = { ...draft, ...derived };
267
+ }
268
+ const result = await saveSettings(payload);
269
+ setRestartRequired(result.restartRequired);
270
+ setDraft({});
271
+ // A save can succeed and STILL leave the deployment unusable: a blank
272
+ // field means "leave it alone", not "this is wrong", so the server
273
+ // accepts a batch that answers only some of what it needs. Saying so is
274
+ // the difference between a form that looks broken and one that tells you
275
+ // what is left.
276
+ const missing = result.settings
277
+ .filter((setting) => REQUIRED_KEYS.includes(setting.key) && !setting.configured)
278
+ .map((setting) => FIELDS[setting.key]?.label ?? setting.key);
279
+ setStillMissing(result.complete || result.awaitingRestart ? [] : missing);
280
+ if (result.awaitingRestart) {
281
+ setNeedsRestart(true);
282
+ // The settings page still wants fresh status — the notice above says
283
+ // what the restart is for; the form should show what was saved.
284
+ if (variant === 'settings') onSaved();
285
+ return;
286
+ }
287
+ if (result.complete && variant === 'setup') {
288
+ // A FULL RELOAD, not just re-rendering the gate. The branch model the
289
+ // browser holds was fetched before any of this existed, and every
290
+ // module that reads it took its value then — so the app behind the
291
+ // gate would build URLs for a branch called nothing. Reloading is the
292
+ // one thing guaranteed to re-fetch it everywhere.
293
+ //
294
+ // SETUP MODE ONLY: on the settings page the app around the form is
295
+ // already running against a fetched branch model, and yanking the
296
+ // whole document out from under an admin who just pressed Save is
297
+ // not a refresh, it is a punishment. Rare branch-model edits there
298
+ // arrive with `restartRequired`, which the notice explains.
299
+ window.location.reload();
300
+ return;
301
+ }
302
+ onSaved();
303
+ } catch (err) {
304
+ if (err instanceof SettingsProblems) setProblems(err.problems);
305
+ else setError(err instanceof Error ? err.message : 'Could not save these settings.');
306
+ } finally {
307
+ setSaving(false);
308
+ // The page scrolls now, and every message lands at the top of it while
309
+ // the button that produced them is at the bottom. Without this, pressing
310
+ // Save on a long form looks like pressing Save did nothing.
311
+ requestAnimationFrame(() => noticeRef.current?.scrollIntoView({ block: 'nearest' }));
312
+ }
313
+ }
314
+
315
+ /**
316
+ * Branch names the connection test found on the remote. Offered as
317
+ * suggestions on the branch fields: these have to match the repository
318
+ * EXACTLY, and a typo produces a deployment pointing at a branch nobody has —
319
+ * which is precisely what a form can prevent and an environment variable
320
+ * cannot.
321
+ */
322
+ const remoteBranches = test?.ok ? (test.branches ?? []) : [];
323
+
324
+ function renderField(setting: SettingStatus) {
325
+ const copy = FIELDS[setting.key];
326
+ if (!copy) return null;
327
+ const isBranchField = setting.key === 'defaultBranch' || setting.key === 'protectedBranches';
328
+ const listId = isBranchField && remoteBranches.length > 0 ? `${setting.key}-options` : undefined;
329
+ return (
330
+ <div key={setting.key}>
331
+ <label className="block space-y-1.5">
332
+ <span className="text-detail font-medium text-ink">{copy.label}</span>
333
+ <TextField
334
+ type={setting.secret ? 'password' : 'text'}
335
+ autoComplete={setting.secret ? 'new-password' : 'off'}
336
+ placeholder={
337
+ // A configured secret has no value to show, so the field says
338
+ // what leaving it blank means instead.
339
+ setting.secret && setting.configured ? 'Saved. Type to replace' : copy.placeholder
340
+ }
341
+ value={draft[setting.key] ?? (setting.secret ? '' : (setting.value ?? ''))}
342
+ onChange={(e) => set(setting.key, e.target.value)}
343
+ list={listId}
344
+ aria-invalid={problems[setting.key] ? true : undefined}
345
+ aria-describedby={problems[setting.key] ? `${setting.key}-problem` : undefined}
346
+ />
347
+ </label>
348
+ {listId && (
349
+ <datalist id={listId}>
350
+ {remoteBranches.map((b) => (
351
+ <option key={b} value={b} />
352
+ ))}
353
+ </datalist>
354
+ )}
355
+ <p className="mt-1 text-meta text-ink-faint">{copy.help}</p>
356
+ {/* Only AFTER setup: on first run there is nothing yet to lose, so
357
+ the caution would be noise. Once a deployment is live, this field
358
+ is the one whose careless edit strands everything. */}
359
+ {variant === 'settings' && setting.key === 'kbRepoUrl' && (
360
+ <p className="mt-1.5 text-meta text-ink-muted">
361
+ <b className="font-semibold">
362
+ Only change this if the same repository was moved or renamed.
363
+ </b>{' '}
364
+ Pointing it at a different repository does not carry anything over: the knowledge,
365
+ skills and tools stay in the old one, and open change requests will stop working.
366
+ </p>
367
+ )}
368
+ {problems[setting.key] && (
369
+ <p id={`${setting.key}-problem`} role="alert" className="mt-1 text-meta text-danger">
370
+ {problems[setting.key]}
371
+ </p>
372
+ )}
373
+ </div>
374
+ );
375
+ }
376
+
377
+ // `h-full`, NOT `min-h-full`. `#root` is `height: 100%; overflow: hidden`, so
378
+ // a MINIMUM height lets this box grow past the viewport and be clipped there
379
+ // — `overflow-y-auto` then scrolls nothing, because nothing bounds the height
380
+ // it would scroll within. Being exactly the height of the root is what makes
381
+ // the overflow this element's own to handle.
382
+ return (
383
+ <div className={variant === 'setup' ? 'h-full overflow-y-auto bg-sunken px-6 py-12' : ''}>
384
+ <div className={variant === 'setup' ? 'mx-auto w-full max-w-2xl' : 'w-full max-w-2xl'}>
385
+ {variant === 'setup' && (
386
+ <>
387
+ <h1 className="text-display font-semibold text-ink">Set up this deployment</h1>
388
+ <p className="mt-2 max-w-[62ch] text-lede text-ink-muted">
389
+ One thing is needed before anyone can use it: somewhere to keep your knowledge,
390
+ skills and tools. Connect a repository below, test it, and the rest fills itself in.
391
+ Single sign-on is optional and can wait.
392
+ </p>
393
+ </>
394
+ )}
395
+
396
+ <div ref={noticeRef}>
397
+ {error && (
398
+ <Banner tone="danger" role="alert" className="mt-6">
399
+ {error}
400
+ </Banner>
401
+ )}
402
+
403
+ {/* Saved, and still not usable. Without this the form empties itself
404
+ and comes back looking untouched — indistinguishable from a save
405
+ that silently failed. */}
406
+ {needsRestart && (
407
+ <Banner tone="wait" role="status" className="mt-6">
408
+ Saved. This deployment needs a restart to pick the branch settings up; everything
409
+ else is in place.
410
+ </Banner>
411
+ )}
412
+
413
+ {stillMissing.length > 0 && (
414
+ <Banner tone="wait" role="status" className="mt-6">
415
+ Saved what you filled in, but this deployment still needs{' '}
416
+ <b className="font-semibold">{stillMissing.join(', ')}</b> before anyone can use it.
417
+ Test the connection and the version fields fill themselves in.
418
+ </Banner>
419
+ )}
420
+ </div>
421
+
422
+ {/* Only when setup is otherwise DONE. While it is not, the banner
423
+ above is already asking for a restart for the same reason, and two
424
+ notices saying "restart" differ only in urgency — which is exactly
425
+ the distinction a reader would miss. */}
426
+ {restartRequired && !needsRestart && (
427
+ <Banner tone="wait" role="status" className="mt-6">
428
+ Saved. One of those settings only takes effect when the server starts, so restart it
429
+ when convenient.
430
+ </Banner>
431
+ )}
432
+
433
+ <form onSubmit={submit} className="mt-8 space-y-10">
434
+ {SECTIONS.map((section) => {
435
+ const fields = editable.filter((s) => s.section === section.id);
436
+ // A section whose every field comes from the environment has
437
+ // nothing to offer — the locked list at the bottom already names
438
+ // them, and an empty heading would read as something missing.
439
+ if (fields.length === 0) return null;
440
+ return (
441
+ <Surface
442
+ key={section.id}
443
+ as="section"
444
+ tone="surface"
445
+ radius="lg"
446
+ elevation="card"
447
+ className="p-6 space-y-6"
448
+ >
449
+ <div>
450
+ <div className="flex items-baseline gap-2.5">
451
+ <h2 className="text-title font-semibold text-ink">{section.title}</h2>
452
+ {/* Says outright that a whole section can be skipped. The
453
+ gate only blocks on the knowledge base and the
454
+ versions, and someone who does not know that will fill
455
+ in an identity provider they do not have. */}
456
+ {section.id === 'sign-in' && (
457
+ <span className="text-meta text-ink-faint">Optional</span>
458
+ )}
459
+ </div>
460
+ <p className="mt-1 max-w-[60ch] text-detail text-ink-muted">{section.blurb}</p>
461
+ {section.id === 'sign-in' && (
462
+ <p className="mt-1.5 text-meta text-ink-faint">
463
+ Redirect URI:{' '}
464
+ <code className="font-mono">{`${window.location.origin}/api/auth/oidc/callback`}</code>
465
+ </p>
466
+ )}
467
+ </div>
468
+ {fields.filter((f) => !FIELDS[f.key]?.advanced).map((f) => renderField(f))}
469
+
470
+ {/* Immediately under the two fields it proves, and above the
471
+ Advanced block it fills in — the middle of the sequence
472
+ someone actually performs. It used to sit after every
473
+ section, so the answer to "did I type the token right?"
474
+ was below the identity-provider questions and, once the
475
+ page grew, below the fold entirely. */}
476
+ {section.id === 'knowledge-base' && (
477
+ <Surface tone="sunken" radius="md" className="p-4">
478
+ <div className="flex flex-wrap items-center gap-3">
479
+ <Button
480
+ type="button"
481
+ variant="outline"
482
+ size="sm"
483
+ onClick={() => void runTest()}
484
+ disabled={testing}
485
+ >
486
+ {testing ? 'Checking…' : 'Test connection'}
487
+ </Button>
488
+ <span className="text-meta text-ink-faint">
489
+ Checks the address and token against the host, and fills in the versions
490
+ below.
491
+ </span>
492
+ </div>
493
+ {test && (
494
+ <p
495
+ role="status"
496
+ className={`mt-3 text-detail ${test.ok ? 'text-ok' : 'text-danger'}`}
497
+ >
498
+ {test.ok
499
+ ? test.empty
500
+ ? 'Connected. The repository is empty; it will be set up for you on first use, and the version fields below are filled in with the standard name.'
501
+ : `Connected. Found ${test.branches?.length ?? 0} branch${
502
+ test.branches?.length === 1 ? '' : 'es'
503
+ }.`
504
+ : test.error}
505
+ </p>
506
+ )}
507
+ </Surface>
508
+ )}
509
+
510
+ {/* Everything a normal setup never touches, out of the way but
511
+ not hidden: a self-hosted git server does need the token
512
+ username, and a provider with unusual scopes does need
513
+ those. Closed by default, because leaving them open makes a
514
+ two-field form look like a seven-field one. */}
515
+ {fields.some((f) => FIELDS[f.key]?.advanced) && (
516
+ <details
517
+ // Forced open when something inside it is wrong. The branch
518
+ // pair lives here and the server validates it as a pair, so
519
+ // a message about it could otherwise land in a box the
520
+ // reader has no reason to open — a form that refuses to
521
+ // save and will not say why.
522
+ open={fields.some(
523
+ (f) =>
524
+ FIELDS[f.key]?.advanced &&
525
+ (problems[f.key] || stillMissing.includes(FIELDS[f.key]?.label ?? '')),
526
+ )}
527
+ className="group rounded-md border border-line bg-sunken px-3.5 py-2.5"
528
+ >
529
+ <summary className="cursor-pointer list-none text-detail font-medium text-ink-muted marker:hidden hover:text-ink">
530
+ Advanced
531
+ <span className="ml-1.5 text-meta text-ink-faint">
532
+ (sensible defaults; open only if you need to change one)
533
+ </span>
534
+ </summary>
535
+ <div className="mt-4 space-y-6">
536
+ {fields.filter((f) => FIELDS[f.key]?.advanced).map((f) => renderField(f))}
537
+ </div>
538
+ </details>
539
+ )}
540
+ </Surface>
541
+ );
542
+ })}
543
+
544
+
545
+ <div className="flex items-center gap-3">
546
+ <Button type="submit" variant="primary" disabled={saving}>
547
+ {saving ? 'Saving…' : 'Save and continue'}
548
+ </Button>
549
+ </div>
550
+ </form>
551
+
552
+ {fromEnv.length > 0 && (
553
+ <Surface tone="sunken" radius="md" className="mt-10 p-4">
554
+ <h2 className="text-label font-semibold uppercase text-ink-faint">
555
+ Set by the environment
556
+ </h2>
557
+ <p className="mt-1.5 text-meta text-ink-muted">
558
+ These already have a value from this deployment&apos;s configuration, which takes
559
+ precedence over anything saved here. Change them where they are set.
560
+ </p>
561
+ <ul className="mt-3 space-y-1">
562
+ {fromEnv.map((s) => (
563
+ <li key={s.key} className="font-mono text-meta text-ink-muted">
564
+ {s.envVar}
565
+ </li>
566
+ ))}
567
+ </ul>
568
+ </Surface>
569
+ )}
570
+ </div>
571
+ </div>
572
+ );
573
+ }
@@ -0,0 +1,106 @@
1
+ import { authFetch } from '../../../lib/api';
2
+
3
+ /** One configurable setting, as the server describes it. */
4
+ export interface SettingStatus {
5
+ key: string;
6
+ /** The environment variable that still wins if it is set. */
7
+ envVar: string;
8
+ section: 'knowledge-base' | 'sign-in';
9
+ source: 'env' | 'stored' | 'unset';
10
+ /** Absent for secrets — the server never sends a stored secret back. */
11
+ value?: string;
12
+ configured: boolean;
13
+ secret: boolean;
14
+ /** The running server cannot pick this one up; it takes a restart. */
15
+ restartToApply: boolean;
16
+ }
17
+
18
+ export interface SetupStatus {
19
+ /** Reachable knowledge base AND a process that can serve it. */
20
+ complete: boolean;
21
+ /**
22
+ * Answered, but the running process still holds the old branch model. Should
23
+ * be rare — saving applies it — and means a restart, not another answer.
24
+ */
25
+ awaitingRestart?: boolean;
26
+ isAdmin: boolean;
27
+ /** Admins only — nobody else is told what is missing. */
28
+ settings?: SettingStatus[];
29
+ }
30
+
31
+ export interface SaveResult {
32
+ restartRequired: boolean;
33
+ complete: boolean;
34
+ awaitingRestart?: boolean;
35
+ settings: SettingStatus[];
36
+ }
37
+
38
+ /** Field-keyed messages, so the form can mark the input that was wrong. */
39
+ export class SettingsProblems extends Error {
40
+ // Declared and assigned rather than a parameter property: this package
41
+ // compiles with `erasableSyntaxOnly`, which forbids the shorthand.
42
+ readonly problems: Record<string, string>;
43
+
44
+ constructor(problems: Record<string, string>) {
45
+ super('Some settings need fixing.');
46
+ this.name = 'SettingsProblems';
47
+ this.problems = problems;
48
+ }
49
+ }
50
+
51
+ async function readError(res: Response): Promise<never> {
52
+ let body: unknown;
53
+ try {
54
+ body = await res.json();
55
+ } catch {
56
+ throw new Error(`Request failed (${res.status})`);
57
+ }
58
+ const data = body as { error?: string; problems?: Record<string, string> };
59
+ if (data.problems) throw new SettingsProblems(data.problems);
60
+ throw new Error(data.error || `Request failed (${res.status})`);
61
+ }
62
+
63
+ export async function fetchSetupStatus(): Promise<SetupStatus> {
64
+ const res = await authFetch('/api/setup/status');
65
+ if (!res.ok) await readError(res);
66
+ return (await res.json()) as SetupStatus;
67
+ }
68
+
69
+ export async function saveSettings(settings: Record<string, string>): Promise<SaveResult> {
70
+ const res = await authFetch('/api/setup/settings', {
71
+ method: 'POST',
72
+ headers: { 'Content-Type': 'application/json' },
73
+ body: JSON.stringify({ settings }),
74
+ });
75
+ if (!res.ok) await readError(res);
76
+ return (await res.json()) as SaveResult;
77
+ }
78
+
79
+ export interface ConnectionTest {
80
+ ok: boolean;
81
+ /** The remote answered but has no branches yet — a supported starting point. */
82
+ empty?: boolean;
83
+ branches?: string[];
84
+ /**
85
+ * What the remote calls its own trunk, when it says. The screen pre-fills
86
+ * the version fields from it — the names have to match the repository
87
+ * exactly, and being one character off is a failure nobody can see.
88
+ */
89
+ defaultBranch?: string | null;
90
+ error?: string;
91
+ }
92
+
93
+ /**
94
+ * Try the credentials against the real remote before saving anything. Values
95
+ * are sent as typed so an admin tests what is on screen, not what is stored;
96
+ * omitted fields fall back to what is already in effect.
97
+ */
98
+ export async function testConnection(fields: Record<string, string>): Promise<ConnectionTest> {
99
+ const res = await authFetch('/api/setup/test-connection', {
100
+ method: 'POST',
101
+ headers: { 'Content-Type': 'application/json' },
102
+ body: JSON.stringify(fields),
103
+ });
104
+ if (!res.ok) await readError(res);
105
+ return (await res.json()) as ConnectionTest;
106
+ }