fix(tui): preserve remote cwd for ssh sessions
This commit is contained in:
+25
-1
@@ -813,6 +813,30 @@ def _completion_cwd(params: dict | None = None) -> str:
|
||||
return os.getcwd()
|
||||
|
||||
|
||||
def _terminal_task_cwd(session: dict | None) -> str:
|
||||
"""Return the cwd that terminal_tool should use for this TUI session.
|
||||
|
||||
``_completion_cwd`` validates paths on the host so file completion does not
|
||||
point at nonsense. Non-local terminal backends are different: their cwd is
|
||||
inside the target environment, so an SSH path like /home/user/workspace may
|
||||
not exist on the local macOS host but is still the correct execution cwd.
|
||||
"""
|
||||
backend = (os.environ.get("TERMINAL_ENV") or "").strip().lower()
|
||||
if backend and backend != "local":
|
||||
raw = os.environ.get("TERMINAL_CWD", "").strip()
|
||||
if not raw:
|
||||
try:
|
||||
terminal_cfg = _load_cfg().get("terminal", {})
|
||||
if isinstance(terminal_cfg, dict):
|
||||
raw = str(terminal_cfg.get("cwd") or "").strip()
|
||||
except Exception:
|
||||
raw = ""
|
||||
if raw and raw not in {".", "auto", "cwd"}:
|
||||
return raw
|
||||
|
||||
return _session_cwd(session)
|
||||
|
||||
|
||||
def _git_branch_for_cwd(cwd: str) -> str:
|
||||
try:
|
||||
result = subprocess.run(
|
||||
@@ -851,7 +875,7 @@ def _register_session_cwd(session: dict | None) -> None:
|
||||
from tools.terminal_tool import register_task_env_overrides
|
||||
|
||||
register_task_env_overrides(
|
||||
session["session_key"], {"cwd": _session_cwd(session)}
|
||||
session["session_key"], {"cwd": _terminal_task_cwd(session)}
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user