claude-dev-env 1.34.0 → 1.34.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-dev-env",
3
- "version": "1.34.0",
3
+ "version": "1.34.1",
4
4
  "description": "Claude Code development standards — rules, hooks, agents, commands, and skills",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,218 +1,220 @@
1
1
  ---
2
2
  name: pr-converge
3
3
  description: >-
4
- Spawns a background subagent that drives the current PR to convergence by
5
- alternating Cursor Bugbot and the in-house bugteam audit. The subagent
6
- fetches each reviewer's findings, applies TDD fixes, pushes one commit per
7
- tick, replies inline, and re-triggers the reviewer. Termination requires a
8
- back-to-back clean cycle bugbot CLEAN immediately followed by bugteam
9
- CLEAN with no intervening fixes at which point the subagent marks the PR
10
- ready for review and terminates. Triggers: '/pr-converge', 'drive PR to
4
+ Drives the current PR to convergence by alternating Cursor Bugbot and the
5
+ in-house bugteam audit. Each invocation runs one tick of work in the main
6
+ session: fetches the latest reviewer state, applies TDD fixes for any
7
+ findings, pushes one commit per tick, replies inline, and re-triggers the
8
+ reviewer. To loop automatically, invoke as `/loop /pr-converge` the /loop
9
+ skill self-paces re-entry via ScheduleWakeup. Convergence requires a
10
+ back-to-back clean cycle (bugbot CLEAN immediately followed by bugteam CLEAN
11
+ with no intervening fixes), at which point the PR is flipped to ready for
12
+ review and the loop terminates. Triggers: '/pr-converge', 'drive PR to
11
13
  convergence', 'loop bugbot and bugteam', 'babysit bugbot and bugteam',
12
14
  'until both are clean', 'converge this PR'.
13
15
  ---
14
16
 
15
17
  # PR Converge
16
18
 
17
- Delegates the bugbot ↔ bugteam convergence loop to a background subagent so the main session stays free. The subagent owns its own cadence and self-terminates on convergence or a hard blocker.
19
+ Runs one tick of the bugbot ↔ bugteam convergence loop in the main session. Designed to be invoked under `/loop /pr-converge` so the parent's ScheduleWakeup paces re-entry. Self-terminates the loop on convergence (back-to-back clean) by flipping the PR to ready for review and omitting the next ScheduleWakeup.
20
+
21
+ ## Why the work runs in the main session, not a background subagent
22
+
23
+ `ScheduleWakeup` is a primitive of the parent harness; it is not exposed to `general-purpose` subagents. A prior version of this skill spawned a background subagent and instructed it to call `ScheduleWakeup` at the end of each tick. The subagent's tool registry returned "No matching deferred tools found" for `ScheduleWakeup`, so the loop could never self-perpetuate — it ran exactly one tick and stalled. Running the loop in the main session via `/loop /pr-converge` puts the work on the same harness that owns `ScheduleWakeup`, eliminating that failure mode.
18
24
 
19
25
  ## When this skill applies
20
26
 
21
- The user is on a PR branch and wants both reviewers — Cursor's Bugbot AND the in-house `/bugteam` audit — to keep re-reviewing after each push, with findings auto-addressed between ticks. The PR stays in draft until convergence; on convergence the subagent flips it to ready for review.
27
+ The user is on a PR branch and wants both reviewers — Cursor's Bugbot AND the in-house `/bugteam` audit — to keep re-reviewing after each push, with findings auto-addressed between ticks. The PR stays in draft until convergence; on convergence the skill flips it to ready for review.
28
+
29
+ ## Invocation modes
30
+
31
+ - **`/loop /pr-converge`** (recommended): loops automatically. The /loop skill runs each tick and uses ScheduleWakeup to pace re-entry. Termination on convergence is automatic; the skill omits the next wakeup at the convergence tick.
32
+ - **`/pr-converge`** (manual): runs exactly one tick and returns. Useful for ad-hoc state checks or for advancing the loop one step manually. The user re-runs the skill (or wraps it in `/loop`) to continue.
33
+
34
+ ## State across ticks
35
+
36
+ Track the following in plain text in the assistant's response so subsequent ticks can re-read it from conversation context:
22
37
 
23
- ## The Process
38
+ - `phase`: `BUGBOT` or `BUGTEAM`. Start in `BUGBOT` on the first tick of a fresh loop.
39
+ - `bugbot_clean_at`: the HEAD SHA at which bugbot last reported clean, or `null`. Reset to `null` whenever a new commit is pushed.
40
+ - `inline_lag_streak`: integer counter, initialized to `0`. Tracks consecutive ticks where bugbot's review body indicates findings against `current_head` but the inline-comments API returns zero matching comments. Reset to `0` on any other branch outcome.
41
+ - `tick_count`: integer, initialized to `0`. Increment on every tick to enforce the safety cap.
24
42
 
25
- ### Step 1: Gather PR context
43
+ Each tick begins by reading the prior tick's state line from the most recent assistant message and ends by emitting the updated state line.
26
44
 
27
- From the current repo:
45
+ ## Per-tick work
46
+
47
+ ### Step 1: Resolve current HEAD and PR context
48
+
49
+ Read the prior tick's state line from the most recent assistant message (or initialize all fields if none). **Increment `tick_count` by 1.** This is the increment referenced in the **State across ticks** section; without it the safety cap (Step 3.5, §Safety cap) never fires.
28
50
 
29
51
  ```bash
30
52
  gh pr view --json number,url,headRefOid,baseRefName,headRefName,isDraft
31
53
  ```
32
54
 
33
- Capture `number`, `headRefOid`, owner/repo (from `url`), branch name, and current draft state. Pass these to the subagent so it can use them directly.
34
-
35
- ### Step 2: Spawn the background subagent
36
-
37
- Invoke the `Agent` tool with:
38
-
39
- - `subagent_type: "general-purpose"`
40
- - `run_in_background: true`
41
- - `description: "PR convergence loop for #<N>"`
42
- - `prompt`: the full instructions in **Step 3 (Subagent prompt template)**, with placeholders filled in from Step 1.
43
-
44
- Record the returned agent ID. Report to the user in one or two lines:
45
-
46
- - The subagent is running in the background and will alternate bugbot ↔ bugteam.
47
- - It self-terminates on back-to-back clean and flips the PR ready for review.
48
- - To stop it early, the user says "stop the converge loop" and you call `TaskStop <agent_id>`.
49
-
50
- The skill's job in the main session ends once the subagent is spawned and reported.
51
-
52
- ### Step 3: Subagent prompt template
53
-
54
- Pass this verbatim to the subagent (substituting the bracketed values):
55
-
56
- > You are driving PR **#[NUMBER]** at **[OWNER]/[REPO]** (branch `[BRANCH]`, current HEAD `[HEAD_SHA]`) to convergence by alternating Cursor Bugbot and the in-house bugteam audit. Your job: keep the loop running until BOTH reviewers return CLEAN against the same HEAD with no intervening fixes, then mark the PR ready for review and stop.
57
- >
58
- > **State you maintain across ticks** (keep it in your own working memory; you re-enter these instructions verbatim each wakeup):
59
- >
60
- > - `phase`: `BUGBOT` or `BUGTEAM`. Start in `BUGBOT`.
61
- > - `bugbot_clean_at`: the HEAD SHA at which bugbot last reported clean, or `null`. Reset to `null` whenever you push a new commit.
62
- > - `inline_lag_streak`: integer counter, initialized to `0`. Tracks consecutive ticks where bugbot's review body indicates findings against `current_head` but the inline-comments API returns zero matching comments. Reset to `0` on any other branch outcome.
63
- >
64
- > **Per-tick work** (do this now, then on each wakeup):
65
- >
66
- > 1. Resolve current HEAD: `gh api repos/[OWNER]/[REPO]/pulls/[NUMBER] --jq '.head.sha'`. Capture it as `current_head`.
67
- >
68
- > 2. Branch on `phase`:
69
- >
70
- > **If `phase == BUGBOT`:**
71
- >
72
- > a. Fetch the latest Cursor Bugbot review:
73
- > ```bash
74
- > gh api repos/[OWNER]/[REPO]/pulls/[NUMBER]/reviews \
75
- > --jq '[.[] | select(.user.login=="cursor[bot]")] | sort_by(.submitted_at) | last'
76
- > ```
77
- > Capture `commit_id`, `state`, `submitted_at`, and the body. Bugbot's body contains either `Cursor Bugbot has reviewed your changes and found <N> potential issue` (findings exist) or text indicating no issues found.
78
- >
79
- > b. Fetch unaddressed inline comments from `cursor[bot]` on `current_head`:
80
- > ```bash
81
- > gh api repos/[OWNER]/[REPO]/pulls/[NUMBER]/comments \
82
- > --jq "[.[] | select(.user.login==\"cursor[bot]\") | select(.commit_id==\"$current_head\")]"
83
- > ```
84
- >
85
- > c. Decide (the four branches below cover every input combination — match the first branch whose predicate holds):
86
- > - **No bugbot review yet, OR latest bugbot review's `commit_id` differs from `current_head`:** Re-trigger bugbot (step 3), set `bugbot_clean_at = null`, reset `inline_lag_streak = 0`, schedule next wakeup, return.
87
- > - **Latest review's `commit_id == current_head` AND zero unaddressed inline findings AND review body indicates clean:** Set `bugbot_clean_at = current_head`. Reset `inline_lag_streak = 0`. Transition `phase = BUGTEAM`. Continue to bugteam branch in this same tick — back-to-back convergence requires bugteam to run against the same HEAD before the next wakeup is scheduled.
88
- > - **Latest review's `commit_id == current_head` with unaddressed inline findings (review body indicates findings):** Apply the **Fix protocol** below to address them. Reset `inline_lag_streak = 0`. The fix protocol pushes a new commit, which sets `current_head` to the new SHA, sets `bugbot_clean_at = null`, replies inline on each thread, and re-triggers bugbot. Schedule next wakeup, return.
89
- > - **Latest review's `commit_id == current_head` AND review body indicates findings AND inline-comments API returns zero matching comments for `current_head`:** Treat as transient API propagation lag — bugbot publishes the review body and inline comments through separate API operations and the two writes can briefly desync. Increment `inline_lag_streak`. When `inline_lag_streak >= 3`, escalate as a hard blocker (bugbot review is structurally inconsistent — body claims findings while inline anchors stay empty across three consecutive ticks); report and terminate. Otherwise schedule next wakeup at `delaySeconds: 60` (lag is short-lived) and return; the inline comments should appear on the next tick.
90
- >
91
- > **If `phase == BUGTEAM`:**
92
- >
93
- > a. Run the in-house bugteam audit on the current PR:
94
- > ```bash
95
- > claude -p "/bugteam" --max-turns 200
96
- > ```
97
- > (The `/bugteam` skill audits the current PR against CODE_RULES, posts review threads, and converges or stops at its own internal cap. Wait for it to complete; capture exit and final summary.)
98
- >
99
- > b. **Re-resolve current HEAD now** because `/bugteam` may have pushed commits during its run. The `current_head` from step 1 is potentially stale at this point:
100
- > ```bash
101
- > new_head=$(gh api repos/[OWNER]/[REPO]/pulls/[NUMBER] --jq '.head.sha')
102
- > ```
103
- > If `new_head != current_head`, set `current_head = new_head` AND set `bugbot_clean_at = null`. The new commits from bugteam invalidate bugbot's prior clean.
104
- >
105
- > c. Inspect bugteam's output. Bugteam reports either `convergence (zero findings)` or a list of unfixed findings with file:line.
106
- >
107
- > d. Decide based on the (post-bugteam) state — order matters; check pushed-during-bugteam FIRST so a convergence report against a stale HEAD never falsely terminates:
108
- > - **bugteam pushed during this tick (i.e., `bugbot_clean_at` was just reset to `null` in step b):** Re-trigger bugbot in this same tick (step 3) so the new HEAD enters bugbot's queue immediately, transition `phase = BUGBOT`, schedule next wakeup, return. The new commit needs a fresh bugbot review before convergence can be claimed.
109
- > - **bugteam reports convergence AND `bugbot_clean_at == current_head` (no push during this tick):** This is back-to-back clean. Mark the PR ready for review:
110
- > ```bash
111
- > gh pr ready [NUMBER] --repo [OWNER]/[REPO]
112
- > ```
113
- > Report to the parent in one sentence: "PR #[NUMBER] converged: bugbot CLEAN at [SHA], bugteam CLEAN at [SHA]; marked ready for review." Terminate; this is the final tick — skip scheduling the next wakeup.
114
- > - **bugteam reports convergence BUT `bugbot_clean_at != current_head` (no push during this tick):** Bugteam reached zero findings without committing, yet bugbot still needs re-confirmation against this HEAD. This branch is reachable only when state diverged BETWEEN ticks — for example, the user pushed a manual commit between two wakeups, leaving `current_head` ahead of the SHA bugbot last cleaned. Transition `phase = BUGBOT`, schedule next wakeup, return.
115
- > - **bugteam reports findings without committing fixes:** apply the **Fix protocol** below (which always re-triggers bugbot after the push), transition `phase = BUGBOT`, schedule next wakeup, return.
116
- >
117
- > 3. Re-trigger bugbot (used in step 2.c first branch, in step 2.d BUGTEAM branch 1, and in the Fix protocol). Post a literal `bugbot run` PR comment:
118
- > ```bash
119
- > printf 'bugbot run\n' > /tmp/bugbot-run.md
120
- > gh pr comment [NUMBER] --repo [OWNER]/[REPO] --body-file /tmp/bugbot-run.md
121
- > rm /tmp/bugbot-run.md
122
- > ```
123
- > Use the literal phrase `bugbot run` exactly — Cursor Bugbot's documented re-trigger phrase, empirically the only one that fires a fresh review.
124
- >
125
- > 4. Schedule the next wakeup with `ScheduleWakeup` using a single rule: `delaySeconds: 300` whenever bugbot was just re-triggered (whether by step 3 directly, by the Fix protocol's mandatory re-trigger, or by BUGTEAM branch 1's same-tick re-trigger). Bugbot finishes a review in 1–4 minutes, so 300s gives a one-minute safety margin past the upper bound. The single exception is the BUGBOT inline-lag branch, which uses `delaySeconds: 60` because no re-trigger fired and the only thing being awaited is GitHub's inline-comments API catching up. Set `reason` to one short sentence on what is being awaited, including the current `phase` and `bugbot_clean_at` SHA when set; set `prompt` to the literal sentinel `<<autonomous-loop-dynamic>>` so the next firing re-enters these instructions.
126
- >
127
- > **Fix protocol** (used by both phases when findings exist):
128
- >
129
- > - Read each referenced file:line.
130
- > - Write a failing test first when the finding has behavior to test. For pure doc, comment, or naming nits with no behavior, go straight to the fix.
131
- > - Implement the fix.
132
- > - Stage the affected files and create one new commit on the existing branch:
133
- > ```bash
134
- > git add <files> && git commit -m "fix(review): <brief summary>"
135
- > ```
136
- > Honor pre-commit and pre-push hooks; when a hook rejects, read its message, fix the underlying issue, retry. Hook rejections flag real underlying issues worth investigating.
137
- > - Push the new commit:
138
- > ```bash
139
- > git push origin [BRANCH]
140
- > ```
141
- > Capture the new HEAD SHA. Set `current_head` to it. Set `bugbot_clean_at = null`.
142
- > - Reply inline on each addressed comment thread:
143
- > ```bash
144
- > gh api -X POST repos/[OWNER]/[REPO]/pulls/[NUMBER]/comments/<comment_id>/replies \
145
- > -f body="Addressed in <new_sha>. <one-line description of the fix>."
146
- > ```
147
- > Use `--body-file` when the body contains backticks (per repo policy on `gh` body content).
148
- > - **Always re-trigger bugbot (step 3 above) after pushing a fix**, regardless of which phase originated the findings. Any new commit invalidates bugbot's prior clean by definition, so bugbot must re-review the new HEAD before convergence can be claimed. Re-triggering in the same tick saves a full wakeup cycle compared to deferring the trigger to the next tick — the fix protocol's last step before scheduling the wakeup is always `printf 'bugbot run\n' > /tmp/bugbot-run.md && gh pr comment ... --body-file /tmp/bugbot-run.md && rm /tmp/bugbot-run.md`.
149
- >
150
- > **Stop conditions:**
151
- >
152
- > - **Convergence** (back-to-back clean as defined in step 2.d BUGTEAM second branch — `bugteam reports convergence AND bugbot_clean_at == current_head` with no push during this tick): mark PR ready for review, report one-sentence summary to parent, terminate.
153
- > - **Hard blocker:** API auth failure persists across two ticks, a CI regression whose root cause falls outside this PR, a hook rejection investigated through three commits and still unresolved, `inline_lag_streak >= 3`, or `/bugteam` itself reports a stuck state. Report the specific blocker and your diagnosis to the parent, then terminate; skip scheduling the next wakeup.
154
- > - **Parent sends `TaskStop`:** terminate immediately.
155
- >
156
- > **Safety cap:** when 30 ticks elapse before convergence, stop and report. That many rounds means something structural is wrong with the loop. (Higher than copilot-review's 20-tick cap because two reviewers run sequentially per round.)
157
-
158
- ### Step 4: Report back to the user
159
-
160
- After spawning, tell the user in one or two lines: subagent ID, PR URL, that it will alternate bugbot and bugteam and notify on convergence or blocker. Nothing else.
161
-
162
- ## Stopping the subagent
163
-
164
- - Convergence → subagent stops itself, marks PR ready for review.
165
- - Blocker → subagent reports and stops.
166
- - User says stop → `TaskStop <agent_id>`.
167
- - User asks what loops are running → `TaskList`.
168
-
169
- ## Ground rules (for the subagent)
55
+ Capture `number` (`<NUMBER>`), `headRefOid` (`current_head`), owner/repo (from `url`), branch name (`<BRANCH>`).
56
+
57
+ ### Step 2: Branch on `phase`
58
+
59
+ #### `phase == BUGBOT`
60
+
61
+ a. Fetch the latest Cursor Bugbot review:
62
+ ```bash
63
+ gh api repos/<OWNER>/<REPO>/pulls/<NUMBER>/reviews \
64
+ --jq '[.[] | select(.user.login=="cursor[bot]")] | sort_by(.submitted_at) | last'
65
+ ```
66
+ Capture `commit_id`, `state`, `submitted_at`, and the body. Bugbot's body contains either `Cursor Bugbot has reviewed your changes and found <N> potential issue` (findings exist) or text indicating no issues found.
67
+
68
+ b. Fetch unaddressed inline comments from `cursor[bot]` on `current_head`:
69
+ ```bash
70
+ gh api repos/<OWNER>/<REPO>/pulls/<NUMBER>/comments \
71
+ --jq "[.[] | select(.user.login==\"cursor[bot]\") | select(.commit_id==\"$current_head\")]"
72
+ ```
73
+
74
+ c. Decide (the four branches below cover every input combination — match the first branch whose predicate holds):
75
+ - **No bugbot review yet, OR latest bugbot review's `commit_id` differs from `current_head`:** Re-trigger bugbot (Step 3), set `bugbot_clean_at = null`, reset `inline_lag_streak = 0`, schedule next wakeup, return.
76
+ - **Latest review's `commit_id == current_head` AND zero unaddressed inline findings AND review body indicates clean:** Set `bugbot_clean_at = current_head`. Reset `inline_lag_streak = 0`. Transition `phase = BUGTEAM`. Continue to bugteam branch in this same tick — back-to-back convergence requires bugteam to run against the same HEAD before the next wakeup is scheduled.
77
+ - **Latest review's `commit_id == current_head` with unaddressed inline findings (review body indicates findings):** Apply the **Fix protocol** below to address them. Reset `inline_lag_streak = 0`. The fix protocol pushes a new commit, which sets `current_head` to the new SHA, sets `bugbot_clean_at = null`, replies inline on each thread, and re-triggers bugbot. Schedule next wakeup, return.
78
+ - **Latest review's `commit_id == current_head` AND review body indicates findings AND inline-comments API returns zero matching comments for `current_head`:** Treat as transient API propagation lag — bugbot publishes the review body and inline comments through separate API operations and the two writes can briefly desync. Increment `inline_lag_streak`. When `inline_lag_streak >= 3`, escalate as a hard blocker (bugbot review is structurally inconsistent body claims findings while inline anchors stay empty across three consecutive ticks); report and terminate. Otherwise schedule next wakeup at `delaySeconds: 60` (lag is short-lived) and return; the inline comments should appear on the next tick.
79
+
80
+ #### `phase == BUGTEAM`
81
+
82
+ a. Run the in-house bugteam audit on the current PR by invoking the `Skill` tool in the main session:
83
+
84
+ ```
85
+ Skill({skill: "bugteam", args: "https://github.com/<OWNER>/<REPO>/pull/<NUMBER>"})
86
+ ```
87
+
88
+ The main session is the team lead, so `TeamCreate` fires from the orchestrator and `/bugteam` emits its CODE_RULES gate output, teammate spawn lines, and audit progress as expected. The skill audits the current PR against CODE_RULES, posts review threads, and converges or stops at its own internal cap. Wait for it to complete; capture exit and final summary.
89
+
90
+ b. **Re-resolve current HEAD now** because `/bugteam` may have pushed commits during its run. The `current_head` from Step 1 is potentially stale at this point:
91
+ ```bash
92
+ new_head=$(gh api repos/<OWNER>/<REPO>/pulls/<NUMBER> --jq '.head.sha')
93
+ ```
94
+ If `new_head != current_head`, set `current_head = new_head` AND set `bugbot_clean_at = null`. The new commits from bugteam invalidate bugbot's prior clean.
95
+
96
+ c. Inspect bugteam's output. Bugteam reports either `convergence (zero findings)` or a list of unfixed findings with file:line.
97
+
98
+ d. Decide based on the (post-bugteam) state — order matters; check pushed-during-bugteam FIRST so a convergence report against a stale HEAD never falsely terminates:
99
+ - **bugteam pushed during this tick (i.e., `bugbot_clean_at` was just reset to `null` in step b):** Re-trigger bugbot in this same tick (Step 3) so the new HEAD enters bugbot's queue immediately, transition `phase = BUGBOT`, schedule next wakeup, return. The new commit needs a fresh bugbot review before convergence can be claimed.
100
+ - **bugteam reports convergence AND `bugbot_clean_at == current_head` (no push during this tick):** This is back-to-back clean. Mark the PR ready for review:
101
+ ```bash
102
+ gh pr ready <NUMBER> --repo <OWNER>/<REPO>
103
+ ```
104
+ Report to the user in one sentence: "PR #<NUMBER> converged: bugbot CLEAN at <SHA>, bugteam CLEAN at <SHA>; marked ready for review." **Omit the next ScheduleWakeup call** — this terminates the /loop.
105
+ - **bugteam reports convergence BUT `bugbot_clean_at != current_head` (no push during this tick):** Bugteam reached zero findings without committing, yet bugbot still needs re-confirmation against this HEAD. This branch is reachable only when state diverged BETWEEN ticks — for example, the user pushed a manual commit between two wakeups, leaving `current_head` ahead of the SHA bugbot last cleaned. Transition `phase = BUGBOT`, schedule next wakeup, return.
106
+ - **bugteam reports findings without committing fixes:** apply the **Fix protocol** below (which always re-triggers bugbot after the push), transition `phase = BUGBOT`, schedule next wakeup, return.
107
+
108
+ ### Step 3: Re-trigger bugbot
109
+
110
+ Used in Step 2 BUGBOT branch 1, in Step 2 BUGTEAM branch 1, and in the Fix protocol. Post a literal `bugbot run` PR comment. Write the body via the Write tool to a temp file, then pass it with `--body-file` (per the gh-body-file rule):
111
+
112
+ ```bash
113
+ gh pr comment <NUMBER> --repo <OWNER>/<REPO> --body-file <path/to/bugbot_run.md>
114
+ ```
115
+
116
+ The body file contains exactly the literal phrase `bugbot run` followed by a newline. Use that phrase exactly — empirically the only re-trigger Cursor Bugbot recognizes; alternative phrasings (`re-review`, `bugbot please`, etc.) silently no-op.
117
+
118
+ ### Step 3.5: Enforce the safety cap
119
+
120
+ Before scheduling the next wakeup, evaluate `tick_count`. When `tick_count >= 30`, stop and report per the **Stop conditions** safety-cap branch (§Safety cap) — **omit Step 4 entirely**. Reaching this many rounds means something structural is wrong with the loop and continuing wastes work. Otherwise proceed to Step 4.
121
+
122
+ ### Step 4: Schedule the next wakeup (only when invoked under `/loop`)
123
+
124
+ **Skip this step entirely when the skill was invoked as bare `/pr-converge`** (manual mode). Manual mode runs exactly one tick and returns without scheduling — the user re-runs the skill or wraps it in `/loop` to continue. References elsewhere in this document to "schedule next wakeup, return" mean Step 4 below; under manual mode every such reference becomes "return" only.
125
+
126
+ Detect manual mode by inspecting the conversation context: when the most recent user message that triggered this run was `/pr-converge` (no `/loop` prefix and no prior `ScheduleWakeup` chain entry that fired with `prompt: "/loop /pr-converge"`), this is manual mode. When the run was triggered by the parent's /loop wakeup chain or the user typed `/loop /pr-converge`, this is loop mode.
127
+
128
+ In **loop mode**, call `ScheduleWakeup` with:
129
+
130
+ - `delaySeconds: 270` whenever bugbot was just re-triggered (whether by Step 3 directly, by the Fix protocol's mandatory re-trigger, or by BUGTEAM branch 1's same-tick re-trigger). Bugbot finishes a review in 1–4 minutes, so 270s stays under the 5-minute prompt-cache TTL while giving a margin past bugbot's typical upper bound. The single exception is the BUGBOT inline-lag branch, which uses `delaySeconds: 60` because no re-trigger fired and the only thing being awaited is GitHub's inline-comments API catching up.
131
+ - `reason`: one short sentence on what is being awaited, including the current `phase` and `bugbot_clean_at` SHA when set.
132
+ - `prompt: "/loop /pr-converge"` — re-enters this skill via /loop on the next firing.
133
+
134
+ **On convergence (loop mode):** omit the ScheduleWakeup call entirely. The /loop terminates because no next wakeup was scheduled.
135
+
136
+ ## Fix protocol
137
+
138
+ Used by both phases when findings exist:
139
+
140
+ - Read each referenced file:line.
141
+ - Write a failing test first when the finding has behavior to test. For pure doc, comment, or naming nits with no behavior, go straight to the fix.
142
+ - Implement the fix.
143
+ - Stage the affected files and create one new commit on the existing branch:
144
+ ```bash
145
+ git add <files> && git commit -m "fix(review): <brief summary>"
146
+ ```
147
+ Honor pre-commit and pre-push hooks; when a hook rejects, read its message, fix the underlying issue, retry. Hook rejections flag real underlying issues worth investigating.
148
+ - Push the new commit:
149
+ ```bash
150
+ git push origin <BRANCH>
151
+ ```
152
+ Capture the new HEAD SHA. Set `current_head` to it. Set `bugbot_clean_at = null`.
153
+ - Reply inline on each addressed comment thread using `--body-file` (per gh-body-file rule):
154
+ ```bash
155
+ gh api -X POST repos/<OWNER>/<REPO>/pulls/<NUMBER>/comments/<comment_id>/replies \
156
+ --field body=@<path/to/reply.md>
157
+ ```
158
+ - **Always re-trigger bugbot (Step 3 above) after pushing a fix**, regardless of which phase originated the findings. Any new commit invalidates bugbot's prior clean by definition, so bugbot must re-review the new HEAD before convergence can be claimed. Re-triggering in the same tick saves a full wakeup cycle compared to deferring the trigger to the next tick.
159
+
160
+ ## Stop conditions
161
+
162
+ - **Convergence** (back-to-back clean as defined in Step 2 BUGTEAM second branch — `bugteam reports convergence AND bugbot_clean_at == current_head` with no push during this tick): mark PR ready for review, report one-sentence summary, omit ScheduleWakeup.
163
+ - **Hard blocker:** API auth failure persists across two ticks, a CI regression whose root cause falls outside this PR, a hook rejection investigated through three commits and still unresolved, `inline_lag_streak >= 3`, or `/bugteam` itself reports a stuck state. Report the specific blocker and the diagnosis, then omit ScheduleWakeup.
164
+ - **User stops the loop:** user says "stop the converge loop" → omit ScheduleWakeup on the next tick.
165
+ - **Safety cap:** `tick_count >= 30` (evaluated in Step 3.5) → omit ScheduleWakeup, report the cap was hit. See §Safety cap below for rationale.
166
+
167
+ ## Safety cap
168
+
169
+ When `tick_count >= 30`, stop and report. That many rounds means something structural is wrong with the loop. (Higher than copilot-review's 20-tick cap because two reviewers run sequentially per round.) The increment lives in Step 1; the evaluation lives in Step 3.5.
170
+
171
+ ## Ground rules
170
172
 
171
173
  - **Append commits.** Each tick adds at most one new fix commit. Multiple findings within one tick collapse into a single commit; the next tick handles the next round.
172
174
  - **`bugbot_clean_at` resets on every push.** A new commit invalidates bugbot's prior clean by definition — bugbot must re-review the new HEAD before convergence can be claimed.
173
175
  - **Back-to-back clean is the ONLY termination criterion.** Convergence requires both reviewers clean against the same HEAD with no intervening fixes; either reviewer clean alone counts as in-progress.
174
- - **The `bugbot run` comment is load-bearing.** Use the literal phrase `bugbot run` exactly — empirically the only re-trigger Cursor Bugbot recognizes; alternative phrasings (`re-review`, `bugbot please`, etc.) silently no-op.
175
- - **`gh pr ready` is the convergence action.** Mark the PR ready for review and stop there. Merge, additional reviewers, title, and body remain the user's decisions; the subagent's contract ends at "ready for review."
176
+ - **The `bugbot run` comment is load-bearing.** Use the literal phrase `bugbot run` exactly — empirically the only re-trigger Cursor Bugbot recognizes; alternative phrasings silently no-op.
177
+ - **`gh pr ready` is the convergence action.** Mark the PR ready for review and stop there. Merge, additional reviewers, title, and body remain the user's decisions; the skill's contract ends at "ready for review."
176
178
  - **Honor pre-push and pre-commit hooks.** When a hook rejects the change, read its output, fix the underlying issue (the failing test, the missing constant, the broken import), and retry.
177
179
 
178
180
  ## Examples
179
181
 
180
182
  <example>
181
- User: `/pr-converge`
182
- Claude: [reads PR context, spawns background subagent with the Step 3 template, reports "subagent X driving PR #280 to convergence; will notify on back-to-back clean"]
183
+ User: `/loop /pr-converge`
184
+ Claude: [reads PR context, runs one tick of bugbot phase, schedules next wakeup at 270s with prompt `/loop /pr-converge`, returns]
183
185
  </example>
184
186
 
185
187
  <example>
186
- User: "drive this PR to convergence — bugbot and bugteam until both are clean"
187
- Claude: [same as above]
188
+ User: `/pr-converge`
189
+ Claude: [runs one tick manually, reports state, does NOT schedule a wakeup; user re-runs to advance]
188
190
  </example>
189
191
 
190
192
  <example>
191
- Subagent tick fires in BUGBOT phase, latest bugbot review is against an older commit.
192
- Subagent: [posts `bugbot run` comment, sets `bugbot_clean_at = null`, schedules next wakeup at 300s, returns]
193
+ Tick fires in BUGBOT phase, latest bugbot review is against an older commit.
194
+ Claude: [posts `bugbot run` comment, sets `bugbot_clean_at = null`, schedules next wakeup at 270s, returns]
193
195
  </example>
194
196
 
195
197
  <example>
196
- Subagent tick fires in BUGBOT phase, bugbot has 2 unaddressed findings on HEAD.
197
- Subagent: [TDD-fixes both, one commit, pushes, replies inline on both threads, posts `bugbot run`, schedules next wakeup at 300s, returns]
198
+ Tick fires in BUGBOT phase, bugbot has 2 unaddressed findings on HEAD.
199
+ Claude: [TDD-fixes both, one commit, pushes, replies inline on both threads, posts `bugbot run`, schedules next wakeup at 270s, returns]
198
200
  </example>
199
201
 
200
202
  <example>
201
- Subagent tick fires in BUGBOT phase, bugbot is clean against HEAD.
202
- Subagent: [sets `bugbot_clean_at = HEAD`, transitions `phase = BUGTEAM`, runs `/bugteam` in the same tick]
203
+ Tick fires in BUGBOT phase, bugbot is clean against HEAD.
204
+ Claude: [sets `bugbot_clean_at = HEAD`, transitions `phase = BUGTEAM`, runs `/bugteam` in the same tick]
203
205
  </example>
204
206
 
205
207
  <example>
206
- Subagent in BUGTEAM phase, /bugteam reports convergence and `bugbot_clean_at == current_head`.
207
- Subagent: [runs `gh pr ready [NUMBER]`, reports "PR converged: bugbot CLEAN at <SHA>, bugteam CLEAN at <SHA>; marked ready for review", terminates]
208
+ In BUGTEAM phase, /bugteam reports convergence and `bugbot_clean_at == current_head`.
209
+ Claude: [runs `gh pr ready <NUMBER>`, reports "PR converged: bugbot CLEAN at <SHA>, bugteam CLEAN at <SHA>; marked ready for review", omits ScheduleWakeup, terminates the /loop]
208
210
  </example>
209
211
 
210
212
  <example>
211
- Subagent in BUGTEAM phase, /bugteam pushed a fix commit during its run.
212
- Subagent: [re-resolves HEAD, sets `bugbot_clean_at = null`, posts `bugbot run` in this same tick, transitions `phase = BUGBOT`, schedules next wakeup at 300s]
213
+ In BUGTEAM phase, /bugteam pushed a fix commit during its run.
214
+ Claude: [re-resolves HEAD, sets `bugbot_clean_at = null`, posts `bugbot run` in this same tick, transitions `phase = BUGBOT`, schedules next wakeup at 270s]
213
215
  </example>
214
216
 
215
217
  <example>
216
- Subagent tick fires in BUGBOT phase, bugbot review body says "found 3 potential issues" against HEAD but the inline-comments API returns zero matching comments for `current_head`.
217
- Subagent: [increments `inline_lag_streak` to 1, schedules next wakeup at 60s, returns; expects inline comments to appear by the next tick]
218
+ Tick fires in BUGBOT phase, bugbot review body says "found 3 potential issues" against HEAD but the inline-comments API returns zero matching comments for `current_head`.
219
+ Claude: [increments `inline_lag_streak` to 1, schedules next wakeup at 60s, returns; expects inline comments to appear by the next tick]
218
220
  </example>