dsh-voice-mode 0.7.36 → 0.7.38

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.en.md CHANGED
@@ -16,9 +16,9 @@ interrupts playback and the running turn. No additional speech-service API key i
16
16
 
17
17
  ![Real recording: streaming transcription → auto-send → sentence-by-sentence read-aloud with live captions](https://raw.githubusercontent.com/qishuilalala/dsh-voice-mode/HEAD/plugin/dsh-voice-mode/assets/demo-voice-flow.gif)
18
18
 
19
- > **Current status (2026-10-28):** v0.7.34 fixes Kokoro int8/fp32 model and explicitly hashed support-file downloads using historical upstream revisions that match the existing checksums. Check npm and Releases for availability; v0.7.33 does not contain this fix. Models, voices and cache locations are unchanged. Do not disable checksum verification.
19
+ > **Current status (2026-11-13):** v0.7.37 stop-on-focus-switch, once-interrupt resume, no-split decimals, mic release on early stop. Check npm and Releases for availability.
20
20
 
21
- Host compatibility check (2026-10-30): anchors, types and isolated runtime checks passed for dsh 0.2.1-rc.5. See the [compatibility record](../../docs/compat-contract.md) for evidence and unverified layers; this does not establish microphone or cross-platform acceptance.
21
+ Host compatibility check: anchors, types and isolated runtime checks passed for dsh 0.2.2-rc.3 (including the client side). See the [compatibility record](../../docs/compat-contract.md) for evidence and unverified layers; this does not establish microphone or cross-platform acceptance.
22
22
  >
23
23
  > CI results do not establish real-device audio quality or compatibility with every host version. See the [changelog](https://github.com/qishuilalala/dsh-voice-mode/blob/main/CHANGELOG.md), [compatibility evidence](https://github.com/qishuilalala/dsh-voice-mode/blob/main/docs/compat-contract.md), and [roadmap](https://github.com/qishuilalala/dsh-voice-mode/blob/main/docs/plan/roadmap-2026-10.md). The declared dsh range is `>=0.1.1-rc.2 <0.3.0-0`; untested versions are not guaranteed.
24
24
 
@@ -44,8 +44,8 @@ Host compatibility check (2026-10-30): anchors, types and isolated runtime check
44
44
  - **Three interaction modes (switchable in settings or by right-clicking the mic)**:
45
45
  - `toggle` (default) continuous listening: RMS VAD segmentation → streaming zipformer2 ASR (words appear as you speak, live caption preview) → automatic sentence split after 1500 ms of silence into the draft, consecutive segments joined into one message, then auto-sent after ~1.2 s more of silence (≈2.7 s total); hold `Ctrl` to force an immediate send
46
46
  - `hold` push-to-talk: from idle, **just hold the mic button to start recording and release to send** (no need to tap in first; a short tap still enters/exits); after sending, voice mode exits on its own once the reply finishes (read aloud, if on); with auto-send off, releasing only leaves the text in the composer (not sent) and exits; if you hold without speaking it exits after ~25 s; (swipe up to cancel, `Esc`/blur abandons the segment; pauses do not split while held, up to 10 min); hold `Ctrl` to record-by-keyboard, release to send
47
- - `once` one-shot: talk like `toggle`; after sending, the mic turns off and voice mode exits once the reply has been read aloud (with auto-send off: exits after the utterance, text stays in the draft)
48
- - **Read-aloud scope** (`readAloud`): `voice` (default) only replies in voice mode; `always` every reply in the visible session, typed ones included (with the session open in several tabs, only the last-viewed tab plays); `off` never
47
+ - `once` one-shot: talk like `toggle`; after sending, the mic turns off and voice mode exits once the reply finishes naturally; holding the mic button or pressing Ctrl interrupts the reply, resumes the mic, and keeps voice mode on for another utterance (with auto-send off: exits after the utterance, text stays in the draft)
48
+ - **Read-aloud scope** (`readAloud`): `voice` (default) only replies in voice mode; `always` every reply in the visible session, typed ones included (with the session open in several tabs, only the last-viewed tab plays; switching sessions immediately stops the previous session and discards its queued speech); `off` never
49
49
  - **The mic button is the status panel** (PR #16 by [@dyguests](https://github.com/dyguests)): green bars follow your voice while listening, blue bars follow playback while reading, a spinner while `once` waits for the reply, a check mark before it exits; orange dot = speech detected, red dot = error (hover for details). Right-click (or the keyboard menu key) for quick settings; touch long-press stays push-to-talk. Turn off the status bar and captions to keep all voice UI on the button
50
50
  - **Wake word (optional, off by default)**: after setting `wakeWord`, entering voice mode starts in standby, and recognition only begins once the wake word is spoken (e.g. `你好小D`). **You may say it together with your command** ("wake word, check the weather") — the wake word is stripped from the transcript/caption and never sent; matching is fault-tolerant (homophone substitutions, a wrong first char, leading fillers); 3-4 characters recommended; in standby the status bar live-shows "say '<word>' · what it heard". Boundaries (important): **toggle mode only** (inactive with `hold` / manual barge-in); **it must be repeated after each completed utterance or barge-in** (if you only said the wake word, the engine keeps listening so you may pause before the command); **saying it while the agent is reading does not trigger** (barge-in is VAD-based and unrelated to the wake word)
51
51
  - **Caption tiers (batch 3)**: `captionFontSize` 4 levels (0=12px / 1=14px / 2=18px / 3=24px) + `captionMaxWidth` 3 levels (0=50vw / 1=70vw / 2=90vw); adapts to narrow viewports
@@ -146,8 +146,8 @@ If a wake word is configured, you land in standby first (the status bar prompts
146
146
  | `idleTimeoutMinutes` | `5` | Minutes of inactivity before auto-exiting voice mode (reading, speech and a running turn renew the timer, subject to a two-hour cap since the last user activity) |
147
147
  | `modelHost` | default | Model download host (use `https://hf-mirror.com` on mainland networks) |
148
148
  | `autoSend` | `true` | Auto-send once quiet (consecutive segments join into one message); when off, text only goes to the draft (hold `Ctrl` / release in hold mode still sends) |
149
- | `mode` | `toggle` | Interaction mode: `toggle` continuous listening + 1500 ms silence split; `hold` push-to-talk, release to send (short tap exits); `once` one utterance, then exit after the reply is read aloud |
150
- | `readAloud` | `voice` | What gets read aloud: `voice` only replies in voice mode; `always` every reply in the visible session, typed ones included; `off` never |
149
+ | `mode` | `toggle` | Interaction mode: `toggle` continuous listening + 1500 ms silence split; `hold` push-to-talk, release to send (short tap exits); `once` one utterance, then exit after the reply finishes naturally; manual interruption resumes the mic and keeps voice mode on |
150
+ | `readAloud` | `voice` | What gets read aloud: `voice` only replies in voice mode; `always` every reply in the visible session, typed ones included; switching sessions stops the previous read-aloud; `off` never |
151
151
  | `showStatusBar` | `true` | Voice status bar above the composer; when off, status lives on the mic button (timer below it, notices beside it) |
152
152
  | `showCaptions` | `true` | Floating caption while reading aloud |
153
153
  | `autoResume` | `false` | Auto-restore voice mode when switching back to your last voice session (off by default). When on: the next time you enter that session it auto-enters voice mode and restores it; when off, press `Ctrl+Shift+V` manually |
@@ -325,7 +325,7 @@ Also: the on-device recording fixture used for debugging is **off by default**;
325
325
 
326
326
  ### Compatibility declaration (what the plugin market's version filter reads)
327
327
 
328
- `package.json` declares `engines.dsh = ">=0.1.1-rc.2 <0.3.0-0"`. This is an eligibility range, not evidence that every version in it has passed tests. The compatibility record lists tested releases through 0.2.2-alpha.2 and the forms actually exercised. The weekly workflow compares upstream tags and opens an issue for uncovered versions; it does not automatically rerun the full matrix. `peerDependencies` lists `@deepseek-ai/cordis` and `react` supplied by the host.
328
+ `package.json` declares `engines.dsh = ">=0.1.1-rc.2 <0.3.0-0"`. This is an eligibility range, not evidence that every version in it has passed tests. The compatibility record lists tested releases through 0.2.2-rc.3 and the forms actually exercised. The default set deduplicates the support endpoints, the latest verified release on each version line, and upstream latest/next: currently 9 versions for anchors and host/client typechecks, with 8 runtime cores. Historical evidence remains available; use `verify-dual.sh --full` or explicit versions to rerun it. Compatibility-only verification does not trigger a release. The daily workflow compares upstream tags and opens an issue for uncovered versions; it does not automatically rerun the full matrix. `peerDependencies` lists `@deepseek-ai/cordis` and `react` supplied by the host.
329
329
 
330
330
  ## 🚧 Known limitations
331
331
 
package/README.md CHANGED
@@ -22,16 +22,16 @@ DeepSeek Harness 语音双工对话模式:会话内一键进入 → 边说边
22
22
  dsh ≥0.1.7 上按钮挂在发送键左侧(`conversation.input.activity`),更早的版本仍在输入框右侧。状态全部画在按钮上:
23
23
 
24
24
  - **聆听**:绿色三根竖条,随麦克风音量跳动;**朗读中**:蓝色五根竖条,随播放音量跳动;**按住说话**:红色
25
- - **说完就关**(`mode: once`):发出后关麦、转圈等回复,读完显示对勾并自动退出
25
+ - **说完就关**(`mode: once`):发出后关麦、转圈等回复,自然读完显示对勾并自动退出;长按麦克风或按 Ctrl 打断后恢复收音并留在语音模式
26
26
  - **检测到说话**:右上角橙点;**出错**:左上角红点(悬停看原因)
27
27
  - **点击**:平时进入/退出;不在语音模式但正在朗读(`readAloud: always`)时点一下 = 停止朗读;等待回复或朗读期间单击 = 停止朗读并完全退出。点按钮不会抢走输入框的光标
28
28
  - **右键菜单**(鼠标右键或键盘菜单键;触屏长按仍是按住说话):交互模式、朗读回复范围、字幕浮层、状态条、自动发送
29
29
  - 状态条与字幕默认开启;两项都关掉即上图的「全部收进按钮」形态,此时录音计时显示在按钮下方、提示文字显示在按钮旁
30
30
 
31
31
 
32
- > **当前状态(2026-10-28)**:v0.7.34 修复 Kokoro int8/fp32 主模型及固定摘要支持文件下载校验失败;可安装版本以 npm 徽章与 Releases 为准。v0.7.33 不含这项修复。修复使用与既有摘要匹配的上游历史版本,不改模型、音色或缓存目录,请勿关闭摘要校验。
32
+ > **当前状态(2026-11-13)**:v0.7.37 切会话停朗读、once 打断续说、小数点不拆句、启动窗口释放麦克风;可安装版本以 npm 徽章与 Releases 为准。
33
33
 
34
- 兼容跟进(2026-10-30):最新 dsh 0.2.1-rc.5 的锚点、类型与隔离运行时复核通过;完整证据和未验收层见[兼容契约](../../docs/compat-contract.md)。
34
+ 兼容跟进:最新 dsh 0.2.2-rc.3 的锚点、类型与隔离运行时复核通过(含客户端侧);完整证据和未验收层见[兼容契约](../../docs/compat-contract.md)。
35
35
  >
36
36
  > CI 通过不代表真实听感、所有硬件或所有宿主版本均已验证。详见 [CHANGELOG](https://github.com/qishuilalala/dsh-voice-mode/blob/main/CHANGELOG.md)、[兼容证据](https://github.com/qishuilalala/dsh-voice-mode/blob/main/docs/compat-contract.md)和[后续路线图](https://github.com/qishuilalala/dsh-voice-mode/blob/main/docs/plan/roadmap-2026-10.md)。包声明范围为 `>=0.1.1-rc.2 <0.3.0-0`,未测版本不保证。
37
37
 
@@ -40,7 +40,7 @@ dsh ≥0.1.7 上按钮挂在发送键左侧(`conversation.input.activity`)
40
40
 
41
41
  ## 🤝 Fork 增强(本仓库新增)
42
42
 
43
- 本仓库在上游 [haoku123/dsh-voice](https://github.com/haoku123/dsh-voice) 基础上加入了大量增强,核心如下(完整清单见 git 历史与 [docs/rules/STATE.md](https://github.com/qishuilalala/dsh-voice-mode/blob/main/docs/rules/STATE.md)):
43
+ 本仓库在上游 [haoku123/dsh-voice](https://github.com/haoku123/dsh-voice) 基础上加入了大量增强,核心如下(完整清单见 git 历史与[旧账本档案](https://github.com/qishuilalala/dsh-voice-mode/blob/main/docs/rules/archive/STATE-until-2026-11-12.md)):
44
44
 
45
45
  - **朗读默认 Edge 云端;本地 TTS 可选(隐私优先)**:本地合成不向独立在线 TTS 服务发送回复文本,宿主 LLM 的网络请求不受此选项控制——
46
46
  - 本地 VITS(WASM 运行时,`sherpa-onnx-vits-zh-ll`,纯中文,5 说话人);
@@ -63,8 +63,8 @@ dsh ≥0.1.7 上按钮挂在发送键左侧(`conversation.input.activity`)
63
63
  - **三种交互模式(右键麦克风或设置可切换,切换即持久化)**:
64
64
  - `toggle`(默认)持续聆听:RMS VAD 分段 → zipformer2 流式识别(边说边出字,实时字幕预览)→ 静音约 1500 毫秒断句进草稿,连续多段拼成一条消息,再静音约 1.2 秒(合计约 2.7 秒)自动发送;按住 `Ctrl` 强制立即发送
65
65
  - `hold` 按住说话:空闲时**直接按住麦克风按钮就开始录音、松手即发**(不必先点一下进入;短按仍是进入/退出);发出后等回复结束(开朗读则读完)自动退出语音模式;关闭自动发送时松手只把文字留在输入框、不发送并直接退出;按住时没说话约 25 秒后兜底退出;滑出取消、`Esc`/失焦放弃本段;按住期间停顿不断句(上限 10 分钟);`Ctrl` 按住即录、松开即发
66
- - `once` 说完就关:像 `toggle` 一样说一段,发出后关麦,等回复朗读完自动退出语音模式(关闭自动发送时:说完这一段即退出,文字留在草稿)
67
- - **朗读范围**(`readAloud`):`voice`(默认)只朗读语音模式下的回复;`always` 当前可见会话的所有回复都朗读(含打字发的;同一会话开多个标签页只在最后看的那个上播);`off` 从不朗读
66
+ - `once` 说完就关:像 `toggle` 一样说一段,发出后关麦,等回复自然朗读完自动退出语音模式;长按麦克风或按 Ctrl 打断后恢复收音、留在语音模式,下一轮自然读完再退出(关闭自动发送时:说完这一段即退出,文字留在草稿)
67
+ - **朗读范围**(`readAloud`):`voice`(默认)只朗读语音模式下的回复;`always` 当前可见会话的所有回复都朗读(含打字发的;同一会话开多个标签页只在最后看的那个上播;切换会话立即停下原会话朗读,待播内容一并作废);`off` 从不朗读
68
68
  - **唤醒词(可选,默认关)**:设置 `wakeWord` 后进入待机态,说出唤醒词才开始识别(如「你好小D」)。**可直接与命令连说**(「你好小D,帮我查天气」)——唤醒词会在定稿/字幕里自动剥掉、不进消息;匹配带容错(同音字替换「小莫→小墨」、首字错、前置语气词「呃/喂/我说」),建议 3-4 字;待机态状态条实时显示「说『x』开始 · 它听到的转写」,唤醒成败可自查。边界(重要):**仅 `toggle` 模式生效**(`hold` / 手动打断下唤醒词静默失效);**说完整一句后回到待机态需重说唤醒词**(只喊唤醒词、还没说命令时保持聆听,可停顿想好再说);**朗读期说唤醒词不触发**(打断由 VAD 开口即触发,与唤醒词无关)
69
69
  - **字幕档位**:`captionFontSize` 4 档(0=12px / 1=14px / 2=18px / 3=24px)+ `captionMaxWidth` 3 档(0=50vw / 1=70vw / 2=90vw),窄屏自适应
70
70
  - **让位语义**(ADR-0008):`backchannelYield` 默认开—— 朗读期用户插话「嗯/对」自动让位 1.5s,真要说走硬打断;让 LLM 主动让出话轮(人格层让位);关掉恢复改造前行为
@@ -133,8 +133,8 @@ dsh plugin --profile web add dsh-voice-mode
133
133
  | `modelHost` | 默认源 | 模型下载源(国内网络填 `https://hf-mirror.com`) |
134
134
  | `autoSend` | `true` | 静音到点自动发送(连续多段拼成一条消息);关闭则只进草稿(按住 `Ctrl` / hold 松手仍会发送) |
135
135
  | `autoResume` | `false` | 切回上次语音会话时自动恢复语音模式(默认关)。开启后:下次进入语音会话即自动进入语音模式 + 恢复上次会话;关闭则需手动按 `Ctrl+Shift+V` 重新进入 |
136
- | `mode` | `toggle` | 交互模式:`toggle` 持续聆听 + 1500ms 静音断句;`hold` 按住说话、松手发送(短按退出);`once` 说一段、回复读完自动退出 |
137
- | `readAloud` | `voice` | 朗读范围:`voice` 仅语音模式下的回复;`always` 当前可见会话的所有回复(含打字发送);`off` 从不朗读 |
136
+ | `mode` | `toggle` | 交互模式:`toggle` 持续聆听 + 1500ms 静音断句;`hold` 按住说话、松手发送(短按退出);`once` 说一段、回复自然读完自动退出;手动打断后恢复收音并留在语音模式 |
137
+ | `readAloud` | `voice` | 朗读范围:`voice` 仅语音模式下的回复;`always` 当前可见会话的所有回复(含打字发送,切换会话即停止原朗读);`off` 从不朗读 |
138
138
  | `showStatusBar` | `true` | 输入框上方的语音状态条;关闭后状态只显示在麦克风按钮上(计时在按钮下方、提示在按钮旁) |
139
139
  | `showCaptions` | `true` | 朗读时的字幕浮层 |
140
140
  | `shortcut` | `Ctrl+Shift+V` | 进入 / 退出语音模式的快捷键(修饰键 Ctrl/Shift/Alt/Meta + 一个字母 / 数字 / Enter / Space / Tab);设置页「快捷键」分组里可点「录制」直接按组合键录入(`Esc` 取消、`Backspace` 清空,缺修饰键或方向键 / F 键等不支持的键会提示);**留空 = 禁用快捷键**,改用麦克风按钮;**即时生效** |
@@ -312,7 +312,7 @@ flowchart LR
312
312
 
313
313
  ### 兼容声明(插件市场的版本筛选依据)
314
314
 
315
- `package.json` 声明 `engines.dsh = ">=0.1.1-rc.2 <0.3.0-0"`。这是版本准入范围,不代表区间内每个版本都已实测。兼容记录列出了截至 0.2.2-alpha.2 的已测版本及实际测试形态。每周工作流只比对上游标签并为未覆盖版本开 issue,不会自动跑完整矩阵。`peerDependencies` 声明宿主提供的 `@deepseek-ai/cordis` 与 `react`。
315
+ `package.json` 声明 `engines.dsh = ">=0.1.1-rc.2 <0.3.0-0"`。这是版本准入范围,不代表区间内每个版本都已实测。兼容记录列出了截至 0.2.2-rc.3 的已测版本及实际测试形态。默认验证集按“支持区间两端 + 每条小版本线最新已验证版 + latest/next”去重,当前为 9 版锚点/双类型检查、8 核心冒烟。历史实证保留,可用 `verify-dual.sh --full` 或显式版本复验;纯补验不发版。每日工作流比对上游标签并为未覆盖版本开 issue,不会自动跑完整矩阵。`peerDependencies` 声明宿主提供的 `@deepseek-ai/cordis` 与 `react`。
316
316
 
317
317
  ## 🚧 已知限制
318
318
 
package/lib/client.js CHANGED
@@ -1350,7 +1350,7 @@ function createAsrEngine(config, sessionId) {
1350
1350
  const myStopSeq = startSeq;
1351
1351
  const wasActive = active;
1352
1352
  active = false;
1353
- if (!wasActive) {
1353
+ if (!wasActive && !stream && !audioCtx) {
1354
1354
  setState("idle");
1355
1355
  return;
1356
1356
  }
@@ -2547,6 +2547,24 @@ function idleAction(input) {
2547
2547
  if (input.busy && input.sinceUserActivityMs <= IDLE_USER_ACTIVITY_CAP_MS) return "renew";
2548
2548
  return input.warn ? "warn" : "exit";
2549
2549
  }
2550
+ function clampMenuRect(input) {
2551
+ const { menuW, menuH, left, top, right, bottom, vw, vh } = input;
2552
+ if (!(menuW > 0)) return { dx: 0, dy: 0, w: 0 };
2553
+ let dx = 0;
2554
+ let dy = 0;
2555
+ let w = 0;
2556
+ if (right > vw - 8) dx = vw - 8 - right;
2557
+ if (left + dx < 8) dx = 8 - left;
2558
+ if (vw < menuW + 16) w = Math.max(120, vw - 16);
2559
+ if (menuH > 0) {
2560
+ if (bottom > vh - 8) dy = vh - 8 - bottom;
2561
+ if (top + dy < 8) dy = 8 - top;
2562
+ }
2563
+ return { dx, dy, w };
2564
+ }
2565
+ function shouldSkipDraftWriteback(quoteCount, attachCount) {
2566
+ return quoteCount > 0 || attachCount > 0;
2567
+ }
2550
2568
 
2551
2569
  // src/runtime-boot.ts
2552
2570
  var runtimeBoot = null;
@@ -3993,7 +4011,7 @@ function telemetryDeltas(tel) {
3993
4011
  }
3994
4012
  return out;
3995
4013
  }
3996
- var BUILD_TAG = "1d7d07a";
4014
+ var BUILD_TAG = "c8eed54";
3997
4015
  var TELEMETRY_FLAG = "dsh-voice-mode.telemetry";
3998
4016
  var telemetryEnabled = typeof localStorage !== "undefined" && localStorage.getItem(TELEMETRY_FLAG) === "1";
3999
4017
  console.log("[dsh-voice] build=" + BUILD_TAG);
@@ -4706,7 +4724,9 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
4706
4724
  });
4707
4725
  source.addEventListener("focus", (e) => {
4708
4726
  try {
4709
- focusOwnerTab = JSON.parse(e.data).tabId ?? null;
4727
+ const tabId = JSON.parse(e.data).tabId ?? null;
4728
+ if (focusOwnerTab === TAB_ID && tabId !== null && tabId !== TAB_ID && focusedSessionId !== null && (activeSessionId === null || activeSessionId === focusedSessionId)) doSkipAudio(focusedSessionId);
4729
+ focusOwnerTab = tabId;
4710
4730
  } catch {
4711
4731
  }
4712
4732
  });
@@ -4776,6 +4796,7 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
4776
4796
  source.addEventListener("tts-idle", (e) => {
4777
4797
  try {
4778
4798
  const ev = JSON.parse(e.data);
4799
+ if (ev.sessionId && ev.turn !== void 0 && ev.turn < (currentTurn.get(ev.sessionId) ?? ev.turn)) return;
4779
4800
  if (ev.sessionId === activeSessionId && !ui.ttsDrained) {
4780
4801
  ui.ttsDrained = true;
4781
4802
  notify();
@@ -5090,6 +5111,7 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
5090
5111
  if (sessionId === null) {
5091
5112
  const { changed, focused } = focusRelease(focusOwners, owner);
5092
5113
  if (!changed) return;
5114
+ if (focusedSessionId !== focused) doSkipAudio(focusedSessionId);
5093
5115
  focusedSessionId = focused;
5094
5116
  if (focused !== null) {
5095
5117
  if (typeof document === "undefined" || document.visibilityState === "visible") postFocus(focused);
@@ -5099,6 +5121,7 @@ function createVoiceBus(basePath = BASE_PATH2, ctx) {
5099
5121
  return;
5100
5122
  }
5101
5123
  focusClaim(focusOwners, owner, sessionId);
5124
+ if (focusedSessionId !== null && focusedSessionId !== sessionId) doSkipAudio(focusedSessionId);
5102
5125
  focusedSessionId = sessionId;
5103
5126
  if (typeof document === "undefined" || document.visibilityState === "visible") postFocus(sessionId);
5104
5127
  },
@@ -5200,6 +5223,26 @@ function MicMenu({ scope, anchor, onClose }) {
5200
5223
  const [snap, setSnap] = (0, import_react3.useState)(() => scope.getSnapshot());
5201
5224
  (0, import_react3.useEffect)(() => scope.subscribe(() => setSnap({ ...scope.getSnapshot() })), [scope]);
5202
5225
  const menuRef = (0, import_react3.useRef)(null);
5226
+ const [adj, setAdj] = (0, import_react3.useState)(null);
5227
+ (0, import_react3.useEffect)(() => {
5228
+ const id = requestAnimationFrame(() => {
5229
+ const el = menuRef.current;
5230
+ if (!el) return;
5231
+ const rect = el.getBoundingClientRect();
5232
+ const next = clampMenuRect({
5233
+ menuW: el.offsetWidth || 208,
5234
+ menuH: el.offsetHeight || 0,
5235
+ left: rect.left,
5236
+ top: rect.top,
5237
+ right: rect.right,
5238
+ bottom: rect.bottom,
5239
+ vw: window.innerWidth,
5240
+ vh: window.innerHeight
5241
+ });
5242
+ if (next.dx !== 0 || next.dy !== 0 || next.w !== 0) setAdj(next);
5243
+ });
5244
+ return () => cancelAnimationFrame(id);
5245
+ }, []);
5203
5246
  (0, import_react3.useEffect)(() => {
5204
5247
  menuRef.current?.querySelector("button")?.focus();
5205
5248
  const onDown = (e) => {
@@ -5233,9 +5276,10 @@ function MicMenu({ scope, anchor, onClose }) {
5233
5276
  const pos = {
5234
5277
  position: "fixed",
5235
5278
  zIndex: 9999,
5236
- width,
5279
+ width: adj?.w || width,
5237
5280
  left: r ? Math.max(8, Math.min(window.innerWidth - width - 8, Math.round(r.right - width))) : 8,
5238
- ...below ? { top: r ? Math.round(r.bottom + 8) : 96 } : { bottom: Math.round(window.innerHeight - r.top + 8) }
5281
+ ...below ? { top: r ? Math.round(r.bottom + 8) : 96 } : { bottom: Math.round(window.innerHeight - r.top + 8) },
5282
+ ...adj && (adj.dx !== 0 || adj.dy !== 0) ? { transform: `translate(${adj.dx}px, ${adj.dy}px)` } : null
5239
5283
  };
5240
5284
  const item = (role, checked, label, onPick) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { type: "button", role, "aria-checked": checked, className: "dshvm-menu-item", onClick: onPick, children: [
5241
5285
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: label }),
@@ -5668,7 +5712,7 @@ function MicButton({
5668
5712
  onceRef.current = o;
5669
5713
  setOnceWaiting(true);
5670
5714
  void engineRef.current?.stop();
5671
- bus.setUi({ partial: "", levels: [], isSpeech: void 0 });
5715
+ bus.setUi({ partial: "", levels: [], isSpeech: void 0, ttsDrained: false });
5672
5716
  checkOnce();
5673
5717
  };
5674
5718
  const exitMode = async (reason) => {
@@ -5751,6 +5795,11 @@ function MicButton({
5751
5795
  sessionId: sid
5752
5796
  });
5753
5797
  const hardBreak = async () => {
5798
+ const resumeOnce = bootNow().mode === "once" && onceRef.current !== null;
5799
+ if (resumeOnce) {
5800
+ clearOnce();
5801
+ resetIdle();
5802
+ }
5754
5803
  bus.skipAudio();
5755
5804
  bus.unduckAudio();
5756
5805
  cancelAutoSend();
@@ -5774,7 +5823,13 @@ function MicButton({
5774
5823
  signal: AbortSignal.timeout(3e3)
5775
5824
  }).catch(() => {
5776
5825
  });
5777
- if (engineRef.current && !engineRef.current.holding) await engineRef.current.discardSegment();
5826
+ if (resumeOnce) {
5827
+ const eng = engineRef.current;
5828
+ void eng?.start().then(() => {
5829
+ if (engineRef.current !== eng || localRef.current !== "on" || !mountedRef.current) return;
5830
+ if (manualHoldRef.current || toggleHoldRef.current) eng.beginHeld();
5831
+ }).catch(() => bus.setUi({ error: t("micUnavailable") }));
5832
+ } else if (engineRef.current && !engineRef.current.holding) await engineRef.current.discardSegment();
5778
5833
  await cancelP;
5779
5834
  bus.setUi({ partial: "\u2026" });
5780
5835
  if (breakDotsTimerRef.current) clearTimeout(breakDotsTimerRef.current);
@@ -5973,6 +6028,7 @@ function MicButton({
5973
6028
  const composed = composeDraft(draftRef.current, lastPartialRef.current, text);
5974
6029
  if (!composed) return;
5975
6030
  lastPartialRef.current = text.trim();
6031
+ if (shouldSkipDraftWriteback(quoteRef.current, attachRef.current)) return;
5976
6032
  try {
5977
6033
  partialActions.setDraft(composed);
5978
6034
  } catch {
@@ -5998,12 +6054,14 @@ function MicButton({
5998
6054
  if (!trimmed) return;
5999
6055
  let nextDraft = composeDraft(draftRef.current, lastPartialRef.current, trimmed);
6000
6056
  lastPartialRef.current = "";
6001
- try {
6002
- if (typeof actions?.setDraft === "function") actions.setDraft(nextDraft);
6003
- } catch {
6057
+ if (!shouldSkipDraftWriteback(quoteRef.current, attachRef.current)) {
6004
6058
  try {
6005
- actions?.setDraft?.(trimmed);
6059
+ if (typeof actions?.setDraft === "function") actions.setDraft(nextDraft);
6006
6060
  } catch {
6061
+ try {
6062
+ actions?.setDraft?.(trimmed);
6063
+ } catch {
6064
+ }
6007
6065
  }
6008
6066
  }
6009
6067
  if (meta?.force) {
@@ -6236,7 +6294,7 @@ function MicButton({
6236
6294
  return;
6237
6295
  }
6238
6296
  const eng = engineRef.current;
6239
- if (e.key === "Control" && !e.shiftKey && !e.altKey && !e.metaKey && !e.repeat && eng && !onceRef.current) {
6297
+ if (e.key === "Control" && !e.shiftKey && !e.altKey && !e.metaKey && !e.repeat && eng && (!onceRef.current || bootNow().mode === "once")) {
6240
6298
  ctrlHoldStart = Date.now();
6241
6299
  otherKeyDuringCtrl = false;
6242
6300
  if (bootNow().mode === "hold") {
@@ -6246,7 +6304,7 @@ function MicButton({
6246
6304
  setHolding(true);
6247
6305
  eng.beginHeld();
6248
6306
  }, 600);
6249
- } else if (bootNow().bargeInMode === "manual" && bus.ui.playing) {
6307
+ } else if (bootNow().bargeInMode === "manual" && bus.ui.playing || bootNow().mode === "once" && onceRef.current) {
6250
6308
  manualHoldRef.current = true;
6251
6309
  setHolding(true);
6252
6310
  eng.beginHeld();
@@ -6349,6 +6407,12 @@ function MicButton({
6349
6407
  const liveDraft = useInput ? useInput((s) => s?.draft ?? "") : "";
6350
6408
  const draftRef = (0, import_react3.useRef)("");
6351
6409
  draftRef.current = liveDraft;
6410
+ const liveQuoteCount = useInput ? useInput((s) => s?.quotes?.length ?? 0) : 0;
6411
+ const liveAttachCount = useInput ? useInput((s) => s?.attachmentIds?.length ?? 0) : 0;
6412
+ const quoteRef = (0, import_react3.useRef)(0);
6413
+ quoteRef.current = liveQuoteCount;
6414
+ const attachRef = (0, import_react3.useRef)(0);
6415
+ attachRef.current = liveAttachCount;
6352
6416
  const lastPartialRef = (0, import_react3.useRef)("");
6353
6417
  const submitInFlightRef = (0, import_react3.useRef)(false);
6354
6418
  const correctCycleRef = (0, import_react3.useRef)(0);
@@ -6473,14 +6537,14 @@ function MicButton({
6473
6537
  }, 250);
6474
6538
  }
6475
6539
  }
6476
- } else if (localRef.current === "on" && bus.ui.playing && !onceRef.current) {
6540
+ } else if (localRef.current === "on" && (bus.ui.playing && !onceRef.current || bootNow().mode === "once" && onceRef.current)) {
6477
6541
  toggleHoldRef.current = true;
6478
6542
  setHolding(true);
6479
6543
  const eng = engineRef.current;
6480
6544
  eng?.beginHeld();
6481
6545
  breakTimerRef.current = setTimeout(() => {
6482
6546
  breakTimerRef.current = null;
6483
- if (holdPtrRef.current && bus.ui.playing) void breakRef.current?.();
6547
+ if (holdPtrRef.current && (bus.ui.playing || onceRef.current)) void breakRef.current?.();
6484
6548
  }, 250);
6485
6549
  }
6486
6550
  };
package/lib/index.js CHANGED
@@ -1155,6 +1155,7 @@ function splitSentences(chunk) {
1155
1155
  let lastEnd = 0;
1156
1156
  while ((m = re.exec(chunk)) !== null) {
1157
1157
  const end = m.index + m[0].length;
1158
+ if (m[0] === "." && end === chunk.length && /\d/.test(chunk[m.index - 1] ?? "")) continue;
1158
1159
  sentences.push(chunk.slice(start, end));
1159
1160
  start = end;
1160
1161
  lastEnd = end;
@@ -1683,7 +1684,7 @@ var TtsQueue = class {
1683
1684
  q.epoch++;
1684
1685
  q.pending.length = 0;
1685
1686
  }
1686
- this.engine.interrupt?.();
1687
+ if (![...this.queues].some(([sid, other]) => sid !== sessionId && other.busy)) this.engine.interrupt?.();
1687
1688
  }
1688
1689
  /** 会话退出/被抢占时彻底清理其队列(防止 Map 长期累积)。 */
1689
1690
  prune(sessionId) {
@@ -3216,6 +3217,11 @@ function apply(ctx, config) {
3216
3217
  if (sessionId === null || sessionId === activeVoiceSession || tapInFlight.has(sessionId)) return;
3217
3218
  dropTurnTables(sessionId);
3218
3219
  };
3220
+ const stopFocusReading = (sessionId) => {
3221
+ if (sessionId === null) return;
3222
+ queue.cancel(sessionId);
3223
+ turnGen.set(sessionId, (turnGen.get(sessionId) ?? 0) + 1);
3224
+ };
3219
3225
  const sessions = ctx.get("sessions");
3220
3226
  const limiter = new RateLimiter();
3221
3227
  const limiterPrune = setInterval(() => limiter.prune(Date.now(), 6e4), 6e4);
@@ -3391,7 +3397,7 @@ function apply(ctx, config) {
3391
3397
  // 单句重试耗尽被跳过:显式下行(客户端提示 + 诊断),不再静默丢句。
3392
3398
  // streak = 连续被跳过的句数:客户端据此区分偶发抖动与「云端整体不可用」(如服务端拒绝握手)。
3393
3399
  onSkip: (sessionId, text, streak) => broadcast("tts-skip", { sessionId, text: text.slice(0, 80), streak }),
3394
- onIdle: (sessionId) => broadcast("tts-idle", { sessionId }),
3400
+ onIdle: (sessionId) => broadcast("tts-idle", { sessionId, turn: turnOfSession.get(sessionId)?.turn }),
3395
3401
  // R15(Issue #15 Important-2 host 侧接线):onIdle 降级为「候选空闲」——「队列排空」不等于
3396
3402
  // 「回合结束」。带工具调用的回合会在工具执行期间把队列排空一次,据此发 tts-idle 会让
3397
3403
  // mode:once 在空档里提前 exitMode(麦克风熄灭、后半段回复永不朗读)。置 true 后 tts-idle
@@ -3497,7 +3503,7 @@ function apply(ctx, config) {
3497
3503
  setTurn(sessionId, state, turn);
3498
3504
  },
3499
3505
  vset.readAloud !== "off",
3500
- () => readMuted.has(sessionId)
3506
+ () => readMuted.has(sessionId) || turnGen.get(sessionId) !== gen
3501
3507
  );
3502
3508
  });
3503
3509
  ctx.on("agent/turn-stopping", ({ agent }) => queue.noteTurnEnd(agent.id));
@@ -4065,6 +4071,7 @@ function apply(ctx, config) {
4065
4071
  focusedSessionId = null;
4066
4072
  focusedTabId = null;
4067
4073
  }
4074
+ if (prevFocus !== null && prevFocus !== focusedSessionId) stopFocusReading(prevFocus);
4068
4075
  if (prevFocus !== null && prevFocus !== focusedSessionId) reclaimFocusState(prevFocus);
4069
4076
  broadcast("focus", { sessionId: focusedSessionId, tabId: focusedTabId });
4070
4077
  respondJson2(res, 200, { ok: true, sessionId: focusedSessionId, tabId: focusedTabId });
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "dsh-voice-mode",
3
3
  "description": "Voice plugin for DeepSeek Harness: local streaming speech recognition into editable drafts, sentence-by-sentence read-aloud with captions, and voice interruption. Edge online or local VITS/Kokoro TTS; host compatibility is bounded by engines.dsh.",
4
4
  "icon": "./icon.svg",
5
- "version": "0.7.36",
5
+ "version": "0.7.38",
6
6
  "type": "module",
7
7
  "main": "lib/index.js",
8
8
  "repository": {
@@ -47,8 +47,9 @@
47
47
  ],
48
48
  "scripts": {
49
49
  "build": "node build.mjs",
50
+ "check:lib-drift": "node scripts/check-lib-drift.mjs",
50
51
  "prepack": "node build.mjs",
51
- "test": "node test/segmenter.test.mjs && node test/aec.test.mjs && node test/download.test.mjs && node test/endpoint.test.mjs && node test/endpoint-short.test.mjs && node test/resample.test.mjs && node test/sense-worker.test.mjs && node test/detect-route.test.mjs && node test/verify-client.mjs && node test/asr-host-rebuild.test.mjs && node test/barge-in-manual.test.mjs && node test/barge-in-detect-behavior.test.mjs && node test/sense-lang.test.mjs && node test/caption-a11y.test.mjs && node test/emotion.test.mjs && node test/emotion-tts-local.test.mjs && node test/emotion-integration.test.mjs && node test/backchannel.test.mjs && node test/strings-coverage.test.mjs && node test/yield-ms-wiring.test.mjs && node test/fail-streak-notice.test.mjs && node test/partial-gating.test.mjs && node test/asr-lifecycle.test.mjs && node test/steer-submit-behavior.test.mjs && node test/correct-cycle-behavior.test.mjs && node test/host-security-behavior.test.mjs && node test/echo-tail.test.mjs && node test/host-fixes.test.mjs && node test/tts-queue-engine.test.mjs && node test/matchBackchannel.test.mjs && node test/settings-load.test.mjs && node test/preview-error.test.mjs && node test/hold-clear.test.mjs && node test/barge-in-detect.test.mjs && node test/wakeword.test.mjs && node test/wake-standby.test.mjs && node test/wake-flow.test.mjs && node test/tts-playback.test.mjs && node test/settings-store.test.mjs && node test/i18n.test.mjs && node test/i18n-protocol.test.mjs && node test/package-install.test.mjs && node test/tts-runtime.test.mjs && node test/steer-submit.test.mjs && node test/draft-compose.test.mjs && node test/finalize-ux.test.mjs && node test/llm-correct.test.mjs && node test/autosend-decouple.test.mjs && node test/settings-effective.test.mjs && node test/silent-path-hints.test.mjs && node test/host-hardening.test.mjs && node test/mic-gesture.test.mjs && node test/shortcut-ui.test.mjs && node test/focus-ownership.test.mjs && node test/finalize-concurrency.test.mjs && node test/telemetry-final-ready.test.mjs && node test/hold-cancel-watermark.test.mjs && node test/idle-activity.test.mjs && node test/tts-edge-escape.test.mjs && node test/tts-empty-audio.test.mjs && node test/partial-202-retry.test.mjs && node test/enter-fail-mic-leak.test.mjs && node test/silence-playing-guard.test.mjs && node test/salvage-seed-cross-sentence.test.mjs && node test/model-download-idle.test.mjs && node test/model-tree-offline.test.mjs && node test/model-sha-cache.test.mjs && node test/tts-local-rpc-timeout.test.mjs && node test/asr-progress-clear.test.mjs && node test/sse-backpressure.test.mjs && node test/sse-teardown.test.mjs && node test/settings-scope-timeout.test.mjs && node test/enter-timeout-cancel.test.mjs && node test/audio-fallback-reset.test.mjs && node test/statusbar-aria.test.mjs && node test/llm-correct-similarity.test.mjs",
52
+ "test": "node scripts/run-tests.mjs",
52
53
  "verify:client": "node test/verify-client.mjs",
53
54
  "prefetch": "node scripts/prefetch.mjs",
54
55
  "list-voices": "node scripts/list-voices.mjs",