dsh-remote-go 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/README.md +64 -95
  2. package/{client.js → dist/client.js} +7805 -5486
  3. package/dist/index.js +4 -0
  4. package/dist/src/admission.js +46 -0
  5. package/dist/src/api.js +442 -0
  6. package/dist/src/atomic-json.js +235 -0
  7. package/dist/src/bootstrap.js +106 -0
  8. package/dist/src/connect/attach.js +43 -0
  9. package/dist/src/connect/bootstrap.js +14 -0
  10. package/dist/src/connect/failures.js +44 -0
  11. package/dist/src/connect/guards.js +31 -0
  12. package/dist/src/connect/launch.js +80 -0
  13. package/dist/src/connect/links.js +70 -0
  14. package/dist/src/connect/ownership.js +220 -0
  15. package/dist/src/connect/pipeline.js +473 -0
  16. package/dist/src/connect/reattach.js +215 -0
  17. package/dist/src/connect/registry.js +11 -0
  18. package/dist/src/connect/repair.js +126 -0
  19. package/dist/src/connect/restart.js +316 -0
  20. package/dist/src/connect/stop.js +198 -0
  21. package/dist/src/connect/transport.js +109 -0
  22. package/dist/src/connect/verify.js +39 -0
  23. package/dist/src/connect/watchdog.js +76 -0
  24. package/dist/src/connect-log.js +162 -0
  25. package/dist/src/connect-progress.js +142 -0
  26. package/dist/src/constants.js +67 -0
  27. package/dist/src/context.js +117 -0
  28. package/dist/src/diagnostics.js +102 -0
  29. package/dist/src/download-jobs.js +230 -0
  30. package/dist/src/errors.js +243 -0
  31. package/dist/src/events.js +390 -0
  32. package/dist/src/host-lifecycle.js +504 -0
  33. package/dist/src/host-registry.js +232 -0
  34. package/dist/src/host-runtime.js +86 -0
  35. package/dist/src/host-view.js +75 -0
  36. package/dist/src/index.js +216 -0
  37. package/dist/src/kernel-adapter.js +434 -0
  38. package/dist/src/key-files.js +52 -0
  39. package/dist/src/known-hosts.js +125 -0
  40. package/dist/src/layout.js +43 -0
  41. package/dist/src/local-download.js +380 -0
  42. package/dist/src/local-ssh.js +30 -0
  43. package/dist/src/local-version.js +101 -0
  44. package/dist/src/node/download.js +160 -0
  45. package/dist/src/node-runtime.js +346 -0
  46. package/dist/src/probe.js +96 -0
  47. package/dist/src/prompts.js +270 -0
  48. package/dist/src/proxy/cookies.js +136 -0
  49. package/dist/src/proxy/headers.js +262 -0
  50. package/dist/src/proxy/http.js +142 -0
  51. package/dist/src/proxy/index.js +135 -0
  52. package/dist/src/proxy/limits.js +8 -0
  53. package/dist/src/proxy/routes.js +39 -0
  54. package/dist/src/proxy/upgrade.js +175 -0
  55. package/dist/src/redact.js +104 -0
  56. package/dist/src/remote-files.js +72 -0
  57. package/dist/src/remote-path.js +123 -0
  58. package/dist/src/remote-proc.js +339 -0
  59. package/dist/src/remote-web/registry.js +147 -0
  60. package/dist/src/remote-web/resolve.js +310 -0
  61. package/dist/src/remote-web/start.js +227 -0
  62. package/dist/src/remote-web/stop.js +93 -0
  63. package/dist/src/request-trust.js +87 -0
  64. package/dist/src/runtime/dispatch.js +310 -0
  65. package/dist/src/runtime/effects.js +91 -0
  66. package/dist/src/runtime/events.js +35 -0
  67. package/dist/src/runtime/fsm.js +120 -0
  68. package/dist/src/runtime/rules.js +565 -0
  69. package/dist/src/secrets.js +142 -0
  70. package/dist/src/service.js +406 -0
  71. package/dist/src/settings.js +144 -0
  72. package/dist/src/ssh-config.js +276 -0
  73. package/dist/src/ssh-failures.js +122 -0
  74. package/dist/src/ssh-port.js +4 -0
  75. package/dist/src/ssh-sftp.js +297 -0
  76. package/dist/src/ssh.js +477 -0
  77. package/dist/src/store.js +191 -0
  78. package/dist/src/tool-shared.js +181 -0
  79. package/dist/src/tools-exec-policy.js +167 -0
  80. package/dist/src/tools-exec.js +371 -0
  81. package/dist/src/tools-report.js +424 -0
  82. package/dist/src/tools.js +411 -0
  83. package/dist/src/tunnel.js +129 -0
  84. package/dist/src/util.js +149 -0
  85. package/dist/src/version.js +114 -0
  86. package/dist/src/watchdog-bus.js +29 -0
  87. package/dist/src/watchdog.js +156 -0
  88. package/index.js +5 -4
  89. package/locale/en.json +2 -2
  90. package/locale/zh.json +2 -2
  91. package/package.json +40 -21
  92. package/vendor/THIRD_PARTY_NOTICES.md +27 -1
  93. package/src/api.js +0 -340
  94. package/src/atomic-json.js +0 -208
  95. package/src/bootstrap.js +0 -100
  96. package/src/connect-log.js +0 -39
  97. package/src/connect-pipeline.js +0 -463
  98. package/src/connect-progress.js +0 -135
  99. package/src/constants.js +0 -31
  100. package/src/diagnostics.js +0 -157
  101. package/src/download-jobs.js +0 -217
  102. package/src/errors.js +0 -316
  103. package/src/host-lifecycle.js +0 -187
  104. package/src/host-registry.js +0 -145
  105. package/src/host-runtime.js +0 -53
  106. package/src/host-view.js +0 -51
  107. package/src/index.js +0 -162
  108. package/src/key-files.js +0 -49
  109. package/src/known-hosts.js +0 -94
  110. package/src/layout.js +0 -35
  111. package/src/local-download.js +0 -162
  112. package/src/local-ssh.js +0 -27
  113. package/src/local-version.js +0 -88
  114. package/src/node-runtime.js +0 -521
  115. package/src/probe.js +0 -89
  116. package/src/prompts.js +0 -132
  117. package/src/redact.js +0 -54
  118. package/src/remote-files.js +0 -71
  119. package/src/remote-path.js +0 -73
  120. package/src/remote-proc.js +0 -208
  121. package/src/remote-web.js +0 -300
  122. package/src/secrets.js +0 -79
  123. package/src/service.js +0 -250
  124. package/src/settings.js +0 -135
  125. package/src/ssh-config.js +0 -271
  126. package/src/ssh.js +0 -652
  127. package/src/store.js +0 -143
  128. package/src/tunnel.js +0 -73
  129. package/src/util.js +0 -153
  130. package/src/version.js +0 -103
  131. package/src/webapp.js +0 -28
  132. package/vendor/ssh2-entry.mjs +0 -12
  133. /package/{vendor → dist/vendor}/ssh2.bundle.cjs +0 -0
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Small pure helpers shared by the host half, unit-tested with node:test.
3
+ */
4
+ export function sleep(ms) {
5
+ return new Promise((resolve) => setTimeout(resolve, ms));
6
+ }
7
+ export function randomDelay(min, max) {
8
+ return Math.round(min + Math.random() * Math.max(0, max - min));
9
+ }
10
+ const ID_ALPHABET = 'abcdefghijklmnopqrstuvwxyz0123456789';
11
+ export function randomId(prefix = 'h') {
12
+ let out = '';
13
+ for (let i = 0; i < 10; i += 1)
14
+ out += ID_ALPHABET[Math.floor(Math.random() * ID_ALPHABET.length)];
15
+ return `${prefix}_${out}`;
16
+ }
17
+ export function nowIso() {
18
+ return new Date().toISOString();
19
+ }
20
+ export function isPlainObject(value) {
21
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
22
+ }
23
+ const LOG_LEVELS = { error: 0, warn: 1, info: 2, debug: 3 };
24
+ /** Prototype-chain names that must never be written by a merge. */
25
+ const UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
26
+ /**
27
+ * Recursively merge `patch` into `base` (arrays and scalars replace). Only keys
28
+ * `base` declares are written, so untrusted input can change known values but
29
+ * never invent a property or poison the prototype.
30
+ */
31
+ export function deepMerge(base, patch) {
32
+ if (!isPlainObject(base) || !isPlainObject(patch))
33
+ return (patch === undefined ? base : patch);
34
+ const out = { ...base };
35
+ for (const key of Object.keys(base)) {
36
+ if (UNSAFE_KEYS.has(key))
37
+ continue;
38
+ const value = patch[key];
39
+ if (value === undefined)
40
+ continue;
41
+ out[key] = isPlainObject(value) && isPlainObject(base[key]) ? deepMerge(base[key], value) : value;
42
+ }
43
+ return out;
44
+ }
45
+ export function clamp(value, min, max) {
46
+ return Math.min(max, Math.max(min, value));
47
+ }
48
+ export function expandHome(value, home) {
49
+ const text = typeof value === 'string' ? value.trim() : '';
50
+ if (text === '')
51
+ return '';
52
+ if (text === '~')
53
+ return home;
54
+ if (text.startsWith('~/') || text.startsWith('~\\'))
55
+ return home.replace(/[\\/]+$/, '') + text.slice(1);
56
+ return text;
57
+ }
58
+ export function parseSshDestination(raw) {
59
+ const text = String(raw ?? '').trim();
60
+ if (text === '')
61
+ return { user: null, host: '', port: null };
62
+ let user = null;
63
+ let rest = text;
64
+ const at = rest.lastIndexOf('@');
65
+ if (at >= 0) {
66
+ user = rest.slice(0, at);
67
+ rest = rest.slice(at + 1);
68
+ }
69
+ let host = rest;
70
+ let port = null;
71
+ if (rest.startsWith('[')) {
72
+ const close = rest.indexOf(']');
73
+ if (close > 0) {
74
+ host = rest.slice(1, close);
75
+ const tail = rest.slice(close + 1);
76
+ if (/^:\d+$/.test(tail))
77
+ port = Number(tail.slice(1));
78
+ }
79
+ }
80
+ else {
81
+ const colon = rest.lastIndexOf(':');
82
+ if (colon > 0 && rest.indexOf(':') === colon) {
83
+ const maybePort = rest.slice(colon + 1);
84
+ if (/^\d{1,5}$/.test(maybePort)) {
85
+ host = rest.slice(0, colon);
86
+ port = Number(maybePort);
87
+ }
88
+ }
89
+ }
90
+ return { user: user || null, host, port };
91
+ }
92
+ export function isLoopbackHost(host) {
93
+ if (!host)
94
+ return false;
95
+ const normalized = host
96
+ .trim()
97
+ .toLowerCase()
98
+ .replace(/^\[|\]$/g, '');
99
+ if (normalized === 'localhost' || normalized === '::1')
100
+ return true;
101
+ if (normalized === '::ffff:127.0.0.1')
102
+ return true;
103
+ return /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(normalized);
104
+ }
105
+ export function shellQuote(value) {
106
+ return `'${String(value).replaceAll("'", `'\\''`)}'`;
107
+ }
108
+ export function headTail(text, max = 4000) {
109
+ const value = String(text ?? '');
110
+ if (value.length <= max)
111
+ return value;
112
+ const head = value.slice(0, Math.floor(max / 2));
113
+ const tail = value.slice(-Math.floor(max / 2));
114
+ return `${head}\n…\n${tail}`;
115
+ }
116
+ export function logVisible(level, threshold = 'info') {
117
+ const rank = LOG_LEVELS[level] ?? LOG_LEVELS.info;
118
+ const floor = LOG_LEVELS[threshold] ?? LOG_LEVELS.info;
119
+ return rank >= floor;
120
+ }
121
+ /** Message of an unknown thrown value, so catch blocks need not spell the ternary. */
122
+ export function messageOf(error) {
123
+ return String(error?.message ?? error);
124
+ }
125
+ /** A positive integer — the only shape `kill`, `/proc` and a TCP port accept. */
126
+ export function isPid(value) {
127
+ return Number.isInteger(value) && value > 0;
128
+ }
129
+ /**
130
+ * A promise that resolves at most once: through `settle`, or with `onTimeout()`
131
+ * when the deadline passes first. `onSettled` runs before the promise resolves so
132
+ * a caller can clear the pending slot it installed on both paths.
133
+ */
134
+ export function createDecision(timeoutMs, onTimeout, onSettled) {
135
+ let settle;
136
+ const promise = new Promise((resolve) => {
137
+ let done = false;
138
+ const timer = setTimeout(() => settle(onTimeout?.()), timeoutMs);
139
+ settle = (value) => {
140
+ if (done)
141
+ return;
142
+ done = true;
143
+ clearTimeout(timer);
144
+ onSettled?.(value);
145
+ resolve(value);
146
+ };
147
+ });
148
+ return { promise, settle };
149
+ }
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Version parsing/comparison and the exact-version parity rule, covering the shapes DSH and Node publish (`0.2.2-rc.1`, `24.22.2`, optional `v`).
3
+ */
4
+ const VERSION_RE = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+([0-9A-Za-z.-]+))?$/;
5
+ export function parseVersion(input) {
6
+ if (typeof input !== 'string')
7
+ return null;
8
+ const match = VERSION_RE.exec(input.trim());
9
+ if (!match)
10
+ return null;
11
+ const [, major, minor, patch, prerelease, build] = match;
12
+ return {
13
+ raw: input.trim(),
14
+ major: Number(major),
15
+ minor: Number(minor),
16
+ patch: Number(patch),
17
+ prerelease: prerelease ? prerelease.split('.').map((part) => (/^\d+$/.test(part) ? Number(part) : part)) : [],
18
+ build: build ?? null,
19
+ };
20
+ }
21
+ export function normalizeVersion(input) {
22
+ const parsed = parseVersion(input);
23
+ if (!parsed)
24
+ return String(input ?? '').trim();
25
+ const core = `${parsed.major}.${parsed.minor}.${parsed.patch}`;
26
+ return parsed.prerelease.length > 0 ? `${core}-${parsed.prerelease.join('.')}` : core;
27
+ }
28
+ /**
29
+ * Semver identifier comparison: numeric identifiers sort before alphanumeric ones. The
30
+ * pre-release list is `(string | number)[]` by spec, so the two `as number` assertions only
31
+ * restore the branch `typeof` already proved — nothing is coerced.
32
+ */
33
+ function compareIdentifiers(a, b) {
34
+ const aNum = typeof a === 'number';
35
+ const bNum = typeof b === 'number';
36
+ if (aNum && bNum)
37
+ return a === b ? 0 : a < b ? -1 : 1;
38
+ if (aNum)
39
+ return -1; // numeric identifiers sort before alphanumeric ones
40
+ if (bNum)
41
+ return 1;
42
+ return a === b ? 0 : String(a) < String(b) ? -1 : 1;
43
+ }
44
+ export function compareVersions(a, b) {
45
+ const pa = parseVersion(a);
46
+ const pb = parseVersion(b);
47
+ if (!pa || !pb) {
48
+ const sa = String(a ?? '');
49
+ const sb = String(b ?? '');
50
+ return sa === sb ? 0 : sa < sb ? -1 : 1;
51
+ }
52
+ for (const key of ['major', 'minor', 'patch']) {
53
+ if (pa[key] !== pb[key])
54
+ return pa[key] < pb[key] ? -1 : 1;
55
+ }
56
+ if (pa.prerelease.length === 0 && pb.prerelease.length === 0)
57
+ return 0;
58
+ if (pa.prerelease.length === 0)
59
+ return 1;
60
+ if (pb.prerelease.length === 0)
61
+ return -1;
62
+ const length = Math.max(pa.prerelease.length, pb.prerelease.length);
63
+ for (let i = 0; i < length; i += 1) {
64
+ const left = pa.prerelease[i];
65
+ const right = pb.prerelease[i];
66
+ if (left === undefined)
67
+ return -1;
68
+ if (right === undefined)
69
+ return 1;
70
+ const result = compareIdentifiers(left, right);
71
+ if (result !== 0)
72
+ return result;
73
+ }
74
+ return 0;
75
+ }
76
+ export function versionsEqual(a, b) {
77
+ return compareVersions(normalizeVersion(a), normalizeVersion(b)) === 0;
78
+ }
79
+ export function versionParity(localVersion, remoteVersion) {
80
+ if (!localVersion || !remoteVersion) {
81
+ return {
82
+ status: 'unknown',
83
+ local: localVersion ?? null,
84
+ remote: remoteVersion ?? null,
85
+ same: false,
86
+ message: {
87
+ zh: '无法确定版本一致性(缺少本机或远端版本)。',
88
+ en: 'Version parity is unknown (a local or remote version is missing).',
89
+ },
90
+ };
91
+ }
92
+ const same = versionsEqual(localVersion, remoteVersion);
93
+ return {
94
+ status: same ? 'same' : 'different',
95
+ local: normalizeVersion(localVersion),
96
+ remote: normalizeVersion(remoteVersion),
97
+ same,
98
+ message: same
99
+ ? { zh: '远端与本机 DSH 版本一致。', en: 'The remote DSH version matches this machine.' }
100
+ : {
101
+ zh: `远端 DSH(${normalizeVersion(remoteVersion)})与本机(${normalizeVersion(localVersion)})不一致。`,
102
+ en: `Remote DSH (${normalizeVersion(remoteVersion)}) differs from this machine (${normalizeVersion(localVersion)}).`,
103
+ },
104
+ };
105
+ }
106
+ export const MIN_NODE_VERSION = '24.9.0';
107
+ export function isNodeVersionSupported(version) {
108
+ if (!version)
109
+ return false;
110
+ // node -v prints "v24.22.2"; a bare "24" from a fallback should not pass.
111
+ if (!parseVersion(version))
112
+ return false;
113
+ return compareVersions(normalizeVersion(version), MIN_NODE_VERSION) >= 0;
114
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Create the one bus a service instance owns.
3
+ * @param options - only the warn sink for a listener that throws.
4
+ * @returns the bus.
5
+ */
6
+ export function createWatchdogBus(options = {}) {
7
+ const listeners = new Set();
8
+ return {
9
+ publish(event) {
10
+ // Snapshot: a listener that (un)subscribes while handling an event must not change the
11
+ // iteration of the event being published.
12
+ for (const listener of [...listeners]) {
13
+ try {
14
+ listener(event);
15
+ }
16
+ catch (error) {
17
+ // A listener failure must never break the probe that published the event.
18
+ options.warn?.('[dsh-remote-go] watchdog listener failed:', error);
19
+ }
20
+ }
21
+ },
22
+ subscribe(listener) {
23
+ listeners.add(listener);
24
+ return () => {
25
+ listeners.delete(listener);
26
+ };
27
+ },
28
+ };
29
+ }
@@ -0,0 +1,156 @@
1
+ /**
2
+ * The liveness watchdog: the heartbeat probe, the episode it opens when the remote UI stops
3
+ * answering, and the two action requests it turns into bus events (design-arch §1.7).
4
+ *
5
+ * It used to live inside `host-lifecycle.ts` and reach its one-shot actions back through `ctx`
6
+ * (`requestReattach`/`repairTunnel`). Those reverse callbacks are gone: a confirmed or recovered
7
+ * episode is published on `ctx.bus`, and `connect/watchdog.ts` — the bus's only subscriber — runs
8
+ * the action. The dependency arrow therefore points one way only: this module never imports
9
+ * `connect/*`, so the modules that dispatch `arm(heartbeat)` do not create a cycle.
10
+ *
11
+ * The two timer *primitives* (`stopRemoteHeartbeat`/`cancelRemoteCheck`) stay in
12
+ * `host-lifecycle.ts`, the owner of the runtime's timer block; the policy that fills them lives
13
+ * here.
14
+ */
15
+ import { REMOTE_EPISODE_COOLDOWN_MS, REMOTE_HEARTBEAT_DEFAULT_SEC, REMOTE_HEARTBEAT_MAX_SEC, REMOTE_HEARTBEAT_MIN_SEC, REMOTE_UNREACHABLE_FAILURES, } from './constants.js';
16
+ import { cancelRemoteCheck, stopRemoteHeartbeat } from './host-lifecycle.js';
17
+ import { isUiUp } from './remote-proc.js';
18
+ /** Milliseconds between liveness probes, from settings (default 30s, disabled allowed). */
19
+ export function remoteHeartbeatIntervalSec(ctx) {
20
+ const raw = ctx.settings()?.remoteHeartbeat;
21
+ const seconds = Number(raw?.intervalSec);
22
+ if (!Number.isFinite(seconds))
23
+ return REMOTE_HEARTBEAT_DEFAULT_SEC;
24
+ return Math.min(REMOTE_HEARTBEAT_MAX_SEC, Math.max(REMOTE_HEARTBEAT_MIN_SEC, Math.round(seconds)));
25
+ }
26
+ /** Start the light liveness probe for a host that just became connected. */
27
+ export function startRemoteHeartbeat(ctx, runtime) {
28
+ stopRemoteHeartbeat(runtime);
29
+ const enabled = ctx.settings()?.remoteHeartbeat?.enabled !== false;
30
+ if (!enabled) {
31
+ ctx.progress.log(runtime, 'debug', 'remote heartbeat: disabled by settings');
32
+ return;
33
+ }
34
+ const intervalSec = remoteHeartbeatIntervalSec(ctx);
35
+ runtime.heartbeatTimer = setInterval(() => {
36
+ void remoteHeartbeatTick(ctx, runtime);
37
+ }, intervalSec * 1000);
38
+ runtime.heartbeatTimer.unref?.();
39
+ ctx.progress.log(runtime, 'debug', `remote heartbeat: probing every ${intervalSec}s`);
40
+ }
41
+ /** A host is watchable only while it is really up and no one-shot action owns the link. */
42
+ export function watchable(ctx, runtime) {
43
+ return (ctx.state.disposed !== true &&
44
+ runtime.desired === 'connected' &&
45
+ runtime.status === 'connected' &&
46
+ runtime.linkBusy === null &&
47
+ runtime.ssh?.connected === true &&
48
+ runtime.tunnel !== null);
49
+ }
50
+ /**
51
+ * Open a liveness episode at most once. Transient reports (a proxy/tunnel failure) are
52
+ * coalesced: after a confirmed-healthy episode the same kind of report is ignored for a
53
+ * cooldown window, so a flapping tunnel cannot emit suspected/recovered on every request.
54
+ * Returns whether a new episode was opened.
55
+ */
56
+ function beginRemoteEpisode(ctx, runtime, source) {
57
+ if (runtime.remoteEpisode === true)
58
+ return false;
59
+ const transient = source === 'proxy' || source === 'tunnel';
60
+ if (transient && Date.now() < (Number(runtime.episodeCooldownUntil) || 0)) {
61
+ ctx.progress.log(runtime, 'debug', `remote-unreachable reported again (${source}); episode cooldown, ignoring`);
62
+ return false;
63
+ }
64
+ runtime.remoteEpisode = true;
65
+ runtime.episodeSource = source;
66
+ ctx.progress.log(runtime, 'debug', `remote-unreachable suspected (${source}); confirming with probes`);
67
+ ctx.onRemoteUnreachable?.(runtime, { phase: 'suspected', source });
68
+ return true;
69
+ }
70
+ /**
71
+ * Reset the failure streak and close the episode. The recovery *action* (probe the local
72
+ * listener, rebuild it when needed, announce the episode) belongs to the bus subscriber:
73
+ * `connect/watchdog.ts` runs it and publishes `recovered` once the link is usable again, which is
74
+ * the same point in the sequence the old inline code announced it at.
75
+ */
76
+ function clearRemoteEpisode(ctx, runtime, source) {
77
+ const wasOpen = runtime.remoteEpisode === true;
78
+ const transient = runtime.episodeSource === 'proxy' || runtime.episodeSource === 'tunnel';
79
+ runtime.remoteEpisode = false;
80
+ runtime.remoteFailures = 0;
81
+ if (!wasOpen)
82
+ return;
83
+ runtime.episodeSource = null;
84
+ if (transient)
85
+ runtime.episodeCooldownUntil = Date.now() + REMOTE_EPISODE_COOLDOWN_MS;
86
+ ctx.bus.publish({ kind: 'recovered', hostId: runtime.id, source });
87
+ }
88
+ function scheduleRemoteCheck(ctx, runtime, source, delayMs) {
89
+ if (runtime.remoteCheckTimer)
90
+ return;
91
+ runtime.remoteCheckTimer = setTimeout(() => {
92
+ runtime.remoteCheckTimer = null;
93
+ void checkRemoteNow(ctx, runtime, source);
94
+ }, delayMs);
95
+ runtime.remoteCheckTimer.unref?.();
96
+ }
97
+ /**
98
+ * Probe the connected host once and feed the consecutive-failure counter. One
99
+ * failed request is not a restart: the counter has to reach
100
+ * {@link REMOTE_UNREACHABLE_FAILURES} before a re-attach is requested.
101
+ */
102
+ async function checkRemoteNow(ctx, runtime, source) {
103
+ if (!watchable(ctx, runtime) || typeof ctx.deps.remoteStatus !== 'function')
104
+ return;
105
+ const ssh = runtime.ssh;
106
+ const port = runtime.remote.port;
107
+ let status = null;
108
+ try {
109
+ status = await ctx.deps.remoteStatus(ssh, port);
110
+ }
111
+ catch {
112
+ // swallow-ok: an unreachable probe is a failed probe, handled by the same counter
113
+ status = null;
114
+ }
115
+ // The transport may have gone away while the probe was in flight; the close handler owns that.
116
+ if (!watchable(ctx, runtime) || runtime.ssh !== ssh)
117
+ return;
118
+ if (isUiUp(status)) {
119
+ clearRemoteEpisode(ctx, runtime, source);
120
+ return;
121
+ }
122
+ runtime.remoteFailures = (Number(runtime.remoteFailures) || 0) + 1;
123
+ ctx.progress.log(runtime, 'debug', `remote heartbeat: probe failed (HTTP ${status ?? 'none'}), ${runtime.remoteFailures}/${REMOTE_UNREACHABLE_FAILURES} (${source})`);
124
+ beginRemoteEpisode(ctx, runtime, source);
125
+ if (runtime.remoteFailures < REMOTE_UNREACHABLE_FAILURES) {
126
+ scheduleRemoteCheck(ctx, runtime, source, ctx.timers.remoteRecheckMs);
127
+ return;
128
+ }
129
+ ctx.progress.log(runtime, 'warn', `remote-unreachable: ${runtime.remoteFailures} consecutive probes failed (${source}); re-attaching`);
130
+ ctx.onRemoteUnreachable?.(runtime, {
131
+ phase: 'confirmed',
132
+ source,
133
+ failures: runtime.remoteFailures,
134
+ });
135
+ cancelRemoteCheck(runtime);
136
+ ctx.bus.publish({ kind: 'confirmed', hostId: runtime.id, reason: `probe-failed-${runtime.remoteFailures}`, source });
137
+ }
138
+ /** One scheduled heartbeat tick. */
139
+ export async function remoteHeartbeatTick(ctx, runtime) {
140
+ if (!watchable(ctx, runtime))
141
+ return;
142
+ if (runtime.remoteCheckTimer)
143
+ return;
144
+ await checkRemoteNow(ctx, runtime, 'heartbeat');
145
+ }
146
+ /**
147
+ * A proxy or tunnel failure was observed: report the episode once and confirm it
148
+ * with probes instead of treating one failed request as a remote restart.
149
+ */
150
+ export function noteRemoteUnreachable(ctx, runtime, source) {
151
+ if (!watchable(ctx, runtime))
152
+ return;
153
+ if (!beginRemoteEpisode(ctx, runtime, source))
154
+ return;
155
+ scheduleRemoteCheck(ctx, runtime, source, ctx.timers.remoteConfirmDelayMs);
156
+ }
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
- /**
2
- * Package entry for the DSH Loader. The implementation lives in `src/`.
3
- */
4
- export { apply, inject, name, optional } from './src/index.js'
1
+ // The Cordis loader resolves a linked plugin by its directory entry (`<dir>/index.js`), not
2
+ // through package exports, so a `link:` install needs this file to exist. It is a one-line shim:
3
+ // the implementation is the build output in `dist/`, and `exports["."]` names the same file for
4
+ // consumers that resolve by exports.
5
+ export { apply, inject, name, optional } from './dist/index.js'
package/locale/en.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
- "title": "dsh remote go",
4
- "description": "Use a remote DSH over SSH in the whole window of the local DSH: one sidebar switcher moves between “Local” and each host, and a connected remote comes back instantly. The remote runs on a plugin-managed Node with npx pinned to the local version, keeps its data in the user’s own ~/.dsh, and ships the connect log and diagnostics."
3
+ "title": "dsh-remote-go",
4
+ "description": "Use a remote DSH over SSH inside your local DSH: the sidebar host bar switches between Local and each host, the remote UI takes over the whole window and comes back without reloading; the connect flow shows staged progress and a live log, and you can restart or stop the remote DSH, download remote files and folders, and give local AI sessions a host list, a diagnosis report and a guarded remote command (hidden until the session unlocks them). The remote runs on a plugin-managed Node with npx pinned to the local version, keeping its data in the remote ~/.dsh."
5
5
  }
6
6
  }
package/locale/zh.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
- "title": "dsh remote go",
4
- "description": "通过 SSH 在本地 DSH 的整窗里使用远端 DSH:侧边栏主机条在「本地」与各主机间切换,已连接的远端一点即回;远端由插件自托管的 Node 加 npx 按本机版本启动,数据留在远端用户自己的 ~/.dsh,含连接日志与诊断。"
3
+ "title": "dsh-remote-go",
4
+ "description": "在本地 DSH 里通过 SSH 使用远端 DSH:侧边栏主机条在「本地」与各主机间切换,远端界面整窗接管、切回不重载;连接过程有阶段进度和实时日志,可重启/关闭远端 DSH、下载远端文件与文件夹,并向本地 AI 会话提供主机清单、体检报告与受控远端命令(默认隐藏,按需解锁)。远端由插件自带的 Node + npx 按本机版本启动,数据留在远端 ~/.dsh。"
5
5
  }
6
6
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-remote-go",
3
- "version": "0.1.0",
4
- "description": "DSH 插件:通过 SSH 在本地 DSH 的整窗里使用远端 DSH(主机条切换、插件托管 Node + npx 固定本机版本、数据留在远端 ~/.dsh) | DSH plugin: use a remote DSH over SSH in the whole local window with one host switcher; the remote runs on a plugin-managed Node with npx pinned to the local version and keeps its data in the remote ~/.dsh",
3
+ "version": "0.3.0",
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",
7
7
  "harness",
@@ -28,19 +28,19 @@
28
28
  "node": ">=24"
29
29
  },
30
30
  "sideEffects": [
31
- "./client.js"
31
+ "./dist/client.js"
32
32
  ],
33
+ "main": "./index.js",
33
34
  "exports": {
34
35
  ".": "./index.js",
35
- "./client": "./client.js",
36
+ "./client": "./dist/client.js",
36
37
  "./locale/*.json": "./locale/*.json",
37
38
  "./package.json": "./package.json"
38
39
  },
39
40
  "files": [
40
41
  "index.js",
41
- "client.js",
42
- "src",
43
- "vendor",
42
+ "dist",
43
+ "vendor/THIRD_PARTY_NOTICES.md",
44
44
  "locale",
45
45
  "cordis.patch.yml",
46
46
  "README.md",
@@ -65,36 +65,55 @@
65
65
  },
66
66
  "dependencies": {},
67
67
  "devDependencies": {
68
- "@deepseek-ai/dsh-plugin-market-index": "0.2.2-rc.2",
69
- "esbuild": "^0.28.2",
68
+ "@types/node": "^24.19.2",
69
+ "@types/react": "^19.3.0",
70
+ "esbuild": "0.28.2",
70
71
  "js-yaml": "^5.5.0",
71
- "prettier": "^3.10.0",
72
+ "prettier": "^3.10.1",
72
73
  "puppeteer-core": "^25.17.0",
73
74
  "react": "^19.3.1",
74
75
  "react-dom": "^19.3.1",
75
- "ssh2": "1.17.0"
76
+ "ssh2": "1.17.0",
77
+ "typescript": "^5.9.3"
76
78
  },
77
79
  "scripts": {
78
- "test": "node --test \"test/unit/*.test.js\"",
79
- "test:unit": "node --test \"test/unit/*.test.js\"",
80
- "test:web": "node --test \"test/integration/web.e2e.js\"",
81
- "test:desktop": "node --test \"test/integration/desktop.e2e.js\"",
82
- "test:integration": "node --test \"test/integration/*.test.js\" \"test/integration/*.e2e.js\"",
80
+ "pretest": "pnpm build",
81
+ "test": "node --test \"test/unit/*.test.ts\"",
82
+ "pretest:unit": "pnpm build",
83
+ "test:unit": "node --test \"test/unit/*.test.ts\"",
84
+ "pretest:web": "pnpm build",
85
+ "test:web": "node --test \"test/integration/web.e2e.ts\"",
86
+ "pretest:desktop": "pnpm build",
87
+ "test:desktop": "node --test \"test/integration/desktop.e2e.ts\"",
88
+ "pretest:integration": "pnpm build",
89
+ "test:integration": "node --test --test-concurrency=1 \"test/integration/*.test.ts\" \"test/integration/*.e2e.ts\"",
90
+ "pretest:integration:local": "pnpm build",
91
+ "test:integration:local": "node --test --test-concurrency=1 test/integration/sim.test.ts test/integration/remote-restart.test.ts test/integration/stop-remote.test.ts",
92
+ "pretest:integration:external": "pnpm build",
93
+ "test:integration:external": "node --test --test-concurrency=1 test/integration/client-ui.test.ts test/integration/remote-proxy.test.ts test/integration/web.e2e.ts test/integration/browser-carrier.test.ts test/integration/guest-tools.e2e.ts test/integration/stop-remote.browser.test.ts",
94
+ "presim:remote": "pnpm build",
83
95
  "sim:remote": "node e2e/sim/simulated-remote.mjs --self-test",
84
- "test:coverage": "node --test --experimental-test-coverage --test-coverage-exclude=vendor/** --test-coverage-exclude=test/** --test-coverage-lines=85 --test-coverage-branches=70 --test-coverage-functions=80 \"test/unit/*.test.js\"",
96
+ "pretest:coverage": "pnpm build",
97
+ "test:coverage": "node scripts/check-coverage.mjs",
85
98
  "lint": "node scripts/check-repo.mjs",
86
99
  "check:repo": "node scripts/check-repo.mjs",
100
+ "check:arch": "node scripts/check-architecture.mjs",
87
101
  "check:syntax": "node scripts/check-syntax.mjs",
88
102
  "check:workflows": "node scripts/check-workflows.mjs",
89
103
  "check:pr-title": "node scripts/check-pr-title.mjs",
90
104
  "format": "prettier --write .",
91
105
  "format:check": "prettier --check .",
92
- "verify": "node scripts/check-repo.mjs && prettier --check . && node scripts/check-syntax.mjs && node scripts/check-workflows.mjs && node scripts/market-entry.mjs --check && node scripts/pack-check.mjs && node --test \"test/unit/*.test.js\" && node --test --test-concurrency=1 \"test/integration/*.test.js\" \"test/integration/*.e2e.js\"",
106
+ "gate": "pnpm build && node scripts/check-repo.mjs && node scripts/check-architecture.mjs && prettier --check . && node scripts/check-syntax.mjs && node scripts/check-workflows.mjs && node scripts/pack-check.mjs && node scripts/verify-artifacts.mjs && pnpm run verify:types && node scripts/check-coverage.mjs && pnpm pack --pack-destination artifacts && node scripts/pack-check.mjs --find artifacts",
107
+ "verify": "pnpm build && node scripts/check-repo.mjs && node scripts/check-architecture.mjs && prettier --check . && node scripts/check-syntax.mjs && node scripts/check-workflows.mjs && node scripts/pack-check.mjs && node scripts/verify-artifacts.mjs && pnpm run verify:types && node scripts/check-coverage.mjs && node --test --test-concurrency=1 \"test/integration/*.test.ts\" \"test/integration/*.e2e.ts\"",
108
+ "build": "node scripts/build.mjs && node scripts/build-client.mjs",
109
+ "clean": "node scripts/clean.mjs",
110
+ "build:client": "node scripts/build-client.mjs",
111
+ "typecheck:client": "node node_modules/typescript/bin/tsc -p client/tsconfig.json --noEmit",
112
+ "verify:artifacts": "node scripts/verify-artifacts.mjs",
113
+ "verify:types": "node scripts/build.mjs --noEmit && pnpm run typecheck:client && node scripts/check-types.mjs --stage P7 --strict",
93
114
  "build:vendor": "node scripts/build-vendor.mjs",
94
- "market:entry": "node scripts/market-entry.mjs",
95
- "market:check": "node scripts/market-entry.mjs --check",
96
115
  "pack:check": "node scripts/pack-check.mjs",
97
116
  "pack:check:tarball": "node scripts/pack-check.mjs --find artifacts",
98
- "prepack": "node scripts/market-entry.mjs --check"
117
+ "prepack": "node scripts/build-vendor.mjs && git diff --exit-code -- vendor/ && pnpm build && node scripts/verify-artifacts.mjs"
99
118
  }
100
119
  }
@@ -1,10 +1,36 @@
1
1
  # Third-party notices
2
2
 
3
+ The published plugin has no runtime dependencies; the only third-party code it ships is
4
+ vendored below. This file is generated by `scripts/build-vendor.mjs`; do not edit by hand.
5
+
3
6
  ## ssh2
4
7
 
5
8
  - Package: `ssh2` (MIT)
6
9
  - Source: https://github.com/mscdex/ssh2
7
10
  - Bundled file: `vendor/ssh2.bundle.cjs` (329 KiB, minified)
8
- - License text: see https://github.com/mscdex/ssh2/blob/master/LICENSE
11
+
12
+ License text from `node_modules/ssh2/LICENSE`:
13
+
14
+ ```text
15
+ Copyright Brian White. All rights reserved.
16
+
17
+ Permission is hereby granted, free of charge, to any person obtaining a copy
18
+ of this software and associated documentation files (the "Software"), to
19
+ deal in the Software without restriction, including without limitation the
20
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
21
+ sell copies of the Software, and to permit persons to whom the Software is
22
+ furnished to do so, subject to the following conditions:
23
+
24
+ The above copyright notice and this permission notice shall be included in
25
+ all copies or substantial portions of the Software.
26
+
27
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
32
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
33
+ IN THE SOFTWARE.
34
+ ```
9
35
 
10
36
  The bundle excludes the optional native accelerator `cpu-features`; ssh2 uses its pure-JavaScript fallback then.