|
| 1 | +--- |
| 2 | +title: CrowClaw Architecture |
| 3 | +--- |
| 4 | + |
| 5 | +# CrowClaw |
| 6 | + |
| 7 | +CrowClaw is a Crow bundle (`type: "mcp-server"`) that provides bot management through 20 MCP tools and a dashboard panel. It runs as a child process of the Crow gateway, sharing the same `crow.db` database. |
| 8 | + |
| 9 | +## Architecture |
| 10 | + |
| 11 | +``` |
| 12 | +┌──────────────────────────────────────────────────────────────────┐ |
| 13 | +│ Crow's Nest Dashboard │ |
| 14 | +│ └── Bots Panel (/dashboard/bots) │ |
| 15 | +│ ├── Bot list (status, health, controls) │ |
| 16 | +│ ├── Create / configure / deploy / delete │ |
| 17 | +│ └── Messages integration (bot chat) │ |
| 18 | +├──────────────────────────────────────────────────────────────────┤ |
| 19 | +│ CrowClaw MCP Server (20 tools) │ |
| 20 | +│ ├── Bot Lifecycle (7): create, configure, deploy, start/stop/restart, delete │ |
| 21 | +│ ├── Monitoring (3): status, logs, health │ |
| 22 | +│ ├── User Profiles (4): create, update, list, delete │ |
| 23 | +│ └── Workspace & Skills (6): templates, workspace files, skills │ |
| 24 | +├──────────────────────────────────────────────────────────────────┤ |
| 25 | +│ BYOAI Bridge │ |
| 26 | +│ └── Crow AI profiles → bot models.json (auto on deploy) │ |
| 27 | +├──────────────────────────────────────────────────────────────────┤ |
| 28 | +│ Bot Chat Routes │ |
| 29 | +│ └── REST API: GET messages, POST message (polling), POST new-session │ |
| 30 | +├──────────────────────────────────────────────────────────────────┤ |
| 31 | +│ crow.db (SQLite, WAL mode, shared by 6+ processes) │ |
| 32 | +│ └── Tables: crowclaw_bots, crowclaw_user_profiles, │ |
| 33 | +│ crowclaw_workspace_files, crowclaw_deployments, │ |
| 34 | +│ crowclaw_skills, crowclaw_safety_events, crowclaw_bot_messages │ |
| 35 | +└──────────────────────────────────────────────────────────────────┘ |
| 36 | + │ │ |
| 37 | + systemctl --user OpenClaw Engine |
| 38 | + (bot services) (per-bot gateway) |
| 39 | +``` |
| 40 | + |
| 41 | +## Bundle Registration |
| 42 | + |
| 43 | +CrowClaw must be registered in three places for Crow to discover it: |
| 44 | + |
| 45 | +| File | Purpose | |
| 46 | +|------|---------| |
| 47 | +| `~/.crow/installed.json` | Bundle entry with `id: "crowclaw"` | |
| 48 | +| `~/.crow/mcp-addons.json` | MCP server config with `cwd` pointing to bundle dir | |
| 49 | +| `~/.crow/panels.json` | Panel ID `"bots"` (routes to `/dashboard/bots`) | |
| 50 | + |
| 51 | +The panel ID is `"bots"` (not `"crowclaw"`). The extension proxy route is `/proxy/crowclaw/`. |
| 52 | + |
| 53 | +## MCP Tools |
| 54 | + |
| 55 | +### Bot Lifecycle (7) |
| 56 | + |
| 57 | +| Tool | Description | |
| 58 | +|------|-------------| |
| 59 | +| `crow_create_bot` | Create a new bot with name, platform credentials, AI config | |
| 60 | +| `crow_configure_bot` | Update bot settings (model, skills, safety) | |
| 61 | +| `crow_deploy_bot` | Deploy bot config, generate models.json, start service | |
| 62 | +| `crow_start_bot` | Start the bot's systemd service | |
| 63 | +| `crow_stop_bot` | Stop the bot's systemd service | |
| 64 | +| `crow_restart_bot` | Restart the bot's systemd service | |
| 65 | +| `crow_delete_bot` | Remove bot, config files, and service (confirm gate) | |
| 66 | + |
| 67 | +### Monitoring (3) |
| 68 | + |
| 69 | +| Tool | Description | |
| 70 | +|------|-------------| |
| 71 | +| `crow_bot_status` | Status of all bots or a specific bot (running, stopped, errors) | |
| 72 | +| `crow_bot_logs` | Recent journal logs for a bot's systemd service | |
| 73 | +| `crow_bot_health` | Health metrics: uptime, error rate, last activity | |
| 74 | + |
| 75 | +### User Profiles (4) |
| 76 | + |
| 77 | +| Tool | Description | |
| 78 | +|------|-------------| |
| 79 | +| `crow_create_user_profile` | Create a user profile (name, platform IDs, permissions) | |
| 80 | +| `crow_update_user_profile` | Update profile fields | |
| 81 | +| `crow_list_user_profiles` | List all profiles | |
| 82 | +| `crow_delete_user_profile` | Remove a profile (confirm gate) | |
| 83 | + |
| 84 | +### Workspace & Skills (6) |
| 85 | + |
| 86 | +| Tool | Description | |
| 87 | +|------|-------------| |
| 88 | +| `crow_list_workspace_templates` | List available bot workspace templates | |
| 89 | +| `crow_update_workspace_file` | Write a file to a bot's workspace | |
| 90 | +| `crow_get_workspace_file` | Read a file from a bot's workspace | |
| 91 | +| `crow_list_bot_skills` | List skills deployed to a bot | |
| 92 | +| `crow_deploy_skill` | Push a SKILL.md file to a bot (confirm gate) | |
| 93 | +| `crow_remove_skill` | Remove a skill from a bot (confirm gate) | |
| 94 | + |
| 95 | +## Confirm Gate |
| 96 | + |
| 97 | +Destructive operations require a two-call confirmation pattern (`server/confirm.js`): |
| 98 | + |
| 99 | +1. **First call**: Returns a confirmation token and description of what will happen |
| 100 | +2. **Second call**: Same parameters plus the confirmation token — executes the operation |
| 101 | + |
| 102 | +This prevents accidental deletions from a single misrouted tool call. Protected operations: deploy, delete bot, delete profile, remove skill. |
| 103 | + |
| 104 | +## Database Tables |
| 105 | + |
| 106 | +All tables live in Crow's shared `crow.db` (WAL mode, `busy_timeout = 5000`). |
| 107 | + |
| 108 | +| Table | Purpose | |
| 109 | +|-------|---------| |
| 110 | +| `crowclaw_bots` | Bot definitions: name, platform, AI config, status | |
| 111 | +| `crowclaw_user_profiles` | Platform user profiles and permissions | |
| 112 | +| `crowclaw_workspace_files` | Bot workspace file contents | |
| 113 | +| `crowclaw_deployments` | Deployment history and timestamps | |
| 114 | +| `crowclaw_skills` | Skills deployed to each bot | |
| 115 | +| `crowclaw_safety_events` | Content moderation and safety audit log | |
| 116 | +| `crowclaw_bot_messages` | Bot chat messages (with attachments JSON column) | |
| 117 | + |
| 118 | +Schema is defined in `server/init-tables.js` and runs `CREATE TABLE IF NOT EXISTS` on every startup. |
| 119 | + |
| 120 | +## BYOAI Bridge |
| 121 | + |
| 122 | +`server/byoai-bridge.js` generates a bot's `models.json` from Crow's AI profiles stored in `dashboard_settings.ai_profiles`. |
| 123 | + |
| 124 | +### Provider Mapping |
| 125 | + |
| 126 | +The bridge maps base URLs to OpenClaw provider namespaces using `openclawProviderFromBaseUrl()`. Provider keys in `models.json` must match OpenClaw's auth profile names (`zai`, `qwen-portal`, `meta`, etc.) — not arbitrary names. Mismatches cause silent auth failures. |
| 127 | + |
| 128 | +### Vision Detection |
| 129 | + |
| 130 | +`isVisionModel()` is a heuristic (regex patterns for known vision model names). When a vision model is detected, the bridge outputs a provider-qualified `imageModel` (e.g., `zai/glm-4.6v`) and configures `tools.media.models` with the appropriate timeout. |
| 131 | + |
| 132 | +### Path Discovery |
| 133 | + |
| 134 | +Uses `openclaw config file` CLI with `OPENCLAW_CONFIG_PATH` env var to find the bot's state directory. The CLI may return tilde paths — these are expanded before `resolve()`. |
| 135 | + |
| 136 | +### Deploy Trigger |
| 137 | + |
| 138 | +When `deployBot()` runs for a bot with `ai_source: "byoai"`, it calls `generateModelsJson()` which writes the bot's `models.json`. This merges ALL Crow AI profiles into one file. |
| 139 | + |
| 140 | +## Bot Chat |
| 141 | + |
| 142 | +`server/bot-chat.js` provides REST routes for the Messages panel: |
| 143 | + |
| 144 | +| Route | Method | Purpose | |
| 145 | +|-------|--------|---------| |
| 146 | +| `/bot-chat/:botId/messages` | GET | Fetch message history | |
| 147 | +| `/bot-chat/:botId/message` | POST | Send message to bot (polls for response) | |
| 148 | +| `/bot-chat/:botId/new-session` | POST | Start a new conversation session | |
| 149 | + |
| 150 | +All routes require `dashboardAuth` middleware. |
| 151 | + |
| 152 | +### Vision Pipeline |
| 153 | + |
| 154 | +When an image is attached to a bot message: |
| 155 | + |
| 156 | +1. Image downloaded from S3 to a temp file |
| 157 | +2. Vision model called directly via API (config from `openclaw.json` → `tools.media.models`) |
| 158 | +3. API credentials resolved from Crow's AI profiles |
| 159 | +4. Text description injected as `[Image N analysis]` context before the user's message |
| 160 | +5. Combined message sent to bot via `openclaw agent` CLI |
| 161 | +6. Temp files cleaned up after the bot responds |
| 162 | + |
| 163 | +This bypasses the limitation that `openclaw agent` has no `--media` flag and the gateway WebSocket protocol doesn't support inline images with non-vision primary models. |
| 164 | + |
| 165 | +## Panel |
| 166 | + |
| 167 | +The dashboard panel (`panel/crowclaw.js`) serves at `/dashboard/bots`. It renders the bot management UI including: |
| 168 | + |
| 169 | +- Bot list with status indicators |
| 170 | +- Create/configure/deploy forms |
| 171 | +- Real-time log viewer |
| 172 | +- Messages integration for bot chat |
| 173 | + |
| 174 | +The OpenClaw Control UI is proxied through Crow at `/proxy/crowclaw/` with the gateway token auto-injected via URL hash. |
| 175 | + |
| 176 | +## Systemd Integration |
| 177 | + |
| 178 | +Each bot runs as a user-level systemd service (`systemctl --user`). CrowClaw manages the service lifecycle: |
| 179 | + |
| 180 | +- `crow_start_bot` → `systemctl --user start openclaw-gateway.service` |
| 181 | +- `crow_stop_bot` → `systemctl --user stop openclaw-gateway.service` |
| 182 | +- `crow_bot_logs` → `journalctl --user -u openclaw-gateway.service` |
| 183 | + |
| 184 | +## Related |
| 185 | + |
| 186 | +- [Bot Management Guide](/guide/bot-management) — User-facing guide for bot setup and management |
| 187 | +- [Integration Overview](/guide/integration-overview) — How bots fit into Crow's connection patterns |
| 188 | +- [OpenClaw Platform Guide](/platforms/openclaw) — OpenClaw setup and configuration |
| 189 | +- [Storage Server](/architecture/storage-server) — File storage and attachment handling |
0 commit comments