@senad-d/micme 0.3.5 → 0.3.6

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
@@ -4,6 +4,7 @@ All notable changes to Micme will be documented in this file.
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ - Preserve Pi's built-in keyboard shortcuts by installing Micme's editor fallback only when a printable-character shortcut is configured.
7
8
  - Move normal Micme persistence to the global `~/.pi/agent/micme.json` store; shell environment variables still override saved settings.
8
9
  - Update `/micme conf`, `micme-doctor`, docs, and package examples for the new global JSON config path.
9
10
  - Document the scoped npm package name, `@senad-d/micme`, in install, diagnostics, update, and uninstall commands.
package/README.md CHANGED
@@ -6,6 +6,7 @@
6
6
  <a href="https://pi.dev"><img alt="pi package" src="https://img.shields.io/badge/pi-package-6f42c1?style=flat-square" /></a>
7
7
  <a href="https://www.npmjs.com/package/@senad-d/micme"><img alt="npm" src="https://img.shields.io/npm/v/%40senad-d%2Fmicme?style=flat-square" /></a>
8
8
  <a href="LICENSE"><img alt="license" src="https://img.shields.io/badge/license-MIT-blue?style=flat-square" /></a>
9
+ <a href="https://sonarcloud.io/summary/new_code?id=senad-d_micme"><img alt="Quality Gate Status" src="https://sonarcloud.io/api/project_badges/measure?project=senad-d_micme&metric=alert_status" /></a>
9
10
  </p>
10
11
 
11
12
  <p align="center">
@@ -39,6 +40,7 @@ MicMe is a Pi extension for coding prompts. It records your microphone with `ffm
39
40
 
40
41
  - [Quick Start](#quick-start)
41
42
  - [Installation](#installation)
43
+ - [Pi Compatibility](#pi-compatibility)
42
44
  - [Backend Setup](#backend-setup)
43
45
  - [Configuration](#configuration)
44
46
  - [Commands](#commands)
@@ -82,7 +84,7 @@ Use it:
82
84
  3. Press `alt+m` again to stop.
83
85
  4. Review the pasted transcript and press Enter.
84
86
 
85
- Micme is toggle-based. Press-and-hold recording is not used because terminal key-up events are not portable.
87
+ Micme is toggle-based. Press-and-hold recording is not used because terminal key-up events are not portable. A toggle received while Micme is starting, stopping, transcribing, or finalizing is rejected with a warning; wait for that operation to finish before toggling again.
86
88
 
87
89
  ---
88
90
 
@@ -114,6 +116,12 @@ pi install /absolute/path/to/micme
114
116
 
115
117
  ---
116
118
 
119
+ ## Pi Compatibility
120
+
121
+ Micme supports `@earendil-works/pi-coding-agent` and `@earendil-works/pi-tui` versions `>=0.80.7 <0.81.0`. CI installs and tests both packages at `0.80.7`, typechecks every production TypeScript file against their real declarations, and loads the default extension through Pi's jiti-based loader. Supporting a new Pi minor release requires intentionally updating the peer ranges, pinned development versions, and contract gate together.
122
+
123
+ ---
124
+
117
125
  ## Backend Setup
118
126
 
119
127
  Micme does not bundle recorder, transcriber, or model binaries.
@@ -147,7 +155,11 @@ MICME_WHISPER_CPP_MODEL=/path/to/ggml-small.en.bin
147
155
 
148
156
  ## Configuration
149
157
 
150
- MicMe reads settings from shell environment variables and from the global Micme config file at `~/.pi/agent/micme.json`. Shell variables win. `/micme conf` writes only `MICME_*` keys to that JSON file, so settings follow you across pi projects on the same machine.
158
+ MicMe reads settings from shell environment variables and from the global Micme config file at `~/.pi/agent/micme.json`. Shell variables win. `/micme conf` writes only `MICME_*` keys to that JSON file, so settings follow you across pi projects on the same machine. If this file is malformed or its top level is not an object, Micme refuses recording, model download, device discovery, and transcription before starting external work; `/micme conf` remains available so you can locate and fix the file.
159
+
160
+ Config saves are serialized in-process and across Pi processes with `micme.json.lock`, then atomically replace the file with mode `0600`. Each save re-reads the latest file while holding the lock and changes only its requested `MICME_*` keys, preserving `$schema` and other metadata. Saves commit in lock-acquisition order, so the last successful save to the same key wins. Micme waits up to five seconds for the lock; on timeout it leaves the existing config and lock untouched because it cannot safely assume another writer's lock is stale. Remove a leftover lock directory manually only after verifying that no Pi process is saving Micme settings.
161
+
162
+ Numeric runtime settings use bounded fallbacks after integer normalization. Invalid, non-finite, or out-of-range values never reach timers or command arguments: transcription timeouts allow `1000..3600000` ms; stream step/length/keep/flush values allow `100..60000`, `1000..120000`, `0..60000`, and `100..60000` ms; stream tokens allow `1..4096`; committed word chunks allow `1..10`; capture ids allow `-1..255`; VAD allows `0.01..0.99`; and audio sample rates allow `8000..384000` Hz. See the schema for each fallback default.
151
163
 
152
164
  The usual setup path is to run:
153
165
 
@@ -182,11 +194,11 @@ Common settings:
182
194
  | `MICME_LANGUAGE=en` | Transcription language when translation is off. Use `auto` for detection. |
183
195
  | `MICME_TRANSLATE_TO_ENGLISH=off` | “Translate from” option. Leave `off`, or set the spoken source language code such as `hr`, `bs`, `de`, or `tr` to output English. |
184
196
  | `MICME_STREAM_KEEP_CONTEXT=0` | Stream default: avoid Whisper prompt carry-over so live chunks are less likely to rewrite each other. |
185
- | `MICME_STREAM_FLUSH_MS=650` | Stream profile quiet interval before tentative words are committed append-only. |
197
+ | `MICME_STREAM_FLUSH_MS=700` | Runtime-default quiet interval before tentative words are committed append-only. Selecting the stream profile in `/micme conf` writes `650`. |
186
198
  | `MICME_STREAM_FINALIZE_WITH_CLIP=0` | Keep the append-only live transcript on stop. Set `1` to opt in to final clip replacement. |
187
199
  | `MICME_AUTO_SUBMIT=0` | Paste for review. Set `1` to send automatically. |
188
200
  | `MICME_SHORTCUT=alt+m` | Toggle shortcut. Use terminal syntax (`alt+m`, `ctrl+space`, `f8`) or a printable character such as `§`. Restart or `/reload` after changing. |
189
- | `MICME_VALIDATE_AUDIO=1` | Reject near-silent recordings. |
201
+ | `MICME_VALIDATE_AUDIO=1` | Reject near-silent recordings and fail closed when ffmpeg omits or truncates the required `max_volume` metric. With a custom recorder and no ffmpeg, Micme warns and skips this guard; set `0` to disable it intentionally. |
190
202
  | `MICME_RECORD_SAMPLE_RATE=auto` | Raw recording sample-rate override. Leave `auto` so ffmpeg uses the selected input's native rate. |
191
203
  | `MICME_RECORD_SYNC=1` | Automatically preserve wall-clock recording duration from ffmpeg timestamps. |
192
204
  | `MICME_RECORD_METER=0` | Quality-safe default: meter from `raw.wav` instead of a second ffmpeg stdout branch. Set `1` to restore the legacy live meter pipe. |
@@ -222,7 +234,7 @@ Micme supports these backend values in JSON/env config:
222
234
 
223
235
  `/micme conf` keeps the interactive backend picker focused on `whisper.cpp` and `Python Whisper`, then shows only the model/binary fields for the selected backend. For whisper.cpp, `MICME_WHISPER_CPP_MODEL` is the selected ggml/gguf model path; if it is unset, Micme falls back to `${MICME_MODEL_DIR}/ggml-${MICME_DEFAULT_WHISPER_CPP_MODEL}.bin`. For Python Whisper, `MICME_WHISPER_MODEL` is passed as the CLI model name.
224
236
 
225
- With `MICME_AUTO_DOWNLOAD_MODEL=1`, Micme downloads missing standard whisper.cpp models into `MICME_MODEL_DIR`. Existing model paths must point to regular files; directories are rejected before download or transcription. Disable downloads with:
237
+ With `MICME_AUTO_DOWNLOAD_MODEL=1`, Micme downloads missing standard whisper.cpp models into `MICME_MODEL_DIR`. Existing model paths must point to regular files; directories are rejected before download or transcription. Header, body, and file-output inactivity is bounded to two minutes; timed-out or cancelled downloads remove their temporary file. Concurrent requests for the same model share one transfer: cancelling one caller leaves it running for other callers, while cancelling the final owner aborts it. Session shutdown and closing `/micme conf` cancel their ownership and suppress later process starts, saves, notifications, and renders. Disable downloads with:
226
238
 
227
239
  ```env
228
240
  MICME_AUTO_DOWNLOAD_MODEL=0
@@ -239,6 +251,8 @@ MICME_TRANSCRIBE_COMMAND=whisper-cli -m /path/to/model.bin -f {audio} -otxt -of
239
251
 
240
252
  `{audio}`, `{tempDir}`, and `{transcript}` are shell-quoted. `*Raw` placeholders bypass quoting and should only be used when you fully control the command.
241
253
 
254
+ Recorder and streaming commands must remain alive until Micme stops them. A requested stop accepts exit code `0`, a signal Micme sent during escalation, its conventional shell exit code, or ffmpeg's signal-stop code `255`; spawn errors, spontaneous exits, unrelated signals, and other nonzero codes are reported as failures. Partial recorder audio is kept for debugging but is not transcribed. When final-clip streaming is enabled, Micme explicitly falls back to the append-only live transcript if that optional clip recorder fails.
255
+
242
256
  ---
243
257
 
244
258
  ## Troubleshooting
@@ -289,6 +303,7 @@ pi remove npm:@senad-d/micme -l # remove project-local install
289
303
  ```bash
290
304
  npm ci
291
305
  npm run typecheck
306
+ npm run test:pi-contract
292
307
  npm run lint
293
308
  npm run format:check
294
309
  npm run validate
@@ -22,14 +22,14 @@
22
22
  "MICME_KEEP_AUDIO": "0",
23
23
  "MICME_METER_GAIN": "1",
24
24
  "MICME_STREAM_CAPTURE": "-1",
25
- "MICME_STREAM_WORDS_PER_CHUNK": "5",
26
- "MICME_STREAM_FLUSH_MS": "650",
27
- "MICME_STREAM_STEP_MS": "500",
28
- "MICME_STREAM_LENGTH_MS": "3000",
29
- "MICME_STREAM_KEEP_MS": "300",
30
- "MICME_STREAM_MAX_TOKENS": "32",
25
+ "MICME_STREAM_WORDS_PER_CHUNK": "10",
26
+ "MICME_STREAM_FLUSH_MS": "700",
27
+ "MICME_STREAM_STEP_MS": "1000",
28
+ "MICME_STREAM_LENGTH_MS": "5000",
29
+ "MICME_STREAM_KEEP_MS": "500",
30
+ "MICME_STREAM_MAX_TOKENS": "64",
31
31
  "MICME_STREAM_KEEP_CONTEXT": "0",
32
32
  "MICME_STREAM_FINALIZE_WITH_CLIP": "0",
33
- "MICME_STREAM_VAD_THRESHOLD": "0.35",
33
+ "MICME_STREAM_VAD_THRESHOLD": "0.45",
34
34
  "MICME_STREAM_DIAGNOSTICS": "0"
35
35
  }
package/micme.schema.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "https://raw.githubusercontent.com/senad-d/micme/main/micme.schema.json",
4
4
  "title": "Micme configuration",
5
- "description": "Machine-level Micme settings. Shell environment variables override saved values.",
5
+ "description": "Machine-level Micme settings. Shell environment variables override saved values. Invalid numeric values fall back to the documented defaults at runtime.",
6
6
  "type": "object",
7
7
  "properties": {
8
8
  "$schema": {
@@ -29,8 +29,18 @@
29
29
  "default": "auto",
30
30
  "description": "Select transcription backend. auto preserves priority: custom command, whisper.cpp, then Python Whisper."
31
31
  },
32
+ "MICME_TRANSCRIBE_TIMEOUT_MS": {
33
+ "type": ["string", "number"],
34
+ "pattern": "^(?:0|[1-9][0-9]*)$",
35
+ "minimum": 1000,
36
+ "maximum": 3600000,
37
+ "multipleOf": 1,
38
+ "default": "120000",
39
+ "description": "Transcription timeout in whole milliseconds. Runtime range: 1000 through 3600000."
40
+ },
32
41
  "MICME_AUTO_SUBMIT": {
33
- "$ref": "#/$defs/stringFlag"
42
+ "$ref": "#/$defs/stringFlag",
43
+ "default": "0"
34
44
  },
35
45
  "MICME_LANGUAGE": {
36
46
  "type": "string",
@@ -44,7 +54,9 @@
44
54
  "description": "Translate from control. off disables translation; any language code means translate speech in that source language to English."
45
55
  },
46
56
  "MICME_AUTO_DOWNLOAD_MODEL": {
47
- "$ref": "#/$defs/stringFlag"
57
+ "$ref": "#/$defs/stringFlag",
58
+ "default": "1",
59
+ "description": "Download a missing standard whisper.cpp model automatically. Defaults on."
48
60
  },
49
61
  "MICME_DEFAULT_WHISPER_CPP_MODEL": {
50
62
  "type": "string",
@@ -74,8 +86,21 @@
74
86
  },
75
87
  "MICME_RECORD_SAMPLE_RATE": {
76
88
  "type": ["string", "number"],
89
+ "pattern": "^(?:auto|0|[1-9][0-9]*)$",
90
+ "minimum": 8000,
91
+ "maximum": 384000,
92
+ "multipleOf": 1,
77
93
  "default": "auto",
78
- "description": "Raw recording sample-rate override. Leave auto/unset so ffmpeg uses the selected input's native sample rate."
94
+ "description": "Raw recording sample-rate override in whole Hz from 8000 through 384000. Leave auto/unset so ffmpeg uses the selected input's native sample rate."
95
+ },
96
+ "MICME_TRANSCRIBE_SAMPLE_RATE": {
97
+ "type": ["string", "number"],
98
+ "pattern": "^(?:0|[1-9][0-9]*)$",
99
+ "minimum": 8000,
100
+ "maximum": 384000,
101
+ "multipleOf": 1,
102
+ "default": "16000",
103
+ "description": "Sample rate in whole Hz from 8000 through 384000 for processed audio sent to Whisper."
79
104
  },
80
105
  "MICME_RECORD_SYNC": {
81
106
  "$ref": "#/$defs/stringFlag",
@@ -84,31 +109,115 @@
84
109
  },
85
110
  "MICME_RECORD_METER": {
86
111
  "$ref": "#/$defs/stringFlag",
112
+ "default": "0",
87
113
  "description": "Enable the legacy ffmpeg stdout PCM branch for live metering. Defaults off to avoid recorder backpressure; the UI can still meter by polling raw.wav."
88
114
  },
89
115
  "MICME_AVFOUNDATION_DROP_LATE_FRAMES": {
90
116
  "$ref": "#/$defs/stringFlag",
117
+ "default": "0",
91
118
  "description": "macOS AVFoundation only. Defaults off so ffmpeg is asked not to drop late frames when capture lags."
92
119
  },
93
120
  "MICME_AVFOUNDATION_INPUT_SAMPLE_RATE": {
94
121
  "type": ["string", "number"],
95
- "description": "Advanced macOS fallback used only when MICME_RECORD_SYNC=0. Reinterpret input samples with this source rate before resampling."
122
+ "pattern": "^(?:0|[1-9][0-9]*)$",
123
+ "minimum": 8000,
124
+ "maximum": 384000,
125
+ "multipleOf": 1,
126
+ "description": "Advanced macOS fallback from 8000 through 384000 Hz used only when MICME_RECORD_SYNC=0."
127
+ },
128
+ "MICME_PROCESS_AUDIO": {
129
+ "$ref": "#/$defs/stringFlag",
130
+ "default": "1"
131
+ },
132
+ "MICME_VALIDATE_AUDIO": {
133
+ "$ref": "#/$defs/stringFlag",
134
+ "default": "1",
135
+ "description": "Reject near-silent clips and fail when ffmpeg does not provide complete max-volume evidence."
96
136
  },
97
137
  "MICME_KEEP_AUDIO": {
98
- "$ref": "#/$defs/stringFlag"
138
+ "$ref": "#/$defs/stringFlag",
139
+ "default": "0"
140
+ },
141
+ "MICME_STREAM_CAPTURE": {
142
+ "type": ["string", "number"],
143
+ "pattern": "^-?(?:0|[1-9][0-9]*)$",
144
+ "minimum": -1,
145
+ "maximum": 255,
146
+ "multipleOf": 1,
147
+ "default": "-1",
148
+ "description": "whisper-stream/SDL capture id from -1 through 255. -1 selects the system default."
149
+ },
150
+ "MICME_STREAM_STEP_MS": {
151
+ "type": ["string", "number"],
152
+ "pattern": "^(?:0|[1-9][0-9]*)$",
153
+ "minimum": 100,
154
+ "maximum": 60000,
155
+ "multipleOf": 1,
156
+ "default": "1000",
157
+ "description": "whisper-stream processing step in whole milliseconds from 100 through 60000."
158
+ },
159
+ "MICME_STREAM_LENGTH_MS": {
160
+ "type": ["string", "number"],
161
+ "pattern": "^(?:0|[1-9][0-9]*)$",
162
+ "minimum": 1000,
163
+ "maximum": 120000,
164
+ "multipleOf": 1,
165
+ "default": "5000",
166
+ "description": "whisper-stream audio window in whole milliseconds from 1000 through 120000."
167
+ },
168
+ "MICME_STREAM_KEEP_MS": {
169
+ "type": ["string", "number"],
170
+ "pattern": "^(?:0|[1-9][0-9]*)$",
171
+ "minimum": 0,
172
+ "maximum": 60000,
173
+ "multipleOf": 1,
174
+ "default": "500",
175
+ "description": "whisper-stream overlap retained in whole milliseconds from 0 through 60000."
176
+ },
177
+ "MICME_STREAM_MAX_TOKENS": {
178
+ "type": ["string", "number"],
179
+ "pattern": "^(?:0|[1-9][0-9]*)$",
180
+ "minimum": 1,
181
+ "maximum": 4096,
182
+ "multipleOf": 1,
183
+ "default": "64",
184
+ "description": "Maximum whisper-stream tokens from 1 through 4096."
99
185
  },
100
186
  "MICME_STREAM_KEEP_CONTEXT": {
101
187
  "$ref": "#/$defs/stringFlag",
188
+ "default": "0",
102
189
  "description": "Pass --keep-context to whisper-stream. Defaults to off for append-only dictation."
103
190
  },
104
191
  "MICME_STREAM_FINALIZE_WITH_CLIP": {
105
192
  "$ref": "#/$defs/stringFlag",
193
+ "default": "0",
106
194
  "description": "When enabled, stop-time clip transcription may replace the append-only live stream transcript."
107
195
  },
108
196
  "MICME_STREAM_FLUSH_MS": {
109
197
  "type": ["string", "number"],
198
+ "pattern": "^(?:0|[1-9][0-9]*)$",
199
+ "minimum": 100,
200
+ "maximum": 60000,
201
+ "multipleOf": 1,
110
202
  "default": "700",
111
- "description": "Quiet interval in milliseconds before tentative stream words are committed append-only."
203
+ "description": "Quiet interval in whole milliseconds from 100 through 60000 before tentative stream words are committed append-only."
204
+ },
205
+ "MICME_STREAM_WORDS_PER_CHUNK": {
206
+ "type": ["string", "number"],
207
+ "pattern": "^(?:0|[1-9][0-9]*)$",
208
+ "minimum": 1,
209
+ "maximum": 10,
210
+ "multipleOf": 1,
211
+ "default": "10",
212
+ "description": "Maximum stable words committed per streaming update, from 1 through 10."
213
+ },
214
+ "MICME_STREAM_VAD_THRESHOLD": {
215
+ "type": ["string", "number"],
216
+ "pattern": "^(?:0(?:\\.[0-9]+)?|1(?:\\.0+)?)$",
217
+ "minimum": 0.01,
218
+ "maximum": 0.99,
219
+ "default": "0.45",
220
+ "description": "whisper-stream voice activity threshold from 0.01 through 0.99."
112
221
  },
113
222
  "MICME_RECORD_COMMAND": {
114
223
  "type": "string",
@@ -129,8 +238,7 @@
129
238
  "$defs": {
130
239
  "stringFlag": {
131
240
  "type": "string",
132
- "enum": ["0", "1", "true", "false", "yes", "no", "on", "off"],
133
- "default": "0"
241
+ "enum": ["0", "1", "true", "false", "yes", "no", "on", "off"]
134
242
  }
135
243
  }
136
244
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@senad-d/micme",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "type": "module",
5
5
  "description": "Local voice dictation for Pi coding prompts. Press Alt+M, speak, review, send.",
6
6
  "license": "MIT",
@@ -58,6 +58,7 @@
58
58
  "doctor": "node scripts/doctor.mjs",
59
59
  "check": "node --check scripts/doctor.mjs && node --check scripts/check-format.mjs && node --check scripts/check-package-contents.mjs && node --check scripts/publish-npm.mjs",
60
60
  "test": "node --test test/*.test.mjs",
61
+ "test:pi-contract": "node --test test/pi-contract.test.mjs",
61
62
  "typecheck": "tsc --noEmit",
62
63
  "lint": "npm run lint:eslint && npm run typecheck && npm run check",
63
64
  "format:check": "node scripts/check-format.mjs",
@@ -66,7 +67,7 @@
66
67
  "validate": "npm run lint && npm run format:check && npm run test && npm run check:pack",
67
68
  "publish:npm": "node scripts/publish-npm.mjs",
68
69
  "prepublishOnly": "npm run validate",
69
- "test:coverage": "node --test --experimental-test-coverage --test-coverage-include=src/**/*.ts --test-reporter=spec --test-reporter=lcov --test-reporter-destination=stdout --test-reporter-destination=lcov.info test/*.test.mjs",
70
+ "test:coverage": "npm run test:pi-contract && node --test --experimental-test-coverage --test-coverage-include=src/**/*.ts --test-coverage-lines=80 --test-coverage-branches=80 --test-coverage-functions=80 --test-reporter=spec --test-reporter=lcov --test-reporter-destination=stdout --test-reporter-destination=lcov.info --test-skip-pattern=\"jiti loader registers\" test/*.test.mjs",
70
71
  "lint:eslint": "eslint eslint.config.mjs \"scripts/**/*.mjs\" \"test/**/*.mjs\" \"src/**/*.ts\""
71
72
  },
72
73
  "pi": {
@@ -76,17 +77,17 @@
76
77
  "image": "https://raw.githubusercontent.com/senad-d/micme/main/img/demo.gif"
77
78
  },
78
79
  "peerDependencies": {
79
- "@earendil-works/pi-coding-agent": "*",
80
- "@earendil-works/pi-tui": "*"
80
+ "@earendil-works/pi-coding-agent": ">=0.80.7 <0.81.0",
81
+ "@earendil-works/pi-tui": ">=0.80.7 <0.81.0"
81
82
  },
82
83
  "devDependencies": {
83
- "@earendil-works/pi-coding-agent": "file:./dev-shims/pi-coding-agent",
84
- "@earendil-works/pi-tui": "*",
84
+ "@earendil-works/pi-coding-agent": "0.80.7",
85
+ "@earendil-works/pi-tui": "0.80.7",
85
86
  "@eslint/js": "^10.0.1",
86
87
  "@types/node": "^26.0.0",
87
88
  "eslint": "^10.6.0",
88
89
  "globals": "^17.7.0",
89
- "typescript": "^6.0.3",
90
+ "typescript": "~6.0.3",
90
91
  "typescript-eslint": "^8.62.1"
91
92
  }
92
93
  }