@illuminis/comprism 2.4.2 → 2.4.3

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.
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.isStandalone = isStandalone;
37
37
  exports.standaloneBinDir = standaloneBinDir;
38
38
  exports.installMethod = installMethod;
39
+ exports.pythonHere = pythonHere;
39
40
  exports.selfLaunch = selfLaunch;
40
41
  exports.shippedFile = shippedFile;
41
42
  exports.relaunchThroughProxy = relaunchThroughProxy;
@@ -93,6 +94,21 @@ function installMethod() {
93
94
  }
94
95
  return "python";
95
96
  }
97
+ /** The Python this copy was installed into by pip, found beside the program. */
98
+ function pythonHere() {
99
+ let dir = path.dirname(process.execPath);
100
+ for (let i = 0; i < 8; i++) {
101
+ for (const p of [path.join(dir, "bin", "python3"), path.join(dir, "Scripts", "python.exe"), path.join(dir, "python.exe")]) {
102
+ if (fs.existsSync(p))
103
+ return p;
104
+ }
105
+ const up = path.dirname(dir);
106
+ if (up === dir)
107
+ break;
108
+ dir = up;
109
+ }
110
+ return null;
111
+ }
96
112
  /** The command and arguments that start another copy of this tool. */
97
113
  function selfLaunch(args, nodeFlags = []) {
98
114
  if (isStandalone())
@@ -44,6 +44,7 @@ exports.savedPassword = savedPassword;
44
44
  exports.savePassword = savePassword;
45
45
  exports.forgetPassword = forgetPassword;
46
46
  exports.openAddress = openAddress;
47
+ exports.removeHere = removeHere;
47
48
  /**
48
49
  * Device helper: the terminal tool's sign in, kept in this computer's key store.
49
50
  *
@@ -62,6 +63,7 @@ const fs = __importStar(require("node:fs"));
62
63
  const os = __importStar(require("node:os"));
63
64
  const path = __importStar(require("node:path"));
64
65
  const home_1 = require("../runtime/home");
66
+ const self_1 = require("../runtime/self");
65
67
  const KEYCHAIN = process.platform === 'darwin' && !process.env.COMPRISM_HOME;
66
68
  const ACCOUNT = (() => { try {
67
69
  return os.userInfo().username;
@@ -123,8 +125,10 @@ function readItem(item) {
123
125
  function writeItem(item, text) {
124
126
  if (KEYCHAIN) {
125
127
  const r = security(['add-generic-password', '-U', '-a', ACCOUNT, '-s', ITEM[item], '-l', ITEM[item], '-w', text]);
128
+ // A locked or missing keychain (a remote session, a new account) falls
129
+ // back to the same owner readable file every other system uses.
126
130
  if (!r.ok)
127
- throw new Error('The sign in could not be kept in this computer\'s keychain.');
131
+ writeFileItem(item, text);
128
132
  }
129
133
  else {
130
134
  writeFileItem(item, text);
@@ -210,3 +214,62 @@ function openAddress(url) {
210
214
  // nosemgrep: javascript.lang.security.detect-child-process.detect-child-process -- opens a sign in address, one argument, no shell
211
215
  cp.spawn(cmd, argv, { stdio: 'ignore', detached: true }).on('error', () => undefined).unref();
212
216
  }
217
+ /**
218
+ * Uninstall with no sign in, or with the server out of reach. The server cannot
219
+ * order steps on a computer it has no line to, so without this a person who was
220
+ * never signed in, or whose copy pointed at a server that is down, had no way to
221
+ * remove the tool at all. Only what the install put on this computer is taken
222
+ * back: the sign in, the shell profile lines, the ~/.comprism folder, the program.
223
+ */
224
+ function removeHere() {
225
+ clearSignIn();
226
+ forgetLast();
227
+ const fence = /^# >>> comprism >>>[\s\S]*?^# <<< comprism <<<[^\n]*\n?/gm;
228
+ const home = os.homedir();
229
+ for (const f of ['.zshrc', '.bashrc', '.bash_profile', '.profile', '.config/fish/config.fish',
230
+ 'Documents/PowerShell/Microsoft.PowerShell_profile.ps1', 'Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1']) {
231
+ const file = path.join(home, f);
232
+ try {
233
+ const text = fs.readFileSync(file, 'utf8');
234
+ if (fence.test(text)) {
235
+ fs.writeFileSync(file, text.replace(fence, ''));
236
+ process.stdout.write(` removed our line from ${file}\n`);
237
+ }
238
+ }
239
+ catch { /* not there */ }
240
+ }
241
+ const kept = process.env.COMPRISM_HOME || path.join(home, '.comprism');
242
+ if (process.platform === 'win32') {
243
+ const bin = path.join(kept, 'bin');
244
+ cp.spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command',
245
+ `$b='${bin.replace(/'/g, "''")}'; $p=[Environment]::GetEnvironmentVariable('Path','User'); `
246
+ + `if ($p) { [Environment]::SetEnvironmentVariable('Path', (($p -split ';') | Where-Object { $_ -and $_ -ne $b }) -join ';', 'User') }`], { stdio: 'ignore' });
247
+ // Only our own program. Under npm or pip the running program is the
248
+ // person's Node or Python, which must never be touched.
249
+ if ((0, self_1.isStandalone)() && path.basename(process.execPath).toLowerCase() === 'comprism.exe') {
250
+ try {
251
+ fs.renameSync(process.execPath, path.join(os.tmpdir(), `comprism-removed-${process.pid}.exe`));
252
+ }
253
+ catch { /* removed below */ }
254
+ }
255
+ }
256
+ fs.rmSync(kept, { recursive: true, force: true });
257
+ process.stdout.write(` removed ${kept}\n`);
258
+ if (__dirname.includes('node_modules') && process.platform === 'win32') {
259
+ // Windows will not delete a running program's files, so the removal runs
260
+ // a moment after this process has exited.
261
+ cp.spawn('cmd.exe', ['/d', '/c', 'ping -n 3 127.0.0.1 >nul & npm.cmd uninstall -g @illuminis/comprism'], { detached: true, stdio: 'ignore', windowsHide: true }).unref();
262
+ process.stdout.write(' removing the comprism command\n');
263
+ }
264
+ else if (__dirname.includes('node_modules')) {
265
+ const npm = 'npm';
266
+ const done = cp.spawnSync(npm, ['uninstall', '-g', '@illuminis/comprism'], { stdio: 'ignore' });
267
+ process.stdout.write(done.status === 0 ? ' removed the comprism command\n' : ` could not remove the command itself; run: ${npm} uninstall -g @illuminis/comprism\n`);
268
+ }
269
+ const python = (0, self_1.isStandalone)() ? (0, self_1.pythonHere)() : null;
270
+ if (python) {
271
+ const done = cp.spawnSync(python, ['-m', 'pip', 'uninstall', '-y', 'comprism-cli'], { stdio: 'ignore' });
272
+ process.stdout.write(done.status === 0 ? ' removed the comprism command\n' : ` could not remove the command itself; run: ${python} -m pip uninstall comprism-cli\n`);
273
+ }
274
+ process.stdout.write(' CompletionPrism is removed from this computer.\n');
275
+ }
@@ -146,7 +146,7 @@ exports.STEPS = {
146
146
  }
147
147
  },
148
148
  /** How this copy of the tool was installed, and where things are on this computer. */
149
- self: () => ({ standalone: (0, self_1.isStandalone)(), method: (0, self_1.installMethod)(), pid: process.pid,
149
+ self: () => ({ standalone: (0, self_1.isStandalone)(), method: (0, self_1.installMethod)(), python: (0, self_1.pythonHere)(), pid: process.pid,
150
150
  platform: process.platform, home: (0, home_1.homeDir)(), user_home: os.homedir(), tmp: os.tmpdir() }),
151
151
  // ── files ─────────────────────────────────────────────────────────────────
152
152
  /** Write a file: `{path, text | base64, mode}`. */
package/out/cli-start.js CHANGED
@@ -55,13 +55,29 @@ const server_generated_1 = require("./server.generated");
55
55
  // This tool's own version, sent so the server can say when a newer one is out.
56
56
  const VERSION = require('../package.json').version;
57
57
  function main() {
58
- const card = signIn.readSignIn();
58
+ // This tool needs Node 22 or newer; on an older one it would fail silently.
59
+ if (Number(process.versions.node.split('.')[0]) < 22) {
60
+ process.stderr.write(` CompletionPrism needs Node 22 or newer, and this computer has ${process.versions.node}.\n Install the current Node from https://nodejs.org, then run comprism again.\n`);
61
+ process.exit(1);
62
+ }
63
+ let card = signIn.readSignIn();
64
+ if (process.argv[2] === 'uninstall' && !card?.workspaceKey) {
65
+ signIn.removeHere();
66
+ return;
67
+ }
59
68
  const server = (card?.url || server_generated_1.HOME_SERVER).replace(/\/+$/, '');
60
69
  // The line the server sends its orders for this computer down.
61
- const line = card?.workspaceKey
62
- ? (0, index_1.openLine)({ baseUrl: server, token: () => card.workspaceKey, client: 'terminal', ...(card.tenant ? { tenant: card.tenant } : {}),
63
- ...(process.env.COMPRISM_LINE_LOG ? { log: (l) => process.stderr.write(`[line] ${l}\n`) } : {}) })
64
- : null;
70
+ // Opened at start when signed in, or the moment a sign in is saved, so the
71
+ // session that follows signing in can reach this computer at once.
72
+ let line = null;
73
+ const openLineNow = () => {
74
+ if (line || !card?.workspaceKey)
75
+ return;
76
+ line = (0, index_1.openLine)({ baseUrl: (card.url || server).replace(/\/+$/, ''), token: () => card?.workspaceKey ?? '', client: 'terminal',
77
+ ...(card.tenant ? { tenant: card.tenant } : {}),
78
+ ...(process.env.COMPRISM_LINE_LOG ? { log: (l) => process.stderr.write(`[line] ${l}\n`) } : {}) });
79
+ };
80
+ openLineNow();
65
81
  // Keys and window changes go to whichever connection is open.
66
82
  let door;
67
83
  let ended = false;
@@ -77,6 +93,13 @@ function main() {
77
93
  // The front door: everything typed goes here, everything shown comes back.
78
94
  // If the server restarts mid session it is asked again once it answers.
79
95
  function connect() {
96
+ // Read again on every connection: a reconnect after a server restart must
97
+ // carry the sign in as it is now, not as it was when the tool started.
98
+ card = signIn.readSignIn();
99
+ if (process.argv[2] === 'uninstall' && !card?.workspaceKey) {
100
+ finish(0);
101
+ return;
102
+ }
80
103
  door = new WebSocket(`${server.replace(/^http/, 'ws')}/api/v1/front-door/terminal/live?client=terminal&client_version=${VERSION}`);
81
104
  door.binaryType = 'arraybuffer';
82
105
  door.onopen = () => {
@@ -93,8 +116,11 @@ function main() {
93
116
  return;
94
117
  }
95
118
  const said = JSON.parse(event.data);
96
- if (said.type === 'save_sign_in')
119
+ if (said.type === 'save_sign_in') {
97
120
  signIn.writeSignIn(said.value);
121
+ card = said.value;
122
+ openLineNow();
123
+ }
98
124
  else if (said.type === 'clear_sign_in')
99
125
  signIn.clearSignIn();
100
126
  else if (said.type === 'exit')
@@ -117,10 +143,18 @@ function main() {
117
143
  catch { /* not up yet */ }
118
144
  await new Promise((r) => setTimeout(r, 1000));
119
145
  }
146
+ if (process.argv[2] === 'uninstall') {
147
+ finish(0);
148
+ return;
149
+ }
120
150
  finish(1, `CompletionPrism could not be reached at ${server}.`);
121
151
  }
122
152
  function finish(code, message) {
123
153
  ended = true;
154
+ // The server's uninstall steps are done; what sits on this computer is
155
+ // removed here, where its real home folder and install are known.
156
+ if (process.argv[2] === 'uninstall' && code === 0 && !process.argv.includes('--keep-settings'))
157
+ signIn.removeHere();
124
158
  if (message)
125
159
  process.stderr.write(`${message}\n`);
126
160
  line?.stop();
@@ -2,5 +2,5 @@
2
2
  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
- exports.HOME_SERVER = "http://localhost:8009";
6
- exports.BUILD_COMMIT = "local";
5
+ exports.HOME_SERVER = "https://completionprism.illuminis.ai";
6
+ exports.BUILD_COMMIT = "a514f1a928469fc865ed0ccbcd971ed0c42ba85d";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@illuminis/comprism",
3
- "version": "2.4.2",
3
+ "version": "2.4.3",
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,
@@ -17,7 +17,8 @@
17
17
  "node": ">=22"
18
18
  },
19
19
  "scripts": {
20
- "build": "node scripts/write-server.mjs src/server.generated.ts && node scripts/sync-machine-services.mjs && tsc -p ./ && node scripts/build-native.mjs"
20
+ "build": "node scripts/write-server.mjs src/server.generated.ts && node scripts/sync-machine-services.mjs && tsc -p ./ && node scripts/build-native.mjs",
21
+ "prepack": "COMPRISM_RELEASE=${COMPRISM_RELEASE:-1} npm run build"
21
22
  },
22
23
  "devDependencies": {
23
24
  "@types/node": "24.12.2",