dsh-remote 1.2.0 → 1.3.0

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/README.en.md CHANGED
@@ -12,7 +12,7 @@ Maintained by [@flymysql](https://github.com/flymysql) · [Homepage](https://fly
12
12
 
13
13
  ![dsh-remote — remote projects, complete context](https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workspace-overview.png)
14
14
 
15
- Turn SSH hosts into everyday development workspaces in [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness): manage projects across hosts, browse and edit remote files, search names and contents, use terminals and inspect Git diffs. Agents read and write files, run commands, build and test in their assigned remote workspace. Multiple workspaces can run independently in parallel.
15
+ Turn SSH hosts into everyday development workspaces in [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness): manage projects across hosts, browse and edit remote files, search names and contents, use terminals, inspect Git diffs and open local/reverse port tunnels. Agents read and write files, run commands, build and test in their assigned remote workspace. Multiple workspaces can run independently in parallel.
16
16
 
17
17
  Use the normal layout or choose the optional **three-column IDE layout** to view remote files, the editor and the native Agent conversation side by side. Switching layouts retains tasks and unsaved edits.
18
18
 
@@ -28,7 +28,7 @@ After installation or an upgrade, restart DSH Web and refresh the page. Check au
28
28
 
29
29
  ## Start in 3 steps
30
30
 
31
- 1. **Configure a host**: open Settings → Remote workspaces to edit SSH configuration or save credentials. Connectivity checks run automatically; no manual connection step is required.
31
+ 1. **Configure a host**: open Settings → Remote workspaces to edit SSH configuration or save credentials. Hosts already in `~/.ssh/config` are listed there — open the row's `…` menu and choose **Edit** to save it as a machine and fill in its login password (the entry is the same `…` menu before and after saving). Connectivity checks run automatically; no manual connection step is required.
32
32
  2. **Create a workspace**: Add workspace → Remote, then choose a host and folder. Each workspace binds its own host; settings have no folder selection or global active host.
33
33
  3. **Develop remotely**: open workspace files or enter IDE mode to edit with syntax highlighting, search, run commands and collaborate with the agent. Files open ready to edit.
34
34
 
@@ -60,6 +60,14 @@ The terminal starts in the session's remote directory. A pixel fish welcomes you
60
60
 
61
61
  <img src="https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-terminal.png" alt="Native remote terminal with pixel fish and actual SSH command output" width="1000"/>
62
62
 
63
+ ### Port forwarding (SSH tunnels)
64
+
65
+ Open the listener on the side that initiates the connection: a listener here is a local forward (`ssh -L`); one on the remote is a reverse forward (`ssh -R`). Run several at once. Each forward names its **host**, so you can define a tunnel for a machine that is not connected yet and start it once that machine is. Every forward can be edited in place — direction, ports, target or owning host; a running one is stopped first and restarted with the new settings. Tick auto reconnect per row to restore only the forwards that were running, scoped to their machine — enabling it for a reverse forward first warns that the remote will listen again.
66
+
67
+ Upgrading from an older version: auto-reconnect entries that predate `lastActive` are paused and marked "Re-confirm" in the row; tick them again to opt back in (reverse forwards also need the remote-listening warning acknowledged).
68
+
69
+ <img src="docs/shots/port-forwards.png" alt="Port forwarding panel with local/reverse directions, per-row auto reconnect and the add form" width="900"/>
70
+
63
71
  ### Edit and build with the agent
64
72
 
65
73
  Tool cards show applied changes, actual exit codes and build output, with compiler diagnostics linking to source. Saving detects remote conflicts, preserves CRLF and protects newer input typed during the save.
@@ -74,7 +82,7 @@ Tool cards show applied changes, actual exit codes and build output, with compil
74
82
 
75
83
  ## Documentation and community
76
84
 
77
- [Full tool and configuration reference](https://github.com/flymysql/dsh-remote/blob/main/docs/reference.en.md) · [Troubleshooting](https://github.com/flymysql/dsh-remote/blob/main/docs/troubleshooting.md) · [Upgrade guide](https://github.com/flymysql/dsh-remote/blob/main/docs/migration-1.0.md) · [Changelog](https://github.com/flymysql/dsh-remote/blob/main/CHANGELOG.md)
85
+ [Full tool and configuration reference](https://github.com/flymysql/dsh-remote/blob/main/docs/reference.en.md) · [Troubleshooting](https://github.com/flymysql/dsh-remote/blob/main/docs/troubleshooting.md) · [Self-update recovery](https://github.com/flymysql/dsh-remote/blob/main/docs/self-heal.md) · [Upgrade guide](https://github.com/flymysql/dsh-remote/blob/main/docs/migration-1.0.md) · [Changelog](https://github.com/flymysql/dsh-remote/blob/main/CHANGELOG.md)
78
86
 
79
87
  [Homepage](https://flymysql.github.io/dsh-remote/) · [Discussions](https://github.com/flymysql/dsh-remote/discussions) · [Report an issue](https://github.com/flymysql/dsh-remote/issues) · [Contributing](https://github.com/flymysql/dsh-remote/blob/main/CONTRIBUTING.md) · [Contributors and credits](#contributors-and-credits)
80
88
 
package/README.md CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  ![dsh-remote —— 远程项目,完整上下文](https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workspace-overview.png)
14
14
 
15
- 在 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 中,把 SSH 主机变成日常开发工作区:管理多主机项目,浏览和编辑远程文件、递归搜索文件与内容、使用终端并查看 Git 差异;让 Agent 在所属远程工作区中读写文件、执行命令、构建和测试。多个工作区可独立并行。
15
+ 在 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) 中,把 SSH 主机变成日常开发工作区:管理多主机项目,浏览和编辑远程文件、递归搜索文件与内容、使用终端、查看 Git 差异、建立本地/反向端口隧道;让 Agent 在所属远程工作区中读写文件、执行命令、构建和测试。多个工作区可独立并行。
16
16
 
17
17
  可按习惯使用普通布局,或切换 **IDE 三栏布局**,并排查看远程文件、编辑器与原生 Agent 会话;切换时保留任务和未保存编辑。
18
18
 
@@ -28,7 +28,7 @@ dsh plugin --profile web add dsh-remote
28
28
 
29
29
  ## 3 步开始
30
30
 
31
- 1. **配置主机**:设置 → 远程工作区,编辑 SSH 配置或保存主机凭据;打开设置会自动检查连通性,无需手动“连接”。
31
+ 1. **配置主机**:设置 → 远程工作区,编辑 SSH 配置或保存主机凭据;直接写在 `~/.ssh/config` 里的 Host 会出现在主机列表中,点该行的「…」菜单 →「编辑」即可保存成机器并填写登录密码(保存前后入口都是同一个「…」菜单)。打开设置会自动检查连通性,无需手动“连接”。
32
32
  2. **创建工作区**:添加工作区 → 远程,选择主机与目录。每个工作区独立绑定主机,设置页不选目录或“当前远程机”。
33
33
  3. **开始开发**:打开工作区文件或切换 IDE 模式,文件打开即可编辑并显示语法高亮,在远端搜索、运行命令并与 Agent 协作。
34
34
 
@@ -60,6 +60,14 @@ dsh plugin --profile web add dsh-remote
60
60
 
61
61
  <img src="https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-terminal.png" alt="DSH 远程终端:像素鱼欢迎图与实际 SSH 命令输出" width="1000"/>
62
62
 
63
+ ### 端口转发(SSH 隧道)
64
+
65
+ 谁要发起访问,就在谁那边开监听口:监听口开在本机是本地转发(`ssh -L`),开在远端是远程转发(`ssh -R`)。可同时运行多条;添加转发时可以选择「主机」,每条转发只属于一台机器——给还没连接的主机也能先存下转发,连上后再启动。每条转发都可以点「编辑」调整方向、端口、目标或所属主机,运行中的会先停止、保存后按新配置重新启动。每行能直接勾选「自动重连」——只恢复上次运行中的转发,且按机器隔离,反向转发首次勾选会提示远端监听风险。
66
+
67
+ 从旧版本升级:旧版没有 `lastActive` 的「自动重连」配置会暂停,行上显示「需重新确认」;重新勾选后才会参与自动恢复(反向转发需重新确认远端监听)。
68
+
69
+ <img src="docs/shots/port-forwards.png" alt="端口转发面板:本地/反向方向、自动重连勾选框与添加转发表单" width="900"/>
70
+
63
71
  ### 与 Agent 一起修改和构建
64
72
 
65
73
  工具卡展示已应用改动、实际退出码和构建输出,编译诊断可跳转源码。编辑器保存会检测远端冲突、保留 CRLF,并保护保存期间继续输入的内容。
@@ -74,7 +82,7 @@ dsh plugin --profile web add dsh-remote
74
82
 
75
83
  ## 文档与社区
76
84
 
77
- [完整工具与配置参考](https://github.com/flymysql/dsh-remote/blob/main/docs/reference.zh.md) · [排障](https://github.com/flymysql/dsh-remote/blob/main/docs/troubleshooting.md) · [升级指南](https://github.com/flymysql/dsh-remote/blob/main/docs/migration-1.0.md) · [更新记录](https://github.com/flymysql/dsh-remote/blob/main/CHANGELOG.md)
85
+ [完整工具与配置参考](https://github.com/flymysql/dsh-remote/blob/main/docs/reference.zh.md) · [排障](https://github.com/flymysql/dsh-remote/blob/main/docs/troubleshooting.md) · [自更新修复](https://github.com/flymysql/dsh-remote/blob/main/docs/self-heal.md) · [升级指南](https://github.com/flymysql/dsh-remote/blob/main/docs/migration-1.0.md) · [更新记录](https://github.com/flymysql/dsh-remote/blob/main/CHANGELOG.md)
78
86
 
79
87
  [主页](https://flymysql.github.io/dsh-remote/) · [讨论区](https://github.com/flymysql/dsh-remote/discussions) · [反馈问题](https://github.com/flymysql/dsh-remote/issues) · [贡献指南](https://github.com/flymysql/dsh-remote/blob/main/CONTRIBUTING.md) · [贡献者与致谢](#贡献者与致谢)
80
88
 
package/lib/binding.js CHANGED
@@ -11,7 +11,7 @@
11
11
  // `username`/`remotePath`) when the workspace is picked, so a session's cwd
12
12
  // alone identifies both the machine to connect to and the workspace root.
13
13
 
14
- import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
14
+ import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from 'node:fs'
15
15
  import path from 'node:path'
16
16
  import zlib from 'node:zlib'
17
17
 
@@ -19,8 +19,37 @@ import zlib from 'node:zlib'
19
19
  const norm = (p) => path.resolve(String(p || '')).replace(/[\\/]+$/, '') || ''
20
20
 
21
21
  /** Whether `base` is `dir` itself or nested under it (separator-aware, so
22
- * `/a/mirror-2` is NOT treated as living inside `/a/mirror`). */
23
- const isUnder = (base, dir) => base === dir || base.startsWith(dir + path.sep) || base.startsWith(dir + '/')
22
+ * `/a/mirror-2` is NOT treated as living inside `/a/mirror`). Windows paths
23
+ * compare case-insensitively: the same directory can be spelled `F:\\Work`
24
+ * and `f:\\work`, and a drive letter's case is not stable across APIs. */
25
+ const samePath = (a, b) => (process.platform === 'win32' ? a.toLowerCase() === b.toLowerCase() : a === b)
26
+ const isUnder = (base, dir) => {
27
+ const b = process.platform === 'win32' ? base.toLowerCase() : base
28
+ const d = process.platform === 'win32' ? dir.toLowerCase() : dir
29
+ return b === d || b.startsWith(d + path.sep) || b.startsWith(d + '/')
30
+ }
31
+
32
+ /** Real path when the OS can resolve it, else the normalized spelling.
33
+ * `path.resolve` is purely lexical: it never resolves a junction/symlink, so
34
+ * the same physical directory can arrive spelled two different ways. */
35
+ const tryRealpath = (p) => { try { return norm(realpathSync(p)) } catch { return norm(p) } }
36
+
37
+ /** Path depth, used to pick the deepest matching mirror regardless of spelling. */
38
+ const depth = (p) => p.split(/[\\/]+/).filter(Boolean).length
39
+
40
+ /** Re-spell `mirrorReal` the way `base` spells the SAME directory: step up
41
+ * from `base` once per segment `baseReal` sits below `mirrorReal`. Walking
42
+ * with path.dirname keeps the platform's root intact ('/' on POSIX, 'C:\\'
43
+ * or a UNC share on Windows) — rebuilding the string from segments loses it.
44
+ * This keeps a resolved mirror path comparable with the session cwd it came
45
+ * from, even when only one of the two was written through a link. */
46
+ function spellLike(base, mirrorReal, baseReal) {
47
+ const rel = path.relative(baseReal, mirrorReal)
48
+ if (!rel) return base
49
+ let out = base
50
+ for (let i = 0; i < rel.split(/[\\/]+/).filter(Boolean).length; i++) out = path.dirname(out)
51
+ return out
52
+ }
24
53
 
25
54
  /**
26
55
  * Resolve which remote workspace a LOCAL path belongs to by scanning the mirror
@@ -50,11 +79,60 @@ export function resolveMirror(local, root) {
50
79
  let machine = null
51
80
  if (!local || !root || !existsSync(root)) return { mirrorDir, remotePath, machine }
52
81
  const base = norm(local)
82
+ const realBase = tryRealpath(local)
83
+ // Issue #173: the registry root is spelled the way DSH_HOME is written
84
+ // (`~/.dsh/...`), while a session's cwd can be spelled through a junction or
85
+ // symlink to that same directory (or the reverse). A purely lexical prefix
86
+ // comparison then says "not inside any mirror" and every rw_* tool refuses
87
+ // the session as LOCAL. Scanning both spellings keeps a plain prefix test
88
+ // usable and lets the reported mirrorDir keep the cwd's own spelling.
89
+ const scanRoots = [norm(root)]
90
+ const realRoot = tryRealpath(root)
91
+ if (!samePath(realRoot, scanRoots[0])) scanRoots.push(realRoot)
92
+ const seen = new Set()
93
+ for (const scanRoot of scanRoots) {
94
+ for (const mirror of mirrorsUnder(scanRoot)) {
95
+ // Prefer the spelling the cwd already uses; fall back to resolving the
96
+ // mirror itself when only the mirror's tail is a link.
97
+ const resolved = isUnder(base, mirror.dir)
98
+ ? mirror.dir
99
+ : (isUnder(realBase, tryRealpath(mirror.dir)) ? spellLike(base, tryRealpath(mirror.dir), realBase) : null)
100
+ if (!resolved) continue
101
+ const key = process.platform === 'win32' ? resolved.toLowerCase() : resolved
102
+ if (seen.has(key)) continue
103
+ // Deepest match wins; the same physical mirror seen under two spellings
104
+ // must not be reported twice.
105
+ if (mirrorDir && depth(resolved) <= depth(mirrorDir)) continue
106
+ let meta
107
+ try {
108
+ meta = JSON.parse(readFileSync(mirror.metaPath, 'utf8'))
109
+ } catch { continue /* unparsable meta → not a usable binding */ }
110
+ if (!meta || !meta.host) continue
111
+ seen.add(key)
112
+ mirrorDir = resolved
113
+ remotePath = String(meta.remotePath || '')
114
+ machine = {
115
+ host: String(meta.host),
116
+ port: Number(meta.port) || 22,
117
+ username: String(meta.username || ''),
118
+ // The ~/.ssh/config alias this mirror was created through, when the
119
+ // machine was saved as one (issue #38): it keeps the mirror bound to
120
+ // its machine even if that alias's HostName/port later change.
121
+ alias: String(meta.alias || ''),
122
+ }
123
+ }
124
+ }
125
+ return { mirrorDir, remotePath, machine }
126
+ }
127
+
128
+ /** Every mirror directory (one that carries a meta file) directly under `root`. */
129
+ function mirrorsUnder(root) {
130
+ const found = []
53
131
  let hostDirs
54
132
  try {
55
133
  hostDirs = readdirSync(root)
56
134
  } catch {
57
- return { mirrorDir, remotePath, machine }
135
+ return found
58
136
  }
59
137
  for (const hostDir of hostDirs) {
60
138
  const hostPath = path.join(root, hostDir)
@@ -66,30 +144,12 @@ export function resolveMirror(local, root) {
66
144
  continue
67
145
  }
68
146
  for (const entry of entries) {
69
- const metaPath = path.join(hostPath, entry, '.dsh-remote-meta.json')
70
- if (!existsSync(metaPath)) continue
71
- const mirrorAbs = norm(path.join(hostPath, entry))
72
- if (!isUnder(base, mirrorAbs)) continue
73
- // Deepest match wins; an equal-length path cannot occur twice.
74
- if (mirrorDir && mirrorAbs.length <= mirrorDir.length) continue
75
- try {
76
- const meta = JSON.parse(readFileSync(metaPath, 'utf8'))
77
- if (!meta || !meta.host) continue
78
- mirrorDir = mirrorAbs
79
- remotePath = String(meta.remotePath || '')
80
- machine = {
81
- host: String(meta.host),
82
- port: Number(meta.port) || 22,
83
- username: String(meta.username || ''),
84
- // The ~/.ssh/config alias this mirror was created through, when the
85
- // machine was saved as one (issue #38): it keeps the mirror bound to
86
- // its machine even if that alias's HostName/port later change.
87
- alias: String(meta.alias || ''),
88
- }
89
- } catch { /* unparsable meta → not a usable binding */ }
147
+ const dir = norm(path.join(hostPath, entry))
148
+ const metaPath = path.join(dir, '.dsh-remote-meta.json')
149
+ if (existsSync(metaPath)) found.push({ dir, metaPath })
90
150
  }
91
151
  }
92
- return { mirrorDir, remotePath, machine }
152
+ return found
93
153
  }
94
154
 
95
155
  /**
@@ -124,6 +184,31 @@ export function readSessionHeaderCwd(file) {
124
184
  }
125
185
  }
126
186
 
187
+ /** Read session logs written by any DSH release: `session.<format>.jsonl[.zst|.gz]`.
188
+ * The format segment (`v4`, `v3`, …) changes between releases, so a fixed name
189
+ * list silently stopped finding the cwd of every newer session. */
190
+ const SESSION_LOG_RE = /^session(\.[A-Za-z0-9]+)*\.jsonl(\.zst|\.zstd|\.gz)?$/
191
+
192
+ /** Newest session log in a session directory, or '' when there is none. */
193
+ function sessionLogFile(sessDir) {
194
+ try {
195
+ const names = readdirSync(sessDir).filter((n) => SESSION_LOG_RE.test(n))
196
+ if (!names.length) return ''
197
+ // Highest format version first, compressed before raw; only the header line
198
+ // matters, so the first readable file is enough.
199
+ const rank = (n) => {
200
+ const version = /\.v(\d+)\./.exec(n)
201
+ return [version ? Number(version[1]) : 0, /\.(zst|zstd|gz)$/.test(n) ? 1 : 0]
202
+ }
203
+ names.sort((a, b) => {
204
+ const [av, ac] = rank(a)
205
+ const [bv, bc] = rank(b)
206
+ return bv - av || bc - ac || a.localeCompare(b)
207
+ })
208
+ return names.map((n) => path.join(sessDir, n)).find((p) => existsSync(p)) || ''
209
+ } catch { return '' }
210
+ }
211
+
127
212
  /**
128
213
  * Resolve a session's workspace cwd from the live sessions service, then from
129
214
  * durable session logs under `$DSH_HOME/sessions`.
@@ -147,8 +232,7 @@ export function lookupSessionCwd(sessionId, { sessions, dshHome } = {}) {
147
232
  if (!statSync(projPath, { throwIfNoEntry: false })?.isDirectory?.()) continue
148
233
  const sessDir = path.join(projPath, targetDir)
149
234
  if (!statSync(sessDir, { throwIfNoEntry: false })?.isDirectory?.()) continue
150
- const logFile = ['session.jsonl.zstd', 'session.jsonl', 'session.jsonl.gz']
151
- .map((n) => path.join(sessDir, n)).find((p) => existsSync(p))
235
+ const logFile = sessionLogFile(sessDir)
152
236
  if (!logFile) continue
153
237
  const cwd = readSessionHeaderCwd(logFile)
154
238
  if (cwd) return cwd
package/lib/boot.js CHANGED
@@ -1,34 +1,7 @@
1
- // dsh-remote — package entry point (package.json "main" / exports["."]).
2
- //
3
- // A thin shell around the real plugin body (lib/index.js). Its only job is to
4
- // give the startup self-repair somewhere to live: ES module imports HOIST, so
5
- // code placed inside index.js runs strictly after every static import of it
6
- // has already been resolved — there is no room inside index.js to react to a
7
- // missing sibling file. Dynamic import() is the only place such a guard can
8
- // sit, hence this indirection.
9
- //
10
- // What happens here (see lib/self-heal.js for the policy):
11
- // import('./index.js') → on a missing-own-file crash (the half-updated
12
- // 0.8.92 scenario, issue #126) the CURRENT version's tarball is re-laid from
13
- // npm and the import retried once. Healthy installs pay zero overhead: one
14
- // extra dynamic import of the same file the host would have loaded anyway.
15
- //
16
- // ★ TWO INVARIANTS protect this file:
17
- // 1. Stay minimal and self-contained — only import lib/self-heal.js (which
18
- // only imports lib/update.js + node builtins). Anything richer could be
19
- // the file that is missing.
20
- // 2. Re-export index.js's public surface EXACTLY. The cordis loader, the
21
- // settings UI and tests consume these names; test/self-heal-boot.test.js
22
- // pins the key set so index.js cannot gain an export this shell forgets
23
- // to forward.
24
-
25
- import { importWithSelfHeal } from './self-heal.js'
26
-
27
- const { module: main, repaired } = await importWithSelfHeal(() => import('./index.js'))
28
-
29
- if (repaired) {
30
- console.warn('[dsh-remote] startup self-repair succeeded — the incomplete update has been fully re-applied and this boot is healthy')
31
- }
1
+ // Package-root entry. Forward the caller's URL query through the shared
2
+ // self-heal guard so cache-busted consumers keep isolated module state.
3
+ const indexUrl = new URL('./index.js' + new URL(import.meta.url).search, import.meta.url).href
4
+ const main = await import(indexUrl)
32
5
 
33
6
  export const name = main.name
34
7
  export const DEFAULT_UPDATE_MODE = main.DEFAULT_UPDATE_MODE