ai-project-manage-cli 6.0.97 → 6.0.98

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.
Files changed (2) hide show
  1. package/dist/index.js +92 -24
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3829,10 +3829,18 @@ function forceReleaseConnectLock() {
3829
3829
  // src/commands/daemon.ts
3830
3830
  import { spawnSync as spawnSync2 } from "child_process";
3831
3831
  import { setTimeout as delay } from "node:timers/promises";
3832
- import { existsSync as existsSync14, mkdirSync as mkdirSync7, writeFileSync as writeFileSync13 } from "fs";
3832
+ import { existsSync as existsSync14, mkdirSync as mkdirSync7, unlinkSync as unlinkSync2, writeFileSync as writeFileSync13 } from "fs";
3833
3833
  import { join as join15 } from "path";
3834
3834
  var PM2_APP_NAME = "apm-connect";
3835
- var PM2_ECOSYSTEM_PATH = join15(APM_CONFIG_DIR, "connect.ecosystem.cjs");
3835
+ var PM2_ECOSYSTEM_PATH = join15(
3836
+ APM_CONFIG_DIR,
3837
+ "connect.ecosystem.config.cjs"
3838
+ );
3839
+ var LEGACY_PM2_ECOSYSTEM_PATH = join15(
3840
+ APM_CONFIG_DIR,
3841
+ "connect.ecosystem.cjs"
3842
+ );
3843
+ var LEGACY_PM2_APP_NAMES = ["connect.ecosystem"];
3836
3844
  function resolveConnectArgs(server) {
3837
3845
  const args = ["connect"];
3838
3846
  const trimmed = server?.trim();
@@ -4033,7 +4041,57 @@ function resolveApmEntryPath(entryArg = process.argv[1]) {
4033
4041
  process.exit(1);
4034
4042
  }
4035
4043
  function isRunningUnderPm2() {
4036
- return process.env.name === PM2_APP_NAME && process.env.pm_id !== void 0;
4044
+ if (process.env.pm_id === void 0) {
4045
+ return false;
4046
+ }
4047
+ const name = process.env.name;
4048
+ return name === PM2_APP_NAME || name !== void 0 && LEGACY_PM2_APP_NAMES.includes(name);
4049
+ }
4050
+ function isConnectPm2Process(app) {
4051
+ if (app.name === PM2_APP_NAME) {
4052
+ return true;
4053
+ }
4054
+ return app.name !== void 0 && LEGACY_PM2_APP_NAMES.includes(app.name);
4055
+ }
4056
+ function listPm2Processes() {
4057
+ try {
4058
+ const raw = runPm2Json(["jlist"]);
4059
+ return JSON.parse(raw);
4060
+ } catch {
4061
+ return [];
4062
+ }
4063
+ }
4064
+ function findPm2ConnectProcess() {
4065
+ return listPm2Processes().find(isConnectPm2Process) ?? null;
4066
+ }
4067
+ function resolvePm2ConnectName(app) {
4068
+ return app?.name ?? PM2_APP_NAME;
4069
+ }
4070
+ function deletePm2AppIfExists(name) {
4071
+ const pm2Bin = findGlobalPm2();
4072
+ if (!pm2Bin) {
4073
+ return;
4074
+ }
4075
+ ensurePm2DaemonUpdated(pm2Bin);
4076
+ spawnSync2(pm2Bin, ["delete", name], {
4077
+ encoding: "utf8",
4078
+ shell: useNpmShell2,
4079
+ stdio: "ignore"
4080
+ });
4081
+ }
4082
+ function removePm2ConnectProcesses() {
4083
+ const seen = /* @__PURE__ */ new Set();
4084
+ for (const app of listPm2Processes()) {
4085
+ if (!isConnectPm2Process(app) || !app.name || seen.has(app.name)) {
4086
+ continue;
4087
+ }
4088
+ seen.add(app.name);
4089
+ deletePm2AppIfExists(app.name);
4090
+ }
4091
+ for (const legacyName of LEGACY_PM2_APP_NAMES) {
4092
+ deletePm2AppIfExists(legacyName);
4093
+ }
4094
+ deletePm2AppIfExists(PM2_APP_NAME);
4037
4095
  }
4038
4096
  function runPm2(args, options) {
4039
4097
  const pm2Bin = ensureGlobalPm2({ quiet: true });
@@ -4075,15 +4133,6 @@ function isPm2ConnectOnline() {
4075
4133
  const status = app.pm2_env?.status;
4076
4134
  return status === "online" || status === "launching";
4077
4135
  }
4078
- function findPm2ConnectProcess() {
4079
- try {
4080
- const raw = runPm2Json(["jlist"]);
4081
- const list = JSON.parse(raw);
4082
- return list.find((app) => app.name === PM2_APP_NAME) ?? null;
4083
- } catch {
4084
- return null;
4085
- }
4086
- }
4087
4136
  function printConnectNotRunningHint() {
4088
4137
  console.log(`[apm] ${PM2_APP_NAME} \u672A\u5728\u8FD0\u884C`);
4089
4138
  console.log("[apm] \u542F\u52A8\u5B88\u62A4: apm connect --daemon");
@@ -4151,6 +4200,12 @@ function writeEcosystemFile(options) {
4151
4200
  formatConnectPm2EcosystemFile(ecosystem),
4152
4201
  "utf8"
4153
4202
  );
4203
+ if (existsSync14(LEGACY_PM2_ECOSYSTEM_PATH)) {
4204
+ try {
4205
+ unlinkSync2(LEGACY_PM2_ECOSYSTEM_PATH);
4206
+ } catch {
4207
+ }
4208
+ }
4154
4209
  }
4155
4210
  async function prepareEcosystem(server) {
4156
4211
  await ensureLoggedConfig();
@@ -4171,7 +4226,14 @@ async function runDaemonStart(options) {
4171
4226
  await runUpdate();
4172
4227
  ensureGlobalPm2();
4173
4228
  const cfg = await prepareEcosystem(options.server);
4229
+ removePm2ConnectProcesses();
4174
4230
  runPm2(["start", PM2_ECOSYSTEM_PATH, "--update-env"], { inherit: true });
4231
+ await delay(1e3);
4232
+ if (!isPm2ConnectOnline()) {
4233
+ console.error(
4234
+ `[apm] ${PM2_APP_NAME} \u542F\u52A8\u540E\u672A\u5904\u4E8E online \u72B6\u6001\uFF0C\u8BF7\u6267\u884C: apm daemon logs -n 200`
4235
+ );
4236
+ }
4175
4237
  console.log(
4176
4238
  `[apm] ${PM2_APP_NAME} \u5DF2\u7531 PM2 \u542F\u52A8\uFF08server=${options.server?.trim() || cfg.baseUrl}\uFF09`
4177
4239
  );
@@ -4194,14 +4256,18 @@ async function runDaemonStop() {
4194
4256
  console.log(`[apm] ${PM2_APP_NAME} \u672A\u5728\u8FD0\u884C`);
4195
4257
  return;
4196
4258
  }
4197
- runPm2(["stop", PM2_APP_NAME], { inherit: true });
4259
+ runPm2(["stop", resolvePm2ConnectName(findPm2ConnectProcess())], {
4260
+ inherit: true
4261
+ });
4198
4262
  for (let i = 0; i < 10; i += 1) {
4199
4263
  if (!isPm2ConnectOnline()) break;
4200
4264
  await delay(500);
4201
4265
  }
4202
4266
  if (isPm2ConnectOnline()) {
4203
4267
  console.log(`[apm] \u4F18\u96C5\u505C\u6B62\u8D85\u65F6\uFF0C\u5F3A\u5236\u79FB\u9664 ${PM2_APP_NAME}\u2026`);
4204
- runPm2(["delete", PM2_APP_NAME], { inherit: true });
4268
+ runPm2(["delete", resolvePm2ConnectName(findPm2ConnectProcess())], {
4269
+ inherit: true
4270
+ });
4205
4271
  }
4206
4272
  killConnectLockProcessIfAlive();
4207
4273
  forceReleaseConnectLock();
@@ -4236,36 +4302,38 @@ async function runDaemonRestart(options) {
4236
4302
  }
4237
4303
  await runUpdate();
4238
4304
  await prepareEcosystem(options.server);
4239
- runPm2(["startOrRestart", PM2_ECOSYSTEM_PATH, "--update-env"], {
4240
- inherit: true
4241
- });
4305
+ removePm2ConnectProcesses();
4306
+ runPm2(["start", PM2_ECOSYSTEM_PATH, "--update-env"], { inherit: true });
4242
4307
  console.log(`[apm] ${PM2_APP_NAME} \u5DF2\u91CD\u542F`);
4243
4308
  }
4244
4309
  async function runDaemonDelete() {
4245
4310
  ensureGlobalPm2();
4246
- if (!findPm2ConnectProcess()) {
4311
+ const app = findPm2ConnectProcess();
4312
+ if (!app?.name) {
4247
4313
  console.log(`[apm] ${PM2_APP_NAME} \u672A\u5728 PM2 \u4E2D\u6CE8\u518C`);
4248
4314
  return;
4249
4315
  }
4250
- runPm2(["delete", PM2_APP_NAME], { inherit: true });
4316
+ runPm2(["delete", app.name], { inherit: true });
4251
4317
  forceReleaseConnectLock();
4252
- console.log(`[apm] ${PM2_APP_NAME} \u5DF2\u4ECE PM2 \u79FB\u9664`);
4318
+ console.log(`[apm] ${app.name} \u5DF2\u4ECE PM2 \u79FB\u9664`);
4253
4319
  }
4254
4320
  async function runDaemonStatus() {
4255
4321
  ensureGlobalPm2();
4256
- if (!findPm2ConnectProcess()) {
4322
+ const app = findPm2ConnectProcess();
4323
+ if (!app?.name) {
4257
4324
  printConnectNotRunningHint();
4258
4325
  return;
4259
4326
  }
4260
- runPm2(["describe", PM2_APP_NAME], { inherit: true });
4327
+ runPm2(["describe", app.name], { inherit: true });
4261
4328
  }
4262
4329
  async function runDaemonLogs(options) {
4263
4330
  ensureGlobalPm2();
4264
- if (!findPm2ConnectProcess()) {
4331
+ const app = findPm2ConnectProcess();
4332
+ if (!app?.name) {
4265
4333
  printConnectNotRunningHint();
4266
4334
  return;
4267
4335
  }
4268
- const args = ["logs", PM2_APP_NAME, "--lines", String(options.lines ?? 100)];
4336
+ const args = ["logs", app.name, "--lines", String(options.lines ?? 100)];
4269
4337
  if (!options.follow) {
4270
4338
  args.push("--nostream");
4271
4339
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-project-manage-cli",
3
- "version": "6.0.97",
3
+ "version": "6.0.98",
4
4
  "description": "命令行工具:后续用于调用平台后端 API 完成运维与自动化操作",
5
5
  "type": "module",
6
6
  "private": false,