@unifan/pi-unifan-zh 1.0.27 → 1.0.29
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/AGENTS.md +4 -0
- package/README.md +1 -0
- package/README_zh.md +1 -0
- package/extensions/commit/index.ts +16 -3
- package/extensions/commit/package.json +1 -1
- package/extensions/commit/src/git.ts +40 -2
- package/extensions/review/index.ts +0 -1
- package/extensions/review/package.json +1 -1
- package/package.json +1 -1
package/AGENTS.md
CHANGED
|
@@ -87,6 +87,10 @@ pi-unifan-zh/
|
|
|
87
87
|
* **网络抖动重试**:`runs.all` 并发调用必须包裹 `try-catch` 并在发生网络断连时自动延迟 800ms 重试一次。
|
|
88
88
|
* **门禁熔断保护**:门禁裁判长(Gate)发生异常时必须兜底捕获,**绝对不能抛出未捕获异常导致已完成的 Reviewer 成果丢失**。
|
|
89
89
|
|
|
90
|
+
### 6. Git 冲突解决铁律(严禁直接使用 ours/theirs)
|
|
91
|
+
* 拉取更新或变基(`git pull --rebase`)发生代码冲突时,**绝对严禁直接使用 `--ours` 或 `--theirs` 无脑覆盖**(严禁粗暴丢失任何一方代码)。
|
|
92
|
+
* **必须仔细对比两方的 diff 修改与完整代码上下文**,逐行融合双方意图与逻辑,确保既不丢失远端的最新改动,又完整保留本地提交的修复与功能。
|
|
93
|
+
|
|
90
94
|
---
|
|
91
95
|
|
|
92
96
|
## 🚀 三、发版与发布指南(Release & Publish Workflow)
|
package/README.md
CHANGED
|
@@ -128,6 +128,7 @@ pi install npm:@unifan/pi-commit-zh
|
|
|
128
128
|
- **Strict ASCII Punctuation**: Parentheses `()` and colon `: ` strictly use ASCII half-width characters for CI / Commitlint compliance.
|
|
129
129
|
- **No Emoji**: Clean, professional plain text commit style.
|
|
130
130
|
- **Smart Auto-Rebase on Push**: In `/commit-push`, if remote contains unpulled commits, it automatically runs `git pull --rebase` and retries push, keeping a clean linear git history.
|
|
131
|
+
- **Smart Conflict Resolution Guidance**: If rebase encounters conflicts, lists conflicting files and explicitly enforces: **never blindly use `--ours` or `--theirs`; always resolve line-by-line based on diff and context**.
|
|
131
132
|
- **Unpushed Commits Sync**: Automatically pushes unpushed local commits even if the working tree is clean.
|
|
132
133
|
|
|
133
134
|
---
|
package/README_zh.md
CHANGED
|
@@ -133,6 +133,7 @@ pi install npm:@unifan/pi-commit-zh
|
|
|
133
133
|
- **严格半角英文标点**:括号 `()` 与冒号空格 `: ` 严格使用英文半角字符,确保 CI / Commitlint 正则解析合规。
|
|
134
134
|
- **严禁 Emoji**:保持严谨、专业的纯文本工程风格。
|
|
135
135
|
- **智能自动变基(Auto Rebase)**:在 `/commit-push` 时,若远端有别人先提交的代码被拒绝,**自动在后台执行 `git pull --rebase` 变基并自动重试推送**,Git 历史保持一条干净直线!
|
|
136
|
+
- **智能冲突比对引导(严禁无脑覆盖)**:变基拉取若遇代码冲突,自动列出冲突文件清单并**明确指示:绝对严禁直接使用 `--ours` 或 `--theirs` 粗暴覆盖,必须根据对比修改和代码上下文逐行解决冲突**,并给出清晰的操作步骤!
|
|
136
137
|
- **未推送提交自动同步**:即使当前工作区干净,若检测到本地有尚未 push 的历史 Commit,`/commit-push` 也会自动将其推送至远端!
|
|
137
138
|
|
|
138
139
|
---
|
|
@@ -131,7 +131,16 @@ export default function (pi: ExtensionAPI) {
|
|
|
131
131
|
display: true,
|
|
132
132
|
});
|
|
133
133
|
} else {
|
|
134
|
-
|
|
134
|
+
if (pushRes.hasConflict) {
|
|
135
|
+
notify("⚠️ 远端拉取变基产生代码冲突!请对比修改和上下文解决冲突,严禁直接使用 ours/theirs。", "warning");
|
|
136
|
+
} else {
|
|
137
|
+
notify(`⚠️ 推送失败: ${pushRes.output}`, "error");
|
|
138
|
+
}
|
|
139
|
+
pi.sendMessage({
|
|
140
|
+
customType: "pi-commit-result",
|
|
141
|
+
content: `### ⚠️ 推送到远端未完成\n\n${pushRes.output}`,
|
|
142
|
+
display: true,
|
|
143
|
+
});
|
|
135
144
|
}
|
|
136
145
|
return;
|
|
137
146
|
}
|
|
@@ -172,8 +181,12 @@ export default function (pi: ExtensionAPI) {
|
|
|
172
181
|
notify(successMsg, "info");
|
|
173
182
|
pushText = `\n\n${successMsg}`;
|
|
174
183
|
} else {
|
|
175
|
-
|
|
176
|
-
|
|
184
|
+
if (pushRes.hasConflict) {
|
|
185
|
+
notify("⚠️ 远端拉取变基产生代码冲突!请对比修改和上下文解决冲突,严禁直接使用 ours/theirs。", "warning");
|
|
186
|
+
} else {
|
|
187
|
+
notify(`⚠️ 推送失败: ${pushRes.output}`, "error");
|
|
188
|
+
}
|
|
189
|
+
pushText = `\n\n${pushRes.output}`;
|
|
177
190
|
}
|
|
178
191
|
}
|
|
179
192
|
|
|
@@ -79,7 +79,7 @@ export async function commitWithMsg(cwd: string, message: string): Promise<{ ok:
|
|
|
79
79
|
export async function pushCurrentBranch(
|
|
80
80
|
cwd: string,
|
|
81
81
|
onLog?: (msg: string) => void,
|
|
82
|
-
): Promise<{ ok: boolean; output: string; autoRebased?: boolean }> {
|
|
82
|
+
): Promise<{ ok: boolean; output: string; autoRebased?: boolean; hasConflict?: boolean; conflictFiles?: string[] }> {
|
|
83
83
|
let initialPush = await runGit(cwd, ["push"]);
|
|
84
84
|
if (initialPush.ok) {
|
|
85
85
|
return { ok: true, output: initialPush.stdout || "推送成功" };
|
|
@@ -111,9 +111,47 @@ export async function pushCurrentBranch(
|
|
|
111
111
|
const pullRebase = await runGit(cwd, ["pull", "--rebase"]);
|
|
112
112
|
if (!pullRebase.ok) {
|
|
113
113
|
const rebaseErr = `${pullRebase.stderr} ${pullRebase.stdout}`;
|
|
114
|
+
|
|
115
|
+
// 检索冲突文件清单
|
|
116
|
+
const conflictDiff = await runGit(cwd, ["diff", "--name-only", "--diff-filter=U"]);
|
|
117
|
+
let conflictFiles = conflictDiff.ok && conflictDiff.stdout.trim()
|
|
118
|
+
? conflictDiff.stdout.trim().split("\n").map((f) => f.trim()).filter(Boolean)
|
|
119
|
+
: [];
|
|
120
|
+
|
|
121
|
+
if (conflictFiles.length === 0) {
|
|
122
|
+
const statusRes = await runGit(cwd, ["status", "--porcelain"]);
|
|
123
|
+
if (statusRes.ok && statusRes.stdout.trim()) {
|
|
124
|
+
conflictFiles = statusRes.stdout
|
|
125
|
+
.split("\n")
|
|
126
|
+
.filter((l) => /^(UU|AA|UD|DU|DD|AU|UA)\s+/.test(l.trim()))
|
|
127
|
+
.map((l) => l.trim().slice(3).trim());
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const filesListText = conflictFiles.length > 0
|
|
132
|
+
? `\n\n📌 **发生冲突的文件 (${conflictFiles.length} 个)**:\n${conflictFiles.map((f) => `- \`${f}\``).join("\n")}`
|
|
133
|
+
: "";
|
|
134
|
+
|
|
135
|
+
const conflictOutput = `⚠️ **远端有新提交,拉取变基 (git pull --rebase) 时与本地提交产生代码冲突!**${filesListText}
|
|
136
|
+
|
|
137
|
+
🚨 **【代码冲突解决核心铁律(重中之重)】**:
|
|
138
|
+
1. **严禁直接无脑使用 \`--theirs\` 或 \`--ours\`**:绝对不要盲目使用其中一方覆盖另一方,否则极易覆盖远端同事的代码或丢失本地修复!
|
|
139
|
+
2. **必须根据对比修改和上下文解决冲突**:
|
|
140
|
+
- 逐个打开冲突文件,对照 \`<<<<<<< HEAD\`(远端基线)与 \`>>>>>>>\`(本地提交)的具体改动;
|
|
141
|
+
- 结合周围类、函数、接口调用与业务上下文,理解两边的意图后逐行融合成正确的最终代码。
|
|
142
|
+
|
|
143
|
+
🛠️ **解决冲突操作步骤**:
|
|
144
|
+
1. 对比并手工/智能修改上述冲突文件,消除所有冲突标记;
|
|
145
|
+
2. 执行 \`git add <已解决文件>\` 标记冲突已解决;
|
|
146
|
+
3. 执行 \`git rebase --continue\` 完成变基;
|
|
147
|
+
4. 变基成功后重新执行 \`/commit-push\` 推送至远端;
|
|
148
|
+
(若需放弃本次变基恢复原状,可执行 \`git rebase --abort\`)。\n\n底层详细输出:\n${rebaseErr}`;
|
|
149
|
+
|
|
114
150
|
return {
|
|
115
151
|
ok: false,
|
|
116
|
-
output:
|
|
152
|
+
output: conflictOutput,
|
|
153
|
+
hasConflict: true,
|
|
154
|
+
conflictFiles,
|
|
117
155
|
};
|
|
118
156
|
}
|
|
119
157
|
|