Cheat Migrate
把老用户的 .cheat-state.json 升级到当前 schema_version。读 migrations/registry.md...
Install
npx skills add XBuilderLAB/cheat-on-content --skill cheat-migrate -g -a claude-code -y- Repository
- XBuilderLAB/cheat-on-content7.4k
- Category
- Engineering
- Updated
- 9d ago
- License
- MIT
- Context cost
- Lightabout 1,451 tokens
- Runs scripts
- No, instructions only
What it does
把老用户的 .cheat-state.json 升级到当前 schema_version。读 migrations/registry.md 算迁移链,按顺序应用每一步迁移文件。幂等:跑两次结果一样。失败停在中间版本不前进。触发词:"迁移"/"升级 state"/"migrate"/"我的 state 是老版本"/"schema 版本不对"。
/cheat-migrate, Schema 版本迁移
把用户 .cheat-state.json 从旧 schema_version 升级到 cheat-on-content 当前期望的 LATEST_SCHEMA。
Overview
[用户:迁移 / 或 SessionStart 提示后用户跑]
↓
[Phase 0: 读 .cheat-state.json + migrations/registry.md → 确定迁移链]
↓
[Phase 1: dry-run(默认)展示迁移计划,等用户确认]
↓
[Phase 2: 备份 .cheat-state.json → .cheat-state.json.backup-<timestamp>]
↓
[Phase 3: 按顺序对每个 step 应用对应迁移文件的 HOW 段]
↓
[Phase 4: 验证升级后 state 文件能被解析 + schema_version 已更新]
↓
[Phase 5: 报告 + 提示如有备份需要清理]
Constants
- REGISTRY_PATH =
${SKILL_DIR}/../../migrations/registry.md, 版本链单一来源 - MIGRATIONS_DIR =
${SKILL_DIR}/../../migrations/, 迁移文件目录 - DRY_RUN_BY_DEFAULT = true, 首次跑展示计划,不直接改文件
- BACKUP_BEFORE_WRITE = true, 写之前必备份;备份文件保留至下次成功 init / 用户手动清理
- STOP_ON_STEP_FAILURE = true, 任何 step 失败 → 停在中间版本,不前进,不回滚
💡 调用时覆盖:
/cheat-migrate, dry-run: false直接执行 //cheat-migrate, to: 1.2仅升到指定版本
Inputs
| 必填 | 来源 |
|---|---|
.cheat-state.json | 用户项目根 |
migrations/registry.md | LATEST_SCHEMA + 版本链表 |
migrations/<from>-to-<to>.md | 每步具体迁移指令 |
Workflow
Phase 0: 确定迁移链
- 读
.cheat-state.json→ 解析current_version = state.schema_version - 读
migrations/registry.md→ 解析LATEST_SCHEMA字段(行:LATEST_SCHEMA = "X.Y") - 解析
args.to覆盖(如有);否则 target = LATEST_SCHEMA - 解析
args.from覆盖(罕见场景:用户的 state 文件 schema 字段坏了,强制指定起点) - 状态判断:
current_version == target→ 输出"✅ state 已是 {target},无需迁移" → 退出current_version > target(比如用户跑了 dev 版又切回 release)→ 报错"无法降级,请手动调整或重新 init"current_version < target→ 继续,从注册表查出迁移链
- 从注册表"版本链"表算出
chain = [(from, to, file), ...],按顺序串起 current → target
如果某一步在注册表里缺失(比如 current_version 不在表里)→ 报错并展示"目前已知版本:[1.0, 1.1, ...]",让用户检查。
Phase 1: dry-run
输出迁移计划:
📋 迁移计划
当前版本: 1.0
目标版本: 1.2
将按顺序跑 2 步:
