-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path.pre-commit-hook.py
More file actions
executable file
·68 lines (53 loc) · 1.88 KB
/
Copy path.pre-commit-hook.py
File metadata and controls
executable file
·68 lines (53 loc) · 1.88 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
#!/usr/bin/env python3
"""
Pre-commit hook for Weaver template/binding synchronization
Prevents prompt version drift by validating and regenerating bindings
"""
import subprocess
import sys
from pathlib import Path
def check_weaver_sync() -> bool:
"""Check if Weaver templates and bindings are synchronized"""
repo_root = Path.cwd()
# Check if any Weaver-related files changed
result = subprocess.run(
["git", "diff", "--cached", "--name-only"],
capture_output=True,
text=True
)
changed_files = result.stdout.strip().split('\n')
weaver_changed = any(
'weaver/templates' in f or 'semantic_conventions' in f or 'registry' in f
for f in changed_files if f
)
if not weaver_changed:
return True
print("🧵 Weaver files changed, validating and regenerating...")
# Run forge validate using uv run to ensure correct environment
validate_result = subprocess.run(
["uv", "run", "python", "-m", "dslmodel.cli", "weaver", "validate"],
capture_output=True,
text=True
)
if validate_result.returncode != 0:
print("❌ Weaver validation failed:")
print(validate_result.stderr)
return False
# Run forge generate using uv run to ensure correct environment
generate_result = subprocess.run(
["uv", "run", "python", "-m", "dslmodel.cli", "weaver", "generate"],
capture_output=True,
text=True
)
if generate_result.returncode != 0:
print("❌ Weaver generation failed:")
print(generate_result.stderr)
return False
# Auto-stage generated files
subprocess.run(["git", "add", "src/dslmodel/generated/"])
print("✅ Weaver templates and bindings synchronized")
return True
if __name__ == "__main__":
if not check_weaver_sync():
sys.exit(1)
sys.exit(0)