Files

71 lines
2.2 KiB
Python

#!/usr/bin/env python3
"""Throwaway helper for the directive_hotswap_harness expansion.
Back-fills the existing 51 v1.md files: strips the metadata header and
writes a meta.md alongside containing the lifted provenance.
This script is throwaway. Lives under scripts/tier2/artifacts/ per the
Tier 2 convention; deleted after the expansion commits land.
"""
import re
from pathlib import Path
REPO = Path(".").resolve()
DIRECTIVES_DIR = REPO / "conductor" / "directives"
HEADER_RE = re.compile(
r"^(?P<name>[^\n]+?)\s*[—–-]\s*v1\s*\n\n"
r"(?P<why>\*\*Why this iteration:\*\*[^\n]*(?:\n(?!\n)[^\n]*)*)\n\n"
r"\*\*Source:\*\*[ \t]+(?P<source>[^\n]+)\n\n"
r"---\n\n",
re.MULTILINE,
)
def parse_header(content: str, directive_name: str) -> tuple[str, str]:
m = HEADER_RE.search(content)
if not m:
raise ValueError(f"Could not parse header in {directive_name}/v1.md")
body = content[m.end():]
header_block = content[:m.end()]
return header_block, body
def main() -> None:
directive_dirs = sorted([
d for d in DIRECTIVES_DIR.iterdir()
if d.is_dir() and d.name != "presets"
])
if not directive_dirs:
raise SystemExit(f"No directive directories found under {DIRECTIVES_DIR}")
print(f"Processing {len(directive_dirs)} directives")
for d in directive_dirs:
name = d.name
v1_path = d / "v1.md"
meta_path = d / "meta.md"
if not v1_path.exists():
print(f"SKIP {name}: no v1.md")
continue
if meta_path.exists():
print(f"SKIP {name}: meta.md already exists")
continue
content = v1_path.read_text(encoding="utf-8")
try:
header_block, body = parse_header(content, name)
except ValueError as e:
print(f"ERROR {name}: {e}")
continue
why_text = header_block.split("**Why this iteration:**", 1)[1].split("**Source:**", 1)[0].strip()
source_text = header_block.split("**Source:**", 1)[1].strip()
meta_content = (
f"# {name}\n\n"
f"## v1\n\n"
f"**Why this iteration:** {why_text}\n"
f"**Source:** {source_text}\n"
f"**Lifted:** 2026-07-02 (Phase 1 harvest by Tier 3 worker; user directive 2026-07-02 moved the header into this meta file)\n"
)
meta_path.write_text(meta_content, encoding="utf-8")
v1_path.write_text(body, encoding="utf-8")
print(f"OK {name}")
if __name__ == "__main__":
main()