@bevel-software/platform-core-frontend 0.26.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +87 -25
  3. package/src/core/ProductName.tsx +49 -0
  4. package/src/core/__tests__/ProductName.test.tsx +46 -0
  5. package/src/core/__tests__/ShellRoutes.test.tsx +22 -0
  6. package/src/core/__tests__/core-contributions.test.ts +16 -0
  7. package/src/core/core-contributions.ts +17 -0
  8. package/src/core/maker-url.ts +30 -0
  9. package/src/core/registry.ts +78 -1
  10. package/src/index.css +23 -5
  11. package/src/index.ts +5 -0
  12. package/src/lib/__tests__/latest-request.test.ts +48 -0
  13. package/src/lib/latest-request.ts +45 -0
  14. package/src/modules/access/__tests__/ManageAccessDialog.no-sso-invite.test.tsx +222 -0
  15. package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +1 -1
  16. package/src/modules/access/api.ts +19 -3
  17. package/src/modules/access/components/ManageAccessDialog.tsx +61 -8
  18. package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +16 -1
  19. package/src/modules/admin/__tests__/RolesCorruptedBanner.test.tsx +70 -0
  20. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +284 -39
  21. package/src/modules/admin/components/AdminRolesPage.tsx +13 -14
  22. package/src/modules/admin/components/RolesCorruptedBanner.tsx +9 -4
  23. package/src/modules/admin/components/UserAccountsPage.tsx +91 -107
  24. package/src/modules/admin/services/roles.api.ts +14 -1
  25. package/src/modules/auth/__tests__/LoginScreen.test.tsx +80 -5
  26. package/src/modules/auth/__tests__/sso-strict-probe.test.ts +66 -0
  27. package/src/modules/auth/components/LoginScreen.tsx +101 -73
  28. package/src/modules/auth/services/account.api.ts +59 -3
  29. package/src/modules/auth/services/sso.ts +30 -10
  30. package/src/modules/auth/state/use-sign-in-methods.ts +41 -0
  31. package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +176 -0
  32. package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +68 -0
  33. package/src/modules/change-requests/__tests__/ChangeRequestLink.test.tsx +182 -0
  34. package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +1 -1
  35. package/src/modules/change-requests/__tests__/readFileOnBranch.test.ts +79 -0
  36. package/src/modules/change-requests/components/ChangeBox.tsx +6 -1
  37. package/src/modules/change-requests/components/ChangeRequestDialog.tsx +45 -15
  38. package/src/modules/change-requests/components/ChangeRequestLink.tsx +151 -0
  39. package/src/modules/change-requests/components/CrFileTree.tsx +2 -1
  40. package/src/modules/change-requests/components/FileChangeBoxes.tsx +4 -2
  41. package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +6 -3
  42. package/src/modules/change-requests/services/change-requests.api.ts +15 -2
  43. package/src/modules/change-requests/utils/readFailure.ts +22 -0
  44. package/src/modules/embed/__tests__/EmbedLinkPage.test.tsx +74 -0
  45. package/src/modules/embed/__tests__/EmbedView.test.tsx +473 -0
  46. package/src/modules/embed/__tests__/embed-config.test.ts +128 -0
  47. package/src/modules/embed/__tests__/embed-host.test.ts +111 -0
  48. package/src/modules/embed/__tests__/mcp-app-view.test.ts +295 -0
  49. package/src/modules/embed/__tests__/mount.test.tsx +157 -0
  50. package/src/modules/embed/components/EmbedLinkPage.tsx +109 -0
  51. package/src/modules/embed/components/EmbedView.tsx +545 -0
  52. package/src/modules/embed/embed-config.ts +132 -0
  53. package/src/modules/embed/embed-host.ts +120 -0
  54. package/src/modules/embed/mount.tsx +80 -0
  55. package/src/modules/embed/services/embed-token.ts +22 -0
  56. package/src/modules/embed/services/embed.api.ts +158 -0
  57. package/src/modules/git/__tests__/BranchSwitcher.test.tsx +202 -4
  58. package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +59 -1
  59. package/src/modules/git/__tests__/PullNeededBanner.test.tsx +39 -22
  60. package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +7 -2
  61. package/src/modules/git/branch-delete-menu-item.tsx +24 -0
  62. package/src/modules/git/components/BranchSwitcher.tsx +29 -5
  63. package/src/modules/git/components/GitSyncFailedBanner.tsx +53 -15
  64. package/src/modules/git/components/HistoryVersionPreview.tsx +5 -3
  65. package/src/modules/git/components/PullNeededBanner.tsx +15 -49
  66. package/src/modules/git/hooks/useAutoPullUpdates.ts +9 -5
  67. package/src/modules/git/index.ts +15 -0
  68. package/src/modules/git/services/__tests__/error-messages.test.ts +67 -0
  69. package/src/modules/git/services/__tests__/pull-failure.test.ts +36 -0
  70. package/src/modules/git/services/error-messages.ts +58 -1
  71. package/src/modules/git/services/pull-failure.ts +68 -0
  72. package/src/modules/git/state/branch-delete-confirm.ts +46 -0
  73. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +1 -0
  74. package/src/modules/layout/__tests__/breakpoints.test.ts +7 -1
  75. package/src/modules/layout/breakpoints.ts +8 -0
  76. package/src/modules/library/__tests__/PluginExtras.test.tsx +9 -9
  77. package/src/modules/library/__tests__/PluginPage.test.tsx +8 -1
  78. package/src/modules/library/__tests__/SkillsTree.test.tsx +13 -4
  79. package/src/modules/library/components/LibraryPage.tsx +22 -0
  80. package/src/modules/library/components/PluginExtras.tsx +23 -6
  81. package/src/modules/library/components/PluginPage.tsx +6 -1
  82. package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
  83. package/src/modules/library/services/plugins.api.ts +4 -1
  84. package/src/modules/library/state/plugins-revision.ts +28 -0
  85. package/src/modules/onboarding/__tests__/InviteButton.test.tsx +214 -0
  86. package/src/modules/onboarding/__tests__/agent-connection-api.test.ts +55 -0
  87. package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +87 -82
  88. package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +164 -0
  89. package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1458 -0
  90. package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +811 -0
  91. package/src/modules/onboarding/__tests__/invite-emails.test.ts +247 -0
  92. package/src/modules/onboarding/__tests__/onboarding.test.tsx +226 -193
  93. package/src/modules/onboarding/__tests__/starter-pack-card.test.tsx +136 -0
  94. package/src/modules/onboarding/components/CreatorWelcomePage.tsx +7 -11
  95. package/src/modules/onboarding/components/EmailChipsInput.tsx +138 -0
  96. package/src/modules/onboarding/components/GetStartedColumn.tsx +670 -0
  97. package/src/modules/onboarding/components/InviteButton.tsx +139 -0
  98. package/src/modules/onboarding/components/InviteDialog.tsx +741 -0
  99. package/src/modules/onboarding/components/RootLanding.tsx +8 -24
  100. package/src/modules/onboarding/components/StarterPackCard.tsx +98 -0
  101. package/src/modules/onboarding/components/WelcomePage.tsx +65 -154
  102. package/src/modules/onboarding/first-page-prompt.ts +123 -0
  103. package/src/modules/onboarding/invite-emails.ts +313 -0
  104. package/src/modules/onboarding/services/agent-connection.api.ts +53 -0
  105. package/src/modules/onboarding/services/starter-packs.api.ts +83 -0
  106. package/src/modules/onboarding/state/agent-connection.ts +167 -0
  107. package/src/modules/onboarding/state/invite-dialog.context.ts +35 -0
  108. package/src/modules/onboarding/state/invite-dialog.tsx +39 -0
  109. package/src/modules/onboarding/state/onboarding.ts +133 -59
  110. package/src/modules/onboarding/state/starter-packs.ts +169 -0
  111. package/src/modules/settings/settings-nav-items.tsx +8 -3
  112. package/src/modules/setup/__tests__/setup.first-run-storage.test.tsx +389 -0
  113. package/src/modules/setup/__tests__/setup.github.test.tsx +5 -5
  114. package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +1 -1
  115. package/src/modules/setup/__tests__/setup.repository-change.test.tsx +1 -1
  116. package/src/modules/setup/__tests__/setup.repository.test.tsx +21 -21
  117. package/src/modules/setup/__tests__/setup.test.tsx +56 -15
  118. package/src/modules/setup/__tests__/useConnectionProbe.test.tsx +123 -0
  119. package/src/modules/setup/components/FirstRunStorage.tsx +560 -0
  120. package/src/modules/setup/components/SetupGate.tsx +46 -1
  121. package/src/modules/setup/components/SetupScreen.tsx +81 -84
  122. package/src/modules/setup/hooks/useConnectionProbe.ts +93 -0
  123. package/src/modules/setup/services/setup.api.ts +3 -3
  124. package/src/modules/setup/utils/suggested-branch.ts +27 -0
  125. package/src/modules/toolbar/commands/__tests__/actions.test.tsx +210 -0
  126. package/src/modules/toolbar/commands/actions.tsx +330 -0
  127. package/src/modules/toolbar/commands/command-menu.ts +44 -0
  128. package/src/modules/toolbar/commands/useCommandActions.ts +71 -0
  129. package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
  130. package/src/modules/toolbar/components/AppSwitcher.tsx +125 -22
  131. package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
  132. package/src/modules/toolbar/components/ProfileMenu.tsx +9 -4
  133. package/src/modules/toolbar/components/SearchPalette.tsx +540 -0
  134. package/src/modules/toolbar/components/Toolbar.tsx +10 -0
  135. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +230 -52
  136. package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
  137. package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +864 -0
  138. package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +57 -2
  139. package/src/modules/toolbar/search/__tests__/rank.test.ts +93 -0
  140. package/src/modules/toolbar/search/__tests__/sources.test.ts +131 -0
  141. package/src/modules/toolbar/search/rank.ts +111 -0
  142. package/src/modules/toolbar/search/sources.ts +169 -0
  143. package/src/modules/workflow/hooks/useFileLock.ts +10 -7
  144. package/src/modules/workflow/services/__tests__/lock.api.test.ts +41 -0
  145. package/src/modules/workflow/services/lock.api.ts +17 -2
  146. package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +49 -1
  147. package/src/modules/workspace/components/EditorTabs.tsx +39 -15
  148. package/src/modules/workspace/components/FileExplorer.tsx +39 -6
  149. package/src/modules/workspace/components/FilePaneCard.tsx +6 -2
  150. package/src/modules/workspace/components/FileRoute.tsx +12 -7
  151. package/src/modules/workspace/components/FileViewer.tsx +271 -74
  152. package/src/modules/workspace/components/KbPageHeader.tsx +13 -6
  153. package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +88 -21
  154. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +92 -4
  155. package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +23 -3
  156. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +330 -6
  157. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +17 -2
  158. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -16
  159. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +6 -0
  160. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +23 -21
  161. package/src/modules/workspace/components/renderers/ImageRenderer.tsx +13 -29
  162. package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +9 -2
  163. package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +8 -0
  164. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +14 -19
  165. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +11 -17
  166. package/src/modules/workspace/components/renderers/ToolRenderer.tsx +35 -7
  167. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -17
  168. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.links.test.tsx +73 -0
  169. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.scaffold.test.tsx +64 -0
  170. package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.surface.test.tsx +82 -0
  171. package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +99 -0
  172. package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +129 -35
  173. package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +149 -0
  174. package/src/modules/workspace/components/renderers/__tests__/kbMarkdownLinkPolicy.test.tsx +100 -0
  175. package/src/modules/workspace/components/renderers/htmlSandbox.ts +76 -20
  176. package/src/modules/workspace/components/renderers/index.ts +26 -0
  177. package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +51 -1
  178. package/src/modules/workspace/components/renderers/rendererRawRead.ts +53 -0
  179. package/src/modules/workspace/components/renderers/rendererSurface.ts +109 -0
  180. package/src/modules/workspace/components/renderers/rendererWorkspace.ts +8 -2
  181. package/src/modules/workspace/hooks/__tests__/useCreatePage.test.ts +137 -0
  182. package/src/modules/workspace/hooks/__tests__/useKnowledgeWriteTarget.test.ts +302 -0
  183. package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +126 -21
  184. package/src/modules/workspace/hooks/useCreatePage.ts +206 -0
  185. package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +238 -0
  186. package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +24 -7
  187. package/src/modules/workspace/hooks/useWorkspaceState.ts +42 -8
  188. package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +10 -0
  189. package/src/modules/workspace/routing/__tests__/md-links-parity.test.tsx +113 -0
  190. package/src/modules/workspace/routing/kb-routes.ts +66 -12
  191. package/src/modules/workspace/state/editable-page.ts +42 -0
  192. package/src/modules/workspace/state/workspace.context.ts +13 -4
  193. package/src/modules/workspace/utils/__tests__/display-file-name.test.ts +60 -0
  194. package/src/modules/workspace/utils/__tests__/fileTree.test.ts +75 -0
  195. package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +16 -0
  196. package/src/modules/workspace/utils/display-file-name.ts +102 -0
  197. package/src/modules/workspace/utils/fileTree.ts +49 -14
  198. package/src/modules/workspace/utils/treeConfirm.ts +15 -0
  199. package/src/shared/__tests__/no-builtin-confirm.test.ts +102 -0
  200. package/src/shared/components/ConfirmProvider.tsx +156 -0
  201. package/src/shared/components/Dialog.tsx +7 -0
  202. package/src/shared/components/__tests__/ConfirmProvider.test.tsx +198 -0
  203. package/src/shared/components/confirm-context.ts +94 -0
  204. package/src/shared/components/index.ts +3 -0
  205. package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
  206. package/src/modules/onboarding/welcome-state.ts +0 -36
@@ -0,0 +1,210 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import type { AdminMenuItem, AppDef } from '../../../../core/registry';
3
+ import {
4
+ COMMAND_SHORTCUTS,
5
+ coreCommandActions,
6
+ mergeCommandActions,
7
+ suggestedActions,
8
+ visibleActions,
9
+ type CommandAction,
10
+ type CommandContext,
11
+ } from '../actions';
12
+
13
+ /**
14
+ * The command list on its own, without a menu: what core offers, what each
15
+ * context hides, and how a distribution's commands join it.
16
+ */
17
+
18
+ const APPS: AppDef[] = [
19
+ // Out of order on purpose: the commands follow the switcher's `order`.
20
+ { id: 'skills-tools', label: 'Skills & Tools', path: '/skills-and-tools', order: 20, element: <></> },
21
+ { id: 'knowledge', label: 'Knowledge', path: '/workspace', order: 10, element: <></> },
22
+ ];
23
+
24
+ const USER = { id: 'u1', email: 'ada@example.com', name: 'Ada' };
25
+
26
+ const row = (over: Partial<AdminMenuItem> & { id: string }): AdminMenuItem => ({ label: over.id, ...over });
27
+
28
+ function ctx(over: Partial<CommandContext> = {}): CommandContext {
29
+ return {
30
+ navigate: vi.fn(),
31
+ user: USER,
32
+ isAdmin: false,
33
+ activeAppId: 'knowledge',
34
+ openFilePath: null,
35
+ editablePage: null,
36
+ openWorkspacePath: vi.fn(),
37
+ invite: { open: vi.fn(), invitedRevision: 0 },
38
+ createPage: vi.fn(async () => 'kb/KnowledgeBase/Untitled.md'),
39
+ onboardingPending: false,
40
+ ...over,
41
+ };
42
+ }
43
+
44
+ const labels = (actions: CommandAction[]) => actions.map((a) => a.label);
45
+
46
+ describe('coreCommandActions', () => {
47
+ const settings = {
48
+ defaultItems: [
49
+ row({ id: 'secrets', label: 'Secrets', path: '/secrets' }),
50
+ row({ id: 'dialog-row', label: 'Feedback', dialog: () => <></> }),
51
+ row({ id: 'node-label', label: <b>Fancy</b>, path: '/fancy' }),
52
+ ],
53
+ adminItems: [row({ id: 'roles', label: 'App roles', path: '/roles-and-members' })],
54
+ };
55
+ const all = coreCommandActions({ apps: APPS, settings });
56
+
57
+ it('offers a member the page verbs, the apps and their own settings', () => {
58
+ expect(labels(visibleActions(all, ctx()))).toEqual([
59
+ 'New page',
60
+ 'Connect your agent',
61
+ 'Go to Knowledge',
62
+ 'Go to Skills & Tools',
63
+ 'Settings: Secrets',
64
+ ]);
65
+ });
66
+
67
+ it('adds Invite people and the admin settings for an admin', () => {
68
+ expect(labels(visibleActions(all, ctx({ isAdmin: true })))).toEqual([
69
+ 'New page',
70
+ 'Invite people',
71
+ 'Connect your agent',
72
+ 'Go to Knowledge',
73
+ 'Go to Skills & Tools',
74
+ 'Settings: Secrets',
75
+ 'Settings: App roles',
76
+ ]);
77
+ });
78
+
79
+ it('leaves out New page before the workspace knows its folder, and Invite with no dialog to open', () => {
80
+ const shown = labels(visibleActions(all, ctx({ isAdmin: true, createPage: null, invite: null })));
81
+ expect(shown).not.toContain('New page');
82
+ expect(shown).not.toContain('Invite people');
83
+ });
84
+
85
+ it('offers Edit this page only for the open page the viewer says can be edited', () => {
86
+ const page = 'kb/KnowledgeBase/Notes.md';
87
+ expect(labels(visibleActions(all, ctx({ openFilePath: page })))).not.toContain('Edit this page');
88
+ expect(labels(visibleActions(all, ctx({ openFilePath: page, editablePage: page })))).toContain('Edit this page');
89
+ // A stale verdict for another page offers nothing.
90
+ expect(labels(visibleActions(all, ctx({ openFilePath: page, editablePage: 'kb/Other.md' })))).not.toContain(
91
+ 'Edit this page',
92
+ );
93
+ });
94
+
95
+ it('runs a settings row’s own onSelect ahead of its path, as the profile menu does', () => {
96
+ const onSelect = vi.fn(({ navigate }: { navigate(to: string): void }) => navigate('/chosen'));
97
+ const [action] = coreCommandActions({
98
+ apps: [],
99
+ settings: { defaultItems: [row({ id: 'x', label: 'X', path: '/declared', onSelect })], adminItems: [] },
100
+ }).filter((a) => a.id === 'settings:x');
101
+ const c = ctx();
102
+ void action.run(c);
103
+ expect(c.navigate).toHaveBeenCalledWith('/chosen');
104
+ expect(c.navigate).not.toHaveBeenCalledWith('/declared');
105
+ expect(onSelect).toHaveBeenCalledWith(expect.objectContaining({ user: USER }));
106
+ });
107
+
108
+ it('offers a settings row only while its isShown holds for the signed-in person, as the profile menu does', () => {
109
+ const isShown = vi.fn((user: { email: string }) => user.email === 'ada@example.com');
110
+ const actions = coreCommandActions({
111
+ apps: [],
112
+ settings: { defaultItems: [row({ id: 'undo', label: 'Ask again', onSelect: vi.fn(), isShown })], adminItems: [] },
113
+ });
114
+ expect(labels(visibleActions(actions, ctx()))).toContain('Settings: Ask again');
115
+ expect(labels(visibleActions(actions, ctx({ user: { ...USER, email: 'bob@example.com' } })))).not.toContain(
116
+ 'Settings: Ask again',
117
+ );
118
+ // Signed out there is nobody to show the profile menu's rows to.
119
+ expect(labels(visibleActions(actions, ctx({ user: null })))).not.toContain('Settings: Ask again');
120
+ // Never asked about nobody: `visibleActions` hides a row whose check
121
+ // throws, so the label alone would pass without the signed-in gate.
122
+ expect(isShown).toHaveBeenCalledTimes(2);
123
+ });
124
+ });
125
+
126
+ describe('shortcut hints', () => {
127
+ it('come from the table the shortcuts are bound by, and only for bound commands', () => {
128
+ const all = coreCommandActions({ apps: APPS, settings: { defaultItems: [], adminItems: [] } });
129
+ const hint = (id: string) => all.find((a) => a.id === id)?.shortcut;
130
+ expect(hint('new-page')).toEqual(['C']);
131
+ expect(hint('go-to:knowledge')).toEqual(['G', 'K']);
132
+ expect(hint('go-to:skills-tools')).toEqual(['G', 'S']);
133
+ expect(hint('invite')).toBeUndefined();
134
+ expect(Object.keys(COMMAND_SHORTCUTS).sort()).toEqual(['go-to:knowledge', 'go-to:skills-tools', 'new-page']);
135
+ });
136
+ });
137
+
138
+ describe('suggestedActions', () => {
139
+ const all = coreCommandActions({ apps: APPS, settings: { defaultItems: [], adminItems: [] } });
140
+ const suggest = (c: CommandContext) => labels(suggestedActions(visibleActions(all, c), c));
141
+
142
+ it('suggests the commonest verbs and the way to the other app', () => {
143
+ expect(suggest(ctx({ isAdmin: true, onboardingPending: true }))).toEqual([
144
+ 'New page',
145
+ 'Invite people',
146
+ 'Connect your agent',
147
+ 'Go to Skills & Tools',
148
+ ]);
149
+ expect(suggest(ctx({ activeAppId: 'skills-tools' }))).toEqual(['New page', 'Go to Knowledge']);
150
+ });
151
+ });
152
+
153
+ describe('mergeCommandActions / visibleActions', () => {
154
+ const core = coreCommandActions({ apps: [], settings: { defaultItems: [], adminItems: [] } });
155
+
156
+ it('puts the registry’s commands after core’s and drops a reused id', () => {
157
+ const error = vi.spyOn(console, 'error').mockImplementation(() => {});
158
+ const extra: CommandAction[] = [
159
+ { id: 'new-ontology', label: 'New ontology', visible: () => true, run: vi.fn() },
160
+ { id: 'new-page', label: 'Impostor', visible: () => true, run: vi.fn() },
161
+ ];
162
+ const merged = mergeCommandActions(core, extra);
163
+ expect(merged.map((a) => a.id).slice(-1)).toEqual(['new-ontology']);
164
+ expect(labels(merged)).not.toContain('Impostor');
165
+ expect(error).toHaveBeenCalled();
166
+ error.mockRestore();
167
+ });
168
+
169
+ it('keeps a registry command whose keys collide with bound ones, but drops its shortcut', () => {
170
+ const error = vi.spyOn(console, 'error').mockImplementation(() => {});
171
+ const withKeys = coreCommandActions({ apps: APPS, settings: { defaultItems: [], adminItems: [] } });
172
+ const extra: CommandAction[] = [
173
+ { id: 'clash', label: 'Clash', shortcut: ['c'], visible: () => true, run: vi.fn() },
174
+ { id: 'prefix', label: 'Prefix', shortcut: ['G'], visible: () => true, run: vi.fn() },
175
+ { id: 'longer', label: 'Longer', shortcut: ['g', 'k', 'x'], visible: () => true, run: vi.fn() },
176
+ // Three keys that collide with nothing: still unbindable, so still dropped.
177
+ { id: 'too-long', label: 'Too long', shortcut: ['x', 'y', 'z'], visible: () => true, run: vi.fn() },
178
+ { id: 'fine', label: 'Fine', shortcut: ['O'], visible: () => true, run: vi.fn() },
179
+ { id: 'also-fine', label: 'Also fine', shortcut: ['g', 'o'], visible: () => true, run: vi.fn() },
180
+ ];
181
+ const merged = mergeCommandActions(withKeys, extra);
182
+ const shortcutOf = (id: string) => merged.find((a) => a.id === id)?.shortcut;
183
+ expect(merged.map((a) => a.id).slice(-6)).toEqual(['clash', 'prefix', 'longer', 'too-long', 'fine', 'also-fine']);
184
+ expect(shortcutOf('clash')).toBeUndefined();
185
+ expect(shortcutOf('prefix')).toBeUndefined();
186
+ expect(shortcutOf('longer')).toBeUndefined();
187
+ expect(shortcutOf('too-long')).toBeUndefined();
188
+ expect(shortcutOf('fine')).toEqual(['O']);
189
+ expect(shortcutOf('also-fine')).toEqual(['g', 'o']);
190
+ expect(error).toHaveBeenCalledTimes(4);
191
+ error.mockRestore();
192
+ });
193
+
194
+ it('drops a command whose visible() throws, and keeps the rest', () => {
195
+ const error = vi.spyOn(console, 'error').mockImplementation(() => {});
196
+ const broken: CommandAction = {
197
+ id: 'broken',
198
+ label: 'Broken',
199
+ visible: () => {
200
+ throw new Error('boom');
201
+ },
202
+ run: vi.fn(),
203
+ };
204
+ expect(labels(visibleActions(mergeCommandActions(core, [broken]), ctx()))).toEqual([
205
+ 'New page',
206
+ 'Connect your agent',
207
+ ]);
208
+ error.mockRestore();
209
+ });
210
+ });
@@ -0,0 +1,330 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { AuthUser } from '@bevel-software/platform-shared';
3
+ import { ArrowRight, FilePlus, Pencil, Plug, Settings, UserPlus } from 'lucide-react';
4
+ import type { AdminMenuItem, AppDef } from '../../../core/registry';
5
+ import type { MenuSections } from '../../settings/settings-nav-items';
6
+ import type { InviteDialogController } from '../../onboarding/state/invite-dialog.context';
7
+ import { WELCOME_PATH } from '../../onboarding/paths';
8
+
9
+ /**
10
+ * The commands the toolbar's menu can run, beside the pages and items it
11
+ * finds: "New page", "Invite people", "Settings: Secrets".
12
+ *
13
+ * A command is DATA plus two functions of a {@link CommandContext}, never a
14
+ * hook or a component of its own: whether it is offered right now
15
+ * (`visible`), and what it does (`run`). Everything a command needs from the
16
+ * app — the router, the admin verdict, the page on screen, the invite dialog —
17
+ * arrives in that one context, built once by `useCommandActions`. That keeps
18
+ * this list pure and testable, and it is what lets a distribution contribute
19
+ * commands (`AppRegistry.commandActions`) without reaching into core's hooks.
20
+ */
21
+
22
+ /** What a command can see and use when it is offered and when it runs. */
23
+ export interface CommandContext {
24
+ /** react-router navigation. */
25
+ navigate(to: string): void;
26
+ /** The signed-in person, or null signed out. */
27
+ user: AuthUser | null;
28
+ isAdmin: boolean;
29
+ /** The app on screen (see `useActiveAppId`); undefined on a settings page. */
30
+ activeAppId: string | undefined;
31
+ /** The workspace path of the file open in the viewer, or null. */
32
+ openFilePath: string | null;
33
+ /**
34
+ * The page on screen an Edit click would open for editing right now, or
35
+ * null — already editing, not writable, locked, nothing open (see
36
+ * `workspace/state/editable-page`).
37
+ */
38
+ editablePage: string | null;
39
+ /** Open a known workspace path; `edit` opens it in the editor (see `useFileNav`). */
40
+ openWorkspacePath(path: string, options?: { edit?: boolean; replace?: boolean }): void;
41
+ /** THE invite dialog, or null where none is mounted. */
42
+ invite: InviteDialogController | null;
43
+ /**
44
+ * Create an untitled page in a Knowledge folder the person may write and
45
+ * open it for editing (`useCreatePage`); null until the workspace knows
46
+ * where that is, and for someone who may write no Knowledge folder.
47
+ * Resolves with null when a refused write found nowhere left to write.
48
+ * Rejects with a message ready to show.
49
+ */
50
+ createPage: (() => Promise<string | null>) | null;
51
+ /** The connect-your-agent onboarding is still open for this person. */
52
+ onboardingPending: boolean;
53
+ }
54
+
55
+ export interface CommandAction {
56
+ /** Stable and unique among all commands — it keys the row and the suggestions. */
57
+ id: string;
58
+ /** What the row says, and the first thing a query is matched against. */
59
+ label: string;
60
+ /** Other words someone might type for it; matched like the label, never shown. */
61
+ keywords?: string[];
62
+ /** Faint text after the label, naming where the command belongs (a distribution's area, say). */
63
+ group?: string;
64
+ /**
65
+ * The keys that run it outside the menu: `['C']`, or `['G', 'K']` for a
66
+ * sequence of two. Shown on the row as its hint AND bound by
67
+ * `useCommandShortcuts`, under the same guards as core's, so a hint is
68
+ * never a key that does nothing. Core's are filled in from
69
+ * {@link COMMAND_SHORTCUTS}. A registry command's shortcut is dropped at
70
+ * merge time, hint and all, and said so in the console, when it is longer
71
+ * than two keys or would collide with keys already bound — the same keys,
72
+ * or a sequence one of them begins: give it other keys.
73
+ */
74
+ shortcut?: string[];
75
+ /** The row's icon; a generic arrow when absent. */
76
+ icon?: ReactNode;
77
+ /** Whether to offer it now. Called on every render of the menu, so keep it cheap. */
78
+ visible(ctx: CommandContext): boolean;
79
+ /**
80
+ * Do it. The menu has already closed. A rejection's message is shown — the
81
+ * menu opens again to say it — so a command need not report its own failure.
82
+ */
83
+ run(ctx: CommandContext): void | Promise<void>;
84
+ }
85
+
86
+ const ICON_SIZE = 15;
87
+
88
+ const NEW_PAGE: CommandAction = {
89
+ id: 'new-page',
90
+ label: 'New page',
91
+ keywords: ['create page', 'add page', 'write', 'document', 'note', 'untitled'],
92
+ icon: <FilePlus size={ICON_SIZE} />,
93
+ visible: (ctx) => ctx.createPage !== null,
94
+ run: async (ctx) => {
95
+ await ctx.createPage?.();
96
+ },
97
+ };
98
+
99
+ /**
100
+ * The page on screen, into the editor — through the same request the
101
+ * just-created page uses, so the lock and the fresh read are not skipped.
102
+ * `replace`: it is the page already showing, and a second history entry for
103
+ * it would make Back look broken.
104
+ */
105
+ const EDIT_PAGE: CommandAction = {
106
+ id: 'edit-page',
107
+ label: 'Edit this page',
108
+ keywords: ['edit', 'write', 'change', 'modify'],
109
+ icon: <Pencil size={ICON_SIZE} />,
110
+ visible: (ctx) => ctx.editablePage !== null && ctx.editablePage === ctx.openFilePath,
111
+ run: (ctx) => {
112
+ if (ctx.editablePage) ctx.openWorkspacePath(ctx.editablePage, { edit: true, replace: true });
113
+ },
114
+ };
115
+
116
+ /**
117
+ * Admins only: creating accounts is an admin act. The toolbar's Invite shows to
118
+ * everyone and tells a non-admin whom to ask; a command menu entry that only
119
+ * answers "ask an admin" would be noise in a list of things you can do.
120
+ */
121
+ const INVITE: CommandAction = {
122
+ id: 'invite',
123
+ label: 'Invite people',
124
+ keywords: ['team', 'teammates', 'members', 'users', 'add people', 'accounts'],
125
+ icon: <UserPlus size={ICON_SIZE} />,
126
+ visible: (ctx) => ctx.isAdmin && ctx.invite !== null,
127
+ run: (ctx) => ctx.invite?.open(),
128
+ };
129
+
130
+ /** Everyone's: the welcome page is how a person connects their own agent, onboarding concluded or not. */
131
+ const CONNECT_AGENT: CommandAction = {
132
+ id: 'connect-agent',
133
+ label: 'Connect your agent',
134
+ keywords: ['claude', 'chatgpt', 'cursor', 'mcp', 'set up', 'setup', 'welcome', 'connector'],
135
+ icon: <Plug size={ICON_SIZE} />,
136
+ visible: () => true,
137
+ run: (ctx) => ctx.navigate(WELCOME_PATH),
138
+ };
139
+
140
+ /** The id of the "Go to" command for an app — what suggestions and shortcuts refer to it by. */
141
+ export function goToAppActionId(appId: string): string {
142
+ return `go-to:${appId}`;
143
+ }
144
+
145
+ /**
146
+ * The single-key shortcuts, keyed by the command they run: `C` for New page,
147
+ * `G` then `K` for Knowledge, `G` then `S` for Skills & Tools. ONE table,
148
+ * read both by `useCommandShortcuts` (which binds the keys) and by the list
149
+ * below (which shows them as hints), so a row never advertises a key that
150
+ * does nothing. Lower-case is what is matched; the hints upper-case it.
151
+ */
152
+ export const COMMAND_SHORTCUTS: Readonly<Record<string, readonly string[]>> = {
153
+ 'new-page': ['c'],
154
+ [goToAppActionId('knowledge')]: ['g', 'k'],
155
+ [goToAppActionId('skills-tools')]: ['g', 's'],
156
+ };
157
+
158
+ /** A core command with its hint from {@link COMMAND_SHORTCUTS}, if it has one. */
159
+ function withShortcutHint(action: CommandAction): CommandAction {
160
+ const keys = COMMAND_SHORTCUTS[action.id];
161
+ return keys ? { ...action, shortcut: keys.map((k) => k.toUpperCase()) } : action;
162
+ }
163
+
164
+ /**
165
+ * One "Go to …" per app in the switcher, in the switcher's order. Offered
166
+ * even for the app on screen: from deep inside it, going to its start is
167
+ * still somewhere.
168
+ */
169
+ function appActions(apps: readonly AppDef[]): CommandAction[] {
170
+ return [...apps]
171
+ .sort((a, b) => (a.order ?? 100) - (b.order ?? 100))
172
+ .map((app) => ({
173
+ id: goToAppActionId(app.id),
174
+ label: `Go to ${app.label}`,
175
+ keywords: [app.label, 'switch app', 'open app'],
176
+ icon: <ArrowRight size={ICON_SIZE} />,
177
+ visible: () => true,
178
+ run: (ctx) => ctx.navigate(app.path),
179
+ }));
180
+ }
181
+
182
+ /**
183
+ * A command per row the profile menu shows, from the same merged list it
184
+ * reads (`useMenuSections`) — the admin section for admins only, as there.
185
+ *
186
+ * Two kinds of row are left out. A `dialog` row's dialog is mounted by the
187
+ * profile menu, driven by the menu's own open flags, so nothing outside it
188
+ * can open one. And a row whose label is not plain text cannot be typed for.
189
+ */
190
+ function settingsActions(settings: MenuSections): CommandAction[] {
191
+ const toAction = (item: AdminMenuItem, adminOnly: boolean): CommandAction | null => {
192
+ if (item.dialog || typeof item.label !== 'string') return null;
193
+ if (!item.path && !item.onSelect) return null;
194
+ const label = item.label;
195
+ return {
196
+ id: `settings:${item.id}`,
197
+ label: `Settings: ${label}`,
198
+ keywords: [label, 'preferences'],
199
+ icon: <Settings size={ICON_SIZE} />,
200
+ // The profile menu's gates: a person to show it to, admin rows for
201
+ // admins, and the row's own `isShown` for this person right now.
202
+ visible: (ctx) =>
203
+ ctx.user !== null && (!adminOnly || ctx.isAdmin) && (item.isShown?.(ctx.user) ?? true),
204
+ run: (ctx) => {
205
+ if (!ctx.user) return;
206
+ // The profile menu's precedence, minus the dialog: code first, then
207
+ // the declared destination.
208
+ if (item.onSelect) item.onSelect({ closeMenu: () => {}, navigate: ctx.navigate, user: ctx.user });
209
+ else if (item.path) ctx.navigate(item.path);
210
+ },
211
+ };
212
+ };
213
+ return [
214
+ ...settings.defaultItems.map((item) => toAction(item, false)),
215
+ ...settings.adminItems.map((item) => toAction(item, true)),
216
+ ].filter((a): a is CommandAction => a !== null);
217
+ }
218
+
219
+ /**
220
+ * Every command core offers, before visibility: the page verbs, the people
221
+ * verbs, the apps, then the settings. The order is the tie-breaker when two
222
+ * commands match a query equally well.
223
+ */
224
+ export function coreCommandActions({
225
+ apps,
226
+ settings,
227
+ }: {
228
+ apps: readonly AppDef[];
229
+ settings: MenuSections;
230
+ }): CommandAction[] {
231
+ return [NEW_PAGE, EDIT_PAGE, INVITE, CONNECT_AGENT, ...appActions(apps), ...settingsActions(settings)].map(
232
+ withShortcutHint,
233
+ );
234
+ }
235
+
236
+ /** A command's keys as `useCommandShortcuts` matches them: lower-cased, space-joined (`g k`); null without a shortcut. */
237
+ export function shortcutSequence(action: Pick<CommandAction, 'shortcut'>): string | null {
238
+ return action.shortcut && action.shortcut.length > 0 ? action.shortcut.map((k) => k.toLowerCase()).join(' ') : null;
239
+ }
240
+
241
+ /**
242
+ * Whether `seq` could not be bound beside `bound`: the same keys, or a
243
+ * sequence one of them begins (a bare `g` would swallow `g k`, and `c x`
244
+ * would never be reached past `c`).
245
+ */
246
+ function shortcutCollides(seq: string, bound: Iterable<string>): boolean {
247
+ for (const b of bound) {
248
+ if (b === seq || b.startsWith(`${seq} `) || seq.startsWith(`${b} `)) return true;
249
+ }
250
+ return false;
251
+ }
252
+
253
+ /**
254
+ * Core's commands, then the registry's — a distribution adds to the list
255
+ * rather than reordering it. A registry command reusing an id core already
256
+ * has is dropped (and said so in the console): two rows with one id would
257
+ * share a DOM id, and the suggestions could not tell them apart. A registry
258
+ * command whose keys collide with ones already bound keeps its row and loses
259
+ * its shortcut, hint included, so the menu never shows a key that does
260
+ * nothing.
261
+ */
262
+ export function mergeCommandActions(
263
+ core: readonly CommandAction[],
264
+ extra: readonly CommandAction[],
265
+ ): CommandAction[] {
266
+ const ids = new Set(core.map((a) => a.id));
267
+ const bound = new Set(core.map(shortcutSequence).filter((s): s is string => s !== null));
268
+ const merged = [...core];
269
+ for (const action of extra) {
270
+ if (ids.has(action.id)) {
271
+ console.error(`[commands] dropping a registry command with a duplicate id: ${action.id}`);
272
+ continue;
273
+ }
274
+ ids.add(action.id);
275
+ const seq = shortcutSequence(action);
276
+ // Only what `useCommandShortcuts` can bind is kept: one key, or two in
277
+ // sequence. A longer one would be drawn as "x then y then z" and never
278
+ // fire.
279
+ if (seq !== null && seq.split(' ').length > 2) {
280
+ console.error(`[commands] the shortcut "${seq}" of ${action.id} is longer than two keys; it is not bound`);
281
+ merged.push({ ...action, shortcut: undefined });
282
+ continue;
283
+ }
284
+ if (seq !== null && shortcutCollides(seq, bound)) {
285
+ console.error(`[commands] the shortcut "${seq}" of ${action.id} collides with keys already bound; it is not bound`);
286
+ merged.push({ ...action, shortcut: undefined });
287
+ continue;
288
+ }
289
+ if (seq !== null) bound.add(seq);
290
+ merged.push(action);
291
+ }
292
+ return merged;
293
+ }
294
+
295
+ /**
296
+ * The commands to offer now. A `visible` that throws costs its own command,
297
+ * never the menu: a registry contribution with a bug must not take the
298
+ * search box down with it.
299
+ */
300
+ export function visibleActions(actions: readonly CommandAction[], ctx: CommandContext): CommandAction[] {
301
+ return actions.filter((action) => {
302
+ try {
303
+ return action.visible(ctx);
304
+ } catch (err) {
305
+ console.error(`[commands] visible() threw for ${action.id}:`, err);
306
+ return false;
307
+ }
308
+ });
309
+ }
310
+
311
+ /**
312
+ * What an empty menu offers before anything is typed: a handful of the
313
+ * commonest verbs, not the whole list — New page, Invite people (for an
314
+ * admin), Connect your agent while that onboarding is open, and a way to the
315
+ * other app. Drawn from `visible`, so nothing is suggested that is not
316
+ * offered.
317
+ */
318
+ export function suggestedActions(visible: readonly CommandAction[], ctx: CommandContext): CommandAction[] {
319
+ const byId = new Map(visible.map((a) => [a.id, a]));
320
+ const ids = ['new-page', 'invite'];
321
+ if (ctx.onboardingPending) ids.push('connect-agent');
322
+ const otherApp = visible.find((a) => a.id.startsWith('go-to:') && a.id !== goToAppActionId(ctx.activeAppId ?? ''));
323
+ if (otherApp) ids.push(otherApp.id);
324
+ return ids.map((id) => byId.get(id)).filter((a): a is CommandAction => a !== undefined);
325
+ }
326
+
327
+ /** What a query is matched against: the label first (the tie-breaker), then the keywords. */
328
+ export function actionNames(action: CommandAction): string[] {
329
+ return [action.label, ...(action.keywords ?? [])];
330
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The command menu's two public facts, for anything outside the toolbar that
3
+ * talks about it or opens it — the Get set up list does both: which keys open
4
+ * it on this platform, and a way to open it from a button.
5
+ *
6
+ * A plain module rather than a context: the palette lives in the toolbar and
7
+ * the people asking for it (the setup column) sit beside it, not under it, so
8
+ * a provider would have to wrap the whole shell to connect two leaves.
9
+ */
10
+
11
+ /**
12
+ * The shortcut belongs to ⌘ on Apple platforms and to Ctrl everywhere else —
13
+ * and ONLY to that one. Ctrl+K on a Mac is the text fields' "delete to end of
14
+ * line", which nobody pressing it there means as "search".
15
+ */
16
+ const APPLE = typeof navigator !== 'undefined' && /Mac|iPhone|iPad|iPod/.test(navigator.userAgent);
17
+
18
+ /** The keys as drawn: `⌘K` on Apple platforms, `Ctrl K` elsewhere. */
19
+ export const COMMAND_MENU_SHORTCUT_LABEL = APPLE ? '⌘K' : 'Ctrl K';
20
+
21
+ /** The keys as `aria-keyshortcuts` spells them. */
22
+ export const COMMAND_MENU_SHORTCUT_ARIA = APPLE ? 'Meta+K' : 'Control+K';
23
+
24
+ /** Whether a keydown is this platform's command-menu shortcut. */
25
+ export function isCommandMenuShortcut(e: KeyboardEvent): boolean {
26
+ if (e.altKey || e.shiftKey || e.key.toLowerCase() !== 'k') return false;
27
+ return APPLE ? e.metaKey && !e.ctrlKey : e.ctrlKey && !e.metaKey;
28
+ }
29
+
30
+ const openRequests = new Set<() => void>();
31
+
32
+ /**
33
+ * Open the command menu, as Ctrl/⌘K would. A no-op where no palette is
34
+ * mounted (a test, a host without the toolbar).
35
+ */
36
+ export function openCommandMenu(): void {
37
+ openRequests.forEach((listener) => listener());
38
+ }
39
+
40
+ /** The palette's half of {@link openCommandMenu}; returns the unsubscribe. */
41
+ export function onCommandMenuRequest(listener: () => void): () => void {
42
+ openRequests.add(listener);
43
+ return () => openRequests.delete(listener);
44
+ }
@@ -0,0 +1,71 @@
1
+ import { useMemo } from 'react';
2
+ import { useNavigate } from 'react-router-dom';
3
+ import { useActiveAppId, useAppRegistry } from '../../../core/registry';
4
+ import { useAdmin } from '../../admin/state/admin.context';
5
+ import { useAuth } from '../../auth/state/auth.context';
6
+ import { useMenuSections } from '../../settings/settings-nav-items';
7
+ import { useInviteDialog } from '../../onboarding/state/invite-dialog.context';
8
+ import { useOnboarding } from '../../onboarding/state/onboarding';
9
+ import { useWorkspace } from '../../workspace/state/workspace.context';
10
+ import { useEditablePage } from '../../workspace/state/editable-page';
11
+ import { useFileNav } from '../../workspace/routing/kb-routes';
12
+ import { useCreatePage } from '../../workspace/hooks/useCreatePage';
13
+ import {
14
+ coreCommandActions,
15
+ mergeCommandActions,
16
+ visibleActions,
17
+ type CommandAction,
18
+ type CommandContext,
19
+ } from './actions';
20
+
21
+ /** The one {@link CommandContext}, read off the app's own hooks. */
22
+ export function useCommandContext(): CommandContext {
23
+ const navigate = useNavigate();
24
+ const { user } = useAuth();
25
+ const { isAdmin } = useAdmin();
26
+ const activeAppId = useActiveAppId();
27
+ const { openFilePath } = useWorkspace();
28
+ const editablePage = useEditablePage();
29
+ const { openWorkspacePath } = useFileNav();
30
+ const invite = useInviteDialog();
31
+ const { knowledgeRoot, createPage, pageFolder } = useCreatePage();
32
+ const { showPill } = useOnboarding();
33
+ return useMemo(
34
+ () => ({
35
+ navigate: (to: string) => navigate(to),
36
+ user,
37
+ isAdmin,
38
+ activeAppId,
39
+ openFilePath,
40
+ editablePage,
41
+ openWorkspacePath,
42
+ invite,
43
+ // Not offered to someone who may write no Knowledge folder, nor before
44
+ // that is known; the C shortcut only runs commands that are offered.
45
+ createPage: knowledgeRoot && pageFolder ? createPage : null,
46
+ onboardingPending: showPill,
47
+ }),
48
+ [navigate, user, isAdmin, activeAppId, openFilePath, editablePage, openWorkspacePath, invite, knowledgeRoot, pageFolder, createPage, showPill],
49
+ );
50
+ }
51
+
52
+ /**
53
+ * The commands to offer right now — core's, then the registry's — and the
54
+ * context to run them with.
55
+ */
56
+ export function useCommandActions(): { actions: CommandAction[]; ctx: CommandContext } {
57
+ const registry = useAppRegistry();
58
+ const settings = useMenuSections();
59
+ const ctx = useCommandContext();
60
+ const all = useMemo(
61
+ () => mergeCommandActions(coreCommandActions({ apps: registry.apps, settings }), registry.commandActions ?? []),
62
+ [registry, settings],
63
+ );
64
+ // Asked on every render rather than memoized on `ctx`: a settings row's
65
+ // `isShown` can follow state the menu does not own (a preference in
66
+ // storage), and the profile menu asks it each time its panel renders.
67
+ // Opening the palette is a render, so a row a command just switched off is
68
+ // gone by the next open.
69
+ const actions = visibleActions(all, ctx);
70
+ return { actions, ctx };
71
+ }