---
name: app-watchdog
description: Audit and verify deployed apps are running the correct version, responding properly, and have no broken navigation. Catches stale builds, wrong codebases, dead routes, and process issues.
user-invocable: true
metadata:
  openclaw:
    emoji: "🐕"
---

# App Watchdog

The App Watchdog ensures every deployed product app is running correctly — right codebase, all routes responding, no stale builds, no broken navigation.

## When to Run

- **After every build/deploy** — automatically verify the deployed app
- **On demand** — `/watchdog` or `/watchdog <slug>`
- **Periodic sweep** — can be scheduled via cron to check all running apps
- **When a user reports issues** — first line of diagnosis

## Commands

### `/watchdog` or `/watchdog all`
Audit ALL running apps. Checks every allocated port in `caddy-ports.json`.

### `/watchdog <slug>`
Audit a specific app by product slug.

### `/watchdog report`
Generate a full health report of all apps.

## Checks Performed

### 1. Process Health
- Is the app process running on its allocated port? (`lsof -ti :<port>`)
- What process is actually running? (Node, Vite, Next.js, etc.)
- Is it the expected framework? (Check `package.json` for Next.js vs Vite vs other)
- Memory/CPU usage reasonable?

### 2. Codebase Verification
- **Framework match**: If `package.json` has `next`, ensure `next start` is running (not `vite preview`)
- **Multiple codebases**: Check for conflicting setups (e.g., both `frontend/` Vite AND `src/` Next.js)
- **Correct entry point**: Verify the running process points to the right directory
- **Build freshness**: Compare `.next/BUILD_ID` or `dist/` timestamps with last git commit

### 3. Route Health
- Hit the app's public URL and verify HTTP 200
- Check key routes based on app type:
  - Login page accessible
  - Dashboard loads after auth (if applicable)
  - API routes respond (if applicable)
- Check for "Coming Soon" or placeholder pages that should have real content

### 4. Version Consistency
- Compare running code with latest git commit
- Flag if uncommitted changes exist
- Flag if running build is older than latest commit

## Audit Process

```bash
# For each app in caddy-ports.json:

# 1. Check if running
PORT=$(jq -r '.allocated["<slug>"]' caddy-ports.json)
PID=$(lsof -ti :$PORT 2>/dev/null)

# 2. Check what's running
ps -p $PID -o args=

# 3. Check framework
cat /home/aria/products/<slug>/apps/main/package.json | jq '.dependencies | keys'

# 4. HTTP health check
curl -s -o /dev/null -w "%{http_code}" https://<slug>.dev.apps.symph.co

# 5. Check for stale builds
ls -la /home/aria/products/<slug>/apps/main/.next/BUILD_ID 2>/dev/null
git -C /home/aria/products/<slug> log --oneline -1
```

## Output Format

```
🐕 App Watchdog Report
━━━━━━━━━━━━━━━━━━━━

✅ ai-teacher-assistant (port 3003)
   Framework: Next.js | Process: node next-start | HTTP: 200
   
⚠️ pen-brothers (port 3017)
   Framework: Next.js (expected) | Process: vite preview (WRONG!)
   Issue: Running Vite prototype instead of Next.js app
   Fix: Kill vite, run `npm run build && npm run start -p 3017`
   
❌ gala-grid (port 3009)
   Process: NOT RUNNING
   
🔄 sthics (port 3011)
   Framework: Next.js | Process: node next-start | HTTP: 200
   Warning: Build is 3 days older than latest commit
```

## Auto-Fix Capabilities

When issues are found, the watchdog can:

1. **Wrong framework running** → Kill old process, build correct one, start it
2. **App not running** → Build and start it
3. **Stale build** → Rebuild and restart
4. **Multiple codebases detected** → Flag for human decision (don't auto-pick)

## Integration

- Results posted to #aria channel on Discord
- Can be triggered from Symph Agency UI (future)
- Runs as part of heartbeat checks (optional — add to HEARTBEAT.md)

## Key Files

- Port allocations: `agency/infra/caddy-ports.json`
- Product apps: `/home/aria/products/<slug>/apps/main/`
- App logs: `/home/aria/projects/.aria-logs/`
