@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.
Files changed (102) 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/__tests__/utils.test.ts +43 -0
  7. package/src/lib/api.ts +19 -2
  8. package/src/lib/utils.ts +17 -7
  9. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +111 -1
  10. package/src/modules/access/__tests__/plugin-token.test.ts +21 -0
  11. package/src/modules/access/api.ts +52 -4
  12. package/src/modules/access/components/ManageAccessDialog.tsx +112 -83
  13. package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +65 -1
  14. package/src/modules/git/components/GitSyncFailedBanner.tsx +68 -5
  15. package/src/modules/layout/components/SidebarFrame.tsx +1 -1
  16. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +2 -1
  17. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +1 -1
  18. package/src/modules/library/__tests__/LinkSkillPanel.test.tsx +121 -0
  19. package/src/modules/library/__tests__/LockedPluginView.test.tsx +6 -0
  20. package/src/modules/library/__tests__/McpServerSection.test.tsx +7 -1
  21. package/src/modules/library/__tests__/NewPluginDialog.test.tsx +5 -4
  22. package/src/modules/library/__tests__/PluginExtras.test.tsx +15 -0
  23. package/src/modules/library/__tests__/PluginPage.test.tsx +195 -1
  24. package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +1 -1
  25. package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +1 -1
  26. package/src/modules/library/__tests__/PluginsSidebar.test.tsx +64 -3
  27. package/src/modules/library/__tests__/SkillPage.test.tsx +9 -2
  28. package/src/modules/library/__tests__/SkillsTree.test.tsx +172 -0
  29. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +216 -8
  30. package/src/modules/library/__tests__/ToolPage.test.tsx +23 -3
  31. package/src/modules/library/__tests__/ToolVarRow.test.tsx +7 -7
  32. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +115 -4
  33. package/src/modules/library/__tests__/library-data.stale.test.tsx +90 -0
  34. package/src/modules/library/__tests__/library-paths.test.ts +32 -0
  35. package/src/modules/library/__tests__/link-membership.test.ts +120 -0
  36. package/src/modules/library/__tests__/plugin-summary.test.ts +32 -0
  37. package/src/modules/library/__tests__/status.test.ts +84 -0
  38. package/src/modules/library/__tests__/useJoinRequests.test.tsx +46 -0
  39. package/src/modules/library/components/AddToPluginDialog.tsx +33 -0
  40. package/src/modules/library/components/LibraryCard.tsx +21 -1
  41. package/src/modules/library/components/LibraryLayout.tsx +24 -14
  42. package/src/modules/library/components/LinkSkillPanel.tsx +171 -0
  43. package/src/modules/library/components/LockedPluginView.tsx +2 -2
  44. package/src/modules/library/components/NewPluginDialog.tsx +4 -4
  45. package/src/modules/library/components/PageActions.tsx +21 -1
  46. package/src/modules/library/components/PersonalPluginPage.tsx +2 -1
  47. package/src/modules/library/components/PluginExtras.tsx +3 -1
  48. package/src/modules/library/components/PluginPage.tsx +92 -12
  49. package/src/modules/library/components/PluginsIndexPage.tsx +11 -6
  50. package/src/modules/library/components/PluginsSidebar.tsx +110 -53
  51. package/src/modules/library/components/RenamePluginDialog.tsx +136 -0
  52. package/src/modules/library/components/SkillsTree.tsx +91 -0
  53. package/src/modules/library/components/StatusDot.tsx +1 -0
  54. package/src/modules/library/components/plugin-page-parts.tsx +32 -9
  55. package/src/modules/library/components/skill-page/SharedViaPlugins.tsx +218 -0
  56. package/src/modules/library/components/skill-page/SkillPage.tsx +75 -7
  57. package/src/modules/library/components/tool-page/McpServerSection.tsx +9 -1
  58. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +223 -8
  59. package/src/modules/library/components/tool-page/ToolPage.tsx +30 -2
  60. package/src/modules/library/components/tool-page/ToolVarRow.tsx +30 -8
  61. package/src/modules/library/hooks/useJoinRequests.ts +48 -18
  62. package/src/modules/library/hooks/useToolPage.ts +28 -11
  63. package/src/modules/library/routes/WorkspaceItemRoute.tsx +180 -83
  64. package/src/modules/library/routes/library-paths.ts +21 -8
  65. package/src/modules/library/services/library.api.ts +55 -1
  66. package/src/modules/library/services/plugins.api.ts +94 -3
  67. package/src/modules/library/state/library-data.tsx +115 -22
  68. package/src/modules/library/utils/plugin-summary.ts +36 -0
  69. package/src/modules/library/utils/status.ts +173 -17
  70. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +3 -2
  71. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +29 -14
  72. package/src/modules/secrets-vault/components/SecretsPage.tsx +4 -1
  73. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +4 -1
  74. package/src/modules/secrets-vault/services/tool-secrets.api.ts +36 -0
  75. package/src/modules/settings/components/ClaudeConnectionCard.tsx +169 -0
  76. package/src/modules/settings/components/DeploymentPage.tsx +15 -1
  77. package/src/modules/settings/components/__tests__/ClaudeConnectionCard.test.tsx +63 -0
  78. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +10 -0
  79. package/src/modules/settings/services/github-facade.api.ts +43 -0
  80. package/src/modules/setup/__tests__/setup.test.tsx +118 -0
  81. package/src/modules/setup/components/SetupGate.tsx +1 -1
  82. package/src/modules/setup/components/SetupScreen.tsx +195 -2
  83. package/src/modules/setup/services/setup.api.ts +78 -0
  84. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +301 -93
  85. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +129 -6
  86. package/src/modules/toolbar/services/external-api-keys.api.ts +2 -0
  87. package/src/modules/workspace/__tests__/testFixtures.ts +1 -0
  88. package/src/modules/workspace/components/FileExplorer.tsx +292 -236
  89. package/src/modules/workspace/components/FileRoute.tsx +37 -0
  90. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +39 -0
  91. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +1 -0
  92. package/src/modules/workspace/hooks/useMergedWorkspaceTree.ts +70 -0
  93. package/src/modules/workspace/hooks/useWorkspaceState.ts +17 -3
  94. package/src/modules/workspace/routing/kb-routes.ts +1 -1
  95. package/src/modules/workspace/state/workspace.context.ts +8 -0
  96. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +15 -0
  97. package/src/modules/workspace/utils/fileTree.ts +14 -16
  98. package/src/shared/__tests__/marketplace-url.test.ts +54 -0
  99. package/src/shared/components/Badge.tsx +3 -1
  100. package/src/shared/components/Banner.tsx +5 -1
  101. package/src/shared/marketplace-url.ts +90 -0
  102. package/src/shared/theme/tokens.css +9 -0
@@ -0,0 +1,136 @@
1
+ import { useId, useState } from 'react';
2
+ import { PERSONAL_PLUGIN_PREFIX, pluginManifestName } from '@bevel-software/platform-shared';
3
+ import { Banner, Button, Dialog, TextField } from '../../../shared/components';
4
+ import { renamePlugin, type PluginSummary } from '../services/plugins.api';
5
+ import { useLibraryToast } from '../state/toast.context';
6
+
7
+ /** The Agent Plugins identifier rule — lowercase kebab-case, nothing else. */
8
+ const IDENTIFIER_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
9
+
10
+ /**
11
+ * Rename a plugin: its identifier, its display name, or both.
12
+ *
13
+ * The identifier is the plugin — the grants spell it, the URLs key on it,
14
+ * the marketplace publishes it — so changing it rewrites every grant that
15
+ * names the old one, in one commit, and the dialog says so before the click.
16
+ * The display name is only what people see.
17
+ */
18
+ export function RenamePluginDialog({
19
+ plugin,
20
+ onClose,
21
+ onRenamed,
22
+ }: {
23
+ plugin: Pick<PluginSummary, 'name' | 'displayName' | 'folders'>;
24
+ onClose(): void;
25
+ /** The rename landed; the host reloads and, when the identifier changed, navigates. */
26
+ onRenamed(next: { name: string; displayName: string }): void;
27
+ }) {
28
+ const nameId = useId();
29
+ const displayId = useId();
30
+ const toast = useLibraryToast();
31
+ const [name, setName] = useState(plugin.name);
32
+ const [displayName, setDisplayName] = useState(plugin.displayName ?? plugin.name);
33
+ const [busy, setBusy] = useState(false);
34
+ const [error, setError] = useState<string | null>(null);
35
+
36
+ const trimmedName = name.trim();
37
+ const identifierChanges = trimmedName !== plugin.name;
38
+ // The same three rules the server applies — the identifier shape, the
39
+ // reserved prefix, and that the name is its own slug (the marketplace keys
40
+ // on a 64-character slug; a longer name would be one thing here and
41
+ // another everywhere it is published) — and, like the server, only to a
42
+ // NEW identifier: the current one is whatever the manifest says, and a
43
+ // name that predates a rule must not block a display-name change.
44
+ const nameError = !identifierChanges || !trimmedName
45
+ ? null
46
+ : !IDENTIFIER_RE.test(trimmedName)
47
+ ? 'Lowercase letters, digits and single hyphens, like sales-team.'
48
+ : trimmedName.startsWith(PERSONAL_PLUGIN_PREFIX)
49
+ ? `"${PERSONAL_PLUGIN_PREFIX}" is reserved for personal folders. Pick another identifier.`
50
+ : pluginManifestName(trimmedName) !== trimmedName
51
+ ? 'Too long: an identifier is at most 64 characters.'
52
+ : null;
53
+ const changed = identifierChanges || displayName.trim() !== (plugin.displayName ?? plugin.name);
54
+ const canSubmit = trimmedName.length > 0 && nameError === null && changed && !busy;
55
+
56
+ async function submit() {
57
+ if (!canSubmit) return;
58
+ setBusy(true);
59
+ setError(null);
60
+ try {
61
+ const next = await renamePlugin(plugin.name, {
62
+ ...(identifierChanges ? { name: trimmedName } : {}),
63
+ displayName: displayName.trim(),
64
+ });
65
+ toast(identifierChanges ? `Renamed ${plugin.name} to ${next.name}.` : `Renamed to ${next.displayName}.`);
66
+ onRenamed(next);
67
+ onClose();
68
+ } catch (err) {
69
+ setError(err instanceof Error ? err.message : "Couldn't rename the plugin.");
70
+ setBusy(false);
71
+ }
72
+ }
73
+
74
+ return (
75
+ <Dialog
76
+ open
77
+ onClose={onClose}
78
+ title={`Rename ${plugin.displayName ?? plugin.name}`}
79
+ size="md"
80
+ busy={busy}
81
+ footer={
82
+ <>
83
+ <Button variant="quiet" onClick={onClose} disabled={busy}>
84
+ Cancel
85
+ </Button>
86
+ <Button onClick={() => void submit()} disabled={!canSubmit}>
87
+ {busy ? 'Renaming…' : 'Rename'}
88
+ </Button>
89
+ </>
90
+ }
91
+ >
92
+ <div className="space-y-3">
93
+ <div>
94
+ <label htmlFor={displayId} className="mb-1 block text-detail font-medium text-ink">
95
+ Display name
96
+ </label>
97
+ <TextField
98
+ id={displayId}
99
+ value={displayName}
100
+ onChange={(e) => setDisplayName(e.target.value)}
101
+ placeholder={plugin.folders[0]?.split('/').pop() ?? plugin.name}
102
+ />
103
+ <p className="mt-1 text-meta text-ink-faint">What people see in the sidebar and on this page.</p>
104
+ </div>
105
+ <div>
106
+ <label htmlFor={nameId} className="mb-1 block text-detail font-medium text-ink">
107
+ Identifier
108
+ </label>
109
+ <TextField
110
+ id={nameId}
111
+ value={name}
112
+ onChange={(e) => setName(e.target.value)}
113
+ aria-invalid={nameError ? true : undefined}
114
+ className="font-mono"
115
+ />
116
+ <p className="mt-1 text-meta text-ink-faint">
117
+ {nameError ??
118
+ 'The name agents install it by, and the one grants use: plugin/<identifier>/read.'}
119
+ </p>
120
+ </div>
121
+ {identifierChanges && !nameError && (
122
+ <Banner tone="wait" role="status">
123
+ Every grant of <span className="font-mono">plugin/{plugin.name}/…</span> in the knowledge base is
124
+ rewritten to <span className="font-mono">plugin/{trimmedName}/…</span> in the same change. The folder
125
+ stays where it is.
126
+ </Banner>
127
+ )}
128
+ {error && (
129
+ <Banner tone="danger" role="alert">
130
+ {error}
131
+ </Banner>
132
+ )}
133
+ </div>
134
+ </Dialog>
135
+ );
136
+ }
@@ -0,0 +1,91 @@
1
+ import { useMemo } from 'react';
2
+ import { useLocation, useNavigate } from 'react-router-dom';
3
+ import { DEFAULT_BRANCH, SKILLS_DIR } from '@bevel-software/platform-shared';
4
+ import { useWorkspace } from '../../workspace/state/workspace.context';
5
+ import { findKbRoot } from '../../workspace/utils/fileTree';
6
+ import { KB_ROUTE_PREFIX, kbFileUrl, safeDecode } from '../../workspace/routing/kb-routes';
7
+ import { useMergedWorkspaceTree } from '../../workspace/hooks/useMergedWorkspaceTree';
8
+ import {
9
+ FileTreeNode,
10
+ TreeChrome,
11
+ UploadNotices,
12
+ type TreeNav,
13
+ } from '../../workspace/components/FileExplorer';
14
+
15
+ /**
16
+ * The Skills section of the Library's nav: the shared `Skills/` root as a
17
+ * file tree, made of the SAME rows as Knowledge's explorer — right-click menu
18
+ * (new file, new folder, rename, delete, manage access, download), drag to
19
+ * move, drop to upload, the caller's proposed files shown in accent. One tree
20
+ * component in the app, holding a different root.
21
+ *
22
+ * The root is a collapsible folder row called Skills, exactly as Knowledge
23
+ * and Data are top-level folders in the Knowledge explorer: open by default
24
+ * with its scopes collapsed under it, a drop target for uploads into
25
+ * `Skills/`, the create buttons on hover, the folder's menu on right-click —
26
+ * minus what a platform-owned root must not offer (`FileTreeNode.reserved`:
27
+ * no rename, delete, drag or pin).
28
+ *
29
+ * Two things differ from Knowledge, and both are the surroundings' (see
30
+ * `TreeChrome`), not the rows':
31
+ *
32
+ * - A click opens the file on its SKILL PAGE, here in Skills & Tools — at
33
+ * the item's canonical default-branch URL, whatever branch is checked
34
+ * out. The Library speaks the default branch everywhere; this is no
35
+ * exception.
36
+ * - The current row is the file the URL names, not the pane workspace's
37
+ * open tab, which the Library never sets.
38
+ *
39
+ * Renders nothing while the tree is loading or when the caller can read no
40
+ * part of the root — an empty Skills folder would be a question, not a
41
+ * section.
42
+ */
43
+ export function SkillsTree() {
44
+ const { kbDirName } = useWorkspace();
45
+ const { tree, suggestionOnlyPaths } = useMergedWorkspaceTree();
46
+ const location = useLocation();
47
+ const navigate = useNavigate();
48
+
49
+ const root = useMemo(() => {
50
+ const kids = findKbRoot(tree)?.children;
51
+ return kids?.find((c) => c.type === 'directory' && c.name === SKILLS_DIR) ?? null;
52
+ }, [tree]);
53
+
54
+ const nav = useMemo<TreeNav>(
55
+ () => ({
56
+ activePath: activeWorkspacePath(location.pathname, kbDirName),
57
+ open: (path) => navigate(kbFileUrl(DEFAULT_BRANCH, path)),
58
+ }),
59
+ [location.pathname, kbDirName, navigate],
60
+ );
61
+
62
+ if (!root) return null;
63
+
64
+ return (
65
+ <TreeChrome nav={nav} suggestionOnlyPaths={suggestionOnlyPaths}>
66
+ {/* A right-click that lands between the tree's rows is the tree's, not
67
+ the plugin nav's behind it: with nothing wired for the gap the
68
+ browser's own menu is the honest answer, as in Knowledge. The rows
69
+ stop their own events before reaching here. */}
70
+ <div data-testid="skills-tree" onContextMenu={(e) => e.stopPropagation()}>
71
+ <UploadNotices />
72
+ <FileTreeNode entry={root} depth={0} reserved collapseChildren />
73
+ </div>
74
+ </TreeChrome>
75
+ );
76
+ }
77
+
78
+ /**
79
+ * The workspace-relative path a Library URL names, or null. Library item
80
+ * pages live at `/workspace/<default>/<kbDir>/...` — the inverse of
81
+ * `kbFileUrl`, segment by segment. Any other URL (the index, a lens, a
82
+ * plugin page) names no file, so no row is current.
83
+ */
84
+ function activeWorkspacePath(pathname: string, kbDirName: string | null): string | null {
85
+ const prefix = `${KB_ROUTE_PREFIX}/`;
86
+ if (!pathname.startsWith(prefix)) return null;
87
+ const [branch, ...rest] = pathname.slice(prefix.length).split('/').map(safeDecode);
88
+ if (branch !== DEFAULT_BRANCH || rest.length < 2) return null;
89
+ if (kbDirName !== null && rest[0] !== kbDirName) return null;
90
+ return rest.join('/');
91
+ }
@@ -4,6 +4,7 @@ import type { GemState } from '../utils/status';
4
4
  const TONE: Record<GemState, string> = {
5
5
  ok: 'bg-ok',
6
6
  warn: 'bg-wait-dot',
7
+ urgent: 'bg-urgent',
7
8
  err: 'bg-danger',
8
9
  };
9
10
 
@@ -7,6 +7,7 @@ import { Banner, Button, Dialog, IconButton } from '../../../shared/components';
7
7
  import { pathForPluginsIndex } from '../routes/library-paths';
8
8
  import type { LibraryItem } from '../state/library-data';
9
9
  import { removeLibraryItem } from '../services/library.api';
10
+ import { unlinkSkill } from '../services/plugins.api';
10
11
  import { LibraryCard } from './LibraryCard';
11
12
 
12
13
  /**
@@ -111,6 +112,7 @@ export function CardGrid({
111
112
  items,
112
113
  onOpen,
113
114
  onRemove,
115
+ canRemove,
114
116
  }: {
115
117
  items: LibraryItem[];
116
118
  onOpen(item: LibraryItem): void;
@@ -121,6 +123,12 @@ export function CardGrid({
121
123
  * card is one <button>, and a button inside a button is not HTML.
122
124
  */
123
125
  onRemove?(item: LibraryItem): void;
126
+ /**
127
+ * Per item, whether the verb would succeed — a link into a plugin whose
128
+ * links live in an external format cannot be removed here. Absent: every
129
+ * item. A verb the server would refuse is not offered.
130
+ */
131
+ canRemove?(item: LibraryItem): boolean;
124
132
  }) {
125
133
  return (
126
134
  <div
@@ -156,6 +164,7 @@ export function CardGrid({
156
164
  owned={item.owned}
157
165
  status={item.status}
158
166
  version={item.version}
167
+ lifecycle={item.lifecycle}
159
168
  pending={
160
169
  item.pending && {
161
170
  authorName: item.pending.authorName,
@@ -167,7 +176,7 @@ export function CardGrid({
167
176
  );
168
177
  // A pending proposal is not IN the place yet — there is nothing to
169
178
  // remove; declining it lives with the review.
170
- if (!onRemove || item.pending) return card;
179
+ if (!onRemove || item.pending || (canRemove && !canRemove(item))) return card;
171
180
  return (
172
181
  // `grid`, not a plain block: the wrapper takes the card's place as
173
182
  // the grid item, and only a grid (or flex) container stretches its
@@ -199,16 +208,24 @@ export function CardGrid({
199
208
  * The "are you sure" a removal deserves: deleting a skill or tool from a
200
209
  * plugin takes it from EVERYONE in the plugin, not from a personal shelf, and
201
210
  * there is no undo shortcut — the content survives only in git history.
211
+ *
212
+ * A LINKED skill is the other case: it lives elsewhere and the plugin only
213
+ * points at it, so "remove" means unlink — the manifest entry and the
214
+ * plugin's grant go, the skill stays where it is. Sending a link through the
215
+ * delete path would delete a shared skill (or be refused by its own rules).
202
216
  */
203
217
  export function RemoveLibraryItemDialog({
204
218
  item,
205
219
  place,
220
+ linked = false,
206
221
  onClose,
207
222
  onRemoved,
208
223
  }: {
209
224
  item: LibraryItem;
210
225
  /** Where it is being removed from, for the copy: a plugin name, or "your space". */
211
226
  place: string;
227
+ /** The item is in `place` by LINK — remove the link, not the item. `place` is then the plugin. */
228
+ linked?: boolean;
212
229
  onClose(): void;
213
230
  /** Fired after the delete lands; the host page reloads and says so. */
214
231
  onRemoved(): void;
@@ -221,7 +238,8 @@ export function RemoveLibraryItemDialog({
221
238
  setBusy(true);
222
239
  setError(null);
223
240
  try {
224
- await removeLibraryItem(item.path);
241
+ if (linked) await unlinkSkill(place, item.path);
242
+ else await removeLibraryItem(item.path);
225
243
  onRemoved();
226
244
  onClose();
227
245
  } catch (err) {
@@ -236,7 +254,7 @@ export function RemoveLibraryItemDialog({
236
254
  <Dialog
237
255
  open
238
256
  onClose={onClose}
239
- title={`Remove ${item.name}?`}
257
+ title={linked ? `Unlink ${item.name}?` : `Remove ${item.name}?`}
240
258
  size="md"
241
259
  busy={busy}
242
260
  footer={
@@ -245,15 +263,17 @@ export function RemoveLibraryItemDialog({
245
263
  Cancel
246
264
  </Button>
247
265
  <Button variant="danger" onClick={() => void remove()} disabled={busy}>
248
- {busy ? 'Removing…' : 'Remove'}
266
+ {busy ? (linked ? 'Unlinking…' : 'Removing…') : linked ? 'Unlink' : 'Remove'}
249
267
  </Button>
250
268
  </>
251
269
  }
252
270
  >
253
271
  <p className="text-ui text-ink-muted">
254
- {item.kind === 'skill'
255
- ? `This deletes the skill and its files from ${place}. Everyone here loses it the next time their agent connects.`
256
- : `This deletes the tool and its connection settings from ${place}. Skills here that need it will ask for setup again.`}
272
+ {linked
273
+ ? `This removes the link from ${place}. The skill itself stays where it lives; ${place}'s members stop seeing it here.`
274
+ : item.kind === 'skill'
275
+ ? `This deletes the skill and its files from ${place}. Everyone here loses it the next time their agent connects.`
276
+ : `This deletes the tool and its connection settings from ${place}. Skills here that need it will ask for setup again.`}
257
277
  </p>
258
278
  {error && (
259
279
  <Banner tone="danger" role="alert" className="mt-3">
@@ -276,6 +296,7 @@ export function PluginItemSections({
276
296
  toolItems,
277
297
  onOpen,
278
298
  onRemove,
299
+ canRemove,
279
300
  emptySkills,
280
301
  emptyTools = 'No tools yet.',
281
302
  hideEmpty = false,
@@ -287,6 +308,8 @@ export function PluginItemSections({
287
308
  onOpen(item: LibraryItem): void;
288
309
  /** See {@link CardGrid} — present only when the caller manages this place. */
289
310
  onRemove?(item: LibraryItem): void;
311
+ /** See {@link CardGrid}. */
312
+ canRemove?(item: LibraryItem): boolean;
290
313
  /**
291
314
  * A plain sentence, or an `EmptySkillsNudge`. A string still gets the band's
292
315
  * standard paragraph; a node is trusted to bring its own — the nudge carries
@@ -329,7 +352,7 @@ export function PluginItemSections({
329
352
  emptySkills
330
353
  )
331
354
  ) : (
332
- <CardGrid items={skillItems} onOpen={onOpen} onRemove={onRemove} />
355
+ <CardGrid items={skillItems} onOpen={onOpen} onRemove={onRemove} canRemove={canRemove} />
333
356
  )}
334
357
  </PluginSection>
335
358
  )}
@@ -339,7 +362,7 @@ export function PluginItemSections({
339
362
  {toolItems.length === 0 ? (
340
363
  <p className="text-ui text-ink-faint">{emptyTools}</p>
341
364
  ) : (
342
- <CardGrid items={toolItems} onOpen={onOpen} onRemove={onRemove} />
365
+ <CardGrid items={toolItems} onOpen={onOpen} onRemove={onRemove} canRemove={canRemove} />
343
366
  )}
344
367
  </PluginSection>
345
368
  )}
@@ -0,0 +1,218 @@
1
+ import { useMemo, useState } from 'react';
2
+ import { Link } from 'react-router-dom';
3
+ import { Badge, Button } from '../../../../shared/components';
4
+ import { useLibrary } from '../../state/library-data';
5
+ import { useLibraryToast } from '../../state/toast.context';
6
+ import { NeedsSkillWriteError, linkSkill, repairSkillLink, unlinkSkill } from '../../services/plugins.api';
7
+ import { requestSkillAccess, type PluginMembership } from '../../services/library.api';
8
+ import { pathForPlugin } from '../../routes/library-paths';
9
+ import { StatusDot } from '../StatusDot';
10
+ import { cn } from '../../../../lib/utils';
11
+
12
+ /**
13
+ * "In plugins" — every plugin this skill belongs to, and the two ways the
14
+ * relationship is managed from the skill's side.
15
+ *
16
+ * A row is INLINE (the skill sits in the plugin's folder) or LINKED (the
17
+ * plugin's manifest points at it). A link is healthy when the skill's own
18
+ * access rules still name the plugin's principal; when a hand edit removed
19
+ * that grant, the row shows the amber dot and — to someone who can edit the
20
+ * skill — a Repair button, because until it is back the plugin's members
21
+ * cannot read the skill. Unlink is the plugin MANAGER's verb (it edits the
22
+ * plugin's manifest), so it appears only on plugins the caller manages.
23
+ *
24
+ * "Add to plugin" links this skill into a plugin the caller manages. It
25
+ * needs write on the skill too; a refusal of that shape offers the request.
26
+ */
27
+ export function SharedViaPlugins({
28
+ skillName,
29
+ skillPath,
30
+ memberships,
31
+ owned,
32
+ onChanged,
33
+ }: {
34
+ skillName: string;
35
+ skillPath: string;
36
+ memberships: PluginMembership[];
37
+ /** The caller may edit the skill (its SKILL.md) — the repair verb. */
38
+ owned: boolean;
39
+ onChanged(): void;
40
+ }) {
41
+ const data = useLibrary();
42
+ const toast = useLibraryToast();
43
+ const [busy, setBusy] = useState<string | null>(null);
44
+ const [adding, setAdding] = useState(false);
45
+ const [needsWrite, setNeedsWrite] = useState<'ask' | 'requested' | null>(null);
46
+
47
+ // Plugins the caller manages AND whose links this platform writes: a
48
+ // plugin read from an external format has no link to add or remove here.
49
+ const managed = useMemo(
50
+ () =>
51
+ new Set(
52
+ data.pluginSummaries.filter((p) => p.canWrite && p.linksAreManaged !== false).map((p) => p.name),
53
+ ),
54
+ [data.pluginSummaries],
55
+ );
56
+ // A retired skill is never shared onward — the link API refuses it, so the
57
+ // chooser offers nothing rather than a list of refusals.
58
+ const retired = useMemo(
59
+ () => data.items.some((i) => i.kind === 'skill' && i.id === skillName && i.lifecycle === 'retired'),
60
+ [data.items, skillName],
61
+ );
62
+ const addable = useMemo(
63
+ () => (retired ? [] : [...managed].filter((name) => !memberships.some((m) => m.name === name)).sort()),
64
+ [managed, memberships, retired],
65
+ );
66
+
67
+ async function run(label: string, op: () => Promise<unknown>, done: string) {
68
+ setBusy(label);
69
+ try {
70
+ await op();
71
+ toast(done);
72
+ onChanged();
73
+ } catch (err) {
74
+ if (err instanceof NeedsSkillWriteError) setNeedsWrite('ask');
75
+ else toast(err instanceof Error ? err.message : `Couldn't ${label}.`, 'danger');
76
+ } finally {
77
+ setBusy(null);
78
+ }
79
+ }
80
+
81
+ if (memberships.length === 0 && addable.length === 0) return null;
82
+
83
+ return (
84
+ <section className="mt-6" data-testid="shared-via-plugins">
85
+ <h2 className="mb-2.5 text-label font-semibold uppercase text-ink-faint">In plugins</h2>
86
+ <div className="grid gap-2">
87
+ {memberships.length === 0 && (
88
+ <p className="text-detail text-ink-faint">This skill is in no plugin yet.</p>
89
+ )}
90
+ {memberships.map((m) => {
91
+ const broken = m.linked && !m.granted;
92
+ return (
93
+ <div
94
+ key={m.name}
95
+ className="flex items-center gap-3 rounded-md border border-line bg-sunken px-3 py-2"
96
+ >
97
+ <div className="min-w-0">
98
+ <div className="flex items-center gap-1.5">
99
+ <Link to={pathForPlugin(m.name)} className="truncate text-detail font-semibold text-ink underline-offset-2 hover:underline">
100
+ {m.name}
101
+ </Link>
102
+ <Badge tone="outline" size="xs" className="shrink-0 uppercase">
103
+ {m.linked ? 'Linked' : 'Inline'}
104
+ </Badge>
105
+ </div>
106
+ <small className={cn('block text-meta', broken ? 'text-urgent' : 'text-ink-faint')}>
107
+ {broken
108
+ ? owned
109
+ ? `Needs setup: ${m.name}'s members can't read this skill until the link is repaired.`
110
+ : `Needs setup: ${m.name}'s members can't read this skill. Ask an editor to repair the link.`
111
+ : m.linked
112
+ ? `${m.name}'s members can read it; its managers can edit it.`
113
+ : `Lives in ${m.name}'s folder.`}
114
+ </small>
115
+ </div>
116
+ <div className="ml-auto flex shrink-0 items-center gap-2">
117
+ {broken && <StatusDot state="urgent" />}
118
+ {broken && owned && (
119
+ <Button
120
+ variant="outline"
121
+ size="tiny"
122
+ disabled={busy !== null}
123
+ onClick={() =>
124
+ void run('repair', () => repairSkillLink(m.name, skillPath), `${m.name} can read ${skillName} again.`)
125
+ }
126
+ >
127
+ Repair
128
+ </Button>
129
+ )}
130
+ {m.linked && managed.has(m.name) && (
131
+ <Button
132
+ variant="quiet"
133
+ size="tiny"
134
+ disabled={busy !== null}
135
+ onClick={() =>
136
+ void run('unlink', () => unlinkSkill(m.name, skillPath), `${skillName} is no longer in ${m.name}.`)
137
+ }
138
+ >
139
+ Unlink
140
+ </Button>
141
+ )}
142
+ </div>
143
+ </div>
144
+ );
145
+ })}
146
+ </div>
147
+
148
+ {addable.length > 0 && (
149
+ <div className="mt-2.5">
150
+ {needsWrite === 'requested' ? (
151
+ <span className="text-detail text-ink-faint">Asked the skill's editors for write access.</span>
152
+ ) : needsWrite === 'ask' ? (
153
+ <div className="flex flex-wrap items-center gap-2">
154
+ <span className="text-detail text-wait">
155
+ {"You can't change who may read this skill yet."}
156
+ </span>
157
+ <Button
158
+ variant="outline"
159
+ size="tiny"
160
+ disabled={busy !== null}
161
+ onClick={() =>
162
+ void (async () => {
163
+ setBusy('request');
164
+ try {
165
+ await requestSkillAccess(skillName);
166
+ setNeedsWrite('requested');
167
+ } catch (err) {
168
+ toast(err instanceof Error ? err.message : "Couldn't request access.", 'danger');
169
+ } finally {
170
+ setBusy(null);
171
+ }
172
+ })()
173
+ }
174
+ >
175
+ Request write access
176
+ </Button>
177
+ </div>
178
+ ) : adding ? (
179
+ <div className="flex flex-wrap items-center gap-2">
180
+ <label className="text-detail text-ink-muted" htmlFor="add-to-plugin-select">
181
+ Add to
182
+ </label>
183
+ <select
184
+ id="add-to-plugin-select"
185
+ className="rounded-md border border-line bg-surface px-2 py-1 text-ui text-ink"
186
+ defaultValue=""
187
+ disabled={busy !== null}
188
+ onChange={(e) => {
189
+ const name = e.target.value;
190
+ if (!name) return;
191
+ void run('link', () => linkSkill(name, skillPath), `${skillName} is now in ${name}.`).then(() =>
192
+ setAdding(false),
193
+ );
194
+ }}
195
+ >
196
+ <option value="" disabled>
197
+ Choose a plugin…
198
+ </option>
199
+ {addable.map((name) => (
200
+ <option key={name} value={name}>
201
+ {name}
202
+ </option>
203
+ ))}
204
+ </select>
205
+ <Button variant="quiet" size="tiny" onClick={() => setAdding(false)}>
206
+ Cancel
207
+ </Button>
208
+ </div>
209
+ ) : (
210
+ <Button variant="outline" size="sm" onClick={() => setAdding(true)}>
211
+ Add to plugin…
212
+ </Button>
213
+ )}
214
+ </div>
215
+ )}
216
+ </section>
217
+ );
218
+ }