How openagentplatform/dive works
Project Type & Purpose
• Project Type: Electron desktop application with a React/TypeScript renderer and a Node/TypeScript main process.
• Purpose: Host and orchestrate “Model Context Protocol” (MCP) LLM agents via a Python-based DiveHost, provide UI for chats, settings, updates, and multi-language support.
File Structure
• Top-Level Modules:
– electron/… → main-process code (IPC channels, tray, menu, auto-update, service).
– electron/preload/… → sandboxed bridge exposing safe IPC methods to the renderer.
– src/… → React renderer: views, components, hooks, atoms (state), styles.
– scripts/… & docker/… → build, packaging, host binaries, MCP host downloads.
– prebuilt/… → precompiled DiveHost Python package for stdio/SSE modes.
• Config & Tooling: vite.config.*.ts, electron-builder.json, tsconfig.*, Dockerfiles, BUILD.md.
Pull Insights from README
• Cross-platform support (Windows, macOS, Linux).
• Universal LLM support via function-calling.
• Auto-update mechanism.
• Python DiveHost rewritten v0.8.0 extracted to separate repo; here prebuilt host used.
• Configurable MCP servers (fetch, filesystem, yt-dl) via stdio or SSE transport.
Main Components & Interactions
a. Components
1. Renderer Process (React UI)
– Chat UI, settings panels, localizations, state mgmt (Jotai atoms), Vite dev server in dev mode.
2. Preload Script
– Exposes a typed IPC API (ipcRenderer.invoke / on) for environment, system, menu, LLM commands.
3. Main Process
– Bootstraps BrowserWindow, handles tray/menu, IPC handlers, spawns DiveHost subprocess, orchestrates update checks, reads/writes store.
4. DiveHost Subprocess (Python)
– Launch command (uvx or Python), supports stdio / SSE for MCP tool invocations, communicates JSON-RPC with main.
5. Persistent Store & File System
– Electron-store or similar (state.json), chat history, MCP server configs, localization JSON.
6. External Services / APIs
– LLM providers (OpenAI, Anthropic, Gemini, Mistral) via HTTP/HTTPS.
– External MCP SSE servers.
– Auto-update server (GitHub Releases).
b. Interactions
– UI → Preload → IPC → Main
– Main ↔ DiveHost (stdio pipes or SSE)
– Main → Local FS (read/write config & history)
– Main → GitHub Releases (auto‐update)
– DiveHost → External MCP tools (spawn local tools or HTTP calls)
– Main → LLMs (via DiveHost or direct HTTP if implemented)
Architectural Patterns & Principles
• Multi‐process separation (renderer vs. main vs. subprocess).
• IPC event/command pattern for security and separation of concerns.
• React + Jotai for unidirectional data flow in the renderer.
• Plugin‐style MCP server configuration (extensible tool integrations).
• Auto-update leveraging electron-builder and GitHub Releases.