dsh-sixlayer-memory 2.5.2 → 2.5.4

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,57 @@
1
1
  # 变更记录 · dsh-sixlayer-memory(六层记忆底座)
2
2
 
3
+ ## 2.5.4 — 2026-12-05
4
+
5
+ 修「字幕条弹出来了但一个字都没有」,并把字幕条改成**透明**。
6
+
7
+ ### 修复
8
+
9
+ - **设备名为空 → ffmpeg 直接退出**:流式识别没做设备自动发现,`-i audio=` 让 ffmpeg 报
10
+ `Malformed dshow input string` 并立刻退出(日志里就是这个),于是只有字幕条、没有字。
11
+ 现在和整段识别一样,先 `-list_devices` 挑第一个麦克风;找不到就明确报"没有麦克风"。
12
+ - 采集进程异常退出时把 ffmpeg 的 stderr 带进 `reason`,不再静默失败。
13
+
14
+ ### 界面
15
+
16
+ - **字幕条改为全透明**:只有文字(白字 + 黑色投影),没有底板,压在游戏/网页上也不挡内容;
17
+ 字号 30、居中、底部往上 240px。
18
+
19
+ ### 回归
20
+
21
+ - 真机验证:4 秒采到 108800 字节音频(≈3.4 秒 16k 单声道),设备自动发现生效
22
+ - 全量 35 个套件全绿
23
+
24
+ ---
25
+
26
+ ## 2.5.3 — 2026-12-05
27
+
28
+ 修「按热键一点声音都没有」:热键被上一次留下的孤儿进程占着。
29
+
30
+ ### 修复
31
+
32
+ - **孤儿 helper 占着热键**:DSH 重启时父进程换了,但 `hotkey-helper.ps1` 的 PowerShell 子进程不会跟着死,
33
+ 继续持有 `Alt+V`,新实例注册直接 `REGFAIL` → 整个动作不执行,连提示音都没有。
34
+ 现在启动前先清理 **owner 不是自己** 的 helper(helper 启动时带 `-OwnerPid` 标记,只杀别的进程,不杀同进程的兄弟 listener)。
35
+ - **状态文案**:`mem_hotkey` 原来无论什么动作都写"唤起系统听写",现在按 `stream / asr / dictation` 分别描述。
36
+
37
+ ### 回归
38
+
39
+ - `p31` 同进程冲突用例仍然有效 · 全量 35 个套件全绿
40
+
41
+ ---
42
+
43
+ ## 2.5.2 — 2026-12-05
44
+
45
+ 修「按热键只响一声低音,没有字幕条」:模型名传空串把默认值顶掉了。
46
+
47
+ - 调用方写 `config.stream?.model ?? ''` 传进来是 `''`,而 `function f({name = DEFAULT_MODEL})` 的空默认只在
48
+ `undefined` 时生效 → 路径拼成 `...\models\`(少一段),`existsSync` 恒 false → 判定"没装模型",
49
+ `start()` 立刻失败,只响错误音。
50
+ - 修法:`const modelName = (typeof name === 'string' && name.trim()) || DEFAULT_MODEL`
51
+ - 字幕条本身单独验证过:置顶 WPF 小窗,内容实时刷新正常
52
+
53
+ ---
54
+
3
55
  ## 2.5.1 — 2026-12-05
4
56
 
5
57
  修「按热键没反应」:流式模型在宿主进程里找不到。
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.2 · **35 个工具** · schema v9 · 零外部依赖 · 回归 35 个套件全绿
14
+ **当前版本**:2.5.4 · **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
 
@@ -5,7 +5,8 @@ param(
5
5
  [Parameter(Mandatory = $true)][string]$Key,
6
6
  [int]$Mods = 1,
7
7
  [int]$Vk = 0,
8
- [string]$Action = 'none'
8
+ [string]$Action = 'none',
9
+ [int]$OwnerPid = 0
9
10
  )
10
11
 
11
12
  $ErrorActionPreference = 'Stop'
@@ -12,7 +12,7 @@
12
12
  *
13
13
  * @module memory/hotkey
14
14
  */
15
- import { spawn } from 'node:child_process'
15
+ import { spawn, execFileSync } 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'
@@ -103,11 +103,25 @@ export class HotkeyListener {
103
103
  }
104
104
 
105
105
  _spawn() {
106
+ // 清掉**别的进程**留下的 helper:DSH 重启时父进程被换掉,但 PowerShell 子进程不会跟着死,
107
+ // 它继续占着 Alt+V,新实例就永远注册失败(error: 已被其它程序占用)。
108
+ // 只杀 owner 不是自己的,否则同进程内两个 listener 会互相把对方干掉(p31 的冲突用例就测不出来了)。
109
+ try {
110
+ const me = String(process.pid)
111
+ const cmd = [
112
+ "Get-CimInstance Win32_Process -Filter \"name='powershell.exe'\"",
113
+ `| Where-Object { $_.CommandLine -like '*hotkey-helper.ps1*' -and $_.CommandLine -notlike '*-OwnerPid ${me}*' }`,
114
+ '| ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }',
115
+ ].join(' ')
116
+ execFileSync('powershell.exe', ['-NoProfile', '-Command', cmd], { windowsHide: true, timeout: 8000, stdio: 'ignore' })
117
+ } catch {
118
+ /* 清不掉也要继续试 */
119
+ }
106
120
  let child
107
121
  try {
108
122
  child = spawn(
109
123
  'powershell.exe',
110
- ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', HELPER, '-Key', this.parsed.key, '-Mods', String(this.parsed.mods), '-Action', this.action],
124
+ ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', HELPER, '-Key', this.parsed.key, '-Mods', String(this.parsed.mods), '-Action', this.action, '-OwnerPid', String(process.pid)],
111
125
  { windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] },
112
126
  )
113
127
  } catch (error) {
@@ -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) => {
@@ -802,12 +802,16 @@ export function buildRegistry(store, host) {
802
802
  if (r.reason) ctl.listener.lastError = r.reason
803
803
  }
804
804
  const st = ctl.listener.status()
805
+ const ACTION_TEXT = {
806
+ stream: '本地流式识别:边说边出字,说完直接作为消息发出去(不看焦点)',
807
+ asr: 'DeepSeek 识别:说完停 1–2 秒,整句一次性投递',
808
+ dictation: 'Windows 听写:边说边出字,但打在光标所在的输入框',
809
+ none: '只记录按键,不做动作',
810
+ }
805
811
  const lines = [
806
- `热键:${st.hotkey || '(未设)'} · 动作:${st.action}`,
812
+ `热键:${st.hotkey || '(未设)'} · 动作:${st.action}(${ACTION_TEXT[st.action] ?? st.action})`,
807
813
  `状态:${st.state}${st.error ? `(${st.error})` : ''} · 已触发 ${st.presses} 次`,
808
- st.state === 'ready'
809
- ? '按下热键就会唤起 Windows 语音听写;说完文字会自动出现在光标处。'
810
- : '热键当前没有在监听。用 enabled:true 打开,或换一个 key。',
814
+ st.state === 'ready' ? '按一下开始,再按一下结束。' : '热键当前没有在监听。用 enabled:true 打开,或换一个 key。',
811
815
  ]
812
816
  return { text: lines.join('\n'), ...st }
813
817
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-sixlayer-memory",
3
- "version": "2.5.2",
3
+ "version": "2.5.4",
4
4
  "private": false,
5
5
  "description": "DSH 工作台:六层记忆底座(每轮自动召回 + 候选沉淀 + 闸门审计)+ 零件化,支持 QQ 随身使用。",
6
6
  "type": "module",
@@ -0,0 +1,13 @@
1
+ import { HotkeyListener } from '../lib/memory/hotkey.js'
2
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
3
+
4
+ console.log('启动前占用检查:')
5
+ const before = new HotkeyListener({ key: 'Alt+V', action: 'none' })
6
+ console.log(' 当前状态(未启动):', before.state)
7
+
8
+ const l = new HotkeyListener({ key: 'Alt+V', action: 'none' })
9
+ const r = l.start()
10
+ console.log('start ->', JSON.stringify(r))
11
+ for (let i = 0; i < 30 && l.state !== 'ready' && l.state !== 'error'; i += 1) await sleep(300)
12
+ console.log('最终状态:', l.state, '| 错误:', l.lastError || '无')
13
+ l.stop()