dsh-wechat-remote 1.7.6 → 1.7.8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Agent远程管理助手 · DSH 插件安装器
2
2
 
3
- 当前版本为 1.7.6,安装同版本正式插件。改善全局安装及 npx 启动的识别,修复 ARM64 设备的一键更新误拦截。
3
+ 当前版本为 `1.7.8`,内嵌同版本正式插件。
4
4
 
5
5
  首次安装和升级旧插件使用同一个命令:
6
6
 
@@ -8,13 +8,13 @@
8
8
  npx -y dsh-wechat-remote@latest
9
9
  ```
10
10
 
11
- 请先按原来的方式启动 DSH WebUI,再在同一个系统用户下另开终端运行本命令。无需改成全局安装 DSH;使用 `npx @deepseek-ai/dsh web` 的用户也使用同一条安装命令。需要 Node.js 22.13 或更高版本,无需另装 pnpm 或 Git。
11
+ 在与 DSH 相同的系统用户下运行即可。无需改成全局安装 DSH;使用 `npx @deepseek-ai/dsh web` 的用户也使用同一条安装命令。需要 Node.js 22.13 或更高版本,无需另装 pnpm 或 Git。Windows CMD / PowerShell 推荐使用 `npx.cmd -y dsh-wechat-remote@latest`,不必修改脚本执行策略。
12
12
 
13
- 安装器安装正式插件,保留原配置、配对和会话,不会升级 DSH 本体。请先结束运行中的任务;安装完成后自动重启原 DSH 并尝试打开 WebUI。
13
+ 安装器保留原配置、配对和会话,不会升级 DSH 本体。请先结束运行中的任务;安装完成后自动重启原 DSH 并尝试打开 WebUI。DSH 已关闭时会尝试启动;若启动失败,按提示查看启动日志,不要删除原有数据。
14
14
 
15
15
  DSH 的新版本、预览版本或未登记的主机架构不会仅因缺少验证记录而被拒绝安装。安装器仍检查必要运行能力、安装包完整性和已知不兼容问题,并保留失败恢复所需的备份;无法确认恢复结果时会提示保留数据。这不代表所有宿主组合均已通过功能验证。
16
16
 
17
- 支持已验证的 DSH `0.1.1-rc.2`、`0.1.2-rc.1`、`0.1.5-rc.1`,Windows / macOS Intel / Linux x64。普通 Node 启动、独立的 macOS launchd 和 Linux 用户级 systemd 服务可自动恢复;无法确认启动方式时不自动停止主机。
17
+ 本版沿用此前已验证的跨平台安装方案,具体发行包与宿主组合以验收记录为准。普通 Node 启动、独立的 macOS launchd 和 Linux 用户级 systemd 服务有对应的自动恢复方式;无法确认启动方式时不自动停止主机。
18
18
 
19
19
  另已在 ARM64 Linux 电视盒子上验证 DSH `0.1.5-rc.1` 的首次安装、重复执行及重装。1.7.4 改善较慢主机启动时被误判为安装超时的问题;安装过程中请等待完成,勿重复执行命令。
20
20
 
@@ -22,4 +22,6 @@ DSH 的新版本、预览版本或未登记的主机架构不会仅因缺少验
22
22
 
23
23
  默认使用 `web` 配置和原来的 DSH 数据目录。自定义数据目录时,在新终端设置相同的 `DSH_HOME`,或附加 `--home "数据目录"`;使用其他配置时附加 `--profile 配置名称`。WSL、容器和其他系统用户内的 DSH,需要在对应环境中执行安装,不能跨环境替换。
24
24
 
25
- DSH 未启动且找到多个安装版本时,会要求选择,不会随意选一份。也可用 `--dsh-cli "DSH的lib/bin.js路径"` 明确指定。安装损坏需要重装时附加 `--repair`;不会自动降级。
25
+ DSH 正在运行时,优先连接它自己的安装接口;未运行时,优先使用当前终端默认的 DSH,再检查全局、当前项目和 NPX 缓存。只有存在多份缓存且没有默认选择时才询问。也可用 `--dsh-cli "DSH的lib/bin.js路径"` 明确指定。
26
+
27
+ 已运行的同版本插件卡在更新验证、尚未就绪时,重新执行命令会尝试修复。DSH 已退出或怀疑插件文件损坏时,附加 `--repair` 主动重装,不会自动降级。宿主本体或其他插件的故障仍可能需要另行处理;安装日志会保留,不必先删除会话或重新配对。
package/assets/plugin.tgz CHANGED
Binary file
@@ -1,17 +1,15 @@
1
1
  {
2
- "version": "1.7.6",
2
+ "version": "1.7.8",
3
3
  "catalog": {
4
4
  "schemaVersion": 1,
5
- "revision": "installer-1.7.6",
6
- "issuedAt": 1789480914884,
7
- "expiresAt": 1791900114884,
5
+ "revision": "installer-1.7.8",
6
+ "issuedAt": 1789590295076,
7
+ "expiresAt": 1792009495076,
8
8
  "releases": [
9
9
  {
10
- "version": "1.7.6",
10
+ "version": "1.7.8",
11
11
  "channel": "stable",
12
12
  "dsh": [
13
- "0.1.1-rc.2",
14
- "0.1.2-rc.1",
15
13
  "0.1.5-rc.1"
16
14
  ],
17
15
  "platforms": [
@@ -20,50 +18,13 @@
20
18
  "linux"
21
19
  ],
22
20
  "architectures": [
23
- "x64",
24
- "arm64"
21
+ "x64"
25
22
  ],
26
23
  "asset": {
27
- "url": "https://github.com/martinbear1/dsh-wechat-remote/releases/download/v1.7.6/harness-remote-dsh-wechat-remote-1.7.6.tgz",
28
- "sha256": "ddd14140e93eaf1704dcca7380b1f99d8243089c2be337eaf94d2e87de4a0ff5",
29
- "bytes": 9549941
30
- },
31
- "targets": [
32
- {
33
- "platform": "windows",
34
- "arch": "x64",
35
- "dsh": [
36
- "0.1.1-rc.2",
37
- "0.1.2-rc.1",
38
- "0.1.5-rc.1"
39
- ]
40
- },
41
- {
42
- "platform": "macos",
43
- "arch": "x64",
44
- "dsh": [
45
- "0.1.1-rc.2",
46
- "0.1.2-rc.1",
47
- "0.1.5-rc.1"
48
- ]
49
- },
50
- {
51
- "platform": "linux",
52
- "arch": "x64",
53
- "dsh": [
54
- "0.1.1-rc.2",
55
- "0.1.2-rc.1",
56
- "0.1.5-rc.1"
57
- ]
58
- },
59
- {
60
- "platform": "linux",
61
- "arch": "arm64",
62
- "dsh": [
63
- "0.1.5-rc.1"
64
- ]
65
- }
66
- ]
24
+ "url": "https://github.com/martinbear1/dsh-wechat-remote/releases/download/v1.7.8/harness-remote-dsh-wechat-remote-1.7.8.tgz",
25
+ "sha256": "bcadaf80e8a2dff008b421870bb42cad89d490178104df1f4d9103aa03cd62a6",
26
+ "bytes": 9554570
27
+ }
67
28
  }
68
29
  ],
69
30
  "blocked": [],
@@ -10,7 +10,8 @@ import { createInterface } from 'node:readline/promises'
10
10
 
11
11
  const execute = promisify(execFile)
12
12
  const PACKAGE = '@deepseek-ai/dsh'
13
- const clean = value => String(value).replace(/[\x00-\x1f\x7f-\x9f]/g, '')
13
+ const clean = value => String(value).replace(/[\x00-\x1f\x7f-\x9f]/g, '')
14
+ const environmentPath = env => env[Object.keys(env).find(key => key.toLowerCase() === 'path')] || ''
14
15
 
15
16
  export function validateDshCli(filename) {
16
17
  const cli = fs.realpathSync(path.resolve(filename))
@@ -36,7 +37,7 @@ export function resolveHome(value, fallback = os.homedir()) {
36
37
  async function npmLocation(key, env, cwd) {
37
38
  let npm = env.npm_execpath
38
39
  if (!npm || !fs.existsSync(npm)) {
39
- const roots = [path.dirname(process.execPath), ...(env.PATH || '').split(path.delimiter)]
40
+ const roots = [path.dirname(process.execPath), ...environmentPath(env).split(path.delimiter)]
40
41
  npm = roots.flatMap(dir => [path.join(dir, 'node_modules/npm/bin/npm-cli.js'),
41
42
  path.join(dir, '../lib/node_modules/npm/bin/npm-cli.js')]).find(file => fs.existsSync(file))
42
43
  }
@@ -58,7 +59,7 @@ export async function discoverDsh({ env = process.env, cwd = process.cwd(), cach
58
59
  if (!found.has(item.cli)) found.set(item.cli, { ...item, source })
59
60
  } catch { /* A missing/broken cache entry is not a usable DSH. */ }
60
61
  }
61
- for (const dir of (env.PATH || '').split(path.delimiter).filter(Boolean)) {
62
+ for (const dir of environmentPath(env).split(path.delimiter).filter(Boolean)) {
62
63
  add(path.join(dir, 'dsh'), 'PATH') // POSIX symlink, never execute a Windows shim.
63
64
  add(path.join(dir, 'node_modules/@deepseek-ai/dsh/lib/bin.js'), 'PATH')
64
65
  add(path.join(dir, '../lib/node_modules/@deepseek-ai/dsh/lib/bin.js'), 'PATH')
@@ -80,7 +81,9 @@ export async function discoverDsh({ env = process.env, cwd = process.cwd(), cach
80
81
  add(path.join(locations[1], 'lib/node_modules/@deepseek-ai/dsh/lib/bin.js'), 'npm-global')
81
82
  }
82
83
  const cacheRoot = locations[0]
83
- if (cacheRoot) {
84
+ // Cached NPX versions cannot supersede a normal default executable. Avoid
85
+ // probing a large/unreadable cache when the terminal already has that default.
86
+ if (cacheRoot && found.size === 0) {
84
87
  try {
85
88
  const entries = fs.readdirSync(path.join(cacheRoot, '_npx'), { withFileTypes: true })
86
89
  if (entries.length > 512) throw new Error('npx 缓存较多,请先启动要使用的 DSH,再运行安装命令。')
@@ -94,10 +97,17 @@ export async function discoverDsh({ env = process.env, cwd = process.cwd(), cach
94
97
 
95
98
  export async function chooseDsh(options = {}) {
96
99
  if (options.cli) return validateDshCli(options.cli).cli
97
- const candidates = await discoverDsh(options)
98
- if (!candidates.length) throw new Error('未找到 DSH。请先按原来的方式启动 DSH WebUI,再运行本命令。')
99
- if (candidates.length === 1) return candidates[0].cli
100
- // Multiple installed/cache versions are not evidence of the user's choice.
100
+ const candidates = await discoverDsh(options)
101
+ if (!candidates.length) throw new Error('未找到 DSH。请先按原来的方式启动 DSH WebUI,再运行本命令。')
102
+ // A stopped host has no handshake yet. Follow the terminal's ordinary DSH
103
+ // resolution before consulting old NPX cache entries; no version sorting or
104
+ // downloading. This fallback never overrides an already running host.
105
+ const normal = candidates.find(item => item.source === 'PATH')
106
+ || candidates.find(item => item.source === 'npm-global')
107
+ || candidates.find(item => item.source === 'project' || item.source === 'source')
108
+ if (normal) return normal.cli
109
+ if (candidates.length === 1) return candidates[0].cli
110
+ // Multiple cache-only versions are not evidence of the user's choice.
101
111
  // A live host normally bypasses this fallback via its native handshake.
102
112
  const prompt = options.prompt || (process.stdin.isTTY && process.stdout.isTTY ? async message => {
103
113
  const rl = createInterface({ input: process.stdin, output: process.stdout })
@@ -0,0 +1,44 @@
1
+ /** Verify a restored, plugin-free DSH through the same native control adapter.
2
+ * Only the first-install rollback uses this; ordinary updates probe the plugin.
3
+ * Bundled outside the profile so neither a failed add nor rollback removes it. */
4
+ import fs from 'node:fs'
5
+ import path from 'node:path'
6
+ import { randomBytes } from 'node:crypto'
7
+ import { attachControl, waitForJson } from './native-control.mjs'
8
+
9
+ export async function verifyNativeRestore(job, start, sessionIds, readableIds) {
10
+ const directory = path.join(job.home, 'harness-remote-updates', randomBytes(16).toString('hex'))
11
+ fs.mkdirSync(directory, { mode: 0o700 })
12
+ fs.writeFileSync(path.join(directory, 'package.json'), '{"type":"module"}\n', { mode: 0o600 })
13
+ const helper = path.join(directory, 'install-control.js'), token = randomBytes(24).toString('hex')
14
+ fs.copyFileSync(path.join(job.directory, 'install-control.js'), helper)
15
+ const remove = attachControl(job.profile, helper, { directory, token, pnpm: job.pnpm })
16
+ let ref
17
+ const request = async (method, payload = {}) => {
18
+ const response = await fetch(ref.origin + '/' + method, { method: 'POST', headers: {
19
+ authorization: `Bearer ${token}`, 'content-type': 'application/json',
20
+ }, body: JSON.stringify(payload), redirect: 'error', signal: AbortSignal.timeout(12000) })
21
+ const value = await response.json()
22
+ if (!response.ok) throw new Error('原 DSH 恢复检查未通过。')
23
+ return value
24
+ }
25
+ try {
26
+ const child = start()
27
+ ref = await waitForJson(path.join(directory, 'control-ready.json'), value =>
28
+ Number.isInteger(value.pid) && value.pid > 0 && (!child || value.pid === child.pid)
29
+ && /^http:\/\/127\.0\.0\.1:[1-9]\d{0,4}$/.test(value.origin), 180000)
30
+ const host = await request('describe')
31
+ if (host.pid !== ref.pid || host.home !== job.home || host.profile !== job.profile
32
+ || host.cli !== job.cli || host.dshVersion !== job.dshVersion || host.pluginVersion !== '0.0.0') {
33
+ throw new Error('恢复后的 DSH 身份不匹配。')
34
+ }
35
+ const items = (await request('read', { method: 'session.list' })).items
36
+ if (!Array.isArray(items) || JSON.stringify(items.map(s => s.sessionId).sort()) !== JSON.stringify(sessionIds)) {
37
+ throw new Error('恢复后的会话列表不一致。')
38
+ }
39
+ for (const sessionId of readableIds) await request('read', { method: 'session.history', payload: { sessionId, maxMessages: 1 } })
40
+ } finally {
41
+ try { remove() }
42
+ finally { if (ref) { try { await request('close') } catch {} } }
43
+ }
44
+ }
package/bin/setup.mjs CHANGED
@@ -6,7 +6,8 @@ import { spawn } from 'node:child_process'
6
6
  import { randomBytes, createHash } from 'node:crypto'
7
7
  import { fileURLToPath } from 'node:url'
8
8
  import { attachControl, waitForJson, waitForInstallControl } from './native-control.mjs'
9
- import { resolveInstallRuntime, verifyInstallRuntime } from '../lib/install-runtime.js'
9
+ import { resolveInstallRuntime, verifyInstallRuntime } from '../lib/install-runtime.js'
10
+ import { installProfile, backupProfile, NativeInstallError } from '../lib/install-profile.js'
10
11
  import { compareVersions } from '../lib/update-policy.js'
11
12
  import { selectInstallTarget } from './release-selection.mjs'
12
13
  import { boundedFetch, downloadRelease, auditArchive } from '../lib/update-download.js'
@@ -24,7 +25,7 @@ function portBusy(port) {
24
25
  socket.setTimeout(500, () => end(false)); socket.once('connect', () => end(true)); socket.once('error', () => end(false))
25
26
  })
26
27
  }
27
- export async function selectRelease(host, assetsRoot = path.join(root, 'assets'), repair = false,
28
+ export async function selectRelease(host, assetsRoot = path.join(root, 'assets'), repair = false,
28
29
  fetchCatalog = () => boundedFetch('https://relay.xyxfood.xyz/v1/update-policy', 256 * 1024)) {
29
30
  const current = { agentKind: 'dsh', agentVersion: host.dshVersion, pluginVersion: host.pluginVersion,
30
31
  platform: { win32: 'windows', darwin: 'macos', linux: 'linux' }[host.platform], arch: host.arch }
@@ -40,9 +41,57 @@ export async function selectRelease(host, assetsRoot = path.join(root, 'assets')
40
41
  if (release.version === pinned.version) archive = fs.readFileSync(path.join(assetsRoot, 'plugin.tgz'))
41
42
  else archive = await downloadRelease(release)
42
43
  auditArchive(archive, release)
43
- return { release, archive }
44
- }
45
- export async function install({ profileName = 'web', cli, home: configuredHome, assetsRoot, open = true, repair = false } = {}) {
44
+ return { release, archive }
45
+ }
46
+
47
+ /** With no running host, native plugin add needs neither HMR nor healthy third-
48
+ * party plugins. Reuse the same installation core; only live hosts need disposal. */
49
+ async function installStopped({ cli, home, profile, profileName, directory, id, runtime, assetsRoot, repair, open }) {
50
+ const dsh = validateDshCli(cli)
51
+ let version = '0.0.0'
52
+ try { version = JSON.parse(fs.readFileSync(path.join(profile, 'node_modules', packageName, 'package.json'), 'utf8')).version } catch {}
53
+ const selected = await selectRelease({ dshVersion: dsh.version, pluginVersion: version, platform: process.platform, arch: process.arch }, assetsRoot, repair)
54
+ fs.mkdirSync(profile, { recursive: true, mode: 0o700 })
55
+ if (fs.realpathSync(profile) !== profile) throw new Error('无法确认 DSH 配置目录的实际位置。')
56
+ const lock = path.join(profile, '.harness-remote-update.lock')
57
+ const fd = fs.openSync(lock, 'wx', 0o600); fs.writeFileSync(fd, id); fs.closeSync(fd)
58
+ let modified = false, keepLock = false
59
+ try {
60
+ // Recheck immediately before writing: a host may have started during npm
61
+ // discovery/download. Never mutate its dependencies underneath that process.
62
+ if (await mayHaveRunningDsh()) throw new Error('DSH 已开始运行,请重新执行安装命令以连接该实例。')
63
+ if (selected.archive) {
64
+ fs.writeFileSync(path.join(directory, 'release.tgz'), selected.archive, { mode: 0o600, flag: 'wx' })
65
+ backupProfile(profile, path.join(directory, 'profile-before'))
66
+ console.log(`正在通过 DSH 原生方式安装插件 ${selected.release.version}…`)
67
+ modified = true
68
+ await installProfile({ profile, directory, cli: dsh.cli, targetVersion: selected.release.version, runtime })
69
+ }
70
+ } catch (error) {
71
+ keepLock = error instanceof NativeInstallError && error.mayStillBeRunning
72
+ if (modified && !keepLock) {
73
+ fs.renameSync(profile, path.join(directory, 'profile-failed'))
74
+ fs.renameSync(path.join(directory, 'profile-before'), profile)
75
+ }
76
+ throw error
77
+ } finally { if (!keepLock) releaseOwnedUpdateLock(lock, id) }
78
+ // Use DSH's own browser opening behavior. Startup failure does not undo an
79
+ // otherwise successful native add; an unrelated plugin can fail to boot.
80
+ const logFile = path.join(directory, 'startup.log'), log = fs.openSync(logFile, 'a', 0o600)
81
+ const env = { ...process.env, DSH_HOME: home }
82
+ delete env.HARNESS_REMOTE_UPDATE_JOB
83
+ const child = spawn(process.execPath, [dsh.cli, '--profile', profileName, ...(open ? [] : ['--no-open'])],
84
+ { cwd: process.cwd(), env, detached: true, windowsHide: true, stdio: ['ignore', log, log] })
85
+ fs.closeSync(log)
86
+ let launchError
87
+ child.on('error', error => { launchError = error }); child.unref()
88
+ await sleep(1200)
89
+ const starting = !launchError && child.pid && child.exitCode === null && child.signalCode === null
90
+ const installedVersion = selected.archive ? selected.release.version : version
91
+ console.log(`插件 ${installedVersion} 已安装。${starting ? '已启动 DSH,请等待 WebUI 就绪。' : `DSH 未能启动,请查看:${logFile}`}`)
92
+ return { version: installedVersion, changed: Boolean(selected.archive), starting: Boolean(starting) }
93
+ }
94
+ export async function install({ profileName = 'web', cli, home: configuredHome, assetsRoot, open = true, repair = false } = {}) {
46
95
  if (!/^[A-Za-z0-9_-]{1,80}$/.test(profileName)) throw new Error('无效的 profile 名称。')
47
96
  if (cli) cli = validateDshCli(cli).cli
48
97
  const runtime = resolveInstallRuntime(root); await verifyInstallRuntime(runtime)
@@ -54,23 +103,16 @@ export async function install({ profileName = 'web', cli, home: configuredHome,
54
103
  fs.mkdirSync(directory, { recursive: true, mode: 0o700 })
55
104
  let remove, ref, job, locked = false, authorized = false, launched
56
105
  const lockFile = path.join(profile, '.harness-remote-update.lock')
57
- console.log('正在检查 DSH 与插件…')
58
- try {
59
- // Initialize missing profiles through DSH itself, never synthesize a bundle list.
60
- if (!fs.existsSync(path.join(profile, 'package.json'))) {
61
- if (await mayHaveRunningDsh()) throw new Error('当前目录下没有此 DSH 配置,但检测到 DSH 正在运行。请使用相同的 DSH_HOME/--home 和 --profile,未修改正在运行的实例。')
62
- cli ||= await chooseDsh()
63
- const log = fs.openSync(path.join(directory, 'startup.log'), 'a', 0o600)
64
- launched = spawn(process.execPath, [cli, '--profile', profileName, '--no-open'], {
65
- cwd: process.cwd(), env: { ...process.env, DSH_HOME: home }, detached: true, windowsHide: true, stdio: ['ignore', log, log] })
66
- fs.closeSync(log); launched.on('error', () => {}); launched.unref()
67
- const initializedBy = Date.now() + 180000
68
- while (!fs.existsSync(path.join(profile, 'package.json')) && Date.now() < initializedBy) {
69
- if (launched.exitCode !== null || launched.signalCode !== null) break
70
- await sleep(100)
71
- }
72
- if (!fs.existsSync(path.join(profile, 'package.json'))) throw new Error('DSH 未能初始化 profile;详情见本机安装记录。')
73
- await sleep(2000)
106
+ console.log('正在检查 DSH 与插件…')
107
+ try {
108
+ if (!await mayHaveRunningDsh()) {
109
+ cli ||= await chooseDsh()
110
+ return await installStopped({ cli, home, profile, profileName, directory, id, runtime, assetsRoot, repair, open })
111
+ }
112
+ // A live host must identify the same home/profile; never synthesize a second
113
+ // profile just because this terminal inherited different environment values.
114
+ if (!fs.existsSync(path.join(profile, 'package.json'))) {
115
+ throw new Error('当前目录下没有此 DSH 配置,但检测到 DSH 正在运行。请使用相同的 DSH_HOME/--home 和 --profile,未修改正在运行的实例。')
74
116
  }
75
117
  const fd = fs.openSync(lockFile, 'wx', 0o600); fs.writeFileSync(fd, id); fs.closeSync(fd); locked = true
76
118
  const helper = path.join(directory, 'install-control.js')
@@ -113,14 +155,28 @@ export async function install({ profileName = 'web', cli, home: configuredHome,
113
155
  assertInstallTarget(host, { home, profile, cli, pid: launched?.pid || ref.pid })
114
156
  remove(); remove = undefined
115
157
  await sleep(600)
116
- const selected = await selectRelease(host, assetsRoot, repair)
158
+ let selected = await selectRelease(host, assetsRoot, repair)
159
+ if (!selected.archive && host.pluginVersion === selected.release.version) {
160
+ // A version string on disk is not proof that a prior restart completed.
161
+ // Re-running the normal command must also repair a stuck installed copy.
162
+ let ready = false
163
+ try {
164
+ const response = await fetch(`http://127.0.0.1:${host.localPort}/gate/status`, { signal: AbortSignal.timeout(5000), redirect: 'error' })
165
+ await response.arrayBuffer(); ready = response.ok
166
+ } catch {}
167
+ if (!ready) {
168
+ console.log('检测到已安装插件尚未就绪,正在重新安装修复…')
169
+ selected = await selectRelease(host, assetsRoot, true)
170
+ }
171
+ }
117
172
  if (!selected.archive) { console.log(`插件 ${host.pluginVersion} 无需更新。`); return { version: host.pluginVersion, changed: false } }
118
173
  console.log(`正在安装插件 ${selected.release.version},保留原配对与会话…`)
119
174
  job = { ...host, argv: installHostArgv(host), id, directory, parentPid: host.pid, pnpm: runtime.cli, targetVersion: selected.release.version,
120
175
  previousVersion: host.pluginVersion, statusToken: token, controlOrigin: ref.origin }
121
176
  validateJob(job)
122
177
  fs.writeFileSync(path.join(directory, 'release.tgz'), selected.archive, { mode: 0o600, flag: 'wx' })
123
- fs.copyFileSync(path.join(root, 'lib/update-worker.js'), path.join(directory, 'update-worker.js'))
178
+ fs.copyFileSync(path.join(root, 'lib/update-worker.js'), path.join(directory, 'update-worker.js'))
179
+ if (host.pluginVersion === '0.0.0') fs.copyFileSync(path.join(root, 'lib/native-recovery.js'), path.join(directory, 'native-recovery.js'))
124
180
  writePrivateJsonAtomic(path.join(directory, 'job.json'), job)
125
181
  await control(job, 'launch')
126
182
  const ready = await waitForJson(path.join(directory, 'worker-ready.json'), v => v.id === id)
@@ -128,7 +184,9 @@ export async function install({ profileName = 'web', cli, home: configuredHome,
128
184
  writePrivateJsonAtomic(path.join(home, 'harness-remote-updates', `profile-${scope}.json`), { jobId: id, statusOrigin: ready.origin, statusToken: token })
129
185
  writePrivateJsonAtomic(path.join(directory, 'authorized.json'), { id }); authorized = true
130
186
  let previous = '', result
131
- const until = Date.now() + 600000
187
+ // Native download/install has its own bounded deadline; allow its restart
188
+ // and possible rollback to finish before reporting an unknown outcome.
189
+ const until = Date.now() + 1200000
132
190
  while (Date.now() < until) {
133
191
  try { result = JSON.parse(fs.readFileSync(path.join(directory, 'result.json'), 'utf8')) } catch {}
134
192
  if (result?.phase !== previous && result?.phase) { console.log(`${result.progress}% ${result.message}`); previous = result.phase }
@@ -147,10 +205,12 @@ export async function install({ profileName = 'web', cli, home: configuredHome,
147
205
  } catch { console.log('插件已更新;请返回原 DSH WebUI 查看。') }
148
206
  }
149
207
  return { version: selected.release.version, changed: true }
150
- } finally {
151
- remove?.()
152
- if (ref && !authorized) { try { await control({ controlOrigin: ref.origin, statusToken: token }, 'close') } catch {} }
153
- if (locked && !authorized) releaseOwnedUpdateLock(lockFile, id)
208
+ } finally {
209
+ try { remove?.() }
210
+ finally {
211
+ if (ref && !authorized) { try { await control({ controlOrigin: ref.origin, statusToken: token }, 'close') } catch {} }
212
+ if (locked && !authorized) releaseOwnedUpdateLock(lockFile, id)
213
+ }
154
214
  }
155
215
  }
156
216
  export function parseArguments(args) {
@@ -168,6 +228,6 @@ export function parseArguments(args) {
168
228
  }
169
229
  if (process.argv[1] && fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
170
230
  const args = process.argv.slice(2)
171
- if (args.includes('--help') || args.includes('-h')) console.log('安装或升级 DSH 微信连接插件:npx -y dsh-wechat-remote@latest\n请先按原来的方式启动 DSH WebUI,支持全局安装与 npx 启动。\n可选:--profile <名称>(默认 web);--home <DSH 数据目录>;--dsh-cli <DSH 的 lib/bin.js>;--repair(重新安装,不降级)')
231
+ if (args.includes('--help') || args.includes('-h')) console.log('安装或升级 DSH 微信连接插件:npx -y dsh-wechat-remote@latest\n支持全局安装与 npx 使用的 DSH,已启动或关闭均可;请在相同系统账号下执行。Windows 可使用 npx.cmd。\n可选:--profile <名称>(默认 web);--home <DSH 数据目录>;--dsh-cli <DSH 的 lib/bin.js>;--repair(重新安装,不降级)')
172
232
  else Promise.resolve().then(() => install(parseArguments(args))).catch(error => { console.error(error.message); process.exitCode = 1 })
173
233
  }
@@ -1151,7 +1151,7 @@ async function createInstallControl(context, config) {
1151
1151
  const scope = resolveAgentProfileScope("", process.argv, home), profile = path5.join(home, "profiles", scope);
1152
1152
  const cli = fs2.realpathSync(process.argv[1]);
1153
1153
  const manifest = JSON.parse(fs2.readFileSync(path5.resolve(cli, "../../package.json"), "utf8"));
1154
- if (manifest.name !== "@deepseek-ai/dsh" || process.execArgv.length || !process.argv.includes("web")) throw new Error("\u6B64 DSH \u542F\u52A8\u65B9\u5F0F\u5C1A\u4E0D\u652F\u6301\u81EA\u52A8\u66F4\u65B0\u3002");
1154
+ if (manifest.name !== "@deepseek-ai/dsh" || process.execArgv.length) throw new Error("\u6B64 DSH \u542F\u52A8\u65B9\u5F0F\u5C1A\u4E0D\u652F\u6301\u81EA\u52A8\u66F4\u65B0\u3002");
1155
1155
  const manager = currentHostManager(), webPort = resolveDshWebRuntime(ctx, process.env).port;
1156
1156
  const ports = deriveGatePorts(scope, loadAgentDescriptor().agentInstanceId);
1157
1157
  const nativeExit = ctx.get("appExit");