pi-mgrep
Unified search extension for Pi Coding Agent — semantic search + exact grep + web fallback in one file.
Quick Start
npm install -g @mixedbread/mgrep
mgrep login
mkdir -p ~/.pi/agent/extensions
cp .pi/extensions/mgrep.ts ~/.pi/agent/extensions/mgrep.ts
What it gives you
Three LLM-callable tools, automatically registered:
search — Local Intelligent Router
Auto-selects the right engine based on the query pattern:
registerTool (camelCase) | ripgrep | 0.02s |
calculate_total (snake_case) | ripgrep | 0.02s |
app.tsx (file extension) | ripgrep | 0.02s |
how to handle errors (NL) | mgrep | 3-8s |
search({ query: "registerTool" })
search({ query: "error handling logic", answer: true })
web_search — Internet Search
Semantic search the web via mgrep, with automatic DuckDuckGo fallback.
web_search({ query: "React 19 new features" })
web_search({ query: "React 19 new features", answer: true })
Fallback chain: mgrep web (primary) → DuckDuckGo HTML scraping (automatic on failure)
web_fetch — Page Reader
Fetch a URL, strip HTML, return clean text.
web_fetch({ url: "https://react.dev/blog/2024/12/05/react-19" })
Interactive Commands
/search <query> [path] | Local search with auto engine selection |
/web <query> | Web search with AI summary |
/fetch <url> | Fetch and display URL content |
Architecture
┌─ search (local) ──────────────────────────────────────────┐
│ Intelligent routing: │
│ code patterns → ripgrep (0.02s, offline) │
│ natural lang → mgrep (3-8s, semantic) │
│ Fallback: mgrep ↓ → ripgrep │
├─ web_search (internet) ───────────────────────────────────┤
│ Primary: mgrep web (semantic + reranking) │
│ Fallback: DuckDuckGo (HTML scraping, no API key needed) │
│ Isolation: points to /tmp/mgrep-empty (no local mixing) │
├─ web_fetch (page reader) ─────────────────────────────────┤
│ curl + Node.js HTML→text extraction │
│ No external dependencies │
└────────────────────────────────────────────────────────────┘
Requirements
- Pi Coding Agent ≥ 0.73.0
- mgrep CLI (
npm install -g @mixedbread/mgrep)
- mgrep login or
MXBAI_API_KEY env var (recommended for CI/CD)
- ripgrep (optional — local sematic search auto-upgrades to mgrep if unavailable)
Tokens
Adds ~400 tokens to system prompt (3 tool definitions). Negligible on 128K+ context windows.
File Structure
pi-mgrep/
├── .pi/
│ └── extensions/
│ └── mgrep.ts ← the extension (349 lines)
├── package.json
├── README.md
└── README_CN.md
Related
License
MIT