codex-to-im 1.0.21 → 1.0.22

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/dist/cli.mjs CHANGED
@@ -61,6 +61,7 @@ var uiStatusFile = path2.join(runtimeDir, "ui-server.json");
61
61
  var uiPort = 4781;
62
62
  var bridgeAutostartTaskName = "CodexToIMBridge";
63
63
  var bridgeAutostartLauncherFile = path2.join(runtimeDir, "bridge-autostart.ps1");
64
+ var npmUninstallLogFile = path2.join(runtimeDir, "npm-uninstall.log");
64
65
  var WINDOWS_HIDE = process.platform === "win32" ? { windowsHide: true } : {};
65
66
  function ensureDirs() {
66
67
  fs2.mkdirSync(runtimeDir, { recursive: true });
@@ -179,6 +180,68 @@ function ensureBridgeAutostartLauncher() {
179
180
  function parsePowerShellJson(raw) {
180
181
  return JSON.parse(raw);
181
182
  }
183
+ function buildDeferredGlobalNpmUninstallLaunch(options = {}) {
184
+ const packageName = options.packageName || "codex-to-im";
185
+ const logPath = options.logPath || npmUninstallLogFile;
186
+ const delayMs = options.delayMs ?? 1500;
187
+ const platform = options.platform || process.platform;
188
+ const npmCommand = options.npmCommand || (platform === "win32" ? "npm.cmd" : "npm");
189
+ const command = options.nodePath || process.execPath;
190
+ const cwd = options.cwd || os2.homedir();
191
+ const script = [
192
+ "const { spawn } = require('node:child_process');",
193
+ "const fs = require('node:fs');",
194
+ `const logPath = ${JSON.stringify(logPath)};`,
195
+ `const npmCommand = ${JSON.stringify(npmCommand)};`,
196
+ `const npmArgs = ['uninstall', '-g', ${JSON.stringify(packageName)}];`,
197
+ `const childCwd = ${JSON.stringify(cwd)};`,
198
+ `const delayMs = ${JSON.stringify(delayMs)};`,
199
+ "const writeLog = (message) => {",
200
+ " try { fs.appendFileSync(logPath, String(message).endsWith('\\n') ? String(message) : String(message) + '\\n'); } catch {}",
201
+ "};",
202
+ "setTimeout(() => {",
203
+ " let fd;",
204
+ " try { fd = fs.openSync(logPath, 'a'); } catch (error) { writeLog(error); process.exit(1); return; }",
205
+ " const child = spawn(npmCommand, npmArgs, { cwd: childCwd, detached: false, stdio: ['ignore', fd, fd], windowsHide: true });",
206
+ " child.on('error', (error) => { writeLog(error); process.exit(1); });",
207
+ " child.on('close', (code) => { process.exit(typeof code === 'number' ? code : 0); });",
208
+ "}, delayMs);"
209
+ ].join("\n");
210
+ return {
211
+ command,
212
+ args: ["-e", script],
213
+ npmCommand,
214
+ logPath,
215
+ delayMs
216
+ };
217
+ }
218
+ async function launchDeferredGlobalNpmUninstall() {
219
+ ensureDirs();
220
+ const launch = buildDeferredGlobalNpmUninstallLaunch();
221
+ fs2.writeFileSync(
222
+ launch.logPath,
223
+ [
224
+ `[${(/* @__PURE__ */ new Date()).toISOString()}] Scheduling global uninstall.`,
225
+ `${launch.npmCommand} uninstall -g codex-to-im`,
226
+ ""
227
+ ].join("\n"),
228
+ "utf-8"
229
+ );
230
+ await new Promise((resolve, reject) => {
231
+ const child = spawn(launch.command, launch.args, {
232
+ cwd: os2.homedir(),
233
+ detached: true,
234
+ stdio: "ignore",
235
+ ...WINDOWS_HIDE
236
+ });
237
+ child.once("error", reject);
238
+ child.once("spawn", () => {
239
+ child.unref();
240
+ resolve();
241
+ });
242
+ });
243
+ return launch;
244
+ }
182
245
  function getUiServerUrl(port = uiPort) {
183
246
  return `http://127.0.0.1:${port}`;
184
247
  }
@@ -396,6 +459,27 @@ async function uninstallBridgeAutostart() {
396
459
  }
397
460
  return await getBridgeAutostartStatus();
398
461
  }
462
+ async function uninstallCodexToImPackage() {
463
+ const autostartBefore = await getBridgeAutostartStatus();
464
+ if (process.platform === "win32" && autostartBefore.installed) {
465
+ await ensureWindowsAdminSession();
466
+ }
467
+ const ui = await stopUiServer();
468
+ const bridge = await stopBridge();
469
+ const autostart = autostartBefore.installed ? await uninstallBridgeAutostart() : autostartBefore;
470
+ if (autostart.installed) {
471
+ throw new Error(`\u672A\u80FD\u5220\u9664\u5F00\u673A\u81EA\u542F\u52A8\u4EFB\u52A1 ${autostart.taskName}\uFF0C\u5DF2\u53D6\u6D88 npm \u5168\u5C40\u5378\u8F7D\u3002`);
472
+ }
473
+ const launch = await launchDeferredGlobalNpmUninstall();
474
+ return {
475
+ ui,
476
+ bridge,
477
+ autostart,
478
+ npmCommand: launch.npmCommand,
479
+ logPath: launch.logPath,
480
+ scheduled: true
481
+ };
482
+ }
399
483
  async function ensureUiServerRunning() {
400
484
  ensureDirs();
401
485
  const current = getUiServerStatus();
@@ -573,6 +657,19 @@ async function main() {
573
657
  );
574
658
  return;
575
659
  }
660
+ case "uninstall": {
661
+ const result = await uninstallCodexToImPackage();
662
+ process.stdout.write(
663
+ [
664
+ `Stopped services. UI running=${result.ui.running ? "yes" : "no"}, Bridge running=${result.bridge.running ? "yes" : "no"}`,
665
+ result.autostart.installed ? `Bridge autostart still installed: ${result.autostart.taskName}` : "Bridge autostart removed.",
666
+ `Global npm uninstall scheduled via ${result.npmCommand}.`,
667
+ `Log: ${result.logPath}`,
668
+ "\u5F53\u524D\u547D\u4EE4\u9000\u51FA\u540E\uFF0C\u540E\u53F0\u4F1A\u7EE7\u7EED\u6267\u884C\u5168\u5C40\u5378\u8F7D\u3002"
669
+ ].join("\n") + "\n"
670
+ );
671
+ return;
672
+ }
576
673
  case "status": {
577
674
  const ui = getUiServerStatus();
578
675
  const bridge = getBridgeStatus();
@@ -607,6 +704,7 @@ async function main() {
607
704
  return;
608
705
  }
609
706
  case "install": {
707
+ await ensureWindowsAdminSession();
610
708
  const password = await promptHidden("\u8BF7\u8F93\u5165\u5F53\u524D Windows \u767B\u5F55\u5BC6\u7801\uFF08\u7528\u4E8E\u521B\u5EFA\u5F00\u673A\u542F\u52A8\u4EFB\u52A1\uFF09: ");
611
709
  const status = await installBridgeAutostart(password);
612
710
  process.stdout.write(`Bridge autostart installed. Task: ${status.taskName}
@@ -627,7 +725,7 @@ async function main() {
627
725
  }
628
726
  }
629
727
  default:
630
- process.stdout.write("Usage: codex-to-im [start|open|url|stop|status|autostart]\n");
728
+ process.stdout.write("Usage: codex-to-im [start|open|url|stop|status|autostart|uninstall]\n");
631
729
  }
632
730
  }
633
731
  main().catch((error) => {
@@ -5949,6 +5949,7 @@ var uiStatusFile = path5.join(runtimeDir, "ui-server.json");
5949
5949
  var uiPort = 4781;
5950
5950
  var bridgeAutostartTaskName = "CodexToIMBridge";
5951
5951
  var bridgeAutostartLauncherFile = path5.join(runtimeDir, "bridge-autostart.ps1");
5952
+ var npmUninstallLogFile = path5.join(runtimeDir, "npm-uninstall.log");
5952
5953
  var WINDOWS_HIDE = process.platform === "win32" ? { windowsHide: true } : {};
5953
5954
  function ensureDirs() {
5954
5955
  fs4.mkdirSync(runtimeDir, { recursive: true });
@@ -10883,9 +10884,6 @@ function renderHtml() {
10883
10884
  showMessage('opsMessage', 'error', error.message);
10884
10885
  });
10885
10886
 
10886
- setInterval(() => {
10887
- loadBindings().catch(() => {});
10888
- }, 4000);
10889
10887
  </script>
10890
10888
  </body>
10891
10889
  </html>`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-to-im",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "description": "Installable Codex-to-IM bridge with local setup UI and background service",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/zhangle1987/codex-to-im#readme",