@bevel-software/platform-core-frontend 0.8.0 → 0.9.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 (36) hide show
  1. package/package.json +2 -2
  2. package/src/core/registry.ts +16 -4
  3. package/src/modules/admin/state/admin.context.tsx +15 -0
  4. package/src/modules/library/__tests__/PluginPage.test.tsx +97 -6
  5. package/src/modules/library/__tests__/PluginsIndexPage.test.tsx +90 -10
  6. package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +1 -0
  7. package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +1 -0
  8. package/src/modules/library/__tests__/PluginsSidebar.test.tsx +29 -0
  9. package/src/modules/library/__tests__/library-data.test.ts +82 -0
  10. package/src/modules/library/components/LibraryCard.tsx +6 -1
  11. package/src/modules/library/components/LibraryLayout.tsx +11 -2
  12. package/src/modules/library/components/NewSkillPanel.tsx +18 -0
  13. package/src/modules/library/components/PageActions.tsx +31 -8
  14. package/src/modules/library/components/PersonalPluginPage.tsx +14 -4
  15. package/src/modules/library/components/PluginJoinRequests.tsx +22 -1
  16. package/src/modules/library/components/PluginPage.tsx +42 -5
  17. package/src/modules/library/components/PluginsIndexPage.tsx +46 -3
  18. package/src/modules/library/components/PluginsSidebar.tsx +50 -0
  19. package/src/modules/library/components/plugin-page-parts.tsx +184 -4
  20. package/src/modules/library/routes/LibraryRoutes.tsx +2 -2
  21. package/src/modules/library/state/library-data.tsx +21 -0
  22. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +318 -0
  23. package/src/modules/onboarding/components/CreatorWelcomePage.tsx +143 -0
  24. package/src/modules/onboarding/components/WelcomePage.tsx +11 -14
  25. package/src/modules/onboarding/components/WelcomeRoute.tsx +57 -0
  26. package/src/modules/onboarding/welcome-state.ts +36 -0
  27. package/src/modules/setup/__tests__/setup.test.tsx +203 -0
  28. package/src/modules/setup/components/SetupScreen.tsx +235 -68
  29. package/src/modules/workspace/components/FileRoute.tsx +8 -1
  30. package/src/modules/workspace/components/FileViewer.tsx +95 -38
  31. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +20 -0
  32. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +227 -18
  33. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +25 -0
  34. package/src/modules/workspace/routing/kb-routes.ts +23 -1
  35. package/src/modules/workspace/utils/fileTree.ts +51 -0
  36. package/src/shared/components/Surface.tsx +15 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bevel-software/platform-core-frontend",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "description": "Open-source core UI of the Bevel platform (raw TS/TSX source): workspace explorer/viewer, branches & change requests, Library, secrets, tools, access control.",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -41,7 +41,7 @@
41
41
  "tailwind-merge": "^3.5.0",
42
42
  "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz",
43
43
  "yaml": "^2.9.0",
44
- "@bevel-software/platform-shared": "0.8.0"
44
+ "@bevel-software/platform-shared": "0.9.1"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@testing-library/jest-dom": "^6.9.1",
@@ -302,8 +302,11 @@ export interface AppRegistry {
302
302
  crCreation?: CrCreationPort;
303
303
  /**
304
304
  * Static override of the suggested-prompt seeding callback (see
305
- * {@link SuggestedPromptSeedContext} for the runtime-state variant). When
306
- * neither is provided the FileViewer hides its suggested-prompt buttons.
305
+ * {@link SuggestedPromptSeedContext} for the runtime-state variant, and for
306
+ * why nothing in core consumes either any more — the Knowledge viewer's
307
+ * empty state offers real pages now, not prompts). Still public API: a
308
+ * registry-provided chat surface may hold it and seed from its own
309
+ * affordances.
307
310
  */
308
311
  suggestedPromptSeed?: (prompt: string) => void;
309
312
  /**
@@ -393,8 +396,17 @@ export function useCrCreationPort(): CrCreationPort | null {
393
396
  }
394
397
 
395
398
  /**
396
- * Seeds the chat composer with a suggested prompt (FileViewer empty state).
397
- * Null → no chat surface registered → the suggested-prompt UI hides.
399
+ * Seeds the chat composer with a suggested prompt. Null → no chat surface is
400
+ * registered.
401
+ *
402
+ * NO CORE CONSUMER. It used to be the Knowledge viewer's empty state, which
403
+ * offered three canned questions for an assistant — on a deployment with no
404
+ * chat surface they never rendered, and on one with a chat surface they sent a
405
+ * reader looking at an empty page to go and ask something instead of opening
406
+ * one of the pages the file tree was already showing them. That empty state
407
+ * offers real documents now. The port stays because it is public API a
408
+ * registry may hold, and a chat surface that provides it is free to seed from
409
+ * its own affordances.
398
410
  */
399
411
  export const SuggestedPromptSeedContext = createContext<
400
412
  ((prompt: string) => void) | null
@@ -18,6 +18,14 @@ import { getRolesHealth, recoverRoles } from '../services/roles.api';
18
18
  // test, or a host app supplying its own admin state) has to be able to say so.
19
19
  export interface AdminContextValue {
20
20
  isAdmin: boolean;
21
+ /**
22
+ * True until the signed-in person's admin verdict has settled.
23
+ *
24
+ * Optional so host applications and older test harnesses that provide this
25
+ * public context directly remain source-compatible. The built-in provider
26
+ * always supplies it.
27
+ */
28
+ isAdminLoading?: boolean;
21
29
  /** Number of feedback rows submitted after `lastSeen` (or total if null). */
22
30
  unreadCount: number;
23
31
  /** ISO timestamp; null means the admin has never opened the inbox. */
@@ -59,6 +67,7 @@ export function AdminProvider({ children }: { children: ReactNode }) {
59
67
  const countUnread = useAppRegistry().adminUnreadCount;
60
68
 
61
69
  const [isAdmin, setIsAdmin] = useState(false);
70
+ const [isAdminLoading, setIsAdminLoading] = useState(true);
62
71
  const [lastSeen, setLastSeen] = useState<string | null>(null);
63
72
  const [unreadCount, setUnreadCount] = useState(0);
64
73
  const [rolesConfigCorrupted, setRolesConfigCorrupted] = useState(false);
@@ -77,6 +86,7 @@ export function AdminProvider({ children }: { children: ReactNode }) {
77
86
  // failure falls back to "no admin" rather than stale access.
78
87
  useEffect(() => {
79
88
  setIsAdmin(false);
89
+ setIsAdminLoading(Boolean(email));
80
90
  setLastSeen(null);
81
91
  setUnreadCount(0);
82
92
  if (!email) return;
@@ -94,6 +104,9 @@ export function AdminProvider({ children }: { children: ReactNode }) {
94
104
  setIsAdmin(false);
95
105
  setLastSeen(null);
96
106
  setUnreadCount(0);
107
+ })
108
+ .finally(() => {
109
+ if (!cancelled) setIsAdminLoading(false);
97
110
  });
98
111
  return () => {
99
112
  cancelled = true;
@@ -202,6 +215,7 @@ export function AdminProvider({ children }: { children: ReactNode }) {
202
215
  const value = useMemo<AdminContextValue>(
203
216
  () => ({
204
217
  isAdmin,
218
+ isAdminLoading,
205
219
  unreadCount,
206
220
  lastSeen,
207
221
  markSeen,
@@ -212,6 +226,7 @@ export function AdminProvider({ children }: { children: ReactNode }) {
212
226
  }),
213
227
  [
214
228
  isAdmin,
229
+ isAdminLoading,
215
230
  unreadCount,
216
231
  lastSeen,
217
232
  markSeen,
@@ -84,6 +84,9 @@ const nonAdmin: AdminContextValue = {
84
84
  runRolesRecovery: vi.fn(),
85
85
  };
86
86
 
87
+ /** The same caller with the admin bit set — the empty band's doorway is theirs. */
88
+ const asAdmin: AdminContextValue = { ...nonAdmin, isAdmin: true };
89
+
87
90
  const connectedTool = (over: Partial<ToolSecrets> = {}): ToolSecrets => ({
88
91
  slug: 'heyreach',
89
92
  name: 'heyreach',
@@ -155,10 +158,10 @@ function LocationProbe() {
155
158
  return <div aria-label="href">{location.pathname + location.search}</div>;
156
159
  }
157
160
 
158
- function renderPlugin(name: string, children?: ReactNode) {
161
+ function renderPlugin(name: string, children?: ReactNode, admin: AdminContextValue = nonAdmin) {
159
162
  return render(
160
163
  <MemoryRouter initialEntries={[`/skills-and-tools/plugins/${encodeURIComponent(name)}`]}>
161
- <AdminContext.Provider value={nonAdmin}>
164
+ <AdminContext.Provider value={admin}>
162
165
  <WorkspaceContext.Provider value={workspace}>
163
166
  <LibraryToastProvider>
164
167
  <LibraryProvider>
@@ -298,12 +301,62 @@ describe('PluginPage', () => {
298
301
  dataMock.useLibraryData.mockReturnValue({ ...CATALOG, skills: [], tools: [] });
299
302
  pluginsMock.listPlugins.mockResolvedValue([gtm({ skillCount: 0, toolCount: 0 })]);
300
303
  renderPlugin('GTM');
304
+ // A non-admin reads one plain sentence: the fact, and the agent as the
305
+ // door that IS theirs. No inline action, so nothing is split around it.
301
306
  expect(
302
- await screen.findByText('No skills yet. Add one, or ask your agent to write one for GTM.'),
307
+ await screen.findByText('No skills yet. Ask your agent to write one for GTM.'),
303
308
  ).toBeInTheDocument();
304
309
  expect(screen.getByText('No tools yet.')).toBeInTheDocument();
305
310
  });
306
311
 
312
+ it('keeps the empty band a dead end for a non-admin — no doorway, no arrow', async () => {
313
+ dataMock.useLibraryData.mockReturnValue({ ...CATALOG, skills: [], tools: [] });
314
+ pluginsMock.listPlugins.mockResolvedValue([gtm({ skillCount: 0, toolCount: 0 })]);
315
+ renderPlugin('GTM');
316
+ await screen.findByText(/No skills yet/);
317
+ expect(screen.queryByRole('button', { name: 'Add the first skill' })).not.toBeInTheDocument();
318
+ expect(screen.queryByTestId('chalk-arrow')).not.toBeInTheDocument();
319
+ });
320
+
321
+ it('keeps the doorway but not the dialog-less click when the plugins endpoint failed', async () => {
322
+ // The add dialog mounts only with a summary and its primary folder. When
323
+ // the endpoint failed there is neither, so an admin's "Add the first
324
+ // skill" would be a button that does nothing — the band must fall back to
325
+ // the sentence whose one door (the agent) still works.
326
+ dataMock.useLibraryData.mockReturnValue({ ...CATALOG, skills: [], tools: [] });
327
+ pluginsMock.listPlugins.mockRejectedValue(new Error('boom'));
328
+ renderPlugin('GTM', undefined, asAdmin);
329
+ expect(
330
+ await screen.findByText('No skills yet. Ask your agent to write one for GTM.'),
331
+ ).toBeInTheDocument();
332
+ expect(screen.queryByRole('button', { name: 'Add the first skill' })).not.toBeInTheDocument();
333
+ // The title row's `+` is under the same prerequisite: both ways to add
334
+ // must agree that adding is impossible here.
335
+ expect(
336
+ screen.queryByRole('button', { name: 'Add a skill or tool to GTM' }),
337
+ ).not.toBeInTheDocument();
338
+ });
339
+
340
+ it('makes the empty Skills band a doorway for an admin: its link opens the same add dialog as `+`', async () => {
341
+ dataMock.useLibraryData.mockReturnValue({ ...CATALOG, skills: [], tools: [] });
342
+ pluginsMock.listPlugins.mockResolvedValue([gtm({ skillCount: 0, toolCount: 0 })]);
343
+ renderPlugin('GTM', undefined, asAdmin);
344
+ // The sentence is split around its inline action, so it is asserted in its
345
+ // parts: the fact, the doorway, and the agent as the other door.
346
+ expect(await screen.findByText(/No skills yet/)).toBeInTheDocument();
347
+ expect(screen.getByText(/or ask your agent to write one for GTM/)).toBeInTheDocument();
348
+ fireEvent.click(screen.getByRole('button', { name: 'Add the first skill' }));
349
+ expect(
350
+ await screen.findByRole('heading', { name: 'Add a skill or tool to GTM' }),
351
+ ).toBeInTheDocument();
352
+ });
353
+
354
+ it('drops the nudge once a skill exists — the arrow belongs to the empty band only', async () => {
355
+ renderPlugin('GTM', undefined, asAdmin); // CATALOG carries outreach in GTM
356
+ await screen.findByRole('button', { name: /^outreach/ });
357
+ expect(screen.queryByRole('button', { name: 'Add the first skill' })).not.toBeInTheDocument();
358
+ });
359
+
307
360
  it('keeps Share on an EMPTY plugin. The folder is what carries access, not the items', async () => {
308
361
  // Plugins used to be derived from their items, which meant a plugin with
309
362
  // nothing in it had no folder to manage and silently lost its access
@@ -395,10 +448,48 @@ describe('PluginPage', () => {
395
448
  pluginsMock.listPlugins.mockRejectedValue(new Error("Couldn't load plugins."));
396
449
  renderPlugin('GTM');
397
450
  expect(await screen.findByTestId('library-card-skill-outreach')).toBeInTheDocument();
398
- // No verified principals, so no claim about them. The add door still opens
399
- // — it writes nothing, so there is no permission to be wrong about.
451
+ // No verified principals, so no claim about them.
400
452
  expect(screen.queryByText(/^Run by/)).not.toBeInTheDocument();
401
- expect(screen.getByRole('button', { name: 'Add a skill or tool to GTM' })).toBeInTheDocument();
453
+ // The add door is GONE. It used to be asserted present-and-enabled, on
454
+ // the reasoning that adding writes nothing a permission could be wrong
455
+ // about — but permission was never what stops it here: `AddToPluginDialog`
456
+ // needs `summary && primaryFolder` to mount, and the failed endpoint left
457
+ // neither, so the button opened nothing at all. Omitted, like `Share`
458
+ // is when there is no folder to manage.
459
+ expect(
460
+ screen.queryByRole('button', { name: 'Add a skill or tool to GTM' }),
461
+ ).not.toBeInTheDocument();
462
+ });
463
+
464
+ it('brings the add door back once plugin discovery lands', async () => {
465
+ // The page renders as soon as the CATALOG has items, so the summary can be
466
+ // missing simply because plugins are still on their way. The button is
467
+ // absent for that moment and appears when there is something behind it —
468
+ // an affordance arriving, never one that was there and stopped working.
469
+ let settle!: (plugins: PluginSummary[]) => void;
470
+ pluginsMock.listPlugins.mockReturnValue(new Promise((resolve) => (settle = resolve)));
471
+ renderPlugin('GTM');
472
+ await screen.findByTestId('library-card-skill-outreach');
473
+ expect(
474
+ screen.queryByRole('button', { name: 'Add a skill or tool to GTM' }),
475
+ ).not.toBeInTheDocument();
476
+
477
+ settle([gtm()]);
478
+ expect(
479
+ await screen.findByRole('button', { name: 'Add a skill or tool to GTM' }),
480
+ ).toBeInTheDocument();
481
+ });
482
+
483
+ it('offers no add door to a caller who only reached the plugin through an item grant', async () => {
484
+ // A per-file grant puts one skill from GTM in this caller's catalog while
485
+ // no summary vouches for the plugin. Discovery worked — they simply have
486
+ // no folder of their own to add into, so there is no door to offer.
487
+ pluginsMock.listPlugins.mockResolvedValue([]);
488
+ renderPlugin('GTM');
489
+ await screen.findByTestId('library-card-skill-outreach');
490
+ expect(
491
+ screen.queryByRole('button', { name: 'Add a skill or tool to GTM' }),
492
+ ).not.toBeInTheDocument();
402
493
  });
403
494
 
404
495
  it('does not claim a missing plugin is gone while the endpoint is still failing', async () => {
@@ -28,6 +28,7 @@ import {
28
28
  WorkspaceContext,
29
29
  type WorkspaceContextValue,
30
30
  } from '../../workspace/state/workspace.context';
31
+ import { AdminContext, type AdminContextValue } from '../../admin/state/admin.context';
31
32
  import { PluginsIndexPage } from '../components/PluginsIndexPage';
32
33
  import { withAuth, TEST_PERSONAL_GROUP } from './auth-harness';
33
34
 
@@ -103,19 +104,35 @@ const WORKSPACE = {
103
104
  kbDirName: 'knowledge-base',
104
105
  } as unknown as WorkspaceContextValue;
105
106
 
106
- function renderIndex() {
107
+ const nonAdmin: AdminContextValue = {
108
+ isAdmin: false,
109
+ unreadCount: 0,
110
+ lastSeen: null,
111
+ markSeen: vi.fn(),
112
+ refresh: vi.fn(),
113
+ rolesConfigCorrupted: false,
114
+ rolesConfigErrors: [],
115
+ runRolesRecovery: vi.fn(),
116
+ };
117
+
118
+ /** The same caller with the admin bit set — the empty index's CTA is theirs. */
119
+ const asAdmin: AdminContextValue = { ...nonAdmin, isAdmin: true };
120
+
121
+ function renderIndex(admin: AdminContextValue = nonAdmin) {
107
122
  return render(
108
123
  <MemoryRouter initialEntries={['/skills-and-tools']}>
109
124
  {withAuth(
110
- <WorkspaceContext.Provider value={WORKSPACE}>
111
- <LibraryProvider>
112
- <Routes>
113
- <Route path="/skills-and-tools" element={<PluginsIndexPage />} />
114
- <Route path="*" element={<div />} />
115
- </Routes>
116
- <LocationProbe />
117
- </LibraryProvider>
118
- </WorkspaceContext.Provider>,
125
+ <AdminContext.Provider value={admin}>
126
+ <WorkspaceContext.Provider value={WORKSPACE}>
127
+ <LibraryProvider>
128
+ <Routes>
129
+ <Route path="/skills-and-tools" element={<PluginsIndexPage />} />
130
+ <Route path="*" element={<div />} />
131
+ </Routes>
132
+ <LocationProbe />
133
+ </LibraryProvider>
134
+ </WorkspaceContext.Provider>
135
+ </AdminContext.Provider>,
119
136
  )}
120
137
  </MemoryRouter>,
121
138
  );
@@ -261,6 +278,69 @@ describe('PluginsIndexPage', () => {
261
278
  expect(await screen.findByRole('button', { name: 'GTM 1 skills · 1 tools' })).toBeInTheDocument();
262
279
  });
263
280
 
281
+ /** An untouched workspace: no summaries, and only unfiled items. */
282
+ function untouchedWorkspace() {
283
+ pluginsMock.listPlugins.mockResolvedValue([]);
284
+ dataMock.useLibraryData.mockReturnValue({
285
+ ...CATALOG,
286
+ skills: [{ name: 'scratch', description: '', path: 'Skills/scratch' }],
287
+ tools: [
288
+ tool({ slug: 'slack', name: 'slack', path: 'Tools/slack.tool' }),
289
+ ],
290
+ });
291
+ }
292
+
293
+ it('turns an untouched index into a create CTA for an admin, and the CTA into the dialog', async () => {
294
+ untouchedWorkspace();
295
+ renderIndex(asAdmin);
296
+
297
+ fireEvent.click(await screen.findByRole('button', { name: 'Create the first plugin' }));
298
+ expect(await screen.findByRole('textbox', { name: 'Plugin name' })).toBeInTheDocument();
299
+ });
300
+
301
+ it('never offers the first plugin to a non-admin — that call is not theirs to make', async () => {
302
+ untouchedWorkspace();
303
+ renderIndex();
304
+ await screen.findByText('Your plugins');
305
+ expect(
306
+ screen.queryByRole('button', { name: 'Create the first plugin' }),
307
+ ).not.toBeInTheDocument();
308
+ });
309
+
310
+ it('keeps the create CTA out of the way once the caller is in a plugin', async () => {
311
+ renderIndex(asAdmin); // default fixture: member of GTM
312
+ await screen.findByRole('button', { name: /^GTM/ });
313
+ expect(
314
+ screen.queryByRole('button', { name: 'Create the first plugin' }),
315
+ ).not.toBeInTheDocument();
316
+ });
317
+
318
+ it('stands the CTA down when plugins exist that the admin is simply not in', async () => {
319
+ // Locked entries are plugins too: "the first plugin" would be a lie here,
320
+ // even though `Your plugins` is empty.
321
+ pluginsMock.listPlugins.mockResolvedValue([
322
+ summary({ name: 'Finance', folders: ['Plugins/Finance'], canRead: false, canWrite: false }),
323
+ ]);
324
+ dataMock.useLibraryData.mockReturnValue({ ...CATALOG, skills: [], tools: [] });
325
+ renderIndex(asAdmin);
326
+ await screen.findByRole('button', { name: /^Finance/ });
327
+ expect(
328
+ screen.queryByRole('button', { name: 'Create the first plugin' }),
329
+ ).not.toBeInTheDocument();
330
+ });
331
+
332
+ it('does not promise the first plugin while the catalog is still loading', async () => {
333
+ // The initial empty `items` is an unanswered question, not an untouched
334
+ // workspace: a catalog-derived plugin may still be on its way in.
335
+ pluginsMock.listPlugins.mockResolvedValue([]);
336
+ dataMock.useLibraryData.mockReturnValue({ ...CATALOG, loading: true, skills: [], tools: [] });
337
+ renderIndex(asAdmin);
338
+ await screen.findByText('Your plugins');
339
+ expect(
340
+ screen.queryByRole('button', { name: 'Create the first plugin' }),
341
+ ).not.toBeInTheDocument();
342
+ });
343
+
264
344
  it('offers a retry when the plugins endpoint fails, and keeps Yours', async () => {
265
345
  pluginsMock.listPlugins.mockRejectedValue(new Error("Couldn't load plugins."));
266
346
  renderIndex();
@@ -32,6 +32,7 @@ function renderSidebar(over: Partial<PluginsSidebarProps> = {}) {
32
32
  attentionCount: 2,
33
33
  onFinishSetup: vi.fn(),
34
34
  onCreatePlugin: vi.fn(),
35
+ canCreatePlugin: true,
35
36
  pluginsIndexActive: false,
36
37
  onOpenPluginsIndex: vi.fn(),
37
38
  onContextMenu,
@@ -30,6 +30,7 @@ function renderSidebar(over: Partial<PluginsSidebarProps> = {}) {
30
30
  attentionCount: 2,
31
31
  onFinishSetup: vi.fn(),
32
32
  onCreatePlugin: vi.fn(),
33
+ canCreatePlugin: true,
33
34
  pluginsIndexActive: false,
34
35
  onOpenPluginsIndex: vi.fn(),
35
36
 
@@ -28,6 +28,7 @@ function renderSidebar(over: Partial<PluginsSidebarProps> = {}) {
28
28
  attentionCount: 2,
29
29
  onFinishSetup,
30
30
  onCreatePlugin: vi.fn(),
31
+ canCreatePlugin: true,
31
32
  pluginsIndexActive: false,
32
33
  onOpenPluginsIndex: vi.fn(),
33
34
 
@@ -83,6 +84,34 @@ describe('PluginsSidebar', () => {
83
84
  expect(onCreatePlugin).toHaveBeenCalledTimes(1);
84
85
  });
85
86
 
87
+ it('spells out Create a plugin while the MCP list is empty — the `+` alone is hover-hidden', () => {
88
+ const { onCreatePlugin } = renderSidebar({ plugins: [] });
89
+ fireEvent.click(screen.getByRole('button', { name: 'Create a plugin' }));
90
+ expect(onCreatePlugin).toHaveBeenCalledTimes(1);
91
+ });
92
+
93
+ it('stands the create CTA down once a real plugin exists', () => {
94
+ renderSidebar(); // default fixture has three plugins
95
+ expect(screen.queryByRole('button', { name: 'Create a plugin' })).not.toBeInTheDocument();
96
+ });
97
+
98
+ it('stands the create CTA down when only locked plugins exist — someone already created them', () => {
99
+ renderSidebar({ plugins: [], lockedPlugins: ['Ops'] });
100
+ expect(screen.queryByRole('button', { name: 'Create a plugin' })).not.toBeInTheDocument();
101
+ });
102
+
103
+ it('stands the create CTA down for a non-admin, empty workspace or not', () => {
104
+ renderSidebar({ plugins: [], lockedPlugins: [], canCreatePlugin: false });
105
+ expect(screen.queryByRole('button', { name: 'Create a plugin' })).not.toBeInTheDocument();
106
+ });
107
+
108
+ it('says nothing about creating when the prop is omitted — the nav a host app already had', () => {
109
+ // `canCreatePlugin` is optional so this public props type survives the
110
+ // upgrade. Omitted must mean OFF, which is the nav exactly as it shipped.
111
+ renderSidebar({ plugins: [], lockedPlugins: [], canCreatePlugin: undefined });
112
+ expect(screen.queryByRole('button', { name: 'Create a plugin' })).not.toBeInTheDocument();
113
+ });
114
+
86
115
  it('marks the selected plugin current and leaves the others alone', () => {
87
116
  renderSidebar({ filter: { kind: 'group', plugin: 'GTM' } });
88
117
  expect(row(/^GTM/)).toHaveAttribute('aria-current', 'true');
@@ -0,0 +1,82 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import {
3
+ workspaceHasNoPlugins,
4
+ type LibraryContextValue,
5
+ type LibraryItem,
6
+ } from '../state/library-data';
7
+
8
+ /**
9
+ * The one predicate behind every "create the FIRST plugin" doorway — the nav's
10
+ * spelled-out row and the index's CTA both. What these tests pin is that the
11
+ * verdict is SETTLED: an empty answer while either witness is loading or has
12
+ * failed must read as "unknown", never as "untouched".
13
+ */
14
+
15
+ function item(plugin: string | null): LibraryItem {
16
+ return {
17
+ kind: 'skill',
18
+ id: 'scratch',
19
+ name: 'scratch',
20
+ description: '',
21
+ owned: false,
22
+ plugin,
23
+ path: plugin ? `Plugins/${plugin}/scratch` : 'Skills/scratch',
24
+ status: { state: 'ok', text: 'Ready' },
25
+ };
26
+ }
27
+
28
+ function lib(over: Partial<LibraryContextValue> = {}): LibraryContextValue {
29
+ return {
30
+ loading: false,
31
+ error: null,
32
+ skills: [],
33
+ pendingSkills: [],
34
+ tools: [],
35
+ ownedSkills: new Set(),
36
+ allowedToolsBySkill: new Map(),
37
+ crs: [],
38
+ myCrNumbers: new Set(),
39
+ reload: vi.fn(),
40
+ items: [],
41
+ pluginSummaries: [],
42
+ pluginsLoading: false,
43
+ pluginsError: null,
44
+ reloadPlugins: vi.fn(),
45
+ ...over,
46
+ };
47
+ }
48
+
49
+ describe('workspaceHasNoPlugins', () => {
50
+ it('is true only for a settled, plugin-less workspace', () => {
51
+ expect(workspaceHasNoPlugins(lib())).toBe(true);
52
+ expect(workspaceHasNoPlugins(lib({ items: [item(null)] }))).toBe(true);
53
+ });
54
+
55
+ it('treats a still-loading source as an unanswered question', () => {
56
+ expect(workspaceHasNoPlugins(lib({ loading: true }))).toBe(false);
57
+ expect(workspaceHasNoPlugins(lib({ pluginsLoading: true }))).toBe(false);
58
+ });
59
+
60
+ it('treats a failed source as an unanswered question', () => {
61
+ expect(workspaceHasNoPlugins(lib({ error: 'boom' }))).toBe(false);
62
+ expect(workspaceHasNoPlugins(lib({ pluginsError: "Couldn't load plugins." }))).toBe(false);
63
+ });
64
+
65
+ it('counts a plugin from either witness — a summary, or a catalog item', () => {
66
+ expect(
67
+ workspaceHasNoPlugins(
68
+ lib({
69
+ pluginSummaries: [
70
+ {
71
+ name: 'GTM',
72
+ folders: ['Plugins/GTM'],
73
+ canRead: false,
74
+ canWrite: false,
75
+ } as LibraryContextValue['pluginSummaries'][number],
76
+ ],
77
+ }),
78
+ ),
79
+ ).toBe(false);
80
+ expect(workspaceHasNoPlugins(lib({ items: [item('GTM')] }))).toBe(false);
81
+ });
82
+ });
@@ -110,8 +110,13 @@ export function LibraryCard({
110
110
  // Dashed, because the card is an outline of a skill rather than one: the
111
111
  // border says "not here yet" before any text is read, and it survives the
112
112
  // badge being missed at a glance.
113
+ // `min-w-0`: the card sits in a grid (or the remove-overlay's wrapper),
114
+ // and a grid item's automatic minimum is its content's min-content width
115
+ // — a long tool name plus its badges would make the card WIDER than its
116
+ // track and paint under the neighbouring card. Allowing the card to
117
+ // shrink is what lets the name's `truncate` actually engage.
113
118
  className={cn(
114
- 'flex min-h-28 flex-col gap-1.5 text-left',
119
+ 'flex min-h-28 min-w-0 flex-col gap-1.5 text-left',
115
120
  pending && 'border-dashed',
116
121
  )}
117
122
  onClick={onOpen}
@@ -3,7 +3,8 @@ import { Outlet, useLocation, useNavigate } from 'react-router-dom';
3
3
  import { cn } from '../../../lib/utils';
4
4
  import { DOCUMENT_COLUMN, documentGutters } from '../../../shared/theme/measure';
5
5
  import { useAuth } from '../../auth/state/auth.context';
6
- import { attentionOf, useLibrary } from '../state/library-data';
6
+ import { useAdmin } from '../../admin/state/admin.context';
7
+ import { attentionOf, useLibrary, workspaceHasNoPlugins } from '../state/library-data';
7
8
  import { personalPluginName } from '../utils/personal-plugin';
8
9
  import {
9
10
  isPluginsIndexPath,
@@ -36,10 +37,12 @@ import { NewPluginDialog } from './NewPluginDialog';
36
37
  * can take its filter as a plain prop and the sidebar can hold no state.
37
38
  */
38
39
  export function LibraryLayout() {
39
- const { items, pluginSummaries, reload, reloadPlugins } = useLibrary();
40
+ const lib = useLibrary();
41
+ const { items, pluginSummaries, reload, reloadPlugins } = lib;
40
42
  const location = useLocation();
41
43
  const navigate = useNavigate();
42
44
  const { user } = useAuth();
45
+ const { isAdmin } = useAdmin();
43
46
  const { kbDirName } = useWorkspace();
44
47
  const toast = useLibraryToast();
45
48
  const [newPluginOpen, setNewPluginOpen] = useState(false);
@@ -217,6 +220,12 @@ export function LibraryLayout() {
217
220
  attentionCount={attentionCount}
218
221
  onFinishSetup={() => navigate('/connect')}
219
222
  onCreatePlugin={() => setNewPluginOpen(true)}
223
+ // The whole verdict, not just the role: the create-a-plugin row is a
224
+ // claim that the workspace holds no plugins AT ALL, and that claim is
225
+ // only honest once both plugin witnesses have settled successfully —
226
+ // while they load (or after they fail) an empty list is an unanswered
227
+ // question, not an untouched workspace.
228
+ canCreatePlugin={isAdmin && workspaceHasNoPlugins(lib)}
220
229
  pluginsIndexActive={isPluginsIndexPath(location.pathname)}
221
230
  onOpenPluginsIndex={() => navigate(pathForPluginsIndex())}
222
231
  onContextMenu={openContextMenu}
@@ -29,6 +29,15 @@ export interface NewSkillPanelProps {
29
29
  existingSkills: string[];
30
30
  /** Fired once the file exists; the host dialog closes on it. */
31
31
  onCreated(): void;
32
+ /**
33
+ * Follows the panel's in-flight state, for a host that can dismiss it. A
34
+ * create that is already running does not stop when this panel unmounts —
35
+ * it finishes, and (direct case) NAVIGATES. A host dialog that stayed
36
+ * closable while that was pending let someone dismiss "New skill" and be
37
+ * carried off the page seconds later; with this it holds its close doors
38
+ * shut (`Dialog.busy`) until the request settles.
39
+ */
40
+ onBusyChange?(busy: boolean): void;
32
41
  }
33
42
 
34
43
  /**
@@ -49,6 +58,7 @@ export function NewSkillPanel({
49
58
  destination,
50
59
  existingSkills,
51
60
  onCreated,
61
+ onBusyChange,
52
62
  }: NewSkillPanelProps) {
53
63
  const { user } = useAuth();
54
64
  const reloadLibrary = useLibraryReload();
@@ -81,6 +91,7 @@ export function NewSkillPanel({
81
91
  async function create() {
82
92
  if (!canCreate || !user) return;
83
93
  setBusy(true);
94
+ onBusyChange?.(true);
84
95
  try {
85
96
  const created = await createEmptySkill({
86
97
  ...('personal' in destination
@@ -93,6 +104,12 @@ export function NewSkillPanel({
93
104
  // The library is where the result lives, whichever way it went — nobody
94
105
  // is bounced to the Knowledge app to meet the thing they just made.
95
106
  reloadLibrary();
107
+ // Settled, and said so BEFORE handing back: the panel owns the whole
108
+ // lifecycle it advertises. Leaving the success case to the host works
109
+ // only while every host remembers to clear the flag in `onCreated` — a
110
+ // host that merely closes its dialog there (as `PersonalAddDialog` does
111
+ // with `onCreated={onClose}`) would stay busy forever.
112
+ onBusyChange?.(false);
96
113
  onCreated();
97
114
  if (created.direct) {
98
115
  // Straight into the new skill's page, editor open: an empty SKILL.md
@@ -112,6 +129,7 @@ export function NewSkillPanel({
112
129
  const msg = err instanceof Error ? err.message : String(err);
113
130
  toast(`Couldn't create that skill: ${msg}`, 'danger');
114
131
  setBusy(false);
132
+ onBusyChange?.(false);
115
133
  }
116
134
  }
117
135