$npx -y skills add anthropics/defending-code-reference-harness --skill patchGenerate candidate fixes for verified security findings. Consumes
| 1 | # patch |
| 2 | |
| 3 | Third leg of the static pipeline (`/vuln-scan` → `/triage` → `/patch`). |
| 4 | Turns a ranked list of verified findings into candidate diffs. |
| 5 | |
| 6 | The skill **never applies a diff** to the target repo. Output is inert text |
| 7 | in `./PATCHES/` for a human to review and apply out-of-band — see |
| 8 | `docs/patching.md#reviewing-generated-patches`. There is no `--apply` or |
| 9 | `--approve` flag by design: the capability isn't present, so it can't be |
| 10 | prompt-injected into use. |
| 11 | |
| 12 | Invoke with `/patch <findings-path> [--repo PATH] [--top N] [--id fNNN] |
| 13 | [--model M] [--fresh]`. |
| 14 | |
| 15 | **Arguments** (parse from `$ARGUMENTS`): |
| 16 | - findings path (first positional, required): `TRIAGE.json`, |
| 17 | `VULN-FINDINGS.json`, a pipeline `results/<target>/<ts>/` directory, or any |
| 18 | JSON the `/triage` ingest table recognizes. |
| 19 | - `--repo PATH`: target codebase, read-only (default cwd). Required for |
| 20 | static mode; the skill stops if cited files don't resolve under it. |
| 21 | - `--top N`: patch only the N highest-severity true positives (static mode). |
| 22 | - `--id fNNN`: patch only the finding with this id. |
| 23 | - `--model M`: passed through to `vuln-pipeline patch` in execution-verified |
| 24 | mode. Ignored in static mode (subagents inherit the orchestrator's model). |
| 25 | - `--fresh`: ignore `./.patch-state/` checkpoint and start over. |
| 26 | |
| 27 | **Tools.** Prefer Read, Glob, Grep, Write, Task. Some sessions do not |
| 28 | provision Glob or Grep; `allowed-tools` is a permission filter, not a loader. |
| 29 | When they are unavailable, fall back to the read-only Bash commands |
| 30 | whitelisted above: `rg`/`grep` for search, `ls` for enumeration, |
| 31 | `head`/`file`/`wc` for sniffing, `jq` for JSON ingest. Bash is otherwise |
| 32 | permitted only for `python3 .claude/skills/_lib/checkpoint.py` (state I/O) |
| 33 | and `vuln-pipeline patch` (execution-verified delegate). `find` is NOT |
| 34 | permitted. |
| 35 | |
| 36 | **Write scope.** The Write tool may target ONLY paths under `./PATCHES/` and |
| 37 | `./.patch-state/`. Never write into `--repo`, never `git apply`, never |
| 38 | `patch`, never edit target source. If a step seems to require it, the step is |
| 39 | wrong. |
| 40 | |
| 41 | --- |
| 42 | |
| 43 | ## Checkpointing (runs before Phase 0 and after every phase) |
| 44 | |
| 45 | State persists to `./.patch-state/` so a fresh `/patch` session resumes |
| 46 | without re-spawning patch or reviewer subagents. All checkpoint I/O goes |
| 47 | through `python3 .claude/skills/_lib/checkpoint.py` (atomic, JSON-validated). |
| 48 | The Write→`--from` pattern keeps repo-derived bytes out of Bash argv; never |
| 49 | pass payload via heredoc or stdin. |
| 50 | |
| 51 | State files: `progress.json` (single source of truth: `{"status": |
| 52 | "running"|"complete", "phase_done": N, "shards_done": [...]}`), |
| 53 | `phaseN.json`, `_chunk.tmp`. |
| 54 | |
| 55 | **Start of run.** Bash: |
| 56 | `python3 .claude/skills/_lib/checkpoint.py load ./.patch-state` |
| 57 | |
| 58 | - `status == "absent"` OR `"complete"`, OR `--fresh` in `$ARGUMENTS` → |
| 59 | fresh start. Bash: |
| 60 | `python3 .claude/skills/_lib/checkpoint.py reset ./.patch-state`, |
| 61 | proceed to Phase 0. |
| 62 | - `status == "running"` with `phase_done == N` → resume. Read |
| 63 | `phase0.json`..`phaseN.json` in order (and any `shard_*.json` listed in |
| 64 | `shards_done`), merge into working state, print |
| 65 | `Resuming from checkpoint: Phase N complete`, skip to Phase N+1. Do not |
| 66 | re-spawn any subagent whose output is already checkpointed. |
| 67 | |
| 68 | **End of every phase N.** Write tool → `./.patch-state/_chunk.tmp` with the |
| 69 | phase's JSON, then Bash: |
| 70 | `python3 .claude/skills/_lib/checkpoint.py save ./.patch-state <N> <name> --from ./.patch-state/_chunk.tmp` |
| 71 | |
| 72 | **End of run.** After writing `PATCHES.md` and `PATCHES.json`, Bash: |
| 73 | `python3 .claude/skills/_lib/checkpoint.py done ./.patch-state 4` |
| 74 | |
| 75 | --- |
| 76 | |
| 77 | ## Phase 0: Parse arguments and detect mode |
| 78 | |
| 79 | ### 0a. Parse `$ARGUMENTS` |
| 80 | |
| 81 | Extract findings path (first positional), `--repo` (default `.`), `--top`, |
| 82 | `--id`, `--model`, `--fresh`. If no findings path, stop and ask. |
| 83 | |
| 84 | ### 0b. Detect mode |
| 85 | |
| 86 | Inspect the findings path: |
| 87 | |
| 88 | - **execution-verified mode** when the path is a directory containing |
| 89 | `reports/manifest.jsonl` OR `found_bugs.jsonl` OR `run_*/result.json` |
| 90 | (pipeline output) — unless an `INCIDENTS.json` is present anywhere in it: |
| 91 | D&R run dirs also contain |