ITADN
README.md

MiQi

🐈‍⬛🪶 A lightweight, extensible personal AI agent framework with a modern desktop interface

Python 3.11 | 3.12 Node.js 20+ Development Status: Alpha MIT License


Overview

MiQi Desktop is an Electron-based desktop application that provides a modern graphical interface for the MiQi AI agent. It combines powerful AI agent capabilities with an intuitive user interface, supporting chat interaction, memory management, task scheduling, and more. interface

Core Positioning

  • 🎯 Personal AI Agent — not just a chatbot: persistent memory, learned skills, file operations, and scheduled tasks
  • 🔧 Highly Extensible — MCP protocol for external tools, custom skills, and pluggable LLM providers
  • 🖥️ Native Desktop Experience — Electron with system-level integration (WSL2 sandbox, filesystem operations)
  • 🔒 Local-First — all data stored locally; non-destructive file editing with versioned snapshots
  • 📋 Typed Application Protocol — typed AppServer with JSON Schema catalog, method stability tracking, and handler-boundary validation

Tech Stack

LayerTechnologyVersion
Desktop FrameworkElectron35.2
Frontend UIReact + TypeScript19.1 / 5.8
CSSTailwind CSS 44.x
Component LibraryRadix UI + Lucide Icons
Python RuntimePython (asyncio)3.11+
Data ValidationPydantic v22.12+
CLI FrameworkTyper0.20+
Build (Desktop)electron-vite + electron-builder3.1 / 26.0
Build (Python)PyInstaller + Hatchling6.20+

Key Features

FeatureDescription
Smart ChatNatural language conversation with streaming responses and tool-call progress
Multi-ProviderOpenAI, Anthropic, Gemini, OpenRouter, DeepSeek, and more — with provider resilience
Typed ProtocolTyped AppServer with method specs, JSON Schema catalog, and handler-boundary validation
Memory SystemLong-term memory snapshots, self-improvement lessons, and cross-session recall
Task SchedulerCron-based scheduled tasks with timezone support
Skill SystemCreate, upload, and manage agent skills; SkillHub registry integration
Plugin EcologyMCP servers, plugins, and marketplace with deterministic catalog
Sandbox Executionbwrap-based sandbox with LANDLOCK filesystem rules, streaming I/O, and process lifecycle
File ManagementWorkspace FS with watch, fuzzy search, snapshot/versioning, and non-destructive editing
Replay & DebugDeterministic replay of turns, timeline, and messages for inspection
Session ManagementBrowse, search, archive, import/export conversation history
Desktop App15+ feature pages with real-time streaming, typewriter animation, and context menus

Quick Start

Prerequisites

  • Python 3.11+ — to run MiQi backend
  • Node.js 20+ — to run Electron frontend
  • uv — Python package manager (recommended)

Installation

# 1. Clone the repository
git clone http://git.miqroera.com/intership/miqi-desktop.git
cd miqi-desktop

# 2. Install Python dependencies
uv sync

# 3. Install frontend dependencies
cd apps/desktop
npm install

Development Mode

# Start Electron dev server with hot-reload
cd apps/desktop
npm run dev

Production Build

One-step build (recommended):

cd apps/desktop
npm run build:all    # Python backend → Frontend compile → Electron package

Step-by-step build:

cd apps/desktop

# 1. Build Python backend (generates dist/miqi-bridge.exe)
npm run build:bridge

# 2. Compile frontend
npm run build

# 3. Package as desktop application
npx electron-builder --win --publish never

The packaged miqi-bridge.exe is a self-contained binary (PyInstaller onefile) that includes Python and all dependencies — no system Python installation required on the target machine. It also supports a --check flag for environment validation:

miqi-bridge.exe --check
# Output: {"ok": true, "python_version": "3.12.10", "issues": []}

Architecture

┌─────────────────────────────────────────────────────────────┐
│                    MiQi Desktop App                         │
├─────────────────────────────────────────────────────────────┤
│  Electron Frontend                                          │
│  ├── React 19 + TypeScript                                 │
│  ├── Tailwind CSS 4 + shadcn/ui                            │
│  └── 15+ Feature Pages (Chat, Agents, Skills, MCPs, ...)   │
├─────────────────────────────────────────────────────────────┤
│  Bridge (IPC Communication)                                 │
│  ├── stdin/stdout JSON-line protocol                        │
│  ├── State synchronization + Log forwarding                 │
│  └── BridgeRuntimeLoop (persistent asyncio event loop)      │
├─────────────────────────────────────────────────────────────┤
│  AppServer (Typed Protocol Layer)                            │
│  ├── ProtocolRegistry (typed method specs)                  │
│  ├── Typed Envelopes (Pydantic v2)                          │
│  ├── JSON Schema Draft 2020-12 Catalog                      │
│  └── Handler Typed Validation                               │
├─────────────────────────────────────────────────────────────┤
│  MiQi Runtime Engine                                        │
│  ├── RuntimeSession / TaskRunner / TurnRunner               │
│  ├── HistoryRuntime + LedgerRuntime (SQLite persistence)    │
│  ├── ContextRuntime (compaction, token budgeting)           │
│  ├── ThreadRuntime (fork, rollback, import/export)          │
│  └── ReplayRuntime (deterministic replay inspection)        │
├─────────────────────────────────────────────────────────────┤
│  Execution & Sandbox                                        │
│  ├── ToolOrchestrator (approval → sandbox → execute)       │
│  ├── PermissionEngine + ApprovalPolicy + HookRuntime        │
│  ├── bwrap Sandbox (LANDLOCK, streaming, cancellation)      │
│  └── Workbench Process Runtime (command/exec, process/*)    │
├─────────────────────────────────────────────────────────────┤
│  Tools & Integrations                                       │
│  ├── Built-in Tools (filesystem, shell, web, papers, ...)   │
│  ├── MCP Client (external tool servers)                     │
│  ├── Plugin Manager + Skill Loader                          │
│  └── Office Document Tools (docx, pptx, xlsx)               │
└─────────────────────────────────────────────────────────────┘
  1. Launch the application
  2. Go through the setup wizard:
    • Environment Check — validates Python and dependencies (bundled exe auto-detects; dev mode checks system Python)
    • WSL2 Setup — (Windows only) auto-detects and installs WSL2 for sandbox support
    • LLM Provider — configure API keys and default model
  3. Start chatting with the AI agent

Protocol Method Families

FamilyScopeMethods
turn/*Turnstart, interrupt, steer
thread/*Threadlist, get, rollback, fork, delete, compact/start, inject_items
fs/*FilesystemreadFile, writeFile, createDirectory, getMetadata, readDirectory, remove, copy, watch, unwatch
fuzzyFileSearch/*FilesystemsessionStart, sessionUpdate, sessionStop
command/execProcessexec, exec/write, exec/resize, exec/terminate
process/*Processspawn, writeStdin, resizePty, kill, list, get, snapshot
replay.*Debugturns, timeline, messages
config/*Sessionget, batchWrite
model/*Sessionlist, get
feature/*Sessionlist, set
permission/*SessionlistProfiles, getProfile
plugin/*Sessionlist, install, uninstall, enable, disable, configure
skills/*Sessionlist, get, create, upload, delete, setExtraRoots
mcp/*SessionlistServers, getServer, status
agent/*Sessionlist, get, spawn, kill
protocol/*Connectioncatalog, method_names, schema

Configuration

The application configuration file is located at ~/.miqi/config.json:

{
  "providers": {
    "openai": { "apiKey": "sk-..." },
    "anthropic": { "apiKey": "sk-ant-..." }
  },
  "agents": {
    "defaults": {
      "model": "claude-sonnet-4-6",
      "temperature": 0.1,
      "maxToolIterations": 100
    }
  },
  "tools": {
    "restrictToWorkspace": true
  }
}

Environment Variables

VariableDescription
MIQI_PYTHON_PATHCustom Python interpreter path
MIQI_AGENTS__DEFAULTS__MODELOverride default model

Development Guide

Project Structure

miqi-desktop/
├── miqi/                         # Python backend
│   ├── runtime/                  # Runtime engine (AppServer, Session, Turn, Thread, Replay, Agent, MCP, ...)
│   ├── agent/                    # Agent logic, tools, memory, trace, context compression, smart routing
│   ├── bridge/                   # Electron bridge service (IPC protocol)
│   ├── bus/                      # Internal message bus (async in/out queues)
│   ├── execution/                # Tool orchestrator, permissions, approval, hooks, sandbox policy
│   ├── providers/                # LLM provider implementations + resilience
│   ├── protocol/                 # Typed commands, events, permissions (runtime-frontend protocol)
│   ├── channels/                 # Chat channel adapters (Feishu, Slack, Discord, Telegram, ...)
│   ├── sandbox/                  # bwrap sandbox manager
│   ├── skills/                   # Built-in skills (cron, paper-research, feishu-report, ...)
│   ├── session/                  # Session management (Manager, SQLite store)
│   ├── config/                   # Configuration loader and schema
│   ├── cli/                      # CLI commands (agent, gateway, trace, config)
│   ├── cron/                     # Cron scheduler service
│   ├── context/                  # Context fragments, thread store
│   ├── heartbeat/                # Heartbeat service
│   ├── plan/                     # Plan tracker and tool
│   ├── documents/                # Office document tools (docx, pptx, xlsx)
│   ├── observability/            # OpenTelemetry integration
│   ├── server/                   # Server assets and configuration
│   ├── templates/                # Templates
│   ├── tui/                      # Terminal UI (Textual-based)
│   └── utils/                    # Utility functions
├── apps/
│   └── desktop/                  # Electron frontend
│       ├── src/main/             # Main process (BridgeManager, IPC handlers)
│       ├── src/renderer/         # Renderer (React pages and components)
│       └── src/preload/          # Preload scripts (contextBridge API)
├── tests/                        # Test suite (~150+ test files)
│   ├── runtime/                  # Runtime unit and integration tests (~70+ files)
│   ├── bridge/                   # Bridge protocol and audit tests (~20+ files)
│   ├── execution/                # Sandbox, permissions, orchestration tests
│   ├── providers/                # LLM provider tests
│   ├── protocol/                 # Protocol commands/events/permissions tests
│   └── agent/tools/              # Tool-level tests
├── docs/                         # Documentation (MkDocs)
├── plan/                         # Implementation plans (not in VCS deliverables)
└── scripts/                      # Build and utility scripts

Code Standards

  • Python: Ruff for linting (line-length 100)
  • TypeScript: ESLint for linting
  • Commit Messages: Conventional Commits format

Testing

# Python backend tests (~1800+ tests)
uv run pytest

# Skip sandbox/subprocess tests for quick feedback
uv run pytest -m "not sandbox and not subprocess"

# Frontend tests
cd apps/desktop
npm run test

E2E Tests

# Electron E2E (full desktop app + bridge + LLM)
cd apps/desktop
npm run build && npx playwright test --config=playwright.config.ts --project=electron
PlatformE2E CoverageNotes
Linux (Ubuntu CI)Full suite ✓bwrap sandbox + all specs
Windows (WSL CI)Full suite ✓WSL bwrap sandbox + all specs (needs MIQI_RUN_SANDBOX_E2E=1)
macOS (CI)Non-sandbox onlybwrap not available; sandbox specs excluded via --grep-invert

macOS known limitation: The "restart recall" E2E test (session-context-recall.spec.ts) is skipped only when process.env.CI && process.platform === 'darwin' (local macOS runs still exercise the test). After a full app restart on macOS ARM64 CI runners, session history (chat messages) fails to render in <main> even though the sidebar session title loads correctly and the bridge reports running / initialized. This is likely a bridge IPC timing issue or APFS/SQLite WAL checkpoint race on cold start — needs native debugging. The non-restart session-switch recall test still validates #490 behavior on macOS.


Documentation


License

MIT License


Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details. test