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/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.4.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
@@ -405,6 +405,16 @@ window.__ModuleLoader__.load({
405
405
  'settings.backendOpensshAliasOk': '已勾选「使用 ssh_config 别名」:主机名原样交给 ssh,端口/用户/私钥/跳板机一律由 ~/.ssh/config 的 Host 块决定,对应的输入框在 openssh 后端下填了也不生效(这就是「配置唯一来源」,issue #50)。密码/Passphrase 仍会通过 askpass 交给 ssh,仅当 Host 块里没有可用认证时才用得上。',
406
406
  'settings.sshBinary': 'ssh 路径',
407
407
  'settings.sshBinaryPlaceholder': '留空 = 用 PATH 里的 ssh',
408
+ // Issue #206: the per-machine shell was only reachable by hand-editing
409
+ // machines.json — and applyMachine dropped it anyway. It is an ordinary
410
+ // machine field with an input now.
411
+ 'settings.shell': '远端 Shell',
412
+ 'settings.shellPlaceholder': '留空 = 自动探测(where bash)',
413
+ 'settings.shellHint': 'Windows 远端专用:指定 bash.exe 的路径或包装脚本,覆盖自动探测。例如自动探测到的是 WSL 启动器 stub、或 Git Bash 需要包装才能在 sshd 的 stdio 下存活时使用。POSIX 远端留空即可。',
414
+ // Issue #212: JumpServer 类网关对带命令的会话不分配远端 PTY。
415
+ 'settings.terminalNoCommand': '终端纯登录',
416
+ 'settings.terminalNoCommandLabel': '终端用纯登录(堡垒机 / 网关适用)',
417
+ 'settings.terminalNoCommandHint': 'JumpServer 类网关只给「不带命令的登录」分配远端 PTY:带命令时(即使 -tt)没有行纪律,回车不生效、按键看似无响应。勾选后生成的终端 launcher 只发纯登录,不再自动 cd 到工作区,但拿到真 PTY(zsh 行编辑、窗口缩放正常)。直连普通 sshd 的机器不要勾。',
408
418
  // Issue #54: the README told users to point `webAttachCommand` at a
409
419
  // private-prefix dsh, but the settings UI offered nowhere to type it —
410
420
  // it could only be written by the deploy flow or by hand-editing
@@ -577,6 +587,8 @@ window.__ModuleLoader__.load({
577
587
  'settings.updateNow': '立即更新',
578
588
  'settings.updateMode': '更新模式:',
579
589
  'settings.explorerAutoOpen': '打开远程工作区时,自动在侧边栏展开「远程文件」',
590
+ // Issue #279: hide the IDE-mode button for users who prefer the plain layout.
591
+ 'settings.ideToggleVisible': '显示「IDE 模式」按钮',
580
592
  'settings.updateManual': '手动',
581
593
  'settings.updateAuto': '自动',
582
594
  'settings.updateOff': '关闭',
@@ -695,6 +707,13 @@ window.__ModuleLoader__.load({
695
707
  'explorer.menuExpand': '📂 展开/收起',
696
708
  'explorer.menuOpen': '📄 打开文件',
697
709
  'explorer.menuDownload': '⬇ 下载到本地镜像',
710
+ 'explorer.menuDownloadLocal': '⬇ 下载到本机',
711
+ 'explorer.downloadLocal': '下载到本机',
712
+ // Issue #207: mirror downloads are invisible without a picker — say
713
+ // where the file landed and offer to reveal it.
714
+ 'explorer.downloadedNote': '已下载到本地镜像:{path}',
715
+ 'explorer.showInFolder': '在文件夹中显示',
716
+ 'explorer.dismissNote': '关闭提示',
698
717
  'explorer.menuCopyRel': '📋 复制相对地址',
699
718
  'explorer.menuCopyAbs': '📋 复制绝对地址',
700
719
  'explorer.menuRename': '✏ 重命名',
@@ -724,6 +743,7 @@ window.__ModuleLoader__.load({
724
743
  'file.dirty': '未保存',
725
744
  'file.saveHint': 'Ctrl/⌘+S 保存',
726
745
  'file.downloaded': '已下载到本地镜像{local}',
746
+ 'file.downloadedToComputer': '已开始下载到本机',
727
747
  'file.downloadedAt': ': {path}',
728
748
  'file.localCopyMissing': '远端没有此文件,但本地镜像中有同名副本。',
729
749
  'file.localCopyHelp': '可先只读查看,确认后上传到远端。上传仅创建新文件,不覆盖已有文件。',
@@ -1033,6 +1053,14 @@ window.__ModuleLoader__.load({
1033
1053
  'settings.backendOpensshAliasOk': '"Use a ~/.ssh/config alias" is on: the name is handed to ssh verbatim, and Port/User/IdentityFile/ProxyJump come from that Host block — the matching fields below have no effect (this is the "one source of truth" case, issue #50). A password/passphrase is still offered to ssh through askpass, and is only used if the Host block has no usable authentication.',
1034
1054
  'settings.sshBinary': 'ssh path',
1035
1055
  'settings.sshBinaryPlaceholder': 'Empty = the ssh on PATH',
1056
+ // Issue #206: the per-machine shell gets a settings input.
1057
+ 'settings.shell': 'Remote shell',
1058
+ 'settings.shellPlaceholder': 'Empty = auto-detect (where bash)',
1059
+ 'settings.shellHint': 'Windows remotes only: the bash.exe path (or a wrapper script) to use as the remote shell, overriding auto-detection — e.g. when auto-detect finds the WSL launcher stub, or your Git Bash needs a wrapper to survive sshd. Leave empty on POSIX remotes.',
1060
+ // Issue #212: gateways that allocate a remote PTY only for plain logins.
1061
+ 'settings.terminalNoCommand': 'Plain-login terminal',
1062
+ 'settings.terminalNoCommandLabel': 'Terminal dials a plain login (bastion / gateway hosts)',
1063
+ 'settings.terminalNoCommandHint': 'JumpServer-class gateways allocate a remote PTY only for logins WITHOUT a command: with one (even with -tt) there is no line discipline — Return does nothing and keys look dead. When checked, the generated terminal launcher sends a plain login instead of the cd-and-exec line: you get a real PTY (zsh line editing, window resize) at the cost of the automatic cd into the workspace. Leave unchecked for direct sshd hosts.',
1036
1064
  // Issue #54: the README documented `webAttachCommand` but the settings
1037
1065
  // UI had no field for it.
1038
1066
  'settings.webAttachCmd': 'Remote dsh command',
@@ -1199,6 +1227,8 @@ window.__ModuleLoader__.load({
1199
1227
  'settings.updateNow': 'Update now',
1200
1228
  'settings.updateMode': 'Update mode:',
1201
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',
1202
1232
 
1203
1233
  'settings.updateManual': 'Manual',
1204
1234
  'settings.updateAuto': 'Auto',
@@ -1318,6 +1348,13 @@ window.__ModuleLoader__.load({
1318
1348
  'explorer.menuExpand': '📂 Expand/collapse',
1319
1349
  'explorer.menuOpen': '📄 Open file',
1320
1350
  'explorer.menuDownload': '⬇ Download to local mirror',
1351
+ 'explorer.menuDownloadLocal': '⬇ Download to this computer',
1352
+ 'explorer.downloadLocal': 'Download to this computer',
1353
+ // Issue #207: mirror downloads are invisible without a picker — say
1354
+ // where the file landed and offer to reveal it.
1355
+ 'explorer.downloadedNote': 'Downloaded to the local mirror: {path}',
1356
+ 'explorer.showInFolder': 'Show in folder',
1357
+ 'explorer.dismissNote': 'Dismiss',
1321
1358
  'explorer.menuCopyRel': '📋 Copy relative path',
1322
1359
  'explorer.menuCopyAbs': '📋 Copy absolute path',
1323
1360
  'explorer.menuRename': '✏ Rename',
@@ -1347,6 +1384,7 @@ window.__ModuleLoader__.load({
1347
1384
  'file.dirty': 'unsaved',
1348
1385
  'file.saveHint': 'Ctrl/⌘+S to save',
1349
1386
  'file.downloaded': 'Downloaded to local mirror{local}',
1387
+ 'file.downloadedToComputer': 'Download started on this computer',
1350
1388
  'file.downloadedAt': ': {path}',
1351
1389
  'file.localCopyMissing': 'This file is missing remotely. A copy exists in the local mirror.',
1352
1390
  'file.localCopyHelp': 'Preview the local copy, then upload it. Upload creates a new remote file and never replaces an existing file.',
@@ -1492,6 +1530,52 @@ window.__ModuleLoader__.load({
1492
1530
  return Object.assign({}, body || {}, { sessionId }, localWorkspaceSession(sessionId) ? { workspace: 'local' } : {})
1493
1531
  }
1494
1532
 
1533
+ /**
1534
+ * Save a remote (or local-workspace) file on the machine running the BROWSER.
1535
+ *
1536
+ * The mirror download (POST /dsh-remote/fs op=download) only writes on the
1537
+ * DSH host, so a user who opens the page from their own desktop had no way to
1538
+ * get the file. The host streams it from /dsh-remote/download.
1539
+ */
1540
+ async function downloadRemoteFileToClient(sessionId, filePath) {
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
+ }
1555
+ return fetch(url, { credentials: 'same-origin' }).then(async (res) => {
1556
+ if (!res.ok) {
1557
+ const data = await res.json().catch(() => ({}))
1558
+ throw new Error(trHostError((data && (data.error || data.message))) || 'HTTP ' + res.status)
1559
+ }
1560
+ const named = res.headers.get('X-Dsh-Download-Name') || ''
1561
+ let name = String(filePath).split(/[\\/]/).filter(Boolean).pop() || 'download'
1562
+ if (named) { try { name = decodeURIComponent(named) } catch { /* keep the basename */ } }
1563
+ const blob = await res.blob()
1564
+ const href = URL.createObjectURL(blob)
1565
+ try {
1566
+ const anchor = document.createElement('a')
1567
+ anchor.href = href
1568
+ anchor.download = name
1569
+ anchor.rel = 'noopener'
1570
+ anchor.style.display = 'none'
1571
+ document.body.appendChild(anchor)
1572
+ anchor.click()
1573
+ window.setTimeout(() => { try { anchor.remove(); URL.revokeObjectURL(href) } catch { /* ignore */ } }, 1000)
1574
+ } catch (err) { URL.revokeObjectURL(href); throw err }
1575
+ return name
1576
+ })
1577
+ }
1578
+
1495
1579
  async function api(method, path, body, signal) {
1496
1580
  const opts = { method, headers: {}, ...(signal ? { signal } : {}) }
1497
1581
  if (body) { opts.headers['Content-Type'] = 'application/json'; opts.body = JSON.stringify(body) }
@@ -2350,6 +2434,10 @@ window.__ModuleLoader__.load({
2350
2434
  proxyUser: (m.proxy && m.proxy.username) || '', proxyPassword: '', proxyKey: (m.proxy && m.proxy.privateKeyPath) || '',
2351
2435
  // Issue #51: the transport backend is per machine.
2352
2436
  backend: m.backend === 'openssh' ? 'openssh' : 'native', sshBinary: m.sshBinary || '',
2437
+ // Issue #206: the per-machine remote shell (Windows remotes).
2438
+ shell: m.shell || '',
2439
+ // Issue #212: plain-login terminal for PTY-stingy gateways.
2440
+ terminalNoCommand: !!m.terminalNoCommand,
2353
2441
  // Issue #54: the per-machine remote-dsh command for Web UI attach.
2354
2442
  webAttachCommand: m.webAttachCommand || '',
2355
2443
  // Issue #125: its resident-instance discover sibling.
@@ -2366,7 +2454,7 @@ window.__ModuleLoader__.load({
2366
2454
  setForm(next)
2367
2455
  setFormOpen(true)
2368
2456
  // 编辑时若该机器用了高级配置(私钥/agent/跳板/钥匙串/系统 OpenSSH 后端),自动展开折叠区
2369
- setAdvOpen(!!(m.privateKeyPath || m.useAgent || m.keyboardInteractive || (m.proxy && m.proxy.host) || m.backend === 'openssh' || m.webAttachCommand || m.webAttachDiscoverCommand || (m.credentialBackend && m.credentialBackend !== 'plain')))
2457
+ setAdvOpen(!!(m.privateKeyPath || m.useAgent || m.keyboardInteractive || (m.proxy && m.proxy.host) || m.backend === 'openssh' || m.shell || m.webAttachCommand || m.webAttachDiscoverCommand || (m.credentialBackend && m.credentialBackend !== 'plain')))
2370
2458
  }
2371
2459
  const startEdit = (machine) => {
2372
2460
  if (busy) return
@@ -2383,7 +2471,7 @@ window.__ModuleLoader__.load({
2383
2471
  }
2384
2472
  const clearForm = () => {
2385
2473
  setFormOpen(false)
2386
- setForm({ name: '', host: '', port: '22', username: 'root', password: '', privateKeyPath: '', passphrase: '', workspace: '', hostKeyMode: '', useAgent: false, keyboardInteractive: false, encryptPassword: false, proxyHost: '', proxyPort: '22', proxyUser: '', proxyPassword: '', proxyKey: '', backend: 'native', sshBinary: '', webAttachCommand: '', webAttachDiscoverCommand: '', id: '', useSshConfig: false, passwordSet: false, passphraseSet: false, proxyPasswordSet: false })
2474
+ setForm({ name: '', host: '', port: '22', username: 'root', password: '', privateKeyPath: '', passphrase: '', workspace: '', hostKeyMode: '', useAgent: false, keyboardInteractive: false, encryptPassword: false, proxyHost: '', proxyPort: '22', proxyUser: '', proxyPassword: '', proxyKey: '', backend: 'native', sshBinary: '', shell: '', terminalNoCommand: false, webAttachCommand: '', webAttachDiscoverCommand: '', id: '', useSshConfig: false, passwordSet: false, passphraseSet: false, proxyPasswordSet: false })
2387
2475
  }
2388
2476
  const save = (action) => {
2389
2477
  if (busy) return
@@ -2400,6 +2488,10 @@ window.__ModuleLoader__.load({
2400
2488
  encryptPassword: form.encryptPassword, useSshConfig: !!form.useSshConfig,
2401
2489
  // Issue #51: the transport backend (and, for `openssh`, the executable).
2402
2490
  backend: form.backend || 'native', sshBinary: form.sshBinary || '',
2491
+ // Issue #206: the per-machine remote shell (Windows remotes).
2492
+ shell: form.shell || '',
2493
+ // Issue #212: plain-login terminal for PTY-stingy gateways.
2494
+ terminalNoCommand: !!form.terminalNoCommand,
2403
2495
  // Issue #54: the per-machine remote-dsh command for Web UI attach.
2404
2496
  webAttachCommand: form.webAttachCommand || '',
2405
2497
  // Issue #125: the per-machine resident-instance discover command.
@@ -2932,6 +3024,11 @@ window.__ModuleLoader__.load({
2932
3024
  (form.backend === 'openssh')
2933
3025
  ? row(tr('settings.sshBinary'), React.createElement('input', { value: form.sshBinary || '', onChange: setF('sshBinary'), placeholder: tr('settings.sshBinaryPlaceholder'), style: inputS }), 'sb')
2934
3026
  : null,
3027
+ // Issue #206: where the Git Bash wrapper comes from on Windows
3028
+ // remotes (empty = auto-detect). Both backends' detection reads it,
3029
+ // so it renders for either backend, right after sshBinary.
3030
+ row(tr('settings.shell'), React.createElement('input', { 'data-testid': 'machine-shell', value: form.shell || '', onChange: setF('shell'), placeholder: tr('settings.shellPlaceholder'), style: inputS }), 'msh'),
3031
+ React.createElement('div', { style: { paddingLeft: LABEL_W + 12, marginBottom: 8, fontSize: 11, lineHeight: 1.5, opacity: 0.7 } }, tr('settings.shellHint')),
2935
3032
  row(tr('settings.privateKey'), React.createElement('input', { value: form.privateKeyPath, onChange: setF('privateKeyPath'), placeholder: 'Empty = password or agent', style: inputS }), 'k'),
2936
3033
  row(tr('settings.passphrase'), React.createElement('input', { type: 'password', value: form.passphrase, onChange: setF('passphrase'), placeholder: form.passphraseSet ? tr('settings.secretSavedPlaceholder') : 'Encrypted private key passphrase', style: inputS, title: form.passphraseSet ? tr('settings.secretSavedHint') : '' }), 'pp'),
2937
3034
  form.passphraseSet
@@ -2942,6 +3039,12 @@ window.__ModuleLoader__.load({
2942
3039
  React.createElement(RwCheckbox, { checked: form.useAgent, onChange: setB('useAgent'), label: tr('settings.agent') }),
2943
3040
  React.createElement(RwCheckbox, { checked: form.keyboardInteractive, onChange: setB('keyboardInteractive'), label: tr('settings.keyboardInteractive') }),
2944
3041
  React.createElement(RwCheckbox, { checked: form.encryptPassword, onChange: setB('encryptPassword'), label: tr('settings.encryptPassword') })),
3042
+ // Issue #212: gateways (JumpServer-class bastions) that allocate a
3043
+ // remote PTY only for plain logins need the terminal launcher to
3044
+ // dial WITHOUT the cd-and-exec command; otherwise the shell has no
3045
+ // line discipline and keys look dead.
3046
+ row(tr('settings.terminalNoCommand'), React.createElement(RwCheckbox, { 'data-testid': 'terminal-no-command', checked: !!form.terminalNoCommand, onChange: () => setForm((f) => ({ ...f, terminalNoCommand: !f.terminalNoCommand })), label: tr('settings.terminalNoCommandLabel') }), 'tnc'),
3047
+ React.createElement('div', { style: { paddingLeft: LABEL_W + 12, marginBottom: 8, fontSize: 11, lineHeight: 1.5, opacity: 0.7 } }, tr('settings.terminalNoCommandHint')),
2945
3048
  row(tr('settings.proxyHost'), React.createElement('input', { value: form.proxyHost, onChange: setF('proxyHost'), placeholder: 'Route through this host (optional)', style: inputS }), 'ph'),
2946
3049
  row(tr('settings.proxyPortUser'), React.createElement('div', { style: { display: 'flex', gap: 6, flex: 1, flexWrap: 'wrap' } },
2947
3050
  React.createElement('input', { value: form.proxyPort, onChange: setF('proxyPort'), placeholder: 'Port (22)', style: { ...inputS, minWidth: 90, maxWidth: 120 } }),
@@ -3250,6 +3353,12 @@ window.__ModuleLoader__.load({
3250
3353
  )
3251
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) })),
3252
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
+ ),
3253
3362
  upd?.lastReload?.ok === false
3254
3363
  ? React.createElement('div', { role: 'status', style: { marginTop: 8, fontSize: 12, lineHeight: 1.6, color: T.warn } }, tr('settings.updateReloadFailed', { reason: upd.lastReload.reason || '' }))
3255
3364
  : null,
@@ -4972,6 +5081,7 @@ window.__ModuleLoader__.load({
4972
5081
  right: 'm6 4 4 4-4 4',
4973
5082
  left: 'm10 4-4 4 4 4',
4974
5083
  more: 'M3 8h.01M8 8h.01M13 8h.01',
5084
+ download: 'M8 2v8m0 0 3.2-3.2M8 10 4.8 6.8M2.5 13h11',
4975
5085
  }
4976
5086
  return React.createElement('svg', { width: size, height: size, viewBox: '0 0 16 16', fill: 'none', stroke: 'currentColor', strokeWidth: 1.25, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true, className, style: { flexShrink: 0 } }, React.createElement('path', { d: paths[name] || paths.file }))
4977
5087
  }
@@ -5110,6 +5220,11 @@ window.__ModuleLoader__.load({
5110
5220
  const dataRef = React.useRef(data)
5111
5221
  const [err, setErr] = React.useState('')
5112
5222
  const [busy, setBusy] = React.useState('')
5223
+ // Issue #207: the local path of the last mirror download from the tree's
5224
+ // context menu — shown with a "show in folder" action, because the
5225
+ // download itself is invisible (no path picker is involved by design).
5226
+ const [dlNote, setDlNote] = React.useState(null)
5227
+ const revealDlNote = (p) => api('POST', '/dsh-remote/fs', withSessionBody({ op: 'revealLocal', path: p }, sessionId)).catch(() => { /* best-effort; the path is still shown */ })
5113
5228
  const [picker, setPicker] = React.useState(false)
5114
5229
  // Issue #180: the remote root the user EXPLICITLY picked in this panel.
5115
5230
  // It only ever overrides what this session's explorer shows — it is never
@@ -5307,6 +5422,7 @@ window.__ModuleLoader__.load({
5307
5422
  if (!m) return
5308
5423
  if (id === 'open') { if (m.isDir) { if (props.onToggleDir) props.onToggleDir(m.path) } else openFile(m.path); return }
5309
5424
  if (id === 'download') { doFs('download', { path: m.path }); return }
5425
+ if (id === 'download-client') { downloadToComputer(m.path); return }
5310
5426
  if (id === 'copy-rel') { copyPath(relPath(m.path), m.path); return }
5311
5427
  if (id === 'copy-abs') { copyPath(m.path, m.path); return }
5312
5428
  if (id === 'rename') { setNamePrompt({ kind: 'rename', path: m.path, name: m.name }); return }
@@ -5332,7 +5448,8 @@ window.__ModuleLoader__.load({
5332
5448
  return d
5333
5449
  }
5334
5450
  box.appendChild(mkItem(menu.isDir ? tr('explorer.menuExpand') : tr('explorer.menuOpen'), false, () => runMenuAction('open', menu)))
5335
- if (!localWorkspaceSession(sessionId)) box.appendChild(mkItem(tr('explorer.menuDownload'), false, () => runMenuAction('download', menu)))
5451
+ if (!menu.isDir) box.appendChild(mkItem(tr('explorer.menuDownloadLocal'), false, () => runMenuAction('download-client', menu)))
5452
+ if (!menu.isDir && !localWorkspaceSession(sessionId)) box.appendChild(mkItem(tr('explorer.menuDownload'), false, () => runMenuAction('download', menu)))
5336
5453
  box.appendChild(mkItem(tr('explorer.menuCopyRel'), false, () => runMenuAction('copy-rel', menu)))
5337
5454
  box.appendChild(mkItem(tr('explorer.menuCopyAbs'), false, () => runMenuAction('copy-abs', menu)))
5338
5455
  box.appendChild(mkItem(tr('explorer.menuRename'), false, () => runMenuAction('rename', menu)))
@@ -5390,17 +5507,27 @@ window.__ModuleLoader__.load({
5390
5507
 
5391
5508
  const doFs = (op, payload, refreshParent) => {
5392
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
+ }
5393
5515
  setBusy(op)
5394
5516
  return api('POST', '/dsh-remote/fs', withSessionBody({ op, ...payload }, sessionId))
5395
- .then(() => {
5517
+ .then((r) => {
5396
5518
  if (viewRef.current !== view) return
5397
5519
  setErr('')
5398
- if (refreshParent) {
5399
- if (root) loadDir(root, { force: true })
5400
- for (const dir of expanded) if (dir !== root) loadDir(dir, { force: true })
5401
- }
5520
+ // Issue #207: the explorer used to discard the download response —
5521
+ // the file landed in the local mirror with zero feedback, reading
5522
+ // as "the download did nothing".
5523
+ if (op === 'download' && r && r.local) setDlNote({ path: String(r.local) })
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()
5402
5530
  })
5403
- .catch((e) => { if (viewRef.current === view) setErr(String(e.message || e)) })
5404
5531
  .finally(() => { if (viewRef.current === view) setBusy('') })
5405
5532
  }
5406
5533
 
@@ -5440,6 +5567,11 @@ window.__ModuleLoader__.load({
5440
5567
  ? React.createElement('span', { style: { fontSize: 11, opacity: 0.75, flexShrink: 0, color: T.ok } }, tr('explorer.copied'))
5441
5568
  : null)
5442
5569
 
5570
+ const downloadToComputer = (p) => {
5571
+ setErr('')
5572
+ downloadRemoteFileToClient(sessionId, p).catch((e) => setErr(String((e && e.message) || e)))
5573
+ }
5574
+
5443
5575
  // One tree row (dir toggles via the framework's onToggleDir; file opens).
5444
5576
  // Text uses the normal foreground (theme-following) — no accent green.
5445
5577
  const treeKeyDown = (e) => {
@@ -5520,6 +5652,16 @@ window.__ModuleLoader__.load({
5520
5652
  React.createElement('span', { style: { flexShrink: 0, display: 'inline-flex' } }, IconFile(entry.name)),
5521
5653
  React.createElement('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', flex: 1 } }, entry.name),
5522
5654
  copiedMark(entry.path),
5655
+ hovered ? React.createElement('span', {
5656
+ className: 'dsh-rw-row-download',
5657
+ role: 'button',
5658
+ tabIndex: -1,
5659
+ title: tr('explorer.downloadLocal'),
5660
+ 'aria-label': tr('explorer.downloadLocal'),
5661
+ onClick: (e) => { e.preventDefault(); e.stopPropagation(); downloadToComputer(entry.path) },
5662
+ onKeyDown: (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); e.stopPropagation(); downloadToComputer(entry.path) } },
5663
+ style: { flexShrink: 0, display: 'inline-flex', alignItems: 'center', color: T.muted, cursor: 'pointer', padding: '0 2px' },
5664
+ }, React.createElement(WorkbenchIcon, { name: 'download', size: 13 })) : null,
5523
5665
  (entry.size != null || entry.mtime)
5524
5666
  ? React.createElement('span', { className: 'dsh-rw-row-meta', style: { fontSize: 10, flexShrink: 0, fontFamily: 'monospace' }, title: entry.mtime ? fmtTime(entry.mtime) : '' }, humanSize(entry.size))
5525
5667
  : null,
@@ -5601,6 +5743,10 @@ window.__ModuleLoader__.load({
5601
5743
  connectionState === 'interrupted' && root ? React.createElement('div', { role: 'status', style: { padding: '6px 10px', display: 'flex', gap: 6, fontSize: 11, color: T.warn, background: T.bg } },
5602
5744
  React.createElement('span', { style: { flex: 1 } }, tr('explorer.connection.interrupted')),
5603
5745
  React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: buttonS, onClick: () => refreshStatus({ force: true }) }, tr('project.retry'))) : null,
5746
+ dlNote ? React.createElement('div', { role: 'status', style: { padding: '6px 10px', display: 'flex', gap: 6, fontSize: 11, alignItems: 'center', background: T.bg } },
5747
+ React.createElement('span', { style: { flex: 1, wordBreak: 'break-all' }, title: dlNote.path }, tr('explorer.downloadedNote', { path: dlNote.path })),
5748
+ React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: buttonS, onClick: () => revealDlNote(dlNote.path) }, tr('explorer.showInFolder')),
5749
+ React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: buttonS, onClick: () => setDlNote(null), 'aria-label': tr('explorer.dismissNote') }, '✕')) : null,
5604
5750
  remoteTerminal.error ? React.createElement('div', { role: 'alert', style: { padding: '6px 10px', color: T.danger, fontSize: 12 } }, remoteTerminal.error) : null,
5605
5751
  picker ? React.createElement('div', { style: { padding: 8 } }, React.createElement(DirPicker, {
5606
5752
  open: true, busy: false, registerWorkspace: false, initialTab: 'remote',
@@ -5658,7 +5804,8 @@ window.__ModuleLoader__.load({
5658
5804
  contextual: true,
5659
5805
  items: [
5660
5806
  { id: 'open', label: menu.isDir ? tr('explorer.menuExpand') : tr('explorer.menuOpen') },
5661
- ...(!localWorkspaceSession(sessionId) ? [{ id: 'download', label: tr('explorer.menuDownload') }] : []),
5807
+ ...(menu.isDir ? [] : [{ id: 'download-client', label: tr('explorer.menuDownloadLocal') }]),
5808
+ ...(!menu.isDir && !localWorkspaceSession(sessionId) ? [{ id: 'download', label: tr('explorer.menuDownload') }] : []),
5662
5809
  { id: 'copy-rel', label: tr('explorer.menuCopyRel') },
5663
5810
  { id: 'copy-abs', label: tr('explorer.menuCopyAbs') },
5664
5811
  { id: 'rename', label: tr('explorer.menuRename') },
@@ -6205,6 +6352,10 @@ window.__ModuleLoader__.load({
6205
6352
  const [findIndex, setFindIndex] = React.useState(0)
6206
6353
  const [cursor, setCursor] = React.useState({ line: 1, col: 1 })
6207
6354
  const [copyNote, setCopyNote] = React.useState('')
6355
+ // Issue #207: the local path of the last mirror download (shown with a
6356
+ // "show in folder" action; dismissible).
6357
+ const [dlLocal, setDlLocal] = React.useState('')
6358
+ const revealLocal = (p) => api('POST', '/dsh-remote/fs', withSessionBody({ op: 'revealLocal', path: p }, fileSessionId)).catch(() => { /* revealing is best-effort; the path is still shown */ })
6208
6359
  const scrollRef = React.useRef(null)
6209
6360
  const editorRef = React.useRef(null)
6210
6361
  const findRef = React.useRef(null)
@@ -6370,7 +6521,22 @@ window.__ModuleLoader__.load({
6370
6521
  const downloadMirror = () => {
6371
6522
  setSaving(true); setErr('')
6372
6523
  api('POST', '/dsh-remote/fs', withSessionBody({ op: 'download', path }, fileSessionId))
6373
- .then((r) => { if (fileViewRef.current === draftKey) setCopyNote(tr('file.downloaded', { local: (r && r.local ? tr('file.downloadedAt', { path: r.local }) : '') })) })
6524
+ .then((r) => {
6525
+ if (fileViewRef.current !== draftKey) return
6526
+ setCopyNote(tr('file.downloaded', { local: (r && r.local ? tr('file.downloadedAt', { path: r.local }) : '') }))
6527
+ // Issue #207: the file lands in the local mirror — make that
6528
+ // actionable instead of a transient note the user never connects
6529
+ // to a place on disk.
6530
+ setDlLocal(r && r.local ? String(r.local) : '')
6531
+ })
6532
+ .catch((e) => { if (fileViewRef.current === draftKey) setErr(String((e && e.message) || e)) })
6533
+ .finally(() => { if (fileViewRef.current === draftKey) setSaving(false) })
6534
+ }
6535
+
6536
+ const downloadToBrowser = () => {
6537
+ setSaving(true); setErr('')
6538
+ downloadRemoteFileToClient(fileSessionId, path)
6539
+ .then((name) => { if (name && fileViewRef.current === draftKey) setCopyNote(tr('file.downloadedToComputer')) })
6374
6540
  .catch((e) => { if (fileViewRef.current === draftKey) setErr(String((e && e.message) || e)) })
6375
6541
  .finally(() => { if (fileViewRef.current === draftKey) setSaving(false) })
6376
6542
  }
@@ -6421,6 +6587,7 @@ window.__ModuleLoader__.load({
6421
6587
  React.createElement(WorkbenchAction, { icon: 'search', label: tr('workbench.find'), pressed: findOpen, disabled: !data || data.binary || data.image, onClick: () => { setFindOpen((v) => !v); setSourceMode(true); keepView({ sourceMode: true }) } }),
6422
6588
  React.createElement(WorkbenchAction, { icon: 'wrap', label: tr('workbench.wrap'), pressed: wrap, onClick: () => { setWrap(!wrap); keepView({ wrap: !wrap }) } }),
6423
6589
  React.createElement(WorkbenchAction, { icon: 'copy', label: tr('workbench.copyContent'), disabled: !data || data.binary || data.image, onClick: () => copy(edit ? draft : originalText) }),
6590
+ React.createElement(WorkbenchAction, { icon: 'download', label: tr('file.download'), disabled: loading || saving || !path || !!localCopy, onClick: downloadToBrowser }),
6424
6591
  React.createElement(WorkbenchAction, { icon: 'terminal', label: tr('workbench.openTerminal'), disabled: remoteTerminal.pending, onClick: remoteTerminal.open }),
6425
6592
  edit ? React.createElement(React.Fragment, null,
6426
6593
  React.createElement('button', { type: 'button', className: 'dsh-rw-btn dsh-rw-primary', style: { ...primaryBtnS, padding: '4px 10px', fontSize: 12 }, onClick: saveRemote, disabled: saving || !dirty || saveConflict, title: tr('file.saveHint') }, saving ? tr('file.saving') : tr('file.saveToRemote')),
@@ -6516,7 +6683,10 @@ window.__ModuleLoader__.load({
6516
6683
  React.createElement('span', {}, data && data.size != null ? humanSize(data.size) : ''),
6517
6684
  React.createElement('span', {}, baseName.includes('.') ? baseName.split('.').pop().toUpperCase() : 'TEXT'),
6518
6685
  data?.eol ? React.createElement('span', {}, data.eol === 'crlf' ? 'CRLF' : data.eol === 'mixed' ? tr('file.mixedEol') : 'LF') : null,
6519
- React.createElement('span', { style: { marginLeft: 'auto', color: copyNote ? T.ok : T.muted } }, copyNote || (localPreview ? tr('file.localCopySource') : loading && data ? tr('workbench.refreshing') : edit ? tr('file.editing') : tr('file.readonly')))),
6686
+ React.createElement('span', { style: { marginLeft: 'auto', color: copyNote ? T.ok : T.muted } }, copyNote || (localPreview ? tr('file.localCopySource') : loading && data ? tr('workbench.refreshing') : edit ? tr('file.editing') : tr('file.readonly'))),
6687
+ dlLocal ? React.createElement('span', { style: { display: 'flex', gap: 6, alignItems: 'center' } },
6688
+ React.createElement('button', { type: 'button', className: 'dsh-rw-btn', onClick: () => revealLocal(dlLocal), title: dlLocal }, tr('explorer.showInFolder')),
6689
+ React.createElement('button', { type: 'button', className: 'dsh-rw-btn', onClick: () => setDlLocal(''), 'aria-label': tr('explorer.dismissNote') }, '✕')) : null),
6520
6690
  )
6521
6691
  }
6522
6692
 
@@ -6555,37 +6725,35 @@ window.__ModuleLoader__.load({
6555
6725
  disposers.forEach((d) => { try { d() } catch {} })
6556
6726
  return
6557
6727
  }
6558
- let autoOpenedFor = new Set()
6559
- let disposeAuto = null
6728
+ const autoOpenedFor = new Set()
6729
+ let disposed = false
6560
6730
  const tryAutoOpen = () => {
6561
- if (typeof bs.subscribeState !== 'function') return
6562
- const snap = bs.getSnapshot && bs.getSnapshot()
6563
- if (!snap || !snap.sessionId) return
6564
- if (autoOpenedFor.has(snap.sessionId)) return
6565
- const sessionId = snap.sessionId
6566
- // Native and better-sidebar await the SAME effective preference. Only
6567
- // after it resolves may we resolve the remote path and call openTab.
6568
- void explorerAutoOpenPreference().then((enabled) => {
6569
- if (!enabled || autoOpenedFor.has(sessionId)) return
6570
- // Issue #13: only auto-open for a genuinely remote session. A plain
6571
- // local session must never borrow the active machine's workspace.
6572
- return resolveSessionRemote(sessionId).then((remotePath) => {
6573
- if (!remotePath || autoOpenedFor.has(sessionId)) return
6574
- autoOpenedFor.add(sessionId)
6575
- try {
6576
- bs.openTab({ type: SIDEBAR_EXPLORER_ID, title: tr('explorer.tabTitle'), path: remotePath })
6577
- } catch (e2) {
6578
- console.warn('[dsh-remote] better-sidebar auto-open skipped:', e2)
6579
- }
6580
- })
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)
6581
6747
  })
6582
6748
  }
6583
- tryAutoOpen()
6584
6749
  if (typeof bs.subscribeState === 'function') {
6585
- disposeAuto = bs.subscribeState(tryAutoOpen)
6586
- disposers.push(disposeAuto)
6750
+ tryAutoOpen()
6751
+ disposers.push(bs.subscribeState(tryAutoOpen))
6752
+ }
6753
+ return () => {
6754
+ disposed = true
6755
+ disposers.forEach((d) => { try { d() } catch {} })
6587
6756
  }
6588
- return () => disposers.forEach((d) => { try { d() } catch {} })
6589
6757
  }
6590
6758
 
6591
6759
  // Official Desktop's right-sidebar extension contract. Reuse the SSH
@@ -7127,15 +7295,27 @@ window.__ModuleLoader__.load({
7127
7295
  const patch = currentDiff?.data?.patch || ''
7128
7296
  const patchLines = patch.split('\n')
7129
7297
  if (patchLines[patchLines.length - 1] === '') patchLines.pop()
7130
- let nextLine = null
7298
+ let nextLine = 0, oldRemaining = 0, newRemaining = 0
7131
7299
  const rows = patchLines.slice(0, 1800).map((text, index) => {
7132
- const hunk = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/.exec(text)
7300
+ const hunk = /^@@ -\d+(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/.exec(text)
7133
7301
  let line = null, kind = 'meta'
7134
- if (hunk) { nextLine = Number(hunk[1]); kind = 'hunk' }
7135
- else if (nextLine !== null && !/^--- |^\+\+\+ /.test(text)) {
7136
- if (text[0] === '+') { line = nextLine++; kind = 'added' }
7137
- else if (text[0] === ' ') { line = nextLine++; kind = 'context' }
7138
- else if (text[0] === '-') kind = 'removed'
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'
7139
7319
  }
7140
7320
  const canOpen = !!line && line > 0 && !chosen?.deleted && typeof props.openFile === 'function'
7141
7321
  return React.createElement('div', { key: index, className: 'dsh-rw-git-diff-line', 'data-rw-diff-kind': kind },
@@ -7339,6 +7519,28 @@ window.__ModuleLoader__.load({
7339
7519
  } catch { return { enabled: false, left: 240, right: 400 } }
7340
7520
  }
7341
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
+ }
7342
7544
  function remoteIdeSet(change) {
7343
7545
  remoteIdeState = { ...remoteIdeState, ...change }
7344
7546
  try { window.localStorage.setItem(REMOTE_IDE_KEY, JSON.stringify(remoteIdeState)) } catch { /* private browsing */ }
@@ -7363,6 +7565,10 @@ window.__ModuleLoader__.load({
7363
7565
  function RemoteIdeToggle(props) {
7364
7566
  const mirror = useSessionMirror(props.sessionId, props.useSessions)
7365
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
7366
7572
  if (!mirror && !localWorkspaceSession(props.sessionId)) return null
7367
7573
  const supported = !!remoteIdeController?.mounted?.getSnapshot && typeof remoteIdeController.openResourceIn === 'function'
7368
7574
  return React.createElement('button', {
@@ -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
+ }