$npx -y skills add Borda/AI-Rig --skill code-remediateCodex-native code-remediation loop: triage/apply code-review findings, rerun checks, publish unresolved gaps with measurable gates; $code-remediate #123 +review remediates a PR from latest matching code-review artifact.
| 1 | # Code Remediate |
| 2 | |
| 3 | Run linear code remediation to close findings. |
| 4 | |
| 5 | ## Input Schema |
| 6 | |
| 7 | ```json |
| 8 | { |
| 9 | "findings_source": "optional path, explicit list, or +review/+report/report/latest to auto-select the newest matching review report", |
| 10 | "mode": "optional report|pr|auto; infer pr for bare number, #number, or PR URL", |
| 11 | "target": "optional shorthand target number, issue/PR URL, path, or current branch", |
| 12 | "pr_target": "optional PR number, PR URL, or current branch PR when mode=pr", |
| 13 | "remediation_scope": "optional all|critical|high|medium|low|comma-separated severities|comma-separated selection indexes; ask before editing when omitted", |
| 14 | "target_scope": "required path/module", |
| 15 | "done_when": "selected findings are fixed/resolved and unselected critical/high findings are explicitly deferred" |
| 16 | } |
| 17 | ``` |
| 18 | |
| 19 | ## Workflow (Exact Commands) |
| 20 | |
| 21 | ### 01: Create Run Directory |
| 22 | |
| 23 | Run `python PLUGIN_ROOT/shared/create_run.py --skill code-remediate` once. Retain its single printed path as |
| 24 | `<run-directory>` and substitute that literal path into every later artifact path and helper argument. Never store or |
| 25 | reuse the path through a shell variable; shell variables do not persist across tool calls. |
| 26 | |
| 27 | ### 02: Normalize Shorthand Input And Copy Findings Source |
| 28 | |
| 29 | Shorthand rules: |
| 30 | |
| 31 | - Canonical in-session: `$code-remediate #123 +review` => `mode=pr`, `PR_TARGET=123`, `FINDINGS_SOURCE=latest-matching-review-report`. |
| 32 | - Compatibility alias: `$code-remediate #123 +report` => `mode=pr`, `PR_TARGET=123`, `FINDINGS_SOURCE=latest-matching-review-report`; `$code-remediate #123 +report compatibility alias` has same report lookup. |
| 33 | - Natural-language aliases: `remediate 123 report`, `remediate #123 report`, and `remediate PR 123 report` => `mode=pr`, `PR_TARGET=123`, `FINDINGS_SOURCE=latest-matching-review-report`. |
| 34 | - `remediate <github-pr-url> report` => `mode=pr`, `PR_TARGET=<github-pr-url>`, `FINDINGS_SOURCE=latest-matching-review-report`. |
| 35 | - If `+review`, `+report`, `report`, `latest`, `latest-report`, or `review-report` replaces a path, find newest `.reports/codex/code-review/*/result.json` whose sibling `pr.json` has same PR number/URL as `PR_TARGET`. |
| 36 | - No matching code-review report => fail with direct instruction to run `$code-review <target>` first or supply report path. |
| 37 | - Multiple matches => use newest timestamped directory; record selected path in `<run-directory>/findings-input.txt`. |
| 38 | |
| 39 | For `latest-matching-review-report`, inspect `python PLUGIN_ROOT/shared/find-review-report.py --help`, resolve `PR_TARGET` against `.reports/codex/code-review`, assign printed path to `FINDINGS_SOURCE`. |
| 40 | |
| 41 | Copy the exact bytes from the retained findings-source path to `<run-directory>/findings-input.txt` with the |
| 42 | filesystem tool. Do not depend on a shell variable retaining that source path. |
| 43 | |
| 44 | For `mode=pr`, inspect `python PLUGIN_ROOT/shared/collect_pr.py --help`; collect `PR_TARGET` into `<run-directory>/pr` with checkout enabled for current online evidence, target/head refresh, local checkout. |
| 45 | |
| 46 | Helper records `gh pr checkout` without `--force` in `<run-directory>/pr/local-checkout.json`. |
| 47 | |
| 48 | Findings intake: review report plus `<run-directory>/pr/comments.json`, `<run-directory>/pr/reviews.json`, `<run-directory>/pr/review-threads.json`, `<run-directory>/pr/unresolved-review-threads.json`. Review report is closure contract, not only code findings: before editing normalize report findings, failed `checks_failed`, `follow_up`, `review_decision.required_next_work`, confidence gaps, confidence-recovery remaining limits, and no-finding residual risks into report-origin action items. Use local checkout in `<run-directory>/pr/local-checkout.json` as authoritative source for code triage/edits. `<run-directory>/pr/target-branch.json` must prove base/target fetch before conflict/review-item resolution; `<run-directory>/pr/pr-head-fetch.json` records same-repo PR refresh or cross-repository skip rationale. Checkout artifacts include `force_policy`; if checkout fails or does not match PR head, record `forced-checkout-not-attempted` and stop before forced retry. If online collection, target refresh, or checkout fails, record failure; continue with supplied report only when user accepts stale online-review coverage and no code edits are required, else fail. Never inspect/edit PR code from `curl`, `raw.githubusercontent.com`, or copied `head-files/` snapshots; raw-file snapshot rejection: snapshots are rejected. |
| 49 | |
| 50 | ### 03: Understand PR Intent, Then Resolve Merge Conflicts |
| 51 | |
| 52 | For `mode=pr`, required before `action-items.md`, `resolution-scope.md`, or report/PR-review code changes. Establish clean PR and latest target implementation before conflict markers make worktree noisy. |
| 53 | |
| 54 | Read `remote_ref` from `<run-directory>/pr/target-branch. |