Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix backlinks (#2636)
shagun-singh-inkeep889878903585
diff --git a/.changeset/wiki-link-suggestion-collision.md b/.changeset/wiki-link-suggestion-collision.mdnew file mode 100644index 000000000..f16e4d5dc--- /dev/null+++ b/.changeset/wiki-link-suggestion-collision.md@@ -0,0 +1,5 @@+---+"@inkeep/open-knowledge": patch+---++Fix the `[[` wiki-link suggestion box silently freezing when a folder and a note share a name. The search index keyed every entry as `page:<name>`, so a folder `wiki` and a note `wiki.md` collided on `page:wiki`; the index rejected the duplicate key and the uncaught error killed the typeahead, leaving the dropdown stuck on the same initial results no matter what you typed. Entries are now keyed by their true kind (`folder:`, `page:`, `file:`), folders and assets are explicitly included in the corpus, and results map back to notes by the full kind-qualified key so a folder can't stand in for a same-named note.diff --git a/packages/app/src/editor/extensions/wiki-link-suggestion.test.ts b/packages/app/src/editor/extensions/wiki-link-suggestion.test.tsindex ad34e7e9e..e2c1516f9 100644--- a/packages/app/src/editor/extensions/wiki-link-suggestion.test.ts+++ b/packages/app/src/editor/extensions/wiki-link-suggestion.test.ts@@ -576,6 +576,44 @@ describe('context-aware ranking', () => {});});+describe('page/folder docName collision', () => {+ // A folder and a page can legally share a docName (`wiki/` next to+ // `wiki.md`). Kind-collapsed corpus ids used to make the second insert throw+ // inside the typed-query path, which @tiptap/suggestion swallows — freezing+ // the dropdown on the empty-query list for every keystroke.+ const collisionCorpus: PageItem[] = [+ { kind: 'page', docName: '_tbd/2026-07-03-alpha', title: 'Alpha note' },+ { kind: 'page', docName: '_tbd/2026-07-03-beta', title: 'Beta note' },+ { kind: 'page', docName: 'conferences/conference-schedule', title: 'Conference Schedule' },+ { kind: 'page', docName: 'wiki', title: 'Wiki' },+ { kind: 'folder', docName: 'wiki', title: 'wiki' },+ ];++ test('typed query filters instead of throwing', () => {+ expect(filterPages(collisionCorpus, 'confe').map((p) => p.docName)).toEqual([+ 'conferences/conference-schedule',+ ]);+ });++ test('query matching the colliding name returns page and folder as distinct items', () => {+ const results = filterPages(collisionCorpus, 'wiki');+ expect(results.map((p) => ({ kind: p.kind, docName: p.docName }))).toEqual([+ { kind: 'page', docName: 'wiki' },+ { kind: 'folder', docName: 'wiki' },+ ]);+ });++ test('folders and assets stay suggestible under the explicit scopes', () => {+ const corpus: PageItem[] = [+ { kind: 'page', docName: 'notes', title: 'Notes' },+ { kind: 'folder', docName: 'projects', title: 'projects' },+ { kind: 'asset', docName: '/img/diagram.png', title: 'diagram.png' },+ ];+ expect(filterPages(corpus, 'projects').map((p) => p.docName)).toEqual(['projects']);+ expect(filterPages(corpus, 'diagram').map((p) => p.docName)).toEqual(['/img/diagram.png']);+ });+});+describe('loadWikiLinkContext', () => {const realFetch = globalThis.fetch;diff --git a/packages/app/src/editor/extensions/wiki-link-suggestion.ts b/packages/app/src/editor/extensions/wiki-link-suggestion.tsindex 99a91d756..72619f74f 100644--- a/packages/app/src/editor/extensions/wiki-link-suggestion.ts+++ b/packages/app/src/editor/extensions/wiki-link-suggestion.ts@@ -11,6 +11,7 @@ import {ProblemDetailsSchema,searchWorkspaceCorpus,type WorkspaceSearchCorpus,+ type WorkspaceSearchKind,} from '@inkeep/open-knowledge-core';import type { Editor } from '@tiptap/core';import type { ResolvedPos } from '@tiptap/pm/model';@@ -133,7 +134,12 @@ export function autocompleteBoost(docName: string, context: WikiLinkContext): nuinterface SuggestionSearchCorpus<T> {fingerprint: string;- byPath: ReadonlyMap<string, T>;+ /**+ * Keyed by the corpus document id (`${kind}:${path}`), NOT by bare docName —+ * a folder and a page can legally share a docName (`wiki/` next to `wiki.md`),+ * so a docName-keyed map would let one silently shadow the other.+ */+ byId: ReadonlyMap<string, T>;corpus: WorkspaceSearchCorpus;}@@ -174,8 +180,13 @@ export function filterPages(// base score + context boost and trim. With an empty context every boost is 0,// so the comparator matches core's own (score desc, path asc) and the trimmed// top-N is identical to requesting `limit: MAX_ITEMS` directly.+ //+ // Scopes are explicit: the corpus classifies folders/assets under their real+ // kinds, and `autocomplete` intent alone would scope to pages only and drop+ // them from the picker.return searchWorkspaceCorpus(searchCorpus.corpus, query, {intent: 'autocomplete',+ scopes: ['page', 'folder', 'file'],limit: MAX_WORKSPACE_SEARCH_LIMIT,}).map((result) => ({@@ -187,10 +198,24 @@ export function filterPages(b.adjusted - a.adjusted || a.result.document.path.localeCompare(b.result.document.path),).slice(0, MAX_ITEMS)- .map((entry) => searchCorpus.byPath.get(entry.result.document.path))+ .map((entry) => searchCorpus.byId.get(entry.result.document.id)).filter((page) => !!page);}+/**+ * Corpus kind for a picker item. Folders and assets must NOT be indexed as+ * `page`: the corpus document id is `${kind}:${path}`, and a folder can share a+ * docName with a page (`wiki/` next to `wiki.md`), so kind-collapsing produced+ * duplicate ids — Orama throws on the duplicate insert, the suggestion plugin+ * swallows the rejection, and the dropdown silently froze on the empty-query+ * list for every typed query. Mirrors the command palette's classification.+ */+function pageSearchKind(item: PageItem): WorkspaceSearchKind {+ if (item.kind === 'folder') return 'folder';+ if (item.kind === 'asset') return 'file';+ return 'page';+}+function getCachedPageSearchCorpus(pages: readonly PageItem[]): SuggestionSearchCorpus<PageItem> {const fingerprint = pages.map((page) => `${page.kind ?? 'page'}\u0000${page.docName}\u0000${page.title}`)@@ -198,11 +223,11 @@ function getCachedPageSearchCorpus(pages: readonly PageItem[]): SuggestionSearchif (cachedPageSearchCorpus?.fingerprint === fingerprint) return cachedPageSearchCorpus;cachedPageSearchCorpus = {fingerprint,- byPath: new Map(pages.map((page) => [page.docName, page])),+ byId: new Map(pages.map((page) => [`${pageSearchKind(page)}:${page.docName}`, page])),corpus: createWorkspaceSearchCorpus(pages.map((page) =>createWorkspaceSearchDocument({- kind: 'page',+ kind: pageSearchKind(page),path: page.docName,title: page.title,}),@@ -221,7 +246,7 @@ function getCachedHeadingSearchCorpus(if (cachedHeadingSearchCorpus?.fingerprint === fingerprint) return cachedHeadingSearchCorpus;cachedHeadingSearchCorpus = {fingerprint,- byPath: new Map(headings.map((heading) => [heading.slug, heading])),+ byId: new Map(headings.map((heading) => [`page:${heading.slug}`, heading])),corpus: createWorkspaceSearchCorpus(headings.map((heading) =>createWorkspaceSearchDocument({@@ -242,7 +267,7 @@ export function filterHeadings(headings: HeadingEntry[], anchorQuery: string): Hintent: 'autocomplete',limit: MAX_ITEMS,})- .map((result) => searchCorpus.byPath.get(result.document.path))+ .map((result) => searchCorpus.byId.get(result.document.id)).filter((heading) => !!heading);}