Before asking, read User Questions.
Code Remediate¶
Apply the shared Proportional Execution policy to bounded analysis or implementation delegated within this workflow; specialized source selection, protected-state, lifecycle, and verification gates remain authoritative.
Code Remediate is a single pass: collect findings, resolve the selected work, obtain one bounded independent challenge of any implemented change, verify, and report. No convergence score, loop ledger, or score-based stop applies to ordinary remediation. Single pass limits workflow expansion, not necessary debugging, regression repair, or rerunning a failed configured check within the authorized scope. A challenge that cannot run (route unavailable, bridge or provider call denied by approval review, or user declines) never blocks completion, opens a question, or adds an unresolved row or incomplete status: remediation completes when its selected findings are closed and gates pass, with implementation challenge not run: <reason> under limitations and the implementation-challenge-not-run confidence gap. Never claim independent coverage that did not happen.
When a linked-worktree delivery holds a commit the run created and passes the publication gate, always show the final handover as a progress message, then open the single standard Approve / Deny push question in the same turn as the final gate. Combine removal with the push when --check-owner confirms ownership of the offered checkout unless the user asks to keep it. This default also applies to an existing PR worktree. Honor a request to publish the PR changes in the initial instructions or a later message, and use the same gate to verify the commit and destination and open the question. For an already completed delivery, enter the gate directly from its promoted run. A request for a push command for an earlier tip applies only to that tip.
Challenge Resolve is opt-in: a Code Remediate invocation alone does not authorize the challenge-resolve skill or an iterative adversarial review-and-fix loop. The bounded independent plan or implementation challenge required by Proportional Execution is not that loop. Enter the separate iterative workflow only when the user explicitly requests it. Do not propose or ask approval for an unsolicited loop. Existing explicit approval for the same scope remains valid; do not ask again. Only an explicitly requested loop reads ../../shared/adversarial-loop.md and applies its convergence and stop rules; afterward resume remediation's selection, implementation evidence, and normal completion gates. An unavailable recovery route remains explicitly blocked rather than bypassed.
Selecting all findings sets the scope of this pass. A joined +review, a request for one more review, a gate retry, or a resumed run keeps its own scope. Start Challenge Resolve only when the user names that workflow or asks to repeat independent review and fixes, for example until reviewers find no remaining issues.
See the fixed recurrence and root-cause policy and reasoning-progress escalation policy for repeated-obstacle handling; record and validate reasoning-progress.json before another cycle after escalation trigger.
Newly discovered in-scope defects do not trigger another review wave or score-based permission request. Resolve feasible work within the authorized scope using source evidence and focused checks; record genuinely separate or unfinished work with evidence, owner, and next action. Ask only for a concrete missing decision or material scope expansion. Never claim unresolved selected findings are closed.
Apply Worktree lifecycle before collection. Capture the original invoking checkout. In PR mode the default is gh pr checkout in that checkout. When local commits on a fork branch prevent exact-head checkout, retain the completed review, show the local-versus-remote differences, and guide the user through freeing the local name. Follow Source recovery. The optional --worktree flag requests a separate linked Git worktree, runs the same native PR checkout there, and retains the branch and finished changes there for the user. Announce both paths and the intended destination. When another worktree already has the PR branch checked out, follow the attached-worktree recovery in Source recovery and continue collection in its verified owner. Run ordinary project checks under current host grants on every PR origin. Inspect the command and its current executable inputs when review evidence is unavailable or stale. Resolve suspicious code within the selected scope before running it. Carry an explicit --sandbox through nested review, direct tests, retries, resume and final gates. Use the enforced host boundary under Sandboxed Test Runs when it supplies the required confinement. For independent confinement, pass --sandbox-gate <gate> for each affected command, or --sandbox for an explicit workflow-wide request. A command that cannot run with the requested confinement stays unexecuted. A detached Code Review worktree belongs to its review.
Keep report and reviewer setup subordinate to selected finding closure under the primary-goal rules in Reasoning-Progress Escalation. After selection and root-cause evidence establish an authorized fix, implement it and its regression before another review-preparation cycle. Diagnose an agent-owned setup failure once and attempt one bounded repair; if it fails, stop that auxiliary route and continue safe primary work. Preserve missing review coverage as a factual limitation; do not ask the user to debug reviewer names, commands, or metadata.
Input Schema¶
{
"findings_source": "optional path, explicit list, or review for the current-session assessed review; +review uses the newest matching PR review and performs any needed review recovery or fresh review; +report/report/latest request existing evidence only; omit with a bare PR target to use current online review items",
"mode": "optional report|pr|auto; default auto: pr for bare number, #number, PR URL, or pr_target; otherwise report, which also carries local supplied findings",
"target": "optional shorthand target number, issue/PR URL, path, or current branch",
"pr_target": "optional PR number, PR URL, or current branch PR when mode=pr",
"sandbox": "optional boolean; --sandbox explicitly requires sandboxed code execution for this invocation, including nested review, targeted tests and final gates",
"worktree": "optional boolean; --worktree requests linked-worktree delivery for a PR; default false",
"remediation_scope": "optional all|required|suggestions|critical|high|medium|low|comma-separated severities|comma-separated selection indexes; ask before editing when omitted",
"target_scope": "optional path/module; derive from the admitted target and selected findings when omitted",
"done_when": "selected findings are fixed/resolved and unselected critical/high findings are explicitly deferred"
}
Workflow¶
Follow these phases in order. Load only the current phase and triggered reference sections; do not concatenate all phase references. If a read is truncated, retrieve the missing applicable section before acting on it. Resume at the first unmet checkpoint, retaining valid evidence and prior authorization. Before admitting the target and evidence, read Fail-fast Rules and Quality Gates; these rules apply throughout. Read Output Contract before any status or final response and Calibration Hooks when changing the corresponding behavior. A genuine stop or denial remains authoritative.
Admit target and evidence¶
When following a completed PR review, apply the reviewed execution decision before executing code. The invocation’s explicit --sandbox always wins, including when metadata.code_safety says safe at the same SHA. An authenticated ordinary decision covers the verified inputs. An inspect decision requires fresh inspection of this command. Reassess after a fix or merge and confine a command whose concrete execution risk persists. Honor any retained integrity hold first.
For fresh PR remediation and resumption of ordinary source work, follow Review checkout scheduling after PR State Preflight and before the first run or checkout write. For in-place delivery, acquire the checkout writer claim before the PR target claim and retain it through delivery. Linked-worktree delivery uses its own checkout. Claim the canonical PR for ordinary work. The resumed source-drift exception acquires the applicable claims before its guarded pull. For protected operations, follow the shared scheduling procedure to exchange the target claim for repository-wide exclusivity and revalidate on admission. Only Code Remediate invoked with the explicit +review argument can start or resume Code Review. On resume, retain that same invocation and target. Its nested Code Review inherits the parent’s owner and current claims. Only the acquiring parent transitions or releases them after writers finish or records the required inspection hold.
Read intake.md. For an unfinished report from the same verified in-place or linked delivery, apply intake's local report-only recovery before PR State Preflight. Recover checkout ownership and reverify delivery under the slot before any handoff write. Otherwise preflight the PR before creating a run or looking up evidence; normalize input and admit exact requested evidence under the documented source and freshness rules. For +review with missing, incomplete, stale, or unstarted review evidence, invoke the owning Code Review workflow using the already authorized update, resume, or fresh review route, subject to its actual permission, independence, retry, and recovery boundaries. When Code Review prepares its reviewer calls, execute the admitted dispatch under its coverage and checkout rules in this turn. Keep the parent’s claims through this work under the scheduling procedure. Admit its exact returned result through the normal validator, then continue this remediation. An incomplete checkpoint, successful collection, or completion of Code Review alone is not a terminal remediation outcome. +report and explicit report paths do not authorize a new review; preserve their decision and stop boundaries.
Collect and select findings¶
Read selection.md. Collect verified source and online items as applicable, establish target intent and resolve authorized integration, normalize findings, and obtain the required resolution scope before edits. Bare PR remediation checks online claims against current source even when their recorded revision is older; age alone requires no review-choice question. Preserve the documented source and selection decisions, including the explicit available-findings choice where required.
Inventory preparation is authorized before the user selects findings. Once intake and integration checks pass, retain any applicable checkout claims, reconcile the admitted findings with the collected online items, and freeze the selection inventory in this turn. If selectable work lacks an explicit scope, deliver the scope question before waiting. A status update saying findings await selection does not deliver that question.
Implement and verify¶
Read implementation.md. Build the work bucket plan, implement selected source-confirmed work, verify closure and run the required shared quality gates. Record unresolved findings and retain evidence for each outcome. Do not treat report or reviewer preparation as a substitute for selected fixes and their regression checks. After a scope answer or on resume, complete any missing commit preference through the upfront decision packet. With the applicable decisions recorded, write the work plan, run its preflight and carry out the selected fixes in the eligible execution mode. Reading planning instructions or helper help leaves that work with the agent.
Finalize, commit, and deliver¶
After the preceding applicable execution and verification checkpoints, or a genuine documented stop, read the finalization and delivery procedures in completion.md. Validate the result artifact, apply the selected commit decision and worktree delivery requirements, and report actual outcomes and limits. Its throughout rules remain active from entry. Incomplete reporting cannot replace an available authorized execution step.