@unifan/pi-unifan-zh 1.0.40 → 1.0.42

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.
@@ -84,11 +84,19 @@ export async function generateCommitMessage(
84
84
  const text = response.content.map((c) => c.type === "text" ? c.text : "").join("").trim()
85
85
  .replace(/^```[a-zA-Z]*\r?\n?/, "").replace(/\r?\n?```$/, "").trim();
86
86
  if (!text) throw new Error("模型返回了空的提交信息。");
87
- if (!/^(feat|fix|perf|refactor|ci|build|chore|docs|test|style|revert)(\([^()\r\n]+\))?: [^\r\n]+$/.test(text.split(/\r?\n/)[0]))
87
+ const lines = text.split(/\r?\n/);
88
+ const normalizedTitle = lines[0].replace(
89
+ /^(feat|fix|perf|refactor|ci|build|chore|docs|test|style|revert)(?:\(([^()\r\n]+)\)|(([^()\r\n]+)))?\s*[::]\s*(.+)$/,
90
+ (_match, type: string, scope: string | undefined, fullWidthScope: string | undefined, description: string) =>
91
+ `${type}${scope || fullWidthScope ? `(${scope || fullWidthScope})` : ""}: ${description.trim()}`,
92
+ );
93
+ lines[0] = normalizedTitle;
94
+ const normalizedText = lines.join("\n").trim();
95
+ if (!/^(feat|fix|perf|refactor|ci|build|chore|docs|test|style|revert)(\([^()\r\n]+\))?: [^\r\n]+$/.test(normalizedTitle))
88
96
  throw new Error("模型返回的提交标题不符合约定格式,请重试或补充修改说明。");
89
- if (text.includes("更新代码与相关配置"))
97
+ if (normalizedText.includes("更新代码与相关配置"))
90
98
  throw new Error("模型返回了无具体业务含义的通用提交信息,请补充修改说明后重试。");
91
- return text;
99
+ return normalizedText;
92
100
  }
93
101
 
94
102
  export default function (pi: ExtensionAPI) {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unifan/pi-commit-zh",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "Pi 智能 Git 提交助手(规范化 Conventional Commits 纯中文版,支持一键提审与推流)",
5
5
  "type": "module",
6
6
  "main": "index.ts",
@@ -24,6 +24,6 @@ export const COMMIT_SYSTEM_PROMPT = `你是专业的 Git 提交信息生成专
24
24
  - 核心改动点 1
25
25
  - 核心改动点 2
26
26
 
27
- 3. 语言约束:所有标题描述与正文说明必须且只能使用纯正中文,严禁长句英文。
27
+ 3. 语言约束:描述与正文必须使用纯正中文;type、可选 scope 以及格式分隔符必须使用英文半角字符。
28
28
 
29
29
  4. 输出格式:直接输出生成的 Commit 信息纯文本(首行标题,空行后跟正文),严禁附加任何 markdown 代码块标记或多余寒暄。`;
@@ -100,6 +100,15 @@ test('提供方或认证缺失时停止生成', async () => {
100
100
  await assert.rejects(generateCommitMessage(ctx, 'diff', []), /提供方不可用/);
101
101
  });
102
102
 
103
+ test('规范化模型返回的全角提交格式', async () => {
104
+ const result = await generateCommitMessage(
105
+ context(async () => response('fix(character):修复角色Renderer收集遗漏')),
106
+ 'diff',
107
+ ['角色.cs'],
108
+ );
109
+ assert.equal(result, 'fix(character): 修复角色Renderer收集遗漏');
110
+ });
111
+
103
112
  test('拒绝空结果、异常完成、截断、非法格式和通用文案', async () => {
104
113
  for (const result of [response(''), response('fix: 修复残留', 'error'), response('fix: 修复残留', 'length'), response('说明文字'), response('chore(GameClient): 更新代码与相关配置')]) {
105
114
  await assert.rejects(generateCommitMessage(context(async () => result), 'diff', ['角色.cs']));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unifan/pi-unifan-zh",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "description": "Pi Coding Agent 中文扩展全家桶与独立插件集",
5
5
  "type": "module",
6
6
  "main": "extensions/sessions/index.ts",