-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauto_skill_sync.py
More file actions
77 lines (69 loc) · 2.68 KB
/
auto_skill_sync.py
File metadata and controls
77 lines (69 loc) · 2.68 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
#!/usr/bin/env python3
# @bigd-hook-meta
# name: auto_skill_sync
# fires_on: PostToolUse
# relevant_intents: [meta, code]
# irrelevant_intents: [bigd, pm, telegram, docx, x_tweet, git, vps, sync, memory, debug]
# cost_score: 2
# always_fire: false
"""PostToolUse hook: sync public skills to claude-skills-curation, remind VPS sync for private."""
import io
import json
import re
import subprocess
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent))
from hook_base import run_hook
PUBLIC_REPO = Path.home() / "claude-skills-curation/skills"
# Sanitization: strip private paths before writing to public repo
_STRIP = [
(re.compile(r"~/telegram-claude-bot/"), "./"),
(re.compile(r"~/"), "~/"),
(re.compile(r"~/"), "~/"),
(re.compile(r"bernard@157\.180\.28\.14"), "<user>@<vps-ip>"),
(re.compile(r"~/.claude/projects/[^\s/]+/memory/"), "~/.claude/projects/*/memory/"),
]
def _sanitize(content: str) -> str:
for pattern, replacement in _STRIP:
content = pattern.sub(replacement, content)
return content
def _find_public(skill_name: str) -> Path | None:
for p in PUBLIC_REPO.rglob("SKILL.md"):
if p.parent.name == skill_name:
return p
return None
def check(tool_name, tool_input, input_data):
if tool_name not in ("Edit", "Write"):
return False
file_path = tool_input.get("file_path", "")
return bool(re.search(r"\.claude/skills/.*SKILL\.md", file_path))
def action(tool_name, tool_input, input_data):
file_path = Path(tool_input.get("file_path", ""))
skill_name = file_path.parent.name
public_dest = _find_public(skill_name)
if public_dest:
content = _sanitize(file_path.read_text())
public_dest.write_text(content)
result = subprocess.run(
f'cd ~/claude-skills-curation && git add skills && git commit -m "skill update: {skill_name}" && git push',
shell=True, capture_output=True, text=True
)
if result.returncode == 0:
return f"Public skill '{skill_name}' synced to claude-skills-curation."
else:
return f"Public skill '{skill_name}' copied but git push failed: {result.stderr.strip()}"
else:
return f"Private skill. Sync to VPS: `cd ~/.claude/skills && git add -A && git commit -m 'skill update' && git push`"
if __name__ == "__main__":
_raw = sys.stdin.read()
try:
_prompt = json.loads(_raw).get("prompt", "") if _raw else ""
except Exception:
_prompt = ""
from _semantic_router import should_fire
if not should_fire(__file__, _prompt):
print("{}")
sys.exit(0)
sys.stdin = io.StringIO(_raw)
run_hook(check, action, "auto_skill_sync")