@unifan/pi-commit-zh 1.0.7 → 1.0.9

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/index.ts CHANGED
@@ -174,13 +174,16 @@ export default function (pi: ExtensionAPI) {
174
174
  let pushText = "";
175
175
  if (andPush) {
176
176
  notify("正在推送到远端仓库 (git push)...", "info");
177
- const pushRes = await pushCurrentBranch(ctx.cwd);
177
+ const pushRes = await pushCurrentBranch(ctx.cwd, (msg) => notify(msg, "info"));
178
178
  if (pushRes.ok) {
179
- notify("🚀 成功推送到远端仓库!", "info");
180
- pushText = "\n\n🚀 **已自动推送到远端分支**";
179
+ const successMsg = pushRes.autoRebased
180
+ ? "🚀 远端有新提交,已自动完成变基 (pull --rebase) 并成功推送!"
181
+ : "🚀 成功推送到远端仓库!";
182
+ notify(successMsg, "info");
183
+ pushText = `\n\n${successMsg}`;
181
184
  } else {
182
- notify(`⚠️ 推送失败: ${pushRes.output}`, "warning");
183
- pushText = `\n\n⚠️ **推送到远端失败**: ${pushRes.output}`;
185
+ notify(`⚠️ 推送失败: ${pushRes.output}`, "error");
186
+ pushText = `\n\n⚠️ **推送到远端失败**:\n${pushRes.output}`;
184
187
  }
185
188
  }
186
189
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unifan/pi-commit-zh",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Pi 智能 Git 提交助手(规范化 Conventional Commits 纯中文版,支持一键提审与推流)",
5
5
  "type": "module",
6
6
  "main": "index.ts",
package/src/git.ts CHANGED
@@ -55,7 +55,46 @@ export async function commitWithMsg(cwd: string, message: string): Promise<{ ok:
55
55
  return { ok: res.ok, output: res.ok ? res.stdout : res.stderr };
56
56
  }
57
57
 
58
- export async function pushCurrentBranch(cwd: string): Promise<{ ok: boolean; output: string }> {
59
- const res = await runGit(cwd, ["push"]);
60
- return { ok: res.ok, output: res.ok ? res.stdout : res.stderr };
58
+ export async function pushCurrentBranch(
59
+ cwd: string,
60
+ onLog?: (msg: string) => void,
61
+ ): Promise<{ ok: boolean; output: string; autoRebased?: boolean }> {
62
+ const initialPush = await runGit(cwd, ["push"]);
63
+ if (initialPush.ok) {
64
+ return { ok: true, output: initialPush.stdout || "推送成功" };
65
+ }
66
+
67
+ const pushError = `${initialPush.stderr} ${initialPush.stdout}`.toLowerCase();
68
+ const needsPull =
69
+ pushError.includes("fetch first") ||
70
+ pushError.includes("non-fast-forward") ||
71
+ pushError.includes("rejected") ||
72
+ pushError.includes("behind");
73
+
74
+ if (!needsPull) {
75
+ return { ok: false, output: initialPush.stderr || initialPush.stdout };
76
+ }
77
+
78
+ if (onLog) onLog("检测到远端有新提交,正在自动执行变基拉取 (git pull --rebase)...");
79
+
80
+ const pullRebase = await runGit(cwd, ["pull", "--rebase"]);
81
+ if (!pullRebase.ok) {
82
+ const rebaseErr = `${pullRebase.stderr} ${pullRebase.stdout}`;
83
+ return {
84
+ ok: false,
85
+ output: `远端有新提交,尝试自动变基 (git pull --rebase) 时产生代码冲突。\n${rebaseErr}\n请手动解决冲突后执行 git rebase --continue,或执行 git rebase --abort 撤销变基。`,
86
+ };
87
+ }
88
+
89
+ if (onLog) onLog("变基拉取成功(无代码冲突),正在重新推送到远端...");
90
+ const retryPush = await runGit(cwd, ["push"]);
91
+ if (retryPush.ok) {
92
+ return {
93
+ ok: true,
94
+ output: "远端有新提交,已自动完成 git pull --rebase 变基并成功推送到远端!",
95
+ autoRebased: true,
96
+ };
97
+ }
98
+
99
+ return { ok: false, output: retryPush.stderr || retryPush.stdout };
61
100
  }
package/src/prompt.ts CHANGED
@@ -1,18 +1,23 @@
1
- export const COMMIT_SYSTEM_PROMPT = `你是专业的 Git 提交信息生成专家(Conventional Commits 中文版)。
2
- 你的唯一任务是根据提供的 Git Diff 变动和修改文件列表,生成规范、准确、地道的中文 Commit Message。
1
+ export const COMMIT_SYSTEM_PROMPT = `你是专业的 Git 提交信息生成专家(Conventional Commits 纯中文规范版)。
2
+ 你的唯一任务是根据提供的 Git Diff 变动和修改文件列表,生成规范、严谨、地道的中文 Commit Message。
3
3
 
4
4
  ## 严格遵循的标准(Conventional Commits 1.0.0):
5
+
5
6
  1. 格式:<type>(<scope>): <中文描述>
6
- - type 必须为标准英文类型之一:
7
+ - 严禁添加任何 Emoji 表情符号(保持严谨专业的工程提交风格)。
8
+ - type 必须为以下标准英文类型之一:
7
9
  • feat: 新增功能/新模块/新特性
8
- • fix: 修复Bug/缺陷
9
- • perf: 性能优化/降低GC/提高帧率
10
- • refactor: 代码重构/结构优化
11
- docs: 文档/注释更新
12
- style: 格式调整/无逻辑影响
13
- test: 单元测试/基准测试
14
- chore: 构建/依赖/配置杂项
15
- - scope 为具体修改的业务模块名(如:combat/战斗、session/会话、review/审查、ui/界面、network/网络、core/核心)
10
+ • fix: 修复Bug/逻辑缺陷/运行时异常
11
+ • perf: 性能优化/降低GC分配/提高运行帧率/降低复杂度
12
+ • refactor: 代码重构(既不加新功能也不修Bug的架构优化)
13
+ ci: CI/CD持续集成与工作流变动(如 .github/workflows、流水线配置、发版脚本)
14
+ build: 构建系统与依赖库变动(如 .csproj 配置、package.json 依赖升级、构建工具)
15
+ chore: 日常杂项与版本号升级(如版本升级统一使用: chore(release): 升级版本号至 vX.Y.Z)
16
+ docs: 文档与注释更新(如 README、技术规范、代码注释)
17
+ test: 单元测试、集成测试与基准测试(Benchmark)
18
+ • style: 代码格式化、缩进与空格调整(不影响实际逻辑)
19
+ • revert: 代码回滚(撤销先前的提交)
20
+ - scope 为修改的核心业务模块名(如:combat/战斗、session/会话、review/审查、ui/界面、network/网络、workflow/工作流、release/发版)
16
21
  - 中文描述:50个汉字以内,动词开头,言简意赅,末尾严禁加句号。
17
22
 
18
23
  2. 若修改较为复杂,可附带简要中文正文列表(Body):
@@ -21,4 +26,4 @@ export const COMMIT_SYSTEM_PROMPT = `你是专业的 Git 提交信息生成专
21
26
 
22
27
  3. 语言约束:所有标题描述与正文说明必须且只能使用纯正中文,严禁长句英文。
23
28
 
24
- 4. 输出格式:直接输出生成的 Commit 信息文本(首行标题,空行后跟正文),不要附加任何额外的 markdown 代码块或寒暄。`;
29
+ 4. 输出格式:直接输出生成的 Commit 信息纯文本(首行标题,空行后跟正文),严禁附加任何 markdown 代码块标记或多余寒暄。`;