@illuminis/comprism 2.7.1 → 2.9.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/files.js +3 -1
- package/out/build/machine/executor/index.js +3 -1
- package/out/build/machine/executor/paths.js +5 -0
- package/out/build/machine/executor/shell.js +49 -0
- package/out/build/machine/line/index.js +62 -4
- package/out/cli-start.js +5 -2
- package/out/machine/executor/files.js +1 -1
- package/out/machine/executor/paths.js +3 -0
- package/out/server.generated.js +1 -1
- package/package.json +1 -1
|
@@ -183,7 +183,9 @@ function projectFiles(dir, root, limit, all) {
|
|
|
183
183
|
return [];
|
|
184
184
|
}
|
|
185
185
|
const listed = all ? null : gitFiles(dir, root);
|
|
186
|
-
|
|
186
|
+
// Git saying "no files" is not trusted: a project inside another repository
|
|
187
|
+
// that ignores it lists nothing, and the plain walk finds what is really there.
|
|
188
|
+
if (listed && listed.length > 0)
|
|
187
189
|
return listed.sort().slice(0, limit);
|
|
188
190
|
const out = [];
|
|
189
191
|
walk(dir, root, out, limit, all);
|
|
@@ -324,7 +324,9 @@ class NativeExecutor {
|
|
|
324
324
|
case "read_output":
|
|
325
325
|
return (0, shell_1.readOutput)(String(a.process_id ?? ""));
|
|
326
326
|
case "stop_process":
|
|
327
|
-
return
|
|
327
|
+
return a.port !== undefined && a.port !== null && a.port !== ""
|
|
328
|
+
? (0, shell_1.stopByPort)(Number(a.port), this.root)
|
|
329
|
+
: (0, shell_1.stopProcess)(String(a.process_id ?? ""));
|
|
328
330
|
case "install_dependency": {
|
|
329
331
|
const cmd = installCommand(this.root, String(a.package ?? ""), a.manager, Boolean(a.dev));
|
|
330
332
|
if (!cmd) {
|
|
@@ -140,6 +140,11 @@ function resolveInside(root, rel, mustExist = false) {
|
|
|
140
140
|
real = fs.realpathSync(probe);
|
|
141
141
|
}
|
|
142
142
|
catch {
|
|
143
|
+
// A path that lands inside the project but is not there is a missing file,
|
|
144
|
+
// said as one, not a refusal about folders.
|
|
145
|
+
if (allowedFolders(realRoot).some((folder) => inside(joined, folder))) {
|
|
146
|
+
throw Object.assign(new Error(`No such file: ${asked}`), { code: "ENOENT" });
|
|
147
|
+
}
|
|
143
148
|
throw new OutsideWorkspace(rel);
|
|
144
149
|
}
|
|
145
150
|
// The comparison, with a separator on the end. Without it `/work/project-two`
|
|
@@ -43,6 +43,7 @@ exports.stopForeground = stopForeground;
|
|
|
43
43
|
exports.startBackground = startBackground;
|
|
44
44
|
exports.readOutput = readOutput;
|
|
45
45
|
exports.stopProcess = stopProcess;
|
|
46
|
+
exports.stopByPort = stopByPort;
|
|
46
47
|
exports.listProcesses = listProcesses;
|
|
47
48
|
exports.stopEverything = stopEverything;
|
|
48
49
|
exports.guessTestCommand = guessTestCommand;
|
|
@@ -458,6 +459,54 @@ function stopProcess(id) {
|
|
|
458
459
|
summary: `stopped ${id}`,
|
|
459
460
|
};
|
|
460
461
|
}
|
|
462
|
+
/** Stop whatever listens on `port`, only when it runs from inside the project.
|
|
463
|
+
*
|
|
464
|
+
* A test script the agent ran with run_command can start a server that
|
|
465
|
+
* outlives it, and the agent then has no number to stop it by. Stopping by
|
|
466
|
+
* port is safe here because every listener is checked first: its working
|
|
467
|
+
* folder must be inside `root`, so a person's own editor, database or server
|
|
468
|
+
* elsewhere on the machine is never touched (owner, November 3, 2026). */
|
|
469
|
+
function stopByPort(port, root) {
|
|
470
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
471
|
+
return { isError: true, content: `${port} is not a port number.` };
|
|
472
|
+
}
|
|
473
|
+
if (process.platform === "win32") {
|
|
474
|
+
return { isError: true, content: "Stopping by port is not available on Windows. Stop it by the number run_background gave it." };
|
|
475
|
+
}
|
|
476
|
+
const listeners = (0, child_process_1.spawnSync)("lsof", ["-nP", `-iTCP:${port}`, "-sTCP:LISTEN", "-t"], { encoding: "utf8" });
|
|
477
|
+
const pids = [...new Set(String(listeners.stdout || "").split(/\s+/).filter((p) => /^\d+$/.test(p)))];
|
|
478
|
+
if (!pids.length)
|
|
479
|
+
return { content: `Nothing is listening on port ${port}.`, summary: `port ${port} free` };
|
|
480
|
+
const inside = path.resolve(root);
|
|
481
|
+
const stopped = [];
|
|
482
|
+
const outside = [];
|
|
483
|
+
for (const pid of pids) {
|
|
484
|
+
const cwd = (0, child_process_1.spawnSync)("lsof", ["-a", "-p", pid, "-d", "cwd", "-Fn"], { encoding: "utf8" });
|
|
485
|
+
const folder = (String(cwd.stdout || "").split("\n").find((l) => l.startsWith("n")) || "").slice(1);
|
|
486
|
+
const resolved = folder ? path.resolve(folder) : "";
|
|
487
|
+
if (resolved && (resolved === inside || resolved.startsWith(inside + path.sep))) {
|
|
488
|
+
try {
|
|
489
|
+
process.kill(Number(pid), "SIGTERM");
|
|
490
|
+
}
|
|
491
|
+
catch { /* already gone */ }
|
|
492
|
+
setTimeout(() => { try {
|
|
493
|
+
process.kill(Number(pid), "SIGKILL");
|
|
494
|
+
}
|
|
495
|
+
catch { /* already gone */ } }, 1500).unref();
|
|
496
|
+
stopped.push(pid);
|
|
497
|
+
}
|
|
498
|
+
else {
|
|
499
|
+
outside.push(pid);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
if (outside.length && !stopped.length) {
|
|
503
|
+
return { isError: true, content: `Port ${port} is held by a process outside this project, so it was left running. Use another port.` };
|
|
504
|
+
}
|
|
505
|
+
return {
|
|
506
|
+
content: `Stopped the project's process on port ${port}.` + (outside.length ? " A process outside this project also listens there and was left running." : ""),
|
|
507
|
+
summary: `stopped port ${port}`,
|
|
508
|
+
};
|
|
509
|
+
}
|
|
461
510
|
/** What this session started and is still tracking, for `processes`. */
|
|
462
511
|
function listProcesses() {
|
|
463
512
|
return [...running.entries()].map(([id, e]) => ({
|
|
@@ -53,6 +53,7 @@ exports.openLine = openLine;
|
|
|
53
53
|
* Shared by the terminal and the VS Code extension, which loads the compiled
|
|
54
54
|
* copy, so there is one helper and not two.
|
|
55
55
|
*/
|
|
56
|
+
const childProcess = __importStar(require("node:child_process"));
|
|
56
57
|
const fs = __importStar(require("node:fs"));
|
|
57
58
|
const os = __importStar(require("node:os"));
|
|
58
59
|
const path = __importStar(require("node:path"));
|
|
@@ -100,8 +101,11 @@ async function readConnectedFolders(opts) {
|
|
|
100
101
|
if (s.kind !== 'computer' || (s.machine && s.machine !== here))
|
|
101
102
|
continue;
|
|
102
103
|
for (const w of s.workspaces ?? []) {
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
// The workspace's own folder, and every folder added to it.
|
|
105
|
+
for (const p of [w.path, ...(w.folders ?? []).map((f) => f.path)]) {
|
|
106
|
+
if (typeof p === 'string' && path.isAbsolute(p))
|
|
107
|
+
out.push(path.resolve(p));
|
|
108
|
+
}
|
|
105
109
|
}
|
|
106
110
|
}
|
|
107
111
|
return out;
|
|
@@ -127,6 +131,32 @@ async function currentFolder(opts) {
|
|
|
127
131
|
return path.resolve(c.path);
|
|
128
132
|
}
|
|
129
133
|
const REFUSED = 'Refused: that place is not inside a folder you connected on this computer.';
|
|
134
|
+
/** How "Open" treats a file, the same rule the server holds. Programs and
|
|
135
|
+
* installers are refused (opening one would run it). Scripts and source code
|
|
136
|
+
* open in the text editor and are never run. Everything else opens in the
|
|
137
|
+
* application this computer uses for that kind of file. */
|
|
138
|
+
const PROGRAMS = new Set('exe msi app pkg dmg com scr apk ipa deb rpm appimage jar'.split(' '));
|
|
139
|
+
const SCRIPTS = new Set(('sh bash zsh fish command py pyw js mjs cjs ts tsx jsx rb php pl ps1 bat cmd vbs scpt '
|
|
140
|
+
+ 'applescript workflow').split(' '));
|
|
141
|
+
/** Hand the file to the system. `text` opens it in the text editor, for a script. */
|
|
142
|
+
function openWithSystem(file, text) {
|
|
143
|
+
const [cmd, ...rest] = process.platform === 'darwin' ? (text ? ['open', '-t', file] : ['open', file])
|
|
144
|
+
: process.platform === 'win32' ? (text ? ['notepad.exe', file] : ['explorer.exe', file]) : ['xdg-open', file];
|
|
145
|
+
return new Promise((resolve, reject) => {
|
|
146
|
+
const child = childProcess.spawn(cmd, rest, { detached: true, stdio: 'ignore' });
|
|
147
|
+
child.once('error', reject);
|
|
148
|
+
// `open` and `xdg-open` answer within a moment, with a failure code when no
|
|
149
|
+
// application is set for the kind of file; Windows' answer means nothing.
|
|
150
|
+
const wait = setTimeout(() => { child.unref(); resolve(); }, 3000);
|
|
151
|
+
child.once('exit', (code) => {
|
|
152
|
+
clearTimeout(wait);
|
|
153
|
+
if (code && process.platform !== 'win32')
|
|
154
|
+
reject(new Error(`exit ${code}`));
|
|
155
|
+
else
|
|
156
|
+
resolve();
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
}
|
|
130
160
|
/** Carry out one order. Refused unless its place is inside a connected folder;
|
|
131
161
|
* a new workspace's folder (make_dir, ordered as the workspace is created)
|
|
132
162
|
* may also be made anywhere in the person's own home folder. */
|
|
@@ -149,6 +179,32 @@ async function perform(order, folders, jobRoot) {
|
|
|
149
179
|
const p = v === '~' || v.startsWith('~/') ? path.join(os.homedir(), v.slice(1)) : v;
|
|
150
180
|
return path.isAbsolute(p) ? path.resolve(p) : null;
|
|
151
181
|
};
|
|
182
|
+
if (order.op === 'open_file') {
|
|
183
|
+
// A file picked in the workspace, opened in the application this computer
|
|
184
|
+
// uses for its type: only inside a folder the person connected, only the
|
|
185
|
+
// safe kinds, never a program or a script.
|
|
186
|
+
const target = abs(args.path);
|
|
187
|
+
if (!target || !folders.some((f) => within(f, target)))
|
|
188
|
+
return { id: order.id, ok: false, error: REFUSED };
|
|
189
|
+
const ext = path.extname(target).slice(1).toLowerCase();
|
|
190
|
+
if (PROGRAMS.has(ext))
|
|
191
|
+
return { id: order.id, ok: false, error: 'Programs and installers are not run from here.' };
|
|
192
|
+
const found = fs.existsSync(target) ? fs.statSync(target) : null;
|
|
193
|
+
if (!found)
|
|
194
|
+
return { id: order.id, ok: false, error: 'That file is not there any more.' };
|
|
195
|
+
if (!found.isFile())
|
|
196
|
+
return { id: order.id, ok: false, error: 'That is not a file.' };
|
|
197
|
+
// A script, or a runnable file with no known type, is read in the text editor and never run.
|
|
198
|
+
const script = SCRIPTS.has(ext) || (!ext && (found.mode & 0o111) !== 0);
|
|
199
|
+
try {
|
|
200
|
+
await openWithSystem(target, script);
|
|
201
|
+
return { id: order.id, ok: true, result: { opened: true, path: target } };
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
// No application on this computer for the kind of file; the server words the note.
|
|
205
|
+
return { id: order.id, ok: false, error: 'no_application' };
|
|
206
|
+
}
|
|
207
|
+
}
|
|
152
208
|
if (order.op === 'tool' && typeof args.job === 'string' && args.job) {
|
|
153
209
|
// A terminal job's action, ordered by the server for the job it opened on
|
|
154
210
|
// this computer, on that job's own executor.
|
|
@@ -194,7 +250,7 @@ async function perform(order, folders, jobRoot) {
|
|
|
194
250
|
try {
|
|
195
251
|
if (order.op === 'list_dir') {
|
|
196
252
|
const entries = fs.readdirSync(where, { withFileTypes: true })
|
|
197
|
-
.filter((e) => !e.name.startsWith('.'))
|
|
253
|
+
.filter((e) => Boolean(args.hidden) || !e.name.startsWith('.'))
|
|
198
254
|
.map((e) => {
|
|
199
255
|
const folder = e.isDirectory();
|
|
200
256
|
let size;
|
|
@@ -207,7 +263,7 @@ async function perform(order, folders, jobRoot) {
|
|
|
207
263
|
return { name: e.name, kind: folder ? 'folder' : 'file', ...(size !== undefined ? { size } : {}) };
|
|
208
264
|
})
|
|
209
265
|
.sort((a, b) => (a.kind === b.kind ? a.name.localeCompare(b.name) : a.kind === 'folder' ? -1 : 1));
|
|
210
|
-
return { id: order.id, ok: true, result: { entries } };
|
|
266
|
+
return { id: order.id, ok: true, result: { path: where, entries } };
|
|
211
267
|
}
|
|
212
268
|
if (order.op === 'make_dir') {
|
|
213
269
|
fs.mkdirSync(where, { recursive: true });
|
|
@@ -275,6 +331,8 @@ function openLine(opts) {
|
|
|
275
331
|
url.searchParams.set('client', opts.client);
|
|
276
332
|
if (opts.tenant)
|
|
277
333
|
url.searchParams.set('tenant', opts.tenant);
|
|
334
|
+
if (opts.lineId)
|
|
335
|
+
url.searchParams.set('line', opts.lineId);
|
|
278
336
|
let s;
|
|
279
337
|
try {
|
|
280
338
|
s = new Ctor(url.toString());
|
package/out/cli-start.js
CHANGED
|
@@ -71,10 +71,13 @@ function main() {
|
|
|
71
71
|
// Opened at start when signed in, or the moment a sign in is saved, so the
|
|
72
72
|
// session that follows signing in can reach this computer at once.
|
|
73
73
|
let line = null;
|
|
74
|
+
// This copy's own line: with many copies on one computer, each job's
|
|
75
|
+
// commands come back to the copy that started it, and no other.
|
|
76
|
+
const lineId = crypto.randomUUID();
|
|
74
77
|
const openLineNow = () => {
|
|
75
78
|
if (line || !card?.workspaceKey)
|
|
76
79
|
return;
|
|
77
|
-
line = (0, index_1.openLine)({ baseUrl: (card.url || server).replace(/\/+$/, ''), token: () => card?.workspaceKey ?? '', client: 'terminal',
|
|
80
|
+
line = (0, index_1.openLine)({ baseUrl: (card.url || server).replace(/\/+$/, ''), token: () => card?.workspaceKey ?? '', client: 'terminal', lineId,
|
|
78
81
|
...(card.tenant ? { tenant: card.tenant } : {}),
|
|
79
82
|
...(process.env.COMPRISM_LINE_LOG ? { log: (l) => process.stderr.write(`[line] ${l}\n`) } : {}) });
|
|
80
83
|
};
|
|
@@ -106,7 +109,7 @@ function main() {
|
|
|
106
109
|
door.onopen = () => {
|
|
107
110
|
door.send(JSON.stringify({
|
|
108
111
|
token: card?.workspaceKey ?? '', tenant: card?.tenant, words: process.argv.slice(2), version: VERSION,
|
|
109
|
-
folder: process.cwd(), machine: os.hostname(), term: process.env.TERM, install: (0, run_ordered_1.installedBy)(__filename),
|
|
112
|
+
folder: process.cwd(), machine: os.hostname(), line: lineId, term: process.env.TERM, install: (0, run_ordered_1.installedBy)(__filename),
|
|
110
113
|
termProgram: process.env.TERM_PROGRAM,
|
|
111
114
|
cols: process.stdout.columns, rows: process.stdout.rows,
|
|
112
115
|
}));
|
|
@@ -183,7 +183,7 @@ function projectFiles(dir, root, limit, all) {
|
|
|
183
183
|
return [];
|
|
184
184
|
}
|
|
185
185
|
const listed = all ? null : gitFiles(dir, root);
|
|
186
|
-
if (listed)
|
|
186
|
+
if (listed && listed.length > 0)
|
|
187
187
|
return listed.sort().slice(0, limit);
|
|
188
188
|
const out = [];
|
|
189
189
|
walk(dir, root, out, limit, all);
|
|
@@ -140,6 +140,9 @@ function resolveInside(root, rel, mustExist = false) {
|
|
|
140
140
|
real = fs.realpathSync(probe);
|
|
141
141
|
}
|
|
142
142
|
catch {
|
|
143
|
+
if (allowedFolders(realRoot).some((folder) => inside(joined, folder))) {
|
|
144
|
+
throw Object.assign(new Error(`No such file: ${asked}`), { code: "ENOENT" });
|
|
145
|
+
}
|
|
143
146
|
throw new OutsideWorkspace(rel);
|
|
144
147
|
}
|
|
145
148
|
// The comparison, with a separator on the end. Without it `/work/project-two`
|
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 = "c237d765b05b6095ab4dadbf4f02510482e1d0b1";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@illuminis/comprism",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.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,
|