Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
Omnibar filename matching + per-kind result quota (PRD-7065 Phase 1) (#2005)
Andrew Mikofalvy74faf3725128
diff --git a/.changeset/omnibar-filename-and-kind-quota.md b/.changeset/omnibar-filename-and-kind-quota.mdnew file mode 100644index 000000000..51efe7b11--- /dev/null+++ b/.changeset/omnibar-filename-and-kind-quota.md@@ -0,0 +1,5 @@+---+"@inkeep/open-knowledge": patch+---++Improve Cmd+K/omnibar search findability. Markdown files are now matchable by their full displayed name including the extension (typing `STORY.md` finds the page named `STORY`, matching how non-markdown files and the file tree already work). And a query that matches many same-named folders or files (e.g. `evidence`, `index`) no longer fills the entire result list with one kind — folders and files are each capped (default 3) so content pages get the remaining slots; full-text search is uncapped.diff --git a/packages/core/src/search/workspace-search.filename-quota.test.ts b/packages/core/src/search/workspace-search.filename-quota.test.tsnew file mode 100644index 000000000..b2b138e55--- /dev/null+++ b/packages/core/src/search/workspace-search.filename-quota.test.ts@@ -0,0 +1,109 @@+import { describe, expect, test } from 'bun:test';+import {+ createWorkspaceSearchDocument,+ DEFAULT_FILE_RESULT_CAP,+ DEFAULT_FOLDER_RESULT_CAP,+ searchWorkspaceDocuments,+} from './workspace-search.ts';++describe('extension-tolerant filename matching', () => {+ const page = createWorkspaceSearchDocument({+ kind: 'page',+ path: 'stories/cloud-collaboration/STORY',+ title: 'Cloud & Collaborative Functionality — User Stories',+ content: 'real-time co-editing without leaving git',+ modifiedTs: 10,+ });+ const csv = createWorkspaceSearchDocument({+ kind: 'file',+ path: 'assets/data.csv',+ modifiedTs: 5,+ });+ const documents = [page, csv];++ test('STORY.md resolves to the page named STORY at the exact-name tier', () => {+ const results = searchWorkspaceDocuments(documents, 'STORY.md', { intent: 'omnibar' });+ const hit = results.find((r) => r.document.path === 'stories/cloud-collaboration/STORY');+ expect(hit).toBeDefined();+ expect(hit?.signals.lexical).toBe(700);+ });++ test('STORY.md and STORY rank the page identically (extension parity)', () => {+ const withExt = searchWorkspaceDocuments(documents, 'STORY.md', { intent: 'omnibar' });+ const withoutExt = searchWorkspaceDocuments(documents, 'STORY', { intent: 'omnibar' });+ expect(withExt[0]?.document.path).toBe('stories/cloud-collaboration/STORY');+ expect(withoutExt[0]?.document.path).toBe('stories/cloud-collaboration/STORY');+ expect(withExt[0]?.signals.lexical).toBe(withoutExt[0]?.signals.lexical);+ });++ test('non-markdown files are findable by their full name', () => {+ const csvQuery = searchWorkspaceDocuments(documents, 'data.csv', { intent: 'omnibar' });+ expect(csvQuery.some((r) => r.document.path === 'assets/data.csv')).toBe(true);+ });++ test('only .md/.mdx is stripped — a .csv suffix is not treated as the page name', () => {+ const results = searchWorkspaceDocuments(documents, 'STORY.csv', { intent: 'omnibar' });+ const hit = results.find((r) => r.document.path === 'stories/cloud-collaboration/STORY');+ expect(hit?.signals.lexical ?? 0).not.toBe(700);+ });++ test('a bare ".md" query does not match every page', () => {+ const results = searchWorkspaceDocuments(documents, '.md', { intent: 'omnibar' });+ expect(results.some((r) => r.document.path === 'stories/cloud-collaboration/STORY')).toBe(+ false,+ );+ });+});++describe('per-kind result quota (content-first composition)', () => {+ const folders = ['a', 'b', 'c', 'd', 'e'].map((p) =>+ createWorkspaceSearchDocument({ kind: 'folder', path: `${p}/reports`, modifiedTs: 0 }),+ );+ const pages = [1, 2, 3, 4].map((n) =>+ createWorkspaceSearchDocument({+ kind: 'page',+ path: `team${n}/reports-notes`,+ title: `Reports Notes ${n}`,+ content: 'quarterly summary',+ modifiedTs: n,+ }),+ );+ const folderDocs = [...folders, ...pages];++ test('omnibar caps folders and lets content fill the rest', () => {+ const results = searchWorkspaceDocuments(folderDocs, 'reports', { intent: 'omnibar' });+ const folderCount = results.filter((r) => r.document.kind === 'folder').length;+ const pageCount = results.filter((r) => r.document.kind === 'page').length;+ expect(folderCount).toBe(DEFAULT_FOLDER_RESULT_CAP);+ expect(pageCount).toBe(4); // every content page survives — only folders are capped+ });++ const fileDocs = ['a', 'b', 'c', 'd', 'e'].map((p) =>+ createWorkspaceSearchDocument({ kind: 'file', path: `${p}/data.csv`, modifiedTs: 0 }),+ );++ test('omnibar caps files', () => {+ const results = searchWorkspaceDocuments(fileDocs, 'data.csv', { intent: 'omnibar' });+ expect(results.filter((r) => r.document.kind === 'file').length).toBe(DEFAULT_FILE_RESULT_CAP);+ });++ test('full_text is NOT capped (content search wants every match)', () => {+ const results = searchWorkspaceDocuments(fileDocs, 'data.csv', { intent: 'full_text' });+ expect(results.filter((r) => r.document.kind === 'file').length).toBe(5);+ });++ test('the cap keeps the highest-ranked folder of its kind', () => {+ const mixed = [+ createWorkspaceSearchDocument({ kind: 'folder', path: 'x/reports', modifiedTs: 0 }),+ createWorkspaceSearchDocument({ kind: 'folder', path: 'y/reports-archive', modifiedTs: 0 }),+ createWorkspaceSearchDocument({ kind: 'folder', path: 'z/reports-old', modifiedTs: 0 }),+ createWorkspaceSearchDocument({ kind: 'folder', path: 'w/reports-draft', modifiedTs: 0 }),+ ];+ const results = searchWorkspaceDocuments(mixed, 'reports', { intent: 'omnibar' });+ const folderPaths = results+ .filter((r) => r.document.kind === 'folder')+ .map((r) => r.document.path);+ expect(folderPaths.length).toBe(DEFAULT_FOLDER_RESULT_CAP);+ expect(folderPaths).toContain('x/reports'); // the exact-name folder is retained+ });+});diff --git a/packages/core/src/search/workspace-search.ts b/packages/core/src/search/workspace-search.tsindex 46bed3929..46a5a2524 100644--- a/packages/core/src/search/workspace-search.ts+++ b/packages/core/src/search/workspace-search.ts@@ -52,6 +52,9 @@ export const DEFAULT_RRF_K = 60;export const DEFAULT_VECTOR_CANDIDATE_LIMIT = 64;export const DEFAULT_VECTOR_SIMILARITY_FLOOR = 0;+export const DEFAULT_FOLDER_RESULT_CAP = 3;+export const DEFAULT_FILE_RESULT_CAP = 3;+const WORKSPACE_SEARCH_SCHEMA = {id: 'string',kind: 'enum',@@ -77,6 +80,14 @@ function normalize(value: string): string {return value.trim().toLowerCase();}+const DOC_EXTENSION_RE = /\.(?:md|mdx)$/;++function queryForKind(normalizedQuery: string, kind: WorkspaceSearchKind): string {+ if (kind !== 'page') return normalizedQuery;+ const stripped = normalizedQuery.replace(DOC_EXTENSION_RE, '');+ return stripped.length > 0 ? stripped : normalizedQuery;+}+export function workspaceSearchBasename(path: string): string {const segments = path.split('/').filter(Boolean);return segments[segments.length - 1] ?? path;@@ -160,18 +171,19 @@ function scopeAllows(document: WorkspaceSearchDocument, scopes: ReadonlySet<Workfunction lexicalBracket(document: WorkspaceSearchDocument, query: string): number {const normalizedQuery = normalize(query);if (!normalizedQuery) return 0;+ const q = queryForKind(normalizedQuery, document.kind);const title = normalize(document.title);const name = normalize(document.name);const path = normalize(document.path);const pathSegments = path.split('/');- if (title === normalizedQuery || name === normalizedQuery) return 700;- if (path === normalizedQuery) return 650;- if (title.startsWith(normalizedQuery) || name.startsWith(normalizedQuery)) return 600;- if (pathSegments.some((segment) => segment.startsWith(normalizedQuery))) return 550;- if (title.includes(normalizedQuery) || name.includes(normalizedQuery)) return 500;- if (path.includes(normalizedQuery)) return 450;+ if (title === q || name === q) return 700;+ if (path === q) return 650;+ if (title.startsWith(q) || name.startsWith(q)) return 600;+ if (pathSegments.some((segment) => segment.startsWith(q))) return 550;+ if (title.includes(q) || name.includes(q)) return 500;+ if (path.includes(q)) return 450;return -1;}@@ -233,6 +245,29 @@ function toleranceFor(intent: WorkspaceSearchIntent, query: string): number {return intent === 'full_text' ? 1 : 0;}+function finalizeResults(+ ranked: readonly WorkspaceSearchResult[],+ intent: WorkspaceSearchIntent,+ limit: number,+): WorkspaceSearchResult[] {+ if (intent === 'full_text') return ranked.slice(0, limit);+ const selected: WorkspaceSearchResult[] = [];+ let folders = 0;+ let files = 0;+ for (const result of ranked) {+ if (result.document.kind === 'folder') {+ if (folders >= DEFAULT_FOLDER_RESULT_CAP) continue;+ folders += 1;+ } else if (result.document.kind === 'file') {+ if (files >= DEFAULT_FILE_RESULT_CAP) continue;+ files += 1;+ }+ selected.push(result);+ if (selected.length >= limit) break;+ }+ return selected;+}+export function searchWorkspaceDocuments(documents: readonly WorkspaceSearchDocument[],query: string,@@ -292,7 +327,7 @@ export function searchWorkspaceCorpus(}if (!options.semantic) {- return [...candidates.values()]+ const ranked = [...candidates.values()].map((document) => {const lexical = Math.max(0, lexicalScore(document, normalizedQuery));const fullText = fullTextScores.get(document.id) ?? 0;@@ -306,19 +341,22 @@ export function searchWorkspaceCorpus(.sort((a, b) => {if (a.score !== b.score) return b.score - a.score;return a.document.path.localeCompare(b.document.path);- })- .slice(0, limit);+ });+ return finalizeResults(ranked, intent, limit);}- return rankWithVector({- scopedDocuments,- candidates,- fullTextScores,- recency,- normalizedQuery,- semantic: options.semantic,+ return finalizeResults(+ rankWithVector({+ scopedDocuments,+ candidates,+ fullTextScores,+ recency,+ normalizedQuery,+ semantic: options.semantic,+ }),+ intent,limit,- });+ );}interface SemanticRow {@@ -346,10 +384,8 @@ function rankWithVector(args: {recency: ReadonlyMap<string, number>;normalizedQuery: string;semantic: WorkspaceSemanticInput;- limit: number;}): WorkspaceSearchResult[] {- const { scopedDocuments, candidates, fullTextScores, recency, normalizedQuery, semantic, limit } =- args;+ const { scopedDocuments, candidates, fullTextScores, recency, normalizedQuery, semantic } = args;const rrfK = semantic.rrfK ?? DEFAULT_RRF_K;const candidateLimit = semantic.candidateLimit ?? DEFAULT_VECTOR_CANDIDATE_LIMIT;const floor = semantic.similarityFloor ?? DEFAULT_VECTOR_SIMILARITY_FLOOR;@@ -425,6 +461,5 @@ function rankWithVector(args: {if (a.recency !== b.recency) return b.recency - a.recency;return a.document.path.localeCompare(b.document.path);})- .map(({ document, score, signals }) => ({ document, score, signals }))- .slice(0, limit);+ .map(({ document, score, signals }) => ({ document, score, signals }));}