Skip to content

fix(cli): stop the pre-clap argv passes at the escape boundary - #13309

Merged
zkochan merged 5 commits into
mainfrom
fix-13302
Jul 25, 2026
Merged

zkochan merged 5 commits into
mainfrom
fix-13302

Conversation

@zkochan

@zkochan zkochan commented Jul 25, 2026 •

Copy link
Copy Markdown
Member

Note

Follows #13300, now merged — that PR fixed the clap layer of this
same boundary, this one fixes the two passes that run before clap. Rebased
onto main, so the diff here is this change alone.

Summary

pacquet rewrites argv in two passes before clap sees it — ConfigOverrides::extract and expand_universal_shorthands — and neither stopped where pnpm stops parsing. Tokens meant for a script were consumed or rewritten on the way through:

command pnpm v11.17.0 pacquet before after
run show --config.foo=bar forwarded swallowed ✅
run show --silent --silent --reporter=silent ✅
exec node show.js --config.foo=bar forwarded swallowed ✅

The --silent case is the worse one: the script received a token the user never typed, not merely one fewer.

Found by Greptile while reviewing #13300, which fixed the clap layer of the same boundary.

Root cause

ConfigOverrides::extract stopped at two things: an explicit --, and external_command_index — the first positional naming no known command. That covers the pnpm <script> fallback, so pnpm show --config.foo=bar was already fine, but with an explicit run / exec the command is known, no boundary was found, and the scan covered the whole argv.

expand_universal_shorthands stopped only at --.

Approach

Rather than give the shorthand pass a third ad-hoc boundary rule, both passes now consult one helper — parse_boundary::passthrough_from, the first argv index that must reach the child untouched. It has three sources, all of which pnpm honors:

  • an explicit --, scanned independently of the command so pnpm install -- --config.foo=bar still ends parsing;
  • the pnpm <script> fallback (existing behavior, moved);
  • a command taking a foreign command line: run / dlx / with — pnpm's SPECIALLY_ESCAPED_CMDS — plus exec, which reaches the same place through its argv shape.

Two subtleties the tests pin:

  • recursive / multi / m defer the classification by one positional, so pnpm -r run build --silent lands on the same boundary.
  • Only the command position is classified, so a package sharing an escaping command's name is unaffected: pnpm add run --config.foo=bar still keeps the setting.

One existing test asserted the old behavior

silent_long_form_expands_for_any_command claimed the long --silent "stays universal" past the script name. Both stacks disagree, verified against v11.17.0:

command echo silenced?
pnpm run --silent show yes, both stacks
pnpm run show --silent no, both stacks — the flag is the script's

Split into the two positions accordingly.

Verification

All ten cases in the matrix match the TypeScript CLI byte for byte, 2214 pacquet-cli tests pass, lint and dylint clean. I confirmed the new tests catch a regression: disabling the foreign-command-line rule fails two parse_boundary tests and one shorthands test.

TypeScript CLI: no change needed — it is the reference.

Closes #13302

Squash Commit Body

Two passes rewrite argv before clap sees it, and neither stopped where
pnpm stops parsing, so tokens meant for a script were consumed or
rewritten on the way through:

    command                              pnpm            pacquet
    run show --config.foo=bar            forwarded       swallowed
    run show --silent                    --silent        --reporter=silent
    exec node show.js --config.foo=bar   forwarded       swallowed

The `--silent` case is the worse one: the script received a token the user
never typed, not merely one fewer.

`ConfigOverrides::extract` stopped at an explicit `--` and at
`external_command_index`, the first positional naming no known command.
That covers the `pnpm <script>` fallback but not an explicit `run` /
`exec`, where the command *is* known, so no boundary was found and the
scan covered the whole argv. `expand_universal_shorthands` stopped only at
`--`.

Rather than give the shorthand pass a third boundary rule, both now
consult one `parse_boundary::passthrough_from`: the first index that must
reach the child untouched, whether that comes from a `--`, the fallback
command, or a command taking a foreign command line (`run` / `exec` /
`dlx` / `with` — pnpm's `SPECIALLY_ESCAPED_CMDS` plus `exec`). The
separator is scanned independently of the command, so `pnpm install --
--config.foo=bar` still ends parsing.

`recursive` / `multi` / `m` defer the classification by one positional, so
`pnpm -r run build --silent` lands on the same boundary. A package sharing
an escaping command's name does not: `pnpm add run --config.foo=bar` keeps
the setting, because only the command position is classified.

One existing shorthand test asserted the old behavior — that `--silent`
"stays universal" past the script name. Both stacks disagree with it:
`pnpm run show --silent` forwards the flag and does not silence the echo,
while `pnpm run --silent show` silences it. Split into the two positions.

Closes pnpm/pnpm#13302

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.
    Rust-only: the TypeScript CLI is the reference behavior being matched.
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.
    A boundary table over every source and command shape, plus the shorthand positions.

Written by an agent (Claude Code, claude-opus-5).

Summary by CodeRabbit

  • Bug Fixes
    • Arguments placed after the script or command name are now forwarded unchanged for pnpm run, pnpm exec, pnpm dlx, and pnpm with.
    • Script arguments resembling pnpm settings or flags, such as --config.foo=bar and --silent, are no longer incorrectly consumed or rewritten.
    • pnpm options should be placed before the script or command name.
    • Improved handling of argument separators and versioned pnpm with commands.

Copilot AI review requested due to automatic review settings July 25, 2026 10:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Pacquet adds shared argv boundary detection for run, exec, dlx, with, fallback scripts, and separators. Config override extraction and shorthand expansion stop at that boundary, with tests covering forwarding and option handling.

Changes

Argument forwarding

Layer / File(s) Summary
Shared passthrough boundary
pnpm/crates/cli/src/parse_boundary.rs, pnpm/crates/cli/src/parse_boundary/tests.rs, pnpm/crates/cli/src/flag_relocation.rs, pnpm/crates/cli/src/lib.rs
Adds shared boundary detection using command structure, aliases, option arity, separators, fallback scripts, and with version handling, with comprehensive unit coverage.
Pre-clap boundary consumers
pnpm/crates/cli/src/config_overrides.rs, pnpm/crates/cli/src/shorthands.rs, pnpm/crates/cli/src/shorthands/tests.rs, pnpm/crates/cli/tests/run.rs
Stops config classification and shorthand rewriting at the forwarding boundary and verifies unchanged script arguments.
Release notes
.changeset/pacquet-preclap-escape-boundary.md
Documents unchanged forwarding for post-command arguments and pnpm flag placement.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI as CLI argv
  participant Boundary as passthrough_from
  participant PreClap as ConfigOverrides and shorthands
  participant Script as Executed script
  CLI->>Boundary: Analyze command, options, and separators
  Boundary-->>PreClap: Return passthrough index
  PreClap->>PreClap: Parse only tokens before index
  PreClap->>Script: Forward remaining tokens unchanged
Loading

Assessment against linked issues

Objective Addressed Explanation
Prevent ConfigOverrides::extract from consuming script arguments past the escape boundary [#13302] ✅
Prevent shorthand expansion from rewriting post-script arguments [#13302] ✅
Use one shared boundary for run, exec, dlx, with, separators, and fallback scripts [#13302] ✅

Possibly related issues

  • #13295 — Related to preserving pnpm run argument boundaries and separator handling.

Possibly related PRs

  • pnpm/pnpm#13194 — Modifies the same shorthand expansion behavior for --silent and -s.
  • pnpm/pnpm#13300 — Addresses the same pnpm run argument-forwarding boundary.
  • pnpm/pnpm#13303 — Adjusts pnpm run forwarding after the user-provided separator.

Suggested labels: product: pacquet

Suggested reviewers: copilot

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-13302

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

qodo-code-review Bot commented Jul 25, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Fix pre-clap argv rewriting to stop at the script escape boundary

🐞 Bug fix 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Stop pre-clap argv rewrites at pnpm’s passthrough boundary for run/exec/dlx and fallback scripts.
• Centralize boundary detection in a single helper shared by config overrides and shorthand
 expansion.
• Update run argument shape so everything after the script name is forwarded verbatim, with new
 tests.
Diagram

graph TD
  A[("argv")] --> B["parse_boundary::passthrough_from"] --> C["ConfigOverrides::extract"] --> D["expand_universal_shorthands"] --> E["clap parse (CliArgs)"] --> F["run/exec/dlx child argv"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Defer all rewrites until after clap parses
  • ➕ Avoids pre-clap boundary classification entirely
  • ➕ Keeps argv transformations command-aware using parsed subcommand context
  • ➖ Harder to extract early config overrides that affect clap/config initialization
  • ➖ May require larger refactors of current initialization order and error reporting
2. Hard-code boundary rules per command (run/exec/dlx/etc.) in each pass
  • ➕ Less new shared machinery; changes stay localized to each pass
  • ➖ Duplication across passes tends to drift (root cause of this bug)
  • ➖ Easier to miss edge cases like recursive/multi prefixes and option arity
3. Port pnpm JS boundary logic directly (nopt-style)
  • ➕ Behavior parity with upstream implementation
  • ➕ Known semantics for tricky cases
  • ➖ Reintroduces hand-maintained option lists and arity tables (prior source of mis-boundaries)
  • ➖ Less aligned with clap’s source-of-truth for option definitions

Recommendation: The PR’s approach is the best tradeoff: centralizing boundary detection in parse_boundary::passthrough_from eliminates drift between pre-clap passes while still deriving option arity from clap metadata (reducing the risk of misclassifying option values as positionals). The accompanying tests cover the subtle cases (recursive prefixes, --, and option arity), which is critical for maintaining parity with pnpm JS.

Files changed (19) +520 / -106

Enhancement (1) +8 / -0
flag_relocation.rsExpose ArgTable helper to absorb subcommand options for boundary parsing +8/-0

Expose ArgTable helper to absorb subcommand options for boundary parsing

• Adds 'ArgTable::absorb_subcommands' so boundary detection can build a single arity view across top-level + subcommand options before the command is known. Supports correct option-width calculation for pre-clap passes.

pnpm/crates/cli/src/flag_relocation.rs

Bug fix (5) +214 / -88
run.rsMake 'run' a single trailing positional to stop parsing at script name +39/-14

Make 'run' a single trailing positional to stop parsing at script name

• Replaces 'command'+'args' with a single 'script: Vec<String>' trailing positional so clap stops parsing at the script name and forwards subsequent tokens verbatim. Adds helpers to access script name/args and updates execution logic accordingly, including exec fallback construction.

pnpm/crates/cli/src/cli_args/run.rs

recursive.rsAdapt recursive run to 'script_name()'/'script_args()' accessors +6/-4

Adapt recursive run to 'script_name()'/'script_args()' accessors

• Updates recursive run logic to read script name and forwarded args from the new RunArgs helpers. Preserves skip/guard logic while ensuring forwarded arguments remain verbatim past the script name.

pnpm/crates/cli/src/cli_args/run/recursive.rs

config_overrides.rsStop config override extraction at shared passthrough boundary +2/-69

Stop config override extraction at shared passthrough boundary

• Replaces the bespoke external-command boundary logic with 'parse_boundary::passthrough_from', ensuring config overrides are only extracted from pnpm-owned argv. Prevents tokens intended for scripts (e.g., '--config.*' after script name) from being swallowed.

pnpm/crates/cli/src/config_overrides.rs

parse_boundary.rsIntroduce shared passthrough boundary classifier for pre-clap passes +162/-0

Introduce shared passthrough boundary classifier for pre-clap passes

• Adds 'passthrough_from' and supporting logic to compute where pnpm must stop parsing and forward argv untouched, honoring '--', fallback scripts, and commands taking foreign command lines. Derives option arity from clap metadata (including subcommand unions) to avoid misclassifying option values as positionals.

pnpm/crates/cli/src/parse_boundary.rs

shorthands.rsStop shorthand expansion at passthrough boundary +5/-1

Stop shorthand expansion at passthrough boundary

• Changes universal shorthand expansion to only run on the pnpm-owned portion of argv as determined by 'passthrough_from'. Prevents rewriting child arguments (e.g., turning script '--silent' into '--reporter=silent').

pnpm/crates/cli/src/shorthands.rs

Refactor (6) +7 / -13
clean.rsConstruct RunArgs using new 'script' positional helper +1/-2

Construct RunArgs using new 'script' positional helper

• Updates CleanArgs to synthesize RunArgs via 'RunArgs::script(...)' rather than separate command/args fields. Aligns with the new single-positional shape for run scripts.

pnpm/crates/cli/src/cli_args/clean.rs

dispatch_install.rsSynthesize 'pnpm test' RunArgs via 'script' vector +1/-2

Synthesize 'pnpm test' RunArgs via 'script' vector

• Adjusts install test dispatch to build RunArgs using the new 'script' positional vector (script name + args). Keeps test invocation behavior while aligning with updated RunArgs structure.

pnpm/crates/cli/src/cli_args/dispatch_install.rs

dispatch_script.rsSwitch fallback/restart paths to new RunArgs script shape +2/-5

Switch fallback/restart paths to new RunArgs script shape

• Updates script fallback and restart helpers to populate 'RunArgs.script' directly instead of splitting into command+args. Ensures internal code paths follow the same forwarding semantics as parsed 'run' invocations.

pnpm/crates/cli/src/cli_args/dispatch_script.rs

restart.rsUse RunArgs::script for restart/start/stop synthesized runs +1/-2

Use RunArgs::script for restart/start/stop synthesized runs

• Migrates RestartArgs to the new RunArgs representation by building a single script positional. Keeps argument propagation intact while unifying script invocation handling.

pnpm/crates/cli/src/cli_args/restart.rs

stop.rsUpdate StopArgs to build RunArgs via 'script' vector +1/-2

Update StopArgs to build RunArgs via 'script' vector

• Switches StopArgs conversion to RunArgs to use 'RunArgs::script("stop", args)' rather than separate command/args fields. Maintains existing behavior while conforming to new RunArgs layout.

pnpm/crates/cli/src/cli_args/stop.rs

lib.rsRegister new 'parse_boundary' module +1/-0

Register new 'parse_boundary' module

• Adds the new parse-boundary module to the CLI crate module list so it can be shared by pre-clap passes.

pnpm/crates/cli/src/lib.rs

Tests (5) +281 / -5
tests.rsAdd parsing tests asserting verbatim forwarding after script name +63/-0

Add parsing tests asserting verbatim forwarding after script name

• Introduces unit tests that parse 'run' argv and assert that everything after the script name (including '--' and pnpm-flag-shaped tokens) lands in 'script_args()'. Also verifies pnpm flags still work when placed before the script name and that missing script name yields listing behavior.

pnpm/crates/cli/src/cli_args/run/tests.rs

tests.rsReorder argv in workspace-root test to keep globals before 'run' script name +5/-2

Reorder argv in workspace-root test to keep globals before 'run' script name

• Adjusts a CLI parsing test so workspace flags are placed before the subcommand; for 'run', tokens after the script name must be treated as script arguments. Prevents the test from inadvertently relying on old parsing behavior.

pnpm/crates/cli/src/cli_args/tests.rs

tests.rsAdd coverage for boundary detection edge cases and option arity +127/-0

Add coverage for boundary detection edge cases and option arity

• Adds tests validating forwarding boundaries for run/exec/dlx, recursive prefixes, explicit '--', fallback scripts, and commands that own their arguments. Includes regression tests ensuring value-taking options don’t shift the boundary onto their values and that 'with current' remains parseable at this stage.

pnpm/crates/cli/src/parse_boundary/tests.rs

tests.rsUpdate/extend shorthand tests for script-boundary behavior +16/-3

Update/extend shorthand tests for script-boundary behavior

• Updates expectations so '--silent' expansion remains for pnpm when placed before the script name, but does not expand after it. Adds explicit regression tests for 'run' and 'exec' passthrough behavior.

pnpm/crates/cli/src/shorthands/tests.rs

run.rsAdd integration test ensuring 'run' forwards '--' and option-shaped args +70/-0

Add integration test ensuring 'run' forwards '--' and option-shaped args

• Adds an integration test that records the actual argv received by pre/main/post scripts to assert that '--' and option-shaped tokens are forwarded verbatim to the main stage only. Mirrors pnpm’s TypeScript test intent and guards against dropping the separator or consuming pnpm-like flags.

pnpm/crates/cli/tests/run.rs

Documentation (2) +10 / -0
pacquet-preclap-escape-boundary.mdAdd changeset documenting pre-clap passthrough boundary fix +5/-0

Add changeset documenting pre-clap passthrough boundary fix

• Adds release notes describing that arguments after script/command names are now forwarded verbatim for run/exec/dlx/with-like flows, matching pnpm JS behavior. Documents prior incorrect swallowing/rewriting of tokens like '--config.*' and '--silent'.

.changeset/pacquet-preclap-escape-boundary.md

pacquet-run-forwards-script-args.mdAdd changeset documenting 'pnpm run' forwarding semantics +5/-0

Add changeset documenting 'pnpm run' forwarding semantics

• Adds release notes stating that 'pnpm run <script> <args>' forwards everything after the script name, including '--' and pnpm-flag-shaped tokens. Provides guidance to place pnpm flags before the script name when intended for pnpm.

.changeset/pacquet-run-forwards-script-args.md

@greptile-apps

greptile-apps Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (6): Last reviewed commit: "test(cli): assert the whole forwarded sl..." | Re-trigger Greptile

Comment thread pnpm/crates/cli/src/parse_boundary.rs Resolved
Comment thread pnpm/crates/cli/src/config_overrides.rs Resolved
@github-actions

github-actions Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                          main                                   pr
-----                          ----                                   --
lockfile/parse_pnpm_lock       1.00     11.4±0.07ms    32.9 MB/sec    1.00     11.4±0.15ms    32.9 MB/sec
packument/parse                1.00     38.1±0.12µs  1739.5 MB/sec    1.01     38.6±0.06µs  1719.8 MB/sec
tarball/download_dependency    1.03      2.3±0.09ms  1926.7 KB/sec    1.00      2.2±0.07ms  1978.4 KB/sec

@qodo-code-review

qodo-code-review Bot commented Jul 25, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (1) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 24 rules

Grey Divider


Action required

1. with missing passthrough boundary ✓ Resolved 📘 Rule violation ≡ Correctness
Description
parse_boundary::passthrough_from() does not treat pnpm with <spec> <pnpm-args...> as a command
that takes a foreign command line, so pre-clap argv rewriting can continue past the version spec and
rewrite or strip tokens intended for the spawned pnpm (e.g., --silent → --reporter=silent, or
--config.* extraction). This creates user-visible behavior that differs from pnpm’s special
escaping for with and can also cause config overrides meant for the child to affect the parent
while it resolves/downloads/execs the requested pnpm version.
Code

pnpm/crates/cli/src/parse_boundary.rs[R15-27]

+/// Commands whose own arguments are a foreign command line.
+///
+/// pnpm's `SPECIALLY_ESCAPED_CMDS` is `run` / `dlx` / `with`; `exec` joins
+/// them here because its argv shape reaches the same place. `with` does
+/// *not*: [`crate::with_current::rewrite`] runs after
+/// [`ConfigOverrides::extract`] and splices the inner command line into
+/// pnpm's own argv, so at this point those tokens are still pnpm's to
+/// claim — `pnpm with current run --config.foo=bar build` must have the
+/// override stripped here, or clap sees it after the rewrite and takes it
+/// for the script name.
+///
+/// [`ConfigOverrides::extract`]: crate::config_overrides::ConfigOverrides::extract
+const COMMANDS_TAKING_A_FOREIGN_COMMAND_LINE: [&str; 3] = ["run", "exec", "dlx"];
Relevance

⭐⭐⭐ High

Repo repeatedly accepts Rust CLI changes to match pnpm TS argv/behavior parity; this is correctness
and user-visible.

PR-#12789
PR-#13006
PR-#13300

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
In parse_boundary, COMMANDS_TAKING_A_FOREIGN_COMMAND_LINE excludes with, which means
passthrough_from() will not establish a stop point at the with spec boundary and pre-clap
transformations can keep operating on arguments that should be forwarded verbatim to the child pnpm.
By contrast, pnpm’s TypeScript argument parser explicitly includes with in
SPECIALLY_ESCAPED_CMDS, demonstrating that upstream pnpm treats with as a specially-escaped
boundary where options after the spec are not parsed/rewritten by the parent, so pacquet’s current
behavior is inconsistent with pnpm’s intended escaping/forwarding semantics.

Rule 713429: Pacquet must not introduce new user-visible behavior beyond pnpm
pnpm/crates/cli/src/parse_boundary.rs[15-27]
pnpm/crates/cli/src/parse_boundary/tests.rs[58-59]
pnpm11/cli/parse-cli-args/src/index.ts[6-8]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`parse_boundary::passthrough_from()` currently does not establish a passthrough boundary for `pnpm with <spec> <cmd> ...`, because `with` is excluded from the set of commands that take a foreign command line. As a result, pre-clap passes (e.g., config override extraction/stripping and universal shorthand expansion) can rewrite or remove flags that are intended to be forwarded verbatim to the spawned pnpm, and may even apply `--config.*` overrides intended for the child to the parent process while it resolves/downloads/execs the requested pnpm version.

## Issue Context
- pnpm’s TypeScript parser treats `with` as a specially-escaped command, so options after the version/range/dist-tag spec are not parsed/rewritten by the parent pnpm.
- pacquet’s Rust `with` command captures the remainder as trailing var-arg positional(s) and forwards everything after the spec directly to the spawned pnpm (e.g., `spawn_pnpm(...).args(args)`), so mutating argv before clap can change what the child pnpm receives.
- The existing `with current ...` rewrite is a deliberate exception that happens in-process after `ConfigOverrides::extract()`, so its inner command line must remain parseable by the parent and should not be treated the same as the general `with <spec> ...` passthrough case.
- This is especially risky because config overrides extracted from the (would-be) child argument list are documented to be applied to the in-process config load; for `with`, that config influences how the engine is resolved/installed, so a `--config.registry=...` intended for the child can affect the parent’s engine download.

## Fix Focus Areas
- pnpm/crates/cli/src/parse_boundary.rs[15-27]
- pnpm/crates/cli/src/parse_boundary.rs[56-60]
- pnpm/crates/cli/src/parse_boundary/tests.rs[58-59]
- pnpm/crates/cli/src/parse_boundary/tests.rs[119-127]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Wrong option width table ✓ Resolved 🐞 Bug ≡ Correctness
Description
parse_boundary::global_option_width does not include several global options that consume a
following value (e.g. --workspace-concurrency, --resume-from, --test-pattern), so
passthrough_from() can treat the option value as a positional and establish the passthrough
boundary too early. This can cause ConfigOverrides::extract() to stop scanning before later
--config.* tokens, leaving them for clap to parse and fail as “unexpected argument” (e.g. `pnpm
--workspace-concurrency 2 install --config.registry=...`).
Code

pnpm/crates/cli/src/parse_boundary.rs[R113-140]

+fn global_option_width(arg: &str) -> Option<usize> {
+    if matches!(arg, "-r" | "-v") {
+        return Some(1);
+    }
+    if matches!(arg, "-C" | "-F") {
+        return Some(2);
+    }
+    if arg.starts_with("-C") || arg.starts_with("-F") {
+        return Some(1);
+    }
+    let name = arg.strip_prefix("--")?;
+    let (name, has_value) = name.split_once('=').map_or((name, false), |(name, _)| (name, true));
+    let consumes_value = matches!(
+        name,
+        "dir"
+            | "filter"
+            | "filter-prod"
+            | "http-proxy"
+            | "https-proxy"
+            | "no-proxy"
+            | "npmrc-auth-file"
+            | "registry"
+            | "reporter"
+            | "store-dir"
+            | "userconfig",
+    );
+    Some(if consumes_value && !has_value { 2 } else { 1 })
+}
Relevance

⭐⭐⭐ High

Likely real argv misparse; team fixes CLI parsing edge cases and option-terminator issues.

PR-#13203
PR-#13008

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
parse_boundary uses a hard-coded list of long options that consume a value; options not listed are
treated as width 1, so their values can be misread as positionals. CliArgs defines multiple
additional global=true options that take values, and ConfigOverrides::extract now relies on
passthrough_from to decide when to stop stripping --config.* tokens, so an early boundary
directly breaks config override extraction.

pnpm/crates/cli/src/parse_boundary.rs[101-140]
pnpm/crates/cli/src/cli_args/cli_command.rs[171-223]
pnpm/crates/cli/src/config_overrides.rs[96-123]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`parse_boundary::global_option_width()` hard-codes which global options consume a separate value token. It currently omits several value-taking globals defined on `CliArgs`, so boundary scanning can misinterpret the next token (the option’s value) as a positional command/script name and compute an incorrect passthrough boundary.

This can prevent `ConfigOverrides::extract()` from stripping `--config.*` tokens (because it stops scanning at the computed boundary), which then causes clap to reject those tokens as unexpected.

### Issue Context
`passthrough_from()` is now used by both `ConfigOverrides::extract()` and `expand_universal_shorthands()`, so any boundary misclassification affects multiple pre-clap argv passes.

### Fix Focus Areas
- pnpm/crates/cli/src/parse_boundary.rs[101-140]
- pnpm/crates/cli/src/parse_boundary/tests.rs[1-93]

### Suggested fix
- Update the width logic so it correctly skips the value for *all* value-consuming global options (at minimum: `workspace-concurrency`, `resume-from`, `test-pattern`, `changed-files-ignore-pattern`).
- Preferably, derive “consumes value” from clap metadata (similar to `ArgTable` usage in `shorthands`/`flag_relocation`) instead of maintaining a hard-coded list.
- Add regression tests in `parse_boundary/tests.rs` for cases like:
 - `pnpm --workspace-concurrency 2 install --config.registry=...` (must not treat `install` as passthrough)
 - `pnpm --test-pattern foo run build --silent` (must not treat `foo` as positional command)

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

3. Repeated clap command rebuilds ✓ Resolved 🐞 Bug ➹ Performance
Description
parse_boundary calls CliArgs::command() in multiple helper functions
(is_known_top_level_command, resolves_to_any), potentially rebuilding the full clap command tree
more than once per boundary computation. This adds avoidable startup overhead in the pre-clap argv
passes, even though the CLI later builds the full command anyway.
Code

pnpm/crates/cli/src/parse_boundary.rs[R146-155]

+pub(crate) fn is_known_top_level_command(name: &str) -> bool {
+    CliArgs::command().get_subcommands().any(|command| resolves_to(command, name))
+}
+
+/// Whether `name` is one of `canonical_names`, or an alias of one.
+fn resolves_to_any(name: &str, canonical_names: &[&str]) -> bool {
+    CliArgs::command()
+        .get_subcommands()
+        .any(|command| canonical_names.contains(&command.get_name()) && resolves_to(command, name))
+}
Relevance

⭐⭐⭐ High

Repo has accepted micro-optimizations to avoid repeated expensive work/allocations in CLI startup
paths.

PR-#13300
PR-#13207

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
parse_boundary currently calls CliArgs::command() from more than one helper, implying multiple
command-tree constructions during one boundary scan. The CLI startup path already treats command
construction as expensive enough to warrant special handling on Windows, so avoiding redundant
builds is a reasonable performance improvement.

pnpm/crates/cli/src/parse_boundary.rs[142-155]
pnpm/crates/cli/src/lib.rs[23-33]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`parse_boundary` repeatedly constructs `CliArgs::command()` to look up subcommands/aliases. Constructing the clap command tree is non-trivial, and doing it multiple times per invocation adds avoidable startup overhead.

### Issue Context
The boundary computation runs before clap parsing (in both config override extraction and shorthand expansion), and `run_cli` later constructs a full command (including boolean-negation augmentation).

### Fix Focus Areas
- pnpm/crates/cli/src/parse_boundary.rs[11-159]
- pnpm/crates/cli/src/lib.rs[23-67]

### Suggested fix
- Construct `let cmd = CliArgs::command();` once inside `passthrough_from()` (or `command_boundary()`) and pass `&cmd` down to helpers, instead of calling `CliArgs::command()` inside each helper.
- Alternatively, precompute a small lookup structure (set/map) of subcommand names and aliases once and reuse it for both `takes_a_foreign_command_line` and `is_known_top_level_command`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

4. Changeset missing pnpm entry 📘 Rule violation § Compliance ⭐ New
Description
The new changeset lists only pacquet and omits the required pnpm package entry, so the release
tooling cannot correctly bump pnpm for this user-visible CLI behavior change. This violates the
changeset requirement to explicitly declare pnpm with an appropriate bump type.
Code

.changeset/pacquet-preclap-escape-boundary.md[R1-3]

+---
+"pacquet": patch
+---
Relevance

⭐ Low

Multiple recent PRs rejected adding required "pnpm" entry to pacquet-only changesets despite same
compliance claim.

PR-#13300
PR-#13304
PR-#13298

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires changesets to include an explicit pnpm package entry with a valid
bump type. The added changeset front-matter contains only "pacquet": patch and does not declare
pnpm.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/pacquet-preclap-escape-boundary.md[1-3]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The changeset front-matter is missing an explicit `pnpm` entry (with a valid bump type).

## Issue Context
Compliance requires every new/modified changeset to declare the `pnpm` package and its bump type (`patch`/`minor`/`major`). This changeset currently declares only `pacquet`.

## Fix Focus Areas
- .changeset/pacquet-preclap-escape-boundary.md[1-3]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. Weak with passthrough test ✓ Resolved 🐞 Bug ⚙ Maintainability
Description
with_forwards_only_for_a_version_that_execs_a_child only asserts the forwarded argv contains the
last token, so it can still pass even if passthrough_from() forwards the wrong slice (e.g.,
dropping the child command like install). This weakens regression protection for with, where
correctness depends on forwarding the full child pnpm command line (command + its args).
Code

pnpm/crates/cli/src/parse_boundary/tests.rs[R130-138]

+    for argv in [
+        ["with", "10", "install", "--config.foo=bar"].as_slice(),
+        &["with", "pnpm@9", "install", "--silent"],
+    ] {
+        let (_, forwarded) = split(argv);
+        assert!(
+            forwarded.contains(&argv[argv.len() - 1].to_string()),
+            "{argv:?} must forward its child's own options, got {forwarded:?}",
+        );
Relevance

⭐⭐⭐ High

Team has accepted strengthening tests to assert stricter invariants and catch subtle regressions.

PR-#13227

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The test currently only checks for the last token’s presence, which would still succeed if the child
command token (install) is missing from forwarded. But with’s runtime behavior depends on
forwarding the full child argv after the version spec, since WithArgs::run passes the tail args
directly to spawn_pnpm.

pnpm/crates/cli/src/parse_boundary/tests.rs[130-138]
pnpm/crates/cli/src/cli_args/with.rs[64-99]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The `with_forwards_only_for_a_version_that_execs_a_child` test currently uses `forwarded.contains(last_token)` which can pass even when the boundary is incorrect (e.g., if the child command token like `install` is missing or if extra tokens are mistakenly forwarded).

### Issue Context
`pacquet with <spec> <child-pnpm-argv...>` works by splitting params into `(spec, args)` and spawning the child pnpm with `args`; correctness therefore requires the *entire* child argv (including the command token) to be forwarded untouched.

### Fix Focus Areas
- pnpm/crates/cli/src/parse_boundary/tests.rs[126-139]

### Suggested fix
Replace the `contains(...)` assertion with `assert_eq!` against the full expected forwarded vector for each case, e.g.:
- `with 10 install --config.foo=bar` => forwarded should be `['install', '--config.foo=bar']`
- `with pnpm@9 install --silent` => forwarded should be `['install', '--silent']`

This makes the test pin both the boundary position and the full forwarded child command line.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Previous review results

Review updated until commit 09573f4

Results up to commit c78afb1 ⚖️ Balanced


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Action required
1. Wrong option width table ✓ Resolved 🐞 Bug ≡ Correctness
Description
parse_boundary::global_option_width does not include several global options that consume a
following value (e.g. --workspace-concurrency, --resume-from, --test-pattern), so
passthrough_from() can treat the option value as a positional and establish the passthrough
boundary too early. This can cause ConfigOverrides::extract() to stop scanning before later
--config.* tokens, leaving them for clap to parse and fail as “unexpected argument” (e.g. `pnpm
--workspace-concurrency 2 install --config.registry=...`).
Code

pnpm/crates/cli/src/parse_boundary.rs[R113-140]

+fn global_option_width(arg: &str) -> Option<usize> {
+    if matches!(arg, "-r" | "-v") {
+        return Some(1);
+    }
+    if matches!(arg, "-C" | "-F") {
+        return Some(2);
+    }
+    if arg.starts_with("-C") || arg.starts_with("-F") {
+        return Some(1);
+    }
+    let name = arg.strip_prefix("--")?;
+    let (name, has_value) = name.split_once('=').map_or((name, false), |(name, _)| (name, true));
+    let consumes_value = matches!(
+        name,
+        "dir"
+            | "filter"
+            | "filter-prod"
+            | "http-proxy"
+            | "https-proxy"
+            | "no-proxy"
+            | "npmrc-auth-file"
+            | "registry"
+            | "reporter"
+            | "store-dir"
+            | "userconfig",
+    );
+    Some(if consumes_value && !has_value { 2 } else { 1 })
+}
Relevance

⭐⭐⭐ High

Likely real argv misparse; team fixes CLI parsing edge cases and option-terminator issues.

PR-#13203
PR-#13008

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
parse_boundary uses a hard-coded list of long options that consume a value; options not listed are
treated as width 1, so their values can be misread as positionals. CliArgs defines multiple
additional global=true options that take values, and ConfigOverrides::extract now relies on
passthrough_from to decide when to stop stripping --config.* tokens, so an early boundary
directly breaks config override extraction.

pnpm/crates/cli/src/parse_boundary.rs[101-140]
pnpm/crates/cli/src/cli_args/cli_command.rs[171-223]
pnpm/crates/cli/src/config_overrides.rs[96-123]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`parse_boundary::global_option_width()` hard-codes which global options consume a separate value token. It currently omits several value-taking globals defined on `CliArgs`, so boundary scanning can misinterpret the next token (the option’s value) as a positional command/script name and compute an incorrect passthrough boundary.

This can prevent `ConfigOverrides::extract()` from stripping `--config.*` tokens (because it stops scanning at the computed boundary), which then causes clap to reject those tokens as unexpected.

### Issue Context
`passthrough_from()` is now used by both `ConfigOverrides::extract()` and `expand_universal_shorthands()`, so any boundary misclassification affects multiple pre-clap argv passes.

### Fix Focus Areas
- pnpm/crates/cli/src/parse_boundary.rs[101-140]
- pnpm/crates/cli/src/parse_boundary/tests.rs[1-93]

### Suggested fix
- Update the width logic so it correctly skips the value for *all* value-consuming global options (at minimum: `workspace-concurrency`, `resume-from`, `test-pattern`, `changed-files-ignore-pattern`).
- Preferably, derive “consumes value” from clap metadata (similar to `ArgTable` usage in `shorthands`/`flag_relocation`) instead of maintaining a hard-coded list.
- Add regression tests in `parse_boundary/tests.rs` for cases like:
 - `pnpm --workspace-concurrency 2 install --config.registry=...` (must not treat `install` as passthrough)
 - `pnpm --test-pattern foo run build --silent` (must not treat `foo` as positional command)

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
2. Repeated clap command rebuilds ✓ Resolved 🐞 Bug ➹ Performance
Description
parse_boundary calls CliArgs::command() in multiple helper functions
(is_known_top_level_command, resolves_to_any), potentially rebuilding the full clap command tree
more than once per boundary computation. This adds avoidable startup overhead in the pre-clap argv
passes, even though the CLI later builds the full command anyway.
Code

pnpm/crates/cli/src/parse_boundary.rs[R146-155]

+pub(crate) fn is_known_top_level_command(name: &str) -> bool {
+    CliArgs::command().get_subcommands().any(|command| resolves_to(command, name))
+}
+
+/// Whether `name` is one of `canonical_names`, or an alias of one.
+fn resolves_to_any(name: &str, canonical_names: &[&str]) -> bool {
+    CliArgs::command()
+        .get_subcommands()
+        .any(|command| canonical_names.contains(&command.get_name()) && resolves_to(command, name))
+}
Relevance

⭐⭐⭐ High

Repo has accepted micro-optimizations to avoid repeated expensive work/allocations in CLI startup
paths.

PR-#13300
PR-#13207

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
parse_boundary currently calls CliArgs::command() from more than one helper, implying multiple
command-tree constructions during one boundary scan. The CLI startup path already treats command
construction as expensive enough to warrant special handling on Windows, so avoiding redundant
builds is a reasonable performance improvement.

pnpm/crates/cli/src/parse_boundary.rs[142-155]
pnpm/crates/cli/src/lib.rs[23-33]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`parse_boundary` repeatedly constructs `CliArgs::command()` to look up subcommands/aliases. Constructing the clap command tree is non-trivial, and doing it multiple times per invocation adds avoidable startup overhead.

### Issue Context
The boundary computation runs before clap parsing (in both config override extraction and shorthand expansion), and `run_cli` later constructs a full command (including boolean-negation augmentation).

### Fix Focus Areas
- pnpm/crates/cli/src/parse_boundary.rs[11-159]
- pnpm/crates/cli/src/lib.rs[23-67]

### Suggested fix
- Construct `let cmd = CliArgs::command();` once inside `passthrough_from()` (or `command_boundary()`) and pass `&cmd` down to helpers, instead of calling `CliArgs::command()` inside each helper.
- Alternatively, precompute a small lookup structure (set/map) of subcommand names and aliases once and reuse it for both `takes_a_foreign_command_line` and `is_known_top_level_command`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Results up to commit 13aa3f6 ⚖️ Balanced


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Action required
1. with missing passthrough boundary ✓ Resolved 📘 Rule violation ≡ Correctness
Description
parse_boundary::passthrough_from() does not treat pnpm with <spec> <pnpm-args...> as a command
that takes a foreign command line, so pre-clap argv rewriting can continue past the version spec and
rewrite or strip tokens intended for the spawned pnpm (e.g., --silent → --reporter=silent, or
--config.* extraction). This creates user-visible behavior that differs from pnpm’s special
escaping for with and can also cause config overrides meant for the child to affect the parent
while it resolves/downloads/execs the requested pnpm version.
Code

pnpm/crates/cli/src/parse_boundary.rs[R15-27]

+/// Commands whose own arguments are a foreign command line.
+///
+/// pnpm's `SPECIALLY_ESCAPED_CMDS` is `run` / `dlx` / `with`; `exec` joins
+/// them here because its argv shape reaches the same place. `with` does
+/// *not*: [`crate::with_current::rewrite`] runs after
+/// [`ConfigOverrides::extract`] and splices the inner command line into
+/// pnpm's own argv, so at this point those tokens are still pnpm's to
+/// claim — `pnpm with current run --config.foo=bar build` must have the
+/// override stripped here, or clap sees it after the rewrite and takes it
+/// for the script name.
+///
+/// [`ConfigOverrides::extract`]: crate::config_overrides::ConfigOverrides::extract
+const COMMANDS_TAKING_A_FOREIGN_COMMAND_LINE: [&str; 3] = ["run", "exec", "dlx"];
Relevance

⭐⭐⭐ High

Repo repeatedly accepts Rust CLI changes to match pnpm TS argv/behavior parity; this is correctness
and user-visible.

PR-#12789
PR-#13006
PR-#13300

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
In parse_boundary, COMMANDS_TAKING_A_FOREIGN_COMMAND_LINE excludes with, which means
passthrough_from() will not establish a stop point at the with spec boundary and pre-clap
transformations can keep operating on arguments that should be forwarded verbatim to the child pnpm.
By contrast, pnpm’s TypeScript argument parser explicitly includes with in
SPECIALLY_ESCAPED_CMDS, demonstrating that upstream pnpm treats with as a specially-escaped
boundary where options after the spec are not parsed/rewritten by the parent, so pacquet’s current
behavior is inconsistent with pnpm’s intended escaping/forwarding semantics.

Rule 713429: Pacquet must not introduce new user-visible behavior beyond pnpm
pnpm/crates/cli/src/parse_boundary.rs[15-27]
pnpm/crates/cli/src/parse_boundary/tests.rs[58-59]
pnpm11/cli/parse-cli-args/src/index.ts[6-8]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`parse_boundary::passthrough_from()` currently does not establish a passthrough boundary for `pnpm with <spec> <cmd> ...`, because `with` is excluded from the set of commands that take a foreign command line. As a result, pre-clap passes (e.g., config override extraction/stripping and universal shorthand expansion) can rewrite or remove flags that are intended to be forwarded verbatim to the spawned pnpm, and may even apply `--config.*` overrides intended for the child to the parent process while it resolves/downloads/execs the requested pnpm version.

## Issue Context
- pnpm’s TypeScript parser treats `with` as a specially-escaped command, so options after the version/range/dist-tag spec are not parsed/rewritten by the parent pnpm.
- pacquet’s Rust `with` command captures the remainder as trailing var-arg positional(s) and forwards everything after the spec directly to the spawned pnpm (e.g., `spawn_pnpm(...).args(args)`), so mutating argv before clap can change what the child pnpm receives.
- The existing `with current ...` rewrite is a deliberate exception that happens in-process after `ConfigOverrides::extract()`, so its inner command line must remain parseable by the parent and should not be treated the same as the general `with <spec> ...` passthrough case.
- This is especially risky because config overrides extracted from the (would-be) child argument list are documented to be applied to the in-process config load; for `with`, that config influences how the engine is resolved/installed, so a `--config.registry=...` intended for the child can affect the parent’s engine download.

## Fix Focus Areas
- pnpm/crates/cli/src/parse_boundary.rs[15-27]
- pnpm/crates/cli/src/parse_boundary.rs[56-60]
- pnpm/crates/cli/src/parse_boundary/tests.rs[58-59]
- pnpm/crates/cli/src/parse_boundary/tests.rs[119-127]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Results up to commit 9bc9e8c ⚖️ Balanced


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Informational
1. Weak with passthrough test ✓ Resolved 🐞 Bug ⚙ Maintainability
Description
with_forwards_only_for_a_version_that_execs_a_child only asserts the forwarded argv contains the
last token, so it can still pass even if passthrough_from() forwards the wrong slice (e.g.,
dropping the child command like install). This weakens regression protection for with, where
correctness depends on forwarding the full child pnpm command line (command + its args).
Code

pnpm/crates/cli/src/parse_boundary/tests.rs[R130-138]

+    for argv in [
+        ["with", "10", "install", "--config.foo=bar"].as_slice(),
+        &["with", "pnpm@9", "install", "--silent"],
+    ] {
+        let (_, forwarded) = split(argv);
+        assert!(
+            forwarded.contains(&argv[argv.len() - 1].to_string()),
+            "{argv:?} must forward its child's own options, got {forwarded:?}",
+        );
Relevance

⭐⭐⭐ High

Team has accepted strengthening tests to assert stricter invariants and catch subtle regressions.

PR-#13227

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The test currently only checks for the last token’s presence, which would still succeed if the child
command token (install) is missing from forwarded. But with’s runtime behavior depends on
forwarding the full child argv after the version spec, since WithArgs::run passes the tail args
directly to spawn_pnpm.

pnpm/crates/cli/src/parse_boundary/tests.rs[130-138]
pnpm/crates/cli/src/cli_args/with.rs[64-99]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The `with_forwards_only_for_a_version_that_execs_a_child` test currently uses `forwarded.contains(last_token)` which can pass even when the boundary is incorrect (e.g., if the child command token like `install` is missing or if extra tokens are mistakenly forwarded).

### Issue Context
`pacquet with <spec> <child-pnpm-argv...>` works by splitting params into `(spec, args)` and spawning the child pnpm with `args`; correctness therefore requires the *entire* child argv (including the command token) to be forwarded untouched.

### Fix Focus Areas
- pnpm/crates/cli/src/parse_boundary/tests.rs[126-139]

### Suggested fix
Replace the `contains(...)` assertion with `assert_eq!` against the full expected forwarded vector for each case, e.g.:
- `with 10 install --config.foo=bar` => forwarded should be `['install', '--config.foo=bar']`
- `with pnpm@9 install --silent` => forwarded should be `['install', '--silent']`

This makes the test pin both the boundary position and the full forwarded child command line.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Qodo Logo

Comment thread pnpm/crates/cli/src/parse_boundary.rs Resolved
@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
pnpm/crates/cli/src/cli_args/run/tests.rs (1)

92-92: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove redundant test doc comments.

  • pnpm/crates/cli/src/cli_args/run/tests.rs#L92-L92: Remove the comment; the test name and assertions state this ordering contract.
  • pnpm/crates/cli/src/cli_args/run/tests.rs#L106-L107: Remove the comment; the test name and assertions state the no-positional behavior.

As per coding guidelines, “Do not duplicate test behavior in documentation”; as per path instructions, comments should explain only non-obvious reasons or invariants.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pnpm/crates/cli/src/cli_args/run/tests.rs` at line 92, Remove the redundant
test doc comments in pnpm/crates/cli/src/cli_args/run/tests.rs at lines 92 and
106-107; the test names and assertions already document the ordering and
no-positional behavior, so leave the test logic unchanged.

Sources: Coding guidelines, Path instructions

pnpm/crates/cli/tests/run.rs (1)

84-90: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use regular comments for private test rationale.

These /// blocks document private test behavior rather than public API contracts. Keep only the non-obvious forwarding rationale in // comments.

  • pnpm/crates/cli/tests/run.rs#L84-L90: replace the rustdoc block with a concise regular comment explaining why the recorder checks lifecycle-stage forwarding.
  • pnpm/crates/cli/src/shorthands/tests.rs#L43-L45: replace the rustdoc block with a concise regular comment explaining the no-rewrite invariant.

As per coding guidelines, “Use rustdoc comments for public API contracts and regular comments for implementation rationale. Do not duplicate test behavior in documentation.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pnpm/crates/cli/tests/run.rs` around lines 84 - 90, Replace the rustdoc block
at pnpm/crates/cli/tests/run.rs:84-90 with a concise regular comment retaining
only the non-obvious lifecycle-stage forwarding rationale for the recorder
assertion. Also replace the rustdoc block at
pnpm/crates/cli/src/shorthands/tests.rs:43-45 with a concise regular comment
explaining the no-rewrite invariant; do not document private test behavior as
public API.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pnpm/crates/cli/tests/run.rs`:
- Around line 119-149: Update the run argument regression test around the
pacquet invocation and recorded assertions to add --config.foo=bar immediately
after foo, without a -- separator, and assert that this override is forwarded to
the recorder as part of the expected arguments. Keep the existing post-script
arguments and other recorded entries unchanged.

---

Nitpick comments:
In `@pnpm/crates/cli/src/cli_args/run/tests.rs`:
- Line 92: Remove the redundant test doc comments in
pnpm/crates/cli/src/cli_args/run/tests.rs at lines 92 and 106-107; the test
names and assertions already document the ordering and no-positional behavior,
so leave the test logic unchanged.

In `@pnpm/crates/cli/tests/run.rs`:
- Around line 84-90: Replace the rustdoc block at
pnpm/crates/cli/tests/run.rs:84-90 with a concise regular comment retaining only
the non-obvious lifecycle-stage forwarding rationale for the recorder assertion.
Also replace the rustdoc block at pnpm/crates/cli/src/shorthands/tests.rs:43-45
with a concise regular comment explaining the no-rewrite invariant; do not
document private test behavior as public API.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: a8f9c13b-7a91-42b9-8170-5d4ccc2e7a46

📥 Commits

Reviewing files that changed from the base of the PR and between ebb6e6b and c78afb1.

📒 Files selected for processing (18)
  • .changeset/pacquet-preclap-escape-boundary.md
  • .changeset/pacquet-run-forwards-script-args.md
  • pnpm/crates/cli/src/cli_args/clean.rs
  • pnpm/crates/cli/src/cli_args/dispatch_install.rs
  • pnpm/crates/cli/src/cli_args/dispatch_script.rs
  • pnpm/crates/cli/src/cli_args/restart.rs
  • pnpm/crates/cli/src/cli_args/run.rs
  • pnpm/crates/cli/src/cli_args/run/recursive.rs
  • pnpm/crates/cli/src/cli_args/run/tests.rs
  • pnpm/crates/cli/src/cli_args/stop.rs
  • pnpm/crates/cli/src/cli_args/tests.rs
  • pnpm/crates/cli/src/config_overrides.rs
  • pnpm/crates/cli/src/lib.rs
  • pnpm/crates/cli/src/parse_boundary.rs
  • pnpm/crates/cli/src/parse_boundary/tests.rs
  • pnpm/crates/cli/src/shorthands.rs
  • pnpm/crates/cli/src/shorthands/tests.rs
  • pnpm/crates/cli/tests/run.rs

Comment thread pnpm/crates/cli/tests/run.rs Resolved
@zkochan
zkochan marked this pull request as draft July 25, 2026 10:48
@codecov-commenter

codecov-commenter commented Jul 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.82353% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 87.05%. Comparing base (875073e) to head (09573f4).

Files with missing lines Patch % Lines
pnpm/crates/cli/src/parse_boundary.rs 98.71% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #13309   +/-   ##
=======================================
  Coverage   87.05%   87.05%           
=======================================
  Files         532      533    +1     
  Lines       91601    91626   +25     
=======================================
+ Hits        79741    79763   +22     
- Misses      11860    11863    +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zkochan

zkochan commented Jul 25, 2026

Copy link
Copy Markdown
Member Author

All three findings were correct — my design was unsound in two ways. Reworked in 13aa3f6; I had put the PR into draft while fixing it.

Greptile: value options misplace the boundary — and Qodo: wrong option width table

Same root defect, and the more serious of the two. I carried the hand-listed set of value-taking option names over from external_command_index. That list was already incomplete — --workspace-concurrency, --resume-from and --test-pattern were all missing — and moving it to a boundary that every command consults turned a latent gap into a live one: an omitted option's value looks like a positional, so the boundary lands on it.

Confirmed exactly as Greptile described:

pnpm dlx --package cowsay --silent cowsay --moo hi
  before:  parsed=[dlx, --package, cowsay]        forwarded=[--silent, cowsay, --moo, hi]
  after:   parsed=[dlx, --package, cowsay, --silent, cowsay]   forwarded=[--moo, hi]

pnpm's own --silent was being handed to the child.

Fixed by taking arity from clap instead of a name list — flag_relocation::ArgTable, which the shorthand and relocation passes already use for precisely this. The CLI's real option set is now the source of truth, and there is no third hand-maintained copy to drift. Qodo's pnpm --workspace-concurrency 2 install --config.registry=… case is covered by the same change and is in the test table.

Greptile: with current skips config overrides

Also correct, and structural: lib.rs runs ConfigOverrides::extract at line 47 and with_current::rewrite at line 52. So extract sees the un-stripped argv, and treating with's inner command line as the child's left --config.foo=bar in place; after the rewrite spliced with current out, clap saw it and — with run's allow_hyphen_values positional — would have taken it for the script name.

with is no longer in the escaping set. Its inner command line becomes pnpm's own argv, so those tokens are still pnpm's to claim at extract time. This restores with's behavior on main (it was never escaping there either, since a known command short-circuited the old scan).

Verification

All eleven parity cases still match the TypeScript CLI byte for byte; 2216 pacquet-cli tests pass; lint and dylint clean. New tests pin both reported shapes plus the three value-taking globals the old list omitted.

One correction to my own earlier reporting: an intermediate full-suite run showed a handful of unrelated failures (approve_builds, install_pnpm_to_store) that I chased before noticing the machine was at load average 117 from my own concurrent builds. Each failed test passes in isolation and two consecutive clean runs are green, so those were contention, not this change.


Written by an agent (Claude Code, claude-opus-5).

@zkochan
zkochan marked this pull request as ready for review July 25, 2026 11:00
Copilot AI review requested due to automatic review settings July 25, 2026 11:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Comment thread pnpm/crates/cli/src/parse_boundary.rs Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
pnpm/crates/cli/src/parse_boundary.rs (1)

15-26: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use regular comments for private implementation rationale.

These explain deliberate internal behavior rather than public API contracts, so use // instead of ///.

  • pnpm/crates/cli/src/parse_boundary.rs#L15-L26: convert the foreign-command exception rationale to regular comments.
  • pnpm/crates/cli/src/parse_boundary.rs#L117-L123: convert the option-arity rationale to regular comments.

As per coding guidelines, “Use rustdoc comments for public API contracts and regular comments for implementation rationale.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pnpm/crates/cli/src/parse_boundary.rs` around lines 15 - 26, Convert the
implementation-rationale documentation comments near parse-boundary handling
from rustdoc comments to regular comments: update
pnpm/crates/cli/src/parse_boundary.rs lines 15-26 for the foreign-command
exception and lines 117-123 for the option-arity rationale, preserving their
text and behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pnpm/crates/cli/src/parse_boundary.rs`:
- Around line 15-26: Convert the implementation-rationale documentation comments
near parse-boundary handling from rustdoc comments to regular comments: update
pnpm/crates/cli/src/parse_boundary.rs lines 15-26 for the foreign-command
exception and lines 117-123 for the option-arity rationale, preserving their
text and behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7ec9bdd7-42e0-48a0-8c95-805b6abfcaba

📥 Commits

Reviewing files that changed from the base of the PR and between c78afb1 and 13aa3f6.

📒 Files selected for processing (3)
  • pnpm/crates/cli/src/flag_relocation.rs
  • pnpm/crates/cli/src/parse_boundary.rs
  • pnpm/crates/cli/src/parse_boundary/tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • pnpm/crates/cli/src/parse_boundary/tests.rs

Comment thread pnpm/crates/cli/src/parse_boundary.rs Resolved
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 13aa3f6

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

Copilot AI review requested due to automatic review settings July 25, 2026 11:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@zkochan

zkochan commented Jul 25, 2026

Copy link
Copy Markdown
Member Author

Both correct again — fixed in 9bc9e8c. Greptile's with finding shows my previous fix was only half right, and it caught the half I had actively reasoned about and got wrong.

Greptile: versioned with loses child overrides

I had excluded with from the boundary entirely and justified it as "restores main's behavior". That was true but not sufficient: it fixes with current, and leaves pnpm with 10 install --config.foo=bar stripping the override from a command line that is about to be handed to a child pnpm process, which then never sees it.

There is a rule correct for both, and with_current::rewrite hands it over: it fires only when the token after with is literally current.

  • with current … → spliced into pnpm's own argv after the pre-clap passes, so the inner tokens are still pnpm's. Must be claimed here, or clap mistakes the override for the script name.
  • with <any other version> … → execs a child pnpm whose command line is its own. Must be forwarded.

The boundary now splits on exactly that. Both shapes are tested; previously only current was, which is precisely why the versioned case slipped through.

Qodo: repeated clap command rebuilds

Fair. command_boundary already assembles the clap tree for the arity table, so the subcommand lookup now takes that &Command rather than calling CliArgs::command() again — one boundary computation was paying for the assembly up to three times, and assembling it is the expensive part of this module. is_known_top_level_command is gone; the single matching_subcommand(&command, arg) lookup covers both the "is it known" and "which one" questions.

CodeRabbit: cover a post-script config override without --

Good catch, and it applied to this PR's own regression coverage. --other=1 is a token ConfigOverrides::extract never claims, so the end-to-end test could not have caught the config-swallowing bug. Added --config.foo=bar before the separator and to the expected recorder output. Verified it now fails when I disable the escaping rule — it did not before.

Verification

2216 pacquet-cli tests pass, lint and dylint clean, all eleven parity cases still match the TypeScript CLI. Machine is quiet this time (load 3.8 rather than the 117 that produced the spurious failures I mentioned earlier), so this run is trustworthy.


Written by an agent (Claude Code, claude-opus-5).

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pnpm/crates/cli/src/parse_boundary.rs`:
- Around line 83-95: Update the with-current branch in the boundary inference
logic to continue scanning from version + 1 instead of returning None,
preserving nested run/exec/dlx and fallback-script boundaries before
ConfigOverrides::extract or flag rewriting. Add regression coverage for with
current run cases involving --config.foo=bar and --silent, and keep pacquet and
the TypeScript pnpm CLI behaviorally identical.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 752b2b2a-6d9a-49f2-b9cf-0e1ae46ed177

📥 Commits

Reviewing files that changed from the base of the PR and between 13aa3f6 and 9bc9e8c.

📒 Files selected for processing (3)
  • pnpm/crates/cli/src/parse_boundary.rs
  • pnpm/crates/cli/src/parse_boundary/tests.rs
  • pnpm/crates/cli/tests/run.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • pnpm/crates/cli/tests/run.rs
  • pnpm/crates/cli/src/parse_boundary/tests.rs

Comment thread pnpm/crates/cli/src/parse_boundary.rs Resolved
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 9bc9e8c

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

Copilot AI review requested due to automatic review settings July 25, 2026 11:21
@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@github-actions

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 13aa3f6dd1b7

Each scenario reports direct installs and pnpr installs. Bencher consumes pacquet@HEAD and pnpr@HEAD.

The tables below show mean ± σ; Bencher thresholds on the minimum latency, which is far less perturbed by shared-runner contention (noise only adds time).

Scenario: Isolated linker: fresh restore, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.423 ± 0.112 2.362 2.737 1.62 ± 0.15
pacquet@main 2.545 ± 0.182 2.371 2.789 1.71 ± 0.18
pnpr@HEAD 1.506 ± 0.113 1.344 1.737 1.01 ± 0.11
pnpr@main 1.491 ± 0.118 1.359 1.761 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.4229464618799996,
      "stddev": 0.11181339259244279,
      "median": 2.39014032318,
      "user": 1.5953270199999996,
      "system": 1.3232614200000001,
      "min": 2.36196986818,
      "max": 2.73666574318,
      "times": [
        2.41811483118,
        2.41511293818,
        2.73666574318,
        2.36196986818,
        2.37035002918,
        2.37848765918,
        2.37140913418,
        2.39632595018,
        2.38395469618,
        2.39707376918
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.5446684103800004,
      "stddev": 0.18166156597541447,
      "median": 2.46972729368,
      "user": 1.59000512,
      "system": 1.3472185199999998,
      "min": 2.37145141318,
      "max": 2.78938052118,
      "times": [
        2.7429723311800003,
        2.77774604418,
        2.42008242018,
        2.37543316318,
        2.78938052118,
        2.67900421218,
        2.37145141318,
        2.5193721671800002,
        2.38174207918,
        2.38949975218
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.5058517892800003,
      "stddev": 0.11297103164898903,
      "median": 1.48061276018,
      "user": 1.0804106199999999,
      "system": 1.15512062,
      "min": 1.34395020518,
      "max": 1.7373457971800002,
      "times": [
        1.56132111318,
        1.41462721118,
        1.7373457971800002,
        1.4358191951800001,
        1.34395020518,
        1.49302782818,
        1.60596028418,
        1.43970824518,
        1.55856032118,
        1.46819769218
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.4912409840800003,
      "stddev": 0.11844978470909605,
      "median": 1.47312765218,
      "user": 1.09567312,
      "system": 1.18014462,
      "min": 1.35933117418,
      "max": 1.7606858731800001,
      "times": [
        1.35933117418,
        1.56883422118,
        1.47488810318,
        1.7606858731800001,
        1.38881421218,
        1.47136720118,
        1.50184467318,
        1.41109969418,
        1.5669523661800002,
        1.40859232218
      ]
    }
  ]
}

Scenario: Isolated linker: fresh restore, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 261.0 ± 4.4 256.1 270.5 1.00 ± 0.03
pacquet@main 260.7 ± 5.9 251.1 270.8 1.00
pnpr@HEAD 283.8 ± 10.0 273.0 304.3 1.09 ± 0.05
pnpr@main 277.4 ± 5.3 269.0 285.6 1.06 ± 0.03
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.2610259745,
      "stddev": 0.004397037204080372,
      "median": 0.2609187352,
      "user": 0.21095146000000004,
      "system": 0.53955744,
      "min": 0.2561217462,
      "max": 0.2704902682,
      "times": [
        0.2614075402,
        0.2586929792,
        0.26090592619999997,
        0.2573475742,
        0.25624587919999997,
        0.2640327762,
        0.2704902682,
        0.2640835112,
        0.2609315442,
        0.2561217462
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.2607261415,
      "stddev": 0.005929214120927965,
      "median": 0.2609192012,
      "user": 0.22711166,
      "system": 0.5185880399999999,
      "min": 0.2511094852,
      "max": 0.2708067932,
      "times": [
        0.26420525019999996,
        0.2545922662,
        0.2595832442,
        0.2708067932,
        0.2628041512,
        0.26689586719999997,
        0.2554259552,
        0.26032103419999997,
        0.2511094852,
        0.2615173682
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.28377491359999996,
      "stddev": 0.00996579919093516,
      "median": 0.28015418319999996,
      "user": 0.21244266,
      "system": 0.56064694,
      "min": 0.2730396202,
      "max": 0.3042590172,
      "times": [
        0.2791481432,
        0.3042590172,
        0.2948387652,
        0.2898289202,
        0.2785711272,
        0.2860420782,
        0.2811602232,
        0.2750899872,
        0.2757712542,
        0.2730396202
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.2774283636,
      "stddev": 0.005295717586275186,
      "median": 0.2790268612,
      "user": 0.21501086000000003,
      "system": 0.55327384,
      "min": 0.2689875382,
      "max": 0.2856006872,
      "times": [
        0.2734762612,
        0.2807345532,
        0.2689875382,
        0.2698802392,
        0.2814831632,
        0.2800909802,
        0.2788103182,
        0.2792434042,
        0.2856006872,
        0.2759764912
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.795 ± 0.018 2.758 2.816 1.78 ± 0.13
pacquet@main 2.798 ± 0.019 2.754 2.827 1.78 ± 0.13
pnpr@HEAD 1.660 ± 0.123 1.438 1.850 1.06 ± 0.11
pnpr@main 1.571 ± 0.117 1.426 1.707 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.7953806834400003,
      "stddev": 0.018314569203673064,
      "median": 2.7997395660400004,
      "user": 1.7189428599999999,
      "system": 1.38138112,
      "min": 2.7577661260400004,
      "max": 2.81645577604,
      "times": [
        2.7998995920400005,
        2.8080577890400003,
        2.7577661260400004,
        2.7995795400400003,
        2.7937283190400004,
        2.8145910830400003,
        2.77996962504,
        2.8046710800400003,
        2.7790879040400003,
        2.81645577604
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.7977879873400004,
      "stddev": 0.019483955807159403,
      "median": 2.8018075510400005,
      "user": 1.7614190600000001,
      "system": 1.34089312,
      "min": 2.75380911904,
      "max": 2.82663546904,
      "times": [
        2.8007927240400003,
        2.80282237804,
        2.7855261660400004,
        2.82663546904,
        2.8068917050400004,
        2.80834962204,
        2.79108335604,
        2.75380911904,
        2.81112768304,
        2.7908416510400005
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.66022196174,
      "stddev": 0.12336260805198988,
      "median": 1.6504260575399998,
      "user": 1.0397287599999998,
      "system": 1.19725572,
      "min": 1.43843701804,
      "max": 1.84990722304,
      "times": [
        1.43843701804,
        1.66010082204,
        1.84990722304,
        1.64075129304,
        1.73408706504,
        1.56616996904,
        1.5785107600400001,
        1.83059576504,
        1.67703081504,
        1.62662888704
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.5708618915399999,
      "stddev": 0.11650657461060938,
      "median": 1.57975118604,
      "user": 1.0436113599999999,
      "system": 1.1940651199999999,
      "min": 1.42558123804,
      "max": 1.70696093404,
      "times": [
        1.46253086304,
        1.67830200004,
        1.42558123804,
        1.67478046704,
        1.43380240004,
        1.58897254504,
        1.70696093404,
        1.5705298270399999,
        1.70403612704,
        1.46312251404
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 604.0 ± 21.8 579.9 636.2 1.95 ± 0.08
pacquet@main 596.6 ± 14.1 573.9 611.7 1.93 ± 0.06
pnpr@HEAD 315.1 ± 5.4 307.0 325.7 1.02 ± 0.03
pnpr@main 309.7 ± 5.6 299.4 320.7 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.6039930237400001,
      "stddev": 0.021769364841533276,
      "median": 0.6033264441400001,
      "user": 0.7276943200000001,
      "system": 0.69101438,
      "min": 0.5799251676400001,
      "max": 0.6362315956400001,
      "times": [
        0.5960638786400001,
        0.6146040706400001,
        0.6180510906400001,
        0.6105890096400001,
        0.6362315956400001,
        0.6346366416400001,
        0.58270411064,
        0.5799251676400001,
        0.5823617256400001,
        0.5847629466400001
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.5966065840400001,
      "stddev": 0.014090809333677824,
      "median": 0.5988791946400001,
      "user": 0.7340362199999999,
      "system": 0.6830461800000001,
      "min": 0.57389824864,
      "max": 0.6116589446400001,
      "times": [
        0.6034242576400001,
        0.6116589446400001,
        0.59433413164,
        0.5867606486400001,
        0.6089411666400001,
        0.6115320656400001,
        0.57389824864,
        0.5862896436400001,
        0.6088757636400001,
        0.5803509696400001
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.31510570194,
      "stddev": 0.0053897143663152675,
      "median": 0.31404914464,
      "user": 0.21020332000000003,
      "system": 0.5580249799999998,
      "min": 0.30704419864000004,
      "max": 0.32565795964,
      "times": [
        0.31824088264,
        0.31401193864000004,
        0.31222830064,
        0.31331744164,
        0.31408635064,
        0.32565795964,
        0.31070805764000003,
        0.32154276964,
        0.31421911964000004,
        0.30704419864000004
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.3097030116400001,
      "stddev": 0.005590906145483713,
      "median": 0.30991842564000005,
      "user": 0.20763151999999999,
      "system": 0.54780018,
      "min": 0.29938864264000004,
      "max": 0.32073869664000004,
      "times": [
        0.31177691064,
        0.30910105264000004,
        0.31329974964,
        0.31057565864000003,
        0.29938864264000004,
        0.32073869664000004,
        0.30770101564,
        0.30430060264000003,
        0.31088659464,
        0.30926119264
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.922 ± 0.008 1.903 1.932 6.24 ± 0.08
pacquet@main 1.920 ± 0.011 1.904 1.942 6.24 ± 0.08
pnpr@HEAD 0.312 ± 0.009 0.303 0.335 1.01 ± 0.03
pnpr@main 0.308 ± 0.004 0.302 0.313 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.92235789516,
      "stddev": 0.008482875133230127,
      "median": 1.92514675476,
      "user": 0.9429354400000001,
      "system": 0.8017791599999999,
      "min": 1.90330840526,
      "max": 1.93203062426,
      "times": [
        1.92596407926,
        1.92432943026,
        1.92167776726,
        1.93203062426,
        1.90330840526,
        1.91969511426,
        1.92923953726,
        1.92766979026,
        1.92609352326,
        1.9135706802599999
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.9198894379600002,
      "stddev": 0.011026645886821522,
      "median": 1.92107001376,
      "user": 0.9774687400000002,
      "system": 0.7657859599999999,
      "min": 1.90416475826,
      "max": 1.94218782026,
      "times": [
        1.92103890526,
        1.94218782026,
        1.92188919526,
        1.92127328626,
        1.9299891092600001,
        1.9180022752600001,
        1.91314320626,
        1.90610470126,
        1.90416475826,
        1.92110112226
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.31207254946,
      "stddev": 0.009463445599593398,
      "median": 0.30909554126,
      "user": 0.20448474,
      "system": 0.5405823599999999,
      "min": 0.30314855726,
      "max": 0.33467826226,
      "times": [
        0.33467826226,
        0.31921589326,
        0.31089418326,
        0.30444396726,
        0.30482125826,
        0.31674929926,
        0.30953643626,
        0.30858299126,
        0.30865464626,
        0.30314855726
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.30783411796,
      "stddev": 0.003665793549691105,
      "median": 0.30808536426,
      "user": 0.20821853999999998,
      "system": 0.5391000599999999,
      "min": 0.30151039326,
      "max": 0.31343785426,
      "times": [
        0.30964671426,
        0.30312528326,
        0.30541416326,
        0.30151039326,
        0.30749494126,
        0.31104946626,
        0.31049163526,
        0.30754035826,
        0.30863037026,
        0.31343785426
      ]
    }
  ]
}

Scenario: Isolated linker: fresh resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 367.2 ± 7.4 361.9 386.5 4.23 ± 0.10
pacquet@main 366.8 ± 6.9 349.8 374.8 4.22 ± 0.10
pnpr@HEAD 87.6 ± 1.3 85.5 91.2 1.01 ± 0.02
pnpr@main 86.9 ± 1.2 84.3 88.9 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.36721032724,
      "stddev": 0.007368729206572527,
      "median": 0.36459681914000003,
      "user": 0.36126122,
      "system": 0.05293469999999999,
      "min": 0.36191456364,
      "max": 0.38652858564000003,
      "times": [
        0.36409153364,
        0.36191456364,
        0.36582110064,
        0.36279822764,
        0.36430730864000005,
        0.36488632964,
        0.36240596864,
        0.36776930864,
        0.37158034564000003,
        0.38652858564000003
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.3668307531400001,
      "stddev": 0.006905076351650309,
      "median": 0.36797291664000004,
      "user": 0.35561412000000003,
      "system": 0.058114,
      "min": 0.34979942864,
      "max": 0.37484690664000003,
      "times": [
        0.36468473964000003,
        0.37317862564000004,
        0.34979942864,
        0.36739849964000004,
        0.36877624464000003,
        0.36366306664000003,
        0.37484690664000003,
        0.36700762464000003,
        0.37040506164000003,
        0.36854733364000003
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.08755081744645163,
      "stddev": 0.0012724343831311028,
      "median": 0.08737601064000002,
      "user": 0.022651926451612906,
      "system": 0.007611616129032255,
      "min": 0.08547883764000001,
      "max": 0.09115957464,
      "times": [
        0.09115957464,
        0.08937110764000002,
        0.08983732564000001,
        0.08597545264,
        0.08961559764000002,
        0.08587367164000001,
        0.08737601064000002,
        0.08677563964000001,
        0.08719233364000001,
        0.08751727564,
        0.08688559664,
        0.08736308564,
        0.08745378664,
        0.08739264164,
        0.08727449964,
        0.08814898564000001,
        0.08631908064,
        0.08876974464000001,
        0.08547883764000001,
        0.08767857964,
        0.08689509464,
        0.08774046664000001,
        0.08593690064000001,
        0.08899192264000001,
        0.08772651064,
        0.08771581964000001,
        0.08619743064,
        0.08705012664,
        0.08707467264,
        0.08831398664000001,
        0.08697358164
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.08687018170249998,
      "stddev": 0.0011903042240228512,
      "median": 0.08685820064000001,
      "user": 0.020734213749999997,
      "system": 0.008729134375,
      "min": 0.08431211964000002,
      "max": 0.08889348764,
      "times": [
        0.08749989364,
        0.08666059264,
        0.08818857964000001,
        0.08711290464000002,
        0.08669046964,
        0.08754594064000001,
        0.08854751664,
        0.08569702864,
        0.08768080464000001,
        0.08887121564000001,
        0.08604500364,
        0.08810149564000001,
        0.08595480364000001,
        0.08685497964000001,
        0.08690758864,
        0.08842077764,
        0.08889348764,
        0.08537963164000001,
        0.08763272364000001,
        0.08684127364000001,
        0.08707002364000001,
        0.08621920164,
        0.08574875564000001,
        0.08591571964000001,
        0.08809253964000001,
        0.08466008464000001,
        0.08614648464,
        0.08515998764,
        0.08686142164,
        0.08774647764000001,
        0.08638628664,
        0.08431211964000002
      ]
    }
  ]
}

Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.508 ± 0.133 4.430 4.874 1.27 ± 0.07
pacquet@main 4.594 ± 0.160 4.452 4.908 1.29 ± 0.07
pnpr@HEAD 3.557 ± 0.151 3.456 3.864 1.00
pnpr@main 3.592 ± 0.161 3.449 3.875 1.01 ± 0.06
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.508498818720001,
      "stddev": 0.13328875127371917,
      "median": 4.47002883682,
      "user": 1.78012158,
      "system": 1.4001327399999999,
      "min": 4.43006653432,
      "max": 4.87379774132,
      "times": [
        4.44181971832,
        4.44723046632,
        4.43025433932,
        4.46309942132,
        4.87379774132,
        4.55014223332,
        4.43006653432,
        4.49465020732,
        4.47695825232,
        4.47696927332
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.59357203542,
      "stddev": 0.15956476647097595,
      "median": 4.5487044788199995,
      "user": 1.7971449800000001,
      "system": 1.36520284,
      "min": 4.4517247303200005,
      "max": 4.90823468732,
      "times": [
        4.90823468732,
        4.81031811632,
        4.45765215532,
        4.4517247303200005,
        4.58147543632,
        4.46554004532,
        4.63612013132,
        4.46186679932,
        4.64685473132,
        4.51593352132
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.55686254052,
      "stddev": 0.1513505622421991,
      "median": 3.47992976482,
      "user": 1.21507998,
      "system": 1.2590696400000003,
      "min": 3.45622009332,
      "max": 3.86359617732,
      "times": [
        3.86359617732,
        3.81269341332,
        3.52246134932,
        3.5476357693200002,
        3.45622009332,
        3.47300855632,
        3.46617466332,
        3.47455411932,
        3.46697585332,
        3.48530541032
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 3.59176861622,
      "stddev": 0.16063720174423554,
      "median": 3.52225056632,
      "user": 1.1941501799999998,
      "system": 1.27838434,
      "min": 3.44855013832,
      "max": 3.87493372932,
      "times": [
        3.59045808732,
        3.48246281632,
        3.87493372932,
        3.80782629432,
        3.56203831632,
        3.46331945832,
        3.44855013832,
        3.75066391332,
        3.4685625243200002,
        3.4688708843200002
      ]
    }
  ]
}

@github-actions

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13309
Testbedpacquet
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
🚷 view threshold
2,757.77 ms
(-2.38%)Baseline: 2,825.03 ms
3,390.03 ms
(81.35%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
1,903.31 ms
(-4.81%)Baseline: 1,999.49 ms
2,399.38 ms
(79.32%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
579.93 ms
(-12.96%)Baseline: 666.24 ms
799.48 ms
(72.54%)
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
361.91 ms
(-11.36%)Baseline: 408.32 ms
489.98 ms
(73.86%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
2,361.97 ms
(-2.23%)Baseline: 2,415.93 ms
2,899.11 ms
(81.47%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
4,430.07 ms
(-1.93%)Baseline: 4,517.18 ms
5,420.62 ms
(81.73%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
256.12 ms
(-6.64%)Baseline: 274.34 ms
329.20 ms
(77.80%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/13309
Testbedpnpr

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds flag.

Click to view all benchmark results
BenchmarkLatencymilliseconds (ms)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,438.44 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
303.15 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
307.04 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
85.48 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,343.95 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
3,456.22 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
273.04 ms
🐰 View full continuous benchmarking report in Bencher

Copilot AI review requested due to automatic review settings July 25, 2026 11:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 548e101

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

The versioned-`with` case only checked that the forwarded argv contained
the last token, so it would have passed with the child's command dropped —
`install` missing leaves the child pnpm nothing to run, which is precisely
the failure worth catching. Assert the exact slice, as the rest of the
table already does.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings July 25, 2026 11:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@zkochan

zkochan commented Jul 25, 2026

Copy link
Copy Markdown
Member Author

Weak with passthrough test — fixed in 09573f4

Right, and it was the one loose assertion in the table. forwarded.contains(&last_token) would have passed with the child's command dropped — install missing leaves the child pnpm nothing to run, which is exactly the failure worth catching. I had written it loosely to cover two argv shapes in one loop; the rest of the table asserts exact slices, and now so does this:

(
    ["with", "10", "install", "--config.foo=bar"].as_slice(),
    ["install", "--config.foo=bar"].as_slice(),
),
(&["with", "pnpm@9", "install", "--silent"], &["install", "--silent"]),

2231 tests pass, lint and dylint clean.

Note this branch was rebased onto main after #13300 merged, so the diff is now this change alone rather than the stack.


Written by an agent (Claude Code, claude-opus-5).

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 09573f4

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@zkochan
zkochan merged commit ffe8133 into main Jul 25, 2026
32 checks passed
@zkochan
zkochan deleted the fix-13302 branch July 25, 2026 11:55
kairosci added a commit to kairosci/pnpm that referenced this pull request Jul 27, 2026
…13309)

Two passes rewrite argv before clap sees it, and neither stopped where
pnpm stops parsing, so tokens meant for a script were consumed or
rewritten on the way through:

    command                              pnpm            pacquet
    run show --config.foo=bar            forwarded       swallowed
    run show --silent                    --silent        --reporter=silent
    exec node show.js --config.foo=bar   forwarded       swallowed

The `--silent` case is the worse one: the script received a token the user
never typed, not merely one fewer.

`ConfigOverrides::extract` stopped at an explicit `--` and at
`external_command_index`, the first positional naming no known command.
That covers the `pnpm <script>` fallback but not an explicit `run` /
`exec`, where the command *is* known, so no boundary was found and the
scan covered the whole argv. `expand_universal_shorthands` stopped only at
`--`.

Rather than give the shorthand pass a third boundary rule, both now
consult one `parse_boundary::passthrough_from`: the first index that must
reach the child untouched, whether that comes from a `--`, the fallback
command, or a command taking a foreign command line (`run` / `exec` /
`dlx` / `with` — pnpm's `SPECIALLY_ESCAPED_CMDS` plus `exec`). The
separator is scanned independently of the command, so `pnpm install --
--config.foo=bar` still ends parsing.

`recursive` / `multi` / `m` defer the classification by one positional, so
`pnpm -r run build --silent` lands on the same boundary. A package sharing
an escaping command's name does not: `pnpm add run --config.foo=bar` keeps
the setting, because only the command position is classified.

One existing shorthand test asserted the old behavior — that `--silent`
"stays universal" past the script name. Both stacks disagree with it:
`pnpm run show --silent` forwards the flag and does not silence the echo,
while `pnpm run --silent show` silences it. Split into the two positions.

Closes pnpm#13302
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pacquet: pre-clap argv passes consume script arguments past the escape boundary

3 participants