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 +1 -1
- package/README.md +1 -1
- package/lib/binding.js +100 -84
- package/lib/boot.js +1 -0
- package/lib/client.js +252 -46
- package/lib/connect-summary.js +28 -0
- package/lib/file-reference.js +63 -7
- package/lib/forwards.js +72 -23
- package/lib/host-api.js +26 -37
- package/lib/hostkey.js +128 -10
- package/lib/http-transport.js +72 -5
- package/lib/ignore.js +64 -21
- package/lib/index.js +1 -0
- package/lib/main.js +221 -231
- package/lib/mirror-paths.js +107 -2
- package/lib/openssh.js +55 -2
- package/lib/pool.js +23 -1
- package/lib/registry.js +50 -6
- package/lib/remote-fs.js +43 -19
- package/lib/remote-git.js +53 -5
- package/lib/remote-shell-child.cjs +9 -1
- package/lib/routes-fs.js +159 -7
- package/lib/routes-machines.js +16 -8
- package/lib/routes-web-attach.js +115 -43
- package/lib/routes-workspace.js +15 -9
- package/lib/search.js +96 -16
- package/lib/sftp-surface.js +5 -1
- package/lib/sshconfig.js +62 -7
- package/lib/sync-status.js +3 -2
- package/lib/sync.js +109 -48
- package/lib/terminal.js +7 -3
- package/lib/update.js +65 -10
- package/lib/web-attach.js +184 -22
- package/lib/workspace-cleanup.js +85 -60
- package/lib/workspace-files-remote.js +154 -3
- package/package.json +2 -2
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.
|
|
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.
|
|
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
|
-
/**
|
|
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
|
|
28
|
-
|
|
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
|
-
|
|
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
|
|
38
|
-
const depth = (p) => p.split(
|
|
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
|
-
/**
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
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
|
|
81
|
-
const base =
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
machine
|
|
115
|
-
|
|
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 =
|
|
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
|
-
|
|
173
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|