-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-audit-loop.sh
More file actions
executable file
·92 lines (71 loc) · 2.96 KB
/
Copy pathrun-audit-loop.sh
File metadata and controls
executable file
·92 lines (71 loc) · 2.96 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
#!/bin/bash
# run-audit-loop.sh — Runs audit + fix cycle every 2 hours overnight
# Usage: ./run-audit-loop.sh
# Stop: Ctrl+C or kill the process
#
# This script runs in auto mode so Claude can both find AND fix issues.
# Each cycle: audit → fix → commit fixes → wait 2 hours → repeat
set -uo pipefail
INTERVAL_SECONDS=7200 # 2 hours
PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$PROJECT_DIR"
echo "============================================"
echo " Unit Overnight Audit Loop"
echo " Interval: every $((INTERVAL_SECONDS / 3600)) hours"
echo " Started: $(date)"
echo " Project: $PROJECT_DIR"
echo " Press Ctrl+C to stop"
echo "============================================"
echo ""
CYCLE=1
while true; do
TIMESTAMP="$(date +%Y-%m-%d_%H%M)"
REPORT="audit-report-${TIMESTAMP}.md"
echo "──────────────────────────────────────────"
echo "Cycle $CYCLE — Starting at $(date)"
echo "Report: $REPORT"
echo "──────────────────────────────────────────"
# Build the prompt with the report filename injected
AUDIT_PROMPT="You are running an automated overnight audit+fix cycle for the Unit iOS app.
## Phase 1: Audit
Follow the full audit process in audit-prompt.md (read it first).
## Phase 2: Fix
After completing the audit, fix every issue you found:
- Fix all design system violations (raw colors -> AppColor.*, raw fonts -> AppFont.*, etc.)
- Fix compass alignment issues (remove banned UI patterns)
- Fix edge case bugs
- Do NOT change app architecture or add new features — only fix violations and bugs
## Phase 3: Report
Write the audit report to ${REPORT}.
## Phase 4: Commit
After fixing, stage all changed .swift files and commit with message:
Auto-audit fixes — ${TIMESTAMP}
followed by a 2-3 line summary of what was fixed.
End with: Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Do NOT push to remote. Only commit locally."
# Run the audit in auto mode with up to 3 retries on failure
MAX_RETRIES=3
ATTEMPT=1
EXIT_CODE=1
while [ $ATTEMPT -le $MAX_RETRIES ] && [ $EXIT_CODE -ne 0 ]; do
if [ $ATTEMPT -gt 1 ]; then
echo " Retry $ATTEMPT/$MAX_RETRIES after 60s cooldown..."
sleep 60
fi
claude --dangerously-skip-permissions -p "$AUDIT_PROMPT" > "$REPORT" 2>&1
EXIT_CODE=$?
ATTEMPT=$((ATTEMPT + 1))
done
if [ $EXIT_CODE -eq 0 ]; then
echo "✓ Cycle $CYCLE completed successfully at $(date)"
else
echo "✗ Cycle $CYCLE failed after $MAX_RETRIES attempts (exit $EXIT_CODE) at $(date)"
fi
echo " Report: $REPORT"
echo ""
CYCLE=$((CYCLE + 1))
echo "Sleeping $((INTERVAL_SECONDS / 3600)) hours until next cycle..."
echo "Next run: $(date -v+${INTERVAL_SECONDS}S 2>/dev/null || date -d "+${INTERVAL_SECONDS} seconds" 2>/dev/null || echo "in $((INTERVAL_SECONDS / 3600)) hours")"
echo ""
sleep $INTERVAL_SECONDS
done