fix(session): restore pane cwd when OSC 7 reports the local hostname - #537
Merged
Merged
Conversation
cwd_from_working_dir() converted the saved working_dir URL with url::Url::to_file_path(), which on unix refuses any host other than empty or "localhost". OSC 7 is conventionally reported as file://$HOST$PWD with the real local hostname, so every pane's saved cwd failed conversion and restored panes spawned in $HOME. Treat file URLs whose host matches this machine's hostname (full or first label, case-insensitive, optional trailing dot) as local by stripping the host before conversion. Any other host still fails, so a remote cwd cannot leak into a local spawn.
|
@dufu1991 is attempting to deploy a commit to the Faberon Team on Vercel. A member of the Team first needs to authorize it. |
Rewrite a verified local hostname to localhost so the url crate can convert the saved file URL back into a path. Share the exact hostname policy with AI context handling and reject ambiguous short-name aliases from nested SSH sessions.
Owner
|
@dufu1991 Thanks for tracking down the OSC 7 restore case and adding the initial coverage. I tightened hostname validation so a same-named host inside a regular SSH session is not treated as local, and the fix is now merged. It is available in the latest Nightly: https://github.com/tw93/Kaku/releases/download/nightly/Kaku-nightly.dmg |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Session restore reopens tabs/splits correctly, but every pane lands in
$HOME.last_session.jsonsaves each pane'sworking_dir, butcwd_from_working_dir()converts it withurl::Url::to_file_path(), which on unix refuses any host other than empty orlocalhost(verified against theurlcrate source:None | Some(Host::Domain("localhost")) => None,_ => return Err(())).OSC 7 is conventionally reported as
file://$HOST$PWD— WezTerm's own shell integration does exactly this — and the snapshot stores the URL verbatim. Verified live on macOS: emitting\033]7;file://<hostname>.local/tmp/x\033\\into a pane makeskaku cli listreport exactly that URL, and every entry in a reallast_session.jsonshows the same shape (file://df-macbook-pro-14.local/Users/...). All of them failto_file_path()->cwd_for_restore()returnsNone-> panes spawn at the default cwd.The ssh-domain branch of
cwd_for_restore()already special-cases thisto_file_path()limitation for remote hosts; local panes hit the same wall when the OSC 7 host is the local hostname.Fix
In
cwd_from_working_dir(), treat afile://URL whose host identifies this machine as local: strip the host before callingto_file_path().$HOST,hostname, andscutil --get LocalHostNamedisagree on whether the domain part is included).Tests
restore_cwd_local_domain_requires_local_urlwith alocalhostcase; the remote-host rejection case is unchanged.restore_cwd_local_domain_accepts_local_hostname: real hostname (uppercased to prove case-insensitivity), short hostname, and trailing-dot FQDN. The hostname is read at runtime, so the test is machine-independent.Verification
make fmt-checkpasses.cargo test --locked -p kaku-gui session_restorecovers the new and existing restore-cwd tests (cold full-workspace build is slow on the author's machine; the checks workflow covers fmt/check/tests on the PR).中文摘要
问题:会话恢复后所有 pane 都打开在
$HOME。快照里保存的working_dir是带本机真实主机名的file://URL(OSC 7 的惯例格式file://$HOST$PWD),而恢复端cwd_from_working_dir()调用的url::Url::to_file_path()在 unix 上拒绝任何非空、非localhost的 host,导致路径转换失败、pane 以默认目录启动。ssh 分支之前已经针对这个限制做过处理,但本地 pane 在 host 是本机主机名时撞上了同一堵墙。修复:转换前把"本机主机名"(全名或首段、忽略大小写、容忍 FQDN 尾点)识别为本地并剥离 host;其他 host 依旧拒绝,保留"远程路径不得泄漏进本地 spawn"的防护。附带覆盖本机主机名三种形态的单元测试,并通过
make fmt-check。