"""Check a proposed file-organization plan before it's executed.
Usage: check_plan.py <plan.md> [--root <dir>]
Verifies every source path the plan references actually exists (relative to
--root, default cwd), and flags any path that appears in both a "delete" step
and a "move"/"rename"/"archive" step (a contradiction that would race).
ap = argparse.ArgumentParser()
ap.add_argument("--root", default=".")
text = Path(args.plan).read_text(encoding="utf-8")
lines = text.splitlines()
deleted, moved = set(), set()
paths = re.findall(r"`([^`]+/[^`]+|[^`]+\.\w+)`", line)
if re.search(r"\bdelete\b", line, re.IGNORECASE):
if re.search(r"\bmove\b|\brename\b|\barchive\b", line, re.IGNORECASE):
if not candidate.exists():
print(f"❌ plan references '{p}' but no file exists at {candidate}")
conflicts = deleted & moved
print(f"❌ path(s) both deleted and moved/renamed/archived in this plan: {sorted(conflicts)}")
print("✅ no path is both deleted and moved in the same plan")
print("✅ every referenced path exists")
if __name__ == "__main__":