@illuminis/comprism 2.13.1 → 2.14.1

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.
@@ -147,15 +147,22 @@ function shippedFile(name, packagePath) {
147
147
  */
148
148
  function relaunchThroughProxy() {
149
149
  const proxy = process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy;
150
- if (!proxy || process.env.NODE_USE_ENV_PROXY)
150
+ // Node 20 has a WebSocket but keeps it switched off (voice and the live
151
+ // browser line need it); Node 22 has it on. Start once more with it on.
152
+ const [major = 0, minor = 0] = process.versions.node.split(".").map(Number);
153
+ const needsSocket = !isStandalone() && typeof globalThis.WebSocket === "undefined"
154
+ && !process.env.COMPRISM_SOCKET_RELAUNCHED && (major === 20 && minor >= 10);
155
+ const needsProxy = Boolean(proxy) && !process.env.NODE_USE_ENV_PROXY;
156
+ if (!needsProxy && !needsSocket)
151
157
  return false;
152
158
  // eslint-disable-next-line @typescript-eslint/no-require-imports
153
159
  const { spawnSync } = require("child_process");
154
160
  // Node 22 calls its proxy support experimental and says so on every start;
155
161
  // that one notice is not the person's concern.
156
- const [cmd, argv] = selfLaunch(process.argv.slice(2), ["--disable-warning=UNDICI-EHPA"]);
162
+ const flags = [...(needsSocket ? ["--experimental-websocket", "--disable-warning=ExperimentalWarning"] : []), ...(needsProxy ? ["--disable-warning=UNDICI-EHPA"] : [])];
163
+ const [cmd, argv] = selfLaunch(process.argv.slice(2), flags);
157
164
  const r = spawnSync(cmd, argv, {
158
- stdio: "inherit", env: { ...process.env, NODE_USE_ENV_PROXY: "1", ...(isStandalone() ? { NODE_NO_WARNINGS: "1" } : {}) },
165
+ stdio: "inherit", env: { ...process.env, COMPRISM_SOCKET_RELAUNCHED: "1", ...(needsProxy ? { NODE_USE_ENV_PROXY: "1" } : {}), ...(isStandalone() ? { NODE_NO_WARNINGS: "1" } : {}) },
159
166
  });
160
167
  process.exitCode = r.status ?? (r.signal === "SIGINT" ? 130 : 1);
161
168
  return true;
@@ -67,14 +67,22 @@ const node_child_process_1 = require("node:child_process");
67
67
  const fs = __importStar(require("node:fs"));
68
68
  const os = __importStar(require("node:os"));
69
69
  const path = __importStar(require("node:path"));
70
- /** Is this on the PATH at all. */
71
- function present(command) {
70
+ /** Where this program is: on the PATH, or in Homebrew's folders. An editor
71
+ * opened from the Dock has no Homebrew on its PATH, and sox or ffmpeg there
72
+ * would otherwise look missing. */
73
+ function locate(command) {
72
74
  try {
73
- return (0, node_child_process_1.spawnSync)('which', [command], { stdio: 'ignore' }).status === 0;
75
+ const found = (0, node_child_process_1.spawnSync)('which', [command], { encoding: 'utf8' });
76
+ if (found.status === 0 && found.stdout.trim())
77
+ return found.stdout.trim();
74
78
  }
75
- catch {
76
- return false;
79
+ catch { /* no which */ }
80
+ for (const dir of ['/opt/homebrew/bin', '/usr/local/bin']) {
81
+ const at = path.join(dir, command);
82
+ if (fs.existsSync(at))
83
+ return at;
77
84
  }
85
+ return null;
78
86
  }
79
87
  /**
80
88
  * Sixteen kilohertz, one channel, everywhere.
@@ -112,7 +120,15 @@ const RECORDERS = [
112
120
  function builtInReader() {
113
121
  if (process.platform !== 'darwin')
114
122
  return null;
115
- for (const at of [path.join(__dirname, '..', '..', 'native', 'dictate'), path.join(__dirname, '..', 'native', 'dictate')]) {
123
+ for (const at of [
124
+ // Unbundled, run from its own compiled location (the CLI): two levels up
125
+ // to the build's out/ folder, where native/ sits beside machine/.
126
+ path.join(__dirname, '..', '..', 'native', 'dictate'),
127
+ path.join(__dirname, '..', 'native', 'dictate'),
128
+ // Bundled into one file (the VS Code extension's dist/line.js): native/
129
+ // is copied beside the bundle itself, in the same directory.
130
+ path.join(__dirname, 'native', 'dictate'),
131
+ ]) {
116
132
  if (fs.existsSync(at))
117
133
  return at;
118
134
  }
@@ -120,7 +136,12 @@ function builtInReader() {
120
136
  }
121
137
  /** The first recording tool this machine has, or null. */
122
138
  function recorder() {
123
- return RECORDERS.find((r) => present(r.command)) ?? null;
139
+ for (const r of RECORDERS) {
140
+ const at = locate(r.command);
141
+ if (at)
142
+ return { ...r, command: at };
143
+ }
144
+ return null;
124
145
  }
125
146
  /**
126
147
  * What to tell somebody who has no recording tool, or null when they do.
@@ -145,13 +166,36 @@ function missing() {
145
166
  * headed off with `missing` so the person gets a sentence rather than an error.
146
167
  */
147
168
  function start() {
169
+ // A recording tool on this computer first, as it always was; the reader in
170
+ // the package when there is none, so a person installs nothing to speak.
148
171
  const tool = recorder();
149
- if (!tool)
172
+ const reader = tool ? null : builtInReader();
173
+ if (!reader && !tool)
150
174
  throw new Error(missing() ?? 'No recording tool.');
151
175
  const file = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'comprism-voice-')), 'said.wav');
152
- const child = (0, node_child_process_1.spawn)(tool.command, tool.args(file), {
153
- stdio: ['ignore', 'ignore', 'ignore'],
154
- });
176
+ let child;
177
+ if (reader) {
178
+ // The reader writes bare samples; the file gets the WAV header the other
179
+ // tools write, with its lengths filled in when the recording ends.
180
+ fs.writeFileSync(file, wavHeader(0));
181
+ child = (0, node_child_process_1.spawn)(reader, ['--raw', RATE], { stdio: ['pipe', 'pipe', 'ignore'] });
182
+ child.stdout?.on('data', (chunk) => { try {
183
+ fs.appendFileSync(file, chunk);
184
+ }
185
+ catch { /* discarded */ } });
186
+ child.once('close', () => {
187
+ try {
188
+ const size = fs.statSync(file).size;
189
+ const fd = fs.openSync(file, 'r+');
190
+ fs.writeSync(fd, wavHeader(size - 44), 0, 44, 0);
191
+ fs.closeSync(fd);
192
+ }
193
+ catch { /* discarded before it finished */ }
194
+ });
195
+ }
196
+ else {
197
+ child = (0, node_child_process_1.spawn)(tool.command, tool.args(file), { stdio: ['ignore', 'ignore', 'ignore'] });
198
+ }
155
199
  let stopped = null;
156
200
  // The recorder never outlives the session. Closing the window or ending the
157
201
  // process while it listens would otherwise leave a microphone recording to a
@@ -214,7 +258,26 @@ function start() {
214
258
  });
215
259
  return stopped;
216
260
  };
217
- return { file, by: tool.name, stop };
261
+ return { file, by: reader ? 'built in microphone reader' : tool.name, stop };
262
+ }
263
+ /** A 44 byte WAV header for 16 bit, one channel samples at RATE. */
264
+ function wavHeader(dataBytes) {
265
+ const rate = Number(RATE);
266
+ const h = Buffer.alloc(44);
267
+ h.write('RIFF', 0, 'ascii');
268
+ h.writeUInt32LE(36 + dataBytes, 4);
269
+ h.write('WAVE', 8, 'ascii');
270
+ h.write('fmt ', 12, 'ascii');
271
+ h.writeUInt32LE(16, 16);
272
+ h.writeUInt16LE(1, 20);
273
+ h.writeUInt16LE(1, 22);
274
+ h.writeUInt32LE(rate, 24);
275
+ h.writeUInt32LE(rate * 2, 28);
276
+ h.writeUInt16LE(2, 32);
277
+ h.writeUInt16LE(16, 34);
278
+ h.write('data', 36, 'ascii');
279
+ h.writeUInt32LE(dataBytes, 40);
280
+ return h;
218
281
  }
219
282
  /** Delete the recording and the folder holding it. Always, and immediately. */
220
283
  function discard(file) {
@@ -3,4 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BUILD_COMMIT = exports.HOME_SERVER = void 0;
4
4
  // Written by the build. Do not edit.
5
5
  exports.HOME_SERVER = "https://completionprism.illuminis.ai";
6
- exports.BUILD_COMMIT = "2f96096926ba24baf245131ed9bc35439c145eb7";
6
+ exports.BUILD_COMMIT = "74a91e52c86cecaad97fa9e1e0f3d0bef189b131";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@illuminis/comprism",
3
- "version": "2.13.1",
3
+ "version": "2.14.1",
4
4
  "description": "CompletionPrism in your terminal. A thin shell: what you type goes to CompletionPrism's front door, and what it answers comes back.",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,