---
description: [remote_db_query]: How to inspect the production SQLite database inside the Docker container on 192.168.68.113 using SSH and Python.
---

This workflow is intended for AI agents to retrieve state or configuration from the production database (`ai_hub_service`) when direct API or logs are insufficient.

# Prerequisites
- Host: `192.168.68.113`
- User: `axieyangb`
- Password: `a6163484a`
- Target Container: `ai_hub_service`
- Target Database: `/app/data/ai-hub.db`

# Execution Pattern

// turbo
1.  **Run Query**: Execute the following command structure. 
    - **Note**: On Mac, use `/opt/homebrew/bin/sshpass` if `sshpass` is not in your PATH.
    - **Note**: Avoid the `-t` flag in SSH to prevent TTY allocation hangs in agent environments.

```bash
/opt/homebrew/bin/sshpass -p "a6163484a" ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no axieyangb@192.168.68.113 "echo 'a6163484a' | sudo -S docker exec ai_hub_service python3 -c 'import sqlite3; conn = sqlite3.connect(\"/app/data/ai-hub.db\"); cur = conn.cursor(); cur.execute(\"THE_SQL_QUERY\"); print(cur.fetchall()); conn.close()'"
```

# Common Queries for Agents

### Check Agent Mesh Status
```sql
SELECT node_id, display_name, last_status, is_active FROM agent_nodes;
```

### Find a Node by Name
```sql
SELECT * FROM agent_nodes WHERE display_name = 'Media Windows Server';
```

### Check User Preferences
```sql
SELECT email, preferences FROM users;
```

# Rules for Use
- **Database Path**: Always use `/app/data/ai-hub.db` (with a hyphen).
- **Compatibility**: Always use `python3 -c` with `sqlite3` inside the container.
- **Auth**: Use `sudo -S` with `echo 'password' |` to handle remote authentication without a TTY.
- **Quoting (CRITICAL)**: When the SQL query contains single quotes (e.g. `WHERE email = '...'`), it MUST be nested inside double quotes in the Python string, which must be escaped for the shell.
    - Correct: `cur.execute(\"SELECT ... WHERE email = 'jerxie.app@gmail.com'\")`
    - If you use single quotes for the SQL inside the single-quoted Python command (`python3 -c '...'`), the shell will break the command and HANG.
- **Non-Interactive**: Do NOT use `ssh -t`. It can cause the command to wait for a pseudo-terminal that doesn't exist.

# Troubleshooting "Stucks"
- If the command hangs, ensure `sshpass` is found (check `/opt/homebrew/bin/`).
- Ensure the password is correct.
- If the output is empty `[]`, check the database path and table name.
- If the connection times out, verify the host `192.168.68.113` is up.
