dsh-remote 0.8.81 → 0.8.82
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 +9 -4
- package/README.md +7 -3
- package/lib/client.js +44 -1
- package/lib/errors.js +1 -1
- package/lib/host-api.js +14 -0
- package/lib/index.js +115 -40
- package/lib/open-folder.js +56 -0
- package/lib/paths.js +42 -2
- package/lib/sync.js +100 -25
- package/lib/tui/i18n.js +6 -6
- package/lib/tui/scene.js +10 -20
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -66,7 +66,7 @@ The rest:
|
|
|
66
66
|
- **Async long tasks** — `rw_sync`/`rw_push` with `async: true` return a `taskId` with progress/result/cancel.
|
|
67
67
|
- **Data lives under the harness home** — machines and mirrors follow `$DSH_HOME`; pre-0.6 data migrates automatically on first run.
|
|
68
68
|
- **No `dsh-workspace` core changes** — everything ships as a normal plugin.
|
|
69
|
-
- **Pages in the terminal UI too (dsh-tui)** — `/dsh-remote` opens a server management page (add/edit/delete, connect, browse remote directories
|
|
69
|
+
- **Pages in the terminal UI too (dsh-tui)** — `/dsh-remote` opens a server management page (add/edit/delete, connect, browse remote directories; press `w` there to set the current directory as a workspace), and the new-workspace picker can list remote project directories directly — again without patching dsh-tui. See "Use it from the TUI" below.
|
|
70
70
|
|
|
71
71
|
## Install
|
|
72
72
|
|
|
@@ -180,14 +180,19 @@ Type `/dsh-remote` to open a full-screen settings page (the command also shows u
|
|
|
180
180
|
and `/help`):
|
|
181
181
|
|
|
182
182
|
- `↑/↓` picks a machine, `Enter` opens the action menu; `a` add, `e` edit, `d` delete, `t` test
|
|
183
|
-
connection, `c` connect, `b` browse remote directories, `
|
|
184
|
-
(inside a sub-view they step back to the list first
|
|
183
|
+
connection, `c` connect, `b` browse remote directories, `o` open the local mirror folder,
|
|
184
|
+
`Esc`/`q` close (inside a sub-view they step back to the list first; `m` in the action menu
|
|
185
|
+
manages workspaces).
|
|
185
186
|
- Add/edit: name, host, port, username, auth method (password / private key / SSH agent), password or
|
|
186
187
|
key path, group. Passwords are **write-only** and never echoed; leaving the field empty keeps the
|
|
187
188
|
stored value.
|
|
188
189
|
- `b` browses remote directories; `w` adopts the current one as a **workspace**: it creates the local
|
|
189
190
|
mirror, registers it as a DSH workspace (title `<machine>-<directory>`) and, per configuration,
|
|
190
191
|
switches the session there.
|
|
192
|
+
- `o` opens the local mirror root `$DSH_HOME/remote-workspaces` in the system file manager (each
|
|
193
|
+
machine's mirrors live under a `<host>-<user>-<port>` subdirectory). That directory also holds
|
|
194
|
+
`machines.json` and other plugin data — with `credentialFallback: plain` it can contain plaintext
|
|
195
|
+
passwords; it is only exposed locally.
|
|
191
196
|
|
|
192
197
|
### Pick a remote directory when creating a workspace
|
|
193
198
|
|
|
@@ -338,7 +343,7 @@ Deploying to a product profile is a separate, explicit action (`./sync.sh`) for
|
|
|
338
343
|
| `tui` | bool | `true` | master switch for the TUI (dsh-tui) layer; `false` registers no `/dsh-remote` page, workspace provider or status field |
|
|
339
344
|
| `tuiProviderListRecent` | bool | `true` | list each machine's recent remote projects in the TUI workspace picker |
|
|
340
345
|
| `tuiProviderRecentLimit` | int | `5` | recent remote projects listed per machine (1–20) |
|
|
341
|
-
| `tuiAutoSwitchWorkspace` | bool | `true` | switch the session right after
|
|
346
|
+
| `tuiAutoSwitchWorkspace` | bool | `true` | switch the session right after pressing `w` (set as workspace) in the directory browser |
|
|
342
347
|
| `tuiLang` | string | `''` | language of the TUI layer's own copy: `''` = auto (zh, or en when `DSH_TUI_LANG=en`), `zh` / `en` pins it |
|
|
343
348
|
| `remoteSandbox` | string | `inherit` | which sandbox semantics remote operations follow (0.8.54+): `inherit` reads the mode the local `ctx.sandboxPolicy` resolved (read-only refuses remote writes/commands/forwards, workspace-write fences remote writes to the workspace root, danger-full-access allows everything); `off` disables the fence (legacy behaviour); an explicit mode name is also accepted. **This is containment, not a security boundary** — deploy hard boundaries on the remote side |
|
|
344
349
|
| `credentialFallback` | string | `refuse` | what to do when the OS secure store refuses a password (0.8.54+): `refuse` saves no password (the machine is still saved, the UI reports why, and nothing is written to machines.json in plaintext); `plain` restores the legacy plaintext fallback (with a warning). Turning encryption off explicitly (`backend: plain`) is unaffected |
|
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ DSH 的 Web 界面刻意只监听 `127.0.0.1`(CLI 为安全拒绝 `--host 0.0.
|
|
|
56
56
|
- **数据跟随 Harness 根目录** —— 机器清单与镜像在 `$DSH_HOME/remote-workspaces`;0.6 之前的数据首次启动自动迁移。
|
|
57
57
|
- **`~/.ssh/config` 是连接四字段的唯一来源**(`0.8.50+`,issue #50)—— 保存机器时把 主机/用户/端口/私钥 写入 `~/.ssh/config` 的受管块(`# dsh-remote: managed` 标记,只动自己的块;你手写的同名 Host 块绝不覆盖,会提示冲突)。之后**改这个文件立即生效**:任何 Host 块点名的主机(含字面 IP),连接都按文件解析(裸 `Host *` 是通用默认,不算点名);机器记录里的副本只做兜底,插件自己的状态(最近工作区/延迟等)仍存注册表。
|
|
58
58
|
- **不改动 `dsh-workspace` 官方代码** —— 全部作为普通插件实现。
|
|
59
|
-
- **终端界面(dsh-tui)里也有页面** —— `/dsh-remote`
|
|
59
|
+
- **终端界面(dsh-tui)里也有页面** —— `/dsh-remote` 打开服务器管理页(增删改/连接/浏览远端目录),浏览时按 `w` 把当前目录设为工作区;同样不改 dsh-tui 本体。见下文「在 TUI 里使用」。
|
|
60
60
|
|
|
61
61
|
## 安装
|
|
62
62
|
|
|
@@ -164,11 +164,15 @@ dsh plugin --profile dsh-tui add dsh-remote
|
|
|
164
164
|
输入 `/dsh-remote` 打开全屏设置页(命令同时出现在 `/` 补全与 `/help` 里):
|
|
165
165
|
|
|
166
166
|
- `↑/↓` 选机器,`Enter` 打开动作菜单;`a` 新增、`e` 编辑、`d` 删除、`t` 测试连接、
|
|
167
|
-
`c` 连接、`b` 浏览远端目录、`
|
|
167
|
+
`c` 连接、`b` 浏览远端目录、`o` 打开本机镜像目录、`Esc`/`q` 关闭
|
|
168
|
+
(子视图里先返回列表;动作菜单里按 `m` 管理工作区)。
|
|
168
169
|
- 新增/编辑:名称、主机、端口、用户名、认证方式(密码 / 私钥 / SSH agent)、密码或私钥路径、
|
|
169
170
|
分组。密码**只写不回显**,编辑时留空表示不修改。
|
|
170
171
|
- `b` 浏览远端目录,按 `w` 把当前目录**设为工作区**:自动建本地镜像、注册成 DSH 工作区
|
|
171
172
|
(标题形如 `机器名-目录名`),并按配置切换过去。
|
|
173
|
+
- `o` 用系统默认文件管理器打开本机镜像根目录 `$DSH_HOME/remote-workspaces`
|
|
174
|
+
(每台机器的镜像按 `<host>-<user>-<port>` 分目录存放;该目录也含 `machines.json`
|
|
175
|
+
等插件数据,`credentialFallback: plain` 时可能含明文密码,仅在本机可见)。
|
|
172
176
|
|
|
173
177
|
### 新建工作区时直接选远程目录
|
|
174
178
|
|
|
@@ -313,7 +317,7 @@ scripts/dev-run.sh --status # 是否在运行
|
|
|
313
317
|
| `tui` | bool | `true` | TUI 适配层(dsh-tui)总开关;`false` 时不注册 `/dsh-remote` 页面、工作区 provider 与状态行字段 |
|
|
314
318
|
| `tuiProviderListRecent` | bool | `true` | TUI 工作区选择器里是否列出每台机器最近的远程项目 |
|
|
315
319
|
| `tuiProviderRecentLimit` | int | `5` | 每台机器列出的最近远程项目数(1–20) |
|
|
316
|
-
| `tuiAutoSwitchWorkspace` | bool | `true` |
|
|
320
|
+
| `tuiAutoSwitchWorkspace` | bool | `true` | 在浏览目录里按 `w`「设为工作区」后立即把会话切过去 |
|
|
317
321
|
| `tuiLang` | string | `''` | TUI 层文案语言:`''`=自动(中文;`DSH_TUI_LANG=en` 时英文),`zh` / `en` 固定 |
|
|
318
322
|
| `remoteSandbox` | string | `inherit` | 远程操作套用哪套 sandbox 语义(0.8.54+):`inherit`=读取本机 `ctx.sandboxPolicy` 已解析的模式(read-only 拒远端写入/命令/转发,workspace-write 把远端写入围在 workspace 根内,danger-full-access 全放行);`off`=不设围栏(旧行为);也可显式写某一模式。**这是遏制不是安全边界**,硬边界请在远端一侧做 |
|
|
319
323
|
| `credentialFallback` | string | `refuse` | 系统密钥库写密码失败时怎么办(0.8.54+):`refuse`=不保存该密码(机器照常保存,界面报出失败原因,绝不把明文写进 machines.json);`plain`=旧的明文回退(会警告)。主动关掉加密(`backend: plain`)不受影响 |
|
package/lib/client.js
CHANGED
|
@@ -37,7 +37,15 @@ window.__ModuleLoader__.load({
|
|
|
37
37
|
// one, so there is no downgrade. Older builds / the test harness fall back to
|
|
38
38
|
// plain source.
|
|
39
39
|
const Primitives = (() => { try { return require('@deepseek-ai/dsh-client-ui-primitives') } catch { return null } })()
|
|
40
|
-
|
|
40
|
+
// A host primitive is a component TYPE, and a component type is not always a
|
|
41
|
+
// function: the host ships MarkdownText as a `React.memo` wrapper, i.e.
|
|
42
|
+
// `typeof === 'object'` with `$$typeof === Symbol.for('react.memo')`, which
|
|
43
|
+
// createElement accepts just fine. Testing `typeof === 'function'` therefore
|
|
44
|
+
// threw the renderer away and every remote .md silently degraded to the
|
|
45
|
+
// raw-source wall (issue #101).
|
|
46
|
+
const isComponentType = (value) => typeof value === 'function'
|
|
47
|
+
|| (typeof value === 'object' && value !== null && typeof value.$$typeof === 'symbol')
|
|
48
|
+
const MarkdownText = (Primitives && isComponentType(Primitives.MarkdownText)) ? Primitives.MarkdownText : null
|
|
41
49
|
// Host visual primitives adopted incrementally, always with a graceful
|
|
42
50
|
// fallback (the shared map's contents vary by host version — the bundle
|
|
43
51
|
// ships ~290 exports, older type packages fewer):
|
|
@@ -1089,6 +1097,16 @@ window.__ModuleLoader__.load({
|
|
|
1089
1097
|
}
|
|
1090
1098
|
|
|
1091
1099
|
let SESSIONS = null // optional sessions service, tracked by ctx.inject in apply()
|
|
1100
|
+
let SIDEBAR_RIGHT = null // optional native right-column controller (ctx.sidebarRight)
|
|
1101
|
+
// Which world currently owns the remote-explorer presentation: set by the
|
|
1102
|
+
// guide-card handshake in registerNativeSidebar (better-sidebar arrival
|
|
1103
|
+
// moves the card there; its departure brings it back).
|
|
1104
|
+
let explorerOwnedByBs = false
|
|
1105
|
+
// Sessions whose native explorer tab we already auto-opened. Per-session,
|
|
1106
|
+
// never persisted: a user who closed the tab keeps it closed for the
|
|
1107
|
+
// session, but tomorrow's visit opens it again (same rule as the
|
|
1108
|
+
// better-sidebar world's autoOpenedFor).
|
|
1109
|
+
const autoOpenedNative = new Set()
|
|
1092
1110
|
|
|
1093
1111
|
// ── Settings → 远程工作区 (machine registry + forwards + audit) ──────────
|
|
1094
1112
|
function RemoteWorkspacePage() {
|
|
@@ -3048,6 +3066,25 @@ window.__ModuleLoader__.load({
|
|
|
3048
3066
|
// nothing from the sidebar.
|
|
3049
3067
|
function RemoteSessionChip(props) {
|
|
3050
3068
|
const m = useSessionMirror(props.sessionId, props.useSessions)
|
|
3069
|
+
// Native-right-column counterpart of the better-sidebar auto-open (#78):
|
|
3070
|
+
// this chip mounts exactly when a session is on screen, making it the
|
|
3071
|
+
// trigger for "a remote session on screen surfaces its remote files".
|
|
3072
|
+
// When better-sidebar is installed it owns the presentation (the
|
|
3073
|
+
// guide-card handshake arbitrates that); never open twice.
|
|
3074
|
+
React.useEffect(() => {
|
|
3075
|
+
if (!m || !props.sessionId) return
|
|
3076
|
+
if (!explorerAutoOpenEnabled()) return // the #78 opt-out covers both worlds
|
|
3077
|
+
if (explorerOwnedByBs) return
|
|
3078
|
+
if (autoOpenedNative.has(props.sessionId)) return
|
|
3079
|
+
const right = SIDEBAR_RIGHT
|
|
3080
|
+
if (!right || typeof right.openTab !== 'function') return
|
|
3081
|
+
autoOpenedNative.add(props.sessionId)
|
|
3082
|
+
try {
|
|
3083
|
+
right.openTab(NATIVE_EXPLORER)
|
|
3084
|
+
} catch {
|
|
3085
|
+
autoOpenedNative.delete(props.sessionId) // unregistered kind, etc: retry next time
|
|
3086
|
+
}
|
|
3087
|
+
}, [m, props.sessionId])
|
|
3051
3088
|
if (!m) return null
|
|
3052
3089
|
const target = mirrorTarget(m)
|
|
3053
3090
|
return React.createElement('span', {
|
|
@@ -4072,6 +4109,7 @@ window.__ModuleLoader__.load({
|
|
|
4072
4109
|
let guideListed = null
|
|
4073
4110
|
const syncExplorerType = () => {
|
|
4074
4111
|
const withGuide = !betterSidebar
|
|
4112
|
+
explorerOwnedByBs = betterSidebar
|
|
4075
4113
|
if (guideListed === withGuide && disposeExplorer) return
|
|
4076
4114
|
const previous = disposeExplorer
|
|
4077
4115
|
disposeExplorer = null
|
|
@@ -4200,6 +4238,11 @@ window.__ModuleLoader__.load({
|
|
|
4200
4238
|
inner.effect(() => registerSidebarIntegration(inner), 'dsh-remote.betterSidebar')
|
|
4201
4239
|
})
|
|
4202
4240
|
ctx.inject(['sidebarRightTabs'], registerNativeSidebar)
|
|
4241
|
+
ctx.inject(['sidebarRight'], (inner) => {
|
|
4242
|
+
const svc = inner.get('sidebarRight')
|
|
4243
|
+
SIDEBAR_RIGHT = svc
|
|
4244
|
+
inner.effect(() => () => { if (SIDEBAR_RIGHT === svc) SIDEBAR_RIGHT = null }, 'dsh-remote.sidebarRight')
|
|
4245
|
+
})
|
|
4203
4246
|
// Issue #49: mark the remote Sessions in the sidebar's own Session list.
|
|
4204
4247
|
// These three seats belong to the SHIPPED ui-workspace browser, so they
|
|
4205
4248
|
// are injected (not assumed): a composition with a replacement sidebar
|
package/lib/errors.js
CHANGED
|
@@ -39,7 +39,7 @@ export function classifyError(err, opts = {}) {
|
|
|
39
39
|
if (/no credentials/i.test(msg)) {
|
|
40
40
|
return {
|
|
41
41
|
category: 'credentials',
|
|
42
|
-
hint: `缺少凭据${where}:这台机器没有可用密码、私钥或 agent。请在「远程工作区」设置里填密码(或用私钥路径 / 勾选 agent
|
|
42
|
+
hint: `缺少凭据${where}:这台机器没有可用密码、私钥或 agent。请在「远程工作区」设置里填密码(或用私钥路径 / 勾选 agent)后保存;若这台机器来自 ~/.ssh/config(勾了「Host 名来自 ~/.ssh/config」)且你的 ssh 本来就能连,请把「连接后端」改成 openssh —— 认证完全交给本机 ssh(默认私钥/agent/ProxyJump 全部生效),不需要再填凭据。若你确信已经填过,说明保存时密码没有真正落盘(看保存后是否弹出密钥库失败警告),重新填写并保存即可,可用「测试连接」当场验证。`,
|
|
43
43
|
raw: msg,
|
|
44
44
|
}
|
|
45
45
|
}
|
package/lib/host-api.js
CHANGED
|
@@ -170,6 +170,7 @@ function parentOf(p, platform) {
|
|
|
170
170
|
* · `resolveDirBinding({machineId, sessionId, local})` → `{pool, ws, bound,
|
|
171
171
|
* machine}` (throws MACHINE_NOT_FOUND / NO_ACTIVE_MACHINE);
|
|
172
172
|
* · `listRemoteProjects()` → mirror registry entries (+machineId);
|
|
173
|
+
* · `revealMirrorFolderRecord()` → `{path}` (opens `remote-workspaces` in the file manager);
|
|
173
174
|
* · `resolveMachine(machineId?)` → `{record, machineId, name, host, port,
|
|
174
175
|
* username, alias}` (resolved connect identity);
|
|
175
176
|
* · `ensureMirror(remotePath, host, username, port, extra)` → local dir;
|
|
@@ -773,6 +774,18 @@ export function createHostApi(deps = {}) {
|
|
|
773
774
|
}
|
|
774
775
|
}
|
|
775
776
|
|
|
777
|
+
/** 在系统文件管理器里打开本机 dsh-remote 的镜像根目录(`remote-workspaces`)。 */
|
|
778
|
+
const revealMirrorFolder = async () => {
|
|
779
|
+
try {
|
|
780
|
+
const result = await need('revealMirrorFolderRecord')()
|
|
781
|
+
const dir = String((result && result.path) || '')
|
|
782
|
+
if (!dir) throw apiError('INTERNAL', 'dshRemote.revealMirrorFolder: host returned no path')
|
|
783
|
+
return { path: dir }
|
|
784
|
+
} catch (err) {
|
|
785
|
+
throw asApiError(err)
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
|
|
776
789
|
const subscribe = (listener) => {
|
|
777
790
|
if (typeof listener !== 'function') {
|
|
778
791
|
throw apiError('INTERNAL', 'dshRemote.subscribe: listener must be a function')
|
|
@@ -803,6 +816,7 @@ export function createHostApi(deps = {}) {
|
|
|
803
816
|
deleteWorkspaceSessions,
|
|
804
817
|
deleteRemoteWorkspace,
|
|
805
818
|
forgetWorkspaceRecent,
|
|
819
|
+
revealMirrorFolder,
|
|
806
820
|
subscribe,
|
|
807
821
|
}
|
|
808
822
|
}
|
package/lib/index.js
CHANGED
|
@@ -29,7 +29,7 @@ import { fileURLToPath } from 'node:url'
|
|
|
29
29
|
import iconv from 'iconv-lite'
|
|
30
30
|
|
|
31
31
|
import {
|
|
32
|
-
shq, normalizeRemotePath, joinRemotePath, remoteDirname, mkdirRemoteDirs,
|
|
32
|
+
shq, normalizeRemotePath, joinRemotePath, joinRemoteRel, resolveRemoteWorkspacePath, remoteDirname, mkdirRemoteDirs,
|
|
33
33
|
toShellPath, toDisplayPath, remotePathBase, remoteWorkspaceTitle, truncate, shortHash,
|
|
34
34
|
} from './paths.js'
|
|
35
35
|
import { createHostKeyGuard, isHostKeyKnown as _isHostKeyKnown } from './hostkey.js'
|
|
@@ -52,6 +52,7 @@ import { TaskManager } from './tasks.js'
|
|
|
52
52
|
import { ForwardManager } from './forwards.js'
|
|
53
53
|
import { WebAttach } from './web-attach.js'
|
|
54
54
|
import { formatAuditLine, readAuditLines } from './audit.js'
|
|
55
|
+
import { openLocalFolder } from './open-folder.js'
|
|
55
56
|
|
|
56
57
|
import { selfDir, diskVersion, LOADED_VERSION, gtVersion, fetchLatestVersion, applyUpdate, persistUpdateMode, readUpdateMode, reloadSelf, scheduleSelfReload, lastSelfReload, isInstalledCopy, writeFileAtomic } from './update.js'
|
|
57
58
|
import { sendHeartbeat, pseudonym, heartbeatUrl, hasPersistedId, installIdPath, telemetryAllowed, persistTelemetryOpt } from './telemetry.js'
|
|
@@ -646,6 +647,46 @@ export async function apply(ctx, config) {
|
|
|
646
647
|
}
|
|
647
648
|
}
|
|
648
649
|
|
|
650
|
+
/**
|
|
651
|
+
* Does this machine carry a credential the NATIVE (ssh2) backend can use?
|
|
652
|
+
*
|
|
653
|
+
* The native backend authenticates only through a password, a private key, an
|
|
654
|
+
* agent or keyboard-interactive. A `~/.ssh/config` machine whose Host block
|
|
655
|
+
* carries just HostName/User relies on OpenSSH's own default-identity
|
|
656
|
+
* discovery (id_rsa/id_ed25519, the agent, AddKeysToAgent/UseKeychain), which
|
|
657
|
+
* ssh2 does not implement — so dialing it with native reports "no credentials"
|
|
658
|
+
* for a host that `ssh <alias>` reaches fine. The system-OpenSSH backend hands
|
|
659
|
+
* the name to the user's own `ssh`, which authenticates exactly like that
|
|
660
|
+
* command.
|
|
661
|
+
*
|
|
662
|
+
* @param {object} m - a machine record or request body carrying the fields.
|
|
663
|
+
* @returns {boolean} true when native has something to authenticate with.
|
|
664
|
+
*/
|
|
665
|
+
const nativeUsableCredential = (m) => !!(
|
|
666
|
+
(m && String(m.password || '').trim())
|
|
667
|
+
|| (m && String(m.privateKeyPath || '').trim())
|
|
668
|
+
|| (m && m.useAgent)
|
|
669
|
+
|| (m && m.keyboardInteractive)
|
|
670
|
+
// A keychain-backed machine stores an empty `password` by design.
|
|
671
|
+
|| (m && (m.secretStored || (m.credentialBackend && m.credentialBackend !== 'plain')))
|
|
672
|
+
)
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* The backend a machine must dial with. Native stays whenever it has a usable
|
|
676
|
+
* credential (or the machine explicitly asks for openssh); otherwise openssh,
|
|
677
|
+
* because native provably cannot connect and would only report a missing
|
|
678
|
+
* credential the user never needed.
|
|
679
|
+
*
|
|
680
|
+
* @param {object} m - machine record or request body.
|
|
681
|
+
* @param {object} cfg - the plugin Config (its `backend` is the fallback).
|
|
682
|
+
* @returns {string} 'openssh' | 'native'.
|
|
683
|
+
*/
|
|
684
|
+
const backendFor = (m, cfg) => {
|
|
685
|
+
const chosen = String((m && m.backend) || (cfg && cfg.backend) || 'native')
|
|
686
|
+
if (chosen === 'openssh') return 'openssh'
|
|
687
|
+
return nativeUsableCredential(m) ? 'native' : 'openssh'
|
|
688
|
+
}
|
|
689
|
+
|
|
649
690
|
/** The alias a machine was saved as ('' for a machine with literal values). */
|
|
650
691
|
const aliasOf = (m) => (m && m.sshAlias) || (m && m.useSshConfig ? String(m.host || '') : '')
|
|
651
692
|
|
|
@@ -934,7 +975,7 @@ export async function apply(ctx, config) {
|
|
|
934
975
|
// Issue #51: the transport backend is a per-machine choice — an
|
|
935
976
|
// enterprise Kerberos host needs `openssh` while its neighbours stay on
|
|
936
977
|
// the native backend.
|
|
937
|
-
backend: (eff
|
|
978
|
+
backend: backendFor(eff, config),
|
|
938
979
|
sshBinary: (eff && typeof eff.sshBinary === 'string') ? eff.sshBinary : config.sshBinary,
|
|
939
980
|
// Identity-pinned pools never carry the shared active workspace: a
|
|
940
981
|
// session passes its own mirror-resolved remote path explicitly.
|
|
@@ -1851,17 +1892,6 @@ export async function apply(ctx, config) {
|
|
|
1851
1892
|
// Everything below is glue: which remote root an agent is bound to, and how a
|
|
1852
1893
|
// workspace-relative directory is listed over the machine's own pool.
|
|
1853
1894
|
|
|
1854
|
-
/** Join a workspace-relative directory onto a remote root, segment by
|
|
1855
|
-
* segment, so the root's separator style is preserved on Windows hosts. */
|
|
1856
|
-
const joinRemoteRel = (base, rel) => {
|
|
1857
|
-
let out = base
|
|
1858
|
-
for (const segment of String(rel || '').split('/')) {
|
|
1859
|
-
if (!segment || segment === '.') continue
|
|
1860
|
-
out = joinRemotePath(out, segment)
|
|
1861
|
-
}
|
|
1862
|
-
return out
|
|
1863
|
-
}
|
|
1864
|
-
|
|
1865
1895
|
const fileReferenceLog = (msg) => {
|
|
1866
1896
|
try {
|
|
1867
1897
|
const logger = typeof ctx.get === 'function' ? ctx.get('logger') : undefined
|
|
@@ -1936,28 +1966,17 @@ export async function apply(ctx, config) {
|
|
|
1936
1966
|
|
|
1937
1967
|
/**
|
|
1938
1968
|
* Resolve a PATH ARGUMENT a tool received against the session's remote
|
|
1939
|
-
* workspace root when it is not already absolute (issue #39).
|
|
1969
|
+
* workspace root when it is not already a remote absolute path (issue #39).
|
|
1940
1970
|
*
|
|
1941
|
-
*
|
|
1942
|
-
*
|
|
1943
|
-
* mean `<remote workspace>/src/main.c`, not the filesystem root's `/src`.
|
|
1944
|
-
* Absolute POSIX (`/a/b`), Windows (`D:\a`, `/D:/a`) and UNC (`\\host\share`)
|
|
1945
|
-
* forms pass through normalizeRemotePath() unchanged, so behaviour for every
|
|
1946
|
-
* existing caller is preserved. `..` segments collapse inside the joined path
|
|
1947
|
-
* exactly as normalizeRemotePath() already did.
|
|
1971
|
+
* Also maps paths inside `b.mirrorDir` onto `b.ws` when the model passes the
|
|
1972
|
+
* local mirror cwd reported by the harness's runtime context to an `rw_*` tool.
|
|
1948
1973
|
*
|
|
1949
|
-
* @param {{ws: string}} b - the binding resolved for this call.
|
|
1974
|
+
* @param {{ws: string, mirrorDir?: string|null}} b - the binding resolved for this call.
|
|
1950
1975
|
* @param {unknown} raw - the raw argument value.
|
|
1951
1976
|
* @returns {string} a normalized remote path.
|
|
1952
1977
|
*/
|
|
1953
|
-
const resolveRemoteArg = (b, raw) =>
|
|
1954
|
-
|
|
1955
|
-
const absolute = s.startsWith('/') || s.startsWith('\\\\') || /^[a-zA-Z]:[\\/]/.test(s)
|
|
1956
|
-
if (absolute) return normalizeRemotePath(s)
|
|
1957
|
-
const rel = s.replace(/^\.\//, '').replace(/^[\\/]+/, '')
|
|
1958
|
-
if (!rel) return normalizeRemotePath(b.ws || '')
|
|
1959
|
-
return normalizeRemotePath(b.ws ? joinRemoteRel(b.ws, rel.replace(/\\/g, '/')) : rel)
|
|
1960
|
-
}
|
|
1978
|
+
const resolveRemoteArg = (b, raw) =>
|
|
1979
|
+
resolveRemoteWorkspacePath((b && b.ws) || '', raw, (b && b.mirrorDir) || '')
|
|
1961
1980
|
|
|
1962
1981
|
// ── tools ─────────────────────────────────────────────────────────────────
|
|
1963
1982
|
|
|
@@ -2164,7 +2183,7 @@ export async function apply(ctx, config) {
|
|
|
2164
2183
|
keyboardInteractive: !!rec.keyboardInteractive,
|
|
2165
2184
|
hostKeyMode: rec.hostKeyMode || config.hostKeyMode,
|
|
2166
2185
|
proxy: ct.proxy,
|
|
2167
|
-
backend: rec
|
|
2186
|
+
backend: backendFor(rec, config),
|
|
2168
2187
|
sshBinary: rec.sshBinary !== undefined ? rec.sshBinary : config.sshBinary,
|
|
2169
2188
|
workspace: config.workspace,
|
|
2170
2189
|
})
|
|
@@ -2323,7 +2342,7 @@ export async function apply(ctx, config) {
|
|
|
2323
2342
|
const depth = Math.min(Math.max(Number(args.depth) || 8, 1), 16)
|
|
2324
2343
|
const maxFiles = Math.min(Math.max(Number(args.maxFiles) || 2000, 1), 20000)
|
|
2325
2344
|
const isIgnored = ignoreMatcher(p)
|
|
2326
|
-
const body = { depth, maxFiles, dryRun: !!args.dryRun, force: !!args.force, isIgnored }
|
|
2345
|
+
const body = { depth, maxDepth: depth, maxFiles, dryRun: !!args.dryRun, force: !!args.force, isIgnored }
|
|
2327
2346
|
const runSync = async () => {
|
|
2328
2347
|
let sftp
|
|
2329
2348
|
try {
|
|
@@ -2332,9 +2351,16 @@ export async function apply(ctx, config) {
|
|
|
2332
2351
|
throw new Error('sftp unavailable: ' + ((err && err.message) || err))
|
|
2333
2352
|
}
|
|
2334
2353
|
const state = loadSyncState(local)
|
|
2335
|
-
const { stats, nextState } = await syncTree(sftp, p, local, {
|
|
2354
|
+
const { stats, nextState } = await syncTree(sftp, p, local, {
|
|
2355
|
+
...body,
|
|
2356
|
+
state,
|
|
2357
|
+
maxFileBytes: config.maxFileBytes,
|
|
2358
|
+
getSftp: () => b.pool.sftp(),
|
|
2359
|
+
})
|
|
2336
2360
|
if (!args.dryRun) saveSyncState(local, nextState)
|
|
2337
2361
|
let text = `${args.dryRun ? 'WOULD download' : 'Downloaded'} ${stats.files} file(s) from ${p} → ${local}.`
|
|
2362
|
+
if (stats.abortedError) text += ` ABORTED early (${stats.abortedError}; re-run rw_sync to resume incremental sync, or use rw_download for a specific file).`
|
|
2363
|
+
else if (stats.failed) text += ` ${stats.failed} failed.`
|
|
2338
2364
|
if (stats.truncated || stats.files >= maxFiles) text += ` TRUNCATED (hit depth=${depth} or maxFiles=${maxFiles} cap; raise maxFiles/depth and re-run).`
|
|
2339
2365
|
if (stats.skippedUnchanged) text += ` ${stats.skippedUnchanged} unchanged.`
|
|
2340
2366
|
if (stats.skippedLarge) text += ` ${stats.skippedLarge} too large (over ${config.maxFileBytes} bytes).`
|
|
@@ -3060,13 +3086,14 @@ export async function apply(ctx, config) {
|
|
|
3060
3086
|
// Issue #39: `@` mentions are resolved from the REMOTE tree by
|
|
3061
3087
|
// lib/file-reference.js, so the model must know they are remote-relative
|
|
3062
3088
|
// and that the built-in read tool sees only the local mirror.
|
|
3089
|
+
const mirrorNote = mirrorDir ? ` (${mirrorDir})` : ''
|
|
3063
3090
|
return (
|
|
3064
3091
|
'## Remote workspace\n' +
|
|
3065
3092
|
`Current remote workspace: ${who}:${shown}\n` +
|
|
3066
|
-
'Use the rw_* tools (rw_list_dir / rw_read_file / rw_write_file / rw_edit / rw_exec / rw_search / rw_sync / rw_push) to inspect and act on files on the remote host. Treat this directory as the working root for this task.\n' +
|
|
3093
|
+
'Use the rw_* tools (rw_list_dir / rw_read_file / rw_write_file / rw_edit / rw_exec / rw_search / rw_sync / rw_push / rw_download / rw_upload) to inspect and act on files on the remote host. Treat this directory as the working root for this task.\n' +
|
|
3067
3094
|
`\`@path\` mentions in this conversation name files under THAT remote root (\`@src/main.c\` = ${shown}/src/main.c). ` +
|
|
3068
3095
|
'The rw_* tools take such paths as workspace-relative and resolve them against this root. ' +
|
|
3069
|
-
|
|
3096
|
+
`The harness's built-in local tools (read / write / edit / grep / glob / working_directory / local shell) only see the LOCAL mirror of this directory${mirrorNote}, which stays empty until rw_sync — use rw_read_file / rw_list_dir / rw_search / rw_exec for remote files, or rw_download to fetch a specific remote file locally.` +
|
|
3070
3097
|
extra
|
|
3071
3098
|
)
|
|
3072
3099
|
},
|
|
@@ -3465,9 +3492,20 @@ export async function apply(ctx, config) {
|
|
|
3465
3492
|
hostKeyMode: body.hostKeyMode || '',
|
|
3466
3493
|
useAgent: !!body.useAgent,
|
|
3467
3494
|
keyboardInteractive: !!body.keyboardInteractive,
|
|
3468
|
-
// Issue #51: the transport backend is per machine.
|
|
3469
|
-
//
|
|
3470
|
-
|
|
3495
|
+
// Issue #51: the transport backend is per machine. Native stays when it
|
|
3496
|
+
// has a credential to authenticate with; otherwise openssh, so saving a
|
|
3497
|
+
// credential-less machine (the normal shape of a ~/.ssh/config alias) can
|
|
3498
|
+
// actually connect instead of reporting a missing credential the user
|
|
3499
|
+
// never needed. An unknown value is not persisted as-is.
|
|
3500
|
+
backend: backendFor({
|
|
3501
|
+
backend: body.backend,
|
|
3502
|
+
password: body.password || (prev && prev.password),
|
|
3503
|
+
privateKeyPath: body.privateKeyPath === undefined ? (prev && prev.privateKeyPath) : body.privateKeyPath,
|
|
3504
|
+
useAgent: !!body.useAgent,
|
|
3505
|
+
keyboardInteractive: !!body.keyboardInteractive,
|
|
3506
|
+
secretStored: prev && prev.secretStored,
|
|
3507
|
+
credentialBackend: prev && prev.credentialBackend,
|
|
3508
|
+
}, config),
|
|
3471
3509
|
sshBinary: String(body.sshBinary || '').trim(),
|
|
3472
3510
|
// Issue #54: the per-machine `dsh web` launch command was only
|
|
3473
3511
|
// ever writable by the deploy flow or by hand-editing
|
|
@@ -3672,7 +3710,15 @@ export async function apply(ctx, config) {
|
|
|
3672
3710
|
const cred = resolveProbeCredentials(body, savedRec, savedPassword)
|
|
3673
3711
|
// Issue #38: "test" on an ssh-config ALIAS resolves the alias first —
|
|
3674
3712
|
// the form holds the alias name, not the host it points at.
|
|
3675
|
-
const probeBackend =
|
|
3713
|
+
const probeBackend = backendFor({
|
|
3714
|
+
backend: cred.backend,
|
|
3715
|
+
password: cred.password,
|
|
3716
|
+
privateKeyPath: cred.privateKeyPath,
|
|
3717
|
+
useAgent: cred.useAgent,
|
|
3718
|
+
keyboardInteractive: cred.keyboardInteractive,
|
|
3719
|
+
secretStored: savedRec && savedRec.secretStored,
|
|
3720
|
+
credentialBackend: savedRec && savedRec.credentialBackend,
|
|
3721
|
+
}, config)
|
|
3676
3722
|
const probeIsOpenssh = isSystemOpenSshBackend({ backend: probeBackend })
|
|
3677
3723
|
const aliasTarget = body.useSshConfig
|
|
3678
3724
|
? resolveMachineSshConfig({
|
|
@@ -3869,6 +3915,19 @@ export async function apply(ctx, config) {
|
|
|
3869
3915
|
return { ...p, machineId: rec && rec.id ? String(rec.id) : null }
|
|
3870
3916
|
})
|
|
3871
3917
|
|
|
3918
|
+
/** 在系统文件管理器里打开本机 dsh-remote 的镜像根目录
|
|
3919
|
+
* (`$DSH_HOME/remote-workspaces`,里面按机器分目录存放所有工作区镜像)。
|
|
3920
|
+
* 只打开已存在的目录,不创建任何东西。 */
|
|
3921
|
+
const revealMirrorFolderForApi = async () => {
|
|
3922
|
+
const dir = remoteWorkspacesRoot()
|
|
3923
|
+
if (!existsSync(dir)) {
|
|
3924
|
+
throw codedError('VALIDATION', '还没有任何远程工作区镜像目录:先浏览远程目录并按 w 建一个工作区')
|
|
3925
|
+
}
|
|
3926
|
+
// spawn 失败(例如 Linux 没有 xdg-open)必须让调用方看到错误,不能先报成功。
|
|
3927
|
+
await openLocalFolder(dir)
|
|
3928
|
+
return { path: dir }
|
|
3929
|
+
}
|
|
3930
|
+
|
|
3872
3931
|
/** SSH `stat` validation used by pickRemoteWorkspace. With a machineId it
|
|
3873
3932
|
* runs on that machine's OWN pool (validation must not switch the active
|
|
3874
3933
|
* machine); without one it behaves like the /mirror route (active pool). */
|
|
@@ -4128,6 +4187,10 @@ export async function apply(ctx, config) {
|
|
|
4128
4187
|
password: payload.password !== undefined && payload.password !== '' ? payload.password : undefined,
|
|
4129
4188
|
privateKeyPath: payload.privateKeyPath,
|
|
4130
4189
|
workspace: payload.workspace,
|
|
4190
|
+
// A credential-less target — including an alias from ~/.ssh/config
|
|
4191
|
+
// whose Host block relies on OpenSSH's default keys — cannot connect
|
|
4192
|
+
// on native; dial it through the user's own ssh instead.
|
|
4193
|
+
backend: backendFor(payload, config),
|
|
4131
4194
|
})
|
|
4132
4195
|
await pool.exec('echo ok', { timeoutMs: Math.min(config.commandTimeoutMs, 8000) })
|
|
4133
4196
|
return sendJson(res, 200, { ok: true, ...status() })
|
|
@@ -4352,7 +4415,12 @@ export async function apply(ctx, config) {
|
|
|
4352
4415
|
hostKeyMode: '',
|
|
4353
4416
|
useAgent: false,
|
|
4354
4417
|
keyboardInteractive: false,
|
|
4355
|
-
|
|
4418
|
+
// ~/.ssh/config defines this machine, and the user's own `ssh`
|
|
4419
|
+
// is what interprets that file (default identity discovery,
|
|
4420
|
+
// agent/keychain, ProxyJump, GSSAPI). Native cannot see any of
|
|
4421
|
+
// it, so a Host block with no IdentityFile would be reported as
|
|
4422
|
+
// "no credentials".
|
|
4423
|
+
backend: 'openssh',
|
|
4356
4424
|
sshBinary: '',
|
|
4357
4425
|
credentialBackend: 'plain',
|
|
4358
4426
|
recentWorkspaces: [],
|
|
@@ -4361,6 +4429,12 @@ export async function apply(ctx, config) {
|
|
|
4361
4429
|
}
|
|
4362
4430
|
machines.push(rec)
|
|
4363
4431
|
saveMachines(machines, store.currentId, false)
|
|
4432
|
+
} else if (String(rec.backend || 'native') !== 'openssh' && !nativeUsableCredential(rec)) {
|
|
4433
|
+
// A record adopted before this fix carries `native` with no
|
|
4434
|
+
// credential: upgrade it in place, so clicking Connect dials what
|
|
4435
|
+
// `ssh <alias>` already does.
|
|
4436
|
+
rec.backend = 'openssh'
|
|
4437
|
+
saveMachines(machines, store.currentId, false)
|
|
4364
4438
|
}
|
|
4365
4439
|
// Making it current is the whole point of the click: the picker and
|
|
4366
4440
|
// every session route then act on this machine.
|
|
@@ -4886,6 +4960,7 @@ export async function apply(ctx, config) {
|
|
|
4886
4960
|
statusSnapshot: () => status(),
|
|
4887
4961
|
resolveDirBinding: listDirBindingForApi,
|
|
4888
4962
|
listRemoteProjects: listRemoteProjectsForApi,
|
|
4963
|
+
revealMirrorFolderRecord: revealMirrorFolderForApi,
|
|
4889
4964
|
resolveMachine: resolveMachineForApi,
|
|
4890
4965
|
ensureMirror,
|
|
4891
4966
|
registerMirroredWorkspace,
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// 在系统默认文件管理器里打开一个本地目录。
|
|
2
|
+
//
|
|
3
|
+
// 插件跑在 dsh-tui 进程里,所以“打开本机文件夹”就是一个本地动作:
|
|
4
|
+
// · macOS → `open <dir>`
|
|
5
|
+
// · Windows → `explorer <dir>`
|
|
6
|
+
// · 其它 → `xdg-open <dir>`
|
|
7
|
+
// 只做一次 spawn,不读输出、不等待、不阻塞;spawn 的异步 `error` 必须被吃掉,
|
|
8
|
+
// 否则一个不存在的 `xdg-open` 会以未处理事件把宿主进程带崩。
|
|
9
|
+
|
|
10
|
+
import { spawn } from 'node:child_process'
|
|
11
|
+
|
|
12
|
+
/** 当前平台对应的“打开文件夹”命令。 */
|
|
13
|
+
export function folderOpenCommand(platform = process.platform) {
|
|
14
|
+
if (platform === 'darwin') return 'open'
|
|
15
|
+
if (platform === 'win32') return 'explorer'
|
|
16
|
+
return 'xdg-open'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 用系统默认文件管理器打开 `target`。
|
|
21
|
+
*
|
|
22
|
+
* 返回的 Promise 在子进程真的 spawn 成功时 resolve、spawn 失败(如 Linux 没有
|
|
23
|
+
* `xdg-open`、权限不足)时 reject —— 调用方不能先报“已打开”再吞掉失败。
|
|
24
|
+
* 子进程本身仍然 detached + ignore,且从不 await 退出码:`explorer` 对目录参数
|
|
25
|
+
* 返回非零退出码是常态。
|
|
26
|
+
*
|
|
27
|
+
* @param {string} target - 本地绝对路径。
|
|
28
|
+
* @param {object} [options]
|
|
29
|
+
* @param {string} [options.platform] - 覆盖平台(测试用)。
|
|
30
|
+
* @param {Function} [options.spawnImpl] - 覆盖 spawn(测试用)。
|
|
31
|
+
* @returns {Promise<string>} resolve 实际使用的命令名。
|
|
32
|
+
*/
|
|
33
|
+
export function openLocalFolder(target, options = {}) {
|
|
34
|
+
const platform = options.platform || process.platform
|
|
35
|
+
const spawnImpl = typeof options.spawnImpl === 'function' ? options.spawnImpl : spawn
|
|
36
|
+
const directory = String(target == null ? '' : target)
|
|
37
|
+
if (!directory) return Promise.reject(new Error('openLocalFolder: target is required'))
|
|
38
|
+
const command = folderOpenCommand(platform)
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
let child
|
|
41
|
+
try {
|
|
42
|
+
child = spawnImpl(command, [directory], { detached: true, stdio: 'ignore' })
|
|
43
|
+
} catch (error) {
|
|
44
|
+
reject(error)
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
if (!child || typeof child.on !== 'function') {
|
|
48
|
+
// 极小化的 spawn 替身:没有事件可等,按成功处理。
|
|
49
|
+
resolve(command)
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
child.on('spawn', () => resolve(command))
|
|
53
|
+
child.on('error', reject)
|
|
54
|
+
if (typeof child.unref === 'function') child.unref()
|
|
55
|
+
})
|
|
56
|
+
}
|
package/lib/paths.js
CHANGED
|
@@ -213,11 +213,12 @@ export function remoteWorkspaceTitle(remotePath, machine) {
|
|
|
213
213
|
|
|
214
214
|
/** Relative path of `p` under `root` (POSIX form, no leading slash), or null
|
|
215
215
|
* when `p` is not inside `root`. Both POSIX and Windows drive paths work
|
|
216
|
-
* (Windows is compared in its `/
|
|
216
|
+
* (Windows is compared in its `/d:/…` POSIX-equivalent form, including `/D:/…`
|
|
217
|
+
* SFTP paths). */
|
|
217
218
|
export function relPathUnder(root, p) {
|
|
218
219
|
const posix = (x) => {
|
|
219
220
|
let n = normalizeRemotePath(x).replace(/[\\/]+$/, '')
|
|
220
|
-
const m = n.match(
|
|
221
|
+
const m = n.match(/^\/?([a-zA-Z]):(.*)$/s)
|
|
221
222
|
if (m) return '/' + m[1].toLowerCase() + ':/' + (m[2] ? m[2].replace(/\\/g, '/').replace(/^\/+/, '') : '')
|
|
222
223
|
return n.replace(/\\/g, '/')
|
|
223
224
|
}
|
|
@@ -229,6 +230,45 @@ export function relPathUnder(root, p) {
|
|
|
229
230
|
return null
|
|
230
231
|
}
|
|
231
232
|
|
|
233
|
+
/**
|
|
234
|
+
* Join a workspace-relative path onto a remote root, segment by segment, so the
|
|
235
|
+
* root's separator style (`/` on POSIX, `\` on Windows) is preserved.
|
|
236
|
+
*/
|
|
237
|
+
export function joinRemoteRel(base, rel) {
|
|
238
|
+
let out = base
|
|
239
|
+
for (const segment of String(rel || '').split(/[\\/]+/)) {
|
|
240
|
+
if (!segment || segment === '.') continue
|
|
241
|
+
out = joinRemotePath(out, segment)
|
|
242
|
+
}
|
|
243
|
+
return out
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Resolve a tool's `path` argument against a session's remote workspace root `ws`.
|
|
248
|
+
*
|
|
249
|
+
* - Relative paths (`src/main.c`, `./a`, empty) resolve under `ws` (issue #39).
|
|
250
|
+
* - If `mirrorDir` is given and `raw` points at `mirrorDir` itself or a child
|
|
251
|
+
* under `mirrorDir` (because the harness reports the local mirror as the
|
|
252
|
+
* session's working directory), the mirror prefix is stripped and mapped
|
|
253
|
+
* onto `ws` instead of being sent to SFTP as a literal local path.
|
|
254
|
+
* - Any other absolute POSIX (`/a/b`), Windows (`D:\a`, `/D:/a`) or UNC
|
|
255
|
+
* (`\\host\share`) path passes through `normalizeRemotePath()` unchanged.
|
|
256
|
+
*/
|
|
257
|
+
export function resolveRemoteWorkspacePath(ws, raw, mirrorDir = '') {
|
|
258
|
+
const s = String(raw ?? '').trim()
|
|
259
|
+
if (mirrorDir && ws && s) {
|
|
260
|
+
const mirrorRel = relPathUnder(mirrorDir, s)
|
|
261
|
+
if (mirrorRel !== null) {
|
|
262
|
+
return normalizeRemotePath(mirrorRel ? joinRemoteRel(ws, mirrorRel) : ws)
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
const absolute = s.startsWith('/') || s.startsWith('\\\\') || /^[a-zA-Z]:[\\/]/.test(s)
|
|
266
|
+
if (absolute) return normalizeRemotePath(s)
|
|
267
|
+
const rel = s.replace(/^\.\//, '').replace(/^[\\/]+/, '')
|
|
268
|
+
if (!rel) return normalizeRemotePath(ws || '')
|
|
269
|
+
return normalizeRemotePath(ws ? joinRemoteRel(ws, rel.replace(/\\/g, '/')) : rel)
|
|
270
|
+
}
|
|
271
|
+
|
|
232
272
|
export function truncate(s, max) {
|
|
233
273
|
// A missing/NaN cap is a CONFIG BUG (measured: a bare `new SshPool({...})`
|
|
234
274
|
// with no maxOutputChars turned EVERY exec result into a 29-char truncation
|
package/lib/sync.js
CHANGED
|
@@ -39,49 +39,94 @@ function mapLimit(items, limit, fn) {
|
|
|
39
39
|
const keyOf = (size, mtime) => `${size}:${Math.floor(mtime || 0)}`
|
|
40
40
|
const localKey = (st) => (st ? keyOf(st.size, st.mtimeMs / 1000) : null)
|
|
41
41
|
const remoteKey = (st) => (st ? keyOf(st.size, st.mtime) : null)
|
|
42
|
+
const isChannelError = (err) => /sftp (?:channel closed|operation timed out)/i.test(String((err && err.message) || err))
|
|
42
43
|
|
|
43
44
|
/** Recursively pull remote → local mirror (three-way, ignore-aware). */
|
|
44
45
|
export async function syncTree(sftp, remoteDir, localDir, opts = {}) {
|
|
45
46
|
const {
|
|
46
|
-
maxDepth = 8,
|
|
47
|
+
maxDepth = opts.depth ?? 8,
|
|
47
48
|
maxFiles = 2000,
|
|
48
49
|
maxFileBytes = 0,
|
|
49
50
|
isIgnored = () => false,
|
|
50
51
|
dryRun = false,
|
|
51
52
|
force = false,
|
|
52
53
|
state = {},
|
|
54
|
+
getSftp = null,
|
|
55
|
+
maxReconnects = 2,
|
|
53
56
|
} = opts
|
|
54
|
-
const stats = {
|
|
57
|
+
const stats = {
|
|
58
|
+
files: 0,
|
|
59
|
+
dirs: 0,
|
|
60
|
+
skippedUnchanged: 0,
|
|
61
|
+
skippedLarge: 0,
|
|
62
|
+
failed: 0,
|
|
63
|
+
abortedError: '',
|
|
64
|
+
conflicts: [],
|
|
65
|
+
staleRemote: 0,
|
|
66
|
+
touched: [],
|
|
67
|
+
truncated: false,
|
|
68
|
+
}
|
|
55
69
|
const nextState = { ...state }
|
|
70
|
+
let curSftp = sftp
|
|
71
|
+
let channelDead = false
|
|
72
|
+
let reconnects = 0
|
|
73
|
+
let reconnecting = null
|
|
56
74
|
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
75
|
+
const reconnectSftp = async (failedSurface) => {
|
|
76
|
+
if (typeof getSftp !== 'function' || reconnects >= maxReconnects) return null
|
|
77
|
+
if (curSftp && curSftp !== failedSurface) return curSftp
|
|
78
|
+
if (!reconnecting) {
|
|
79
|
+
reconnecting = (async () => {
|
|
80
|
+
reconnects++
|
|
81
|
+
const next = await getSftp()
|
|
82
|
+
if (next) curSftp = next
|
|
83
|
+
return next
|
|
84
|
+
})().finally(() => { reconnecting = null })
|
|
85
|
+
}
|
|
86
|
+
return reconnecting
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const callSftp = async (fn) => {
|
|
90
|
+
if (channelDead) throw new Error(stats.abortedError || 'sftp channel closed')
|
|
91
|
+
const surface = curSftp
|
|
92
|
+
try {
|
|
93
|
+
return await fn(surface)
|
|
94
|
+
} catch (err) {
|
|
95
|
+
if (isChannelError(err)) {
|
|
96
|
+
try {
|
|
97
|
+
const next = await reconnectSftp(surface)
|
|
98
|
+
if (next) return await fn(next)
|
|
99
|
+
} catch (retryErr) {
|
|
100
|
+
if (isChannelError(retryErr)) err = retryErr
|
|
101
|
+
else throw retryErr
|
|
102
|
+
}
|
|
103
|
+
channelDead = true
|
|
104
|
+
if (!stats.abortedError) stats.abortedError = String((err && err.message) || err)
|
|
68
105
|
}
|
|
69
|
-
|
|
70
|
-
const lp = path.join(lDir, name)
|
|
71
|
-
const rel = relPathUnder(remoteDir, rp) || name
|
|
72
|
-
if (isIgnored(rel, true)) continue
|
|
73
|
-
if (!existsSync(lp)) mkdirSync(lp, { recursive: true })
|
|
74
|
-
await walk(rp, lp, depth - 1)
|
|
75
|
-
stats.dirs++
|
|
76
|
-
if (stats.files >= maxFiles) break
|
|
106
|
+
throw err
|
|
77
107
|
}
|
|
78
|
-
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const walk = async (rDir, lDir, depth) => {
|
|
111
|
+
if (channelDead) return
|
|
112
|
+
let entries
|
|
113
|
+
try {
|
|
114
|
+
entries = (await callSftp((s) => s.readdir(rDir))) || []
|
|
115
|
+
} catch {
|
|
116
|
+
stats.failed++
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
if (!dryRun && !existsSync(lDir)) mkdirSync(lDir, { recursive: true })
|
|
79
120
|
|
|
121
|
+
// Sync files in the current directory BEFORE recursing into subdirectories,
|
|
122
|
+
// so shallow/root-level files are never starved when a deep subtree hits
|
|
123
|
+
// maxFiles or an SFTP timeout.
|
|
80
124
|
const files = entries.filter(
|
|
81
125
|
(e) => !(e.attrs && e.attrs.isDirectory && e.attrs.isDirectory()) &&
|
|
82
126
|
String(e.filename) !== '.' && String(e.filename) !== '..',
|
|
83
127
|
)
|
|
84
128
|
await mapLimit(files, 4, async (e) => {
|
|
129
|
+
if (channelDead) return
|
|
85
130
|
if (stats.files >= maxFiles) { stats.truncated = true; return }
|
|
86
131
|
const name = String(e.filename)
|
|
87
132
|
const rp = joinRemotePath(rDir, name)
|
|
@@ -89,7 +134,12 @@ export async function syncTree(sftp, remoteDir, localDir, opts = {}) {
|
|
|
89
134
|
const rel = relPathUnder(remoteDir, rp) || name
|
|
90
135
|
if (isIgnored(rel, false)) return
|
|
91
136
|
let r
|
|
92
|
-
try {
|
|
137
|
+
try {
|
|
138
|
+
r = await callSftp((s) => s.stat(rp))
|
|
139
|
+
} catch {
|
|
140
|
+
stats.failed++
|
|
141
|
+
return
|
|
142
|
+
}
|
|
93
143
|
if (maxFileBytes > 0 && r.size > maxFileBytes) { stats.skippedLarge++; return }
|
|
94
144
|
const rk = remoteKey(r)
|
|
95
145
|
const sk = state[rel] ? keyOf(state[rel].size, state[rel].mtime) : null
|
|
@@ -114,14 +164,39 @@ export async function syncTree(sftp, remoteDir, localDir, opts = {}) {
|
|
|
114
164
|
return
|
|
115
165
|
}
|
|
116
166
|
try {
|
|
117
|
-
const buf = await
|
|
167
|
+
const buf = await callSftp((s) => s.readFile(rp))
|
|
118
168
|
writeFileSync(lp, buf)
|
|
119
169
|
try { utimesSync(lp, new Date(r.mtime * 1000), new Date(r.mtime * 1000)) } catch {}
|
|
120
170
|
stats.files++
|
|
121
171
|
stats.touched.push(rp)
|
|
122
172
|
nextState[rel] = { size: r.size, mtime: r.mtime }
|
|
123
|
-
} catch {
|
|
173
|
+
} catch {
|
|
174
|
+
stats.failed++
|
|
175
|
+
}
|
|
124
176
|
})
|
|
177
|
+
if (channelDead) return
|
|
178
|
+
if (stats.files >= maxFiles) { stats.truncated = true; return }
|
|
179
|
+
|
|
180
|
+
// Subdirectories next (sequential, depth-bounded). Local directories are
|
|
181
|
+
// only created after their remote readdir succeeds, never when SFTP is dead.
|
|
182
|
+
for (const e of entries) {
|
|
183
|
+
if (channelDead) break
|
|
184
|
+
const name = String(e.filename)
|
|
185
|
+
if (name === '.' || name === '..') continue
|
|
186
|
+
const isDir = !!(e.attrs && e.attrs.isDirectory && e.attrs.isDirectory())
|
|
187
|
+
if (!isDir) continue
|
|
188
|
+
if (depth <= 0 || stats.files >= maxFiles) {
|
|
189
|
+
stats.truncated = true
|
|
190
|
+
continue
|
|
191
|
+
}
|
|
192
|
+
const rp = joinRemotePath(rDir, name)
|
|
193
|
+
const lp = path.join(lDir, name)
|
|
194
|
+
const rel = relPathUnder(remoteDir, rp) || name
|
|
195
|
+
if (isIgnored(rel, true)) continue
|
|
196
|
+
await walk(rp, lp, depth - 1)
|
|
197
|
+
if (!channelDead) stats.dirs++
|
|
198
|
+
if (stats.files >= maxFiles) { stats.truncated = true; break }
|
|
199
|
+
}
|
|
125
200
|
}
|
|
126
201
|
|
|
127
202
|
await walk(remoteDir, localDir, maxDepth)
|
package/lib/tui/i18n.js
CHANGED
|
@@ -23,7 +23,7 @@ const DICT = {
|
|
|
23
23
|
'status.detailRemote': '远端 {path}',
|
|
24
24
|
|
|
25
25
|
// ── 机器列表 ──────────────────────────────────────────────────────────
|
|
26
|
-
'list.hints': '↑↓ 选择 ·
|
|
26
|
+
'list.hints': '↑↓ 选择 · Enter 动作 · a 新增 · c 连接 · t 探测 · b 浏览 · o 镜像 · e 编辑 · d 删除 · ←/Esc 关闭',
|
|
27
27
|
'list.empty': '还没有保存的远程机 —— 按 a 添加一台',
|
|
28
28
|
'list.count': '{count} 台机器',
|
|
29
29
|
'list.current': '当前',
|
|
@@ -32,7 +32,6 @@ const DICT = {
|
|
|
32
32
|
// ── 动作菜单 ──────────────────────────────────────────────────────────
|
|
33
33
|
'menu.title': '动作 · {name}',
|
|
34
34
|
'menu.connect': '连接',
|
|
35
|
-
'menu.workspace': '设为工作区',
|
|
36
35
|
'menu.workspaces': '工作区管理(删除/清理)',
|
|
37
36
|
'menu.edit': '编辑',
|
|
38
37
|
'menu.delete': '删除',
|
|
@@ -117,6 +116,7 @@ const DICT = {
|
|
|
117
116
|
'busy.saving': '正在保存',
|
|
118
117
|
'busy.deleting': '正在删除',
|
|
119
118
|
'busy.settingWorkspace': '正在建立工作区',
|
|
119
|
+
'busy.revealFolder': '正在打开镜像文件夹',
|
|
120
120
|
'busy.loading': '正在加载',
|
|
121
121
|
'busy.loadingMirrors': '正在读取本地镜像工作区',
|
|
122
122
|
'footer.error': '错误:{err}',
|
|
@@ -130,11 +130,11 @@ const DICT = {
|
|
|
130
130
|
'notify.probeFailed': '探测失败:{err}',
|
|
131
131
|
'notify.saved': '已保存 {name}',
|
|
132
132
|
'notify.deleted': '已删除 {name}',
|
|
133
|
+
'notify.revealed': '已在文件管理器中打开 {path}',
|
|
133
134
|
'notify.workspaceSet': '已采用工作区 {label}',
|
|
134
135
|
'notify.switchRefused': '宿主拒绝切换到 {label}',
|
|
135
136
|
'notify.switchFailed': '切换工作区失败:{err}',
|
|
136
137
|
'notify.pickFailed': '无法采用该目录:{err}',
|
|
137
|
-
'notify.noWorkspace': '该机器还没有记录的工作区,正在打开目录浏览',
|
|
138
138
|
'notify.warnings': '警告:{text}',
|
|
139
139
|
|
|
140
140
|
// ── 无场景时的对话框降级流程 ──────────────────────────────────────────
|
|
@@ -175,7 +175,7 @@ const DICT = {
|
|
|
175
175
|
'status.detailTarget': '{user}@{host}:{port}',
|
|
176
176
|
'status.detailRemote': 'remote {path}',
|
|
177
177
|
|
|
178
|
-
'list.hints': '↑↓ select ·
|
|
178
|
+
'list.hints': '↑↓ select · Enter actions · a add · c connect · t probe · b browse · o mirror · e edit · d delete · ←/Esc close',
|
|
179
179
|
'list.empty': 'no saved machines yet — press a to add one',
|
|
180
180
|
'list.count': '{count} machines',
|
|
181
181
|
'list.current': 'current',
|
|
@@ -183,7 +183,6 @@ const DICT = {
|
|
|
183
183
|
|
|
184
184
|
'menu.title': 'Actions · {name}',
|
|
185
185
|
'menu.connect': 'Connect',
|
|
186
|
-
'menu.workspace': 'Use as workspace',
|
|
187
186
|
'menu.workspaces': 'Manage workspaces (delete)',
|
|
188
187
|
'menu.edit': 'Edit',
|
|
189
188
|
'menu.delete': 'Delete',
|
|
@@ -262,6 +261,7 @@ const DICT = {
|
|
|
262
261
|
'busy.saving': 'saving',
|
|
263
262
|
'busy.deleting': 'deleting',
|
|
264
263
|
'busy.settingWorkspace': 'creating workspace',
|
|
264
|
+
'busy.revealFolder': 'opening mirror folder',
|
|
265
265
|
'busy.loading': 'loading',
|
|
266
266
|
'busy.loadingMirrors': 'loading local mirror workspaces',
|
|
267
267
|
'footer.error': 'error: {err}',
|
|
@@ -274,11 +274,11 @@ const DICT = {
|
|
|
274
274
|
'notify.probeFailed': 'probe failed: {err}',
|
|
275
275
|
'notify.saved': 'saved {name}',
|
|
276
276
|
'notify.deleted': 'deleted {name}',
|
|
277
|
+
'notify.revealed': 'opened {path} in the file manager',
|
|
277
278
|
'notify.workspaceSet': 'workspace adopted: {label}',
|
|
278
279
|
'notify.switchRefused': 'the host refused to switch to {label}',
|
|
279
280
|
'notify.switchFailed': 'workspace switch failed: {err}',
|
|
280
281
|
'notify.pickFailed': 'cannot adopt this directory: {err}',
|
|
281
|
-
'notify.noWorkspace': 'this machine has no recorded workspace yet — opening the directory browser',
|
|
282
282
|
'notify.warnings': 'warning: {text}',
|
|
283
283
|
|
|
284
284
|
'flow.add': '+ Add remote machine',
|
package/lib/tui/scene.js
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
} from './format.js'
|
|
23
23
|
|
|
24
24
|
/** 动作菜单项(顺序即渲染顺序)。 */
|
|
25
|
-
const MENU_ACTIONS = ['connect', '
|
|
25
|
+
const MENU_ACTIONS = ['connect', 'workspaces', 'edit', 'delete', 'probe', 'browse']
|
|
26
26
|
/** 表单里永远出现的字段。 */
|
|
27
27
|
const BASE_FORM_FIELDS = ['name', 'host', 'useSshConfig', 'port', 'username', 'auth']
|
|
28
28
|
|
|
@@ -294,6 +294,14 @@ export function createSceneComponent({ api, config, i18n, notify } = {}) {
|
|
|
294
294
|
await reload()
|
|
295
295
|
}
|
|
296
296
|
|
|
297
|
+
/** 在系统文件管理器里打开本机 dsh-remote 的镜像根目录(remote-workspaces)。 */
|
|
298
|
+
async function revealMirrorFolder() {
|
|
299
|
+
if (typeof api.revealMirrorFolder !== 'function') return
|
|
300
|
+
const result = await runOp(t('busy.revealFolder'), () => api.revealMirrorFolder())
|
|
301
|
+
if (!result) return
|
|
302
|
+
toast(t('notify.revealed', { path: result.path }), { color: 'success' })
|
|
303
|
+
}
|
|
304
|
+
|
|
297
305
|
async function probeMachine(machine) {
|
|
298
306
|
if (!machine || typeof api.probeMachine !== 'function') return
|
|
299
307
|
const patch = {
|
|
@@ -330,22 +338,6 @@ export function createSceneComponent({ api, config, i18n, notify } = {}) {
|
|
|
330
338
|
await reload()
|
|
331
339
|
}
|
|
332
340
|
|
|
333
|
-
async function ensureMachineWorkspace(machine) {
|
|
334
|
-
if (!machine) return
|
|
335
|
-
if (!machine.workspace) {
|
|
336
|
-
toast(t('notify.noWorkspace'), { color: 'warning' })
|
|
337
|
-
openBrowse(machine)
|
|
338
|
-
return
|
|
339
|
-
}
|
|
340
|
-
const workspace = await runOp(t('busy.settingWorkspace'), () => api.ensureRemoteWorkspace({
|
|
341
|
-
machineId: machine.id,
|
|
342
|
-
remotePath: machine.workspace,
|
|
343
|
-
register: true,
|
|
344
|
-
}))
|
|
345
|
-
if (!workspace) return
|
|
346
|
-
await adoptWorkspace(machine, workspace, machine.workspace)
|
|
347
|
-
}
|
|
348
|
-
|
|
349
341
|
async function pickBrowseWorkspace() {
|
|
350
342
|
const current = browse
|
|
351
343
|
if (!current) return
|
|
@@ -532,7 +524,6 @@ export function createSceneComponent({ api, config, i18n, notify } = {}) {
|
|
|
532
524
|
if (!machine) return
|
|
533
525
|
switch (action) {
|
|
534
526
|
case 'connect': void connectMachine(machine); break
|
|
535
|
-
case 'workspace': void ensureMachineWorkspace(machine); break
|
|
536
527
|
case 'workspaces': openWorkspaces(machine); break
|
|
537
528
|
case 'edit': openForm(machine); break
|
|
538
529
|
case 'delete': openConfirm(machine); break
|
|
@@ -582,7 +573,7 @@ export function createSceneComponent({ api, config, i18n, notify } = {}) {
|
|
|
582
573
|
case 'd': openConfirm(selectedMachine); break
|
|
583
574
|
case 't': void probeMachine(selectedMachine); break
|
|
584
575
|
case 'b': openBrowse(selectedMachine); break
|
|
585
|
-
case '
|
|
576
|
+
case 'o': void revealMirrorFolder(); break
|
|
586
577
|
default: break
|
|
587
578
|
}
|
|
588
579
|
}
|
|
@@ -611,7 +602,6 @@ export function createSceneComponent({ api, config, i18n, notify } = {}) {
|
|
|
611
602
|
else if (input === 'd') executeAction('delete', selectedMachine)
|
|
612
603
|
else if (input === 't') executeAction('probe', selectedMachine)
|
|
613
604
|
else if (input === 'b') executeAction('browse', selectedMachine)
|
|
614
|
-
else if (input === 'w') executeAction('workspace', selectedMachine)
|
|
615
605
|
else if (input === 'm') executeAction('workspaces', selectedMachine)
|
|
616
606
|
}
|
|
617
607
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-remote",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.82",
|
|
4
4
|
"description": "Remote-work assistant for DeepSeek Harness: connect SSH (password/key/agent/keyboard-interactive, multi-hop ProxyJump), list hosts from ~/.ssh/config, pick a remote workspace, operate on it with 21 rw_* tools, conflict-aware mirror sync, an embedded PTY terminal, remote DSH web UI attach, port forwarding, host grouping, remote sandbox fencing, audit log, keychain passwords.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "flymysql <flyphp@outlook.com>",
|