-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecurity-agent-loop.sh
More file actions
executable file
·71 lines (57 loc) · 2.81 KB
/
security-agent-loop.sh
File metadata and controls
executable file
·71 lines (57 loc) · 2.81 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
#!/bin/bash
# Security Agent Continuous Monitoring Loop
# Runs indefinitely, checking for completed requirements every 10 seconds
PROJECT_ROOT="/home/user/Tradingpoly"
REQUIREMENTS_FILE="$PROJECT_ROOT/REQUIREMENTS.md"
FINDINGS_FILE="$PROJECT_ROOT/SECURITY_FINDINGS.md"
STATE_FILE="$PROJECT_ROOT/.security-agent-state"
# Initialize state file
if [ ! -f "$STATE_FILE" ]; then
echo "0" > "$STATE_FILE"
fi
echo "╔══════════════════════════════════════════════════════════╗"
echo "║ SECURITY AGENT - CONTINUOUS MONITORING MODE ║"
echo "╚══════════════════════════════════════════════════════════╝"
echo ""
echo "Started: $(date '+%Y-%m-%d %H:%M:%S')"
echo "Monitoring: $REQUIREMENTS_FILE"
echo "Output: $FINDINGS_FILE"
echo ""
echo "Press Ctrl+C to stop monitoring"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
LOOP_COUNT=0
while true; do
LOOP_COUNT=$((LOOP_COUNT + 1))
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
# Get current completed count
COMPLETED_NOW=$(grep -c "^- \[x\]" "$REQUIREMENTS_FILE" 2>/dev/null || echo "0")
COMPLETED_PREV=$(cat "$STATE_FILE")
# Display status
echo "[$TIMESTAMP] Check #$LOOP_COUNT - Completed requirements: $COMPLETED_NOW"
# Check if new requirements have been completed
if [ "$COMPLETED_NOW" -gt "$COMPLETED_PREV" ]; then
NEW_COMPLETED=$((COMPLETED_NOW - COMPLETED_PREV))
echo ""
echo "🔔 ALERT: $NEW_COMPLETED new requirement(s) completed!"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Show which requirements were completed
echo "Newly completed requirements:"
grep "^- \[x\]" "$REQUIREMENTS_FILE" | tail -$NEW_COMPLETED
echo ""
# Run security scan
echo "🔍 Running security scan..."
echo ""
$PROJECT_ROOT/security-scan.sh
echo ""
# Update state
echo "$COMPLETED_NOW" > "$STATE_FILE"
# Update monitoring activity in findings file
echo "[$TIMESTAMP] Reviewed $NEW_COMPLETED newly completed requirement(s)" >> "$FINDINGS_FILE.activity.log"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
fi
# Sleep for 10 seconds
sleep 10
done