@bevel-software/platform-core-frontend 0.35.0 → 0.37.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 (75) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +40 -97
  3. package/src/core/KnowledgeSurface.tsx +92 -0
  4. package/src/core/__tests__/CoreAppShell.root-claims.test.tsx +280 -0
  5. package/src/core/registry.ts +110 -2
  6. package/src/index.ts +3 -0
  7. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +1 -1
  8. package/src/modules/access/hooks/useFileAccess.ts +1 -1
  9. package/src/modules/audit/components/principal-grouping.ts +49 -49
  10. package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +1 -1
  11. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +6 -6
  12. package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +8 -8
  13. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +1 -1
  14. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +1 -1
  15. package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +1 -1
  16. package/src/modules/git/__tests__/pr.api.test.ts +3 -3
  17. package/src/modules/git/components/FileHistoryPanel.tsx +1 -1
  18. package/src/modules/git/components/GitSyncFailedBanner.tsx +1 -1
  19. package/src/modules/git/services/git.api.ts +1 -1
  20. package/src/modules/git/services/pr-prompts.ts +1 -1
  21. package/src/modules/layout/state/layout.context.ts +8 -0
  22. package/src/modules/library/__tests__/SkillPage.test.tsx +5 -5
  23. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +11 -0
  24. package/src/modules/library/__tests__/ToolVarRow.test.tsx +109 -0
  25. package/src/modules/library/components/tool-page/ToolVarRow.tsx +86 -19
  26. package/src/modules/library/services/library.api.ts +2 -2
  27. package/src/modules/onboarding/__tests__/onboarding.test.tsx +8 -8
  28. package/src/modules/onboarding/state/agent-connection.ts +1 -1
  29. package/src/modules/pr/services/pr-merge.api.ts +1 -1
  30. package/src/modules/pr/services/pr-open.api.ts +1 -1
  31. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +96 -30
  32. package/src/modules/secrets-vault/components/IncludeToggle.tsx +29 -0
  33. package/src/modules/secrets-vault/components/ManagedConnectorCard.tsx +189 -0
  34. package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.managed.test.tsx +212 -0
  35. package/src/modules/secrets-vault/components/__tests__/ManagedConnectorCard.test.tsx +182 -0
  36. package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +3 -0
  37. package/src/modules/secrets-vault/components/__tests__/ToolSecretsPanel.test.tsx +1 -0
  38. package/src/modules/secrets-vault/components/__tests__/connect-lists-what-the-banner-counted.test.tsx +1 -0
  39. package/src/modules/secrets-vault/index.ts +2 -0
  40. package/src/modules/secrets-vault/probe/__tests__/probe-verdict.test.ts +1 -0
  41. package/src/modules/secrets-vault/services/connect.api.ts +46 -5
  42. package/src/modules/secrets-vault/services/tool-secrets.api.ts +21 -3
  43. package/src/modules/secrets-vault/utils/managed-card-state.ts +61 -0
  44. package/src/modules/setup/utils/__tests__/root-folders.test.ts +5 -1
  45. package/src/modules/setup/utils/root-folders.ts +2 -2
  46. package/src/modules/toolbar/components/Toolbar.tsx +1 -1
  47. package/src/modules/{workflow → version-control}/hooks/__tests__/useFileLock.test.tsx +10 -10
  48. package/src/modules/{workflow → version-control}/hooks/__tests__/useFileLock.wire.test.tsx +1 -1
  49. package/src/modules/{workflow → version-control}/hooks/useEventBusSubscription.ts +2 -2
  50. package/src/modules/{workflow → version-control}/hooks/useFileLock.ts +1 -1
  51. package/src/modules/{workflow → version-control}/index.ts +2 -2
  52. package/src/modules/{workflow → version-control}/services/__tests__/lock.api.test.ts +1 -1
  53. package/src/modules/{workflow → version-control}/state/EventBusProvider.tsx +6 -6
  54. package/src/modules/{workflow → version-control}/state/event-bus.context.ts +4 -4
  55. package/src/modules/workspace/components/FileExplorer.tsx +96 -41
  56. package/src/modules/workspace/components/FileRoute.tsx +24 -1
  57. package/src/modules/workspace/components/FileViewer.tsx +1 -1
  58. package/src/modules/workspace/components/KbPageHeader.tsx +1 -1
  59. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +159 -13
  60. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +50 -2
  61. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +5 -5
  62. package/src/modules/workspace/components/renderers/__tests__/ImageRenderer.test.tsx +5 -5
  63. package/src/modules/workspace/hooks/__tests__/useImageRevision.test.tsx +9 -9
  64. package/src/modules/workspace/hooks/__tests__/useWorkspaceImageResolver.test.tsx +7 -7
  65. package/src/modules/workspace/hooks/useImageRevision.ts +1 -1
  66. package/src/modules/workspace/hooks/useWorkspaceState.ts +2 -2
  67. package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +9 -9
  68. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +9 -1
  69. package/src/modules/workspace/utils/fileTree.ts +10 -2
  70. package/src/modules/workspace/utils/treeConfirm.ts +1 -1
  71. /package/src/modules/{workflow → version-control}/services/lock.api.ts +0 -0
  72. /package/src/modules/{workflow → version-control}/state/ChangeRequestStaleBinder.tsx +0 -0
  73. /package/src/modules/{workflow → version-control}/state/EventBusFocusBinder.tsx +0 -0
  74. /package/src/modules/{workflow → version-control}/state/__tests__/EventBusProvider.storage.test.tsx +0 -0
  75. /package/src/modules/{workflow → version-control}/state/__tests__/EventBusProvider.watch.test.tsx +0 -0
@@ -36,7 +36,7 @@ import {
36
36
  PLUGINS_DIR,
37
37
  SKILLS_DIR,
38
38
  AGENTS_DIR,
39
- PIPELINES_DIR,
39
+ WORKFLOWS_DIR,
40
40
  } from '@bevel-software/platform-shared';
41
41
  import {
42
42
  KNOWLEDGE_UPLOAD_TARGET,
@@ -57,7 +57,7 @@ import { uploadErrorNextStep } from '../utils/uploadError';
57
57
  import { useMergedWorkspaceTree } from '../hooks/useMergedWorkspaceTree';
58
58
  import { ChangeRequestDialog } from '../../change-requests/components/ChangeRequestDialog';
59
59
  import { PR_STALE_EVENT, SUGGESTIONS_RETRACTED_EVENT } from '../../../core/events';
60
- import { canonicalizeWorkspaceId, useEventBusSubscription } from '../../workflow';
60
+ import { canonicalizeWorkspaceId, useEventBusSubscription } from '../../version-control';
61
61
  import {
62
62
  listChangeRequestsUnderFolder,
63
63
  removeFolderFromChangeRequests,
@@ -76,7 +76,10 @@ import { AdminContext } from '../../admin';
76
76
  import { ManageAccessDialog } from '../../access/components/ManageAccessDialog';
77
77
  import { offersManageAccess, fetchFileAccess, fetchProspectiveAccess } from '../../access';
78
78
  import {
79
+ appClaimingRoot,
80
+ appHostingPath,
79
81
  useAppRegistry,
82
+ useRootClaims,
80
83
  type FolderMenuContext,
81
84
  type FolderMenuItemDef,
82
85
  type FolderMenuTools,
@@ -2232,13 +2235,18 @@ export const CHECKOUT_MISSING_MESSAGE = 'Nothing to show here: the repository ch
2232
2235
  * reserved roots aside, an entry anywhere counts, because a stray top-level
2233
2236
  * folder is folded into Knowledge). A Library tree shows one root
2234
2237
  * (`scope: 'root'`): it is empty when that root is, whatever the notes
2235
- * beside it hold.
2238
+ * beside it hold. A root an app claims is not in Knowledge's tree, so what
2239
+ * it holds does not count there either.
2236
2240
  */
2237
2241
  export function EmptyTreeNotice({ rootPath, scope = 'tree' }: { rootPath: string | null; scope?: 'tree' | 'root' }) {
2238
2242
  const { kbDirName } = useWorkspace();
2239
2243
  const { tree, withheld: listingWithheld } = useMergedWorkspaceTree();
2244
+ const claims = useRootClaims();
2240
2245
  const oneRoot = scope === 'root' && rootPath !== null;
2241
- const empty = tree !== null && (oneRoot ? !subtreeHasVisibleEntries(tree, rootPath) : !treeHasVisibleEntries(tree, kbDirName));
2246
+ const claimed = (name: string) => appClaimingRoot(claims, name) !== undefined;
2247
+ const empty =
2248
+ tree !== null &&
2249
+ (oneRoot ? !subtreeHasVisibleEntries(tree, rootPath) : !treeHasVisibleEntries(tree, kbDirName, claimed));
2242
2250
  // What was kept out of what THIS notice covers: one root's own count, or
2243
2251
  // the listing's — a Skills tree emptied by the rules says so; a Skills tree
2244
2252
  // that is simply empty beside a withheld Knowledge does not.
@@ -2384,8 +2392,15 @@ export function UploadNotices() {
2384
2392
  // (`checkoutRoot` lives in `../utils/fileTree` — the one lookup every
2385
2393
  // surface that reads the workspace tree goes through.)
2386
2394
 
2387
- export function FileExplorer() {
2395
+ /**
2396
+ * The Knowledge app's file tree. With `roots`, the tree of the folder surface
2397
+ * an app mounts for the roots it claims (see `AppDef.roots`): those
2398
+ * top-level folders as sections, in that order, and nothing else of the
2399
+ * knowledge base. Without it, every root no app claims.
2400
+ */
2401
+ export function FileExplorer({ roots }: { roots?: readonly string[] } = {}) {
2388
2402
  const { openFilePath, dispatchUpload, kbDirName } = useWorkspace();
2403
+ const claims = useRootClaims();
2389
2404
  const { openFile } = useFileNav();
2390
2405
  const [dragOver, setDragOver] = useState(false);
2391
2406
  // Download is a per-path permission (resolved server-side from the access
@@ -2429,14 +2444,25 @@ export function FileExplorer() {
2429
2444
  // Resolved from the CHECKOUT, not the workspace root, for the same reason
2430
2445
  // the sections are: a pin is a shortcut into the repository, and a path
2431
2446
  // that lands beside it resolves to nothing rather than to a row.
2447
+ //
2448
+ // A pin into a root this tree does not show is not on it either: Knowledge
2449
+ // leaves the claimed roots to their app, a narrowed tree shows its own.
2450
+ const showsPath = useCallback(
2451
+ (path: string) => {
2452
+ const root = path.split('/').filter(Boolean)[1]?.toLowerCase();
2453
+ if (!roots) return appHostingPath(claims, path, kbDirName) === undefined;
2454
+ return root !== undefined && roots.some((r) => r.toLowerCase() === root);
2455
+ },
2456
+ [roots, claims, kbDirName],
2457
+ );
2432
2458
  const pinnedEntries = useMemo(
2433
2459
  () =>
2434
2460
  checkout
2435
2461
  ? pinnedPaths
2436
2462
  .map((p) => findEntryByPath(checkout, p))
2437
- .filter((e): e is FileTreeEntry => e != null)
2463
+ .filter((e): e is FileTreeEntry => e != null && showsPath(e.relativePath))
2438
2464
  : [],
2439
- [checkout, pinnedPaths],
2465
+ [checkout, pinnedPaths, showsPath],
2440
2466
  );
2441
2467
 
2442
2468
  // Registry-contributed rows for the Pinned section (rendered below the
@@ -2464,18 +2490,34 @@ export function FileExplorer() {
2464
2490
  // own tree (`SkillsTree`), with these same rows, and a skill file opens on
2465
2491
  // its skill page there.
2466
2492
  //
2467
- // `Data/`, `Agents/` and `Pipelines/` are rendered when PRESENT but never
2493
+ // `Data/`, `Agents/` and `Workflows/` are rendered when PRESENT but never
2468
2494
  // created by core (see `CORE_REQUIRED_DIRS`) — a deployment that owns the
2469
2495
  // agentic execution layer seeds them, and this reads whatever is there.
2496
+ //
2497
+ // A root an app claims (`AppDef.roots`) is that app's to show: it is left
2498
+ // out here, whether reserved or not, and folds nowhere. A narrowed tree
2499
+ // (`roots`) is the other side of the same claim: its roots, nothing else.
2470
2500
  const sections = useMemo(() => {
2471
2501
  const kids = checkout?.children;
2472
2502
  if (!kids) return null;
2473
2503
  const findDir = (name: string) =>
2474
2504
  kids.find((c) => c.type === 'directory' && c.name === name);
2505
+ const asSection = (name: string): FileTreeEntry | null => {
2506
+ const found = findDir(name);
2507
+ return found ? { ...found, name } : null;
2508
+ };
2509
+ if (roots) {
2510
+ // By name in any case, as a claim is read (see `rootClaims`).
2511
+ const narrowed = roots
2512
+ .map((name) => kids.find((c) => c.type === 'directory' && c.name.toLowerCase() === name.toLowerCase()))
2513
+ .filter((e): e is FileTreeEntry => e !== undefined);
2514
+ return { knowledge: null, roots: narrowed, looseFiles: [] };
2515
+ }
2516
+ const claimed = (name: string) => appClaimingRoot(claims, name) !== undefined;
2475
2517
  const knowledgeBase = findDir(KNOWLEDGE_BASE_DIR);
2476
2518
  const data = findDir(DATA_DIR);
2477
2519
  const agents = findDir(AGENTS_DIR);
2478
- const pipelines = findDir(PIPELINES_DIR);
2520
+ const workflows = findDir(WORKFLOWS_DIR);
2479
2521
  // Plugins counts toward "is this a split layout?" even though it is never
2480
2522
  // rendered: its presence proves the split just as well as the others, and
2481
2523
  // without it a KB whose only root is Plugins would fail this check, fall
@@ -2483,12 +2525,13 @@ export function FileExplorer() {
2483
2525
  const plugins = findDir(PLUGINS_DIR);
2484
2526
  // Same for Skills: the Library surface renders it, not this explorer.
2485
2527
  const skills = findDir(SKILLS_DIR);
2486
- if (!knowledgeBase && !data && !agents && !pipelines && !plugins && !skills) return null;
2487
- // Any other top-level content folder (e.g. a stray `Legal/`) folds into Knowledge.
2528
+ if (!knowledgeBase && !data && !agents && !workflows && !plugins && !skills) return null;
2529
+ // Any other top-level content folder (e.g. a stray `Legal/`) folds into
2530
+ // Knowledge, unless an app claims it.
2488
2531
  const otherDirs = kids.filter(
2489
- (c) => c.type === 'directory' && !KB_ROOT_DIRS.has(c.name),
2532
+ (c) => c.type === 'directory' && !KB_ROOT_DIRS.has(c.name) && !claimed(c.name),
2490
2533
  );
2491
- // Present Knowledge, Data, Agents and Pipelines as named roots. Knowledge is
2534
+ // Present Knowledge, Data, Agents and Workflows as named roots. Knowledge is
2492
2535
  // synthetic so it can relabel `KnowledgeBase` and absorb the stray
2493
2536
  // content folders; it reuses KnowledgeBase's own path so file ops on the
2494
2537
  // row still resolve.
@@ -2501,19 +2544,31 @@ export function FileExplorer() {
2501
2544
  : otherDirs.length > 0
2502
2545
  ? { name: 'Knowledge', relativePath: otherDirs[0].relativePath, type: 'directory', children: otherDirs }
2503
2546
  : null;
2504
- const dataRoot: FileTreeEntry | null = data ? { ...data, name: DATA_DIR } : null;
2505
- const agentsRoot: FileTreeEntry | null = agents ? { ...agents, name: AGENTS_DIR } : null;
2506
- const pipelinesRoot: FileTreeEntry | null = pipelines
2507
- ? { ...pipelines, name: PIPELINES_DIR }
2508
- : null;
2509
2547
  return {
2510
2548
  knowledge,
2511
- data: dataRoot,
2512
- agents: agentsRoot,
2513
- pipelines: pipelinesRoot,
2549
+ roots: [DATA_DIR, AGENTS_DIR, WORKFLOWS_DIR]
2550
+ .filter((name) => !claimed(name))
2551
+ .map(asSection)
2552
+ .filter((e): e is FileTreeEntry => e !== null),
2514
2553
  looseFiles: kids.filter((c) => c.type === 'file'),
2515
2554
  };
2516
- }, [checkout]);
2555
+ }, [checkout, roots, claims]);
2556
+
2557
+ // The flat tree of a clone that predates the split, less the roots an app
2558
+ // claims: still the checkout row, with its own path and actions, so a
2559
+ // claim never makes another folder stand in for it.
2560
+ const flatRoot = useMemo(
2561
+ () =>
2562
+ checkout && claims.size > 0
2563
+ ? {
2564
+ ...checkout,
2565
+ children: checkout.children?.filter(
2566
+ (c) => c.type !== 'directory' || appClaimingRoot(claims, c.name) === undefined,
2567
+ ),
2568
+ }
2569
+ : checkout,
2570
+ [checkout, claims],
2571
+ );
2517
2572
 
2518
2573
  const handleDrop = useCallback(
2519
2574
  (e: React.DragEvent) => {
@@ -2522,7 +2577,11 @@ export function FileExplorer() {
2522
2577
  // target — the workspace root, beside the missing folder, where
2523
2578
  // nothing this sidebar shows can ever live. Refused before
2524
2579
  // `preventDefault`, so the browser's own cursor says "not here".
2525
- if (!checkout) return;
2580
+ //
2581
+ // A narrowed tree has no background folder either: the checkout is not
2582
+ // one of its roots, and a file dropped there would land out of sight.
2583
+ // Its folders' own rows take drops as they do in Knowledge.
2584
+ if (!checkout || roots) return;
2526
2585
  e.preventDefault();
2527
2586
  setDragOver(false);
2528
2587
  // Only handle external file/folder drops at the root level.
@@ -2539,7 +2598,7 @@ export function FileExplorer() {
2539
2598
  const files = Array.from(e.dataTransfer.files);
2540
2599
  if (files.length > 0) dispatchUpload({ kind: 'files', files }, target, KNOWLEDGE_UPLOAD_TARGET);
2541
2600
  },
2542
- [checkout, dispatchUpload],
2601
+ [checkout, roots, dispatchUpload],
2543
2602
  );
2544
2603
 
2545
2604
  return (
@@ -2561,7 +2620,7 @@ export function FileExplorer() {
2561
2620
  onDragOver={(e) => {
2562
2621
  // Same refusal as the drop: no checkout, no drop target, so no
2563
2622
  // highlight promising one.
2564
- if (!checkout) return;
2623
+ if (!checkout || roots) return;
2565
2624
  e.preventDefault();
2566
2625
  setDragOver(true);
2567
2626
  }}
@@ -2583,9 +2642,9 @@ export function FileExplorer() {
2583
2642
  {pinnedEntries.map((e) => (
2584
2643
  <FileTreeNode key={`pin:${e.relativePath}`} entry={e} depth={0} collapseChildren />
2585
2644
  ))}
2586
- {explorerItems.map(({ id, Component }) => (
2587
- <Component key={id} tree={mergedTree} />
2588
- ))}
2645
+ {/* Knowledge's own rows (the graph view): not part of a narrowed tree. */}
2646
+ {!roots &&
2647
+ explorerItems.map(({ id, Component }) => <Component key={id} tree={mergedTree} />)}
2589
2648
  <div className="mx-3 my-2 border-t border-line" />
2590
2649
  {!mergedTree ? (
2591
2650
  <div className="px-3 py-4 text-xs text-ink-muted">Loading...</div>
@@ -2598,15 +2657,9 @@ export function FileExplorer() {
2598
2657
  {sections.knowledge && (
2599
2658
  <FileTreeNode entry={sections.knowledge} depth={0} collapseChildren />
2600
2659
  )}
2601
- {sections.data && (
2602
- <FileTreeNode entry={sections.data} depth={0} collapseChildren />
2603
- )}
2604
- {sections.agents && (
2605
- <FileTreeNode entry={sections.agents} depth={0} collapseChildren />
2606
- )}
2607
- {sections.pipelines && (
2608
- <FileTreeNode entry={sections.pipelines} depth={0} collapseChildren />
2609
- )}
2660
+ {sections.roots.map((root) => (
2661
+ <FileTreeNode key={root.relativePath} entry={root} depth={0} collapseChildren />
2662
+ ))}
2610
2663
  {sections.looseFiles.length > 0 && (
2611
2664
  <>
2612
2665
  <div className="mx-3 my-2 border-t border-line" />
@@ -2622,7 +2675,7 @@ export function FileExplorer() {
2622
2675
  // fallback is a different SHAPE, never a different directory — and
2623
2676
  // it is the ROOT row, not a folder inside one: the workspace
2624
2677
  // directory above it is not something this explorer shows.
2625
- <FileTreeNode entry={checkout} depth={0} root />
2678
+ <FileTreeNode entry={flatRoot ?? checkout} depth={0} root />
2626
2679
  )}
2627
2680
  {/* Under the (empty) roots, so the hint's "folder above" is on
2628
2681
  screen: Knowledge's own folder is where a first page goes. A tree
@@ -2630,9 +2683,11 @@ export function FileExplorer() {
2630
2683
  folder itself is where a first page goes — and when there is no
2631
2684
  checkout at all the notice says THAT instead, and there is no
2632
2685
  folder to offer. */}
2633
- <EmptyTreeNotice
2634
- rootPath={sections ? sections.knowledge?.relativePath ?? null : checkout?.relativePath ?? null}
2635
- />
2686
+ {!roots && (
2687
+ <EmptyTreeNotice
2688
+ rootPath={sections ? sections.knowledge?.relativePath ?? null : checkout?.relativePath ?? null}
2689
+ />
2690
+ )}
2636
2691
  </div>
2637
2692
  </div>
2638
2693
  </TreeChrome>
@@ -15,6 +15,7 @@ import {
15
15
  } from '../routing/kb-routes';
16
16
  import { Banner, Button, Surface, useLatestRef } from '../../../shared/components';
17
17
  import { FileViewer } from './FileViewer';
18
+ import { appHostingPath, useRootClaims } from '../../../core/registry';
18
19
 
19
20
  type SyncError =
20
21
  | { kind: 'dirty'; current: string; target: string; dirtyFilenames: string[] }
@@ -33,6 +34,10 @@ type SyncError =
33
34
  * `.tool` behind "Edit the tool file", a note with a frontmatter id — back to
34
35
  * the Knowledge surface, which is exactly the switch that frame exists to
35
36
  * avoid. The path URL stays; the file is the same.
37
+ *
38
+ * A file under a root an app claims (`AppDef.roots`) is the same case, and
39
+ * needs no flag: its path URL is what opens it in that app, so it is never
40
+ * replaced, and an id URL that resolves to it is replaced by its path URL.
36
41
  */
37
42
  export function FileRoute({ canonicalize = true }: { canonicalize?: boolean } = {}) {
38
43
  const params = useParams<{ branch: string; '*': string }>();
@@ -54,6 +59,7 @@ export function FileRoute({ canonicalize = true }: { canonicalize?: boolean } =
54
59
  // to be a node is canonicalized to its id URL (the redirect effect).
55
60
  const segment = params['*'] ?? '';
56
61
  const segmentIsId = NODE_ID_LINK_RE.test(segment);
62
+ const claims = useRootClaims();
57
63
 
58
64
  const workspace = useWorkspace();
59
65
  const git = useGit();
@@ -123,6 +129,22 @@ export function FileRoute({ canonicalize = true }: { canonicalize?: boolean } =
123
129
  };
124
130
  }, [segmentIsId, segment, branchFromUrl]);
125
131
 
132
+ // ── An id URL for a hosted file → its path URL ───────────────────────────
133
+ // The path URL is the one that opens the file in the app hosting its root;
134
+ // the id URL would keep it here. Same entry, same state and query, as the
135
+ // canonical swap below.
136
+ const hostedPath =
137
+ segmentIsId && idResolved?.seg === segment && idResolved.branch === branchFromUrl && idResolved.path
138
+ ? appHostingPath(claims, idResolved.path, workspace.kbDirName) && idResolved.path
139
+ : undefined;
140
+ useEffect(() => {
141
+ if (!hostedPath) return;
142
+ navigate(kbFileUrl(branchFromUrl, hostedPath) + location.search + location.hash, {
143
+ replace: true,
144
+ state: location.state,
145
+ });
146
+ }, [hostedPath, branchFromUrl, navigate, location.search, location.hash, location.state]);
147
+
126
148
  // ── Canonicalize a path URL → the node's id URL ──────────────────────────
127
149
  // Once the file is the active tab, look up its node id and replace the path
128
150
  // URL with `/workspace/<branch>/<id>`. Non-node files (no id) stay path-based.
@@ -141,6 +163,7 @@ export function FileRoute({ canonicalize = true }: { canonicalize?: boolean } =
141
163
  const searchRef = useLatestRef(location.search);
142
164
  useEffect(() => {
143
165
  if (!canonicalize || segmentIsId || !segment || !branchFromUrl) return;
166
+ if (appHostingPath(claims, segment, workspace.kbDirName)) return;
144
167
  if (openFilePath !== segment) return;
145
168
  let cancelled = false;
146
169
  (async () => {
@@ -155,7 +178,7 @@ export function FileRoute({ canonicalize = true }: { canonicalize?: boolean } =
155
178
  return () => {
156
179
  cancelled = true;
157
180
  };
158
- }, [canonicalize, segmentIsId, segment, branchFromUrl, openFilePath, location.hash, navigate, routerStateRef, searchRef]);
181
+ }, [canonicalize, segmentIsId, segment, branchFromUrl, openFilePath, location.hash, navigate, routerStateRef, searchRef, claims, workspace.kbDirName]);
159
182
 
160
183
  // ── Branch sync + hydrate + URL → state (forward direction) ──────────────
161
184
 
@@ -28,7 +28,7 @@ import {
28
28
  type OpenComparisonDetail,
29
29
  } from '../../../core/events';
30
30
  import { useAppRegistry } from '../../../core/registry';
31
- import { LockApiError, SELF_HOLD_MESSAGE, useFileLock } from '../../workflow';
31
+ import { LockApiError, SELF_HOLD_MESSAGE, useFileLock } from '../../version-control';
32
32
  import { useAuth } from '../../auth';
33
33
  import {
34
34
  knowledgeSuggestionBranchFor,
@@ -17,7 +17,7 @@ import { useDismissableMenu } from '../../../shared/components';
17
17
  import { HEADER_BAND, PAGE_HEADER_TESTID, TITLE_INK_ROOM } from '../../../shared/theme/header';
18
18
  import { rootAnchoredPath } from '../utils/pasteLink';
19
19
  import { displayFileName, fileNameTooltip } from '../utils/display-file-name';
20
- import { SELF_HOLD_MESSAGE } from '../../workflow';
20
+ import { SELF_HOLD_MESSAGE } from '../../version-control';
21
21
  import { FullScreenButton } from './FullScreenView';
22
22
 
23
23
  /**
@@ -18,11 +18,12 @@ import { AuthContext, type AuthContextValue } from '../../../auth';
18
18
  import { OpenChangeRequestsContext } from '../../state/open-change-requests.context';
19
19
  import { AdminContext, type AdminContextValue } from '../../../admin';
20
20
  import { PR_STALE_EVENT } from '../../../../core/events';
21
- import { EventBusProvider } from '../../../workflow';
22
- import type { WorkflowEvent } from '@bevel-software/platform-shared';
21
+ import { EventBusProvider } from '../../../version-control';
22
+ import type { VersionControlEvent } from '@bevel-software/platform-shared';
23
23
  import {
24
24
  AppRegistryContext,
25
25
  makeRegistry,
26
+ type AppDef,
26
27
  type FolderMenuContext,
27
28
  type FolderMenuItemDef,
28
29
  type FolderMenuTools,
@@ -200,6 +201,10 @@ interface RenderOptions {
200
201
  * empty, which is what every other test in this file renders against.
201
202
  */
202
203
  folderMenuItems?: FolderMenuItemDef[];
204
+ /** Apps in the registry — the ones whose `roots` claim top-level folders. */
205
+ apps?: AppDef[];
206
+ /** Render the narrowed tree an app mounts for its roots. */
207
+ roots?: string[];
203
208
  /** The workspace id — the encoded branch name, so it decides "protected". */
204
209
  workspaceId?: string;
205
210
  openFilePath?: string | null;
@@ -285,7 +290,7 @@ function renderExplorer(opts: RenderOptions = {}) {
285
290
  // the fixture must not hand out a pair that cannot exist.
286
291
  workspaceBranch: decodeURIComponent(opts.workspaceId ?? 'ws-1'),
287
292
  });
288
- const registry = makeRegistry({ folderMenuItems: opts.folderMenuItems ?? [] });
293
+ const registry = makeRegistry({ folderMenuItems: opts.folderMenuItems ?? [], apps: opts.apps ?? [] });
289
294
  const ui = (ws: WorkspaceContextValue, mine: Map<string, number>) => (
290
295
  <MemoryRouter initialEntries={opts.initialEntries ?? ['/']}>
291
296
  <AppRegistryContext.Provider value={registry}>
@@ -322,7 +327,7 @@ function renderExplorer(opts: RenderOptions = {}) {
322
327
  mineNumbers: new Set(opts.mineNumbers ?? [...mine.values()]),
323
328
  }}
324
329
  >
325
- <FileExplorer />
330
+ <FileExplorer roots={opts.roots} />
326
331
  <LocationProbe />
327
332
  </OpenChangeRequestsContext.Provider>
328
333
  </GitContext.Provider>
@@ -1163,6 +1168,17 @@ describe('FileExplorer sections: root folders', () => {
1163
1168
  cleanup();
1164
1169
  });
1165
1170
 
1171
+ /**
1172
+ * The root names on screen, in document order. Knowledge renders open, so
1173
+ * a folder folded into it shows between it and the next section.
1174
+ */
1175
+ const sectionNames = () =>
1176
+ ['Knowledge', 'Data', 'Agents', 'Workflows', 'Pipelines', 'Legal']
1177
+ .map((name) => screen.queryByText(name))
1178
+ .filter((el): el is HTMLElement => el !== null)
1179
+ .sort((a, b) => (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1))
1180
+ .map((el) => el.textContent);
1181
+
1166
1182
  const dir = (name: string): FileTreeEntry => ({
1167
1183
  name,
1168
1184
  relativePath: name,
@@ -1171,23 +1187,111 @@ describe('FileExplorer sections: root folders', () => {
1171
1187
  });
1172
1188
 
1173
1189
  /**
1174
- * `Data/`, `Agents/` and `Pipelines/` are never created by core — a
1190
+ * `Data/`, `Agents/` and `Workflows/` are never created by core — a
1175
1191
  * deployment that owns the agentic execution layer seeds them. When they ARE
1176
1192
  * there they get their own sections, and in particular must not fold into
1177
1193
  * Knowledge the way a stray content folder does.
1178
1194
  */
1179
- it('renders Data, Agents and Pipelines as their own sections when present', () => {
1195
+ it('renders Data, Agents and Workflows as their own sections when present, in that order', () => {
1180
1196
  const tree: FileTreeEntry = {
1181
1197
  name: '.',
1182
1198
  relativePath: '.',
1183
1199
  type: 'directory',
1184
- children: [dir('KnowledgeBase'), dir('Data'), dir('Agents'), dir('Pipelines')],
1200
+ children: [dir('Workflows'), dir('KnowledgeBase'), dir('Agents'), dir('Data')],
1185
1201
  };
1186
1202
  renderExplorer({ fileTree: tree });
1187
- expect(screen.getByText('Knowledge')).toBeInTheDocument();
1188
- expect(screen.getByText('Data')).toBeInTheDocument();
1189
- expect(screen.getByText('Agents')).toBeInTheDocument();
1190
- expect(screen.getByText('Pipelines')).toBeInTheDocument();
1203
+ expect(sectionNames()).toEqual(['Knowledge', 'Data', 'Agents', 'Workflows']);
1204
+ });
1205
+
1206
+ /** `Pipelines` is not a name core knows: a stray folder like any other. */
1207
+ it('folds a Pipelines folder into Knowledge', () => {
1208
+ const tree: FileTreeEntry = {
1209
+ name: '.',
1210
+ relativePath: '.',
1211
+ type: 'directory',
1212
+ children: [dir('Data'), dir('Pipelines'), dir('KnowledgeBase')],
1213
+ };
1214
+ renderExplorer({ fileTree: tree });
1215
+ expect(sectionNames()).toEqual(['Knowledge', 'Pipelines', 'Data']);
1216
+ });
1217
+
1218
+ const agentsApp = (roots: string[]): AppDef => ({
1219
+ id: 'agents',
1220
+ label: 'Agents',
1221
+ path: '/agents',
1222
+ element: <div />,
1223
+ roots,
1224
+ });
1225
+
1226
+ /**
1227
+ * A root an app claims is that app's to show. Left out of Knowledge
1228
+ * whether core reserves the name or not, and folded nowhere.
1229
+ */
1230
+ it('leaves out the roots an app claims, reserved or not', () => {
1231
+ const tree: FileTreeEntry = {
1232
+ name: '.',
1233
+ relativePath: '.',
1234
+ type: 'directory',
1235
+ children: [dir('KnowledgeBase'), dir('Data'), dir('Agents'), dir('Workflows'), dir('Pipelines'), dir('Legal')],
1236
+ };
1237
+ renderExplorer({ fileTree: tree, apps: [agentsApp(['Agents', 'Workflows', 'Data', 'Pipelines'])] });
1238
+ // The stray folder still folds in; the claimed ones show nowhere.
1239
+ expect(sectionNames()).toEqual(['Knowledge', 'Legal']);
1240
+ });
1241
+
1242
+ /**
1243
+ * A tree with none of core's roots falls back to the flat tree: the
1244
+ * checkout row, with its own path and actions. A claimed root is left out
1245
+ * of it, and no other folder stands in for a Knowledge section.
1246
+ */
1247
+ it('keeps a claimed root out of a tree with none of core’s roots', () => {
1248
+ const tree: FileTreeEntry = {
1249
+ name: '.',
1250
+ relativePath: '.',
1251
+ type: 'directory',
1252
+ children: [dir('Pipelines'), dir('Legal')],
1253
+ };
1254
+ renderExplorer({ fileTree: tree, apps: [agentsApp(['Pipelines'])] });
1255
+ expect(screen.getByText('Legal')).toBeInTheDocument();
1256
+ expect(screen.queryByText('Pipelines')).not.toBeInTheDocument();
1257
+ expect(screen.queryByText('Knowledge')).not.toBeInTheDocument();
1258
+ });
1259
+
1260
+ /** Root names compare case-insensitively, as the layout's do. */
1261
+ it('leaves out a root claimed in another case', () => {
1262
+ const tree: FileTreeEntry = {
1263
+ name: '.',
1264
+ relativePath: '.',
1265
+ type: 'directory',
1266
+ children: [dir('KnowledgeBase'), dir('Agents'), dir('Legal')],
1267
+ };
1268
+ renderExplorer({ fileTree: tree, apps: [agentsApp(['agents', 'LEGAL'])] });
1269
+ expect(sectionNames()).toEqual(['Knowledge']);
1270
+ });
1271
+
1272
+ /** The narrowed tree: its roots, in its order, and nothing else of the knowledge base. */
1273
+ it('shows only its roots when narrowed', () => {
1274
+ const tree: FileTreeEntry = {
1275
+ name: '.',
1276
+ relativePath: '.',
1277
+ type: 'directory',
1278
+ children: [
1279
+ dir('KnowledgeBase'),
1280
+ dir('Data'),
1281
+ dir('Agents'),
1282
+ dir('Workflows'),
1283
+ dir('Legal'),
1284
+ { name: 'roles.yaml', relativePath: 'roles.yaml', type: 'file' },
1285
+ ],
1286
+ };
1287
+ renderExplorer({
1288
+ fileTree: tree,
1289
+ apps: [agentsApp(['Agents', 'Workflows'])],
1290
+ roots: ['Workflows', 'Agents'],
1291
+ });
1292
+ expect(sectionNames()).toEqual(['Workflows', 'Agents']);
1293
+ expect(screen.queryByText('Knowledge')).not.toBeInTheDocument();
1294
+ expect(screen.queryByText('roles.yaml')).not.toBeInTheDocument();
1191
1295
  });
1192
1296
 
1193
1297
  /**
@@ -3171,6 +3275,48 @@ describe('FileExplorer: an empty tree says why', () => {
3171
3275
  renderExplorer({ fileTree: null });
3172
3276
  expect(screen.queryByTestId('tree-empty-notice')).not.toBeInTheDocument();
3173
3277
  });
3278
+
3279
+ /**
3280
+ * A root an app claims is not in Knowledge's tree, so what it holds does
3281
+ * not make that tree non-empty: the notice and its hint still show.
3282
+ */
3283
+ const hostingApp = (roots: string[]): AppDef => ({
3284
+ id: 'agents',
3285
+ label: 'Agents',
3286
+ path: '/agents',
3287
+ element: <div />,
3288
+ roots,
3289
+ });
3290
+
3291
+ it('says "empty" when the only content is under a claimed root', () => {
3292
+ renderExplorer({
3293
+ fileTree: seeded([], {}, [dirAt(`${KBD}/Agents`, [fileAt(`${KBD}/Agents/Planner.md`)])]),
3294
+ apps: [hostingApp(['Agents'])],
3295
+ workspaceId: 'alice%2Fdraft',
3296
+ });
3297
+ expect(screen.getByTestId('tree-empty-notice')).toHaveTextContent('This knowledge base is empty.');
3298
+ expect(screen.getByTestId('tree-empty-create-hint')).toBeInTheDocument();
3299
+ });
3300
+
3301
+ it('says "empty" for a tree that predates the split whose only folder is claimed', () => {
3302
+ renderExplorer({
3303
+ fileTree: rootedAtCheckout(
3304
+ dirAt('.', [dirAt(KBD, [dirAt(`${KBD}/Pipelines`, [fileAt(`${KBD}/Pipelines/run.workflow`)])])]),
3305
+ ),
3306
+ apps: [hostingApp(['Pipelines'])],
3307
+ workspaceId: 'alice%2Fdraft',
3308
+ });
3309
+ expect(screen.queryByText('Pipelines')).not.toBeInTheDocument();
3310
+ expect(screen.getByTestId('tree-empty-notice')).toHaveTextContent('This knowledge base is empty.');
3311
+ expect(screen.getByTestId('tree-empty-create-hint')).toBeInTheDocument();
3312
+ });
3313
+
3314
+ it('still counts that content when no app claims the root', () => {
3315
+ renderExplorer({
3316
+ fileTree: seeded([], {}, [dirAt(`${KBD}/Agents`, [fileAt(`${KBD}/Agents/Planner.md`)])]),
3317
+ });
3318
+ expect(screen.queryByTestId('tree-empty-notice')).not.toBeInTheDocument();
3319
+ });
3174
3320
  });
3175
3321
 
3176
3322
  // The sidebar refuses a platform file's drag and its rename itself, with the
@@ -4261,7 +4407,7 @@ describe('FileExplorer: a document the server could not read', () => {
4261
4407
  this.listeners.set(type, (this.listeners.get(type) ?? []).filter((f) => f !== fn));
4262
4408
  }
4263
4409
  close() {}
4264
- deliver(event: WorkflowEvent) {
4410
+ deliver(event: VersionControlEvent) {
4265
4411
  for (const fn of [...(this.listeners.get('message') ?? [])]) {
4266
4412
  fn(new MessageEvent('message', { data: JSON.stringify(event) }));
4267
4413
  }
@@ -4298,7 +4444,7 @@ describe('FileExplorer: a document the server could not read', () => {
4298
4444
  let id = 1;
4299
4445
  const push = (payload: { workspaceId: string; path: string; reason: string }) =>
4300
4446
  act(() => {
4301
- const event = { id: id++, ts: new Date().toISOString(), kind: 'document-unreadable', ...payload } as WorkflowEvent;
4447
+ const event = { id: id++, ts: new Date().toISOString(), kind: 'document-unreadable', ...payload } as VersionControlEvent;
4302
4448
  FakeEventSource.current!.deliver(event);
4303
4449
  });
4304
4450
  return { push };