-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathinteractive-approver.sh
More file actions
98 lines (81 loc) · 3.28 KB
/
interactive-approver.sh
File metadata and controls
98 lines (81 loc) · 3.28 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
# Interactive Approver: Detects prompts and notifies user for approval
set -uo pipefail
SESSION_NAME="$1"
APPROVAL_DIR="/tmp/claude-approvals"
if [ -z "$SESSION_NAME" ]; then
echo "Usage: $0 <tmux-session-name>"
exit 1
fi
mkdir -p "$APPROVAL_DIR"
PENDING_FILE="$APPROVAL_DIR/${SESSION_NAME}.pending"
RESPONSE_FILE="$APPROVAL_DIR/${SESSION_NAME}.response"
echo "[Interactive-Approver] Monitoring session: $SESSION_NAME"
echo "[Interactive-Approver] Approval dir: $APPROVAL_DIR"
while true; do
# Capture current pane content
OUTPUT=$(tmux capture-pane -t "$SESSION_NAME" -p 2>/dev/null)
# Check if session still exists
if [ $? -ne 0 ]; then
echo "[Interactive-Approver] Session ended. Exiting."
rm -f "$PENDING_FILE" "$RESPONSE_FILE"
exit 0
fi
# Look for "Do you trust..." prompt (folder trust)
if echo "$OUTPUT" | grep -q "Do you trust"; then
# Auto-approve trust prompts (one-time, safe)
echo "[Interactive-Approver] Trust prompt detected, auto-approving..."
tmux send-keys -t "$SESSION_NAME" Enter
sleep 2
continue
fi
# Look for approval prompt (any "Do you want..." question)
if echo "$OUTPUT" | grep -q "Do you want"; then
# Check if already waiting for response
if [ -f "$PENDING_FILE" ]; then
# Check for user response
if [ -f "$RESPONSE_FILE" ]; then
RESPONSE=$(cat "$RESPONSE_FILE")
echo "[Interactive-Approver] User responded: $RESPONSE"
case "$RESPONSE" in
yes|1)
echo "[Interactive-Approver] Approving (option 1)..."
tmux send-keys -t "$SESSION_NAME" Enter
;;
always|2)
echo "[Interactive-Approver] Approving always (option 2)..."
tmux send-keys -t "$SESSION_NAME" Down Enter
;;
no|3)
echo "[Interactive-Approver] Declining..."
tmux send-keys -t "$SESSION_NAME" Down Down Enter
;;
*)
echo "[Interactive-Approver] Unknown response, defaulting to decline"
tmux send-keys -t "$SESSION_NAME" Down Down Enter
;;
esac
rm -f "$PENDING_FILE" "$RESPONSE_FILE"
sleep 2
fi
else
# New prompt detected, notify user
echo "[Interactive-Approver] Approval prompt detected! Waiting for user decision..."
# Extract the prompt question
QUESTION=$(echo "$OUTPUT" | grep -A 10 "Do you want" | head -20)
# Write to pending file
cat > "$PENDING_FILE" << EOF
Session: $SESSION_NAME
Timestamp: $(date)
Prompt:
$QUESTION
To respond, write one of these to: $RESPONSE_FILE
yes - Approve this once (option 1)
always - Approve and don't ask again for this project (option 2)
no - Decline (option 3)
EOF
echo "[Interactive-Approver] Pending approval written to: $PENDING_FILE"
fi
fi
sleep 1 # Check every second
done