#!/usr/bin/env bash
set -euo pipefail

if [[ "${1:-}" == "-h" || "${1:-}" == "--help" || "$#" -lt 4 ]]; then
  cat <<'EOF'
Usage: .agent/scripts/devloop-wait <job-or-command> <proof-claim> <poll-in> <mode-task>

Record an active wait state with an explicit poll time and mode-rotation task.
Use immediately after starting a long test/import/daemon/build command.
EOF
  exit 0
fi

waiting_on="$1"
proof_claim="$2"
poll_in="$3"
mode_task="$4"

repo="${POLYLOGUE_REPO:-$(git rev-parse --show-toplevel 2>/dev/null || printf /realm/project/polylogue)}"
current="${POLYLOGUE_AGENT_CURRENT:-$repo/.agent/conductor-devloop}"
cd "$repo"

log_path="$current/OPERATING-LOG.md"
mkdir -p "$current"

"$(dirname "$0")/devloop-log" "wait state: $waiting_on" "\
Loop phase: verify | velocity
Focus: Proof -> Velocity
Waiting on: $waiting_on
Proof claim: $proof_claim
Next poll: $poll_in
Mode rotation: $mode_task
Escalation trigger: if the command exceeds the expected poll window without a
new signal, inspect job status/output and host pressure before starting any
duplicate heavy work.
Velocity note: waiting is active loop time; rotate focus deliberately, do the
mode task, then poll."

.agent/scripts/devloop-sync >/dev/null
printf '%s\n' "$log_path"
