#!/usr/bin/env bash
set -euo pipefail
REPO=gbharg/exult-agent
PR=67
reply() { gh api "repos/$REPO/pulls/$PR/comments/$1/replies" -f body="$2" >/dev/null; echo "replied $1"; }
resolve() { gh api graphql -f query='mutation($id:ID!){resolveReviewThread(input:{threadId:$id}){thread{isResolved}}}' -f id="$1" >/dev/null; echo "resolved $1"; }

# ---- Addressed in af31b21 / fb71336: reply + resolve ----
reply 3431626441 "Addressed in af31b21: lock/log/health moved out of /tmp into a private 0700 state dir (\$XDG_STATE_HOME/curogram-mcp)."
resolve PRRT_kwDOR5bkYM6KXPU2
reply 3431631594 "Addressed in af31b21: concurrent 401s now share a single relogin cycle via reloginInFlight, and the attempt counter tracks cycles (not parallel callers), so N parallel 401s no longer each burn an attempt."
resolve PRRT_kwDOR5bkYM6KXQNO
reply 3431635012 "Addressed in af31b21: relogin is deduped through reloginInFlight; concurrent 401s await one cycle instead of each incrementing the counter."
resolve PRRT_kwDOR5bkYM6KXQ0Q
reply 3431635017 "Addressed in af31b21: the fail-closed message now reports the member count so a members-shape drift is distinguishable from a genuine mismatch."
resolve PRRT_kwDOR5bkYM6KXQ0U
reply 3431635021 "Addressed in af31b21: the success response no longer echoes the full API object; it returns only message_id / status / created_at."
resolve PRRT_kwDOR5bkYM6KXQ0W
reply 3431635023 "Addressed in af31b21: renamed restarts_today to total_restarts (since-start semantics)."
resolve PRRT_kwDOR5bkYM6KXQ0Y
reply 3431635024 "Addressed in af31b21: _find_ai_extension now paginates through all extension pages."
resolve PRRT_kwDOR5bkYM6KXQ0Z
reply 3431635026 "Addressed in af31b21: _TOKEN_CACHE_KEYS hoisted to module scope."
resolve PRRT_kwDOR5bkYM6KXQ0a
reply 3431635028 "Addressed in af31b21: MFA check tightened to Array.isArray(login.mfa) && login.mfa.length > 0."
resolve PRRT_kwDOR5bkYM6KXQ0d
reply 3431646815 "Addressed in af31b21: relogin deduped via reloginInFlight so concurrent 401s share one cycle and don't each burn an attempt."
resolve PRRT_kwDOR5bkYM6KXS35
reply 3431646818 "Addressed in fb71336: health file is now written to a temp file and mv'd into place (atomic)."
resolve PRRT_kwDOR5bkYM6KXS37
reply 3431646828 "Addressed in af31b21: renamed to total_restarts."
resolve PRRT_kwDOR5bkYM6KXS4C
reply 3431646831 "Addressed in af31b21: _TOKEN_CACHE_KEYS moved to module scope."
resolve PRRT_kwDOR5bkYM6KXS4F
reply 3431646837 "Addressed in af31b21: _find_ai_extension now paginates."
resolve PRRT_kwDOR5bkYM6KXS4I
reply 3431646840 "Confirmed/kept fail-closed; af31b21 also improved the diagnostic message (member count) and fb71336 made the JSON parse fail-closed too."
resolve PRRT_kwDOR5bkYM6KXS4K
reply 3431659367 "Addressed in fb71336: res.json() is now wrapped and fails closed (linked:false) if the members body isn't valid JSON."
resolve PRRT_kwDOR5bkYM6KXVGl
reply 3431659397 "Addressed in fb71336: numArg now coerces skip/take to a non-negative integer."
resolve PRRT_kwDOR5bkYM6KXVG2

# ---- Conscious trade-offs / minor: reply + resolve ----
reply 3431646804 "Intentional trade-off: an earlier review asked us to drop message_length/text from the dry-run to minimize PHI in tool output, and the caller already holds the message text it passed in. Leaving the message body out of would_send by design."
resolve PRRT_kwDOR5bkYM6KXS3w
reply 3431646844 "Noted as a minor perf item — a shared httpx.AsyncClient would save a few connections per write. Out of scope for this review pass; the correctness/safety behavior is unaffected."
resolve PRRT_kwDOR5bkYM6KXS4N

# ---- Recurring architecture / scope: reply, DO NOT resolve (Gautam's call) ----
reply 3431626438 "Same fresh-approval architecture question tracked elsewhere on this PR. Deferring to Gautam; leaving open."
reply 3431635464 "Duplicate of the send fresh-approval architecture question; deferring to Gautam. Leaving open."
reply 3431626446 "Scope-split decision for Gautam; leaving open."
reply 3431635466 "Scope-split decision for Gautam; leaving open."
reply 3431659416 "Scope-split decision for Gautam; leaving open."

echo "FINAL DONE"
