Skip to main content

@ai-coach/vault-adapter-markdown

Reads a note's YAML frontmatter. parseMatter is the FrontmatterParser the vault uses, built on gray-matter. It splits a note into its frontmatter and its body. You change this package only if notes need to be parsed differently.

What it does not do​

  • No meaning. It returns raw frontmatter values; vault-domain normalises them, for example dates to YYYY-MM-DD.
  • No file access. It parses text it is given; reading files is vault-adapter-fs's job.
  • Only gray-matter. Nx boundaries (adapter:vault-markdown) forbid any other external import.

Architecture fit​

  • Scope: scope:vault
  • Style: architecture:hexagonal (type:adapter, adapter:vault-markdown)
  • Depends on: @ai-coach/vault-domain (the FrontmatterParser port)
  • Used by: @ai-coach/vault-mcp-server, @ai-coach/vault-view-server (their composition roots)
[composeVault] ──▶ parseMatter ──implements──▶ FrontmatterParser (vault-domain)

Internal architecture & rules​

  • One function, parseMatter in src/lib/markdown.ts, wrapping gray-matter.
  • A thin wrapper. It returns gray-matter's data and content unchanged; any interpretation of the values happens in the domain.
  • No comments in source code (DEC-AIC-0011).

Public surface​

  • parseMatter — the FrontmatterParser passed to createVault as deps.frontmatter.

How to extend it​

  1. Change the port in vault-domain first if the parser's contract changes.
  2. Adjust parseMatter in src/lib/markdown.ts.
  3. Cover the case in src/lib/markdown.spec.ts.
  4. Run npm exec nx test @ai-coach/vault-adapter-markdown and npm exec nx lint @ai-coach/vault-adapter-markdown.

Running & testing​

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

The specs parse note strings in memory with Vitest.

Key ADRs​

  • DEC-AIC-0052 — puts frontmatter parsing behind a port and keeps gray-matter in this adapter.
  • DEC-AIC-0051 — one adapter per outside dependency, each with its own import whitelist.