@senad-d/micme 0.1.0 → 0.1.2
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 +4 -1
- package/README.md +48 -29
- package/SECURITY.md +5 -3
- package/micme.example.json +30 -0
- package/micme.schema.json +72 -0
- package/package.json +5 -3
- package/scripts/check-package-contents.mjs +4 -1
- package/scripts/doctor.mjs +61 -29
- package/scripts/publish-npm.mjs +148 -0
- package/src/config.ts +122 -81
- package/src/extension.ts +3 -3
- package/src/settings.ts +44 -22
- package/src/types.ts +1 -1
- package/.env.example +0 -75
package/CHANGELOG.md
CHANGED
|
@@ -4,8 +4,11 @@ All notable changes to Micme will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
## Unreleased
|
|
6
6
|
|
|
7
|
+
- Move normal Micme persistence to the global `~/.pi/agent/micme.json` store; shell environment variables still override saved settings.
|
|
8
|
+
- Update `/micme conf`, `micme-doctor`, docs, and package examples for the new global JSON config path.
|
|
9
|
+
- Document the scoped npm package name, `@senad-d/micme`, in install, diagnostics, update, and uninstall commands.
|
|
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.
|
|
7
11
|
- Keep publication on hold until package name, metadata, security review, validation, and smoke tests are complete.
|
|
8
|
-
- Use the `docs/PUBLISHING.md` checklist for the first npm release.
|
|
9
12
|
|
|
10
13
|
## 0.1.0 - 2026-06-18
|
|
11
14
|
|
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img alt="Micme logo" src="img/micme_logo.
|
|
2
|
+
<img alt="Micme logo" src="img/micme_logo.svg" width="128">
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
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
|
-
<a href="https://www.npmjs.com/package/micme"><img alt="npm" src="https://img.shields.io/npm/v
|
|
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
9
|
</p>
|
|
10
10
|
|
|
@@ -20,9 +20,9 @@ Micme is a pi extension for short coding prompts. It records your microphone wit
|
|
|
20
20
|
- **Local-first:** no telemetry and no cloud STT service by default.
|
|
21
21
|
- **Review-first:** transcripts paste into the editor unless you enable auto-submit.
|
|
22
22
|
- **Pi-native:** install globally, project-locally, from git, or from a source checkout.
|
|
23
|
-
- **Configurable:** use `/micme conf`,
|
|
23
|
+
- **Configurable:** use `/micme conf`, `~/.pi/agent/micme.json`, or shell variables.
|
|
24
24
|
|
|
25
|
-
> **Security:** pi packages run with your full system permissions. Micme can use your microphone, spawn local commands, write `MICME_*` settings to
|
|
25
|
+
> **Security:** pi packages run with your full system permissions. Micme can use your microphone, spawn local commands, write `MICME_*` settings to `~/.pi/agent/micme.json`, and optionally download Whisper model files. Read [`SECURITY.md`](SECURITY.md).
|
|
26
26
|
|
|
27
27
|
## Table of Contents
|
|
28
28
|
|
|
@@ -35,13 +35,16 @@ Micme is a pi extension for short coding prompts. It records your microphone wit
|
|
|
35
35
|
- [Troubleshooting](#troubleshooting)
|
|
36
36
|
- [Diagnostics](#diagnostics)
|
|
37
37
|
- [Update and Uninstall](#update-and-uninstall)
|
|
38
|
+
- [Development](#development)
|
|
39
|
+
- [Publishing](#publishing)
|
|
40
|
+
- [License](#license)
|
|
38
41
|
|
|
39
42
|
---
|
|
40
43
|
|
|
41
44
|
## Quick Start
|
|
42
45
|
|
|
43
46
|
```bash
|
|
44
|
-
pi install npm
|
|
47
|
+
pi install npm:@senad-d/micme
|
|
45
48
|
```
|
|
46
49
|
|
|
47
50
|
Install a local backend. On macOS:
|
|
@@ -76,9 +79,9 @@ Micme is toggle-based. Press-and-hold recording is not used because terminal key
|
|
|
76
79
|
|
|
77
80
|
| Scope | Command | Notes |
|
|
78
81
|
| --- | --- | --- |
|
|
79
|
-
| Global | `pi install npm
|
|
80
|
-
| Project-local | `pi install npm
|
|
81
|
-
| One run | `pi -e npm
|
|
82
|
+
| Global | `pi install npm:@senad-d/micme` | Loads in every trusted pi project. |
|
|
83
|
+
| Project-local | `pi install npm:@senad-d/micme -l` | Writes to `.pi/settings.json` in the current project. |
|
|
84
|
+
| One run | `pi -e npm:@senad-d/micme` | Try without changing settings. |
|
|
82
85
|
| Git | `pi install git:github.com/senad-d/micme@<tag>` | Pin a tag or commit. |
|
|
83
86
|
| Local checkout | `pi -e .` | Develop or test this repository. |
|
|
84
87
|
|
|
@@ -133,26 +136,29 @@ MICME_WHISPER_CPP_MODEL=/path/to/ggml-small.en.bin
|
|
|
133
136
|
|
|
134
137
|
## Configuration
|
|
135
138
|
|
|
136
|
-
Micme reads settings from shell environment variables and from
|
|
139
|
+
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.
|
|
137
140
|
|
|
138
|
-
|
|
141
|
+
The usual setup path is to run:
|
|
139
142
|
|
|
140
|
-
```
|
|
141
|
-
|
|
143
|
+
```text
|
|
144
|
+
/micme conf
|
|
142
145
|
```
|
|
143
146
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
MICME_LANGUAGE
|
|
150
|
-
MICME_AUTO_DOWNLOAD_MODEL
|
|
151
|
-
MICME_DEFAULT_WHISPER_CPP_MODEL
|
|
152
|
-
MICME_AUTO_SUBMIT
|
|
153
|
-
MICME_KEEP_AUDIO
|
|
147
|
+
You can also edit the JSON manually. Minimal `~/.pi/agent/micme.json`:
|
|
148
|
+
|
|
149
|
+
```json
|
|
150
|
+
{
|
|
151
|
+
"$schema": "https://raw.githubusercontent.com/senad-d/micme/main/micme.schema.json",
|
|
152
|
+
"MICME_LANGUAGE": "en",
|
|
153
|
+
"MICME_AUTO_DOWNLOAD_MODEL": "1",
|
|
154
|
+
"MICME_DEFAULT_WHISPER_CPP_MODEL": "small.en",
|
|
155
|
+
"MICME_AUTO_SUBMIT": "0",
|
|
156
|
+
"MICME_KEEP_AUDIO": "0"
|
|
157
|
+
}
|
|
154
158
|
```
|
|
155
159
|
|
|
160
|
+
For temporary one-off overrides, set shell variables when starting pi, for example `MICME_KEEP_AUDIO=1 pi`.
|
|
161
|
+
|
|
156
162
|
Common settings:
|
|
157
163
|
|
|
158
164
|
| Variable | Meaning |
|
|
@@ -166,7 +172,7 @@ Common settings:
|
|
|
166
172
|
| `MICME_KEEP_AUDIO=0` | Delete successful temp audio. Set `1` for debugging. |
|
|
167
173
|
| `MICME_MODEL_DIR=~/.cache/whisper.cpp` | Model cache/discovery directory. |
|
|
168
174
|
|
|
169
|
-
See [
|
|
175
|
+
See [`micme.example.json`](micme.example.json) for the full JSON template.
|
|
170
176
|
|
|
171
177
|
---
|
|
172
178
|
|
|
@@ -222,7 +228,7 @@ MICME_TRANSCRIBE_COMMAND=whisper-cli -m /path/to/model.bin -f {audio} -otxt -of
|
|
|
222
228
|
## Diagnostics
|
|
223
229
|
|
|
224
230
|
```bash
|
|
225
|
-
npx -p micme micme-doctor
|
|
231
|
+
npx -p @senad-d/micme micme-doctor
|
|
226
232
|
```
|
|
227
233
|
|
|
228
234
|
From a source checkout:
|
|
@@ -238,10 +244,10 @@ The doctor checks Node, pi, `ffmpeg`, whisper.cpp, optional `whisper-stream`, mo
|
|
|
238
244
|
## Update and Uninstall
|
|
239
245
|
|
|
240
246
|
```bash
|
|
241
|
-
pi update --extensions
|
|
242
|
-
pi update npm
|
|
243
|
-
pi remove npm
|
|
244
|
-
pi remove npm
|
|
247
|
+
pi update --extensions # update installed pi packages
|
|
248
|
+
pi update npm:@senad-d/micme # update Micme only
|
|
249
|
+
pi remove npm:@senad-d/micme # remove global install
|
|
250
|
+
pi remove npm:@senad-d/micme -l # remove project-local install
|
|
245
251
|
```
|
|
246
252
|
|
|
247
253
|
---
|
|
@@ -251,9 +257,22 @@ pi remove npm:micme -l # remove project-local install
|
|
|
251
257
|
```bash
|
|
252
258
|
npm ci
|
|
253
259
|
npm run validate
|
|
254
|
-
pi -e . --list-models micme-load-test
|
|
255
260
|
```
|
|
256
261
|
|
|
262
|
+
## Publishing
|
|
263
|
+
|
|
264
|
+
Micme publishes to npm as `@senad-d/micme`. You need an npm account with publish access to the `@senad-d` scope.
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
npm login
|
|
268
|
+
npm whoami
|
|
269
|
+
npm run publish:npm
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
The publish script asks for the version number, validates the package, runs `npm version <version>` to update `package.json` and `package-lock.json`, creates the `v<version>` git tag, publishes with `npm publish --access public`, and then offers to push the release commit and tag.
|
|
273
|
+
|
|
274
|
+
Run it only from a clean working tree after updating `CHANGELOG.md`.
|
|
275
|
+
|
|
257
276
|
## License
|
|
258
277
|
|
|
259
278
|
MIT
|
package/SECURITY.md
CHANGED
|
@@ -61,11 +61,13 @@ MICME_AUTO_DOWNLOAD_MODEL=0
|
|
|
61
61
|
|
|
62
62
|
You can also download models manually and set `MICME_WHISPER_CPP_MODEL=/path/to/model.bin`.
|
|
63
63
|
|
|
64
|
-
##
|
|
64
|
+
## Micme config handling
|
|
65
65
|
|
|
66
|
-
Micme reads only `MICME_*` keys from
|
|
66
|
+
Micme reads only `MICME_*` runtime keys from `~/.pi/agent/micme.json`. Shell environment variables override saved JSON values.
|
|
67
67
|
|
|
68
|
-
`/micme conf` writes only `MICME_*` values to
|
|
68
|
+
`/micme conf` writes only `MICME_*` values to `micme.json` and preserves other JSON metadata. Micme uses its own global config store to reduce accidental project influence over microphone and command-hook behavior.
|
|
69
|
+
|
|
70
|
+
Treat `micme.json` as trusted local user configuration. Command hooks stored there, especially `MICME_RECORD_COMMAND` and `MICME_TRANSCRIBE_COMMAND`, execute local shell commands with your user permissions. Avoid placing secrets in custom commands.
|
|
69
71
|
|
|
70
72
|
## Telemetry and retention
|
|
71
73
|
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://raw.githubusercontent.com/senad-d/micme/main/micme.schema.json",
|
|
3
|
+
"MICME_SHORTCUT": "alt+m",
|
|
4
|
+
"MICME_PRINTABLE_SHORTCUTS": "§",
|
|
5
|
+
"MICME_TRANSCRIPTION_MODE": "clip",
|
|
6
|
+
"MICME_AUTO_SUBMIT": "0",
|
|
7
|
+
"MICME_LANGUAGE": "en",
|
|
8
|
+
"MICME_TRANSCRIBE_TIMEOUT_MS": "120000",
|
|
9
|
+
"MICME_AUTO_DOWNLOAD_MODEL": "1",
|
|
10
|
+
"MICME_DEFAULT_WHISPER_CPP_MODEL": "small.en",
|
|
11
|
+
"MICME_MODEL_DIR": "${HOME}/.cache/whisper.cpp",
|
|
12
|
+
"MICME_AUDIO_DEVICE": "0",
|
|
13
|
+
"MICME_RECORD_SAMPLE_RATE": "48000",
|
|
14
|
+
"MICME_TRANSCRIBE_SAMPLE_RATE": "16000",
|
|
15
|
+
"MICME_PROCESS_AUDIO": "1",
|
|
16
|
+
"MICME_AUDIO_FILTER": "highpass=f=80,lowpass=f=7600",
|
|
17
|
+
"MICME_VALIDATE_AUDIO": "1",
|
|
18
|
+
"MICME_KEEP_AUDIO": "0",
|
|
19
|
+
"MICME_METER_GAIN": "1",
|
|
20
|
+
"MICME_STREAM_CAPTURE": "-1",
|
|
21
|
+
"MICME_STREAM_WORDS_PER_CHUNK": "5",
|
|
22
|
+
"MICME_STREAM_STEP_MS": "500",
|
|
23
|
+
"MICME_STREAM_LENGTH_MS": "3000",
|
|
24
|
+
"MICME_STREAM_KEEP_MS": "300",
|
|
25
|
+
"MICME_STREAM_MAX_TOKENS": "32",
|
|
26
|
+
"MICME_STREAM_KEEP_CONTEXT": "1",
|
|
27
|
+
"MICME_STREAM_FINALIZE_WITH_CLIP": "0",
|
|
28
|
+
"MICME_STREAM_VAD_THRESHOLD": "0.35",
|
|
29
|
+
"MICME_STREAM_DIAGNOSTICS": "0"
|
|
30
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://raw.githubusercontent.com/senad-d/micme/main/micme.schema.json",
|
|
4
|
+
"title": "Micme configuration",
|
|
5
|
+
"description": "Machine-level Micme settings. Shell environment variables override saved values.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"$schema": {
|
|
9
|
+
"type": "string"
|
|
10
|
+
},
|
|
11
|
+
"MICME_SHORTCUT": {
|
|
12
|
+
"type": "string",
|
|
13
|
+
"default": "alt+m"
|
|
14
|
+
},
|
|
15
|
+
"MICME_PRINTABLE_SHORTCUTS": {
|
|
16
|
+
"type": "string",
|
|
17
|
+
"default": "§"
|
|
18
|
+
},
|
|
19
|
+
"MICME_TRANSCRIPTION_MODE": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"enum": ["clip", "stream"],
|
|
22
|
+
"default": "clip"
|
|
23
|
+
},
|
|
24
|
+
"MICME_AUTO_SUBMIT": {
|
|
25
|
+
"$ref": "#/$defs/stringFlag"
|
|
26
|
+
},
|
|
27
|
+
"MICME_LANGUAGE": {
|
|
28
|
+
"type": "string",
|
|
29
|
+
"default": "en"
|
|
30
|
+
},
|
|
31
|
+
"MICME_AUTO_DOWNLOAD_MODEL": {
|
|
32
|
+
"$ref": "#/$defs/stringFlag"
|
|
33
|
+
},
|
|
34
|
+
"MICME_DEFAULT_WHISPER_CPP_MODEL": {
|
|
35
|
+
"type": "string",
|
|
36
|
+
"default": "small.en"
|
|
37
|
+
},
|
|
38
|
+
"MICME_MODEL_DIR": {
|
|
39
|
+
"type": "string",
|
|
40
|
+
"default": "${HOME}/.cache/whisper.cpp"
|
|
41
|
+
},
|
|
42
|
+
"MICME_AUDIO_DEVICE": {
|
|
43
|
+
"type": "string",
|
|
44
|
+
"default": "0"
|
|
45
|
+
},
|
|
46
|
+
"MICME_KEEP_AUDIO": {
|
|
47
|
+
"$ref": "#/$defs/stringFlag"
|
|
48
|
+
},
|
|
49
|
+
"MICME_RECORD_COMMAND": {
|
|
50
|
+
"type": "string",
|
|
51
|
+
"description": "Advanced shell command hook. Use only trusted commands."
|
|
52
|
+
},
|
|
53
|
+
"MICME_TRANSCRIBE_COMMAND": {
|
|
54
|
+
"type": "string",
|
|
55
|
+
"description": "Advanced shell command hook. Use only trusted commands."
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"patternProperties": {
|
|
59
|
+
"^MICME_": {
|
|
60
|
+
"type": ["string", "number", "boolean"],
|
|
61
|
+
"description": "Micme runtime setting. Values are read as strings by Micme."
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"additionalProperties": true,
|
|
65
|
+
"$defs": {
|
|
66
|
+
"stringFlag": {
|
|
67
|
+
"type": "string",
|
|
68
|
+
"enum": ["0", "1", "true", "false", "yes", "no", "on", "off"],
|
|
69
|
+
"default": "0"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@senad-d/micme",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Local voice-to-text for pi, optimized for fast Whisper-style backends.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
"LICENSE",
|
|
35
35
|
"SECURITY.md",
|
|
36
36
|
"CHANGELOG.md",
|
|
37
|
-
".
|
|
37
|
+
"micme.example.json",
|
|
38
|
+
"micme.schema.json",
|
|
38
39
|
"img/micme_logo.png",
|
|
39
40
|
"src/**/*.ts",
|
|
40
41
|
"scripts/*.mjs",
|
|
@@ -43,11 +44,12 @@
|
|
|
43
44
|
],
|
|
44
45
|
"scripts": {
|
|
45
46
|
"doctor": "node scripts/doctor.mjs",
|
|
46
|
-
"check": "node --check scripts/doctor.mjs && node --check scripts/check-package-contents.mjs",
|
|
47
|
+
"check": "node --check scripts/doctor.mjs && node --check scripts/check-package-contents.mjs && node --check scripts/publish-npm.mjs",
|
|
47
48
|
"typecheck": "tsc --noEmit",
|
|
48
49
|
"pack:dry-run": "npm pack --dry-run --json",
|
|
49
50
|
"check:pack": "node scripts/check-package-contents.mjs",
|
|
50
51
|
"validate": "npm run typecheck && npm run check && npm run check:pack",
|
|
52
|
+
"publish:npm": "node scripts/publish-npm.mjs",
|
|
51
53
|
"prepublishOnly": "npm run validate"
|
|
52
54
|
},
|
|
53
55
|
"pi": {
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { execFileSync } from "node:child_process";
|
|
3
3
|
|
|
4
|
+
const hiddenEnvironmentFilePattern = new RegExp(`^\\.${"env"}(?:$|\\.)`);
|
|
5
|
+
|
|
4
6
|
const forbiddenChecks = [
|
|
5
7
|
{
|
|
6
8
|
label: "environment files",
|
|
7
|
-
test: (path) =>
|
|
9
|
+
test: (path) => hiddenEnvironmentFilePattern.test(path),
|
|
8
10
|
},
|
|
9
11
|
{ label: "project-local pi state", test: (path) => path.startsWith(".pi/") },
|
|
12
|
+
{ label: "generated Micme config", test: (path) => path === "micme.json" || path.endsWith("/micme.json") },
|
|
10
13
|
{ label: "node_modules", test: (path) => path.startsWith("node_modules/") || path.includes("/node_modules/") },
|
|
11
14
|
{ label: "planning specs", test: (path) => path.startsWith("specs/") },
|
|
12
15
|
{ label: "Micme cache", test: (path) => path.startsWith(".micme/") || path.includes("/.micme/") },
|
package/scripts/doctor.mjs
CHANGED
|
@@ -1,34 +1,55 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
3
|
import { access } from "node:fs/promises";
|
|
4
|
-
import { delimiter, join } from "node:path";
|
|
4
|
+
import { delimiter, join, resolve } from "node:path";
|
|
5
|
+
import { homedir } from "node:os";
|
|
5
6
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
6
7
|
|
|
7
8
|
const isWin = process.platform === "win32";
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
function
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
values
|
|
9
|
+
const micmeConfig = loadMicmeConfig();
|
|
10
|
+
|
|
11
|
+
function getMicmeConfigPath() {
|
|
12
|
+
const agentDir = process.env.PI_CODING_AGENT_DIR ? resolve(process.env.PI_CODING_AGENT_DIR) : join(homedir(), ".pi", "agent");
|
|
13
|
+
return join(agentDir, "micme.json");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function loadMicmeConfig() {
|
|
17
|
+
const path = getMicmeConfigPath();
|
|
18
|
+
if (!existsSync(path)) return { path, found: false, values: {} };
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
const parsed = JSON.parse(readFileSync(path, "utf8").replace(/^\uFEFF/, ""));
|
|
22
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
23
|
+
return { path, found: true, values: {}, error: "top-level value must be a JSON object" };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const values = {};
|
|
27
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
28
|
+
if (!key.startsWith("MICME_")) continue;
|
|
29
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") values[key] = String(value);
|
|
30
|
+
}
|
|
31
|
+
return { path, found: true, values };
|
|
32
|
+
} catch (error) {
|
|
33
|
+
return { path, found: true, values: {}, error: error instanceof Error ? error.message : String(error) };
|
|
26
34
|
}
|
|
27
|
-
return { path, values };
|
|
28
35
|
}
|
|
29
36
|
|
|
30
37
|
function env(name) {
|
|
31
|
-
return process.env[name] ??
|
|
38
|
+
return process.env[name] ?? micmeConfig.values[name];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function expandConfigValue(value) {
|
|
42
|
+
const home = process.env.HOME || homedir();
|
|
43
|
+
const withHome = value.startsWith("~/") && home ? `${home}${value.slice(1)}` : value;
|
|
44
|
+
return withHome.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Za-z_][A-Za-z0-9_]*)/g, (_m, braced, bare) => {
|
|
45
|
+
const key = braced || bare || "";
|
|
46
|
+
return process.env[key] ?? micmeConfig.values[key] ?? "";
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function envPath(name) {
|
|
51
|
+
const value = env(name);
|
|
52
|
+
return value ? expandConfigValue(value) : undefined;
|
|
32
53
|
}
|
|
33
54
|
|
|
34
55
|
function which(names) {
|
|
@@ -46,7 +67,7 @@ function which(names) {
|
|
|
46
67
|
}
|
|
47
68
|
|
|
48
69
|
function resolveExecutable(value) {
|
|
49
|
-
const expanded = value
|
|
70
|
+
const expanded = expandConfigValue(value);
|
|
50
71
|
if (/[\\/]/.test(expanded)) return expanded;
|
|
51
72
|
return which([expanded]) || expanded;
|
|
52
73
|
}
|
|
@@ -70,12 +91,23 @@ function summarizeConfiguredCommand(value) {
|
|
|
70
91
|
return `configured (${trimmed.length} chars${placeholderText}; full value redacted)`;
|
|
71
92
|
}
|
|
72
93
|
|
|
94
|
+
function printConfigDiagnostics() {
|
|
95
|
+
if (micmeConfig.error) warn("micme.json invalid", `${micmeConfig.path}: ${micmeConfig.error}`);
|
|
96
|
+
else if (micmeConfig.found) ok("micme.json loaded", `${micmeConfig.path} (${Object.keys(micmeConfig.values).length} MICME_* key(s))`);
|
|
97
|
+
else info("micme.json", `not found; /micme conf will create ${micmeConfig.path}`);
|
|
98
|
+
|
|
99
|
+
const micmeEnvKeys = Object.keys(process.env).filter((key) => key.startsWith("MICME_")).sort((a, b) => a.localeCompare(b));
|
|
100
|
+
const overrides = micmeEnvKeys.filter((key) => micmeConfig.values[key] !== undefined);
|
|
101
|
+
const shellOnly = micmeEnvKeys.filter((key) => micmeConfig.values[key] === undefined);
|
|
102
|
+
if (overrides.length) warn("shell env overrides micme.json", overrides.join(", "));
|
|
103
|
+
if (shellOnly.length) info("MICME_* shell values", shellOnly.join(", "));
|
|
104
|
+
}
|
|
105
|
+
|
|
73
106
|
async function main() {
|
|
74
107
|
console.log("Micme doctor\n");
|
|
75
108
|
info("platform", `${process.platform} ${process.arch}`);
|
|
76
109
|
info("node", process.version);
|
|
77
|
-
|
|
78
|
-
else info(".env", "not found");
|
|
110
|
+
printConfigDiagnostics();
|
|
79
111
|
|
|
80
112
|
const pi = which(["pi"]);
|
|
81
113
|
if (pi) ok("pi CLI", pi);
|
|
@@ -87,15 +119,15 @@ async function main() {
|
|
|
87
119
|
|
|
88
120
|
const configuredWhisperCpp = env("MICME_WHISPER_CPP_BIN");
|
|
89
121
|
const whisperCpp = configuredWhisperCpp ? resolveExecutable(configuredWhisperCpp) : which(["whisper-cli", "whisper-cpp"]);
|
|
90
|
-
const whisperCppModel =
|
|
122
|
+
const whisperCppModel = envPath("MICME_WHISPER_CPP_MODEL");
|
|
91
123
|
if (whisperCpp && existsSync(whisperCpp)) ok("whisper.cpp binary", whisperCpp);
|
|
92
|
-
else if (configuredWhisperCpp) warn("MICME_WHISPER_CPP_BIN is set but not found", configuredWhisperCpp);
|
|
124
|
+
else if (configuredWhisperCpp) warn("MICME_WHISPER_CPP_BIN is set but not found", resolveExecutable(configuredWhisperCpp));
|
|
93
125
|
else warn("whisper.cpp binary missing", "recommended backend for portable local transcription");
|
|
94
126
|
|
|
95
127
|
const configuredWhisperStream = env("MICME_WHISPER_STREAM_BIN");
|
|
96
128
|
const whisperStream = configuredWhisperStream ? resolveExecutable(configuredWhisperStream) : which(["whisper-stream"]);
|
|
97
129
|
if (whisperStream && existsSync(whisperStream)) ok("whisper-stream binary", whisperStream);
|
|
98
|
-
else if (configuredWhisperStream) warn("MICME_WHISPER_STREAM_BIN is set but not found", configuredWhisperStream);
|
|
130
|
+
else if (configuredWhisperStream) warn("MICME_WHISPER_STREAM_BIN is set but not found", resolveExecutable(configuredWhisperStream));
|
|
99
131
|
else info("whisper-stream binary", "not installed; only needed for MICME_TRANSCRIPTION_MODE=stream");
|
|
100
132
|
|
|
101
133
|
if (whisperCppModel) {
|
|
@@ -108,7 +140,7 @@ async function main() {
|
|
|
108
140
|
}
|
|
109
141
|
} else {
|
|
110
142
|
const defaultModel = env("MICME_DEFAULT_WHISPER_CPP_MODEL") || "small.en";
|
|
111
|
-
const modelDir = env("MICME_MODEL_DIR") ||
|
|
143
|
+
const modelDir = expandConfigValue(env("MICME_MODEL_DIR") || join(homedir(), ".cache", "whisper.cpp"));
|
|
112
144
|
info("MICME_WHISPER_CPP_MODEL", `not set; Micme defaults to ${modelDir}/ggml-${defaultModel}.bin and auto-downloads when needed`);
|
|
113
145
|
}
|
|
114
146
|
|
|
@@ -140,7 +172,7 @@ async function main() {
|
|
|
140
172
|
if (macbookMic) {
|
|
141
173
|
const current = env("MICME_AUDIO_DEVICE") || "0";
|
|
142
174
|
if (current !== macbookMic[1]) {
|
|
143
|
-
warn("MacBook Pro microphone is not the configured default", `try:
|
|
175
|
+
warn("MacBook Pro microphone is not the configured default", `try: MICME_AUDIO_DEVICE=${macbookMic[1]} pi`);
|
|
144
176
|
}
|
|
145
177
|
}
|
|
146
178
|
console.log("\nSet MICME_AUDIO_DEVICE to the numeric audio device id if device 0 is wrong.");
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
4
|
+
import { createInterface } from "node:readline/promises";
|
|
5
|
+
import { stdin as input, stdout as output } from "node:process";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
|
|
8
|
+
const rootUrl = new URL("../", import.meta.url);
|
|
9
|
+
const root = fileURLToPath(rootUrl);
|
|
10
|
+
const packageJsonUrl = new URL("package.json", rootUrl);
|
|
11
|
+
const pkg = JSON.parse(readFileSync(packageJsonUrl, "utf8"));
|
|
12
|
+
const semverPattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
13
|
+
|
|
14
|
+
function capture(command, args, options = {}) {
|
|
15
|
+
return execFileSync(command, args, {
|
|
16
|
+
cwd: root,
|
|
17
|
+
encoding: "utf8",
|
|
18
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
19
|
+
...options,
|
|
20
|
+
}).trim();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function run(command, args) {
|
|
24
|
+
console.log(`\n$ ${command} ${args.join(" ")}`);
|
|
25
|
+
const result = spawnSync(command, args, {
|
|
26
|
+
cwd: root,
|
|
27
|
+
stdio: "inherit",
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (result.status !== 0) {
|
|
31
|
+
process.exit(result.status ?? 1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function fail(message) {
|
|
36
|
+
console.error(`\n${message}`);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function commandSucceeds(command, args) {
|
|
41
|
+
const result = spawnSync(command, args, {
|
|
42
|
+
cwd: root,
|
|
43
|
+
stdio: "ignore",
|
|
44
|
+
});
|
|
45
|
+
return result.status === 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function ensureCleanGitTree() {
|
|
49
|
+
const status = capture("git", ["status", "--porcelain"]);
|
|
50
|
+
if (status) {
|
|
51
|
+
fail("Working tree is not clean. Commit or stash changes before publishing.");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function ensureNpmLogin() {
|
|
56
|
+
const result = spawnSync("npm", ["whoami"], {
|
|
57
|
+
cwd: root,
|
|
58
|
+
encoding: "utf8",
|
|
59
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (result.status !== 0) {
|
|
63
|
+
fail("npm login is required before publishing. Run `npm login`, then retry.");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
console.log(`npm user: ${result.stdout.trim()}`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function main() {
|
|
70
|
+
console.log(`Publishing ${pkg.name}`);
|
|
71
|
+
console.log(`Current version: ${pkg.version}`);
|
|
72
|
+
|
|
73
|
+
ensureCleanGitTree();
|
|
74
|
+
ensureNpmLogin();
|
|
75
|
+
|
|
76
|
+
const rl = createInterface({ input, output });
|
|
77
|
+
const version = (await rl.question("Version to publish (for example 0.1.1): ")).trim();
|
|
78
|
+
|
|
79
|
+
if (!semverPattern.test(version)) {
|
|
80
|
+
rl.close();
|
|
81
|
+
fail("Enter a valid semver version, for example 0.1.1 or 1.0.0-beta.1.");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (version === pkg.version) {
|
|
85
|
+
rl.close();
|
|
86
|
+
fail(`package.json is already at version ${version}. Choose a new version.`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const gitTag = `v${version}`;
|
|
90
|
+
if (commandSucceeds("git", ["rev-parse", "--verify", `refs/tags/${gitTag}`])) {
|
|
91
|
+
rl.close();
|
|
92
|
+
fail(`Git tag ${gitTag} already exists.`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const publishedVersion = spawnSync("npm", ["view", `${pkg.name}@${version}`, "version"], {
|
|
96
|
+
cwd: root,
|
|
97
|
+
encoding: "utf8",
|
|
98
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
if (publishedVersion.status === 0 && publishedVersion.stdout.trim()) {
|
|
102
|
+
rl.close();
|
|
103
|
+
fail(`${pkg.name}@${version} already exists on npm.`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const publishArgs = ["publish"];
|
|
107
|
+
if (pkg.name.startsWith("@")) {
|
|
108
|
+
publishArgs.push("--access", "public");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
console.log("\nThis will:");
|
|
112
|
+
console.log(`- run npm validation`);
|
|
113
|
+
console.log(`- run npm version ${version} to update package.json/package-lock.json`);
|
|
114
|
+
console.log(`- create a release commit and git tag ${gitTag}`);
|
|
115
|
+
console.log(`- run npm ${publishArgs.join(" ")}`);
|
|
116
|
+
|
|
117
|
+
const confirm = (await rl.question("Continue? [y/N] ")).trim().toLowerCase();
|
|
118
|
+
if (confirm !== "y" && confirm !== "yes") {
|
|
119
|
+
rl.close();
|
|
120
|
+
fail("Publish cancelled.");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
rl.close();
|
|
124
|
+
|
|
125
|
+
run("npm", ["run", "validate"]);
|
|
126
|
+
run("npm", ["version", version, "-m", "chore(release): v%s"]);
|
|
127
|
+
run("npm", publishArgs);
|
|
128
|
+
|
|
129
|
+
const pushRl = createInterface({ input, output });
|
|
130
|
+
const push = (await pushRl.question(`Push current branch and ${gitTag} to origin? [y/N] `)).trim().toLowerCase();
|
|
131
|
+
pushRl.close();
|
|
132
|
+
|
|
133
|
+
if (push === "y" || push === "yes") {
|
|
134
|
+
const branch = capture("git", ["branch", "--show-current"]);
|
|
135
|
+
if (!branch) {
|
|
136
|
+
fail(`Release was published, but git is in detached HEAD. Push ${gitTag} manually.`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
run("git", ["push", "origin", branch]);
|
|
140
|
+
run("git", ["push", "origin", gitTag]);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
console.log(`\nPublished ${pkg.name}@${version}.`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
main().catch((error) => {
|
|
147
|
+
fail(error instanceof Error ? error.message : String(error));
|
|
148
|
+
});
|
package/src/config.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
-
import { writeFile } from "node:fs/promises";
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
2
|
+
import { mkdir, rename, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { dirname, join, resolve } from "node:path";
|
|
6
|
+
import type { MicmeConfigState, TranscriptionMode } from "./types.ts";
|
|
5
7
|
import {
|
|
6
8
|
DEFAULT_MACOS_PRINTABLE_SHORTCUT,
|
|
7
9
|
DEFAULT_RECORD_SAMPLE_RATE,
|
|
@@ -22,11 +24,77 @@ import {
|
|
|
22
24
|
STREAM_PROFILE_WORDS_PER_CHUNK,
|
|
23
25
|
} from "./constants.ts";
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
const MICME_CONFIG_FILE = "micme.json";
|
|
28
|
+
const MICME_SCHEMA_URL = "https://raw.githubusercontent.com/senad-d/micme/main/micme.schema.json";
|
|
29
|
+
const requireModule = createRequire(import.meta.url);
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
type JsonObject = Record<string, unknown>;
|
|
32
|
+
|
|
33
|
+
let piAgentDirChecked = false;
|
|
34
|
+
let piAgentDir: string | undefined;
|
|
35
|
+
let micmeConfigState: MicmeConfigState = loadMicmeJson();
|
|
36
|
+
|
|
37
|
+
export function getMicmeAgentDir() {
|
|
38
|
+
const configured = process.env.PI_CODING_AGENT_DIR?.trim();
|
|
39
|
+
if (configured) return resolve(configured);
|
|
40
|
+
|
|
41
|
+
const exported = getPiExportedAgentDir();
|
|
42
|
+
if (exported) return resolve(exported);
|
|
43
|
+
|
|
44
|
+
return join(homedir(), ".pi", "agent");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function getMicmeConfigPath() {
|
|
48
|
+
return join(getMicmeAgentDir(), MICME_CONFIG_FILE);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function reloadMicmeConfig() {
|
|
52
|
+
micmeConfigState = loadMicmeJson();
|
|
53
|
+
return micmeConfigState;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function loadMicmeJson(): MicmeConfigState {
|
|
57
|
+
const path = getMicmeConfigPath();
|
|
58
|
+
if (!existsSync(path)) return { path, values: {} };
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const parsed: unknown = JSON.parse(readFileSync(path, "utf8").replace(/^\uFEFF/, ""));
|
|
62
|
+
if (!isJsonObject(parsed)) {
|
|
63
|
+
return { path, values: {}, error: "top-level value must be a JSON object" };
|
|
64
|
+
}
|
|
65
|
+
return { path, values: extractMicmeValues(parsed) };
|
|
66
|
+
} catch (error) {
|
|
67
|
+
return { path, values: {}, error: error instanceof Error ? error.message : String(error) };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function writeMicmeConfigValue(key: string, value: string) {
|
|
72
|
+
await writeMicmeConfigValues({ [key]: value });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function writeMicmeConfigValues(values: Record<string, string>) {
|
|
76
|
+
for (const key of Object.keys(values)) {
|
|
77
|
+
if (!key.startsWith("MICME_")) throw new Error(`Micme config keys must start with MICME_: ${key}`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const configPath = getMicmeConfigPath();
|
|
81
|
+
const configDir = dirname(configPath);
|
|
82
|
+
const existing = readMicmeJsonObjectForWrite(configPath);
|
|
83
|
+
const next: JsonObject = { ...existing };
|
|
84
|
+
|
|
85
|
+
for (const [key, value] of Object.entries(values)) next[key] = String(value);
|
|
86
|
+
|
|
87
|
+
await mkdir(configDir, { recursive: true });
|
|
88
|
+
const tempPath = join(configDir, `.micme.${process.pid}.${Date.now()}.${Math.random().toString(16).slice(2)}.tmp`);
|
|
89
|
+
try {
|
|
90
|
+
await writeFile(tempPath, `${JSON.stringify(next, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
|
|
91
|
+
await rename(tempPath, configPath);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
await rm(tempPath, { force: true }).catch(() => undefined);
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
reloadMicmeConfig();
|
|
30
98
|
}
|
|
31
99
|
|
|
32
100
|
export function getTranscriptionModeProfile(mode: TranscriptionMode): Record<string, string> {
|
|
@@ -57,90 +125,20 @@ export function getTranscriptionModeProfile(mode: TranscriptionMode): Record<str
|
|
|
57
125
|
};
|
|
58
126
|
}
|
|
59
127
|
|
|
60
|
-
export async function writeDotEnvValue(cwd: string, key: string, value: string) {
|
|
61
|
-
const path = join(cwd, ".env");
|
|
62
|
-
const lines = existsSync(path) ? readFileSync(path, "utf8").split(/\r?\n/) : [];
|
|
63
|
-
const matcher = new RegExp(`^\\s*(?:export\\s+)?${escapeRegExp(key)}\\s*=`);
|
|
64
|
-
let found = false;
|
|
65
|
-
const nextLines = lines.map((line) => {
|
|
66
|
-
if (!matcher.test(line)) return line;
|
|
67
|
-
found = true;
|
|
68
|
-
return `${key}=${formatDotEnvValue(value)}`;
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
if (!found) {
|
|
72
|
-
if (nextLines.length > 0 && nextLines[nextLines.length - 1] !== "") nextLines.push("");
|
|
73
|
-
nextLines.push(`${key}=${formatDotEnvValue(value)}`);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
await writeFile(path, `${nextLines.join("\n").replace(/\n*$/, "")}\n`, "utf8");
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function formatDotEnvValue(value: string) {
|
|
80
|
-
if (value === "") return "";
|
|
81
|
-
if (/^[A-Za-z0-9_./:@%+=,-]+$/.test(value)) return value;
|
|
82
|
-
return JSON.stringify(value);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export function escapeRegExp(value: string) {
|
|
86
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
87
|
-
}
|
|
88
|
-
|
|
89
128
|
export function expandConfigPath(value: string) {
|
|
90
|
-
return expandEnvReferences(value,
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function loadDotEnv(cwd: string): DotEnvState {
|
|
94
|
-
const path = join(cwd, ".env");
|
|
95
|
-
if (!existsSync(path)) return { path: "", values: {} };
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
const values: Record<string, string> = {};
|
|
99
|
-
const content = readFileSync(path, "utf8").replace(/^\uFEFF/, "");
|
|
100
|
-
for (const line of content.split(/\r?\n/)) {
|
|
101
|
-
const parsed = parseDotEnvLine(line, values);
|
|
102
|
-
if (!parsed) continue;
|
|
103
|
-
values[parsed.key] = parsed.value;
|
|
104
|
-
}
|
|
105
|
-
return { path, values };
|
|
106
|
-
} catch (error) {
|
|
107
|
-
return { path, values: {}, error: error instanceof Error ? error.message : String(error) };
|
|
108
|
-
}
|
|
129
|
+
return expandEnvReferences(value, micmeConfigState.values);
|
|
109
130
|
}
|
|
110
131
|
|
|
111
|
-
export function
|
|
112
|
-
const trimmed = line.trim();
|
|
113
|
-
if (!trimmed || trimmed.startsWith("#")) return undefined;
|
|
114
|
-
|
|
115
|
-
const match = trimmed.match(/^(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/);
|
|
116
|
-
if (!match) return undefined;
|
|
117
|
-
|
|
118
|
-
const key = match[1] ?? "";
|
|
119
|
-
if (!key.startsWith("MICME_")) return undefined;
|
|
120
|
-
|
|
121
|
-
let value = match[2] ?? "";
|
|
122
|
-
if (value.startsWith('"') && value.endsWith('"')) {
|
|
123
|
-
value = value.slice(1, -1).replace(/\\n/g, "\n").replace(/\\r/g, "\r").replace(/\\t/g, "\t").replace(/\\"/g, '"').replace(/\\\\/g, "\\");
|
|
124
|
-
} else if (value.startsWith("'") && value.endsWith("'")) {
|
|
125
|
-
value = value.slice(1, -1);
|
|
126
|
-
} else {
|
|
127
|
-
value = value.replace(/\s+#.*$/, "").trim();
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
value = expandEnvReferences(value, previousValues);
|
|
131
|
-
return { key, value };
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export function expandEnvReferences(value: string, previousValues: Record<string, string>) {
|
|
132
|
+
export function expandEnvReferences(value: string, configValues: Record<string, string>) {
|
|
135
133
|
const withHome = value.startsWith("~/") && process.env.HOME ? `${process.env.HOME}${value.slice(1)}` : value;
|
|
136
134
|
return withHome.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Za-z_][A-Za-z0-9_]*)/g, (_match, braced: string | undefined, bare: string | undefined) => {
|
|
137
135
|
const key = braced ?? bare ?? "";
|
|
138
|
-
return
|
|
136
|
+
return process.env[key] ?? configValues[key] ?? "";
|
|
139
137
|
});
|
|
140
138
|
}
|
|
141
139
|
|
|
142
140
|
export function env(name: string) {
|
|
143
|
-
return process.env[name] ??
|
|
141
|
+
return process.env[name] ?? micmeConfigState.values[name];
|
|
144
142
|
}
|
|
145
143
|
|
|
146
144
|
export function getShortcut() {
|
|
@@ -254,3 +252,46 @@ export function getMeterGain() {
|
|
|
254
252
|
export function envFlag(name: string) {
|
|
255
253
|
return /^(1|true|yes|on)$/i.test(env(name) || "");
|
|
256
254
|
}
|
|
255
|
+
|
|
256
|
+
function readMicmeJsonObjectForWrite(configPath: string): JsonObject {
|
|
257
|
+
if (!existsSync(configPath)) return { $schema: MICME_SCHEMA_URL };
|
|
258
|
+
|
|
259
|
+
try {
|
|
260
|
+
const parsed: unknown = JSON.parse(readFileSync(configPath, "utf8").replace(/^\uFEFF/, ""));
|
|
261
|
+
if (!isJsonObject(parsed)) throw new Error("top-level value must be a JSON object");
|
|
262
|
+
return parsed;
|
|
263
|
+
} catch (error) {
|
|
264
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
265
|
+
throw new Error(`Cannot save Micme config: ${configPath} is invalid JSON (${message}). Fix or remove it first.`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function extractMicmeValues(json: JsonObject) {
|
|
270
|
+
const values: Record<string, string> = {};
|
|
271
|
+
for (const [key, value] of Object.entries(json)) {
|
|
272
|
+
if (!key.startsWith("MICME_")) continue;
|
|
273
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") values[key] = String(value);
|
|
274
|
+
}
|
|
275
|
+
return values;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function isJsonObject(value: unknown): value is JsonObject {
|
|
279
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function getPiExportedAgentDir() {
|
|
283
|
+
if (piAgentDirChecked) return piAgentDir;
|
|
284
|
+
piAgentDirChecked = true;
|
|
285
|
+
|
|
286
|
+
try {
|
|
287
|
+
const piModule = requireModule("@earendil-works/pi-coding-agent") as { getAgentDir?: unknown };
|
|
288
|
+
if (typeof piModule.getAgentDir === "function") {
|
|
289
|
+
const value = piModule.getAgentDir();
|
|
290
|
+
if (typeof value === "string" && value.trim()) piAgentDir = value;
|
|
291
|
+
}
|
|
292
|
+
} catch {
|
|
293
|
+
// Some pi runtimes may not expose this helper or may be ESM-only. Falling back is safe.
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return piAgentDir;
|
|
297
|
+
}
|
package/src/extension.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
getShortcut,
|
|
11
11
|
getStreamFinalizeWithClip,
|
|
12
12
|
getTranscriptionMode,
|
|
13
|
-
|
|
13
|
+
reloadMicmeConfig,
|
|
14
14
|
} from "./config.ts";
|
|
15
15
|
import { buildRecorderCommand, listAudioDevices, prepareAudioForTranscription, validateRecordedAudio } from "./audio.ts";
|
|
16
16
|
import { installMicmeEditorFallback, type MicmeEditorInputHandlers } from "./editor.ts";
|
|
@@ -51,7 +51,7 @@ let lastAudioDir = "";
|
|
|
51
51
|
let lastShortcutInputAt = 0;
|
|
52
52
|
|
|
53
53
|
export default function micmeExtension(pi: ExtensionAPI) {
|
|
54
|
-
|
|
54
|
+
reloadMicmeConfig();
|
|
55
55
|
|
|
56
56
|
async function toggle(ctx: ExtensionContext) {
|
|
57
57
|
if (recording) {
|
|
@@ -113,7 +113,7 @@ export default function micmeExtension(pi: ExtensionAPI) {
|
|
|
113
113
|
});
|
|
114
114
|
|
|
115
115
|
pi.on("session_start", async (_event, ctx) => {
|
|
116
|
-
|
|
116
|
+
reloadMicmeConfig();
|
|
117
117
|
installMicmeEditorFallback(ctx, createMicmeEditorHandlers(ctx, toggle));
|
|
118
118
|
});
|
|
119
119
|
|
package/src/settings.ts
CHANGED
|
@@ -12,7 +12,8 @@ import {
|
|
|
12
12
|
truncateToWidth,
|
|
13
13
|
visibleWidth,
|
|
14
14
|
} from "@earendil-works/pi-tui";
|
|
15
|
-
import {
|
|
15
|
+
import { homedir } from "node:os";
|
|
16
|
+
import { basename } from "node:path";
|
|
16
17
|
import {
|
|
17
18
|
DEFAULT_MACOS_PRINTABLE_SHORTCUT,
|
|
18
19
|
DEFAULT_RECORD_SAMPLE_RATE,
|
|
@@ -26,10 +27,11 @@ import {
|
|
|
26
27
|
import {
|
|
27
28
|
env,
|
|
28
29
|
expandConfigPath,
|
|
30
|
+
getMicmeConfigPath,
|
|
29
31
|
getTranscriptionMode,
|
|
30
32
|
getTranscriptionModeProfile,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
reloadMicmeConfig,
|
|
34
|
+
writeMicmeConfigValues,
|
|
33
35
|
} from "./config.ts";
|
|
34
36
|
import { discoverAudioDevices } from "./audio.ts";
|
|
35
37
|
import { discoverWhisperCppModels, ensureWhisperCppModel, getDefaultWhisperCppModelPath } from "./models.ts";
|
|
@@ -74,14 +76,17 @@ export async function showConfiguration(ctx: ExtensionContext) {
|
|
|
74
76
|
return;
|
|
75
77
|
}
|
|
76
78
|
|
|
77
|
-
|
|
79
|
+
const configState = reloadMicmeConfig();
|
|
80
|
+
if (configState.error) {
|
|
81
|
+
ctx.ui.notify(`Micme config is invalid at ${configState.path}: ${configState.error}. Fix it before saving settings.`, "warning");
|
|
82
|
+
}
|
|
78
83
|
const audioDevices = await discoverAudioDevices();
|
|
79
84
|
const modelCandidates = discoverWhisperCppModels(ctx.cwd);
|
|
80
85
|
|
|
81
86
|
await ctx.ui.custom<void>((tui, theme, _keybindings, done) => {
|
|
82
87
|
const items = buildConfigurationItems(modelCandidates, audioDevices, theme);
|
|
83
88
|
return new ConfigurationScreen({
|
|
84
|
-
|
|
89
|
+
configPath: configState.path,
|
|
85
90
|
items,
|
|
86
91
|
theme,
|
|
87
92
|
onDone: done,
|
|
@@ -93,7 +98,7 @@ export async function showConfiguration(ctx: ExtensionContext) {
|
|
|
93
98
|
}
|
|
94
99
|
|
|
95
100
|
class ConfigurationScreen implements Component {
|
|
96
|
-
private readonly
|
|
101
|
+
private readonly configPath: string;
|
|
97
102
|
private readonly items: ConfigurationItem[];
|
|
98
103
|
private readonly theme: MicmeTheme;
|
|
99
104
|
private readonly onDone: () => void;
|
|
@@ -111,7 +116,7 @@ class ConfigurationScreen implements Component {
|
|
|
111
116
|
private statusText = "";
|
|
112
117
|
|
|
113
118
|
constructor(options: {
|
|
114
|
-
|
|
119
|
+
configPath: string;
|
|
115
120
|
items: ConfigurationItem[];
|
|
116
121
|
theme: MicmeTheme;
|
|
117
122
|
onDone: () => void;
|
|
@@ -119,7 +124,7 @@ class ConfigurationScreen implements Component {
|
|
|
119
124
|
onSave: (id: string, newValue: string) => Promise<Record<string, string>>;
|
|
120
125
|
requestRender: () => void;
|
|
121
126
|
}) {
|
|
122
|
-
this.
|
|
127
|
+
this.configPath = options.configPath;
|
|
123
128
|
this.items = options.items;
|
|
124
129
|
this.theme = options.theme;
|
|
125
130
|
this.onDone = options.onDone;
|
|
@@ -201,7 +206,7 @@ class ConfigurationScreen implements Component {
|
|
|
201
206
|
const lines: string[] = [];
|
|
202
207
|
|
|
203
208
|
lines.push(this.renderTitleBorder(width, this.currentHeaderLabel()));
|
|
204
|
-
lines.push(this.renderFullLine(width,
|
|
209
|
+
lines.push(this.renderFullLine(width, this.renderConfigSourceText(width)));
|
|
205
210
|
lines.push(this.renderFullLine(width, "↑↓ move Tab pane Enter edit / search Esc back q quit"));
|
|
206
211
|
lines.push(this.renderPaneSeparator(width, leftWidth, rightWidth, "top"));
|
|
207
212
|
|
|
@@ -226,7 +231,7 @@ class ConfigurationScreen implements Component {
|
|
|
226
231
|
const lines: string[] = [];
|
|
227
232
|
|
|
228
233
|
lines.push(this.renderTitleBorder(width, this.currentHeaderLabel()));
|
|
229
|
-
lines.push(this.renderFullLine(width,
|
|
234
|
+
lines.push(this.renderFullLine(width, this.renderConfigSourceText(width)));
|
|
230
235
|
lines.push(this.renderFullLine(width, showCategories ? "↑↓ category Enter open / search q quit" : "↑↓ move Enter edit Esc categories / search q quit"));
|
|
231
236
|
lines.push(this.colorBorder(`├${"─".repeat(innerWidth)}┤`, width));
|
|
232
237
|
for (const line of bodyLines) lines.push(this.renderFullLine(width, line));
|
|
@@ -284,6 +289,15 @@ class ConfigurationScreen implements Component {
|
|
|
284
289
|
return this.theme.fg("accent", fitAnsi(line, width, ""));
|
|
285
290
|
}
|
|
286
291
|
|
|
292
|
+
private renderConfigSourceText(width: number) {
|
|
293
|
+
const innerWidth = Math.max(0, width - 2);
|
|
294
|
+
const prefix = "writes ";
|
|
295
|
+
const suffix = " • shell env overrides Micme settings";
|
|
296
|
+
const pathWidth = Math.max(0, innerWidth - visibleWidth(prefix) - visibleWidth(suffix));
|
|
297
|
+
const path = pathWidth > 0 ? fitPath(this.configPath, pathWidth) : "micme.json";
|
|
298
|
+
return `${prefix}${path}${suffix}`;
|
|
299
|
+
}
|
|
300
|
+
|
|
287
301
|
private renderCategoryPaneLines(width: number) {
|
|
288
302
|
return CONFIGURATION_CATEGORIES.map((category, index) => {
|
|
289
303
|
const selected = index === this.categoryIndex;
|
|
@@ -843,20 +857,20 @@ export async function saveConfigurationValue(ctx: ExtensionContext, id: string,
|
|
|
843
857
|
await ensureWhisperCppModel(expandConfigPath(value), ctx);
|
|
844
858
|
}
|
|
845
859
|
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
}
|
|
860
|
+
await writeMicmeConfigValues(valuesToWrite);
|
|
861
|
+
reloadMicmeConfig();
|
|
849
862
|
|
|
850
|
-
|
|
863
|
+
const configLabel = formatConfigPathForMessage(getMicmeConfigPath());
|
|
851
864
|
const overriddenKeys = Object.keys(valuesToWrite).filter((key) => process.env[key] !== undefined);
|
|
852
865
|
if (id === "MICME_TRANSCRIPTION_MODE") {
|
|
853
866
|
const mode = valuesToWrite.MICME_TRANSCRIPTION_MODE === "stream" ? "stream" : "clip";
|
|
854
867
|
const detail = mode === "stream" ? "low-latency stream profile" : "stable clip profile";
|
|
855
|
-
const
|
|
856
|
-
ctx.ui.notify(`Saved ${mode} mode and applied ${detail}${
|
|
868
|
+
const sourceSuffix = overriddenKeys.length ? `; shell env still overrides ${overriddenKeys.join(", ")}` : ` (${configLabel})`;
|
|
869
|
+
ctx.ui.notify(`Saved ${mode} mode and applied ${detail}${sourceSuffix}.`, overriddenKeys.length ? "warning" : "info");
|
|
857
870
|
} else {
|
|
858
|
-
const
|
|
859
|
-
|
|
871
|
+
const overrideSuffix = overriddenKeys.includes(id) ? `, but shell env still overrides ${id}` : ` (${configLabel})`;
|
|
872
|
+
const reloadSuffix = id === "MICME_SHORTCUT" ? " • /reload required" : id === "MICME_PRINTABLE_SHORTCUTS" ? " • /reload recommended" : "";
|
|
873
|
+
ctx.ui.notify(`Saved ${id}=${displayConfigurationValue(id, value)}${overrideSuffix}${reloadSuffix}`, overriddenKeys.includes(id) ? "warning" : "info");
|
|
860
874
|
}
|
|
861
875
|
|
|
862
876
|
const effectiveValues: Record<string, string> = {};
|
|
@@ -885,16 +899,24 @@ export function uniqueStrings(values: string[]) {
|
|
|
885
899
|
function formatSaveStatus(id: string, value: string) {
|
|
886
900
|
const writtenKeys = id === "MICME_TRANSCRIPTION_MODE" ? Object.keys(getTranscriptionModeProfile(value === "stream" ? "stream" : "clip")) : [id];
|
|
887
901
|
const overriddenKeys = writtenKeys.filter((key) => process.env[key] !== undefined);
|
|
902
|
+
const configLabel = formatConfigPathForMessage(getMicmeConfigPath());
|
|
888
903
|
if (id === "MICME_TRANSCRIPTION_MODE") {
|
|
889
904
|
const mode = value === "stream" ? "stream" : "clip";
|
|
890
905
|
const detail = mode === "stream" ? "low-latency stream profile" : "stable clip profile";
|
|
891
|
-
const
|
|
892
|
-
return `Saved MICME_TRANSCRIPTION_MODE=${mode} and applied ${detail}${
|
|
906
|
+
const sourceSuffix = overriddenKeys.length ? ` • shell env still overrides ${overriddenKeys.join(", ")}` : ` • ${configLabel}`;
|
|
907
|
+
return `Saved MICME_TRANSCRIPTION_MODE=${mode} and applied ${detail}${sourceSuffix}`;
|
|
893
908
|
}
|
|
894
909
|
|
|
895
|
-
const
|
|
910
|
+
const sourceSuffix = overriddenKeys.includes(id) ? `, but shell env still overrides ${id}` : ` (${configLabel})`;
|
|
896
911
|
const reloadSuffix = id === "MICME_SHORTCUT" ? " • /reload required" : id === "MICME_PRINTABLE_SHORTCUTS" ? " • /reload recommended" : "";
|
|
897
|
-
return `Saved ${id}=${displayConfigurationValue(id, value)}
|
|
912
|
+
return `Saved ${id}=${displayConfigurationValue(id, value)}${sourceSuffix}${reloadSuffix}`;
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
function formatConfigPathForMessage(path: string) {
|
|
916
|
+
const home = homedir();
|
|
917
|
+
if (home && path === home) return "~";
|
|
918
|
+
if (home && path.startsWith(`${home}/`)) return `~/${path.slice(home.length + 1)}`;
|
|
919
|
+
return path;
|
|
898
920
|
}
|
|
899
921
|
|
|
900
922
|
function fitAnsi(text: string, width: number, ellipsis = "…") {
|
package/src/types.ts
CHANGED
package/.env.example
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
# Micme safe example configuration
|
|
2
|
-
# Copy this file to .env, then run /micme conf inside pi to adjust it for your machine.
|
|
3
|
-
# Shell environment variables override values from .env.
|
|
4
|
-
|
|
5
|
-
# Shortcut used by the extension. macOS displays alt as Option.
|
|
6
|
-
# Some terminals insert a printable character for Option+M instead of sending Alt+M.
|
|
7
|
-
MICME_SHORTCUT=alt+m
|
|
8
|
-
MICME_PRINTABLE_SHORTCUTS=§
|
|
9
|
-
|
|
10
|
-
# Transcription behavior.
|
|
11
|
-
# clip = stable default: record first, then transcribe when stopped.
|
|
12
|
-
# stream = experimental live preview using whisper-stream.
|
|
13
|
-
MICME_TRANSCRIPTION_MODE=clip
|
|
14
|
-
MICME_AUTO_SUBMIT=0
|
|
15
|
-
MICME_LANGUAGE=en
|
|
16
|
-
MICME_TRANSCRIBE_TIMEOUT_MS=120000
|
|
17
|
-
|
|
18
|
-
# Privacy/debugging.
|
|
19
|
-
# By default Micme removes temp audio after successful transcription.
|
|
20
|
-
MICME_KEEP_AUDIO=0
|
|
21
|
-
MICME_VALIDATE_AUDIO=1
|
|
22
|
-
MICME_MIN_MAX_VOLUME_DB=-50
|
|
23
|
-
|
|
24
|
-
# Recorder selection.
|
|
25
|
-
# Leave these unset until /micme devices shows the right value for your OS.
|
|
26
|
-
# macOS avfoundation examples:
|
|
27
|
-
# MICME_AUDIO_DEVICE=0
|
|
28
|
-
# MICME_AVFOUNDATION_INPUT=:0
|
|
29
|
-
# Linux PulseAudio example:
|
|
30
|
-
# MICME_PULSE_SOURCE=default
|
|
31
|
-
# Windows DirectShow example:
|
|
32
|
-
# MICME_DSHOW_AUDIO_DEVICE=default
|
|
33
|
-
|
|
34
|
-
# Recording/preprocessing. Micme records a raw WAV, then prepares a 16 kHz WAV for Whisper.
|
|
35
|
-
MICME_RECORD_SAMPLE_RATE=48000
|
|
36
|
-
MICME_TRANSCRIBE_SAMPLE_RATE=16000
|
|
37
|
-
MICME_PROCESS_AUDIO=1
|
|
38
|
-
MICME_AUDIO_FILTER=highpass=f=80,lowpass=f=7600
|
|
39
|
-
|
|
40
|
-
# Recording meter tuning. Defaults should be fine for most microphones.
|
|
41
|
-
MICME_METER_GAIN=1
|
|
42
|
-
MICME_METER_FLOOR_DB=55
|
|
43
|
-
MICME_METER_RANGE_DB=35
|
|
44
|
-
|
|
45
|
-
# Recommended backend: whisper.cpp. Install it separately, then either leave the binary unset
|
|
46
|
-
# so Micme searches PATH, or set MICME_WHISPER_CPP_BIN to an explicit local path.
|
|
47
|
-
MICME_AUTO_DOWNLOAD_MODEL=1
|
|
48
|
-
MICME_DEFAULT_WHISPER_CPP_MODEL=small.en
|
|
49
|
-
MICME_MODEL_DIR=$HOME/.cache/whisper.cpp
|
|
50
|
-
# MICME_WHISPER_CPP_BIN=whisper-cli
|
|
51
|
-
# MICME_WHISPER_STREAM_BIN=whisper-stream
|
|
52
|
-
# MICME_WHISPER_CPP_MODEL=$HOME/.cache/whisper.cpp/ggml-small.en.bin
|
|
53
|
-
|
|
54
|
-
# Python openai-whisper fallback. Used only when whisper.cpp is not configured/found.
|
|
55
|
-
MICME_WHISPER_MODEL=base.en
|
|
56
|
-
MICME_WHISPER_DEVICE=cpu
|
|
57
|
-
MICME_WHISPER_FP16=False
|
|
58
|
-
|
|
59
|
-
# Experimental streaming profile. /micme conf can apply a low-latency profile automatically.
|
|
60
|
-
MICME_STREAM_CAPTURE=-1
|
|
61
|
-
MICME_STREAM_WORDS_PER_CHUNK=5
|
|
62
|
-
MICME_STREAM_STEP_MS=500
|
|
63
|
-
MICME_STREAM_LENGTH_MS=3000
|
|
64
|
-
MICME_STREAM_KEEP_MS=300
|
|
65
|
-
MICME_STREAM_MAX_TOKENS=32
|
|
66
|
-
MICME_STREAM_KEEP_CONTEXT=1
|
|
67
|
-
MICME_STREAM_FINALIZE_WITH_CLIP=0
|
|
68
|
-
MICME_STREAM_VAD_THRESHOLD=0.35
|
|
69
|
-
MICME_STREAM_DIAGNOSTICS=0
|
|
70
|
-
|
|
71
|
-
# Advanced custom hooks. Placeholders are shell-quoted unless the Raw suffix is used:
|
|
72
|
-
# {audio}, {audioRaw}, {tempDir}, {tempDirRaw}, {transcript}, {transcriptRaw}
|
|
73
|
-
# Raw placeholders bypass shell quoting; use them only when you fully control the command.
|
|
74
|
-
# MICME_RECORD_COMMAND=ffmpeg -hide_banner -loglevel error -f avfoundation -i :0 -ac 1 -ar 16000 -y {audio}
|
|
75
|
-
# MICME_TRANSCRIBE_COMMAND=whisper-cli -m /path/to/model.bin -f {audio} -otxt -of {tempDirRaw}/out -nt -np && cat {tempDirRaw}/out.txt
|