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): a WSL bridge shell reports its folder, so restores follow cd - #35385
In a WSL terminal opened from a \\wsl.localhost\… project, Orca didn't know which folder the shell was in. If you ran cd deep and then the distro stopped or Orca quit, the restored terminal came back with its history but in the project root. The shell now tells Orca its folder every time it changes, so a restored terminal reopens where you left it.
What Changed
Before (verify-18 e): cd deep, then wsl --terminate, quit and relaunch. History is restored, but the pane reopens at the project root.
Bridge bash and zsh send no OSC 7, so the terminal daemon's emulator never learned the folder.
After: the checkpoint follows cd, and the pane reopens in deep.
Mechanism:
New __orca_wsl_cwd_report in src/main/wsl-shell-cwd-report.ts, with a bash and a zsh version.
It prints ESC ]7;file://<path> BEL for $PWD at every prompt, only when WSL_DISTRO_NAME is set. The path is encoded only when it changed since the last prompt; otherwise the cached encoding is re-sent.
The path is percent-encoded byte by byte as UTF-8, under LC_ALL=C / no_multibyte. Bytes are masked with & 255 so bash 3.2's signed chars encode correctly.
bash: the shell-ready rcfile, which bridge bash already runs via --rcfile from ORCA_SHELL_READY_ROOT, calls it from __orca_osc133_precmd. That function is already composed into PROMPT_COMMAND ahead of the user's own hooks and keeps $?.
zsh: the local ZDOTDIR wrapper (wslCwdReports: true in the local spec) defines it. The deferred init adds it to precmd_functions inside WSL and runs it once for the first prompt.
Which wrapper a bridge pane runs: the daemon's own bridge spawn uses these local wrappers, not the daemon's Unix fileset.
buildWslShellArgs then calls ensureShellReadyWrappersAt(), which writes buildLocalShellReadyWrapperFiles at getShellReadyWrapperRoot().
addOrcaWslInteropEnv sets ORCA_SHELL_READY_ROOT to that same root and passes it to the guest as /p.
The guest login command sources ${ORCA_SHELL_READY_ROOT}/bash/rcfile or sets ZDOTDIR=${ORCA_SHELL_READY_ROOT}/zsh.
daemon-shell-ready-wrapper-fileset.ts is used only for the daemon's non-Windows spawns.
pty-subprocess-wsl-cwd-report.test.ts checks this through the daemon's createPtySubprocess.
daemon: no change. It already parses OSC 7 into a WSL pane's \\wsl.localhost\<distro>\… path (TerminalOscCwdTitleScanner with wslDistro), and the checkpoint takes the emulator's folder.
Why
Why OSC 7: it's the standard way a shell reports its folder. The daemon already consumes it, so no new channel or guest probe is needed.
What it fixes: every checkpoint is now current, so a terminate, a quit, or a Sleep whose guest read times out (the p8 "first Sleep times out" branch) no longer falls back to the spawn folder.
Coexistence:
A user prompt that already emits OSC 7 (e.g. vte.sh) just reports the same folder twice; the daemon keeps the last one.
A foreign OSC 7, for example from an ssh session that exits back to this shell, is corrected at the next prompt because the report is re-sent every prompt.
The user's PROMPT_COMMAND / precmd_functions are kept; the test checks a user prompt hook still runs.
Cost: on a prompt where the folder didn't change, one printf of the cached string. On a change, one loop over the path's bytes inside the shell. No subprocess either way.
Scope:
Only inside WSL (WSL_DISTRO_NAME), so macOS/Linux local panes are unchanged.
The daemon's own bash rcfile (mac/Linux daemon spawns and hosted WSL) is unchanged.
Known gaps (these panes keep today's behaviour, the spawn folder plus the Sleep probe):
fish: bridge fish gets no Orca wrapper today.
Unwrapped shells: sh, dash, nushell and any other login shell the bridge execs without a wrapper. Also a wrapper root that is missing in the guest, where the login command falls back to exec "$shell" -l.
The features.length === 0 path in getShellLaunchConfig: a Linux Orca running inside WSL opens bash/zsh unwrapped when no startup features are selected, so those panes report nothing. Bridge panes don't go through that check; they always pick the wrapper by path.
Spelling of /mnt/c: OSC 7 reports a folder under /mnt/c/... as the UNC path \\wsl.localhost\<distro>\mnt\c\..., while the Sleep probe and the spawn path spell it as a drive path (C:\...). Both open the same folder; only the stored string differs.
Alternatives considered:
Polling the guest's /proc: costs a wsl.exe per poll, and it can't run once the distro is gone.
A wider Sleep read budget: doesn't help terminate or quit.
Flag-off: not behind the WSL hosts gate. Bridge panes exist with it off, and this applies to them with the gate on or off.
User risk: low.
Inside WSL, the shell prints one OSC 7 sequence when its folder changes; terminals ignore it visually.
Restores now reopen in the last folder instead of the project root. If that folder was deleted, the existing deleted-folder fallback still opens the requested folder.
Linked Issue
Internal: verify-18 item (e); also covers the p8 Sleep→Wake "read timed out" branch.
Visual Proof
N/A. This is restore behaviour; verify-18 will re-check (e) on awin.
Testing
Not yet run on awin.
wsl-shell-cwd-report.test.ts (real shells, skipped where missing):
bash with the real rcfile reports at every prompt: the start folder, …/deep er/déjà a%b#c (space, unicode, %, #), the same again after cd .. After a foreign /elsewhere report, the next prompt reports …/deep er/déjà a%b#c again. The user's PROMPT_COMMAND still runs.
Passes with bash 5.3 and macOS bash 3.2.
bash outside WSL adds no reports of its own.
zsh 5.9 with the real ZDOTDIR wrapper reports the same sequence.
Each report parses to the right \\wsl.localhost\Ubuntu\… path.
pty-subprocess-wsl-cwd-report.test.ts: a daemon-spawned bridge pane points the guest at an ORCA_SHELL_READY_ROOT whose bash rcfile and zsh .zshenv both carry __orca_wsl_cwd_report.
daemon-pty-adapter-wsl-sleep-cwd.test.ts: with the distro unreadable, a checkpoint carries the folder the shell last reported (deep er\déjà), not the spawn folder.
pnpm tc:node, oxlint, pnpm run check:code-quality:changed and the ast-grep gate pass. The providers/daemon/zsh suites pass (3,910). Two pre-existing local failures also fail on main here: zsh-deferred-startup-line-init.live-shell (3) and pty-runtime-hidden-at-spawn-mark.
AI Disclosure
Written with Claude Code.
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.
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)
Bridge bash and zsh send no OSC 7, so the terminal daemon's emulator and every checkpoint kept
the spawn folder until a Sleep read the shell's folder in the distro. A terminate, a quit or a
timed-out read reopened the pane at the project root (verify-18 e). The bash rcfile and zsh
wrapper now report the folder at each prompt where it changed, only inside WSL, percent-encoded;
the daemon already reads OSC 7 into a WSL pane's UNC path.
Co-Authored-By: Claude <noreply@anthropic.com>
Adds prompt-time folder reports for WSL bridge bash and zsh shells so existing checkpoints can follow cd.
WSL bridge terminals restore the folder you last used.
Diagram
sequenceDiagram
participant Shell as WSL bash or zsh
participant Daemon as Terminal daemon
participant Checkpoint as Saved checkpoint
Shell->>Daemon: OSC 7 with encoded current folder
Daemon->>Daemon: Convert Linux folder to WSL path
Daemon->>Checkpoint: Save reported folder
Bash and zsh startup hooks now report changed WSL working directories through OSC 7. The reports encode path characters for a file:// URI and are emitted only when WSL is detected. Tests cover shell report behavior and shutdown checkpointing from a reported directory.
Priority: Normal
Merge Risk: Low · previous review fde11
Some WSL panes may restore to the previous folder when a prompt hook changes directories. This is a bounded edge case.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 0.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. Documentat…
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 summarizes the primary change: WSL bridge shells report their current folder so restored terminals follow directory changes.
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.
Description check
The description is complete and closely follows the repository template. It explains the user impact, implementation, rationale, scope, known gaps, testing, AI use, and visual-proof status. The linked…
Full details: Description check
Explanation
The description is complete and closely follows the repository template. It explains the user impact, implementation, rationale, scope, known gaps, testing, AI use, and visual-proof status. The linked issue is identified as an internal verify-18 item, and the author clearly reports that awin testing and some full checks remain incomplete. The optional Review and Notes headings are not included, but the required information is covered elsewhere.
Full details: Docstring Coverage
Explanation
Docstring coverage is 0.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 3 functions across 6 files.
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Report the folder after user prompt hooks.
__orca_osc133_precmd runs before the user's PROMPT_COMMAND. If that command changes directories, OSC 7 reports the previous folder. A checkpoint taken before the next prompt then restores the wrong folder. Move the report to a prompt hook that runs after the user command.
set -o pipefail
printf'%s\n''--- reporter ---'
sed -n '1,90p' src/main/wsl-shell-cwd-report.ts
printf'%s\n''--- user zshenv source block ---'
sed -n '1,100p' src/main/shell-templates.ts
printf'%s\n''--- deferred line-init block ---'
sed -n '1,220p' src/main/zsh-deferred-startup-line-init.ts
printf'%s\n''--- wrapper generation tests around zsh ordering ---'
sed -n '230,330p' src/main/providers/local-pty-shell-ready-wrapper-generation.test.ts
printf'%s\n''--- all direct user-hook references ---'
rg -n -F --glob '*.ts' -e 'precmd_functions+=' -e 'precmd_functions=(' -e 'precmd()' -e 'precmd_functions' src/main | head -160
Repository: stablyai/orca
Length of output: 17310
Web query:
zsh official documentation precmd_functions execution order
Result:
<source_evidence>
<source kind="open_page">
<title>9 Functions (zsh)</title>
<location>https://zsh.sourceforge.io/Doc/Release/Functions.html</location>
<excerpt>citeturn1view0 [wordlim: 200] Crawled: today; Content type: text/html; Source: open({"ref_id":"turn0search0","lineno":null}); Total lines: 204
L12: ## 9.1 Autoloading Functions 【2†¶】
L13:
L18: The usual alias expansion during reading will be suppressed if the `autoload` builtin or its equivalent is given the option `-U`. This is recommended for the use of functions supplied with the zsh distribution. Note that for functions precompiled with the `zcompile` builtin command the flag `-U` must be provided when the `.zwc` file is created, as the corresponding information is compiled into the latter.
L19: For each `element` in `fpath`, the shell looks for three possible files, the newest of which is used to load the definition for the function:
L20:
L21: `element``.zwc`
L22: A file created with the `zcompile` builtin command, which is expected to contain the definitions for all functions in the directory named `element`. The file is treated in the same manner as a directory containing files for functions and is searched for the definition of the function. If the definition is not found, the search for a definition proceeds with the other two possibilities described below.
L23: If `element` already includes a `.zwc` extension (i.e. the extension was explicitly given by the user), `element` is searched for the definition of the function without comparing its age to that of other files; in fact, there does not need to be any directory named `element` without the suffix.
L24: Thus including an element such as ‘`/usr/local/funcs.zwc`’ in `fpath` will speed up the search for functions, with the disadvantage that functions included must be explicitly recompiled by hand before the shell notices any changes.
L25: `element``/``function``.zwc`
L26:
L27:
L28: A file created with `zcompile`, which is expected to contain the definition for `function`. It may include other function definitions as well, but those are neither loaded nor executed; a file found in this way is searched only for the definition of `function`.
L29:
L30: `element``/``function`
L31:
L32:
L33: A file of zsh command text, taken to be the definition for `function`.
L34: In summary, the order of searching is, first, in the parents of directories in `fpath` for the newer of either a compiled directory or a directory in `fpath`; second, if more than one of these contains a definition for the function that is sought, the leftmost in the `fpath` is chosen; and third, within a directory, the newer of either a compiled function or an ordinary function definition is used.
L35: If the `KSH_AUTOLOAD` option is set, or the file contains only a simple definition of the function, the file’s contents will be executed. This will normally define the function in question, but may also perform initialization, which is executed in the context of the function execution, and may therefore define local parameters. It is an error if the function is not defined by loading the file.
L36: Otherwise, the function body (with no surrounding ‘`funcname``() {``...``}`’) is taken to be the complete contents of the file. This form allows the file to be used directly as an executable shell script. If processing of the file results in the function being re-defined, the function itself is not re-executed.
L37: To force the shell to perform initialization and then call the function defined, the file should contain initialization code (which will be executed then discarded) in addition to a complete function definition (which will be retained for subsequent calls to the function), and a call to the shell function, including any arguments, at the end.
L38: For example, suppose the autoload file `func` contains
L39:
L40: func() { print This is func; }
L41: print func is initialized
L42:
L43:
L44: then ‘`func; func`’ with `KSH_AUTOLOAD` set will produce both messages on the first call, but only the message ‘`This is func`’ on the second and subsequent calls. Without `KSH_AUTOLOAD` set, it will produce the initialization message on the first call, and the other message on the second and subsequent calls.
L45: It is also possible to create a function that is not marked as autoloaded, but which loads its own definition by searching `fpath`, by using ‘`autoload -X`’ within a shell function. For example, the following are equivalent:
L46:
L47: myfunc() {
L48: autoload -X
L49: }
L50: myfunc args...
L51:
L52:
L53: and
L54:
L55: unfunction myfunc # if myfunc was defined
L56: autoload myfunc
L57: myfunc args...
L58: In fact, the `functions` command outputs ‘`builtin autoload -X`’ as the body of an autoloaded function. This is done so that
L59:
L60: eval "$(functions)"
L61:
L62:
L63: produces a reasonable result. A true autoloaded function can be identified by the presence of the comment ‘`# undefined`’ in the body, because all comments are discarded from defined functions.
L64:
L65: To load the definition of an autoloaded function `myfunc` without executing `myfunc`, use:
L66:
L67: autoload +X myfunc
L68:
L69:
L70: * * *
L71: [ 【8†<<】 ] | [ 【2†<】 ] | [ 【8†Up】 ] | [ 【10†>】 ] | [ 【3†>>】 ] | | | | | [【1†Top】] | [【4†Contents】] | [【5†Index】] | [ 【6†?】 ]
L72: ## 9.2 Anonymous Functions 【9†¶】
L73:
L74: If no name is given for a function, it is ‘anonymous’ and is handled specially. Either form of function definition may be used: a ‘`()`’ with no preceding name, or a ‘`function`’ with an immediately following open brace. The function is executed immediately at the point of definition and is not stored for future use. The function name is set to ‘`(anon)`’.
L75: Arguments to the function may be specified as words following the closing brace defining the function, hence if there are none no arguments (other than `$0`) are set. This is a difference from the way other functions are parsed: normal function definitions may be followed by certain keywords such as ‘`else`’ or ‘`fi`’, which will be treated as arguments to anonymous functions, so that a newline or semicolon is needed to force keyword interpretation.
L76: Note also that the argument list of any enclosing script or function is hidden (as would be the case for any other function called at this point).
L77:
L78: Redirections may be applied to the anonymous function in the same manner as to a current-shell structure enclosed in braces. The main use of anonymous functions is to provide a scope for local variables. This is particularly convenient in start-up files as these do not provide their own local variable scope.
L79: For example,
L80:
L81: variable=outside
L82: function {
L83: local variable=inside
L84: print "I am $variable with arguments $*"
L85: } this and that
L86: print "I am $variable"
L87:
L88:
L89: outputs the following:
L90:
L91: I am inside with arguments this and that
L92: I am outside
L93: Note that function definitions with arguments that expand to nothing, for example ‘`name=; function $name { ``...`` }`’, are not treated as anonymous functions. Instead, they are treated as normal function definitions where the definition is silently discarded.
L94:
L95: * * *
L96:
L97: [ 【8†<<】 ] | [ 【9†<】 ] | [ 【8†Up】 ] | [ 【11†>】 ] | [ 【3†>>】 ] | | | | | [【1†Top】] | [【4†Contents】] | [【5†Index】] | [ 【6†?】 ]
L98: ## 9.3 Special Functions 【10†¶】
L99:
L100: Certain functions, if defined, have special meaning to the shell.
L101:
L102: * * *
L103:
L104: [ 【8†<<】 ] | [ 【10†<】 ] | [ 【10†Up】 ] | [ 【12†>】 ] | [ 【3†>>】 ] | | | | | [【1†Top】] | [【4†Contents】] | [【5†Index】] | [ 【6†?】 ]
L105: ### 9.3.1 Hook Functions 【11†¶】
L106: For the functions below, it is possible to define an array that has the same name as the function with ‘`_functions`’ appended. Any element in such an array is taken as the name of a function to execute; it is executed in the same context and with the same arguments and same initial value of `$?` as the basic function.
L107: For example, if `$chpwd_functions` is an array containing the values ‘`mychpwd`’, ‘`chpwd_save_dirstack`’, then the shell attempts to execute the functions ‘`chpwd`’, ‘`mychpwd`’ and ‘`chpwd_save_dirstack`’, in that order. Any function that does not exist is silently ignored. A function found by this mechanism is referred to elsewhere as a hook function. An error in any function causes subsequent functions not to be run.
L108: Note further that an error in a `precmd` hook causes an immediately following `periodic` function not to run (though it may run at the next opportunity).
L109: `chpwd` 【13†¶】
L110:
L111:
L112: Executed whenever the current working directory is changed.
L113:
L114: `periodic` 【14†¶】
L115:
L116:
L117: If the parameter `PERIOD` is set, this function is executed every `$PERIOD` seconds, just before a prompt. Note that if multiple functions are defined using the array `periodic_functions` only one period is applied to the complete set of functions, and the scheduled time is not reset if the list of functions is altered. Hence the set of functions is always called together.
L118:
L119: `precmd` 【15†¶】
L120: Executed before each prompt. Note that precommand functions are not re-executed simply because the command line is redrawn, as happens, for example, when a notification about an exiting job is displayed.
L121:
L122: `preexec` 【16†¶】
L123: Executed just after a command has been read and is about to be executed. If the history mechanism is active (regardless of whether the line was discarded from the history buffer), the string that the user typed is passed as the first argument, otherwise it is an empty string.
L124: The actual command that will be executed (including expanded aliases) is passed in two different forms: the second argument is a single-line, size-limited version of the command (with things like function bodies elided); the third argument contains the full text that is being executed.
L125: `zshaddhistory` 【17†¶】
L126:
L127:
L128: Executed when a history line has been read interactively, but before it is executed. The sole argument is the complete history line (so that any terminating newline will still be present).
L129: If any of the hook functions returns status 1 (or any non-zero value other than 2, though this is not guaranteed for future versions of the shell) the history line will not be saved, although it lingers in the history until the next line is executed, allowing you to reuse or edit it immediately.
L130:
L131: If any of the hook functions returns status 2 the history line will be saved on the internal history list, but not written to the history file. In case of a conflict, the first non-zero status value is taken.
L132: A hook function may call ‘`fc -p` `...`’ to switch the history context so that the history is saved in a different file from that in the global `HISTFILE` parameter. This is handled specially: the history context is automatically restored after the processing of the history line is finished.
L133: The following example function works with one of the options `INC_APPEND_HISTORY` or `SHARE_HISTORY` set, in order that the line is written out immediately after the history entry is added. It first adds the history line to the normal history with the newline stripped, which is usually the correct behaviour. Then it switches the history context so that the line will be written to a history file in the current directory.
L134:
L135: zshaddhistory() {
L136: print -sr -- ${1%%$'\n'}
L137: fc -p .zsh_local_history
L138: }
L139: `zshexit` 【18†¶】
L140:
L141:
L142: Executed at the point where the main shell is about to exit normally. This is not called by exiting subshells, nor when the `exec` precommand modifier is used before an external command. Also, unlike `TRAPEXIT`, it is not called when functions exit.
L143:
L144: * * *
L145:
L146: [ 【8†<<】 ] | [ 【11†<】 ] | [ 【10†Up】 ] | [ 【3†>】 ] | [ 【3†>>】 ] | | | | | [【1†Top】] | [【4†Contents】] | [【5†Index】] | [ 【6†?】 ]
L147: ### 9.3.2 Trap Functions 【12†¶】
L148:
L149: The functions below are treated specially but do not have corresponding hook arrays.
L150:
L151: `TRAP``NAL` 【19†¶】
L152:
L153:
L154: If defined and non-null, this function will be executed whenever the shell catches a signal `SIG``NAL`, where `NAL` is a signal name as specified for the `kill` builtin. The signal number will be passed as the first parameter to the function.
L155:
L156: If a function of this form is defined and null, the shell and processes spawned by it will ignore `SIG``NAL`.
L157: The return status from the function is handled specially. If it is zero, the signal is assumed to have been handled, and execution continues normally. Otherwise, the shell will behave as interrupted except that the return status of the trap is retained.
L158: Programs terminated by uncaught signals typically return the status 128 plus the signal number. Hence the following causes the handler for `SIGINT` to print a message, then mimic the usual effect of the signal.
L159:
L160: TRAPINT() {
L161: print "Caught SIGINT, aborting."
L162: return $(( 128 + $1 ))
L163: }
L164:
L165:
L166: The functions `TRAPZERR`, `TRAPDEBUG` and `TRAPEXIT` are never executed inside other traps.
L167:
L168: `TRAPDEBUG` 【20†¶】
L169: If the option `DEBUG_BEFORE_CMD` is set (as it is by default), executed before each command; otherwise executed after each command. See the description of the `trap` builtin in 【21†Shell Builtin Commands】 for details of additional features provided in debug traps.
L170:
L171: `TRAPEXIT` 【22†¶】
L172:
L173:
L174: Executed when the shell exits, or when the current function exits if defined inside a function. The value of `$?` at the start of execution is the exit status of the shell or the return status of the function exiting.
L175: `TRAPZERR` 【23†¶】
L176:
L177:
L178: Executed whenever a command has a non-zero exit status. However, the function is not executed if the command occurred in a sublist followed by ‘`&&`’ or ‘`||`’; only the final command in a sublist of this type causes the trap to be executed. The function `TRAPERR` acts the same as `TRAPZERR` on systems where there is no `SIGERR` (this is the usual case).
L179: The functions beginning ‘`TRAP`’ may alternatively be defined with the `trap` builtin: this may be preferable for some uses. Setting a trap with one form removes any trap of the other form for the same signal; removing a trap in either form removes all traps for the same signal. The forms
L180:
L181: TRAPNAL() {
L182: # code
L183: }
L184:
L185:
L186: (’function traps’) and
L187:
L188: trap '
L189: # code
L190: ' NAL
L191:
L192:
L193: (’list traps’) are equivalent in most ways, the exceptions being the following:
</excerpt>
</source>
<source kind="open_page">
<title>26 User Contributions (zsh)</title>
<location>https://zsh.sourceforge.io/Doc/Release/User-Contributions.html</location>
<excerpt>citeturn1view1 [wordlim: 200] Crawled: today; Content type: text/html; Source: open({"ref_id":"turn0search2","lineno":null}); Total lines: 3302
L138: `all`
L139:
L140:
L141: Output everything listed below.
L142:
L143: `aliases`
L144:
L145:
L146: Output alias definitions.
L147:
L148: `bindings`
L149:
L150:
L151: Output ZLE key maps and bindings.
L152:
L153: `completion`
L154:
L155:
L156: Output old-style `compctl` commands. New completion is covered by `functions` and `zstyles`.
L157:
L158: `functions`
L159:
L160:
L161: Output autoloads and function definitions.
L162:
L163: `limits`
L164:
L165:
L166: Output `limit` commands.
L167:
L168: `options`
L169:
L170:
L171: Output `setopt` commands.
L172:
L173: `styles`
L174:
L175:
L176: Same as `zstyles`.
L177:
L178: `variables`
L179: Output shell parameter assignments, plus `export` commands for any environment variables.
L180:
L181: `zstyles`
L182:
L183:
L184: Output `zstyle` commands.
L185:
L186: If the `state` is omitted, `all` is assumed.
L187:
L188: With the exception of ‘`all`’, every `state` can be abbreviated by any prefix, even a single letter; thus `a` is the same as `aliases`, `z` is the same as `zstyles`, etc.
L189:
L190: * * *
L191:
L192: [ 【9†<<】 ] | [ 【28†<】 ] | [ 【10†Up】 ] | [ 【11†>】 ] | [ 【4†>>】 ] | | | | | [【2†Top】] | [【5†Contents】] | [【6†Index】] | [ 【7†?】 ]
L193: ### 26.2.5 Manipulating Hook Functions 【29†¶】
L194:
L195: `add-zsh-hook` [ `-L` | `-dD` ] [ `-Uzk` ] `hook` `function` 【33†¶】
L196: Several functions are special to the shell, as described in the section Special Functions, 【34†Functions】, in that they are automatically called at specific points during shell execution. Each has an associated array consisting of names of functions to be called at the same point; these are so-called ‘hook functions’. The shell function `add-zsh-hook` provides a simple way of adding or removing functions from the array.
L197: `hook` is one of `chpwd`, `periodic`, `precmd`, `preexec`, `zshaddhistory`, `zshexit`, or `zsh_directory_name`, the special functions in question. Note that `zsh_directory_name` is called in a different way from the other functions, but may still be manipulated as a hook.
L198:
L199: `function` is name of an ordinary shell function. If no options are given this will be added to the array of functions to be executed in the given context. Functions are invoked in the order they were added.
L200: If the option `-L` is given, the current values for the hook arrays are listed with `typeset`.
L201:
L202: If the option `-d` is given, the `function` is removed from the array of functions to be executed.
L203:
L204: If the option `-D` is given, the `function` is treated as a pattern and any matching names of functions are removed from the array of functions to be executed.
L205: The options `-U`, `-z` and `-k` are passed as arguments to `autoload` for `function`. For functions contributed with zsh, the options `-Uz` are appropriate.
L206:
L207: `add-zle-hook-widget` [ `-L` | `-dD` ] [ `-Uzk` ] `hook` `widgetname` 【35†¶】
L208: Several widget names are special to the line editor, as described in the section Special Widgets, 【36†Zle Widgets】, in that they are automatically called at specific points during editing. Unlike function hooks, these do not use a predefined array of other names to call at the same point; the shell function `add-zle-hook-widget` maintains a similar array and arranges for the special widget to invoke those additional widgets.
L209: `hook` is one of `isearch-exit`, `isearch-update`, `line-pre-redraw`, `line-init`, `line-finish`, `history-line-set`, or `keymap-select`, corresponding to each of the special widgets `zle-isearch-exit`, etc. The special widget names are also accepted as the `hook` argument.
L210: `widgetname` is the name of a ZLE widget. If no options are given this is added to the array of widgets to be invoked in the given hook context. Widgets are invoked in the order they were added, with
L211:
L212: `zle ``widgetname`` -Nw -f "nolast" -- "$@"`
L213:
L214:
L215: Note that this means that the ‘`WIDGET`’ special parameter tracks the `widgetname` when the widget function is called, rather than tracking the name of the corresponding special hook widget.
L216: If the option `-d` is given, the `widgetname` is removed from the array of widgets to be executed.
L217:
L218: If the option `-D` is given, the `widgetname` is treated as a pattern and any matching names of widgets are removed from the array.
L219: If `widgetname` does not name an existing widget when added to the array, it is assumed that a shell function also named `widgetname` is meant to provide the implementation of the widget. This name is therefore marked for autoloading, and the options `-U`, `-z` and `-k` are passed as arguments to `autoload` as with `add-zsh-hook`. The widget is also created with ‘`zle -N ``widgetname`’ to cause the corresponding function to be loaded the first time the hook is called.
L220: The arrays of `widgetname` are currently maintained in `zstyle` contexts, one for each `hook` context, with a style of ‘`widgets`’. If the `-L` option is given, this set of styles is listed with ‘`zstyle -L`’. This implementation may change, and the special widgets that refer to the styles are created only if `add-zle-hook-widget` is called to add at least one widget, so if this function is used for any hooks, then all hooks should be managed only via this function.
L221:
L222: * * *
L223: [ 【9†<<】 ] | [ 【29†<】 ] | [ 【9†Up】 ] | [ 【37†>】 ] | [ 【4†>>】 ] | | | | | [【2†Top】] | [【5†Contents】] | [【6†Index】] | [ 【7†?】 ]
L224: ## 26.3 Remembering Recent Directories 【38†¶】
L225: The function `cdr` allows you to change the working directory to a previous working directory from a list maintained automatically. It is similar in concept to the directory stack controlled by the `pushd`, `popd` and `dirs` builtins, but is more configurable, and as it stores all entries in files it is maintained across sessions and (by default) between terminal emulators in the current session. Duplicates are automatically removed, so that the list reflects the single most recent use of each directory.
L226: Note that the `pushd` directory stack is not actually modified or used by `cdr` unless you configure it to do so as described in the configuration section below.
L227:
L228: * * *
L229:
L230: [ 【9†<<】 ] | [ 【11†<】 ] | [ 【11†Up】 ] | [ 【39†>】 ] | [ 【4†>>】 ] | | | | | [【2†Top】] | [【5†Contents】] | [【6†Index】] | [ 【7†?】 ]
L231: ### 26.3.1 Installation 【37†¶】
L232:
L233: The system works by means of a hook function that is called every time the directory changes. To install the system, autoload the required functions and use the `add-zsh-hook` function described above:
L234:
L235: autoload -Uz chpwd_recent_dirs cdr add-zsh-hook
L236: add-zsh-hook chpwd chpwd_recent_dirs
L237:
L238:
L239: Now every time you change directly interactively, no matter which command you use, the directory to which you change will be remembered in most-recent-first order.
L240:
L241: * * *
</excerpt>
</source>
<source kind="search">
<title>9 Functions (zsh)</title>
<location>https://zsh.sourceforge.io/Doc/Release/Functions.html</location>
<excerpt>citeturn0search0 [wordlim: 200] Crawled: 3 months ago; A file of zsh command text, taken to be the definition for `function`. ... This will normally define the function in question, but may also perform initialization, which is executed in the context of the function execution, and may therefore define local parameters. ... For example, if `$chpwd_functions` is an array containing the values ‘`mychpwd`’, ‘`chpwd_save_dirstack`’, then the shell attempts to execute the functions ‘`chpwd`’, ‘`mychpwd`’ and ‘`chpwd_save_dirstack`’, in that order. ... Note further that an error in a `precmd` hook causes an immediately following `periodic` function not to run (though it may run at the next opportunity).
`chpwd` ¶
Executed whenever the current working directory is changed.
`periodic` ¶
If the parameter `PERIOD` is set, this function is executed every `$PERIOD` seconds, just before a prompt. Note that if multiple functions are defined using the array `periodic_functions` only one period is applied to the complete set of functions, and the scheduled time is not reset if the list of functions is altered. Hence the set of functions is always called together.
`precmd` ¶
Executed before each prompt. Note that precommand functions are not re-executed simply because the command line is redrawn, as happens, for example, when a notification about an exiting job is displayed.
`preexec` ¶
Executed just after a command has been read and is about to be executed. If the history mechanism is active (regardless of whether the line was discarded from the history buffer), the string that the user typed is passed as the first argument, otherwise it is an empty string. </excerpt>
</source>
<source kind="search">
<title>26 User Contributions (zsh)</title>
<location>https://zsh.sourceforge.io/Doc/Release/User-Contributions.html</location>
<excerpt>citeturn0search2 [wordlim: 200] Crawled: 3 months ago; The shell function `add-zsh-hook` provides a simple way of adding or removing functions from the array.
`hook` is one of `chpwd`, `periodic`, `precmd`, `preexec`, `zshaddhistory`, `zshexit`, or `zsh_directory_name`, the special functions in question. ... Functions are invoked in the order they were added.
</excerpt>
</source>
<source kind="search">
<title>The Z Shell Manual (zsh)</title>
<location>https://zsh.sourceforge.io/Doc/Release/index.html</location>
<excerpt>citeturn0search1 [wordlim: 200] Published: 3 months ago; Crawled: 3 months ago; This Info file documents Zsh, a freely available UNIX command interpreter (shell), which of the standard shells most closely resembles the Korn shell (ksh), although it is not completely compatible. ... 8 Command Execution | ... 23 Calendar Function System |
</excerpt>
</source>
<omitted_sources count="24">Additional source records were omitted from this bounded result.</omitted_sources>
</source_evidence>
Citations:
- 1: https://zsh.sourceforge.io/Doc/Release/Functions.html
- 2: https://zsh.sourceforge.io/Doc/Release/User-Contributions.html
set -o pipefail
printf'%s\n''--- headless emulator scanner and snapshot binding ---'
sed -n '50,105p' src/main/daemon/headless-emulator.ts
sed -n '300,365p' src/main/daemon/headless-emulator.ts
rg -n -F --glob '*.ts' -e 'oscText.cwd' -e 'getSnapshot()' -e 'snapshot.cwd' -e 'checkpoint(session' src/main/daemon | head -160
printf'%s\n''--- changed zsh block with line numbers ---'
nl -ba src/main/zsh-startup-wrapper-builder.ts | sed -n '128,150p'
nl -ba src/main/wsl-shell-cwd-report.ts | sed -n '20,38p'
Repository: stablyai/orca
Length of output: 24027
Register the WSL reporter as a chpwd hook.
A user precmd hook can run after __orca_wsl_cwd_report and change directory. The reporter has already recorded and emitted the previous directory, and __orca_deferred_init has no later report. The emulator and subsequent checkpoint can therefore retain the previous directory until the next prompt.
The reason will be displayed to describe this comment to others. Learn more.
Folder report misses hook changes
The new report runs inside __orca_osc133_precmd, before the user's PROMPT_COMMAND hooks. If a user hook changes directories, Orca saves the folder from before that hook, not the folder where the prompt appears. Quitting or terminating WSL before another prompt can therefore restore the wrong folder.
Run the report after the user hooks while preserving the command's exit status.
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
In a WSL terminal opened from a
\\wsl.localhost\…project, Orca didn't know which folder the shell was in. If you rancd deepand then the distro stopped or Orca quit, the restored terminal came back with its history but in the project root. The shell now tells Orca its folder every time it changes, so a restored terminal reopens where you left it.What Changed
cd deep, thenwsl --terminate, quit and relaunch. History is restored, but the pane reopens at the project root.cd, and the pane reopens indeep.__orca_wsl_cwd_reportinsrc/main/wsl-shell-cwd-report.ts, with a bash and a zsh version.ESC ]7;file://<path> BELfor$PWDat every prompt, only whenWSL_DISTRO_NAMEis set. The path is encoded only when it changed since the last prompt; otherwise the cached encoding is re-sent.LC_ALL=C/no_multibyte. Bytes are masked with& 255so bash 3.2's signed chars encode correctly.--rcfilefromORCA_SHELL_READY_ROOT, calls it from__orca_osc133_precmd. That function is already composed intoPROMPT_COMMANDahead of the user's own hooks and keeps$?.wslCwdReports: truein the local spec) defines it. The deferred init adds it toprecmd_functionsinside WSL and runs it once for the first prompt.shell-launch-plan.ts(win32 branch) callsresolveWindowsShellLaunchArgs.buildWslShellArgsthen callsensureShellReadyWrappersAt(), which writesbuildLocalShellReadyWrapperFilesatgetShellReadyWrapperRoot().addOrcaWslInteropEnvsetsORCA_SHELL_READY_ROOTto that same root and passes it to the guest as/p.${ORCA_SHELL_READY_ROOT}/bash/rcfileor setsZDOTDIR=${ORCA_SHELL_READY_ROOT}/zsh.daemon-shell-ready-wrapper-fileset.tsis used only for the daemon's non-Windows spawns.pty-subprocess-wsl-cwd-report.test.tschecks this through the daemon'screatePtySubprocess.\\wsl.localhost\<distro>\…path (TerminalOscCwdTitleScannerwithwslDistro), and the checkpoint takes the emulator's folder.Why
PROMPT_COMMAND/precmd_functionsare kept; the test checks a user prompt hook still runs.printfof the cached string. On a change, one loop over the path's bytes inside the shell. No subprocess either way.WSL_DISTRO_NAME), so macOS/Linux local panes are unchanged.execs without a wrapper. Also a wrapper root that is missing in the guest, where the login command falls back toexec "$shell" -l.features.length === 0path ingetShellLaunchConfig: a Linux Orca running inside WSL opens bash/zsh unwrapped when no startup features are selected, so those panes report nothing. Bridge panes don't go through that check; they always pick the wrapper by path./mnt/c: OSC 7 reports a folder under/mnt/c/...as the UNC path\\wsl.localhost\<distro>\mnt\c\..., while the Sleep probe and the spawn path spell it as a drive path (C:\...). Both open the same folder; only the stored string differs./proc: costs awsl.exeper poll, and it can't run once the distro is gone.Flag-off: not behind the WSL hosts gate. Bridge panes exist with it off, and this applies to them with the gate on or off.
User risk: low.
Linked Issue
Internal: verify-18 item (e); also covers the p8 Sleep→Wake "read timed out" branch.
Visual Proof
N/A. This is restore behaviour; verify-18 will re-check (e) on awin.
Testing
wsl-shell-cwd-report.test.ts(real shells, skipped where missing):…/deep er/déjà a%b#c(space, unicode,%,#), the same again aftercd .. After a foreign/elsewherereport, the next prompt reports…/deep er/déjà a%b#cagain. The user'sPROMPT_COMMANDstill runs.\\wsl.localhost\Ubuntu\…path.pty-subprocess-wsl-cwd-report.test.ts: a daemon-spawned bridge pane points the guest at anORCA_SHELL_READY_ROOTwhose bash rcfile and zsh.zshenvboth carry__orca_wsl_cwd_report.daemon-pty-adapter-wsl-sleep-cwd.test.ts: with the distro unreadable, a checkpoint carries the folder the shell last reported (deep er\déjà), not the spawn folder.pnpm tc:node,oxlint,pnpm run check:code-quality:changedand the ast-grep gate pass. The providers/daemon/zsh suites pass (3,910). Two pre-existing local failures also fail on main here:zsh-deferred-startup-line-init.live-shell(3) andpty-runtime-hidden-at-spawn-mark.AI Disclosure
Written with Claude Code.
Agent skill upstream boundary
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)