claude-dev-env 1.86.1 → 1.88.0

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.
@@ -250,35 +250,35 @@ test('the COPILOT phase recomputes copilotDown from each gate outcome via resolv
250
250
  );
251
251
  });
252
252
 
253
- test('markReady receives copilotDown so it can opt the unflagged hook out of the Copilot gate', () => {
253
+ test('the merged FINALIZE check receives copilotDown so its mark-ready step can opt the unflagged hook out of the Copilot gate', () => {
254
254
  const finalizeStart = convergeSource.indexOf("if (phase === 'FINALIZE') {");
255
255
  assert.notEqual(finalizeStart, -1, 'expected a FINALIZE phase block');
256
- const markReadyCall = convergeSource.indexOf("'mark-ready'", finalizeStart);
257
- assert.notEqual(markReadyCall, -1, 'expected the FINALIZE phase to route mark-ready through the general-utility agent');
258
- const callSlice = convergeSource.slice(markReadyCall - 20, markReadyCall + 60);
256
+ const checkCall = convergeSource.indexOf('runConvergenceCheck(', finalizeStart);
257
+ assert.notEqual(checkCall, -1, 'expected the FINALIZE phase to route the merged convergence check');
258
+ const callSlice = convergeSource.slice(checkCall, checkCall + 60);
259
259
  assert.match(
260
260
  callSlice,
261
261
  /copilotDown/,
262
- 'expected mark-ready context to include copilotDown so the agent can opt the unflagged hook out of the Copilot gate',
262
+ 'expected the merged check context to include copilotDown so its mark-ready step can opt the unflagged hook out of the Copilot gate',
263
263
  );
264
264
  });
265
265
 
266
- test('the mark-ready task in runGeneralUtilityTask opts the unflagged convergence hook out of Copilot when copilotDown', () => {
267
- const markReadyBody = functionBody('runGeneralUtilityTask');
266
+ test('the merged FINALIZE check opts the unflagged convergence hook out of Copilot when copilotDown before gh pr ready', () => {
267
+ const checkBody = functionBody('runConvergenceCheck');
268
268
  assert.match(
269
- markReadyBody,
269
+ checkBody,
270
270
  /context\.copilotDown/,
271
- 'expected the mark-ready task to branch on copilotDown',
271
+ 'expected the merged check to branch on copilotDown',
272
272
  );
273
273
  assert.match(
274
- markReadyBody,
274
+ checkBody,
275
275
  /CLAUDE_REVIEWS_DISABLED/,
276
- 'expected the mark-ready prompt to set CLAUDE_REVIEWS_DISABLED so the unflagged hook re-derives the Copilot bypass',
276
+ 'expected the merged check prompt to set CLAUDE_REVIEWS_DISABLED so the unflagged hook re-derives the Copilot bypass',
277
277
  );
278
278
  assert.match(
279
- markReadyBody,
279
+ checkBody,
280
280
  /copilot/,
281
- 'expected the mark-ready opt-out to name the copilot token',
281
+ 'expected the merged check opt-out to name the copilot token',
282
282
  );
283
283
  });
284
284
 
@@ -32,6 +32,12 @@ const CONFIG = {
32
32
 
33
33
  const REVIEWER_GATE_SENTINEL = 'CLAUDE_REVIEWER_GATE=autoconverge '
34
34
 
35
+ const TIERS = {
36
+ opusMedium: { model: 'opus', effort: 'medium' },
37
+ sonnetMedium: { model: 'sonnet', effort: 'medium' },
38
+ haikuLow: { model: 'haiku', effort: 'low' },
39
+ }
40
+
35
41
  const HEADLESS_SAFETY_PREAMBLE =
36
42
  'HEADLESS RUN — you run unattended: no human can answer a permission or confirmation prompt, and any such prompt stalls the entire convergence run. The destructive_command_blocker hook matches dangerous patterns (rm -rf, git reset --hard, dd, mkfs, chmod -R, fork bombs) as raw text anywhere in a Bash command, with no quote-awareness — so a destructive string stalls you even when it is only data you never execute. Therefore:\n' +
37
43
  '- Never place a destructive-command literal inside a Bash command — not in echo, not in a heredoc, and not as an argument to python -c, node -e, or awk. To exercise or verify destructive_command_blocker (or any hook) behavior, run the committed test suite, e.g. python -m pytest <test_file>, which passes the command strings as in-language data rather than as a shell command.\n' +
@@ -84,8 +90,10 @@ const convergeAgent = (prompt, options) =>
84
90
  * 'preflight-git', bundles the mechanical git reads and the reviewer-availability
85
91
  * probe into a single agent startup: it prints the PR HEAD SHA, fetches origin
86
92
  * main so the review lenses diff against an up-to-date base, polls GitHub
87
- * mergeability, and runs the shared reviewer_availability.py CLI for Copilot and
88
- * Bugbot, returning {sha, conflicting, fetched, copilot, bugbot} in one
93
+ * mergeability, runs the shared reviewer_availability.py CLI for Copilot and
94
+ * Bugbot, and enumerates the origin/main...HEAD diff so the review lenses reuse
95
+ * one changed-file list rather than each re-deriving it, returning
96
+ * {sha, conflicting, fetched, changedFiles, diffstat, copilot, bugbot} in one
89
97
  * structured result. The reviewer availability rides this same preflight so the
90
98
  * round's first git-utility spawn carries the pre-spawn reviewer decision without
91
99
  * a separate agent. The agent never edits code, so it runs on the cheapest model
@@ -98,7 +106,7 @@ function runGitTask(task) {
98
106
  throw new Error(`runGitTask has no handler for task ${task}`)
99
107
  }
100
108
  return convergeAgent(
101
- `Run four read-only preflight steps for ${prCoordinates}. Do not edit, commit, push, rebase, or modify any files — read only.\n\n` +
109
+ `Run five read-only preflight steps for ${prCoordinates}. Do not edit, commit, push, rebase, or modify any files — read only.\n\n` +
102
110
  `STEP 1 — resolve HEAD. Print the current PR HEAD SHA. Run exactly:\n` +
103
111
  ` gh api repos/${input.owner}/${input.repo}/pulls/${input.prNumber} --jq .head.sha\n` +
104
112
  `Return the full 40-character SHA in the sha field.\n\n` +
@@ -112,8 +120,12 @@ function runGitTask(task) {
112
120
  `STEP 4 — check whether GitHub Copilot and Cursor Bugbot are available to review this PR, before either reviewer's own agent is spawned. Run exactly:\n` +
113
121
  ` python "${CONFIG.prLoopScripts}/reviewer_availability.py" --reviewer copilot\n` +
114
122
  ` python "${CONFIG.prLoopScripts}/reviewer_availability.py" --reviewer bugbot\n` +
115
- `Each run exits 0 when that reviewer is available and non-zero when it is down, and prints one line naming the reason (stdout when available, stderr when down) — capture that line. In the copilot and bugbot fields, report down as whether that reviewer's run exited non-zero and reason as its printed line.`,
116
- { label: 'git-utility', phase: 'Converge', schema: PREFLIGHT_GIT_SCHEMA, agentType: 'Explore', model: 'haiku', effort: 'low' },
123
+ `Each run exits 0 when that reviewer is available and non-zero when it is down, and prints one line naming the reason (stdout when available, stderr when down) — capture that line. In the copilot and bugbot fields, report down as whether that reviewer's run exited non-zero and reason as its printed line.\n\n` +
124
+ `STEP 5 enumerate the diff against the refreshed base so the parallel review lenses reuse this file list rather than each re-deriving the diff. Run exactly:\n` +
125
+ ` git diff --name-status origin/main...HEAD\n` +
126
+ ` git diff --stat origin/main...HEAD\n` +
127
+ `Return the first command's output verbatim in changedFiles and the second's in diffstat (both strings; an empty string when a command produced no output).`,
128
+ { label: 'git-utility', phase: 'Converge', schema: PREFLIGHT_GIT_SCHEMA, agentType: 'Explore', ...TIERS.haikuLow },
117
129
  )
118
130
  }
119
131
 
@@ -138,7 +150,7 @@ function runFixerTask(task, context) {
138
150
  `- On a successful push: newSha=the new HEAD SHA after your push, pushed=true, resolvedWithoutCommit=false, blockedNeedingEdit=false, blockerDetail="", and a one-line summary.\n` +
139
151
  `- When a commit-time hook or gate (for example code_rules_gate, the CODE_RULES commit gate) rejects the commit because the fix needs a code change: keep the no-edit rule, return newSha=${context.head}, pushed=false, resolvedWithoutCommit=false, blockedNeedingEdit=true, blockerDetail=<the verbatim hook message naming the file and rule>, and a summary. A recovery fixer runs after you to clear it.\n` +
140
152
  `- On a transient or non-code failure (auth, network, a non-fast-forward, a lock): newSha=${context.head}, pushed=false, resolvedWithoutCommit=false, blockedNeedingEdit=false, blockerDetail="", and a summary naming the failure.`,
141
- { label, phase: 'Converge', schema: FIX_SCHEMA, agentType: 'clean-coder' },
153
+ { label, phase: 'Converge', schema: FIX_SCHEMA, agentType: 'clean-coder', ...TIERS.sonnetMedium },
142
154
  )
143
155
  }
144
156
  if (task === 'commit-recover') {
@@ -152,7 +164,7 @@ function runFixerTask(task, context) {
152
164
  `- Leave the corrected fixes in the working tree. Do NOT commit and do NOT push — the verify step re-binds a verdict and the commit step pushes after you.\n\n` +
153
165
  `Return values: edited=true with a one-line summary when you changed code to clear the block; edited=false, resolvedWithoutCommit=false when the block cannot be cleared with a code change.` +
154
166
  PRE_COMMIT_GATE_STEP,
155
- { label, phase: 'Converge', schema: EDIT_SCHEMA, agentType: 'clean-coder' },
167
+ { label, phase: 'Converge', schema: EDIT_SCHEMA, agentType: 'clean-coder', ...TIERS.sonnetMedium },
156
168
  )
157
169
  }
158
170
  const objection = context.objection || VERIFY_OBJECTION_FALLBACK
@@ -166,7 +178,7 @@ function runFixerTask(task, context) {
166
178
  `- Leave the corrected fixes in the working tree. Do NOT commit and do NOT push — the verify step re-binds a verdict and the commit step pushes after you.\n\n` +
167
179
  `Return values: edited=true with a one-line summary when you changed code to address the objections; edited=false, resolvedWithoutCommit=false when the objections cannot be cleared with a code change.` +
168
180
  PRE_COMMIT_GATE_STEP,
169
- { label, phase: 'Converge', schema: EDIT_SCHEMA, agentType: 'clean-coder' },
181
+ { label, phase: 'Converge', schema: EDIT_SCHEMA, agentType: 'clean-coder', ...TIERS.sonnetMedium },
170
182
  )
171
183
  }
172
184
 
@@ -237,7 +249,7 @@ function runCodeEditorTask(task, context) {
237
249
  `- When every finding was already addressed so no code change was needed — yet you still resolved each GitHub review thread above: edited=false, resolvedWithoutCommit=true. Only set this when every thread that carries a comment id is resolved; otherwise the round is treated as stalled.\n` +
238
250
  `Always include a one-line summary.` +
239
251
  PRE_COMMIT_GATE_STEP,
240
- { label, phase: 'Converge', schema: EDIT_SCHEMA, agentType: 'clean-coder' },
252
+ { label, phase: 'Converge', schema: EDIT_SCHEMA, agentType: 'clean-coder', ...TIERS.opusMedium },
241
253
  )
242
254
  }
243
255
  if (task === 'conflict-edit') {
@@ -248,7 +260,7 @@ function runCodeEditorTask(task, context) {
248
260
  `- Rebase the branch onto origin/main and resolve every conflict so the tree is clean and conflict-free: git fetch origin main; git rebase origin/main; resolve each conflict, preserving the intent of both the PR's change and the incoming base change. A rebase creates local commits, which is fine.\n` +
249
261
  `- Do NOT push and do NOT force-push — the commit step force-pushes after the verify step binds a verdict. Pushing here would change the surface the verifier binds to.\n\n` +
250
262
  `Return rebased=true with a one-line summary when you rebased onto origin/main and resolved the conflicts; rebased=false with a summary when the branch did not actually need a rebase or you could not complete it.`,
251
- { label, phase: 'Converge', schema: CONFLICT_EDIT_SCHEMA, agentType: 'clean-coder' },
263
+ { label, phase: 'Converge', schema: CONFLICT_EDIT_SCHEMA, agentType: 'clean-coder', ...TIERS.opusMedium },
252
264
  )
253
265
  }
254
266
  if (task === 'repair-edit') {
@@ -268,7 +280,7 @@ function runCodeEditorTask(task, context) {
268
280
  `- resolvedWithoutCommit=true only when you addressed the gates with neither a code change nor a rebase (bot threads resolved only), so there is nothing for the commit step to push.\n` +
269
281
  `Always include a one-line summary.` +
270
282
  PRE_COMMIT_GATE_STEP,
271
- { label, phase: 'Finalize', schema: REPAIR_EDIT_SCHEMA, agentType: 'clean-coder' },
283
+ { label, phase: 'Finalize', schema: REPAIR_EDIT_SCHEMA, agentType: 'clean-coder', ...TIERS.opusMedium },
272
284
  )
273
285
  }
274
286
  if (task === 'repair-commit') {
@@ -284,7 +296,7 @@ function runCodeEditorTask(task, context) {
284
296
  `- On a successful push: newSha=the new HEAD SHA after your push, pushed=true, resolvedWithoutCommit=false, blockedNeedingEdit=false, blockerDetail="", and a one-line summary.\n` +
285
297
  `- When a commit-time hook or gate (for example code_rules_gate, the CODE_RULES commit gate) rejects the commit because the fix needs a code change: keep the no-edit rule, return newSha=${context.head}, pushed=false, resolvedWithoutCommit=false, blockedNeedingEdit=true, blockerDetail=<the verbatim hook message naming the file and rule>, and a summary. A recovery fixer runs after you to clear it.\n` +
286
298
  `- On a transient or non-code failure (auth, network, a non-fast-forward, a lock): newSha=${context.head}, pushed=false, resolvedWithoutCommit=false, blockedNeedingEdit=false, blockerDetail="", and a summary naming the failure.`,
287
- { label, phase: 'Finalize', schema: FIX_SCHEMA, agentType: 'clean-coder' },
299
+ { label, phase: 'Finalize', schema: FIX_SCHEMA, agentType: 'clean-coder', ...TIERS.sonnetMedium },
288
300
  )
289
301
  }
290
302
  if (task === 'standards-edit') {
@@ -300,7 +312,7 @@ function runCodeEditorTask(task, context) {
300
312
  `3. For each finding that carries a GitHub review comment id (${threadIds.length ? threadIds.join(', ') : 'none this batch'}): post an inline reply via python "${CONFIG.sharedScripts}/post_fix_reply.py" --owner ${input.owner} --repo ${input.repo} --pr-number ${input.prNumber} --in-reply-to <id> --body "Code-standard-only finding — deferred to follow-up issue <url>." Then resolve the thread by its PRRT_ node id (GraphQL lookup on comment databaseId, then resolveReviewThread or the github MCP pull_request_review_write method=resolve_thread — not the numeric comment id).\n\n` +
301
313
  `Return the issue URL in issueUrl (empty string when it could not be filed), the hardening checkout path and branch, hardeningEdited, and a one-line summary.` +
302
314
  PRE_COMMIT_GATE_STEP,
303
- { label, phase: 'Converge', schema: STANDARDS_EDIT_SCHEMA, agentType: 'clean-coder' },
315
+ { label, phase: 'Converge', schema: STANDARDS_EDIT_SCHEMA, agentType: 'clean-coder', ...TIERS.opusMedium },
304
316
  )
305
317
  }
306
318
  if (task === 'standards-resolve-threads') {
@@ -314,7 +326,7 @@ function runCodeEditorTask(task, context) {
314
326
  `Findings:\n${findingsBlock}\n\n` +
315
327
  `For each finding that carries a GitHub review comment id (${threadIds.length ? threadIds.join(', ') : 'none this batch'}): post an inline reply via python "${CONFIG.sharedScripts}/post_fix_reply.py" --owner ${input.owner} --repo ${input.repo} --pr-number ${input.prNumber} --in-reply-to <id> --body "Code-standard-only finding — deferred to ${issueReference}." Then resolve the thread by its PRRT_ node id (GraphQL lookup on comment databaseId, then resolveReviewThread or the github MCP pull_request_review_write method=resolve_thread — not the numeric comment id).\n\n` +
316
328
  `Return a one-line summary naming the threads you resolved.`,
317
- { label, phase: 'Converge', agentType: 'clean-coder' },
329
+ { label, phase: 'Converge', agentType: 'clean-coder', ...TIERS.sonnetMedium },
318
330
  )
319
331
  }
320
332
  if (task === 'hardening-commit') {
@@ -325,7 +337,7 @@ function runCodeEditorTask(task, context) {
325
337
  `- In ${context.hardeningRepoPath}: make ONE commit of the staged hooks/rules change on branch ${context.hardeningBranch}, push it, then open a DRAFT PR. The PR body references the follow-up issue ${context.issueUrl || '(none)'} and states the PR hardens the environment so the deferred violation classes are blocked at Write/Edit time. Honor the gh-body-file rule: write a BOM-free temp file and pass --body-file.\n` +
326
338
  `- Title the PR as a Conventional Commit — a type prefix (feat, fix, chore, docs, refactor, perf, ci, style, test, build, revert), an optional scope in parentheses, then a colon and a short summary, e.g. "feat(hooks): block the deferred violation class". The target repo's CI validates the PR title as a semantic commit and rejects a non-conforming title.\n\n` +
327
339
  `Return the full https URL of the DRAFT hardening PR in hardeningPrUrl (empty string when no PR was opened) and a one-line summary.`,
328
- { label, phase: 'Converge', schema: HARDENING_COMMIT_SCHEMA, agentType: 'clean-coder' },
340
+ { label, phase: 'Converge', schema: HARDENING_COMMIT_SCHEMA, agentType: 'clean-coder', ...TIERS.sonnetMedium },
329
341
  )
330
342
  }
331
343
  if (task === 'commit-recover') {
@@ -339,7 +351,7 @@ function runCodeEditorTask(task, context) {
339
351
  `- Leave the corrected fixes in the working tree. Do NOT commit and do NOT push — the verify step re-binds a verdict and the commit step pushes after you.\n\n` +
340
352
  `Return values: edited=true with a one-line summary when you changed code to clear the block; edited=false, resolvedWithoutCommit=false when the block cannot be cleared with a code change.` +
341
353
  PRE_COMMIT_GATE_STEP,
342
- { label, phase: 'Converge', schema: EDIT_SCHEMA, agentType: 'clean-coder' },
354
+ { label, phase: 'Converge', schema: EDIT_SCHEMA, agentType: 'clean-coder', ...TIERS.sonnetMedium },
343
355
  )
344
356
  }
345
357
  // verify-recover
@@ -354,7 +366,7 @@ function runCodeEditorTask(task, context) {
354
366
  `- Leave the corrected fixes in the working tree. Do NOT commit and do NOT push — the verify step re-binds a verdict and the commit step pushes after you.\n\n` +
355
367
  `Return values: edited=true with a one-line summary when you changed code to address the objections; edited=false, resolvedWithoutCommit=false when the objections cannot be cleared with a code change.` +
356
368
  PRE_COMMIT_GATE_STEP,
357
- { label, phase: 'Converge', schema: EDIT_SCHEMA, agentType: 'clean-coder' },
369
+ { label, phase: 'Converge', schema: EDIT_SCHEMA, agentType: 'clean-coder', ...TIERS.sonnetMedium },
358
370
  )
359
371
  }
360
372
 
@@ -377,7 +389,7 @@ function runVerifierTask(task, context) {
377
389
  `1. Resolve the worktree repo root for running tests: REPO=$(git rev-parse --show-toplevel).\n` +
378
390
  `2. Verify the uncommitted working-tree changes resolve every finding above: run the relevant tests and the named gates against the working tree. Read the diff (git diff) and confirm each finding is fixed test-first per CODE_RULES.\n` +
379
391
  `3. ${buildVerdictFenceSteps(input.owner, input.repo, input.prNumber)}`,
380
- { label, phase: 'Converge', agentType: 'code-verifier' },
392
+ { label, phase: 'Converge', agentType: 'code-verifier', ...TIERS.sonnetMedium },
381
393
  )
382
394
  }
383
395
  if (task === 'repair-verify') {
@@ -391,7 +403,7 @@ function runVerifierTask(task, context) {
391
403
  `1. Resolve the worktree repo root for running tests: REPO=$(git rev-parse --show-toplevel).\n` +
392
404
  `2. Verify the working tree against origin/main: any bot-thread code fix is correct test-first per CODE_RULES, and a rebase (if any) left a clean, conflict-free tree. Read the diff (git diff origin/main) and run the relevant tests and named gates.\n` +
393
405
  `3. ${buildVerdictFenceSteps(input.owner, input.repo, input.prNumber)}`,
394
- { label, phase: 'Finalize', agentType: 'code-verifier' },
406
+ { label, phase: 'Finalize', agentType: 'code-verifier', ...TIERS.sonnetMedium },
395
407
  )
396
408
  }
397
409
  return convergeAgent(
@@ -410,7 +422,7 @@ function runVerifierTask(task, context) {
410
422
  ` {"all_pass": true, "findings": [], "manifest_sha256": "<that hash>"}\n` +
411
423
  " ```\n" +
412
424
  ` When verification fails, set all_pass to false and list the unresolved concerns in findings; still include the manifest_sha256. The verdict fence must be the last thing in your message.`,
413
- { label, phase: 'Converge', agentType: 'code-verifier' },
425
+ { label, phase: 'Converge', agentType: 'code-verifier', ...TIERS.sonnetMedium },
414
426
  )
415
427
  }
416
428
 
@@ -435,11 +447,10 @@ function serializeOneLineJson(valueToSerialize) {
435
447
  }
436
448
 
437
449
  /**
438
- * Spawn a fresh general-utility general-purpose agent for one of its two
439
- * administrative tasks: 'post-clean-audit' posts the terminal CLEAN bugteam
440
- * review, and 'mark-ready' marks the PR ready and confirms it left draft state.
441
- * The agent edits no code.
442
- * @param {'post-clean-audit'|'mark-ready'} task the short task name
450
+ * Spawn a fresh general-utility general-purpose agent for its administrative task:
451
+ * 'post-clean-audit' posts the terminal CLEAN bugteam review. The agent edits no
452
+ * code.
453
+ * @param {'post-clean-audit'} task the short task name
443
454
  * @param {object} context task-specific context
444
455
  * @returns {Promise<object>} the task result
445
456
  */
@@ -480,41 +491,44 @@ function runGeneralUtilityTask(task, context) {
480
491
  `python "${CONFIG.prLoopScripts}/post_audit_thread.py" --skill bugteam --owner ${input.owner} --repo ${input.repo} --pr-number ${input.prNumber} --commit ${context.head} --state CLEAN --findings-json <temp-file>\n` +
481
492
  `Run the script with --help first if any flag name differs. This posts the APPROVE review body that check_convergence.py reads for the bugteam gate. Do not edit code, commit, or push.\n\n` +
482
493
  `Report whether the review landed. When the script prints a review URL, return {posted:true, reviewUrl:<that URL>, reason:""}. When the script is denied (a permission prompt or auto-mode-classifier block), errors, or prints anything other than a review URL, return {posted:false, reviewUrl:"", reason:<the denial message or error as one line>}. Do not retry a denied post.`,
483
- { label, phase: 'Converge', schema: CLEAN_AUDIT_SCHEMA, agentType: 'general-purpose' },
484
- )
485
- }
486
- if (task === 'mark-ready') {
487
- const copilotOptOut = context.copilotDown
488
- ? `0. Copilot is down this run, so opt the independent mark-ready blocker hook out of the Copilot gate before step 1. Export the token in the same shell session as step 1 so the hook's convergence re-check inherits it:\n bash: export CLAUDE_REVIEWS_DISABLED="copilot" (PowerShell: $env:CLAUDE_REVIEWS_DISABLED = "copilot")\n`
489
- : ''
490
- return convergeAgent(
491
- `All convergence gates pass for ${prCoordinates} on HEAD ${context.head}. Mark the PR ready, then confirm it left draft state. Do not edit code.\n\n` +
492
- copilotOptOut +
493
- `1. Run: gh pr ready ${input.prNumber} --repo ${input.owner}/${input.repo}\n` +
494
- `2. Re-query the draft state: gh api repos/${input.owner}/${input.repo}/pulls/${input.prNumber} --jq .draft\n` +
495
- `Return {ready:true} only when step 2 prints false (the PR is no longer a draft). If step 1 errors or step 2 still prints true, return {ready:false}.`,
496
- { label, phase: 'Finalize', schema: READY_SCHEMA, agentType: 'general-purpose' },
494
+ { label, phase: 'Converge', schema: CLEAN_AUDIT_SCHEMA, agentType: 'general-purpose', ...TIERS.haikuLow },
497
495
  )
498
496
  }
499
497
  throw new Error(`runGeneralUtilityTask: unknown task ${task}`)
500
498
  }
501
499
 
502
500
  /**
503
- * Spawn a fresh convergence-check Explore agent for the convergence check.
504
- * @param {object} context carries bugbotDown and copilotDown
505
- * @returns {Promise<object>} CONVERGENCE_SCHEMA result
501
+ * Spawn a fresh convergence-check general-utility agent that runs the convergence
502
+ * gate and, when it passes, marks the PR ready in the same turn — one agent doing
503
+ * check_convergence.py and (on exit 0) gh pr ready rather than a separate
504
+ * check-then-mark pair. A failing check returns its FAIL lines with ready:false so
505
+ * the FINALIZE loop routes to the repair path, which loops back and re-runs this
506
+ * same combined check; only the passing path ever attempts gh pr ready. The agent
507
+ * edits no code, so it runs on the cheapest model at low effort.
508
+ * @param {object} context carries head, bugbotDown, and copilotDown
509
+ * @returns {Promise<object>} FINALIZE_SCHEMA result
506
510
  */
507
511
  function runConvergenceCheck(context) {
508
- const label = 'check-convergence'
512
+ const label = 'finalize-check'
509
513
  const bugbotDownFlag = context.bugbotDown ? ' --bugbot-down' : ''
510
514
  const copilotDownFlag = context.copilotDown ? ' --copilot-down' : ''
515
+ const copilotOptOut = context.copilotDown
516
+ ? ` Copilot is down this run, so before gh pr ready export the token in this same shell session so the independent mark-ready blocker hook's convergence re-check inherits it:\n bash: export CLAUDE_REVIEWS_DISABLED="copilot" (PowerShell: $env:CLAUDE_REVIEWS_DISABLED = "copilot")\n`
517
+ : ''
511
518
  return convergeAgent(
512
- `Run the convergence gate for ${prCoordinates} and report the result. Do not edit code.\n\n` +
513
- `Run: python "${CONFIG.sharedScripts}/check_convergence.py" --owner ${input.owner} --repo ${input.repo} --pr-number ${input.prNumber}${bugbotDownFlag}${copilotDownFlag}\n\n` +
514
- `Exit 0 -> every gate passed: return {pass:true, failures:[]}.\n` +
515
- `Exit 1 -> return {pass:false, failures:[<each printed FAIL line verbatim>]}.\n` +
516
- `Exit 2 -> retry once; if it still errors, return {pass:false, failures:["check_convergence gh error"]}.`,
517
- { label, phase: 'Finalize', schema: CONVERGENCE_SCHEMA, agentType: 'Explore' },
519
+ `Run the convergence gate for ${prCoordinates} on HEAD ${context.head} and, only when every gate passes, mark the PR ready. Do not edit code.\n\n` +
520
+ `1. Run: python "${CONFIG.sharedScripts}/check_convergence.py" --owner ${input.owner} --repo ${input.repo} --pr-number ${input.prNumber}${bugbotDownFlag}${copilotDownFlag}\n` +
521
+ ` Exit 0 -> every gate passed: set pass:true, failures:[].\n` +
522
+ ` Exit 1 -> set pass:false and failures to each printed FAIL line verbatim.\n` +
523
+ ` Exit 2 -> retry once; if it still errors, set pass:false, failures:["check_convergence gh error"].\n\n` +
524
+ `2. Only when step 1 set pass:true, mark the PR ready and confirm it left draft state:\n` +
525
+ copilotOptOut +
526
+ ` Run: gh pr ready ${input.prNumber} --repo ${input.owner}/${input.repo}\n` +
527
+ ` Re-query the draft state: gh api repos/${input.owner}/${input.repo}/pulls/${input.prNumber} --jq .draft\n` +
528
+ ` Set ready:true only when the re-query prints false (the PR is no longer a draft); set ready:false when gh pr ready errors or the re-query still prints true.\n` +
529
+ ` When step 1 set pass:false, do NOT run gh pr ready — set ready:false.\n\n` +
530
+ `Return strictly the schema {pass, failures, ready}.`,
531
+ { label, phase: 'Finalize', schema: FINALIZE_SCHEMA, agentType: 'general-purpose', ...TIERS.haikuLow },
518
532
  )
519
533
  }
520
534
 
@@ -599,10 +613,12 @@ const PREFLIGHT_GIT_SCHEMA = {
599
613
  description: 'true only when GitHub reports the PR branch conflicts with its base (mergeable:false or mergeable_state:dirty); false when it merges cleanly or mergeability could not be computed',
600
614
  },
601
615
  fetched: { type: 'boolean', description: 'true when git fetch origin main completed successfully' },
616
+ changedFiles: { type: 'string', description: 'git diff --name-status origin/main...HEAD output — the changed-file list the review lenses reuse instead of re-deriving the diff' },
617
+ diffstat: { type: 'string', description: 'git diff --stat origin/main...HEAD output' },
602
618
  copilot: REVIEWER_AVAILABILITY_SCHEMA.properties.copilot,
603
619
  bugbot: REVIEWER_AVAILABILITY_SCHEMA.properties.bugbot,
604
620
  },
605
- required: ['sha', 'conflicting', 'fetched', 'copilot', 'bugbot'],
621
+ required: ['sha', 'conflicting', 'fetched', 'changedFiles', 'diffstat', 'copilot', 'bugbot'],
606
622
  }
607
623
 
608
624
  const FIX_SCHEMA = {
@@ -703,23 +719,15 @@ function buildVerdictFenceSteps(prOwner, prRepo, prNumber) {
703
719
  )
704
720
  }
705
721
 
706
- const CONVERGENCE_SCHEMA = {
722
+ const FINALIZE_SCHEMA = {
707
723
  type: 'object',
708
724
  additionalProperties: false,
709
725
  properties: {
710
726
  pass: { type: 'boolean', description: 'true only when check_convergence.py exits 0' },
711
727
  failures: { type: 'array', items: { type: 'string' }, description: 'FAIL lines from check_convergence.py when pass is false' },
728
+ ready: { type: 'boolean', description: 'true only when the convergence check passed and gh pr ready confirmed the PR left draft state (isDraft false); false on any failing check or a mark-ready that did not clear draft' },
712
729
  },
713
- required: ['pass', 'failures'],
714
- }
715
-
716
- const READY_SCHEMA = {
717
- type: 'object',
718
- additionalProperties: false,
719
- properties: {
720
- ready: { type: 'boolean', description: 'true only when isDraft is confirmed false after gh pr ready' },
721
- },
722
- required: ['ready'],
730
+ required: ['pass', 'failures', 'ready'],
723
731
  }
724
732
 
725
733
  const CLEAN_AUDIT_SCHEMA = {
@@ -1281,7 +1289,7 @@ function isMergeConflicting(mergeState) {
1281
1289
  * agent (null result) or a ready:false report means `gh pr ready` did not land
1282
1290
  * (auth or token drift, a transient gh failure), so the PR is still a draft and
1283
1291
  * the run must surface a blocker rather than claim success.
1284
- * @param {object|null|undefined} readyResult the READY_SCHEMA result, or null on agent failure
1292
+ * @param {object|null|undefined} readyResult the FINALIZE_SCHEMA result carrying the ready field, or null on agent failure
1285
1293
  * @returns {{converged: boolean, blocker: string|null}} convergence decision
1286
1294
  */
1287
1295
  function classifyReadyOutcome(readyResult) {
@@ -1405,16 +1413,50 @@ const input = runInput.input
1405
1413
  activeRepoPath = typeof input.repoPath === 'string' && input.repoPath ? input.repoPath : null
1406
1414
  const prCoordinates = `owner=${input.owner} repo=${input.repo} PR #${input.prNumber} (https://github.com/${input.owner}/${input.repo}/pull/${input.prNumber})`
1407
1415
 
1416
+ /**
1417
+ * Render the changed-file context a review lens reuses instead of re-deriving the
1418
+ * origin/main...HEAD diff itself. The preflight-git task already enumerated the
1419
+ * diff once for the round, so a lens reads the file list and diffstat below and
1420
+ * opens only the files it needs; its review judgment stays its own. A preflight
1421
+ * result missing the file list — a dead preflight agent, or a round that resolved
1422
+ * HEAD before the enumeration ran — falls back to instructing the lens to
1423
+ * enumerate the diff itself.
1424
+ *
1425
+ * ::
1426
+ *
1427
+ * renderLensDiffContext({changedFiles: 'M\ta.py', diffstat: ' a.py | 2 +-'})
1428
+ * -> a block quoting the file list and diffstat
1429
+ * renderLensDiffContext(null) -> the enumerate-it-yourself fallback
1430
+ *
1431
+ * @param {{changedFiles?: string, diffstat?: string}|null|undefined} preflightResult the preflight-git result carrying changedFiles and diffstat
1432
+ * @returns {string} the diff-context block to inject into a lens prompt
1433
+ */
1434
+ function renderLensDiffContext(preflightResult) {
1435
+ const changedFiles = typeof preflightResult?.changedFiles === 'string' ? preflightResult.changedFiles.trim() : ''
1436
+ const diffstat = typeof preflightResult?.diffstat === 'string' ? preflightResult.diffstat.trim() : ''
1437
+ if (changedFiles.length === 0) {
1438
+ return `The workflow already fetched origin/main this round, so do NOT run git fetch; run git diff --name-only origin/main...HEAD to enumerate the changed files, then read the complete diff of each.\n\n`
1439
+ }
1440
+ const diffstatBlock = diffstat.length > 0 ? `Diffstat (git diff --stat origin/main...HEAD):\n${diffstat}\n\n` : ''
1441
+ return (
1442
+ `The workflow already enumerated the origin/main...HEAD diff this round; use the changed-file list and diffstat below rather than re-deriving the diff, and read only the files you need. Your review judgment stays independent.\n\n` +
1443
+ `Changed files (git diff --name-status origin/main...HEAD):\n${changedFiles}\n\n` +
1444
+ diffstatBlock
1445
+ )
1446
+ }
1447
+
1408
1448
  /**
1409
1449
  * Bugbot lens: ensure Cursor Bugbot has rendered a verdict on the given HEAD,
1410
1450
  * triggering and polling its CI check run when needed, and return its findings.
1411
1451
  * @param {string} head PR HEAD SHA to evaluate
1452
+ * @param {object|null|undefined} preflightResult the preflight-git result carrying the changed-file list and diffstat for this round
1412
1453
  * @returns {Promise<object>} LENS_SCHEMA result
1413
1454
  */
1414
- function runBugbotLens(head) {
1455
+ function runBugbotLens(head, preflightResult) {
1415
1456
  return convergeAgent(
1416
1457
  `You are the Cursor Bugbot lens for ${prCoordinates}, HEAD ${head}. Cursor Bugbot participates this run.\n\n` +
1417
1458
  `Goal: return Bugbot's verdict on HEAD ${head}. Do not edit code, commit, or push. You may post the literal trigger comment described below.\n\n` +
1459
+ renderLensDiffContext(preflightResult) +
1418
1460
  `Procedure (use the existing scripts; each step below shows the exact flags that script accepts):\n` +
1419
1461
  `1. Opt-out: python "${CONFIG.prLoopScripts}/reviews_disabled.py" --reviewer bugbot. Exit 0 means disabled -> return {sha, clean:true, down:true, findings:[]}.\n` +
1420
1462
  `2. Silent pass: python "${CONFIG.sharedScripts}/check_bugbot_ci.py" --owner ${input.owner} --repo ${input.repo} --sha ${head} --check-clean. Exit 0 means the CI check completed clean with no review -> return clean with no findings.\n` +
@@ -1427,7 +1469,7 @@ function runBugbotLens(head) {
1427
1469
  `4. No review yet on HEAD: check_bugbot_ci.py --check-active. If active (exit 0), poll: repeat check_bugbot_ci.py --check-clean / --check-active every 60 seconds (wait each 60-second interval inside this turn with the Monitor tool, per the WAITS AND POLLS rule above) for up to 25 iterations, then re-fetch the review. If not active (exit 1), post the literal comment "bugbot run" (no @mention, no other text) via ${REVIEWER_GATE_SENTINEL}python "${CONFIG.sharedScripts}/post_fix_reply.py" --owner ${input.owner} --repo ${input.repo} --pr-number ${input.prNumber} --body "bugbot run", wait 8 seconds inside this turn with the Monitor tool (per the WAITS AND POLLS rule above), then poll as above.\n` +
1428
1470
  `5. If after the full poll budget Bugbot has neither a check run nor a review on HEAD -> return {sha:${'`'}${head}${'`'}, clean:true, down:true, findings:[]} (treat as down).\n\n` +
1429
1471
  `Scope is the whole PR; you are only reading Bugbot's own output here. For each finding set category: 'code-standard' when it is a pure CODE_RULES/style violation (naming, comments, type hints, magic values, structure) with no behavioral impact; 'bug' otherwise. Return strictly the schema.`,
1430
- { label: 'lens:bugbot', phase: 'Converge', schema: LENS_SCHEMA },
1472
+ { label: 'lens:bugbot', phase: 'Converge', schema: LENS_SCHEMA, ...TIERS.opusMedium },
1431
1473
  )
1432
1474
  }
1433
1475
 
@@ -1435,15 +1477,17 @@ function runBugbotLens(head) {
1435
1477
  * Code-review lens: a full-diff /code-review-style pass that reports findings
1436
1478
  * without applying any fix.
1437
1479
  * @param {string} head PR HEAD SHA to evaluate
1480
+ * @param {object|null|undefined} preflightResult the preflight-git result carrying the changed-file list and diffstat for this round
1438
1481
  * @returns {Promise<object>} LENS_SCHEMA result
1439
1482
  */
1440
- function runCodeReviewLens(head) {
1483
+ function runCodeReviewLens(head, preflightResult) {
1441
1484
  return convergeAgent(
1442
1485
  `You are the code-review lens for ${prCoordinates}, HEAD ${head}.\n\n` +
1443
- `Review the FULL origin/main...HEAD diff — every file the PR touches. Do NOT delta-scope to recent commits or to a single file. The workflow already fetched origin/main this round, so do NOT run git fetch; run git diff --name-only origin/main...HEAD to enumerate the changed files, then review the complete diff of each.\n\n` +
1486
+ `Review the FULL origin/main...HEAD diff — every file the PR touches. Do NOT delta-scope to recent commits or to a single file.\n\n` +
1487
+ renderLensDiffContext(preflightResult) +
1444
1488
  `Apply correctness-focused review: real bugs, broken logic, incorrect error handling, data-loss or security risks, contract mismatches, and reuse/simplification problems. Report only defensible findings with concrete file:line evidence.\n\n` +
1445
1489
  `Do NOT edit, commit, or push — reporting only. Return strictly the schema: clean=true with empty findings when the diff is sound, otherwise one entry per finding (severity P0/P1/P2; category 'code-standard' for pure CODE_RULES/style violations with no behavioral impact, 'bug' otherwise; replyToCommentId=null since these are not yet GitHub threads). Set sha=${'`'}${head}${'`'}, down=false.`,
1446
- { label: 'lens:code-review', phase: 'Converge', schema: LENS_SCHEMA, agentType: 'code-quality-agent' },
1490
+ { label: 'lens:code-review', phase: 'Converge', schema: LENS_SCHEMA, agentType: 'code-quality-agent', ...TIERS.opusMedium },
1447
1491
  )
1448
1492
  }
1449
1493
 
@@ -1451,15 +1495,17 @@ function runCodeReviewLens(head) {
1451
1495
  * Bug-audit lens: the bugteam-class second-opinion audit over the full diff,
1452
1496
  * applying the shared A–P audit rubric. Reports findings without fixing.
1453
1497
  * @param {string} head PR HEAD SHA to evaluate
1498
+ * @param {object|null|undefined} preflightResult the preflight-git result carrying the changed-file list and diffstat for this round
1454
1499
  * @returns {Promise<object>} LENS_SCHEMA result
1455
1500
  */
1456
- function runAuditLens(head) {
1501
+ function runAuditLens(head, preflightResult) {
1457
1502
  return convergeAgent(
1458
1503
  `You are the second-opinion bug-audit lens for ${prCoordinates}, HEAD ${head}.\n\n` +
1459
- `Read the audit rubric at ${CONFIG.bugteamRubric} and apply its categories (A through P) against the FULL origin/main...HEAD diff — every file the PR touches, never a delta cut. The workflow already fetched origin/main this round, so do NOT run git fetch; run git diff --name-only origin/main...HEAD first to enumerate scope.\n\n` +
1504
+ `Read the audit rubric at ${CONFIG.bugteamRubric} and apply its categories (A through P) against the FULL origin/main...HEAD diff — every file the PR touches, never a delta cut.\n\n` +
1505
+ renderLensDiffContext(preflightResult) +
1460
1506
  `This is a clean-room audit: assume nothing from other lenses. Report only findings backed by concrete file:line evidence. Do NOT edit, commit, or push.\n\n` +
1461
1507
  `Return strictly the schema: clean=true with empty findings when the diff passes every category, otherwise one entry per finding (severity P0/P1/P2; category 'code-standard' for pure CODE_RULES/style violations with no behavioral impact, 'bug' otherwise; replyToCommentId=null). Set sha=${'`'}${head}${'`'}, down=false.`,
1462
- { label: 'lens:bug-audit', phase: 'Converge', schema: LENS_SCHEMA, agentType: 'code-quality-agent' },
1508
+ { label: 'lens:bug-audit', phase: 'Converge', schema: LENS_SCHEMA, agentType: 'code-quality-agent', ...TIERS.opusMedium },
1463
1509
  )
1464
1510
  }
1465
1511
 
@@ -1471,18 +1517,21 @@ function runAuditLens(head) {
1471
1517
  * reuse pass routes the qualifying findings through applyFixes so they are
1472
1518
  * implemented in one commit before the convergence rounds begin.
1473
1519
  * @param {string} head PR HEAD SHA to evaluate
1520
+ * @param {object|null|undefined} preflightResult the preflight-git result carrying the changed-file list and diffstat for this round
1474
1521
  * @returns {Promise<object>} LENS_SCHEMA result carrying the qualifying reuse findings
1475
1522
  */
1476
- function runReuseAuditPass(head) {
1523
+ function runReuseAuditPass(head, preflightResult) {
1477
1524
  return convergeAgent(
1478
1525
  `You are the REUSE lens for ${prCoordinates}, HEAD ${head}. This pass runs once before convergence to find where the PR re-implements behavior the codebase already provides.\n\n` +
1479
- `Review the FULL origin/main...HEAD diff — every file the PR touches. Do NOT delta-scope to recent commits or a single file. The workflow already fetched origin/main, so do NOT run git fetch; run git diff --name-only origin/main...HEAD to enumerate the changed files, then read the complete diff of each. For every new function, helper, constant, type, or block of logic the PR introduces, search the repository (Serena symbol search, grep, and the project's config/ and shared/ modules) for an existing equivalent that already provides the same behavior.\n\n` +
1526
+ `Review the FULL origin/main...HEAD diff — every file the PR touches. Do NOT delta-scope to recent commits or a single file.\n\n` +
1527
+ renderLensDiffContext(preflightResult) +
1528
+ `For every new function, helper, constant, type, or block of logic the PR introduces, search the repository (Serena symbol search, grep, and the project's config/ and shared/ modules) for an existing equivalent that already provides the same behavior.\n\n` +
1480
1529
  `Report a reuse finding ONLY when ALL THREE criteria hold — when any one is in doubt, omit the finding:\n` +
1481
1530
  ` A. CERTAIN: an existing symbol or module unquestionably covers the new code's behavior, and you can cite it at file:line.\n` +
1482
1531
  ` B. BEHAVIORALLY IDENTICAL: replacing the new code with the existing one changes no observable behavior — same inputs, outputs, side effects, and error handling.\n` +
1483
1532
  ` C. AUTONOMOUSLY IMPLEMENTABLE: the replacement is a mechanical edit (import and call the existing symbol, delete the duplicate) that needs no product decision, no API the existing code lacks, and no human judgment.\n\n` +
1484
1533
  `Do NOT edit, commit, or push — report only; a separate fix step applies what you return. Return strictly the schema: clean=true with empty findings when no reuse case clears all three criteria, otherwise one entry per qualifying reuse improvement. For each: file and line of the duplicate in the PR; severity P2; category 'code-standard'; title naming the existing symbol to reuse; detail giving the existing symbol's file:line and the exact mechanical replacement; replyToCommentId=null. Set sha=${'`'}${head}${'`'}, down=false.`,
1485
- { label: 'lens:reuse', phase: 'Reuse', schema: LENS_SCHEMA, agentType: 'code-quality-agent' },
1534
+ { label: 'lens:reuse', phase: 'Reuse', schema: LENS_SCHEMA, agentType: 'code-quality-agent', ...TIERS.opusMedium },
1486
1535
  )
1487
1536
  }
1488
1537
 
@@ -1629,7 +1678,7 @@ function runCopilotGate(head) {
1629
1678
  ` - Copilot findings on HEAD -> return them (each with its inline comment id in replyToCommentId; category 'code-standard' for pure CODE_RULES/style violations with no behavioral impact, 'bug' otherwise), clean:false, down:false.\n` +
1630
1679
  ` - No review after ${CONFIG.copilotMaxPolls} attempts -> Copilot is down for this run (unreachable, or silently out of quota with no notice): return {sha:${'`'}${head}${'`'}, clean:false, down:true, findings:[]}.\n\n` +
1631
1680
  `Return strictly the schema.`,
1632
- { label: 'copilot-gate', phase: 'Copilot gate', schema: COPILOT_SCHEMA },
1681
+ { label: 'copilot-gate', phase: 'Copilot gate', schema: COPILOT_SCHEMA, ...TIERS.haikuLow },
1633
1682
  )
1634
1683
  }
1635
1684
 
@@ -2017,7 +2066,7 @@ if (isResolvedHeadUsable(preflight?.sha)) {
2017
2066
 
2018
2067
  log('Reuse pass: scanning the full diff for certain, behaviorally identical, autonomously implementable reuse improvements before convergence')
2019
2068
  if (isResolvedHeadUsable(head)) {
2020
- const reuse = await runReuseAuditPass(head)
2069
+ const reuse = await runReuseAuditPass(head, preflight)
2021
2070
  const reuseFindings = reuse?.findings || []
2022
2071
  if (reuseFindings.length > 0) {
2023
2072
  log(`Reuse pass: ${reuseFindings.length} qualifying reuse improvement(s) — applying before convergence`)
@@ -2039,7 +2088,7 @@ while (iterations < CONFIG.maxIterations) {
2039
2088
  iterations += 1
2040
2089
  if (phase === 'CONVERGE') {
2041
2090
  rounds += 1
2042
- if (!isResolvedHeadUsable(head)) {
2091
+ if (!isResolvedHeadUsable(head) || reviewerAvailability?.sha !== head) {
2043
2092
  const refreshedPreflight = await runGitTask('preflight-git')
2044
2093
  reviewerAvailability = refreshedPreflight
2045
2094
  head = isResolvedHeadUsable(refreshedPreflight?.sha) ? refreshedPreflight.sha : null
@@ -2055,9 +2104,9 @@ while (iterations < CONFIG.maxIterations) {
2055
2104
  const isBugbotDownPreSpawn = resolveReviewerDown(reviewerAvailability?.bugbot, input.bugbotDisabled || false)
2056
2105
  log(`Round ${rounds}: parallel Bugbot + code-review + bug-audit on ${head?.slice(0, 7)}`)
2057
2106
  const lenses = await parallel([
2058
- () => (isBugbotDownPreSpawn ? Promise.resolve({ sha: head, clean: true, down: true, notSpawned: true, findings: [] }) : runBugbotLens(head)),
2059
- () => runCodeReviewLens(head),
2060
- () => runAuditLens(head),
2107
+ () => (isBugbotDownPreSpawn ? Promise.resolve({ sha: head, clean: true, down: true, notSpawned: true, findings: [] }) : runBugbotLens(head, reviewerAvailability)),
2108
+ () => runCodeReviewLens(head, reviewerAvailability),
2109
+ () => runAuditLens(head, reviewerAvailability),
2061
2110
  ])
2062
2111
  bugbotDown = lenses[0] == null ? true : resolveReviewerDown(lenses[0], input.bugbotDisabled || false)
2063
2112
  const roundOutcome = resolveRoundOutcome(lenses)
@@ -2193,15 +2242,14 @@ while (iterations < CONFIG.maxIterations) {
2193
2242
  }
2194
2243
 
2195
2244
  if (phase === 'FINALIZE') {
2196
- const convergence = await runConvergenceCheck({ bugbotDown, copilotDown })
2197
- const convergenceOutcome = classifyConvergenceOutcome(convergence)
2245
+ const finalizeResult = await runConvergenceCheck({ head, bugbotDown, copilotDown })
2246
+ const convergenceOutcome = classifyConvergenceOutcome(finalizeResult)
2198
2247
  if (convergenceOutcome.kind === 'retry') {
2199
2248
  log('Convergence check agent died or returned no FAIL lines — re-running the check on the same HEAD')
2200
2249
  continue
2201
2250
  }
2202
2251
  if (convergenceOutcome.kind === 'ready') {
2203
- const readyResult = await runGeneralUtilityTask('mark-ready', { head, copilotDown })
2204
- const readyOutcome = classifyReadyOutcome(readyResult)
2252
+ const readyOutcome = classifyReadyOutcome(finalizeResult)
2205
2253
  if (readyOutcome.converged) {
2206
2254
  return { converged: true, rounds, finalSha: head, blocker: null, standardsNote, copilotNote, reuseNote, deferredPrs }
2207
2255
  }
@@ -12,7 +12,7 @@
12
12
  - **Clean-room audits, every loop.** Each bugfind subagent's spawn prompt contains only the PR scope, audit rubric, and the current loop number. Prior loop history stays in the lead.
13
13
  - **Targeted fixes.** Each fix subagent sees ONLY the most recent audit's findings. Prior loops are invisible to the fix subagent.
14
14
  - **Fix subagent receives the latest audit as its input contract.** Each loop's fix run operates on the current audit's output and only that.
15
- - **Lead owns the final PR description rewrite only** (Step 4.5), via the `pr-description-writer` agent.
15
+ - **Lead owns the final PR description rewrite only** (Step 4.5), composed directly against `docs/PR_DESCRIPTION_GUIDE.md`.
16
16
 
17
17
  ## Why this design
18
18
 
@@ -98,7 +98,7 @@ end-to-end mental model before starting Step 0.
98
98
  | FIX action and verify-push semantics | [reference/audit-and-teammates.md](reference/audit-and-teammates.md) |
99
99
  | Posting the end-of-pass audit review (APPROVE on CLEAN, REQUEST_CHANGES with inline anchored comments on DIRTY) | [§ Audit posting](#audit-posting), which applies [../post-audit-findings/SKILL.md](../post-audit-findings/SKILL.md) |
100
100
  | Posting per-finding fix replies via GitHub MCP `add_reply_to_pull_request_comment` (rendered with the unified template at [`_shared/pr-loop/audit-reply-template.md`](../../_shared/pr-loop/audit-reply-template.md)) | [reference/github-pr-reviews.md](reference/github-pr-reviews.md) |
101
- | Teardown, PR description rewrite via `pr-description-writer`, permission revoke, final report | [../pr-loop-lifecycle/reference/teardown-publish-permissions.md](../pr-loop-lifecycle/reference/teardown-publish-permissions.md) |
101
+ | Teardown, PR description rewrite composed by the lead, permission revoke, final report | [../pr-loop-lifecycle/reference/teardown-publish-permissions.md](../pr-loop-lifecycle/reference/teardown-publish-permissions.md) |
102
102
  | Spawn-prompt XML, A–P category bindings, outcome XML schemas | [PROMPTS.md](PROMPTS.md) |
103
103
  | Per-category audit content (sub-buckets, decision criteria, ready-to-send Variant C templates) | `$HOME/.claude/audit-rubrics/{category_rubrics,prompts}/` |
104
104
  | Invariants and design rationale | [CONSTRAINTS.md](CONSTRAINTS.md), [reference/design-rationale.md](reference/design-rationale.md) |
@@ -5,7 +5,7 @@ description: >-
5
5
  auto-mode AskUserQuestion escalation when the classifier blocks it),
6
6
  worktree preflight and cwd routing, then the ordered close — conditional
7
7
  TeamDelete for team callers, worktree teardown, working-tree clean, PR
8
- description rewrite via pr-description-writer, the always-run permission
8
+ description rewrite composed by the lead, the always-run permission
9
9
  revoke, and the caller-parameterized final report. Invoked by PR-loop
10
10
  orchestrators (bugteam, pr-converge, autoconverge, qbug) at run start and
11
11
  run end, including error exits; not for general git cleanup or permission
@@ -48,7 +48,7 @@ Run these in order from the lead session on EVERY exit — converged, cap reache
48
48
  ```
49
49
  Tolerates already-removed worktrees and missing directories; removal is Windows-safe per `~/.claude/rules/windows-filesystem-safe.md`.
50
50
  3. **Clean the working tree.** Return to the session worktree, remove run-scoped scratch files, and leave `git status` clean of run artifacts.
51
- 4. **Rewrite the PR description.** Follow [`reference/teardown-publish-permissions.md` § Publish the final PR description](reference/teardown-publish-permissions.md): capture the cumulative diff and original body, brief the `pr-description-writer` agent, publish via `update_pull_request`, remove the scratch files. On failure, report it and continue — the revoke still runs.
51
+ 4. **Rewrite the PR description.** Follow [`reference/teardown-publish-permissions.md` § Publish the final PR description](reference/teardown-publish-permissions.md): capture the cumulative diff and original body, compose the new body directly against `docs/PR_DESCRIPTION_GUIDE.md`, publish via `update_pull_request`, remove the scratch files. On failure, report it and continue — the revoke still runs.
52
52
  5. **Revoke project permissions (always):**
53
53
  `python "$HOME/.claude/_shared/pr-loop/scripts/revoke_project_claude_permissions.py"`
54
54
  Non-negotiable, including on error exits: leaving the grant in place lets future sessions inherit elevated `.claude/**` access without an explicit opt-in. Run revoke even when earlier close steps partially failed; log cleanup errors separately.