@bevel-software/platform-core-frontend 0.13.6 → 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.
- package/package.json +2 -2
- package/src/core/CoreAppShell.tsx +18 -17
- package/src/core/__tests__/bootstrap.test.ts +33 -1
- package/src/core/bootstrap.ts +30 -1
- package/src/lib/__tests__/api.test.ts +38 -0
- package/src/lib/__tests__/utils.test.ts +43 -0
- package/src/lib/api.ts +19 -2
- package/src/lib/utils.ts +17 -7
- package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +111 -1
- package/src/modules/access/__tests__/plugin-token.test.ts +21 -0
- package/src/modules/access/api.ts +52 -4
- package/src/modules/access/components/ManageAccessDialog.tsx +112 -83
- package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +65 -1
- package/src/modules/git/components/GitSyncFailedBanner.tsx +68 -5
- package/src/modules/layout/components/SidebarFrame.tsx +1 -1
- package/src/modules/library/__tests__/LibraryRoutes.test.tsx +2 -1
- package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +1 -1
- package/src/modules/library/__tests__/LinkSkillPanel.test.tsx +121 -0
- package/src/modules/library/__tests__/LockedPluginView.test.tsx +6 -0
- package/src/modules/library/__tests__/McpServerSection.test.tsx +7 -1
- package/src/modules/library/__tests__/NewPluginDialog.test.tsx +5 -4
- package/src/modules/library/__tests__/PluginExtras.test.tsx +15 -0
- package/src/modules/library/__tests__/PluginPage.test.tsx +195 -1
- package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +1 -1
- package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +1 -1
- package/src/modules/library/__tests__/PluginsSidebar.test.tsx +64 -3
- package/src/modules/library/__tests__/SkillPage.test.tsx +9 -2
- package/src/modules/library/__tests__/SkillsTree.test.tsx +172 -0
- package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +216 -8
- package/src/modules/library/__tests__/ToolPage.test.tsx +23 -3
- package/src/modules/library/__tests__/ToolVarRow.test.tsx +7 -7
- package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +115 -4
- package/src/modules/library/__tests__/library-data.stale.test.tsx +90 -0
- package/src/modules/library/__tests__/library-paths.test.ts +32 -0
- package/src/modules/library/__tests__/link-membership.test.ts +120 -0
- package/src/modules/library/__tests__/plugin-summary.test.ts +32 -0
- package/src/modules/library/__tests__/status.test.ts +84 -0
- package/src/modules/library/__tests__/useJoinRequests.test.tsx +46 -0
- package/src/modules/library/components/AddToPluginDialog.tsx +33 -0
- package/src/modules/library/components/LibraryCard.tsx +21 -1
- package/src/modules/library/components/LibraryLayout.tsx +24 -14
- package/src/modules/library/components/LinkSkillPanel.tsx +171 -0
- package/src/modules/library/components/LockedPluginView.tsx +2 -2
- package/src/modules/library/components/NewPluginDialog.tsx +4 -4
- package/src/modules/library/components/PageActions.tsx +21 -1
- package/src/modules/library/components/PersonalPluginPage.tsx +2 -1
- package/src/modules/library/components/PluginExtras.tsx +3 -1
- package/src/modules/library/components/PluginPage.tsx +92 -12
- package/src/modules/library/components/PluginsIndexPage.tsx +11 -6
- package/src/modules/library/components/PluginsSidebar.tsx +110 -53
- package/src/modules/library/components/RenamePluginDialog.tsx +136 -0
- package/src/modules/library/components/SkillsTree.tsx +91 -0
- package/src/modules/library/components/StatusDot.tsx +1 -0
- package/src/modules/library/components/plugin-page-parts.tsx +32 -9
- package/src/modules/library/components/skill-page/SharedViaPlugins.tsx +218 -0
- package/src/modules/library/components/skill-page/SkillPage.tsx +75 -7
- package/src/modules/library/components/tool-page/McpServerSection.tsx +9 -1
- package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +223 -8
- package/src/modules/library/components/tool-page/ToolPage.tsx +30 -2
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +30 -8
- package/src/modules/library/hooks/useJoinRequests.ts +48 -18
- package/src/modules/library/hooks/useToolPage.ts +28 -11
- package/src/modules/library/routes/WorkspaceItemRoute.tsx +180 -83
- package/src/modules/library/routes/library-paths.ts +21 -8
- package/src/modules/library/services/library.api.ts +55 -1
- package/src/modules/library/services/plugins.api.ts +94 -3
- package/src/modules/library/state/library-data.tsx +115 -22
- package/src/modules/library/utils/plugin-summary.ts +36 -0
- package/src/modules/library/utils/status.ts +173 -17
- package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +3 -2
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +29 -14
- package/src/modules/secrets-vault/components/SecretsPage.tsx +4 -1
- package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +4 -1
- package/src/modules/secrets-vault/services/tool-secrets.api.ts +36 -0
- package/src/modules/settings/components/ClaudeConnectionCard.tsx +169 -0
- package/src/modules/settings/components/DeploymentPage.tsx +15 -1
- package/src/modules/settings/components/__tests__/ClaudeConnectionCard.test.tsx +63 -0
- package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +10 -0
- package/src/modules/settings/services/github-facade.api.ts +43 -0
- package/src/modules/setup/__tests__/setup.test.tsx +118 -0
- package/src/modules/setup/components/SetupGate.tsx +1 -1
- package/src/modules/setup/components/SetupScreen.tsx +195 -2
- package/src/modules/setup/services/setup.api.ts +78 -0
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +301 -93
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +129 -6
- package/src/modules/toolbar/services/external-api-keys.api.ts +2 -0
- package/src/modules/workspace/__tests__/testFixtures.ts +1 -0
- package/src/modules/workspace/components/FileExplorer.tsx +292 -236
- package/src/modules/workspace/components/FileRoute.tsx +37 -0
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +39 -0
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +1 -0
- package/src/modules/workspace/hooks/useMergedWorkspaceTree.ts +70 -0
- package/src/modules/workspace/hooks/useWorkspaceState.ts +17 -3
- package/src/modules/workspace/routing/kb-routes.ts +1 -1
- package/src/modules/workspace/state/workspace.context.ts +8 -0
- package/src/modules/workspace/utils/__tests__/fileTree.test.ts +15 -0
- package/src/modules/workspace/utils/fileTree.ts +14 -16
- package/src/shared/__tests__/marketplace-url.test.ts +54 -0
- package/src/shared/components/Badge.tsx +3 -1
- package/src/shared/components/Banner.tsx +5 -1
- package/src/shared/marketplace-url.ts +90 -0
- package/src/shared/theme/tokens.css +9 -0
|
@@ -40,16 +40,41 @@ export interface JoinRequestsState {
|
|
|
40
40
|
reload(): void;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Where the requests come from. The default is a plugin's join requests; a
|
|
45
|
+
* skill page passes the skill's write-access endpoints instead — same
|
|
46
|
+
* proposals, same accept-by-grant, a different folder.
|
|
47
|
+
*/
|
|
48
|
+
export interface JoinRequestsApi {
|
|
49
|
+
list(name: string): Promise<JoinRequest[]>;
|
|
50
|
+
reconcile(name: string, number: number): Promise<boolean>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Lazy wrappers, not the functions themselves: the plugin API is resolved at
|
|
54
|
+
// call time, so a surface that never lists requests never needs those exports.
|
|
55
|
+
const PLUGIN_JOIN_API: JoinRequestsApi = {
|
|
56
|
+
list: (name) => listJoinRequests(name),
|
|
57
|
+
reconcile: (name, number) => reconcileJoinRequest(name, number),
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export function useJoinRequests(
|
|
61
|
+
plugin: string,
|
|
62
|
+
folder: string | null,
|
|
63
|
+
api: JoinRequestsApi = PLUGIN_JOIN_API,
|
|
64
|
+
): JoinRequestsState {
|
|
65
|
+
// Keyed by the plugin they came from: a page that moves from skill A to
|
|
66
|
+
// skill B without unmounting must not show A's requests until B's arrive —
|
|
67
|
+
// a banner that lets an editor grant A's proposal against B's folder.
|
|
68
|
+
const [loaded, setLoaded] = useState<{ plugin: string; rows: JoinRequest[] } | null>(null);
|
|
69
|
+
const requests = loaded?.plugin === plugin ? loaded.rows : [];
|
|
45
70
|
const [revision, setRevision] = useState(0);
|
|
46
71
|
const toast = useLibraryToast();
|
|
47
72
|
|
|
48
73
|
useEffect(() => {
|
|
49
74
|
let cancelled = false;
|
|
50
|
-
|
|
75
|
+
api.list(plugin)
|
|
51
76
|
.then((rows) => {
|
|
52
|
-
if (!cancelled)
|
|
77
|
+
if (!cancelled) setLoaded({ plugin, rows });
|
|
53
78
|
})
|
|
54
79
|
.catch(() => {
|
|
55
80
|
// Silent: a manager surface that fails must not put an error banner in
|
|
@@ -58,7 +83,7 @@ export function useJoinRequests(plugin: string, folder: string | null): JoinRequ
|
|
|
58
83
|
return () => {
|
|
59
84
|
cancelled = true;
|
|
60
85
|
};
|
|
61
|
-
}, [plugin, revision]);
|
|
86
|
+
}, [plugin, revision, api]);
|
|
62
87
|
|
|
63
88
|
const reload = useCallback(() => setRevision((r) => r + 1), []);
|
|
64
89
|
|
|
@@ -79,23 +104,28 @@ export function useJoinRequests(plugin: string, folder: string | null): JoinRequ
|
|
|
79
104
|
}
|
|
80
105
|
// Drop the accepted proposal locally so the row goes immediately; the
|
|
81
106
|
// refetch below is what makes it true.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
107
|
+
setLoaded((cur) =>
|
|
108
|
+
cur && cur.plugin === plugin
|
|
109
|
+
? {
|
|
110
|
+
...cur,
|
|
111
|
+
rows: cur.rows.map((r) =>
|
|
112
|
+
r.number === request.number
|
|
113
|
+
? {
|
|
114
|
+
...r,
|
|
115
|
+
proposals: r.proposals.filter(
|
|
116
|
+
(p) => !(p.id === proposal.id && p.verb === proposal.verb),
|
|
117
|
+
),
|
|
118
|
+
}
|
|
119
|
+
: r,
|
|
120
|
+
),
|
|
121
|
+
}
|
|
122
|
+
: cur,
|
|
93
123
|
);
|
|
94
124
|
toast(`${proposal.label} now has ${proposal.verb} access.`);
|
|
95
|
-
await
|
|
125
|
+
await api.reconcile(plugin, request.number).catch(() => false);
|
|
96
126
|
setRevision((r) => r + 1);
|
|
97
127
|
},
|
|
98
|
-
[folder, plugin, toast],
|
|
128
|
+
[folder, plugin, toast, api],
|
|
99
129
|
);
|
|
100
130
|
|
|
101
131
|
const decline = useCallback(
|
|
@@ -41,6 +41,12 @@ export interface ToolPageState {
|
|
|
41
41
|
skillsLoaded: boolean;
|
|
42
42
|
/** Skills whose `allowed-tools` reach this tool. */
|
|
43
43
|
poweredSkills: LibrarySkillSummary[];
|
|
44
|
+
/**
|
|
45
|
+
* Bumped by every `reload()`. A same-slug reload no longer remounts the page,
|
|
46
|
+
* so a child that fetches its own data on `[slug]` would never refetch —
|
|
47
|
+
* this is the signal it puts in its dependency list instead.
|
|
48
|
+
*/
|
|
49
|
+
revision: number;
|
|
44
50
|
reload(): void;
|
|
45
51
|
}
|
|
46
52
|
|
|
@@ -64,15 +70,23 @@ export function useToolPage(slug: string): ToolPageState {
|
|
|
64
70
|
const [revision, setRevision] = useState(0);
|
|
65
71
|
const requestRef = useRef(0);
|
|
66
72
|
|
|
67
|
-
// Switching tools
|
|
68
|
-
//
|
|
69
|
-
//
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
|
|
73
|
+
// Switching tools has to clear the PREVIOUS tool's spine and detail, or the
|
|
74
|
+
// page paints stale content under the new slug's heading. That reset is state
|
|
75
|
+
// derived from a changed input, so it happens during render against the
|
|
76
|
+
// previous key rather than in the effect body — an effect resets after paint,
|
|
77
|
+
// which is both a frame of the old tool showing through and the synchronous
|
|
78
|
+
// setState that `react-hooks/set-state-in-effect` flags. `useState(key)` seeds
|
|
79
|
+
// the key so a fresh mount, already holding LOADING, does not reset itself on
|
|
80
|
+
// the first render.
|
|
81
|
+
//
|
|
82
|
+
// Keyed on the SLUG ALONE, so a same-tool `reload()` refetches WITHOUT
|
|
83
|
+
// blanking the page. There is no stale-slug hazard when the slug hasn't
|
|
84
|
+
// changed, and blanking had a cost: it dropped the page to `loading`, which
|
|
85
|
+
// unmounts the whole tool page — taking with it the connection section's
|
|
86
|
+
// probe verdict, which is held in component state precisely because it is not
|
|
87
|
+
// stored anywhere. Saving a key and then being told nothing about whether it
|
|
88
|
+
// works is the outcome that made this worth fixing.
|
|
89
|
+
const key = slug;
|
|
76
90
|
const [seenKey, setSeenKey] = useState(key);
|
|
77
91
|
if (key !== seenKey) {
|
|
78
92
|
setSeenKey(key);
|
|
@@ -106,7 +120,10 @@ export function useToolPage(slug: string): ToolPageState {
|
|
|
106
120
|
if (current()) setDetail(d);
|
|
107
121
|
})
|
|
108
122
|
.catch(() => {
|
|
109
|
-
// Degraded, not broken: no lede and no capabilities section
|
|
123
|
+
// Degraded, not broken: no lede and no capabilities section — and on
|
|
124
|
+
// a same-slug reload, degraded NOW: the previous fetch's description
|
|
125
|
+
// must not stand in for one this fetch could not vouch for.
|
|
126
|
+
if (current()) setDetail(null);
|
|
110
127
|
});
|
|
111
128
|
|
|
112
129
|
listSkills()
|
|
@@ -141,5 +158,5 @@ export function useToolPage(slug: string): ToolPageState {
|
|
|
141
158
|
|
|
142
159
|
const reload = useCallback(() => setRevision((r) => r + 1), []);
|
|
143
160
|
|
|
144
|
-
return { ...spine, detail, skillsLoaded, poweredSkills, reload };
|
|
161
|
+
return { ...spine, detail, skillsLoaded, poweredSkills, revision, reload };
|
|
145
162
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Navigate, useParams, useSearchParams } from 'react-router-dom';
|
|
2
|
-
import { DEFAULT_BRANCH, PLUGINS_DIR } from '@bevel-software/platform-shared';
|
|
1
|
+
import { Navigate, useLocation, useParams, useSearchParams } from 'react-router-dom';
|
|
2
|
+
import { DEFAULT_BRANCH, PLUGINS_DIR, SKILLS_DIR, type FileTreeEntry } from '@bevel-software/platform-shared';
|
|
3
3
|
import { useWorkspace } from '../../workspace/state/workspace.context';
|
|
4
|
+
import { safeDecode } from '../../workspace/routing/kb-routes';
|
|
4
5
|
import { useLibrary } from '../state/library-data';
|
|
5
6
|
import { SkillPage } from '../components/skill-page/SkillPage';
|
|
6
7
|
import { ToolPage } from '../components/tool-page/ToolPage';
|
|
@@ -8,20 +9,25 @@ import { LIBRARY_ROOT, pathForPlugin } from './library-paths';
|
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* The library page behind a canonical workspace URL —
|
|
11
|
-
* `/workspace/<default>/<kbDir>/Plugins/<plugin>/<...>`
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* `/workspace/<default>/<kbDir>/Plugins/<plugin>/<...>` or
|
|
13
|
+
* `/workspace/<default>/<kbDir>/Skills/<...>` — rendered INSIDE the same
|
|
14
|
+
* `LibraryLayout` route tree as every other library page, so the sidebar is
|
|
15
|
+
* the one the reader already had and nothing remounts on the way in.
|
|
14
16
|
*
|
|
15
17
|
* Resolution is STRUCTURAL, not a catalog lookup: under `Plugins/<plugin>/`, a
|
|
16
18
|
* `*.tool` file is a tool page, the plugin's `mcp.json` is a tool page too
|
|
17
19
|
* (which of its servers is named by `?server=`, or by the catalog when the file
|
|
18
|
-
* declares only one),
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
20
|
+
* declares only one), and everything else — under either root — is a skill
|
|
21
|
+
* FOLDER whose name is the skill's id, resolved by {@link resolveSkillPath}.
|
|
22
|
+
* That is what makes a skill created a moment ago open instantly: its URL
|
|
23
|
+
* says everything the page needs, and `SkillPage` fetches the skill by name
|
|
24
|
+
* itself. Waiting on the catalog here raced every reload and lost (the
|
|
25
|
+
* just-created skill bounced to its plugin's page).
|
|
26
|
+
*
|
|
27
|
+
* The two roots differ only in where a path that is NO skill goes: a
|
|
28
|
+
* container folder or a loose file belongs to its plugin page under
|
|
29
|
+
* `Plugins/`; under `Skills/` a scope folder has no page (home) and a loose
|
|
30
|
+
* file opens as the plain file it is.
|
|
25
31
|
*
|
|
26
32
|
* The catalog is consulted only to REFINE a tool's slug (a `.tool` may
|
|
27
33
|
* declare an explicit id different from its filename); the filename is the
|
|
@@ -30,28 +36,25 @@ import { LIBRARY_ROOT, pathForPlugin } from './library-paths';
|
|
|
30
36
|
export function WorkspaceItemRoute() {
|
|
31
37
|
const params = useParams<{ branch: string; '*': string }>();
|
|
32
38
|
const [searchParams] = useSearchParams();
|
|
39
|
+
const location = useLocation();
|
|
33
40
|
const splat = params['*'] ?? '';
|
|
34
41
|
const branch = safeDecode(params.branch ?? '');
|
|
35
|
-
const { kbDirName } = useWorkspace();
|
|
42
|
+
const { kbDirName, fileTree } = useWorkspace();
|
|
36
43
|
const data = useLibrary();
|
|
44
|
+
// The workspace tree as a second witness — see `resolveSkillPath`.
|
|
45
|
+
const witness = (folderRel: string) => folderHasSkillMd(fileTree, kbDirName ? `${kbDirName}/${folderRel}` : null);
|
|
37
46
|
|
|
38
47
|
// Shape re-validation: the route pattern (`:branch/*`) is broader than the
|
|
39
48
|
// shape the shell dispatches here, and a stray URL must not read as a page.
|
|
40
49
|
const segments = splat.split('/').filter(Boolean).map(safeDecode);
|
|
41
|
-
|
|
50
|
+
const kbRoot = segments[1];
|
|
51
|
+
if (branch !== DEFAULT_BRANCH || (kbRoot !== PLUGINS_DIR && kbRoot !== SKILLS_DIR) || segments.length < 3) {
|
|
42
52
|
return <Navigate to={LIBRARY_ROOT} replace />;
|
|
43
53
|
}
|
|
44
54
|
if (kbDirName !== null && segments[0] !== kbDirName) {
|
|
45
55
|
return <Navigate to={LIBRARY_ROOT} replace />;
|
|
46
56
|
}
|
|
47
57
|
|
|
48
|
-
const [, , plugin, ...tail] = segments;
|
|
49
|
-
const last = tail[tail.length - 1];
|
|
50
|
-
if (!plugin || !last) {
|
|
51
|
-
return <Navigate to={LIBRARY_ROOT} replace />;
|
|
52
|
-
}
|
|
53
|
-
const repoRel = `${PLUGINS_DIR}/${plugin}/${tail.join('/')}`;
|
|
54
|
-
|
|
55
58
|
/**
|
|
56
59
|
* `key={name}` is load-bearing. A provisional name gets CORRECTED once the
|
|
57
60
|
* catalog lands (folder name → declared id), and without a remount the page
|
|
@@ -63,6 +66,45 @@ export function WorkspaceItemRoute() {
|
|
|
63
66
|
<SkillPage key={name} name={name} activeFile={activeFile} provisional={provisional} />
|
|
64
67
|
);
|
|
65
68
|
|
|
69
|
+
if (kbRoot === SKILLS_DIR) {
|
|
70
|
+
const rest = segments.slice(2);
|
|
71
|
+
const resolved = resolveSkillPath(data, `${SKILLS_DIR}/${rest.join('/')}`, rest, null, witness);
|
|
72
|
+
switch (resolved.kind) {
|
|
73
|
+
case 'skill':
|
|
74
|
+
return skillPage(resolved.name, resolved.file, resolved.provisional);
|
|
75
|
+
case 'wait':
|
|
76
|
+
return null;
|
|
77
|
+
case 'container':
|
|
78
|
+
// A scope has no page of its own — the sidebar's tree is where it is browsed.
|
|
79
|
+
return <Navigate to={LIBRARY_ROOT} replace />;
|
|
80
|
+
case 'loose-file': {
|
|
81
|
+
// A file filed directly in a scope (its access.md, a stray note)
|
|
82
|
+
// opens as the plain file it is, in the pane workspace. Router STATE,
|
|
83
|
+
// not a different URL: the shell reads `rawFile` to step past the
|
|
84
|
+
// shape rule, and a shared link can never carry state — so nobody
|
|
85
|
+
// lands on the raw view by accident. Once asked, hold still: the
|
|
86
|
+
// shell is swapping surfaces on that state, and asking again from
|
|
87
|
+
// here would be a navigation loop.
|
|
88
|
+
const rawRequested = (location.state as { rawFile?: boolean } | null)?.rawFile === true;
|
|
89
|
+
if (rawRequested) return null;
|
|
90
|
+
return (
|
|
91
|
+
<Navigate
|
|
92
|
+
to={`${location.pathname}${location.search}${location.hash}`}
|
|
93
|
+
state={{ rawFile: true }}
|
|
94
|
+
replace
|
|
95
|
+
/>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const [, , plugin, ...tail] = segments;
|
|
102
|
+
const last = tail[tail.length - 1];
|
|
103
|
+
if (!plugin || !last) {
|
|
104
|
+
return <Navigate to={LIBRARY_ROOT} replace />;
|
|
105
|
+
}
|
|
106
|
+
const repoRel = `${PLUGINS_DIR}/${plugin}/${tail.join('/')}`;
|
|
107
|
+
|
|
66
108
|
// A `.tool` is a tool page wherever it sits. The backend finds manuals at
|
|
67
109
|
// ANY depth below `Plugins/` (`walkFiles` over the whole tree), so a manual
|
|
68
110
|
// filed inside a category folder is a real, listed tool — matching only at
|
|
@@ -99,68 +141,132 @@ export function WorkspaceItemRoute() {
|
|
|
99
141
|
return <Navigate to={pathForPlugin(plugin)} replace />;
|
|
100
142
|
}
|
|
101
143
|
|
|
102
|
-
//
|
|
103
|
-
// is
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
144
|
+
// `Plugins/<plugin>/SKILL.md` makes the plugin folder itself the skill,
|
|
145
|
+
// which is what the backend's walk would report for it.
|
|
146
|
+
const resolved = resolveSkillPath(data, repoRel, tail, plugin, witness);
|
|
147
|
+
switch (resolved.kind) {
|
|
148
|
+
case 'skill':
|
|
149
|
+
return skillPage(resolved.name, resolved.file, resolved.provisional);
|
|
150
|
+
case 'wait':
|
|
151
|
+
return null;
|
|
152
|
+
case 'container':
|
|
153
|
+
case 'loose-file':
|
|
154
|
+
// A category has no page of its own; its plugin does. A file that can
|
|
155
|
+
// be no skill's — `access.md` at either level, a stray upload — is the
|
|
156
|
+
// plugin's business too.
|
|
157
|
+
return <Navigate to={pathForPlugin(plugin)} replace />;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
type SkillPathResolution =
|
|
162
|
+
| { kind: 'skill'; name: string; file: string; provisional: boolean }
|
|
163
|
+
/** A folder with catalog skills BELOW it — a category or a scope, never a skill itself. */
|
|
164
|
+
| { kind: 'container' }
|
|
165
|
+
/** A file that can be no skill's: directly in the root folder, or in a known container. */
|
|
166
|
+
| { kind: 'loose-file' }
|
|
167
|
+
/** Nothing positive settled it and the catalog is still loading. */
|
|
168
|
+
| { kind: 'wait' };
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* What a path under a root names, by the ONE set of evidence rules both roots
|
|
172
|
+
* share. `tail` is the path below the root's own folder (the plugin, or
|
|
173
|
+
* `Skills/` itself); `selfName` is that folder's name when it can be a skill
|
|
174
|
+
* (a plugin holding a bare `SKILL.md`), null when it cannot (`Skills/`).
|
|
175
|
+
*
|
|
176
|
+
* THE CATALOG IS THE AUTHORITY on which folder is a skill and what its id
|
|
177
|
+
* is. Folders may nest (`Plugins/Engineering/coding/create-ticket/SKILL.md`),
|
|
178
|
+
* and a skill's id is its frontmatter `id`/`name` — only FALLING BACK to the
|
|
179
|
+
* folder name — so neither the depth nor the id can be read off the URL with
|
|
180
|
+
* certainty. Take the DEEPEST skill whose folder contains this path: a
|
|
181
|
+
* category folder is never itself a skill, so the deepest match is the owner,
|
|
182
|
+
* and a `SKILL.md` bundled inside a skill (`<skill>/examples/SKILL.md`)
|
|
183
|
+
* stays that skill's file instead of inventing a skill called `examples`.
|
|
184
|
+
*
|
|
185
|
+
* Not in the catalog: a `SKILL.md` still names its own skill structurally —
|
|
186
|
+
* the folder holding it — and that is deliberately catalog-FREE, so a skill
|
|
187
|
+
* created a moment ago opens from its URL alone, before any reload lands.
|
|
188
|
+
*
|
|
189
|
+
* Everything below that is decided on POSITIVE evidence only. What the
|
|
190
|
+
* catalog KNOWS is trustworthy whenever it is there — cached entries survive
|
|
191
|
+
* a failed refresh — but what it does NOT know proves nothing: it may be
|
|
192
|
+
* loading, stale (a skill created seconds ago), or have failed outright.
|
|
193
|
+
* Reading absence as "this is not a page" is what bounced valid deep links
|
|
194
|
+
* to the plugin, so this never draws that inference. A folder with catalog
|
|
195
|
+
* skills UNDER it is a container, not a skill — the discriminator between a
|
|
196
|
+
* category and a just-created skill whose reload hasn't landed: the former
|
|
197
|
+
* has known descendants, the latter has none. A FILE is loose when it cannot
|
|
198
|
+
* be a skill's: it sits directly in the root folder (structurally never
|
|
199
|
+
* inside a skill), or its own folder is a known container. A file under an
|
|
200
|
+
* UNKNOWN folder is left alone — that folder is most likely a skill the
|
|
201
|
+
* catalog hasn't caught up with — unless the WORKSPACE TREE, the second
|
|
202
|
+
* witness, has the folder and shows no `SKILL.md` in it: then it is a
|
|
203
|
+
* container (a scope with nothing the caller may read beneath) or a loose
|
|
204
|
+
* file in one, and no catalog can make it a skill. When nothing positive
|
|
205
|
+
* settled it and the catalog is still loading, WAIT: the evidence may be one
|
|
206
|
+
* render away, and guessing flashes a page for a name that is about to
|
|
207
|
+
* change. Only then is the URL read structurally — a file belongs to the
|
|
208
|
+
* folder holding it, a bare folder names itself — and provisionally, so
|
|
209
|
+
* `SkillPage` must not turn a failed lookup into "doesn't exist" until the
|
|
210
|
+
* catalog has answered.
|
|
211
|
+
*/
|
|
212
|
+
function resolveSkillPath(
|
|
213
|
+
data: { items: readonly { kind: string; id: string; path: string }[]; loading: boolean },
|
|
214
|
+
repoRel: string,
|
|
215
|
+
tail: readonly string[],
|
|
216
|
+
selfName: string | null,
|
|
217
|
+
/** Whether a repo-relative folder holds a SKILL.md — true, false, or undefined when the tree cannot say. */
|
|
218
|
+
witness?: (folderRel: string) => boolean | undefined,
|
|
219
|
+
): SkillPathResolution {
|
|
220
|
+
const last = tail[tail.length - 1]!;
|
|
110
221
|
const owner = deepestSkillOwning(data.items, repoRel);
|
|
111
222
|
if (owner) {
|
|
112
223
|
const file = repoRel.slice(owner.path.length + 1);
|
|
113
|
-
return
|
|
224
|
+
return { kind: 'skill', name: owner.id, file: file || 'SKILL.md', provisional: false };
|
|
114
225
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
//
|
|
118
|
-
//
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return skillPage(tail.length >= 2 ? tail[tail.length - 2]! : plugin, 'SKILL.md', true);
|
|
226
|
+
const parentName = tail.length >= 2 ? tail[tail.length - 2]! : selfName;
|
|
227
|
+
const parentRel = repoRel.slice(0, repoRel.length - last.length - 1);
|
|
228
|
+
// The tree's verdict comes BEFORE any structural reading of the URL: a
|
|
229
|
+
// folder the tree holds with no SKILL.md in it is no skill, whatever the
|
|
230
|
+
// path is called — a `SKILL.md` URL into it included.
|
|
231
|
+
if (witness?.(hasExtension(last) ? parentRel : repoRel) === false) {
|
|
232
|
+
return hasExtension(last) ? { kind: 'loose-file' } : { kind: 'container' };
|
|
123
233
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
// KNOWS is trustworthy whenever it is there — cached entries survive a
|
|
127
|
-
// failed refresh — but what it does NOT know proves nothing: it may be
|
|
128
|
-
// loading, stale (a skill created seconds ago), or have failed outright.
|
|
129
|
-
// Reading absence as "this is not a page" is what bounced valid deep links
|
|
130
|
-
// to the plugin, so this no longer draws that inference at all.
|
|
131
|
-
|
|
132
|
-
// A folder with catalog skills UNDER it is a category, not a skill. That is
|
|
133
|
-
// the discriminator between a category folder and a just-created skill whose
|
|
134
|
-
// reload hasn't landed: the former has known descendants, the latter has
|
|
135
|
-
// none. A category has no page of its own; its plugin does.
|
|
136
|
-
if (!hasExtension(last) && containsCatalogSkill(data.items, repoRel)) {
|
|
137
|
-
return <Navigate to={pathForPlugin(plugin)} replace />;
|
|
234
|
+
if (last === 'SKILL.md' && parentName !== null) {
|
|
235
|
+
return { kind: 'skill', name: parentName, file: 'SKILL.md', provisional: true };
|
|
138
236
|
}
|
|
139
|
-
|
|
140
|
-
// A FILE is the plugin's business when it cannot be a skill's file: either it
|
|
141
|
-
// sits directly in the plugin folder (structurally never inside a skill), or
|
|
142
|
-
// its own folder is a known category. `access.md` at either level, a stray
|
|
143
|
-
// upload. A file under an UNKNOWN folder is left alone — that folder is most
|
|
144
|
-
// likely a skill the catalog hasn't caught up with.
|
|
145
|
-
const parentRel = repoRel.slice(0, repoRel.length - last.length - 1);
|
|
237
|
+
if (!hasExtension(last) && containsCatalogSkill(data.items, repoRel)) return { kind: 'container' };
|
|
146
238
|
if (hasExtension(last) && (tail.length === 1 || containsCatalogSkill(data.items, parentRel))) {
|
|
147
|
-
return
|
|
239
|
+
return { kind: 'loose-file' };
|
|
148
240
|
}
|
|
241
|
+
if (data.loading) return { kind: 'wait' };
|
|
242
|
+
if (hasExtension(last)) {
|
|
243
|
+
return parentName === null
|
|
244
|
+
? { kind: 'loose-file' }
|
|
245
|
+
: { kind: 'skill', name: parentName, file: last, provisional: true };
|
|
246
|
+
}
|
|
247
|
+
return { kind: 'skill', name: last, file: 'SKILL.md', provisional: true };
|
|
248
|
+
}
|
|
149
249
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
250
|
+
/**
|
|
251
|
+
* Whether the folder at `workspaceRel` holds a `SKILL.md`, by the workspace
|
|
252
|
+
* tree: true or false when the tree has the folder, undefined when it does
|
|
253
|
+
* not (not loaded, not readable, not on this branch) — an absence that
|
|
254
|
+
* proves nothing, exactly like the catalog's.
|
|
255
|
+
*/
|
|
256
|
+
function folderHasSkillMd(tree: FileTreeEntry | null, workspaceRel: string | null): boolean | undefined {
|
|
257
|
+
if (!tree || workspaceRel === null) return undefined;
|
|
258
|
+
const find = (node: FileTreeEntry): FileTreeEntry | null => {
|
|
259
|
+
if (node.relativePath === workspaceRel) return node;
|
|
260
|
+
if (!node.children || !workspaceRel.startsWith(node.relativePath === '.' ? '' : `${node.relativePath}/`)) return null;
|
|
261
|
+
for (const child of node.children) {
|
|
262
|
+
const hit = find(child);
|
|
263
|
+
if (hit) return hit;
|
|
264
|
+
}
|
|
265
|
+
return null;
|
|
266
|
+
};
|
|
267
|
+
const folder = find(tree);
|
|
268
|
+
if (!folder || folder.type !== 'directory') return undefined;
|
|
269
|
+
return (folder.children ?? []).some((c) => c.type === 'file' && c.name === 'SKILL.md');
|
|
164
270
|
}
|
|
165
271
|
|
|
166
272
|
/** Whether a path segment names a file rather than a folder. */
|
|
@@ -202,12 +308,3 @@ function deepestSkillOwning(
|
|
|
202
308
|
}
|
|
203
309
|
return best;
|
|
204
310
|
}
|
|
205
|
-
|
|
206
|
-
/** A malformed escape is a bad link, not a crash — fall back to the raw segment. */
|
|
207
|
-
function safeDecode(raw: string): string {
|
|
208
|
-
try {
|
|
209
|
-
return decodeURIComponent(raw);
|
|
210
|
-
} catch {
|
|
211
|
-
return raw;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEFAULT_BRANCH, PLUGINS_DIR, pluginOfPath, isPersonalPluginFolder } from '@bevel-software/platform-shared';
|
|
1
|
+
import { DEFAULT_BRANCH, PLUGINS_DIR, SKILLS_DIR, pluginOfPath, isPersonalPluginFolder } from '@bevel-software/platform-shared';
|
|
2
2
|
import { matchPath } from 'react-router-dom';
|
|
3
3
|
import { kbFileUrl } from '../../workspace/routing/kb-routes';
|
|
4
4
|
import type { LibraryFilter } from '../utils/status';
|
|
@@ -143,8 +143,8 @@ export function isLibraryLocation(pathname: string): boolean {
|
|
|
143
143
|
return (
|
|
144
144
|
segments[0] === 'workspace' &&
|
|
145
145
|
segments[1] === DEFAULT_BRANCH &&
|
|
146
|
-
segments[3] === PLUGINS_DIR &&
|
|
147
|
-
|
|
146
|
+
((segments[3] === PLUGINS_DIR && segments.length >= 6) || // workspace/<branch>/<kbDir>/Plugins/<plugin>/<item>
|
|
147
|
+
(segments[3] === SKILLS_DIR && segments.length >= 5)) // workspace/<branch>/<kbDir>/Skills/<skill or scope>/…
|
|
148
148
|
);
|
|
149
149
|
}
|
|
150
150
|
|
|
@@ -206,16 +206,29 @@ function decodeSegment(raw: string): string {
|
|
|
206
206
|
* plugin page for a grouped item, the personal page for a personal one, and
|
|
207
207
|
* the root only for the legacy shapes that live in neither.
|
|
208
208
|
*/
|
|
209
|
-
export function libraryHomeForItemPath(
|
|
209
|
+
export function libraryHomeForItemPath(
|
|
210
|
+
repoRelativePath: string,
|
|
211
|
+
/**
|
|
212
|
+
* The plugin's IDENTITY, resolved by the caller through the catalog. Both
|
|
213
|
+
* `undefined` (not resolved) and `null` (resolved to no plugin) fall back
|
|
214
|
+
* to the folder — a personal shelf is decided by the folder before either.
|
|
215
|
+
*/
|
|
216
|
+
pluginName?: string | null,
|
|
217
|
+
/** The label for that identity; identity by default. */
|
|
218
|
+
labelOf: (name: string) => string = (n) => n,
|
|
219
|
+
): {
|
|
210
220
|
label: string;
|
|
211
221
|
path: string;
|
|
212
222
|
} {
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
223
|
+
const folder = pluginOfPath(repoRelativePath);
|
|
224
|
+
// A personal shelf is decided by the FOLDER, whatever identity the caller
|
|
225
|
+
// resolved (a personal item's identity is null: a shelf is not a plugin).
|
|
226
|
+
if (folder !== null && isPersonalPluginFolder(folder)) {
|
|
227
|
+
return { label: 'Yours', path: `${LIBRARY_ROOT}/yours` };
|
|
216
228
|
}
|
|
229
|
+
const plugin = pluginName ?? folder;
|
|
217
230
|
if (plugin !== null) {
|
|
218
|
-
return { label:
|
|
231
|
+
return { label: labelOf(plugin), path: pathForPlugin(plugin) };
|
|
219
232
|
}
|
|
220
233
|
return { label: 'All skills & tools', path: LIBRARY_ROOT };
|
|
221
234
|
}
|
|
@@ -6,7 +6,7 @@ import { deleteFile, getOrCreateWorkspace, writeFile } from '../../workspace/ser
|
|
|
6
6
|
import { openChangeRequest } from '../../pr/services/pr-open.api';
|
|
7
7
|
import { postPrComment } from '../../pr/services/pr-comments.api';
|
|
8
8
|
import { branchSegment } from '../../change-requests/services/propose.api';
|
|
9
|
-
import { ensurePersonalPlugin } from './plugins.api';
|
|
9
|
+
import { ensurePersonalPlugin, type JoinRequest } from './plugins.api';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Library data access. Skills come from the browser skill routes
|
|
@@ -26,6 +26,18 @@ import { ensurePersonalPlugin } from './plugins.api';
|
|
|
26
26
|
*/
|
|
27
27
|
export const defaultWorkspaceId = () => encodeURIComponent(DEFAULT_BRANCH);
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* One plugin a skill belongs to — inside the plugin folder (`linked: false`)
|
|
31
|
+
* or linked from the plugin's manifest (`linked: true`). `granted` is the
|
|
32
|
+
* link's health: whether the skill's own access rules still name the plugin's
|
|
33
|
+
* `plugin/<Name>/read` principal. Mirrors the backend contract.
|
|
34
|
+
*/
|
|
35
|
+
export interface PluginMembership {
|
|
36
|
+
name: string;
|
|
37
|
+
linked: boolean;
|
|
38
|
+
granted: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
29
41
|
export interface LibrarySkillSummary {
|
|
30
42
|
/** Canonical id = the skill's folder name (e.g. `rfi`). */
|
|
31
43
|
name: string;
|
|
@@ -33,6 +45,48 @@ export interface LibrarySkillSummary {
|
|
|
33
45
|
version?: string;
|
|
34
46
|
/** Repo-root-relative skill folder, e.g. `Plugins/Everyone/rfi`. */
|
|
35
47
|
path: string;
|
|
48
|
+
/** Every plugin holding this skill. Absent from an older server. */
|
|
49
|
+
plugins?: PluginMembership[];
|
|
50
|
+
/** The governance owner (`metadata.owner`), when declared. */
|
|
51
|
+
owner?: string;
|
|
52
|
+
/** The governance lifecycle (`metadata.lifecycle`), lowercased: `active`, `deprecated`, `retired`. */
|
|
53
|
+
lifecycle?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The open write-access requests on a skill — `[]` to anyone but its editors. */
|
|
57
|
+
export async function listSkillAccessRequests(name: string): Promise<JoinRequest[]> {
|
|
58
|
+
const data = await handleApiResponse<{ requests: JoinRequest[] }>(
|
|
59
|
+
await authFetch(`/api/skills/${encodeURIComponent(name)}/access-requests`),
|
|
60
|
+
);
|
|
61
|
+
return data.requests;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Settle one request if every proposal has landed. Returns whether it closed. */
|
|
65
|
+
export async function reconcileSkillAccessRequest(name: string, number: number): Promise<boolean> {
|
|
66
|
+
const data = await handleApiResponse<{ closed: boolean }>(
|
|
67
|
+
await authFetch(`/api/skills/${encodeURIComponent(name)}/access-requests/${number}/reconcile`, {
|
|
68
|
+
method: 'POST',
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
71
|
+
return data.closed;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Ask the skill's editors for write on it — a change request that proposes
|
|
76
|
+
* the grant, exactly like asking to join a plugin. Idempotent: a second ask
|
|
77
|
+
* returns the open request.
|
|
78
|
+
*/
|
|
79
|
+
export async function requestSkillAccess(name: string): Promise<{ number: number }> {
|
|
80
|
+
const res = await authFetch(`/api/skills/${encodeURIComponent(name)}/access-request`, {
|
|
81
|
+
method: 'POST',
|
|
82
|
+
headers: { 'Content-Type': 'application/json' },
|
|
83
|
+
body: JSON.stringify({ verb: 'write' }),
|
|
84
|
+
});
|
|
85
|
+
if (!res.ok) {
|
|
86
|
+
const body = (await res.json().catch(() => ({}))) as { error?: string };
|
|
87
|
+
throw new Error(body.error ?? "Couldn't request access.");
|
|
88
|
+
}
|
|
89
|
+
return (await res.json()) as { number: number };
|
|
36
90
|
}
|
|
37
91
|
|
|
38
92
|
export interface LibrarySkill extends LibrarySkillSummary {
|