#!/usr/bin/env python3 """Stamp each ideas/*.md `status:` from the stance edges pointing at it. Status describes the *shape of the discourse*, not truth (PROJECT.md), so it is derived from the edges rather than set by hand — hand-set values drifted (ideas with for AND against edges still marked `open`). Counted over papers/ and influences/, one vote per paper: support S = papers holding `first-mention::` or `argues-for::` against A = papers holding `argues-against::` (`nuances::` / `tests::` refine or examine; they are not votes) widely-adopted S >= WIDE_MIN and A <= WIDE_MAX_AGAINST * S contested A >= 1 and S >= 1 (and not widely-adopted) open everything else `historical` (a superseded framing) cannot be read off the edges: it is the one hand-set value, and this script never overwrites it. python3 _scripts/make_status.py # restamp, list every change python3 _scripts/make_status.py --dry-run # list changes, write nothing Idempotent; run by end_of_wave.py after edges change. """ import collections import re import sys from pathlib import Path VAULT = Path(__file__).resolve().parent.parent IDEAS = VAULT / "ideas" EDGE_DIRS = ["papers", "influences"] WIDE_MIN = 10 # supporting papers needed for widely-adopted WIDE_MAX_AGAINST = 0.10 # opposition tolerated, as a fraction of support MANUAL = {"historical"} # hand-set values the script leaves alone EDGE_RE = re.compile( r"^(first-mention|argues-for|argues-against)::\s*\[\[([^\]|#]+)", re.M) STATUS_RE = re.compile(r"^status:[ \t]*([^\s#]*)", re.M) def derive(support: int, against: int) -> str: if support >= WIDE_MIN and against <= WIDE_MAX_AGAINST * support: return "widely-adopted" if support and against: return "contested" return "open" def main() -> int: dry = "--dry-run" in sys.argv[1:] sup: dict[str, set] = collections.defaultdict(set) ag: dict[str, set] = collections.defaultdict(set) for d in EDGE_DIRS: for f in sorted((VAULT / d).glob("*.md")): for kind, target in EDGE_RE.findall(f.read_text()): (ag if kind == "argues-against" else sup)[target.strip()].add(f.stem) counts = collections.Counter() changes = [] for f in sorted(IDEAS.glob("*.md")): if f.name.startswith("_"): continue text = f.read_text() m = STATUS_RE.search(text) if not m: print(f" !! no status line: {f.name}", file=sys.stderr) continue old = m.group(1) s, a = len(sup[f.stem]), len(ag[f.stem]) new = old if old in MANUAL else derive(s, a) counts[new] += 1 if new != old: changes.append((old, new, s, a, f.stem)) if not dry: f.write_text(text[: m.start(1)] + new + text[m.end(1):]) print(f"{sum(counts.values())} ideas: " + ", ".join(f"{k} {v}" for k, v in counts.most_common()) + f"; {len(changes)} {'would change' if dry else 'updated'}") for old, new, s, a, slug in sorted(changes, key=lambda c: (c[1], c[4])): print(f" {old:>14} -> {new:<14} (for {s:2d} / against {a}) {slug}") return 0 if __name__ == "__main__": sys.exit(main())