@mnemosyne_os/affine-reader
v0.1.8
Published
Read a local AFFiNE workspace (SQLite + Yjs) and render its documents to Markdown. No BlockSuite at runtime, no native module, read-only.
Maintainers
Readme
@mnemosyne_os/affine-reader: Read a local AFFiNE workspace (SQLite + Yjs) and render its documents to Markdown. No BlockSuite at runtime, no native module, read-only.
Product mnemosyne-os.io · Company, press and labs mnemosyne-os.com · Documentation docs.mnemosyne-os.io
@mnemosyne_os/affine-reader
Read a local AFFiNE workspace and render its documents to Markdown. AFFiNE does not need to run. No BlockSuite, no server.
Read-only, in every direction. Two processes writing one CRDT corrupt it. This package copies the database before it reads, and never writes back.
Quick start: one command
npx @mnemosyne_os/affine-reader ./outThis writes one Markdown file per document, plus its images, for every AFFiNE workspace on this machine. It needs Node 22.13+ or 23.4+ (see Bring your own SQLite).
Install
npm install @mnemosyne_os/affine-readerRuntime dependency: yjs. That is the whole list.
Use
import {
affineDataDir,
exportWorkspace,
findWorkspaces,
openNodeSqlite,
stageDatabase,
} from '@mnemosyne_os/affine-reader';
import { mkdtempSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
for (const ref of findWorkspaces()) {
const staged = stageDatabase(ref.dbPath, mkdtempSync(join(tmpdir(), 'affine-')));
const db = openNodeSqlite(staged.path);
try {
const result = exportWorkspace(db, `./out/${ref.id}`);
console.log(result.files, result.skipped);
} finally {
db.close();
staged.dispose();
}
}findWorkspaces() returning [] and affineDataDir() returning null are different
answers. The first says there is nothing to read. The second says AFFiNE is not
installed. Both are reported.
Bring your own SQLite
openNodeSqlite uses Node's built-in node:sqlite. It runs without a flag from
Node 22.13 and 23.4 onward, and exists from 22.5 behind --experimental-sqlite.
Electron 31 ships Node 20 and has none, so a host passes its own adapter:
import Database from 'better-sqlite3';
import { readWorkspace } from '@mnemosyne_os/affine-reader';
const raw = new Database(stagedPath);
readWorkspace({ prepare: (sql) => raw.prepare(sql), close: () => raw.close() });What it reads
| | |
|---|---|
| Location | <app-data>/AFFiNE*/<workspaces\|userspaces>/<peer>/<id>/storage.db |
| Channels | Every one you have installed. AFFiNE names the folder AFFiNE for a stable release, and AFFiNE-canary, AFFiNE-beta or AFFiNE-internal otherwise. Most of their releases are canary |
| Schema | nbstore v2 (snapshots + updates + blobs), and the legacy v1 shape |
| Content | Yjs history replayed into a document, rendered by AFFiNE's own MIT parser |
Headings, lists, checkboxes, bold and italic, links, code, tables, database views, LaTeX and images all survive the trip. Images come out as blob files, with links that point at them.
Two things that will bite you
The content may live in the -wal, not in storage.db. Measured on one running
0.27.4 install: at 14:28, storage.db was 4 KB next to a 1.8 MB -wal. At 14:46, same
app still running, the journal had been checkpointed away and storage.db was 1.14 MB
with no sidecar at all. A reader that copies only storage.db sees an empty
workspace in the first state and cannot tell. stageDatabase() copies the sidecars
when they exist and reports which ones it took.
A snapshot alone is stale. A document typed one minute earlier decoded to 2
characters from its snapshot row, and to 323 once its 16 updates rows were
replayed. Older documents give the same answer either way. A test written on those
passes while the reader loses everything the user just wrote. Every load here replays
the updates.
Your AFFiNE notes, searchable in Mnemosyne OS
This package was built for Mnemosyne OS, a memory system that runs on your own machine. Its desktop app uses this reader to bring an AFFiNE workspace into memory:
- Open Settings › Vaults › Import from AFFiNE.
- Choose a folder. Each document becomes one Markdown file, with its images.
- Point a vault at that folder. You can then ask the chat about your notes, or reach
them from Claude, Cursor or any MCP agent through
@mnemosyne_os/mcp.
AFFiNE itself is only read, never written to. Run the import again after you edit: renamed, deleted or trashed documents leave the folder too.
⬇ Download Mnemosyne OS
Free download for Windows, macOS and Linux
The @mnemosyne_os packages
All of them live under one npm organization: npmjs.com/org/mnemosyne_os
| Package | What it is |
|---|---|
| @mnemosyne_os/sdk | Build a Layer 2 app: a Node or browser process talking to the local WebSocket surface |
| @mnemosyne_os/create-app | npm create @mnemosyne_os/app scaffolds that Layer 2 app in one command |
| @mnemosyne_os/cartridge-sdk | Build an in-app cartridge: a sandboxed iframe widget rendered on the canvas |
| @mnemosyne_os/mcp | MCP server: plug Claude, Cursor or any MCP agent into the vaults |
| @mnemosyne_os/design-sdk | Skin the OS with JSON alone, no TypeScript |
| @mnemosyne_os/public-contracts | The shared types and Zod schemas. No business logic |
| @mnemosyne_os/agent-transcripts | Read what coding agents already write on disk: the connector format and the interpreter |
| @mnemosyne_os/affine-reader (you are here) | Read a local AFFiNE workspace and render its documents to Markdown |
| @mnemosyne_os/forge | CLI: scaffold, list chronicles, import and export |
| @mnemosyne_os/sync | The name of the P2P layer to come. A placeholder today, not the library |
Where Mnemosyne OS lives
Published by XPACEGEMS LLC. Its official addresses:
- Product site: https://mnemosyne-os.io
- Organizations: https://mnemosyne-os.com
- Documentation: https://docs.mnemosyne-os.io
- Source: https://github.com/Mnemosyne-OS/Mnemosyne-Neural-OS
- Packages: https://www.npmjs.com/org/mnemosyne_os
Licence
MIT © Tony Trochet / XPACEGEMS LLC. Includes MIT-licensed source vendored from AFFiNE, see NOTICE.md. BlockSuite (MPL-2.0) is not included and is not required at runtime.
