dsh-tinyasr 1.10.1 → 1.11.0

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
@@ -3,6 +3,19 @@
3
3
  All notable changes to this plugin. Entries up to 1.11.0 are local pre-release iterations of the
4
4
  1.0 line; the public package starts at 1.2.0.
5
5
 
6
+ ## 1.11.0 — 7 December 2026
7
+
8
+ - State safety net: on every start the plugin copies `settings.json`, `glossary.json` and the mobile
9
+ plugin's `voice-settings.json` into `<dataDir>/backups` with a timestamp, keeping five copies. Those
10
+ files live outside the package directory and outside `~/.dsh`, so a plugin update or a profile reset
11
+ no longer takes them with it.
12
+
13
+ ## 1.10.2 — 7 December 2026
14
+
15
+ - Recovery housekeeping: the tap buffer stops growing at 310 s, an unclaimed transcript expires after
16
+ 10 minutes, discards are logged (`tap discard`), and `tap`/`recover` lines carry the session tail so
17
+ a recovery can be traced to its conversation.
18
+
6
19
  ## 1.10.1 — 7 December 2026
7
20
 
8
21
  - The recovery keeps the conversation captured when the recording started instead of reading it
package/README.md CHANGED
@@ -180,6 +180,13 @@ dsh plugin --profile <profile> add dsh-tinyasr
180
180
  списке языков панели нет русского — поэтому «auto» и есть правильный выбор. Аудио обрабатывается
181
181
  на компьютере и в облако не уходит.
182
182
 
183
+ ## Резервные копии настроек
184
+
185
+ При каждом запуске плагин сохраняет копии `settings.json`, `glossary.json` и настроек голосового
186
+ ввода мобильного плагина в `<dataDir>/backups` с меткой времени (хранятся пять последних копий).
187
+ Каталог данных находится вне пакета плагина и вне `~/.dsh`, поэтому обновление плагина или сброс
188
+ профиля их не затрагивают. Восстановление — скопировать нужный `*.bak` обратно под исходным именем.
189
+
183
190
  ## Требования
184
191
 
185
192
  - macOS на Apple Silicon (arm64): сборка `tinyasr-cli`/`tinyasr-serve` под эту машину.
package/client.js CHANGED
@@ -800,6 +800,7 @@ window.__ModuleLoader__.load({
800
800
  // conversation. Returning to that conversation inserts the text into the draft.
801
801
  let tap = null
802
802
  const pendingRecovery = new Map()
803
+ const PENDING_TTL_MS = 10 * 60 * 1000
803
804
  const sessionOf = () => {
804
805
  const node = document.querySelector('[data-conversation-session]')
805
806
  const value = node?.getAttribute('data-conversation-session')
@@ -834,6 +835,7 @@ window.__ModuleLoader__.load({
834
835
  // already belong to the conversation the user switched to.
835
836
  const state = { media, audio, source, processor, chunks: [], length: 0, session: sessionOf() }
836
837
  processor.onaudioprocess = (event) => {
838
+ if (state.length >= 16000 * 310) return // the recorder caps at 300 s; never grow past it
837
839
  const block = event.inputBuffer.getChannelData(0)
838
840
  const samples = audio.sampleRate === 16000 ? block : resample(block, audio.sampleRate)
839
841
  const copy = new Float32Array(samples.length)
@@ -844,7 +846,7 @@ window.__ModuleLoader__.load({
844
846
  source.connect(processor)
845
847
  processor.connect(audio.destination)
846
848
  tap = state
847
- hello('tap', { stage: 'start', session: state.session.slice(0, 8) })
849
+ hello('tap', { stage: 'start', session: state.session.slice(-8) })
848
850
  } catch (error) {
849
851
  hello('tap', { stage: 'failed', message: String(error?.message ?? error).slice(0, 120) })
850
852
  }
@@ -857,7 +859,7 @@ window.__ModuleLoader__.load({
857
859
  try { state.source.disconnect() } catch {}
858
860
  try { for (const track of state.media.getTracks()) track.stop() } catch {}
859
861
  try { await state.audio.close() } catch {}
860
- if (!keep) return null
862
+ if (!keep) { hello('tap', { stage: 'discard', ms: String(state.length * 1000 / 16000 | 0) }); return null }
861
863
  const wav = encodeWav(state.chunks, state.length, 16000)
862
864
  if (wav.length <= 44) return { text: '', session: state.session }
863
865
  try {
@@ -874,6 +876,11 @@ window.__ModuleLoader__.load({
874
876
  }
875
877
  const waitingLogged = new Set()
876
878
  const flushRecovery = () => {
879
+ if (pendingRecovery.size === 0) return
880
+ const now = Date.now()
881
+ for (const [key, entry] of pendingRecovery) {
882
+ if (now - entry.at > PENDING_TTL_MS) { pendingRecovery.delete(key); hello('recover', { stage: 'expired', session: key.slice(-8) }) }
883
+ }
877
884
  if (pendingRecovery.size === 0) return
878
885
  if (tap !== null) return
879
886
  const session = sessionOf()
@@ -882,17 +889,17 @@ window.__ModuleLoader__.load({
882
889
  for (const key of pendingRecovery.keys()) {
883
890
  if (key !== session && !waitingLogged.has(key)) {
884
891
  waitingLogged.add(key)
885
- hello('recover', { stage: 'waiting', for: key.slice(0, 8), session: session.slice(0, 8) })
892
+ hello('recover', { stage: 'waiting', for: key.slice(-8), session: session.slice(-8) })
886
893
  }
887
894
  }
888
895
  return
889
896
  }
890
897
  waitingLogged.delete(session)
891
898
  if (document.querySelector('[data-voice-activity]') !== null) return
892
- const text = pendingRecovery.get(session)
893
- if (insertIntoComposer(text)) {
899
+ const entry = pendingRecovery.get(session)
900
+ if (insertIntoComposer(entry.text)) {
894
901
  pendingRecovery.delete(session)
895
- hello('recover', { stage: 'inserted', chars: String(text.length) })
902
+ hello('recover', { stage: 'inserted', chars: String(entry.text.length), session: session.slice(-8) })
896
903
  }
897
904
  }
898
905
  const recoverCancelledTake = async () => {
@@ -903,8 +910,8 @@ window.__ModuleLoader__.load({
903
910
  const session = result.session
904
911
  if (session === '') { hello('recover', { stage: 'no-session', chars: String(text.length) }); return }
905
912
  const previous = pendingRecovery.get(session)
906
- pendingRecovery.set(session, previous === undefined ? text : `${previous} ${text}`)
907
- hello('recover', { stage: 'stashed', chars: String(text.length), session: session.slice(0, 8) })
913
+ pendingRecovery.set(session, { text: previous === undefined ? text : `${previous.text} ${text}`, at: Date.now() })
914
+ hello('recover', { stage: 'stashed', chars: String(text.length), session: session.slice(-8) })
908
915
  }
909
916
 
910
917
  // Track the built-in recorder's phase so a dropped recording leaves evidence on the Host.
package/index.js CHANGED
@@ -22,6 +22,7 @@ import { createGunzip } from 'node:zlib'
22
22
  import { pipeline } from 'node:stream/promises'
23
23
  import { Glossary } from './lib/glossary.js'
24
24
  import { SettingsStore } from './lib/settings.js'
25
+ import { backupState } from './lib/backup.js'
25
26
  import { registerRoutes } from './lib/routes.js'
26
27
  import { registerLiveRoutes } from './lib/live.js'
27
28
  import { installMobileVoiceBridge } from './lib/mobile-bridge.js'
@@ -527,6 +528,15 @@ export function apply(ctx, config) {
527
528
  }
528
529
  const settings = new SettingsStore(resolved.settingsPath)
529
530
  const glossary = new Glossary(resolved.glossaryPath)
531
+ // Keep small state files recoverable across plugin updates and profile resets.
532
+ const dshHome = process.env.DSH_HOME ?? join(homedir(), '.dsh')
533
+ void backupState([
534
+ resolved.settingsPath,
535
+ resolved.glossaryPath,
536
+ join(dshHome, 'storages', 'mobile-plugin', 'voice-settings.json'),
537
+ ], join(resolved.dataDir, 'backups')).then((files) => {
538
+ if (files.length > 0) ctx.logger?.info?.('tinyasr: state backed up', files.length)
539
+ }).catch(() => {})
530
540
  const provider = new TinyAsrProvider(ctx, resolved, ctx.logger, { settings, glossary })
531
541
  // Let the mobile plugin's `host` voice provider reach this recognizer.
532
542
  const speech = typeof ctx.get === 'function' ? ctx.get('speechToText') : ctx.speechToText
package/lib/backup.js ADDED
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Timestamped backups of the small state files a plugin profile accumulates:
3
+ * the tinyasr settings and glossary, and the mobile plugin's voice settings.
4
+ * A plugin update replaces the package directory, and a profile reset wipes
5
+ * `~/.dsh`; both would take those files with them, so each start keeps a copy in
6
+ * the plugin's data directory (which lives outside the package and the profile).
7
+ */
8
+ import { copyFile, mkdir, readdir, stat, unlink } from 'node:fs/promises'
9
+ import { basename, join } from 'node:path'
10
+
11
+ const stamp = () => new Date().toISOString().replace(/[:.]/g, '-')
12
+
13
+ /**
14
+ * Copy each source file into `dir` under a timestamped name and keep the newest
15
+ * `keep` copies per file.
16
+ * @param sources - absolute paths that may or may not exist.
17
+ * @param dir - backup directory.
18
+ * @param keep - how many historical copies of each file to retain.
19
+ * @returns the names written.
20
+ */
21
+ export async function backupState(sources, dir, keep = 5) {
22
+ await mkdir(dir, { recursive: true })
23
+ const written = []
24
+ for (const source of sources) {
25
+ if (typeof source !== 'string' || source === '') continue
26
+ try {
27
+ const info = await stat(source)
28
+ if (!info.isFile()) continue
29
+ } catch {
30
+ continue
31
+ }
32
+ const name = basename(source)
33
+ const target = join(dir, `${name}.${stamp()}.bak`)
34
+ try {
35
+ await copyFile(source, target)
36
+ written.push(basename(target))
37
+ } catch {
38
+ continue
39
+ }
40
+ const prefix = `${name}.`
41
+ const history = (await readdir(dir))
42
+ .filter(entry => entry.startsWith(prefix) && entry.endsWith('.bak'))
43
+ .sort()
44
+ for (const stale of history.slice(0, Math.max(0, history.length - keep))) {
45
+ try { await unlink(join(dir, stale)) } catch {}
46
+ }
47
+ }
48
+ return written
49
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-tinyasr",
3
- "version": "1.10.1",
3
+ "version": "1.11.0",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "description": "Offline Russian and English dictation for the DeepSeek Harness Web GUI through the local tinyasr recognizer, with an optional model cleanup pass.",