dsh-sixlayer-memory 2.5.3 → 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,55 @@
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
+
30
+ ## 2.5.4 — 2026-12-05
31
+
32
+ 修「字幕条弹出来了但一个字都没有」,并把字幕条改成**透明**。
33
+
34
+ ### 修复
35
+
36
+ - **设备名为空 → ffmpeg 直接退出**:流式识别没做设备自动发现,`-i audio=` 让 ffmpeg 报
37
+ `Malformed dshow input string` 并立刻退出(日志里就是这个),于是只有字幕条、没有字。
38
+ 现在和整段识别一样,先 `-list_devices` 挑第一个麦克风;找不到就明确报"没有麦克风"。
39
+ - 采集进程异常退出时把 ffmpeg 的 stderr 带进 `reason`,不再静默失败。
40
+
41
+ ### 界面
42
+
43
+ - **字幕条改为全透明**:只有文字(白字 + 黑色投影),没有底板,压在游戏/网页上也不挡内容;
44
+ 字号 30、居中、底部往上 240px。
45
+
46
+ ### 回归
47
+
48
+ - 真机验证:4 秒采到 108800 字节音频(≈3.4 秒 16k 单声道),设备自动发现生效
49
+ - 全量 35 个套件全绿
50
+
51
+ ---
52
+
3
53
  ## 2.5.3 — 2026-12-05
4
54
 
5
55
  修「按热键一点声音都没有」:热键被上一次留下的孤儿进程占着。
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.3 · **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 = '热键格式不支持'
@@ -1,5 +1,6 @@
1
- # overlay.ps1 -- always-on-top subtitle bar for streaming speech recognition.
2
- # Polls a UTF-8 text file and shows its content. Exit when the file disappears.
1
+ # overlay.ps1 -- always-on-top subtitle bar for streaming speech recognition.
2
+ # Transparent by design: only the text is visible, with a soft shadow so it stays
3
+ # readable over any background. Polls a UTF-8 text file; exits when it disappears.
3
4
  # Usage: powershell -STA -NoProfile -ExecutionPolicy Bypass -File overlay.ps1 -Path <file> -Title <text>
4
5
  param(
5
6
  [Parameter(Mandatory = $true)][string]$Path,
@@ -11,38 +12,52 @@ Add-Type -AssemblyName PresentationFramework
11
12
  Add-Type -AssemblyName PresentationCore
12
13
  Add-Type -AssemblyName WindowsBase
13
14
 
15
+ function Brush([string]$hex) {
16
+ return [System.Windows.Media.BrushConverter]::new().ConvertFromString($hex)
17
+ }
18
+
14
19
  $w = New-Object System.Windows.Window
15
20
  $w.WindowStyle = 'None'
16
21
  $w.AllowsTransparency = $true
17
- $w.Background = [System.Windows.Media.BrushConverter]::new().ConvertFromString('#E6141A22')
22
+ $w.Background = [System.Windows.Media.Brushes]::Transparent
18
23
  $w.Topmost = $true
19
24
  $w.ShowInTaskbar = $false
20
25
  $w.ResizeMode = 'NoResize'
21
- $w.Width = 940
22
- $w.Height = 96
23
- $screen = [System.Windows.SystemParameters]::PrimaryScreenWidth
24
- $w.Left = ($screen - 940) / 2
25
- $w.Top = [System.Windows.SystemParameters]::PrimaryScreenHeight - 220
26
-
27
- $border = New-Object System.Windows.Controls.Border
28
- $border.CornerRadius = [System.Windows.CornerRadius]::new(14)
29
- $border.Padding = [System.Windows.Thickness]::new(20, 10, 20, 10)
30
- $border.Background = [System.Windows.Media.BrushConverter]::new().ConvertFromString('#F21B2330')
26
+ $w.Width = 1000
27
+ $w.Height = 132
28
+ $w.Left = ([System.Windows.SystemParameters]::PrimaryScreenWidth - 1000) / 2
29
+ $w.Top = [System.Windows.SystemParameters]::PrimaryScreenHeight - 240
31
30
 
31
+ # 只有文字,没有底板;靠阴影保证任何背景上都看得清
32
32
  $stack = New-Object System.Windows.Controls.StackPanel
33
+ $stack.HorizontalAlignment = 'Center'
34
+ $stack.VerticalAlignment = 'Bottom'
35
+ $stack.Margin = [System.Windows.Thickness]::new(0, 0, 0, 6)
36
+
33
37
  $tip = New-Object System.Windows.Controls.TextBlock
34
38
  $tip.Text = $Title
35
39
  $tip.FontSize = 12
36
- $tip.Foreground = [System.Windows.Media.BrushConverter]::new().ConvertFromString('#88FFFFFF')
37
- $tip.Margin = [System.Windows.Thickness]::new(0, 0, 0, 4)
40
+ $tip.Foreground = Brush '#B3FFFFFF'
41
+ $tip.HorizontalAlignment = 'Center'
42
+ $tip.Margin = [System.Windows.Thickness]::new(0, 0, 0, 2)
43
+ $tipShadow = New-Object System.Windows.Media.Effects.DropShadowEffect
44
+ $tipShadow.Color = [System.Windows.Media.Colors]::Black
45
+ $tipShadow.BlurRadius = 4
46
+ $tipShadow.ShadowDepth = 0
47
+ $tipShadow.Opacity = 0.95
48
+ $tip.Effect = $tipShadow
49
+
38
50
  $tb = New-Object System.Windows.Controls.TextBlock
39
- $tb.FontSize = 24
51
+ $tb.FontSize = 30
52
+ $tb.FontWeight = 'SemiBold'
40
53
  $tb.TextWrapping = 'Wrap'
41
- $tb.Foreground = [System.Windows.Media.BrushConverter]::new().ConvertFromString('#FFFFFFFF')
54
+ $tb.TextAlignment = 'Center'
55
+ $tb.Foreground = Brush '#FFFFFFFF'
56
+ $tb.Effect = $tipShadow.Clone()
57
+
42
58
  $stack.Children.Add($tip) | Out-Null
43
59
  $stack.Children.Add($tb) | Out-Null
44
- $border.Child = $stack
45
- $w.Content = $border
60
+ $w.Content = $stack
46
61
 
47
62
  $timer = New-Object System.Windows.Threading.DispatcherTimer
48
63
  $timer.Interval = [TimeSpan]::FromMilliseconds(120)
@@ -15,6 +15,7 @@ import fs from 'node:fs'
15
15
  import path from 'node:path'
16
16
  import { createRequire } from 'node:module'
17
17
  import { fileURLToPath } from 'node:url'
18
+ import { listAudioDevices } from './asr.js'
18
19
 
19
20
  const require_ = createRequire(fileURLToPath(import.meta.url))
20
21
 
@@ -178,8 +179,19 @@ export class StreamRecognizer {
178
179
  this.stream = this.recognizer.createStream()
179
180
  this.text = ''
180
181
  this.startedAt = Date.now()
182
+ this.lastError = ''
181
183
 
182
- const args = ['-hide_banner', '-loglevel', 'error', '-f', 'dshow', '-i', `audio=${this.device}`, '-ac', '1', '-ar', '16000', '-f', 's16le', '-']
184
+ // 设备名不能空着:`-i audio=` 会让 ffmpeg 报 "Malformed dshow input string" 然后立刻退出,
185
+ // 表现就是"字幕条出来了但一个字都没有"。
186
+ let dev = this.device
187
+ if (!dev) {
188
+ const devices = await listAudioDevices({ ffmpegPath: this.ffmpegPath })
189
+ dev = devices[0] ?? ''
190
+ if (!dev) return { ok: false, reason: '没有找到麦克风设备' }
191
+ this.device = dev
192
+ }
193
+
194
+ const args = ['-hide_banner', '-loglevel', 'error', '-f', 'dshow', '-i', `audio=${dev}`, '-ac', '1', '-ar', '16000', '-f', 's16le', '-']
183
195
  let child
184
196
  try {
185
197
  child = spawn(this.ffmpegPath, args, { windowsHide: true, stdio: ['pipe', 'pipe', 'pipe'] })
@@ -198,12 +210,17 @@ export class StreamRecognizer {
198
210
  this._feed(buf)
199
211
  }
200
212
  })
201
- child.stderr.on('data', (c) => this.log(String(c).trim().slice(0, 160)))
213
+ child.stderr.on('data', (c) => {
214
+ const msg = String(c).trim().slice(0, 160)
215
+ if (msg) this.lastError = msg
216
+ this.log(msg)
217
+ })
202
218
  child.on('exit', (code) => {
203
219
  if (this.child === child) this.child = null
220
+ if (code && !this.lastError) this.lastError = `麦克风采集退出(code=${code})`
204
221
  this.log(`ffmpeg 退出 code=${code}`)
205
222
  })
206
- return { ok: true }
223
+ return { ok: true, device: dev }
207
224
  }
208
225
 
209
226
  _feed(buf) {
@@ -229,7 +246,9 @@ export class StreamRecognizer {
229
246
  /** 停止并给出最终文本。 @returns {Promise<{ok:boolean, text:string, ms:number, reason?:string}>} */
230
247
  async stop() {
231
248
  const child = this.child
232
- if (!child) return { ok: false, text: '', ms: 0, reason: '没有在流式识别' }
249
+ if (!child) {
250
+ return { ok: false, text: this.text || '', ms: Date.now() - (this.startedAt || Date.now()), reason: this.lastError || '麦克风没有在采集(ffmpeg 已退出)' }
251
+ }
233
252
  this.child = null
234
253
  const ms = Date.now() - this.startedAt
235
254
  await new Promise((resolve) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-sixlayer-memory",
3
- "version": "2.5.3",
3
+ "version": "2.5.5",
4
4
  "private": false,
5
5
  "description": "DSH 工作台:六层记忆底座(每轮自动召回 + 候选沉淀 + 闸门审计)+ 零件化,支持 QQ 随身使用。",
6
6
  "type": "module",