#!/usr/bin/env bash # Auto-commit + push loop for CausalGrok. # # Every INTERVAL seconds (default 900 = 15 min) this: # 1. Stages safe paths (paper_figures/, experiments/*.py, scripts/*.sh, # *.md, plus mechinterp/*.json under experiments/runs/) — never # adds checkpoints (*.pt) or large per-run logs. # 2. If there are staged changes, commits with a uniform message and # pushes to origin master. # 3. Logs everything to logs/auto_commit_push.log. # # Usage: # nohup bash scripts/auto_commit_push.sh > /dev/null 2>&1 & # disown # tail -f logs/auto_commit_push.log # # Stop: # pkill -f "auto_commit_push.sh" set +e # tolerate transient git/network errors; loop continues ROOT="$(cd "$(dirname "$0")/.." && pwd)" cd "$ROOT" INTERVAL="${INTERVAL:-900}" # 15 min default LOG="logs/auto_commit_push.log" mkdir -p logs stamp() { date -u +"[%FT%TZ]"; } echo "$(stamp) auto-pusher starting (interval ${INTERVAL}s, repo=$(pwd))" >> "$LOG" while true; do # Stage all paths the user wants on GitHub. # `git add -A` would also add .pt files but they're now in .gitignore so # they're excluded automatically. git add -A 2>>"$LOG" # Belt-and-suspenders: explicitly drop any *.pt that might have slipped # through (e.g., if .gitignore is briefly missing the rule). git diff --cached --name-only | grep '\.pt$' | while read f; do git rm --cached -- "$f" 2>/dev/null done # If anything is staged, commit + push. if ! git diff --cached --quiet; then files=$(git diff --cached --name-only | wc -l | tr -d ' ') msg="auto: snapshot $(date -u +%FT%TZ) ($files file$([ "$files" = 1 ] || echo s))" echo "$(stamp) committing: $msg" >> "$LOG" git diff --cached --name-only | sed 's/^/ /' >> "$LOG" if git commit -m "$msg" >>"$LOG" 2>&1; then git push origin master >>"$LOG" 2>&1 echo "$(stamp) pushed." >> "$LOG" else echo "$(stamp) commit failed; resetting index" >> "$LOG" git reset >>"$LOG" 2>&1 fi else echo "$(stamp) nothing to commit" >> "$LOG" fi sleep "$INTERVAL" done