diff --git a/.claude/hooks/watchdog_gate.py b/.claude/hooks/watchdog_gate.py index 0fc3782..6ff20b0 100644 --- a/.claude/hooks/watchdog_gate.py +++ b/.claude/hooks/watchdog_gate.py @@ -33,12 +33,17 @@ def result_text(item): if isinstance(c, str): return c if isinstance(c, list): - return "\n".join(x.get("text", "") for x in c if isinstance(x, dict)) + return "\n".join((x.get("text") or "") for x in c if isinstance(x, dict)) return "" def verdict(text): - return "WATCHDOG: PASS" in text and "WATCHDOG: FIX" not in text + # 판정은 결과의 마지막 비어 있지 않은 줄이 정확히 "WATCHDOG: PASS" 일 때만 인정한다 (본문 중간 인용·FIX 혼재 차단) + lines = [l.strip() for l in text.replace("\\n", "\n").splitlines() if l.strip()] + if not lines: + return False + last = re.sub(r"[`*_<>/]|result", "", lines[-1]).strip() + return last == "WATCHDOG: PASS" and "WATCHDOG: FIX" not in text def main(): @@ -60,6 +65,8 @@ def main(): watchdog_ids = set() passed = False for r in rows: + if not isinstance(r, dict): + continue if r.get("isSidechain"): continue # 요청 사본 행은 앞선 도구 호출을 다시 담고 있어 순서를 흐트러뜨린다. 건너뛴다 @@ -74,7 +81,7 @@ def main(): if m and m.group(1) in watchdog_ids: passed = verdict(prompt) continue - c = r.get("message", {}).get("content") + c = (r.get("message") or {}).get("content") if isinstance(r, dict) else None if isinstance(c, str): if "" in c: m = re.search(r"([^<]+)", c) @@ -110,4 +117,9 @@ def main(): if __name__ == "__main__": - main() + try: + main() + except SystemExit: + raise + except Exception as e: # 훅이 깨지면 막는 쪽으로 (fail-closed) + deny(f"watchdog 게이트 훅 오류로 초안 도구를 막았습니다: {type(e).__name__}: {e}")