Files
timmy-config/hermes-sovereign/guards/max-attempts.sh
Alexander Whitestone 530f84b92f feat: add 5 poka-yoke guards for agent fleet
Guards added:
- api-key-preflight.sh: validates API keys before loop starts
- duplicate-pr-gate.sh: prevents duplicate PRs for same issue
- hardcoded-ip-scanner.sh: pre-commit hook rejecting hardcoded VPS IPs
- quality-verify.sh: verifies PRs have real diffs after agent success
- max-attempts.sh: tracks attempts per issue, skips after 3 failures

All guards tested and verified working.
Hardcoded IP scanner symlinked as pre-commit hook.

Note: --no-verify used because the scanner script itself contains
the IP patterns as definitions (not actual hardcoded usage).
2026-04-07 10:23:36 -04:00

38 lines
1021 B
Bash
Executable File

#!/bin/bash
# max-attempts.sh <agent> <issue_number> [max_attempts]
# Exit 0 = attempt allowed, Exit 1 = max attempts exceeded, skip permanently
AGENT="$1"
ISSUE="$2"
MAX="${3:-3}"
ATTEMPTS_FILE="$HOME/.hermes/logs/${AGENT}-attempts.json"
if [ -z "$AGENT" ] || [ -z "$ISSUE" ]; then
echo "Usage: max-attempts.sh <agent_name> <issue_number> [max_attempts]"
exit 2
fi
# Ensure logs dir exists
mkdir -p "$HOME/.hermes/logs"
# Initialize if needed
[ ! -f "$ATTEMPTS_FILE" ] && echo '{}' > "$ATTEMPTS_FILE"
# Read current count
COUNT=$(python3 -c "import json; d=json.load(open('$ATTEMPTS_FILE')); print(d.get('$ISSUE',0))" 2>/dev/null)
COUNT=${COUNT:-0}
if [ "$COUNT" -ge "$MAX" ]; then
echo "SKIP: Issue #$ISSUE exceeded $MAX attempts by $AGENT"
exit 1
fi
# Increment
python3 -c "
import json
with open('$ATTEMPTS_FILE') as f: d=json.load(f)
d['$ISSUE'] = d.get('$ISSUE',0) + 1
with open('$ATTEMPTS_FILE','w') as f: json.dump(d,f,indent=2)
print(f'ATTEMPT {d[\"$ISSUE\"]}/$MAX for #$ISSUE by $AGENT')
"
exit 0