orca icon indicating copy to clipboard operation
orca copied to clipboard

fix(worktrees): respect Windows shell for setup runners

Open rodboev opened this issue 5 months ago β€’ 9 comments

Summary

  • Makes Windows worktree setup runners follow the configured Orca terminal shell instead of forcing cmd.exe semantics for every native Windows worktree.
  • Preserves that shell selection through deferred setup launch paths, including wait-for-setup sequencing and automation background setup tabs or splits.
  • Keeps existing cmd.exe batch fail-fast behavior for cmd users, while allowing Git Bash, WSL, or PowerShell setup scripts to run with matching runner content and launch commands.

Closes #6896.

Testing

  • [ ] pnpm lint
  • [x] pnpm typecheck
  • [ ] pnpm test
  • [ ] pnpm build
  • [x] Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Focused validation:

  • pnpm exec vitest run --config config/vitest.config.ts src/main/hooks.test.ts src/shared/setup-runner-command.test.ts src/shared/setup-agent-sequencing.test.ts src/main/ipc/worktrees.test.ts src/main/ipc/worktrees-windows.test.ts src/main/runtime/orca-runtime.test.ts src/renderer/src/lib/worktree-activation.test.ts src/renderer/src/lib/launch-worktree-background-terminals.test.ts - passed (815 tests, 4 skipped).
  • pnpm run typecheck:node - passed.
  • pnpm run typecheck:web - passed.
  • pnpm exec oxlint src/main/hooks.test.ts src/main/hooks.ts src/main/ipc/worktree-remote.ts src/main/ipc/worktrees-windows.test.ts src/main/ipc/worktrees.test.ts src/main/runtime/orca-runtime.test.ts src/main/runtime/orca-runtime.ts src/renderer/src/lib/launch-worktree-background-terminals.test.ts src/renderer/src/lib/launch-worktree-background-terminals.ts src/renderer/src/lib/setup-runner.ts src/renderer/src/lib/worktree-activation.test.ts src/renderer/src/lib/worktree-activation.ts src/shared/setup-agent-sequencing.test.ts src/shared/setup-agent-sequencing.ts src/shared/setup-runner-command.test.ts src/shared/setup-runner-command.ts src/shared/types.ts - passed.
  • pnpm exec oxfmt --check src/main/hooks.test.ts src/main/hooks.ts src/main/ipc/worktree-remote.ts src/main/ipc/worktrees-windows.test.ts src/main/ipc/worktrees.test.ts src/main/runtime/orca-runtime.test.ts src/main/runtime/orca-runtime.ts src/renderer/src/lib/launch-worktree-background-terminals.test.ts src/renderer/src/lib/launch-worktree-background-terminals.ts src/renderer/src/lib/setup-runner.ts src/renderer/src/lib/worktree-activation.test.ts src/renderer/src/lib/worktree-activation.ts src/shared/setup-agent-sequencing.test.ts src/shared/setup-agent-sequencing.ts src/shared/setup-runner-command.test.ts src/shared/setup-runner-command.ts src/shared/types.ts - passed.
  • git diff --check - passed.

AI Review Report

Reviewed the final diff for Windows cmd, PowerShell, Git Bash, and WSL setup behavior across local worktree creation, SSH worktree setup, wait-for-setup sequencing, runtime-spawned and renderer-spawned setup terminals, path quoting, and automation background setup launches. The change is scoped to setup runner generation plus setup runner launch command routing.

Security Audit

Setup still runs only through the existing user-approved setup flow. The change adds explicit shell metadata, selects .cmd, .ps1, or .sh runner content from that metadata, and reuses the existing setup terminal launch path. No new background execution path is added.

Notes

Scope is limited to worktree setup runner generation and launch semantics on Windows. Ordinary terminal spawning, archive hooks, notification behavior, and unrelated git provider behavior are unchanged.


Open in Stage

rodboev avatar Jul 01 '26 00:07 rodboev

Ready to review this PR? Stage has broken it down into 6 individual chapters for you:

Title
1 Define shell metadata types and command resolution
2 Implement shell-aware setup runner generation
3 Update setup-agent sequencing for custom shells
4 Wire shell selection through IPC handlers
5 Integrate shell selection into Orca runtime
6 Update renderer to respect setup shell metadata
Open in Stage

Chapters generated by Stage for commit 5b717f120810601d96eb0739feda8ebe7270346e on Jul 1, 2026 1:07am UTC.

ghost avatar Jul 01 '26 00:07 ghost

Review Change Stack

No actionable comments were generated in the recent review. πŸŽ‰

ℹ️ Recent review info
βš™οΈ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fc05e961-e086-445b-b6d1-167a2746b7fa

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 5ff89e5da2b774a24705f07042675ba95c39b770 and 8e6448649e96eafe8fb9d67a0afaecbf7a556ecc.

πŸ“’ Files selected for processing (4)
  • src/main/ipc/parcel-watcher-in-process-fallback.ts
  • src/main/plugins/plugin-content-safety.test.ts
  • src/main/plugins/plugin-dev-watcher.test.ts
  • src/main/plugins/plugin-dev-watcher.ts

πŸ“ Walkthrough

Walkthrough

This PR adds SetupRunnerShell support for POSIX, cmd, and PowerShell setup runners. Main hooks generate shell-specific scripts and resolve shell metadata from terminal settings. IPC, runtime, shared sequencing, and renderer paths propagate this metadata through setup generation and command execution. Tests cover Windows paths, WSL, PowerShell, cmd, shell resolution, and setup sequencing.

πŸš₯ Pre-merge checks | βœ… 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR also changes Parcel watcher teardown and plugin watcher subscription cleanup, which are unrelated to Windows worktree setup runners. Remove these watcher changes or move them to a separate pull request focused on watcher cleanup.
Docstring Coverage ⚠️ Warning Docstring coverage is 3.03% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
βœ… Passed checks (3 passed)
Check name Status Explanation
Title check βœ… Passed The title clearly identifies the primary change: Windows setup runners now respect the configured shell.
Description check βœ… Passed The description includes Summary, Testing, AI Review Report, Security Audit, and Notes, but omits Screenshots and leaves several standard checks unchecked.
Linked Issues check βœ… Passed The implementation threads shell metadata through runner generation and launch, covering Git Bash and WSL behavior and the cmd.exe /c path-conversion failure in #6896.

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[bot] avatar Jul 01 '26 01:07 coderabbitai[bot]

Addressed the CodeRabbit pass in 5b717f120: deferred setup now preserves an explicit Git Bash bash.exe path, the renderer suite now covers the shell-aware issue-command path, and I added short why-comments around the Windows POSIX path translations and deferred background setup shell handoff.

rodboev avatar Jul 01 '26 01:07 rodboev

Taking a look!

OrcaWin avatar Jul 20 '26 19:07 OrcaWin

πŸ‘‹ Did a deep Opus review of this on Windows (native + WSL + SSH paths) after rebasing onto current main. The core fix is solid β€” it correctly threads a SetupRunnerShell through every create/launch site so the runner's extension, content, and invocation all agree with the configured Windows shell (Git Bash / WSL / PowerShell / cmd), fixing the forced-cmd.exe bug in #6896. Repro confirmed pre-fix and resolved post-fix; no regressions on macOS/Linux (resolver returns undefined off-win32, chmod still applied). All targeted suites green (hooks, worktrees, worktrees-windows, setup-runner-command, setup-agent-sequencing, worktree-activation, launch-worktree-background-terminals, runtime setup tests).

I pushed 3 small hardening fixes on our rebased branch OrcaWin/pr-6967-rebase (commit a083b8fd1, intended for a superseding PR since the original cross-repo branch is CONFLICTING):

  1. Remote pwsh binary no longer chosen from the local host. For SSH/remote Windows worktrees, resolveSetupRunnerShell was calling isPwshAvailable() β€” a local-only probe β€” so an auto PowerShell implementation could route the remote runner to a pwsh.exe the remote doesn't have (e.g. mac/local-with-pwsh β†’ Windows-remote-without). Added resolveSetupRunnerShell(..., { probeLocalPwsh: false }) at the remote call site so remote auto keeps the always-present powershell.exe; an explicit pwsh.exe choice is still honored.

  2. PowerShell runner preserves native exit codes. Reordered the per-line guards to check $LASTEXITCODE before $?, so a failing native command surfaces its real exit code instead of a generic exit 1. $? still catches cmdlet soft-failures (-ErrorAction SilentlyContinue) that leave $LASTEXITCODE at 0.

  3. PowerShell runner written with a UTF-8 BOM. Since the default powershell.exe (Windows PowerShell 5.1) decodes BOM-less files as ANSI, non-ASCII in a setup script could be mangled. A BOM makes both 5.1 and pwsh 7 read it as UTF-8. cmd/.sh runners are untouched.

Added unit tests locking the remote-probe behavior.

Heads-up worth a release note (not a code bug): for unconfigured Windows users this PR shifts the setup runner default from cmd β†’ PowerShell to match Orca's default terminal (terminalWindowsShell: powershell.exe). Setup scripts that rely on cmd/batch syntax (set X=Y, %VAR%, if errorlevel) would need updating on upgrade.

Residual risk: if a user configures Git Bash locally and creates a remote Windows worktree, the runner is emitted as bash … and depends on Git Bash being present on the remote (inherent to honoring the configured shell without a remote capability probe). Low-impact and out of scope for #6896. Not merging β€” flagging for the superseding PR.

OrcaWin avatar Jul 21 '26 18:07 OrcaWin

Thanks @rodboev β€” the root-cause analysis and the Git Bash routing here were exactly right. We've pushed five maintainer commits on top of your branch (no history rewrite) that narrow the scope so only the broken configurations change behavior:

  • Git Bash fix kept as you built it: .sh runner + bash /c/... launch.
  • PowerShell/default users stay on the existing .cmd runner β€” existing Windows setup scripts were authored for cmd, and cmd.exe /c launches fine from PowerShell, so moving the default cohort to .ps1 would have silently changed the semantics of working setups.
  • SSH remotes keep remote-owned shell selection β€” terminalWindowsShell (and the local pwsh probe) describe the local host, so they no longer pick the runner format or launch executable for remote hosts.
  • WSL setup launches route from the project runtime and use plain bash /mnt/... β€” the wsl.exe -- re-entry ran in the default distro and dropped env vars at the interop boundary.
  • Removed the unused Git Bash executable capture (the launch builder never read it).

Verified on the combined head: the focused vitest suite (814 tests) and node/web typecheck are green.

Known follow-ups, deliberately out of scope: the git-bash-configured-but-not-installed case (the terminal falls back to PowerShell while the runner would go posix), and the issue-command runner, which still launches via cmd.exe /c under Git Bash.

brennanb2025 avatar Jul 21 '26 21:07 brennanb2025

@OrcaWin thanks for the deep Windows pass β€” good catches. Status update so we don't fork efforts: we've kept this PR as the canonical branch (no superseding PR needed; maintainerCanModify let us push directly) and it's now conflict-free with main (merged, MERGEABLE).

On your three hardening fixes from OrcaWin/pr-6967-rebase:

  1. Local pwsh probe leaking into remote runner selection β€” same issue we found. Our fix goes further: SSH/remote worktrees no longer consume the local terminalWindowsShell at all and keep remote-owned .cmd/.sh selection, so there's no remote pwsh routing left to guard.
  2. PowerShell runner exit codes and 3. UTF-8 BOM — both moot on the current head: we removed the .ps1 runner family entirely. Default/PowerShell users stay on the existing .cmd runner (cmd.exe /c launches fine from PowerShell), which also resolves the cmd→PowerShell upgrade-compat concern from your release-note heads-up.

Your residual-risk note (Git Bash config + remote Windows worktree) is also resolved by the remote-owned selection β€” local shell preferences never reach remote hosts now. No need to carry OrcaWin/pr-6967-rebase forward; feel free to delete that branch.

brennanb2025 avatar Jul 21 '26 21:07 brennanb2025

Hey β€” hope this is helpful! We rebased this branch onto the latest main and pushed our review fixes here to try to help it land. CI (typecheck for node + web, oxlint, and the Windows worktree setup-shell tests) is passing now. Thanks so much for the original work on this β€” happy to adjust anything if you'd prefer a different approach. πŸ™

OrcaWin avatar Jul 21 '26 21:07 OrcaWin

My bad, force-pushed and overwrote the five maintainer commits I'd pushed to this branch 20 minutes earlier (see the two comments above). Restored them in 79c0229b0 on top of your rebase β€” nothing of yours was rewritten, and your rebase onto latest main was kept.

State of the branch now:

  • Scope is narrowed again: only POSIX-family shells (Git Bash) change behavior; PowerShell/cmd/default users keep the existing .cmd runner, and SSH remotes keep remote-owned selection.
  • Your probeLocalPwsh guard is superseded: the SSH path no longer calls resolveSetupRunnerShell at all, so there is no remote pwsh routing left to guard (the option and its tests were removed with it).
  • Your .ps1 BOM and exit-code hardening were dropped as moot β€” the .ps1 runner family no longer exists on this branch.

Verified on the pushed head: focused vitest suite (1123 tests) and node/web typecheck green.

brennanb2025 avatar Jul 21 '26 22:07 brennanb2025

Rebased this onto the latest main and pushed the review fixes here to help get it landed. The only conflicts were in src/shared/types.ts (import ordering) and src/main/runtime/orca-runtime.ts, where main's new setup-completion observer landed in the same spots as the setup-shell platform resolution β€” both sides are kept: the observed setup command still runs, and the shell hint now flows into buildSetupRunnerCommand. Locally green on typecheck, oxlint, and the covering suites (1239 tests). Thanks so much for the contribution!

OrcaWin avatar Jul 28 '26 03:07 OrcaWin

Quick follow-up: CI flagged two changed-code gates (a param-count limit on the runner helper and a hooks-runner test expectation for the new shell field), which I've addressed in the latest commit β€” all 22 checks are green now.

OrcaWin avatar Jul 28 '26 04:07 OrcaWin

Greptile Summary

This PR fixes Windows worktree setup runners to respect the user's configured terminal shell (Git Bash, WSL, PowerShell) instead of always writing cmd.exe-format runners. The shell metadata is now threaded through the WorktreeSetupLaunch type and propagated across all launch paths β€” wait-for-setup sequencing, background setup tabs, and automation splits β€” so the runner script format, env var path encoding, and launch command all stay consistent end-to-end.

  • Adds SetupRunnerShell metadata to WorktreeSetupLaunch; resolveSetupRunnerShell in hooks.ts reads the user's terminalWindowsShell setting and selects { family: 'posix' } (Git Bash) or { family: 'cmd' } (PowerShell, WSL-as-terminal, cmd); this shell hint is carried through all launch paths.
  • resolveSetupRunnerCommand now routes between /c/… (Git Bash), /mnt/… (WSL), or cmd.exe /c based on SetupRunnerShell, and adds a PowerShell-wrapped delayed-expansion launcher (buildWindowsCmdRunnerDelayedLaunchCommand) for cmd-family paths containing shell metacharacters that cannot survive standard quoting.
  • buildWindowsRunnerScript adds DisableDelayedExpansion to prevent ! being consumed by any inherited delayed-expansion state when setup content is run under the new cmd /v:on launcher.

Confidence Score: 5/5

Safe to merge β€” shell selection, path conversion, and env var encoding are all correctly threaded end-to-end and covered by the expanded test suite.

The change is well-scoped: SetupRunnerShell metadata flows from settings resolution through runner creation, sequencing, background launch, and completion signaling without any gaps. Path conversion helpers (/c/… for Git Bash, /mnt/… for WSL, delayed-expansion wrapper for metacharacter paths) are correct. The DisableDelayedExpansion fix in buildWindowsRunnerScript is a genuine correctness improvement for cmd users under the new launcher. No execution path leaves the shell hint unthreaded.

Files Needing Attention: No files require special attention β€” the logic across all 33 changed files is consistent and well-commented.

Important Files Changed

Filename Overview
src/shared/setup-runner-command.ts Core routing logic for setup runner commands; adds shell-aware path conversion (Git Bash /c/… vs WSL /mnt/… vs cmd.exe), with correct guard ordering (WSL UNC, Linux path, posix shell, fallback cmd).
src/main/hooks.ts Adds resolveSetupRunnerShell reading terminalWindowsShell settings, threads SetupRunnerShell through createWorktreeRunnerScript, converts POSIX env var paths for Git Bash, and fixes DisableDelayedExpansion in cmd runner header.
src/shared/windows-cmd-runner-delayed-launch.ts New file: PowerShell-wrapped delayed-expansion launcher for cmd-family paths containing metacharacters that survive no amount of quoting; well-reasoned guard pattern and script.
src/shared/types.ts Adds optional shell field to WorktreeSetupLaunch; correctly typed and backward-compatible.
src/main/ipc/worktree-remote.ts Threads setup.shell through sequenced setup and background setup launch paths consistently.
src/main/runtime/orca-runtime.ts Threads setup.shell through all setup launch paths; fixes setupCommandPlatform derivation; adds didStartInProcessSetupHook to avoid reporting spawn_failed when the in-process hook is already running.
src/renderer/src/lib/worktree-activation.ts Passes setup.shell through to buildSetupRunnerCommand and createSequencedSetupAgentCommands in the renderer activation path.
src/preload/index.ts Broadens IPC type annotations from inline object literals to WorktreeSetupLaunch so the new shell field is included in renderer-visible payloads.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[createLocalWorktree / runHook] --> B[resolveSetupRunnerShell\nsettings.terminalWindowsShell]
    B --> C{Platform}
    C -- non-win32 --> D[return undefined]
    C -- win32 --> E{Shell family}
    E -- wsl.exe terminal --> F[family: cmd]
    E -- PowerShell terminal --> F
    E -- bash.exe / bash\nGit for Windows --> G{resolveWindowsGitBashShellPath}
    G -- found --> H[family: posix]
    G -- not found --> F
    H --> I[createWorktreeRunnerScript]
    F --> I
    D --> I
    I --> J{nativeWindowsWorktree?}
    J -- yes --> K[runnerShell = setupShell ?? cmd\nExtension .cmd or .sh]
    J -- no WSL distro --> L[runnerShell = posix\nlaunchShell = posix + wsl.exe]
    J -- posix host --> M[runnerShell = posix]
    K --> N[Write runner + convert env paths]
    L --> N
    M --> N
    N --> O[WorktreeSetupLaunch\nrunnerScriptPath + shell]
    O --> P[resolveSetupRunnerCommand]
    P --> Q{Windows platform?}
    Q -- WSL UNC path --> R[bash /linux/path]
    Q -- Linux / path --> R
    Q -- shell.family=posix no WSL --> S[bash '/c/...' Git Bash]
    Q -- shell.family=posix wsl.exe --> T[bash '/mnt/...' WSL]
    Q -- shell.family=cmd safe path --> U[cmd.exe /c path]
    Q -- shell.family=cmd metachar --> V[powershell delayed expansion]
    Q -- posix platform --> R

Reviews (5): Last reviewed commit: "fix(plugins): keep in-process unsubscrib..." | Re-trigger Greptile

greptile-apps avatar Jul 31 '26 04:07 greptile-apps

PR ready. pending windows verification

AmethystLiang avatar Aug 02 '26 03:08 AmethystLiang

@coderabbitai[bot] fixed

AmethystLiang avatar Aug 02 '26 18:08 AmethystLiang

[!TIP] For best results, initiate chat on the files or code changes.

@AmethystLiang: Acknowledged. Thank you for the fix.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

You are interacting with an AI system.

coderabbitai[bot] avatar Aug 02 '26 18:08 coderabbitai[bot]