dsh-remote 0.8.93 → 0.8.94

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/lib/boot.js ADDED
@@ -0,0 +1,42 @@
1
+ // dsh-remote — package entry point (package.json "main" / exports["."]).
2
+ //
3
+ // A thin shell around the real plugin body (lib/index.js). Its only job is to
4
+ // give the startup self-repair somewhere to live: ES module imports HOIST, so
5
+ // code placed inside index.js runs strictly after every static import of it
6
+ // has already been resolved — there is no room inside index.js to react to a
7
+ // missing sibling file. Dynamic import() is the only place such a guard can
8
+ // sit, hence this indirection.
9
+ //
10
+ // What happens here (see lib/self-heal.js for the policy):
11
+ // import('./index.js') → on a missing-own-file crash (the half-updated
12
+ // 0.8.92 scenario, issue #126) the CURRENT version's tarball is re-laid from
13
+ // npm and the import retried once. Healthy installs pay zero overhead: one
14
+ // extra dynamic import of the same file the host would have loaded anyway.
15
+ //
16
+ // ★ TWO INVARIANTS protect this file:
17
+ // 1. Stay minimal and self-contained — only import lib/self-heal.js (which
18
+ // only imports lib/update.js + node builtins). Anything richer could be
19
+ // the file that is missing.
20
+ // 2. Re-export index.js's public surface EXACTLY. The cordis loader, the
21
+ // settings UI and tests consume these names; test/self-heal-boot.test.js
22
+ // pins the key set so index.js cannot gain an export this shell forgets
23
+ // to forward.
24
+
25
+ import { importWithSelfHeal } from './self-heal.js'
26
+
27
+ const { module: main, repaired } = await importWithSelfHeal(() => import('./index.js'))
28
+
29
+ if (repaired) {
30
+ console.warn('[dsh-remote] startup self-repair succeeded — the incomplete update has been fully re-applied and this boot is healthy')
31
+ }
32
+
33
+ export const name = main.name
34
+ export const DEFAULT_UPDATE_MODE = main.DEFAULT_UPDATE_MODE
35
+ export const decodePickStdout = main.decodePickStdout
36
+ export const win32FolderPickScript = main.win32FolderPickScript
37
+ export const LOCAL_BOOTSTRAP_TOOLS = main.LOCAL_BOOTSTRAP_TOOLS
38
+ export const normalizeLocalTools = main.normalizeLocalTools
39
+ export const pickWorkspaceNextStep = main.pickWorkspaceNextStep
40
+ export const inject = main.inject
41
+ export const Config = main.Config
42
+ export const apply = main.apply
package/lib/client.js CHANGED
@@ -280,7 +280,7 @@ window.__ModuleLoader__.load({
280
280
  'settings.checkUpdate': '检查更新',
281
281
  'settings.updateNow': '立即更新',
282
282
  'settings.updateMode': '更新模式:',
283
- 'settings.explorerAutoOpen': '打开远程工作区时,自动在侧边栏展开「远程文件」(需安装 better-sidebar)',
283
+ 'settings.explorerAutoOpen': '打开远程工作区时,自动在侧边栏展开「远程文件」',
284
284
  'settings.updateManual': '手动',
285
285
  'settings.updateAuto': '自动',
286
286
  'settings.updateOff': '关闭',
@@ -609,7 +609,7 @@ window.__ModuleLoader__.load({
609
609
  'settings.checkUpdate': 'Check for updates',
610
610
  'settings.updateNow': 'Update now',
611
611
  'settings.updateMode': 'Update mode:',
612
- 'settings.explorerAutoOpen': 'Auto-open the Remote Files sidebar tab for remote workspaces (via better-sidebar)',
612
+ 'settings.explorerAutoOpen': 'Auto-open the Remote Files sidebar tab for remote workspaces',
613
613
 
614
614
  'settings.updateManual': 'Manual',
615
615
  'settings.updateAuto': 'Auto',
@@ -1123,6 +1123,20 @@ window.__ModuleLoader__.load({
1123
1123
  const pad = (x) => String(x).padStart(2, '0')
1124
1124
  return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`
1125
1125
  }
1126
+ // Audit lines arrive with a leading UTC ISO stamp (the on-disk format stays
1127
+ // UTC — sortable and machine-comparable across timezones). Render it in the
1128
+ // user's LOCAL timezone like the file browser's mtime (fmtTime above), so
1129
+ // "when did that command run" needs no mental +N conversion. Seconds are
1130
+ // kept: command ordering inside a minute matters for audit reading.
1131
+ // Unparseable lines render unchanged (issue #124).
1132
+ function fmtAuditLine(line) {
1133
+ return String(line).replace(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z/, (iso) => {
1134
+ const d = new Date(iso)
1135
+ if (isNaN(d.getTime())) return iso
1136
+ const pad = (x) => String(x).padStart(2, '0')
1137
+ return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
1138
+ })
1139
+ }
1126
1140
 
1127
1141
  // Write text to the clipboard. Order: the host primitive (its behavior is
1128
1142
  // the reference), then the async Clipboard API (works on http://127.0.0.1
@@ -2058,7 +2072,7 @@ window.__ModuleLoader__.load({
2058
2072
  auditMsg ? React.createElement('div', { style: { fontSize: 11, marginBottom: 4, lineHeight: 1.5, wordBreak: 'break-all', color: /无法|failed|error/i.test(auditMsg) ? T.warn : T.ok } }, auditMsg) : null,
2059
2073
  auditLines.length
2060
2074
  ? React.createElement('div', { style: { maxHeight: 180, overflowY: 'auto', fontSize: 11, fontFamily: 'monospace', lineHeight: 1.6 } },
2061
- auditLines.map((l, i) => React.createElement('div', { key: i, style: { whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' } }, l)))
2075
+ auditLines.map((l, i) => React.createElement('div', { key: i, title: String(l), style: { whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' } }, fmtAuditLine(l))))
2062
2076
  : React.createElement('div', { style: { opacity: 0.6, fontSize: 12 } }, tr('settings.auditEmpty')))
2063
2077
  : React.createElement('div', { style: { fontSize: 11, opacity: 0.55 } }, String(auditLines.length)),
2064
2078
  ),
@@ -0,0 +1,130 @@
1
+ // dsh-remote — startup self-repair for an incompletely applied update.
2
+ //
3
+ // The failure this wards off (0.8.92, issue #126): the updater at the time
4
+ // installed only top-level `lib/*.js`, so a release that added `.cjs` helpers
5
+ // or `lib/` subdirectories produced a half-updated tree. The next boot died at
6
+ // import time with ERR_MODULE_NOT_FOUND — and because the updater lives INSIDE
7
+ // the plugin, a plugin that cannot be imported can never repair itself. Every
8
+ // rw_* tool, the terminal, web attach and forwarding simply vanished, for good.
9
+ //
10
+ // This module is the outermost line of defence: lib/boot.js (the package
11
+ // entry) runs it BEFORE loading the real plugin body, detects the
12
+ // "missing own file" crash, re-downloads the CURRENT version's tarball from
13
+ // npm and lays the full file tree down, then retries the import exactly once.
14
+ //
15
+ // ★ HARD CONSTRAINT — this module must stay self-contained within the package:
16
+ // it may only import node builtins and lib/update.js (which is likewise
17
+ // self-contained). Any richer import could itself be the file that is missing,
18
+ // and then the guard dies together with the guarded.
19
+
20
+ import { readFileSync } from 'node:fs'
21
+ import path from 'node:path'
22
+
23
+ import { applyUpdate, isInstalledCopy, diskVersion } from './update.js'
24
+
25
+ /**
26
+ * Whether `err` is the specific crash a half-applied update produces: Node
27
+ * could not find a file belonging to THIS package.
28
+ *
29
+ * Deliberately narrower than "any load failure":
30
+ * - `Cannot find package '…'` names an external dependency — a tarball re-lay
31
+ * cannot fix the host environment, so we do not even try;
32
+ * - `Cannot find module '…'` (relative specifier or absolute path) is the
33
+ * signature of our own file being absent — repairable;
34
+ * - an ERR_MODULE_NOT_FOUND whose message matches neither is treated as
35
+ * repairable too: the worst case is one doomed download followed by an
36
+ * honest combined error, while missing a repairable case strands the user.
37
+ * @param err - anything thrown by a failed dynamic import().
38
+ */
39
+ export function isMissingOwnModuleError(err) {
40
+ if (!err || typeof err !== 'object') return false
41
+ if (err.code !== 'ERR_MODULE_NOT_FOUND') return false
42
+ const msg = String(err.message || '')
43
+ if (/Cannot find package/.test(msg)) return false
44
+ return true
45
+ }
46
+
47
+ /**
48
+ * Re-lay the CURRENTLY INSTALLED version's full file tree from npm, healing a
49
+ * half-applied update in place. Uses the version from the on-disk package.json
50
+ * (in a half-updated tree that file HAS landed, so it names exactly the
51
+ * version whose lib/ got mangled). Thin wrapper over applyUpdate(); the same
52
+ * refusal rules apply (non-installed copies must be passed an explicit dir).
53
+ * @param options - forwarded to applyUpdate ({dir, fetchImpl} for tests);
54
+ * when options.dir is set, the version is read from THAT directory's
55
+ * package.json rather than this package's own install dir.
56
+ */
57
+ export async function repairInstall(options = {}) {
58
+ let version = diskVersion()
59
+ if (options.dir) {
60
+ try {
61
+ version = String(JSON.parse(readFileSync(path.join(options.dir, 'package.json'), 'utf8')).version || '')
62
+ } catch {
63
+ version = ''
64
+ }
65
+ }
66
+ if (!/^\d+\.\d+\.\d+/.test(version)) {
67
+ throw new Error(`cannot self-repair: on-disk package.json version is unusable (${JSON.stringify(version)})`)
68
+ }
69
+ return applyUpdate(version, options)
70
+ }
71
+
72
+ /** Actionable suffix attached to every failure we hand back to the user. */
73
+ const REINSTALL_HINT = 'please reinstall the plugin once (e.g. `dsh plugin --profile <profile> add dsh-remote@latest`) — a damaged install cannot always heal itself'
74
+
75
+ /**
76
+ * Import the plugin body, repairing the install in between when the first
77
+ * attempt dies from a missing own-file.
78
+ *
79
+ * Order of operations (every exit path is deliberate):
80
+ * 1. `await importer()` succeeds → `{ module, repaired: false }`;
81
+ * 2. failure that is NOT a missing-own-module crash → rethrow untouched
82
+ * (a genuine code bug must not be masked by a pointless download);
83
+ * 3. missing-own-module but this copy is not an installed one → rethrow
84
+ * (never touch a source checkout; same contract as applyUpdate, where an
85
+ * explicit options.dir opts out for tests);
86
+ * 4. otherwise repairInstall() → retry the import ONCE → success becomes
87
+ * `{ module, repaired: true }`; a second failure throws a combined error
88
+ * naming BOTH the original crash and the repair outcome plus the
89
+ * reinstall hint, with `cause` chaining the second import error.
90
+ *
91
+ * @param importer - zero-arg function performing `import('<the real entry>')`.
92
+ * @param options - `{ log?, dir?, fetchImpl? }` — dir/fetchImpl are test seams
93
+ * forwarded to applyUpdate; log defaults to console.warn.
94
+ */
95
+ export async function importWithSelfHeal(importer, options = {}) {
96
+ const { log = console.warn, ...repairOpts } = options || {}
97
+ let firstErr
98
+ try {
99
+ return { module: await importer(), repaired: false }
100
+ } catch (err) {
101
+ firstErr = err
102
+ }
103
+ if (!isMissingOwnModuleError(firstErr)) throw firstErr
104
+ if (!repairOpts.dir && !isInstalledCopy()) throw firstErr
105
+
106
+ const version = repairOpts.dir ? '(test dir)' : `v${diskVersion()}`
107
+ log(`[dsh-remote] startup crashed on a missing package file (${firstErr.message.split('\n')[0]}) — the last self-update looks incomplete; re-downloading ${version} from npm to repair the install`)
108
+
109
+ let repairOutcome
110
+ try {
111
+ repairOutcome = await repairInstall(repairOpts)
112
+ } catch (repairErr) {
113
+ const wrapped = new Error(
114
+ `[dsh-remote] automatic startup repair FAILED (${(repairErr && repairErr.message) || repairErr}); original error: ${firstErr.message.split('\n')[0]}. ${REINSTALL_HINT}`,
115
+ )
116
+ wrapped.cause = repairErr
117
+ throw wrapped
118
+ }
119
+ log(`[dsh-remote] startup repair applied ${repairOutcome.changed?.length ?? 0} file(s); retrying the load`)
120
+
121
+ try {
122
+ return { module: await importer(), repaired: true }
123
+ } catch (secondErr) {
124
+ const wrapped = new Error(
125
+ `[dsh-remote] the install was re-laid from npm but loading still fails: ${(secondErr && secondErr.message) || secondErr}. ${REINSTALL_HINT}`,
126
+ )
127
+ wrapped.cause = secondErr
128
+ throw wrapped
129
+ }
130
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-remote",
3
- "version": "0.8.93",
3
+ "version": "0.8.94",
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>",
@@ -26,9 +26,9 @@
26
26
  "plugin"
27
27
  ],
28
28
  "type": "module",
29
- "main": "lib/index.js",
29
+ "main": "lib/boot.js",
30
30
  "exports": {
31
- ".": "./lib/index.js",
31
+ ".": "./lib/boot.js",
32
32
  "./client": "./lib/client.js",
33
33
  "./package.json": "./package.json",
34
34
  "./cordis.patch.yml": "./cordis.patch.yml"