#!/bin/bash # Wait until a dispatched Hermes worker session finishes its turn (or goes silent), then print # worktree state. Use when `hermes -p chat --oneshot -Q` exited with "Gateway disconnected" # but the session keeps running server side. Run with terminal(background=true, notify=true) # so the PM is notified on completion instead of polling. # Usage: wait-worker-idle.sh [idle_seconds=900] # Idle default is long on purpose: flutter/xcode builds run 4+ minutes without writing a log line, # so a short idle threshold reports a live worker as stopped. P="$1"; SID="$2"; WT="$3"; IDLE="${4:-900}" LOG="$HOME/.hermes/profiles/$P/logs/agent.log" [ -f "$LOG" ] || { echo "log yok: $LOG"; exit 2; } ts() { date -j -f "%Y-%m-%d %H:%M:%S" "$1" +%s 2>/dev/null || echo 0; } while true; do last=$(grep "$SID" "$LOG" | grep -E "API call|tool .* completed" | tail -1 | cut -c1-19) lt=$(ts "$last") tend=$(grep "$SID" "$LOG" | grep "Turn ended" | tail -1 | cut -c1-19) if [ -n "$tend" ] && [ "$(ts "$tend")" -ge "$lt" ]; then echo "tur bitti: $tend"; break; fi if [ $(( $(date +%s) - lt )) -gt "$IDLE" ]; then echo "durdu (tur bitmeden): son etkinlik $last"; break; fi sleep 60 done git -C "$WT" log --oneline -5 git -C "$WT" status --short | head -40