This directory holds clawpatch-autofix.sh, a Bash driver behind the
mise run clawpatch:autofix task. The script asks Clawpatch for the next open
finding, runs clawpatch fix until Clawpatch revalidates the finding as
fixed, runs two Codex cleanup passes ($simplify and $deslop), checks the
finding again after each pass, and then asks Codex to commit the result.
CAUTION: The script runs Codex with --dangerously-bypass-approvals-and-sandbox
and tells Codex to "commit everything". It does not check for a clean working
tree first, so uncommitted changes that exist before the run go into the commit.
mise run clawpatch:autofixrunsscripts/clawpatch-autofix.shwith no arguments. Its description is "Fix Clawpatch findings, run Codex cleanup passes, and commit". [mise.toml:tasks."clawpatch:autofix"]scripts/clawpatch-autofix.shtakes no positional arguments and no flags. The top level never reads$@. [clawpatch-autofix.sh:190-197]
| Variable | Default | Effect | Source |
|---|---|---|---|
ROOT |
$(git rev-parse --show-toplevel) |
Repository root. Passed to clawpatch --root, codex exec -C, and git -C. |
[clawpatch-autofix.sh:ROOT] |
MAX_FINDINGS |
1 |
Maximum number of findings processed in one run. | [clawpatch-autofix.sh:MAX_FINDINGS] |
MAX_FIX_ATTEMPTS |
3 |
Maximum clawpatch fix attempts per call to fix_until_fixed. |
[clawpatch-autofix.sh:MAX_FIX_ATTEMPTS] |
MAX_HYGIENE_ROUNDS |
2 |
Maximum fix, simplify, and deslop rounds per finding. | [clawpatch-autofix.sh:MAX_HYGIENE_ROUNDS] |
CODEX_MODEL |
unset | When set, the script adds --model "$CODEX_MODEL" to every Codex call. |
[clawpatch-autofix.sh:codex_one_shot] |
0:next_findingreturned no ID. The script printsno open findings. [clawpatch-autofix.sh:192-195]0: the main loop finishedMAX_FINDINGSfindings. [clawpatch-autofix.sh:190-197]- Non-zero:
fix_until_fixed,process_finding, orcommit_current_changesreturned1, or another unguarded command failed underset -Eeuo pipefail. [clawpatch-autofix.sh:2] [clawpatch-autofix.sh:34] [clawpatch-autofix.sh:154] [clawpatch-autofix.sh:187]
claw: runsclawpatch --root "$ROOT" "$@". [clawpatch-autofix.sh:claw]codex_one_shot <prompt>: runscodex exec -C "$ROOT"with--dangerously-bypass-approvals-and-sandbox, an optional--model "$CODEX_MODEL", and the prompt. Stdin comes from/dev/null. [clawpatch-autofix.sh:codex_one_shot]commit_current_changes: sends Codex the prompt "commit everything to git. Do not push or open a pull request." Returns1ifgit status --porcelainstill shows changes. [clawpatch-autofix.sh:commit_current_changes]finding_id: reads JSON on stdin and prints.finding.id // .id. [clawpatch-autofix.sh:finding_id]finding_status: reads JSON on stdin and prints.outcome // .status // .finding.status. [clawpatch-autofix.sh:finding_status]finding_details_file <id>: builds or fetches the finding details JSON once per run and prints its path. [clawpatch-autofix.sh:finding_details_file]finding_title <id>: prints the finding title, oruntitled finding. [clawpatch-autofix.sh:finding_title]print_finding_summary <id>: prints title, severity, feature, description, recommendation, and evidence lines. [clawpatch-autofix.sh:print_finding_summary]next_finding: runsclawpatch next --jsonand prints the finding ID. [clawpatch-autofix.sh:next_finding]revalidate <id>: runsclawpatch revalidate --finding <id> --jsonand prints the status. [clawpatch-autofix.sh:revalidate]fix_until_fixed <id>: runsclawpatch fixandrevalidateup toMAX_FIX_ATTEMPTStimes. [clawpatch-autofix.sh:fix_until_fixed]process_finding <id>: runs fix,$simplify, revalidate,$deslop, revalidate, then commit, up toMAX_HYGIENE_ROUNDStimes. [clawpatch-autofix.sh:process_finding]
- None.
set -Eeuo pipefailis on. Unset variables and unguarded failing commands stop the script. [clawpatch-autofix.sh:2]- A fix attempt succeeds only when
revalidateprints exactlyfixed. [clawpatch-autofix.sh:fix_until_fixed] process_findingcallsfix_until_fixedwithout a guard. Underset -e, a finding that is still notfixedafterMAX_FIX_ATTEMPTSends the whole run with a non-zero exit, so no later hygiene round or finding runs. [clawpatch-autofix.sh:166] [clawpatch-autofix.sh:2]- The script commits a finding only after
revalidateprintsfixedafter the$simplifypass and again after the$desloppass. Any other status starts the next hygiene round. [clawpatch-autofix.sh:process_finding] - A commit counts as done only when
git status --porcelainis empty after the Codex commit call. [clawpatch-autofix.sh:commit_current_changes] - Codex always runs with stdin from
/dev/null. [clawpatch-autofix.sh:codex_one_shot] - The commit prompt tells Codex not to push and not to open a pull request. [clawpatch-autofix.sh:commit_current_changes]
- The temporary directory is removed on exit by
trap 'rm -rf "$tmpdir"' EXIT. [clawpatch-autofix.sh:10] - The script does not check for a clean working tree at start, and does not
check that
clawpatch,codex,jq, orgitexist. A missing tool fails at its first use. [clawpatch-autofix.sh:1-10]
- Creates a temporary directory with
mktemp -dand writesnext.json,fix-<id>.json,revalidate-<id>.json, andfinding-details-<id>.jsoninto it. [clawpatch-autofix.sh:9] [clawpatch-autofix.sh:next_finding] [clawpatch-autofix.sh:fix_until_fixed] [clawpatch-autofix.sh:revalidate] [clawpatch-autofix.sh:finding_details_file] - Reads
$ROOT/.clawpatch/findings/<id>.jsonand$ROOT/.clawpatch/features/<featureId>.jsonwithjq. If the finding file is missing, runsclawpatch show --finding <id> --jsoninstead. [clawpatch-autofix.sh:finding_details_file] - Runs these Clawpatch commands against
$ROOT:clawpatch next --json,clawpatch fix --finding <id> --skip-git-repo-check --json, andclawpatch revalidate --finding <id> --json. [clawpatch-autofix.sh:next_finding] [clawpatch-autofix.sh:fix_until_fixed] [clawpatch-autofix.sh:revalidate] - Runs Codex in
$ROOTwith approvals and the sandbox disabled, using the literal prompts$simplifyand$deslop. The single quotes stop shell expansion. [clawpatch-autofix.sh:168] [clawpatch-autofix.sh:175] [clawpatch-autofix.sh:codex_one_shot] - Creates git commits through Codex. The script itself runs only
git rev-parse,git status --porcelain, andgit status --short. [clawpatch-autofix.sh:ROOT] [clawpatch-autofix.sh:commit_current_changes] - Leaves edits in the working tree when a finding fails. The script contains no
git reset,git checkout, orgit stash. [clawpatch-autofix.sh:1-197] - Prints to stdout: progress lines that start with
==>, the finding summary fromprint_finding_summaryin the first hygiene round, andno open findings. Prints failure messages plusgit status --shortoutput to stderr. [clawpatch-autofix.sh:fix_until_fixed] [clawpatch-autofix.sh:process_finding] [clawpatch-autofix.sh:print_finding_summary] [clawpatch-autofix.sh:193] [clawpatch-autofix.sh:commit_current_changes] - Makes no direct network calls. Network use by
clawpatchandcodexis not visible in this script. [clawpatch-autofix.sh:1-197]
- Run:
bash -n scripts/clawpatch-autofix.sh(syntax check only). The repository has no tests and no shell linter task for this script. - Runner:
mise run clawpatch:autofix. CAUTION: This runs Clawpatch and Codex with the sandbox disabled, edits files, and creates git commits. Run it only on a branch where those commits are wanted.