Skill: kid0114/agent-migration (version 1.0.1)

--- name: agent-migration description: Safely rename or migrate an OpenClaw agent by updating config and naming, migrating session content, fixing session metadata, restarting, verifying, and asking separately before deleting the old agent. input: old agent id, new agent id, new workspace, optional model change output: new agent active; prior session content migrated unless explicitly skipped; old agent deletion handled only after separate confirmation --- # Agent Migration Use this skill when the user wants to rename or migrate an OpenClaw agent safely. ## Scope This skill handles: - agent id rename - workspace rename - config/path updates - prior session content migration - session display metadata updates - restart and verification - separate deletion confirmation for the old agent ## Defaults and boundaries - Confirm old id, new id, new workspace, and whether model also changes. - Migrate prior session content by default unless the user explicitly says not to. - Do not skip migration just because a session does not look active. - Do not hard-edit active lock files or force-rewrite a live session shell. - Restart is required after migration. - Never delete the old agent without a separate user confirmation. ## Files involved - config: `~/.openclaw/openclaw.json` - agent dirs: `~/.openclaw/agents/<id>/...` - workspace: `/home/yln/claw-workspace/<name>` - session metadata such as `sessions.json` ## Use the included files - `references/checklist.md` - `references/cleanup.md` - `scripts/inspect_agent_migration.sh` - `scripts/copy_session_content.sh` - `scripts/verify_agent_migration.sh` ## Recommended commands ```bash bash skills/agent-migration/scripts/inspect_agent_migration.sh <old-id> <new-id> bash skills/agent-migration/scripts/copy_session_content.sh <old-id> <new-id> bash skills/agent-migration/scripts/verify_agent_migration.sh <old-id> <new-id> ``` ## Guardrails - Keep config, workspace, and naming changes consistent. - Update session display-layer metadata as part of the migration. - Verify the new agent before offering deletion of the old one. - Use `references/cleanup.md` only after the user separately confirms deletion.

path: README.md
content: # agent-migration

A higher-privilege OpenClaw skill for renaming or migrating an agent safely.

## What it handles
- agent id rename
- workspace rename
- session content migration
- session display metadata rename (`sessions.json`, related paths)
- restart + verification
- separate confirmation before deleting the old agent

## Typical owner
Usually run by the **`master`** agent.

## Permission note
This skill generally needs elevated local access because it edits OpenClaw config, agent directories, workspace paths, and session metadata.

## Safe default
It **does migrate session content by default** and **does not delete the old agent by default**.


path: metadata.txt
content: Suggested ClawHub summary:
A high-permission skill for safely renaming or migrating OpenClaw agents. It updates config and workspace naming, migrates prior session content, rewrites session display metadata, restarts, verifies, and only deletes the old agent after an extra confirmation.

Suggested notes:
- Typical owner: master
- Permission level: high / local persistent changes
- Safe default: migrate content automatically, ask separately before delete


path: references/checklist.md
content: # Agent Migration Checklist

## 迁移前确认
- [ ] 旧 agent id 已确认
- [ ] 新 agent id 已确认
- [ ] 新 workspace 路径已确认
- [ ] 是否一起改 model 已确认
- [ ] 是否替换文档中的旧名字已确认

## 配置修改检查
- [ ] `openclaw.json` 中 agent id 已更新
- [ ] `openclaw.json` 中 workspace 已更新
- [ ] model（如需）已更新
- [ ] 相关文档中的旧名字已替换

## 会话内容迁移检查（默认必须执行）
- [ ] 旧会话内容已复制到新 agent 侧
- [ ] 如有需要，迁移摘要已写入 memory / notes
- [ ] 未强改 `.lock` / session key
- [ ] 未因为“会话是否活跃”而跳过迁移

## 重启后检查
- [ ] Gateway / OpenClaw 已重启
- [ ] UI 中出现新 agent
- [ ] 当前 agent id 正确
- [ ] workspace 正确
- [ ] model 正确
- [ ] 关键 skill / 工具正常
- [ ] 新 agent 可见迁移内容
- [ ] `sessions.json` 等会话显示层元数据里的旧名字已同步改掉

## 清理前确认
- [ ] 用户已再次明确确认是否删除旧 agent
- [ ] 用户已确认是否需要备份
- [ ] 已确认系统已稳定，不再依赖旧 agent


path: references/cleanup.md
content: # Cleanup Notes

## 清理原则
- 不要在迁移刚完成时立刻删除旧 agent
- 先观察新 agent 是否稳定运行
- 删除旧 agent 前，必须再次询问用户
- 会话内容迁移属于默认步骤，不能用“活跃会话判断”替代或跳过

## 推荐清理对象
- 旧 agent 目录：`~/.openclaw/agents/<old-id>`
- 旧 session 历史
- 明确不再使用的旧索引或残留文件

## 不建议直接做的事
- 未确认 UI / runtime 已切稳就删旧历史
- 未经确认直接删除旧 session 文件
- 默认假设不需要备份

## 建议清理顺序
1. 再次询问用户是否删除旧 agent
2. 确认是否需要备份
3. 删除旧 agent 目录 / 历史
4. 展示删除证据
5. 观察新 agent 是否仍正常工作


path: scripts/copy_session_content.sh
content: #!/usr/bin/env bash
set -euo pipefail

OLD_ID="${1:-}"
NEW_ID="${2:-}"
MODE="${3:-copy}"

if [[ -z "$OLD_ID" || -z "$NEW_ID" ]]; then
  echo "Usage: copy_session_content.sh <old-agent-id> <new-agent-id> [copy|summary]"
  exit 1
fi

OLD_DIR="$HOME/.openclaw/agents/$OLD_ID/sessions"
NEW_DIR="$HOME/.openclaw/agents/$NEW_ID/sessions"
mkdir -p "$NEW_DIR"

if [[ ! -d "$OLD_DIR" ]]; then
  echo "Old session dir not found: $OLD_DIR"
  exit 2
fi

mapfile -t FILES < <(find "$OLD_DIR" -maxdepth 1 -type f \( -name '*.jsonl' -o -name 'sessions.json' \) | sort)
if [[ ${#FILES[@]} -eq 0 ]]; then
  echo "No session files found in $OLD_DIR"
  exit 3
fi

case "$MODE" in
  copy)
    for f in "${FILES[@]}"; do
      base=$(basename "$f")
      cp "$f" "$NEW_DIR/migrated-from-$OLD_ID-$base"
      echo "COPIED $f -> $NEW_DIR/migrated-from-$OLD_ID-$base"
    done
    ;;
  summary)
    OUT="$NEW_DIR/migration-summary-from-$OLD_ID.txt"
    {
      echo "Migration summary from $OLD_ID to $NEW_ID"
      echo "Generated: $(date -Is)"
      echo
      printf 'Files:\n'
      printf '%s\n' "${FILES[@]}"
    } > "$OUT"
    echo "WROTE $OUT"
    ;;
  *)
    echo "Unknown mode: $MODE"
    exit 4
    ;;
esac


path: scripts/inspect_agent_migration.sh
content: #!/usr/bin/env bash
set -euo pipefail

OLD_ID="${1:-}"
NEW_ID="${2:-}"

if [[ -z "$OLD_ID" || -z "$NEW_ID" ]]; then
  echo "Usage: inspect_agent_migration.sh <old-agent-id> <new-agent-id>"
  exit 1
fi

echo "== Config matches =="
grep -nE "\"id\": \"$OLD_ID\"|\"id\": \"$NEW_ID\"|$OLD_ID|$NEW_ID" ~/.openclaw/openclaw.json || true

echo
echo "== Agent dirs =="
ls -ld ~/.openclaw/agents/$OLD_ID ~/.openclaw/agents/$NEW_ID 2>/dev/null || true

echo
echo "== Session files =="
find ~/.openclaw/agents/$OLD_ID ~/.openclaw/agents/$NEW_ID -maxdepth 3 \( -name '*.jsonl' -o -name '*.json' -o -name '*.lock' \) 2>/dev/null | sort || true

echo
echo "== Workspace dirs =="
find ~/claw-workspace -maxdepth 1 -type d | sort || true

echo
echo "Inspection complete."


path: scripts/verify_agent_migration.sh
content: #!/usr/bin/env bash
set -euo pipefail

OLD_ID="${1:-}"
NEW_ID="${2:-}"
if [[ -z "$OLD_ID" || -z "$NEW_ID" ]]; then
  echo "Usage: verify_agent_migration.sh <old-agent-id> <new-agent-id>"
  exit 1
fi

CFG="$HOME/.openclaw/openclaw.json"

echo "== Config =="
grep -nE "\"id\": \"$OLD_ID\"|\"id\": \"$NEW_ID\"|/claw-workspace/$OLD_ID|/claw-workspace/$NEW_ID" "$CFG" || true

echo
echo "== Agent dirs =="
ls -ld "$HOME/.openclaw/agents/$OLD_ID" "$HOME/.openclaw/agents/$NEW_ID" 2>/dev/null || true

echo
echo "== Workspace dirs =="
ls -ld "$HOME/claw-workspace/$OLD_ID" "$HOME/claw-workspace/$NEW_ID" 2>/dev/null || true

echo
echo "== Session files =="
find "$HOME/.openclaw/agents/$NEW_ID" -maxdepth 3 -type f \( -name '*.jsonl' -o -name '*.json' -o -name '*.lock' -o -name '*.txt' \) 2>/dev/null | sort || true

echo
echo "== Doctor =="
openclaw doctor --non-interactive || true

echo
echo "Verification complete."


Security scan verdicts — ClawScan: suspicious | static analysis: clean | VirusTotal: clean | SkillSpector: clean (LOW)