Diamond-Technologies-Inc/account-migration-skill

GitHub: Diamond-Technologies-Inc/account-migration-skill

这是一个用于在两个 Claude 账号之间迁移项目、对话和上下文的技能,解决官方数据导出无导入功能的问题。

Stars: 0 | Forks: 0

# 账号迁移 一个 Claude 技能,引导用户在两个 Claude 账号之间迁移项目、对话、累积的上下文、自定义技能和计划任务——填补 Anthropic 数据导出功能缺乏导入操作的空白。 ## 功能介绍 该技能在源账号和目标账号上并行运行两条轨道: - **轨道 A(源账号)** —— 处理用户的数据导出,从已保存的 Chats 页面副本中恢复每个项目的归属信息,逐个引导用户对 claude.ai 上的每个项目进行选择/跳过决策,并将选中的项目重建为磁盘上的文件夹,包含自定义指令、知识库和每个对话的记录。源机器上的 Cowork 项目通过用户运行的会话重建脚本发现(典型路径中无需手动选择循环)——该技能通过 session-info MCP 直接拉取每个项目的会话记录,并询问每个项目的内存转储。自定义的 `.skill` 安装程序(包括此程序)和计划任务会自动从安装中捕获到新账号。一个 `tracker.html` 文件承载跨账号状态。 - **轨道 B(目标账号)** —— 同一技能,在新账号上调用。读取源端写入的跟踪器,从快照初始化新账号的全局内存,立即验证初始化数据,通过创建指向现有磁盘文件夹的新 Cowork 项目来引导重新链接每个项目(第 1 部分重建 + 第 2 部分 Cowork),通过 scheduled-tasks MCP 在新账号上主动重新创建每个捕获的计划任务,引导安装捕获的自定义技能(过滤掉目标账号上已有的),引导下载无法从导出中提取的二进制文件,并进行清理。清理是可选的——如果你说 `later`,技能会将迁移标记为延迟,并在后续调用中重新处理延迟的项目。 方向无关:个人→企业,企业→个人,个人→个人。方向只是元数据,不影响机制。 **两种范围:** 全账号(所有项目)或单项目(一次迁移一个项目——适用于重做和单次转移)。技能从你的调用措辞中检测范围,并在继续前确认。 ## 仓库布局 ``` SKILL.md ← orchestration + discipline rules assets/ ← prompts and templates written to the user's hub README-template.md memory-capture-prompt.md memory-seed-prompt.md migration-prompt-template.md ← fallback path only as of v1.5 validation-prompt.md cowork-memory-dump-prompt.md ← per-project source-side memory dump cowork-memory-restore-prompt.md ← destination-side memory restore (also embedded in blueprints) cowork-session-transcript-dump-prompt.md ← fallback path only as of v1.5 recon-script-windows.ps1.template ← Windows sessions-recon template recon-script-mac.sh.template ← macOS sessions-recon template references/ ← longer reference material the skill reads on demand skill-user-facing-text.md ← canonical locked copy of every user-facing prompt architecture-notes.md ← three project categories, four artifact kinds, tracker schema scripts/ ← Python scripts run via the skill's bash environment extract_export.py ← splits the data export into per-conversation transcripts parse_allchats.py ← recovers per-project attribution from saved Chats page reconstruct.py ← writes per-project folders for Part 1 reconstructed projects reshape_and_extract.py ← extracts artifacts (four categories) per conversation generate_blueprint.py ← writes transition-data/project-blueprint.md for any project blueprint_coverage_check.py ← end-of-Track-A gate: every picked project has a blueprint derive_install_root.py ← self-determines install root + UUIDs from the mount table render_recon_script.py ← renders the OS-appropriate sessions-recon script parse_recon_csv.py ← parses the recon CSV into structured per-project JSON package_self.py ← repackages this skill into a .skill for Track B export_custom_skills.py ← repackages other installed user skills into .skill files README.md ← this file LICENSE ← MIT License CHANGELOG.md ← version history ``` 技能源文件位于仓库根目录,便于浏览。预构建的 `.skill` 二进制文件通过 [GitHub Releases](https://github.com/dbachen-dt/account-migration-skill/releases) 分发,而不是提交到仓库,这样源历史保持清晰,每个发布版本都有明确的版本到二进制文件的映射。`.skill` 文件就是一个 zip 包,包含一个顶级 `account-migration/` 文件夹,里面是源文件——通过使用 `skill-creator` 的 `package_skill.py` 或任何标准 zip 工具对这些文件的副本进行压缩来生成(具体命令见下文“从源代码构建”)。 ## 安装说明 ### 选项 1 — Cowork(推荐大多数用户使用) 1. 从 [Releases](https://github.com/dbachen-dt/account-migration-skill/releases/latest) 页面下载最新的 `account-migration.skill`。 2. 在 Cowork 中:**自定义 → + → 技能 → 上传**,选择 `.skill` 文件。 3. 打开一个新对话。告诉 Claude *"我需要迁移到一个新的 Claude 账号"*(或任何自然语言的表述)。技能会自行识别并询问你从哪一边开始。 ### 选项 2 — 从源代码构建(适用于想要验证二进制文件的用户) `.skill` 文件就是一个 zip 包,包含一个以技能命名的顶级文件夹(`account-migration/`),里面是源文件。此仓库中的源文件位于根目录,因此构建 `.skill` 意味着将它们包裹在该文件夹名中并压缩。 1. 克隆或下载此仓库。 2. 验证源文件完整(`SKILL.md`、`assets/`、`references/`、`scripts/`——参见上方的仓库布局)。 3. 构建 `.skill`(显示 Linux/macOS shell 命令;Windows 用户可使用 7-Zip 或 PowerShell 的 `Compress-Archive` 等效命令): mkdir -p _build/account-migration cp -r SKILL.md assets references scripts _build/account-migration/ (cd _build && zip -r ../account-migration-rebuilt.skill account-migration) rm -rf _build 4. 从 [Releases](https://github.com/dbachen-dt/account-migration-skill/releases/latest) 页面下载已发布的 `account-migration.skill` 并进行比较: unzip -l account-migration.skill # 已发布二进制文件的文件列表 unzip -l account-migration-rebuilt.skill # 你构建的二进制文件的文件列表 文件列表应该匹配。要进行更深入的检查,解压两个文件并执行 `diff -r`: unzip -d _shipped account-migration.skill unzip -d _rebuilt account-migration-rebuilt.skill diff -r _shipped _rebuilt rm -rf _shipped _rebuilt 你应该看不到内容差异(只有文件系统元数据如时间戳不同)。 5. 通过与选项 1 相同的 Cowork UI 上传步骤安装你构建的二进制文件。 这就是你如何审计已发布的 `.skill` 是否与此仓库中的源代码匹配的方式。 ## 工作原理(架构概述) ### 轨道 A 流程 ``` Prompt 0 (which side?) → "old" ↓ Scope selection (whole-account or single-project) ↓ Install recon (Step 2.0) Skill self-determines its install root from the sandbox mount table and renders an OS-appropriate sessions-recon script (PowerShell on Windows, bash+python3 on macOS). User runs it natively to produce a CSV of per-session metadata (sessionId, spaceId, title, timestamps, working folders). parse_recon_csv.py groups rows by spaceId — that's the project-membership map. ↓ Part 1 — claude.ai web/chat projects Drop the data export (.zip) and a saved copy of the Chats page (.html) into the hub → extract_export.py splits conversations.json into per-conversation files → parse_allchats.py recovers project attribution from the Chats HTML → tracker.html written + rendered as a Cowork sidebar artifact → Catch-all Cowork project created by user → Per-project walk-through (pick / skip / quit) — alphabetical → reconstruct.py + reshape_and_extract.py + generate_blueprint.py run inline after each pick ↓ Part 2 — Cowork projects on the source machine Recon-driven (primary): for each in-scope spaceId, the hub session pulls every attributed transcript via session-info MCP and writes them to disk. User pastes a per-project memory-dump prompt in each project's own source-account Cowork session (Cowork space memory isn't reachable across spaces). generate_blueprint.py writes transition-data/project-blueprint.md per project. ↓ Custom-skills capture (Step 3.5) package_self.py repackages this migration skill into the hub's skills/ folder. export_custom_skills.py walks the .claude/skills/ mount, filters bundled anthropic-skills + the migration skill, and repackages every other user custom skill as a .skill file into the same folder. ↓ Scheduled-tasks capture (Step 3.7, multi-project only) Skill enumerates active scheduled tasks via the scheduled-tasks MCP, captures each task's cron, prompt body, dependencies, and writes scheduled-tasks-export.md. Track B will recreate these on the new account. ↓ Blueprint coverage check (Step 3.6) blueprint_coverage_check.py verifies every picked project has a blueprint before the user is told the old account is safe to delete. ↓ Track A wrap README - Final Transition + memory-capture-prompt + tracker handoff state + scheduled-tasks-export written to hub. User runs memory-capture-prompt on the old account (no-project Chat conversation). ``` ### 轨道 B 流程 ``` Prompt 0 (which side?) → "new" ↓ Hub access (detect-at-runtime OR folder picker) Skill reads tracker.html's embedded handoff-state JSON. If the tracker shows a deferred-cleanup migration, the skill offers to re-walk skipped items + re-fire cleanup; otherwise proceeds to Phase 2. ↓ Memory seed (Phase 2) User pastes memory-seed-prompt in a no-project Claude Chat conversation, attaching memory-capture.md. ↓ Memory validation (Step 6.5 — immediate) Still in the same Chat conversation: user pastes a validation prompt and confirms the seed worked. Done while the user is still on the Chat side (avoids an end-of-Track-B context switch back to Chat). ↓ Catch-all setup (Phase 3) User imports the catch-all folder as a Cowork project on the new account. ↓ Per-project walk-through (Phase 4 — Step 8) For each Part 1 reconstructed project + Part 2 Cowork project (alphabetical): User creates a Cowork project (Choose existing folder) → skill verifies the project's blueprint → User pastes Custom Instructions + a short bootstrap prompt (the bootstrap points the destination Claude at the blueprint's Section 7 directive, which itself drives memory restore + history archival) ↓ Scheduled-tasks recreation (Step 8.5 — active walk-through, multi-project only) For each captured task: skill calls mcp__scheduled-tasks__create_scheduled_task directly with the cron, prompt, and description from the source-side export. User says "recreate" / "skip" per task. Folder-dependency reattach surfaced as a manual reminder per task (Cowork UI step, not MCP-exposed). ↓ Custom-skills installation (Step 8.7 — active walk-through, multi-project only) Skill reads .claude/skills/ on the destination, filters out anything already installed (notably this migration skill itself), and surfaces the pending .skill files as clickable "Save skill" cards. User installs what they want; skill re-reads the mount on `done` to confirm. ↓ Binary recovery (Phase 5) Walk through _ARTIFACTS_TO_RECOVER.md conversation by conversation, downloading files from claude.ai before the old account is deleted. Skill ticks each conversation's checkboxes after the user confirms recovery. ↓ Cleanup (Phase 7) User says `done` (archive both hub Cowork projects + delete on-disk hub), `later` (leave hub in place; skill flags migration as deferred-cleanup and re-walks any skipped items on a subsequent run), or `quit`. ``` ### 导出中的四种构件类型 Claude 数据导出的对话消息可以包含四种模式的助手生成内容,每种都需要不同的处理: - `tool_use: artifacts` —— Claude 的网页 Artifacts 面板。内容是内联的;提取到每个对话的 `artifacts/` 子文件夹中。 - `tool_use: create_file` —— 通过 Claude 的网页文件工具(通常是构建脚本)写入的文件。内容是内联的;类似地提取。 - `tool_use: bash` heredoc / tee / 重定向写入 —— 由 `cat << EOF > path` heredoc(内容在 bash 命令本身中是内联的)或 `tee`/`>` 重定向(内容来自前一个命令的 stdout)写入的文件内容。完整的 heredoc 被提取;tee/重定向写入和截断的 heredoc(渲染器的 `[Omitted long matching line]` 标记)则被列在 `_ARTIFACTS_TO_RECOVER.md` 中——仅从记录本身无法恢复内容。 - `tool_use: present_files` —— 二进制输出,如 `.docx`、`.xlsx`、`.pdf`、`.pptx`。导出中只有文件路径引用;二进制文件本身不在其中。这些被列在 `_ARTIFACTS_TO_RECOVER.md` 中,以便在旧账号删除前从 claude.ai 手动恢复。 ### 跟踪器 JSON 模式 `tracker.html` 文件包含一个嵌入的 `