Skip to content

fix(worktrees): respect Windows shell for setup runners - #6967

Merged
AmethystLiang merged 16 commits into
stablyai:mainfrom
rodboev:pr/windows-worktree-setup-shell
Aug 3, 2026
Merged

AmethystLiang merged 16 commits into
stablyai:mainfrom
rodboev:pr/windows-worktree-setup-shell

Conversation

@rodboev

@rodboev rodboev commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

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
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • 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

ELI5

Windows worktree setup always forced cmd.exe-style runners. Setup now follows your configured shell (PowerShell, Git Bash, WSL) so scripts match the terminal.

@ghost

ghost commented Jul 1, 2026 •

Copy link
Copy Markdown

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.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

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 5ff89e5 and 8e64486.

📒 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 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 (3)
src/shared/setup-runner-command.ts (1)

59-83: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a short “why” comment for the Windows shell/path translation logic.

This branching is doing non-obvious behavior (/c/... vs /mnt/c/..., PowerShell vs cmd fallback), so a brief rationale here would make future edits much safer.

As per coding guidelines, **/*.{ts,tsx,js,jsx}: "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."

Also applies to: 121-144

Source: Coding guidelines

src/renderer/src/lib/launch-worktree-background-terminals.ts (1)

121-126: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document why background setup launches must reuse setup.shell.

The extra argument is easy to remove in a later cleanup unless this helper states that deferred/background setup tabs must preserve the shell chosen when the runner was generated.

As per coding guidelines, **/*.{ts,tsx,js,jsx}: "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."

Source: Coding guidelines

src/renderer/src/lib/worktree-activation.test.ts (1)

75-121: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add one shell-aware issueCommand case.

These additions cover setup launches well, but Line 723 in src/renderer/src/lib/worktree-activation.ts now forwards issueCommand.shell through buildSetupRunnerCommand(), and the suite still only exercises the shell-less issue-command path. A single PowerShell or WSL issue-command assertion would keep that new branch from regressing unnoticed.

Also applies to: 419-441, 596-624


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: fc5113fa-9220-4c39-9fa8-b692d0d63a89

📥 Commits

Reviewing files that changed from the base of the PR and between 764e2fe and aa8723db4b9fa2f38593bd30c33d8c5d29dde50a.

📒 Files selected for processing (17)
  • 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

Comment thread src/main/hooks.ts Resolved
@rodboev

rodboev commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

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.

@OrcaWin

OrcaWin commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Taking a look!

@OrcaWin

OrcaWin commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

👋 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.

@brennanb2025

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

@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.

@OrcaWin
OrcaWin force-pushed the pr/windows-worktree-setup-shell branch from 5dec683 to 14983af Compare July 21, 2026 21:39
@OrcaWin

OrcaWin commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

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. 🙏

@brennanb2025

brennanb2025 commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

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.

@nwparker nwparker added the bug Something isn't working label Jul 27, 2026
@OrcaWin
OrcaWin force-pushed the pr/windows-worktree-setup-shell branch from 79c0229 to fd3c5dc Compare July 28, 2026 03:47
@OrcaWin

OrcaWin commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

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

OrcaWin commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

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.

rodboev and others added 9 commits July 30, 2026 18:04
- Resolve remote PowerShell binary without local pwsh probe: for SSH/remote
  Windows worktrees, isPwshAvailable() reflects only the LOCAL host, so an
  'auto' implementation could route the remote runner to a pwsh.exe the remote
  lacks. Add resolveSetupRunnerShell(..., { probeLocalPwsh: false }) so remote
  auto keeps the always-present powershell.exe; explicit pwsh.exe still honored.
- Preserve native exit codes in the PowerShell runner by checking
  $LASTEXITCODE before $?, so a failing native command surfaces its real code
  instead of a generic exit 1; $? still catches cmdlet soft-failures.
- Write the PowerShell runner with a UTF-8 BOM so Windows PowerShell 5.1 (the
  new default powershell.exe) reads it as UTF-8 instead of ANSI, preventing
  non-ASCII setup-script corruption.
- Add unit tests for the remote-probe behavior.
The force-pushed rebase dropped five review-fix commits that were already
on this branch; this reapplies their combined effect on top of the new
base and the hardening commit:

- Keep SSH setup shell selection remote-owned (no local terminalWindowsShell
  or pwsh routing for remote hosts; supersedes the probeLocalPwsh guard)
- Preserve cmd setup compatibility outside POSIX shells (no .ps1 runner
  family, so the BOM/exit-code hardening is no longer applicable)
- Route WSL setup runners from the project runtime
- Avoid blocking PowerShell probes during setup creation
- Correct SSH and WSL background setup fixtures
- createWorktreeRunnerScript took 7 positional parameters, tripping the
  changed-code max-params gate; move it to a single options object.
- hooks-runner.test.ts deep-equals the createSetupRunnerScript result, so
  assert the cmd shell now returned for native Windows worktrees.
@AmethystLiang
AmethystLiang force-pushed the pr/windows-worktree-setup-shell branch from c8f27a2 to 8361080 Compare July 31, 2026 04:19
@greptile-apps

greptile-apps Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

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
Loading

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

Comment thread src/main/hooks.ts Resolved
@AmethystLiang

Copy link
Copy Markdown
Contributor

PR ready. pending windows verification

- buildObservedSetupCommand takes the runner's launch shell so WSL-routed
  Windows-drive setup replays use /mnt/c instead of Git Bash /c
- resolveSetupRunnerShell gates the posix runner on the same Git Bash
  resolution the PTY uses, so a missing or non-MSYS bash keeps the cmd runner
- issue-command runners carry their launch shell, and the renderer passes it
  when building the queued command
- treat a bare `bash` shell setting as POSIX like `bash.exe`

Co-authored-by: Orca <[email protected]>
@AmethystLiang

Copy link
Copy Markdown
Contributor

@coderabbitai[bot] fixed

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

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.

AmethystLiang and others added 6 commits August 2, 2026 16:08
Route windowless/headless creates through the shell-aware setup runner when a
PTY controller is available, existence-check explicit Git Bash paths before
committing to .sh runners, thread the resolved shell into issue-command
runners, and document the intentional Git Bash interpreter flip with a narrow
scope table.
C3: a Git Bash setup runner now receives ORCA_*/CONDUCTOR_*/GHOSTX_* path
values in /c/... form, matching the runner path and the shell's own HOME/PWD.
C5: extension-less `bash` resolves to Git Bash everywhere, matching how
resolveWindowsShellStartupFamily already classifies it.
C7: runner paths carrying characters that cannot be quoted on a cmd command
line launch through a delayed-expansion PowerShell shim instead, and the batch
runner disables inherited delayed expansion so `!` in setup lines survives.

Co-authored-by: Orca <[email protected]>
Keep the setup-shell release note aligned with C3 env conversion and C5 bare
bash resolution so the published claim matches runtime behavior.
Keep the counsel P1/P2 product fixes without expanding the docs allowlist
or AGENTS.md guidance surface.
Dev plugin watchers fire-and-forget unsubscribe, and in-process Parcel
can reject when temp watch roots are already deleted. Catch those
rejections so they cannot fail the suite as unhandled errors.
Swallowing Parcel unsubscribe errors broke mocked unsubscribe tests
that return non-Promises and expect rejections. Contain failures only
in PluginDevWatcher fire-and-forget paths.
@AmethystLiang
AmethystLiang merged commit 8c5371e into stablyai:main Aug 3, 2026
43 checks passed
OrcaWin added a commit that referenced this pull request Aug 4, 2026
…s to Git Bash (#12406)

* fix(worktrees): stop silently switching existing Windows setup scripts to Git Bash

#6967 derived the Windows setup-runner shell from `terminalWindowsShell`. On
upgrade, any Windows user whose terminal preference resolved to Git Bash had
their existing `orca.yaml` setup script (and issue command) handed to bash
instead of cmd.exe. Scripts authored against the cmd runner — `copy`, `xcopy`,
`set VAR=value`, `if errorlevel 1`, `%VAR%`, backslash paths — broke with no
migration and no warning, and the failure looked like Orca broke the project.

The conflation is also wrong in the steady state: a terminal preference is
per-user, so two people on the same repo got different interpreters for the
same orca.yaml and no project could write a setup script that worked for all
of its Windows contributors.

The interpreter is now a property of the script, declared the standard way:
a leading `#!` line. Native Windows keeps the historical `.cmd` runner unless
the script declares a POSIX shell, so no existing script changes behavior.
`resolveSetupRunnerShell` keeps its role as the feasibility gate — a bash
runner still requires the terminal to resolve to Git Bash, since the launch
command is typed into that shell and uses MSYS `/c/...` paths.

`buildWindowsRunnerScript` now drops a leading `#!` line rather than `call`ing
it, so a declared-bash script that falls back to cmd (Git Bash missing) fails
on a real setup line instead of aborting on errorlevel at line one.

WSL worktrees, POSIX platforms, and SSH hosts are untouched.

* fix(worktrees): keep the cmd setup runner launchable from a Git Bash pane

Adversarial review of this PR found that pinning the runner format per script
reopened issue #6896 one layer down.

- `WorktreeSetupLaunch.shell` had been redefined to mean "the format the runner
  file was written in". `resolveSetupRunnerCommand` consumes it as "the shell
  that types the launch command", so a Git Bash terminal with a batch setup
  script produced `cmd.exe /c "C:\...\setup-runner.cmd"` typed into a bash pane,
  where MSYS rewrites the `/c` switch into a drive path: cmd opens interactively
  and setup never runs. `shell` is the terminal's family again; the runner file's
  .cmd/.sh extension carries the format, and a batch runner launched from a POSIX
  pane reuses the existing PowerShell ProcessStartInfo launcher.
- The cmd runner dropped a leading `#!` line and ran the rest as batch, so a bash
  script reaching cmd (PowerShell/cmd terminal, or any SSH-to-Windows host) got
  its interpreter-agnostic prefix executed before failing mid-way. It now prints
  why and exits 1 without running anything.
- A `#!` line's option flags were discarded: `#!/usr/bin/env -S bash -euo
  pipefail` lost pipefail because the runner is launched as `bash <path>`. The
  generated posix runner now replays declared flags via `set` and drops the
  duplicate interpreter line.
- Docs cover the per-user setup command in repository hook settings, which goes
  through the same `#!` rule, and describe what the `#!` line does and does not
  select.

Tests: composed launch command for a POSIX pane + cmd runner (hooks, shared
runner command, setup sequencing gate, observed-setup signal), the cmd runner's
shebang refusal, and shebang flag replay. Each fails with the source reverted.

* fix(worktrees): replay only real `set` flags and keep the gate in the pane's shell

Two round-2 review findings:

- `#!/bin/bash -l` replayed `set -l`, which exits 2 and aborted the runner under
  its own `set -e` before a single setup line ran (all platforms). Only the flags
  `set` documents are replayed now; a bare `-o` with no option name is dropped
  instead of dumping the shell-option table.
- The wait-for-setup gate picked its language from the runner file, so a batch
  runner launched from a Git Bash pane got the PowerShell gate while the agent
  startup command was already POSIX-quoted — `Invoke-Expression` cannot parse
  `'\''`. The gate now follows the pane; the runner still launches through the
  ProcessStartInfo launcher, never through bash.

---------

Co-authored-by: OrcaWin <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* Honor configured shells during worktree setup

* Align setup launch paths with selected Windows shells

* Carry setup shell selection through deferred launches

* Prove Windows setup shell routing at its real adapters

* Ground remote PowerShell proof in the real writer

* Preserve Git Bash across deferred setup launches

* Harden Windows setup runner shell selection

- Resolve remote PowerShell binary without local pwsh probe: for SSH/remote
  Windows worktrees, isPwshAvailable() reflects only the LOCAL host, so an
  'auto' implementation could route the remote runner to a pwsh.exe the remote
  lacks. Add resolveSetupRunnerShell(..., { probeLocalPwsh: false }) so remote
  auto keeps the always-present powershell.exe; explicit pwsh.exe still honored.
- Preserve native exit codes in the PowerShell runner by checking
  $LASTEXITCODE before $?, so a failing native command surfaces its real code
  instead of a generic exit 1; $? still catches cmdlet soft-failures.
- Write the PowerShell runner with a UTF-8 BOM so Windows PowerShell 5.1 (the
  new default powershell.exe) reads it as UTF-8 instead of ANSI, preventing
  non-ASCII setup-script corruption.
- Add unit tests for the remote-probe behavior.

* Restore setup-shell scope narrowing over the rebase

The force-pushed rebase dropped five review-fix commits that were already
on this branch; this reapplies their combined effect on top of the new
base and the hardening commit:

- Keep SSH setup shell selection remote-owned (no local terminalWindowsShell
  or pwsh routing for remote hosts; supersedes the probeLocalPwsh guard)
- Preserve cmd setup compatibility outside POSIX shells (no .ps1 runner
  family, so the BOM/exit-code hardening is no longer applicable)
- Route WSL setup runners from the project runtime
- Avoid blocking PowerShell probes during setup creation
- Correct SSH and WSL background setup fixtures

* Satisfy the changed-code gates for the setup-shell runner

- createWorktreeRunnerScript took 7 positional parameters, tripping the
  changed-code max-params gate; move it to a single options object.
- hooks-runner.test.ts deep-equals the createSetupRunnerScript result, so
  assert the cmd shell now returned for native Windows worktrees.

* Carry the setup launch shell through observed and issue runners

- buildObservedSetupCommand takes the runner's launch shell so WSL-routed
  Windows-drive setup replays use /mnt/c instead of Git Bash /c
- resolveSetupRunnerShell gates the posix runner on the same Git Bash
  resolution the PTY uses, so a missing or non-MSYS bash keeps the cmd runner
- issue-command runners carry their launch shell, and the renderer passes it
  when building the queued command
- treat a bare `bash` shell setting as POSIX like `bash.exe`

Co-authored-by: Orca <[email protected]>

* fix(worktrees): close counsel P1 gaps for Windows setup shells

Route windowless/headless creates through the shell-aware setup runner when a
PTY controller is available, existence-check explicit Git Bash paths before
committing to .sh runners, thread the resolved shell into issue-command
runners, and document the intentional Git Bash interpreter flip with a narrow
scope table.

* Convert setup env to MSYS form and harden the bare cmd runner launch

C3: a Git Bash setup runner now receives ORCA_*/CONDUCTOR_*/GHOSTX_* path
values in /c/... form, matching the runner path and the shell's own HOME/PWD.
C5: extension-less `bash` resolves to Git Bash everywhere, matching how
resolveWindowsShellStartupFamily already classifies it.
C7: runner paths carrying characters that cannot be quoted on a cmd command
line launch through a delayed-expansion PowerShell shim instead, and the batch
runner disables inherited delayed expansion so `!` in setup lines survives.

Co-authored-by: Orca <[email protected]>

* docs: note MSYS ORCA_* paths and bare bash Git Bash resolution

Keep the setup-shell release note aligned with C3 env conversion and C5 bare
bash resolution so the published claim matches runtime behavior.

* revert: drop windows-setup-shell doc allowlist and AGENTS link

Keep the counsel P1/P2 product fixes without expanding the docs allowlist
or AGENTS.md guidance surface.

* fix(plugins): contain Parcel unsubscribe rejections under Vitest

Dev plugin watchers fire-and-forget unsubscribe, and in-process Parcel
can reject when temp watch roots are already deleted. Catch those
rejections so they cannot fail the suite as unhandled errors.

* fix(plugins): keep in-process unsubscribe rejection surface

Swallowing Parcel unsubscribe errors broke mocked unsubscribe tests
that return non-Promises and expect rejections. Contain failures only
in PluginDevWatcher fire-and-forget paths.

---------

Co-authored-by: OrcaWin <[email protected]>
Co-authored-by: Brennan Benson <[email protected]>
Co-authored-by: Jinjing <[email protected]>
Co-authored-by: Orca <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…s to Git Bash (stablyai#12406)

* fix(worktrees): stop silently switching existing Windows setup scripts to Git Bash

stablyai#6967 derived the Windows setup-runner shell from `terminalWindowsShell`. On
upgrade, any Windows user whose terminal preference resolved to Git Bash had
their existing `orca.yaml` setup script (and issue command) handed to bash
instead of cmd.exe. Scripts authored against the cmd runner — `copy`, `xcopy`,
`set VAR=value`, `if errorlevel 1`, `%VAR%`, backslash paths — broke with no
migration and no warning, and the failure looked like Orca broke the project.

The conflation is also wrong in the steady state: a terminal preference is
per-user, so two people on the same repo got different interpreters for the
same orca.yaml and no project could write a setup script that worked for all
of its Windows contributors.

The interpreter is now a property of the script, declared the standard way:
a leading `#!` line. Native Windows keeps the historical `.cmd` runner unless
the script declares a POSIX shell, so no existing script changes behavior.
`resolveSetupRunnerShell` keeps its role as the feasibility gate — a bash
runner still requires the terminal to resolve to Git Bash, since the launch
command is typed into that shell and uses MSYS `/c/...` paths.

`buildWindowsRunnerScript` now drops a leading `#!` line rather than `call`ing
it, so a declared-bash script that falls back to cmd (Git Bash missing) fails
on a real setup line instead of aborting on errorlevel at line one.

WSL worktrees, POSIX platforms, and SSH hosts are untouched.

* fix(worktrees): keep the cmd setup runner launchable from a Git Bash pane

Adversarial review of this PR found that pinning the runner format per script
reopened issue stablyai#6896 one layer down.

- `WorktreeSetupLaunch.shell` had been redefined to mean "the format the runner
  file was written in". `resolveSetupRunnerCommand` consumes it as "the shell
  that types the launch command", so a Git Bash terminal with a batch setup
  script produced `cmd.exe /c "C:\...\setup-runner.cmd"` typed into a bash pane,
  where MSYS rewrites the `/c` switch into a drive path: cmd opens interactively
  and setup never runs. `shell` is the terminal's family again; the runner file's
  .cmd/.sh extension carries the format, and a batch runner launched from a POSIX
  pane reuses the existing PowerShell ProcessStartInfo launcher.
- The cmd runner dropped a leading `#!` line and ran the rest as batch, so a bash
  script reaching cmd (PowerShell/cmd terminal, or any SSH-to-Windows host) got
  its interpreter-agnostic prefix executed before failing mid-way. It now prints
  why and exits 1 without running anything.
- A `#!` line's option flags were discarded: `#!/usr/bin/env -S bash -euo
  pipefail` lost pipefail because the runner is launched as `bash <path>`. The
  generated posix runner now replays declared flags via `set` and drops the
  duplicate interpreter line.
- Docs cover the per-user setup command in repository hook settings, which goes
  through the same `#!` rule, and describe what the `#!` line does and does not
  select.

Tests: composed launch command for a POSIX pane + cmd runner (hooks, shared
runner command, setup sequencing gate, observed-setup signal), the cmd runner's
shebang refusal, and shebang flag replay. Each fails with the source reverted.

* fix(worktrees): replay only real `set` flags and keep the gate in the pane's shell

Two round-2 review findings:

- `#!/bin/bash -l` replayed `set -l`, which exits 2 and aborted the runner under
  its own `set -e` before a single setup line ran (all platforms). Only the flags
  `set` documents are replayed now; a bare `-o` with no option name is dropped
  instead of dumping the shell-option table.
- The wait-for-setup gate picked its language from the runner file, so a batch
  runner launched from a Git Bash pane got the PowerShell gate while the agent
  startup command was already POSIX-quoted — `Invoke-Expression` cannot parse
  `'\''`. The gate now follows the pane; the runner still launches through the
  ProcessStartInfo launcher, never through bash.

---------

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

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Worktree "Local setup command" is built as a cmd.exe invocation on Windows — fails to run under the configured Git Bash shell

5 participants