diff options
| author | Octavian Guzu <oct@anthropic.com> | 2026-09-09 19:05:41 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-09-09 19:05:41 +0100 |
| commit | 3ea32df27be71d78775e627df2382fc26203577f (patch) | |
| tree | 849075bd62d15d2e938bc7938434fd4e1a893b88 /plugins/security-guidance/hooks/diffstate.py | |
| parent | 517b2fcd1b60fa2181ac52dcf8492361ba341180 (diff) | |
| parent | debbe686ab74ec095436a499b1a59864037e46cf (diff) | |
Merge pull request #5982 from anthropics/sg-resolve-repo-root
security-guidance: resolve repository from command and edited paths
Diffstat (limited to 'plugins/security-guidance/hooks/diffstate.py')
| -rw-r--r-- | plugins/security-guidance/hooks/diffstate.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/plugins/security-guidance/hooks/diffstate.py b/plugins/security-guidance/hooks/diffstate.py index 3ce9da1b..8d0665dd 100644 --- a/plugins/security-guidance/hooks/diffstate.py +++ b/plugins/security-guidance/hooks/diffstate.py @@ -71,7 +71,7 @@ def record_touched_path(session_id, file_path): with_locked_state(session_id, _record) -def consume_stop_state(session_id): +def consume_stop_state(session_id, clear=True): """Atomically snapshot all state the Stop hook needs and clear touched_paths. The Stop hook is asyncRewake — it runs in the background after Claude's @@ -102,17 +102,27 @@ def consume_stop_state(session_id): "fire_count": 0 if expired else state.get("stop_hook_fire_count", 0), "fire_count_expired": expired and state.get("stop_hook_fire_count", 0) > 0, "previous_findings": [] if findings_expired else list(state.get("previous_findings", [])), + "reviewed_diff_hash": state.get("reviewed_diff_hash"), } - state["touched_paths"] = [] + if clear: + state["touched_paths"] = [] + state.pop("reviewed_diff_hash", None) return snap return with_locked_state(session_id, _snap) or { "touched_paths": [], "baseline_sha": None, "head_at_capture": None, "untracked_at_baseline": {}, "fire_count": 0, "fire_count_expired": False, "previous_findings": [], + "reviewed_diff_hash": None, } +def record_reviewed_diff(session_id, diff_hash): + def _save(state): + state["reviewed_diff_hash"] = diff_hash + with_locked_state(session_id, _save) + + def restore_unreviewed_stop_state(session_id, paths, baseline_sha): """Put consumed touched_paths back so the next Stop reviews them. |
