You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
vp -C dev run gives no Bash task completions when the directory is named dev #3608
From the project root, type each command and press Tab immediately after review-.
Input
Expected candidate
Actual candidate
vp -C dev run review-
review-child
No candidates
vp -C ./dev run review-
review-child
review-root
Typing review-child in full and pressing Enter runs the task in the dev directory with either spelling of the path.
This came up while reviewing Vitest option completion. The behavior above reproduces with vp run on the released v1.8.0 CLI. Related discussion in PR #3190
Reproduced: Yes — both reported cases (vp -C dev run review-<TAB> → no candidates, vp -C ./dev run review-<TAB> → review-root) reproduce on current main, and the bug is broader than the dev name: any -C <dir> completes tasks from the invocation directory.
Unit Test: Yes — 4 tests added in the tests module of crates/vp_global_cli/src/main.rs (qualify_completion_chdir_*)
Priority:Priority P2: Has Workaround. Only shell completion is affected — execution (vp -C dev run review-child) works correctly with either path spelling, and users can simply cd into the directory or type the task name. It does break the documented -C completion behavior for every directory target, not just the reported one.
Two defects combined to cause this. First, the pre-completion -C peek in crates/vp_global_cli/src/main.rs was dead code: the shell glue invokes the completer as vp -- <bin> <words...>, so parse_leading_chdir(&args[1..]) always saw the -- separator first and the process cwd was never changed, leaving the cwd-sensitive task completer in the invocation directory. Second, clap_complete 4.6.11's engine matches words against subcommand names before consuming a pending option value, so a directory named like a subcommand (dev, build, ...) routed -C dev run ... into the vp dev subcommand, producing zero candidates.
I found a potential fix for this issue. On branch triagebot/fix-3608, complete_request() now drives the completion via the public CompleteEnv::try_complete, consuming the leading -C <dir> from the completion words (applied with the existing apply_chdir) and rewriting the bare value to a path spelling (dev → ./dev) so the engine consumes it as the option value instead of a subcommand name — the word count is unchanged, so every shell's cursor-index derivation keeps working. This needs human review before merging.
vp -C dev run offers no Bash task completions when the target directory is named dev, and vp -C ./dev run offers the root project's tasks instead of the child directory's tasks. Expected: both spellings complete tasks from the -C target directory (review-child).
Environment
Vite+ global CLI: vp v1.8.0 on PATH (bootstrapped from this checkout; crates/vp_global_cli/Cargo.toml also reports 1.8.0 at current main, HEAD 5cf0b72c8)
vite-plus local package: 1.8.0 (installed from npm in the repro project)
Node.js v24.22.3, pnpm v12.11.2, GNU bash 5.3.9, Ubuntu Linux x86_64
Reporter environment: v1.8.0 global CLI, Bash, macOS (shell-level behavior reproduced identically on Linux, so not host-specific)
Reproduction path
/tmp/vite-plus-triage/gh-3608/repro — the exact project from the issue, plus a web/ control child with script review-web.
Commands attempted and results
Direct clap_complete protocol invocation (what the Bash glue calls): VP_COMPLETE=bash vp -- vp -C dev run review- → no candidates; vp -C ./dev run review- → review-root (wrong).
Execution control (tasks themselves work): vp -C dev run review-child exits 0 and runs in the dev directory, confirming only completion is broken.
Result: reproduced on the current checkout, both reported observations match exactly.
Diagnosis
The behavior is the visible result of two independent defects, one in Vite+ and one an upstream clap_complete engine limitation. Both live in the global-CLI completion path; the local JS CLI has no completion code of its own, so the fix layer is crates/vp_global_cli.
Bug 1 — the -C-before-completion peek never fires (explains ./dev → review-root)
Files/lines: crates/vp_global_cli/src/main.rs:462-474 (parse_leading_chdir(&args[1..]) + apply_chdir before CompleteEnv::...complete()).
All shell glue invokes the completer as vp -- "${words[@]}" (bash: crates/vp_global_cli/completion-register.bash; clap_complete's generated zsh/fish/powershell glue). clap_complete's CompleteEnv::try_complete_ (4.6.11, src/env/mod.rs:239-246) drains argv up to and including --, but the peek in main.rs runs beforecomplete() and sees the raw argv [<vp path>, "--", "vp", "-C", "dev", "run", "review-"].
parse_leading_chdir(&args[1..]) inspects args[1], which is "--", so it always returned None. The process cwd therefore stayed the invocation directory, and the cwd-sensitive task completer (crates/vp_global_cli/src/cli.rs:646, run_tasks_completions → commands::delegate::execute_output(cwd, "run", ...)) suggested the root project's tasks.
Empirical proof: applying the chdir by hand (running the completer from inside dev/) yields review-child for vp run review-; the glued invocation from the root yields review-root.
Bug 2 — clap_complete routes an option value that matches a subcommand name into that subcommand (explains dev → zero candidates)
Upstream: clap_complete 4.6.11, src/engine/complete.rs word loop (~lines 59-65): for every non-flag word it calls current_cmd.find_subcommand(value)before consulting ParseState::Opt (pending option value).
For vp -C dev run review-, after -C sets ParseState::Opt, the next word dev matches the vp dev subcommand (cli.rs:126), so the engine descends into vp dev; run becomes a positional of Dev { args: Vec<String> } (trailing var args, no completer), and review- completes against those positionals → zero candidates.
Any -C target colliding with a vp subcommand triggers this: confirmed dev, build → no candidates; web → root candidates. Verified behaviorally: vp dev run review- (no -C at all) produces the same zero-candidate result, confirming the misroute.
Worth reporting upstream to clap_complete (pending option value should win over the subcommand name match), but it can be worked around in vp_global_cli.
Verification
Verdict: bug — contradicts the documented contract for -C (docs/guide/monorepo.md:210-220: "The global -C flag runs any vp command *as if you had cd'd into the package first, identical to cd <dir> && vp <command>"; the cd dev form completes review-child), the explicit intent in the completion code comment, and execution-vs-completion consistency. No issue/PR establishes an intent for this behavior. Confidence: high.
Fix (branch triagebot/fix-3608)
Changed files: crates/vp_global_cli/src/main.rs only (136 insertions, 11 deletions, including 4 unit tests).
complete_request() now owns the completion request, calling the public CompleteEnv::try_complete with the argv instead of complete() (which re-reads raw argv), after qualify_completion_chdir() has:
dug a leading -C <dir> out of the words behind the -- separator and applied it with the existing apply_chdir (best-effort, silent), and
rewritten the separate -C <dir> form's value to a path spelling (dev → ./dev), which resolves to the same directory but can never equal a subcommand name, so the engine consumes it as the option value. Attached forms (-Cdev, -C=dev) keep the value inside the flag token, and values with path separators or .// prefixes cannot collide, so only bare relative names are rewritten.
Word count is never changed, so the shell-exported _CLAP_COMPLETE_INDEX stays valid for every glue (bash/zsh set it explicitly; fish/PowerShell writers derive the index as args.len() - 1). No env mutation, no new clap arguments, no completion-command-surface changes. While the cursor is still on the -C flag or its value (vp -C <TAB>, vp -C dev<TAB>), the request passes through untouched.
Regression tests
Four unit tests beside the existing parse_leading_chdir tests in crates/vp_global_cli/src/main.rs: qualify_completion_chdir_qualifies_subcommand_named_directory, qualify_completion_chdir_keeps_path_spellings_intact, qualify_completion_chdir_keeps_attached_forms_intact, qualify_completion_chdir_passes_through_mid_chdir_requests. No snapshot fixtures exercise VP_COMPLETE completions, and the PTY snapshot runner drives command execution rather than shell completion glue, so end-to-end behavior was validated manually.
Validation
cargo test -p vp_global_cli — 581 passed (dev and release), including the 4 new tests.
cargo fmt --all --check, crate clippy, just check, and just lint — clean.
End-to-end from the issue's reproduction project (before → after):
Input
Before
After
vp -C dev run review-<TAB>
(none)
review-child
vp -C ./dev run review-<TAB>
review-root
review-child
vp run review-<TAB> (control)
review-root
review-root
vp -C web run review-<TAB> (control)
review-root
review-web
vp -Cdev run review-<TAB>
review-root
review-child
vp -C=dev run review-<TAB>
review-root
review-child
vp -C ../repro/dev run review-<TAB>
review-root
review-child
vp -C dev run <TAB> (new word)
(none)
task + subcommand candidates
vp -C dev<TAB> / vp -C <TAB>
(none)
(none) (unchanged)
Verified through the real Bash glue (_clap_complete_vp with COMP_WORDS/COMP_CWORD/COMP_TYPE=9) and the fish/PowerShell writers (different cursor-index derivation), plus unchanged VP_COMPLETE=bash|zsh vp registration output, VP_COMPLETE=0/VP_COMPLETE= falling through to a normal run, and vp -C dev run review-child execution still running in dev.
Skipped checks and reasons
pnpm test / full JS suites — no TypeScript changes.
just snapshot-test — no snapshot covers shell completions.
Upstream clap_complete engine fix — worth reporting upstream, but the in-repo rewrite fully works around it.
Alternatives considered
Strip the -C tokens and rewrite _CLAP_COMPLETE_INDEX: also works, but requires mutating a process env var after the Tokio runtime exists (edition 2024 unsafe); the path-qualify rewrite achieves the same parse with no index bookkeeping.
Only fix the dead peek: would fix the ./dev case but leave -C dev completing nothing.
A hidden clap flag for completion-only chdir: the engine's subcommand check still misroutes the value word, so it does not work without rewriting the value anyway.
Known remaining limitation
A -C that is not leading (e.g. vp run -C dev <TAB>, or vpr -C dev ... where the glue prepends run) is not consumed by completion; it falls back to the invocation-directory suggestions, matching the pre-existing scope of the leading-only parse_leading_chdir pre-parse used for real runs.
This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.
Activity
voidzero-bot commentedon Nov 29, 2026
vp -C dev run review-<TAB>→ no candidates,vp -C ./dev run review-<TAB>→review-root) reproduce on currentmain, and the bug is broader than thedevname: any-C <dir>completes tasks from the invocation directory.testsmodule ofcrates/vp_global_cli/src/main.rs(qualify_completion_chdir_*)vp -C dev run review-child) works correctly with either path spelling, and users can simplycdinto the directory or type the task name. It does break the documented-Ccompletion behavior for every directory target, not just the reported one.Two defects combined to cause this. First, the pre-completion
-Cpeek incrates/vp_global_cli/src/main.rswas dead code: the shell glue invokes the completer asvp -- <bin> <words...>, soparse_leading_chdir(&args[1..])always saw the--separator first and the process cwd was never changed, leaving the cwd-sensitive task completer in the invocation directory. Second, clap_complete 4.6.11's engine matches words against subcommand names before consuming a pending option value, so a directory named like a subcommand (dev,build, ...) routed-C dev run ...into thevp devsubcommand, producing zero candidates.I found a potential fix for this issue. On branch
triagebot/fix-3608,complete_request()now drives the completion via the publicCompleteEnv::try_complete, consuming the leading-C <dir>from the completion words (applied with the existingapply_chdir) and rewriting the bare value to a path spelling (dev→./dev) so the engine consumes it as the option value instead of a subcommand name — the word count is unchanged, so every shell's cursor-index derivation keeps working. This needs human review before merging.Full Triage Report
Triage report — issue #3608
Issue summary
vp -C dev runoffers no Bash task completions when the target directory is nameddev, andvp -C ./dev runoffers the root project's tasks instead of the child directory's tasks. Expected: both spellings complete tasks from the-Ctarget directory (review-child).Environment
vpv1.8.0 onPATH(bootstrapped from this checkout;crates/vp_global_cli/Cargo.tomlalso reports 1.8.0 at currentmain, HEAD5cf0b72c8)Reproduction path
/tmp/vite-plus-triage/gh-3608/repro— the exact project from the issue, plus aweb/control child with scriptreview-web.Commands attempted and results
clap_completeprotocol invocation (what the Bash glue calls):VP_COMPLETE=bash vp -- vp -C dev run review-→ no candidates;vp -C ./dev run review-→review-root(wrong).VP_COMPLETE=bash vpregister script, invoked_clap_complete_vpwithCOMP_WORDS/COMP_CWORD/COMP_TYPE=9):vp run review-(control)review-rootreview-root✓vp -C dev run review-review-child✗vp -C ./dev run review-review-rootreview-child✗vp -C web run review-(control)review-rootreview-web✗vp -C build run review-(control)vp -C dev run review-childexits 0 and runs in thedevdirectory, confirming only completion is broken.Result: reproduced on the current checkout, both reported observations match exactly.
Diagnosis
The behavior is the visible result of two independent defects, one in Vite+ and one an upstream
clap_completeengine limitation. Both live in the global-CLI completion path; the local JS CLI has no completion code of its own, so the fix layer iscrates/vp_global_cli.Bug 1 — the
-C-before-completion peek never fires (explains./dev→review-root)crates/vp_global_cli/src/main.rs:462-474(parse_leading_chdir(&args[1..])+apply_chdirbeforeCompleteEnv::...complete()).vp -- "${words[@]}"(bash:crates/vp_global_cli/completion-register.bash; clap_complete's generated zsh/fish/powershell glue). clap_complete'sCompleteEnv::try_complete_(4.6.11,src/env/mod.rs:239-246) drains argv up to and including--, but the peek inmain.rsruns beforecomplete()and sees the raw argv[<vp path>, "--", "vp", "-C", "dev", "run", "review-"].parse_leading_chdir(&args[1..])inspectsargs[1], which is"--", so it always returnedNone. The process cwd therefore stayed the invocation directory, and the cwd-sensitive task completer (crates/vp_global_cli/src/cli.rs:646,run_tasks_completions→commands::delegate::execute_output(cwd, "run", ...)) suggested the root project's tasks.parse_leading_chdirunit tests pass because they never include the--+ bin-name prefix.dev/) yieldsreview-childforvp run review-; the glued invocation from the root yieldsreview-root.Bug 2 — clap_complete routes an option value that matches a subcommand name into that subcommand (explains
dev→ zero candidates)src/engine/complete.rsword loop (~lines 59-65): for every non-flag word it callscurrent_cmd.find_subcommand(value)before consultingParseState::Opt(pending option value).vp -C dev run review-, after-CsetsParseState::Opt, the next worddevmatches thevp devsubcommand (cli.rs:126), so the engine descends intovp dev;runbecomes a positional ofDev { args: Vec<String> }(trailing var args, no completer), andreview-completes against those positionals → zero candidates.-Ctarget colliding with avpsubcommand triggers this: confirmeddev,build→ no candidates;web→ root candidates. Verified behaviorally:vp dev run review-(no-Cat all) produces the same zero-candidate result, confirming the misroute.vp_global_cli.Verification
Verdict: bug — contradicts the documented contract for
-C(docs/guide/monorepo.md:210-220: "The global-Cflag runs any vp command *as if you hadcd'd into the package first, identical tocd <dir> && vp <command>"; thecd devform completesreview-child), the explicit intent in the completion code comment, and execution-vs-completion consistency. No issue/PR establishes an intent for this behavior. Confidence: high.Fix (branch
triagebot/fix-3608)Changed files:
crates/vp_global_cli/src/main.rsonly (136 insertions, 11 deletions, including 4 unit tests).complete_request()now owns the completion request, calling the publicCompleteEnv::try_completewith the argv instead ofcomplete()(which re-reads raw argv), afterqualify_completion_chdir()has:-C <dir>out of the words behind the--separator and applied it with the existingapply_chdir(best-effort, silent), and-C <dir>form's value to a path spelling (dev→./dev), which resolves to the same directory but can never equal a subcommand name, so the engine consumes it as the option value. Attached forms (-Cdev,-C=dev) keep the value inside the flag token, and values with path separators or.//prefixes cannot collide, so only bare relative names are rewritten.Word count is never changed, so the shell-exported
_CLAP_COMPLETE_INDEXstays valid for every glue (bash/zsh set it explicitly; fish/PowerShell writers derive the index asargs.len() - 1). No env mutation, no new clap arguments, no completion-command-surface changes. While the cursor is still on the-Cflag or its value (vp -C <TAB>,vp -C dev<TAB>), the request passes through untouched.Regression tests
Four unit tests beside the existing
parse_leading_chdirtests incrates/vp_global_cli/src/main.rs:qualify_completion_chdir_qualifies_subcommand_named_directory,qualify_completion_chdir_keeps_path_spellings_intact,qualify_completion_chdir_keeps_attached_forms_intact,qualify_completion_chdir_passes_through_mid_chdir_requests. No snapshot fixtures exerciseVP_COMPLETEcompletions, and the PTY snapshot runner drives command execution rather than shell completion glue, so end-to-end behavior was validated manually.Validation
cargo test -p vp_global_cli— 581 passed (dev and release), including the 4 new tests.cargo fmt --all --check, crate clippy,just check, andjust lint— clean.vp -C dev run review-<TAB>review-childvp -C ./dev run review-<TAB>review-rootreview-childvp run review-<TAB>(control)review-rootreview-rootvp -C web run review-<TAB>(control)review-rootreview-webvp -Cdev run review-<TAB>review-rootreview-childvp -C=dev run review-<TAB>review-rootreview-childvp -C ../repro/dev run review-<TAB>review-rootreview-childvp -C dev run <TAB>(new word)vp -C dev<TAB>/vp -C <TAB>Verified through the real Bash glue (
_clap_complete_vpwithCOMP_WORDS/COMP_CWORD/COMP_TYPE=9) and the fish/PowerShell writers (different cursor-index derivation), plus unchangedVP_COMPLETE=bash|zsh vpregistration output,VP_COMPLETE=0/VP_COMPLETE=falling through to a normal run, andvp -C dev run review-childexecution still running indev.Skipped checks and reasons
pnpm test/ full JS suites — no TypeScript changes.just snapshot-test— no snapshot covers shell completions.clap_completeengine fix — worth reporting upstream, but the in-repo rewrite fully works around it.Alternatives considered
-Ctokens and rewrite_CLAP_COMPLETE_INDEX: also works, but requires mutating a process env var after the Tokio runtime exists (edition 2024unsafe); the path-qualify rewrite achieves the same parse with no index bookkeeping../devcase but leave-C devcompleting nothing.Known remaining limitation
A
-Cthat is not leading (e.g.vp run -C dev <TAB>, orvpr -C dev ...where the glue prependsrun) is not consumed by completion; it falls back to the invocation-directory suggestions, matching the pre-existing scope of the leading-onlyparse_leading_chdirpre-parse used for real runs.This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.
I've opened a pull request with this fix: #3609