P2P & Mobile
The Mia mobile app is the primary way to interact with your AI coding assistant. It connects to your daemon over Hyperswarm DHT — encrypted, serverless, peer-to-peer. No cloud servers, no port forwarding, no relay. Just your phone talking directly to your dev machine.
How It Works
Section titled “How It Works”Architecture
Section titled “Architecture”┌──────────────┐ Hyperswarm DHT ┌──────────────┐│ Mia Daemon │◄──────────────────────►│ Mobile App ││ (your PC) │ Encrypted P2P conn │ (your phone)│└──────┬───────┘ └──────────────┘ │ │ IPC (child process) │┌──────▼───────┐│ P2P Sub-Agent││ (Hyperswarm) │└──────────────┘The daemon spawns a P2P sub-agent as a child process. This sub-agent handles all Hyperswarm networking and communicates with the daemon via IPC (stdin/stdout).
Pairing Flow
Section titled “Pairing Flow”- Generate seed — On first setup, Mia generates a persistent cryptographic seed stored in
mia.json. - Derive topic — A deterministic topic key is derived from the seed. Both peers must join the same topic to discover each other.
- Show QR code —
mia p2p qrencodes the seed into a QR code. - Mobile scans — The Mia mobile app decodes the QR, derives the same topic key.
- DHT discovery — Both peers join the Hyperswarm DHT with the topic key. The DHT handles NAT traversal and hole punching.
- Encrypted connection — Once peers find each other, an encrypted channel is established.
# Show QR codemia p2p qr
# Check connection statusmia p2p status
# Rotate seed (generates new QR, disconnects existing peers)mia p2p refreshMessage Protocol
Section titled “Message Protocol”All messages are typed JSON objects sent over the encrypted P2P channel.
Mobile → Daemon (Inbound)
Section titled “Mobile → Daemon (Inbound)”| Type | Description |
|---|---|
ping | Keepalive |
dispatch | Send a prompt to the AI |
abort | Cancel a running dispatch |
new_conversation | Start a new conversation |
load_conversation | Switch to an existing conversation |
rename_conversation | Rename a conversation |
delete_conversation | Delete a conversation |
conversations_request | List all conversations |
history_request | Fetch message history (paginated) |
plugins_request | List available plugins |
plugin_switch | Change active plugin |
scheduler_list_request | List scheduled tasks |
scheduler_create | Create a new scheduled task |
search_request | Search memory/conversations |
suggestions_request | Get prompt suggestions |
Daemon → Mobile (Outbound)
Section titled “Daemon → Mobile (Outbound)”| Type | Description |
|---|---|
pong | Keepalive response |
token | Streaming token from AI |
dispatch_complete | Dispatch finished |
conversations_list | Full conversation list |
history_response | Message history page |
plugins_list | Available plugins and active |
scheduler_list | All scheduled tasks |
search_results | Search results |
error | Error message |
Message Store
Section titled “Message Store”All conversations and messages are persisted in a local SQLite database:
- Conversations: ID, title, timestamps, first user message
- Messages: Role, content, metadata, timestamps
- Export: NDJSON format for interop
The message store initializes with a 15-second timeout. If initialization fails, a write buffer queues messages until the store becomes available.
Connection Management
Section titled “Connection Management”Reconnection
Section titled “Reconnection”The swarm-connection-manager handles peer lifecycle:
- Exponential backoff for reconnects (caps at 30 seconds)
- Automatic reconnection on disconnect
- Connection pool management
- Anonymous peer cap enforcement
Real-time Sync
Section titled “Real-time Sync”Everything stays in sync across devices:
- Conversations: Broadcast on create/rename/delete
- Messages: Stored locally, broadcast to all peers
- Plugin state: Switch on one device, reflected everywhere
- Scheduler: Tasks run on daemon, results synced to mobile
Echo Prevention
Section titled “Echo Prevention”To prevent message duplication when peers sync:
- Outbound messages are tracked by ID
- Incoming messages with matching IDs are ignored
- Timestamp-based ordering resolves conflicts
Mobile App
Section titled “Mobile App”The mobile app (Mia Expo) is built with React Native and is the primary interface for Mia:
- Real-time streaming AI responses with full markdown rendering
- Conversation management (create, rename, delete, search)
- Plugin switching between coding agents
- AI persona management (create, edit, delete, generate from description)
- Scheduler management (create and monitor cron tasks)
- Slash commands (
/standup,/doctor,/usage,/memory,/recap, etc.) - QR code scanning for pairing
- Auto-reconnect on foreground
- Inline tool output with collapsible summaries