@bevel-software/platform-core-frontend 0.20.0 → 0.22.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 (64) hide show
  1. package/package.json +2 -2
  2. package/src/core/registry.ts +57 -0
  3. package/src/modules/access/__tests__/ManageAccessDialog.request.test.tsx +376 -0
  4. package/src/modules/access/components/AccessRequestControl.tsx +155 -0
  5. package/src/modules/{library → access}/components/AccessRequestsBanner.tsx +62 -24
  6. package/src/modules/access/components/ManageAccessDialog.tsx +81 -4
  7. package/src/modules/access/hooks/useAccessRequests.ts +183 -0
  8. package/src/modules/access/hooks/useFileAccess.ts +2 -2
  9. package/src/modules/access/requests.api.ts +121 -0
  10. package/src/modules/auth/components/LoginScreen.tsx +6 -0
  11. package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +171 -38
  12. package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +34 -19
  13. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +173 -6
  14. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +155 -98
  15. package/src/modules/git/components/BranchSwitcher.tsx +9 -3
  16. package/src/modules/git/components/FileComparisonPanel.tsx +10 -4
  17. package/src/modules/git/components/PullNeededBanner.tsx +2 -2
  18. package/src/modules/git/services/error-messages.ts +2 -2
  19. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +110 -9
  20. package/src/modules/layout/components/SidebarFrame.tsx +26 -9
  21. package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +11 -0
  22. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +3 -0
  23. package/src/modules/library/__tests__/PluginIndexRow.test.tsx +146 -0
  24. package/src/modules/library/__tests__/PluginPage.test.tsx +110 -3
  25. package/src/modules/library/__tests__/SkillPage.test.tsx +15 -0
  26. package/src/modules/library/__tests__/ToolPage.test.tsx +34 -0
  27. package/src/modules/library/__tests__/name-with-badges.test.tsx +16 -3
  28. package/src/modules/library/__tests__/title-row-actions.ts +95 -0
  29. package/src/modules/library/components/PluginIndexRow.tsx +37 -20
  30. package/src/modules/library/components/PluginJoinRequests.tsx +2 -2
  31. package/src/modules/library/components/PluginPage.tsx +115 -3
  32. package/src/modules/library/components/skill-page/SkillPage.tsx +2 -2
  33. package/src/modules/library/components/tool-page/ToolPage.tsx +36 -18
  34. package/src/modules/library/hooks/useJoinRequests.ts +26 -101
  35. package/src/modules/library/routes/library-paths.ts +9 -2
  36. package/src/modules/library/services/plugins.api.ts +45 -0
  37. package/src/modules/library/utils/plugin-summary.ts +7 -2
  38. package/src/modules/onboarding/__tests__/onboarding.test.tsx +43 -0
  39. package/src/modules/onboarding/components/ConnectAgentPill.tsx +13 -2
  40. package/src/modules/pr/components/OpenChangeRequestDialog.tsx +3 -2
  41. package/src/modules/pr/services/pr-merge.api.ts +10 -2
  42. package/src/modules/review/components/ReviewPanel.tsx +2 -2
  43. package/src/modules/settings/components/DeploymentPage.tsx +22 -0
  44. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +72 -4
  45. package/src/modules/setup/__tests__/setup.first-run.test.tsx +276 -0
  46. package/src/modules/setup/__tests__/setup.github.test.tsx +416 -0
  47. package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +275 -0
  48. package/src/modules/setup/__tests__/setup.repository.test.tsx +373 -0
  49. package/src/modules/setup/__tests__/setup.test.tsx +8 -14
  50. package/src/modules/setup/components/GitHubRepositoryPanel.tsx +369 -0
  51. package/src/modules/setup/components/SetupGate.tsx +1 -0
  52. package/src/modules/setup/components/SetupScreen.tsx +464 -38
  53. package/src/modules/setup/services/setup.api.ts +93 -0
  54. package/src/modules/setup/utils/kept-draft.ts +86 -0
  55. package/src/modules/workspace/components/FileExplorer.tsx +4 -2
  56. package/src/modules/workspace/components/FileViewer.tsx +8 -3
  57. package/src/modules/workspace/components/KbDocumentShell.tsx +50 -8
  58. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +49 -0
  59. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +49 -1
  60. package/src/modules/workspace/hooks/useWorkspaceState.ts +7 -2
  61. package/src/modules/workspace/utils/fileTree.ts +2 -1
  62. package/src/modules/workspace/utils/treeConfirm.ts +7 -3
  63. package/src/shared/components/SlotBoundary.tsx +51 -0
  64. package/src/shared/theme/measure.ts +23 -2
@@ -72,6 +72,28 @@ export interface KbInitFailure {
72
72
  cause: string;
73
73
  }
74
74
 
75
+ /**
76
+ * A way a deployment can have the repository its knowledge base lives in:
77
+ * one it keeps itself, one on GitHub reached through a GitHub App, or one on
78
+ * any git host reached by its address and a token.
79
+ */
80
+ export type GitMode = 'managed' | 'github-app' | 'token';
81
+
82
+ /** The ways this deployment offers, in the order they are shown, and the one it is on. */
83
+ export interface RepositoryStatus {
84
+ /** The way IN EFFECT: the one the running deployment is on. Null on a deployment that has no repository yet. */
85
+ mode: GitMode | null;
86
+ /**
87
+ * The way the settings say, which a restart puts in effect. Differs from
88
+ * `mode` between a move and the restart it owes. Absent from a server
89
+ * that does not tell the two apart.
90
+ */
91
+ chosen?: GitMode | null;
92
+ /** The environment variable that chose for the deployment, when one did: the choice is then not the screen's to make. */
93
+ pinned?: string;
94
+ modes: GitMode[];
95
+ }
96
+
75
97
  export interface SetupStatus {
76
98
  /** Reachable knowledge base AND a process that can serve it. */
77
99
  complete: boolean;
@@ -92,6 +114,8 @@ export interface SetupStatus {
92
114
  sync?: SyncStatus;
93
115
  /** Admins only. Absent from an older server. */
94
116
  oidcVerification?: OidcVerification;
117
+ /** Admins only. Absent from a server that knows one way of having a repository. */
118
+ repository?: RepositoryStatus;
95
119
  }
96
120
 
97
121
  export interface SaveResult {
@@ -100,6 +124,7 @@ export interface SaveResult {
100
124
  awaitingRestart?: boolean;
101
125
  settings: SettingStatus[];
102
126
  oidcVerification?: OidcVerification;
127
+ repository?: RepositoryStatus;
103
128
  }
104
129
 
105
130
  /** Field-keyed messages, so the form can mark the input that was wrong. */
@@ -319,3 +344,71 @@ export async function testOidc(fields: Record<string, string>): Promise<OidcTest
319
344
  if (!res.ok) await readError(res);
320
345
  return (await res.json()) as OidcTest;
321
346
  }
347
+
348
+ /** Where a deployment's connection to GitHub through a GitHub App stands. */
349
+ export interface GitHubAppStatus {
350
+ /** Who supplied the app. Null: there is none yet, and this deployment can register its own. */
351
+ registeredBy: 'environment' | 'setup' | null;
352
+ app: { slug: string; url: string } | null;
353
+ /** The installation, and the account it is on, once the app is installed. */
354
+ installation: { id: string; account: string } | null;
355
+ /** `owner/name`, once one is chosen. */
356
+ repository: string | null;
357
+ }
358
+
359
+ /** A repository the installation reaches. */
360
+ export interface GitHubRepository {
361
+ fullName: string;
362
+ private: boolean;
363
+ defaultBranch: string;
364
+ writable: boolean;
365
+ }
366
+
367
+ export async function fetchGitHubApp(): Promise<GitHubAppStatus> {
368
+ const res = await authFetch('/api/setup/github-app');
369
+ if (!res.ok) await readError(res);
370
+ return (await res.json()) as GitHubAppStatus;
371
+ }
372
+
373
+ /** The manifest of this deployment's own app, and the address on GitHub the browser posts it to. */
374
+ export async function startGitHubAppRegistration(
375
+ organization: string,
376
+ ): Promise<{ action: string; manifest: Record<string, unknown> }> {
377
+ const res = await authFetch('/api/setup/github-app/manifest', {
378
+ method: 'POST',
379
+ headers: { 'Content-Type': 'application/json' },
380
+ body: JSON.stringify(organization ? { organization } : {}),
381
+ });
382
+ if (!res.ok) await readError(res);
383
+ return (await res.json()) as { action: string; manifest: Record<string, unknown> };
384
+ }
385
+
386
+ export async function fetchGitHubRepositories(): Promise<{ repositories: GitHubRepository[]; more: boolean }> {
387
+ const res = await authFetch('/api/setup/github-app/repositories');
388
+ if (!res.ok) await readError(res);
389
+ return (await res.json()) as { repositories: GitHubRepository[]; more: boolean };
390
+ }
391
+
392
+ /**
393
+ * Where on GitHub the app is installed, for the browser to be sent to. Asked
394
+ * for, never linked to: asking is what starts the round trip, and a link
395
+ * would let anyone start one in an admin's browser.
396
+ */
397
+ export async function startGitHubAppInstallation(): Promise<string> {
398
+ const res = await authFetch('/api/setup/github-app/install', { method: 'POST' });
399
+ if (!res.ok) await readError(res);
400
+ return ((await res.json()) as { url: string }).url;
401
+ }
402
+
403
+ /**
404
+ * Where to sign in on GitHub so the deployment can read again which
405
+ * repositories may be connected. Nothing is installed: GitHub sends the
406
+ * browser straight back. It is how a repository added to the installation
407
+ * on GitHub gets into the list, since GitHub sends nobody back from the
408
+ * page it is added on.
409
+ */
410
+ export async function startGitHubAppRefresh(): Promise<string> {
411
+ const res = await authFetch('/api/setup/github-app/refresh', { method: 'POST' });
412
+ if (!res.ok) await readError(res);
413
+ return ((await res.json()) as { url: string }).url;
414
+ }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * What was typed on the setup screen, kept across a trip to another site.
3
+ *
4
+ * Connecting GitHub takes the browser away, twice: once to create the app,
5
+ * once to install it. The page that comes back is a new page, and the form
6
+ * on it is empty. An admin who had named their branches, renamed a folder
7
+ * or started on single sign-on before pressing "Create the GitHub App"
8
+ * would find all of it gone, with nothing to say it had been there.
9
+ *
10
+ * So what was typed is kept in this tab for the length of the trip and put
11
+ * back on return.
12
+ *
13
+ * SECRETS ARE NOT KEPT. An access token or an application secret typed into
14
+ * the form lives in the page's memory and nowhere else; writing it to the
15
+ * browser's storage would leave it readable by any script on the page and
16
+ * lying there after the tab moved on. They are dropped, and the screen says
17
+ * which ones to enter again, which is a smaller loss than the one this
18
+ * exists to prevent.
19
+ *
20
+ * Session storage, so it is this tab's alone and goes with the tab. It is
21
+ * good for half an hour and for one return: read once, then removed.
22
+ */
23
+
24
+ const KEY = 'hexis_setup_draft';
25
+ const GOOD_FOR_MS = 30 * 60_000;
26
+
27
+ export interface KeptDraft {
28
+ /** What was typed, without the secrets. */
29
+ draft: Record<string, string>;
30
+ /** The secrets that were typed and not kept, by setting key. */
31
+ dropped: string[];
32
+ }
33
+
34
+ const NOTHING: KeptDraft = { draft: {}, dropped: [] };
35
+
36
+ /**
37
+ * Keep what was typed, ahead of leaving the page. `isSecret` says which
38
+ * settings are. Storage that refuses (a private window, a policy) keeps
39
+ * nothing, which is where things stood before.
40
+ */
41
+ export function keepDraft(draft: Record<string, string>, isSecret: (key: string) => boolean, now: number = Date.now()): void {
42
+ const typed = Object.entries(draft).filter(([, value]) => value.trim() !== '');
43
+ const kept: KeptDraft & { at: number } = {
44
+ draft: Object.fromEntries(typed.filter(([key]) => !isSecret(key))),
45
+ dropped: typed.filter(([key]) => isSecret(key)).map(([key]) => key),
46
+ at: now,
47
+ };
48
+ try {
49
+ if (Object.keys(kept.draft).length === 0 && kept.dropped.length === 0) sessionStorage.removeItem(KEY);
50
+ else sessionStorage.setItem(KEY, JSON.stringify(kept));
51
+ } catch {
52
+ // Nothing is kept.
53
+ }
54
+ }
55
+
56
+ /**
57
+ * What was kept, if it is still good. Reading does not remove it, so it can
58
+ * be read while the page is being built; {@link forgetDraft} removes it
59
+ * once the page has it. A secret is never returned, whatever the storage
60
+ * holds: `isSecret` is asked again on the way out.
61
+ */
62
+ export function keptDraft(isSecret: (key: string) => boolean, now: number = Date.now()): KeptDraft {
63
+ try {
64
+ const raw = sessionStorage.getItem(KEY);
65
+ if (!raw) return NOTHING;
66
+ const kept = JSON.parse(raw) as Partial<KeptDraft> & { at?: unknown };
67
+ if (typeof kept.at !== 'number' || now - kept.at > GOOD_FOR_MS || now < kept.at) return NOTHING;
68
+ const draft: Record<string, string> = {};
69
+ for (const [key, value] of Object.entries(kept.draft ?? {})) {
70
+ if (typeof value === 'string' && !isSecret(key)) draft[key] = value;
71
+ }
72
+ const dropped = Array.isArray(kept.dropped) ? kept.dropped.filter((key): key is string => typeof key === 'string') : [];
73
+ return { draft, dropped };
74
+ } catch {
75
+ return NOTHING;
76
+ }
77
+ }
78
+
79
+ /** Remove what was kept: the page has it, or the trip it was kept for is not the one that brought the browser here. */
80
+ export function forgetDraft(): void {
81
+ try {
82
+ sessionStorage.removeItem(KEY);
83
+ } catch {
84
+ // There was nothing to remove from.
85
+ }
86
+ }
@@ -28,6 +28,7 @@ import {
28
28
  } from 'lucide-react';
29
29
  import type { FileTreeEntry } from '@bevel-software/platform-shared';
30
30
  import {
31
+ currentBranchModel,
31
32
  isProtectedBranch,
32
33
  validateFilename,
33
34
  KNOWLEDGE_BASE_DIR,
@@ -1822,7 +1823,7 @@ export function TreeChrome({
1822
1823
  const focusAfterConfirm = useRef<(() => HTMLElement | null) | null>(null);
1823
1824
  useEffect(() => {
1824
1825
  if (confirmRequest?.kind !== 'move' || !workspaceId || !kbDirName) return;
1825
- if (!isProtectedBranch(decodeURIComponent(workspaceId))) return;
1826
+ if (!isProtectedBranch(currentBranchModel(), decodeURIComponent(workspaceId))) return;
1826
1827
  const prefix = `${kbDirName}/`;
1827
1828
  if (!confirmRequest.targetDir.startsWith(prefix)) return;
1828
1829
  let cancelled = false;
@@ -2106,7 +2107,8 @@ function useCanWriteFolder(workspacePath: string | null): boolean {
2106
2107
  const isKbRoot = workspacePath !== null && workspacePath === kbDirName;
2107
2108
  const shortCircuit =
2108
2109
  key !== null &&
2109
- ((!isKbRoot && !workspacePath!.startsWith(prefix!)) || !isProtectedBranch(decodeURIComponent(workspaceId!)));
2110
+ ((!isKbRoot && !workspacePath!.startsWith(prefix!)) ||
2111
+ !isProtectedBranch(currentBranchModel(), decodeURIComponent(workspaceId!)));
2110
2112
  useEffect(() => {
2111
2113
  if (key === null || shortCircuit) return;
2112
2114
  let cancelled = false;
@@ -962,10 +962,15 @@ export function FileViewer() {
962
962
 
963
963
  // Which shape the document column takes. A history / comparison panel is a
964
964
  // fixed-height viewport with its own scroller (both roots are
965
- // `flex-1 flex flex-col min-h-0`), so it gets the full-bleed contract for
966
- // the same reason a PDF does — an auto-height column would collapse it.
965
+ // `flex-1 flex flex-col min-h-0`), so it needs the definite height a PDF
966
+ // needs — but NOT the full bleed. It is standing in for the document, in the
967
+ // document's place, and a panel that threw the column away took the title,
968
+ // the tab strip and the timeline with it: the heading ran into the pane's
969
+ // left edge and the commit list started flush against it, so going to
970
+ // history and coming back moved every row on the page. `panel` is the
971
+ // reading view's column with full-bleed's height — see `KbDocumentShell`.
967
972
  const shellVariant =
968
- activeTab === 'content' ? getRendererLayout(openFilePath) : 'full-bleed';
973
+ activeTab === 'content' ? getRendererLayout(openFilePath) : 'panel';
969
974
 
970
975
  // No-preview routes (legacy Office, ODF) have no editing surface at all —
971
976
  // offering Edit/Propose there would acquire a lock for a mode the renderer
@@ -4,6 +4,7 @@ import {
4
4
  DOCUMENT_COLUMN,
5
5
  DOCUMENT_COLUMN_WIDE,
6
6
  documentGutters,
7
+ documentSideGutters,
7
8
  } from '../../../shared/theme/measure';
8
9
  import { HEADER_COLUMN_TOP } from '../../../shared/theme/header';
9
10
 
@@ -22,7 +23,12 @@ import { HEADER_COLUMN_TOP } from '../../../shared/theme/header';
22
23
  * It mounts inside it BELOW the title bar, though — see `header`.
23
24
  */
24
25
  export interface KbDocumentShellProps {
25
- /** Widens the column and opens the second track for the rail. */
26
+ /**
27
+ * Widens the column and opens the second track for the rail. Read by the
28
+ * 'prose' and 'full-bleed' variants only: 'panel' is the document column
29
+ * standing in for the document, and the pages that use it (history,
30
+ * comparison) withdraw the rail with the document it describes.
31
+ */
26
32
  rail?: ReactNode;
27
33
  /**
28
34
  * 'prose' — the shell scrolls, holds the 880/980 measure and the gutters.
@@ -35,12 +41,22 @@ export interface KbDocumentShellProps {
35
41
  * auto-height column), image, csv, xlsx, the html sandbox
36
42
  * iframe, and the tool form (whose `w-72` aside does not fit
37
43
  * inside 880px minus gutters).
44
+ * 'panel' — the reading view's COLUMN with full-bleed's HEIGHT: the same
45
+ * 880px measure and the same side margins as 'prose', and a
46
+ * definite height so a panel that scrolls inside itself gets
47
+ * real pixels. For the file page's history and comparison
48
+ * modes, which are viewports the way a PDF is but which take
49
+ * the DOCUMENT's place and must not move it: switching to
50
+ * history changes what is in the column, not where the column
51
+ * is. They used to take 'full-bleed', which gave the title
52
+ * nothing to stand on at the pane's left edge and started the
53
+ * timeline flush against it.
38
54
  *
39
55
  * The caller picks from the extension, via `getRendererLayout` in
40
56
  * `renderers/index.ts` — the same map `getFileRenderer` uses. Getting this
41
57
  * wrong does not type-error; it renders a zero-height PDF.
42
58
  */
43
- variant?: 'prose' | 'full-bleed';
59
+ variant?: 'prose' | 'full-bleed' | 'panel';
44
60
  /**
45
61
  * The file tree beside this column is hidden, so the space it gave up should
46
62
  * become margin on both sides rather than more line length (proto:709). The
@@ -54,10 +70,11 @@ export interface KbDocumentShellProps {
54
70
  * and is the only thing resetting the file lock's idle-release timer for a
55
71
  * user who is reading rather than typing. Scroll events do not bubble, so a
56
72
  * ref on an element nested *inside* the scroller never fires — which is why
57
- * the ref lands on this component's outermost box in BOTH variants, and why
58
- * that box carries `overflow-auto` in both. In `full-bleed` the child is
59
- * exactly `h-full`, so nothing overflows and no scrollbar appears; the
60
- * listener still catches the renderer's own scroller during capture.
73
+ * the ref lands on this component's outermost box in EVERY variant, and why
74
+ * that box carries `overflow-auto` in all of them. In `full-bleed` and
75
+ * `panel` the child is exactly `h-full`, so nothing overflows and no
76
+ * scrollbar appears; the listener still catches the renderer's own scroller
77
+ * during capture.
61
78
  */
62
79
  scrollRef?: Ref<HTMLDivElement>;
63
80
  /**
@@ -104,10 +121,35 @@ export function KbDocumentShell({
104
121
  data-variant={variant}
105
122
  className={cn(
106
123
  'relative min-h-0 flex-1 overflow-auto',
107
- variant === 'full-bleed' && 'flex flex-col',
124
+ variant !== 'prose' && 'flex flex-col',
108
125
  )}
109
126
  >
110
- {variant === 'full-bleed' ? (
127
+ {variant === 'panel' ? (
128
+ // The reading view's frame, to the class: `DOCUMENT_COLUMN` and
129
+ // `documentSideGutters` are the same two calls the prose branch below
130
+ // makes, from the same `roomy` flag, so the title, the tab strip and
131
+ // whatever panel follows them all open on the margin the document
132
+ // opens on. The tests compare the two frames rather than restating
133
+ // either — `__tests__/KbDocumentShell.test.tsx` on the component and
134
+ // `__tests__/FileViewer.test.tsx` on the real page going into history
135
+ // and coming back.
136
+ //
137
+ // What differs is the height and the bottom: `h-full min-h-0 flex-col`
138
+ // hands the panel a definite box to scroll inside, exactly as
139
+ // full-bleed does for a PDF, and the 110px rhythm under a document is
140
+ // left off a column that ends where the pane does.
141
+ <div
142
+ className={cn(
143
+ DOCUMENT_COLUMN,
144
+ documentSideGutters(roomy),
145
+ HEADER_COLUMN_TOP,
146
+ 'flex h-full min-h-0 flex-col',
147
+ )}
148
+ >
149
+ {header}
150
+ {children}
151
+ </div>
152
+ ) : variant === 'full-bleed' ? (
111
153
  // A definite height, not a scroll. `h-full` resolves against this
112
154
  // component's own (flex-sized, definite) height, so an `h-full` iframe
113
155
  // inside gets real pixels instead of collapsing to zero.
@@ -859,6 +859,55 @@ describe('FileViewer', () => {
859
859
  expect(screen.getByRole('button', { name: 'Version history' })).toBeInTheDocument();
860
860
  });
861
861
 
862
+ /**
863
+ * The log stands in for the document, in the document's PLACE.
864
+ *
865
+ * It used to take the full-bleed contract — right about the height it
866
+ * needs, wrong about everything else: the column went with it, so the title
867
+ * ran into the pane's left edge and the timeline started flush against it,
868
+ * and going to history and coming back moved every row on the page.
869
+ * `panel` is the reading view's column with full-bleed's height, so the
870
+ * frame is the SAME frame and the assertion can say so without naming a
871
+ * single measurement.
872
+ */
873
+ it('keeps the document column when the log takes the place of the document', async () => {
874
+ const user = userEvent.setup();
875
+ render(<ViewerHarness initialContent="historic" />);
876
+
877
+ const frameOf = () =>
878
+ [...(screen.getByTestId('kb-document-shell').firstElementChild as HTMLElement).classList]
879
+ // The measure, the side margins and the offset the band opens on —
880
+ // everything that decides WHERE the column is. What the two modes are
881
+ // allowed to differ on is how the box below is sized: a document
882
+ // scrolls and ends on the bottom rhythm, a panel fills the pane.
883
+ .filter((cls) => /^(mx-auto|w-full|max-w-|px-|pt-|max-\[900px\]:px-)/.test(cls))
884
+ .sort();
885
+
886
+ const reading = frameOf();
887
+ // Non-empty, or the filter has stopped matching anything and the two
888
+ // empty lists below would agree about nothing.
889
+ expect(reading).toContain('max-w-[880px]');
890
+ expect(reading).toContain('px-[40px]');
891
+
892
+ await user.click(screen.getByRole('button', { name: 'Version history' }));
893
+ await screen.findByRole('button', { name: /Back to the document/ });
894
+ expect(screen.getByTestId('kb-document-shell').getAttribute('data-variant')).toBe('panel');
895
+ expect(frameOf()).toEqual(reading);
896
+
897
+ // The title is in that column, not beside it — the clipping Juan saw was
898
+ // a heading with no margin to stand on.
899
+ const column = screen.getByTestId('kb-document-shell').firstElementChild as HTMLElement;
900
+ expect(column).toContainElement(screen.getByRole('heading', { level: 1 }));
901
+ // So are the tab strip and the log itself.
902
+ expect(column).toContainElement(screen.getByRole('tablist', { name: 'Open files' }));
903
+ expect(column).toContainElement(screen.getByText(/Timeline:/));
904
+
905
+ // …and back: nothing about the frame moved.
906
+ await user.click(screen.getByRole('button', { name: /Back to the document/ }));
907
+ expect(await screen.findByRole('button', { name: 'Edit' })).toBeInTheDocument();
908
+ expect(frameOf()).toEqual(reading);
909
+ });
910
+
862
911
  it('closes Version history from the pressed clock in the header', async () => {
863
912
  const user = userEvent.setup();
864
913
  render(<ViewerHarness initialContent="historic" />);
@@ -24,6 +24,7 @@ describe('KbDocumentShell', () => {
24
24
  it.each([
25
25
  ['prose', {}],
26
26
  ['full-bleed', { variant: 'full-bleed' as const }],
27
+ ['panel', { variant: 'panel' as const }],
27
28
  ['with a rail', { rail: <p>About this file</p> }],
28
29
  ])('puts the header first in the column (%s)', (_name, props) => {
29
30
  render(
@@ -99,13 +100,60 @@ describe('KbDocumentShell', () => {
99
100
  expect(box.className).toContain('h-full');
100
101
  });
101
102
 
103
+ /**
104
+ * `panel` is the reading view's COLUMN with full-bleed's HEIGHT — the one
105
+ * variant that has to agree with another one, so it is asserted against the
106
+ * prose column rather than against a list of classes copied out of
107
+ * `measure.ts`.
108
+ *
109
+ * The file page's history and comparison modes use it. They are viewports
110
+ * the way a PDF is, and they took 'full-bleed' for that reason; what they
111
+ * are not is a renderer the document makes room for. They stand IN the
112
+ * document's place, so the column has to stay exactly where the document
113
+ * left it, which is what this compares.
114
+ */
115
+ it('gives a panel the prose column, minus the rhythm a document ends on', () => {
116
+ const frameOf = (text: string) => (screen.getByText(text).parentElement as HTMLElement).className;
117
+
118
+ const prose = render(
119
+ <KbDocumentShell roomy>
120
+ <p>The document</p>
121
+ </KbDocumentShell>,
122
+ );
123
+ const reading = frameOf('The document');
124
+ prose.unmount();
125
+
126
+ render(
127
+ <KbDocumentShell variant="panel" roomy>
128
+ <p>The log</p>
129
+ </KbDocumentShell>,
130
+ );
131
+ const panel = frameOf('The log');
132
+
133
+ // The measure, the margins and the offset the band opens on: identical,
134
+ // and read off the reading view rather than restated.
135
+ for (const cls of ['mx-auto', 'max-w-[880px]', 'px-[64px]', 'max-[900px]:px-[18px]', 'pt-3']) {
136
+ expect(reading).toContain(cls);
137
+ expect(panel).toContain(cls);
138
+ }
139
+ // `roomy` reaches it too, or a panel would keep the nav's margins on a
140
+ // page that has hidden the nav.
141
+ expect(panel).not.toContain('px-[40px]');
142
+
143
+ // A definite height instead of the bottom rhythm — a column that ends
144
+ // where the pane does has nothing to leave room after.
145
+ expect(panel).toContain('h-full');
146
+ expect(panel).not.toContain('pb-[110px]');
147
+ expect(reading).toContain('pb-[110px]');
148
+ });
149
+
102
150
  // The regression this file exists for. `editorContainerRef` carries a
103
151
  // capture-phase scroll listener that is the file lock's ONLY activity signal
104
152
  // for someone who is reading rather than typing. Scroll events do not
105
153
  // bubble, so a ref on an element nested inside the scroller never fires —
106
154
  // and nothing type-errors when that happens; locks just silently drop out
107
155
  // from under readers after two minutes.
108
- it.each(['prose', 'full-bleed'] as const)(
156
+ it.each(['prose', 'full-bleed', 'panel'] as const)(
109
157
  'lands scrollRef on the element that scrolls (%s)',
110
158
  (variant) => {
111
159
  const ref = createRef<HTMLDivElement>();
@@ -1,5 +1,10 @@
1
1
  import { useState, useCallback, useContext, useEffect, useMemo, useRef } from 'react';
2
- import { DEFAULT_BRANCH, isProtectedBranch, type FileTreeEntry } from '@bevel-software/platform-shared';
2
+ import {
3
+ DEFAULT_BRANCH,
4
+ currentBranchModel,
5
+ isProtectedBranch,
6
+ type FileTreeEntry,
7
+ } from '@bevel-software/platform-shared';
3
8
  import { useEventBus, canonicalizeWorkspaceId } from '../../workflow/state/event-bus.context';
4
9
  import { AuthContext } from '../../auth/state/auth.context';
5
10
  import { fetchFileAccess } from '../../access/api';
@@ -810,7 +815,7 @@ export function useWorkspaceState(): UseWorkspaceStateReturn {
810
815
  const resolveSuggestionRouting = useCallback(
811
816
  async (targetDirectory: string): Promise<KnowledgeSuggestionTarget | null> => {
812
817
  if (!workspaceId || !kbDirName || !authUser) return null;
813
- if (!isProtectedBranch(decodeURIComponent(workspaceId))) return null;
818
+ if (!isProtectedBranch(currentBranchModel(), decodeURIComponent(workspaceId))) return null;
814
819
  const prefix = `${kbDirName}/`;
815
820
  if (!targetDirectory.startsWith(prefix)) return null;
816
821
  const repoRelative = targetDirectory.slice(prefix.length);
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  KNOWLEDGE_BASE_DIR,
3
+ currentKbLayout,
3
4
  reservedRootDirNames,
4
5
  type FileTreeEntry,
5
6
  } from '@bevel-software/platform-shared';
@@ -12,7 +13,7 @@ import type { PendingEntry } from '../state/workspace.context';
12
13
  // folded into Knowledge as stray content. A function, not a module-scope set:
13
14
  // three of the names are configurable and arrive after this module loads.
14
15
  export const KB_ROOT_DIRS = {
15
- has: (name: string): boolean => reservedRootDirNames().has(name),
16
+ has: (name: string): boolean => reservedRootDirNames(currentKbLayout()).has(name),
16
17
  };
17
18
 
18
19
  /**
@@ -1,4 +1,5 @@
1
1
  import {
2
+ currentKbLayout,
2
3
  isPlatformFile,
3
4
  isPlatformRestoreShape,
4
5
  isRootPlatformFile,
@@ -41,7 +42,7 @@ export function platformFileMoveRefusal(
41
42
  ): string | null {
42
43
  const rel = repoRelative(wsRelativePath, kbDirName);
43
44
  if (rel === null) return null;
44
- return isPlatformFile(rel) ? platformFileRefusal(rel) : null;
45
+ return isPlatformFile(rel, currentKbLayout()) ? platformFileRefusal(rel) : null;
45
46
  }
46
47
 
47
48
  /**
@@ -71,7 +72,7 @@ export function platformFileDragRefusal(
71
72
  const refusal = platformFileMoveRefusal(wsRelativePath, kbDirName);
72
73
  if (refusal === null || !isAdmin) return refusal;
73
74
  const rel = repoRelative(wsRelativePath, kbDirName);
74
- return rel === null || isRootPlatformFile(rel) ? refusal : null;
75
+ return rel === null || isRootPlatformFile(rel, currentKbLayout()) ? refusal : null;
75
76
  }
76
77
 
77
78
  /**
@@ -303,7 +304,10 @@ export function moveWarnings(opts: {
303
304
  const from = repoRelative(opts.sourcePath, opts.kbDirName);
304
305
  const to = repoRelative(destination, opts.kbDirName);
305
306
  const restore =
306
- opts.isAdmin === true && from !== null && to !== null && isPlatformRestoreShape(from, to);
307
+ opts.isAdmin === true &&
308
+ from !== null &&
309
+ to !== null &&
310
+ isPlatformRestoreShape(from, to, currentKbLayout());
307
311
  warnings.push(
308
312
  restore
309
313
  ? `You can't write to ${opts.destinationLabel}, but putting ${name} back where the platform reads it is allowed for an Admin.`
@@ -0,0 +1,51 @@
1
+ import { Component, type ErrorInfo, type ReactNode } from 'react';
2
+ import { Banner } from './Banner';
3
+
4
+ interface SlotBoundaryProps {
5
+ children: ReactNode;
6
+ /**
7
+ * What the slot holds, as the page would name it to the person reading:
8
+ * "workspace panel". It completes the sentence shown in its place.
9
+ */
10
+ label: string;
11
+ }
12
+
13
+ interface SlotBoundaryState {
14
+ failed: boolean;
15
+ }
16
+
17
+ /**
18
+ * A fence around a component core did not write.
19
+ *
20
+ * A registry slot hands part of a core page to the distribution that runs
21
+ * it. Without a boundary, a throw while that component renders unmounts the
22
+ * whole page around it, because React takes down the nearest tree that has
23
+ * one — so a fault in the part core knows nothing about would cost the
24
+ * person the part core does own. The slot's failure stays the slot's: its
25
+ * place says it could not be shown, and everything else on the page stands.
26
+ *
27
+ * It does not retry. What failed is the distribution's code on this render;
28
+ * rendering it again gets the same throw, and the page has a reload for the
29
+ * day the cause was something that passes.
30
+ */
31
+ export class SlotBoundary extends Component<SlotBoundaryProps, SlotBoundaryState> {
32
+ state: SlotBoundaryState = { failed: false };
33
+
34
+ static getDerivedStateFromError(): SlotBoundaryState {
35
+ return { failed: true };
36
+ }
37
+
38
+ componentDidCatch(error: Error, info: ErrorInfo) {
39
+ console.error(`[slot] the ${this.props.label} failed to render`, error, info.componentStack);
40
+ }
41
+
42
+ render() {
43
+ if (!this.state.failed) return this.props.children;
44
+ return (
45
+ <Banner tone="danger" role="alert">
46
+ The {this.props.label} couldn&rsquo;t be shown. The rest of this page is unaffected; reload to try
47
+ again.
48
+ </Banner>
49
+ );
50
+ }
51
+ }
@@ -57,11 +57,32 @@ export const DOCUMENT_COLUMN_WIDE = 'mx-auto w-full max-w-[980px]';
57
57
  * drops the bottom rhythm from 110px to 90px (proto:623-632) — that part is a
58
58
  * genuine viewport rule and stays a media query.
59
59
  */
60
- const GUTTER_TAIL = 'pb-[110px] max-[900px]:px-[18px] max-[900px]:pb-[90px]';
60
+ const BOTTOM_RHYTHM = 'pb-[110px] max-[900px]:pb-[90px]';
61
61
 
62
62
  /**
63
+ * The SIDES alone — the column's left and right margins, without the rhythm
64
+ * below the last paragraph.
65
+ *
66
+ * Split out for the column that is a VIEWPORT rather than a document: the
67
+ * file page in history or comparison mode fills the pane's height with a
68
+ * panel that scrolls inside itself, and 110px of padding under a panel like
69
+ * that is not breathing room after the text, it is 110px the timeline does
70
+ * not get. The margins are the part that has to agree with the reading view
71
+ * — they are what "switching to history moves nothing but the content" means
72
+ * — so they are what this returns, and the two callers differ in the bottom
73
+ * rhythm and in nothing else.
74
+ *
75
+ * @param roomy the nav beside this column is hidden, so the space it gave up
76
+ * becomes margin on both sides rather than more line length.
77
+ */
78
+ export const documentSideGutters = (roomy: boolean): string =>
79
+ `${roomy ? 'px-[64px]' : 'px-[40px]'} max-[900px]:px-[18px]`;
80
+
81
+ /**
82
+ * The sides AND the bottom rhythm — a column of prose, which ends.
83
+ *
63
84
  * @param roomy the nav beside this column is hidden, so the space it gave up
64
85
  * becomes margin on both sides rather than more line length.
65
86
  */
66
87
  export const documentGutters = (roomy: boolean): string =>
67
- `${roomy ? 'px-[64px]' : 'px-[40px]'} ${GUTTER_TAIL}`;
88
+ `${documentSideGutters(roomy)} ${BOTTOM_RHYTHM}`;