@senad-d/micme 0.3.8 → 0.3.9
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 +5 -0
- package/README.md +3 -1
- package/package.json +4 -4
- package/src/editor.ts +2 -1
- package/src/processes.ts +83 -36
- package/src/settings.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -25,6 +25,11 @@ All notable changes to Micme will be documented in this file.
|
|
|
25
25
|
- Align `micme-doctor` executable/model checks with runtime validation and translation-capable model fallback behavior.
|
|
26
26
|
- Let `MICME_RECORD_COMMAND` use the same `{audio}`, `{tempDir}`, and `{transcript}` placeholders as custom transcription commands.
|
|
27
27
|
|
|
28
|
+
## [0.3.9] - 2026-11-24
|
|
29
|
+
|
|
30
|
+
- Windows recording and transcription hooks now launch the system command interpreter rather than a same-named executable in the project directory.
|
|
31
|
+
- Micme reports failed signal escalation instead of treating a still-running recorder as stopped or letting a second signal error go unhandled.
|
|
32
|
+
|
|
28
33
|
## 0.1.0 - 2026-06-18
|
|
29
34
|
|
|
30
35
|
Initial publication-readiness candidate.
|
package/README.md
CHANGED
|
@@ -118,7 +118,9 @@ pi install /absolute/path/to/micme
|
|
|
118
118
|
|
|
119
119
|
## Pi Compatibility
|
|
120
120
|
|
|
121
|
-
Micme
|
|
121
|
+
Micme declares `*` as the peer dependency range for both `@earendil-works/pi-coding-agent` and `@earendil-works/pi-tui`. These published ranges are not a compatibility guarantee. CI pins both packages to `1.6.0` and tests only that version: it typechecks every production TypeScript file against their declarations and loads the default extension through Pi's jiti-based loader.
|
|
122
|
+
|
|
123
|
+
Before adopting another Pi release, review both published peer ranges and update the development pins and the contract test together.
|
|
122
124
|
|
|
123
125
|
---
|
|
124
126
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@senad-d/micme",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Local voice dictation for Pi coding prompts. Press Alt+M, speak, review, send.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -81,13 +81,13 @@
|
|
|
81
81
|
"@earendil-works/pi-tui": "*"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
|
-
"@earendil-works/pi-coding-agent": "
|
|
85
|
-
"@earendil-works/pi-tui": "
|
|
84
|
+
"@earendil-works/pi-coding-agent": "1.6.0",
|
|
85
|
+
"@earendil-works/pi-tui": "1.6.0",
|
|
86
86
|
"@eslint/js": "^10.0.1",
|
|
87
87
|
"@types/node": "^26.0.0",
|
|
88
88
|
"eslint": "^10.6.0",
|
|
89
89
|
"globals": "^17.7.0",
|
|
90
|
-
"typescript": "
|
|
90
|
+
"typescript": "6.0.3",
|
|
91
91
|
"typescript-eslint": "^8.62.1"
|
|
92
92
|
}
|
|
93
93
|
}
|
package/src/editor.ts
CHANGED
|
@@ -63,7 +63,8 @@ class WrappedMicmeEditor extends CustomEditor {
|
|
|
63
63
|
|
|
64
64
|
override render(width: number): string[] {
|
|
65
65
|
this.syncBaseEditor();
|
|
66
|
-
|
|
66
|
+
// Pi components may reuse readonly render output; CustomEditor promises a mutable array.
|
|
67
|
+
return [...this.base.render(width)];
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
override invalidate(): void {
|
package/src/processes.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
1
|
+
import { spawn, type ChildProcess } from "node:child_process";
|
|
2
2
|
import { accessSync, constants as fsConstants, statSync } from "node:fs";
|
|
3
3
|
import { rm, stat } from "node:fs/promises";
|
|
4
|
-
import { delimiter, join } from "node:path";
|
|
4
|
+
import { delimiter, join, win32 } from "node:path";
|
|
5
5
|
import { MAX_CAPTURED_OUTPUT_CHARS, MIN_AUDIO_BYTES, RECORDER_STOP_GRACE_MS } from "./constants.ts";
|
|
6
6
|
import { pcm16BufferLevel } from "./audio-level.ts";
|
|
7
7
|
import { sanitizeTerminalOutput, stripTerminalControlSequences } from "./terminal-text.ts";
|
|
8
8
|
import type { CommandSpec, ExitResult, Recording, RunResult } from "./types.ts";
|
|
9
9
|
|
|
10
|
+
const TERMINATE_GRACE_MS = 1_000;
|
|
11
|
+
const FAILED_KILL_CLOSE_GRACE_MS = 1_000;
|
|
12
|
+
|
|
10
13
|
export function spawnRecording(command: CommandSpec, audioPath: string, tempDir: string): Recording {
|
|
11
14
|
const child = spawn(command.command, command.args, {
|
|
12
15
|
stdio: [command.stopInput ? "pipe" : "ignore", "pipe", "pipe"],
|
|
@@ -36,13 +39,9 @@ export function spawnRecording(command: CommandSpec, audioPath: string, tempDir:
|
|
|
36
39
|
});
|
|
37
40
|
|
|
38
41
|
const exitPromise = new Promise<ExitResult>((resolve) => {
|
|
39
|
-
child
|
|
40
|
-
settled = true;
|
|
41
|
-
resolve({ code: null, signal: null, error });
|
|
42
|
-
});
|
|
43
|
-
child.once("close", (code, signal) => {
|
|
42
|
+
observeProcessExit(child, (exit) => {
|
|
44
43
|
settled = true;
|
|
45
|
-
resolve(
|
|
44
|
+
resolve(exit);
|
|
46
45
|
});
|
|
47
46
|
});
|
|
48
47
|
|
|
@@ -80,23 +79,56 @@ async function stopProcessOnce(active: Recording) {
|
|
|
80
79
|
}
|
|
81
80
|
if (!exit) {
|
|
82
81
|
sendStopSignal(active, "SIGTERM");
|
|
83
|
-
exit = await raceWithTimeout(active.exitPromise,
|
|
84
|
-
}
|
|
85
|
-
if (!exit) {
|
|
86
|
-
sendStopSignal(active, "SIGKILL");
|
|
87
|
-
exit = await active.exitPromise;
|
|
82
|
+
exit = await raceWithTimeout(active.exitPromise, TERMINATE_GRACE_MS);
|
|
88
83
|
}
|
|
89
|
-
return exit;
|
|
84
|
+
if (exit) return exit;
|
|
85
|
+
|
|
86
|
+
const failure = sendStopSignal(active, "SIGKILL");
|
|
87
|
+
if (!failure) return active.exitPromise;
|
|
88
|
+
// A failed kill can race with a real exit. Bound the stop attempt, not the exit promise.
|
|
89
|
+
exit = await raceWithTimeout(active.exitPromise, FAILED_KILL_CLOSE_GRACE_MS);
|
|
90
|
+
if (exit) return exit;
|
|
91
|
+
throw failure;
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
function sendStopSignal(active: Recording, signal: NodeJS.Signals) {
|
|
95
|
+
const failure = sendProcessSignal(active.process, signal);
|
|
96
|
+
if (failure) return failure;
|
|
97
|
+
active.stopSignals ??= new Set();
|
|
98
|
+
active.stopSignals.add(signal);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function observeProcessExit(child: ChildProcess, settle: (exit: ExitResult) => void) {
|
|
102
|
+
let launchFailed = false;
|
|
103
|
+
const onError = (error: Error) => {
|
|
104
|
+
// Node assigns the PID before emitting 'spawn', so even an immediate signal can fail after launch.
|
|
105
|
+
if (child.pid !== undefined || launchFailed) return;
|
|
106
|
+
launchFailed = true;
|
|
107
|
+
settle({ code: null, signal: null, error });
|
|
108
|
+
};
|
|
109
|
+
child.on("error", onError);
|
|
110
|
+
child.once("close", (code, signal) => {
|
|
111
|
+
child.off("error", onError);
|
|
112
|
+
if (!launchFailed) settle({ code, signal });
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function sendProcessSignal(child: ChildProcess, signal: NodeJS.Signals) {
|
|
117
|
+
let cause: unknown;
|
|
118
|
+
const captureError = (error: Error) => {
|
|
119
|
+
cause = error;
|
|
120
|
+
};
|
|
121
|
+
// ChildProcess.kill() can emit an error synchronously or throw instead.
|
|
122
|
+
child.on("error", captureError);
|
|
93
123
|
try {
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
124
|
+
if (child.kill(signal) && cause === undefined) return;
|
|
125
|
+
} catch (error) {
|
|
126
|
+
cause = error;
|
|
127
|
+
} finally {
|
|
128
|
+
child.off("error", captureError);
|
|
99
129
|
}
|
|
130
|
+
const reason = cause instanceof Error ? formatProcessOutput(appendCapped("", cause.message)) : "";
|
|
131
|
+
return new Error(`Micme could not send ${signal}${reason ? ` (${reason})` : ""}; the child process may still be running.`, { cause });
|
|
100
132
|
}
|
|
101
133
|
|
|
102
134
|
export function sendStopInput(active: Recording) {
|
|
@@ -129,7 +161,12 @@ export function runShell(command: string, timeoutMs: number, options: RunProcess
|
|
|
129
161
|
|
|
130
162
|
export function shellCommand(command: string): CommandSpec {
|
|
131
163
|
if (process.platform === "win32") {
|
|
132
|
-
|
|
164
|
+
// Use the host's Windows installation directory, not ComSpec or executable lookup.
|
|
165
|
+
const systemRoot = process.env.SystemRoot;
|
|
166
|
+
if (!systemRoot || !/^[a-z]:[\\/]/i.test(systemRoot)) {
|
|
167
|
+
throw new Error("Micme cannot locate the Windows system shell: SystemRoot must be a drive-qualified absolute path.");
|
|
168
|
+
}
|
|
169
|
+
return { command: win32.join(systemRoot, "System32", "cmd.exe"), args: ["/d", "/s", "/c", command], display: command };
|
|
133
170
|
}
|
|
134
171
|
return { command: "sh", args: ["-lc", command], display: command };
|
|
135
172
|
}
|
|
@@ -150,24 +187,40 @@ export function runProcess(command: string, args: string[], timeoutMs: number, o
|
|
|
150
187
|
let stderr = "";
|
|
151
188
|
let timedOut = false;
|
|
152
189
|
let cancelled = false;
|
|
153
|
-
let
|
|
190
|
+
let finished = false;
|
|
191
|
+
let killAttempted = false;
|
|
154
192
|
let abortTimer: ReturnType<typeof setTimeout> | undefined;
|
|
193
|
+
let failedKillTimer: ReturnType<typeof setTimeout> | undefined;
|
|
155
194
|
|
|
156
195
|
const timer = setTimeout(() => {
|
|
157
196
|
timedOut = true;
|
|
158
|
-
|
|
197
|
+
forceStop();
|
|
159
198
|
}, timeoutMs);
|
|
160
199
|
const abort = () => {
|
|
161
|
-
if (
|
|
200
|
+
if (finished || cancelled) return;
|
|
162
201
|
cancelled = true;
|
|
163
|
-
|
|
164
|
-
abortTimer = setTimeout(
|
|
202
|
+
if (killAttempted) return;
|
|
203
|
+
abortTimer = setTimeout(forceStop, TERMINATE_GRACE_MS);
|
|
204
|
+
sendProcessSignal(child, "SIGTERM");
|
|
165
205
|
};
|
|
166
206
|
const finish = () => {
|
|
207
|
+
finished = true;
|
|
167
208
|
clearTimeout(timer);
|
|
168
|
-
|
|
209
|
+
clearTimeout(abortTimer);
|
|
210
|
+
clearTimeout(failedKillTimer);
|
|
169
211
|
options.signal?.removeEventListener("abort", abort);
|
|
170
212
|
};
|
|
213
|
+
const forceStop = () => {
|
|
214
|
+
if (finished || killAttempted) return;
|
|
215
|
+
killAttempted = true;
|
|
216
|
+
clearTimeout(abortTimer);
|
|
217
|
+
const failure = sendProcessSignal(child, "SIGKILL");
|
|
218
|
+
if (!failure || finished) return;
|
|
219
|
+
failedKillTimer = setTimeout(() => {
|
|
220
|
+
finish();
|
|
221
|
+
reject(failure);
|
|
222
|
+
}, FAILED_KILL_CLOSE_GRACE_MS);
|
|
223
|
+
};
|
|
171
224
|
options.signal?.addEventListener("abort", abort, { once: true });
|
|
172
225
|
|
|
173
226
|
child.stdout?.setEncoding("utf8");
|
|
@@ -178,17 +231,11 @@ export function runProcess(command: string, args: string[], timeoutMs: number, o
|
|
|
178
231
|
child.stderr?.on("data", (chunk: string) => {
|
|
179
232
|
stderr = appendCapped(stderr, chunk);
|
|
180
233
|
});
|
|
181
|
-
child
|
|
182
|
-
if (
|
|
183
|
-
settled = true;
|
|
184
|
-
finish();
|
|
185
|
-
reject(error);
|
|
186
|
-
});
|
|
187
|
-
child.once("close", (code, signal) => {
|
|
188
|
-
if (settled) return;
|
|
189
|
-
settled = true;
|
|
234
|
+
observeProcessExit(child, ({ code, signal, error }) => {
|
|
235
|
+
if (finished) return;
|
|
190
236
|
finish();
|
|
191
|
-
|
|
237
|
+
if (error) reject(error);
|
|
238
|
+
else resolve({ code, signal, stdout, stderr, timedOut, ...(cancelled ? { cancelled: true } : {}) });
|
|
192
239
|
});
|
|
193
240
|
if (options.signal?.aborted) abort();
|
|
194
241
|
});
|
package/src/settings.ts
CHANGED
|
@@ -269,7 +269,7 @@ class ConfigurationScreen implements Component {
|
|
|
269
269
|
this.requestRender();
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
-
render(width: number): string[] {
|
|
272
|
+
render(width: number): readonly string[] {
|
|
273
273
|
this.refreshDerivedItems();
|
|
274
274
|
if (this.submenuComponent) return this.submenuComponent.render(width);
|
|
275
275
|
if (width < TWO_PANE_MIN_WIDTH) return this.renderNarrow(width);
|