ai-project-manage-cli 6.0.83 → 6.0.84

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 +109 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3939,6 +3939,99 @@ async function runConnect(options) {
3939
3939
  });
3940
3940
  }
3941
3941
 
3942
+ // src/commands/create-pr-errors.ts
3943
+ import { ApiError as ApiError2 } from "listpage-http";
3944
+ function extractMessage(error) {
3945
+ if (error instanceof ApiError2) {
3946
+ return String(error.message ?? "").trim();
3947
+ }
3948
+ if (error instanceof Error) {
3949
+ return error.message.trim();
3950
+ }
3951
+ return String(error).trim();
3952
+ }
3953
+ function extractHttpStatus(error) {
3954
+ if (error instanceof ApiError2) {
3955
+ return error.httpStatus;
3956
+ }
3957
+ return void 0;
3958
+ }
3959
+ function buildHints(message, httpStatus) {
3960
+ const hints = [];
3961
+ if (/未配置.*Gitee.*API Key/i.test(message)) {
3962
+ hints.push(
3963
+ "\u8BF7\u5728 APM Web \u2192 \u5BA2\u6237\u673A\u7BA1\u7406 \u2192 \u7F16\u8F91\u5F53\u524D\u5BA2\u6237\u673A \u2192 \u586B\u5199\u300CGitee API Key\u300D\uFF08Gitee \u79C1\u4EBA\u4EE4\u724C\uFF0C\u9700\u6709\u4ED3\u5E93 PR \u6743\u9650\uFF09"
3964
+ );
3965
+ } else if (/未配置.*GitHub.*API Key/i.test(message)) {
3966
+ hints.push(
3967
+ "\u8BF7\u5728 APM Web \u2192 \u5BA2\u6237\u673A\u7BA1\u7406 \u2192 \u7F16\u8F91\u5F53\u524D\u5BA2\u6237\u673A \u2192 \u586B\u5199\u300CGithub API Key\u300D\uFF08GitHub Personal Access Token\uFF0C\u9700\u6709 repo \u6743\u9650\uFF09"
3968
+ );
3969
+ } else if (httpStatus === 401 || /access token does not exist/i.test(message) || /bad credentials/i.test(message) || /Git 平台返回 401|认证失败 \(401\)/i.test(message)) {
3970
+ hints.push(
3971
+ "Git \u5E73\u53F0 Token \u65E0\u6548\u6216\u5DF2\u8FC7\u671F\uFF1A\u8BF7\u5728 Gitee/GitHub \u91CD\u65B0\u751F\u6210\u79C1\u4EBA\u4EE4\u724C\uFF0C\u5E76\u66F4\u65B0\u5230 APM\u300C\u5BA2\u6237\u673A\u7BA1\u7406\u300D"
3972
+ );
3973
+ }
3974
+ if (/未绑定仓库|未关联仓库|选择关联仓库/i.test(message)) {
3975
+ hints.push("\u5728 APM Web \u2192 \u5DE5\u4F5C\u76EE\u5F55 \u2192 \u4E3A\u5F53\u524D\u8DEF\u5F84\u5173\u8054\u5BF9\u5E94 Git \u4ED3\u5E93");
3976
+ }
3977
+ if (/路径.*不匹配|尚未登记任何工作目录/i.test(message)) {
3978
+ hints.push(
3979
+ "\u5728 APM Web \u2192 \u5DE5\u4F5C\u76EE\u5F55 \u2192 \u767B\u8BB0\u5F53\u524D\u9879\u76EE\u8DEF\u5F84\uFF08\u9700\u4E0E apm create-pr \u6267\u884C\u65F6\u7684 cwd \u4E00\u81F4\uFF09"
3980
+ );
3981
+ }
3982
+ if (/no commits between|分支不存在|branch.*not found|找不到.*分支/i.test(
3983
+ message
3984
+ )) {
3985
+ hints.push(
3986
+ "\u7279\u6027\u5206\u652F\u53EF\u80FD\u672A\u63A8\u9001\uFF1A\u5148\u6267\u884C apm branch <sessionId> \u521B\u5EFA\u5206\u652F\u5E76 push\uFF0C\u518D\u91CD\u8BD5 create-pr"
3987
+ );
3988
+ }
3989
+ if (/pull request already exists|已存在.*pull/i.test(message)) {
3990
+ hints.push("\u8BE5\u5206\u652F\u53EF\u80FD\u5DF2\u6709\u5F00\u542F\u7684 PR\uFF0C\u8BF7\u5230 Git \u5E73\u53F0\u6216 APM \u4F1A\u8BDD\u8BE6\u60C5\u67E5\u770B");
3991
+ }
3992
+ if (/403|无权限|forbidden/i.test(message)) {
3993
+ hints.push("\u786E\u8BA4 Token \u5BF9\u76EE\u6807\u4ED3\u5E93\u6709\u521B\u5EFA Pull Request \u7684\u6743\u9650");
3994
+ }
3995
+ if (hints.length === 0) {
3996
+ hints.push(
3997
+ "\u82E5\u65E0\u6CD5\u81EA\u884C\u6392\u67E5\uFF0C\u8BF7\u5728\u4F1A\u8BDD\u4E2D @\u9879\u76EE\u7ECF\u7406\uFF0C\u5E76\u63D0\u4F9B\u4E0A\u8FF0\u4F1A\u8BDD ID \u4E0E\u5DE5\u4F5C\u76EE\u5F55"
3998
+ );
3999
+ }
4000
+ return hints;
4001
+ }
4002
+ function formatCreatePrErrorLines(error, context) {
4003
+ const message = extractMessage(error);
4004
+ const httpStatus = extractHttpStatus(error);
4005
+ const headBranch = `feat/session-${context.sessionId}`;
4006
+ const lines = [
4007
+ "[apm] \u521B\u5EFA PR \u5931\u8D25",
4008
+ "",
4009
+ `\u4F1A\u8BDD ID: ${context.sessionId}`,
4010
+ `\u5DE5\u4F5C\u76EE\u5F55: ${context.workdir}`,
4011
+ `\u7279\u6027\u5206\u652F: ${headBranch}`
4012
+ ];
4013
+ if (context.clientMachineId) {
4014
+ lines.push(`\u5BA2\u6237\u673A ID: ${context.clientMachineId}`);
4015
+ }
4016
+ lines.push("", "\u539F\u56E0:", message || "(\u672A\u77E5\u9519\u8BEF)");
4017
+ const hints = buildHints(message, httpStatus);
4018
+ if (hints.length > 0) {
4019
+ lines.push("", "\u5EFA\u8BAE:");
4020
+ hints.forEach((hint, index) => {
4021
+ lines.push(`${index + 1}. ${hint}`);
4022
+ });
4023
+ }
4024
+ if (httpStatus !== void 0) {
4025
+ lines.push("", `HTTP \u72B6\u6001: ${httpStatus}`);
4026
+ }
4027
+ return lines;
4028
+ }
4029
+ function printCreatePrError(error, context) {
4030
+ for (const line of formatCreatePrErrorLines(error, context)) {
4031
+ console.error(line);
4032
+ }
4033
+ }
4034
+
3942
4035
  // src/commands/create-pr.ts
3943
4036
  async function runCreatePr(options) {
3944
4037
  const sessionId = options.sessionId.trim();
@@ -3954,13 +4047,22 @@ async function runCreatePr(options) {
3954
4047
  const cfg = await ensureLoggedConfig();
3955
4048
  const api = createApmApiClient(cfg);
3956
4049
  const workdir = resolveWorkdirPath(options.cwd ?? process.cwd());
3957
- const pr = await api.cli.createPullRequest({
3958
- sessionId,
3959
- workdir,
3960
- title,
3961
- content: options.content ?? ""
3962
- });
3963
- console.log(`[apm] PR \u5DF2\u5C31\u7EEA #${pr.number} (${pr.state}): ${pr.url}`);
4050
+ try {
4051
+ const pr = await api.cli.createPullRequest({
4052
+ sessionId,
4053
+ workdir,
4054
+ title,
4055
+ content: options.content ?? ""
4056
+ });
4057
+ console.log(`[apm] PR \u5DF2\u5C31\u7EEA #${pr.number} (${pr.state}): ${pr.url}`);
4058
+ } catch (error) {
4059
+ printCreatePrError(error, {
4060
+ sessionId,
4061
+ workdir,
4062
+ clientMachineId: resolveClientMachineId(cfg)
4063
+ });
4064
+ process.exit(1);
4065
+ }
3964
4066
  }
3965
4067
 
3966
4068
  // src/commands/deploy/deploy-execute.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-project-manage-cli",
3
- "version": "6.0.83",
3
+ "version": "6.0.84",
4
4
  "description": "命令行工具:后续用于调用平台后端 API 完成运维与自动化操作",
5
5
  "type": "module",
6
6
  "private": false,