242 lines
6.9 KiB
Bash
Executable File
242 lines
6.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
||
set -euo pipefail
|
||
|
||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||
SRC_VAULT="${1:-/Users/lingyuzeng/openclawd/vaults}"
|
||
|
||
if [[ ! -d "${REPO_ROOT}/.git" ]]; then
|
||
echo "[error] not a git repo: ${REPO_ROOT}" >&2
|
||
exit 1
|
||
fi
|
||
if [[ ! -d "${SRC_VAULT}" ]]; then
|
||
echo "[error] source vault not found: ${SRC_VAULT}" >&2
|
||
exit 1
|
||
fi
|
||
|
||
cd "${REPO_ROOT}"
|
||
|
||
mkdir -p \
|
||
agents/openclaw-main/drafts \
|
||
agents/claude-code/drafts \
|
||
agents/codex/drafts \
|
||
shared/long-term/decisions \
|
||
shared/long-term/projects \
|
||
shared/long-term/lessons \
|
||
tasks/openclawd-migration-2026-03 \
|
||
tasks/openclawd-team-archive \
|
||
tasks/openclawd-legacy-inbox
|
||
|
||
write_agent_card() {
|
||
local agent_id="$1"
|
||
cat > "agents/${agent_id}/AGENT-CARD.md" <<CARD
|
||
# AGENT-CARD: ${agent_id}
|
||
|
||
- agent_id: \
|
||
\`${agent_id}\`
|
||
- writable_scope: \
|
||
\`agents/${agent_id}/**\`
|
||
- query_authority: \
|
||
\`remote MCP/QMD\`
|
||
- promote_target: \
|
||
\`shared/long-term/**\`
|
||
CARD
|
||
}
|
||
|
||
write_agent_guide() {
|
||
local agent_id="$1"
|
||
cat > "agents/${agent_id}/AGENTS.md" <<GUIDE
|
||
# AGENTS.md (agents/${agent_id})
|
||
|
||
## 工作根路径
|
||
- 当前工作根路径 = 本文件所在目录(\`memory-repo/agents/${agent_id}/\`)。
|
||
- 智能体仅在该目录维护自己的工作记忆。
|
||
|
||
## 目录类型
|
||
- 类型:\`agent\`。
|
||
|
||
## 目录作用
|
||
- 智能体私域工作记忆:收件、当前上下文、草稿。
|
||
|
||
## 查询规则
|
||
- 群体共享记忆查询必须走远程 MCP/QMD。
|
||
- 本地检索仅用于未 push 草稿、故障降级和本地调试。
|
||
|
||
## Git 规则
|
||
- 修改前先 \`git fetch --prune origin\`,再 \`git pull --rebase\`。
|
||
- 小步提交,避免与长期共享记忆同提交混改。
|
||
|
||
## Promote 规则
|
||
- 稳定结论通过 task 或 promote 流程进入 \`shared/long-term/\`。
|
||
GUIDE
|
||
}
|
||
|
||
write_agent_card openclaw-main
|
||
write_agent_card claude-code
|
||
write_agent_card codex
|
||
write_agent_guide openclaw-main
|
||
write_agent_guide claude-code
|
||
write_agent_guide codex
|
||
|
||
cat > agents/openclaw-main/current.md <<'EOF_CURRENT'
|
||
# current
|
||
|
||
- role: OpenClaw 主控智能体(mac-5 控制面)
|
||
- memory_source_of_truth: collective-memory-repo + remote memory-gateway
|
||
- next_actions:
|
||
- 完成远程 memory-gateway 联调
|
||
- 按任务将阶段结论沉淀到 shared/long-term
|
||
EOF_CURRENT
|
||
|
||
cat > agents/openclaw-main/inbox.md <<'EOF_INBOX'
|
||
# inbox
|
||
|
||
- [ ] 验证 RTX 2080Ti 上 memory-gateway /query 返回 commit_hash 与 synced_at
|
||
- [ ] 校验 OpenClaw / Claude Code / Codex 三端统一走 gateway
|
||
EOF_INBOX
|
||
|
||
for agent in claude-code codex; do
|
||
cat > "agents/${agent}/current.md" <<EOF_CUR
|
||
# current
|
||
|
||
- role: ${agent} 工作智能体
|
||
- default_memory_entry: memory-gateway
|
||
EOF_CUR
|
||
cat > "agents/${agent}/inbox.md" <<'EOF_IB'
|
||
# inbox
|
||
|
||
- [ ] 等待任务分派
|
||
EOF_IB
|
||
done
|
||
|
||
import_file() {
|
||
local src="$1"
|
||
local dst="$2"
|
||
local title="$3"
|
||
mkdir -p "$(dirname "$dst")"
|
||
cat > "$dst" <<EOF_IMPORT
|
||
# ${title}
|
||
|
||
- imported_from: \`${src}\`
|
||
- imported_at_utc: \`$(date -u +%Y-%m-%dT%H:%M:%SZ)\`
|
||
- note: migrated from openclawd/vaults to collective-memory-repo.
|
||
|
||
---
|
||
|
||
EOF_IMPORT
|
||
cat "$src" >> "$dst"
|
||
}
|
||
|
||
import_file "${SRC_VAULT}/MEMORY.md" "shared/long-term/projects/openclawd-memory-index.md" "OpenClaw MEMORY Index (Imported)"
|
||
import_file "${SRC_VAULT}/memory/infra.md" "shared/long-term/decisions/openclawd-infra-baseline.md" "OpenClaw Infra Baseline (Imported)"
|
||
import_file "${SRC_VAULT}/memory/projects.md" "shared/long-term/projects/openclawd-project-status.md" "OpenClaw Project Status (Imported)"
|
||
import_file "${SRC_VAULT}/memory/lessons.md" "shared/long-term/lessons/openclawd-ops-lessons.md" "OpenClaw Ops Lessons (Imported)"
|
||
|
||
# Import all dated memory notes into daily/YYYY-MM-DD.md (append with source markers)
|
||
for src in "${SRC_VAULT}"/memory/20*.md; do
|
||
[[ -f "$src" ]] || continue
|
||
base="$(basename "$src")"
|
||
if [[ "$base" =~ ^([0-9]{4}-[0-9]{2}-[0-9]{2}).*\.md$ ]]; then
|
||
day="${BASH_REMATCH[1]}"
|
||
else
|
||
continue
|
||
fi
|
||
|
||
dest="daily/${day}.md"
|
||
marker="<!-- imported:openclawd:${base} -->"
|
||
|
||
if [[ ! -f "$dest" ]]; then
|
||
printf '# %s\n' "$day" > "$dest"
|
||
fi
|
||
|
||
if grep -Fq "$marker" "$dest"; then
|
||
continue
|
||
fi
|
||
|
||
{
|
||
printf '\n%s\n' "$marker"
|
||
printf '## Import from openclawd/vaults/memory/%s\n\n' "$base"
|
||
printf -- '- imported_at_utc: `%s`\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
||
printf -- '- source_path: `%s`\n\n' "$src"
|
||
cat "$src"
|
||
printf '\n'
|
||
} >> "$dest"
|
||
done
|
||
|
||
# Archive shared/team and legacy inbox context for traceability
|
||
if [[ -d "${SRC_VAULT}/shared/10-Team" ]]; then
|
||
rm -rf tasks/openclawd-team-archive/10-Team
|
||
cp -R "${SRC_VAULT}/shared/10-Team" tasks/openclawd-team-archive/10-Team
|
||
fi
|
||
|
||
if [[ -d "${SRC_VAULT}/mac-5/00-Inbox" ]]; then
|
||
rm -rf tasks/openclawd-legacy-inbox/mac-5-00-Inbox
|
||
cp -R "${SRC_VAULT}/mac-5/00-Inbox" tasks/openclawd-legacy-inbox/mac-5-00-Inbox
|
||
fi
|
||
|
||
cat > tasks/openclawd-migration-2026-03/TASK.md <<'EOF_TASK'
|
||
# TASK: openclawd-migration-2026-03
|
||
|
||
## Goal
|
||
- Migrate openclawd memory into collective-memory-repo and switch group retrieval to memory-gateway.
|
||
|
||
## Scope
|
||
- Import long-term, daily, and legacy team memory.
|
||
- Preserve openclawd runtime files in local vaults.
|
||
- Validate gateway consistency chain (/health, /sync, /query).
|
||
EOF_TASK
|
||
|
||
cat > tasks/openclawd-migration-2026-03/RUNLOG.md <<EOF_RUNLOG
|
||
# RUNLOG
|
||
|
||
- $(date '+%Y-%m-%d %H:%M:%S %Z'): executed scripts/migrate-openclawd-memory.sh
|
||
- source: ${SRC_VAULT}
|
||
- destination: ${REPO_ROOT}
|
||
EOF_RUNLOG
|
||
|
||
cat > tasks/openclawd-migration-2026-03/DECISIONS.md <<'EOF_DECISIONS'
|
||
# DECISIONS
|
||
|
||
- Keep `openclawd/vaults` as runtime home (persona/tooling/heartbeat).
|
||
- Use `collective-memory-repo` as shared memory source-of-truth.
|
||
- Route multi-agent retrieval through `memory-gateway` rather than direct qmd MCP.
|
||
EOF_DECISIONS
|
||
|
||
cat > tasks/openclawd-migration-2026-03/LINKS.md <<'EOF_LINKS'
|
||
# LINKS
|
||
|
||
- Source vault: `/Users/lingyuzeng/openclawd/vaults`
|
||
- Target repo: `/Users/lingyuzeng/project/collective-memory-repo`
|
||
- Gateway project (remote path intent): `/home/lingyuzeng/project/qmd-local`
|
||
EOF_LINKS
|
||
|
||
cat > tasks/openclawd-migration-2026-03/AGENTS.md <<'EOF_TASK_AGENTS'
|
||
# AGENTS.md (tasks/openclawd-migration-2026-03)
|
||
|
||
## 目录类型
|
||
- `task`
|
||
|
||
## 规则
|
||
- 过程记录 append-only 到 `RUNLOG.md`。
|
||
- 稳定结论 promote 到 `shared/long-term/`。
|
||
- 群体查询结果只认远程 memory-gateway。
|
||
EOF_TASK_AGENTS
|
||
|
||
# Replace template/sample entities with real ones for production migration
|
||
rm -rf agents/agent-a agents/agent-b tasks/task-001 tasks/task-002
|
||
|
||
if ! grep -q 'openclawd-migration-2026-03' MEMORY.md; then
|
||
cat >> MEMORY.md <<'EOF_MEMORY'
|
||
|
||
## Migration Snapshot (2026-03-10)
|
||
- openclawd memory imported into:
|
||
- `shared/long-term/decisions/openclawd-infra-baseline.md`
|
||
- `shared/long-term/projects/openclawd-memory-index.md`
|
||
- `shared/long-term/projects/openclawd-project-status.md`
|
||
- `shared/long-term/lessons/openclawd-ops-lessons.md`
|
||
- task tracking: `tasks/openclawd-migration-2026-03/`
|
||
- group retrieval should use remote memory-gateway only.
|
||
EOF_MEMORY
|
||
fi
|
||
|
||
echo "[ok] migration completed"
|