@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.
- package/package.json +2 -2
- package/src/core/CoreAppShell.tsx +40 -97
- package/src/core/KnowledgeSurface.tsx +92 -0
- package/src/core/__tests__/CoreAppShell.root-claims.test.tsx +280 -0
- package/src/core/registry.ts +110 -2
- package/src/index.ts +3 -0
- package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +1 -1
- package/src/modules/access/hooks/useFileAccess.ts +1 -1
- package/src/modules/audit/components/principal-grouping.ts +49 -49
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +1 -1
- package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +6 -6
- package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +8 -8
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +1 -1
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +1 -1
- package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +1 -1
- package/src/modules/git/__tests__/pr.api.test.ts +3 -3
- package/src/modules/git/components/FileHistoryPanel.tsx +1 -1
- package/src/modules/git/components/GitSyncFailedBanner.tsx +1 -1
- package/src/modules/git/services/git.api.ts +1 -1
- package/src/modules/git/services/pr-prompts.ts +1 -1
- package/src/modules/layout/state/layout.context.ts +8 -0
- package/src/modules/library/__tests__/SkillPage.test.tsx +5 -5
- package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +11 -0
- package/src/modules/library/__tests__/ToolVarRow.test.tsx +109 -0
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +86 -19
- package/src/modules/library/services/library.api.ts +2 -2
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +8 -8
- package/src/modules/onboarding/state/agent-connection.ts +1 -1
- package/src/modules/pr/services/pr-merge.api.ts +1 -1
- package/src/modules/pr/services/pr-open.api.ts +1 -1
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +96 -30
- package/src/modules/secrets-vault/components/IncludeToggle.tsx +29 -0
- package/src/modules/secrets-vault/components/ManagedConnectorCard.tsx +189 -0
- package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.managed.test.tsx +212 -0
- package/src/modules/secrets-vault/components/__tests__/ManagedConnectorCard.test.tsx +182 -0
- package/src/modules/secrets-vault/components/__tests__/SecretsPage.test.tsx +3 -0
- package/src/modules/secrets-vault/components/__tests__/ToolSecretsPanel.test.tsx +1 -0
- package/src/modules/secrets-vault/components/__tests__/connect-lists-what-the-banner-counted.test.tsx +1 -0
- package/src/modules/secrets-vault/index.ts +2 -0
- package/src/modules/secrets-vault/probe/__tests__/probe-verdict.test.ts +1 -0
- package/src/modules/secrets-vault/services/connect.api.ts +46 -5
- package/src/modules/secrets-vault/services/tool-secrets.api.ts +21 -3
- package/src/modules/secrets-vault/utils/managed-card-state.ts +61 -0
- package/src/modules/setup/utils/__tests__/root-folders.test.ts +5 -1
- package/src/modules/setup/utils/root-folders.ts +2 -2
- package/src/modules/toolbar/components/Toolbar.tsx +1 -1
- package/src/modules/{workflow → version-control}/hooks/__tests__/useFileLock.test.tsx +10 -10
- package/src/modules/{workflow → version-control}/hooks/__tests__/useFileLock.wire.test.tsx +1 -1
- package/src/modules/{workflow → version-control}/hooks/useEventBusSubscription.ts +2 -2
- package/src/modules/{workflow → version-control}/hooks/useFileLock.ts +1 -1
- package/src/modules/{workflow → version-control}/index.ts +2 -2
- package/src/modules/{workflow → version-control}/services/__tests__/lock.api.test.ts +1 -1
- package/src/modules/{workflow → version-control}/state/EventBusProvider.tsx +6 -6
- package/src/modules/{workflow → version-control}/state/event-bus.context.ts +4 -4
- package/src/modules/workspace/components/FileExplorer.tsx +96 -41
- package/src/modules/workspace/components/FileRoute.tsx +24 -1
- package/src/modules/workspace/components/FileViewer.tsx +1 -1
- package/src/modules/workspace/components/KbPageHeader.tsx +1 -1
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +159 -13
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +50 -2
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +5 -5
- package/src/modules/workspace/components/renderers/__tests__/ImageRenderer.test.tsx +5 -5
- package/src/modules/workspace/hooks/__tests__/useImageRevision.test.tsx +9 -9
- package/src/modules/workspace/hooks/__tests__/useWorkspaceImageResolver.test.tsx +7 -7
- package/src/modules/workspace/hooks/useImageRevision.ts +1 -1
- package/src/modules/workspace/hooks/useWorkspaceState.ts +2 -2
- package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +9 -9
- package/src/modules/workspace/utils/__tests__/fileTree.test.ts +9 -1
- package/src/modules/workspace/utils/fileTree.ts +10 -2
- package/src/modules/workspace/utils/treeConfirm.ts +1 -1
- /package/src/modules/{workflow → version-control}/services/lock.api.ts +0 -0
- /package/src/modules/{workflow → version-control}/state/ChangeRequestStaleBinder.tsx +0 -0
- /package/src/modules/{workflow → version-control}/state/EventBusFocusBinder.tsx +0 -0
- /package/src/modules/{workflow → version-control}/state/__tests__/EventBusProvider.storage.test.tsx +0 -0
- /package/src/modules/{workflow → version-control}/state/__tests__/EventBusProvider.watch.test.tsx +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bevel-software/platform-core-frontend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"description": "Open-source core UI of the Bevel platform (raw TS/TSX source): workspace explorer/viewer, branches & change requests, Library, secrets, tools, access control.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"tailwind-merge": "^3.5.0",
|
|
46
46
|
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz",
|
|
47
47
|
"yaml": "^2.9.0",
|
|
48
|
-
"@bevel-software/platform-shared": "0.
|
|
48
|
+
"@bevel-software/platform-shared": "0.37.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@modelcontextprotocol/client": "^2.3.1",
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
createContext,
|
|
3
2
|
useContext,
|
|
4
3
|
useEffect,
|
|
5
4
|
useMemo,
|
|
@@ -7,33 +6,30 @@ import {
|
|
|
7
6
|
Fragment,
|
|
8
7
|
type ReactNode,
|
|
9
8
|
} from 'react';
|
|
10
|
-
import { BrowserRouter, Navigate, Routes, Route, useLocation } from 'react-router-dom';
|
|
9
|
+
import { BrowserRouter, Navigate, Routes, Route, matchPath, useLocation } from 'react-router-dom';
|
|
11
10
|
import { AuthContext } from '../modules/auth/state/auth.context';
|
|
12
11
|
import { useAuthState } from '../modules/auth/hooks/useAuthState';
|
|
13
12
|
import { LoginScreen } from '../modules/auth/components/LoginScreen';
|
|
14
13
|
import { SetupGate } from '../modules/setup/components/SetupGate';
|
|
15
|
-
import { WorkspaceContext } from '../modules/workspace/state/workspace.context';
|
|
14
|
+
import { WorkspaceContext, useWorkspace } from '../modules/workspace/state/workspace.context';
|
|
16
15
|
import { useWorkspaceState } from '../modules/workspace/hooks/useWorkspaceState';
|
|
17
16
|
import { GitContext } from '../modules/git/state/git.context';
|
|
18
17
|
import { AutoUpdateContext } from '../modules/git/state/auto-update.context';
|
|
19
18
|
import { useGitState } from '../modules/git/hooks/useGitState';
|
|
20
19
|
import { useAutoPullUpdates } from '../modules/git/hooks/useAutoPullUpdates';
|
|
21
|
-
import { EventBusProvider } from '../modules/
|
|
22
|
-
import { EventBusFocusBinder } from '../modules/
|
|
23
|
-
import { ChangeRequestStaleBinder } from '../modules/
|
|
20
|
+
import { EventBusProvider } from '../modules/version-control';
|
|
21
|
+
import { EventBusFocusBinder } from '../modules/version-control/state/EventBusFocusBinder';
|
|
22
|
+
import { ChangeRequestStaleBinder } from '../modules/version-control/state/ChangeRequestStaleBinder';
|
|
24
23
|
import { Toolbar } from '../modules/toolbar/components/Toolbar';
|
|
25
24
|
import { DemoBanner } from '../modules/layout/components/DemoBanner';
|
|
26
25
|
import { ReadOnlyBanner } from '../modules/layout/components/ReadOnlyBanner';
|
|
27
|
-
import { FileExplorer } from '../modules/workspace/components/FileExplorer';
|
|
28
|
-
import { FileViewer } from '../modules/workspace/components/FileViewer';
|
|
29
26
|
import { OpenChangeRequestsProvider } from '../modules/workspace/state/open-change-requests';
|
|
30
|
-
import {
|
|
31
|
-
import { KB_ROUTE_PREFIX } from '../modules/workspace/routing/kb-routes';
|
|
27
|
+
import { KB_ROUTE_PREFIX, safeDecode } from '../modules/workspace/routing/kb-routes';
|
|
32
28
|
import { CONNECT_TOOLS_PATH } from '../modules/library';
|
|
33
|
-
import { AppLayout } from '../modules/layout/components/AppLayout';
|
|
34
29
|
import {
|
|
35
30
|
LayoutContext,
|
|
36
31
|
NO_PANES_LAYOUT,
|
|
32
|
+
PaneControllerContext,
|
|
37
33
|
type LayoutController,
|
|
38
34
|
} from '../modules/layout/state/layout.context';
|
|
39
35
|
import { MaintenanceOverlay } from '../modules/layout/components/MaintenanceOverlay';
|
|
@@ -51,10 +47,8 @@ import { AuditLogPage } from '../modules/audit/components/AuditLogPage';
|
|
|
51
47
|
import { ToolsExplorerPage } from '../modules/tools/ToolsExplorerPage';
|
|
52
48
|
import { LibraryRoutes } from '../modules/library/routes/LibraryRoutes';
|
|
53
49
|
import { RootLanding } from '../modules/onboarding/components/RootLanding';
|
|
54
|
-
import { ConnectAgentPill } from '../modules/onboarding/components/ConnectAgentPill';
|
|
55
50
|
import { GetStartedColumn } from '../modules/onboarding/components/GetStartedColumn';
|
|
56
51
|
import { InviteDialogProvider } from '../modules/onboarding/state/invite-dialog';
|
|
57
|
-
import { PullRequestsForMe } from '../modules/git/components/PullRequestsForMe';
|
|
58
52
|
import { OpenChangeRequestDialog } from '../modules/pr/components/OpenChangeRequestDialog';
|
|
59
53
|
import { ChangeRequestLink } from '../modules/change-requests/components/ChangeRequestLink';
|
|
60
54
|
import { useMediaQuery } from '../modules/layout/hooks/useMediaQuery';
|
|
@@ -62,6 +56,9 @@ import { NARROW_QUERY } from '../modules/layout/breakpoints';
|
|
|
62
56
|
import { setSidebarCollapsed } from '../modules/layout/state/sidebar';
|
|
63
57
|
import {
|
|
64
58
|
activeAppId,
|
|
59
|
+
appHostingPath,
|
|
60
|
+
rootClaims,
|
|
61
|
+
useRootClaims,
|
|
65
62
|
ActiveAppIdContext,
|
|
66
63
|
AppClaimContext,
|
|
67
64
|
AppRegistryContext,
|
|
@@ -74,9 +71,9 @@ import {
|
|
|
74
71
|
type BannerDef,
|
|
75
72
|
type CrCreationInput,
|
|
76
73
|
type CrCreationPort,
|
|
77
|
-
type PaneDef,
|
|
78
74
|
} from './registry';
|
|
79
75
|
import { withCoreModuleContributions } from './core-contributions';
|
|
76
|
+
import { KnowledgeSurface } from './KnowledgeSurface';
|
|
80
77
|
import { isLibraryLocation } from '../modules/library/routes/library-paths';
|
|
81
78
|
import { EmbedView } from '../modules/embed/components/EmbedView';
|
|
82
79
|
import { EmbedLinkPage } from '../modules/embed/components/EmbedLinkPage';
|
|
@@ -84,7 +81,7 @@ import { ConfirmProvider } from '../shared/components';
|
|
|
84
81
|
|
|
85
82
|
/**
|
|
86
83
|
* The registry-driven application shell for the core modules (workspace, git,
|
|
87
|
-
* pr, access, auth,
|
|
84
|
+
* pr, access, auth, version control/SSE, layout, secrets-vault, tools, toolbar,
|
|
88
85
|
* library, and the admin roles page). Everything else — chat, connectors,
|
|
89
86
|
* routines, watchlist, voice, embed, onboarding, admin LLM/feedback pages —
|
|
90
87
|
* is contributed through the {@link AppRegistry} passed in (see
|
|
@@ -188,19 +185,6 @@ const CORE_BANNERS: BannerDef[] = [
|
|
|
188
185
|
{ id: 'roles-corrupted', order: 30, node: <RolesCorruptedBanner /> },
|
|
189
186
|
];
|
|
190
187
|
|
|
191
|
-
// Core panes; merged (by `order`) with registry-contributed panes (the
|
|
192
|
-
// enterprise chat pane registers at order 30). Sizing mirrors the historical
|
|
193
|
-
// hard-coded three-pane layout exactly. These are the KNOWLEDGE app's panes —
|
|
194
|
-
// other apps render their own full surface (see CORE_APPS).
|
|
195
|
-
const CORE_PANES: PaneDef[] = [
|
|
196
|
-
// The file tree is the SIDEBAR, not a panel — the same frame, at the same
|
|
197
|
-
// width, that Skills & Tools puts its plugin list in. It left the resizable
|
|
198
|
-
// group when the two navs were unified; `SidebarFrame` owns its width and
|
|
199
|
-
// the shared store owns whether it is showing.
|
|
200
|
-
{ id: 'explorer', order: 10, node: <FileExplorer />, sidebar: true, collapsible: true },
|
|
201
|
-
{ id: 'viewer', order: 20, node: <ViewerRoutes />, minSize: '30%' },
|
|
202
|
-
];
|
|
203
|
-
|
|
204
188
|
/**
|
|
205
189
|
* The two pages that are not part of the app: the embed a chat host frames,
|
|
206
190
|
* and the account-link page it sends an unlinked viewer to. Routes rather
|
|
@@ -263,17 +247,36 @@ const CORE_APPS: AppDef[] = [
|
|
|
263
247
|
* While the library renders under a `/workspace` URL it CLAIMS the Skills &
|
|
264
248
|
* Tools app (see {@link AppClaimContext}), so the switcher and the toolbar's
|
|
265
249
|
* sidebar toggle follow the surface on screen, not the URL prefix.
|
|
250
|
+
*
|
|
251
|
+
* The third case is a root folder a registered app claims (`AppDef.roots`):
|
|
252
|
+
* a file URL under it renders THAT app's element, which mounts the narrowed
|
|
253
|
+
* `KnowledgeSurface`, and claims that app the same way. Same shape rule, read
|
|
254
|
+
* from the path's root and the registry; with no root claimed it never applies.
|
|
255
|
+
* It never meets the library: `Skills/` and `Plugins/` are core's own roots,
|
|
256
|
+
* which `rootClaims` refuses to hand to an app.
|
|
266
257
|
*/
|
|
267
258
|
function CoreSurfaces() {
|
|
268
259
|
const location = useLocation();
|
|
269
260
|
const claim = useContext(AppClaimContext);
|
|
261
|
+
const { apps } = useAppRegistry();
|
|
262
|
+
const claims = useRootClaims();
|
|
263
|
+
const { kbDirName } = useWorkspace();
|
|
270
264
|
const library = isLibraryLocation(location.pathname);
|
|
271
265
|
const claimsSkills = library && location.pathname.startsWith(KB_ROUTE_PREFIX);
|
|
266
|
+
const host = useMemo(() => {
|
|
267
|
+
const file = matchPath(`${KB_ROUTE_PREFIX}/:branch/*`, location.pathname);
|
|
268
|
+
const id = file ? appHostingPath(claims, safeDecode(file.params['*'] ?? ''), kbDirName) : undefined;
|
|
269
|
+
return id === undefined ? undefined : apps.find((app) => app.id === id);
|
|
270
|
+
}, [location.pathname, claims, kbDirName, apps]);
|
|
271
|
+
const claimedApp = host ? host.id : claimsSkills ? 'skills-tools' : null;
|
|
272
272
|
useEffect(() => {
|
|
273
|
-
if (!
|
|
274
|
-
claim(
|
|
273
|
+
if (!claimedApp) return;
|
|
274
|
+
claim(claimedApp);
|
|
275
275
|
return () => claim(null);
|
|
276
|
-
}, [
|
|
276
|
+
}, [claimedApp, claim]);
|
|
277
|
+
// The hosting app's frame is its own: the surface it mounts brings the
|
|
278
|
+
// change-request provider with it (see `KnowledgeSurface`).
|
|
279
|
+
if (host) return host.element;
|
|
277
280
|
// Mounted here, once, above BOTH surfaces: the Knowledge tree, the tab
|
|
278
281
|
// strip, the viewer's banner AND the Library's Skills tree all ask the same
|
|
279
282
|
// question, and a tree rendered outside the provider would read the empty
|
|
@@ -296,44 +299,6 @@ function CoreSurfaces() {
|
|
|
296
299
|
);
|
|
297
300
|
}
|
|
298
301
|
|
|
299
|
-
/**
|
|
300
|
-
* Setter through which the Knowledge surface's pane layout reports its
|
|
301
|
-
* controller to AppChrome (whose LayoutContext provider wraps the toolbar).
|
|
302
|
-
*/
|
|
303
|
-
const PaneControllerContext = createContext<(c: LayoutController | null) => void>(
|
|
304
|
-
() => {},
|
|
305
|
-
);
|
|
306
|
-
|
|
307
|
-
/** The Knowledge app: the historical pane workspace (explorer / viewer / panes). */
|
|
308
|
-
function KnowledgeSurface() {
|
|
309
|
-
const registry = useAppRegistry();
|
|
310
|
-
const setController = useContext(PaneControllerContext);
|
|
311
|
-
const panes = useMemo(
|
|
312
|
-
() =>
|
|
313
|
-
[...CORE_PANES, ...registry.panes].sort(
|
|
314
|
-
(a, b) => (a.order ?? 100) - (b.order ?? 100),
|
|
315
|
-
),
|
|
316
|
-
[registry],
|
|
317
|
-
);
|
|
318
|
-
return (
|
|
319
|
-
/* The connect-your-agent reminder rides Knowledge's sidebar too, and
|
|
320
|
-
the shell is where that is decided: `layout` is the app's generic
|
|
321
|
-
consistency layer and must not name a domain component, so the pill
|
|
322
|
-
is passed IN from the composition root. The Library passes the same
|
|
323
|
-
one from `LibraryLayout` — one pill, both surfaces, so a person who
|
|
324
|
-
skipped the welcome page and stayed in Knowledge still sees it. */
|
|
325
|
-
<AppLayout
|
|
326
|
-
panes={panes}
|
|
327
|
-
onController={setController}
|
|
328
|
-
sidebarHeader={<ConnectAgentPill />}
|
|
329
|
-
// The change-request dock, pinned under the tree — and under the
|
|
330
|
-
// Library's nav, which passes the same one: the requests waiting on
|
|
331
|
-
// you are the same whichever app you are in.
|
|
332
|
-
sidebarFooter={<PullRequestsForMe />}
|
|
333
|
-
/>
|
|
334
|
-
);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
302
|
/**
|
|
338
303
|
* Everything that frames the active app: the banner strip, the toolbar, and
|
|
339
304
|
* the surface the registry routes into.
|
|
@@ -520,27 +485,6 @@ export function ShellRoutes({ apps }: { apps: AppDef[] }) {
|
|
|
520
485
|
);
|
|
521
486
|
}
|
|
522
487
|
|
|
523
|
-
/**
|
|
524
|
-
* The viewer pane: registry routes first, then the core routes. This
|
|
525
|
-
* `<Routes>` block is nested inside the Knowledge surface's
|
|
526
|
-
* `${KB_ROUTE_PREFIX}/*` route, so every path here matches the REMAINDER
|
|
527
|
-
* after `/workspace` — `:branch/*` is `/workspace/<branch>/<path>` (the
|
|
528
|
-
* absolute URLs `kbFileUrl()` builds), and the default `*` is the
|
|
529
|
-
* knowledge-home fallback for `/workspace` itself.
|
|
530
|
-
*/
|
|
531
|
-
function ViewerRoutes() {
|
|
532
|
-
const registry = useAppRegistry();
|
|
533
|
-
return (
|
|
534
|
-
<Routes>
|
|
535
|
-
{registry.viewerRoutes.map((r) => (
|
|
536
|
-
<Route key={r.path} path={r.path} element={r.element} />
|
|
537
|
-
))}
|
|
538
|
-
<Route path=":branch/*" element={<FileRoute />} />
|
|
539
|
-
<Route path="*" element={<FileViewer />} />
|
|
540
|
-
</Routes>
|
|
541
|
-
);
|
|
542
|
-
}
|
|
543
|
-
|
|
544
488
|
/**
|
|
545
489
|
* Provides the change-request creation port. A registry-supplied override
|
|
546
490
|
* (`registry.crCreation`) wins; otherwise the core default opens the direct
|
|
@@ -635,13 +579,12 @@ export function CoreAppShell({ registry }: { registry: AppRegistry }) {
|
|
|
635
579
|
// and core modules' own rows (see `withCoreModuleContributions`). The
|
|
636
580
|
// review file-viewer panel is no longer registered here — see the note on
|
|
637
581
|
// `chrome` above.
|
|
638
|
-
const mergedRegistry = useMemo<AppRegistry>(
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
);
|
|
582
|
+
const mergedRegistry = useMemo<AppRegistry>(() => {
|
|
583
|
+
const apps = [...CORE_APPS, ...registry.apps];
|
|
584
|
+
// A root claimed twice fails here, when the shell mounts.
|
|
585
|
+
rootClaims(apps);
|
|
586
|
+
return { ...withCoreModuleContributions(registry), apps };
|
|
587
|
+
}, [registry]);
|
|
645
588
|
// BrowserRouter wraps both auth and authenticated views so the address bar URL
|
|
646
589
|
// (e.g. a pasted /workspace/<branch>/<path> link) survives login —
|
|
647
590
|
// FileRoute picks it up automatically once auth resolves.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { useContext, useMemo } from 'react';
|
|
2
|
+
import { Routes, Route } from 'react-router-dom';
|
|
3
|
+
import { FileExplorer } from '../modules/workspace/components/FileExplorer';
|
|
4
|
+
import { FileViewer } from '../modules/workspace/components/FileViewer';
|
|
5
|
+
import { FileRoute } from '../modules/workspace/components/FileRoute';
|
|
6
|
+
import { OpenChangeRequestsProvider } from '../modules/workspace/state/open-change-requests';
|
|
7
|
+
import { AppLayout } from '../modules/layout/components/AppLayout';
|
|
8
|
+
import { PaneControllerContext } from '../modules/layout/state/layout.context';
|
|
9
|
+
import { ConnectAgentPill } from '../modules/onboarding/components/ConnectAgentPill';
|
|
10
|
+
import { PullRequestsForMe } from '../modules/git/components/PullRequestsForMe';
|
|
11
|
+
import { useAppRegistry, type PaneDef } from './registry';
|
|
12
|
+
|
|
13
|
+
// Core panes; merged (by `order`) with registry-contributed panes (the
|
|
14
|
+
// enterprise chat pane registers at order 30). Sizing mirrors the historical
|
|
15
|
+
// hard-coded three-pane layout exactly. These are the KNOWLEDGE app's panes —
|
|
16
|
+
// other apps render their own full surface (see CORE_APPS).
|
|
17
|
+
const CORE_PANES: PaneDef[] = [
|
|
18
|
+
// The file tree is the SIDEBAR, not a panel — the same frame, at the same
|
|
19
|
+
// width, that Skills & Tools puts its plugin list in. It left the resizable
|
|
20
|
+
// group when the two navs were unified; `SidebarFrame` owns its width and
|
|
21
|
+
// the shared store owns whether it is showing.
|
|
22
|
+
{ id: 'explorer', order: 10, node: <FileExplorer />, sidebar: true, collapsible: true },
|
|
23
|
+
{ id: 'viewer', order: 20, node: <ViewerRoutes />, minSize: '30%' },
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The Knowledge app: the pane workspace (explorer / viewer / panes).
|
|
28
|
+
*
|
|
29
|
+
* With `roots`, the same surface narrowed to those top-level folders: the
|
|
30
|
+
* folder surface an app mounts to show the roots it claims (see
|
|
31
|
+
* `AppDef.roots`). Only the explorer changes, to those roots alone; the
|
|
32
|
+
* viewer, the tab strip, the file operations, the renderers and the
|
|
33
|
+
* proposed-file state are the Knowledge app's own. The Knowledge app is
|
|
34
|
+
* mounted under the shell's change-request provider, which it shares with
|
|
35
|
+
* the library; a narrowed surface is mounted by its app, outside it, so it
|
|
36
|
+
* brings its own.
|
|
37
|
+
*/
|
|
38
|
+
export function KnowledgeSurface({ roots }: { roots?: readonly string[] } = {}) {
|
|
39
|
+
const registry = useAppRegistry();
|
|
40
|
+
const setController = useContext(PaneControllerContext);
|
|
41
|
+
const panes = useMemo(
|
|
42
|
+
() =>
|
|
43
|
+
[
|
|
44
|
+
...(roots
|
|
45
|
+
? CORE_PANES.map((pane) =>
|
|
46
|
+
pane.id === 'explorer' ? { ...pane, node: <FileExplorer roots={roots} /> } : pane,
|
|
47
|
+
)
|
|
48
|
+
: CORE_PANES),
|
|
49
|
+
...registry.panes,
|
|
50
|
+
].sort((a, b) => (a.order ?? 100) - (b.order ?? 100)),
|
|
51
|
+
[registry, roots],
|
|
52
|
+
);
|
|
53
|
+
const layout = (
|
|
54
|
+
/* The connect-your-agent reminder rides Knowledge's sidebar too, and
|
|
55
|
+
the shell is where that is decided: `layout` is the app's generic
|
|
56
|
+
consistency layer and must not name a domain component, so the pill
|
|
57
|
+
is passed IN from the composition root. The Library passes the same
|
|
58
|
+
one from `LibraryLayout` — one pill, both surfaces, so a person who
|
|
59
|
+
skipped the welcome page and stayed in Knowledge still sees it. */
|
|
60
|
+
<AppLayout
|
|
61
|
+
panes={panes}
|
|
62
|
+
onController={setController}
|
|
63
|
+
sidebarHeader={<ConnectAgentPill />}
|
|
64
|
+
// The change-request dock, pinned under the tree — and under the
|
|
65
|
+
// Library's nav, which passes the same one: the requests waiting on
|
|
66
|
+
// you are the same whichever app you are in.
|
|
67
|
+
sidebarFooter={<PullRequestsForMe />}
|
|
68
|
+
/>
|
|
69
|
+
);
|
|
70
|
+
return roots ? <OpenChangeRequestsProvider>{layout}</OpenChangeRequestsProvider> : layout;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The viewer pane: registry routes first, then the core routes. This
|
|
75
|
+
* `<Routes>` block is nested inside the Knowledge surface's
|
|
76
|
+
* `${KB_ROUTE_PREFIX}/*` route, so every path here matches the REMAINDER
|
|
77
|
+
* after `/workspace` — `:branch/*` is `/workspace/<branch>/<path>` (the
|
|
78
|
+
* absolute URLs `kbFileUrl()` builds), and the default `*` is the
|
|
79
|
+
* knowledge-home fallback for `/workspace` itself.
|
|
80
|
+
*/
|
|
81
|
+
function ViewerRoutes() {
|
|
82
|
+
const registry = useAppRegistry();
|
|
83
|
+
return (
|
|
84
|
+
<Routes>
|
|
85
|
+
{registry.viewerRoutes.map((r) => (
|
|
86
|
+
<Route key={r.path} path={r.path} element={r.element} />
|
|
87
|
+
))}
|
|
88
|
+
<Route path=":branch/*" element={<FileRoute />} />
|
|
89
|
+
<Route path="*" element={<FileViewer />} />
|
|
90
|
+
</Routes>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
|
|
3
|
+
import type { ReactNode } from 'react';
|
|
4
|
+
import type { FileTreeEntry } from '@bevel-software/platform-shared';
|
|
5
|
+
import type { WorkspaceContextValue } from '../../modules/workspace';
|
|
6
|
+
import type { GitContextValue } from '../../modules/git';
|
|
7
|
+
import { makeWorkspaceFixture } from '../../modules/workspace/__tests__/testFixtures';
|
|
8
|
+
import { CoreAppShell } from '../CoreAppShell';
|
|
9
|
+
import { KnowledgeSurface } from '../KnowledgeSurface';
|
|
10
|
+
import { makeRegistry, useActiveAppId, type AppDef, type FileRendererDef } from '../registry';
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* The whole shell, mounted at a URL, with the session and the server stubbed:
|
|
14
|
+
* which app a `/workspace` URL opens in is decided by the shell's own route
|
|
15
|
+
* element, so it is asserted through the shell.
|
|
16
|
+
*/
|
|
17
|
+
const session = vi.hoisted(() => ({ workspace: null as WorkspaceContextValue | null }));
|
|
18
|
+
|
|
19
|
+
vi.mock('../../modules/auth/hooks/useAuthState', () => ({
|
|
20
|
+
useAuthState: () => ({
|
|
21
|
+
user: { email: 'ada@example.com', name: 'Ada', role: 'Admin' },
|
|
22
|
+
token: 't',
|
|
23
|
+
isLoading: false,
|
|
24
|
+
login: async () => {},
|
|
25
|
+
logout: () => {},
|
|
26
|
+
}),
|
|
27
|
+
}));
|
|
28
|
+
vi.mock('../../modules/setup/components/SetupGate', () => ({
|
|
29
|
+
SetupGate: ({ children }: { children: ReactNode }) => <>{children}</>,
|
|
30
|
+
}));
|
|
31
|
+
vi.mock('../../modules/workspace/hooks/useWorkspaceState', () => ({
|
|
32
|
+
useWorkspaceState: () => session.workspace,
|
|
33
|
+
}));
|
|
34
|
+
vi.mock('../../modules/git/hooks/useGitState', () => ({
|
|
35
|
+
useGitState: (): GitContextValue => ({
|
|
36
|
+
status: { branch: 'main', hasUpstream: true, unmergedFromUpstream: false },
|
|
37
|
+
branches: [],
|
|
38
|
+
availability: 'ready',
|
|
39
|
+
lastError: null,
|
|
40
|
+
refreshStatus: async () => null,
|
|
41
|
+
refreshBranches: async () => {},
|
|
42
|
+
createBranch: async () => {},
|
|
43
|
+
deleteBranch: async () => {},
|
|
44
|
+
pull: async () => {},
|
|
45
|
+
fetchForkBase: async () => null,
|
|
46
|
+
fetchFileHistory: async () => [],
|
|
47
|
+
fetchFileDiff: async () => '',
|
|
48
|
+
fetchFileAtChange: async () => ({ baseline: null, current: null }),
|
|
49
|
+
fetchFileComparison: async () => '',
|
|
50
|
+
}),
|
|
51
|
+
}));
|
|
52
|
+
vi.mock('../../modules/git/hooks/useAutoPullUpdates', () => ({ useAutoPullUpdates: () => null }));
|
|
53
|
+
vi.mock('../../modules/workspace/routing/kb-routes', async (importOriginal) => ({
|
|
54
|
+
...(await importOriginal<typeof import('../../modules/workspace/routing/kb-routes')>()),
|
|
55
|
+
fetchNodeId: async () => null,
|
|
56
|
+
fetchNodeWorkspacePath: async () => null,
|
|
57
|
+
}));
|
|
58
|
+
// The chrome around the surfaces: the toolbar says which app is active, and
|
|
59
|
+
// the rest is out of the way.
|
|
60
|
+
vi.mock('../../modules/toolbar/components/Toolbar', () => ({
|
|
61
|
+
Toolbar: () => <output aria-label="active app">{useActiveAppId()}</output>,
|
|
62
|
+
}));
|
|
63
|
+
vi.mock('../../modules/layout/components/MaintenanceOverlay', () => ({ MaintenanceOverlay: () => null }));
|
|
64
|
+
vi.mock('../../modules/layout/components/DemoBanner', () => ({ DemoBanner: () => null }));
|
|
65
|
+
vi.mock('../../modules/layout/components/ReadOnlyBanner', () => ({ ReadOnlyBanner: () => null }));
|
|
66
|
+
vi.mock('../../modules/admin/components/RolesCorruptedBanner', () => ({ RolesCorruptedBanner: () => null }));
|
|
67
|
+
vi.mock('../../modules/onboarding/components/GetStartedColumn', () => ({ GetStartedColumn: () => null }));
|
|
68
|
+
vi.mock('../../modules/onboarding/components/ConnectAgentPill', () => ({ ConnectAgentPill: () => null }));
|
|
69
|
+
vi.mock('../../modules/git/components/PullRequestsForMe', () => ({ PullRequestsForMe: () => null }));
|
|
70
|
+
|
|
71
|
+
const KB = 'knowledge-base';
|
|
72
|
+
const AGENT = `${KB}/Agents/coder.agent`;
|
|
73
|
+
const PAGE = `${KB}/KnowledgeBase/Home.md`;
|
|
74
|
+
|
|
75
|
+
const file = (relativePath: string): FileTreeEntry => ({
|
|
76
|
+
name: relativePath.split('/').pop()!,
|
|
77
|
+
relativePath,
|
|
78
|
+
type: 'file',
|
|
79
|
+
});
|
|
80
|
+
const folder = (relativePath: string, children: FileTreeEntry[] = []): FileTreeEntry => ({
|
|
81
|
+
name: relativePath.split('/').pop()!,
|
|
82
|
+
relativePath,
|
|
83
|
+
type: 'directory',
|
|
84
|
+
children,
|
|
85
|
+
});
|
|
86
|
+
const TREE = folder('', [
|
|
87
|
+
folder(KB, [
|
|
88
|
+
folder(`${KB}/KnowledgeBase`, [file(PAGE)]),
|
|
89
|
+
folder(`${KB}/Agents`, [file(AGENT)]),
|
|
90
|
+
folder(`${KB}/Workflows`),
|
|
91
|
+
]),
|
|
92
|
+
]);
|
|
93
|
+
|
|
94
|
+
/** The workspace with one file open, as the tab system would hold it. */
|
|
95
|
+
function workspaceOn(path: string, content: string): WorkspaceContextValue {
|
|
96
|
+
const tab = { path, content, savedContent: content, isDirty: false, pendingFileContent: null };
|
|
97
|
+
return makeWorkspaceFixture({
|
|
98
|
+
fileTree: TREE,
|
|
99
|
+
openTabs: [tab],
|
|
100
|
+
activeTab: tab,
|
|
101
|
+
openFilePath: path,
|
|
102
|
+
openFileContent: content,
|
|
103
|
+
openFileSavedContent: content,
|
|
104
|
+
hydrateTabs: async () => ({ surviving: [path], dropped: [], denied: [], superseded: false }),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** The `.agent` renderer a distribution registers by extension. */
|
|
109
|
+
const agentRenderer: FileRendererDef = {
|
|
110
|
+
extensions: ['.agent'],
|
|
111
|
+
Component: ({ content }) => <div data-testid="agent-renderer">{content}</div>,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/** A distribution's app hosting `Agents/` and `Workflows/` in a frame of its own. */
|
|
115
|
+
const agentsApp: AppDef = {
|
|
116
|
+
id: 'agents',
|
|
117
|
+
label: 'Agents',
|
|
118
|
+
path: '/agents',
|
|
119
|
+
roots: ['Agents', 'Workflows'],
|
|
120
|
+
element: (
|
|
121
|
+
<div data-testid="agents-frame">
|
|
122
|
+
<KnowledgeSurface roots={['Agents', 'Workflows']} />
|
|
123
|
+
</div>
|
|
124
|
+
),
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
function renderShellAt(url: string, apps: AppDef[]) {
|
|
128
|
+
window.history.replaceState(null, '', url);
|
|
129
|
+
return render(<CoreAppShell registry={makeRegistry({ apps, renderers: [agentRenderer] })} />);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const explorer = () => within(screen.getByTestId('file-explorer-root'));
|
|
133
|
+
|
|
134
|
+
beforeEach(() => {
|
|
135
|
+
vi.stubGlobal(
|
|
136
|
+
'fetch',
|
|
137
|
+
vi.fn(async () => new Response('{}', { status: 404, headers: { 'content-type': 'application/json' } })),
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
afterEach(() => {
|
|
141
|
+
cleanup();
|
|
142
|
+
vi.unstubAllGlobals();
|
|
143
|
+
window.history.replaceState(null, '', '/');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe('CoreAppShell: a root folder an app claims', () => {
|
|
147
|
+
it('opens a file under the claimed root in the claiming app, with its renderer', async () => {
|
|
148
|
+
session.workspace = workspaceOn(AGENT, 'role: coder');
|
|
149
|
+
renderShellAt(`/workspace/main/${AGENT}`, [agentsApp]);
|
|
150
|
+
|
|
151
|
+
expect(await screen.findByTestId('agents-frame')).toBeInTheDocument();
|
|
152
|
+
expect(screen.getByLabelText('active app')).toHaveTextContent('agents');
|
|
153
|
+
expect(within(screen.getByTestId('agents-frame')).getByTestId('agent-renderer')).toHaveTextContent('role: coder');
|
|
154
|
+
// The frame's tree is the narrowed one: its roots, and not Knowledge.
|
|
155
|
+
expect(explorer().getByText('Agents')).toBeInTheDocument();
|
|
156
|
+
expect(explorer().getByText('Workflows')).toBeInTheDocument();
|
|
157
|
+
expect(explorer().queryByText('Knowledge')).not.toBeInTheDocument();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('leaves the claimed roots out of the Knowledge app', async () => {
|
|
161
|
+
session.workspace = workspaceOn(PAGE, '# Home');
|
|
162
|
+
renderShellAt(`/workspace/main/${PAGE}`, [agentsApp]);
|
|
163
|
+
|
|
164
|
+
await waitFor(() => expect(screen.getByLabelText('active app')).toHaveTextContent('knowledge'));
|
|
165
|
+
expect(screen.queryByTestId('agents-frame')).not.toBeInTheDocument();
|
|
166
|
+
expect(explorer().getByText('Knowledge')).toBeInTheDocument();
|
|
167
|
+
expect(explorer().queryByText('Agents')).not.toBeInTheDocument();
|
|
168
|
+
expect(explorer().queryByText('Workflows')).not.toBeInTheDocument();
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
/*
|
|
172
|
+
* A link inside a page opens its destination in a new browser tab at the
|
|
173
|
+
* destination's plain URL (see `useFileNav`'s `linkTarget`); that URL is
|
|
174
|
+
* what lands in the claiming app.
|
|
175
|
+
*/
|
|
176
|
+
it('lands a link from a Knowledge page to a hosted file in the claiming app', async () => {
|
|
177
|
+
session.workspace = workspaceOn(PAGE, '[The coder](../Agents/coder.agent)');
|
|
178
|
+
const opened: string[] = [];
|
|
179
|
+
const open = vi.spyOn(window, 'open').mockImplementation((url) => {
|
|
180
|
+
opened.push(String(url));
|
|
181
|
+
return {} as Window;
|
|
182
|
+
});
|
|
183
|
+
try {
|
|
184
|
+
renderShellAt(`/workspace/main/${PAGE}`, [agentsApp]);
|
|
185
|
+
fireEvent.click(await screen.findByRole('link', { name: 'The coder' }));
|
|
186
|
+
} finally {
|
|
187
|
+
open.mockRestore();
|
|
188
|
+
}
|
|
189
|
+
expect(opened).toEqual([`/workspace/main/${AGENT}`]);
|
|
190
|
+
|
|
191
|
+
cleanup();
|
|
192
|
+
session.workspace = workspaceOn(AGENT, 'role: coder');
|
|
193
|
+
renderShellAt(opened[0]!, [agentsApp]);
|
|
194
|
+
expect(await screen.findByTestId('agents-frame')).toBeInTheDocument();
|
|
195
|
+
expect(screen.getByLabelText('active app')).toHaveTextContent('agents');
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('opens the same URL in Knowledge, with every root a section, when no app claims it', async () => {
|
|
199
|
+
session.workspace = workspaceOn(AGENT, 'role: coder');
|
|
200
|
+
renderShellAt(`/workspace/main/${AGENT}`, []);
|
|
201
|
+
|
|
202
|
+
await waitFor(() => expect(screen.getByLabelText('active app')).toHaveTextContent('knowledge'));
|
|
203
|
+
expect(screen.getByTestId('agent-renderer')).toHaveTextContent('role: coder');
|
|
204
|
+
for (const name of ['Knowledge', 'Agents', 'Workflows']) {
|
|
205
|
+
expect(explorer().getByText(name), name).toBeInTheDocument();
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('refuses two apps claiming one root, naming the root and both apps', () => {
|
|
210
|
+
const rival: AppDef = { id: 'runs', label: 'Runs', path: '/runs', roots: ['Workflows'], element: <div /> };
|
|
211
|
+
const error = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
212
|
+
try {
|
|
213
|
+
expect(() => renderShellAt('/workspace', [agentsApp, rival])).toThrow(
|
|
214
|
+
'The root folder "Workflows" is claimed by two apps: "agents" and "runs".',
|
|
215
|
+
);
|
|
216
|
+
} finally {
|
|
217
|
+
error.mockRestore();
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
/*
|
|
222
|
+
* Knowledge and Skills & Tools are built on these: the library's URLs open
|
|
223
|
+
* on the library whatever the registry says, so a claim on one could never
|
|
224
|
+
* be honoured.
|
|
225
|
+
*/
|
|
226
|
+
it.each(['KnowledgeBase', 'Skills', 'Plugins', 'skills'])('refuses an app claiming core’s own root %s', (root) => {
|
|
227
|
+
const greedy: AppDef = { id: 'greedy', label: 'Greedy', path: '/greedy', roots: [root], element: <div /> };
|
|
228
|
+
const error = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
229
|
+
try {
|
|
230
|
+
expect(() => renderShellAt('/workspace', [greedy])).toThrow(
|
|
231
|
+
`The root folder "${root}" is core's own; the app "greedy" cannot claim it.`,
|
|
232
|
+
);
|
|
233
|
+
} finally {
|
|
234
|
+
error.mockRestore();
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
/* Root names compare case-insensitively, as the layout's do. */
|
|
239
|
+
it('refuses two apps claiming one root in different cases', () => {
|
|
240
|
+
const rival: AppDef = { id: 'runs', label: 'Runs', path: '/runs', roots: ['workflows'], element: <div /> };
|
|
241
|
+
const error = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
242
|
+
try {
|
|
243
|
+
expect(() => renderShellAt('/workspace', [agentsApp, rival])).toThrow(
|
|
244
|
+
'The root folder "workflows" is claimed by two apps: "agents" and "runs".',
|
|
245
|
+
);
|
|
246
|
+
} finally {
|
|
247
|
+
error.mockRestore();
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
/* A claim is one top-level folder NAME: a path would never match a file's root segment, so the app would host nothing and nobody would be told. */
|
|
252
|
+
it.each(['Agents/foo', 'Agents\\foo', '', ' Agents', '..'])('refuses a claim that is not one folder name: %j', (root) => {
|
|
253
|
+
const bad: AppDef = { id: 'runs', label: 'Runs', path: '/runs', roots: [root], element: <div /> };
|
|
254
|
+
const error = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
255
|
+
try {
|
|
256
|
+
expect(() => renderShellAt('/workspace', [bad])).toThrow(
|
|
257
|
+
`The root folder "${root}" claimed by the app "runs" must be a single top-level folder name.`,
|
|
258
|
+
);
|
|
259
|
+
} finally {
|
|
260
|
+
error.mockRestore();
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('opens a file in the claiming app when the claim names its root in another case', async () => {
|
|
265
|
+
session.workspace = workspaceOn(AGENT, 'role: coder');
|
|
266
|
+
renderShellAt(`/workspace/main/${AGENT}`, [{ ...agentsApp, roots: ['agents', 'workflows'] }]);
|
|
267
|
+
|
|
268
|
+
expect(await screen.findByTestId('agents-frame')).toBeInTheDocument();
|
|
269
|
+
expect(screen.getByLabelText('active app')).toHaveTextContent('agents');
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it('opens a path outside the knowledge base in Knowledge, even under a claimed name', async () => {
|
|
273
|
+
const outside = 'other-repo/Agents/coder.agent';
|
|
274
|
+
session.workspace = workspaceOn(outside, 'role: coder');
|
|
275
|
+
renderShellAt(`/workspace/main/${outside}`, [agentsApp]);
|
|
276
|
+
|
|
277
|
+
await waitFor(() => expect(screen.getByLabelText('active app')).toHaveTextContent('knowledge'));
|
|
278
|
+
expect(screen.queryByTestId('agents-frame')).not.toBeInTheDocument();
|
|
279
|
+
});
|
|
280
|
+
});
|