summaryrefslogtreecommitdiff
path: root/plugins/security-guidance/hooks/diffstate.py
diff options
context:
space:
mode:
authorMohamed Hegazy <mhegazy@anthropic.com>2026-11-07 02:01:32 +0000
committerClaude <noreply@anthropic.com>2026-11-07 02:01:32 +0000
commita8fa1532035ddf875c8594dd4407cbe38ffbe99a (patch)
tree2694d4dd1767f07c9938fc687b1a0c4593eaa6d4 /plugins/security-guidance/hooks/diffstate.py
parentaa5665a817bc2a48d48084c4192a083995aa024d (diff)
security-guidance: keep an incomplete edit record incomplete for the whole turnmhegazy/sg-stop-finding-names-unwritten
A record lost before one Stop was treated as whole by the next, and a prompt that was never stored as having no edits, so the note could name the session's own file. File names in the note are quoted as JSON. Co-authored-by: mhegazy <mhegazy@anthropic.com>
Diffstat (limited to 'plugins/security-guidance/hooks/diffstate.py')
-rw-r--r--plugins/security-guidance/hooks/diffstate.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/plugins/security-guidance/hooks/diffstate.py b/plugins/security-guidance/hooks/diffstate.py
index 612932ed..9ca56774 100644
--- a/plugins/security-guidance/hooks/diffstate.py
+++ b/plugins/security-guidance/hooks/diffstate.py
@@ -61,10 +61,6 @@ def load_baseline_sha(session_id):
return with_locked_state(session_id, _load)
-# record_touched_path and turn_touched keep the newest paths only.
-TOUCHED_PATHS_CAP = 200
-
-
def record_touched_path(session_id, file_path):
"""Append a file path to the touched_paths list (deduped, capped at 200).
@@ -132,6 +128,9 @@ def consume_stop_state(session_id, clear=True):
+ snap["touched_paths"]))[-TOUCHED_PATHS_CAP:]
snap["turn_touched"] = turn
if clear:
+ if snap["state_resets"] or snap["state_overwrites"]:
+ # turn_touched outlives this Stop, and so does its gap.
+ state["turn_touched_lost"] = True
state["turn_touched"] = turn
state["touched_paths"] = []
state.pop("reviewed_diff_hash", None)
@@ -149,13 +148,18 @@ def consume_stop_state(session_id, clear=True):
}
+# record_touched_path and turn_touched keep the newest paths only.
+TOUCHED_PATHS_CAP = 200
+
+
def touched_since_prompt(session_id):
"""(paths, complete): every path the session's edit tools recorded since
the prompt hook's baseline, read now and without consuming or writing
anything, so edits recorded while a Stop review runs are in it.
`complete` is False when the list is known to be missing paths: the
- state file was lost or overwritten since the last Stop, or it could not
- be read. Callers check the length against TOUCHED_PATHS_CAP."""
+ state was lost or overwritten since the prompt, it could not be read, or
+ the prompt hook's own save is not in it. Callers check the length
+ against TOUCHED_PATHS_CAP."""
try:
state = load_state(session_id)
except Exception:
@@ -165,8 +169,9 @@ def touched_since_prompt(session_id):
paths = list(dict.fromkeys(
[p for p in state.get("turn_touched", []) if isinstance(p, str)]
+ [p for p in state.get("touched_paths", []) if isinstance(p, str)]))
- lost = state.get("state_resets") or state.get("state_overwrites")
- return paths, not lost
+ lost = (state.get("state_resets") or state.get("state_overwrites")
+ or state.get("turn_touched_lost"))
+ return paths, not lost and state.get("prompt_at") is not None
# Path names compare without case where the filesystem usually does.