@zhangfengshun/dsh-remote-ssh 2.4.4 → 2.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  本文件的版本号与 `package.json` 的 `version` 保持一致。每个版本对应一个 Cordis Package 快照(`pkg-N`)。
4
4
 
5
+ ## [2.4.5] — 集成终端落在工作区远程目录(issue #7)+ 密码认证回退提示
6
+ ### 修复
7
+ - **「终端」页签现在落在工作区对应的远程目录**(感谢 @Linhaojing 的完整定位与验证矩阵):此前生成的 `dsh-remote-shell.js` 只拼 host/user/port/keyPath/proxyJump,`ssh -tt` 不带远程命令,交互式 shell 落在远程 `$HOME`;同一会话里出现「文件树在工作区目录、终端在 $HOME」的割裂。现在 wrapper 读取标记文件里**已有的** `remotePath` 并追加远程命令:
8
+ - `~`/`~/x` 的展开交给**远端** shell(`$HOME/...`)——本地 homedir 与远程不同,本地展开必错;
9
+ - `cd … 2>/dev/null || cd "$HOME"`:目标目录被删/改名时回退,终端仍可打开;
10
+ - `exec "${SHELL:-/bin/bash}" -l`:尊重远端登录 shell(zsh/fish 等),保持单进程与退出码语义;
11
+ - 无 `remotePath` 的旧标记文件不追加命令,行为与 2.4.5 之前完全一致(向后兼容)。
12
+ - **密码认证的远程工作区现在会明确提示**:集成终端仅支持密钥认证,此前静默回退为本地 shell,用户会误以为已连上远程;现在向 stderr 打印中英双语提示(本地工作区与密钥认证路径不受影响)。
13
+
14
+ ### 测试
15
+ - 新增 `tests/wrapper-terminal.test.mjs`:从 `lib/index.js` 提取**真实**的 wrapper 生成文本,用 CJS runner 桩掉 `child_process` 后捕获实际 spawn argv,覆盖 5 组场景(`~/子路径`、`~`、绝对路径、无 remotePath、非密钥认证)共 16 条断言。
16
+
5
17
  ## [2.4.4] — 文档结构补全(README 代码示例 / 兼容性矩阵 / 故障排查)
6
18
  ### 文档
7
19
  - **新增「代码示例」章节**(中英双语):6 组可直接照抄的示例——远程命令(含 `timeoutMs`)、文件读写、长时任务与挂起恢复(`timeoutMs: 0` / `remote_ssh_kill`)、远程工作区内的免参调用、`~/.ssh/config` 导入、镜像 sync/push,并给出真实返回值形状。
package/README.md CHANGED
@@ -12,7 +12,7 @@
12
12
  | --- | --- |
13
13
  | 🔌 SSH 连接 | 密钥 / 密码认证,ProxyJump 跳板机,`~/.ssh/config` 一键导入 |
14
14
  | 📂 远程文件 | 内置「文件」页签直接 SSH 读写远程文件,无需同步 |
15
- | 💻 远程终端 | 内置「终端」页签自动检测远程工作区,SSH 交互式终端 |
15
+ | 💻 远程终端 | 内置「终端」页签自动检测远程工作区,SSH 交互式终端,**落在工作区对应的远程目录**(与 VSCode Remote-SSH 一致) |
16
16
  | 🌐 远程工作区 | 选择远程目录创建原生工作区,一键进入远程环境 |
17
17
  | 🤖 模型工具 | 13 个 `remote_ssh_*` 工具,会话感知免填连接参数;命令级超时 + `remote_ssh_kill` 兜底恢复 |
18
18
  | ⚡ 打开提速 | 单往返合并读 + raw 文本快路径 + 结果缓存(LRU + 5s TTL):首开 ≈**1.31×**,TTL 内重复打开 **0 往返**,过期复验 **≈5×**(真实超算实测);`remote_ssh_exec` 连接复用 **≈15×** |
@@ -45,7 +45,7 @@
45
45
  **一条命令安装**(无需 token、API Key 或额外配置):
46
46
 
47
47
  ```bash
48
- dsh plugin --profile <name> add @zhangfengshun/dsh-remote-ssh@2.4.4
48
+ dsh plugin --profile <name> add @zhangfengshun/dsh-remote-ssh@2.4.5
49
49
  ```
50
50
 
51
51
  安装后**重启 DSH**。`@zhangfengshun/dsh-remote-ssh` 必须在 bundles 列表中排在 `dsh-better-sidebar` **之后**。
@@ -64,7 +64,7 @@ dsh plugin --profile <name> remove @zhangfengshun/dsh-remote-ssh
64
64
 
65
65
  1. **设置 → 远程连接** → 添加连接(主机 / 端口 / 用户 / 密钥)→ 点「测试连接」验证;已有 `~/.ssh/config` 可直接一键导入
66
66
  2. **添加工作区** → 选「选择远程目录…」→ 选连接 → 浏览并选择远程目录(该目录会成为原生 DSH 工作区)
67
- 3. 进入该工作区会话:内置「文件」页签直接显示远程文件(编辑保存直写远程),「终端」页签自动 SSH 到远程主机(仅密钥认证)
67
+ 3. 进入该工作区会话:内置「文件」页签直接显示远程文件(编辑保存直写远程),「终端」页签自动 SSH 到该工作区的**远程目录**(仅密钥认证)
68
68
 
69
69
  **会话内直接对模型说**(远程工作区会话中免填连接参数):
70
70
 
@@ -185,7 +185,8 @@ dsh plugin --profile <name> remove @zhangfengshun/dsh-remote-ssh
185
185
  | 「测试连接」报 `Permission denied (publickey)` | ① 私钥**带口令**:插件以批处理模式运行(`BatchMode=yes`),无法交互输口令——先用 `ssh-add` 加载,或去掉密钥口令;② Windows host 且用户在 Administrators 组时,公钥须写入 `C:\ProgramData\ssh\administrators_authorized_keys`;③ 用户名的写法(`user` / `.\user` / `user@domain`)要与手动连接一致 |
186
186
  | 从 git-bash 启动 `dsh web` 后密钥认证失败 | 2.3.9 起已修复:Windows 下 ssh 解析固定为系统 OpenSSH 绝对路径(此前会误用 Git 自带的 MSYS2 ssh) |
187
187
  | 侧边栏文件页签显示「这类内容还没有可用的查看方式。」 | `dsh-better-sidebar` 主机半边未加载:0.18.1 / 0.19.0 / 0.19.1 在 DSH Desktop 上会因 `SessionLogOffset` 运行时导入失败——降到 0.18.0 或使用修复版(上游 PR [#641](https://github.com/omdsh-dev/DSH-better-sidebar/pull/641)) |
188
- | 内置「终端」页签连不上 | 终端为 `ssh -tt` 交互式通道,**仅支持密钥认证**;密码认证请改用「文件」页签与模型工具 |
188
+ | 内置「终端」页签连不上 | 终端为 `ssh -tt` 交互式通道,**仅支持密钥认证**;密码认证的连接会回退为本地 shell 并打印一行提示(避免把本地 shell 误认为已连上远程),密码认证请改用「文件」页签与模型工具 |
189
+ | 终端落在远程 `$HOME` 而不是工作区目录 | 2.4.5 起已修复(wrapper 会 `cd` 到工作区 `remotePath`,目录不存在时回退 `$HOME`);若仍停在 `$HOME`,确认 2.4.5 已装入并重启 DSH |
189
190
  | 安装时提示 `minimumReleaseAge` 或「No matching version」(刚发布) | npm 供应链新鲜度策略,等 1–5 分钟后重试即可 |
190
191
  | 命令卡住不返回 | 默认 120s 超时后自动丢弃会话;长时任务用 `timeoutMs: 0`,随时可用 `remote_ssh_kill` 强杀 |
191
192
  | 大文件读取被截断 | 单文件读取上限 4MB、下载池化路径约 6.29MB(更大自动回落一次性连接);用 `remote_ssh_exec` + `head`/`tail` 分段处理 |
package/README_EN.md CHANGED
@@ -12,7 +12,7 @@ A **DSH** plugin like **VSCode Remote-SSH**: connect to remote HPC / servers via
12
12
  | --- | --- |
13
13
  | 🔌 SSH Connection | Key / password auth, ProxyJump bastion, one-click import from `~/.ssh/config` |
14
14
  | 📂 Remote Files | Built-in **Files** tab reads/writes remote files directly via SSH — no sync needed |
15
- | 💻 Remote Terminal | Built-in **Terminal** tab auto-detects remote workspaces, opens SSH interactive shell |
15
+ | 💻 Remote Terminal | Built-in **Terminal** tab auto-detects remote workspaces, opens an SSH interactive shell **in the workspace's remote directory** (like VSCode Remote-SSH) |
16
16
  | 🌐 Remote Workspace | Select a remote directory to create a native workspace, one-click enter |
17
17
  | 🤖 Model Tools | 13 `remote_ssh_*` tools, session-aware with auto-filled connection params; command-level timeout + `remote_ssh_kill` recovery |
18
18
  | ⚡ Faster Opens | Single-roundtrip merged reads + raw text fast path + result cache (LRU + 5s TTL): first open ≈**1.31×**, repeat opens within TTL **0 round-trips**, expired revalidation **≈5×** (measured on a real HPC); `remote_ssh_exec` connection reuse **≈15×** |
@@ -45,7 +45,7 @@ A **DSH** plugin like **VSCode Remote-SSH**: connect to remote HPC / servers via
45
45
  **One command** (no token, API key or extra configuration needed):
46
46
 
47
47
  ```bash
48
- dsh plugin --profile <name> add @zhangfengshun/dsh-remote-ssh@2.4.4
48
+ dsh plugin --profile <name> add @zhangfengshun/dsh-remote-ssh@2.4.5
49
49
  ```
50
50
 
51
51
  **Restart DSH** after installation. `@zhangfengshun/dsh-remote-ssh` must come **after** `dsh-better-sidebar` in the bundles list.
@@ -64,7 +64,7 @@ dsh plugin --profile <name> remove @zhangfengshun/dsh-remote-ssh
64
64
 
65
65
  1. **Settings → Remote SSH** → Add a connection (host / port / user / key) → Click "Test Connection"; an existing `~/.ssh/config` can be imported in one click
66
66
  2. **Add Workspace** → Choose "Select Remote Directory…" → Pick a connection → Browse and select a remote directory (it becomes a native DSH workspace)
67
- 3. Inside that workspace session: the built-in **Files** tab shows remote files (edits save straight back to remote), and the **Terminal** tab auto-SSHes to the host (key auth only)
67
+ 3. Inside that workspace session: the built-in **Files** tab shows remote files (edits save straight back to remote), and the **Terminal** tab auto-SSHes **into the workspace's remote directory** (key auth only)
68
68
 
69
69
  **Just ask the model** (connection params are auto-filled inside a remote-workspace session):
70
70
 
@@ -185,7 +185,8 @@ The plugin never patches DSH sources or injects into the profile dependency tree
185
185
  | "Test Connection" reports `Permission denied (publickey)` | ① key has a **passphrase**: the plugin runs in batch mode (`BatchMode=yes`) and cannot prompt — load it with `ssh-add` first, or strip the passphrase; ② on a Windows host where the user is in Administrators, the public key must go to `C:\ProgramData\ssh\administrators_authorized_keys`; ③ the username spelling (`user` / `.\user` / `user@domain`) must match a manual connection |
186
186
  | Key auth fails after launching `dsh web` from git-bash | Fixed in 2.3.9: on Windows the ssh binary is pinned to the system OpenSSH absolute path (previously Git's MSYS2 ssh was picked up) |
187
187
  | Sidebar Files tab says "Nothing here can view this kind of content yet." | `dsh-better-sidebar` host half failed to load: 0.18.1 / 0.19.0 / 0.19.1 hit the `SessionLogOffset` runtime import on DSH Desktop — downgrade to 0.18.0 or use a fixed build (upstream PR [#641](https://github.com/omdsh-dev/DSH-better-sidebar/pull/641)) |
188
- | Built-in Terminal tab cannot connect | The terminal is an `ssh -tt` interactive channel and supports **key auth only**; use the Files tab and the model tools for password auth |
188
+ | Built-in Terminal tab cannot connect | The terminal is an `ssh -tt` interactive channel and supports **key auth only**; password-auth profiles fall back to a local shell and now print a one-line notice (so a local shell is not mistaken for a remote one) — use the Files tab and the model tools for password auth |
189
+ | Terminal opens in the remote `$HOME` instead of the workspace directory | Fixed in 2.4.5 (the wrapper `cd`s into the workspace `remotePath`, falling back to `$HOME` when it no longer exists); if it still starts in `$HOME`, make sure 2.4.5 is installed and DSH restarted |
189
190
  | Install fails with `minimumReleaseAge` or "No matching version" right after a release | npm supply-chain freshness policy — retry after 1–5 minutes |
190
191
  | A command hangs forever | The 120s timeout discards the pooled session automatically; use `timeoutMs: 0` for long jobs and `remote_ssh_kill` at any time |
191
192
  | Large files are truncated | 4MB per read, ≈6.29MB on the pooled download path (larger files fall back to a one-shot connection); use `remote_ssh_exec` with `head`/`tail` to page through |
package/lib/index.js CHANGED
@@ -1947,8 +1947,9 @@ function apply(ctx, config) {
1947
1947
  });
1948
1948
 
1949
1949
  // ---- 创建 shell wrapper(供 better-sidebar 的 shell 配置指向它,实现远程终端透明接入)----
1950
- // wrapper 逻辑:读取当前工作目录下的 .remote-ssh.json,若存在且含 keyPath → exec ssh -tt
1951
- // 否则降级到平台默认 shell(bash -l / powershell)。
1950
+ // wrapper 逻辑:读取当前工作目录下的 .remote-ssh.json,若存在且含 keyPath → exec ssh -tt
1951
+ // (并把终端 cd 到该工作区的 remotePath,与 VSCode Remote-SSH 行为一致);
1952
+ // 否则降级到平台默认 shell(bash -l / powershell)——远程工作区但非密钥认证时打一行提示。
1952
1953
  // 实现方式:跨平台 Node.js 脚本 + 平台特定的薄壳调用它。
1953
1954
  const wrapperDir = join(homedir(), ".dsh", "remote-ssh");
1954
1955
  const isWin = process.platform === "win32";
@@ -1971,10 +1972,23 @@ function apply(ctx, config) {
1971
1972
  " // ExitOnForwardFailure=no:ssh config 里的 RemoteForward 端口被占时终端仍能打开",
1972
1973
  " const args = ['-tt', '-o', 'StrictHostKeyChecking=no', '-o', 'ExitOnForwardFailure=no', '-p', String(port), '-i', j.keyPath, j.user + '@' + j.host];",
1973
1974
  " if (j.proxyJump) { args.splice(2, 0, '-J', j.proxyJump); }",
1975
+ " // 终端落在工作区对应的远程目录(issue #7:此前不带远程命令,落点是远程 $HOME)。",
1976
+ " // remotePath 的 ~ 必须交给【远端】shell 展开——本地 homedir 与远程不同,本地展开必错;",
1977
+ " // cd 失败(目录被删/改名)回退 $HOME,保证终端仍能打开;",
1978
+ " // exec 让远端只留一个交互式登录 shell,退出码语义与之前一致。",
1979
+ " const remotePath = typeof j.remotePath === 'string' ? j.remotePath.trim() : '';",
1980
+ " if (remotePath !== '') {",
1981
+ " const expanded = remotePath === '~' ? '$HOME' : (remotePath.indexOf('~/') === 0 ? '$HOME/' + remotePath.slice(2) : remotePath);",
1982
+ " args.push('cd \"' + expanded + '\" 2>/dev/null || cd \"$HOME\"; exec \"${SHELL:-/bin/bash}\" -l');",
1983
+ " }",
1974
1984
  " const ssh = spawn(sshBin, args, { stdio: 'inherit' });",
1975
1985
  " ssh.on('exit', function(c) { process.exit(c == null ? 0 : c); });",
1976
1986
  " return;",
1977
1987
  " }",
1988
+ " // 远程工作区但该连接不是密钥认证(如密码认证,keyPath 为空):集成终端仅支持",
1989
+ " // 密钥认证,这里显式提示一行,避免用户把本地 shell 误认为已连上远程。",
1990
+ " process.stderr.write('[dsh-remote-ssh] 检测到远程工作区,但该连接不是密钥认证:集成终端仅支持密钥认证,已回退为本地 shell。\\n');",
1991
+ " process.stderr.write('[dsh-remote-ssh] remote workspace detected, but this profile is not key-authenticated; the integrated terminal only supports key auth and fell back to a local shell.\\n');",
1978
1992
  " }",
1979
1993
  "} catch (e) {}",
1980
1994
  "// 默认本地 shell",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhangfengshun/dsh-remote-ssh",
3
- "version": "2.4.4",
3
+ "version": "2.4.5",
4
4
  "description": "DSH web plugin: VSCode Remote-SSH-like remote development (SSH to supercomputers/servers, remote workspace, file explorer, integrated terminal), integrated with dsh-better-sidebar and DSH settings.",
5
5
  "keywords": [
6
6
  "dsh",