@bevel-software/platform-core-frontend 0.19.0 → 0.21.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 (52) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +6 -2
  3. package/src/modules/access/hooks/useFileAccess.ts +2 -2
  4. package/src/modules/audit/__tests__/AuditLogPage.test.tsx +312 -0
  5. package/src/modules/audit/components/AuditEventsPanel.tsx +319 -0
  6. package/src/modules/audit/components/AuditLogPage.tsx +373 -0
  7. package/src/modules/audit/components/principal-grouping.ts +49 -0
  8. package/src/modules/audit/services/audit.api.ts +98 -0
  9. package/src/modules/auth/components/LoginScreen.tsx +1 -0
  10. package/src/modules/git/components/BranchSwitcher.tsx +9 -3
  11. package/src/modules/git/components/FileComparisonPanel.tsx +10 -4
  12. package/src/modules/git/components/PullNeededBanner.tsx +2 -2
  13. package/src/modules/git/services/error-messages.ts +2 -2
  14. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +110 -9
  15. package/src/modules/layout/components/SidebarFrame.tsx +26 -9
  16. package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +11 -0
  17. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +3 -0
  18. package/src/modules/library/__tests__/PluginIndexRow.test.tsx +146 -0
  19. package/src/modules/library/__tests__/PluginPage.test.tsx +110 -3
  20. package/src/modules/library/__tests__/ToolPage.test.tsx +20 -0
  21. package/src/modules/library/__tests__/name-with-badges.test.tsx +16 -3
  22. package/src/modules/library/__tests__/title-row-actions.ts +43 -0
  23. package/src/modules/library/components/PluginIndexRow.tsx +37 -20
  24. package/src/modules/library/components/PluginPage.tsx +115 -3
  25. package/src/modules/library/components/tool-page/ToolPage.tsx +25 -17
  26. package/src/modules/library/routes/library-paths.ts +9 -2
  27. package/src/modules/library/services/plugins.api.ts +45 -0
  28. package/src/modules/library/utils/plugin-summary.ts +7 -2
  29. package/src/modules/onboarding/__tests__/onboarding.test.tsx +43 -0
  30. package/src/modules/onboarding/components/ConnectAgentPill.tsx +13 -2
  31. package/src/modules/pr/components/OpenChangeRequestDialog.tsx +3 -2
  32. package/src/modules/review/components/ReviewPanel.tsx +2 -2
  33. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +2 -1
  34. package/src/modules/settings/settings-nav-items.tsx +11 -9
  35. package/src/modules/setup/components/SetupScreen.tsx +11 -0
  36. package/src/modules/setup/services/setup.api.ts +1 -1
  37. package/src/modules/toolbar/services/external-api-keys.api.ts +2 -0
  38. package/src/modules/workspace/components/FileExplorer.tsx +4 -2
  39. package/src/modules/workspace/components/FileViewer.tsx +14 -4
  40. package/src/modules/workspace/components/KbDocumentShell.tsx +50 -8
  41. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +60 -0
  42. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +99 -0
  43. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +49 -1
  44. package/src/modules/workspace/hooks/useWorkspaceState.ts +7 -2
  45. package/src/modules/workspace/services/__tests__/workspace.api.test.ts +78 -1
  46. package/src/modules/workspace/utils/fileTree.ts +2 -1
  47. package/src/modules/workspace/utils/treeConfirm.ts +7 -3
  48. package/src/shared/theme/measure.ts +23 -2
  49. package/src/modules/admin/__tests__/ConnectionKeysPage.test.tsx +0 -266
  50. package/src/modules/admin/components/ConnectionKeysPage.tsx +0 -269
  51. package/src/modules/admin/components/connection-keys-grouping.ts +0 -43
  52. package/src/modules/admin/services/connection-keys.api.ts +0 -47
@@ -10,7 +10,7 @@ export interface SettingStatus {
10
10
  * entered here and nowhere else.
11
11
  */
12
12
  envVar?: string;
13
- section: 'knowledge-base' | 'sign-in';
13
+ section: 'knowledge-base' | 'sign-in' | 'audit';
14
14
  source: 'env' | 'stored' | 'unset';
15
15
  /** Absent for secrets — the server never sends a stored secret back. */
16
16
  value?: string;
@@ -14,6 +14,8 @@ export interface ExternalApiKeySummary {
14
14
  * live, and on keys revoked before this was recorded.
15
15
  */
16
16
  revokedBy: 'owner' | 'admin' | null;
17
+ /** Never set on a key the owner can see: a deleted key leaves their listings. */
18
+ deletedAt?: number | null;
17
19
  /** Model-proxy usage for this key today + the daily cap (in tokens). */
18
20
  llmUsage?: { usedTodayTokens: number; dailyTokenCap: number };
19
21
  }
@@ -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
@@ -985,8 +990,13 @@ export function FileViewer() {
985
990
  kbDirName && openFilePath.startsWith(`${kbDirName}/`)
986
991
  ? openFilePath.slice(kbDirName.length + 1)
987
992
  : null;
993
+ // Named owners only once THIS file's lookup has answered. The hook keeps the
994
+ // previous file's grants while the next request is in flight, and "Waiting on
995
+ // Docs" over the incoming file's box is a false statement about who decides
996
+ // it — the same staleness `othersPending` guards against below. The anonymous
997
+ // wording is always true, so it is what the window gets.
988
998
  const ownersLabel =
989
- access.owners.roles.length > 0 || access.owners.users.length > 0
999
+ !access.loading && (access.owners.roles.length > 0 || access.owners.users.length > 0)
990
1000
  ? formatEligible(access.owners)
991
1001
  : 'the owners';
992
1002
 
@@ -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.
@@ -2341,6 +2341,66 @@ describe('FileExplorer: delete and move ask first', () => {
2341
2341
  }
2342
2342
  });
2343
2343
 
2344
+ /**
2345
+ * The one drag test that actually DRAGS.
2346
+ *
2347
+ * Every other drop here hands the handler a `dataTransfer` built by the
2348
+ * test, with the source path and kind written in by hand. That skips the
2349
+ * handshake: `handleDragStart` writing the payload, and `handleDrop`
2350
+ * reading it back under the same two MIME keys. Stop setting the payload,
2351
+ * rename a key, or leave the row undraggable, and all of those tests still
2352
+ * pass while no real drag in the app does anything at all.
2353
+ *
2354
+ * This one grabs the row, lets the component's own `dragStart` fill a
2355
+ * DataTransfer that behaves like the browser's (what `setData` stores is
2356
+ * what `getData` returns), and drops THAT on the folder. So the refused
2357
+ * drag is evidenced end to end in the one place it can be: the criterion
2358
+ * has otherwise gone unevidenced through local, staging and production
2359
+ * testing, each time for want of a safe live fixture to drag.
2360
+ */
2361
+ it('a real drag — payload written by dragStart, read by drop — is refused with the sentence', async () => {
2362
+ const clash = 'A file named contract.pdf already exists in Sales.';
2363
+ const moveEntry = vi.fn().mockRejectedValue(new Error(clash));
2364
+ renderExplorer({ fileTree: TREE, moveEntry });
2365
+ openLegal();
2366
+
2367
+ // A row you cannot pick up cannot be dragged onto anything.
2368
+ const source = screen.getByText('contract.pdf').closest('[draggable]');
2369
+ expect(source).toHaveAttribute('draggable', 'true');
2370
+
2371
+ // Stands in for the browser's DataTransfer: a store, not a script.
2372
+ const store = new Map<string, string>();
2373
+ const dataTransfer = {
2374
+ setData: (type: string, value: string) => void store.set(type, value),
2375
+ getData: (type: string) => store.get(type) ?? '',
2376
+ files: [],
2377
+ items: undefined,
2378
+ effectAllowed: 'none',
2379
+ dropEffect: 'none',
2380
+ };
2381
+
2382
+ await act(async () => {
2383
+ fireEvent.dragStart(source!, { dataTransfer });
2384
+ });
2385
+ // The component put the drag's subject where the drop handler looks.
2386
+ expect(store.get(DRAG_MIME)).toBe(CONTRACT);
2387
+ expect(store.get(DRAG_KIND_MIME)).toBe('file');
2388
+
2389
+ await act(async () => {
2390
+ fireEvent.drop(screen.getByText('Sales'), { dataTransfer });
2391
+ });
2392
+ await act(async () => {
2393
+ fireEvent.click(screen.getByRole('button', { name: 'Move' }));
2394
+ });
2395
+
2396
+ // The destination was derived from the dragged row, not from the test.
2397
+ expect(moveEntry).toHaveBeenCalledWith(CONTRACT, `${KB}/KnowledgeBase/Sales/contract.pdf`);
2398
+ expect(screen.getByTestId('tree-move-error')).toHaveTextContent(clash);
2399
+ // Both entries where they were: the tree still shows each row.
2400
+ expect(screen.getByText('contract.pdf')).toBeInTheDocument();
2401
+ expect(screen.getByText('Sales')).toBeInTheDocument();
2402
+ });
2403
+
2344
2404
  it('a drop that lands says nothing', async () => {
2345
2405
  renderExplorer({ fileTree: TREE });
2346
2406
  openLegal();
@@ -392,6 +392,9 @@ describe('FileViewer', () => {
392
392
  owners: EMPTY_ELIGIBLE,
393
393
  };
394
394
  accessMock.fetchFileAccess.mockClear();
395
+ // mockClear keeps the implementation: a test that parks the lookup
396
+ // in flight would park every test after it.
397
+ accessMock.fetchFileAccess.mockImplementation(async () => accessMock.result);
395
398
  readBranchMock.mockImplementation(async () => '');
396
399
  // Restore the default "acquire succeeds" behaviour so a per-test 403
397
400
  // override doesn't leak into the next test.
@@ -856,6 +859,55 @@ describe('FileViewer', () => {
856
859
  expect(screen.getByRole('button', { name: 'Version history' })).toBeInTheDocument();
857
860
  });
858
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
+
859
911
  it('closes Version history from the pressed clock in the header', async () => {
860
912
  const user = userEvent.setup();
861
913
  render(<ViewerHarness initialContent="historic" />);
@@ -988,6 +1040,53 @@ describe('FileViewer', () => {
988
1040
  expect(screen.queryByText(/Waiting on you/)).not.toBeInTheDocument();
989
1041
  });
990
1042
 
1043
+ /**
1044
+ * Switching files keeps the PREVIOUS file's grants in the access hook until
1045
+ * the next lookup answers — which is why the "and N others" count is gated on
1046
+ * `!access.loading`. The "Waiting on …" line is the same hazard: it names
1047
+ * people, and naming the OUTGOING file's owners over the incoming file's box
1048
+ * is a false statement about who decides this change. Mid-lookup it has to
1049
+ * fall back to the anonymous wording.
1050
+ */
1051
+ it('never names the previous file’s owners while the next lookup is in flight', async () => {
1052
+ accessMock.result = {
1053
+ canWrite: false,
1054
+ canOwner: false,
1055
+ eligible: { roles: ['Docs'], users: [] },
1056
+ owners: { roles: ['Docs'], users: [] },
1057
+ };
1058
+ readBranchMock.mockImplementation((async (branch: string) =>
1059
+ branch.startsWith('suggestions/') ? 'proposed' : 'current') as never);
1060
+ // The outgoing file's only job is to be the file we switch AWAY from,
1061
+ // leaving its owners behind in the hook. It renders a box of its own —
1062
+ // nothing is asserted on that one.
1063
+ const { rerender } = render(
1064
+ <ViewerHarness
1065
+ initialContent="outgoing"
1066
+ branch="target-company-state"
1067
+ filePath="knowledge-base/Knowledge/Other.md"
1068
+ changeRequests={[{ number: 34, title: 'Tighten the wording', who: 'Ali Raza' }]}
1069
+ />,
1070
+ );
1071
+ await waitFor(() => expect(accessMock.fetchFileAccess).toHaveBeenCalled());
1072
+
1073
+ // The incoming file's lookup never answers, so the box renders for the
1074
+ // whole of the in-flight window.
1075
+ accessMock.fetchFileAccess.mockImplementation(() => new Promise(() => {}));
1076
+ rerender(
1077
+ <ViewerHarness
1078
+ initialContent="incoming"
1079
+ branch="target-company-state"
1080
+ filePath="knowledge-base/Knowledge/Foo.md"
1081
+ changeRequests={[{ number: 34, title: 'Tighten the wording', who: 'Ali Raza' }]}
1082
+ />,
1083
+ );
1084
+
1085
+ expect(await screen.findByText(/proposed a change/)).toBeInTheDocument();
1086
+ expect(screen.getByText('Waiting on the owners')).toBeInTheDocument();
1087
+ expect(screen.queryByText('Waiting on Docs')).not.toBeInTheDocument();
1088
+ });
1089
+
991
1090
  it('says nothing on a file nobody has proposed a change to', () => {
992
1091
  render(<ViewerHarness initialContent="quiet" />);
993
1092
  expect(screen.queryByText(/proposed a change/)).not.toBeInTheDocument();
@@ -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);
@@ -6,7 +6,7 @@ vi.mock('../../../../lib/api', () => ({
6
6
  authFetch: vi.fn(),
7
7
  }));
8
8
 
9
- import { uploadFile, createDirectory, rawFileUrl, writeFile, WorkspaceApiError } from '../workspace.api';
9
+ import { uploadFile, createDirectory, moveEntry, rawFileUrl, writeFile, WorkspaceApiError } from '../workspace.api';
10
10
  import { authFetch } from '../../../../lib/api';
11
11
 
12
12
  const mockedFetch = vi.mocked(authFetch);
@@ -126,3 +126,80 @@ describe('writeFile', () => {
126
126
  await expect(writeFile('ws', 'kb/notes.md', 'x')).resolves.toEqual({});
127
127
  });
128
128
  });
129
+
130
+ /**
131
+ * The refusal a rename or a drag shows is the SERVER's sentence, and this is
132
+ * the layer it has to survive to reach the sidebar intact.
133
+ *
134
+ * The explorer renders whatever `moveEntry` rejects with — the rename box puts
135
+ * it under the name you typed, a refused drop puts it under the row. Those
136
+ * components are tested against a stubbed `moveEntry`, so nothing there can
137
+ * tell whether a real 409 becomes that message or becomes "HTTP 409". This
138
+ * closes that half: the body the backend actually sends, through the real
139
+ * client, out as the message the UI renders.
140
+ */
141
+ describe('moveEntry carries the destination-taken refusal through unchanged', () => {
142
+ beforeEach(() => {
143
+ vi.clearAllMocks();
144
+ });
145
+
146
+ const SENTENCE = 'A file named Notes.md already exists in Sales.';
147
+
148
+ it('rejects with the sentence itself, not with the HTTP status', async () => {
149
+ mockedFetch.mockResolvedValueOnce(
150
+ // The WHOLE body `EntryExistsError` puts on the wire, not a convenient
151
+ // slice of it: the backend's `domainErrorBody` spreads the payload
152
+ // (`kind`, `entryKind`, `destination`) and then writes `error` last, so
153
+ // these four keys are what a client actually receives. The client here
154
+ // reads only `error`; the rest are present so this fixture cannot drift
155
+ // into testing a body the server never sends.
156
+ notOk(409, {
157
+ kind: 'entry-exists',
158
+ entryKind: 'file',
159
+ destination: 'kb/Sales/Notes.md',
160
+ error: SENTENCE,
161
+ }),
162
+ );
163
+
164
+ const err = await moveEntry('ws-1', 'kb/Sales/Report.docx', 'kb/Sales/Notes.md').catch((e) => e);
165
+
166
+ expect(err).toBeInstanceOf(WorkspaceApiError);
167
+ expect(err.status).toBe(409);
168
+ expect(err.message).toBe(SENTENCE);
169
+ });
170
+
171
+ it('says so for a folder in the way too, and sends the move as a PATCH of both paths', async () => {
172
+ const folder = 'A folder named Q4 already exists in Sales.';
173
+ mockedFetch.mockResolvedValueOnce(
174
+ notOk(409, {
175
+ kind: 'entry-exists',
176
+ entryKind: 'folder',
177
+ destination: 'kb/Sales/Q4',
178
+ error: folder,
179
+ }),
180
+ );
181
+
182
+ await expect(moveEntry('ws-1', 'kb/Archive/Q4', 'kb/Sales/Q4')).rejects.toMatchObject({
183
+ status: 409,
184
+ message: folder,
185
+ });
186
+
187
+ const [url, init] = mockedFetch.mock.calls[0] as [string, RequestInit];
188
+ expect(url).toBe('/api/workspace/ws-1/file');
189
+ expect(init.method).toBe('PATCH');
190
+ expect(JSON.parse(String(init.body))).toEqual({
191
+ oldPath: 'kb/Archive/Q4',
192
+ newPath: 'kb/Sales/Q4',
193
+ });
194
+ });
195
+
196
+ it('resolves silently when the move lands, so the explorer closes its box', async () => {
197
+ mockedFetch.mockResolvedValueOnce({
198
+ ok: true,
199
+ status: 200,
200
+ json: async () => ({ status: 'moved' }),
201
+ } as unknown as Response);
202
+
203
+ await expect(moveEntry('ws-1', 'kb/a.md', 'kb/b.md')).resolves.toBeUndefined();
204
+ });
205
+ });
@@ -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.`
@@ -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}`;