Files
pyramid/autopilot.sh
T

73 lines
3.7 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Pyramid-Autopilot (Pi/Linux): startet Claude-Sessions in Endlosschleife.
# Laeuft eine Session ins Limit, wird alle 20 Minuten neu versucht.
# Start (am besten in tmux): tmux new -d -s pyramid ./autopilot.sh
# Wieder reinschauen: tmux attach -t pyramid (verlassen: Strg+B, dann D)
# PAUSIEREN: touch ~/pyramid/PAUSE (greift vor der naechsten Session)
# FORTSETZEN: rm ~/pyramid/PAUSE
# GANZ STOPPEN: tmux kill-session -t pyramid
cd "$(dirname "$0")"
export PATH="$HOME/.local/bin:$HOME/flutter/bin:$PATH"
# --- NUR EIN Konto: das nordmann-Konto (Profil ~/.claude = Standard-Profil) ---
# Bewusst KEINE Konto-Rotation (Bernd, 2026-07-06): der Pyramid-Autopilot arbeitet
# ausschliesslich mit dem nordmann-Konto. Das Standard-Profil liegt unter
# ~/.claude / ~/.claude.json -> CLAUDE_CONFIG_DIR NICHT setzen (sonst sucht Claude
# die Config faelschlich unter ~/.claude/.claude.json).
# (Die E-Mail-Adresse des Kontos steht absichtlich NICHT hier: das Gitea-Repo
# ist oeffentlich, PII gehoert nicht hinein.)
apply_account() { unset CLAUDE_CONFIG_DIR; }
ACCOUNT_NAME="nordmann"
# --- Matrix-Statusberichte (Raum "🔺 Pyramid Autopilot", Token vom Gatus-Bot) ---
MATRIX_URL="http://127.0.0.1:6167"
MATRIX_ROOM="!sYfOwD4Dw4jBDTlNmL:steggi-matrix.work"
MATRIX_TOKEN="$(grep -s '^MATRIX_TOKEN=' "$HOME/gatus/.env" | cut -d= -f2-)"
notify_matrix() {
[ -z "$MATRIX_TOKEN" ] && return 0
local body
body=$(python3 -c 'import json,sys; print(json.dumps({"msgtype":"m.text","body":sys.stdin.read().strip()}))' <<< "$1")
curl -s -m 10 -X PUT \
"$MATRIX_URL/_matrix/client/v3/rooms/$MATRIX_ROOM/send/m.room.message/autopilot$(date +%s%N)" \
-H "Authorization: Bearer $MATRIX_TOKEN" -H "Content-Type: application/json" \
-d "$body" > /dev/null || true
}
PROMPT="Lies CLAUDE.md. Arbeite in dieser Reihenfolge: (1) Review-Pass: Gehe die in ROADMAP.md/PROGRESS.md als erledigt markierten Punkte durch, prüfe den zugehörigen Code kritisch und überarbeite/verbessere ihn, wo nötig. Führe in PROGRESS.md einen Abschnitt 'Fable-5-Review' und hake dort jeden geprüften Punkt ab, damit bereits reviewte Punkte nicht erneut geprüft werden. (2) Wenn alle erledigten Punkte reviewt sind, arbeite ROADMAP.md Punkt für Punkt weiter ab. Halte dich strikt an den Arbeitszyklus (PROGRESS.md pflegen, kleine Commits + Push). Arbeite so viel ab wie möglich."
while true; do
if [ -f PAUSE ]; then
echo "===== $(date '+%F %T') PAUSE aktiv (rm PAUSE zum Fortsetzen) - pruefe wieder in 10 Minuten ====="
sleep 600
continue
fi
apply_account
echo "===== $(date '+%F %T') Neue Claude-Session (Konto $ACCOUNT_NAME) =====" | tee -a autopilot.log
BEFORE=$(git rev-parse HEAD 2>/dev/null)
SESSION_OUT=$(mktemp)
claude -p "$PROMPT" --model claude-fable-5 --dangerously-skip-permissions 2>&1 | tee -a autopilot.log "$SESSION_OUT"
AFTER=$(git rev-parse HEAD 2>/dev/null)
if [ -n "$BEFORE" ] && [ "$BEFORE" != "$AFTER" ]; then
COMMITS=$(git log --oneline --no-decorate "$BEFORE..$AFTER" | head -15)
NEXT=$(grep -m1 -A3 "Offen/Nächster Schritt" PROGRESS.md)
notify_matrix "🔺 Pyramid-Autopilot $(date '+%H:%M') Session fertig.
Neue Commits:
$COMMITS
$NEXT"
fi
# Limit erkannt? -> 20 Minuten warten (KEINE Konto-Rotation mehr)
if grep -qiE "hit your.*limit|usage limit|session limit" "$SESSION_OUT"; then
rm -f "$SESSION_OUT"
echo "===== $(date '+%F %T') nordmann-Konto am Limit - naechster Versuch in 20 Minuten =====" | tee -a autopilot.log
sleep 1200
continue
fi
rm -f "$SESSION_OUT"
echo "===== $(date '+%F %T') Session beendet - Neustart in 20 Minuten (Strg+C zum Stoppen) =====" | tee -a autopilot.log
sleep 1200
done