summaryrefslogtreecommitdiff
path: root/plugins/security-guidance/hooks/diffstate.py
diff options
context:
space:
mode:
authorMohamed Hegazy <mhegazy@anthropic.com>2026-10-22 17:11:25 +0000
committerClaude <noreply@anthropic.com>2026-10-22 17:11:25 +0000
commit22aea1e9b9b4e4efa98237d4d52154f973b47fec (patch)
tree47f7f055cec40bb8768f6f32c838ee8169f56217 /plugins/security-guidance/hooks/diffstate.py
parentaf59ee3a1051a29dda4a2e7a2af221aa457ae08b (diff)
security-guidance: report where a slow prompt's time goesmhegazy/sg-prompt-capture-time
Prompts that wait a second or more in the UserPromptSubmit hook send one metrics row: total, baseline and untracked listing time, index size, and whether the repository is on a Windows drive under WSL. Measures only; capture is unchanged. See #6854.
Diffstat (limited to 'plugins/security-guidance/hooks/diffstate.py')
-rw-r--r--plugins/security-guidance/hooks/diffstate.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/plugins/security-guidance/hooks/diffstate.py b/plugins/security-guidance/hooks/diffstate.py
index 6532fb6c..063b0604 100644
--- a/plugins/security-guidance/hooks/diffstate.py
+++ b/plugins/security-guidance/hooks/diffstate.py
@@ -16,6 +16,7 @@ from gitutil import (
GIT_CMD,
_git_dir, _git_toplevel, _git_status_porcelain,
_git_rev_parse_head, _is_ancestor, _git_name_only, _temp_index,
+ index_entry_count,
)
from session_state import with_locked_state
from extensibility import _same_dir
@@ -322,6 +323,8 @@ def get_baseline_file_content(session_id, file_path, cwd):
# from uncommitted work that was already there. Stored with baseline_sha.
# Telemetry only.
last_baseline_fail = 0
+# Entries in the index the last capture copied, None if unknown. Telemetry only.
+last_index_entries = None
def capture_git_baseline(cwd):
@@ -350,8 +353,9 @@ def capture_git_baseline(cwd):
# with `Ávila_report.txt` triggers a quotePath/locale warning) would
# trip the stderr reader thread on Windows cp1252. Decode both streams
# leniently for symmetry with _list_untracked. See #2056.
- global last_baseline_fail
+ global last_baseline_fail, last_index_entries
last_baseline_fail = 0
+ last_index_entries = None
try:
# Check if HEAD exists (i.e., repo has at least one commit)
head_check = subprocess.run(
@@ -369,6 +373,7 @@ def capture_git_baseline(cwd):
# env is None when no usable index copy could be made: fall
# back to HEAD.
if env is not None:
+ last_index_entries = index_entry_count(env["GIT_INDEX_FILE"])
result = subprocess.run(
[*GIT_CMD, "stash", "create"],
cwd=cwd, capture_output=True, timeout=15, env=env