{"id":"init-first-agent","name":"init-first-agent","summary":"オペレーターに最初のNanoClawエージェントをDMチャネルに接続する方法を案内し、オペレーターのチャネル識別を特定し、エージェントを選択しまたは作成し、通常の配信経路でウェルカムDMをトリガーします。","body":"# Init First Agent\n\nWire the first NanoClaw agent to a channel and verify end-to-end delivery by having the agent DM the operator. Everything the skill does is idempotent — rerunning is safe.\n\n## Prerequisites\n\n- **Service running.** Check: `launchctl list | grep \"$(. setup/lib/install-slug.sh && launchd_label)\"` (macOS) or `systemctl --user status \"$(. setup/lib/install-slug.sh && systemd_unit)\"` (Linux). If stopped, tell the user to run `/setup` first.\n- **Target channel installed.** At least one `/add-<channel>` skill has run, credentials are in `.env`, and the adapter is uncommented in `src/channels/index.ts`.\n- **Adapter connected.** Tail `logs/nanoclaw.log` — look for a recent `channel setup` / `adapter connected` line for the target channel.\n\n## 1. Pick the channel\n\nRead `src/channels/index.ts` to find enabled channels (uncommented imports). Cross-check `.env` for the relevant credentials.\n\nAskUserQuestion: \"Which channel should host the welcome DM?\" with one option per enabled channel (Discord, Slack, Telegram, WhatsApp, Webex, Teams, Google Chat, Matrix, iMessage, Resend, …).\n\nRecord the choice as `CHANNEL` (lowercase, e.g. `discord`).\n\n## 2. Ask for the operator's identity\n\nRead the channel's own skill for its `## Channel Info > how-to-find-id` section (e.g. `.claude/skills/add-discord/SKILL.md`, `.claude/skills/add-telegram/SKILL.md`). Show those instructions to the user in plain text.\n\nThen ask in plain text (NOT `AskUserQuestion` — these are free-form):\n\n1. **Your user id on this channel** — e.g. a Discord user ID, Telegram user ID, Slack user ID. Record as `USER_HANDLE`.\n2. **Your display name** — human name, used to name the agent group (`dm-with-<normalized>`) and as the welcome-message addressee. Record as `DISPLAY_NAME`.\n3. **Agent persona name** — the assistant's display name. Default: `DISPLAY_NAME`. Record as `AGENT_NAME`.\n\n## 3. Resolve the DM platform id\n\nThis depends on whether the channel supports cold DM via `adapter.openDM`.\n\n**Channels without cold DM (direct-addressable): telegram, whatsapp, imessage, matrix, resend.** The user handle doubles as the DM chat id. Set:\n\n```\nPLATFORM_ID=${CHANNEL}:${USER_HANDLE}\n```\n\nSkip to step 4.\n\n**Channels with cold DM (resolution-required): discord, slack, teams, webex, gchat.** The bot can DM cold at runtime via Chat SDK, but this skill runs standalone — it can't call the adapter. Two resolutions:\n\n### 3a. User DMs the bot once (Discord / Slack / Teams / Webex / gChat)\n\nTell the user:\n\n> Send any single message to the bot as a DM from your account on `${CHANNEL}`. The router will record the DM as a messaging group. Reply `done` here when you've sent the message.\n\nWait for the user's confirmation. Then look up the most recent DM messaging groups:\n\n```bash\npnpm exec tsx scripts/q.ts data/v2.db \"SELECT id, platform_id, name, created_at FROM messaging_groups WHERE channel_type='${CHANNEL}' AND is_group=0 ORDER BY created_at DESC LIMIT 5\"\n```\n\nShow the top rows to the user and confirm which `platform_id` is theirs (usually the most recent). Record as `PLATFORM_ID`. If none appeared, check `logs/nanoclaw.log` for `unknown_sender` drops — the adapter might be rejecting inbound due to connection or permission issues.\n\n### 3b. Telegram pair-code path (if the user prefers not to DM first)\n\nFor Telegram only, there's an existing pair-code primitive. When you run this tool, take the output and extract the pairing code. Then show it to the user in plain text and ask the user to send the code in the Telegram chat to complete the pairing.\n\n```bash\nnpx tsx setup/index.ts --step pair-telegram -- --intent new-agent:dm-with-<folder>\n```\n\nParse the `PAIR_TELEGRAM_ISSUED` status block for `CODE` and follow the `REMINDER_TO_ASSISTANT` line in that block. Then wait for the `PAIR_TELEGRAM` block — read `PLATFORM_ID` and `PAIRED_USER_ID` from it. telegram.ts's interceptor has already upserted the user and granted owner if none existed yet. Use `PLATFORM_ID` and `PAIRED_USER_ID` directly in step 5.\n\n## 4. Pick the agent group\n\nList the existing agent groups and their wirings through the admin CLI:\n\n```bash\nncl groups list --json\nncl wirings list --json\n```\n\nIf setup already installed a template, it appears in the groups result even when it has no wiring. Show the user each group's name, folder, and id, and note which groups already appear as `agent_group_id` values in the wirings result.\n\n- If no group exists, continue without `AGENT_GROUP_ID`; the init script will create one.\n- If groups exist, ask whether to wire one of them or create a new agent. Recommend the sole unwired group when there is exactly one.\n- When the user picks an existing group, record its exact `id` as `AGENT_GROUP_ID`. Do not infer it from the display name or folder.\n\n## 5. Run the init script\n\nWhen creating a new agent, first pick the provider. Read `src/providers/index.ts` and collect the installed providers from its `import './<name>.js';` lines — `claude` is always available as the built-in default. If a non-default provider is installed (e.g. codex), ask the user which one this agent should run on; if only claude is available, skip the question. An existing group keeps the provider and template configuration it already has.\n\n```bash\nnpx tsx scripts/init-first-agent.ts \\\n  --channel \"${CHANNEL}\" \\\n  --user-id \"${CHANNEL}:${USER_HANDLE}\" \\\n  --platform-id \"${PLATFORM_ID}\" \\\n  --display-name \"${DISPLAY_NAME}\" \\\n  --agent-name \"${AGENT_NAME}\"\n```\n\nWhen an existing group was selected, append its exact id:\n\n```bash\n  --agent-group-id \"${AGENT_GROUP_ID}\"\n```\n\nThe new group is created on the instance default provider (`DEFAULT_AGENT_PROVIDER` in `.env`, or `claude` when unset). To put it on a different provider, switch after creation with `ncl groups config update --id <group-id> --provider <name>`. Add `--welcome \"System instruction: ...\"` to override the default welcome prompt.\n\nThe script:\n1. Upserts the `users` row and grants `owner` role if no owner exists.\n2. Uses the selected `agent_groups` row, or creates one and calls `initGroupFilesystem` at `groups/dm-with-<name>/`.\n3. Reuses or creates the DM `messaging_groups` row.\n4. Wires them via `messaging_group_agents` (which auto-creates the companion `agent_destinations` row).\n5. Hands the welcome message to the running service via its CLI socket (`data/cli.sock`), targeting the DM messaging group. The service routes it into the DM session, which wakes the container synchronously. If the socket isn't reachable (service down), falls back to a direct `inbound.db` write that the next host sweep picks up.\n\nShow the script's output to the user.\n\n## 6. Verify\n\nThe welcome DM is queued synchronously; the only wait is container cold-start (~60s on first launch) before the agent processes the message and the reply flows through `outbound.db` to the channel.\n\nDo not tail the log or poll in a sleep loop. Ask the user in plain text:\n\n> The welcome DM should arrive shortly. Let me know when you've received it (or if it doesn't arrive within two minutes).\n\nWait for the user's reply. If they confirm receipt, the skill is done.\n\nIf they say it didn't arrive, then diagnose using the DB directly (no waiting loops required — the message either delivered or it didn't):\n\n- `pnpm exec tsx scripts/q.ts data/v2-sessions/<agent-group-id>/<session-id>/outbound.db \"SELECT id, status, created_at FROM messages_out ORDER BY created_at DESC LIMIT 5\"` — check for stuck `pending` rows. Replace `<agent-group-id>` and `<session-id>` with the values from the script's output.\n- `grep -E 'Unauthorized channel destination|container.*exited|error' logs/nanoclaw.log | tail -20` — look for ACL rejections or container crashes.\n- `ls data/v2-sessions/<agent-group-id>/*/outbound.db` — confirm the session exists.\n\n## Troubleshooting\n\n**\"Missing required args\"** — the script wants `--channel`, `--user-id`, `--platform-id`, `--display-name` at minimum. Re-check the command you assembled.\n\n**No `messaging_groups` row appears after the user DMs (step 3a)** — auto-created rows are stamped with the channel adapter's declared `unknown_sender_policy` (two-level model: adapter declaration → per-row override; `strict` only when the adapter has no declaration). Under `strict` the router silently drops messages from unknown senders but still creates the `messaging_groups` row; under `request_approval` an approval card goes to an admin instead. If the row is missing entirely, the adapter isn't receiving the inbound message. Check `logs/nanoclaw.log` for adapter errors (auth, gateway disconnect, rate limit).\n\n**Owner already exists** — `hasAnyOwner()` returned true, so the grant is skipped silently. That's fine; the script still creates the agent and wiring. Reassigning ownership needs a separate flow (not this skill).\n\n**Wrong person got the welcome DM** — the `--platform-id` you passed is someone else's DM channel. Rerun with the correct one; the script is idempotent on user/messaging-group/agent-group but writes a new session welcome each run.\n\n**Agent group name collision** — use step 4 to select the intended group by id. If creating a new agent and `dm-with-<display-name>` already exists, the script reuses it; pass a different `--display-name` to get a distinct folder.","author":"@nanocoai","ownerProfile":null,"authorContacts":null,"sourceUrl":"https://github.com/nanocoai/nanoclaw/tree/main/.claude/skills/init-first-agent","license":"MIT","category":null,"lang":"en","tokens":2254,"stars":0,"calls30d":2,"claimed":false,"visibility":"public","origin":"crawler","version":"0.1.0","createdAt":"2026-08-22","updatedAt":"2026-08-22","files":[],"requires":{"mcp":[],"tools":[]},"safety":{"flags":[],"scannedAt":"2026-08-22","hasScripts":false,"networkEndpoints":[]}}