@leiyi-works/dsh-auto-restart 0.1.3 → 0.1.5
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 +4 -2
- package/client.js +135 -11
- package/index.js +24 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
只支持 **Windows 桌面端**(Electron 外壳 + Host 子进程的形态)。`dsh web` / headless 不会重启(插件会写日志说明不支持)。
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
左侧菜单有一个「自动重启」入口:点一下先回到会话,再在**右侧原生侧边栏**打开面板(和「临时目录」等插件一致,不遮挡会话);状态、上次重启回执、开关与参数都在那里改,改完即时生效。右侧边栏不可用时才退回全页面板。
|
|
8
8
|
|
|
9
9
|
## 它怎么判断"插件变了"
|
|
10
10
|
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
## 它怎么重启
|
|
20
20
|
|
|
21
21
|
1. 等所有会话空闲(`api-session/status` + `agent/status`),默认最多等 2 分钟;
|
|
22
|
-
2.
|
|
22
|
+
2. 最后一次会话活动(发消息、回合开始/结束)之后再安静 10 秒,避免刚发出、回合还没起来的消息被重启吞掉、文字回到输入框;
|
|
23
|
+
3. 等插件管理器安静 3 秒(不打断进行中的安装/更新);
|
|
23
24
|
3. 由 WMI 起一个**脱离进程树、隐藏控制台**的 PowerShell 守护进程;
|
|
24
25
|
4. 守护进程等 `restartDelayMs`(默认 2 秒)→ **先杀 Electron 主进程**(否则 Host 先退出会让主进程弹「DeepSeek Harness 无法使用」并响一声)→ 清掉残留应用进程 → `Start-Process` 拉起应用 → 等主窗口出现 → 按 `maximizeOnRestart` 把窗口最大化 → 写回执。
|
|
25
26
|
|
|
@@ -59,6 +60,7 @@
|
|
|
59
60
|
| `maxPerHour` | `0` | 每小时上限;`0` = 不限制 |
|
|
60
61
|
| `waitForIdle` | `true` | 等会话空闲再重启 |
|
|
61
62
|
| `maxIdleWaitMs` | `120000` | 等空闲上限,超时放弃本次 |
|
|
63
|
+
| `idleSettleMs` | `10000` | 最后一次会话活动后安静多久再重启;防止刚发出、回合还没起来的消息被吞掉 |
|
|
62
64
|
| `forceWhenBusy` | `false` | 超时后是否强重启 |
|
|
63
65
|
| `restartDelayMs` | `2000` | 守护进程收到请求后等多久动手 |
|
|
64
66
|
| `maximizeOnRestart` | `true` | 重启后最大化主窗口 |
|
package/client.js
CHANGED
|
@@ -19,6 +19,8 @@ window.__ModuleLoader__.load({
|
|
|
19
19
|
|
|
20
20
|
/** Global panel id shared by the sidebar row and the main page. */
|
|
21
21
|
const PANEL_ID = 'auto-restart'
|
|
22
|
+
/** Right-sidebar tab type id. */
|
|
23
|
+
const TAB_ID = 'auto-restart-tab'
|
|
22
24
|
const API = '/auto-restart'
|
|
23
25
|
const REFRESH_MS = 5000
|
|
24
26
|
|
|
@@ -27,14 +29,14 @@ window.__ModuleLoader__.load({
|
|
|
27
29
|
height: '100%',
|
|
28
30
|
overflow: 'auto',
|
|
29
31
|
boxSizing: 'border-box',
|
|
30
|
-
padding: '
|
|
32
|
+
padding: '10px 12px 20px',
|
|
31
33
|
color: 'var(--dsw-alias-label-primary)',
|
|
32
34
|
fontSize: 13,
|
|
33
35
|
lineHeight: 1.55,
|
|
34
36
|
},
|
|
35
|
-
inner: { display: 'flex', flexDirection: 'column', gap:
|
|
36
|
-
header: { display: 'flex', alignItems: 'center', gap:
|
|
37
|
-
title: { margin: 0, fontSize:
|
|
37
|
+
inner: { display: 'flex', flexDirection: 'column', gap: 12 },
|
|
38
|
+
header: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' },
|
|
39
|
+
title: { margin: 0, fontSize: 15, fontWeight: 600 },
|
|
38
40
|
badge: {
|
|
39
41
|
fontSize: 11,
|
|
40
42
|
lineHeight: '18px',
|
|
@@ -70,7 +72,7 @@ window.__ModuleLoader__.load({
|
|
|
70
72
|
background: 'var(--dsw-alias-bg-layer-2, rgba(127,127,127,.04))',
|
|
71
73
|
},
|
|
72
74
|
cardTitle: { margin: 0, fontSize: 13, fontWeight: 600 },
|
|
73
|
-
row: { display: 'flex', alignItems: 'center', gap:
|
|
75
|
+
row: { display: 'flex', alignItems: 'center', gap: 8, justifyContent: 'space-between', flexWrap: 'wrap' },
|
|
74
76
|
rowMain: { display: 'flex', flexDirection: 'column', gap: 2, minWidth: 0 },
|
|
75
77
|
rowLabel: { fontSize: 13 },
|
|
76
78
|
rowHint: { fontSize: 11.5, color: 'var(--dsw-alias-label-secondary)' },
|
|
@@ -357,6 +359,15 @@ window.__ModuleLoader__.load({
|
|
|
357
359
|
suffix: '秒',
|
|
358
360
|
onChange: (value) => change({ maxIdleWaitMs: Math.max(0, Math.round(value)) * 1000 }),
|
|
359
361
|
}),
|
|
362
|
+
h(NumberRow, {
|
|
363
|
+
label: '空闲后安静',
|
|
364
|
+
hint: '最后一次会话活动之后安静这么久再重启,防止刚发出、回合还没起来的消息被吞掉。',
|
|
365
|
+
value: Math.round((config.idleSettleMs ?? 10000) / 1000),
|
|
366
|
+
min: 0,
|
|
367
|
+
max: 300,
|
|
368
|
+
suffix: '秒',
|
|
369
|
+
onChange: (value) => change({ idleSettleMs: Math.max(0, Math.round(value)) * 1000 }),
|
|
370
|
+
}),
|
|
360
371
|
h('p', { style: styles.note }, '改动即时保存、即时生效,不需要重启 DSH。'),
|
|
361
372
|
)
|
|
362
373
|
|
|
@@ -408,7 +419,86 @@ window.__ModuleLoader__.load({
|
|
|
408
419
|
name: '@leiyi-works/dsh-auto-restart',
|
|
409
420
|
inject: ['slots', 'layout'],
|
|
410
421
|
apply(ctx) {
|
|
411
|
-
|
|
422
|
+
/** Opens/focuses this plugin's native right-sidebar tab; null while unavailable. */
|
|
423
|
+
let nativeOpen = null
|
|
424
|
+
let redirecting = false
|
|
425
|
+
|
|
426
|
+
const openTab = () => {
|
|
427
|
+
if (nativeOpen === null) return false
|
|
428
|
+
try {
|
|
429
|
+
nativeOpen()
|
|
430
|
+
return true
|
|
431
|
+
} catch (error) {
|
|
432
|
+
console.warn('[dsh-auto-restart] right-sidebar openTab failed:', error)
|
|
433
|
+
return false
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/** Register the right-sidebar tab type and its narrow body. */
|
|
438
|
+
const mountTab = (inner) => {
|
|
439
|
+
let registry
|
|
440
|
+
let slots
|
|
441
|
+
let sidebarRight
|
|
442
|
+
try {
|
|
443
|
+
registry = inner.sidebarRightTabs ?? inner.get?.('sidebarRightTabs')
|
|
444
|
+
slots = inner.slots
|
|
445
|
+
sidebarRight = inner.sidebarRight ?? inner.get?.('sidebarRight')
|
|
446
|
+
} catch {
|
|
447
|
+
return undefined
|
|
448
|
+
}
|
|
449
|
+
if (registry === undefined || typeof registry.register !== 'function' || slots === undefined) return undefined
|
|
450
|
+
const disposers = []
|
|
451
|
+
try {
|
|
452
|
+
const disposeType = registry.register({
|
|
453
|
+
id: TAB_ID,
|
|
454
|
+
kind: TAB_ID,
|
|
455
|
+
title: () => '自动重启',
|
|
456
|
+
})
|
|
457
|
+
if (typeof disposeType === 'function') disposers.push(disposeType)
|
|
458
|
+
const disposeBody = slots.inject('sidebar.right.pane.tab', () =>
|
|
459
|
+
slots.register({ name: 'sidebar.right.pane.tab', key: TAB_ID }, (props) => h(AutoRestartPanel, props)),
|
|
460
|
+
)
|
|
461
|
+
if (typeof disposeBody === 'function') disposers.push(disposeBody)
|
|
462
|
+
if (sidebarRight !== undefined && typeof sidebarRight.openTab === 'function') {
|
|
463
|
+
nativeOpen = () => sidebarRight.openTab(TAB_ID)
|
|
464
|
+
}
|
|
465
|
+
} catch (error) {
|
|
466
|
+
for (const dispose of disposers.reverse()) {
|
|
467
|
+
try {
|
|
468
|
+
dispose()
|
|
469
|
+
} catch {
|
|
470
|
+
/* best-effort teardown */
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
console.warn('[dsh-auto-restart] right-sidebar tab registration failed:', error)
|
|
474
|
+
return undefined
|
|
475
|
+
}
|
|
476
|
+
return () => {
|
|
477
|
+
for (const dispose of disposers.reverse()) {
|
|
478
|
+
try {
|
|
479
|
+
dispose()
|
|
480
|
+
} catch {
|
|
481
|
+
/* already gone */
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
ctx.effect(() => {
|
|
488
|
+
try {
|
|
489
|
+
return ctx.inject(['sidebarRightTabs', 'sidebarRight', 'slots'], mountTab)
|
|
490
|
+
} catch {
|
|
491
|
+
return mountTab(ctx)
|
|
492
|
+
}
|
|
493
|
+
}, 'dsh-auto-restart: right-sidebar tab')
|
|
494
|
+
|
|
495
|
+
// Full-page fallback, used only when the native right sidebar is unavailable.
|
|
496
|
+
ctx.effect(
|
|
497
|
+
() => ctx.slots.inject('main', () => ctx.slots.register({ name: 'main', key: PANEL_ID }, AutoRestartPanel)),
|
|
498
|
+
'dsh-auto-restart: page fallback',
|
|
499
|
+
)
|
|
500
|
+
|
|
501
|
+
// Left-menu entry: same row style as the other plugins.
|
|
412
502
|
ctx.effect(
|
|
413
503
|
() =>
|
|
414
504
|
ctx.slots.inject('sidebar.panellist', () =>
|
|
@@ -416,11 +506,45 @@ window.__ModuleLoader__.load({
|
|
|
416
506
|
),
|
|
417
507
|
'dsh-auto-restart: sidebar entry',
|
|
418
508
|
)
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
509
|
+
|
|
510
|
+
// Clicking the left entry keeps the conversation: return to it, then open the
|
|
511
|
+
// native right-sidebar tab; fall back to the full-page panel when unavailable.
|
|
512
|
+
ctx.effect(() => {
|
|
513
|
+
const layout = ctx.layout
|
|
514
|
+
if (!layout || !layout.panelInfo) return undefined
|
|
515
|
+
const openAfterReturn = () => {
|
|
516
|
+
if (!openTab()) {
|
|
517
|
+
try {
|
|
518
|
+
layout.selectPanel(PANEL_ID)
|
|
519
|
+
} catch (error) {
|
|
520
|
+
console.warn('[dsh-auto-restart] full-page fallback failed:', error)
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
redirecting = false
|
|
524
|
+
}
|
|
525
|
+
const check = () => {
|
|
526
|
+
if (redirecting) return
|
|
527
|
+
let active
|
|
528
|
+
try {
|
|
529
|
+
active = layout.panelInfo.getSnapshot().activePanelId
|
|
530
|
+
} catch {
|
|
531
|
+
return
|
|
532
|
+
}
|
|
533
|
+
if (active !== PANEL_ID) return
|
|
534
|
+
redirecting = true
|
|
535
|
+
try {
|
|
536
|
+
layout.selectPanel(null)
|
|
537
|
+
} catch (error) {
|
|
538
|
+
redirecting = false
|
|
539
|
+
console.warn('[dsh-auto-restart] returning to the conversation failed:', error)
|
|
540
|
+
return
|
|
541
|
+
}
|
|
542
|
+
if (typeof queueMicrotask === 'function') queueMicrotask(openAfterReturn)
|
|
543
|
+
else setTimeout(openAfterReturn, 0)
|
|
544
|
+
}
|
|
545
|
+
check()
|
|
546
|
+
return layout.panelInfo.subscribe(check)
|
|
547
|
+
}, 'dsh-auto-restart: entry opens the right-sidebar tab')
|
|
424
548
|
},
|
|
425
549
|
}
|
|
426
550
|
},
|
package/index.js
CHANGED
|
@@ -75,6 +75,11 @@ const DEFAULTS = Object.freeze({
|
|
|
75
75
|
waitForIdle: true,
|
|
76
76
|
/** 等空闲的最长时间(毫秒),超时按下面 forceWhenBusy 处理。 */
|
|
77
77
|
maxIdleWaitMs: 120000,
|
|
78
|
+
/**
|
|
79
|
+
* 最后一次会话活动(发消息、回合开始/结束)之后,再安静这么久才重启。
|
|
80
|
+
* 防止「刚按发送、回合还没起来」的瞬间被重启吞掉,导致输入框回填已发出的文字。
|
|
81
|
+
*/
|
|
82
|
+
idleSettleMs: 10000,
|
|
78
83
|
/** 等空闲超时后是否仍然强重启;默认 false(放弃本次,等下次变化)。 */
|
|
79
84
|
forceWhenBusy: false,
|
|
80
85
|
/** 守护进程收到请求后等多久动手(毫秒),留时间给当前回合收尾。 */
|
|
@@ -227,6 +232,7 @@ function sanitizeConfig(raw) {
|
|
|
227
232
|
cfg.cooldownMs = num(raw.cooldownMs, cfg.cooldownMs, 0, 3600000)
|
|
228
233
|
cfg.maxPerHour = num(raw.maxPerHour, cfg.maxPerHour, 0, 100)
|
|
229
234
|
cfg.maxIdleWaitMs = num(raw.maxIdleWaitMs, cfg.maxIdleWaitMs, 0, 3600000)
|
|
235
|
+
cfg.idleSettleMs = num(raw.idleSettleMs, cfg.idleSettleMs, 0, 600000)
|
|
230
236
|
cfg.restartDelayMs = num(raw.restartDelayMs, cfg.restartDelayMs, 0, 600000)
|
|
231
237
|
cfg.logMaxBytes = num(raw.logMaxBytes, cfg.logMaxBytes, 4096, 64 * 1024 * 1024)
|
|
232
238
|
for (const key of ['exePath', 'supervisorScript', 'powershellPath', 'profileDir']) {
|
|
@@ -528,6 +534,7 @@ function createState(profileDir) {
|
|
|
528
534
|
lastChangeAt: 0,
|
|
529
535
|
pendingSince: 0,
|
|
530
536
|
waitingSince: 0,
|
|
537
|
+
lastActivityAt: 0,
|
|
531
538
|
lastRestartAt: persisted.lastRestartAt,
|
|
532
539
|
restarts: persisted.restarts.filter((t) => now - t < 3600000),
|
|
533
540
|
lastManagerAt: 0,
|
|
@@ -618,6 +625,16 @@ function tick(baseConfig) {
|
|
|
618
625
|
logLine('warn', `会话忙了 ${Math.round(cfg.maxIdleWaitMs / 1000)}s,forceWhenBusy=true,按配置强重启`)
|
|
619
626
|
}
|
|
620
627
|
|
|
628
|
+
// 最后一次会话活动之后必须安静够久:刚发出、回合还没起来的消息不能被重启吞掉。
|
|
629
|
+
const sinceActivity = state.lastActivityAt > 0 ? now - state.lastActivityAt : Number.POSITIVE_INFINITY
|
|
630
|
+
if (cfg.idleSettleMs > 0 && sinceActivity < cfg.idleSettleMs) {
|
|
631
|
+
if (now - state.lastSkipLog > 15000) {
|
|
632
|
+
state.lastSkipLog = now
|
|
633
|
+
logLine('info', `刚有会话活动(${Math.round(sinceActivity / 1000)}s 前),等安静 ${Math.round(cfg.idleSettleMs / 1000)}s 后再重启`)
|
|
634
|
+
}
|
|
635
|
+
return
|
|
636
|
+
}
|
|
637
|
+
|
|
621
638
|
dispatchRestart(state, cfg, '插件文件变化(装/更/改插件)')
|
|
622
639
|
}
|
|
623
640
|
|
|
@@ -799,6 +816,7 @@ export function apply(ctx, config) {
|
|
|
799
816
|
const id = String(sessionId)
|
|
800
817
|
if (running === false) state.busy.delete(id)
|
|
801
818
|
else state.busy.add(id)
|
|
819
|
+
state.lastActivityAt = Date.now()
|
|
802
820
|
}), 'auto-restart: session status')
|
|
803
821
|
|
|
804
822
|
ctx.effect(() => ctx.on('agent/status', (payload) => {
|
|
@@ -807,8 +825,14 @@ export function apply(ctx, config) {
|
|
|
807
825
|
const status = payload?.status
|
|
808
826
|
if (status === 'idle') state.busy.delete(String(id))
|
|
809
827
|
else if (ACTIVE_STATUSES.has(status)) state.busy.add(String(id))
|
|
828
|
+
state.lastActivityAt = Date.now()
|
|
810
829
|
}), 'auto-restart: agent status')
|
|
811
830
|
|
|
831
|
+
// User-authored messages: the turn may not have started yet, but the text was
|
|
832
|
+
// just sent, so a restart here would swallow it and restore the draft.
|
|
833
|
+
safeOn(ctx, 'api-session/activity', () => { state.lastActivityAt = Date.now() }, 'auto-restart: session activity')
|
|
834
|
+
safeOn(ctx, 'agent/inbox/inserted', () => { state.lastActivityAt = Date.now() }, 'auto-restart: inbox inserted')
|
|
835
|
+
|
|
812
836
|
// Plugin-manager activity: do not restart in the middle of an operation.
|
|
813
837
|
for (const event of ['plugin-manager/operation', 'plugin-manager/install-state', 'plugin-manager/update-state', 'plugin-manager/changed']) {
|
|
814
838
|
safeOn(ctx, event, () => { state.lastManagerAt = Date.now() }, `auto-restart: ${event}`)
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leiyi-works/dsh-auto-restart",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
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",
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
"@deepseek-ai/dsh-client-locale",
|
|
35
35
|
"@deepseek-ai/dsh-client-ui-slots",
|
|
36
36
|
"@deepseek-ai/dsh-client-ui-layout",
|
|
37
|
-
"@deepseek-ai/dsh-client-ui-sidebar"
|
|
37
|
+
"@deepseek-ai/dsh-client-ui-sidebar",
|
|
38
|
+
"@deepseek-ai/dsh-client-ui-sidebar-right"
|
|
38
39
|
]
|
|
39
40
|
}
|
|
40
41
|
},
|