From 8860a9478f168a8ab536781fd8afbe6e3c94ac12 Mon Sep 17 00:00:00 2001 From: wusp Date: Thu, 16 Apr 2026 20:35:53 +0800 Subject: [PATCH] fix: preserve configured cwd during environment bootstrap snapshot --- tools/environments/base.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/environments/base.py b/tools/environments/base.py index 19c3bf024ed24..0712b7b563244 100644 --- a/tools/environments/base.py +++ b/tools/environments/base.py @@ -293,8 +293,19 @@ def init_session(self): ``_snapshot_ready = True`` so subsequent commands source the snapshot instead of running with ``bash -l``. """ + requested_cwd = self.cwd or "." + quoted_cwd = ( + shlex.quote(requested_cwd) + if requested_cwd != "~" and not requested_cwd.startswith("~/") + else requested_cwd + ) + # Full capture: env vars, functions (filtered), aliases, shell options. + # IMPORTANT: enter the requested working directory before sampling pwd, + # otherwise login-shell startup defaults (often "/") overwrite the cwd + # passed in by ACP/terminal configuration. bootstrap = ( + f"cd {quoted_cwd} || exit 126\n" f"export -p > {self._snapshot_path}\n" f"declare -f | grep -vE '^_[^_]' >> {self._snapshot_path}\n" f"alias -p >> {self._snapshot_path}\n"