@bevel-software/platform-core-frontend 0.14.0 → 0.15.1

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 (89) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +18 -17
  3. package/src/core/__tests__/bootstrap.test.ts +33 -1
  4. package/src/core/bootstrap.ts +30 -1
  5. package/src/lib/__tests__/api.test.ts +38 -0
  6. package/src/lib/api.ts +19 -2
  7. package/src/lib/utils.ts +2 -0
  8. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +111 -1
  9. package/src/modules/access/__tests__/plugin-token.test.ts +21 -0
  10. package/src/modules/access/api.ts +52 -4
  11. package/src/modules/access/components/ManageAccessDialog.tsx +112 -83
  12. package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +65 -1
  13. package/src/modules/git/components/GitSyncFailedBanner.tsx +68 -5
  14. package/src/modules/layout/components/SidebarFrame.tsx +1 -1
  15. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +1 -1
  16. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +1 -1
  17. package/src/modules/library/__tests__/LinkSkillPanel.test.tsx +121 -0
  18. package/src/modules/library/__tests__/LockedPluginView.test.tsx +6 -0
  19. package/src/modules/library/__tests__/NewPluginDialog.test.tsx +5 -4
  20. package/src/modules/library/__tests__/PluginExtras.test.tsx +15 -0
  21. package/src/modules/library/__tests__/PluginPage.test.tsx +195 -1
  22. package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +1 -1
  23. package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +1 -1
  24. package/src/modules/library/__tests__/PluginsSidebar.test.tsx +64 -3
  25. package/src/modules/library/__tests__/SkillPage.test.tsx +9 -2
  26. package/src/modules/library/__tests__/SkillsTree.test.tsx +172 -0
  27. package/src/modules/library/__tests__/ToolPage.test.tsx +7 -0
  28. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +115 -4
  29. package/src/modules/library/__tests__/library-data.stale.test.tsx +90 -0
  30. package/src/modules/library/__tests__/library-paths.test.ts +32 -0
  31. package/src/modules/library/__tests__/link-membership.test.ts +120 -0
  32. package/src/modules/library/__tests__/plugin-summary.test.ts +32 -0
  33. package/src/modules/library/__tests__/useJoinRequests.test.tsx +46 -0
  34. package/src/modules/library/components/AddToPluginDialog.tsx +33 -0
  35. package/src/modules/library/components/LibraryCard.tsx +14 -0
  36. package/src/modules/library/components/LibraryLayout.tsx +24 -14
  37. package/src/modules/library/components/LinkSkillPanel.tsx +171 -0
  38. package/src/modules/library/components/LockedPluginView.tsx +2 -2
  39. package/src/modules/library/components/NewPluginDialog.tsx +4 -4
  40. package/src/modules/library/components/PageActions.tsx +21 -1
  41. package/src/modules/library/components/PersonalPluginPage.tsx +2 -1
  42. package/src/modules/library/components/PluginExtras.tsx +3 -1
  43. package/src/modules/library/components/PluginPage.tsx +92 -12
  44. package/src/modules/library/components/PluginsIndexPage.tsx +11 -6
  45. package/src/modules/library/components/PluginsSidebar.tsx +110 -53
  46. package/src/modules/library/components/RenamePluginDialog.tsx +136 -0
  47. package/src/modules/library/components/SkillsTree.tsx +91 -0
  48. package/src/modules/library/components/StatusDot.tsx +1 -0
  49. package/src/modules/library/components/plugin-page-parts.tsx +32 -9
  50. package/src/modules/library/components/skill-page/SharedViaPlugins.tsx +218 -0
  51. package/src/modules/library/components/skill-page/SkillPage.tsx +70 -6
  52. package/src/modules/library/components/tool-page/ToolPage.tsx +11 -2
  53. package/src/modules/library/hooks/useJoinRequests.ts +48 -18
  54. package/src/modules/library/routes/WorkspaceItemRoute.tsx +180 -83
  55. package/src/modules/library/routes/library-paths.ts +21 -8
  56. package/src/modules/library/services/library.api.ts +55 -1
  57. package/src/modules/library/services/plugins.api.ts +94 -3
  58. package/src/modules/library/state/library-data.tsx +115 -22
  59. package/src/modules/library/utils/plugin-summary.ts +36 -0
  60. package/src/modules/library/utils/status.ts +74 -7
  61. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +3 -2
  62. package/src/modules/settings/components/ClaudeConnectionCard.tsx +169 -0
  63. package/src/modules/settings/components/DeploymentPage.tsx +15 -1
  64. package/src/modules/settings/components/__tests__/ClaudeConnectionCard.test.tsx +63 -0
  65. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +10 -0
  66. package/src/modules/settings/services/github-facade.api.ts +43 -0
  67. package/src/modules/setup/__tests__/setup.test.tsx +118 -0
  68. package/src/modules/setup/components/SetupGate.tsx +1 -1
  69. package/src/modules/setup/components/SetupScreen.tsx +195 -2
  70. package/src/modules/setup/services/setup.api.ts +78 -0
  71. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +295 -83
  72. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +129 -6
  73. package/src/modules/toolbar/services/external-api-keys.api.ts +2 -0
  74. package/src/modules/workspace/__tests__/testFixtures.ts +1 -0
  75. package/src/modules/workspace/components/FileExplorer.tsx +292 -236
  76. package/src/modules/workspace/components/FileRoute.tsx +37 -0
  77. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +39 -0
  78. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +1 -0
  79. package/src/modules/workspace/hooks/useMergedWorkspaceTree.ts +70 -0
  80. package/src/modules/workspace/hooks/useWorkspaceState.ts +17 -3
  81. package/src/modules/workspace/routing/kb-routes.ts +1 -1
  82. package/src/modules/workspace/state/workspace.context.ts +8 -0
  83. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +15 -0
  84. package/src/modules/workspace/utils/fileTree.ts +14 -16
  85. package/src/shared/__tests__/marketplace-url.test.ts +54 -0
  86. package/src/shared/components/Badge.tsx +3 -1
  87. package/src/shared/components/Banner.tsx +5 -1
  88. package/src/shared/marketplace-url.ts +90 -0
  89. package/src/shared/theme/tokens.css +9 -0
@@ -1,4 +1,13 @@
1
- import { useState, useCallback, useEffect, useMemo, useRef, createContext, useContext } from 'react';
1
+ import {
2
+ useState,
3
+ useCallback,
4
+ useEffect,
5
+ useMemo,
6
+ useRef,
7
+ createContext,
8
+ useContext,
9
+ type ReactNode,
10
+ } from 'react';
2
11
  import {
3
12
  ChevronRight,
4
13
  FilePlus,
@@ -22,11 +31,13 @@ import {
22
31
  KNOWLEDGE_BASE_DIR,
23
32
  DATA_DIR,
24
33
  PLUGINS_DIR,
34
+ SKILLS_DIR,
25
35
  AGENTS_DIR,
26
36
  PIPELINES_DIR,
27
37
  } from '@bevel-software/platform-shared';
28
- import { useWorkspace, type PendingEntry } from '../state/workspace.context';
29
- import { mergePendingIntoTree, pathExistsInTree, findKbRoot, KB_ROOT_DIRS } from '../utils/fileTree';
38
+ import { useWorkspace } from '../state/workspace.context';
39
+ import { findKbRoot, KB_ROOT_DIRS } from '../utils/fileTree';
40
+ import { useMergedWorkspaceTree } from '../hooks/useMergedWorkspaceTree';
30
41
  import { ChangeRequestDialog } from '../../change-requests/components/ChangeRequestDialog';
31
42
  import { PR_STALE_EVENT } from '../../../core/events';
32
43
  import { snapshotEntries } from '../utils/readDroppedEntries';
@@ -94,16 +105,24 @@ function readPinnedPaths(): string[] {
94
105
  }
95
106
 
96
107
  interface PinnedController {
108
+ /**
109
+ * Whether this tree offers pinning at all. Only the Knowledge explorer has
110
+ * a Company Context section to pin INTO; a tree without one hides the item
111
+ * rather than offering a verb that lands nowhere.
112
+ */
113
+ available: boolean;
97
114
  isPinned: (path: string) => boolean;
98
115
  togglePin: (path: string) => void;
99
116
  }
100
117
 
101
118
  // Default no-op so a ContextMenu rendered outside the provider (e.g. in a unit
102
119
  // test) never throws — the real controller is supplied by FileExplorer.
103
- const PinnedContext = createContext<PinnedController>({
120
+ const NO_PINNING: PinnedController = {
121
+ available: false,
104
122
  isPinned: () => false,
105
123
  togglePin: () => {},
106
- });
124
+ };
125
+ const PinnedContext = createContext<PinnedController>(NO_PINNING);
107
126
  const usePinned = () => useContext(PinnedContext);
108
127
 
109
128
  // Lets the deep right-click menu open the Manage access sheet without prop
@@ -135,6 +154,23 @@ const SuggestionsContext = createContext<SuggestionsController>({
135
154
  });
136
155
  const useSuggestions = () => useContext(SuggestionsContext);
137
156
 
157
+ /**
158
+ * Which row is current, and where a row's click goes.
159
+ *
160
+ * Context, for the same reason as the three above — and because the SAME rows
161
+ * serve two navs. The Knowledge explorer opens a file in the pane workspace
162
+ * on the checked-out branch; the Library's Skills tree opens a skill on its
163
+ * own page, on the default branch, whatever is checked out. The rows know
164
+ * neither: they report the path they hold and read which one is active.
165
+ */
166
+ export interface TreeNav {
167
+ /** The workspace-relative path the surface is showing — lights its row, reveals its folders. */
168
+ activePath: string | null;
169
+ open(path: string): void;
170
+ }
171
+ const TreeNavContext = createContext<TreeNav>({ activePath: null, open: () => {} });
172
+ const useTreeNav = () => useContext(TreeNavContext);
173
+
138
174
  /** Depth-first lookup of a tree entry by its exact relativePath. */
139
175
  function findEntryByPath(node: FileTreeEntry, path: string): FileTreeEntry | null {
140
176
  if (node.relativePath === path) return node;
@@ -159,11 +195,14 @@ function ContextMenu({
159
195
  onRename,
160
196
  onDownload,
161
197
  returnFocusTo,
198
+ deletable = true,
162
199
  }: {
163
200
  x: number;
164
201
  y: number;
165
202
  entry: FileTreeEntry;
166
203
  isRoot: boolean;
204
+ /** False for a folder the platform owns (a reserved root): no Delete. */
205
+ deletable?: boolean;
167
206
  onClose: () => void;
168
207
  onCreateFile?: () => void;
169
208
  onCreateFolder?: () => void;
@@ -173,7 +212,7 @@ function ContextMenu({
173
212
  returnFocusTo?: React.RefObject<HTMLElement | null>;
174
213
  }) {
175
214
  const { deleteEntry, unzipHere } = useWorkspace();
176
- const { isPinned, togglePin } = usePinned();
215
+ const { isPinned, togglePin, available: pinning } = usePinned();
177
216
  const openManageAccess = useManageAccess();
178
217
  const pinned = isPinned(entry.relativePath);
179
218
  const [unzipping, setUnzipping] = useState(false);
@@ -297,7 +336,7 @@ function ContextMenu({
297
336
  </MenuItem>
298
337
  </>
299
338
  )}
300
- {entry.type === 'directory' && !isRoot && (
339
+ {entry.type === 'directory' && !isRoot && pinning && (
301
340
  <MenuItem role="menuitem" onClick={() => { togglePin(entry.relativePath); onClose(); }}>
302
341
  <span className="flex items-center gap-2">
303
342
  {pinned ? <PinOff size={14} /> : <Pin size={14} />}
@@ -310,7 +349,7 @@ function ContextMenu({
310
349
  <span className="flex items-center gap-2"><Pencil size={14} />Rename</span>
311
350
  </MenuItem>
312
351
  )}
313
- {!isRoot && (
352
+ {!isRoot && deletable && (
314
353
  // Danger tone comes from the primitive, not from a hand-written red.
315
354
  <MenuItem role="menuitem" tone="danger" onClick={handleDelete}>
316
355
  <span className="flex items-center gap-2"><Trash2 size={14} />Delete</span>
@@ -424,11 +463,12 @@ function RenameInput({
424
463
 
425
464
  const DRAG_MIME = 'application/x-workspace-path';
426
465
 
427
- function FileTreeNode({
466
+ export function FileTreeNode({
428
467
  entry,
429
468
  depth,
430
469
  initiallyExpanded,
431
470
  collapseChildren,
471
+ reserved = false,
432
472
  }: {
433
473
  entry: FileTreeEntry;
434
474
  depth: number;
@@ -439,9 +479,17 @@ function FileTreeNode({
439
479
  // When set, this node's direct children start collapsed (so opening Knowledge
440
480
  // reveals the ontologies without cascading them all open).
441
481
  collapseChildren?: boolean;
482
+ /**
483
+ * The folder is a root the platform owns (`Skills/` in the Library). It is
484
+ * an ordinary collapsible folder row — the same row Knowledge and Data get
485
+ * at the top of the explorer: it takes drops, offers the create buttons,
486
+ * opens the folder's menu on right-click — minus what a reserved root must
487
+ * not do: be renamed, deleted, dragged, or pinned.
488
+ */
489
+ reserved?: boolean;
442
490
  }) {
443
- const { openFilePath, createFile, createDirectory, dispatchUpload, isUploading, moveEntry, workspaceId, pendingUploads } = useWorkspace();
444
- const { openFile } = useFileNav();
491
+ const { createFile, createDirectory, dispatchUpload, isUploading, moveEntry, workspaceId, pendingUploads } = useWorkspace();
492
+ const nav = useTreeNav();
445
493
  // One shared fetch behind this — see `OpenChangeRequestsProvider`.
446
494
  const openChangeRequests = useOpenChangeRequests();
447
495
  const suggestions = useSuggestions();
@@ -496,11 +544,12 @@ function FileTreeNode({
496
544
 
497
545
  // Resetting `value` after dispatch lets users re-select the same file and
498
546
  // still get an `onChange` event the second time around.
547
+ const pickTarget = entry.relativePath === '.' ? '' : entry.relativePath;
499
548
  const handleRootFileChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
500
549
  const files = Array.from(e.target.files ?? []);
501
550
  e.target.value = '';
502
- if (files.length > 0) dispatchUpload({ kind: 'files', files }, '');
503
- }, [dispatchUpload]);
551
+ if (files.length > 0) dispatchUpload({ kind: 'files', files }, pickTarget);
552
+ }, [dispatchUpload, pickTarget]);
504
553
 
505
554
  // Folder picker: each File carries a `webkitRelativePath` like
506
555
  // "foldername/sub/file.txt" — we feed those straight into the upload
@@ -516,8 +565,8 @@ function FileTreeNode({
516
565
  file,
517
566
  relativePath: file.webkitRelativePath || file.name,
518
567
  }));
519
- dispatchUpload({ kind: 'paths', items }, '');
520
- }, [dispatchUpload]);
568
+ dispatchUpload({ kind: 'paths', items }, pickTarget);
569
+ }, [dispatchUpload, pickTarget]);
521
570
  const [dragging, setDragging] = useState(false);
522
571
  const [contextMenu, setContextMenu] = useState<{ x: number; y: number } | null>(null);
523
572
 
@@ -534,15 +583,15 @@ function FileTreeNode({
534
583
  // deep-link URLs reveal the file's row in the tree) or while files
535
584
  // dropped under it are still uploading (so the user can watch them
536
585
  // fill in).
537
- const isOpenFileAncestor = entry.type === 'directory' && !!openFilePath && (
538
- isRoot || openFilePath.startsWith(entry.relativePath + '/')
586
+ const isOpenFileAncestor = entry.type === 'directory' && !!nav.activePath && (
587
+ isRoot || nav.activePath.startsWith(entry.relativePath + '/')
539
588
  );
540
589
  const autoExpanded = entry.type === 'directory' && (isPending || isOpenFileAncestor);
541
590
 
542
591
  // Fingerprint of what currently drives auto-expand. When it transitions
543
592
  // (different file opened, upload starts), the user's prior collapse intent
544
593
  // is stale — reset so deep-links / new uploads can re-reveal the folder.
545
- const autoTrigger = `${isPending ? 'P' : ''}|${isOpenFileAncestor ? openFilePath : ''}`;
594
+ const autoTrigger = `${isPending ? 'P' : ''}|${isOpenFileAncestor ? nav.activePath : ''}`;
546
595
  const prevAutoTriggerRef = useRef(autoTrigger);
547
596
  useEffect(() => {
548
597
  if (prevAutoTriggerRef.current !== autoTrigger) {
@@ -561,11 +610,11 @@ function FileTreeNode({
561
610
 
562
611
  // ── Drag source (internal reorder) ──
563
612
  const handleDragStart = useCallback((e: React.DragEvent) => {
564
- if (isRoot) { e.preventDefault(); return; }
613
+ if (isRoot || reserved) { e.preventDefault(); return; }
565
614
  e.dataTransfer.setData(DRAG_MIME, entry.relativePath);
566
615
  e.dataTransfer.effectAllowed = 'move';
567
616
  setDragging(true);
568
- }, [entry.relativePath, isRoot]);
617
+ }, [entry.relativePath, isRoot, reserved]);
569
618
 
570
619
  const handleDragEnd = useCallback(() => {
571
620
  setDragging(false);
@@ -633,6 +682,75 @@ function FileTreeNode({
633
682
 
634
683
  if (entry.type === 'directory') {
635
684
  const dirPath = isRoot ? '' : entry.relativePath;
685
+ const createButtons = (
686
+ <>
687
+ <IconButton
688
+ size={18}
689
+ title="New file"
690
+ aria-label={`New file in ${entry.name}`}
691
+ onClick={(e) => {
692
+ e.stopPropagation();
693
+ setUserIntent(true);
694
+ setCreating('file');
695
+ }}
696
+ >
697
+ <FilePlus size={13} />
698
+ </IconButton>
699
+ <IconButton
700
+ size={18}
701
+ title="New folder"
702
+ aria-label={`New folder in ${entry.name}`}
703
+ onClick={(e) => {
704
+ e.stopPropagation();
705
+ setUserIntent(true);
706
+ setCreating('directory');
707
+ }}
708
+ >
709
+ <FolderPlus size={13} />
710
+ </IconButton>
711
+ </>
712
+ );
713
+ const pickerButtons = (
714
+ <>
715
+ <IconButton
716
+ size={18}
717
+ title="Add files"
718
+ aria-label="Add files"
719
+ disabled={isUploading}
720
+ onClick={handleRootUploadClick}
721
+ >
722
+ <Upload size={13} />
723
+ </IconButton>
724
+ <input
725
+ ref={rootFileInputRef}
726
+ type="file"
727
+ multiple
728
+ hidden
729
+ aria-hidden="true"
730
+ data-testid="file-explorer-file-input"
731
+ onChange={handleRootFileChange}
732
+ />
733
+ <IconButton
734
+ size={18}
735
+ title="Add folder"
736
+ aria-label="Add folder"
737
+ disabled={isUploading}
738
+ onClick={handleRootFolderClick}
739
+ >
740
+ <FolderUp size={13} />
741
+ </IconButton>
742
+ <input
743
+ ref={rootFolderInputRef}
744
+ type="file"
745
+ multiple
746
+ webkitdirectory=""
747
+ hidden
748
+ aria-hidden="true"
749
+ data-testid="file-explorer-folder-input"
750
+ onChange={handleRootFolderChange}
751
+ />
752
+ </>
753
+ );
636
754
  return (
637
755
  <div>
638
756
  <div
@@ -643,7 +761,7 @@ function FileTreeNode({
643
761
  dragOver && 'bg-hover text-ink ring-1 ring-accent/40',
644
762
  )}
645
763
  style={{ paddingLeft, opacity: dragging ? 0.5 : isPending ? 0.6 : 1 }}
646
- draggable={!isRoot && !renaming && !isPending}
764
+ draggable={!isRoot && !reserved && !renaming && !isPending}
647
765
  onDragStart={handleDragStart}
648
766
  onDragEnd={handleDragEnd}
649
767
  onDrop={handleDrop}
@@ -686,72 +804,9 @@ function FileTreeNode({
686
804
  )}
687
805
  </button>
688
806
  <div className="hidden shrink-0 items-center gap-0.5 group-hover:flex group-focus-within:flex">
689
- <IconButton
690
- size={18}
691
- title="New file"
692
- aria-label={`New file in ${entry.name}`}
693
- onClick={(e) => {
694
- e.stopPropagation();
695
- setUserIntent(true);
696
- setCreating('file');
697
- }}
698
- >
699
- <FilePlus size={13} />
700
- </IconButton>
701
- <IconButton
702
- size={18}
703
- title="New folder"
704
- aria-label={`New folder in ${entry.name}`}
705
- onClick={(e) => {
706
- e.stopPropagation();
707
- setUserIntent(true);
708
- setCreating('directory');
709
- }}
710
- >
711
- <FolderPlus size={13} />
712
- </IconButton>
807
+ {createButtons}
713
808
  </div>
714
- {isRoot && (
715
- <>
716
- <IconButton
717
- size={18}
718
- title="Add files"
719
- aria-label="Add files"
720
- disabled={isUploading}
721
- onClick={handleRootUploadClick}
722
- >
723
- <Upload size={13} />
724
- </IconButton>
725
- <input
726
- ref={rootFileInputRef}
727
- type="file"
728
- multiple
729
- hidden
730
- aria-hidden="true"
731
- data-testid="file-explorer-file-input"
732
- onChange={handleRootFileChange}
733
- />
734
- <IconButton
735
- size={18}
736
- title="Add folder"
737
- aria-label="Add folder"
738
- disabled={isUploading}
739
- onClick={handleRootFolderClick}
740
- >
741
- <FolderUp size={13} />
742
- </IconButton>
743
- <input
744
- ref={rootFolderInputRef}
745
- type="file"
746
- multiple
747
- webkitdirectory=""
748
- hidden
749
- aria-hidden="true"
750
- data-testid="file-explorer-folder-input"
751
- onChange={handleRootFolderChange}
752
- />
753
- </>
754
- )}
809
+ {isRoot && pickerButtons}
755
810
  </div>
756
811
  {isExpanded && (
757
812
  <div>
@@ -807,7 +862,11 @@ function FileTreeNode({
807
862
  onClose={() => setContextMenu(null)}
808
863
  onCreateFile={() => { setUserIntent(true); setCreating('file'); }}
809
864
  onCreateFolder={() => { setUserIntent(true); setCreating('directory'); }}
810
- onRename={() => setRenaming(true)}
865
+ // A reserved root is the platform's: no rename, no delete. (No pin
866
+ // either, but that needs no gate: only the Knowledge explorer
867
+ // offers pinning, and its roots are not reserved.)
868
+ onRename={reserved ? undefined : () => setRenaming(true)}
869
+ deletable={!reserved}
811
870
  onDownload={handleDownload}
812
871
  returnFocusTo={rowRef}
813
872
  />
@@ -846,7 +905,7 @@ function FileTreeNode({
846
905
  );
847
906
  }
848
907
 
849
- const isActive = entry.relativePath === openFilePath;
908
+ const isActive = entry.relativePath === nav.activePath;
850
909
 
851
910
  return (
852
911
  <>
@@ -864,7 +923,7 @@ function FileTreeNode({
864
923
  draggable={!renaming && !isPending}
865
924
  onDragStart={handleDragStart}
866
925
  onDragEnd={handleDragEnd}
867
- onClick={() => { if (!renaming && !isPending) openFile(entry.relativePath); }}
926
+ onClick={() => { if (!renaming && !isPending) nav.open(entry.relativePath); }}
868
927
  onContextMenu={handleContextMenu}
869
928
  title={isPending ? 'Adding…' : undefined}
870
929
  >
@@ -931,6 +990,133 @@ function FileTreeNode({
931
990
 
932
991
  // ── Explorer Root ──
933
992
 
993
+ /**
994
+ * Everything a tree of `FileTreeNode`s needs AROUND it, and nothing about
995
+ * where it sits: the navigation (which row is current, where a click goes),
996
+ * the suggestion rows' change-request dialog, the right-click menu's Manage
997
+ * access sheet, and — for the one tree that has somewhere to pin into — a pin
998
+ * controller. The Knowledge explorer and the Library's Skills tree both render
999
+ * inside one of these, which is why their rows cannot drift: the rows are one
1000
+ * component and so are their surroundings.
1001
+ */
1002
+ export function TreeChrome({
1003
+ nav,
1004
+ suggestionOnlyPaths,
1005
+ pinned,
1006
+ children,
1007
+ }: {
1008
+ nav: TreeNav;
1009
+ suggestionOnlyPaths: ReadonlyMap<string, number>;
1010
+ pinned?: PinnedController;
1011
+ children: ReactNode;
1012
+ }) {
1013
+ const openChangeRequests = useOpenChangeRequests();
1014
+ // A clicked suggestion row opens the SHARED change-request dialog on the
1015
+ // request the path belongs to — the row is a link to the request, and the
1016
+ // dialog is the one change-request view the app has.
1017
+ const [openSuggestionCr, setOpenSuggestionCr] = useState<PullRequestSummary | null>(null);
1018
+ const suggestionsController = useMemo<SuggestionsController>(
1019
+ () => ({
1020
+ crFor: (path) => suggestionOnlyPaths.get(path) ?? null,
1021
+ open: (path, crNumber) => {
1022
+ const cr = openChangeRequests.forPath(path).find((c) => c.number === crNumber) ?? null;
1023
+ setOpenSuggestionCr(cr);
1024
+ },
1025
+ }),
1026
+ [suggestionOnlyPaths, openChangeRequests],
1027
+ );
1028
+ // Right-click → Manage access opens this sheet for the chosen entry.
1029
+ const [accessTarget, setAccessTarget] = useState<FileTreeEntry | null>(null);
1030
+
1031
+ return (
1032
+ <>
1033
+ <TreeNavContext.Provider value={nav}>
1034
+ <PinnedContext.Provider value={pinned ?? NO_PINNING}>
1035
+ <ManageAccessContext.Provider value={setAccessTarget}>
1036
+ <SuggestionsContext.Provider value={suggestionsController}>
1037
+ {children}
1038
+ </SuggestionsContext.Provider>
1039
+ </ManageAccessContext.Provider>
1040
+ </PinnedContext.Provider>
1041
+ </TreeNavContext.Provider>
1042
+ {openSuggestionCr && (
1043
+ <ChangeRequestDialog
1044
+ cr={openSuggestionCr}
1045
+ onClose={() => setOpenSuggestionCr(null)}
1046
+ onResolved={() => {
1047
+ setOpenSuggestionCr(null);
1048
+ window.dispatchEvent(new Event(PR_STALE_EVENT));
1049
+ }}
1050
+ />
1051
+ )}
1052
+ {accessTarget && (
1053
+ <ManageAccessDialog
1054
+ key={accessTarget.relativePath}
1055
+ entry={accessTarget}
1056
+ // The dialog is keyed on the path, so pointing it at a parent remounts
1057
+ // it against that folder — the whole retarget is this one setter.
1058
+ onManageAncestor={setAccessTarget}
1059
+ onClose={() => setAccessTarget(null)}
1060
+ />
1061
+ )}
1062
+ </>
1063
+ );
1064
+ }
1065
+
1066
+ /**
1067
+ * The upload banners: the last upload's error, or the one non-error notice
1068
+ * (it landed on the suggestions branch). Rendered by every tree that can
1069
+ * upload, because the state is the workspace's and a drop into a tree with no
1070
+ * banner would fail — or succeed elsewhere — in silence.
1071
+ */
1072
+ export function UploadNotices() {
1073
+ const { uploadError, clearUploadError, uploadNotice, clearUploadNotice } = useWorkspace();
1074
+ return (
1075
+ <>
1076
+ {uploadError && (
1077
+ <div
1078
+ role="alert"
1079
+ className="flex items-start gap-1 px-2 py-1 text-xs text-danger bg-danger-soft border-b border-danger/30 shrink-0"
1080
+ >
1081
+ <span className="flex-1 truncate" title={uploadError.reason}>
1082
+ Couldn't add {uploadError.filename}: {uploadError.reason}
1083
+ </span>
1084
+ <IconButton
1085
+ size={18}
1086
+ tone="danger"
1087
+ title="Dismiss"
1088
+ aria-label="Dismiss upload error"
1089
+ onClick={clearUploadError}
1090
+ >
1091
+ <X size={12} />
1092
+ </IconButton>
1093
+ </div>
1094
+ )}
1095
+ {/* Not an error: the upload LANDED, on the suggestions branch. Saying
1096
+ so is load-bearing — nothing appears in the tree where the user
1097
+ dropped the files, and silence there reads as a failed upload. */}
1098
+ {uploadNotice && (
1099
+ <div
1100
+ role="status"
1101
+ className="flex items-start gap-1 px-2 py-1 text-xs text-ink bg-wait-soft border-b border-line shrink-0"
1102
+ >
1103
+ <span className="flex-1" title={uploadNotice}>
1104
+ {uploadNotice}
1105
+ </span>
1106
+ <IconButton
1107
+ size={18}
1108
+ title="Dismiss"
1109
+ aria-label="Dismiss upload notice"
1110
+ onClick={clearUploadNotice}
1111
+ >
1112
+ <X size={12} />
1113
+ </IconButton>
1114
+ </div>
1115
+ )}
1116
+ </>
1117
+ );
1118
+ }
1119
+
934
1120
  /**
935
1121
  * Walk down to the node that actually holds the KB content. The file tree roots
936
1122
  * at the per-branch workspace dir and wraps the KB clone a level or two deep
@@ -943,86 +1129,18 @@ function FileTreeNode({
943
1129
  // contributed explorer items.)
944
1130
 
945
1131
  export function FileExplorer() {
946
- const {
947
- fileTree,
948
- kbDirName,
949
- dispatchUpload,
950
- uploadError,
951
- clearUploadError,
952
- uploadNotice,
953
- clearUploadNotice,
954
- pendingUploads,
955
- } = useWorkspace();
1132
+ const { openFilePath, dispatchUpload } = useWorkspace();
1133
+ const { openFile } = useFileNav();
956
1134
  const [dragOver, setDragOver] = useState(false);
957
1135
  // Download is now a per-path permission (resolved server-side from the
958
1136
  // access tree's `download:` verb), so there's no global preflight gate
959
1137
  // here anymore. The menu items always render; if the user clicks on a
960
1138
  // file they don't have download permission for, the backend returns 403
961
1139
  // and `handleDownload` shows the error.
962
- // Optimistic overlay: every dropped/picked file shows up in the tree
963
- // within a frame, even before its commit echoes back from the server.
964
- const serverTree = useMemo(
965
- () => (fileTree ? mergePendingIntoTree(fileTree, pendingUploads) : null),
966
- [fileTree, pendingUploads],
967
- );
968
-
969
- // The caller's own proposed files that do NOT exist on this branch — they
970
- // live only on the personal suggestions branch behind an open change
971
- // request. The tree shows them beside the branch's real files (synthesized
972
- // below), coloured differently, and clicking one opens the request.
973
- const openChangeRequests = useOpenChangeRequests();
974
- const suggestionOnlyPaths = useMemo(() => {
975
- const map = new Map<string, number>();
976
- if (!serverTree) return map;
977
- /**
978
- * "Not in the tree" has TWO causes, and only one earns a row: the file is
979
- * new on the suggestions branch — or the server FILTERED it (.bevelignore,
980
- * read gates). The client cannot evaluate those rules itself, but it can
981
- * read their verdict off the tree: if the path's top-level folder under
982
- * the repo root is absent, the whole subtree is hidden (a skill proposal
983
- * under a bevelignored `Plugins/` was the observed leak), so the overlay
984
- * must not resurrect it. The known cost: a proposal that CREATES a new
985
- * top-level root folder shows no row until it merges.
986
- */
987
- const hiddenRoot = (path: string): boolean => {
988
- const prefix = kbDirName && path.startsWith(`${kbDirName}/`) ? `${kbDirName}/` : '';
989
- const segments = path.slice(prefix.length).split('/');
990
- if (segments.length < 2) return false; // directly under the repo root
991
- return !pathExistsInTree(serverTree, `${prefix}${segments[0]}`);
992
- };
993
- for (const [path, crNumber] of openChangeRequests.minePaths) {
994
- if (!pathExistsInTree(serverTree, path) && !hiddenRoot(path)) {
995
- map.set(path, crNumber);
996
- }
997
- }
998
- return map;
999
- }, [serverTree, openChangeRequests, kbDirName]);
1000
-
1001
- const mergedTree = useMemo(() => {
1002
- if (!serverTree || suggestionOnlyPaths.size === 0) return serverTree;
1003
- // Reuses the pending-upload synthesizer: same parent-directory creation,
1004
- // same sort order, and a real entry always wins over a synthesized one.
1005
- const asEntries = new Map<string, PendingEntry>();
1006
- for (const path of suggestionOnlyPaths.keys()) {
1007
- asEntries.set(path, { fullPath: path, type: 'file' });
1008
- }
1009
- return mergePendingIntoTree(serverTree, asEntries);
1010
- }, [serverTree, suggestionOnlyPaths]);
1011
-
1012
- // A clicked suggestion row opens the SHARED change-request dialog on the
1013
- // request the path belongs to — the row is a link to the request, and the
1014
- // dialog is the one change-request view the app has.
1015
- const [openSuggestionCr, setOpenSuggestionCr] = useState<PullRequestSummary | null>(null);
1016
- const suggestionsController = useMemo<SuggestionsController>(
1017
- () => ({
1018
- crFor: (path) => suggestionOnlyPaths.get(path) ?? null,
1019
- open: (path, crNumber) => {
1020
- const cr = openChangeRequests.forPath(path).find((c) => c.number === crNumber) ?? null;
1021
- setOpenSuggestionCr(cr);
1022
- },
1023
- }),
1024
- [suggestionOnlyPaths, openChangeRequests],
1025
- );
1140
+ const { tree: mergedTree, suggestionOnlyPaths } = useMergedWorkspaceTree();
1141
+ // The pane workspace's own navigation: the open tab is the current row, and
1142
+ // a click opens the file on the checked-out branch.
1143
+ const nav = useMemo<TreeNav>(() => ({ activePath: openFilePath, open: openFile }), [openFilePath, openFile]);
1026
1144
 
1027
1145
  // Pinned folders — a personal, client-side shortcut list surfaced at the top
1028
1146
  // of the explorer. Stored as relativePaths in localStorage; toggled from the
@@ -1040,7 +1158,7 @@ export function FileExplorer() {
1040
1158
  });
1041
1159
  }, []);
1042
1160
  const pinnedController = useMemo<PinnedController>(
1043
- () => ({ isPinned: (path) => pinnedPaths.includes(path), togglePin }),
1161
+ () => ({ available: true, isPinned: (path) => pinnedPaths.includes(path), togglePin }),
1044
1162
  [pinnedPaths, togglePin],
1045
1163
  );
1046
1164
  // Resolve pinned paths to live tree entries, dropping any that no longer
@@ -1061,9 +1179,6 @@ export function FileExplorer() {
1061
1179
  // ships none of its own.
1062
1180
  const { explorerItems } = useAppRegistry();
1063
1181
 
1064
- // Right-click → Manage access opens this sheet for the chosen entry.
1065
- const [accessTarget, setAccessTarget] = useState<FileTreeEntry | null>(null);
1066
-
1067
1182
  // KB content splits into separate top-level folders; surface them as labelled
1068
1183
  // sections rather than a single flat root. The Knowledge section hoists
1069
1184
  // `KnowledgeBase/`'s children and folds in any other top-level content folder
@@ -1079,6 +1194,10 @@ export function FileExplorer() {
1079
1194
  // from the plugin page. Deep links into a plugin file still resolve; the
1080
1195
  // folder just is not a browsing destination in Knowledge.
1081
1196
  //
1197
+ // `Skills/` neither: the Skills & Tools sidebar renders that root as its
1198
+ // own tree (`SkillsTree`), with these same rows, and a skill file opens on
1199
+ // its skill page there.
1200
+ //
1082
1201
  // `Data/`, `Agents/` and `Pipelines/` are rendered when PRESENT but never
1083
1202
  // created by core (see `CORE_REQUIRED_DIRS`) — a deployment that owns the
1084
1203
  // agentic execution layer seeds them, and this reads whatever is there.
@@ -1098,7 +1217,9 @@ export function FileExplorer() {
1098
1217
  // without it a KB whose only root is Plugins would fail this check, fall
1099
1218
  // back to the flat tree, and show the folder that way instead.
1100
1219
  const plugins = findDir(PLUGINS_DIR);
1101
- if (!knowledgeBase && !data && !agents && !pipelines && !plugins) return null;
1220
+ // Same for Skills: the Library surface renders it, not this explorer.
1221
+ const skills = findDir(SKILLS_DIR);
1222
+ if (!knowledgeBase && !data && !agents && !pipelines && !plugins && !skills) return null;
1102
1223
  // Any other top-level content folder (e.g. a stray `Legal/`) folds into Knowledge.
1103
1224
  const otherDirs = kids.filter(
1104
1225
  (c) => c.type === 'directory' && !KB_ROOT_DIRS.has(c.name),
@@ -1148,7 +1269,7 @@ export function FileExplorer() {
1148
1269
  );
1149
1270
 
1150
1271
  return (
1151
- <>
1272
+ <TreeChrome nav={nav} suggestionOnlyPaths={suggestionOnlyPaths} pinned={pinnedController}>
1152
1273
  {/* No background, no border, no width: this is the CONTENTS of the app's
1153
1274
  one sidebar, and `SidebarFrame` is the sidebar. It used to be
1154
1275
  `bg-white` against the Library's `bg-sidebar`, which is how two navs in
@@ -1172,49 +1293,7 @@ export function FileExplorer() {
1172
1293
  setDragOver(false);
1173
1294
  }}
1174
1295
  >
1175
- {uploadError && (
1176
- <div
1177
- role="alert"
1178
- className="flex items-start gap-1 px-2 py-1 text-xs text-danger bg-danger-soft border-b border-danger/30 shrink-0"
1179
- >
1180
- <span className="flex-1 truncate" title={uploadError.reason}>
1181
- Couldn't add {uploadError.filename}: {uploadError.reason}
1182
- </span>
1183
- <IconButton
1184
- size={18}
1185
- tone="danger"
1186
- title="Dismiss"
1187
- aria-label="Dismiss upload error"
1188
- onClick={clearUploadError}
1189
- >
1190
- <X size={12} />
1191
- </IconButton>
1192
- </div>
1193
- )}
1194
- {/* Not an error: the upload LANDED, on the suggestions branch. Saying
1195
- so is load-bearing — nothing appears in the tree where the user
1196
- dropped the files, and silence there reads as a failed upload. */}
1197
- {uploadNotice && (
1198
- <div
1199
- role="status"
1200
- className="flex items-start gap-1 px-2 py-1 text-xs text-ink bg-wait-soft border-b border-line shrink-0"
1201
- >
1202
- <span className="flex-1" title={uploadNotice}>
1203
- {uploadNotice}
1204
- </span>
1205
- <IconButton
1206
- size={18}
1207
- title="Dismiss"
1208
- aria-label="Dismiss upload notice"
1209
- onClick={clearUploadNotice}
1210
- >
1211
- <X size={12} />
1212
- </IconButton>
1213
- </div>
1214
- )}
1215
- <PinnedContext.Provider value={pinnedController}>
1216
- <ManageAccessContext.Provider value={setAccessTarget}>
1217
- <SuggestionsContext.Provider value={suggestionsController}>
1296
+ <UploadNotices />
1218
1297
  <div className="flex-1 overflow-y-auto min-h-0">
1219
1298
  {/* "Company Context", not "Pinned". The mechanism is pinning; the
1220
1299
  SECTION is the handful of places this company actually works out
@@ -1260,31 +1339,8 @@ export function FileExplorer() {
1260
1339
  <FileTreeNode entry={mergedTree} depth={0} />
1261
1340
  )}
1262
1341
  </div>
1263
- </SuggestionsContext.Provider>
1264
- </ManageAccessContext.Provider>
1265
- </PinnedContext.Provider>
1266
1342
  <PullRequestsForMe />
1267
1343
  </div>
1268
- {openSuggestionCr && (
1269
- <ChangeRequestDialog
1270
- cr={openSuggestionCr}
1271
- onClose={() => setOpenSuggestionCr(null)}
1272
- onResolved={() => {
1273
- setOpenSuggestionCr(null);
1274
- window.dispatchEvent(new Event(PR_STALE_EVENT));
1275
- }}
1276
- />
1277
- )}
1278
- {accessTarget && (
1279
- <ManageAccessDialog
1280
- key={accessTarget.relativePath}
1281
- entry={accessTarget}
1282
- // The dialog is keyed on the path, so pointing it at a parent remounts
1283
- // it against that folder — the whole retarget is this one setter.
1284
- onManageAncestor={setAccessTarget}
1285
- onClose={() => setAccessTarget(null)}
1286
- />
1287
- )}
1288
- </>
1344
+ </TreeChrome>
1289
1345
  );
1290
1346
  }