mihomo-cli 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ venv/
5
+ build/
6
+ dist/
7
+ *.egg-info/
8
+ .pytest_cache/
9
+ .ruff_cache/
10
+ .coverage
11
+ htmlcov/
12
+ .DS_Store
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 - 2026-10-21
4
+
5
+ - First release: Linux (Ubuntu 20.04 / 22.04 / 24.04) command-line client built on the mihomo core.
6
+ - Interactive menu and direct commands; proxy services (subscription / local file / manual nodes),
7
+ node switching, latency test and `node auto`, global / rule / direct modes, CN-sites switch.
8
+ - systemd service installed with a single sudo; TUN mode with systemd-resolved DNS takeover.
9
+ - Automatic backup before every change with rollback on failure; `backup restore`.
10
+ - `doctor` with 15 checks and `--fix`; `--json` output; English / Chinese help; shell completion.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 jakoes-wu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,115 @@
1
+ Metadata-Version: 2.5
2
+ Name: mihomo-cli
3
+ Version: 0.1.0
4
+ Summary: A command-line Clash-style client for Linux servers, powered by the mihomo kernel
5
+ Project-URL: Homepage, https://github.com/jakoes-wu/mihomo-cli
6
+ Project-URL: Issues, https://github.com/jakoes-wu/mihomo-cli/issues
7
+ Author: jakoes-wu
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: clash,cli,mihomo,proxy,tun
11
+ Classifier: Environment :: Console
12
+ Classifier: Operating System :: POSIX :: Linux
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.8
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Internet :: Proxy Servers
21
+ Requires-Python: >=3.8
22
+ Requires-Dist: click>=8.0
23
+ Requires-Dist: httpx>=0.24
24
+ Requires-Dist: pyyaml>=5.4
25
+ Requires-Dist: questionary>=1.10
26
+ Requires-Dist: rich>=12.0
27
+ Provides-Extra: test
28
+ Requires-Dist: pytest>=7; extra == 'test'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # mihomo-cli
32
+
33
+ English | [简体中文](README.zh-CN.md)
34
+
35
+ A command-line, Clash-style proxy client for Linux machines without a desktop, powered by the
36
+ [mihomo](https://github.com/MetaCubeX/mihomo) core. Use it through an interactive menu or plain commands.
37
+
38
+ - Proxy services: an airport subscription, a local Clash/mihomo file, or hand-added node links (e.g. your own VPS)
39
+ - Switch nodes without restarting; latency test and automatic fastest-node pick
40
+ - Global / rule / direct modes, plus a switch for whether domestic (CN) sites go direct
41
+ - Background systemd service, installed with a single `sudo`; no root needed day to day
42
+ - Optional TUN mode for the whole machine, including programs that ignore proxy settings
43
+ - Every change is validated, backed up, and rolled back automatically if it fails
44
+ - `doctor` self-check with fixes, `--json` output, English / Chinese interface, shell completion
45
+
46
+ Supported: Linux (tested on Ubuntu 20.04 / 22.04 / 24.04), Python 3.8+. macOS and Windows are not supported yet.
47
+
48
+ ## Install
49
+
50
+ ```bash
51
+ pipx install mihomo-cli
52
+ mihomo-cli install # downloads the mihomo core and geo data, installs the service (asks for sudo once)
53
+ ```
54
+
55
+ If GitHub is slow to reach, pass a mirror that proxies `https://github.com`:
56
+
57
+ ```bash
58
+ mihomo-cli install --mirror https://your-mirror.example/https://github.com
59
+ ```
60
+
61
+ ## Quick start
62
+
63
+ ```bash
64
+ mihomo-cli profile add airport --url 'https://example.com/sub?token=...'
65
+ # or a single self-hosted node
66
+ mihomo-cli profile add vps --node 'vless://...#my-vps'
67
+
68
+ mihomo-cli node auto # pick the fastest node
69
+ mihomo-cli status # one-screen overview including exit IP
70
+ eval "$(mihomo-cli proxy-env on)" # proxy the current shell (127.0.0.1:7897)
71
+ ```
72
+
73
+ Run `mihomo-cli` with no arguments to open the menu. `mihomo-cli help <command>` shows help and examples.
74
+
75
+ ## Commands
76
+
77
+ | Command | What it does |
78
+ | ---- | ---- |
79
+ | `status` | Service, core, proxy service, node, mode, CN switch, TUN, port, exit IP |
80
+ | `install` / `uninstall` | Install or remove the core and the systemd service |
81
+ | `core upgrade` | Replace the core; the old one is kept if verification fails |
82
+ | `service start/stop/restart/status/logs` | Control the background service |
83
+ | `profile list/show/add/rm/use/update/rename` | Manage proxy services |
84
+ | `node list/use/add/rm/restore/test/auto` | Manage nodes of the active proxy service |
85
+ | `mode [global/rule/direct]` | Show or set the mode |
86
+ | `cn [direct/proxy]` | Domestic sites direct or via proxy (rule mode) |
87
+ | `tun on/off/status` | Whole-machine TUN mode (on/off need sudo) |
88
+ | `proxy-env [on/off]` | Print shell statements for proxy variables |
89
+ | `conns` / `logs` | Active connections and core logs |
90
+ | `backup list/restore` | Automatic backups (latest 10) |
91
+ | `doctor [--fix]` | 15 checks with fix hints |
92
+ | `completion bash/zsh [--install]` | Shell completion and the `mproxy on/off` helper |
93
+
94
+ Global options: `--json`, `--lang zh|en`, `--home DIR` (or `MIHOMO_CLI_HOME`), `--version`.
95
+
96
+ Exit codes: 0 ok, 1 error, 2 usage, 3 core unreachable, 4 invalid config or rolled back, 5 needs sudo
97
+ or run as root, 6 unsupported platform, 7 rollback incomplete (manual action needed).
98
+
99
+ ## Files
100
+
101
+ Everything lives in `~/.local/share/mihomo-cli` (mode 0700): `state.yaml` (what you asked for — the
102
+ source of truth), the generated `config.yaml`, the core in `bin/`, `backups/`, and `mihomo-cli.log`.
103
+ The service unit is `/etc/systemd/system/mihomo-cli.service`.
104
+
105
+ ## Notes
106
+
107
+ - The mihomo core (GPL-3.0) is not bundled; it is downloaded from the official releases and checked
108
+ against the published SHA-256 digest when available.
109
+ - mihomo-cli runs as its own instance and does not touch other mihomo / Clash services. Only one TUN can
110
+ be active on a machine; `tun on` refuses if another one is running.
111
+ - Do not run mihomo-cli with `sudo`; it calls sudo itself for the few steps that need it.
112
+
113
+ ## License
114
+
115
+ MIT
@@ -0,0 +1,85 @@
1
+ # mihomo-cli
2
+
3
+ English | [简体中文](README.zh-CN.md)
4
+
5
+ A command-line, Clash-style proxy client for Linux machines without a desktop, powered by the
6
+ [mihomo](https://github.com/MetaCubeX/mihomo) core. Use it through an interactive menu or plain commands.
7
+
8
+ - Proxy services: an airport subscription, a local Clash/mihomo file, or hand-added node links (e.g. your own VPS)
9
+ - Switch nodes without restarting; latency test and automatic fastest-node pick
10
+ - Global / rule / direct modes, plus a switch for whether domestic (CN) sites go direct
11
+ - Background systemd service, installed with a single `sudo`; no root needed day to day
12
+ - Optional TUN mode for the whole machine, including programs that ignore proxy settings
13
+ - Every change is validated, backed up, and rolled back automatically if it fails
14
+ - `doctor` self-check with fixes, `--json` output, English / Chinese interface, shell completion
15
+
16
+ Supported: Linux (tested on Ubuntu 20.04 / 22.04 / 24.04), Python 3.8+. macOS and Windows are not supported yet.
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ pipx install mihomo-cli
22
+ mihomo-cli install # downloads the mihomo core and geo data, installs the service (asks for sudo once)
23
+ ```
24
+
25
+ If GitHub is slow to reach, pass a mirror that proxies `https://github.com`:
26
+
27
+ ```bash
28
+ mihomo-cli install --mirror https://your-mirror.example/https://github.com
29
+ ```
30
+
31
+ ## Quick start
32
+
33
+ ```bash
34
+ mihomo-cli profile add airport --url 'https://example.com/sub?token=...'
35
+ # or a single self-hosted node
36
+ mihomo-cli profile add vps --node 'vless://...#my-vps'
37
+
38
+ mihomo-cli node auto # pick the fastest node
39
+ mihomo-cli status # one-screen overview including exit IP
40
+ eval "$(mihomo-cli proxy-env on)" # proxy the current shell (127.0.0.1:7897)
41
+ ```
42
+
43
+ Run `mihomo-cli` with no arguments to open the menu. `mihomo-cli help <command>` shows help and examples.
44
+
45
+ ## Commands
46
+
47
+ | Command | What it does |
48
+ | ---- | ---- |
49
+ | `status` | Service, core, proxy service, node, mode, CN switch, TUN, port, exit IP |
50
+ | `install` / `uninstall` | Install or remove the core and the systemd service |
51
+ | `core upgrade` | Replace the core; the old one is kept if verification fails |
52
+ | `service start/stop/restart/status/logs` | Control the background service |
53
+ | `profile list/show/add/rm/use/update/rename` | Manage proxy services |
54
+ | `node list/use/add/rm/restore/test/auto` | Manage nodes of the active proxy service |
55
+ | `mode [global/rule/direct]` | Show or set the mode |
56
+ | `cn [direct/proxy]` | Domestic sites direct or via proxy (rule mode) |
57
+ | `tun on/off/status` | Whole-machine TUN mode (on/off need sudo) |
58
+ | `proxy-env [on/off]` | Print shell statements for proxy variables |
59
+ | `conns` / `logs` | Active connections and core logs |
60
+ | `backup list/restore` | Automatic backups (latest 10) |
61
+ | `doctor [--fix]` | 15 checks with fix hints |
62
+ | `completion bash/zsh [--install]` | Shell completion and the `mproxy on/off` helper |
63
+
64
+ Global options: `--json`, `--lang zh|en`, `--home DIR` (or `MIHOMO_CLI_HOME`), `--version`.
65
+
66
+ Exit codes: 0 ok, 1 error, 2 usage, 3 core unreachable, 4 invalid config or rolled back, 5 needs sudo
67
+ or run as root, 6 unsupported platform, 7 rollback incomplete (manual action needed).
68
+
69
+ ## Files
70
+
71
+ Everything lives in `~/.local/share/mihomo-cli` (mode 0700): `state.yaml` (what you asked for — the
72
+ source of truth), the generated `config.yaml`, the core in `bin/`, `backups/`, and `mihomo-cli.log`.
73
+ The service unit is `/etc/systemd/system/mihomo-cli.service`.
74
+
75
+ ## Notes
76
+
77
+ - The mihomo core (GPL-3.0) is not bundled; it is downloaded from the official releases and checked
78
+ against the published SHA-256 digest when available.
79
+ - mihomo-cli runs as its own instance and does not touch other mihomo / Clash services. Only one TUN can
80
+ be active on a machine; `tun on` refuses if another one is running.
81
+ - Do not run mihomo-cli with `sudo`; it calls sudo itself for the few steps that need it.
82
+
83
+ ## License
84
+
85
+ MIT
@@ -0,0 +1,84 @@
1
+ # mihomo-cli
2
+
3
+ [English](README.md) | 简体中文
4
+
5
+ 给没有桌面环境的 Linux 机器用的命令行版简易 Clash,以 [mihomo](https://github.com/MetaCubeX/mihomo) 为内核。
6
+ 既可以用交互菜单,也可以直接敲命令。
7
+
8
+ - 代理服务:机场订阅、本地 Clash / mihomo 配置文件,或手工添加的节点链接(比如自建 VPS)
9
+ - 切换节点不重启、不断网;测延迟,一键选最快节点
10
+ - 全局 / 规则 / 直连三种模式,另有“国内网站走不走代理”开关
11
+ - 后台 systemd 服务,安装时输一次 sudo 密码,日常不需要 root
12
+ - 可选 TUN 模式:整台机器(包括不认代理设置的程序)都走代理
13
+ - 每次改配置都先校验、先备份,失败自动恢复原状
14
+ - `doctor` 自检并可自动修复,`--json` 输出,中英文界面,shell 补全
15
+
16
+ 支持:Linux(在 Ubuntu 20.04 / 22.04 / 24.04 上测试),Python 3.8 及以上。暂不支持 macOS 和 Windows。
17
+
18
+ ## 安装
19
+
20
+ ```bash
21
+ pipx install mihomo-cli
22
+ mihomo-cli install # 下载 mihomo 内核与地区数据库,安装后台服务(输一次 sudo 密码)
23
+ ```
24
+
25
+ 访问 GitHub 慢时,可以指定一个代理 `https://github.com` 的镜像:
26
+
27
+ ```bash
28
+ mihomo-cli install --mirror https://your-mirror.example/https://github.com
29
+ ```
30
+
31
+ ## 快速上手
32
+
33
+ ```bash
34
+ mihomo-cli profile add airport --url 'https://example.com/sub?token=...'
35
+ # 或者只加一台自建节点
36
+ mihomo-cli profile add vps --node 'vless://...#my-vps'
37
+
38
+ mihomo-cli node auto # 选最快的节点
39
+ mihomo-cli status # 一屏概览,含出口 IP
40
+ eval "$(mihomo-cli proxy-env on)" # 当前终端走代理(127.0.0.1:7897)
41
+ ```
42
+
43
+ 不带参数运行 `mihomo-cli` 进入菜单。`mihomo-cli help <命令>` 查看说明和示例。
44
+
45
+ ## 命令一览
46
+
47
+ | 命令 | 作用 |
48
+ | ---- | ---- |
49
+ | `status` | 后台服务、内核、代理服务、节点、模式、国内开关、TUN、端口、出口 IP |
50
+ | `install` / `uninstall` | 安装或删除内核与后台服务 |
51
+ | `core upgrade` | 更换内核;校验不通过时原内核不变 |
52
+ | `service start/stop/restart/status/logs` | 控制后台服务 |
53
+ | `profile list/show/add/rm/use/update/rename` | 管理代理服务 |
54
+ | `node list/use/add/rm/restore/test/auto` | 管理当前代理服务的节点 |
55
+ | `mode [global/rule/direct]` | 查看或切换模式 |
56
+ | `cn [direct/proxy]` | 规则模式下国内网站直连或走代理 |
57
+ | `tun on/off/status` | 整机 TUN 模式(开 / 关需要 sudo) |
58
+ | `proxy-env [on/off]` | 输出终端代理环境变量语句 |
59
+ | `conns` / `logs` | 当前连接与内核日志 |
60
+ | `backup list/restore` | 自动备份(保留最近 10 份) |
61
+ | `doctor [--fix]` | 15 项自检与修复建议 |
62
+ | `completion bash/zsh [--install]` | shell 补全与 `mproxy on/off` 函数 |
63
+
64
+ 全局选项:`--json`、`--lang zh|en`、`--home 目录`(或环境变量 `MIHOMO_CLI_HOME`)、`--version`。
65
+
66
+ 退出码:0 成功,1 一般错误,2 用法错误,3 内核不可达,4 配置校验失败或已回滚,5 需要 sudo 或被以 root 运行,
67
+ 6 平台不支持,7 回滚未完成、需要手动处理。
68
+
69
+ ## 文件位置
70
+
71
+ 全部放在 `~/.local/share/mihomo-cli`(权限 0700):`state.yaml`(记录你想要的状态,是权威来源)、
72
+ 生成的 `config.yaml`、`bin/` 里的内核、`backups/` 和 `mihomo-cli.log`。服务单元是
73
+ `/etc/systemd/system/mihomo-cli.service`。
74
+
75
+ ## 说明
76
+
77
+ - mihomo 内核(GPL-3.0)不随包分发,从官方发布页下载,能拿到官方 SHA-256 时会核对。
78
+ - mihomo-cli 是独立实例,不改动机器上其它 mihomo / Clash 服务。同一台机器只能开一个 TUN,
79
+ 已有其它 TUN 时 `tun on` 会拒绝。
80
+ - 不要用 `sudo` 运行 mihomo-cli;需要权限的几步它会自己调用 sudo。
81
+
82
+ ## 许可证
83
+
84
+ MIT
@@ -0,0 +1,68 @@
1
+ [build-system]
2
+ requires = ["hatchling", "hatch-vcs"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "mihomo-cli"
7
+ dynamic = ["version"]
8
+ description = "A command-line Clash-style client for Linux servers, powered by the mihomo kernel"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.8"
13
+ authors = [{ name = "jakoes-wu" }]
14
+ keywords = ["mihomo", "clash", "proxy", "cli", "tun"]
15
+ classifiers = [
16
+ "Environment :: Console",
17
+ "Operating System :: POSIX :: Linux",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.8",
20
+ "Programming Language :: Python :: 3.9",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: 3.13",
25
+ "Topic :: Internet :: Proxy Servers",
26
+ ]
27
+ # 只写下限:pip 按各版本的 requires_python 自动挑出 Python 3.8 还能装的最后版本(方案 §3)。
28
+ dependencies = [
29
+ "click>=8.0",
30
+ "rich>=12.0",
31
+ "questionary>=1.10",
32
+ "httpx>=0.24",
33
+ "PyYAML>=5.4",
34
+ ]
35
+
36
+ [project.optional-dependencies]
37
+ test = ["pytest>=7"]
38
+
39
+ [project.scripts]
40
+ mihomo-cli = "mihomo_cli.cli:main"
41
+
42
+ [project.urls]
43
+ Homepage = "https://github.com/jakoes-wu/mihomo-cli"
44
+ Issues = "https://github.com/jakoes-wu/mihomo-cli/issues"
45
+
46
+ [tool.hatch.version]
47
+ source = "vcs"
48
+
49
+ [tool.hatch.version.raw-options]
50
+ # 仓库还没有任何标签时(本地开发 / 首次构建)给一个可识别的占位版本。
51
+ fallback_version = "0.0.0"
52
+
53
+ [tool.hatch.build.targets.wheel]
54
+ packages = ["src/mihomo_cli"]
55
+
56
+ [tool.hatch.build.targets.sdist]
57
+ include = ["src/", "tests/", "README.md", "README.zh-CN.md", "LICENSE", "CHANGELOG.md"]
58
+
59
+ [tool.pytest.ini_options]
60
+ testpaths = ["tests"]
61
+
62
+ [tool.ruff]
63
+ line-length = 110
64
+ target-version = "py38"
65
+
66
+ [tool.ruff.lint]
67
+ select = ["E", "F", "W", "B", "UP"]
68
+ ignore = ["UP006", "UP007", "UP035", "UP031", "UP037", "UP045", "E501"]
@@ -0,0 +1,13 @@
1
+ """mihomo-cli:以 mihomo 为内核的命令行代理客户端。"""
2
+
3
+ try:
4
+ from importlib.metadata import PackageNotFoundError, version as _pkg_version
5
+ except ImportError: # pragma: no cover - Python 3.8 起标准库自带 importlib.metadata
6
+ _pkg_version = None
7
+ PackageNotFoundError = Exception
8
+
9
+ try:
10
+ # 版本号由 hatch-vcs 从 git 标签写进包元数据,代码里不写死(方案 5.1.11)。
11
+ __version__ = _pkg_version("mihomo-cli") if _pkg_version else "0.0.0"
12
+ except PackageNotFoundError:
13
+ __version__ = "0.0.0"
@@ -0,0 +1,6 @@
1
+ # 供 `<python> -m mihomo_cli` 使用:sudo 自调用与 systemd 单元都走这条路径,
2
+ # 不依赖 ~/.local/bin 是否在 sudo 的 secure_path 里(方案 5.1.7「sudo 的使用方式」)。
3
+ from mihomo_cli.cli import main
4
+
5
+ if __name__ == "__main__":
6
+ main()