Mangopi CLI
Single-file, zero-dependency AI coding assistant for the terminal.
Mangopi CLI is a local-first autonomous coding agent built with only the Python standard library.
No frameworks. No Electron. No Docker. No dependency hell.
Just one fast, hackable Python file.
Design Philosophy
Seeking a perfect balance between code size, complexity, and the functionality & effectiveness of the agent.
Mangopi CLI intentionally keeps the runtime extremely small.
Why?
- easier to audit
- easier to hack
- easier to fork
- easier to understand
- easier to run locally
The project avoids unnecessary abstractions, frameworks, and dependencies whenever possible.
Why Mangopi CLI?
| Mangopi CLI | Typical AI Agent Frameworks |
|---|---|
| Single-file runtime | Large multi-module codebases |
| Python standard library only | Heavy dependency trees |
| Instant startup | Slow boot time |
| Fully hackable | Framework-heavy |
| Local-first | Cloud-oriented |
| Minimal abstractions | Over-engineered |
| Easy to fork | Hard to customize |
Ideal For
- developers who prefer terminal workflows
- users who dislike heavyweight AI frameworks
- hackers and tinkerers
- local-first enthusiasts
- people who want full runtime control
- building custom coding agents
Features
- Single-file architecture
- Python standard library only
- Instant startup speed
- Local-first workflow design
- Autonomous loop execution (multi-agent implement / verify / refine pipeline)
- Sparse loop — MailBox collective memory for cross-session task persistence (
--sparse) - Smart provider routing with tiered models (high/medium/low)
- Multimodal support (image reading via
view_image) - Web search via Bocha AI Search (
web_searchtool) - Context-aware conversation management
- Automatic context compacting
- OpenAI-compatible API support
- Built-in file and shell tools
- Persistent local sessions
- Skill system support (
SKILL.md) - Safe shell execution checks
- Fully hackable and easy to extend
- Large-context optimized runtime
Installation
From PyPI
pip install mangopi-cli
Start Mangopi CLI:
mangopi-cli
From Source
git clone git@github.com:w4n9H/mangopi-cli.git
cd mangopi-cli
python mangopi_cli.py
Configuration
Required:
export MANGO_KEY="your_api_key"
Recommended:
export MANGO_API_URL="https://api.deepseek.com"
export MANGO_MODEL="deepseek-v4-flash"
Optional:
export MANGO_MAX_CONTEXT=1000000 # default 1,000,000 tokens
export MANGO_LANG=en # en (default) | zh — controls UI text and CLI help language
Smart Provider Routing
Enable multi-model routing with the MANGO_ROUTING env var:
export MANGO_ROUTING=on
Define providers in .mangocli/providers.json (tiers: low/medium/high):
{
"providers": [
{"name": "low", "url": "https://api.deepseek.com", "model": "deepseek-v4-flash", "tier": "low", "api_key": "sk-xxx"},
{"name": "medium", "url": "https://api.deepseek.com", "model": "deepseek-v4", "tier": "medium", "api_key": "sk-xxx"},
{"name": "high", "url": "https://api.deepseek.com", "model": "deepseek-v4-reasoning", "tier": "high", "api_key": "sk-xxx"}
],
"routing": {
"default_tier": "medium",
"score_thresholds": {"low_max": 3, "medium_max": 7}
}
}
Mangopi CLI auto-selects the appropriate tier based on task complexity — keyword matching + LLM scoring. Each turn uses one model; no mid-loop switching. A sample config is at providers.json.example.
Supported Providers
Mangopi CLI supports:
- DeepSeek
- OpenAI-compatible APIs
- MiniMax
- Custom compatible endpoints
Example:
export MANGO_API_URL="https://api.openai.com/v1"
export MANGO_MODEL="gpt-4o-mini"
Usage
Start the CLI:
mangopi-cli
or:
python mangopi_cli.py
Built-in Commands
| Command | Aliases | Description |
|---|---|---|
/q |
/quit |
Quit |
/n |
/new |
Start a new session (old session is auto-backed-up) |
/c |
/compact |
Manually trigger full conversation compact |
/h |
/help |
Show built-in command help |
/l <goal> |
/loop <query> |
Start Loop Engineering — configurable pipeline with optional modes |
/loop runs up to 5 iterations; the pipeline short-circuits on the first VERIFY: PASS.
| Flag | Description |
|---|---|
--fast |
Skip design/review, only dev → test → push |
--only-dev |
Dev only: no test/review, dev → push/succeed |
--wish |
Prepend research (web_search) before the pipeline |
--dry-run |
Print pipeline topology and exit |
--push |
Commit verified changes on PASS |
--task-id <id> |
Assign a persistent task ID (for resume) |
--sparse HANDLE |
Enable MailBox collective memory (e.g. --sparse @agent-a) |
--output jsonl |
Emit structured events for web UI |
Loop Engineering
Loop Engineering replaces the legacy Goal Mode with a configurable Step/Pipeline:
| Agent | Role |
|---|---|
| ResearchAgent | Optional (--wish). Gathers information via web_search; independent ctx. |
| DesignAgent | Reads code, plans the design; shares impl_ctx with DevAgent. |
| DevAgent | Implements progressively, extracts changed files for downstream agents. |
| ReviewAgent | Inspects git diff, returns VERIFY: PASS/FAIL; independent ctx. |
| TestAgent | Runs tests, judges PASS/FAIL; independent ctx. |
| UpdaterAgent | On failure, refines the prompt for the next iteration; read/grep only. |
Modes:
| Mode | Pipeline | Command |
|---|---|---|
| Normal | DesignAgent → DevAgent → ReviewAgent → TestAgent → SucceedStep / UpdaterAgent |
/loop <goal> |
| Fast | DevAgent → TestAgent → PushAgent / UpdaterAgent |
/loop <goal> --fast |
| Wish | ResearchAgent → DesignAgent → DevAgent → ReviewAgent → TestAgent → … |
/loop <goal> --wish |
The pipeline runs up to 5 iterations, short-circuiting on the first VERIFY: PASS. All agents return structured results via attempt_completion.
Sparse Loop (MailBox Collective Memory)
The --sparse HANDLE flag extends loop with cross-session collective memory via the MailBox system:
# Start a task with sparse mode
/loop data cleaning pipeline --sparse @agent-a --task-id clean-v1
# Resume the same task hours or days later — agents inherit full history
/loop continue cleaning --sparse @agent-a --task-id clean-v1
When --sparse is set:
- Each task gets a MailBox group (
gid = task-id) - All pipeline agents (DesignAgent, DevAgent, ReviewAgent, TestAgent) share the same group as persistent thread
- Agents are prompted to:
- Start →
mailbox_readprevious progress before acting - Claim →
mailbox_postwhat they're about to do - Update →
mailbox_postat key milestones ([State], decisions, blockers) - Finish →
mailbox_post [Result]to mark completion for the next agent
- Start →
- Same
--task-idacross separate CLI invocations → agents automatically see the full history
This turns loop from a stateless pipeline into a collaborative engine where agents and humans coordinate asynchronously across time.
Built-in Tools
| Tool | Description |
|---|---|
read |
Read a file or image (png/jpg/gif/webp auto-routed to vision) |
write |
Write or overwrite a file |
edit |
Replace an exact string in a file, with unified-diff preview |
search |
Search files using glob patterns, sorted by mtime |
grep |
Recursive regex content search |
bash |
Execute a shell command (60s timeout, output filtered) |
view_image |
Load a local image into the model's vision context |
web_search |
Search the live web via Bocha AI Search API |
use_skill |
Load an installed SKILL.md with its scripts/references |
loop_engine |
Pipeline: design → dev → review → test (invoked via /loop) |
mailbox_post |
Post a message or [State]/[Result] to a MailBox group |
mailbox_read |
Read thread history and member info from a MailBox group |
mailbox_check |
Check all groups for unread messages |
attempt_completion |
Final step — present the result to the user |
Mangopi CLI can autonomously inspect files, modify code, search projects, and execute shell commands.
Skill System
Mangopi CLI supports reusable workflow skills.
Example structure:
~/.mangocli/skills/python_backend/
├── SKILL.md
├── scripts/
└── references/
Example SKILL.md:
---
description: Python backend workflow
tags: ["python", "backend"]
---
Use pytest for tests.
Prefer small functions.
The model can automatically discover and load relevant skills during execution.
Session Persistence
Sessions are stored locally:
.mangocli/session/session.json
Mangopi CLI automatically:
- restores previous sessions
- preserves important context
- compacts old conversations
- manages long-running workflows
Context Compacting
Mangopi CLI uses a three-tier compacting strategy that triggers automatically once context exceeds 80% of MANGO_MAX_CONTEXT:
| Tier | Strategy | Scope |
|---|---|---|
micro_compact |
Head/tail truncation | Individual tool outputs and long assistant messages |
session_memory_compact |
Force-compact old turns | Drops the oldest turns, keeps last 10 turns in full |
compact_conversation |
Drop-while-overflow | Strips oldest turns first, then trims recent turns |
full_compact |
LLM-driven summary | Replaces the whole conversation with a structured recap (manual /c) |
The compact pipeline is invoked by ContextManager.prepare_for_api() before every model call, so long-running autonomous workflows stay within the configured context budget without manual intervention.
Safety
Mangopi CLI enforces safety at two layers:
Dangerous command detection — the following patterns require explicit y/n confirmation before execution:
- File deletion —
rm -rf,unlink - Disk / partition —
mkfs,fdisk,parted,dd if=... of=... - Permission changes —
chmod 777(and similar*7*7*modes),chown ... root - Privilege escalation —
sudo rm,su -,su root - Dangerous process control —
kill -9 1,killall -9,pkill -9 - Environment tampering —
export PATH=...,unset PATH, writes to/etc/ - History / log clearing —
history -c,> /dev/null 2>&1
Path sandbox — write and edit resolve the target path with realpath and reject any file outside the project root. Operating on a directory path (rather than a file) is also rejected. This prevents the model from escaping the working directory.
Architecture
Core components:
| Component | Responsibility |
|---|---|
Printer |
Terminal UI rendering (spinner, diff, tool call/result) |
ContextManager |
Conversation memory, three-tier compact, session save/restore |
ToolBase |
Tool framework (schema, confirm, before/after hooks, preview) |
Provider |
API abstraction (OpenAIProvider, DeepSeekProvider, MiniMaxProvider) |
SystemPrompt |
Layered runtime prompt assembly (base, safety, rules, tools, env) |
SkillManager |
Discovers and loads SKILL.md + scripts/references |
loop_engine |
Multi-agent Step/Pipeline (Design → Dev → Review → Test → …) with persistent task sessions |
MailBox |
File-based async messaging system for agent/agent & agent/human collaboration |
agent_loop |
Drives the read → think → tool-call → verify loop until the model stops or calls attempt_completion |
License
Apache License 2.0
✨ Contributors
| Contributor | Role |
|---|---|
| @BeWater799 | 💡 Inspiration for the Loop Engineering user prompt constraints |
Author
Created by moofs.
Release files for mangopi-cli 0.1.42
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mangopi_cli-0.1.42.tar.gz | 91.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mangopi_cli-0.1.42-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 134.5 kB
Release files / mangopi_cli-0.1.42.tar.gz
| Download URL | mangopi_cli-0.1.42.tar.gz |
|---|---|
| Size | 91.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bb80aed270e2546aa800008133295e3f08b62dce2882dff4a98ebd4145b42a42
|
|
BLAKE2b-256 checksum How to use checksums |
cb8ea3c5b811699e1298e42a76f48a40eda04f2d0be618500784ba329b7ee875
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.
Transparency logRelease files / mangopi_cli-0.1.42-py3-none-any.whl
| Download URL | mangopi_cli-0.1.42-py3-none-any.whl |
|---|---|
| Size | 43.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
262a348e8d148cb4ec578666b4c642e3e117792b93be464e05507da65f0c92a3
|
|
BLAKE2b-256 checksum How to use checksums |
3578889fc935ba8fd426d024cb53298b8e93c3984ba0b7706d30de19978958c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.
Transparency log