@bevel-software/platform-core-frontend 0.32.0 → 0.33.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 (167) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +1 -1
  3. package/src/modules/access/api.ts +1 -1
  4. package/src/modules/access/components/ManageAccessDialog.tsx +4 -5
  5. package/src/modules/access/hooks/useAccessRequests.ts +1 -1
  6. package/src/modules/access/hooks/useFileAccess.ts +1 -1
  7. package/src/modules/access/index.ts +11 -0
  8. package/src/modules/access/requests.api.ts +1 -1
  9. package/src/modules/admin/components/AddMemberInput.tsx +1 -1
  10. package/src/modules/admin/components/UserAccountsPage.tsx +3 -3
  11. package/src/modules/admin/index.ts +7 -0
  12. package/src/modules/admin/state/admin.context.tsx +1 -1
  13. package/src/modules/audit/components/AuditEventsPanel.tsx +1 -1
  14. package/src/modules/audit/components/AuditLogPage.tsx +2 -2
  15. package/src/modules/auth/index.ts +12 -0
  16. package/src/modules/change-requests/__tests__/ChangeRequestDialog.access-rules.test.tsx +0 -1
  17. package/src/modules/change-requests/__tests__/ChangeRequestDialog.binary.test.tsx +0 -1
  18. package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +0 -1
  19. package/src/modules/change-requests/__tests__/ChangeRequestDialog.edit.test.tsx +166 -0
  20. package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +0 -1
  21. package/src/modules/change-requests/__tests__/ChangeRequestDialog.initial-file.test.tsx +0 -1
  22. package/src/modules/change-requests/__tests__/ChangeRequestDialog.moved.test.tsx +0 -1
  23. package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +0 -1
  24. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +0 -2
  25. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +0 -1
  26. package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +0 -1
  27. package/src/modules/change-requests/components/BranchFilePreview.tsx +4 -12
  28. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +138 -30
  29. package/src/modules/change-requests/components/ChangeRequestLink.tsx +2 -3
  30. package/src/modules/change-requests/components/CrFileTree.tsx +1 -1
  31. package/src/modules/change-requests/components/FileChangeBoxes.tsx +2 -3
  32. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +3 -5
  33. package/src/modules/change-requests/hooks/useCrFileDiffs.ts +1 -1
  34. package/src/modules/change-requests/index.ts +14 -0
  35. package/src/modules/change-requests/services/change-requests.api.ts +2 -2
  36. package/src/modules/change-requests/services/denied-file.api.ts +2 -2
  37. package/src/modules/change-requests/services/propose.api.ts +3 -4
  38. package/src/modules/change-requests/utils/diff.ts +1 -1
  39. package/src/modules/change-requests/utils/readFailure.ts +1 -1
  40. package/src/modules/embed/__tests__/EmbedView.test.tsx +19 -2
  41. package/src/modules/embed/components/EmbedLinkPage.tsx +1 -2
  42. package/src/modules/git/components/BranchSwitcher.tsx +3 -4
  43. package/src/modules/git/components/FileHistoryPanel.tsx +2 -2
  44. package/src/modules/git/components/GitSyncFailedBanner.tsx +2 -4
  45. package/src/modules/git/components/HistoryVersionPreview.tsx +4 -15
  46. package/src/modules/git/components/PullNeededBanner.tsx +1 -1
  47. package/src/modules/git/hooks/useAutoPullUpdates.ts +1 -1
  48. package/src/modules/git/index.ts +11 -0
  49. package/src/modules/layout/components/MobileChatLayout.tsx +1 -1
  50. package/src/modules/layout/index.ts +9 -0
  51. package/src/modules/library/__tests__/SkillPage.test.tsx +39 -0
  52. package/src/modules/library/__tests__/propose-change.test.ts +75 -0
  53. package/src/modules/library/components/AddToPluginDialog.tsx +1 -1
  54. package/src/modules/library/components/ChangeRequestDock.tsx +1 -1
  55. package/src/modules/library/components/LibraryLayout.tsx +2 -2
  56. package/src/modules/library/components/LibraryPage.tsx +3 -3
  57. package/src/modules/library/components/ManagedPluginRequests.tsx +1 -1
  58. package/src/modules/library/components/NewSkillPanel.tsx +2 -2
  59. package/src/modules/library/components/PersonalAddDialog.tsx +1 -1
  60. package/src/modules/library/components/PersonalPluginPage.tsx +1 -1
  61. package/src/modules/library/components/PluginExtras.tsx +1 -4
  62. package/src/modules/library/components/PluginPage.tsx +1 -1
  63. package/src/modules/library/components/PluginRows.tsx +1 -1
  64. package/src/modules/library/components/SkillsTree.tsx +1 -4
  65. package/src/modules/library/components/plugin-page-parts.tsx +1 -1
  66. package/src/modules/library/components/skill-page/SkillFilePane.tsx +19 -7
  67. package/src/modules/library/components/skill-page/SkillPage.tsx +19 -26
  68. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +2 -4
  69. package/src/modules/library/components/tool-page/ToolVarRow.tsx +2 -2
  70. package/src/modules/library/hooks/useJoinRequests.ts +1 -1
  71. package/src/modules/library/hooks/useLibraryData.ts +3 -3
  72. package/src/modules/library/hooks/useToolPage.ts +1 -1
  73. package/src/modules/library/hooks/useToolSource.ts +1 -1
  74. package/src/modules/library/index.ts +12 -0
  75. package/src/modules/library/routes/LibraryRoutes.tsx +1 -1
  76. package/src/modules/library/routes/WorkspaceItemRoute.tsx +1 -3
  77. package/src/modules/library/routes/library-paths.ts +1 -1
  78. package/src/modules/library/services/library.api.ts +10 -8
  79. package/src/modules/library/services/plugins.api.ts +1 -1
  80. package/src/modules/library/services/teams.api.ts +1 -1
  81. package/src/modules/library/utils/status.ts +2 -2
  82. package/src/modules/onboarding/components/ConnectAgentPill.tsx +1 -1
  83. package/src/modules/onboarding/components/CreatorWelcomePage.tsx +2 -3
  84. package/src/modules/onboarding/components/GetStartedColumn.tsx +6 -13
  85. package/src/modules/onboarding/components/InviteButton.tsx +2 -2
  86. package/src/modules/onboarding/components/InviteDialog.tsx +4 -6
  87. package/src/modules/onboarding/components/RootLanding.tsx +2 -2
  88. package/src/modules/onboarding/components/StarterPackCard.tsx +1 -1
  89. package/src/modules/onboarding/components/WelcomePage.tsx +2 -5
  90. package/src/modules/onboarding/index.ts +10 -0
  91. package/src/modules/onboarding/paths.ts +1 -1
  92. package/src/modules/onboarding/state/agent-connection.ts +2 -2
  93. package/src/modules/onboarding/state/onboarding.ts +1 -1
  94. package/src/modules/onboarding/state/starter-packs.ts +1 -1
  95. package/src/modules/pr/components/OpenChangeRequestDialog.tsx +1 -1
  96. package/src/modules/pr/index.ts +14 -0
  97. package/src/modules/pr/services/pr-approvals.api.ts +1 -1
  98. package/src/modules/pr/services/pr-cancel.api.ts +1 -1
  99. package/src/modules/pr/services/pr-detail.api.ts +2 -2
  100. package/src/modules/pr/services/pr-edit.api.ts +22 -0
  101. package/src/modules/pr/services/pr-merge.api.ts +1 -1
  102. package/src/modules/pr/services/pr-open.api.ts +1 -1
  103. package/src/modules/review/components/DiffViewer.tsx +1 -1
  104. package/src/modules/review/components/MarkdownDiffViewer.tsx +1 -2
  105. package/src/modules/review/components/ReviewPanel.tsx +2 -3
  106. package/src/modules/review/state/ReviewProvider.tsx +2 -2
  107. package/src/modules/secrets-vault/index.ts +6 -0
  108. package/src/modules/settings/components/DeploymentPage.tsx +2 -2
  109. package/src/modules/settings/components/SettingsLayout.tsx +2 -2
  110. package/src/modules/settings/index.ts +8 -0
  111. package/src/modules/setup/components/FirstRunStorage.tsx +1 -1
  112. package/src/modules/setup/index.ts +6 -0
  113. package/src/modules/toolbar/commands/actions.tsx +3 -3
  114. package/src/modules/toolbar/commands/useCommandActions.ts +5 -9
  115. package/src/modules/toolbar/components/AgentInstructionsCard.tsx +2 -2
  116. package/src/modules/toolbar/components/AppSwitcher.tsx +1 -2
  117. package/src/modules/toolbar/components/CoworkSetupSteps.tsx +1 -1
  118. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
  119. package/src/modules/toolbar/components/ProfileMenu.tsx +3 -3
  120. package/src/modules/toolbar/components/SearchPalette.tsx +4 -8
  121. package/src/modules/toolbar/components/Toolbar.tsx +2 -5
  122. package/src/modules/toolbar/index.ts +6 -0
  123. package/src/modules/toolbar/search/sources.ts +4 -7
  124. package/src/modules/toolbar/services/agent-instructions.api.ts +1 -1
  125. package/src/modules/tools/ToolsExplorerPage.tsx +217 -18
  126. package/src/modules/tools/__tests__/ToolsExplorerPage.read-only.test.tsx +220 -0
  127. package/src/modules/tools/tool-hints.api.ts +44 -0
  128. package/src/modules/workflow/index.ts +7 -0
  129. package/src/modules/workflow/state/ChangeRequestStaleBinder.tsx +1 -0
  130. package/src/modules/workflow/state/EventBusFocusBinder.tsx +1 -1
  131. package/src/modules/workspace/components/FileExplorer.tsx +35 -8
  132. package/src/modules/workspace/components/FilePaneCard.tsx +37 -12
  133. package/src/modules/workspace/components/FileRoute.tsx +10 -3
  134. package/src/modules/workspace/components/FileViewer.tsx +169 -25
  135. package/src/modules/workspace/components/FullScreenView.tsx +93 -0
  136. package/src/modules/workspace/components/KbFileRail.tsx +1 -1
  137. package/src/modules/workspace/components/KbPageHeader.tsx +9 -0
  138. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +137 -0
  139. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +11 -0
  140. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +487 -3
  141. package/src/modules/workspace/components/readingCarry.ts +59 -0
  142. package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +36 -175
  143. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +1 -1
  144. package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.tools.test.tsx +168 -42
  145. package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +20 -3
  146. package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +63 -4
  147. package/src/modules/workspace/components/renderers/__tests__/htmlToolBridge.test.ts +235 -1
  148. package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +14 -3
  149. package/src/modules/workspace/components/renderers/__tests__/pageToolsHarness.ts +79 -0
  150. package/src/modules/workspace/components/renderers/__tests__/useHtmlToolBridge.test.tsx +316 -0
  151. package/src/modules/workspace/components/renderers/htmlSandbox.ts +75 -13
  152. package/src/modules/workspace/components/renderers/htmlToolBridge.ts +196 -25
  153. package/src/modules/workspace/components/renderers/index.ts +10 -0
  154. package/src/modules/workspace/components/renderers/useHtmlToolBridge.tsx +253 -0
  155. package/src/modules/workspace/hooks/useFullScreenView.ts +52 -0
  156. package/src/modules/workspace/hooks/useImageRevision.ts +1 -1
  157. package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +1 -1
  158. package/src/modules/workspace/hooks/useLastCommit.ts +1 -1
  159. package/src/modules/workspace/hooks/useWorkspaceState.ts +4 -4
  160. package/src/modules/workspace/index.ts +30 -1
  161. package/src/modules/workspace/routing/kb-routes.ts +1 -1
  162. package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +0 -1
  163. package/src/modules/workspace/state/open-change-requests.tsx +1 -1
  164. package/src/modules/workspace/utils/frameEscape.ts +15 -0
  165. package/src/modules/workspace/utils/treeConfirm.ts +1 -1
  166. package/src/shared/theme/measure.ts +7 -0
  167. package/src/modules/pr/services/pr-comments.api.ts +0 -45
@@ -57,31 +57,30 @@ import { uploadErrorNextStep } from '../utils/uploadError';
57
57
  import { useMergedWorkspaceTree } from '../hooks/useMergedWorkspaceTree';
58
58
  import { ChangeRequestDialog } from '../../change-requests/components/ChangeRequestDialog';
59
59
  import { PR_STALE_EVENT, SUGGESTIONS_RETRACTED_EVENT } from '../../../core/events';
60
+ import { canonicalizeWorkspaceId, useEventBusSubscription } from '../../workflow';
60
61
  import {
61
62
  listChangeRequestsUnderFolder,
62
63
  removeFolderFromChangeRequests,
63
- } from '../../change-requests/services/change-requests.api';
64
- import { cancelPullRequest } from '../../pr/services/pr-cancel.api';
64
+ } from '../../change-requests';
65
+ import { cancelPullRequest } from '../../pr';
65
66
  import { snapshotEntries } from '../utils/readDroppedEntries';
66
67
  import { useSearchParams } from 'react-router-dom';
67
68
  import { CR_FILE_PARAM, CR_PARAM, useFileNav } from '../routing/kb-routes';
68
69
  import { rawFileUrl } from '../services/workspace.api';
69
70
  import { downloadViaBlob } from './renderers/downloadFile';
70
71
  import { cn } from '../../../lib/utils';
71
- import { Banner, MenuPanel, MenuItem, TextField, IconButton } from '../../../shared/components';
72
- import { useDismissableMenu, usePointerMenuPosition } from '../../../shared/components';
72
+ import { Banner, MenuPanel, MenuItem, TextField, IconButton, useDismissableMenu, usePointerMenuPosition } from '../../../shared/components';
73
73
  import { displayFileName, fileNameTooltip } from '../utils/display-file-name';
74
74
  import { useOpenChangeRequests } from '../hooks/useOpenChangeRequests';
75
- import { AdminContext } from '../../admin/state/admin.context';
75
+ import { AdminContext } from '../../admin';
76
76
  import { ManageAccessDialog } from '../../access/components/ManageAccessDialog';
77
- import { offersManageAccess } from '../../access/manage-access-affordance';
77
+ import { offersManageAccess, fetchFileAccess, fetchProspectiveAccess } from '../../access';
78
78
  import {
79
79
  useAppRegistry,
80
80
  type FolderMenuContext,
81
81
  type FolderMenuItemDef,
82
82
  type FolderMenuTools,
83
83
  } from '../../../core/registry';
84
- import { fetchFileAccess, fetchProspectiveAccess } from '../../access/api';
85
84
  import {
86
85
  TreeActionConfirmDialog,
87
86
  type DeleteMode,
@@ -1009,7 +1008,8 @@ function RenameInput({
1009
1008
  // ── Row Notice ──
1010
1009
 
1011
1010
  /**
1012
- * One row's own bad news — a refused download, a refused drop — drawn under
1011
+ * One row's own bad news — a refused download, a refused drop, a document
1012
+ * whose text the server could not read — drawn under
1013
1013
  * the row at the row's indent, with a Dismiss. Never an `alert()`: a modal
1014
1014
  * popup stops the whole app to say something the tree can say in place, and
1015
1015
  * (the create flow learned this the hard way) it steals focus from whatever
@@ -1135,6 +1135,22 @@ export function FileTreeNode({
1135
1135
  * Sales.") is the whole message, so it is shown verbatim.
1136
1136
  */
1137
1137
  const [moveError, setMoveError] = useState<string | null>(null);
1138
+ /**
1139
+ * Why the server just failed to read this document's text, pushed as it
1140
+ * happened (`document-unreadable`). Transient by design: only a row on
1141
+ * screen at that moment shows it, Dismiss clears it, and nothing is kept —
1142
+ * the reason stays available from `read_file` and `file_stat`.
1143
+ */
1144
+ const [unreadable, setUnreadable] = useState<string | null>(null);
1145
+ const onDocumentUnreadable = useCallback(
1146
+ (event: { workspaceId: string; path: string; reason: string }) => {
1147
+ if (!workspaceId || canonicalizeWorkspaceId(event.workspaceId) !== canonicalizeWorkspaceId(workspaceId)) return;
1148
+ if (entry.type !== 'file' || event.path !== entry.relativePath) return;
1149
+ setUnreadable(event.reason);
1150
+ },
1151
+ [workspaceId, entry.type, entry.relativePath],
1152
+ );
1153
+ useEventBusSubscription('document-unreadable', onDocumentUnreadable);
1138
1154
  /**
1139
1155
  * Which download the notice is allowed to speak for. The menu closes on
1140
1156
  * click but the ROW does not, so a second Download can be started (reopen,
@@ -1304,6 +1320,15 @@ export function FileTreeNode({
1304
1320
  onDismiss={() => setMoveError(null)}
1305
1321
  />
1306
1322
  );
1323
+ const unreadableNotice = unreadable && (
1324
+ <RowNotice
1325
+ message={`Could not be read: ${unreadable}${/[.!?]$/.test(unreadable) ? '' : '.'}`}
1326
+ testId="tree-unreadable-notice"
1327
+ dismissLabel="Dismiss could not be read"
1328
+ paddingLeft={paddingLeft}
1329
+ onDismiss={() => setUnreadable(null)}
1330
+ />
1331
+ );
1307
1332
 
1308
1333
  /**
1309
1334
  * The rename box's submit: move this entry to `newName` beside itself.
@@ -1562,6 +1587,7 @@ export function FileTreeNode({
1562
1587
  </div>
1563
1588
  {downloadNotice}
1564
1589
  {moveNotice}
1590
+ {unreadableNotice}
1565
1591
  {isExpanded && (
1566
1592
  <div>
1567
1593
  {creating && (
@@ -1795,6 +1821,7 @@ export function FileTreeNode({
1795
1821
  </button>
1796
1822
  {downloadNotice}
1797
1823
  {moveNotice}
1824
+ {unreadableNotice}
1798
1825
  {contextMenu && (
1799
1826
  <ContextMenu
1800
1827
  x={contextMenu.x}
@@ -1,4 +1,4 @@
1
- import type { ReactNode } from 'react';
1
+ import type { CSSProperties, ReactNode } from 'react';
2
2
  import { cn } from '../../../lib/utils';
3
3
  import { Surface } from '../../../shared/components';
4
4
 
@@ -29,29 +29,54 @@ export interface FilePaneCardProps {
29
29
  actions?: ReactNode;
30
30
  /** Sits between the bar and the body: the "your suggestions are inline" strip. */
31
31
  notice?: ReactNode;
32
+ /**
33
+ * Draw nothing but the body: no edges, no bar, no notice. For the file
34
+ * page's full-screen view, which shows the document and nothing else. A
35
+ * flag rather than a second tree, because a different tree around
36
+ * `children` would remount the renderer — and lose an editor's unsaved text.
37
+ */
38
+ chromeless?: boolean;
32
39
  className?: string;
40
+ /** Inline geometry the caller measured, e.g. a width to hold across a layout switch. */
41
+ style?: CSSProperties;
33
42
  children: ReactNode;
34
43
  }
35
44
 
36
- export function FilePaneCard({ file, fileTitle, actions, notice, className, children }: FilePaneCardProps) {
45
+ export function FilePaneCard({
46
+ file,
47
+ fileTitle,
48
+ actions,
49
+ notice,
50
+ chromeless = false,
51
+ className,
52
+ style,
53
+ children,
54
+ }: FilePaneCardProps) {
37
55
  return (
38
56
  <Surface
39
57
  tone="surface"
40
58
  radius="lg"
41
- elevation="card"
59
+ elevation={chromeless ? 'none' : 'card'}
42
60
  data-testid="file-pane-card"
43
- className={cn('overflow-hidden', className)}
61
+ // The border goes TRANSPARENT, not away: the box keeps its width to the
62
+ // pixel, so the text inside wraps exactly as it did with the edges drawn.
63
+ className={cn('overflow-hidden', chromeless && 'border-transparent bg-transparent', className)}
64
+ style={style}
44
65
  >
45
- <div className="flex min-h-11 items-center gap-3 border-b border-line px-3.5 py-2">
46
- <span className="mr-auto truncate font-mono text-meta text-ink-muted" title={fileTitle}>
47
- {file}
48
- </span>
49
- {actions}
50
- </div>
66
+ {!chromeless && (
67
+ <div className="flex min-h-11 items-center gap-3 border-b border-line px-3.5 py-2">
68
+ <span className="mr-auto truncate font-mono text-meta text-ink-muted" title={fileTitle}>
69
+ {file}
70
+ </span>
71
+ {actions}
72
+ </div>
73
+ )}
51
74
 
52
- {notice}
75
+ {!chromeless && notice}
53
76
 
54
- <div className="px-6 py-4">{children}</div>
77
+ <div data-file-pane-body="" className="px-6 py-4">
78
+ {children}
79
+ </div>
55
80
  </Surface>
56
81
  );
57
82
  }
@@ -2,7 +2,7 @@ import { useEffect, useRef, useState, type ReactNode } from 'react';
2
2
  import { useParams, useNavigate, useLocation } from 'react-router-dom';
3
3
  import { useWorkspace } from '../state/workspace.context';
4
4
  import { WorkspaceApiError } from '../services/workspace.api';
5
- import { useGit } from '../../git/state/git.context';
5
+ import { useGit } from '../../git';
6
6
  import { readPersistedTabs } from '../utils/tab-persistence';
7
7
  import { syncFileTraceFlag, traceFiles } from '../utils/file-trace';
8
8
  import { DEFAULT_BRANCH } from '@bevel-software/platform-shared';
@@ -134,7 +134,11 @@ export function FileRoute({ canonicalize = true }: { canonicalize?: boolean } =
134
134
  // the entry's router state — a `startEditing` request (or `rawFile`) not yet
135
135
  // acted on must survive it. Read through a ref, at the moment of the swap,
136
136
  // so a request the viewer has consumed in the meantime is not put back.
137
+ // The query rides along for the same reason: it is the entry's view
138
+ // (`?fullscreen=1`), and a link that asked for it must still have it once
139
+ // the path has become an id.
137
140
  const routerStateRef = useLatestRef<unknown>(location.state);
141
+ const searchRef = useLatestRef(location.search);
138
142
  useEffect(() => {
139
143
  if (!canonicalize || segmentIsId || !segment || !branchFromUrl) return;
140
144
  if (openFilePath !== segment) return;
@@ -142,13 +146,16 @@ export function FileRoute({ canonicalize = true }: { canonicalize?: boolean } =
142
146
  (async () => {
143
147
  const nodeId = await fetchNodeId(branchFromUrl, segment);
144
148
  if (!cancelled && nodeId) {
145
- navigate(kbNodeUrl(branchFromUrl, nodeId) + location.hash, { replace: true, state: routerStateRef.current });
149
+ navigate(kbNodeUrl(branchFromUrl, nodeId) + searchRef.current + location.hash, {
150
+ replace: true,
151
+ state: routerStateRef.current,
152
+ });
146
153
  }
147
154
  })();
148
155
  return () => {
149
156
  cancelled = true;
150
157
  };
151
- }, [canonicalize, segmentIsId, segment, branchFromUrl, openFilePath, location.hash, navigate, routerStateRef]);
158
+ }, [canonicalize, segmentIsId, segment, branchFromUrl, openFilePath, location.hash, navigate, routerStateRef, searchRef]);
152
159
 
153
160
  // ── Branch sync + hydrate + URL → state (forward direction) ──────────────
154
161
 
@@ -1,4 +1,4 @@
1
- import { useMemo, useCallback, useContext, useEffect, useRef, useState } from 'react';
1
+ import { useMemo, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from 'react';
2
2
  import { Check, XCircle, Pencil, AlertTriangle, ArrowLeft, FileText, History, Users } from 'lucide-react';
3
3
  import {
4
4
  KNOWLEDGE_BASE_DIR,
@@ -14,13 +14,13 @@ import { useOpenChangeRequests } from '../hooks/useOpenChangeRequests';
14
14
  import { Banner, Button, IconButton, Surface, useFocusHandoff } from '../../../shared/components';
15
15
  import { displayFileName, fileNameTooltip, isAccessRulesFile } from '../utils/display-file-name';
16
16
  import { ManageAccessDialog } from '../../access/components/ManageAccessDialog';
17
- import { useGit } from '../../git/state/git.context';
18
- import { LayoutContext } from '../../layout/state/layout.context';
17
+ import { useGit } from '../../git';
18
+ import { LayoutContext } from '../../layout';
19
19
  import { useLocation, useNavigate, useParams } from 'react-router-dom';
20
20
  import { useCanonicalFileUrl, useFileNav } from '../routing/kb-routes';
21
21
  import { PullNeededBanner } from '../../git/components/PullNeededBanner';
22
22
  import { GitSyncFailedBanner } from '../../git/components/GitSyncFailedBanner';
23
- import { useFileAccess } from '../../access/hooks/useFileAccess';
23
+ import { useFileAccess, formatEligible } from '../../access';
24
24
  import { FileHistoryPanel } from '../../git/components/FileHistoryPanel';
25
25
  import { FileComparisonPanel } from '../../git/components/FileComparisonPanel';
26
26
  import {
@@ -29,30 +29,37 @@ import {
29
29
  } from '../../../core/events';
30
30
  import { useAppRegistry } from '../../../core/registry';
31
31
  import { LockApiError, SELF_HOLD_MESSAGE, useFileLock } from '../../workflow';
32
- import { useAuth } from '../../auth/state/auth.context';
32
+ import { useAuth } from '../../auth';
33
33
  import {
34
34
  knowledgeSuggestionBranchFor,
35
35
  proposeKnowledgeChange,
36
- } from '../../change-requests/services/propose.api';
36
+ } from '../../change-requests';
37
37
  import {
38
38
  listMyChangeRequests,
39
39
  readFileOnBranch,
40
- } from '../../change-requests/services/change-requests.api';
40
+ } from '../../change-requests';
41
41
  import { FileChangeBoxes } from '../../change-requests/components/FileChangeBoxes';
42
- import { othersPendingBesides } from '../../change-requests/utils/author';
42
+ import { othersPendingBesides } from '../../change-requests';
43
43
  import { ChangeRequestDialog } from '../../change-requests/components/ChangeRequestDialog';
44
- import { formatEligible } from '../../access/hooks/useFileAccess';
45
44
  import { PR_STALE_EVENT } from '../../../core/events';
46
45
  import { suggestedPages } from '../utils/fileTree';
47
- import { getRendererLayout, isViewOnlyFile, pickFileRenderer } from './renderers';
46
+ import { PageToolsContext, getRendererLayout, isViewOnlyFile, pickFileRenderer } from './renderers';
48
47
  import { READ_PANE } from './renderers/readPane';
49
48
  import { CanDownloadContext } from './renderers/DownloadFileButton';
50
- import { PageToolsContext } from './renderers/htmlToolBridge';
51
49
  import type { RendererSaveState } from './renderers';
52
50
  import { KbDocumentShell } from './KbDocumentShell';
53
51
  import { FilePaneCard } from './FilePaneCard';
52
+ import {
53
+ ExitFullScreenButton,
54
+ FULL_SCREEN_ENTRY_SELECTOR,
55
+ FULL_SCREEN_SURFACE,
56
+ FullScreenButton,
57
+ } from './FullScreenView';
58
+ import { useFullScreenView } from '../hooks/useFullScreenView';
59
+ import { carryReadingOffset, readingAnchorIn, readingOffset, readingWidthOf } from './readingCarry';
60
+ import { DOCUMENT_COLUMN_CONTENT, documentSideGutters } from '../../../shared/theme/measure';
54
61
  import { StarterPackCard } from '../../onboarding/components/StarterPackCard';
55
- import { useStarterPacks } from '../../onboarding/state/starter-packs';
62
+ import { useStarterPacks } from '../../onboarding';
56
63
 
57
64
  /**
58
65
  * How many pages the empty viewer offers. Enough to look like a starting
@@ -926,6 +933,106 @@ export function FileViewer() {
926
933
  return () => el.removeEventListener('scroll', onScroll, { capture: true } as EventListenerOptions);
927
934
  }, [editMode, recordActivity]);
928
935
 
936
+ // ── Full screen ──────────────────────────────────────────────────────────
937
+ // The view is the HOST's: the read pane below — the element that already
938
+ // holds the renderer, prose and full-bleed alike — switches its classes to
939
+ // fill the viewport. Same element, same tree, so the renderer never
940
+ // remounts: an editor keeps its unsaved text, an HTML page its script state
941
+ // and its page-tool bridge. A portal, or a second tree, would lose all three.
942
+ // History and comparison are not the renderer, so the view waits for the
943
+ // document to be back (`filling`).
944
+ const fullScreen = useFullScreenView();
945
+ const filling = fullScreen.fullscreen && activeTab === 'content';
946
+ const readPaneRef = useRef<HTMLDivElement>(null);
947
+ // How far into the document the reader was when the view switched. The
948
+ // pane leaving the shell's flow collapses the shell's scroll height (and
949
+ // its scrollTop with it), so the position is carried across by hand: into
950
+ // the pane's own scroller on the way in, back into the shell's on the way
951
+ // out. A full-bleed renderer scrolls inside itself and keeps its own.
952
+ //
953
+ // Measured against the document's BODY (`readingAnchor`), not the pane:
954
+ // between the two views the pane gains padding and the card loses its bar,
955
+ // so the pane's top is a different distance above the text in each, and a
956
+ // carry against it lands the reader that many pixels off. And the text is
957
+ // laid out at the SAME width in both (`readingWidth`): a column that wraps
958
+ // differently puts every line below the first at a different height, and
959
+ // no pixel offset survives that — Section 24 came back as Section 30.
960
+ const readingOffsetRef = useRef<number | null>(null);
961
+ // The card's width on the page at the moment of entry, held while filling
962
+ // the window. Null when the view was opened by URL: there was no page, and
963
+ // the column's own content width stands in.
964
+ const [readingWidth, setReadingWidth] = useState<number | null>(null);
965
+ const { enter: enterFullScreenView, leave: leaveFullScreenView } = fullScreen;
966
+ // Focus crosses the switch the way it crosses a dialog's: in on opening,
967
+ // back on closing. The control that was pressed is captured HERE, before
968
+ // the switch, because the switch itself withdraws it (the pane bar, or the
969
+ // header's button) and focus would fall to the body with it.
970
+ const focusBeforeFullScreenRef = useRef<HTMLElement | null>(null);
971
+ const exitFullScreenRef = useRef<HTMLButtonElement>(null);
972
+ const pageRef = useRef<HTMLDivElement>(null);
973
+ const enterFullScreen = useCallback(() => {
974
+ focusBeforeFullScreenRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
975
+ const shell = editorContainerRef.current;
976
+ const anchor = readingAnchorIn(readPaneRef.current);
977
+ if (shell && anchor) {
978
+ readingOffsetRef.current = readingOffset(shell, anchor);
979
+ setReadingWidth(readingWidthOf(anchor));
980
+ }
981
+ enterFullScreenView();
982
+ }, [enterFullScreenView]);
983
+ const leaveFullScreen = useCallback(() => {
984
+ const pane = readPaneRef.current;
985
+ const anchor = readingAnchorIn(readPaneRef.current);
986
+ if (pane && anchor) readingOffsetRef.current = readingOffset(pane, anchor);
987
+ setReadingWidth(null);
988
+ leaveFullScreenView();
989
+ }, [leaveFullScreenView]);
990
+ // The banners that need the reader's hand — a refused save with what to
991
+ // fix, an agent's update to accept or reject — render in the shell the
992
+ // filled view covers. The view gives way so they are seen, rather than
993
+ // leave the reader pressing Save at a surface that answers nothing.
994
+ useEffect(() => {
995
+ // eslint-disable-next-line react-hooks/set-state-in-effect -- a response to state that arrived from a save's refusal or an agent's update, not a derivation of it; it settles in one extra render
996
+ if (filling && (saveError || isReviewingPending || waitingOnAgentUpdate)) leaveFullScreen();
997
+ }, [filling, saveError, isReviewingPending, waitingOnAgentUpdate, leaveFullScreen]);
998
+
999
+ useLayoutEffect(() => {
1000
+ const offset = readingOffsetRef.current;
1001
+ readingOffsetRef.current = null;
1002
+ const scroller = filling ? readPaneRef.current : editorContainerRef.current;
1003
+ const anchor = readingAnchorIn(readPaneRef.current);
1004
+ if (offset === null || !scroller || !anchor) return;
1005
+ // Put the scroller's top edge `offset` px below the body's top, as it was
1006
+ // in the view just left.
1007
+ carryReadingOffset(scroller, anchor, offset);
1008
+ }, [filling]);
1009
+ // Focus still inside the renderer (an editor's caret, a page's control) is
1010
+ // where the reader is working, and stays there both ways. Otherwise: on
1011
+ // the way in — the button, a URL, a reload — the exit control; on the way
1012
+ // out, the element that had focus before, or, when that is gone or there
1013
+ // never was one (opened by URL), the way back in, else the read pane.
1014
+ // `preventScroll`, so the reading offset carried above is not undone.
1015
+ const wasFillingRef = useRef(false);
1016
+ useEffect(() => {
1017
+ const pane = readPaneRef.current;
1018
+ const keepsFocus = (el: Element | null) => !!pane && !!el && pane.contains(el) && el !== pane;
1019
+ if (filling) {
1020
+ wasFillingRef.current = true;
1021
+ if (!keepsFocus(document.activeElement)) exitFullScreenRef.current?.focus({ preventScroll: true });
1022
+ return;
1023
+ }
1024
+ if (!wasFillingRef.current) return;
1025
+ wasFillingRef.current = false;
1026
+ const before = focusBeforeFullScreenRef.current;
1027
+ focusBeforeFullScreenRef.current = null;
1028
+ if (keepsFocus(document.activeElement)) return;
1029
+ const target =
1030
+ (before?.isConnected ? before : null) ??
1031
+ pageRef.current?.querySelector<HTMLElement>(FULL_SCREEN_ENTRY_SELECTOR) ??
1032
+ pane;
1033
+ target?.focus({ preventScroll: true });
1034
+ }, [filling]);
1035
+
929
1036
  // A page opened for writing (the `startEditing` request above) gets the
930
1037
  // caret at its END — under the title it was created with — rather than
931
1038
  // where a freshly focused textarea puts it, in front of the `#`. Only for
@@ -1191,8 +1298,8 @@ export function FileViewer() {
1191
1298
  // above — not a component created during render. The provider hands the
1192
1299
  // open file's `download:` verdict to any DownloadFileButton inside the
1193
1300
  // renderer without widening the renderer contract. The page-tools
1194
- // provider is what makes this the file page for an HTML page: the one
1195
- // place its `window.bevel.tools` is answered, under its own path.
1301
+ // provider is what answers an HTML page's `window.bevel.tools` here,
1302
+ // under its own path (`htmlToolBridge.ts` lists every host that does).
1196
1303
  <CanDownloadContext.Provider value={access.canDownload}>
1197
1304
  <PageToolsContext.Provider value={{ pagePath: repoRelativePath ?? openFilePath }}>
1198
1305
  {/* eslint-disable-next-line react-hooks/static-components */}
@@ -1337,16 +1444,20 @@ export function FileViewer() {
1337
1444
  <History size={14} />
1338
1445
  </IconButton>
1339
1446
  ) : null;
1340
- const paneActions =
1341
- historyAction || writeAction ? (
1342
- <>
1343
- {historyAction}
1344
- {writeAction}
1345
- </>
1346
- ) : null;
1447
+ // Full screen sits with the file's other actions: here in the pane bar for
1448
+ // a prose document, in the page header for a full-bleed one (which has no
1449
+ // bar). Every file that reaches this point has a renderer, so every one
1450
+ // gets it — read mode and edit mode alike.
1451
+ const paneActions = (
1452
+ <>
1453
+ {historyAction}
1454
+ <FullScreenButton onEnter={enterFullScreen} />
1455
+ {writeAction}
1456
+ </>
1457
+ );
1347
1458
 
1348
1459
  return (
1349
- <div className="h-full w-full flex flex-col bg-white min-w-0 relative">
1460
+ <div ref={pageRef} className="h-full w-full flex flex-col bg-white min-w-0 relative">
1350
1461
  <PullNeededBanner />
1351
1462
  <GitSyncFailedBanner />
1352
1463
  {/* No "you don't have permission to edit" banner, deliberately: for a
@@ -1413,6 +1524,8 @@ export function FileViewer() {
1413
1524
  onShare={handleShare}
1414
1525
  onCopyPage={canCopyPage ? handleCopyPage : undefined}
1415
1526
  onCopyLink={handleCopyLink}
1527
+ // Withdrawn while filling the window: the exit control replaces it.
1528
+ onFullScreen={shellVariant === 'full-bleed' && !filling ? enterFullScreen : undefined}
1416
1529
  />
1417
1530
  }
1418
1531
  >
@@ -1650,20 +1763,50 @@ export function FileViewer() {
1650
1763
  restart at the top of the page. This wrapper stays mounted through
1651
1764
  every state the read goes through, prose and full-bleed alike, so
1652
1765
  it is what focus lands on. See `RetryReadButton`. */}
1766
+ {/* Full screen is THIS element's classes changing, not a second
1767
+ tree: fixed over the whole viewport, above the app's chrome, on
1768
+ the page background. A full-bleed renderer takes the viewport's
1769
+ definite height; a prose one keeps its reading column, centred,
1770
+ with its card's edges and bar withdrawn. While it fills the window
1771
+ it is modal, and says so: everything else of the app is covered,
1772
+ so the shortcuts that open something in that chrome (the command
1773
+ menu, the single-key commands) stand down, as they do for a
1774
+ dialog, rather than open it unseen behind this surface. */}
1653
1775
  <div
1654
1776
  {...READ_PANE}
1655
- className={shellVariant === 'full-bleed' ? 'flex min-h-0 flex-1 flex-col' : 'min-w-0'}
1777
+ ref={readPaneRef}
1778
+ data-full-screen={filling ? '' : undefined}
1779
+ role={filling ? 'dialog' : undefined}
1780
+ aria-modal={filling ? true : undefined}
1781
+ aria-label={filling ? `${fileBaseName}, full screen` : undefined}
1782
+ className={
1783
+ shellVariant === 'full-bleed'
1784
+ ? filling
1785
+ ? `${FULL_SCREEN_SURFACE} flex flex-col`
1786
+ : 'flex min-h-0 flex-1 flex-col'
1787
+ : filling
1788
+ ? `${FULL_SCREEN_SURFACE} ${documentSideGutters(false)} py-10`
1789
+ : 'min-w-0'
1790
+ }
1656
1791
  >
1657
1792
  {shellVariant === 'prose' ? (
1658
1793
  <>
1659
- <FilePaneCard file={fileBaseName} fileTitle={fileNameTooltip(openFilePath, kbDirName)} actions={paneActions}>
1794
+ <FilePaneCard
1795
+ file={fileBaseName}
1796
+ fileTitle={fileNameTooltip(openFilePath, kbDirName)}
1797
+ actions={paneActions}
1798
+ chromeless={filling}
1799
+ className={filling ? DOCUMENT_COLUMN_CONTENT : undefined}
1800
+ // The page's own width, so every line wraps where it did.
1801
+ style={filling && readingWidth !== null ? { maxWidth: readingWidth } : undefined}
1802
+ >
1660
1803
  {rendererElement}
1661
1804
  </FilePaneCard>
1662
1805
  {/* Every open proposal on this file, under the file it is
1663
1806
  about — the same boxes, the same dialog, as the skill
1664
1807
  page. Hidden while the reader IS editing or proposing:
1665
1808
  the diffs are against text that is changing under them. */}
1666
- {!editMode && !proposeMode && repoRelativePath && requestsOnThisFile.length > 0 && (
1809
+ {!filling && !editMode && !proposeMode && repoRelativePath && requestsOnThisFile.length > 0 && (
1667
1810
  <FileChangeBoxes
1668
1811
  repoRelativePath={repoRelativePath}
1669
1812
  requests={requestsOnThisFile}
@@ -1693,6 +1836,7 @@ export function FileViewer() {
1693
1836
  ) : (
1694
1837
  rendererElement
1695
1838
  )}
1839
+ {filling && <ExitFullScreenButton ref={exitFullScreenRef} onExit={leaveFullScreen} surface={readPaneRef} />}
1696
1840
  </div>
1697
1841
  </>
1698
1842
  )}
@@ -0,0 +1,93 @@
1
+ import { useEffect, type Ref, type RefObject } from 'react';
2
+ import { Maximize2, Minimize2 } from 'lucide-react';
3
+ import { IconButton, useModalLayer, useLatestRef } from '../../../shared/components';
4
+ import { isFrameEscape } from '../utils/frameEscape';
5
+
6
+ /**
7
+ * Names the way in, so leaving the view can hand focus back to it: the
8
+ * control that was pressed is withdrawn while the view fills the window, and
9
+ * the one that comes back is a new element.
10
+ */
11
+ export const FULL_SCREEN_ENTRY_SELECTOR = '[data-full-screen-entry]';
12
+
13
+ /** The way in: an icon button beside the file's other actions. */
14
+ export function FullScreenButton({ onEnter }: { onEnter(): void }) {
15
+ return (
16
+ <IconButton data-full-screen-entry="" aria-label="Full screen" title="Full screen" onClick={onEnter}>
17
+ <Maximize2 size={14} />
18
+ </IconButton>
19
+ );
20
+ }
21
+
22
+ /**
23
+ * The way out: one small control pinned to the viewport's top right, and
24
+ * Escape.
25
+ *
26
+ * `fixed` and a layer above the surface it sits in, so neither the renderer's
27
+ * own content nor an HTML page's iframe can scroll it away or cover it.
28
+ * Escape goes through the modal layer stack: a dialog opened on top of the
29
+ * view registers after it, so it is the topmost layer and takes Escape first.
30
+ *
31
+ * An Escape pressed inside a page's frame never reaches this document, so the
32
+ * frame posts one the page left alone instead (`bevel.key`, see
33
+ * `htmlSandbox.ts`), a task after the key. One that comes from a frame inside
34
+ * `surface` (`isFrameEscape`) is pressed here again, on the document, so it
35
+ * meets the app's document- and window-level Escape listeners in their usual
36
+ * order — the modal layer's among them, so a card over the page takes it
37
+ * first. A handler on an element of the app's does not see it: none of them
38
+ * had focus. Any other window's message is not the view's to act on.
39
+ */
40
+ export function ExitFullScreenButton({
41
+ onExit,
42
+ surface,
43
+ ref,
44
+ }: {
45
+ onExit(): void;
46
+ /** The element filling the window; only frames inside it are heard. */
47
+ surface: RefObject<HTMLElement | null>;
48
+ /** The view moves focus here when it opens with none in the renderer. */
49
+ ref?: Ref<HTMLButtonElement>;
50
+ }) {
51
+ const isTopLayer = useModalLayer(true);
52
+ const onExitRef = useLatestRef(onExit);
53
+ useEffect(() => {
54
+ function onKeyDown(e: KeyboardEvent) {
55
+ if (e.key !== 'Escape' || !isTopLayer()) return;
56
+ e.stopPropagation();
57
+ onExitRef.current();
58
+ }
59
+ function onFrameKey(e: MessageEvent) {
60
+ if (!isFrameEscape(e, surface.current)) return;
61
+ document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true, cancelable: true }));
62
+ }
63
+ document.addEventListener('keydown', onKeyDown);
64
+ window.addEventListener('message', onFrameKey);
65
+ return () => {
66
+ document.removeEventListener('keydown', onKeyDown);
67
+ window.removeEventListener('message', onFrameKey);
68
+ };
69
+ }, [isTopLayer, onExitRef, surface]);
70
+
71
+ return (
72
+ <IconButton
73
+ ref={ref}
74
+ data-testid="exit-full-screen"
75
+ aria-label="Exit full screen"
76
+ title="Exit full screen (Esc)"
77
+ aria-keyshortcuts="Escape"
78
+ onClick={onExit}
79
+ className="fixed right-3 top-3 z-[41] bg-surface shadow-md"
80
+ >
81
+ <Minimize2 size={14} />
82
+ </IconButton>
83
+ );
84
+ }
85
+
86
+ /**
87
+ * The classes that make the read pane fill the viewport: above the app's
88
+ * chrome (the sidebar's grip is z-30, its drawer's scrim z-40 only at phone
89
+ * width, where the view hides the toggle that opens it), BELOW the dialogs
90
+ * and menus (z-50 and up), so a confirm opened from the renderer still shows
91
+ * on top.
92
+ */
93
+ export const FULL_SCREEN_SURFACE = 'fixed inset-0 z-40 overflow-auto bg-canvas';
@@ -1,5 +1,5 @@
1
1
  import { Link2 } from 'lucide-react';
2
- import type { AccessEligible } from '../../access/api';
2
+ import type { AccessEligible } from '../../access';
3
3
  import { Badge } from '../../../shared/components';
4
4
  import type { LinkOut } from '../hooks/useLinksOut';
5
5
 
@@ -18,6 +18,7 @@ import { HEADER_BAND, PAGE_HEADER_TESTID, TITLE_INK_ROOM } from '../../../shared
18
18
  import { rootAnchoredPath } from '../utils/pasteLink';
19
19
  import { displayFileName, fileNameTooltip } from '../utils/display-file-name';
20
20
  import { SELF_HOLD_MESSAGE } from '../../workflow';
21
+ import { FullScreenButton } from './FullScreenView';
21
22
 
22
23
  /**
23
24
  * The document's title, and the page's actions beside it.
@@ -134,6 +135,12 @@ export interface KbPageHeaderProps {
134
135
  /** The canonical URL, via `useCanonicalFileUrl`. Its sibling, Copy path,
135
136
  * needs nothing from the caller: it is `path`, root-anchored. */
136
137
  onCopyLink(): Promise<boolean>;
138
+ /**
139
+ * Fill the browser window with the renderer. Given only for a full-bleed
140
+ * file, which has no pane bar to carry the control; a prose document's bar
141
+ * carries it beside Edit. Absent, the header offers none.
142
+ */
143
+ onFullScreen?: () => void;
137
144
  }
138
145
 
139
146
  /**
@@ -182,6 +189,7 @@ export function KbPageHeader({
182
189
  onShare,
183
190
  onCopyPage,
184
191
  onCopyLink,
192
+ onFullScreen,
185
193
  }: KbPageHeaderProps) {
186
194
  const [shareOpen, setShareOpen] = useState(false);
187
195
  const [copied, setCopied] = useState<Record<string, CopyState>>({});
@@ -466,6 +474,7 @@ export function KbPageHeader({
466
474
  <History size={14} />
467
475
  </IconButton>
468
476
  )}
477
+ {onFullScreen && <FullScreenButton onEnter={onFullScreen} />}
469
478
  </div>
470
479
  </div>
471
480
  );