@leiyi-works/dsh-auto-restart 0.3.2 → 0.3.3

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 (4) hide show
  1. package/README.md +1 -1
  2. package/client.js +1 -10
  3. package/index.js +17 -11
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
  ## 它怎么重启
20
20
 
21
- 1. 等所有会话空闲(`api-session/status` + `agent/status`):最多等 `maxIdleWaitMs`(默认 **10 分钟**),超时就按计划重启并记录被中断的会话;设 `0` 表示一直等;
21
+ 1. 等所有会话空闲(`api-session/status` + `agent/status`):正在回答/干活的会一直等;**只卡在后台任务(`job_*`)上的会话不算忙**——这些 job 随 Host 被杀、不会自动恢复,所以重启会直接打断它们并在重启后发「继续」;停在选择题/审批上的会话永远不打断,答完且任务跑完才重新计 10 秒;
22
22
  2. 最后一次会话活动(发消息、回合开始/结束)之后再安静 10 秒,避免刚发出、回合还没起来的消息被重启吞掉、文字回到输入框;
23
23
  3. 等插件管理器安静 3 秒(不打断进行中的安装/更新);
24
24
  4. **优先交给常驻后台看门狗**:看门狗只在登录 Windows 时由「启动文件夹」里的引线自动启动,插件把请求写进 `~/.dsh/dsh-auto-restart/watchdog-request.json`,由它先杀 Electron 主进程、清残留、拉起应用并最大化——**不碰 WMI,也不会触发安全软件的 WMI 提示**;
package/client.js CHANGED
@@ -308,19 +308,10 @@ window.__ModuleLoader__.load({
308
308
  }),
309
309
  h(SwitchRow, {
310
310
  label: '等所有会话空闲再重启',
311
- hint: '有回答或任务在跑时一直等它们结束,避免截断。',
311
+ hint: '正在回答/干活的会话会等它们结束;只卡在后台任务(job_*,如 npm 轮询、长命令)上的会话不算忙,会被本次重启打断并在重启后收到“继续”。',
312
312
  checked: config.waitForIdle !== false,
313
313
  onChange: (value) => change({ waitForIdle: value }),
314
314
  }),
315
- h(NumberRow, {
316
- label: '等空闲上限',
317
- hint: '忙超过这么久就按计划重启,不再无限等(重启后自动给被中断的会话发“继续”);0 表示一直等。',
318
- value: Math.round((config.maxIdleWaitMs ?? 600000) / 60000),
319
- min: 0,
320
- max: 240,
321
- suffix: '分钟',
322
- onChange: (value) => change({ maxIdleWaitMs: Math.max(0, Math.round(value)) * 60000 }),
323
- }),
324
315
  h(SwitchRow, {
325
316
  label: '重启后自动继续',
326
317
  hint: '只给被后台任务(job_*,如 npm 轮询、长命令)打断的会话自动发“继续”;正在回答或等用户选择/授权的会话不动。',
package/index.js CHANGED
@@ -72,11 +72,9 @@ const DEFAULTS = Object.freeze({
72
72
  cooldownMs: 60000,
73
73
  /** 每小时最多重启几次;0 = 不限制。 */
74
74
  maxPerHour: 0,
75
- /** 有会话在跑时一直等它们空闲(没有上限,不会硬切)。 */
75
+ /** 有会话在跑时等它们空闲;等空闲的会话若只是卡在后台任务(job_*)上,会被本次重启打断并在重启后收到“继续”。 */
76
76
  waitForIdle: true,
77
- /** 等空闲最多等多久;超过就按计划重启(重启后会给被中断的会话发“继续”);0 = 一直等。 */
78
- maxIdleWaitMs: 600000,
79
- /** 重启后是否自动给被中断的会话发一条“继续”。 */
77
+ /** 重启后是否自动给被后台任务打断的会话发一条“继续”。 */
80
78
  continueInterrupted: true,
81
79
  /** 自动继续时发送的文本。 */
82
80
  continueText: '继续',
@@ -559,7 +557,6 @@ function sanitizeConfig(raw) {
559
557
  cfg.enabled = bool(raw.enabled, cfg.enabled)
560
558
  cfg.dryRun = bool(raw.dryRun, cfg.dryRun)
561
559
  cfg.waitForIdle = bool(raw.waitForIdle, cfg.waitForIdle)
562
- cfg.maxIdleWaitMs = num(raw.maxIdleWaitMs, cfg.maxIdleWaitMs, 0, 86400000)
563
560
  cfg.continueInterrupted = bool(raw.continueInterrupted, cfg.continueInterrupted)
564
561
  cfg.continueWindowMs = num(raw.continueWindowMs, cfg.continueWindowMs, 60000, 86400000)
565
562
  if (typeof raw.continueText === 'string' && raw.continueText.trim() !== '') cfg.continueText = raw.continueText.slice(0, 200)
@@ -1005,16 +1002,26 @@ function tick(baseConfig) {
1005
1002
  }
1006
1003
  return
1007
1004
  }
1008
- const busyForMs = state.waitingSince > 0 ? now - state.waitingSince : 0
1009
- const overLimit = cfg.maxIdleWaitMs > 0 && busyForMs >= cfg.maxIdleWaitMs
1010
- if (!overLimit) {
1005
+
1006
+ // A Session blocked on a running background job (job_*, e.g. an npm polling
1007
+ // loop) is deliberately NOT counted as busy: its job dies with the Host and
1008
+ // cannot recover on its own, so the restart interrupts it and resumeInterrupted
1009
+ // sends one "继续" after the new process is up. Only Sessions doing real work
1010
+ // (streaming an answer, running the model) keep the restart waiting.
1011
+ const jobBlocked = []
1012
+ const hardBusy = []
1013
+ for (const id of state.busy) {
1014
+ if (runningJobsFor(String(id)).length > 0) jobBlocked.push(String(id))
1015
+ else hardBusy.push(String(id))
1016
+ }
1017
+ if (hardBusy.length > 0) {
1011
1018
  if (state.waitingSince === 0) {
1012
1019
  state.waitingSince = now
1013
- logLine('info', `有 ${state.busy.size} 个会话在跑,等它们空闲后再重启(最多等 ${cfg.maxIdleWaitMs > 0 ? Math.round(cfg.maxIdleWaitMs / 60000) + ' 分钟' : '一直等'})`)
1020
+ logLine('info', `有 ${hardBusy.length} 个会话正在回答/干活,等它们空闲后再重启(会一直等)${jobBlocked.length > 0 ? `;另外 ${jobBlocked.length} 个会话在等后台任务,重启会打断它们并在重启后发“继续”` : ''}`)
1014
1021
  }
1015
1022
  return
1016
1023
  }
1017
- logLine('warn', `等空闲已超过 ${Math.round(cfg.maxIdleWaitMs / 60000)} 分钟(${state.busy.size} 个会话还在跑),按计划重启;重启后会给它们发“继续”`)
1024
+ logLine('info', `其余 ${jobBlocked.length} 个会话都在等后台任务(job_*);本次重启会打断它们,重启后自动发“继续”`)
1018
1025
  }
1019
1026
  state.waitingSince = 0
1020
1027
 
@@ -1112,7 +1119,6 @@ function installRoutes(ctx, baseConfig) {
1112
1119
  logPath: watchdogLogPath(),
1113
1120
  },
1114
1121
  waitForIdle: cfg.waitForIdle,
1115
- maxIdleWaitMs: cfg.maxIdleWaitMs,
1116
1122
  continueInterrupted: cfg.continueInterrupted,
1117
1123
  continueText: cfg.continueText,
1118
1124
  busySessions: state ? [...state.busy] : [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leiyi-works/dsh-auto-restart",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "type": "module",
5
5
  "title": "自动重启",
6
6
  "description": "装/更插件后自动重启 DSH 并回到原会话:检测 profile 插件文件变化,一直等所有会话空闲且最近活动安静,由常驻后台看门狗(登录自启、不碰 WMI)或 WMI 守护先杀主进程再拉起(可最大化窗口),带冷却、试运行、日志和右侧原生侧边栏面板。",