@bevel-software/platform-core-frontend 0.14.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +18 -17
  3. package/src/core/__tests__/bootstrap.test.ts +33 -1
  4. package/src/core/bootstrap.ts +30 -1
  5. package/src/lib/__tests__/api.test.ts +38 -0
  6. package/src/lib/api.ts +19 -2
  7. package/src/lib/utils.ts +2 -0
  8. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +111 -1
  9. package/src/modules/access/__tests__/plugin-token.test.ts +21 -0
  10. package/src/modules/access/api.ts +52 -4
  11. package/src/modules/access/components/ManageAccessDialog.tsx +112 -83
  12. package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +65 -1
  13. package/src/modules/git/components/GitSyncFailedBanner.tsx +68 -5
  14. package/src/modules/layout/components/SidebarFrame.tsx +1 -1
  15. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +1 -1
  16. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +1 -1
  17. package/src/modules/library/__tests__/LinkSkillPanel.test.tsx +121 -0
  18. package/src/modules/library/__tests__/LockedPluginView.test.tsx +6 -0
  19. package/src/modules/library/__tests__/NewPluginDialog.test.tsx +5 -4
  20. package/src/modules/library/__tests__/PluginExtras.test.tsx +15 -0
  21. package/src/modules/library/__tests__/PluginPage.test.tsx +195 -1
  22. package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +1 -1
  23. package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +1 -1
  24. package/src/modules/library/__tests__/PluginsSidebar.test.tsx +64 -3
  25. package/src/modules/library/__tests__/SkillPage.test.tsx +9 -2
  26. package/src/modules/library/__tests__/SkillsTree.test.tsx +172 -0
  27. package/src/modules/library/__tests__/ToolPage.test.tsx +7 -0
  28. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +115 -4
  29. package/src/modules/library/__tests__/library-data.stale.test.tsx +90 -0
  30. package/src/modules/library/__tests__/library-paths.test.ts +32 -0
  31. package/src/modules/library/__tests__/link-membership.test.ts +120 -0
  32. package/src/modules/library/__tests__/plugin-summary.test.ts +32 -0
  33. package/src/modules/library/__tests__/useJoinRequests.test.tsx +46 -0
  34. package/src/modules/library/components/AddToPluginDialog.tsx +33 -0
  35. package/src/modules/library/components/LibraryCard.tsx +14 -0
  36. package/src/modules/library/components/LibraryLayout.tsx +24 -14
  37. package/src/modules/library/components/LinkSkillPanel.tsx +171 -0
  38. package/src/modules/library/components/LockedPluginView.tsx +2 -2
  39. package/src/modules/library/components/NewPluginDialog.tsx +4 -4
  40. package/src/modules/library/components/PageActions.tsx +21 -1
  41. package/src/modules/library/components/PersonalPluginPage.tsx +2 -1
  42. package/src/modules/library/components/PluginExtras.tsx +3 -1
  43. package/src/modules/library/components/PluginPage.tsx +92 -12
  44. package/src/modules/library/components/PluginsIndexPage.tsx +11 -6
  45. package/src/modules/library/components/PluginsSidebar.tsx +110 -53
  46. package/src/modules/library/components/RenamePluginDialog.tsx +136 -0
  47. package/src/modules/library/components/SkillsTree.tsx +91 -0
  48. package/src/modules/library/components/StatusDot.tsx +1 -0
  49. package/src/modules/library/components/plugin-page-parts.tsx +32 -9
  50. package/src/modules/library/components/skill-page/SharedViaPlugins.tsx +218 -0
  51. package/src/modules/library/components/skill-page/SkillPage.tsx +70 -6
  52. package/src/modules/library/components/tool-page/ToolPage.tsx +11 -2
  53. package/src/modules/library/hooks/useJoinRequests.ts +48 -18
  54. package/src/modules/library/routes/WorkspaceItemRoute.tsx +180 -83
  55. package/src/modules/library/routes/library-paths.ts +21 -8
  56. package/src/modules/library/services/library.api.ts +55 -1
  57. package/src/modules/library/services/plugins.api.ts +94 -3
  58. package/src/modules/library/state/library-data.tsx +115 -22
  59. package/src/modules/library/utils/plugin-summary.ts +36 -0
  60. package/src/modules/library/utils/status.ts +74 -7
  61. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +3 -2
  62. package/src/modules/settings/components/ClaudeConnectionCard.tsx +169 -0
  63. package/src/modules/settings/components/DeploymentPage.tsx +15 -1
  64. package/src/modules/settings/components/__tests__/ClaudeConnectionCard.test.tsx +63 -0
  65. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +10 -0
  66. package/src/modules/settings/services/github-facade.api.ts +43 -0
  67. package/src/modules/setup/__tests__/setup.test.tsx +118 -0
  68. package/src/modules/setup/components/SetupGate.tsx +1 -1
  69. package/src/modules/setup/components/SetupScreen.tsx +195 -2
  70. package/src/modules/setup/services/setup.api.ts +78 -0
  71. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +295 -83
  72. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +129 -6
  73. package/src/modules/toolbar/services/external-api-keys.api.ts +2 -0
  74. package/src/modules/workspace/__tests__/testFixtures.ts +1 -0
  75. package/src/modules/workspace/components/FileExplorer.tsx +292 -236
  76. package/src/modules/workspace/components/FileRoute.tsx +37 -0
  77. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +39 -0
  78. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +1 -0
  79. package/src/modules/workspace/hooks/useMergedWorkspaceTree.ts +70 -0
  80. package/src/modules/workspace/hooks/useWorkspaceState.ts +17 -3
  81. package/src/modules/workspace/routing/kb-routes.ts +1 -1
  82. package/src/modules/workspace/state/workspace.context.ts +8 -0
  83. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +15 -0
  84. package/src/modules/workspace/utils/fileTree.ts +14 -16
  85. package/src/shared/__tests__/marketplace-url.test.ts +54 -0
  86. package/src/shared/components/Badge.tsx +3 -1
  87. package/src/shared/components/Banner.tsx +5 -1
  88. package/src/shared/marketplace-url.ts +90 -0
  89. package/src/shared/theme/tokens.css +9 -0
@@ -0,0 +1,218 @@
1
+ import { useMemo, useState } from 'react';
2
+ import { Link } from 'react-router-dom';
3
+ import { Badge, Button } from '../../../../shared/components';
4
+ import { useLibrary } from '../../state/library-data';
5
+ import { useLibraryToast } from '../../state/toast.context';
6
+ import { NeedsSkillWriteError, linkSkill, repairSkillLink, unlinkSkill } from '../../services/plugins.api';
7
+ import { requestSkillAccess, type PluginMembership } from '../../services/library.api';
8
+ import { pathForPlugin } from '../../routes/library-paths';
9
+ import { StatusDot } from '../StatusDot';
10
+ import { cn } from '../../../../lib/utils';
11
+
12
+ /**
13
+ * "In plugins" — every plugin this skill belongs to, and the two ways the
14
+ * relationship is managed from the skill's side.
15
+ *
16
+ * A row is INLINE (the skill sits in the plugin's folder) or LINKED (the
17
+ * plugin's manifest points at it). A link is healthy when the skill's own
18
+ * access rules still name the plugin's principal; when a hand edit removed
19
+ * that grant, the row shows the amber dot and — to someone who can edit the
20
+ * skill — a Repair button, because until it is back the plugin's members
21
+ * cannot read the skill. Unlink is the plugin MANAGER's verb (it edits the
22
+ * plugin's manifest), so it appears only on plugins the caller manages.
23
+ *
24
+ * "Add to plugin" links this skill into a plugin the caller manages. It
25
+ * needs write on the skill too; a refusal of that shape offers the request.
26
+ */
27
+ export function SharedViaPlugins({
28
+ skillName,
29
+ skillPath,
30
+ memberships,
31
+ owned,
32
+ onChanged,
33
+ }: {
34
+ skillName: string;
35
+ skillPath: string;
36
+ memberships: PluginMembership[];
37
+ /** The caller may edit the skill (its SKILL.md) — the repair verb. */
38
+ owned: boolean;
39
+ onChanged(): void;
40
+ }) {
41
+ const data = useLibrary();
42
+ const toast = useLibraryToast();
43
+ const [busy, setBusy] = useState<string | null>(null);
44
+ const [adding, setAdding] = useState(false);
45
+ const [needsWrite, setNeedsWrite] = useState<'ask' | 'requested' | null>(null);
46
+
47
+ // Plugins the caller manages AND whose links this platform writes: a
48
+ // plugin read from an external format has no link to add or remove here.
49
+ const managed = useMemo(
50
+ () =>
51
+ new Set(
52
+ data.pluginSummaries.filter((p) => p.canWrite && p.linksAreManaged !== false).map((p) => p.name),
53
+ ),
54
+ [data.pluginSummaries],
55
+ );
56
+ // A retired skill is never shared onward — the link API refuses it, so the
57
+ // chooser offers nothing rather than a list of refusals.
58
+ const retired = useMemo(
59
+ () => data.items.some((i) => i.kind === 'skill' && i.id === skillName && i.lifecycle === 'retired'),
60
+ [data.items, skillName],
61
+ );
62
+ const addable = useMemo(
63
+ () => (retired ? [] : [...managed].filter((name) => !memberships.some((m) => m.name === name)).sort()),
64
+ [managed, memberships, retired],
65
+ );
66
+
67
+ async function run(label: string, op: () => Promise<unknown>, done: string) {
68
+ setBusy(label);
69
+ try {
70
+ await op();
71
+ toast(done);
72
+ onChanged();
73
+ } catch (err) {
74
+ if (err instanceof NeedsSkillWriteError) setNeedsWrite('ask');
75
+ else toast(err instanceof Error ? err.message : `Couldn't ${label}.`, 'danger');
76
+ } finally {
77
+ setBusy(null);
78
+ }
79
+ }
80
+
81
+ if (memberships.length === 0 && addable.length === 0) return null;
82
+
83
+ return (
84
+ <section className="mt-6" data-testid="shared-via-plugins">
85
+ <h2 className="mb-2.5 text-label font-semibold uppercase text-ink-faint">In plugins</h2>
86
+ <div className="grid gap-2">
87
+ {memberships.length === 0 && (
88
+ <p className="text-detail text-ink-faint">This skill is in no plugin yet.</p>
89
+ )}
90
+ {memberships.map((m) => {
91
+ const broken = m.linked && !m.granted;
92
+ return (
93
+ <div
94
+ key={m.name}
95
+ className="flex items-center gap-3 rounded-md border border-line bg-sunken px-3 py-2"
96
+ >
97
+ <div className="min-w-0">
98
+ <div className="flex items-center gap-1.5">
99
+ <Link to={pathForPlugin(m.name)} className="truncate text-detail font-semibold text-ink underline-offset-2 hover:underline">
100
+ {m.name}
101
+ </Link>
102
+ <Badge tone="outline" size="xs" className="shrink-0 uppercase">
103
+ {m.linked ? 'Linked' : 'Inline'}
104
+ </Badge>
105
+ </div>
106
+ <small className={cn('block text-meta', broken ? 'text-urgent' : 'text-ink-faint')}>
107
+ {broken
108
+ ? owned
109
+ ? `Needs setup: ${m.name}'s members can't read this skill until the link is repaired.`
110
+ : `Needs setup: ${m.name}'s members can't read this skill. Ask an editor to repair the link.`
111
+ : m.linked
112
+ ? `${m.name}'s members can read it; its managers can edit it.`
113
+ : `Lives in ${m.name}'s folder.`}
114
+ </small>
115
+ </div>
116
+ <div className="ml-auto flex shrink-0 items-center gap-2">
117
+ {broken && <StatusDot state="urgent" />}
118
+ {broken && owned && (
119
+ <Button
120
+ variant="outline"
121
+ size="tiny"
122
+ disabled={busy !== null}
123
+ onClick={() =>
124
+ void run('repair', () => repairSkillLink(m.name, skillPath), `${m.name} can read ${skillName} again.`)
125
+ }
126
+ >
127
+ Repair
128
+ </Button>
129
+ )}
130
+ {m.linked && managed.has(m.name) && (
131
+ <Button
132
+ variant="quiet"
133
+ size="tiny"
134
+ disabled={busy !== null}
135
+ onClick={() =>
136
+ void run('unlink', () => unlinkSkill(m.name, skillPath), `${skillName} is no longer in ${m.name}.`)
137
+ }
138
+ >
139
+ Unlink
140
+ </Button>
141
+ )}
142
+ </div>
143
+ </div>
144
+ );
145
+ })}
146
+ </div>
147
+
148
+ {addable.length > 0 && (
149
+ <div className="mt-2.5">
150
+ {needsWrite === 'requested' ? (
151
+ <span className="text-detail text-ink-faint">Asked the skill's editors for write access.</span>
152
+ ) : needsWrite === 'ask' ? (
153
+ <div className="flex flex-wrap items-center gap-2">
154
+ <span className="text-detail text-wait">
155
+ {"You can't change who may read this skill yet."}
156
+ </span>
157
+ <Button
158
+ variant="outline"
159
+ size="tiny"
160
+ disabled={busy !== null}
161
+ onClick={() =>
162
+ void (async () => {
163
+ setBusy('request');
164
+ try {
165
+ await requestSkillAccess(skillName);
166
+ setNeedsWrite('requested');
167
+ } catch (err) {
168
+ toast(err instanceof Error ? err.message : "Couldn't request access.", 'danger');
169
+ } finally {
170
+ setBusy(null);
171
+ }
172
+ })()
173
+ }
174
+ >
175
+ Request write access
176
+ </Button>
177
+ </div>
178
+ ) : adding ? (
179
+ <div className="flex flex-wrap items-center gap-2">
180
+ <label className="text-detail text-ink-muted" htmlFor="add-to-plugin-select">
181
+ Add to
182
+ </label>
183
+ <select
184
+ id="add-to-plugin-select"
185
+ className="rounded-md border border-line bg-surface px-2 py-1 text-ui text-ink"
186
+ defaultValue=""
187
+ disabled={busy !== null}
188
+ onChange={(e) => {
189
+ const name = e.target.value;
190
+ if (!name) return;
191
+ void run('link', () => linkSkill(name, skillPath), `${skillName} is now in ${name}.`).then(() =>
192
+ setAdding(false),
193
+ );
194
+ }}
195
+ >
196
+ <option value="" disabled>
197
+ Choose a plugin…
198
+ </option>
199
+ {addable.map((name) => (
200
+ <option key={name} value={name}>
201
+ {name}
202
+ </option>
203
+ ))}
204
+ </select>
205
+ <Button variant="quiet" size="tiny" onClick={() => setAdding(false)}>
206
+ Cancel
207
+ </Button>
208
+ </div>
209
+ ) : (
210
+ <Button variant="outline" size="sm" onClick={() => setAdding(true)}>
211
+ Add to plugin…
212
+ </Button>
213
+ )}
214
+ </div>
215
+ )}
216
+ </section>
217
+ );
218
+ }
@@ -3,7 +3,6 @@ import { useLocation, useNavigate, useParams } from 'react-router-dom';
3
3
  import { ArrowLeft, History } from 'lucide-react';
4
4
  import {
5
5
  DEFAULT_BRANCH,
6
- pluginOfPath,
7
6
  type PullRequestSummary,
8
7
  } from '@bevel-software/platform-shared';
9
8
  import '../../library.css';
@@ -33,9 +32,14 @@ import { useLibrary } from '../../state/library-data';
33
32
  import { useLibraryToast } from '../../state/toast.context';
34
33
  import { libraryHomeForItemPath, urlForSkillFile } from '../../routes/library-paths';
35
34
  import { changeAuthorName, formatWhen } from '../../../change-requests/utils/author';
36
- import { ownersTextOf } from '../../utils/plugin-summary';
35
+ import { ownersTextOf, pluginLabel } from '../../utils/plugin-summary';
37
36
  import { neededToolsFor, toolStatus } from '../../utils/status';
38
37
  import { StatusDot } from '../StatusDot';
38
+ import { SharedViaPlugins } from './SharedViaPlugins';
39
+ import { AccessRequestsBanner } from '../AccessRequestsBanner';
40
+ import { useJoinRequests, type JoinRequestsApi } from '../../hooks/useJoinRequests';
41
+ import { listSkillAccessRequests, reconcileSkillAccessRequest } from '../../services/library.api';
42
+ import { ManageAccessDialog } from '../../../access/components/ManageAccessDialog';
39
43
  import { ChangeRequestDock } from '../ChangeRequestDock';
40
44
  import { ChangeRequestDialog } from '../../../change-requests/components/ChangeRequestDialog';
41
45
  import { SkillFileTabs } from './SkillFileTabs';
@@ -136,17 +140,37 @@ export function SkillPage({
136
140
  const skillPath = skill?.path ?? '';
137
141
  const prefix = `${skillPath}/`;
138
142
 
143
+ /** Every plugin holding this skill, from the catalog's decoration. */
144
+ const memberships = useMemo(
145
+ () => data.items.find((i) => i.kind === 'skill' && i.id === name)?.plugins ?? [],
146
+ [data.items, name],
147
+ );
148
+ /**
149
+ * Write-access requests on this skill, for its editors. The endpoint answers
150
+ * `[]` to everyone else, so the fetch is unconditional and the banner hides
151
+ * itself; `owned` only spares a pointless call.
152
+ */
153
+ const skillRequestsApi = useMemo<JoinRequestsApi>(
154
+ () => ({ list: listSkillAccessRequests, reconcile: reconcileSkillAccessRequest }),
155
+ [],
156
+ );
157
+ const accessRequests = useJoinRequests(name, skillPath || null, skillRequestsApi);
158
+ const [manageOpen, setManageOpen] = useState(false);
159
+
139
160
  /**
140
161
  * Who has to say yes. A skill has no owner of its own — it inherits its plugin
141
162
  * folder's `access.md` — so the people who review a change to it are the
142
163
  * plugin's owners. Naming the wrong reviewer is worse than naming none, hence
143
164
  * the neutral fallback when the plugin index hasn't resolved.
144
165
  */
166
+ const itemPlugin = useMemo(
167
+ () => data.items.find((i) => i.kind === 'skill' && i.id === name)?.plugin ?? null,
168
+ [data.items, name],
169
+ );
145
170
  const ownerName = useMemo(() => {
146
- const plugin = skill ? pluginOfPath(skill.path) : null;
147
- const summary = plugin ? data.pluginSummaries.find((g) => g.name === plugin) : undefined;
171
+ const summary = itemPlugin ? data.pluginSummaries.find((g) => g.name === itemPlugin) : undefined;
148
172
  return summary ? ownersTextOf(summary) : 'the owner';
149
- }, [skill, data.pluginSummaries]);
173
+ }, [itemPlugin, data.pluginSummaries]);
150
174
 
151
175
  const files = useMemo(
152
176
  () => ['SKILL.md', ...(skill?.files ?? []).map((f) => f.slice(prefix.length))],
@@ -467,7 +491,7 @@ export function SkillPage({
467
491
  // The page the skill lives on, not the Library root: "back" from a skill
468
492
  // you opened off its plugin page must land on that plugin page. Derived from
469
493
  // the path, so a deep link gets the same honest destination as a click.
470
- const home = libraryHomeForItemPath(skillPath);
494
+ const home = libraryHomeForItemPath(skillPath, itemPlugin, (n) => pluginLabel(n, data.pluginSummaries));
471
495
  const backLink = (
472
496
  <Button variant="quiet" size="sm" onClick={() => navigate(home.path)}>
473
497
  {`‹ ${home.label}`}
@@ -590,8 +614,48 @@ export function SkillPage({
590
614
  those rules are decided. Same call the tool page made. */}
591
615
  </header>
592
616
 
617
+ {/* Not before the folder is known: Accept grants ON the folder and
618
+ Manage access opens it, and both are no-ops against ''. */}
619
+ {owned && skillPath && (
620
+ <AccessRequestsBanner
621
+ plugin={name}
622
+ folders={[skillPath]}
623
+ requests={accessRequests.requests}
624
+ onManage={() => setManageOpen(true)}
625
+ onAccept={(r, p) => void accessRequests.accept(r, p)}
626
+ onDecline={(r) => void accessRequests.decline(r)}
627
+ />
628
+ )}
629
+ {manageOpen && kbDirName && skillPath && (
630
+ <ManageAccessDialog
631
+ // The Library speaks the DEFAULT branch: a skill's rules are edited
632
+ // where the catalog reads them, whatever branch the ambient
633
+ // workspace happens to be on.
634
+ workspaceId={encodeURIComponent(DEFAULT_BRANCH)}
635
+ entry={{ name, relativePath: `${kbDirName}/${skillPath}`, type: 'directory' }}
636
+ onClose={() => {
637
+ setManageOpen(false);
638
+ accessRequests.reload();
639
+ data.reload();
640
+ }}
641
+ />
642
+ )}
643
+
593
644
  <IntegrationsSection needed={needed} onConnect={() => navigate('/connect')} />
594
645
 
646
+ {skill && (
647
+ <SharedViaPlugins
648
+ skillName={name}
649
+ skillPath={skillPath}
650
+ memberships={memberships}
651
+ owned={owned}
652
+ onChanged={() => {
653
+ data.reload();
654
+ data.reloadPlugins();
655
+ }}
656
+ />
657
+ )}
658
+
595
659
  <SkillFileTabs
596
660
  files={files}
597
661
  selected={active}
@@ -7,6 +7,8 @@ import { useToolPage } from '../../hooks/useToolPage';
7
7
  import { useToolSource } from '../../hooks/useToolSource';
8
8
  import { McpServerSection } from './McpServerSection';
9
9
  import { libraryHomeForItemPath, LIBRARY_ROOT } from '../../routes/library-paths';
10
+ import { useLibrary } from '../../state/library-data';
11
+ import { pluginLabel, pluginNameForPath } from '../../utils/plugin-summary';
10
12
  import { readOAuthFragment } from '../../utils/oauth-fragment';
11
13
  import type { ToolCapability } from '../../services/tools.api';
12
14
  import type { LibrarySkillSummary } from '../../services/library.api';
@@ -70,8 +72,15 @@ export function ToolPage({
70
72
 
71
73
  // Same rule as the skill page: back goes to the page the tool LIVES on —
72
74
  // its plugin, or the personal page — never to a root the reader may not
73
- // have come from. Falls back to the root while the tool is still loading.
74
- const home = libraryHomeForItemPath(page.tool?.path ?? '');
75
+ // have come from. While the tool is still loading the path is empty, so
76
+ // the home is the root; a resolved identity of null falls back to the folder.
77
+ const data = useLibrary();
78
+ const toolPath = page.tool?.path ?? '';
79
+ const home = libraryHomeForItemPath(
80
+ toolPath,
81
+ toolPath ? pluginNameForPath(toolPath, data.pluginSummaries) : undefined,
82
+ (n) => pluginLabel(n, data.pluginSummaries),
83
+ );
75
84
  const backLink = (
76
85
  <Button variant="quiet" size="sm" onClick={() => navigate(home.path)}>
77
86
  {`‹ ${home.label}`}
@@ -40,16 +40,41 @@ export interface JoinRequestsState {
40
40
  reload(): void;
41
41
  }
42
42
 
43
- export function useJoinRequests(plugin: string, folder: string | null): JoinRequestsState {
44
- const [requests, setRequests] = useState<JoinRequest[]>([]);
43
+ /**
44
+ * Where the requests come from. The default is a plugin's join requests; a
45
+ * skill page passes the skill's write-access endpoints instead — same
46
+ * proposals, same accept-by-grant, a different folder.
47
+ */
48
+ export interface JoinRequestsApi {
49
+ list(name: string): Promise<JoinRequest[]>;
50
+ reconcile(name: string, number: number): Promise<boolean>;
51
+ }
52
+
53
+ // Lazy wrappers, not the functions themselves: the plugin API is resolved at
54
+ // call time, so a surface that never lists requests never needs those exports.
55
+ const PLUGIN_JOIN_API: JoinRequestsApi = {
56
+ list: (name) => listJoinRequests(name),
57
+ reconcile: (name, number) => reconcileJoinRequest(name, number),
58
+ };
59
+
60
+ export function useJoinRequests(
61
+ plugin: string,
62
+ folder: string | null,
63
+ api: JoinRequestsApi = PLUGIN_JOIN_API,
64
+ ): 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 : [];
45
70
  const [revision, setRevision] = useState(0);
46
71
  const toast = useLibraryToast();
47
72
 
48
73
  useEffect(() => {
49
74
  let cancelled = false;
50
- listJoinRequests(plugin)
75
+ api.list(plugin)
51
76
  .then((rows) => {
52
- if (!cancelled) setRequests(rows);
77
+ if (!cancelled) setLoaded({ plugin, rows });
53
78
  })
54
79
  .catch(() => {
55
80
  // Silent: a manager surface that fails must not put an error banner in
@@ -58,7 +83,7 @@ export function useJoinRequests(plugin: string, folder: string | null): JoinRequ
58
83
  return () => {
59
84
  cancelled = true;
60
85
  };
61
- }, [plugin, revision]);
86
+ }, [plugin, revision, api]);
62
87
 
63
88
  const reload = useCallback(() => setRevision((r) => r + 1), []);
64
89
 
@@ -79,23 +104,28 @@ export function useJoinRequests(plugin: string, folder: string | null): JoinRequ
79
104
  }
80
105
  // Drop the accepted proposal locally so the row goes immediately; the
81
106
  // refetch below is what makes it true.
82
- setRequests((rows) =>
83
- rows.map((r) =>
84
- r.number === request.number
85
- ? {
86
- ...r,
87
- proposals: r.proposals.filter(
88
- (p) => !(p.id === proposal.id && p.verb === proposal.verb),
89
- ),
90
- }
91
- : r,
92
- ),
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,
93
123
  );
94
124
  toast(`${proposal.label} now has ${proposal.verb} access.`);
95
- await reconcileJoinRequest(plugin, request.number).catch(() => false);
125
+ await api.reconcile(plugin, request.number).catch(() => false);
96
126
  setRevision((r) => r + 1);
97
127
  },
98
- [folder, plugin, toast],
128
+ [folder, plugin, toast, api],
99
129
  );
100
130
 
101
131
  const decline = useCallback(