MkAgent is a Bun monorepo with three clients sharing one authenticated WebSocket RPC protocol. Only the pi agent backend is registered. The direct Pi integration is @earendil-works/pi-coding-agent; pi-agent-core and pi-ai are lower-level dependencies, not the application-facing session API.
+-----------------------------------------------------------+
| apps/electron apps/webui apps/cli |
| Electron Browser RPC client |
| (Browser pane, adapter (loads (connects to |
| Sentry, auto- the same React running server |
| update, IPC) app via header or spawns a |
| \ handshake) one-shot server) |
+---------|----------------|--------------------|-------------+
v v v
Browser adapter ──> preload Client API ──> RPC client
(window.MkAgent) (rpc-client.ts)
|
WebSocket (wss://)
v
+-----------------------------------------------------------+
| packages/server-core |
| transport (WS server + JWT) / SessionManager / |
| handlers / services / webui (HTTP+sessions) / |
| model-fetchers / sessions |
+---------|---------------------------------------|
v |
packages/server (headless `MKAGENT_SERVER_TOKEN` server)
v |
+-----------------------------------------------------------+
| packages/shared |
| config / credentials / prompts / Skills / |
| workspaces / views / theme / i18n / AgentEvent / |
| backend registry (only `pi`) |
+-----------------------------------------------------------+
|
v
+-----------------------------------------------------------+
| packages/pi-agent-server |
| Bun subprocess, JSONL on stdio, talks to Pi SDK |
+-----------------------------------------------------------+
v
+-----------------------------------------------------------+
| packages/ui packages/session-tools-core |
| React primitives, LLM-backed session tools |
| markdown/doc (plan, skill, mermaid, |
| renderers, IPC, convert, mini LLM, browser, |
| settings pages session info/list, etc.) |
+-----------------------------------------------------------+
All three clients operate the same workspace and JSONL sessions; there is no client-specific storage.
apps/electronembeds the local server, exposes the Client API through preload, and owns windows, Browser panes, proxy integration, auto-update, and Sentry.apps/webuiloads the same React application through a browser adapter. The headless server serves its static files and the authenticated attachment endpoint.apps/cliuses the same RPC methods and can connect to an existing server or start a temporary local instance forrun.
packages/server-coreowns transport, handlers,SessionManager, and platform-neutral services. Subpackages:bootstrap/,domain/,handlers/,model-fetchers/,runtime/,services/,sessions/,transport/,utils/,webui/.packages/sharedowns protocol DTOs (@mkagent/shared/protocol), config, credentials, Skills, prompts, the backend registry, workspace storage, and the Pi client.packages/pi-agent-serverrunscreateAgentSession(...)from@earendil-works/pi-coding-agentin a separate Bun subprocess (packages/pi-agent-server/dist/index.js) and communicates through JSONL. The same SDK boundary is used in development and packaged builds;bun run server:build:subprocessproduces the bundle.packages/uiandpackages/session-tools-coreprovide shared rendering and session-level tools. They are platform-neutral: Electron, WebUI, and CLI reuse them.
Only the pi backend is registered. Custom endpoints (openai-completions, anthropic-messages) and Ollama are connection variants executed through Pi rather than separate backends. The registry is initialized by registerPiModelResolver(...) inside packages/server/src/index.ts and apps/electron/src/main.
- The server binds on
MKAGENT_RPC_HOST:MKAGENT_RPC_PORT(default127.0.0.1:9100). - The bearer token is read from
MKAGENT_SERVER_TOKEN(Electron generates one automatically on launch; the headless server requires it to be passed in). - The token is exchanged for a short-lived JWT used on every subsequent WebSocket frame (
@mkagent/server-core/webui). - WebUI and CLI additionally support
MKAGENT_WEBUI_PASSWORD(falls back toMKAGENT_SERVER_TOKEN) and an optionalMKAGENT_TLS_CAfor TLS pinning. - The handshake binds a workspace id; later RPC commands are scoped to that workspace and only see its sessions, Skills, permissions, and Views.
The Pi subprocess is isolated from the main process:
main process (Bun)
└─ spawns: bun packages/pi-agent-server/dist/index.js
↕ JSONL on stdio (one JSON object per turn event)
Pi SDK ↔ provider (HTTPS)
Abort, model switching, thinking-level change, permission responses, and session resume are all routed through the same JSONL stream. Pi recovery files are stored under ~/.mkagent/workspaces/<slug>/sessions/<id>/.
- Desktop app: macOS arm64 / x64 (DMG + ZIP), Windows x64 (NSIS), Linux x64 (AppImage). Build entry:
bun run electron:dist[:dev][:mac|:win|:linux]. - Headless server: per-platform compiled Bun archive; build with
bun run scripts/build-server.ts. - CLI:
bun run cli:buildproducesdist/mkagent. - Pi subprocess:
bun run server:build:subprocessproducespackages/pi-agent-server/dist/index.js.
The main MkThingsHQ/mkagent repository publishes DMG/ZIP/NSIS/AppImage assets, headless-server archives, a Bun CLI archive, manifests, blockmaps, checksums, and release notes in GitHub Releases. electron-updater reads the public manifests and never embeds a GitHub token in the client.
Craft Agents bundles broad OAuth and Sources integrations, a Slack/Teams/Lark messaging gateway, a WhatsApp worker backed by Baileys, a session MCP server, a bridge MCP server, and an apps/viewer Electron app for public sharing. MkAgent retains only the ChatGPT and Claude LLM OAuth flows from that surface; the other components remain absent. Although Craft's underlying pi-ai dependency contains an OpenRouter image-generation API, neither Craft nor MkAgent registers it as an agent tool. See comparison-with-craft.md for an evidence-backed side-by-side and the resulting installer-size delta.