dsh-remote-go 0.3.1 → 0.3.2
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.md +1 -0
- package/dist/client.js +4 -0
- package/dist/src/connect/pipeline.js +2 -2
- package/dist/src/connect/reattach.js +6 -0
- package/dist/src/constants.js +17 -4
- package/dist/src/context.js +3 -1
- package/dist/src/host-lifecycle.js +36 -8
- package/dist/src/runtime/rules.js +8 -1
- package/dist/src/ssh.js +4 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
- **连接过程可见**:首次连接在浮窗里完成:确认主机指纹、按需输入密码,下方按阶段打印 SSH → 探测 → 准备运行时 → 启动 → 隧道 → 校验的日志并自动跟随;失败时的错误与建议也留在这个窗口里。连上后窗口自动关闭并接管整窗。
|
|
14
14
|
- **远端运行时自管**:远端不需要预装 Node,也不用安装本插件。插件把 Node 装到 `~/.dsh/remote-go/node`,再用 `npx` 拉起 `@deepseek-ai/dsh@<本机版本>`(`--port 0`),所以两端版本恒等,不动系统 Node、不需要 root,也不干扰远端其他项目。
|
|
15
15
|
- **重启 / 关闭远端 DSH**:已连接的主机卡片上可以直接重启或关闭远端 DSH。重启复用当前 SSH 会话,不重新认证,换新端口与新 token;关闭先弹一句确认,然后停掉本连接管理的远端进程并断开(不自动重连,点「重连」得到全新实例)。「重启」和「重连」都会浮出这台主机的连接窗口,进度与连接日志都在那里。远端自己重启(例如在远端更新插件)时,探活确认后会自动重新接管。
|
|
16
|
+
- **弱网也能自己缓过来**:SSH keepalive 容忍约 60 秒的停顿;探活要连续三次失败才判定远端不可用;自动重连在快速退避预算用尽后继续每约 30 秒试一次、最长 10 分钟,连接窗口会显示「链路仍未恢复,N 秒后继续重试」;远端自重启的重挂若因网络问题失败,也会自动重拨,不用手动点「重连」。
|
|
16
17
|
- **远端文件下载**:远端 Files 面板右键文件「下载」、右键文件夹「下载到本地」,Host 用同一条 SSH/SFTP 连接流式写入本地目录;不打包 ZIP、不限大小或数量,重名自动加 ` (2)`,保存位置限本机用户主目录。
|
|
17
18
|
- **给本地 AI 会话用主机**:注册三个模型工具——只读的 `remote_hosts_list`(清单、连接状态、SSH 用户与端口)、`remote_host_report`(单台主机的十项体检 + 连接日志)、`remote_exec`(在已连接主机上跑一条命令,复用插件已有的 SSH 会话)。三个工具默认全部隐藏,只注入解锁入口 `remote_tools`;调用后按会话解锁并在下一步可用。返回值不含密码、token、指纹原文或私钥路径,`remote_exec` 的写模式默认关闭,需在插件配置里显式打开。
|
|
18
19
|
|
package/dist/client.js
CHANGED
|
@@ -811,6 +811,10 @@ window.__ModuleLoader__.load({
|
|
|
811
811
|
'progress.verifying': ['正在验证远端界面…', 'Verifying the remote UI…'],
|
|
812
812
|
'progress.ready': ['就绪', 'Ready'],
|
|
813
813
|
'progress.reconnecting': ['断线重连中(第 {attempt}/{max} 次)…', 'Reconnecting ({attempt}/{max})…'],
|
|
814
|
+
'progress.reconnect-waiting': [
|
|
815
|
+
'链路仍未恢复,{retryInSec} 秒后继续重试(第 {attempt} 次)…',
|
|
816
|
+
'The link is still down; retrying in {retryInSec}s (attempt {attempt})…',
|
|
817
|
+
],
|
|
814
818
|
'progress.restarting-remote': [
|
|
815
819
|
'远端 DSH 正在重启,正在重新挂载界面…',
|
|
816
820
|
'The remote DSH is restarting; re-attaching the remote UI…',
|
|
@@ -366,8 +366,8 @@ async function connectPipeline(ctx, runtime) {
|
|
|
366
366
|
runtime.connectPromise = null;
|
|
367
367
|
}
|
|
368
368
|
}
|
|
369
|
-
/** Arm the next automatic attempt; `scheduleReconnect` owns the settings gate and the budget, so a spent budget is reported once. */
|
|
370
|
-
function scheduleConnectRetry(ctx, runtime) {
|
|
369
|
+
/** Arm the next automatic attempt; `scheduleReconnect` owns the settings gate and the budget, so a spent budget is reported once. Exported for the one-shot actions whose failure leaves no usable transport (`reattach.ts`): they must hand the link back to the same retry loop instead of parking at an error card. */
|
|
370
|
+
export function scheduleConnectRetry(ctx, runtime) {
|
|
371
371
|
if (ctx.state.disposed === true || runtime.desired !== 'connected')
|
|
372
372
|
return;
|
|
373
373
|
if (!runtime.entry.autoReconnect || !ctx.settings().autoReconnect.enabled)
|
|
@@ -12,6 +12,7 @@ import { markConnected, recordRestart } from './attach.js';
|
|
|
12
12
|
import { SSH_CLOSED_DETAIL } from './failures.js';
|
|
13
13
|
import { LinkCancelled, linkActionState } from './guards.js';
|
|
14
14
|
import { rememberBound } from './ownership.js';
|
|
15
|
+
import { scheduleConnectRetry } from './pipeline.js';
|
|
15
16
|
import { openTunnelFor } from './transport.js';
|
|
16
17
|
import { verifyRemoteUi } from './verify.js';
|
|
17
18
|
export async function reattachHost(ctx, runtime, info = {}) {
|
|
@@ -180,6 +181,11 @@ async function runReattach(ctx, runtime, info, token) {
|
|
|
180
181
|
caller: 'script',
|
|
181
182
|
emit: false,
|
|
182
183
|
});
|
|
184
|
+
// A re-attach that lost the transport (the stall the probe saw first) leaves no usable link: hand it back to the
|
|
185
|
+
// retry loop, otherwise the error card would wait for a click while the network has already recovered. A policy
|
|
186
|
+
// failure (no launch token, version mismatch) stays terminal — reconnecting cannot fix it.
|
|
187
|
+
if (runtime.ssh?.connected !== true || view.code === 'network')
|
|
188
|
+
scheduleConnectRetry(ctx, runtime);
|
|
183
189
|
ctx.emitState();
|
|
184
190
|
}
|
|
185
191
|
finally {
|
package/dist/src/constants.js
CHANGED
|
@@ -6,24 +6,37 @@ export const API_PREFIX = '/dsh-remote-go/api';
|
|
|
6
6
|
export const REMOTE_VIEW_PREFIX = '/dsh-remote-go/remote/';
|
|
7
7
|
export const API_HEADER = 'x-dsh-remote-go';
|
|
8
8
|
export const PLUGIN_ID = 'dsh-remote-go';
|
|
9
|
-
export const PLUGIN_VERSION = '0.3.
|
|
9
|
+
export const PLUGIN_VERSION = '0.3.2';
|
|
10
10
|
export const MIN_DSH_VERSION = '0.2.2-rc.3';
|
|
11
11
|
export const API_VERSION = '2.12';
|
|
12
12
|
export const DEFAULT_KEY_PATH = '~/.ssh/id_rsa';
|
|
13
13
|
export const REMOTE_START_TIMEOUT_MS = 300_000;
|
|
14
14
|
export const REMOTE_CONFLICT_TIMEOUT_MS = 120_000;
|
|
15
15
|
export const SSH_READY_TIMEOUT_MS = 20_000;
|
|
16
|
+
/** SSH keepalive cadence: a probe every 15 s keeps NAT/firewall state alive without loading a thin link. */
|
|
17
|
+
export const SSH_KEEPALIVE_INTERVAL_MS = 15_000;
|
|
18
|
+
/** Unanswered keepalives tolerated before the transport is declared dead: 4 x 15 s rides out a ~60 s stall
|
|
19
|
+
* (mobile handoff, VPN re-key, congestion) that used to drop the session after 45 s. */
|
|
20
|
+
export const SSH_KEEPALIVE_COUNT_MAX = 4;
|
|
16
21
|
export const DEFAULT_IDLE_MINUTES = 15;
|
|
17
22
|
export const TUNNEL_PROBE_TIMEOUT_MS = 10_000;
|
|
18
23
|
export const REMOTE_HEARTBEAT_DEFAULT_SEC = 30;
|
|
19
24
|
export const REMOTE_HEARTBEAT_MIN_SEC = 5;
|
|
20
25
|
export const REMOTE_HEARTBEAT_MAX_SEC = 600;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export const
|
|
26
|
+
/** Consecutive failed probes before a re-attach. Two was one lost packet away from tearing down a healthy link over a
|
|
27
|
+
* slow tunnel; the quick recheck after each failure still proves a real restart in a few seconds. */
|
|
28
|
+
export const REMOTE_UNREACHABLE_FAILURES = 3;
|
|
29
|
+
export const REMOTE_UNREACHABLE_CONFIRM_DELAY_MS = 2_500;
|
|
30
|
+
export const REMOTE_UNREACHABLE_RECHECK_DELAY_MS = 3_500;
|
|
24
31
|
export const REMOTE_EPISODE_COOLDOWN_MS = 15_000;
|
|
25
32
|
export const REMOTE_REPAIR_BACKOFF_MS = 30_000;
|
|
26
33
|
export const REMOTE_REPAIR_BACKOFF_MAX_MS = 120_000;
|
|
27
34
|
export const REMOTE_TUNNEL_REPAIR_SETTLE_MS = 5_000;
|
|
28
35
|
export const REMOTE_REATTACH_ATTEMPTS = 6;
|
|
29
36
|
export const REMOTE_REATTACH_INTERVAL_MS = 2_000;
|
|
37
|
+
/** Spacing of the slow retries that follow the fast reconnect budget: one attempt every 30 s keeps a bad link from
|
|
38
|
+
* being hammered while the user still gets the link back on its own. */
|
|
39
|
+
export const REMOTE_RECONNECT_SLOW_DELAY_MS = 30_000;
|
|
40
|
+
/** How long the slow phase keeps trying before auto-reconnect gives up: 10 minutes covers a reboot, a VPN re-dial or
|
|
41
|
+
* a carrier handoff, which is exactly the window where a user expects the connection to come back by itself. */
|
|
42
|
+
export const REMOTE_RECONNECT_PATIENCE_MS = 10 * 60_000;
|
package/dist/src/context.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* 47-key god-`ctx`, so a module reaches only the capability it declares; the assembled object keeps the same keys and
|
|
3
3
|
* paths because tests use `service.ctx` as public API. Narrowing is in the parameter types, never a rename. */
|
|
4
4
|
import { planNpx, verifyNpxVersion } from './bootstrap.js';
|
|
5
|
-
import { REMOTE_CONFLICT_TIMEOUT_MS, REMOTE_REATTACH_ATTEMPTS, REMOTE_REATTACH_INTERVAL_MS, REMOTE_TUNNEL_REPAIR_SETTLE_MS, REMOTE_UNREACHABLE_CONFIRM_DELAY_MS, REMOTE_UNREACHABLE_RECHECK_DELAY_MS, } from './constants.js';
|
|
5
|
+
import { REMOTE_CONFLICT_TIMEOUT_MS, REMOTE_REATTACH_ATTEMPTS, REMOTE_REATTACH_INTERVAL_MS, REMOTE_RECONNECT_PATIENCE_MS, REMOTE_RECONNECT_SLOW_DELAY_MS, REMOTE_TUNNEL_REPAIR_SETTLE_MS, REMOTE_UNREACHABLE_CONFIRM_DELAY_MS, REMOTE_UNREACHABLE_RECHECK_DELAY_MS, } from './constants.js';
|
|
6
6
|
import { createConnectProgress } from './connect-progress.js';
|
|
7
7
|
import { loadLocalSshMaterial } from './local-ssh.js';
|
|
8
8
|
import { ensureRemoteNode } from './node-runtime.js';
|
|
@@ -31,6 +31,8 @@ export function createCtx(options, hooks) {
|
|
|
31
31
|
reattachAttempts: options.reattachAttempts ?? REMOTE_REATTACH_ATTEMPTS,
|
|
32
32
|
reattachIntervalMs: options.reattachIntervalMs ?? REMOTE_REATTACH_INTERVAL_MS,
|
|
33
33
|
tunnelRepairSettleMs: options.tunnelRepairSettleMs ?? REMOTE_TUNNEL_REPAIR_SETTLE_MS,
|
|
34
|
+
reconnectSlowDelayMs: options.reconnectSlowDelayMs ?? REMOTE_RECONNECT_SLOW_DELAY_MS,
|
|
35
|
+
reconnectPatienceMs: options.reconnectPatienceMs ?? REMOTE_RECONNECT_PATIENCE_MS,
|
|
34
36
|
};
|
|
35
37
|
const deps = {
|
|
36
38
|
sshFactory: options.sshFactory ?? ((sshOptions) => createSsh2Port(sshOptions)),
|
|
@@ -67,22 +67,50 @@ export function scheduleReconnect(ctx, runtime, onDue) {
|
|
|
67
67
|
const settings = ctx.settings();
|
|
68
68
|
if (!runtime.entry.autoReconnect || !settings.autoReconnect.enabled)
|
|
69
69
|
return skip();
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
// `maxAttempts` bounds the fast, exponential phase; the patience window then adds slow attempts on top, so a
|
|
71
|
+
// multi-minute outage (reboot, VPN re-dial, carrier handoff) still recovers instead of parking at an error card.
|
|
72
|
+
// `maxAttempts: 0` and a spent patience window both stay "no retry", exactly as before.
|
|
73
|
+
const fastAttempts = Math.max(0, Number(settings.autoReconnect.maxAttempts) || 0);
|
|
74
|
+
const slowDelayMs = Math.max(0, Number(ctx.timers.reconnectSlowDelayMs) || 0);
|
|
75
|
+
const patienceMs = Math.max(0, Number(ctx.timers.reconnectPatienceMs) || 0);
|
|
76
|
+
const slowAttempts = fastAttempts > 0 && slowDelayMs > 0 ? Math.floor(patienceMs / slowDelayMs) : 0;
|
|
77
|
+
const totalAttempts = fastAttempts + slowAttempts;
|
|
78
|
+
if (totalAttempts <= 0 || runtime.reconnectAttempts >= totalAttempts) {
|
|
79
|
+
if (slowAttempts > 0) {
|
|
80
|
+
ctx.progress.log(runtime, 'warn', `auto reconnect gave up after ${totalAttempts} attempts (${fastAttempts} fast + ${slowAttempts} slow, about ${Math.round(patienceMs / 60_000)} min)`);
|
|
81
|
+
}
|
|
72
82
|
const view = toErrorView(errors.network({
|
|
73
|
-
zh: `连接已断开,自动重连 ${
|
|
74
|
-
en: `The connection dropped and ${
|
|
83
|
+
zh: `连接已断开,自动重连 ${totalAttempts} 次均失败。远端任务可能仍在运行。`,
|
|
84
|
+
en: `The connection dropped and ${totalAttempts} automatic retries failed. Remote tasks may still be running.`,
|
|
75
85
|
}));
|
|
76
|
-
const event = { type: 'reconnect.gaveup', maxAttempts, view };
|
|
86
|
+
const event = { type: 'reconnect.gaveup', maxAttempts: totalAttempts, view };
|
|
77
87
|
void dispatch(effectsOf(ctx), runtime, event, scopeFactsFor(ctx, runtime, event), { caller: 'timer' });
|
|
78
88
|
return;
|
|
79
89
|
}
|
|
80
90
|
const attempt = runtime.reconnectAttempts + 1;
|
|
91
|
+
const slow = attempt > fastAttempts;
|
|
81
92
|
const baseDelayMs = settings.autoReconnect.baseDelayMs;
|
|
82
|
-
const delay =
|
|
93
|
+
const delay = slow
|
|
94
|
+
? randomDelay(slowDelayMs * 0.85, slowDelayMs * 1.15)
|
|
95
|
+
: randomDelay(baseDelayMs, baseDelayMs * 2 ** Math.min(attempt, 4));
|
|
83
96
|
const seconds = Math.round(delay / 100) / 10;
|
|
84
|
-
|
|
85
|
-
|
|
97
|
+
if (slow) {
|
|
98
|
+
// The slow phase is long by design: one line when it starts and every fifth attempt after it, the rest at debug.
|
|
99
|
+
const slowIndex = attempt - fastAttempts;
|
|
100
|
+
const level = slowIndex === 1 || slowIndex % 5 === 0 ? 'info' : 'debug';
|
|
101
|
+
ctx.progress.log(runtime, level, `still offline; retrying in ${seconds}s (slow retry ${slowIndex}/${slowAttempts})`);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
ctx.progress.log(runtime, 'warn', `link lost; retrying in ${seconds}s (attempt ${attempt}/${fastAttempts})`);
|
|
105
|
+
}
|
|
106
|
+
// `max` stays the fast budget the setting names; a slow retry reports its own count on the card instead.
|
|
107
|
+
const scheduled = {
|
|
108
|
+
type: 'reconnect.scheduled',
|
|
109
|
+
attempt,
|
|
110
|
+
max: fastAttempts,
|
|
111
|
+
delayMs: delay,
|
|
112
|
+
...(slow ? { slow: true } : {}),
|
|
113
|
+
};
|
|
86
114
|
void dispatch(effectsOf(ctx), runtime, scheduled, scopeFactsFor(ctx, runtime, scheduled), {
|
|
87
115
|
caller: 'timer',
|
|
88
116
|
armReconnect: (ms) => {
|
|
@@ -419,7 +419,14 @@ export const TABLE = {
|
|
|
419
419
|
guard: (state) => (state.desired === 'connected' ? true : 'illegal-transition'),
|
|
420
420
|
apply: (state, event) => move(state, {
|
|
421
421
|
reconnectAttempts: event.attempt,
|
|
422
|
-
|
|
422
|
+
// A slow retry says when it comes back rather than how many quick attempts were spent: after the fast budget
|
|
423
|
+
// the attempt count alone would read as "the 7th of 5 tries".
|
|
424
|
+
progress: event.slow === true
|
|
425
|
+
? progressOf('reconnect-waiting', {
|
|
426
|
+
attempt: event.attempt,
|
|
427
|
+
retryInSec: Math.round(event.delayMs / 100) / 10,
|
|
428
|
+
})
|
|
429
|
+
: progressOf('reconnecting', { attempt: event.attempt, max: event.max }),
|
|
423
430
|
}),
|
|
424
431
|
effects: (_state, event) => [arm('reconnect', event.delayMs), emit()],
|
|
425
432
|
},
|
package/dist/src/ssh.js
CHANGED
|
@@ -6,6 +6,7 @@ import { open } from 'node:fs/promises';
|
|
|
6
6
|
import { homedir } from 'node:os';
|
|
7
7
|
import path from 'node:path';
|
|
8
8
|
import ssh2 from '../vendor/ssh2.bundle.cjs';
|
|
9
|
+
import { SSH_KEEPALIVE_COUNT_MAX, SSH_KEEPALIVE_INTERVAL_MS } from './constants.js';
|
|
9
10
|
import { errors } from './errors.js';
|
|
10
11
|
import { fingerprintFromBlob } from './known-hosts.js';
|
|
11
12
|
import { classifySshFailure, closedError, isHostKeyError } from './ssh-failures.js';
|
|
@@ -56,7 +57,8 @@ export class SshConnection extends EventEmitter {
|
|
|
56
57
|
pinnedFingerprint: null,
|
|
57
58
|
knownHostFingerprints: [],
|
|
58
59
|
readyTimeoutMs: 20_000,
|
|
59
|
-
keepaliveIntervalMs:
|
|
60
|
+
keepaliveIntervalMs: SSH_KEEPALIVE_INTERVAL_MS,
|
|
61
|
+
keepaliveCountMax: SSH_KEEPALIVE_COUNT_MAX,
|
|
60
62
|
home: homedir(),
|
|
61
63
|
...options,
|
|
62
64
|
identityFiles: options.identityFiles ?? [],
|
|
@@ -135,7 +137,7 @@ export class SshConnection extends EventEmitter {
|
|
|
135
137
|
username: this.options.username ?? undefined,
|
|
136
138
|
readyTimeout: this.options.readyTimeoutMs,
|
|
137
139
|
keepaliveInterval: this.options.keepaliveIntervalMs,
|
|
138
|
-
keepaliveCountMax:
|
|
140
|
+
keepaliveCountMax: this.options.keepaliveCountMax,
|
|
139
141
|
tryKeyboard: false,
|
|
140
142
|
...(this.options.sock ? { sock: this.options.sock } : {}),
|
|
141
143
|
...authConfig,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-remote-go",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "DSH 插件:在本地 DSH 里通过 SSH 使用远端 DSH(主机条切换、整窗接管、连接进度与日志、重启/关闭远端、远端文件下载、给本地 AI 会话的主机清单 / 体检报告 / 受控远端命令,三者默认隐藏按需解锁;插件自带 Node + npx,数据留在远端 ~/.dsh) | DSH plugin: use a remote DSH over SSH inside your local DSH (host switcher, full-window UI, connect progress and log, remote restart/stop, remote file downloads, and a host list / diagnosis report / guarded remote command for local AI sessions — hidden until the session unlocks them; plugin-managed Node + npx, data stays in the remote ~/.dsh)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek",
|
|
@@ -65,12 +65,12 @@
|
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@types/node": "^
|
|
68
|
+
"@types/node": "^26.6.6",
|
|
69
69
|
"@types/react": "^19.3.0",
|
|
70
70
|
"esbuild": "0.28.2",
|
|
71
71
|
"js-yaml": "^5.5.0",
|
|
72
72
|
"prettier": "^3.10.1",
|
|
73
|
-
"puppeteer-core": "^25.
|
|
73
|
+
"puppeteer-core": "^25.18.1",
|
|
74
74
|
"react": "^19.3.1",
|
|
75
75
|
"react-dom": "^19.3.1",
|
|
76
76
|
"ssh2": "1.17.0",
|