@leiyi-works/dsh-auto-restart 0.1.5 → 0.1.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
@@ -18,11 +18,13 @@
18
18
 
19
19
  ## 它怎么重启
20
20
 
21
- 1. 等所有会话空闲(`api-session/status` + `agent/status`),默认最多等 2 分钟;
21
+ 1. 等所有会话空闲(`api-session/status` + `agent/status`),**一直等、没有上限**;
22
22
  2. 最后一次会话活动(发消息、回合开始/结束)之后再安静 10 秒,避免刚发出、回合还没起来的消息被重启吞掉、文字回到输入框;
23
23
  3. 等插件管理器安静 3 秒(不打断进行中的安装/更新);
24
- 3. 由 WMI 起一个**脱离进程树、隐藏控制台**的 PowerShell 守护进程;
25
- 4. 守护进程等 `restartDelayMs`(默认 2 秒)→ **先杀 Electron 主进程**(否则 Host 先退出会让主进程弹「DeepSeek Harness 无法使用」并响一声)→ 清掉残留应用进程 → `Start-Process` 拉起应用 → 等主窗口出现 → 按 `maximizeOnRestart` 把窗口最大化 → 写回执。
24
+ 4. 写一个隐藏窗口的快捷方式,交给 **explorer.exe** 启动守护进程(它是 Explorer 的子进程,能脱离 DSH 的 job object 活下来;**全程不用 WMI**,避免安全软件弹「操作 WMI」);
25
+ 5. 守护进程等 `restartDelayMs`(默认 2 秒)→ **先杀 Electron 主进程**(否则 Host 先退出会让主进程弹「DeepSeek Harness 无法使用」并响一声)→ 清掉残留应用进程 → `Start-Process` 拉起应用 → 等主窗口出现 → 按 `maximizeOnRestart` 把窗口最大化 → 写回执。
26
+
27
+ > 少数安全软件(如 360 的「文件防护」)仍可能按进程树把重启瞬间其它会话写图片/文档的行为提示出来;把 DSH 安装目录和 `~/.dsh` 加入信任区即可。
26
28
 
27
29
  会话记录在磁盘上,重启后回到同一个会话。**没有每小时次数上限**,只有 60 秒冷却防止连环重启。
28
30
 
@@ -41,10 +43,10 @@
41
43
  | 启用自动重启 | 总开关 |
42
44
  | 试运行(dryRun) | 只记日志不重启 |
43
45
  | 重启后最大化窗口 | 守护进程拉起应用后把主窗口最大化 |
44
- | 等所有会话空闲再重启 | 有回答在跑时先等 |
46
+ | 等所有会话空闲再重启 | 有回答在跑时一直等,没有上限 |
45
47
  | 文件稳定判定 | 默认 10 秒 |
46
48
  | 两次重启冷却 | 默认 60 秒 |
47
- | 等空闲上限 | 默认 120 秒,超时放弃本次 |
49
+ | 空闲后安静 | 默认 10 秒 |
48
50
  | 立即重启 | 手动触发一次(有会话在跑时会被拒绝) |
49
51
 
50
52
  ## 配置
@@ -59,9 +61,7 @@
59
61
  | `cooldownMs` | `60000` | 两次重启最小间隔(跨重启持久化) |
60
62
  | `maxPerHour` | `0` | 每小时上限;`0` = 不限制 |
61
63
  | `waitForIdle` | `true` | 等会话空闲再重启 |
62
- | `maxIdleWaitMs` | `120000` | 等空闲上限,超时放弃本次 |
63
64
  | `idleSettleMs` | `10000` | 最后一次会话活动后安静多久再重启;防止刚发出、回合还没起来的消息被吞掉 |
64
- | `forceWhenBusy` | `false` | 超时后是否强重启 |
65
65
  | `restartDelayMs` | `2000` | 守护进程收到请求后等多久动手 |
66
66
  | `maximizeOnRestart` | `true` | 重启后最大化主窗口 |
67
67
  | `exePath` | `''` | 应用可执行文件,留空自动推导 |
@@ -93,6 +93,6 @@ dsh plugin --profile desktop remove @leiyi-works/dsh-auto-restart
93
93
  ## 边界
94
94
 
95
95
  - 只重启应用,不动其它进程。
96
- - 正在跑的任务会被重启打断——所以先等空闲;`maxIdleWaitMs` 超时默认放弃本次。
96
+ - 正在跑的任务会被重启打断——所以一直等它空闲,不会硬切;等多久都不会放弃,直到空闲。
97
97
  - 不碰 `app.asar`,DSH 升级不受影响。
98
98
  - 桌面端正式构建没有可用重启入口(官方菜单项只在 development 构建出现),所以只能用外部守护进程的方式;这也是为什么需要一次引导重启。
package/client.js CHANGED
@@ -350,15 +350,6 @@ window.__ModuleLoader__.load({
350
350
  suffix: '秒',
351
351
  onChange: (value) => change({ cooldownMs: Math.max(0, Math.round(value)) * 1000 }),
352
352
  }),
353
- h(NumberRow, {
354
- label: '等空闲上限',
355
- hint: '超时还没有空闲就按「放弃本次」处理(除非另开了强制重启)。',
356
- value: Math.round((config.maxIdleWaitMs ?? 120000) / 1000),
357
- min: 10,
358
- max: 3600,
359
- suffix: '秒',
360
- onChange: (value) => change({ maxIdleWaitMs: Math.max(0, Math.round(value)) * 1000 }),
361
- }),
362
353
  h(NumberRow, {
363
354
  label: '空闲后安静',
364
355
  hint: '最后一次会话活动之后安静这么久再重启,防止刚发出、回合还没起来的消息被吞掉。',
package/index.js CHANGED
@@ -71,17 +71,13 @@ const DEFAULTS = Object.freeze({
71
71
  cooldownMs: 60000,
72
72
  /** 每小时最多重启几次;0 = 不限制。 */
73
73
  maxPerHour: 0,
74
- /** 有会话在跑时先等它们空闲。 */
74
+ /** 有会话在跑时一直等它们空闲(没有上限,不会硬切)。 */
75
75
  waitForIdle: true,
76
- /** 等空闲的最长时间(毫秒),超时按下面 forceWhenBusy 处理。 */
77
- maxIdleWaitMs: 120000,
78
76
  /**
79
77
  * 最后一次会话活动(发消息、回合开始/结束)之后,再安静这么久才重启。
80
78
  * 防止「刚按发送、回合还没起来」的瞬间被重启吞掉,导致输入框回填已发出的文字。
81
79
  */
82
80
  idleSettleMs: 10000,
83
- /** 等空闲超时后是否仍然强重启;默认 false(放弃本次,等下次变化)。 */
84
- forceWhenBusy: false,
85
81
  /** 守护进程收到请求后等多久动手(毫秒),留时间给当前回合收尾。 */
86
82
  restartDelayMs: 2000,
87
83
  /** 重启后把主窗口最大化(开关在左侧「自动重启」面板里)。 */
@@ -224,14 +220,12 @@ function sanitizeConfig(raw) {
224
220
  cfg.enabled = bool(raw.enabled, cfg.enabled)
225
221
  cfg.dryRun = bool(raw.dryRun, cfg.dryRun)
226
222
  cfg.waitForIdle = bool(raw.waitForIdle, cfg.waitForIdle)
227
- cfg.forceWhenBusy = bool(raw.forceWhenBusy, cfg.forceWhenBusy)
228
223
  cfg.maximizeOnRestart = bool(raw.maximizeOnRestart, cfg.maximizeOnRestart)
229
224
  cfg.pollIntervalMs = num(raw.pollIntervalMs, cfg.pollIntervalMs, 500, 60000)
230
225
  cfg.stableMs = num(raw.stableMs, cfg.stableMs, 0, 600000)
231
226
  cfg.managerQuietMs = num(raw.managerQuietMs, cfg.managerQuietMs, 0, 60000)
232
227
  cfg.cooldownMs = num(raw.cooldownMs, cfg.cooldownMs, 0, 3600000)
233
228
  cfg.maxPerHour = num(raw.maxPerHour, cfg.maxPerHour, 0, 100)
234
- cfg.maxIdleWaitMs = num(raw.maxIdleWaitMs, cfg.maxIdleWaitMs, 0, 3600000)
235
229
  cfg.idleSettleMs = num(raw.idleSettleMs, cfg.idleSettleMs, 0, 600000)
236
230
  cfg.restartDelayMs = num(raw.restartDelayMs, cfg.restartDelayMs, 0, 600000)
237
231
  cfg.logMaxBytes = num(raw.logMaxBytes, cfg.logMaxBytes, 4096, 64 * 1024 * 1024)
@@ -614,16 +608,11 @@ function tick(baseConfig) {
614
608
  if (cfg.waitForIdle && state.busy.size > 0) {
615
609
  if (state.waitingSince === 0) {
616
610
  state.waitingSince = now
617
- logLine('info', `有 ${state.busy.size} 个会话在跑,等它们空闲后再重启`)
618
- return
611
+ logLine('info', `有 ${state.busy.size} 个会话在跑,一直等它们空闲后再重启`)
619
612
  }
620
- if (now - state.waitingSince <= cfg.maxIdleWaitMs) return
621
- if (!cfg.forceWhenBusy) {
622
- abortPending(state, `会话忙了 ${Math.round(cfg.maxIdleWaitMs / 1000)}s 仍未空闲`)
623
- return
624
- }
625
- logLine('warn', `会话忙了 ${Math.round(cfg.maxIdleWaitMs / 1000)}s,forceWhenBusy=true,按配置强重启`)
613
+ return
626
614
  }
615
+ state.waitingSince = 0
627
616
 
628
617
  // 最后一次会话活动之后必须安静够久:刚发出、回合还没起来的消息不能被重启吞掉。
629
618
  const sinceActivity = state.lastActivityAt > 0 ? now - state.lastActivityAt : Number.POSITIVE_INFINITY
@@ -5,8 +5,9 @@ param(
5
5
  )
6
6
 
7
7
  # Creates the restart supervisor through WMI so it runs outside this Host's
8
- # process tree (taskkill /T on the app cannot reach it) and with no visible
9
- # console (Win32_ProcessStartup.ShowWindow = 0 is SW_HIDE at creation time).
8
+ # process tree and its job object (a plain spawned child is killed together with
9
+ # the Host), and with no visible console (Win32_ProcessStartup.ShowWindow = 0 is
10
+ # SW_HIDE at creation time).
10
11
  # ASCII only: Windows PowerShell 5.1 would decode a BOM-less non-ASCII file as ANSI.
11
12
 
12
13
  $ErrorActionPreference = 'Stop'
@@ -172,22 +172,25 @@ try {
172
172
  Write-Result 'stopped' ''
173
173
  Write-Log 'app stopped; relaunching'
174
174
 
175
+ # Relaunch with Start-Process (no WMI: security software flags WMI operations).
176
+ $workDir = Split-Path -Parent $exe
177
+ $argsList = @($spec.launchArgs)
175
178
  $startArgs = @{
176
179
  FilePath = $exe
177
- WorkingDirectory = (Split-Path -Parent $exe)
180
+ WorkingDirectory = $workDir
178
181
  PassThru = $true
179
182
  }
180
- $argsList = @($spec.launchArgs)
181
183
  if ($argsList.Count -gt 0) {
182
184
  $startArgs['ArgumentList'] = $argsList
183
185
  }
184
- $newProcess = Start-Process @startArgs
185
- Write-Log ('relaunched pid=' + $newProcess.Id)
186
+ $started = Start-Process @startArgs
187
+ $newPid = [int]$started.Id
188
+ Write-Log ('relaunched, pid=' + $newPid)
186
189
 
187
190
  $windowDeadline = (Get-Date).AddSeconds(60)
188
191
  $windowUp = $false
189
192
  while ((Get-Date) -lt $windowDeadline) {
190
- $alive = Get-Process -Id $newProcess.Id -ErrorAction SilentlyContinue
193
+ $alive = Get-Process -Id $newPid -ErrorAction SilentlyContinue
191
194
  if ($alive -eq $null) { break }
192
195
  if ($alive.MainWindowHandle -ne 0) { $windowUp = $true; break }
193
196
  Start-Sleep -Milliseconds 500
@@ -197,22 +200,22 @@ try {
197
200
  Write-Log 'window is up'
198
201
  if ($Maximize) {
199
202
  $handle = [IntPtr]::Zero
200
- $current = Get-Process -Id $newProcess.Id -ErrorAction SilentlyContinue
203
+ $current = Get-Process -Id $newPid -ErrorAction SilentlyContinue
201
204
  if ($current -ne $null) { $handle = $current.MainWindowHandle }
202
205
  $maximized = Set-WindowMaximized $handle
203
206
  if ($maximized) {
204
207
  # The shell may apply its own placement right after showing; do it once more.
205
208
  Start-Sleep -Milliseconds 700
206
- $again = Get-Process -Id $newProcess.Id -ErrorAction SilentlyContinue
209
+ $again = Get-Process -Id $newPid -ErrorAction SilentlyContinue
207
210
  if ($again -ne $null) { [void](Set-WindowMaximized $again.MainWindowHandle) }
208
211
  Write-Log 'window maximized'
209
212
  }
210
213
  }
211
- $detail = 'window up, pid=' + $newProcess.Id
214
+ $detail = 'window up, pid=' + $newPid
212
215
  if ($maximized) { $detail = $detail + ', maximized' }
213
216
  Write-Result 'relaunched' $detail
214
217
  } else {
215
- Write-Result 'relaunched-no-window' ('pid=' + $newProcess.Id + ' no window within 60s')
218
+ Write-Result 'relaunched-no-window' ('pid=' + $newPid + ' no window within 60s')
216
219
  Write-Log 'relaunched without a window within 60s'
217
220
  }
218
221
  exit 0
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@leiyi-works/dsh-auto-restart",
3
- "version": "0.1.5",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "title": "自动重启",
6
- "description": "装/更插件后自动重启 DSH 并回到原会话:检测 profile 插件文件变化,等所有会话空闲且最近活动安静后,由脱离进程树的守护者先杀主进程再拉起(可最大化窗口),带冷却、试运行、日志和右侧原生侧边栏面板。",
6
+ "description": "装/更插件后自动重启 DSH 并回到原会话:检测 profile 插件文件变化,一直等所有会话空闲且最近活动安静,由脱离进程树的守护者先杀主进程再拉起(可最大化窗口),带冷却、试运行、日志和右侧原生侧边栏面板。",
7
7
  "main": "index.js",
8
8
  "exports": {
9
9
  ".": "./index.js",