@senad-d/micme 0.2.1 → 0.3.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
@@ -10,6 +10,8 @@ All notable changes to Micme will be documented in this file.
10
10
  - Add an interactive npm publishing script that prompts for a version, validates the package, creates the release commit/tag, and publishes with public scoped-package access.
11
11
  - Keep publication on hold until package name, metadata, security review, validation, and smoke tests are complete.
12
12
  - Add explicit transcription backend selection with backend-specific `/micme conf` model rows, doctor diagnostics, schema, and docs.
13
+ - Store kept audio in sequential project directories under `./micme-rec/rec-###/` instead of the system temp directory.
14
+ - Make the recorder quality-safe by default: preserve recorder timing from ffmpeg timestamps, disable the stdout meter branch, and ask macOS AVFoundation not to drop late frames.
13
15
 
14
16
  ## 0.1.0 - 2026-06-18
15
17
 
package/README.md CHANGED
@@ -15,15 +15,15 @@
15
15
 
16
16
  ---
17
17
 
18
- Micme is a pi extension for short coding prompts. It records your microphone with `ffmpeg`, transcribes locally with `whisper.cpp` or another local backend, and inserts the transcript into pi.
18
+ MicMe is a pi extension for short coding prompts. It records your microphone with `ffmpeg`, transcribes locally with `whisper.cpp` or another local backend, and inserts the transcript into pi.
19
19
 
20
20
  <table align="center">
21
21
  <tr>
22
- <th>Micme demo</th>
22
+ <th>MicMe demo</th>
23
23
  </tr>
24
24
  <tr>
25
25
  <td align="center">
26
- <img src="img/demo.gif" alt="Micme demo: record voice and paste the transcript into pi" title="Micme demo" width="760">
26
+ <img src="img/demo.gif" alt="MicMe demo: record voice and paste the transcript into pi" title="MicMe demo" width="760">
27
27
  </td>
28
28
  </tr>
29
29
  </table>
@@ -120,7 +120,7 @@ Micme does not bundle recorder, transcriber, or model binaries.
120
120
 
121
121
  | OS | Install | Device setting |
122
122
  | --- | --- | --- |
123
- | macOS | `brew install ffmpeg whisper-cpp` | `MICME_AUDIO_DEVICE=0` or `MICME_AVFOUNDATION_INPUT=:0` |
123
+ | macOS | `brew install ffmpeg whisper-cpp` | Run `/micme devices`, then set `MICME_AUDIO_DEVICE=<audio id>` or `MICME_AVFOUNDATION_INPUT=:<audio id>`. |
124
124
  | Linux | Install `ffmpeg` and `whisper.cpp` with your package manager, Nix, Homebrew, or source build. | `MICME_PULSE_SOURCE=default` |
125
125
  | Windows | `winget install Gyan.FFmpeg`, then install/build `whisper.cpp`. | `MICME_DSHOW_AUDIO_DEVICE=Microphone Name` |
126
126
 
@@ -182,10 +182,13 @@ Common settings:
182
182
  | `MICME_STREAM_FLUSH_MS=650` | Stream profile quiet interval before tentative words are committed append-only. |
183
183
  | `MICME_STREAM_FINALIZE_WITH_CLIP=0` | Keep the append-only live transcript on stop. Set `1` to opt in to final clip replacement. |
184
184
  | `MICME_AUTO_SUBMIT=0` | Paste for review. Set `1` to send automatically. |
185
- | `MICME_SHORTCUT=alt+m` | Toggle shortcut. Restart or `/reload` after changing. |
186
- | `MICME_PRINTABLE_SHORTCUTS=§` | macOS Option-key fallback. |
185
+ | `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. |
187
186
  | `MICME_VALIDATE_AUDIO=1` | Reject near-silent recordings. |
188
- | `MICME_KEEP_AUDIO=0` | Delete successful temp audio. Set `1` for debugging. |
187
+ | `MICME_RECORD_SAMPLE_RATE=auto` | Raw recording sample-rate override. Leave `auto` so ffmpeg uses the selected input's native rate. |
188
+ | `MICME_RECORD_SYNC=1` | Automatically preserve wall-clock recording duration from ffmpeg timestamps. |
189
+ | `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. |
190
+ | `MICME_AVFOUNDATION_DROP_LATE_FRAMES=0` | macOS only: ask AVFoundation not to drop late frames when capture lags. |
191
+ | `MICME_KEEP_AUDIO=0` | Delete successful recording audio. Set `1` to keep each recording under `./micme-rec/rec-###/` for debugging. |
189
192
  | `MICME_MODEL_DIR=~/.cache/whisper.cpp` | Model cache/discovery directory. |
190
193
 
191
194
  See [`micme.example.json`](micme.example.json) for the full JSON template.
@@ -211,10 +214,8 @@ Streaming mode treats `whisper-stream` output as repeated, overlapping hypothese
211
214
 
212
215
  Micme supports these backend values in JSON/env config:
213
216
 
214
- - `auto` (default): custom command when configured, otherwise whisper.cpp, otherwise Python Whisper.
215
217
  - `whisper.cpp`: uses `whisper-cli`/`whisper-cpp` and a ggml/gguf model path.
216
218
  - `python`: uses the OpenAI Whisper `whisper` CLI and a Python model name.
217
- - `custom`: runs `MICME_TRANSCRIBE_COMMAND`; Micme treats the model as unknown.
218
219
 
219
220
  `/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.
220
221
 
@@ -229,7 +230,7 @@ Recommended model progression: `base.en` for speed, `small.en` for a stronger de
229
230
  Advanced users can replace the recorder or transcriber:
230
231
 
231
232
  ```env
232
- MICME_RECORD_COMMAND=ffmpeg -hide_banner -loglevel error -f avfoundation -i :0 -ac 1 -ar 16000 -y {audio}
233
+ MICME_RECORD_COMMAND=ffmpeg -hide_banner -loglevel error -f avfoundation -i :0 -af aresample=async=1:first_pts=0 -ac 1 -y {audio}
233
234
  MICME_TRANSCRIBE_COMMAND=whisper-cli -m /path/to/model.bin -f {audio} -otxt -of {tempDirRaw}/out -nt -np && cat {tempDirRaw}/out.txt
234
235
  ```
235
236
 
@@ -243,6 +244,7 @@ MICME_TRANSCRIBE_COMMAND=whisper-cli -m /path/to/model.bin -f {audio} -otxt -of
243
244
  | --- | --- |
244
245
  | No backend found | Use `/micme conf` to choose `whisper.cpp` or Python Whisper, install the selected backend, or configure a trusted custom command manually. |
245
246
  | Wrong microphone | Run `/micme devices`, then set the OS-specific device variable. |
247
+ | Crackling or shortened audio | Keep `MICME_RECORD_SYNC=1` and `MICME_RECORD_METER=0`; on macOS keep `MICME_AVFOUNDATION_DROP_LATE_FRAMES=0`, and avoid Aggregate/BlackHole devices unless intentionally routing audio. |
246
248
  | Unrelated transcript | You probably recorded silence. Set `MICME_KEEP_AUDIO=1` and check `/micme audio`. |
247
249
  | Slow transcription | Use `whisper.cpp`, a smaller model, and shorter recordings. |
248
250
  | Option/Alt inserts `§` or `µ` | Set `MICME_PRINTABLE_SHORTCUTS=§` or change `MICME_SHORTCUT`, then `/reload`. |
package/SECURITY.md CHANGED
@@ -23,7 +23,7 @@ The default recorder uses `ffmpeg` and your operating system's microphone APIs:
23
23
  - Linux: PulseAudio through `ffmpeg -f pulse`
24
24
  - Windows: DirectShow through `ffmpeg -f dshow`
25
25
 
26
- Micme writes temporary audio files under the operating system temp directory while a recording is being processed. After successful transcription, those files are removed by default. Set `MICME_KEEP_AUDIO=1` only when you intentionally want to keep the last raw/preprocessed audio for debugging.
26
+ Micme writes temporary audio files under the operating system temp directory by default. After successful transcription, those files are removed. Set `MICME_KEEP_AUDIO=1` only when you intentionally want to keep raw/preprocessed audio for debugging; kept recordings are written to per-recording project directories such as `./micme-rec/rec-001/`.
27
27
 
28
28
  ## Local process execution
29
29
 
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/senad-d/micme/main/micme.schema.json",
3
3
  "MICME_SHORTCUT": "alt+m",
4
- "MICME_PRINTABLE_SHORTCUTS": "§",
5
4
  "MICME_TRANSCRIPTION_MODE": "clip",
6
5
  "MICME_TRANSCRIBE_BACKEND": "auto",
7
6
  "MICME_AUTO_SUBMIT": "0",
@@ -11,8 +10,11 @@
11
10
  "MICME_DEFAULT_WHISPER_CPP_MODEL": "small.en",
12
11
  "MICME_MODEL_DIR": "${HOME}/.cache/whisper.cpp",
13
12
  "MICME_AUDIO_DEVICE": "0",
14
- "MICME_RECORD_SAMPLE_RATE": "48000",
13
+ "MICME_RECORD_SAMPLE_RATE": "auto",
15
14
  "MICME_TRANSCRIBE_SAMPLE_RATE": "16000",
15
+ "MICME_RECORD_SYNC": "1",
16
+ "MICME_RECORD_METER": "0",
17
+ "MICME_AVFOUNDATION_DROP_LATE_FRAMES": "0",
16
18
  "MICME_PROCESS_AUDIO": "1",
17
19
  "MICME_AUDIO_FILTER": "highpass=f=80,lowpass=f=7600",
18
20
  "MICME_VALIDATE_AUDIO": "1",
package/micme.schema.json CHANGED
@@ -10,11 +10,13 @@
10
10
  },
11
11
  "MICME_SHORTCUT": {
12
12
  "type": "string",
13
- "default": "alt+m"
13
+ "default": "alt+m",
14
+ "description": "Unified toggle shortcut. Use terminal syntax such as alt+m/ctrl+space/f8, or a printable character such as §."
14
15
  },
15
16
  "MICME_PRINTABLE_SHORTCUTS": {
16
17
  "type": "string",
17
- "default": "§"
18
+ "default": "§",
19
+ "description": "Legacy printable-character fallback. Prefer MICME_SHORTCUT with a printable character."
18
20
  },
19
21
  "MICME_TRANSCRIPTION_MODE": {
20
22
  "type": "string",
@@ -63,6 +65,28 @@
63
65
  "type": "string",
64
66
  "default": "0"
65
67
  },
68
+ "MICME_RECORD_SAMPLE_RATE": {
69
+ "type": ["string", "number"],
70
+ "default": "auto",
71
+ "description": "Raw recording sample-rate override. Leave auto/unset so ffmpeg uses the selected input's native sample rate."
72
+ },
73
+ "MICME_RECORD_SYNC": {
74
+ "$ref": "#/$defs/stringFlag",
75
+ "default": "1",
76
+ "description": "Preserve wall-clock recording duration from ffmpeg timestamps with aresample async correction. Defaults on."
77
+ },
78
+ "MICME_RECORD_METER": {
79
+ "$ref": "#/$defs/stringFlag",
80
+ "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."
81
+ },
82
+ "MICME_AVFOUNDATION_DROP_LATE_FRAMES": {
83
+ "$ref": "#/$defs/stringFlag",
84
+ "description": "macOS AVFoundation only. Defaults off so ffmpeg is asked not to drop late frames when capture lags."
85
+ },
86
+ "MICME_AVFOUNDATION_INPUT_SAMPLE_RATE": {
87
+ "type": ["string", "number"],
88
+ "description": "Advanced macOS fallback used only when MICME_RECORD_SYNC=0. Reinterpret input samples with this source rate before resampling."
89
+ },
66
90
  "MICME_KEEP_AUDIO": {
67
91
  "$ref": "#/$defs/stringFlag"
68
92
  },
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@senad-d/micme",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
- "description": "Local voice-to-text for pi, optimized for fast Whisper-style backends.",
5
+ "description": "Local voice dictation for Pi coding prompts. Press Alt+M, speak, review, send.",
6
6
  "license": "MIT",
7
7
  "author": "Senad Dizdarević <112484166+senad-d@users.noreply.github.com>",
8
8
  "repository": {
@@ -16,12 +16,22 @@
16
16
  "keywords": [
17
17
  "pi-package",
18
18
  "pi-extension",
19
+ "pi-agent",
20
+ "pi-coding-agent",
19
21
  "voice-to-text",
20
22
  "speech-to-text",
23
+ "voice-input",
21
24
  "dictation",
22
25
  "whisper",
23
- "whisper.cpp",
24
- "local-first"
26
+ "whisper-cpp",
27
+ "local-first",
28
+ "offline",
29
+ "privacy",
30
+ "developer-tools",
31
+ "cli",
32
+ "terminal",
33
+ "typescript",
34
+ "coding-agent"
25
35
  ],
26
36
  "engines": {
27
37
  "node": ">=22.19.0"
@@ -56,7 +66,8 @@
56
66
  "pi": {
57
67
  "extensions": [
58
68
  "./src/extension.ts"
59
- ]
69
+ ],
70
+ "image": "https://raw.githubusercontent.com/senad-d/micme/main/img/demo.gif"
60
71
  },
61
72
  "peerDependencies": {
62
73
  "@earendil-works/pi-coding-agent": "*",
@@ -13,6 +13,7 @@ const forbiddenChecks = [
13
13
  { label: "node_modules", test: (path) => path.startsWith("node_modules/") || path.includes("/node_modules/") },
14
14
  { label: "planning specs", test: (path) => path.startsWith("specs/") },
15
15
  { label: "Micme cache", test: (path) => path.startsWith(".micme/") || path.includes("/.micme/") },
16
+ { label: "Micme recordings", test: (path) => path.startsWith("micme-rec/") || path.includes("/micme-rec/") },
16
17
  { label: "token insight files", test: (path) => path.includes("token-insights") },
17
18
  { label: "npm tarballs", test: (path) => /(^|\/)micme-[^/]+\.tgz$/i.test(path) || path.endsWith(".tgz") },
18
19
  { label: "audio artifacts", test: (path) => /\.(wav|mp3|m4a|flac|ogg|opus|aiff?|pcm)$/i.test(path) },
package/src/audio.ts CHANGED
@@ -2,7 +2,7 @@ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-a
2
2
  import { sliceByColumn, visibleWidth, type Component } from "@earendil-works/pi-tui";
3
3
  import { join } from "node:path";
4
4
  import { AUDIO_VALIDATION_TIMEOUT_MS } from "./constants.ts";
5
- import { env, envFlag, getAudioFilter, getMinMaxVolumeDb, getRecordSampleRate, getTranscribeSampleRate } from "./config.ts";
5
+ import { env, envFlag, getAudioFilter, getAvfoundationDropLateFrames, getAvfoundationInputSampleRate, getMinMaxVolumeDb, getRecordMeter, getRecordSampleRate, getRecordSync, getTranscribeSampleRate } from "./config.ts";
6
6
  import { findExecutable, formatRunExit, replacePlaceholders, runProcess, shellCommand, shellQuote } from "./processes.ts";
7
7
  import type { AudioDeviceCandidate, AudioDiagnostics, CommandSpec, RunResult } from "./types.ts";
8
8
 
@@ -58,6 +58,7 @@ const DEVICE_PANEL_MESSAGE_TYPE = "micme-devices";
58
58
  const DEVICE_PANEL_DEFAULT_WIDTH = 92;
59
59
  const DEVICE_PANEL_MAX_WIDTH = 100;
60
60
  const DEVICE_PANEL_MIN_WIDTH = 36;
61
+ const RECORD_TIMING_SYNC_FILTER = "aresample=async=1:first_pts=0";
61
62
 
62
63
  let deviceMessageRendererRegistered = false;
63
64
 
@@ -337,7 +338,11 @@ function sendDevicePanelMessage(pi: ExtensionAPI | undefined, options: DevicePan
337
338
  }
338
339
 
339
340
  class DevicePanelMessageComponent implements Component {
340
- constructor(private readonly options: DevicePanelOptions) {}
341
+ private readonly options: DevicePanelOptions;
342
+
343
+ constructor(options: DevicePanelOptions) {
344
+ this.options = options;
345
+ }
341
346
 
342
347
  render(width: number): string[] {
343
348
  return renderDevicePanel(this.options, Math.min(width, DEVICE_PANEL_MAX_WIDTH)).split("\n");
@@ -644,31 +649,45 @@ export function buildRecorderCommand(audioPath: string): CommandSpec {
644
649
  throw new Error("Micme needs ffmpeg for recording, or set MICME_RECORD_COMMAND.");
645
650
  }
646
651
 
647
- const recordSampleRate = String(getRecordSampleRate());
652
+ const recordSampleRate = getRecordSampleRate()?.toString();
653
+ const recordMeter = getRecordMeter();
654
+ const recordSync = getRecordSync();
655
+ const timingFilters = recordSync ? [RECORD_TIMING_SYNC_FILTER] : [];
648
656
 
649
657
  if (process.platform === "darwin") {
650
658
  const input = env("MICME_AVFOUNDATION_INPUT") || `:${env("MICME_AUDIO_DEVICE") || "0"}`;
651
- const args = buildMeteredFfmpegRecorderArgs("avfoundation", input, audioPath, recordSampleRate);
652
- return { command: ffmpeg, args, display: `${ffmpeg} ${args.map(shellQuote).join(" ")}`, meterFromStdout: true, stopInput: "q\n" };
659
+ const avfoundationInputSampleRate = getAvfoundationInputSampleRate();
660
+ const args = buildFfmpegRecorderArgs("avfoundation", input, audioPath, recordSampleRate, {
661
+ meter: recordMeter,
662
+ inputOptions: ["-drop_late_frames", getAvfoundationDropLateFrames() ? "true" : "false"],
663
+ audioFilters: recordSync ? timingFilters : avfoundationInputSampleRate ? [`asetrate=${avfoundationInputSampleRate}`] : [],
664
+ });
665
+ return { command: ffmpeg, args, display: `${ffmpeg} ${args.map(shellQuote).join(" ")}`, meterFromStdout: recordMeter, stopInput: "q\n" };
653
666
  }
654
667
 
655
668
  if (process.platform === "linux") {
656
669
  const input = env("MICME_PULSE_SOURCE") || "default";
657
- const args = buildMeteredFfmpegRecorderArgs("pulse", input, audioPath, recordSampleRate);
658
- return { command: ffmpeg, args, display: `${ffmpeg} ${args.map(shellQuote).join(" ")}`, meterFromStdout: true, stopInput: "q\n" };
670
+ const args = buildFfmpegRecorderArgs("pulse", input, audioPath, recordSampleRate, { meter: recordMeter, audioFilters: timingFilters });
671
+ return { command: ffmpeg, args, display: `${ffmpeg} ${args.map(shellQuote).join(" ")}`, meterFromStdout: recordMeter, stopInput: "q\n" };
659
672
  }
660
673
 
661
674
  if (process.platform === "win32") {
662
675
  const input = `audio=${env("MICME_DSHOW_AUDIO_DEVICE") || "default"}`;
663
- const args = buildMeteredFfmpegRecorderArgs("dshow", input, audioPath, recordSampleRate);
664
- return { command: ffmpeg, args, display: `${ffmpeg} ${args.map(shellQuote).join(" ")}`, meterFromStdout: true, stopInput: "q\n" };
676
+ const args = buildFfmpegRecorderArgs("dshow", input, audioPath, recordSampleRate, { meter: recordMeter, audioFilters: timingFilters });
677
+ return { command: ffmpeg, args, display: `${ffmpeg} ${args.map(shellQuote).join(" ")}`, meterFromStdout: recordMeter, stopInput: "q\n" };
665
678
  }
666
679
 
667
680
  throw new Error(`Micme has no default recorder for ${process.platform}. Set MICME_RECORD_COMMAND.`);
668
681
  }
669
682
 
670
- export function buildMeteredFfmpegRecorderArgs(inputFormat: string, input: string, audioPath: string, recordSampleRate: string) {
671
- return [
683
+ type FfmpegRecorderOptions = {
684
+ meter?: boolean;
685
+ inputOptions?: string[];
686
+ audioFilters?: string[];
687
+ };
688
+
689
+ export function buildFfmpegRecorderArgs(inputFormat: string, input: string, audioPath: string, recordSampleRate: string | undefined, options: FfmpegRecorderOptions = {}) {
690
+ const inputArgs = [
672
691
  "-hide_banner",
673
692
  "-loglevel",
674
693
  "error",
@@ -676,21 +695,28 @@ export function buildMeteredFfmpegRecorderArgs(inputFormat: string, input: strin
676
695
  "4096",
677
696
  "-f",
678
697
  inputFormat,
698
+ ...(options.inputOptions ?? []),
679
699
  "-i",
680
700
  input,
701
+ ];
702
+ const fileOutputArgs = ["-ac", "1", ...formatOptionalSampleRateArgs(recordSampleRate), "-c:a", "pcm_s16le", "-vn", "-y", audioPath];
703
+ const audioFilters = (options.audioFilters ?? []).filter(Boolean);
704
+
705
+ if (options.meter === false && audioFilters.length === 0) {
706
+ return [...inputArgs, "-map", "0:a:0", ...fileOutputArgs];
707
+ }
708
+
709
+ if (options.meter === false) {
710
+ return [...inputArgs, "-filter_complex", buildFileOnlyAudioFilterGraph(audioFilters), "-map", "[micme_file]", ...fileOutputArgs];
711
+ }
712
+
713
+ return [
714
+ ...inputArgs,
681
715
  "-filter_complex",
682
- "[0:a]asplit=2[micme_file][micme_meter]",
716
+ buildMeteredAudioFilterGraph(audioFilters),
683
717
  "-map",
684
718
  "[micme_file]",
685
- "-ac",
686
- "1",
687
- "-ar",
688
- recordSampleRate,
689
- "-c:a",
690
- "pcm_s16le",
691
- "-vn",
692
- "-y",
693
- audioPath,
719
+ ...fileOutputArgs,
694
720
  "-map",
695
721
  "[micme_meter]",
696
722
  "-ac",
@@ -702,3 +728,20 @@ export function buildMeteredFfmpegRecorderArgs(inputFormat: string, input: strin
702
728
  "pipe:1",
703
729
  ];
704
730
  }
731
+
732
+ export function buildMeteredFfmpegRecorderArgs(inputFormat: string, input: string, audioPath: string, recordSampleRate: string | undefined) {
733
+ return buildFfmpegRecorderArgs(inputFormat, input, audioPath, recordSampleRate, { meter: true });
734
+ }
735
+
736
+ function formatOptionalSampleRateArgs(recordSampleRate: string | undefined) {
737
+ return recordSampleRate ? ["-ar", recordSampleRate] : [];
738
+ }
739
+
740
+ function buildFileOnlyAudioFilterGraph(audioFilters: string[]) {
741
+ return audioFilters.length > 0 ? `[0:a]${audioFilters.join(",")}[micme_file]` : "[0:a]anull[micme_file]";
742
+ }
743
+
744
+ function buildMeteredAudioFilterGraph(audioFilters: string[]) {
745
+ const prefix = audioFilters.length > 0 ? `${audioFilters.join(",")},` : "";
746
+ return `[0:a]${prefix}asplit=2[micme_file][micme_meter]`;
747
+ }
package/src/config.ts CHANGED
@@ -75,7 +75,7 @@ export async function writeMicmeConfigValue(key: string, value: string) {
75
75
  await writeMicmeConfigValues({ [key]: value });
76
76
  }
77
77
 
78
- export async function writeMicmeConfigValues(values: Record<string, string>) {
78
+ export async function writeMicmeConfigValues(values: Record<string, string | undefined>) {
79
79
  for (const key of Object.keys(values)) {
80
80
  if (!key.startsWith("MICME_")) throw new Error(`Micme config keys must start with MICME_: ${key}`);
81
81
  }
@@ -85,7 +85,13 @@ export async function writeMicmeConfigValues(values: Record<string, string>) {
85
85
  const existing = readMicmeJsonObjectForWrite(configPath);
86
86
  const next: JsonObject = { ...existing };
87
87
 
88
- for (const [key, value] of Object.entries(values)) next[key] = String(value);
88
+ for (const [key, value] of Object.entries(values)) {
89
+ if (value === undefined) {
90
+ delete next[key];
91
+ } else {
92
+ next[key] = String(value);
93
+ }
94
+ }
89
95
 
90
96
  await mkdir(configDir, { recursive: true });
91
97
  const tempPath = join(configDir, `.micme.${process.pid}.${Date.now()}.${Math.random().toString(16).slice(2)}.tmp`);
@@ -147,8 +153,22 @@ export function env(name: string) {
147
153
  return process.env[name] ?? micmeConfigState.values[name];
148
154
  }
149
155
 
156
+ export function getShortcutSettingValue() {
157
+ const shortcut = env("MICME_SHORTCUT");
158
+ if (shortcut !== undefined) return shortcut;
159
+
160
+ const legacyPrintableShortcut = firstShortcutValue(env("MICME_PRINTABLE_SHORTCUTS"));
161
+ return legacyPrintableShortcut || DEFAULT_SHORTCUT;
162
+ }
163
+
150
164
  export function getShortcut() {
151
- return env("MICME_SHORTCUT") || DEFAULT_SHORTCUT;
165
+ return getShortcutSettingValue() || "not set";
166
+ }
167
+
168
+ export function getTerminalShortcut() {
169
+ const shortcut = env("MICME_SHORTCUT");
170
+ if (shortcut !== undefined) return isTerminalShortcut(shortcut) ? shortcut.trim() : undefined;
171
+ return DEFAULT_SHORTCUT;
152
172
  }
153
173
 
154
174
  export function getTranscriptionMode() {
@@ -165,13 +185,15 @@ export function isTranscribeBackend(value: string | undefined): value is Transcr
165
185
  }
166
186
 
167
187
  export function getPrintableShortcuts() {
168
- const configured = env("MICME_PRINTABLE_SHORTCUTS");
169
- if (configured !== undefined) {
170
- return configured
171
- .split(",")
172
- .map((value) => value.trim())
173
- .filter(Boolean);
188
+ const shortcut = env("MICME_SHORTCUT");
189
+ if (shortcut !== undefined) {
190
+ if (shortcut && !isTerminalShortcut(shortcut)) return splitShortcutValues(shortcut);
191
+ const legacyConfigured = env("MICME_PRINTABLE_SHORTCUTS");
192
+ return legacyConfigured !== undefined ? splitShortcutValues(legacyConfigured) : [];
174
193
  }
194
+
195
+ const legacyConfigured = env("MICME_PRINTABLE_SHORTCUTS");
196
+ if (legacyConfigured !== undefined) return splitShortcutValues(legacyConfigured);
175
197
  return process.platform === "darwin" ? [DEFAULT_MACOS_PRINTABLE_SHORTCUT] : [];
176
198
  }
177
199
 
@@ -179,6 +201,22 @@ export function matchesPrintableMicmeShortcut(data: string) {
179
201
  return getPrintableShortcuts().includes(data);
180
202
  }
181
203
 
204
+ export function isTerminalShortcut(value: string) {
205
+ const normalized = value.trim();
206
+ return /^[\x20-\x7E]$/.test(normalized) || /^(?:escape|esc|enter|return|tab|space|backspace|delete|insert|clear|home|end|pageUp|pageDown|up|down|left|right|f\d{1,2}|(?:(?:ctrl|control|alt|option|meta|cmd|command|shift|super)\+)+.+)$/i.test(normalized);
207
+ }
208
+
209
+ function firstShortcutValue(value: string | undefined) {
210
+ return splitShortcutValues(value ?? "")[0] ?? "";
211
+ }
212
+
213
+ function splitShortcutValues(value: string) {
214
+ return value
215
+ .split(",")
216
+ .map((candidate) => candidate.trim())
217
+ .filter(Boolean);
218
+ }
219
+
182
220
  export function getTranscribeTimeoutMs() {
183
221
  const value = Number(env("MICME_TRANSCRIBE_TIMEOUT_MS"));
184
222
  return Number.isFinite(value) && value > 0 ? value : DEFAULT_TRANSCRIBE_TIMEOUT_MS;
@@ -230,8 +268,10 @@ export function getStreamWordsPerChunk() {
230
268
  }
231
269
 
232
270
  export function getRecordSampleRate() {
233
- const value = Number(env("MICME_RECORD_SAMPLE_RATE"));
234
- return Number.isFinite(value) && value > 0 ? Math.round(value) : DEFAULT_RECORD_SAMPLE_RATE;
271
+ const configured = env("MICME_RECORD_SAMPLE_RATE")?.trim();
272
+ if (!configured || /^auto$/i.test(configured)) return undefined;
273
+ const value = Number(configured);
274
+ return Number.isFinite(value) && value > 0 ? Math.round(value) : undefined;
235
275
  }
236
276
 
237
277
  export function getTranscribeSampleRate() {
@@ -239,6 +279,24 @@ export function getTranscribeSampleRate() {
239
279
  return Number.isFinite(value) && value > 0 ? Math.round(value) : DEFAULT_TRANSCRIBE_SAMPLE_RATE;
240
280
  }
241
281
 
282
+ export function getRecordMeter() {
283
+ return envFlag("MICME_RECORD_METER");
284
+ }
285
+
286
+ export function getRecordSync() {
287
+ const value = env("MICME_RECORD_SYNC");
288
+ return value === undefined ? true : /^(1|true|yes|on)$/i.test(value);
289
+ }
290
+
291
+ export function getAvfoundationDropLateFrames() {
292
+ return envFlag("MICME_AVFOUNDATION_DROP_LATE_FRAMES");
293
+ }
294
+
295
+ export function getAvfoundationInputSampleRate() {
296
+ const value = Number(env("MICME_AVFOUNDATION_INPUT_SAMPLE_RATE"));
297
+ return Number.isFinite(value) && value > 0 ? Math.round(value) : undefined;
298
+ }
299
+
242
300
  export function getAudioFilter() {
243
301
  if (env("MICME_AUDIO_FILTER") !== undefined) return env("MICME_AUDIO_FILTER")!.trim();
244
302
  return "highpass=f=80,lowpass=f=7600";
package/src/constants.ts CHANGED
@@ -3,7 +3,7 @@ export const RECORDING_WIDGET_KEY = "micme-recording";
3
3
  export const DEFAULT_SHORTCUT = "alt+m";
4
4
  export const DEFAULT_MACOS_PRINTABLE_SHORTCUT = "§";
5
5
  export const DEFAULT_TRANSCRIBE_TIMEOUT_MS = 120_000;
6
- export const DEFAULT_RECORD_SAMPLE_RATE = 48_000;
6
+ export const DEFAULT_RECORD_SAMPLE_RATE = "auto";
7
7
  export const DEFAULT_TRANSCRIBE_SAMPLE_RATE = 16_000;
8
8
  export const RECORDER_STARTUP_GRACE_MS = 700;
9
9
  export const RECORDER_STOP_GRACE_MS = 3_000;
package/src/extension.ts CHANGED
@@ -1,13 +1,11 @@
1
1
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
2
- import { mkdtemp } from "node:fs/promises";
3
- import { tmpdir } from "node:os";
4
2
  import { join } from "node:path";
5
3
  import { RECORDER_STARTUP_GRACE_MS, STATUS_KEY } from "./constants.ts";
6
4
  import {
7
- env,
8
5
  envFlag,
9
6
  getShortcut,
10
7
  getStreamFinalizeWithClip,
8
+ getTerminalShortcut,
11
9
  getTranscriptionMode,
12
10
  reloadMicmeConfig,
13
11
  } from "./config.ts";
@@ -25,6 +23,7 @@ import {
25
23
  stopRecorder,
26
24
  } from "./processes.ts";
27
25
  import { clearRecordingWidget, startRecordingWidget } from "./recording-widget.ts";
26
+ import { createRecordingDirectory } from "./recording-dir.ts";
28
27
  import { showConfiguration } from "./settings.ts";
29
28
  import {
30
29
  buildWhisperStreamCommand,
@@ -101,17 +100,20 @@ export default function micmeExtension(pi: ExtensionAPI) {
101
100
  },
102
101
  });
103
102
 
104
- pi.registerShortcut(getShortcut() as Parameters<ExtensionAPI["registerShortcut"]>[0], {
105
- description: "Micme: toggle local voice recording",
106
- handler: async (ctx) => {
107
- try {
108
- if (isShortcutAutoRepeat()) return;
109
- await toggle(ctx);
110
- } catch (error) {
111
- handleExtensionError(ctx, error);
112
- }
113
- },
114
- });
103
+ const terminalShortcut = getTerminalShortcut();
104
+ if (terminalShortcut) {
105
+ pi.registerShortcut(terminalShortcut as Parameters<ExtensionAPI["registerShortcut"]>[0], {
106
+ description: "Micme: toggle local voice recording",
107
+ handler: async (ctx) => {
108
+ try {
109
+ if (isShortcutAutoRepeat()) return;
110
+ await toggle(ctx);
111
+ } catch (error) {
112
+ handleExtensionError(ctx, error);
113
+ }
114
+ },
115
+ });
116
+ }
115
117
 
116
118
  pi.on("session_start", async (_event, ctx) => {
117
119
  reloadMicmeConfig();
@@ -163,13 +165,14 @@ function getHelpText() {
163
165
 
164
166
  async function startRecording(ctx: ExtensionContext, stopHint = getShortcut()) {
165
167
  if (recording) return;
168
+ reloadMicmeConfig();
166
169
 
167
170
  if (getTranscriptionMode() === "stream") {
168
171
  await startStreamingTranscription(ctx, stopHint);
169
172
  return;
170
173
  }
171
174
 
172
- const tempDir = await mkdtemp(join(tmpdir(), "micme-"));
175
+ const tempDir = await createRecordingDirectory(ctx.cwd, envFlag("MICME_KEEP_AUDIO"), "micme-");
173
176
  const audioPath = join(tempDir, "raw.wav");
174
177
  const command = buildRecorderCommand(audioPath);
175
178
  const active = spawnRecording(command, audioPath, tempDir);
@@ -247,7 +250,7 @@ async function startStreamingTranscription(ctx: ExtensionContext, stopHint = get
247
250
 
248
251
  await ensureWhisperCppModel(plan.modelPath, ctx, { allowDownload: plan.modelDownloadable !== false });
249
252
 
250
- const tempDir = await mkdtemp(join(tmpdir(), "micme-stream-"));
253
+ const tempDir = await createRecordingDirectory(ctx.cwd, envFlag("MICME_KEEP_AUDIO"), "micme-stream-");
251
254
  const command = buildWhisperStreamCommand(plan.binary, plan.modelPath, tempDir);
252
255
  const active = spawnRecording(command, "", tempDir);
253
256
  const baseText = ctx.ui.getEditorText();
@@ -0,0 +1,54 @@
1
+ import { mkdir, mkdtemp, readdir } from "node:fs/promises";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+
5
+ const PROJECT_RECORDINGS_DIR = "micme-rec";
6
+ const RECORDING_DIR_PREFIX = "rec-";
7
+ const MAX_SEQUENTIAL_RECORDING_DIRS = 999_999;
8
+
9
+ export async function createRecordingDirectory(cwd: string, keepAudio: boolean, tempPrefix = "micme-") {
10
+ if (!keepAudio) return mkdtemp(join(tmpdir(), tempPrefix));
11
+ return createProjectRecordingDirectory(cwd);
12
+ }
13
+
14
+ export async function createProjectRecordingDirectory(cwd: string) {
15
+ const recordingsRoot = join(cwd, PROJECT_RECORDINGS_DIR);
16
+ await mkdir(recordingsRoot, { recursive: true });
17
+
18
+ const nextIndex = await getNextRecordingIndex(recordingsRoot);
19
+
20
+ for (let index = nextIndex; index <= MAX_SEQUENTIAL_RECORDING_DIRS; index += 1) {
21
+ const candidate = join(recordingsRoot, formatRecordingDirectoryName(index));
22
+ try {
23
+ await mkdir(candidate);
24
+ return candidate;
25
+ } catch (error) {
26
+ if (isAlreadyExistsError(error)) continue;
27
+ throw error;
28
+ }
29
+ }
30
+
31
+ throw new Error(`Unable to create a Micme recording directory under ${recordingsRoot}.`);
32
+ }
33
+
34
+ async function getNextRecordingIndex(recordingsRoot: string) {
35
+ const entries = await readdir(recordingsRoot, { withFileTypes: true });
36
+ let maxIndex = 0;
37
+ for (const entry of entries) {
38
+ const match = /^rec-(\d+)$/.exec(entry.name);
39
+ if (!match) continue;
40
+ const index = Number(match[1]);
41
+ if (Number.isInteger(index) && index > maxIndex) maxIndex = index;
42
+ }
43
+ return Math.max(1, maxIndex + 1);
44
+ }
45
+
46
+ export function formatRecordingDirectoryName(index: number) {
47
+ const safeIndex = Math.max(1, Math.trunc(index));
48
+ const text = String(safeIndex);
49
+ return `${RECORDING_DIR_PREFIX}${text.padStart(Math.max(3, text.length), "0")}`;
50
+ }
51
+
52
+ function isAlreadyExistsError(error: unknown) {
53
+ return typeof error === "object" && error !== null && "code" in error && (error as NodeJS.ErrnoException).code === "EEXIST";
54
+ }
package/src/settings.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import { DynamicBorder, type ExtensionContext } from "@earendil-works/pi-coding-agent";
2
2
  import {
3
3
  Container,
4
+ decodeKittyPrintable,
4
5
  fuzzyFilter,
5
6
  Key,
6
7
  matchesKey,
8
+ parseKey,
7
9
  type Component,
8
10
  type SelectItem,
9
11
  SelectList,
@@ -14,9 +16,7 @@ import {
14
16
  } from "@earendil-works/pi-tui";
15
17
  import { basename } from "node:path";
16
18
  import {
17
- DEFAULT_MACOS_PRINTABLE_SHORTCUT,
18
19
  DEFAULT_RECORD_SAMPLE_RATE,
19
- DEFAULT_SHORTCUT,
20
20
  DEFAULT_STREAM_VAD_THRESHOLD,
21
21
  DEFAULT_STREAM_FLUSH_MS,
22
22
  DEFAULT_TRANSCRIBE_SAMPLE_RATE,
@@ -24,6 +24,7 @@ import {
24
24
  import {
25
25
  env,
26
26
  expandConfigPath,
27
+ getShortcutSettingValue,
27
28
  getTranscriptionMode,
28
29
  getTranscriptionModeProfile,
29
30
  reloadMicmeConfig,
@@ -109,6 +110,8 @@ class ConfigurationScreen implements Component {
109
110
  private searchQuery = "";
110
111
  private selectedSearchIndex = 0;
111
112
  private submenuComponent: Component | null = null;
113
+ private editingShortcutItem: ConfigurationItem | null = null;
114
+ private pendingShortcutValue = "";
112
115
  private saving = false;
113
116
  private statusText = "";
114
117
 
@@ -148,6 +151,11 @@ class ConfigurationScreen implements Component {
148
151
  return;
149
152
  }
150
153
 
154
+ if (this.editingShortcutItem) {
155
+ this.handleShortcutCaptureInput(data);
156
+ return;
157
+ }
158
+
151
159
  if (matchesKey(data, Key.ctrl("c")) || data === "q" || data === "Q") {
152
160
  this.onDone();
153
161
  return;
@@ -348,6 +356,10 @@ class ConfigurationScreen implements Component {
348
356
  const selected = this.getSelectedSetting();
349
357
  const category = this.currentCategory();
350
358
  const selection = this.getSelectionText();
359
+ if (this.editingShortcutItem) {
360
+ const hint = this.pendingShortcutValue ? `Captured ${this.pendingShortcutValue} • Enter save • Esc cancel` : "Press desired key or key combination • Enter save • Esc cancel";
361
+ return `${selection} • ${this.statusText || hint}`;
362
+ }
351
363
  const search = this.searchActive ? `Search: ${this.searchQuery || "type to filter all settings"}` : "";
352
364
  const lead = this.statusText || search;
353
365
  const description = selected?.description ?? category.description;
@@ -356,6 +368,7 @@ class ConfigurationScreen implements Component {
356
368
 
357
369
  private formatValue(item: ConfigurationItem, width: number) {
358
370
  if (width <= 0) return "";
371
+ if (this.editingShortcutItem?.id === item.id) return this.pendingShortcutValue ? this.theme.fg("accent", fitAnsi(this.pendingShortcutValue, width)) : "";
359
372
  const raw = item.rawValue;
360
373
  if (!raw) return this.theme.fg("dim", fitAnsi(item.emptyLabel ?? displayConfigurationValue(item.id, raw), width));
361
374
 
@@ -465,6 +478,11 @@ class ConfigurationScreen implements Component {
465
478
  const item = displayItems[this.getSelectedSettingIndex(displayItems.length)];
466
479
  if (!item) return;
467
480
 
481
+ if (item.id === "MICME_SHORTCUT") {
482
+ this.startShortcutCapture(item);
483
+ return;
484
+ }
485
+
468
486
  if (item.submenu) {
469
487
  this.submenuComponent = item.submenu(item.rawValue, (selectedValue?: string) => {
470
488
  this.submenuComponent = null;
@@ -480,6 +498,50 @@ class ConfigurationScreen implements Component {
480
498
  this.saveSetting(item, nextValue);
481
499
  }
482
500
 
501
+ private startShortcutCapture(item: ConfigurationItem) {
502
+ this.editingShortcutItem = item;
503
+ this.pendingShortcutValue = "";
504
+ this.statusText = "";
505
+ this.requestRender();
506
+ }
507
+
508
+ private handleShortcutCaptureInput(data: string) {
509
+ const item = this.editingShortcutItem;
510
+ if (!item) return;
511
+
512
+ if (matchesKey(data, Key.escape)) {
513
+ this.editingShortcutItem = null;
514
+ this.pendingShortcutValue = "";
515
+ this.statusText = "";
516
+ this.requestRender();
517
+ return;
518
+ }
519
+
520
+ if (matchesKey(data, Key.enter)) {
521
+ if (!this.pendingShortcutValue) {
522
+ this.statusText = "Press a shortcut before confirming";
523
+ this.requestRender();
524
+ return;
525
+ }
526
+ const nextValue = this.pendingShortcutValue;
527
+ this.editingShortcutItem = null;
528
+ this.pendingShortcutValue = "";
529
+ this.saveSetting(item, nextValue);
530
+ return;
531
+ }
532
+
533
+ const captured = getShortcutInput(data);
534
+ if (!captured) {
535
+ this.statusText = "Shortcut input not recognized";
536
+ this.requestRender();
537
+ return;
538
+ }
539
+
540
+ this.pendingShortcutValue = captured;
541
+ this.statusText = "";
542
+ this.requestRender();
543
+ }
544
+
483
545
  private saveSetting(item: ConfigurationItem, nextValue: string) {
484
546
  this.saving = true;
485
547
  this.statusText = `Saving ${item.id}…`;
@@ -603,7 +665,7 @@ export function buildConfigurationItems(
603
665
  const whisperCppBinValues = uniqueStrings([env("MICME_WHISPER_CPP_BIN") ?? "", findExecutable(["whisper-cli"]) ?? "", findExecutable(["whisper-cpp"]) ?? "", "whisper-cli", "whisper-cpp"]);
604
666
  const whisperStreamBinValues = uniqueStrings([env("MICME_WHISPER_STREAM_BIN") ?? "", findExecutable(["whisper-stream"]) ?? "", "whisper-stream"]);
605
667
  const audioFilter = env("MICME_AUDIO_FILTER") ?? "highpass=f=80,lowpass=f=7600";
606
- const macosPrintableShortcut = env("MICME_PRINTABLE_SHORTCUTS") ?? (process.platform === "darwin" ? DEFAULT_MACOS_PRINTABLE_SHORTCUT : "");
668
+ const shortcut = getShortcutSettingValue();
607
669
  const plan = resolveTranscriptionPlan({ transcriptionMode: getTranscriptionMode() });
608
670
  const backendValues = ["whisper.cpp", "python"] as const;
609
671
  const backendLabels = Object.fromEntries(backendValues.map((value) => [value, formatBackendLabel(value)]));
@@ -778,12 +840,22 @@ export function buildConfigurationItems(
778
840
  {
779
841
  id: "MICME_RECORD_SAMPLE_RATE",
780
842
  categoryId: "audio",
781
- label: "Record sample rate",
782
- description: "Raw recording sample rate. 48000 is usually best for macOS devices.",
843
+ label: "Sample rate override",
844
+ description: "Advanced. Leave auto so ffmpeg uses the selected input's native sample rate.",
783
845
  rawValue: env("MICME_RECORD_SAMPLE_RATE") ?? String(DEFAULT_RECORD_SAMPLE_RATE),
784
846
  currentValue: env("MICME_RECORD_SAMPLE_RATE") ?? String(DEFAULT_RECORD_SAMPLE_RATE),
785
- values: ["48000", "44100", "16000"],
786
- displayKind: "number",
847
+ values: ["auto", "48000", "44100", "16000", "96000"],
848
+ displayKind: "text",
849
+ },
850
+ {
851
+ id: "MICME_RECORD_SYNC",
852
+ categoryId: "audio",
853
+ label: "Record timing sync",
854
+ description: "Automatically preserve wall-clock recording duration from ffmpeg timestamps. Keep on unless debugging recorder timing.",
855
+ rawValue: env("MICME_RECORD_SYNC") ?? "1",
856
+ currentValue: env("MICME_RECORD_SYNC") ?? "1",
857
+ values: ["1", "0"],
858
+ displayKind: "boolean",
787
859
  },
788
860
  {
789
861
  id: "MICME_TRANSCRIBE_SAMPLE_RATE",
@@ -795,6 +867,30 @@ export function buildConfigurationItems(
795
867
  values: ["16000", "48000", "44100"],
796
868
  displayKind: "number",
797
869
  },
870
+ {
871
+ id: "MICME_RECORD_METER",
872
+ categoryId: "audio",
873
+ label: "Live meter pipe",
874
+ description: "Stream a second PCM branch from ffmpeg for the waveform meter. Leave off if recordings crackle or sound shortened.",
875
+ rawValue: env("MICME_RECORD_METER") ?? "0",
876
+ currentValue: env("MICME_RECORD_METER") ?? "0",
877
+ values: ["0", "1"],
878
+ displayKind: "boolean",
879
+ },
880
+ ...(process.platform === "darwin"
881
+ ? [
882
+ {
883
+ id: "MICME_AVFOUNDATION_DROP_LATE_FRAMES",
884
+ categoryId: "audio" as const,
885
+ label: "AVF drop late frames",
886
+ description: "macOS only. Keep off to preserve audio timing when devices or virtual routes lag.",
887
+ rawValue: env("MICME_AVFOUNDATION_DROP_LATE_FRAMES") ?? "0",
888
+ currentValue: env("MICME_AVFOUNDATION_DROP_LATE_FRAMES") ?? "0",
889
+ values: ["0", "1"],
890
+ displayKind: "boolean" as const,
891
+ },
892
+ ]
893
+ : []),
798
894
  {
799
895
  id: "MICME_AUDIO_FILTER",
800
896
  categoryId: "audio",
@@ -840,7 +936,7 @@ export function buildConfigurationItems(
840
936
  id: "MICME_KEEP_AUDIO",
841
937
  categoryId: "audio",
842
938
  label: "Keep audio",
843
- description: "Keep raw.wav and clip.wav in /tmp after successful transcription for debugging.",
939
+ description: "Keep raw.wav and clip.wav under ./micme-rec/rec-###/ after successful transcription for debugging.",
844
940
  rawValue: env("MICME_KEEP_AUDIO") ?? "0",
845
941
  currentValue: env("MICME_KEEP_AUDIO") ?? "0",
846
942
  values: ["0", "1"],
@@ -849,21 +945,10 @@ export function buildConfigurationItems(
849
945
  {
850
946
  id: "MICME_SHORTCUT",
851
947
  categoryId: "general",
852
- label: "Terminal shortcut",
853
- description: "Shortcut when your terminal sends real Alt/Ctrl keys. Requires /reload or restart after changing.",
854
- rawValue: env("MICME_SHORTCUT") ?? DEFAULT_SHORTCUT,
855
- currentValue: env("MICME_SHORTCUT") ?? DEFAULT_SHORTCUT,
856
- values: ["alt+m", "ctrl+shift+m", "ctrl+space", "f8", "f9"],
857
- displayKind: "text",
858
- },
859
- {
860
- id: "MICME_PRINTABLE_SHORTCUTS",
861
- categoryId: "general",
862
- label: "macOS printable shortcut",
863
- description: "Toggle-only fallback for terminals where Option+M inserts a character instead of sending Alt+M. Use /reload after changing.",
864
- rawValue: macosPrintableShortcut,
865
- currentValue: displayConfigurationValue("MICME_PRINTABLE_SHORTCUTS", macosPrintableShortcut),
866
- values: [DEFAULT_MACOS_PRINTABLE_SHORTCUT, "µ", ""],
948
+ label: "Shortcut",
949
+ description: "Press Enter, then press the desired key or key combination, and press Enter again to confirm.",
950
+ rawValue: shortcut,
951
+ currentValue: displayConfigurationValue("MICME_SHORTCUT", shortcut),
867
952
  displayKind: "text",
868
953
  emptyLabel: "not set",
869
954
  },
@@ -921,7 +1006,7 @@ export function createModelSelector(candidates: ModelCandidate[], theme: MicmeTh
921
1006
  export async function saveConfigurationValue(ctx: ExtensionContext, id: string, value: string): Promise<Record<string, string>> {
922
1007
  if (!id.startsWith("MICME_")) return {};
923
1008
 
924
- const valuesToWrite = id === "MICME_TRANSCRIPTION_MODE" ? getTranscriptionModeProfile(value === "stream" ? "stream" : "clip") : { [id]: value };
1009
+ const valuesToWrite = getConfigurationValuesToWrite(id, value);
925
1010
  if (id === "MICME_WHISPER_CPP_MODEL" && value) {
926
1011
  await ensureWhisperCppModel(expandConfigPath(value), ctx);
927
1012
  }
@@ -963,13 +1048,19 @@ export function uniqueStrings(values: string[]) {
963
1048
  return output.length > 0 ? output : [""];
964
1049
  }
965
1050
 
1051
+ function getConfigurationValuesToWrite(id: string, value: string) {
1052
+ if (id === "MICME_TRANSCRIPTION_MODE") return getTranscriptionModeProfile(value === "stream" ? "stream" : "clip");
1053
+ if (id === "MICME_SHORTCUT") return { MICME_SHORTCUT: value, MICME_PRINTABLE_SHORTCUTS: undefined };
1054
+ return { [id]: value };
1055
+ }
1056
+
966
1057
  function formatSaveStatus(id: string, value: string) {
967
- const writtenKeys = id === "MICME_TRANSCRIPTION_MODE" ? Object.keys(getTranscriptionModeProfile(value === "stream" ? "stream" : "clip")) : [id];
1058
+ const writtenKeys = Object.keys(getConfigurationValuesToWrite(id, value));
968
1059
  const overriddenKeys = writtenKeys.filter((key) => process.env[key] !== undefined);
969
1060
  const reloadHint = id === "MICME_SHORTCUT" ? "/reload required for shortcut changes" : id === "MICME_PRINTABLE_SHORTCUTS" ? "/reload recommended for printable shortcuts" : "";
970
1061
 
971
1062
  if (id === "MICME_TRANSCRIPTION_MODE" && overriddenKeys.length) return `Shell env still overrides ${overriddenKeys.join(", ")}`;
972
- if (overriddenKeys.includes(id)) return reloadHint ? `Shell env still overrides ${id} • ${reloadHint}` : `Shell env still overrides ${id}`;
1063
+ if (overriddenKeys.length) return reloadHint ? `Shell env still overrides ${overriddenKeys.join(", ")} • ${reloadHint}` : `Shell env still overrides ${overriddenKeys.join(", ")}`;
973
1064
  return reloadHint;
974
1065
  }
975
1066
 
@@ -1015,6 +1106,12 @@ function isTruthyConfigValue(value: string) {
1015
1106
  return /^(1|true|yes|on)$/i.test(value);
1016
1107
  }
1017
1108
 
1109
+ function getShortcutInput(data: string) {
1110
+ const parsed = parseKey(data);
1111
+ if (parsed && parsed !== "enter" && parsed !== "escape" && parsed !== "esc") return parsed;
1112
+ return decodeKittyPrintable(data) ?? getPrintableInput(data);
1113
+ }
1114
+
1018
1115
  function getPrintableInput(data: string) {
1019
1116
  if (!data || data.includes("\x1b")) return "";
1020
1117
  if (matchesKey(data, Key.space)) return " ";