From 999335447b95cb0c72e3be5bee5f0b4094b39efd Mon Sep 17 00:00:00 2001 From: Mikola Lysenko Date: Mon, 23 Nov 2026 16:03:38 -0500 Subject: [PATCH 01/23] Route hosted pnpm pins through one named registry per patch On pnpm 11.20 and newer, hosted mode now has pnpm verify each patched package against the patch server instead of trusting the whole lock, and keeps the patch installed when pnpm resolves again. What the scan writes. Each patch gets its own named registry in pnpm-workspace.yaml, `socket-`, whose address is the directory the patch's tarball is served from (the grant's `npmRegistryUrl`, used verbatim). An override routes the patched release to it (`'name@version': 'socket-:version'`), and every governing pnpm-lock.yaml is rewritten to exactly what pnpm writes for that: the `overrides:` record, `name@socket-:version` keys and references, importer specifiers. No `trustLockfile` is written. - A name that is taken (two patches sharing eight digits, or a registry of the user's) takes four more digits at a time. - A registry is the CLI's only by its name together with its address, a patch's directory on a patch server; everything else under `namedRegistries` and `overrides` is the user's and is never touched. A lock key under a registry the user named `socket` is not read as a hosted release. - The route is taken only when every hosted pin has an address and the project's pnpm pins prove 11.20; otherwise the whole lock stays on `trustLockfile` and the warning names the packages or the reason. A run granted only part of the project's patches leaves the rest routed. A pin on a patch mirror stays on `trustLockfile`. - Lock shapes pnpm does not lock as a respelling stay on `trustLockfile`: a package installed with and without the patched release as its peer, a patched optional peer, and a routed release with a multi-paragraph deprecation message. - A patch replaced by a newer one has a new UUID, so its registry is renamed and the release's lock keys with it. - An override holds every dependency whose range admits the patched version. When a governing lock also holds a newer release in that range, the scan notes that pnpm may move its dependents to the patched one the next time it resolves. Cleanup. Nothing of the route outlives its use, per patch: the registry, the override, the lock's record and the registry-form keys go together. Every hosted scan reconciles them; `repair` and `scan --prune` do it offline from the files alone; `rollback`, `remove` and a switch to vendored mode take a restored package's entries with it. Each removal is reported (`registry_entry_unused`, `gc.removedRegistryEntries`), a dry run lists the same and writes nothing, and a pnpm-workspace.yaml a run created is deleted once nothing else is in it. A registry address is never printed. - The workspace overrides and the lock's record change together. A lock that cannot be read, or member locks that cannot be listed, keep the route whole: leaving the route does nothing and rollback refuses the pin. - With `--no-trust-lockfile-config`, a routed release stays on the patch it is routed to (`redirect_pnpm_registry_held`). - On a patch server the run was not told about, a cleanup leaves such registries alone and says so (`registry_cleanup_unknown_host`). The lock rewrite is pinned byte for byte to real pnpm by golden fixtures (scripts/gen-pnpm-registry-override-golden.mjs), generated with pnpm 12.22.0 and identical on 11.20.0 through 12.21.0. Real-pnpm e2e legs cover frozen installs, `pnpm add` / `update` / `dedupe` / `install --fix-lockfile`, a newer release in range, and every cleanup. Shapes written by unreleased builds of this branch are converted or removed by the next scan. Co-Authored-By: Claude Fable 5.2 --- crates/socket-patch-cli/CLI_CONTRACT.md | 77 +- crates/socket-patch-cli/src/args.rs | 16 +- crates/socket-patch-cli/src/commands/mod.rs | 1 + .../src/commands/registry_gc.rs | 302 + .../socket-patch-cli/src/commands/repair.rs | 130 +- .../socket-patch-cli/src/commands/scan/gc.rs | 139 +- .../src/commands/scan/hosted.rs | 192 +- .../src/commands/scan/hosted/takeover.rs | 1 + .../socket-patch-cli/src/commands/scan/mod.rs | 66 +- .../src/commands/scan/vendor_flow.rs | 1 + .../src/commands/vendored_backend/repair.rs | 1 + crates/socket-patch-cli/src/json_envelope.rs | 8 + crates/socket-patch-cli/src/lib.rs | 6 +- .../tests/cli/telemetry_e2e.rs | 243 + .../tests/e2e_golang_hosted_build.rs | 2 + .../tests/e2e_redirect_pnpm_build.rs | 1587 +++ .../tests/e2e_vex_lockfile/bun.rs | 1 + .../tests/help_text_hygiene.rs | 6 +- .../tests/in_process_pnpm_registry_cleanup.rs | 1572 +++ .../tests/in_process_redirect.rs | 6 +- .../tests/in_process_redirect_pnpm.rs | 979 ++ .../tests/in_process_vendor_pnpm_takeover.rs | 90 +- .../tests/repair/repair_invariants.rs | 1 + crates/socket-patch-cli/tests/report_e2e.rs | 64 + .../tests/scan/scan_render.rs | 13 +- crates/socket-patch-core/src/api/types.rs | 10 + .../src/formats/gem/hosted.rs | 1 + .../src/formats/pnpm/grammar.rs | 19 + .../src/formats/pnpm/hosted.rs | 24 +- .../socket-patch-core/src/formats/pnpm/mod.rs | 53 +- .../src/formats/pnpm/named_registries.rs | 1964 ++++ .../src/formats/pnpm/plan.rs | 62 + .../src/formats/pnpm/registry_alias.rs | 1818 ++++ .../src/formats/pnpm/version.rs | 389 + crates/socket-patch-core/src/hosted/engine.rs | 9384 ++++++++++++----- .../socket-patch-core/src/hosted/guidance.rs | 1124 +- .../src/hosted/memory/mod.rs | 70 +- .../socket-patch-core/src/hosted/sbt_reads.rs | 1 + crates/socket-patch-core/src/origin.rs | 21 + .../src/patch/redirect/bun_binary.rs | 1 + .../redirect/cargo_rewrite_order_tests.rs | 1 + .../redirect/composer_equivalence_tests.rs | 1 + .../redirect/golang_equivalence_tests.rs | 1 + .../src/patch/redirect/gradle.rs | 1 + .../src/patch/redirect/grant.rs | 24 + .../patch/redirect/group_equivalence_tests.rs | 1 + .../redirect/lock_index_equivalence_tests.rs | 1 + .../src/patch/redirect/mod.rs | 33 + .../src/patch/redirect/pdm.rs | 5 +- .../src/patch/redirect/pipenv_pylock_tests.rs | 1 + .../patch/redirect/platform_wheel_tests.rs | 1 + .../patch/redirect/pnpm_equivalence_tests.rs | 1 + .../src/patch/redirect/poetry.rs | 1 + .../patch/redirect/pypi_no_lockfile_tests.rs | 1 + .../redirect/python_lock_equivalence_tests.rs | 2 + .../src/patch/redirect/requirements.rs | 1 + .../src/patch/redirect/upstream/bun_lockb.rs | 1 + .../src/patch/redirect/upstream/gem.rs | 4 + .../src/patch/redirect/upstream/gradle.rs | 1 + .../src/patch/redirect/upstream/maven.rs | 1 + .../src/patch/redirect/upstream/mod.rs | 73 + .../src/patch/redirect/upstream/npm.rs | 414 +- .../redirect/upstream/route_sweep_tests.rs | 519 + .../src/vendor/lock_inventory/tests.rs | 1 + crates/socket-patch-core/src/vendor/mod.rs | 14 +- .../src/vendor/yarn_layering_tests.rs | 3 + .../socket-patch-core/src/vex/discover/bun.rs | 1 + .../src/vex/discover/gradle.rs | 1 + .../socket-patch-core/src/vex/discover/npm.rs | 1 + .../pnpm-registry-overrides/README.md | 45 + .../both-versions/expected/pnpm-lock.yaml | 49 + .../expected/pnpm-workspace.yaml | 8 + .../both-versions/patches.json | 18 + .../both-versions/project/package.json | 9 + .../both-versions/project/pnpm-lock.yaml | 45 + .../deprecated-block/expected/pnpm-lock.yaml | 41 + .../expected/pnpm-workspace.yaml | 6 + .../deprecated-block/patches.json | 10 + .../deprecated-block/project/package.json | 9 + .../deprecated-block/project/pnpm-lock.yaml | 42 + .../expected/packages/a/pnpm-lock.yaml | 36 + .../expected/packages/b/pnpm-lock.yaml | 25 + .../member-locks/expected/pnpm-lock.yaml | 26 + .../member-locks/expected/pnpm-workspace.yaml | 7 + .../member-locks/patches.json | 10 + .../member-locks/project/package.json | 8 + .../project/packages/a/package.json | 9 + .../project/packages/a/pnpm-lock.yaml | 33 + .../project/packages/b/package.json | 8 + .../project/packages/b/pnpm-lock.yaml | 22 + .../member-locks/project/pnpm-lock.yaml | 23 + .../member-locks/project/pnpm-workspace.yaml | 3 + .../optional-peer/expected/pnpm-lock.yaml | 71 + .../expected/pnpm-workspace.yaml | 6 + .../optional-peer/patches.json | 10 + .../optional-peer/project/package.json | 5 + .../project/packages/a/package.json | 9 + .../project/packages/b/package.json | 9 + .../optional-peer/project/pnpm-lock.yaml | 57 + .../optional-peer/project/pnpm-workspace.yaml | 2 + .../optional-peer/refuses.txt | 1 + .../own-peers/expected/pnpm-lock.yaml | 44 + .../own-peers/expected/pnpm-workspace.yaml | 6 + .../own-peers/patches.json | 10 + .../own-peers/project/package.json | 9 + .../own-peers/project/pnpm-lock.yaml | 41 + .../patched-peer/expected/pnpm-lock.yaml | 45 + .../patched-peer/expected/pnpm-workspace.yaml | 6 + .../patched-peer/patches.json | 10 + .../patched-peer/project/package.json | 9 + .../patched-peer/project/pnpm-lock.yaml | 41 + .../expected/pnpm-lock.yaml | 43 + .../expected/pnpm-workspace.yaml | 6 + .../peer-suffixed-parent/patches.json | 10 + .../peer-suffixed-parent/project/package.json | 9 + .../project/pnpm-lock.yaml | 40 + .../peer-variants/expected/pnpm-lock.yaml | 65 + .../expected/pnpm-workspace.yaml | 6 + .../peer-variants/patches.json | 10 + .../peer-variants/project/package.json | 5 + .../project/packages/a/package.json | 9 + .../project/packages/b/package.json | 9 + .../peer-variants/project/pnpm-lock.yaml | 62 + .../peer-variants/project/pnpm-workspace.yaml | 2 + .../peer-variants/refuses.txt | 1 + .../peers-both/expected/pnpm-lock.yaml | 60 + .../peers-both/expected/pnpm-workspace.yaml | 8 + .../peers-both/patches.json | 18 + .../peers-both/project/package.json | 10 + .../peers-both/project/pnpm-lock.yaml | 55 + .../pinned-pnpm/expected/pnpm-lock.yaml | 200 + .../pinned-pnpm/expected/pnpm-workspace.yaml | 6 + .../pinned-pnpm/patches.json | 10 + .../pinned-pnpm/project/package.json | 9 + .../pinned-pnpm/project/pnpm-lock.yaml | 197 + .../scoped-direct/expected/pnpm-lock.yaml | 34 + .../expected/pnpm-workspace.yaml | 6 + .../scoped-direct/patches.json | 10 + .../scoped-direct/project/package.json | 8 + .../scoped-direct/project/pnpm-lock.yaml | 31 + .../several/expected/pnpm-lock.yaml | 65 + .../several/expected/pnpm-workspace.yaml | 12 + .../several/patches.json | 34 + .../several/project/package.json | 11 + .../several/project/pnpm-lock.yaml | 60 + .../shared-digits/expected/pnpm-lock.yaml | 35 + .../expected/pnpm-workspace.yaml | 8 + .../shared-digits/patches.json | 18 + .../shared-digits/project/package.json | 8 + .../shared-digits/project/pnpm-lock.yaml | 31 + .../sibling-version/expected/pnpm-lock.yaml | 48 + .../expected/pnpm-workspace.yaml | 6 + .../sibling-version/patches.json | 10 + .../sibling-version/project/package.json | 9 + .../sibling-version/project/pnpm-lock.yaml | 45 + .../three-packages/expected/pnpm-lock.yaml | 57 + .../expected/pnpm-workspace.yaml | 10 + .../three-packages/patches.json | 26 + .../three-packages/project/package.json | 10 + .../three-packages/project/pnpm-lock.yaml | 52 + .../transitive-leaf/expected/pnpm-lock.yaml | 33 + .../expected/pnpm-workspace.yaml | 6 + .../transitive-leaf/patches.json | 10 + .../transitive-leaf/project/package.json | 8 + .../transitive-leaf/project/pnpm-lock.yaml | 30 + .../user-overrides/expected/pnpm-lock.yaml | 42 + .../expected/pnpm-workspace.yaml | 6 + .../user-overrides/patches.json | 10 + .../user-overrides/project/package.json | 9 + .../user-overrides/project/pnpm-lock.yaml | 41 + .../project/pnpm-workspace.yaml | 3 + .../user-registry/expected/pnpm-lock.yaml | 33 + .../expected/pnpm-workspace.yaml | 6 + .../user-registry/patches.json | 10 + .../user-registry/project/package.json | 8 + .../user-registry/project/pnpm-lock.yaml | 30 + .../user-registry/project/pnpm-workspace.yaml | 3 + .../expected/pnpm-lock.yaml | 57 + .../expected/pnpm-workspace.yaml | 6 + .../workspace-importers/patches.json | 10 + .../workspace-importers/project/package.json | 8 + .../project/packages/a/package.json | 9 + .../project/packages/b/package.json | 11 + .../project/pnpm-lock.yaml | 54 + .../project/pnpm-workspace.yaml | 2 + .../pnpm-registry-overrides.json | 1200 +++ crates/socket-patch-core/tests/pnpm_hosted.rs | 1 + .../socket-patch-core/tests/poetry_hosted.rs | 1 + crates/socket-patch-core/tests/uv_hosted.rs | 1 + crates/socket-patch-node/npm/index.d.ts | 6 +- docs/ecosystems.md | 167 +- docs/testing/pnpm-compatibility.md | 197 +- docs/usage.md | 10 +- scripts/gen-pnpm-registry-override-golden.mjs | 501 + 194 files changed, 23805 insertions(+), 2656 deletions(-) create mode 100644 crates/socket-patch-cli/src/commands/registry_gc.rs create mode 100644 crates/socket-patch-cli/tests/in_process_pnpm_registry_cleanup.rs create mode 100644 crates/socket-patch-core/src/formats/pnpm/named_registries.rs create mode 100644 crates/socket-patch-core/src/formats/pnpm/registry_alias.rs create mode 100644 crates/socket-patch-core/src/patch/redirect/upstream/route_sweep_tests.rs create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/README.md create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/both-versions/expected/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/both-versions/expected/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/both-versions/patches.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/both-versions/project/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/both-versions/project/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/deprecated-block/expected/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/deprecated-block/expected/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/deprecated-block/patches.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/deprecated-block/project/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/deprecated-block/project/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/member-locks/expected/packages/a/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/member-locks/expected/packages/b/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/member-locks/expected/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/member-locks/expected/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/member-locks/patches.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/member-locks/project/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/member-locks/project/packages/a/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/member-locks/project/packages/a/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/member-locks/project/packages/b/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/member-locks/project/packages/b/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/member-locks/project/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/member-locks/project/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/optional-peer/expected/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/optional-peer/expected/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/optional-peer/patches.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/optional-peer/project/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/optional-peer/project/packages/a/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/optional-peer/project/packages/b/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/optional-peer/project/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/optional-peer/project/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/optional-peer/refuses.txt create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/own-peers/expected/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/own-peers/expected/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/own-peers/patches.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/own-peers/project/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/own-peers/project/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/patched-peer/expected/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/patched-peer/expected/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/patched-peer/patches.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/patched-peer/project/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/patched-peer/project/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/peer-suffixed-parent/expected/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/peer-suffixed-parent/expected/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/peer-suffixed-parent/patches.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/peer-suffixed-parent/project/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/peer-suffixed-parent/project/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/peer-variants/expected/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/peer-variants/expected/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/peer-variants/patches.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/peer-variants/project/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/peer-variants/project/packages/a/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/peer-variants/project/packages/b/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/peer-variants/project/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/peer-variants/project/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/peer-variants/refuses.txt create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/peers-both/expected/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/peers-both/expected/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/peers-both/patches.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/peers-both/project/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/peers-both/project/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/pinned-pnpm/expected/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/pinned-pnpm/expected/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/pinned-pnpm/patches.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/pinned-pnpm/project/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/pinned-pnpm/project/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/scoped-direct/expected/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/scoped-direct/expected/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/scoped-direct/patches.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/scoped-direct/project/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/scoped-direct/project/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/several/expected/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/several/expected/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/several/patches.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/several/project/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/several/project/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/shared-digits/expected/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/shared-digits/expected/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/shared-digits/patches.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/shared-digits/project/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/shared-digits/project/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/sibling-version/expected/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/sibling-version/expected/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/sibling-version/patches.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/sibling-version/project/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/sibling-version/project/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/three-packages/expected/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/three-packages/expected/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/three-packages/patches.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/three-packages/project/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/three-packages/project/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/transitive-leaf/expected/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/transitive-leaf/expected/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/transitive-leaf/patches.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/transitive-leaf/project/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/transitive-leaf/project/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/user-overrides/expected/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/user-overrides/expected/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/user-overrides/patches.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/user-overrides/project/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/user-overrides/project/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/user-overrides/project/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/user-registry/expected/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/user-registry/expected/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/user-registry/patches.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/user-registry/project/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/user-registry/project/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/user-registry/project/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/workspace-importers/expected/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/workspace-importers/expected/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/workspace-importers/patches.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/workspace-importers/project/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/workspace-importers/project/packages/a/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/workspace-importers/project/packages/b/package.json create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/workspace-importers/project/pnpm-lock.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/workspace-importers/project/pnpm-workspace.yaml create mode 100644 crates/socket-patch-core/tests/fixtures/vex-discover-golden/pnpm-registry-overrides.json create mode 100644 scripts/gen-pnpm-registry-override-golden.mjs diff --git a/crates/socket-patch-cli/CLI_CONTRACT.md b/crates/socket-patch-cli/CLI_CONTRACT.md index a1d543d5e..b9036ed0f 100644 --- a/crates/socket-patch-cli/CLI_CONTRACT.md +++ b/crates/socket-patch-cli/CLI_CONTRACT.md @@ -26,7 +26,7 @@ For task-oriented guidance, start with [usage](../../docs/usage.md), | `rollback` | — | **Full-state rollback (v5.0, MAJOR)**: restore original files AND unwind vendored lockfile wiring / restore hosted pins to their upstream registry entries, remove the rolled-back entries from the manifest, and GC their blobs/archives; takes optional variadic positional `targets` (PURL \| UUID \| package name \| path glob). See [Rollback command contract](#rollback-command-contract-v50) | | `report` | — | (additive) Tell Socket that a patch broke the build, the tests or the application. Requires one or more positional patches: a patch UUID, or a PURL or package name of a patch the project holds. Sends one request; changes nothing in the project and takes no lock. See [`report`](#report-report-a-broken-patch). | | `remove` | — | Restore and remove one patch across hosted, vendored, and agent state; requires positional `identifier`. | -| `repair` | — | Download missing agent blobs and replace corrupt ones (every referenced blob on disk is re-hashed against its git-sha256 name), redownload missing/corrupt vendored artifacts (never re-synthesizing a lost ledger), and clean up unused ones: a blob no manifest patch references (the afterHash and beforeHash blobs of every manifest patch are kept, so an offline `rollback` still has its originals; `scan --prune` keeps the same set) and every obsolete diff or package archive (refuses with `lock_held` when a live process holds the lock; see "Lock lifecycle" below) | +| `repair` | — | Download missing agent blobs and replace corrupt ones (every referenced blob on disk is re-hashed against its git-sha256 name), redownload missing/corrupt vendored artifacts (never re-synthesizing a lost ledger), and clean up unused ones: a blob no manifest patch references (the afterHash and beforeHash blobs of every manifest patch are kept, so an offline `rollback` still has its originals; `scan --prune` keeps the same set) and every obsolete diff or package archive (refuses with `lock_held` when a live process holds the lock; see "Lock lifecycle" below). The cleanup phase also removes the pnpm registry entries of hosted patches that no lockfile uses any more, offline, from the project's files alone (see the vendored-phase section's "Registry cleanup") | Rows are in `--help` order (v5.0): the hosted/vendored workflow (`scan` → `vex` → `vendor`, with `list` to inspect), then the agent-mode (in-place patching) commands. @@ -117,7 +117,7 @@ Every subcommand accepts the same set of "global" flags via a single shared `Glo | `--lock-timeout` | — | `SOCKET_LOCK_TIMEOUT` | (none) | seconds (u64) | How long to wait for `<.socket>/apply.lock`. Unset and `0` both mean a single non-blocking try; a positive value retries with a 100 ms backoff. Only meaningful on the lock-taking subcommands — `apply`, `rollback`, `repair`, `remove`, `vendor`, and `scan`/`get` whenever they write (agent-mode download + apply, vendored, hosted) | | `--debug` | — | `SOCKET_DEBUG` | `false` | bool | Verbose debug logs to stderr | | `--no-telemetry` | — | `SOCKET_TELEMETRY_DISABLED` | `false` | bool | Disable usage telemetry (every switch: [Telemetry](#telemetry)) | -| `--no-trust-lockfile-config` | — | `SOCKET_NO_TRUST_LOCKFILE_CONFIG` | `false` | bool | Opt out of hosted mode's automatic `trustLockfile: true` write to `pnpm-workspace.yaml` (see the pnpm trust-config note under the scan arguments) | +| `--no-trust-lockfile-config` | — | `SOCKET_NO_TRUST_LOCKFILE_CONFIG` | `false` | bool | Opt out of hosted mode's automatic write to `pnpm-workspace.yaml`: the `namedRegistries` entries and `overrides` of the registry route, or `trustLockfile: true` (see the pnpm lockfile-verification notes under the scan arguments) | | `--no-npm-allow-remote-config` | — | `SOCKET_NO_NPM_ALLOW_REMOTE_CONFIG` | `false` | bool | Opt out of hosted mode's automatic `allow-remote=all` write to the project `.npmrc` (see the npm allow-remote note under the scan arguments). Read by `scan --mode hosted` and `get --mode hosted`; other subcommands accept it silently | | `--no-vlt-install-cleanup` | — | `SOCKET_NO_VLT_INSTALL_CLEANUP` | `false` | bool | Opt out of hosted mode's warm-tree heal for vlt: stale installed copies (`node_modules/.vlt-lock.json` and the stale `node_modules/.vlt/` entries) are left in place after `vlt-lock.json` is repointed (`scan`/`get --mode hosted`) or restored (`rollback`/`remove`), and the `redirect_vlt_reinstall_required` advisory tells you to run `vlt ci` instead. Stale copies of optional dependencies are always left in place (see `redirect_vlt_reinstall_required`). Other subcommands accept it silently | | `--no-gem-install-refresh` | — | `SOCKET_NO_GEM_INSTALL_REFRESH` | `false` | bool | Opt out of hosted mode's gem stale-install refresh: the gems Bundler already holds for the project (an installed gem under the project and its cached `.gem`, an archive in `vendor/cache`) are left as they are after `Gemfile.lock` is repointed (`scan`/`get --mode hosted`) or restored (`rollback`/`remove`, of a hosted pin or of a vendored gem; `vendor --revert`), and the `redirect_gem_stale_install` / `upstream_gem_stale_install` warning names the files to remove by hand instead (see the "Gem stale-install guard" section). Other subcommands accept it silently | @@ -299,8 +299,8 @@ Beyond the globals above, each subcommand defines a small set of local arguments | `apply`, `scan`, `vendor` | `--vex` | `SOCKET_VEX` | Generate an OpenVEX 0.2.0 document at this path on a successful run; see "embedded VEX" below | | `apply`, `scan`, `vendor` | `--vex-product`, `--vex-no-verify`, `--vex-no-bazel`, `--vex-doc-id`, `--vex-compact` | `SOCKET_VEX_PRODUCT`, `SOCKET_VEX_NO_VERIFY`, `SOCKET_VEX_NO_BAZEL`, `SOCKET_VEX_DOC_ID`, `SOCKET_VEX_COMPACT` | Passthrough to the embedded VEX builder; mirror the standalone `vex` knobs. Inert unless `--vex` is set | | `scan` | positional `[PATHS]...` | — | (v5.0) Meaning depends on the mode. **Hosted / vendored** (bare `scan` included): each PATH, or directory glob (`apps/*`), is a project directory scanned on its own as if it were `--cwd`. **Agent** (and a mode-less `--prune`/`--global` report): path globs scoping DISCOVERY to packages installed under matching paths (`packages/foo`, `apps/**`). See "Path-scoped scans" below | -| `scan` | `--mode ` | — | The documented selector for the three patch-application modes (v5.0 default: `hosted`, except that a `--prune` or `--global`/`--global-prefix` scan with no mode is report-only). v5.0 removes the hidden value aliases `host`/`redirect`/`vendor` (now an invalid-value usage error), and the hidden boolean spellings `--redirect`, `--vendor` and `--apply` (now unknown-argument usage errors). `--sync` selects agent mode, so `--sync` with any other `--mode` is a usage error (exit 2, enforced in `resolve_mode_flags` — clap's `conflicts_with` is value-independent); `--mode agent --sync` is accepted. `--prune` is an orthogonal GC knob and never conflicts — but hosted mode runs no GC, so `--mode hosted --prune` emits an explicit `redirect_prune_ignored` warning (JSON `warnings[]` + stderr) instead of silently dropping the flag | -| `scan` | `--prune` / `--sync` | — | `--prune` = GC after the scan (ignored with a `redirect_prune_ignored` warning in hosted mode); `--sync` = `--mode agent --prune` | +| `scan` | `--mode ` | — | The documented selector for the three patch-application modes (v5.0 default: `hosted`, except that a `--prune` or `--global`/`--global-prefix` scan with no mode is report-only). v5.0 removes the hidden value aliases `host`/`redirect`/`vendor` (now an invalid-value usage error), and the hidden boolean spellings `--redirect`, `--vendor` and `--apply` (now unknown-argument usage errors). `--sync` selects agent mode, so `--sync` with any other `--mode` is a usage error (exit 2, enforced in `resolve_mode_flags` — clap's `conflicts_with` is value-independent); `--mode agent --sync` is accepted. `--prune` is an orthogonal GC knob and never conflicts. Hosted mode keeps no `.socket/` state and sweeps none, so `--mode hosted --prune` emits an explicit `redirect_prune_ignored` warning (JSON `warnings[]` + stderr) instead of silently dropping that half of the flag. Hosted mode's own state is in the lockfiles: every hosted scan removes the pnpm registry entries no lockfile uses any more, with or without the flag, and under `--prune` the envelope's `gc` counts them (see "pnpm registry route", *Cleanup*) | +| `scan` | `--prune` / `--sync` | — | `--prune` = GC after the scan; `--sync` = `--mode agent --prune`. In hosted mode the `.socket/` sweeps do not run (`redirect_prune_ignored` warning), the unused pnpm registry entries go as on every hosted scan, and `gc.removedRegistryEntries` counts them. In every other mode, and with no mode, the GC pass removes those entries itself, from the lockfiles alone | | `scan` | `--package ` (repeatable or comma-separated) | `SOCKET_SCAN_PACKAGES` | (v5.0) Only scan these packages: a name (`lodash`, `@scope/pkg`, `requests`, `group:artifact`; matched against the full name or its last segment, case-insensitively; PyPI names compare by their PEP 503 canonical form, so `typing_extensions` matches `pkg:pypi/typing-extensions`) or a purl with or without a version (`pkg:npm/lodash` matches every version, `pkg:pypi/requests@2.31.0` only that one). Qualifiers are ignored. Filters the crawl like `--ecosystems`, after the prune universe is captured, so `--prune` still judges the full crawl | | `scan` | `--mode vendored` | — | Vendor every patched dependency instead of applying in place (conflicts with `--sync`, combines with `--prune`). Vendored mode is manifest-free (v5.0): the vendor ledger embeds the patch records and `.socket/manifest.json` is never written. The former opt-in for exactly that, `--detached`, is removed in v5.0 (unknown-flag usage error) | | `scan` | `--batch-size` | `SOCKET_BATCH_SIZE` | API batch chunk size. Unset (v5.0): `500` on the authenticated API (the server's per-request maximum), `100` on the public proxy; a given value applies on either endpoint (`0` is floored to `1`). A chunk whose request body would exceed 256 KiB (the public proxy's body cap) is split into consecutive smaller chunks, deterministically (greedy, in crawl order). A mid-run downgrade to the proxy keeps the chunks already formed | @@ -318,7 +318,30 @@ Beyond the globals above, each subcommand defines a small set of local arguments Each matching package instance is spliced, including scoped, quoted and nested-peer keys, one `redirect_pnpm_resolution` edit per changed instance (`rollback` / `remove` restore each from the npm registry — see "Hosted unwind coverage"). LF/CRLF and unrelated lock bytes are preserved. Unsupported matching instances refuse that dependency across the lockfile set; an already-hosted URL elsewhere cannot confirm a partial rewrite. -For a **9.0 root lock**, the CLI ensures `pnpm-workspace.yaml` carries `trustLockfile: true` (created with a root-only `packages:` scaffold, or appended while preserving user bytes; the added lines end as the file's own lines do, so a CRLF file stays CRLF). An existing file with no keys at all — empty, comments only, bare `---` / `...` / `%` directive lines — reads to pnpm like no file, but pnpm 8.x–10.4 refuse every command once it holds a key without `packages` ("packages field missing or empty", #1096), so it gets the same root-only `packages:` scaffold spliced in with the key, and follows the no-file rules below. pnpm 8–10.4 read a keyless file as every nested package (pnpm >= 10.5 as the root alone), so when `pnpm-lock.yaml` lists importers besides `.` the file is left untouched and the warning says to list the members under `packages:` after upgrading to pnpm >= 11 (or install with `--trust-lockfile`); the vendored mirror skips the file the same way. A keyless file holding several documents is not spliced (the shapes rule below). A project with no `pnpm-workspace.yaml` (or a keyless one) whose every pnpm pin — the installed `node_modules/.modules.yaml` `packageManager`, and package.json `packageManager`, `devEngines.packageManager` and `engines.pnpm` (at least one present) — names pnpm 9.0–10.4 gets no file (#734): those releases never read the key, and a created root-only workspace makes `pnpm add ` fail with ERR_PNPM_ADDING_TO_ROOT there; the warning names the pins and says to re-run after upgrading to pnpm >=11 (or install with `--trust-lockfile`). A pin naming a later pnpm, a range reaching past 10.4, an unparseable pin, or no pin keeps the scaffold, whose warning notes that pnpm 9.0–10.4 then need `pnpm add -w ` and that pinning that pnpm in package.json `packageManager` (then deleting the file and re-running) avoids it — provided every other pin names 9.0–10.4 too (the "every pin" rule above). **Known residual (#734)**: an unpinned project with no install record (no `node_modules/.modules.yaml`, no package.json pnpm pin — e.g. a fresh clone) still gets the root-only scaffold, since nothing shows its pnpm cannot read it; on pnpm 9.0–10.4 such a project needs `pnpm add -w ` to add dependencies, or a `packageManager` pin naming that pnpm so the scaffold is never created. pnpm >=11 requires this to accept hosted URLs; it disables registry re-verification for the whole lock, while sha512 tarball integrity remains enforced. The write (edit kind `redirect_pnpm_workspace_trust`) respects `--dry-run`, skips legacy locks and Rush repos, preserves explicit user settings (an existing top-level key in any YAML spelling: quoted, `trustLockfile :`, with a trailing comment; and a `pnpm_config_trust_lockfile` / `PNPM_CONFIG_TRUST_LOCKFILE` environment variable set to anything but `true` when the project's pnpm is >=11 or unknown, which pnpm reads ahead of the file, so nothing is written and the warning names the variable, #1514), and is disabled by `--no-trust-lockfile-config`. The key goes inside the document (before a `...` end marker); a file a line append would corrupt (a flow-style root, an indented root, several documents) is left untouched and the warning gives the manual recoveries. The vendored `overrides:` mirror in `pnpm-workspace.yaml` reads keys the same way and refuses those shapes before writing. The `redirect_pnpm_trust_lockfile` warning explains manual configuration when required and clean reinstall guidance for all pnpm versions. When every lock the run spliced is a Rush lock, the same warning code carries the Rush remedy instead (rush runs pnpm in `common/temp`, so neither the repo-root key nor `--trust-lockfile` reaches it): `pnpm_config_trust_lockfile=true rush install`, plus `"usePnpmFrozenLockfileForRushInstall": true` in `common/config/rush/experiments.json` on pnpm 11 (whose default Rush install otherwise re-resolves the hosted entries to upstream with exit 0), and `rush purge` before reinstalling. A re-run over a 9.0 Rush lock an earlier run already redirected (nothing spliced) re-issues the same Rush remedy; a run that also spliced a non-Rush pnpm lock keeps the generic text plus a Rush note. Existing installs and warm stores can retain upstream files; use a clean install tree and empty store, then verify installed files with `socket-patch vex`. Neither a successful install nor a local VEX export guarantees hosted SBOM recognition or changes dashboard alert actions/counts. +**pnpm lockfile verification**: pnpm >=11 checks every lock entry that records a tarball URL against a registry's version document and rejects the lock when the URLs differ (pnpm 11: `ERR_PNPM_TARBALL_URL_MISMATCH`, pnpm 12: `ERR_PNPM_LOCKFILE_RESOLUTION_VERIFICATION`). For a **9.0 root lock** (and members' own locks under `sharedWorkspaceLockfile: false`) the run therefore configures the root `pnpm-workspace.yaml` in one of the two ways below; `--no-trust-lockfile-config` opts out of both, and both keep the warning code `redirect_pnpm_trust_lockfile`. + +**pnpm registry route** (edit kinds `redirect_pnpm_workspace_named_registry` and `redirect_pnpm_workspace_override` in `pnpm-workspace.yaml`, `redirect_pnpm_registry_alias` and `redirect_pnpm_lock_override` in a lock; actions `created` / `added` / `rewritten` / `removed`): a reference grant for an npm package may carry `npmRegistryUrl`, the registry address of that patch: the directory its tarball is served from (`/patch/npm/////` on Socket's patch server). `GET
` answers the one-version document of the patched package, with the package's own dependency fields and `dist.tarball` the grant's tarball URL; any other name there is a 404, so the CLI only ever declares the address as a named registry, never as a scope or default registry. An address is fixed for the life of its patch, and what it answers depends on that patch alone. The CLI writes an address exactly as the patch service returns it, and takes it only when it is an `http(s)` URL that ends in `/`, its last path segment is the UUID of the granted patch, and the grant's tarball is a file of that directory (the artifact URL starts with the address). An absent address and every other shape read as no address, never as an error. The route is two entries **per patch** in the root `pnpm-workspace.yaml` and the lock pnpm itself writes for them: + +```yaml +namedRegistries: + socket-58f14d5a: https://patch.socket.dev/patch/npm/picomatch/2.3.1//58f14d5a-…/ +overrides: + 'picomatch@2.3.1': 'socket-58f14d5a:2.3.1' +``` + +The declaration is what pnpm verifies the lock entries against; the override is what makes pnpm resolve the package there every time it resolves, so `pnpm add`, `update`, `dedupe` and `install --fix-lockfile` keep the patched tarball (a declaration alone does not: see the [pnpm compatibility notes](../../docs/testing/pnpm-compatibility.md)). pnpm records an overridden release under its own key and records the overrides in the lock, and takes a lock that disagrees with the file for out of date, so the run rewrites every governing lock to exactly what pnpm writes (`` is the registry's name): the top-level `overrides:` entry `@: :` (in the file's order, in every governing lock, a member's own lock that holds no patched package included), the `packages:` and `snapshots:` keys `@:` (peer suffix kept, sections re-sorted), every reference (`: :`, the `(@:)` in another package's peer suffix), an importer's `specifier: :` / `version: :`, the `version:` line pnpm adds to a package whose key now contains a `:`, and no `deprecated:` line on the routed entry (the registry document carries none). The `resolution` keeps the tarball URL hosted mode writes today. The rewrite is pinned byte for byte to real pnpm by golden fixtures (`crates/socket-patch-core/tests/fixtures/pnpm-registry-overrides/`, regenerated by `scripts/gen-pnpm-registry-override-golden.mjs`), which pnpm 11.20.0 through 12.22.0 produce alike. No `trustLockfile` is written, and pnpm's verification stays on for every entry. + +**Registry names.** A registry is named after its patch: `socket-` and the first eight hex digits of the patch UUID, in lower case (`socket-58f14d5a`). When two patches of the project start with the same eight digits, or the project declares a registry of its own under that name, the name takes four more digits at a time (12, 16, … up to all 32) until it is free; every patch that shares the digits is lengthened, so each name still tells its patch. A registry is the CLI's only when its name has that shape (`socket-` and 8 to 32 lowercase hex digits) **and** its address is the serve directory of a patch whose UUID starts with those digits, on a patch server (Socket's own, a `--patch-server-url`, or the server a grant of the run is served from). An override is the CLI's only when it routes `@` to such a registry (`:`). Everything else in `namedRegistries`, in `overrides` and in a lock's `overrides:` is the user's and is never rewritten or removed: a registry of the user's under a name of that shape (`socket-58f14d5a: https://npm.corp.example/`) stays theirs, and so does one named `socket`. The one exception is a leftover: a name of that shape that `namedRegistries` does not declare at all, still used by an override or a lock key (an interrupted run), is the CLI's to clean up. **How a lock key is read.** Every reader of a pnpm lock (the hosted rewrite, `vex`, `list`, `rollback`, `remove`, vendoring, the lock inventory) takes a key `@:` for the release `@` only when `` has that shape, `socket-` and 8 to 32 lowercase hex digits: a lock is all they have to go by. A key through any other registry is a release from a registry of the project's own, never the npm release of the same name and version, whatever the registry is called: `leaf@socket:1.0.0` from a registry the project named `socket` is not read, not repointed and not counted. **A replaced patch renames its registry.** A patch that supersedes another for the same release has a new UUID, so its registry has a new name and a new address. The scan that is granted it rewrites the `namedRegistries` entry, the override's value, the lock's `overrides:` record and every lock key and reference of that release (`@socket-:` becomes `@socket-:`), with the new tarball and integrity. That is the whole diff of a superseded patch, and it is larger than the two `resolution` lines the `trustLockfile` path changes. + +The route is taken only when **all** of these hold; otherwise the run takes the `trustLockfile` path below with the locks in the plain shape (a lock half routed would fail to install): (1) the project's own root file is the one pnpm reads (not a workspace member whose settings live in an ancestor file, #880), every governing lock is lockfileVersion 9 (Rush and legacy locks keep their own guidance); (2) every Socket-hosted tarball the governing locks record after the run has a registry: this run was granted it **with** a registry address, or an earlier run routed it, this run was **not** granted it, and the files still route it (the lock keys the release by a registry of the CLI's, the workspace file has its override to that registry, and the registry's address is the directory the tarball is served from). So a run granted only part of the project's patches (a scan of one subtree of a monorepo with one root lock, a search that lists fewer patches than the lock pins) leaves the rest routed and rewrites nothing for them. A pin this run was granted **without** an address is never kept that way (the grant overrules the files), and neither is an ungranted pin the files do not route: either one puts the whole lock on `trustLockfile` and is named. A pin on a patch mirror (`--patch-mirror-url`, experimental) has no address either, whatever its grant carries: see "Patch mirror (experimental)". A tarball is Socket-hosted when this run pinned it or its URL has the patch server's path shape, and every other tarball is the user's own; (3) every pnpm pin of the project (the sources of the #734 rule below, at least one present) proves pnpm 11.20 or newer: the lowest version it admits is 11.20 or higher (`11.28.13`, `^11.20.0`, `>=11.20`, `12`, `>=12`, `12 || 13`, `11.20.0 - 13.0.0`; `>` is read as `>=`, so `>11.19` proves nothing), since older releases write another lock for the same override; a range that reaches below it (`>=11`, `^11`), one the CLI cannot read, or pins that disagree prove nothing; (4) the workspace file can be read, is not a keyless file beside a lock that lists workspace members (#1096), and is a shape a line splice can extend (not a flow-style or indented root, several documents, a `namedRegistries` or `overrides` value on one line, a repeated key, an entry that is not a one-line `key: value`); (5) no override of the user's targets a patched package, by any selector (``, `@`, `>`): pnpm applies one override per dependency, so the CLI's would lose to it or displace it, and the user's is never overwritten. It is looked for in pnpm-workspace.yaml, the one place the gated pnpm releases read overrides from (`pnpm.overrides` and `resolutions` in package.json are not read by pnpm 11.20 and later, measured through 12.22.0); (6) each lock is one the rewrite was captured against: the release is not a `pnpm patch` copy or an npm alias, an importer that depends on it asks through a plain semver range that admits it (not a tag, `catalog:`, `workspace:`, `npm:` or a URL), no importer locks another version of the package through a range that admits the patched one, no package is installed both with and without the release as its peer (pnpm 11 and 12 lock that differently), the release is not installed as another package's optional peer (pnpm resolves that copy around an override, so it would stay unpatched), and every entry of the lock is one run of lines (a `deprecated:` message of several paragraphs, or one that keeps its trailing line breaks, is written with empty lines inside its entry; a message of several lines without one is a block the routed entry simply loses); (7) no package version is pinned to two patches (an override routes a package version to one registry, and a registry serves one patch); (8) `--no-trust-lockfile-config` is not set, or the file already holds the route exactly. The write respects `--dry-run` and is refused through a symlink. + +**What the warning says.** A patch service that gives no pin of the project a registry address offers no route, and the run and its warning are exactly what they were. As soon as one pin has an address, a run that still ends on `trustLockfile` says why, in one sentence of the `redirect_pnpm_trust_lockfile` warning ("Per-package registry verification was not set up because …"): the hosted packages the patch service gave no address for, by `name@version` (the first five, then "and N more"), since one of them puts the whole lock on `trustLockfile`; the hosted packages pinned on a patch mirror, named the same way; pins that do not prove pnpm 11.20; and whichever of (4) to (7) applied, naming the file, the override or the lock entry. With no pnpm pin at all (and not under `--no-trust-lockfile-config`) the sentence is instead that pinning pnpm 11.20 or later (for example with package.json `packageManager`) and re-running the scan switches the project to per-package registry verification. On the route the warning's detail says the file declares the patch server's registry of each patched package (the `socket-` entries, one per patch) and routes each patched release to its own, to commit it alongside the lock, and keeps the rebuild-the-lockfile and clean-reinstall cautions; it carries no whole-lock tradeoff note. **A newer release in range (a note, never a refusal).** An override keyed `@` applies to every dependency whose range admits that version, and a lock records what a transitive dependent resolved, not the range it asked through. So when a governing lock also holds a newer release of a routed package within the routed release's caret range (the same major, or the same minor below 1.0), on the default registry, the detail ends with a note that names the package and both versions: "pnpm-lock.yaml also locks `` at ``, which a range that admits `` may admit too: a package that depends on `` through such a range moves to the patched `@` the next time pnpm resolves (`pnpm add`, `update`, `dedupe`), …". The lock is written as it is (pnpm installs it frozen, and re-locks it unchanged, until a command resolves the project again: see the [pnpm compatibility notes](../../docs/testing/pnpm-compatibility.md) for what each command does). The note is reported on every run that leaves the project routed, a re-run that changes nothing included (in human mode after the one-line reminder), and changes neither the route nor the exit code. + +**The file edit.** The file is created with the root-only `packages:` scaffold; a file with no keys gets the scaffold and the two maps; otherwise each map is appended after the last non-empty line (before a `...` end marker), or its missing entries are inserted after the map's last entry at its own indent. These are line splices: every other byte and the file's line endings are kept. Each registry and each override is one line. A file the run creates lists the registries by name and the overrides by key; an entry added to a map that already has entries goes after the map's last entry, so a file that grew over several runs lists the patches in the order they arrived (pnpm reads either, and the lock's `overrides:` record follows the file's order). An entry of the CLI's already as wanted is a byte-stable no-op (so is the whole re-run). `trustLockfile` plays no part here: an explicit non-true value or a `pnpm_config_trust_lockfile` variable blocks nothing. A `trustLockfile: true` an earlier run wrote is removed in the same run (a `redirect_pnpm_workspace_trust` edit with action `removed`) when the file's bytes prove that run wrote it: the file is exactly what the trust write creates (its `packages:` scaffold stays), or a keyless document plus exactly the lines that write splices into one. Any other `trustLockfile: true` is left untouched (v5 keeps no record of who wrote a line) and the warning says the hosted patches no longer need it. The `registries: {: {prefix: …}}` spelling pnpm 12 also reads is never written: pnpm 10 fails on it. The registry's version document is dated by the upstream release of the version (undated when unknown), so pnpm's default `minimumReleaseAge` does not hold back a freshly published patch. + +**Cleanup.** Nothing of the route outlives its use, the file and the locks always change together (pnpm refuses a frozen install when a lock's `overrides:` and the file's disagree), and nothing of the user's is touched. Cleanup is per patch: a patch's registry, its override, the locks' record of that override and the lock keys spelled through the registry go together. *Re-scan*: the entries follow the pins. A package that left the lock (removed, or upgraded to a release with no patch) loses its registry and its override in the file and the override's record in every lock; a patch that supersedes another for the same release brings its own registry, so the release's override, lock keys and tarball move to it and the replaced patch's registry is removed (see *A replaced patch renames its registry*); an override or a registry of the CLI's that no governing lock references (an interrupted run, a registry no longer needed) is removed, also by a hosted run that touches no hosted pnpm pin or selects no patch at all, which then writes no `trustLockfile` and no warning. *Leaving the route*: a routed project whose next run does not qualify (a pin without an address, a pnpm pin below 11.20, an override of the user's) is put back in that run: every registry key of the locks back to `@` with its references, each importer's specifier back to what its package.json asks for, the locks' `overrides:` entries and both maps of the file removed, `trustLockfile: true` in their place; the warning says so. When a lock cannot be converted (an importer's package.json no longer names the package; a governing lock the edits cannot read, such as one with mixed line endings, that still names a registry) lock and file stay routed, whole, and the warning says that instead: the route is never taken out of the workspace file while a lock beside it may still install through it. A file the route created is then no file of the user's: whether the project should have a workspace file at all is decided as for a project with none (#734), so for a project now pinned to pnpm 9.0–10.4, or under a `trustLockfile` variable of the environment, the scaffold is not topped up with `trustLockfile` and is deleted with the route. *A routed release is never left half moved*: a run that does not update the workspace file (`--no-trust-lockfile-config`; a file it cannot read; a lock that could not be converted back) leaves each routed release on the patch it is routed to. A newer patch of such a release has another registry, so its tarball under the old registry's key, override and declaration is one pnpm refuses and its next resolve replaces; the lock entry is left as it was, the newer patch is `skipped` / `redirect_unconfirmed`, and a `redirect_pnpm_registry_held` warning names the release and what moves it (re-run without the flag). *`rollback`, `remove`, and a hosted → vendored takeover*: each restored release gets its plain key, its references, its importer specifier (from package.json; a pin whose specifier cannot be read is refused and stays as it is) and the upstream resolution back; its registry and its override leave the file, and the override's record leaves every governed lock's `overrides:` block, in the same step; the block goes when it held only the CLI's (the user's entries stay), and the other patches' registries and overrides are not touched. The workspace file serves every lock of the workspace, so a routed pin is restored only when all of them can be accounted for: when the workspace's member locks cannot be listed, or a lock the file governs is one the edits cannot read while it still names a registry, the pin is refused and stays hosted (a failed restore that says why), with no file changed, rather than restored beside an override that would re-apply it or stripped of entries another lock still installs through. A file left exactly as a run created it is deleted, a keyless file has the scaffold taken back out, and any other file keeps the user's bytes. That holds for every command that takes the last of a route out, a hosted scan included: its rewrite carries writes only, so it writes such a file back as its `packages:` list and the scan deletes it once the writes have landed (the file is listed in `redirect.rewrittenFiles` like any file the run changed; one that could not be deleted is a `registry_cleanup_failed` warning naming it); the in-memory engine reports it in `deletedFiles` instead of `changedFiles`. A dry run deletes nothing. *Leaving hosted mode for agent mode*: `scan --mode agent` patches installed files and unwinds no hosted lockfile wiring, so a routed project keeps its pins and with them the whole route, which the lock still installs through; the run says so (`hosted_wiring_retained`, naming each package) and nothing is removed, `--prune` / `--sync` included, because every entry is in use. `rollback` or `remove` (or `scan --mode vendored`) is what takes a pin and its route out together; what is left unused after that is removed by `repair` or `scan --prune`. *Which commands clean up, and when*: a registry entry (a registry of the CLI's, an override of the CLI's, its record in a lock) is unused when no governed lock keys a release by that registry any more, which the files alone tell exactly, and it is removed by (1) every `scan --mode hosted`, with no extra flag, as part of its rewrite, also when the scan selects no patch or crawls no package at all (a scan that redirects nothing takes the apply lock for this tidying alone, and a lock it cannot have, because another run holds it or the checkout cannot be written, is no error: the run goes on, exits as it would have, and the entries wait for the next scan); (2) `scan --prune` and `scan --sync` in any other mode, and `scan --prune` with no mode, in their GC pass; (3) `repair`, in its cleanup phase (`--download-only` skips it); (4) `rollback`, `remove`, the withdrawn-patch restore of a scan and a hosted → vendored takeover, for the releases they restore. (2) and (3) read the project's files alone and ask no patch service or registry, so they work `--offline`; they cannot know that a patch was withdrawn, so a release a lock still routes keeps everything it needs until a scan restores it. With several governed locks an entry goes only when none of them uses it. A dry run of each lists the same removals and writes nothing. *What is reported*: each entry taken out by (1) to (3) is an artifact-level event (no `purl`), `removed` or, on a dry run, `verified`, with `errorCode: "registry_entry_unused"` and `details: {mode: "hosted", file, entry, key, value?}`: `entry` is `registry` (a `namedRegistries` entry; `key` its name, and no `value`), `override` or `lockOverride` (`key` the release, `value` the override's value) or `lockKey` (a lock key spelled back to `@` when a run leaves the route; `value` the key it had). An address holds a grant's token, so no event or line of output carries one. The registry of a patch that was superseded is reported the same way (one `registry` entry), while its release stays routed through the new patch's. The events bump no `summary` counter; `gc.removedRegistryEntries` is their count, reported by `repair`, by `scan --prune` / `--sync` and, in hosted mode, only under `--prune` (hosted mode reports no `gc` otherwise). Human mode prints `Removed N pnpm registry entries that no lockfile uses any more:` (`Would remove …` on a dry run) and one line per entry. Two warnings: `registry_cleanup_skipped` (the pnpm locks or the workspace file could not be read to tell what still uses the route; nothing was removed) and `registry_cleanup_failed` (the cleaned files could not be written; they are as they were, or the detail names each one that is not). The releases restored by (4) are reported as that command's own events (`rolledBack`, `hosted_reverted`), not entry by entry. Limits: a routed entry's `deprecated:` line is not put back (pnpm restores it the next time it resolves); and a registry on a host the run does not know for a patch server (not Socket's, not `--patch-server-url`, not the host of a grant of the run) is taken for the user's and left alone. The commands that tidy from the files alone have no grant to go by, so on a patch server other than Socket's they need the setting; without it they say what they passed over instead of doing nothing without a word. `repair`, the `--prune` pass and a hosted scan that crawled no package report one `registry_cleanup_unknown_host` warning per host that holds registries in the shape hosted mode writes (a `socket-` name at an address that is a patch's directory, its UUID starting with those digits): how many registries, the host as its origin only (`https://host[:port]`, never the path, which holds the grant's token), and that `--patch-server-url ` / `SOCKET_PATCH_SERVER_URL` lets the command tidy them. The warning is reported whether or not any of those registries is unused (the run cannot tell), on a dry run too, and changes neither the exit code nor what is the user's: the registries stay untouched. A person reads it as one line: `Warning: …` on stderr from `repair`, `GC: ….` from the `--prune` pass. Shapes an unreleased build wrote are converted to the registries above by the next scan that routes the project, or removed with their package, with nothing of them left, but only where pnpm-workspace.yaml proves them the CLI's (a declaration at an address that build wrote, on a patch server): the hosted run then respells such lock keys under today's names before anything else reads the lock, and no other command reads a key through one of those names. They are: a registry per patch named `socket-patch-`, with no override, with the override value `socket-patch-:` or with `socket-patch-:@`; and one registry for the whole project named `socket` or `socket-patch` (either also with `-`) at an address of the form `/patch/npm/~/./` (a name of that kind at any other address is the user's). + +**pnpm `trustLockfile`**: when the registry route above does not apply, for a **9.0 root lock** the CLI ensures `pnpm-workspace.yaml` carries `trustLockfile: true` (created with a root-only `packages:` scaffold, or appended while preserving user bytes; the added lines end as the file's own lines do, so a CRLF file stays CRLF). An existing file with no keys at all — empty, comments only, bare `---` / `...` / `%` directive lines — reads to pnpm like no file, but pnpm 8.x–10.4 refuse every command once it holds a key without `packages` ("packages field missing or empty", #1096), so it gets the same root-only `packages:` scaffold spliced in with the key, and follows the no-file rules below. pnpm 8–10.4 read a keyless file as every nested package (pnpm >= 10.5 as the root alone), so when `pnpm-lock.yaml` lists importers besides `.` the file is left untouched and the warning says to list the members under `packages:` after upgrading to pnpm >= 11 (or install with `--trust-lockfile`); the vendored mirror skips the file the same way. A keyless file holding several documents is not spliced (the shapes rule below). A project with no `pnpm-workspace.yaml` (or a keyless one) whose every pnpm pin — the installed `node_modules/.modules.yaml` `packageManager`, and package.json `packageManager`, `devEngines.packageManager` and `engines.pnpm` (at least one present) — names pnpm 9.0–10.4 gets no file (#734): those releases never read the key, and a created root-only workspace makes `pnpm add ` fail with ERR_PNPM_ADDING_TO_ROOT there; the warning names the pins and says to re-run after upgrading to pnpm >=11 (or install with `--trust-lockfile`). A pin naming a later pnpm, a range reaching past 10.4, an unparseable pin, or no pin keeps the scaffold, whose warning notes that pnpm 9.0–10.4 then need `pnpm add -w ` and that pinning that pnpm in package.json `packageManager` (then deleting the file and re-running) avoids it — provided every other pin names 9.0–10.4 too (the "every pin" rule above). **Known residual (#734)**: an unpinned project with no install record (no `node_modules/.modules.yaml`, no package.json pnpm pin — e.g. a fresh clone) still gets the root-only scaffold, since nothing shows its pnpm cannot read it; on pnpm 9.0–10.4 such a project needs `pnpm add -w ` to add dependencies, or a `packageManager` pin naming that pnpm so the scaffold is never created. Without a named registry pnpm >=11 requires this to accept hosted URLs; it disables registry re-verification for the whole lock, while sha512 tarball integrity remains enforced. The write (edit kind `redirect_pnpm_workspace_trust`) respects `--dry-run`, skips legacy locks and Rush repos, preserves explicit user settings (an existing top-level key in any YAML spelling: quoted, `trustLockfile :`, with a trailing comment; and a `pnpm_config_trust_lockfile` / `PNPM_CONFIG_TRUST_LOCKFILE` environment variable set to anything but `true` when the project's pnpm is >=11 or unknown, which pnpm reads ahead of the file, so nothing is written and the warning names the variable, #1514), and is disabled by `--no-trust-lockfile-config`. The key goes inside the document (before a `...` end marker); a file a line append would corrupt (a flow-style root, an indented root, several documents) is left untouched and the warning gives the manual recoveries. The vendored `overrides:` mirror in `pnpm-workspace.yaml` reads keys the same way and refuses those shapes before writing. The `redirect_pnpm_trust_lockfile` warning explains manual configuration when required and clean reinstall guidance for all pnpm versions. When every lock the run spliced is a Rush lock, the same warning code carries the Rush remedy instead (rush runs pnpm in `common/temp`, so neither the repo-root key nor `--trust-lockfile` reaches it): `pnpm_config_trust_lockfile=true rush install`, plus `"usePnpmFrozenLockfileForRushInstall": true` in `common/config/rush/experiments.json` on pnpm 11 (whose default Rush install otherwise re-resolves the hosted entries to upstream with exit 0), and `rush purge` before reinstalling. A re-run over a 9.0 Rush lock an earlier run already redirected (nothing spliced) re-issues the same Rush remedy; a run that also spliced a non-Rush pnpm lock keeps the generic text plus a Rush note. Existing installs and warm stores can retain upstream files; use a clean install tree and empty store, then verify installed files with `socket-patch vex`. Neither a successful install nor a local VEX export guarantees hosted SBOM recognition or changes dashboard alert actions/counts. **npm hosted-mode `allow-remote` contract**: npm >=12 defaults `allow-remote=none` and refuses (EALLOWREMOTE) every lockfile entry whose `resolved` tarball is not served by the configured registry — exactly what a hosted redirect writes into `package-lock.json` / `npm-shrinkwrap.json`. Whenever a run leaves a ROOT npm lock carrying a granted hosted artifact URL (spliced this run, or already redirected by an earlier one — a missed config heals on re-run), the CLI ensures `allow-remote=all` in the project-root `.npmrc`: the file is created holding exactly `allow-remote=all\n` when absent, otherwise one `allow-remote=all` line is spliced in after the last non-empty top-level line (before any ini `[section]` header), in the file's own line ending, with the BOM, CRLF and trailing-newline shape preserved. The write lands in `redirect.rewrittenFiles` (edit kind `redirect_npmrc_allow_remote`), respects `--dry-run` (nothing written; the warning says what would be — including for a vendored → hosted takeover the dry run only previews), and is disabled by `--no-npm-allow-remote-config` / `SOCKET_NO_NPM_ALLOW_REMOTE_CONFIG`. The `.npmrc` grammar is npm's own `ini` parser's (cross-checked against it): lines split on any run of `\r` / `\n` (a bare `\r` ends a line), only the exact key `allow-remote` counts after ini unquoting (npm ignores `allow_remote` / `ALLOW-REMOTE` in a `.npmrc`; such a line is left alone and the real key appended), comment lines are ignored, a `[section]` header is recognized only as npm does — on the UNTRIMMED line (an indented or BOM-prefixed `[sec]` is a plain top-level key) — and ends the top-level scope, quotes and inline comments are stripped, the LAST top-level assignment wins, and the value is case-sensitive. An explicit other value (`allow-remote=none` / `root` / anything but `all`) is RESPECTED and never rewritten — the pnpm `trustLockfile: false` precedent — in the project `.npmrc` AND in every other npm config layer npm would consult: an `npm_config_allow_remote` environment variable (any spelling npm normalizes; it beats every `.npmrc`, so a project write could not take effect), and — when the project file sets nothing — the user (`npm_config_userconfig` / `~/.npmrc`), global (`npm_config_globalconfig` / `/etc/npmrc`, prefix from `npm_config_prefix`, the user/builtin config, `PREFIX` or the `node` binary's install root) and builtin (npm's own `npmrc` beside the `node` binary: `/lib/node_modules/npm/npmrc`, `\node_modules\npm\npmrc` on Windows) config files — path values `${VAR}`-expanded and `~`-expanded like npm, env names case-insensitive on Windows, where a committed project line would silently override a machine / org policy. A symlinked, non-regular or unreadable `.npmrc`, or one with bare-`\r` line endings (npm splits on them, the line splice does not), is left untouched. Every variant emits the `redirect_npm_allow_remote` warning (written / would write / already set / explicit value respected — naming the project file, the env var, or the user/global/builtin config path — / opted out / unreadable or unsupported), always with the tradeoff: `allow-remote=all` lets npm install ANY url-resolved dependency, not just Socket's patched ones, while the per-entry sha512 integrity pins stay enforced; the remedy for the non-writing variants is `allow-remote=all` in `.npmrc` or `npm ci --allow-remote=all`. npm <=11 is unaffected (11 defaults to `all`, <=10 has no such setting). **Unwind (v5.0: no ledger)**: once `rollback`, `remove` or a hosted → vendored takeover has restored the last hosted entry of the root `package-lock.json` / `npm-shrinkwrap.json` to its upstream registry entry (see "Hosted unwind coverage"), a project `.npmrc` holding exactly `allow-remote=all\n` (the file hosted mode creates) is deleted; any other `.npmrc` that still has a top-level `allow-remote=all` line is left untouched and the `npm_allow_remote_left` warning says the line may be removed if nothing else needs it (v5 keeps no record of whether hosted mode added it, so it is never removed behind the user's back). The rewrite's stage file is created with the `.npmrc`'s own permission bits (a 0600 token-bearing file is never staged world-readable). **Vendored mode is unaffected by `allow-remote`**: its `file:.socket/vendor/…` resolutions are npm `file` specs, which npm >= 11.14 gates by `allow-file` (default `all`), never `allow-remote` — verified by the real npm 12 vendored matrix. **npm vendored `allow-file` contract (#969)**: `allow-file=none` refuses every `file:` dependency, and any other non-`all` value (`root`) admits one only when the project root or a workspace declares it and resolves to that very lock node (arborist's `_isRoot`); otherwise every `npm ci` / `npm install` fails EALLOWFILE. The effective value is read from the same npm config layers as `allow-remote` (an `npm_config_allow_file` environment variable, then the project `.npmrc`, then the user / global / builtin config files). When it refuses a `package-lock.json` / `npm-shrinkwrap.json` instance of a vendored `name@version` (the set vendoring rewires), the vendored run (`vendor`, `scan` / `get --mode vendored`, dry runs and in-sync re-runs included) still vendors, leaves the setting untouched, and records the `vendor_npm_allow_file` advisory naming the setting's source, the refused lock entries and the remedy (`allow-file=all` in the project `.npmrc`, unsetting the env var, or `npm ci --allow-file=all`); `vendor --check` fails that entry `vendor_check_failed` with the same reason. Other npm-family flavors (yarn, pnpm, bun, vlt) do not read `allow-file` and are not checked. @@ -381,7 +404,7 @@ For a **9.0 root lock**, the CLI ensures `pnpm-workspace.yaml` carries `trustLoc **Agent-flow run-level warnings (additive).** An agent-mode apply (`--mode agent` / `--sync`, `--json`) may add a top-level `warnings[]` array of `{code, detail}` entries to the scan envelope (absent when none fired; each is also mirrored to stderr unless `--silent`). They surface cross-mode state the apply cannot change — never a status or exit-code change (hosted refusals set the precedent: exit 0 + warning). Codes (stable; new codes are additive/MINOR): `vendored_ownership_retained` — vendor-owned package(s) were skipped before download (each is also a `skipped` / `vendored` event); the detail names the purls and the migration path (`remove `, or `vendor --revert` which unwinds every vendored package, then re-run). `hosted_wiring_retained` — the lockfiles still pin scanned package(s) to a hosted patch (the agent run does not unwind hosted wiring — as of v5.0 that is `socket-patch rollback`'s job, which restores the upstream registry entries, or `remove ` per package); the detail names the purls and the options (stay `--mode hosted`, migrate via `scan --mode vendored`, or `socket-patch rollback`). The warning keys on the hosted pins lockfile discovery finds at scan time, so a flow that restored the upstream entries retires it. The human path prints the same `hosted_wiring_retained` text to stderr after an apply; the vendored counterpart is already covered by its per-package `[skip] … (vendored …)` lines. `ownership_not_restored` (v5.0; `apply` and `rollback` `warnings[]` alike) — a file WAS patched (or restored) but could not be given its original uid/gid (its mode is kept; the group is kept when the caller belongs to it); the detail is `: : patched, but ownership could not be restored to uid N gid M: ` and the human line `Warning: ` (stderr, muted by `--silent`); never a status or exit change. `go_installed_tool_stale` (v5.0; `apply`, dry runs included) — a `--global` Go apply patched a module cache copy that a tool installed with `go install` was built from before the patch; the detail names the binary and the `go install @` remedy (or, when they can't be inspected, what could not be checked); never a status or exit change. `stale_bytecode_not_removed` (`apply` and `rollback` `warnings[]` alike) — a `.py` file WAS patched (or restored) but CPython bytecode compiled from its previous bytes (`__pycache__/.[.opt-N].pyc`) could not be deleted, so Python may keep running the old code until it is removed; the detail is `: could not remove stale Python bytecode (: , …); …` and the human line `Warning: `; never a status or exit change. `patch_files_skipped` (`apply --force`) — a file of the patch is not on disk and was skipped; the detail is `: N patch file(s) not found on disk and skipped (--force): , …` and the human line `Warning: `. The package's event is `applied` with the files that were written, or, when the run wrote none and the files that exist are patched, `skipped` / `already_patched`; never a status or exit change. `cargo_build_cache_stale` (v5.0; `apply` and `rollback` `warnings[]` alike) — a cargo crate's bytes changed but its compiled copy in a project build directory could not be invalidated (a fingerprint directory that could not be removed, or a `build.build-dir` with a `{workspace-path-hash}` template); the detail names the crates to `cargo clean -p` before the next build, which may otherwise link the stale code; never a status or exit change. -`scan --prune` opts into garbage collection. When set, `scan` removes manifest entries for packages no longer present in the crawl, then deletes orphan blob files, and every obsolete diff and package archive, from `.socket/`. A blob is an orphan when no patch left in the manifest references it: the afterHash and beforeHash blobs of every remaining patch are kept, the same retention policy `repair` uses (the beforeHash blobs are an offline rollback's only restore data, and `repair` downloads afterHash blobs only). Diff and legacy package archives are never kept, even for a remaining patch: nothing reads them any more. Off by default (v3.0) so a temporary uninstall doesn't silently destroy manifest state. Under `--global`/`--global-prefix` the crawl covers only the global installs while the manifest is still `--cwd`'s, so the prune also keeps every entry the `--cwd` project accounts for (its installed packages and its lockfile-listed ones, exactly what the project's own `--prune` keeps): a global prune removes only entries neither scope has. Only entries whose ecosystem this run actually crawled are eligible: a `pkg:/` with no crawler in this build (a newer CLI's ecosystem in the committed manifest) is exempt — the crawl never looked for them, so their absence is not evidence of removal (same fail-safe as the `--ecosystems` filter, which narrows the query but never the prune's installed set). A Cargo entry is also exempt while its agent-mode copy is still patched: the project crawl looks up only the crates `Cargo.lock` resolves, but a crate the lock bumped or dropped keeps its patched copy in the machine-wide `$CARGO_HOME/registry/src` cache (nothing deletes it), and the entry holds the only blobs that can restore that copy. The wet pass keeps it with a `cargo_cache_patch_kept` warning naming the `socket-patch rollback ` that restores the copy and drops the entry; the `--dry-run` preview reports no event (and no warning) for it. A PyPI entry is exempt the same way: a project with no environment of its own is crawled only for the packages it declares, in the one interpreter it installs into, so a package it stopped declaring, or one an earlier release patched in another interpreter or a tool's environment, drops out of the crawl with its copy still patched. The copies `rollback ` restores are looked up by PURL, and for a project that installs into a shared interpreter so are the ones `rollback --global` restores (a project with an environment of its own never patched a copy outside it). The wet pass keeps an entry with a still-patched copy with a `pypi_installed_patch_kept` warning. A prune that an empty crawl skips drops no record, and reports the same warning for each recorded PyPI patch that is still on disk. The pass also reconciles vendored state (runs FIRST, under ONE apply-lock acquisition shared with the manifest prune — lock contention skips the whole pass without failing the scan; `--lock-timeout` is honored and a lock I/O error is reported rather than swallowed; the existence gate — a manifest file OR a vendor ledger file, both cheap stats; an emptied ledger is deleted on save, so its presence is its content proxy — runs BEFORE the lock, so a bare project never gets a `.socket/`; in the vendored scan arms the pass runs AFTER the vendor step): (a) ledger entries still tracked by a manifest record (manifest-mode entries written by standalone `vendor`) whose patch is gone from the manifest are reverted — `detached` entries (every `scan`/`get --mode vendored` entry, v5.0) have no manifest record to lose and are exempt from this leg; (b) EVERY ledger entry whose dependency is no longer in the lockfile graph is reverted and any manifest entry it still had dropped (v5.0: the check is about the lockfile, not the manifest, so embedded-record entries are no longer exempt; a missing or undeterminable lockfile keeps the entry, fail-safe); and (c) orphan `.socket/vendor//` dirs with no ledger entry are swept. The prune never deletes a zero-patch `.socket/manifest.json` (its `{"patches": {}}` + `setup` block stay). Under `--json` (v5.0, MAJOR) the pass is recorded into the scan envelope: each pruned manifest entry is a `removed` event with `details.manifest: true`, each reverted vendored entry a `removed` event (`errorCode: "vendor_reverted"`, `details.mode: "vendored"`), each drift-kept entry a `skipped` / `vendor_revert_kept` event and each entry whose revert failed a `skipped` / `vendor_revert_failed` event (a GC revert failure never fails the run); a `--dry-run` preview reports the removals as `verified`. The artifact sweep is the envelope's `gc` (`summary.bytesFreed` mirrors it) and the orphan vendor dirs swept are the top-level `removedVendorOrphanDirs` count. The pass's warnings join the top-level `warnings[]`: `vendor_state_write_failed` (entries were reverted but the ledger rewrite failed), `manifest_write_failed` (the pruned manifest could not be written: no entry was pruned and no blob, diff or package archive was swept, since the manifest on disk still references them), `cleanup_failed` (an orphan sweep failed mid-way, or `.socket/` or one of its `blobs/`, `diffs/`, `packages/` directories is a symlink, which is never swept), `cargo_cache_patch_kept` (see above), and the reinstall advisories of the vendored reverts (`vendor_bun_reinstall_required`, `vendor_vlt_reinstall_required`, `vendor_pypi_reinstall_required`; a revert's other warnings, such as `vendor_lock_entry_removed` or a drift keep's, are not repeated). A pass skipped at the lock (`lock_held` | `lock_io`) has no `gc` and no events, only a `gc_skipped` warning whose detail ends with the code. Human mode prints `GC: skipped: .`, one `GC: .` line per warning, and `GC: failed to revert N vendored entries: …` (singular for one). A drift keep is an entry the revert deliberately preserved (`vendor_artifact_kept` — undo the drift and re-run `vendor --revert` to finish); the preview cannot see drift (backends return before the wiring replay on dry runs), so its `verified` reverts may over-promise what a wet run will actually reclaim. +`scan --prune` opts into garbage collection. When set, `scan` removes manifest entries for packages no longer present in the crawl, then deletes orphan blob files, and every obsolete diff and package archive, from `.socket/`. A blob is an orphan when no patch left in the manifest references it: the afterHash and beforeHash blobs of every remaining patch are kept, the same retention policy `repair` uses (the beforeHash blobs are an offline rollback's only restore data, and `repair` downloads afterHash blobs only). Diff and legacy package archives are never kept, even for a remaining patch: nothing reads them any more. Off by default (v3.0) so a temporary uninstall doesn't silently destroy manifest state. Under `--global`/`--global-prefix` the crawl covers only the global installs while the manifest is still `--cwd`'s, so the prune also keeps every entry the `--cwd` project accounts for (its installed packages and its lockfile-listed ones, exactly what the project's own `--prune` keeps): a global prune removes only entries neither scope has. Only entries whose ecosystem this run actually crawled are eligible: a `pkg:/` with no crawler in this build (a newer CLI's ecosystem in the committed manifest) is exempt — the crawl never looked for them, so their absence is not evidence of removal (same fail-safe as the `--ecosystems` filter, which narrows the query but never the prune's installed set). A Cargo entry is also exempt while its agent-mode copy is still patched: the project crawl looks up only the crates `Cargo.lock` resolves, but a crate the lock bumped or dropped keeps its patched copy in the machine-wide `$CARGO_HOME/registry/src` cache (nothing deletes it), and the entry holds the only blobs that can restore that copy. The wet pass keeps it with a `cargo_cache_patch_kept` warning naming the `socket-patch rollback ` that restores the copy and drops the entry; the `--dry-run` preview reports no event (and no warning) for it. A PyPI entry is exempt the same way: a project with no environment of its own is crawled only for the packages it declares, in the one interpreter it installs into, so a package it stopped declaring, or one an earlier release patched in another interpreter or a tool's environment, drops out of the crawl with its copy still patched. The copies `rollback ` restores are looked up by PURL, and for a project that installs into a shared interpreter so are the ones `rollback --global` restores (a project with an environment of its own never patched a copy outside it). The wet pass keeps an entry with a still-patched copy with a `pypi_installed_patch_kept` warning. A prune that an empty crawl skips drops no record, and reports the same warning for each recorded PyPI patch that is still on disk. The pass also reconciles vendored state (runs FIRST, under ONE apply-lock acquisition shared with the manifest prune — lock contention skips the whole pass without failing the scan; `--lock-timeout` is honored and a lock I/O error is reported rather than swallowed; the existence gate — a manifest file OR a vendor ledger file, both cheap stats; an emptied ledger is deleted on save, so its presence is its content proxy — runs BEFORE the lock, so a bare project never gets a `.socket/`; in the vendored scan arms the pass runs AFTER the vendor step): (a) ledger entries still tracked by a manifest record (manifest-mode entries written by standalone `vendor`) whose patch is gone from the manifest are reverted — `detached` entries (every `scan`/`get --mode vendored` entry, v5.0) have no manifest record to lose and are exempt from this leg; (b) EVERY ledger entry whose dependency is no longer in the lockfile graph is reverted and any manifest entry it still had dropped (v5.0: the check is about the lockfile, not the manifest, so embedded-record entries are no longer exempt; a missing or undeterminable lockfile keeps the entry, fail-safe); and (c) orphan `.socket/vendor//` dirs with no ledger entry are swept. The pass also takes out the entries of hosted mode's pnpm registry route that no lockfile uses any more (see "pnpm registry route", *Cleanup*): from pnpm-workspace.yaml and the pnpm locks alone, under the same lock, for a project that holds something of a route (which then passes the existence gate without a manifest or a ledger; the lock's `.socket/` is removed again when it stays empty); never under `--global`. A run whose crawl found nothing still does this half and the vendored one. The prune never deletes a zero-patch `.socket/manifest.json` (its `{"patches": {}}` + `setup` block stay). Under `--json` (v5.0, MAJOR) the pass is recorded into the scan envelope: each pruned manifest entry is a `removed` event with `details.manifest: true`, each reverted vendored entry a `removed` event (`errorCode: "vendor_reverted"`, `details.mode: "vendored"`), each drift-kept entry a `skipped` / `vendor_revert_kept` event and each entry whose revert failed a `skipped` / `vendor_revert_failed` event (a GC revert failure never fails the run); a `--dry-run` preview reports the removals as `verified`. The artifact sweep is the envelope's `gc` (`summary.bytesFreed` mirrors it), the orphan vendor dirs swept are the top-level `removedVendorOrphanDirs` count, and each registry entry taken out is a `registry_entry_unused` event counted in `gc.removedRegistryEntries`. The pass's warnings join the top-level `warnings[]`: `vendor_state_write_failed` (entries were reverted but the ledger rewrite failed), `manifest_write_failed` (the pruned manifest could not be written: no entry was pruned and no blob, diff or package archive was swept, since the manifest on disk still references them), `cleanup_failed` (an orphan sweep failed mid-way, or `.socket/` or one of its `blobs/`, `diffs/`, `packages/` directories is a symlink, which is never swept), `cargo_cache_patch_kept` (see above), `registry_cleanup_skipped` / `registry_cleanup_failed` (the registry-route half could not read or write the pnpm files), and the reinstall advisories of the vendored reverts (`vendor_bun_reinstall_required`, `vendor_vlt_reinstall_required`, `vendor_pypi_reinstall_required`; a revert's other warnings, such as `vendor_lock_entry_removed` or a drift keep's, are not repeated). A pass skipped at the lock (`lock_held` | `lock_io`) has no `gc` and no events, only a `gc_skipped` warning whose detail ends with the code. Human mode prints `GC: skipped: .`, one `GC: .` line per warning, and `GC: failed to revert N vendored entries: …` (singular for one). A drift keep is an entry the revert deliberately preserved (`vendor_artifact_kept` — undo the drift and re-run `vendor --revert` to finish); the preview cannot see drift (backends return before the wiring replay on dry runs), so its `verified` reverts may over-promise what a wet run will actually reclaim. `scan` queries the patch API in `--batch-size` chunks. Authenticated runs POST `/v0/orgs/{slug}/patches/batch`; token-less runs POST `{proxy}/patch/batch` on the public proxy and degrade to per-package `GET /patch/by-package/:purl` requests in two cases: the deployed proxy predates the batch endpoint (legacy proxies answer the POST with their `400 "Unsupported endpoint"` catch-all), or the all-or-nothing batch validation rejects the chunk (e.g. a crawled PURL type the server doesn't recognize, such as `pkg:jsr/…` — the per-package path tolerates those individually, preserving the pre-batch scan semantics). Rate limits and over-capacity 503s surface instead of silently degrading. @@ -527,6 +550,7 @@ A patch mirror is a caching proxy the operator runs in front of the patch server * **Operator configuration only.** The base is read from the flag or the environment, never from `socket.yml` or any other repository file (the socket.yml trust boundary below): it names the host every later install fetches from and the host whose references `vex` attests. It must be an `http(s)` URL with a host and no userinfo, query or fragment, in the characters a grant URL may hold; trailing slashes are dropped. Anything else is a usage error (exit 2, `Error: --patch-mirror-url (or SOCKET_PATCH_MIRROR_URL) is not a usable patch mirror base URL: `), checked before the project is read. The message never repeats the value. `apply` is the exception: it does not use the mirror and runs unattended from install hooks, so there a base it cannot use is no mirror and no error. * **What hosted mode writes.** `scan` / `get --mode hosted` move each granted reference onto the mirror before anything else reads it: the artifact URL, and the registry index URL of a gem or Maven-layout reference, keep their path (grant token and patch uuid included) and take the base in place of scheme and authority. The integrity pins are unchanged, and a re-run is idempotent. A Go reference is not moved: its pin is the module path `patch.socket.dev/gopatch/`, which names no host to fetch from. A Cargo or NuGet reference is not written at all: `skipped` / `redirect_mirror_unsupported` (their registry index is rendered by the patch server with its own absolute download URLs, which a mirror cannot rewrite; the detail names `--mode vendored`). A reference with no path to serve, or whose mirrored URL the grant gate refuses, is `skipped` / `redirect_mirror_url_refused`. * **A project already pinned on the patch server.** npm, pnpm, yarn classic, `requirements.txt` and uv locks are re-pinned onto the mirror by the same run. The yarn berry, Bun, Bundler, Poetry and PDM rewriters own an earlier pin only on the host they are writing, so they leave a direct pin as it is: the patch is `skipped` (`redirect_unconfirmed`) and a `redirect_mirror_pin_not_moved` warning names the file, the host and the remedy (`rollback `, then the same command again). +* **pnpm takes `trustLockfile`, never the registry route.** The registry address a grant carries (`npmRegistryUrl`, see "pnpm registry route") is not moved onto the mirror: the document the patch server answers there names the tarball on the patch server itself, which a mirror cannot rewrite, so pnpm would refuse a mirrored tarball against it. A mirrored tarball is no file of that address, which reads as no address, and a mirror run pins a pnpm project exactly as a patch service without registries does (`trustLockfile: true`, with nothing said of registries). A project an earlier run routed is taken off the route by the run that moves its pins onto the mirror: the registries (on the patch server, which the run still knows for one: the configured server, else the one the grants' registry addresses name), the overrides, the locks' records and the registry keys go as in *Leaving the route*, each entry reported as usual, and the `redirect_pnpm_trust_lockfile` warning says "the patch mirror serves no registry for `@`, …". `repair` and `scan --prune` clean up a route's unused entries the same with or without the setting; a registry of the CLI's name shape declared under the mirror's base or elsewhere on its host is on no patch server and is the user's. * **The run's own downloads** (a wheel's metadata, a tarball's `package.json`, a gem for the stale-install refresh) read the patch server, not the mirror, which may want credentials the run does not have. * **The mirror is checked before anything is pinned.** One `HEAD` for each mirrored reference the project's files do not already hold (a re-run that pins nothing new sends none), in candidate order, after the unconfigured-host guard and before the rewrite. The request carries no Socket credential, carries `SOCKET_PATCH_MIRROR_AUTHORIZATION` as its `Authorization` header when that is set, and follows no redirect. 2xx: that pin proceeds. 401 / 403 / 407, or a 3xx: nothing more is asked, every pin the mirror has not already refused proceeds, and one `redirect_mirror_unverified` warning says they were not checked. A transport failure, or no answer within the per-attempt timeout: nothing more is asked, and that reference and every one not yet asked about are `skipped` / `redirect_mirror_unavailable`. Any other answer: that reference is `skipped` / `redirect_mirror_unavailable`. Nothing is written for a skipped reference, and a warning names its package; when the mirror served none of the references it was asked about there is one warning instead, about the mirror. Exit 0 either way, files byte-identical for the skipped references, no `.npmrc` setting when nothing was pinned. No retry. A dry run checks too. * **What every command reads.** The mirror's base counts as a patch host for `list`, `vex`, `rollback`, `remove`, `vendor`, `repair` and `scan` ("Patch hosts" under Manifest-less VEX): a mirrored reference is the patch server's own path under that base. A URL elsewhere on the mirror's host, in another repository of it, is not one: unlike a `--patch-server-url` origin, which holds its whole host, the mirror holds only what is under its base. Without the setting those references are on a host the run was not given and are not hosted pins. What a command downloads for itself while it restores a pin (a yarn berry checksum) comes from the patch server, never the mirror. @@ -1639,10 +1663,24 @@ releases re-synthesized such entries (`details.ledgerRestored`); ledgers they wr Because of this phase, `repair` does not error with `manifest_not_found` when the project has a vendor ledger or vendor-path lockfile references — it runs the vendored phase alone. A **hosted-only** project (no manifest, no vendor ledger, no vendored references — only hosted pins -in its lockfiles, v5.0, or a pre-v5 `.socket/vendor/redirect-state.json`) is a no-op: `repair` -exits 0 with a `redirect_only_project` skip pointing at `scan --mode hosted` (hosted pins have no -local artifacts to repair), rather than the `manifest_not_found` error a bare directory still -gets. Agent blob acquisition skips vendored records and lockfile-referenced UUIDs, so repairing a vendored project does not populate `.socket/blobs`. +in its lockfiles, v5.0, or a pre-v5 `.socket/vendor/redirect-state.json`) has nothing to download +or rebuild: `repair` exits 0 with a `redirect_only_project` skip pointing at `scan --mode hosted` +(hosted pins have no local artifacts to repair), rather than the `manifest_not_found` error a bare +directory still gets. + +**Registry cleanup.** `repair`'s cleanup phase also removes the entries of hosted mode's pnpm +registry route that no lockfile uses any more (see "pnpm registry route", *Cleanup*), in every +project that holds something of a route: beside the `.socket/` sweeps when there is a manifest, +and on its own in a hosted-only project, including one whose patched packages all left its lock +(no hosted pin, only the route's leftovers; such a project takes the `redirect_only_project` +path, not `manifest_not_found`). It reads pnpm-workspace.yaml and the pnpm locks and asks no +patch service or registry, so it runs `--offline`; `--download-only` skips it with the rest of the +phase. Each entry is a `registry_entry_unused` event (`removed`; `verified` on `--dry-run`, which +writes nothing) and `gc.removedRegistryEntries` counts them; in a hosted-only project that `gc` +has zeros for the `.socket/` sweeps, which did not run, and is absent when the project holds +nothing of a route. A hosted-only project takes the apply lock only when there is an entry to +remove on a wet run, so `.socket/` is never left behind. A file a routed scan created is deleted +once it holds nothing else; a file of the user's keeps their bytes. Agent blob acquisition skips vendored records and lockfile-referenced UUIDs, so repairing a vendored project does not populate `.socket/blobs`. ### Path convention + patch-UUID recovery (stable) @@ -2182,7 +2220,7 @@ Empty string means unset at every layer: exported-but-empty flag-bound vars are | `SOCKET_LOCK_TIMEOUT` | `--lock-timeout` | (none) | Seconds to wait for `apply.lock` on the lock-taking subcommands (incl. hosted/vendored `scan`/`get`); unset/`0` = single non-blocking try. | | `SOCKET_DEBUG` | `--debug` | `false` | — | | `SOCKET_TELEMETRY_DISABLED` | `--no-telemetry` | `false` | One of several opt-outs; see [Telemetry](#telemetry). | -| `SOCKET_NO_TRUST_LOCKFILE_CONFIG` | `--no-trust-lockfile-config` | `false` | Hosted mode: skip the `trustLockfile: true` write to `pnpm-workspace.yaml`. | +| `SOCKET_NO_TRUST_LOCKFILE_CONFIG` | `--no-trust-lockfile-config` | `false` | Hosted mode: skip the `pnpm-workspace.yaml` write (the registry route's `namedRegistries` entries and `overrides`, or `trustLockfile: true`). | | `SOCKET_NO_NPM_ALLOW_REMOTE_CONFIG` | `--no-npm-allow-remote-config` | `false` | Hosted mode: skip the `allow-remote=all` write to the project `.npmrc`. | | `SOCKET_NO_VLT_INSTALL_CLEANUP` | `--no-vlt-install-cleanup` | `false` | Hosted mode, `rollback`, `remove`: keep stale vlt installed copies. | | `SOCKET_NO_GEM_INSTALL_REFRESH` | `--no-gem-install-refresh` | `false` | Hosted mode, `rollback`, `remove`: leave the project's stale installed gems and cached archives alone. | @@ -2329,11 +2367,12 @@ command's integration tests check its output. "rolledBack": 0, "bytesFreed": 0 // = gc.bytesFreed; 0 when no GC ran }, - "gc": { // only when the run swept .socket/ (repair, remove, rollback) + "gc": { // only when the run swept .socket/ (repair, remove, rollback) or a pnpm registry route "removedBlobs": 0, "removedDiffArchives": 0, "removedPackageArchives": 0, - "bytesFreed": 0 + "bytesFreed": 0, + "removedRegistryEntries": 0 // unused entries of hosted mode's pnpm registry route (repair, scan --prune) }, "error": { "code": "...", "message": "..." } // only on status=error } @@ -2341,7 +2380,7 @@ command's integration tests check its output. `events` is the load-bearing payload. `summary` is pre-computed from `events` so consumers don't have to walk the array; its action counters count patch-level events, so a GC carrier event (the artifact-level `removed`, or `verified` on a dry run, that `repair` and `remove` emit for a sweep) bumps none of them. The sweep itself is reported once, in `gc`. `error` is set only on top-level failures (e.g. `manifest_not_found`); per-patch failures appear as `events[*]` with `action: "failed"`. -**One GC shape (v5.0).** Every command that sweeps orphan artifacts from `.socket/blobs`, `.socket/diffs` and `.socket/packages` reports the pass as the same `gc` object, `{removedBlobs, removedDiffArchives, removedPackageArchives, bytesFreed}`: the envelope's `gc` (`repair`, `remove`, `rollback`) and the `gc` of `scan --prune` / `--sync` (which adds its manifest and vendored keys beside them). On a dry run the counts are what the pass would remove, under the same keys (v5.0, MAJOR: scan's `--dry-run` preview no longer prints `prunableManifestEntries` / `orphanBlobs` / `orphanDiffArchives` / `orphanPackageArchives` / `revertableVendoredEntries` / `vendorOrphanDirs` / `bytesReclaimable`; it prints `prunedManifestEntries`, `removedBlobs`, `removedDiffArchives`, `removedPackageArchives`, `revertedVendoredEntries`, `removedVendorOrphanDirs` and `bytesFreed`, and leaves out only the keys a real pass alone can fill: `keptVendoredEntries`, `failedVendoredEntries`, `skipped`, `warnings`). `summary.bytesFreed` mirrors `gc.bytesFreed` on the envelope commands (0 when no GC ran: `repair --download-only`, `remove --preserve-state`, and every command without a GC pass). `gc` is absent when no sweep ran. v5.0 removes `summary.bytesDownloaded`, which no command ever emitted. +**One GC shape (v5.0).** Every command that sweeps orphan artifacts from `.socket/blobs`, `.socket/diffs` and `.socket/packages` reports the pass as the same `gc` object, `{removedBlobs, removedDiffArchives, removedPackageArchives, bytesFreed, removedRegistryEntries}`: the envelope's `gc` (`repair`, `remove`, `rollback`) and the `gc` of `scan --prune` / `--sync` (which adds its manifest and vendored keys beside them). `removedRegistryEntries` (additive) counts the entries of hosted mode's pnpm registry route that no lockfile uses any more and the run took out of pnpm-workspace.yaml and the pnpm locks (`repair`, `scan --prune` / `--sync`, and `scan --mode hosted --prune`); it is 0 from `remove` and `rollback`, which report the pins they restore as events. Those entries are lines of project files, not artifacts: `bytesFreed` and the carrier event's `count` leave them out, and each is its own `registry_entry_unused` event. On a dry run the counts are what the pass would remove, under the same keys (v5.0, MAJOR: scan's `--dry-run` preview no longer prints `prunableManifestEntries` / `orphanBlobs` / `orphanDiffArchives` / `orphanPackageArchives` / `revertableVendoredEntries` / `vendorOrphanDirs` / `bytesReclaimable`; it prints `prunedManifestEntries`, `removedBlobs`, `removedDiffArchives`, `removedPackageArchives`, `revertedVendoredEntries`, `removedVendorOrphanDirs` and `bytesFreed`, and leaves out only the keys a real pass alone can fill: `keptVendoredEntries`, `failedVendoredEntries`, `skipped`, `warnings`). `summary.bytesFreed` mirrors `gc.bytesFreed` on the envelope commands (0 when no GC ran: `repair --download-only`, `remove --preserve-state`, and every command without a GC pass). `gc` is absent when no sweep ran. v5.0 removes `summary.bytesDownloaded`, which no command ever emitted. **GC carrier event (v5.0, MAJOR).** `repair` and `remove` add one artifact-level event (no `purl`) for a sweep that removed something: `removed` (`verified` on a dry run) with `bytes` = bytes freed and `details: {count, checked}` — `count` the artifacts swept (= `gc.removedBlobs + gc.removedDiffArchives + gc.removedPackageArchives`), `checked` the artifacts the sweep examined. It bumps no `summary` counter. `remove`'s carrier no longer carries `details.blobsRemoved` / `details.archivesRemoved` (read `gc`) or `details.rolledBack` (see `remove`'s `rolledBack` events). @@ -2388,7 +2427,7 @@ command's integration tests check its output. | `updated` | `--update`, `get`, `scan` | `--update`: the binary was replaced (`details.from` / `details.to`). Agent `get` / `scan`: a manifest record was replaced by a newer patch (`oldUuid`, metadata in `details`). | | `skipped` | every envelope command | No-op — already patched, not in scope, filtered, etc. `errorCode` carries the reason. | | `failed` | `apply`, `repair`, `vendor`, `rollback`, `get`, `scan` | A specific attempt failed. `errorCode` + `error` set. | -| `removed` | `remove`, `repair`, `vendor`, `rollback`, `scan --prune` (manifest entries carry `details.manifest: true`) | A manifest entry or vendored state was removed, or (artifact-level, no `purl`) `.socket/` artifacts were swept — that GC carrier sets `bytes` and is not counted in `summary.removed`; the sweep's totals are the envelope's `gc`. | +| `removed` | `remove`, `repair`, `vendor`, `rollback`, `scan --prune` (manifest entries carry `details.manifest: true`), `scan --mode hosted` | A manifest entry or vendored state was removed, or (artifact-level, no `purl`) `.socket/` artifacts were swept — that GC carrier sets `bytes` and is not counted in `summary.removed`; the sweep's totals are the envelope's `gc`. Also artifact-level and uncounted: one event per unused entry of a pnpm registry route taken out (`errorCode: "registry_entry_unused"`). | | `verified` | `apply`, `remove`, `repair`, `vendor`, `rollback`, `get`, `scan` (dry run); `vex`; `--update --dry-run` | The action *would* succeed cleanly (`files` lists previewed changes); `vex`: the patch verified and was attested. | | `rebuilt` | `repair`, `vendor` | A missing/corrupt vendored artifact was restored from its exact server download (v5.0: never a lost ledger entry — see `vendor_ledger_missing`). `summary.rebuilt` counts these. | | `rolledBack` | `rollback`, `remove`, `scan --mode hosted` | A patched package was restored to its original files (`files` lists them), or (`rollback`) a vendored / hosted wiring was unwound (`details.mode`). `remove`: one per restored installed copy, `details.path` naming it — v5.0, MAJOR: was the GC carrier's `details.rolledBack`. `scan --mode hosted`: a pin whose patch was withdrawn was restored upstream (`errorCode: "patch_withdrawn"`). | @@ -2419,6 +2458,10 @@ command's integration tests check its output. | `no_files` | `skipped` | rollback (v5.0): the patch record lists no files, so nothing was restored. | | `hosted_restore_refused` / `hosted_write_failed` | `failed` (`details.mode: "hosted"`) | rollback (v5.0): a hosted pin's upstream restore was refused (detail names the `git checkout` remedy), or writing the restored lockfiles failed (artifact-level, no `purl`; on `--dry-run`: would fail). That write is all or nothing, so no pin of the run is `rolledBack` / `verified` beside it; the detail ends `nothing was written` / `nothing was changed`, or names each file that could not be put back (see "Hosted unwind coverage"). Exit 1. | | `gc_skipped` | rollback `warnings[]` | rollback (v5.0): the artifact GC could not run (a before-blob gate abort, an unreadable vendor ledger); `gc` is absent. Not raised under `--preserve-state`, which never asks for one. | +| `registry_entry_unused` | `removed` (`verified` on dry-run; artifact-level, no `purl`) | repair, scan (and `get --mode hosted`, which runs the same rewrite): an entry of hosted mode's pnpm registry route that no lockfile uses any more was taken out of pnpm-workspace.yaml or a pnpm lock (`details: {mode: "hosted", file, entry, key, value?}`; `entry` is `registry`, `override`, `lockOverride` or `lockKey`). A registry's address is never in the event. Bumps no `summary` counter; counted in `gc.removedRegistryEntries` where the run reports a `gc`. See "pnpm registry route", *Cleanup*. | +| `redirect_pnpm_registry_held` | `warnings[]` (warning) | scan/get `--mode hosted` (pnpm): a release the project routes through its patch's registry has a newer patch, and this run does not update pnpm-workspace.yaml (`--no-trust-lockfile-config`, an unreadable file, a lock that could not be converted back). The newer patch's tarball under the old patch's registry would not install, so the lock entry is left on the patch it is routed to and the newer patch is `skipped` / `redirect_unconfirmed`. The detail names the releases and, under the opt-out, says to re-run without the flag. See "pnpm registry route", *Cleanup*. | +| `registry_cleanup_unknown_host` | repair + scan run-level `warnings[]` | repair, `scan --prune`, a hosted scan that crawled no package: pnpm-workspace.yaml declares registries in the shape of a patch's registry (`socket-` at a patch's directory with matching digits) on a host this run was not given as a patch server. They were left alone, as a registry of the project's own is, so nothing of them was tidied. One warning per host; the detail gives the count, the host's origin (never the address) and `--patch-server-url ` / `SOCKET_PATCH_SERVER_URL` as what lets the command tidy them. The run continues and exits 0. See "pnpm registry route", *Cleanup* (Limits). | +| `registry_cleanup_skipped` / `registry_cleanup_failed` | repair + scan run-level `warnings[]` | repair, `scan --prune`, a hosted scan that crawled no package: the cleanup of unused pnpm registry entries could not read the pnpm locks or pnpm-workspace.yaml to tell what still uses the route (`…_skipped`; nothing was removed), or could not write the cleaned files (`…_failed`; they are as they were, or the detail names each one that is not). `…_failed` is also what a hosted scan reports when it could not delete a pnpm-workspace.yaml a run created and it has emptied (the file is left holding its `packages:` list; the detail says to delete it). The run continues and exits 0. | | `vendored` | `skipped` | apply (every ecosystem) + scan `--mode agent`: the package is managed by `socket-patch vendor`; the command yields ownership (scan also skips the download). v5.0: rollback no longer yields — its vendored leg reverts these entries by default, except under global scope, where `rollback`/`remove` skip a vendored NuGet project's own install with this code (#489) (a corrupt vendor ledger surfaces via the `vendor_state_unreadable` warning + exit 1 — the skip cannot name purls, since naming them needs the ledger). Scan `--mode agent --json` additionally surfaces one run-level `vendored_ownership_retained` warning naming the skipped purls (additive; exit/status unchanged). | | `vendor_reverted` | `removed` | remove: vendoring reverted (lock fragments restored, artifact + ledger entry gone) as part of removing the patch. v5.0: carries `details.mode: "vendored"` (as do the vendored leg's `skipped` events). | | `vendor_revert_failed` | top-level error; rollback `failed` | remove: the vendor revert failed; the manifest was NOT modified. Rollback (v5.0): a `failed` event with `details.mode: "vendored"` (`vendor_state_write_failed` when the revert landed but the ledger could not be saved); the entry, artifact and manifest record survive for a retry, exit 1. | @@ -2442,7 +2485,7 @@ command's integration tests check its output. | `vendor_would_refuse_symlinked_file` | `skipped` (advisory event) under `vendor --dry-run`; a top-level `warnings[]` entry (detail prefixed `: `) for each package the `scan` / `get --mode vendored --dry-run` preview would vendor (human: an `[warning] (): ` line) | dry run (#627): a dry run captures no writes, so for each package it would vendor (not one previewed as in sync, whose re-run writes nothing) it names every symlinked file of that package's ecosystem a vendored run may rewrite (the registry's vendored rewrite targets plus `pnpm-workspace.yaml`, `nuget.config`, `packages.lock.json`, the root `pom.xml`, `.mvn/maven.config` and `hatch.toml`; for PyPI also every variable-name lock in the project root — `pylock.toml`, `pylock..toml`, a PEP 723 `