Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112#!/usr/bin/env bash# bootcc autonomous crank driver.## Loops: read TASKS/NEXT.md, launch a headless `crush run` to perform that one# increment against /home/lrvick/Sources/bootcc, wait, and if it committed,# advance. Crash-resilient: each agent commits its verified step.## Stall guard: every agent runs under `timeout $AGENT_TIMEOUT`. If an agent# exceeds the bound or makes no commit, the task is parked under TASKS/blocked-*# and the crank moves to the next queue item instead of retrying forever.## Usage: ./crank.sh [--once]# Env: CRUSH_BIN, AGENT_TIMEOUT (s), MAX_ITER, DRY_RUN=1
set -ucd /home/lrvick/Sources/bootcc || exit 2
CRUSH_BIN="${CRUSH_BIN:-/home/lrvick/.local/bin/crush}"AGENT_TIMEOUT="${AGENT_TIMEOUT:-1200}"MAX_ITER="${MAX_ITER:-1000}"ITER=0PARKCOUNT=0LAST_COMMIT="$(git rev-parse HEAD 2>/dev/null)"
log() { echo "[crank] $*"; }
pick_next() { if [ -s TASKS/NEXT.md ] && grep -q '^# Task' TASKS/NEXT.md 2>/dev/null; then return 0 fi local item item="$(grep -m1 '^- \[ \]' TASKS/QUEUE.md || true)" if [ -z "$item" ]; then return 1; fi { echo "# Task — $(echo "$item" | sed 's/^- \[ \] //')" echo echo "Single-task continuation of the bootcc project (see AUTONOMY.md)." echo "Read AUTONOMY.md, STATE.md, and QUEUE.md before acting." echo "Do the single smallest verifiable increment for:" echo " $item" echo echo "Requirements: file(s) end with a trailing newline; M2-subset" echo "(integer-only, no for(;;), no long long, no variadic stdlib);" echo "PROVE it via 'make' then 'make test' (all PASS, 0 failed) before" echo "committing; commit with a clear message; append to LOG.md; mark" echo "this line in QUEUE.md from '- [ ]' to '- [x]'; rewrite this" echo "NEXT.md into the concrete next single increment; update STATE.md." } > TASKS/NEXT.md return 0}
park_blocked() { local stamp stamp="$(date +%s)" if [ -f TASKS/NEXT.md ]; then cp TASKS/NEXT.md "TASKS/blocked-${stamp}.md" 2>/dev/null log "blocked current NEXT as TASKS/blocked-${stamp}.md" # Clear NEXT so the next pick advances, never re-running the same # task forever (this was the cause of the earlier silent retry loop). rm -f TASKS/NEXT.md fi # 3-strike cap: after three consecutive parks, drop the front open queue # item so the churn moves on instead of looping on a hopeless task. PARKCOUNT=$((PARKCOUNT+1)) if [ "$PARKCOUNT" -ge 3 ]; then log "3-strike: dropping the front open queue item." awk 'BEGIN{seen=0} { if (!seen && /^- \[ \] /){seen=1; next} print }' TASKS/QUEUE.md > TASKS/QUEUE.md.tmp && mv TASKS/QUEUE.md.tmp TASKS/QUEUE.md PARKCOUNT=0 fi}
while [ "$ITER" -lt "$MAX_ITER" ]; do ITER=$((ITER+1)) log "iteration $ITER"
if [ -f TASKS/HALT ]; then log "halt file present; stopping"; break; fi
pick_next || { log "queue empty / no NEXT; stopping"; break; }
log "launching headless agent for: $(head -1 TASKS/NEXT.md)" if [ "${DRY_RUN:-0}" = "1" ]; then log "DRY-RUN: would run: $CRUSH_BIN run --quiet < TASKS/NEXT.md" break fi
timeout "$AGENT_TIMEOUT" "$CRUSH_BIN" run --quiet \ "$(cat TASKS/NEXT.md)" >crank-agent.out 2>crank-agent.err RC=$?
NEW_COMMIT="$(git rev-parse HEAD 2>/dev/null)" ADVANCED=0 if [ -n "$NEW_COMMIT" ] && [ "$NEW_COMMIT" != "$LAST_COMMIT" ]; then ADVANCED=1; fi
if [ "$ADVANCED" = "1" ]; then log "commit advanced: ${LAST_COMMIT:0:8} -> ${NEW_COMMIT:0:8}" LAST_COMMIT="$NEW_COMMIT" # Mark only the first open queue line done (the one this task stood # for); do NOT strip every open line, or the churn target is lost. if [ -f TASKS/QUEUE.md ]; then awk 'BEGIN{seen=0} { if(!seen && /^- \[ \] /){sub(/^- \[ \] /,"- [x] ");seen=1} print }' TASKS/QUEUE.md > TASKS/QUEUE.md.tmp && mv TASKS/QUEUE.md.tmp TASKS/QUEUE.md fi else log "no commit (rc=$RC, timeout=${AGENT_TIMEOUT}s). Parking task and advancing." park_blocked fi
if [ "${1:-}" = "--once" ]; then log "once-mode; exiting"; break; fi sleep 10done
log "crank finished after $ITER iterations"