Skip to main content

@ai-coach/vault-adapter-pdf

Reads the text of a PDF book. readPdf is the PdfReader behind the convert_raw tool, built on pdf.js. It returns each page's text, the title and author, and the outline with page numbers. You change this package when PDFs need to be read differently.

What it does not do​

  • No splitting into chapters. Turning pages into chapter notes is the application's planConvert in vault-application.
  • No writing. It reads a PDF's bytes and returns text; the vault writes the notes.
  • Only pdfjs-dist. Nx boundaries (adapter:vault-pdf) forbid any other external import.

Architecture fit​

  • Scope: scope:vault
  • Style: architecture:hexagonal (type:adapter, adapter:vault-pdf)
  • Depends on: @ai-coach/vault-application (the PdfReader port)
  • Used by: @ai-coach/vault-mcp-server, @ai-coach/vault-view-server (their composition roots)
[convert_raw] ──▶ planConvert (vault-application) ──▶ PdfReader ◀──implements── readPdf ──▶ pdf.js

Internal architecture & rules​

  • One function, readPdf in src/lib/pdf-reader.ts, passed to createVault as deps.readPdf by each server's compose.ts.
  • Pages keep their numbers. Page texts and outline entries carry the PDF's page numbers, which later anchor quotes to pages (DEC-KI-0059).
  • No comments in source code (DEC-AIC-0011).

Public surface​

  • readPdf — the PdfReader the vault's convertRaw uses.

How to extend it​

  1. Change the PdfReader port in vault-application first if the result needs more fields.
  2. Fill them in readPdf in src/lib/pdf-reader.ts.
  3. Cover the change in the conversion integration tests in vault-mcp-server, which convert real PDFs.
  4. Run npm exec nx test @ai-coach/vault-mcp-server and npm exec nx lint @ai-coach/vault-adapter-pdf.

Running & testing​

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

It has no specs of its own: the conversion tests in vault-mcp-server run real PDFs through it.

Key ADRs​

  • DEC-KI-0059 — a PDF is converted once into page-headed Markdown notes.
  • DEC-AIC-0052 — puts PDF reading behind the PdfReader port in its own adapter.