Skip to content

fix(prd): stop body lines being read as a PRD's title and status#42

Merged
ralyodio merged 1 commit into
moshcoder:mainfrom
clawedassistant26:fix/prd-index-reads-body-as-front-matter
Jul 26, 2026
Merged

fix(prd): stop body lines being read as a PRD's title and status#42
ralyodio merged 1 commit into
moshcoder:mainfrom
clawedassistant26:fix/prd-index-reads-body-as-front-matter

Conversation

@clawedassistant26

Copy link
Copy Markdown
Contributor

A PRD whose body has a line starting with title: or status: gets those values shown in prd list and the README index, in place of its real front matter.

Repro

prd/0001-job-api.md — an ordinary PRD documenting an API, with a YAML sample in a fenced block:

---
title: "Job API v2"
status: Accepted
---

## Requirements

- R1 [P0] Return the job record:

```yaml
title: nightly-import
status: queued

`listPrds()` returns `title: "nightly-import", status: "queued"`. The README index table and the `prd list` output (both `bin/moshcode.mjs` and the TUI) show those instead of `Job API v2` / `Accepted`.

## Cause

`src/prd.mjs:214` read a fixed window of the first 16 lines and kept the **last** `^title:`/`^status:` match anywhere in it, never stopping at the closing `---`. Generated front matter is exactly 16 lines, so freshly created PRDs hide the bug; it appears as soon as the front matter is shorter, which any hand-written or trimmed PRD is.

## Fix

Parse the delimited front-matter block (leading `---` to its closing `---`) and scan only that. Two follow-on effects, both intended:

- A file with no front matter no longer takes a title or status out of prose; it falls back to the slug and `?`, which is what an undeclared status means.
- Front matter longer than 16 lines is now read in full.

Existing PRDs render byte-identically — verified against this repo's own `prd/` (0001-0004 unchanged).

## Tests

Two added to `test/prd.test.mjs`: the fenced-YAML case above, and the no-front-matter fallback. Stash-verified with `git stash push -- src/`: both **fail** unpatched, both pass with the fix. Full suite `node --test`: **151 pass / 0 fail** (main is 149).

listPrds scanned the first sixteen lines of each PRD and kept the last
`title:`/`status:` match it found, without stopping at the closing `---`.
A PRD whose body starts a line with one of those keys — a YAML sample in a
fenced code block, say — therefore had its real front matter overwritten, so
`prd list` and the README index showed the sample's values instead.

Parse the delimited front-matter block instead. Files with no front matter
now fall back to the slug and `?` rather than lifting values out of prose.
Existing PRDs render byte-identically.
@ralyodio
ralyodio merged commit 4abd6e5 into moshcoder:main Jul 26, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants