@leiyi-works/dsh-auto-restart 0.3.8 → 0.3.10

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 (2) hide show
  1. package/index.js +10 -6
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -76,8 +76,8 @@ const DEFAULTS = Object.freeze({
76
76
  waitForIdle: true,
77
77
  /** 重启后是否自动给被后台任务打断的会话发一条“继续”。 */
78
78
  continueInterrupted: true,
79
- /** 会话持有运行中的 job 时,安静多久才算“在等后台任务”(可被重启打断);低于这个值按“正在干活”处理。 */
80
- jobWaitQuietMs: 180000,
79
+ /** 兜底:会话持有 job 又安静了多久也算“在等后台任务”;0 = 关闭兜底,只认当前工具是不是 job_*。 */
80
+ jobWaitQuietMs: 0,
81
81
  /** 自动继续时发送的文本。 */
82
82
  continueText: '继续',
83
83
  /** 多久以内的中断记录还值得自动继续(毫秒)。 */
@@ -290,7 +290,8 @@ function recordInterrupted(state, reason) {
290
290
  async function resumeInterrupted(ctx, cfg) {
291
291
  const file = interruptedPath()
292
292
  const record = readJsonFile(file)
293
- if (record === null) return
293
+ // readJsonFile returns undefined when the file does not exist; nothing to resume.
294
+ if (record === null || record === undefined || typeof record !== 'object') return
294
295
  try {
295
296
  const entries = Array.isArray(record.entries)
296
297
  ? record.entries
@@ -682,7 +683,7 @@ function sanitizeConfig(raw) {
682
683
  cfg.enabled = bool(raw.enabled, cfg.enabled)
683
684
  cfg.dryRun = bool(raw.dryRun, cfg.dryRun)
684
685
  cfg.waitForIdle = bool(raw.waitForIdle, cfg.waitForIdle)
685
- cfg.jobWaitQuietMs = num(raw.jobWaitQuietMs, cfg.jobWaitQuietMs, 30000, 3600000)
686
+ cfg.jobWaitQuietMs = num(raw.jobWaitQuietMs, cfg.jobWaitQuietMs, 0, 3600000)
686
687
  cfg.continueInterrupted = bool(raw.continueInterrupted, cfg.continueInterrupted)
687
688
  cfg.continueWindowMs = num(raw.continueWindowMs, cfg.continueWindowMs, 60000, 86400000)
688
689
  if (typeof raw.continueText === 'string' && raw.continueText.trim() !== '') cfg.continueText = raw.continueText.slice(0, 200)
@@ -1149,10 +1150,13 @@ function tick(baseConfig) {
1149
1150
  const sessionId = String(id)
1150
1151
  const hasJobs = runningJobsFor(sessionId).length > 0
1151
1152
  const active = state.activeTools instanceof Map ? state.activeTools.get(sessionId) : undefined
1152
- const inJobTool = active !== undefined && /^job_/i.test(String(active.name))
1153
+ // Only job_output blocks on a job; job_list/job_kill/job_read return at once
1154
+ // and must not make a busy Session look interruptible.
1155
+ const inJobTool = active !== undefined && /^job_output$/i.test(String(active.name))
1153
1156
  const lastAt = state.sessionLastEventAt instanceof Map ? (state.sessionLastEventAt.get(sessionId) ?? 0) : 0
1154
1157
  const quietMs = lastAt > 0 ? now - lastAt : Number.POSITIVE_INFINITY
1155
- if (hasJobs && (inJobTool || quietMs >= cfg.jobWaitQuietMs)) jobBlocked.push(sessionId)
1158
+ const fallbackWait = cfg.jobWaitQuietMs > 0 && quietMs >= cfg.jobWaitQuietMs
1159
+ if (hasJobs && (inJobTool || fallbackWait)) jobBlocked.push(sessionId)
1156
1160
  else hardBusy.push(sessionId)
1157
1161
  }
1158
1162
  if (hardBusy.length > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leiyi-works/dsh-auto-restart",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "type": "module",
5
5
  "title": "自动重启",
6
6
  "description": "装/更插件后自动重启 DSH 并回到原会话:检测 profile 插件文件变化,一直等所有会话空闲且最近活动安静,由常驻后台看门狗(登录自启、不碰 WMI)或 WMI 守护先杀主进程再拉起(可最大化窗口),带冷却、试运行、日志和右侧原生侧边栏面板。",