# Scratchpad — RI-4-001 One transitional PRD authority (RI-N3, #1275)

- Objective: single PrdService authority in `@mosaicstack/prdy`; `mosaic prdy` and
  `mission --plan` become thin adapters; mission↔PRD linkage persisted on disk;
  Markdown export is a labeled generated view (never read back); import is
  validated/conflict-aware with typed refusals.
- Budget: ~35K tokens (card cap). Baselines: prdy build/lint rc=0, 0 tests;
  mosaic build rc=0 (after root turbo build), lint rc=0, 1548 tests pass;
  root build rc=0.
- Plan: (1) extend store schema (version, missions linkage) (2) PrdService +
  typed errors (3) wizard/cli route through service (4) mosaic adapters
  (5) contract specs both packages (6) gates (7) sabotage control (8) report
  to /var/tmp/ri-050/ri-4-001-report.md.
- Decisions:
  - Linkage lives ON the PRD document (`missions` array) — one authority file,
    survives restart, no sidecar sync problems.
  - `version` = content revision of sections/status (bumped by update/import
    accept). Linkage writes bump `updatedAt` only, so ids/versions stay stable
    for the card's "stable ids/versions" contract.
  - Mission version marker = `mission.updatedAt` (gateway MissionInfo has no
    numeric version field).
  - Import reads YAML documents only — never the exported Markdown (keeps the
    "no code path reads exported Markdown" invariant).
  - Import of an existing id with identical core content → `identical` no-op;
    divergent → typed `PrdImportConflictError` carrying proposed successor
    (existing.version + 1, status draft, linkages preserved). Original bytes
    untouched until explicit `acceptSuccessor`.
  - `requirementIds` default `[]` at the mission command (no requirement
    selection UI yet) — service accepts ids when a caller has them.
- Progress log:
  - [16:35] baselines captured (prdy 0 tests; mosaic 1548 after root build; root build rc=0)
  - [16:38] store schema v2 + PrdService + wizard/cli rerouted; prdy build/lint green
  - [16:40] mosaic adapters done; prdy spec 20/20 (found+fixed: import project-path leak, empty-store typed error, YAML timestamp coercion)
  - [16:44] mosaic specs 9/9 (fixed commander from:'user' argv, vi.mock hoisting, restoreAllMocks wiping factory mocks)
  - [16:45] all gates green; 4 commits (e291bfb, 2c5d208, a23826c, 540d6f1)
  - [16:46] sabotage: linkage write removed → prdy 3 fail / mosaic 2 fail, 1548/1548 pre-existing pass; restored byte-identically; re-green 20/20 + 1557/1557
  - [16:47] report written to /var/tmp/ri-050/ri-4-001-report.md — card complete
