-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvisual_check.sh
More file actions
executable file
·35 lines (27 loc) · 1.6 KB
/
visual_check.sh
File metadata and controls
executable file
·35 lines (27 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env bash
# PostToolUse hook: remind to visually inspect generated images/plots
# Reads tool result from stdin JSON for Bash commands.
# If the command produced image files (.png, .jpg, .pdf, .svg),
# reminds the assistant to actually look at the generated output.
set -euo pipefail
# Read the hook input from stdin
input=$(cat)
# Extract the command that was run
command=$(echo "$input" | jq -r '.tool_input.command // empty' 2>/dev/null)
stdout=$(echo "$input" | jq -r '.tool_result.stdout // empty' 2>/dev/null)
if [ -z "$command" ]; then
exit 0
fi
# Check if the command or its output mentions image generation
image_pattern='\.(png|jpg|jpeg|svg|pdf|eps|tiff)\b'
# Check command for savefig, plt.save, output paths, etc.
if echo "$command" | grep -qiE "(savefig|save_fig|imwrite|imsave|\.save\(|convert|>.*${image_pattern})" 2>/dev/null; then
echo '{"decision": "allow", "reason": "VISUAL CHECK: An image/plot was likely generated. Use the Read tool to inspect the output file and verify it looks correct. Do not trust metrics alone — check that labels, legends, colors, axis ranges, and the overall visual message match expectations."}'
exit 0
fi
# Check stdout for image file paths
if echo "$stdout" | grep -qiE "(saved|written|created|generated).*${image_pattern}" 2>/dev/null; then
echo '{"decision": "allow", "reason": "VISUAL CHECK: An image/plot was generated. Use the Read tool to inspect the output file and verify it looks correct. Do not trust metrics alone — check that labels, legends, colors, axis ranges, and the overall visual message match expectations."}'
exit 0
fi
exit 0