#!/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" < "agents/${agent_id}/AGENTS.md" < 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" < "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" <> "$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="" 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 < 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"