Skip to main content

Mango Pi Cli

Project description

Mangopi CLI

CI PyPI Python License
Stars Release Downloads Last commit

Mangopi CLI demo

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 (3-agent implement / verify / refine pipeline)
  • Smart provider routing with tiered models (high/medium/low)
  • Flash-ext thinking framework server (OpenAI-compatible proxy)
  • Multimodal support (image reading via view_image)
  • Web search via Bocha AI Search (web_search tool)
  • 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 — 3-agent pipeline (implement → verify → refine)
/g <goal> /goal <query> (deprecated) Use /loop instead

/loop runs up to 5 iterations; the pipeline short-circuits on the first VERIFY: PASS.


Loop Engineering

Loop Engineering replaces the legacy Goal Mode with a 3-agent collaborative pipeline:

Agent Role
Implementer Designs & writes code. Explicitly forbidden from running tests — "that's the Verifier's job."
Verifier Inspects changed files, determines the right test command, runs tests, judges PASS/FAIL at the architecture level.
Updater On failure, reads the Verifier's analysis and produces a refined prompt (50–200 words) for the next Implementer iteration; read/grep only, no code edits.

The pipeline runs up to 5 iterations, short-circuiting on the first VERIFY: PASS. Session files under .mangocli/loops/ are automatically cleaned up on exit.

Example:

/loop build a fastapi todo app with tests

The agent implements, a dedicated Verifier runs the actual tests, and if anything fails, the Updater refines the prompt for the next attempt — all autonomously.

Flash-ext Server

Flash-ext is a standalone OpenAI-compatible HTTP proxy that injects phase-aware structured thinking frameworks before each model call. Designed for IDEs and clients that cannot run the full Mangopi agent loop.

Start the server:

python mangopi_cli.py --flash-ext --debug
# Optional flags: --web-search --port 8080 --token my-token

Flash-ext:

  • Matches keywords + tool-call patterns to select thinking frameworks (debug/design/explain/optimize/implement/investigate/verify/reevaluate).
  • On complex tasks, calls its own LLM to analyze session state and provide tailored guidance.
  • Injects all context into the user message via XML tags — zero new system messages.
  • Supports optional web search augmentation.
  • Is cognitive-only: never touches file I/O or bash; only enhances reasoning before the request reaches upstream.

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 3-agent pipeline: implement → verify → refine (invoked via /loop)
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 sandboxwrite 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 3-agent pipeline (Implementer / Verifier / Updater) with persistent task sessions
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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mangopi_cli-0.1.33.tar.gz (87.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mangopi_cli-0.1.33-py3-none-any.whl (41.7 kB view details)

Uploaded Python 3

File details

Details for the file mangopi_cli-0.1.33.tar.gz.

File metadata

  • Download URL: mangopi_cli-0.1.33.tar.gz
  • Upload date:
  • Size: 87.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mangopi_cli-0.1.33.tar.gz
Algorithm Hash digest
SHA256 f427888419126c91c865ec1846e7116b069c2c63b75256b1628c47cf295a9810
MD5 a7d3b9575f0c0fa98a0f734189ede7ce
BLAKE2b-256 190552d4ef1346f5aeba1a7b5e30427e5869c7fc44bd88aa1e6058c3e89002f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for mangopi_cli-0.1.33.tar.gz:

Publisher: ci.yml on w4n9H/mangopi-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mangopi_cli-0.1.33-py3-none-any.whl.

File metadata

  • Download URL: mangopi_cli-0.1.33-py3-none-any.whl
  • Upload date:
  • Size: 41.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mangopi_cli-0.1.33-py3-none-any.whl
Algorithm Hash digest
SHA256 897c8fc85541c090519fa1a73709f7e5da3ae265c93129b3c404354618bf74e5
MD5 19382c3deee736d91668e4d9fb5649dc
BLAKE2b-256 ac57d580b00aaf538c578a3de237921e1d09dd2b149be88feab48068787eb6f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for mangopi_cli-0.1.33-py3-none-any.whl:

Publisher: ci.yml on w4n9H/mangopi-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page