# Clawdbot Scripts

Automation scripts for the Clawdbot system. These run on the VPS at `134.199.153.159`.

## Scripts

### Core Operations
| Script | Purpose | Schedule |
|--------|---------|----------|
| `health-check.sh` | Basic system health check | Every 5 min |
| `health-check-v2.sh` | Health check with auto-rollback | Every 5 min |
| `telegram-alert.sh` | Send alerts to Telegram | On-demand |
| `agent-status.sh` | Update AI Agent status in Notion | On-demand |
| `slack-to-notion.sh` | Monitor Slack, create tasks in Notion | Every 5 min |
| `morning-brief.sh` | Send morning brief to Telegram | 6am Sydney |
| `evening-brief.sh` | Send evening brief to Telegram | 6pm Sydney |

### Self-Improvement Loop
| Script | Purpose | Schedule |
|--------|---------|----------|
| `cc-read-lessons.sh` | Read lessons at CC session start | Session start |
| `cc-learn-stage.sh` | Stage a new lesson to Notion | After discoveries |
| `weekly-patterns.sh` | Analyze patterns, identify improvements | Monday 7am |

### Data Sync
| Script | Purpose | Schedule |
|--------|---------|----------|
| `hot-leads-sync.sh` | Sync hot leads (score 70+) to Notion | Hourly |

See `SYSTEM-REFERENCE.md` for complete documentation.

## Setup

1. Copy scripts to VPS:
   ```bash
   scp -r clawd-scripts/* root@134.199.153.159:/home/clawd/scripts/
   ```

2. Copy and configure environment:
   ```bash
   ssh root@134.199.153.159
   cd /home/clawd/scripts
   cp config.env.example config.env
   nano config.env  # Fill in values
   ```

3. Make scripts executable:
   ```bash
   chmod +x /home/clawd/scripts/*.sh
   ```

4. Install dependencies:
   ```bash
   apt-get install -y jq bc curl
   ```

5. Set up cron jobs:
   ```bash
   /home/clawd/scripts/setup-cron.sh
   ```

## Configuration

Copy `config.env.example` to `config.env` and fill in:

- `NOTION_API_KEY` - Notion integration token
- `TELEGRAM_BOT_TOKEN` - Telegram bot token
- `TELEGRAM_CHAT_ID` - Your Telegram chat ID
- `SLACK_BOT_TOKEN` - Slack bot token
- `ANTHROPIC_API_KEY` - Claude API key (for AI features)
- Database IDs for Notion databases

## Notion Databases Required

| Database | Purpose |
|----------|---------|
| Command Center | Central hub, dashboard |
| Work Tracker | Tasks and bugs |
| Deploy Log | Deployment records |
| AI Agents | Agent status tracking |
| System State | System health status |
| Lessons Learned | Post-deploy learnings |
| Hot Leads | High-score leads from Growth Engine |

See `SYSTEM-REFERENCE.md` for MCP data_source_ids.

## Logs

Logs are written to `/var/log/clawdbot/`:
- `health-check.log`
- `slack-sync.log`
- `morning-brief.log`
- `evening-brief.log`

## Manual Testing

```bash
# Test Telegram alerts
./telegram-alert.sh INFO "Test message"

# Test agent status update
./agent-status.sh "Clawdbot" "Online" "Testing"

# Test health check (will update Notion)
./health-check.sh

# Test briefs (will send to Telegram)
./morning-brief.sh
./evening-brief.sh
```

## Timezone Notes

Sydney is UTC+11 (AEDT) or UTC+10 (AEST).
- 6am Sydney AEDT = 7pm UTC (previous day)
- 6am Sydney AEST = 8pm UTC (previous day)
- 6pm Sydney AEDT = 7am UTC
- 6pm Sydney AEST = 8am UTC

Adjust cron times in `setup-cron.sh` when daylight savings changes.
