Build a Desktop AI Coding Agent with Electron and TypeScript
Build a Desktop AI Coding Agent with Electron and TypeScript: Designed as a zero-dependency, open-source TypeScript architecture under the MIT License with native Model Context Protocol (MCP) support and deterministic phase state machines.
- Runs 100% offline with Ollama — no internet required after setup
- Native file system access for full codebase operations
- Ship as a standalone .dmg / .exe without cloud infrastructure
- IPC bridge between Electron main and renderer for real-time streaming
Electron + Smoke Monkey Architecture
In an Electron app, Smoke Monkey runs in the main process where it has full Node.js API access. The renderer process (React/HTML UI) communicates via IPC:
- Renderer sends user instructions via
ipcRenderer.send('agent:run', instruction). - Main process creates an agent and streams events back via
ipcMain.on/mainWindow.webContents.send. - Renderer renders the live event stream in the chat UI.
This separation keeps the heavy agent execution away from the UI thread, maintaining a responsive interface.
import { app, BrowserWindow, ipcMain } from 'electron';import { createAgent } from 'smoke-monkey-harness';let mainWindow: BrowserWindow;ipcMain.on('agent:run', async (event, { instruction, workspacePath }) => {const agent = createAgent({provider: 'ollama',model: 'qwen2.5-coder:7b',workspacePath,autoApprove: false, // Surface permission gates to UI});// Stream events to rendereragent.on('tool.started', (e) =>mainWindow.webContents.send('agent:event', { type: 'tool.started', data: e.data }));agent.on('model.streaming', (e) =>mainWindow.webContents.send('agent:event', { type: 'streaming', chunk: e.data.chunk }));await agent.run(instruction);mainWindow.webContents.send('agent:event', { type: 'completed' });});
Configuring Ollama for Fully Offline Operation
To ship a fully offline desktop agent:
- Bundle Ollama in your app's resources, or guide users to install it via the onboarding flow.
- Pull the model at first launch if not already cached: run
ollama pull qwen2.5-coder:7bvia Electron'schild_process. - Set `OLLAMA_HOST` in the Electron main process environment before initializing the agent.
- Detect Ollama availability and show a setup screen if the local server isn't running.
Use qwen2.5-coder:7b for the best offline coding performance
At 7B parameters, it fits comfortably in 8GB of RAM and runs at 20-40 tokens/second on Apple Silicon — fast enough for a responsive desktop experience.
Frequently Asked Questions
Q:Can I package an Electron agent app for both macOS and Windows?
Yes. Smoke Monkey Harness has no platform-specific native dependencies. Use electron-builder to produce .dmg and .exe artifacts from the same TypeScript codebase.
Q:How do I handle the permission gate UI in Electron?
Subscribe to permission.requested events in the main process and use ipcMain to forward them to the renderer. Render a dialog in React and send the user's decision back via ipcRenderer.send.
Related Alternatives & Comparisons
Build with Smoke Monkey Harness
Zero dependencies. 24 built-in tools. Human-in-the-loop safety. 100% open source under the MIT License.