fix(skill): 改名发布后确认未嵌进已有目录 / Detect a nested rename after publishing

检查与 mv 之间若目标被别的程序建出,mv 会把临时目录移进去且返回成功。
改名后确认 <目标>/SKILL.md 存在、<目标>/<临时目录名> 不存在,嵌进去时移回
再按重名规则处理;Linux 可用 mv -T。Windows 只用 Rename-Item(目标已存在时
报错),不用 Move-Item 发布。重算 source_hash。

If the target appears between the check and mv, mv nests the temporary
directory and still succeeds. After renaming, confirm <target>/SKILL.md exists
and <target>/<temporary name> does not; move it back and apply the conflict
rules if nested. Windows publishes with Rename-Item only. source_hash
recomputed.
This commit is contained in:
yige committed 2026-12-03 09:15:40 -05:00
1 parent 12d3b76489
commit 273f832499
2 files changed
+10 -4

No files matched your search

+6 -3
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:57df4b3436266ee3
source_hash: sha256:e52a0cec963cbe45
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:57df4b3436266ee3
source_hash: sha256:e52a0cec963cbe45
translated_by: human
market:
icon: >-
@@ -164,7 +164,10 @@ Handle each skill directory (each global skill; for private skills, each subdire
1. **Look for leftovers**: before copying, use the shell to list the directories in the target's parent directory whose names start with `.<target directory name>.openclaw-import-` (macOS/Linux: `ls -a <parent directory>`; Windows PowerShell: `Get-ChildItem -Force -LiteralPath <parent directory>`). File search tools may omit directories whose names start with a dot, so their results cannot show that there are no leftovers. 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.
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, and confirm afterwards that it really landed on the target:
- macOS/Linux: `test ! -e <target directory> && mv <temporary directory> <target directory>` (on Linux add `-T`, which fails outright when the target exists and is not empty). If another program creates the target between the check and the rename, `mv` moves the temporary directory inside it without an error, so after renaming confirm that `<target directory>/SKILL.md` exists and `<target directory>/<temporary directory name>` does not. If the temporary directory ended up inside the target, move it back with `mv <target directory>/<temporary directory name> <temporary directory>` and apply the conflict rules above.
- Windows PowerShell: after `Test-Path -LiteralPath <target directory>` confirms the target does not exist, run `Rename-Item -LiteralPath <temporary directory> -NewName <target directory name>`. When the target already exists, `Rename-Item` fails instead of moving the temporary directory inside it; apply the conflict rules then. Do not publish with `Move-Item`: when the target is an existing directory it moves the temporary directory inside it. 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