@bevel-software/platform-core-frontend 0.20.0 → 0.21.0

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 (35) hide show
  1. package/package.json +2 -2
  2. package/src/modules/access/hooks/useFileAccess.ts +2 -2
  3. package/src/modules/auth/components/LoginScreen.tsx +1 -0
  4. package/src/modules/git/components/BranchSwitcher.tsx +9 -3
  5. package/src/modules/git/components/FileComparisonPanel.tsx +10 -4
  6. package/src/modules/git/components/PullNeededBanner.tsx +2 -2
  7. package/src/modules/git/services/error-messages.ts +2 -2
  8. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +110 -9
  9. package/src/modules/layout/components/SidebarFrame.tsx +26 -9
  10. package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +11 -0
  11. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +3 -0
  12. package/src/modules/library/__tests__/PluginIndexRow.test.tsx +146 -0
  13. package/src/modules/library/__tests__/PluginPage.test.tsx +110 -3
  14. package/src/modules/library/__tests__/ToolPage.test.tsx +20 -0
  15. package/src/modules/library/__tests__/name-with-badges.test.tsx +16 -3
  16. package/src/modules/library/__tests__/title-row-actions.ts +43 -0
  17. package/src/modules/library/components/PluginIndexRow.tsx +37 -20
  18. package/src/modules/library/components/PluginPage.tsx +115 -3
  19. package/src/modules/library/components/tool-page/ToolPage.tsx +25 -17
  20. package/src/modules/library/routes/library-paths.ts +9 -2
  21. package/src/modules/library/services/plugins.api.ts +45 -0
  22. package/src/modules/library/utils/plugin-summary.ts +7 -2
  23. package/src/modules/onboarding/__tests__/onboarding.test.tsx +43 -0
  24. package/src/modules/onboarding/components/ConnectAgentPill.tsx +13 -2
  25. package/src/modules/pr/components/OpenChangeRequestDialog.tsx +3 -2
  26. package/src/modules/review/components/ReviewPanel.tsx +2 -2
  27. package/src/modules/workspace/components/FileExplorer.tsx +4 -2
  28. package/src/modules/workspace/components/FileViewer.tsx +8 -3
  29. package/src/modules/workspace/components/KbDocumentShell.tsx +50 -8
  30. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +49 -0
  31. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +49 -1
  32. package/src/modules/workspace/hooks/useWorkspaceState.ts +7 -2
  33. package/src/modules/workspace/utils/fileTree.ts +2 -1
  34. package/src/modules/workspace/utils/treeConfirm.ts +7 -3
  35. package/src/shared/theme/measure.ts +23 -2
@@ -12,6 +12,7 @@ import type { LibraryData } from '../hooks/useLibraryData';
12
12
  import type { ToolSecrets } from '../../secrets-vault/services/tool-secrets.api';
13
13
  import type { PluginSummary } from '../services/plugins.api';
14
14
  import { withAuth } from './auth-harness';
15
+ import { expectMenuAtTheEndOfTheTitleRow } from './title-row-actions';
15
16
 
16
17
  /**
17
18
  * The plugin page: which view a caller gets, what the page says about who runs
@@ -30,6 +31,7 @@ const pluginsMock = vi.hoisted(() => ({
30
31
  requestPluginAccess: vi.fn(),
31
32
  unlinkSkill: vi.fn(),
32
33
  renamePlugin: vi.fn(),
34
+ repairPluginLinks: vi.fn(),
33
35
  }));
34
36
  const libApiMock = vi.hoisted(() => ({ removeLibraryItem: vi.fn() }));
35
37
  vi.mock('../services/library.api', async (importOriginal) => ({
@@ -45,6 +47,7 @@ vi.mock('../services/plugins.api', () => ({
45
47
  requestPluginAccess: pluginsMock.requestPluginAccess,
46
48
  unlinkSkill: pluginsMock.unlinkSkill,
47
49
  renamePlugin: pluginsMock.renamePlugin,
50
+ repairPluginLinks: pluginsMock.repairPluginLinks,
48
51
  AlreadyReadableError: class AlreadyReadableError extends Error {},
49
52
  }));
50
53
 
@@ -234,6 +237,9 @@ describe('PluginPage', () => {
234
237
  pluginsMock.reconcileJoinRequest.mockResolvedValue(false);
235
238
  pluginsMock.requestPluginAccess.mockResolvedValue(undefined);
236
239
  pluginsMock.renamePlugin.mockReset();
240
+ // The page-open repair: nothing to do, unless a test says otherwise.
241
+ pluginsMock.repairPluginLinks.mockReset();
242
+ pluginsMock.repairPluginLinks.mockResolvedValue({ repaired: [], skipped: [] });
237
243
  });
238
244
 
239
245
  it('lets a plugin MANAGER remove a skill, behind a confirm that says who loses it', async () => {
@@ -327,6 +333,19 @@ describe('PluginPage', () => {
327
333
  expect(screen.getByTestId('library-card-skill-outreach')).toBeInTheDocument();
328
334
  });
329
335
 
336
+ /**
337
+ * The other half of the shared criterion — see `title-row-actions.ts`. This
338
+ * page is the reference the tool page was brought into line with, so it is
339
+ * the one that must not drift: if this fails, the helper is describing the
340
+ * plugin page's old shape and the tool page has been pinned to it.
341
+ */
342
+ it('carries its ⋯ at the right end of the title row', async () => {
343
+ pluginsMock.listPlugins.mockResolvedValue([gtm({ name: 'gtm', displayName: 'GTM' })]);
344
+ renderPlugin('gtm');
345
+ await screen.findByRole('heading', { name: 'GTM', level: 1 });
346
+ expectMenuAtTheEndOfTheTitleRow();
347
+ });
348
+
330
349
  it('offers Rename plugin to a MANAGER, and moves to the new identity once the rename lands', async () => {
331
350
  pluginsMock.listPlugins.mockResolvedValue([gtm({ name: 'gtm', displayName: 'GTM', canWrite: true })]);
332
351
  pluginsMock.renamePlugin.mockResolvedValue({ name: 'go-to-market', displayName: 'GTM', rewritten: [] });
@@ -554,18 +573,106 @@ describe('PluginPage', () => {
554
573
  });
555
574
 
556
575
  it("warns about a broken link even when the caller cannot read that skill — the server's count wins", async () => {
557
- // The manager the missing grant locks out: the skill is NOT in their
576
+ // The member the missing grant locks out: the skill is NOT in their
558
577
  // catalog, so nothing in `items` could say a link is broken. The summary
559
- // carries the index's own count.
578
+ // carries the index's own count. (A MANAGER never gets this far — their
579
+ // page repairs the links first; see the repair tests below.)
560
580
  dataMock.useLibraryData.mockReturnValue({ ...CATALOG, tools: [connectedTool()] });
561
- pluginsMock.listPlugins.mockResolvedValue([gtm({ canWrite: true, brokenLinks: 2 })]);
581
+ pluginsMock.listPlugins.mockResolvedValue([gtm({ canWrite: false, brokenLinks: 2 })]);
562
582
  renderPlugin('GTM');
563
583
  expect(
564
584
  await screen.findByText(/2 linked skills can't be read by GTM's members: their access rules no longer name them\. Repair the links from the skill pages\./),
565
585
  ).toBeInTheDocument();
586
+ expect(pluginsMock.repairPluginLinks).not.toHaveBeenCalled();
566
587
  expect(screen.queryByText(/integrations? needs? setup/)).not.toBeInTheDocument();
567
588
  });
568
589
 
590
+ it('repairs the plugin\'s links on open for a MANAGER — once, silently, and then reloads', async () => {
591
+ dataMock.useLibraryData.mockReturnValue({ ...CATALOG, tools: [connectedTool()] });
592
+ pluginsMock.listPlugins.mockResolvedValue([gtm({ canWrite: true, brokenLinks: 1 })]);
593
+ pluginsMock.repairPluginLinks.mockResolvedValue({ repaired: ['Skills/Eng/deploy'], skipped: [] });
594
+ vi.mocked(CATALOG.reload).mockClear();
595
+ renderPlugin('GTM');
596
+
597
+ await waitFor(() => expect(pluginsMock.repairPluginLinks).toHaveBeenCalledWith('GTM'));
598
+ // Once per page open: the reload it asks for must not run it again.
599
+ await waitFor(() => expect(CATALOG.reload).toHaveBeenCalled());
600
+ expect(pluginsMock.repairPluginLinks).toHaveBeenCalledTimes(1);
601
+ // Nothing is said about a repaired link — not a banner, not a toast. The
602
+ // count the summary was serving was taken before the repair wrote.
603
+ expect(screen.queryByText(/can't be read by GTM's members/)).not.toBeInTheDocument();
604
+ });
605
+
606
+ it('names the skill and its editors for a link the manager cannot repair', async () => {
607
+ dataMock.useLibraryData.mockReturnValue({ ...CATALOG, tools: [connectedTool()] });
608
+ pluginsMock.listPlugins.mockResolvedValue([gtm({ canWrite: true, brokenLinks: 1 })]);
609
+ pluginsMock.repairPluginLinks.mockResolvedValue({
610
+ repaired: [],
611
+ skipped: [
612
+ {
613
+ root: 'Skills/Eng/deploy',
614
+ reason: 'needs-skill-write',
615
+ skills: [{ path: 'Skills/Eng/deploy', name: 'deploy' }],
616
+ editors: { roles: ['Eng'], users: [{ name: 'Eve', email: 'eve@x.io' }] },
617
+ },
618
+ ],
619
+ });
620
+ vi.mocked(CATALOG.reload).mockClear();
621
+ renderPlugin('GTM');
622
+
623
+ const banner = await screen.findByText(
624
+ "deploy can't be read by GTM's members. Eng and Eve can repair the link from the skill page.",
625
+ );
626
+ expect(banner.closest('[role="status"]')).toHaveClass('bg-urgent-soft');
627
+ // The count-shaped sentence is gone: this one names what is actually left.
628
+ expect(screen.queryByText(/access rules no longer name them/)).not.toBeInTheDocument();
629
+ // Nothing was written, so nothing is reloaded.
630
+ expect(CATALOG.reload).not.toHaveBeenCalled();
631
+ });
632
+
633
+ it('says a denied link is denied, not merely unrepaired — Repair would write nothing', async () => {
634
+ dataMock.useLibraryData.mockReturnValue({ ...CATALOG, tools: [connectedTool()] });
635
+ pluginsMock.listPlugins.mockResolvedValue([gtm({ canWrite: true, brokenLinks: 1 })]);
636
+ pluginsMock.repairPluginLinks.mockResolvedValue({
637
+ repaired: [],
638
+ skipped: [
639
+ {
640
+ root: 'Skills/Eng/deploy',
641
+ reason: 'denied',
642
+ skills: [{ path: 'Skills/Eng/deploy', name: 'deploy' }],
643
+ editors: { roles: [], users: [{ name: 'Mia', email: 'mia@x.io' }] },
644
+ },
645
+ ],
646
+ });
647
+ vi.mocked(CATALOG.reload).mockClear();
648
+ renderPlugin('GTM');
649
+
650
+ const banner = await screen.findByText(
651
+ "deploy is denied to GTM's members in its access rules. Mia can change that from the skill page.",
652
+ );
653
+ expect(banner.closest('[role="status"]')).toHaveClass('bg-urgent-soft');
654
+ expect(CATALOG.reload).not.toHaveBeenCalled();
655
+ });
656
+
657
+ it('asks for no repair on a plugin whose links live in an external format', async () => {
658
+ pluginsMock.listPlugins.mockResolvedValue([
659
+ gtm({ canWrite: true, linksAreManaged: false, brokenLinks: 0 }),
660
+ ]);
661
+ renderPlugin('GTM');
662
+ await screen.findByRole('heading', { name: 'GTM', level: 1 });
663
+ expect(pluginsMock.repairPluginLinks).not.toHaveBeenCalled();
664
+ });
665
+
666
+ it('falls back to the served count when the repair itself could not be asked for', async () => {
667
+ dataMock.useLibraryData.mockReturnValue({ ...CATALOG, tools: [connectedTool()] });
668
+ pluginsMock.listPlugins.mockResolvedValue([gtm({ canWrite: true, brokenLinks: 1 })]);
669
+ pluginsMock.repairPluginLinks.mockRejectedValue(new Error('offline'));
670
+ renderPlugin('GTM');
671
+ expect(
672
+ await screen.findByText(/1 linked skill can't be read by GTM's members/),
673
+ ).toBeInTheDocument();
674
+ });
675
+
569
676
  it('pluralises the attention banner', async () => {
570
677
  dataMock.useLibraryData.mockReturnValue({
571
678
  ...CATALOG,
@@ -61,6 +61,7 @@ vi.mock('../utils/navigate-external', () => ({ navigateExternal: vi.fn() }));
61
61
 
62
62
  import { ToolPage } from '../components/tool-page/ToolPage';
63
63
  import { NAME_MIN_WIDTH } from '../components/NameWithBadges';
64
+ import { expectMenuAtTheEndOfTheTitleRow } from './title-row-actions';
64
65
  import { TOOL_CREDENTIALS_STALE_EVENT } from '../../../core/events';
65
66
 
66
67
  const GITHUB: ToolSecrets = {
@@ -214,6 +215,25 @@ describe('ToolPage: frame', () => {
214
215
  expect(row.className).toContain('overflow-hidden');
215
216
  });
216
217
 
218
+ /**
219
+ * The `⋯` belongs at the right end of the title row, where the plugin page
220
+ * and the skill page put their trailing controls. It used to be the last
221
+ * child of this page's `<header>` — below the description, on a line of its
222
+ * own under the back link, left-aligned — so the one gesture the three item
223
+ * pages share was in a different place on one of them.
224
+ *
225
+ * Asserted through the shared helper, which `PluginPage.test.tsx` calls
226
+ * too: the criterion is a comparison, so it is written once.
227
+ */
228
+ // The owner's case — the same menu with `Delete tool` in it — is asserted
229
+ // in `DeleteToolDialog.test.tsx`, which is the file that can actually own
230
+ // the plugin holding this tool.
231
+ it('puts the ⋯ at the right end of the title row, where the plugin page has it', async () => {
232
+ renderPage();
233
+ await screen.findByRole('heading', { name: 'heyreach', level: 1 });
234
+ expectMenuAtTheEndOfTheTitleRow();
235
+ });
236
+
217
237
  it('shows no kicker for a legacy ungrouped path either', async () => {
218
238
  secretsMock.listToolSecrets.mockResolvedValue([
219
239
  { ...GITHUB, slug: 'slack', name: 'slack', path: 'Tools/slack.tool' },
@@ -226,7 +226,17 @@ describe('LibraryCard: the name keeps its width', () => {
226
226
  });
227
227
 
228
228
  describe('PluginIndexRow: the same rule, one line tall', () => {
229
- it('holds a long plugin name to the floor beside its chips', () => {
229
+ /**
230
+ * The row is the ONE caller that keeps the name and hands the badges back.
231
+ *
232
+ * A card's chips sit beside its name and drop under it when the two stop
233
+ * fitting, and `NAME_MIN_WIDTH` is the floor that decides when. An index
234
+ * row has somewhere better to put them — its own right edge, beside the
235
+ * counts — so the name never competes with a chip and is never given a
236
+ * floor to defend itself with. A floor here would be a claim on space with
237
+ * nothing left on the line to give it back.
238
+ */
239
+ it('gives the name the whole title line, chips or no chips', () => {
230
240
  render(
231
241
  <PluginIndexRow
232
242
  label={LONG_NAME}
@@ -238,8 +248,9 @@ describe('PluginIndexRow: the same rule, one line tall', () => {
238
248
 
239
249
  const name = screen.getByTitle(LONG_NAME);
240
250
  expect(name).toHaveTextContent(LONG_NAME);
241
- expect(name.className).toContain(NAME_MIN_WIDTH);
242
- expect(name.parentElement!.className).toContain('flex-wrap');
251
+ expect(name.className).not.toContain(NAME_MIN_WIDTH);
252
+ // And the chip is not on that line at all — it went to the row's edge.
253
+ expect(name.parentElement).not.toContainElement(screen.getByText('Owner'));
243
254
  });
244
255
 
245
256
  it('is laid out in a track that can actually run short', () => {
@@ -265,6 +276,8 @@ describe('PluginIndexRow: the same rule, one line tall', () => {
265
276
  it('says the whole name on a row that carries no chip at all', () => {
266
277
  // The row used to pass its label through as a bare string, so a plugin
267
278
  // whose name the row had to truncate had nowhere to finish saying it.
279
+ // `NameWithBadges` is still what gives it the `title`, which is the only
280
+ // reason the row still goes through it now that the chips have left.
268
281
  render(<PluginIndexRow label={LONG_NAME} meta="4 skills · 2 tools" onOpen={vi.fn()} />);
269
282
  const name = screen.getByTitle(LONG_NAME);
270
283
  expect(name).toHaveTextContent(LONG_NAME);
@@ -0,0 +1,43 @@
1
+ import { expect } from 'vitest';
2
+ import { screen, within } from '@testing-library/react';
3
+ import { PAGE_HEADER_TESTID } from '../../../shared/theme/header';
4
+
5
+ /**
6
+ * Where an item page's `⋯` goes: the right end of the title row.
7
+ *
8
+ * Shared between `PluginPage.test.tsx` and `ToolPage.test.tsx` because the
9
+ * acceptance criterion is a COMPARISON — "the same position and size as on the
10
+ * plugin page" — and two hand-written copies of it would be two things that can
11
+ * drift apart while both stay green. One function, asserted on both pages: the
12
+ * day one of them moves its menu, exactly one of the two callers fails and the
13
+ * other says what it was supposed to look like.
14
+ *
15
+ * The tool page used to render `PageActions` as the last child of its
16
+ * `<header>`, after the description paragraph — a menu on its own line under
17
+ * the way back, at the left margin, which is where nothing else on any page
18
+ * is.
19
+ *
20
+ * Size needs no assertion of its own: it is the same `PageActions` component,
21
+ * so the only thing that could differ is where it is put. That is what this
22
+ * pins — in the band, last, in a group that neither shrinks nor wraps.
23
+ */
24
+ export function expectMenuAtTheEndOfTheTitleRow(): void {
25
+ const band = screen.getByTestId(PAGE_HEADER_TESTID);
26
+ const menu = within(band).getByRole('button', { name: 'More actions' });
27
+
28
+ // LAST in the band. The title before it carries `flex-1`, so "last" is what
29
+ // puts the group against the row's right edge — there is no `ml-auto` doing
30
+ // it invisibly from somewhere else.
31
+ expect(band.lastElementChild).toContainElement(menu);
32
+
33
+ // The group the plugin page puts it in: fixed width, on the band's line.
34
+ const group = band.lastElementChild as HTMLElement;
35
+ expect(group.className).toContain('flex');
36
+ expect(group.className).toContain('flex-none');
37
+ expect(group.className).toContain('items-center');
38
+
39
+ // And nothing else in the page's header renders one — a second `⋯` under
40
+ // the back link is the bug this replaced.
41
+ const header = band.closest('header') ?? band.parentElement!;
42
+ expect(within(header).getAllByRole('button', { name: 'More actions' })).toHaveLength(1);
43
+ }
@@ -7,10 +7,16 @@ import { NameWithBadges } from './NameWithBadges';
7
7
  export interface PluginIndexRowProps {
8
8
  label: string;
9
9
  /**
10
- * Beside the label — the `Owner` and `Private` chips. Beside it while there
11
- * is room for both: past that the chips drop below the name rather than go
12
- * on taking width from it (see `NameWithBadges`), so a row with chips can
13
- * be two lines tall on a narrow window.
10
+ * The `Owner` and `Private` chips — LEADING the row's trailing group, on
11
+ * the counts' line.
12
+ *
13
+ * They used to sit beside the label, through `NameWithBadges`, and drop
14
+ * under the name when the two stopped fitting. That is the right rule for a
15
+ * card, whose name is the only thing on its row; on an index row it put the
16
+ * pill one line above the counts it belongs with, on the left, hanging off
17
+ * a title block that is two lines tall the moment a plugin has a
18
+ * description. The chips qualify the row, not the name, so they travel with
19
+ * the rest of what the row's right edge says.
14
20
  */
15
21
  badge?: ReactNode;
16
22
  description?: string;
@@ -39,15 +45,23 @@ export interface PluginIndexRowProps {
39
45
  * The whole row is the target, which is why it is a `<button>` and not a card
40
46
  * with a link inside it: every row here means exactly one thing, "go there".
41
47
  * Counts live in `meta` as plain text so the row's accessible name reads as the
42
- * sentence it looks like ("GTM Run by Olga Ivanova 4 skills · 2 tools").
48
+ * sentence it looks like ("GTM Run by Olga Ivanova Owner 4 skills · 2 tools") —
49
+ * the chips are in that group too, and read in the order they are shown.
50
+ *
51
+ * The row's right edge is ONE line: chips, counts and the `…`, centred against
52
+ * the row however tall the title block is. `ListRow` already spaces and
53
+ * centres its `meta` group (`ml-auto flex flex-none items-center`), so
54
+ * everything that belongs at that edge is passed there — which is why `badge`
55
+ * goes to `meta` and not, as it once did, beside the name.
43
56
  *
44
57
  * When the row has `actions`, a `…` rides its right edge — a SIBLING of the row
45
- * button, since the row is the button (see `ItemMenuFrame`). The row then keeps
46
- * the trailing room clear for it (`pr-10`) instead of letting the menu paint
47
- * over the counts and the Locked chip it is right beside. The frame itself is
48
- * always there: which verbs a row has depends on answers that arrive after the
49
- * first paint, and a frame that came with them would remount the row under
50
- * whoever was already using it.
58
+ * button, since the row is the button (see `ItemMenuFrame`). It is positioned
59
+ * on the row's mid-line, so it is already ON that one line; what it is not is
60
+ * IN the flex flow, so the row keeps the trailing room clear for it (`pr-10`)
61
+ * instead of letting the menu paint over the counts and the Locked chip it is
62
+ * right beside. The frame itself is always there: which verbs a row has
63
+ * depends on answers that arrive after the first paint, and a frame that came
64
+ * with them would remount the row under whoever was already using it.
51
65
  */
52
66
  export function PluginIndexRow({
53
67
  label,
@@ -64,18 +78,21 @@ export function PluginIndexRow({
64
78
  density="row"
65
79
  onClick={onOpen}
66
80
  className={cn(actions && actions.length > 0 && 'pr-10')}
67
- // The same rule a card's name lives by, and for the same reason: a row
68
- // narrowed by its counts used to spend all of its shortfall on the
69
- // plugin's name while `Owner` and `Private` kept every pixel they
70
- // asked for. Through `NameWithBadges` the chips drop to a second line
71
- // before the name goes under a readable width — and the name carries
72
- // its full self in `title` even on a row that has no chips at all,
73
- // which the bare string it used to be could not.
74
- label={<NameWithBadges name={label} badges={badge} />}
81
+ // No badges here any more — they are part of the trailing group below,
82
+ // so the name has the whole title line to truncate into and needs no
83
+ // floor to defend it. `NameWithBadges` stays for what it still does
84
+ // that a bare string cannot: the name carries its full self in `title`,
85
+ // so a plugin whose name does not fit can still be read.
86
+ label={<NameWithBadges name={label} />}
75
87
  description={description}
88
+ // One line at the row's right edge, in reading order: what this plugin
89
+ // is to you, then how much is in it, then the state of your access.
90
+ // `ListRow` centres the group against the row, so a two-line title
91
+ // block moves it not at all.
76
92
  meta={
77
- meta || trailing ? (
93
+ badge || meta || trailing ? (
78
94
  <>
95
+ {badge}
79
96
  {meta && <span className="whitespace-nowrap tabular-nums">{meta}</span>}
80
97
  {trailing}
81
98
  </>
@@ -14,6 +14,8 @@ import {
14
14
  urlForLibraryItem,
15
15
  } from '../routes/library-paths';
16
16
  import { pluginLabel, primaryFolderOf } from '../utils/plugin-summary';
17
+ import { joinNames } from '../utils/names';
18
+ import { repairPluginLinks, type LinkRepairReport, type UnrepairedLink } from '../services/plugins.api';
17
19
  import { RenamePluginDialog } from './RenamePluginDialog';
18
20
  import { PluginJoinRequests } from './PluginJoinRequests';
19
21
  import { useWorkspace } from '../../workspace/state/workspace.context';
@@ -123,6 +125,19 @@ export function PluginPage() {
123
125
  return () => window.clearTimeout(timer);
124
126
  }, [refreshState]);
125
127
 
128
+ /**
129
+ * What the page-open repair did — null until it has answered, and left null
130
+ * for a viewer who never runs one (see the effect below). Once it is in, it
131
+ * is the truth about this plugin's links: the served `brokenLinks` was
132
+ * counted before the repair wrote anything.
133
+ */
134
+ const [repairReport, setRepairReport] = useState<LinkRepairReport | null>(null);
135
+ /**
136
+ * The repair could not even be asked for. Then — and only then — the page
137
+ * falls back to the banner it showed before this existed: the served count
138
+ * is all anyone knows.
139
+ */
140
+ const [repairFailed, setRepairFailed] = useState(false);
126
141
  /** The card being removed, while its confirm dialog is up. */
127
142
  const [removing, setRemoving] = useState<LibraryItem | null>(null);
128
143
  /** Whether the plugin's own delete confirmation is up. */
@@ -134,6 +149,49 @@ export function PluginPage() {
134
149
  () => data.pluginSummaries.find((g) => g.name === plugin) ?? null,
135
150
  [data.pluginSummaries, plugin],
136
151
  );
152
+
153
+ /**
154
+ * THE automatic repair: opening this page as someone who may write the
155
+ * plugin writes back the grants of every link that lost them and that this
156
+ * person may also write. Silent — a repaired link shows nothing at all; what
157
+ * could not be repaired becomes the banner below.
158
+ *
159
+ * Why the page and not the server's read path: the commit lands in the
160
+ * VIEWER's name, so it needs a person, and a page open is the one moment a
161
+ * person with both verbs is known to be here. Why once — `repairedFor` keys
162
+ * the run on the plugin, so a re-render, a reload of the catalog (which this
163
+ * effect itself causes) or a summary arriving late cannot run it twice; the
164
+ * backend's link locks serialise two people opening the page at the same
165
+ * moment, and the second finds the lines already there and writes nothing.
166
+ *
167
+ * A failure is not the reader's problem to act on: the report stays null and
168
+ * the page falls back to the banner it has always shown.
169
+ */
170
+ const { reload, reloadPlugins } = data;
171
+ const repairedFor = useRef<string | null>(null);
172
+ const canRepairLinks = summary?.canWrite === true && summary.linksAreManaged !== false;
173
+ useEffect(() => {
174
+ if (!canRepairLinks || repairedFor.current === plugin) return;
175
+ repairedFor.current = plugin;
176
+ let live = true;
177
+ void repairPluginLinks(plugin)
178
+ .then((report) => {
179
+ if (!live) return;
180
+ setRepairReport(report);
181
+ // Only a write is worth a refetch: the catalog and the summaries carry
182
+ // the link health this just changed.
183
+ if (report.repaired.length > 0) {
184
+ reload();
185
+ reloadPlugins();
186
+ }
187
+ })
188
+ .catch(() => {
189
+ if (live) setRepairFailed(true);
190
+ });
191
+ return () => {
192
+ live = false;
193
+ };
194
+ }, [canRepairLinks, plugin, reload, reloadPlugins]);
137
195
  // Inline AND linked: a shared skill linked from this plugin's manifest is
138
196
  // one of its skills. A link whose grant went missing carries the amber
139
197
  // "needs setup" foot note here — the one place the plugin's members look.
@@ -154,6 +212,16 @@ export function PluginPage() {
154
212
  // plugin's members out of a skill NOW, so it outranks an integration the
155
213
  // reader has not connected for themselves.
156
214
  const { total: attention, brokenLinks, warnings: warningCount } = attentionOf(data.items, plugin, data.pluginSummaries);
215
+ /** Links the page-open repair could not put back — the banner's own list. */
216
+ const unrepairedLinks = repairReport?.skipped ?? [];
217
+ /**
218
+ * Whether the served count is still the best thing this page can say. It is
219
+ * not, for a plugin writer who is having their links repaired: the count was
220
+ * taken before the repair wrote anything, so printing it would name links
221
+ * that are already fixed. They get the report's list instead, once it lands.
222
+ */
223
+ const showServedBrokenLinks =
224
+ brokenLinks > 0 && (!canRepairLinks || repairFailed) && unrepairedLinks.length === 0;
157
225
  const integrationsNeedingSetup = attention - brokenLinks - warningCount;
158
226
  const definitionWarnings = summary?.warnings ?? [];
159
227
  // What the Skills band actually renders. The filter is a VIEW over the band,
@@ -361,7 +429,27 @@ export function PluginPage() {
361
429
  />
362
430
  )}
363
431
 
364
- {brokenLinks > 0 && (
432
+ {/* What the repair could not put back, one line per skill, naming the
433
+ people who can. A viewer whose repair is still in flight — or who
434
+ repaired everything — is shown nothing at all: the whole point of
435
+ repairing on open is that a link a writer can fix never becomes a
436
+ sentence somebody has to read. Everyone else (a reader, or a writer
437
+ whose repair could not even be asked for) gets the count that was
438
+ served, exactly as before. */}
439
+ {unrepairedLinks.length > 0 && (
440
+ <Banner role="status" tone="urgent" className="mt-4">
441
+ <ul className="grid gap-1">
442
+ {unrepairedLinks.flatMap((link) =>
443
+ link.skills.map((skill) => (
444
+ <li key={`${link.root}:${skill.path}`}>
445
+ {unrepairedText(link, skill.name, label)}
446
+ </li>
447
+ )),
448
+ )}
449
+ </ul>
450
+ </Banner>
451
+ )}
452
+ {showServedBrokenLinks && (
365
453
  <Banner role="status" tone="urgent" className="mt-4">
366
454
  {`${brokenLinks} ${
367
455
  brokenLinks === 1
@@ -604,6 +692,30 @@ export function PluginPage() {
604
692
  );
605
693
  }
606
694
 
695
+ /**
696
+ * Who the banner tells the reader to ask — the roles first, then the people,
697
+ * spoken the way a person lists them.
698
+ *
699
+ * "Its editors" is not a placeholder for a list that failed to load: a skill
700
+ * root whose access file names nobody is still writable by the platform's
701
+ * admins through the rescue on `access.md`, so the sentence stays true and
702
+ * stays actionable when the list comes back empty.
703
+ */
704
+ function editorsText(link: UnrepairedLink): string {
705
+ return joinNames([...link.editors.roles, ...link.editors.users.map((u) => u.name)]) || 'Its editors';
706
+ }
607
707
 
608
-
609
-
708
+ /**
709
+ * The one line the banner says about a link the repair left broken. Two
710
+ * sentences, by what is actually wrong: a link whose grant lines are missing
711
+ * is repaired from the skill page; a link whose lines are there and denied
712
+ * beside them is not — Repair would write nothing, and the person who can
713
+ * act has to remove the deny.
714
+ */
715
+ function unrepairedText(link: UnrepairedLink, skill: string, plugin: string): string {
716
+ const who = editorsText(link);
717
+ if (link.reason === 'denied') {
718
+ return `${skill} is denied to ${plugin}'s members in its access rules. ${who} can change that from the skill page.`;
719
+ }
720
+ return `${skill} can't be read by ${plugin}'s members. ${who} can repair the link from the skill page.`;
721
+ }
@@ -201,29 +201,37 @@ export function ToolPage({
201
201
  name={tool.name}
202
202
  nameClassName="text-display font-semibold text-ink"
203
203
  />
204
+ {/* No `Manage access` here, deliberately. Access is decided at the
205
+ PLUGIN — a tool inherits its folder's `access.md`, so an editor
206
+ on this page would either duplicate the plugin's one or quietly
207
+ write a per-file override that nobody looking at the plugin
208
+ would see. The plugin's `Share` panel is the single place.
209
+
210
+ The `⋯` menu, though, is the same one the plugin page carries,
211
+ and now in the same PLACE: the end of the title row, in the same
212
+ `flex flex-none items-center gap-1` group `PluginPage` puts it
213
+ in, so the three item pages answer the same gesture at the same
214
+ point on the screen. It used to be the last child of this
215
+ `<header>`, below the description — a menu on its own line under
216
+ the way back, which is where nothing else on any page is.
217
+ `onAdd` is absent: there is nothing to add to a tool. */}
218
+ <div className="flex flex-none items-center gap-1">
219
+ <PageActions
220
+ onCopyLink={() => copyToClipboard(window.location.href)}
221
+ // The OWNER's verb, and the same verdict the DELETE route
222
+ // enforces (ownership of the plugin holding the tool) — so the
223
+ // item appears for exactly the people the backend will let
224
+ // through.
225
+ onDelete={canDelete ? () => setDeleteOpen(true) : undefined}
226
+ deleteLabel="Delete tool"
227
+ />
228
+ </div>
204
229
  </div>
205
230
  {page.detail?.description && (
206
231
  <p className="mt-1.5 max-w-[56ch] text-lede text-ink-muted">
207
232
  {page.detail.description}
208
233
  </p>
209
234
  )}
210
- {/* No `Manage access` here, deliberately. Access is decided at the
211
- PLUGIN — a tool inherits its folder's `access.md`, so an editor on
212
- this page would either duplicate the plugin's one or quietly write a
213
- per-file override that nobody looking at the plugin would see. The
214
- plugin's `Share` panel is the single place.
215
-
216
- The `⋯` menu, though, is the same one the plugin page carries, in
217
- the same spot — Delete belongs where people already look for it.
218
- `onAdd` is absent: there is nothing to add to a tool. */}
219
- <PageActions
220
- onCopyLink={() => copyToClipboard(window.location.href)}
221
- // The OWNER's verb, and the same verdict the DELETE route enforces
222
- // (ownership of the plugin holding the tool) — so the item appears
223
- // for exactly the people the backend will let through.
224
- onDelete={canDelete ? () => setDeleteOpen(true) : undefined}
225
- deleteLabel="Delete tool"
226
- />
227
235
  </header>
228
236
 
229
237
  {actionError && (
@@ -1,4 +1,11 @@
1
- import { DEFAULT_BRANCH, PLUGINS_DIR, SKILLS_DIR, pluginOfPath, isPersonalPluginFolder } from '@bevel-software/platform-shared';
1
+ import {
2
+ DEFAULT_BRANCH,
3
+ PLUGINS_DIR,
4
+ SKILLS_DIR,
5
+ currentKbLayout,
6
+ pluginOfPath,
7
+ isPersonalPluginFolder,
8
+ } from '@bevel-software/platform-shared';
2
9
  import { matchPath } from 'react-router-dom';
3
10
  import { kbFileUrl } from '../../workspace/routing/kb-routes';
4
11
  import type { LibraryFilter } from '../utils/status';
@@ -218,7 +225,7 @@ export function libraryHomeForItemPath(
218
225
  label: string;
219
226
  path: string;
220
227
  } {
221
- const folder = pluginOfPath(repoRelativePath);
228
+ const folder = pluginOfPath(repoRelativePath, currentKbLayout());
222
229
  // A personal shelf is decided by the FOLDER, whatever identity the caller
223
230
  // resolved (a personal item's identity is null: a shelf is not a plugin).
224
231
  if (folder !== null && isPersonalPluginFolder(folder)) {
@@ -247,6 +247,51 @@ export async function repairSkillLink(plugin: string, skillPath: string): Promis
247
247
  });
248
248
  }
249
249
 
250
+ /** Who may edit a skill root's access file — who can repair its link. */
251
+ export interface LinkEditors {
252
+ roles: string[];
253
+ users: { name: string; email: string }[];
254
+ }
255
+
256
+ /** One link the page-open repair left alone, and why — mirrors the backend. */
257
+ export interface UnrepairedLink {
258
+ /** Repo-relative root, as the plugin's manifest declares it. */
259
+ root: string;
260
+ /**
261
+ * `needs-skill-write` — the viewer may not write its access file; `failed`
262
+ * — the write did not land; `denied` — the lines are there and a `deny` of
263
+ * the plugin beside them keeps the link broken, so there is nothing to
264
+ * write and only an editor removing the deny would change it.
265
+ */
266
+ reason: 'needs-skill-write' | 'failed' | 'denied';
267
+ /** The skills the plugin's members still cannot read through it. */
268
+ skills: { path: string; name: string }[];
269
+ /** Who the banner names as able to repair it. */
270
+ editors: LinkEditors;
271
+ }
272
+
273
+ /** What one page-open repair did, and what is still broken. */
274
+ export interface LinkRepairReport {
275
+ repaired: string[];
276
+ skipped: UnrepairedLink[];
277
+ }
278
+
279
+ /**
280
+ * Repair every link of a plugin whose grants are missing — what the plugin
281
+ * page runs, once, on open, for someone who may write the plugin.
282
+ *
283
+ * Silent by design: a repaired link shows nothing, so the only thing the
284
+ * caller does with `repaired` is reload the catalog. `skipped` is the banner.
285
+ * Refused with the ordinary 404 for a caller who may not write the plugin,
286
+ * which is why the page asks only when its summary says they can.
287
+ */
288
+ export async function repairPluginLinks(plugin: string): Promise<LinkRepairReport> {
289
+ const body = await linkCall(`/api/plugins/${encodeURIComponent(plugin)}/links/repair-all`, {
290
+ method: 'POST',
291
+ });
292
+ return body as unknown as LinkRepairReport;
293
+ }
294
+
250
295
  /**
251
296
  * Thrown when a join request is refused because access already landed —
252
297
  * between the page load and the click. Not an error to show: the right