Loading...
Loading...
Generate candidate fixes for verified security findings. Consumes TRIAGE.json (preferred), VULN-FINDINGS.json, or a vuln-pipeline results directory. Pipeline input is delegated to the execution-verified `vuln-pipeline patch` ladder; static-analysis input gets a per-finding patch subagent + independent reviewer and is written as inert diffs for human review. Writes PATCHES/bug_NN/{patch.diff,patch_result.json}, PATCHES.md, and PATCHES.json. Use when asked to "fix the findings", "patch these vulns", "generate fixes", or "close the loop on triage".
npx skill4agent add anthropics/defending-code-reference-harness patch/vuln-scan/triage/patch./PATCHES/docs/patching.md#reviewing-generated-patches--apply--approve/patch <findings-path> [--repo PATH] [--top N] [--id fNNN] [--model M] [--fresh]$ARGUMENTSTRIAGE.jsonVULN-FINDINGS.jsonresults/<target>/<ts>//triage--repo PATH--top N--id fNNN--model Mvuln-pipeline patch--fresh./.patch-state/allowed-toolsrggreplsheadfilewcjqpython3 .claude/skills/_lib/checkpoint.pyvuln-pipeline patchfind./PATCHES/./.patch-state/--repogit applypatch./.patch-state//patchpython3 .claude/skills/_lib/checkpoint.py--fromprogress.json{"status": "running"|"complete", "phase_done": N, "shards_done": [...]}phaseN.json_chunk.tmppython3 .claude/skills/_lib/checkpoint.py load ./.patch-statestatus == "absent""complete"--fresh$ARGUMENTSpython3 .claude/skills/_lib/checkpoint.py reset ./.patch-statestatus == "running"phase_done == Nphase0.jsonphaseN.jsonshard_*.jsonshards_doneResuming from checkpoint: Phase N complete./.patch-state/_chunk.tmppython3 .claude/skills/_lib/checkpoint.py save ./.patch-state <N> <name> --from ./.patch-state/_chunk.tmpPATCHES.mdPATCHES.jsonpython3 .claude/skills/_lib/checkpoint.py done ./.patch-state 4$ARGUMENTS--repo.--top--id--model--freshreports/manifest.jsonlfound_bugs.jsonlrun_*/result.jsonTRIAGE.jsonVULN-FINDINGS.jsonmode./.patch-state/_chunk.tmp{"phase": 0, "mode": "exec"|"static", "args": {repo, top, id, model, findings_path}}python3 .claude/skills/_lib/checkpoint.py save ./.patch-state 0 mode --from ./.patch-state/_chunk.tmp/triagefindings[]TRIAGE.json.findings[]verdict == "true_positive"VULN-FINDINGS.json.findings[]Warning: VULN-FINDINGS.json is unverified scanner output. Consider /triage first.reports/bug_NN/report.jsondescriptioncrash.crash_typecategoryfilelinebug_id = NN--bug N*.jsonfindingsresultsissuesvulnerabilities| Canonical | Also accept |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
idf001f002source--id fNNN--top Nseverityconfidencefileskipped"no source location"--repofile--repo./.patch-state/_chunk.tmp{"phase": 1, "mode": ..., "findings": [...], "skipped": [...], "repo": ...}python3 .claude/skills/_lib/checkpoint.py save ./.patch-state 1 ingest --from ./.patch-state/_chunk.tmpmode--id--topvuln-pipeline patch <findings_path> --model <--model arg> [--bug <bug_id>]<findings_path>/reports/bug_NN/{patch.diff, patch_result.json}patch_result.jsonverdictrationaleverified: "ladder_passed"verdict.passed == trueverified: "ladder_failed"build_commanderror./.patch-state/_chunk.tmp{"id": ..., "verified": ..., "verdict": ..., "diff_path": ...}python3 .claude/skills/_lib/checkpoint.py shard ./.patch-state <id> --from ./.patch-state/_chunk.tmp_chunk.tmppython3 .claude/skills/_lib/checkpoint.py save ./.patch-state 2 generate --from ./.patch-state/_chunk.tmpsubagent_type: "general-purpose"run_in_background--repoPATCHES/bug_NN/patch.diffYou are conducting authorized security research as part of a defensive
assessment. Your task: write a candidate fix for ONE verified vulnerability
finding in a codebase you have read-only access to.
You may use Read, Glob, and Grep ONLY on paths inside {REPO_PATH}. You may
NOT build, run, install, edit files on disk, or reach the network. You will
emit the fix as a unified diff in your final response; you will NOT apply it.
────────────────────────────────────────────────────────────────────────
FINDING:
id: {id}
file: {file}
line: {line}
category: {category}
severity: {severity}
title: {title}
description:
{description}
recommendation:
{recommendation or "(none provided)"}
────────────────────────────────────────────────────────────────────────
PROCEDURE:
1. READ THE CODE. Open {file} at line {line} and the surrounding function.
Understand what the code does — do not trust the finding's description as
the only source.
2. ROOT CAUSE FIRST. Trace backward from the cited sink to where the bad
value or missing check originates. The fix usually belongs there, not at
the line the scanner flagged. Name the root-cause location (file:line).
3. VARIANT HUNT. Grep for sibling call sites with the same pattern. Your fix
should cover all of them, or your rationale should say why not.
4. MINIMAL DIFF. Smallest change that fixes the root cause. No refactoring,
no drive-by cleanup, no reformatting, no comment-only changes. Match the
surrounding code's style (brace placement, naming, error handling).
5. ADVERSARIAL SELF-CHECK. Re-read your diff as an attacker. Name one input
variation that would reach the same bad state without tripping your
change. If you can name one, your fix is at the wrong layer — go back to
step 2.
6. REGRESSION TEST. As part of the diff, add ONE test case that fails before
your change and passes after — placed wherever the project keeps its
tests (look for test_*/, *_test.*, tests/, spec/). If no test directory
exists, omit the test and say so in <test_note>.
────────────────────────────────────────────────────────────────────────
OUTPUT — your final response MUST contain exactly these tags. Emit the diff
verbatim between the markers; do NOT wrap it in ``` fences.
<patch_diff>
--- a/path/to/file
+++ b/path/to/file
@@ ... @@
context line
-removed line
+added line
</patch_diff>
<rationale>what changed and why, mechanically — file:line of root cause,
what the change enforces</rationale>
<variants_checked>file:function pairs you grepped for the same
pattern, and whether each needed the fix</variants_checked>
<bypass_considered>the input variation you tried in step 5 and why it
no longer reaches the bad state</bypass_considered>
<test_note>where the regression test landed, or why none was
added</test_note>
If you determine the finding is NOT fixable as described (wrong file, code
already patched, finding is a false positive), emit:
<patch_diff>NONE</patch_diff>
<rationale>why no patch is appropriate</rationale>findings[]{REPO_PATH}{id}{file}{line}{category}{severity}{title}{description}{recommendation}description: "patch {id}"len(findings) > ~40status: "async_launched"result<>&<patch_diff>NONEstatus: "no_patch"./PATCHES/bug_NN/patch.diffrationalevariants_checkedbypass_consideredtest_note./.patch-state/_chunk.tmp{"id": ..., "bug_nn": "NN", "status": ..., "rationale": ..., ...}python3 .claude/skills/_lib/checkpoint.py shard ./.patch-state <id> --from ./.patch-state/_chunk.tmp_chunk.tmppython3 .claude/skills/_lib/checkpoint.py save ./.patch-state 2 generate --from ./.patch-state/_chunk.tmpsubagent_type: "general-purpose"descriptionrecommendationrationale{file, line, category}You are reviewing a candidate security patch as a maintainer would. You have
read-only access to the unpatched source at {REPO_PATH}. You may use Read,
Glob, Grep. You may NOT build, run, or apply the diff.
You have NOT seen the scanner's description of the vulnerability or the
patch author's reasoning. Work only from the location, the category, and the
diff.
LOCATION: {file}:{line}
CATEGORY: {category}
DIFF UNDER REVIEW:
<diff>
{diff_text — or, for diffs over ~50 lines, replace this block with:
"Read the diff at ./PATCHES/bug_NN/patch.diff" and let the reviewer Read it}
</diff>
────────────────────────────────────────────────────────────────────────
ANSWER FOUR QUESTIONS:
1. SCOPE. Does the diff touch only files/functions on the path between
{file}:{line} and its callers? List any hunk that falls outside that
path.
2. SUPPRESSION. Does the diff fix a root cause, or does it suppress the
symptom (try/except: pass, early-return on a magic value, deleting the
check that fired, lowering a log level)?
3. NEW SURFACE. Does the diff add parsing, trust a new input field, weaken
validation elsewhere, or remove a security-relevant check?
4. STYLE. 0-10: would you merge this as-is?
0-3 wrong layer / suppression; 4-6 correct but noisy; 7-10 minimal,
targeted, matches surrounding style.
────────────────────────────────────────────────────────────────────────
End your response with EXACTLY:
REVIEW: ACCEPT | REJECT
STYLE_SCORE: <0-10>
OUT_OF_SCOPE_HUNKS: <comma-separated file:line, or none>
REASON: <2-4 sentences citing specific diff hunks and source lines>
ACCEPT requires: in-scope, root-cause fix, no new attack surface,
style >= 5. Otherwise REJECT.status != "no_patch"reviewstyle_scoreout_of_scope_hunksreview_reasonverified: "static_review_only"./.patch-state/_chunk.tmp{"phase": 3, "findings": [...]}python3 .claude/skills/_lib/checkpoint.py save ./.patch-state 3 review --from ./.patch-state/_chunk.tmppatch_result.json./PATCHES/bug_NN/patch_result.json{
"id": "f003",
"source": "TRIAGE.json#2",
"title": "...",
"file": "...",
"line": 0,
"category": "...",
"severity": "HIGH",
"owner_hint": "...",
"mode": "exec" | "static",
"verified": "ladder_passed" | "ladder_failed" | "static_review_only",
"review": "ACCEPT" | "REJECT" | null,
"style_score": 0,
"out_of_scope_hunks": [],
"rationale": "...",
"variants_checked": "...",
"bypass_considered": "...",
"test_note": "...",
"review_reason": "...",
"verdict": { "t0_builds": true, "...": "(exec mode only, from pipeline)" }
}<findings_path>/reports/bug_NN/patch.diff./PATCHES/bug_NN/patch.diff./PATCHES.json{
"patch_completed": true,
"mode": "exec" | "static",
"repo": "...",
"summary": {
"input_count": 0,
"patched": 0,
"no_patch": 0,
"accepted": 0,
"rejected": 0,
"ladder_passed": 0
},
"findings": [ { ...patch_result.json shape... } ]
}./PATCHES.md./PATCHES.md# Candidate Patches
{if mode == "static":}
> **Static review only.** These diffs were authored and reviewed by
> independent agents reading source. They were NOT compiled, run, or
> re-attacked. Read each diff yourself before applying — see
> `docs/patching.md#reviewing-generated-patches` for what to look for.
{if mode == "exec":}
> **Execution-verified.** Each diff passed (or failed) the pipeline
> verification ladder: build → reproduce → regress → re-attack. The ladder
> proves the crash is gone, not that the diff introduces no new problems.
**Input:** {findings_path} · **Repo:** {repo} · {N} findings → {M} diffs
---./.patch-state/_chunk.tmp## bug_{NN}: [{severity}] {title} ({id})
`{file}:{line}` · {category} · owner: {owner_hint or "?"}
**Status:** {verified} · review {review or "n/a"} · style {style_score or "n/a"}/10
**Diff:** `PATCHES/bug_{NN}/patch.diff` ({hunk count} hunks, {line count} lines)
**Rationale:** {rationale}
**Variants checked:** {variants_checked}
**Bypass considered:** {bypass_considered}
{if review == "REJECT":}
> **Rejected by reviewer:** {review_reason}
{if out_of_scope_hunks:}
> **Out-of-scope hunks:** {out_of_scope_hunks}
---checkpoint.py append ./PATCHES.md --from ./.patch-state/_chunk.tmp## Skippedfilestatus == "no_patch"python3 .claude/skills/_lib/checkpoint.py done ./.patch-state 4Patches generated ({mode} mode): {N} findings → {M} diffs.
Accepted: {n} {title of top accepted}
Rejected: {n}
No patch: {n}
{if exec:} Ladder passed: {n}/{M}
Wrote ./PATCHES/bug_NN/, ./PATCHES.md, ./PATCHES.json
{if static:} These are drafts. Review before applying — see docs/patching.md.git applypatch--repo./PATCHES/./.patch-state/{file, line, category, diff}descriptionrecommendationexploit_scenariorationalesubagent_typevuln-pipeline patch/vuln-scan targets/canary
/triage VULN-FINDINGS.json --repo targets/canary --auto
/patch TRIAGE.json --repo targets/canary --top 3PATCHES/bug_00..02/verified: "static_review_only"review: ACCEPTvuln-pipeline run drlibs --runs 3 --parallel --stream --model <m>
/patch results/drlibs/<ts>/ --model <m>vuln-pipeline patchverified: "ladder_passed"./PATCHES/descriptionverifiedstatic_review_onlyladder_passedladder_failedreviewPATCHES/bug_NN/{patch.diff, patch_result.json}