@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
@@ -17,8 +17,11 @@ import { approvePrFile, revertPrFile, unapprovePrFile } from '../../pr/services/
17
17
  import { deleteChangeRequest } from '../../pr/services/pr-cancel.api';
18
18
  import { refreshChangeRequestFromTarget } from '../../pr/services/pr-merge.api';
19
19
  import { GitApiError } from '../../git/services/git.api';
20
+ import { friendlyGitError, friendlyGitMessage } from '../../git/services/error-messages';
21
+ import { GitSyncFailedBanner } from '../../git/components/GitSyncFailedBanner';
20
22
  import { useApplyChangeRequest } from '../hooks/useApplyChangeRequest';
21
23
  import { readFileOnBranch } from '../services/change-requests.api';
24
+ import { WorkspaceApiError } from '../../workspace/services/workspace.api';
22
25
  import { describeReadFailure } from '../services/denied-file.api';
23
26
  import { deniedSentence, readErrorLead, type ReadFailure } from '../utils/readFailure';
24
27
  import { changeAuthorName } from '../utils/author';
@@ -237,6 +240,16 @@ export function ChangeRequestDialog({
237
240
  };
238
241
  }, [bus, cr.number]);
239
242
 
243
+ // The request's verbs (revert, update) push its SOURCE branch, which is
244
+ // rarely the branch in the address bar. Watch that workspace while the
245
+ // dialog is open, so a push the host refuses raises the sync banner here —
246
+ // and the push that later lands clears it here.
247
+ const sourceWorkspaceId = encodeURIComponent(cr.branch);
248
+ useEffect(() => {
249
+ if (!bus) return;
250
+ return bus.watchWorkspace(sourceWorkspaceId);
251
+ }, [bus, sourceWorkspaceId]);
252
+
240
253
  // EVERYTHING is repo-relative, scoped or not — the scope's baseFiles are
241
254
  // lifted to full paths, and every touched file lists whatever folder it is
242
255
  // in. The dialog is a decision about the WHOLE request; a file it touches
@@ -337,22 +350,35 @@ export function ChangeRequestDialog({
337
350
  const token = {};
338
351
  asked.current.set(selected, token);
339
352
  const current = () => asked.current.get(selected) === token;
353
+ const removes = detail.files.some((f) => f.path === selected && f.status === 'removed');
340
354
  readFileOnBranch(cr.branch, selected)
341
355
  .then((content) => {
342
356
  if (current()) setBranchContents((c) => ({ ...c, [selected]: content }));
343
357
  })
344
- // NOT `''`. An unreadable branch copy stored as empty would diff as
345
- // "every line deleted" — a change request that erases the file.
346
- //
347
- // The failure is described before it is published: naming the folder
348
- // to ask about is a second read, and the pane stays on "Loading…"
349
- // until it settles rather than saying "couldn't be read" and then
350
- // rewriting it as "you don't have access" a moment later.
351
- .catch((err: unknown) =>
352
- describeReadFailure(err, cr.branch, selected).then((failure) => {
358
+ .catch((err: unknown) => {
359
+ if (!current()) return;
360
+ // A file the request REMOVES is not on its branch, and the FILE read
361
+ // says so with a 404. That is the proposal, not a failed read: the
362
+ // branch copy is empty, and the current copy diffs against it as
363
+ // every line deleted — the same rule the diff boxes apply. A branch
364
+ // that could not be opened is not a `WorkspaceApiError` here
365
+ // (`readFileOnBranch` answers that apart), so it stays a failure.
366
+ if (removes && err instanceof WorkspaceApiError && err.status === 404) {
367
+ setBranchContents((c) => ({ ...c, [selected]: '' }));
368
+ return;
369
+ }
370
+ // Anything else is NOT `''`. An unreadable branch copy stored as
371
+ // empty would diff as "every line deleted" — a change request that
372
+ // erases the file.
373
+ //
374
+ // The failure is described before it is published: naming the
375
+ // folder to ask about is a second read, and the pane stays on
376
+ // "Loading…" until it settles rather than saying "couldn't be read"
377
+ // and then rewriting it as "you don't have access" a moment later.
378
+ void describeReadFailure(err, cr.branch, selected).then((failure) => {
353
379
  if (current()) setBranchFailure((m) => new Map(m).set(selected, failure));
354
- }),
355
- );
380
+ });
381
+ });
356
382
  }
357
383
  }, [selected, selectedIsBinary, cr.branch, branchRevision, detail]);
358
384
 
@@ -674,7 +700,7 @@ export function ChangeRequestDialog({
674
700
  : await approvePrFile(cr.number, path);
675
701
  setDetail((d) => (d ? { ...d, approvals } : d));
676
702
  } catch (err) {
677
- setVerbError(err instanceof Error ? err.message : "Couldn't record that.");
703
+ setVerbError(err instanceof Error ? friendlyGitError(err) : "Couldn't record that.");
678
704
  } finally {
679
705
  setVerbBusy(false);
680
706
  }
@@ -696,7 +722,7 @@ export function ChangeRequestDialog({
696
722
  setDetail((d) => (d ? { ...d, approvals } : d));
697
723
  }
698
724
  } catch (err) {
699
- setVerbError(err instanceof Error ? err.message : "Couldn't record that.");
725
+ setVerbError(err instanceof Error ? friendlyGitError(err) : "Couldn't record that.");
700
726
  } finally {
701
727
  setVerbBusy(false);
702
728
  }
@@ -1088,6 +1114,10 @@ export function ChangeRequestDialog({
1088
1114
  )}
1089
1115
  </p>
1090
1116
 
1117
+ <div className="mx-8 mt-4 empty:hidden overflow-hidden rounded-lg">
1118
+ <GitSyncFailedBanner workspaceId={sourceWorkspaceId} />
1119
+ </div>
1120
+
1091
1121
  {error && (
1092
1122
  <Banner tone="danger" role="alert" className="mx-8 mt-4">
1093
1123
  {error}
@@ -1104,7 +1134,7 @@ export function ChangeRequestDialog({
1104
1134
  ? `${detail.lastApplyFailure.byName} could not apply this`
1105
1135
  : 'The last apply did not land'}
1106
1136
  </b>
1107
- : {detail.lastApplyFailure.reason}
1137
+ : {friendlyGitMessage(detail.lastApplyFailure.reason)}
1108
1138
  </Banner>
1109
1139
  )}
1110
1140
 
@@ -1374,7 +1404,7 @@ export function ChangeRequestDialog({
1374
1404
  ? `Your approval is needed on ${mine.length} file${mine.length === 1 ? '' : 's'}`
1375
1405
  : waitingOn.length > 0
1376
1406
  ? `Waiting on ${waitingOn.join(', ')}`
1377
- : (detail.mergeWarnings[0] ??
1407
+ : ((detail.mergeWarnings[0] && friendlyGitMessage(detail.mergeWarnings[0])) ??
1378
1408
  'Waiting on approval from the files’ owners — applying is theirs to do.')}
1379
1409
  </p>
1380
1410
  {mine.length > 1 && (
@@ -0,0 +1,151 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { Link, useNavigate, useParams } from 'react-router-dom';
3
+ import type { PullRequestSummary } from '@bevel-software/platform-shared';
4
+ import { getPullRequest } from '../../git/services/pr.api';
5
+ import { GitApiError } from '../../git/services/git.api';
6
+ import { KB_ROUTE_PREFIX } from '../../workspace/routing/kb-routes';
7
+ import { ChangeRequestDialog } from './ChangeRequestDialog';
8
+
9
+ /**
10
+ * `/change-requests/<number>` — the link a person is handed for a change
11
+ * request: by `open_change_request` and the change-request read tools (the
12
+ * `url` on every summary), and by anything else that uses the backend's
13
+ * change-request-link helper. The backend has built that address since the
14
+ * link became absolute, and no route ever matched it: the shell's catch-all
15
+ * sent it to the workspace with nothing open and no word about why, so an
16
+ * agent's "here is the request" link opened nothing.
17
+ *
18
+ * What it opens is THE change-request view — {@link ChangeRequestDialog},
19
+ * the same one the explorer and the skill page open — over a quiet page, on
20
+ * the request's first changed file. Closing it, or applying the request,
21
+ * goes to the workspace: there is nothing under the dialog to go back to.
22
+ *
23
+ * A number that is not one, a request that is not there, and one the
24
+ * viewer may not see all read the same way: there is no request at this
25
+ * address for them, and which of the three it is would tell a person who
26
+ * may not see a request that it exists. Any other failure keeps its own
27
+ * message, since it is the platform's, not the link's.
28
+ */
29
+ export function ChangeRequestLink() {
30
+ const { number: raw } = useParams();
31
+ const number = changeRequestNumber(raw);
32
+ // Keyed by the number: the router reuses this element across a change of
33
+ // the parameter, and a lookup that had resolved would otherwise keep the
34
+ // previous request on screen under the new address until the new fetch
35
+ // settled. A new number is a fresh lookup from "loading".
36
+ return number === null ? (
37
+ <NoSuchRequest raw={raw ?? ''} />
38
+ ) : (
39
+ <OpenRequest key={number} number={number} />
40
+ );
41
+ }
42
+
43
+ /** The largest number a request can have: the database sequence is a 32-bit integer. */
44
+ const MAX_CHANGE_REQUEST_NUMBER = 2_147_483_647;
45
+
46
+ /** A positive integer, spelled plainly — the only thing the link helper ever puts in the path. */
47
+ function changeRequestNumber(raw: string | undefined): number | null {
48
+ if (!raw || !/^[1-9]\d*$/.test(raw)) return null;
49
+ const number = Number(raw);
50
+ return number <= MAX_CHANGE_REQUEST_NUMBER ? number : null;
51
+ }
52
+
53
+ type Lookup =
54
+ | { kind: 'loading' }
55
+ | { kind: 'open'; cr: PullRequestSummary }
56
+ | { kind: 'missing' }
57
+ | { kind: 'failed'; message: string };
58
+
59
+ function OpenRequest({ number }: { number: number }) {
60
+ const navigate = useNavigate();
61
+ const [lookup, setLookup] = useState<Lookup>({ kind: 'loading' });
62
+
63
+ useEffect(() => {
64
+ let cancelled = false;
65
+ getPullRequest(number).then(
66
+ (cr) => {
67
+ if (!cancelled) setLookup({ kind: 'open', cr });
68
+ },
69
+ (err: unknown) => {
70
+ if (cancelled) return;
71
+ // Not there. A 403 takes the same path for a deployment whose summary
72
+ // route is viewer-scoped; core's is not — every member sees the
73
+ // request list, and the FILES behind a request are what access rules
74
+ // gate, in the detail the dialog then reads — so the same sentence
75
+ // serves both and the address never says which.
76
+ const hidden = err instanceof GitApiError && (err.status === 404 || err.status === 403);
77
+ setLookup(
78
+ hidden
79
+ ? { kind: 'missing' }
80
+ : { kind: 'failed', message: err instanceof Error ? err.message : String(err) },
81
+ );
82
+ },
83
+ );
84
+ return () => {
85
+ cancelled = true;
86
+ };
87
+ }, [number]);
88
+
89
+ // `replace`: the link's entry leaves history with the view, so Back after
90
+ // closing does not land on the address again and reopen the request.
91
+ const leave = () => navigate(KB_ROUTE_PREFIX, { replace: true });
92
+
93
+ if (lookup.kind === 'missing') return <NoSuchRequest raw={String(number)} />;
94
+ if (lookup.kind === 'failed') {
95
+ return (
96
+ <Quiet>
97
+ <p>Change request #{number} could not be opened: {lookup.message}</p>
98
+ <BackToKnowledge />
99
+ </Quiet>
100
+ );
101
+ }
102
+ return (
103
+ <>
104
+ <Quiet>
105
+ <p>{lookup.kind === 'loading' ? `Opening change request #${number}…` : lookup.cr.title}</p>
106
+ <BackToKnowledge />
107
+ </Quiet>
108
+ {lookup.kind === 'open' && (
109
+ <ChangeRequestDialog cr={lookup.cr} onClose={leave} onResolved={leave} />
110
+ )}
111
+ </>
112
+ );
113
+ }
114
+
115
+ function NoSuchRequest({ raw }: { raw: string }) {
116
+ return (
117
+ <Quiet>
118
+ <p>
119
+ There is no change request {raw ? `#${raw}` : 'at this address'} — it does not exist, or
120
+ you may not see it.
121
+ </p>
122
+ <BackToKnowledge />
123
+ </Quiet>
124
+ );
125
+ }
126
+
127
+ /**
128
+ * The page under the dialog: a sentence and a way out, nothing to be read as
129
+ * content. A landmark with a heading all the same, and the sentence in a
130
+ * live region: somebody arriving by the address, or by keyboard, is told what
131
+ * page this is and hears the state change from "opening" to the request.
132
+ */
133
+ function Quiet({ children }: { children: React.ReactNode }) {
134
+ return (
135
+ <main className="flex h-full flex-col items-center justify-center gap-2 bg-white text-sm text-ink-muted">
136
+ <h1 className="text-base font-semibold text-ink">Change request</h1>
137
+ <div aria-live="polite" className="contents">
138
+ {children}
139
+ </div>
140
+ </main>
141
+ );
142
+ }
143
+
144
+ /** The way out of the quiet page. `replace`, like the dialog's exits: the link's entry leaves with the page. */
145
+ function BackToKnowledge() {
146
+ return (
147
+ <Link to={KB_ROUTE_PREFIX} replace className="underline hover:text-ink">
148
+ Back to the knowledge base
149
+ </Link>
150
+ );
151
+ }
@@ -13,6 +13,7 @@ import {
13
13
  import type { FileApprovalState, PrFileStatus } from '@bevel-software/platform-shared';
14
14
  import { cn } from '../../../lib/utils';
15
15
  import { hasOwnApproval } from '../utils/approval';
16
+ import { displayFileName } from '../../workspace/utils/display-file-name';
16
17
 
17
18
  /**
18
19
  * The change request's files as a TREE — the Knowledge sidebar's visual
@@ -205,7 +206,7 @@ function Level({
205
206
  );
206
207
  })}
207
208
  {folder.files.map((file) => {
208
- const name = file.path.slice(file.path.lastIndexOf('/') + 1);
209
+ const name = displayFileName(file.path);
209
210
  const on = selected === file.path;
210
211
  const eligible = file.changed && file.approval?.viewerCanApprove === true;
211
212
  // The viewer's own state wins the slot when there is one: approved
@@ -11,6 +11,7 @@ import { conflictResolutionPrompt } from '../utils/conflict';
11
11
  import { isBinaryFile } from '../../workspace/components/renderers';
12
12
  import { ChangeBox } from './ChangeBox';
13
13
  import { ChangeRequestDialog } from './ChangeRequestDialog';
14
+ import { displayFileName, fileNameTooltip } from '../../workspace/utils/display-file-name';
14
15
 
15
16
  export interface FileChangeBoxesProps {
16
17
  /** Repo-root-relative path of the open file (kbDirName stripped). */
@@ -105,7 +106,7 @@ export function FileChangeBoxes({
105
106
  {applied && (
106
107
  <Banner role="status" tone="ok" aria-live="polite" className="mt-3">
107
108
  <div className="flex items-center gap-2">
108
- <span className="flex-1">Applied: the file now reads with that change.</span>
109
+ <span className="flex-1">Published: the file now reads with that change.</span>
109
110
  <Button variant="quiet" size="sm" title="Dismiss" onClick={() => setApplied(false)}>
110
111
  Dismiss
111
112
  </Button>
@@ -128,7 +129,8 @@ export function FileChangeBoxes({
128
129
  return (
129
130
  <ChangeBox
130
131
  key={cr.number}
131
- file={repoRelativePath.slice(repoRelativePath.lastIndexOf('/') + 1)}
132
+ file={displayFileName(repoRelativePath)}
133
+ fileTitle={fileNameTooltip(repoRelativePath)}
132
134
  author={changeAuthorName(cr)}
133
135
  when={formatWhen(cr.createdAt)}
134
136
  mine={mine}
@@ -4,6 +4,7 @@ import { useEventBus } from '../../workflow/state/event-bus.context';
4
4
  import { fetchPrDetail } from '../../pr/services/pr-detail.api';
5
5
  import { approvePrFile } from '../../pr/services/pr-approvals.api';
6
6
  import { mergePullRequest } from '../../pr/services/pr-merge.api';
7
+ import { friendlyGitError, friendlyGitMessage } from '../../git/services/error-messages';
7
8
 
8
9
  /**
9
10
  * Safety net for the async apply: if neither a `change-request-merged` nor a
@@ -45,7 +46,9 @@ export function refusalLine(
45
46
  const own = refusals.get(cr.number);
46
47
  const persisted = cr.lastApplyFailure ?? null;
47
48
  if (own && !isLater(persisted?.at, own.at)) return own.conflicts ? null : own.reason;
48
- return persisted?.reason ?? null;
49
+ // The server stored this one as the gate said it; the reader gets it in the
50
+ // same words the dialog's banner uses.
51
+ return persisted?.reason ? friendlyGitMessage(persisted.reason) : null;
49
52
  }
50
53
 
51
54
  /** True when `a` is a strictly later instant than `b`; unknown is never later. */
@@ -165,7 +168,7 @@ export function useApplyChangeRequest(opts: {
165
168
  const offFailed = bus.subscribe('change-request-merge-failed', (e) => {
166
169
  if (runningRef.current !== e.number) return;
167
170
  fail(e.number, {
168
- reason: e.reason || "Couldn't apply this change.",
171
+ reason: e.reason ? friendlyGitMessage(e.reason) : "Couldn't apply this change.",
169
172
  conflicts: e.conflicts === true,
170
173
  at: e.at,
171
174
  });
@@ -257,7 +260,7 @@ export function useApplyChangeRequest(opts: {
257
260
  // instead of waiting for an event that will never come.
258
261
  if (runningRef.current !== cr.number) return;
259
262
  fail(cr.number, {
260
- reason: err instanceof Error ? err.message : "Couldn't apply this change.",
263
+ reason: err instanceof Error ? friendlyGitError(err) : "Couldn't apply this change.",
261
264
  conflicts: false,
262
265
  });
263
266
  }
@@ -6,6 +6,7 @@ import type {
6
6
  import { authFetch } from '../../../lib/api';
7
7
  import { handleApiResponse } from '../../git/services/git.api';
8
8
  import { getOrCreateWorkspace, readFile } from '../../workspace/services/workspace.api';
9
+ import { BranchUnavailableError } from '../utils/readFailure';
9
10
 
10
11
  /**
11
12
  * The change-request module's data access — the reads every review surface
@@ -70,9 +71,21 @@ export async function removeFolderFromChangeRequests(folder: string): Promise<Fo
70
71
  return data.results;
71
72
  }
72
73
 
73
- /** Read a file from a branch's shared workspace (bootstraps the clone if needed). */
74
+ /**
75
+ * Read a file from a branch's shared workspace (bootstraps the clone if
76
+ * needed). A failure to open the branch is answered as
77
+ * {@link BranchUnavailableError}, never as the file read's own error: both
78
+ * answer 404 for different reasons, and a caller that reads a file-read 404
79
+ * as "the branch has no such file" must not be told that about a branch that
80
+ * could not be opened.
81
+ */
74
82
  export async function readFileOnBranch(branch: string, repoRelativePath: string): Promise<string> {
75
- const { workspace } = await getOrCreateWorkspace(branch);
83
+ let workspace: Awaited<ReturnType<typeof getOrCreateWorkspace>>['workspace'];
84
+ try {
85
+ ({ workspace } = await getOrCreateWorkspace(branch));
86
+ } catch (err: unknown) {
87
+ throw new BranchUnavailableError(branch, err);
88
+ }
76
89
  return readFile(workspace.id, `${workspace.kbDirName}/${repoRelativePath}`);
77
90
  }
78
91
 
@@ -27,6 +27,28 @@ export function statusOf(err: unknown): number | null {
27
27
  return typeof status === 'number' ? status : null;
28
28
  }
29
29
 
30
+ /**
31
+ * A read that never reached the file: opening the BRANCH failed, so nothing
32
+ * was said about the path. Kept apart from the file read's own errors because
33
+ * the two share a status and mean opposite things — a 404 from the file read
34
+ * says "this branch has no such file", which a request that removes the file
35
+ * is exactly expected to answer; a 404 from the branch says the branch itself
36
+ * is gone, which says nothing about the file at all. `status` is the cause's,
37
+ * so a refusal to open the branch still reads as a refusal.
38
+ */
39
+ export class BranchUnavailableError extends Error {
40
+ readonly branch: string;
41
+ readonly cause: unknown;
42
+ readonly status: number | null;
43
+ constructor(branch: string, cause: unknown) {
44
+ super(`the branch ${branch} couldn't be opened (${failureReason(cause)})`);
45
+ this.name = 'BranchUnavailableError';
46
+ this.branch = branch;
47
+ this.cause = cause;
48
+ this.status = statusOf(cause);
49
+ }
50
+ }
51
+
30
52
  /** A read the server refused because the caller may not see the path. */
31
53
  export function isDenial(err: unknown): boolean {
32
54
  return statusOf(err) === 403;
@@ -0,0 +1,74 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import { render, screen, waitFor } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+
5
+ const mocks = vi.hoisted(() => ({
6
+ linkEmbedAccount: vi.fn(),
7
+ auth: {
8
+ user: { id: 'u-1', email: 'alice@bevel.software', name: 'Alice' } as unknown,
9
+ isLoading: false,
10
+ },
11
+ }));
12
+ vi.mock('../services/embed.api', () => ({ linkEmbedAccount: mocks.linkEmbedAccount }));
13
+ vi.mock('../../auth/hooks/useAuthState', () => ({ useAuthState: () => mocks.auth }));
14
+ vi.mock('../../auth/components/LoginScreen', () => ({ LoginScreen: () => <p>Sign in</p> }));
15
+ vi.mock('../../../lib/api', () => ({ getToken: () => 'session-bearer' }));
16
+
17
+ import { EmbedLinkPage } from '../components/EmbedLinkPage';
18
+ import { outsideAccountOf } from '../services/embed-token';
19
+
20
+ /** A token shaped like the server's: only the payload is read, for display. */
21
+ function tokenFor(claims: Record<string, unknown>): string {
22
+ const payload = btoa(JSON.stringify(claims)).replace(/=+$/, '').replace(/\+/g, '-').replace(/\//g, '_');
23
+ return `eyJhbGciOiJIUzI1NiJ9.${payload}.sig`;
24
+ }
25
+
26
+ const TOKEN = tokenFor({ scope: 'embed', kind: 'atlassian', sub: '557058:abc-def', repoRelative: 'Data/x.md' });
27
+
28
+ beforeEach(() => {
29
+ mocks.linkEmbedAccount.mockReset();
30
+ window.history.replaceState({}, '', `/embed/link?token=${TOKEN}`);
31
+ });
32
+
33
+ /**
34
+ * Anybody holding a token for their OWN outside account can craft a link to
35
+ * this page. Followed by a signed-in victim, a silent link would bind the
36
+ * attacker's account to the victim's — so nothing is linked until the person
37
+ * signed in confirms it, seeing both accounts named.
38
+ */
39
+ describe('the account-link page', () => {
40
+ it('links nothing on arrival — it asks first, naming both accounts', async () => {
41
+ render(<EmbedLinkPage />);
42
+ expect(await screen.findByText('Link your Atlassian account?')).toBeTruthy();
43
+ expect(screen.getByText('557058:abc-def')).toBeTruthy();
44
+ expect(screen.getByText('alice@bevel.software')).toBeTruthy();
45
+ expect(mocks.linkEmbedAccount).not.toHaveBeenCalled();
46
+ });
47
+
48
+ it('links when the signed-in person confirms', async () => {
49
+ mocks.linkEmbedAccount.mockResolvedValue(undefined);
50
+ render(<EmbedLinkPage />);
51
+ await userEvent.click(await screen.findByRole('button', { name: 'Link accounts' }));
52
+ await waitFor(() => expect(mocks.linkEmbedAccount).toHaveBeenCalledWith(TOKEN, 'session-bearer'));
53
+ expect(await screen.findByText('Account linked')).toBeTruthy();
54
+ });
55
+
56
+ it('links nothing when they cancel', async () => {
57
+ render(<EmbedLinkPage />);
58
+ await userEvent.click(await screen.findByRole('button', { name: 'Cancel' }));
59
+ expect(await screen.findByText(/Nothing was linked/)).toBeTruthy();
60
+ expect(mocks.linkEmbedAccount).not.toHaveBeenCalled();
61
+ });
62
+ });
63
+
64
+ describe('outsideAccountOf', () => {
65
+ it('reads the outside account a token names', () => {
66
+ expect(outsideAccountOf(TOKEN)).toBe('557058:abc-def');
67
+ });
68
+
69
+ it('answers null for a token minted for a Hexis user, or one it cannot read', () => {
70
+ expect(outsideAccountOf(tokenFor({ kind: 'user', sub: 'u-1' }))).toBeNull();
71
+ expect(outsideAccountOf('not-a-jwt')).toBeNull();
72
+ expect(outsideAccountOf('')).toBeNull();
73
+ });
74
+ });