@leiyi-works/dsh-auto-restart 0.1.6 → 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
@@ -21,8 +21,10 @@
21
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
 
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@leiyi-works/dsh-auto-restart",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "title": "自动重启",
6
6
  "description": "装/更插件后自动重启 DSH 并回到原会话:检测 profile 插件文件变化,一直等所有会话空闲且最近活动安静,由脱离进程树的守护者先杀主进程再拉起(可最大化窗口),带冷却、试运行、日志和右侧原生侧边栏面板。",