Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(command): surface nested commands, show full hotkeys (#4108)
Seamusbae34a3b720c
diff --git a/js/app/packages/app/component/GlobalHotkeys.tsx b/js/app/packages/app/component/GlobalHotkeys.tsxindex 4bce09533c..627dffddf5 100644--- a/js/app/packages/app/component/GlobalHotkeys.tsx+++ b/js/app/packages/app/component/GlobalHotkeys.tsx@@ -1,10 +1,15 @@import { useAnalytics } from '@app/component/analytics-context';+import { useFeatureFlag } from '@app/lib/analytics/posthog';import { useSubscribeToKeypress } from '@app/signal/hotkeyRoot';import { useHandleFileUpload } from '@app/util/handleFileUpload';import { useLogout } from '@core/auth/logout';import { useOpenInstructionsMd } from '@core/component/AI/util/instructions';import { toast } from '@core/component/Toast/Toast';-import { LOCAL_ONLY } from '@core/constant/featureFlags';+import {+ ENABLE_SNIPPETS_FLAG,+ ENABLE_SNIPPETS_OVERRIDE,+ LOCAL_ONLY,+} from '@core/constant/featureFlags';import {type SettingsTab,useSettingsState,@@ -16,6 +21,7 @@ import {openFolderPicker,} from '@core/util/upload';import IconGear from '@icon/macro-gear.svg';+import Plus from '@phosphor/plus.svg';import LogoutIcon from '@phosphor/sign-out.svg';import Upload from '@phosphor/upload.svg';import UserIcon from '@phosphor/user.svg';@@ -31,7 +37,11 @@ import { themes } from '../../theme/signals/themeSignals';import { applyTheme } from '../../theme/utils/themeUtils';import { globalSplitManager } from '../signal/splitLayout';import { CommandState } from './command';-import { createMenuOpen, setCreateMenuOpen } from './Launcher';+import {+ CREATABLE_BLOCKS,+ createMenuOpen,+ setCreateMenuOpen,+} from './Launcher';import { openMacroMcpSetupModal } from './macro-mcp-setup-modal/MacroMcpSetupModal';import { useSplitLayout } from './split-layout/layout';@@ -97,6 +107,9 @@ export default function GlobalShortcuts() {const logout = useLogout();const handleFileUpload = useHandleFileUpload();+ const snippetsFlag = useFeatureFlag(ENABLE_SNIPPETS_FLAG, {+ enabledOverride: ENABLE_SNIPPETS_OVERRIDE,+ });const handleCommandMenu = () => {if (!CommandState.isOpen()) {@@ -105,7 +118,7 @@ export default function GlobalShortcuts() {CommandState.toggle();};- registerHotkey({+ const createScope = registerHotkey({hotkeyToken: TOKENS.global.createCommand,hotkey: 'c',scopeId: 'global',@@ -122,6 +135,28 @@ export default function GlobalShortcuts() {},displayPriority: 10,activateCommandScope: true,+ surfaceNestedCommands: true,+ keywords: ['new', 'make', 'add'],+ icon: Plus,+ });++ CREATABLE_BLOCKS.forEach((item) => {+ registerHotkey({+ hotkeyToken: item.hotkeyToken,+ hotkey: item.hotkey,+ scopeId: createScope.commandScopeId,+ description: item.description,+ condition: () =>+ (item.condition?.() ?? true) &&+ (item.blockName !== 'snippet' || snippetsFlag().enabled),+ keyDownHandler: item.keyDownHandler,+ icon: Plus,+ tags: item.tags,+ keywords: item.keywords,+ hide: () => item.blockName === 'snippet' && !snippetsFlag().enabled,+ runWithInputFocused: true,+ proxiedHotkey: true,+ });});registerHotkey({diff --git a/js/app/packages/app/component/Launcher.tsx b/js/app/packages/app/component/Launcher.tsxindex 13df71cfcb..07e5bca9f0 100644--- a/js/app/packages/app/component/Launcher.tsx+++ b/js/app/packages/app/component/Launcher.tsx@@ -281,6 +281,7 @@ export const CREATABLE_BLOCKS: CreatableBlock[] = [icon: WideFileMd,animatedIcon: AnimatedFileMdIcon,description: 'Create doc',+ keywords: ['new', 'make', 'add', 'document', 'note'],blockName: 'md',hotkeyToken: TOKENS.create.note,altHotkeyToken: TOKENS.create.noteNewSplit,@@ -295,6 +296,7 @@ export const CREATABLE_BLOCKS: CreatableBlock[] = [icon: WideTask,animatedIcon: AnimatedTaskIcon,description: 'Create task',+ keywords: ['new', 'make', 'add', 'todo'],blockName: 'task',hotkeyToken: TOKENS.create.task,altHotkeyToken: TOKENS.create.taskNewSplit,@@ -309,6 +311,7 @@ export const CREATABLE_BLOCKS: CreatableBlock[] = [icon: WideSnippet,animatedIcon: AnimatedSnippetIcon,description: 'Create snippet',+ keywords: ['new', 'make', 'add'],blockName: 'snippet',hotkeyToken: TOKENS.create.snippet,altHotkeyToken: TOKENS.create.snippetNewSplit,@@ -323,6 +326,7 @@ export const CREATABLE_BLOCKS: CreatableBlock[] = [icon: WideEmail,animatedIcon: AnimatedEmailIcon,description: 'Create email',+ keywords: ['new', 'make', 'add', 'compose'],blockName: 'email',hotkeyToken: TOKENS.create.email,altHotkeyToken: TOKENS.create.emailNewSplit,@@ -337,6 +341,7 @@ export const CREATABLE_BLOCKS: CreatableBlock[] = [icon: WideChat,animatedIcon: AnimatedChatIcon,description: 'Create message',+ keywords: ['new', 'make', 'add', 'channel'],blockName: 'channel',hotkeyToken: TOKENS.create.message,altHotkeyToken: TOKENS.create.messageNewSplit,@@ -351,6 +356,7 @@ export const CREATABLE_BLOCKS: CreatableBlock[] = [icon: WideStar,animatedIcon: AnimatedStarIcon,description: 'Create AI chat',+ keywords: ['new', 'make', 'add', 'agent'],blockName: 'chat',hotkeyToken: TOKENS.create.chat,altHotkeyToken: TOKENS.create.chatNewSplit,@@ -365,6 +371,7 @@ export const CREATABLE_BLOCKS: CreatableBlock[] = [icon: WideDiagram,animatedIcon: AnimatedDiagramIcon,description: 'Create canvas',+ keywords: ['new', 'make', 'add', 'diagram'],blockName: 'canvas',hotkeyToken: TOKENS.create.canvas,altHotkeyToken: TOKENS.create.canvasNewSplit,@@ -381,6 +388,7 @@ export const CREATABLE_BLOCKS: CreatableBlock[] = [icon: WideFolder,animatedIcon: AnimatedFolderIcon,description: 'Create folder',+ keywords: ['new', 'make', 'add', 'project'],blockName: 'project',hotkeyToken: TOKENS.create.project,altHotkeyToken: TOKENS.create.projectNewSplit,@@ -395,6 +403,7 @@ export const CREATABLE_BLOCKS: CreatableBlock[] = [icon: WideFileCode,animatedIcon: AnimatedFileCodeIcon,description: 'Create code file',+ keywords: ['new', 'make', 'add'],blockName: 'code',hotkeyToken: TOKENS.create.code,altHotkeyToken: TOKENS.create.codeNewSplit,diff --git a/js/app/packages/app/component/command/CommandItem.tsx b/js/app/packages/app/component/command/CommandItem.tsxindex 31132ce251..d7697f94f5 100644--- a/js/app/packages/app/component/command/CommandItem.tsx+++ b/js/app/packages/app/component/command/CommandItem.tsx@@ -107,8 +107,15 @@ function CommandDisplay(props: { item: CommandMenuItem }) {return (<div class="flex items-center gap-2 flex-1 min-w-0"><div class="size-5 flex items-center justify-center text-ink-muted shrink-0">- <Show when={command()?.icon} fallback={<Terminal class="size-4" />}>- {(icon) => <Dynamic component={icon()} class="size-4" />}+ <Show+ when={command()?.commandPaletteIcon}+ fallback={+ <Show when={command()?.icon} fallback={<Terminal class="size-4" />}>+ {(icon) => <Dynamic component={icon()} class="size-4" />}+ </Show>+ }+ >+ {(Icon) => <Dynamic component={Icon()} class="size-4" />}</Show></div><Showdiff --git a/js/app/packages/app/component/command/CommandMenu.tsx b/js/app/packages/app/component/command/CommandMenu.tsxindex 062651e237..7fa56355da 100644--- a/js/app/packages/app/component/command/CommandMenu.tsx+++ b/js/app/packages/app/component/command/CommandMenu.tsx@@ -7,6 +7,11 @@ import { globalSplitManager } from '@app/signal/splitLayout';import { TabsInset } from '@core/component/TabsInset';import { itemToBlockName } from '@core/constant/allBlocks';import { getActiveCommandsFromScope } from '@core/hotkey/getCommands';+import {+ hotkeyScopeTree,+ setActiveScope,+ setPressedKeys,+} from '@core/hotkey/state';import type { RegisterHotkeyReturn } from '@core/hotkey/types';import { runCommand } from '@core/hotkey/utils';import { debouncedDependent } from '@core/util/debounce';@@ -200,6 +205,15 @@ export function CommandMenuInner(props: {// Check if this is a multi-stage commandif (command.activateCommandScopeId) {+ const commandScope = hotkeyScopeTree.get(+ command.activateCommandScopeId+ );+ if (commandScope) {+ commandScope.parentScopeId = hotkeyScope;+ setPressedKeys(new Set<string>());+ setActiveScope(commandScope.scopeId);+ }+// Get commands from the nested scopeconst nestedCommands = getActiveCommandsFromScope(command.activateCommandScopeId,@@ -217,6 +231,9 @@ export function CommandMenuInner(props: {}// Regular command - close and run+ if (CommandState.commandScopeCommands().length > 0) {+ setActiveScope(hotkeyScope);+ }CommandState.close();CommandState.setQuery('');runCommand(command);@@ -383,6 +400,7 @@ export function CommandMenuInner(props: {if (CommandState.commandScopeCommands().length > 0) {CommandState.clearCommandScopeCommands();CommandState.setSelectedIndex(0);+ setActiveScope(hotkeyScope);return true;}// Entity action mode and normal mode both close the menu@@ -407,6 +425,7 @@ export function CommandMenuInner(props: {if (CommandState.commandScopeCommands().length > 0) {CommandState.clearCommandScopeCommands();CommandState.setSelectedIndex(0);+ setActiveScope(hotkeyScope);return true;}// Entity action mode doesn't have "back" - just close with escapediff --git a/js/app/packages/app/component/command/useCommandItems.ts b/js/app/packages/app/component/command/useCommandItems.tsindex a04bbf3ab0..d7a8a93f2e 100644--- a/js/app/packages/app/component/command/useCommandItems.ts+++ b/js/app/packages/app/component/command/useCommandItems.ts@@ -11,7 +11,7 @@ import {type CommandWithInfo,getActiveCommandsFromScope,} from '@core/hotkey/getCommands';-import { activeScope } from '@core/hotkey/state';+import { activeScope, hotkeyScopeTree } from '@core/hotkey/state';import type { HotkeyCommand } from '@core/hotkey/types';import {createFreshSearch,@@ -164,6 +164,7 @@ function commandsToItems(? command.description(): command.description;const tags = command.tags?.join(' ') ?? '';+ const keywords = command.keywords?.join(' ') ?? '';const id = `command-${description.replaceAll(' ', '-')}`;const lastUsedAt = getCommandLastUsedAt(id);@@ -171,7 +172,7 @@ function commandsToItems(id,kind: 'command',bucket: 'command',- searchText: [tags, description].filter(Boolean).join(' '),+ searchText: [tags, keywords, description].filter(Boolean).join(' '),sortTimestamp: lastUsedAt?.getTime() ?? 0,timestamps: { viewedAt: lastUsedAt, updatedAt: lastUsedAt },data: command,@@ -183,6 +184,50 @@ function commandsToItems(return items.sort((a, b) => b.sortTimestamp - a.sortTimestamp);}+function commandDisplayStep(+ command: CommandWithInfo+): DisplayHotkeyStep | null {+ if (command.hotkeyToken) return { token: command.hotkeyToken };+ const hotkey = command.hotkeys?.[0];+ return hotkey ? { shortcut: hotkey } : null;+}++function nestedCommandScopeDisplaySequence(command: CommandWithInfo) {+ const scope = hotkeyScopeTree.get(command.scopeId);+ const activationKey =+ scope?.type === 'command' ? scope.activationKeys?.[0] : undefined;+ const childStep = commandDisplayStep(command);++ if (!activationKey || !childStep) return undefined;++ return [{ shortcut: activationKey }, childStep];+}++function getSurfacedNestedCommands(commands: CommandWithInfo[]) {+ return commands.flatMap((command) => {+ if (!command.surfaceNestedCommands || !command.activateCommandScopeId) {+ return [];+ }++ const parentStep = commandDisplayStep(command);+ if (!parentStep) return [];++ return getActiveCommandsFromScope(command.activateCommandScopeId, {+ sortByScopeLevel: false,+ hideShadowedCommands: false,+ hideCommandsWithoutHotkeys: false,+ limitToCurrentScope: true,+ ignoreInputFocused: true,+ }).map((nestedCommand) => ({+ command: nestedCommand,+ displayHotkeySequence: [+ parentStep,+ commandDisplayStep(nestedCommand),+ ].filter((step): step is DisplayHotkeyStep => step !== null),+ }));+ });+}+/*** Convert active hotkey commands to QuickAccessItem format.*@@ -212,7 +257,9 @@ function useCommandsList(): () => CommandItem[] {// If we're in a command scope (multi-stage command), show those commands insteadconst scopeCommands = CommandState.commandScopeCommands();if (scopeCommands.length > 0) {- return commandsToItems(scopeCommands);+ return commandsToItems(scopeCommands, {+ displayHotkeySequence: nestedCommandScopeDisplaySequence,+ });}// If in entity action mode, filter to only show selection modification commands@@ -225,8 +272,25 @@ function useCommandsList(): () => CommandItem[] {// Include sidebar go-to commands in the main command menu with their// leader-key sequence rendered as a display-only shortcut.+ const surfacedNestedCommands = getSurfacedNestedCommands(capturedCommands);+ const surfacedHotkeySequences = new Map(+ surfacedNestedCommands.map((item) => [+ item.command,+ item.displayHotkeySequence,+ ])+ );+return [- ...commandsToItems(capturedCommands),+ ...commandsToItems(+ [+ ...capturedCommands,+ ...surfacedNestedCommands.map((item) => item.command),+ ],+ {+ displayHotkeySequence: (command) =>+ surfacedHotkeySequences.get(command),+ }+ ),...commandsToItems(goToCommands, {displayHotkeySequence: (command) => {const hotkey = command.hotkeys?.[0];diff --git a/js/app/packages/core/hotkey/hotkeys.ts b/js/app/packages/core/hotkey/hotkeys.tsindex 046de1b86d..3f4f5e2551 100644--- a/js/app/packages/core/hotkey/hotkeys.ts+++ b/js/app/packages/core/hotkey/hotkeys.ts@@ -124,8 +124,11 @@ export function registerHotkey(registrationType = 'override',hide,icon,+ commandPaletteIcon,displayComponent,tags,+ keywords,+ surfaceNestedCommands,shouldReturnFocusOnClose,proxiedHotkey,} = args;@@ -229,8 +232,11 @@ export function registerHotkey(handlerPriority: handlerPriority ?? HOTKEY_PRIORITY_DEFAULT,hide,icon,+ commandPaletteIcon,displayComponent,tags,+ keywords,+ surfaceNestedCommands,shouldReturnFocusOnClose,proxiedHotkey,};diff --git a/js/app/packages/core/hotkey/types.ts b/js/app/packages/core/hotkey/types.tsindex 56c3f712f2..e27ace3ca1 100644--- a/js/app/packages/core/hotkey/types.ts+++ b/js/app/packages/core/hotkey/types.ts@@ -44,10 +44,16 @@ export interface HotkeyCommand {hide?: boolean | (() => boolean);// Optional icon to display in the command palette.icon?: Component<JSX.SvgSVGAttributes<SVGSVGElement>>;+ // Optional custom icon component to display in the command palette.+ commandPaletteIcon?: Component<{ class?: string }>;// Optional component to display in the command palettedisplayComponent?: Component<any>;// Optional tags for categorizing in the command palette.tags?: string[];+ // Optional related search terms for the command palette.+ keywords?: string[];+ // If true, command palette search also includes one level of nested commands.+ surfaceNestedCommands?: boolean;/*** @description Should the focus be returned to the previously active element when this command is selected in the Konsole* @default true@@ -160,6 +166,10 @@ export interface HotkeyRegistrationOptions {* Optional icon to display in the command palette.*/icon?: Component<JSX.SvgSVGAttributes<SVGSVGElement>>;+ /**+ * Optional custom icon component to display in the command palette.+ */+ commandPaletteIcon?: Component<{ class?: string }>;/*** Optional component to display in command palette rather than description.*/@@ -168,6 +178,14 @@ export interface HotkeyRegistrationOptions {* Optional tags for categorizing in the command palette.*/tags?: string[];+ /**+ * Optional related search terms for the command palette.+ */+ keywords?: string[];+ /**+ * If true, command palette search also includes one level of nested commands.+ */+ surfaceNestedCommands?: boolean;/*** @description Should the focus be returned to the previously active element when this command is selected in the Konsolediff --git a/js/app/packages/core/hotkey/utils.ts b/js/app/packages/core/hotkey/utils.tsindex eb14ca29d6..b57d213c89 100644--- a/js/app/packages/core/hotkey/utils.ts+++ b/js/app/packages/core/hotkey/utils.ts@@ -622,7 +622,11 @@ export function registerScopeSignalHotkey(displayPriority: args.displayPriority,hide: args.hide,icon: args.icon,+ commandPaletteIcon: args.commandPaletteIcon,+ displayComponent: args.displayComponent,tags: args.tags,+ keywords: args.keywords,+ surfaceNestedCommands: args.surfaceNestedCommands,proxiedHotkey: args.proxiedHotkey,});