#!/usr/bin/env python3
"""PostToolUse hook: 编辑高风险文件后提醒审计"""
import json, re, sys

try:
    data = json.load(sys.stdin)
except Exception:
    sys.exit(0)

fp = (data.get("tool_input") or {}).get("file_path", "")
if not fp:
    sys.exit(0)

# 转相对路径
rel = re.sub(r"^.*?NeoZQYY[/\\]", "", fp.replace("\\", "/"))

HIGH_RISK = [
    r"^apps/etl/connectors/feiqiu/(tasks|loaders|scd|orchestration|config|database|models|quality)/",
    r"^apps/backend/app/(routers|services|auth|schemas)/",
    r"^db/.*/migrations/.*\.sql$",
    r"^db/.*/schemas/.*\.sql$",
    r"^packages/shared/",
]

for p in HIGH_RISK:
    if re.search(p, rel):
        print(json.dumps({
            "hookSpecificOutput": {
                "hookEventName": "PostToolUse",
                "additionalContext": f"[audit-reminder] 已编辑高风险文件: {rel} — 完成本轮改动后请执行 /audit"
            }
        }))
        break
