Skip to content

Check_plan

FieldValue
TypeSkill Resource
Source~/.copilot/skills/file-organizer/scripts/check_plan.py
DescriptionNot specified

Source Content

#!/usr/bin/env python3
"""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).
"""
import argparse
import re
import sys
from pathlib import Path
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("plan")
ap.add_argument("--root", default=".")
args = ap.parse_args()
text = Path(args.plan).read_text(encoding="utf-8")
root = Path(args.root)
fail = 0
lines = text.splitlines()
deleted, moved = set(), set()
for line in lines:
paths = re.findall(r"`([^`]+/[^`]+|[^`]+\.\w+)`", line)
if re.search(r"\bdelete\b", line, re.IGNORECASE):
deleted.update(paths)
if re.search(r"\bmove\b|\brename\b|\barchive\b", line, re.IGNORECASE):
moved.update(paths)
for p in paths:
candidate = root / p
if not candidate.exists():
print(f"❌ plan references '{p}' but no file exists at {candidate}")
fail = 1
conflicts = deleted & moved
if conflicts:
print(f"❌ path(s) both deleted and moved/renamed/archived in this plan: {sorted(conflicts)}")
fail = 1
else:
print("✅ no path is both deleted and moved in the same plan")
if fail == 0:
print("✅ every referenced path exists")
return fail
if __name__ == "__main__":
raise SystemExit(main())