@illuminis/comprism 2.7.0 → 2.8.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 +76 -4
- 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"));
|
|
@@ -68,7 +69,23 @@ function headers(opts, token) {
|
|
|
68
69
|
return h;
|
|
69
70
|
}
|
|
70
71
|
/** The folders the person connected on this computer, from the server. */
|
|
72
|
+
// A job asks for dozens of files in a row; the folder list is read once for a
|
|
73
|
+
// few seconds rather than once per order.
|
|
74
|
+
const FOLDERS_FOR_MS = 30_000;
|
|
75
|
+
let folderMemo = null;
|
|
71
76
|
async function connectedFolders(opts) {
|
|
77
|
+
const key = opts.baseUrl;
|
|
78
|
+
if (folderMemo && folderMemo.key === key && Date.now() - folderMemo.at < FOLDERS_FOR_MS)
|
|
79
|
+
return folderMemo.folders;
|
|
80
|
+
const folders = readConnectedFolders(opts);
|
|
81
|
+
folderMemo = { key, at: Date.now(), folders };
|
|
82
|
+
// A failure or an empty answer is never kept, so the next order asks again.
|
|
83
|
+
void folders.then((f) => { if (f.length === 0 && folderMemo?.folders === folders)
|
|
84
|
+
folderMemo = null; }, () => { if (folderMemo?.folders === folders)
|
|
85
|
+
folderMemo = null; });
|
|
86
|
+
return folders;
|
|
87
|
+
}
|
|
88
|
+
async function readConnectedFolders(opts) {
|
|
72
89
|
const token = await opts.token();
|
|
73
90
|
if (!token)
|
|
74
91
|
return [];
|
|
@@ -84,8 +101,11 @@ async function connectedFolders(opts) {
|
|
|
84
101
|
if (s.kind !== 'computer' || (s.machine && s.machine !== here))
|
|
85
102
|
continue;
|
|
86
103
|
for (const w of s.workspaces ?? []) {
|
|
87
|
-
|
|
88
|
-
|
|
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
|
+
}
|
|
89
109
|
}
|
|
90
110
|
}
|
|
91
111
|
return out;
|
|
@@ -111,6 +131,32 @@ async function currentFolder(opts) {
|
|
|
111
131
|
return path.resolve(c.path);
|
|
112
132
|
}
|
|
113
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
|
+
}
|
|
114
160
|
/** Carry out one order. Refused unless its place is inside a connected folder;
|
|
115
161
|
* a new workspace's folder (make_dir, ordered as the workspace is created)
|
|
116
162
|
* may also be made anywhere in the person's own home folder. */
|
|
@@ -133,6 +179,32 @@ async function perform(order, folders, jobRoot) {
|
|
|
133
179
|
const p = v === '~' || v.startsWith('~/') ? path.join(os.homedir(), v.slice(1)) : v;
|
|
134
180
|
return path.isAbsolute(p) ? path.resolve(p) : null;
|
|
135
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
|
+
}
|
|
136
208
|
if (order.op === 'tool' && typeof args.job === 'string' && args.job) {
|
|
137
209
|
// A terminal job's action, ordered by the server for the job it opened on
|
|
138
210
|
// this computer, on that job's own executor.
|
|
@@ -178,7 +250,7 @@ async function perform(order, folders, jobRoot) {
|
|
|
178
250
|
try {
|
|
179
251
|
if (order.op === 'list_dir') {
|
|
180
252
|
const entries = fs.readdirSync(where, { withFileTypes: true })
|
|
181
|
-
.filter((e) => !e.name.startsWith('.'))
|
|
253
|
+
.filter((e) => Boolean(args.hidden) || !e.name.startsWith('.'))
|
|
182
254
|
.map((e) => {
|
|
183
255
|
const folder = e.isDirectory();
|
|
184
256
|
let size;
|
|
@@ -191,7 +263,7 @@ async function perform(order, folders, jobRoot) {
|
|
|
191
263
|
return { name: e.name, kind: folder ? 'folder' : 'file', ...(size !== undefined ? { size } : {}) };
|
|
192
264
|
})
|
|
193
265
|
.sort((a, b) => (a.kind === b.kind ? a.name.localeCompare(b.name) : a.kind === 'folder' ? -1 : 1));
|
|
194
|
-
return { id: order.id, ok: true, result: { entries } };
|
|
266
|
+
return { id: order.id, ok: true, result: { path: where, entries } };
|
|
195
267
|
}
|
|
196
268
|
if (order.op === 'make_dir') {
|
|
197
269
|
fs.mkdirSync(where, { recursive: true });
|
|
@@ -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 = "ac5d1e4e50878ef0f5202670a43ec694622820b8";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@illuminis/comprism",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.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,
|