@leiyi-works/dsh-auto-restart 0.3.7 → 0.3.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.
Files changed (2) hide show
  1. package/index.js +15 -6
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -245,6 +245,13 @@ function runningJobsFor(sessionId) {
245
245
  * with the Host and never recover on their own, so they get one "继续" after the
246
246
  * restart. Sessions that are merely answering are left alone.
247
247
  */
248
+ /** One-line, bounded label for a job (bash jobs carry the whole command line). */
249
+ function shortenLabel(text, max = 48) {
250
+ const clean = String(text ?? '').replace(/\s+/g, ' ').trim()
251
+ if (clean === '') return ''
252
+ return clean.length <= max ? clean : `${clean.slice(0, Math.max(1, max - 1))}…`
253
+ }
254
+
248
255
  function recordInterrupted(state, reason) {
249
256
  const file = interruptedPath()
250
257
  const entries = []
@@ -254,7 +261,7 @@ function recordInterrupted(state, reason) {
254
261
  if (jobs.length === 0) continue
255
262
  entries.push({
256
263
  sessionId,
257
- jobs: jobs.slice(0, 5).map((job) => ({ id: String(job.id), label: String(job.label || job.kind || job.id) })),
264
+ jobs: jobs.slice(0, 5).map((job) => ({ id: String(job.id), label: shortenLabel(job.label || job.kind || job.id) })),
258
265
  })
259
266
  }
260
267
  if (entries.length === 0) {
@@ -309,10 +316,12 @@ async function resumeInterrupted(ctx, cfg) {
309
316
  const entry = entries[index]
310
317
  const sessionId = String(entry.sessionId)
311
318
  const short = sessionId.slice(0, 18)
312
- const labels = Array.isArray(entry.jobs) ? entry.jobs.map((job) => String(job.label || job.id)).join('、') : ''
319
+ const labels = Array.isArray(entry.jobs)
320
+ ? entry.jobs.map((job) => shortenLabel(job.label || job.id, 40)).filter((label) => label !== '').join('、')
321
+ : ''
313
322
  const text = labels === ''
314
323
  ? String(cfg.continueText || '继续')
315
- : `${String(cfg.continueText || '继续')}(刚才的后台任务因 DSH 重启被中断,不会自动恢复:${labels.slice(0, 120)}。请继续原来的工作)`
324
+ : `${String(cfg.continueText || '继续')}(刚才的后台任务因 DSH 重启被中断,不会自动恢复:${labels.slice(0, 140)}。请继续原来的工作)`
316
325
  try {
317
326
  let sessionState = null
318
327
  try { sessionState = await controller.state({ sessionId }) } catch {}
@@ -1415,9 +1424,9 @@ export function apply(ctx, config) {
1415
1424
  safeOn(ctx, event, () => { state.lastManagerAt = Date.now() }, `auto-restart: ${event}`)
1416
1425
  }
1417
1426
 
1418
- // Drop the on-demand tool tracker when the plugin unloads.
1419
- ctx.effect(() => () => stopToolsTracking())
1420
-
1427
+ // Drop the on-demand tool tracker when the plugin unloads.
1428
+ ctx.effect(() => () => stopToolsTracking())
1429
+
1421
1430
  // One timer for the whole plugin; disposal clears it.
1422
1431
  const interval = Math.max(500, Math.min(5000, cfg.pollIntervalMs))
1423
1432
  ctx.effect(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leiyi-works/dsh-auto-restart",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "type": "module",
5
5
  "title": "自动重启",
6
6
  "description": "装/更插件后自动重启 DSH 并回到原会话:检测 profile 插件文件变化,一直等所有会话空闲且最近活动安静,由常驻后台看门狗(登录自启、不碰 WMI)或 WMI 守护先杀主进程再拉起(可最大化窗口),带冷却、试运行、日志和右侧原生侧边栏面板。",