dsh-remote 1.4.1 → 1.6.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
@@ -18,7 +18,7 @@ Use the normal layout or choose the optional **three-column IDE layout** to view
18
18
 
19
19
  <img src="https://raw.githubusercontent.com/flymysql/dsh-remote/main/docs/shots/workbench-ide.png" alt="DSH remote IDE with file tree, native code editor and agent conversation" width="1200"/>
20
20
 
21
- [1.4.1 release notes](https://github.com/flymysql/dsh-remote/blob/main/docs/release/1.4.1.md): Windows OpenSSH connect and platform-detection fixes, opaque IDE floors for wallpaper themes.
21
+ [1.6.0 release notes](https://github.com/flymysql/dsh-remote/blob/main/docs/release/1.6.0.md): a read-only remote commit graph, an IDE-button visibility preference, and a large batch of robustness fixes across search, sync, self-update and forwarding.
22
22
 
23
23
  ## Install
24
24
 
package/README.md CHANGED
@@ -26,7 +26,7 @@ dsh plugin --profile web add dsh-remote
26
26
 
27
27
  安装或升级后,重启 DSH Web 并刷新页面。自动更新状态在设置 → 远程工作区 → 插件偏好中查看。
28
28
 
29
- [1.4.1 更新说明](https://github.com/flymysql/dsh-remote/blob/main/docs/release/1.4.1.md):Windows OpenSSH 连接与平台探测修复、IDE 模式壁纸主题底板加固。
29
+ [1.6.0 更新说明](https://github.com/flymysql/dsh-remote/blob/main/docs/release/1.6.0.md):远程提交图、IDE 按钮可见性偏好,以及搜索/同步/自更新/转发等一大批健壮性修复。
30
30
 
31
31
  ## 3 步开始
32
32
 
package/lib/binding.js CHANGED
@@ -11,44 +11,30 @@
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, realpathSync, statSync } from 'node:fs'
14
+ import { closeSync, existsSync, lstatSync, openSync, readFileSync, readSync, readdirSync, realpathSync, statSync } from 'node:fs'
15
15
  import path from 'node:path'
16
16
  import zlib from 'node:zlib'
17
17
 
18
- /** Strip trailing separators so a mirror root and a path inside it compare cleanly. */
19
- const norm = (p) => path.resolve(String(p || '')).replace(/[\\/]+$/, '') || ''
20
-
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`). 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)
18
+ /** Separator-aware containment, with Windows drive and case handling from path.relative. */
26
19
  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 + '/')
20
+ const rel = path.relative(dir, base)
21
+ return !path.isAbsolute(rel) && rel !== '..' && !rel.startsWith('..' + path.sep)
30
22
  }
31
23
 
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) } }
24
+ const tryRealpath = (p) => { try { return realpathSync.native(p) } catch { return null } }
36
25
 
37
- /** Path depth, used to pick the deepest matching mirror regardless of spelling. */
38
- const depth = (p) => p.split(/[\\/]+/).filter(Boolean).length
26
+ /** Path depth, used to pick the deepest matching physical mirror. */
27
+ const depth = (p) => p.split(path.sep).filter(Boolean).length
39
28
 
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
29
+ /** Keep the cwd's spelling when its matching ancestor is the registered mirror. */
30
+ function mirrorSpelling(base, baseReal, dir, dirReal) {
31
+ if (isUnder(base, dir)) return dir
32
+ const levels = depth(path.relative(dirReal, baseReal))
33
+ let candidate = base
34
+ for (let i = 0; i < levels; i++) candidate = path.dirname(candidate)
35
+ // A nested link can change the depth below the mirror between spellings.
36
+ const candidateReal = tryRealpath(candidate)
37
+ return candidateReal && path.relative(dirReal, candidateReal) === '' ? candidate : dir
52
38
  }
53
39
 
54
40
  /**
@@ -77,49 +63,42 @@ export function resolveMirror(local, root) {
77
63
  let mirrorDir = null
78
64
  let remotePath = ''
79
65
  let machine = null
80
- if (!local || !root || !existsSync(root)) return { mirrorDir, remotePath, machine }
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
- }
66
+ if (!local || !root) return { mirrorDir, remotePath, machine }
67
+ const base = path.resolve(local)
68
+ let realBase
69
+ try {
70
+ // Resolve the original spelling before any lexical normalization.
71
+ realBase = realpathSync.native(local)
72
+ } catch (error) {
73
+ // Keep lexical matching for a cwd that has not been created yet.
74
+ if (error.code !== 'ENOENT') return { mirrorDir, remotePath, machine }
75
+ }
76
+ let bestDepth = -1
77
+ for (const { dir, metaPath } of mirrorsUnder(path.resolve(root))) {
78
+ const realDir = tryRealpath(dir)
79
+ if (!realDir) continue
80
+ // A registry symlink or junction may give the same mirror two spellings.
81
+ // For an existing cwd, only the physical paths determine containment.
82
+ const containsCwd = realBase ? isUnder(realBase, realDir) : isUnder(base, dir) || isUnder(base, realDir)
83
+ if (!containsCwd) continue
84
+ const candidateDepth = depth(realDir)
85
+ if (candidateDepth <= bestDepth) continue
86
+ let meta
87
+ try {
88
+ meta = JSON.parse(readFileSync(metaPath, 'utf8'))
89
+ } catch { continue /* unparsable meta → not a usable binding */ }
90
+ if (!meta || !meta.host) continue
91
+ mirrorDir = mirrorSpelling(base, realBase || base, dir, realDir)
92
+ bestDepth = candidateDepth
93
+ remotePath = String(meta.remotePath || '')
94
+ machine = {
95
+ host: String(meta.host),
96
+ port: Number(meta.port) || 22,
97
+ username: String(meta.username || ''),
98
+ // The ~/.ssh/config alias this mirror was created through, when the
99
+ // machine was saved as one (issue #38): it keeps the mirror bound to
100
+ // its machine even if that alias's HostName/port later change.
101
+ alias: String(meta.alias || ''),
123
102
  }
124
103
  }
125
104
  return { mirrorDir, remotePath, machine }
@@ -144,7 +123,7 @@ function mirrorsUnder(root) {
144
123
  continue
145
124
  }
146
125
  for (const entry of entries) {
147
- const dir = norm(path.join(hostPath, entry))
126
+ const dir = path.join(hostPath, entry)
148
127
  const metaPath = path.join(dir, '.dsh-remote-meta.json')
149
128
  if (existsSync(metaPath)) found.push({ dir, metaPath })
150
129
  }
@@ -169,21 +148,44 @@ export function encodeSegmentSafe(id) {
169
148
  return s || 'session'
170
149
  }
171
150
 
172
- /** Read the cwd from a session log header (JSONL / .gz / zstd first frame). */
173
- export function readSessionHeaderCwd(file) {
151
+ function sessionHeaderLine(file, buf, partial = false) {
152
+ if (/\.z(?:st|std)$/.test(file)) buf = zlib.zstdDecompressSync(buf)
153
+ else if (/\.gz$/.test(file)) {
154
+ buf = zlib.gunzipSync(buf, partial ? { finishFlush: zlib.constants.Z_SYNC_FLUSH } : undefined)
155
+ }
156
+ const nl = buf.indexOf(10)
157
+ return nl < 0 ? '' : buf.subarray(0, nl).toString('utf8')
158
+ }
159
+
160
+ function readSessionHeader(file) {
174
161
  try {
175
- let buf = readFileSync(file)
176
- if (/\.zstd$/.test(file)) buf = zlib.zstdDecompressSync(buf)
177
- else if (/\.gz$/.test(file)) buf = zlib.gunzipSync(buf)
178
- const nl = buf.indexOf(10)
179
- if (nl < 0) return ''
180
- const head = JSON.parse(buf.subarray(0, nl).toString('utf8'))
181
- return typeof head.cwd === 'string' ? head.cwd : ''
162
+ const fd = openSync(file, 'r')
163
+ try {
164
+ // The first JSONL line or compressed frame usually fits in the prefix.
165
+ const prefix = Buffer.allocUnsafe(8192)
166
+ const size = readSync(fd, prefix, 0, prefix.length, 0)
167
+ let line
168
+ if (size < prefix.length) {
169
+ line = sessionHeaderLine(file, prefix.subarray(0, size))
170
+ } else {
171
+ try { line = sessionHeaderLine(file, prefix, true) } catch { /* frame extends past the prefix */ }
172
+ if (!line) line = sessionHeaderLine(file, readFileSync(fd))
173
+ }
174
+ return line ? JSON.parse(line) : undefined
175
+ } finally {
176
+ closeSync(fd)
177
+ }
182
178
  } catch {
183
- return ''
179
+ return undefined
184
180
  }
185
181
  }
186
182
 
183
+ /** Read the cwd from a session log header (JSONL / .gz / zstd first frame). */
184
+ export function readSessionHeaderCwd(file) {
185
+ const header = readSessionHeader(file)
186
+ return typeof header?.cwd === 'string' ? header.cwd : ''
187
+ }
188
+
187
189
  /** Read session logs written by any DSH release: `session.<format>.jsonl[.zst|.gz]`.
188
190
  * The format segment (`v4`, `v3`, …) changes between releases, so a fixed name
189
191
  * list silently stopped finding the cwd of every newer session. */
@@ -209,6 +211,20 @@ function sessionLogFile(sessDir) {
209
211
  } catch { return '' }
210
212
  }
211
213
 
214
+ /** Read a persisted session's cwd for ownership checks in its own directory. */
215
+ export function readStoredSessionCwd(dir, id) {
216
+ const file = sessionLogFile(dir)
217
+ if (!file) return ''
218
+ try {
219
+ if (!lstatSync(file, { throwIfNoEntry: false })?.isFile()) return ''
220
+ const header = readSessionHeader(file)
221
+ if (header?.type !== 'session' || header.id !== id) return ''
222
+ return typeof header.cwd === 'string' ? header.cwd : ''
223
+ } catch {
224
+ return ''
225
+ }
226
+ }
227
+
212
228
  /**
213
229
  * Resolve a session's workspace cwd from the live sessions service, then from
214
230
  * durable session logs under `$DSH_HOME/sessions`.
package/lib/boot.js CHANGED
@@ -10,6 +10,7 @@ export const win32FolderPickScript = main.win32FolderPickScript
10
10
  export const LOCAL_BOOTSTRAP_TOOLS = main.LOCAL_BOOTSTRAP_TOOLS
11
11
  export const normalizeLocalTools = main.normalizeLocalTools
12
12
  export const pickWorkspaceNextStep = main.pickWorkspaceNextStep
13
+ export const pickWorkspaceRebindNote = main.pickWorkspaceRebindNote
13
14
  export const inject = main.inject
14
15
  export const Config = main.Config
15
16
  export const apply = main.apply