@duanluan/codex-plus-plus-launcher 1.2.19 → 1.2.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/npm/launcher.js CHANGED
@@ -402,6 +402,39 @@ function findRunningSidecarProcesses(options = {}) {
402
402
  }
403
403
  }
404
404
 
405
+ function findRunningCodexPlusManagerProcesses(options = {}) {
406
+ const platform = optionValue(options, 'platform', process.platform);
407
+ if (platform !== 'win32') {
408
+ return [];
409
+ }
410
+ if (typeof options.findRunningCodexPlusManagerProcesses === 'function') {
411
+ return options.findRunningCodexPlusManagerProcesses(options) || [];
412
+ }
413
+
414
+ const run = options.processSpawnSync || (options.spawnSync ? null : spawnSync);
415
+ if (!run) {
416
+ return [];
417
+ }
418
+ const script = [
419
+ '$ErrorActionPreference = "SilentlyContinue"',
420
+ 'Get-CimInstance Win32_Process | Where-Object {',
421
+ ' $_.Name -ieq "codex-plus-plus-manager.exe"',
422
+ '} | Select-Object ProcessId,Name,ExecutablePath,CommandLine | ConvertTo-Json -Compress',
423
+ ].join('\n');
424
+ const result = run('powershell.exe', ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', script], {
425
+ encoding: 'utf8',
426
+ windowsHide: true,
427
+ });
428
+ if (!result || result.status !== 0) {
429
+ return [];
430
+ }
431
+ try {
432
+ return parsePowerShellJson(result.stdout);
433
+ } catch (_error) {
434
+ return [];
435
+ }
436
+ }
437
+
405
438
  function cdpTargetsAvailable(debugPort, options = {}) {
406
439
  if (typeof options.cdpTargetsAvailable === 'function') {
407
440
  return options.cdpTargetsAvailable(debugPort, options);
@@ -777,6 +810,22 @@ function preflightWindowsCodexLaunch(args = [], options = {}) {
777
810
  const requestedDebugPort = launchDebugPort(args);
778
811
  const runningDebugPorts = codexProcessDebugPorts(processes);
779
812
  const portsToCheck = runningDebugPorts.length > 0 ? runningDebugPorts : [requestedDebugPort];
813
+ if (runningDebugPorts.length === 0) {
814
+ const terminate = options.terminateProcesses || terminateProcesses;
815
+ terminate(processes, options);
816
+ const sidecars = findRunningSidecarProcesses(options);
817
+ if (sidecars.length > 0) {
818
+ terminate(sidecars, options);
819
+ } else {
820
+ terminateSidecarsByImageName(options);
821
+ }
822
+ return {
823
+ action: 'terminated_codex_for_missing_cdp',
824
+ debugPort: requestedDebugPort,
825
+ processCount: processes.length,
826
+ sidecarCount: sidecars.length,
827
+ };
828
+ }
780
829
  if (runningDebugPorts.length > 0) {
781
830
  const availableDebugPort = portsToCheck.find((debugPort) => cdpTargetsAvailable(debugPort, options));
782
831
  if (availableDebugPort) {
@@ -1038,9 +1087,8 @@ async function installSidecars(options = {}) {
1038
1087
  return installed;
1039
1088
  }
1040
1089
 
1041
- function readInstalledSidecarVersion(options = {}) {
1090
+ function readInstalledSidecarStampVersion(options = {}) {
1042
1091
  const fsImpl = options.fs || fs;
1043
- const platform = optionValue(options, 'platform', process.platform);
1044
1092
  const installRoot = optionValue(options, 'installRoot', () => detectedInstallRoot(options));
1045
1093
  const stampPath = path.join(installRoot, SIDECAR_VERSION_STAMP);
1046
1094
  try {
@@ -1050,21 +1098,25 @@ function readInstalledSidecarVersion(options = {}) {
1050
1098
  return first;
1051
1099
  }
1052
1100
  } catch (_error) {
1053
- // stamp absent or unreadable; fall through to platform probe
1054
- }
1055
- if (platform !== 'win32') {
1056
- return null;
1101
+ // stamp absent or unreadable
1057
1102
  }
1103
+ return null;
1104
+ }
1105
+
1106
+ function readWindowsSidecarBinaryVersion(options = {}) {
1107
+ const fsImpl = options.fs || fs;
1108
+ const installRoot = optionValue(options, 'installRoot', () => detectedInstallRoot(options));
1058
1109
  const silent = installedSidecarPath('silent', { ...options, installRoot });
1059
1110
  if (!fsImpl.existsSync(silent)) {
1060
1111
  return null;
1061
1112
  }
1062
1113
  const run = options.spawnSync || spawnSync;
1063
1114
  try {
1115
+ const env = { ...(options.env || process.env), CODEXPP_VERSION_PROBE_PATH: silent };
1064
1116
  const result = run(
1065
- 'powershell',
1066
- ['-NoProfile', '-NonInteractive', '-Command', '(Get-Item -LiteralPath $args[0]).VersionInfo.FileVersion', '--', silent],
1067
- { encoding: 'utf8', windowsHide: true },
1117
+ 'powershell.exe',
1118
+ ['-NoProfile', '-NonInteractive', '-Command', '(Get-Item -LiteralPath $env:CODEXPP_VERSION_PROBE_PATH).VersionInfo.FileVersion'],
1119
+ { encoding: 'utf8', env, windowsHide: true },
1068
1120
  );
1069
1121
  if (result && result.status === 0) {
1070
1122
  const out = String(result.stdout || '').trim();
@@ -1078,6 +1130,14 @@ function readInstalledSidecarVersion(options = {}) {
1078
1130
  return null;
1079
1131
  }
1080
1132
 
1133
+ function readInstalledSidecarVersion(options = {}) {
1134
+ const platform = optionValue(options, 'platform', process.platform);
1135
+ if (platform !== 'win32') {
1136
+ return readInstalledSidecarStampVersion(options);
1137
+ }
1138
+ return readWindowsSidecarBinaryVersion(options) || readInstalledSidecarStampVersion(options);
1139
+ }
1140
+
1081
1141
  function computeSidecarDrift(options = {}) {
1082
1142
  const platform = optionValue(options, 'platform', process.platform);
1083
1143
  const arch = optionValue(options, 'arch', process.arch);
@@ -1098,6 +1158,38 @@ function computeSidecarDrift(options = {}) {
1098
1158
  return installed === bundled ? 'none' : 'mismatch';
1099
1159
  }
1100
1160
 
1161
+ function stopCodexPlusProcesses(options = {}) {
1162
+ const platform = optionValue(options, 'platform', process.platform);
1163
+ if (platform !== 'win32') {
1164
+ return { status: 1, error: new Error('cxpp stop is only supported on Windows in this package') };
1165
+ }
1166
+ const sidecars = findRunningSidecarProcesses(options);
1167
+ const managers = findRunningCodexPlusManagerProcesses(options);
1168
+ const codex = findRunningCodexProcesses(options);
1169
+ const targets = [...sidecars, ...managers, ...codex];
1170
+ const uniqueTargets = [];
1171
+ const seen = new Set();
1172
+ for (const target of targets) {
1173
+ const id = Number(target && target.ProcessId);
1174
+ if (!Number.isInteger(id) || id <= 0 || seen.has(id)) {
1175
+ continue;
1176
+ }
1177
+ seen.add(id);
1178
+ uniqueTargets.push(target);
1179
+ }
1180
+ if (uniqueTargets.length > 0) {
1181
+ const terminate = options.terminateProcesses || terminateProcesses;
1182
+ terminate(uniqueTargets, options);
1183
+ }
1184
+ return {
1185
+ status: 0,
1186
+ stoppedCount: uniqueTargets.length,
1187
+ sidecarCount: sidecars.length,
1188
+ managerCount: managers.length,
1189
+ codexCount: codex.length,
1190
+ };
1191
+ }
1192
+
1101
1193
  async function ensureSidecarsFresh(options = {}) {
1102
1194
  const drift = computeSidecarDrift(options);
1103
1195
  if (drift === 'none' || drift === 'unsupported') {
@@ -1833,17 +1925,23 @@ function doctorReport(options = {}) {
1833
1925
  const sidecars = installedSidecars(options);
1834
1926
  const entrypoints = inspectEntrypoints(options);
1835
1927
  const supported = SUPPORTED_PLATFORMS.has(platformKey(platform, arch));
1928
+ const installedVersion = readInstalledSidecarVersion({ ...options, installRoot });
1929
+ const expectedVersion = packageVersion(options);
1930
+ const drift = computeSidecarDrift(options);
1836
1931
  const report = {
1837
1932
  platform,
1838
1933
  arch,
1839
1934
  supported: supported ? 'yes' : 'no',
1840
- package_version: packageVersion(options),
1935
+ package_version: expectedVersion,
1841
1936
  upstream_version: bundledUpstreamVersion(options) || 'missing',
1842
1937
  upstream_commit: upstreamMetadata(options).commit || 'missing',
1843
1938
  sidecar_dir: upstreamBinDir(options),
1844
1939
  install_root: installRoot,
1845
1940
  silent_binary: sidecars.silent,
1846
1941
  silent_binary_state: sidecars.silent_state,
1942
+ expected_sidecar_version: expectedVersion,
1943
+ installed_sidecar_version: installedVersion || 'missing',
1944
+ sidecar_drift: drift,
1847
1945
  manager_binary: sidecars.manager,
1848
1946
  manager_binary_state: sidecars.manager_state,
1849
1947
  silent_entrypoint_state: entrypoints.silent,
@@ -1946,6 +2044,7 @@ Usage:
1946
2044
  cxpp manager Open Codex++ manager
1947
2045
  cxpp install-app Install or repair local entrypoints
1948
2046
  cxpp repair-app Alias of install-app
2047
+ cxpp stop Stop running Codex++ and Codex processes
1949
2048
  cxpp doctor [--json] Inspect local state
1950
2049
  cxpp version Print wrapper version
1951
2050
  `);
@@ -1964,6 +2063,17 @@ async function runLauncher(args = [], options = {}) {
1964
2063
  if (command === 'doctor') {
1965
2064
  return { status: printDoctor(args.includes('--json'), options) };
1966
2065
  }
2066
+ if (command === 'stop') {
2067
+ const result = stopCodexPlusProcesses(options);
2068
+ if (result.error) {
2069
+ return result;
2070
+ }
2071
+ console.log(`stopped_processes=${result.stoppedCount}`);
2072
+ console.log(`sidecar_processes=${result.sidecarCount}`);
2073
+ console.log(`manager_processes=${result.managerCount}`);
2074
+ console.log(`codex_processes=${result.codexCount}`);
2075
+ return result;
2076
+ }
1967
2077
  if (command === 'install-app' || command === 'repair-app' || command === 'setup' || command === 'repair' || command === 'npm-postinstall') {
1968
2078
  const supported = SUPPORTED_PLATFORMS.has(platformKey(optionValue(options, 'platform', process.platform), optionValue(options, 'arch', process.arch)));
1969
2079
  if (!supported) {
@@ -2047,9 +2157,12 @@ module.exports = {
2047
2157
  sidecarArgsWithDebugPort,
2048
2158
  promptYesNoWindowsPopup,
2049
2159
  readInstalledSidecarVersion,
2160
+ readInstalledSidecarStampVersion,
2161
+ readWindowsSidecarBinaryVersion,
2050
2162
  removePath,
2051
2163
  runLauncher,
2052
2164
  spawnSidecar,
2165
+ stopCodexPlusProcesses,
2053
2166
  terminateProcesses,
2054
2167
  terminateSidecarsByImageName,
2055
2168
  upstreamBinDir,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duanluan/codex-plus-plus-launcher",
3
- "version": "1.2.19",
3
+ "version": "1.2.22",
4
4
  "description": "Install and launch Codex++ from npm",
5
5
  "bin": {
6
6
  "cxpp": "npm/cxpp.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "upstream_version": "v1.2.15",
3
- "package_version": "1.2.19",
3
+ "package_version": "1.2.22",
4
4
  "ref": "v1.2.15",
5
5
  "version": "v1.2.15",
6
6
  "commit": "324a350d00376d4f9565aeeae3c8820b0cbbbe2a",