This repository has been archived on 2026-07-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files

29 lines
1.0 KiB
Python

#!/usr/bin/env python3
"""
Git pre-commit hook — 在提交前强制运行 SKILL 静态一致性检查。
安装方式:复制或软链接到 .git/hooks/pre-commit
Windows: copy .opencode\skills\skill-tester\hooks\pre-commit .git\hooks\pre-commit
Unix: ln -sf ../../.opencode/skills/skill-tester/hooks/pre-commit .git/hooks/pre-commit
"""
import subprocess
import sys
from pathlib import Path
SCRIPT = Path(__file__).resolve().parent.parent / "static-checks" / "run.py"
# 检查是否有 .opencode/skills/ 下的文件被 staged
result = subprocess.run(
["git", "diff", "--cached", "--name-only", "--", ".opencode/skills/"],
capture_output=True, text=True
)
staged = [f for f in result.stdout.strip().split("\n") if f]
if not staged:
print("[pre-commit] 无 Skill 文件变更,跳过静态检查")
sys.exit(0)
print(f"[pre-commit] 检测到 {len(staged)} 个 Skill 文件变更,运行 Layer 1 静态检查...\n")
result = subprocess.run([sys.executable, str(SCRIPT)])
sys.exit(result.returncode)