#!/usr/bin/env python3 """Destroy the vault's dead weight: era ledgers, retired runtimes, dead experiments. `AGENTS.md` was treating a measurement as a record worth keeping forever. It is not: a throughput figure for a payload that no longer runs, on a runtime that no longer exists, is a liability — the next agent spends context on a number that AI progress has already obsolete. This pass moves those pages to `.AGENTTRASH/` (repo law: never `rm`) and then deletes every reference to them from the surviving pages, including the sentence that carried the link when the link was the sentence's only content. Usage: destroy-vault.py List file: one vault-relative path per line; a directory path destroys the whole tree. """ import pathlib import re import shutil import sys VAULT = pathlib.Path("serverAppConfigs-docs") TRASH = VAULT / ".AGENTTRASH" / "20261019-destruction" def targets(list_file): out = [] for line in pathlib.Path(list_file).read_text().splitlines(): line = line.strip() if not line or line.startswith("#"): continue p = VAULT / line if p.is_dir(): out += [f for f in sorted(p.rglob("*.md"))] elif p.is_file(): out.append(p) else: print(f" SKIP (missing): {line}") return out def main(argv): if len(argv) < 2: print(__doc__) return 2 doomed = targets(argv[1]) # Stems come from the trash too, so re-running the pass (or running it after a # partial destruction) still knows which names are dead and keeps scrubbing. stems = {p.stem for p in doomed} if TRASH.is_dir(): stems |= {p.stem for p in TRASH.rglob("*.md")} moved = 0 for p in doomed: dest = TRASH / p.relative_to(VAULT) dest.parent.mkdir(parents=True, exist_ok=True) shutil.move(str(p), str(dest)) moved += 1 print(f"destroyed {moved} pages ({sum(len(p.read_text(errors='replace').splitlines()) for p in TRASH.rglob('*.md'))} lines staged in trash)") # Repoint-or-delete: a link to a destroyed page is itself dead information. link_wl = re.compile(r"\[\[([^\]|#]+)(?:#[^\]|]*)?(?:\|([^\]]*))?\]\]") link_md = re.compile(r"\[[^\]]*\]\(([^)#]*\.md)(?:#[^)]*)?\)") pages_cleaned = links_dropped = lines_dropped = 0 for page in sorted(VAULT.rglob("*.md")): s = str(page) if ".AGENTTRASH" in s or ".obsidian" in s: continue text = page.read_text(errors="replace") lines = text.split("\n") out = [] hits = 0 def dead(target): # NOT pathlib.Path(...).stem: that strips a real suffix off names like # `Lemonade and sd.cpp`, so a link to a destroyed page survives and the # vault then fails its own link check. t = target.strip() if t.endswith(".md"): t = t[:-3] return t in stems or pathlib.PurePosixPath(t).name in stems for line in lines: found = [t for t in link_wl.findall(line) if dead(t[0])] for m in link_md.finditer(line): if dead(m.group(1)): found.append(m.group(1)) if not found: out.append(line) continue hits += len(found) stripped = link_wl.sub( lambda m: m.group(2) if (m.group(2) and not dead(m.group(1))) else "", line) stripped = link_md.sub( lambda m: "" if dead(m.group(1)) else m.group(0), stripped) # What is left of the line after the dead links are gone? residue = re.sub(r"[\s\-*•·|:;,.\u2014\u2013]+", "", stripped) if residue: out.append(re.sub(r"\s+$", "", re.sub(r"^(\s*[-*]\s*)[\s:;,.\u2014-]+", r"\1", stripped))) else: lines_dropped += 1 if hits: page.write_text("\n".join(out)) pages_cleaned += 1 links_dropped += hits print(f"cleaned {pages_cleaned} surviving pages: {links_dropped} dead links dropped, " f"{lines_dropped} lines left empty and deleted") return 0 if __name__ == "__main__": sys.exit(main(sys.argv))