dsh-remote 1.1.2 → 1.2.1
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 +17 -3
- package/README.md +17 -3
- package/lib/binding.js +26 -2
- package/lib/boot.js +4 -31
- package/lib/client.js +600 -103
- package/lib/connect-summary.js +52 -0
- package/lib/forwards.js +285 -35
- package/lib/index.js +20 -4573
- package/lib/local-workspace.js +103 -0
- package/lib/main.js +4660 -0
- package/lib/openssh.js +59 -8
- package/lib/remote-git.js +6 -4
- package/lib/routes-forwards.js +24 -4
- package/lib/routes-fs.js +26 -22
- package/lib/self-heal.js +58 -5
- package/lib/sshconfig.js +6 -0
- package/lib/telemetry.js +64 -25
- package/lib/update.js +95 -33
- package/lib/vendor/jsdiff/SOURCE.md +1 -1
- package/lib/vendor/jsdiff/diff/base.js +1 -1
- package/lib/vendor/jsdiff/diff/line.js +1 -1
- package/lib/vendor/jsdiff/patch/create.js +147 -18
- package/lib/vendor/jsdiff/util/params.js +1 -1
- package/package.json +5 -5
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.1
|
|
30
|
+
const CLIENT_VERSION = '1.2.1'
|
|
31
31
|
|
|
32
32
|
// ── optional host primitives ────────────────────────────────────────────
|
|
33
33
|
// Issue #74: a remote session's .md link must open over SFTP, NOT via the
|
|
@@ -166,6 +166,42 @@ window.__ModuleLoader__.load({
|
|
|
166
166
|
'ide.guideLayoutHint': '拖动分隔线调整栏宽;窄屏可切换文件、编辑器和会话。',
|
|
167
167
|
'ide.documentation': '使用指南',
|
|
168
168
|
'ide.tools': '会话工具', 'ide.toolsHint': '展开或收起会话附加工具与连接信息',
|
|
169
|
+
"local.explorer.tabTitle": "本地文件",
|
|
170
|
+
"local.workbench.openTerminal": "打开本地终端",
|
|
171
|
+
"local.workbench.terminalUnavailable": "本地终端尚不可用,请检查宿主终端插件。",
|
|
172
|
+
"local.workbench.filter": "搜索本地工作区",
|
|
173
|
+
"local.workbench.remote": "本地工作区",
|
|
174
|
+
"local.workbench.copyPath": "复制本地路径",
|
|
175
|
+
"local.workbench.saved": "已保存到本地",
|
|
176
|
+
"local.workbench.loadingFile": "正在读取本地文件…",
|
|
177
|
+
"local.file.readFail": "本地读取失败:{msg}",
|
|
178
|
+
"local.file.listFail": "本地目录读取失败:{msg}",
|
|
179
|
+
"local.file.conflictHelp": "本地文件已变化,草稿已保留。请重新读取并比较后合并修改。",
|
|
180
|
+
"local.file.discardReload": "舍弃草稿并重新读取",
|
|
181
|
+
"local.file.incompletePreview": "当前文件预览不完整,请在终端编辑完整文件。",
|
|
182
|
+
"local.explorer.connection.loading": "正在读取本地目录…",
|
|
183
|
+
"local.explorer.connection.interrupted": "本地访问失败 · 已保留文件列表",
|
|
184
|
+
"local.explorer.connection.ready": "本地目录已就绪",
|
|
185
|
+
"local.ide.welcomeTitle": "本地开发工作区",
|
|
186
|
+
"local.ide.guideFilesHint": "在左侧展开目录,或搜索项目文件、目录和内容。",
|
|
187
|
+
"local.ide.guideEditHint": "文件打开即可编辑。使用 Ctrl / ⌘ + S 保存到本地项目。",
|
|
188
|
+
"local.ide.guideAgentHint": "Agent 继续使用宿主原生文件与命令工具,在当前本地项目中工作。",
|
|
189
|
+
"local.ide.chooseFile": "从左侧选择项目文件,在这里编辑。",
|
|
190
|
+
"local.file.saveToRemote": "保存到本地",
|
|
191
|
+
"local.file.binary": "二进制文件({size}),请使用本机应用打开。",
|
|
192
|
+
"local.file.truncated": "… 内容已截断,请在本机应用中查看完整文件。",
|
|
193
|
+
"local.file.conflict": "本地文件已变化,请重新读取",
|
|
194
|
+
"local.changes.title": "本地 Git 改动",
|
|
195
|
+
"local.changes.failed": "无法读取本地 Git 状态",
|
|
196
|
+
"local.changes.noGit": "本机未安装 Git,安装后点击刷新。",
|
|
197
|
+
"local.changes.unavailable": "当前无法查看本地 Git 状态。",
|
|
198
|
+
"local.changes.readOnly": "查看本地仓库,不自动提交或更改暂存区。",
|
|
199
|
+
"local.changes.refreshing": "正在刷新本地状态…",
|
|
200
|
+
"local.changes.loading": "正在读取本地 Git 状态…",
|
|
201
|
+
"local.changes.diff": "本地文件差异",
|
|
202
|
+
"local.changes.openFile": "打开本地文件",
|
|
203
|
+
"workspace.files": "工作区文件",
|
|
204
|
+
"workspace.git": "Git 改动",
|
|
169
205
|
'ide.enter': 'IDE 模式', 'ide.exit': '返回普通模式', 'ide.files': '文件',
|
|
170
206
|
'ide.editor': '编辑器', 'ide.chat': '会话', 'ide.openEditor': '打开编辑区',
|
|
171
207
|
'ide.chooseFile': '从左侧选择远程文件,在这里编辑。',
|
|
@@ -396,7 +432,7 @@ window.__ModuleLoader__.load({
|
|
|
396
432
|
// 灰按钮必须能解释自己:用户「点了没反应」时唯一能拿到的线索就是 hover 提示。
|
|
397
433
|
'settings.saveNeedsHost': '先填写主机地址才能保存',
|
|
398
434
|
'settings.saveHint': '保存这台机器(留空的密码/私钥/passphrase 沿用已保存的值)',
|
|
399
|
-
'settings.fwdNeedsPort': '
|
|
435
|
+
'settings.fwdNeedsPort': '先填写监听端口才能添加转发',
|
|
400
436
|
'settings.fwdAddHint': '添加一条端口转发',
|
|
401
437
|
'settings.advCollapse': '收起高级配置',
|
|
402
438
|
'settings.advExpand': '高级配置:认证与连接选项',
|
|
@@ -420,15 +456,31 @@ window.__ModuleLoader__.load({
|
|
|
420
456
|
'settings.saving': '保存中…',
|
|
421
457
|
'settings.save': '保存',
|
|
422
458
|
'settings.forwards': '端口转发(SSH 隧道)',
|
|
459
|
+
'settings.forwardsHint': '谁要发起访问,就在谁那边开监听口:监听口开在本机就是本地转发(ssh -L),开在远端就是远程转发(ssh -R)。',
|
|
460
|
+
'settings.fwdLocalHint': '监听口开在本机,连接转发到远端目标。',
|
|
461
|
+
'settings.fwdSideLocal': '本机 -L',
|
|
462
|
+
'settings.fwdSideReverse': '远端 -R',
|
|
463
|
+
'settings.fwdReverseHint': '监听口开在远端,连接转发回本机目标。',
|
|
423
464
|
'settings.fwdStop': '停止',
|
|
424
465
|
'settings.fwdStart': '启动',
|
|
466
|
+
'settings.fwdStarting': '启动中…',
|
|
425
467
|
'settings.fwdRemove': '删除',
|
|
426
|
-
'settings.fwdDirLocal': '
|
|
427
|
-
'settings.fwdDirReverse': '
|
|
468
|
+
'settings.fwdDirLocal': '本地 (-L)',
|
|
469
|
+
'settings.fwdDirReverse': '远程 (-R)',
|
|
428
470
|
'settings.fwdListen': '监听端口',
|
|
429
471
|
'settings.fwdTargetHost': '目标主机',
|
|
430
472
|
'settings.fwdTargetPort': '目标端口',
|
|
431
473
|
'settings.fwdAuto': '自动重连',
|
|
474
|
+
'settings.fwdAutoHint': '掉线重连后自动恢复这条转发',
|
|
475
|
+
'settings.fwdLegacyBadge': '需重新确认',
|
|
476
|
+
'settings.fwdLegacyHint': '旧版「自动重连」配置已暂停:重新勾选,并在需要时手动启动一次。',
|
|
477
|
+
'settings.fwdAutoNoticeTitle': '自动重连会做什么?',
|
|
478
|
+
'settings.fwdAutoNoticeBody': '勾选后,这条转发会记住“上次是否在运行”。\n\ndsh-web 启动时会自动连接当前机器,连上后恢复这条转发。\n\n如果机器连不上、凭据失效或端口被占用,本次恢复会失败,但不影响其他功能。\n\nDSH 重启后,只会恢复上次运行中的转发(从没启动过的不会自动启动)。',
|
|
479
|
+
'settings.fwdAutoNoticeTitleReverse': '反向转发的自动重连会做什么?',
|
|
480
|
+
'settings.fwdAutoNoticeBodyReverse': '勾选后,这条反向转发会记住“上次是否在运行”。\n\ndsh-web 启动时会自动连接当前机器,并在这台机器上重新监听端口、把连接转发回你本机;也就是说,重启后它会在远端自动重新打开监听。\n\n只有上次运行中的反向转发会被恢复;如果机器连不上、远端 AllowTcpForwarding 被关闭或端口被占用,本次恢复会失败,但不影响其他功能。\n\n如果不想让远端自动重新监听,请取消勾选或手动停止。',
|
|
481
|
+
'settings.fwdAutoNoticeConfirm': '仍然勾选',
|
|
482
|
+
'settings.fwdAutoNoticeCancel': '取消',
|
|
483
|
+
'settings.fwdAutoNoticeDontShow': '不再提示',
|
|
432
484
|
'settings.fwdAdd': '添加转发',
|
|
433
485
|
'settings.cleanup': '工作区清理(本地镜像与对话)',
|
|
434
486
|
'settings.cleanupRefresh': '刷新',
|
|
@@ -726,6 +778,42 @@ window.__ModuleLoader__.load({
|
|
|
726
778
|
'ide.guideLayoutHint': 'Drag separators to resize columns. Switch panes on narrow screens.',
|
|
727
779
|
'ide.documentation': 'User guide',
|
|
728
780
|
'ide.tools': 'Chat tools', 'ide.toolsHint': 'Show or hide extra conversation tools and connection details',
|
|
781
|
+
"local.explorer.tabTitle": "Local files",
|
|
782
|
+
"local.workbench.openTerminal": "Open local terminal",
|
|
783
|
+
"local.workbench.terminalUnavailable": "Local terminal unavailable. Check the host terminal plugin.",
|
|
784
|
+
"local.workbench.filter": "Search local workspace",
|
|
785
|
+
"local.workbench.remote": "Local workspace",
|
|
786
|
+
"local.workbench.copyPath": "Copy local path",
|
|
787
|
+
"local.workbench.saved": "Saved locally",
|
|
788
|
+
"local.workbench.loadingFile": "Reading local file…",
|
|
789
|
+
"local.file.readFail": "Local read failed: {msg}",
|
|
790
|
+
"local.file.listFail": "Local listing failed: {msg}",
|
|
791
|
+
"local.file.conflictHelp": "Local file changed. Your draft is retained; reload and compare before merging.",
|
|
792
|
+
"local.file.discardReload": "Discard draft and reload",
|
|
793
|
+
"local.file.incompletePreview": "Incomplete preview; edit the complete file in the terminal.",
|
|
794
|
+
"local.explorer.connection.loading": "Reading local directory…",
|
|
795
|
+
"local.explorer.connection.interrupted": "Local access failed · file list retained",
|
|
796
|
+
"local.explorer.connection.ready": "Local directory ready",
|
|
797
|
+
"local.ide.welcomeTitle": "Local development workspace",
|
|
798
|
+
"local.ide.guideFilesHint": "Expand folders on the left, or search project files, directories and contents.",
|
|
799
|
+
"local.ide.guideEditHint": "Files open ready to edit. Use Ctrl / ⌘ + S to save to the local project.",
|
|
800
|
+
"local.ide.guideAgentHint": "The Agent uses the host’s native file and command tools in this local project.",
|
|
801
|
+
"local.ide.chooseFile": "Select a project file on the left to edit here.",
|
|
802
|
+
"local.file.saveToRemote": "Save locally",
|
|
803
|
+
"local.file.binary": "Binary file ({size}); open it with a local application.",
|
|
804
|
+
"local.file.truncated": "… Preview truncated; open the complete file with a local application.",
|
|
805
|
+
"local.file.conflict": "Local file changed; reload before saving",
|
|
806
|
+
"local.changes.title": "Local Git changes",
|
|
807
|
+
"local.changes.failed": "Could not read local Git status",
|
|
808
|
+
"local.changes.noGit": "Git is unavailable on this host. Install it and refresh.",
|
|
809
|
+
"local.changes.unavailable": "Local Git status is unavailable.",
|
|
810
|
+
"local.changes.readOnly": "Inspect the local repository without changing commits or the index.",
|
|
811
|
+
"local.changes.refreshing": "Refreshing local status…",
|
|
812
|
+
"local.changes.loading": "Reading local Git status…",
|
|
813
|
+
"local.changes.diff": "Local file diff",
|
|
814
|
+
"local.changes.openFile": "Open local file",
|
|
815
|
+
"workspace.files": "Workspace files",
|
|
816
|
+
"workspace.git": "Git changes",
|
|
729
817
|
'ide.enter': 'IDE mode', 'ide.exit': 'Return to standard mode', 'ide.files': 'Files',
|
|
730
818
|
'ide.editor': 'Editor', 'ide.chat': 'Chat', 'ide.openEditor': 'Open editor area',
|
|
731
819
|
'ide.chooseFile': 'Choose a remote file on the left to edit it here.',
|
|
@@ -948,7 +1036,7 @@ window.__ModuleLoader__.load({
|
|
|
948
1036
|
'settings.testNeedsHost': 'Fill in the host before testing',
|
|
949
1037
|
'settings.saveNeedsHost': 'Fill in the host before saving',
|
|
950
1038
|
'settings.saveHint': 'Save this machine (a blank password/key/passphrase keeps the saved one)',
|
|
951
|
-
'settings.fwdNeedsPort': 'Fill in the
|
|
1039
|
+
'settings.fwdNeedsPort': 'Fill in the listen port before adding a forward',
|
|
952
1040
|
'settings.fwdAddHint': 'Add a port forward',
|
|
953
1041
|
'settings.advCollapse': 'Hide advanced options',
|
|
954
1042
|
'settings.advExpand': 'Advanced authentication and connection options',
|
|
@@ -972,15 +1060,31 @@ window.__ModuleLoader__.load({
|
|
|
972
1060
|
'settings.saving': 'Saving…',
|
|
973
1061
|
'settings.save': 'Save',
|
|
974
1062
|
'settings.forwards': 'Port forwarding (SSH tunnels)',
|
|
1063
|
+
'settings.forwardsHint': 'Open the listener on the side that starts the connection: a listener here is a local forward (ssh -L); one on the remote is a reverse forward (ssh -R).',
|
|
1064
|
+
'settings.fwdLocalHint': 'The listener is on this machine; connections go to the remote target.',
|
|
1065
|
+
'settings.fwdSideLocal': 'Local -L',
|
|
1066
|
+
'settings.fwdSideReverse': 'Remote -R',
|
|
1067
|
+
'settings.fwdReverseHint': 'The listener is on the remote; connections come back to the local target.',
|
|
975
1068
|
'settings.fwdStop': 'Stop',
|
|
976
1069
|
'settings.fwdStart': 'Start',
|
|
1070
|
+
'settings.fwdStarting': 'Starting…',
|
|
977
1071
|
'settings.fwdRemove': 'Remove',
|
|
978
|
-
'settings.fwdDirLocal': 'Local
|
|
979
|
-
'settings.fwdDirReverse': 'Remote
|
|
1072
|
+
'settings.fwdDirLocal': 'Local (-L)',
|
|
1073
|
+
'settings.fwdDirReverse': 'Remote (-R)',
|
|
980
1074
|
'settings.fwdListen': 'Listen port',
|
|
981
1075
|
'settings.fwdTargetHost': 'Target host',
|
|
982
1076
|
'settings.fwdTargetPort': 'Target port',
|
|
983
1077
|
'settings.fwdAuto': 'Auto reconnect',
|
|
1078
|
+
'settings.fwdAutoHint': 'Restore this forward automatically after a reconnect',
|
|
1079
|
+
'settings.fwdLegacyBadge': 'Re-confirm',
|
|
1080
|
+
'settings.fwdLegacyHint': 'The legacy auto-reconnect setting was paused: tick it again and start the forward once if needed.',
|
|
1081
|
+
'settings.fwdAutoNoticeTitle': 'What does Auto reconnect do?',
|
|
1082
|
+
'settings.fwdAutoNoticeBody': 'When checked, this forward remembers whether it was running.\n\ndsh web connects the current machine on startup and restores the forward once connected.\n\nIf the host is unreachable, credentials fail, or the port is taken, that restore fails without affecting anything else.\n\nAfter a DSH restart only forwards that were running come back (one that was never started stays down).',
|
|
1083
|
+
'settings.fwdAutoNoticeTitleReverse': 'What does Auto reconnect do for a reverse forward?',
|
|
1084
|
+
'settings.fwdAutoNoticeBodyReverse': 'When checked, this reverse forward remembers whether it was running.\n\ndsh web connects the current machine on startup and makes the REMOTE listen again, piping connections back to your machine. In other words, it re-opens the remote listener automatically after a restart.\n\nOnly reverse forwards that were running are restored; if the host is unreachable, AllowTcpForwarding was disabled, or the port is taken, that restore fails without affecting anything else.\n\nUncheck this or stop the forward if the remote must not listen again on its own.',
|
|
1085
|
+
'settings.fwdAutoNoticeConfirm': 'Enable anyway',
|
|
1086
|
+
'settings.fwdAutoNoticeCancel': 'Cancel',
|
|
1087
|
+
'settings.fwdAutoNoticeDontShow': "Don't show again",
|
|
984
1088
|
'settings.fwdAdd': 'Add forward',
|
|
985
1089
|
'settings.cleanup': 'Workspace cleanup (local mirrors & chats)',
|
|
986
1090
|
'settings.cleanupRefresh': 'Refresh',
|
|
@@ -1300,13 +1404,35 @@ window.__ModuleLoader__.load({
|
|
|
1300
1404
|
// The official Electron shell serves the shared API over its private
|
|
1301
1405
|
// dsh-app carrier. Legacy browser hosts keep their existing route prefix.
|
|
1302
1406
|
// Choose before sending: never retry a mutating request on another route.
|
|
1407
|
+
//
|
|
1408
|
+
// A browser host may mount the harness UNDER A PATH PREFIX (the fnOS
|
|
1409
|
+
// console serves it at /app/<app>/dsh/, and any prefix-stripping reverse
|
|
1410
|
+
// proxy does the same). The routes are registered at the server ROOT, so a
|
|
1411
|
+
// ROOT-ABSOLUTE '/dsh-remote/...' request would leave the mount and hit
|
|
1412
|
+
// the gateway's own SPA — a 404 with an empty body, and the remote
|
|
1413
|
+
// workspace panel then shows no hosts at all.
|
|
1414
|
+
//
|
|
1415
|
+
// The page's <base href="./"> makes every relative resource resolve
|
|
1416
|
+
// against the mount DIRECTORY, so the route must resolve the same way:
|
|
1417
|
+
// drop the leading slash and let the base carry the prefix. Resolving
|
|
1418
|
+
// against the base's own directory ('.' against the base URL) is exactly
|
|
1419
|
+
// what the browser does for the plugin bundle URL, so the API and the
|
|
1420
|
+
// bundle can never disagree about where the mount lives.
|
|
1303
1421
|
function apiPath(path) {
|
|
1304
|
-
|
|
1305
|
-
|
|
1422
|
+
if (window.location && window.location.protocol === 'dsh-app:') return '/api' + path
|
|
1423
|
+
const base = typeof document !== 'undefined' ? document.baseURI : ''
|
|
1424
|
+
if (!base) return path
|
|
1425
|
+
try {
|
|
1426
|
+
const baseUrl = new URL(base)
|
|
1427
|
+
if (baseUrl.protocol !== 'http:' && baseUrl.protocol !== 'https:') return path
|
|
1428
|
+
return new URL('.', baseUrl).pathname + path.replace(/^\/+/, '')
|
|
1429
|
+
} catch {
|
|
1430
|
+
return path
|
|
1431
|
+
}
|
|
1306
1432
|
}
|
|
1307
1433
|
|
|
1308
1434
|
function sessionQuery(sessionId) {
|
|
1309
|
-
return sessionId ? 'sessionId=' + encodeURIComponent(sessionId) : ''
|
|
1435
|
+
return sessionId ? 'sessionId=' + encodeURIComponent(sessionId) + (localWorkspaceSession(sessionId) ? '&workspace=local' : '') : ''
|
|
1310
1436
|
}
|
|
1311
1437
|
function withSessionQuery(path, sessionId) {
|
|
1312
1438
|
const q = sessionQuery(sessionId)
|
|
@@ -1315,7 +1441,7 @@ window.__ModuleLoader__.load({
|
|
|
1315
1441
|
}
|
|
1316
1442
|
function withSessionBody(body, sessionId) {
|
|
1317
1443
|
if (!sessionId) return body
|
|
1318
|
-
return Object.assign({}, body || {}, { sessionId })
|
|
1444
|
+
return Object.assign({}, body || {}, { sessionId }, localWorkspaceSession(sessionId) ? { workspace: 'local' } : {})
|
|
1319
1445
|
}
|
|
1320
1446
|
|
|
1321
1447
|
async function api(method, path, body, signal) {
|
|
@@ -1731,9 +1857,80 @@ window.__ModuleLoader__.load({
|
|
|
1731
1857
|
observer.observe(document.body, { childList: true, subtree: true }); sync()
|
|
1732
1858
|
return () => { observer.disconnect(); for (const button of marked) button.removeAttribute('data-rw-settings-legacy-icon') }
|
|
1733
1859
|
}
|
|
1734
|
-
|
|
1735
|
-
|
|
1860
|
+
// A slow probe uses the server's configured connectTimeoutMs; the client
|
|
1861
|
+
// never overrides it. Only a genuine timeout may be retried (never exit -1).
|
|
1862
|
+
const isProbeTimeout = (error) => /\bETIMEDOUT\b|\btimed[\s-]?out\b|\btimeout\b/i.test(String((error && error.message) || error || ''))
|
|
1863
|
+
// dsh-remote-fix4: identity, not alias, is what a probe may dial once, and
|
|
1864
|
+
// what a list row may show once. `dogyun`, `dg` and `dogyun.up2mountain.top`
|
|
1865
|
+
// are one machine; showing or probing them three times was how the same
|
|
1866
|
+
// server came out green, red and green in one sweep.
|
|
1867
|
+
const identityKeyOf = (host, port, username) => String(host || '').trim().toLowerCase() + '|' + (Number(port) || 22) + '|' + String(username || '').trim()
|
|
1868
|
+
/** Resolved identity of a ~/.ssh/config entry — the alias is only a name. */
|
|
1869
|
+
const hostIdentityKey = (h) => identityKeyOf(h && (h.hostName || h.alias || h.host), h && h.port, h && h.user)
|
|
1870
|
+
/** A discovered alias may share a probe only when its effective SSH
|
|
1871
|
+
* connection settings match, not merely when HostName/User/Port match. */
|
|
1872
|
+
const discoveredConfigKey = (h) => JSON.stringify([hostIdentityKey(h), String((h && h.identityFile) || ''), String((h && h.proxyJump) || ''), String((h && h.proxyCommand) || '')])
|
|
1873
|
+
/** Resolved identity of a saved machine (registry values may be stale). */
|
|
1874
|
+
const machineIdentityKey = (m) => identityKeyOf((m && m.sshConfigResolved && m.sshConfigResolved.host) || (m && m.host), (m && m.sshConfigResolved && m.sshConfigResolved.port) || (m && m.port), (m && m.sshConfigResolved && m.sshConfigResolved.username) || (m && m.username))
|
|
1875
|
+
/** Effective SSH settings of a saved alias, in the same key shape as a
|
|
1876
|
+
* discovered entry. Missing metadata never becomes an endpoint fallback. */
|
|
1877
|
+
const machineConfigKey = (m) => {
|
|
1878
|
+
const r = m && m.sshConfigResolved
|
|
1879
|
+
if (!r || !r.matched) return ''
|
|
1880
|
+
return discoveredConfigKey({ hostName: r.host, port: r.port, user: r.username,
|
|
1881
|
+
identityFile: r.identityFile, proxyJump: r.proxyJump, proxyCommand: r.proxyCommand })
|
|
1736
1882
|
}
|
|
1883
|
+
/** Git-only hosts: SSH works, but there is no shell and no workspace. */
|
|
1884
|
+
const isGitHost = (value) => /(^|\.)github\.com$/i.test(String(value || '').trim())
|
|
1885
|
+
// Saved GitHub rows remain manageable, but a known shell-less endpoint is
|
|
1886
|
+
// not probed as if it were a remote workspace host.
|
|
1887
|
+
const shouldProbeMachine = (m) => !isGitHost(m && m.host) && !isGitHost(m && m.sshConfigResolved && m.sshConfigResolved.host)
|
|
1888
|
+
/**
|
|
1889
|
+
* One entry per resolved identity, preferring the block's canonical name
|
|
1890
|
+
* (the alias that equals HostName) over a short alias.
|
|
1891
|
+
*/
|
|
1892
|
+
function dedupeHostEntries(hosts) {
|
|
1893
|
+
const byIdentity = new Map()
|
|
1894
|
+
for (const host of hosts || []) {
|
|
1895
|
+
const name = String((host && (host.alias || host.host)) || '')
|
|
1896
|
+
if (isGitHost(name) || isGitHost(host && host.hostName) || isGitHost(host && host.host)) continue
|
|
1897
|
+
const key = discoveredConfigKey(host)
|
|
1898
|
+
const current = byIdentity.get(key)
|
|
1899
|
+
if (!current) { byIdentity.set(key, host); continue }
|
|
1900
|
+
const currentName = String(current.alias || current.host || '')
|
|
1901
|
+
const canonical = String((host && host.hostName) || '')
|
|
1902
|
+
if (currentName !== String(current.hostName || '') && name === canonical) byIdentity.set(key, host)
|
|
1903
|
+
}
|
|
1904
|
+
return [...byIdentity.values()]
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
/** Saved records keep their own management and probe identity. Only a
|
|
1908
|
+
* resolved SSH identity or an exact alias may suppress a discovered row. */
|
|
1909
|
+
function savedSshIdentitySets(machines) {
|
|
1910
|
+
const resolvedIdentities = new Set(), aliases = new Set()
|
|
1911
|
+
for (const m of machines || []) {
|
|
1912
|
+
if (m && m.sshConfigResolved && m.sshConfigResolved.matched) resolvedIdentities.add(machineConfigKey(m))
|
|
1913
|
+
if (m && m.useSshConfig && m.host) aliases.add(String(m.host))
|
|
1914
|
+
}
|
|
1915
|
+
return { resolvedIdentities, aliases }
|
|
1916
|
+
}
|
|
1917
|
+
function dedupeDiscoveredForSaved(hosts, machines) {
|
|
1918
|
+
const { resolvedIdentities, aliases } = savedSshIdentitySets(machines)
|
|
1919
|
+
const suppressed = new Set(resolvedIdentities)
|
|
1920
|
+
// Resolve an exact saved alias through the discovered config itself. This
|
|
1921
|
+
// suppresses the whole alias group before canonical-name selection, so a
|
|
1922
|
+
// saved short alias cannot reappear under its full HostName sibling.
|
|
1923
|
+
for (const h of hosts || []) {
|
|
1924
|
+
const alias = String((h && (h.alias || h.host)) || '')
|
|
1925
|
+
if (aliases.has(alias)) suppressed.add(discoveredConfigKey(h))
|
|
1926
|
+
}
|
|
1927
|
+
return dedupeHostEntries(hosts).filter((h) => !suppressed.has(discoveredConfigKey(h)))
|
|
1928
|
+
}
|
|
1929
|
+
// dsh-remote-fix4: the old discoveredProbeTargets() built one probe target
|
|
1930
|
+
// per ~/.ssh/config alias and only filtered exact-name duplicates. The sweep
|
|
1931
|
+
// now derives its targets from the deduped lists inside each component, so
|
|
1932
|
+
// keeping a second, differently-deduped builder here would invite the two to
|
|
1933
|
+
// drift apart.
|
|
1737
1934
|
function RemoteWorkspacePage() {
|
|
1738
1935
|
const settingsId = React.useId()
|
|
1739
1936
|
const [settingsTab, setSettingsTab] = React.useState('hosts')
|
|
@@ -1783,6 +1980,14 @@ window.__ModuleLoader__.load({
|
|
|
1783
1980
|
// push the update/audit cards far down the page for a feature most sessions
|
|
1784
1981
|
// never touch.
|
|
1785
1982
|
const [fwdOpen, setFwdOpen] = React.useState(false)
|
|
1983
|
+
// id → true while a start/stop request is in flight; the row shows a
|
|
1984
|
+
// pending label and cannot be clicked twice (a second click used to race
|
|
1985
|
+
// the first one for the same listen port).
|
|
1986
|
+
const [fwdBusy, setFwdBusy] = React.useState({})
|
|
1987
|
+
// First-time explanation for 自动重连. `fwdNotice.target` is either
|
|
1988
|
+
// {kind:'row', id} or {kind:'form'} (the add-forward form's checkbox).
|
|
1989
|
+
const [fwdNotice, setFwdNotice] = React.useState(null)
|
|
1990
|
+
const [fwdNoticeDontShow, setFwdNoticeDontShow] = React.useState(false)
|
|
1786
1991
|
const [auditOpen, setAuditOpen] = React.useState(false)
|
|
1787
1992
|
// Issue #96: workspace cleanup on Web/Desktop (the TUI's machine-menu
|
|
1788
1993
|
// cleanup page has an in-process API; here it is these two routes).
|
|
@@ -2106,6 +2311,7 @@ window.__ModuleLoader__.load({
|
|
|
2106
2311
|
probeRevision.current++; settingsEditorDraft = null; formBaseline.current = null
|
|
2107
2312
|
const focusId = settingsId + '-actions-' + form.id
|
|
2108
2313
|
clearForm(); setErr(''); setMsg(''); setTst(''); setAdvOpen(false)
|
|
2314
|
+
setProbeGeneration(value => value + 1)
|
|
2109
2315
|
window.setTimeout(() => document.getElementById(focusId)?.focus?.(), 0)
|
|
2110
2316
|
}
|
|
2111
2317
|
const clearForm = () => 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 })
|
|
@@ -2177,10 +2383,30 @@ window.__ModuleLoader__.load({
|
|
|
2177
2383
|
// Every visible host is tested once on entry/config changes; at most three
|
|
2178
2384
|
// probes run together. Leaving the page cancels queued work and stale results.
|
|
2179
2385
|
const [probeGeneration, setProbeGeneration] = React.useState(0)
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2386
|
+
// dsh-remote-fix5: derivation hoisted - the probe queue below reads
|
|
2387
|
+
// these lists, so declaring them afterwards is a TDZ crash at render.
|
|
2388
|
+
//
|
|
2389
|
+
// Saved records are NEVER collapsed: the same endpoint can intentionally
|
|
2390
|
+
// use different credentials, backends or proxies. Only discovered rows
|
|
2391
|
+
// are deduped, and explicit saved records (including GitHub) stay visible.
|
|
2392
|
+
const uniqueMachines = machines
|
|
2393
|
+
const discovered = dedupeDiscoveredForSaved(sshHosts || [], machines)
|
|
2394
|
+
|
|
2395
|
+
// Keep row order stable while connectivity results arrive.
|
|
2396
|
+
const sortedMachines = [...uniqueMachines].sort((a, b) => String(a.name || a.host).localeCompare(String(b.name || b.host)))
|
|
2397
|
+
// Every saved machine id gets its own probe (credentials and backend are
|
|
2398
|
+
// record-specific); each discovered effective config gets at most one.
|
|
2399
|
+
const probeTargets = []
|
|
2400
|
+
for (const machine of uniqueMachines) {
|
|
2401
|
+
if (!shouldProbeMachine(machine)) continue
|
|
2402
|
+
const identity = machineIdentityKey(machine)
|
|
2403
|
+
probeTargets.push({ key: 'machine:' + machine.id, identity, body: { id: machine.id, host: machine.host, port: machine.port, username: machine.username, useSshConfig: !!machine.useSshConfig }, fingerprint: machine })
|
|
2404
|
+
}
|
|
2405
|
+
for (const host of discovered) {
|
|
2406
|
+
const identity = discoveredConfigKey(host)
|
|
2407
|
+
const alias = String(host.alias || host.host)
|
|
2408
|
+
probeTargets.push({ key: 'ssh:' + alias, identity, body: { host: alias, port: Number(host.port) || 22, username: host.user || '', useSshConfig: true }, fingerprint: host })
|
|
2409
|
+
}
|
|
2184
2410
|
probeTargets.sort((a, b) => a.key.localeCompare(b.key))
|
|
2185
2411
|
const probeSignature = JSON.stringify(probeTargets.map(target => ({ ...target, fingerprint: target.fingerprint && { ...target.fingerprint, connected: undefined, lastConnectedAt: undefined, latencyMs: undefined, recentWorkspaces: undefined, workspace: undefined } })))
|
|
2186
2412
|
React.useEffect(() => {
|
|
@@ -2192,7 +2418,21 @@ window.__ModuleLoader__.load({
|
|
|
2192
2418
|
while (queue.length && !controller.signal.aborted) {
|
|
2193
2419
|
const target = queue.shift()
|
|
2194
2420
|
try {
|
|
2195
|
-
|
|
2421
|
+
// Omitting connectTimeoutMs lets the server use its real config.
|
|
2422
|
+
// The route reports failures as 200 + {ok:false,error}, so one
|
|
2423
|
+
// loop handles both throw and payload forms, at most two attempts.
|
|
2424
|
+
const probeBody = target.body
|
|
2425
|
+
let result
|
|
2426
|
+
for (let attempt = 1; attempt <= 2; attempt++) {
|
|
2427
|
+
try {
|
|
2428
|
+
result = await api('POST', '/dsh-remote/test-connect', probeBody, controller.signal)
|
|
2429
|
+
} catch (error) {
|
|
2430
|
+
if (controller.signal.aborted || attempt === 2 || !isProbeTimeout(error)) throw error
|
|
2431
|
+
continue
|
|
2432
|
+
}
|
|
2433
|
+
if (attempt < 2 && !controller.signal.aborted && result && result.ok === false && isProbeTimeout(result.error)) continue
|
|
2434
|
+
break
|
|
2435
|
+
}
|
|
2196
2436
|
if (!controller.signal.aborted) setRow(target.key, { ok: !!result?.ok, latencyMs: result?.latencyMs, text: result?.ok ? '' : result?.error || tr('settings.connFail') })
|
|
2197
2437
|
} catch (error) {
|
|
2198
2438
|
if (!controller.signal.aborted) setRow(target.key, { ok: false, text: String(error.message || error) })
|
|
@@ -2200,15 +2440,68 @@ window.__ModuleLoader__.load({
|
|
|
2200
2440
|
}
|
|
2201
2441
|
}
|
|
2202
2442
|
Promise.all(Array.from({ length: Math.min(3, queue.length) }, () => worker()))
|
|
2203
|
-
return () =>
|
|
2443
|
+
return () => {
|
|
2444
|
+
controller.abort()
|
|
2445
|
+
// Aborted rows must not remain visually pending forever. Completed
|
|
2446
|
+
// results stay; a new effect will rebuild its own pending queue.
|
|
2447
|
+
setRowState((prev) => Object.fromEntries(Object.entries(prev || {}).filter(([, value]) => !value || !value.pending)))
|
|
2448
|
+
}
|
|
2204
2449
|
}, [probeSignature, probeGeneration, hostsLoaded, sshHosts === null])
|
|
2205
2450
|
const refreshHosts = () => { setProbeGeneration(value => value + 1); refresh().catch(error => setErr(String(error.message || error))); loadSshHosts() }
|
|
2206
2451
|
|
|
2207
2452
|
// ── forwards panel ────────────────────────────────────────────────────
|
|
2208
|
-
const fwdAction = (action, id) => {
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2453
|
+
const fwdAction = (action, id, extra) => {
|
|
2454
|
+
setFwdBusy((m) => ({ ...m, [id]: true }))
|
|
2455
|
+
// apiRaw, not api: a failed start still carries the CURRENT list (a
|
|
2456
|
+
// concurrent autoStart pass may have bound the port already), and the UI
|
|
2457
|
+
// must not keep showing 启动 for a tunnel that is listening.
|
|
2458
|
+
apiRaw('POST', '/dsh-remote/forwards', { action, id, ...(extra || {}) })
|
|
2459
|
+
.then(({ status, data }) => {
|
|
2460
|
+
const body = data || {}
|
|
2461
|
+
if (Array.isArray(body.forwards)) setForwards(body.forwards)
|
|
2462
|
+
if (status >= 400 || body.ok === false) {
|
|
2463
|
+
setErr(String(body.error || ('HTTP ' + status)))
|
|
2464
|
+
if (!Array.isArray(body.forwards)) refreshForwards()
|
|
2465
|
+
return
|
|
2466
|
+
}
|
|
2467
|
+
setErr('')
|
|
2468
|
+
setMsg('')
|
|
2469
|
+
})
|
|
2470
|
+
.catch((e) => { setErr(String((e && e.message) || e)); refreshForwards() })
|
|
2471
|
+
.finally(() => setFwdBusy((m) => {
|
|
2472
|
+
if (!m[id]) return m
|
|
2473
|
+
const next = { ...m }
|
|
2474
|
+
delete next[id]
|
|
2475
|
+
return next
|
|
2476
|
+
}))
|
|
2477
|
+
}
|
|
2478
|
+
// The two directions carry different risks, so they are explained (and
|
|
2479
|
+
// remembered) separately: dismissing the local notice must not silence
|
|
2480
|
+
// the reverse-listener warning.
|
|
2481
|
+
const fwdNoticeKey = (direction) => 'dsh-remote.fwd-auto-notice-' + (direction === 'reverse' ? 'reverse' : 'local') + '-v1'
|
|
2482
|
+
const fwdNoticeDismissed = (direction) => {
|
|
2483
|
+
try { return window.localStorage.getItem(fwdNoticeKey(direction)) === '1' } catch { return false }
|
|
2484
|
+
}
|
|
2485
|
+
const dismissFwdNotice = (direction) => {
|
|
2486
|
+
try { window.localStorage.setItem(fwdNoticeKey(direction), '1') } catch { /* private mode */ }
|
|
2487
|
+
}
|
|
2488
|
+
const applyFwdAutoStart = (target, value) => {
|
|
2489
|
+
if (target.kind === 'form') { setFwdForm((form) => ({ ...form, autoStart: !!value })); return }
|
|
2490
|
+
fwdAction('update', target.id, { autoStart: !!value })
|
|
2491
|
+
}
|
|
2492
|
+
// The semantics are not obvious on first use: explain once, with a
|
|
2493
|
+
// "不再提示" opt-out stored in the browser.
|
|
2494
|
+
const requestFwdAutoStart = (target, value, direction) => {
|
|
2495
|
+
if (!value) { applyFwdAutoStart(target, false); return }
|
|
2496
|
+
if (fwdNoticeDismissed(direction)) { applyFwdAutoStart(target, true); return }
|
|
2497
|
+
setFwdNoticeDontShow(false)
|
|
2498
|
+
setFwdNotice({ target, direction })
|
|
2499
|
+
}
|
|
2500
|
+
const confirmFwdNotice = () => {
|
|
2501
|
+
if (!fwdNotice) return
|
|
2502
|
+
if (fwdNoticeDontShow) dismissFwdNotice(fwdNotice.direction)
|
|
2503
|
+
applyFwdAutoStart(fwdNotice.target, true)
|
|
2504
|
+
setFwdNotice(null)
|
|
2212
2505
|
}
|
|
2213
2506
|
const fwdDefine = () => {
|
|
2214
2507
|
if (!fwdForm.listenPort) return
|
|
@@ -2240,11 +2533,6 @@ window.__ModuleLoader__.load({
|
|
|
2240
2533
|
// first thing the page shows, because that is the whole list a VSCode
|
|
2241
2534
|
// Remote-SSH user expects. A saved alias machine hides its file entry (the row
|
|
2242
2535
|
// below it is the same host, with the actions that belong to a saved machine).
|
|
2243
|
-
const savedAliases = new Set(machines.filter((m) => m.useSshConfig).map((m) => String(m.host)))
|
|
2244
|
-
const discovered = (sshHosts || []).filter((h) => !savedAliases.has(String(h.alias || h.host)))
|
|
2245
|
-
|
|
2246
|
-
// Keep row order stable while connectivity results arrive.
|
|
2247
|
-
const sortedMachines = [...machines].sort((a, b) => String(a.name || a.host).localeCompare(String(b.name || b.host)))
|
|
2248
2536
|
|
|
2249
2537
|
// One filter box for BOTH halves of the list (ssh-config hosts + saved ones).
|
|
2250
2538
|
const needle = hostFilter.trim().toLowerCase()
|
|
@@ -2266,6 +2554,27 @@ window.__ModuleLoader__.load({
|
|
|
2266
2554
|
return React.createElement('div',
|
|
2267
2555
|
{ className: 'dsh-rw-settings', 'data-rw-settings': true, 'aria-label': tr('settings.title'), style: { color: T.label } },
|
|
2268
2556
|
confirmUi.node,
|
|
2557
|
+
fwdNotice ? React.createElement('div', {
|
|
2558
|
+
style: { position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.45)', display: 'flex', alignItems: 'center', justifyContent: 'center', zIndex: 3000 },
|
|
2559
|
+
},
|
|
2560
|
+
React.createElement('div', {
|
|
2561
|
+
role: 'dialog', 'aria-modal': 'true',
|
|
2562
|
+
'aria-label': tr(fwdNotice.direction === 'reverse' ? 'settings.fwdAutoNoticeTitleReverse' : 'settings.fwdAutoNoticeTitle'),
|
|
2563
|
+
className: 'dsh-rw-forward-notice',
|
|
2564
|
+
style: { width: 480, maxWidth: '92vw', background: T.bg, border: '1px solid ' + T.border, borderRadius: 12, padding: '18px 20px', boxShadow: '0 16px 48px rgba(0,0,0,0.35)', color: T.label },
|
|
2565
|
+
},
|
|
2566
|
+
React.createElement('div', { style: { fontSize: 15, fontWeight: 650, letterSpacing: '-0.01em', marginBottom: 10 } }, tr(fwdNotice.direction === 'reverse' ? 'settings.fwdAutoNoticeTitleReverse' : 'settings.fwdAutoNoticeTitle')),
|
|
2567
|
+
React.createElement('div', { style: { display: 'flex', flexDirection: 'column', gap: 8 } },
|
|
2568
|
+
tr(fwdNotice.direction === 'reverse' ? 'settings.fwdAutoNoticeBodyReverse' : 'settings.fwdAutoNoticeBody').split('\n\n').map((paragraph, index) => React.createElement('div', {
|
|
2569
|
+
key: index,
|
|
2570
|
+
style: { fontSize: 12.5, lineHeight: 1.6, color: index === 0 ? T.label : T.muted },
|
|
2571
|
+
}, paragraph))),
|
|
2572
|
+
React.createElement('label', { style: { display: 'flex', gap: 6, alignItems: 'center', fontSize: 12, marginTop: 16 } },
|
|
2573
|
+
React.createElement('input', { type: 'checkbox', checked: fwdNoticeDontShow, onChange: (e) => setFwdNoticeDontShow(!!e.target.checked) }),
|
|
2574
|
+
tr('settings.fwdAutoNoticeDontShow')),
|
|
2575
|
+
React.createElement('div', { style: { display: 'flex', gap: 8, justifyContent: 'flex-end', marginTop: 16 } },
|
|
2576
|
+
React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, padding: '4px 14px' }, onClick: () => setFwdNotice(null) }, tr('settings.fwdAutoNoticeCancel')),
|
|
2577
|
+
React.createElement('button', { type: 'button', className: 'dsh-rw-btn dsh-rw-primary', style: { ...primaryBtnS, padding: '4px 14px' }, onClick: confirmFwdNotice }, tr('settings.fwdAutoNoticeConfirm'))))) : null,
|
|
2269
2578
|
React.createElement('div', { style: { fontSize: 16, fontWeight: 650, letterSpacing: '-0.01em' } }, tr('settings.pageTitle')),
|
|
2270
2579
|
React.createElement('div', { style: { fontSize: 12, opacity: 0.8, lineHeight: 1.55 } },
|
|
2271
2580
|
tr('settings.intro')),
|
|
@@ -2534,23 +2843,70 @@ window.__ModuleLoader__.load({
|
|
|
2534
2843
|
React.createElement('div', { style: boxS },
|
|
2535
2844
|
sectionToggle(fwdOpen, setFwdOpen, tr('settings.forwards')),
|
|
2536
2845
|
fwdOpen ? React.createElement(React.Fragment, null,
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
f.
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
React.createElement('
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2846
|
+
React.createElement('div', { style: { opacity: 0.65, fontSize: 11, lineHeight: 1.5, marginBottom: 8 } }, tr('settings.forwardsHint')),
|
|
2847
|
+
forwards.length ? forwards.map((f) => {
|
|
2848
|
+
const busy = !!fwdBusy[f.id]
|
|
2849
|
+
return React.createElement('div', { key: f.id, className: 'dsh-rw-row', style: { display: 'flex', gap: 8, alignItems: 'center', padding: '6px 0', fontSize: 12, fontFamily: 'monospace' } },
|
|
2850
|
+
React.createElement('span', { style: { color: f.active ? T.ok : T.muted } }, f.active ? '●' : '○'),
|
|
2851
|
+
React.createElement('span', {
|
|
2852
|
+
title: f.direction === 'reverse' ? tr('settings.fwdDirReverse') : tr('settings.fwdDirLocal'),
|
|
2853
|
+
style: { flex: '0 0 auto', color: T.muted, opacity: 0.85 },
|
|
2854
|
+
}, f.direction === 'reverse' ? '-R' : '-L'),
|
|
2855
|
+
React.createElement('span', {
|
|
2856
|
+
title: tr(f.direction === 'reverse' ? 'settings.fwdReverseHint' : 'settings.fwdLocalHint'),
|
|
2857
|
+
style: { flex: 1 },
|
|
2858
|
+
}, `127.0.0.1:${f.listenPort} → ${f.targetHost}:${f.targetPort}`),
|
|
2859
|
+
f.needsReconsent ? React.createElement('span', {
|
|
2860
|
+
title: tr('settings.fwdLegacyHint'),
|
|
2861
|
+
style: { fontSize: 10, color: T.warn, border: '1px solid ' + T.border, borderRadius: 4, padding: '0 4px', whiteSpace: 'nowrap' },
|
|
2862
|
+
}, tr('settings.fwdLegacyBadge')) : null,
|
|
2863
|
+
React.createElement('label', {
|
|
2864
|
+
style: { display: 'flex', alignItems: 'center', gap: 4, fontSize: 11, color: T.muted, whiteSpace: 'nowrap' },
|
|
2865
|
+
title: tr('settings.fwdAutoHint'),
|
|
2866
|
+
},
|
|
2867
|
+
React.createElement('input', {
|
|
2868
|
+
type: 'checkbox',
|
|
2869
|
+
checked: !!f.autoStart,
|
|
2870
|
+
disabled: busy,
|
|
2871
|
+
'aria-label': tr('settings.fwdAuto'),
|
|
2872
|
+
onChange: (e) => requestFwdAutoStart({ kind: 'row', id: f.id }, !!e.target.checked, f.direction),
|
|
2873
|
+
}),
|
|
2874
|
+
tr('settings.fwdAuto')),
|
|
2875
|
+
f.active
|
|
2876
|
+
? React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, padding: '2px 8px' }, disabled: busy, onClick: () => fwdAction('stop', f.id) }, tr('settings.fwdStop'))
|
|
2877
|
+
: React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, padding: '2px 8px' }, disabled: busy, onClick: () => fwdAction('start', f.id) }, busy ? tr('settings.fwdStarting') : tr('settings.fwdStart')),
|
|
2878
|
+
React.createElement('button', { type: 'button', className: 'dsh-rw-btn', style: { ...buttonS, padding: '2px 8px' }, disabled: busy, onClick: () => fwdAction('remove', f.id) }, tr('settings.fwdRemove')))
|
|
2879
|
+
}) : null,
|
|
2880
|
+
React.createElement('div', { style: { display: 'flex', gap: 6, alignItems: 'center', marginTop: 8, flexWrap: 'wrap' } },
|
|
2881
|
+
React.createElement('div', {
|
|
2882
|
+
role: 'group', 'aria-label': tr('settings.forwards'),
|
|
2883
|
+
style: { display: 'flex', alignItems: 'stretch', flex: '0 0 auto', height: 30, border: '1px solid ' + T.border, borderRadius: T.radius, overflow: 'hidden' },
|
|
2884
|
+
},
|
|
2885
|
+
['local', 'reverse'].map((value) => React.createElement('button', {
|
|
2886
|
+
key: value, type: 'button',
|
|
2887
|
+
'aria-pressed': fwdForm.direction === value,
|
|
2888
|
+
onClick: () => setFwdForm({ ...fwdForm, direction: value }),
|
|
2889
|
+
style: {
|
|
2890
|
+
border: 'none', cursor: 'pointer', padding: '0 8px', fontSize: 11, whiteSpace: 'nowrap',
|
|
2891
|
+
background: fwdForm.direction === value ? T.primary : 'transparent',
|
|
2892
|
+
color: fwdForm.direction === value ? T.onPrimary : T.muted,
|
|
2893
|
+
},
|
|
2894
|
+
}, tr(value === 'local' ? 'settings.fwdSideLocal' : 'settings.fwdSideReverse')))),
|
|
2895
|
+
React.createElement('input', { className: 'dsh-rw-input', value: fwdForm.listenPort, onChange: (e) => setFwdForm({ ...fwdForm, listenPort: e.target.value }), placeholder: tr('settings.fwdListen'), style: { ...inputS, flex: '0 0 90px', width: 90, minWidth: 0, boxSizing: 'border-box', padding: '6px 8px' } }),
|
|
2896
|
+
React.createElement('span', { style: { opacity: 0.55, fontSize: 12, flex: '0 0 auto' } }, '→'),
|
|
2897
|
+
React.createElement('input', { className: 'dsh-rw-input', value: fwdForm.targetHost, onChange: (e) => setFwdForm({ ...fwdForm, targetHost: e.target.value }), placeholder: tr('settings.fwdTargetHost'), style: { ...inputS, flex: '1 1 100px', width: 'auto', minWidth: 90, maxWidth: 240, boxSizing: 'border-box', padding: '6px 8px' } }),
|
|
2898
|
+
React.createElement('span', { style: { opacity: 0.55, fontSize: 12, flex: '0 0 auto' } }, ':'),
|
|
2899
|
+
React.createElement('input', { className: 'dsh-rw-input', value: fwdForm.targetPort, onChange: (e) => setFwdForm({ ...fwdForm, targetPort: e.target.value }), placeholder: tr('settings.fwdTargetPort'), style: { ...inputS, flex: '0 0 72px', width: 72, minWidth: 0, boxSizing: 'border-box', padding: '6px 8px' } })),
|
|
2900
|
+
// Fields on their own row, then the option + primary action: this is
|
|
2901
|
+
// the plugin's existing form pattern (.dsh-rw-settings-editor-actions
|
|
2902
|
+
// right-aligns its primary button), and it keeps 添加转发 from sitting
|
|
2903
|
+
// alone on a wrapped third line.
|
|
2904
|
+
React.createElement('div', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8, marginTop: 8 } },
|
|
2905
|
+
React.createElement('label', { style: { fontSize: 12, display: 'flex', gap: 4, alignItems: 'center', whiteSpace: 'nowrap' } },
|
|
2906
|
+
React.createElement('input', { type: 'checkbox', checked: fwdForm.autoStart, onChange: (e) => requestFwdAutoStart({ kind: 'form' }, !!e.target.checked, fwdForm.direction) }), tr('settings.fwdAuto')),
|
|
2553
2907
|
React.createElement('button', { type: 'button', className: 'dsh-rw-btn dsh-rw-primary', style: primaryBtnS, onClick: fwdDefine, disabled: !fwdForm.listenPort, title: fwdForm.listenPort ? tr('settings.fwdAddHint') : tr('settings.fwdNeedsPort') }, tr('settings.fwdAdd'))),
|
|
2908
|
+
React.createElement('div', { style: { opacity: 0.6, fontSize: 11, lineHeight: 1.5, marginTop: 6 } },
|
|
2909
|
+
tr(fwdForm.direction === 'reverse' ? 'settings.fwdReverseHint' : 'settings.fwdLocalHint')),
|
|
2554
2910
|
) : null,
|
|
2555
2911
|
),
|
|
2556
2912
|
React.createElement('div', { style: boxS },
|
|
@@ -2800,8 +3156,9 @@ window.__ModuleLoader__.load({
|
|
|
2800
3156
|
const matches = (...fields) => !needle || fields.some((f) => String(f || '').toLowerCase().includes(needle))
|
|
2801
3157
|
const sorted = machines.slice().sort((a, b) => (Date.parse(b.lastConnectedAt) || 0) - (Date.parse(a.lastConnectedAt) || 0))
|
|
2802
3158
|
const recentProjects = sorted.flatMap((m) => (m.recentWorkspaces || []).filter((p) => matches(m.name, m.host, p)).map((path) => ({ machine: m, path })))
|
|
2803
|
-
|
|
2804
|
-
|
|
3159
|
+
// The picker keeps every saved record too; only discovered aliases are
|
|
3160
|
+
// deduped or hidden behind a saved SSH identity / exact alias.
|
|
3161
|
+
const discovered = dedupeDiscoveredForSaved(hosts || [], sorted).filter((h) => matches(h.alias, h.hostName, h.host, h.user))
|
|
2805
3162
|
const saved = sorted.filter((m) => matches(m.name, m.host, m.username))
|
|
2806
3163
|
const chooseAlias = async (h) => {
|
|
2807
3164
|
if (busy || opening) return
|
|
@@ -2992,6 +3349,13 @@ window.__ModuleLoader__.load({
|
|
|
2992
3349
|
const cands = [{ host: String(m.host || ''), port: Number(m.port) || 22, username: String(m.username || '') }]
|
|
2993
3350
|
const r = m.sshConfigResolved
|
|
2994
3351
|
if (r && r.host) cands.push({ host: String(r.host), port: Number(r.port) || 22, username: String(r.username || m.username || '') })
|
|
3352
|
+
// System OpenSSH hands the alias to ssh and deliberately emits no -l/-p.
|
|
3353
|
+
// Its pool echo is therefore alias/22/'' even when the registry and
|
|
3354
|
+
// resolved config name a concrete user and a non-default SSH Port.
|
|
3355
|
+
// Accept that exact transport identity without making '' a wildcard.
|
|
3356
|
+
const aliasOpenssh = String(m.backend || '').toLowerCase() === 'openssh'
|
|
3357
|
+
&& (m.useSshConfig || (r && r.matched))
|
|
3358
|
+
if (aliasOpenssh) cands.push({ host: String(m.host || ''), port: 22, username: '' })
|
|
2995
3359
|
return cands.some((c) => c.host === String(echo.host) && c.port === (Number(echo.port) || 22) && c.username === String(echo.username || ''))
|
|
2996
3360
|
}
|
|
2997
3361
|
|
|
@@ -3309,6 +3673,33 @@ window.__ModuleLoader__.load({
|
|
|
3309
3673
|
const res = await api('POST', '/dsh-remote/mirror', { path: target, machineId: selectedMachineId, registerWorkspace: registerWorkspace !== false }, signal)
|
|
3310
3674
|
if (!current()) return
|
|
3311
3675
|
if (!res || !res.localMirror) throw new Error((res && res.error) || tr('project.failed'))
|
|
3676
|
+
// dsh-remote-fix2: mirror-cache — record the mirror BEFORE the host adopts it.
|
|
3677
|
+
// `localWorkspaceSession()` classifies a session as local when its
|
|
3678
|
+
// cwd is outside every cached mirror, and the host rejects local
|
|
3679
|
+
// requests for a mirror it binds remotely (409 "Workspace execution
|
|
3680
|
+
// context changed"). The registry here is normally loaded once at
|
|
3681
|
+
// startup, so a mirror created a second ago is missing from it: the
|
|
3682
|
+
// first requests of the new session would be misclassified. Adding
|
|
3683
|
+
// the entry now makes the new session remote from request one; the
|
|
3684
|
+
// delayed refresh below then replaces it with the on-disk record.
|
|
3685
|
+
const newMirror = res.machine || {}
|
|
3686
|
+
const newMirrorDir = String(res.localMirror || '')
|
|
3687
|
+
mirrorGeneration += 1 // supersede any registry request started before this mutation
|
|
3688
|
+
if (newMirrorDir && !MIRRORS.list.some((m) => m && sameMirrorDir(m.dir, newMirrorDir))) {
|
|
3689
|
+
MIRRORS.list.push({
|
|
3690
|
+
dir: newMirrorDir,
|
|
3691
|
+
host: String(newMirror.host || ''),
|
|
3692
|
+
port: Number(newMirror.port) || 22,
|
|
3693
|
+
username: String(newMirror.username || ''),
|
|
3694
|
+
remotePath: String(res.path || target),
|
|
3695
|
+
alias: '',
|
|
3696
|
+
name: '',
|
|
3697
|
+
})
|
|
3698
|
+
}
|
|
3699
|
+
// Keep loaded/error tied to the latest authoritative GET. An optimistic
|
|
3700
|
+
// entry is confirmed, but a partial or failed registry is not healthy.
|
|
3701
|
+
notifyMirrors()
|
|
3702
|
+
setTimeout(() => { void refreshMirrors() }, 2000)
|
|
3312
3703
|
await onPicked(res.localMirror, res.path || target)
|
|
3313
3704
|
})
|
|
3314
3705
|
}
|
|
@@ -3750,7 +4141,34 @@ window.__ModuleLoader__.load({
|
|
|
3750
4141
|
return api('POST', EXPLORER_AUTO_OPEN_ROUTE, { enabled: on }).catch(() => null)
|
|
3751
4142
|
}
|
|
3752
4143
|
|
|
4144
|
+
// A registry read at least once, plus the session's own cwd, proves local vs
|
|
4145
|
+
// remote. `known` rather than `loaded` is deliberate: `refreshMirrors()`
|
|
4146
|
+
// clears `loaded` while /bindings is in flight, and classifying against that
|
|
4147
|
+
// window demoted a local session to "remote with no root" mid-refresh, which
|
|
4148
|
+
// reset the pane and discarded the refresh the user had just asked for.
|
|
4149
|
+
// Registry failure still never turns an unrecognised mirror into local.
|
|
4150
|
+
function localWorkspaceSession(sessionId) {
|
|
4151
|
+
const cwd = sessionCwdFor(sessionId)
|
|
4152
|
+
return !!(cwd && MIRRORS.known && !MIRRORS.error && !mirrorForCwd(cwd, MIRRORS.list))
|
|
4153
|
+
}
|
|
4154
|
+
function workspaceText(key, sessionId, params) {
|
|
4155
|
+
return tr(localWorkspaceSession(sessionId) && L.en['local.' + key] ? 'local.' + key : key, params)
|
|
4156
|
+
}
|
|
4157
|
+
function workspaceSummary(sessionId) {
|
|
4158
|
+
const cwd = sessionCwdFor(sessionId)
|
|
4159
|
+
const remote = mirrorForCwd(cwd, MIRRORS.list)
|
|
4160
|
+
if (remote) return remote
|
|
4161
|
+
return localWorkspaceSession(sessionId) ? { local: true, remotePath: cwd, name: workspaceText('workbench.remote', sessionId) } : null
|
|
4162
|
+
}
|
|
4163
|
+
function workspaceMemoryKey(sessionId) {
|
|
4164
|
+
return localWorkspaceSession(sessionId) ? 'local:' + sessionCwdFor(sessionId) + ':' + sessionId : String(sessionId || '')
|
|
4165
|
+
}
|
|
4166
|
+
function fetchWorkspaceContext(sessionId) {
|
|
4167
|
+
return api('GET', '/dsh-remote/workspace-context?sessionId=' + encodeURIComponent(sessionId))
|
|
4168
|
+
}
|
|
4169
|
+
|
|
3753
4170
|
function fetchRemoteStatus(sessionId) {
|
|
4171
|
+
if (localWorkspaceSession(sessionId)) return fetchWorkspaceContext(sessionId).then(value => ({ ...value, local: true, connected: true, workspace: value.root })).catch(() => null)
|
|
3754
4172
|
return api('GET', withSessionQuery('/dsh-remote/status', sessionId)).catch(() => null)
|
|
3755
4173
|
}
|
|
3756
4174
|
|
|
@@ -3800,9 +4218,13 @@ window.__ModuleLoader__.load({
|
|
|
3800
4218
|
// Failure is not fatal and not retried in a loop: no registry means no
|
|
3801
4219
|
// badge, which is exactly what a user with zero mirrors sees.
|
|
3802
4220
|
|
|
3803
|
-
|
|
4221
|
+
// `loaded` is cleared for the duration of a forced refresh; `known` latches
|
|
4222
|
+
// on the first successful read, so "which workspace is this?" does not
|
|
4223
|
+
// depend on a /bindings round-trip being in flight.
|
|
4224
|
+
const MIRRORS = { list: [], loaded: false, known: false, error: '' }
|
|
3804
4225
|
const mirrorWatchers = new Set()
|
|
3805
|
-
let mirrorLoad = null
|
|
4226
|
+
let mirrorLoad = null // { generation, promise } for the current request only
|
|
4227
|
+
let mirrorGeneration = 0
|
|
3806
4228
|
let mirrorTimer = null
|
|
3807
4229
|
|
|
3808
4230
|
const notifyMirrors = () => {
|
|
@@ -3811,26 +4233,52 @@ window.__ModuleLoader__.load({
|
|
|
3811
4233
|
/** Load the mirror registry once (concurrent callers share the request). */
|
|
3812
4234
|
function ensureMirrors() {
|
|
3813
4235
|
if (MIRRORS.loaded) return Promise.resolve(MIRRORS)
|
|
3814
|
-
if (mirrorLoad) return mirrorLoad
|
|
3815
|
-
|
|
4236
|
+
if (mirrorLoad && mirrorLoad.generation === mirrorGeneration) return mirrorLoad.promise
|
|
4237
|
+
const generation = ++mirrorGeneration
|
|
4238
|
+
const promise = api('GET', '/dsh-remote/bindings')
|
|
3816
4239
|
.then((r) => {
|
|
4240
|
+
if (generation !== mirrorGeneration) return MIRRORS
|
|
3817
4241
|
MIRRORS.list = (r && Array.isArray(r.mirrors)) ? r.mirrors : []
|
|
3818
4242
|
MIRRORS.error = ''
|
|
4243
|
+
MIRRORS.known = true
|
|
4244
|
+
})
|
|
4245
|
+
.catch((e) => {
|
|
4246
|
+
if (generation === mirrorGeneration) MIRRORS.error = String((e && e.message) || e)
|
|
3819
4247
|
})
|
|
3820
|
-
.catch((e) => { MIRRORS.error = String((e && e.message) || e) })
|
|
3821
4248
|
.then(() => {
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
4249
|
+
if (generation === mirrorGeneration) {
|
|
4250
|
+
MIRRORS.loaded = true
|
|
4251
|
+
notifyMirrors()
|
|
4252
|
+
}
|
|
4253
|
+
// An old request must not clear the pointer of a newer one.
|
|
4254
|
+
if (mirrorLoad && mirrorLoad.generation === generation) mirrorLoad = null
|
|
3825
4255
|
return MIRRORS
|
|
3826
4256
|
})
|
|
3827
|
-
|
|
4257
|
+
mirrorLoad = { generation, promise }
|
|
4258
|
+
return promise
|
|
3828
4259
|
}
|
|
3829
4260
|
/** Force a refresh (mirrors appear when a workspace is picked). */
|
|
3830
4261
|
function refreshMirrors() {
|
|
3831
4262
|
MIRRORS.loaded = false
|
|
4263
|
+
mirrorGeneration += 1
|
|
3832
4264
|
return ensureMirrors()
|
|
3833
4265
|
}
|
|
4266
|
+
|
|
4267
|
+
/** A client-safe path grammar: Windows drive/UNC paths fold case and
|
|
4268
|
+
* separators; POSIX paths keep case and backslashes. */
|
|
4269
|
+
function mirrorPathKey(value) {
|
|
4270
|
+
const raw = String(value || '')
|
|
4271
|
+
if (!raw) return { windows: false, key: '' }
|
|
4272
|
+
// Detect the grammar BEFORE trimming: C:\ and UNC roots must stay
|
|
4273
|
+
// Windows, while POSIX / remains a real root instead of an empty key.
|
|
4274
|
+
const windows = /^(?:[a-z]:[\\/]|[a-z]:$|[\\/]{2})/i.test(raw)
|
|
4275
|
+
const trimmed = raw.replace(/[\\/]+$/, '')
|
|
4276
|
+
return { windows, key: windows ? trimmed.replace(/\\/g, '/').toLowerCase() : (trimmed || '/') }
|
|
4277
|
+
}
|
|
4278
|
+
function sameMirrorDir(a, b) {
|
|
4279
|
+
const left = mirrorPathKey(a), right = mirrorPathKey(b)
|
|
4280
|
+
return !!(left.key && right.key && left.windows === right.windows && left.key === right.key)
|
|
4281
|
+
}
|
|
3834
4282
|
/**
|
|
3835
4283
|
* The mirror containing a local path, or null.
|
|
3836
4284
|
*
|
|
@@ -3840,20 +4288,20 @@ window.__ModuleLoader__.load({
|
|
|
3840
4288
|
* case-insensitively because the platform does.
|
|
3841
4289
|
*/
|
|
3842
4290
|
function mirrorForCwd(cwd, mirrors) {
|
|
3843
|
-
const
|
|
3844
|
-
if (!
|
|
4291
|
+
const base = mirrorPathKey(cwd)
|
|
4292
|
+
if (!base.key) return null
|
|
3845
4293
|
const list = Array.isArray(mirrors) ? mirrors : []
|
|
3846
|
-
|
|
3847
|
-
const sep = isWin ? '\\' : '/'
|
|
3848
|
-
const fold = (s) => (isWin ? s.toLowerCase() : s)
|
|
3849
|
-
const base = fold(raw.replace(/[\\/]+$/, ''))
|
|
3850
|
-
let best = null
|
|
4294
|
+
let best = null, bestKey = ''
|
|
3851
4295
|
for (const m of list) {
|
|
3852
|
-
const
|
|
3853
|
-
if (!
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
4296
|
+
const dir = mirrorPathKey(m && m.dir)
|
|
4297
|
+
if (!dir.key || dir.windows !== base.windows) continue
|
|
4298
|
+
if (base.key !== dir.key) {
|
|
4299
|
+
// POSIX root contains every absolute child (dir + '/' would be '//').
|
|
4300
|
+
if (dir.key === '/') {
|
|
4301
|
+
if (!base.key.startsWith('/')) continue
|
|
4302
|
+
} else if (!base.key.startsWith(dir.key) || base.key.charAt(dir.key.length) !== '/') continue
|
|
4303
|
+
}
|
|
4304
|
+
if (dir.key.length > bestKey.length) { best = m; bestKey = dir.key }
|
|
3857
4305
|
}
|
|
3858
4306
|
return best
|
|
3859
4307
|
}
|
|
@@ -4033,16 +4481,16 @@ window.__ModuleLoader__.load({
|
|
|
4033
4481
|
}
|
|
4034
4482
|
|
|
4035
4483
|
function readRemoteFile(path, maxBytes, sessionId) {
|
|
4036
|
-
return api('POST', '/dsh-remote/read', withSessionBody({ path, maxBytes }, sessionId)).catch((e) => {
|
|
4037
|
-
const error = new Error(
|
|
4484
|
+
return ensureMirrors().then(() => api('POST', '/dsh-remote/read', withSessionBody({ path, maxBytes }, sessionId))).catch((e) => {
|
|
4485
|
+
const error = new Error(workspaceText('file.readFail', sessionId, { msg: ((e && e.message) || e) }))
|
|
4038
4486
|
error.code = e?.code; error.localCopy = e?.localCopy
|
|
4039
4487
|
throw error
|
|
4040
4488
|
})
|
|
4041
4489
|
}
|
|
4042
4490
|
|
|
4043
4491
|
function listRemoteDir(path, sessionId) {
|
|
4044
|
-
return api('GET', withSessionQuery('/dsh-remote/ls?path=' + encodeURIComponent(path || ''), sessionId)).catch((e) => {
|
|
4045
|
-
throw new Error(
|
|
4492
|
+
return ensureMirrors().then(() => api('GET', withSessionQuery('/dsh-remote/ls?path=' + encodeURIComponent(path || ''), sessionId))).catch((e) => {
|
|
4493
|
+
throw new Error(workspaceText('file.listFail', sessionId, { msg: ((e && e.message) || e) }))
|
|
4046
4494
|
})
|
|
4047
4495
|
}
|
|
4048
4496
|
|
|
@@ -4223,7 +4671,7 @@ window.__ModuleLoader__.load({
|
|
|
4223
4671
|
// tab, which is where the resolved root becomes known.)
|
|
4224
4672
|
const sharedKey = sharedExpanded.join('\u0000')
|
|
4225
4673
|
React.useEffect(() => {
|
|
4226
|
-
if (!evictShared) return
|
|
4674
|
+
if (!evictShared || localWorkspaceSession(props.scope?.sessionId)) return
|
|
4227
4675
|
const stray = strayRemoteSharedPaths('', sharedKey ? sharedKey.split('\u0000') : [])
|
|
4228
4676
|
for (const p of stray) evictShared(p)
|
|
4229
4677
|
}, [sharedKey, evictShared])
|
|
@@ -4234,7 +4682,7 @@ window.__ModuleLoader__.load({
|
|
|
4234
4682
|
return React.createElement(RemoteExplorerTab, {
|
|
4235
4683
|
...owned,
|
|
4236
4684
|
evictStray: (root) => {
|
|
4237
|
-
if (!evictShared || !sharedExpanded.length) return []
|
|
4685
|
+
if (!evictShared || !sharedExpanded.length || localWorkspaceSession(props.scope?.sessionId)) return []
|
|
4238
4686
|
const stray = strayRemoteSharedPaths(root, sharedExpanded)
|
|
4239
4687
|
for (const p of stray) evictShared(p)
|
|
4240
4688
|
return stray
|
|
@@ -4267,12 +4715,17 @@ window.__ModuleLoader__.load({
|
|
|
4267
4715
|
try {
|
|
4268
4716
|
const right = SIDEBAR_RIGHT
|
|
4269
4717
|
const terminals = WEB_TERMINALS
|
|
4270
|
-
if (!right || !terminals || typeof terminals.launchShells !== 'function') throw new Error(
|
|
4718
|
+
if (!right || !terminals || typeof terminals.launchShells !== 'function') throw new Error(workspaceText('workbench.terminalUnavailable', sessionId))
|
|
4271
4719
|
const choices = await terminals.launchShells(sessionId, controller.signal)
|
|
4272
4720
|
if (controller.signal.aborted) return
|
|
4273
4721
|
if (right.mounted && typeof right.mounted.getSnapshot === 'function' && right.mounted.getSnapshot() !== sessionId) return
|
|
4274
|
-
const
|
|
4275
|
-
|
|
4722
|
+
const shells = choices.shells || []
|
|
4723
|
+
const isRemote = s => s.name === 'remote ssh' || /(^|[\\/])remote ssh(?:\.cmd)?$/i.test(s.path || '')
|
|
4724
|
+
const local = localWorkspaceSession(sessionId)
|
|
4725
|
+
const shell = local
|
|
4726
|
+
? shells.find(s => !isRemote(s) && (s.path === choices.selectedShell || s.name === choices.selectedShell)) || shells.find(s => !isRemote(s))
|
|
4727
|
+
: shells.find(isRemote)
|
|
4728
|
+
if (!shell) throw new Error(workspaceText('workbench.terminalUnavailable', sessionId))
|
|
4276
4729
|
right.openTab('terminal', { params: { shellPath: shell.path } })
|
|
4277
4730
|
} catch (e) { if (!controller.signal.aborted) setError(String(e.message || e)) }
|
|
4278
4731
|
finally { if (lifetime.current === controller) { lifetime.current = null; setPending(false) } }
|
|
@@ -4385,8 +4838,9 @@ window.__ModuleLoader__.load({
|
|
|
4385
4838
|
}
|
|
4386
4839
|
|
|
4387
4840
|
function RemoteExplorerTab(props) {
|
|
4841
|
+
const tr = (key, params) => workspaceText(key, props.scope?.sessionId, params)
|
|
4388
4842
|
const [status, setStatus] = React.useState(null)
|
|
4389
|
-
const [root, setRoot] = React.useState('') //
|
|
4843
|
+
const [root, setRoot] = React.useState('') // execution-world project root for this session
|
|
4390
4844
|
const [data, setData] = React.useState({}) // dir -> { entries | error | loading }
|
|
4391
4845
|
const dataRef = React.useRef(data)
|
|
4392
4846
|
const [err, setErr] = React.useState('')
|
|
@@ -4431,7 +4885,7 @@ window.__ModuleLoader__.load({
|
|
|
4431
4885
|
setData(dataRef.current)
|
|
4432
4886
|
}
|
|
4433
4887
|
|
|
4434
|
-
const viewKey =
|
|
4888
|
+
const viewKey = workspaceMemoryKey(sessionId) + '\0' + String(scopeCwd || '')
|
|
4435
4889
|
const viewRef = React.useRef({ key: viewKey, requests: new Map() })
|
|
4436
4890
|
if (viewRef.current.key !== viewKey) {
|
|
4437
4891
|
viewRef.current = { key: viewKey, requests: new Map() }
|
|
@@ -4457,7 +4911,7 @@ window.__ModuleLoader__.load({
|
|
|
4457
4911
|
const request = {}
|
|
4458
4912
|
view.requests.set(dir, request)
|
|
4459
4913
|
const current = () => viewRef.current === view && view.requests.get(dir) === request
|
|
4460
|
-
storeLevel(dir, { ...existing, loading: true })
|
|
4914
|
+
if (!opts?.quiet || !existing?.entries) storeLevel(dir, { ...existing, loading: true })
|
|
4461
4915
|
return listRemoteDir(dir, sessionId)
|
|
4462
4916
|
.then((res) => {
|
|
4463
4917
|
if (!current()) return
|
|
@@ -4520,7 +4974,10 @@ window.__ModuleLoader__.load({
|
|
|
4520
4974
|
|
|
4521
4975
|
}
|
|
4522
4976
|
}
|
|
4523
|
-
const resolveRoot = () => {
|
|
4977
|
+
const resolveRoot = async () => {
|
|
4978
|
+
if (opts?.force) await refreshMirrors()
|
|
4979
|
+
else await ensureMirrors()
|
|
4980
|
+
if (localWorkspaceSession(sessionId)) return fetchWorkspaceContext(sessionId).then(value => value.root || '')
|
|
4524
4981
|
if (scopeCwd) {
|
|
4525
4982
|
return api('GET', '/dsh-remote/resolve-mirror?local=' + encodeURIComponent(scopeCwd))
|
|
4526
4983
|
.then((r) => (r && r.remotePath) || '')
|
|
@@ -4589,7 +5046,7 @@ window.__ModuleLoader__.load({
|
|
|
4589
5046
|
return d
|
|
4590
5047
|
}
|
|
4591
5048
|
box.appendChild(mkItem(menu.isDir ? tr('explorer.menuExpand') : tr('explorer.menuOpen'), false, () => runMenuAction('open', menu)))
|
|
4592
|
-
box.appendChild(mkItem(tr('explorer.menuDownload'), false, () => runMenuAction('download', menu)))
|
|
5049
|
+
if (!localWorkspaceSession(sessionId)) box.appendChild(mkItem(tr('explorer.menuDownload'), false, () => runMenuAction('download', menu)))
|
|
4593
5050
|
box.appendChild(mkItem(tr('explorer.menuCopyRel'), false, () => runMenuAction('copy-rel', menu)))
|
|
4594
5051
|
box.appendChild(mkItem(tr('explorer.menuCopyAbs'), false, () => runMenuAction('copy-abs', menu)))
|
|
4595
5052
|
box.appendChild(mkItem(tr('explorer.menuRename'), false, () => runMenuAction('rename', menu)))
|
|
@@ -4810,6 +5267,10 @@ window.__ModuleLoader__.load({
|
|
|
4810
5267
|
const view = viewRef.current
|
|
4811
5268
|
const timer = setInterval(() => {
|
|
4812
5269
|
fetchRemoteStatus(sessionId).then((next) => { if (next && viewRef.current === view) setStatus(next) })
|
|
5270
|
+
if (localWorkspaceSession(sessionId)) {
|
|
5271
|
+
loadDir(root, { force: true, quiet: true })
|
|
5272
|
+
for (const dir of expandedRef.current) if (dir !== root) loadDir(dir, { force: true, quiet: true })
|
|
5273
|
+
}
|
|
4813
5274
|
}, 5000)
|
|
4814
5275
|
return () => clearInterval(timer)
|
|
4815
5276
|
}, [root, sessionId, props.visible])
|
|
@@ -4881,7 +5342,7 @@ window.__ModuleLoader__.load({
|
|
|
4881
5342
|
getAnchorRect: () => ({ left: menu.x, top: menu.y, right: menu.x, bottom: menu.y, width: 0, height: 0 }),
|
|
4882
5343
|
items: [
|
|
4883
5344
|
{ id: 'open', label: menu.isDir ? tr('explorer.menuExpand') : tr('explorer.menuOpen') },
|
|
4884
|
-
{ id: 'download', label: tr('explorer.menuDownload') },
|
|
5345
|
+
...(!localWorkspaceSession(sessionId) ? [{ id: 'download', label: tr('explorer.menuDownload') }] : []),
|
|
4885
5346
|
{ id: 'copy-rel', label: tr('explorer.menuCopyRel') },
|
|
4886
5347
|
{ id: 'copy-abs', label: tr('explorer.menuCopyAbs') },
|
|
4887
5348
|
{ id: 'rename', label: tr('explorer.menuRename') },
|
|
@@ -5174,10 +5635,11 @@ window.__ModuleLoader__.load({
|
|
|
5174
5635
|
const remoteDrafts = new Map()
|
|
5175
5636
|
const pendingFileSaves = new Map()
|
|
5176
5637
|
function RemoteFileTab(props) {
|
|
5638
|
+
const tr = (key, params) => workspaceText(key, props.scope?.sessionId, params)
|
|
5177
5639
|
const { tab, scope } = props
|
|
5178
5640
|
const path = tab.path || ''
|
|
5179
5641
|
const fileSessionId = scope && scope.sessionId
|
|
5180
|
-
const [data, setData] = React.useState(() => fileViewMemory.get(
|
|
5642
|
+
const [data, setData] = React.useState(() => fileViewMemory.get(workspaceMemoryKey(fileSessionId) + '\0' + path)?.data || null)
|
|
5181
5643
|
const [err, setErr] = React.useState('')
|
|
5182
5644
|
const [loading, setLoading] = React.useState(true)
|
|
5183
5645
|
const [localCopy, setLocalCopy] = React.useState(null)
|
|
@@ -5188,7 +5650,7 @@ window.__ModuleLoader__.load({
|
|
|
5188
5650
|
const [edit, setEdit] = React.useState(false)
|
|
5189
5651
|
const [draft, setDraft] = React.useState('')
|
|
5190
5652
|
const [saving, setSaving] = React.useState(false)
|
|
5191
|
-
const draftKey =
|
|
5653
|
+
const draftKey = workspaceMemoryKey(fileSessionId) + '\0' + path
|
|
5192
5654
|
const draftRecord = remoteDrafts.get(draftKey)
|
|
5193
5655
|
const fileViewRef = React.useRef(draftKey)
|
|
5194
5656
|
fileViewRef.current = draftKey
|
|
@@ -5527,7 +5989,7 @@ window.__ModuleLoader__.load({
|
|
|
5527
5989
|
try {
|
|
5528
5990
|
disposers.push(bs.registerTab({
|
|
5529
5991
|
id: SIDEBAR_EXPLORER_ID,
|
|
5530
|
-
title: () => tr('
|
|
5992
|
+
title: () => tr('workspace.files'),
|
|
5531
5993
|
icon: (size) => React.createElement('span', { style: { fontSize: (size || 14), lineHeight: 1 } }, '🌐'),
|
|
5532
5994
|
order: 55,
|
|
5533
5995
|
single: true,
|
|
@@ -5699,6 +6161,28 @@ window.__ModuleLoader__.load({
|
|
|
5699
6161
|
if (/^[A-Za-z]:/.test(relBody) || /^\//.test(relBody)) return toRemote(relBody)
|
|
5700
6162
|
return remoteRoot + remoteSep + toRemote(relBody)
|
|
5701
6163
|
}
|
|
6164
|
+
function localPathForCoreAddress(parsed, cwd) {
|
|
6165
|
+
if (!localWorkspaceSession(parsed.sessionId)) return null
|
|
6166
|
+
const root = String(cwd || '').replace(/[\\/]+$/, '') || '/'
|
|
6167
|
+
const win = /^(?:[a-z]:|\\\\)/i.test(root)
|
|
6168
|
+
const value = String(parsed.path || '')
|
|
6169
|
+
const absolute = /^(?:[a-z]:[\\/]|[\\/])/i.test(value) ? value : joinRemote(root, value)
|
|
6170
|
+
const canonical = text => {
|
|
6171
|
+
const parts = []
|
|
6172
|
+
for (const part of (win ? text.replace(/\\/g, '/') : text).split('/')) {
|
|
6173
|
+
if (part === '.') continue
|
|
6174
|
+
if (part === '..') { if (parts.length > 1) parts.pop() }
|
|
6175
|
+
else parts.push(part)
|
|
6176
|
+
}
|
|
6177
|
+
const result = parts.join('/').replace(/\/$/, '') || '/'
|
|
6178
|
+
return win ? result.toLowerCase() : result
|
|
6179
|
+
}
|
|
6180
|
+
const base = canonical(root), target = canonical(absolute)
|
|
6181
|
+
return target === base || target.startsWith(base === '/' ? '/' : base + '/') ? absolute : null
|
|
6182
|
+
}
|
|
6183
|
+
function workspacePathForCoreAddress(parsed, cwd) {
|
|
6184
|
+
return remotePathForCoreAddress(parsed, cwd) || (remoteIdeState.enabled ? localPathForCoreAddress(parsed, cwd) : null)
|
|
6185
|
+
}
|
|
5702
6186
|
function NativeExplorer(props) {
|
|
5703
6187
|
const info = props.useTabInfo()
|
|
5704
6188
|
const [expanded, setExpanded] = React.useState(() => explorerMemory.get(props.sessionId)?.expanded || [])
|
|
@@ -5735,7 +6219,7 @@ window.__ModuleLoader__.load({
|
|
|
5735
6219
|
// Resolve from the current navigation on every render. Keeping only an
|
|
5736
6220
|
// initial path in state made same-tab navigation continue reading the old file.
|
|
5737
6221
|
const [, invalidate] = React.useState(0)
|
|
5738
|
-
const remotePath = parsed ?
|
|
6222
|
+
const remotePath = parsed ? workspacePathForCoreAddress(parsed, sessionCwdFor(sessionId)) : null
|
|
5739
6223
|
React.useEffect(() => {
|
|
5740
6224
|
const changed = () => invalidate((version) => version + 1)
|
|
5741
6225
|
mirrorWatchers.add(changed)
|
|
@@ -5784,8 +6268,9 @@ window.__ModuleLoader__.load({
|
|
|
5784
6268
|
} catch { return '' }
|
|
5785
6269
|
}
|
|
5786
6270
|
// The shipped workspace-files command opens kind "files". Route that
|
|
5787
|
-
// intent before navigation, using the captured session's binding
|
|
5788
|
-
//
|
|
6271
|
+
// intent before navigation, using the captured session's binding. Proven
|
|
6272
|
+
// local projects now share this explorer; unknown roots and other kinds
|
|
6273
|
+
// retain the host's original routing.
|
|
5789
6274
|
function routeWorkspaceFiles(sidebar) {
|
|
5790
6275
|
const originals = new Map(), pending = new Map()
|
|
5791
6276
|
let disposed = false
|
|
@@ -5805,7 +6290,7 @@ window.__ModuleLoader__.load({
|
|
|
5805
6290
|
if (sessionIndex == null && sidebar.mounted?.getSnapshot?.() !== sessionId) return
|
|
5806
6291
|
const remote = mirrorForCwd(sessionCwdFor(sessionId), MIRRORS.list)
|
|
5807
6292
|
const next = args.slice()
|
|
5808
|
-
next[kindIndex] = remote ? NATIVE_EXPLORER : kind
|
|
6293
|
+
next[kindIndex] = remote || localWorkspaceSession(sessionId) ? NATIVE_EXPLORER : kind
|
|
5809
6294
|
return Reflect.apply(original, owner, next)
|
|
5810
6295
|
}
|
|
5811
6296
|
if (MIRRORS.loaded) return open()
|
|
@@ -5867,8 +6352,8 @@ window.__ModuleLoader__.load({
|
|
|
5867
6352
|
if (previous) { try { previous() } catch { /* already released */ } }
|
|
5868
6353
|
disposeExplorer = tabs.register({
|
|
5869
6354
|
id: NATIVE_EXPLORER, kind: NATIVE_EXPLORER,
|
|
5870
|
-
title: () => tr('
|
|
5871
|
-
...(withGuide ? { guide: [{ order: 55, title: () => tr('
|
|
6355
|
+
title: () => tr('workspace.files'),
|
|
6356
|
+
...(withGuide ? { guide: [{ order: 55, title: () => tr('workspace.files') }] } : {}),
|
|
5872
6357
|
})
|
|
5873
6358
|
guideListed = withGuide
|
|
5874
6359
|
}
|
|
@@ -5896,7 +6381,7 @@ window.__ModuleLoader__.load({
|
|
|
5896
6381
|
}, 'dsh-remote.start-card-owner')
|
|
5897
6382
|
})
|
|
5898
6383
|
inner.effect(() => tabs.register({ id: NATIVE_WELCOME, kind: NATIVE_WELCOME, title: () => tr('ide.welcome') }), 'dsh-remote.native-welcome-type')
|
|
5899
|
-
inner.effect(() => tabs.register({ id: NATIVE_CHANGES, kind: NATIVE_CHANGES, title: () => tr('
|
|
6384
|
+
inner.effect(() => tabs.register({ id: NATIVE_CHANGES, kind: NATIVE_CHANGES, title: () => tr('workspace.git') }), 'dsh-remote.native-changes-type')
|
|
5900
6385
|
inner.effect(() => tabs.register({
|
|
5901
6386
|
id: NATIVE_FILE, kind: NATIVE_FILE, keepMounted: true,
|
|
5902
6387
|
patterns: ['dsh-resource://dsh-remote/**'],
|
|
@@ -5908,10 +6393,9 @@ window.__ModuleLoader__.load({
|
|
|
5908
6393
|
// `dsh-resource://file/**` in the `fallback` band and reads locally.
|
|
5909
6394
|
// better-sidebar also registers an extension-band editor, so the more
|
|
5910
6395
|
// specific session/** pattern below must win the pattern-length tie-break.
|
|
5911
|
-
// `canOpen`
|
|
5912
|
-
//
|
|
5913
|
-
//
|
|
5914
|
-
// built-in preview and behave exactly as they did before.
|
|
6396
|
+
// `canOpen` guards execution-world selection. Proven remote links use
|
|
6397
|
+
// SFTP; in IDE mode, project-scoped local links share this editor. Other
|
|
6398
|
+
// local links and cold/unknown contexts retain the native host viewer.
|
|
5915
6399
|
//
|
|
5916
6400
|
// Registration is wrapped because the address-claiming half of this
|
|
5917
6401
|
// contract (`patterns` + `canOpen`) is not something every DSH line
|
|
@@ -5938,12 +6422,12 @@ window.__ModuleLoader__.load({
|
|
|
5938
6422
|
// file that was never synced dies with ENOENT and shows nothing at
|
|
5939
6423
|
// all. This editor opens the file over SFTP and RENDERS it via the
|
|
5940
6424
|
// host's MarkdownText (source only when the primitive is missing),
|
|
5941
|
-
// so claiming is no longer a downgrade. Local
|
|
5942
|
-
//
|
|
6425
|
+
// so claiming is no longer a downgrade. Local project links also
|
|
6426
|
+
// share the editor when IDE mode is enabled, proven below.
|
|
5943
6427
|
const cwd = sessionCwdFor(parsed.sessionId)
|
|
5944
6428
|
// `MIRRORS.loaded` is checked so a cold start NEVER steals a local
|
|
5945
|
-
// link:
|
|
5946
|
-
//
|
|
6429
|
+
// link: only a successfully loaded registry can distinguish a
|
|
6430
|
+
// local project from a mirror.
|
|
5947
6431
|
if (!cwd || !MIRRORS.loaded) return false
|
|
5948
6432
|
// Ask the SAME resolver the body uses, not merely whether the cwd
|
|
5949
6433
|
// is a mirror. A remote session can cite a LOCAL absolute path
|
|
@@ -5951,7 +6435,7 @@ window.__ModuleLoader__.load({
|
|
|
5951
6435
|
// the old check claimed it here, then NativeRemoteLink rejected it
|
|
5952
6436
|
// and showed file.linkUnresolved. Refusing it here hands the address
|
|
5953
6437
|
// back to the built-in LOCAL editor, which is the correct owner.
|
|
5954
|
-
return !!
|
|
6438
|
+
return !!workspacePathForCoreAddress(parsed, cwd)
|
|
5955
6439
|
},
|
|
5956
6440
|
title: (address) => {
|
|
5957
6441
|
const parsed = parseCoreFileAddress(address)
|
|
@@ -5999,6 +6483,7 @@ window.__ModuleLoader__.load({
|
|
|
5999
6483
|
}
|
|
6000
6484
|
|
|
6001
6485
|
function RemoteGitTab(props) {
|
|
6486
|
+
const tr = (key, params) => workspaceText(key, props.sessionId, params)
|
|
6002
6487
|
const key = String(props.sessionId || '')
|
|
6003
6488
|
const initial = gitViewMemory.get(key)
|
|
6004
6489
|
const [git, setGit] = React.useState({ key, data: null, error: '', busy: false, revision: 0 })
|
|
@@ -6331,7 +6816,7 @@ window.__ModuleLoader__.load({
|
|
|
6331
6816
|
function RemoteIdeToggle(props) {
|
|
6332
6817
|
const mirror = useSessionMirror(props.sessionId, props.useSessions)
|
|
6333
6818
|
const state = useRemoteIdeState()
|
|
6334
|
-
if (!mirror) return null
|
|
6819
|
+
if (!mirror && !localWorkspaceSession(props.sessionId)) return null
|
|
6335
6820
|
const supported = !!remoteIdeController?.mounted?.getSnapshot && typeof remoteIdeController.openResourceIn === 'function'
|
|
6336
6821
|
return React.createElement('button', {
|
|
6337
6822
|
type: 'button', 'data-rw-ide-toggle': '', 'aria-pressed': state.enabled,
|
|
@@ -6365,6 +6850,17 @@ window.__ModuleLoader__.load({
|
|
|
6365
6850
|
[data-rw-ide-navigation]{display:flex;gap:3px}
|
|
6366
6851
|
[data-rw-ide-navigation] button[aria-pressed=true]{background:var(--dsw-alias-interactive-bg-hover,#eee);font-weight:600}
|
|
6367
6852
|
@media(max-width:600px){[data-rw-ide-header]{gap:5px;padding:0 6px}[data-rw-ide-title]{display:none}[data-rw-ide-header] button{font-size:11px!important;padding:4px 6px!important}}
|
|
6853
|
+
/* macOS desktop (titleBarStyle hiddenInset) floats the native traffic lights at
|
|
6854
|
+
* x 16..68 over the window's top strip, which this shell's header covers. That
|
|
6855
|
+
* strip is 48px tall and its chrome sits on the y=25 centre line (28px controls
|
|
6856
|
+
* at top:11), so the header takes the same height and one pixel of top padding
|
|
6857
|
+
* (at 38px the title sat ~6px above the lights, and plain 48px centring left it
|
|
6858
|
+
* ~1px high). Pad the leading edge by the 88px the host keeps for its fullscreen
|
|
6859
|
+
* panels (lights end at 68, then 20px of air). Fullscreen hides the lights, so
|
|
6860
|
+
* the ordinary 38px header and 12px inset return. The selector out-specifies the
|
|
6861
|
+
* narrow-mode shorthand above, which stays in effect for its right inset. */
|
|
6862
|
+
html[data-platform='darwin'] [data-rw-ide-header]{height:48px;min-height:48px;padding-top:1px;padding-left:88px}
|
|
6863
|
+
html[data-platform='darwin'][data-fullscreen] [data-rw-ide-header]{height:38px;min-height:38px;padding-top:0;padding-left:12px}
|
|
6368
6864
|
/* Reversible IDE-only header adapter for DSH 0.2.1/0.2.2.
|
|
6369
6865
|
* Uses published slot/DOM markers rather than compiled class names.
|
|
6370
6866
|
* Removing data-rw-ide-chat restores all native host styles automatically. */
|
|
@@ -6424,6 +6920,7 @@ window.__ModuleLoader__.load({
|
|
|
6424
6920
|
}
|
|
6425
6921
|
}
|
|
6426
6922
|
function RemoteIdeWelcome() {
|
|
6923
|
+
const tr = (key, params) => workspaceText(key, remoteIdeController?.mounted?.getSnapshot?.(), params)
|
|
6427
6924
|
return React.createElement('article', { 'data-rw-ide-welcome': '', style: { boxSizing: 'border-box', width: '100%', minHeight: '100%', padding: 'clamp(24px,5vw,64px)', color: T.label, overflowWrap: 'anywhere' } },
|
|
6428
6925
|
React.createElement('div', { style: { maxWidth: 560, margin: 'auto' } },
|
|
6429
6926
|
React.createElement('div', { style: { display: 'flex', alignItems: 'center', gap: 10, color: T.muted, fontSize: 12, marginBottom: 14 } }, React.createElement(WorkbenchIcon, { name: 'remote', size: 24 }), 'dsh / remote'),
|
|
@@ -6462,7 +6959,7 @@ window.__ModuleLoader__.load({
|
|
|
6462
6959
|
const dragCleanup = React.useRef(null)
|
|
6463
6960
|
const controller = remoteIdeController
|
|
6464
6961
|
const sizes = remoteIdeWidths(width, state)
|
|
6465
|
-
const mirror = sessionId ?
|
|
6962
|
+
const mirror = sessionId ? workspaceSummary(sessionId) : null
|
|
6466
6963
|
const active = !!(state.enabled && sessionId && mirror && controller)
|
|
6467
6964
|
React.useEffect(() => {
|
|
6468
6965
|
const update = () => {
|