audit
Use to audit a whole codebase (the entire repository by default, or a specified package or path) with the native review panel, then fix the actionable findings and put them up as pull requests using the project's version control or stacking tool (GitButler or plain git). Triggers on requests to audit the repo or a crate or package and open fixes for what it finds. Like review-loop, but scoped to standing code and shipping the fixes as PRs.
- License 许可
- MIT
- 所属仓库
- 0xgleb/dotconfig
- 最近更新
- 2026-11-14
- Stars
- ★ 3
- Forks
- 0
01 前言 Front Matter
- name
- audit
- description
- Use to audit a whole codebase (the entire repository by default, or a specified package or path) with the native review panel, then fix the actionable findings and put them up as pull requests using the project's version control or stacking tool (GitButler or plain git). Triggers on requests to audit the repo or a crate or package and open fixes for what it finds. Like review-loop, but scoped to standing code and shipping the fixes as PRs.
- allowed-tools
- Bash(git:*), Bash(gh:*), Bash(but:*), Bash(direnv:*), Bash(command:*), Bash(cargo:*), Bash(nix:*), Bash(mkdir:*), Bash(cat:*), Bash(mktemp:*), Bash(rm:*), Bash(test:*), Bash(grep:*), Bash(wc:*), Bash(date:*), Bash(basename:*), Bash(find:*), Read, Write, Edit, Agent, Workflow, AskUserQuestion, Skill
- argument-hint
- [ "package-or-path" ]
- user-invocable
- true
03 SKILL.md 正文
Audit a whole codebase with the same native panel the rest of the review stack
uses, then fix what it finds and put the fixes up as PRs. Where
/review-pr, /review-loop, and /review-sweep review a diff, this
reviews standing code — the whole repo, or a package/path you name — and,
like /review-loop, fixes the findings; but instead of leaving fixes
uncommitted it opens one PR per coherent fix-cluster using whatever VCS/stacking
tool the repo uses.
The review engine is the shared ~/.claude/skills/review-core/SKILL.md. The
fix discipline (triage, surgical fixes, compile gate, delta re-review,
discovered check command) is /review-loop's. The tool detection and stack
primitives are /review-sweep's. This skill adds only: a whole-repo scope
(via a synthetic diff) and a branch-per-cluster, open-a-PR action.
Follow these steps precisely.
1. Resolve the audit scope
$ARGUMENTS is an optional package or path. With no argument — the common case
— audit the whole repository. A whole-repo audit is the intended default: it
is expected to be large, and size alone is NEVER a reason to stop and ask. Chunk
hard (step 5) and proceed. The only scope-related stop-and-ask is a named
scope that fails to resolve (below); an unscoped invocation always runs the
whole repo.
repo_root=$(git rev-parse --show-toplevel 2>/dev/null || pwd)
scope="${ARGUMENTS:-.}" # dir / crate dir / pathspec under repo_root; "." = whole repo
If $ARGUMENTS names a thing that is not a path (a bare crate name), resolve it
to its directory before continuing; if it cannot be resolved under the repo,
stop and ask rather than auditing everything by accident.
2. Detect the VCS/stacking tool and preflight
The action opens branches and PRs, so detect the tool (same as /review-sweep).
Complete the directory-ignore preflight before requiring a clean tree or writing
artifacts.
git_common_dir=$(git -C "$repo_root" rev-parse --path-format=absolute --git-common-dir)
main_root=$(git -C "$repo_root" worktree list --porcelain | sed -n 's/^worktree //p' | head -n1)
if [ "$repo_root" != "$main_root" ]; then tool=git
elif [ -d "$git_common_dir/gitbutler" ]; then tool=gitbutler
else tool=git
fi
trunk=$(git -C "$repo_root" symbolic-ref refs/remotes/origin/HEAD --short 2>/dev/null | sed 's#^origin/##' || echo master)
start_branch=$(git -C "$repo_root" rev-parse --abbrev-ref HEAD) # return here at the end
GitButler is main-worktree-only; every linked, isolated, or scratch worktree
uses plain Git without probing but. In a verified GitButler main worktree,
confirm workspace mode (but status ok) as /review-sweep does.
Apply GLOBAL_AGENTS.md's directory-ignore preflight, including state capture
and separate repair accounting, before the clean-tree gate or any artifact
write. This preflight also applies to a zero-finding audit.
After accounting for the repair, require a clean working tree/index; stop and
report any remaining unrelated changes without discarding them. Fix clusters
start from clean branches off trunk. Recheck ignore coverage after each checkout
transition, including returning to start_branch, before using either
directory. Follow the same global preflight at each transition rather than
carrying an unaccounted repair between fix clusters.
3. Prepare the workspace and build the audit target
Render the scoped tree as an all-additions diff against the empty tree so the diff-centric engine can audit standing code. Gitignored paths drop out for free; exclude the tracked lockfiles.
invocation_id=$(uuidgen) || exit 1
safe_scope=$(echo "$scope" | tr '/. ' '___')
out_dir="$repo_root/.tmp/agent-local-ctx/reviews/audit-${invocation_id}-${safe_scope}"
After step 2's preflight covers this invocation path, create and record its resolved absolute directory through the registered harness tool:
{ "action": "create_directory", "path": "<resolved absolute out_dir>" }
Use artifact_provenance or an available registered harness equivalent. Require
successful creation/recording before writing descendants; the recorded directory
covers them. Add crossWorkspace: true only for an explicitly authorized target
outside the tool session's workspace. Do not substitute raw mkdir.
empty=$(git -C "$repo_root" hash-object -t tree /dev/null) # canonical empty-tree object
git -C "$repo_root" diff "$empty" HEAD -- "$scope" \
':(exclude)*.lock' ':(exclude)Cargo.lock' ':(exclude)flake.lock' \
':(exclude)**/.env*' ':(exclude)**/credentials*' ':(exclude)**/secrets*' \
':(exclude)**/.ssh/**' ':(exclude)**/.aws/**' ':(exclude)**/.gnupg/**' \
':(exclude)**/*.key' ':(exclude)**/*.pem' ':(exclude)**/*.p12' \
':(exclude)**/*.pfx' ':(exclude)**/*.crt' ':(exclude)**/*.cer' > "$out_dir/diff.patch"
git -C "$repo_root" diff --name-status "$empty" HEAD -- "$scope" \
':(exclude)*.lock' ':(exclude)Cargo.lock' ':(exclude)flake.lock' \
':(exclude)**/.env*' ':(exclude)**/credentials*' ':(exclude)**/secrets*' \
':(exclude)**/.ssh/**' ':(exclude)**/.aws/**' ':(exclude)**/.gnupg/**' \
':(exclude)**/*.key' ':(exclude)**/*.pem' ':(exclude)**/*.p12' \
':(exclude)**/*.pfx' ':(exclude)**/*.crt' ':(exclude)**/*.cer' > "$out_dir/files.txt"
wc -l "$out_dir/diff.patch"
Apply these credential/private-key/certificate exclusions before retrieving contents or even generating the file manifest. Use the identical exclusions for every chunk-generation command and context search; Git tracking/ignore status is not evidence that a file is safe. Never collect first and redact afterward. Report protected paths as excluded, not reviewed.
Refuse on an empty target. A whole repo is large, so this leans hard on chunking
(step 5) — large is expected, not a blocker. Do not stop for size confirmation
on an unscoped audit: the whole repo is the intended default, so chunk and
proceed. A one-line heads-up that it is a long, token-heavy run is fine (and you
may note that /audit crates/NAME is a cheaper way to focus a follow-up), but
size alone never gates the run — only an explicit user "stop" does. (Audit
HEAD by default; drop HEAD from the git diff to audit the working tree
instead.)
4. Load project context and the check command
find "$repo_root" -maxdepth 3 \( -name "CLAUDE.md" -o -name "AGENTS.md" \) \
-not -path "*/node_modules/*" -not -path "*/target/*"
Keep the paths for docsPaths. Discover the project's check command exactly as
/review-loop step 3 does (declared in the docs or a task-runner target) and
record it as check_cmd; if none is declared, leave it empty and skip the check
steps. The engine's "author description" is the audit intent:
"Full audit of SCOPE: assess correctness, security, concurrency, and maintainability of the standing code."
5. Run the review engine
Run the shared engine (review-core steps 1–7) with these contract inputs:
| Contract input | Value for audit |
|---|---|
out_dir, {DIFF_PATH}, {FILES_PATH}, {REPO_ROOT} |
from steps 3 ($out_dir/diff.patch, $out_dir/files.txt) |
{PROJECT_DOCS_PATHS} |
the docs paths from step 4 |
{PR_DESCRIPTION} |
the audit-intent sentence from step 4 |
{SOURCE_ACCESS} |
Read source files directly from the working tree, which is the code under audit. |
{SCOPE_NOTE} |
This is a full audit, not a change review: the diff renders the entire scoped codebase as additions, so ALL of it is standing code under audit. "Pre-existing, on lines the diff did not modify" does not apply — everything shown is in scope. |
{INSPECTOR_ARG} |
empty string |
{REPORT_HEADER} |
# Audit — SCOPE\n**Repo:** REPO_ROOT\n**Commit:** HEAD_SHA\n**Files:** N\n**Size:** LOC lines |
{TERMINAL_HEADER} |
Audit — SCOPE\nN files, LOC lines |
{SYNTHESIS_EXTRA} |
empty string |
{INCLUDE_ATTRIBUTION} |
true |
Chunk HARDER than a review — that is the whole point of audit-vs-review. A review sees a small diff; an audit sees the entire tree, so split aggressively for maximum parallelism: aim for ~1,500-2,000 lines per chunk (not review-core's ~3,500 review default), and give a single large file its own chunk rather than bundling it. Group by crate / directory / feature so each chunk is coherent. Generate each chunk's diff with the same empty-tree command plus a path filter, duplicate the reviewer lanes per chunk, and run the context-selected inspectors (review-core step 3 — only the languages actually present) once over the full target. Pass ALL chunk lanes to one workflow invocation: the executor caps real concurrency, but more, smaller chunks keep every slot busy and keep each reviewer well within quality range. Scale up rather than down — a large repo wants dozens of lanes, not a handful. Report the chunk plan first.
Usage limits / native-only: if step 1 lands on native-only (typical on
limit-blown days), batch workflow passes (~40 lanes each) for whole-repo audits.
Tell the user once; do not re-probe. /review-pr-scale diffs run one
native-only pass — five reviewers + inspectors is sufficient.
The engine writes review.md / findings.json and prints the summary. Only
status: completed with empty findings establishes a clean audit. A missing
or failed required native inspector/reviewer/verifier/synthesis phase is
incomplete, not a clean result; retain evidence and finish the missing
authorized work.
6. Triage
Triage the returned findings with /review-loop's bias-to-fix table (severity
- verdict + confidence → auto-fix / discuss / auto-dismiss). The verifier already dropped invalid and out-of-scope findings. For an audit, defer-by-default is fine for low-value findings — a whole-repo audit surfaces more than is worth a PR; fix the ones that clearly should be fixed, and offer the rest as a list.
Verified violations of required code conventions are not optional style nits. Include the general style lane and relevant language/typing lanes from the shared engine. Fix bounded spacing/import repairs and justified identifier/error-model corrections in the authorized fix clusters rather than deferring them as cosmetic; preserve behavior, genuine namespace ambiguity and error context. Normal check/re-review gates still apply. PR-plan confirmation applies only when publication scope is not already authorized by the global-resource workflow.
7. Plan the PRs and confirm
Cluster the fix-now findings into coherent, independently reviewable PRs — group by crate/module/theme so each PR is small, revertable, and tells one story; never one giant PR. Audit findings are usually unrelated, so default to independent sibling branches off trunk (one PR each); use a stack only when a fix genuinely depends on another.
Print the plan and confirm before creating anything (opening multiple PRs is a large outward action — this is the one place to stop for input):
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Audit fix plan — <tool> · <N> PRs off <trunk>
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1. fix/settlement-rounding crates/settlement (2 findings: 1 critical, 1 high)
2. fix/auth-check-admin crates/api (1 finding: high)
...
Deferred (offered, not fixed): 6 lower-value findings
Use AskUserQuestion to confirm: create all, a subset, file the deferred ones
as issues instead, or stop. Do not create PRs until the user picks, unless the
exact scoped global-resource branch/PR workflow is already authorized by
GLOBAL_AGENTS.md. In that case record the bounded plan and execute it without
another approval round; do not add unrelated clusters or external effects.
8. Deliver one PR per cluster
For each confirmed cluster (return to trunk/start between independent
clusters):
- Use the cluster's branch. Continue an existing unmerged branch/PR for follow-up corrections, checking later stacked changes before revising an earlier version. For a new independent cluster, create a virtual branch in a verified GitButler workspace, or a plain-Git branch off trunk. A new prompt or session is not a reason to duplicate ongoing work.
- Apply only this cluster's fixes with
/review-loop's fix discipline: read the source, re-verify each finding, make surgical fixes and add required behavior tests. Use scoped file/hunk assignment to keep unrelated changes off the branch. Draft status never excuses mixed commits, branches or PRs. - Publish checkpoints continuously. Commit and push the first scoped checkpoint and open a self-assigned draft PR through the repository's authorized workflow; update an existing PR instead of creating a duplicate. Keep normal hooks. Incomplete code or failing checks can be checkpointed in that correctly scoped draft with their status stated accurately. Commit and push each completed unit before starting another.
- Verify the published head. Run the scoped compile gate, delta re-review and the project's required checks, including required CI when applicable. Local checks suffice when the repository uses local verification instead of CI. Agent reviews do not replace required checks; failed, pending or unverified checks keep the PR draft.
- Keep the description current. Use the repository's PR template, or Motivation / Solution when none exists. Explain the problem and solution without private attribution or an AI-process journal.
- Mark completed PRs ready. Once the cluster is complete and its required
checks pass for the published head, run
gh pr ready <number>or the repository's equivalent and verify the resulting state. This applies to all authorized audit-fix PRs, not only global resources; do not invent a second approval gate. Honor an explicit owner instruction to retain a draft. Otherwise continue unfinished scoped work or report its concrete blocker; do not call a still-draft delivery complete.
Never merge or override branch protection.
9. Return and summarize
Return to start_branch (plain Git: git checkout; GitButler: nothing to
restore). Print the summary:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Audit delivery — <tool> · <N> PRs ready · <M> drafts blocked
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
#123 fix/settlement-rounding <url> ready; closes 2 findings
#124 fix/auth-check-admin <url> draft; required check failing
Deferred (not fixed): 6 findings — say the word to file them as issues.
Full report: <path to review.md>
For deferred findings the user wants filed, use GitHub issues
(gh issue create), one issue per finding with a problem-only description. Show
each exact draft and obtain confirmation before creating it.
Hard rules
- Deliver verified PRs, not permanent drafts. Publish scoped draft checkpoints, then mark each PR ready once its work and required checks pass for the published head, unless the owner explicitly requires draft-only delivery. Self-assign; never merge or override branch protection.
- Confirm new publication scope before creating branches/PRs. Do not ask
again for the exact scoped global-resource workflow already authorized by
GLOBAL_AGENTS.md; unrelated extra PRs still need authority. - One coherent, small PR per cluster. Never a single giant PR; group by crate/module/theme; default to independent sibling branches off trunk, stack only on real dependencies.
- Required checks gate readiness, not checkpoint publication. Preserve normal hooks, keep incomplete or failing work draft, and verify the published head before marking ready. Fixes and branch diffs stay scoped to one cluster at every checkpoint; re-verify findings against current source.
- Clean tree after the directory-ignore preflight; never leak unrelated changes into fix branches. Account for owned ignore repairs separately, including zero-finding audits and checkout transitions. Return to the start branch at the end.
- The audit target is a synthetic diff against the empty tree — everything shown is in scope; "pre-existing/out of scope" never applies.
- The review runs as a single
Workflowinvocation per pass (review-core), using read-only authenticatedopenai-codex/gpt-6.1-sollanes through the active harness's classified workflow. Do not launch external model CLIs. - Filing deferred findings is gated: show drafts, confirm, then create. Use GitHub issues with problem-only descriptions.
Failure modes
- Dirty tree — stop; fixes need clean branches off trunk.
- Empty or unresolvable scope — stop and ask; never fall back to the whole repo when a named scope failed to resolve.
- Target large — expected for a whole-repo audit; never a blocker. Chunk hard and proceed; a one-line heads-up is fine, but do NOT stop for confirmation on an unscoped audit. Scoping to a package is an optional cheaper follow-up the user may choose, not a gate.
- A cluster's fix fails to converge or breaks a required check — preserve and publish its scoped checkpoint as a draft with the exact blocker. Do not mark it ready or silently reclassify unfinished work as deferred. Follow the repository's blocked-publication rules before starting another unit.
- A required native lane errors — preserve an incomplete result and its reason. Selected inspectors are required; empty findings do not prove clean.
- The workflow fails mid-run — relaunch with
{scriptPath, args, resumeFromRunId}; completed lanes return cached results. - Not a git repo / no trunk / no
gh— the branch+PR action needs them; tell the user what is missing instead of half-opening a PR. - GitButler not in workspace mode — stop and ask the user to enter it; never switch modes yourself.
04 同仓库更多 Skills
worktree
Manage worktrees only for concurrent work by the owner or agents launched by the owner on the same repository, or for explicitly requested inventory and cleanup; never create one for isolation alone.
unslop
Rewrite draft prose before owner-facing replies, docs, issues, PR text, handoffs, or Telegram reports to remove AI tells while preserving facts, links, tone, and authority; auto-trigger on externally visible prose, but never on code, commands, logs, tool output, quoted sources, or user text.
threat-model-first
Use at the START of a change that moves money, changes balances or custody, touches access control or signing, deserializes untrusted input, adds an external or on-chain integration, or wires an LLM tool. Design-time threat modeling that turns abuse cases into the first failing tests; it precedes the post-hoc security-review pass.
test-inspector
Auto-run for new or changed retained behavior, even without test changes, and for test, fixture, snapshot or mock changes; verify real happy-path and error-path coverage, expose false-confidence assertions and over-mocking, but do not perform general production-code correctness review.
strong-typing-inspector
Lightweight review — flags primitives used where a domain type already exists (e.g. String for a USD field when Usd exists) and missed newtype opportunities.
spec-review
Critique existing specifications and design proposals, including whether their approach or addition is justified, and refine them through adversarial Pi review and authorized author revisions. Not for code review, implementation-plan sequencing, creating a design from scratch or minor copy edits.