{"slug":"migrate-from-v1","title":"migrate-from-v1","summary":"Finish migrating a NanoClaw v1 install into v2. Run after `bash migrate-v2.sh` completes. Seeds the owner, migrates legacy memory, reconciles container configs, and helps port custom v1 code. Triggers on \"migrate from v1\", \"finish migration\", \"v1 migration\".","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-08-24T05:37:21.007527Z","repo":{"url":"https://github.com/nanocoai/nanoclaw","stars":31126,"forks":12641,"license":"MIT","updatedAt":"2026-11-19T19:19:36Z"},"bodyHtml":"<hr>\n<h2>name: migrate-from-v1\ndescription: Finish migrating a NanoClaw v1 install into v2. Run after <code>bash migrate-v2.sh</code> completes. Seeds the owner, migrates legacy memory, reconciles container configs, and helps port custom v1 code. Triggers on \"migrate from v1\", \"finish migration\", \"v1 migration\".</h2>\n<h1>Finish v1 → v2 migration</h1>\n<p><code>bash migrate-v2.sh</code> already ran the deterministic migration. It handled:</p>\n<ul>\n<li>.env keys merged</li>\n<li>v2 DB seeded (agent_groups, messaging_groups, wiring)</li>\n<li>Group folders copied (v1 CLAUDE.md → v2 CLAUDE.local.md)</li>\n<li>Session data copied with conversation continuity (incl. Claude Code memory + JSONL transcripts)</li>\n<li>Scheduled tasks ported</li>\n<li>Channel code installed and auth state copied (incl. WhatsApp Baileys keystore)</li>\n<li>WhatsApp LIDs resolved from <code>store/auth</code> and aliased into <code>messaging_groups</code></li>\n<li>Container skills copied</li>\n<li>Container image built</li>\n</ul>\n<p>Your job is the parts that need human judgment: triage failed steps, seed the owner, run the shared-memory migration, reconcile configs, and port fork customizations.</p>\n<p>Read <code>logs/setup-migration/handoff.json</code> first — it has <code>overall_status</code>, per-step results in <code>steps</code>, and a <code>followups</code> list.</p>\n<h2>Preflight: was the script run?</h2>\n<p>Before anything else, check that <code>logs/setup-migration/handoff.json</code> exists. If it doesn't, the user is invoking this skill before <code>migrate-v2.sh</code> ran. Stop and tell them, verbatim:</p>\n<blockquote>\n<p>This skill finishes a migration that <code>migrate-v2.sh</code> started. Run that first, in your terminal — not from inside Claude:</p>\n<pre><code>bash migrate-v2.sh\n</code></pre>\n<p>It needs interactive prompts (channel selection, service switchover) and runs Node/pnpm bootstrap, Docker, OneCLI setup, and a container build that don't fit inside a Claude session. When it finishes, it'll hand control back to Claude automatically — at which point this skill picks up.</p>\n</blockquote>\n<p>Do not attempt to run the script yourself, simulate its effects, or pick up the migration mid-stream. The deterministic side has dependencies on a real interactive shell.</p>\n<p>Once <code>handoff.json</code> exists, proceed to Phase 0.</p>\n<h2>Phase 0: Get v2 routing real messages</h2>\n<p>Before any deeper migration work, prove v2 actually answers messages on the user's real channels. v1 is paused, not touched — flipping back is a service restart.</p>\n<h3>0a — Fix blockers only</h3>\n<p>Walk <code>handoff.steps</code>. Fix only the failures that would stop the bot from routing one message; defer the rest to its later phase.</p>\n<h3>0b — Smoke test, then continue</h3>\n<p>Tell the user the switch is non-destructive (v1 is paused, not modified; reverting is one command). Help them stop v1's service unit and start v2's, tail the host log for a clean boot, and have them send a real test message. Use <code>AskUserQuestion</code> to confirm the bot responded.</p>\n<p>If yes, continue to Phase 1. If no, diagnose from <code>logs/nanoclaw.log</code> and re-test — don't proceed to deeper work on a broken router.</p>\n<h3>Deferred failures</h3>\n<p>Re-visit anything you skipped in 0a before declaring the migration done. Most surface naturally in later phases (<code>1c-groups</code> ↔ Phase 2, <code>1e-tasks</code> ↔ task verification).</p>\n<h2>Phase 1: Owner and access</h2>\n<p>v2 auto-creates a <code>users</code> row for every sender it sees (via <code>extractAndUpsertUser</code> in <code>src/modules/permissions/index.ts</code>). By the time this skill runs, the owner's row likely already exists — it just needs the <code>owner</code> role granted.</p>\n<p><strong>User ID format</strong>: always <code>&lt;channel_type&gt;:&lt;platform_handle&gt;</code>. Each channel populates this differently:</p>\n<ul>\n<li><strong>Telegram</strong>: <code>telegram:&lt;numeric_user_id&gt;</code> (e.g. <code>telegram:6037840640</code>)</li>\n<li><strong>Discord</strong>: <code>discord:&lt;snowflake_user_id&gt;</code> (e.g. <code>discord:123456789012345678</code>)</li>\n<li><strong>WhatsApp</strong>: <code>whatsapp:&lt;phone&gt;@s.whatsapp.net</code> (e.g. <code>whatsapp:14155551234@s.whatsapp.net</code>)</li>\n<li><strong>Slack</strong>: <code>slack:&lt;user_id&gt;</code> (e.g. <code>slack:U04ABCDEF</code>)</li>\n<li><strong>Others</strong>: <code>&lt;channel_type&gt;:&lt;platform_id&gt;</code></li>\n</ul>\n<p><strong>Steps:</strong></p>\n<ol>\n<li>Query <code>users</code> table: <code>SELECT id, kind, display_name FROM users</code>.</li>\n<li>If exactly one user exists, confirm: <code>AskUserQuestion</code>: \"Is <code>&lt;display_name&gt;</code> (<code>&lt;id&gt;</code>) you?\" — Yes / No, let me type it.</li>\n<li>If multiple users exist, present them as options in <code>AskUserQuestion</code>.</li>\n<li>If no users exist yet (service hasn't received a message), ask the user to send a test message first, then re-query.</li>\n<li>Once confirmed, check <code>user_roles</code> via <code>getUserRoles(userId)</code>. If an <code>owner</code> row already exists, skip. Otherwise grant it with <code>grantRole</code>. <code>grantRole</code> inserts a new row per call, so the <code>getUserRoles</code> check keeps this re-runnable.</li>\n</ol>\n<p>Use the DB helpers in <code>src/modules/permissions/db/user-roles.ts</code> (<code>getUserRoles</code>, <code>grantRole</code>). Init the DB first, then call the helpers:</p>\n<pre><code>import { closeDb, initDb } from '../src/db/connection.js';\nimport { runMigrations } from '../src/db/migrations/index.js';\nimport { CENTRAL_DB_PATH } from '../src/config.js';\nimport { getUserRoles, grantRole } from '../src/modules/permissions/db/user-roles.js';\n\nconst db = await initDb(CENTRAL_DB_PATH);\ntry {\n  await runMigrations(db); // idempotent\n\n  const userId = '&lt;user_id&gt;';\n  if (!(await getUserRoles(userId)).some((r) =&gt; r.role === 'owner')) {\n    await grantRole({\n      user_id: userId,\n      role: 'owner',\n      agent_group_id: null, // owner role must be global\n      granted_by: null,\n      granted_at: new Date().toISOString(),\n    });\n  }\n} finally {\n  await closeDb();\n}\n</code></pre>\n<h3>Access policy</h3>\n<p>After seeding the owner, discuss the access policy. v2's <code>messaging_groups.unknown_sender_policy</code> controls who can interact with the bot. <code>migrate-v2.sh</code> set it to <code>public</code> so the bot would respond during the switchover test, but the user may want to tighten it.</p>\n<p>Present the options via <code>AskUserQuestion</code>:</p>\n<ol>\n<li><strong>Public</strong> (<code>public</code>, current) — anyone can message the bot. Good for personal DM bots.</li>\n<li><strong>Known users only</strong> (<code>strict</code>) — only users the access gate accepts (owner, admin, or <code>agent_group_members</code>) can trigger the bot. Others are silently dropped.</li>\n<li><strong>Approval required</strong> (<code>request_approval</code>) — unknown senders trigger an approval request to the owner. Good for group chats where you want to vet new members.</li>\n</ol>\n<p>The <code>unknown_sender_policy</code> column accepts exactly these three values; use the parenthesized value for <code>&lt;chosen_policy&gt;</code> below.</p>\n<p>If the user picks option 2 or 3, seed the known users from v1's message history. The v1 database is at <code>&lt;handoff.v1_path&gt;/store/messages.db</code>. It has a <code>messages</code> table with <code>sender</code> and <code>sender_name</code> columns. For each group:</p>\n<pre><code>-- v1: unique senders per chat (excluding bot messages)\nSELECT DISTINCT sender, sender_name\nFROM messages\nWHERE chat_jid = '&lt;v1_jid&gt;' AND is_from_me = 0 AND sender IS NOT NULL\n</code></pre>\n<p>The <code>sender</code> value is a platform handle (e.g. <code>6037840640</code> for Telegram). Build the v2 user ID by inferring the channel type from the chat JID prefix (use <code>parseJid</code> from <code>setup/migrate-v2/shared.ts</code>) and combining: <code>&lt;channel_type&gt;:&lt;sender&gt;</code>.</p>\n<p>For each sender:</p>\n<ol>\n<li>Upsert into <code>users(id, kind, display_name)</code> if not already present.</li>\n<li>Insert into <code>agent_group_members(user_id, agent_group_id)</code> for each agent group wired to that messaging group.</li>\n</ol>\n<p>Show the user the list of senders being imported and let them deselect any they don't want.</p>\n<p>Then update the messaging groups:</p>\n<pre><code>UPDATE messaging_groups SET unknown_sender_policy = '&lt;chosen_policy&gt;'\nWHERE id IN (SELECT id FROM messaging_groups WHERE channel_type IN (&lt;migrated_channels&gt;))\n</code></pre>\n<h2>Phase 2: Migrate legacy memory</h2>\n<p>Run <code>/migrate-memory</code> for the imported groups. It quiesces each group, moves the\nv1 <code>CLAUDE.local.md</code> into the shared <code>memory/</code> tree without reading it during\nstaging, then has the invoking coding harness distill standing identity into\n<code>instructions.prepend.md</code> and durable facts into Core Memory or focused linked\nfiles before the NanoClaw group runs again.</p>\n<p>Do not duplicate that migration logic here. Record each group's result in the\nhandoff before continuing.</p>\n<h2>Phase 3: Container config</h2>\n<p><code>migrate-v2.sh</code> writes <code>container.json</code> directly from v1's <code>container_config</code> (the <code>additionalMounts</code> shape is identical). If the v1 config was unparseable, it falls back to a <code>.v1-container-config.json</code> sidecar.</p>\n<p>For each group, check:</p>\n<ol>\n<li>If <code>container.json</code> exists, read it and verify the <code>additionalMounts</code> host paths are still valid on this machine. Flag any that don't exist.</li>\n<li>If <code>.v1-container-config.json</code> exists (parse failure fallback), read it, discuss with the user, and write a proper <code>container.json</code>. Then delete the sidecar.</li>\n<li>Check for <code>env</code> or <code>packages</code> fields — <code>env</code> may overlap with OneCLI vault, <code>packages</code> (apt/npm) are portable.</li>\n</ol>\n<h2>Phase 4: Fork customizations</h2>\n<p>Check whether the user's v1 install was a customized fork.</p>\n<pre><code>cd &lt;v1_path&gt;\ngit remote -v\ngit log --oneline &lt;upstream&gt;/main..HEAD 2&gt;/dev/null\n</code></pre>\n<p>If no commits ahead of upstream: stock v1, skip this phase.</p>\n<p>If there are commits:</p>\n<ol>\n<li>Show the commit list to the user.</li>\n<li><code>AskUserQuestion</code>: \"How do you want to handle your v1 customizations?\"\n<ul>\n<li><strong>Copy portable items</strong> (recommended) — copy <code>container/skills/*</code>, <code>.claude/skills/*</code>, <code>docs/*</code>. Grep each copied file for v1-only references that won't resolve in v2 and flag them to the user: workspace paths (<code>/workspace/group/</code>, <code>/workspace/project/</code>, <code>/workspace/ipc/</code>, <code>/workspace/extra/</code>), the v1 IPC mechanism, <code>registered_groups</code> / <code>is_main</code>, the v1 sender allowlist, and <code>store/messages.db</code>.</li>\n<li><strong>Full walkthrough</strong> — go commit by commit, decide together.</li>\n<li><strong>Reference only</strong> — stash to <code>docs/v1-fork-reference/</code> for later.</li>\n</ul>\n</li>\n<li>Source code (<code>src/*</code>, <code>container/agent-runner/src/*</code>) is NOT portable — v2's architecture is fundamentally different. Stash to <code>docs/v1-fork-reference/</code> with a README explaining what each file did. Don't translate.</li>\n</ol>\n<h2>Principles</h2>\n<ul>\n<li><strong>v1 checkout is read-only.</strong> Never modify files under <code>handoff.v1_path</code>.</li>\n<li><strong>Show before writing.</strong> Show diffs or proposed content before modifying standing instructions, memory, or container.json.</li>\n<li><strong>Mask credentials</strong> when displaying (first 4 + <code>...</code> + last 4 characters).</li>\n<li><strong><code>handoff.json</code> is the recovery point.</strong> If context gets compacted, re-read it and <code>git status</code> to recover state.</li>\n</ul>\n<h2>Setup steps you can run</h2>\n<p>The setup flow at <code>setup/index.ts</code> has individual steps you can invoke if something is missing or failed:</p>\n<pre><code>pnpm exec tsx setup/index.ts --step &lt;name&gt;\n</code></pre>\n<table>\n<thead>\n<tr>\n<th>Step</th>\n<th>When to use</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>onecli</code></td>\n<td>OneCLI not installed or not healthy</td>\n</tr>\n<tr>\n<td><code>auth</code></td>\n<td>No Anthropic credential in vault</td>\n</tr>\n<tr>\n<td><code>container</code></td>\n<td>Container image needs rebuild</td>\n</tr>\n<tr>\n<td><code>service</code></td>\n<td>Service not installed or not running</td>\n</tr>\n<tr>\n<td><code>mounts</code></td>\n<td>Mount allowlist missing</td>\n</tr>\n<tr>\n<td><code>verify</code></td>\n<td>End-to-end health check (run after everything else)</td>\n</tr>\n<tr>\n<td><code>environment</code></td>\n<td>System check (Node, dirs)</td>\n</tr>\n</tbody>\n</table>\n<h2>When done</h2>\n<ol>\n<li>Run the verify step to confirm everything works:\n<pre><code>pnpm exec tsx setup/index.ts --step verify\n</code></pre>\n</li>\n<li>Delete <code>logs/setup-migration/handoff.json</code> — offer to save as <code>docs/migration-&lt;date&gt;.md</code> first.</li>\n<li>Restart the service if running so changes take effect. The v2 service label is install-specific (<code>nanoclaw-v2-&lt;slug&gt;</code> / <code>com.nanoclaw-v2-&lt;slug&gt;</code>), so derive it from <code>src/install-slug.ts</code> rather than guessing:\n<pre><code># Linux\nUNIT=$(pnpm exec tsx -e \"import{getSystemdUnit}from'./src/install-slug.js';console.log(getSystemdUnit())\")\nsystemctl --user restart \"$UNIT\"\n# macOS\nLABEL=$(pnpm exec tsx -e \"import{getLaunchdLabel}from'./src/install-slug.js';console.log(getLaunchdLabel())\")\nlaunchctl kickstart -k \"gui/$(id -u)/$LABEL\"\n</code></pre>\n</li>\n</ol>\n","files":[{"path":"SKILL.md","sizeBytes":11455,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"notes-only","suspicious":0,"notes":2,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-08-24T05:39:33.109097Z","sha256":"A75406F8B9FD61EA9CC2E472AAF02B2629F09F115F6115F504CF6E42320DDCD0","sizeBytes":5246},"review":null,"source":{"repositoryUrl":"https://github.com/nanocoai/nanoclaw","path":".claude/skills/migrate-from-v1","license":"MIT","commit":"8683bddf9a3cac6f0ef36127c3a585e56579cca8","subtreeSha":"7CB6B2ABCB0DF5CB1B61EA0EECBAD31501F3C09EF0EC192C65C04B8A80D7C364","lastSyncedAt":"2026-11-19T19:29:56.648801Z"},"reviewedAt":"2026-08-24T05:46:43.205554Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/nanocoai/nanoclaw/tree/main/.claude/skills/migrate-from-v1"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install nanocoai-nanoclaw@llmmart"},{"target":"git","command":"git clone https://github.com/nanocoai/nanoclaw.git"}]}