Skip to content

feat(wsl): bridge sh/dash/ash panes report their folder (OSC 7) at every prompt - #35597

Merged
nwparker merged 4 commits into
mainfrom
nwparker/wsl-sh-cwd-report
Oct 29, 2026
Merged

nwparker merged 4 commits into
mainfrom
nwparker/wsl-sh-cwd-report

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​290 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​290
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​114 $\color{#cf222e}{\Huge{\mathbf{−}}}$​30 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​84

ELI5

Orca remembers which folder each WSL terminal is in, so a restored pane reopens there. bash, zsh, fish and nushell panes tell Orca their folder at every prompt. A pane whose login shell is plain sh, dash or busybox ash never did, so after a restart it reopened in the starting folder. Now it reports too.

What Changed

Before: the WSL bridge launch (buildWslInteractiveLoginShellCommand) ran sh/dash/ash as a bare exec … -l. Nothing reported the folder.

After: three pieces, all inside the WSL bridge only.

  1. New wrapper file. sh/env is added to the host-published, content-addressed wrapper tree (local-pty-shell-ready-wrapper-fileset.ts), next to bash's rcfile. The content is SH_WSL_ENV_FILE in wsl-shell-cwd-report.ts.
  2. Bridge case. A new sh|dash|ash) case saves the user's own ENV (if set) as ORCA_WSL_USER_ENV and exports ENV pointing at that file. It only does this when the file exists and the root contains no $, backtick or backslash; the shell expands ENV's value, so such a root would be mangled. Otherwise the pane starts exactly as before.
  3. What the file does (an interactive sh reads $ENV once, after /etc/profile and ~/.profile):
    • first sets ENV back to the user's value, or unsets it, so child processes see the user's own ENV; then sources it. The value is expanded through a here-document, as the shell itself expands ENV. That way a quote, $ or space in it is never parsed as shell syntax;
    • then, only when WSL_DISTRO_NAME is set, prefixes PS1 with $(__orca_wsl_cwd_report). For bash-as-sh ($BASH_VERSION) and busybox ash ($BB_ASH_VERSION), the prefix sits inside \[ \], so its invisible bytes don't count toward the prompt width and long lines wrap correctly. Both honour \[ \]; I checked Alpine's and Debian's busybox 1.36.1 (fancy prompt, on in busybox's default config) and bash --posix. dash has no line editor to miscount, and it would print \[ literally, so it stays bare. That function percent-encodes $PWD byte by byte, with the same unreserved set as bash/zsh/fish, and prints ESC ]7;file://…BEL. The user's own prompt is kept after it, and it's applied once.

Why

dash has no rcfile flag and no prompt hook. ENV is the only startup hook an interactive POSIX sh gives, and $(...) in PS1 is the only per-prompt hook. I checked both in docker. dash expands $(...) in PS1 on 0.5.8 (Ubuntu 16.04/18.04, Debian 9), 0.5.10 (20.04), 0.5.11 (22.04) and 0.5.12 (24.04), and so do busybox ash (Alpine 3.20) and bash-as-sh (Fedora 40).

The file lives in the published wrapper tree rather than being written into the distro, which is how bash's rcfile already reaches WSL. The cost is one command substitution (a subshell) per prompt; dash has nothing cheaper.

Fail-safe when the file is gone. Wrapper roots are content-addressed under userData and never pruned. An updated Orca writes a new root and leaves the old one, so a long-lived shell or a tmux session keeps a valid ENV path. After an uninstall that removes userData, a nested interactive sh started from an old pane finds ENV pointing at a missing file. dash 0.5.8–0.5.12, busybox ash and bash-as-sh all start silently in that case, with no "can't open". A shell that's already running keeps its in-memory function and prompt.

Known limits:

  • If ~/.profile itself exports ENV, ours is replaced: no report, and nothing clobbered. In that case ORCA_WSL_USER_ENV stays set, holding only the user's own former ENV. Nothing of ours runs after the profile to unset it, since ENV was our only hook.
  • A busybox built without its fancy-prompt option would show \[ \] literally. Alpine's and Debian's builds have it on.
  • Resetting PS1 later in a session drops the report.
  • A nested interactive sh gets the user's ENV, not ours, so it doesn't report while it's open; the outer pane reports again at its next prompt.

Linked Issue

N/A (internal WSL flag-on checklist: gaps in folder reporting).

Visual Proof

N/A: no UI. The effect is that a restored sh/dash pane reopens in the folder it was in.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

New src/main/wsl-sh-cwd-report.node-pty.test.ts, added to the "Test real shell contracts" CI job (ubuntu-24.04-arm, where /bin/sh is dash 0.5.12). The test is excluded from the sharded unit lane, as is the fish WSL pty test. Edits to the sh hook, its test and the bridge launch now trigger that job (SHELL_PREFIXES). That list moved to config/scripts/pr-shell-contract-prefixes.mjs to keep the scope script under its line limit.

  • Real /bin/sh, dash and busybox ash (whichever are installed), each launched through the actual bridge command under a pty. The user's PS1 is '$PWD "x" \$ ' and the user's ENV is $HOME/u "q" sp/env. Inside WSL, each:
    • reports at every prompt, including deep er/déjà a%b#c?d. Reports are read through the daemon's parseFileUriPath with wslDistro, as a real pane is;
    • sources the user's ENV with no syntax error, and children see it;
    • keeps the user's prompt after the prefix, with no literal \[.
  • Same shells, no WSL. With no user ENV and outside WSL, there are no reports and children see ENV unset.
  • sh -c. A non-interactive sh -c never reads the file.
  • Missing file. /bin/sh and dash start quietly when the ENV file is gone.
  • Launch. The bridge exports ENV at the published file and saves the user's raw value ($HOME/.shrc). It leaves ENV alone when the root contains $.

3 cases fail with the bridge change reverted, and 2 fail with the earlier eval-quoted env file.

Docker matrix (manual, using the real generated file): ubuntu 16.04/18.04/20.04/22.04/24.04 dash, debian 9 dash, alpine 3.20 ash, fedora 40 sh. Re-run after the quoting fix with ENV='$HOME/u "q" sp/env'. Each passes four checks:

  • cd "/tmp/a b é%#?" reports file:///tmp/a%20b%20%C3%A9%25%23%3F;
  • the user's ENV is sourced and children see it;
  • with no user ENV, children see it unset;
  • sh -c stays plain, and a missing ENV file starts silently.

pnpm tc, pnpm run typecheck:ci, pnpm run check:code-quality:changed, the anti-slop lint, ast-grep and the related wrapper/bridge/shell suites pass. The one exception is zsh-deferred-startup-line-init.live-shell.test.ts, which fails identically on main on this machine. Not run on Windows.

Flag-off: this applies to WSL bridge panes whose login shell is sh, dash or ash. Other shells and non-WSL panes are untouched.
User-risk: low. It only adds a prompt prefix that prints nothing visible, only inside WSL. The user's ENV is honoured and handed back, and a missing file is silent.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Status

Ready for review (two reviewers). Not merged.

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 (or CI will cover; local preferred)

…ery prompt

bash, zsh, fish and nushell panes already tell the terminal daemon their
folder; a bridge pane whose login shell is sh, dash or busybox ash did
not, so restores fell back to the starting folder.

dash has no rcfile flag or prompt hook, but an interactive sh reads $ENV
after ~/.profile, and dash 0.5.8+ (plus ash and bash-as-sh) expand $(...)
in PS1. The bridge now points ENV at a new sh/env file in the published
wrapper tree, saving the user's own ENV. That file hands ENV back to the
user's value (so children see theirs), sources it, and inside WSL only
prefixes PS1 with the report. A root containing $, ` or \ is skipped,
since the shell expands ENV's value.

A non-interactive sh -c never reads ENV, and a missing file (Orca
updated away or uninstalled) is silently ignored by dash, ash and bash.
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The change adds an ENV-file hook that reports WSL working directories for interactive sh-family shells. The shell launch setup publishes and selects the hook while preserving a user's existing ENV value. New PTY tests cover shell behavior and bridge launch. CI path filters, sparse checkout, test commands, and scope checks now include the hook and its test coverage.

Priority: Normal

Merge Risk: Low · up to a7dd0

The new prompt-by-prompt folder reporting for WSL sh-family shells is mostly sound. Two rare edge cases in how a user's existing ENV startup file is restored could skip or misresolve that file at pane startup. Fixing them before or shortly after merge is low effort and the exposure is small.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: OSC 7 folder reporting for WSL sh, dash, and ash panes.
Description check Passed The description covers the required sections and provides detailed user impact, implementation details, rationale, limitations, testing, and compatibility considerations. The linked issue is marked N/…
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.
Full details: Description check

Explanation

The description covers the required sections and provides detailed user impact, implementation details, rationale, limitations, testing, and compatibility considerations. The linked issue is marked N/A and some checklist items remain unchecked, but the description is otherwise complete and directly related to the changes.

Full details: Docstring Coverage

Explanation

Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 11 files. (2 skipped: 2 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The latest changes appear safe to merge; the earlier newline-filename issue remains non-blocking.

Findings

  1. P2 Startup filenames lose newline content ▶

Summary

Adds folder reports at each prompt for WSL bridge panes running sh, dash, or ash.

  • WSL sh-family panes report their current folder at every prompt.
  • Shell-related changes now run the real-shell contract checks in CI.

Reviews (4) · Last reviewed commit: "ci: list the shell-contract prefix modul..." · Reviewed by Greptile

Comment thread src/main/wsl-shell-cwd-report.ts Resolved
…mpt width

- The user's ENV is expanded through a here-document, so a value with a
  quote, $ or space no longer breaks startup with a syntax error.
- bash-as-sh and busybox ash (fancy prompt) get the report inside \[ \]
  so its invisible bytes don't count toward the prompt width; dash has no
  line editor to miscount and would print \[ literally, so it stays bare.
- Tests: a user ENV of `$HOME/u "q" sp/env`, a user PS1 with $, a quote
  and a backslash, and reports read through the daemon's WSL parser.
- CI: edits to the sh hook and the bridge launch trigger the shell
  contracts job (its prefix list moves to its own module, keeping the
  scope script under its line limit), and the sh and fish WSL pty tests
  leave the unit shards.
Comment thread config/scripts/pr-code-change-scope.mjs Resolved
Comment on lines +58 to +61
eval "IFS= read -r __orca_user_env <<__ORCA_USER_ENV_EOF
$ENV
__ORCA_USER_ENV_EOF
"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Startup filenames lose newline content

If the expanded ENV filename contains a newline, read -r keeps only its first line. The wrapper then skips the user's startup file or sources a different file at the shortened path. The previous assignment preserved newlines. Keep the entire expanded value rather than reading one line.

The detector job sparse-checks-out a fixed file list; the new
pr-shell-contract-prefixes.mjs that pr-code-change-scope.mjs imports was
missing from it, so the job failed with ERR_MODULE_NOT_FOUND. A contract
test now walks the scope script's local imports and requires each in
that list.
… modules are listed

Two config-script suites copy pr-code-change-scope.mjs and its sibling
modules into a fixture repo; without the new pr-shell-contract-prefixes.mjs
the copied script failed to load, and the detector fell back to running
everything. Also lists it with the scope script's other modules in the
mobile workflow trigger and the mobile non-test file set.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 59012df8-2850-42a8-aee6-78be3780e8bb
Commits

Reviewing files that changed from the base of the PR and between a0969d5 and a7dd012.

Files selected for processing: 13
  • .github/workflows/mobile.yml
  • .github/workflows/pr.yml
  • config/scripts/ci-unit-files.mjs
  • config/scripts/mobile-release-check-scope.test.mjs
  • config/scripts/mobile-test-change-scope.mjs
  • config/scripts/pr-auxiliary-preflight-admission.test.mjs
  • config/scripts/pr-code-change-scope-sparse-checkout.test.mjs
  • config/scripts/pr-code-change-scope.mjs
  • config/scripts/pr-shell-contract-prefixes.mjs
  • src/main/providers/local-pty-shell-ready-wrapper-fileset.ts
  • src/main/wsl-sh-cwd-report.node-pty.test.ts
  • src/main/wsl-shell-cwd-report.ts
  • src/shared/wsl-login-shell-command.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

Comment on lines +58 to +61
eval "IFS= read -r __orca_user_env <<__ORCA_USER_ENV_EOF
$ENV
__ORCA_USER_ENV_EOF
"

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.

Minor · Stability & Availability · Quick win

Supported by static analysis

Script executed:

sed -n 36,110p src/main/wsl-shell-cwd-report.ts
sed -n 75,115p src/shared/wsl-login-shell-command.ts

Repository: stablyai/orca

Length of output: 3755


Script executed:

set -o pipefail
printf '%s\n' '--- wsl-shell-cwd-report.ts ---'
nl -ba src/main/wsl-shell-cwd-report.ts | sed -n '42,108p'
printf '%s\n' '--- wsl-login-shell-command.ts ---'
nl -ba src/shared/wsl-login-shell-command.ts | sed -n '1,135p'
printf '%s\n' '--- related references/tests ---'
rg -n -F --glob '*.{ts,tsx,md}' -e 'SH_WSL_ENV_FILE' -e 'ORCA_WSL_USER_ENV' -e 'wsl-shell-cwd-report' -e 'shell-contract' src tests docs || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 9845


Script executed:

printf '%s\n' '--- node-pty bridge tests ---'
nl -ba src/main/wsl-sh-cwd-report.node-pty.test.ts | sed -n '1,235p'
printf '%s\n' '--- bridge file consumers ---'
nl -ba src/main/providers/local-pty-shell-ready-wrapper-fileset.ts | sed -n '1,90p'
rg -n -F --glob '*.{ts,tsx,md}' -e 'user ENV' -e 'ENV value' -e 'ENV file' -e '__ORCA_USER_ENV_EOF' src tests docs || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 13955


Preserve ENV values that contain the here-document delimiter.

SH_WSL_ENV_FILE inserts the expanded ENV value into an eval here-document. If the value contains a line equal to __ORCA_USER_ENV_EOF, that line closes the here-document. The remaining text is parsed as bridge commands, and the prefix becomes a different pathname.

This is not an additional security-boundary crossing because ENV already expands as a shell startup-script hook. It is a narrow startup-correctness defect. Use a collision-safe restoration method that preserves the expanded ENV value without allowing its contents to terminate the here-document.

__ORCA_USER_ENV_EOF
"
if [ -r "$__orca_user_env" ]; then
. "$__orca_user_env"

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.

Minor · Functional Correctness · Quick win

Source a checked relative ENV path directly.

If the user's ENV is init and init is readable in the current directory, the -r check succeeds. . "$__orca_user_env" can then search PATH instead of opening that checked file. The user's startup commands may not run, or a different init file may run. Prefix slash-free relative paths with ./ after resolving the value. The dot builtin's PATH lookup differs from the shell's documented use of the file named by ENV. (gnu.org)

@nwparker
nwparker merged commit a50a44b into main Oct 29, 2026
74 of 75 checks passed
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