---
name: gh-compact-pr-monitor
description: Produce compact, read-only GitHub pull-request and Actions-run snapshots with exact-head, job-stage, artifact, remote-branch, and local-cleanliness checks. Use when checking or repeatedly monitoring a PR, CI run, workflow, submission branch, or acceptance signal across any GitHub repository while avoiding large comment bodies, full logs, and unchanged-status narration.
---

# Compact GitHub PR Monitor

The helper uses Python 3.11 or newer, authenticated `gh`, and `git`. Keep cached state outside the repository you are monitoring.

Use `scripts/compact_pr_monitor.py` before making several separate `gh` and
`git` calls. It reports the current PR head, labels, run state, passed/active
jobs, earliest failed job and step, artifact count, local cleanliness, remote
branch head, and identity agreement.

## Routine check

Run:

```text
python <skill>/scripts/compact_pr_monitor.py \
  --repo OWNER/REPO \
  --pr NUMBER \
  --run-id RUN_ID \
  --local-repo /path/to/checkout \
  --remote fork \
  --expected-head FULL_SHA
```

Omit `--run-id` to select the newest run whose `headSha` equals the current PR
head. Add `--workflow NAME` when more than one workflow can run on that head.
Omit local or remote arguments when those checks do not apply.

For recurring monitoring, add:

```text
--state-file /path/outside/production/repo/pr-monitor.json --quiet-unchanged
```

Keep the state file outside the monitored production repository. The script
updates only that local cache; all GitHub and repository checks are read-only.
The state claim is serialized so overlapping monitor turns cannot both report
the same transition. `--quiet-unchanged` emits zero bytes and returns success,
including when the cached transition is a terminal failure.

Use `--format json` when another tool needs structured output.

## Escalation

- If the snapshot is healthy, queued, or in progress, do not fetch comments,
  reviews, annotations, or logs.
- If identity is `mismatch`, stop mutation and reconcile the exact PR, run,
  local, and remote heads.
- If the run fails, inspect only the reported earliest failed job and failed
  step first. Then fetch that job's annotations/log and material artifacts.
- Treat downstream skipped or fail-closed jobs as noncausal until the earliest
  producer is classified.
- Fetch PR comments or review bodies only when a failure, acceptance signal, or
  explicit user request makes them material.
- Do not rerun workflows, change labels, post comments, or edit repositories
  merely because this monitoring skill was invoked.

## Exit codes

- `0`: healthy, pending, successful, or unchanged snapshot
- `1`: invalid input or a `gh`/`git` query failed
- `2`: exact-head identity mismatch
- `3`: newly observed terminal failed transition

Report only meaningful transitions. Never restate an unchanged terminal
failure. If the user requested recurring monitoring that stops on failure, pause
that automation before its single terminal notification and verify the pause.
Do not create or change an automation merely because a manual status check
finds a failure. Atomically claim the exact head/run/attempt/producer event
fingerprint. A duplicate fingerprint is `DONT_NOTIFY`, not another failure report.

The CLI requires a pull request. For a branch-only Actions run, use bounded read-only
`gh run view` plus local/remote head checks rather than inventing a PR number.

When upgrading a schema-1 cache that lacks `run_attempt`, seed a schema-2 cache
from exact run metadata when available. Otherwise the monitor conservatively
treats the same head/run/conclusion as already delivered so migration itself
cannot repeat a terminal failure. Notification claiming is at-most-once; it
does not claim transport-level exactly-once delivery.
