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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +18 -17
  3. package/src/core/__tests__/bootstrap.test.ts +33 -1
  4. package/src/core/bootstrap.ts +30 -1
  5. package/src/lib/__tests__/api.test.ts +38 -0
  6. package/src/lib/__tests__/utils.test.ts +43 -0
  7. package/src/lib/api.ts +19 -2
  8. package/src/lib/utils.ts +17 -7
  9. package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +111 -1
  10. package/src/modules/access/__tests__/plugin-token.test.ts +21 -0
  11. package/src/modules/access/api.ts +52 -4
  12. package/src/modules/access/components/ManageAccessDialog.tsx +112 -83
  13. package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +65 -1
  14. package/src/modules/git/components/GitSyncFailedBanner.tsx +68 -5
  15. package/src/modules/layout/components/SidebarFrame.tsx +1 -1
  16. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +2 -1
  17. package/src/modules/library/__tests__/LibrarySidebarMenu.test.tsx +1 -1
  18. package/src/modules/library/__tests__/LinkSkillPanel.test.tsx +121 -0
  19. package/src/modules/library/__tests__/LockedPluginView.test.tsx +6 -0
  20. package/src/modules/library/__tests__/McpServerSection.test.tsx +7 -1
  21. package/src/modules/library/__tests__/NewPluginDialog.test.tsx +5 -4
  22. package/src/modules/library/__tests__/PluginExtras.test.tsx +15 -0
  23. package/src/modules/library/__tests__/PluginPage.test.tsx +195 -1
  24. package/src/modules/library/__tests__/PluginsSidebar.contextmenu.test.tsx +1 -1
  25. package/src/modules/library/__tests__/PluginsSidebar.locked.test.tsx +1 -1
  26. package/src/modules/library/__tests__/PluginsSidebar.test.tsx +64 -3
  27. package/src/modules/library/__tests__/SkillPage.test.tsx +9 -2
  28. package/src/modules/library/__tests__/SkillsTree.test.tsx +172 -0
  29. package/src/modules/library/__tests__/ToolConnectionSection.test.tsx +216 -8
  30. package/src/modules/library/__tests__/ToolPage.test.tsx +23 -3
  31. package/src/modules/library/__tests__/ToolVarRow.test.tsx +7 -7
  32. package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +115 -4
  33. package/src/modules/library/__tests__/library-data.stale.test.tsx +90 -0
  34. package/src/modules/library/__tests__/library-paths.test.ts +32 -0
  35. package/src/modules/library/__tests__/link-membership.test.ts +120 -0
  36. package/src/modules/library/__tests__/plugin-summary.test.ts +32 -0
  37. package/src/modules/library/__tests__/status.test.ts +84 -0
  38. package/src/modules/library/__tests__/useJoinRequests.test.tsx +46 -0
  39. package/src/modules/library/components/AddToPluginDialog.tsx +33 -0
  40. package/src/modules/library/components/LibraryCard.tsx +21 -1
  41. package/src/modules/library/components/LibraryLayout.tsx +24 -14
  42. package/src/modules/library/components/LinkSkillPanel.tsx +171 -0
  43. package/src/modules/library/components/LockedPluginView.tsx +2 -2
  44. package/src/modules/library/components/NewPluginDialog.tsx +4 -4
  45. package/src/modules/library/components/PageActions.tsx +21 -1
  46. package/src/modules/library/components/PersonalPluginPage.tsx +2 -1
  47. package/src/modules/library/components/PluginExtras.tsx +3 -1
  48. package/src/modules/library/components/PluginPage.tsx +92 -12
  49. package/src/modules/library/components/PluginsIndexPage.tsx +11 -6
  50. package/src/modules/library/components/PluginsSidebar.tsx +110 -53
  51. package/src/modules/library/components/RenamePluginDialog.tsx +136 -0
  52. package/src/modules/library/components/SkillsTree.tsx +91 -0
  53. package/src/modules/library/components/StatusDot.tsx +1 -0
  54. package/src/modules/library/components/plugin-page-parts.tsx +32 -9
  55. package/src/modules/library/components/skill-page/SharedViaPlugins.tsx +218 -0
  56. package/src/modules/library/components/skill-page/SkillPage.tsx +75 -7
  57. package/src/modules/library/components/tool-page/McpServerSection.tsx +9 -1
  58. package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +223 -8
  59. package/src/modules/library/components/tool-page/ToolPage.tsx +30 -2
  60. package/src/modules/library/components/tool-page/ToolVarRow.tsx +30 -8
  61. package/src/modules/library/hooks/useJoinRequests.ts +48 -18
  62. package/src/modules/library/hooks/useToolPage.ts +28 -11
  63. package/src/modules/library/routes/WorkspaceItemRoute.tsx +180 -83
  64. package/src/modules/library/routes/library-paths.ts +21 -8
  65. package/src/modules/library/services/library.api.ts +55 -1
  66. package/src/modules/library/services/plugins.api.ts +94 -3
  67. package/src/modules/library/state/library-data.tsx +115 -22
  68. package/src/modules/library/utils/plugin-summary.ts +36 -0
  69. package/src/modules/library/utils/status.ts +173 -17
  70. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +3 -2
  71. package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +29 -14
  72. package/src/modules/secrets-vault/components/SecretsPage.tsx +4 -1
  73. package/src/modules/secrets-vault/components/ToolSecretsPanel.tsx +4 -1
  74. package/src/modules/secrets-vault/services/tool-secrets.api.ts +36 -0
  75. package/src/modules/settings/components/ClaudeConnectionCard.tsx +169 -0
  76. package/src/modules/settings/components/DeploymentPage.tsx +15 -1
  77. package/src/modules/settings/components/__tests__/ClaudeConnectionCard.test.tsx +63 -0
  78. package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +10 -0
  79. package/src/modules/settings/services/github-facade.api.ts +43 -0
  80. package/src/modules/setup/__tests__/setup.test.tsx +118 -0
  81. package/src/modules/setup/components/SetupGate.tsx +1 -1
  82. package/src/modules/setup/components/SetupScreen.tsx +195 -2
  83. package/src/modules/setup/services/setup.api.ts +78 -0
  84. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +301 -93
  85. package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +129 -6
  86. package/src/modules/toolbar/services/external-api-keys.api.ts +2 -0
  87. package/src/modules/workspace/__tests__/testFixtures.ts +1 -0
  88. package/src/modules/workspace/components/FileExplorer.tsx +292 -236
  89. package/src/modules/workspace/components/FileRoute.tsx +37 -0
  90. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +39 -0
  91. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +1 -0
  92. package/src/modules/workspace/hooks/useMergedWorkspaceTree.ts +70 -0
  93. package/src/modules/workspace/hooks/useWorkspaceState.ts +17 -3
  94. package/src/modules/workspace/routing/kb-routes.ts +1 -1
  95. package/src/modules/workspace/state/workspace.context.ts +8 -0
  96. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +15 -0
  97. package/src/modules/workspace/utils/fileTree.ts +14 -16
  98. package/src/shared/__tests__/marketplace-url.test.ts +54 -0
  99. package/src/shared/components/Badge.tsx +3 -1
  100. package/src/shared/components/Banner.tsx +5 -1
  101. package/src/shared/marketplace-url.ts +90 -0
  102. package/src/shared/theme/tokens.css +9 -0
@@ -24,6 +24,11 @@ import {
24
24
  grantAccess,
25
25
  revokeAccess,
26
26
  suggestPrincipals,
27
+ PLUGIN_PRINCIPAL_VERBS,
28
+ parsePluginPrincipalToken,
29
+ pluginPrincipalLabel,
30
+ pluginPrincipalToken,
31
+ type ResolvedPrincipal,
27
32
  asInheritedError,
28
33
  type AccessEligible,
29
34
  type AccessResponse,
@@ -83,7 +88,7 @@ interface PrincipalRow {
83
88
  * (grant audience). Decides the badge ("Role" vs "Group") and which
84
89
  * principal kind mutations round-trip with.
85
90
  */
86
- kind: 'user' | 'role' | 'group';
91
+ kind: 'user' | 'role' | 'group' | 'plugin';
87
92
  isYou: boolean;
88
93
  /** The principal to send on grant / revoke. */
89
94
  principal: Principal;
@@ -164,7 +169,10 @@ function principalKey(p: Principal): string {
164
169
  ? `r:${p.role.toLowerCase()}`
165
170
  : p.kind === 'group'
166
171
  ? `g:${p.group.toLowerCase()}`
167
- : `u:${p.email.toLowerCase()}`;
172
+ : p.kind === 'plugin'
173
+ // The server keys plugin principals by their full token (`p:plugin/gtm/read`).
174
+ ? `p:${pluginPrincipalToken(p.plugin, p.verb).toLowerCase()}`
175
+ : `u:${p.email.toLowerCase()}`;
168
176
  }
169
177
 
170
178
  /**
@@ -527,25 +535,35 @@ export function ManageAccessDialog({
527
535
  // Kinded collective list for one eligible set. Older servers omit
528
536
  // `principals` (version skew) — fall back to the name-only `roles`,
529
537
  // treating everything as a role (the pre-groups display).
530
- const collectivesOf = (list: AccessEligible): { name: string; kind: 'role' | 'group' }[] =>
538
+ const collectivesOf = (list: AccessEligible): ResolvedPrincipal[] =>
531
539
  list.principals ?? list.roles.map((name) => ({ name, kind: 'role' as const }));
532
- const touchCollective = (c: { name: string; kind: 'role' | 'group' }): PrincipalRow => {
533
- // Rows are keyed by KIND + name (`g:`/`r:`) — the backend treats a bare
534
- // `Product` (group) and `role/Product` (role) as DIFFERENT principals,
535
- // so a group and a role sharing a name are two rows, each mutating its
536
- // own grant. Collapsing them to one row silently pointed every edit at
537
- // the group and hid the role's grant entirely.
540
+ const touchCollective = (c: ResolvedPrincipal): PrincipalRow => {
541
+ // Rows are keyed by KIND + name (`g:`/`r:`/`p:`) — the backend treats a
542
+ // bare `Product` (group) and `role/Product` (role) as DIFFERENT
543
+ // principals, so a group and a role sharing a name are two rows, each
544
+ // mutating its own grant. Collapsing them to one row silently pointed
545
+ // every edit at the group and hid the role's grant entirely. A plugin
546
+ // principal's name is its full `plugin/<Name>/<verb>` token.
538
547
  const key =
539
- c.kind === 'group' ? `g:${c.name.toLowerCase()}` : `r:${c.name.toLowerCase()}`;
548
+ c.kind === 'group'
549
+ ? `g:${c.name.toLowerCase()}`
550
+ : c.kind === 'plugin'
551
+ ? `p:${c.name.toLowerCase()}`
552
+ : `r:${c.name.toLowerCase()}`;
540
553
  let row = rows.get(key);
541
554
  if (!row) {
555
+ const plugin = c.kind === 'plugin' ? parsePluginPrincipalToken(c.name) : null;
542
556
  row = {
543
557
  key,
544
- label: c.name,
558
+ label: plugin ? pluginPrincipalLabel(plugin.plugin, plugin.verb) : c.name,
545
559
  kind: c.kind,
546
560
  isYou: false,
547
561
  principal:
548
- c.kind === 'group' ? { kind: 'group', group: c.name } : { kind: 'role', role: c.name },
562
+ c.kind === 'group'
563
+ ? { kind: 'group', group: c.name }
564
+ : plugin
565
+ ? { kind: 'plugin', plugin: plugin.plugin, verb: plugin.verb }
566
+ : { kind: 'role', role: c.name },
549
567
  verbs: { owner: false, write: false, read: false, download: false },
550
568
  manage: 'direct',
551
569
  ancestors: [],
@@ -582,12 +600,22 @@ export function ManageAccessDialog({
582
600
  for (const u of data.owners.users) touchUser(u).verbs.owner = true;
583
601
  for (const c of collectivesOf(data.eligible)) touchCollective(c).verbs.write = true;
584
602
  for (const u of data.eligible.users) touchUser(u).verbs.write = true;
585
- // Read membership is per-principal only for a restricted node. When
586
- // `restricted` is false, read is `everyone` and the reader lists are empty.
587
- if (data.readers.restricted) {
588
- for (const c of collectivesOf(data.readers)) touchCollective(c).verbs.read = true;
589
- for (const u of data.readers.users) touchUser(u).verbs.read = true;
603
+ // Read grants are rows whether or not the node is public: on a public
604
+ // node they are what MAKES it public, and a row is the ONE place any
605
+ // grant is removed. The built-in `everyone` is a row like any principal
606
+ // — when a file spells it. A derived everyone (public only through a
607
+ // plugin principal) has no line of its own; the plugin's row is that grant.
608
+ for (const c of collectivesOf(data.readers)) {
609
+ if (c.kind === 'role' && isEveryoneRole({ kind: 'role', role: c.name })) {
610
+ if (!lookupSources(data.sources, 'r:everyone')?.read?.length) continue;
611
+ const row = touchCollective(c);
612
+ row.label = 'Everyone';
613
+ row.verbs.read = true;
614
+ continue;
615
+ }
616
+ touchCollective(c).verbs.read = true;
590
617
  }
618
+ for (const u of data.readers.users) touchUser(u).verbs.read = true;
591
619
  for (const c of collectivesOf(data.downloaders)) touchCollective(c).verbs.download = true;
592
620
  for (const u of data.downloaders.users) touchUser(u).verbs.download = true;
593
621
 
@@ -687,7 +715,13 @@ export function ManageAccessDialog({
687
715
  }, [query, suggest]);
688
716
 
689
717
  const principalLabel = (p: Principal): string =>
690
- p.kind === 'role' ? p.role : p.kind === 'group' ? p.group : p.displayName || p.email;
718
+ p.kind === 'role'
719
+ ? p.role
720
+ : p.kind === 'group'
721
+ ? p.group
722
+ : p.kind === 'plugin'
723
+ ? pluginPrincipalLabel(p.plugin, p.verb)
724
+ : p.displayName || p.email;
691
725
 
692
726
  const addChip = useCallback((p: Principal) => {
693
727
  setPickedChips((chips) =>
@@ -779,41 +813,20 @@ export function ManageAccessDialog({
779
813
  }
780
814
  }, [workspaceId, repoRelative, pickedChips, entry.relativePath, targetKind, grantVerbs, effectiveNewVerbs, reload]);
781
815
 
782
- // Revoke the public-read grant (`read: everyone`) at THIS path. Clears the
783
- // "Anyone can read" state when it was granted here; an inherited public grant
784
- // (from a parent folder) stays and is removed where it was set.
785
- const removePublicRead = useCallback(async () => {
786
- if (!workspaceId || repoRelative === null) return;
787
- setBusy(true);
788
- setMutateError(null);
789
- try {
790
- await revokeAccess(workspaceId, {
791
- path: entry.relativePath,
792
- kind: targetKind,
793
- principal: { kind: 'role', role: 'everyone' },
794
- verb: 'read',
795
- });
796
- reload();
797
- } catch (err) {
798
- // The public-read grant lives in a parent folder — route the 409 into the
799
- // same "Remove from parent? / Restrict here?" confirmation the grantee rows
800
- // use, instead of a raw error toast.
801
- const inherited = asInheritedError(err);
802
- if (inherited) {
803
- setConfirmRemove({
804
- principal: { kind: 'role', role: 'everyone' },
805
- label: 'Everyone',
806
- ancestors: ancestorsFromSources(inherited.sources),
807
- verb: 'read',
808
- });
809
- } else {
810
- setMutateError(err instanceof Error ? err.message : String(err));
811
- reload();
812
- }
813
- } finally {
814
- setBusy(false);
815
- }
816
- }, [workspaceId, repoRelative, entry.relativePath, targetKind, reload]);
816
+ // WHY the node is public, said in the band and acted on in the rows: every
817
+ // literal `everyone` line (here, or in a parent) is the Everyone row's
818
+ // source; every public plugin principal granted read is that plugin's
819
+ // row. The band only describes — one mechanism removes, and it is the
820
+ // same one for every principal.
821
+ const publicReasons = [
822
+ ...(lookupSources(data?.sources, 'r:everyone')?.read ?? []).map((s) =>
823
+ s.kind === 'direct' ? 'granted here' : `inherited from ${folderLabel((s as { path: string }).path)}`,
824
+ ),
825
+ ...(data?.readers.publicVia ?? []).map((token) => {
826
+ const parsed = parsePluginPrincipalToken(token);
827
+ return `through ${parsed ? pluginPrincipalLabel(parsed.plugin, parsed.verb) : token}`;
828
+ }),
829
+ ];
817
830
 
818
831
  // Toggle a single verb on an existing grantee: check → grant that verb, uncheck
819
832
  // → revoke just that verb. The server's fresh view is authoritative (we never
@@ -1036,7 +1049,7 @@ export function ManageAccessDialog({
1036
1049
  // The same chip vocabulary as the suggest menu's trailing tags:
1037
1050
  // a role is a capability, a group is an audience — badge which.
1038
1051
  <Badge tone="outline" size="xs" className="shrink-0 uppercase">
1039
- {p.kind === 'group' ? 'Group' : 'Role'}
1052
+ {p.kind === 'group' ? 'Group' : p.kind === 'plugin' ? 'Plugin' : 'Role'}
1040
1053
  </Badge>
1041
1054
  )}
1042
1055
  </div>
@@ -1081,7 +1094,9 @@ export function ManageAccessDialog({
1081
1094
  </Button>
1082
1095
  {openRowKey === p.key && (
1083
1096
  <AnchoredMenu>
1084
- {TIER_ROLES.map((role) => {
1097
+ {/* Everyone is public READ only (the grant route refuses the
1098
+ rest), so its row offers exactly the verb it can hold. */}
1099
+ {(isEveryoneRole(p.principal) ? (['Can read'] as Role[]) : TIER_ROLES).map((role) => {
1085
1100
  const k = ROLE_TO_KEY[role];
1086
1101
  const checked = p.verbs[k];
1087
1102
  const disabled =
@@ -1100,21 +1115,22 @@ export function ManageAccessDialog({
1100
1115
  </MenuItem>
1101
1116
  );
1102
1117
  })}
1103
- <div className="my-1 border-t border-line" />
1104
- {(() => {
1105
- const checked = p.verbs.download;
1106
- const disabled = busy || p.verbs.owner;
1107
- return (
1108
- <MenuItem
1109
- disabled={disabled}
1110
- active={checked}
1111
- onClick={() => doToggleVerb(p.principal, 'Can download', checked)}
1112
- trailing={checked ? <Check size={14} className="text-accent" /> : undefined}
1113
- >
1114
- Can download
1115
- </MenuItem>
1116
- );
1117
- })()}
1118
+ {!isEveryoneRole(p.principal) && <div className="my-1 border-t border-line" />}
1119
+ {!isEveryoneRole(p.principal) &&
1120
+ (() => {
1121
+ const checked = p.verbs.download;
1122
+ const disabled = busy || p.verbs.owner;
1123
+ return (
1124
+ <MenuItem
1125
+ disabled={disabled}
1126
+ active={checked}
1127
+ onClick={() => doToggleVerb(p.principal, 'Can download', checked)}
1128
+ trailing={checked ? <Check size={14} className="text-accent" /> : undefined}
1129
+ >
1130
+ Can download
1131
+ </MenuItem>
1132
+ );
1133
+ })()}
1118
1134
  <div className="my-1 border-t border-line" />
1119
1135
  <MenuItem
1120
1136
  tone="danger"
@@ -1202,7 +1218,7 @@ export function ManageAccessDialog({
1202
1218
  `roles` or `groups` (version skew) must degrade to an empty
1203
1219
  section, never a crash. Groups lead — they are the audience
1204
1220
  concept grants are meant for; roles remain grantable below. */}
1205
- {query.trim() && suggest && ((suggest.groups?.length ?? 0) > 0 || (suggest.roles?.length ?? 0) > 0 || (suggest.people?.length ?? 0) > 0) && (
1221
+ {query.trim() && suggest && ((suggest.groups?.length ?? 0) > 0 || (suggest.roles?.length ?? 0) > 0 || (suggest.pluginPrincipals?.length ?? 0) > 0 || (suggest.people?.length ?? 0) > 0) && (
1206
1222
  <AnchoredMenu width="anchor" align="left" className="max-h-56 overflow-auto">
1207
1223
  {(suggest.groups ?? []).map((g) => (
1208
1224
  <MenuItem
@@ -1232,6 +1248,24 @@ export function ManageAccessDialog({
1232
1248
  <span className="min-w-0 flex-1 truncate">{g}</span>
1233
1249
  </MenuItem>
1234
1250
  ))}
1251
+ {/* A plugin is three grantees — its readers, its writers, its
1252
+ owners — each following the plugin's own roster live. */}
1253
+ {(suggest.pluginPrincipals ?? []).flatMap((name) =>
1254
+ PLUGIN_PRINCIPAL_VERBS.map((verb) => (
1255
+ <MenuItem
1256
+ key={`pl:${name}/${verb}`}
1257
+ onClick={() => addChip({ kind: 'plugin', plugin: name, verb })}
1258
+ trailing={
1259
+ <span className="text-label uppercase text-ink-faint">plugin</span>
1260
+ }
1261
+ >
1262
+ <span className="flex size-6 shrink-0 items-center justify-center rounded-full bg-sunken text-label font-bold text-ink-muted">
1263
+ {initials(name)}
1264
+ </span>
1265
+ <span className="min-w-0 flex-1 truncate">{pluginPrincipalLabel(name, verb)}</span>
1266
+ </MenuItem>
1267
+ )),
1268
+ )}
1235
1269
  {(suggest.people ?? []).map((p) => {
1236
1270
  const tone = avatarTone(p.name || p.email);
1237
1271
  return (
@@ -1370,6 +1404,10 @@ export function ManageAccessDialog({
1370
1404
  )}
1371
1405
  </h3>
1372
1406
 
1407
+ {/* A statement, not a control: it says the node is public and
1408
+ why. Each reason is a grant with a row below — the Everyone
1409
+ row for a literal line, the plugin's row for a public plugin
1410
+ principal — and the row is where it is removed. */}
1373
1411
  {data && !data.readers.restricted && (
1374
1412
  <div className="flex items-center gap-3 py-1.5">
1375
1413
  <span className="flex size-8 shrink-0 items-center justify-center rounded-full bg-ok-soft text-ok">
@@ -1378,20 +1416,11 @@ export function ManageAccessDialog({
1378
1416
  <div className="min-w-0 flex-1">
1379
1417
  <div className="text-ui text-ink">Anyone can read</div>
1380
1418
  <div className="text-detail text-ink-muted">
1381
- Public: every signed-in user can read this {targetKind}
1419
+ {`Public: every signed-in user can read this ${targetKind}${
1420
+ publicReasons.length > 0 ? ` — ${publicReasons.join(', ')}` : ''
1421
+ }.`}
1382
1422
  </div>
1383
1423
  </div>
1384
- {canManage && (
1385
- <Button
1386
- variant="danger"
1387
- size="tiny"
1388
- className="shrink-0"
1389
- disabled={busy}
1390
- onClick={removePublicRead}
1391
- >
1392
- Remove
1393
- </Button>
1394
- )}
1395
1424
  </div>
1396
1425
  )}
1397
1426
 
@@ -1,4 +1,4 @@
1
- import { describe, it, expect } from 'vitest';
1
+ import { describe, it, expect, vi } from 'vitest';
2
2
  import { act, render, screen } from '@testing-library/react';
3
3
  import { GitSyncFailedBanner } from '../components/GitSyncFailedBanner';
4
4
  import {
@@ -11,6 +11,15 @@ import {
11
11
  } from '../../workspace/state/workspace.context';
12
12
  import { makeWorkspaceFixture } from '../../workspace/__tests__/testFixtures';
13
13
 
14
+ // The conflict rendering opens files through the file-navigation hook, which
15
+ // needs a router and the git context. Neither belongs in this suite: the
16
+ // banner's contract is what it says and which paths it offers, so the hook
17
+ // is replaced with a recorder.
18
+ const { openWorkspacePath } = vi.hoisted(() => ({ openWorkspacePath: vi.fn() }));
19
+ vi.mock('../../workspace/routing/kb-routes', () => ({
20
+ useFileNav: () => ({ openFile: vi.fn(), openWorkspacePath }),
21
+ }));
22
+
14
23
  /**
15
24
  * A minimal stand-in for the SSE bus: keeps the handlers the component
16
25
  * registers and lets a test push events through them, so these assertions
@@ -179,3 +188,58 @@ describe('GitSyncFailedBanner', () => {
179
188
  expect(screen.getAllByRole('alert')).toHaveLength(1);
180
189
  });
181
190
  });
191
+
192
+ describe('GitSyncFailedBanner — remote-sync conflict', () => {
193
+ const CONFLICT = {
194
+ kind: 'git-sync-failed',
195
+ workspaceId: 'ws-1',
196
+ branch: 'feat/x',
197
+ reason:
198
+ 'feat/x could not be synced: Plugins/x/SKILL.md was changed in Hexis and on the git host. Resolve the conflict on feat/x in Hexis, then sync again.',
199
+ conflictedPaths: ['Plugins/x/SKILL.md', 'Docs/a.md'],
200
+ };
201
+
202
+ it('tells the author to reconcile the files, and lists each one', () => {
203
+ const bus = renderBanner();
204
+ bus.emit(CONFLICT);
205
+ const alert = screen.getByRole('alert');
206
+ // This one IS the author's to act on — no "check the server logs".
207
+ expect(alert.textContent).toContain('changed both here and there');
208
+ expect(alert.textContent).not.toContain('server logs');
209
+ expect(screen.getByRole('button', { name: 'Plugins/x/SKILL.md' })).toBeTruthy();
210
+ expect(screen.getByRole('button', { name: 'Docs/a.md' })).toBeTruthy();
211
+ });
212
+
213
+ it('a file link opens that file in this workspace', () => {
214
+ const bus = renderBanner();
215
+ bus.emit(CONFLICT);
216
+ openWorkspacePath.mockClear();
217
+ act(() => {
218
+ screen.getByRole('button', { name: 'Docs/a.md' }).click();
219
+ });
220
+ expect(openWorkspacePath).toHaveBeenCalledWith('knowledge-base/Docs/a.md');
221
+ });
222
+
223
+ it('clears like any other failure once the branch syncs', () => {
224
+ const bus = renderBanner();
225
+ bus.emit(CONFLICT);
226
+ bus.emit({ kind: 'git-sync-recovered', workspaceId: 'ws-1', branch: 'feat/x' });
227
+ expect(screen.queryByRole('alert')).toBeNull();
228
+ });
229
+ });
230
+
231
+ describe('GitSyncFailedBanner — a conflict that arrives before the workspace has bootstrapped', () => {
232
+ it('lists the files as text, never as links to null/<path>', () => {
233
+ const bus = renderBanner({ kbDirName: null });
234
+ const early = {
235
+ kind: 'git-sync-failed',
236
+ workspaceId: 'ws-1',
237
+ branch: 'feat/x',
238
+ reason: 'conflict',
239
+ conflictedPaths: ['Docs/a.md'],
240
+ };
241
+ bus.emit(early);
242
+ expect(screen.getByText('Docs/a.md')).toBeTruthy();
243
+ expect(screen.queryByRole('button', { name: 'Docs/a.md' })).toBeNull();
244
+ });
245
+ });
@@ -1,8 +1,43 @@
1
1
  import { useCallback, useState } from 'react';
2
- import { CloudOff } from 'lucide-react';
2
+ import { CloudOff, GitMerge } from 'lucide-react';
3
3
  import { useEventBusSubscription } from '../../workflow/hooks/useEventBusSubscription';
4
4
  import { canonicalizeWorkspaceId } from '../../workflow/state/event-bus.context';
5
5
  import { useWorkspace } from '../../workspace/state/workspace.context';
6
+ import { useFileNav } from '../../workspace/routing/kb-routes';
7
+
8
+ /**
9
+ * The files a remote sync could not reconcile, each a link that opens it.
10
+ * Its own component so the navigation hook is only mounted for the conflict
11
+ * case — the push-failure banner has nothing to open.
12
+ *
13
+ * The paths arrive repo-relative; opening one needs the workspace's KB folder
14
+ * name, which the context holds as null until the workspace has bootstrapped.
15
+ * A conflict event can arrive before that fetch answers, so until the name is
16
+ * known the files are listed as text — never as links to `null/<path>`.
17
+ */
18
+ function ConflictFiles({ paths }: { paths: string[] }) {
19
+ const { kbDirName } = useWorkspace();
20
+ const { openWorkspacePath } = useFileNav();
21
+ return (
22
+ <ul className="mt-1 ml-5 flex flex-wrap gap-x-3 gap-y-0.5">
23
+ {paths.map((p) => (
24
+ <li key={p}>
25
+ {kbDirName ? (
26
+ <button
27
+ type="button"
28
+ className="font-mono underline underline-offset-2 hover:text-ink"
29
+ onClick={() => openWorkspacePath(`${kbDirName}/${p}`)}
30
+ >
31
+ {p}
32
+ </button>
33
+ ) : (
34
+ <span className="font-mono">{p}</span>
35
+ )}
36
+ </li>
37
+ ))}
38
+ </ul>
39
+ );
40
+ }
6
41
 
7
42
  /**
8
43
  * Shown when a commit landed locally but could not be pushed to the remote.
@@ -48,9 +83,9 @@ export function GitSyncFailedBanner() {
48
83
  // settles it (failures re-emit on every attempt, recoveries on the next
49
84
  // transition). The alternative — clearing on switch — hides real, still-
50
85
  // broken state, which is the exact failure mode this PR exists to fix.
51
- const [failures, setFailures] = useState<ReadonlyMap<string, { branch: string; reason: string }>>(
52
- new Map(),
53
- );
86
+ const [failures, setFailures] = useState<
87
+ ReadonlyMap<string, { branch: string; reason: string; conflictedPaths?: string[] }>
88
+ >(new Map());
54
89
 
55
90
  useEventBusSubscription(
56
91
  'git-sync-failed',
@@ -61,7 +96,11 @@ export function GitSyncFailedBanner() {
61
96
  // failure from being recorded under this one's key.
62
97
  if (!canonId || canonicalizeWorkspaceId(e.workspaceId) !== canonId) return;
63
98
  setFailures((prev) =>
64
- new Map(prev).set(canonId, { branch: e.branch, reason: e.reason }),
99
+ new Map(prev).set(canonId, {
100
+ branch: e.branch,
101
+ reason: e.reason,
102
+ conflictedPaths: e.conflictedPaths,
103
+ }),
65
104
  );
66
105
  },
67
106
  [canonId],
@@ -87,6 +126,30 @@ export function GitSyncFailedBanner() {
87
126
  const failure = canonId ? failures.get(canonId) : undefined;
88
127
  if (!failure) return null;
89
128
 
129
+ // A remote-sync CONFLICT is the one failure an author can act on, not only
130
+ // an operator: the same file changed here and on the git host. Automatic
131
+ // recovery is already running; if it does not clear, the person decides.
132
+ // Different copy, and the files themselves, each a link.
133
+ if (failure.conflictedPaths && failure.conflictedPaths.length > 0) {
134
+ return (
135
+ <div
136
+ role="alert"
137
+ className="px-3 py-1.5 bg-sunken border-b border-line text-xs text-ink shrink-0"
138
+ >
139
+ <div className="flex items-center gap-2">
140
+ <GitMerge size={13} className="shrink-0" />
141
+ <span className="flex-1">
142
+ <span className="font-mono font-semibold">{failure.branch}</span> isn’t in sync with
143
+ the git repository yet: these files were changed both here and there. Hexis is trying
144
+ to reconcile them. If this notice stays, open each one, keep the content you want, and
145
+ save.
146
+ </span>
147
+ </div>
148
+ <ConflictFiles paths={failure.conflictedPaths} />
149
+ </div>
150
+ );
151
+ }
152
+
90
153
  return (
91
154
  <div
92
155
  role="alert"
@@ -57,7 +57,7 @@ export function SidebarFrame({
57
57
  header,
58
58
  }: {
59
59
  children: ReactNode;
60
- /** Names the region and its resize handle, e.g. `Library plugins`. */
60
+ /** Names the region and its resize handle, e.g. `Library navigation`. */
61
61
  label: string;
62
62
  /**
63
63
  * Pinned above `children`, outside whatever list the surface is holding.
@@ -121,6 +121,7 @@ const TOOL_PAGE_STATE: ToolPageState = {
121
121
  detail: null,
122
122
  skillsLoaded: true,
123
123
  poweredSkills: [],
124
+ revision: 0,
124
125
  reload: vi.fn(),
125
126
  };
126
127
 
@@ -258,7 +259,7 @@ describe('LibraryRoutes', () => {
258
259
  },
259
260
  ]);
260
261
  renderAt('/skills-and-tools');
261
- const nav = await screen.findByRole('navigation', { name: 'Library plugins' });
262
+ const nav = await screen.findByRole('navigation', { name: 'Library navigation' });
262
263
  // In the member half, with a zero count — never below the gap as locked.
263
264
  expect(await within(nav).findByRole('button', { name: /^Fresh/ })).toBeInTheDocument();
264
265
  expect(within(nav).queryByRole('button', { name: 'Fresh (locked)' })).toBeNull();
@@ -142,7 +142,7 @@ function renderLibrary(path = '/skills-and-tools') {
142
142
  );
143
143
  }
144
144
 
145
- const nav = () => screen.getByRole('navigation', { name: 'Library plugins' });
145
+ const nav = () => screen.getByRole('navigation', { name: 'Library navigation' });
146
146
  const menuItems = () =>
147
147
  within(screen.getByRole('menu'))
148
148
  .getAllByRole('menuitem')
@@ -0,0 +1,121 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { render, screen, fireEvent, waitFor } from '@testing-library/react';
3
+ import { LibraryToastProvider } from '../state/toast';
4
+ import type { LibraryItem } from '../state/library-data';
5
+
6
+ /**
7
+ * The link picker: offers what is not yet in the plugin, links on click, and
8
+ * turns the server's "you may edit the plugin but not the skill" refusal into
9
+ * the request path — never deciding that client-side.
10
+ */
11
+
12
+ const api = vi.hoisted(() => ({
13
+ linkSkill: vi.fn(),
14
+ requestSkillAccess: vi.fn(),
15
+ }));
16
+ vi.mock('../services/plugins.api', async (importOriginal) => ({
17
+ ...(await importOriginal<typeof import('../services/plugins.api')>()),
18
+ linkSkill: api.linkSkill,
19
+ }));
20
+ vi.mock('../services/library.api', async (importOriginal) => ({
21
+ ...(await importOriginal<typeof import('../services/library.api')>()),
22
+ requestSkillAccess: api.requestSkillAccess,
23
+ }));
24
+
25
+ import { NeedsSkillWriteError } from '../services/plugins.api';
26
+ import { LinkSkillPanel } from '../components/LinkSkillPanel';
27
+
28
+ const OK = { state: 'ok' as const, text: 'Ready' };
29
+ const items: LibraryItem[] = [
30
+ { kind: 'skill', id: 'deploy', name: 'deploy', description: 'Ship it.', owned: false, plugin: null, shared: true, plugins: [], path: 'Skills/Eng/deploy', status: OK },
31
+ { kind: 'skill', id: 'outreach', name: 'outreach', description: '', owned: true, plugin: 'GTM', plugins: [{ name: 'GTM', linked: false, granted: true }], path: 'Plugins/GTM/skills/outreach', status: OK },
32
+ { kind: 'skill', id: 'pitch', name: 'pitch', description: 'Sales pitch.', owned: false, plugin: 'Sales', plugins: [{ name: 'Sales', linked: false, granted: true }], path: 'Plugins/Sales/skills/pitch', status: OK },
33
+ { kind: 'integration', id: 'notion', name: 'Notion', description: '', owned: false, plugin: 'GTM', path: 'Plugins/GTM/mcp.json', status: OK },
34
+ ];
35
+
36
+ function renderPanel() {
37
+ const onLinked = vi.fn();
38
+ render(
39
+ <LibraryToastProvider>
40
+ <LinkSkillPanel plugin="GTM" items={items} onLinked={onLinked} />
41
+ </LibraryToastProvider>,
42
+ );
43
+ return { onLinked };
44
+ }
45
+
46
+ beforeEach(() => {
47
+ api.linkSkill.mockReset();
48
+ api.requestSkillAccess.mockReset();
49
+ });
50
+
51
+ describe('LinkSkillPanel', () => {
52
+ it('offers released skills not already in the plugin — never tools, never its own', () => {
53
+ renderPanel();
54
+ expect(screen.getByText('deploy')).toBeInTheDocument();
55
+ expect(screen.getByText('pitch')).toBeInTheDocument();
56
+ expect(screen.queryByText('outreach')).not.toBeInTheDocument();
57
+ expect(screen.queryByText('Notion')).not.toBeInTheDocument();
58
+ });
59
+
60
+ it('narrows by the search box', () => {
61
+ renderPanel();
62
+ fireEvent.change(screen.getByLabelText('Search skills to link'), { target: { value: 'pit' } });
63
+ expect(screen.queryByText('deploy')).not.toBeInTheDocument();
64
+ expect(screen.getByText('pitch')).toBeInTheDocument();
65
+ });
66
+
67
+ it('links by the skill\'s path and reports back', async () => {
68
+ api.linkSkill.mockResolvedValue({ root: 'Skills/Eng/deploy', skills: ['Skills/Eng/deploy'] });
69
+ const { onLinked } = renderPanel();
70
+ fireEvent.click(screen.getAllByRole('button', { name: 'Link' })[0]);
71
+ await waitFor(() => expect(api.linkSkill).toHaveBeenCalledWith('GTM', 'Skills/Eng/deploy'));
72
+ await waitFor(() => expect(onLinked).toHaveBeenCalled());
73
+ });
74
+
75
+ it('says it is linking while the commit is in flight — a greyed button reads as a freeze', async () => {
76
+ let settle: (v: { root: string; skills: string[] }) => void = () => undefined;
77
+ api.linkSkill.mockReturnValue(new Promise((resolve) => (settle = resolve)));
78
+ const { onLinked } = renderPanel();
79
+ fireEvent.click(screen.getAllByRole('button', { name: 'Link' })[0]);
80
+ // The clicked row says what is happening; the others wait, still saying Link.
81
+ const linking = await screen.findByRole('button', { name: 'Linking…' });
82
+ expect(linking).toBeDisabled();
83
+ expect(screen.getByRole('button', { name: 'Link' })).toBeDisabled();
84
+ // A disabled button drops focus, so the word is ALSO in a live region
85
+ // that assistive tech reads out — and it clears once the link lands.
86
+ expect(screen.getByRole('status', { name: 'Link progress' })).toHaveTextContent('Linking deploy…');
87
+
88
+ settle({ root: 'Skills/Eng/deploy', skills: ['Skills/Eng/deploy'] });
89
+ await waitFor(() => expect(onLinked).toHaveBeenCalled());
90
+ expect(screen.getByRole('status', { name: 'Link progress' })).toHaveTextContent('');
91
+ });
92
+
93
+ it('turns the server\'s needs-skill-write refusal into a request, and says when it is sent', async () => {
94
+ api.linkSkill.mockRejectedValue(new NeedsSkillWriteError('Skills/Eng/deploy'));
95
+ api.requestSkillAccess.mockResolvedValue({ number: 7 });
96
+ const { onLinked } = renderPanel();
97
+ fireEvent.click(screen.getAllByRole('button', { name: 'Link' })[0]);
98
+ const request = await screen.findByRole('button', { name: 'Request write access' });
99
+ expect(onLinked).not.toHaveBeenCalled();
100
+ fireEvent.click(request);
101
+ await waitFor(() => expect(api.requestSkillAccess).toHaveBeenCalledWith('deploy'));
102
+ expect(await screen.findByText('Requested')).toBeInTheDocument();
103
+ });
104
+
105
+ it('announces a write-access request as a request, never as a link', async () => {
106
+ api.linkSkill.mockRejectedValue(new NeedsSkillWriteError('Skills/Eng/deploy'));
107
+ let settle: (v: { number: number }) => void = () => undefined;
108
+ api.requestSkillAccess.mockReturnValue(new Promise((resolve) => (settle = resolve)));
109
+ renderPanel();
110
+ fireEvent.click(screen.getAllByRole('button', { name: 'Link' })[0]);
111
+ fireEvent.click(await screen.findByRole('button', { name: 'Request write access' }));
112
+ // The same live region, the right words for THIS operation.
113
+ expect(await screen.findByRole('button', { name: 'Requesting…' })).toBeDisabled();
114
+ expect(screen.getByRole('status', { name: 'Link progress' })).toHaveTextContent('Requesting write access to deploy…');
115
+ expect(screen.getByRole('status', { name: 'Link progress' })).not.toHaveTextContent('Linking');
116
+
117
+ settle({ number: 7 });
118
+ expect(await screen.findByText('Requested')).toBeInTheDocument();
119
+ expect(screen.getByRole('status', { name: 'Link progress' })).toHaveTextContent('');
120
+ });
121
+ });
@@ -80,6 +80,12 @@ describe('LockedPluginView', () => {
80
80
  );
81
81
  });
82
82
 
83
+ it('calls the plugin by its display name — the same name the unlocked page uses', () => {
84
+ renderLocked(finance({ name: 'finance', displayName: 'Finance & Ops' }));
85
+ expect(screen.getByRole('heading', { name: 'Finance & Ops', level: 1 })).toBeInTheDocument();
86
+ expect(screen.queryByText('finance')).toBeNull();
87
+ });
88
+
83
89
  it('never leaks an address, even when the summary carries one', () => {
84
90
  // The backend nulls emails for non-readers; this asserts the view would not
85
91
  // print one if a future wire change ever handed it one anyway.