Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(open-knowledge): stop .ok folder rows opening a phantom <dir>.md (PRD-7633) (#3001)
Andrew Mikofalvye0dd07757778
diff --git a/.changeset/ok-folder-rows-open-real-folder.md b/.changeset/ok-folder-rows-open-real-folder.mdnew file mode 100644index 000000000..5cd91451d--- /dev/null+++ b/.changeset/ok-folder-rows-open-real-folder.md@@ -0,0 +1,7 @@+---+"@inkeep/open-knowledge": patch+---++With "Show .ok folders" turned on in the sidebar, clicking `.ok` or one of its subfolders such as `templates` no longer opens an error tab reading "This file could not be found" for a name like `templates.md`. Those rows are folders, but OpenKnowledge was reading the folder path as the name of a missing file, and the bad tab came back on its own every time the file list refreshed.++The `.ok` folder view still lists no documents of its own, because `.ok` contents stay out of the file index.diff --git a/packages/app/src/App.dom.test.tsx b/packages/app/src/App.dom.test.tsxindex ba43eb3ee..a2d96e98d 100644--- a/packages/app/src/App.dom.test.tsx+++ b/packages/app/src/App.dom.test.tsx@@ -413,6 +413,37 @@ describe('App runtime wiring', () => {expect(openTargetTransitionMock).not.toHaveBeenCalledWith(resolved);});+ test('hash navigation defers an unresolvable folder hash instead of opening a tab', async () => {+ // Re-resolution fires on every page-list change, so a folder hash the+ // resolver cannot place must leave the folder view the click already opened+ // untouched — opening or clearing here would stomp it.+ resolveNavigationTargetMock = vi.fn((docName: string) => ({+ kind: 'missing' as const,+ target: docName.replace(/\/+$/, ''),+ }));+ setHash('#/articles/.ok/');++ renderApp();++ await waitFor(() => {+ expect(resolveNavigationTargetMock).toHaveBeenCalledWith('articles/.ok/', expect.anything());+ });+ expect(openTargetTransitionMock).not.toHaveBeenCalled();+ expect(clearTargetMock).not.toHaveBeenCalled();+ });++ test('hash navigation still opens an unresolvable document hash in create mode', async () => {+ const missing: NavigationTarget = { kind: 'missing', target: 'articles/brand-new' };+ resolveNavigationTargetMock = vi.fn(() => missing);+ setHash('#/articles/brand-new');++ renderApp();++ await waitFor(() => {+ expect(openTargetTransitionMock).toHaveBeenCalledWith(missing);+ });+ });+test('hash navigation keeps an open extension-qualified markdown tab exact', async () => {openTabs = ['docs/guide.mdx'];resolveNavigationTargetMock = vi.fn(() => ({diff --git a/packages/app/src/components/navigation-targets.test.ts b/packages/app/src/components/navigation-targets.test.tsindex bd0fbe446..01644279c 100644--- a/packages/app/src/components/navigation-targets.test.ts+++ b/packages/app/src/components/navigation-targets.test.ts@@ -481,12 +481,103 @@ describe('okContentNavigationTarget (read-only .ok routing)', () => {expect(okContentNavigationTarget(target, { pages })?.kind).toBe('asset');}});++ test('the docName contract is file-shaped: a leaf still gains its .md extension', () => {+ // The mapping has no concept of a directory, so callers that can distinguish+ // a folder path from a docName must not route folder paths here — the shape+ // gate lives in resolveNavigationTarget, exercised below.+ expect(okContentNavigationTarget('articles/.ok', { pages })).toMatchObject({+ kind: 'asset',+ assetPath: 'articles/.ok.md',+ });+ });+});++describe('resolveNavigationTarget — folder-shaped .ok targets', () => {+ // A revealed `.ok` directory holds no indexed markdown, so it never enters the+ // page-derived folder index — the shape that used to reach the `.ok` file+ // fallback and come back as a phantom `<dir>.md` asset.+ const options = {+ pages: new Set(['articles/intro']),+ folderPaths: new Set(['articles']),+ };++ test('a revealed .ok directory does not resolve to a phantom .md asset', () => {+ for (const target of ['articles/.ok/', 'articles/.ok/templates/', '.ok/']) {+ expect(resolveNavigationTarget(target, options).kind).not.toBe('asset');+ }+ });++ test('folder-shaped misses resolve the same inside and outside .ok', () => {+ expect(resolveNavigationTarget('articles/nope/', options)).toEqual({+ kind: 'missing',+ target: 'articles/nope',+ });+ expect(resolveNavigationTarget('articles/.ok/', options)).toEqual({+ kind: 'missing',+ target: 'articles/.ok',+ });+ expect(resolveNavigationTarget('articles/.ok/templates/', options)).toEqual({+ kind: 'missing',+ target: 'articles/.ok/templates',+ });+ expect(resolveNavigationTarget('.ok/', options)).toEqual({+ kind: 'missing',+ target: '.ok',+ });+ });++ test('.ok folders backed by indexed skill docs still resolve as folders', () => {+ // Project skill docs ARE page-list members, so `.ok` and `.ok/skills`+ // register as real folder paths and resolve before the fallback.+ const skillOptions = { pages: new Set(['.ok/skills/writer/SKILL']) };+ for (const folderPath of ['.ok', '.ok/skills', '.ok/skills/writer']) {+ expect(resolveNavigationTarget(`${folderPath}/`, skillOptions)).toEqual({+ kind: 'folder',+ target: folderPath,+ folderPath,+ });+ }+ });++ test('doc-shaped .ok targets keep their read-only routing', () => {+ expect(resolveNavigationTarget('articles/.ok/templates/meeting', options)).toEqual({+ kind: 'doc',+ target: '__template__/articles/meeting',+ docName: '__template__/articles/meeting',+ });+ expect(+ resolveNavigationTarget('.ok/skills/writer/SKILL', {+ pages: new Set(['.ok/skills/writer/SKILL']),+ }),+ ).toEqual({+ kind: 'doc',+ target: '.ok/skills/writer/SKILL',+ docName: '.ok/skills/writer/SKILL',+ });+ expect(resolveNavigationTarget('articles/.ok', options)).toMatchObject({+ kind: 'asset',+ assetPath: 'articles/.ok.md',+ });+ });++ test('a trailing-slash template path returns missing, bypassing the rewrite', () => {+ // `managedArtifactDocNameFromContentTarget` rejects the slashed form, so+ // before the shape gate this reached the fallback, which re-tested the+ // slash-stripped path and rewrote it to the template editor. The folder+ // shape now wins instead. Pinned so a caller that later emits+ // trailing-slash template hashes cannot flip this silently.+ expect(resolveNavigationTarget('articles/.ok/templates/meeting/', options)).toEqual({+ kind: 'missing',+ target: 'articles/.ok/templates/meeting',+ });+ });});describe('resolveNavigationTarget .ok guard', () => {const options = { pages: new Set(['notes/real', '.ok/skills/writer/SKILL']) };- test('.ok targets never resolve to missing — the viewer replaces create-mode', () => {+ test('doc-shaped .ok targets never resolve to missing — the viewer replaces create-mode', () => {// Existing file and nonexistent name are unknowable at resolve time; both// shapes must land on the read-only viewer (its error pane is the// non-create missing surface), never on the create-mode editor.diff --git a/packages/app/src/components/navigation-targets.ts b/packages/app/src/components/navigation-targets.tsindex 04cbefb5c..50dac1834 100644--- a/packages/app/src/components/navigation-targets.ts+++ b/packages/app/src/components/navigation-targets.ts@@ -402,14 +402,25 @@ export function resolveNavigationTarget(};}- // A missing `.ok` target must not fall through to the create-mode editor —- // route it to the read-only viewer instead (see okContentNavigationTarget).- return (- okContentNavigationTarget(normalizedTarget, options) ?? {- kind: 'missing',- target: extensionlessTarget || normalizedTarget,- }- );+ // A missing DOC-shaped `.ok` target must not fall through to the create-mode+ // editor — route it to the read-only viewer instead (see+ // okContentNavigationTarget). A folder-shaped one deliberately does fall+ // through, because that fallback maps an extension-less leaf to its `.md`+ // file and has no concept of a directory, so it would come back as a phantom+ // `<dir>.md` asset. Folder shape alone is not enough to reach here for+ // ordinary content — every ancestor of an indexed doc registers above — but a+ // revealed `.ok` directory holds no indexed markdown, so it never enters the+ // folder index and lands here. Falling through to `missing` keeps it+ // shape-consistent with any other unindexed folder path, and lets hash+ // navigation defer rather than open anything.+ if (!expectsFolder) {+ const okTarget = okContentNavigationTarget(normalizedTarget, options);+ if (okTarget) return okTarget;+ }+ return {+ kind: 'missing',+ target: extensionlessTarget || normalizedTarget,+ };}/**