Skip to content

fix(wsl): pass guest argv verbatim through --exec - #15039

Merged
OrcaWin merged 4 commits into
mainfrom
OrcaWin/wsl-exec-verbatim-argv
Aug 18, 2026
Merged

OrcaWin merged 4 commits into
mainfrom
OrcaWin/wsl-exec-verbatim-argv

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Aug 17, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 27 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​239 $\color{#cf222e}{\Huge{\mathbf{−}}}$​113 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​126
Prod 28 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​81 $\color{#cf222e}{\Huge{\mathbf{−}}}$​129 $\color{#cf222e}{\Huge{\mathbf{−}}}$​48

Stack

Merge bottom-up; each PR is based on the one above it.

# PR Base
1 ▶ #15039 main fix(wsl): pass guest argv verbatim through --exec ← you are here
2 #15040 #15039 fix(wsl): read machine output from a fenced login shell
3 #15060 #15040 fix(git): fence buffered WSL login-shell reads
4 #15257 #15060 fix(git): run WSL git reads without a shell

ELI5

When Orca asks WSL to run something, it hands wsl.exe a little shell script. But wsl.exe reads that script first and swaps out anything that looks like a variable — $HOME, $2, $PATH — before the Linux side ever sees it. So a script that says "print the word $HOME" arrives as "print /home/you", and awk '{print $2}' arrives as awk '{print }'.

Orca tried to defend against this by escaping every $. That escaper had a hole, and half the call sites never used it at all.

wsl.exe has a flag that turns the rewriting off: --exec. This PR uses it everywhere and deletes the escaper.

Root cause

wsl.exe -d <distro> -- <argv> expands $name in every argument against the guest environment before the guest runs. This is wsl.exe itself, not the guest shell — it happens with no shell in the command at all:

$ wsl.exe -d Ubuntu-24.04 --      /usr/bin/printf %s '$HOME'
/home/neil                 <-- wsl.exe substituted it
$ wsl.exe -d Ubuntu-24.04 --exec  /usr/bin/printf %s '$HOME'
$HOME                      <-- argv passed through untouched

escapeWslShCommandForWindows compensated by rewriting $ to \$, but skipped any $ preceded by a backslash:

if (char === '$' && command[index - 1] !== '\') { escaped += '\$' }

So a POSIX script containing \$ — an escaped dollar inside double quotes, or a sed/awk program — was left unescaped and silently corrupted. And runner.ts's non-login path, wsl.ts, skill-discovery-wsl.ts and others never called the escaper at all.

Evidence

Measured against a real Ubuntu-24.04. The A/B holds the login-shell wrapper constant and changes only -- → --exec:

case today (-- + escaper) this PR (--exec) same?
plain echo "READY" "READY" yes
variable expansion "[bar]" "[bar]" yes
awk '{print $2}' "b\n" "b\n" yes
sed backreference "bac\n" "bac\n" yes
single-quoted $ "[$HOME]" "[$HOME]" yes
exit code 7 c=7 c=7 yes
nested quotes identical identical yes
grep $ anchor "foo\n" "foo\n" yes
literal \$HOME "[/home/neil]" "[$HOME]" no — bug fixed

Eight of nine byte-identical; the only divergence is the escaper's bug. Unescaped call sites were worse — awk '{print $2}' returned the whole line a b instead of b.

--exec was also verified to preserve everything the callers depend on: exit codes (exit 7 → 7, git in a non-repo → 128), bare-name PATH resolution, separate stderr, 20k-char argv, and the /usr/bin/env VAR=x prefix form. The codebase already shipped --exec on the direct-git path, so this is not a new compatibility dependency.

What changed

  • buildWslExecArgs() is the single place that builds wsl.exe argv.
  • escapeWslShCommandForWindows and its tests are deleted.
  • Every production call site now uses --exec. The second -- in sh -s -- <path> is a shell argument separator and is deliberately left alone.

Net −50 lines of production code.

Second pass: the blind spots

A follow-up audit of every wsl.exe invocation found sites the first pass missed — including two it actively broke:

  • config/scripts/wsl-git-shell-benchmark.mjs imported escapeWslShCommandForWindows, which no longer exists, so the script threw on startup.
  • classifySubprocessCommand unwrapped wsl.exe … -- <binary> by breaking on -- alone. With every spawn now on --exec it never found the guest binary and bucketed all WSL subprocesses as plain wsl, losing the git/gh/glab breakdown in diagnostics. It now breaks on either separator, since foreign wsl.exe processes still use --.
  • CliSkillRuntimeSetup.tsx builds its setup command as a template literal, not an argv array, so no array-shaped search could see it. Its decoder accepts both separators so commands persisted before this change still decode.
  • Two more -- sites in tests/e2e/ and config/scripts/, outside the original guard's scanned root.

Guard

A test walks the tree and fails if the -- form reappears. Both spellings that have shipped a regression are covered — the argv array and the command string — across src/, config/ and tests/. It skips comment lines so prose about the old form stays allowed, and asserts it scanned a plausible file count so a bad root cannot make it silently vacuous. Both forms were mutation-checked: each fails and names the offending file when a violation is injected.

Testing

  • buildWslLoginShellCommand payloads round-trip through a live distro.
  • Four regression cases (awk field ref, literal \$, sed backreference, single-quoted $) assert byte-for-byte guest delivery — each returned the wrong bytes before this change.
  • Typecheck (node/cli/web), oxlint, and the code-quality gate are clean.
  • Suite compared against origin/main on the same machine, at test-name granularity. The remaining local failures are present on unmodified main too (verified by re-running main right then, since some of these suites leave on-disk state and a stale baseline lies).

`wsl.exe <...> -- <argv>` expands `$name` in every argument against the
guest environment before the guest ever runs. It does this even when no
shell is involved, so `-- /usr/bin/printf %s '$HOME'` prints /home/you.

Every WSL invocation went through that preprocessor, so scripts arrived
already rewritten: `awk '{print $2}'` lost its field reference, and a
POSIX script asking for the literal `$HOME` got the expanded path.

`escapeWslShCommandForWindows` tried to compensate by escaping `$`, but
it skipped any `$` preceded by a backslash, so a script containing `\$`
was still corrupted -- and half the call sites never applied it at all.

Route every invocation through `--exec`, which passes argv through
untouched, and delete the escaper. The direct-git path already used
`--exec`, so this is not a new compatibility dependency.

A guard test fails if the `--` form reappears anywhere in the tree.

Net -50 lines of production code.
@coderabbitai

coderabbitai Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change standardizes WSL invocations on wsl.exe --exec. A shared buildWslExecArgs helper now assembles distro and shell arguments without Windows-specific escaping. Claude, Codex, Git, preflight, filesystem, PTY, hook, skill, and rate-limit paths use the new form. Tests update expected arguments and verify guest-shell variable expansion and unchanged script transmission.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.92% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the problem, solution, scope, evidence, and testing, but it omits the required linked issue and several template sections. Add a linked issue, Visual Proof with N/A and a reason, Review, boundary, Notes, Checklist, and any applicable AI Disclosure details.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: passing guest arguments verbatim through WSL using --exec.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@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: 2

🧹 Nitpick comments (1)
src/shared/wsl-login-shell-command.ts (1)

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

Condense the repeated --exec comments.

Keep the reason for --exec, but state it in one short comment at each site.

  • src/shared/wsl-login-shell-command.ts#L5-L14: reduce the JSDoc to one concise statement about preserving guest-shell $name references.
  • src/shared/wsl-login-shell-command.test.ts#L165-L167: reduce the test comment to one concise statement about --exec preserving argv.

As per coding guidelines: “Comments must be concise, non-obvious, and brief—prefer one line.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 66c8085c-dae4-41c6-8525-cb97d8578459

📥 Commits

Reviewing files that changed from the base of the PR and between 77ef6bb and 203f0d7.

📒 Files selected for processing (46)
  • src/main/claude-accounts/claude-account-service-login-process.test.ts
  • src/main/claude-accounts/runtime-auth-service.ts
  • src/main/claude-accounts/service.ts
  • src/main/cli/wsl-cli-installer.ts
  • src/main/codex-accounts/runtime-home-service.ts
  • src/main/codex-accounts/runtime-home-wsl-session-bridge.test.ts
  • src/main/codex-accounts/service-wsl-accounts.test.ts
  • src/main/codex-accounts/service.ts
  • src/main/codex-accounts/wsl-codex-command.test.ts
  • src/main/codex-accounts/wsl-codex-command.ts
  • src/main/codex/codex-wsl-hook-install-plan.test.ts
  • src/main/codex/codex-wsl-hook-install-plan.ts
  • src/main/codex/wsl-codex-session-bridge.test.ts
  • src/main/codex/wsl-codex-session-bridge.ts
  • src/main/daemon/pty-subprocess-wsl-launch.test.ts
  • src/main/git/runner-command-exec.test.ts
  • src/main/git/runner-wsl-gh-fallback.test.ts
  • src/main/git/runner.ts
  • src/main/git/wsl-git-read-environment.ts
  • src/main/hooks.test.ts
  • src/main/hooks.ts
  • src/main/ipc/filesystem-watcher-wsl.test.ts
  • src/main/ipc/filesystem-watcher-wsl.ts
  • src/main/ipc/preflight-agent-detection.test.ts
  • src/main/ipc/preflight-host-cli-status.test.ts
  • src/main/ipc/preflight-wsl-agent-detection.test.ts
  • src/main/ipc/preflight-wsl-agent-detection.ts
  • src/main/ipc/preflight-wsl-command.ts
  • src/main/local-worktree-filesystem.ts
  • src/main/providers/local-pty-provider-windows-shell-launch.test.ts
  • src/main/providers/windows-shell-args.test.ts
  • src/main/providers/windows-shell-args.ts
  • src/main/rate-limits/claude-pty.ts
  • src/main/rate-limits/codex-fetcher.test.ts
  • src/main/rate-limits/codex-fetcher.ts
  • src/main/skills/claude-plugin-skill-sources-wsl.ts
  • src/main/skills/skill-discovery-wsl.ts
  • src/main/skills/skill-wsl-provider-detection.ts
  • src/main/text-generation/commit-message-text-generation-local-subprocess.test.ts
  • src/main/text-generation/commit-message-text-generation-model-discovery.test.ts
  • src/main/wsl.test.ts
  • src/main/wsl.ts
  • src/shared/posix-command-path-lookup.test.ts
  • src/shared/wsl-exec-mode-separator.test.ts
  • src/shared/wsl-login-shell-command.test.ts
  • src/shared/wsl-login-shell-command.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 9 remain after this review.

Comment on lines +158 to +166
it('keeps Linux-side shell variable expansion intact for the guest shell', () => {
const shellCommand = buildWslCodexSessionBridgeShellCommand({
systemSessionsRoot: '/home/alice/.codex/sessions',
managedSessionsRoot: '/home/alice/.local/share/orca/codex-runtime-home/home/sessions'
})

expect(shellCommand).toContain('\\$source_sessions_root')
expect(shellCommand).toContain('\\$source_file')
expect(shellCommand).toContain('\\$((scanned_files + 1))')
expect(shellCommand).toContain('$source_sessions_root')
expect(shellCommand).toContain('$source_file')
expect(shellCommand).toContain('$((scanned_files + 1))')

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Distinguish unescaped variables from escaped variables.

toContain('$source_sessions_root') also matches '\$source_sessions_root'. The same issue applies to $source_file and $((scanned_files + 1)). The test can pass after Windows-specific escaping is reintroduced. Assert exact unescaped fragments or assert that the backslash-prefixed forms are absent.

An audit of every wsl.exe invocation found sites the first pass missed,
including two it actively broke:

- config/scripts/wsl-git-shell-benchmark.mjs imported
  escapeWslShCommandForWindows, which no longer exists, so the script
  threw on startup. Its wslShellArgs helper also still used `--`; the
  file already had an --exec helper, so route both call sites there.
- classifySubprocessCommand unwrapped `wsl.exe <...> -- <binary>` by
  breaking on `--` alone. With every Orca spawn now on --exec it never
  found the guest binary and bucketed all WSL subprocesses as plain
  "wsl", losing the git/gh/glab breakdown. Break on either separator,
  since foreign wsl.exe processes still use `--`.

CliSkillRuntimeSetup builds its setup command as a template literal
rather than an argv array, so no array-shaped search could see it. Its
decoder accepts both separators so commands persisted before this
change still decode.

The guard now scans config/ and tests/ as well as src/, and checks the
command-string spelling alongside the argv one — the two shapes that
have each shipped a regression. It skips comment lines so prose about
the old form stays allowed, and asserts it scanned a plausible file
count so a bad root cannot make it vacuous.
The guard matched line by line, so `'--',\s*'bash'` could not span a
newline -- and every argv array in this repo is formatted one element
per line, which is exactly the shape it exists to catch. Measured
against the pre-migration tree it caught 17 files before and 9 fewer
after. It now strips comment lines and matches the rejoined text, with
a case that pins the multi-line shape so this cannot silently return.

The program list is wider than shells now, which surfaced a false
positive: tmux takes a `--` separator followed by a program too
(`split-window ... -- cat`). Matching is scoped to files that mention
WSL rather than narrowing the list back.

Also:
- Replaced the `sed` regression case, which was vacuous. A backreference
  contains no `$`, so it returned `bac` under both separators and would
  have passed without the fix. The block claimed every case proved the
  bug. Swapped in a positional argument and a shell local, both measured
  to differ -- the positional is the shape `wslUncDirectoryExists` uses,
  where `--` blanked `$1` so every existing directory probed as missing.
- windows-shell-args.test.ts derived its expected argv from
  buildWslExecArgs, the helper under test, so six assertions would still
  pass if it regressed to `--`. Spelled the expectation out.
- Dropped two comments citing the removed `--` behavior as rationale.

@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 (1)
src/shared/wsl-login-shell-command.test.ts (1)

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

Reduce the fixture comments.

Keep the test rationale concise. Replace the multi-line historical notes with one short comment for the affected fixture.

Proposed change
-  // so these scripts reached the shell already rewritten. Each case below was
-  // measured to return DIFFERENT bytes under `--` than under `--exec`; cases
-  // that merely look risky but are unaffected (a sed backreference has no `$`)
-  // are deliberately not here, because they would pass either way.
+  // Verify payloads that `--` rewrites but `--exec` preserves.
...
-    // The shape wslUncDirectoryExists uses: `--` blanked $1, so every existing
-    // directory probed as missing.
+    // `$1` previously caused WSL UNC directory checks to report missing paths.

As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line”.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1a1bde3f-73e1-4498-afa0-593ab5e81424

📥 Commits

Reviewing files that changed from the base of the PR and between b2e993f and 2a2ce1b.

📒 Files selected for processing (5)
  • src/main/codex-accounts/runtime-home-service.ts
  • src/main/providers/windows-shell-args.test.ts
  • src/main/wsl-bash-command.ts
  • src/shared/wsl-exec-mode-separator.test.ts
  • src/shared/wsl-login-shell-command.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/providers/windows-shell-args.test.ts
  • src/main/codex-accounts/runtime-home-service.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 8 remain after this review.

Comment on lines +18 to +19
const ARGV_FORM = new RegExp(String.raw`'--',\s*'${GUEST_PROGRAM}'`)
const STRING_FORM = new RegExp(String.raw`wsl(?:\.exe)?\b[^\n]*?[^-]--\s+${GUEST_PROGRAM}\b`)

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.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Bind separator matches to the WSL invocation.

STRING_FORM searches from wsl.exe to the end of the line. It can match a nested separator after a valid --exec invocation. For example, wsl.exe --exec bash -c "git diff -- cat" matches -- cat and is reported as legacy.

ARGV_FORM has the same problem. The file-level /wsl/i check does not prove that ['--', 'cat'] belongs to the WSL argv.

Parse the WSL argv or constrain the match to the actual WSL separator. Add a negative regression for nested separators.

🧪 Add regression coverage
+  it('ignores nested separators in a valid --exec command', () => {
+    const valid = 'wsl.exe --exec bash -c "git diff -- cat"'
+    expect(STRING_FORM.test(valid)).toBe(false)
+  })

Also applies to: 75-80, 85-91

🧰 Tools
🪛 ast-grep (0.45.1)

[warning] 18-18: Do not use variable for regular expressions
Context: new RegExp(String.rawwsl(?:\.exe)?\b[^\n]*?[^-]--\s+${GUEST_PROGRAM}\b)
Note: [CWE-1333] Inefficient Regular Expression Complexity. Security best practice.

(regexp-non-literal-typescript)

@OrcaWin
OrcaWin merged commit 6e8da1d into main Aug 18, 2026
54 checks passed
@OrcaWin
OrcaWin deleted the OrcaWin/wsl-exec-verbatim-argv branch August 18, 2026 09:12
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 21, 2026
* fix(wsl): pass guest argv verbatim through --exec

`wsl.exe <...> -- <argv>` expands `$name` in every argument against the
guest environment before the guest ever runs. It does this even when no
shell is involved, so `-- /usr/bin/printf %s '$HOME'` prints /home/you.

Every WSL invocation went through that preprocessor, so scripts arrived
already rewritten: `awk '{print $2}'` lost its field reference, and a
POSIX script asking for the literal `$HOME` got the expanded path.

`escapeWslShCommandForWindows` tried to compensate by escaping `$`, but
it skipped any `$` preceded by a backslash, so a script containing `\$`
was still corrupted -- and half the call sites never applied it at all.

Route every invocation through `--exec`, which passes argv through
untouched, and delete the escaper. The direct-git path already used
`--exec`, so this is not a new compatibility dependency.

A guard test fails if the `--` form reappears anywhere in the tree.

Net -50 lines of production code.

* test(wsl): drop remaining escaped-dollar assertions

* fix(wsl): cover the --exec migration's blind spots

An audit of every wsl.exe invocation found sites the first pass missed,
including two it actively broke:

- config/scripts/wsl-git-shell-benchmark.mjs imported
  escapeWslShCommandForWindows, which no longer exists, so the script
  threw on startup. Its wslShellArgs helper also still used `--`; the
  file already had an --exec helper, so route both call sites there.
- classifySubprocessCommand unwrapped `wsl.exe <...> -- <binary>` by
  breaking on `--` alone. With every Orca spawn now on --exec it never
  found the guest binary and bucketed all WSL subprocesses as plain
  "wsl", losing the git/gh/glab breakdown. Break on either separator,
  since foreign wsl.exe processes still use `--`.

CliSkillRuntimeSetup builds its setup command as a template literal
rather than an argv array, so no array-shaped search could see it. Its
decoder accepts both separators so commands persisted before this
change still decode.

The guard now scans config/ and tests/ as well as src/, and checks the
command-string spelling alongside the argv one — the two shapes that
have each shipped a regression. It skips comment lines so prose about
the old form stays allowed, and asserts it scanned a plausible file
count so a bad root cannot make it vacuous.

* fix(wsl): restore the guard's multi-line sensitivity

The guard matched line by line, so `'--',\s*'bash'` could not span a
newline -- and every argv array in this repo is formatted one element
per line, which is exactly the shape it exists to catch. Measured
against the pre-migration tree it caught 17 files before and 9 fewer
after. It now strips comment lines and matches the rejoined text, with
a case that pins the multi-line shape so this cannot silently return.

The program list is wider than shells now, which surfaced a false
positive: tmux takes a `--` separator followed by a program too
(`split-window ... -- cat`). Matching is scoped to files that mention
WSL rather than narrowing the list back.

Also:
- Replaced the `sed` regression case, which was vacuous. A backreference
  contains no `$`, so it returned `bac` under both separators and would
  have passed without the fix. The block claimed every case proved the
  bug. Swapped in a positional argument and a shell local, both measured
  to differ -- the positional is the shape `wslUncDirectoryExists` uses,
  where `--` blanked `$1` so every existing directory probed as missing.
- windows-shell-args.test.ts derived its expected argv from
  buildWslExecArgs, the helper under test, so six assertions would still
  pass if it regressed to `--`. Spelled the expectation out.
- Dropped two comments citing the removed `--` behavior as rationale.

---------

Co-authored-by: OrcaWin <[email protected]>
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
* fix(wsl): pass guest argv verbatim through --exec

`wsl.exe <...> -- <argv>` expands `$name` in every argument against the
guest environment before the guest ever runs. It does this even when no
shell is involved, so `-- /usr/bin/printf %s '$HOME'` prints /home/you.

Every WSL invocation went through that preprocessor, so scripts arrived
already rewritten: `awk '{print $2}'` lost its field reference, and a
POSIX script asking for the literal `$HOME` got the expanded path.

`escapeWslShCommandForWindows` tried to compensate by escaping `$`, but
it skipped any `$` preceded by a backslash, so a script containing `\$`
was still corrupted -- and half the call sites never applied it at all.

Route every invocation through `--exec`, which passes argv through
untouched, and delete the escaper. The direct-git path already used
`--exec`, so this is not a new compatibility dependency.

A guard test fails if the `--` form reappears anywhere in the tree.

Net -50 lines of production code.

* test(wsl): drop remaining escaped-dollar assertions

* fix(wsl): cover the --exec migration's blind spots

An audit of every wsl.exe invocation found sites the first pass missed,
including two it actively broke:

- config/scripts/wsl-git-shell-benchmark.mjs imported
  escapeWslShCommandForWindows, which no longer exists, so the script
  threw on startup. Its wslShellArgs helper also still used `--`; the
  file already had an --exec helper, so route both call sites there.
- classifySubprocessCommand unwrapped `wsl.exe <...> -- <binary>` by
  breaking on `--` alone. With every Orca spawn now on --exec it never
  found the guest binary and bucketed all WSL subprocesses as plain
  "wsl", losing the git/gh/glab breakdown. Break on either separator,
  since foreign wsl.exe processes still use `--`.

CliSkillRuntimeSetup builds its setup command as a template literal
rather than an argv array, so no array-shaped search could see it. Its
decoder accepts both separators so commands persisted before this
change still decode.

The guard now scans config/ and tests/ as well as src/, and checks the
command-string spelling alongside the argv one — the two shapes that
have each shipped a regression. It skips comment lines so prose about
the old form stays allowed, and asserts it scanned a plausible file
count so a bad root cannot make it vacuous.

* fix(wsl): restore the guard's multi-line sensitivity

The guard matched line by line, so `'--',\s*'bash'` could not span a
newline -- and every argv array in this repo is formatted one element
per line, which is exactly the shape it exists to catch. Measured
against the pre-migration tree it caught 17 files before and 9 fewer
after. It now strips comment lines and matches the rejoined text, with
a case that pins the multi-line shape so this cannot silently return.

The program list is wider than shells now, which surfaced a false
positive: tmux takes a `--` separator followed by a program too
(`split-window ... -- cat`). Matching is scoped to files that mention
WSL rather than narrowing the list back.

Also:
- Replaced the `sed` regression case, which was vacuous. A backreference
  contains no `$`, so it returned `bac` under both separators and would
  have passed without the fix. The block claimed every case proved the
  bug. Swapped in a positional argument and a shell local, both measured
  to differ -- the positional is the shape `wslUncDirectoryExists` uses,
  where `--` blanked `$1` so every existing directory probed as missing.
- windows-shell-args.test.ts derived its expected argv from
  buildWslExecArgs, the helper under test, so six assertions would still
  pass if it regressed to `--`. Spelled the expectation out.
- Dropped two comments citing the removed `--` behavior as rationale.

---------

Co-authored-by: OrcaWin <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(wsl): pass guest argv verbatim through --exec

`wsl.exe <...> -- <argv>` expands `$name` in every argument against the
guest environment before the guest ever runs. It does this even when no
shell is involved, so `-- /usr/bin/printf %s '$HOME'` prints /home/you.

Every WSL invocation went through that preprocessor, so scripts arrived
already rewritten: `awk '{print $2}'` lost its field reference, and a
POSIX script asking for the literal `$HOME` got the expanded path.

`escapeWslShCommandForWindows` tried to compensate by escaping `$`, but
it skipped any `$` preceded by a backslash, so a script containing `\$`
was still corrupted -- and half the call sites never applied it at all.

Route every invocation through `--exec`, which passes argv through
untouched, and delete the escaper. The direct-git path already used
`--exec`, so this is not a new compatibility dependency.

A guard test fails if the `--` form reappears anywhere in the tree.

Net -50 lines of production code.

* test(wsl): drop remaining escaped-dollar assertions

* fix(wsl): cover the --exec migration's blind spots

An audit of every wsl.exe invocation found sites the first pass missed,
including two it actively broke:

- config/scripts/wsl-git-shell-benchmark.mjs imported
  escapeWslShCommandForWindows, which no longer exists, so the script
  threw on startup. Its wslShellArgs helper also still used `--`; the
  file already had an --exec helper, so route both call sites there.
- classifySubprocessCommand unwrapped `wsl.exe <...> -- <binary>` by
  breaking on `--` alone. With every Orca spawn now on --exec it never
  found the guest binary and bucketed all WSL subprocesses as plain
  "wsl", losing the git/gh/glab breakdown. Break on either separator,
  since foreign wsl.exe processes still use `--`.

CliSkillRuntimeSetup builds its setup command as a template literal
rather than an argv array, so no array-shaped search could see it. Its
decoder accepts both separators so commands persisted before this
change still decode.

The guard now scans config/ and tests/ as well as src/, and checks the
command-string spelling alongside the argv one — the two shapes that
have each shipped a regression. It skips comment lines so prose about
the old form stays allowed, and asserts it scanned a plausible file
count so a bad root cannot make it vacuous.

* fix(wsl): restore the guard's multi-line sensitivity

The guard matched line by line, so `'--',\s*'bash'` could not span a
newline -- and every argv array in this repo is formatted one element
per line, which is exactly the shape it exists to catch. Measured
against the pre-migration tree it caught 17 files before and 9 fewer
after. It now strips comment lines and matches the rejoined text, with
a case that pins the multi-line shape so this cannot silently return.

The program list is wider than shells now, which surfaced a false
positive: tmux takes a `--` separator followed by a program too
(`split-window ... -- cat`). Matching is scoped to files that mention
WSL rather than narrowing the list back.

Also:
- Replaced the `sed` regression case, which was vacuous. A backreference
  contains no `$`, so it returned `bac` under both separators and would
  have passed without the fix. The block claimed every case proved the
  bug. Swapped in a positional argument and a shell local, both measured
  to differ -- the positional is the shape `wslUncDirectoryExists` uses,
  where `--` blanked `$1` so every existing directory probed as missing.
- windows-shell-args.test.ts derived its expected argv from
  buildWslExecArgs, the helper under test, so six assertions would still
  pass if it regressed to `--`. Spelled the expectation out.
- Dropped two comments citing the removed `--` behavior as rationale.

---------

Co-authored-by: OrcaWin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant