@bevel-software/platform-core-frontend 0.32.0 → 0.34.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 (207) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +1 -1
  3. package/src/lib/__tests__/api.test.ts +28 -1
  4. package/src/lib/api.ts +4 -2
  5. package/src/modules/access/__tests__/ManageAccessDialog.add-row-picking.test.tsx +53 -1
  6. package/src/modules/access/api.ts +4 -5
  7. package/src/modules/access/components/ManageAccessDialog.tsx +11 -12
  8. package/src/modules/access/hooks/useAccessRequests.ts +1 -1
  9. package/src/modules/access/hooks/useFileAccess.ts +1 -1
  10. package/src/modules/access/index.ts +11 -0
  11. package/src/modules/access/requests.api.ts +1 -1
  12. package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +51 -0
  13. package/src/modules/admin/components/AddMemberInput.tsx +1 -1
  14. package/src/modules/admin/components/DirectoryGroupsPage.tsx +42 -5
  15. package/src/modules/admin/components/UserAccountsPage.tsx +3 -3
  16. package/src/modules/admin/index.ts +7 -0
  17. package/src/modules/admin/services/groups.api.ts +11 -1
  18. package/src/modules/admin/state/admin.context.tsx +1 -1
  19. package/src/modules/agents/__tests__/useConnectAsChoice.test.ts +56 -0
  20. package/src/modules/agents/components/ConnectAsChoice.tsx +81 -0
  21. package/src/modules/agents/connect-as.ts +15 -0
  22. package/src/modules/agents/index.ts +5 -0
  23. package/src/modules/agents/services/agent-choices.api.ts +39 -0
  24. package/src/modules/agents/useConnectAsChoice.ts +66 -0
  25. package/src/modules/audit/__tests__/AuditLogPage.test.tsx +13 -0
  26. package/src/modules/audit/components/AuditEventsPanel.tsx +1 -1
  27. package/src/modules/audit/components/AuditLogPage.tsx +11 -2
  28. package/src/modules/audit/services/audit.api.ts +5 -0
  29. package/src/modules/auth/__tests__/AccountPage.test.tsx +21 -0
  30. package/src/modules/auth/__tests__/account.api.test.ts +69 -0
  31. package/src/modules/auth/components/AccountPage.tsx +8 -2
  32. package/src/modules/auth/index.ts +12 -0
  33. package/src/modules/auth/services/account.api.ts +18 -2
  34. package/src/modules/change-requests/__tests__/ChangeRequestDialog.access-rules.test.tsx +0 -1
  35. package/src/modules/change-requests/__tests__/ChangeRequestDialog.binary.test.tsx +0 -1
  36. package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +0 -1
  37. package/src/modules/change-requests/__tests__/ChangeRequestDialog.edit.test.tsx +166 -0
  38. package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +0 -1
  39. package/src/modules/change-requests/__tests__/ChangeRequestDialog.initial-file.test.tsx +0 -1
  40. package/src/modules/change-requests/__tests__/ChangeRequestDialog.moved.test.tsx +0 -1
  41. package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +0 -1
  42. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +0 -2
  43. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +0 -1
  44. package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +0 -1
  45. package/src/modules/change-requests/components/BranchFilePreview.tsx +4 -12
  46. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +138 -30
  47. package/src/modules/change-requests/components/ChangeRequestLink.tsx +2 -3
  48. package/src/modules/change-requests/components/CrFileTree.tsx +1 -1
  49. package/src/modules/change-requests/components/FileChangeBoxes.tsx +2 -3
  50. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +3 -5
  51. package/src/modules/change-requests/hooks/useCrFileDiffs.ts +1 -1
  52. package/src/modules/change-requests/index.ts +14 -0
  53. package/src/modules/change-requests/services/change-requests.api.ts +2 -2
  54. package/src/modules/change-requests/services/denied-file.api.ts +2 -2
  55. package/src/modules/change-requests/services/propose.api.ts +3 -4
  56. package/src/modules/change-requests/utils/diff.ts +1 -1
  57. package/src/modules/change-requests/utils/readFailure.ts +1 -1
  58. package/src/modules/embed/__tests__/EmbedView.test.tsx +19 -2
  59. package/src/modules/embed/components/EmbedLinkPage.tsx +1 -2
  60. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +0 -14
  61. package/src/modules/git/__tests__/git.api.test.ts +2 -2
  62. package/src/modules/git/components/BranchSwitcher.tsx +3 -4
  63. package/src/modules/git/components/FileHistoryPanel.tsx +2 -2
  64. package/src/modules/git/components/GitSyncFailedBanner.tsx +2 -4
  65. package/src/modules/git/components/HistoryVersionPreview.tsx +4 -15
  66. package/src/modules/git/components/PullNeededBanner.tsx +1 -1
  67. package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +1 -1
  68. package/src/modules/git/hooks/useAutoPullUpdates.ts +1 -1
  69. package/src/modules/git/index.ts +11 -0
  70. package/src/modules/layout/components/MobileChatLayout.tsx +1 -1
  71. package/src/modules/layout/index.ts +9 -0
  72. package/src/modules/library/__tests__/SkillPage.test.tsx +268 -24
  73. package/src/modules/library/__tests__/propose-change.test.ts +75 -0
  74. package/src/modules/library/components/AddToPluginDialog.tsx +1 -1
  75. package/src/modules/library/components/ChangeRequestDock.tsx +1 -1
  76. package/src/modules/library/components/LibraryLayout.tsx +2 -2
  77. package/src/modules/library/components/LibraryPage.tsx +3 -3
  78. package/src/modules/library/components/ManagedPluginRequests.tsx +1 -1
  79. package/src/modules/library/components/NewSkillPanel.tsx +2 -2
  80. package/src/modules/library/components/PersonalAddDialog.tsx +1 -1
  81. package/src/modules/library/components/PersonalPluginPage.tsx +1 -1
  82. package/src/modules/library/components/PluginExtras.tsx +1 -4
  83. package/src/modules/library/components/PluginPage.tsx +1 -1
  84. package/src/modules/library/components/PluginRows.tsx +1 -1
  85. package/src/modules/library/components/SkillsTree.tsx +1 -4
  86. package/src/modules/library/components/plugin-page-parts.tsx +1 -1
  87. package/src/modules/library/components/skill-page/SkillFilePane.tsx +74 -14
  88. package/src/modules/library/components/skill-page/SkillPage.tsx +80 -47
  89. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +2 -4
  90. package/src/modules/library/components/tool-page/ToolVarRow.tsx +2 -2
  91. package/src/modules/library/hooks/useJoinRequests.ts +1 -1
  92. package/src/modules/library/hooks/useLibraryData.ts +3 -3
  93. package/src/modules/library/hooks/useToolPage.ts +1 -1
  94. package/src/modules/library/hooks/useToolSource.ts +1 -1
  95. package/src/modules/library/index.ts +12 -0
  96. package/src/modules/library/routes/LibraryRoutes.tsx +1 -1
  97. package/src/modules/library/routes/WorkspaceItemRoute.tsx +1 -3
  98. package/src/modules/library/routes/library-paths.ts +1 -1
  99. package/src/modules/library/services/library.api.ts +10 -8
  100. package/src/modules/library/services/plugins.api.ts +1 -1
  101. package/src/modules/library/services/teams.api.ts +1 -1
  102. package/src/modules/library/utils/status.ts +2 -2
  103. package/src/modules/onboarding/components/ConnectAgentPill.tsx +1 -1
  104. package/src/modules/onboarding/components/CreatorWelcomePage.tsx +2 -3
  105. package/src/modules/onboarding/components/GetStartedColumn.tsx +6 -13
  106. package/src/modules/onboarding/components/InviteButton.tsx +2 -2
  107. package/src/modules/onboarding/components/InviteDialog.tsx +4 -6
  108. package/src/modules/onboarding/components/RootLanding.tsx +2 -2
  109. package/src/modules/onboarding/components/StarterPackCard.tsx +1 -1
  110. package/src/modules/onboarding/components/WelcomePage.tsx +2 -5
  111. package/src/modules/onboarding/index.ts +10 -0
  112. package/src/modules/onboarding/paths.ts +1 -1
  113. package/src/modules/onboarding/state/agent-connection.ts +2 -2
  114. package/src/modules/onboarding/state/onboarding.ts +1 -1
  115. package/src/modules/onboarding/state/starter-packs.ts +1 -1
  116. package/src/modules/pr/components/OpenChangeRequestDialog.tsx +1 -1
  117. package/src/modules/pr/index.ts +14 -0
  118. package/src/modules/pr/services/pr-approvals.api.ts +1 -1
  119. package/src/modules/pr/services/pr-cancel.api.ts +1 -1
  120. package/src/modules/pr/services/pr-detail.api.ts +2 -2
  121. package/src/modules/pr/services/pr-edit.api.ts +22 -0
  122. package/src/modules/pr/services/pr-merge.api.ts +1 -1
  123. package/src/modules/pr/services/pr-open.api.ts +1 -1
  124. package/src/modules/review/components/DiffViewer.tsx +1 -1
  125. package/src/modules/review/components/MarkdownDiffViewer.tsx +24 -3
  126. package/src/modules/review/components/ReviewPanel.tsx +10 -5
  127. package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +31 -0
  128. package/src/modules/review/state/ReviewProvider.tsx +2 -2
  129. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +79 -16
  130. package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +112 -2
  131. package/src/modules/secrets-vault/index.ts +6 -0
  132. package/src/modules/secrets-vault/services/connect.api.ts +20 -5
  133. package/src/modules/settings/components/DeploymentPage.tsx +2 -2
  134. package/src/modules/settings/components/SettingsLayout.tsx +2 -2
  135. package/src/modules/settings/index.ts +8 -0
  136. package/src/modules/setup/components/FirstRunStorage.tsx +1 -1
  137. package/src/modules/setup/index.ts +6 -0
  138. package/src/modules/toolbar/commands/actions.tsx +3 -3
  139. package/src/modules/toolbar/commands/useCommandActions.ts +5 -9
  140. package/src/modules/toolbar/components/AgentInstructionsCard.tsx +2 -2
  141. package/src/modules/toolbar/components/AppSwitcher.tsx +1 -2
  142. package/src/modules/toolbar/components/CoworkSetupSteps.tsx +1 -1
  143. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +39 -5
  144. package/src/modules/toolbar/components/ProfileMenu.tsx +3 -3
  145. package/src/modules/toolbar/components/SearchPalette.tsx +4 -8
  146. package/src/modules/toolbar/components/Toolbar.tsx +2 -5
  147. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +91 -2
  148. package/src/modules/toolbar/index.ts +6 -0
  149. package/src/modules/toolbar/search/sources.ts +4 -7
  150. package/src/modules/toolbar/services/agent-instructions.api.ts +1 -1
  151. package/src/modules/toolbar/services/external-api-keys.api.ts +5 -2
  152. package/src/modules/tools/ToolsExplorerPage.tsx +217 -18
  153. package/src/modules/tools/__tests__/ToolsExplorerPage.read-only.test.tsx +220 -0
  154. package/src/modules/tools/tool-hints.api.ts +44 -0
  155. package/src/modules/workflow/index.ts +7 -0
  156. package/src/modules/workflow/state/ChangeRequestStaleBinder.tsx +1 -0
  157. package/src/modules/workflow/state/EventBusFocusBinder.tsx +1 -1
  158. package/src/modules/workspace/components/FileExplorer.tsx +35 -8
  159. package/src/modules/workspace/components/FilePaneCard.tsx +37 -12
  160. package/src/modules/workspace/components/FileRoute.tsx +10 -3
  161. package/src/modules/workspace/components/FileViewer.tsx +169 -25
  162. package/src/modules/workspace/components/FullScreenView.tsx +93 -0
  163. package/src/modules/workspace/components/KbFileRail.tsx +1 -1
  164. package/src/modules/workspace/components/KbPageHeader.tsx +9 -0
  165. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +163 -0
  166. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +11 -0
  167. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +487 -3
  168. package/src/modules/workspace/components/readingCarry.ts +59 -0
  169. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +74 -180
  170. package/src/modules/workspace/components/renderers/KbAppLink.tsx +56 -0
  171. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +30 -10
  172. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +37 -40
  173. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +1 -1
  174. package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.links.test.tsx +185 -0
  175. package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.tools.test.tsx +168 -42
  176. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.sectionReclick.test.tsx +88 -0
  177. package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +199 -29
  178. package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +57 -7
  179. package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +122 -4
  180. package/src/modules/workspace/components/renderers/__tests__/htmlToolBridge.test.ts +235 -1
  181. package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +29 -4
  182. package/src/modules/workspace/components/renderers/__tests__/liveDataReferencePage.test.ts +397 -0
  183. package/src/modules/workspace/components/renderers/__tests__/pageToolsHarness.ts +79 -0
  184. package/src/modules/workspace/components/renderers/__tests__/useHtmlToolBridge.test.tsx +316 -0
  185. package/src/modules/workspace/components/renderers/htmlSandbox.ts +123 -28
  186. package/src/modules/workspace/components/renderers/htmlToolBridge.ts +215 -25
  187. package/src/modules/workspace/components/renderers/index.ts +10 -0
  188. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +35 -28
  189. package/src/modules/workspace/components/renderers/scrollToHeading.ts +35 -0
  190. package/src/modules/workspace/components/renderers/useHtmlToolBridge.tsx +253 -0
  191. package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +6 -0
  192. package/src/modules/workspace/hooks/useFullScreenView.ts +52 -0
  193. package/src/modules/workspace/hooks/useImageRevision.ts +1 -1
  194. package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +1 -1
  195. package/src/modules/workspace/hooks/useLastCommit.ts +1 -1
  196. package/src/modules/workspace/hooks/useLinksOut.ts +12 -6
  197. package/src/modules/workspace/hooks/useWorkspaceState.ts +4 -4
  198. package/src/modules/workspace/index.ts +50 -2
  199. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +262 -25
  200. package/src/modules/workspace/routing/kb-routes.ts +222 -54
  201. package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +0 -1
  202. package/src/modules/workspace/state/open-change-requests.tsx +1 -1
  203. package/src/modules/workspace/utils/fileTree.ts +1 -1
  204. package/src/modules/workspace/utils/frameEscape.ts +15 -0
  205. package/src/modules/workspace/utils/treeConfirm.ts +1 -1
  206. package/src/shared/theme/measure.ts +7 -0
  207. package/src/modules/pr/services/pr-comments.api.ts +0 -45
@@ -1,8 +1,9 @@
1
1
  import { useCallback, useContext, useEffect, useState } from 'react';
2
2
  import { useLocation, useNavigate } from 'react-router-dom';
3
- import { GitContext } from '../../git/state/git.context';
3
+ import { GitContext } from '../../git';
4
4
  import { WorkspaceContext } from '../state/workspace.context';
5
5
  import { useRendererSurface } from '../components/renderers/rendererSurface';
6
+ import type { KbLinkTarget } from '../components/renderers/KbAppLink';
6
7
  import { authFetch } from '../../../lib/api';
7
8
  import {
8
9
  isExternalHref,
@@ -149,23 +150,22 @@ export function fetchNodeId(branch: string, workspacePath: string): Promise<stri
149
150
  }
150
151
 
151
152
  /**
152
- * The canonical absolute URL for a file, for the "copy link" affordances: a node's
153
- * id URL (`<origin>/workspace/<branch>/<id>`) when the file is an id-bearing node,
154
- * else its path URL. Resolves the id in the background and falls back to the path
155
- * URL until it resolves (and permanently for non-node files). Null when there's no
156
- * branch or path yet. Callers append any `#heading` themselves. This makes copied
157
- * links id-based on their own, independent of the `FileRoute` path→id redirect.
153
+ * The frontmatter id of the file at `workspacePath` on the checked-out branch,
154
+ * as the backend answers it ({@link fetchNodeId}), or null — not a node, not
155
+ * resolved yet, or a renderer surface, which has no git status to ask with.
156
+ * `onBranch` names another branch the file was read from: the skill page
157
+ * renders its files from the default branch whatever is checked out.
158
+ * The one answer to "which node is this file", shared by the copy-link URL
159
+ * below and the id-link rule in {@link useNodeIdNav}, so neither re-reads the
160
+ * frontmatter its own way.
158
161
  */
159
- export function useCanonicalFileUrl(workspacePath: string | null): string | null {
160
- // A surface outside the app knows the address of the file it is showing —
161
- // it was told it by whatever opened it — and has no git status to resolve
162
- // one from. Asked FIRST, and before `useGit`, which has no provider there.
162
+ export function useFileNodeId(workspacePath: string | null, onBranch?: string): string | null {
163
163
  const surface = useRendererSurface();
164
164
  const git = useContext(GitContext);
165
- const branch = surface ? null : (git?.status?.branch ?? null);
165
+ const branch = surface ? null : (onBranch ?? git?.status?.branch ?? null);
166
166
  // Tie the resolved id to the exact (branch, path) it was fetched for. Inputs
167
- // change a render before the effect re-resolves, so without this key the URL
168
- // would briefly pair the new path with the *previous* node's id.
167
+ // change a render before the effect re-resolves, so without this key the
168
+ // answer would briefly pair the new path with the *previous* node's id.
169
169
  const key = branch && workspacePath ? `${branch}\n${workspacePath}` : null;
170
170
  const [resolved, setResolved] = useState<{ key: string; id: string | null } | null>(null);
171
171
 
@@ -181,9 +181,28 @@ export function useCanonicalFileUrl(workspacePath: string | null): string | null
181
181
  };
182
182
  }, [key, branch, workspacePath]);
183
183
 
184
+ return resolved && resolved.key === key ? resolved.id : null;
185
+ }
186
+
187
+ /**
188
+ * The canonical absolute URL for a file, for the "copy link" affordances: a node's
189
+ * id URL (`<origin>/workspace/<branch>/<id>`) when the file is an id-bearing node,
190
+ * else its path URL. Resolves the id in the background and falls back to the path
191
+ * URL until it resolves (and permanently for non-node files). Null when there's no
192
+ * branch or path yet. Callers append any `#heading` themselves. This makes copied
193
+ * links id-based on their own, independent of the `FileRoute` path→id redirect.
194
+ */
195
+ export function useCanonicalFileUrl(workspacePath: string | null): string | null {
196
+ // A surface outside the app knows the address of the file it is showing —
197
+ // it was told it by whatever opened it — and has no git status to resolve
198
+ // one from. Asked FIRST, and before `useGit`, which has no provider there.
199
+ const surface = useRendererSurface();
200
+ const git = useContext(GitContext);
201
+ const branch = surface ? null : (git?.status?.branch ?? null);
202
+ const nodeId = useFileNodeId(workspacePath);
203
+
184
204
  if (surface) return workspacePath ? surface.canonicalUrlFor(workspacePath) : null;
185
205
  if (!branch || !workspacePath) return null;
186
- const nodeId = resolved && resolved.key === key ? resolved.id : null;
187
206
  const relative = nodeId ? kbNodeUrl(branch, nodeId) : kbFileUrl(branch, workspacePath);
188
207
  return `${window.location.origin}${relative}`;
189
208
  }
@@ -329,6 +348,60 @@ export function openExternalHref(href: string): boolean {
329
348
  return true;
330
349
  }
331
350
 
351
+ /**
352
+ * Open an in-app address in a new tab: the one way a link inside rendered
353
+ * file content leaves the file it sits in. The tab gets the plain address;
354
+ * whatever view this tab is in (full screen, a query of its own) stays here.
355
+ *
356
+ * `window.open(url, '_blank', 'noopener')` answers `null` whether or not the
357
+ * tab opened, so a tab the browser refused (no user gesture left, a popup
358
+ * blocker) would be a click swallowed without a word. The tab is opened
359
+ * without the feature instead and its `opener` severed at once: the address
360
+ * is this app's own, and a tab just opened has run nothing before this line.
361
+ */
362
+ function openInNewTab(url: string): void {
363
+ const opened = window.open(url, '_blank');
364
+ if (!opened) {
365
+ console.warn(`[useFileNav] the browser did not open a new tab for ${url}`);
366
+ return;
367
+ }
368
+ opened.opener = null;
369
+ }
370
+
371
+ /** Follow a content link where its target says: a new tab, or this tab by its fragment. */
372
+ function followLinkTarget(target: KbLinkTarget | null, navigate: (to: string) => void): void {
373
+ if (!target) return;
374
+ if (target.newTab) openInNewTab(target.href);
375
+ else navigate(target.href);
376
+ }
377
+
378
+ /**
379
+ * A link to the file on screen: this tab's OWN address with the link's
380
+ * fragment — an id URL stays an id URL, and the query (`?fullscreen=1`)
381
+ * stays — so following it scrolls and changes nothing else.
382
+ */
383
+ function sectionOfThisTab(location: { pathname: string; search: string }, hash: string): KbLinkTarget {
384
+ return { href: location.pathname + location.search + hash, newTab: false };
385
+ }
386
+
387
+ const noLinkTarget = (): KbLinkTarget | null => null;
388
+
389
+ /** How `useFileNav().openLink` follows one link, beyond the rule itself. */
390
+ export interface OpenLinkOptions {
391
+ /** The branch the link's file was read from, when not this tab's (see `linkTarget`). */
392
+ homeBranch?: string;
393
+ /** Follow a link to a section of the same file here, given its fragment, instead of moving this tab. */
394
+ onSection?(hash: string): void;
395
+ /**
396
+ * The reader asked for a new tab — a modified or middle click a host had
397
+ * to relay, because it could not leave the click to the browser (the HTML
398
+ * page's sandboxed frame). Every in-app destination then opens in a new
399
+ * tab at its plain address, a section of this file included, as the
400
+ * browser opens a new-tab link: this tab stays as it is.
401
+ */
402
+ newTab?: boolean;
403
+ }
404
+
332
405
  /**
333
406
  * The branch segment of a `/workspace/<branch>/…` pathname, decoded, or null
334
407
  * when this location is not a workspace URL. The pathname from the router is
@@ -395,6 +468,34 @@ export function useFileNav() {
395
468
  [branch, kbDirName, navigate],
396
469
  );
397
470
 
471
+ /**
472
+ * Where an in-app link destination written inside `basePath` leads, as
473
+ * {@link openLink} follows it: the file it sits in keeps THIS tab's own
474
+ * address with the link's fragment (an id URL stays an id URL, and the
475
+ * query — `?fullscreen=1` — stays), any other file opens in a new tab at
476
+ * its plain `kbFileUrl`. Null for an external or unresolvable destination,
477
+ * which is not this rule's.
478
+ *
479
+ * `homeBranch` is the branch the file the link sits in was read from, when
480
+ * that is not the branch this tab stands on: the skill page renders its
481
+ * files from the default branch whatever is checked out, so a relative link
482
+ * there resolves on the default branch. Omitted, it is this tab's branch.
483
+ */
484
+ const linkTarget = useCallback(
485
+ (href: string, basePath: string, homeBranch?: string): KbLinkTarget | null => {
486
+ const target = resolveKbHref(href, { basePath, kbDirName });
487
+ if (target?.kind !== 'workspace') return null;
488
+ const home = homeBranch ?? branch;
489
+ const onBranch = target.branch ?? home;
490
+ if (!onBranch) return null;
491
+ if (onBranch === home && target.path === basePath) {
492
+ return sectionOfThisTab(location, target.hash);
493
+ }
494
+ return { href: kbFileUrl(onBranch, target.path) + target.hash, newTab: true };
495
+ },
496
+ [branch, kbDirName, location],
497
+ );
498
+
398
499
  /**
399
500
  * Follow a link DESTINATION out of a rendered document: the href as the
400
501
  * author wrote it (or as react-markdown encoded it), resolved against
@@ -404,6 +505,16 @@ export function useFileNav() {
404
505
  * branch; a relative one opens on the branch you are standing on. See
405
506
  * {@link resolveKbHref}.
406
507
  *
508
+ * A LINK INSIDE A FILE NEVER NAVIGATES AWAY FROM IT. Another file opens in
509
+ * a new tab at its plain address, and this tab — its location, its scroll,
510
+ * its full-screen view — stays as it was; only a link to the file it sits
511
+ * in (a section link) moves this tab, by its fragment. {@link linkTarget}
512
+ * decides which, and the markdown pipeline renders its anchors from the
513
+ * same answer, so a click and a middle-click go to one place. This is the
514
+ * rule for content, not for the app's own navigation: the tree, the tabs,
515
+ * search and the library reach `openFile` and `openWorkspacePath`, which
516
+ * navigate in place.
517
+ *
407
518
  * AN EXTERNAL LINK IS OPENED HERE TOO, in a new tab. It used to be dropped
408
519
  * on the floor — "not ours to open" — which is true of a link the browser
409
520
  * still owns, and false of every link that reaches this function. Callers
@@ -429,20 +540,35 @@ export function useFileNav() {
429
540
  * URL as a `Referer`, and the scheme allowlist is what keeps the sandbox
430
541
  * sealed — see {@link isOpenableExternalHref}. A destination that is
431
542
  * external but not openable stays a no-op, as it was.
543
+ *
544
+ * `onSection` is how a host whose file does not scroll to this tab's
545
+ * fragment follows a section link instead: the HTML page's frame (a
546
+ * fragment on the app's address never reaches it) and the skill page (its
547
+ * address has no heading scroll). It is handed the link's fragment —
548
+ * `#steps`, or `''` for the file itself — and this tab's address stays as
549
+ * it is. Without it the tab moves to its own address plus the fragment,
550
+ * which the markdown file page scrolls to.
432
551
  */
433
552
  const openLink = useCallback(
434
- (href: string, basePath: string) => {
435
- const target = resolveKbHref(href, { basePath, kbDirName });
436
- if (target?.kind === 'external') {
553
+ (href: string, basePath: string, options: OpenLinkOptions = {}) => {
554
+ const resolved = resolveKbHref(href, { basePath, kbDirName });
555
+ if (resolved?.kind === 'external') {
437
556
  openExternalHref(href);
438
557
  return;
439
558
  }
440
- if (target?.kind !== 'workspace') return;
441
- const onBranch = target.branch ?? branch;
442
- if (!onBranch) return;
443
- navigate(kbFileUrl(onBranch, target.path) + target.hash);
559
+ if (options.newTab && resolved) {
560
+ const onBranch = resolved.branch ?? options.homeBranch ?? branch;
561
+ if (onBranch) openInNewTab(kbFileUrl(onBranch, resolved.path) + resolved.hash);
562
+ return;
563
+ }
564
+ const target = linkTarget(href, basePath, options.homeBranch);
565
+ if (target && !target.newTab && resolved && options.onSection) {
566
+ options.onSection(resolved.hash);
567
+ return;
568
+ }
569
+ followLinkTarget(target, navigate);
444
570
  },
445
- [branch, kbDirName, navigate],
571
+ [branch, kbDirName, linkTarget, navigate],
446
572
  );
447
573
 
448
574
  /**
@@ -486,13 +612,17 @@ export function useFileNav() {
486
612
 
487
613
  // The file page for a path a skill's page would otherwise claim (see
488
614
  // `FILE_PAGE_PARAM`): an HTML page's "Open in the platform", whose tools
489
- // are answered there and nowhere else.
615
+ // are answered there and nowhere else. The page asked for it from inside
616
+ // itself, so it opens in a new tab like any other way out of a page.
617
+ // `homeBranch` as in `linkTarget`: the skill page's files are read from the
618
+ // default branch, whatever this tab stands on.
490
619
  const openFilePage = useCallback(
491
- (path: string) => {
492
- if (!branch) return;
493
- navigate(kbFilePageUrl(branch, path));
620
+ (path: string, homeBranch?: string) => {
621
+ const onBranch = homeBranch ?? branch;
622
+ if (!onBranch) return;
623
+ openInNewTab(kbFilePageUrl(onBranch, path));
494
624
  },
495
- [branch, navigate],
625
+ [branch],
496
626
  );
497
627
 
498
628
  const closeFile = useCallback(() => {
@@ -509,25 +639,57 @@ export function useFileNav() {
509
639
  return {
510
640
  openFile: (pathOrUrl: string) => surface.openLink(pathOrUrl, ''),
511
641
  openLink: surface.openLink,
642
+ // A surface takes every click itself (`linkPolicy: 'surface'`), so its
643
+ // anchors carry no app address of their own.
644
+ linkTarget: noLinkTarget,
512
645
  openWorkspacePath: surface.openWorkspacePath,
513
646
  openFilePage: surface.openFilePage,
514
647
  closeFile: () => undefined,
648
+ // A surface stands on no branch of its own (an embed shows one page).
649
+ branch: null,
515
650
  };
516
651
  }
517
- return { openFile, openLink, openWorkspacePath, openFilePage, closeFile };
652
+ // `branch`: the one this tab stands on, as the URL says it — what a page
653
+ // shown on it is told as `window.bevel.branch`.
654
+ return { openFile, openLink, linkTarget, openWorkspacePath, openFilePage, closeFile, branch };
518
655
  }
519
656
 
520
657
  /**
521
- * Navigate to a node referenced by its frontmatter id (`<id>` or `<id#heading>`).
522
- * Resolves the id → its file location via the backend (the same `resolve-id`
523
- * route the in-KB markdown renderer uses; it 404s fail-closed for ids the caller
524
- * may not read), then opens the file, preserving any heading anchor as a real
525
- * URL fragment so the deep-link scroll fires. Shared by the file renderer and
526
- * the chat citation renderer so both resolve id-links identically.
658
+ * Follow a node referenced by its frontmatter id (`<id>` or `<id#heading>`), a
659
+ * link inside rendered content — so it follows {@link useFileNav}'s rule for
660
+ * those: a node other than the one on screen opens in a NEW TAB at its
661
+ * canonical id URL (`kbNodeUrl`, plus any heading as a real fragment so the
662
+ * deep-link scroll fires there), and this tab stays as it was. The id is
663
+ * resolved by that tab's `FileRoute`, through the same `resolve-id` route this
664
+ * hook used to call first (it 404s fail-closed for ids the reader may not
665
+ * read, and the tab shows not-found). Resolving here first would put a round
666
+ * trip between the click and `window.open`, and a browser lets a click open a
667
+ * tab only for so long — and the address would be one a middle-click on the
668
+ * same anchor never reaches.
669
+ *
670
+ * A link to the node on screen is a section link and moves this tab by its
671
+ * fragment only. Which node is on screen is decided by its ID, not by this
672
+ * tab's address: `ownId` is the id of the file the link sits in, as the
673
+ * renderer read it from that file, so a tab still on the file's PATH URL —
674
+ * the id not canonicalized yet, or a `FileRoute` that never canonicalizes
675
+ * (the library's) — knows the node too. Without one, the node whose id URL
676
+ * this tab is at (where `FileRoute` puts a node) is the one on screen.
677
+ * Shared by the file renderer and the chat citation renderer so both follow
678
+ * id-links identically.
679
+ *
680
+ * `onSection` is `OpenLinkOptions.onSection` for an id-link: a host whose
681
+ * address has no heading scroll (the skill page) scrolls to the fragment of a
682
+ * link to its own node itself, and this tab's address stays as it is.
683
+ *
684
+ * `homeBranch` is `linkTarget`'s, for an id-link: the branch the file the
685
+ * link sits in was read from, when not this tab's. The skill page renders
686
+ * its files from the default branch whatever is checked out, so an id there
687
+ * names a node on the default branch, not on somebody's draft. Omitted, it
688
+ * is this tab's branch.
527
689
  */
528
690
  export function useNodeIdNav() {
529
691
  const surface = useRendererSurface();
530
- const { openFile } = useFileNav();
692
+ const navigate = useNavigate();
531
693
  const git = useContext(GitContext);
532
694
  const location = useLocation();
533
695
  // The URL's branch first, the git status second — the same order as
@@ -535,32 +697,38 @@ export function useNodeIdNav() {
535
697
  // being left, and an id resolved against it would open the wrong tree.
536
698
  const branch = branchFromPathname(location.pathname) ?? git?.status?.branch ?? null;
537
699
 
538
- const openNodeId = useCallback(
539
- async (idOrLink: string) => {
540
- if (!branch) return;
700
+ const nodeIdTarget = useCallback(
701
+ (idOrLink: string, ownId?: string | null, homeBranch?: string): KbLinkTarget | null => {
702
+ const onBranch = homeBranch ?? branch;
703
+ if (!onBranch) return null;
541
704
  const hashIdx = idOrLink.indexOf('#');
542
705
  const id = hashIdx >= 0 ? idOrLink.slice(0, hashIdx) : idOrLink;
543
706
  const hash = hashIdx >= 0 ? idOrLink.slice(hashIdx) : '';
544
- try {
545
- const r = await authFetch(
546
- `/api/workspace/${encodeURIComponent(branch)}/resolve-id/${encodeURIComponent(id)}`,
547
- );
548
- if (!r.ok) {
549
- console.warn(`[useNodeIdNav] unresolved id-link '${id}' (HTTP ${r.status})`);
550
- return;
551
- }
552
- const { workspacePath } = (await r.json()) as { workspacePath: string };
553
- openFile(workspacePath + hash);
554
- } catch (err) {
555
- console.error('[useNodeIdNav] id-link resolve failed:', err);
707
+ const url = kbNodeUrl(onBranch, id);
708
+ if (id === ownId || url === location.pathname) {
709
+ return sectionOfThisTab(location, hash);
710
+ }
711
+ return { href: url + hash, newTab: true };
712
+ },
713
+ [branch, location],
714
+ );
715
+
716
+ const openNodeId = useCallback(
717
+ (idOrLink: string, ownId?: string | null, options: OpenLinkOptions = {}) => {
718
+ const target = nodeIdTarget(idOrLink, ownId, options.homeBranch);
719
+ if (target && !target.newTab && options.onSection) {
720
+ const hashIdx = idOrLink.indexOf('#');
721
+ options.onSection(hashIdx >= 0 ? idOrLink.slice(hashIdx) : '');
722
+ return;
556
723
  }
724
+ followLinkTarget(target, navigate);
557
725
  },
558
- [branch, openFile],
726
+ [nodeIdTarget, navigate],
559
727
  );
560
728
 
561
729
  // The surface resolves an id its own way — the embed hands it to its host
562
730
  // as an app address, which the app then resolves with the reader's own
563
731
  // session. Resolving it HERE would need a session the embed does not have.
564
- if (surface) return { openNodeId: surface.openNodeId };
565
- return { openNodeId };
732
+ if (surface) return { openNodeId: surface.openNodeId, nodeIdTarget: noLinkTarget };
733
+ return { openNodeId, nodeIdTarget };
566
734
  }
@@ -208,7 +208,6 @@ describe('an applied change request stops showing as pending — for every viewe
208
208
  source: 'suggestions/bo/knowledge',
209
209
  target: 'main',
210
210
  authorIdHash: null,
211
- title: 'Upload into Plugins/x',
212
211
  }),
213
212
  );
214
213
  await waitFor(() => expect(pending(result)).toBe(true));
@@ -3,7 +3,7 @@ import type { PullRequestSummary } from '@bevel-software/platform-shared';
3
3
  import {
4
4
  listMyChangeRequests,
5
5
  listOpenChangeRequests,
6
- } from '../../change-requests/services/change-requests.api';
6
+ } from '../../change-requests';
7
7
  import { useWorkspace } from './workspace.context';
8
8
  import {
9
9
  PR_STALE_FALLBACK_MS,
@@ -48,7 +48,7 @@ export function checkoutRoot(
48
48
  * Whether the tree shows the caller anything of the knowledge base at all.
49
49
  * What does not count: the reserved root folders themselves (every knowledge
50
50
  * base has them, and the server keeps them visible even to a reader who may
51
- * open nothing inside), and the root `.bevelignore` an admin sees in a
51
+ * open nothing inside), and the root `.bevelignore` every reader sees in a
52
52
  * knowledge base nobody has written to yet. Anything else — a file, or a
53
53
  * folder, at any depth — is an entry on screen.
54
54
  *
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Whether a window message is an Escape handed up by a page's frame inside
3
+ * `surface` (`bevel.key`, posted by the sandbox's key bridge in
4
+ * `htmlSandbox.ts`) — the one kind the full-screen view acts on. A message
5
+ * from any other window, or of any other shape, is not.
6
+ *
7
+ * Closes over nothing, so the real-browser suite can load it into a page from
8
+ * its source and hold it to a real sandboxed frame's `postMessage`.
9
+ */
10
+ export function isFrameEscape(e: MessageEvent, surface: Element | null): boolean {
11
+ const msg = e.data as { type?: unknown; key?: unknown } | null;
12
+ if (!msg || typeof msg !== 'object' || msg.type !== 'bevel.key' || msg.key !== 'Escape') return false;
13
+ if (!e.source || !surface) return false;
14
+ return Array.from(surface.querySelectorAll('iframe')).some((f) => f.contentWindow === e.source);
15
+ }
@@ -14,7 +14,7 @@ import {
14
14
  type AccessPrincipalRef,
15
15
  type PathPrincipals,
16
16
  type ProspectiveAccess,
17
- } from '../../access/api';
17
+ } from '../../access';
18
18
  import { KB_ROOT_DIRS } from './fileTree';
19
19
 
20
20
  // What the tree's delete and move confirmations say — see
@@ -29,6 +29,13 @@
29
29
  /** The default column: an 880px measure, centred. */
30
30
  export const DOCUMENT_COLUMN = 'mx-auto w-full max-w-[880px]';
31
31
 
32
+ /**
33
+ * What the default column leaves for its content: the 880px measure less the
34
+ * 40px side gutters `documentSideGutters(false)` puts inside it, centred. For
35
+ * a surface that holds the column's content without the column around it.
36
+ */
37
+ export const DOCUMENT_COLUMN_CONTENT = 'mx-auto w-full max-w-[800px]';
38
+
32
39
  /** The opt-out, for a page that puts a second column (a rail) beside the article. */
33
40
  export const DOCUMENT_COLUMN_WIDE = 'mx-auto w-full max-w-[980px]';
34
41
 
@@ -1,45 +0,0 @@
1
- import type { PostPrCommentInput, PrReviewComment } from '@bevel-software/platform-shared';
2
- import { authFetch } from '../../../lib/api';
3
- import { handleApiResponse } from '../../git/services/git.api';
4
-
5
- export async function listPrComments(prNumber: number): Promise<PrReviewComment[]> {
6
- return handleApiResponse(await authFetch(`/api/workflow/change-requests/${prNumber}/comments`));
7
- }
8
-
9
- export async function postPrComment(
10
- prNumber: number,
11
- input: PostPrCommentInput,
12
- ): Promise<PrReviewComment> {
13
- return handleApiResponse(
14
- await authFetch(`/api/workflow/change-requests/${prNumber}/comments`, {
15
- method: 'POST',
16
- headers: { 'Content-Type': 'application/json' },
17
- body: JSON.stringify(input),
18
- }),
19
- );
20
- }
21
-
22
- export async function editPrComment(
23
- prNumber: number,
24
- commentId: string,
25
- body: string,
26
- ): Promise<PrReviewComment> {
27
- return handleApiResponse(
28
- await authFetch(`/api/workflow/change-requests/${prNumber}/comments/${commentId}`, {
29
- method: 'PATCH',
30
- headers: { 'Content-Type': 'application/json' },
31
- body: JSON.stringify({ body }),
32
- }),
33
- );
34
- }
35
-
36
- export async function deletePrComment(
37
- prNumber: number,
38
- commentId: string,
39
- ): Promise<void> {
40
- await handleApiResponse(
41
- await authFetch(`/api/workflow/change-requests/${prNumber}/comments/${commentId}`, {
42
- method: 'DELETE',
43
- }),
44
- );
45
- }