diff options
| author | Octavian Guzu <oct@anthropic.com> | 2026-09-09 16:46:55 +0000 |
|---|---|---|
| committer | Octavian Guzu <oct@anthropic.com> | 2026-09-09 16:46:55 +0000 |
| commit | f03d41e2c96f30b7b59a05566e998e6236a943e7 (patch) | |
| tree | f3c27a2016de7fca17e3546fb50b0cd81e29edcc /plugins/security-guidance/hooks/diffstate.py | |
| parent | 0b2f3e30a9c6f6e5ed7ca72408ffb957103174ca (diff) | |
Adjust SubagentStop handling and repository precedence
- SubagentStop reviews without consuming or advancing the session's
Stop state; an identical diff is not reviewed twice.
- SubagentStop from a different working tree than the project is skipped.
- An explicit `git -C <dir>` / `cd <dir>` naming another repository takes
precedence over the hook cwd.
- Narrows the `git -C … commit` matcher; keeps Windows path separators
when tokenizing; adds `--no-textconv` to diff/show invocations.
- Adds tests.
:house: Remote-Dev: homespace
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. |
