dsh-sixlayer-memory 2.5.4 → 2.5.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/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # 变更记录 · dsh-sixlayer-memory(六层记忆底座)
2
2
 
3
+ ## 2.5.5 — 2026-12-05
4
+
5
+ 修「长按热键导致整个 App 重启」。
6
+
7
+ ### 根因
8
+
9
+ `hotkey.js` 里的孤儿进程清理用的是 **`execFileSync`**——同步阻塞宿主事件循环,最长 8 秒。
10
+ 它挂在"启动热键"这条路径上,而长按会反复触发启动:
11
+
12
+ ```
13
+ 长按 → 连发 PRESS → 反复 start() → 反复 execFileSync(每次卡 1-8 秒)
14
+ → 宿主事件循环被占死 → Electron 父进程判定无响应 → 杀掉宿主 → App 重启
15
+ ```
16
+
17
+ ### 修复
18
+
19
+ - 清理改成**异步 spawn**,只在 `REGFAIL`(热键被占用)这条失败路上跑,跑完重试一次;
20
+ 正常启动路径**不再有任何同步阻塞**
21
+ - 热键切换加**重入锁**(`streamBusy`):上一次 start/stop 没结束,后面的按键直接忽略
22
+ - 去抖 400ms → **700ms**:长按时最多每 0.7 秒切换一次,不再抖动
23
+
24
+ ### 回归
25
+
26
+ - 全量 35 个套件全绿
27
+
28
+ ---
29
+
3
30
  ## 2.5.4 — 2026-12-05
4
31
 
5
32
  修「字幕条弹出来了但一个字都没有」,并把字幕条改成**透明**。
package/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  dsh plugin --profile desktop add dsh-sixlayer-memory
12
12
  ```
13
13
 
14
- **当前版本**:2.5.4 · **35 个工具** · schema v9 · 零外部依赖 · 回归 35 个套件全绿
14
+ **当前版本**:2.5.5 · **35 个工具** · schema v9 · 零外部依赖 · 回归 35 个套件全绿
15
15
 
16
16
  📦 [npm](https://www.npmjs.com/package/dsh-sixlayer-memory) · 🎬 [40 秒介绍视频](media/intro-40s.mp4) · 📝 [变更记录](CHANGELOG.md)
17
17
 
package/lib/index.js CHANGED
@@ -324,8 +324,16 @@ export function apply(ctx, config = {}) {
324
324
  )
325
325
 
326
326
  /** 流式:按一下开始(弹字幕条),再按一下结束并投递。 */
327
+ let streamBusy = false
327
328
  const toggleStream = async () => {
328
- if (streamer.running) {
329
+ // 长按会连发,且 start/stop 里有异步等待;重入会把识别器/ffmpeg 弄成半死状态。
330
+ if (streamBusy) {
331
+ diag('stream: 上一次切换还没结束,忽略这次')
332
+ return lastVoice
333
+ }
334
+ streamBusy = true
335
+ try {
336
+ if (streamer.running) {
329
337
  const r = await streamer.stop()
330
338
  stopOverlay(overlayChild, overlayFile)
331
339
  overlayChild = null
@@ -351,6 +359,9 @@ export function apply(ctx, config = {}) {
351
359
  }
352
360
  lastVoice = { at: new Date().toISOString(), ok: true, stage: 'recording', via: 'stream' }
353
361
  return lastVoice
362
+ } finally {
363
+ streamBusy = false
364
+ }
354
365
  }
355
366
 
356
367
  /** 把识别出的文本投进当前会话(优先 agent,失败退回粘贴)。 */
@@ -392,12 +403,12 @@ export function apply(ctx, config = {}) {
392
403
  // 去抖:按住键会连发,只认第一次。
393
404
  if (hotkeyConfig.action === 'asr') {
394
405
  const now = Date.now()
395
- if (now - lastHotkeyAt < 400) return
406
+ if (now - lastHotkeyAt < 700) return
396
407
  lastHotkeyAt = now
397
408
  toggleVoice().catch((error) => diag('asr: 热键流程异常 ' + (error?.message ?? error)))
398
409
  } else if (hotkeyConfig.action === 'stream') {
399
410
  const now = Date.now()
400
- if (now - lastHotkeyAt < 400) return
411
+ if (now - lastHotkeyAt < 700) return
401
412
  lastHotkeyAt = now
402
413
  toggleStream().catch((error) => diag('stream: 热键流程异常 ' + (error?.message ?? error)))
403
414
  }
@@ -12,7 +12,7 @@
12
12
  *
13
13
  * @module memory/hotkey
14
14
  */
15
- import { spawn, execFileSync } from 'node:child_process'
15
+ import { spawn } from 'node:child_process'
16
16
  import fs from 'node:fs'
17
17
  import path from 'node:path'
18
18
  import { fileURLToPath } from 'node:url'
@@ -102,10 +102,11 @@ export class HotkeyListener {
102
102
  return { ok: true, hotkey: this.parsed.label, action: this.action }
103
103
  }
104
104
 
105
- _spawn() {
106
- // 清掉**别的进程**留下的 helper:DSH 重启时父进程被换掉,但 PowerShell 子进程不会跟着死,
107
- // 它继续占着 Alt+V,新实例就永远注册失败(error: 已被其它程序占用)。
108
- // 只杀 owner 不是自己的,否则同进程内两个 listener 会互相把对方干掉(p31 的冲突用例就测不出来了)。
105
+ /**
106
+ * 异步清理别的进程留下的 helper(**不能同步执行**:execFileSync 会把宿主事件循环卡住十几秒,
107
+ * 长按热键时会被反复调用,宿主表现为"卡死"然后被父进程杀掉 → 整个 App 重启)。
108
+ */
109
+ _cleanupOrphansAsync(onDone) {
109
110
  try {
110
111
  const me = String(process.pid)
111
112
  const cmd = [
@@ -113,10 +114,16 @@ export class HotkeyListener {
113
114
  `| Where-Object { $_.CommandLine -like '*hotkey-helper.ps1*' -and $_.CommandLine -notlike '*-OwnerPid ${me}*' }`,
114
115
  '| ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }',
115
116
  ].join(' ')
116
- execFileSync('powershell.exe', ['-NoProfile', '-Command', cmd], { windowsHide: true, timeout: 8000, stdio: 'ignore' })
117
+ const p = spawn('powershell.exe', ['-NoProfile', '-Command', cmd], { windowsHide: true, stdio: 'ignore' })
118
+ p.on('error', () => onDone?.())
119
+ p.on('exit', () => onDone?.())
120
+ setTimeout(() => onDone?.(), 3000)
117
121
  } catch {
118
- /* 清不掉也要继续试 */
122
+ onDone?.()
119
123
  }
124
+ }
125
+
126
+ _spawn() {
120
127
  let child
121
128
  try {
122
129
  child = spawn(
@@ -183,6 +190,19 @@ export class HotkeyListener {
183
190
  this._fatalReason = `热键 ${this.parsed.label} 已被其它程序占用`
184
191
  this.lastError = this._fatalReason
185
192
  this._emit({ type: 'conflict', hotkey: this.parsed.label })
193
+ // 只在"被占用"这条路上清一次孤儿进程,然后重试;清完还不行就认输,别死循环
194
+ if (!this._retriedAfterCleanup) {
195
+ this._retriedAfterCleanup = true
196
+ this._cleanupOrphansAsync(() => {
197
+ if (this.stoppedByUs) return
198
+ this._fatalReason = ''
199
+ this.lastError = ''
200
+ this.state = 'idle'
201
+ setTimeout(() => {
202
+ if (!this.stoppedByUs && !this.child) this._spawn()
203
+ }, 300)
204
+ })
205
+ }
186
206
  } else if (line === 'BADKEY') {
187
207
  this.state = 'error'
188
208
  this._fatalReason = '热键格式不支持'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-sixlayer-memory",
3
- "version": "2.5.4",
3
+ "version": "2.5.5",
4
4
  "private": false,
5
5
  "description": "DSH 工作台:六层记忆底座(每轮自动召回 + 候选沉淀 + 闸门审计)+ 零件化,支持 QQ 随身使用。",
6
6
  "type": "module",