@olegkoval/agent-skills 1.51.0 → 1.51.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/.github/prompts/coderabbitloop.prompt.md +72 -23
  2. package/.github/prompts/codexloop.prompt.md +87 -85
  3. package/.github/prompts/copilotloop.prompt.md +84 -88
  4. package/.github/prompts/geminiloop.prompt.md +85 -85
  5. package/.github/prompts/qodoloop.prompt.md +78 -20
  6. package/.kiro/steering/coderabbitloop.md +72 -23
  7. package/.kiro/steering/codexloop.md +87 -85
  8. package/.kiro/steering/copilotloop.md +84 -88
  9. package/.kiro/steering/geminiloop.md +85 -85
  10. package/.kiro/steering/qodoloop.md +78 -20
  11. package/.windsurf/rules/coderabbitloop.md +72 -23
  12. package/.windsurf/rules/codexloop.md +87 -85
  13. package/.windsurf/rules/copilotloop.md +84 -88
  14. package/.windsurf/rules/geminiloop.md +85 -85
  15. package/.windsurf/rules/qodoloop.md +78 -20
  16. package/adapters/claude/olko-github-pr/skills/coderabbitloop/SKILL.md +73 -24
  17. package/adapters/claude/olko-github-pr/skills/coderabbitloop/scripts/pr-review-state.sh +163 -0
  18. package/adapters/claude/olko-github-pr/skills/codexloop/SKILL.md +90 -88
  19. package/adapters/claude/olko-github-pr/skills/codexloop/scripts/pr-review-state.sh +163 -0
  20. package/adapters/claude/olko-github-pr/skills/copilotloop/SKILL.md +85 -89
  21. package/adapters/claude/olko-github-pr/skills/copilotloop/scripts/pr-review-state.sh +163 -0
  22. package/adapters/claude/olko-github-pr/skills/geminiloop/SKILL.md +87 -87
  23. package/adapters/claude/olko-github-pr/skills/geminiloop/scripts/pr-review-state.sh +163 -0
  24. package/adapters/claude/olko-github-pr/skills/lekker-review/references/github-post.md +4 -3
  25. package/adapters/claude/olko-github-pr/skills/lekker-review/references/output-format.md +5 -1
  26. package/adapters/claude/olko-github-pr/skills/lekker-review/references/pricing.json +5 -1
  27. package/adapters/claude/olko-github-pr/skills/lekker-review/references/revmux/profiles/lekker-deep-codex.md +2 -2
  28. package/adapters/claude/olko-github-pr/skills/lekker-review/references/revmux/profiles/lekker-medium-codex.md +2 -2
  29. package/adapters/claude/olko-github-pr/skills/qodoloop/SKILL.md +79 -21
  30. package/adapters/claude/olko-github-pr/skills/qodoloop/scripts/pr-review-state.sh +163 -0
  31. package/adapters/cursor/olko-github-pr/skills/coderabbitloop/SKILL.md +73 -24
  32. package/adapters/cursor/olko-github-pr/skills/coderabbitloop/scripts/pr-review-state.sh +163 -0
  33. package/adapters/cursor/olko-github-pr/skills/codexloop/SKILL.md +90 -88
  34. package/adapters/cursor/olko-github-pr/skills/codexloop/scripts/pr-review-state.sh +163 -0
  35. package/adapters/cursor/olko-github-pr/skills/copilotloop/SKILL.md +85 -89
  36. package/adapters/cursor/olko-github-pr/skills/copilotloop/scripts/pr-review-state.sh +163 -0
  37. package/adapters/cursor/olko-github-pr/skills/geminiloop/SKILL.md +87 -87
  38. package/adapters/cursor/olko-github-pr/skills/geminiloop/scripts/pr-review-state.sh +163 -0
  39. package/adapters/cursor/olko-github-pr/skills/qodoloop/SKILL.md +79 -21
  40. package/adapters/cursor/olko-github-pr/skills/qodoloop/scripts/pr-review-state.sh +163 -0
  41. package/adapters/grok/olko-github-pr/skills/coderabbitloop/SKILL.md +73 -24
  42. package/adapters/grok/olko-github-pr/skills/coderabbitloop/scripts/pr-review-state.sh +163 -0
  43. package/adapters/grok/olko-github-pr/skills/codexloop/SKILL.md +90 -88
  44. package/adapters/grok/olko-github-pr/skills/codexloop/scripts/pr-review-state.sh +163 -0
  45. package/adapters/grok/olko-github-pr/skills/copilotloop/SKILL.md +85 -89
  46. package/adapters/grok/olko-github-pr/skills/copilotloop/scripts/pr-review-state.sh +163 -0
  47. package/adapters/grok/olko-github-pr/skills/geminiloop/SKILL.md +87 -87
  48. package/adapters/grok/olko-github-pr/skills/geminiloop/scripts/pr-review-state.sh +163 -0
  49. package/adapters/grok/olko-github-pr/skills/qodoloop/SKILL.md +79 -21
  50. package/adapters/grok/olko-github-pr/skills/qodoloop/scripts/pr-review-state.sh +163 -0
  51. package/package.json +1 -1
  52. package/plugins/olko-apple-kit/.claude-plugin/plugin.json +1 -1
  53. package/plugins/olko-creative/.claude-plugin/plugin.json +1 -1
  54. package/plugins/olko-garmin-kit/.claude-plugin/plugin.json +1 -1
  55. package/plugins/olko-git-tools/.claude-plugin/plugin.json +1 -1
  56. package/plugins/olko-github-pr/.claude-plugin/plugin.json +1 -1
  57. package/plugins/olko-github-pr/skills/coderabbitloop/SKILL.md +73 -24
  58. package/plugins/olko-github-pr/skills/coderabbitloop/scripts/pr-review-state.sh +163 -0
  59. package/plugins/olko-github-pr/skills/codexloop/SKILL.md +90 -88
  60. package/plugins/olko-github-pr/skills/codexloop/scripts/pr-review-state.sh +163 -0
  61. package/plugins/olko-github-pr/skills/copilotloop/SKILL.md +85 -89
  62. package/plugins/olko-github-pr/skills/copilotloop/scripts/pr-review-state.sh +163 -0
  63. package/plugins/olko-github-pr/skills/geminiloop/SKILL.md +87 -87
  64. package/plugins/olko-github-pr/skills/geminiloop/scripts/pr-review-state.sh +163 -0
  65. package/plugins/olko-github-pr/skills/lekker-review/references/github-post.md +4 -3
  66. package/plugins/olko-github-pr/skills/lekker-review/references/output-format.md +5 -1
  67. package/plugins/olko-github-pr/skills/lekker-review/references/pricing.json +5 -1
  68. package/plugins/olko-github-pr/skills/lekker-review/references/revmux/profiles/lekker-deep-codex.md +2 -2
  69. package/plugins/olko-github-pr/skills/lekker-review/references/revmux/profiles/lekker-medium-codex.md +2 -2
  70. package/plugins/olko-github-pr/skills/qodoloop/SKILL.md +79 -21
  71. package/plugins/olko-github-pr/skills/qodoloop/scripts/pr-review-state.sh +163 -0
  72. package/plugins/olko-obsidian/.claude-plugin/plugin.json +1 -1
  73. package/plugins/olko-product/.claude-plugin/plugin.json +1 -1
  74. package/plugins/olko-reflection/.claude-plugin/plugin.json +1 -1
  75. package/plugins/olko-release/.claude-plugin/plugin.json +1 -1
  76. package/plugins/olko-skill-meta/.claude-plugin/plugin.json +1 -1
  77. package/plugins/olko-web-ops/.claude-plugin/plugin.json +1 -1
@@ -3,12 +3,12 @@ name: codexloop
3
3
  description: >
4
4
  Iteratively satisfy OpenAI Codex's code review on a GitHub PR, but treat every Codex comment
5
5
  SKEPTICALLY: verify each finding against the real code first, fix ONLY the genuinely-correct
6
- ones, and rebut + resolve false positives WITHOUT changing correct code. Repeat until no
7
- unresolved Codex comments remain. Use when the user says "satisfy codex", "clear the codex
6
+ ones, and rebut + resolve false positives WITHOUT changing correct code. Repeat until Codex
7
+ has reviewed the latest push and nothing is left unresolved. Use when the user says "satisfy codex", "clear the codex
8
8
  review", "fix codex comments", "codex loop", or wants to iterate on Codex PR review feedback.
9
9
  compatibility: GitHub only (Codex code review is a GitHub app). Requires git + jq + gh (GitHub CLI) authenticated, and the Codex / ChatGPT connector app installed on the repo with code review enabled.
10
10
  metadata:
11
- version: "1.2"
11
+ version: "1.3"
12
12
  allowed-tools: Bash(gh:*) Bash(git:*)
13
13
  ---
14
14
  <!-- Generated by scripts/build-adapters.sh. Do not edit directly. -->
@@ -23,7 +23,8 @@ suggestion applied is worse than the comment itself.
23
23
 
24
24
  - **No check-run, no score.** Codex does not publish an `X/5` confidence or a named check. It posts
25
25
  a **PR review** (state `COMMENTED`) plus inline review comments. Detection is by polling the
26
- *reviews* endpoint. "Satisfied" = zero unresolved comments (each either fixed or rebutted).
26
+ *reviews* endpoint. "Satisfied" = Codex has reviewed the latest push and no bot comment is left unresolved (each
27
+ either fixed or rebutted).
27
28
  - **Trigger phrase is `@codex review`.** Codex reviews automatically when a PR opens or gets new
28
29
  commits if auto-review is enabled on the repo; the mention forces a fresh pass. Other useful
29
30
  mentions: `@codex review focus on <area>` for a scoped re-review.
@@ -55,11 +56,32 @@ Pick the login matching `*codex*` (commonly `chatgpt-codex-connector[bot]`, some
55
56
 
56
57
  **Finding nothing here is NOT a stop condition.** On a PR Codex has never reviewed there is no bot
57
58
  login to find yet: that is the normal starting state, not a missing app. When the probe comes back
58
- empty, fall through to step 2A, post `@codex review`, and re-run this probe once a review lands;
59
+ empty, fall through to step A, post `@codex review`, and re-run this probe once a review lands;
59
60
  until then match any login containing `codex` when polling. Only conclude the app is absent after
60
- step 2A's bounded wait has expired with no review and no codex-like login anywhere on the PR, and
61
+ step A's bounded wait has expired with no review and no codex-like login anywhere on the PR, and
61
62
  then say so and stop, rather than looping against nothing.
62
63
 
64
+ ## Review state comes from the PR, not from memory
65
+
66
+ `scripts/pr-review-state.sh` reads the PR and prints one JSON object: the current head, whether
67
+ Codex has acted on that head (a review of it, or any comment after it was pushed), and every
68
+ unresolved review thread with its author. Every "is there work / are we done" decision in this
69
+ loop comes from its exit code, never from what you remember resolving. The script lives in this
70
+ skill's directory, `SKILL_ROOT`: the directory holding this `SKILL.md` (Claude Code prints it as the
71
+ skill's base directory when the skill loads; in Codex, derive it from the selected `SKILL.md` path).
72
+
73
+ | Exit | `verdict` | Meaning | Do |
74
+ |------|------------|---------------------------------------------------------------------|--------------------------------------|
75
+ | 0 | `clean` | Codex acted on the current head and no bot thread is unresolved | exit check: done |
76
+ | 10 | `findings` | unresolved threads from Codex **or any other review bot** | run an iteration |
77
+ | 20 | `pending` | Codex has not acted on the current head yet | trigger if needed, then wait |
78
+ | 30 | `limited` | a rate-limit or paused notice from Codex after the current head | stop, report `blocked: rate-limited` |
79
+
80
+ Resolving the last thread does not make a PR clean: Codex has not reviewed your push yet. Earlier
81
+ versions of this loop exited at exactly that moment, while the next round of comments was still on
82
+ its way. Human threads are listed in `.unresolved` (`is_bot: false`) and counted in `.counts.humans`;
83
+ they never block `clean`, and this loop never resolves them.
84
+
63
85
  ## 1. Identify the PR
64
86
 
65
87
  ```bash
@@ -80,66 +102,50 @@ Keep an explicit iteration counter and stop at 5: the cap is a real bound to enf
80
102
  figure of speech. Each pass through A–G is one iteration; on hitting the cap, go straight to the
81
103
  report and list what is still unresolved rather than starting a sixth.
82
104
 
83
- ### A. Ensure a fresh Codex review on the current head
84
-
85
- ```bash
86
- HEAD_SHA=$(gh pr view <PR> --json headRefOid -q .headRefOid)
87
- # Only trigger if no Codex review already exists for this exact SHA.
88
- # gh cannot combine --slurp with --jq, so pipe to `jq -s`: it folds every page
89
- # into one array. Without it the filter runs once per page and HAVE becomes a
90
- # multi-line count that never equals "0", silently skipping the trigger.
91
- HAVE=$(gh api repos/{owner}/{repo}/pulls/<PR>/reviews --paginate |
92
- jq -s --arg bot "$BOT" --arg head "$HEAD_SHA" \
93
- '[.[][] | select(.user.login==$bot and .commit_id==$head)] | length')
94
- if [ "$HAVE" = "0" ]; then gh pr comment <PR> --body "@codex review"; fi
95
- ```
105
+ ### A. Read the PR state; wait for Codex's review of the current head
96
106
 
97
- Poll for the review of THIS head to land. No check-run exists, so poll the reviews endpoint, and
98
- poll it on a **deadline**, never `while true`: a review that never arrives must end the skill with
99
- an honest timeout, not hang it.
107
+ One read answers both "is there work?" and "has Codex seen my last push?". `SINCE` is the
108
+ timestamp you took right before your last push (step E); leave it empty on iteration 1. Right
109
+ after a push, add `--wait 600` straight away: the wait ends only once the bot has acted on the new
110
+ head, so threads left open on purpose cannot make the push look reviewed.
100
111
 
101
112
  ```bash
102
- # 10-minute deadline, one retry, then give up. DEADLINE/RETRIES are the
103
- # enforcement of the bounds this skill claims: do not drop them.
104
- wait_for_review() { # $1 = attempt label
105
- local deadline=$(( SECONDS + 600 ))
106
- while [ "$SECONDS" -lt "$deadline" ]; do
107
- R=$(gh api repos/{owner}/{repo}/pulls/<PR>/reviews --paginate |
108
- jq -s --arg bot "$BOT" --arg head "$HEAD_SHA" \
109
- '[.[][] | select(.user.login==$bot and .commit_id==$head)] | sort_by(.submitted_at, .id) | last')
110
- if [ -n "$R" ] && [ "$R" != "null" ]; then return 0; fi
111
- echo "waiting for Codex review of $HEAD_SHA ($1)..."; sleep 15
112
- done
113
- return 1
114
- }
115
-
116
- if ! wait_for_review "first wait"; then
117
- echo "no Codex review after 10m, retrying once" # say the retry out loud
118
- gh pr comment <PR> --body "@codex review"
119
- if ! wait_for_review "after retry"; then
120
- echo "Codex did not review $HEAD_SHA after a retry; stopping and reporting."
121
- exit 1 # honest timeout, never a success claim
122
- fi
123
- fi
113
+ "$SKILL_ROOT/scripts/pr-review-state.sh" --repo OWNER/REPO --pr <PR> --bot codex --since "$SINCE"
124
114
  ```
125
115
 
126
- Codex can take several minutes on a large diff, which is why the deadline is generous. Report the
127
- retry in the final summary; two silent timeouts are the failure mode this guard exists to prevent.
116
+ - Exit `10` (`findings`): go to B. On iteration 1 this is whatever Codex (or another bot)
117
+ already posted.
118
+ - Exit `20` (`pending`): post `@codex review` (`gh pr comment <PR> --body "@codex review"`). Then wait with the same command plus `--wait 600`. Run the
119
+ wait in the background where the host allows it (Claude Code: Bash `run_in_background`; you are
120
+ re-invoked when it exits) so ten minutes of polling never sits in the conversation. Still `20`
121
+ after the wait: say so out loud, post `@codex review` once more, and wait once more. Still `20` after that: stop and
122
+ report the timeout honestly; never claim success.
123
+ - Exit `0` (`clean`): go to the exit check. A `--wait` call returns `clean` only after a settle
124
+ re-read 60 seconds later, so a comment landing right behind the review is still caught. A bare
125
+ read (no `--wait`) that says `clean` is good enough only when you have not pushed since Codex's
126
+ last review.
127
+ - Exit `30` (`limited`): stop now and report `blocked: rate-limited`; nothing more is coming.
128
+ - Exit `1`: the read itself failed (often a transient GitHub 502). Retry once; if it fails again,
129
+ stop and report it. An unknown state is not a clean one.
128
130
 
129
131
  ### B. Fetch the findings
130
132
 
131
- - **Summary**: the review `.body` from the object above: read the overall take and the priority
133
+ The working set is every unresolved thread in the state JSON with `is_bot: true`: Codex's
134
+ own (`is_target: true`) **and any other review bot's** (Greptile, for example). A
135
+ fix for one bot often draws a comment from another, and leaving those open is how a "finished" loop
136
+ leaves a PR that is not clean. Treat another bot's thread with exactly the same verify-first rules
137
+ below. Never act on a human's thread (`is_bot: false`); list it in the report.
138
+
139
+ - **Summary**: the latest review `.body` from this bot (`gh pr view <PR> --json reviews`): read the overall take and the priority
132
140
  spread.
133
- - **Unresolved inline comments** on the current head:
141
+ - **Unresolved inline comments**: `.unresolved[] | select(.is_bot)` in step A's state JSON lists
142
+ each thread's `thread_id`, `comment_id`, `path`, `line` and a short excerpt, across every page of
143
+ threads. Read the full comment before judging it:
134
144
 
135
145
  ```bash
136
- gh api repos/{owner}/{repo}/pulls/<PR>/comments --paginate \
137
- --jq ".[] | select(.user.login==\"$BOT\") | {id, path, line, body}"
146
+ gh api repos/{owner}/{repo}/pulls/comments/<COMMENT_ID> --jq '{user: .user.login, path, line, body}'
138
147
  ```
139
148
 
140
- Also pull the review threads + their resolved state via GraphQL (see step F) so you only act on
141
- unresolved ones.
142
-
143
149
  Mark each unresolved comment as seen, so the bot and a watching human can tell it is being handled.
144
150
  GitHub's reaction set is fixed; `eyes` is the only "looking at it" value:
145
151
 
@@ -196,6 +202,7 @@ If step D changed code:
196
202
  git status --short # look before you stage
197
203
  git add <path> [<path>...] # the files named in the findings you fixed
198
204
  git commit -m "address codex review feedback (codexloop iteration N)"
205
+ SINCE=$(date -u +%Y-%m-%dT%H:%M:%SZ) # step A reads bot activity after this
199
206
  git push
200
207
  ```
201
208
 
@@ -215,31 +222,8 @@ to and resolved without a push.
215
222
 
216
223
  ### F. Reply to and resolve every addressed thread
217
224
 
218
- Only now, with the fixes pushed, reply and resolve. Fetch unresolved threads, **following
219
- pagination**: a PR with more than 100 threads will otherwise look clean while unresolved findings
220
- sit on page two:
221
-
222
- ```bash
223
- # Loop until hasNextPage is false, passing endCursor back in as $cursor.
224
- CURSOR=null
225
- while : ; do
226
- PAGE=$(gh api graphql -F cursor="$CURSOR" -f query='
227
- query($cursor: String) {
228
- repository(owner: "OWNER", name: "REPO") {
229
- pullRequest(number: PR_NUMBER) {
230
- reviewThreads(first: 100, after: $cursor) {
231
- pageInfo { hasNextPage endCursor }
232
- nodes { id isResolved comments(first: 1) { nodes { databaseId author { login } path body } } }
233
- }
234
- }
235
- }
236
- }')
237
- echo "$PAGE" # collect nodes from every page before deciding the PR is clean
238
- PI='.data.repository.pullRequest.reviewThreads.pageInfo'
239
- [ "$(echo "$PAGE" | jq -r "$PI.hasNextPage")" = "true" ] || break
240
- CURSOR=$(echo "$PAGE" | jq -r "$PI.endCursor")
241
- done
242
- ```
225
+ Only now, with the fixes pushed, reply and resolve. Take thread and comment ids from step A's state
226
+ JSON (`.unresolved[]`): the script already follows pagination, so do not hand-roll a threads query.
243
227
 
244
228
  Reply on a thread's comment via `gh api repos/{owner}/{repo}/pulls/<PR>/comments -f body="..." -F in_reply_to=<comment_id>`,
245
229
  then resolve:
@@ -263,7 +247,8 @@ gh api --method POST repos/{owner}/{repo}/pulls/comments/<COMMENT_ID>/reactions
263
247
  Reply first, then react, then resolve: the reaction is not a substitute for the reply, and a
264
248
  resolved thread with no reply loses the reasoning.
265
249
 
266
- Resolve a thread only for comments authored by `$BOT` that you have fixed or rebutted: never
250
+ Resolve a thread only for a bot comment in your working set (this bot's or another
251
+ review bot's) that you have fixed or rebutted: never
267
252
  blanket-resolve, and never resolve a human reviewer's thread. For each fixed comment, verify the
268
253
  push first, reply with the change made, then resolve the thread and verify `isResolved: true`.
269
254
  For each rebutted comment, reply with the evidence and verify resolution. Do not report a comment
@@ -272,19 +257,34 @@ as fixed or rebutted until its thread is confirmed resolved.
272
257
  Threads you are **rebutting** need no push, so they may be replied to and resolved regardless of
273
258
  whether step D changed code.
274
259
 
275
- ### G. Re-review
260
+ ### G. Back to A
276
261
 
277
- Pushing re-triggers Codex when auto-review is on; otherwise post `@codex review`. Go back to **A**
278
- with the new head SHA. If step D changed nothing (all comments were rebutted), skip the push,
279
- ensure all threads are resolved, and exit.
262
+ Go back to **A**. After a push, A waits for Codex's review of the new head (pushing re-triggers
263
+ it when auto-review is on; otherwise A triggers it). If this iteration changed no code (every finding
264
+ rebutted), there is no new head to wait for: A's fresh read says `clean` or shows what is still open.
280
265
 
281
266
  ## 3. Exit conditions
282
267
 
268
+ Decide from a fresh state read, never from what you remember resolving.
269
+
283
270
  Stop when **any** is true:
284
- - Zero unresolved `$BOT` comments remain, and every comment this round was fixed or
285
- rebutted+resolved. (There is no score to hit: this is "done".)
286
- - Max iterations (5) reached: report what remains.
287
- - Codex never responded after one retry: report the timeout honestly; do not claim success.
271
+ - **Done**: the latest `pr-review-state.sh --wait 600` call, made after your last push, exited `0`
272
+ (`clean`); with no push since the bot's last review, a bare read that exits `0` is enough. Open human threads do not block this; list them in the report.
273
+ - **Max iterations (5)** reached: report what remains.
274
+ - **Timeout**: still `pending` after the retry in step A. Report it honestly; do not claim success.
275
+ - **Rate limited**: exit `30`. Report `blocked: rate-limited`.
276
+
277
+ ## Keep the context small; resume instead of restarting
278
+
279
+ - Carry only three things between iterations: the iteration counter, the latest state JSON, and a
280
+ ledger of each thread you handled (fixed with its commit, rebutted, or blocked). Re-read files
281
+ fresh each iteration; do not re-paste earlier rounds' comment bodies.
282
+ - All loop state lives on the PR, so the loop is resumable. If the session has grown long or slow,
283
+ or a bot commented after the loop ended, run this skill again in a fresh session: step A picks up
284
+ from the PR as it is now. Starting fresh is cheaper than dragging a long session through more
285
+ rounds.
286
+ - After reporting done, if the host can schedule a follow-up (Claude Code: `/loop` or a scheduled
287
+ wakeup), offer one re-check about 20 minutes later for bots that comment late.
288
288
 
289
289
  ## 4. Report
290
290
 
@@ -295,7 +295,9 @@ Codexloop complete.
295
295
  Iterations: N
296
296
  Comments fixed: N (genuinely-correct findings)
297
297
  Comments rebutted: N (false positives / nits, resolved with rationale)
298
- Remaining: 0
298
+ Remaining: N (bot threads still open)
299
+ Human threads: N (open, listed below; this loop never resolves them)
300
+ Final state: clean | timeout | rate-limited | iteration cap
299
301
  ```
300
302
 
301
303
  If it stopped at max iterations, list the remaining threads with your current assessment
@@ -0,0 +1,163 @@
1
+ #!/usr/bin/env bash
2
+ # pr-review-state.sh: read a PR's review-bot state once (or until it settles) and print it as JSON.
3
+ #
4
+ # Shared by every review loop in olko-github-pr (codexloop, geminiloop, copilotloop,
5
+ # coderabbitloop, qodoloop). Each skill ships its own copy so it works on every adapter;
6
+ # tests/test-pr-review-state.sh fails if the copies drift apart.
7
+ #
8
+ # The loops decide "done" from this output, never from their own memory of what they resolved:
9
+ # clean every --bot has acted on the current head AND no bot thread is unresolved
10
+ # findings at least one unresolved thread from any bot (target or not): work to do
11
+ # pending some --bot has not acted on the current head yet
12
+ #
13
+ # "Acted on the head" = a review of the head commit, or after the head was pushed: a
14
+ # comment that is not a progress notice, or a PR reaction other than 👀 (Codex signals a clean
15
+ # review with only a 👍 on the PR, and edits a "**Running**" summary comment while it works).
16
+ # limited a --bot posted a rate-limit / paused notice after the current head
17
+ set -euo pipefail
18
+
19
+ usage() {
20
+ cat >&2 <<'EOF'
21
+ usage: pr-review-state.sh --repo OWNER/REPO --pr N --bot REGEX [--bot REGEX ...]
22
+ [--since ISO8601] [--wait SECONDS] [--settle SECONDS] [--interval SECONDS]
23
+
24
+ --bot case-insensitive regex matched against the bare bot login (GraphQL drops "[bot]"),
25
+ e.g. codex, gemini-code-assist, copilot, coderabbitai, qodo-code-review. Repeatable:
26
+ every --bot must have acted on the current head before the verdict can be "clean".
27
+ --since when the current head was pushed (date -u +%Y-%m-%dT%H:%M:%SZ, taken before the push).
28
+ Bot activity counts for the head only if it happened after max(head commit date, since).
29
+ --wait poll until every --bot has acted on the current head (or posted a limit notice), or
30
+ SECONDS pass (default 0: read once). Open threads do not end the wait early, so threads
31
+ left open on purpose cannot make a fresh push look reviewed.
32
+ --settle once "clean", wait SECONDS and read again, so a late comment is not missed
33
+ (default 60 when --wait is set, else 0).
34
+ --interval seconds between polls (default 20).
35
+
36
+ exit: 0 clean, 10 findings, 20 pending, 30 limited, 2 usage, 1 error
37
+ EOF
38
+ exit 2
39
+ }
40
+
41
+ REPO="" PR="" SINCE="" WAIT=0 SETTLE="" INTERVAL=20
42
+ BOTS=()
43
+ while [ $# -gt 0 ]; do
44
+ case "$1" in
45
+ --repo) REPO="${2:-}"; shift 2 ;;
46
+ --pr) PR="${2:-}"; shift 2 ;;
47
+ --bot) BOTS+=("${2:-}"); shift 2 ;;
48
+ --since) SINCE="${2:-}"; shift 2 ;;
49
+ --wait) WAIT="${2:-}"; shift 2 ;;
50
+ --settle) SETTLE="${2:-}"; shift 2 ;;
51
+ --interval) INTERVAL="${2:-}"; shift 2 ;;
52
+ -h|--help) usage ;;
53
+ *) echo "unknown argument: $1" >&2; usage ;;
54
+ esac
55
+ done
56
+ [ -n "$REPO" ] && [ -n "$PR" ] && [ "${#BOTS[@]}" -gt 0 ] || usage
57
+ case "$REPO" in */*) ;; *) usage ;; esac
58
+ [ -n "$SETTLE" ] || { [ "$WAIT" -gt 0 ] && SETTLE=60 || SETTLE=0; }
59
+ OWNER="${REPO%%/*}" NAME="${REPO#*/}"
60
+ BOTS_JSON=$(printf '%s\n' "${BOTS[@]}" | jq -R . | jq -s .)
61
+
62
+ QUERY='query($owner:String!,$name:String!,$pr:Int!,$cursor:String){
63
+ repository(owner:$owner,name:$name){ pullRequest(number:$pr){
64
+ headRefOid
65
+ commits(last:1){ nodes{ commit{ oid committedDate } } }
66
+ reviews(last:100){ nodes{ author{ login __typename } commit{ oid } submittedAt body } }
67
+ comments(last:100){ nodes{ author{ login __typename } createdAt updatedAt body } }
68
+ reactions(last:50){ nodes{ content createdAt user{ login } } }
69
+ reviewThreads(first:100, after:$cursor){
70
+ pageInfo{ hasNextPage endCursor }
71
+ nodes{ id isResolved isOutdated path line
72
+ comments(first:1){ nodes{ databaseId url author{ login __typename } body } } }
73
+ }
74
+ } }
75
+ }'
76
+
77
+ # One full read: first page carries head/reviews/comments; every page carries threads.
78
+ read_state() {
79
+ local cursor=null page first="" threads="[]"
80
+ while :; do
81
+ page=$(gh api graphql -f query="$QUERY" -f owner="$OWNER" -f name="$NAME" \
82
+ -F pr="$PR" -F cursor="$cursor")
83
+ [ -n "$first" ] || first="$page"
84
+ threads=$(jq -c --argjson acc "$threads" \
85
+ '$acc + .data.repository.pullRequest.reviewThreads.nodes' <<<"$page")
86
+ [ "$(jq -r '.data.repository.pullRequest.reviewThreads.pageInfo.hasNextPage' <<<"$page")" = "true" ] || break
87
+ cursor=$(jq -r '.data.repository.pullRequest.reviewThreads.pageInfo.endCursor' <<<"$page")
88
+ done
89
+
90
+ jq -c --argjson bots "$BOTS_JSON" --argjson threads "$threads" --arg since "$SINCE" '
91
+ .data.repository.pullRequest as $p
92
+ | $p.headRefOid as $head
93
+ | ([$p.commits.nodes[0].commit.committedDate // "", $since] | max) as $after
94
+ | def matches($login): any($bots[]; . as $re | ($login // "") | test($re; "i"));
95
+ def isbot($a): ($a.__typename // "User") != "User";
96
+ def progress: test("busy working|in progress|currently processing|currently reviewing|\\*\\*(running|queued)\\*\\*"; "i");
97
+ def limited: test("review limit reached|reached your (pr )?review limit|reviews are paused|rate limit (exceeded|reached)|been rate[- ]limited"; "i");
98
+ [ $bots[] as $re
99
+ | ($p.reviews.nodes | map(select((.author.login // "") | test($re; "i")))) as $revs
100
+ | ($p.comments.nodes | map(select((.author.login // "") | test($re; "i")))) as $coms
101
+ | ($coms | map(select(.updatedAt >= $after))) as $fresh
102
+ | ($p.reactions.nodes | map(select(((.user.login // "") | test($re; "i"))
103
+ and .content != "EYES" and .createdAt >= $after))) as $reacts
104
+ | {
105
+ bot: $re,
106
+ reviewed_head: any($revs[]; .commit.oid == $head),
107
+ activity_after_head: (any($fresh[]; (.body | progress) | not)
108
+ or ($reacts | length) > 0),
109
+ limited: any($fresh[]; .body | limited)
110
+ }
111
+ | .acted_on_head = (.reviewed_head or .activity_after_head)
112
+ ] as $per_bot
113
+ | [ $threads[] | select(.isResolved | not)
114
+ | .comments.nodes[0] as $c
115
+ | {
116
+ thread_id: .id, comment_id: $c.databaseId, url: $c.url,
117
+ author: $c.author.login, is_bot: isbot($c.author), is_target: matches($c.author.login),
118
+ path, line, outdated: .isOutdated,
119
+ excerpt: (($c.body // "") | gsub("\\s+"; " ") | .[0:160])
120
+ } ] as $open
121
+ | ($open | map(select(.is_bot))) as $open_bot
122
+ | {
123
+ head: $head,
124
+ head_after: $after,
125
+ bots: $per_bot,
126
+ unresolved: $open,
127
+ counts: {
128
+ target: ($open_bot | map(select(.is_target)) | length),
129
+ other_bots: ($open_bot | map(select(.is_target | not)) | length),
130
+ humans: ($open | map(select(.is_bot | not)) | length)
131
+ },
132
+ verdict: (
133
+ if any($per_bot[]; .limited) then "limited"
134
+ elif ($open_bot | length) > 0 then "findings"
135
+ elif any($per_bot[]; .acted_on_head | not) then "pending"
136
+ else "clean" end)
137
+ }' <<<"$first"
138
+ }
139
+
140
+ exit_for() {
141
+ case "$1" in clean) echo 0 ;; findings) echo 10 ;; pending) echo 20 ;; limited) echo 30 ;; *) echo 1 ;; esac
142
+ }
143
+
144
+ deadline=$(( SECONDS + WAIT ))
145
+ state=$(read_state)
146
+ verdict=$(jq -r .verdict <<<"$state")
147
+ waiting() { jq -e '.verdict != "limited" and any(.bots[]; .acted_on_head | not)' >/dev/null <<<"$state"; }
148
+ while :; do
149
+ if waiting && [ "$SECONDS" -lt "$deadline" ]; then
150
+ sleep "$INTERVAL"
151
+ elif [ "$verdict" = "clean" ] && [ "$SETTLE" -gt 0 ]; then
152
+ # Clean once is not clean: bots post a review, then a second bot or a follow-up lands.
153
+ sleep "$SETTLE"
154
+ SETTLE=0
155
+ else
156
+ break
157
+ fi
158
+ state=$(read_state)
159
+ verdict=$(jq -r .verdict <<<"$state")
160
+ done
161
+
162
+ printf '%s\n' "$state"
163
+ exit "$(exit_for "$verdict")"