@bevel-software/platform-core-frontend 0.25.2 → 0.27.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 (193) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +87 -25
  3. package/src/core/ProductName.tsx +49 -0
  4. package/src/core/__tests__/ShellRoutes.test.tsx +22 -0
  5. package/src/core/__tests__/core-contributions.test.ts +16 -0
  6. package/src/core/core-contributions.ts +17 -0
  7. package/src/core/registry.ts +51 -1
  8. package/src/index.css +23 -5
  9. package/src/index.ts +5 -0
  10. package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +1 -1
  11. package/src/modules/access/components/ManageAccessDialog.tsx +1 -1
  12. package/src/modules/admin/__tests__/RolesCorruptedBanner.test.tsx +70 -0
  13. package/src/modules/admin/components/RolesCorruptedBanner.tsx +9 -4
  14. package/src/modules/auth/components/LoginScreen.tsx +4 -1
  15. package/src/modules/auth/services/account.api.ts +28 -1
  16. package/src/modules/auth/services/sso.ts +1 -2
  17. package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +176 -0
  18. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +68 -0
  19. package/src/modules/change-requests/__tests__/ChangeRequestLink.test.tsx +182 -0
  20. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +1 -1
  21. package/src/modules/change-requests/__tests__/readFileOnBranch.test.ts +79 -0
  22. package/src/modules/change-requests/components/ChangeBox.tsx +6 -1
  23. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +45 -15
  24. package/src/modules/change-requests/components/ChangeRequestLink.tsx +151 -0
  25. package/src/modules/change-requests/components/CrFileTree.tsx +2 -1
  26. package/src/modules/change-requests/components/FileChangeBoxes.tsx +4 -2
  27. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +6 -3
  28. package/src/modules/change-requests/services/change-requests.api.ts +15 -2
  29. package/src/modules/change-requests/utils/readFailure.ts +22 -0
  30. package/src/modules/embed/__tests__/EmbedLinkPage.test.tsx +74 -0
  31. package/src/modules/embed/__tests__/EmbedView.test.tsx +473 -0
  32. package/src/modules/embed/__tests__/embed-config.test.ts +128 -0
  33. package/src/modules/embed/__tests__/embed-host.test.ts +111 -0
  34. package/src/modules/embed/__tests__/mcp-app-view.test.ts +295 -0
  35. package/src/modules/embed/__tests__/mount.test.tsx +157 -0
  36. package/src/modules/embed/components/EmbedLinkPage.tsx +109 -0
  37. package/src/modules/embed/components/EmbedView.tsx +545 -0
  38. package/src/modules/embed/embed-config.ts +132 -0
  39. package/src/modules/embed/embed-host.ts +120 -0
  40. package/src/modules/embed/mount.tsx +80 -0
  41. package/src/modules/embed/services/embed-token.ts +22 -0
  42. package/src/modules/embed/services/embed.api.ts +158 -0
  43. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +202 -4
  44. package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +59 -1
  45. package/src/modules/git/__tests__/PullNeededBanner.test.tsx +39 -22
  46. package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +7 -2
  47. package/src/modules/git/branch-delete-menu-item.tsx +24 -0
  48. package/src/modules/git/components/BranchSwitcher.tsx +29 -5
  49. package/src/modules/git/components/GitSyncFailedBanner.tsx +53 -15
  50. package/src/modules/git/components/HistoryVersionPreview.tsx +5 -3
  51. package/src/modules/git/components/PullNeededBanner.tsx +15 -49
  52. package/src/modules/git/hooks/useAutoPullUpdates.ts +9 -5
  53. package/src/modules/git/index.ts +15 -0
  54. package/src/modules/git/services/__tests__/error-messages.test.ts +67 -0
  55. package/src/modules/git/services/__tests__/pull-failure.test.ts +36 -0
  56. package/src/modules/git/services/error-messages.ts +58 -1
  57. package/src/modules/git/services/pull-failure.ts +68 -0
  58. package/src/modules/git/state/branch-delete-confirm.ts +46 -0
  59. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +1 -0
  60. package/src/modules/layout/__tests__/breakpoints.test.ts +7 -1
  61. package/src/modules/layout/breakpoints.ts +8 -0
  62. package/src/modules/library/__tests__/PluginExtras.test.tsx +9 -9
  63. package/src/modules/library/__tests__/PluginPage.test.tsx +8 -1
  64. package/src/modules/library/__tests__/SkillsTree.test.tsx +13 -4
  65. package/src/modules/library/__tests__/ToolPage.test.tsx +53 -0
  66. package/src/modules/library/components/LibraryPage.tsx +22 -0
  67. package/src/modules/library/components/PluginExtras.tsx +23 -6
  68. package/src/modules/library/components/PluginPage.tsx +6 -1
  69. package/src/modules/library/components/tool-page/ToolPage.tsx +45 -1
  70. package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
  71. package/src/modules/library/services/plugins.api.ts +4 -1
  72. package/src/modules/library/services/tools.api.ts +27 -0
  73. package/src/modules/library/state/plugins-revision.ts +28 -0
  74. package/src/modules/onboarding/__tests__/agent-connection-api.test.ts +55 -0
  75. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +87 -82
  76. package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +109 -0
  77. package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1001 -0
  78. package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +392 -0
  79. package/src/modules/onboarding/__tests__/onboarding.test.tsx +226 -193
  80. package/src/modules/onboarding/__tests__/starter-pack-card.test.tsx +136 -0
  81. package/src/modules/onboarding/components/CreatorWelcomePage.tsx +7 -11
  82. package/src/modules/onboarding/components/EmailChipsInput.tsx +138 -0
  83. package/src/modules/onboarding/components/GetStartedColumn.tsx +651 -0
  84. package/src/modules/onboarding/components/InviteButton.tsx +35 -0
  85. package/src/modules/onboarding/components/InviteDialog.tsx +424 -0
  86. package/src/modules/onboarding/components/RootLanding.tsx +8 -24
  87. package/src/modules/onboarding/components/StarterPackCard.tsx +98 -0
  88. package/src/modules/onboarding/components/WelcomePage.tsx +65 -154
  89. package/src/modules/onboarding/first-page-prompt.ts +89 -0
  90. package/src/modules/onboarding/invite-emails.ts +175 -0
  91. package/src/modules/onboarding/services/agent-connection.api.ts +53 -0
  92. package/src/modules/onboarding/services/starter-packs.api.ts +83 -0
  93. package/src/modules/onboarding/state/agent-connection.ts +167 -0
  94. package/src/modules/onboarding/state/invite-dialog.context.ts +32 -0
  95. package/src/modules/onboarding/state/invite-dialog.tsx +31 -0
  96. package/src/modules/onboarding/state/onboarding.ts +133 -59
  97. package/src/modules/onboarding/state/starter-packs.ts +169 -0
  98. package/src/modules/settings/settings-nav-items.tsx +8 -3
  99. package/src/modules/setup/__tests__/setup.first-run-storage.test.tsx +389 -0
  100. package/src/modules/setup/__tests__/setup.github.test.tsx +5 -5
  101. package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +1 -1
  102. package/src/modules/setup/__tests__/setup.repository-change.test.tsx +1 -1
  103. package/src/modules/setup/__tests__/setup.repository.test.tsx +21 -21
  104. package/src/modules/setup/__tests__/setup.test.tsx +65 -81
  105. package/src/modules/setup/__tests__/useConnectionProbe.test.tsx +123 -0
  106. package/src/modules/setup/components/FirstRunStorage.tsx +560 -0
  107. package/src/modules/setup/components/SetupGate.tsx +46 -1
  108. package/src/modules/setup/components/SetupScreen.tsx +92 -152
  109. package/src/modules/setup/hooks/useConnectionProbe.ts +93 -0
  110. package/src/modules/setup/services/setup.api.ts +3 -3
  111. package/src/modules/setup/utils/suggested-branch.ts +27 -0
  112. package/src/modules/toolbar/commands/__tests__/actions.test.tsx +210 -0
  113. package/src/modules/toolbar/commands/actions.tsx +324 -0
  114. package/src/modules/toolbar/commands/command-menu.ts +44 -0
  115. package/src/modules/toolbar/commands/useCommandActions.ts +69 -0
  116. package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
  117. package/src/modules/toolbar/components/AppSwitcher.tsx +106 -22
  118. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
  119. package/src/modules/toolbar/components/ProfileMenu.tsx +9 -4
  120. package/src/modules/toolbar/components/SearchPalette.tsx +540 -0
  121. package/src/modules/toolbar/components/Toolbar.tsx +10 -0
  122. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +187 -54
  123. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +4 -4
  124. package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
  125. package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +832 -0
  126. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +57 -2
  127. package/src/modules/toolbar/search/__tests__/rank.test.ts +93 -0
  128. package/src/modules/toolbar/search/__tests__/sources.test.ts +131 -0
  129. package/src/modules/toolbar/search/rank.ts +111 -0
  130. package/src/modules/toolbar/search/sources.ts +169 -0
  131. package/src/modules/workflow/hooks/useFileLock.ts +10 -7
  132. package/src/modules/workflow/services/__tests__/lock.api.test.ts +41 -0
  133. package/src/modules/workflow/services/lock.api.ts +17 -2
  134. package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +49 -1
  135. package/src/modules/workspace/components/EditorTabs.tsx +39 -15
  136. package/src/modules/workspace/components/FileExplorer.tsx +39 -6
  137. package/src/modules/workspace/components/FilePaneCard.tsx +6 -2
  138. package/src/modules/workspace/components/FileRoute.tsx +12 -7
  139. package/src/modules/workspace/components/FileViewer.tsx +271 -74
  140. package/src/modules/workspace/components/KbPageHeader.tsx +13 -6
  141. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +88 -21
  142. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +101 -11
  143. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +23 -3
  144. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +330 -6
  145. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +17 -2
  146. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -16
  147. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +6 -0
  148. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +23 -21
  149. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +13 -29
  150. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +9 -2
  151. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +8 -0
  152. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +14 -19
  153. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +11 -17
  154. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +35 -7
  155. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -17
  156. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.links.test.tsx +73 -0
  157. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.scaffold.test.tsx +64 -0
  158. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.surface.test.tsx +82 -0
  159. package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +99 -0
  160. package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +129 -35
  161. package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +149 -0
  162. package/src/modules/workspace/components/renderers/__tests__/kbMarkdownLinkPolicy.test.tsx +100 -0
  163. package/src/modules/workspace/components/renderers/htmlSandbox.ts +76 -20
  164. package/src/modules/workspace/components/renderers/index.ts +26 -0
  165. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +51 -1
  166. package/src/modules/workspace/components/renderers/rendererRawRead.ts +53 -0
  167. package/src/modules/workspace/components/renderers/rendererSurface.ts +109 -0
  168. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +8 -2
  169. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +126 -21
  170. package/src/modules/workspace/hooks/useCreatePage.ts +116 -0
  171. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +24 -7
  172. package/src/modules/workspace/hooks/useWorkspaceState.ts +42 -8
  173. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +10 -0
  174. package/src/modules/workspace/routing/__tests__/md-links-parity.test.tsx +113 -0
  175. package/src/modules/workspace/routing/kb-routes.ts +66 -12
  176. package/src/modules/workspace/state/editable-page.ts +42 -0
  177. package/src/modules/workspace/state/workspace.context.ts +13 -4
  178. package/src/modules/workspace/utils/__tests__/display-file-name.test.ts +60 -0
  179. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +75 -0
  180. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +26 -14
  181. package/src/modules/workspace/utils/display-file-name.ts +102 -0
  182. package/src/modules/workspace/utils/fileTree.ts +49 -14
  183. package/src/modules/workspace/utils/treeConfirm.ts +22 -5
  184. package/src/shared/__tests__/no-builtin-confirm.test.ts +102 -0
  185. package/src/shared/components/ConfirmProvider.tsx +156 -0
  186. package/src/shared/components/Dialog.tsx +7 -0
  187. package/src/shared/components/__tests__/ConfirmProvider.test.tsx +198 -0
  188. package/src/shared/components/confirm-context.ts +94 -0
  189. package/src/shared/components/index.ts +3 -0
  190. package/src/shared/mcp/__tests__/connect-snippets.test.ts +2 -2
  191. package/src/shared/mcp/connect-snippets.ts +8 -5
  192. package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
  193. package/src/modules/onboarding/welcome-state.ts +0 -36
@@ -1,23 +1,20 @@
1
1
  import { useEffect, useRef, useState, type FormEvent, type KeyboardEvent, type ReactNode } from 'react';
2
- import {
3
- DEFAULT_KB_LAYOUT,
4
- agentsFilePointerSentence,
5
- type KbLayout,
6
- } from '@bevel-software/platform-shared';
2
+ import { DEFAULT_KB_LAYOUT, type KbLayout } from '@bevel-software/platform-shared';
7
3
  import { Banner, Button, Surface, TextField } from '../../../shared/components';
8
4
  import { SlotBoundary } from '../../../shared/components/SlotBoundary';
9
5
  import { tokenUsernameForHost } from '../utils/git-host';
6
+ import { suggestedBranch } from '../utils/suggested-branch';
10
7
  import { isRootFolderSuggestion, rootFolderState, type RootFolderState } from '../utils/root-folders';
11
8
  import { copyToClipboard } from '../../../lib/clipboard';
12
9
  import { GitHubRepositoryPanel } from './GitHubRepositoryPanel';
13
10
  import { forgetDraft, keepDraft, keptDraft } from '../utils/kept-draft';
14
11
  import { useAppRegistry } from '../../../core/registry';
15
12
  import { MarketplaceSection } from '../../settings/components/MarketplaceSection';
13
+ import { ConnectionProbeFailed, useConnectionProbe } from '../hooks/useConnectionProbe';
16
14
  import {
17
15
  saveSettings,
18
16
  syncNow,
19
17
  syncOutcomeError,
20
- testConnection,
21
18
  KbInitFailed,
22
19
  testOidc,
23
20
  RepositoryChangeNeedsConfirmation,
@@ -66,13 +63,13 @@ function CopyValue({ value, label }: { value: string; label: string }) {
66
63
 
67
64
  /** "main updated, ali/x up to date" — the per-branch outcomes as one phrase. */
68
65
  function describeOutcomes(results: LastSync['results']): string {
69
- if (results.length === 0) return 'nothing to sync yet';
66
+ if (results.length === 0) return 'nothing to update yet';
70
67
  const word = (r: LastSync['results'][number]): string => {
71
68
  switch (r.outcome) {
72
69
  case 'up-to-date':
73
70
  return 'up to date';
74
71
  case 'not-cloned':
75
- return 'not cloned';
72
+ return 'not set up on this server yet';
76
73
  case 'remote-gone':
77
74
  return 'deleted on the host';
78
75
  default:
@@ -85,7 +82,14 @@ function describeOutcomes(results: LastSync['results']): string {
85
82
  /** Copy for each setting: what it is, in the words of someone who has to fill it in. */
86
83
  const FIELDS: Record<
87
84
  string,
88
- { label: string; help: string; placeholder?: string; advanced?: boolean }
85
+ {
86
+ label: string;
87
+ help: string;
88
+ placeholder?: string;
89
+ advanced?: boolean;
90
+ /** An on/off setting, shown as a checkbox and saved as `true` / `false`; `on` is what an unset one means. */
91
+ toggle?: { on: boolean };
92
+ }
89
93
  > = {
90
94
  kbRepoUrl: {
91
95
  label: 'Repository address',
@@ -114,8 +118,8 @@ const FIELDS: Record<
114
118
  advanced: true,
115
119
  },
116
120
  kbSyncSecret: {
117
- label: 'Sync secret',
118
- help: 'Lets your git host tell this deployment when the repository changes, so pushes and merged pull requests show up right away. Add a webhook, action or pipeline step that calls POST /api/sync/<branch> with this value as a bearer token. Optional: without it, only an administrator can trigger a sync. Stored encrypted, and never shown again.',
121
+ label: 'Hook secret',
122
+ help: 'Lets your git host tell this deployment when the repository changes, so changes made there show up here right away. Add a webhook, action or pipeline step that calls POST /api/sync/<branch> with this value as a bearer token. Optional: without it, only an administrator can bring in updates. Stored encrypted, and never shown again.',
119
123
  placeholder: 'A long random string',
120
124
  advanced: true,
121
125
  },
@@ -137,14 +141,6 @@ const FIELDS: Record<
137
141
  help: 'The top-level folder that holds plugins. The three folder names must differ.',
138
142
  placeholder: 'Plugins',
139
143
  },
140
- // Beside the folders, and not under Advanced, for the same reason they are
141
- // not: a repository that already has an `AGENTS.md` of its own loses it to
142
- // the platform's on the first boot unless this is answered first.
143
- agentsFile: {
144
- label: 'Agent guide file',
145
- 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.',
146
- placeholder: 'AGENTS.md',
147
- },
148
144
  defaultBranch: {
149
145
  label: 'Main branch',
150
146
  help: 'The version everyone sees. Filled in from your repository when you test the connection.',
@@ -157,6 +153,12 @@ const FIELDS: Record<
157
153
  placeholder: 'main',
158
154
  advanced: true,
159
155
  },
156
+ retireMergedBranches: {
157
+ label: 'Remove branches left over from merged change requests',
158
+ help: 'Removes, on its own, a draft whose change request was merged but which is still there: every commit on it is already on the main branch and no request is open from or into it. Runs at startup and whenever the server checks for deleted branches. Merging a change request removes its draft either way. Applies without a restart.',
159
+ advanced: true,
160
+ toggle: { on: true },
161
+ },
160
162
  oidcIssuerUrl: {
161
163
  label: 'Provider address',
162
164
  help: 'From your identity provider. Entra, Okta, Google Workspace, Auth0 and others all publish one.',
@@ -207,7 +209,7 @@ const BRANCH_MODEL_KEYS = ['defaultBranch', 'protectedBranches'];
207
209
 
208
210
  /** What each way of having a repository is called on its tab. */
209
211
  const GIT_MODE_LABEL: Record<GitMode, string> = {
210
- managed: 'Managed for you',
212
+ managed: 'Hexis takes care of it',
211
213
  'github-app': 'GitHub',
212
214
  token: 'Address and token',
213
215
  };
@@ -255,22 +257,15 @@ const isRootFolderKey = (key: string): key is (typeof ROOT_FOLDER_KEYS)[number]
255
257
  (ROOT_FOLDER_KEYS as readonly string[]).includes(key);
256
258
 
257
259
  /**
258
- * The knowledge-base LAYOUT fields — the three folders and the agent guide's
259
- * file name — which render together, under the connection test whose listing
260
- * the folders are checked against, rather than with the connection fields
261
- * above it.
260
+ * The knowledge-base LAYOUT fields — the three folders — which render
261
+ * together, under the connection test whose listing they are checked
262
+ * against, rather than with the connection fields above it. (The guide's
263
+ * file name was one of them while the guide was written to disk; it is
264
+ * served by the platform now and has no field.)
262
265
  */
263
- const LAYOUT_KEYS: readonly (keyof KbLayout)[] = [...ROOT_FOLDER_KEYS, 'agentsFile'];
266
+ const LAYOUT_KEYS: readonly (keyof KbLayout)[] = [...ROOT_FOLDER_KEYS];
264
267
  const isLayoutKey = (key: string): boolean => (LAYOUT_KEYS as readonly string[]).includes(key);
265
268
 
266
- /**
267
- * The consent that rides along with a renamed guide: keep the platform's
268
- * one-sentence pointer in the customer's own `AGENTS.md`. Not a text field, so
269
- * it has no {@link FIELDS} entry and is drawn by hand under the name it
270
- * belongs to.
271
- */
272
- const AGENTS_LINK_KEY = 'agentsFileLink';
273
-
274
269
  /** How a near-miss folder differs from the configured name, as the warning words it. */
275
270
  const VARIANT_DIFFERENCE: Record<Extract<RootFolderState, { kind: 'variant' }>['difference'], string> = {
276
271
  case: 'differs only by case',
@@ -503,12 +498,10 @@ export function SetupScreen({
503
498
  const [repositoryChanged, setRepositoryChanged] = useState<RepositoryChangeResult | null>(null);
504
499
  const [retrying, setRetrying] = useState(false);
505
500
  const [syncing, setSyncing] = useState(false);
506
- /** What the last "Sync now" from THIS page came back with (a failure to ask is `error`). */
501
+ /** What the last "Update now" from THIS page came back with (a failure to ask is `error`). */
507
502
  const [syncResult, setSyncResult] = useState<SyncNowResult | null>(null);
508
503
  const [problems, setProblems] = useState<Record<string, string>>({});
509
504
  const [error, setError] = useState<string | null>(null);
510
- const [test, setTest] = useState<ConnectionTest | null>(null);
511
- const [testing, setTesting] = useState(false);
512
505
  const [saving, setSaving] = useState(false);
513
506
  const [restartRequired, setRestartRequired] = useState(false);
514
507
  /** Required answers still missing after a save that otherwise succeeded. */
@@ -517,16 +510,16 @@ export function SetupScreen({
517
510
  const [needsRestart, setNeedsRestart] = useState(false);
518
511
  const noticeRef = useRef<HTMLDivElement>(null);
519
512
  /**
520
- * Which set of connection answers the screen is showing, bumped on every
521
- * edit to one of them. A test result describes the answers as they were when
522
- * the request left; if they changed while it was in flight, the result that
523
- * comes back is evidence about values no longer on screen and must not be
524
- * shown as if it were about the new ones.
513
+ * The connection test: what the host last said about the answers on screen,
514
+ * cleared by an edit to one of them, with an answer that lands after such
515
+ * an edit held stale rather than shown. The probe is the one mechanism for
516
+ * it, shared with the first-run storage screen.
525
517
  */
526
- const connectionEpoch = useRef(0);
518
+ const probe = useConnectionProbe();
519
+ const { result: test, testing } = probe;
527
520
  const [oidcTest, setOidcTest] = useState<OidcTest | null>(null);
528
521
  const [oidcTesting, setOidcTesting] = useState(false);
529
- /** The same staleness guard as {@link connectionEpoch}, for the sign-in answers. */
522
+ /** The probe's staleness guard, for the sign-in answers: a result describes the answers as they were when the request left. */
530
523
  const oidcEpoch = useRef(0);
531
524
  /**
532
525
  * A verification state newer than the one the host last passed in — what a
@@ -772,34 +765,9 @@ export function SetupScreen({
772
765
  // A test's "Verified" was about the values before this edit.
773
766
  setLatest(null);
774
767
  }
775
- if (CONNECTION_KEYS.includes(key)) {
776
- // Any in-flight test is now asking about values that are gone; the epoch
777
- // bump makes its answer land as stale rather than as evidence.
778
- connectionEpoch.current++;
779
- setTest(null);
780
- }
781
- }
782
-
783
- /**
784
- * Which branch the repository just named, or the best conventional stand-in.
785
- *
786
- * Prefer what the remote calls its trunk. Not every host advertises it —
787
- * older servers answer `ls-remote` without the symref line — so fall back to
788
- * the conventional names before the first branch it did list. Leaving these
789
- * blank is the one way a save can succeed and still not finish setup, which
790
- * is worth a guess the reader can see and correct.
791
- */
792
- function suggestedBranch(result: ConnectionTest): string | null {
793
- return (
794
- result.defaultBranch ||
795
- ['main', 'master', 'trunk'].find((name) => result.branches?.includes(name)) ||
796
- result.branches?.[0] ||
797
- // An EMPTY repository has no branch to report, but it will be seeded
798
- // with whatever is configured here, so the conventional name is the
799
- // right suggestion. Suggesting nothing was the one way "Connected"
800
- // could still end, silently, in a save that did not finish setup.
801
- (result.empty ? 'main' : null)
802
- );
768
+ // Any in-flight test is now asking about values that are gone; its answer
769
+ // lands as stale rather than as evidence.
770
+ if (CONNECTION_KEYS.includes(key)) probe.invalidate();
803
771
  }
804
772
 
805
773
  /**
@@ -819,21 +787,13 @@ export function SetupScreen({
819
787
  result: ConnectionTest;
820
788
  derived: Record<string, string>;
821
789
  }> {
822
- const epoch = connectionEpoch.current;
823
- const result = await testConnection(draft);
824
- // Read the answer BEFORE storing it, so a response that is not one at all
825
- // throws to the caller (which treats that as "could not ask") instead of
826
- // parking a value in state that every reader downstream has to defend
827
- // against.
790
+ // The result describes the connection values as they were when the
791
+ // request left. Edited while it was out, it is stale: the probe never
792
+ // shows it, and it comes back to the caller, whose payload is the same
793
+ // snapshot. `derived` is likewise computed against that snapshot, because
794
+ // it travels with the payload.
795
+ const { result, stale } = await probe.ask(draft);
828
796
  const suggested = result.ok ? suggestedBranch(result) : null;
829
- // The result describes the connection values captured above. If they were
830
- // edited while the request was in flight, showing it would let the OLD
831
- // values' success (or failure) stand in for the new ones — so it is
832
- // returned to the caller, whose payload is the same snapshot, but never
833
- // shown. `derived` is likewise computed against that snapshot, because it
834
- // travels with the payload.
835
- const stale = epoch !== connectionEpoch.current;
836
- if (!stale) setTest(result);
837
797
  const derived: Record<string, string> = {};
838
798
  if (suggested) {
839
799
  if (!resolved('defaultBranch')) derived.defaultBranch = suggested;
@@ -854,9 +814,7 @@ export function SetupScreen({
854
814
  }
855
815
 
856
816
  async function runTest() {
857
- setTesting(true);
858
817
  setError(null);
859
- const epoch = connectionEpoch.current;
860
818
  try {
861
819
  await probeConnection();
862
820
  } catch (err) {
@@ -864,11 +822,9 @@ export function SetupScreen({
864
822
  // was edited while this request was out, the error describes values no
865
823
  // longer on screen, and showing it would complain about something the
866
824
  // reader already changed.
867
- if (epoch === connectionEpoch.current) {
825
+ if (!(err instanceof ConnectionProbeFailed) || !err.stale) {
868
826
  setError(err instanceof Error ? err.message : 'Could not test the connection.');
869
827
  }
870
- } finally {
871
- setTesting(false);
872
828
  }
873
829
  }
874
830
 
@@ -971,7 +927,7 @@ export function SetupScreen({
971
927
  setSyncResult({
972
928
  ok: false,
973
929
  results: [],
974
- error: err instanceof Error ? err.message : 'Could not sync.',
930
+ error: err instanceof Error ? err.message : 'Couldn’t get the latest changes.',
975
931
  });
976
932
  } finally {
977
933
  setSyncing(false);
@@ -990,7 +946,7 @@ export function SetupScreen({
990
946
  <Surface tone="surface" radius="md" className="mt-3 space-y-3 border border-line p-3">
991
947
  <div className="space-y-1.5">
992
948
  <span className="text-meta font-medium text-ink">Address for the hook</span>
993
- <CopyValue value={`${sync.url}/<branch>`} label="Copy the sync address" />
949
+ <CopyValue value={`${sync.url}/<branch>`} label="Copy the hook address" />
994
950
  <p className="text-meta text-ink-faint">
995
951
  Replace <code className="font-mono">&lt;branch&gt;</code> with the branch that changed;
996
952
  send the secret as a bearer token.
@@ -1000,8 +956,8 @@ export function SetupScreen({
1000
956
  <div className="space-y-2">
1001
957
  <p role="status" className="text-meta text-ink-muted">
1002
958
  {last
1003
- ? `Last sync ${new Date(last.at).toLocaleString()} by ${last.by}: ${describeOutcomes(last.results)}.`
1004
- : 'No sync since this server started.'}
959
+ ? `Last update ${new Date(last.at).toLocaleString()} by ${last.by}: ${describeOutcomes(last.results)}.`
960
+ : 'No updates since this server started.'}
1005
961
  </p>
1006
962
  <div className="flex flex-wrap items-center gap-3">
1007
963
  <Button
@@ -1011,11 +967,10 @@ export function SetupScreen({
1011
967
  onClick={() => void runSync()}
1012
968
  disabled={syncing}
1013
969
  >
1014
- {syncing ? 'Syncing…' : 'Sync now'}
970
+ {syncing ? 'Updating…' : 'Update now'}
1015
971
  </Button>
1016
972
  <span className="text-meta text-ink-faint">
1017
- Pulls every branch from the repository with your own session — the same thing the
1018
- hook does.
973
+ Gets the latest changes from your git host now, the same as the hook does.
1019
974
  </span>
1020
975
  </div>
1021
976
  {syncResult && (
@@ -1028,12 +983,12 @@ export function SetupScreen({
1028
983
  {syncResult.error
1029
984
  ? syncResult.error
1030
985
  : syncResult.ok
1031
- ? `Synced: ${describeOutcomes(syncResult.results)}.`
986
+ ? `Updated: ${describeOutcomes(syncResult.results)}.`
1032
987
  : (syncResult.results
1033
988
  .map(syncOutcomeError)
1034
989
  .filter((e): e is string => !!e)
1035
990
  .join('\n') ||
1036
- `Not fully synced: ${describeOutcomes(syncResult.results)}.`)}
991
+ `Not fully updated: ${describeOutcomes(syncResult.results)}.`)}
1037
992
  </p>
1038
993
  )}
1039
994
  </div>
@@ -1107,7 +1062,7 @@ export function SetupScreen({
1107
1062
  /** What the host said this time, or null when it could not be asked. */
1108
1063
  let proven: ConnectionTest | null = test;
1109
1064
  let probed = false;
1110
- const probe = async () => {
1065
+ const prove = async () => {
1111
1066
  probed = true;
1112
1067
  try {
1113
1068
  const { result, derived } = await probeConnection();
@@ -1128,9 +1083,7 @@ export function SetupScreen({
1128
1083
  // host rejects finishes setup just as well as one it accepts, and the
1129
1084
  // gate opens onto an app whose every call fails against a repository
1130
1085
  // it cannot clone. This is the one moment that can tell the two apart.
1131
- setTesting(true);
1132
- await probe();
1133
- setTesting(false);
1086
+ await prove();
1134
1087
  // Includes a probe the server REFUSED (a 4xx comes back as a
1135
1088
  // rejection, not a throw) — that is an answer about these values.
1136
1089
  if (proven && !proven.ok) {
@@ -1163,7 +1116,7 @@ export function SetupScreen({
1163
1116
  !!resolvedIn(payload, 'kbRepoUrl') &&
1164
1117
  (!resolvedIn(payload, 'defaultBranch') || !resolvedIn(payload, 'protectedBranches'))
1165
1118
  ) {
1166
- await probe();
1119
+ await prove();
1167
1120
  }
1168
1121
  // An ordinary save is sent exactly as it always was — one argument, and
1169
1122
  // no `confirmRepositoryChange` in the body. Only the save that answers
@@ -1298,42 +1251,6 @@ export function SetupScreen({
1298
1251
  );
1299
1252
  }
1300
1253
 
1301
- /**
1302
- * Under the guide's name, once it is no longer `AGENTS.md`: the exact
1303
- * sentence the platform would add to the customer's own `AGENTS.md`, and the
1304
- * consent to keep it there.
1305
- *
1306
- * Shown ONLY while the name differs, because that is the only time there is
1307
- * anything to point at — under the default name the guide IS `AGENTS.md`.
1308
- * The sentence is rendered by the same helper the server appends with, so
1309
- * what the admin reads here is what lands in their file, character for
1310
- * character.
1311
- */
1312
- function renderAgentsFileLink() {
1313
- const name = resolved('agentsFile') || DEFAULT_KB_LAYOUT.agentsFile;
1314
- if (name === DEFAULT_KB_LAYOUT.agentsFile) return null;
1315
- // Unset means on: the server reads an unanswered setting the same way.
1316
- const on = (draft[AGENTS_LINK_KEY] ?? settings.find((s) => s.key === AGENTS_LINK_KEY)?.value ?? 'true') !== 'false';
1317
- return (
1318
- <div className="mt-2 space-y-2" data-testid="agents-file-link">
1319
- <label className="flex cursor-pointer select-none items-start gap-2 text-detail text-ink">
1320
- <input
1321
- type="checkbox"
1322
- className="mt-0.5"
1323
- checked={on}
1324
- onChange={(e) => set(AGENTS_LINK_KEY, e.target.checked ? 'true' : 'false')}
1325
- />
1326
- <span>Keep a pointer to {name} in your own AGENTS.md</span>
1327
- </label>
1328
- <CopyValue value={agentsFilePointerSentence(name)} label="Copy the pointer sentence" />
1329
- <p className="text-meta text-ink-faint">
1330
- While this is ticked, every start looks for “{name}” in your AGENTS.md and adds the
1331
- sentence at the end when it is not there — in your own words counts too. Nothing is added
1332
- if you have no AGENTS.md, and no file is ever created for it. Untick it to stop.
1333
- </p>
1334
- </div>
1335
- );
1336
- }
1337
1254
 
1338
1255
  function renderField(setting: SettingStatus) {
1339
1256
  const copy = FIELDS[setting.key];
@@ -1345,6 +1262,31 @@ export function SetupScreen({
1345
1262
  : isFolderField
1346
1263
  ? (remoteRootFolders ?? []).filter(isRootFolderSuggestion)
1347
1264
  : [];
1265
+ if (copy.toggle) {
1266
+ const raw = draft[setting.key] ?? setting.value ?? '';
1267
+ const checked = raw === '' ? copy.toggle.on : raw !== 'false';
1268
+ return (
1269
+ <div key={setting.key}>
1270
+ <label className="flex items-start gap-2">
1271
+ <input
1272
+ type="checkbox"
1273
+ className="mt-1"
1274
+ checked={checked}
1275
+ onChange={(e) => set(setting.key, e.target.checked ? 'true' : 'false')}
1276
+ aria-invalid={problems[setting.key] ? true : undefined}
1277
+ aria-describedby={problems[setting.key] ? `${setting.key}-problem` : undefined}
1278
+ />
1279
+ <span className="text-detail font-medium text-ink">{copy.label}</span>
1280
+ </label>
1281
+ <p className="mt-1 text-meta text-ink-faint">{copy.help}</p>
1282
+ {problems[setting.key] && (
1283
+ <p id={`${setting.key}-problem`} role="alert" className="mt-1 text-meta text-danger">
1284
+ {problems[setting.key]}
1285
+ </p>
1286
+ )}
1287
+ </div>
1288
+ );
1289
+ }
1348
1290
  const listId = suggestions.length > 0 ? `${setting.key}-options` : undefined;
1349
1291
  return (
1350
1292
  <div key={setting.key}>
@@ -1374,7 +1316,6 @@ export function SetupScreen({
1374
1316
  )}
1375
1317
  <p className="mt-1 text-meta text-ink-faint">{copy.help}</p>
1376
1318
  {isRootFolderKey(setting.key) && renderRootFolderState(setting.key)}
1377
- {setting.key === 'agentsFile' && renderAgentsFileLink()}
1378
1319
  {setting.key === 'kbSyncSecret' && renderSyncPanel()}
1379
1320
  {/* Only AFTER setup: on first run there is nothing yet to lose, so
1380
1321
  the caution would be noise. Once a deployment is live, this field
@@ -1758,11 +1699,10 @@ export function SetupScreen({
1758
1699
  )}
1759
1700
  </SectionFields>
1760
1701
 
1761
- {/* The layout: the three root folders and the agent guide's
1762
- file name, in the main section, directly under the test
1763
- whose listing the folders are checked against — the
1764
- connection fields above it stay next to the button that
1765
- proves them. */}
1702
+ {/* The layout: the three root folders, in the main section,
1703
+ directly under the test whose listing they are checked
1704
+ against — the connection fields above it stay next to the
1705
+ button that proves them. */}
1766
1706
  {fields.filter((f) => isLayoutKey(f.key)).map((f) => renderField(f))}
1767
1707
 
1768
1708
  {/* Everything a normal setup never touches, out of the way but
@@ -1799,7 +1739,7 @@ export function SetupScreen({
1799
1739
  {/* The sync panel normally hangs off the secret's field. When
1800
1740
  the secret comes from the environment that field is in the
1801
1741
  locked list below, not here — but the address, the last
1802
- sync and Sync now are about the deployment, not the secret,
1742
+ update and Update now are about the deployment, not the secret,
1803
1743
  and an admin with an env-set secret needs them just as much. */}
1804
1744
  {section.id === 'knowledge-base' &&
1805
1745
  sync &&
@@ -1819,10 +1759,10 @@ export function SetupScreen({
1819
1759
  gets its own place here in that case. */}
1820
1760
  {sync && editable.every((s) => s.section !== 'knowledge-base') && (
1821
1761
  <Surface as="section" tone="surface" radius="lg" elevation="card" className="p-6">
1822
- <h2 className="text-title font-semibold text-ink">Repository sync</h2>
1762
+ <h2 className="text-title font-semibold text-ink">Updates from your git host</h2>
1823
1763
  <p className="mt-1 max-w-[60ch] text-detail text-ink-muted">
1824
- The knowledge-base connection is set by the environment. The sync hook is still
1825
- yours to wire up and check on here.
1764
+ The knowledge-base connection is set by the environment. The hook that brings in
1765
+ updates from your git host is still yours to wire up and check on here.
1826
1766
  </p>
1827
1767
  {renderSyncPanel()}
1828
1768
  </Surface>
@@ -1877,8 +1817,8 @@ export function SetupScreen({
1877
1817
  <p className="mt-1">
1878
1818
  The move happens as soon as you confirm, with no restart. Unless the new repository holds the
1879
1819
  same history, every working copy on this server stops being used and is cloned fresh from the
1880
- new repository. Anything committed here and not
1881
- yet pushed from this server goes out of the app with it. Nothing is deleted, but it is only
1820
+ new repository. Anything saved here that hasn’t reached your git host yet goes out of
1821
+ the app with it. Nothing is deleted, but it is only
1882
1822
  recoverable from the
1883
1823
  <code className="mx-1">replaced-working-copies</code>
1884
1824
  folder on the server, by hand.
@@ -0,0 +1,93 @@
1
+ import { useRef, useState } from 'react';
2
+ import { testConnection, type ConnectionTest } from '../services/setup.api';
3
+
4
+ /**
5
+ * The connection test, as every screen that asks it keeps it: the first-run
6
+ * storage screen and the full form. ONE mechanism for what a test needs
7
+ * beyond the request itself — what the host last said about the answers ON
8
+ * SCREEN; that editing one of those answers invalidates it; that an answer
9
+ * landing after such an edit is stale, evidence about values no longer there,
10
+ * and is never shown as if it were about the new ones; and whether a save may
11
+ * lean on the answer on screen instead of asking again — so no two screens
12
+ * can drift on any of them.
13
+ */
14
+
15
+ /** The request itself failed: the endpoint is down, the request threw. Not an answer about the credentials. */
16
+ export class ConnectionProbeFailed extends Error {
17
+ /** The answers were edited while the request was out: the failure describes values no longer on screen. */
18
+ readonly stale: boolean;
19
+
20
+ constructor(message: string, stale: boolean) {
21
+ super(message);
22
+ this.name = 'ConnectionProbeFailed';
23
+ this.stale = stale;
24
+ }
25
+ }
26
+
27
+ export interface ConnectionProbe {
28
+ /** What the host said about the answers on screen: null until asked, and again after any edit to them. */
29
+ result: ConnectionTest | null;
30
+ /** A request is out. */
31
+ testing: boolean;
32
+ /** The host said yes about the answers on screen: a save may lean on it without asking again. */
33
+ proven: boolean;
34
+ /**
35
+ * An answer the test proves was edited. The result on screen described the
36
+ * old answers and goes; a request still out will land stale.
37
+ */
38
+ invalidate(): void;
39
+ /**
40
+ * Ask the host about `answers`. Resolves to the host's answer — a refusal is
41
+ * an answer — and whether it is `stale`: the answers were edited, or a newer
42
+ * request went out, while this one was out, so the answer on screen is not
43
+ * this one's to set. A stale answer is not shown; it is the caller's to use
44
+ * only against the snapshot it sent. Rejects with
45
+ * {@link ConnectionProbeFailed} when the request itself failed, flagged
46
+ * stale the same way.
47
+ */
48
+ ask(answers: Record<string, string>): Promise<{ result: ConnectionTest; stale: boolean }>;
49
+ }
50
+
51
+ export function useConnectionProbe(): ConnectionProbe {
52
+ const [result, setResult] = useState<ConnectionTest | null>(null);
53
+ const [testing, setTesting] = useState(false);
54
+ /**
55
+ * Which set of answers is on screen, bumped on every edit to one of them.
56
+ * An answer carries the epoch its request left under; a different one by
57
+ * the time it lands means the answers it describes are gone.
58
+ */
59
+ const epoch = useRef(0);
60
+ /**
61
+ * Which request is the newest. Two requests for the same answers can land
62
+ * in either order; only the newest one's answer is the answer on screen,
63
+ * or an older response would overwrite a newer one.
64
+ */
65
+ const newest = useRef(0);
66
+ const inFlight = useRef(0);
67
+
68
+ const invalidate = () => {
69
+ epoch.current++;
70
+ setResult(null);
71
+ };
72
+
73
+ const ask = async (answers: Record<string, string>) => {
74
+ const asked = epoch.current;
75
+ const request = ++newest.current;
76
+ const isStale = () => asked !== epoch.current || request !== newest.current;
77
+ inFlight.current++;
78
+ setTesting(true);
79
+ try {
80
+ const answer = await testConnection(answers);
81
+ const stale = isStale();
82
+ if (!stale) setResult(answer);
83
+ return { result: answer, stale };
84
+ } catch (err) {
85
+ throw new ConnectionProbeFailed(err instanceof Error ? err.message : 'Could not test the connection.', isStale());
86
+ } finally {
87
+ inFlight.current--;
88
+ if (inFlight.current === 0) setTesting(false);
89
+ }
90
+ };
91
+
92
+ return { result, testing, proven: result?.ok === true, invalidate, ask };
93
+ }
@@ -235,7 +235,7 @@ async function readError(res: Response): Promise<never> {
235
235
  const SYNC_RESPONSE_HEADER = 'x-hexis-sync';
236
236
  const SYNC_RESPONSE_MARKER = 'result';
237
237
 
238
- /** What "Sync now" came back with. A 409 or 503 still carries per-branch results. */
238
+ /** What "Update now" came back with. A 409 or 503 still carries per-branch results. */
239
239
  export interface SyncNowResult {
240
240
  /** True for 200 — every branch current. */
241
241
  ok: boolean;
@@ -267,11 +267,11 @@ export async function syncNow(): Promise<SyncNowResult> {
267
267
  try {
268
268
  body = await res.json();
269
269
  } catch {
270
- throw new Error(`Sync failed (${res.status})`);
270
+ throw new Error(`Couldn’t get the latest changes (${res.status})`);
271
271
  }
272
272
  const data = body as { status?: 'synced' | 'partial'; results?: SyncBranchOutcome[]; error?: string };
273
273
  if (!Array.isArray(data.results)) {
274
- return { ok: false, results: [], error: data.error || `Sync failed (${res.status})` };
274
+ return { ok: false, results: [], error: data.error || `Couldn’t get the latest changes (${res.status})` };
275
275
  }
276
276
  return { ok: res.status === 200, status: data.status, results: data.results };
277
277
  }
@@ -0,0 +1,27 @@
1
+ import type { ConnectionTest } from '../services/setup.api';
2
+
3
+ /**
4
+ * Which branch the repository just named, or the best conventional stand-in.
5
+ *
6
+ * Prefer what the remote calls its trunk. Not every host advertises it —
7
+ * older servers answer `ls-remote` without the symref line — so fall back to
8
+ * the conventional names before the first branch it did list. Leaving these
9
+ * blank is the one way a save can succeed and still not finish setup, which
10
+ * is worth a guess the reader can see and correct.
11
+ *
12
+ * An EMPTY repository has no branch to report, but it will be seeded with
13
+ * whatever is configured, so the conventional name is the right suggestion.
14
+ * Suggesting nothing was the one way "Connected" could still end, silently,
15
+ * in a save that did not finish setup.
16
+ *
17
+ * ONE function for every screen that tests a connection, because two copies
18
+ * of "which branch did it name?" is how two answers drift apart.
19
+ */
20
+ export function suggestedBranch(result: ConnectionTest): string | null {
21
+ return (
22
+ result.defaultBranch ||
23
+ ['main', 'master', 'trunk'].find((name) => result.branches?.includes(name)) ||
24
+ result.branches?.[0] ||
25
+ (result.empty ? 'main' : null)
26
+ );
27
+ }