mihomo-rs
English | 简体中文
Rust SDK and CLI for mihomo: version install/switch, config profiles, service lifecycle, proxy operations, and real-time connection/traffic monitoring.
What It Does
- Manage mihomo versions from GitHub releases (
stable,beta,nightlyor explicit tag likev1.19.17). - Manage local config profiles under
~/.config/mihomo-rs(or$MIHOMO_HOME). - Start/stop/restart mihomo with PID tracking.
- Query/switch proxies and run delay tests.
- Query/filter/close active connections.
- Stream logs, traffic, and connection snapshots via WebSocket APIs.
Install
Library usage:
[]
= "*"
Quick Start (CLI)
# 1) Install and select a kernel version
# 2) Start service (auto-creates default config when missing)
# 3) Proxy operations
# 4) Observability
Run mihomo-rs --help for full command list.
Quick Start (SDK)
use ;
async
Progressive Examples
Examples are organized as an incremental path:
01_bootstrap.rs- isolated home + manager bootstrap02_config_profiles.rs- save/list/switch config profiles03_version_inventory.rs- local version inventory/default lookup04_service_lifecycle_dry_run.rs- service manager dry-run checks05_proxy_queries.rs- proxy/group queries (online)06_connection_queries.rs- connection queries/filters (online)07_streaming.rs- logs/traffic streaming (online)08_complete_workflow.rs- full orchestration template
See examples/README.md for details.
CLI Command Map
- Version:
version install|update|use|list|list-remote|uninstall - Config:
config list|current|path|set|unset|use|show|delete - Service:
service start|stop|restart|status|logs|traffic|memory - Proxy:
proxy list|groups|switch|test|current - Connections:
connection list [--host ...] [--process ...],connection stats|stream,connection close [--id ...|--all|--host ...|--process ...] - Doctor:
doctor run|fix|list|explain
For proxies, list shows proxy nodes, groups shows selectable groups, and current shows each group's current selection.
Doctor
Use doctor to inspect config, version, service, and controller health in one place.
# Run the default check set
# Inspect only one category or check id
# Machine-readable output
# List and explain checks
The current default checks include:
- config parsing and config-directory resolution
- current profile and YAML validity
- default binary availability
- PID consistency and stale pid-file detection
- external-controller resolution
- controller API reachability when the service is running
doctor fix is intentionally conservative and only applies safe fixes:
- create a missing configs directory
- create the missing default/current config file
- repair or add
external-controllerwhen it can be derived safely - remove a stale or malformed
mihomo.pid
Exit codes:
0: doctor completed without failing checks1: doctor completed and found at least one failing check2: doctor itself failed unexpectedly
Data Directory
By default, data is stored under ~/.config/mihomo-rs/.
~/.config/mihomo-rs/
├── versions/ # Installed kernels
├── configs/ # Profile yaml files
├── config.toml # Default version/profile
└── mihomo.pid # PID record
Override with:
To keep only profile files in a cloud-synced folder while leaving binaries and runtime files local,
set a dedicated config directory in config.toml:
[]
= "~/Library/Mobile Documents/com~apple~CloudDocs/mihomo-rs/configs"
You can also override it temporarily with:
Or write it into config.toml via CLI:
Development
Security
See SECURITY.md.
Contributing
See CONTRIBUTING.md.
License
MIT. See LICENSE.