diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 81ca3e7..50c8bf4 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -14,7 +14,7 @@ name: Sync AI Rules entry: duolingo/pre-commit-hooks:1.16.1 sh -c "PYTHONPATH=/ python3 -m sync_ai_rules" language: docker_image - files: &sync_ai_rules_files (^\.cursor/rules/.*\.mdc$|^\.code_review/.*\.md$) + always_run: true pass_filenames: false # Nobody should ever use these hooks in production. They're just for testing PRs in @@ -32,5 +32,5 @@ name: Sync AI Rules (dev) entry: sh -c "PYTHONPATH=/ python3 -m sync_ai_rules" language: docker - files: *sync_ai_rules_files + always_run: true pass_filenames: false diff --git a/sync_ai_rules/__main__.py b/sync_ai_rules/__main__.py index 6961c89..53e5d0c 100755 --- a/sync_ai_rules/__main__.py +++ b/sync_ai_rules/__main__.py @@ -5,6 +5,7 @@ import logging import os +import subprocess from pathlib import Path from typing import Dict, List @@ -96,8 +97,29 @@ def _ensure_agents_skills_symlinks(project_root: str) -> None: logger.warning("Failed to create agents skills symlink at %s: %s", rel, e) +_SOURCE_PREFIXES = (".cursor/", ".code_review/", ".agents/") + + +def _has_relevant_staged_changes() -> bool: + """Check if any staged files (including deletions) touch source directories.""" + try: + result = subprocess.run( + ["git", "diff", "--cached", "--name-only"], + capture_output=True, + text=True, + check=True, + ) + except (subprocess.CalledProcessError, FileNotFoundError): + return True + + return any(line.startswith(_SOURCE_PREFIXES) for line in result.stdout.splitlines()) + + def main(): """Main orchestration: load pipelines → parse → generate → update files.""" + if not _has_relevant_staged_changes(): + return + # Setup project_root = str(Path.cwd()) script_dir = os.path.dirname(os.path.abspath(__file__))