A tiny code-editing agent in Rust — a minimal, hackable CLI that talks to OpenAI and can read, list, and edit files in your working directory.
This repository is for educational purposes, to demonstrate the core elements of a minimal CLI coding agent, adapted from How to Build an Agent by Amp.
- Chat-based CLI that calls OpenAI and uses tool calls
- File tools:
read_file,list_files,edit_file(single, unique replacement or create new file) - Prefers reading files over guessing; makes the smallest edit that satisfies a request
- Minimal dependencies and simple code you can tweak
Note
No bash tool is included because it can be risky and this project is intended for educational use.
You can add it yourself if needed.
- Rust toolchain (
cargo,rustc) - An OpenAI API key
export OPENAI_API_KEY=sk-...
mbx runOr put OPENAI_API_KEY=sk-... in a .env file in the directory where you run the binary.
If OPENAI_API_KEY is missing, the CLI prints setup instructions and exits.
Developer compile/test/clippy commands use
mr boxington (mbx); keep cargo fmt /
cargo install as plain cargo.
src/main.rs: Entry point; checksOPENAI_API_KEY, starts the agentsrc/agent.rs: Chat loop, tool routing, and message statesrc/tools.rs: Three built-in tools implemented with Rust filesystem APIssrc/env.rs: Loads.envfrom the current working directory
The agent exposes three file tools:
read_file(path: string): Reads and returns the text contents of a file at a relative path.list_files(path?: string | null): Lists files and directories at the given path (or current directory).edit_file(path: string, old_str: string, new_str: string): Replaces exactly one occurrence ofold_strwithnew_strin the given file.
Conventions:
- All paths are relative to your current working directory.
- The agent prefers reading over guessing and aims to make the smallest possible change.
cargo fmt
mbx test
mbx clippy --all-targets --all-features -- -D warningsInstall the repository hooks:
./scripts/setup-hooks.shThis enables a pre-commit hook that runs:
cargo fmt --all -- --checkmbx clippy --workspace --all-targets --all-features -- -D warningsmbx test --all-targets
Adapted from How to Build an Agent by Amp.
This project is licensed under the PolyForm Shield License 1.0.0 — see LICENSE for details.