Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

feat(desktop): add "Open file…" for temporary single-file sessions (#2761)

mike-inkeepc7e66e4d429f
diff --git a/.changeset/open-file-desktop-entry.md b/.changeset/open-file-desktop-entry.md
new file mode 100644
index 000000000..664df445b
--- /dev/null
+++ b/.changeset/open-file-desktop-entry.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+OK Desktop can now open a single markdown file without setting up a project. The single-file editing session that `ok <file>` already provides is now reachable from the app itself: **File → Open file… (⇧⌘O)**, the Cmd+K palette, and the Project Navigator, each opening a native `.md`/`.mdx` picker. Loose files also open via Finder's **Open With → OpenKnowledge**. These flows open the file in a temporary session and never write a `.ok` folder into its directory, so previewing one file no longer risks turning its parent folder into a project. A picked file that already lives inside a project opens that project instead.
diff --git a/knip.config.ts b/knip.config.ts
index 9633755a0..16d637b4b 100644
--- a/knip.config.ts
+++ b/knip.config.ts
@@ -119,9 +119,7 @@ export default {
'packages/server': {
entry: ['src/**/*.test.ts'],
project: 'src/**',
- ignoreDependencies: [
- '@types/shell-quote',
- ],
+ ignoreDependencies: ['@types/shell-quote'],
},
'packages/cli': {
entry: ['src/**/*.test.ts', 'scripts/*.ts', 'tests/**/*.ts'],
diff --git a/packages/app/src/components/CommandPalette.dom.test.tsx b/packages/app/src/components/CommandPalette.dom.test.tsx
index cdce3161c..819c92c40 100644
--- a/packages/app/src/components/CommandPalette.dom.test.tsx
+++ b/packages/app/src/components/CommandPalette.dom.test.tsx
@@ -235,6 +235,7 @@ function createBridge() {
]),
),
open: mock(() => Promise.resolve()),
+ openFile: mock(() => Promise.resolve()),
},
dialog: {
openFolder: mock(() => Promise.resolve('/chosen/folder')),
@@ -343,6 +344,9 @@ describe('CommandPalette DOM behavior', () => {
/⇧⌘ N|Ctrl Shift N/,
);
expect(screen.getByTestId('command-palette-open-folder').textContent).toMatch(/⌘ O|Ctrl O/);
+ expect(screen.getByTestId('command-palette-open-file').textContent).toMatch(
+ /⇧⌘ O|Ctrl Shift O/,
+ );
fireEvent.click(switchProject);
await waitFor(() => expect(bridge.navigator.open).toHaveBeenCalledTimes(1));
@@ -356,6 +360,11 @@ describe('CommandPalette DOM behavior', () => {
});
});
+ // Open file delegates entirely to main (picker + ephemeral open); the
+ // renderer just fires the single bridge hop.
+ fireEvent.click(screen.getByTestId('command-palette-open-file'));
+ await waitFor(() => expect(bridge.project.openFile).toHaveBeenCalledTimes(1));
+
fireEvent.click(screen.getByTestId('command-palette-recent-/projects/alpha'));
await waitFor(() => {
expect(bridge.project.open).toHaveBeenCalledWith({
diff --git a/packages/app/src/components/NavigatorApp.dom.test.tsx b/packages/app/src/components/NavigatorApp.dom.test.tsx
index 0046c31d7..0e18aed26 100644
--- a/packages/app/src/components/NavigatorApp.dom.test.tsx
+++ b/packages/app/src/components/NavigatorApp.dom.test.tsx
@@ -103,6 +103,7 @@ function createBridge() {
getSessionState: mock(() => Promise.resolve({})),
setSessionState: mock(() => Promise.resolve()),
open: mock(() => Promise.resolve()),
+ openFile: mock(() => Promise.resolve()),
createNew: mock(() => Promise.resolve()),
recordCreateNewBannerShown: mock(() => Promise.resolve()),
close: mock(() => Promise.resolve()),
@@ -171,6 +172,11 @@ describe('NavigatorApp launcher runtime behavior', () => {
});
});
+ // Open file on disk → temporary single-file session; a single main-side hop
+ // (picker + ephemeral open both live in main).
+ fireEvent.click(screen.getByTestId('nav-open-file'));
+ await waitFor(() => expect(bridge.project.openFile).toHaveBeenCalledTimes(1));
+
fireEvent.click(await screen.findByText('Recent Project'));
await waitFor(() => {
expect(bridge.project.open).toHaveBeenCalledWith({
diff --git a/packages/app/src/components/NavigatorApp.tsx b/packages/app/src/components/NavigatorApp.tsx
index ebc24d168..278ce1c87 100644
--- a/packages/app/src/components/NavigatorApp.tsx
+++ b/packages/app/src/components/NavigatorApp.tsx
@@ -3,11 +3,13 @@
* boots without a `lastOpenedProject`, OR when the user holds Option at
* launch.
*
- * Three primary cards (Clone from GitHub, Open folder on disk, Create new
- * project) above a Recent list. Every project pick spawns a NEW editor
- * window via `ok:project:open` IPC — no switch-in-place. Navigator window
- * stays open. Create new project opens an in-app `CreateProjectDialog`
- * inside the Navigator window rather than dispatching to a separate flow.
+ * Four primary cards (Create new project, Open folder on disk, Open file on
+ * disk, Clone from GitHub) above a Recent list. Every project pick spawns a
+ * NEW editor window via `ok:project:open` IPC — no switch-in-place. Navigator
+ * window stays open. Create new project opens an in-app `CreateProjectDialog`
+ * inside the Navigator window rather than dispatching to a separate flow. Open
+ * file on disk opens a loose markdown file in a temporary single-file session
+ * (`ok:project:open-file-picker`), never writing a `.ok` folder to its parent.
*
* Web / CLI distribution never reaches this component — it only renders
* when `window.okDesktop?.config.mode === 'navigator'` (gated in
@@ -15,7 +17,15 @@
*/
import { Trans, useLingui } from '@lingui/react/macro';
-import { Folder, FolderOpenIcon, GitBranch, Loader2Icon, PlusIcon, XIcon } from 'lucide-react';
+import {
+ FileText,
+ Folder,
+ FolderOpenIcon,
+ GitBranch,
+ Loader2Icon,
+ PlusIcon,
+ XIcon,
+} from 'lucide-react';
import { useTheme } from 'next-themes';
import { type ComponentType, lazy, Suspense, useEffect, useState } from 'react';
import { useThemeBridge } from '@/hooks/use-theme-bridge';
@@ -250,6 +260,13 @@ export function NavigatorApp({ bridge }: { bridge: OkDesktopBridge }) {
const onCreate = () => setCreateDialogOpen(true);
+ // Open a loose markdown file in a temporary single-file session (no project
+ // setup, never writes `.ok` to the file's folder). Picker + open both run
+ // main-side; no window-manager focus dance is needed here (the ephemeral
+ // window is its own).
+ const onOpenFile = () =>
+ runWithErrorState(() => bridge.project.openFile(), t`Failed to open file.`);
+
// First-run pack pick → open the create dialog with the pack pre-selected
// and the full pack list so the dialog's Select can switch in-place.
const onPackSelect = (packId: OkPackId, packs: OkSeedPackInfo[]) => {
@@ -352,11 +369,12 @@ export function NavigatorApp({ bridge }: { bridge: OkDesktopBridge }) {
<FirstRunPacksView
onPackSelect={onPackSelect}
onOpenFolder={onOpenFolder}
+ onOpenFile={onOpenFile}
onClone={onClone}
onCreate={onCreate}
/>
) : (
- <section className="grid shrink-0 sm:grid-cols-3 gap-3">
+ <section className="grid shrink-0 sm:grid-cols-2 gap-3">
<NavigatorCard
title={t`Create new project`}
description={t`Start a new OpenKnowledge project.`}
@@ -371,6 +389,13 @@ export function NavigatorApp({ bridge }: { bridge: OkDesktopBridge }) {
dataTestId="nav-open"
Icon={FolderOpenIcon}
/>
+ <NavigatorCard
+ title={t`Open file on disk`}
+ description={t`Open a single markdown file — no project setup.`}
+ onClick={onOpenFile}
+ dataTestId="nav-open-file"
+ Icon={FileText}
+ />
<NavigatorCard
title={t`Clone from GitHub`}
description={t`Bring a remote repository onto this machine.`}
@@ -579,11 +604,13 @@ function NavigatorCard({ title, description, onClick, dataTestId, Icon }: Naviga
function FirstRunPacksView({
onPackSelect,
onOpenFolder,
+ onOpenFile,
onClone,
onCreate,
}: {
onPackSelect: (packId: OkPackId, packs: OkSeedPackInfo[]) => void;
onOpenFolder: () => void;
+ onOpenFile: () => void;
onClone: () => void;
onCreate: () => void;
}) {
@@ -658,6 +685,16 @@ function FirstRunPacksView({
<FolderOpenIcon aria-hidden="true" className="size-3.5" />
<Trans>Open folder</Trans>
</Button>
+ <Button
+ type="button"
+ variant="link-muted"
+ size="sm"
+ onClick={onOpenFile}
+ data-testid="nav-first-run-open-file"
+ >
+ <FileText aria-hidden="true" className="size-3.5" />
+ <Trans>Open file</Trans>
+ </Button>
<Button
type="button"
variant="link-muted"
diff --git a/packages/app/src/components/ProjectSwitcher.dom.test.tsx b/packages/app/src/components/ProjectSwitcher.dom.test.tsx
index dfd60036a..004072cd5 100644
--- a/packages/app/src/components/ProjectSwitcher.dom.test.tsx
+++ b/packages/app/src/components/ProjectSwitcher.dom.test.tsx
@@ -235,6 +235,7 @@ function createBridge() {
]),
),
open: mock(() => Promise.resolve()),
+ openFile: mock(() => Promise.resolve()),
},
dialog: {
openFolder: mock(() => Promise.resolve('/chosen/folder')),
@@ -298,6 +299,7 @@ describe('ProjectSwitcher dropdown behavior', () => {
'project-switcher-new-project',
'project-switcher-switch-project',
'project-switcher-open-folder',
+ 'project-switcher-open-file',
]) {
expect(screen.getByTestId(testId).querySelector('svg[aria-hidden="true"]')).not.toBeNull();
}
@@ -314,6 +316,10 @@ describe('ProjectSwitcher dropdown behavior', () => {
});
});
+ // Open file delegates to main (picker + ephemeral open); a single bridge hop.
+ fireEvent.click(screen.getByTestId('project-switcher-open-file'));
+ await waitFor(() => expect(bridge.project.openFile).toHaveBeenCalledTimes(1));
+
// Recents render through RecentProjectsMenu; a non-git recent opens with the
// `recents` entry point.
fireEvent.click(screen.getByTestId('project-switcher-recent-/projects/project-1'));
diff --git a/packages/app/src/components/ProjectSwitcher.tsx b/packages/app/src/components/ProjectSwitcher.tsx
index 6937f55c8..af07c2fb1 100644
--- a/packages/app/src/components/ProjectSwitcher.tsx
+++ b/packages/app/src/components/ProjectSwitcher.tsx
@@ -17,7 +17,15 @@
*/
import { Trans, useLingui } from '@lingui/react/macro';
-import { ChevronsUpDown, FolderOpen, GitBranch, LayoutGrid, Plus, Search } from 'lucide-react';
+import {
+ ChevronsUpDown,
+ FileText,
+ FolderOpen,
+ GitBranch,
+ LayoutGrid,
+ Plus,
+ Search,
+} from 'lucide-react';
import { useEffect, useRef, useState } from 'react';
import {
DropdownMenu,
@@ -175,6 +183,13 @@ export function ProjectSwitcher({ bridge }: ProjectSwitcherProps) {
}, t`Failed to open folder.`);
};
+ // Open a loose markdown file in a temporary single-file session (no project
+ // setup). Picker + open both run main-side; nothing crosses back here.
+ const onOpenFile = () => {
+ handleOpenChange(false);
+ void runWithToast(() => bridge.project.openFile(), t`Failed to open file.`);
+ };
+
const onSwitchProject = () => {
handleOpenChange(false);
void runWithToast(() => bridge.navigator.open(), t`Failed to open Project Navigator.`);
@@ -382,6 +397,16 @@ export function ProjectSwitcher({ bridge }: ProjectSwitcherProps) {
<FolderOpen aria-hidden="true" className="text-muted-foreground" />
<Trans>Open folder</Trans>
</DropdownMenuItem>
+ <DropdownMenuItem
+ onSelect={(e) => {
+ if (guardStaleSelect(e)) return;
+ onOpenFile();
+ }}
+ data-testid="project-switcher-open-file"
+ >
+ <FileText aria-hidden="true" className="text-muted-foreground" />
+ <Trans>Open file</Trans>
+ </DropdownMenuItem>
{/* "New worktree" sits at the bottom of the project-selection menu:
the per-project worktree flyouts are the primary worktree affordance
now, so the standalone create action is a secondary, last-position
diff --git a/packages/app/src/components/command-palette-commands.ts b/packages/app/src/components/command-palette-commands.ts
index 3b8813abd..f47b7afcf 100644
--- a/packages/app/src/components/command-palette-commands.ts
+++ b/packages/app/src/components/command-palette-commands.ts
@@ -166,6 +166,7 @@ const PALETTE_COMMAND_LABELS = {
initializeStarterPack: msg`Initialize starter pack`,
newProject: msg`New project`,
openFolderOnDisk: msg`Open folder on disk`,
+ openFileOnDisk: msg`Open file on disk`,
switchProject: msg`Switch project`,
settings: msg`Settings`,
installClaudeDesktop: msg`Install for Claude Chat & Cowork (Desktop App)`,
@@ -214,6 +215,7 @@ const COMMAND_ICONS: Record<string, ComponentType<{ className?: string }>> = {
'initialize-starter-pack': Package,
'new-project': Plus,
'open-folder': FolderOpen,
+ 'open-file': FileText,
'switch-project': LayoutGrid,
settings: Settings,
'install-claude-desktop': Download,
@@ -280,6 +282,14 @@ const COMMAND_DISPATCH: Record<string, (ctx: PaletteCommandContext) => void> = {
await bridge.project.open({ path, target: 'new-window', entryPoint: 'pick-existing' });
});
},
+ 'open-file': (ctx) => {
+ const bridge = ctx.bridge;
+ if (!bridge) return;
+ // The picker + ephemeral open both live main-side (`openEphemeralFile` owns
+ // the temp server/dir lifecycle), so this is a single fire-and-forget hop —
+ // no picked path crosses back to the renderer.
+ ctx.runAction(() => bridge.project.openFile());
+ },
'switch-project': (ctx) => {
const bridge = ctx.bridge;
if (!bridge) return;
diff --git a/packages/app/src/lib/command-menu-parity.test.ts b/packages/app/src/lib/command-menu-parity.test.ts
index c7b455fc6..c27bca64f 100644
--- a/packages/app/src/lib/command-menu-parity.test.ts
+++ b/packages/app/src/lib/command-menu-parity.test.ts
@@ -77,6 +77,7 @@ const PALETTE_COMMAND_LABELS = new Set<string>([
'New project',
'Switch project',
'Open folder',
+ 'Open file',
'New worktree',
'Switch worktree',
'Duplicate',
@@ -127,6 +128,7 @@ function makeFullDeps(): MenuDeps {
dialog: {} as MenuDeps['dialog'],
openNavigator: noop,
openProject: () => Promise.resolve(),
+ openEphemeralFile: () => Promise.resolve(),
getRecentProjects: () => [],
clearRecentProjects: noop,
openExternalUrl: noop,
@@ -325,6 +327,7 @@ describe('command-menu parity ratchet', () => {
{ menuLabel: 'New folder', shortcutId: 'new-folder' },
{ menuLabel: 'Switch project', shortcutId: 'switch-project' },
{ menuLabel: 'Open folder', shortcutId: 'open-folder' },
+ { menuLabel: 'Open file', shortcutId: 'open-file' },
{ menuLabel: 'Duplicate', shortcutId: 'file-tree-duplicate' },
{ menuLabel: 'Move to Trash', shortcutId: 'file-tree-delete' },
{ menuLabel: 'Settings', shortcutId: 'settings' },
@@ -445,6 +448,7 @@ describe('command identity registry (Phase 2b)', () => {
'initialize-starter-pack',
'new-project',
'open-folder',
+ 'open-file',
'switch-project',
'settings',
'install-claude-desktop',
diff --git a/packages/app/src/lib/desktop-bridge-types.ts b/packages/app/src/lib/desktop-bridge-types.ts
index 0a52ec11c..fa82419cc 100644
--- a/packages/app/src/lib/desktop-bridge-types.ts
+++ b/packages/app/src/lib/desktop-bridge-types.ts
@@ -1041,6 +1041,14 @@ export interface OkDesktopBridge {
currentBranch: string | null;
};
}): Promise<void>;
+ /**
+ * File → Open file… — show the native md/mdx picker and open the pick in a
+ * temporary single-file session (the desktop side of `ok <file>`). Picker +
+ * open both run main-side; the picked path never crosses back to the
+ * renderer. See canonical JSDoc in
+ * `packages/desktop/src/shared/bridge-contract.ts`.
+ */
+ openFile(): Promise<void>;
/**
* Atomically scaffold a new project under `parent/name` with the
* user-chosen `editors` set. `editors` is the renderer's exact selection
diff --git a/packages/app/src/lib/keyboard-shortcuts.ts b/packages/app/src/lib/keyboard-shortcuts.ts
index d3de7d64f..06a2d5aa5 100644
--- a/packages/app/src/lib/keyboard-shortcuts.ts
+++ b/packages/app/src/lib/keyboard-shortcuts.ts
@@ -298,6 +298,14 @@ const KEYBOARD_SHORTCUT_DEFINITIONS = [
scope: msg`OK Desktop`,
bindings: [{ mac: '⌘ O', windowsLinux: 'Ctrl O' }],
},
+ {
+ id: 'open-file',
+ category: 'workspace',
+ title: msg`Open file`,
+ description: msg`Open a single markdown file in a temporary session, without project setup.`,
+ scope: msg`OK Desktop`,
+ bindings: [{ mac: '⇧⌘ O', windowsLinux: 'Ctrl Shift O' }],
+ },
{
id: 'switch-project',
category: 'workspace',
diff --git a/packages/app/src/locales/en/messages.json b/packages/app/src/locales/en/messages.json
index eea4394a1..de8cb9c99 100644
--- a/packages/app/src/locales/en/messages.json
+++ b/packages/app/src/locales/en/messages.json
@@ -439,6 +439,7 @@
"8uAWix": [
"This template lives in a parent folder — deleting it affects every folder beneath it that doesn't define its own version."
],
+ "8vCZcs": ["Failed to open file."],
"8vETh9": ["Show"],
"92rbk2": ["Mirror loading <0>", ["mirrorRef"], "</0>"],
"96G6Re": ["New folder"],
@@ -815,6 +816,7 @@
"Gx0VS1": ["e.g. drafts/ or *.draft.md"],
"GzPQ2f": ["Stay in the loop"],
"H-vDm3": ["Relaunching to install the update…"],
+ "H08D2X": ["Open a single markdown file in a temporary session, without project setup."],
"H0WlWQ": ["Grid of rows and columns with a header row."],
"H86f9p": ["Collapse"],
"HAvRAI": [["skillCount", "plural", { "one": ["skill"], "other": ["skills"] }]],
@@ -1913,6 +1915,7 @@
],
"gJR87V": ["Could not create the project folder. Pick a different folder."],
"gKi-a_": ["New project"],
+ "gOD68k": ["Open a single markdown file — no project setup."],
"gQV-9w": [
"Branch switched but the ",
["targetNoun"],
@@ -2130,6 +2133,7 @@
],
"k_pade": ["Config sharing is now shared. Commit the OK files to share with your team."],
"k_yIIc": ["Will be created at: <0>", ["targetPreview"], "</0>"],
+ "ka6Eke": ["Open file on disk"],
"kdzzOK": ["Off — search ranks by keyword only. No content leaves this computer."],
"keNFEd": ["Set identity"],
"khCa4M": ["Teaches coding agents in this project to read and write through OpenKnowledge."],
diff --git a/packages/app/src/locales/en/messages.po b/packages/app/src/locales/en/messages.po
index b5cbff011..3bc9e470f 100644
--- a/packages/app/src/locales/en/messages.po
+++ b/packages/app/src/locales/en/messages.po
@@ -3456,6 +3456,11 @@ msgstr "Failed to move"
msgid "Failed to open cloned project."
msgstr "Failed to open cloned project."
+#: src/components/NavigatorApp.tsx
+#: src/components/ProjectSwitcher.tsx
+msgid "Failed to open file."
+msgstr "Failed to open file."
+
#: src/components/NavigatorApp.tsx
#: src/components/ProjectSwitcher.tsx
msgid "Failed to open folder."
@@ -5537,6 +5542,14 @@ msgstr "Open a project to edit."
msgid "Open a project to manage its AI tool connections."
msgstr "Open a project to manage its AI tool connections."
+#: src/components/NavigatorApp.tsx
+msgid "Open a single markdown file — no project setup."
+msgstr "Open a single markdown file — no project setup."
+
+#: src/lib/keyboard-shortcuts.ts
+msgid "Open a single markdown file in a temporary session, without project setup."
+msgstr "Open a single markdown file in a temporary session, without project setup."
+
#: src/presence/PresenceBar.tsx
msgid "Open activity panel for {tooltipName}"
msgstr "Open activity panel for {tooltipName}"
@@ -5606,10 +5619,18 @@ msgid "Open emoji picker for {keyName}"
msgstr "Open emoji picker for {keyName}"
#: src/components/AssetPreview.tsx
+#: src/components/NavigatorApp.tsx
+#: src/components/ProjectSwitcher.tsx
#: src/components/ViewerStatusPane.tsx
+#: src/lib/keyboard-shortcuts.ts
msgid "Open file"
msgstr "Open file"
+#: src/components/command-palette-commands.ts
+#: src/components/NavigatorApp.tsx
+msgid "Open file on disk"
+msgstr "Open file on disk"
+
#: src/components/NavigatorApp.tsx
#: src/components/ProjectSwitcher.tsx
#: src/lib/keyboard-shortcuts.ts
diff --git a/packages/app/src/locales/pseudo/messages.json b/packages/app/src/locales/pseudo/messages.json
index ebd4d6541..3ffea1a67 100644
--- a/packages/app/src/locales/pseudo/messages.json
+++ b/packages/app/src/locales/pseudo/messages.json
@@ -439,6 +439,7 @@
"8uAWix": [
"Ţĥĩś ţēḿƥĺàţē ĺĩvēś ĩń à ƥàŕēńţ ƒōĺďēŕ — ďēĺēţĩńĝ ĩţ àƒƒēćţś ēvēŕŷ ƒōĺďēŕ ƀēńēàţĥ ĩţ ţĥàţ ďōēśń'ţ ďēƒĩńē ĩţś ōŵń vēŕśĩōń."
],
+ "8vCZcs": ["Ƒàĩĺēď ţō ōƥēń ƒĩĺē."],
"8vETh9": ["Śĥōŵ"],
"92rbk2": ["Ḿĩŕŕōŕ ĺōàďĩńĝ <0>", ["mirrorRef"], "</0>"],
"96G6Re": ["Ńēŵ ƒōĺďēŕ"],
@@ -815,6 +816,7 @@
"Gx0VS1": ["ē.ĝ. ďŕàƒţś/ ōŕ *.ďŕàƒţ.ḿď"],
"GzPQ2f": ["Śţàŷ ĩń ţĥē ĺōōƥ"],
"H-vDm3": ["Ŕēĺàũńćĥĩńĝ ţō ĩńśţàĺĺ ţĥē ũƥďàţē…"],
+ "H08D2X": ["Ōƥēń à śĩńĝĺē ḿàŕķďōŵń ƒĩĺē ĩń à ţēḿƥōŕàŕŷ śēśśĩōń, ŵĩţĥōũţ ƥŕōĴēćţ śēţũƥ."],
"H0WlWQ": ["Ĝŕĩď ōƒ ŕōŵś àńď ćōĺũḿńś ŵĩţĥ à ĥēàďēŕ ŕōŵ."],
"H86f9p": ["Ćōĺĺàƥśē"],
"HAvRAI": [["skillCount", "plural", { "one": ["śķĩĺĺ"], "other": ["śķĩĺĺś"] }]],
@@ -1913,6 +1915,7 @@
],
"gJR87V": ["Ćōũĺď ńōţ ćŕēàţē ţĥē ƥŕōĴēćţ ƒōĺďēŕ. Ƥĩćķ à ďĩƒƒēŕēńţ ƒōĺďēŕ."],
"gKi-a_": ["Ńēŵ ƥŕōĴēćţ"],
+ "gOD68k": ["Ōƥēń à śĩńĝĺē ḿàŕķďōŵń ƒĩĺē — ńō ƥŕōĴēćţ śēţũƥ."],
"gQV-9w": [
"ßŕàńćĥ śŵĩţćĥēď ƀũţ ţĥē ",
["targetNoun"],
@@ -2130,6 +2133,7 @@
],
"k_pade": ["Ćōńƒĩĝ śĥàŕĩńĝ ĩś ńōŵ śĥàŕēď. Ćōḿḿĩţ ţĥē ŌĶ ƒĩĺēś ţō śĥàŕē ŵĩţĥ ŷōũŕ ţēàḿ."],
"k_yIIc": ["Ŵĩĺĺ ƀē ćŕēàţēď àţ: <0>", ["targetPreview"], "</0>"],
+ "ka6Eke": ["Ōƥēń ƒĩĺē ōń ďĩśķ"],
"kdzzOK": ["Ōƒƒ — śēàŕćĥ ŕàńķś ƀŷ ķēŷŵōŕď ōńĺŷ. Ńō ćōńţēńţ ĺēàvēś ţĥĩś ćōḿƥũţēŕ."],
"keNFEd": ["Śēţ ĩďēńţĩţŷ"],
"khCa4M": ["Ţēàćĥēś ćōďĩńĝ àĝēńţś ĩń ţĥĩś ƥŕōĴēćţ ţō ŕēàď àńď ŵŕĩţē ţĥŕōũĝĥ ŌƥēńĶńōŵĺēďĝē."],
diff --git a/packages/app/src/locales/pseudo/messages.po b/packages/app/src/locales/pseudo/messages.po
index 53f1a4fb2..60b0669f5 100644
--- a/packages/app/src/locales/pseudo/messages.po
+++ b/packages/app/src/locales/pseudo/messages.po
@@ -3452,6 +3452,11 @@ msgstr ""
msgid "Failed to open cloned project."
msgstr ""
+#: src/components/NavigatorApp.tsx
+#: src/components/ProjectSwitcher.tsx
+msgid "Failed to open file."
+msgstr ""
+
#: src/components/NavigatorApp.tsx
#: src/components/ProjectSwitcher.tsx
msgid "Failed to open folder."
@@ -5533,6 +5538,14 @@ msgstr ""
msgid "Open a project to manage its AI tool connections."
msgstr ""
+#: src/components/NavigatorApp.tsx
+msgid "Open a single markdown file — no project setup."
+msgstr ""
+
+#: src/lib/keyboard-shortcuts.ts
+msgid "Open a single markdown file in a temporary session, without project setup."
+msgstr ""
+
#: src/presence/PresenceBar.tsx
msgid "Open activity panel for {tooltipName}"
msgstr ""
@@ -5602,10 +5615,18 @@ msgid "Open emoji picker for {keyName}"
msgstr ""
#: src/components/AssetPreview.tsx
+#: src/components/NavigatorApp.tsx
+#: src/components/ProjectSwitcher.tsx
#: src/components/ViewerStatusPane.tsx
+#: src/lib/keyboard-shortcuts.ts
msgid "Open file"
msgstr ""
+#: src/components/command-palette-commands.ts
+#: src/components/NavigatorApp.tsx
+msgid "Open file on disk"
+msgstr ""
+
#: src/components/NavigatorApp.tsx
#: src/components/ProjectSwitcher.tsx
#: src/lib/keyboard-shortcuts.ts
diff --git a/packages/app/tests/stress/fixtures/handoff-mocks.ts b/packages/app/tests/stress/fixtures/handoff-mocks.ts
index 9422187ab..c7b7b751c 100644
--- a/packages/app/tests/stress/fixtures/handoff-mocks.ts
+++ b/packages/app/tests/stress/fixtures/handoff-mocks.ts
@@ -411,6 +411,7 @@ export async function installHandoffMocks(page: Page, cfg: HandoffMockConfig): P
}),
setSessionState: async () => {},
open: async () => {},
+ openFile: async () => {},
createNew: async () => {},
recordCreateNewBannerShown: async () => {},
checkTargetExists: async () => 'unreadable' as const,
diff --git a/packages/core/src/bridge/bind-frontmatter-doc.ts b/packages/core/src/bridge/bind-frontmatter-doc.ts
index 8f9d95287..c014b1413 100644
--- a/packages/core/src/bridge/bind-frontmatter-doc.ts
+++ b/packages/core/src/bridge/bind-frontmatter-doc.ts
@@ -1,4 +1,3 @@
-
import type * as Y from 'yjs';
import type { Err, Ok, Result } from '../config/result.ts';
import { type FrontmatterValidationError, toFrontmatterIssue } from '../frontmatter/errors.ts';
diff --git a/packages/core/src/bridge/bridge-invariant.ts b/packages/core/src/bridge/bridge-invariant.ts
index 8bfdb40cd..005627195 100644
--- a/packages/core/src/bridge/bridge-invariant.ts
+++ b/packages/core/src/bridge/bridge-invariant.ts
@@ -1,4 +1,3 @@
-
import { fnv1aDigest } from './hash-util.ts';
export type BridgeInvariantSite = 'observer-b' | 'persistence' | 'test-harness';
diff --git a/packages/core/src/bridge/doc-boundary-space.ts b/packages/core/src/bridge/doc-boundary-space.ts
index c18c086d5..8890f6739 100644
--- a/packages/core/src/bridge/doc-boundary-space.ts
+++ b/packages/core/src/bridge/doc-boundary-space.ts
@@ -1,4 +1,3 @@
-
import { FRONTMATTER_RE, stripFrontmatter } from '../extensions/frontmatter.ts';
const LEADING_BOUNDARY_RE = /^(?:\r?\n)+/;
diff --git a/packages/core/src/bridge/growth-detect.ts b/packages/core/src/bridge/growth-detect.ts
index 463e89595..9d9c244b0 100644
--- a/packages/core/src/bridge/growth-detect.ts
+++ b/packages/core/src/bridge/growth-detect.ts
@@ -1,4 +1,3 @@
-
const DEFAULT_MIN_SUBSTANTIVE_LINE_LENGTH = 16;
export const DUPLICATION_GATE_MIN_LINE_LENGTH = 8;
diff --git a/packages/core/src/bridge/merge-three-way.ts b/packages/core/src/bridge/merge-three-way.ts
index 3c927eb47..3ab9cc6ef 100644
--- a/packages/core/src/bridge/merge-three-way.ts
+++ b/packages/core/src/bridge/merge-three-way.ts
@@ -38,7 +38,6 @@ function mergeThreeWayImpl(baseline: string, userText: string, agentText: string
return parts.join('\n');
}
-
export type BridgeMergeContentLossSide = 'user' | 'agent';
export type BridgeMergeContentLossWhich = 'substring' | 'order' | 'growth';
diff --git a/packages/core/src/bridge/normalize.ts b/packages/core/src/bridge/normalize.ts
index 3f0880aa5..4b8890476 100644
--- a/packages/core/src/bridge/normalize.ts
+++ b/packages/core/src/bridge/normalize.ts
@@ -1,4 +1,3 @@
-
const COMMONMARK_ESCAPE_RE = /\\([!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~])/g;
const TABLE_ALIGN_ROW_RE = /^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)+\|?\s*$/;
diff --git a/packages/core/src/bridge/pm-structural-equivalence.ts b/packages/core/src/bridge/pm-structural-equivalence.ts
index 0be5203e4..754dc5cc2 100644
--- a/packages/core/src/bridge/pm-structural-equivalence.ts
+++ b/packages/core/src/bridge/pm-structural-equivalence.ts
@@ -32,7 +32,6 @@ const BR_SENTINEL: PmStructuralNode = { type: '__br__' };
const BR_LITERAL_RE = /^<br\s*\/?>$/i;
-
interface DegradeEntry {
readonly label: string;
readonly severity: ToleranceClassSeverity;
@@ -128,7 +127,6 @@ export interface ComparePmStructuralOptions {
ignoreAttrs?: (attrKey: string) => boolean;
}
-
/** Rebuild a node with `fn` applied to each child; identity when childless.
* Shared by the degrade canonicalizers so none re-implements the walk. */
function mapChildren(
@@ -250,7 +248,6 @@ function applyDegrades(tree: PmStructuralNode): {
return { normalized: current, fired };
}
-
export function comparePmStructural(
expected: PmStructuralNode,
actual: PmStructuralNode,
diff --git a/packages/core/src/bridge/subsequence.ts b/packages/core/src/bridge/subsequence.ts
index dca644141..af20de1e2 100644
--- a/packages/core/src/bridge/subsequence.ts
+++ b/packages/core/src/bridge/subsequence.ts
@@ -1,4 +1,3 @@
-
/** True when `needle` is a subsequence of `haystack` (two-pointer, O(n+m)):
* insertions in `haystack` are free; any dropped or substituted `needle` byte
* fails. */
diff --git a/packages/core/src/commands/command-identity.ts b/packages/core/src/commands/command-identity.ts
index 41e892d04..cffa5e39a 100644
--- a/packages/core/src/commands/command-identity.ts
+++ b/packages/core/src/commands/command-identity.ts
@@ -270,7 +270,7 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [
{
id: 'open-folder',
labelKey: 'openFolderOnDisk',
- keywords: ['project'],
+ keywords: ['project', 'folder', 'disk'],
shortcutId: 'open-folder',
availability: { host: 'desktop' },
palette: { group: 'project', visibility: 'always' },
@@ -284,6 +284,28 @@ export const COMMAND_IDENTITIES: readonly CommandIdentity[] = [
},
],
},
+ {
+ // Open a loose markdown file in a temporary single-file session (the desktop
+ // side of `ok <file>`): no project setup, never writes `.ok` to the file's
+ // folder. Sits right after Open folder in the File menu; the receiver
+ // (`openEphemeralFile`) re-derives project-vs-ephemeral, so a file that
+ // happens to live inside a project opens that project instead.
+ id: 'open-file',
+ labelKey: 'openFileOnDisk',
+ keywords: ['file', 'markdown', 'single', 'standalone', 'temporary'],
+ shortcutId: 'open-file',
+ availability: { host: 'desktop' },
+ palette: { group: 'project', visibility: 'always' },
+ menu: [
+ {
+ section: 'file-project',
+ order: 3,
+ accelerator: 'CmdOrCtrl+Shift+O',
+ ellipsis: true,
+ menuLabelKey: 'openFile',
+ },
+ ],
+ },
{
id: 'switch-project',
labelKey: 'switchProject',
diff --git a/packages/core/src/constants/menu-labels.ts b/packages/core/src/constants/menu-labels.ts
index 8cd48757b..14a9d2f2a 100644
--- a/packages/core/src/constants/menu-labels.ts
+++ b/packages/core/src/constants/menu-labels.ts
@@ -29,6 +29,7 @@ export const MENU_LABELS = {
newFromTemplate: 'New from template',
newProject: 'New project',
openFolder: 'Open folder',
+ openFile: 'Open file',
duplicate: 'Duplicate',
rename: 'Rename',
revealInFinder: 'Reveal in Finder',
@@ -71,6 +72,11 @@ export const MENU_LABELS = {
// Open folder's palette row is the descriptive "Open folder on disk"; the
// native File menu renders the terser "Open folder…" via `openFolder` above.
openFolderOnDisk: 'Open folder on disk',
+ // Open file's palette + Navigator row is the descriptive "Open file on disk";
+ // the native File menu renders the terser "Open file…" via `openFile` above.
+ // Opens a loose markdown file in a temporary single-file session (no project
+ // setup, no `.ok` written to its folder) — the desktop side of `ok <file>`.
+ openFileOnDisk: 'Open file on disk',
// Palette-only commands (no native-menu leaf); shared here so the label-parity
// test guards them and the registry keeps a single label source.
openGraph: 'Open graph',
diff --git a/packages/core/src/desktop-bridge.ts b/packages/core/src/desktop-bridge.ts
index 75f1784ba..76ba13e03 100644
--- a/packages/core/src/desktop-bridge.ts
+++ b/packages/core/src/desktop-bridge.ts
@@ -1215,6 +1215,14 @@ export interface OkDesktopBridge {
getSessionState(): Promise<ProjectSessionState>;
setSessionState(state: ProjectSessionState): Promise<void>;
open(request: OkProjectOpenRequest): Promise<void>;
+ /**
+ * File → Open file… — show the native md/mdx picker and open the pick in a
+ * temporary single-file session (the desktop side of `ok <file>`). Picker +
+ * open both run main-side; the picked path never crosses back to the
+ * renderer. See canonical JSDoc in
+ * `packages/desktop/src/shared/bridge-contract.ts`.
+ */
+ openFile(): Promise<void>;
/**
* Atomically scaffold a new project under `parent/name` with the
* user-chosen `editors` set. `editors` is the renderer's exact selection
diff --git a/packages/core/src/markdown/callout-transformer.ts b/packages/core/src/markdown/callout-transformer.ts
index a363dfd54..83d47404a 100644
--- a/packages/core/src/markdown/callout-transformer.ts
+++ b/packages/core/src/markdown/callout-transformer.ts
@@ -1,4 +1,3 @@
-
import type { Blockquote, Paragraph, Root } from 'mdast';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import { visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/comment-promoter.ts b/packages/core/src/markdown/comment-promoter.ts
index 47f0d07e4..193e286b0 100644
--- a/packages/core/src/markdown/comment-promoter.ts
+++ b/packages/core/src/markdown/comment-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Paragraph, PhrasingContent, Root, RootContent, Text } from 'mdast';
import { SKIP, visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
diff --git a/packages/core/src/markdown/dedent-block-jsx-close.ts b/packages/core/src/markdown/dedent-block-jsx-close.ts
index b6299a948..ece5c02a1 100644
--- a/packages/core/src/markdown/dedent-block-jsx-close.ts
+++ b/packages/core/src/markdown/dedent-block-jsx-close.ts
@@ -1,4 +1,3 @@
-
import { findFencedRegions, isInsideFence } from './fence-regions.ts';
const INDENTED_BLOCK_JSX_CLOSE_RE = /^([ ]{1,3})(<\/[A-Z][A-Za-z0-9_]*\s*>)([ \t]*)$/gm;
diff --git a/packages/core/src/markdown/details-accordion-promoter.ts b/packages/core/src/markdown/details-accordion-promoter.ts
index acd398aa6..54774764a 100644
--- a/packages/core/src/markdown/details-accordion-promoter.ts
+++ b/packages/core/src/markdown/details-accordion-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Paragraph, Parent, Root, Text } from 'mdast';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import { visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/fence-regions.ts b/packages/core/src/markdown/fence-regions.ts
index fb5ac8e8a..c7518d614 100644
--- a/packages/core/src/markdown/fence-regions.ts
+++ b/packages/core/src/markdown/fence-regions.ts
@@ -1,4 +1,3 @@
-
const FENCE_RE = /^(`{3,}|~{3,})/gm;
export function findFencedRegions(src: string): Array<[number, number]> {
diff --git a/packages/core/src/markdown/fixtures/index.ts b/packages/core/src/markdown/fixtures/index.ts
index 6931623c7..00f5771ee 100644
--- a/packages/core/src/markdown/fixtures/index.ts
+++ b/packages/core/src/markdown/fixtures/index.ts
@@ -1,4 +1,3 @@
-
import { readFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -9,7 +8,6 @@ function fixturePath(...segments: string[]): string {
return resolve(FIXTURES_DIR, ...segments);
}
-
interface GfmExample {
section: string;
markdown: string;
@@ -19,7 +17,6 @@ export function loadGfmExamples(): GfmExample[] {
return JSON.parse(readFileSync(fixturePath('gfm', 'examples.json'), 'utf8')) as GfmExample[];
}
-
interface MdxCrashEntry {
id: string;
input: string;
@@ -71,7 +68,6 @@ export function loadLargeEmbedFixtures(): LargeEmbedFixture[] {
) as LargeEmbedFixture[];
}
-
export function loadPrd6955Before(): string {
return readFileSync(fixturePath('regression', 'prd-6955-before.md'), 'utf8');
}
@@ -80,7 +76,6 @@ export function loadPrd6955CorruptedTriplicated(): string {
return readFileSync(fixturePath('regression', 'prd-6955-corrupted-triplicated.md'), 'utf8');
}
-
export interface NgPinnedCase {
id: string;
name: string;
@@ -97,7 +92,6 @@ export function loadNgPinnedCases(): NgPinnedCase[] {
) as NgPinnedCase[];
}
-
export function loadLargeRealistic(): string {
return readFileSync(fixturePath('perf', 'large-realistic.md'), 'utf8');
}
diff --git a/packages/core/src/markdown/fixtures/perf/generate.ts b/packages/core/src/markdown/fixtures/perf/generate.ts
index daa3ef82b..8b1eb8519 100644
--- a/packages/core/src/markdown/fixtures/perf/generate.ts
+++ b/packages/core/src/markdown/fixtures/perf/generate.ts
@@ -1,4 +1,3 @@
-
import { writeFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -11,7 +10,6 @@ const BASELINE_ONLY_COUNTS = [500, 2500] as const;
const SEED = 0xf1de1117;
-
function mulberry32(seed: number): () => number {
let a = seed >>> 0;
return () => {
@@ -38,7 +36,6 @@ function pickWeighted<T>(rand: () => number, items: readonly [T, number][]): T {
return items[items.length - 1][0];
}
-
const WORDS = [
'lorem',
'ipsum',
@@ -156,7 +153,6 @@ function mdxBlock(rand: () => number): string {
return `<${name}>\n\n${sentence(rand)}\n\n</${name}>`;
}
-
type BlockKind = 'paragraph' | 'heading' | 'list' | 'code' | 'table' | 'mdx';
const MIX: readonly [BlockKind, number][] = [
@@ -195,7 +191,6 @@ function generateDocument(blockCount: number, seed: number): string {
return `${blocks.join('\n\n')}\n`;
}
-
function main(): void {
for (const count of [...BLOCK_COUNTS, ...BASELINE_ONLY_COUNTS]) {
const doc = generateDocument(count, SEED);
diff --git a/packages/core/src/markdown/guard-flanking-matrix.ts b/packages/core/src/markdown/guard-flanking-matrix.ts
index 32c055c5b..420dc0fe5 100644
--- a/packages/core/src/markdown/guard-flanking-matrix.ts
+++ b/packages/core/src/markdown/guard-flanking-matrix.ts
@@ -7,7 +7,6 @@ import {
import { BACKSLASH_GUARD_SUBSTITUTIONS, encodeBackslashEscapes } from './backslash-escape-guard.ts';
import { ENTITY_REF_GUARD_SUBSTITUTIONS, encodeEntityRefs } from './entity-ref-guard.ts';
-
export const ATTENTION_DELIMITERS = ['*', '_', '**', '~~', '=='] as const;
export type FlankClass = 'whitespace' | 'punctuation' | 'other';
diff --git a/packages/core/src/markdown/handler-shadow-audit.ts b/packages/core/src/markdown/handler-shadow-audit.ts
index 283913255..2653473da 100644
--- a/packages/core/src/markdown/handler-shadow-audit.ts
+++ b/packages/core/src/markdown/handler-shadow-audit.ts
@@ -1,4 +1,3 @@
-
export interface HandlerShadowWitness {
input: string;
expect: 'byte' | 'byte-and-reparse-type';
diff --git a/packages/core/src/markdown/highlight-promoter.ts b/packages/core/src/markdown/highlight-promoter.ts
index 6319f264f..f55912407 100644
--- a/packages/core/src/markdown/highlight-promoter.ts
+++ b/packages/core/src/markdown/highlight-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Parent, PhrasingContent, Root, Text } from 'mdast';
import type { MdxJsxTextElement } from 'mdast-util-mdx';
import { SKIP, visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/html-to-mdast.ts b/packages/core/src/markdown/html-to-mdast.ts
index 2f082e6d0..78fdfeb02 100644
--- a/packages/core/src/markdown/html-to-mdast.ts
+++ b/packages/core/src/markdown/html-to-mdast.ts
@@ -1,4 +1,3 @@
-
import type { Root as HastRoot } from 'hast';
import type { Root as MdastRoot } from 'mdast';
import rehypeParse from 'rehype-parse';
@@ -76,8 +75,7 @@ export function htmlToMdast(html: string, options?: HtmlToMdastOptions): MdastRo
throw new HtmlPayloadTooLargeError(html.length, maxBytes);
}
- const processor = unified()
- .use(rehypeParse, { fragment: true });
+ const processor = unified().use(rehypeParse, { fragment: true });
for (const plugin of cleanupPlugins) {
processor.use(plugin);
diff --git a/packages/core/src/markdown/image-promoter.ts b/packages/core/src/markdown/image-promoter.ts
index 994eb6917..706fa9afb 100644
--- a/packages/core/src/markdown/image-promoter.ts
+++ b/packages/core/src/markdown/image-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Image, Paragraph, Root } from 'mdast';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import { visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/index.ts b/packages/core/src/markdown/index.ts
index fc30bda02..8b36807fd 100644
--- a/packages/core/src/markdown/index.ts
+++ b/packages/core/src/markdown/index.ts
@@ -1,4 +1,3 @@
-
import {
type FromProseMirrorOptions,
fromPmMark,
@@ -197,7 +196,6 @@ export class MarkdownManager {
}
}
-
const registry = createRegistry();
function destructureAttrs(
@@ -246,7 +244,6 @@ function destructureAttrs(
return result;
}
-
function hasDirtyDescendant(node: PmNode): boolean {
let found = false;
node.descendants((child) => {
@@ -266,7 +263,6 @@ function effectiveDirty(node: PmNode, freshnessChecker?: StructuralFreshnessChec
return freshnessChecker ? freshnessChecker.isDiverged(node.toJSON()) : false;
}
-
function isEmptyMdastParagraph(node: MdastNodes): boolean {
if (node.type !== 'paragraph') return false;
const children = node.children ?? [];
@@ -335,7 +331,6 @@ function extractTextFromMdastNodes(nodes: MdastNodes[]): string {
return out;
}
-
import {
AUDIO_EXTENSIONS,
FILE_ATTACHMENT_EXTENSIONS,
@@ -582,7 +577,6 @@ function buildMdastToPmHandlers(
}));
}
-
if (m.emphasis) {
handlers.emphasis = toPmMark(m.emphasis, (node: Emphasis) => ({
sourceDelimiter: node.data?.sourceDelimiter ?? '*',
@@ -663,7 +657,6 @@ function buildMdastToPmHandlers(
}));
}
-
if (m.link) {
const sourceLiteralMark = m.sourceLiteral;
handlers.link = (node: Link, _parent: MdastParent, state: MdastToPmState) => {
@@ -942,7 +935,6 @@ function buildMdastToPmHandlers(
};
}
-
const blockUnknownHandler = (node: {
type: string;
position?: { start: { offset: number }; end: { offset: number } };
@@ -1068,7 +1060,6 @@ function buildMdastToPmHandlers(
return handlers as RemarkProseMirrorOptions['handlers'];
}
-
function buildPmToMdastHandlers(
schema: Schema,
freshness: FreshnessCheckerHolder,
diff --git a/packages/core/src/markdown/lint/config-schemas.ts b/packages/core/src/markdown/lint/config-schemas.ts
index 207cd95c2..e78a1381d 100644
--- a/packages/core/src/markdown/lint/config-schemas.ts
+++ b/packages/core/src/markdown/lint/config-schemas.ts
@@ -29,7 +29,6 @@ const fullPluginShape = Object.fromEntries(
LINT_PLUGINS.map((plugin) => [plugin.id, plugin.sliceSchema]),
) as z.ZodRawShape;
-
export const LinterConfigSchema = z.object({
enabled: z.boolean(),
plugins: z.object(fullPluginShape),
diff --git a/packages/core/src/markdown/lint/default-config.ts b/packages/core/src/markdown/lint/default-config.ts
index a51f2ffb0..d48eea5e4 100644
--- a/packages/core/src/markdown/lint/default-config.ts
+++ b/packages/core/src/markdown/lint/default-config.ts
@@ -6,7 +6,6 @@ export const DEFAULT_MARKDOWNLINT_CONFIG: Record<string, MarkdownlintRuleSetting
MD013: false,
};
-
export function resolveMarkdownlintConfig(
rules: Record<string, MarkdownlintRuleSetting> | undefined,
): Configuration {
diff --git a/packages/core/src/markdown/lint/index.ts b/packages/core/src/markdown/lint/index.ts
index 3baacdeb7..d1a5ab4dc 100644
--- a/packages/core/src/markdown/lint/index.ts
+++ b/packages/core/src/markdown/lint/index.ts
@@ -1,4 +1,3 @@
-
import { LINT_PLUGINS, type LinterConfig } from './plugins.ts';
import type { LintDiagnostic } from './types.ts';
diff --git a/packages/core/src/markdown/lint/plugins.ts b/packages/core/src/markdown/lint/plugins.ts
index 65a1b564c..1cd40ef3a 100644
--- a/packages/core/src/markdown/lint/plugins.ts
+++ b/packages/core/src/markdown/lint/plugins.ts
@@ -1,4 +1,3 @@
-
import { z } from 'zod';
import { DEFAULT_MARKDOWNLINT_CONFIG, resolveMarkdownlintConfig } from './default-config.ts';
import { fixMarkdownText, runMarkdownlint } from './markdownlint-runner.ts';
@@ -9,7 +8,6 @@ import {
type MarkdownlintSlice,
} from './types.ts';
-
const MarkdownlintRuleSettingSchema = z.union([
z.boolean(),
z.enum(MARKDOWNLINT_RULE_SEVERITIES),
diff --git a/packages/core/src/markdown/lint/types.ts b/packages/core/src/markdown/lint/types.ts
index 3651bd7eb..617f6e5b9 100644
--- a/packages/core/src/markdown/lint/types.ts
+++ b/packages/core/src/markdown/lint/types.ts
@@ -1,4 +1,3 @@
-
export const LINT_PLUGIN_IDS = ['markdownlint'] as const;
export type LintPluginId = (typeof LINT_PLUGIN_IDS)[number];
@@ -42,7 +41,6 @@ export interface MarkdownlintSlice {
rules: Record<string, MarkdownlintRuleSetting>;
}
-
interface RuleOptionSpecBase {
key: string;
description: string;
diff --git a/packages/core/src/markdown/math-promoter.ts b/packages/core/src/markdown/math-promoter.ts
index bd79424c7..a5b511f25 100644
--- a/packages/core/src/markdown/math-promoter.ts
+++ b/packages/core/src/markdown/math-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Code, Root } from 'mdast';
import type { Math as MdastMath } from 'mdast-util-math';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
diff --git a/packages/core/src/markdown/mdast-to-hast-handlers.ts b/packages/core/src/markdown/mdast-to-hast-handlers.ts
index f84967798..679c72ef7 100644
--- a/packages/core/src/markdown/mdast-to-hast-handlers.ts
+++ b/packages/core/src/markdown/mdast-to-hast-handlers.ts
@@ -1,4 +1,3 @@
-
import type { Comment, Element, ElementContent, Properties } from 'hast';
import type { FootnoteDefinition, FootnoteReference } from 'mdast';
import type { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx';
diff --git a/packages/core/src/markdown/mdast-to-html.ts b/packages/core/src/markdown/mdast-to-html.ts
index df788a80d..8ce2b2492 100644
--- a/packages/core/src/markdown/mdast-to-html.ts
+++ b/packages/core/src/markdown/mdast-to-html.ts
@@ -1,4 +1,3 @@
-
import type { Element, Root as HastRoot, Text as HastText } from 'hast';
import type { Root as MdastRoot, Text as MdastText } from 'mdast';
import type { Handler } from 'mdast-util-to-hast';
diff --git a/packages/core/src/markdown/merged-walker.ts b/packages/core/src/markdown/merged-walker.ts
index fa3cfcd86..bfd7e3109 100644
--- a/packages/core/src/markdown/merged-walker.ts
+++ b/packages/core/src/markdown/merged-walker.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Parent, Root } from 'mdast';
import { SKIP, visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
diff --git a/packages/core/src/markdown/mermaid-promoter.ts b/packages/core/src/markdown/mermaid-promoter.ts
index 17ed2b829..1a897fca8 100644
--- a/packages/core/src/markdown/mermaid-promoter.ts
+++ b/packages/core/src/markdown/mermaid-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Code, Root } from 'mdast';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import { visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/parse-with-fallback.ts b/packages/core/src/markdown/parse-with-fallback.ts
index 7e4a9a48b..9864b3b60 100644
--- a/packages/core/src/markdown/parse-with-fallback.ts
+++ b/packages/core/src/markdown/parse-with-fallback.ts
@@ -168,7 +168,6 @@ export function parseRecursive(
}
}
-
interface VFilePlace {
offset?: number;
start?: { offset?: number };
@@ -187,7 +186,6 @@ function extractErrorOffset(err: unknown): number | undefined {
return undefined;
}
-
interface Region {
start: number;
end: number;
@@ -211,7 +209,6 @@ function nearestBlankLineAfter(src: string, offset: number): number | null {
return null;
}
-
export interface TagEvent {
kind: 'open' | 'close' | 'self-close';
name: string;
@@ -358,7 +355,6 @@ function findFallbackRegion(src: string, errorOffset: number): Region {
return { start: blockStart, end: blockEnd };
}
-
interface SourceBlock {
src: string;
start: number;
@@ -456,7 +452,6 @@ function tryPerBlockFallback(
};
}
-
function wholeDocRawText(source: string): JSONContent {
return {
type: 'doc',
diff --git a/packages/core/src/markdown/parser-drop-closure.ts b/packages/core/src/markdown/parser-drop-closure.ts
index 43d420187..e6ab4fd57 100644
--- a/packages/core/src/markdown/parser-drop-closure.ts
+++ b/packages/core/src/markdown/parser-drop-closure.ts
@@ -1,4 +1,3 @@
-
export type DroppedTokenAdjudication =
| {
kind: 'format-dof-axis';
diff --git a/packages/core/src/markdown/pipeline.ts b/packages/core/src/markdown/pipeline.ts
index e9e507469..7f2d5adca 100644
--- a/packages/core/src/markdown/pipeline.ts
+++ b/packages/core/src/markdown/pipeline.ts
@@ -1,4 +1,3 @@
-
import {
type FromProseMirrorOptions,
fromProseMirror,
diff --git a/packages/core/src/markdown/position-aware-join.ts b/packages/core/src/markdown/position-aware-join.ts
index f8f5e8530..5a5e4c42a 100644
--- a/packages/core/src/markdown/position-aware-join.ts
+++ b/packages/core/src/markdown/position-aware-join.ts
@@ -1,4 +1,3 @@
-
import type { Join } from 'mdast-util-to-markdown';
import type { Position } from 'unist';
diff --git a/packages/core/src/markdown/position-slice.ts b/packages/core/src/markdown/position-slice.ts
index e5b4c9eba..0f399d34c 100644
--- a/packages/core/src/markdown/position-slice.ts
+++ b/packages/core/src/markdown/position-slice.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Root } from 'mdast';
import { visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
@@ -477,8 +476,7 @@ export function applyPositionSliceToNode(
const first = source[startOff];
if (first !== '[' && first !== '<' && !node.title) {
node.data.sourceStyle = 'gfm-autolink';
- }
- else if (first === '[') {
+ } else if (first === '[') {
const slice = source.slice(startOff, endOff);
const closeBracketIdx = slice.lastIndexOf('](');
if (closeBracketIdx !== -1) {
diff --git a/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts b/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts
index ca225ce9b..db10fa54b 100644
--- a/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts
+++ b/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts
@@ -1,4 +1,3 @@
-
import type { Comment, Element, Root, Text } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts b/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts
index 3a2524a9a..34068d103 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts
@@ -1,4 +1,3 @@
-
import type { Element, ElementContent, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts b/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts
index 2279a0189..93151d43b 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts
@@ -1,4 +1,3 @@
-
import type { Element, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts b/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts
index a0f467c42..188f02d83 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts
@@ -1,4 +1,3 @@
-
import type { Element, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts b/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts
index 4e8542a21..4ba2c3418 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts
@@ -1,4 +1,3 @@
-
import type { Element, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts b/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts
index a3c96b24a..1a74b1272 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts
@@ -1,4 +1,3 @@
-
import type { Element, ElementContent, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts b/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts
index e95cf43d6..de35e7b79 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts
@@ -1,4 +1,3 @@
-
import type { Comment, Element, ElementContent, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts b/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts
index ffdb4d5b5..b4be1b2ea 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts
@@ -1,4 +1,3 @@
-
import type { Element, ElementContent, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts b/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts
index e2a96d1a7..3c8d88b7c 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts
@@ -1,4 +1,3 @@
-
import type { Element, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/resolve-image-url.ts b/packages/core/src/markdown/resolve-image-url.ts
index 0389575ac..cf2c9da8e 100644
--- a/packages/core/src/markdown/resolve-image-url.ts
+++ b/packages/core/src/markdown/resolve-image-url.ts
@@ -1,4 +1,3 @@
-
import { isRelativeUrl } from './safe-url.ts';
function isDevDiagnosticContext(): boolean {
diff --git a/packages/core/src/markdown/safe-url.ts b/packages/core/src/markdown/safe-url.ts
index 8be632ba4..4d3250d3a 100644
--- a/packages/core/src/markdown/safe-url.ts
+++ b/packages/core/src/markdown/safe-url.ts
@@ -1,4 +1,3 @@
-
export const SAFE_URL_SCHEMES = ['https', 'http', 'mailto', 'tel', 'ftp', 'sms'] as const;
const SCHEME_ALT = SAFE_URL_SCHEMES.map((s) => `${s}:`).join('|');
diff --git a/packages/core/src/markdown/serialize-helpers.ts b/packages/core/src/markdown/serialize-helpers.ts
index 542204403..46cc6a074 100644
--- a/packages/core/src/markdown/serialize-helpers.ts
+++ b/packages/core/src/markdown/serialize-helpers.ts
@@ -1,4 +1,3 @@
-
import type { Node as PmNode } from '@tiptap/pm/model';
import type { MdxJsxAttribute, MdxJsxExpressionAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import type { PropDef, SerializeContext } from '../registry/types.ts';
diff --git a/packages/core/src/markdown/single-dollar-math-promoter.ts b/packages/core/src/markdown/single-dollar-math-promoter.ts
index fe73659e6..be97d4d62 100644
--- a/packages/core/src/markdown/single-dollar-math-promoter.ts
+++ b/packages/core/src/markdown/single-dollar-math-promoter.ts
@@ -1,4 +1,3 @@
-
import type { PhrasingContent, Root, Text } from 'mdast';
import type { InlineMath } from 'mdast-util-math';
import { SKIP, visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/to-markdown-handlers.ts b/packages/core/src/markdown/to-markdown-handlers.ts
index 7bce04302..8f4e9a41c 100644
--- a/packages/core/src/markdown/to-markdown-handlers.ts
+++ b/packages/core/src/markdown/to-markdown-handlers.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Parents } from 'mdast';
import type { MdxJsxAttribute, MdxJsxExpressionAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import type { Handle, Info, State } from 'mdast-util-to-markdown';
diff --git a/packages/core/src/markdown/unknown-mdast-guard.ts b/packages/core/src/markdown/unknown-mdast-guard.ts
index c5bfd2386..cd245c38c 100644
--- a/packages/core/src/markdown/unknown-mdast-guard.ts
+++ b/packages/core/src/markdown/unknown-mdast-guard.ts
@@ -1,4 +1,3 @@
-
import type { Root as MdastRoot } from 'mdast';
import type { VFile } from 'vfile';
diff --git a/packages/core/src/markdown/whitespace-char-ref.ts b/packages/core/src/markdown/whitespace-char-ref.ts
index ac9f5239b..d578476a7 100644
--- a/packages/core/src/markdown/whitespace-char-ref.ts
+++ b/packages/core/src/markdown/whitespace-char-ref.ts
@@ -1,4 +1,3 @@
-
const INLINE_WHITESPACE_BY_CODE: ReadonlyMap<number, string> = new Map([
[0x20, ' '],
[0x09, '\t'],
diff --git a/packages/core/src/markdown/wiki-link-micromark.ts b/packages/core/src/markdown/wiki-link-micromark.ts
index afd9936fe..6dad26200 100644
--- a/packages/core/src/markdown/wiki-link-micromark.ts
+++ b/packages/core/src/markdown/wiki-link-micromark.ts
@@ -17,7 +17,6 @@ declare module 'micromark-util-types' {
}
}
-
const CODE_BANG = 33; // !
const CODE_LBRACKET = 91; // [
const CODE_RBRACKET = 93; // ]
@@ -261,7 +260,6 @@ export function wikiLinkSyntax(): Extension {
};
}
-
function enterWikiLink(this: CompileContext, token: Token) {
this.enter(
{
@@ -387,7 +385,6 @@ export const wikiLinkToMarkdown: {
unsafe: [{ character: '[', inConstruct: ['phrasing'] }],
};
-
const MICROMARK_EXT = wikiLinkSyntax();
export function remarkWikiLink(this: Processor) {
diff --git a/packages/desktop/electron-builder.yml b/packages/desktop/electron-builder.yml
index 0079040f9..c6243edad 100644
--- a/packages/desktop/electron-builder.yml
+++ b/packages/desktop/electron-builder.yml
@@ -324,6 +324,18 @@ protocols:
schemes: [openknowledge]
role: Editor
+# Finder "Open With → OpenKnowledge" for loose markdown files. `role: Editor`
+# advertises us as an editor of these types; `rank: Alternate` means we do NOT
+# steal the user's default handler (their existing editor keeps the
+# double-click) — we only appear in the Open With list. macOS delivers the pick
+# via the `open-file` Apple Event, which `registerProtocolHandler` routes
+# through the same queue-then-flush spine as `ok <file>` (see main/url-scheme.ts).
+fileAssociations:
+ - ext: [md, mdx]
+ name: Markdown Document
+ role: Editor
+ rank: Alternate
+
publish:
- provider: github
owner: inkeep
diff --git a/packages/desktop/src/main/dialog-helpers.test.ts b/packages/desktop/src/main/dialog-helpers.test.ts
index 907a9cdb4..4da512b5d 100644
--- a/packages/desktop/src/main/dialog-helpers.test.ts
+++ b/packages/desktop/src/main/dialog-helpers.test.ts
@@ -5,7 +5,11 @@
* bypass the real picker.
*/
import { afterEach, beforeEach, describe, expect, mock, test } from 'bun:test';
-import { promptForExistingFolder, resolvePickedPathForIndex } from './dialog-helpers.ts';
+import {
+ promptForExistingFolder,
+ promptForExistingMarkdownFile,
+ resolvePickedPathForIndex,
+} from './dialog-helpers.ts';
const ORIGINAL_SMOKE = process.env.OK_DESKTOP_E2E_SMOKE;
const ORIGINAL_PICKED = process.env.OK_DESKTOP_TEST_PICKED_PATH;
@@ -121,3 +125,48 @@ describe('resolvePickedPathForIndex', () => {
expect(resolvePickedPathForIndex(' \x1f/real', 1)).toBe('/real');
});
});
+
+describe('promptForExistingMarkdownFile', () => {
+ beforeEach(() => {
+ delete process.env.OK_DESKTOP_E2E_SMOKE;
+ delete process.env.OK_DESKTOP_TEST_PICKED_PATH;
+ });
+
+ test('OS picker uses openFile + a md/mdx filter', async () => {
+ const showOpenDialog = mock(async () => ({ canceled: false, filePaths: ['/notes/x.md'] }));
+ const result = await promptForExistingMarkdownFile({ showOpenDialog });
+ expect(result).toBe('/notes/x.md');
+ expect(showOpenDialog).toHaveBeenCalledWith({
+ properties: ['openFile'],
+ filters: [{ name: 'Markdown', extensions: ['md', 'mdx'] }],
+ });
+ });
+
+ test('OS picker returns null on cancel', async () => {
+ const showOpenDialog = mock(async () => ({ canceled: true, filePaths: [] }));
+ expect(await promptForExistingMarkdownFile({ showOpenDialog })).toBe(null);
+ });
+
+ test('OS picker returns null on empty filePaths', async () => {
+ const showOpenDialog = mock(async () => ({ canceled: false, filePaths: [] }));
+ expect(await promptForExistingMarkdownFile({ showOpenDialog })).toBe(null);
+ });
+
+ test('test seam returns env path when both gates set, never calls OS picker', async () => {
+ process.env.OK_DESKTOP_E2E_SMOKE = '1';
+ process.env.OK_DESKTOP_TEST_PICKED_PATH = '/tmp/seam.md';
+ const showOpenDialog = mock(async () => ({ canceled: false, filePaths: ['/never/used.md'] }));
+ expect(await promptForExistingMarkdownFile({ showOpenDialog })).toBe('/tmp/seam.md');
+ expect(showOpenDialog).not.toHaveBeenCalled();
+ });
+
+ test('defaultPath threads through to showOpenDialog', async () => {
+ const showOpenDialog = mock(async () => ({ canceled: false, filePaths: ['/notes/x.md'] }));
+ await promptForExistingMarkdownFile({ showOpenDialog }, { defaultPath: '/notes' });
+ expect(showOpenDialog).toHaveBeenCalledWith({
+ properties: ['openFile'],
+ filters: [{ name: 'Markdown', extensions: ['md', 'mdx'] }],
+ defaultPath: '/notes',
+ });
+ });
+});
diff --git a/packages/desktop/src/main/dialog-helpers.ts b/packages/desktop/src/main/dialog-helpers.ts
index 8b9e0bb03..0b32bf1ee 100644
--- a/packages/desktop/src/main/dialog-helpers.ts
+++ b/packages/desktop/src/main/dialog-helpers.ts
@@ -22,10 +22,12 @@ interface DialogLike {
| 'showHiddenFiles'
)[];
defaultPath?: string;
+ filters?: { name: string; extensions: string[] }[];
}): Promise<{ canceled: boolean; filePaths: string[] }>;
}
-interface PromptForFolderOpts {
+/** Options shared by the folder + markdown-file pickers below. */
+interface PromptForPickerOpts {
/** Initial directory shown in the picker. Pass the project root so the user
* doesn't have to navigate to it. */
defaultPath?: string;
@@ -115,7 +117,7 @@ function readTestPickedPath(): string | null {
*/
export async function promptForExistingFolder(
dialogModule: DialogLike,
- opts: PromptForFolderOpts = {},
+ opts: PromptForPickerOpts = {},
): Promise<string | null> {
const testSeam = readTestPickedPath();
if (testSeam !== null) return testSeam;
@@ -126,3 +128,28 @@ export async function promptForExistingFolder(
if (result.canceled) return null;
return result.filePaths[0] ?? null;
}
+
+/**
+ * Prompt for a single existing markdown file (File → Open file… and the
+ * `ok:project:open-file-picker` IPC both call this). Filtered to `.md`/`.mdx`
+ * so the picker steers users to markdown, but the filter is advisory: the
+ * receiver (`openEphemeralFile`) re-validates the pick and renders a native
+ * error for a non-markdown / missing file. Colocated with `promptForExistingFolder`
+ * so the two Open-… affordances share one definition of their dialog options.
+ * Routes through the same E2E test seam so smoke tests can drive the picked
+ * path without an OS dialog.
+ */
+export async function promptForExistingMarkdownFile(
+ dialogModule: DialogLike,
+ opts: PromptForPickerOpts = {},
+): Promise<string | null> {
+ const testSeam = readTestPickedPath();
+ if (testSeam !== null) return testSeam;
+ const result = await dialogModule.showOpenDialog({
+ properties: ['openFile'],
+ filters: [{ name: 'Markdown', extensions: ['md', 'mdx'] }],
+ ...(opts.defaultPath !== undefined ? { defaultPath: opts.defaultPath } : {}),
+ });
+ if (result.canceled) return null;
+ return result.filePaths[0] ?? null;
+}
diff --git a/packages/desktop/src/main/index.ts b/packages/desktop/src/main/index.ts
index 066eb00ec..8f0e9777e 100644
--- a/packages/desktop/src/main/index.ts
+++ b/packages/desktop/src/main/index.ts
@@ -207,7 +207,7 @@ import {
resolveDesktopUninstallProjectSelection,
runDesktopUninstallCleanup,
} from './desktop-uninstall.ts';
-import { promptForExistingFolder } from './dialog-helpers.ts';
+import { promptForExistingFolder, promptForExistingMarkdownFile } from './dialog-helpers.ts';
import {
type DriverUtilityLike,
isDriverBootSmokeMode,
@@ -2257,6 +2257,10 @@ async function runApplicationMenuRefresh(): Promise<void> {
dialog,
openNavigator,
openProject: (path, entryPoint) => openProjectOrFallbackToNavigator(path, entryPoint),
+ // File → Open file… — the picker runs in the menu binding (menu.ts), which
+ // hands the absolute path here. `openEphemeralFile` re-derives project-vs-
+ // ephemeral (a file inside a project opens that project, not a temp session).
+ openEphemeralFile: (filePath) => openEphemeralFile(filePath),
getRecentProjects: () => appState.recentProjects,
clearRecentProjects: () => {
appState = { ...appState, recentProjects: [] };
@@ -3476,6 +3480,16 @@ function registerIpcHandlers() {
return promptForExistingFolder(dialog, opts);
});
+ // File → Open file… (palette / Navigator entry). Picker + ephemeral open both
+ // run main-side, mirroring the native-menu binding in menu.ts; the picked path
+ // never crosses back to the renderer. Shares `promptForExistingMarkdownFile`
+ // with the menu binding so both agree on the picker's filters.
+ handle('ok:project:open-file-picker', async () => {
+ const picked = await promptForExistingMarkdownFile(dialog);
+ if (picked) await openEphemeralFile(picked);
+ return undefined;
+ });
+
const shellOpenExternal = handleShellOpenExternal({
openExternal: (url) => shell.openExternal(url),
});
diff --git a/packages/desktop/src/main/menu.ts b/packages/desktop/src/main/menu.ts
index 164905a17..e17327384 100644
--- a/packages/desktop/src/main/menu.ts
+++ b/packages/desktop/src/main/menu.ts
@@ -46,7 +46,7 @@ import {
import type { Dialog, MenuItemConstructorOptions } from 'electron';
import type { EntryPoint } from '../shared/entry-point.ts';
import type { EditorActiveTargetSnapshot } from '../shared/ipc-channels.ts';
-import { promptForExistingFolder } from './dialog-helpers.ts';
+import { promptForExistingFolder, promptForExistingMarkdownFile } from './dialog-helpers.ts';
export interface MenuDeps {
/** `app.name` — the running app's name, used for the macOS App menu label. */
@@ -69,6 +69,15 @@ export interface MenuDeps {
* can branch on user intent.
*/
openProject(projectPath: string, entryPoint: EntryPoint): Promise<void>;
+ /**
+ * File → Open file… click handler target — open a loose markdown file in a
+ * temporary single-file session (`openEphemeralFile`, the desktop side of
+ * `ok <file>`). The menu binding shows the native md/mdx picker via
+ * `promptForExistingMarkdownFile(d.dialog)` first, so this receives an
+ * absolute path. Optional because the menu is also built in deps-unwired unit
+ * tests; production `index.ts` always wires it.
+ */
+ openEphemeralFile?(filePath: string): Promise<void>;
/** Current recent-projects list (top-of-LRU first). Used to build Recent project submenu. */
getRecentProjects(): ReadonlyArray<{ path: string; name: string }>;
/** Clear the recent-projects list (File → Recent project → Clear menu). */
@@ -373,6 +382,8 @@ const MENU_BINDINGS: Record<string, MenuCommandBinding> = {
enabled: (d) => d.onNewProject !== undefined,
},
// Switch project / Open folder are always enabled — their deps are required.
+ // Open file (below) is the exception: it gates on `openEphemeralFile`, which is
+ // optional so deps-unwired unit tests can build the menu (always wired in production).
'switch-project': { click: (d) => () => d.openNavigator() },
'open-folder': {
click: (d) => async () => {
@@ -384,6 +395,18 @@ const MENU_BINDINGS: Record<string, MenuCommandBinding> = {
}
},
},
+ 'open-file': {
+ click: (d) => async () => {
+ // Shared picker options with the `ok:project:open-file-picker` IPC handler
+ // (see dialog-helpers). `openEphemeralFile` re-derives project-vs-ephemeral,
+ // so a file inside a project opens that project rather than a temp session.
+ const picked = await promptForExistingMarkdownFile(d.dialog);
+ if (picked) {
+ await d.openEphemeralFile?.(picked);
+ }
+ },
+ enabled: (d) => d.openEphemeralFile !== undefined,
+ },
'new-worktree': {
click: (d) => () => d.onNewWorktree?.(),
enabled: (d) => d.onNewWorktree !== undefined,
diff --git a/packages/desktop/src/main/url-scheme.ts b/packages/desktop/src/main/url-scheme.ts
index 9070bd04a..ce8833db9 100644
--- a/packages/desktop/src/main/url-scheme.ts
+++ b/packages/desktop/src/main/url-scheme.ts
@@ -497,6 +497,10 @@ interface ProtocolHandlerDeps {
/** `electron.app` subset — the listeners + setters we touch. */
app: {
on(event: 'open-url', cb: (event: { preventDefault: () => void }, url: string) => void): void;
+ // macOS Finder "Open With → OpenKnowledge" (and double-click on a handled
+ // file type). Fires only on darwin; can arrive before `whenReady` on a cold
+ // launch, so the listener is wired synchronously alongside `open-url`.
+ on(event: 'open-file', cb: (event: { preventDefault: () => void }, path: string) => void): void;
on(event: 'second-instance', cb: (event: unknown, argv: readonly string[]) => void): void;
on(event: 'before-quit', cb: () => void): void;
// macOS Handoff / Universal Links: `details.webpageURL` carries the
@@ -1295,6 +1299,19 @@ export function registerProtocolHandler(deps: ProtocolHandlerDeps): ProtocolHand
enqueueOrRoute(url);
});
+ // `open-file` — macOS Apple Event fired when the user opens a `.md`/`.mdx`
+ // via Finder ("Open With → OpenKnowledge", or a double-click on a file type
+ // we handle). Synthesize the same `openknowledge://open?file=<abs>` URL the
+ // CLI emits for `ok <file>` and route it through the identical queue-then-
+ // flush + launch-claim spine, so a cold-launch Finder open suppresses the
+ // boot-restore window exactly like `ok <file>` does. macOS-only — the event
+ // never fires on other platforms. `encodeURIComponent` matches the CLI's
+ // construction (`parseOpenKnowledgeFileUrl` decodes once via `searchParams`).
+ deps.app.on('open-file', (event, filePath) => {
+ event.preventDefault();
+ enqueueOrRoute(`openknowledge://open?file=${encodeURIComponent(filePath)}`);
+ });
+
// `continue-activity` — macOS Handoff path for Universal Links. Fires when
// the user taps `https://openknowledge.ai/d/<encoded>` in Slack/iMessage
// (or any AASA-eligible surface) and the OS routes the activity into OK.
diff --git a/packages/desktop/src/preload/index.ts b/packages/desktop/src/preload/index.ts
index a796aeadf..545925e77 100644
--- a/packages/desktop/src/preload/index.ts
+++ b/packages/desktop/src/preload/index.ts
@@ -421,6 +421,7 @@ const bridge: OkDesktopBridge = {
getSessionState: () => invoke('ok:project:get-session-state'),
setSessionState: (state) => invoke('ok:project:set-session-state', state),
open: (request) => invoke('ok:project:open', request),
+ openFile: () => invoke('ok:project:open-file-picker'),
createNew: (args) => invoke('ok:project:create-new', args),
recordCreateNewBannerShown: (banner) =>
invoke('ok:project:record-create-new-banner-shown', banner),
diff --git a/packages/desktop/src/shared/bridge-contract.ts b/packages/desktop/src/shared/bridge-contract.ts
index e3cdfc49a..d21fe1bc0 100644
--- a/packages/desktop/src/shared/bridge-contract.ts
+++ b/packages/desktop/src/shared/bridge-contract.ts
@@ -1319,6 +1319,15 @@ export interface OkDesktopBridge {
currentBranch: string | null;
};
}): Promise<void>;
+ /**
+ * File → Open file… — show the native md/mdx picker and open the pick in a
+ * temporary single-file session (the desktop side of `ok <file>`; no project
+ * setup, never writes `.ok` to the file's folder). Picker + open both run
+ * main-side (`openEphemeralFile` owns the temp server/dir lifecycle), so
+ * this takes no args and returns nothing — the picked path never crosses
+ * back to the renderer. A cancelled picker resolves as a no-op.
+ */
+ openFile(): Promise<void>;
/**
* Atomically scaffold a new project under `parent/name` with the
* user-chosen `editors` set. `editors` is the renderer's exact selection
diff --git a/packages/desktop/src/shared/ipc-channels.ts b/packages/desktop/src/shared/ipc-channels.ts
index bb2e22af5..12e77612a 100644
--- a/packages/desktop/src/shared/ipc-channels.ts
+++ b/packages/desktop/src/shared/ipc-channels.ts
@@ -30,7 +30,7 @@
* existing channels is preferred over net-new hand-rolled channels until
* that migration lands.
*
- * Count is 85 (ratchet cap 85). The 74→75 bump reconciled a merge collision:
+ * Count is 86 (ratchet cap 86). The 74→75 bump reconciled a merge collision:
* the worktree selector (`ok:worktree:dispatch`) and the terminal-controls PR
* (`ok:terminal:cli-installed-map`) each landed in the base tree's single free
* slot concurrently. The 75→76 bump then unioned in the desktop
@@ -53,7 +53,11 @@
* added the two Cmd+K / native-menu command invokes: `ok:mcp-wiring:reconfigure`
* (File → "Set up OpenKnowledge integrations…") and `ok:spellcheck:toggle`
* (Edit → "Check spelling while typing"), each delegating to an existing
- * main-side function. Full rationale in the ratchet test header.
+ * main-side function. The 85→86 bump added File → "Open file…"
+ * (`ok:project:open-file-picker`): the palette / Navigator entry point to the
+ * temporary single-file session, delegating to the existing main-side picker +
+ * `openEphemeralFile` (the desktop side of `ok <file>`). Full rationale in the
+ * ratchet test header.
*/
import type {
@@ -854,6 +858,13 @@ export interface RequestChannels {
'ok:project:set-session-state': { args: [state: ProjectSessionState]; result: undefined };
/** Request main to open a project (always spawns a new editor window). */
'ok:project:open': { args: [request: ProjectOpenRequest]; result: undefined };
+ /**
+ * File → Open file… palette / Navigator entry: show the native md/mdx picker
+ * and open the pick in a temporary single-file session (the desktop side of
+ * `ok <file>`). Picker + `openEphemeralFile` both run main-side, so no picked
+ * path crosses back to the renderer — the channel is a void fire-and-forget.
+ */
+ 'ok:project:open-file-picker': { args: []; result: undefined };
/**
* Probe `<projectPath>/<path>` and classify it against the share target's
* `kind` — a regular-file hit for `doc`, a directory hit for `folder` —
diff --git a/packages/desktop/tests/integration/ipc-channel-count-ratchet.test.ts b/packages/desktop/tests/integration/ipc-channel-count-ratchet.test.ts
index 1a911af61..08f864260 100644
--- a/packages/desktop/tests/integration/ipc-channel-count-ratchet.test.ts
+++ b/packages/desktop/tests/integration/ipc-channel-count-ratchet.test.ts
@@ -346,8 +346,14 @@ const CHANNELS_SRC = readFileSync(SRC_PATH, 'utf-8');
* and `ok:spellcheck:toggle` (Edit → "Check spelling while typing"). Each
* delegates to an existing main-side function; the typed-ipc migration remains
* the committed end state, with the `ipc-channels.ts` header in lock-step.
+ *
+ * Bumped from 85 to 86 for File → "Open file…" (`ok:project:open-file-picker`):
+ * the palette / Navigator entry point to the temporary single-file session,
+ * delegating to the existing main-side picker + `openEphemeralFile` (the
+ * desktop side of `ok <file>`). Single member; the typed-ipc migration remains
+ * the committed end state, with the `ipc-channels.ts` header in lock-step.
*/
-const REQUEST_CHANNEL_CAP = 85;
+const REQUEST_CHANNEL_CAP = 86;
/**
* Extract the body of an interface block by name. Returns the substring
diff --git a/packages/desktop/tests/main/url-scheme-handler.test.ts b/packages/desktop/tests/main/url-scheme-handler.test.ts
index edd4935a4..8796eed28 100644
--- a/packages/desktop/tests/main/url-scheme-handler.test.ts
+++ b/packages/desktop/tests/main/url-scheme-handler.test.ts
@@ -18,8 +18,9 @@ import { parseOpenKnowledgeFileUrl, registerProtocolHandler } from '../../src/ma
* stub.
*/
-type AppEvent = 'open-url' | 'second-instance' | 'before-quit' | 'continue-activity';
+type AppEvent = 'open-url' | 'open-file' | 'second-instance' | 'before-quit' | 'continue-activity';
type OpenUrlListener = (event: { preventDefault: () => void }, url: string) => void;
+type OpenFileListener = (event: { preventDefault: () => void }, path: string) => void;
type SecondInstanceListener = (event: unknown, argv: readonly string[]) => void;
type BeforeQuitListener = () => void;
type ContinueActivityListener = (
@@ -30,6 +31,7 @@ type ContinueActivityListener = (
) => void;
type AppListener =
| OpenUrlListener
+ | OpenFileListener
| SecondInstanceListener
| BeforeQuitListener
| ContinueActivityListener;
@@ -41,6 +43,7 @@ interface FakeApp {
setAsDefaultProtocolClient: ReturnType<typeof mock>;
removeAsDefaultProtocolClient: ReturnType<typeof mock>;
fireOpenUrl: (url: string) => void;
+ fireOpenFile: (path: string) => { preventDefault: ReturnType<typeof mock> };
fireSecondInstance: (argv: readonly string[]) => void;
fireBeforeQuit: () => void;
fireContinueActivity: (
@@ -73,6 +76,13 @@ function makeFakeApp(opts?: { isPackaged?: boolean }): FakeApp {
const event = { preventDefault: mock(() => {}) };
cb(event, url);
},
+ fireOpenFile: (path) => {
+ const cb = listeners.get('open-file') as OpenFileListener | undefined;
+ if (!cb) throw new Error('open-file listener not registered');
+ const event = { preventDefault: mock(() => {}) };
+ cb(event, path);
+ return event;
+ },
fireSecondInstance: (argv) => {
const cb = listeners.get('second-instance') as SecondInstanceListener | undefined;
if (!cb) throw new Error('second-instance listener not registered');
@@ -2436,3 +2446,87 @@ describe('registerProtocolHandler — single-file open (file=)', () => {
expect(env.openProject).not.toHaveBeenCalled();
});
});
+
+// Finder "Open With → OpenKnowledge" (and double-click on a handled type)
+// delivers the picked file via the macOS `open-file` Apple Event. The handler
+// synthesizes the same `open?file=` URL as `ok <file>` and routes it through
+// the shared queue-then-flush spine, so a warm open lands immediately and a
+// cold-launch open queues until whenReady — parity with the deep-link path.
+describe('registerProtocolHandler — open-file Apple event (Finder Open With)', () => {
+ let env: TestEnv;
+
+ beforeEach(() => {
+ env = makeEnv();
+ });
+
+ test('a warm open-file event routes to openEphemeralFile with the raw path + calls preventDefault', async () => {
+ env.readyWindow = { id: 'pre-existing' };
+ registerProtocolHandler({
+ app: env.app,
+ focusWindowForProject: env.focusWindowForProject,
+ openProject: env.openProject,
+ openEphemeralFile: env.openEphemeralFile,
+ sendDeepLink: env.sendDeepLink,
+ getAnyReadyWindow: env.getAnyReadyWindow,
+ setTimeout: (cb, ms) => env.timers.push({ cb, ms }),
+ });
+ env.app.resolveReady();
+ await flushPromises();
+
+ const event = env.app.fireOpenFile('/Users/me/notes/todo.md');
+ await flushPromises();
+
+ // preventDefault silences Electron's default stderr log + signals handled.
+ expect(event.preventDefault).toHaveBeenCalled();
+ expect(env.openEphemeralFile).toHaveBeenCalledWith('/Users/me/notes/todo.md');
+ expect(env.openProject).not.toHaveBeenCalled();
+ });
+
+ test('a path with spaces/special chars round-trips through the synthesized file= URL', async () => {
+ env.readyWindow = { id: 'pre-existing' };
+ registerProtocolHandler({
+ app: env.app,
+ focusWindowForProject: env.focusWindowForProject,
+ openProject: env.openProject,
+ openEphemeralFile: env.openEphemeralFile,
+ sendDeepLink: env.sendDeepLink,
+ getAnyReadyWindow: env.getAnyReadyWindow,
+ setTimeout: (cb, ms) => env.timers.push({ cb, ms }),
+ });
+ env.app.resolveReady();
+ await flushPromises();
+
+ // A `#`/space/`&` path would corrupt an un-encoded URL; the handler's
+ // encodeURIComponent + `searchParams` decode must hand back the exact path.
+ const messy = '/Users/me/My Notes/draft #1 & more.md';
+ env.app.fireOpenFile(messy);
+ await flushPromises();
+
+ expect(env.openEphemeralFile).toHaveBeenCalledWith(messy);
+ });
+
+ test('a cold-launch open-file (before whenReady) queues, then drains to openEphemeralFile', async () => {
+ // No ready window yet — a Finder cold launch fires open-file before the
+ // first window paints; the event must queue and route once ready.
+ registerProtocolHandler({
+ app: env.app,
+ focusWindowForProject: env.focusWindowForProject,
+ openProject: env.openProject,
+ openEphemeralFile: env.openEphemeralFile,
+ sendDeepLink: env.sendDeepLink,
+ getAnyReadyWindow: env.getAnyReadyWindow,
+ setTimeout: (cb, ms) => env.timers.push({ cb, ms }),
+ });
+
+ env.app.fireOpenFile('/Users/me/notes/todo.md');
+ // Not flushed yet — routing is deferred until whenReady drains the queue.
+ expect(env.openEphemeralFile).not.toHaveBeenCalled();
+
+ env.readyWindow = { id: 'pre-existing' };
+ env.app.resolveReady();
+ await flushPromises();
+ await flushPromises();
+
+ expect(env.openEphemeralFile).toHaveBeenCalledWith('/Users/me/notes/todo.md');
+ });
+});