patchloop 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. patchloop/__init__.py +23 -0
  2. patchloop/api.py +110 -0
  3. patchloop/build.py +118 -0
  4. patchloop/classify.py +137 -0
  5. patchloop/cli.py +370 -0
  6. patchloop/config.py +148 -0
  7. patchloop/detect.py +133 -0
  8. patchloop/doctor.py +207 -0
  9. patchloop/enrich/__init__.py +66 -0
  10. patchloop/enrich/epss.py +65 -0
  11. patchloop/enrich/kev.py +39 -0
  12. patchloop/fixers/__init__.py +1 -0
  13. patchloop/fixers/base.py +20 -0
  14. patchloop/fixers/js_fix.py +288 -0
  15. patchloop/fixers/poetry_fix.py +144 -0
  16. patchloop/fixers/uv_fix.py +118 -0
  17. patchloop/git_ops.py +171 -0
  18. patchloop/github.py +161 -0
  19. patchloop/hints.py +180 -0
  20. patchloop/images.py +208 -0
  21. patchloop/isolate.py +57 -0
  22. patchloop/js/__init__.py +1 -0
  23. patchloop/js/lockfiles.py +237 -0
  24. patchloop/js/manifest.py +121 -0
  25. patchloop/js/ranges.py +130 -0
  26. patchloop/js/registry.py +67 -0
  27. patchloop/js/yarn.py +189 -0
  28. patchloop/lockgraph.py +181 -0
  29. patchloop/models.py +248 -0
  30. patchloop/plan.py +194 -0
  31. patchloop/pr_body.py +253 -0
  32. patchloop/prioritize.py +38 -0
  33. patchloop/proc.py +71 -0
  34. patchloop/py.typed +0 -0
  35. patchloop/pypi.py +60 -0
  36. patchloop/report/__init__.py +1 -0
  37. patchloop/report/console.py +243 -0
  38. patchloop/report/json_out.py +26 -0
  39. patchloop/report/sarif.py +143 -0
  40. patchloop/runner.py +494 -0
  41. patchloop/scanner.py +214 -0
  42. patchloop/sources/__init__.py +1 -0
  43. patchloop/sources/base.py +5 -0
  44. patchloop/sources/imports.py +292 -0
  45. patchloop/sources/merge.py +113 -0
  46. patchloop/sources/osv.py +255 -0
  47. patchloop/specifiers.py +259 -0
  48. patchloop/validate.py +198 -0
  49. patchloop/versions.py +81 -0
  50. patchloop/workspaces.py +142 -0
  51. patchloop/worktree.py +153 -0
  52. patchloop-0.2.0.dist-info/METADATA +388 -0
  53. patchloop-0.2.0.dist-info/RECORD +56 -0
  54. patchloop-0.2.0.dist-info/WHEEL +4 -0
  55. patchloop-0.2.0.dist-info/entry_points.txt +3 -0
  56. patchloop-0.2.0.dist-info/licenses/LICENSE +21 -0
patchloop/worktree.py ADDED
@@ -0,0 +1,153 @@
1
+ """Temporary git worktree from origin/<base_branch>: the developer's checkout is never touched."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import shutil
6
+ from collections.abc import Iterator
7
+ from contextlib import contextmanager
8
+ from dataclasses import dataclass
9
+ from datetime import UTC, datetime, timedelta
10
+ from pathlib import Path, PurePosixPath
11
+
12
+ from patchloop import proc
13
+ from patchloop.proc import ProcResult
14
+
15
+ # Files tools may create while installing / testing; never counted as changes.
16
+ _TOOL_DIRS = {
17
+ ".venv", "__pycache__", ".pytest_cache", ".mypy_cache", ".ruff_cache", ".tox",
18
+ "node_modules", ".yarn", ".pnpm-store", ".next", ".turbo",
19
+ } # fmt: skip
20
+ _TOOL_FILES = (".pnp.cjs", ".pnp.loader.mjs", ".pnp.data.json")
21
+ _TOOL_SUFFIXES = (".pyc", ".egg-info", ".egg-info/")
22
+
23
+
24
+ class WorktreeError(Exception):
25
+ """git could not prepare or clean up the worktree."""
26
+
27
+
28
+ @dataclass(frozen=True)
29
+ class Worktree:
30
+ repo_root: Path
31
+ path: Path
32
+ project_dir: Path
33
+ """The project inside the worktree (repos can hold the project in a subfolder)."""
34
+ project_rel: str
35
+ """Project folder relative to the repo root, '' for the root itself."""
36
+ ref: str
37
+ commit_sha: str
38
+
39
+
40
+ def git(args: list[str], cwd: Path, timeout: float = 120) -> ProcResult:
41
+ return proc.run(["git", *args], cwd=cwd, timeout=timeout)
42
+
43
+
44
+ def _must(result: ProcResult, what: str) -> str:
45
+ if not result.ok:
46
+ detail = (result.stderr.strip().splitlines() or ["no output"])[-1]
47
+ raise WorktreeError(f"{what}: {detail}")
48
+ return result.stdout.strip()
49
+
50
+
51
+ def _base_ref(repo: Path, base_branch: str) -> str:
52
+ remotes = _must(git(["remote"], repo), "git remote").split()
53
+ if "origin" in remotes:
54
+ _must(
55
+ git(["fetch", "--quiet", "origin", base_branch], repo, timeout=300),
56
+ (f"could not fetch origin/{base_branch}"),
57
+ )
58
+ return f"origin/{base_branch}"
59
+ _must(
60
+ git(["rev-parse", "--verify", "--quiet", base_branch], repo),
61
+ (f"no 'origin' remote and no local branch '{base_branch}'"),
62
+ )
63
+ return base_branch
64
+
65
+
66
+ STALE_AFTER = timedelta(hours=6)
67
+
68
+
69
+ def prune_stale(repo: Path, runs_root: Path, now: datetime | None = None) -> list[Path]:
70
+ """Remove worktrees an interrupted PatchLoop run left behind in ``repo``.
71
+
72
+ Only worktrees inside PatchLoop's own runs folder, from runs older than STALE_AFTER
73
+ (the run id starts with its UTC start time), are touched.
74
+ """
75
+ now = now or datetime.now(UTC)
76
+ listing = git(["worktree", "list", "--porcelain"], repo)
77
+ if not listing.ok:
78
+ return []
79
+ removed = []
80
+ root = runs_root.resolve()
81
+ for line in listing.stdout.splitlines():
82
+ if not line.startswith("worktree "):
83
+ continue
84
+ path = Path(line.removeprefix("worktree ")).resolve()
85
+ if root not in path.parents:
86
+ continue
87
+ run_id = path.relative_to(root).parts[0]
88
+ try:
89
+ started = datetime.strptime(run_id[:16], "%Y%m%dT%H%M%SZ").replace(tzinfo=UTC)
90
+ except ValueError:
91
+ continue
92
+ if now - started >= STALE_AFTER:
93
+ git(["worktree", "remove", "--force", str(path)], repo)
94
+ removed.append(path)
95
+ git(["worktree", "prune"], repo)
96
+ return removed
97
+
98
+
99
+ @contextmanager
100
+ def worktree(
101
+ project_root: Path, base_branch: str, dest: Path, keep: bool = False
102
+ ) -> Iterator[Worktree]:
103
+ top = git(["rev-parse", "--show-toplevel"], project_root)
104
+ if not top.ok:
105
+ raise WorktreeError(f"{project_root} is not inside a git repository")
106
+ repo = Path(top.stdout.strip()).resolve()
107
+ rel = project_root.resolve().relative_to(repo)
108
+ ref = _base_ref(repo, base_branch)
109
+ prune_stale(repo, dest.parent.parent)
110
+ dest.parent.mkdir(parents=True, exist_ok=True)
111
+ _must(
112
+ git(["worktree", "add", "--detach", "--quiet", str(dest), ref], repo),
113
+ (f"could not create a worktree from {ref}"),
114
+ )
115
+ try:
116
+ sha = _must(git(["rev-parse", "HEAD"], dest), "git rev-parse")
117
+ project_dir = dest / rel
118
+ if not any((project_dir / m).is_file() for m in ("pyproject.toml", "package.json")):
119
+ raise WorktreeError(
120
+ f"{rel.as_posix() or '.'} has no pyproject.toml or package.json on {ref}"
121
+ )
122
+ project_rel = "" if rel == Path() else rel.as_posix() # keeps dot-folders intact
123
+ yield Worktree(repo, dest, project_dir, project_rel, ref, sha)
124
+ finally:
125
+ if not keep:
126
+ removed = git(["worktree", "remove", "--force", str(dest)], repo)
127
+ if not removed.ok:
128
+ shutil.rmtree(dest, ignore_errors=True)
129
+ git(["worktree", "prune"], repo)
130
+
131
+
132
+ def _is_tool_file(path: str) -> bool:
133
+ parts = PurePosixPath(path).parts
134
+ return (
135
+ any(p in _TOOL_DIRS for p in parts)
136
+ or path.endswith(_TOOL_SUFFIXES)
137
+ or PurePosixPath(path).name in _TOOL_FILES
138
+ )
139
+
140
+
141
+ def changed_files(wt: Worktree) -> list[str]:
142
+ """Tracked changes plus new files git does not ignore, relative to the repo root."""
143
+ result = git(["status", "--porcelain", "--untracked-files=all"], wt.path)
144
+ _must(result, "git status")
145
+ # Porcelain lines are "XY <path>": two status columns, a space, then the path.
146
+ files = [line[3:].strip().strip('"') for line in result.stdout.splitlines() if len(line) > 3]
147
+ return sorted(f for f in files if not _is_tool_file(f))
148
+
149
+
150
+ def allowed_files(wt: Worktree, files: list[str]) -> set[str]:
151
+ """``files`` (relative to the project) as paths relative to the repo root."""
152
+ prefix = f"{wt.project_rel}/" if wt.project_rel else ""
153
+ return {f"{prefix}{f}" for f in files}
@@ -0,0 +1,388 @@
1
+ Metadata-Version: 2.4
2
+ Name: patchloop
3
+ Version: 0.2.0
4
+ Summary: Fix vulnerable dependencies in Python and JavaScript projects: upgrade, test, rescan, one PR.
5
+ Keywords: security,vulnerabilities,cve,dependencies,uv,poetry,npm,pnpm,yarn
6
+ Author: Ayush Kumar Singh
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Environment :: Console
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Operating System :: MacOS
13
+ Classifier: Operating System :: POSIX :: Linux
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Topic :: Security
19
+ Classifier: Topic :: Software Development :: Quality Assurance
20
+ Classifier: Typing :: Typed
21
+ Requires-Dist: httpx>=0.27
22
+ Requires-Dist: packaging>=24.0
23
+ Requires-Dist: pydantic>=2.7
24
+ Requires-Dist: pyyaml>=6.0
25
+ Requires-Dist: rich>=13.7
26
+ Requires-Dist: tomlkit>=0.13
27
+ Requires-Dist: typer>=0.12
28
+ Requires-Python: >=3.12
29
+ Project-URL: Repository, https://github.com/AyushSingh012/PatchLoop
30
+ Project-URL: Issues, https://github.com/AyushSingh012/PatchLoop/issues
31
+ Description-Content-Type: text/markdown
32
+
33
+ # PatchLoop
34
+
35
+ Finds vulnerable dependencies in a Python project (uv or Poetry) or a JavaScript project
36
+ (npm, pnpm or yarn: Next.js, React, Node), upgrades them to the
37
+ lowest safe version, runs your tests, rescans to confirm each fix, and opens **one** GitHub
38
+ pull request with everything that is confirmed. Nothing counts as fixed without a clean
39
+ rescan, and nothing counts as tested without passing tests.
40
+
41
+ PatchLoop was called VulnPilot up to v0.1.2.
42
+
43
+ ## Install
44
+
45
+ You need Python 3.12+.
46
+
47
+ ```sh
48
+ pipx install patchloop # or: uv tool install patchloop
49
+ patchloop --version
50
+ ```
51
+
52
+ To get the latest unreleased code instead:
53
+ `uv tool install "git+https://github.com/AyushSingh012/PatchLoop"`.
54
+
55
+ PatchLoop drives these tools; install any that are missing:
56
+
57
+ | Tool | Needed for | Install |
58
+ |---|---|---|
59
+ | `osv-scanner` v2 | finding vulnerabilities | `brew install osv-scanner` or the [releases page](https://github.com/google/osv-scanner/releases) |
60
+ | `uv` | uv projects | `brew install uv`, or [docs.astral.sh/uv](https://docs.astral.sh/uv/getting-started/installation/) |
61
+ | `poetry` | Poetry projects only | [python-poetry.org](https://python-poetry.org/docs/#installation) |
62
+ | `node` + `npm` / `pnpm` | JavaScript projects only (yarn comes through Node's `corepack`) | [nodejs.org](https://nodejs.org) |
63
+ | `git` | `fix` | `brew install git` |
64
+ | `gh` (logged in) | opening the PR | `brew install gh`, then `gh auth login` |
65
+ | `trivy` | image scans with `--scanner trivy` (the default) | `brew install trivy`; Linux: [apt / rpm repositories](https://trivy.dev/latest/getting-started/installation/) |
66
+ | `wizcli` (logged in) | image scans with `--scanner wiz` | needs a Wiz account: get `wizcli` and credentials from your Wiz admin, then `wizcli auth` |
67
+ | `docker` | `--build`, and multi-platform images | [Docker](https://docs.docker.com/get-docker/) |
68
+
69
+ The commands above are for macOS; on Linux use your distribution's packages or the linked
70
+ pages. Windows is not supported: run PatchLoop inside
71
+ [WSL](https://learn.microsoft.com/windows/wsl/install).
72
+
73
+ Then check everything at once (it shows the install command for anything missing):
74
+
75
+ ```sh
76
+ patchloop doctor
77
+ ```
78
+
79
+ ## First run
80
+
81
+ Run these from the project folder (the one with `pyproject.toml` and `uv.lock` / `poetry.lock`,
82
+ or `package.json` and its lockfile).
83
+
84
+ ```sh
85
+ patchloop scan # what is vulnerable; changes nothing
86
+ patchloop fix --dry-run # which upgrades it would make; changes nothing
87
+ patchloop fix --no-push # the whole loop, committed to a local branch only
88
+ patchloop fix # the whole loop, then opens or updates the PR
89
+ ```
90
+
91
+ `--no-push` is the safe way to try it: it commits to the local branch
92
+ `patchloop/security-fixes`, writes the PR text to a file in the run folder, and pushes
93
+ nothing. Look at the result with `git log -p patchloop/security-fixes`.
94
+
95
+ ### What `fix` does
96
+
97
+ 1. Makes a temporary copy (git worktree) of `origin/main`, so your checkout is never touched.
98
+ 2. Scans the lockfile and picks, for each vulnerable package, the lowest release that fixes it.
99
+ 3. Runs your tests once before changing anything, and stops if they already fail.
100
+ 4. Upgrades the packages (only `pyproject.toml` and the lockfile change), runs the tests, and
101
+ if they fail, finds the upgrade that breaks them and leaves just that one out.
102
+ 5. Rescans; only what the rescan no longer finds counts as fixed.
103
+ 6. Commits to `patchloop/security-fixes`, rebuilt from the base branch on every run, and
104
+ opens the PR, or updates the one already open. There is never more than one.
105
+
106
+ The PR lists every finding: fixed, fixed but not tested, and not fixed with the reason
107
+ (breaks tests, needs a major upgrade, no fix released, …). Failing tests are named, never
108
+ copied in. PatchLoop opens no PR if an upgrade brings in a new vulnerability, and never
109
+ overwrites the branch if someone else has committed to it.
110
+
111
+ ### Exit codes
112
+
113
+ | Code | Meaning |
114
+ |---|---|
115
+ | 0 | Nothing at or above the threshold remains |
116
+ | 1 | Findings remain (listed with the reason), or an upgrade brought in a new one |
117
+ | 2 | Something stopped the run; the message ends with a `Fix:` line saying what to do |
118
+
119
+ ## Which vulnerabilities get fixed
120
+
121
+ By default **HIGH and CRITICAL**, plus:
122
+
123
+ - findings with no severity rating (they count as HIGH until a source rates them);
124
+ - findings on CISA's Known Exploited (KEV) list, or with an EPSS score of 0.1 or more, at
125
+ any severity;
126
+ - lower-severity advisories on a package that is being upgraded anyway, when a release in
127
+ the same major version fixes them too.
128
+
129
+ Everything else is listed in the PR under "Skipped". To include more:
130
+
131
+ ```sh
132
+ patchloop fix --min-severity MEDIUM # this run only; LOW includes everything
133
+ patchloop fix --severity MEDIUM,HIGH # an exact set
134
+ ```
135
+
136
+ or set `severity_threshold` in `patchloop.yml` (below).
137
+
138
+ ## Scanning container images
139
+
140
+ PatchLoop can run Trivy or Wiz on an image itself and merge the result:
141
+
142
+ ```sh
143
+ patchloop scan --image myapp:latest # Trivy (default)
144
+ patchloop scan --image myapp:latest --scanner wiz # Wiz (needs `wizcli auth`)
145
+ patchloop fix --image myapp:latest --scanner trivy,wiz # both
146
+ ```
147
+
148
+ The image must be local (`docker image ls`) or pullable by the scanner. For a
149
+ multi-platform image of which only one platform was pulled, PatchLoop saves that platform
150
+ and scans it (`--platform linux/amd64` to choose). Or set it in `patchloop.yml`:
151
+
152
+ ```yaml
153
+ images: [myapp:latest]
154
+ image_scanners: [trivy] # trivy, wiz, or both
155
+ ```
156
+
157
+ Results are matched to the lockfile exactly like imported reports (below).
158
+
159
+ ### Building the image
160
+
161
+ For a repo with a Dockerfile, `--build` builds the image and scans it. With `fix`,
162
+ PatchLoop then rebuilds the image from the fixed lockfile and scans it again: the PR gets an
163
+ "Image check" section with before / after counts, and findings only count as fixed in the
164
+ image once the rebuilt image no longer has them. Both images are removed afterwards.
165
+
166
+ ```sh
167
+ patchloop fix --build # ./Dockerfile, Trivy
168
+ patchloop fix --build --dockerfile docker/Dockerfile --scanner trivy,wiz
169
+ patchloop fix --build --build-arg FEED_URL # value taken from $FEED_URL
170
+ ```
171
+
172
+ Build-arg values never appear on a command line, in PatchLoop's logs, reports or the PR:
173
+ Docker reads them from the environment. In `patchloop.yml` list names only:
174
+
175
+ ```yaml
176
+ build:
177
+ dockerfile: Dockerfile
178
+ context: .
179
+ args: [FEED_URL] # values come from the environment
180
+ ```
181
+
182
+ Docker itself stores the values of build args used by `RUN` steps in the image's history,
183
+ where anyone who can pull the image can read them; PatchLoop warns when it finds one there.
184
+ Use BuildKit secrets (`RUN --mount=type=secret`) for credentials instead.
185
+
186
+ ## Trivy and Wiz reports
187
+
188
+ If you also scan with Trivy or Wiz (for example the container image in CI), pass their JSON
189
+ reports and PatchLoop merges them with its own scan. The same CVE from several tools shows
190
+ once, with every source listed.
191
+
192
+ ```sh
193
+ trivy image --scanners vuln --format json -o trivy.json <image>
194
+ wizcli scan container-image <image> --by-policy-hits DISABLED --json-output-file wiz.json
195
+ patchloop fix --import trivy.json --import wiz.json
196
+ ```
197
+
198
+ Each finding is matched to the lockfile:
199
+
200
+ | Finding | Result |
201
+ |---|---|
202
+ | Package in the lockfile, at an affected version | Fixed like any other finding |
203
+ | Package in the lockfile, already fixed there (the image was built earlier) | FIXED_IN_SOURCE: rebuild the image |
204
+ | OS package, or a package the lockfile doesn't have | OUT_OF_SCOPE: needs a base-image or Dockerfile change |
205
+
206
+ A project needs no Dockerfile: the lockfile scan covers every Python package it uses.
207
+ Secret findings in an imported report are never read, printed or stored.
208
+
209
+ ## Configuration: `patchloop.yml`
210
+
211
+ Optional, in the project folder. Every key is optional; unknown keys are an error.
212
+
213
+ ```yaml
214
+ severity_threshold: HIGH # LOW | MEDIUM | HIGH | CRITICAL
215
+ allow_major_upgrades: false # true lets a fix move to a new major version
216
+ imports: [] # Trivy / Wiz JSON files, relative to the project
217
+ images: [] # container images to scan on every run
218
+ image_scanners: [trivy] # trivy, wiz, or both
219
+ image_platform: null # e.g. linux/amd64 for multi-platform images
220
+ build: null # or {dockerfile: Dockerfile, context: ., args: [NAME]}
221
+ osv_offline: true # match against a local OSV database (see below)
222
+ enrich: true # look up KEV and EPSS for each CVE
223
+
224
+ validate:
225
+ install: null # default: uv sync --frozen / poetry sync
226
+ test: null # default: uv run pytest -q / poetry run pytest -q; "none" = no tests
227
+ timeout_minutes: 15
228
+ retries: 1 # re-run failing tests before blaming an upgrade
229
+ isolate_breakers: true # find and drop only the upgrade that breaks tests
230
+
231
+ ignore: # hide a finding until a date, with a reason
232
+ - id: CVE-2024-12345
233
+ reason: not reachable; tracked in SEC-42
234
+ expires: 2026-12-31
235
+
236
+ pr:
237
+ base_branch: main
238
+ branch: patchloop/security-fixes
239
+ labels: [security, dependencies] # labels missing from the repo are skipped with a warning
240
+ reviewers: []
241
+ gh_user: null # open the PR as this gh account (must be logged in)
242
+ repo: null # owner/name; default: read from the origin remote
243
+ ```
244
+
245
+ `gh_user` lets you keep your usual account active in `gh`: PatchLoop uses that account's
246
+ token for its own `gh` and `git push` calls only.
247
+
248
+ ## What leaves your machine
249
+
250
+ | Where | What is sent | When |
251
+ |---|---|---|
252
+ | osv-vulnerabilities.storage.googleapis.com | nothing about the project: the PyPI vulnerability database (about 36 MB) is downloaded and matched locally | every scan (`osv_offline: true`) |
253
+ | api.osv.dev | the name and version of every package in the lockfile | only with `osv_offline: false` |
254
+ | PyPI | names of the packages being upgraded, to list their releases | `fix` |
255
+ | CISA | nothing (the KEV catalog is downloaded, at most daily) | `enrich: true` |
256
+ | FIRST (EPSS) | CVE IDs | `enrich: true` |
257
+ | GitHub | the branch and the PR | `fix` without `--no-push` |
258
+
259
+ Run data (raw scanner output, test logs, the report) stays in
260
+ `~/.cache/patchloop/runs/<run-id>/`.
261
+
262
+ ## JavaScript projects (Next.js, React, Node)
263
+
264
+ A folder with `package.json` and a lockfile (`package-lock.json`, `pnpm-lock.yaml` or
265
+ `yarn.lock`, classic or Berry) is fixed the same way as a Python project: the lowest
266
+ release that fixes each advisory, tests, rescan, one PR. Only `package.json` and the
267
+ lockfile change.
268
+
269
+ - In-range fixes change only the lockfile. npm and pnpm get there by pinning the target,
270
+ locking, removing the pin and locking again; yarn keys its lockfile by range, so the
271
+ entry is pinned in `yarn.lock` directly (Berry: `yarn set resolution`).
272
+ - A direct dependency whose range excludes the fix gets the smallest edit in the same
273
+ style (`"4.17.20"` → `"4.17.21"`, `^1.6.0` → `^2.0.1`).
274
+ - When a parent package caps a vulnerable one, PatchLoop first upgrades the parent (npm,
275
+ pnpm). If the parent still caps it, the version is forced with `overrides` (npm),
276
+ `pnpm.overrides` or `resolutions` (yarn), the tests are run, and the PR marks it
277
+ **forced via override** so a reviewer checks it works with that parent.
278
+ - Tests: the `test` script in package.json (`npm test`, `pnpm test`, `yarn test`); a
279
+ project without one gets its fixes marked "not tested". Install: `npm ci`,
280
+ `pnpm install --frozen-lockfile`, `yarn install --frozen-lockfile` / `--immutable`.
281
+ - yarn is run through `corepack` when it is not installed.
282
+
283
+ The npm vulnerability database used for offline matching is about 213 MB, downloaded once
284
+ and refreshed only when it changes.
285
+
286
+ ## Workspaces and monorepos
287
+
288
+ **Workspaces** (several packages sharing one lockfile at the root) work for npm, pnpm, yarn
289
+ (classic and Berry) and uv. Run PatchLoop on the workspace root:
290
+
291
+ - Members come from `workspaces` in package.json, `packages` in pnpm-workspace.yaml, or
292
+ `[tool.uv.workspace]` in pyproject.toml (globs, with `!` / `exclude` honoured).
293
+ - A dependency counts as direct when any member lists it. A range that blocks a fix is
294
+ widened in each member that has it; the PR names the file (`packages/web/package.json`).
295
+ - Tests: the root's `test` script when there is one; otherwise each member's own `test`
296
+ script, run in that member's folder. uv runs `uv sync --frozen --all-packages` and
297
+ `uv run --all-packages pytest -q`. Set `validation.test` to use your own command.
298
+ - npm does not apply new `overrides` to packages under workspace members once they are
299
+ locked, so a vulnerable package capped by its parent in an npm workspace is reported as
300
+ blocked instead of forced. pnpm and yarn force it as usual.
301
+ - Running it on a member folder says which workspace root to use instead.
302
+
303
+ **Repos with separate projects** (say `backend/` with uv.lock and `web/` with
304
+ package-lock.json) are fixed one folder at a time: `patchloop fix backend`, then
305
+ `patchloop fix web`. Each folder gets its own branch (`patchloop/security-fixes-backend`)
306
+ and its own PR, titled with the folder. Run at the repo root, PatchLoop lists the folders it
307
+ found.
308
+
309
+ ## Poetry projects
310
+
311
+ Poetry projects get the same exact versions as uv projects, not the newest version the
312
+ range allows: each target is pinned in a temporary dependency group, locked, then unpinned
313
+ and locked again, and Poetry keeps the locked versions. A constraint that blocks a fix gets
314
+ the smallest edit in Poetry's own style (`"2.31.0"` → `"2.33.0"`, `^2.31` → `^3.0.1`).
315
+ Poetry 1.x and 2.x both work.
316
+
317
+ Poetry rejects any version that declares `python <4` when the project's range is open-ended
318
+ (`>=3.12`), so bound it (`>=3.12,<4` or `^3.12`), as most Poetry projects already do.
319
+
320
+ ## Output files
321
+
322
+ `scan` and `fix` take `--json FILE` and `--sarif FILE`. The SARIF file (2.1.0) points each
323
+ finding at the package's line in the lockfile, for GitHub code scanning; after `fix` it lists
324
+ only what is still open.
325
+
326
+ ## Using it from Python
327
+
328
+ ```python
329
+ from patchloop import scan, fix
330
+
331
+ result = scan("path/to/project", min_severity="MEDIUM")
332
+ for f in result.shown:
333
+ print(f.package, f.installed_version, f.advisory_id, f.severity)
334
+
335
+ outcome = fix("path/to/project", push=False) # commit to a local branch only
336
+ print(outcome.exit_code, [r.status for r in outcome.report.results])
337
+ ```
338
+
339
+ Both accept the same settings as `patchloop.yml` (`config=` a dict or `Config`), plus
340
+ `imports=`, `images=`, `scanners=`, `build=` and `build_args=`, and return the same models
341
+ the CLI writes to `--json`. Nothing is printed.
342
+
343
+ ## Limits
344
+
345
+ - macOS and Linux. Windows is not supported.
346
+ - PyPI and npm packages only; OS packages in images are reported, not fixed.
347
+ - Projects need a lockfile: uv.lock, poetry.lock, package-lock.json, pnpm-lock.yaml or
348
+ yarn.lock. A plain `requirements.txt` is not supported yet.
349
+ - Advisories come from public databases (OSV), and fix versions are looked up on the
350
+ public pypi.org and registry.npmjs.org (falling back to the advisory's fixed versions
351
+ when that fails). Public packages served through a private mirror work; packages that
352
+ exist only in a private registry have no public advisories, so they are not checked.
353
+ - Poetry has no workspaces, so a Poetry monorepo is fixed one project folder at a time.
354
+ - GitHub only. There is no built-in schedule: run it from a scheduled CI job or cron
355
+ (re-runs update the one open PR instead of opening another).
356
+
357
+ ## Releasing
358
+
359
+ `.github/workflows/release.yml` publishes to PyPI when a `v*` tag is pushed, through PyPI
360
+ Trusted Publishing (no token stored). It is off until the repository variable
361
+ `PUBLISH_TO_PYPI` is set to `true`. One-time setup:
362
+
363
+ 1. On pypi.org, add a pending trusted publisher for the project `patchloop`: this
364
+ repository, workflow `release.yml`, environment `pypi`.
365
+ 2. In the repository settings, create the environment `pypi` and set the repository
366
+ variable `PUBLISH_TO_PYPI=true`.
367
+ 3. Bump `version` in `pyproject.toml`, tag `v<version>`, push the tag.
368
+
369
+ ## Development
370
+
371
+ ```sh
372
+ uv sync # install
373
+ make check # ruff + mypy (strict) + offline tests
374
+ make integration # live scan + fix on every fixture (uv, Poetry, osv-scanner, PyPI, pytest)
375
+ make github-test # real PRs on a throwaway repo; see tests/test_github_live.py
376
+ make osv-data # refresh saved osv-scanner output used by the offline tests
377
+ make fixtures # regenerate fixture lockfiles at their seeded vulnerable versions
378
+ scripts/capture_imports.sh # rebuild the sample Trivy / Wiz files in tests/data/imports
379
+ uv run python scripts/fixture_repo.py tests-break /tmp/tb # a fixture as its own git repo
380
+ ```
381
+
382
+ `tests/fixtures/{uv,poetry}/<name>/` are small projects pinned to known-vulnerable versions.
383
+ Each has a `fixture.yaml` with its seed versions and the expected `scan` and `fix` results,
384
+ which the integration tests check.
385
+
386
+ ## License
387
+
388
+ MIT; see [LICENSE](https://github.com/AyushSingh012/PatchLoop/blob/main/LICENSE).
@@ -0,0 +1,56 @@
1
+ patchloop/__init__.py,sha256=skVZghYJ0bFTzRwyCjjy1CLzQmFc5OPbSZtc4dACiJQ,806
2
+ patchloop/api.py,sha256=6uN9gTJccm8Q3MfKWmhHmDqH16qcVfQ4ZOK_NVfC79Q,3704
3
+ patchloop/build.py,sha256=1BGabcRIEN_wCvxNWGrbjxJItyqFCIK1r6Mtkx3sTrs,4288
4
+ patchloop/classify.py,sha256=s2Py6nPjp1NIeE6CZVEHCav5TT44TmNZS5BWuPW3mcI,5452
5
+ patchloop/cli.py,sha256=vFIwH2ZaAVTvoN8FOiEzkr4-Fvvl2G9JKPS7a3yfUjs,12420
6
+ patchloop/config.py,sha256=BbmqcuqeaeTd6TmOpwry-L9JBfj7XLvifLpSYOQ9OMI,5762
7
+ patchloop/detect.py,sha256=rmzG_8Yo9xNPU9DEQK9UXHusTfKqNkadVXNwu5EhIuw,4531
8
+ patchloop/doctor.py,sha256=ZfB5GlNlakj_9Qxnri2_PAW_1aEQsterJ881QGziYUE,7028
9
+ patchloop/enrich/__init__.py,sha256=0JmQD5MkqdEIToIflYSDAv4FFH-GSoToEQ5h7BCV1Sg,2015
10
+ patchloop/enrich/epss.py,sha256=-recWudnVgP8yXAW9dtN071ShF-5_TFjhRcXok9rfUg,2176
11
+ patchloop/enrich/kev.py,sha256=A9bqr8nPeLszSXp8WbzupvMhbeO6oqunZCY5A27KOII,1568
12
+ patchloop/fixers/__init__.py,sha256=E_zGWz-KrTKlWcl1tjZwA51zrzhykaGcZuirCKxPvMo,74
13
+ patchloop/fixers/base.py,sha256=n2oqXiALeHUUAE_TxuiYv6UaLfnLxXDPgdtSfzso_JM,689
14
+ patchloop/fixers/js_fix.py,sha256=b46RENe2ornUuJSc55QDDZqtdpZ6fZ2z2LbCZRjpApY,12870
15
+ patchloop/fixers/poetry_fix.py,sha256=biNzKQNq8JW6UKPI7-QTwGONXn01v9vumldpQ1G4des,6243
16
+ patchloop/fixers/uv_fix.py,sha256=sAMqcH1wyqH52QtEF23M7YYx-FJubJNT1T8ihGs-zcU,4766
17
+ patchloop/git_ops.py,sha256=WUaROKeEz_f1HvFv_TtIT_YB7utN9N04i_uTqPn9gaU,6833
18
+ patchloop/github.py,sha256=iN3thq8AU5QN9ei3H6UueOR4MDmmCI6Pd9x1kLxjP8M,6373
19
+ patchloop/hints.py,sha256=WYsYoiUPzIAJVPECW8QFn_J1GEQG33BJVNuDoZr9cGs,6418
20
+ patchloop/images.py,sha256=BreHOE1-11W91zchle6hxoATDsR0f20lf_GJ4B5Nlpk,7828
21
+ patchloop/isolate.py,sha256=DNSWHeW7D9zXVXUWpNxLElN4faSS9CPKLABuQykdMaQ,2029
22
+ patchloop/js/__init__.py,sha256=NJgYCatQ2VJnOe8u73go_5PxiT7NOEctpe0Ibb9iMlE,47
23
+ patchloop/js/lockfiles.py,sha256=7wKS3OCwvzN-ynpP8Rw_jaEUfbyejCnjLZ3pX1QFCqA,9112
24
+ patchloop/js/manifest.py,sha256=hS-t4k7tzBuTUkbSgmTtVORwREruIdfgnEiDvm56VYs,4474
25
+ patchloop/js/ranges.py,sha256=ir32WtnjpRCo4RB2nXRx3vu3UN6GLDuaKbiwIIlKZxU,4988
26
+ patchloop/js/registry.py,sha256=FTb7GN-431nDCYg9Sy_oIIOsG-M9SnfMWsSAgFqmsUo,2493
27
+ patchloop/js/yarn.py,sha256=2am44KlGZo8xCGf_cYBAdGHoZdWG_r2R335CqIsA6Kw,7247
28
+ patchloop/lockgraph.py,sha256=5cyfwPvFt3YwaOKox-NuONQL64xrj3kGB4QVbOxBIVI,7413
29
+ patchloop/models.py,sha256=KnMVs-f5wkpVJrY9hMwBmUjHjU9Wuhs8Jth0Mv2I4nc,8247
30
+ patchloop/plan.py,sha256=GXs3NsNqg94kqixLnC2-gL8Fyl__jD1yGCLXjMvwVCw,7850
31
+ patchloop/pr_body.py,sha256=ixTeflTI-8FO9Ly86HG4EHpk7w1t0G6aI3Uin-OYpgk,10147
32
+ patchloop/prioritize.py,sha256=qZ5aJlQwhLY-MCjnV3E4R-2kk5KiWm1fevGDQ-c4Lk8,1254
33
+ patchloop/proc.py,sha256=2rj9wYpNAGMKBpoY9e2c7EZqVRTEnYrvUmlE1v6i6h8,2047
34
+ patchloop/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
+ patchloop/pypi.py,sha256=CfygOhlnuEpE9UHw7nExSFZficqKsIGTBohzsJyDD4M,1956
36
+ patchloop/report/__init__.py,sha256=S0JeaIt3vqGbyNcdA2xAlsRcQFeW1le-Ogmb74lhAJ0,75
37
+ patchloop/report/console.py,sha256=6RHteZw_HB6rp_O9yg9K2T9aXcR0ZC2_2krGDWyU-Lc,9389
38
+ patchloop/report/json_out.py,sha256=6z3tRnvFDKNt0TwYS5rpH3Ruf7NO8ctMIPxldJhAwkw,953
39
+ patchloop/report/sarif.py,sha256=SyJTH_dugDKqjn8lRES-_hcLD4Q_SYDbBSNCJiMEZu8,5157
40
+ patchloop/runner.py,sha256=nS671LB_40eZh4ZG8U9ShVjdmCQwNVSQCVoiT1p7D7E,18509
41
+ patchloop/scanner.py,sha256=lZiF59YV_Jl9Uo8DIkDNC-P-HDvtx4bgZTSJ-wrPS1U,7688
42
+ patchloop/sources/__init__.py,sha256=MXngt1WOxfGlCcBw2xijvaNjTI96v8V709kwqWUiqxA,70
43
+ patchloop/sources/base.py,sha256=Dup3r3fsaF5mLyC5avQYNtN8Qg-6q3iGUCJpLzWWJVI,136
44
+ patchloop/sources/imports.py,sha256=Y9NKyBz5dNRSJF8yenHkAw2x1M3ub1tjlqgFFFeGaGI,10720
45
+ patchloop/sources/merge.py,sha256=Qt0--PnKxNebk1XE7uRLvacD3BAQUesKllWjfmPPdZ4,4018
46
+ patchloop/sources/osv.py,sha256=NIqWECxJ_J4E5mMvJ_Rql_pNJiYgz8suhPzWIu-NjKE,10004
47
+ patchloop/specifiers.py,sha256=1endLujc63Ban4i-BE96fQN8fa5rU1Z7FKoM3HTjt6k,10269
48
+ patchloop/validate.py,sha256=jHgjKRgwNXFWSGeKHwUmtnm9q3AAcoLp69ryIAao7zI,7853
49
+ patchloop/versions.py,sha256=w1RLRVX3qPWMe6KeBDWmikEZTRfDPKH23NcVxu_uZ2k,2567
50
+ patchloop/workspaces.py,sha256=DDVR_Yxpx-DQqwkRjJKvFBADYo9AjGVdQNZ-zFVeyLg,5502
51
+ patchloop/worktree.py,sha256=Nhrg6mXJJdAkCpItykbGHZ62l0x_1svVlWB15EzbGMY,5653
52
+ patchloop-0.2.0.dist-info/licenses/LICENSE,sha256=b9nK3LhprXJT-KtmuZJIuDeFdNy7Hq0FR-R_f2oAer4,1074
53
+ patchloop-0.2.0.dist-info/WHEEL,sha256=wfHFB5CQ4yOA68LQ_ISeFjKJGxj2GfVzMH9QxkYgrCw,81
54
+ patchloop-0.2.0.dist-info/entry_points.txt,sha256=6Rzny6Msr-FRkBmtG1Wwi3vN2BCnhyovObirG5MAFhI,49
55
+ patchloop-0.2.0.dist-info/METADATA,sha256=DUCIA7Px8lmRmbb1kXquDbn8cG7S6NvVo1FMSwTUAqI,18296
56
+ patchloop-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.13.13
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ patchloop = patchloop.cli:app
3
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ayush Kumar Singh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.