-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_sync_all.py
More file actions
118 lines (94 loc) · 3.85 KB
/
Copy path_sync_all.py
File metadata and controls
118 lines (94 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Sync all source artifacts from .claude/ to cli/assets/ before release.
This is the single entry point for ensuring CLI bundles are up-to-date.
Usage:
python3 .claude/scripts/_sync_all.py # Dry run (verbose)
python3 .claude/scripts/_sync_all.py --apply # Actually copy files
python3 .claude/scripts/_sync_all.py --verify # Only check for differences
"""
import argparse
import filecmp
import os
import shutil
import sys
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent.parent # .claude/scripts/ -> repo root
CLAUDE_DIR = REPO_ROOT / ".claude"
CLI_ASSETS_DIR = REPO_ROOT / "cli" / "assets"
SKILL_DIR = CLAUDE_DIR / "skills"
# Sync mappings: (source_relative, dest_relative, description)
SYNC_MAP = [
# All 7 skills (to cli/assets/skills/)
("skills", "skills", "All 7 skill directories"),
# Troubleshoot scripts + data (to cli/assets/scripts/ + cli/assets/data/)
("skills/generalupdate-troubleshoot/scripts", "scripts", "BM25 search engine"),
("skills/generalupdate-troubleshoot/data", "data", "Issues + strategies CSV"),
# Code generator
("scripts/generate.py", "scripts/generate.py", "Parameterized code generator"),
("scripts/generate", "scripts/generate", "Generator templates"),
]
def sync_file(src: Path, dst: Path, apply: bool, dry_run: bool) -> str:
"""Sync one file or directory. Returns status string."""
if not src.exists():
return f"⚠️ SOURCE MISSING: {src.relative_to(REPO_ROOT)}"
if dst.exists() and filecmp.cmp(src, dst) if src.is_file() else _dirs_equal(src, dst):
return f"✓ UP TO DATE: {src.relative_to(REPO_ROOT)}"
if dry_run or not apply:
return f"→ NEEDS SYNC: {src.relative_to(REPO_ROOT)} → {dst.relative_to(REPO_ROOT)}"
# Apply the sync
dst.parent.mkdir(parents=True, exist_ok=True)
if src.is_file():
shutil.copy2(src, dst)
else:
if dst.exists():
shutil.rmtree(dst)
shutil.copytree(src, dst)
return f"✅ SYNCED: {src.relative_to(REPO_ROOT)}"
def _dirs_equal(a: Path, b: Path) -> bool:
"""Check if all files in source exist and match in destination (b may have extras)."""
if not b.exists():
return False
def _files(p: Path):
return sorted(
(f for f in p.rglob("*") if f.is_file() and "__pycache__" not in str(f)),
key=lambda x: str(x).lower(),
)
afiles = _files(a)
for fa in afiles:
rel = fa.relative_to(a)
fb = b / rel
if not fb.exists():
return False
if not filecmp.cmp(fa, fb, shallow=False):
return False
return True
def main():
parser = argparse.ArgumentParser(description="Sync .claude/ source to cli/assets/")
parser.add_argument("--apply", action="store_true", help="Actually copy files (default: dry-run)")
parser.add_argument("--verify", action="store_true", help="Only check, exit 1 if out of sync")
args = parser.parse_args()
dry_run = not args.apply
if dry_run and not args.verify:
print("═══ DRY RUN ═══ Use --apply to actually copy\n")
statuses = []
all_ok = True
for src_rel, dst_rel, desc in SYNC_MAP:
src = CLAUDE_DIR / src_rel
dst = CLI_ASSETS_DIR / dst_rel
status = sync_file(src, dst, args.apply, dry_run)
statuses.append((desc, status))
if status.startswith("⚠️"):
all_ok = False
print(f"\n═══ Summary ({'DRY RUN' if dry_run else 'APPLIED'}) ═══\n")
for desc, status in statuses:
print(f" {status}")
if args.verify and not all_ok:
print("\n❌ Verify FAILED: some sources are missing")
sys.exit(1)
if args.verify:
print("\n✅ Verify PASSED: all sources are in sync")
sys.exit(0)
if __name__ == "__main__":
main()