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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +18 -17
  3. package/src/core/__tests__/bootstrap.test.ts +33 -1
  4. package/src/core/bootstrap.ts +30 -1
  5. package/src/lib/__tests__/api.test.ts +38 -0
  6. package/src/lib/api.ts +19 -2
  7. package/src/lib/utils.ts +2 -0
  8. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +111 -1
  9. package/src/modules/access/__tests__/plugin-token.test.ts +21 -0
  10. package/src/modules/access/api.ts +52 -4
  11. package/src/modules/access/components/ManageAccessDialog.tsx +112 -83
  12. package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +65 -1
  13. package/src/modules/git/components/GitSyncFailedBanner.tsx +68 -5
  14. package/src/modules/layout/components/SidebarFrame.tsx +1 -1
  15. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +1 -1
  16. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +1 -1
  17. package/src/modules/library/__tests__/LinkSkillPanel.test.tsx +121 -0
  18. package/src/modules/library/__tests__/LockedPluginView.test.tsx +6 -0
  19. package/src/modules/library/__tests__/NewPluginDialog.test.tsx +5 -4
  20. package/src/modules/library/__tests__/PluginExtras.test.tsx +15 -0
  21. package/src/modules/library/__tests__/PluginPage.test.tsx +195 -1
  22. package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +1 -1
  23. package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +1 -1
  24. package/src/modules/library/__tests__/PluginsSidebar.test.tsx +64 -3
  25. package/src/modules/library/__tests__/SkillPage.test.tsx +9 -2
  26. package/src/modules/library/__tests__/SkillsTree.test.tsx +172 -0
  27. package/src/modules/library/__tests__/ToolPage.test.tsx +7 -0
  28. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +115 -4
  29. package/src/modules/library/__tests__/library-data.stale.test.tsx +90 -0
  30. package/src/modules/library/__tests__/library-paths.test.ts +32 -0
  31. package/src/modules/library/__tests__/link-membership.test.ts +120 -0
  32. package/src/modules/library/__tests__/plugin-summary.test.ts +32 -0
  33. package/src/modules/library/__tests__/useJoinRequests.test.tsx +46 -0
  34. package/src/modules/library/components/AddToPluginDialog.tsx +33 -0
  35. package/src/modules/library/components/LibraryCard.tsx +14 -0
  36. package/src/modules/library/components/LibraryLayout.tsx +24 -14
  37. package/src/modules/library/components/LinkSkillPanel.tsx +171 -0
  38. package/src/modules/library/components/LockedPluginView.tsx +2 -2
  39. package/src/modules/library/components/NewPluginDialog.tsx +4 -4
  40. package/src/modules/library/components/PageActions.tsx +21 -1
  41. package/src/modules/library/components/PersonalPluginPage.tsx +2 -1
  42. package/src/modules/library/components/PluginExtras.tsx +3 -1
  43. package/src/modules/library/components/PluginPage.tsx +92 -12
  44. package/src/modules/library/components/PluginsIndexPage.tsx +11 -6
  45. package/src/modules/library/components/PluginsSidebar.tsx +110 -53
  46. package/src/modules/library/components/RenamePluginDialog.tsx +136 -0
  47. package/src/modules/library/components/SkillsTree.tsx +91 -0
  48. package/src/modules/library/components/StatusDot.tsx +1 -0
  49. package/src/modules/library/components/plugin-page-parts.tsx +32 -9
  50. package/src/modules/library/components/skill-page/SharedViaPlugins.tsx +218 -0
  51. package/src/modules/library/components/skill-page/SkillPage.tsx +70 -6
  52. package/src/modules/library/components/tool-page/ToolPage.tsx +11 -2
  53. package/src/modules/library/hooks/useJoinRequests.ts +48 -18
  54. package/src/modules/library/routes/WorkspaceItemRoute.tsx +180 -83
  55. package/src/modules/library/routes/library-paths.ts +21 -8
  56. package/src/modules/library/services/library.api.ts +55 -1
  57. package/src/modules/library/services/plugins.api.ts +94 -3
  58. package/src/modules/library/state/library-data.tsx +115 -22
  59. package/src/modules/library/utils/plugin-summary.ts +36 -0
  60. package/src/modules/library/utils/status.ts +74 -7
  61. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +3 -2
  62. package/src/modules/settings/components/ClaudeConnectionCard.tsx +169 -0
  63. package/src/modules/settings/components/DeploymentPage.tsx +15 -1
  64. package/src/modules/settings/components/__tests__/ClaudeConnectionCard.test.tsx +63 -0
  65. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +10 -0
  66. package/src/modules/settings/services/github-facade.api.ts +43 -0
  67. package/src/modules/setup/__tests__/setup.test.tsx +118 -0
  68. package/src/modules/setup/components/SetupGate.tsx +1 -1
  69. package/src/modules/setup/components/SetupScreen.tsx +195 -2
  70. package/src/modules/setup/services/setup.api.ts +78 -0
  71. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +295 -83
  72. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +129 -6
  73. package/src/modules/toolbar/services/external-api-keys.api.ts +2 -0
  74. package/src/modules/workspace/__tests__/testFixtures.ts +1 -0
  75. package/src/modules/workspace/components/FileExplorer.tsx +292 -236
  76. package/src/modules/workspace/components/FileRoute.tsx +37 -0
  77. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +39 -0
  78. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +1 -0
  79. package/src/modules/workspace/hooks/useMergedWorkspaceTree.ts +70 -0
  80. package/src/modules/workspace/hooks/useWorkspaceState.ts +17 -3
  81. package/src/modules/workspace/routing/kb-routes.ts +1 -1
  82. package/src/modules/workspace/state/workspace.context.ts +8 -0
  83. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +15 -0
  84. package/src/modules/workspace/utils/fileTree.ts +14 -16
  85. package/src/shared/__tests__/marketplace-url.test.ts +54 -0
  86. package/src/shared/components/Badge.tsx +3 -1
  87. package/src/shared/components/Banner.tsx +5 -1
  88. package/src/shared/marketplace-url.ts +90 -0
  89. package/src/shared/theme/tokens.css +9 -0
@@ -1,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>/<...>` — rendered INSIDE the
12
- * same `LibraryLayout` route tree as every other library page, so the sidebar
13
- * is the one the reader already had and nothing remounts on the way in.
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), any other direct FILE (an extension, no segments below
19
- * it — `access.md`) belongs to the plugin page, and everything else is a skill
20
- * FOLDER whose name is the skill's id — the same identity the old name-based
21
- * route used. That is what makes a skill created a moment ago
22
- * open instantly: its URL says everything the page needs, and `SkillPage`
23
- * fetches the skill by name itself. Waiting on the catalog here raced every
24
- * reload and lost (the just-created skill bounced to its plugin's page).
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
- if (branch !== DEFAULT_BRANCH || segments[1] !== PLUGINS_DIR || segments.length < 3) {
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
- // THE CATALOG IS THE AUTHORITY on which folder is a skill and what its id
103
- // is. Plugins may nest (`Plugins/Engineering/coding/create-ticket/SKILL.md`),
104
- // and a skill's id is its frontmatter `id`/`name` — only FALLING BACK to the
105
- // folder name — so neither the depth nor the id can be read off the URL with
106
- // certainty. Take the DEEPEST skill whose folder contains this path: a
107
- // category folder is never itself a skill, so the deepest match is the owner,
108
- // and a `SKILL.md` bundled inside a skill (`<skill>/examples/SKILL.md`)
109
- // stays that skill's file instead of inventing a skill called `examples`.
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 skillPage(owner.id, file || 'SKILL.md', false);
224
+ return { kind: 'skill', name: owner.id, file: file || 'SKILL.md', provisional: false };
114
225
  }
115
-
116
- // Not in the catalog. A `SKILL.md` still names its own skill structurally —
117
- // the folder holding it — and that is deliberately catalog-FREE: a skill
118
- // created a moment ago opens from its URL alone, before any reload lands.
119
- // (`Plugins/<plugin>/SKILL.md` makes the plugin folder itself the skill, which
120
- // is what the backend's walk would report for it.)
121
- if (last === 'SKILL.md') {
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
- // Everything below is decided on POSITIVE evidence only. What the catalog
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 <Navigate to={pathForPlugin(plugin)} replace />;
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
- // Nothing positive settled it. While the catalog is still loading, WAIT: the
151
- // evidence above may be one render away, and guessing flashes a page for a
152
- // name that is about to change. The layout and its sidebar are already on
153
- // screen around this.
154
- if (data.loading) return null;
155
-
156
- // Read the URL structurally — a file belongs to the folder holding it, a
157
- // bare folder names itself, the same rule the backend applies when no
158
- // frontmatter declares an id. Provisional: the catalog never confirmed it,
159
- // so SkillPage must not turn a failed lookup into "doesn't exist" until the
160
- // catalog has actually answered.
161
- return hasExtension(last)
162
- ? skillPage(tail.length >= 2 ? tail[tail.length - 2]! : plugin, last, true)
163
- : skillPage(last, 'SKILL.md', true);
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
- segments.length >= 6 // workspace/<branch>/<kbDir>/Plugins/<plugin>/<item>
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(repoRelativePath: string): {
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 plugin = pluginOfPath(repoRelativePath);
214
- if (plugin !== null && !isPersonalPluginFolder(plugin)) {
215
- return { label: plugin, path: pathForPlugin(plugin) };
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: 'Yours', path: `${LIBRARY_ROOT}/yours` };
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 {
@@ -27,8 +27,10 @@ export interface PluginReaders extends PluginPrincipals {
27
27
  }
28
28
 
29
29
  export interface PluginSummary {
30
- /** Plugin folder name, e.g. `GTM`. */
30
+ /** The plugin's identity — its manifest name, e.g. `gtm`. Grants, URLs and the marketplace spell it. */
31
31
  name: string;
32
+ /** What people see it called, e.g. `GTM`. Absent from an older server: show `name`. */
33
+ displayName?: string;
32
34
  /** Repo-relative constituent folders, e.g. `['Plugins/GTM']`. */
33
35
  folders: string[];
34
36
  /** Per-caller: can read the folder (membership). Locked === !canRead. */
@@ -41,9 +43,23 @@ export interface PluginSummary {
41
43
  * enforces this same verdict, so it also decides who sees the affordance.
42
44
  */
43
45
  isOwner: boolean;
46
+ /**
47
+ * Whether this platform writes the plugin's links (a native manifest).
48
+ * False for a plugin read from an external format — its links are edited
49
+ * in that repository, and the link endpoints refuse it. Absent from an
50
+ * older server, which knew only managed plugins.
51
+ */
52
+ linksAreManaged?: boolean;
44
53
  /** The plugin's TOTALS, not the caller's slice. */
45
54
  skillCount: number;
46
55
  toolCount: number;
56
+ /**
57
+ * How many of the plugin's linked skills its members cannot read, counted
58
+ * by the server from the unfiltered link index — so a manager the missing
59
+ * grant locks out of the skill still sees the count. Absent from an older
60
+ * server: fall back to what the caller's own catalog shows.
61
+ */
62
+ brokenLinks?: number;
47
63
  owners: PluginPrincipals;
48
64
  writers: PluginPrincipals;
49
65
  readers: PluginReaders;
@@ -67,7 +83,7 @@ export async function listPlugins(): Promise<PluginSummary[]> {
67
83
  * seeded `access.md` before answering, and refuses with its own words —
68
84
  * worth surfacing verbatim.
69
85
  */
70
- export async function createPlugin(name: string): Promise<{ folder: string }> {
86
+ export async function createPlugin(name: string): Promise<{ folder: string; name: string }> {
71
87
  const res = await authFetch('/api/plugins', {
72
88
  method: 'POST',
73
89
  headers: { 'Content-Type': 'application/json' },
@@ -77,7 +93,28 @@ export async function createPlugin(name: string): Promise<{ folder: string }> {
77
93
  const body = (await res.json().catch(() => ({}))) as { error?: string };
78
94
  throw new Error(body.error ?? "Couldn't create that plugin.");
79
95
  }
80
- return (await res.json()) as { folder: string };
96
+ return (await res.json()) as { folder: string; name: string };
97
+ }
98
+
99
+ /**
100
+ * Rename a plugin: its identifier (which rewrites every grant naming it),
101
+ * its display name, or both. The refusal's message names the reason — a
102
+ * taken name, a bad identifier, files the caller cannot edit.
103
+ */
104
+ export async function renamePlugin(
105
+ name: string,
106
+ patch: { name?: string; displayName?: string },
107
+ ): Promise<{ name: string; displayName: string; rewritten: string[] }> {
108
+ const res = await authFetch(`/api/plugins/${encodeURIComponent(name)}`, {
109
+ method: 'PATCH',
110
+ headers: { 'Content-Type': 'application/json' },
111
+ body: JSON.stringify(patch),
112
+ });
113
+ if (!res.ok) {
114
+ const body = (await res.json().catch(() => ({}))) as { error?: string };
115
+ throw new Error(body.error ?? "Couldn't rename the plugin.");
116
+ }
117
+ return (await res.json()) as { name: string; displayName: string; rewritten: string[] };
81
118
  }
82
119
 
83
120
  /**
@@ -108,6 +145,60 @@ export async function ensurePersonalPlugin(): Promise<{ folder: string; created:
108
145
  return (await res.json()) as { folder: string; created: boolean };
109
146
  }
110
147
 
148
+ /**
149
+ * Thrown when linking is refused because the caller may edit the plugin but
150
+ * not the skill's access rules — the link would share nothing. The UI turns
151
+ * this into "request write access".
152
+ */
153
+ export class NeedsSkillWriteError extends Error {
154
+ readonly root: string;
155
+ constructor(root: string) {
156
+ super("You can't change who may read this skill yet.");
157
+ this.name = 'NeedsSkillWriteError';
158
+ this.root = root;
159
+ }
160
+ }
161
+
162
+ async function linkCall(url: string, init: RequestInit): Promise<Record<string, unknown>> {
163
+ const res = await authFetch(url, init);
164
+ const body = (await res.json().catch(() => ({}))) as { error?: string; kind?: string; root?: string };
165
+ if (!res.ok) {
166
+ if (body.kind === 'needs-skill-write') throw new NeedsSkillWriteError(body.root ?? '');
167
+ throw new Error(body.error ?? "Couldn't update the plugin's links.");
168
+ }
169
+ return body;
170
+ }
171
+
172
+ /**
173
+ * Link a skill (or a folder of skills) into a plugin: the path goes into the
174
+ * plugin's manifest and the skill's rules grant the plugin's principals. Needs
175
+ * write on both sides — see `NeedsSkillWriteError`.
176
+ */
177
+ export async function linkSkill(plugin: string, skillPath: string): Promise<{ root: string; skills: string[] }> {
178
+ return (await linkCall(`/api/plugins/${encodeURIComponent(plugin)}/links`, {
179
+ method: 'POST',
180
+ headers: { 'Content-Type': 'application/json' },
181
+ body: JSON.stringify({ skillPath }),
182
+ })) as { root: string; skills: string[] };
183
+ }
184
+
185
+ /** Remove a link. `revoked` says whether the plugin's grant on the skill went with it. */
186
+ export async function unlinkSkill(plugin: string, skillPath: string): Promise<{ root: string; revoked: boolean }> {
187
+ return (await linkCall(
188
+ `/api/plugins/${encodeURIComponent(plugin)}/links?skillPath=${encodeURIComponent(skillPath)}`,
189
+ { method: 'DELETE' },
190
+ )) as { root: string; revoked: boolean };
191
+ }
192
+
193
+ /** Re-grant the plugin's principals on a linked skill whose grant was hand-removed. */
194
+ export async function repairSkillLink(plugin: string, skillPath: string): Promise<void> {
195
+ await linkCall(`/api/plugins/${encodeURIComponent(plugin)}/links/repair`, {
196
+ method: 'POST',
197
+ headers: { 'Content-Type': 'application/json' },
198
+ body: JSON.stringify({ skillPath }),
199
+ });
200
+ }
201
+
111
202
  /**
112
203
  * Thrown when a join request is refused because access already landed —
113
204
  * between the page load and the click. Not an error to show: the right