# collab-doctor

`collab-doctor` is the v0.3.0 self-diagnosis tool. It probes 6 layers of your
claude-collab setup and prints a fix suggestion for every failure.

## Checks (in order)

1. **config.json valid** — JSON parse + readable file
2. **mcp_url reachable** — TCP connect to `cfg.mcp_url`
3. **api_key configured** — non-empty inline or `api_key_file`
4. **api_key accepted** — `GET /api/messages?limit=1` with `X-API-Key` header, expect 200
5. **pending_dir writable** — `mkdir -p` + write probe + cleanup
6. **Node.js + collab-mcp version** — runtime sanity

## Exit codes

- `0` — all green (warnings OK)
- `1` — fixable errors found (read output, apply fixes, re-run)

## Common fixes

| Symptom | Fix |
|---|---|
| `mcp_url 127.0.0.1:3010 reachable` ✗ | `collab-mcp start` on the host |
| `api_key configured` ✗ | `claude-collab-config set api_key cmcp_xxx.<secret>` |
| `api_key accepted` ✗ (HTTP 401) | Key revoked — `collab-mcp keys create claude-collab --scopes=read,write` then update |
| `pending_dir ./tmp writable` ✗ | `mkdir -p` or update config |
| `Node.js < 18` ✗ | Upgrade Node.js |

## Programmatic

```js
// Doctor is a CLI; for runtime checks use rpc() from src/cli.js:
const { rpc } = require('@trustbaseai/claude-collab');
try {
  const r = await rpc('read_messages', { since_id: 0, limit: 1 });
  console.log('healthy', r);
} catch (e) {
  console.error('unhealthy', e.message);
}
```