/skillbook-skills:copilot-review-smartfrom skillbook-skills
Smart Copilot PR-review watchdog (multi-repo) that reads review state + timestamps, checks merge conflicts first, and lets an LLM decide (rebase/review/fix/notify/wait) instead of pinging daily. Webhook-first Listener with Expectation fallback; cron as alternate mode. Use for PR monitors that kept spamming '@copilot code review'.
Ships in skillbook-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Webhook-first: a signed GitHub Delivery wakes one tick scoped to the affected
PR, and the fallback is an Expectation the tick arms (next_check_at) —
not a schedule. Cron is the alternate mode for Hosts that cannot expose a
public HTTPS endpoint. Design record:
docs/adr/0005-webhook-first-expectation-fallback.md (repo root).
Both modes drive open PRs toward a Copilot clean bill of health without
spamming: they ping @copilot code review only when a review is actually
useful, ask Copilot to resolve merge conflicts when needed, and tell the OWNER
when a PR is ready for human review — staying silent the rest of the time.
Triggers:
pr_monitor.mjs (next to this file) is the portable reference tick script:
plain ESM JavaScript, no build step, runs on Node >= 18 with an
authenticated gh CLI (see docs/adr/0002 for the repo's script standard).
It is env-driven and the repos to watch are passed as context, never
defaulted — an installed skill must not silently watch someone else's
repos:
DRY_RUN=1 PR_MONITOR_REPOS="your-org/your-repo" node pr_monitor.mjs
pr_monitor_webhook.mjs is the Listener (webhook transport only, no decision
logic): plain ESM, node:http, no dependencies. Its implementation lives in
the listener/ package next to this file (one module per concern — see
listener/README.md); the script itself is the CLI shim. It spawns ticks of
pr_monitor.mjs and arms their Expectations:
PR_MONITOR_REPOS="your-org/your-repo" \
PR_MONITOR_WEBHOOK_SECRET="$(openssl rand -hex 32)" \
PR_MONITOR_PUBLIC_URL="https://your-public-host" \
node pr_monitor_webhook.mjs --serve --setup-hooks
Other env: PR_MONITOR_STATE_PATH (default ~/.cache/pr-monitor/state.json)
and DRY_RUN=1 (print would-be comments, never post, never persist state).
The decision source — an explicit command, an explicit model+credential pair,
or the auto-discovered agent session, with its precedence, settings and launch
examples — is documented under
Decision source.
Tick (shipped):
node pr_monitor.mjs --repo owner/repo --json-reportnode pr_monitor.mjs --pr owner/repo#123 --json-reportPR_MONITOR_REPOS, PR_MONITOR_PR, PR_MONITOR_REPORT=jsonlowner/repo#123 or https://github.com/owner/repo/pull/123Listener (webhook mode):
node pr_monitor_webhook.mjs --serve [--setup-hooks] [--keep-alive] [--tunnel ngrok|cloudflared]node pr_monitor_webhook.mjs --daemon / --stop / --statusnode pr_monitor_webhook.mjs --setup-hooks [--rotate-secret] / --list-hooks / --teardownContract:
--json-report / PR_MONITOR_REPORT=jsonl emits one JSON line per PR plus
one overall JSON line at the end for machine-readable loop control. Each PR
line carries next_check_at and owner_notifications for the Listener.DRY_RUN=1 still prints would-be comments, but never posts to GitHub and never
persists state.Implementation status:
pr_monitor_webhook.mjs)next_check_at + structured owner notifications in the tick reportHarness command:
npm run harness:copilot-review-smart -- all-clear-human
npm run harness:copilot-review-smart -- loop-single-pr-to-done --loop
Loop recipe (caller-owned; the script never sleeps):
done: true, tell the owner the scope reached either All-clear or
needs-human, then stop.Terminal meanings in the JSON report:
terminal: "done" → All-clear observed; Notify-ready path.terminal: "needs-human" → the loop cannot safely advance on its own for this
head sha (for example conflict retries exhausted, or recurring LLM failure).terminal: "skipped" → draft/WIP PR skipped entirely and excluded from loop
completion.Full design record:
docs/adr/0005-webhook-first-expectation-fallback.md (repo root).
A delivery is a trigger, not a decision: it wakes one tick scoped to the
affected PR (--pr), and the existing gates + LLM decide the next step.
Lifecycle:
--setup-hooks, idempotent, bound by hook id)
and starts the Listener (--serve foreground, --daemon detached so the
invoking session can end).PR_MONITOR_STARTUP_TICK=0 disables).PR_MONITOR_DEBOUNCE_MS, default 30s) and queued; one tick runs at
a time as node pr_monitor.mjs --pr owner/repo#123 --json-report.next_check_at per PR and the Listener arms it. If
no Delivery arrives first, it runs a Fallback tick — the only fallback,
there is no periodic sweep. next_check_at: null means the PR is quiescent.notify_ready (All-clear) or when the PR is closed or
merged; needs-human keeps its weekly retry. When no open PR is left to
watch, the Listener exits (--keep-alive keeps it up under a supervisor).
Pending Expectations, confirmed PR-closure evidence and Hook ids persist in
the Listener state file and survive restarts.Events subscribed (all filtered by watched repo): pull_request opened /
synchronize / reopened / ready_for_review / converted_to_draft /
closed; pull_request_review submitted / dismissed;
pull_request_review_comment created; issue_comment created / edited.
Security: X-Hub-Signature-256 (HMAC-SHA256 over the raw body, constant-time
compare) with PR_MONITOR_WEBHOOK_SECRET; the Listener refuses to start
without it. PR_MONITOR_LOGIN (default from gh api user) filters the loop's
own comments.
Serving and management:
POST /github/webhook, GET /healthz (liveness + last Delivery);
PR_MONITOR_WEBHOOK_HOST/PORT (default 127.0.0.1:8787), JSONL log to
stdout (PR_MONITOR_WEBHOOK_LOG optional).--setup-hooks [--rotate-secret], --list-hooks, --teardown: manage the
GitHub-side Hook. Setup verifies PR_MONITOR_PUBLIC_URL reaches the
Listener and waits for GitHub's ping before reporting success; it refuses
to create a Hook it cannot verify.PR_MONITOR_NOTIFY_CMD: owner notifications (notify_ready,
needs-human, escalation) as JSON on stdin, 30s timeout, failures logged
only.--tunnel ngrok|cloudflared: spawn a tunnel, use its public URL for setup,
clean it up on exit (dev convenience; the Hook is updated by id).PR_MONITOR_TICK_TIMEOUT (5 min) kills a hung tick; failed ticks re-arm
their Expectation with backoff (1 → 5 → 15 min, then hourly).https://<host>.<tailnet>.ts.net), ngrok or
cloudflared. Recipes and platform-agnostic deploy files in
resources/deploy/.Cron remains the alternate mode for Hosts that cannot expose a public endpoint; everything below applies unchanged.
A separate loopback process projects the persisted state — it is not part of the Listener (which is ephemeral and absent under tick and cron), so it answers in every mode and whether or not the watchdog is running. It holds no state of its own and never writes; GET only, no version prefix:
node pr_monitor_observability.mjs # http://127.0.0.1:8788 by default
curl -s http://127.0.0.1:8788/flows | jq
Routes: /health (watchdog liveness, in the Listener's health shape),
/timeline (executed, in-flight and scheduled ticks), /flows (one row per
watched PR with its Stage sequence) and /flows/:owner/:repo/:num (one Flow
in full; 404 when unknown). Stage statuses, outcomes and terminal words use
GLOSSARY.md; the projection derivation is documented in
observability/README.md.
pr_monitor_tui.mjs is the coloured client of that contract — one command,
no setup beyond the API being reachable:
node pr_monitor_tui.mjs # refresh every 2s; Ctrl-C exits
node pr_monitor_tui.mjs --once # one frame, for scripts
node pr_monitor_tui.mjs --url http://127.0.0.1:8788 --interval 5000
The header is the loop's tick timeline: ticks done (with the last one), the
in-flight tick and when the next check fires. One line per watched PR shows
its Stage sequence in glossary order — collect check reuse decide act schedule — with past green, current bold yellow and next grey,
then the terminal outcome in the glossary's words (All-clear / Notify-ready, Stuck PR, Needs-human; waiting is not terminal). The TUI
reads only GET /timeline and GET /flows; it never touches the state
files. When the API is unreachable it names the URL, says what to start and
keeps retrying. Settings: --url / PR_MONITOR_OBSERVABILITY_URL (default
http://127.0.0.1:8788), --interval / PR_MONITOR_TUI_INTERVAL_MS
(default 2000), --once, --color / --no-color / NO_COLOR.
Settings (flags override env): --host /
PR_MONITOR_OBSERVABILITY_HOST (loopback only; default 127.0.0.1),
--port / PR_MONITOR_OBSERVABILITY_PORT (default 8788), --state /
PR_MONITOR_STATE_PATH (Tick state, default ~/.cache/pr-monitor/state.json),
--listener-state / PR_MONITOR_WEBHOOK_STATE_PATH (default
~/.cache/pr-monitor/listener-state.json) and --pid /
PR_MONITOR_WEBHOOK_PID_PATH (default ~/.cache/pr-monitor/listener.pid).
The implementation is the private observability/ package
(@skillbook/pr-monitor-observability, zero dependencies).
for each open PR:
draft or WIP-titled? → SKIP (record skip_wip, no LLM, no ping)
mergeable_state == "dirty"? → REBASE-POLICY (below)
mergeable == None? → per-PR fetch; still None → wait
signature unchanged? → reuse cached decision (no LLM call)
else → LLM decides: request_review | request_fix | notify_ready | wait
Rebase policy (for dirty PRs, evaluated BEFORE the LLM):
newest non-Copilot conflict-resolution request on this head sha:
none → request_rebase (ask Copilot to resolve conflicts)
< 6h old → wait (give Copilot its window)
>= 6h, pings < 3 → request_rebase again (retry)
>= 6h, pings >= 3 → notify owner ONCE per sha; retry weekly
next_check_at derivation policy (the Expectation contract)The tick derives each PR's next_check_at from state, not from the LLM, so a
reused cached decision carries the same deadline a fresh one would. This table
is the complete policy — every arm in the derivation corresponds to a row here,
and a deadline is never anchored at now: a stale anchor advances by whole
weeks instead of collapsing into an immediate re-arm (a Fallback tick storm).
Weekly retries anchor at the escalation moment recorded in state
(stuck_notified_ts, review_fix_exhausted_ts), not at the last ping.
| State (first match wins) | next_check_at |
|---|---|
notify_ready / skip_wip (draft/WIP) | null — quiescent; only a Delivery wakes it |
Recurring LLM failure (llm_failed) | now + 1h |
| Review/fix budget exhausted (needs-human) | exhaustion moment + 168h (weekly, whole weeks) |
| Review/fix exhausted with no recorded exhaustion ts (legacy state) | last ping + 168h (weekly, whole weeks) |
| Stuck PR, owner escalated (conflicts + pings >= 3) | escalation moment + 168h (weekly, whole weeks) |
| Stuck PR with no recorded escalation ts (legacy state) | last ping + 168h (weekly, whole weeks) |
| Active work (last commit < 3h) | last commit + 3h |
| A Ping just posted this run | ping + 12h (review/fix) or + 6h (rebase) |
| Review/fix Ping pending a response | last ping + 12h |
| Rebase Ping inside its 6h same-sha throttle | last rebase ping + 6h (never the older request's deadline) |
| Mergeability unknown | now + 1h |
| Conflicts with a pending resolution request | request + 6h |
| Newest Copilot review < 6h old | review + 6h |
| Otherwise | null — quiescent |
| Action | When (decided by) | Message |
|---|---|---|
request_rebase | dirty PR (HARD gate, deterministic) | @copilot resolve the merge conflicts between this branch and origin/main. Be wise with the strategy: … (see script — wisdom policy: preserve BOTH branches, drop only what belongs to the new features; on doubt consult spec/tickets/docs, then ask the user) |
request_review | new commits unseen by Copilot (LLM) | @copilot code review |
request_fix | unaddressed review comments (LLM) | @copilot work on the issues mentioned in these comments <urls> |
notify_ready | review transcript reached an All-clear on the current head (LLM) | owner notification only — NEVER pings GitHub |
wait | not enough info / too soon (LLM or gates) | silence |
A Tick resolves one decider per invocation, first match wins:
decision command → model+credential pair → auto → none
Decision command — PR_MONITOR_LLM_CMD: the request goes to the
command on stdin, a {"action","reason"} JSON decision comes back on
stdout. Timeout PR_MONITOR_LLM_CMD_TIMEOUT_MS (default 60000 ms). The
universal adapter — any agent CLI that answers a prompt non-interactively
fits. Non-zero exit, timeout and unparseable output are real decision
failures: they consume the three-attempt-per-head budget and can escalate
to Needs-human.
Model + credential pair — PR_MONITOR_LLM_API_KEY (default
OPENROUTER_API_KEY) with PR_MONITOR_MODEL (default
deepseek/deepseek-v4-flash-0731) and PR_MONITOR_LLM_ENDPOINT (default
https://openrouter.ai/api/v1/chat/completions). This is exactly the
deployed OpenRouter cron path, and the defaults keep it unchanged. The key
selects this layer — a model without a key does not.
Auto — the invoking agent session — export nothing: the Tick finds the
agent surrounding it (the session's marker variables plus the agent CLI on
PATH) and synthesizes that CLI as the decision command, pinning the
session's model where the host exposes one. Registered adapters, in match
order:
| Agent | Session markers | Session model pinned | Synthesized command |
|---|---|---|---|
pi | PI_CODING_AGENT=true or AI_AGENT=pi | PI_PROVIDER / PI_MODEL | pi --print [--provider …] [--model …] … |
claude | CLAUDECODE=1 or AI_AGENT=claude-code… | ANTHROPIC_MODEL | claude --print [--model …] … |
opencode | OPENCODE=1, OPENCODE_CLIENT or AI_AGENT=opencode | OPENCODE_CONFIG_CONTENT.model | opencode run [--model …] … |
Discovery is innermost-first: a nested agent session inherits the outer
session's env, so when several markers coexist the explicit AI_AGENT
marker names the session that actually surrounds the process and selects
that adapter (when its CLI is runnable). Without AI_AGENT, the table's
registry order is the deterministic fallback.
Each adapter authenticates through its own CLI; the skill never reads or
prints another tool's credential store. Claude Code authentication through
a Teams seat is not confirmed — see the caveat on that unit in agents.mjs
and confirm it in the Teams-seat environment before relying on the adapter.
None — the handled case, not a failure: action wait,
decision_source: "none", no owner notification, and the
three-attempt-per-head budget untouched. The reason is the operator's
checklist — it starts No LLM decision source is configured: and names
the setup paths: define PR_MONITOR_LLM_CMD, or define a
chat-completions provider with PR_MONITOR_LLM_API_KEY (default
OPENROUTER_API_KEY) and optionally PR_MONITOR_LLM_ENDPOINT /
PR_MONITOR_MODEL.
Settings are read from the invoking agent's environment first, then from the
skill's env files (~/.pr-monitor.env, then ~/.hermes/.env, the legacy
deployed cron location), and never printed:
| Setting | Meaning | Where it may be set |
|---|---|---|
PR_MONITOR_LLM_CMD | decision command (stdin request, stdout JSON) | process env, then either env file |
PR_MONITOR_LLM_CMD_TIMEOUT_MS | decision-command timeout (default 60000) | process env, then either env file |
PR_MONITOR_LLM_API_KEY | credential for the chat-completions provider | process env, then either env file |
OPENROUTER_API_KEY | credential fallback when PR_MONITOR_LLM_API_KEY is unset | process env, then either env file |
PR_MONITOR_LLM_ENDPOINT | provider endpoint (default https://openrouter.ai/api/v1/chat/completions) | process env, then either env file |
PR_MONITOR_MODEL | provider model (default deepseek/deepseek-v4-flash-0731) | process env, then either env file |
Traceability: every LLM decision carries decision_source in the Tick's JSON
report — decision_command, model_credential,
auto:<agent> or auto:<agent>:<provider>/<model> (the provider part only
when the host exposes one), injected_decider for a bare injected callable, or
none when no decision source is configured (a configuration gap, not a
decision). An injected { adapter, decider } unit retains its declared adapter.
Deterministic gate decisions carry no decision_source field at all. The same value persists into the per-PR Tick history
(tick_history in the state file), so a decision can be traced after the
fact; the observability API projects it (see "Observability API" above).
Launch examples — one per explicit form, then the auto default:
# decision command: request on stdin, {"action","reason"} on stdout.
PR_MONITOR_REPOS="your-org/your-repo" \
PR_MONITOR_LLM_CMD='claude --print "Reply with only one JSON decision object."' \
PR_MONITOR_LLM_CMD_TIMEOUT_MS=90000 \
node pr_monitor.mjs --json-report
# model + credential pair: the deployed OpenRouter path, defaults unchanged.
PR_MONITOR_REPOS="your-org/your-repo" \
PR_MONITOR_MODEL="deepseek/deepseek-v4-flash-0731" \
PR_MONITOR_LLM_API_KEY="$OPENROUTER_API_KEY" \
node pr_monitor.mjs --json-report
# custom provider: add PR_MONITOR_LLM_ENDPOINT="https://your-provider.example/v1/chat/completions"
# auto default: export nothing; launch from the agent session.
PR_MONITOR_REPOS="your-org/your-repo" node pr_monitor.mjs --json-report
notify_ready is exempt). The LLM also receives an
agent_still_working flag with a prefer-WAIT note.mergeable_state == "dirty" or mergeable is False triggers the rebase
policy above. "behind"/"blocked"/"unstable" are NOT conflicts. If
mergeability is null → per-PR fetch; still null → wait.> @copilot …). Strip quote-lines and ignore Copilot-authored
comments when detecting pending requests — an ack must never renew a
request or count as progress.resources/docs/adr/0005-anti-spam-throttle-numbers.md; the
full next_check_at derivation table above is the contract).seen_ready shas: notify_ready fires ONCE per head sha — never
re-message the owner.no_agent cron
mode, empty stdout = silent). Agent-facing runs opt into JSON lines; cron does not.repos/{r}/pulls?state=open → the watched PRs (list; mergeability often
null here — do a per-PR fetch repos/{r}/pulls/{n} when null).repos/{r}/pulls/{n}/reviews → formal reviews (filter user.login
contains copilot); state + submitted_at.repos/{r}/pulls/{n}/comments → inline review comments (inline transcript).repos/{r}/issues/{n}/comments → the FULL transcript (any author).repos/{r}/pulls/{n}/commits → last commit ts (oldest-first; take
max(author.date)).LLM: a chat-completions provider (OpenRouter by default), temperature 0,
response_format: json_object, four-action prompt (request_rebase is
deterministic — the LLM never picks it; English reasoning, see callLlm in
the script). The endpoint, credential and model are the decision-source
settings above.
Decision architecture and policy intent are documented in ADRs:
resources/docs/adr/0003-llm-decision-maker-behind-deterministic-gates.mdresources/docs/adr/0004-transcript-truth-over-thread-resolution-state.mdresources/docs/adr/0005-anti-spam-throttle-numbers.mdDecision seam:
decision.mjs exposes a pure deterministic gate function and an LLM boundary
with injectable dependency, so gate behavior is testable without network and
LLM failure/escalation paths can be validated with stubs.Cron is the alternate mode (Hosts with no public endpoint); the webhook Listener is the primary path — see "Webhook mode" above.
node pr_monitor.mjs with PR_MONITOR_REPOS set; stdout must be
delivered verbatim and empty stdout = silent.no_agent: true, deliver: origin, deployed as
3f51bedf15cd, hourly, no_agent,
deliver origin). It runs pr_monitor.sh — a wrapper that exports
PR_MONITOR_REPOS="dyegolara/monitor,dyegolara/bitsimp" and the legacy
state path, then exec node pr_monitor.mjs. The wrapper exists because the
Hermes cron runner executes non-.sh scripts with Python (a bare .mjs
script would never run as Node).~/.cache/pr-monitor/state.json is for fresh installs).COMMENTED, not APPROVED — never key the "done" check
on an APPROVED state alone (this exact bug made the naive loop ping daily
forever: review_sha == head_sha never held, and Copilot had confirmed
"21/21 tests passing" for days).review_sha/fix_sha) made the
green-check never fire. Prefer timestamp comparisons + a decision LLM.code review and never resumed).gh exit 0 ≠ Copilot acted. Always re-read real GitHub state; don't
report success on a 200 response.resolved field on pulls/{n}/comments. Count every top-level Copilot
inline comment as unaddressed and let the decision LLM read the transcript
to judge whether the feedback was really handled. (The Python v2.0.0
"checked" a resolved field that never exists — always-true bug.)DRY_RUN=1, which prints would-be comments and never posts or persists.README.md (opens in a new tab)agents.mjs (opens in a new tab)collection_failure.mjs (opens in a new tab)decision.mjs (opens in a new tab)decision.test.mjs (opens in a new tab)decision_source.mjs (opens in a new tab)harness.test.mjs (opens in a new tab)harness/bin/gh (opens in a new tab)harness/fake_openrouter.mjs (opens in a new tab)harness/fixture_data.mjs (opens in a new tab)harness/fixture_runtime.mjs (opens in a new tab)harness/gh.mjs (opens in a new tab)harness/run_fixture.mjs (opens in a new tab)listener/README.md (opens in a new tab)listener/package.json (opens in a new tab)listener/src/cli.mjs (opens in a new tab)listener/src/daemon.mjs (opens in a new tab)listener/src/gh.mjs (opens in a new tab)listener/src/hooks.mjs (opens in a new tab)listener/src/http-transport.mjs (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub dyegolara/skillbook --plugin skillbook-skills56 skills in this plugin
/architectSketch types, signatures, and module structure before code, then stay in the loop while implementation fills in. Use for "architect this", "design this", or non-trivial work where jumping to code would lock in the wrong shape./arenaSpawn N parallel candidates at the same task, pick a base, graft the strongest parts of the losers into it. Use for "arena this", "throw it in the arena", or when one attempt at a non-trivial artifact would lock in the wrong shape./automate-meUse for "automate me", "create/update/refresh my -mode skill", "turn/capture my preferences or working style into a skill", or wanting agents to follow how the user works. Drafts or revises a personal -mode skill via create-skill + unslop, optionally pulling fresh evidence from recent transcripts.