claude-dev-env 1.74.0 → 1.76.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.
Files changed (78) hide show
  1. package/_shared/pr-loop/scripts/code_rules_gate.py +60 -5
  2. package/_shared/pr-loop/scripts/pr_loop_shared_constants/CLAUDE.md +1 -0
  3. package/_shared/pr-loop/scripts/pr_loop_shared_constants/inline_duplicate_body_span_constants.py +22 -0
  4. package/_shared/pr-loop/scripts/tests/test_code_rules_gate.py +147 -3
  5. package/docs/CODE_RULES.md +1 -1
  6. package/hooks/blocking/CLAUDE.md +3 -2
  7. package/hooks/blocking/claude_md_orphan_file_blocker.py +170 -20
  8. package/hooks/blocking/code_rules_duplicate_body.py +378 -26
  9. package/hooks/blocking/code_rules_enforcer.py +36 -5
  10. package/hooks/blocking/code_rules_imports_logging.py +679 -1
  11. package/hooks/blocking/code_rules_shared.py +8 -5
  12. package/hooks/blocking/code_rules_test_assertions.py +6 -7
  13. package/hooks/blocking/code_verifier_spawn_preflight_gate.py +2 -1
  14. package/hooks/blocking/duplicate_rmtree_helper_blocker.py +155 -0
  15. package/hooks/blocking/hedging_language_blocker.py +1 -13
  16. package/hooks/blocking/intent_only_ending_blocker.py +1 -15
  17. package/hooks/blocking/pre_tool_use_dispatcher.py +4 -5
  18. package/hooks/blocking/question_to_user_enforcer.py +1 -11
  19. package/hooks/blocking/session_handoff_blocker.py +1 -15
  20. package/hooks/blocking/test_claude_md_orphan_file_blocker.py +484 -0
  21. package/hooks/blocking/test_code_rules_enforcer_cap_meta.py +1 -0
  22. package/hooks/blocking/test_code_rules_enforcer_import_block_sort.py +157 -0
  23. package/hooks/blocking/test_code_rules_enforcer_same_file_inline_duplicate.py +466 -0
  24. package/hooks/blocking/test_code_rules_enforcer_split_test_assertions.py +11 -9
  25. package/hooks/blocking/test_code_rules_js_resume_task_enumeration.py +758 -0
  26. package/hooks/blocking/test_code_rules_logging_printf_tokens.py +134 -0
  27. package/hooks/blocking/test_code_verifier_spawn_preflight_gate.py +16 -0
  28. package/hooks/blocking/test_duplicate_rmtree_helper_blocker.py +328 -0
  29. package/hooks/blocking/test_hedging_language_blocker.py +6 -0
  30. package/hooks/blocking/test_intent_only_ending_blocker.py +5 -0
  31. package/hooks/blocking/test_pre_tool_use_dispatcher.py +52 -5
  32. package/hooks/blocking/test_question_to_user_enforcer.py +6 -0
  33. package/hooks/blocking/test_session_handoff_blocker.py +6 -0
  34. package/hooks/blocking/test_verification_verdict_store.py +66 -1
  35. package/hooks/blocking/test_verifier_verdict_minter.py +64 -5
  36. package/hooks/blocking/verification_verdict_store.py +19 -5
  37. package/hooks/blocking/verifier_verdict_minter.py +18 -15
  38. package/hooks/hooks_constants/CLAUDE.md +4 -1
  39. package/hooks/hooks_constants/blocking_check_limits.py +30 -1
  40. package/hooks/hooks_constants/claude_md_orphan_file_blocker_constants.py +52 -24
  41. package/hooks/hooks_constants/code_rules_enforcer_constants.py +41 -1
  42. package/hooks/hooks_constants/code_verifier_spawn_preflight_gate_constants.py +2 -1
  43. package/hooks/hooks_constants/duplicate_function_body_constants.py +21 -5
  44. package/hooks/hooks_constants/duplicate_rmtree_helper_blocker_constants.py +27 -0
  45. package/hooks/hooks_constants/post_tool_use_dispatcher_constants.py +2 -0
  46. package/hooks/hooks_constants/pre_tool_use_dispatcher_constants.py +8 -2
  47. package/hooks/hooks_constants/test_post_tool_use_dispatcher_constants.py +43 -0
  48. package/hooks/hooks_constants/test_pre_tool_use_dispatcher_constants.py +99 -0
  49. package/hooks/hooks_constants/test_text_stripping.py +39 -0
  50. package/hooks/hooks_constants/text_stripping.py +36 -0
  51. package/hooks/validation/CLAUDE.md +1 -0
  52. package/hooks/validation/post_tool_use_dispatcher.py +2 -2
  53. package/hooks/validation/test_mypy_validator.py +1 -1
  54. package/hooks/validation/test_post_tool_use_dispatcher.py +6 -0
  55. package/hooks/workflow/auto_formatter.py +8 -5
  56. package/hooks/workflow/test_auto_formatter.py +33 -0
  57. package/package.json +1 -1
  58. package/rules/claude-md-orphan-file.md +7 -8
  59. package/rules/docstring-prose-matches-implementation.md +1 -0
  60. package/rules/package-inventory-stale-entry.md +8 -0
  61. package/rules/windows-filesystem-safe.md +2 -0
  62. package/skills/anthropic-plan/CLAUDE.md +1 -1
  63. package/skills/anthropic-plan/SKILL.md +15 -2
  64. package/skills/autoconverge/SKILL.md +6 -3
  65. package/skills/autoconverge/reference/stop-conditions.md +7 -0
  66. package/skills/autoconverge/workflow/converge.clean-audit.test.mjs +5 -4
  67. package/skills/autoconverge/workflow/converge.contract.test.mjs +306 -137
  68. package/skills/autoconverge/workflow/converge.copilot-gate.test.mjs +16 -16
  69. package/skills/autoconverge/workflow/converge.fix-recovery.test.mjs +107 -44
  70. package/skills/autoconverge/workflow/converge.merge-conflict.test.mjs +16 -24
  71. package/skills/autoconverge/workflow/converge.mjs +581 -613
  72. package/skills/autoconverge/workflow/convergence_summary.py +1 -1
  73. package/skills/autoconverge/workflow/render_report.py +2 -6
  74. package/skills/autoconverge/workflow/test_convergence_summary.py +17 -0
  75. package/skills/autoconverge/workflow/test_render_report.py +1 -0
  76. package/skills/bugteam/scripts/bugteam_code_rules_gate.py +58 -4
  77. package/skills/bugteam/scripts/bugteam_scripts_constants/bugteam_code_rules_gate_constants.py +9 -0
  78. package/skills/bugteam/scripts/test_bugteam_code_rules_gate.py +42 -0
@@ -34,7 +34,7 @@ const HEADLESS_SAFETY_PREAMBLE =
34
34
  '- 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' +
35
35
  '- When a commit message, or a PR / issue / review-comment body, must describe destructive-command behavior, write that text to a file and pass it by path (git commit -F <file>, gh ... --body-file <file>); never inline it with git commit -m or gh ... -b, where the literal lands in the Bash command and stalls you.\n' +
36
36
  '- Keep scratch files and cleanup inside the OS temp dir; never target a repository or worktree path.\n' +
37
- '- rm shape rules — the hook grants several rm auto-allow paths. The simplest one accepts a standalone Bash call whose target resolves inside the ephemeral namespace (/tmp, /temp, the OS temp root, or the run worktree); a compound path accepts an rm joined with benign reporting segments when every rm target is an absolute ephemeral path. Both of those paths fail closed on $(...) command substitution, on backtick subshells, and on any $ in the target — including $CLAUDE_JOB_DIR so neither resolves an environment variable. A third, broad path matches only when the command itself declares an ephemeral working directory (it cds into one, or runs under one): that cwd-scoped path resolves the target against the declared cwd, fails closed on $(...) , backticks, and unknown variables, and resolves the known temporary variables TEMP, TMP, TMPDIR, and CLAUDE_JOB_DIR to the OS temp root, so under that declared ephemeral cwd a bare $CLAUDE_JOB_DIR/tmp/<name> target and a relative target after a cd are auto-allowed. Even so, prefer a Python helper for any cleanup whose path is variable-built or whose setup/teardown spans multiple steps: author the helper file and run it as python <file>.py, which keeps every destructive literal out of a Bash command string entirely and never depends on which auto-allow path matches.\n' +
37
+ '- rm shape rules — the hook grants several rm auto-allow paths. The simplest one accepts a standalone Bash call whose target resolves inside the ephemeral namespace (/tmp, /temp, the OS temp root, or the run worktree); a compound path accepts an rm joined with benign reporting segments when every rm target is an absolute ephemeral path. Both of those paths fail closed on $(...) command substitution and on backtick subshells. The compound path additionally fails closed on any $ in the target — including $CLAUDE_JOB_DIR. The standalone path declines a $-bearing target only when the literal path is not already under an ephemeral root, so it does not by itself stop a $VAR that expands inside an ephemeral root. A third, broad path matches only when the command itself declares an ephemeral working directory (it cds into one, or runs under one): that cwd-scoped path resolves the target against the declared cwd, fails closed on $(...) , backticks, and unknown variables, and resolves the known temporary variables TEMP, TMP, TMPDIR, and CLAUDE_JOB_DIR to the OS temp root, so under that declared ephemeral cwd a bare $CLAUDE_JOB_DIR/tmp/<name> target and a relative target after a cd are auto-allowed. Even so, prefer a Python helper for any cleanup whose path is variable-built or whose setup/teardown spans multiple steps: author the helper file and run it as python <file>.py, which keeps every destructive literal out of a Bash command string entirely and never depends on which auto-allow path matches.\n' +
38
38
  '- If a step appears to require a real destructive command, use a non-destructive equivalent or report it as a blocker instead of running it.\n\n'
39
39
 
40
40
  let activeRepoPath = null
@@ -69,8 +69,490 @@ const worktreeDirective = (repoPath) =>
69
69
  * @param {object} options the agent() options (label, phase, schema, agentType, model)
70
70
  * @returns {Promise<*>} the agent() result
71
71
  */
72
- const convergeAgent = (prompt, options) =>
73
- agent(`${HEADLESS_SAFETY_PREAMBLE}${worktreeDirective(activeRepoPath)}${prompt}`, options)
72
+ const convergeAgent = (prompt, options) => {
73
+ const isResume = typeof options?.resume === 'string' && options.resume.length > 0
74
+ const fullPrompt = isResume
75
+ ? prompt
76
+ : `${HEADLESS_SAFETY_PREAMBLE}${worktreeDirective(activeRepoPath)}${prompt}`
77
+ return agent(fullPrompt, options)
78
+ }
79
+
80
+ /**
81
+ * Spawn the git/utility Explore agent once before the converge loop.
82
+ * @returns {Promise<string>} the agent id
83
+ */
84
+ async function spawnGitAgent() {
85
+ const result = await convergeAgent(
86
+ `You are the git-utility agent for ${prCoordinates}. Your role is to resolve the PR HEAD SHA, fetch origin main, and check merge conflicts when asked. Do not edit code.\n\n` +
87
+ `Initial task: print the current HEAD SHA of ${prCoordinates}. Run exactly:\n` +
88
+ `gh api repos/${input.owner}/${input.repo}/pulls/${input.prNumber} --jq .head.sha\n` +
89
+ `Return the full 40-character SHA in the sha field.`,
90
+ { label: 'git-utility', phase: 'Converge', schema: HEAD_SCHEMA, agentType: 'Explore' },
91
+ )
92
+ return result?.agentId
93
+ }
94
+
95
+ /**
96
+ * Resume the git/utility agent for a specific task.
97
+ * @param {string} agentId the agent id from spawnGitAgent
98
+ * @param {string} task the short task name
99
+ * @param {string} head optional HEAD SHA for conflict checks
100
+ * @returns {Promise<object>} the structured output
101
+ */
102
+ function resumeGitAgent(agentId, task, head) {
103
+ if (task === 'resolve-head') {
104
+ return convergeAgent(
105
+ `Print the current HEAD SHA of ${prCoordinates}. Run exactly:\n` +
106
+ `gh api repos/${input.owner}/${input.repo}/pulls/${input.prNumber} --jq .head.sha\n` +
107
+ `Return the full 40-character SHA in the sha field. Do not modify any files.`,
108
+ { label: 'git-utility', phase: 'Converge', schema: HEAD_SCHEMA, agentType: 'Explore', resume: agentId },
109
+ )
110
+ }
111
+ if (task === 'prefetch-main') {
112
+ return convergeAgent(
113
+ `Refresh the base ref for ${prCoordinates} so the parallel review lenses can diff against an up-to-date origin/main without each running its own fetch. Run exactly:\n` +
114
+ `git fetch origin main\n` +
115
+ `Do not edit, commit, push, rebase, or modify any files — fetch only.`,
116
+ { label: 'git-utility', phase: 'Converge', agentType: 'Explore', resume: agentId },
117
+ )
118
+ }
119
+ return convergeAgent(
120
+ `Report whether ${prCoordinates} (HEAD ${head}) has merge conflicts with its base branch. Do not edit, commit, push, or rebase — read only.\n\n` +
121
+ `GitHub computes mergeability asynchronously, so .mergeable is null right after a push until it finishes. Poll until it resolves: run\n` +
122
+ ` gh api repos/${input.owner}/${input.repo}/pulls/${input.prNumber} --jq '{mergeable: .mergeable, state: .mergeable_state}'\n` +
123
+ `up to 5 times, 5 seconds apart (delay each retry with "sleep 5", or the PowerShell alternative "Start-Sleep -Seconds 5"), stopping as soon as mergeable is true or false.\n\n` +
124
+ `Return conflicting:true when mergeable is false or state is "dirty" (the branch conflicts with the base). Return conflicting:false when mergeable is true, or when mergeable stays null after the full poll budget — mergeability is unknown, so let the bug checks proceed rather than rebase on a guess.`,
125
+ { label: 'git-utility', phase: 'Converge', schema: MERGE_CONFLICT_SCHEMA, agentType: 'Explore', resume: agentId },
126
+ )
127
+ }
128
+
129
+ /**
130
+ * Spawn the fixer clean-coder agent for one fix batch, establishing its role and
131
+ * the PR coordinates so each later resume (commit and recovery edits) continues
132
+ * the same session. The fixer never verifies — a separate verifier agent grades
133
+ * the working tree, so the verdict comes from a different session than the one
134
+ * that commits and recovers, mirroring the repair and conflict paths. The spawn
135
+ * makes no edits — the first recovery resume is the earliest step that touches
136
+ * the working tree. Returns the runtime agent id so the resume calls target the
137
+ * live session; a runtime without resume support returns no agent id, and each
138
+ * resume falls back to a fresh spawn.
139
+ * @param {string} head PR HEAD SHA
140
+ * @param {Array<object>} findings the findings to fix
141
+ * @param {string} sourceLabel short description of where the findings came from
142
+ * @returns {Promise<string|undefined>} the runtime agent id, or undefined when the runtime returns none
143
+ */
144
+ async function spawnFixerAgent(head, findings, sourceLabel) {
145
+ const result = await convergeAgent(
146
+ `You are the fixer agent for ${findings.length} finding(s) (${sourceLabel}) on ${prCoordinates}, HEAD ${head}. The edit step left fixes in the working tree, uncommitted. Across this session you run a sequence of steps: commit and push the working-tree fixes once a separate verifier passes them, and recover when a verify objection or a commit-gate block needs another edit. A separate verifier agent grades the working tree, so you never verify your own edits. Make NO edits in this first turn — confirm only that the working tree is on the PR branch at HEAD ${head} with uncommitted fixes present, then wait for the next step's instructions. Reply READY.`,
147
+ { label: `fixer:${sourceLabel}`, phase: 'Converge', agentType: 'clean-coder' },
148
+ )
149
+ return result?.agentId
150
+ }
151
+
152
+ /**
153
+ * Resume the fixer agent for commit or recovery edits. The fixer never verifies;
154
+ * a separate verifier agent emits the verdict, so commit, verify-recover, and
155
+ * commit-recover all run on the editing session while the verdict that gates the
156
+ * commit comes from a different session.
157
+ * @param {string} agentId the agent id from spawnFixerAgent
158
+ * @param {string} task the short task name
159
+ * @param {object} context task-specific context
160
+ * @returns {Promise<object>} the structured output
161
+ */
162
+ function resumeFixerAgent(agentId, task, context) {
163
+ const label = `fixer:${context.sourceLabel}`
164
+ if (task === 'commit') {
165
+ return convergeAgent(
166
+ `You are the COMMIT step for fixes (${context.sourceLabel}) on ${prCoordinates}, HEAD ${context.head}. The edit step left fixes in the working tree and the verify step passed, so a verifier verdict already binds to this exact working tree.\n\n` +
167
+ `Rules:\n` +
168
+ `- Make NO further file edits of any kind. Any edit changes the surface and invalidates the verdict that unlocks the commit gate, so the commit would be blocked. Do not run a formatter, do not touch a test, do not re-fix anything — only commit and push what is already there.\n` +
169
+ `- Make ONE commit for all the working-tree fixes, then push to the PR branch.\n\n` +
170
+ `Return values:\n` +
171
+ `- 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` +
172
+ `- 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` +
173
+ `- 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.`,
174
+ { label, phase: 'Converge', schema: FIX_SCHEMA, agentType: 'clean-coder', resume: agentId },
175
+ )
176
+ }
177
+ if (task === 'commit-recover') {
178
+ const attempt = context.attempt || 1
179
+ return convergeAgent(
180
+ `You are the COMMIT-RECOVERY fixer (attempt ${attempt}) for fixes (${context.sourceLabel}) on ${prCoordinates}, HEAD ${context.head}. A prior commit step was blocked by a commit-time hook or gate that requires a code change. A separate verify step then a separate commit step run after you.\n\n` +
181
+ `The blocking hook or gate said:\n${context.blockerDetail}\n\n` +
182
+ `Rules:\n` +
183
+ `- Confirm the working tree is on the PR branch at HEAD ${context.head} with the prior fixes still present.\n` +
184
+ `- Fix ONLY the violation named above, test-first (failing test, then minimum code to pass) per CODE_RULES. Do not re-open the original findings, and do not touch GitHub review threads — the edit step already handled those.\n` +
185
+ `- 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` +
186
+ `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.` +
187
+ PRE_COMMIT_GATE_STEP,
188
+ { label, phase: 'Converge', schema: EDIT_SCHEMA, agentType: 'clean-coder', resume: agentId },
189
+ )
190
+ }
191
+ const objection = context.objection || VERIFY_OBJECTION_FALLBACK
192
+ const attempt = context.attempt || 1
193
+ return convergeAgent(
194
+ `You are the VERIFY-RECOVERY fixer (attempt ${attempt}) for fixes (${context.sourceLabel}) on ${prCoordinates}, HEAD ${context.head}. The verify step rejected the working-tree fixes; its verdict named what is still unresolved. A separate verify step then a separate commit step run after you.\n\n` +
195
+ `The verify step's objections:\n${objection}\n\n` +
196
+ `Rules:\n` +
197
+ `- Confirm the working tree is on the PR branch at HEAD ${context.head} with the prior fixes still present.\n` +
198
+ `- Address every objection above test-first (failing test, then minimum code to pass) per CODE_RULES, so each named concern is genuinely resolved the way the verdict requires. Do not touch GitHub review threads — the edit step already handled those.\n` +
199
+ `- 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` +
200
+ `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.` +
201
+ PRE_COMMIT_GATE_STEP,
202
+ { label, phase: 'Converge', schema: EDIT_SCHEMA, agentType: 'clean-coder', resume: agentId },
203
+ )
204
+ }
205
+
206
+ /**
207
+ * Joined fixer recovery loop: a separate verifier agent grades the working-tree
208
+ * fixes while the fixer session only recovers and commits, so the verdict that
209
+ * gates the commit comes from a different session than the one that edits and
210
+ * pushes — the same editor/verifier separation the repair and conflict paths
211
+ * use. The verify step routes through verifyWithRecovery (verify on the verifier,
212
+ * recover on the fixer); the commit step routes through commitWithRecovery
213
+ * (commit and commit-recover on the fixer, re-verify on the verifier). A failed
214
+ * verdict returns the unchanged HEAD so the round reads as not-progressed.
215
+ * @param {string} fixerAgentId the fixer agent id from spawnFixerAgent
216
+ * @param {string} verifierId the verifier agent id from spawnVerifierAgent
217
+ * @param {string} head PR HEAD SHA
218
+ * @param {Array<object>} findings the findings to fix
219
+ * @param {string} sourceLabel short description of where the findings came from
220
+ * @returns {Promise<object>} FIX_SCHEMA result
221
+ */
222
+ async function fixerWithRecovery(fixerAgentId, verifierId, head, findings, sourceLabel) {
223
+ const verifyTranscript = await verifyWithRecovery({
224
+ runVerify: () => resumeVerifierAgent(verifierId, 'fix-verify', { head, findings, sourceLabel }),
225
+ runRecoverEdit: (objection, attempt) => resumeFixerAgent(fixerAgentId, 'verify-recover', { head, findings, sourceLabel, objection, attempt }),
226
+ })
227
+ if (!verdictPassed(verifyTranscript)) {
228
+ return {
229
+ newSha: head,
230
+ pushed: false,
231
+ resolvedWithoutCommit: false,
232
+ summary: `verify step did not pass the working-tree fixes for ${findings.length} finding(s) — not committing`,
233
+ blockedNeedingEdit: false,
234
+ blockerDetail: '',
235
+ }
236
+ }
237
+ return commitWithRecovery({
238
+ runCommit: () => resumeFixerAgent(fixerAgentId, 'commit', { head, findings, sourceLabel }),
239
+ runVerify: () => resumeVerifierAgent(verifierId, 'fix-verify', { head, findings, sourceLabel }),
240
+ runRecoverEdit: (detail, attempt) => resumeFixerAgent(fixerAgentId, 'commit-recover', { head, findings, sourceLabel, blockerDetail: detail, attempt }),
241
+ })
242
+ }
243
+
244
+ /**
245
+ * Spawn the code-editor clean-coder agent once per converge round, establishing
246
+ * its role so each later resume (fix-edit, conflict-edit, repair-edit,
247
+ * repair-commit, standards-edit, hardening-commit, commit-recover, verify-recover)
248
+ * continues the same session. The spawn makes no edits — each resume carries the
249
+ * task-specific edit instructions. Returns the runtime agent id so the resume
250
+ * calls target the live session; a runtime without resume support returns no
251
+ * agent id, and each resume falls back to a fresh spawn.
252
+ * @returns {Promise<string|undefined>} the runtime agent id, or undefined when the runtime returns none
253
+ */
254
+ async function spawnCodeEditorAgent() {
255
+ const result = await convergeAgent(
256
+ `You are the code-editor agent for ${prCoordinates}. Across this converge round you run a sequence of edit and commit steps, each delivered as its own instruction. Make NO edits in this first turn — wait for the first task's instructions. Reply READY.`,
257
+ { label: 'code-editor', phase: 'Converge', agentType: 'clean-coder' },
258
+ )
259
+ return result?.agentId
260
+ }
261
+
262
+ /**
263
+ * Resume the code-editor agent for a specific edit task.
264
+ * @param {string} agentId the agent id from spawnCodeEditorAgent
265
+ * @param {string} task the short task name
266
+ * @param {object} context task-specific context
267
+ * @returns {Promise<object>} the structured output
268
+ */
269
+ function resumeCodeEditorAgent(agentId, task, context) {
270
+ const label = `code-editor:${task}`
271
+ if (task === 'fix-edit') {
272
+ const findingsBlock = renderFindingsBlock(context.findings)
273
+ const threadIds = context.findings
274
+ .flatMap((each) => collectFindingThreadIds(each))
275
+ .filter((each) => typeof each === 'number')
276
+ return convergeAgent(
277
+ `You are the EDIT step fixing ${context.findings.length} finding(s) (${context.sourceLabel}) on ${prCoordinates}, HEAD ${context.head}. A separate verify step then a separate commit step run after you.\n\n` +
278
+ `Findings:\n${findingsBlock}\n\n` +
279
+ `Rules:\n` +
280
+ `- Confirm the working tree is on the PR branch at HEAD ${context.head} with no unrelated edits before you start.\n` +
281
+ `- Fix every finding test-first (failing test, then minimum code to pass) per CODE_RULES. Verify each concern against current code; a finding whose concern no longer applies needs no code change but still needs its thread resolved.\n` +
282
+ `- Leave all fixes in the working tree. Do NOT commit and do NOT push — the commit step does that after verification. Committing or pushing here would change the surface the verifier binds to.\n` +
283
+ `- For each finding that carries a GitHub review comment id (${threadIds.length ? threadIds.join(', ') : 'none this batch'}): post an inline reply with python "${CONFIG.sharedScripts}/post_fix_reply.py" --owner ${input.owner} --repo ${input.repo} --pr-number ${input.prNumber} --in-reply-to <id> --body "<what changed>". Then resolve the PR review thread by thread node id (PRRT_...): look up the thread id for that comment via GraphQL (match on comment databaseId == <id> in the pull request's reviewThreads), then call the github MCP pull_request_review_write method=resolve_thread with threadId=<PRRT_...> (not the numeric comment id), or run the resolveReviewThread GraphQL mutation with the same threadId.\n` +
284
+ `- Findings with replyToCommentId null are in-memory audit findings: fix them, no reply needed.\n\n` +
285
+ `Return values:\n` +
286
+ `- When you edited code to fix at least one finding: edited=true, resolvedWithoutCommit=false.\n` +
287
+ `- 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` +
288
+ `Always include a one-line summary.` +
289
+ PRE_COMMIT_GATE_STEP,
290
+ { label, phase: 'Converge', schema: EDIT_SCHEMA, agentType: 'clean-coder', resume: agentId },
291
+ )
292
+ }
293
+ if (task === 'conflict-edit') {
294
+ return convergeAgent(
295
+ `You are the EDIT step resolving merge conflicts for ${prCoordinates}, HEAD ${context.head}, before the bug checks run. The PR branch conflicts with origin/main. A separate verify step then a separate commit step run after you.\n\n` +
296
+ `Rules:\n` +
297
+ `- Confirm the working tree is on the PR branch at HEAD ${context.head} with no unrelated edits before you start.\n` +
298
+ `- 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` +
299
+ `- 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` +
300
+ `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.`,
301
+ { label, phase: 'Converge', schema: CONFLICT_EDIT_SCHEMA, agentType: 'clean-coder', resume: agentId },
302
+ )
303
+ }
304
+ if (task === 'repair-edit') {
305
+ const failureBlock = context.failures.length
306
+ ? context.failures.map((each, position) => `${position + 1}. ${each}`).join('\n')
307
+ : 'none reported'
308
+ return convergeAgent(
309
+ `You are the EDIT step repairing the convergence gates that failed for ${prCoordinates} on HEAD ${context.head}. A separate verify step then a separate commit step run after you.\n\n` +
310
+ `Failing gates:\n${failureBlock}\n\n` +
311
+ `Address only the failing gates, and make NO commit and NO push — leave every code change in the working tree (a rebase necessarily creates local commits, which is fine; just do not push them):\n` +
312
+ `- Unresolved bot review threads: fetch the threads where isResolved is false (gh api graphql, or the github MCP pull_request_read get_review_comments), then keep only the bot-authored ones — a thread whose root comment author login contains "cursor", "claude", or "copilot" (case-insensitive substring). Explicitly skip every human reviewer thread; the convergence gate counts only unresolved bot threads, so touching a human thread is out of scope. For each bot thread, verify the concern against current code; if it still applies, fix it test-first in the working tree and leave the fix uncommitted; either way post an inline reply and resolve the thread by its PRRT_ node id (GraphQL lookup matching the comment databaseId, then resolveReviewThread or the github MCP pull_request_review_write method=resolve_thread — not the numeric comment id).\n` +
313
+ `- PR not mergeable: rebase onto origin/main FIRST, before applying any uncommitted bot-thread fix, so the rebase runs on a clean tree (git fetch origin main; git rebase origin/main; resolve conflicts). Do NOT force-push — the commit step does that after verification.\n` +
314
+ `- A dirty bot review or a still-pending requested reviewer: leave it; the next round re-runs that reviewer.\n\n` +
315
+ `Return values:\n` +
316
+ `- edited=true when you changed code in the working tree to fix a bot-thread concern.\n` +
317
+ `- rebased=true when you rebased the branch onto origin/main.\n` +
318
+ `- 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` +
319
+ `Always include a one-line summary.` +
320
+ PRE_COMMIT_GATE_STEP,
321
+ { label, phase: 'Finalize', schema: REPAIR_EDIT_SCHEMA, agentType: 'clean-coder', resume: agentId },
322
+ )
323
+ }
324
+ if (task === 'repair-commit') {
325
+ const pushInstruction = context.wasRebased
326
+ ? 'The edit step rebased the branch, so push with git push --force-with-lease.'
327
+ : 'Push to the PR branch with a plain git push.'
328
+ return convergeAgent(
329
+ `You are the COMMIT step for the convergence repair on ${prCoordinates}, HEAD ${context.head}. The edit step left its repair in the working tree and the verify step passed, so a verifier verdict already binds to this exact working tree.\n\n` +
330
+ `Rules:\n` +
331
+ `- Make NO further file edits of any kind. Any edit changes the surface and invalidates the verdict that unlocks the commit gate, so the push would be blocked. Do not run a formatter, do not re-fix anything — only commit and push what is already there.\n` +
332
+ `- Commit any uncommitted bot-thread fix in ONE commit (skip the commit when the working tree carries only already-committed rebase results). ${pushInstruction}\n\n` +
333
+ `Return values:\n` +
334
+ `- 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` +
335
+ `- 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` +
336
+ `- 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.`,
337
+ { label, phase: 'Finalize', schema: FIX_SCHEMA, agentType: 'clean-coder', resume: agentId },
338
+ )
339
+ }
340
+ if (task === 'standards-edit') {
341
+ const findingsBlock = renderFindingsBlock(context.findings)
342
+ const threadIds = context.findings
343
+ .flatMap((each) => collectFindingThreadIds(each))
344
+ .filter((each) => typeof each === 'number')
345
+ return convergeAgent(
346
+ `You are the EDIT step deferring a code-standard-only round on ${prCoordinates}, HEAD ${context.head} (${context.sourceLabel}). The round surfaced ONLY code-standard violations (CODE_RULES/style, no behavioral impact); the run treats it as passed and defers the fixes to follow-up work, which you now stage. A separate verify step then a separate commit step open the hardening PR after you. Do NOT commit or push to the PR's own branch.\n\n` +
347
+ `Findings:\n${findingsBlock}\n\n` +
348
+ `1. Follow-up fix issue: file a GitHub issue on ${input.owner}/${input.repo} (gh issue create --body-file with a temp file) titled "Deferred code-standard fixes from PR #${input.prNumber}". The body references the PR and lists each finding with its file:line, severity, and detail. The issue carries the fix work; do not open a fix PR. Capture the issue URL.\n` +
349
+ `2. Stage the environment-hardening change: in the Claude environment config repo (the repo owning ~/.claude hooks and rules — JonEcho/llm-settings for hooks, jl-cmd/claude-code-config for rules/skills; pick whichever owns the surface that would block these violation classes), find or clone a local checkout, fetch origin, and create a branch off origin/main. Edit the hooks/rules in that checkout's WORKING TREE so each violation class found here is blocked at Write/Edit time, before code is written. Do NOT commit and do NOT push — the commit step does that after the verify step binds a verdict to the working tree. Return the checkout's absolute path in hardeningRepoPath, the branch name in hardeningBranch, and set hardeningEdited=true. When no hardening is feasible for these classes, leave hardeningRepoPath and hardeningBranch empty and hardeningEdited=false; the follow-up issue still stands.\n` +
350
+ `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` +
351
+ `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.` +
352
+ PRE_COMMIT_GATE_STEP,
353
+ { label, phase: 'Converge', schema: STANDARDS_EDIT_SCHEMA, agentType: 'clean-coder', resume: agentId },
354
+ )
355
+ }
356
+ if (task === 'hardening-commit') {
357
+ return convergeAgent(
358
+ `You are the COMMIT step opening the environment-hardening PR (${context.sourceLabel}) for the change staged in ${context.hardeningRepoPath} on branch ${context.hardeningBranch}. The edit step left the hooks/rules edits in the working tree and the verify step passed, so a verifier verdict already binds to this exact working tree. Do NOT touch the PR's own branch.\n\n` +
359
+ `Rules:\n` +
360
+ `- Make NO further file edits of any kind. Any edit changes the surface and invalidates the verdict that unlocks the commit gate, so the push would be blocked. Only commit and push what is already there.\n` +
361
+ `- 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\n` +
362
+ `Return a one-line summary naming the hardening PR URL.`,
363
+ { label, phase: 'Converge', agentType: 'clean-coder', resume: agentId },
364
+ )
365
+ }
366
+ if (task === 'commit-recover') {
367
+ const attempt = context.attempt || 1
368
+ return convergeAgent(
369
+ `You are the COMMIT-RECOVERY fixer (attempt ${attempt}) for fixes (${context.sourceLabel}) on ${prCoordinates}, HEAD ${context.head}. A prior commit step was blocked by a commit-time hook or gate that requires a code change. A separate verify step then a separate commit step run after you.\n\n` +
370
+ `The blocking hook or gate said:\n${context.blockerDetail}\n\n` +
371
+ `Rules:\n` +
372
+ `- Confirm the working tree is on the PR branch at HEAD ${context.head} with the prior fixes still present.\n` +
373
+ `- Fix ONLY the violation named above, test-first (failing test, then minimum code to pass) per CODE_RULES. Do not re-open the original findings, and do not touch GitHub review threads — the edit step already handled those.\n` +
374
+ `- 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` +
375
+ `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.` +
376
+ PRE_COMMIT_GATE_STEP,
377
+ { label, phase: 'Converge', schema: EDIT_SCHEMA, agentType: 'clean-coder', resume: agentId },
378
+ )
379
+ }
380
+ // verify-recover
381
+ const attempt = context.attempt || 1
382
+ const objection = context.objection || VERIFY_OBJECTION_FALLBACK
383
+ return convergeAgent(
384
+ `You are the VERIFY-RECOVERY fixer (attempt ${attempt}) for fixes (${context.sourceLabel}) on ${prCoordinates}, HEAD ${context.head}. The verify step rejected the working-tree fixes; its verdict named what is still unresolved. A separate verify step then a separate commit step run after you.\n\n` +
385
+ `The verify step's objections:\n${objection}\n\n` +
386
+ `Rules:\n` +
387
+ `- Confirm the working tree is on the PR branch at HEAD ${context.head} with the prior fixes still present.\n` +
388
+ `- Address every objection above test-first (failing test, then minimum code to pass) per CODE_RULES, so each named concern is genuinely resolved the way the verdict requires. Do not touch GitHub review threads — the edit step already handled those.\n` +
389
+ `- 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` +
390
+ `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.` +
391
+ PRE_COMMIT_GATE_STEP,
392
+ { label, phase: 'Converge', schema: EDIT_SCHEMA, agentType: 'clean-coder', resume: agentId },
393
+ )
394
+ }
395
+
396
+ /**
397
+ * Spawn the verifier code-verifier agent once per converge round, establishing
398
+ * its role so each later resume (fix-verify, repair-verify, hardening-verify) continues the
399
+ * same session. The spawn makes no edits — verification only. Returns the runtime
400
+ * agent id so the resume calls target the live session; a runtime without resume
401
+ * support returns no agent id, and each resume falls back to a fresh spawn.
402
+ * @returns {Promise<string|undefined>} the runtime agent id, or undefined when the runtime returns none
403
+ */
404
+ async function spawnVerifierAgent() {
405
+ const result = await convergeAgent(
406
+ `You are the verifier agent for ${prCoordinates}. Across this converge round you run a sequence of verify steps, each delivered as its own instruction; each ends with a fenced verdict block. Do NO edits of any kind — verification only. Make no move in this first turn — wait for the first verify task's instructions. Reply READY.`,
407
+ { label: 'verifier', phase: 'Converge', agentType: 'code-verifier' },
408
+ )
409
+ return result?.agentId
410
+ }
411
+
412
+ /**
413
+ * Resume the verifier agent for a specific verify task.
414
+ * @param {string} agentId the agent id from spawnVerifierAgent
415
+ * @param {string} task the short task name
416
+ * @param {object} context task-specific context
417
+ * @returns {Promise<string>} the verifier transcript carrying the verdict fence
418
+ */
419
+ function resumeVerifierAgent(agentId, task, context) {
420
+ const label = `verifier:${task}`
421
+ if (task === 'fix-verify') {
422
+ const findingsBlock = renderFindingsBlock(context.findings)
423
+ return convergeAgent(
424
+ `You are the VERIFY step for ${context.findings.length} finding(s) (${context.sourceLabel}) on ${prCoordinates}, HEAD ${context.head}. The edit step left fixes in the working tree, uncommitted. Do NO edits of any kind — verification only; any edit invalidates the verdict you are about to emit.\n\n` +
425
+ `Findings the working-tree fixes must address:\n${findingsBlock}\n\n` +
426
+ `Steps:\n` +
427
+ `1. Resolve the worktree repo root for running tests: REPO=$(git rev-parse --show-toplevel).\n` +
428
+ `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` +
429
+ `3. ${buildVerdictFenceSteps(input.owner, input.repo, input.prNumber)}`,
430
+ { label, phase: 'Converge', agentType: 'code-verifier', resume: agentId },
431
+ )
432
+ }
433
+ if (task === 'repair-verify') {
434
+ const failureBlock = context.failures.length
435
+ ? context.failures.map((each, position) => `${position + 1}. ${each}`).join('\n')
436
+ : 'none reported'
437
+ return convergeAgent(
438
+ `You are the VERIFY step for the convergence repair on ${prCoordinates}, HEAD ${context.head}. The edit step left its repair in the working tree (a bot-thread fix uncommitted, and/or a rebase onto origin/main), unpushed. Do NO edits of any kind — verification only; any edit invalidates the verdict you are about to emit.\n\n` +
439
+ `Concerns the working-tree repair must resolve (the gates the convergence check flagged):\n${failureBlock}\n\n` +
440
+ `Steps:\n` +
441
+ `1. Resolve the worktree repo root for running tests: REPO=$(git rev-parse --show-toplevel).\n` +
442
+ `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` +
443
+ `3. ${buildVerdictFenceSteps(input.owner, input.repo, input.prNumber)}`,
444
+ { label, phase: 'Finalize', agentType: 'code-verifier', resume: agentId },
445
+ )
446
+ }
447
+ return convergeAgent(
448
+ `You are the VERIFY step for an environment-hardening change (${context.sourceLabel}) staged in the working tree of ${context.hardeningRepoPath}. The edit step left the hooks/rules edits uncommitted there. Do NO edits of any kind — verification only; any edit invalidates the verdict you are about to emit.\n\n` +
449
+ `Concern the working-tree change must resolve: the edited hooks/rules block the code-standard violation classes from the deferred round at Write/Edit time, and a hook change carries a passing test per CODE_RULES.\n\n` +
450
+ `Steps:\n` +
451
+ `1. cd into ${context.hardeningRepoPath}, then resolve its repo root: REPO=$(git rev-parse --show-toplevel).\n` +
452
+ `2. Verify the uncommitted working-tree change in REPO: read the diff (git diff) and run the hook/rule tests in that repo, confirming each violation class is now blocked.\n` +
453
+ `3. Compute the binding hash for the live surface:\n` +
454
+ ` The hardening branch is: ${context.hardeningBranch}\n` +
455
+ ` Run exactly:\n` +
456
+ ` "C:\\Python313\\python.exe" "<REPO>/packages/claude-dev-env/hooks/blocking/verification_verdict_store.py" --manifest-hash-for-branch "${context.hardeningBranch}"\n` +
457
+ ` (substitute the REPO path you resolved for the script path). That prints a single 64-char hex hash on stdout — capture it.\n` +
458
+ ` Then END your message with a fenced verdict block exactly in this shape, on its own, carrying that hash:\n` +
459
+ " ```verdict\n" +
460
+ ` {"all_pass": true, "findings": [], "manifest_sha256": "<that hash>"}\n` +
461
+ " ```\n" +
462
+ ` 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.`,
463
+ { label, phase: 'Converge', agentType: 'code-verifier', resume: agentId },
464
+ )
465
+ }
466
+
467
+ /**
468
+ * Spawn the general-utility general-purpose agent once per converge round,
469
+ * establishing its role so each later resume (post-clean-audit, mark-ready)
470
+ * continues the same session. The spawn edits no code.
471
+ * Returns the runtime agent id so the resume calls target the live session; a
472
+ * runtime without resume support returns no agent id, and each resume falls back
473
+ * to a fresh spawn.
474
+ * @returns {Promise<string|undefined>} the runtime agent id, or undefined when the runtime returns none
475
+ */
476
+ async function spawnGeneralUtilityAgent() {
477
+ const result = await convergeAgent(
478
+ `You are the general-utility agent for ${prCoordinates}. Across this converge round you run a sequence of administrative steps (posting the clean audit, marking the PR ready), each delivered as its own instruction. Do not edit code, commit, or push. Make no move in this first turn — wait for the first task's instructions. Reply READY.`,
479
+ { label: 'general-utility', phase: 'Converge', agentType: 'general-purpose' },
480
+ )
481
+ return result?.agentId
482
+ }
483
+
484
+ /**
485
+ * Resume the general-utility agent for one of its two administrative tasks:
486
+ * 'post-clean-audit' posts the terminal CLEAN bugteam review, and 'mark-ready'
487
+ * marks the PR ready and confirms it left draft state.
488
+ * @param {string} agentId the agent id from spawnGeneralUtilityAgent
489
+ * @param {'post-clean-audit'|'mark-ready'} task the short task name
490
+ * @param {object} context task-specific context
491
+ * @returns {Promise<object>} the task result
492
+ */
493
+ function resumeGeneralUtilityAgent(agentId, task, context) {
494
+ const label = `general-utility:${task}`
495
+ if (task === 'post-clean-audit') {
496
+ return convergeAgent(
497
+ `Post a CLEAN bugteam audit review on ${prCoordinates} at commit ${context.head}. All review lenses are clean on this HEAD.\n\n` +
498
+ `Write an empty findings file: create a temp file containing exactly [] (an empty JSON array). Then run:\n` +
499
+ `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` +
500
+ `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` +
501
+ `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.`,
502
+ { label, phase: 'Converge', schema: CLEAN_AUDIT_SCHEMA, agentType: 'general-purpose', resume: agentId },
503
+ )
504
+ }
505
+ if (task === 'mark-ready') {
506
+ const copilotOptOut = context.copilotDown
507
+ ? `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`
508
+ : ''
509
+ return convergeAgent(
510
+ `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` +
511
+ copilotOptOut +
512
+ `1. Run: gh pr ready ${input.prNumber} --repo ${input.owner}/${input.repo}\n` +
513
+ `2. Re-query the draft state: gh api repos/${input.owner}/${input.repo}/pulls/${input.prNumber} --jq .draft\n` +
514
+ `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}.`,
515
+ { label, phase: 'Finalize', schema: READY_SCHEMA, agentType: 'general-purpose', resume: agentId },
516
+ )
517
+ }
518
+ throw new Error(`resumeGeneralUtilityAgent: unknown task ${task}`)
519
+ }
520
+
521
+ /**
522
+ * Spawn the convergence-check Explore agent once before the converge loop,
523
+ * establishing its role so each per-round resume runs the convergence gate in the
524
+ * same session. The spawn edits no code. Returns the runtime agent id so the
525
+ * resume calls target the live session; a runtime without resume support returns
526
+ * no agent id, and each resume falls back to a fresh spawn.
527
+ * @returns {Promise<string|undefined>} the runtime agent id, or undefined when the runtime returns none
528
+ */
529
+ async function spawnConvergenceCheckAgent() {
530
+ const result = await convergeAgent(
531
+ `You are the convergence-check agent for ${prCoordinates}. Each round you run the authoritative convergence gate and report its result, delivered as its own instruction. Do not edit code. Make no move in this first turn — wait for the first check instruction. Reply READY.`,
532
+ { label: 'convergence-check', phase: 'Converge', agentType: 'Explore' },
533
+ )
534
+ return result?.agentId
535
+ }
536
+
537
+ /**
538
+ * Resume the convergence-check agent for the convergence check.
539
+ * @param {string} agentId the agent id from spawnConvergenceCheckAgent
540
+ * @param {object} context carries bugbotDown and copilotDown
541
+ * @returns {Promise<object>} CONVERGENCE_SCHEMA result
542
+ */
543
+ function resumeConvergenceCheckAgent(agentId, context) {
544
+ const label = 'check-convergence'
545
+ const bugbotDownFlag = context.bugbotDown ? ' --bugbot-down' : ''
546
+ const copilotDownFlag = context.copilotDown ? ' --copilot-down' : ''
547
+ return convergeAgent(
548
+ `Run the convergence gate for ${prCoordinates} and report the result. Do not edit code.\n\n` +
549
+ `Run: python "${CONFIG.sharedScripts}/check_convergence.py" --owner ${input.owner} --repo ${input.repo} --pr-number ${input.prNumber}${bugbotDownFlag}${copilotDownFlag}\n\n` +
550
+ `Exit 0 -> every gate passed: return {pass:true, failures:[]}.\n` +
551
+ `Exit 1 -> return {pass:false, failures:[<each printed FAIL line verbatim>]}.\n` +
552
+ `Exit 2 -> retry once; if it still errors, return {pass:false, failures:["check_convergence gh error"]}.`,
553
+ { label, phase: 'Finalize', schema: CONVERGENCE_SCHEMA, agentType: 'Explore', resume: agentId },
554
+ )
555
+ }
74
556
 
75
557
  const PRE_COMMIT_GATE_STEP =
76
558
  `\n\nFINAL STEP — pre-commit gate check (do NOT commit): before your turn ends, prove your working-tree changes CAN be committed by dry-running the CODE_RULES commit gate that gates git commit (precommit_code_rules_gate). From inside the checkout that holds your changes, resolve its root with git rev-parse --show-toplevel, stage your changes with git add -A, then run exactly:\n` +
@@ -224,31 +706,6 @@ function buildVerdictFenceSteps(prOwner, prRepo, prNumber) {
224
706
  )
225
707
  }
226
708
 
227
- const CONVERGENCE_SUMMARY_SCHEMA = {
228
- type: 'object',
229
- additionalProperties: false,
230
- properties: {
231
- verdictLine: { type: 'string', description: 'one factual BLUF sentence: converged?, distinct issue-class count, all fixed or deferred. No hedging words.' },
232
- issueClasses: {
233
- type: 'array',
234
- items: {
235
- type: 'object',
236
- additionalProperties: false,
237
- properties: {
238
- plainName: { type: 'string', description: 'everyday-language name of the issue class — no tool tokens, rule ids, file paths, line numbers, severity codes (P0/P1/P2), or bot names' },
239
- count: { type: 'integer', description: 'number of raw findings grouped into this class' },
240
- severity: { type: 'string', enum: ['P0', 'P1', 'P2'], description: 'most severe among the class' },
241
- category: { type: 'string', enum: ['bug', 'code-standard'] },
242
- status: { type: 'string', enum: ['fixed', 'deferred'] },
243
- whatItWas: { type: 'string', description: 'at most 2 sentences, plain language, what the problem was' },
244
- },
245
- required: ['plainName', 'count', 'severity', 'category', 'status', 'whatItWas'],
246
- },
247
- },
248
- },
249
- required: ['verdictLine', 'issueClasses'],
250
- }
251
-
252
709
  const CONVERGENCE_SCHEMA = {
253
710
  type: 'object',
254
711
  additionalProperties: false,
@@ -433,32 +890,40 @@ function normalizeShaForComparison(sha) {
433
890
  }
434
891
 
435
892
  /**
436
- * Decide whether a workflow code-verifier transcript ended in a passing
437
- * verdict. The verify step runs with no schema so its verdict lands as plain
438
- * assistant text; this reads the LAST ```verdict ...``` fenced JSON block and
439
- * returns true only when it parses to an object with all_pass true. A missing
440
- * fence, a parse failure, or all_pass false reads as not-passed so the commit
441
- * step is skipped and the round reads as not-progressed.
442
- * @param {string|null|undefined} verifyTranscript the verifier's transcript text
443
- * @returns {boolean} true only when the last verdict fence reports all_pass true
893
+ * Parse the LAST ```verdict ...``` fenced JSON block from a transcript.
894
+ * Guards against non-string input, iterates all fence matches for the last one,
895
+ * parses the JSON, and returns the object or null on any failure.
896
+ * @param {string|null|undefined} transcript the agent transcript text
897
+ * @returns {object|null} the parsed verdict object, or null when absent or malformed
444
898
  */
445
- function verdictPassed(verifyTranscript) {
446
- if (typeof verifyTranscript !== 'string') return false
899
+ function parseLastVerdictFence(transcript) {
900
+ if (typeof transcript !== 'string') return null
447
901
  const fencePattern = /```verdict\s*\n([\s\S]*?)```/g
448
902
  let lastFenceBody = null
449
903
  let eachMatch
450
- while ((eachMatch = fencePattern.exec(verifyTranscript)) !== null) {
904
+ while ((eachMatch = fencePattern.exec(transcript)) !== null) {
451
905
  lastFenceBody = eachMatch[1]
452
906
  }
453
- if (lastFenceBody === null) return false
907
+ if (lastFenceBody === null) return null
454
908
  try {
455
- const verdictRecord = JSON.parse(lastFenceBody)
456
- return verdictRecord != null && verdictRecord.all_pass === true
909
+ return JSON.parse(lastFenceBody)
457
910
  } catch {
458
- return false
911
+ return null
459
912
  }
460
913
  }
461
914
 
915
+ /**
916
+ * Decide whether a workflow code-verifier transcript ended in a passing
917
+ * verdict. Reads the LAST ```verdict ...``` fenced JSON block via the shared
918
+ * parser and returns true only when it parses to an object with all_pass true.
919
+ * @param {string|null|undefined} verifyTranscript the verifier's transcript text
920
+ * @returns {boolean} true only when the last verdict fence reports all_pass true
921
+ */
922
+ function verdictPassed(verifyTranscript) {
923
+ const verdictRecord = parseLastVerdictFence(verifyTranscript)
924
+ return verdictRecord != null && verdictRecord.all_pass === true
925
+ }
926
+
462
927
  const VERIFY_OBJECTION_FALLBACK = 'The verify step rejected the working-tree fixes without a parseable verdict; re-read the fix-verify transcript above and address every concern it raised.'
463
928
 
464
929
  /**
@@ -500,25 +965,14 @@ function renderVerifyObjectionLine(eachFinding) {
500
965
  * @returns {string} a human-readable block of the verifier's objections
501
966
  */
502
967
  function extractVerifyObjection(verifyTranscript) {
503
- if (typeof verifyTranscript !== 'string') return VERIFY_OBJECTION_FALLBACK
504
- const fencePattern = /```verdict\s*\n([\s\S]*?)```/g
505
- let lastFenceBody = null
506
- let eachMatch
507
- while ((eachMatch = fencePattern.exec(verifyTranscript)) !== null) {
508
- lastFenceBody = eachMatch[1]
509
- }
510
- if (lastFenceBody === null) return VERIFY_OBJECTION_FALLBACK
511
- try {
512
- const verdictRecord = JSON.parse(lastFenceBody)
513
- const allObjections = Array.isArray(verdictRecord?.findings) ? verdictRecord.findings : []
514
- const renderedObjections = allObjections
515
- .map((eachFinding) => renderVerifyObjectionLine(eachFinding))
516
- .filter((eachLine) => eachLine !== null)
517
- if (renderedObjections.length === 0) return VERIFY_OBJECTION_FALLBACK
518
- return renderedObjections.map((eachLine, position) => `${position + 1}. ${eachLine}`).join('\n')
519
- } catch {
520
- return VERIFY_OBJECTION_FALLBACK
521
- }
968
+ const verdictRecord = parseLastVerdictFence(verifyTranscript)
969
+ if (verdictRecord == null) return VERIFY_OBJECTION_FALLBACK
970
+ const allObjections = Array.isArray(verdictRecord?.findings) ? verdictRecord.findings : []
971
+ const renderedObjections = allObjections
972
+ .map((eachFinding) => renderVerifyObjectionLine(eachFinding))
973
+ .filter((eachLine) => eachLine !== null)
974
+ if (renderedObjections.length === 0) return VERIFY_OBJECTION_FALLBACK
975
+ return renderedObjections.map((eachLine, position) => `${position + 1}. ${eachLine}`).join('\n')
522
976
  }
523
977
 
524
978
  /**
@@ -575,7 +1029,7 @@ function commitNeedsCodeRecovery(commitResult) {
575
1029
  * resolve-head agent or a malformed result yields a falsy SHA; spawning lenses
576
1030
  * against it interpolates the literal string 'HEAD undefined' into their prompts
577
1031
  * and produces a spurious clean verdict on a non-existent commit.
578
- * @param {string|null|undefined} resolvedHead the SHA from resolveHead()
1032
+ * @param {string|null|undefined} resolvedHead the SHA from the git-utility agent resume for 'resolve-head'
579
1033
  * @returns {boolean} true only when the SHA is a non-empty string
580
1034
  */
581
1035
  function isResolvedHeadUsable(resolvedHead) {
@@ -588,7 +1042,7 @@ function isResolvedHeadUsable(resolvedHead) {
588
1042
  * not-conflicting so the run proceeds straight to the bug checks rather than
589
1043
  * force-pushing a rebase on a verdict that does not exist — a transient check
590
1044
  * failure must never trigger a destructive rebase.
591
- * @param {object|null|undefined} mergeState the checkMergeConflicts result
1045
+ * @param {object|null|undefined} mergeState the git-utility agent resume result for 'check-merge-conflicts'
592
1046
  * @returns {boolean} true only when the check reported conflicting:true
593
1047
  */
594
1048
  function isMergeConflicting(mergeState) {
@@ -724,37 +1178,6 @@ const input = runInput.input
724
1178
  activeRepoPath = typeof input.repoPath === 'string' && input.repoPath ? input.repoPath : null
725
1179
  const prCoordinates = `owner=${input.owner} repo=${input.repo} PR #${input.prNumber} (https://github.com/${input.owner}/${input.repo}/pull/${input.prNumber})`
726
1180
 
727
- /**
728
- * Resolve the current PR HEAD SHA from GitHub.
729
- * @returns {Promise<string>} the 40-char HEAD SHA
730
- */
731
- async function resolveHead() {
732
- const head = await convergeAgent(
733
- `Print the current HEAD SHA of ${prCoordinates}. Run exactly:\n` +
734
- `gh api repos/${input.owner}/${input.repo}/pulls/${input.prNumber} --jq .head.sha\n` +
735
- `Return the full 40-character SHA in the sha field. Do not modify any files.`,
736
- { label: 'resolve-head', phase: 'Converge', schema: HEAD_SCHEMA, agentType: 'Explore' },
737
- )
738
- return head?.sha
739
- }
740
-
741
- /**
742
- * Fetch origin/main once per round before the parallel lenses spawn. The
743
- * code-review and bug-audit lenses both diff against origin/main; running their
744
- * own git fetch in parallel contends on the worktree .git lock and fails
745
- * intermittently, so a single serial fetch here keeps the ref current and the
746
- * parallel lenses do no git fetch of their own.
747
- * @returns {Promise<string>} agent transcript (unused)
748
- */
749
- function prefetchMainForRound() {
750
- return convergeAgent(
751
- `Refresh the base ref for ${prCoordinates} so the parallel review lenses can diff against an up-to-date origin/main without each running its own fetch. Run exactly:\n` +
752
- `git fetch origin main\n` +
753
- `Do not edit, commit, push, rebase, or modify any files — fetch only.`,
754
- { label: 'prefetch-main', phase: 'Converge', agentType: 'Explore' },
755
- )
756
- }
757
-
758
1181
  /**
759
1182
  * Bugbot lens: ensure Cursor Bugbot has rendered a verdict on the given HEAD,
760
1183
  * triggering and polling its CI check run when needed, and return its findings.
@@ -856,139 +1279,6 @@ function renderFindingsBlock(findings) {
856
1279
  .join('\n')
857
1280
  }
858
1281
 
859
- /**
860
- * Edit step: one clean-coder fixes every finding test-first in the working
861
- * tree and resolves the GitHub review threads, making NO commit or push so the
862
- * verify step can bind a verdict to the unstaged fixes.
863
- * @param {string} head PR HEAD SHA the findings were raised against
864
- * @param {Array<object>} findings deduped findings across all lenses
865
- * @param {string} sourceLabel short description of where the findings came from
866
- * @returns {Promise<object>} EDIT_SCHEMA result
867
- */
868
- function applyFixesEdit(head, findings, sourceLabel) {
869
- const findingsBlock = renderFindingsBlock(findings)
870
- const threadIds = findings
871
- .flatMap((each) => collectFindingThreadIds(each))
872
- .filter((each) => typeof each === 'number')
873
- return convergeAgent(
874
- `You are the EDIT step fixing ${findings.length} finding(s) (${sourceLabel}) on ${prCoordinates}, HEAD ${head}. A separate verify step then a separate commit step run after you.\n\n` +
875
- `Findings:\n${findingsBlock}\n\n` +
876
- `Rules:\n` +
877
- `- Confirm the working tree is on the PR branch at HEAD ${head} with no unrelated edits before you start.\n` +
878
- `- Fix every finding test-first (failing test, then minimum code to pass) per CODE_RULES. Verify each concern against current code; a finding whose concern no longer applies needs no code change but still needs its thread resolved.\n` +
879
- `- Leave all fixes in the working tree. Do NOT commit and do NOT push — the commit step does that after verification. Committing or pushing here would change the surface the verifier binds to.\n` +
880
- `- For each finding that carries a GitHub review comment id (${threadIds.length ? threadIds.join(', ') : 'none this batch'}): post an inline reply with python "${CONFIG.sharedScripts}/post_fix_reply.py" --owner ${input.owner} --repo ${input.repo} --pr-number ${input.prNumber} --in-reply-to <id> --body "<what changed>". Then resolve the PR review thread by thread node id (PRRT_...): look up the thread id for that comment via GraphQL (match on comment databaseId == <id> in the pull request's reviewThreads), then call the github MCP pull_request_review_write method=resolve_thread with threadId=<PRRT_...> (not the numeric comment id), or run the resolveReviewThread GraphQL mutation with the same threadId.\n` +
881
- `- Findings with replyToCommentId null are in-memory audit findings: fix them, no reply needed.\n\n` +
882
- `Return values:\n` +
883
- `- When you edited code to fix at least one finding: edited=true, resolvedWithoutCommit=false.\n` +
884
- `- 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` +
885
- `Always include a one-line summary.` +
886
- PRE_COMMIT_GATE_STEP,
887
- { label: `fix-edit:${sourceLabel}`, phase: 'Converge', schema: EDIT_SCHEMA, agentType: 'clean-coder' },
888
- )
889
- }
890
-
891
- /**
892
- * Verify step: a code-verifier checks the working-tree fixes against the
893
- * findings, computes the binding surface hash, and ends with a verdict fence
894
- * as plain assistant text (NO schema, so the fence is not consumed as
895
- * structured output). The fence's manifest_sha256 is what unlocks the
896
- * verified-commit gate for the commit step. The verifier makes no edits.
897
- * @param {string} head PR HEAD SHA the findings were raised against
898
- * @param {Array<object>} findings deduped findings the fixes must address
899
- * @param {string} sourceLabel short description of where the findings came from
900
- * @returns {Promise<string>} the verifier transcript carrying the verdict fence
901
- */
902
- function verifyFixesInWorkingTree(head, findings, sourceLabel) {
903
- const findingsBlock = renderFindingsBlock(findings)
904
- return convergeAgent(
905
- `You are the VERIFY step for ${findings.length} finding(s) (${sourceLabel}) on ${prCoordinates}, HEAD ${head}. The edit step left fixes in the working tree, uncommitted. Do NO edits of any kind — verification only; any edit invalidates the verdict you are about to emit.\n\n` +
906
- `Findings the working-tree fixes must address:\n${findingsBlock}\n\n` +
907
- `Steps:\n` +
908
- `1. Resolve the worktree repo root for running tests: REPO=$(git rev-parse --show-toplevel).\n` +
909
- `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` +
910
- `3. ${buildVerdictFenceSteps(input.owner, input.repo, input.prNumber)}`,
911
- { label: `fix-verify:${sourceLabel}`, phase: 'Converge', agentType: 'code-verifier' },
912
- )
913
- }
914
-
915
- /**
916
- * Commit step: one clean-coder commits the already-verified working-tree fixes
917
- * in a single commit and pushes to the PR branch, making NO further file edits
918
- * — any edit changes the surface and invalidates the verifier verdict that
919
- * unlocks the commit gate.
920
- * @param {string} head PR HEAD SHA before the fix commit
921
- * @param {string} sourceLabel short description of where the findings came from
922
- * @returns {Promise<object>} FIX_SCHEMA result
923
- */
924
- function commitVerifiedFixes(head, sourceLabel) {
925
- return convergeAgent(
926
- `You are the COMMIT step for fixes (${sourceLabel}) on ${prCoordinates}, HEAD ${head}. The edit step left fixes in the working tree and the verify step passed, so a verifier verdict already binds to this exact working tree.\n\n` +
927
- `Rules:\n` +
928
- `- Make NO further file edits of any kind. Any edit changes the surface and invalidates the verdict that unlocks the commit gate, so the commit would be blocked. Do not run a formatter, do not touch a test, do not re-fix anything — only commit and push what is already there.\n` +
929
- `- Make ONE commit for all the working-tree fixes, then push to the PR branch.\n\n` +
930
- `Return values:\n` +
931
- `- 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` +
932
- `- 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=${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` +
933
- `- On a transient or non-code failure (auth, network, a non-fast-forward, a lock): newSha=${head}, pushed=false, resolvedWithoutCommit=false, blockedNeedingEdit=false, blockerDetail="", and a summary naming the failure.`,
934
- { label: `fix-commit:${sourceLabel}`, phase: 'Converge', schema: FIX_SCHEMA, agentType: 'clean-coder' },
935
- )
936
- }
937
-
938
- /**
939
- * Commit-recovery fixer: when a commit step is blocked by a commit-time hook or
940
- * gate that requires a code change, one clean-coder fixes only that blocking
941
- * violation test-first in the working tree and leaves it uncommitted, so the
942
- * re-verify step can bind a fresh verdict and the retry commit can push. It does
943
- * not re-open the original findings or touch GitHub threads — the edit step
944
- * already handled those.
945
- * @param {string} head PR HEAD SHA the fixes were raised against
946
- * @param {string} blockerDetail verbatim hook/gate message naming the file and rule to change
947
- * @param {string} sourceLabel short description of where the findings came from
948
- * @param {number} attempt the 1-based recovery attempt number
949
- * @returns {Promise<object>} EDIT_SCHEMA result
950
- */
951
- function recoverCommitBlockEdit(head, blockerDetail, sourceLabel, attempt) {
952
- return convergeAgent(
953
- `You are the COMMIT-RECOVERY fixer (attempt ${attempt}) for fixes (${sourceLabel}) on ${prCoordinates}, HEAD ${head}. A prior commit step was blocked by a commit-time hook or gate that requires a code change. A separate verify step then a separate commit step run after you.\n\n` +
954
- `The blocking hook or gate said:\n${blockerDetail}\n\n` +
955
- `Rules:\n` +
956
- `- Confirm the working tree is on the PR branch at HEAD ${head} with the prior fixes still present.\n` +
957
- `- Fix ONLY the violation named above, test-first (failing test, then minimum code to pass) per CODE_RULES. Do not re-open the original findings, and do not touch GitHub review threads — the edit step already handled those.\n` +
958
- `- 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` +
959
- `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.` +
960
- PRE_COMMIT_GATE_STEP,
961
- { label: `fix-recover:${sourceLabel}`, phase: 'Converge', schema: EDIT_SCHEMA, agentType: 'clean-coder' },
962
- )
963
- }
964
-
965
- /**
966
- * Verify-recovery fixer: when the verify step rejects the working-tree fixes, one
967
- * clean-coder re-fixes against the verdict's stated objections, test-first, and
968
- * leaves the work uncommitted so the re-verify step can bind a fresh verdict. The
969
- * objection text names which findings the verifier judged unresolved and why, so
970
- * the fixer addresses those concerns; it does not touch GitHub review threads —
971
- * the edit step already replied to and resolved those.
972
- * @param {string} head PR HEAD SHA the fixes were raised against
973
- * @param {string} objection the verifier's rendered objections from the failed verdict
974
- * @param {string} sourceLabel short description of where the findings came from
975
- * @param {number} attempt the 1-based recovery attempt number
976
- * @returns {Promise<object>} EDIT_SCHEMA result
977
- */
978
- function recoverVerifyFailEdit(head, objection, sourceLabel, attempt) {
979
- return convergeAgent(
980
- `You are the VERIFY-RECOVERY fixer (attempt ${attempt}) for fixes (${sourceLabel}) on ${prCoordinates}, HEAD ${head}. The verify step rejected the working-tree fixes; its verdict named what is still unresolved. A separate verify step then a separate commit step run after you.\n\n` +
981
- `The verify step's objections:\n${objection}\n\n` +
982
- `Rules:\n` +
983
- `- Confirm the working tree is on the PR branch at HEAD ${head} with the prior fixes still present.\n` +
984
- `- Address every objection above test-first (failing test, then minimum code to pass) per CODE_RULES, so each named concern is genuinely resolved the way the verdict requires. Do not touch GitHub review threads — the edit step already handled those.\n` +
985
- `- 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` +
986
- `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.` +
987
- PRE_COMMIT_GATE_STEP,
988
- { label: `fix-verify-recover:${sourceLabel}`, phase: 'Converge', schema: EDIT_SCHEMA, agentType: 'clean-coder' },
989
- )
990
- }
991
-
992
1282
  const FIX_RECOVERY_MAX_ATTEMPTS = 2
993
1283
 
994
1284
  /**
@@ -1041,21 +1331,24 @@ async function verifyWithRecovery({ runVerify, runRecoverEdit }) {
1041
1331
  }
1042
1332
 
1043
1333
  /**
1044
- * Fix lens: edit (clean-coder, no commit) -> verify (code-verifier emits a
1045
- * verdict fence binding the working tree) -> commit (clean-coder, one commit +
1046
- * push, no edits). Splitting the single editing-and-committing agent lets a
1047
- * workflow code-verifier produce the verdict the verified-commit gate requires,
1048
- * which the SubagentStop minter cannot mint for workflow-spawned agents. When
1049
- * verification fails (or the edit step stalled with no thread to resolve), the
1050
- * commit step is skipped and the unchanged HEAD is returned so the round reads
1051
- * as not-progressed.
1334
+ * Fix lens: edit (clean-coder, no commit) -> verify (a separate code-verifier
1335
+ * emits a verdict fence binding the working tree) -> commit (clean-coder, one
1336
+ * commit + push, no edits). The verifier is a distinct persistent group from the
1337
+ * fixer, so the verdict that gates the commit comes from a different session than
1338
+ * the one that edits and pushes the same editor/verifier separation the repair
1339
+ * and conflict paths use, and the separation a workflow code-verifier needs to
1340
+ * produce the verdict the verified-commit gate requires, which the SubagentStop
1341
+ * minter cannot mint for workflow-spawned agents. When verification fails (or the
1342
+ * edit step stalled with no thread to resolve), the commit step is skipped and the
1343
+ * unchanged HEAD is returned so the round reads as not-progressed.
1052
1344
  * @param {string} head PR HEAD SHA the findings were raised against
1053
1345
  * @param {Array<object>} findings deduped findings across all lenses
1054
1346
  * @param {string} sourceLabel short description of where the findings came from
1055
1347
  * @returns {Promise<object>} FIX_SCHEMA result
1056
1348
  */
1057
1349
  async function applyFixes(head, findings, sourceLabel) {
1058
- const editResult = await applyFixesEdit(head, findings, sourceLabel)
1350
+ const codeEditorId = await spawnCodeEditorAgent()
1351
+ const editResult = await resumeCodeEditorAgent(codeEditorId, 'fix-edit', { head, findings, sourceLabel })
1059
1352
  if (editResult?.resolvedWithoutCommit === true && editResult?.edited !== true) {
1060
1353
  return {
1061
1354
  newSha: head,
@@ -1066,47 +1359,9 @@ async function applyFixes(head, findings, sourceLabel) {
1066
1359
  blockerDetail: '',
1067
1360
  }
1068
1361
  }
1069
- const verifyTranscript = await verifyWithRecovery({
1070
- runVerify: () => verifyFixesInWorkingTree(head, findings, sourceLabel),
1071
- runRecoverEdit: (objection, attempt) => recoverVerifyFailEdit(head, objection, sourceLabel, attempt),
1072
- })
1073
- if (!verdictPassed(verifyTranscript)) {
1074
- return {
1075
- newSha: head,
1076
- pushed: false,
1077
- resolvedWithoutCommit: false,
1078
- summary: `verify step did not pass the working-tree fixes for ${findings.length} finding(s) — not committing`,
1079
- blockedNeedingEdit: false,
1080
- blockerDetail: '',
1081
- }
1082
- }
1083
- return commitWithRecovery({
1084
- runCommit: () => commitVerifiedFixes(head, sourceLabel),
1085
- runVerify: () => verifyFixesInWorkingTree(head, findings, sourceLabel),
1086
- runRecoverEdit: (detail, attempt) => recoverCommitBlockEdit(head, detail, sourceLabel, attempt),
1087
- })
1088
- }
1089
-
1090
- /**
1091
- * Post the terminal CLEAN bugteam audit artifact so check_convergence.py sees
1092
- * a clean bugteam review on the converged HEAD. The post is load-bearing: the
1093
- * convergence gate's bugteam-review check can never pass until this review
1094
- * lands, so the result reports whether the post succeeded rather than
1095
- * discarding it. A blocked post (a permission or auto-mode-classifier denial)
1096
- * or a script error returns posted:false with the reason so the caller can
1097
- * surface a blocker instead of re-converging into the iteration cap.
1098
- * @param {string} head converged PR HEAD SHA
1099
- * @returns {Promise<object>} CLEAN_AUDIT_SCHEMA result
1100
- */
1101
- function postCleanAudit(head) {
1102
- return convergeAgent(
1103
- `Post a CLEAN bugteam audit review on ${prCoordinates} at commit ${head}. All review lenses are clean on this HEAD.\n\n` +
1104
- `Write an empty findings file: create a temp file containing exactly [] (an empty JSON array). Then run:\n` +
1105
- `python "${CONFIG.prLoopScripts}/post_audit_thread.py" --skill bugteam --owner ${input.owner} --repo ${input.repo} --pr-number ${input.prNumber} --commit ${head} --state CLEAN --findings-json <temp-file>\n` +
1106
- `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` +
1107
- `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.`,
1108
- { label: 'post-clean-audit', phase: 'Converge', schema: CLEAN_AUDIT_SCHEMA, agentType: 'general-purpose' },
1109
- )
1362
+ const fixerAgentId = await spawnFixerAgent(head, findings, sourceLabel)
1363
+ const verifierId = await spawnVerifierAgent()
1364
+ return fixerWithRecovery(fixerAgentId, verifierId, head, findings, sourceLabel)
1110
1365
  }
1111
1366
 
1112
1367
  /**
@@ -1115,7 +1370,7 @@ function postCleanAudit(head) {
1115
1370
  * post stops the run with an actionable message rather than re-converging until
1116
1371
  * the iteration cap. Handles a dead post agent (a null result) as not posted.
1117
1372
  * @param {string} head converged PR HEAD SHA
1118
- * @param {object} auditResult CLEAN_AUDIT_SCHEMA result from postCleanAudit, or null when the agent died
1373
+ * @param {object} auditResult CLEAN_AUDIT_SCHEMA result from the post-clean-audit resume, or null when the agent died
1119
1374
  * @returns {string} the blocker message naming the post failure and the unblock path
1120
1375
  */
1121
1376
  function cleanAuditBlocker(head, auditResult) {
@@ -1153,133 +1408,6 @@ function runCopilotGate(head) {
1153
1408
  )
1154
1409
  }
1155
1410
 
1156
- /**
1157
- * Run the authoritative convergence gate.
1158
- * @param {boolean} bugbotDown pass --bugbot-down when Bugbot is opted out or proved unreachable this run
1159
- * @param {boolean} copilotDown pass --copilot-down when Copilot is down or out of quota this run
1160
- * @returns {Promise<object>} CONVERGENCE_SCHEMA result
1161
- */
1162
- function checkConvergence(bugbotDown, copilotDown) {
1163
- const bugbotDownFlag = bugbotDown ? ' --bugbot-down' : ''
1164
- const copilotDownFlag = copilotDown ? ' --copilot-down' : ''
1165
- return convergeAgent(
1166
- `Run the convergence gate for ${prCoordinates} and report the result. Do not edit code.\n\n` +
1167
- `Run: python "${CONFIG.sharedScripts}/check_convergence.py" --owner ${input.owner} --repo ${input.repo} --pr-number ${input.prNumber}${bugbotDownFlag}${copilotDownFlag}\n\n` +
1168
- `Exit 0 -> every gate passed: return {pass:true, failures:[]}.\n` +
1169
- `Exit 1 -> return {pass:false, failures:[<each printed FAIL line verbatim>]}.\n` +
1170
- `Exit 2 -> retry once; if it still errors, return {pass:false, failures:["check_convergence gh error"]}.`,
1171
- { label: 'check-convergence', phase: 'Finalize', schema: CONVERGENCE_SCHEMA, agentType: 'Explore' },
1172
- )
1173
- }
1174
-
1175
- /**
1176
- * Mark the PR ready for review (draft=false) and confirm the transition landed.
1177
- * When Copilot is down this run, the mark-ready agent first opts the
1178
- * independent mark-ready blocker hook out of the Copilot gate by exporting
1179
- * the Copilot token into CLAUDE_REVIEWS_DISABLED: that hook re-runs
1180
- * check_convergence.py without --copilot-down, so the env token is the only
1181
- * channel a genuine Copilot outage has to pass its Copilot review gate.
1182
- * @param {string} head converged PR HEAD SHA
1183
- * @param {boolean} copilotDown true when the Copilot gate was bypassed for an outage this run
1184
- * @returns {Promise<object>} READY_SCHEMA result
1185
- */
1186
- function markReady(head, copilotDown) {
1187
- const copilotOptOut = copilotDown
1188
- ? `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`
1189
- : ''
1190
- return convergeAgent(
1191
- `All convergence gates pass for ${prCoordinates} on HEAD ${head}. Mark the PR ready, then confirm it left draft state. Do not edit code.\n\n` +
1192
- copilotOptOut +
1193
- `1. Run: gh pr ready ${input.prNumber} --repo ${input.owner}/${input.repo}\n` +
1194
- `2. Re-query the draft state: gh api repos/${input.owner}/${input.repo}/pulls/${input.prNumber} --jq .draft\n` +
1195
- `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}.`,
1196
- { label: 'mark-ready', phase: 'Finalize', schema: READY_SCHEMA, agentType: 'general-purpose' },
1197
- )
1198
- }
1199
-
1200
- /**
1201
- * Repair edit step: one clean-coder resolves the lingering bot review threads
1202
- * the convergence check flagged, fixes any still-applicable bot-thread concern
1203
- * test-first in the working tree, and rebases onto origin/main when the PR is
1204
- * not mergeable — making NO commit and NO push, so the verify step can bind a
1205
- * verdict to the resulting surface before the commit step pushes it. Human
1206
- * reviewer threads are never touched.
1207
- * @param {string} head current PR HEAD SHA
1208
- * @param {Array<string>} failures FAIL lines from the convergence check
1209
- * @returns {Promise<object>} REPAIR_EDIT_SCHEMA result
1210
- */
1211
- function repairConvergenceEdit(head, failures) {
1212
- const failureBlock = failures.length
1213
- ? failures.map((each, position) => `${position + 1}. ${each}`).join('\n')
1214
- : 'none reported'
1215
- return convergeAgent(
1216
- `You are the EDIT step repairing the convergence gates that failed for ${prCoordinates} on HEAD ${head}. A separate verify step then a separate commit step run after you.\n\n` +
1217
- `Failing gates:\n${failureBlock}\n\n` +
1218
- `Address only the failing gates, and make NO commit and NO push — leave every code change in the working tree (a rebase necessarily creates local commits, which is fine; just do not push them):\n` +
1219
- `- Unresolved bot review threads: fetch the threads where isResolved is false (gh api graphql, or the github MCP pull_request_read get_review_comments), then keep only the bot-authored ones — a thread whose root comment author login contains "cursor", "claude", or "copilot" (case-insensitive substring). Explicitly skip every human reviewer thread; the convergence gate counts only unresolved bot threads, so touching a human thread is out of scope. For each bot thread, verify the concern against current code; if it still applies, fix it test-first in the working tree and leave the fix uncommitted; either way post an inline reply and resolve the thread by its PRRT_ node id (GraphQL lookup matching the comment databaseId, then resolveReviewThread or the github MCP pull_request_review_write method=resolve_thread — not the numeric comment id).\n` +
1220
- `- PR not mergeable: rebase onto origin/main FIRST, before applying any uncommitted bot-thread fix, so the rebase runs on a clean tree (git fetch origin main; git rebase origin/main; resolve conflicts). Do NOT force-push — the commit step does that after verification.\n` +
1221
- `- A dirty bot review or a still-pending requested reviewer: leave it; the next round re-runs that reviewer.\n\n` +
1222
- `Return values:\n` +
1223
- `- edited=true when you changed code in the working tree to fix a bot-thread concern.\n` +
1224
- `- rebased=true when you rebased the branch onto origin/main.\n` +
1225
- `- 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` +
1226
- `Always include a one-line summary.` +
1227
- PRE_COMMIT_GATE_STEP,
1228
- { label: 'repair-edit', phase: 'Finalize', schema: REPAIR_EDIT_SCHEMA, agentType: 'clean-coder' },
1229
- )
1230
- }
1231
-
1232
- /**
1233
- * Repair verify step: a code-verifier confirms the working-tree repair (any
1234
- * bot-thread fix plus any rebase result) is sound, computes the binding surface
1235
- * hash, and ends with a verdict fence as plain assistant text (NO schema). The
1236
- * fence's manifest_sha256 unlocks the verified-commit gate for the commit step's
1237
- * push. The verifier makes no edits.
1238
- * @param {string} head PR HEAD SHA the repair started from
1239
- * @param {Array<string>} failures FAIL lines the repair addressed
1240
- * @returns {Promise<string>} the verifier transcript carrying the verdict fence
1241
- */
1242
- function verifyRepairChanges(head, failures) {
1243
- const failureBlock = failures.length
1244
- ? failures.map((each, position) => `${position + 1}. ${each}`).join('\n')
1245
- : 'none reported'
1246
- return convergeAgent(
1247
- `You are the VERIFY step for the convergence repair on ${prCoordinates}, HEAD ${head}. The edit step left its repair in the working tree (a bot-thread fix uncommitted, and/or a rebase onto origin/main), unpushed. Do NO edits of any kind — verification only; any edit invalidates the verdict you are about to emit.\n\n` +
1248
- `Concerns the working-tree repair must resolve (the gates the convergence check flagged):\n${failureBlock}\n\n` +
1249
- `Steps:\n` +
1250
- `1. Resolve the worktree repo root for running tests: REPO=$(git rev-parse --show-toplevel).\n` +
1251
- `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` +
1252
- `3. ${buildVerdictFenceSteps(input.owner, input.repo, input.prNumber)}`,
1253
- { label: 'repair-verify', phase: 'Finalize', agentType: 'code-verifier' },
1254
- )
1255
- }
1256
-
1257
- /**
1258
- * Repair commit step: one clean-coder commits any uncommitted bot-thread fix in
1259
- * a single commit and pushes to the PR branch (force-with-lease when the edit
1260
- * step rebased), making NO further file edits — any edit changes the surface and
1261
- * invalidates the verifier verdict that unlocks the commit gate.
1262
- * @param {string} head PR HEAD SHA before the repair push
1263
- * @param {boolean} wasRebased true when the edit step rebased the branch, so the push must be force-with-lease
1264
- * @returns {Promise<object>} FIX_SCHEMA result
1265
- */
1266
- function commitRepairFixes(head, wasRebased) {
1267
- const pushInstruction = wasRebased
1268
- ? 'The edit step rebased the branch, so push with git push --force-with-lease.'
1269
- : 'Push to the PR branch with a plain git push.'
1270
- return convergeAgent(
1271
- `You are the COMMIT step for the convergence repair on ${prCoordinates}, HEAD ${head}. The edit step left its repair in the working tree and the verify step passed, so a verifier verdict already binds to this exact working tree.\n\n` +
1272
- `Rules:\n` +
1273
- `- Make NO further file edits of any kind. Any edit changes the surface and invalidates the verdict that unlocks the commit gate, so the push would be blocked. Do not run a formatter, do not re-fix anything — only commit and push what is already there.\n` +
1274
- `- Commit any uncommitted bot-thread fix in ONE commit (skip the commit when the working tree carries only already-committed rebase results). ${pushInstruction}\n\n` +
1275
- `Return values:\n` +
1276
- `- 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` +
1277
- `- 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=${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` +
1278
- `- On a transient or non-code failure (auth, network, a non-fast-forward, a lock): newSha=${head}, pushed=false, resolvedWithoutCommit=false, blockedNeedingEdit=false, blockerDetail="", and a summary naming the failure.`,
1279
- { label: 'repair-commit', phase: 'Finalize', schema: FIX_SCHEMA, agentType: 'clean-coder' },
1280
- )
1281
- }
1282
-
1283
1411
  /**
1284
1412
  * Address the gates a convergence check reported as failing, then hand control
1285
1413
  * back to the converge phase: edit (clean-coder resolves bot threads, applies
@@ -1295,7 +1423,8 @@ function commitRepairFixes(head, wasRebased) {
1295
1423
  * @returns {Promise<object>} FIX_SCHEMA result
1296
1424
  */
1297
1425
  async function repairConvergence(head, failures) {
1298
- const editResult = await repairConvergenceEdit(head, failures)
1426
+ const codeEditorId = await spawnCodeEditorAgent()
1427
+ const editResult = await resumeCodeEditorAgent(codeEditorId, 'repair-edit', { head, failures })
1299
1428
  const hasPushWork = editResult?.edited === true || editResult?.rebased === true
1300
1429
  if (!hasPushWork) {
1301
1430
  return {
@@ -1307,9 +1436,10 @@ async function repairConvergence(head, failures) {
1307
1436
  blockerDetail: '',
1308
1437
  }
1309
1438
  }
1439
+ const verifierId = await spawnVerifierAgent()
1310
1440
  const verifyTranscript = await verifyWithRecovery({
1311
- runVerify: () => verifyRepairChanges(head, failures),
1312
- runRecoverEdit: (objection, attempt) => recoverVerifyFailEdit(head, objection, 'repair', attempt),
1441
+ runVerify: () => resumeVerifierAgent(verifierId, 'repair-verify', { head, failures }),
1442
+ runRecoverEdit: (objection, attempt) => resumeCodeEditorAgent(codeEditorId, 'verify-recover', { head, sourceLabel: 'repair', objection, attempt }),
1313
1443
  })
1314
1444
  if (!verdictPassed(verifyTranscript)) {
1315
1445
  return {
@@ -1323,51 +1453,12 @@ async function repairConvergence(head, failures) {
1323
1453
  }
1324
1454
  const wasRebased = editResult?.rebased === true
1325
1455
  return commitWithRecovery({
1326
- runCommit: () => commitRepairFixes(head, wasRebased),
1327
- runVerify: () => verifyRepairChanges(head, failures),
1328
- runRecoverEdit: (detail, attempt) => recoverCommitBlockEdit(head, detail, 'repair', attempt),
1456
+ runCommit: () => resumeCodeEditorAgent(codeEditorId, 'repair-commit', { head, wasRebased }),
1457
+ runVerify: () => resumeVerifierAgent(verifierId, 'repair-verify', { head, failures }),
1458
+ runRecoverEdit: (detail, attempt) => resumeCodeEditorAgent(codeEditorId, 'commit-recover', { head, sourceLabel: 'repair', blockerDetail: detail, attempt }),
1329
1459
  })
1330
1460
  }
1331
1461
 
1332
- /**
1333
- * Pre-flight merge-conflict check: ask GitHub whether the PR branch still merges
1334
- * cleanly into its base. GitHub computes mergeability asynchronously, so the
1335
- * agent polls until .mergeable resolves to a boolean before judging. Read-only —
1336
- * it makes no edit, commit, push, or rebase.
1337
- * @param {string} head PR HEAD SHA the check runs against
1338
- * @returns {Promise<object>} MERGE_CONFLICT_SCHEMA result
1339
- */
1340
- function checkMergeConflicts(head) {
1341
- return convergeAgent(
1342
- `Report whether ${prCoordinates} (HEAD ${head}) has merge conflicts with its base branch. Do not edit, commit, push, or rebase — read only.\n\n` +
1343
- `GitHub computes mergeability asynchronously, so .mergeable is null right after a push until it finishes. Poll until it resolves: run\n` +
1344
- ` gh api repos/${input.owner}/${input.repo}/pulls/${input.prNumber} --jq '{mergeable: .mergeable, state: .mergeable_state}'\n` +
1345
- `up to 5 times, 5 seconds apart (delay each retry with "sleep 5", or the PowerShell alternative "Start-Sleep -Seconds 5"), stopping as soon as mergeable is true or false.\n\n` +
1346
- `Return conflicting:true when mergeable is false or state is "dirty" (the branch conflicts with the base). Return conflicting:false when mergeable is true, or when mergeable stays null after the full poll budget — mergeability is unknown, so let the bug checks proceed rather than rebase on a guess.`,
1347
- { label: 'check-merge-conflicts', phase: 'Converge', schema: MERGE_CONFLICT_SCHEMA, agentType: 'Explore' },
1348
- )
1349
- }
1350
-
1351
- /**
1352
- * Conflict-resolution edit step: one clean-coder rebases the PR branch onto
1353
- * origin/main and resolves every conflict in the working tree, making NO push —
1354
- * the verify step binds a verdict to the rebased tree before the commit step
1355
- * force-pushes it. A rebase necessarily creates local commits, which is expected;
1356
- * only the force-push is withheld so the verifier binds the surface first.
1357
- * @param {string} head PR HEAD SHA before the rebase
1358
- * @returns {Promise<object>} CONFLICT_EDIT_SCHEMA result
1359
- */
1360
- function resolveConflictsEdit(head) {
1361
- return convergeAgent(
1362
- `You are the EDIT step resolving merge conflicts for ${prCoordinates}, HEAD ${head}, before the bug checks run. The PR branch conflicts with origin/main. A separate verify step then a separate commit step run after you.\n\n` +
1363
- `Rules:\n` +
1364
- `- Confirm the working tree is on the PR branch at HEAD ${head} with no unrelated edits before you start.\n` +
1365
- `- 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` +
1366
- `- 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` +
1367
- `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.`,
1368
- { label: 'resolve-conflicts-edit', phase: 'Converge', schema: CONFLICT_EDIT_SCHEMA, agentType: 'clean-coder' },
1369
- )
1370
- }
1371
1462
 
1372
1463
  /**
1373
1464
  * Pre-flight conflict resolution: when the PR branch conflicts with its base,
@@ -1382,22 +1473,24 @@ function resolveConflictsEdit(head) {
1382
1473
  * @param {string} head PR HEAD SHA before any rebase
1383
1474
  * @returns {Promise<string>} the HEAD SHA after a successful rebase push, or the unchanged head
1384
1475
  */
1385
- async function resolveMergeConflicts(head) {
1386
- const mergeState = await checkMergeConflicts(head)
1476
+ async function resolveMergeConflicts(head, gitAgentId) {
1477
+ const mergeState = await resumeGitAgent(gitAgentId, 'check-merge-conflicts', head)
1387
1478
  if (!isMergeConflicting(mergeState)) return head
1388
1479
  log(`Pre-flight: ${prCoordinates} conflicts with origin/main — rebasing clean before the bug checks`)
1389
- const editResult = await resolveConflictsEdit(head)
1480
+ const codeEditorId = await spawnCodeEditorAgent()
1481
+ const editResult = await resumeCodeEditorAgent(codeEditorId, 'conflict-edit', { head })
1390
1482
  if (editResult?.rebased !== true) return head
1391
1483
  const failures = ['PR branch had merge conflicts with origin/main; the rebase must leave a clean, conflict-free tree']
1484
+ const verifierId = await spawnVerifierAgent()
1392
1485
  const verifyTranscript = await verifyWithRecovery({
1393
- runVerify: () => verifyRepairChanges(head, failures),
1394
- runRecoverEdit: (objection, attempt) => recoverVerifyFailEdit(head, objection, 'conflict-rebase', attempt),
1486
+ runVerify: () => resumeVerifierAgent(verifierId, 'repair-verify', { head, failures }),
1487
+ runRecoverEdit: (objection, attempt) => resumeCodeEditorAgent(codeEditorId, 'verify-recover', { head, sourceLabel: 'conflict-rebase', objection, attempt }),
1395
1488
  })
1396
1489
  if (!verdictPassed(verifyTranscript)) return head
1397
1490
  const commitResult = await commitWithRecovery({
1398
- runCommit: () => commitRepairFixes(head, true),
1399
- runVerify: () => verifyRepairChanges(head, failures),
1400
- runRecoverEdit: (detail, attempt) => recoverCommitBlockEdit(head, detail, 'conflict-rebase', attempt),
1491
+ runCommit: () => resumeCodeEditorAgent(codeEditorId, 'repair-commit', { head, wasRebased: true }),
1492
+ runVerify: () => resumeVerifierAgent(verifierId, 'repair-verify', { head, failures }),
1493
+ runRecoverEdit: (detail, attempt) => resumeCodeEditorAgent(codeEditorId, 'commit-recover', { head, sourceLabel: 'conflict-rebase', blockerDetail: detail, attempt }),
1401
1494
  })
1402
1495
  return commitResult?.newSha || head
1403
1496
  }
@@ -1414,90 +1507,6 @@ function isStandardsOnlyRound(findings) {
1414
1507
  return findings.length > 0 && findings.every((each) => each.category === 'code-standard')
1415
1508
  }
1416
1509
 
1417
- /**
1418
- * Standards-deferral edit step: one clean-coder files the follow-up fix issue,
1419
- * stages an environment-hardening hooks/rules change in the config repo's
1420
- * working tree WITHOUT committing, and resolves the PR's code-standard threads.
1421
- * Leaving the hardening edit uncommitted lets the verify step bind a verdict to
1422
- * it before the commit step opens the PR. The PR's own branch is never touched.
1423
- * @param {string} head PR HEAD SHA the findings were raised against
1424
- * @param {Array<object>} findings deduped code-standard-only findings
1425
- * @param {string} sourceLabel short description of where the findings came from
1426
- * @returns {Promise<object>} STANDARDS_EDIT_SCHEMA result
1427
- */
1428
- function standardsFollowUpEdit(head, findings, sourceLabel) {
1429
- const findingsBlock = renderFindingsBlock(findings)
1430
- const threadIds = findings
1431
- .flatMap((each) => collectFindingThreadIds(each))
1432
- .filter((each) => typeof each === 'number')
1433
- return convergeAgent(
1434
- `You are the EDIT step deferring a code-standard-only round on ${prCoordinates}, HEAD ${head} (${sourceLabel}). The round surfaced ONLY code-standard violations (CODE_RULES/style, no behavioral impact); the run treats it as passed and defers the fixes to follow-up work, which you now stage. A separate verify step then a separate commit step open the hardening PR after you. Do NOT commit or push to the PR's own branch.\n\n` +
1435
- `Findings:\n${findingsBlock}\n\n` +
1436
- `1. Follow-up fix issue: file a GitHub issue on ${input.owner}/${input.repo} (gh issue create --body-file with a temp file) titled "Deferred code-standard fixes from PR #${input.prNumber}". The body references the PR and lists each finding with its file:line, severity, and detail. The issue carries the fix work; do not open a fix PR. Capture the issue URL.\n` +
1437
- `2. Stage the environment-hardening change: in the Claude environment config repo (the repo owning ~/.claude hooks and rules — JonEcho/llm-settings for hooks, jl-cmd/claude-code-config for rules/skills; pick whichever owns the surface that would block these violation classes), find or clone a local checkout, fetch origin, and create a branch off origin/main. Edit the hooks/rules in that checkout's WORKING TREE so each violation class found here is blocked at Write/Edit time, before code is written. Do NOT commit and do NOT push — the commit step does that after the verify step binds a verdict to the working tree. Return the checkout's absolute path in hardeningRepoPath, the branch name in hardeningBranch, and set hardeningEdited=true. When no hardening is feasible for these classes, leave hardeningRepoPath and hardeningBranch empty and hardeningEdited=false; the follow-up issue still stands.\n` +
1438
- `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` +
1439
- `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.` +
1440
- PRE_COMMIT_GATE_STEP,
1441
- { label: `standards-edit:${sourceLabel}`, phase: 'Converge', schema: STANDARDS_EDIT_SCHEMA, agentType: 'clean-coder' },
1442
- )
1443
- }
1444
-
1445
- /**
1446
- * Standards-hardening verify step: a code-verifier confirms the uncommitted
1447
- * hooks/rules change staged in the hardening repo blocks the deferred violation
1448
- * classes, computes the binding surface hash for that repo by branch (cwd-immune),
1449
- * and ends with a verdict fence as plain assistant text (NO schema) — unlocking the
1450
- * verified-commit gate for the cross-repo hardening commit. The verifier makes
1451
- * no edits.
1452
- * @param {string} hardeningRepoPath absolute path of the hardening repo checkout the edit staged
1453
- * @param {string} hardeningBranch the branch in the hardening repo that the edit staged the change on
1454
- * @param {string} sourceLabel short description of where the findings came from
1455
- * @returns {Promise<string>} the verifier transcript carrying the verdict fence
1456
- */
1457
- function verifyHardeningChanges(hardeningRepoPath, hardeningBranch, sourceLabel) {
1458
- return convergeAgent(
1459
- `You are the VERIFY step for an environment-hardening change (${sourceLabel}) staged in the working tree of ${hardeningRepoPath}. The edit step left the hooks/rules edits uncommitted there. Do NO edits of any kind — verification only; any edit invalidates the verdict you are about to emit.\n\n` +
1460
- `Concern the working-tree change must resolve: the edited hooks/rules block the code-standard violation classes from the deferred round at Write/Edit time, and a hook change carries a passing test per CODE_RULES.\n\n` +
1461
- `Steps:\n` +
1462
- `1. cd into ${hardeningRepoPath}, then resolve its repo root: REPO=$(git rev-parse --show-toplevel).\n` +
1463
- `2. Verify the uncommitted working-tree change in REPO: read the diff (git diff) and run the hook/rule tests in that repo, confirming each violation class is now blocked.\n` +
1464
- `3. Compute the binding hash for the live surface:\n` +
1465
- ` The hardening branch is: ${hardeningBranch}\n` +
1466
- ` Run exactly:\n` +
1467
- ` "C:\\Python313\\python.exe" "<REPO>/packages/claude-dev-env/hooks/blocking/verification_verdict_store.py" --manifest-hash-for-branch "${hardeningBranch}"\n` +
1468
- ` (substitute the REPO path you resolved for the script path). That prints a single 64-char hex hash on stdout — capture it.\n` +
1469
- ` Then END your message with a fenced verdict block exactly in this shape, on its own, carrying that hash:\n` +
1470
- " ```verdict\n" +
1471
- ` {"all_pass": true, "findings": [], "manifest_sha256": "<that hash>"}\n` +
1472
- " ```\n" +
1473
- ` 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.`,
1474
- { label: `standards-verify:${sourceLabel}`, phase: 'Converge', agentType: 'code-verifier' },
1475
- )
1476
- }
1477
-
1478
- /**
1479
- * Standards-hardening commit step: one clean-coder commits the verified
1480
- * working-tree hooks/rules change in a single commit, pushes the hardening
1481
- * branch, and opens the DRAFT hardening PR — making NO further file edits, since
1482
- * any edit changes the surface and invalidates the verdict that unlocks the
1483
- * commit gate. The PR's own branch is never touched.
1484
- * @param {string} hardeningRepoPath absolute path of the hardening repo checkout
1485
- * @param {string} hardeningBranch the hardening branch the edit step created
1486
- * @param {string} issueUrl the follow-up fix issue URL the PR body references
1487
- * @param {string} sourceLabel short description of where the findings came from
1488
- * @returns {Promise<string>} agent transcript (unused)
1489
- */
1490
- function commitHardeningPr(hardeningRepoPath, hardeningBranch, issueUrl, sourceLabel) {
1491
- return convergeAgent(
1492
- `You are the COMMIT step opening the environment-hardening PR (${sourceLabel}) for the change staged in ${hardeningRepoPath} on branch ${hardeningBranch}. The edit step left the hooks/rules edits in the working tree and the verify step passed, so a verifier verdict already binds to this exact working tree. Do NOT touch the PR's own branch.\n\n` +
1493
- `Rules:\n` +
1494
- `- Make NO further file edits of any kind. Any edit changes the surface and invalidates the verdict that unlocks the commit gate, so the push would be blocked. Only commit and push what is already there.\n` +
1495
- `- In ${hardeningRepoPath}: make ONE commit of the staged hooks/rules change on branch ${hardeningBranch}, push it, then open a DRAFT PR. The PR body references the follow-up issue ${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\n` +
1496
- `Return a one-line summary naming the hardening PR URL.`,
1497
- { label: `standards-commit:${sourceLabel}`, phase: 'Converge', agentType: 'clean-coder' },
1498
- )
1499
- }
1500
-
1501
1510
  /**
1502
1511
  * Build the standards-deferral note for the closing report, naming the
1503
1512
  * environment-hardening PR only when one was opened this round so the note
@@ -1530,63 +1539,24 @@ function standardsDeferralNote(findingsCount, hardeningPrOpened) {
1530
1539
  * @returns {Promise<object>} `{ hardeningPrOpened }` — true only when the hardening PR was opened this round
1531
1540
  */
1532
1541
  async function spawnStandardsFollowUp(head, findings, sourceLabel) {
1533
- const editResult = await standardsFollowUpEdit(head, findings, sourceLabel)
1542
+ const codeEditorId = await spawnCodeEditorAgent()
1543
+ const editResult = await resumeCodeEditorAgent(codeEditorId, 'standards-edit', { head, findings, sourceLabel })
1534
1544
  if (editResult?.hardeningEdited !== true || !editResult?.hardeningRepoPath) {
1535
1545
  return { hardeningPrOpened: false }
1536
1546
  }
1537
- const verifyTranscript = await verifyHardeningChanges(editResult.hardeningRepoPath, editResult.hardeningBranch, sourceLabel)
1547
+ const verifierId = await spawnVerifierAgent()
1548
+ const verifyTranscript = await resumeVerifierAgent(verifierId, 'hardening-verify', {
1549
+ head, sourceLabel, hardeningRepoPath: editResult.hardeningRepoPath, hardeningBranch: editResult.hardeningBranch,
1550
+ })
1538
1551
  if (!verdictPassed(verifyTranscript)) {
1539
1552
  return { hardeningPrOpened: false }
1540
1553
  }
1541
- await commitHardeningPr(editResult.hardeningRepoPath, editResult.hardeningBranch, editResult.issueUrl, sourceLabel)
1554
+ await resumeCodeEditorAgent(codeEditorId, 'hardening-commit', {
1555
+ head, sourceLabel, hardeningRepoPath: editResult.hardeningRepoPath, hardeningBranch: editResult.hardeningBranch, issueUrl: editResult.issueUrl,
1556
+ })
1542
1557
  return { hardeningPrOpened: true }
1543
1558
  }
1544
1559
 
1545
- /**
1546
- * Spawn the convergence-summary agent at finalize so its StructuredOutput is
1547
- * recorded into the run journal for the closing report to read. The agent groups
1548
- * the deduped findings into plain-language issue classes, translates reviewer
1549
- * jargon to everyday English, and writes one BLUF verdict line. The side effect
1550
- * is the journal record; the return value is discarded by the caller.
1551
- * @param {Array<object>} distinctFindings deduped findings across every round
1552
- * @param {Array<string>} fixSummaries per-round fix-lens one-line summaries
1553
- * @param {number} roundCount the number of converge rounds the run took
1554
- * @param {string|null} standardsNote deferral note when a round was code-standard-only
1555
- * @param {string|null} copilotNote outage note when the Copilot gate was bypassed
1556
- * @returns {Promise<object>} CONVERGENCE_SUMMARY_SCHEMA result (journal side effect)
1557
- */
1558
- function spawnConvergenceSummary(distinctFindings, fixSummaries, roundCount, standardsNote, copilotNote) {
1559
- const findingsBlock = distinctFindings.length
1560
- ? distinctFindings
1561
- .map((each, position) => {
1562
- const truncatedDetail = (each.detail || '').slice(0, 400)
1563
- return `${position + 1}. [${each.severity}/${each.category}] ${each.file}:${each.line} — ${each.title} :: ${truncatedDetail}`
1564
- })
1565
- .join('\n')
1566
- : 'none — every lens was clean on a stable HEAD'
1567
- const fixSummariesBlock = fixSummaries.length
1568
- ? fixSummaries.map((each, position) => `${position + 1}. ${each}`).join('\n')
1569
- : 'none'
1570
- const standardsBlock = standardsNote ? `\nDeferred code-standard note: ${standardsNote}\n` : ''
1571
- const copilotBlock = copilotNote ? `\nCopilot gate note: ${copilotNote}\n` : ''
1572
- return convergeAgent(
1573
- `You write the plain-language convergence summary for ${prCoordinates}. The autoconverge run reached convergence in ${roundCount} round(s). Use ONLY the findings and fix summaries below; invent nothing not present.\n\n` +
1574
- `Distinct findings caught across the run (already deduped):\n${findingsBlock}\n\n` +
1575
- `Per-round fix summaries:\n${fixSummariesBlock}\n${standardsBlock}${copilotBlock}\n` +
1576
- `Produce a summary an everyday reader understands:\n` +
1577
- `- GROUP near-duplicate findings into issue CLASSES: the same KIND of problem across different files or lines becomes ONE class with a count. Example: seven "Missing return type annotation on test function" findings become one class with count 7.\n` +
1578
- `- TRANSLATE reviewer jargon into plain everyday English. Examples: "CodingGuidelineID 1000000 / Repository guideline (Types)" -> "a typing rule the project enforces"; "missing return type annotation / Add -> None" -> "a test did not declare what it returns"; "Banned identifier result" -> "a vague variable name the project bans"; a magic-value finding -> "a raw number or string that should be a named value".\n` +
1579
- `- plainName must carry NO tool token, rule id, file path, line number, severity code (P0/P1/P2), or bot name.\n` +
1580
- `- Lead with category 'bug' classes, then 'code-standard'. Cap to about 5 classes. whatItWas is at most 2 sentences. No paragraphs.\n` +
1581
- `- status is 'fixed' unless the fix summaries or the deferred code-standard note mark the class deferred, in which case status is 'deferred'.\n` +
1582
- `- Use NO hedging words anywhere (likely, probably, should, appears, seems, may, might, could, possibly). State facts ("caught and fixed").\n` +
1583
- `- When there are zero findings, return issueClasses: [] and a verdictLine stating the run converged with no issues caught.\n` +
1584
- `- verdictLine is one factual sentence naming the round count and that all classes are fixed or deferred.\n\n` +
1585
- `Return strictly the schema.`,
1586
- { label: 'convergence-summary', phase: 'Finalize', schema: CONVERGENCE_SUMMARY_SCHEMA, agentType: 'general-purpose' },
1587
- )
1588
- }
1589
-
1590
1560
  let phase = 'CONVERGE'
1591
1561
  let head = null
1592
1562
  let rounds = 0
@@ -1597,25 +1567,24 @@ let copilotDown = false
1597
1567
  let copilotNote = null
1598
1568
  let standardsNote = null
1599
1569
  let reuseNote = null
1600
- const allRoundFindings = []
1601
- const fixSummaries = []
1602
1570
 
1603
- const preflightHead = await resolveHead()
1604
- if (isResolvedHeadUsable(preflightHead)) {
1605
- await resolveMergeConflicts(preflightHead)
1571
+ const gitAgentId = await spawnGitAgent()
1572
+
1573
+ const preflightHead = await resumeGitAgent(gitAgentId, 'resolve-head')
1574
+ if (isResolvedHeadUsable(preflightHead?.sha)) {
1575
+ await resolveMergeConflicts(preflightHead.sha, gitAgentId)
1606
1576
  }
1607
1577
 
1608
1578
  log('Reuse pass: scanning the full diff for certain, behaviorally identical, autonomously implementable reuse improvements before convergence')
1609
- const reuseHead = await resolveHead()
1579
+ const reuseHeadResult = await resumeGitAgent(gitAgentId, 'resolve-head')
1580
+ const reuseHead = reuseHeadResult?.sha
1610
1581
  if (isResolvedHeadUsable(reuseHead)) {
1611
- await prefetchMainForRound()
1582
+ await resumeGitAgent(gitAgentId, 'prefetch-main')
1612
1583
  const reuse = await runReuseAuditPass(reuseHead)
1613
1584
  const reuseFindings = reuse?.findings || []
1614
1585
  if (reuseFindings.length > 0) {
1615
1586
  log(`Reuse pass: ${reuseFindings.length} qualifying reuse improvement(s) — applying before convergence`)
1616
- allRoundFindings.push(...reuseFindings)
1617
1587
  const reuseFix = await applyFixes(reuseHead, reuseFindings, 'reuse-pass')
1618
- if (reuseFix?.summary) fixSummaries.push(reuseFix.summary)
1619
1588
  reuseNote = reuseFix?.pushed === true
1620
1589
  ? `${reuseFindings.length} reuse improvement(s) applied before convergence (${reuseFix.newSha?.slice(0, SHA_COMPARISON_PREFIX_LENGTH)})`
1621
1590
  : `${reuseFindings.length} reuse improvement(s) identified before convergence but not landed — the code-review lens re-surfaces any that remain`
@@ -1626,16 +1595,19 @@ if (isResolvedHeadUsable(reuseHead)) {
1626
1595
  log('Reuse pass: could not resolve HEAD — proceeding to convergence')
1627
1596
  }
1628
1597
 
1598
+ const convergenceId = await spawnConvergenceCheckAgent()
1599
+
1629
1600
  while (iterations < CONFIG.maxIterations) {
1630
1601
  iterations += 1
1631
1602
  if (phase === 'CONVERGE') {
1632
1603
  rounds += 1
1633
- head = await resolveHead()
1604
+ const headResult = await resumeGitAgent(gitAgentId, 'resolve-head')
1605
+ head = headResult?.sha
1634
1606
  if (!isResolvedHeadUsable(head)) {
1635
1607
  log(`Round ${rounds}: resolve-head agent returned no SHA — retrying without spawning lenses`)
1636
1608
  continue
1637
1609
  }
1638
- await prefetchMainForRound()
1610
+ await resumeGitAgent(gitAgentId, 'prefetch-main')
1639
1611
  log(`Round ${rounds}: parallel Bugbot + code-review + bug-audit on ${head?.slice(0, 7)}`)
1640
1612
  const lenses = await parallel([
1641
1613
  () => runBugbotLens(head),
@@ -1651,10 +1623,10 @@ while (iterations < CONFIG.maxIterations) {
1651
1623
  const findings = roundOutcome.findings
1652
1624
  if (isStandardsOnlyRound(findings)) {
1653
1625
  log(`Round ${rounds}: ${findings.length} code-standard-only finding(s) — deferring to follow-up PRs and treating the round as passed`)
1654
- allRoundFindings.push(...findings)
1626
+ const generalId = await spawnGeneralUtilityAgent()
1655
1627
  const standardsOutcome = await spawnStandardsFollowUp(head, findings, 'converge-round')
1656
1628
  standardsNote = standardsDeferralNote(findings.length, standardsOutcome?.hardeningPrOpened === true)
1657
- const auditResult = await postCleanAudit(head)
1629
+ const auditResult = await resumeGeneralUtilityAgent(generalId, 'post-clean-audit', { head })
1658
1630
  if (!auditResult?.posted) {
1659
1631
  blocker = cleanAuditBlocker(head, auditResult)
1660
1632
  break
@@ -1664,9 +1636,7 @@ while (iterations < CONFIG.maxIterations) {
1664
1636
  }
1665
1637
  if (findings.length > 0) {
1666
1638
  log(`Round ${rounds}: ${findings.length} finding(s) — applying fixes`)
1667
- allRoundFindings.push(...findings)
1668
1639
  const fixResult = await applyFixes(head, findings, 'converge-round')
1669
- if (fixResult?.summary) fixSummaries.push(fixResult.summary)
1670
1640
  const hadThreadBearingFinding = findings.some((each) => collectFindingThreadIds(each).length > 0)
1671
1641
  const fixProgress = detectFixProgress(fixResult, head, hadThreadBearingFinding)
1672
1642
  if (!fixProgress.progressed) {
@@ -1682,7 +1652,8 @@ while (iterations < CONFIG.maxIterations) {
1682
1652
  continue
1683
1653
  }
1684
1654
  log(`Round ${rounds}: all lenses clean on ${head?.slice(0, 7)} — posting clean audit artifact`)
1685
- const auditResult = await postCleanAudit(head)
1655
+ const cleanGeneralId = await spawnGeneralUtilityAgent()
1656
+ const auditResult = await resumeGeneralUtilityAgent(cleanGeneralId, 'post-clean-audit', { head })
1686
1657
  if (!auditResult?.posted) {
1687
1658
  blocker = cleanAuditBlocker(head, auditResult)
1688
1659
  break
@@ -1710,7 +1681,6 @@ while (iterations < CONFIG.maxIterations) {
1710
1681
  if (copilotOutcome.kind === 'fix') {
1711
1682
  if (isStandardsOnlyRound(copilotOutcome.findings)) {
1712
1683
  log(`Copilot raised ${copilotOutcome.findings.length} code-standard-only finding(s) — deferring to follow-up PRs and treating the gate as passed`)
1713
- allRoundFindings.push(...copilotOutcome.findings)
1714
1684
  const standardsOutcome = await spawnStandardsFollowUp(head, copilotOutcome.findings, 'copilot')
1715
1685
  standardsNote = standardsDeferralNote(copilotOutcome.findings.length, standardsOutcome?.hardeningPrOpened === true)
1716
1686
  copilotDown = false
@@ -1719,9 +1689,7 @@ while (iterations < CONFIG.maxIterations) {
1719
1689
  continue
1720
1690
  }
1721
1691
  log(`Copilot raised ${copilotOutcome.findings.length} finding(s) — fixing and re-converging`)
1722
- allRoundFindings.push(...copilotOutcome.findings)
1723
1692
  const fixResult = await applyFixes(head, copilotOutcome.findings, 'copilot')
1724
- if (fixResult?.summary) fixSummaries.push(fixResult.summary)
1725
1693
  const hadThreadBearingFinding = copilotOutcome.findings.some((each) => collectFindingThreadIds(each).length > 0)
1726
1694
  const fixProgress = detectFixProgress(fixResult, head, hadThreadBearingFinding)
1727
1695
  if (!fixProgress.progressed) {
@@ -1740,17 +1708,17 @@ while (iterations < CONFIG.maxIterations) {
1740
1708
  }
1741
1709
 
1742
1710
  if (phase === 'FINALIZE') {
1743
- const convergence = await checkConvergence(bugbotDown, copilotDown)
1711
+ const convergence = await resumeConvergenceCheckAgent(convergenceId, { bugbotDown, copilotDown })
1744
1712
  const convergenceOutcome = classifyConvergenceOutcome(convergence)
1745
1713
  if (convergenceOutcome.kind === 'retry') {
1746
1714
  log('Convergence check agent died or returned no FAIL lines — re-running the check on the same HEAD')
1747
1715
  continue
1748
1716
  }
1749
1717
  if (convergenceOutcome.kind === 'ready') {
1750
- const readyResult = await markReady(head, copilotDown)
1718
+ const finalGeneralId = await spawnGeneralUtilityAgent()
1719
+ const readyResult = await resumeGeneralUtilityAgent(finalGeneralId, 'mark-ready', { head, copilotDown })
1751
1720
  const readyOutcome = classifyReadyOutcome(readyResult)
1752
1721
  if (readyOutcome.converged) {
1753
- await spawnConvergenceSummary(dedupeFindings(allRoundFindings), fixSummaries, rounds, standardsNote, copilotNote)
1754
1722
  return { converged: true, rounds, finalSha: head, blocker: null, standardsNote, copilotNote, reuseNote }
1755
1723
  }
1756
1724
  blocker = readyOutcome.blocker