fix(skill): 迁移技能目录先放临时目录、检查后改名发布 / Stage skill copies and publish by rename

migrate-from-openclaw 复制技能目录时,先复制到目标同一父目录下以点开头的
临时目录 .<目标>.openclaw-import-<随机串>(技能发现跳过点目录),检查
SKILL.md 与 frontmatter 后用同目录改名发布;目标已存在时按原重名规则处理、
不覆盖;失败只删本次创建的临时目录;中断残留经用户同意后清理。Windows
用 Rename-Item / Move-Item,占用时重试或报告。回执逐项写明成功、拒绝或
已清理。同步重算中英文 source_hash。

Skill directories are copied into a dot-prefixed temporary directory next to
the target, checked (SKILL.md and frontmatter), then published with a
same-directory rename. Existing targets are never overwritten, failures delete
only the run's own temporary directory, and leftovers from interrupted runs are
cleaned up with the user's consent. The receipt states succeeded / rejected /
cleaned up per skill directory. source_hash recomputed.
This commit is contained in:
yige committed 2026-12-03 08:42:13 -05:00
1 parent 4245947c4c
commit f067801c72
2 files changed
+34 -12

No files matched your search

+18 -7
View File
@@ -29,7 +29,7 @@ metadata:
description: >-
把本机 OpenClaw 数据目录(~/.openclaw/)中的智能体与技能迁移到 DesireCore:按固定映射(SOUL.md→persona.md、AGENTS.md→principles.md、USER.md/MEMORY.md→memory/、workspace skills→智能体私有技能)经 ManageAgent 创建智能体并复制技能,迁移后逐项核对。Use when 用户要求从 OpenClaw 导入、迁移或搬家智能体与技能(migrate / import from OpenClaw)。需要本机已有 OpenClaw 数据目录;不安装、不运行 OpenClaw。
body: ./SKILL.zh-CN.md
source_hash: sha256:1afa5bf5e6016987
source_hash: sha256:63deff0e68c3f3ea
translated_by: human
en-US:
name: Migrate from OpenClaw
@@ -37,7 +37,7 @@ metadata:
description: >-
Migrate agents and skills from the local OpenClaw data directory (~/.openclaw/) into DesireCore using a fixed mapping (SOUL.md→persona.md, AGENTS.md→principles.md, USER.md/MEMORY.md→memory/, workspace skills→agent-private skills): create agents with ManageAgent, copy skills, then verify every item. Use when the user asks to import or migrate agents or skills from OpenClaw. Requires an existing local OpenClaw data directory; does not install or run OpenClaw.
body: ./SKILL.md
source_hash: sha256:1afa5bf5e6016987
source_hash: sha256:63deff0e68c3f3ea
translated_by: human
market:
icon: >-
@@ -117,11 +117,12 @@ If the workspace directory does not exist, record the agent as "cannot migrate:
| `AGENTS.md` | `principles.md` | Full text, unchanged, as the `ManageAgent` `principles` string |
| `USER.md` | `memory/USER.md` | Byte-for-byte copy after creation |
| `MEMORY.md` | `memory/MEMORY.md` | Byte-for-byte copy after creation |
| `skills/` (whole directory) | `skills/` (the agent's private skills) | Whole-directory copy after creation |
| Each skill subdirectory of `skills/` | `skills/<subdirectory name>/` (the agent's private skills) | Copied one by one after creation; see "How to copy a skill directory" in section 5 |
- Skip a target when its source file does not exist; never invent content. When `SOUL.md` or `AGENTS.md` is missing, omit the `persona` / `principles` parameter so the platform generates its default template, and mention it in the receipt.
- Pass `persona` / `principles` as Markdown strings whose content is **exactly** the source file: do not rewrite, summarize, translate, or add an L0/L1/L2 structure.
- Global skill `.openclaw/skills/<directory>/` → DesireCore global skills directory `<DesireCore data directory>/skills/<target directory>/`, copied as a whole directory (including scripts and resources).
- Skill directories (private and global) are always copied into a temporary directory in the same parent directory first and published by renaming once they pass the check; never write them straight to the final location. See "How to copy a skill directory" in section 5.
- **Global skills only**: when the `SKILL.md` frontmatter has no version (neither top-level `version` nor `metadata.version`), add `1.0.0`: write `metadata.version` if the frontmatter has a `metadata` object, otherwise a top-level `version`. Change nothing else. Agent-private skills are copied as they are, with no version added.
Determine the DesireCore data directory from the current environment (for example from the agent directory returned by `ManageAgent(action="get")`); do not assume it is `~/.desirecore`.
@@ -151,10 +152,20 @@ ManageAgent({
- `avatarGeneration.enabled:false` keeps parity with the source (OpenClaw has no image avatar); drop it only when the user explicitly asks for a generated avatar.
- When there is an emoji you may add `"config": { "avatar": { "char": "<emoji>" } }`; if the parameter is rejected, retry without it and say so in the receipt.
- Record the returned agent ID. If one agent fails, record the reason and continue with the next.
4. **Copy memory and private skills**: copy `USER.md` and `MEMORY.md` into the new agent's `memory/`, and copy the workspace `skills/` directory as a whole into the new agent's `skills/`. Prefer a whole-directory shell copy (macOS/Linux: `cp -R <source> <target>`; Windows PowerShell: `Copy-Item -Recurse -LiteralPath <source> -Destination <target>`); without a shell, copy file by file with Read + Write. If a target file already exists, stop and ask; never overwrite. Leave copied private skills unchanged (no version added).
5. **Copy global skills**: pick the target directory name per section 4, copy the whole directory, then add the version per section 3.
6. **Verify**: for every copied or written file, compare the source and target SHA-256 with `FileDigest` (except a `SKILL.md` that received a version; read it instead and confirm the version is the only addition), and use `ManageAgent(action="get")` to confirm each new agent exists with the right name and description. On any mismatch, name the file; never claim success.
7. **Receipt**: list each item's result in a table (migrated / renamed to … / skipped with reason / failed with reason) together with where it was written, and remind the user that the new agents are ready to chat and that the original OpenClaw directory is untouched; whether to clean it up is the user's decision.
4. **Copy memory and private skills**: copy `USER.md` and `MEMORY.md` into the new agent's `memory/` (macOS/Linux: `cp <source> <target>`; Windows PowerShell: `Copy-Item -LiteralPath <source> -Destination <target>`; without a shell, Read + Write). If a target file already exists, stop and ask; never overwrite. Copy each subdirectory of the workspace `skills/` into the new agent's `skills/` one by one, as described in "How to copy a skill directory" below; entries in `skills/` that are not directories are not copied and are listed in the receipt. Leave copied private skills unchanged (no version added).
5. **Copy global skills**: pick the target directory name per section 4, copy as described in "How to copy a skill directory" below, and add the version per section 3 inside the temporary directory before publishing.
6. **Verify**: for every copied or written file, compare the SHA-256 of the source and the published target with `FileDigest` (except a `SKILL.md` that received a version; read it instead and confirm the version is the only addition). Confirm that each skill's target directory holds `SKILL.md` directly (no extra nested directory), and use `ManageAgent(action="get")` to confirm each new agent exists with the right name and description. On any mismatch, name the file; never claim success.
7. **Receipt**: list each item's result in a table together with where it was written. For every skill directory state one of: **succeeded** (published to …, with the new name if it was renamed), **rejected** (why the check failed; the temporary directory was deleted), **cleaned up** (which temporary directory was deleted and why). For other items: migrated / skipped with reason / failed with reason. Remind the user that the new agents are ready to chat and that the original OpenClaw directory is untouched; whether to clean it up is the user's decision.
#### How to copy a skill directory
Handle each skill directory (each global skill; for private skills, each subdirectory of the workspace `skills/`) in this order, and finish one before starting the next:
1. **Look for leftovers**: list the directories in the target's parent directory whose names start with `.<target directory name>.openclaw-import-`. They are temporary directories left by an interrupted run. Tell the user, delete them once the user agrees, and record them as "cleaned up" in the receipt. Do not delete dot-directories with any other prefix (for example the platform's own `.<name>.import-…` and `.<name>.install-…` temporary directories).
2. **Copy into a temporary directory**: the temporary directory sits in the **same parent directory** as the target and is named `.<target directory name>.openclaw-import-<random>` (at least 8 random letters and digits). Skill discovery skips directories whose names start with a dot, so a half-finished copy never shows up as a skill. macOS/Linux: `cp -R <source directory> <temporary directory>`; Windows PowerShell: `Copy-Item -Recurse -LiteralPath <source directory> -Destination <temporary directory>`; without a shell, write each file into the temporary directory with Read + Write.
3. **Check**: the temporary directory must contain a regular file `SKILL.md` that starts with YAML frontmatter opened and closed by `---` lines, parses, and has a non-empty `description`. Otherwise **reject** it: delete this temporary directory, do not publish, and give the reason in the receipt. Once the check passes, add the version to global skills per section 3 inside the temporary directory; leave private skills unchanged.
4. **Publish**: first confirm that the target directory does not exist. If it does, never overwrite: for a global skill take the next name per section 4; for a private skill stop and ask. Then publish by renaming within the same parent directory: macOS/Linux `test ! -e <target directory> && mv <temporary directory> <target directory>` (when the target is an existing directory, `mv` moves the temporary directory inside it, so the check cannot be skipped); Windows PowerShell `Rename-Item -LiteralPath <temporary directory> -NewName <target directory name>`, or `Move-Item -LiteralPath <temporary directory> -Destination <target directory>`, in both cases after `Test-Path -LiteralPath <target directory>` confirms the target does not exist. If Windows reports the files are in use or access is denied, wait a few seconds and retry, at most 3 times; if it still fails, clean up per step 5 and ask the user in the receipt to close whatever holds the directory (an editor, a file manager, an antivirus scan) and migrate this item again. Never fall back to copying over the target.
5. **Clean up on failure**: when copying, checking or publishing fails, delete only the temporary directory this run created (macOS/Linux: `rm -rf -- <temporary directory>`; Windows PowerShell: `Remove-Item -Recurse -Force -LiteralPath <temporary directory>`), after confirming that its path starts with `.<target directory name>.openclaw-import-` and that it is the one created in this run. Never touch the target directory or any other directory. If deleting fails too, give the temporary directory's location in the receipt.
### 6. Boundaries