Skip to content

Provide the Orca CLI automatically in managed WSL terminals - #22761

Merged
OrcaWin merged 8 commits into
mainfrom
OrcaWin/wsl-managed-cli-auto-setup
Sep 26, 2026
Merged

OrcaWin merged 8 commits into
mainfrom
OrcaWin/wsl-managed-cli-auto-setup

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​368 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​363
Prod 15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​198 $\color{#cf222e}{\Huge{\mathbf{−}}}$​19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​179

ELI5

Terminals Orca opens inside WSL (Linux on Windows) now have this Orca's command-line tool (orca-ide, or orca-dev in development) ready to use. Nothing is installed inside Linux, and no shell profile or PATH setting is edited. Before, the command only existed if the user had registered it by hand in Settings → General, which is still how shells opened outside Orca get it.

What Changed

Before: in an Orca WSL terminal, orca-ide was "command not found" unless the user had registered the CLI, and agents running there could not call back into Orca.

After: it resolves to the Orca instance that opened the terminal.

How:

  1. Host (Windows). When Orca builds the environment for a WSL terminal (buildPtyHostEnv), getManagedWslCliDir writes a small launcher script and PowerShell bridge into <userData>/wsl-managed-cli/<content hash> and sets ORCA_WSL_CLI_DIR. Terminals that are not WSL clear the variable.
  2. Crossing into WSL. addOrcaWslInteropEnv, which every WSL launch already goes through (daemon and in-process), passes the folder with WSLENV /p, so each distro translates the path with its own mount settings.
  3. Guest (Linux). After the user's own startup files run, the bash rcfile and the zsh first-prompt hook put the folder first on PATH, once. If the launcher can't be executed (for example, a mount without exec permission), the shell prints one warning and carries on. It never blocks a shell.

The launcher and bridge reuse the builders from WSL registration (wsl-cli-scripts.ts). The registered scripts' output is byte-for-byte unchanged. The managed bridge also:

  • pins this app's user-data directory, quoted with the shared quotePowerShellLiteral (now also escaping typographic quotes such as ’, which PowerShell treats as string delimiters);
  • is written with a UTF-8 byte-order mark so Windows PowerShell 5.1 reads non-ASCII paths correctly;
  • clears the guest-only directory before starting Windows processes (the daemon also drops an inherited copy, alongside pane identity);
  • in development, runs Electron as Node on out/cli/index.js with the same environment as the existing dev launcher.

Why

  • Why not install into the guest? That needs a subprocess per distro, a guest directory that may not be on PATH, and cleanup on uninstall. Host-owned files mounted through WSLENV avoid all three.
  • Why a content hash in the folder name? For the same reason as the shell-ready wrappers (shell-wrapper-content-address.ts): builds that share user data never overwrite each other, and a file that exists is complete because each one lands by rename.
  • Why hook addOrcaWslInteropEnv? It runs on the final, merged environment for both spawn paths, so a user's own WSLENV entries survive.

Linked Issue

Launch-side prerequisite for the WSL skill-setup work in #22720; that branch is not modified. This PR removes no UI prerequisite. Skill setup can stop requiring WSL registration only in a follow-up that also handles older paired hosts.

Visual Proof

Before: in an isolated home with PATH=/usr/bin:/bin, neither orca-ide nor orca-dev resolved.

After (captured on the first revision of this PR through Playwright CDP from a hidden Electron build): a managed WSL terminal resolves its own launcher, --help passes, and status --json returns the isolated app's runtime ID.

Managed WSL terminal: help passes and owning runtime is ready

The current revision was verified by the live WSL test below rather than a new app screenshot.

Testing

Windows 11, WSL 2, Ubuntu-24.04, ORCA_BACKGROUND_LAUNCH=1.

  • I manually tested these changes locally (the first revision was tested in a real Electron app; this revision is covered by the live WSL and PowerShell tests below)
  • Automated tests added/updated

Live tests (Windows only):

  • wsl-managed-cli.wsl.test.ts (opt-in) runs the real rcfile in the real distro, with a profile that resets PATH and a user-data path containing 张三. It checks:
    • arguments containing spaces and $, piped stdout, stderr and exit codes;
    • the owning app and terminal identity;
    • that shells outside Orca do not get the command;
    • that a missing directory only warns;
    • that the user's profiles and registration are unchanged.
  • The same test passes with Node and with Electron as the started program.
  • wsl-cli-powershell-boundary.test.ts runs the managed bridge under Windows PowerShell 5.1 with a 张三 O’Brien user-data path, checking the dev NODE_OPTIONS stash and that ORCA_WSL_CLI_DIR is cleared. It fails without the byte-order mark (the path arrives as å¼ ä¸‰) and without the typographic-quote escaping (Unexpected token 'Brien').

Unit tests:

  • WSLENV routing for WSL terminals, and clearing a leftover value for other terminals.
  • Content-addressed reuse, repair of a missing file, and isolation between app instances.
  • Missing-runtime behaviour.
  • Regenerated bash and zsh wrapper snapshots.

Checks: typecheck (node and web), oxlint, oxfmt and the changed-code quality gate pass.

Full-suite comparison: the whole suite (89,197 tests) was run on this branch and on its base commit on the same Windows machine, and the failing-test lists compared. Every branch-only failure either also fails on the base when re-run alone (timing flakes under full-suite load) or passes in a fresh checkout of this exact commit (one SQLite EBUSY cleanup failure local to the original worktree). No failure is attributable to this change.

Not covered:

  • zsh is not installed in this distro.
  • No second distro, custom automount root, or disabled-interop setup was tried.
  • The full suite and release packaging were not run.
  • 9 daemon/pty tests fail on this Windows machine; they fail identically on the base commit.

To repeat the live test:

$env:ORCA_BACKGROUND_LAUNCH='1'
$env:ORCA_TEST_MANAGED_WSL='1'
$env:ORCA_TEST_WSL_DISTRO='Ubuntu-24.04' # omit for the default distro
node node_modules/vitest/vitest.mjs run --config config/vitest.config.ts src/main/cli/wsl-managed-cli.wsl.test.ts src/main/cli/wsl-cli-powershell-boundary.test.ts

Review

  • Security software (EDR): every CLI call from an Orca WSL terminal now runs powershell.exe -ExecutionPolicy Bypass -File <bridge>. Before, this happened only after the user registered the CLI. docs/reference/windows-edr-posture.md records this.
  • SSH and relay: unaffected (buildPtyHostEnv is local-only, and the relay wrapper spec opts out).
  • Folder workspaces: unaffected.
  • Older daemons: a daemon still running an older build's wrappers simply has no managed CLI until it restarts.

Agent skill upstream boundary

  • Not applicable: no upstream installer source or skills copied.

Notes

Mechanism details: docs/reference/wsl-managed-cli.md.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (focused checks above pass locally; the package runner cannot reinstall here, so CI covers the rest)

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

Important

Managed WSL terminals now refuse to open when the distro's login shell is not bash or zsh. The reference doc calls this intentional, but it converts a previously working pane into an immediate failure for fish/ksh/dash users — see the inline comment for a fallback option before merging.

Reviewed changes

  • App-owned launcher provisioning — on a win32 host, prependOrcaCliDirToChildPath now calls applyManagedWslCliEnvironment, which writes an app-owned launcher/bridge tree under <userData>/wsl-managed-cli/<content hash> and exports ORCA_WSL_CLI_DIR plus a WSLENV /p translation (or ORCA_WSL_CLI_ERROR on failure).
  • Guest-side PATH restore — the shared WSL_MANAGED_CLI_PATH block is injected into the bash shell-ready rcfile, the local zsh .zshenv deferred init (fixture snapshots updated), and every buildWslLoginShellCommand payload, so the CLI survives profile resets without editing guest profiles or ~/.local/bin.
  • Managed launcher/bridge variants — buildWslLauncher/buildWslBridgeScript gain optional managed behavior: host-resolved Windows PowerShell via wslpath, ORCA_USER_DATA_PATH pinning, hidden child, explicit stdout/stderr forwarding, and dev-mode ELECTRON_RUN_AS_NODE direct CLI invocation.
  • Capability advertisement — terminal.managed-wsl-cli.v1 is added to RUNTIME_CAPABILITIES for a later UI integration; no consumer yet.
  • Concurrency/repair semantics — content-addressed directories, temp+rename publishing, missing-file repair, and refusal of modified files/symlinks, with focused unit, snapshot, and opt-in live WSL tests.

ℹ️ Two different "managed WSL CLI" concepts now share a name

main already has reconcileManagedWslCliRegistrations / repairManagedRegistration (src/main/cli/wsl-cli-registration-reconciliation.ts), which means guest-side global registration of orca-ide into each distro. This PR introduces ensureManagedWslCli / applyManagedWslCliEnvironment (src/main/cli/wsl-managed-cli.ts), which means host-side app-owned launcher provisioning. Same phrase, opposite mechanisms — a future reader could reasonably wire the wrong one. Consider naming the new surface around the app-owned/terminal reach (e.g. ensureWslTerminalCli) so the two do not collide.

Technical details
# Distinct "managed WSL CLI" subsystems share a name

## Affected sites
- `src/main/cli/wsl-cli-registration-reconciliation.ts:61` — `reconcileManagedWslCliRegistrations`, startup repair of per-distro global registration.
- `src/main/cli/wsl-managed-cli.ts:18` — `ensureManagedWslCli`, host-side app-owned launcher tree.
- `src/shared/protocol-version.ts:139` — `TERMINAL_MANAGED_WSL_CLI_RUNTIME_CAPABILITY` names the new behavior "managed WSL CLI" too.

## Required outcome
- A name for the new surface that does not read as the existing global-registration reconciliation, or an explicit doc note distinguishing them.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread src/shared/wsl-login-shell-command.ts Resolved
@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Reviews paused

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

Use the following commands to manage reviews:

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

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: b9097a93-f804-4fc0-84da-23ccd0a5a40e

📥 Commits

Reviewing files that changed from the base of the PR and between 6cad86c and e4bb947.

📒 Files selected for processing (1)
  • src/main/wsl-managed-cli-path-restore.test.ts

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


📝 Walkthrough

Walkthrough

The change resolves and provisions the managed WSL CLI from host runtime details, generates launcher and bridge scripts, and passes the managed CLI directory into WSL. Local Bash and zsh wrappers now restore the directory to PATH when the configured executable is available. The change also updates bridge and WSL integration tests, shell snapshots, and reference documentation.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to e4bb9

The reviewed quoting and shell-test concerns are addressed, and CLI output remains available in managed WSL terminals. No material unresolved issue remains before merge.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to e4bb9

Processes and agents in Orca-managed WSL terminals will be able to invoke the host application’s CLI without the previous manual registration step. The change is scoped to managed terminals and handles unavailable launchers, but the expanded access to application commands warrants a security design review.

Retained concerns

  • Medium · security · inferred: Automatic PATH exposure lets any process in a managed WSL pane invoke the host application’s CLI, including commands that send requests to the live application. The bridge does not itself authorize commands; whether downstream command policy sufficiently distinguishes guest agents from the user remains unestablished.
Security review details

Security Blast Radius

  • inferred — The newly convenient application-control path is limited to processes with access to an Orca-managed WSL pane and its launcher environment. The evidence does not establish cross-user, cross-tenant, or elevated Windows authority.

Security Findings and Attack Paths

  • inferred — Code or an agent running in a managed WSL shell can invoke the exposed command, pass arguments through the bridge, and reach CLI application requests without first registering the CLI. Whether a particular request succeeds remains subject to downstream controls not established here.

Trust Boundaries and Controls

  • observed — The bridge quotes native arguments, starts the child with UseShellExecute disabled, and clears the guest-only launcher variable. Host and daemon environment assembly also prevent an inherited launcher directory from silently selecting another spawn’s CLI.

Resilience and Maintainability Implications

  • observed — Failed provisioning does not publish a PATH entry, and an unavailable executable does not alter PATH. This contains partial-startup failures, though custom mount behavior has not been established by production execution evidence.

Hardening Proposals

  • proposed — Define whether managed WSL agents are intended to have the user’s full CLI authority. If not, enforce the distinction at the application command boundary rather than relying on PATH availability or restrictions in the launcher.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 29 functions across 29 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: automatic availability of the Orca CLI in managed WSL terminals.
Description check ✅ Passed The description is detailed and covers the required explanation, user impact, implementation, rationale, linked issue, visual proof, testing, review risks, and checklist. Some checklist items remain u…
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: d63d412b-5b91-44cb-b44b-f881b2dc13ce

📥 Commits

Reviewing files that changed from the base of the PR and between 1c1b782 and 184b33c.

📒 Files selected for processing (18)
  • docs/reference/wsl-managed-cli.md
  • src/main/__fixtures__/shell-wrapper-snapshots/local-bash-rcfile.txt
  • src/main/__fixtures__/shell-wrapper-snapshots/local-zsh-zshenv.txt
  • src/main/cli/orca-cli-child-path.test.ts
  • src/main/cli/orca-cli-child-path.ts
  • src/main/cli/wsl-cli-powershell-boundary.test.ts
  • src/main/cli/wsl-cli-scripts.ts
  • src/main/cli/wsl-managed-cli.test.ts
  • src/main/cli/wsl-managed-cli.ts
  • src/main/cli/wsl-managed-cli.wsl.test.ts
  • src/main/providers/local-pty-shell-ready-bash-rcfile.ts
  • src/main/providers/local-pty-shell-ready-wrapper-fileset.ts
  • src/main/zsh-startup-wrapper-builder.ts
  • src/renderer/src/components/settings/CliSkillRuntimeSetup.test.tsx
  • src/shared/protocol-version.ts
  • src/shared/wsl-login-shell-command.test.ts
  • src/shared/wsl-login-shell-command.ts
  • src/shared/wsl-managed-cli-path.ts

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

Comment thread src/main/cli/wsl-cli-scripts.ts Outdated
userDataPath: string
cliEntryPath?: string
}): string {
const psQuote = (value: string): string => `'${value.replace(/'/g, "''")}'`

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

Escape typographic single quotes in psQuote.

PowerShell treats U+2018, U+2019, U+201A, and U+201B as single-quote delimiters inside single-quoted strings. psQuote escapes only the ASCII '. Assume userDataPath or cliEntryPath contains ’, for example a Windows profile named O’Brien. The generated literal then ends early, and the bridge fails to parse. Every managed CLI call in that case fails with a script error.

🐛 Proposed fix
-  const psQuote = (value: string): string => `'${value.replace(/'/g, "''")}'`
+  const psQuote = (value: string): string =>
+    `'${value.replace(/['\u2018\u2019\u201A\u201B]/g, (quote) => quote + quote)}'`
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const psQuote = (value: string): string => `'${value.replace(/'/g, "''")}'`
const psQuote = (value: string): string =>
`'${value.replace(/['\u2018\u2019\u201A\u201B]/g, (quote) => quote + quote)}'`

Never block a shell on CLI availability, keep the shared WSL login-shell
builder unchanged, provision from PTY env assembly only, drop the error
variable and command probing, and reuse the existing WSLENV helper.

@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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 7bd9b572-a492-4cd9-8106-556ed087d0ce

📥 Commits

Reviewing files that changed from the base of the PR and between 184b33c and c356ac0.

📒 Files selected for processing (17)
  • docs/reference/wsl-managed-cli.md
  • src/main/__fixtures__/shell-wrapper-snapshots/local-bash-rcfile.txt
  • src/main/__fixtures__/shell-wrapper-snapshots/local-zsh-zshenv.txt
  • src/main/cli/orca-cli-child-path.ts
  • src/main/cli/wsl-cli-scripts.ts
  • src/main/cli/wsl-managed-cli.test.ts
  • src/main/cli/wsl-managed-cli.ts
  • src/main/cli/wsl-managed-cli.wsl.test.ts
  • src/main/daemon/daemon-zsh-shell-ready-wrapper-spec.ts
  • src/main/ipc/pty/host-env/assembly.ts
  • src/main/pty/wsl-orca-env.ts
  • src/main/zsh-startup-wrapper-builder.ts
  • src/relay/pty-shell-overlay-wrappers.ts
  • src/renderer/src/components/settings/CliSkillRuntimeSetup.test.tsx
  • src/renderer/src/components/settings/CliSkillRuntimeSetup.tsx
  • src/shared/protocol-version.ts
  • src/shared/wsl-managed-cli-path.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/shared/protocol-version.ts
  • docs/reference/wsl-managed-cli.md
Files not reviewed due to moderation or processing errors (15)
  • src/main/cli/wsl-cli-scripts.ts
  • src/main/cli/wsl-managed-cli.ts
  • src/main/cli/wsl-managed-cli.test.ts
  • src/main/cli/wsl-managed-cli.wsl.test.ts
  • src/main/ipc/pty/host-env/assembly.ts
  • src/main/pty/wsl-orca-env.ts
  • src/main/cli/orca-cli-child-path.ts
  • src/shared/wsl-managed-cli-path.ts
  • src/main/zsh-startup-wrapper-builder.ts
  • src/main/fixtures/shell-wrapper-snapshots/local-bash-rcfile.txt
  • src/main/fixtures/shell-wrapper-snapshots/local-zsh-zshenv.txt
  • src/main/daemon/daemon-zsh-shell-ready-wrapper-spec.ts
  • src/relay/pty-shell-overlay-wrappers.ts
  • src/renderer/src/components/settings/CliSkillRuntimeSetup.tsx
  • src/renderer/src/components/settings/CliSkillRuntimeSetup.test.tsx

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

Comment on lines +32 to +49
return null
}
const powerShellPath = win32.join(
process.env.SystemRoot || 'C:\\Windows',
'System32\\WindowsPowerShell\\v1.0\\powershell.exe'
)
const launcherScript = buildColocatedWslLauncher(launcher, powerShellPath)
const bridge = buildWslBridgeScript({ userDataPath: options.userDataPath, cliEntryPath })
const digest = createHash('sha256').update(launcherScript).update(bridge).digest('hex')
const directory = join(options.userDataPath, 'wsl-managed-cli', digest.slice(0, 20))
const files = [
[join(directory, options.isPackaged ? 'orca-ide' : 'orca-dev'), launcherScript],
[join(directory, 'orca-wsl-bridge.ps1'), bridge]
] as const
const ready =
files.every(([path]) => existsSync(path)) || writeShellWrapperFiles(files, '[WSL CLI]')
return ready ? directory : null
}

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

🔎 Supported by static analysis

🏁 Script executed:

sed -n '1,110p' src/main/cli/wsl-managed-cli.ts
sed -n '1,100p' src/main/shell-wrapper-file-writer.ts
sed -n '1,100p' src/main/cli/wsl-managed-cli.test.ts

Repository: stablyai/orca

Length of output: 8607


🏁 Script executed:

printf '%s\n' '--- diff ---'
git diff --unified=40 bf40d35b0b77b02fe1ad0f4103f83b73b1637522 -- src/main/cli/wsl-managed-cli.ts src/main/cli/wsl-cli-scripts.ts src/main/shell-wrapper-file-writer.ts
printf '%s\n' '--- script definitions and calls ---'
rg -n -C 5 "buildColocatedWslLauncher|buildWslBridgeScript|ORCA_WSL_CLI_DIR|orca-wsl-bridge|orca-dev|orca-ide|ensureManagedWslCli" src/main src/shared
printf '%s\n' '--- remaining managed CLI test ---'
sed -n '90,260p' src/main/cli/wsl-managed-cli.test.ts

Repository: stablyai/orca

Length of output: 45659


🤖 get_repo_knowledge executed:

get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions

Length of output: 36696


🏁 Script executed:

git diff --unified=25 bf40d35b0b77b02fe1ad0f4103f83b73b1637522 -- src/main/cli/wsl-managed-cli.ts src/main/cli/wsl-cli-scripts.ts src/main/shell-wrapper-file-writer.ts
printf '%s\n' '--- bindings ---'
rg -n -C 4 "buildColocatedWslLauncher|buildWslBridgeScript|ORCA_WSL_CLI_DIR|orca-wsl-bridge|orca-dev|orca-ide|ensureManagedWslCli" src/main src/shared
printf '%s\n' '--- tests ---'
sed -n '90,260p' src/main/cli/wsl-managed-cli.test.ts

Repository: stablyai/orca

Length of output: 45659


🏁 Script executed:

set -eu
printf '%s\n' '--- managed cli and writer ---'
nl -ba src/main/cli/wsl-managed-cli.ts
nl -ba src/main/shell-wrapper-file-writer.ts | sed -n '1,90p'
printf '%s\n' '--- WSL path and assembly ---'
nl -ba src/shared/wsl-managed-cli-path.ts
rg -n -C 12 "applyManagedWslCliEnvironment|WSL_MANAGED_CLI_PATH|ensureManagedWslCli" src/main src/shared -g '*.ts'
printf '%s\n' '--- base-tree candidates ---'
git ls-tree -r --name-only bf40d35b0b77b02fe1ad0f4103f83b73b1637522 | rg 'wsl-managed-cli|wsl-cli|shell-wrapper-file-writer|wsl-managed-cli-path'

Repository: stablyai/orca

Length of output: 38275


🏁 Script executed:

rg -n -C 8 "modified|user.?owned|managed|marker|safe.*replace|conflict|repair|overwrite|existsSync|readFileSync" \
  src/main/cli/wsl-cli-installer.ts \
  src/main/cli/wsl-cli-registration-command.ts \
  src/main/cli/wsl-cli-registration-operation.ts \
  src/main/cli/wsl-cli-registration-reconciliation.ts \
  src/main/cli/wsl-cli-scripts.ts \
  src/main/cli/wsl-cli-*.test.ts

Repository: stablyai/orca

Length of output: 42571


Repair modified managed WSL files before reuse.

ensureManagedWslCli accepts any existing launcher and bridge. WSL then prepends ORCA_WSL_CLI_DIR to PATH, so later orca-ide or orca-dev calls execute the modified files. Compare file contents before reusing the content-addressed directory and rewrite mismatches.

Suggested fix
-import { existsSync } from 'node:fs'
+import { existsSync, readFileSync } from 'node:fs'
...
-  const ready =
-    files.every(([path]) => existsSync(path)) || writeShellWrapperFiles(files, '[WSL CLI]')
+  const ready =
+    files.every(([path, content]) => {
+      try {
+        return readFileSync(path, 'utf8') === content
+      } catch {
+        return false
+      }
+    }) || writeShellWrapperFiles(files, '[WSL CLI]')

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

✅ No new issues found.

Reviewed changes — the delta since the prior pullfrog review (184b33c6d6 → c356ac0e01, "Simplify managed WSL CLI provisioning"):

  • Removed the shell-refusal guard — non-bash/zsh login shells and a missing zsh wrapper now degrade to the plain login shell instead of failing the pane, and the in-guest ORCA_WSL_CLI_ERROR hard-stop is gone (host now logs and leaves the var unset).
  • Simplified guest PATH restore — WSL_MANAGED_CLI_PATH now just prepends ORCA_WSL_CLI_DIR to PATH when readable (no ORCA_CLI_COMMAND export, no exit 1), and buildWslLoginShellCommand no longer injects it; the renderer skill-setup path prepends it explicitly (CliSkillRuntimeSetup.tsx:67).
  • Scoped provisioning to PTYs — applyManagedWslCliEnvironment moved from prependOrcaCliDirToChildPath into buildPtyHostEnv, so it covers every Windows PTY (native PowerShell panes included) without leaking into the structured-worker env.
  • Softer ensureManagedWslCli — returns string | null instead of throwing and trusts a present content-addressed tree rather than re-verifying file contents; the refuses to overwrite unrelated content test was dropped.
  • Builder refactor — wsl-cli-scripts.ts gained buildColocatedWslLauncher/buildLauncher/bridgeLines/quotePowerShell; the guest-registration launcher/bridge output is unchanged. ZshWrapperRestoreSpec.managedWslCli is now a required boolean.

Both prior pullfrog inline threads were addressed and resolved: the managed-block assertion was restored in CliSkillRuntimeSetup.test.tsx, and the non-bash/zsh refusal was removed.

ℹ️ Nitpicks

  • The PR description still says "Missing or modified files produce actionable errors." That no longer matches the code after this commit — missing files are silently repaired, a present tree is trusted as-is, and provisioning failures only console.warn on the host. Worth updating the description for reviewers.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Provision only for WSL panes and publish the directory through
addOrcaWslInteropEnv, so daemon terminals keep inherited WSLENV entries and
non-WSL builds never see the variable. Write the bridge with a UTF-8 BOM so
Windows PowerShell 5.1 keeps non-ASCII user-data paths, give the dev bridge the
dev launcher's app-launch env, and drop the unused skill-setup wiring and
runtime capability.

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

✅ No new issues found.

Reviewed changes — the delta since the prior pullfrog review (c356ac0e01 → 2a69500731, "Scope the managed WSL CLI to WSL terminals"):

  • Scoped provisioning to WSL panes — buildPtyHostEnv now calls getManagedWslCliDir only inside if (opts.isWsl) and deletes any inherited ORCA_WSL_CLI_DIR, so native Windows PTYs no longer receive it.
  • Dropped the runtime capability and skill-setup injection — TERMINAL_MANAGED_WSL_CLI_RUNTIME_CAPABILITY and its RUNTIME_CAPABILITIES entry are removed, the renderer's WSL skill-setup command no longer prepends the managed block, and the doc's integration section is gone.
  • Moved and strengthened the guest PATH restore — WSL_MANAGED_CLI_PATH became src/main/wsl-managed-cli-path-restore.ts; it now checks the launcher is executable, de-dupes a nested PATH entry, and warns with clearer text.
  • Split host resolution — getManagedWslCliDir / getWslCliCommandName / resolveManagedWslCliRuntime, using windowsPowerShellPath() and a hasAppEnvironment() gate for dev.
  • Bridge hardening — app bridges are written with a UTF-8 BOM and set the dev app-launch env (ELECTRON_RUN_AS_NODE, ORCA_APP_EXECUTABLE, ORCA_APP_EXECUTABLE_NEEDS_APP_ROOT).
  • Tests — added a non-ASCII PowerShell 5.1 boundary test; reworked the unit and opt-in WSL e2e tests; dropped the concurrent-provisioning and interop-failure coverage.

ℹ️ PR description still describes the pre-scoping behavior

The body says the runtime advertises terminal.managed-wsl-cli.v1 and links to docs/reference/wsl-managed-cli.md#integration-with-pr-22720, but this commit deletes both the capability constant and that doc section. It also still claims managed terminals "cover skill installers that start in PowerShell and then enter WSL", which the WSL-only scoping (plus the removed skill-setup injection) no longer does. Worth updating so the description matches the shipped surface.

Technical details
# Stale PR description claims after scoping

## Affected sites
- `docs/reference/wsl-managed-cli.md` — no longer contains an `#integration-with-pr-22720` section.
- `src/shared/protocol-version.ts` — `TERMINAL_MANAGED_WSL_CLI_RUNTIME_CAPABILITY` and its `RUNTIME_CAPABILITIES` entry were deleted in `2a69500731`.
- `src/main/ipc/pty/host-env/assembly.ts:277` — provisioning is now `opts.isWsl` only, so a native PowerShell pane that shells into WSL no longer has `ORCA_WSL_CLI_DIR` to `/p`-translate.

## Required outcome
- The PR body's capability claim, doc anchor, and "skill installers that start in PowerShell and then enter WSL" sentence should reflect the shipped surface.

## Open questions for the human
- Is `terminal.managed-wsl-cli.v1` intentionally deferred to the #22720 UI work, or should it stay advertised here?

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Launch the bridge child exactly like the registered bridge (no hidden
window or output relay; verified through WSL with Node and Electron), give
the dev bridge the dev launcher's NODE_OPTIONS stash, clear the guest-only
directory before starting Windows processes, collapse setup into one
function, warn once, and guard WSL env routing with tests.

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

✅ No new issues found.

Reviewed changes — the delta since the prior pullfrog review (2a69500731 → a29b49763d, "Tighten the managed WSL CLI bridge and setup"):

  • Extracted shared script builders — wsl-cli-scripts.ts now factors the launcher into a generic buildLauncher, keeps buildWslLauncher (guest registration) and adds buildColocatedWslLauncher (managed, bridge found beside itself, PowerShell resolved via wslpath). buildWslBridgeScript takes an optional app object; the registered bridge's output is unchanged.
  • Hardened the managed bridge — it pins ORCA_USER_DATA_PATH, clears the WSLENV-mapped ORCA_WSL_CLI_DIR so a CLI-started app never inherits a guest path, and mirrors buildWindowsDevLauncher's dev env (ELECTRON_RUN_AS_NODE, ORCA_APP_EXECUTABLE/_NEEDS_APP_ROOT, stashing NODE_OPTIONS/NODE_REPL_EXTERNAL_MODULE into ORCA_*). The bespoke hidden-child stdout/stderr redirection is gone — the managed bridge now launches its child exactly like the registered one, which the live WSL test still covers for piped stdout/stderr/exit codes.
  • Simplified host resolution — getManagedWslCliDir inlines the former resolveManagedWslCliRuntime/ensureManagedWslCli split and latches the "runtime missing" warning to fire once per process.
  • Cleared stale provisioning for non-WSL panes — buildPtyHostEnv deletes any inherited ORCA_WSL_CLI_DIR before re-provisioning for WSL, and derives ORCA_CLI_COMMAND from getWslCliCommandName.
  • Coverage — new PowerShell 5.1 boundary test pinning the non-ASCII app identity, stashed NODE_OPTIONS, and cleared guest-only ORCA_WSL_CLI_DIR; unit tests for reuse/repair/isolation and missing runtime; a pty-serializer assertion that a stale ORCA_WSL_CLI_DIR is stripped from non-WSL panes.

Both prior pullfrog inline threads remain resolved (the managed-block assertion and the non-bash/zsh refusal), and no open pullfrog threads remain.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

PowerShell also ends single-quoted strings at typographic quotes, so a
user-data path such as O'Brien with a curly apostrophe broke the managed
bridge. Fix the shared quotePowerShellLiteral and reuse it. Drop an inherited
ORCA_WSL_CLI_DIR on the daemon path, remove the unreachable PATH dedupe, and
cover failed setup with a stale caller value.

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

✅ No new issues found.

Reviewed changes — the delta since the prior pullfrog review (a29b49763d → 81d5752ae6, "Harden managed WSL CLI quoting and inheritance"):

  • Typographic-quote escaping hardened — quotePowerShellLiteral now doubles U+2018/U+2019/U+201A/U+201B in addition to ASCII ', and wsl-cli-scripts.ts uses it instead of its local copy. Verified against PowerShell's CharTraits.IsSingleQuote, which matches all four code points (QuoteSingleLeft/Right, QuoteSingleBase, QuoteReversed), so the doubling round-trips rather than corrupting the path.
  • Inherited CLI dir stripped in the daemon — ORCA_WSL_CLI_DIR joined PANE_IDENTITY_ENV_KEYS, so createDaemonPtyEnvironment drops an inherited copy unless the caller sends one explicitly; the host path likewise clears it in buildPtyHostEnv before re-provisioning.
  • PATH de-dupe removed — both guest restore hooks already run once per Orca shell (the bash rcfile is sourced once; the zsh __orca_deferred_init self-guards on _orca_deferred_init_done and removes its precmd entry), so the leading-entry case was dead weight. Doc and both fixture snapshots updated to match.
  • Coverage extended — the PowerShell 5.1 boundary test now exercises a typographic/non-ASCII userData path and adds windowsHide; the pty-serializer suite asserts a stale caller ORCA_WSL_CLI_DIR is dropped even when provisioning fails.

Focused changed suites pass locally (64 tests across 6 files).

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Add a live zsh case that reaches a real prompt, a POSIX test that runs the
PATH restore snippet in bash and zsh under set -u, and a null result for
unwritable user data. Say what a failed write actually costs, and document
per-spawn write logging and older-daemon behaviour.

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

Important

The new POSIX test src/main/wsl-managed-cli-path-restore.test.ts fails on Ubuntu CI. Both bash cases assert an empty stderr, but bash reads /etc/bash.bashrc under set -u and writes PS1: unbound variable. CI shard test / tests node 24 8/8 is red on exactly these two assertions (:47 and :57); the other seven shards are green.

Reviewed changes — the delta since the prior pullfrog review (81d5752ae6 → 6cad86cb84, "Cover the managed WSL CLI in zsh and on POSIX CI"):

  • Added a POSIX restore test — runs WSL_MANAGED_CLI_PATH_RESTORE in bash (-uc) and zsh (-fuc, wrapped in a __orca_hook function) and asserts PATH-leading, warning, and no-op behavior.
  • Added a live zsh case — drives an interactive zsh through script to reach the first-prompt hook, and extracts a withManagedCli helper so the bash and zsh cases share provisioning, wrapper files, and the profile-unchanged snapshot.
  • Added an unwritable-userData unit case — getManagedWslCliDir returns null when the userData path is a file.
  • Gave writeShellWrapperFiles a consequence parameter — managed WSL provisioning now logs WSL terminals will start without the Orca CLI instead of the generic unwrapped-shell line; other callers keep the default.
  • Updated the reference doc — per-spawn write logging, older-daemon behavior, and the zsh test's skip conditions.

ℹ️ Nitpicks

  • The PR body's Testing list still says the live WSL test checks "that shells outside Orca do not get the command"; that assertion was removed in this commit.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

CI runners make bash -c read /etc/bash.bashrc, which fails under set -u.

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

✅ No new issues found.

Reviewed changes — the delta since the prior pullfrog review (6cad86cb84 → e4bb947235, "Keep system bashrc out of the PATH restore test"):

  • Fixed the red POSIX bash case — the bash variant of wsl-managed-cli-path-restore.test.ts now spawns with --norc --noprofile, so it no longer sources /etc/bash.bashrc (whose PS1 reference aborts under set -u) and the empty-stderr assertions pass. Verified locally on Linux: 3 bash cases pass, 3 zsh cases skip where zsh is absent.

The prior thread at wsl-managed-cli-path-restore.test.ts:25 is resolved and no open pullfrog threads remain.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

…li-auto-setup

# Conflicts:
#	src/main/cli/wsl-cli-powershell-boundary.test.ts
@OrcaWin
OrcaWin merged commit 58d1ff3 into main Sep 26, 2026
34 of 36 checks passed

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

✅ No new issues found.

Reviewed changes — the delta since the prior pullfrog review (e4bb947235 → 96d329e5cc, a merge of origin/main):

  • Merged origin/main — main independently added -WslDistro forwarding to the WSL launcher and bridge. It merged cleanly with the refactor from a29b49763d: the distro block now lives inside the shared buildLauncher (src/main/cli/wsl-cli-scripts.ts:59), so both the guest launcher and the managed buildColocatedWslLauncher forward $WSL_DISTRO_NAME. The bridge's -WslDistro parse and ORCA_CLI_WSL_DISTRO clear/set are intact, so managed-CLI calls now also pin the distro.
  • Resolved the single merge conflict in src/main/cli/wsl-cli-powershell-boundary.test.ts — kept both sides: main's -WslDistro invocation and stale ORCA_CLI_WSL_DISTRO/WSL_DISTRO_NAME assertions, plus the PR's windowsHide: true (invocations and exit case) and the non-ASCII app-identity test.

All prior pullfrog threads are resolved and no new issues surfaced; the review of e4bb947235 still holds.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

This was referenced Oct 9, 2026
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