Skip to content

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.

┌──────────────┐ 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).

  1. Generate seed — On first setup, Mia generates a persistent cryptographic seed stored in mia.json.
  2. Derive topic — A deterministic topic key is derived from the seed. Both peers must join the same topic to discover each other.
  3. Show QR codemia p2p qr encodes the seed into a QR code.
  4. Mobile scans — The Mia mobile app decodes the QR, derives the same topic key.
  5. DHT discovery — Both peers join the Hyperswarm DHT with the topic key. The DHT handles NAT traversal and hole punching.
  6. Encrypted connection — Once peers find each other, an encrypted channel is established.
Terminal window
# Show QR code
mia p2p qr
# Check connection status
mia p2p status
# Rotate seed (generates new QR, disconnects existing peers)
mia p2p refresh

All messages are typed JSON objects sent over the encrypted P2P channel.

TypeDescription
pingKeepalive
dispatchSend a prompt to the AI
abortCancel a running dispatch
new_conversationStart a new conversation
load_conversationSwitch to an existing conversation
rename_conversationRename a conversation
delete_conversationDelete a conversation
conversations_requestList all conversations
history_requestFetch message history (paginated)
plugins_requestList available plugins
plugin_switchChange active plugin
scheduler_list_requestList scheduled tasks
scheduler_createCreate a new scheduled task
search_requestSearch memory/conversations
suggestions_requestGet prompt suggestions
TypeDescription
pongKeepalive response
tokenStreaming token from AI
dispatch_completeDispatch finished
conversations_listFull conversation list
history_responseMessage history page
plugins_listAvailable plugins and active
scheduler_listAll scheduled tasks
search_resultsSearch results
errorError message

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.

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

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

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

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