dsh-remote 1.3.0 → 1.4.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 +2 -0
- package/README.md +2 -0
- package/lib/client.js +290 -11
- package/lib/deck-bridge.js +17 -0
- package/lib/errors.js +5 -2
- package/lib/main.js +19 -0
- package/lib/openssh.js +119 -5
- package/lib/pool.js +46 -4
- package/lib/update.js +163 -34
- package/lib/workspace-files-remote.js +479 -0
- package/package.json +4 -3
package/README.en.md
CHANGED
|
@@ -18,6 +18,8 @@ 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.0 release notes](https://github.com/flymysql/dsh-remote/blob/main/docs/release/1.4.0.md): mirror-session file previews read the remote, Markdown figures render, one OpenSSH connect-timeout retry, workspace picker restored.
|
|
22
|
+
|
|
21
23
|
## Install
|
|
22
24
|
|
|
23
25
|
```bash
|
package/README.md
CHANGED
|
@@ -26,6 +26,8 @@ dsh plugin --profile web add dsh-remote
|
|
|
26
26
|
|
|
27
27
|
安装或升级后,重启 DSH Web 并刷新页面。自动更新状态在设置 → 远程工作区 → 插件偏好中查看。
|
|
28
28
|
|
|
29
|
+
[1.4.0 更新说明](https://github.com/flymysql/dsh-remote/blob/main/docs/release/1.4.0.md):镜像会话文件预览直读远端、Markdown 插图渲染、OpenSSH 建连超时重试、工作区选择器恢复。
|
|
30
|
+
|
|
29
31
|
## 3 步开始
|
|
30
32
|
|
|
31
33
|
1. **配置主机**:设置 → 远程工作区,编辑 SSH 配置或保存主机凭据;直接写在 `~/.ssh/config` 里的 Host 会出现在主机列表中,点该行的「…」菜单 →「编辑」即可保存成机器并填写登录密码(保存前后入口都是同一个「…」菜单)。打开设置会自动检查连通性,无需手动“连接”。
|
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.4.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
|
|
@@ -603,7 +603,7 @@ window.__ModuleLoader__.load({
|
|
|
603
603
|
'settings.updateAppliedNoReload': '✅ 已更新到 v{to}({from} → {to})。重启 Harness 生效。',
|
|
604
604
|
'settings.updatePendingReload': '磁盘已是 v{disk},运行中仍是 v{loaded}。请完全重启 DSH 并刷新页面。',
|
|
605
605
|
'settings.selfUpdateBlocked': 'ℹ️ 当前是 link:/开发模式安装(不在 node_modules 下),已禁止自动更新以免覆盖源码——请在你的源码仓库里更新。',
|
|
606
|
-
'settings.updateRegistryError': '
|
|
606
|
+
'settings.updateRegistryError': '更新来源查询失败:{msg}',
|
|
607
607
|
'settings.updateFailed': '更新失败',
|
|
608
608
|
'settings.updateFailedMsg': '更新失败: {msg}',
|
|
609
609
|
'settings.registryUnreachable': '无法连接 npm registry',
|
|
@@ -675,6 +675,10 @@ window.__ModuleLoader__.load({
|
|
|
675
675
|
'explorer.refresh': '刷新',
|
|
676
676
|
'explorer.newDir': '新建目录',
|
|
677
677
|
'explorer.more': '…',
|
|
678
|
+
'explorer.pickRemote': '选择远程工作区',
|
|
679
|
+
'explorer.pickRemoteHint': '在远程主机上选择要浏览的目录(只影响这个会话的文件面板,不改动会话的工作区绑定)',
|
|
680
|
+
'explorer.retry': '重试',
|
|
681
|
+
'explorer.registryUnavailable': '暂时无法读取远程工作区列表,因此无法判断这个会话是不是远程会话。请重试。',
|
|
678
682
|
'explorer.remoteWs': '远程工作区: {path}{host}',
|
|
679
683
|
'explorer.hostTag': ' ({user}@{host})',
|
|
680
684
|
'explorer.noRemoteWs': '未设置远程工作区',
|
|
@@ -1222,7 +1226,7 @@ window.__ModuleLoader__.load({
|
|
|
1222
1226
|
'settings.updateAppliedNoReload': '✅ Updated to v{to} ({from} → {to}). Restart Harness to apply.',
|
|
1223
1227
|
'settings.updatePendingReload': 'v{disk} is on disk; v{loaded} is still running. Restart DSH and refresh this page.',
|
|
1224
1228
|
'settings.selfUpdateBlocked': 'ℹ️ This is a link:/dev install (not under node_modules), so self-update is disabled to avoid overwriting source — update it from its source repo.',
|
|
1225
|
-
'settings.updateRegistryError': '
|
|
1229
|
+
'settings.updateRegistryError': 'Update sources unavailable: {msg}',
|
|
1226
1230
|
'settings.updateFailed': 'Update failed',
|
|
1227
1231
|
'settings.updateFailedMsg': 'Update failed: {msg}',
|
|
1228
1232
|
'settings.registryUnreachable': 'Cannot reach the npm registry',
|
|
@@ -1294,6 +1298,10 @@ window.__ModuleLoader__.load({
|
|
|
1294
1298
|
'explorer.refresh': 'Refresh',
|
|
1295
1299
|
'explorer.newDir': 'New directory',
|
|
1296
1300
|
'explorer.more': '…',
|
|
1301
|
+
'explorer.pickRemote': 'Pick a remote workspace',
|
|
1302
|
+
'explorer.pickRemoteHint': 'Pick a directory on the remote host (affects only this session’s file panel; the session’s workspace binding is untouched)',
|
|
1303
|
+
'explorer.retry': 'Retry',
|
|
1304
|
+
'explorer.registryUnavailable': 'Could not read the remote workspace list, so this session cannot be classified as local or remote. Please retry.',
|
|
1297
1305
|
'explorer.remoteWs': 'Remote workspace: {path}{host}',
|
|
1298
1306
|
'explorer.hostTag': ' ({user}@{host})',
|
|
1299
1307
|
'explorer.noRemoteWs': 'No remote workspace set',
|
|
@@ -5103,6 +5111,11 @@ window.__ModuleLoader__.load({
|
|
|
5103
5111
|
const [err, setErr] = React.useState('')
|
|
5104
5112
|
const [busy, setBusy] = React.useState('')
|
|
5105
5113
|
const [picker, setPicker] = React.useState(false)
|
|
5114
|
+
// Issue #180: the remote root the user EXPLICITLY picked in this panel.
|
|
5115
|
+
// It only ever overrides what this session's explorer shows — it is never
|
|
5116
|
+
// written into the session's workspace binding and never used as a
|
|
5117
|
+
// fallback for "the current machine" (issue #13).
|
|
5118
|
+
const [pickedRoot, setPickedRoot] = React.useState('')
|
|
5106
5119
|
const [menu, setMenu] = React.useState(null) // { x, y, path, isDir, name }
|
|
5107
5120
|
const [rootOpen, setRootOpen] = React.useState(true) // first level expanded by default
|
|
5108
5121
|
const [hoverPath, setHoverPath] = React.useState('') // row hover highlight
|
|
@@ -5235,20 +5248,35 @@ window.__ModuleLoader__.load({
|
|
|
5235
5248
|
const resolveRoot = async () => {
|
|
5236
5249
|
if (opts?.force) await refreshMirrors()
|
|
5237
5250
|
else await ensureMirrors()
|
|
5238
|
-
|
|
5251
|
+
// An explicit pick wins over everything below, but ONLY while this
|
|
5252
|
+
// session has no mirror of its own to honour: a session that IS bound
|
|
5253
|
+
// to a remote workspace must always show that binding (issue #13).
|
|
5254
|
+
const picked = String(pickedRoot || '')
|
|
5255
|
+
if (localWorkspaceSession(sessionId)) {
|
|
5256
|
+
if (picked) return picked
|
|
5257
|
+
return fetchWorkspaceContext(sessionId).then(value => value.root || '')
|
|
5258
|
+
}
|
|
5239
5259
|
if (scopeCwd) {
|
|
5240
5260
|
return api('GET', '/dsh-remote/resolve-mirror?local=' + encodeURIComponent(scopeCwd))
|
|
5241
|
-
.then((r) => (r && r.remotePath) || '')
|
|
5261
|
+
.then((r) => (r && r.remotePath) || picked || '')
|
|
5242
5262
|
|
|
5243
5263
|
}
|
|
5244
|
-
if (sessionId) return resolveSessionRemote(sessionId, true)
|
|
5245
|
-
return Promise.resolve(
|
|
5264
|
+
if (sessionId) return resolveSessionRemote(sessionId, true).then((r) => r || picked || '')
|
|
5265
|
+
return Promise.resolve(picked)
|
|
5246
5266
|
}
|
|
5247
5267
|
resolveRoot().then((r) => {
|
|
5248
5268
|
if (!current()) return
|
|
5249
5269
|
return fetchRemoteStatus(sessionId).then((s) => {
|
|
5250
5270
|
if (!current()) return
|
|
5251
5271
|
if (s) setStatus(s)
|
|
5272
|
+
// Issue #180: with the mirror registry unreadable we cannot tell a
|
|
5273
|
+
// local session from a remote one we failed to recognise, so the
|
|
5274
|
+
// "this session is a local workspace" copy is a guess. Say what
|
|
5275
|
+
// actually happened instead of silently showing an empty local pane.
|
|
5276
|
+
if (!r && !localWorkspaceSession(sessionId) && MIRRORS.error) {
|
|
5277
|
+
setErr(tr('explorer.registryUnavailable'))
|
|
5278
|
+
return
|
|
5279
|
+
}
|
|
5252
5280
|
// Issue #13: NEVER fall back to the machine-level workspace here —
|
|
5253
5281
|
// a session whose cwd is not a mirror is a LOCAL session and shows
|
|
5254
5282
|
// the "no remote workspace" empty state instead.
|
|
@@ -5261,7 +5289,7 @@ window.__ModuleLoader__.load({
|
|
|
5261
5289
|
const previous = dataRef.current[r]
|
|
5262
5290
|
if (r && previous && previous.entries) storeLevel(r, { ...previous, loading: false, softError: String(e.message || e) })
|
|
5263
5291
|
})
|
|
5264
|
-
}, [scopeCwd, sessionId])
|
|
5292
|
+
}, [scopeCwd, sessionId, pickedRoot])
|
|
5265
5293
|
|
|
5266
5294
|
React.useEffect(() => { refreshStatus() }, [refreshStatus])
|
|
5267
5295
|
React.useEffect(() => { if (props.visible) refreshStatus({ visible: true }) }, [props.visible])
|
|
@@ -5545,6 +5573,11 @@ window.__ModuleLoader__.load({
|
|
|
5545
5573
|
React.createElement(WorkbenchAction, { icon: 'branch', label: tr('changes.title'), disabled: !root, onClick: () => { if (props.onOpenChanges) props.onOpenChanges(); else if (SIDEBAR_RIGHT?.openTabIn) SIDEBAR_RIGHT.openTabIn(sessionId, NATIVE_CHANGES); else if (SIDEBAR_RIGHT?.mounted?.getSnapshot?.() === sessionId) SIDEBAR_RIGHT.openTab?.(NATIVE_CHANGES) } }),
|
|
5546
5574
|
React.createElement(WorkbenchAction, { icon: 'search', label: tr('workbench.filter'), pressed: filterOpen, disabled: !root, onClick: () => { setFilterOpen((v) => !v); setFilter('') } }),
|
|
5547
5575
|
React.createElement(WorkbenchAction, { icon: 'refresh', label: tr('explorer.refresh'), onClick: () => refreshStatus({ force: true }) }),
|
|
5576
|
+
// Issue #180: this entry point disappeared in 1.0.0 (b28fcc3) while
|
|
5577
|
+
// the empty state still told the user to click it, so "pick a remote
|
|
5578
|
+
// workspace" had no way in at all. `explorer.more` ("…") survived
|
|
5579
|
+
// only as an unused translation string.
|
|
5580
|
+
React.createElement(WorkbenchAction, { icon: 'more', label: tr('explorer.pickRemote'), pressed: picker, onClick: () => setPicker((v) => !v) }),
|
|
5548
5581
|
React.createElement(WorkbenchAction, { icon: 'collapse', label: tr('workbench.collapse'), disabled: !root, onClick: () => { props.onCollapseAll?.(); setRootOpen(true) } }),
|
|
5549
5582
|
),
|
|
5550
5583
|
React.createElement('div', { className: 'dsh-rw-path', title: root, style: { marginTop: 4, display: 'flex', alignItems: 'center', gap: 6 } },
|
|
@@ -5570,12 +5603,28 @@ window.__ModuleLoader__.load({
|
|
|
5570
5603
|
React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: buttonS, onClick: () => refreshStatus({ force: true }) }, tr('project.retry'))) : null,
|
|
5571
5604
|
remoteTerminal.error ? React.createElement('div', { role: 'alert', style: { padding: '6px 10px', color: T.danger, fontSize: 12 } }, remoteTerminal.error) : null,
|
|
5572
5605
|
picker ? React.createElement('div', { style: { padding: 8 } }, React.createElement(DirPicker, {
|
|
5573
|
-
open: true, busy: false, registerWorkspace: false, initialTab: 'remote',
|
|
5606
|
+
open: true, busy: false, registerWorkspace: false, initialTab: 'remote',
|
|
5607
|
+
// Issue #180: the picked path used to be dropped on the floor — the
|
|
5608
|
+
// picker closed, refreshStatus() re-resolved the SAME session cwd, and
|
|
5609
|
+
// the pane did not change. Adopt the picked remote root instead;
|
|
5610
|
+
// `pickedRoot` is part of refreshStatus' identity, so the tree reloads.
|
|
5611
|
+
onPicked: (localMirror, remotePath) => {
|
|
5612
|
+
setPicker(false)
|
|
5613
|
+
const next = String(remotePath || '')
|
|
5614
|
+
if (next) setPickedRoot(next)
|
|
5615
|
+
else refreshStatus({ force: true })
|
|
5616
|
+
},
|
|
5617
|
+
onCancel: () => setPicker(false),
|
|
5574
5618
|
})) : null,
|
|
5575
5619
|
root && filterOpen && filter.trim() ? React.createElement(RemoteWorkspaceSearch, { key: sessionId + ':' + root, root, sessionId, query: filter.trim(), mode: searchMode, includeIgnored: searchIgnored, caseSensitive: searchCase, retryKey: searchRetry, onOpenFile: openFile, onRevealDirectory: revealDirectory }) : null,
|
|
5576
5620
|
React.createElement('div', { role: 'tree', 'aria-label': tr('explorer.tabTitle'), ref: treeRef, onScroll: (e) => explorerMemory.set(sessionId || '', { ...explorerMemory.get(sessionId || ''), scrollTop: e.currentTarget.scrollTop }), onKeyDown: treeKeyDown, style: { flex: 1, overflowY: 'auto', minHeight: 0, padding: '2px 0', display: filterOpen && filter.trim() ? 'none' : undefined } },
|
|
5577
5621
|
!root
|
|
5578
|
-
? React.createElement('div', { style: { opacity: 0.6, padding: 12, fontSize: 13 } },
|
|
5622
|
+
? React.createElement('div', { style: { opacity: 0.6, padding: 12, fontSize: 13 } },
|
|
5623
|
+
err ? tr('explorer.cannotResolve') : tr('explorer.localSession'),
|
|
5624
|
+
// A failure the user can act on must not look like a fact.
|
|
5625
|
+
err ? React.createElement('div', { style: { marginTop: 6, fontSize: 11, opacity: 0.85, wordBreak: 'break-word' }, title: err }, err) : null,
|
|
5626
|
+
err ? React.createElement('div', { style: { marginTop: 8 } },
|
|
5627
|
+
React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: buttonS, onClick: () => refreshStatus({ force: true }) }, tr('explorer.retry'))) : null)
|
|
5579
5628
|
: React.createElement('div', { key: root },
|
|
5580
5629
|
React.createElement('div', {
|
|
5581
5630
|
role: 'treeitem', className: 'dsh-rw-tree-row', 'data-rw-tree-row': root, 'aria-level': 1, 'aria-expanded': rootOpen, tabIndex: !focusedPath || focusedPath === root ? 0 : -1, onFocus: () => setFocusedPath(root),
|
|
@@ -5899,6 +5948,228 @@ window.__ModuleLoader__.load({
|
|
|
5899
5948
|
)
|
|
5900
5949
|
}
|
|
5901
5950
|
|
|
5951
|
+
// ── Remote Markdown illustrations ──────────────────────────────────────
|
|
5952
|
+
// The host renderer draws `` two ways: an absolute
|
|
5953
|
+
// HTTP(S) destination is used as authored, and EVERYTHING ELSE needs the
|
|
5954
|
+
// owner's `pathImages` vocabulary to turn it into a displayable absolute
|
|
5955
|
+
// URL (primitives: `imageSource` → `vocabularyImageUrl`). A miss is not an
|
|
5956
|
+
// error — it degrades to the alt text, which is exactly why a remote .md
|
|
5957
|
+
// showed captions where its figures belong: this pane never passed a
|
|
5958
|
+
// vocabulary at all.
|
|
5959
|
+
//
|
|
5960
|
+
// The built-in document preview supplies one from the LOCAL document path
|
|
5961
|
+
// (`markdownImageUrl` → `api/file?path=…`). That answer is wrong for a
|
|
5962
|
+
// remote document twice over: the path names a different file (or none) on
|
|
5963
|
+
// THIS host, and the host's file route cannot carry bytes that only exist
|
|
5964
|
+
// on the far side of the SSH connection. The remote owner therefore answers
|
|
5965
|
+
// with `data:` URLs built from the bytes the EXISTING `/dsh-remote/read`
|
|
5966
|
+
// route already returns for image extensions (issue #66). `data:` is on the
|
|
5967
|
+
// renderer's rewritten-image allowlist, so the host contract needs no
|
|
5968
|
+
// change — and a data URL cannot alias a local file the way a path could.
|
|
5969
|
+
const MARKDOWN_IMAGE_EXTENSION = /\.(?:png|jpe?g|gif|webp|svg|bmp)$/i
|
|
5970
|
+
// Per-document and per-cache ceilings: a figure set is normally a handful,
|
|
5971
|
+
// and one pathological document must not turn a preview into hundreds of
|
|
5972
|
+
// SFTP reads or megabytes of retained base64.
|
|
5973
|
+
const MARKDOWN_IMAGE_MAX_PER_DOC = 32
|
|
5974
|
+
const MARKDOWN_IMAGE_CACHE_LIMIT = 32
|
|
5975
|
+
const MARKDOWN_IMAGE_MAX_BYTES = 2 * 1024 * 1024
|
|
5976
|
+
/** `sessionId\0remotePath` → data URL, or null when no readable image exists there. */
|
|
5977
|
+
const markdownImageBytes = new Map()
|
|
5978
|
+
/** `sessionId\0remotePath` → the in-flight read, so two tabs of one file share it. */
|
|
5979
|
+
const markdownImageReads = new Map()
|
|
5980
|
+
|
|
5981
|
+
/**
|
|
5982
|
+
* The filesystem path a markdown image destination names.
|
|
5983
|
+
*
|
|
5984
|
+
* Mirrors the host's own reading of a destination (primitives
|
|
5985
|
+
* `markdownImageUrl`): a query/fragment suffix is dropped and the remainder
|
|
5986
|
+
* percent-decoded. A destination carrying a URL scheme is either an
|
|
5987
|
+
* absolute image the renderer handles itself or another owner's address, so
|
|
5988
|
+
* it is NOT resolved here — only local paths are. Windows drive letters are
|
|
5989
|
+
* paths, not schemes.
|
|
5990
|
+
*/
|
|
5991
|
+
function markdownImageDestination(value) {
|
|
5992
|
+
const authored = String(value == null ? '' : value)
|
|
5993
|
+
const cut = authored.search(/[?#]/)
|
|
5994
|
+
let path = cut === -1 ? authored : authored.slice(0, cut)
|
|
5995
|
+
try { path = decodeURIComponent(path) } catch { return '' }
|
|
5996
|
+
if (!path) return ''
|
|
5997
|
+
if (/^[a-z]:[\\/]/i.test(path)) return path
|
|
5998
|
+
if (/^[a-z][a-z\d+.-]*:/i.test(path)) return ''
|
|
5999
|
+
// `//host/x` is protocol-relative (a URL the host renderer refuses), not
|
|
6000
|
+
// a remote path; do not turn it into a doomed read.
|
|
6001
|
+
if (path.startsWith('//')) return ''
|
|
6002
|
+
return path
|
|
6003
|
+
}
|
|
6004
|
+
|
|
6005
|
+
/** Parent directory of a POSIX or Windows remote path (string-level). */
|
|
6006
|
+
function remoteParentPath(p) {
|
|
6007
|
+
const value = String(p || '').replace(/[\\/]+$/, '')
|
|
6008
|
+
const index = Math.max(value.lastIndexOf('/'), value.lastIndexOf('\\'))
|
|
6009
|
+
if (index < 0) return ''
|
|
6010
|
+
if (index === 0) return value.startsWith('\\\\') ? value : '/'
|
|
6011
|
+
const parent = value.slice(0, index)
|
|
6012
|
+
// A drive root needs its separator back before a child can be joined.
|
|
6013
|
+
return /^[a-z]:$/i.test(parent) ? parent + (value.includes('\\') ? '\\' : '/') : parent
|
|
6014
|
+
}
|
|
6015
|
+
|
|
6016
|
+
/**
|
|
6017
|
+
* Collapse `.` / `..` and mixed separators in a remote path.
|
|
6018
|
+
*
|
|
6019
|
+
* The read route normalizes again, so this is not a security boundary —
|
|
6020
|
+
* it keeps the CACHE KEY canonical (`a/../img/x.png` and `img/x.png` are
|
|
6021
|
+
* one illustration, not two reads) and keeps audit/log entries legible.
|
|
6022
|
+
* The rules mirror `normalizeRemotePath` on the host side.
|
|
6023
|
+
*/
|
|
6024
|
+
function normalizeRemoteImagePath(value) {
|
|
6025
|
+
const raw = String(value || '')
|
|
6026
|
+
if (!raw) return ''
|
|
6027
|
+
let prefix = ''
|
|
6028
|
+
let rest = raw
|
|
6029
|
+
const unc = raw.match(/^(\\\\[^\\/]+\\[^\\/]+)(.*)$/s)
|
|
6030
|
+
const drive = raw.match(/^([a-zA-Z]:)(.*)$/s)
|
|
6031
|
+
if (unc) { prefix = unc[1]; rest = unc[2] || '' }
|
|
6032
|
+
else if (drive) { prefix = drive[1]; rest = drive[2] || '' }
|
|
6033
|
+
else if (raw.startsWith('/')) prefix = '/'
|
|
6034
|
+
const windows = prefix.startsWith('\\\\') || /^[a-zA-Z]:$/.test(prefix)
|
|
6035
|
+
const separator = windows ? '\\' : '/'
|
|
6036
|
+
const parts = []
|
|
6037
|
+
for (const segment of rest.split(/[\\/]+/)) {
|
|
6038
|
+
if (!segment || segment === '.') continue
|
|
6039
|
+
if (segment === '..') { parts.pop(); continue }
|
|
6040
|
+
parts.push(segment)
|
|
6041
|
+
}
|
|
6042
|
+
if (prefix === '/') return '/' + parts.join('/')
|
|
6043
|
+
if (!prefix) return parts.join(separator)
|
|
6044
|
+
const root = prefix.replace(/[\\/]$/, '')
|
|
6045
|
+
if (!parts.length) return windows ? root + separator : root
|
|
6046
|
+
return root + separator + parts.join(separator)
|
|
6047
|
+
}
|
|
6048
|
+
|
|
6049
|
+
/**
|
|
6050
|
+
* Resolve one authored image destination against the document's directory.
|
|
6051
|
+
* Absolute POSIX / Windows / UNC destinations are taken as authored.
|
|
6052
|
+
*/
|
|
6053
|
+
function resolveMarkdownImagePath(documentPath, destination) {
|
|
6054
|
+
const dest = String(destination || '')
|
|
6055
|
+
if (!dest) return ''
|
|
6056
|
+
if (dest.startsWith('/') || dest.startsWith('\\\\') || /^[a-z]:[\\/]/i.test(dest)) return normalizeRemoteImagePath(dest)
|
|
6057
|
+
const doc = String(documentPath || '')
|
|
6058
|
+
// The tab always carries an absolute document path; a relative one has
|
|
6059
|
+
// no directory to resolve against and must not become a root-relative
|
|
6060
|
+
// read on the far side.
|
|
6061
|
+
if (!doc || !(doc.startsWith('/') || doc.startsWith('\\\\') || /^[a-z]:[\\/]/i.test(doc))) return ''
|
|
6062
|
+
const parent = remoteParentPath(doc)
|
|
6063
|
+
return normalizeRemoteImagePath(parent ? joinRemote(parent, dest) : dest)
|
|
6064
|
+
}
|
|
6065
|
+
|
|
6066
|
+
/** `sessionId + NUL + path` — the cache and in-flight identity of one illustration. */
|
|
6067
|
+
function markdownImageKey(sessionId, path) {
|
|
6068
|
+
return String(sessionId || '') + '\0' + String(path || '')
|
|
6069
|
+
}
|
|
6070
|
+
|
|
6071
|
+
/**
|
|
6072
|
+
* Every image destination one markdown document can plausibly render,
|
|
6073
|
+
* resolved to remote absolute paths, deduped and capped.
|
|
6074
|
+
*
|
|
6075
|
+
* Deliberately a SUPERSET of what the renderer will ask for: inline
|
|
6076
|
+
* `` plus link/reference definitions (`[id]: dest`, which also
|
|
6077
|
+
* feed `![alt][id]`). Non-image destinations are dropped BEFORE any read,
|
|
6078
|
+
* so a document's ordinary links never cost a round trip. `resolve()` may
|
|
6079
|
+
* still miss a destination this scan did not predict — the renderer then
|
|
6080
|
+
* keeps the alt text, exactly as before.
|
|
6081
|
+
*/
|
|
6082
|
+
function markdownImageTargets(sessionId, documentPath, text) {
|
|
6083
|
+
const targets = []
|
|
6084
|
+
const seen = new Set()
|
|
6085
|
+
const add = (destination) => {
|
|
6086
|
+
if (targets.length >= MARKDOWN_IMAGE_MAX_PER_DOC) return
|
|
6087
|
+
const path = markdownImageDestination(destination)
|
|
6088
|
+
if (!path || !MARKDOWN_IMAGE_EXTENSION.test(path)) return
|
|
6089
|
+
const absolute = resolveMarkdownImagePath(documentPath, path)
|
|
6090
|
+
if (!absolute) return
|
|
6091
|
+
const key = markdownImageKey(sessionId, absolute)
|
|
6092
|
+
if (seen.has(key)) return
|
|
6093
|
+
seen.add(key)
|
|
6094
|
+
targets.push({ key, path: absolute })
|
|
6095
|
+
}
|
|
6096
|
+
const source = String(text || '')
|
|
6097
|
+
const inline = /!\[[^\]]*\]\(\s*(?:<([^<>]*)>|([^\s()]+))/g
|
|
6098
|
+
let match
|
|
6099
|
+
while ((match = inline.exec(source)) !== null) add(match[1] !== undefined ? match[1] : match[2])
|
|
6100
|
+
const definition = /^[ \t]*\[[^\]]*\]:[ \t]*(?:<([^<>]*)>|([^\s]+))/gm
|
|
6101
|
+
while ((match = definition.exec(source)) !== null) add(match[1] !== undefined ? match[1] : match[2])
|
|
6102
|
+
return targets
|
|
6103
|
+
}
|
|
6104
|
+
|
|
6105
|
+
/**
|
|
6106
|
+
* Read one illustration over the session's binding and remember its data
|
|
6107
|
+
* URL. Failures are cached as null (alt text stays) so a missing or
|
|
6108
|
+
* oversized image costs ONE round trip, not one per render.
|
|
6109
|
+
*/
|
|
6110
|
+
function readMarkdownImage(sessionId, target) {
|
|
6111
|
+
const existing = markdownImageReads.get(target.key)
|
|
6112
|
+
if (existing) return existing
|
|
6113
|
+
const request = api('POST', '/dsh-remote/read',
|
|
6114
|
+
withSessionBody({ path: target.path, maxBytes: MARKDOWN_IMAGE_MAX_BYTES }, sessionId))
|
|
6115
|
+
.then((payload) => {
|
|
6116
|
+
markdownImageBytes.set(target.key, (payload && payload.image && payload.content && payload.mime)
|
|
6117
|
+
? 'data:' + String(payload.mime) + ';base64,' + String(payload.content)
|
|
6118
|
+
: null)
|
|
6119
|
+
})
|
|
6120
|
+
.catch(() => { markdownImageBytes.set(target.key, null) })
|
|
6121
|
+
.then(() => {
|
|
6122
|
+
while (markdownImageBytes.size > MARKDOWN_IMAGE_CACHE_LIMIT) {
|
|
6123
|
+
markdownImageBytes.delete(markdownImageBytes.keys().next().value)
|
|
6124
|
+
}
|
|
6125
|
+
})
|
|
6126
|
+
markdownImageReads.set(target.key, request)
|
|
6127
|
+
void request.then(() => { markdownImageReads.delete(target.key) })
|
|
6128
|
+
return request
|
|
6129
|
+
}
|
|
6130
|
+
|
|
6131
|
+
/**
|
|
6132
|
+
* The `pathImages` vocabulary of one remote markdown document.
|
|
6133
|
+
*
|
|
6134
|
+
* `resolve()` must be synchronous and MarkdownText memoizes the vocabulary
|
|
6135
|
+
* (a fresh identity per render would rebuild the host's component table),
|
|
6136
|
+
* so the bytes are prefetched by an effect and the object identity changes
|
|
6137
|
+
* only when new bytes land: revision is the identity knob, not the clock.
|
|
6138
|
+
* Nothing is read while the document is in source mode — the pane only pays
|
|
6139
|
+
* for the figures it actually draws.
|
|
6140
|
+
*/
|
|
6141
|
+
function useRemoteMarkdownImages(sessionId, documentPath, text, enabled) {
|
|
6142
|
+
const [revision, setRevision] = React.useState(0)
|
|
6143
|
+
React.useEffect(() => {
|
|
6144
|
+
if (!enabled || !documentPath || !text) return undefined
|
|
6145
|
+
const targets = markdownImageTargets(sessionId, documentPath, text)
|
|
6146
|
+
const missing = targets.filter((target) => !markdownImageBytes.has(target.key))
|
|
6147
|
+
if (!missing.length) return undefined
|
|
6148
|
+
let cancelled = false
|
|
6149
|
+
;(async () => {
|
|
6150
|
+
for (const target of missing) {
|
|
6151
|
+
if (cancelled) return
|
|
6152
|
+
await readMarkdownImage(sessionId, target)
|
|
6153
|
+
if (cancelled) return
|
|
6154
|
+
setRevision((value) => value + 1)
|
|
6155
|
+
}
|
|
6156
|
+
})()
|
|
6157
|
+
return () => { cancelled = true }
|
|
6158
|
+
}, [enabled, sessionId, documentPath, text])
|
|
6159
|
+
return {
|
|
6160
|
+
pathImages: React.useMemo(() => ({
|
|
6161
|
+
resolve(value) {
|
|
6162
|
+
const path = markdownImageDestination(value)
|
|
6163
|
+
if (!path || !MARKDOWN_IMAGE_EXTENSION.test(path)) return undefined
|
|
6164
|
+
const absolute = resolveMarkdownImagePath(documentPath, path)
|
|
6165
|
+
if (!absolute) return undefined
|
|
6166
|
+
const hit = markdownImageBytes.get(markdownImageKey(sessionId, absolute))
|
|
6167
|
+
return typeof hit === 'string' && hit ? hit : undefined
|
|
6168
|
+
},
|
|
6169
|
+
}), [sessionId, documentPath, revision]),
|
|
6170
|
+
}
|
|
6171
|
+
}
|
|
6172
|
+
|
|
5902
6173
|
const remoteDrafts = new Map()
|
|
5903
6174
|
const pendingFileSaves = new Map()
|
|
5904
6175
|
function RemoteFileTab(props) {
|
|
@@ -6106,6 +6377,14 @@ window.__ModuleLoader__.load({
|
|
|
6106
6377
|
|
|
6107
6378
|
const baseName = path.split(/[\\/]/).pop() || path
|
|
6108
6379
|
const isMarkdown = /\.(md|markdown)$/i.test(baseName)
|
|
6380
|
+
// A rendered .md owns its figures (see useRemoteMarkdownImages). Only the
|
|
6381
|
+
// branch that actually DRAWS the document pays for them: source mode
|
|
6382
|
+
// never reads an image, and a draft reads only the destinations that are
|
|
6383
|
+
// not cached yet (typing therefore costs nothing until a new figure path
|
|
6384
|
+
// appears). The text is the same one the host renders: the draft while
|
|
6385
|
+
// editing, the loaded document otherwise.
|
|
6386
|
+
const markdownPreview = isMarkdown && !sourceMode && !!MarkdownText
|
|
6387
|
+
const markdownImages = useRemoteMarkdownImages(fileSessionId, path, markdownPreview ? (edit ? draft : originalText) : '', markdownPreview)
|
|
6109
6388
|
const searchableText = edit ? draft : originalText
|
|
6110
6389
|
const matches = React.useMemo(() => {
|
|
6111
6390
|
if (!findQuery) return []
|
|
@@ -6218,7 +6497,7 @@ window.__ModuleLoader__.load({
|
|
|
6218
6497
|
},
|
|
6219
6498
|
}, edit ? draft : originalText),
|
|
6220
6499
|
},
|
|
6221
|
-
React.createElement(MarkdownText, { text: edit ? draft : originalText, variant: 'body', labels: markdownLabels })),
|
|
6500
|
+
React.createElement(MarkdownText, { text: edit ? draft : originalText, variant: 'body', labels: markdownLabels, pathImages: markdownImages.pathImages })),
|
|
6222
6501
|
(data && data.truncated)
|
|
6223
6502
|
? React.createElement('div', { style: { color: T.warn, fontSize: 12, marginTop: 8 } }, tr('file.truncated'))
|
|
6224
6503
|
: null)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// lib/deck-bridge.js —— 给 dsh-mattpocock-skills-deck 的远端工作区适配层用的公开入口。
|
|
2
|
+
//
|
|
3
|
+
// 背景:外挂插件 dsh-deck-remote-exec 让 deck 在 dsh-remote 的远端工作区里工作,
|
|
4
|
+
// 它需要的只是 dsh-remote 已有的几个纯能力(镜像识别、路径翻译、SSH 连接池)。
|
|
5
|
+
// 在此之前它靠「绝对路径动态 import lib/*.js」绕过 package.json 的 exports 限制,
|
|
6
|
+
// 因为那些内部模块没有公开导出。这种做法依赖 dsh-remote 的内部文件布局,
|
|
7
|
+
// 一旦文件改名或 exports 收紧就会失效,而且无法被 Node 的模块解析静态检查。
|
|
8
|
+
//
|
|
9
|
+
// 本文件把这些能力里插件实际用到的符号正式导出,插件改成
|
|
10
|
+
// `import { ... } from 'dsh-remote/deck-bridge'` 即可,不再碰内部路径。
|
|
11
|
+
// 只导出插件真正需要的 6 个符号,不把整个内部模块摊开——公开面越小,
|
|
12
|
+
// 内部实现越能自由演进;要加符号时按插件的实际需要再加。
|
|
13
|
+
//
|
|
14
|
+
// 这些函数/类本身的实现仍在各自原模块里,这里只做转发,零逻辑。
|
|
15
|
+
export { resolveMirror } from './binding.js'
|
|
16
|
+
export { SystemOpenSshPool } from './openssh.js'
|
|
17
|
+
export { resolveRemoteWorkspacePath, relPathUnder, remoteDirname, shq } from './paths.js'
|
package/lib/errors.js
CHANGED
|
@@ -55,10 +55,13 @@ export function classifyError(err, opts = {}) {
|
|
|
55
55
|
// the message a user sees when the port is open but nothing speaks SSH on it,
|
|
56
56
|
// or when a firewall/security group cuts the connection after the TCP accept;
|
|
57
57
|
// it is indistinguishable from "wrong credentials" unless it is classified.
|
|
58
|
-
if (/
|
|
58
|
+
if (/handshake failed|no matching (?:key exchange|host key|cipher|kex|mac)|no matching.*(?:algorithm|cipher)|unsupported.*algorithm/i.test(msg)) {
|
|
59
|
+
return { category: 'network', hint: `SSH 握手未完成${where}:客户端与服务器的 SSH 算法协商失败。若本机 ssh 能连接,请在主机编辑页把「连接后端」改为 openssh 后测试;插件不会自动启用弱算法或跳过主机指纹校验。`, raw: msg }
|
|
60
|
+
}
|
|
61
|
+
if (/connection lost before handshake/i.test(msg)) {
|
|
59
62
|
return {
|
|
60
63
|
category: 'network',
|
|
61
|
-
hint: `SSH 握手未完成${where}
|
|
64
|
+
hint: `SSH 握手未完成${where}:连接在 SSH 认证前断开,当前错误无法确定是服务端限流、网络设备断开还是协议兼容问题,也不能据此判断密码错误。请稍后重试;若同一台电脑的 ssh 可以连接,请在主机编辑页把「连接后端」改为 openssh 后测试。持续失败时再检查 sshd 日志及来源 IP 限制。`,
|
|
62
65
|
raw: msg,
|
|
63
66
|
}
|
|
64
67
|
}
|
package/lib/main.js
CHANGED
|
@@ -79,6 +79,7 @@ import { createWebAttachRoutes } from './routes-web-attach.js'
|
|
|
79
79
|
import { createWorkspaceRoutes } from './routes-workspace.js'
|
|
80
80
|
import { listDirStructured, removeRemoteTree } from './remote-fs.js'
|
|
81
81
|
import { registerRemoteSkills } from './remote-skills.js'
|
|
82
|
+
import { installWorkspaceFilesRemote } from './workspace-files-remote.js'
|
|
82
83
|
import { describeConnect } from './connect-summary.js'
|
|
83
84
|
|
|
84
85
|
export const name = 'dsh-remote'
|
|
@@ -315,6 +316,10 @@ export const Config = z.object({
|
|
|
315
316
|
* transparently falls back to a local shell. `false` keeps "remote ssh"
|
|
316
317
|
* menu-only. */
|
|
317
318
|
remoteTerminalDefault: z.boolean().default(true),
|
|
319
|
+
/** Serve the core `workspaceFiles` Remote (file previews, byte windows,
|
|
320
|
+
* workspace listings) from the session's REMOTE origin instead of the
|
|
321
|
+
* local mirror (issue #194). `false` restores the core's mirror behavior. */
|
|
322
|
+
workspaceFilesRemote: z.boolean().default(true),
|
|
318
323
|
/** TUI integration layer (docs/tui.md): register the `/dsh-remote` scene,
|
|
319
324
|
* the workspace provider and the `/dsh-remote` slash command when a
|
|
320
325
|
* dsh-tui profile is present. `false` disables the whole layer — on a Web or
|
|
@@ -1484,6 +1489,20 @@ export async function apply(ctx, config) {
|
|
|
1484
1489
|
poolForMachine,
|
|
1485
1490
|
logger: typeof ctx.get === 'function' ? ctx.get('logger') : undefined,
|
|
1486
1491
|
})
|
|
1492
|
+
// Issue #194: the core `workspaceFiles` Remote resolves every mirror-session
|
|
1493
|
+
// read/stat/list against the LOCAL MIRROR (the header cwd), so previews and
|
|
1494
|
+
// listings could serve silently stale content. Serve those calls from the
|
|
1495
|
+
// remote origin through the same mirror binding the rw_* tools use; scopes
|
|
1496
|
+
// that are not mirror sessions fall through to the core untouched. See
|
|
1497
|
+
// lib/workspace-files-remote.js for the seam analysis and the `changes`
|
|
1498
|
+
// trade-off. Opt-out via the config switch above.
|
|
1499
|
+
const workspaceFilesRemote = config.workspaceFilesRemote === false
|
|
1500
|
+
? null
|
|
1501
|
+
: installWorkspaceFilesRemote(ctx, {
|
|
1502
|
+
resolveBinding: resolveMirrorForLocal,
|
|
1503
|
+
poolForMachine,
|
|
1504
|
+
logger: typeof ctx.get === 'function' ? ctx.get('logger') : undefined,
|
|
1505
|
+
})
|
|
1487
1506
|
|
|
1488
1507
|
/**
|
|
1489
1508
|
* The whole local-mirror registry with each mirror's recorded remote origin
|