Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion crates/socket-patch-cli/CLI_CONTRACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ Beyond the globals above, each subcommand defines a small set of local arguments
| `get` | positional `identifier`; `--id` / `--cve` / `--ghsa` / `--package` (`-p`); `--save-only`; `--mode <hosted\|vendored\|agent>` | `SOCKET_SAVE_ONLY` | Patch lookup + consumption mode (v3.6). `--mode` reuses scan's value enum (same hidden value aliases `host`/`redirect`/`vendor`; deliberately no env binding, matching scan). Default (v5.0): the mode the project's patch state records, like scan (see **Mode resolution**), so `hosted` for a project with no state; `agent` (save + apply in place) when `--save-only` or `--global`/`--global-prefix` is given. An explicit `--mode hosted\|vendored` with `--global`/`--global-prefix` is a usage error (exit 2, scan's wording: global installs have no project lockfile). An explicit `--save-only` conflicts with `--mode hosted\|vendored` — rejected with **exit 1** via get's established self-enforced-conflict style (unlike scan's exit-2 mode conflicts; see the exit-code table) |
| `remove` | positional `identifier` (target grammar: UUID, PURL with or without version, or exact package name); `--skip-rollback`; `--preserve-state` (v5.0) | `SOCKET_SKIP_ROLLBACK`, `SOCKET_PRESERVE_STATE` | Manifest entry removal. The identifier matches like a `rollback` target (a PyPI name compares by its PEP 503 canonical form). `--preserve-state` is the single-patch twin of `rollback --preserve-state`: restore the tree and unwind the identifier's vendored/hosted wiring, but keep the manifest entry, the vendored artifact + ledger entry, and skip all GC. Combining it with `--skip-rollback` is a self-enforced usage error (exit 2): one flag keeps the tree and drops the state, the other restores the tree and keeps the state — together they select the do-nothing quadrant ("the combination would be a no-op: nothing would change"). The conflict fires whether either flag is spelled on the command line or sourced from its env var |
| `rollback` | optional variadic positional `targets` (PURL \| UUID \| package name \| path glob); `--preserve-state` (v5.0) | `SOCKET_PRESERVE_STATE` | Rollback scope. Multiple targets union. A token becomes a path glob ONLY when it is path-SHAPED — contains a separator (`/` or `\`) or a glob metacharacter (`*?[`), or starts with `./`, or is absolute (an npm `@scope/name` is a name, not a path; a relative slash name without glob metacharacters or `.`/`..` segments — composer `vendor/pkg`, a go module path — is a name when it selects a recorded or hosted patch); a `pkg:` prefix is a PURL and every other token keeps the target grammar (UUID, PURL or exact package name), so a mistyped identifier or truncated UUID stays a safe exit-1 "No patch found matching identifier: X" (with a hint suggesting `./X` or `X/**` for directory targeting) instead of silently becoming a path scope. An unparseable glob is a usage error (exit 2) |
| `vex` | `--output` / `-O`, `--product`, `--no-verify`, `--no-bazel`, `--doc-id`, `--compact` | `SOCKET_VEX_OUTPUT`, `SOCKET_VEX_PRODUCT`, `SOCKET_VEX_NO_VERIFY`, `SOCKET_VEX_NO_BAZEL`, `SOCKET_VEX_DOC_ID`, `SOCKET_VEX_COMPACT` | OpenVEX 0.2.0 document generation; see "vex output channels" below. `--no-bazel` is **Experimental** (Bazel workspaces) |
| `vex` | `--output` / `-O`, `--product`, `--no-verify`, `--no-bazel`, `--doc-id`, `--compact`, `--grype-config [<path>]` | `SOCKET_VEX_OUTPUT`, `SOCKET_VEX_PRODUCT`, `SOCKET_VEX_NO_VERIFY`, `SOCKET_VEX_NO_BAZEL`, `SOCKET_VEX_DOC_ID`, `SOCKET_VEX_COMPACT`, `SOCKET_VEX_GRYPE_CONFIG` | OpenVEX 0.2.0 document generation; see "vex output channels" below. `--grype-config` lists the document in a Grype config (see "Grype config" below). `--no-bazel` is **Experimental** (Bazel workspaces) |
| `repair` | `--download-only` | `SOCKET_DOWNLOAD_ONLY` | Repair-specific cleanup mode (mutually exclusive with `--offline`; combining them is a usage error, exit 2) |

**pnpm hosted-mode contract**: `scan --mode hosted` handles block and flow resolutions in legacy `shrinkwrap.yaml` and lockfileVersion 5.x, 6.0, and 9.0. The [pinned compatibility matrix](../../docs/testing/pnpm-compatibility.md) samples pnpm majors 1–12. Early shrinkwrapVersion 3 without a positive minor version is refused with `redirect_pnpm_legacy_lockfile_unsupported`: pnpm 1.0.0 discards hosted URLs even on frozen installs. Upgrade to a tested release (1.43.1 or newer) and regenerate the lock, or use agent mode.
Expand Down Expand Up @@ -2782,6 +2782,7 @@ outcome for a selected record, rather than inferring a write from exit 0.
| `invalid_env` | scan | Usage error (exit 2): a malformed `SOCKET_MIN_SEVERITY` or `SOCKET_MAX_NEW_PATCHES`. |
| `filter_invalid` | scan | Usage error (exit 2): the `--selection-filter` file cannot be read or honored (internal interface, see "Selection filter"). |
| `json_requires_output` | vex | Usage error (exit 2): `--json` without `--output`. |
| `grype_config_requires_output` | vex | Usage error (exit 2): `--grype-config` without `--output` (Grype reads the document from a file). |
| `no_patches` | vex | The manifest file exists but is empty AND no vendor-ledger record or lockfile reference names a patch (exit 1). |
| `vendor_ledger_corrupt` | vex (every form) | `.socket/vendor/state.json` exists but is malformed or unreadable. The vendor ledger is an attestation input (records and liveness), so attesting from a partial view is refused (exit 2 standalone; the host command fails). A missing ledger is simply empty. |
| `redirect_ledger_corrupt` | vex, list (`warnings[]`) | v5.0: a WARNING, no longer an error — a pre-v5 `.socket/vendor/redirect-state.json` exists but is malformed or unreadable. v5 hosted mode keeps no ledger (hosted references come from the lockfiles, their records from the API), so the file is only an optional migration record source: its records are not consulted and the run continues. Delete the file or restore it from version control. |
Expand Down Expand Up @@ -3202,6 +3203,16 @@ The VEX document is JSON-LD, which collides with the standard `--json` envelope

When verification is enabled (the default) and a patch is omitted, the failed PURLs are surfaced on stderr in plain mode or as `skipped` events on the envelope in JSON mode (one per patch, sorted by PURL; `errorCode` is the tag). Plain mode prints one line per reason, largest first: `Warning: omitting 82 packages from VEX: the patched files still hold the original content (not_applied): @sigstore/core@1.1.0, @sigstore/core@2.0.0, @simple-git/argv-parser@1.1.1 and 79 more (--verbose lists them all)`; a reason with a single patch keeps the per-patch line `Warning: omitting <purl> from VEX: <reason> (<tag>)`, and `--verbose` prints that line for every patch. The run's advisories print before them, folded the same way: the first of each kind in full, then ` ... and 9 more like these: glob@10.4.5, glob@11.0.3, minimatch@3.1.2 and 6 more (--verbose lists them all)` (the packages are named where each advisory opens with one). When nothing could be attested, the `Error: No applied patches with vulnerability metadata to attest.` line is followed by the remedy for the patches that only need installing (`The patched packages are not installed yet: ... Reinstall from the lockfile (hosted or vendored patches) or run \`socket-patch apply\` (agent-mode patches), then run \`socket-patch vex\` again.`, or `N of the patched packages ...` when other reasons are among them). A hosted gem among them is not told to reinstall, since Bundler keeps a gem it has already installed and `bundle pristine` on Bundler 2.6+ removes the gems and then fails on the lock's checksum; its remedy is the scan that replaces the installed copy: `The patched packages are hosted gems whose installed copies are still the upstream builds. ... Run \`socket-patch scan\` to replace the installed copies (for a gem home outside the project, run \`bundle config set --local path vendor/bundle && bundle install\` instead, or add \`--gem-refresh-shared\` to the scan), then run \`socket-patch vex\` again.` (see "Gem stale-install guard"). Where a scan with no `--mode` is not a hosted one (the project also holds agent-mode or vendored patches), that sentence names the files to remove instead: `Remove each gem's \`specifications/<name>-<version>.gemspec\` and \`cache/<name>-<version>.gem\` from its gem home (and its archive in \`vendor/cache\`, if the project keeps one) and run \`bundle install\`. Other projects may load a gem home outside the project, so for one run \`bundle config set --local path vendor/bundle && bundle install\` instead, then run \`socket-patch vex\` again.` A gem the manifest records under the same patch as the hosted pin keeps the general remedy, since `apply` patches it in place; a record of another patch, which the pin superseded, does not. `--json` is unchanged: every advisory is its own `warnings[]` entry and every omission its own `skipped` event. Status becomes `partialFailure` when at least one patch was omitted but at least one was emitted. It is `partialFailure` too, with exit `0`, when a statement of the document says `affected`, also when every one does: `summary.verified` counts the packages attested as patched and no other.

### Grype config (`vex --grype-config`)

`--grype-config [<path>]` (`SOCKET_VEX_GRYPE_CONFIG`; `.grype.yaml` when the flag has no value, or when the value is a switch value — `1`, `true`, `yes` — while `0`, `false`, `no` turn it off; resolved like `--output` against the current directory) keeps the config's top-level `vex-documents` list naming the `--output` document, so `grype` run in the config's directory reads it without `--vex`. It needs `--output` (`grype_config_requires_output`, exit 2, otherwise).

* **Entry.** The document's path relative to the config's directory, `/`-separated, quoted only when YAML would read it differently. Grype resolves a listed path against the directory it runs in. A document outside the config's directory, or a config or document path that contains `..`, is not listed. An item that names the same path in another spelling (`./socket.vex.json`, `out/../socket.vex.json`, `\` separators) counts as the entry, when adding and when removing.
* **Edit.** A missing config is created as `vex-documents:` with the one item. An existing one gains the item: under its `vex-documents` block list, with the indentation of the last item, or as a new key appended to the document when it has none, or in place of an inline `[]`. Every other byte stays: each line keeps its own ending (a file mixing CRLF and LF is read line by line), new lines take the file's most common ending, and a missing final newline stays missing. A listed entry leaves the file unchanged.
* **Refused shapes.** A config the editor cannot read with certainty is left unchanged: `vex-documents` with any other inline value (a flow list, a scalar), spelled in another case or named twice (Grype refuses both), items other than plain paths, uneven or tab indentation, nested content, a flow-style root, an indented root, or more than one YAML document. So is a config that is not a regular file or cannot be read or written. The run then warns `grype_config_not_updated` with the line to add, and the document and exit status stay the run's own.
* **Removal.** Grype fails the whole scan when a listed document is missing. A failed run that leaves no document at `--output` (it removed the previous one, `vex_stale_doc_removed`, or there was none) takes every spelling of the entry out of the list, leaving the key. A config it cannot read or check with certainty is warned about (`grype_config_not_updated`, saying to remove the entry if it is there).
* **Output.** The human summary adds one line when the config changes (`Created .grype.yaml, listing socket.vex.json in vex-documents`, `Listed … in vex-documents of …`, `Removed … from vex-documents of …, since the document is gone`). The success envelope carries `grypeConfig: { path, entry, change }`, with `change` one of `created`, `added`, `listed`, `not_updated`, or under `--dry-run` (which writes nothing) `would_create` / `would_add`. The error envelope of a failed run that touched the config carries it too, with `change` `removed`, `not_updated` or, under `--dry-run`, `would_remove`.

## Semver policy

Versioning lives in **`Cargo.toml`** at the workspace root (`version = "..."`) and is propagated to the Cargo and npm packages by **`scripts/version-sync.sh <new-version>`** (the full list of stamped files is below).
Expand Down
1 change: 1 addition & 0 deletions crates/socket-patch-cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ pub const LOCAL_ARG_ENV_VARS: &[&str] = &[
"SOCKET_VEX_NO_BAZEL",
"SOCKET_VEX_DOC_ID",
"SOCKET_VEX_COMPACT",
"SOCKET_VEX_GRYPE_CONFIG",
];

/// Remove exported-but-empty flag-bound env vars before clap parses, so
Expand Down
1 change: 1 addition & 0 deletions crates/socket-patch-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub(crate) mod vendor_orphans;
pub(crate) mod vendored_backend;
pub mod vex;
pub(crate) mod vex_consumed;
pub(crate) mod vex_grype;
pub(crate) mod vex_sources;
pub(crate) mod vlt_heal;

Expand Down
Loading
Loading