mirror of
https://git.openapi.site/https://github.com/desirecore/market.git
synced 2026-12-05 21:19:28 +08:00
fix(skill): 迁移技能目录先放临时目录、检查后改名发布 / Stage skill copies and publish by rename (#433)
## 概要 / Summary desirecore/desirecore#7068 评审意见 1 的修正:`migrate-from-openclaw` 复制技能目录时不再直接写到最终位置。 1. 在**目标同一父目录**下复制到临时目录 `.<目标目录名>.openclaw-import-<随机串>`。客户端的全局与智能体私有技能发现都会跳过以点开头的目录(`skills/discovery.ts` 的 `scanSkillsFromDir`),复制到一半不会出现半成品技能;前缀与平台自己的 `.<名>.import-…`(本地技能导入)、`.<名>.install-…`(智能体安装)区分开。 2. 检查:`SKILL.md` 是普通文件,frontmatter 以 `---` 行开始和结束、能解析,`description` 非空(与客户端 Schema 唯一必填项一致)。不通过即拒绝,删除临时目录,不发布。 3. 全局技能在临时目录里补版本号;私有技能不改。 4. 发布:确认目标不存在后同目录改名(macOS/Linux `test ! -e … && mv`,避免 `mv` 把目录移进已有目录;Windows `Rename-Item` / `Move-Item`,先 `Test-Path`)。目标已存在时按原重名规则(全局技能换 `-openclaw[-N]`,私有技能停下询问),绝不覆盖。Windows 被占用时重试最多 3 次,仍失败则清理并在回执中给出指引。 5. 失败只删本次创建的临时目录;中断留下的同前缀临时目录经用户同意后清理,不碰其他点目录。 6. 回执逐个技能目录写明 **成功 / 拒绝 / 已清理**;核对步骤增加「目标目录下直接就是 `SKILL.md`」。 工作区 `skills/` 下不是目录的条目不复制,在回执中列出。中英文正文同步修改,`source_hash` 重算为 `sha256:63deff0e68c3f3ea`(按 `scripts/i18n/translate.py` 的算法,先用旧哈希 `1afa5bf5e6016987` 验证算法一致)。 Follow-up to review comment 1 on desirecore/desirecore#7068. Skill directories are now copied into a dot-prefixed temporary directory next to the target (skill discovery skips dot-directories), checked (`SKILL.md` with parseable frontmatter and a non-empty `description`), and published with a same-directory rename. Existing targets are never overwritten; on failure only the run's own temporary directory is deleted; leftovers from interrupted runs are cleaned up with the user's consent. Windows uses `Rename-Item` / `Move-Item` with up to 3 retries when files are in use. The receipt states succeeded / rejected / cleaned up per skill directory. Both locales updated; `source_hash` recomputed. ## 验证 / Verification 隔离实例:desirecore#7068 分支,`npm run dev -- --home /tmp/dc-oc`,算力只用官方 `desirecore-cloud`(运行记录中 72 处 provider 字段全部是它),审批模式为「每次确认」。技能使用本 PR 的 f067801,从菜单入口预填草稿后发送。合成夹具包括:智能体「赛博牛马」及其私有技能 daily-report,全局技能 web-notes、pdf-tools(与已有技能重名)、broken-notes(SKILL.md 没有 frontmatter)、not-a-skill。另外预置了中断残留 `.web-notes.openclaw-import-k3j9x2m7`,以及平台前缀的干扰目录 `.web-notes.import-…-decoy`。 | 情况 | 结果 | | --- | --- | | 成功 | 私有技能 daily-report,以及全局技能 pdf-tools(改名为 pdf-tools-openclaw)、web-notes,都走了同父目录的 `.<目标>.openclaw-import-<12 位十六进制>` → 补版本号(仅全局技能)→ `test ! -e && mv` 发布。产物 SHA-256 与旧导入器基线逐个一致:`356893c9`、`55ed792d`、`78b63fba`、`2376c01e`;记忆和人格文件同样一致 | | 被拒 | broken-notes 的检查未通过,本次临时目录已删除,没有发布 | | 中断后清理 | 残留 `.web-notes.openclaw-import-k3j9x2m7` 经用户同意后删除,回执记为「已清理」;不同前缀的干扰目录保留 | | 技能发现 | 迁移前列表里没有两个点开头的目录 | | 来源 | `/tmp/ocs/home/.openclaw` 没有被改动 | 回执逐项写明了成功、拒绝和已清理。验证中发现一个问题:模型用文件搜索工具查残留,没有返回点开头的目录,预览时误报「无残留」,直到最终核对才用 `ls` 发现。12d3b76 改为复制前用 `ls -a` / `Get-ChildItem -Force` 列目录。273f832 按 Copilot 评审修正了 `mv` 嵌套问题。这两个提交改的是列目录和发布后的复核,没有重跑整轮界面验证;`mv` 的嵌套与移回已在本机用 shell 实测。 Verified in an isolated instance (official compute only) withf067801. Success, rejection and leftover cleanup all behaved as specified, the output hashes match the old importer baseline, and the decoy with the platform prefix was kept.12d3b76(list leftovers with the shell) and273f832(detect a nested rename, Windows uses Rename-Item only) were not re-run end to end; the `mv` nesting and move-back were tested locally in a shell.
This commit is contained in:
2 files changed
+40
-12
No files matched your search
@@ -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: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:1afa5bf5e6016987
|
||||
source_hash: sha256:e52a0cec963cbe45
|
||||
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,23 @@ 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**: 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, 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
|
||||
|
||||
|
||||
@@ -66,11 +66,12 @@
|
||||
| `AGENTS.md` | `principles.md` | 全文原样作为 `ManageAgent` 的 `principles` 字符串 |
|
||||
| `USER.md` | `memory/USER.md` | 创建后逐字节复制 |
|
||||
| `MEMORY.md` | `memory/MEMORY.md` | 创建后逐字节复制 |
|
||||
| `skills/`(整个目录) | `skills/`(该智能体私有技能) | 创建后整目录复制 |
|
||||
| `skills/` 下的每个技能子目录 | `skills/<子目录名>/`(该智能体私有技能) | 创建后逐个复制,见第 5 节「技能目录的复制方式」 |
|
||||
|
||||
- 源文件不存在就跳过对应目标,不要编造内容。`SOUL.md` 或 `AGENTS.md` 不存在时省略 `persona` / `principles` 参数,由平台生成默认模板,并在回执里说明。
|
||||
- `persona` / `principles` 传 Markdown 字符串,内容与源文件**完全一致**:不改写、不总结、不翻译、不补 L0/L1/L2 结构。
|
||||
- 全局技能 `.openclaw/skills/<目录名>/` → DesireCore 全局技能目录 `<DesireCore 数据目录>/skills/<目标目录名>/`,整目录复制(含脚本与资源)。
|
||||
- 技能目录(私有和全局)一律先复制到同一父目录下的临时目录,检查通过后改名发布,不直接写到最终位置,见第 5 节「技能目录的复制方式」。
|
||||
- 只对**全局技能**:`SKILL.md` frontmatter 没有版本号(顶层 `version` 和 `metadata.version` 都没有)时补 `1.0.0`:frontmatter 有 `metadata` 对象就写成 `metadata.version`,否则写顶层 `version`。其他内容不改。智能体私有技能原样复制,不补版本号。
|
||||
|
||||
DesireCore 数据目录的位置以当前环境为准(例如通过 `ManageAgent(action="get")` 返回的智能体目录推断),不要假设一定是 `~/.desirecore`。
|
||||
@@ -100,10 +101,23 @@ ManageAgent({
|
||||
- `avatarGeneration.enabled:false` 保持与来源一致(OpenClaw 没有图片头像);用户明确要求生成头像时再去掉。
|
||||
- 有表情时可加 `"config": { "avatar": { "char": "<表情>" } }`;参数被拒就去掉重试,并在回执说明未设置。
|
||||
- 记录返回的智能体 ID。某个智能体失败时记录原因,继续处理下一个。
|
||||
4. **复制记忆与私有技能**:把 `USER.md`、`MEMORY.md` 复制到新智能体目录的 `memory/`,把工作区 `skills/` 整目录复制到新智能体目录的 `skills/`。优先用 Shell 整目录复制(macOS/Linux:`cp -R <源> <目标>`;Windows PowerShell:`Copy-Item -Recurse -LiteralPath <源> -Destination <目标>`),没有 Shell 时用 Read + Write 逐个文件复制。目标已存在同名文件时停下询问,不覆盖。私有技能复制后不做任何修改(不补版本号)。
|
||||
5. **复制全局技能**:按第 4 节确定目标目录名后整目录复制,再按第 3 节补版本号。
|
||||
6. **核对**:对每个复制或写入的文件,用 `FileDigest` 比较来源与目标的 SHA-256(补过版本号的 `SKILL.md` 除外,改为读取确认只多了版本号),并用 `ManageAgent(action="get")` 确认每个新智能体存在且名称、描述正确。不一致时说明是哪个文件,不要假装成功。
|
||||
7. **回执**:用表格列出每个项目的结果(已迁移 / 已改名为… / 跳过及原因 / 失败及原因)和产出位置,提醒用户:新智能体可以直接对话;OpenClaw 原目录未改动,确认无误后由用户自行决定是否清理。
|
||||
4. **复制记忆与私有技能**:把 `USER.md`、`MEMORY.md` 复制到新智能体目录的 `memory/`(macOS/Linux:`cp <源> <目标>`;Windows PowerShell:`Copy-Item -LiteralPath <源> -Destination <目标>`;没有 Shell 时用 Read + Write),目标已存在同名文件时停下询问,不覆盖。工作区 `skills/` 下的每个子目录按下面「技能目录的复制方式」逐个复制到新智能体目录的 `skills/`;`skills/` 下不是目录的条目不复制,在回执中列出。私有技能复制后不做任何修改(不补版本号)。
|
||||
5. **复制全局技能**:按第 4 节确定目标目录名,按下面「技能目录的复制方式」复制,在临时目录里按第 3 节补版本号后再发布。
|
||||
6. **核对**:对每个复制或写入的文件,用 `FileDigest` 比较来源与已发布目标的 SHA-256(补过版本号的 `SKILL.md` 除外,改为读取确认只多了版本号),确认每个技能目标目录下直接就是 `SKILL.md`(没有多套一层目录),并用 `ManageAgent(action="get")` 确认每个新智能体存在且名称、描述正确。不一致时说明是哪个文件,不要假装成功。
|
||||
7. **回执**:用表格列出每个项目的结果和产出位置。技能目录逐项写明:**成功**(发布到…,改过名的写明新名称)、**拒绝**(检查未通过的原因,临时目录已删除)、**已清理**(删除了哪个临时目录、为什么);其他项目写已迁移 / 跳过及原因 / 失败及原因。提醒用户:新智能体可以直接对话;OpenClaw 原目录未改动,确认无误后由用户自行决定是否清理。
|
||||
|
||||
#### 技能目录的复制方式
|
||||
|
||||
每个技能目录(全局技能逐个;私有技能为工作区 `skills/` 下的每个子目录)按以下顺序处理,处理完一个再处理下一个:
|
||||
|
||||
1. **查残留**:在复制之前,用 Shell 列出目标父目录里以 `.<目标目录名>.openclaw-import-` 开头的目录(macOS/Linux:`ls -a <父目录>`;Windows PowerShell:`Get-ChildItem -Force -LiteralPath <父目录>`)。文件搜索工具可能不返回以点开头的目录,不能用它的结果判断没有残留。它们是之前中断留下的临时目录,告诉用户,用户同意后删除并在回执记为「已清理」。不删除其他前缀的点目录(例如平台自己的 `.<名>.import-…`、`.<名>.install-…` 临时目录)。
|
||||
2. **复制到临时目录**:临时目录与目标在**同一父目录**,名称为 `.<目标目录名>.openclaw-import-<随机串>`(随机串用 8 位以上字母数字)。以点开头的目录不会被技能发现读到,复制到一半时不会出现半成品技能。macOS/Linux:`cp -R <源目录> <临时目录>`;Windows PowerShell:`Copy-Item -Recurse -LiteralPath <源目录> -Destination <临时目录>`;没有 Shell 时用 Read + Write 逐个文件写进临时目录。
|
||||
3. **检查**:临时目录里必须有普通文件 `SKILL.md`,开头是以 `---` 行开始和结束的 YAML frontmatter,能解析,且 `description` 非空。不满足就**拒绝**:删除这个临时目录,不发布,回执写明原因。检查通过后,全局技能按第 3 节在临时目录里补版本号;私有技能不改。
|
||||
4. **发布**:先确认目标目录不存在。已存在时不覆盖:全局技能按第 4 节换下一个名称,私有技能停下询问。然后在同一父目录内改名发布,改名后确认确实发布到了目标:
|
||||
- macOS/Linux:`test ! -e <目标目录> && mv <临时目录> <目标目录>`(Linux 可加 `-T`,目标已存在且非空时直接失败)。检查和改名之间如果有别的程序先建了目标目录,`mv` 会把临时目录移进去而不报错,所以改名后必须确认 `<目标目录>/SKILL.md` 存在、`<目标目录>/<临时目录名>` 不存在。临时目录被移进了目标时,用 `mv <目标目录>/<临时目录名> <临时目录>` 移回原处,再按上面的重名规则处理。
|
||||
- Windows PowerShell:用 `Test-Path -LiteralPath <目标目录>` 确认目标不存在后,执行 `Rename-Item -LiteralPath <临时目录> -NewName <目标目录名>`。目标已存在时 `Rename-Item` 报错而不会把临时目录移进去,此时按重名规则处理。不要用 `Move-Item` 发布:目标是已有目录时它会把临时目录移进去。报文件被占用或拒绝访问时,等几秒重试,最多 3 次;仍失败就按第 5 步清理,并在回执里请用户关闭占用该目录的程序(如编辑器、文件管理器、杀毒扫描)后重新迁移这一项。
|
||||
- 不要改用复制覆盖。
|
||||
5. **失败清理**:复制、检查或发布任何一步失败时,只删除本次创建的这个临时目录(macOS/Linux:`rm -rf -- <临时目录>`;Windows PowerShell:`Remove-Item -Recurse -Force -LiteralPath <临时目录>`),删除前核对路径以 `.<目标目录名>.openclaw-import-` 开头、且就是本次创建的那个。不碰目标目录和其他任何目录。删除也失败时在回执中写明临时目录的位置。
|
||||
|
||||
### 6. 边界
|
||||
|
||||
|
||||
Reference in new issue
Block a user