@illuminis/comprism 2.16.0 → 2.17.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/out/build/machine/executor/documents.js +1 -1
- package/out/build/machine/executor/files.js +24 -14
- package/out/build/machine/executor/notebook.js +1 -1
- package/out/build/machine/executor/paths.js +36 -1
- package/out/build/machine/line/index.js +17 -2
- package/out/build/machine/voice/record.js +105 -13
- package/out/server.generated.js +1 -1
- package/package.json +1 -1
|
@@ -112,7 +112,7 @@ async function applyPatch(patch, opts) {
|
|
|
112
112
|
async function readPdf(root, rel, pages, opts) {
|
|
113
113
|
let file;
|
|
114
114
|
try {
|
|
115
|
-
file = (0, paths_1.
|
|
115
|
+
file = (0, paths_1.resolveForRead)(root, rel);
|
|
116
116
|
}
|
|
117
117
|
catch (err) {
|
|
118
118
|
return { isError: true, content: err.message };
|
|
@@ -268,7 +268,8 @@ function performFileAction(root, name, a) {
|
|
|
268
268
|
if ((0, paths_1.isSecret)(rel)) {
|
|
269
269
|
return fail(`Refused: ${rel} holds credentials, and credentials are never read into a prompt.`);
|
|
270
270
|
}
|
|
271
|
-
|
|
271
|
+
// Reading is never limited to the workspace (owner, November 24, 2026).
|
|
272
|
+
const p = (0, paths_1.resolveForRead)(realRoot, rel);
|
|
272
273
|
if (!isText(path.basename(p))) {
|
|
273
274
|
const size = fs.statSync(p).size;
|
|
274
275
|
return fail(`${rel} is not a text file (${size.toLocaleString()} bytes). Reading it would be noise rather than context.`);
|
|
@@ -312,7 +313,7 @@ function performFileAction(root, name, a) {
|
|
|
312
313
|
};
|
|
313
314
|
}
|
|
314
315
|
case "list_dir": {
|
|
315
|
-
const p = (0, paths_1.
|
|
316
|
+
const p = (0, paths_1.resolveForRead)(realRoot, String(a.path ?? ""));
|
|
316
317
|
const here = slashed(path.relative(realRoot, p));
|
|
317
318
|
const rows = fs.readdirSync(p, { withFileTypes: true })
|
|
318
319
|
.filter((e) => !denied(here ? `${here}/${e.name}` : e.name, a.exclude))
|
|
@@ -320,20 +321,26 @@ function performFileAction(root, name, a) {
|
|
|
320
321
|
return ok(rows.join("\n") || "(empty)", `${rows.length} entries`);
|
|
321
322
|
}
|
|
322
323
|
case "file_map": {
|
|
323
|
-
const p = (0, paths_1.
|
|
324
|
-
|
|
324
|
+
const p = (0, paths_1.resolveForRead)(realRoot, String(a.path ?? ""));
|
|
325
|
+
// Outside the workspace, paths are named in full, from the folder asked about.
|
|
326
|
+
const base = (0, paths_1.insideAllowed)(realRoot, p) ? realRoot : (fs.statSync(p).isFile() ? path.dirname(p) : p);
|
|
327
|
+
const named = (f) => (base === realRoot ? f : slashed(path.join(base, f)));
|
|
328
|
+
const found = projectFiles(p, base, Number.MAX_SAFE_INTEGER, Boolean(a.include_ignored))
|
|
325
329
|
.filter((f) => !denied(f, a.exclude));
|
|
326
330
|
const shown = found.slice(0, MAX_MAP_PATHS);
|
|
327
331
|
const note = found.length > shown.length
|
|
328
332
|
? `\n\n[... ${found.length - shown.length} more paths left out. Map a subfolder for the rest.]` : "";
|
|
329
333
|
return {
|
|
330
|
-
content: shown.join("\n") + note, summary: `${found.length} files`,
|
|
334
|
+
content: shown.map(named).join("\n") + note, summary: `${found.length} files`,
|
|
331
335
|
facts: { files: shown.length, left_out: found.length - shown.length },
|
|
332
336
|
};
|
|
333
337
|
}
|
|
334
338
|
case "glob": {
|
|
335
|
-
const p = (0, paths_1.
|
|
336
|
-
|
|
339
|
+
const p = (0, paths_1.resolveForRead)(realRoot, String(a.path ?? ""));
|
|
340
|
+
// Outside the workspace, paths are named in full, from the folder asked about.
|
|
341
|
+
const base = (0, paths_1.insideAllowed)(realRoot, p) ? realRoot : (fs.statSync(p).isFile() ? path.dirname(p) : p);
|
|
342
|
+
const named = (f) => (base === realRoot ? f : slashed(path.join(base, f)));
|
|
343
|
+
const found = projectFiles(p, base, Number.MAX_SAFE_INTEGER, Boolean(a.include_ignored))
|
|
337
344
|
.filter((f) => !denied(f, a.exclude));
|
|
338
345
|
const pattern = String(a.pattern ?? "");
|
|
339
346
|
const rx = globToRegExp(pattern);
|
|
@@ -343,13 +350,13 @@ function performFileAction(root, name, a) {
|
|
|
343
350
|
const all = found.filter((f) => rx.test(f) || Boolean(anywhere?.test(f)));
|
|
344
351
|
// Newest first, as the tool description promises.
|
|
345
352
|
const mtime = (f) => { try {
|
|
346
|
-
return fs.statSync(path.join(
|
|
353
|
+
return fs.statSync(path.join(base, f)).mtimeMs;
|
|
347
354
|
}
|
|
348
355
|
catch {
|
|
349
356
|
return 0;
|
|
350
357
|
} };
|
|
351
358
|
const hits = all.map((f) => [f, mtime(f)])
|
|
352
|
-
.sort((x, y) => y[1] - x[1]).slice(0, MAX_RESULTS).map(([f]) => f);
|
|
359
|
+
.sort((x, y) => y[1] - x[1]).slice(0, MAX_RESULTS).map(([f]) => named(f));
|
|
353
360
|
const note = all.length > hits.length
|
|
354
361
|
? `\n\n[... ${all.length - hits.length} more files left out. Narrow the pattern.]` : "";
|
|
355
362
|
return {
|
|
@@ -358,7 +365,10 @@ function performFileAction(root, name, a) {
|
|
|
358
365
|
};
|
|
359
366
|
}
|
|
360
367
|
case "grep": {
|
|
361
|
-
const p = (0, paths_1.
|
|
368
|
+
const p = (0, paths_1.resolveForRead)(realRoot, String(a.path ?? ""));
|
|
369
|
+
// Outside the workspace, paths are named in full, from the folder asked about.
|
|
370
|
+
const base = (0, paths_1.insideAllowed)(realRoot, p) ? realRoot : (fs.statSync(p).isFile() ? path.dirname(p) : p);
|
|
371
|
+
const named = (f) => (base === realRoot ? f : slashed(path.join(base, f)));
|
|
362
372
|
let rx;
|
|
363
373
|
try {
|
|
364
374
|
rx = new RegExp(String(a.pattern ?? ""), a.case_sensitive ? "" : "i");
|
|
@@ -369,7 +379,7 @@ function performFileAction(root, name, a) {
|
|
|
369
379
|
const globText = a.glob ? String(a.glob) : "";
|
|
370
380
|
const globRx = globText ? globToRegExp(globText) : null;
|
|
371
381
|
const globAnywhere = globText && !globText.includes("/") ? globToRegExp(`**/${globText}`) : null;
|
|
372
|
-
const files = projectFiles(p,
|
|
382
|
+
const files = projectFiles(p, base, Number.MAX_SAFE_INTEGER, Boolean(a.include_ignored))
|
|
373
383
|
.filter((f) => !denied(f, a.exclude));
|
|
374
384
|
const context = Math.max(0, Math.min(Number(a.context_lines ?? 0), 5));
|
|
375
385
|
const hits = [];
|
|
@@ -385,7 +395,7 @@ function performFileAction(root, name, a) {
|
|
|
385
395
|
continue;
|
|
386
396
|
let text;
|
|
387
397
|
try {
|
|
388
|
-
text = fs.readFileSync(path.join(
|
|
398
|
+
text = fs.readFileSync(path.join(base, rel), "utf8");
|
|
389
399
|
}
|
|
390
400
|
catch {
|
|
391
401
|
continue;
|
|
@@ -399,10 +409,10 @@ function performFileAction(root, name, a) {
|
|
|
399
409
|
if (hits.length >= MAX_RESULTS)
|
|
400
410
|
continue;
|
|
401
411
|
if (context === 0)
|
|
402
|
-
hits.push(`${rel}:${i + 1}:${lines[i]}`);
|
|
412
|
+
hits.push(`${named(rel)}:${i + 1}:${lines[i]}`);
|
|
403
413
|
else {
|
|
404
414
|
const from = Math.max(0, i - context), to = Math.min(lines.length, i + context + 1);
|
|
405
|
-
hits.push(`${rel}:${i + 1}:\n${lines.slice(from, to).join("\n")}`);
|
|
415
|
+
hits.push(`${named(rel)}:${i + 1}:\n${lines.slice(from, to).join("\n")}`);
|
|
406
416
|
}
|
|
407
417
|
}
|
|
408
418
|
}
|
|
@@ -105,7 +105,7 @@ function outputOf(cell) {
|
|
|
105
105
|
function readNotebook(root, path, includeOutput = true) {
|
|
106
106
|
let raw;
|
|
107
107
|
try {
|
|
108
|
-
raw = fs.readFileSync((0, paths_1.
|
|
108
|
+
raw = fs.readFileSync((0, paths_1.resolveForRead)(root, path), "utf8");
|
|
109
109
|
}
|
|
110
110
|
catch (err) {
|
|
111
111
|
return { isError: true, content: `Could not read ${path}: ${err.message}` };
|
|
@@ -37,6 +37,8 @@ exports.OutsideWorkspace = void 0;
|
|
|
37
37
|
exports.allowFolders = allowFolders;
|
|
38
38
|
exports.allowedFolders = allowedFolders;
|
|
39
39
|
exports.isSecret = isSecret;
|
|
40
|
+
exports.insideAllowed = insideAllowed;
|
|
41
|
+
exports.resolveForRead = resolveForRead;
|
|
40
42
|
exports.resolveInside = resolveInside;
|
|
41
43
|
/**
|
|
42
44
|
* The folder boundary, on a real filesystem.
|
|
@@ -62,6 +64,7 @@ exports.resolveInside = resolveInside;
|
|
|
62
64
|
* Neither alone is the boundary.
|
|
63
65
|
*/
|
|
64
66
|
const fs = __importStar(require("fs"));
|
|
67
|
+
const os = __importStar(require("os"));
|
|
65
68
|
const path = __importStar(require("path"));
|
|
66
69
|
class OutsideWorkspace extends Error {
|
|
67
70
|
attempted;
|
|
@@ -104,8 +107,40 @@ const SECRET = /^(\.env(\..*)?|.*\.pem|.*\.key|.*\.p12|.*\.pfx|id_rsa.*|id_ed255
|
|
|
104
107
|
function isSecret(p) {
|
|
105
108
|
return SECRET.test(path.basename(p));
|
|
106
109
|
}
|
|
110
|
+
/** Is this real path inside one of the job's own folders? */
|
|
111
|
+
function insideAllowed(root, real) {
|
|
112
|
+
return allowedFolders(root).some((folder) => inside(real, folder));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* A path to READ, anywhere on this computer (owner, November 24, 2026: "the
|
|
116
|
+
* workspace is where work is organized and written; it never limits what can
|
|
117
|
+
* be read"). A relative path is taken from the workspace, an absolute or `~`
|
|
118
|
+
* path as written, on Mac, Windows and Linux alike. Credentials are still
|
|
119
|
+
* never read: this checks the real file a link leads to. Every change keeps
|
|
120
|
+
* `resolveInside`.
|
|
121
|
+
*/
|
|
122
|
+
function resolveForRead(root, rel) {
|
|
123
|
+
const realRoot = fs.realpathSync(root);
|
|
124
|
+
let asked = String(rel ?? "").trim();
|
|
125
|
+
if (asked === "~" || asked.startsWith("~/") || asked.startsWith("~\\")) {
|
|
126
|
+
asked = path.join(os.homedir(), asked.slice(1));
|
|
127
|
+
}
|
|
128
|
+
const joined = path.isAbsolute(asked) ? path.resolve(asked) : path.resolve(realRoot, asked);
|
|
129
|
+
let real;
|
|
130
|
+
try {
|
|
131
|
+
real = fs.realpathSync(joined);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
throw Object.assign(new Error(`No such file: ${rel}`), { code: "ENOENT" });
|
|
135
|
+
}
|
|
136
|
+
if (isSecret(real)) {
|
|
137
|
+
throw new Error(`Refused: ${rel} holds credentials, and credentials are never read into a prompt.`);
|
|
138
|
+
}
|
|
139
|
+
return real;
|
|
140
|
+
}
|
|
107
141
|
/**
|
|
108
|
-
* An absolute path inside the workspace, or a refusal.
|
|
142
|
+
* An absolute path inside the workspace, or a refusal. Used for every change;
|
|
143
|
+
* reading uses `resolveForRead`.
|
|
109
144
|
*
|
|
110
145
|
* `mustExist` is false when the caller is about to CREATE the thing. A file that
|
|
111
146
|
* does not exist yet cannot be resolved, so the check is applied to the deepest
|
|
@@ -157,6 +157,8 @@ function openWithSystem(file, text) {
|
|
|
157
157
|
});
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
|
+
/** The actions that only read, answered for any path on the computer. */
|
|
161
|
+
const READS_ANYWHERE = new Set(['read_file', 'list_dir', 'file_map', 'glob', 'grep', 'read_pdf', 'read_notebook']);
|
|
160
162
|
/** Carry out one order. Refused unless its place is inside a connected folder;
|
|
161
163
|
* a new workspace's folder (make_dir, ordered as the workspace is created)
|
|
162
164
|
* may also be made anywhere in the person's own home folder. */
|
|
@@ -221,8 +223,13 @@ async function perform(order, folders, jobRoot) {
|
|
|
221
223
|
if (order.op === 'tool') {
|
|
222
224
|
// A coding job's file action: `{name, input}`, run in the current
|
|
223
225
|
// workspace's folder, as the job's own executor runs it.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
+
// Reading is never limited to connected folders (owner, November 24, 2026):
|
|
227
|
+
// a read of any path on this computer, Mac, Windows or Linux, is answered,
|
|
228
|
+
// from the home folder when no workspace folder is named. Every change
|
|
229
|
+
// still runs only inside a connected folder.
|
|
230
|
+
const reading = READS_ANYWHERE.has(String(args.name ?? ''));
|
|
231
|
+
const root = abs(args.root) ?? jobRoot ?? (reading ? os.homedir() : null);
|
|
232
|
+
if (!root || (!reading && !folders.some((f) => within(f, root))))
|
|
226
233
|
return { id: order.id, ok: false, error: REFUSED };
|
|
227
234
|
const engine = new index_1.NativeExecutor({ root });
|
|
228
235
|
try {
|
|
@@ -343,7 +350,13 @@ function openLine(opts) {
|
|
|
343
350
|
return;
|
|
344
351
|
}
|
|
345
352
|
sock = s;
|
|
353
|
+
// Still here, every 20 seconds: the server calls a line silent for 150
|
|
354
|
+
// seconds gone while an action is out (November 24, 2026).
|
|
355
|
+
let still = null;
|
|
346
356
|
s.onopen = () => {
|
|
357
|
+
still = setInterval(() => { if (s.readyState === 1)
|
|
358
|
+
s.send(JSON.stringify({ type: 'ping' })); }, 20_000);
|
|
359
|
+
still.unref?.();
|
|
347
360
|
pause = 1000;
|
|
348
361
|
// The sign in goes in this first message, never in the address, so it
|
|
349
362
|
// is not written to any log of addresses.
|
|
@@ -389,6 +402,8 @@ function openLine(opts) {
|
|
|
389
402
|
})();
|
|
390
403
|
s.onerror = () => undefined;
|
|
391
404
|
s.onclose = () => {
|
|
405
|
+
if (still)
|
|
406
|
+
clearInterval(still);
|
|
392
407
|
if (up)
|
|
393
408
|
log('Line to the server closed; reconnecting.');
|
|
394
409
|
up = false;
|
|
@@ -113,11 +113,83 @@ const RECORDERS = [
|
|
|
113
113
|
{ name: 'arecord', command: 'arecord', args: (out) => ['-q', '-f', 'S16_LE', '-c', '1', '-r', RATE, out] },
|
|
114
114
|
];
|
|
115
115
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
116
|
+
* Windows' own microphone, through the sound system every copy of Windows has
|
|
117
|
+
* (winmm), driven from the PowerShell every copy of Windows has. Nothing to
|
|
118
|
+
* install. Samples go to the output as they are heard; closing the input (or
|
|
119
|
+
* this process ending) stops it, so the microphone never outlives us.
|
|
120
|
+
*/
|
|
121
|
+
const WINDOWS_MIC = `
|
|
122
|
+
$ErrorActionPreference = 'Stop'
|
|
123
|
+
Add-Type -TypeDefinition @'
|
|
124
|
+
using System; using System.IO; using System.Runtime.InteropServices; using System.Threading;
|
|
125
|
+
public static class CpMic {
|
|
126
|
+
[StructLayout(LayoutKind.Sequential)] public struct Fmt { public ushort tag, ch; public uint rate, bps; public ushort align, bits, extra; }
|
|
127
|
+
[StructLayout(LayoutKind.Sequential)] public struct Hdr { public IntPtr data; public uint length, recorded; public IntPtr user; public uint flags, loops; public IntPtr next, reserved; }
|
|
128
|
+
[DllImport("winmm.dll")] static extern int waveInOpen(out IntPtr h, uint dev, ref Fmt f, IntPtr cb, IntPtr inst, uint flags);
|
|
129
|
+
[DllImport("winmm.dll")] static extern int waveInPrepareHeader(IntPtr h, IntPtr hdr, uint size);
|
|
130
|
+
[DllImport("winmm.dll")] static extern int waveInUnprepareHeader(IntPtr h, IntPtr hdr, uint size);
|
|
131
|
+
[DllImport("winmm.dll")] static extern int waveInAddBuffer(IntPtr h, IntPtr hdr, uint size);
|
|
132
|
+
[DllImport("winmm.dll")] static extern int waveInStart(IntPtr h);
|
|
133
|
+
[DllImport("winmm.dll")] static extern int waveInReset(IntPtr h);
|
|
134
|
+
[DllImport("winmm.dll")] static extern int waveInClose(IntPtr h);
|
|
135
|
+
static volatile bool stop;
|
|
136
|
+
static void Watch() { try { Console.OpenStandardInput().Read(new byte[1], 0, 1); } catch { } stop = true; }
|
|
137
|
+
public static int Run(int rate) {
|
|
138
|
+
Fmt f = new Fmt(); f.tag = 1; f.ch = 1; f.rate = (uint)rate; f.bits = 16; f.align = 2; f.bps = (uint)(rate * 2);
|
|
139
|
+
IntPtr h; int r = waveInOpen(out h, 0xFFFFFFFF, ref f, IntPtr.Zero, IntPtr.Zero, 0);
|
|
140
|
+
if (r != 0) { Console.Error.WriteLine("No microphone could be opened (" + r + ")."); return 2; }
|
|
141
|
+
int n = 8, len = rate / 10 * 2, hs = Marshal.SizeOf(typeof(Hdr));
|
|
142
|
+
IntPtr[] hdrs = new IntPtr[n];
|
|
143
|
+
for (int k = 0; k < n; k++) {
|
|
144
|
+
Hdr w = new Hdr(); w.data = Marshal.AllocHGlobal(len); w.length = (uint)len;
|
|
145
|
+
hdrs[k] = Marshal.AllocHGlobal(hs); Marshal.StructureToPtr(w, hdrs[k], false);
|
|
146
|
+
waveInPrepareHeader(h, hdrs[k], (uint)hs); waveInAddBuffer(h, hdrs[k], (uint)hs);
|
|
147
|
+
}
|
|
148
|
+
Thread t = new Thread(Watch); t.IsBackground = true; t.Start();
|
|
149
|
+
Stream o = Console.OpenStandardOutput(); byte[] buf = new byte[len]; int i = 0;
|
|
150
|
+
waveInStart(h);
|
|
151
|
+
try {
|
|
152
|
+
while (!stop) {
|
|
153
|
+
Hdr w = (Hdr)Marshal.PtrToStructure(hdrs[i], typeof(Hdr));
|
|
154
|
+
if ((w.flags & 1) == 0) { Thread.Sleep(10); continue; }
|
|
155
|
+
Marshal.Copy(w.data, buf, 0, (int)w.recorded); o.Write(buf, 0, (int)w.recorded); o.Flush();
|
|
156
|
+
w.recorded = 0; w.flags = 2; Marshal.StructureToPtr(w, hdrs[i], false);
|
|
157
|
+
waveInAddBuffer(h, hdrs[i], (uint)hs);
|
|
158
|
+
i = (i + 1) % n;
|
|
159
|
+
}
|
|
160
|
+
waveInReset(h);
|
|
161
|
+
for (int k = 0; k < n; k++, i = (i + 1) % n) {
|
|
162
|
+
Hdr w = (Hdr)Marshal.PtrToStructure(hdrs[i], typeof(Hdr));
|
|
163
|
+
if (w.recorded > 0) { Marshal.Copy(w.data, buf, 0, (int)w.recorded); o.Write(buf, 0, (int)w.recorded); }
|
|
164
|
+
}
|
|
165
|
+
o.Flush();
|
|
166
|
+
} catch (IOException) { }
|
|
167
|
+
for (int k = 0; k < n; k++) waveInUnprepareHeader(h, hdrs[k], (uint)hs);
|
|
168
|
+
waveInClose(h);
|
|
169
|
+
return 0;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
'@
|
|
173
|
+
exit [CpMic]::Run([int]$args[0])
|
|
174
|
+
`;
|
|
175
|
+
/**
|
|
176
|
+
* The microphone reader that needs nothing installed: on a Mac the program
|
|
177
|
+
* that ships inside the package (built from native/dictate.swift), on Windows
|
|
178
|
+
* the sound system Windows already has. It only passes the microphone's sound
|
|
179
|
+
* on; the server does the transcribing.
|
|
119
180
|
*/
|
|
120
181
|
function builtInReader() {
|
|
182
|
+
if (process.platform === 'win32') {
|
|
183
|
+
const root = process.env.SystemRoot ?? 'C:\\Windows';
|
|
184
|
+
const ps = path.join(root, 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe');
|
|
185
|
+
return {
|
|
186
|
+
name: 'Windows microphone',
|
|
187
|
+
command: fs.existsSync(ps) ? ps : 'powershell.exe',
|
|
188
|
+
// Encoded so no quoting of the script can go wrong; the rate follows it.
|
|
189
|
+
args: (rate) => ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass',
|
|
190
|
+
'-Command', `& ([scriptblock]::Create([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('${Buffer.from(WINDOWS_MIC, 'utf16le').toString('base64')}')))) ${rate}`],
|
|
191
|
+
};
|
|
192
|
+
}
|
|
121
193
|
if (process.platform !== 'darwin')
|
|
122
194
|
return null;
|
|
123
195
|
for (const at of [
|
|
@@ -130,12 +202,28 @@ function builtInReader() {
|
|
|
130
202
|
path.join(__dirname, 'native', 'dictate'),
|
|
131
203
|
]) {
|
|
132
204
|
if (fs.existsSync(at))
|
|
133
|
-
return at;
|
|
205
|
+
return { name: 'built in microphone reader', command: at, args: (rate) => ['--raw', rate] };
|
|
134
206
|
}
|
|
135
207
|
return null;
|
|
136
208
|
}
|
|
209
|
+
/** Ask a recorder to stop and finish its file. A signal everywhere but Windows,
|
|
210
|
+
* where there are no signals: there the reader stops when its input closes. */
|
|
211
|
+
function interrupt(child) {
|
|
212
|
+
if (process.platform === 'win32') {
|
|
213
|
+
try {
|
|
214
|
+
child.stdin?.end();
|
|
215
|
+
}
|
|
216
|
+
catch { /* already closed */ }
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
child.kill('SIGINT');
|
|
220
|
+
}
|
|
137
221
|
/** The first recording tool this machine has, or null. */
|
|
138
222
|
function recorder() {
|
|
223
|
+
// These tools are driven with Mac and Linux sound devices; on Windows the
|
|
224
|
+
// sound system Windows already has does the listening instead.
|
|
225
|
+
if (process.platform === 'win32')
|
|
226
|
+
return null;
|
|
139
227
|
for (const r of RECORDERS) {
|
|
140
228
|
const at = locate(r.command);
|
|
141
229
|
if (at)
|
|
@@ -153,6 +241,10 @@ function recorder() {
|
|
|
153
241
|
function missing() {
|
|
154
242
|
if (builtInReader() || recorder())
|
|
155
243
|
return null;
|
|
244
|
+
if (process.platform === 'win32') {
|
|
245
|
+
return 'Speaking needs Windows PowerShell, which this computer is missing. '
|
|
246
|
+
+ 'Turn it on under Settings, Apps, Optional features.';
|
|
247
|
+
}
|
|
156
248
|
return process.platform === 'darwin'
|
|
157
249
|
? 'Speaking needs a recording tool, and macOS does not come with one. '
|
|
158
250
|
+ 'Install it once with: brew install sox'
|
|
@@ -178,7 +270,7 @@ function start() {
|
|
|
178
270
|
// The reader writes bare samples; the file gets the WAV header the other
|
|
179
271
|
// tools write, with its lengths filled in when the recording ends.
|
|
180
272
|
fs.writeFileSync(file, wavHeader(0));
|
|
181
|
-
child = (0, node_child_process_1.spawn)(reader,
|
|
273
|
+
child = (0, node_child_process_1.spawn)(reader.command, reader.args(RATE), { stdio: ['pipe', 'pipe', 'ignore'], windowsHide: true });
|
|
182
274
|
child.stdout?.on('data', (chunk) => { try {
|
|
183
275
|
fs.appendFileSync(file, chunk);
|
|
184
276
|
}
|
|
@@ -240,7 +332,7 @@ function start() {
|
|
|
240
332
|
// that was never finished reads as silence to whoever transcribes it.
|
|
241
333
|
child.once('close', done);
|
|
242
334
|
try {
|
|
243
|
-
child
|
|
335
|
+
interrupt(child);
|
|
244
336
|
}
|
|
245
337
|
catch {
|
|
246
338
|
done();
|
|
@@ -258,7 +350,7 @@ function start() {
|
|
|
258
350
|
});
|
|
259
351
|
return stopped;
|
|
260
352
|
};
|
|
261
|
-
return { file, by: reader ?
|
|
353
|
+
return { file, by: reader ? reader.name : tool.name, stop };
|
|
262
354
|
}
|
|
263
355
|
/** A 44 byte WAV header for 16 bit, one channel samples at RATE. */
|
|
264
356
|
function wavHeader(dataBytes) {
|
|
@@ -315,12 +407,12 @@ function liveArgs(tool) {
|
|
|
315
407
|
/** Start listening live. Throws when there is nothing to listen with. */
|
|
316
408
|
function startLive(onSound) {
|
|
317
409
|
const reader = builtInReader();
|
|
318
|
-
const tool = reader ?
|
|
319
|
-
if (!tool)
|
|
410
|
+
const tool = reader ? null : recorder();
|
|
411
|
+
if (!reader && !tool)
|
|
320
412
|
throw new Error(missing() ?? 'No recording tool.');
|
|
321
413
|
// The built in reader stops when its input closes, so it is given one.
|
|
322
414
|
const child = reader
|
|
323
|
-
? (0, node_child_process_1.spawn)(reader,
|
|
415
|
+
? (0, node_child_process_1.spawn)(reader.command, reader.args(exports.LIVE_RATE), { stdio: ['pipe', 'pipe', 'ignore'], windowsHide: true })
|
|
324
416
|
: (0, node_child_process_1.spawn)(tool.command, liveArgs(tool), { stdio: ['ignore', 'pipe', 'ignore'] });
|
|
325
417
|
child.stdout?.on('data', (chunk) => onSound(chunk));
|
|
326
418
|
// As with a file: the microphone never outlives the process that opened it.
|
|
@@ -336,14 +428,14 @@ function startLive(onSound) {
|
|
|
336
428
|
stopped = new Promise((resolve) => {
|
|
337
429
|
child.once('close', () => resolve());
|
|
338
430
|
try {
|
|
339
|
-
child
|
|
431
|
+
interrupt(child);
|
|
340
432
|
}
|
|
341
433
|
catch {
|
|
342
434
|
resolve();
|
|
343
435
|
}
|
|
344
|
-
setTimeout(() => { abandon(); resolve(); }, 500).unref();
|
|
436
|
+
setTimeout(() => { abandon(); resolve(); }, process.platform === 'win32' ? 1500 : 500).unref();
|
|
345
437
|
}).then(() => { process.off('exit', abandon); });
|
|
346
438
|
return stopped;
|
|
347
439
|
};
|
|
348
|
-
return { by: tool.name, stop };
|
|
440
|
+
return { by: reader ? reader.name : tool.name, stop };
|
|
349
441
|
}
|
package/out/server.generated.js
CHANGED
|
@@ -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 = "
|
|
6
|
+
exports.BUILD_COMMIT = "cc0f1be0918a17c26e7c46d3c0c4f0844e42587e";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@illuminis/comprism",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.17.0",
|
|
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,
|