dsh-tinyasr 1.10.2 → 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,13 @@
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
+
6
13
  ## 1.10.2 — 7 December 2026
7
14
 
8
15
  - Recovery housekeeping: the tap buffer stops growing at 310 s, an unclaimed transcript expires after
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/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.2",
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.",