Skip to content

[AI][Fix #26] 防止 slug 冲突时静默覆盖已有前任(数据丢失)#31

Open
josephmqiu wants to merge 1 commit into
perkfly:mainfrom
josephmqiu:fix/26-slug-collision-data-loss
Open

[AI][Fix #26] 防止 slug 冲突时静默覆盖已有前任(数据丢失)#31
josephmqiu wants to merge 1 commit into
perkfly:mainfrom
josephmqiu:fix/26-slug-collision-data-loss

Conversation

@josephmqiu

Copy link
Copy Markdown

Important

🤖 AI 声明:本 PR 由 AI 模型 Claude Fable 5(Anthropic,运行于 Claude Code)编写并在本地测试,经 @josephmqiu 授权提交。

Fixes #26

问题

未安装 pypinyin 时(文档标注它为"可选"),slugify() 的 fallback 会丢弃所有非 ASCII 字符——任何纯中文昵称都退化为 "ex";而 create_skill() 全程 exist_ok=True 且无条件覆盖写入。组合结果:创建第二个前任会静默覆盖第一个的全部数据(memories.md / persona.md / meta.json),无提示、无存档、不可恢复。

改动

  • slugify() 生成失败时返回空字符串(不再退化为 "ex"),create 路径对空 slug 明确报错并提示安装 pypinyin 或显式传入 --slug
  • create_skill() 在目标目录已存在时抛出 FileExistsError,拒绝静默覆盖;CLI 捕获后友好报错退出
  • SKILL.md(中英双语)Step 5 新增第 0 步:写入前检查 exes/{slug} 是否已存在,存在则停下询问用户(换 slug 或确认覆盖并先存档)
  • README / README_EN / requirements.txt:把 pypinyin 如实标注为「中文昵称必需」

本地测试

== 1. 未安装 pypinyin + 中文昵称 -> 明确报错 ==
$ PYTHONPATH=<stub> python3 tools/skill_writer.py --action create --name 小美 --base-dir <test>/exes
错误:无法从昵称生成 slug(中文昵称需要安装 pypinyin:pip3 install pypinyin),或请显式传入 --slug
exit: 1

== 2. 显式 slug -> 正常创建 ==
$ python3 tools/skill_writer.py --action create --name 小美 --slug xiaomei --base-dir <test>/exes
✅ Skill 已创建:.../exes/xiaomei
exit: 0

== 3. 同名 slug 再创建 -> 拒绝覆盖 ==
$ python3 tools/skill_writer.py --action create --name 阿静 --slug xiaomei --base-dir <test>/exes
错误:.../exes/xiaomei 已存在。请换一个 slug,或先用 version_manager.py 存档/手动备份后再删除,避免静默覆盖导致数据丢失
exit: 1

== 4. 第一个前任的数据完好 ==
$ grep '"name"' <test>/exes/xiaomei/meta.json
  "name": "小美",

🤖 Generated with Claude Code

https://claude.ai/code/session_01Qxv8G25EYkYzQyY6FdJ6qH

Without pypinyin (documented as optional), slugify() stripped all
non-ASCII characters and fell back to "ex" for every Chinese-only
nickname, and create_skill() overwrote existing files unconditionally
(exist_ok=True) — so creating a second ex silently destroyed the first,
with no warning and no archive.

- slugify() now returns "" instead of falling back to "ex"; the create
  path exits with a clear error suggesting pypinyin or an explicit --slug
- create_skill() raises FileExistsError when the target directory
  already exists instead of overwriting
- SKILL.md (zh + en) Step 5 gains a step-0 collision check: stop and ask
  the user instead of silently overwriting
- README/README_EN/requirements.txt: pypinyin documented as required for
  Chinese nicknames

Fixes perkfly#26

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qxv8G25EYkYzQyY6FdJ6qH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AI审查][Bug] 未安装 pypinyin 时中文昵称 slug 全部退化为 "ex",创建第二个前任会静默覆盖第一个(数据丢失)

1 participant