Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(ok): add the search terms users type for palette commands (PRD-7829) (#3720)
Andrew Mikofalvybf4331c5300f
diff --git a/.changeset/command-keyword-vocabulary.md b/.changeset/command-keyword-vocabulary.mdnew file mode 100644index 000000000..9d004af2a--- /dev/null+++ b/.changeset/command-keyword-vocabulary.md@@ -0,0 +1,9 @@+---+"@inkeep/open-knowledge": patch+---++Commands in the ⌘K palette are now findable by the words people actually search for, not only the words in their names. Commands are named for what they are, while users search for what they want to do, so "delete file" did not find Move to Trash, "open settings" did not find Settings, and "file bug" did not find Report a bug. Across a sweep of seventy realistic phrasings, thirty-one returned nothing at all.++Thirty-five search terms were added across twenty-one commands, nineteen distinct words in all, each one chosen because a measured phrasing failed without it. "new document" and "create note" now reach New file, "show in folder" reaches Reveal in Finder, "change branch" reaches Switch worktree, and "go back" reaches Back. Panels that change their own name as you use them — Show Terminal becomes Hide Terminal once it is open — now answer to both verbs, so "show agents" and "hide files" work whichever state the panel is in rather than only half the time.++No command was renamed, and nothing that matched before stopped matching. One consequence worth knowing: a few ordinary single words now reach a command that they did not before, and commands are listed above file results. In a project containing a file called note, typing "note" and pressing Enter opens the New file dialog rather than the document, where previously it opened the document. Arrow down to the file, or keep typing, to reach it.diff --git a/docs/content/features/editor.mdx b/docs/content/features/editor.mdxindex 70dda35e1..babcd8f61 100644--- a/docs/content/features/editor.mdx+++ b/docs/content/features/editor.mdx@@ -218,6 +218,8 @@ In the browser, `Cmd+P` is normally the print shortcut; OpenKnowledge takes it fRemove a recent project from the list by hovering its row and clicking the ×, or right-clicking for a **Remove from recent projects** menu — the same controls are on the sidebar's **Switch project** dropdown and in the Project Navigator. A recent whose folder was deleted or moved off disk isn't greyed out; it's cleared automatically the next time you open it, with a brief notice, instead of opening a broken window.+Every word you type has to appear somewhere in a command's name or its search terms, but the order does not matter and the words do not have to sit next to each other: `branch switch` and `switch branch` both reach **Switch worktree**. Commands also carry the words people search by rather than only the words in their names, so `delete file` reaches **Move to Trash** and `open settings` reaches **Settings**. Because commands are listed above file results, a query that matches both will highlight the command — arrow down to reach the file, or keep typing to narrow.+A `tag:` prefix searches by tag: `tag:` alone lists every tag, `tag:fr` narrows the tag list, and `tag:frontend` lists the docs tagged `#frontend` (including its hierarchy children). When semantic search is configured for the project, a **By meaning** pill switches the palette to meaning-based search — press Enter to run it; typing alone never fires a query.## Sidebars and window widthdiff --git a/packages/app/src/components/command-palette-vocabulary.test.ts b/packages/app/src/components/command-palette-vocabulary.test.tsnew file mode 100644index 000000000..b32754d9a--- /dev/null+++ b/packages/app/src/components/command-palette-vocabulary.test.ts@@ -0,0 +1,206 @@+/**+ * Vocabulary contract for the ⌘K command palette.+ *+ * The matcher decides whether a row is admitted once the user's words are in+ * its searchable text. This file covers the other half: whether the words a+ * user is likely to type are in that text at all. Commands are named by the+ * product ("Move to Trash", "Reveal in Finder") while users search by intent+ * ("delete file", "show in folder"), so the registry has to carry both.+ *+ * Each row below is one realistic phrasing paired with the command it should+ * reach. A failure here is not necessarily a bug in the matcher — it usually+ * means a command's keywords no longer carry a word people search by, which is+ * how a command becomes unreachable without anything looking broken.+ */+import { COMMAND_IDENTITIES, MENU_LABELS } from '@inkeep/open-knowledge-core';+import { describe, expect, test } from 'vitest';+import { matchesCommandQuery } from '@/components/command-palette-search';++/**+ * Every label a row can actually render. A state toggle shows "Show X" in one+ * state and "Hide X" in the other, and the agent panel additionally renders an+ * override label over a selection — so pinning a single `labelKey` would model a+ * string the user may never see, and would let a command look reachable while+ * being unreachable for half the app's runtime.+ */+const renderableLabels = (command: (typeof COMMAND_IDENTITIES)[number]): string[] => {+ const keys = [+ command.labelKey,+ command.stateToggle?.showKey,+ command.stateToggle?.hideKey,+ command.stateToggle?.overrideKey,+ command.placementToggle?.bottomKey,+ command.placementToggle?.rightKey,+ ].filter((key) => key !== undefined);+ const resolved = [...new Set(keys)].map((key) => MENU_LABELS[key]).filter((label) => !!label);+ return resolved.length > 0 ? resolved : [''];+};++const paletteRows = COMMAND_IDENTITIES.filter((command) => command.palette).map((command) => ({+ id: command.id,+ labels: renderableLabels(command),+ keywords: command.keywords,+}));++/** Rows admitted in EVERY state they can render in. */+const commandsMatching = (query: string): string[] =>+ paletteRows+ .filter((row) => row.labels.every((label) => matchesCommandQuery(label, query, row.keywords)))+ .map((row) => row.id);++/** Rows admitted in AT LEAST ONE state — the gap between this and the above is state-dependence. */+const commandsMatchingSomeState = (query: string): string[] =>+ paletteRows+ .filter((row) => row.labels.some((label) => matchesCommandQuery(label, query, row.keywords)))+ .map((row) => row.id);++/** Realistic phrasing -> the command the user is trying to reach. */+const INTENTS: ReadonlyArray<readonly [string, string]> = [+ // Bug reporting. "file bug" is the phrasing that went unmatched in the wild.+ ['file bug', 'report-bug'],+ ['report problem', 'report-bug'],+ ['report issue', 'report-bug'],+ ['past reports', 'bug-report-history'],++ // Destructive and file actions, named by product vs searched by intent.+ ['delete file', 'move-to-trash'],+ ['delete folder', 'move-to-trash'],+ ['remove file', 'move-to-trash'],+ ['rename file', 'rename'],+ ['copy file', 'duplicate'],+ ['duplicate folder', 'duplicate'],+ ['copy absolute path', 'copy-full-path'],+ ['copy relative path', 'copy-relative-path'],+ ['show in folder', 'reveal-in-finder'],+ ['open in finder', 'reveal-in-finder'],++ // Creation. Users say "document" and "note"; the command says "file".+ ['new document', 'new-file'],+ ['create note', 'new-file'],+ ['new note', 'new-file'],+ ['new directory', 'new-folder'],+ ['create directory', 'new-folder'],+ ['create from template', 'new-from-template'],+ ['create project', 'new-project'],+ ['create skill', 'new-skill'],+ ['open single file', 'open-file'],++ // Panels, named by their current state ("Show Terminal") but searched by verb.+ ['open terminal', 'toggle-terminal'],+ ['show console', 'toggle-terminal'],+ ['new terminal tab', 'new-terminal'],+ ['close terminal', 'kill-terminal'],+ ['stop terminal', 'kill-terminal'],+ ['move terminal right', 'move-terminal'],+ ['open chat', 'toggle-agent-panel'],+ ['open agents', 'toggle-agent-panel'],+ ['show ai', 'toggle-agent-panel'],+ ['document info', 'toggle-doc-panel'],+ ['show properties', 'toggle-doc-panel'],+ ['hide files', 'toggle-sidebar'],+ ['files panel', 'toggle-sidebar'],+ ['show graph', 'open-graph'],+ ['graph view', 'open-graph'],++ // Projects and worktrees.+ ['change project', 'switch-project'],+ ['open project', 'open-folder'],+ ['create worktree', 'new-worktree'],+ ['change branch', 'switch-worktree'],+ ['checkout branch', 'switch-worktree'],++ // Tree and file-visibility toggles.+ ['expand folders', 'expand-all-tree'],+ ['collapse folders', 'collapse-all-tree'],+ ['show dotfiles', 'toggle-show-hidden-files'],+ ['hidden files', 'toggle-show-hidden-files'],+ ['only markdown', 'toggle-show-only-markdown-files'],+ ['skills section', 'toggle-show-skills-section'],+ ['show ok folders', 'toggle-show-ok-folders'],+ ['show sidebar', 'toggle-sidebar'],+ ['hide document panel', 'toggle-doc-panel'],+ ['hide agents', 'toggle-agent-panel'],++ // App-level.+ ['open settings', 'settings'],+ ['open preferences', 'settings'],+ ['check version', 'check-for-updates'],+ ['update app', 'check-for-updates'],+ ['browse skills', 'open-skills'],+ ['open skills', 'open-skills'],+ ['install skill', 'open-skills'],+ ['view source', 'open-github'],+ ['open repo', 'open-github'],+ ['setup mcp', 'set-up-integrations'],+ ['configure claude', 'set-up-integrations'],+ ['install claude', 'install-claude-desktop'],+ ['give feedback', 'send-feedback'],+ ['send suggestion', 'send-feedback'],+ ['spell check', 'toggle-spell-check'],+ ['new window', 'open-in-new-window'],+ ['pop out', 'open-in-new-window'],+ ['starter pack', 'initialize-starter-pack'],+ ['close window', 'close-tab'],+ ['go back', 'navigate-back'],+ ['go forward', 'navigate-forward'],+ ['play game', 'open-blob-run'],+];++describe('command palette vocabulary', () => {+ test.each(INTENTS)('"%s" reaches %s', (query, expectedId) => {+ expect(commandsMatching(query)).toContain(expectedId);+ });++ test('no intent is answered in only some of a command’s render states', () => {+ // A row whose keywords carry only one polarity ("show" but not "hide")+ // answers the intent while one label is showing and goes silent when the+ // other is. That reads as a working command until the moment it is not, so+ // the two derivations have to agree.+ const stateDependent = INTENTS.filter(+ ([query, id]) =>+ commandsMatchingSomeState(query).includes(id) && !commandsMatching(query).includes(id),+ ).map(([query, id]) => `${query} -> ${id}`);++ expect(stateDependent).toEqual([]);+ });++ test('every intent resolves to a usefully short list', () => {+ // Pinned just above the measured ceiling rather than at a round number: as+ // written, every intent resolves to exactly one command, so a threshold with+ // slack in it would absorb a large ambiguity increase before complaining.+ const tooBroad = INTENTS.map(([query]) => [query, commandsMatching(query).length] as const)+ .filter(([, count]) => count > 2)+ .map(([query, count]) => `${query} -> ${count} rows`);++ expect(tooBroad).toEqual([]);+ });++ test('a broad single word stays inside a committed ceiling', () => {+ // The all-terms rule makes two-word intents inherently narrow, so the guard+ // above barely moves when broad tokens are added. Single words are where a+ // keyword sweep actually widens the palette, so the ceiling lives here.+ // Raising a number below means a sweep made a common word noisier; that+ // should be a deliberate edit, not a silent side effect.+ const ceilings: ReadonlyArray<readonly [string, number]> = [+ ['open', 13],+ ['file', 11],+ ['show', 12],+ ['new', 9],+ ['create', 7],+ ['folder', 10],+ ['view', 3],+ ['go', 3],+ ];+ const over = ceilings+ .map(([word, max]) => [word, commandsMatchingSomeState(word).length, max] as const)+ .filter(([, count, max]) => count > max)+ .map(([word, count, max]) => `${word} -> ${count} rows (ceiling ${max})`);++ expect(over).toEqual([]);+ });++ test('a query whose terms match nothing returns nothing', () => {+ expect(commandsMatching('zzzznomatch')).toEqual([]);+ expect(commandsMatching('bug zzzznomatch')).toEqual([]);+ });+});diff --git a/packages/core/src/commands/command-identity.ts b/packages/core/src/commands/command-identity.tsindex 74ffbf070..1e8db0ef3 100644--- a/packages/core/src/commands/command-identity.ts+++ b/packages/core/src/commands/command-identity.ts@@ -266,7 +266,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [id: 'navigate-back',menuActionId: 'navigate-back',labelKey: 'back',- keywords: ['previous history'],+ keywords: ['previous history', 'go'],shortcutId: 'navigate-back',shortcutDesktopOnly: true,availability: { host: 'desktop' },@@ -280,7 +280,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [id: 'navigate-forward',menuActionId: 'navigate-forward',labelKey: 'forward',- keywords: ['next history'],+ keywords: ['next history', 'go'],shortcutId: 'navigate-forward',shortcutDesktopOnly: true,availability: { host: 'desktop' },@@ -295,7 +295,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [id: 'new-file',menuActionId: 'new-doc',labelKey: 'newFile',- keywords: ['create file'],+ keywords: ['create file', 'document', 'note'],shortcutId: 'new-item',availability: {},palette: { group: 'commands', visibility: 'always' },@@ -305,7 +305,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [id: 'new-folder',menuActionId: 'new-folder',labelKey: 'newFolder',- keywords: ['create folder'],+ keywords: ['create folder', 'directory'],shortcutId: 'new-folder',shortcutDesktopOnly: true,availability: {},@@ -315,7 +315,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [{id: 'open-graph',labelKey: 'openGraph',- keywords: ['graph panel network'],+ keywords: ['graph panel network', 'show', 'view'],availability: { requiresActiveDoc: true },palette: { group: 'commands', visibility: 'always' },},@@ -404,7 +404,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [{id: 'open-skills',labelKey: 'openSkills',- keywords: ['skills marketplace explore import discover'],+ keywords: ['skills marketplace explore import discover', 'browse', 'install', 'open'],availability: { singleFileHidden: true },palette: { group: 'project', visibility: 'always' },menu: [],@@ -412,7 +412,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [{id: 'switch-project',labelKey: 'switchProject',- keywords: ['switch project navigator projects'],+ keywords: ['switch project navigator projects', 'change'],shortcutId: 'switch-project',availability: { host: 'desktop', singleFileHidden: true },palette: { group: 'project', visibility: 'always' },@@ -421,7 +421,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [{id: 'settings',labelKey: 'settings',- keywords: ['preferences config'],+ keywords: ['preferences config', 'open'],shortcutId: 'settings',availability: { singleFileHidden: true },palette: { group: 'project', visibility: 'always' },@@ -461,7 +461,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [id: 'report-bug',menuActionId: 'report-bug',labelKey: 'reportBug',- keywords: ['bug report issue feedback problem'],+ keywords: ['bug report issue feedback problem', 'file'],availability: { host: 'desktop' },palette: { group: 'project', visibility: 'always' },menu: [{ section: 'help-links', order: 1, ellipsis: true }],@@ -484,7 +484,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [id: 'send-feedback',menuActionId: 'send-feedback',labelKey: 'sendFeedback',- keywords: ['feedback', 'suggestion', 'idea', 'rate', 'survey', 'contact'],+ keywords: ['feedback', 'suggestion', 'idea', 'rate', 'survey', 'contact', 'give'],availability: {},palette: { group: 'project', visibility: 'always' },menu: [{ section: 'help-links', order: 2, ellipsis: true }],@@ -522,7 +522,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [id: 'move-to-trash',menuActionId: 'move-to-trash',labelKey: 'moveToTrash',- keywords: ['delete', 'trash', 'remove'],+ keywords: ['delete', 'trash', 'remove', 'file', 'folder'],shortcutId: 'file-tree-delete',availability: { host: 'desktop', requiresTargetKinds: ['doc', 'folder', 'asset'] },palette: { group: 'file', visibility: 'search-only' },@@ -532,7 +532,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [id: 'reveal-in-finder',menuActionId: 'reveal-in-finder',labelKey: 'revealInFinder',- keywords: ['finder', 'reveal', 'show', 'file'],+ keywords: ['finder', 'reveal', 'show', 'file', 'folder', 'open'],availability: { host: 'desktop', requiresTargetKinds: ['doc', 'folder', 'asset', 'project'] },palette: { group: 'file', visibility: 'search-only' },menu: [{ section: 'file-reveal', order: 0 }],@@ -578,7 +578,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [id: 'new-worktree',menuActionId: 'new-worktree',labelKey: 'newWorktree',- keywords: ['worktree', 'branch', 'new'],+ keywords: ['worktree', 'branch', 'new', 'create'],availability: { host: 'desktop' },palette: { group: 'file', visibility: 'search-only' },menu: [{ section: 'file-worktree', order: 0, ellipsis: true }],@@ -587,7 +587,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [id: 'switch-worktree',menuActionId: 'switch-worktree',labelKey: 'switchWorktree',- keywords: ['worktree', 'switch', 'branch'],+ keywords: ['worktree', 'switch', 'branch', 'change', 'checkout'],availability: { host: 'desktop' },palette: { group: 'file', visibility: 'search-only' },menu: [{ section: 'file-worktree', order: 1, ellipsis: true }],@@ -597,7 +597,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [id: 'toggle-sidebar',menuActionId: 'toggle-sidebar',labelKey: 'sidebarHide',- keywords: ['sidebar', 'files', 'panel', 'toggle'],+ keywords: ['sidebar', 'files', 'panel', 'toggle', 'show', 'hide', 'open'],shortcutId: 'toggle-files-sidebar',stateToggle: {showKey: 'sidebarShow',@@ -613,7 +613,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [id: 'toggle-doc-panel',menuActionId: 'toggle-doc-panel',labelKey: 'docPanelHide',- keywords: ['document', 'panel', 'info', 'toggle'],+ keywords: ['document', 'panel', 'info', 'toggle', 'properties', 'show', 'hide', 'open'],shortcutId: 'toggle-document-panel',stateToggle: {showKey: 'docPanelShow',@@ -644,6 +644,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [// phrasing. Both now match, and the view group renders above the terminal// group, so the reversible one is preselected.'close',+ 'open',],shortcutId: 'toggle-terminal-panel',stateToggle: {@@ -663,7 +664,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [id: 'toggle-agent-panel',menuActionId: 'toggle-agent-panel',labelKey: 'agentPanelShow',- keywords: ['agent', 'agents', 'chat', 'ai', 'ask', 'panel', 'toggle'],+ keywords: ['agent', 'agents', 'chat', 'ai', 'ask', 'panel', 'toggle', 'open', 'show', 'hide'],shortcutId: 'toggle-agent-panel',stateToggle: {showKey: 'agentPanelShow',@@ -771,7 +772,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [id: 'kill-terminal',menuActionId: 'kill-terminal',labelKey: 'killTerminal',- keywords: ['terminal', 'kill', 'close', 'session'],+ keywords: ['terminal', 'kill', 'close', 'session', 'stop'],availability: {host: 'desktop',requiresTerminalCapability: true,@@ -784,7 +785,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [{id: 'check-for-updates',labelKey: 'checkForUpdates',- keywords: ['update', 'upgrade', 'version', 'check'],+ keywords: ['update', 'upgrade', 'version', 'check', 'app'],availability: { host: 'desktop' },palette: { group: 'app', visibility: 'search-only' },menu: [@@ -811,7 +812,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [{id: 'open-github',labelKey: 'openOnGithub',- keywords: ['github', 'source', 'repository', 'code'],+ keywords: ['github', 'source', 'repository', 'code', 'view'],availability: {},palette: { group: 'app', visibility: 'search-only' },menu: [{ section: 'help-links', order: 0 }],