92 """Return ``{note_id: (title, verbatim_body)}`` for the 5 framing sections."""
93 text = roadmap_text.replace(
"\r\n",
"\n")
94 out: dict[str, tuple[str, str]] = {}
95 for prefix, note_id
in _SECTIONS:
96 match = re.search(rf
"^{re.escape(prefix)}.*$", text, re.MULTILINE)
99 title = match.group(0)[3:].strip()
100 nxt = _BOUNDARY_RE.search(text, match.end())
101 end = nxt.start()
if nxt
else len(text)
102 body = text[match.start():end].strip(
"\n")
103 body = _TRAILING_RULE_RE.sub(
"", body).strip(
"\n")
104 out[note_id] = (title, body)
108def backfill(roadmap_md: Path, source_dir: Path) -> FramingReport:
109 """Write each framing section to ``source/notes/<id>.md`` (verbatim body)."""
112 out_dir = Path(source_dir) /
"notes"
113 out_dir.mkdir(parents=
True, exist_ok=
True)
115 for note_id, (title, body)
in sections.items():
116 model = rc.Note(schema_version=rc.SCHEMA_VERSION, id=note_id, title=title)
117 (out_dir / f
"{note_id}.md").write_text(
118 format_record_text(model, body=body), encoding=
"utf-8", newline=
""
120 report.notes_written += 1
121 report.sections[note_id] = (title, body)
122 _dbg(
"OC_CHAT.MAIN", func, f
"wrote note {note_id} ({len(body)} chars)", 3)
123 _dbg(
"OC_CHAT.MAIN", func, f
"wrote {report.notes_written} framing notes", 2)