chore: 日志同步逻辑优化

This commit is contained in:
digua
2026-04-13 19:47:53 +08:00
parent dd88c499b3
commit 3c022b069a
10 changed files with 68 additions and 53 deletions
+19 -10
View File
@@ -1,17 +1,17 @@
---
name: generate-changelog
description: 根据当前项目 package.json 版本与 Git 提交记录生成中文版本日志。用于用户提出生成版本日志”“生成 changelog”“发布新版本并生成更新记录等请求时,自动读取当前版本号、定位上一版本、汇总版本区间 commit,并更新 docs/changelogs_cn.json(新增版本、生成中文 summary、按类型归类变更)。
description: 根据当前项目 package.json 版本与 Git 提交记录生成中文版本日志。用于用户提出"生成版本日志""生成 changelog""发布新版本并生成更新记录"等请求时,自动读取当前版本号、定位上一版本、汇总版本区间 commit,并更新 docs/public/changelogs/cn.json(新增版本、生成中文 summary、按类型归类变更)。
---
# generate-changelog
按以下流程更新 `docs/changelogs_cn.json`
按以下流程更新 `docs/public/changelogs/cn.json`
## 1. 读取版本与日志现状
1. 读取 `package.json` 中的 `version` 作为 `currentVersion`
2. 读取 `docs/changelogs_cn.json`,确认是否已存在 `currentVersion`
3. 若已存在:停止新增流程,改为就地更新该版本内容
2. 读取 `docs/public/changelogs/cn.json`,确认是否已存在 `currentVersion`
3. 若已存在:停止新增流程,改为"就地更新该版本内容"
4. 计算 `previousVersion`
-`currentVersion` 已存在于 changelog:取它的下一条记录版本号。
-`currentVersion` 不存在于 changelog:取第一条记录版本号。
@@ -23,7 +23,7 @@ description: 根据当前项目 package.json 版本与 Git 提交记录生成中
1. 若存在 tag `v{currentVersion}`:使用 `v{previousVersion}..v{currentVersion}`
2. 若不存在 tag `v{currentVersion}`:使用 `v{previousVersion}..HEAD`
3.`v{previousVersion}` 不存在:回退为从首个提交到 `HEAD`,并在结果中明确标注缺少上一版本 tag,采用全量范围
3.`v{previousVersion}` 不存在:回退为从首个提交到 `HEAD`,并在结果中明确标注"缺少上一版本 tag,采用全量范围"
使用命令:
@@ -71,7 +71,7 @@ git show -s --format='%B' <commit>
## 5. 更新 JSON 文件
目标文件:`docs/changelogs_cn.json`
目标文件:`docs/public/changelogs/cn.json`
更新规则:
@@ -83,13 +83,13 @@ git show -s --format='%B' <commit>
2. 若不存在当前版本,插入到数组首位。
3. 若已存在当前版本,替换该版本对象,但保持其在数组中的原位置。
4. 保持 JSON 可读格式(2 空格缩进,UTF-8,无注释)。
5. 写入后必须执行格式化,优先使用项目 Prettier,确保与手动保存风格一致:
5. 写入后必须执行格式化,优先使用项目 Prettier,确保与"手动保存"风格一致:
```bash
npx prettier --write docs/changelogs_cn.json
npx prettier --write docs/public/changelogs/cn.json
```
6. 若环境没有 Prettier,回退为 `JSON.stringify(..., null, 2)` 的最小格式保证,并在输出中明确提示未执行 Prettier 格式化
6. 若环境没有 Prettier,回退为 `JSON.stringify(..., null, 2)` 的最小格式保证,并在输出中明确提示"未执行 Prettier 格式化"
## 6. 自检
@@ -104,7 +104,16 @@ npx prettier --write docs/changelogs_cn.json
补充检查:
5. 确认 `docs/changelogs_cn.json` 已经过 Prettier(若可用)。
5. 确认 `docs/public/changelogs/cn.json` 已经过 Prettier(若可用)。
## 7. 任务完成后询问
自检通过并输出结果后,必须询问用户:
> "changelog 已生成完毕。是否继续执行 sync-changelog 技能,将本版本日志同步为多语言版本并提交?"
- 若用户确认,立即读取并执行同目录下的 `../sync-changelog/SKILL.md`
- 若用户拒绝或未明确回应,结束当前任务。
## 参考文件
+19 -19
View File
@@ -1,6 +1,6 @@
---
name: sync-changelog
description: 将 docs/changelogs_cn.json 的当前版本日志同步为多语言版本:生成适合英文母语者阅读的英文版、适合繁体中文用户阅读的繁中版、适合日语母语者阅读的日文版,分别更新 docs/changelogs_en.json、docs/changelogs_tw.json、docs/changelogs_ja.json,并在当前项目创建 release 提交(包含 package.json 与四种语言 changelog);随后同步四种语言 changelog 到同级仓库 ../chatlab.fun 并创建文档提交。用于用户提出同步版本日志”“生成并同步 changelog”“发布前同步多语言日志等请求。仅创建 commit,不执行 push。
description: 将 docs/public/changelogs/cn.json 的当前版本日志同步为多语言版本:生成适合英文母语者阅读的英文版、适合繁体中文用户阅读的繁中版、适合日语母语者阅读的日文版,分别更新 docs/public/changelogs/en.json、docs/public/changelogs/tw.json、docs/public/changelogs/ja.json,并在当前项目创建 release 提交(包含 package.json 与四种语言 changelog);随后同步四种语言 changelog 到同级仓库 ../chatlab.fun 并创建文档提交。用于用户提出"同步版本日志""生成并同步 changelog""发布前同步多语言日志"等请求。仅创建 commit,不执行 push。
---
# sync-changelog
@@ -11,7 +11,7 @@ description: 将 docs/changelogs_cn.json 的当前版本日志同步为多语言
1. 当前仓库必须工作区干净:
- 执行 `git status --porcelain`
- 允许白名单改动:`package.json``docs/changelogs_cn.json`(这两个文件可作为本次任务前置输入)。
- 允许白名单改动:`package.json``docs/public/changelogs/cn.json`(这两个文件可作为本次任务前置输入)。
- 若存在白名单外改动(包含已暂存/未暂存/未跟踪),立即退出并提示用户手动处理。
2. 当前仓库必须在 `main`
- 若不在 `main`,仅在工作区干净时执行 `git checkout main`
@@ -23,21 +23,21 @@ description: 将 docs/changelogs_cn.json 的当前版本日志同步为多语言
可复用脚本:`scripts/preflight_main_clean.sh` 当前仓库建议调用:
```bash
scripts/preflight_main_clean.sh . "package.json,docs/changelogs_cn.json"
scripts/preflight_main_clean.sh . "package.json,docs/public/changelogs/cn.json"
```
`chatlab.fun` 仓库仍需严格干净(不传白名单参数)。
## 2. 读取当前版本并校验文件
1.`docs/changelogs_cn.json` 读取第一个对象作为当前版本。
1.`docs/public/changelogs/cn.json` 读取第一个对象作为当前版本。
2. 读取版本号 `version`(例如 `0.9.6`)。
3. **在开始翻译前,必须重新读取一次该版本的完整中文内容(`summary` 与 `changes`),并以这次读取结果作为唯一翻译源。**
4. **严禁复用之前由 `generate-changelog` 或任意草稿步骤产出的缓存文案;若用户在生成后手动修改过中文日志,必须以用户修改后的文件内容为准。**
5. 检查以下文件是否存在:
- `docs/changelogs_en.json`
- `docs/changelogs_tw.json`
- `docs/changelogs_ja.json`
- `docs/public/changelogs/en.json`
- `docs/public/changelogs/tw.json`
- `docs/public/changelogs/ja.json`
6. 任一目标文件不存在都立即退出,不允许自动创建。
## 3. 生成多语言 changelogAI 翻译)
@@ -51,9 +51,9 @@ scripts/preflight_main_clean.sh . "package.json,docs/changelogs_cn.json"
- 繁体中文:以台湾常见产品文案口吻重写,避免简体直转。
- 日文:使用自然、简洁、适合日本用户阅读的产品更新说明语气,避免中文式表达。
3. 分别更新:
- `docs/changelogs_en.json`
- `docs/changelogs_tw.json`
- `docs/changelogs_ja.json`
- `docs/public/changelogs/en.json`
- `docs/public/changelogs/tw.json`
- `docs/public/changelogs/ja.json`
4. 每个目标文件都遵循相同规则:
- 若已存在该版本,替换该版本对象。
- 若不存在,插入到数组首位。
@@ -64,10 +64,10 @@ scripts/preflight_main_clean.sh . "package.json,docs/changelogs_cn.json"
1. 提交文件必须包含:
- `package.json`
- `docs/changelogs_cn.json`
- `docs/changelogs_en.json`
- `docs/changelogs_tw.json`
- `docs/changelogs_ja.json`
- `docs/public/changelogs/cn.json`
- `docs/public/changelogs/en.json`
- `docs/public/changelogs/tw.json`
- `docs/public/changelogs/ja.json`
2. commit message`release: v<version>`(示例:`release: v0.9.6`)。
3. 仅创建 commit,不 push。
@@ -76,10 +76,10 @@ scripts/preflight_main_clean.sh . "package.json,docs/changelogs_cn.json"
## 5. 同步到 chatlab.fun 并提交
1. 从当前仓库复制:
- `docs/changelogs_cn.json` -> `../chatlab.fun/docs/public/cn/changelogs.json`
- `docs/changelogs_en.json` -> `../chatlab.fun/docs/public/en/changelogs.json`
- `docs/changelogs_tw.json` -> `../chatlab.fun/docs/public/tw/changelogs.json`
- `docs/changelogs_ja.json` -> `../chatlab.fun/docs/public/ja/changelogs.json`
- `docs/public/changelogs/cn.json` -> `../chatlab.fun/public/cn/changelogs.json`
- `docs/public/changelogs/en.json` -> `../chatlab.fun/public/en/changelogs.json`
- `docs/public/changelogs/tw.json` -> `../chatlab.fun/public/tw/changelogs.json`
- `docs/public/changelogs/ja.json` -> `../chatlab.fun/public/ja/changelogs.json`
2. 目标路径必须存在;不存在则报错退出,不自动创建目录。
3.`../chatlab.fun` 提交:
- 仅提交上述四个文件。
@@ -95,7 +95,7 @@ scripts/preflight_main_clean.sh . "package.json,docs/changelogs_cn.json"
1. 当前版本号。
2. 当前仓库 release commit hash。
3. `chatlab.fun` 仓库 docs commit hash。
4. 明确声明未执行 push
4. 明确声明"未执行 push"
## 参考
@@ -9,10 +9,10 @@ if [[ -z "$REPO_PATH" ]]; then
exit 1
fi
CN_FILE="$REPO_PATH/docs/changelogs_cn.json"
EN_FILE="$REPO_PATH/docs/changelogs_en.json"
TW_FILE="$REPO_PATH/docs/changelogs_tw.json"
JA_FILE="$REPO_PATH/docs/changelogs_ja.json"
CN_FILE="$REPO_PATH/docs/public/changelogs/cn.json"
EN_FILE="$REPO_PATH/docs/public/changelogs/en.json"
TW_FILE="$REPO_PATH/docs/public/changelogs/tw.json"
JA_FILE="$REPO_PATH/docs/public/changelogs/ja.json"
PKG_FILE="$REPO_PATH/package.json"
if [[ ! -f "$CN_FILE" || ! -f "$EN_FILE" || ! -f "$TW_FILE" || ! -f "$JA_FILE" || ! -f "$PKG_FILE" ]]; then
@@ -30,10 +30,10 @@ fi
# 注意:package.json 中的版本号需要和 release 提交一起落盘。
git -C "$REPO_PATH" add \
package.json \
docs/changelogs_cn.json \
docs/changelogs_en.json \
docs/changelogs_tw.json \
docs/changelogs_ja.json
docs/public/changelogs/cn.json \
docs/public/changelogs/en.json \
docs/public/changelogs/tw.json \
docs/public/changelogs/ja.json
# 若没有差异则不提交,避免空提交失败。
if git -C "$REPO_PATH" diff --cached --quiet; then
@@ -11,14 +11,14 @@ if [[ -z "$SOURCE_REPO" || -z "$TARGET_REPO" ]]; then
exit 1
fi
SRC_CN="$SOURCE_REPO/docs/changelogs_cn.json"
SRC_EN="$SOURCE_REPO/docs/changelogs_en.json"
SRC_TW="$SOURCE_REPO/docs/changelogs_tw.json"
SRC_JA="$SOURCE_REPO/docs/changelogs_ja.json"
DST_CN="$TARGET_REPO/docs/public/cn/changelogs.json"
DST_EN="$TARGET_REPO/docs/public/en/changelogs.json"
DST_TW="$TARGET_REPO/docs/public/tw/changelogs.json"
DST_JA="$TARGET_REPO/docs/public/ja/changelogs.json"
SRC_CN="$SOURCE_REPO/docs/public/changelogs/cn.json"
SRC_EN="$SOURCE_REPO/docs/public/changelogs/en.json"
SRC_TW="$SOURCE_REPO/docs/public/changelogs/tw.json"
SRC_JA="$SOURCE_REPO/docs/public/changelogs/ja.json"
DST_CN="$TARGET_REPO/public/cn/changelogs.json"
DST_EN="$TARGET_REPO/public/en/changelogs.json"
DST_TW="$TARGET_REPO/public/tw/changelogs.json"
DST_JA="$TARGET_REPO/public/ja/changelogs.json"
# 目标文件必须预先存在,不允许自动创建。
if [[ ! -f "$DST_CN" || ! -f "$DST_EN" || ! -f "$DST_TW" || ! -f "$DST_JA" ]]; then
@@ -38,10 +38,10 @@ cp "$SRC_JA" "$DST_JA"
# 仅提交目标文档文件,避免提交其他改动。
git -C "$TARGET_REPO" add \
docs/public/cn/changelogs.json \
docs/public/en/changelogs.json \
docs/public/tw/changelogs.json \
docs/public/ja/changelogs.json
public/cn/changelogs.json \
public/en/changelogs.json \
public/tw/changelogs.json \
public/ja/changelogs.json
if git -C "$TARGET_REPO" diff --cached --quiet; then
echo "错误: chatlab.fun 没有可提交的 changelog 变更" >&2