ai-project-manage-cli 6.0.45 → 6.0.47

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 +63 -19
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -384,24 +384,63 @@ function createApmApiClient(cfg) {
384
384
  });
385
385
  }
386
386
 
387
+ // src/git-remote.ts
388
+ import { execFile } from "child_process";
389
+ import { promisify } from "util";
390
+ var execFileAsync = promisify(execFile);
391
+ async function tryReadGitOriginUrl(cwd) {
392
+ try {
393
+ const { stdout } = await execFileAsync(
394
+ "git",
395
+ ["config", "--get", "remote.origin.url"],
396
+ { cwd, encoding: "utf8", maxBuffer: 1024 * 1024 }
397
+ );
398
+ const url = stdout.trim();
399
+ return url || null;
400
+ } catch {
401
+ return null;
402
+ }
403
+ }
404
+
387
405
  // src/deployment-config-sync.ts
406
+ var TEMPLATE_HINT = "\u4FDD\u7559\u6A21\u677F .apm/apm.config.json \u4E0E .apm/deploy/README.md";
388
407
  var SYNC_HINT = "\u767B\u8BB0\u5DE5\u4F5C\u7A7A\u95F4\u8DEF\u5F84\u3001\u7ED1\u5B9A\u4ED3\u5E93\u540E\uFF0C\u53EF\u6267\u884C: apm sync-deploy-config";
408
+ async function resolveRepositoryIdForSync(api, workdirPath) {
409
+ const baseline = await api.cli.workspaceBaseline({ workdirPath });
410
+ if (baseline.repositoryId) {
411
+ return { repositoryId: baseline.repositoryId, diagnostic: null };
412
+ }
413
+ const gitUrl = await tryReadGitOriginUrl(workdirPath);
414
+ if (gitUrl) {
415
+ const matched = await api.cli.matchRepository({ url: gitUrl });
416
+ if (matched.repositoryId) {
417
+ console.log(
418
+ `[apm] \u5DE5\u4F5C\u7A7A\u95F4\u8DEF\u5F84\u672A\u5339\u914D\uFF0C\u5DF2\u901A\u8FC7 git remote \u5173\u8054\u4ED3\u5E93: ${gitUrl}`
419
+ );
420
+ return { repositoryId: matched.repositoryId, diagnostic: null };
421
+ }
422
+ }
423
+ const detail = baseline.diagnostic?.message ?? `\u5F53\u524D\u8DEF\u5F84\uFF08\u89C4\u8303\u5316\uFF1A${baseline.workdirPath}\uFF09\u672A\u5339\u914D\u5230\u5DF2\u7ED1\u5B9A\u4ED3\u5E93\u7684\u5DE5\u4F5C\u7A7A\u95F4\u3002`;
424
+ return { repositoryId: null, diagnostic: detail };
425
+ }
389
426
  async function syncRemoteDeploymentConfig(workdirPath, apmDir) {
390
427
  const cfg = await tryReadApmConfig();
391
428
  if (!cfg || !resolveApiKey(cfg)) {
392
429
  console.log(
393
- "[apm] \u672A\u68C0\u6D4B\u5230\u767B\u5F55\u4FE1\u606F\uFF0C\u8DF3\u8FC7\u5E73\u53F0\u90E8\u7F72\u914D\u7F6E\u540C\u6B65\uFF08\u4FDD\u7559\u6A21\u677F apm.config.json\uFF09\u3002\n[apm] \u8BF7\u5148\u6267\u884C apm login\uFF0C\u518D\u6267\u884C apm sync-deploy-config \u62C9\u53D6\u6700\u65B0\u914D\u7F6E\u3002"
430
+ `[apm] \u672A\u68C0\u6D4B\u5230\u767B\u5F55\u4FE1\u606F\uFF0C\u8DF3\u8FC7\u5E73\u53F0\u90E8\u7F72\u914D\u7F6E\u540C\u6B65\uFF08${TEMPLATE_HINT}\uFF09\u3002
431
+ [apm] \u8BF7\u5148\u6267\u884C apm login\uFF0C\u518D\u6267\u884C apm sync-deploy-config \u62C9\u53D6\u6700\u65B0\u914D\u7F6E\u3002`
394
432
  );
395
433
  return { synced: false, repositoryId: null };
396
434
  }
397
435
  const api = createApmApiClient(cfg);
398
- const baseline = await api.cli.workspaceBaseline({ workdirPath });
399
- const repositoryId = baseline.repositoryId;
436
+ const { repositoryId, diagnostic } = await resolveRepositoryIdForSync(
437
+ api,
438
+ workdirPath
439
+ );
400
440
  if (!repositoryId) {
401
- const detail = baseline.diagnostic?.message ?? `\u5F53\u524D\u8DEF\u5F84\uFF08\u89C4\u8303\u5316\uFF1A${baseline.workdirPath}\uFF09\u672A\u5339\u914D\u5230\u5DF2\u7ED1\u5B9A\u4ED3\u5E93\u7684\u5DE5\u4F5C\u7A7A\u95F4\u3002`;
402
441
  console.log(
403
- `[apm] \u672A\u80FD\u540C\u6B65\u5E73\u53F0\u90E8\u7F72\u914D\u7F6E\uFF0C\u4FDD\u7559\u6A21\u677F apm.config.json\u3002
404
- ${detail}
442
+ `[apm] \u672A\u80FD\u540C\u6B65\u5E73\u53F0\u90E8\u7F72\u914D\u7F6E\uFF08${TEMPLATE_HINT}\uFF09\u3002
443
+ ${diagnostic ?? ""}
405
444
  [apm] ${SYNC_HINT}`
406
445
  );
407
446
  return { synced: false, repositoryId: null };
@@ -409,7 +448,7 @@ ${detail}
409
448
  const { config } = await api.cli.getDeploymentConfiguration({ repositoryId });
410
449
  if (!config) {
411
450
  console.log(
412
- `[apm] \u672A\u627E\u5230\u5173\u8054\u4ED3\u5E93\u7684\u90E8\u7F72\u914D\u7F6E\uFF0C\u4FDD\u7559\u6A21\u677F apm.config.json\uFF08repositoryId\uFF1A${repositoryId}\uFF09\u3002
451
+ `[apm] \u672A\u627E\u5230\u5173\u8054\u4ED3\u5E93\u7684\u90E8\u7F72\u914D\u7F6E\uFF08${TEMPLATE_HINT}\uFF0CrepositoryId\uFF1A${repositoryId}\uFF09\u3002
413
452
  [apm] \u8BF7\u5728\u5E73\u53F0\u300C\u90E8\u7F72\u914D\u7F6E\u300D\u4E2D\u521B\u5EFA\u914D\u7F6E\u5E76\u5173\u8054\u8BE5\u4ED3\u5E93\uFF0C\u7136\u540E\u6267\u884C: apm sync-deploy-config`
414
453
  );
415
454
  return { synced: false, repositoryId };
@@ -419,7 +458,7 @@ ${detail}
419
458
  parsed = JSON.parse(config.content);
420
459
  } catch {
421
460
  console.warn(
422
- `[apm] \u8FDC\u7A0B\u90E8\u7F72\u914D\u7F6E\u300C${config.name}\u300DJSON \u65E0\u6548\uFF0C\u4F7F\u7528\u6A21\u677F\u90E8\u7F72\u914D\u7F6E`
461
+ `[apm] \u8FDC\u7A0B\u90E8\u7F72\u914D\u7F6E\u300C${config.name}\u300DJSON \u65E0\u6548\uFF08${TEMPLATE_HINT}\uFF09`
423
462
  );
424
463
  return { synced: false, repositoryId };
425
464
  }
@@ -463,7 +502,7 @@ async function runInit(name) {
463
502
  console.log(`[apm] \u5DE5\u4F5C\u76EE\u5F55\u8DEF\u5F84\uFF1A${workdir}`);
464
503
  if (!syncResult.synced) {
465
504
  console.log(
466
- "[apm] \u5F53\u524D apm.config.json \u4E3A\u6A21\u677F\u9ED8\u8BA4\u503C\uFF1B\u5B8C\u6210\u5E73\u53F0\u767B\u8BB0\u540E\u6267\u884C apm sync-deploy-config \u62C9\u53D6\u90E8\u7F72\u914D\u7F6E"
505
+ "[apm] \u5F53\u524D .apm/apm.config.json \u4E0E .apm/deploy/README.md \u4E3A\u6A21\u677F\u9ED8\u8BA4\u503C\uFF1B\u5B8C\u6210\u5E73\u53F0\u767B\u8BB0\u540E\u6267\u884C apm sync-deploy-config"
467
506
  );
468
507
  }
469
508
  console.log("[apm] \u8BF7\u5728\u5E73\u53F0\u300C\u63A5\u5165\u7BA1\u7406 \u2192 \u5DE5\u4F5C\u7A7A\u95F4\u300D\u767B\u8BB0\u4E0A\u8FF0\u76EE\u5F55\u8DEF\u5F84");
@@ -531,9 +570,9 @@ async function runLogin(opts) {
531
570
  }
532
571
 
533
572
  // src/commands/branch.ts
534
- import { execFile } from "child_process";
535
- import { promisify } from "util";
536
- var execFileAsync = promisify(execFile);
573
+ import { execFile as execFile2 } from "child_process";
574
+ import { promisify as promisify2 } from "util";
575
+ var execFileAsync2 = promisify2(execFile2);
537
576
  function branchNameForSession(sessionId) {
538
577
  const id = sessionId.trim();
539
578
  if (!id) {
@@ -548,7 +587,7 @@ function branchNameForSession(sessionId) {
548
587
  }
549
588
  async function execGit(cwd, args, quiet) {
550
589
  try {
551
- const { stdout, stderr } = await execFileAsync("git", args, {
590
+ const { stdout, stderr } = await execFileAsync2("git", args, {
552
591
  cwd,
553
592
  encoding: "utf8",
554
593
  maxBuffer: 10 * 1024 * 1024
@@ -1085,6 +1124,13 @@ function readCliVersion() {
1085
1124
  }
1086
1125
 
1087
1126
  // src/commands/update.ts
1127
+ var useNpmShell = process.platform === "win32";
1128
+ function runNpm(args, options = {}) {
1129
+ return spawnSync(useNpmShell ? "npm.cmd" : "npm", args, {
1130
+ ...options,
1131
+ shell: useNpmShell
1132
+ });
1133
+ }
1088
1134
  function registryBaseUrl() {
1089
1135
  const fromEnv = process.env.npm_config_registry?.trim() || process.env.NPM_CONFIG_REGISTRY?.trim();
1090
1136
  return (fromEnv || "https://registry.npmjs.org").replace(/\/+$/, "");
@@ -1101,7 +1147,7 @@ async function fetchLatestPublishedVersion() {
1101
1147
  }
1102
1148
  }
1103
1149
  function npmAvailable() {
1104
- const r = spawnSync("npm", ["--version"], { encoding: "utf8" });
1150
+ const r = runNpm(["--version"], { encoding: "utf8" });
1105
1151
  return !r.error && r.status === 0;
1106
1152
  }
1107
1153
  async function runUpdate() {
@@ -1121,11 +1167,9 @@ async function runUpdate() {
1121
1167
  console.error(
1122
1168
  `[apm] \u5F53\u524D\u7248\u672C ${current}\uFF0C\u6B63\u5728\u5B89\u88C5 ${CLI_PACKAGE_NAME}@${targetLabel} \u2026`
1123
1169
  );
1124
- const install = spawnSync(
1125
- "npm",
1126
- ["install", "-g", `${CLI_PACKAGE_NAME}@latest`],
1127
- { stdio: "inherit", shell: process.platform === "win32" }
1128
- );
1170
+ const install = runNpm(["install", "-g", `${CLI_PACKAGE_NAME}@latest`], {
1171
+ stdio: "inherit"
1172
+ });
1129
1173
  if (install.error) {
1130
1174
  console.error("[apm] \u66F4\u65B0\u5931\u8D25:", install.error.message);
1131
1175
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-project-manage-cli",
3
- "version": "6.0.45",
3
+ "version": "6.0.47",
4
4
  "description": "命令行工具:后续用于调用平台后端 API 完成运维与自动化操作",
5
5
  "type": "module",
6
6
  "private": false,