@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
@@ -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
@@ -1,21 +1,33 @@
1
+ import { PR_STALE_EVENT } from '../../../core/events';
1
2
  import { useCallback, useContext, useEffect, useMemo, useState, type ReactNode, } from 'react';
2
3
  import { LibraryContext } from './library-context';
3
- import { pluginOfPath, isPersonalPluginFolder } from '@bevel-software/platform-shared';
4
+ import { SKILLS_DIR } from '@bevel-software/platform-shared';
5
+ import { pluginNameForPath } from '../utils/plugin-summary';
6
+ import type { PluginMembership } from '../services/library.api';
4
7
 
5
8
  /**
6
- * The plugin a card files under — with personal folders mapped to `null`, the
7
- * "yours alone" bucket. A personal folder (`Plugins/personal-<id>/`) is where
8
- * a person's own skills live; it is a place, not a plugin, and the only
9
- * personal items a caller can ever read are their own (the folder's seeded
10
- * access.md names nobody else), so `null` here always means "yours".
9
+ * The plugin a card files under, by IDENTITY — the server's own answer for a
10
+ * skill it decorated (the inline membership), else the folder resolved
11
+ * through the plugin summaries (see `pluginNameForPath`). Personal folders
12
+ * map to `null`, the "yours alone" bucket: a personal folder is a place, not
13
+ * a plugin, and the only personal items a caller can ever read are their own.
11
14
  */
12
- function displayPluginOf(path: string): string | null {
13
- const plugin = pluginOfPath(path);
14
- return plugin !== null && isPersonalPluginFolder(plugin) ? null : plugin;
15
+ function pluginOfItem(
16
+ path: string,
17
+ memberships: readonly { name: string; linked: boolean }[] | undefined,
18
+ summaries: readonly PluginSummary[],
19
+ ): string | null {
20
+ return memberships?.find((m) => !m.linked)?.name ?? pluginNameForPath(path, summaries);
21
+ }
22
+
23
+ /** Under the shared `Skills/` root — owned by a scope, not by a person or a plugin folder. */
24
+ function isSharedPath(path: string): boolean {
25
+ return path === SKILLS_DIR || path.startsWith(`${SKILLS_DIR}/`);
15
26
  }
16
27
  import { useLibraryData, type LibraryData } from '../hooks/useLibraryData';
17
28
  import { listPlugins, type PluginSummary } from '../services/plugins.api';
18
29
  import {
30
+ isInPlugin,
19
31
  neededToolsFor,
20
32
  skillStatus,
21
33
  toolStatus,
@@ -48,6 +60,12 @@ export interface LibraryItem {
48
60
  status: AttentionStatus;
49
61
  /** Folder plugin from the KB path, or null when the item is in none. */
50
62
  plugin: string | null;
63
+ /** Under the shared `Skills/` root — see `LibraryFilterable.shared`. */
64
+ shared?: boolean;
65
+ /** Every plugin holding a skill, inline or linked (skills only). */
66
+ plugins?: PluginMembership[];
67
+ /** A skill's governance lifecycle (`metadata.lifecycle`), when declared. */
68
+ lifecycle?: string;
51
69
  /** Repo-root-relative path — the skill's folder, or the `.tool` file. */
52
70
  path: string;
53
71
  /**
@@ -86,6 +104,7 @@ export interface LibraryContextValue extends LibraryData {
86
104
 
87
105
  export function LibraryProvider({ children }: { children: ReactNode }) {
88
106
  const data = useLibraryData();
107
+ const { reload } = data;
89
108
  const [pluginSummaries, setPluginSummaries] = useState<PluginSummary[]>([]);
90
109
  const [pluginsLoading, setPluginsLoading] = useState(true);
91
110
  const [pluginsError, setPluginsError] = useState<string | null>(null);
@@ -120,7 +139,10 @@ export function LibraryProvider({ children }: { children: ReactNode }) {
120
139
  name: s.name,
121
140
  description: s.description,
122
141
  owned: data.ownedSkills.has(s.name),
123
- plugin: displayPluginOf(s.path),
142
+ plugin: pluginOfItem(s.path, s.plugins, pluginSummaries),
143
+ shared: isSharedPath(s.path),
144
+ plugins: s.plugins ?? [],
145
+ lifecycle: s.lifecycle,
124
146
  path: s.path,
125
147
  version: s.version,
126
148
  status: skillStatus(
@@ -144,7 +166,8 @@ export function LibraryProvider({ children }: { children: ReactNode }) {
144
166
  name: s.name,
145
167
  description: s.description,
146
168
  owned: false,
147
- plugin: displayPluginOf(s.path),
169
+ plugin: pluginOfItem(s.path, undefined, pluginSummaries),
170
+ shared: isSharedPath(s.path),
148
171
  path: s.path,
149
172
  version: s.version,
150
173
  status: { state: 'ok', text: 'In review' },
@@ -163,7 +186,7 @@ export function LibraryProvider({ children }: { children: ReactNode }) {
163
186
  // manual yet (see report) — the card stays clean; detail lives behind it.
164
187
  description: '',
165
188
  owned: t.canWrite,
166
- plugin: displayPluginOf(t.path),
189
+ plugin: pluginOfItem(t.path, undefined, pluginSummaries),
167
190
  path: t.path,
168
191
  status: toolStatus(t),
169
192
  }));
@@ -174,6 +197,7 @@ export function LibraryProvider({ children }: { children: ReactNode }) {
174
197
  data.tools,
175
198
  data.ownedSkills,
176
199
  data.allowedToolsBySkill,
200
+ pluginSummaries,
177
201
  ]);
178
202
 
179
203
  // The loading flag is raised HERE rather than in the effect: `useState(true)`
@@ -185,16 +209,39 @@ export function LibraryProvider({ children }: { children: ReactNode }) {
185
209
  setPluginsRevision((r) => r + 1);
186
210
  }, []);
187
211
 
212
+ // ONE reload for the whole Library. The plugin summaries carry counts and
213
+ // verdicts derived from the same knowledge base as the catalog — how many
214
+ // skills a plugin holds, how many of its links are broken, who may read
215
+ // it — so a page that refreshes the catalog after a link, a repair or an
216
+ // access edit must refresh the summaries too, or the sidebar count and the
217
+ // plugin page's banner keep the number from before the change.
218
+ const reloadAll = useCallback(() => {
219
+ reload();
220
+ reloadPlugins();
221
+ }, [reload, reloadPlugins]);
222
+
223
+ // The catalog carries its own view of open change requests (proposals,
224
+ // review boxes). The shell's change-request provider refreshes on this
225
+ // event; so does the whole Library, or the two would disagree after a
226
+ // proposal lands or is resolved — and a merged change can move plugin
227
+ // links and access, so the summaries refresh with the catalog here too.
228
+ useEffect(() => {
229
+ const onStale = () => reloadAll();
230
+ window.addEventListener(PR_STALE_EVENT, onStale);
231
+ return () => window.removeEventListener(PR_STALE_EVENT, onStale);
232
+ }, [reloadAll]);
233
+
188
234
  const value = useMemo(
189
235
  (): LibraryContextValue => ({
190
236
  ...data,
237
+ reload: reloadAll,
191
238
  items,
192
239
  pluginSummaries,
193
240
  pluginsLoading,
194
241
  pluginsError,
195
242
  reloadPlugins,
196
243
  }),
197
- [data, items, pluginSummaries, pluginsLoading, pluginsError, reloadPlugins],
244
+ [data, reloadAll, items, pluginSummaries, pluginsLoading, pluginsError, reloadPlugins],
198
245
  );
199
246
 
200
247
  return <LibraryContext.Provider value={value}>{children}</LibraryContext.Provider>;
@@ -228,17 +275,63 @@ export function workspaceHasNoPlugins(lib: LibraryContextValue): boolean {
228
275
  }
229
276
 
230
277
  /**
231
- * How many of a plugin's integrations need setup — the amber count on the
232
- * sidebar row and the plugin page's banner, computed from one place so the two
233
- * can never disagree.
278
+ * How much of a plugin needs a person — the count on the sidebar row, the
279
+ * index badge and the plugin page's banners, computed from one place so they
280
+ * can never disagree. Two kinds, added together:
281
+ *
282
+ * - integrations that need setup (`brokenLinksOf` subtracted from this
283
+ * gives that number alone);
284
+ * - linked skills the plugin's members cannot read (`brokenLinksOf`).
285
+ *
286
+ * A skill that reports `warn` about a tool is NOT counted: it is warning
287
+ * about the very integration already counted here, so counting both would
288
+ * double every broken connection. Pending change requests are a review
289
+ * concern, not a setup one, and belong to a different surface.
290
+ */
291
+ export interface PluginAttention {
292
+ /** Everything that needs a person: integrations to set up plus broken links. */
293
+ total: number;
294
+ /** The broken-link part alone — what turns the count orange. */
295
+ brokenLinks: number;
296
+ }
297
+
298
+ export function attentionOf(
299
+ items: LibraryItem[],
300
+ plugin: string,
301
+ summaries: readonly Pick<PluginSummary, 'name' | 'brokenLinks'>[] = [],
302
+ ): PluginAttention {
303
+ // One pass for the links, returned beside the total: every caller wants
304
+ // both, and computing the part again for the tone would filter the whole
305
+ // catalog a second time per plugin.
306
+ const brokenLinks = brokenLinksOf(items, plugin, summaries);
307
+ const integrations = items.filter(
308
+ (i) => isInPlugin(i, plugin) && i.kind === 'integration' && i.status.state !== 'ok',
309
+ ).length;
310
+ return { total: integrations + brokenLinks, brokenLinks };
311
+ }
312
+
313
+ /**
314
+ * How many of `plugin`'s LINKED skills its members cannot read: the link is
315
+ * in the manifest but the skill folder no longer grants the plugin's readers.
316
+ * Counted apart from the integrations because it is a different kind of
317
+ * problem — a tool that needs setup blocks the reader's own use; a link
318
+ * without its grant blocks every member of the plugin, right now — and the
319
+ * sidebar and the plugin page rank it above amber for that reason.
234
320
  *
235
- * Only integrations count. A skill that reports `warn` is warning about the
236
- * very integration already counted here, so counting both would double every
237
- * broken connection; pending change requests are a review concern, not a setup
238
- * one, and belong to a different surface.
321
+ * The SERVER's count wins when the summary carries one: it comes from the
322
+ * unfiltered link index, so a manager whom the missing grant locks out of
323
+ * the skill still sees it. The caller's own catalog is only the fallback for
324
+ * an older server — it cannot list a skill the caller may not read, which is
325
+ * exactly the skill this is about.
239
326
  */
240
- export function attentionOf(items: LibraryItem[], plugin: string): number {
327
+ export function brokenLinksOf(
328
+ items: LibraryItem[],
329
+ plugin: string,
330
+ summaries: readonly Pick<PluginSummary, 'name' | 'brokenLinks'>[] = [],
331
+ ): number {
332
+ const served = summaries.find((s) => s.name === plugin)?.brokenLinks;
333
+ if (served !== undefined) return served;
241
334
  return items.filter(
242
- (i) => i.plugin === plugin && i.kind === 'integration' && i.status.state !== 'ok',
335
+ (i) => i.kind === 'skill' && (i.plugins ?? []).some((m) => m.name === plugin && m.linked && m.granted === false),
243
336
  ).length;
244
337
  }
@@ -1,5 +1,41 @@
1
+ import { isPersonalPluginFolder, pluginOfPath } from '@bevel-software/platform-shared';
1
2
  import type { PluginPrincipals, PluginSummary } from '../services/plugins.api';
2
3
 
4
+ /**
5
+ * The plugin a repository path sits in, by IDENTITY: the summary whose
6
+ * folder holds the path (deepest wins, so a nested plugin beats the scope
7
+ * around it). Before the summaries have loaded — or for a path under a
8
+ * folder the catalog does not list — the folder name stands in, which is
9
+ * what every plugin was called before the manifest became the identity. A
10
+ * personal folder is a place, not a plugin: null.
11
+ */
12
+ export function pluginNameForPath(
13
+ repoPath: string,
14
+ summaries: readonly Pick<PluginSummary, 'name' | 'folders'>[],
15
+ ): string | null {
16
+ const folder = pluginOfPath(repoPath);
17
+ if (folder === null) return null;
18
+ // The catalog is the authority: whatever folder it lists as holding the
19
+ // path names the plugin. Only a path no listed folder holds falls back to
20
+ // the folder name — and a personal shelf, which the catalog never lists,
21
+ // to null.
22
+ let best: { name: string; length: number } | null = null;
23
+ for (const s of summaries) {
24
+ for (const f of s.folders) {
25
+ if ((repoPath === f || repoPath.startsWith(`${f}/`)) && (!best || f.length > best.length)) {
26
+ best = { name: s.name, length: f.length };
27
+ }
28
+ }
29
+ }
30
+ if (best) return best.name;
31
+ return isPersonalPluginFolder(folder) ? null : folder;
32
+ }
33
+
34
+ /** What a plugin is called on screen — its display name, else its identity. */
35
+ export function pluginLabel(name: string, summaries: readonly Pick<PluginSummary, 'name' | 'displayName'>[]): string {
36
+ return summaries.find((s) => s.name === name)?.displayName || name;
37
+ }
38
+
3
39
  /**
4
40
  * How a plugin describes its membership in prose.
5
41
  *
@@ -1,4 +1,5 @@
1
- import type { ToolSecrets, ToolVarStatus } from '../../secrets-vault/services/tool-secrets.api';
1
+ import { formatRelativeTime } from '../../../lib/utils';
2
+ import type { ProbeVerdict, ToolSecrets, ToolVarStatus } from '../../secrets-vault/services/tool-secrets.api';
2
3
 
3
4
  /**
4
5
  * Status derivation for the Library. Everything the cards, gems and loadout
@@ -11,29 +12,62 @@ import type { ToolSecrets, ToolVarStatus } from '../../secrets-vault/services/to
11
12
  */
12
13
 
13
14
  /**
14
- * Three states, and no fourth.
15
+ * Four states, and no fifth.
15
16
  *
16
17
  * There used to be an `off` — "not set up yet", drawn in grey. Grey reads as
17
18
  * *disabled*, or as *not your problem*: an unconfigured integration looked like
18
19
  * furniture next to the amber ones, when in fact it is the state that most
19
20
  * needs somebody. Anything that needs a person is amber; anything that was
20
21
  * working and stopped is red. Nothing that needs a person is grey.
22
+ *
23
+ * `urgent` sits between the two: it needs a person, like amber, but it is
24
+ * blocking OTHER people right now — a plugin's members locked out of a skill
25
+ * it ships — where amber blocks only the reader's own use. Orange, the same
26
+ * colour the sidebar count turns for it, so the card and the count agree.
21
27
  */
22
- export type GemState = 'ok' | 'warn' | 'err';
28
+ export type GemState = 'ok' | 'warn' | 'urgent' | 'err';
23
29
 
24
30
  export interface AttentionStatus {
25
31
  state: GemState;
26
32
  /** User-facing state line (glossary-compliant plain words). */
27
33
  text: string;
34
+ /**
35
+ * The sentence behind the word, for a tooltip: what the provider said, or why
36
+ * we couldn't ask. Absent when the word is the whole story.
37
+ *
38
+ * This is where a status EARNS its claim. "Connected" backed by "checked 2
39
+ * minutes ago" is a different assertion from "Connected" backed by nothing,
40
+ * and the difference is exactly what used to be missing.
41
+ */
42
+ hint?: string;
28
43
  }
29
44
 
45
+ /**
46
+ * Stored, and PROVEN to work by a real call.
47
+ *
48
+ * Reachable ONLY from a passing probe verdict. Nothing derived from what is
49
+ * merely stored may return this — that inference is the entire bug.
50
+ */
30
51
  const OK: AttentionStatus = { state: 'ok', text: 'Connected' };
31
52
 
53
+ /**
54
+ * In place, and untested — all a STORED value can ever support.
55
+ *
56
+ * Two words rather than one because they describe two different things the
57
+ * reader did. Green, because nothing here needs a person.
58
+ */
59
+ const SIGNED_IN: AttentionStatus = { state: 'ok', text: 'Signed in' };
60
+ const KEY_SAVED: AttentionStatus = { state: 'ok', text: 'Key saved' };
61
+
32
62
  /** Severity order for aggregation: broken sign-in beats anything merely unset. */
33
- const RANK: Record<GemState, number> = { ok: 0, warn: 1, err: 2 };
63
+ const RANK: Record<GemState, number> = { ok: 0, warn: 1, urgent: 2, err: 3 };
34
64
 
35
65
  /**
36
- * Two states, and the words for them: `Connected`, or `Needs <the thing>`.
66
+ * What ONE variable is: in place, or `Needs <the thing>`.
67
+ *
68
+ * Never `Connected`. This reads the vault, which knows only whether a value
69
+ * exists — so the strongest true statement it can make is that something was
70
+ * saved or signed into. Only a probe earns the other word.
37
71
  *
38
72
  * There is deliberately no middle. "Not set up yet", "Sign in again to keep
39
73
  * this working" and "Needs your sign-in" were three ways of saying one thing —
@@ -53,22 +87,82 @@ function varStatus(v: ToolVarStatus, canWrite: boolean): AttentionStatus {
53
87
  if (!v.adminConfigured) return notSetUp;
54
88
  if (v.authorized && v.needsReauth) return { state: 'err', text: 'Needs signing in again' };
55
89
  if (!v.authorized) return { state: 'warn', text: 'Needs your sign-in' };
56
- return OK;
90
+ return SIGNED_IN;
57
91
  }
58
92
  if (v.scope === 'user') {
59
- return v.userConfigured ? OK : { state: 'warn', text: 'Needs a key from you' };
93
+ return v.userConfigured ? KEY_SAVED : { state: 'warn', text: 'Needs a key from you' };
94
+ }
95
+ return v.adminConfigured ? KEY_SAVED : notSetUp;
96
+ }
97
+
98
+ /**
99
+ * The word for a tool that is fully SET UP, decided by whether the credential
100
+ * has actually been tested.
101
+ *
102
+ * Three outcomes, and the reason there are three: `Connected` is a claim we can
103
+ * back — something called the provider and it answered. `Key saved` is the
104
+ * narrower claim we can back when nothing tested it: a value is stored, and
105
+ * that is genuinely all we know. `Not working` is the provider's own verdict.
106
+ *
107
+ * `Key saved` stays GREEN. It is a complete, true statement about a tool that
108
+ * needs nothing from anybody, and painting it amber would put a permanent
109
+ * warning on every integration that simply has no way to be tested — which
110
+ * teaches people that amber means nothing.
111
+ *
112
+ * A tool whose vars are oauth-backed says `Signed in` instead: the user did not
113
+ * give us a key, they signed in, and telling them a key was saved is a small
114
+ * lie in a component whose entire job is to stop telling small lies.
115
+ */
116
+ function healthStatus(tool: ToolSecrets, verdict?: ProbeVerdict | null): AttentionStatus {
117
+ if (verdict?.status === 'ok') {
118
+ // The app's one relative-time formatter, not a local dialect of it. A
119
+ // verdict with no usable timestamp still just happened — it cannot outlive
120
+ // the component holding it — so "just now" is the honest fallback.
121
+ return { ...OK, hint: `Checked ${formatRelativeTime(verdict.checkedAt) || 'just now'}.` };
60
122
  }
61
- return v.adminConfigured ? OK : notSetUp;
123
+ if (verdict?.status === 'failed') {
124
+ return {
125
+ state: 'err',
126
+ text: 'Not working',
127
+ hint: verdict.detail ?? 'The provider rejected this credential.',
128
+ };
129
+ }
130
+ // The word has to match what the user actually did. A tool with no variables
131
+ // asked nothing of them, so "Key saved" would name a key that does not exist;
132
+ // an oauth-backed one got a sign-in, not a key. Same claim in all three cases
133
+ // — something is in place, nothing has tested it — said in the reader's terms.
134
+ const allOAuth = tool.variables.length > 0 && tool.variables.every((v) => v.oauth);
135
+ const text =
136
+ tool.variables.length === 0 ? 'No key needed' : allOAuth ? 'Signed in' : 'Key saved';
137
+ return {
138
+ state: 'ok',
139
+ text,
140
+ hint: verdict?.detail ?? "Not verified — this tool hasn't been tested yet.",
141
+ };
62
142
  }
63
143
 
64
- /** Aggregate connection state of one integration for the current user. */
65
- export function toolStatus(tool: ToolSecrets): AttentionStatus {
66
- let worst = OK;
144
+ /**
145
+ * Aggregate connection state of one integration for the current user.
146
+ *
147
+ * Setup comes FIRST: a tool still missing a key is `Needs a key from you`, never
148
+ * `Not working`. Both are unhealthy, but only one names something the user can
149
+ * act on, and a probe verdict from before the key was entered must not outrank
150
+ * the thing actually in the way. Only once every variable is provided does the
151
+ * question become whether what was provided works.
152
+ *
153
+ * `verdict` is the result of a probe the CALLER just ran and is holding, so only
154
+ * the tool page passes one. Every other surface — the library cards, the skill
155
+ * page's tool list — renders the untested green, because nothing there has
156
+ * tested anything: no verdict is stored, so claiming `Connected` on a list built
157
+ * from what is merely saved is the exact lie this module exists to stop.
158
+ */
159
+ export function toolStatus(tool: ToolSecrets, verdict?: ProbeVerdict | null): AttentionStatus {
160
+ let worst: AttentionStatus | null = null;
67
161
  for (const v of tool.variables) {
68
162
  const s = varStatus(v, tool.canWrite);
69
- if (RANK[s.state] > RANK[worst.state]) worst = s;
163
+ if (s.state !== 'ok' && (worst === null || RANK[s.state] > RANK[worst.state])) worst = s;
70
164
  }
71
- return worst;
165
+ return worst ?? healthStatus(tool, verdict);
72
166
  }
73
167
 
74
168
  /** Per-variable status rows for the integration detail dialog. */
@@ -152,6 +246,67 @@ export interface LibraryFilterable {
152
246
  owned: boolean;
153
247
  /** Folder plugin from the item's KB path, or null when it sits in none. */
154
248
  plugin: string | null;
249
+ /**
250
+ * Lives under the shared `Skills/` root rather than in a plugin folder.
251
+ * Such an item has no folder plugin, but it is not "yours alone" either —
252
+ * it is owned by a scope and shared into plugins by link — so the
253
+ * ungrouped view leaves it out and only the catalog-wide view lists it.
254
+ */
255
+ shared?: boolean;
256
+ /**
257
+ * Every plugin the item belongs to, inline or by link. `plugin` above is the
258
+ * FOLDER plugin only (routing, "yours alone"); this is what the plugin
259
+ * page and the sidebar counts go by.
260
+ */
261
+ plugins?: { name: string }[];
262
+ }
263
+
264
+ /** "Yours alone": in no plugin folder AND not a shared skill. */
265
+ export function isUngrouped(item: Pick<LibraryFilterable, 'plugin' | 'shared'>): boolean {
266
+ return item.plugin === null && !item.shared;
267
+ }
268
+
269
+ /** Whether an item belongs to `plugin` — by folder, or by a link from the plugin's manifest. */
270
+ export function isInPlugin(item: Pick<LibraryFilterable, 'plugin' | 'plugins'>, plugin: string): boolean {
271
+ return item.plugin === plugin || (item.plugins?.some((m) => m.name === plugin) ?? false);
272
+ }
273
+
274
+ /**
275
+ * The item as the plugin page should show it: a LINK whose grant is missing
276
+ * gets the note in the tools' grammar — "Needs setup", and "share with plugin
277
+ * members" for someone who can edit the skill's rules — because until the
278
+ * grant is back, the plugin's members cannot read it. In ORANGE (`urgent`),
279
+ * not amber: it locks other people out, and the sidebar count for the plugin
280
+ * is the same colour. Healthy links are untouched.
281
+ */
282
+ export function withLinkHealth<T extends LibraryFilterable & { status: AttentionStatus }>(
283
+ item: T,
284
+ plugin: string,
285
+ ): T {
286
+ const membership = (item.plugins as { name: string; linked?: boolean; granted?: boolean }[] | undefined)?.find(
287
+ (m) => m.name === plugin,
288
+ );
289
+ if (!membership?.linked || membership.granted !== false) return item;
290
+ // One amber note at a time, and the card's own comes first: a skill whose
291
+ // tools need setup, or one under review, already says what to do — the
292
+ // broken link is reported once that is settled, not in its place.
293
+ if (item.status.state !== 'ok') return item;
294
+ return {
295
+ ...item,
296
+ status: {
297
+ state: 'urgent',
298
+ text: item.owned ? 'Needs setup: share with plugin members' : 'Needs setup',
299
+ hint: `The skill's access rules no longer name ${plugin}'s members. Repair the link from the skill page.`,
300
+ },
301
+ };
302
+ }
303
+
304
+ /** The distinct plugin names an item belongs to. */
305
+ export function pluginsOfItem(item: Pick<LibraryFilterable, 'plugin' | 'plugins'>): string[] {
306
+ const names = new Set<string>();
307
+ if (item.plugin !== null) names.add(item.plugin);
308
+ for (const m of item.plugins ?? []) names.add(m.name);
309
+ return [...names];
155
310
  }
156
311
 
157
312
  /** Sidebar selection narrows; the query matches name/description within it. */
@@ -171,9 +326,9 @@ export function filterLibraryItems<T extends LibraryFilterable>(
171
326
  case 'owned':
172
327
  return item.owned;
173
328
  case 'group':
174
- return item.plugin === filter.plugin;
329
+ return isInPlugin(item, filter.plugin);
175
330
  case 'ungrouped':
176
- return item.plugin === null;
331
+ return isUngrouped(item);
177
332
  }
178
333
  });
179
334
  }
@@ -190,8 +345,9 @@ export function pluginCounts<T extends LibraryFilterable>(
190
345
  ): { plugin: string; count: number }[] {
191
346
  const counts = new Map<string, number>();
192
347
  for (const item of items) {
193
- if (item.plugin === null) continue;
194
- counts.set(item.plugin, (counts.get(item.plugin) ?? 0) + 1);
348
+ // A linked skill counts for every plugin that links it, like the plugin
349
+ // index's own totals.
350
+ for (const name of pluginsOfItem(item)) counts.set(name, (counts.get(name) ?? 0) + 1);
195
351
  }
196
352
  return [...counts.entries()]
197
353
  .map(([plugin, count]) => ({ plugin, count }))
@@ -136,7 +136,7 @@ beforeEach(() => {
136
136
  resetOnboardingForTests();
137
137
  setSidebarCollapsed(false, true);
138
138
  serviceMocks.createPlugin.mockReset();
139
- serviceMocks.createPlugin.mockResolvedValue({ folder: 'Design' });
139
+ serviceMocks.createPlugin.mockResolvedValue({ folder: 'Design', name: 'design' });
140
140
  serviceMocks.createEmptySkill.mockReset();
141
141
  serviceMocks.createEmptySkill.mockResolvedValue({
142
142
  repoRelativePath: 'Plugins/personal-u1/weekly-report/SKILL.md',
@@ -249,8 +249,9 @@ describe('creator welcome actions', () => {
249
249
  // indexes -> navigate), so it is the settled state to wait for; asserting
250
250
  // it immediately races the refresh microtasks and flakes under CI load.
251
251
  await waitFor(() =>
252
+ // The new plugin's page is addressed by its identity, not its folder.
252
253
  expect(screen.getByLabelText('pathname')).toHaveTextContent(
253
- '/skills-and-tools/plugins/Design',
254
+ '/skills-and-tools/plugins/design',
254
255
  ),
255
256
  );
256
257
  expect(data.reload).toHaveBeenCalledOnce();