Setup

From DingyangLyu/MatClaw · View interactive version

Setup is an AI agent skill from the GitHub repository DingyangLyu/MatClaw. Run initial MatClaw setup. Use when user wants to install dependencies, authenticate messaging channels, register their main channel, or start the background services. Triggers on "setup", "install", "configure matclaw", or first-time setup requests.

How to use this skill

Skill file

MatClaw Setup

Run setup steps automatically. Only pause when user action is required (channel authentication, configuration choices). Setup uses bash setup.sh for bootstrap, then npx tsx setup/index.ts --step <name> for all other steps. Steps emit structured status blocks to stdout. Verbose logs go to logs/setup.log.

Principle: When something is broken or missing, fix it. Don't tell the user to go fix it themselves unless it genuinely requires their manual action (e.g. authenticating a channel, pasting a secret token). If a dependency is missing, install it. If a service won't start, diagnose and repair. Ask the user for permission when needed, then do the work.

UX Note: Use AskUserQuestion for all user-facing questions.

1. Bootstrap (Node.js + Dependencies)

Run bash setup.sh and parse the status block.

2. Check Environment

Run npx tsx setup/index.ts --step environment and parse the status block.

3. Container Runtime

3a. Choose runtime

Check the preflight results for APPLE_CONTAINER and DOCKER, and the PLATFORM from step 1.

3a-docker. Install Docker

3b. Apple Container conversion gate (if needed)

If the chosen runtime is Apple Container, you MUST check whether the source code has already been converted from Docker to Apple Container. Do NOT skip this step. Run:

grep -q "CONTAINER_RUNTIME_BIN = 'container'" src/container-runtime.ts && echo "ALREADY_CONVERTED" || echo "NEEDS_CONVERSION"

If NEEDS_CONVERSION, the source code still uses Docker as the runtime. You MUST run the /convert-to-apple-container skill NOW, before proceeding to the build step.

If ALREADY_CONVERTED, the code already uses Apple Container. Continue to 4c.

If the chosen runtime is Docker, no conversion is needed. Continue to 4c.

3c. Build and test

Run npx tsx setup/index.ts --step container -- --runtime <chosen> and parse the status block.

If BUILD_OK=false: Read logs/setup.log tail for the build error.

If TEST_OK=false but BUILD_OK=true: The image built but won't run. Check logs — common cause is runtime not fully started. Wait a moment and retry the test.

4. API Configuration

Run npm run setup:api and parse the status block.

The interactive wizard handles provider selection (34 providers: Anthropic, Gemini, OpenAI, DeepSeek, Qwen, GLM, Kimi, and more), API key input with validation, and .env updates. If the user already has keys configured (detected from .env or Claude OAuth), the wizard will show the current config and offer to keep or reconfigure.

If STATUS=ok: API configured. Continue to step 5.

If STATUS=failed:

5. Set Up Channels

AskUserQuestion (multiSelect): Which messaging channels do you want to enable?

Delegate to each selected channel's own skill. Each channel skill handles its own code installation, authentication, registration, and JID resolution. This avoids duplicating channel-specific logic and ensures JIDs are always correct.

For each selected channel, invoke its skill:

Each skill will:

  1. Install the channel code (via apply-skill)
  2. Collect credentials/tokens and write to .env
  3. Authenticate (WhatsApp QR/pairing, or verify token-based connection)
  4. Register the chat with the correct JID format
  5. Build and verify

After all channel skills complete, continue to step 6.

6. Mount Allowlist

AskUserQuestion: Agent access to external directories?

No: npx tsx setup/index.ts --step mounts -- --empty

Yes: Collect paths/permissions. npx tsx setup/index.ts --step mounts -- --json '{"allowedRoots":[...],"blockedPatterns":[],"nonMainReadOnly":true}'

7. Start Service

If service already running: unload first.

Run npx tsx setup/index.ts --step service and parse the status block.

If FALLBACK=wsl_no_systemd: WSL without systemd detected. Tell user they can either enable systemd in WSL (echo -e "[boot]\nsystemd=true" | sudo tee /etc/wsl.conf then restart WSL) or use the generated start-matclaw.sh wrapper.

If DOCKER_GROUP_STALE=true: The user was added to the docker group after their session started — the systemd service can't reach the Docker socket. Ask user to run these two commands:

  1. Immediate fix: sudo setfacl -m u:$(whoami):rw /var/run/docker.sock
  2. Persistent fix (re-applies after every Docker restart):
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo tee /etc/systemd/system/docker.service.d/socket-acl.conf << 'EOF'
[Service]
ExecStartPost=/usr/bin/setfacl -m u:USERNAME:rw /var/run/docker.sock
EOF
sudo systemctl daemon-reload

Replace USERNAME with the actual username (from whoami). Run the two sudo commands separately — the tee heredoc first, then daemon-reload. After user confirms setfacl ran, re-run the service step.

If SERVICE_LOADED=false:

8. Verify

Run npx tsx setup/index.ts --step verify and parse the status block.

If STATUS=failed, fix each:

Tell user to test: send a message in their registered chat. Show: tail -f logs/matclaw.log

Troubleshooting

Service not starting: Check logs/matclaw.error.log. Common: wrong Node path (re-run step 7), missing .env (step 4), missing channel credentials (re-invoke channel skill).

Container agent fails ("Claude Code process exited with code 1"): Ensure the container runtime is running — open -a Docker (macOS Docker), container system start (Apple Container), or sudo systemctl start docker (Linux). Check container logs in groups/main/logs/container-*.log.

No response to messages: Check trigger pattern. Main channel doesn't need prefix. Check DB: npx tsx setup/index.ts --step verify. Check logs/matclaw.log.

Channel not connecting: Verify the channel's credentials are set in .env. Channels auto-enable when their credentials are present. For WhatsApp: check store/auth/creds.json exists. For token-based channels: check token values in .env. Restart the service after any .env change.

Unload service: macOS: launchctl unload ~/Library/LaunchAgents/com.matclaw.plist | Linux: systemctl --user stop matclaw

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.