@bevel-software/platform-core-frontend 0.20.0 → 0.22.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 (64) hide show
  1. package/package.json +2 -2
  2. package/src/core/registry.ts +57 -0
  3. package/src/modules/access/__tests__/ManageAccessDialog.request.test.tsx +376 -0
  4. package/src/modules/access/components/AccessRequestControl.tsx +155 -0
  5. package/src/modules/{library → access}/components/AccessRequestsBanner.tsx +62 -24
  6. package/src/modules/access/components/ManageAccessDialog.tsx +81 -4
  7. package/src/modules/access/hooks/useAccessRequests.ts +183 -0
  8. package/src/modules/access/hooks/useFileAccess.ts +2 -2
  9. package/src/modules/access/requests.api.ts +121 -0
  10. package/src/modules/auth/components/LoginScreen.tsx +6 -0
  11. package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +171 -38
  12. package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +34 -19
  13. package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +173 -6
  14. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +155 -98
  15. package/src/modules/git/components/BranchSwitcher.tsx +9 -3
  16. package/src/modules/git/components/FileComparisonPanel.tsx +10 -4
  17. package/src/modules/git/components/PullNeededBanner.tsx +2 -2
  18. package/src/modules/git/services/error-messages.ts +2 -2
  19. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +110 -9
  20. package/src/modules/layout/components/SidebarFrame.tsx +26 -9
  21. package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +11 -0
  22. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +3 -0
  23. package/src/modules/library/__tests__/PluginIndexRow.test.tsx +146 -0
  24. package/src/modules/library/__tests__/PluginPage.test.tsx +110 -3
  25. package/src/modules/library/__tests__/SkillPage.test.tsx +15 -0
  26. package/src/modules/library/__tests__/ToolPage.test.tsx +34 -0
  27. package/src/modules/library/__tests__/name-with-badges.test.tsx +16 -3
  28. package/src/modules/library/__tests__/title-row-actions.ts +95 -0
  29. package/src/modules/library/components/PluginIndexRow.tsx +37 -20
  30. package/src/modules/library/components/PluginJoinRequests.tsx +2 -2
  31. package/src/modules/library/components/PluginPage.tsx +115 -3
  32. package/src/modules/library/components/skill-page/SkillPage.tsx +2 -2
  33. package/src/modules/library/components/tool-page/ToolPage.tsx +36 -18
  34. package/src/modules/library/hooks/useJoinRequests.ts +26 -101
  35. package/src/modules/library/routes/library-paths.ts +9 -2
  36. package/src/modules/library/services/plugins.api.ts +45 -0
  37. package/src/modules/library/utils/plugin-summary.ts +7 -2
  38. package/src/modules/onboarding/__tests__/onboarding.test.tsx +43 -0
  39. package/src/modules/onboarding/components/ConnectAgentPill.tsx +13 -2
  40. package/src/modules/pr/components/OpenChangeRequestDialog.tsx +3 -2
  41. package/src/modules/pr/services/pr-merge.api.ts +10 -2
  42. package/src/modules/review/components/ReviewPanel.tsx +2 -2
  43. package/src/modules/settings/components/DeploymentPage.tsx +22 -0
  44. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +72 -4
  45. package/src/modules/setup/__tests__/setup.first-run.test.tsx +276 -0
  46. package/src/modules/setup/__tests__/setup.github.test.tsx +416 -0
  47. package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +275 -0
  48. package/src/modules/setup/__tests__/setup.repository.test.tsx +373 -0
  49. package/src/modules/setup/__tests__/setup.test.tsx +8 -14
  50. package/src/modules/setup/components/GitHubRepositoryPanel.tsx +369 -0
  51. package/src/modules/setup/components/SetupGate.tsx +1 -0
  52. package/src/modules/setup/components/SetupScreen.tsx +464 -38
  53. package/src/modules/setup/services/setup.api.ts +93 -0
  54. package/src/modules/setup/utils/kept-draft.ts +86 -0
  55. package/src/modules/workspace/components/FileExplorer.tsx +4 -2
  56. package/src/modules/workspace/components/FileViewer.tsx +8 -3
  57. package/src/modules/workspace/components/KbDocumentShell.tsx +50 -8
  58. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +49 -0
  59. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +49 -1
  60. package/src/modules/workspace/hooks/useWorkspaceState.ts +7 -2
  61. package/src/modules/workspace/utils/fileTree.ts +2 -1
  62. package/src/modules/workspace/utils/treeConfirm.ts +7 -3
  63. package/src/shared/components/SlotBoundary.tsx +51 -0
  64. package/src/shared/theme/measure.ts +23 -2
@@ -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,95 @@
1
+ import { expect } from 'vitest';
2
+ import { screen, within } from '@testing-library/react';
3
+ import { PAGE_HEADER_TESTID } from '../../../shared/theme/header';
4
+ import { DOCUMENT_COLUMN } from '../../../shared/theme/measure';
5
+
6
+ /**
7
+ * The one width an item page is allowed to be: the shared document measure,
8
+ * which the Library layout's `<main>` already puts around every page.
9
+ */
10
+ const SHARED_MEASURE = DOCUMENT_COLUMN.split(' ').filter((c) => c.startsWith('max-w-'));
11
+
12
+ /**
13
+ * Where an item page's `⋯` goes: the right end of the title row.
14
+ *
15
+ * Shared between `PluginPage.test.tsx` and `ToolPage.test.tsx` because the
16
+ * acceptance criterion is a COMPARISON — "the same position and size as on the
17
+ * plugin page" — and two hand-written copies of it would be two things that can
18
+ * drift apart while both stay green. One function, asserted on both pages: the
19
+ * day one of them moves its menu, exactly one of the two callers fails and the
20
+ * other says what it was supposed to look like.
21
+ *
22
+ * The tool page used to render `PageActions` as the last child of its
23
+ * `<header>`, after the description paragraph — a menu on its own line under
24
+ * the way back, at the left margin, which is where nothing else on any page
25
+ * is.
26
+ *
27
+ * Size needs no assertion of its own: it is the same `PageActions` component,
28
+ * so the only thing that could differ is where it is put. That is what this
29
+ * pins — in the band, last, in a group that neither shrinks nor wraps: that,
30
+ * plus {@link expectTitleRowSpansTheDocumentColumn} for the row's WIDTH, is
31
+ * the whole of "the same position".
32
+ */
33
+ export function expectMenuAtTheEndOfTheTitleRow(): void {
34
+ const band = screen.getByTestId(PAGE_HEADER_TESTID);
35
+ const menu = within(band).getByRole('button', { name: 'More actions' });
36
+
37
+ // LAST in the band. The title before it carries `flex-1`, so "last" is what
38
+ // puts the group against the row's right edge — there is no `ml-auto` doing
39
+ // it invisibly from somewhere else.
40
+ expect(band.lastElementChild).toContainElement(menu);
41
+
42
+ // The group the plugin page puts it in: fixed width, on the band's line.
43
+ const group = band.lastElementChild as HTMLElement;
44
+ expect(group.className).toContain('flex');
45
+ expect(group.className).toContain('flex-none');
46
+ expect(group.className).toContain('items-center');
47
+
48
+ // And nothing else in the page's header renders one — a second `⋯` under
49
+ // the back link is the bug this replaced.
50
+ const header = band.closest('header') ?? band.parentElement!;
51
+ expect(within(header).getAllByRole('button', { name: 'More actions' })).toHaveLength(1);
52
+
53
+ // Last in a right-aligned row says WHERE ON the row; this says where the row
54
+ // ENDS. Both are needed, and only the pair is the criterion.
55
+ expectTitleRowSpansTheDocumentColumn();
56
+ }
57
+
58
+ /**
59
+ * The title row runs the full width of the shared document column — the page
60
+ * wraps it in no narrower measure of its own.
61
+ *
62
+ * This is the half of "the same position as on the plugin page" that structure
63
+ * alone cannot see, and the half that shipped broken. The tool page put its
64
+ * band, correctly, last-in-row inside a group with the plugin page's exact
65
+ * classes — and rendered it 16px left of the plugin page's, every viewport,
66
+ * because the article around it was `max-w-3xl` (768px) inside the layout's
67
+ * 800px line. Every structural assertion above passed on both pages while the
68
+ * two menus sat at different points on the screen; staging found it with a
69
+ * ruler, which is not a thing this suite can do.
70
+ *
71
+ * So it asserts the CAUSE rather than the pixels: jsdom computes no layout, but
72
+ * the width of a page's title row is decided entirely by which ancestors
73
+ * constrain it, and the layout's `<main>` is the only one entitled to. Anything
74
+ * else between the band and the document is a second column inside the first,
75
+ * and the row cannot reach the same right edge as a page that has none.
76
+ */
77
+ export function expectTitleRowSpansTheDocumentColumn(): void {
78
+ const band = screen.getByTestId(PAGE_HEADER_TESTID);
79
+ const narrowed: string[] = [];
80
+ for (let el = band.parentElement; el && el !== document.body; el = el.parentElement) {
81
+ for (const cls of Array.from(el.classList)) {
82
+ // `DOCUMENT_COLUMN` itself is allowed through: a test that renders the
83
+ // page inside `LibraryLayout` passes the shared measure on the way up,
84
+ // and the shared measure is the one width the row is meant to have.
85
+ if (cls.startsWith('max-w-') && !SHARED_MEASURE.includes(cls)) {
86
+ narrowed.push(`<${el.tagName.toLowerCase()} class="${el.className}">`);
87
+ }
88
+ }
89
+ }
90
+ expect(
91
+ narrowed,
92
+ `The title row is inside a narrower column than the document measure (${SHARED_MEASURE.join(' ')}), ` +
93
+ 'so its right end — and the ⋯ on it — cannot line up with the plugin page\'s.',
94
+ ).toEqual([]);
95
+ }
@@ -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
  </>
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useLayoutEffect } from 'react';
2
2
  import { useJoinRequests } from '../hooks/useJoinRequests';
3
- import { AccessRequestsBanner } from './AccessRequestsBanner';
3
+ import { AccessRequestsBanner } from '../../access/components/AccessRequestsBanner';
4
4
 
5
5
  /**
6
6
  * One plugin's join requests, fetching their own data.
@@ -65,7 +65,7 @@ export function PluginJoinRequests({
65
65
 
66
66
  return (
67
67
  <AccessRequestsBanner
68
- plugin={plugin}
68
+ itemName={plugin}
69
69
  folders={folders}
70
70
  requests={requests.requests}
71
71
  onManage={onManage}
@@ -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
+ }
@@ -51,7 +51,7 @@ import { ownersTextOf, pluginLabel } from '../../utils/plugin-summary';
51
51
  import { neededToolsFor, toolStatus } from '../../utils/status';
52
52
  import { StatusDot } from '../StatusDot';
53
53
  import { SharedViaPlugins } from './SharedViaPlugins';
54
- import { AccessRequestsBanner } from '../AccessRequestsBanner';
54
+ import { AccessRequestsBanner } from '../../../access/components/AccessRequestsBanner';
55
55
  import { useJoinRequests, type JoinRequestsApi } from '../../hooks/useJoinRequests';
56
56
  import { listSkillAccessRequests, reconcileSkillAccessRequest } from '../../services/library.api';
57
57
  import { ManageAccessDialog } from '../../../access/components/ManageAccessDialog';
@@ -710,7 +710,7 @@ export function SkillPage({
710
710
  Manage access opens it, and both are no-ops against ''. */}
711
711
  {canWrite && skillFolderEntry && (
712
712
  <AccessRequestsBanner
713
- plugin={name}
713
+ itemName={name}
714
714
  folders={[skillPath]}
715
715
  requests={accessRequests.requests}
716
716
  onManage={() => setManageTarget(skillFolderEntry)}
@@ -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 && (
@@ -308,9 +316,19 @@ export function ToolPage({
308
316
  * The reading column. Horizontal and vertical padding come from the Library
309
317
  * layout's `<main>`, which already wraps every page under `/skills-and-tools` —
310
318
  * repeating them here would double the gutter.
319
+ *
320
+ * And no `max-w` of its own, for the same reason the skill page has none: the
321
+ * layout's `<main>` already holds the shared `DOCUMENT_COLUMN` measure, so a
322
+ * second, narrower width here is a second column inside the first. It was
323
+ * `max-w-3xl` — a 768px article centred in the measure's 800px line — and the
324
+ * 16px that left on each side moved this page's title row in from where the
325
+ * plugin page's and the skill page's are: the same band, the same group, the
326
+ * same `⋯`, ending 16px short of the right edge the other two reach. Where
327
+ * the menu sits on the row is decided by how wide the row is, so the column
328
+ * is where "the same position as on the plugin page" is actually kept.
311
329
  */
312
330
  function Article({ children }: { children: ReactNode }) {
313
- return <article className="mx-auto w-full max-w-3xl">{children}</article>;
331
+ return <article className="w-full">{children}</article>;
314
332
  }
315
333
 
316
334
  function SectionHeading({ children }: { children: ReactNode }) {
@@ -1,7 +1,8 @@
1
- import { useCallback, useEffect, useState } from 'react';
2
- import { DEFAULT_BRANCH } from '@bevel-software/platform-shared';
3
- import { grantAccess } from '../../access/api';
4
- import { cancelPullRequest } from '../../pr/services/pr-cancel.api';
1
+ import { useMemo } from 'react';
2
+ import {
3
+ useAccessRequests,
4
+ type AccessRequestsState,
5
+ } from '../../access/hooks/useAccessRequests';
5
6
  import {
6
7
  listJoinRequests,
7
8
  reconcileJoinRequest,
@@ -11,31 +12,18 @@ import {
11
12
  import { useLibraryToast } from '../state/toast.context';
12
13
 
13
14
  /**
14
- * The join requests one plugin's managers can answer, and the two ways to
15
- * answer them.
16
- *
17
- * ACCEPTING IS A GRANT, NOT A MERGE. A proposal is "give this principal this
18
- * verb on the plugin folder", so accepting it calls the ordinary access-grant
19
- * API — the same endpoint the Manage-access dialog uses, with the same gate,
20
- * lock and commit. The request's branch is never merged, so nothing else it
21
- * carries can ride in on an approval, and a request naming five people can be
22
- * answered with two yeses and three ignores.
23
- *
24
- * The request then retires ITSELF: it is open exactly while its `access.md`
25
- * grants something the default branch does not, so once the accepted grant
26
- * lands the diff is empty and the server closes it and deletes the branch.
27
- * `reconcile` just asks for that check immediately instead of waiting for the
28
- * next listing (which does it too).
15
+ * The Library's face of {@link useAccessRequests}: one plugin's (or skill's)
16
+ * join requests, with the failures said as Library toasts.
29
17
  *
30
- * Fetching is unconditional and degrades to `[]` — the endpoint answers `[]`
31
- * to non-managers rather than 403, so "am I a manager here" stays a question
32
- * only the server answers.
18
+ * Everything about how a request is answered lives in the access module now —
19
+ * accepting is a grant, declining rejects the change request, and the request
20
+ * retires itself. What stays here is where the words go: the Library has a
21
+ * toast host, and the Manage access dialog does not, which is why the generic
22
+ * hook reports failures as state and lets each surface choose.
33
23
  */
34
24
  export interface JoinRequestsState {
35
25
  requests: JoinRequest[];
36
- /** Grant one proposal, then settle the request if that was the last one. */
37
26
  accept(request: JoinRequest, proposal: JoinProposal): Promise<void>;
38
- /** Decline the whole request — reject the change request. */
39
27
  decline(request: JoinRequest): Promise<void>;
40
28
  reload(): void;
41
29
  }
@@ -62,83 +50,20 @@ export function useJoinRequests(
62
50
  folder: string | null,
63
51
  api: JoinRequestsApi = PLUGIN_JOIN_API,
64
52
  ): JoinRequestsState {
65
- // Keyed by the plugin they came from: a page that moves from skill A to
66
- // skill B without unmounting must not show A's requests until B's arrive —
67
- // a banner that lets an editor grant A's proposal against B's folder.
68
- const [loaded, setLoaded] = useState<{ plugin: string; rows: JoinRequest[] } | null>(null);
69
- const requests = loaded?.plugin === plugin ? loaded.rows : [];
70
- const [revision, setRevision] = useState(0);
71
53
  const toast = useLibraryToast();
72
-
73
- useEffect(() => {
74
- let cancelled = false;
75
- api.list(plugin)
76
- .then((rows) => {
77
- if (!cancelled) setLoaded({ plugin, rows });
78
- })
79
- .catch(() => {
80
- // Silent: a manager surface that fails must not put an error banner in
81
- // front of somebody who came to read a skill.
82
- });
83
- return () => {
84
- cancelled = true;
85
- };
86
- }, [plugin, revision, api]);
87
-
88
- const reload = useCallback(() => setRevision((r) => r + 1), []);
89
-
90
- const accept = useCallback(
91
- async (request: JoinRequest, proposal: JoinProposal) => {
92
- if (!folder) return;
93
- try {
94
- await grantAccess(encodeURIComponent(DEFAULT_BRANCH), {
95
- path: folder,
96
- kind: 'folder',
97
- verb: proposal.verb,
98
- principal: proposal.principal,
99
- });
100
- } catch (err) {
101
- toast(err instanceof Error ? err.message : "Couldn't grant that: try again.", 'danger');
102
- setRevision((r) => r + 1);
103
- return;
104
- }
105
- // Drop the accepted proposal locally so the row goes immediately; the
106
- // refetch below is what makes it true.
107
- setLoaded((cur) =>
108
- cur && cur.plugin === plugin
109
- ? {
110
- ...cur,
111
- rows: cur.rows.map((r) =>
112
- r.number === request.number
113
- ? {
114
- ...r,
115
- proposals: r.proposals.filter(
116
- (p) => !(p.id === proposal.id && p.verb === proposal.verb),
117
- ),
118
- }
119
- : r,
120
- ),
121
- }
122
- : cur,
123
- );
124
- toast(`${proposal.label} now has ${proposal.verb} access.`);
125
- await api.reconcile(plugin, request.number).catch(() => false);
126
- setRevision((r) => r + 1);
127
- },
128
- [folder, plugin, toast, api],
129
- );
130
-
131
- const decline = useCallback(
132
- async (request: JoinRequest) => {
133
- try {
134
- await cancelPullRequest(request.number);
135
- } catch {
136
- toast("Couldn't dismiss that: try again.", 'danger');
137
- }
138
- setRevision((r) => r + 1);
139
- },
140
- [toast],
54
+ const source = useMemo(
55
+ () => ({
56
+ list: () => api.list(plugin),
57
+ reconcile: (number: number) => api.reconcile(plugin, number),
58
+ }),
59
+ [api, plugin],
141
60
  );
142
-
143
- return { requests, accept, decline, reload };
61
+ const state: AccessRequestsState = useAccessRequests({
62
+ itemKey: plugin,
63
+ source,
64
+ grantOn: folder ? { path: folder, kind: 'folder' } : null,
65
+ onError: (message) => toast(message, 'danger'),
66
+ onAccepted: (message) => toast(message),
67
+ });
68
+ return state;
144
69
  }