dsh-remote 1.5.0 → 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/client.js +107 -45
- 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/main.js +179 -228
- package/lib/mirror-paths.js +107 -2
- package/lib/openssh.js +51 -1
- package/lib/pool.js +9 -0
- package/lib/registry.js +47 -7
- package/lib/remote-fs.js +43 -19
- package/lib/remote-git.js +53 -5
- package/lib/routes-fs.js +33 -17
- 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 +137 -20
- 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/client.js
CHANGED
|
@@ -27,7 +27,7 @@ window.__ModuleLoader__.load({
|
|
|
27
27
|
|
|
28
28
|
const React = require('react')
|
|
29
29
|
const name = 'dsh-remote'
|
|
30
|
-
const CLIENT_VERSION = '1.
|
|
30
|
+
const CLIENT_VERSION = '1.6.0'
|
|
31
31
|
|
|
32
32
|
// ── optional host primitives ────────────────────────────────────────────
|
|
33
33
|
// Issue #74: a remote session's .md link must open over SFTP, NOT via the
|
|
@@ -587,6 +587,8 @@ window.__ModuleLoader__.load({
|
|
|
587
587
|
'settings.updateNow': '立即更新',
|
|
588
588
|
'settings.updateMode': '更新模式:',
|
|
589
589
|
'settings.explorerAutoOpen': '打开远程工作区时,自动在侧边栏展开「远程文件」',
|
|
590
|
+
// Issue #279: hide the IDE-mode button for users who prefer the plain layout.
|
|
591
|
+
'settings.ideToggleVisible': '显示「IDE 模式」按钮',
|
|
590
592
|
'settings.updateManual': '手动',
|
|
591
593
|
'settings.updateAuto': '自动',
|
|
592
594
|
'settings.updateOff': '关闭',
|
|
@@ -1225,6 +1227,8 @@ window.__ModuleLoader__.load({
|
|
|
1225
1227
|
'settings.updateNow': 'Update now',
|
|
1226
1228
|
'settings.updateMode': 'Update mode:',
|
|
1227
1229
|
'settings.explorerAutoOpen': 'Auto-open the Remote Files sidebar tab for remote workspaces',
|
|
1230
|
+
// Issue #279: hide the IDE-mode button for users who prefer the plain layout.
|
|
1231
|
+
'settings.ideToggleVisible': 'Show the IDE mode button',
|
|
1228
1232
|
|
|
1229
1233
|
'settings.updateManual': 'Manual',
|
|
1230
1234
|
'settings.updateAuto': 'Auto',
|
|
@@ -1531,12 +1535,23 @@ window.__ModuleLoader__.load({
|
|
|
1531
1535
|
*
|
|
1532
1536
|
* The mirror download (POST /dsh-remote/fs op=download) only writes on the
|
|
1533
1537
|
* DSH host, so a user who opens the page from their own desktop had no way to
|
|
1534
|
-
* get the file. The host streams it from /dsh-remote/download
|
|
1535
|
-
* saves it; failures (too large, gone, wrong session) reject instead of
|
|
1536
|
-
* silently saving a JSON error as if it were the file.
|
|
1538
|
+
* get the file. The host streams it from /dsh-remote/download.
|
|
1537
1539
|
*/
|
|
1538
|
-
function downloadRemoteFileToClient(sessionId, filePath) {
|
|
1540
|
+
async function downloadRemoteFileToClient(sessionId, filePath) {
|
|
1539
1541
|
const url = withSessionQuery(apiPath('/dsh-remote/download') + '?path=' + encodeURIComponent(filePath), sessionId)
|
|
1542
|
+
const { protocol, origin } = window.location || {}
|
|
1543
|
+
if (protocol === 'http:' || protocol === 'https:') {
|
|
1544
|
+
const anchor = document.createElement('a')
|
|
1545
|
+
anchor.href = origin + url
|
|
1546
|
+
anchor.target = '_blank'
|
|
1547
|
+
anchor.rel = 'noopener'
|
|
1548
|
+
anchor.style.display = 'none'
|
|
1549
|
+
// Content-Disposition starts a native download. HTTP errors can render
|
|
1550
|
+
// in the new tab while the workspace stays open.
|
|
1551
|
+
document.body.appendChild(anchor)
|
|
1552
|
+
try { anchor.click() } finally { anchor.remove() }
|
|
1553
|
+
return
|
|
1554
|
+
}
|
|
1540
1555
|
return fetch(url, { credentials: 'same-origin' }).then(async (res) => {
|
|
1541
1556
|
if (!res.ok) {
|
|
1542
1557
|
const data = await res.json().catch(() => ({}))
|
|
@@ -3338,6 +3353,12 @@ window.__ModuleLoader__.load({
|
|
|
3338
3353
|
)
|
|
3339
3354
|
: React.createElement('span', { 'data-testid': 'explorer-auto-open', style: { display: 'inline-flex', opacity: 0.85 } }, React.createElement(RwCheckbox, { checked: explorerAuto, label: tr('settings.explorerAutoOpen'), onChange: (on) => applyExplorerAutoOpen(on === true) })),
|
|
3340
3355
|
),
|
|
3356
|
+
React.createElement('div', { style: { display: 'flex', gap: 8, alignItems: 'center', marginTop: 6, fontSize: 12 } },
|
|
3357
|
+
// Issue #279: offer the IDE-mode button only when the user wants it
|
|
3358
|
+
// — the layout itself keeps working for those who already use it.
|
|
3359
|
+
React.createElement('span', { 'data-testid': 'ide-toggle-visible', style: { display: 'inline-flex', opacity: 0.85 } },
|
|
3360
|
+
React.createElement(RwCheckbox, { checked: useIdeToggleVisible(), label: tr('settings.ideToggleVisible'), onChange: (on) => ideToggleSetVisible(on === true) })),
|
|
3361
|
+
),
|
|
3341
3362
|
upd?.lastReload?.ok === false
|
|
3342
3363
|
? React.createElement('div', { role: 'status', style: { marginTop: 8, fontSize: 12, lineHeight: 1.6, color: T.warn } }, tr('settings.updateReloadFailed', { reason: upd.lastReload.reason || '' }))
|
|
3343
3364
|
: null,
|
|
@@ -5486,6 +5507,11 @@ window.__ModuleLoader__.load({
|
|
|
5486
5507
|
|
|
5487
5508
|
const doFs = (op, payload, refreshParent) => {
|
|
5488
5509
|
const view = viewRef.current
|
|
5510
|
+
const refreshTree = () => {
|
|
5511
|
+
if (!refreshParent) return
|
|
5512
|
+
if (root) loadDir(root, { force: true })
|
|
5513
|
+
for (const dir of expanded) if (dir !== root) loadDir(dir, { force: true })
|
|
5514
|
+
}
|
|
5489
5515
|
setBusy(op)
|
|
5490
5516
|
return api('POST', '/dsh-remote/fs', withSessionBody({ op, ...payload }, sessionId))
|
|
5491
5517
|
.then((r) => {
|
|
@@ -5495,12 +5521,13 @@ window.__ModuleLoader__.load({
|
|
|
5495
5521
|
// the file landed in the local mirror with zero feedback, reading
|
|
5496
5522
|
// as "the download did nothing".
|
|
5497
5523
|
if (op === 'download' && r && r.local) setDlNote({ path: String(r.local) })
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
|
|
5524
|
+
refreshTree()
|
|
5525
|
+
})
|
|
5526
|
+
.catch((e) => {
|
|
5527
|
+
if (viewRef.current !== view) return
|
|
5528
|
+
setErr(String(e.message || e))
|
|
5529
|
+
if (e.code === 'REMOTE_REMOVE_INCOMPLETE') refreshTree()
|
|
5502
5530
|
})
|
|
5503
|
-
.catch((e) => { if (viewRef.current === view) setErr(String(e.message || e)) })
|
|
5504
5531
|
.finally(() => { if (viewRef.current === view) setBusy('') })
|
|
5505
5532
|
}
|
|
5506
5533
|
|
|
@@ -5540,7 +5567,6 @@ window.__ModuleLoader__.load({
|
|
|
5540
5567
|
? React.createElement('span', { style: { fontSize: 11, opacity: 0.75, flexShrink: 0, color: T.ok } }, tr('explorer.copied'))
|
|
5541
5568
|
: null)
|
|
5542
5569
|
|
|
5543
|
-
// Fetch the file through the host and let the browser save it.
|
|
5544
5570
|
const downloadToComputer = (p) => {
|
|
5545
5571
|
setErr('')
|
|
5546
5572
|
downloadRemoteFileToClient(sessionId, p).catch((e) => setErr(String((e && e.message) || e)))
|
|
@@ -6510,7 +6536,7 @@ window.__ModuleLoader__.load({
|
|
|
6510
6536
|
const downloadToBrowser = () => {
|
|
6511
6537
|
setSaving(true); setErr('')
|
|
6512
6538
|
downloadRemoteFileToClient(fileSessionId, path)
|
|
6513
|
-
.then(() => { if (fileViewRef.current
|
|
6539
|
+
.then((name) => { if (name && fileViewRef.current === draftKey) setCopyNote(tr('file.downloadedToComputer')) })
|
|
6514
6540
|
.catch((e) => { if (fileViewRef.current === draftKey) setErr(String((e && e.message) || e)) })
|
|
6515
6541
|
.finally(() => { if (fileViewRef.current === draftKey) setSaving(false) })
|
|
6516
6542
|
}
|
|
@@ -6699,37 +6725,35 @@ window.__ModuleLoader__.load({
|
|
|
6699
6725
|
disposers.forEach((d) => { try { d() } catch {} })
|
|
6700
6726
|
return
|
|
6701
6727
|
}
|
|
6702
|
-
|
|
6703
|
-
let
|
|
6728
|
+
const autoOpenedFor = new Set()
|
|
6729
|
+
let disposed = false
|
|
6704
6730
|
const tryAutoOpen = () => {
|
|
6705
|
-
if (
|
|
6706
|
-
const
|
|
6707
|
-
if (!
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
//
|
|
6715
|
-
//
|
|
6716
|
-
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
} catch (e2) {
|
|
6722
|
-
console.warn('[dsh-remote] better-sidebar auto-open skipped:', e2)
|
|
6723
|
-
}
|
|
6724
|
-
})
|
|
6731
|
+
if (disposed) return
|
|
6732
|
+
const sessionId = bs.getSnapshot?.()?.sessionId
|
|
6733
|
+
if (!sessionId || autoOpenedFor.has(sessionId)) return
|
|
6734
|
+
const canAutoOpen = () => !disposed && !autoOpenedFor.has(sessionId) && bs.getSnapshot?.()?.sessionId === sessionId
|
|
6735
|
+
// Native and better-sidebar await the same effective preference.
|
|
6736
|
+
void explorerAutoOpenPreference().then(async (enabled) => {
|
|
6737
|
+
if (!enabled || !canAutoOpen()) return
|
|
6738
|
+
// Issue #13: only auto-open for a genuinely remote session.
|
|
6739
|
+
const remotePath = await resolveSessionRemote(sessionId)
|
|
6740
|
+
// Only surface the tab while its session is still active. Older
|
|
6741
|
+
// better-sidebar builds may ignore the explicit session scope.
|
|
6742
|
+
if (!remotePath || !canAutoOpen() || bs.isTabEnabled?.(SIDEBAR_EXPLORER_ID) === false) return
|
|
6743
|
+
bs.openTab({ type: SIDEBAR_EXPLORER_ID, title: tr('explorer.tabTitle'), path: remotePath }, { sessionId })
|
|
6744
|
+
autoOpenedFor.add(sessionId)
|
|
6745
|
+
}).catch((e) => {
|
|
6746
|
+
console.warn('[dsh-remote] better-sidebar auto-open skipped:', e)
|
|
6725
6747
|
})
|
|
6726
6748
|
}
|
|
6727
|
-
tryAutoOpen()
|
|
6728
6749
|
if (typeof bs.subscribeState === 'function') {
|
|
6729
|
-
|
|
6730
|
-
disposers.push(
|
|
6750
|
+
tryAutoOpen()
|
|
6751
|
+
disposers.push(bs.subscribeState(tryAutoOpen))
|
|
6752
|
+
}
|
|
6753
|
+
return () => {
|
|
6754
|
+
disposed = true
|
|
6755
|
+
disposers.forEach((d) => { try { d() } catch {} })
|
|
6731
6756
|
}
|
|
6732
|
-
return () => disposers.forEach((d) => { try { d() } catch {} })
|
|
6733
6757
|
}
|
|
6734
6758
|
|
|
6735
6759
|
// Official Desktop's right-sidebar extension contract. Reuse the SSH
|
|
@@ -7271,15 +7295,27 @@ window.__ModuleLoader__.load({
|
|
|
7271
7295
|
const patch = currentDiff?.data?.patch || ''
|
|
7272
7296
|
const patchLines = patch.split('\n')
|
|
7273
7297
|
if (patchLines[patchLines.length - 1] === '') patchLines.pop()
|
|
7274
|
-
let nextLine =
|
|
7298
|
+
let nextLine = 0, oldRemaining = 0, newRemaining = 0
|
|
7275
7299
|
const rows = patchLines.slice(0, 1800).map((text, index) => {
|
|
7276
|
-
const hunk = /^@@ -\d+(
|
|
7300
|
+
const hunk = /^@@ -\d+(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/.exec(text)
|
|
7277
7301
|
let line = null, kind = 'meta'
|
|
7278
|
-
if (hunk) {
|
|
7279
|
-
|
|
7280
|
-
|
|
7281
|
-
|
|
7282
|
-
|
|
7302
|
+
if (hunk) {
|
|
7303
|
+
oldRemaining = Number(hunk[1] ?? 1)
|
|
7304
|
+
nextLine = Number(hunk[2])
|
|
7305
|
+
newRemaining = Number(hunk[3] ?? 1)
|
|
7306
|
+
kind = 'hunk'
|
|
7307
|
+
} else if (text[0] === '+' && newRemaining > 0) {
|
|
7308
|
+
newRemaining--
|
|
7309
|
+
line = nextLine++
|
|
7310
|
+
kind = 'added'
|
|
7311
|
+
} else if (text[0] === ' ' && oldRemaining > 0 && newRemaining > 0) {
|
|
7312
|
+
oldRemaining--
|
|
7313
|
+
newRemaining--
|
|
7314
|
+
line = nextLine++
|
|
7315
|
+
kind = 'context'
|
|
7316
|
+
} else if (text[0] === '-' && oldRemaining > 0) {
|
|
7317
|
+
oldRemaining--
|
|
7318
|
+
kind = 'removed'
|
|
7283
7319
|
}
|
|
7284
7320
|
const canOpen = !!line && line > 0 && !chosen?.deleted && typeof props.openFile === 'function'
|
|
7285
7321
|
return React.createElement('div', { key: index, className: 'dsh-rw-git-diff-line', 'data-rw-diff-kind': kind },
|
|
@@ -7483,6 +7519,28 @@ window.__ModuleLoader__.load({
|
|
|
7483
7519
|
} catch { return { enabled: false, left: 240, right: 400 } }
|
|
7484
7520
|
}
|
|
7485
7521
|
let remoteIdeState = remoteIdeRead()
|
|
7522
|
+
// Issue #279: whether the IDE-mode BUTTON is offered at all. A separate
|
|
7523
|
+
// preference from `remoteIdeState.enabled` (the layout choice) — hiding
|
|
7524
|
+
// the button must not tear down an IDE session the user is already in.
|
|
7525
|
+
const IDE_TOGGLE_KEY = 'dsh-remote.ide-toggle-visible'
|
|
7526
|
+
const ideToggleWatchers = new Set()
|
|
7527
|
+
let ideToggleVisible = (() => {
|
|
7528
|
+
try { return window.localStorage.getItem(IDE_TOGGLE_KEY) !== '0' } catch { return true }
|
|
7529
|
+
})()
|
|
7530
|
+
function ideToggleSetVisible(visible) {
|
|
7531
|
+
ideToggleVisible = !!visible
|
|
7532
|
+
try { window.localStorage.setItem(IDE_TOGGLE_KEY, ideToggleVisible ? '1' : '0') } catch { /* session-only */ }
|
|
7533
|
+
for (const fn of ideToggleWatchers) fn()
|
|
7534
|
+
}
|
|
7535
|
+
function useIdeToggleVisible() {
|
|
7536
|
+
const [visible, setVisible] = React.useState(ideToggleVisible)
|
|
7537
|
+
React.useEffect(() => {
|
|
7538
|
+
const update = () => setVisible(ideToggleVisible)
|
|
7539
|
+
ideToggleWatchers.add(update); update()
|
|
7540
|
+
return () => ideToggleWatchers.delete(update)
|
|
7541
|
+
}, [])
|
|
7542
|
+
return visible
|
|
7543
|
+
}
|
|
7486
7544
|
function remoteIdeSet(change) {
|
|
7487
7545
|
remoteIdeState = { ...remoteIdeState, ...change }
|
|
7488
7546
|
try { window.localStorage.setItem(REMOTE_IDE_KEY, JSON.stringify(remoteIdeState)) } catch { /* private browsing */ }
|
|
@@ -7507,6 +7565,10 @@ window.__ModuleLoader__.load({
|
|
|
7507
7565
|
function RemoteIdeToggle(props) {
|
|
7508
7566
|
const mirror = useSessionMirror(props.sessionId, props.useSessions)
|
|
7509
7567
|
const state = useRemoteIdeState()
|
|
7568
|
+
const toggleVisible = useIdeToggleVisible()
|
|
7569
|
+
// Issue #279: hiding the button is a preference, not a state change —
|
|
7570
|
+
// the IDE session itself stays usable for users who have it on.
|
|
7571
|
+
if (!toggleVisible) return null
|
|
7510
7572
|
if (!mirror && !localWorkspaceSession(props.sessionId)) return null
|
|
7511
7573
|
const supported = !!remoteIdeController?.mounted?.getSnapshot && typeof remoteIdeController.openResourceIn === 'function'
|
|
7512
7574
|
return React.createElement('button', {
|
package/lib/connect-summary.js
CHANGED
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
// Kept as a pure function so the rule is testable without a live SSH server: an
|
|
22
22
|
// alias connect cannot be faked against the real `ssh` binary in CI (ssh reads
|
|
23
23
|
// the developer's own ~/.ssh/config, not the plugin's reader).
|
|
24
|
+
//
|
|
25
|
+
// `connectFailureText` is the failure half of the same idea: what `rw_connect`
|
|
26
|
+
// prints when the post-dial `echo ok` probe does not come back clean.
|
|
24
27
|
|
|
25
28
|
/**
|
|
26
29
|
* @param {object} input
|
|
@@ -50,3 +53,28 @@ export function describeConnect({ alias = '', aliasNative = false, resolved = nu
|
|
|
50
53
|
: ''
|
|
51
54
|
return `Connected to ${machineHost}${user ? ` as ${user}` : ''}.${via}`
|
|
52
55
|
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The failure half: what `rw_connect` prints when the post-dial `echo ok`
|
|
59
|
+
* probe does not come back clean.
|
|
60
|
+
*
|
|
61
|
+
* pool.exec never rejects — its deadline RESOLVES with
|
|
62
|
+
* `{ code: -1, signal: 'TIMEOUT', stdout: '', stderr: '' }` (both backends,
|
|
63
|
+
* see the pool timers) — so the only way to see a probe timeout is the
|
|
64
|
+
* `signal` field, exactly how the rw_info ping ("Ping: timeout"), the
|
|
65
|
+
* connect-stage probe ("ssh timed out after Xms", dsh-remote-fix3) and the
|
|
66
|
+
* exec tools ("[command timed out after Xms]") already treat this shape.
|
|
67
|
+
* Reading only code/stderr degrades every slower-than-budget dial to a bare
|
|
68
|
+
* `exit -1` and hides the one fact the user needs.
|
|
69
|
+
*
|
|
70
|
+
* @param {{code: number, signal?: string, stderr?: string}} res - the resolved pool.exec result.
|
|
71
|
+
* @param {{host?: string, timeoutMs?: number}} [where] - dial host and probe budget, echoed in the message.
|
|
72
|
+
* @returns {string} the detail after the literal `connect failed: ` prefix.
|
|
73
|
+
*/
|
|
74
|
+
export function connectFailureText(res, { host = '', timeoutMs = 0 } = {}) {
|
|
75
|
+
if (res.signal === 'TIMEOUT') {
|
|
76
|
+
return `the post-dial probe timed out after ${Number(timeoutMs) || 0}ms with no reply from ${String(host || 'the host')}`
|
|
77
|
+
+ ' — check the link (a dual-stack hostname whose ::1 blackholes can also stall every dial before the IPv4 fallback)'
|
|
78
|
+
}
|
|
79
|
+
return res.stderr || `exit ${res.code}`
|
|
80
|
+
}
|