You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(wsl): bridge sh/dash/ash panes report their folder (OSC 7) at every prompt - #35597
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.
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.
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.
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.
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: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
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 checks: 4 passed
Check name
Status
Explanation
Title check
The title clearly and concisely describes the main change: OSC 7 folder reporting for WSL sh, dash, and ash panes.
Description check
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
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
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.
…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.
The reason will be displayed to describe this comment to others. Learn more.
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
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.
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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,dashor busyboxashnever did, so after a restart it reopened in the starting folder. Now it reports too.What Changed
Before: the WSL bridge launch (
buildWslInteractiveLoginShellCommand) ransh/dash/ashas a bareexec … -l. Nothing reported the folder.After: three pieces, all inside the WSL bridge only.
sh/envis added to the host-published, content-addressed wrapper tree (local-pty-shell-ready-wrapper-fileset.ts), next to bash'srcfile. The content isSH_WSL_ENV_FILEinwsl-shell-cwd-report.ts.sh|dash|ash)case saves the user's ownENV(if set) asORCA_WSL_USER_ENVand exportsENVpointing at that file. It only does this when the file exists and the root contains no$, backtick or backslash; the shell expandsENV's value, so such a root would be mangled. Otherwise the pane starts exactly as before.$ENVonce, after/etc/profileand~/.profile):ENVback to the user's value, or unsets it, so child processes see the user's ownENV; then sources it. The value is expanded through a here-document, as the shell itself expandsENV. That way a quote,$or space in it is never parsed as shell syntax;WSL_DISTRO_NAMEis set, prefixesPS1with$(__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$PWDbyte by byte, with the same unreserved set as bash/zsh/fish, and printsESC ]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.
ENVis the only startup hook an interactive POSIX sh gives, and$(...)inPS1is 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
ENVpointing 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:
~/.profileitself exportsENV, ours is replaced: no report, and nothing clobbered. In that caseORCA_WSL_USER_ENVstays set, holding only the user's own formerENV. Nothing of ours runs after the profile to unset it, since ENV was our only hook.\[ \]literally. Alpine's and Debian's builds have it on.PS1later in a session drops the report.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
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/shis 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 toconfig/scripts/pr-shell-contract-prefixes.mjsto keep the scope script under its line limit./bin/sh, dash and busybox ash (whichever are installed), each launched through the actual bridge command under a pty. The user'sPS1is'$PWD "x" \$ 'and the user'sENVis$HOME/u "q" sp/env. Inside WSL, each:deep er/déjà a%b#c?d. Reports are read through the daemon'sparseFileUriPathwithwslDistro, as a real pane is;ENVwith no syntax error, and children see it;\[.ENVand outside WSL, there are no reports and children seeENVunset.sh -c. A non-interactivesh -cnever reads the file./bin/shand dash start quietly when theENVfile is gone.ENVat the published file and saves the user's raw value ($HOME/.shrc). It leavesENValone 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 é%#?"reportsfile:///tmp/a%20b%20%C3%A9%25%23%3F;ENVis sourced and children see it;ENV, children see it unset;sh -cstays plain, and a missingENVfile 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 iszsh-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
ENVis honoured and handed back, and a missing file is silent.Agent skill upstream boundary
Status
Ready for review (two reviewers). Not merged.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)