@bevel-software/platform-core-frontend 0.26.0 → 0.27.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.
- package/package.json +2 -2
- package/src/core/CoreAppShell.tsx +87 -25
- package/src/core/ProductName.tsx +49 -0
- package/src/core/__tests__/ShellRoutes.test.tsx +22 -0
- package/src/core/__tests__/core-contributions.test.ts +16 -0
- package/src/core/core-contributions.ts +17 -0
- package/src/core/registry.ts +51 -1
- package/src/index.css +23 -5
- package/src/index.ts +5 -0
- package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +1 -1
- package/src/modules/access/components/ManageAccessDialog.tsx +1 -1
- package/src/modules/admin/__tests__/RolesCorruptedBanner.test.tsx +70 -0
- package/src/modules/admin/components/RolesCorruptedBanner.tsx +9 -4
- package/src/modules/auth/components/LoginScreen.tsx +4 -1
- package/src/modules/auth/services/account.api.ts +28 -1
- package/src/modules/auth/services/sso.ts +1 -2
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +176 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +68 -0
- package/src/modules/change-requests/__tests__/ChangeRequestLink.test.tsx +182 -0
- package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +1 -1
- package/src/modules/change-requests/__tests__/readFileOnBranch.test.ts +79 -0
- package/src/modules/change-requests/components/ChangeBox.tsx +6 -1
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +45 -15
- package/src/modules/change-requests/components/ChangeRequestLink.tsx +151 -0
- package/src/modules/change-requests/components/CrFileTree.tsx +2 -1
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +4 -2
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +6 -3
- package/src/modules/change-requests/services/change-requests.api.ts +15 -2
- package/src/modules/change-requests/utils/readFailure.ts +22 -0
- package/src/modules/embed/__tests__/EmbedLinkPage.test.tsx +74 -0
- package/src/modules/embed/__tests__/EmbedView.test.tsx +473 -0
- package/src/modules/embed/__tests__/embed-config.test.ts +128 -0
- package/src/modules/embed/__tests__/embed-host.test.ts +111 -0
- package/src/modules/embed/__tests__/mcp-app-view.test.ts +295 -0
- package/src/modules/embed/__tests__/mount.test.tsx +157 -0
- package/src/modules/embed/components/EmbedLinkPage.tsx +109 -0
- package/src/modules/embed/components/EmbedView.tsx +545 -0
- package/src/modules/embed/embed-config.ts +132 -0
- package/src/modules/embed/embed-host.ts +120 -0
- package/src/modules/embed/mount.tsx +80 -0
- package/src/modules/embed/services/embed-token.ts +22 -0
- package/src/modules/embed/services/embed.api.ts +158 -0
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +202 -4
- package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +59 -1
- package/src/modules/git/__tests__/PullNeededBanner.test.tsx +39 -22
- package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +7 -2
- package/src/modules/git/branch-delete-menu-item.tsx +24 -0
- package/src/modules/git/components/BranchSwitcher.tsx +29 -5
- package/src/modules/git/components/GitSyncFailedBanner.tsx +53 -15
- package/src/modules/git/components/HistoryVersionPreview.tsx +5 -3
- package/src/modules/git/components/PullNeededBanner.tsx +15 -49
- package/src/modules/git/hooks/useAutoPullUpdates.ts +9 -5
- package/src/modules/git/index.ts +15 -0
- package/src/modules/git/services/__tests__/error-messages.test.ts +67 -0
- package/src/modules/git/services/__tests__/pull-failure.test.ts +36 -0
- package/src/modules/git/services/error-messages.ts +58 -1
- package/src/modules/git/services/pull-failure.ts +68 -0
- package/src/modules/git/state/branch-delete-confirm.ts +46 -0
- package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +1 -0
- package/src/modules/layout/__tests__/breakpoints.test.ts +7 -1
- package/src/modules/layout/breakpoints.ts +8 -0
- package/src/modules/library/__tests__/PluginExtras.test.tsx +9 -9
- package/src/modules/library/__tests__/PluginPage.test.tsx +8 -1
- package/src/modules/library/__tests__/SkillsTree.test.tsx +13 -4
- package/src/modules/library/components/LibraryPage.tsx +22 -0
- package/src/modules/library/components/PluginExtras.tsx +23 -6
- package/src/modules/library/components/PluginPage.tsx +6 -1
- package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
- package/src/modules/library/services/plugins.api.ts +4 -1
- package/src/modules/library/state/plugins-revision.ts +28 -0
- package/src/modules/onboarding/__tests__/agent-connection-api.test.ts +55 -0
- package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +87 -82
- package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +109 -0
- package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1001 -0
- package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +392 -0
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +226 -193
- package/src/modules/onboarding/__tests__/starter-pack-card.test.tsx +136 -0
- package/src/modules/onboarding/components/CreatorWelcomePage.tsx +7 -11
- package/src/modules/onboarding/components/EmailChipsInput.tsx +138 -0
- package/src/modules/onboarding/components/GetStartedColumn.tsx +651 -0
- package/src/modules/onboarding/components/InviteButton.tsx +35 -0
- package/src/modules/onboarding/components/InviteDialog.tsx +424 -0
- package/src/modules/onboarding/components/RootLanding.tsx +8 -24
- package/src/modules/onboarding/components/StarterPackCard.tsx +98 -0
- package/src/modules/onboarding/components/WelcomePage.tsx +65 -154
- package/src/modules/onboarding/first-page-prompt.ts +89 -0
- package/src/modules/onboarding/invite-emails.ts +175 -0
- package/src/modules/onboarding/services/agent-connection.api.ts +53 -0
- package/src/modules/onboarding/services/starter-packs.api.ts +83 -0
- package/src/modules/onboarding/state/agent-connection.ts +167 -0
- package/src/modules/onboarding/state/invite-dialog.context.ts +32 -0
- package/src/modules/onboarding/state/invite-dialog.tsx +31 -0
- package/src/modules/onboarding/state/onboarding.ts +133 -59
- package/src/modules/onboarding/state/starter-packs.ts +169 -0
- package/src/modules/settings/settings-nav-items.tsx +8 -3
- package/src/modules/setup/__tests__/setup.first-run-storage.test.tsx +389 -0
- package/src/modules/setup/__tests__/setup.github.test.tsx +5 -5
- package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +1 -1
- package/src/modules/setup/__tests__/setup.repository-change.test.tsx +1 -1
- package/src/modules/setup/__tests__/setup.repository.test.tsx +21 -21
- package/src/modules/setup/__tests__/setup.test.tsx +56 -15
- package/src/modules/setup/__tests__/useConnectionProbe.test.tsx +123 -0
- package/src/modules/setup/components/FirstRunStorage.tsx +560 -0
- package/src/modules/setup/components/SetupGate.tsx +46 -1
- package/src/modules/setup/components/SetupScreen.tsx +81 -84
- package/src/modules/setup/hooks/useConnectionProbe.ts +93 -0
- package/src/modules/setup/services/setup.api.ts +3 -3
- package/src/modules/setup/utils/suggested-branch.ts +27 -0
- package/src/modules/toolbar/commands/__tests__/actions.test.tsx +210 -0
- package/src/modules/toolbar/commands/actions.tsx +324 -0
- package/src/modules/toolbar/commands/command-menu.ts +44 -0
- package/src/modules/toolbar/commands/useCommandActions.ts +69 -0
- package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
- package/src/modules/toolbar/components/AppSwitcher.tsx +106 -22
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
- package/src/modules/toolbar/components/ProfileMenu.tsx +9 -4
- package/src/modules/toolbar/components/SearchPalette.tsx +540 -0
- package/src/modules/toolbar/components/Toolbar.tsx +10 -0
- package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +187 -54
- package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
- package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +832 -0
- package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +57 -2
- package/src/modules/toolbar/search/__tests__/rank.test.ts +93 -0
- package/src/modules/toolbar/search/__tests__/sources.test.ts +131 -0
- package/src/modules/toolbar/search/rank.ts +111 -0
- package/src/modules/toolbar/search/sources.ts +169 -0
- package/src/modules/workflow/hooks/useFileLock.ts +10 -7
- package/src/modules/workflow/services/__tests__/lock.api.test.ts +41 -0
- package/src/modules/workflow/services/lock.api.ts +17 -2
- package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +49 -1
- package/src/modules/workspace/components/EditorTabs.tsx +39 -15
- package/src/modules/workspace/components/FileExplorer.tsx +39 -6
- package/src/modules/workspace/components/FilePaneCard.tsx +6 -2
- package/src/modules/workspace/components/FileRoute.tsx +12 -7
- package/src/modules/workspace/components/FileViewer.tsx +271 -74
- package/src/modules/workspace/components/KbPageHeader.tsx +13 -6
- package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +88 -21
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +92 -4
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +23 -3
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +330 -6
- package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +17 -2
- package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -16
- package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +6 -0
- package/src/modules/workspace/components/renderers/EmailRenderer.tsx +23 -21
- package/src/modules/workspace/components/renderers/ImageRenderer.tsx +13 -29
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +9 -2
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +8 -0
- package/src/modules/workspace/components/renderers/PdfRenderer.tsx +14 -19
- package/src/modules/workspace/components/renderers/PptxRenderer.tsx +11 -17
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +35 -7
- package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -17
- package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.links.test.tsx +73 -0
- package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.scaffold.test.tsx +64 -0
- package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.surface.test.tsx +82 -0
- package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +99 -0
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +129 -35
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +149 -0
- package/src/modules/workspace/components/renderers/__tests__/kbMarkdownLinkPolicy.test.tsx +100 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +76 -20
- package/src/modules/workspace/components/renderers/index.ts +26 -0
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +51 -1
- package/src/modules/workspace/components/renderers/rendererRawRead.ts +53 -0
- package/src/modules/workspace/components/renderers/rendererSurface.ts +109 -0
- package/src/modules/workspace/components/renderers/rendererWorkspace.ts +8 -2
- package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +126 -21
- package/src/modules/workspace/hooks/useCreatePage.ts +116 -0
- package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +24 -7
- package/src/modules/workspace/hooks/useWorkspaceState.ts +42 -8
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +10 -0
- package/src/modules/workspace/routing/__tests__/md-links-parity.test.tsx +113 -0
- package/src/modules/workspace/routing/kb-routes.ts +66 -12
- package/src/modules/workspace/state/editable-page.ts +42 -0
- package/src/modules/workspace/state/workspace.context.ts +13 -4
- package/src/modules/workspace/utils/__tests__/display-file-name.test.ts +60 -0
- package/src/modules/workspace/utils/__tests__/fileTree.test.ts +75 -0
- package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +16 -0
- package/src/modules/workspace/utils/display-file-name.ts +102 -0
- package/src/modules/workspace/utils/fileTree.ts +49 -14
- package/src/modules/workspace/utils/treeConfirm.ts +15 -0
- package/src/shared/__tests__/no-builtin-confirm.test.ts +102 -0
- package/src/shared/components/ConfirmProvider.tsx +156 -0
- package/src/shared/components/Dialog.tsx +7 -0
- package/src/shared/components/__tests__/ConfirmProvider.test.tsx +198 -0
- package/src/shared/components/confirm-context.ts +94 -0
- package/src/shared/components/index.ts +3 -0
- package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
- package/src/modules/onboarding/welcome-state.ts +0 -36
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
type AdminMenuItem,
|
|
29
29
|
type ToolbarItemDef,
|
|
30
30
|
} from '../../../../core/registry';
|
|
31
|
+
import { GIT_MENU_ITEMS } from '../../../git';
|
|
31
32
|
|
|
32
33
|
const stubAdminMenuItems: AdminMenuItem[] = [
|
|
33
34
|
{
|
|
@@ -48,9 +49,19 @@ const stubAdminMenuItems: AdminMenuItem[] = [
|
|
|
48
49
|
section: 'admin',
|
|
49
50
|
order: 90,
|
|
50
51
|
label: 'Stub admin row',
|
|
51
|
-
onSelect: ({ closeMenu }) =>
|
|
52
|
+
onSelect: ({ closeMenu, user }) => {
|
|
53
|
+
stubAdminRowSelectedBy.push(user.email);
|
|
54
|
+
closeMenu();
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: 'stub-hidden-row',
|
|
59
|
+
order: 20,
|
|
60
|
+
label: 'Stub hidden row',
|
|
61
|
+
isShown: (user) => user.email !== 'user@example.com',
|
|
52
62
|
},
|
|
53
63
|
];
|
|
64
|
+
const stubAdminRowSelectedBy: string[] = [];
|
|
54
65
|
|
|
55
66
|
/** Exposes the router's current pathname so menu navigation can be asserted. */
|
|
56
67
|
function LocationProbe() {
|
|
@@ -166,7 +177,9 @@ function renderToolbar(overrides?: {
|
|
|
166
177
|
>
|
|
167
178
|
<AppRegistryContext.Provider
|
|
168
179
|
value={makeRegistry({
|
|
169
|
-
|
|
180
|
+
// As `withCoreModuleContributions` composes it: git's own
|
|
181
|
+
// rows ahead of the registry's.
|
|
182
|
+
adminMenuItems: [...GIT_MENU_ITEMS, ...stubAdminMenuItems],
|
|
170
183
|
toolbarItems: overrides?.toolbarItems ?? [],
|
|
171
184
|
})}
|
|
172
185
|
>
|
|
@@ -448,6 +461,37 @@ describe('Toolbar', () => {
|
|
|
448
461
|
expect(logout).toHaveBeenCalledTimes(1);
|
|
449
462
|
});
|
|
450
463
|
|
|
464
|
+
// The way back from the branch delete's "Don't ask again": there exactly
|
|
465
|
+
// while THIS person's question is off in this browser.
|
|
466
|
+
describe('Ask before deleting branches', () => {
|
|
467
|
+
const KEY = 'hexis.skipBranchDeleteConfirm:user@example.com';
|
|
468
|
+
afterEach(() => localStorage.clear());
|
|
469
|
+
|
|
470
|
+
it('is not offered while the question is on', async () => {
|
|
471
|
+
renderToolbar();
|
|
472
|
+
await openMenu();
|
|
473
|
+
expect(noRow('Ask before deleting branches')).toBeNull();
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
it("is not offered for someone else's choice", async () => {
|
|
477
|
+
localStorage.setItem('hexis.skipBranchDeleteConfirm:someone@example.com', '1');
|
|
478
|
+
renderToolbar();
|
|
479
|
+
await openMenu();
|
|
480
|
+
expect(noRow('Ask before deleting branches')).toBeNull();
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
it('is offered while the question is off, and turns it back on', async () => {
|
|
484
|
+
localStorage.setItem(KEY, '1');
|
|
485
|
+
renderToolbar();
|
|
486
|
+
await openMenu();
|
|
487
|
+
await userEvent.click(row('Ask before deleting branches'));
|
|
488
|
+
expect(localStorage.getItem(KEY)).toBeNull();
|
|
489
|
+
expect(panelGone()).toBeNull();
|
|
490
|
+
await openMenu();
|
|
491
|
+
expect(noRow('Ask before deleting branches')).toBeNull();
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
|
|
451
495
|
// Nothing in the menu means anything without a person, and the trigger is
|
|
452
496
|
// that person — so signed out there is no button at all.
|
|
453
497
|
it('renders nothing when there is no signed-in user', () => {
|
|
@@ -493,6 +537,17 @@ describe('Toolbar', () => {
|
|
|
493
537
|
expect(row('Stub extension')).toBeInTheDocument();
|
|
494
538
|
});
|
|
495
539
|
|
|
540
|
+
// A row decides for itself whether it is offered, and its action learns
|
|
541
|
+
// who is signed in — how git's "Ask before deleting branches" is built.
|
|
542
|
+
it('leaves out a row that is not shown to this person, and tells a row who selected it', async () => {
|
|
543
|
+
stubAdminRowSelectedBy.length = 0;
|
|
544
|
+
renderToolbar({ isAdmin: true });
|
|
545
|
+
await openMenu();
|
|
546
|
+
expect(noRow('Stub hidden row')).toBeNull();
|
|
547
|
+
await userEvent.click(row('Stub admin row'));
|
|
548
|
+
expect(stubAdminRowSelectedBy).toEqual(['user@example.com']);
|
|
549
|
+
});
|
|
550
|
+
|
|
496
551
|
// Core rows all NAVIGATE — the settings surfaces are standalone routed
|
|
497
552
|
// pages below the persistent toolbar, not dialogs.
|
|
498
553
|
it('navigates to the standalone settings pages from the core rows and closes the menu', async () => {
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { matchTier, normalizeForMatch, rankByName, rankByNames } from '../rank';
|
|
3
|
+
|
|
4
|
+
const names = (items: string[], query: string, limit = 10) => rankByName(items, query, (n) => n, limit);
|
|
5
|
+
|
|
6
|
+
describe('matchTier', () => {
|
|
7
|
+
it('ranks a prefix above a word start above a bare substring', () => {
|
|
8
|
+
expect(matchTier('Pricing', 'pri')).toBe(0);
|
|
9
|
+
expect(matchTier('Team pricing', 'pri')).toBe(1);
|
|
10
|
+
expect(matchTier('Enterprise', 'pri')).toBe(2);
|
|
11
|
+
expect(matchTier('Onboarding', 'pri')).toBeNull();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('counts a later word-start occurrence even when the first one lands mid-word', () => {
|
|
15
|
+
expect(matchTier('Banana and', 'an')).toBe(1);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('treats punctuation and separators as word boundaries', () => {
|
|
19
|
+
expect(matchTier('heyreach-campaign', 'camp')).toBe(1);
|
|
20
|
+
expect(matchTier('q3_roadmap', 'road')).toBe(1);
|
|
21
|
+
expect(matchTier('Notes (draft)', 'draft')).toBe(1);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('reads a letter outside the Basic Multilingual Plane as a letter, not a word boundary', () => {
|
|
25
|
+
// `𝐀` (U+1D400) is two UTF-16 code units; its trailing half alone is no letter.
|
|
26
|
+
expect(matchTier('𝐀bc', 'bc')).toBe(2);
|
|
27
|
+
expect(matchTier('𝐀 bc', 'bc')).toBe(1);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('ignores case, accents and repeated whitespace', () => {
|
|
31
|
+
expect(matchTier('Café Menu', 'cafe')).toBe(0);
|
|
32
|
+
expect(matchTier('How to get started', 'TO GET')).toBe(1);
|
|
33
|
+
expect(normalizeForMatch(' Ärger Über ')).toBe('arger uber');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('matches everything for an empty query', () => {
|
|
37
|
+
expect(matchTier('Anything', ' ')).toBe(2);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('rankByName', () => {
|
|
42
|
+
it('orders by tier, then shorter name, then alphabet', () => {
|
|
43
|
+
expect(names(['Enterprise plan', 'Team pricing', 'Pricing', 'Pricing FAQ', 'Onboarding'], 'pri')).toEqual([
|
|
44
|
+
'Pricing',
|
|
45
|
+
'Pricing FAQ',
|
|
46
|
+
'Team pricing',
|
|
47
|
+
'Enterprise plan',
|
|
48
|
+
]);
|
|
49
|
+
expect(names(['beta', 'Alfa', 'gamma'], 'a')).toEqual(['Alfa', 'beta', 'gamma']);
|
|
50
|
+
// Same tier, same length: only the alphabet puts them in order, whatever order they came in.
|
|
51
|
+
expect(names(['Coda', 'Bora'], 'o')).toEqual(['Bora', 'Coda']);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('keeps the caller’s order for equal names', () => {
|
|
55
|
+
const items = [
|
|
56
|
+
{ id: 1, name: 'Plan' },
|
|
57
|
+
{ id: 2, name: 'Plan' },
|
|
58
|
+
];
|
|
59
|
+
expect(rankByName(items, 'plan', (i) => i.name, 10).map((i) => i.id)).toEqual([1, 2]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('honours the limit after ranking, not before', () => {
|
|
63
|
+
expect(names(['Xa', 'Xb', 'Alpha'], 'a', 1)).toEqual(['Alpha']);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('returns the caller’s own order, capped, for an empty query', () => {
|
|
67
|
+
expect(names(['c', 'a', 'b'], '', 2)).toEqual(['c', 'a']);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('returns nothing when nothing matches', () => {
|
|
71
|
+
expect(names(['Pricing'], 'zzz')).toEqual([]);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('rankByNames', () => {
|
|
76
|
+
const commands = [
|
|
77
|
+
{ label: 'Invite people', keywords: ['team', 'members'] },
|
|
78
|
+
{ label: 'Team settings', keywords: [] },
|
|
79
|
+
{ label: 'New page', keywords: ['write'] },
|
|
80
|
+
];
|
|
81
|
+
const ranked = (query: string) =>
|
|
82
|
+
rankByNames(commands, query, (c) => [c.label, ...c.keywords], 10).map((c) => c.label);
|
|
83
|
+
|
|
84
|
+
it('ranks an item at the best tier any of its names reaches', () => {
|
|
85
|
+
// "Invite people" reaches tier 0 through its keyword, as "Team settings" does through its label.
|
|
86
|
+
expect(ranked('team')).toEqual(['Invite people', 'Team settings']);
|
|
87
|
+
expect(ranked('wri')).toEqual(['New page']);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('breaks ties on the first name, the one on screen', () => {
|
|
91
|
+
expect(ranked('e')).toEqual(['New page', 'Invite people', 'Team settings']);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { DEFAULT_BRANCH, type FileTreeEntry } from '@bevel-software/platform-shared';
|
|
3
|
+
import type { PluginSummary } from '../../../library/services/plugins.api';
|
|
4
|
+
import { libraryResults, pageResults } from '../sources';
|
|
5
|
+
|
|
6
|
+
const KB = 'knowledge-base';
|
|
7
|
+
// Encoded as `urlForLibraryItem` encodes it, so a branch name with a `/` in it still matches.
|
|
8
|
+
const BRANCH = encodeURIComponent(DEFAULT_BRANCH);
|
|
9
|
+
const file = (relativePath: string): FileTreeEntry => ({
|
|
10
|
+
name: relativePath.split('/').pop()!,
|
|
11
|
+
relativePath,
|
|
12
|
+
type: 'file',
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const plugin = (name: string, displayName?: string): PluginSummary =>
|
|
16
|
+
({
|
|
17
|
+
name,
|
|
18
|
+
displayName,
|
|
19
|
+
folders: [`Plugins/${name}`],
|
|
20
|
+
canRead: true,
|
|
21
|
+
canWrite: false,
|
|
22
|
+
isOwner: false,
|
|
23
|
+
skillCount: 0,
|
|
24
|
+
toolCount: 0,
|
|
25
|
+
}) as PluginSummary;
|
|
26
|
+
|
|
27
|
+
describe('pageResults', () => {
|
|
28
|
+
it('names a page without its markdown extension and locates it by folder under Knowledge', () => {
|
|
29
|
+
const rows = pageResults(
|
|
30
|
+
[
|
|
31
|
+
file(`${KB}/KnowledgeBase/Onboarding.md`),
|
|
32
|
+
file(`${KB}/KnowledgeBase/GTM/Deals/pipeline.csv`),
|
|
33
|
+
file(`${KB}/Legal/Terms.markdown`),
|
|
34
|
+
],
|
|
35
|
+
KB,
|
|
36
|
+
new Set(),
|
|
37
|
+
);
|
|
38
|
+
expect(rows.map((r) => [r.name, r.location])).toEqual([
|
|
39
|
+
['Onboarding', 'Knowledge'],
|
|
40
|
+
['pipeline.csv', 'GTM / Deals'],
|
|
41
|
+
['Terms', 'Legal'],
|
|
42
|
+
]);
|
|
43
|
+
expect(rows[0].target).toEqual({ kind: 'workspace', path: `${KB}/KnowledgeBase/Onboarding.md` });
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('leaves out paths that are only proposals', () => {
|
|
47
|
+
const proposed = `${KB}/KnowledgeBase/Draft.md`;
|
|
48
|
+
const rows = pageResults([file(proposed), file(`${KB}/KnowledgeBase/Real.md`)], KB, new Set([proposed]));
|
|
49
|
+
expect(rows.map((r) => r.name)).toEqual(['Real']);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('libraryResults', () => {
|
|
54
|
+
const catalog = {
|
|
55
|
+
skills: [
|
|
56
|
+
{ name: 'rfi', description: '', path: 'Plugins/GTM/skills/rfi', plugins: [{ name: 'gtm', linked: false, granted: true }] },
|
|
57
|
+
{ name: 'shared-skill', description: '', path: 'Skills/shared-skill' },
|
|
58
|
+
],
|
|
59
|
+
tools: [
|
|
60
|
+
{ slug: 'linear', name: 'Linear', path: 'Plugins/gtm/linear.tool', type: 'http', setup: null, canWrite: false, variables: [] },
|
|
61
|
+
{ slug: 'notion', name: 'Notion', path: 'Plugins/gtm/mcp.json', type: 'mcp', setup: null, canWrite: false, variables: [] },
|
|
62
|
+
],
|
|
63
|
+
plugins: [plugin('gtm', 'GTM')],
|
|
64
|
+
} as Parameters<typeof libraryResults>[0];
|
|
65
|
+
|
|
66
|
+
it('links skills and tools to their canonical item URL and plugins to their page', () => {
|
|
67
|
+
const rows = libraryResults(catalog, KB);
|
|
68
|
+
expect(rows.map((r) => [r.kind, r.name, r.location])).toEqual([
|
|
69
|
+
['skill', 'rfi', 'GTM'],
|
|
70
|
+
['skill', 'shared-skill', 'Skills'],
|
|
71
|
+
['tool', 'Linear', 'GTM'],
|
|
72
|
+
['tool', 'Notion', 'GTM'],
|
|
73
|
+
['plugin', 'GTM', 'Plugin'],
|
|
74
|
+
]);
|
|
75
|
+
expect(rows[0].target).toEqual({ kind: 'url', url: `/workspace/${BRANCH}/${KB}/Plugins/GTM/skills/rfi` });
|
|
76
|
+
expect(rows[3].target).toEqual({ kind: 'url', url: `/workspace/${BRANCH}/${KB}/Plugins/gtm/mcp.json?server=notion` });
|
|
77
|
+
expect(rows[4].target).toEqual({ kind: 'url', url: '/skills-and-tools/plugins/gtm' });
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('lists only plugins while the checkout name is unknown', () => {
|
|
81
|
+
expect(libraryResults(catalog, null).map((r) => r.kind)).toEqual(['plugin']);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('still lists the plugins skills belong to when the plugin index came back empty', () => {
|
|
85
|
+
const rows = libraryResults(
|
|
86
|
+
{
|
|
87
|
+
...catalog,
|
|
88
|
+
skills: [
|
|
89
|
+
...catalog.skills,
|
|
90
|
+
{
|
|
91
|
+
name: 'brief',
|
|
92
|
+
description: '',
|
|
93
|
+
path: 'Plugins/Product/skills/brief',
|
|
94
|
+
plugins: [
|
|
95
|
+
{ name: 'product', linked: false, granted: true },
|
|
96
|
+
{ name: 'gtm', linked: true, granted: true },
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
plugins: [],
|
|
101
|
+
},
|
|
102
|
+
KB,
|
|
103
|
+
);
|
|
104
|
+
expect(rows.filter((r) => r.kind === 'plugin').map((r) => [r.name, r.target])).toEqual([
|
|
105
|
+
['gtm', { kind: 'url', url: '/skills-and-tools/plugins/gtm' }],
|
|
106
|
+
['product', { kind: 'url', url: '/skills-and-tools/plugins/product' }],
|
|
107
|
+
]);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('adds a plugin a skill names to the ones the index lists, once', () => {
|
|
111
|
+
const rows = libraryResults(
|
|
112
|
+
{
|
|
113
|
+
...catalog,
|
|
114
|
+
skills: [
|
|
115
|
+
...catalog.skills,
|
|
116
|
+
{
|
|
117
|
+
name: 'brief',
|
|
118
|
+
description: '',
|
|
119
|
+
path: 'Shared/brief',
|
|
120
|
+
plugins: [
|
|
121
|
+
{ name: 'gtm', linked: true, granted: true },
|
|
122
|
+
{ name: 'product', linked: true, granted: true },
|
|
123
|
+
],
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
KB,
|
|
128
|
+
);
|
|
129
|
+
expect(rows.filter((r) => r.kind === 'plugin').map((r) => r.name)).toEqual(['GTM', 'product']);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Name matching for the toolbar's search palette.
|
|
3
|
+
*
|
|
4
|
+
* NAME search, deliberately, and nothing cleverer: a query is matched as one
|
|
5
|
+
* case-insensitive substring of an item's name, and the matches are ordered
|
|
6
|
+
* by WHERE the query landed. No fuzzy matching — a palette that offers
|
|
7
|
+
* "Pricing" for "pcg" teaches people to distrust its first row, and the first
|
|
8
|
+
* row is the one Enter opens.
|
|
9
|
+
*
|
|
10
|
+
* Three tiers, best first:
|
|
11
|
+
*
|
|
12
|
+
* 0. the name STARTS with the query (`pri` → "Pricing")
|
|
13
|
+
* 1. a WORD of the name starts with it (`pri` → "Team pricing")
|
|
14
|
+
* 2. the query is anywhere in the name (`pri` → "Enterprise")
|
|
15
|
+
*
|
|
16
|
+
* Within a tier the shorter name wins (the query is more of it), then the
|
|
17
|
+
* alphabet, then the order the caller listed the items in — so an empty query
|
|
18
|
+
* returns the caller's own order untouched, which is how the palette shows its
|
|
19
|
+
* starting suggestions.
|
|
20
|
+
*
|
|
21
|
+
* Pure, with no React and no DOM: the ranking is the part worth pinning with
|
|
22
|
+
* tests, and it is tested without rendering anything.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** Lowercased, accents folded, whitespace collapsed — what both sides are compared as. */
|
|
26
|
+
export function normalizeForMatch(text: string): string {
|
|
27
|
+
return text
|
|
28
|
+
.normalize('NFD')
|
|
29
|
+
.replace(/\p{M}/gu, '')
|
|
30
|
+
.toLowerCase()
|
|
31
|
+
.replace(/\s+/g, ' ')
|
|
32
|
+
.trim();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A letter or digit at the very END of the text — the character just before a
|
|
37
|
+
* match. Tested against the whole prefix rather than `text[at - 1]` because
|
|
38
|
+
* that indexes UTF-16 code units: a letter outside the Basic Multilingual
|
|
39
|
+
* Plane (`𝐀`, the later CJK ideographs) is two of them, and its trailing half alone
|
|
40
|
+
* is no letter, so a mid-word match after one would pass for a word start.
|
|
41
|
+
* The `u` flag reads the prefix by code point.
|
|
42
|
+
*/
|
|
43
|
+
const ENDS_IN_WORD_CHAR = /[\p{L}\p{N}]$/u;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The tier `query` matches `name` at, or null for no match. Both arguments
|
|
47
|
+
* are normalized here; an empty query matches everything at the worst tier,
|
|
48
|
+
* so it never reorders anything.
|
|
49
|
+
*/
|
|
50
|
+
export function matchTier(name: string, query: string): 0 | 1 | 2 | null {
|
|
51
|
+
const q = normalizeForMatch(query);
|
|
52
|
+
if (!q) return 2;
|
|
53
|
+
const n = normalizeForMatch(name);
|
|
54
|
+
let at = n.indexOf(q);
|
|
55
|
+
if (at === -1) return null;
|
|
56
|
+
if (at === 0) return 0;
|
|
57
|
+
// Any occurrence at a word start counts, not just the first: `an` in
|
|
58
|
+
// "Banana and" first lands mid-word, then again at the start of "and".
|
|
59
|
+
while (at !== -1) {
|
|
60
|
+
if (!ENDS_IN_WORD_CHAR.test(n.slice(0, at))) return 1;
|
|
61
|
+
at = n.indexOf(q, at + 1);
|
|
62
|
+
}
|
|
63
|
+
return 2;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The items whose name contains `query`, best first, at most `limit` of them.
|
|
68
|
+
* `nameOf` is what is matched — the name a person would type, not the path.
|
|
69
|
+
*/
|
|
70
|
+
export function rankByName<T>(
|
|
71
|
+
items: readonly T[],
|
|
72
|
+
query: string,
|
|
73
|
+
nameOf: (item: T) => string,
|
|
74
|
+
limit: number,
|
|
75
|
+
): T[] {
|
|
76
|
+
return rankByNames(items, query, (item) => [nameOf(item)], limit);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* {@link rankByName} for items known by more than one name — a command's
|
|
81
|
+
* label and the words someone might type for it instead ("Invite people" for
|
|
82
|
+
* `team`). An item ranks at the BEST tier any of its names reaches; ties are
|
|
83
|
+
* broken on the FIRST name, the one on screen, so two rows that matched
|
|
84
|
+
* equally still read in a sensible order.
|
|
85
|
+
*/
|
|
86
|
+
export function rankByNames<T>(
|
|
87
|
+
items: readonly T[],
|
|
88
|
+
query: string,
|
|
89
|
+
namesOf: (item: T) => readonly string[],
|
|
90
|
+
limit: number,
|
|
91
|
+
): T[] {
|
|
92
|
+
if (!normalizeForMatch(query)) return items.slice(0, limit);
|
|
93
|
+
const scored: { item: T; tier: number; name: string; index: number }[] = [];
|
|
94
|
+
items.forEach((item, index) => {
|
|
95
|
+
const names = namesOf(item);
|
|
96
|
+
let tier: number | null = null;
|
|
97
|
+
for (const n of names) {
|
|
98
|
+
const t = matchTier(n, query);
|
|
99
|
+
if (t !== null && (tier === null || t < tier)) tier = t;
|
|
100
|
+
}
|
|
101
|
+
if (tier !== null) scored.push({ item, tier, name: names[0] ?? '', index });
|
|
102
|
+
});
|
|
103
|
+
scored.sort(
|
|
104
|
+
(a, b) =>
|
|
105
|
+
a.tier - b.tier ||
|
|
106
|
+
a.name.length - b.name.length ||
|
|
107
|
+
a.name.localeCompare(b.name, undefined, { sensitivity: 'base' }) ||
|
|
108
|
+
a.index - b.index,
|
|
109
|
+
);
|
|
110
|
+
return scored.slice(0, limit).map((s) => s.item);
|
|
111
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import {
|
|
2
|
+
KNOWLEDGE_BASE_DIR,
|
|
3
|
+
SKILLS_DIR,
|
|
4
|
+
currentKbLayout,
|
|
5
|
+
isPersonalPluginFolder,
|
|
6
|
+
pluginOfPath,
|
|
7
|
+
type FileTreeEntry,
|
|
8
|
+
} from '@bevel-software/platform-shared';
|
|
9
|
+
import type { LibrarySkillSummary } from '../../library/services/library.api';
|
|
10
|
+
import type { PluginSummary } from '../../library/services/plugins.api';
|
|
11
|
+
import type { ToolSecrets } from '../../secrets-vault/services/tool-secrets.api';
|
|
12
|
+
import { pathForPlugin, urlForLibraryItem } from '../../library/routes/library-paths';
|
|
13
|
+
import { pluginLabel, pluginNameForPath } from '../../library/utils/plugin-summary';
|
|
14
|
+
import { PERSONAL_PLUGIN_NAME } from '../../library/utils/personal-plugin';
|
|
15
|
+
import { displayFileName } from '../../workspace/utils/display-file-name';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* What the search palette lists, flattened out of the two places it reads:
|
|
19
|
+
* the Knowledge tree (pages) and the Library catalog (skills, tools, plugins).
|
|
20
|
+
*
|
|
21
|
+
* Pure, like `rank.ts` beside it: the palette hands in what it loaded and
|
|
22
|
+
* gets rows back, so the row shapes — the name a person types, the faint
|
|
23
|
+
* location after it, where Enter goes — are decided in one testable place.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
export type SearchResultKind = 'page' | 'skill' | 'tool' | 'plugin';
|
|
27
|
+
|
|
28
|
+
export interface SearchResult {
|
|
29
|
+
/** Unique across both groups — it becomes the option's DOM id. */
|
|
30
|
+
key: string;
|
|
31
|
+
kind: SearchResultKind;
|
|
32
|
+
/** What is shown, and what the query is matched against. */
|
|
33
|
+
name: string;
|
|
34
|
+
/** The faint text after the name: a page's folder, an item's plugin. */
|
|
35
|
+
location: string;
|
|
36
|
+
/**
|
|
37
|
+
* Where choosing the row goes. A page is a WORKSPACE PATH, opened on the
|
|
38
|
+
* branch on screen; a Library entry is a URL the Library already builds.
|
|
39
|
+
*/
|
|
40
|
+
target: { kind: 'workspace'; path: string } | { kind: 'url'; url: string };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** What a page is called, without the extension the reader did not choose. */
|
|
44
|
+
function pageTitle(path: string, kbDirName: string | null): string {
|
|
45
|
+
return displayFileName(path, kbDirName).replace(/\.(md|markdown)$/i, '');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The folder a page sits in, said the way the explorer says it: relative to
|
|
50
|
+
* the Knowledge section, which hoists `KnowledgeBase/`'s children and folds
|
|
51
|
+
* any other content folder in beside them. A page at the top of the section
|
|
52
|
+
* sits in "Knowledge".
|
|
53
|
+
*/
|
|
54
|
+
function pageLocation(relativePath: string, kbDirName: string | null): string {
|
|
55
|
+
let segments = relativePath.split('/');
|
|
56
|
+
if (kbDirName && segments[0] === kbDirName) segments = segments.slice(1);
|
|
57
|
+
if (segments[0] === KNOWLEDGE_BASE_DIR) segments = segments.slice(1);
|
|
58
|
+
const folders = segments.slice(0, -1);
|
|
59
|
+
return folders.length > 0 ? folders.join(' / ') : 'Knowledge';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Page rows for the files `knowledgeFiles` returned. `excluded` names paths
|
|
64
|
+
* that are in the tree without being openable — the caller's own proposed
|
|
65
|
+
* files, which exist only behind a change request, so opening one by path
|
|
66
|
+
* would land on a 404.
|
|
67
|
+
*/
|
|
68
|
+
export function pageResults(
|
|
69
|
+
files: readonly FileTreeEntry[],
|
|
70
|
+
kbDirName: string | null,
|
|
71
|
+
excluded: { has(path: string): boolean },
|
|
72
|
+
): SearchResult[] {
|
|
73
|
+
return files
|
|
74
|
+
.filter((f) => !excluded.has(f.relativePath))
|
|
75
|
+
.map((f) => ({
|
|
76
|
+
key: `page:${f.relativePath}`,
|
|
77
|
+
kind: 'page',
|
|
78
|
+
name: pageTitle(f.relativePath, kbDirName),
|
|
79
|
+
location: pageLocation(f.relativePath, kbDirName),
|
|
80
|
+
target: { kind: 'workspace', path: f.relativePath },
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Where a skill or tool lives, as the Library names it: its plugin's display
|
|
86
|
+
* name (the inline membership a skill carries, else the plugin whose folder
|
|
87
|
+
* holds the path), the personal plugin for a personal shelf, and the shared
|
|
88
|
+
* `Skills/` root by its own name.
|
|
89
|
+
*/
|
|
90
|
+
function itemLocation(
|
|
91
|
+
path: string,
|
|
92
|
+
memberships: readonly { name: string; linked: boolean }[] | undefined,
|
|
93
|
+
plugins: readonly PluginSummary[],
|
|
94
|
+
): string {
|
|
95
|
+
const plugin = memberships?.find((m) => !m.linked)?.name ?? pluginNameForPath(path, plugins);
|
|
96
|
+
if (plugin) return pluginLabel(plugin, plugins);
|
|
97
|
+
const folder = pluginOfPath(path, currentKbLayout());
|
|
98
|
+
if (folder !== null && isPersonalPluginFolder(folder)) return PERSONAL_PLUGIN_NAME;
|
|
99
|
+
if (path === SKILLS_DIR || path.startsWith(`${SKILLS_DIR}/`)) return SKILLS_DIR;
|
|
100
|
+
return 'Skills & Tools';
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface LibraryCatalog {
|
|
104
|
+
skills: readonly LibrarySkillSummary[];
|
|
105
|
+
tools: readonly ToolSecrets[];
|
|
106
|
+
plugins: readonly PluginSummary[];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Skill, tool and plugin rows, in that order. Skills and tools open at their
|
|
111
|
+
* canonical item URL (`urlForLibraryItem`, the rule every Library card
|
|
112
|
+
* follows), which needs the checkout's name — without it they are left out
|
|
113
|
+
* rather than linked somewhere wrong. Plugins open on their own page, and are
|
|
114
|
+
* listed even when only the skills' memberships name them (`pluginNames`).
|
|
115
|
+
*
|
|
116
|
+
* Proposals (skills and tools that exist only on a change request) are not
|
|
117
|
+
* listed: their rows in the Library open a review, not a page, and a search
|
|
118
|
+
* result that opens something other than the thing named would be a trap.
|
|
119
|
+
*/
|
|
120
|
+
export function libraryResults(catalog: LibraryCatalog, kbDirName: string | null): SearchResult[] {
|
|
121
|
+
const { plugins } = catalog;
|
|
122
|
+
const skills: SearchResult[] = kbDirName
|
|
123
|
+
? catalog.skills.map((s) => ({
|
|
124
|
+
key: `skill:${s.path}`,
|
|
125
|
+
kind: 'skill',
|
|
126
|
+
name: s.name,
|
|
127
|
+
location: itemLocation(s.path, s.plugins, plugins),
|
|
128
|
+
target: { kind: 'url', url: urlForLibraryItem(kbDirName, { kind: 'skill', id: s.name, path: s.path }) },
|
|
129
|
+
}))
|
|
130
|
+
: [];
|
|
131
|
+
const tools: SearchResult[] = kbDirName
|
|
132
|
+
? catalog.tools.map((t) => ({
|
|
133
|
+
// Slug AND path: one `mcp.json` declares several servers, so the path
|
|
134
|
+
// alone does not tell two of them apart.
|
|
135
|
+
key: `tool:${t.path}:${t.slug}`,
|
|
136
|
+
kind: 'tool',
|
|
137
|
+
name: t.name,
|
|
138
|
+
location: itemLocation(t.path, undefined, plugins),
|
|
139
|
+
target: {
|
|
140
|
+
kind: 'url',
|
|
141
|
+
url: urlForLibraryItem(kbDirName, { kind: 'integration', id: t.slug, path: t.path }),
|
|
142
|
+
},
|
|
143
|
+
}))
|
|
144
|
+
: [];
|
|
145
|
+
const pluginRows: SearchResult[] = pluginNames(catalog).map((name) => ({
|
|
146
|
+
key: `plugin:${name}`,
|
|
147
|
+
kind: 'plugin',
|
|
148
|
+
name: pluginLabel(name, plugins),
|
|
149
|
+
location: 'Plugin',
|
|
150
|
+
target: { kind: 'url', url: pathForPlugin(name) },
|
|
151
|
+
}));
|
|
152
|
+
return [...skills, ...tools, ...pluginRows];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Every plugin the catalog proves is there, from both witnesses the Library's
|
|
157
|
+
* plugin rows read: the plugin index, then any plugin a skill names as one it
|
|
158
|
+
* belongs to (inline or linked) that the index did not list. The second is
|
|
159
|
+
* what keeps plugins findable when `/api/plugins` fails and the index arrives
|
|
160
|
+
* empty: the skills still carry their plugins' identities.
|
|
161
|
+
*/
|
|
162
|
+
function pluginNames(catalog: LibraryCatalog): string[] {
|
|
163
|
+
const listed = new Set(catalog.plugins.map((p) => p.name));
|
|
164
|
+
const named = new Set<string>();
|
|
165
|
+
for (const skill of catalog.skills) {
|
|
166
|
+
for (const m of skill.plugins ?? []) if (!listed.has(m.name)) named.add(m.name);
|
|
167
|
+
}
|
|
168
|
+
return [...listed, ...[...named].sort((a, b) => a.localeCompare(b))];
|
|
169
|
+
}
|
|
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useRef, useState } from 'react';
|
|
|
2
2
|
import type { Change, FileLock } from '@bevel-software/platform-shared';
|
|
3
3
|
import {
|
|
4
4
|
acquireLock as acquireLockApi,
|
|
5
|
+
EDITING_ENDED_MESSAGE,
|
|
5
6
|
checkpointLockedFile,
|
|
6
7
|
getLock as getLockApi,
|
|
7
8
|
heartbeatLock,
|
|
@@ -35,8 +36,8 @@ interface UseFileLockArgs {
|
|
|
35
36
|
* by me" responses from the server during the brief window between a
|
|
36
37
|
* tab-switch cleanup releasing the lock and the backend actually
|
|
37
38
|
* committing the release — without this, switching away and back to a
|
|
38
|
-
* file you were just editing would flicker an amber "
|
|
39
|
-
*
|
|
39
|
+
* file you were just editing would flicker an amber "[your own name]
|
|
40
|
+
* is editing this page" banner. Optional so test harnesses without auth context
|
|
40
41
|
* still work; in that case nothing is filtered.
|
|
41
42
|
*/
|
|
42
43
|
currentUserId?: string | null;
|
|
@@ -116,7 +117,7 @@ interface UseFileLockReturn {
|
|
|
116
117
|
* a heartbeat fails (lock expired, stolen, branch deleted) we drop
|
|
117
118
|
* `holdingLock` so the UI can re-arm.
|
|
118
119
|
* - External holder polling when we don't hold the lock. The editor
|
|
119
|
-
* surface shows "
|
|
120
|
+
* surface shows "X is editing this page" via `externalLock`.
|
|
120
121
|
* - Autosave checkpoints. Every minute while holding the lock, persist
|
|
121
122
|
* the latest buffer + commit. The lock stays held — releasing here
|
|
122
123
|
* would race against the next keystroke.
|
|
@@ -164,7 +165,7 @@ export function useFileLock(args: UseFileLockArgs): UseFileLockReturn {
|
|
|
164
165
|
holder: result.lock.holderName,
|
|
165
166
|
holderUserId: result.lock.holderUserId,
|
|
166
167
|
});
|
|
167
|
-
const msg =
|
|
168
|
+
const msg = `${result.lock.holderName} is editing this page`;
|
|
168
169
|
setHoldingLock(false);
|
|
169
170
|
setExternalLock(result.lock);
|
|
170
171
|
setLockError(msg);
|
|
@@ -245,7 +246,9 @@ export function useFileLock(args: UseFileLockArgs): UseFileLockReturn {
|
|
|
245
246
|
// on the next dirty edit.
|
|
246
247
|
const msg = err instanceof Error ? err.message : String(err);
|
|
247
248
|
console.warn('[useFileLock] heartbeat lost', { workspaceId, branch, path, error: msg });
|
|
248
|
-
|
|
249
|
+
// The session-ended sentence already says editing stopped; anything
|
|
250
|
+
// else is a reason, and gets the prefix that makes it one.
|
|
251
|
+
setLockError(msg === EDITING_ENDED_MESSAGE ? msg : `Editing stopped: ${msg}`);
|
|
249
252
|
setHoldingLock(false);
|
|
250
253
|
}
|
|
251
254
|
}, HEARTBEAT_INTERVAL_MS);
|
|
@@ -268,7 +271,7 @@ export function useFileLock(args: UseFileLockArgs): UseFileLockReturn {
|
|
|
268
271
|
// time without per-tab polling traffic.
|
|
269
272
|
//
|
|
270
273
|
// We bail on the subscription path when the bus isn't mounted (tests),
|
|
271
|
-
// and the initial fetch is enough to render a static "
|
|
274
|
+
// and the initial fetch is enough to render a static "X is editing this page" if
|
|
272
275
|
// anyone holds it at mount time.
|
|
273
276
|
const bus = useEventBus();
|
|
274
277
|
useEffect(() => {
|
|
@@ -277,7 +280,7 @@ export function useFileLock(args: UseFileLockArgs): UseFileLockReturn {
|
|
|
277
280
|
// "Lock held by me" means the previous tab's cleanup hasn't finished
|
|
278
281
|
// committing the release on the backend yet — we just switched away
|
|
279
282
|
// and back fast enough that the persist+release is still in flight.
|
|
280
|
-
// We don't want to render an amber "
|
|
283
|
+
// We don't want to render an amber "[you] is editing this page" banner
|
|
281
284
|
// for that fraction of a second; the SSE `lock-released` event
|
|
282
285
|
// will arrive shortly and we'll be back to a clean state.
|
|
283
286
|
const isSelfLock = (lock: FileLock | null): boolean =>
|