modify documents
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Add FESA context before repository files are edited."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
WATCHED_PATTERNS = (
|
||||
r"\bAGENTS\.md\b",
|
||||
r"\bPLAN\.md\b",
|
||||
r"\bPROGRESS\.md\b",
|
||||
r"\bdocs[\\/]",
|
||||
r"\bphases[\\/]",
|
||||
r"\.codex[\\/]agents[\\/]",
|
||||
r"\.codex[\\/]commands[\\/]",
|
||||
r"\.codex[\\/]skills[\\/]",
|
||||
r"\.codex[\\/]hooks",
|
||||
r"\.codex[\\/]config\.toml\b",
|
||||
r"\bplugins[\\/]",
|
||||
r"\.agents[\\/]plugins[\\/]",
|
||||
)
|
||||
|
||||
|
||||
def has_watched_path(tool_input: object) -> bool:
|
||||
text = json.dumps(tool_input, ensure_ascii=False)
|
||||
return any(re.search(pattern, text, re.IGNORECASE) for pattern in WATCHED_PATTERNS)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
try:
|
||||
payload = json.load(sys.stdin)
|
||||
except json.JSONDecodeError:
|
||||
return 0
|
||||
|
||||
if not has_watched_path(payload.get("tool_input", {})):
|
||||
return 0
|
||||
|
||||
json.dump(
|
||||
{
|
||||
"hookSpecificOutput": {
|
||||
"hookEventName": "PreToolUse",
|
||||
"additionalContext": (
|
||||
"FESA edit guardrail: after editing docs, phases, or .codex extension files, "
|
||||
"keep PLAN.md/PROGRESS.md synchronized and run python scripts/validate_workspace.py "
|
||||
"when the turn changes files."
|
||||
),
|
||||
}
|
||||
},
|
||||
sys.stdout,
|
||||
)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user