Notes for agents working in this repo.
Mihoro is a Rust CLI for managing Mihomo on Linux. It handles:
- Initializing and updating the Mihomo binary
- Managing remote configuration subscriptions (YAML configs)
- Bootstrapping config interactively via
mihoro init - Applying config overrides via TOML (local settings override remote YAML)
- Managing the per-user systemd service
- Managing optional web dashboard assets
- Exporting proxy environment variables for shells
- Self-upgrading to the latest GitHub release
# Build
cargo build
cargo build --release
# Run
cargo run -- [args]
# Check code
cargo check --all-targets
# Format
cargo fmt --all
cargo fmt --all -- --check # Verify formatting
# Lint
cargo clippy
# Run tests
cargo test
# Local installation
cargo install --path .From .github/workflows/ci.yml:
cargo fmt --all -- --check
cargo clippy
cargo check --all-targetssrc/
├── main.rs # CLI entry point, Clap parsing, command dispatch
├── init.rs # `mihoro init` flow: bootstrap config, prompt for subscription URL, stage reporting
├── mihoro.rs # Core Mihoro struct with init/update/apply/uninstall helpers
├── config.rs # Config (TOML) and MihomoConfig parsing with serde defaults
├── ui.rs # Dashboard source selection and UI asset installation
├── resolve_mihomo_bin.rs # Resolve/download mihomo release artifacts for supported architectures
├── utils.rs # File I/O, download, gzip extraction, base64 decoding
├── systemctl.rs # Fluent wrapper around systemctl commands
├── cmd.rs # Clap derive enums for CLI structure
├── proxy.rs # Shell-specific proxy env var generation
├── upgrade.rs # Self-upgrade functionality using self_update crate
└── cron.rs # Auto-update cron job management
-
Config override system: merges local TOML overrides with remote YAML configs
Config: Main TOML config at~/.config/mihoro.tomlMihomoConfig: Mihomo-specific settings using#[serde(default)]extensivelyMihomoYamlConfig: Parses remote YAML with#[serde(flatten)]to preserve unrecognized fields- Only mihomo_config fields are overridden; remote YAML fields pass through unchanged
-
Systemctl builder: method chaining for systemd commands
Systemctl::new().start("mihomo.service").execute()?
-
Init flow:
mihoro initis the main onboarding pathbootstrap_config()creates the default TOML config if missing- Interactive runs prompt for
remote_config_urland continue in the same command --yesis for non-interactive use and expects required fields to already be present- Stage reports make repeat runs safe and easier to follow
-
Mihoro: main struct holding config and derived paths
- All methods return
anyhow::Result<T>for consistent error handling - Uses Tokio async for downloads
- All methods return
-
Self-upgrade: updates from GitHub releases
upgrade::run_upgrade(): Downloads and replaces the current binaryupgrade::check_for_update(): Checks for new versions without installing- Uses
self_updatecrate with GitHub backend - Runs in
tokio::task::spawn_blockingto avoid async runtime conflicts - Release artifacts must be named
mihoro-<version>-<target>.tar.gz
mihoro initcreates~/.config/mihoro.tomlif it does not exist- Interactive init prompts for the remote subscription URL when
remote_config_urlis empty - Remote YAML config is downloaded from the subscription URL
- Local TOML overrides are merged into the final
config.yaml - The user systemd service is written, enabled, and started
- Config:
~/.config/mihoro.toml - Mihomo binary:
~/.local/bin/mihomo - Mihomo config:
~/.config/mihomo/config.yaml - Systemd service:
~/.config/systemd/user/mihomo.service
clap4.5: CLI argument parsing with derive macrostokio1.44: Async runtime (full features)serde+serde_yaml: Serialization/deserializationreqwest0.12: HTTP client with streaming supportanyhow: Error handlingcolored: Terminal colorsindicatif: Progress bars for downloadsself_update0.42: Self-upgrade functionality with GitHub releases backend
- Edition: Rust 2021
- Formatting:
rustfmt.toml(max line width 100, hard tabs) - Linting:
clippy.tomlsets thresholds for complexity/argument count - Unit tests live alongside the modules under
src/ cargo testcurrently discovers 32 unit tests
Proxy commands detect shell type (bash/zsh/fish) and generate appropriate export/unset commands for eval $(mihoro proxy export) usage.