Skip to main content

@ai-coach/vault-application

Use cases and ports for the life vault. This package implements everything you can do with a vault: scanning notes, recording sparring sessions, filing notes, converting PDFs, distilling books, creating concepts, tracking the climb, planning periods, rolling over tasks, reviewing periods, and building view projections. Change this package when adding or modifying vault behavior.

What it does not do​

  • No direct disk, PDF, YAML, or network I/O. All external effects go through ports in VaultDeps (NoteStore, FrontmatterParser, SearchRanker, PdfReader, digest, randomHex).
  • No MCP transport, HTTP server, or CLI output. vault-mcp-server exposes these use cases over MCP and vault-view-server serves the browser UI.
  • No cross-scope imports. Nothing outside scope:vault may import this package.

Architecture fit​

  • Scope: scope:vault
  • Style: architecture:hexagonal (type:application)
  • Depends on: @ai-coach/vault-domain, @ai-coach/util-path
  • Used by: @ai-coach/vault-mcp-server, @ai-coach/vault-view-server, @ai-coach/vault-adapter-view, and the adapters that implement its ports (@ai-coach/vault-adapter-fs, @ai-coach/vault-adapter-pdf, @ai-coach/vault-adapter-search)
[vault-mcp-server / vault-view-server]
│
▼
[@ai-coach/vault-application] ──▶ [@ai-coach/vault-domain]
│
└──▶ Ports (NoteStore, FrontmatterParser, PdfReader, SearchRanker)

Internal architecture & rules​

  • One folder per vault server tool group (DEC-AIC-0064) under src/lib/, each re-exported through its own index.ts:
    • notes/ — scanning and searching the vault, filing (init, capture, file, archive) and editing a note's body.
    • reading/ — converting PDFs, marking and summarizing chapters, finding and marking passages, and writing concept notes.
    • climb/ — recording sessions, reading notes, structures, guidelines, extending concepts and the climb view.
    • planning/ — plan periods and days, tasks, habits, workstreams, roll-over, review, overview, the plans view and harvest.
    • shared/ — what several groups write with: safeName, note writes and version checks, note-edit plumbing, frontmatter edits and plan templates. ports/ holds NoteStore.
  • Groups never import each other. Each depends only on shared/, ports/ and @ai-coach/vault-domain; pure rules belong in the domain.
  • Composed Vault facade: createVault(deps, opts) in vault/ assembles one slice per group (notes, reading, climb, planning) over a shared runtime context.
  • Preview before write: Every mutating use case returns a plan first and writes only when execute: true. Planners read an immutable VaultTree snapshot and reject writes if a note's version hash changed since preview.
  • No comments in source code: Follow DEC-AIC-0011.

Public surface​

  • Facade & ports — createVault, Vault, VaultDeps, VaultOptions, writeViewGraph, NoteStore.
  • Notes — planInit, planCapture, planFileNote, planArchiveProject, editNote, searchNotes, searchPassages.
  • Reading — planConvert, planMarkRead, planSummary, planConcept, markedPassages.
  • Climb — planSession, executeSession, addReadingNotes, writeStructure, saveGuideline, extendConcept, climbView.
  • Planning — planPeriod, planDays, planningOverview, plansView, updateTasks, addTasks, addHabits, createWorkstream, reviewPeriod, rollOver, harvestWorkstream, expandTasksQueries.
  • Shared — setFrontmatter, executeWrites, versionsOf.

The pure rules these use (climb steps, periods, passages, marks) are exported by @ai-coach/vault-domain.

See the glossary for domain terms and vault-mcp-server for the exposed MCP tools.

How to extend it​

  1. Put any new pure rule in @ai-coach/vault-domain, then implement the planner and executor in the group folder whose server tool it serves (notes/, reading/, climb/ or planning/), using VaultTree for reads and NoteStore only in the execute step, and export it from that folder's index.ts.
  2. Wire the operation into the group's slice in src/lib/vault/ and add its method signature to Vault in src/lib/vault/types.ts.
  3. Add in-memory unit tests using createMemoryNoteStore from src/testing/.
  4. Run npm exec nx test @ai-coach/vault-application and npm exec nx lint @ai-coach/vault-application.

Running & testing​

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

Unit tests run in memory with Vitest and createMemoryNoteStore. Integration tests against real temporary vault directories live in vault-mcp-server.

Key ADRs​

  • DEC-AIC-0052 — Defines the hexagonal split, NoteStore port, and VaultTree snapshot rule.
  • DEC-AIC-0064 — Groups the application by the vault server's tool groups and keeps each group independent.
  • DEC-AIC-0048 — Keeps vault capabilities behind the MCP boundary.
  • DEC-AIC-0061 — Separates MCP tool hosting from the local HTTP view server.
  • DEC-AIC-0011 — Requires self-explanatory code without inline comments.