mihomo-cli 4.14.0 → 26.9.37
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.
- package/CHANGELOG.md +25 -0
- package/README.md +8 -2
- package/dist/index.js +278 -58
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [26.9.37] - 2026-09-29
|
|
4
|
+
|
|
5
|
+
自本版起版本号改为「年.月.序号」(序号连续递增、永不重置,跨月不归一)。
|
|
6
|
+
|
|
7
|
+
### 新增
|
|
8
|
+
|
|
9
|
+
- `mihomo kernel --proxy <端口|地址>`:显式指定出网代理,纯端口视为 `127.0.0.1:<端口>`,支持 `host:port` 与 `http(s)/socks5(h)` 地址;版本查询与下载共用,可与 `--mirror` 组合(镜像决定下载地址、代理只做传输),与 `--mirror direct` 互斥。mihomo 自己没在跑、但本机有别的代理工具时不再只能干等直连。
|
|
10
|
+
- 内核版本查询在**无代理可用**时走 gh 认证通道(`gh api`,配额 5000 次/时 vs 未认证直连 60 次/时):此前本机明明装着已登录的 gh,版本查询仍走无认证 API,共享出口 IP 撞 403 限流时 gh 通道形同虚设;代理可用时直接经代理(在跑的代理就是已定的出网路径,先试 gh 直连只会把被墙的等待叠在前面),gh 失败自动回退直连,镜像仍绝不作用于 API。
|
|
11
|
+
- start(mixed)成功后的系统代理提醒按实际状态分档:用 `scutil --proxy` 检测当前生效网络集,已指向 Mixed 端口只一句确认(仍有条目指向别处时升级提醒),指向别处或未设置才给出可粘贴的 `networksetup` 命令(HTTP/HTTPS/SOCKS 三条);PAC/WPAD 接管时只说明状态、不给覆盖命令;检测不可用回退原静态提示。
|
|
12
|
+
- `sub` 列表在全部订阅无流量数据且至少一个从未更新过时提示一句「更新订阅后可显示流量与到期」——刚 update 完仍无数据(机场不下发用量头)不再反复提示。
|
|
13
|
+
|
|
14
|
+
### 修复
|
|
15
|
+
|
|
16
|
+
- GitHub API 403 限流时的提示不再误导用户用镜像(镜像只作用于下载、解决不了版本查询的限流),改为指向真正的出路:等待限流重置或安装登录 gh 走认证查询。
|
|
17
|
+
- 拼错的镜像短别名(如 `--mirror cdnn`)此前被当自定义主机名放行、经 punycode 转换展示成一串认不出的主机且下载注定失败;现在按未知别名报错并给 did-you-mean。`--mirror 7897` 这类纯数字值提示改用 `--proxy`。含点/冒号的自定义主机名与完整 URL 的承诺行为不变。
|
|
18
|
+
- 帮助示例区首条从 `install` 改为 `kernel` 并按首次使用依赖顺序排列(kernel → sub add → install → start)——照旧示例敲的新用户第一步就撞「未找到内核」的墙。
|
|
19
|
+
- 裸 `--mirror` 后跟 `--proxy`/`-p` 的组合写法此前被参数校验误报「多余的参数」(四种等价形式里 exact 两种被拒、等号形式却通过)。
|
|
20
|
+
- `--proxy` 地址带认证信息(`http://user:pass@host:port`)时凭据被静默剥掉、连代理必 407 且报错无任何线索;显式写出的协议默认端口(`:80`/`:443`)被误报「需要端口」。
|
|
21
|
+
- gh 版本查询子进程超时从 120s 收紧到 10s:gh 无内建连接超时,直连被墙时挂满 120s 既拖慢回退链,也会在 doctor 弃掉查询后继续占住事件循环、推迟进程退出(doctor 的 4s 预算原本会被它整个耗干,「内核版本 ok」退化成 skip)。
|
|
22
|
+
|
|
23
|
+
### 变更
|
|
24
|
+
|
|
25
|
+
- `ow` 列表编号改为 1 基,与 `sub` 列表同口径(logs 的 `0=当前` 是特有语义,不受影响)。
|
|
26
|
+
- npm 卸载残留提醒的表述修正:经 registry 实测,npm 11.19.0 在全局/本地/`--prefix` 三种卸载场景下均不执行 preuninstall 生命周期脚本(官方文档亦注明 uninstall lifecycle scripts 未实现)——该提醒实际不会出现,卸载顺序的告诫不再依赖它;`scripts/preuninstall.mjs` 保留(未来 npm 恢复支持即生效),README 已如实改写。
|
|
27
|
+
|
|
3
28
|
## [4.14.0] - 2026-09-14
|
|
4
29
|
|
|
5
30
|
### 新增
|
package/README.md
CHANGED
|
@@ -59,6 +59,10 @@ mihomo kernel --mirror
|
|
|
59
59
|
# 或用短别名指定镜像(纯 IPv6 网络用 v6)
|
|
60
60
|
mihomo kernel --mirror cdn
|
|
61
61
|
mihomo kernel --mirror v6
|
|
62
|
+
|
|
63
|
+
# mihomo 没在跑、但本机有别的代理工具时,经指定代理出网(纯端口视为 127.0.0.1)
|
|
64
|
+
mihomo kernel --proxy 7897
|
|
65
|
+
mihomo kernel --proxy socks5://127.0.0.1:7897
|
|
62
66
|
```
|
|
63
67
|
|
|
64
68
|
### 2. 添加订阅
|
|
@@ -221,7 +225,7 @@ mihomo status # 查看状态
|
|
|
221
225
|
|
|
222
226
|
> `uninstall` 只卸服务,订阅/内核/日志仍留在数据目录(重装后可继续用)。要彻底移除 mihomo-cli:`mihomo reset --full` 删全部数据,再 `npm uninstall -g mihomo-cli`——`uninstall` 结束时也会提示这两步。
|
|
223
227
|
>
|
|
224
|
-
> **顺序别反**:先 `npm uninstall -g` 的话,LaunchAgent plist 会留下来,而能清理它的命令已经没了(plist 带 `KeepAlive`,仍会尝试拉起一个不存在的内核)。npm
|
|
228
|
+
> **顺序别反**:先 `npm uninstall -g` 的话,LaunchAgent plist 会留下来,而能清理它的命令已经没了(plist 带 `KeepAlive`,仍会尝试拉起一个不存在的内核)。npm 现代版本**不会执行** uninstall 生命周期钩子(实测 npm 11.19.0 三种卸载场景均不触发,官方文档亦注明 uninstall lifecycle scripts 未实现),所以别指望卸载时看到任何提醒——按上面的顺序来。真反了也能救,手动执行:
|
|
225
229
|
>
|
|
226
230
|
> ```bash
|
|
227
231
|
> launchctl bootout gui/$(id -u)/com.mihomo-cli.daemon 2>/dev/null
|
|
@@ -298,7 +302,7 @@ mihomo logs 1 # 查看最新的归档
|
|
|
298
302
|
|
|
299
303
|
镜像不持久化——每次按当前环境独立决策,换网络不会用到上次的镜像。
|
|
300
304
|
|
|
301
|
-
版本查询(GitHub API
|
|
305
|
+
版本查询(GitHub API)优先走 **gh 认证通道**(配额 5000 次/时,未认证直连仅 60 次/时——共享出口 IP 撞 403 限流时 gh 是唯一即时出路),gh 失败回退本机代理、再直连;镜像**绝不**作用于 API——
|
|
302
306
|
内核二进制在 TUN 模式下会以 root 运行,下载地址必须由 GitHub 官方 API 给出,不能让镜像自己指定。
|
|
303
307
|
|
|
304
308
|
手动覆盖:
|
|
@@ -310,6 +314,8 @@ mihomo kernel --mirror v6 # 显式走 v6.gh-proxy.org
|
|
|
310
314
|
mihomo kernel --mirror cdn # 短别名指定镜像(cdn/v4/v6/axisnow)
|
|
311
315
|
mihomo kernel --mirror hk.gh-proxy.org # 任意镜像主机名或完整 URL
|
|
312
316
|
mihomo kernel --mirror direct # 强制直连(绕过 gh/代理自动通道)
|
|
317
|
+
mihomo kernel --proxy 7897 # 经指定代理出网(纯端口视为 127.0.0.1:7897;mihomo 没跑但本机有别的代理工具时用)
|
|
318
|
+
mihomo kernel --proxy socks5://127.0.0.1:7897 # 完整代理地址;可与 --mirror 组合(镜像决定下载地址,代理只做传输)
|
|
313
319
|
```
|
|
314
320
|
|
|
315
321
|
> 镜像经第三方中转,无法验证来源完整性;gh 与本机代理通道直连 GitHub,优先使用。
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import fs15 from "fs";
|
|
5
5
|
|
|
6
|
-
//
|
|
6
|
+
// node_modules/compare-versions/lib/esm/utils.js
|
|
7
7
|
var semver = /^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;
|
|
8
8
|
var validateAndParse = (version) => {
|
|
9
9
|
if (typeof version !== "string") {
|
|
@@ -41,7 +41,7 @@ var compareSegments = (a, b) => {
|
|
|
41
41
|
return 0;
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
//
|
|
44
|
+
// node_modules/compare-versions/lib/esm/compareVersions.js
|
|
45
45
|
var compareVersions = (v1, v2) => {
|
|
46
46
|
const n1 = validateAndParse(v1);
|
|
47
47
|
const n2 = validateAndParse(v2);
|
|
@@ -82,7 +82,7 @@ import fs4 from "fs";
|
|
|
82
82
|
import path4 from "path";
|
|
83
83
|
import { promisify } from "util";
|
|
84
84
|
|
|
85
|
-
//
|
|
85
|
+
// node_modules/js-yaml/dist/js-yaml.mjs
|
|
86
86
|
var NOT_RESOLVED = /* @__PURE__ */ Symbol("NOT_RESOLVED");
|
|
87
87
|
function defineScalarTag(tagName, options) {
|
|
88
88
|
return {
|
|
@@ -4103,10 +4103,13 @@ var FLAGS = [
|
|
|
4103
4103
|
{ forms: ["-s", "--no-update"], takesValue: false, passthroughToRestart: true },
|
|
4104
4104
|
{ forms: ["-u", "--update-timeout"], takesValue: true, passthroughToRestart: true },
|
|
4105
4105
|
// === logs 的选项 ===
|
|
4106
|
-
{ forms: ["-n", "--lines"], takesValue: true }
|
|
4106
|
+
{ forms: ["-n", "--lines"], takesValue: true },
|
|
4107
|
+
// === kernel 的选项 ===
|
|
4108
|
+
{ forms: ["-p", "--proxy"], takesValue: true }
|
|
4107
4109
|
// 注意:`--mirror`(kernel)是可选值选项——`--mirror`、`--mirror=url`、`--mirror url`
|
|
4108
4110
|
// 三种形式都合法,只走 parseMirrorArg。故意不在此登记:登记了 getNonFlagArg 反而会
|
|
4109
4111
|
// 把它的值吞掉。它的解析与校验由 parseMirrorArg 自己负责。
|
|
4112
|
+
// `--proxy` 与之不同:值必填(裸 `--proxy` 无意义),是标准带值选项,走登记表。
|
|
4110
4113
|
];
|
|
4111
4114
|
var VALUE_FLAGS = new Set(FLAGS.filter((f) => f.takesValue).flatMap((f) => f.forms));
|
|
4112
4115
|
var START_RESTART_FLAGS = FLAGS.filter((f) => f.passthroughToRestart);
|
|
@@ -4146,6 +4149,10 @@ function sanitizeTerminal(s) {
|
|
|
4146
4149
|
function shellQuote(s) {
|
|
4147
4150
|
return `'${s.replace(/'/g, "'\\''")}'`;
|
|
4148
4151
|
}
|
|
4152
|
+
function isLoopbackHost(host) {
|
|
4153
|
+
const h = host.toLowerCase();
|
|
4154
|
+
return h === "127.0.0.1" || h === "localhost" || h === "::1";
|
|
4155
|
+
}
|
|
4149
4156
|
function proxyEnvPointsAtSelf(value, selfPort) {
|
|
4150
4157
|
let parsed;
|
|
4151
4158
|
try {
|
|
@@ -4157,8 +4164,8 @@ function proxyEnvPointsAtSelf(value, selfPort) {
|
|
|
4157
4164
|
return false;
|
|
4158
4165
|
}
|
|
4159
4166
|
}
|
|
4160
|
-
const host = parsed.hostname.replace(/^\[|\]$/g, "")
|
|
4161
|
-
if (host
|
|
4167
|
+
const host = parsed.hostname.replace(/^\[|\]$/g, "");
|
|
4168
|
+
if (!isLoopbackHost(host)) return false;
|
|
4162
4169
|
return Number.parseInt(parsed.port, 10) === selfPort;
|
|
4163
4170
|
}
|
|
4164
4171
|
function displayWidth(s) {
|
|
@@ -4277,7 +4284,7 @@ function assertPositionalCount(args, max, startIdx, usage, valueFlags = VALUE_FL
|
|
|
4277
4284
|
for (let i = startIdx; i < args.length; i++) {
|
|
4278
4285
|
const a = args[i];
|
|
4279
4286
|
if (a.startsWith("-")) {
|
|
4280
|
-
if (valueFlags.has(a)) i++;
|
|
4287
|
+
if (valueFlags.has(a) && i + 1 < args.length && !args[i + 1].startsWith("-")) i++;
|
|
4281
4288
|
continue;
|
|
4282
4289
|
}
|
|
4283
4290
|
count++;
|
|
@@ -4384,6 +4391,18 @@ function normalizeMirrorUrl(val) {
|
|
|
4384
4391
|
if (val === "direct") return null;
|
|
4385
4392
|
const alias = MIRROR_ALIASES[val.toLowerCase()];
|
|
4386
4393
|
if (alias) return alias;
|
|
4394
|
+
if (!/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(val) && !val.includes(".") && !val.includes(":")) {
|
|
4395
|
+
const suggestions = suggestSimilar(val, [...Object.keys(MIRROR_ALIASES), "direct"]);
|
|
4396
|
+
throw new CliError(`\u672A\u77E5\u7684\u955C\u50CF\u522B\u540D: "${val}"`, {
|
|
4397
|
+
label: "\u53C2\u6570\u9519\u8BEF",
|
|
4398
|
+
hint: [
|
|
4399
|
+
...suggestions.length > 0 ? [`\u662F\u5426\u60F3\u8F93\u5165: ${suggestions.join(" / ")}?`] : [],
|
|
4400
|
+
.../^\d+$/.test(val) ? ["\u6307\u5B9A\u4EE3\u7406\u7AEF\u53E3\u8BF7\u7528: --proxy <\u7AEF\u53E3>"] : [],
|
|
4401
|
+
`\u53EF\u7528\u522B\u540D: ${Object.keys(MIRROR_ALIASES).join(", ")}`,
|
|
4402
|
+
"\u81EA\u5B9A\u4E49\u955C\u50CF\u8BF7\u7528\u4E3B\u673A\u540D\u6216\u5B8C\u6574 URL: --mirror gh-proxy.org / --mirror https://gh-proxy.org/"
|
|
4403
|
+
]
|
|
4404
|
+
});
|
|
4405
|
+
}
|
|
4387
4406
|
const withScheme = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(val) ? val : `https://${val}`;
|
|
4388
4407
|
let parsed;
|
|
4389
4408
|
try {
|
|
@@ -4407,7 +4426,7 @@ function parseMirrorArg(args) {
|
|
|
4407
4426
|
if (!args || args.length < 2) {
|
|
4408
4427
|
return { mirror: null, isOverride: false };
|
|
4409
4428
|
}
|
|
4410
|
-
assertKnownFlags(args.slice(1),
|
|
4429
|
+
assertKnownFlags(args.slice(1), KERNEL_FLAG_WHITELIST, "kernel [--mirror [\u955C\u50CF]] [--proxy <\u7AEF\u53E3|\u5730\u5740>]");
|
|
4411
4430
|
const mirrorCount = args.filter((a) => a === "--mirror" || a.startsWith("--mirror=")).length;
|
|
4412
4431
|
if (mirrorCount > 1) {
|
|
4413
4432
|
throw new CliError("--mirror \u53EA\u80FD\u6307\u5B9A\u4E00\u6B21", {
|
|
@@ -4431,6 +4450,72 @@ function parseMirrorArg(args) {
|
|
|
4431
4450
|
}
|
|
4432
4451
|
return { mirror: null, isOverride: false };
|
|
4433
4452
|
}
|
|
4453
|
+
var KERNEL_FLAG_WHITELIST = ["--mirror", "--proxy", "-p"];
|
|
4454
|
+
var PROXY_SCHEMES = /* @__PURE__ */ new Set(["http:", "https:", "socks5:", "socks5h:"]);
|
|
4455
|
+
function normalizeProxyUrl(val) {
|
|
4456
|
+
if (/^\d+$/.test(val)) {
|
|
4457
|
+
const port = Number(val);
|
|
4458
|
+
if (!Number.isSafeInteger(port) || port < 1 || port > 65535) {
|
|
4459
|
+
throw new CliError(`\u4EE3\u7406\u7AEF\u53E3\u65E0\u6548: "${val}"`, { label: "\u53C2\u6570\u9519\u8BEF", hint: ["\u7AEF\u53E3\u8303\u56F4 1-65535\uFF0C\u4F8B\u5982: --proxy 7897"] });
|
|
4460
|
+
}
|
|
4461
|
+
return `http://127.0.0.1:${port}`;
|
|
4462
|
+
}
|
|
4463
|
+
const withScheme = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(val) ? val : `http://${val}`;
|
|
4464
|
+
let parsed;
|
|
4465
|
+
try {
|
|
4466
|
+
parsed = new URL(withScheme);
|
|
4467
|
+
} catch {
|
|
4468
|
+
throw new CliError(`\u4EE3\u7406\u5730\u5740\u65E0\u6548: "${val}"`, {
|
|
4469
|
+
label: "\u53C2\u6570\u9519\u8BEF",
|
|
4470
|
+
hint: ["\u683C\u5F0F\u5982: --proxy 7897\uFF08\u89C6\u4E3A 127.0.0.1:7897\uFF09", " --proxy 127.0.0.1:7897", " --proxy socks5://127.0.0.1:7897"]
|
|
4471
|
+
});
|
|
4472
|
+
}
|
|
4473
|
+
if (!PROXY_SCHEMES.has(parsed.protocol)) {
|
|
4474
|
+
throw new CliError(`\u4EE3\u7406\u534F\u8BAE\u4E0D\u652F\u6301: "${val}"`, { label: "\u53C2\u6570\u9519\u8BEF", hint: [`\u652F\u6301\u7684\u534F\u8BAE: ${[...PROXY_SCHEMES].map((s) => s.replace(":", "")).join(", ")}`] });
|
|
4475
|
+
}
|
|
4476
|
+
if (!parsed.hostname) {
|
|
4477
|
+
throw new CliError(`\u4EE3\u7406\u5730\u5740\u65E0\u6548: "${val}"\uFF08\u7F3A\u5C11\u4E3B\u673A\u540D\uFF09`, { label: "\u53C2\u6570\u9519\u8BEF", hint: ["\u4F8B\u5982: --proxy 127.0.0.1:7897"] });
|
|
4478
|
+
}
|
|
4479
|
+
const authority = withScheme.replace(/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//, "").split(/[/?#]/)[0];
|
|
4480
|
+
if (!/:\d+$/.test(authority)) {
|
|
4481
|
+
throw new CliError(`\u4EE3\u7406\u5730\u5740\u9700\u8981\u7AEF\u53E3: "${val}"`, { label: "\u53C2\u6570\u9519\u8BEF", hint: ["\u4F8B\u5982: --proxy 127.0.0.1:7897"] });
|
|
4482
|
+
}
|
|
4483
|
+
return `${parsed.protocol}//${authority}`;
|
|
4484
|
+
}
|
|
4485
|
+
function parseProxyArg(args) {
|
|
4486
|
+
if (!args || args.length < 2) {
|
|
4487
|
+
return { proxy: null };
|
|
4488
|
+
}
|
|
4489
|
+
assertKnownFlags(args.slice(1), KERNEL_FLAG_WHITELIST, "kernel [--mirror [\u955C\u50CF]] [--proxy <\u7AEF\u53E3|\u5730\u5740>]");
|
|
4490
|
+
const hits = [];
|
|
4491
|
+
for (let i = 0; i < args.length; i++) {
|
|
4492
|
+
const match = matchValueFlagToken(args[i]);
|
|
4493
|
+
if (!match?.spec.forms.includes("--proxy")) continue;
|
|
4494
|
+
if (match.form === "exact") {
|
|
4495
|
+
hits.push(args[i + 1] ?? "");
|
|
4496
|
+
i++;
|
|
4497
|
+
} else {
|
|
4498
|
+
hits.push(match.inlineValue ?? "");
|
|
4499
|
+
}
|
|
4500
|
+
}
|
|
4501
|
+
if (hits.length === 0) {
|
|
4502
|
+
return { proxy: null };
|
|
4503
|
+
}
|
|
4504
|
+
if (hits.length > 1) {
|
|
4505
|
+
throw new CliError("--proxy \u53EA\u80FD\u6307\u5B9A\u4E00\u6B21", {
|
|
4506
|
+
label: "\u53C2\u6570\u9519\u8BEF",
|
|
4507
|
+
hint: ["\u7528\u6CD5: mihomo kernel --proxy <\u7AEF\u53E3|\u5730\u5740>", "\u4F8B\u5982: mihomo kernel --proxy 7897"]
|
|
4508
|
+
});
|
|
4509
|
+
}
|
|
4510
|
+
const raw = hits[0].trim();
|
|
4511
|
+
if (!raw || raw.startsWith("-")) {
|
|
4512
|
+
throw new CliError("--proxy \u9700\u8981\u4E00\u4E2A\u7AEF\u53E3\u6216\u4EE3\u7406\u5730\u5740", {
|
|
4513
|
+
label: "\u53C2\u6570\u9519\u8BEF",
|
|
4514
|
+
hint: ["\u4F8B\u5982: --proxy 7897\uFF08\u89C6\u4E3A 127.0.0.1:7897\uFF09", " --proxy 127.0.0.1:7897 \u6216 --proxy socks5://127.0.0.1:7897"]
|
|
4515
|
+
});
|
|
4516
|
+
}
|
|
4517
|
+
return { proxy: normalizeProxyUrl(raw) };
|
|
4518
|
+
}
|
|
4434
4519
|
|
|
4435
4520
|
// src/config.ts
|
|
4436
4521
|
var SAFE_YAML_LOAD_OPTIONS = { maxAliases: 200 };
|
|
@@ -5644,12 +5729,15 @@ ${colors.cyan(colors.bold(`mihomo-cli v${VERSION}`))}`, "", "\u547D\u4EE4\u522B\
|
|
|
5644
5729
|
lines.push(
|
|
5645
5730
|
"",
|
|
5646
5731
|
`${colors.cyan("\u793A\u4F8B:")}`,
|
|
5732
|
+
// 顺序即首次使用的依赖顺序(kernel → 订阅 → 服务 → 启动):install 在无内核时会被
|
|
5733
|
+
// 拦下提示先跑 kernel,示例若把 install 放第一条,照着敲的新用户第一步就撞墙
|
|
5734
|
+
" mihomo kernel # \u4E0B\u8F7D\u5185\u6838\uFF08\u9996\u6B21\u4F7F\u7528\u7684\u7B2C\u4E00\u6B65\uFF09",
|
|
5735
|
+
" mihomo sub add <url> # \u6DFB\u52A0\u8BA2\u9605 (sub \u662F subscription \u522B\u540D)",
|
|
5647
5736
|
" mihomo install # \u5B89\u88C5\u670D\u52A1\uFF08Mixed \u6A21\u5F0F\u7684\u524D\u7F6E\uFF0C\u53EA\u9700\u4E00\u6B21\uFF09",
|
|
5648
5737
|
" mihomo start # \u542F\u52A8\u4EE3\u7406\u5E76\u5F00\u542F\u767B\u5F55\u81EA\u542F",
|
|
5649
5738
|
" mihomo stop # \u505C\u6B62\u5E76\u5173\u95ED\u767B\u5F55\u81EA\u542F",
|
|
5650
5739
|
" mihomo start tun # \u4E34\u65F6 TUN \u900F\u660E\u4EE3\u7406\uFF08\u4E0D\u8D70\u670D\u52A1\uFF0C\u9700 sudo\uFF09",
|
|
5651
5740
|
" mihomo start -s # \u8DF3\u8FC7\u81EA\u52A8\u66F4\u65B0\u8BA2\u9605",
|
|
5652
|
-
" mihomo sub add <url> # \u6DFB\u52A0\u8BA2\u9605 (sub \u662F subscription \u522B\u540D)",
|
|
5653
5741
|
" mihomo ui # \u6253\u5F00 Web UI",
|
|
5654
5742
|
"",
|
|
5655
5743
|
`${colors.cyan("\u5FEB\u6377\u547D\u4EE4:")}`,
|
|
@@ -6385,6 +6473,83 @@ async function assertServiceHealthy(label = "\u542F\u52A8\u5931\u8D25") {
|
|
|
6385
6473
|
});
|
|
6386
6474
|
}
|
|
6387
6475
|
|
|
6476
|
+
// src/system-proxy.ts
|
|
6477
|
+
import { spawnSync as spawnSync5 } from "child_process";
|
|
6478
|
+
function parseScutilProxy(stdout) {
|
|
6479
|
+
const values = /* @__PURE__ */ new Map();
|
|
6480
|
+
for (const line of stdout.split("\n")) {
|
|
6481
|
+
const m = line.match(/^ {2}([A-Za-z]+) : (.+)$/);
|
|
6482
|
+
if (m) values.set(m[1], m[2].trim());
|
|
6483
|
+
}
|
|
6484
|
+
const read = (prefix) => {
|
|
6485
|
+
if (values.get(`${prefix}Enable`) !== "1") return void 0;
|
|
6486
|
+
const host = values.get(`${prefix}Proxy`);
|
|
6487
|
+
const port = Number.parseInt(values.get(`${prefix}Port`) ?? "", 10);
|
|
6488
|
+
if (!host || !Number.isFinite(port)) return void 0;
|
|
6489
|
+
return { host, port };
|
|
6490
|
+
};
|
|
6491
|
+
const readPac = () => {
|
|
6492
|
+
if (values.get("ProxyAutoConfigEnable") === "1") {
|
|
6493
|
+
const url = values.get("ProxyAutoConfigURLString") ?? "";
|
|
6494
|
+
const host = values.get("ProxyAutoConfigHost");
|
|
6495
|
+
const port = values.get("ProxyAutoConfigPort");
|
|
6496
|
+
const legacy = host ? `${host}${port ? `:${port}` : ""}` : "";
|
|
6497
|
+
return { source: url || legacy, wpad: false };
|
|
6498
|
+
}
|
|
6499
|
+
if (values.get("ProxyAutoDiscoveryEnable") === "1") {
|
|
6500
|
+
return { source: "", wpad: true };
|
|
6501
|
+
}
|
|
6502
|
+
return void 0;
|
|
6503
|
+
};
|
|
6504
|
+
return { http: read("HTTP"), https: read("HTTPS"), socks: read("SOCKS"), pac: readPac() };
|
|
6505
|
+
}
|
|
6506
|
+
var entryMatches = (e, mixedPort) => isLoopbackHost(e.host) && e.port === mixedPort;
|
|
6507
|
+
function summarizeSystemProxy(view, mixedPort) {
|
|
6508
|
+
const entries = [view.http, view.https, view.socks].filter((e) => e !== void 0);
|
|
6509
|
+
return {
|
|
6510
|
+
matched: entries.some((e) => entryMatches(e, mixedPort)),
|
|
6511
|
+
active: [...new Set(entries.map((e) => `${e.host}:${e.port}`))],
|
|
6512
|
+
diverged: [...new Set(entries.filter((e) => !entryMatches(e, mixedPort)).map((e) => `${e.host}:${e.port}`))],
|
|
6513
|
+
pac: view.pac ?? null
|
|
6514
|
+
};
|
|
6515
|
+
}
|
|
6516
|
+
function detectSystemProxy(mixedPort) {
|
|
6517
|
+
let r;
|
|
6518
|
+
try {
|
|
6519
|
+
r = spawnSync5("scutil", ["--proxy"], { encoding: "utf8", timeout: 3e3 });
|
|
6520
|
+
} catch {
|
|
6521
|
+
return null;
|
|
6522
|
+
}
|
|
6523
|
+
if (r.error || r.status !== 0 || typeof r.stdout !== "string" || !r.stdout.includes("<dictionary>")) return null;
|
|
6524
|
+
return summarizeSystemProxy(parseScutilProxy(r.stdout), mixedPort);
|
|
6525
|
+
}
|
|
6526
|
+
function printSystemProxyHint(mixedPort) {
|
|
6527
|
+
const summary = detectSystemProxy(mixedPort);
|
|
6528
|
+
if (summary === null) {
|
|
6529
|
+
console.log(colors.gray(`\u63D0\u793A: Mixed \u6A21\u5F0F\u9700\u5728\u7CFB\u7EDF\u8BBE\u7F6E\u914D\u7F6E HTTP/SOCKS \u4EE3\u7406 127.0.0.1:${mixedPort}\uFF08TUN \u6A21\u5F0F\u65E0\u9700\uFF09`));
|
|
6530
|
+
return;
|
|
6531
|
+
}
|
|
6532
|
+
if (summary.pac) {
|
|
6533
|
+
const desc = summary.pac.wpad ? "WPAD \u81EA\u52A8\u53D1\u73B0" : `PAC \u6587\u4EF6${summary.pac.source ? `\uFF08${summary.pac.source}\uFF09` : ""}`;
|
|
6534
|
+
console.log(colors.gray(`\u7CFB\u7EDF\u4EE3\u7406\u7531 ${desc} \u63A5\u7BA1\uFF0C\u662F\u5426\u8D70 mihomo \u7531\u811A\u672C\u51B3\u5B9A\uFF1B\u5982\u9700\u56FA\u5B9A\u5168\u91CF\u8D70\u4EE3\u7406\uFF0C\u53EF\u5728\u7CFB\u7EDF\u8BBE\u7F6E\u6539\u7528\u624B\u52A8\u4EE3\u7406 127.0.0.1:${mixedPort}`));
|
|
6535
|
+
return;
|
|
6536
|
+
}
|
|
6537
|
+
if (summary.matched) {
|
|
6538
|
+
if (summary.diverged.length > 0) {
|
|
6539
|
+
console.log(colors.yellow(`\u63D0\u793A: \u90E8\u5206\u7CFB\u7EDF\u4EE3\u7406\u5DF2\u6307\u5411 127.0.0.1:${mixedPort}\uFF0C\u4F46 ${summary.diverged.join("\u3001")} \u4ECD\u6307\u5411\u522B\u5904\u2014\u2014\u5BF9\u5E94\u6D41\u91CF\u53EF\u80FD\u4E0D\u7ECF mihomo`));
|
|
6540
|
+
} else {
|
|
6541
|
+
console.log(colors.gray(`\u7CFB\u7EDF\u4EE3\u7406\u5DF2\u6307\u5411 127.0.0.1:${mixedPort}`));
|
|
6542
|
+
}
|
|
6543
|
+
return;
|
|
6544
|
+
}
|
|
6545
|
+
const pointing = summary.active.length > 0 ? `\uFF0C\u5F53\u524D\u6307\u5411 ${summary.active.join("\u3001")}` : "";
|
|
6546
|
+
console.log(colors.yellow(`\u63D0\u793A: \u7CFB\u7EDF\u4EE3\u7406\u672A\u6307\u5411 127.0.0.1:${mixedPort}${pointing}\uFF1B\u9700\u8981\u4EE3\u7406\u7684\u5E94\u7528\u8BF7\u914D\u7F6E\u540E\u4F7F\u7528\uFF08TUN \u6A21\u5F0F\u65E0\u9700\uFF09`));
|
|
6547
|
+
console.log(colors.gray(" \u8BBE\u7F6E\u547D\u4EE4\uFF08\u628A Wi-Fi \u6362\u6210\u5B9E\u9645\u7F51\u7EDC\u670D\u52A1\uFF0C\u5168\u90E8\u670D\u52A1\u89C1 networksetup -listallnetworkservices\uFF09:"));
|
|
6548
|
+
console.log(colors.gray(` networksetup -setwebproxy "Wi-Fi" 127.0.0.1 ${mixedPort}`));
|
|
6549
|
+
console.log(colors.gray(` networksetup -setsecurewebproxy "Wi-Fi" 127.0.0.1 ${mixedPort}`));
|
|
6550
|
+
console.log(colors.gray(` networksetup -setsocksfirewallproxy "Wi-Fi" 127.0.0.1 ${mixedPort}`));
|
|
6551
|
+
}
|
|
6552
|
+
|
|
6388
6553
|
// src/proxy-probe.ts
|
|
6389
6554
|
import { execFile as execFile2 } from "child_process";
|
|
6390
6555
|
import { promisify as promisify2 } from "util";
|
|
@@ -6760,7 +6925,7 @@ async function cmdStart(args) {
|
|
|
6760
6925
|
}
|
|
6761
6926
|
await printStatus();
|
|
6762
6927
|
if (targetMode === "mixed") {
|
|
6763
|
-
|
|
6928
|
+
printSystemProxyHint(getPorts().mixed);
|
|
6764
6929
|
} else {
|
|
6765
6930
|
console.log(colors.gray("TUN \u4E3A\u4E34\u65F6\u8FDB\u7A0B\uFF0C\u5173\u95ED\u7EC8\u7AEF\u4E0D\u4F1A\u505C\u6B62\uFF1B\u505C\u6B62: mihomo stop\uFF08\u4E4B\u540E mihomo start \u6062\u590D Mixed\uFF09"));
|
|
6766
6931
|
}
|
|
@@ -6877,11 +7042,11 @@ async function cmdDirectory(args) {
|
|
|
6877
7042
|
}
|
|
6878
7043
|
|
|
6879
7044
|
// src/commands/doctor.ts
|
|
6880
|
-
import { spawnSync as
|
|
7045
|
+
import { spawnSync as spawnSync7 } from "child_process";
|
|
6881
7046
|
import fs11 from "fs";
|
|
6882
7047
|
|
|
6883
7048
|
// src/kernel.ts
|
|
6884
|
-
import { execFile as execFile3, spawnSync as
|
|
7049
|
+
import { execFile as execFile3, spawnSync as spawnSync6 } from "child_process";
|
|
6885
7050
|
import fs10 from "fs";
|
|
6886
7051
|
import path8 from "path";
|
|
6887
7052
|
import { promisify as promisify3 } from "util";
|
|
@@ -6915,13 +7080,16 @@ function assertTrustedAssetUrl(rawUrl) {
|
|
|
6915
7080
|
}
|
|
6916
7081
|
function resolveDownloadChannel(input) {
|
|
6917
7082
|
if (input.isOverride && !input.mirror) return { kind: "direct" };
|
|
6918
|
-
if (input.isOverride && input.mirror)
|
|
7083
|
+
if (input.isOverride && input.mirror) {
|
|
7084
|
+
return input.proxyOverride ? { kind: "mirror", mirror: input.mirror, proxy: input.proxyOverride } : { kind: "mirror", mirror: input.mirror };
|
|
7085
|
+
}
|
|
7086
|
+
if (input.proxyOverride) return { kind: "proxy", proxy: input.proxyOverride };
|
|
6919
7087
|
if (input.ghAvailable) return { kind: "gh" };
|
|
6920
|
-
if (input.proxyRunning && input.proxyPort !== null) return { kind: "proxy",
|
|
7088
|
+
if (input.proxyRunning && input.proxyPort !== null) return { kind: "proxy", proxy: `http://127.0.0.1:${input.proxyPort}` };
|
|
6921
7089
|
return { kind: "direct" };
|
|
6922
7090
|
}
|
|
6923
7091
|
function hasGh() {
|
|
6924
|
-
const result =
|
|
7092
|
+
const result = spawnSync6("gh", ["--version"], { stdio: "ignore" });
|
|
6925
7093
|
return !result.error && result.status === 0;
|
|
6926
7094
|
}
|
|
6927
7095
|
function getArch() {
|
|
@@ -6950,11 +7118,11 @@ function pickLatestRelease(releases) {
|
|
|
6950
7118
|
}
|
|
6951
7119
|
return stableReleases[0];
|
|
6952
7120
|
}
|
|
6953
|
-
function buildReleaseApiCurlArgs(
|
|
7121
|
+
function buildReleaseApiCurlArgs(proxy, url) {
|
|
6954
7122
|
return [
|
|
6955
7123
|
"-s",
|
|
6956
7124
|
"-x",
|
|
6957
|
-
|
|
7125
|
+
proxy,
|
|
6958
7126
|
"--proto",
|
|
6959
7127
|
"=https",
|
|
6960
7128
|
"--proto-redir",
|
|
@@ -6996,12 +7164,30 @@ function translateReleaseApiCurlError(e) {
|
|
|
6996
7164
|
const lastLine = stderr ? stderr.split("\n").pop()?.replace(/^curl: \(\d+\)\s*/, "") : void 0;
|
|
6997
7165
|
return new Error(`\u7248\u672C\u67E5\u8BE2\u5931\u8D25 (curl \u9000\u51FA\u7801 ${err.code ?? "?"}${lastLine ? `: ${lastLine}` : ""})`);
|
|
6998
7166
|
}
|
|
6999
|
-
|
|
7167
|
+
function buildGhApiReleaseArgs(repo) {
|
|
7168
|
+
return ["api", `repos/${repo}/releases`, "--method", "GET"];
|
|
7169
|
+
}
|
|
7170
|
+
var GH_API_TIMEOUT = 1e4;
|
|
7171
|
+
async function getLatestReleaseViaGh(repo) {
|
|
7172
|
+
const result = await execFileAsync2("gh", buildGhApiReleaseArgs(repo), {
|
|
7173
|
+
encoding: "utf8",
|
|
7174
|
+
maxBuffer: 50 * 1024 * 1024,
|
|
7175
|
+
timeout: GH_API_TIMEOUT
|
|
7176
|
+
});
|
|
7177
|
+
return pickLatestRelease(JSON.parse(result.stdout));
|
|
7178
|
+
}
|
|
7179
|
+
async function getLatestRelease(repo, opts = { proxy: null, useGh: false }) {
|
|
7000
7180
|
const url = `https://api.github.com/repos/${repo}/releases`;
|
|
7001
|
-
if (
|
|
7181
|
+
if (opts.useGh) {
|
|
7182
|
+
try {
|
|
7183
|
+
return await getLatestReleaseViaGh(repo);
|
|
7184
|
+
} catch {
|
|
7185
|
+
}
|
|
7186
|
+
}
|
|
7187
|
+
if (opts.proxy) {
|
|
7002
7188
|
let stdout;
|
|
7003
7189
|
try {
|
|
7004
|
-
const result = await execFileAsync2("curl", buildReleaseApiCurlArgs(
|
|
7190
|
+
const result = await execFileAsync2("curl", buildReleaseApiCurlArgs(opts.proxy, url), {
|
|
7005
7191
|
encoding: "utf8",
|
|
7006
7192
|
maxBuffer: 50 * 1024 * 1024,
|
|
7007
7193
|
timeout: KERNEL_HTTP_TIMEOUT + 1e4
|
|
@@ -7025,9 +7211,9 @@ async function getLatestRelease(repo, proxyPort) {
|
|
|
7025
7211
|
const response = await HTTP_CLIENT2.get(url, { responseType: "json" });
|
|
7026
7212
|
return pickLatestRelease(response.data);
|
|
7027
7213
|
}
|
|
7028
|
-
async function checkUpdate(
|
|
7214
|
+
async function checkUpdate(opts) {
|
|
7029
7215
|
const currentVersion = getKernelVersion();
|
|
7030
|
-
const latest = await getLatestRelease(GITHUB_REPO,
|
|
7216
|
+
const latest = await getLatestRelease(GITHUB_REPO, opts);
|
|
7031
7217
|
const latestVersion = latest.tag_name;
|
|
7032
7218
|
let needsUpdate = false;
|
|
7033
7219
|
const currentDisplay = currentVersion || "\u672A\u5B89\u88C5";
|
|
@@ -7067,8 +7253,8 @@ function buildKernelCurlArgs(args) {
|
|
|
7067
7253
|
"--max-time",
|
|
7068
7254
|
String(Math.floor(KERNEL_DOWNLOAD_TIMEOUT / 1e3))
|
|
7069
7255
|
];
|
|
7070
|
-
if (args.
|
|
7071
|
-
argv.push("-x",
|
|
7256
|
+
if (args.proxy) {
|
|
7257
|
+
argv.push("-x", args.proxy);
|
|
7072
7258
|
}
|
|
7073
7259
|
argv.push("-o", args.outputPath, args.url);
|
|
7074
7260
|
return argv;
|
|
@@ -7078,7 +7264,8 @@ function buildGhReleaseDownloadArgs(tag, assetName, dir) {
|
|
|
7078
7264
|
}
|
|
7079
7265
|
async function downloadKernel(progressCallback, channel, releaseInfo) {
|
|
7080
7266
|
ensureDirs();
|
|
7081
|
-
const
|
|
7267
|
+
const apiProxy = channel.kind === "proxy" ? channel.proxy : channel.kind === "mirror" ? channel.proxy ?? null : null;
|
|
7268
|
+
const latest = releaseInfo || await getLatestRelease(GITHUB_REPO, { proxy: apiProxy, useGh: channel.kind === "gh" });
|
|
7082
7269
|
const arch = getArch();
|
|
7083
7270
|
const platform = process.platform;
|
|
7084
7271
|
const asset = findMatchingAsset(latest.assets, platform, arch);
|
|
@@ -7106,7 +7293,7 @@ async function downloadKernel(progressCallback, channel, releaseInfo) {
|
|
|
7106
7293
|
if (/[*?[\]]/.test(asset.name) || asset.name !== path8.basename(asset.name)) {
|
|
7107
7294
|
throw new Error(`\u5185\u6838\u8D44\u4EA7\u540D\u542B\u975E\u6CD5\u5B57\u7B26: ${asset.name}`);
|
|
7108
7295
|
}
|
|
7109
|
-
const ghResult =
|
|
7296
|
+
const ghResult = spawnSync6("gh", buildGhReleaseDownloadArgs(latest.tag_name, asset.name, tempDir), {
|
|
7110
7297
|
stdio: "inherit",
|
|
7111
7298
|
timeout: KERNEL_DOWNLOAD_TIMEOUT + 3e4
|
|
7112
7299
|
});
|
|
@@ -7124,11 +7311,11 @@ async function downloadKernel(progressCallback, channel, releaseInfo) {
|
|
|
7124
7311
|
}
|
|
7125
7312
|
} else {
|
|
7126
7313
|
const maxBytes = Number.isFinite(asset.size) && asset.size > 0 ? Math.floor(asset.size * 2 + 1024 * 1024) : 512 * 1024 * 1024;
|
|
7127
|
-
const curlResult =
|
|
7314
|
+
const curlResult = spawnSync6(
|
|
7128
7315
|
"curl",
|
|
7129
7316
|
buildKernelCurlArgs({
|
|
7130
7317
|
url: downloadUrl,
|
|
7131
|
-
|
|
7318
|
+
proxy: apiProxy,
|
|
7132
7319
|
maxBytes,
|
|
7133
7320
|
outputPath: tempPath
|
|
7134
7321
|
}),
|
|
@@ -7166,7 +7353,7 @@ async function downloadKernel(progressCallback, channel, releaseInfo) {
|
|
|
7166
7353
|
throw new Error(`\u4E0D\u652F\u6301\u7684\u5185\u6838\u8D44\u4EA7\u683C\u5F0F: ${asset.name}\uFF08\u671F\u671B\u5355\u6587\u4EF6 .gz\uFF09`);
|
|
7167
7354
|
}
|
|
7168
7355
|
const foundBinary = path8.join(tempDir, path8.basename(tempPath, ".gz"));
|
|
7169
|
-
const gzipResult =
|
|
7356
|
+
const gzipResult = spawnSync6("gzip", ["-dc", tempPath], { maxBuffer: 256 * 1024 * 1024, timeout: 6e4 });
|
|
7170
7357
|
if (gzipResult.error) throw gzipResult.error;
|
|
7171
7358
|
if (gzipResult.status !== 0) throw new Error(`gzip \u9000\u51FA\u7801 ${gzipResult.status}`);
|
|
7172
7359
|
fs10.writeFileSync(foundBinary, gzipResult.stdout, { mode: 493 });
|
|
@@ -7174,7 +7361,7 @@ async function downloadKernel(progressCallback, channel, releaseInfo) {
|
|
|
7174
7361
|
progressCallback("\u6821\u9A8C\u5185\u6838...");
|
|
7175
7362
|
}
|
|
7176
7363
|
fs10.chmodSync(foundBinary, 493);
|
|
7177
|
-
const check =
|
|
7364
|
+
const check = spawnSync6(foundBinary, ["-v"], { encoding: "utf8", timeout: 5e3 });
|
|
7178
7365
|
const checkOutput = `${check.stdout || ""}${check.stderr || ""}`.trim();
|
|
7179
7366
|
if (check.error || check.status !== 0 || !/v?\d+\.\d+\.\d+/.test(checkOutput)) {
|
|
7180
7367
|
throw new Error(`\u5185\u6838\u81EA\u68C0\u5931\u8D25\uFF08\u53EF\u80FD\u4E0B\u8F7D\u635F\u574F\u6216\u67B6\u6784\u4E0D\u5339\u914D\uFF09\uFF0C\u65E7\u5185\u6838\u672A\u53D7\u5F71\u54CD
|
|
@@ -7291,7 +7478,7 @@ function withTimeout2(promise, ms) {
|
|
|
7291
7478
|
}
|
|
7292
7479
|
function isPortListening(port) {
|
|
7293
7480
|
try {
|
|
7294
|
-
const r =
|
|
7481
|
+
const r = spawnSync7("lsof", ["-nP", `-iTCP:${port}`, "-sTCP:LISTEN"], { encoding: "utf8", timeout: 5e3 });
|
|
7295
7482
|
return r.status === 0 && (r.stdout || "").trim().length > 0;
|
|
7296
7483
|
} catch {
|
|
7297
7484
|
return false;
|
|
@@ -7310,7 +7497,13 @@ async function collectChecks() {
|
|
|
7310
7497
|
} catch {
|
|
7311
7498
|
kernelProxyPort = null;
|
|
7312
7499
|
}
|
|
7313
|
-
const kernelVersionPromise = hasKernel() ? withTimeout2(
|
|
7500
|
+
const kernelVersionPromise = hasKernel() ? withTimeout2(
|
|
7501
|
+
checkUpdate({
|
|
7502
|
+
proxy: kernelProxyPort !== null ? `http://127.0.0.1:${kernelProxyPort}` : null,
|
|
7503
|
+
useGh: kernelProxyPort === null && hasGh()
|
|
7504
|
+
}),
|
|
7505
|
+
4e3
|
|
7506
|
+
).then(
|
|
7314
7507
|
(v) => v,
|
|
7315
7508
|
() => null
|
|
7316
7509
|
) : Promise.resolve(null);
|
|
@@ -7318,7 +7511,7 @@ async function collectChecks() {
|
|
|
7318
7511
|
push("\u5185\u6838", "fail", "\u672A\u5B89\u88C5", "mihomo kernel");
|
|
7319
7512
|
} else {
|
|
7320
7513
|
const v = getKernelVersion();
|
|
7321
|
-
const r =
|
|
7514
|
+
const r = spawnSync7(PATHS.mihomoBinary, ["-v"], { encoding: "utf8", timeout: 5e3 });
|
|
7322
7515
|
if (r.status === 0 && /v?\d+\.\d+\.\d+/.test(`${r.stdout}${r.stderr}`)) {
|
|
7323
7516
|
push("\u5185\u6838", "ok", v || "\u53EF\u6267\u884C");
|
|
7324
7517
|
} else if (r.error) {
|
|
@@ -7491,34 +7684,44 @@ async function cmdDoctor(args = []) {
|
|
|
7491
7684
|
var KERNEL_VALUE_FLAGS = /* @__PURE__ */ new Set([...VALUE_FLAGS, "--mirror"]);
|
|
7492
7685
|
async function cmdKernel(args) {
|
|
7493
7686
|
const mirrorInfo = parseMirrorArg(args);
|
|
7494
|
-
|
|
7495
|
-
|
|
7687
|
+
const proxyInfo = parseProxyArg(args);
|
|
7688
|
+
assertPositionalCount(args, 0, 1, "mihomo kernel [--mirror [\u955C\u50CF]] [--proxy <\u7AEF\u53E3|\u5730\u5740>]", KERNEL_VALUE_FLAGS);
|
|
7689
|
+
if (proxyInfo.proxy && mirrorInfo.isOverride && !mirrorInfo.mirror) {
|
|
7690
|
+
throw new CliError("--mirror direct \u4E0E --proxy \u4E0D\u80FD\u540C\u65F6\u4F7F\u7528", {
|
|
7691
|
+
label: "\u53C2\u6570\u9519\u8BEF",
|
|
7692
|
+
hint: ["--mirror direct \u5F3A\u5236\u4E0D\u7ECF\u4EFB\u4F55\u4EE3\u7406\u76F4\u8FDE\uFF0C\u9700\u8D70\u4EE3\u7406\u65F6\u53BB\u6389\u5B83:", " mihomo kernel --proxy <\u7AEF\u53E3|\u5730\u5740>"]
|
|
7693
|
+
});
|
|
7694
|
+
}
|
|
7496
7695
|
const proxyRunning = getRunningState().running;
|
|
7497
7696
|
const proxyPort = proxyRunning ? getPorts().mixed : null;
|
|
7498
7697
|
const forceDirect = mirrorInfo.isOverride && !mirrorInfo.mirror;
|
|
7698
|
+
const ghAvailable = hasGh();
|
|
7499
7699
|
const channel = resolveDownloadChannel({
|
|
7500
7700
|
mirror: mirrorInfo.mirror,
|
|
7501
7701
|
isOverride: mirrorInfo.isOverride,
|
|
7502
|
-
ghAvailable
|
|
7702
|
+
ghAvailable,
|
|
7503
7703
|
proxyRunning,
|
|
7504
|
-
proxyPort
|
|
7704
|
+
proxyPort,
|
|
7705
|
+
proxyOverride: proxyInfo.proxy
|
|
7505
7706
|
});
|
|
7506
7707
|
if (channel.kind === "gh") {
|
|
7507
7708
|
console.log("\u4E0B\u8F7D\u901A\u9053: gh\uFF08GitHub CLI \u76F4\u8FDE\uFF09");
|
|
7508
7709
|
console.log("");
|
|
7509
7710
|
} else if (channel.kind === "proxy") {
|
|
7510
|
-
|
|
7711
|
+
const label = proxyInfo.proxy ? "\u4EE3\u7406" : "\u672C\u673A\u4EE3\u7406";
|
|
7712
|
+
console.log(`\u4E0B\u8F7D\u901A\u9053: ${label} ${channel.proxy}`);
|
|
7511
7713
|
console.log("");
|
|
7512
7714
|
} else if (channel.kind === "mirror") {
|
|
7513
7715
|
const host = channel.mirror.replace(/^https?:\/\//, "").replace(/\/$/, "");
|
|
7514
|
-
console.log(`\u955C\u50CF: ${host}`);
|
|
7716
|
+
console.log(`\u955C\u50CF: ${host}${channel.proxy ? `\uFF08\u7ECF\u4EE3\u7406 ${channel.proxy}\uFF09` : ""}`);
|
|
7515
7717
|
console.log("");
|
|
7516
7718
|
}
|
|
7719
|
+
const apiProxy = proxyInfo.proxy ?? (proxyRunning && !forceDirect && proxyPort !== null ? `http://127.0.0.1:${proxyPort}` : null);
|
|
7720
|
+
const useGh = apiProxy === null && !forceDirect && ghAvailable;
|
|
7517
7721
|
let info;
|
|
7518
7722
|
try {
|
|
7519
|
-
const
|
|
7520
|
-
|
|
7521
|
-
info = await withSpinner(spinnerText, () => checkUpdate(useProxyForApi ? proxyPort : null));
|
|
7723
|
+
const spinnerText = apiProxy ? `\u68C0\u67E5\u5185\u6838\u66F4\u65B0\uFF08\u7ECF\u4EE3\u7406 ${apiProxy}\uFF09` : useGh ? "\u68C0\u67E5\u5185\u6838\u66F4\u65B0\uFF08gh \u8BA4\u8BC1\u901A\u9053\uFF09" : "\u68C0\u67E5\u5185\u6838\u66F4\u65B0\uFF08GitHub \u76F4\u8FDE\uFF0C\u56FD\u5185\u7F51\u7EDC\u53EF\u80FD\u8F83\u6162\uFF09";
|
|
7724
|
+
info = await withSpinner(spinnerText, () => checkUpdate({ proxy: apiProxy, useGh }));
|
|
7522
7725
|
} catch (e) {
|
|
7523
7726
|
if (e instanceof CliError) throw e;
|
|
7524
7727
|
const err = e;
|
|
@@ -7529,15 +7732,26 @@ async function cmdKernel(args) {
|
|
|
7529
7732
|
if (err.response?.data?.documentation_url) {
|
|
7530
7733
|
hint.push(`\u6587\u6863: ${err.response.data.documentation_url}`);
|
|
7531
7734
|
}
|
|
7532
|
-
if (
|
|
7533
|
-
|
|
7534
|
-
|
|
7735
|
+
if (err.response?.status === 403 && /rate limit/i.test(err.response.data?.message ?? "")) {
|
|
7736
|
+
hint.push(
|
|
7737
|
+
"",
|
|
7738
|
+
"\u63D0\u793A: GitHub \u5BF9\u672A\u8BA4\u8BC1 API \u8BF7\u6C42\u9650\u6D41\uFF08\u7EA6 60 \u6B21/\u65F6\uFF0C\u5171\u4EAB\u51FA\u53E3 IP \u5E38\u89E6\u53D1\uFF09\uFF1B\u955C\u50CF\u53EA\u4F5C\u7528\u4E8E\u4E0B\u8F7D\uFF0C\u89E3\u51B3\u4E0D\u4E86\u7248\u672C\u67E5\u8BE2\u7684\u9650\u6D41",
|
|
7739
|
+
"\u7B49\u5F85\u9650\u6D41\u91CD\u7F6E\uFF08\u7EA6 1 \u5C0F\u65F6\uFF09\u540E\u91CD\u8BD5\uFF0C\u6216\u5B89\u88C5\u5E76\u767B\u5F55 GitHub CLI \u8D70\u8BA4\u8BC1\u67E5\u8BE2\uFF08\u914D\u989D 5000 \u6B21/\u65F6\uFF09:",
|
|
7740
|
+
" brew install gh && gh auth login"
|
|
7741
|
+
);
|
|
7742
|
+
if (useGh) {
|
|
7743
|
+
hint.push("", "\u672C\u6B21\u5DF2\u5148\u5C1D\u8BD5 gh \u8BA4\u8BC1\u901A\u9053\u3001\u5931\u8D25\u540E\u624D\u56DE\u9000\u76F4\u8FDE\uFF0C\u53EF\u68C0\u67E5 gh \u767B\u5F55\u72B6\u6001: gh auth status");
|
|
7744
|
+
}
|
|
7745
|
+
} else if (!mirrorInfo.mirror) {
|
|
7746
|
+
if (apiProxy) {
|
|
7747
|
+
hint.push("", "\u63D0\u793A: \u7ECF\u4EE3\u7406\u67E5\u8BE2 GitHub \u5931\u8D25\uFF0C\u53EF\u68C0\u67E5\u4EE3\u7406\u662F\u5426\u53EF\u7528\uFF0C\u6216 mihomo kernel --mirror direct \u91CD\u8BD5\u76F4\u8FDE");
|
|
7535
7748
|
} else {
|
|
7536
7749
|
hint.push(
|
|
7537
7750
|
"",
|
|
7538
|
-
"\u63D0\u793A: \u76F4\u8FDE\u5931\u8D25\u6216\u4E0B\u8F7D\u8FC7\u6162\u65F6\u53EF\u4F7F\u7528\u955C\u50CF:",
|
|
7751
|
+
"\u63D0\u793A: \u76F4\u8FDE\u5931\u8D25\u6216\u4E0B\u8F7D\u8FC7\u6162\u65F6\u53EF\u4F7F\u7528\u955C\u50CF\u6216\u4EE3\u7406:",
|
|
7539
7752
|
" mihomo kernel --mirror [\u955C\u50CF] # \u5F3A\u5236\u8D70\u955C\u50CF\uFF08\u88F8 --mirror \u56FA\u5B9A\u88F8\u57DF\uFF0C\u53EF\u7528 v6/v4/cdn \u7B49\u522B\u540D\uFF09",
|
|
7540
|
-
` \u53EF\u7528\u955C\u50CF: ${AVAILABLE_MIRRORS.join(", ")}
|
|
7753
|
+
` \u53EF\u7528\u955C\u50CF: ${AVAILABLE_MIRRORS.join(", ")}`,
|
|
7754
|
+
" mihomo kernel --proxy <\u7AEF\u53E3> # \u7ECF\u672C\u673A\u5176\u4ED6\u4EE3\u7406\u5DE5\u5177\u51FA\u7F51"
|
|
7541
7755
|
);
|
|
7542
7756
|
}
|
|
7543
7757
|
}
|
|
@@ -7559,7 +7773,8 @@ async function cmdKernel(args) {
|
|
|
7559
7773
|
hint: [
|
|
7560
7774
|
"",
|
|
7561
7775
|
"\u4E0B\u8F7D\u901A\u9053\u6309\u4F18\u5148\u7EA7\u81EA\u52A8\u9009\u62E9: gh\uFF08GitHub CLI\uFF09> \u672C\u673A\u4EE3\u7406 > \u76F4\u8FDE",
|
|
7562
|
-
"\u624B\u52A8\u6307\u5B9A: mihomo kernel --mirror [\u955C\u50CF]\uFF08\u5F3A\u5236\u955C\u50CF\uFF09/ mihomo kernel --mirror direct\uFF08\u5F3A\u5236\u76F4\u8FDE\uFF09"
|
|
7776
|
+
"\u624B\u52A8\u6307\u5B9A: mihomo kernel --mirror [\u955C\u50CF]\uFF08\u5F3A\u5236\u955C\u50CF\uFF09/ mihomo kernel --mirror direct\uFF08\u5F3A\u5236\u76F4\u8FDE\uFF09",
|
|
7777
|
+
" mihomo kernel --proxy <\u7AEF\u53E3>\uFF08\u7ECF\u672C\u673A\u5176\u4ED6\u4EE3\u7406\u5DE5\u5177\u51FA\u7F51\uFF09"
|
|
7563
7778
|
]
|
|
7564
7779
|
});
|
|
7565
7780
|
}
|
|
@@ -7664,7 +7879,8 @@ function printOverwriteList() {
|
|
|
7664
7879
|
console.log(`${colors.cyan("\u8986\u5199\u6587\u4EF6")} (${countText}):`);
|
|
7665
7880
|
console.log("");
|
|
7666
7881
|
info.files.forEach((f, i) => {
|
|
7667
|
-
const
|
|
7882
|
+
const seq = i + 1;
|
|
7883
|
+
const num = seq < 10 ? ` ${seq}` : `${seq}`;
|
|
7668
7884
|
const mark = f.enabled ? "" : ` ${colors.yellow("[\u5DF2\u7981\u7528]")}`;
|
|
7669
7885
|
console.log(` ${num}. ${f.name}${mark}`);
|
|
7670
7886
|
if (f.scope) {
|
|
@@ -7677,7 +7893,8 @@ function printOverwriteList() {
|
|
|
7677
7893
|
if (info.broken.length > 0) {
|
|
7678
7894
|
console.log(colors.red(`\u52A0\u8F7D\u5931\u8D25 (${info.broken.length} \u4E2A\uFF0C\u672A\u53C2\u4E0E\u5408\u5E76\uFF1Bstart/doctor \u4F1A\u62A5\u9519):`));
|
|
7679
7895
|
info.broken.forEach((b, i) => {
|
|
7680
|
-
const
|
|
7896
|
+
const seq = info.files.length + i + 1;
|
|
7897
|
+
const num = seq < 10 ? ` ${seq}` : `${seq}`;
|
|
7681
7898
|
console.log(` ${num}. ${colors.red(b.name)} ${colors.red("[\u52A0\u8F7D\u5931\u8D25]")}`);
|
|
7682
7899
|
console.log(colors.red(` ${b.message}`));
|
|
7683
7900
|
});
|
|
@@ -7736,7 +7953,7 @@ async function cmdOverwrite(args) {
|
|
|
7736
7953
|
import fs13 from "fs";
|
|
7737
7954
|
|
|
7738
7955
|
// src/process-stop.ts
|
|
7739
|
-
import { spawnSync as
|
|
7956
|
+
import { spawnSync as spawnSync8 } from "child_process";
|
|
7740
7957
|
import fs12 from "fs";
|
|
7741
7958
|
var PROCESS_WAIT_ATTEMPTS = 50;
|
|
7742
7959
|
var PROCESS_WAIT_INTERVAL = 100;
|
|
@@ -7751,7 +7968,7 @@ function clearPid() {
|
|
|
7751
7968
|
if (!fs12.existsSync(PATHS.pidFile)) return;
|
|
7752
7969
|
if (isPidFileOwnedByRoot()) {
|
|
7753
7970
|
try {
|
|
7754
|
-
|
|
7971
|
+
spawnSync8("sudo", ["rm", "-f", PATHS.pidFile], { stdio: "inherit", timeout: 1e4 });
|
|
7755
7972
|
} catch {
|
|
7756
7973
|
}
|
|
7757
7974
|
} else {
|
|
@@ -7774,7 +7991,7 @@ function killAllMihomo(forceSudo = false) {
|
|
|
7774
7991
|
const argv = forceSudo ? ["sudo", ["pkill", "-9", "-f", pattern]] : ["pkill", ["-9", "-f", pattern]];
|
|
7775
7992
|
const options = forceSudo ? { stdio: "inherit", timeout: SUDO_TIMEOUT_MS } : { timeout: 1e4 };
|
|
7776
7993
|
try {
|
|
7777
|
-
const result =
|
|
7994
|
+
const result = spawnSync8(argv[0], argv[1], options);
|
|
7778
7995
|
if (result.error) return false;
|
|
7779
7996
|
return result.status === 0 || result.status === 1;
|
|
7780
7997
|
} catch {
|
|
@@ -8107,7 +8324,7 @@ async function cmdStop(args) {
|
|
|
8107
8324
|
}
|
|
8108
8325
|
|
|
8109
8326
|
// src/commands/subscription.ts
|
|
8110
|
-
import { spawnSync as
|
|
8327
|
+
import { spawnSync as spawnSync9 } from "child_process";
|
|
8111
8328
|
function printRestartHintIfRunning() {
|
|
8112
8329
|
const state = getRunningState();
|
|
8113
8330
|
if (state.running) {
|
|
@@ -8148,6 +8365,9 @@ function printSubscriptionList() {
|
|
|
8148
8365
|
console.log(` ${colors.gray("\u9875\u9762: ")}${s.web_page_url}`);
|
|
8149
8366
|
}
|
|
8150
8367
|
});
|
|
8368
|
+
if (subs.some((s) => s.updated_at == null) && subs.every((s) => formatTraffic(s.upload, s.download, s.total) === null)) {
|
|
8369
|
+
console.log(colors.gray("\u63D0\u793A: \u66F4\u65B0\u8BA2\u9605\u540E\u53EF\u663E\u793A\u6D41\u91CF\u4E0E\u5230\u671F\u4FE1\u606F\uFF08mihomo sub update\uFF1B\u673A\u573A\u4E0D\u4E0B\u53D1\u7528\u91CF\u6570\u636E\u5219\u65E0\u6B64\u4FE1\u606F\uFF09"));
|
|
8370
|
+
}
|
|
8151
8371
|
console.log("");
|
|
8152
8372
|
console.log("\u5207\u6362\u8BA2\u9605: mihomo sub use <name>");
|
|
8153
8373
|
console.log("\u65B0\u589E\u8BA2\u9605: mihomo sub add <url> [name]");
|
|
@@ -8166,7 +8386,7 @@ function assertNotFlagLike(name, usage) {
|
|
|
8166
8386
|
function readUrlFromClipboard() {
|
|
8167
8387
|
if (!process.stdin.isTTY) return null;
|
|
8168
8388
|
try {
|
|
8169
|
-
const r =
|
|
8389
|
+
const r = spawnSync9("pbpaste", [], { encoding: "utf8", timeout: 3e3 });
|
|
8170
8390
|
if (r.status !== 0) return null;
|
|
8171
8391
|
const text = (r.stdout || "").trim();
|
|
8172
8392
|
return isValidHttpUrl(text) ? text : null;
|
|
@@ -8355,7 +8575,7 @@ async function cmdSubscription(args) {
|
|
|
8355
8575
|
}
|
|
8356
8576
|
|
|
8357
8577
|
// src/commands/ui.ts
|
|
8358
|
-
import { spawnSync as
|
|
8578
|
+
import { spawnSync as spawnSync10 } from "child_process";
|
|
8359
8579
|
function resolveUiName(args) {
|
|
8360
8580
|
const raw = getNonFlagArg(args, 1);
|
|
8361
8581
|
const name = (raw ?? "zash").toLowerCase();
|
|
@@ -8366,7 +8586,7 @@ function resolveUiName(args) {
|
|
|
8366
8586
|
}
|
|
8367
8587
|
function copyToClipboard(text) {
|
|
8368
8588
|
try {
|
|
8369
|
-
return
|
|
8589
|
+
return spawnSync10("pbcopy", [], { input: text }).status === 0;
|
|
8370
8590
|
} catch {
|
|
8371
8591
|
return false;
|
|
8372
8592
|
}
|
|
@@ -8517,7 +8737,7 @@ var COMMANDS = [
|
|
|
8517
8737
|
aliases: [],
|
|
8518
8738
|
handler: cmdKernel,
|
|
8519
8739
|
group: "system",
|
|
8520
|
-
usage: [{ signature: "kernel [--mirror [\u955C\u50CF]]", description: "\u66F4\u65B0\u5185\u6838\uFF08\u81EA\u52A8\u9009\u62E9\u901A\u9053\uFF1Agh > \u672C\u673A\u4EE3\u7406 > \u76F4\u8FDE\uFF09" }]
|
|
8740
|
+
usage: [{ signature: "kernel [--mirror [\u955C\u50CF]] [--proxy <\u7AEF\u53E3|\u5730\u5740>]", description: "\u66F4\u65B0\u5185\u6838\uFF08\u81EA\u52A8\u9009\u62E9\u901A\u9053\uFF1Agh > \u672C\u673A\u4EE3\u7406 > \u76F4\u8FDE\uFF09" }]
|
|
8521
8741
|
},
|
|
8522
8742
|
{
|
|
8523
8743
|
name: "update",
|