Skip to content

Commit e86d710

Browse files
kodesh87claude
andcommitted
fix(render): sections by name, not number — and the upgrade counts the one move no validator sees
An agent ran wdi-upgrade on a 0.5.12 corpus and reported green. The diff said otherwise on two points the report never mentioned: - The migrated PRD kept its old section numbers (`## 4. Features`, `## 8. MVP Scope`). The renderer keyed on "3. Features" and rendered a PRD with no Features, MVP Scope, Success Metrics, NFRs, or Constraints — every FR fell into the fallback list. `_section` now matches by name; the skill renumbers to the template after the deletions. - 23 FR description paragraphs were deleted from the PRD and landed nowhere: the `statement:` rule existed and was skipped, and nothing counted it. The skill now says this is the one move with no validator behind it, demands blocks-with-a-paragraph equal rows-with-statement, and reports both. Also from that run: a `questions/` table older than the `Whose` column gets the column added; a cost the source never stated is `—`, not invented; an unmarked open question files in assumptions.md. The renderer test was seen red on the previous `_section` before the fix. Co-Authored-By: Claude Code <noreply@anthropic.com>
1 parent 17ba48d commit e86d710

5 files changed

Lines changed: 64 additions & 13 deletions

File tree

‎kit/.constitution/method/scripts/validate.py‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,18 +1628,26 @@ def as_markdown(name: str, payload: dict) -> str:
16281628
"MUST NOT be hand-edited.\n")
16291629

16301630

1631+
def _hname(heading: str) -> str:
1632+
"""A heading's NAME: lower-cased, with any leading `3.` / `4.2` / `§5` numbering dropped. Section
1633+
numbers moved between kits (Non-Goals was §7 in one, §5 in the next) and a migrated document may
1634+
keep its old ones — a page that keyed on the number went blind on exactly those corpora."""
1635+
return re.sub(r"^\s*(?:§\s*)?\d+(?:\.\d+)*\.?\s*", "", heading.strip().lower())
1636+
1637+
16311638
def _section(path: Path, heading: str) -> str:
1632-
"""Extract one `## <heading>` section from a markdown file, as-is."""
1639+
"""Extract one `## <heading>` section from a markdown file, as-is. Matched by name, not number."""
16331640
if not path.exists():
16341641
return ""
16351642
lines = path.read_text(encoding="utf-8", errors="replace").splitlines()
16361643
out: list[str] = []
16371644
inside = False
1645+
want = _hname(heading)
16381646
for line in lines:
16391647
if line.startswith("## "):
16401648
if inside:
16411649
break
1642-
inside = line[3:].strip().lower().startswith(heading.lower())
1650+
inside = _hname(line[3:]).startswith(want)
16431651
continue
16441652
if inside:
16451653
out.append(line)
@@ -1895,7 +1903,7 @@ def _subsection(path: Path, parent: str, sub: str) -> str:
18951903
if line.startswith("### "):
18961904
if inside:
18971905
break
1898-
inside = line[4:].strip().lower().startswith(sub.lower())
1906+
inside = _hname(line[4:]).startswith(_hname(sub))
18991907
continue
19001908
if inside:
19011909
out.append(line)

‎kit/skills/wdi-upgrade/SKILL.md‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,13 @@ that says something the other did not. Each `BG-N` statement under `## Goals` MU
7575
item becomes a row in `.control/questions/assumptions.md` with `Whose: owner`; each `## Prerequisites`
7676
item a row in `external.md` — **after** checking that no `OQ-` row already states it, because a brief
7777
written under an earlier kit usually landed them already and a second row is a copy. A prerequisite
78-
the brief itself marks satisfied is dropped, not landed as open. Delete both sections, and say how
79-
many items were already rows. Check `## Success Criteria` names one measurable
78+
the brief itself marks satisfied is dropped, not landed as open. A `questions/` table written before
79+
the `Whose` column existed (`| id | Assumption | Cost if wrong | Taken | By |`) gets the column added —
80+
header and separator, and an empty cell on every existing row, which the validator counts as
81+
`unstated`, which is what they are. The rows this skill lands say `owner`. `Cost if wrong` is `—` when
82+
the source never stated one; it is not invented. An open question the source never marked blocking is
83+
filed in `assumptions.md`, as the template's three tests say. Delete both sections, and say how many
84+
items were already rows. Check `## Success Criteria` names one measurable
8085
figure — if it does not, that is a finding for the owner, not a sentence for this skill to invent.
8186

8287
**4 — each PRD.** Sections are matched **by name, never by number**: the numbers moved between kits
@@ -88,16 +93,23 @@ this PRD's `MVP Scope → Out of Scope` — if neither holds it, add it to the o
8893
delete `Non-Goals`. Every `Open Questions` and `Assumptions Index` item becomes a `questions/` row
8994
(after the same already-a-row check as the brief's); delete both.
9095
Under each feature, every `FR` block is folded into its row in `requirements-<slug>.yaml` (Step 2)
91-
before the block goes: the block's description paragraph becomes the row's `statement:` when the row
92-
has none (the row's `title` stays); its `**Consequences (testable):**` bullets move verbatim to
96+
before the block goes: the block's description paragraph — the prose between the `#### FR-N` heading
97+
and the first `**…:**` label — becomes the row's `statement:` when the row has none (the row's `title`
98+
stays). **This is the one move with no validator behind it**, so count it: blocks with a paragraph
99+
versus rows that now carry `statement:` MUST match, and Step 5 reports both numbers. A run that deletes
100+
the blocks and lands zero statements has thrown the requirement's own sentence away; its `**Consequences (testable):**` bullets move verbatim to
93101
`addendum.md` under `## Technical how — testable consequences per FR`, appended **after** the sections
94102
already there, one `### FR-N — title` each,
95103
because `prd-guide.md` repealed the double proof of done and that is where the technical restatement
96104
lives now; its `**Proof of done:**` is compared with the row's `proof` — when they differ, the
97105
**registry is kept** (it is the declared SSOT), the PRD's is dropped, and both texts are reported side
98106
by side for the owner, never merged. Then the block becomes `**Realizes:** FR-a, FR-b, NFR-c`, and a
99107
`**Functional Requirements:**` label left with nothing under it is deleted — the rendered page rebuilds
100-
the blocks from the rows. A `UJ-N` the prose names that has no row in any requirement file is
108+
the blocks from the rows. When the deletions are done, **renumber the surviving `##` headings to the
109+
template's order** — 1 Why This Initiative · 2 Target User · 3 Features · 4 MVP Scope · 5 Success
110+
Metrics · 6 Cross-Cutting NFRs · 7 Constraints and Guardrails — and the `###` beneath them to match
111+
(`### 8.2` → `### 4.2`). Numbers are not sentences; leaving `## 4. Features` beside `## 8. MVP Scope`
112+
tells the next reader two sections went missing. A `UJ-N` the prose names that has no row in any requirement file is
101113
not given one — it is marked with an HTML comment where it stands and reported; `wdi-product`
102114
allocates ids. A moved sentence that cites a section number (`§ 8`) of a section this step deletes
103115
keeps the number — it is reported as wording for the owner, not repointed, because its new home is a
@@ -159,5 +171,6 @@ event.
159171
## Output
160172

161173
The Step 1 checklist with each item marked done · skipped (already new shape) · left for the owner, with
162-
the id list for the last · the registry rows landed · the path of every rendered page · the validator
163-
result · the commit.
174+
the id list for the last · the registry rows landed · **statements landed / FR blocks that had a
175+
paragraph** · consequences moved · `questions/` rows added and rows found already present · proof-of-done
176+
divergences, both texts · the path of every rendered page · the validator result · the commit.

‎package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wdi-method",
3-
"version": "0.5.44",
3+
"version": "0.5.45",
44
"description": "WDI Method — software delivery method that wraps BMad",
55
"type": "module",
66
"bin": {

‎tests/fixture-corpus.test.mjs‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,3 +729,33 @@ test("no-cycles still sees a depends_on that crosses two initiative files", (t)
729729
`no-cycles stopped seeing a depends_on cycle once the two capabilities sat in different files. That `
730730
+ `edge is how an initiative says it waits on another one:\n${out}`);
731731
});
732+
733+
// A migrated PRD may keep the numbers its kit gave it — `## 4. Features`, `## 8. MVP Scope`. The renderer
734+
// keyed on "3. Features" and went blind: on a real 0.5.12 corpus the rendered PRD lost Features, MVP
735+
// Scope, Success Metrics, Cross-Cutting NFRs, and Constraints, and every FR fell into the fallback list.
736+
test("the rendered PRD finds its sections by NAME — a PRD numbered by an older kit still renders whole", (t) => {
737+
if (requireUv(t)) return;
738+
const tmp = briefPrdCorpus();
739+
try {
740+
const prd = path.join(tmp, ".what", "_prd", "checkout-v1", "prd.md");
741+
const renumbered = fs.readFileSync(prd, "utf8")
742+
.replace("## 3. Features", "## 4. Features")
743+
.replace("### 3.1 Guest Checkout", "### 4.1 Guest Checkout")
744+
.replace("## 4. MVP Scope", "## 8. MVP Scope")
745+
.replace("### 4.1 In Scope", "### 8.1 In Scope")
746+
.replace("### 4.2 Out of Scope for MVP", "### 8.2 Out of Scope for MVP")
747+
.replace("## 5. Success Metrics", "## 9. Success Metrics");
748+
assert.notEqual(renumbered, fs.readFileSync(prd, "utf8"), "the fixture PRD did not carry the headings this test renumbers");
749+
fs.writeFileSync(prd, renumbered);
750+
generateIn(tmp);
751+
const rendered = fs.readFileSync(path.join(tmp, ".what-rendered", "_prd", "checkout-v1", "prd.md"), "utf8");
752+
for (const h of ["## Features", "## MVP Scope", "## Success Metrics"]) {
753+
assert.ok(rendered.includes(h), `${h} is missing from the rendered PRD — the renderer keyed on a section number:\n${rendered}`);
754+
}
755+
assert.ok(rendered.indexOf("### 4.1 Guest Checkout") < rendered.indexOf("#### FR-1 — ")
756+
&& rendered.indexOf("#### FR-1 — ") < rendered.indexOf("### Capabilities"),
757+
"FR-1 fell into the fallback list instead of landing under its feature");
758+
} finally {
759+
fs.rmSync(tmp, { recursive: true, force: true });
760+
}
761+
});

0 commit comments

Comments
 (0)