aicodeman 1.49.0 → 1.50.1

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.
Files changed (324) hide show
  1. package/README.md +30 -4
  2. package/dist/cli-install-runner.d.ts +112 -0
  3. package/dist/cli-install-runner.d.ts.map +1 -0
  4. package/dist/cli-install-runner.js +289 -0
  5. package/dist/cli-install-runner.js.map +1 -0
  6. package/dist/cli.d.ts.map +1 -1
  7. package/dist/cli.js +2 -2
  8. package/dist/cli.js.map +1 -1
  9. package/dist/config/attachment-guard.d.ts +11 -0
  10. package/dist/config/attachment-guard.d.ts.map +1 -1
  11. package/dist/config/attachment-guard.js +21 -1
  12. package/dist/config/attachment-guard.js.map +1 -1
  13. package/dist/config/local-model-catalog.d.ts +188 -0
  14. package/dist/config/local-model-catalog.d.ts.map +1 -0
  15. package/dist/config/local-model-catalog.js +556 -0
  16. package/dist/config/local-model-catalog.js.map +1 -0
  17. package/dist/config-backup.js +1 -1
  18. package/dist/config-backup.js.map +1 -1
  19. package/dist/custom-model-hosts-writer.d.ts +50 -0
  20. package/dist/custom-model-hosts-writer.d.ts.map +1 -0
  21. package/dist/custom-model-hosts-writer.js +110 -0
  22. package/dist/custom-model-hosts-writer.js.map +1 -0
  23. package/dist/git-clone.d.ts.map +1 -1
  24. package/dist/git-clone.js +21 -1
  25. package/dist/git-clone.js.map +1 -1
  26. package/dist/git-fetch.d.ts.map +1 -1
  27. package/dist/git-fetch.js +6 -0
  28. package/dist/git-fetch.js.map +1 -1
  29. package/dist/git-workspace-status.d.ts.map +1 -1
  30. package/dist/git-workspace-status.js +4 -0
  31. package/dist/git-workspace-status.js.map +1 -1
  32. package/dist/git-worktrees.d.ts.map +1 -1
  33. package/dist/git-worktrees.js +6 -0
  34. package/dist/git-worktrees.js.map +1 -1
  35. package/dist/hooks-config.d.ts +15 -3
  36. package/dist/hooks-config.d.ts.map +1 -1
  37. package/dist/hooks-config.js +108 -4
  38. package/dist/hooks-config.js.map +1 -1
  39. package/dist/live-worktree.d.ts +73 -15
  40. package/dist/live-worktree.d.ts.map +1 -1
  41. package/dist/live-worktree.js +200 -32
  42. package/dist/live-worktree.js.map +1 -1
  43. package/dist/local-model/connect.d.ts +155 -0
  44. package/dist/local-model/connect.d.ts.map +1 -0
  45. package/dist/local-model/connect.js +243 -0
  46. package/dist/local-model/connect.js.map +1 -0
  47. package/dist/local-model/developer-tools.d.ts +45 -0
  48. package/dist/local-model/developer-tools.d.ts.map +1 -0
  49. package/dist/local-model/developer-tools.js +105 -0
  50. package/dist/local-model/developer-tools.js.map +1 -0
  51. package/dist/local-model/format.d.ts +39 -0
  52. package/dist/local-model/format.d.ts.map +1 -0
  53. package/dist/local-model/format.js +48 -0
  54. package/dist/local-model/format.js.map +1 -0
  55. package/dist/local-model/hardware.d.ts +125 -0
  56. package/dist/local-model/hardware.d.ts.map +1 -0
  57. package/dist/local-model/hardware.js +336 -0
  58. package/dist/local-model/hardware.js.map +1 -0
  59. package/dist/local-model/harness-facts.d.ts +77 -0
  60. package/dist/local-model/harness-facts.d.ts.map +1 -0
  61. package/dist/local-model/harness-facts.js +145 -0
  62. package/dist/local-model/harness-facts.js.map +1 -0
  63. package/dist/local-model/install-job.d.ts +431 -0
  64. package/dist/local-model/install-job.d.ts.map +1 -0
  65. package/dist/local-model/install-job.js +1822 -0
  66. package/dist/local-model/install-job.js.map +1 -0
  67. package/dist/local-model/ollama-client.d.ts +216 -0
  68. package/dist/local-model/ollama-client.d.ts.map +1 -0
  69. package/dist/local-model/ollama-client.js +636 -0
  70. package/dist/local-model/ollama-client.js.map +1 -0
  71. package/dist/local-model/paths.d.ts +64 -0
  72. package/dist/local-model/paths.d.ts.map +1 -0
  73. package/dist/local-model/paths.js +75 -0
  74. package/dist/local-model/paths.js.map +1 -0
  75. package/dist/local-model/recommend.d.ts +118 -0
  76. package/dist/local-model/recommend.d.ts.map +1 -0
  77. package/dist/local-model/recommend.js +430 -0
  78. package/dist/local-model/recommend.js.map +1 -0
  79. package/dist/local-model/runtime.d.ts +339 -0
  80. package/dist/local-model/runtime.d.ts.map +1 -0
  81. package/dist/local-model/runtime.js +1240 -0
  82. package/dist/local-model/runtime.js.map +1 -0
  83. package/dist/local-model/state-store.d.ts +45 -0
  84. package/dist/local-model/state-store.d.ts.map +1 -0
  85. package/dist/local-model/state-store.js +261 -0
  86. package/dist/local-model/state-store.js.map +1 -0
  87. package/dist/readmymind-collectors.d.ts.map +1 -1
  88. package/dist/readmymind-collectors.js +4 -0
  89. package/dist/readmymind-collectors.js.map +1 -1
  90. package/dist/reboot-restore.d.ts +3 -1
  91. package/dist/reboot-restore.d.ts.map +1 -1
  92. package/dist/reboot-restore.js.map +1 -1
  93. package/dist/session.d.ts +29 -7
  94. package/dist/session.d.ts.map +1 -1
  95. package/dist/session.js +63 -10
  96. package/dist/session.js.map +1 -1
  97. package/dist/types/common.d.ts +5 -0
  98. package/dist/types/common.d.ts.map +1 -1
  99. package/dist/types/index.d.ts +4 -0
  100. package/dist/types/index.d.ts.map +1 -1
  101. package/dist/types/index.js +4 -0
  102. package/dist/types/index.js.map +1 -1
  103. package/dist/types/local-model-install.d.ts +533 -0
  104. package/dist/types/local-model-install.d.ts.map +1 -0
  105. package/dist/types/local-model-install.js +169 -0
  106. package/dist/types/local-model-install.js.map +1 -0
  107. package/dist/types/local-model.d.ts +551 -0
  108. package/dist/types/local-model.d.ts.map +1 -0
  109. package/dist/types/local-model.js +115 -0
  110. package/dist/types/local-model.js.map +1 -0
  111. package/dist/types/session.d.ts +17 -6
  112. package/dist/types/session.d.ts.map +1 -1
  113. package/dist/types/session.js.map +1 -1
  114. package/dist/utils/cli-executable-resolver.d.ts +18 -0
  115. package/dist/utils/cli-executable-resolver.d.ts.map +1 -1
  116. package/dist/utils/cli-executable-resolver.js +34 -2
  117. package/dist/utils/cli-executable-resolver.js.map +1 -1
  118. package/dist/utils/git-availability.d.ts +65 -0
  119. package/dist/utils/git-availability.d.ts.map +1 -0
  120. package/dist/utils/git-availability.js +134 -0
  121. package/dist/utils/git-availability.js.map +1 -0
  122. package/dist/web/agent-skill-default-migration.d.ts +60 -0
  123. package/dist/web/agent-skill-default-migration.d.ts.map +1 -0
  124. package/dist/web/agent-skill-default-migration.js +97 -0
  125. package/dist/web/agent-skill-default-migration.js.map +1 -0
  126. package/dist/web/approval-inbox.d.ts +10 -0
  127. package/dist/web/approval-inbox.d.ts.map +1 -1
  128. package/dist/web/approval-inbox.js +15 -0
  129. package/dist/web/approval-inbox.js.map +1 -1
  130. package/dist/web/case-state-sync.d.ts +28 -0
  131. package/dist/web/case-state-sync.d.ts.map +1 -0
  132. package/dist/web/case-state-sync.js +41 -0
  133. package/dist/web/case-state-sync.js.map +1 -0
  134. package/dist/web/ports/config-port.d.ts +1 -1
  135. package/dist/web/ports/config-port.d.ts.map +1 -1
  136. package/dist/web/public/admin-ui.js.gz +0 -0
  137. package/dist/web/public/api-client.c9b1cddc.js.gz +0 -0
  138. package/dist/web/public/{app.9ea37070.js → app.07398d90.js} +1 -1
  139. package/dist/web/public/app.07398d90.js.br +0 -0
  140. package/dist/web/public/app.07398d90.js.gz +0 -0
  141. package/dist/web/public/approvals-ui.js.gz +0 -0
  142. package/dist/web/public/constants.782170e1.js.gz +0 -0
  143. package/dist/web/public/cron-ui.js.gz +0 -0
  144. package/dist/web/public/edit-history-ui.js.gz +0 -0
  145. package/dist/web/public/entrance-animations.js.gz +0 -0
  146. package/dist/web/public/foreign-sessions.js.gz +0 -0
  147. package/dist/web/public/git-status-ui.js.gz +0 -0
  148. package/dist/web/public/header-divider.eb2d2463.js.gz +0 -0
  149. package/dist/web/public/home-sessions.js +38 -18
  150. package/dist/web/public/home-sessions.js.br +0 -0
  151. package/dist/web/public/home-sessions.js.gz +0 -0
  152. package/dist/web/public/host-wake-ui.js.gz +0 -0
  153. package/dist/web/public/{i18n.a5e82c95.js → i18n.519d025e.js} +2 -2
  154. package/dist/web/public/i18n.519d025e.js.br +0 -0
  155. package/dist/web/public/i18n.519d025e.js.gz +0 -0
  156. package/dist/web/public/image-input.a5d0f8f3.js.gz +0 -0
  157. package/dist/web/public/index.html +88 -13
  158. package/dist/web/public/index.html.br +0 -0
  159. package/dist/web/public/index.html.gz +0 -0
  160. package/dist/web/public/input-cjk.8bc46081.js.gz +0 -0
  161. package/dist/web/public/{keyboard-accessory.b941676c.js → keyboard-accessory.0800fc44.js} +160 -2
  162. package/dist/web/public/keyboard-accessory.0800fc44.js.br +0 -0
  163. package/dist/web/public/keyboard-accessory.0800fc44.js.gz +0 -0
  164. package/dist/web/public/local-model-ui.js +1735 -0
  165. package/dist/web/public/local-model-ui.js.br +0 -0
  166. package/dist/web/public/local-model-ui.js.gz +0 -0
  167. package/dist/web/public/mobile-handlers.f7c3f692.js.gz +0 -0
  168. package/dist/web/public/mobile-ime-preview.2dbaf262.js.gz +0 -0
  169. package/dist/web/public/mobile-overview.js +30 -14
  170. package/dist/web/public/mobile-overview.js.br +0 -0
  171. package/dist/web/public/mobile-overview.js.gz +0 -0
  172. package/dist/web/public/mobile.4dfd5c55.css +1 -0
  173. package/dist/web/public/mobile.4dfd5c55.css.br +0 -0
  174. package/dist/web/public/mobile.4dfd5c55.css.gz +0 -0
  175. package/dist/web/public/notification-manager.feb82c04.js.gz +0 -0
  176. package/dist/web/public/orchestrator-panel.js.gz +0 -0
  177. package/dist/web/public/{panels-ui.8bcd4473.js → panels-ui.9ba2683e.js} +100 -98
  178. package/dist/web/public/panels-ui.9ba2683e.js.br +0 -0
  179. package/dist/web/public/panels-ui.9ba2683e.js.gz +0 -0
  180. package/dist/web/public/ralph-panel.b350e2ef.js.gz +0 -0
  181. package/dist/web/public/ralph-wizard.b6c0dd19.js.gz +0 -0
  182. package/dist/web/public/readmymind-ui.js.gz +0 -0
  183. package/dist/web/public/reboot-restore-ui.js +2 -0
  184. package/dist/web/public/reboot-restore-ui.js.br +0 -0
  185. package/dist/web/public/reboot-restore-ui.js.gz +0 -0
  186. package/dist/web/public/respawn-ui.304ba0d4.js.gz +0 -0
  187. package/dist/web/public/sanitize-html.e7147e76.js.gz +0 -0
  188. package/dist/web/public/session-lineage.js.gz +0 -0
  189. package/dist/web/public/{session-ui.a7c8c095.js → session-ui.8f300b14.js} +21 -21
  190. package/dist/web/public/session-ui.8f300b14.js.br +0 -0
  191. package/dist/web/public/session-ui.8f300b14.js.gz +0 -0
  192. package/dist/web/public/{settings-ui.18f92052.js → settings-ui.8b37cf07.js} +14 -14
  193. package/dist/web/public/settings-ui.8b37cf07.js.br +0 -0
  194. package/dist/web/public/settings-ui.8b37cf07.js.gz +0 -0
  195. package/dist/web/public/spreadsheet-preview-worker.js.gz +0 -0
  196. package/dist/web/public/spreadsheet-preview.75c751de.js.gz +0 -0
  197. package/dist/web/public/spreadsheet-xlsx-core.js.gz +0 -0
  198. package/dist/web/public/styles.21b93520.css +1 -0
  199. package/dist/web/public/styles.21b93520.css.br +0 -0
  200. package/dist/web/public/styles.21b93520.css.gz +0 -0
  201. package/dist/web/public/subagent-windows.07277a58.js.gz +0 -0
  202. package/dist/web/public/sw.js +2 -2
  203. package/dist/web/public/sw.js.br +0 -0
  204. package/dist/web/public/sw.js.gz +0 -0
  205. package/dist/web/public/tab-layout-browser.2d6189f7.js.gz +0 -0
  206. package/dist/web/public/tab-rail-resize.b5cdceaf.js.gz +0 -0
  207. package/dist/web/public/terminal-keycode229-recovery.98843069.js.gz +0 -0
  208. package/dist/web/public/terminal-split.js.gz +0 -0
  209. package/dist/web/public/terminal-tile.js.gz +0 -0
  210. package/dist/web/public/{terminal-ui.a7883640.js → terminal-ui.f92eae28.js} +2 -2
  211. package/dist/web/public/terminal-ui.f92eae28.js.br +0 -0
  212. package/dist/web/public/terminal-ui.f92eae28.js.gz +0 -0
  213. package/dist/web/public/tile-grid.js.gz +0 -0
  214. package/dist/web/public/ultracode-panel.js.gz +0 -0
  215. package/dist/web/public/ultracode-windows.js.gz +0 -0
  216. package/dist/web/public/vendor/dompurify.min.js.gz +0 -0
  217. package/dist/web/public/vendor/exceljs.min.js.gz +0 -0
  218. package/dist/web/public/vendor/fflate.min.js.gz +0 -0
  219. package/dist/web/public/vendor/marked.min.js.gz +0 -0
  220. package/dist/web/public/vendor/xterm-addon-fit.min.js.gz +0 -0
  221. package/dist/web/public/vendor/xterm-addon-serialize.min.js.gz +0 -0
  222. package/dist/web/public/vendor/xterm-addon-unicode11.min.js.gz +0 -0
  223. package/dist/web/public/vendor/xterm-addon-webgl.min.js.gz +0 -0
  224. package/dist/web/public/vendor/xterm-predictive-echo.276b11d9.js.gz +0 -0
  225. package/dist/web/public/vendor/xterm-zerolag-input.1be42307.js.gz +0 -0
  226. package/dist/web/public/vendor/xterm.css.gz +0 -0
  227. package/dist/web/public/vendor/xterm.min.js.gz +0 -0
  228. package/dist/web/public/{voice-input.2342c37b.js → voice-input.d0580528.js} +232 -137
  229. package/dist/web/public/voice-input.d0580528.js.br +0 -0
  230. package/dist/web/public/voice-input.d0580528.js.gz +0 -0
  231. package/dist/web/public/voice-pcm-worklet.js.gz +0 -0
  232. package/dist/web/public/webview-tabs.js.gz +0 -0
  233. package/dist/web/public/whats-new.json +9 -9
  234. package/dist/web/repo-status.d.ts.map +1 -1
  235. package/dist/web/repo-status.js +4 -0
  236. package/dist/web/repo-status.js.map +1 -1
  237. package/dist/web/route-helpers.d.ts +29 -0
  238. package/dist/web/route-helpers.d.ts.map +1 -1
  239. package/dist/web/route-helpers.js +37 -0
  240. package/dist/web/route-helpers.js.map +1 -1
  241. package/dist/web/routes/approval-routes.d.ts.map +1 -1
  242. package/dist/web/routes/approval-routes.js +3 -2
  243. package/dist/web/routes/approval-routes.js.map +1 -1
  244. package/dist/web/routes/case-routes.d.ts.map +1 -1
  245. package/dist/web/routes/case-routes.js +31 -5
  246. package/dist/web/routes/case-routes.js.map +1 -1
  247. package/dist/web/routes/cli-registry-routes.d.ts +1 -27
  248. package/dist/web/routes/cli-registry-routes.d.ts.map +1 -1
  249. package/dist/web/routes/cli-registry-routes.js +11 -202
  250. package/dist/web/routes/cli-registry-routes.js.map +1 -1
  251. package/dist/web/routes/custom-model-routes.d.ts +15 -0
  252. package/dist/web/routes/custom-model-routes.d.ts.map +1 -1
  253. package/dist/web/routes/custom-model-routes.js +114 -33
  254. package/dist/web/routes/custom-model-routes.js.map +1 -1
  255. package/dist/web/routes/file-routes.d.ts +4 -2
  256. package/dist/web/routes/file-routes.d.ts.map +1 -1
  257. package/dist/web/routes/file-routes.js +160 -24
  258. package/dist/web/routes/file-routes.js.map +1 -1
  259. package/dist/web/routes/html-view-routes.d.ts.map +1 -1
  260. package/dist/web/routes/html-view-routes.js +12 -3
  261. package/dist/web/routes/html-view-routes.js.map +1 -1
  262. package/dist/web/routes/index.d.ts +1 -0
  263. package/dist/web/routes/index.d.ts.map +1 -1
  264. package/dist/web/routes/index.js +1 -0
  265. package/dist/web/routes/index.js.map +1 -1
  266. package/dist/web/routes/local-model-routes.d.ts +103 -0
  267. package/dist/web/routes/local-model-routes.d.ts.map +1 -0
  268. package/dist/web/routes/local-model-routes.js +210 -0
  269. package/dist/web/routes/local-model-routes.js.map +1 -0
  270. package/dist/web/routes/reboot-restore-routes.d.ts.map +1 -1
  271. package/dist/web/routes/reboot-restore-routes.js +16 -0
  272. package/dist/web/routes/reboot-restore-routes.js.map +1 -1
  273. package/dist/web/routes/session-routes.d.ts.map +1 -1
  274. package/dist/web/routes/session-routes.js +22 -27
  275. package/dist/web/routes/session-routes.js.map +1 -1
  276. package/dist/web/routes/system-routes.d.ts +2 -2
  277. package/dist/web/routes/system-routes.d.ts.map +1 -1
  278. package/dist/web/routes/system-routes.js +23 -4
  279. package/dist/web/routes/system-routes.js.map +1 -1
  280. package/dist/web/schemas.d.ts +30 -0
  281. package/dist/web/schemas.d.ts.map +1 -1
  282. package/dist/web/schemas.js +52 -5
  283. package/dist/web/schemas.js.map +1 -1
  284. package/dist/web/self-update.d.ts.map +1 -1
  285. package/dist/web/self-update.js +4 -0
  286. package/dist/web/self-update.js.map +1 -1
  287. package/dist/web/sensitive-path.d.ts.map +1 -1
  288. package/dist/web/sensitive-path.js +5 -0
  289. package/dist/web/sensitive-path.js.map +1 -1
  290. package/dist/web/server.d.ts +20 -0
  291. package/dist/web/server.d.ts.map +1 -1
  292. package/dist/web/server.js +83 -7
  293. package/dist/web/server.js.map +1 -1
  294. package/dist/web/voice-stream.d.ts +4 -3
  295. package/dist/web/voice-stream.d.ts.map +1 -1
  296. package/dist/web/voice-stream.js +5 -4
  297. package/dist/web/voice-stream.js.map +1 -1
  298. package/package.json +2 -1
  299. package/skills/codeman/SKILL.md +318 -24
  300. package/skills/codeman/preamble.sh +242 -16
  301. package/skills/codeman/reference/recipes.md +1 -1
  302. package/skills/codeman/reference/verbs.md +101 -1
  303. package/dist/web/public/app.9ea37070.js.br +0 -0
  304. package/dist/web/public/app.9ea37070.js.gz +0 -0
  305. package/dist/web/public/i18n.a5e82c95.js.br +0 -0
  306. package/dist/web/public/i18n.a5e82c95.js.gz +0 -0
  307. package/dist/web/public/keyboard-accessory.b941676c.js.br +0 -0
  308. package/dist/web/public/keyboard-accessory.b941676c.js.gz +0 -0
  309. package/dist/web/public/mobile.67c8eb5b.css +0 -1
  310. package/dist/web/public/mobile.67c8eb5b.css.br +0 -0
  311. package/dist/web/public/mobile.67c8eb5b.css.gz +0 -0
  312. package/dist/web/public/panels-ui.8bcd4473.js.br +0 -0
  313. package/dist/web/public/panels-ui.8bcd4473.js.gz +0 -0
  314. package/dist/web/public/session-ui.a7c8c095.js.br +0 -0
  315. package/dist/web/public/session-ui.a7c8c095.js.gz +0 -0
  316. package/dist/web/public/settings-ui.18f92052.js.br +0 -0
  317. package/dist/web/public/settings-ui.18f92052.js.gz +0 -0
  318. package/dist/web/public/styles.6a718331.css +0 -1
  319. package/dist/web/public/styles.6a718331.css.br +0 -0
  320. package/dist/web/public/styles.6a718331.css.gz +0 -0
  321. package/dist/web/public/terminal-ui.a7883640.js.br +0 -0
  322. package/dist/web/public/terminal-ui.a7883640.js.gz +0 -0
  323. package/dist/web/public/voice-input.2342c37b.js.br +0 -0
  324. package/dist/web/public/voice-input.2342c37b.js.gz +0 -0
@@ -14,11 +14,11 @@
14
14
  * auto-detects MIME type (opus/webm/mp4), and supports custom key terms for dev vocabulary.
15
15
  *
16
16
  * - VoiceInput — High-level voice input controller. Toggle mode: tap mic to start, tap
17
- * again to stop. Auto-stops after 3s silence. Shows floating preview overlay with recording
17
+ * again to stop. Auto-stops after configurable silence. Shows floating preview overlay with recording
18
18
  * indicator, level meter (AnalyserNode), and elapsed timer. Two insert modes: "direct"
19
19
  * (inject into local echo overlay or PTY) and "compose" (editable textarea overlay).
20
20
  * Includes a temporary green Send button that replaces the settings gear icon after voice input.
21
- * Web Speech API has auto-retry (up to 2x) for premature onend and iOS Safari stability check.
21
+ * Web Speech API retries empty runs twice with backoff and preserves late results after Stop.
22
22
  *
23
23
  * @globals {object} ClaudeVoiceProvider
24
24
  * @globals {object} DeepgramProvider
@@ -216,9 +216,12 @@ const DeepgramProvider = {
216
216
 
217
217
  _resetSilenceTimeout() {
218
218
  clearTimeout(this._silenceTimeout);
219
+ this._silenceTimeout = null;
220
+ const delay = VoiceInput.getSilenceTimeoutMs(3000);
221
+ if (delay === 0) return;
219
222
  this._silenceTimeout = setTimeout(() => {
220
223
  this.stop();
221
- }, 3000);
224
+ }, delay);
222
225
  },
223
226
 
224
227
  stop() {
@@ -269,8 +272,8 @@ const DeepgramProvider = {
269
272
  * DeepgramProvider's recorder. The AudioContext is constructed at 16000 Hz so the
270
273
  * browser does the resampling.
271
274
  *
272
- * ⚠️ Transcript frames carry the WHOLE running transcript, not deltas. Callers
273
- * must replace, never concatenate.
275
+ * Transcript frames cover the current utterance. Replace interims and append
276
+ * each endpoint final once; an endpoint alone does not end the recording.
274
277
  */
275
278
  const ClaudeVoiceProvider = {
276
279
  _ws: null,
@@ -284,6 +287,8 @@ const ClaudeVoiceProvider = {
284
287
  _onError: null,
285
288
  _onEnd: null,
286
289
  _finalized: false,
290
+ _finalizeTimeout: null,
291
+ _generation: 0,
287
292
 
288
293
  /** How long without any transcript before the recording gives up on its own. */
289
294
  SILENCE_MS: 6000,
@@ -293,6 +298,8 @@ const ClaudeVoiceProvider = {
293
298
  * @param {object} opts - { language, keyterms[], onResult(text, isFinal), onError(msg), onEnd(), onStream(stream) }
294
299
  */
295
300
  async start(opts) {
301
+ this._cleanup();
302
+ const generation = this._generation;
296
303
  this._onResult = opts.onResult;
297
304
  this._onError = opts.onError;
298
305
  this._onEnd = opts.onEnd;
@@ -304,10 +311,17 @@ const ClaudeVoiceProvider = {
304
311
  return;
305
312
  }
306
313
  try {
307
- this._stream = await navigator.mediaDevices.getUserMedia({
314
+ const stream = await navigator.mediaDevices.getUserMedia({
308
315
  audio: { noiseSuppression: true, echoCancellation: true, autoGainControl: true }
309
316
  });
317
+ // Permission prompts can resolve after Stop/reconnect or a newer recording.
318
+ if (generation !== this._generation || this._finalized) {
319
+ stream.getTracks().forEach(t => t.stop());
320
+ return;
321
+ }
322
+ this._stream = stream;
310
323
  } catch (err) {
324
+ if (generation !== this._generation || this._finalized) return;
311
325
  const msg = err.name === 'NotAllowedError'
312
326
  ? 'Microphone access denied. Check browser settings.'
313
327
  : 'Microphone error: ' + err.message;
@@ -331,10 +345,12 @@ const ClaudeVoiceProvider = {
331
345
  this._ws.binaryType = 'arraybuffer';
332
346
 
333
347
  this._ws.onopen = () => {
348
+ if (generation !== this._generation || this._finalized) return;
334
349
  // Capture starts only once the socket is up: PCM buffered before that would
335
350
  // be the oldest audio, and dropping it keeps the transcript aligned with what
336
351
  // the user hears themselves saying.
337
- this._startCapture().catch((err) => {
352
+ this._startCapture(generation).catch((err) => {
353
+ if (generation !== this._generation || this._finalized) return;
338
354
  this._onError?.('Microphone capture failed: ' + err.message);
339
355
  this.stop();
340
356
  });
@@ -342,6 +358,7 @@ const ClaudeVoiceProvider = {
342
358
  };
343
359
 
344
360
  this._ws.onmessage = (event) => {
361
+ if (generation !== this._generation) return;
345
362
  let msg;
346
363
  try {
347
364
  msg = JSON.parse(event.data);
@@ -361,6 +378,7 @@ const ClaudeVoiceProvider = {
361
378
  };
362
379
 
363
380
  this._ws.onclose = (event) => {
381
+ if (generation !== this._generation) return;
364
382
  if (event.code === 4004) {
365
383
  this._onError?.(this._unavailableMessage(event.reason));
366
384
  } else if (event.code === 4008) {
@@ -385,16 +403,19 @@ const ClaudeVoiceProvider = {
385
403
  },
386
404
 
387
405
  /** Wire mic -> 16 kHz PCM16 frames -> WebSocket. */
388
- async _startCapture() {
406
+ async _startCapture(generation = this._generation) {
407
+ if (generation !== this._generation || this._finalized) return;
389
408
  const Ctx = window.AudioContext || window.webkitAudioContext;
390
409
  // Ask for 16 kHz directly so the browser resamples; Safari may hand back its
391
410
  // own rate, which _pcmFromFloat32 then downsamples to match.
392
411
  this._audioContext = new Ctx({ sampleRate: 16000 });
393
412
  if (this._audioContext.state === 'suspended') await this._audioContext.resume();
413
+ if (generation !== this._generation || this._finalized) return;
394
414
  this._sourceNode = this._audioContext.createMediaStreamSource(this._stream);
395
415
 
396
416
  if (this._audioContext.audioWorklet) {
397
417
  await this._audioContext.audioWorklet.addModule(this._workletUrl());
418
+ if (generation !== this._generation || this._finalized) return;
398
419
  this._workletNode = new AudioWorkletNode(this._audioContext, 'pcm-frame-processor');
399
420
  this._workletNode.port.onmessage = (event) => this._sendAudio(event.data);
400
421
  this._sourceNode.connect(this._workletNode);
@@ -455,7 +476,10 @@ const ClaudeVoiceProvider = {
455
476
 
456
477
  _resetSilenceTimeout() {
457
478
  clearTimeout(this._silenceTimeout);
458
- this._silenceTimeout = setTimeout(() => this.stop(), this.SILENCE_MS);
479
+ this._silenceTimeout = null;
480
+ const delay = VoiceInput.getSilenceTimeoutMs(this.SILENCE_MS);
481
+ if (delay === 0) return;
482
+ this._silenceTimeout = setTimeout(() => this.stop(), delay);
459
483
  },
460
484
 
461
485
  /**
@@ -469,6 +493,13 @@ const ClaudeVoiceProvider = {
469
493
  if (this._finalized) return;
470
494
  this._finalized = true;
471
495
  this._stopCapture();
496
+ // Bound both manual and silence-triggered finalization on a dead connection.
497
+ // Repeated stop requests return above, so they cannot extend this deadline.
498
+ this._finalizeTimeout = setTimeout(() => {
499
+ const onEnd = this._onEnd;
500
+ this._cleanup();
501
+ onEnd?.();
502
+ }, 5000);
472
503
  if (this._ws?.readyState === WebSocket.OPEN) {
473
504
  try {
474
505
  this._ws.send(JSON.stringify({ t: 'finalize' }));
@@ -510,15 +541,19 @@ const ClaudeVoiceProvider = {
510
541
 
511
542
  /** Hard stop: drop the socket without waiting for a final transcript. */
512
543
  _cleanup() {
544
+ this._generation++;
513
545
  this._finalized = true;
546
+ clearTimeout(this._finalizeTimeout);
547
+ this._finalizeTimeout = null;
514
548
  clearTimeout(this._silenceTimeout);
515
549
  this._silenceTimeout = null;
516
550
  this._stopCapture();
517
551
  if (this._ws) {
552
+ this._ws.onopen = null;
518
553
  this._ws.onclose = null;
519
554
  this._ws.onmessage = null;
520
555
  this._ws.onerror = null;
521
- if (this._ws.readyState === WebSocket.OPEN) {
556
+ if (this._ws.readyState === WebSocket.OPEN || this._ws.readyState === WebSocket.CONNECTING) {
522
557
  try { this._ws.close(1000); } catch (_e) { /* ignore */ }
523
558
  }
524
559
  this._ws = null;
@@ -537,18 +572,27 @@ const ClaudeVoiceProvider = {
537
572
  * Inserts final text into the active session (user presses Enter to submit).
538
573
  */
539
574
  const VoiceInput = {
575
+ SILENCE_TIMEOUT_SECONDS: Object.freeze([0, 3, 6, 15, 30]),
576
+ WEB_SPEECH_INSTANT_END_MS: 1000, // an empty run shorter than this counts toward the retry cap
540
577
  recognition: null,
541
578
  isRecording: false,
542
579
  supported: false,
543
580
  silenceTimeout: null,
544
581
  previewEl: null,
545
- _lastTranscript: '',
546
- _stabilityTimer: null,
547
582
  _accumulatedFinal: '',
548
- _activeProvider: null, // 'deepgram' | 'webspeech' | null
583
+ _pendingInterim: '',
584
+ _webSpeechCommitted: '', // Text from completed native recognition runs.
585
+ _webSpeechSingleUtterance: false,
586
+ _webSpeechSoundActive: false,
587
+ _webSpeechActivityUntil: 0,
588
+ _webSpeechStopping: false,
589
+ _webSpeechStopTimer: null,
590
+ _webSpeechRestartTimer: null,
591
+ _activeProvider: null, // 'claude' | 'deepgram' | 'webspeech' | null
549
592
  _recordingStartedAt: 0, // timestamp when recording started
550
- _retryCount: 0, // auto-retry counter for premature Web Speech API ends
551
- _hasReceivedResult: false, // whether any speech result came in this session
593
+ _retryCount: 0, // consecutive Web Speech runs that ended empty right after starting
594
+ _hasReceivedResult: false, // whether this native recognition run received speech
595
+ _webSpeechRunStartedAt: 0, // when the current native recognition run was started
552
596
  _durationInterval: null, // timer for updating elapsed time display
553
597
  _analyser: null, // AudioContext analyser for level meter
554
598
  _analyserSource: null, // MediaStreamSource for level meter
@@ -599,6 +643,12 @@ const VoiceInput = {
599
643
  }
600
644
  },
601
645
 
646
+ /** Seconds in settings; zero means stop only when the user asks. */
647
+ getSilenceTimeoutMs(fallback) {
648
+ const seconds = this._getDeepgramConfig().silenceTimeout;
649
+ return this.SILENCE_TIMEOUT_SECONDS.includes(seconds) ? seconds * 1000 : fallback;
650
+ },
651
+
602
652
  _saveDeepgramConfig(config) {
603
653
  localStorage.setItem('codeman-voice-settings', JSON.stringify(config));
604
654
  },
@@ -648,7 +698,18 @@ const VoiceInput = {
648
698
  if (!this.supported) return;
649
699
 
650
700
  this.recognition = new SR();
651
- this.recognition.continuous = true;
701
+ // Android's continuous bridge promotes growing partials to separate finals.
702
+ // Single-utterance mode keeps refinements provisional; onend resumes the mic
703
+ // while our own silence deadline controls the overall dictation session.
704
+ // Android tablets in desktop-site mode may identify as touch-capable Linux.
705
+ // ChromeOS also reports Linux but says CrOS, so it keeps continuous mode.
706
+ // A Linux laptop with a touchscreen still matches; single-utterance works
707
+ // there too, with one native restart per phrase.
708
+ const ua = navigator.userAgent || '';
709
+ this._webSpeechSingleUtterance = navigator.userAgentData?.platform === 'Android'
710
+ || /Android/i.test(ua)
711
+ || (navigator.maxTouchPoints > 0 && /Linux/i.test(navigator.platform || '') && !/CrOS/.test(ua));
712
+ this.recognition.continuous = !this._webSpeechSingleUtterance;
652
713
  this.recognition.interimResults = true;
653
714
  this.recognition.lang = 'en-US';
654
715
  this.recognition.maxAlternatives = 1;
@@ -656,6 +717,8 @@ const VoiceInput = {
656
717
  this.recognition.onresult = (e) => this._onWebSpeechResult(e);
657
718
  this.recognition.onerror = (e) => this._onWebSpeechError(e);
658
719
  this.recognition.onend = () => this._onWebSpeechEnd();
720
+ this.recognition.onsoundstart = this.recognition.onspeechstart = () => this._onWebSpeechSound(true);
721
+ this.recognition.onsoundend = this.recognition.onspeechend = this.recognition.onaudioend = () => this._onWebSpeechSound(false);
659
722
  },
660
723
 
661
724
  toggle() {
@@ -706,7 +769,7 @@ const VoiceInput = {
706
769
  this.isRecording = true;
707
770
  this._activeProvider = 'claude';
708
771
  this._accumulatedFinal = '';
709
- this._lastTranscript = '';
772
+ this._pendingInterim = '';
710
773
  this._hasReceivedResult = false;
711
774
  this._recordingStartedAt = Date.now();
712
775
  this._updateButtons('recording');
@@ -725,25 +788,25 @@ const VoiceInput = {
725
788
  onResult: (text, isFinal) => {
726
789
  if (!this.isRecording) return;
727
790
  this._hasReceivedResult = true;
728
- // Each frame is the WHOLE running transcript, so replace rather than append.
729
- this._accumulatedFinal = text;
791
+ // Interims replace the current utterance; each endpoint commits it once.
730
792
  if (isFinal) {
731
- this._hidePreview();
732
- this._insertText(text);
733
- this.stop();
793
+ this._accumulatedFinal = [this._accumulatedFinal, text].filter(Boolean).join(' ');
794
+ this._pendingInterim = '';
795
+ if (ClaudeVoiceProvider._finalized) this.stop(true);
796
+ else this._showPreview(this._accumulatedFinal, 'claude');
734
797
  } else {
735
- this._showPreview(text, 'claude');
798
+ this._pendingInterim = (this._accumulatedFinal ? ' ' : '') + text;
799
+ this._showPreview(this._accumulatedFinal + this._pendingInterim, 'claude');
736
800
  }
737
801
  },
738
802
  onError: (msg) => {
739
803
  const wasRecording = this.isRecording;
740
- this.stop();
804
+ this.stop(true);
741
805
  if (wasRecording) app.showToast(msg, 'error');
742
806
  },
743
807
  onEnd: () => {
744
808
  if (this.isRecording) {
745
- if (this._accumulatedFinal) this._insertText(this._accumulatedFinal);
746
- this.stop();
809
+ this.stop(true);
747
810
  }
748
811
  }
749
812
  });
@@ -756,7 +819,7 @@ const VoiceInput = {
756
819
  this.isRecording = true;
757
820
  this._activeProvider = 'deepgram';
758
821
  this._accumulatedFinal = '';
759
- this._lastTranscript = '';
822
+ this._pendingInterim = '';
760
823
  this._hasReceivedResult = false;
761
824
  this._recordingStartedAt = Date.now();
762
825
  this._updateButtons('recording');
@@ -777,12 +840,12 @@ const VoiceInput = {
777
840
  if (!this.isRecording) return;
778
841
  this._hasReceivedResult = true;
779
842
  if (isFinal) {
780
- this._accumulatedFinal += text;
781
- this._hidePreview();
782
- this._insertText(this._accumulatedFinal);
783
- this.stop();
843
+ this._accumulatedFinal += (this._accumulatedFinal ? ' ' : '') + text;
844
+ this._pendingInterim = '';
845
+ this._showPreview(this._accumulatedFinal, 'deepgram');
784
846
  } else {
785
- const display = this._accumulatedFinal + text;
847
+ this._pendingInterim = (this._accumulatedFinal ? ' ' : '') + text;
848
+ const display = this._accumulatedFinal + this._pendingInterim;
786
849
  this._showPreview(display, 'deepgram');
787
850
  }
788
851
  },
@@ -793,9 +856,6 @@ const VoiceInput = {
793
856
  },
794
857
  onEnd: () => {
795
858
  if (this.isRecording) {
796
- if (this._accumulatedFinal) {
797
- this._insertText(this._accumulatedFinal);
798
- }
799
859
  this.stop();
800
860
  }
801
861
  }
@@ -818,44 +878,74 @@ const VoiceInput = {
818
878
  }
819
879
  this.isRecording = true;
820
880
  this._activeProvider = 'webspeech';
881
+ this._retryCount = 0;
882
+ this._webSpeechCommitted = '';
883
+ this._webSpeechSoundActive = false;
884
+ this._webSpeechActivityUntil = 0;
821
885
  this._accumulatedFinal = '';
822
- this._lastTranscript = '';
886
+ this._pendingInterim = '';
823
887
  this._hasReceivedResult = false;
824
888
  this._recordingStartedAt = Date.now();
825
889
  this._updateButtons('recording');
826
890
  this._showPreview('Listening...');
827
891
  this._startDurationTimer();
828
892
  try {
893
+ this._webSpeechRunStartedAt = Date.now();
829
894
  this.recognition.start();
830
895
  } catch (e) {
831
896
  // InvalidStateError = already started — ignore. Other errors = genuine failure.
832
897
  if (e.name !== 'InvalidStateError') {
833
- this.stop();
898
+ this.stop(true);
834
899
  app.showToast('Voice input failed to start: ' + e.message, 'error');
835
900
  return;
836
901
  }
837
902
  }
838
903
  this._resetSilenceTimeout();
839
- // Get mic stream for level meter (non-blocking — level meter is cosmetic)
840
- navigator.mediaDevices?.getUserMedia({ audio: true }).then(stream => {
841
- if (this.isRecording && this._activeProvider === 'webspeech') {
842
- this._webSpeechStream = stream;
843
- this._startLevelMeter(stream);
844
- } else {
845
- stream.getTracks().forEach(t => t.stop());
846
- }
847
- }).catch(() => { /* level meter just won't show */ });
904
+ // SpeechRecognition owns its microphone. A second getUserMedia capture for
905
+ // a cosmetic meter can take audio away from Android's recognition service.
906
+ // Streaming providers still meter the same stream they transcribe.
907
+ this._drawLevelMeter();
848
908
  // Haptic feedback on mobile
849
909
  if (navigator.vibrate) navigator.vibrate(50);
850
910
  },
851
911
 
852
- stop() {
912
+ stop(providerFinished = false) {
853
913
  if (!this.isRecording) return;
914
+ if (this._webSpeechRestartTimer !== null) {
915
+ clearTimeout(this._webSpeechRestartTimer);
916
+ this._webSpeechRestartTimer = null;
917
+ // The recognizer already ended; no onend remains to wait for.
918
+ providerFinished = true;
919
+ }
920
+ // Claude delivers its final transcript after finalize. Keep accepting it
921
+ // until that frame (or onEnd) completes this recording.
922
+ if (this._activeProvider === 'claude' && !providerFinished && ClaudeVoiceProvider._ws?.readyState === WebSocket.OPEN) {
923
+ ClaudeVoiceProvider.stop();
924
+ return;
925
+ }
926
+ if (this._activeProvider === 'webspeech' && !providerFinished) {
927
+ if (this._webSpeechStopping) return;
928
+ this._webSpeechStopping = true;
929
+ clearTimeout(this.silenceTimeout);
930
+ // stop() requests a result; Android may deliver it only before onend.
931
+ // Keep accepting results, with a backstop for engines that never end.
932
+ this._webSpeechStopTimer = setTimeout(() => {
933
+ try { this.recognition?.abort(); } catch (_e) { /* already ended */ }
934
+ this.stop(true);
935
+ }, 3000);
936
+ try { this.recognition?.stop(); } catch (_e) { this.stop(true); }
937
+ return;
938
+ }
939
+ clearTimeout(this._webSpeechStopTimer);
940
+ this._webSpeechStopTimer = null;
941
+ this._webSpeechStopping = false;
854
942
  this.isRecording = false;
943
+ const text = this._accumulatedFinal + this._pendingInterim;
944
+ this._accumulatedFinal = '';
945
+ this._pendingInterim = '';
946
+ if (text) this._insertText(text);
855
947
  clearTimeout(this.silenceTimeout);
856
- clearTimeout(this._stabilityTimer);
857
948
  this.silenceTimeout = null;
858
- this._stabilityTimer = null;
859
949
  this._retryCount = 0;
860
950
  this._stopDurationTimer();
861
951
  this._stopLevelMeter();
@@ -863,21 +953,10 @@ const VoiceInput = {
863
953
  this._hidePreview();
864
954
 
865
955
  if (this._activeProvider === 'claude') {
866
- // Finalize, don't hang up: the last transcript arrives after the audio does.
867
- ClaudeVoiceProvider.stop();
956
+ // Completion received, or forced teardown: callbacks must not outlive it.
957
+ ClaudeVoiceProvider._cleanup();
868
958
  } else if (this._activeProvider === 'deepgram') {
869
959
  DeepgramProvider.stop();
870
- } else if (this._activeProvider === 'webspeech') {
871
- try {
872
- this.recognition?.stop();
873
- } catch (_e) {
874
- // Already stopped — ignore
875
- }
876
- // Stop the mic stream we opened for the level meter
877
- if (this._webSpeechStream) {
878
- this._webSpeechStream.getTracks().forEach(t => t.stop());
879
- this._webSpeechStream = null;
880
- }
881
960
  }
882
961
  this._activeProvider = null;
883
962
 
@@ -885,41 +964,44 @@ const VoiceInput = {
885
964
  if (navigator.vibrate) navigator.vibrate([30, 50, 30]);
886
965
  },
887
966
 
967
+ _onWebSpeechSound(active) {
968
+ if (!this.isRecording || this._activeProvider !== 'webspeech' || this._webSpeechStopping) return;
969
+ this._webSpeechSoundActive = active;
970
+ if (!active) this._webSpeechActivityUntil = 0;
971
+ },
972
+
888
973
  _onWebSpeechResult(event) {
889
974
  if (!this.isRecording) return;
890
- this._hasReceivedResult = true;
891
975
  this._resetSilenceTimeout();
892
- let interim = '';
893
- let finalText = '';
894
- for (let i = event.resultIndex; i < event.results.length; i++) {
895
- const transcript = event.results[i][0].transcript;
896
- if (event.results[i].isFinal) {
897
- finalText += transcript;
898
- } else {
899
- interim += transcript;
900
- }
901
- }
902
-
903
- if (finalText) {
904
- this._accumulatedFinal += finalText;
905
- this._hidePreview();
906
- this._insertText(this._accumulatedFinal);
907
- this.stop();
908
- } else if (interim) {
909
- const display = this._accumulatedFinal + interim;
910
- this._showPreview(display);
911
- // iOS Safari workaround: isFinal is always false.
912
- // Detect when interim results stop changing for 750ms → treat as final.
913
- this._iosStabilityCheck(interim);
976
+ // results is the current run's complete snapshot, not a list of new words.
977
+ // Rebuild by result position so repeats/corrections replace the same text.
978
+ // Never deduplicate by text: "go go" and repeated phrases can be intentional.
979
+ const finals = [];
980
+ const interims = [];
981
+ for (let i = 0; i < event.results.length; i++) {
982
+ const result = event.results[i];
983
+ const text = result[0]?.transcript?.trim();
984
+ if (text) (result.isFinal ? finals : interims).push(text);
914
985
  }
986
+ this._accumulatedFinal = [this._webSpeechCommitted, ...finals].filter(Boolean).join(' ');
987
+ const interim = interims.join(' ');
988
+ this._hasReceivedResult ||= finals.length > 0 || !!interim;
989
+ this._pendingInterim = interim ? (this._accumulatedFinal ? ' ' : '') + interim : '';
990
+ this._showPreview(this._accumulatedFinal + this._pendingInterim);
991
+ // Some engines omit sound events; transcript updates are also real evidence
992
+ // of speech activity. This is an activity animation, not an amplitude meter.
993
+ if (finals.length || interim) this._webSpeechActivityUntil = Date.now() + 600;
915
994
  },
916
995
 
917
996
  _onWebSpeechError(event) {
918
997
  // During auto-retry, 'aborted' and 'no-speech' errors are expected — ignore them
919
998
  if (this._retryCount > 0 && (event.error === 'aborted' || event.error === 'no-speech')) return;
920
999
 
1000
+ // Browser silence events must not override an extended/manual deadline.
1001
+ if (event.error === 'no-speech' && this.getSilenceTimeoutMs(3000) !== 3000) return;
1002
+
921
1003
  const wasRecording = this.isRecording;
922
- this.stop();
1004
+ this.stop(true);
923
1005
  if (!wasRecording) return;
924
1006
 
925
1007
  switch (event.error) {
@@ -943,27 +1025,45 @@ const VoiceInput = {
943
1025
  _onWebSpeechEnd() {
944
1026
  // Recognition ended (browser auto-stopped or we called stop())
945
1027
  if (!this.isRecording) return;
1028
+ this._onWebSpeechSound(false);
1029
+ if (this._webSpeechStopping) {
1030
+ this.stop(true);
1031
+ return;
1032
+ }
946
1033
 
947
- const elapsed = Date.now() - this._recordingStartedAt;
948
- // Web Speech API often fires onend prematurely on the first attempt (< 500ms, no results).
949
- // Auto-retry up to 2 times to avoid the "needs two clicks" problem.
950
- if (elapsed < 500 && !this._hasReceivedResult && this._retryCount < 2) {
951
- this._retryCount++;
952
- try {
953
- this.recognition.start();
954
- } catch (_e) {
955
- // If restart fails, fall through to stop
956
- if (this._accumulatedFinal) this._insertText(this._accumulatedFinal);
957
- this.stop();
958
- }
1034
+ // Only a run that ends empty right after start() counts toward the cap: that
1035
+ // is a recognizer that cannot listen. A silent run of normal length is the
1036
+ // engine's own no-speech window, and 30 s or Manual must outlast many of them.
1037
+ const empty = !this._hasReceivedResult;
1038
+ const instant = empty && Date.now() - this._webSpeechRunStartedAt < this.WEB_SPEECH_INSTANT_END_MS;
1039
+ this._retryCount = instant ? this._retryCount + 1 : 0;
1040
+ if (this._retryCount > 2) {
1041
+ this.stop(true);
959
1042
  return;
960
1043
  }
961
1044
 
962
- // Genuine end — finalize any accumulated text
963
- if (this._accumulatedFinal) {
964
- this._insertText(this._accumulatedFinal);
1045
+ // Native endpoints must not extend the configured silence deadline.
1046
+ const delay = this.getSilenceTimeoutMs(3000);
1047
+ if (empty || this._webSpeechSingleUtterance || delay === 0 || delay > 3000) {
1048
+ // Commit this run once before the next run resets its result indexes.
1049
+ this._webSpeechCommitted = (this._accumulatedFinal + this._pendingInterim).trim();
1050
+ this._accumulatedFinal = this._webSpeechCommitted;
1051
+ this._pendingInterim = '';
1052
+ const restart = () => {
1053
+ this._webSpeechRestartTimer = null;
1054
+ if (!this.isRecording || this._webSpeechStopping) return;
1055
+ this._hasReceivedResult = false;
1056
+ this._webSpeechRunStartedAt = Date.now();
1057
+ try { this.recognition.start(); } catch (_e) { this.stop(true); }
1058
+ };
1059
+ // A broken or unavailable recognizer must not spin forever in Manual mode.
1060
+ if (empty) this._webSpeechRestartTimer = setTimeout(restart, 250);
1061
+ else restart();
1062
+ return;
965
1063
  }
966
- this.stop();
1064
+
1065
+ // Genuine end — finalize any accumulated text
1066
+ this.stop(true);
967
1067
  },
968
1068
 
969
1069
  /** The session this dictation belongs to (see _targetSessionId). */
@@ -1138,30 +1238,14 @@ const VoiceInput = {
1138
1238
 
1139
1239
  _resetSilenceTimeout() {
1140
1240
  clearTimeout(this.silenceTimeout);
1241
+ this.silenceTimeout = null;
1242
+ const delay = this.getSilenceTimeoutMs(3000);
1243
+ if (delay === 0) return;
1141
1244
  this.silenceTimeout = setTimeout(() => {
1142
1245
  if (this.isRecording) {
1143
- // Finalize any accumulated text before stopping
1144
- if (this._accumulatedFinal) {
1145
- this._insertText(this._accumulatedFinal);
1146
- }
1147
1246
  this.stop();
1148
1247
  }
1149
- }, 3000);
1150
- },
1151
-
1152
- _iosStabilityCheck(transcript) {
1153
- if (transcript !== this._lastTranscript) {
1154
- this._lastTranscript = transcript;
1155
- clearTimeout(this._stabilityTimer);
1156
- this._stabilityTimer = setTimeout(() => {
1157
- if (this.isRecording) {
1158
- const finalText = this._accumulatedFinal + transcript;
1159
- this._hidePreview();
1160
- this._insertText(finalText);
1161
- this.stop();
1162
- }
1163
- }, 750);
1164
- }
1248
+ }, delay);
1165
1249
  },
1166
1250
 
1167
1251
  _startDurationTimer() {
@@ -1200,6 +1284,8 @@ const VoiceInput = {
1200
1284
  },
1201
1285
 
1202
1286
  _stopLevelMeter() {
1287
+ this._webSpeechSoundActive = false;
1288
+ this._webSpeechActivityUntil = 0;
1203
1289
  if (this._levelAnimFrame) {
1204
1290
  cancelAnimationFrame(this._levelAnimFrame);
1205
1291
  this._levelAnimFrame = null;
@@ -1216,13 +1302,21 @@ const VoiceInput = {
1216
1302
  },
1217
1303
 
1218
1304
  _drawLevelMeter() {
1219
- if (!this._analyser || !this.isRecording) return;
1220
- const dataArray = new Uint8Array(this._analyser.frequencyBinCount);
1221
- this._analyser.getByteFrequencyData(dataArray);
1222
- // Compute RMS level 0-1
1223
- let sum = 0;
1224
- for (let i = 0; i < dataArray.length; i++) sum += dataArray[i] * dataArray[i];
1225
- const rms = Math.sqrt(sum / dataArray.length) / 255;
1305
+ if (!this.isRecording) return;
1306
+ let rms = 0;
1307
+ if (this._activeProvider === 'webspeech') {
1308
+ // The speech API exposes activity events, but no microphone sample level.
1309
+ const active = !this._webSpeechStopping
1310
+ && (this._webSpeechSoundActive || Date.now() < this._webSpeechActivityUntil);
1311
+ if (active) rms = 0.25 + 0.55 * (1 + Math.sin(Date.now() / 110)) / 2;
1312
+ } else {
1313
+ if (!this._analyser) return;
1314
+ const dataArray = new Uint8Array(this._analyser.frequencyBinCount);
1315
+ this._analyser.getByteFrequencyData(dataArray);
1316
+ let sum = 0;
1317
+ for (let i = 0; i < dataArray.length; i++) sum += dataArray[i] * dataArray[i];
1318
+ rms = Math.sqrt(sum / dataArray.length) / 255;
1319
+ }
1226
1320
  // Update the level bars in the preview
1227
1321
  const barsEl = this.previewEl?.querySelector('.voice-level-bars');
1228
1322
  if (barsEl) {
@@ -1252,6 +1346,8 @@ const VoiceInput = {
1252
1346
  indicator.innerHTML = '<span class="voice-rec-dot"></span>';
1253
1347
  const barsEl = document.createElement('span');
1254
1348
  barsEl.className = 'voice-level-bars';
1349
+ barsEl.setAttribute('aria-label', this._activeProvider === 'webspeech' ? 'Speech activity' : 'Microphone level');
1350
+ barsEl.title = this._activeProvider === 'webspeech' ? 'Speech activity' : 'Microphone level';
1255
1351
  for (let i = 0; i < 5; i++) {
1256
1352
  const bar = document.createElement('span');
1257
1353
  bar.className = 'voice-level-bar';
@@ -1319,28 +1415,27 @@ const VoiceInput = {
1319
1415
 
1320
1416
  /** Cleanup on SSE reconnect or page unload */
1321
1417
  cleanup() {
1322
- if (this.isRecording) this.stop();
1418
+ // Hide the Send button first: stop(true) below may insert the words it
1419
+ // salvaged and show the button again for them.
1323
1420
  this._hideVoiceSendBtn();
1421
+ if (this.isRecording) {
1422
+ this.stop(true);
1423
+ try { this.recognition?.abort(); } catch (_e) { /* already ended */ }
1424
+ }
1324
1425
  DeepgramProvider._cleanup();
1325
1426
  ClaudeVoiceProvider._cleanup();
1326
1427
  this.recognition = null;
1327
1428
  this._activeProvider = null;
1328
1429
  this._stopDurationTimer();
1329
1430
  this._stopLevelMeter();
1330
- if (this._webSpeechStream) {
1331
- this._webSpeechStream.getTracks().forEach(t => t.stop());
1332
- this._webSpeechStream = null;
1333
- }
1334
1431
  if (this.previewEl) {
1335
1432
  this.previewEl.remove();
1336
1433
  this.previewEl = null;
1337
1434
  }
1338
1435
  clearTimeout(this.silenceTimeout);
1339
- clearTimeout(this._stabilityTimer);
1340
1436
  this.silenceTimeout = null;
1341
- this._stabilityTimer = null;
1342
1437
  this._accumulatedFinal = '';
1343
- this._lastTranscript = '';
1438
+ this._pendingInterim = '';
1344
1439
  this._retryCount = 0;
1345
1440
  this._hasReceivedResult = false;
1346
1441
  }