Skill: deerleo/modelwise-openclaw-setup (version 1.0.1)

--- name: OpenClaw Setup description: This skill should be used when the user asks to "install OpenClaw", "setup OpenClaw", "configure OpenClaw", "start OpenClaw gateway", "部署 OpenClaw", or needs help with OpenClaw installation, configuration, and initial setup on Windows/macOS/Linux systems. By ModelWise team. version: 1.0.0 --- # OpenClaw Installation and Setup Guide > **By ModelWise team** - Professional AI Agent Solutions This skill provides comprehensive guidance for installing, configuring, and running OpenClaw - an open-source personal AI assistant gateway. ## Overview **OpenClaw** is a multi-channel AI assistant gateway that enables users to use AI assistants on their existing messaging platforms (WhatsApp, Telegram, Slack, Discord, etc.). **Key Features:** - Local-first architecture - 20+ messaging channel integrations - Multi-model support (Anthropic, OpenAI, Google, local models) - Voice interaction (Voice Wake + Talk Mode) - Canvas visualization workspace (A2UI protocol) - Skills extension system ## Prerequisites ### System Requirements | Platform | Requirements | |----------|-------------| | **Windows** | Windows 10/11, Node.js >= 22.12.0 | | **macOS** | macOS 12+, Node.js >= 22.12.0 | | **Linux** | Ubuntu 20.04+/Debian 11+, Node.js >= 22.12.0 | ### Node.js Installation Check Node.js version first: ```bash node --version ``` #### Windows ```powershell # Option 1: Using winget winget install OpenJS.NodeJS.LTS # Option 2: Using Chocolatey choco install nodejs-lts # Option 3: Download installer # https://nodejs.org/ ``` #### macOS / Linux ```bash # Install nvm curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash # Reload shell source ~/.zshrc # or ~/.bashrc # Install Node.js 22 nvm install 22 nvm use 22 nvm alias default 22 ``` ## Installation ### Step 1: Install OpenClaw CLI ```bash # All platforms npm install -g openclaw@latest # Verify installation openclaw --version ``` ### Step 2: Run Configuration Wizard ```bash # Start interactive configuration openclaw onboard # Or with daemon installation (recommended) openclaw onboard --install-daemon ``` The wizard will guide through: 1. Model provider selection (Anthropic, OpenAI, Volcengine, etc.) 2. API key configuration 3. Channel setup (Telegram, Slack, etc.) 4. Gateway configuration ### Step 3: Configure API Keys API keys are stored in `~/.openclaw/credentials/` (or `%USERPROFILE%\.openclaw\credentials\` on Windows). ```bash # Set Anthropic API key openclaw credentials set anthropic YOUR_API_KEY # Set Volcengine API key (for Kimi) openclaw credentials set volcengine YOUR_API_KEY # Set OpenAI API key openclaw credentials set openai YOUR_API_KEY ``` ### Step 4: Start Gateway ```bash # Start gateway on default port (18789) openclaw gateway # Or specify port openclaw gateway --port 18789 # Run in background (macOS/Linux) openclaw gateway --daemon # Windows: run in new window or use pm2 start /B openclaw gateway ``` ## Configuration ### Config File Location | Platform | Path | |----------|------| | macOS/Linux | `~/.openclaw/openclaw.json` | | Windows | `%USERPROFILE%\.openclaw\openclaw.json` | ### Essential Configuration ```json5 { // Gateway settings gateway: { enabled: true, port: 18789, mode: "local", bind: "0.0.0.0" }, // Agent settings agents: { defaults: { model: "volcengine/kimi-k2.5", thinking: { enabled: true, level: "medium" } } }, // Telegram channel (example) telegram: { enabled: true, botToken: "YOUR_BOT_TOKEN", dmPolicy: "open", streaming: "partial" } } ``` ### Model Provider Configuration | Provider | Model Format | Credentials Key | |----------|-------------|-----------------| | Anthropic | `anthropic/claude-opus-4-6` | `anthropic` | | OpenAI | `openai/gpt-5.2` | `openai` | | Volcengine | `volcengine/kimi-k2.5` | `volcengine` | | Google | `google/gemini-2.5-pro` | `google` | | Local | `local/llama-3.2` | N/A | ## Channel Setup ### Telegram Bot Setup 1. **Create Bot:** - Open @BotFather on Telegram - Send `/newbot` - Follow instructions to get bot token 2. **Configure OpenClaw:** ```bash openclaw credentials set telegram 7123456789:AAHxxxxxxxx openclaw config set telegram.enabled true openclaw config set telegram.dmPolicy "open" ``` 3. **Restart Gateway:** ```bash openclaw gateway restart ``` ### Security Policies **DM Policy Options:** - `open`: Accept messages from anyone (for public bots) - `pairing`: Require pairing code approval (default, more secure) ## Common Commands ### Diagnostics ```bash # Check system status openclaw doctor # View running processes (macOS/Linux) ps aux | grep openclaw | grep -v grep # View running processes (Windows PowerShell) Get-Process | Where-Object {$_.ProcessName -eq "node"} # Check gateway status openclaw gateway status ``` ### Updates ```bash # Update to latest stable openclaw update --channel stable # Update to beta version openclaw update --channel beta ``` ### Maintenance ```bash # Stop gateway (macOS/Linux) killall openclaw openclaw-gateway # Stop gateway (Windows PowerShell) Stop-Process -Name "node" -Force # View logs tail -f ~/.openclaw/logs/gateway.log # macOS/Linux Get-Content $env:USERPROFILE\.openclaw\logs\gateway.log -Tail 100 # Windows # Clear sessions openclaw sessions prune ``` ## Directory Structure | Platform | Base Path | |----------|-----------| | macOS/Linux | `~/.openclaw/` | | Windows | `%USERPROFILE%\.openclaw\` | ``` .openclaw/ ├── openclaw.json # Main configuration ├── credentials/ # API keys (encrypted) ├── sessions/ # Session data ├── logs/ # Log files ├── workspace/ # Working directory │ └── skills/ # Custom skills ├── agents/ # Agent configurations ├── canvas/ # Canvas data ├── browser/ # Browser profiles └── memory/ # Memory storage ``` ## Troubleshooting ### Common Issues **1. Node.js version mismatch:** ```bash # Check version node --version # Should be >= 22.12.0 # Fix (macOS/Linux) nvm use 22 # Fix (Windows) # Download and install from https://nodejs.org/ ``` **2. Port already in use:** ```bash # macOS/Linux lsof -i :18789 kill -9 <PID> # Windows PowerShell netstat -ano | findstr :18789 taskkill /PID <PID> /F ``` **3. Permission denied:** ```bash # macOS/Linux sudo chown -R $(whoami) ~/.npm # Windows (run PowerShell as Administrator) npm cache clean --force ``` **4. Gateway not starting:** ```bash # Check logs (macOS/Linux) cat ~/.openclaw/logs/gateway.log # Check logs (Windows) type %USERPROFILE%\.openclaw\logs\gateway.log # Run diagnostics openclaw doctor ``` ### Reset Configuration ```bash # Backup and reset (macOS/Linux) cp ~/.openclaw/openclaw.json ~/.openclaw/openclaw.json.bak rm -rf ~/.openclaw openclaw onboard # Backup and reset (Windows PowerShell) Copy-Item $env:USERPROFILE\.openclaw\openclaw.json $env:USERPROFILE\.openclaw\openclaw.json.bak Remove-Item -Recurse -Force $env:USERPROFILE\.openclaw openclaw onboard ``` ## Quick Reference ```bash # Installation npm install -g openclaw@latest # Configuration openclaw onboard --install-daemon # Start/Stop openclaw gateway # Start killall openclaw # Stop (macOS/Linux) # Status openclaw doctor # Diagnostics openclaw --version # Version # Update openclaw update --channel stable ``` ## Additional Resources ### Scripts Cross-platform installation checkers: - **`scripts/check-installation.sh`** - Bash script (macOS/Linux/Windows Git Bash) - **`scripts/check-installation.ps1`** - PowerShell script (Windows) ### Reference Files - **`references/configuration-reference.md`** - Complete configuration options ### Example Files - **`examples/openclaw.json`** - Full configuration example - **`examples/telegram-setup.md`** - Telegram channel setup guide ### Official Resources - Website: https://openclaw.ai - Documentation: https://docs.openclaw.ai - GitHub: https://github.com/openclaw/openclaw - Discord: https://discord.gg/clawd - ClawHub (Skills): https://clawhub.com

path: examples/openclaw.json
content: {
  // Gateway Configuration
  gateway: {
    enabled: true,
    port: 18789,
    mode: "local",
    bind: "0.0.0.0",
    auth: {
      mode: "token"
    }
  },

  // Agent Configuration
  agents: {
    defaults: {
      model: "volcengine/kimi-k2.5",
      thinking: {
        enabled: true,
        level: "medium"
      },
      workspace: "~/.openclaw/workspace",
      compaction: {
        mode: "safeguard"
      },
      maxConcurrent: 4,
      subagents: {
        maxConcurrent: 8
      }
    }
  },

  // Model Providers
  models: {
    providers: {
      anthropic: {
        baseUrl: "https://api.anthropic.com",
        [REDACTED_SECRET]",
        models: [
          { id: "claude-opus-4-6", name: "Claude Opus 4.6", contextWindow: 200000 },
          { id: "claude-sonnet-4-6", name: "Claude Sonnet 4.6", contextWindow: 200000 }
        ]
      },
      volcengine: {
        baseUrl: "https://ark.cn-beijing.volces.com/api/coding/v3",
        [REDACTED_SECRET]",
        models: [
          { id: "kimi-k2.5", name: "Kimi K2.5", contextWindow: 128000 }
        ]
      },
      openai: {
        baseUrl: "https://api.openai.com/v1",
        [REDACTED_SECRET]",
        models: [
          { id: "gpt-5.2", name: "GPT-5.2", contextWindow: 128000 },
          { id: "o3", name: "O3", contextWindow: 200000 }
        ]
      }
    }
  },

  // Telegram Channel
  telegram: {
    enabled: true,
    botToken: "${TELEGRAM_BOT_TOKEN}",
    dmPolicy: "open",
    streaming: "partial",
    allowFrom: ["*"]
  },

  // Skills Configuration
  skills: {
    install: {
      nodeManager: "npm"
    },
    entries: {}
  },

  // Memory System
  memory: {
    enabled: true,
    provider: "lancedb"
  },

  // Browser Automation
  browser: {
    enabled: true,
    headless: false,
    color: "#FF4500"
  },

  // Canvas Workspace
  canvas: {
    enabled: true,
    a2ui: true
  }
}


path: examples/telegram-setup.md
content: # Telegram Bot Setup Guide

Complete guide to set up Telegram integration with OpenClaw.

## Step 1: Create Telegram Bot

1. Open Telegram and search for **@BotFather**
2. Send `/newbot` command
3. Follow the prompts:
   - Enter bot name (e.g., "My AI Assistant")
   - Enter bot username (must end with `bot`, e.g., "myai_assistant_bot")
4. BotFather will respond with your **Bot Token**

Example response:
```
Done! Congratulations on your new bot...
Use this token to access the HTTP API:
[REDACTED_SECRET]

Keep your token secure...
```

## Step 2: Configure OpenClaw

### Method A: Using CLI

```bash
# Set bot token
openclaw credentials set telegram 7123456789:AAHxxxxxxxx

# Enable Telegram channel
openclaw config set telegram.enabled true
openclaw config set telegram.dmPolicy "open"
```

### Method B: Edit Config File

Edit `~/.openclaw/openclaw.json`:

```json5
{
  telegram: {
    enabled: true,
    botToken: "${TELEGRAM_BOT_TOKEN}",
    dmPolicy: "open",
    streaming: "partial",
    allowFrom: ["*"]
  }
}
```

Then set the credential:

```bash
openclaw credentials set telegram 7123456789:AAHxxxxxxxx
```

## Step 3: Restart Gateway

```bash
# Stop existing gateway
killall openclaw openclaw-gateway 2>/dev/null

# Start gateway
openclaw gateway
```

## Step 4: Test the Bot

1. Open Telegram
2. Find your bot (search by username)
3. Send a message like "Hello"
4. The bot should respond

## Security Configuration

### Open Mode (Public Bot)

Anyone can message the bot:

```json5
{
  telegram: {
    dmPolicy: "open",
    allowFrom: ["*"]
  }
}
```

### Pairing Mode (Private Bot)

Requires approval for new users:

```json5
{
  telegram: {
    dmPolicy: "pairing"
  }
}
```

When someone messages the bot, they receive a pairing code. To approve:

```bash
openclaw pairing approve telegram <code>
```

### Allowlist Mode

Only specific users can message:

```json5
{
  telegram: {
    dmPolicy: "open",
    allowFrom: ["+1234567890", "+0987654321"]
  }
}
```

## Group Chat Configuration

### Require Mention

Bot only responds when mentioned:

```json5
{
  telegram: {
    groups: {
      "*": {
        requireMention: true,
        activation: "mention"
      }
    }
  }
}
```

### Always Active

Bot responds to all messages:

```json5
{
  telegram: {
    groups: {
      "*": {
        requireMention: false,
        activation: "always"
      }
    }
  }
}
```

### Reply Tracking

Bot tracks replies to its messages:

```json5
{
  telegram: {
    groups: {
      "*": {
        activation: "reply"
      }
    }
  }
}
```

## Streaming Configuration

| Mode | Description |
|------|-------------|
| `none` | Send complete response only |
| `partial` | Stream partial responses (recommended) |
| `full` | Stream every token |

```json5
{
  telegram: {
    streaming: "partial"
  }
}
```

## Troubleshooting

### Bot Not Responding

1. Check gateway is running:
```bash
ps aux | grep openclaw | grep -v grep
```

2. Check bot token is correct:
```bash
openclaw credentials get telegram
```

3. Check logs:
```bash
tail -f ~/.openclaw/logs/gateway.log
```

### Rate Limiting

Telegram has rate limits. If experiencing issues:

```json5
{
  telegram: {
    rateLimit: {
      enabled: true,
      messagesPerSecond: 1
    }
  }
}
```

### Webhook vs Polling

OpenClaw uses long polling by default. For webhook mode:

```json5
{
  telegram: {
    webhook: {
      enabled: true,
      url: "https://your-domain.com/telegram/webhook"
    }
  }
}
```


path: publish.sh
content: #!/bin/bash
# ClawHub Skill Publishing Script
# Usage: ./publish.sh

set -e

SKILL_DIR="./openclaw-setup"
SKILL_SLUG="openclaw-setup"
SKILL_NAME="OpenClaw Setup"
SKILL_VERSION="1.0.0"

echo "🦞 ClawHub Publishing Script"
echo "=============================="
echo ""

# Check if clawhub is installed
if ! command -v clawhub &> /dev/null; then
    echo "📦 Installing clawhub CLI..."
    npm i -g clawhub
fi

# Check login status
echo "🔐 Checking authentication..."
if ! clawhub whoami &> /dev/null; then
    echo "Please login first:"
    echo "  clawhub login"
    exit 1
fi

echo "✓ Authenticated as: $(clawhub whoami)"
echo ""

# Validate skill structure
echo "📋 Validating skill structure..."
if [ ! -f "$SKILL_DIR/SKILL.md" ]; then
    echo "✗ SKILL.md not found in $SKILL_DIR"
    exit 1
fi

echo "✓ SKILL.md found"
echo ""

# Show skill info
echo "📦 Skill to publish:"
echo "  Slug: $SKILL_SLUG"
echo "  Name: $SKILL_NAME"
echo "  Version: $SKILL_VERSION"
echo "  Directory: $SKILL_DIR"
echo ""

# Ask for changelog
read -p "📝 Enter changelog (press Enter for default): " CHANGELOG
CHANGELOG=${CHANGELOG:-"Release v$SKILL_VERSION"}

echo ""
echo "🚀 Publishing to ClawHub..."

# Publish
clawhub publish "$SKILL_DIR" \
    --slug "$SKILL_SLUG" \
    --name "$SKILL_NAME" \
    --version "$SKILL_VERSION" \
    --tags latest \
    --changelog "$CHANGELOG"

echo ""
echo "✅ Published successfully!"
echo ""
echo "🔗 View at: https://clawhub.com/skills/$SKILL_SLUG"
echo ""
echo "📥 Others can install with:"
echo "  clawhub install $SKILL_SLUG"


path: references/configuration-reference.md
content: # OpenClaw Configuration Reference

Complete configuration options for `~/.openclaw/openclaw.json`.

## Top-Level Structure

```json5
{
  gateway: { ... },      // Gateway server settings
  agents: { ... },       // Agent runtime settings
  channels: { ... },     // Messaging channel configs
  models: { ... },       // Model provider configs
  skills: { ... },       // Skills system configs
  cron: { ... },         // Scheduled jobs
  memory: { ... },       // Memory system
  browser: { ... },      // Browser automation
  canvas: { ... },       // Canvas workspace
}
```

## Gateway Configuration

```json5
{
  gateway: {
    enabled: true,           // Enable gateway
    port: 18789,             // WebSocket port
    mode: "local",           // "local" or "remote"
    bind: "0.0.0.0",         // Bind address (0.0.0.0 for LAN)
    auth: {
      mode: "token",         // "none", "token", "password"
      [REDACTED_SECRET]"    // Auth token (if mode="token")
    },
    tls: {
      enabled: false,        // Enable HTTPS/WSS
      cert: "/path/to/cert",
      key: "/path/to/key"
    },
    tailscale: {
      enabled: false,        // Enable Tailscale Serve
      funnel: false          // Enable public funnel
    }
  }
}
```

## Agent Configuration

```json5
{
  agents: {
    defaults: {
      model: "anthropic/claude-opus-4-6",  // Default model
      thinking: {
        enabled: true,
        level: "medium"       // "low", "medium", "high"
      },
      workspace: "~/.openclaw/workspace",
      compaction: {
        mode: "safeguard"     // Context compaction strategy
      },
      maxConcurrent: 4,       // Max concurrent agents
      subagents: {
        maxConcurrent: 8
      },
      sandbox: {
        mode: "non-main",     // "none", "non-main", "all"
        allowlist: ["bash", "read", "write"],
        denylist: ["browser", "canvas"]
      }
    }
  }
}
```

## Model Provider Configuration

### Anthropic

```json5
{
  models: {
    providers: {
      anthropic: {
        baseUrl: "https://api.anthropic.com",
        [REDACTED_SECRET]",  // From credentials
        models: [
          {
            id: "claude-opus-4-6",
            name: "Claude Opus 4.6",
            contextWindow: 200000,
            maxTokens: 16384
          }
        ]
      }
    }
  }
}
```

### Volcengine (Kimi)

```json5
{
  models: {
    providers: {
      volcengine: {
        baseUrl: "https://ark.cn-beijing.volces.com/api/coding/v3",
        [REDACTED_SECRET]",
        models: [
          {
            id: "kimi-k2.5",
            name: "Kimi K2.5",
            contextWindow: 128000,
            maxTokens: 8192
          }
        ]
      }
    }
  }
}
```

### OpenAI

```json5
{
  models: {
    providers: {
      openai: {
        baseUrl: "https://api.openai.com/v1",
        [REDACTED_SECRET]",
        models: [
          { id: "gpt-5.2", name: "GPT-5.2" },
          { id: "o3", name: "O3" }
        ]
      }
    }
  }
}
```

### Local (Ollama/LMStudio)

```json5
{
  models: {
    providers: {
      ollama: {
        baseUrl: "http://127.0.0.1:11434",
        [REDACTED_SECRET]",
        api: "ollama",
        models: [
          {
            id: "qwen3:8b",
            name: "Qwen3 8B",
            contextWindow: 32768
          }
        ]
      }
    }
  }
}
```

## Channel Configuration

### Telegram

```json5
{
  telegram: {
    enabled: true,
    botToken: "${TELEGRAM_BOT_TOKEN}",
    dmPolicy: "open",          // "open" or "pairing"
    streaming: "partial",      // "none", "partial", "full"
    allowFrom: ["*"],          // Allowed senders
    groups: {
      "*": {
        requireMention: true,  // Require @mention
        activation: "mention"  // "mention", "always", "reply"
      }
    }
  }
}
```

### Slack

```json5
{
  slack: {
    enabled: true,
    botToken: "${SLACK_BOT_TOKEN}",
    appToken: "${SLACK_APP_TOKEN}",
    signingSecret: "${SLACK_SIGNING_SECRET}",
    dmPolicy: "pairing"
  }
}
```

### Discord

```json5
{
  discord: {
    enabled: true,
    botToken: "${DISCORD_BOT_TOKEN}",
    clientId: "${DISCORD_CLIENT_ID}",
    dmPolicy: "pairing"
  }
}
```

### WhatsApp

```json5
{
  whatsapp: {
    enabled: true,
    dmPolicy: "pairing",
    allowFrom: ["+1234567890"],
    groups: {
      "*": { requireMention: true }
    }
  }
}
```

## Skills Configuration

```json5
{
  skills: {
    install: {
      nodeManager: "npm"       // "npm" or "pnpm"
    },
    entries: {
      "skill-name": {
        enabled: true,
        [REDACTED_SECRET]",
        env: {
          "CUSTOM_VAR": "value"
        }
      }
    }
  }
}
```

## Cron Jobs

```json5
{
  cron: {
    enabled: true,
    jobs: [
      {
        id: "daily-report",
        schedule: "0 9 * * *",    // Cron expression
        session: "main",
        message: "Generate daily report"
      }
    ]
  }
}
```

## Memory System

```json5
{
  memory: {
    enabled: true,
    provider: "lancedb",        // "lancedb", "sqlite-vec"
    embedding: {
      provider: "openai",
      model: "text-embedding-3-small"
    }
  }
}
```

## Browser Automation

```json5
{
  browser: {
    enabled: true,
    headless: false,
    color: "#FF4500",           // Browser frame color
    profile: "~/.openclaw/browser/profile"
  }
}
```

## Canvas Workspace

```json5
{
  canvas: {
    enabled: true,
    port: 18790,                // Canvas server port
    a2ui: true                  // Enable A2UI protocol
  }
}
```

## Environment Variables

Credentials are stored in `~/.openclaw/credentials/` and referenced via `${VAR_NAME}`:

| Variable | Description |
|----------|-------------|
| `ANTHROPIC_API_KEY` | Anthropic API key |
| `OPENAI_API_KEY` | OpenAI API key |
| `VOLCENGINE_API_KEY` | Volcengine (Kimi) API key |
| `GOOGLE_API_KEY` | Google AI API key |
| `TELEGRAM_BOT_TOKEN` | Telegram bot token |
| `SLACK_BOT_TOKEN` | Slack bot token |

## Set Credentials

```bash
# Set API key
openclaw credentials set anthropic sk-ant-xxxxx

# List credentials
openclaw credentials list

# Delete credential
openclaw credentials delete anthropic
```

## Configuration Commands

```bash
# Get config value
openclaw config get agents.defaults.model

# Set config value
openclaw config set agents.defaults.model anthropic/claude-opus-4-6

# Edit config in editor
openclaw config edit

# Validate config
openclaw config validate
```


path: scripts/check-installation.sh
content: #!/bin/bash
# OpenClaw Installation Checker - Cross Platform (macOS/Linux/Windows Git Bash)

# Colors (disable on Windows if not supported)
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
    GREEN=""
    YELLOW=""
    RED=""
    NC=""
else
    GREEN='\033[0;32m'
    YELLOW='\033[1;33m'
    RED='\033[0;31m'
    NC='\033[0m'
fi

echo "🦞 OpenClaw Installation Checker"
echo "================================="
echo ""

# Detect OS
detect_os() {
    case "$OSTYPE" in
        darwin*)  echo "macOS" ;;
        linux*)   echo "Linux" ;;
        msys*)    echo "Windows (Git Bash)" ;;
        cygwin*)  echo "Windows (Cygwin)" ;;
        win32*)   echo "Windows" ;;
        *)        echo "Unknown ($OSTYPE)" ;;
    esac
}

echo "📋 System: $(detect_os)"
echo ""

# Check Node.js
echo "📋 Checking Node.js..."
if command -v node &> /dev/null; then
    NODE_VERSION=$(node --version 2>/dev/null)
    NODE_MAJOR=$(echo "$NODE_VERSION" | cut -d'.' -f1 | tr -d 'v')

    if [ "$NODE_MAJOR" -ge 22 ]; then
        echo -e "  ${GREEN}✓${NC} Node.js version: $NODE_VERSION"
    else
        echo -e "  ${YELLOW}!${NC} Node.js version: $NODE_VERSION (need >= 22)"
        echo "    Upgrade: nvm install 22 && nvm use 22"
    fi
else
    echo -e "  ${RED}✗${NC} Node.js not installed"
    echo "    Install: https://nodejs.org/ or use nvm"
fi

# Check npm
echo ""
echo "📋 Checking npm..."
if command -v npm &> /dev/null; then
    NPM_VERSION=$(npm --version 2>/dev/null)
    echo -e "  ${GREEN}✓${NC} npm version: $NPM_VERSION"
else
    echo -e "  ${RED}✗${NC} npm not installed"
fi

# Check OpenClaw
echo ""
echo "📋 Checking OpenClaw..."
if command -v openclaw &> /dev/null; then
    OPENCLAW_VERSION=$(openclaw --version 2>/dev/null || echo "unknown")
    echo -e "  ${GREEN}✓${NC} OpenClaw CLI installed: $OPENCLAW_VERSION"
else
    echo -e "  ${RED}✗${NC} OpenClaw not installed"
    echo "    Install: npm install -g openclaw@latest"
fi

# Check config directory
echo ""
echo "📋 Checking configuration..."

# Cross-platform home directory
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then
    # Windows: use USERPROFILE or HOME
    if [ -n "$USERPROFILE" ]; then
        CONFIG_DIR="$USERPROFILE/.openclaw"
    else
        CONFIG_DIR="$HOME/.openclaw"
    fi
else
    # macOS/Linux
    CONFIG_DIR="$HOME/.openclaw"
fi

if [ -d "$CONFIG_DIR" ]; then
    echo -e "  ${GREEN}✓${NC} Config directory: $CONFIG_DIR"

    # Check config file
    if [ -f "$CONFIG_DIR/openclaw.json" ]; then
        echo -e "  ${GREEN}✓${NC} Configuration file exists"

        # Check model config (cross-platform grep)
        if grep -q "model" "$CONFIG_DIR/openclaw.json" 2>/dev/null; then
            echo -e "  ${GREEN}✓${NC} Model configured"
        else
            echo -e "  ${YELLOW}!${NC} Model not configured"
        fi
    else
        echo -e "  ${YELLOW}!${NC} Configuration file missing"
        echo "    Run: openclaw onboard"
    fi
else
    echo -e "  ${YELLOW}!${NC} Config directory missing: $CONFIG_DIR"
    echo "    Run: openclaw onboard"
fi

# Check Gateway
echo ""
echo "📋 Checking Gateway..."

# Cross-platform process check
check_gateway_process() {
    if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then
        # Windows: use tasklist
        tasklist //FI "IMAGENAME eq node.exe" 2>/dev/null | grep -q "node.exe" && return 0
        return 1
    else
        # macOS/Linux: use pgrep
        pgrep -f "openclaw gateway" > /dev/null 2>&1 && return 0
        return 1
    fi
}

if check_gateway_process; then
    echo -e "  ${GREEN}✓${NC} Gateway is running"
else
    echo -e "  ${YELLOW}!${NC} Gateway is not running"
    echo "    Start with: openclaw gateway"
fi

# Check port 18789 (cross-platform)
check_port() {
    if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then
        # Windows: use netstat
        netstat -an 2>/dev/null | grep -q ":18789.*LISTENING" && return 0
        return 1
    else
        # macOS/Linux: use lsof
        lsof -i :18789 > /dev/null 2>&1 && return 0
        return 1
    fi
}

if check_port; then
    echo -e "  ${GREEN}✓${NC} Port 18789 is in use"
else
    echo -e "  ${YELLOW}!${NC} Port 18789 is not in use"
fi

# Summary
echo ""
echo "================================="
echo "📊 Summary"

# Count issues
ISSUES=0

if ! command -v node &> /dev/null; then ((ISSUES++)); fi
if [ "$NODE_MAJOR" -lt 22 ] 2>/dev/null; then ((ISSUES++)); fi
if ! command -v openclaw &> /dev/null; then ((ISSUES++)); fi
if [ ! -d "$CONFIG_DIR" ]; then ((ISSUES++)); fi
if [ ! -f "$CONFIG_DIR/openclaw.json" ]; then ((ISSUES++)); fi

if [ "$ISSUES" -eq 0 ]; then
    echo -e "${GREEN}✓ OpenClaw is properly installed!${NC}"
    echo ""
    echo "Quick commands:"
    echo "  openclaw doctor      - Run diagnostics"
    echo "  openclaw gateway     - Start gateway"
    echo "  openclaw skills list - List installed skills"
else
    echo -e "${YELLOW}! Found $ISSUES issue(s)${NC}"
    echo ""
    echo "Installation steps:"
    echo ""
    echo "  Windows (PowerShell):"
    echo "    1. Install Node.js 22+: winget install OpenJS.NodeJS.LTS"
    echo "    2. Or download from: https://nodejs.org/"
    echo "    3. Install openclaw: npm install -g openclaw@latest"
    echo "    4. Run setup wizard: openclaw onboard"
    echo ""
    echo "  macOS/Linux:"
    echo "    1. Install Node.js 22+: nvm install 22"
    echo "    2. Install openclaw: npm install -g openclaw@latest"
    echo "    3. Run setup wizard: openclaw onboard"
fi

echo ""


Security scan verdicts — ClawScan: suspicious | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (CRITICAL)