ai-project-manage-cli 6.0.45 → 6.0.46

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 +50 -13
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -384,24 +384,61 @@ 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(`[apm] \u5DE5\u4F5C\u7A7A\u95F4\u8DEF\u5F84\u672A\u5339\u914D\uFF0C\u5DF2\u901A\u8FC7 git remote \u5173\u8054\u4ED3\u5E93: ${gitUrl}`);
418
+ return { repositoryId: matched.repositoryId, diagnostic: null };
419
+ }
420
+ }
421
+ 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`;
422
+ return { repositoryId: null, diagnostic: detail };
423
+ }
389
424
  async function syncRemoteDeploymentConfig(workdirPath, apmDir) {
390
425
  const cfg = await tryReadApmConfig();
391
426
  if (!cfg || !resolveApiKey(cfg)) {
392
427
  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"
428
+ `[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
429
+ [apm] \u8BF7\u5148\u6267\u884C apm login\uFF0C\u518D\u6267\u884C apm sync-deploy-config \u62C9\u53D6\u6700\u65B0\u914D\u7F6E\u3002`
394
430
  );
395
431
  return { synced: false, repositoryId: null };
396
432
  }
397
433
  const api = createApmApiClient(cfg);
398
- const baseline = await api.cli.workspaceBaseline({ workdirPath });
399
- const repositoryId = baseline.repositoryId;
434
+ const { repositoryId, diagnostic } = await resolveRepositoryIdForSync(
435
+ api,
436
+ workdirPath
437
+ );
400
438
  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
439
  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}
440
+ `[apm] \u672A\u80FD\u540C\u6B65\u5E73\u53F0\u90E8\u7F72\u914D\u7F6E\uFF08${TEMPLATE_HINT}\uFF09\u3002
441
+ ${diagnostic ?? ""}
405
442
  [apm] ${SYNC_HINT}`
406
443
  );
407
444
  return { synced: false, repositoryId: null };
@@ -409,7 +446,7 @@ ${detail}
409
446
  const { config } = await api.cli.getDeploymentConfiguration({ repositoryId });
410
447
  if (!config) {
411
448
  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
449
+ `[apm] \u672A\u627E\u5230\u5173\u8054\u4ED3\u5E93\u7684\u90E8\u7F72\u914D\u7F6E\uFF08${TEMPLATE_HINT}\uFF0CrepositoryId\uFF1A${repositoryId}\uFF09\u3002
413
450
  [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
451
  );
415
452
  return { synced: false, repositoryId };
@@ -419,7 +456,7 @@ ${detail}
419
456
  parsed = JSON.parse(config.content);
420
457
  } catch {
421
458
  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`
459
+ `[apm] \u8FDC\u7A0B\u90E8\u7F72\u914D\u7F6E\u300C${config.name}\u300DJSON \u65E0\u6548\uFF08${TEMPLATE_HINT}\uFF09`
423
460
  );
424
461
  return { synced: false, repositoryId };
425
462
  }
@@ -463,7 +500,7 @@ async function runInit(name) {
463
500
  console.log(`[apm] \u5DE5\u4F5C\u76EE\u5F55\u8DEF\u5F84\uFF1A${workdir}`);
464
501
  if (!syncResult.synced) {
465
502
  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"
503
+ "[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
504
  );
468
505
  }
469
506
  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 +568,9 @@ async function runLogin(opts) {
531
568
  }
532
569
 
533
570
  // src/commands/branch.ts
534
- import { execFile } from "child_process";
535
- import { promisify } from "util";
536
- var execFileAsync = promisify(execFile);
571
+ import { execFile as execFile2 } from "child_process";
572
+ import { promisify as promisify2 } from "util";
573
+ var execFileAsync2 = promisify2(execFile2);
537
574
  function branchNameForSession(sessionId) {
538
575
  const id = sessionId.trim();
539
576
  if (!id) {
@@ -548,7 +585,7 @@ function branchNameForSession(sessionId) {
548
585
  }
549
586
  async function execGit(cwd, args, quiet) {
550
587
  try {
551
- const { stdout, stderr } = await execFileAsync("git", args, {
588
+ const { stdout, stderr } = await execFileAsync2("git", args, {
552
589
  cwd,
553
590
  encoding: "utf8",
554
591
  maxBuffer: 10 * 1024 * 1024
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.46",
4
4
  "description": "命令行工具:后续用于调用平台后端 API 完成运维与自动化操作",
5
5
  "type": "module",
6
6
  "private": false,