Skip to main content

@ai-coach/vault-adapter-fs

The vault's files on your disk. createFsNoteStore(root) is the NoteStore the vault reads and writes through; it is the only code that opens vault files. The package also decides which folder is your vault, and makes note versions and new ids. You change it when the vault's file handling or root resolution changes.

What it does not do​

  • No vault rules. Which notes go where, previews and version checks live in vault-application; this package only lists, reads, writes and moves files.
  • No following symlinks. A symlinked folder is listed as neither file nor folder, so a scan never leaves the vault.
  • Only Node built-ins. Nx boundaries (adapter:vault-fs) allow node:* imports and no npm package.

Architecture fit​

  • Scope: scope:vault
  • Style: architecture:hexagonal (type:adapter, adapter:vault-fs)
  • Depends on: @ai-coach/vault-application (the NoteStore port)
  • Used by: @ai-coach/vault-mcp-server, @ai-coach/vault-view-server (their composition roots)
[server compose.ts] ──▶ resolveVaultForProcess ──▶ vault root
└─▶ createFsNoteStore(root) ──implements──▶ NoteStore ──▶ node:fs

Internal architecture & rules​

  • fs-store.ts implements NoteStore on node:fs, async only.
  • It never overwrites by accident. A new note is created only if nothing is there, and a move links the file to its new place before removing the old one.
  • root.ts and process-root.ts resolve the vault: --vault, else DOCS_MCP_VAULT, else vault.root in ~/.config/docs-mcp/config.json. A vault inside a folder with a reasonry.config.json or docs-mcp.config.json (a knowledge-base workspace) is refused.
  • node-crypto.ts gives sha256Hex for note versions and randomHex for new ids.
  • No comments in source code (DEC-AIC-0011).

Public surface​

  • createFsNoteStore — the NoteStore passed to createVault as deps.store.
  • resolveVaultForProcess, resolveVaultRoot, parseVaultFlags, parseViewFlags — find the vault from flags, environment and config.
  • sha256Hex, randomHex — passed to createVault as deps.digest and deps.randomHex.

How you point the servers at your vault is in the configuration guide.

How to extend it​

  1. Change the NoteStore port in vault-application first if the store needs a new operation.
  2. Implement it in src/lib/fs-store.ts, keeping writes refuse-if-present and moves link-then-unlink.
  3. Cover it in src/lib/fs-store.spec.ts against a temporary directory.
  4. Run npm exec nx test @ai-coach/vault-adapter-fs and npm exec nx lint @ai-coach/vault-adapter-fs.

Running & testing​

npm exec nx test @ai-coach/vault-adapter-fs
npm exec nx lint @ai-coach/vault-adapter-fs
npm exec nx typecheck @ai-coach/vault-adapter-fs
npm exec nx build @ai-coach/vault-adapter-fs

Each spec runs against its own temporary directory, never a real vault.

Key ADRs​

  • DEC-AIC-0052 — defines the async NoteStore port and keeps node:fs in this adapter.
  • DEC-AIC-0061 — both vault servers compose this store and resolve the vault the same way.
  • DEC-AIC-0051 — one adapter per outside dependency, each with its own import whitelist.