dsh-sixlayer-memory 2.3.0 → 2.3.2

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,33 @@
1
1
  # 变更记录 · dsh-sixlayer-memory(六层记忆底座)
2
2
 
3
+ ## 2.3.2 — 2026-12-05
4
+
5
+ 修「识别出来了但没粘进输入框、也没提示音」——两处都是进程环境问题。
6
+
7
+ ### 修复
8
+
9
+ - **粘贴**:`keybd_event` 从独立进程发 Ctrl+V,在 Electron 窗口里收不到(用户实测要手动按)。
10
+ 改用 `System.Windows.Forms.SendKeys::SendWait('^v')`(走"当前活动窗口"的正路),
11
+ 失败时再回退到 `keybd_event` 老路,两条都失败才报错。
12
+ - **提示音**:`[Console]::Beep` 在隐藏窗口的 PowerShell 里没有控制台,调用直接哑掉。
13
+ 改用 `System.Media.SoundPlayer` 播系统自带 wav(开始 `Windows Notify.wav`、结束 `Windows Notify Calendar.wav`)。
14
+
15
+ ---
16
+
17
+ ## 2.3.1 — 2026-12-05
18
+
19
+ 修两个让「按一下说话」实际不可用的问题(2.3.0 当天发现)。
20
+
21
+ ### 修复
22
+
23
+ - **按键连发**:按住热键时 Windows 会连发 `WM_HOTKEY`(1 秒十几条),原来每一条都被当成「停止」,
24
+ 刚开的录音被立刻掐断,产出 0 字节 WAV,于是永远转不出字。
25
+ 现在:热键去抖 400ms + 录音不足 800ms 的停止请求一律忽略。
26
+ - **没有反馈**:录音开始/结束各响一声提示音(880Hz / 520Hz)——没有界面可看时,
27
+ 至少能靠声音知道它在听。
28
+
29
+ ---
30
+
3
31
  ## 2.3.0 — 2026-12-05
4
32
 
5
33
  主题:**按一下说话,说完文字直接进输入框**(不再只是唤起系统听写)。
package/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  dsh plugin --profile desktop add dsh-sixlayer-memory
12
12
  ```
13
13
 
14
- **当前版本**:2.3.0 · **35 个工具** · schema v9 · 零外部依赖 · 回归 35 个套件全绿
14
+ **当前版本**:2.3.2 · **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
@@ -18,7 +18,7 @@ import { decorateRows, explainRecord } from './memory/explain.js'
18
18
  import { readDetail } from './memory/detail.js'
19
19
  import { createQqBridge } from './memory/qq.js'
20
20
  import { HotkeyListener, resolveHotkeyConfig } from './memory/hotkey.js'
21
- import { VoiceRecorder, loadDeepSeekKey, pasteText, resolveAsrConfig, transcribe, transcribeLocal } from './memory/asr.js'
21
+ import { VoiceRecorder, beep, loadDeepSeekKey, pasteText, resolveAsrConfig, transcribe, transcribeLocal } from './memory/asr.js'
22
22
  import { createApiHandler, ensureApiToken, createApiServer } from './memory/api.js'
23
23
  import { createQqOfficialBridge } from './memory/qq-official.js'
24
24
  import { ingestQqSessions, affectReport } from './memory/affect-events.js'
@@ -202,10 +202,18 @@ export function apply(ctx, config = {}) {
202
202
  logger: (m) => diag('asr: ' + m),
203
203
  })
204
204
  let lastVoice = null
205
+ let lastHotkeyAt = 0
205
206
  const toggleVoice = async () => {
206
207
  // 正在录 → 停 + 转写 + 粘贴
207
208
  if (voice.recording) {
209
+ // 按住键时 Windows 会连发 WM_HOTKEY,按住 1 秒能来十几条。
210
+ // 太短的"停止"一律忽略,否则会把刚开的录音立刻掐断(这次就是 0 字节 WAV 的原因)。
211
+ const heldMs = Date.now() - (voice.startedAt || 0)
212
+ if (heldMs < 800) {
213
+ return { at: new Date().toISOString(), ok: true, stage: 'recording', reason: `按下太快(${heldMs}ms),继续录` }
214
+ }
208
215
  const stopped = await voice.stop()
216
+ beep({ freq: 520, ms: 90 })
209
217
  if (!stopped.ok) {
210
218
  lastVoice = { at: new Date().toISOString(), ok: false, stage: 'record', reason: stopped.reason }
211
219
  diag('asr: 录音失败 ' + stopped.reason)
@@ -248,6 +256,7 @@ export function apply(ctx, config = {}) {
248
256
  }
249
257
  // 没在录 → 开始录
250
258
  const started = await voice.start()
259
+ if (started.ok) beep({ freq: 880, ms: 70 })
251
260
  lastVoice = started.ok
252
261
  ? { at: new Date().toISOString(), ok: true, stage: 'recording', file: started.file }
253
262
  : { at: new Date().toISOString(), ok: false, stage: 'record', reason: started.reason }
@@ -265,8 +274,12 @@ export function apply(ctx, config = {}) {
265
274
  try {
266
275
  if (ev.type === 'press') {
267
276
  store?.recorder?.record?.({ op: 'hotkey', hotkey: ev.hotkey, action: hotkeyConfig.action })
268
- // 动作是 asr 时,按下热键 = 开始/结束录音(录音和识别都在 Node 侧做)
277
+ // 动作是 asr 时,按下热键 = 开始/结束录音(录音和识别都在 Node 侧做)。
278
+ // 去抖:按住键会连发,只认第一次。
269
279
  if (hotkeyConfig.action === 'asr') {
280
+ const now = Date.now()
281
+ if (now - lastHotkeyAt < 400) return
282
+ lastHotkeyAt = now
270
283
  toggleVoice().catch((error) => diag('asr: 热键流程异常 ' + (error?.message ?? error)))
271
284
  }
272
285
  } else if (ev.type === 'conflict') {
package/lib/memory/asr.js CHANGED
@@ -314,28 +314,80 @@ export function saveAsrConfig(dataDir, patch = {}) {
314
314
  }
315
315
 
316
316
  /**
317
- * 把文本送进当前焦点输入框:写剪贴板 + 模拟 Ctrl+V。
317
+ * 提示音:录音开始/结束各响一声。没有界面可看时,声音就是"我在听"的反馈。
318
+ *
319
+ * 不用 `[Console]::Beep`:隐藏窗口的 PowerShell 没有控制台,调用直接哑掉(用户实测没声音)。
320
+ * 改用 SoundPlayer 放系统自带的 wav,任何进程都能出声。
321
+ */
322
+ export function beep({ freq = 880, ms = 80 } = {}) {
323
+ try {
324
+ // 高音/低音用两个系统 wav 代替,避免依赖 freq(系统 wav 不支持调频,但够区分开始和结束)
325
+ const file = freq >= 700 ? 'Windows Notify.wav' : 'Windows Notify Calendar.wav'
326
+ const child = spawn(
327
+ 'powershell.exe',
328
+ ['-NoProfile', '-Command', `$p = New-Object System.Media.SoundPlayer "$env:SystemRoot\\Media\\${file}"; $p.PlaySync()`],
329
+ { windowsHide: true, stdio: 'ignore' },
330
+ )
331
+ child.on('error', () => {})
332
+ } catch {
333
+ /* 忽略 */
334
+ }
335
+ }
336
+
337
+ /**
338
+ * 把文本送进当前焦点输入框:写剪贴板 + SendKeys 发 Ctrl+V。
339
+ *
340
+ * 为什么改成 SendKeys:`keybd_event` 从独立进程发键时,在部分应用(Electron 窗口)
341
+ * 里收不到,用户实测要手动按 Ctrl+V 才能粘上。SendKeys 走的是"当前活动窗口"这条正路。
342
+ *
318
343
  * 故意**不自动回车**——粘错了还能改,自动发送就救不回来了。
319
344
  */
320
345
  export function pasteText(text, { autoEnter = false } = {}) {
321
- return new Promise((resolve) => {
322
- const esc = String(text).replace(/`/g, '``').replace(/'/g, "''")
323
- const script = [
324
- `Add-Type -AssemblyName System.Windows.Forms`,
325
- `Set-Clipboard -Value '${esc}'`,
326
- `Add-Type @"`,
327
- `using System;using System.Runtime.InteropServices;`,
328
- `public class P { [DllImport("user32.dll")] public static extern void keybd_event(byte vk, byte scan, uint flags, UIntPtr extra); }`,
329
- `"@`,
330
- `[P]::keybd_event(0x11,0,0,[UIntPtr]::Zero)`,
331
- `[P]::keybd_event(0x56,0,0,[UIntPtr]::Zero)`,
332
- `Start-Sleep -Milliseconds 40`,
333
- `[P]::keybd_event(0x56,0,2,[UIntPtr]::Zero)`,
334
- `[P]::keybd_event(0x11,0,2,[UIntPtr]::Zero)`,
335
- autoEnter ? `Start-Sleep -Milliseconds 80; [P]::keybd_event(0x0D,0,0,[UIntPtr]::Zero); [P]::keybd_event(0x0D,0,2,[UIntPtr]::Zero)` : `'pasted'`,
336
- ].join('\n')
337
- const child = spawn('powershell.exe', ['-NoProfile', '-Command', script], { windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] })
338
- child.on('error', (error) => resolve({ ok: false, reason: error.message }))
339
- child.on('exit', (code) => resolve({ ok: code === 0, reason: code === 0 ? '' : `粘贴进程退出 ${code}` }))
340
- })
346
+ const one = String(text).replace(/\r?\n/g, ' ').replace(/'/g, "''")
347
+
348
+ const runSendKeys = () =>
349
+ new Promise((resolve) => {
350
+ const script = [
351
+ 'Add-Type -AssemblyName System.Windows.Forms',
352
+ `Set-Clipboard -Value '${one}'`,
353
+ 'Start-Sleep -Milliseconds 60',
354
+ "[System.Windows.Forms.SendKeys]::SendWait('^v')",
355
+ autoEnter ? "Start-Sleep -Milliseconds 120; [System.Windows.Forms.SendKeys]::SendWait('{ENTER}')" : "Write-Output 'pasted'",
356
+ ].join('\n')
357
+ const child = spawn('powershell.exe', ['-NoProfile', '-STA', '-Command', script], { windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] })
358
+ let err = ''
359
+ child.stderr.on('data', (c) => {
360
+ err += c.toString('utf8')
361
+ })
362
+ child.stdout.on('data', () => {})
363
+ child.on('error', (e) => resolve({ ok: false, reason: e.message }))
364
+ child.on('exit', (code) =>
365
+ resolve({ ok: code === 0, reason: code === 0 ? '' : `SendKeys 退出 ${code}${err ? ':' + err.trim().slice(0, 120) : ''}` }),
366
+ )
367
+ })
368
+
369
+ // 老路:keybd_event。SendKeys 在某些环境被拦时还能兜住。
370
+ const runKeybd = () =>
371
+ new Promise((resolve) => {
372
+ const script = [
373
+ 'Add-Type -AssemblyName System.Windows.Forms',
374
+ `Set-Clipboard -Value '${one}'`,
375
+ 'Add-Type @"',
376
+ 'using System;using System.Runtime.InteropServices;',
377
+ 'public class PK { [DllImport("user32.dll")] public static extern void keybd_event(byte vk, byte scan, uint flags, UIntPtr extra); }',
378
+ '"@',
379
+ 'Start-Sleep -Milliseconds 40',
380
+ '[PK]::keybd_event(0x11,0,0,[UIntPtr]::Zero)',
381
+ '[PK]::keybd_event(0x56,0,0,[UIntPtr]::Zero)',
382
+ 'Start-Sleep -Milliseconds 40',
383
+ '[PK]::keybd_event(0x56,0,2,[UIntPtr]::Zero)',
384
+ '[PK]::keybd_event(0x11,0,2,[UIntPtr]::Zero)',
385
+ autoEnter ? 'Start-Sleep -Milliseconds 100; [PK]::keybd_event(0x0D,0,0,[UIntPtr]::Zero); [PK]::keybd_event(0x0D,0,2,[UIntPtr]::Zero)' : "Write-Output 'pasted'",
386
+ ].join('\n')
387
+ const child = spawn('powershell.exe', ['-NoProfile', '-Command', script], { windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'] })
388
+ child.on('error', (e) => resolve({ ok: false, reason: e.message }))
389
+ child.on('exit', (code) => resolve({ ok: code === 0, reason: code === 0 ? '' : `keybd 退出 ${code}` }))
390
+ })
391
+
392
+ return runSendKeys().then((r) => (r.ok ? r : runKeybd().then((r2) => (r2.ok ? { ok: true, via: 'keybd' } : { ok: false, reason: `${r.reason} / ${r2.reason}` }))))
341
393
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-sixlayer-memory",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
4
4
  "private": false,
5
5
  "description": "DSH 工作台:六层记忆底座(每轮自动召回 + 候选沉淀 + 闸门审计)+ 零件化,支持 QQ 随身使用。",
6
6
  "type": "module",