#!/usr/bin/env python3 """ Merge one or more raw .txt files that came from the IDE Read tool (line prefix like ' 12|...') into reports/inventory/DEPLOYED_CONTRACTS_UNIFIED_EXTENDED.md. Skips "lines not shown" continuation lines. Removes the leading ' N| ' prefix. """ import re import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[2] OUT = ROOT / "reports/inventory/DEPLOYED_CONTRACTS_UNIFIED_EXTENDED.md" PREFIX = re.compile(r"^\s*\d+\|") def strip_file(text: str) -> str: out: list[str] = [] for line in text.splitlines(): if "lines not shown" in line and "..." in line: continue m = PREFIX.match(line) if m: line = line[m.end() :] out.append(line) return "\n".join(out) + "\n" def main() -> None: paths = [Path(p) for p in sys.argv[1:]] if not paths: print("Usage: stitch_unified_from_read_output_chunks.py [chunk2 ...]", file=sys.stderr) sys.exit(2) text = "" for p in paths: if not p.is_file(): print("Missing", p, file=sys.stderr) sys.exit(1) text += strip_file(p.read_text(encoding="utf-8")) OUT.parent.mkdir(parents=True, exist_ok=True) OUT.write_text(text, encoding="utf-8") print(OUT, len(text), "bytes") if __name__ == "__main__": main()