mihomo-cli 26.10.106 → 26.10.107
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 +17 -9
- package/dist/index.js +228 -142
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [26.10.107] - 2026-10-04
|
|
4
|
+
|
|
5
|
+
### 修复
|
|
6
|
+
|
|
7
|
+
- **curl 代理通道不再被 no_proxy 例外表静默改写**:shell 里 export 过 `no_proxy='*'` 或含目标域条目时,curl 会绕过显式 `-x` 直连——版本查询、内核下载、连通性探测三处 spawn 统一置空 per-spawn env 的 no_proxy/NO_PROXY(`curl-spawn.ts` 唯一出口,新增加 curl 必须经此);direct 通道显式 `--noproxy '*'` 堵住另一类分叉——curl 默认读 `https_proxy` 等 env 代理,此前 `--mirror direct` 的「强制直连」实际会经 shell 代理出网,两条出网路径分叉、故障时还把原因误诊成直连被墙
|
|
8
|
+
- **订阅下载重定向逐跳校验 https**:改手动逐跳跟随、每一跳校验协议并设 20 跳上限,堵「先降 http 再跳回 https」的中间明文 hop——订阅 URL 的 token 常被服务器保留在重定向查询串里,旧守卫只看最终地址挡不住;错误消息对降级地址脱敏
|
|
9
|
+
- **启动 TUN 失败的恢复指引扩面**:关掉服务自启后任何一步失败(订阅校验/自动更新/配置构建/启动本身)都在错误里带「恢复 Mixed: `mihomo-cli start`」,此前只有启动失败分支带——只报「配置错误」会让用户以为一切照旧,下次开机才发现代理没回来
|
|
10
|
+
- **status/doctor 对坏状态容错**:手改 settings.json 写入非法订阅名不再击穿 status 整屏报错;doctor 内核版本检查失败带真实原因(「全部是预发行版」「未找到 curl」不再一律渲染成「GitHub 不可达」);start 成功后的系统代理提示撞上坏 ports 配置时降级默认端口提示,不再把成功命令翻成 exit 1
|
|
11
|
+
- **`sub remove` 删最后一个订阅保留运行中提示**:此前按「切换目标」判定会把提示整个吞掉;没有可切换的新订阅时提示改为「(订阅已全部删除),重新添加订阅后执行 mihomo-cli start tun」
|
|
12
|
+
- **`reset service` 补残留进程提示**:纯重置服务此前把卸载透传的残留进程丢弃、「已重置: 服务」成了谎报,现在与 uninstall 同款式黄字列出 PID
|
|
13
|
+
- **覆写键 `++key` 加载即报错**:`++rules`/`rules++` 这类笔误此前静默落成字面顶层键不生效(内核对未知键宽容),`++secret` 还绕过锁定键告警;与 `key!+` 同口径报「操作符位置矛盾」
|
|
14
|
+
- **其余并发与容错修正**:内核配置校验的临时 stage 迁出会被整目录删除的 runtime/(并发 stop/reset 曾把校验配置一起删掉,把误诊指向毫无问题的订阅/覆写);sudo 脚本名加 pid 后缀,双终端并发跑同一动作不再互踩「密码正确却报已取消」;启动过程中订阅被并发移除时给「已被移除」分档报错,不再指引必败的 `sub update <已删除名>`;热重载的控制器端口与密钥改同一份快照读取(settings 被原子替换时不再发新端口带旧密钥);`-h` 提示文案与实际命令级帮助行为对齐
|
|
15
|
+
|
|
16
|
+
### 变更(内部清理,无用户可见变化)
|
|
17
|
+
|
|
18
|
+
- **/simplify 三轮收尾**:`firstLine` 收编全仓 12 处 `split('\n')[0]` 副本;卸载/重置残留提示与 bootout 未装载容忍码(3/113)收单点(TS 判定与 legacy bash 脚本生成共用一份码表);控制器端口+密钥快照读收 `getControllerEndpoint`;CliError 再包装收 `relabelCliError`(exitCode 透传在结构上不可能丢);「桩 curl 记录 no_proxy」端到端夹具收 test-support 新模块(三份逐字骨架合一);http 手动跟随重定收单循环。960 用例全绿
|
|
19
|
+
|
|
3
20
|
## [26.10.106] - 2026-10-03
|
|
4
21
|
|
|
5
22
|
### 修复(覆写提示降噪)
|
|
@@ -199,12 +216,3 @@
|
|
|
199
216
|
|
|
200
217
|
- **内核下载本机代理优先、失败自动换通道**:`mihomo kernel` 在本机代理运行时默认经代理下载,失败自动回退 gh;全部失败时汇总各通道原因,并提示可在面板手动换节点。显式 `--mirror`/`--proxy` 仍严格按指定通道、不自动切换
|
|
201
218
|
- **劣质节点下载不再长时间干等**:节点握手延迟低但实际带宽极低时(实测约 20 KB/s),此前 gh 通道会卡满 210 秒;现代理通道在 20 秒内平均速度低于 50 KB/s 即快速失败,gh 通道超时也缩短到 100 秒。超时或低速失败给出可读原因,不再只显示「curl 退出码 28」
|
|
202
|
-
|
|
203
|
-
## [26.10.97] - 2026-10-01
|
|
204
|
-
|
|
205
|
-
### 修复
|
|
206
|
-
|
|
207
|
-
- **sudo 执行超时不再漏出内部错误串**:密码提示停留或脚本执行超过 60 秒时,此前用户看到的是 `spawnSync sudo ETIMEDOUT`,现改为超时提示并点明操作可能只完成了一部分
|
|
208
|
-
- **覆写 match 值加载期校验补齐**:`url-domain` 带协议、尾斜杠、端口、空格,或 `name` 精确值含非法字符时,文件会静默永不生效,现一律加载时报错;`rules!+`、`+~rules` 等操作符漏网形态同样拦下
|
|
209
|
-
- **帮助文案与实际行为对齐**:logs 用法行更正裸命令语义、version 用法不再内嵌别名、subscription use 补上自动重启说明;子命令名(如 `sub USE`)改为大小写不敏感
|
|
210
|
-
- **到期时间戳对非法值返回「未知」**:手工改坏缓存(非数字、负数、超出日期上限)时此前漏出字面 `Invalid Date` 或 1970 日期
|
package/dist/index.js
CHANGED
|
@@ -80,6 +80,9 @@ var CliError = class extends Error {
|
|
|
80
80
|
this.exitCode = options.exitCode ?? 1;
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
|
+
function relabelCliError(e, options) {
|
|
84
|
+
return new CliError(e.message, { label: options.label ?? e.label, hint: options.hint ?? e.hint, exitCode: e.exitCode });
|
|
85
|
+
}
|
|
83
86
|
function errorMessage(e) {
|
|
84
87
|
return e instanceof Error ? e.message : String(e);
|
|
85
88
|
}
|
|
@@ -291,7 +294,7 @@ function assertKnownFlags(args, known, command) {
|
|
|
291
294
|
const match = matchValueFlagToken(a);
|
|
292
295
|
if (match && match.form !== "exact" && knownSet.has(match.baseForm)) continue;
|
|
293
296
|
const isHelpFlag = a === "-h" || a === "--help";
|
|
294
|
-
const helpNote = isHelpFlag ? ["", `${a} \
|
|
297
|
+
const helpNote = isHelpFlag ? ["", `${a} \u8981\u7D27\u8DDF\u547D\u4EE4\u540D\u624D\u663E\u793A\u8BE5\u547D\u4EE4\u7684\u5E2E\u52A9\uFF08\u4F8B: mihomo-cli start ${a}\uFF09\uFF1B\u7EFC\u5408\u5E2E\u52A9: mihomo-cli help`] : [];
|
|
295
298
|
const hasValueFlag = known.some((f) => VALUE_FLAGS.has(f));
|
|
296
299
|
const looksLikeName = a.length > 2 && !a.startsWith("--") && !hasValueFlag;
|
|
297
300
|
const nameNote = looksLikeName ? ["", `\u82E5\u8FD9\u662F\u5728\u586B\u5199\u540D\u79F0\uFF1A\u540D\u79F0\u4E0D\u80FD\u4EE5 \`-\` \u5F00\u5934\uFF08argv \u4F1A\u628A\u5B83\u5F53\u9009\u9879\u62E6\u622A\uFF09\uFF0C\u8BF7\u53BB\u6389\u524D\u5BFC \`-\``] : [];
|
|
@@ -3600,7 +3603,7 @@ function cleanupStaleTmpFiles() {
|
|
|
3600
3603
|
for (const entry of entries) {
|
|
3601
3604
|
const isAtomicTmpFile = entry.endsWith(".tmp");
|
|
3602
3605
|
const isKernelTmpDir = dir === DIRS.kernel && entry.startsWith(".tmp-");
|
|
3603
|
-
const isConfigCheckTmpDir = dir ===
|
|
3606
|
+
const isConfigCheckTmpDir = dir === USER_DATA_DIR && entry.startsWith("check-");
|
|
3604
3607
|
const isPlistStage = dir === USER_DATA_DIR && entry === "service.plist.stage";
|
|
3605
3608
|
if (!isAtomicTmpFile && !isKernelTmpDir && !isConfigCheckTmpDir && !isPlistStage) continue;
|
|
3606
3609
|
const full = path.join(dir, entry);
|
|
@@ -3760,13 +3763,18 @@ function getPorts(settings = readSettings()) {
|
|
|
3760
3763
|
}
|
|
3761
3764
|
return { mixed, controller };
|
|
3762
3765
|
}
|
|
3763
|
-
function getPortsOrNull() {
|
|
3766
|
+
function getPortsOrNull(settings = readSettings()) {
|
|
3764
3767
|
try {
|
|
3765
|
-
return getPorts();
|
|
3768
|
+
return getPorts(settings);
|
|
3766
3769
|
} catch {
|
|
3767
3770
|
return null;
|
|
3768
3771
|
}
|
|
3769
3772
|
}
|
|
3773
|
+
function getControllerEndpoint(settings = readSettings()) {
|
|
3774
|
+
const port = getPortsOrNull(settings)?.controller ?? null;
|
|
3775
|
+
const secret = settings.controller_secret;
|
|
3776
|
+
return { port, secret: typeof secret === "string" && secret ? secret : null };
|
|
3777
|
+
}
|
|
3770
3778
|
function readSubscriptionCache() {
|
|
3771
3779
|
ensureDirs();
|
|
3772
3780
|
const empty = () => /* @__PURE__ */ Object.create(null);
|
|
@@ -3862,6 +3870,7 @@ function addSubscription(url, name = "default") {
|
|
|
3862
3870
|
function removeSubscription(name) {
|
|
3863
3871
|
let switchedTo = null;
|
|
3864
3872
|
let found = false;
|
|
3873
|
+
let wasActive = false;
|
|
3865
3874
|
updateSettings(
|
|
3866
3875
|
(settings) => {
|
|
3867
3876
|
const subs = getSubscriptions(settings);
|
|
@@ -3871,6 +3880,7 @@ function removeSubscription(name) {
|
|
|
3871
3880
|
subs.splice(idx, 1);
|
|
3872
3881
|
const updates = { subscriptions: subs };
|
|
3873
3882
|
if (settings.active_subscription === name) {
|
|
3883
|
+
wasActive = true;
|
|
3874
3884
|
switchedTo = subs.length > 0 ? subs[0].name : null;
|
|
3875
3885
|
updates.active_subscription = switchedTo ?? void 0;
|
|
3876
3886
|
}
|
|
@@ -3883,9 +3893,9 @@ function removeSubscription(name) {
|
|
|
3883
3893
|
}
|
|
3884
3894
|
}
|
|
3885
3895
|
);
|
|
3886
|
-
if (!found) return { found: false, switchedTo: null };
|
|
3896
|
+
if (!found) return { found: false, switchedTo: null, wasActive: false };
|
|
3887
3897
|
deleteSubscriptionCache(name);
|
|
3888
|
-
return { found: true, switchedTo };
|
|
3898
|
+
return { found: true, switchedTo, wasActive };
|
|
3889
3899
|
}
|
|
3890
3900
|
function setDefaultSubscription(name) {
|
|
3891
3901
|
let found = false;
|
|
@@ -3912,8 +3922,13 @@ function removeSubscriptionRawConfig(subName) {
|
|
|
3912
3922
|
}
|
|
3913
3923
|
function readSubscriptionRawConfig(subName) {
|
|
3914
3924
|
const filePath = getSubscriptionRawConfigPath(subName);
|
|
3915
|
-
|
|
3916
|
-
|
|
3925
|
+
try {
|
|
3926
|
+
return fs2.readFileSync(filePath, "utf8");
|
|
3927
|
+
} catch (e) {
|
|
3928
|
+
const code = e.code;
|
|
3929
|
+
if (code === "ENOENT" || code === "EISDIR") return null;
|
|
3930
|
+
throw e;
|
|
3931
|
+
}
|
|
3917
3932
|
}
|
|
3918
3933
|
function requireSubscriptionRawConfig(subName) {
|
|
3919
3934
|
const content = readSubscriptionRawConfig(subName);
|
|
@@ -3923,6 +3938,66 @@ function requireSubscriptionRawConfig(subName) {
|
|
|
3923
3938
|
return content;
|
|
3924
3939
|
}
|
|
3925
3940
|
|
|
3941
|
+
// src/text.ts
|
|
3942
|
+
function escapeRegExp(s) {
|
|
3943
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3944
|
+
}
|
|
3945
|
+
function shellQuote(s) {
|
|
3946
|
+
return `'${s.replace(/'/g, "'\\''")}'`;
|
|
3947
|
+
}
|
|
3948
|
+
function firstLine(text) {
|
|
3949
|
+
return text.split("\n")[0];
|
|
3950
|
+
}
|
|
3951
|
+
function sanitizeTerminal(s) {
|
|
3952
|
+
const ansiEscape = /\x1b\[[0-9;]*[a-zA-Z]/g;
|
|
3953
|
+
const controlChars = /[\x00-\x08\x0b\x0c\x0d\x0e-\x1f]/g;
|
|
3954
|
+
return s.replace(ansiEscape, "").replace(controlChars, "");
|
|
3955
|
+
}
|
|
3956
|
+
function lastCurlErrorLine(stderr) {
|
|
3957
|
+
const text = typeof stderr === "string" || Buffer.isBuffer(stderr) ? stderr.toString().trim() : "";
|
|
3958
|
+
const lastLine = text ? text.split("\n").pop() : void 0;
|
|
3959
|
+
return lastLine ? lastLine.replace(/^curl: \(\d+\)\s*/, "") : void 0;
|
|
3960
|
+
}
|
|
3961
|
+
var TOKEN_KEY_NAMES = [
|
|
3962
|
+
"token",
|
|
3963
|
+
"key",
|
|
3964
|
+
"secret",
|
|
3965
|
+
"pass",
|
|
3966
|
+
"password",
|
|
3967
|
+
"auth",
|
|
3968
|
+
"access_token",
|
|
3969
|
+
"api_key",
|
|
3970
|
+
"uuid",
|
|
3971
|
+
"sid",
|
|
3972
|
+
"id",
|
|
3973
|
+
"sub",
|
|
3974
|
+
"user",
|
|
3975
|
+
"email",
|
|
3976
|
+
"passwd",
|
|
3977
|
+
"apikey",
|
|
3978
|
+
"access"
|
|
3979
|
+
];
|
|
3980
|
+
var TOKEN_KEYS = new Set(TOKEN_KEY_NAMES);
|
|
3981
|
+
function maskUrl(url) {
|
|
3982
|
+
try {
|
|
3983
|
+
const parsed = new URL(url);
|
|
3984
|
+
for (const [key, value] of parsed.searchParams) {
|
|
3985
|
+
if (TOKEN_KEYS.has(key.toLowerCase()) || value.length >= 16) {
|
|
3986
|
+
parsed.searchParams.set(key, "***");
|
|
3987
|
+
}
|
|
3988
|
+
}
|
|
3989
|
+
if (parsed.username) parsed.username = "***";
|
|
3990
|
+
if (parsed.password) parsed.password = "***";
|
|
3991
|
+
parsed.pathname = parsed.pathname.split("/").map((seg) => seg.length >= 16 ? `${seg.slice(0, 4)}***${seg.slice(-4)}` : seg).join("/");
|
|
3992
|
+
return parsed.toString();
|
|
3993
|
+
} catch {
|
|
3994
|
+
if (url.length > 15) {
|
|
3995
|
+
return `${url.slice(0, 15)}...`;
|
|
3996
|
+
}
|
|
3997
|
+
return url;
|
|
3998
|
+
}
|
|
3999
|
+
}
|
|
4000
|
+
|
|
3926
4001
|
// src/overwrite.ts
|
|
3927
4002
|
function parseOverrideKey(key) {
|
|
3928
4003
|
let actualKey = key;
|
|
@@ -3980,6 +4055,12 @@ function assertValidParsedKey(rawKey, parsed) {
|
|
|
3980
4055
|
hint: ["\u6574\u4F53\u8986\u76D6\u7684 ! \u53EA\u80FD\u5199\u5728\u952E\u540D\u672B\u5C3E\u3001\u4E14\u4E0D\u80FD\u4E0E\u5176\u4ED6\u64CD\u4F5C\u7B26\u540C\u7528\uFF08key!\uFF09\u3002", "\u60F3\u5411\u6570\u7EC4\u8FFD\u52A0\u8BF7\u53EA\u7528 key+\u3002"]
|
|
3981
4056
|
});
|
|
3982
4057
|
}
|
|
4058
|
+
if (parsed.key.includes("+")) {
|
|
4059
|
+
throw new CliError(`\u8986\u5199\u952E "${rawKey}" \u7684\u64CD\u4F5C\u7B26\u4F4D\u7F6E\u77DB\u76FE`, {
|
|
4060
|
+
label: "\u8986\u5199\u914D\u7F6E\u9519\u8BEF",
|
|
4061
|
+
hint: ["\u6570\u7EC4\u524D\u63D2/\u8FFD\u52A0\u5404\u53EA\u6709\u4E00\u4E2A +\uFF08+key \u6216 key+\uFF09\uFF0C\u952E\u540D\u91CC\u4E0D\u80FD\u542B +\u3002"]
|
|
4062
|
+
});
|
|
4063
|
+
}
|
|
3983
4064
|
const ops = [];
|
|
3984
4065
|
if (parsed.forceOverwrite) ops.push("!\uFF08\u6574\u4F53\u8986\u76D6\uFF09");
|
|
3985
4066
|
if (parsed.arrayPrepend) ops.push("+\u524D\u7F00\uFF08\u6570\u7EC4\u524D\u63D2\uFF09");
|
|
@@ -4319,7 +4400,7 @@ function loadOverwriteScript(filePath, fileName) {
|
|
|
4319
4400
|
try {
|
|
4320
4401
|
mod = createRequire2(filePath)(filePath);
|
|
4321
4402
|
} catch (e) {
|
|
4322
|
-
throw new CliError(`\u8986\u5199\u811A\u672C "${fileName}" \u52A0\u8F7D\u5931\u8D25: ${e.message
|
|
4403
|
+
throw new CliError(`\u8986\u5199\u811A\u672C "${fileName}" \u52A0\u8F7D\u5931\u8D25: ${firstLine(e.message ?? String(e))}`, {
|
|
4323
4404
|
label: "\u8986\u5199\u914D\u7F6E\u9519\u8BEF",
|
|
4324
4405
|
hint: ["\u8BE5\u811A\u672C\u5F53\u524D\u672A\u53C2\u4E0E\u5408\u5E76\u3002\u5E38\u89C1\u539F\u56E0\uFF1A\u8BED\u6CD5\u9519\u8BEF\u3001import/require \u4E86\u4E0D\u5B58\u5728\u7684\u6A21\u5757\u3001\u6216\u4F7F\u7528\u4E86 top-level await\uFF08\u811A\u672C\u5FC5\u987B\u53EF\u540C\u6B65\u52A0\u8F7D\uFF09\u3002"]
|
|
4325
4406
|
});
|
|
@@ -4425,7 +4506,7 @@ function applyOverwrite(baseConfig, files, opts) {
|
|
|
4425
4506
|
try {
|
|
4426
4507
|
returned = file.transform(result, ctx);
|
|
4427
4508
|
} catch (e) {
|
|
4428
|
-
throw new CliError(`\u8986\u5199\u811A\u672C "${file.name}" \u6267\u884C\u5931\u8D25: ${e.message
|
|
4509
|
+
throw new CliError(`\u8986\u5199\u811A\u672C "${file.name}" \u6267\u884C\u5931\u8D25: ${firstLine(e.message ?? String(e))}`, {
|
|
4429
4510
|
label: "\u8986\u5199\u914D\u7F6E\u9519\u8BEF",
|
|
4430
4511
|
hint: ["\u672C\u6B21\u6784\u5EFA\u5DF2\u4E2D\u6B62\uFF1B\u4FEE\u590D\u811A\u672C\u540E\u91CD\u8BD5\uFF08mihomo-cli ow \u53EF\u67E5\u770B\u5168\u90E8\u8986\u5199\u6587\u4EF6\u4E0E\u811A\u672C\uFF09\u3002"]
|
|
4431
4512
|
});
|
|
@@ -4465,63 +4546,6 @@ function listOverwriteFile(scope) {
|
|
|
4465
4546
|
};
|
|
4466
4547
|
}
|
|
4467
4548
|
|
|
4468
|
-
// src/text.ts
|
|
4469
|
-
function escapeRegExp(s) {
|
|
4470
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4471
|
-
}
|
|
4472
|
-
function shellQuote(s) {
|
|
4473
|
-
return `'${s.replace(/'/g, "'\\''")}'`;
|
|
4474
|
-
}
|
|
4475
|
-
function sanitizeTerminal(s) {
|
|
4476
|
-
const ansiEscape = /\x1b\[[0-9;]*[a-zA-Z]/g;
|
|
4477
|
-
const controlChars = /[\x00-\x08\x0b\x0c\x0d\x0e-\x1f]/g;
|
|
4478
|
-
return s.replace(ansiEscape, "").replace(controlChars, "");
|
|
4479
|
-
}
|
|
4480
|
-
function lastCurlErrorLine(stderr) {
|
|
4481
|
-
const text = typeof stderr === "string" || Buffer.isBuffer(stderr) ? stderr.toString().trim() : "";
|
|
4482
|
-
const lastLine = text ? text.split("\n").pop() : void 0;
|
|
4483
|
-
return lastLine ? lastLine.replace(/^curl: \(\d+\)\s*/, "") : void 0;
|
|
4484
|
-
}
|
|
4485
|
-
var TOKEN_KEY_NAMES = [
|
|
4486
|
-
"token",
|
|
4487
|
-
"key",
|
|
4488
|
-
"secret",
|
|
4489
|
-
"pass",
|
|
4490
|
-
"password",
|
|
4491
|
-
"auth",
|
|
4492
|
-
"access_token",
|
|
4493
|
-
"api_key",
|
|
4494
|
-
"uuid",
|
|
4495
|
-
"sid",
|
|
4496
|
-
"id",
|
|
4497
|
-
"sub",
|
|
4498
|
-
"user",
|
|
4499
|
-
"email",
|
|
4500
|
-
"passwd",
|
|
4501
|
-
"apikey",
|
|
4502
|
-
"access"
|
|
4503
|
-
];
|
|
4504
|
-
var TOKEN_KEYS = new Set(TOKEN_KEY_NAMES);
|
|
4505
|
-
function maskUrl(url) {
|
|
4506
|
-
try {
|
|
4507
|
-
const parsed = new URL(url);
|
|
4508
|
-
for (const [key, value] of parsed.searchParams) {
|
|
4509
|
-
if (TOKEN_KEYS.has(key.toLowerCase()) || value.length >= 16) {
|
|
4510
|
-
parsed.searchParams.set(key, "***");
|
|
4511
|
-
}
|
|
4512
|
-
}
|
|
4513
|
-
if (parsed.username) parsed.username = "***";
|
|
4514
|
-
if (parsed.password) parsed.password = "***";
|
|
4515
|
-
parsed.pathname = parsed.pathname.split("/").map((seg) => seg.length >= 16 ? `${seg.slice(0, 4)}***${seg.slice(-4)}` : seg).join("/");
|
|
4516
|
-
return parsed.toString();
|
|
4517
|
-
} catch {
|
|
4518
|
-
if (url.length > 15) {
|
|
4519
|
-
return `${url.slice(0, 15)}...`;
|
|
4520
|
-
}
|
|
4521
|
-
return url;
|
|
4522
|
-
}
|
|
4523
|
-
}
|
|
4524
|
-
|
|
4525
4549
|
// src/config.ts
|
|
4526
4550
|
var SAFE_YAML_LOAD_OPTIONS = { maxAliases: YAML_MAX_ALIASES };
|
|
4527
4551
|
function loadYamlSafe(content) {
|
|
@@ -4536,7 +4560,7 @@ function parseConfigContent(content, errorMsg) {
|
|
|
4536
4560
|
try {
|
|
4537
4561
|
result = loadYamlSafe(content);
|
|
4538
4562
|
} catch (e) {
|
|
4539
|
-
throw new CliError(`${label}\u683C\u5F0F\u9519\u8BEF\uFF0C\u65E0\u6CD5\u89E3\u6790: ${e.message
|
|
4563
|
+
throw new CliError(`${label}\u683C\u5F0F\u9519\u8BEF\uFF0C\u65E0\u6CD5\u89E3\u6790: ${firstLine(e.message)}`, { label: "\u914D\u7F6E\u9519\u8BEF" });
|
|
4540
4564
|
}
|
|
4541
4565
|
if (result == null || typeof result !== "object" || Array.isArray(result)) {
|
|
4542
4566
|
throw new CliError(`${label}\u4E0D\u662F\u6709\u6548\u7684\u914D\u7F6E\u5BF9\u8C61\uFF08\u9876\u5C42\u9700\u4E3A\u6620\u5C04\uFF0C\u5F53\u524D\u662F${Array.isArray(result) ? "\u5217\u8868" : typeof result}\uFF09`, { label: "\u914D\u7F6E\u9519\u8BEF" });
|
|
@@ -4704,7 +4728,7 @@ function judgeScriptMatches(subRawContent, mode, scope, entries) {
|
|
|
4704
4728
|
});
|
|
4705
4729
|
return { matches: scriptMatches };
|
|
4706
4730
|
} catch (e) {
|
|
4707
|
-
return { matches: [], error: e.message
|
|
4731
|
+
return { matches: [], error: firstLine(e.message ?? String(e)) };
|
|
4708
4732
|
}
|
|
4709
4733
|
}
|
|
4710
4734
|
function deriveRuntimeMode(info) {
|
|
@@ -4749,7 +4773,7 @@ function buildKernelRejectHint(detail, overwriteSummaries, opts = {}) {
|
|
|
4749
4773
|
async function validateConfigWithKernel(config, overwriteSummaries) {
|
|
4750
4774
|
assertKernelInstalled();
|
|
4751
4775
|
ensureDirs();
|
|
4752
|
-
const stageDir = fs4.mkdtempSync(path4.join(
|
|
4776
|
+
const stageDir = fs4.mkdtempSync(path4.join(USER_DATA_DIR, "check-"));
|
|
4753
4777
|
const stageFile = path4.join(stageDir, "config.yaml");
|
|
4754
4778
|
try {
|
|
4755
4779
|
fs4.writeFileSync(stageFile, dumpYaml(config), { mode: 384 });
|
|
@@ -4817,7 +4841,7 @@ function getKernelVersion(probe) {
|
|
|
4817
4841
|
try {
|
|
4818
4842
|
const p = probe ?? probeKernelVersion();
|
|
4819
4843
|
if (!p.output) return "unknown";
|
|
4820
|
-
return p.version ?? p.output
|
|
4844
|
+
return p.version ?? firstLine(p.output);
|
|
4821
4845
|
} catch {
|
|
4822
4846
|
return "unknown";
|
|
4823
4847
|
}
|
|
@@ -4964,6 +4988,10 @@ function parseDisabledList(output, label) {
|
|
|
4964
4988
|
return value === "true" || value === "disabled";
|
|
4965
4989
|
}
|
|
4966
4990
|
var LAUNCHCTL_NOT_LOADED = 113;
|
|
4991
|
+
var BOOTOUT_NOT_LOADED_CODES = [3, LAUNCHCTL_NOT_LOADED];
|
|
4992
|
+
function isBootoutNotLoaded(status) {
|
|
4993
|
+
return status !== null && BOOTOUT_NOT_LOADED_CODES.includes(status);
|
|
4994
|
+
}
|
|
4967
4995
|
function runLaunchctl(args, timeoutMs = LAUNCHCTL_TIMEOUT_MS) {
|
|
4968
4996
|
try {
|
|
4969
4997
|
const result = spawnSync2("launchctl", args, { encoding: "utf8", timeout: timeoutMs });
|
|
@@ -5058,6 +5086,14 @@ async function waitUntilUnloaded(target = serviceTarget()) {
|
|
|
5058
5086
|
import { execFile as execFile2, spawnSync as spawnSync4 } from "child_process";
|
|
5059
5087
|
import { promisify as promisify2 } from "util";
|
|
5060
5088
|
|
|
5089
|
+
// src/curl-spawn.ts
|
|
5090
|
+
function buildCurlSpawnEnv() {
|
|
5091
|
+
const env = { ...process.env };
|
|
5092
|
+
env.no_proxy = "";
|
|
5093
|
+
env.NO_PROXY = "";
|
|
5094
|
+
return env;
|
|
5095
|
+
}
|
|
5096
|
+
|
|
5061
5097
|
// src/process-probe.ts
|
|
5062
5098
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
5063
5099
|
import fs6 from "fs";
|
|
@@ -5172,7 +5208,11 @@ async function probeProxyConnectivity(port) {
|
|
|
5172
5208
|
const { stdout } = await execFileAsync(
|
|
5173
5209
|
"curl",
|
|
5174
5210
|
["-x", `http://127.0.0.1:${port}`, "-s", "-o", "/dev/null", "-w", "%{http_code}", "--max-time", String(Math.ceil(PROBE_TIMEOUT_MS / 1e3)), PROBE_URL],
|
|
5175
|
-
{
|
|
5211
|
+
{
|
|
5212
|
+
timeout: PROBE_TIMEOUT_MS + 2e3,
|
|
5213
|
+
// 例外表会绕过显式 -x、让探测考成直连(绿灯作废),置空兜住统一走 curl-spawn.ts 出口
|
|
5214
|
+
env: buildCurlSpawnEnv()
|
|
5215
|
+
}
|
|
5176
5216
|
);
|
|
5177
5217
|
const code = Number.parseInt(stdout.trim(), 10);
|
|
5178
5218
|
const statusCode = Number.isFinite(code) ? code : null;
|
|
@@ -5240,18 +5280,18 @@ async function tryHotReload(prefetched) {
|
|
|
5240
5280
|
try {
|
|
5241
5281
|
const status = prefetched ?? getServiceStatus({ withDisabled: false });
|
|
5242
5282
|
if (!status.running || status.pid === null) return false;
|
|
5243
|
-
const
|
|
5244
|
-
|
|
5245
|
-
const
|
|
5283
|
+
const endpoint = getControllerEndpoint();
|
|
5284
|
+
if (endpoint.port === null) return false;
|
|
5285
|
+
const baseUrl = `http://127.0.0.1:${endpoint.port}`;
|
|
5246
5286
|
const headers = { "Content-Type": "application/json" };
|
|
5247
|
-
if (
|
|
5287
|
+
if (endpoint.secret) headers.Authorization = `Bearer ${endpoint.secret}`;
|
|
5248
5288
|
const timer = setTimeout(() => controller.abort(), HOT_RELOAD_TIMEOUT_MS);
|
|
5249
5289
|
try {
|
|
5250
5290
|
const probe = await fetch(`${baseUrl}/version`, { headers, signal: controller.signal });
|
|
5251
5291
|
if (!probe.ok) return false;
|
|
5252
5292
|
const info = await probe.json();
|
|
5253
5293
|
if (typeof info?.version !== "string") return false;
|
|
5254
|
-
const listenerPids = lsofListenPids(
|
|
5294
|
+
const listenerPids = lsofListenPids(endpoint.port);
|
|
5255
5295
|
if (listenerPids === null || listenerPids[0] !== status.pid) return false;
|
|
5256
5296
|
const res = await fetch(`${baseUrl}/configs?force=true`, {
|
|
5257
5297
|
method: "PUT",
|
|
@@ -5306,7 +5346,7 @@ function runSudoScript(scriptBody, opts) {
|
|
|
5306
5346
|
throw new Error("\u5F53\u524D\u73AF\u5883\u65E0\u6CD5\u8F93\u5165\u7BA1\u7406\u5458\u5BC6\u7801\uFF08\u9700\u8981\u5728\u4EA4\u4E92\u5F0F\u7EC8\u7AEF\u8FD0\u884C sudo\uFF09");
|
|
5307
5347
|
}
|
|
5308
5348
|
ensureDirs();
|
|
5309
|
-
const scriptPath = path5.join(USER_DATA_DIR, opts.file);
|
|
5349
|
+
const scriptPath = path5.join(USER_DATA_DIR, `${opts.file}.${process.pid}.tmp`);
|
|
5310
5350
|
fs9.writeFileSync(scriptPath, scriptBody, { mode: 448 });
|
|
5311
5351
|
fs9.chmodSync(scriptPath, 448);
|
|
5312
5352
|
try {
|
|
@@ -5338,6 +5378,10 @@ function describePidCleanupFailure(err) {
|
|
|
5338
5378
|
return `pid \u6587\u4EF6\u672A\u80FD\u6E05\u7406\uFF08${err.message}\uFF09`;
|
|
5339
5379
|
}
|
|
5340
5380
|
var MANUAL_PKILL_HINT = "\u624B\u52A8\u6E05\u7406: sudo pkill -9 mihomo";
|
|
5381
|
+
function printResidueWarning(remaining) {
|
|
5382
|
+
console.log(colors.yellow(`\u4ECD\u6709\u5185\u6838\u8FDB\u7A0B\u6B8B\u7559 (PID ${remaining.join(", ")})`));
|
|
5383
|
+
console.log(MANUAL_PKILL_HINT);
|
|
5384
|
+
}
|
|
5341
5385
|
function warnPidCleanupFailed(err) {
|
|
5342
5386
|
if (!err) return;
|
|
5343
5387
|
console.warn(colors.yellow(`\u8B66\u544A: ${describePidCleanupFailure(err)}\uFF0C\u4E0B\u6B21 stop \u4F1A\u518D\u6B21\u5C1D\u8BD5`));
|
|
@@ -5507,13 +5551,14 @@ async function cleanupKernelsOrThrow(ctx) {
|
|
|
5507
5551
|
return result;
|
|
5508
5552
|
}
|
|
5509
5553
|
function buildLegacyCleanupScript() {
|
|
5554
|
+
const toleratedBootoutCodes = [0, ...BOOTOUT_NOT_LOADED_CODES].map((code) => `[ $bootout_code -ne ${code} ]`).join(" && ");
|
|
5510
5555
|
return [
|
|
5511
5556
|
"#!/bin/bash",
|
|
5512
|
-
// bootout 退出码分级:113=未装载(daemon
|
|
5513
|
-
//
|
|
5557
|
+
// bootout 退出码分级:0=成功,3/113=未装载(daemon 已不在,正常);其余是真实
|
|
5558
|
+
// 失败,不能 || true 吞掉后照样 rm plist 报「已清理」
|
|
5514
5559
|
`bootout_code=0`,
|
|
5515
5560
|
`launchctl bootout ${shellQuote(`system/${SERVICE_LABEL}`)} 2>/dev/null || bootout_code=$?`,
|
|
5516
|
-
`if
|
|
5561
|
+
`if ${toleratedBootoutCodes}; then`,
|
|
5517
5562
|
` echo "launchctl bootout \u5931\u8D25\uFF08\u9000\u51FA\u7801 $bootout_code\uFF09" >&2`,
|
|
5518
5563
|
` exit 3`,
|
|
5519
5564
|
`fi`,
|
|
@@ -5822,7 +5867,7 @@ function bootstrapServiceIdempotentOrThrow(what) {
|
|
|
5822
5867
|
}
|
|
5823
5868
|
function bootoutService(timeoutMs = LAUNCHCTL_TIMEOUT_MS) {
|
|
5824
5869
|
const result = runLaunchctl(["bootout", serviceTarget()], timeoutMs);
|
|
5825
|
-
if (result.status === 0 || result.status
|
|
5870
|
+
if (result.status === 0 || isBootoutNotLoaded(result.status)) return;
|
|
5826
5871
|
const detail = result.stderr.trim();
|
|
5827
5872
|
throw new CliError(`\u5378\u8F7D\u65E7\u670D\u52A1\u5B9E\u4F8B\u5931\u8D25\uFF08launchctl bootout \u9000\u51FA\u7801 ${result.status ?? "\u6267\u884C\u5931\u8D25"}\uFF09`, {
|
|
5828
5873
|
hint: [detail, `\u624B\u52A8\u786E\u8BA4: launchctl print ${serviceTarget()}`].filter(Boolean)
|
|
@@ -6163,6 +6208,8 @@ function redactConfigSecrets(config) {
|
|
|
6163
6208
|
|
|
6164
6209
|
// src/http.ts
|
|
6165
6210
|
var MAX_RESPONSE_BYTES = 50 * 1024 * 1024;
|
|
6211
|
+
var MAX_REDIRECTS = 20;
|
|
6212
|
+
var REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
6166
6213
|
var MAX_ERROR_BODY_BYTES = 64 * 1024;
|
|
6167
6214
|
function isHttpsUrl(url) {
|
|
6168
6215
|
try {
|
|
@@ -6188,12 +6235,26 @@ function createHttpClient(options = {}) {
|
|
|
6188
6235
|
const timer = setTimeout(() => controller.abort(), timeout);
|
|
6189
6236
|
const signal = config?.signal ? AbortSignal.any([controller.signal, config.signal]) : controller.signal;
|
|
6190
6237
|
try {
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6238
|
+
let currentUrl = url;
|
|
6239
|
+
let response;
|
|
6240
|
+
for (let hop = 0; ; hop++) {
|
|
6241
|
+
response = await fetch(currentUrl, {
|
|
6242
|
+
signal,
|
|
6243
|
+
redirect: "manual",
|
|
6244
|
+
headers: { "User-Agent": `mihomo-cli/${VERSION}` }
|
|
6245
|
+
});
|
|
6246
|
+
if (!REDIRECT_STATUSES.has(response.status)) break;
|
|
6247
|
+
if (hop >= MAX_REDIRECTS) {
|
|
6248
|
+
throw new Error(`\u91CD\u5B9A\u5411\u6B21\u6570\u8D85\u8FC7 ${MAX_REDIRECTS}\uFF0C\u5DF2\u4E2D\u6B62: ${maskUrl(url)}`);
|
|
6249
|
+
}
|
|
6250
|
+
const location = response.headers.get("location");
|
|
6251
|
+
if (!location) break;
|
|
6252
|
+
const nextUrl = new URL(location, currentUrl).toString();
|
|
6253
|
+
if (isHttpsUrl(url) && !isHttpsUrl(nextUrl)) {
|
|
6254
|
+
throw new Error(`\u8BF7\u6C42\u88AB\u91CD\u5B9A\u5411\u5230\u975E https \u5730\u5740\uFF08${maskUrl(nextUrl)}\uFF09\uFF0C\u5DF2\u62D2\u7EDD`);
|
|
6255
|
+
}
|
|
6256
|
+
await response.body?.cancel().catch(() => void 0);
|
|
6257
|
+
currentUrl = nextUrl;
|
|
6197
6258
|
}
|
|
6198
6259
|
if (!response.ok) {
|
|
6199
6260
|
let text2 = "";
|
|
@@ -6457,7 +6518,17 @@ async function downloadSubscription(url, subName = "default", signal) {
|
|
|
6457
6518
|
return { proxies, proxyGroups };
|
|
6458
6519
|
}
|
|
6459
6520
|
async function prepareConfigForStart(mode, subName = "default") {
|
|
6460
|
-
|
|
6521
|
+
let rawContent;
|
|
6522
|
+
try {
|
|
6523
|
+
rawContent = requireSubscriptionRawConfig(subName);
|
|
6524
|
+
} catch (e) {
|
|
6525
|
+
if (e instanceof CliError && !getSubscriptions().some((s) => s.name === subName)) {
|
|
6526
|
+
throw new CliError(`\u8BA2\u9605 "${subName}" \u5DF2\u5728\u542F\u52A8\u8FC7\u7A0B\u4E2D\u88AB\u79FB\u9664\uFF08\u53EF\u80FD\u53E6\u4E00\u7EC8\u7AEF\u6267\u884C\u4E86 sub remove/reset\uFF09`, {
|
|
6527
|
+
hint: ["\u67E5\u770B\u5F53\u524D\u5217\u8868: mihomo-cli sub", "\u786E\u8BA4\u540E\u91CD\u8BD5: mihomo-cli start"]
|
|
6528
|
+
});
|
|
6529
|
+
}
|
|
6530
|
+
throw e;
|
|
6531
|
+
}
|
|
6461
6532
|
const subUrl = getSubscriptions().find((s) => s.name === subName)?.url;
|
|
6462
6533
|
const buildResult = buildConfig(rawContent, mode, { subName, subUrl });
|
|
6463
6534
|
await validateConfigWithKernel(buildResult.config, buildResult.overwriteSummaries);
|
|
@@ -6500,7 +6571,7 @@ function printUpdateResult(r) {
|
|
|
6500
6571
|
} else if (r.aborted) {
|
|
6501
6572
|
console.log(`${colors.gray("\xB7")} ${r.name}: ${colors.gray("\u8DF3\u8FC7\uFF08\u66F4\u65B0\u8D85\u65F6\uFF0C\u4F7F\u7528\u672C\u5730\u7F13\u5B58\uFF09")}`);
|
|
6502
6573
|
} else {
|
|
6503
|
-
console.log(`${colors.red("\u2717")} ${r.name}: ${colors.red("\u5931\u8D25")} (${(r.error || "")
|
|
6574
|
+
console.log(`${colors.red("\u2717")} ${r.name}: ${colors.red("\u5931\u8D25")} (${firstLine(r.error || "")})`);
|
|
6504
6575
|
}
|
|
6505
6576
|
}
|
|
6506
6577
|
async function autoUpdateStaleSubscription(options = {}) {
|
|
@@ -7016,13 +7087,17 @@ async function printStatus(args = []) {
|
|
|
7016
7087
|
broken: overwriteBroken
|
|
7017
7088
|
} = listOverwriteFile(activeSub ? { subName: activeSub.name, subUrl: activeSub.url } : void 0);
|
|
7018
7089
|
if (activeSub && overwriteEnabled && overwriteFiles.some((f) => f.kind === "script")) {
|
|
7019
|
-
|
|
7020
|
-
|
|
7021
|
-
|
|
7022
|
-
|
|
7023
|
-
|
|
7024
|
-
|
|
7090
|
+
try {
|
|
7091
|
+
const rawContent = readSubscriptionRawConfig(activeSub.name);
|
|
7092
|
+
if (rawContent) {
|
|
7093
|
+
const { matches } = judgeScriptMatches(rawContent, deriveRuntimeMode(info), { subName: activeSub.name, subUrl: activeSub.url }, overwriteEntries);
|
|
7094
|
+
const matchedByName = new Map(matches.map((m) => [m.file, m.matched]));
|
|
7095
|
+
for (const f of overwriteFiles) {
|
|
7096
|
+
if (f.kind === "script" && matchedByName.has(f.name)) f.matched = matchedByName.get(f.name);
|
|
7097
|
+
}
|
|
7025
7098
|
}
|
|
7099
|
+
} catch (e) {
|
|
7100
|
+
if (!(e instanceof CliError)) throw e;
|
|
7026
7101
|
}
|
|
7027
7102
|
}
|
|
7028
7103
|
const cached = activeSub ? getSubscriptionsWithCache().find((s) => s.name === activeSub.name) : void 0;
|
|
@@ -7224,40 +7299,41 @@ async function cmdStart(args) {
|
|
|
7224
7299
|
hint: ["Mixed \u6A21\u5F0F\u7531 launchd \u670D\u52A1\u6258\u7BA1\uFF0C\u9700\u5148\u5B89\u88C5:", " mihomo-cli install", "", "\u4E34\u65F6\u4F7F\u7528\u53EF\u8D70 TUN: mihomo-cli tun"]
|
|
7225
7300
|
});
|
|
7226
7301
|
}
|
|
7227
|
-
const
|
|
7228
|
-
|
|
7229
|
-
await autoUpdateStaleSubscription({ timeout: updateTimeout });
|
|
7230
|
-
}
|
|
7231
|
-
let prepared;
|
|
7302
|
+
const tunHint = disabledAutoStartForTun ? ["", "\u670D\u52A1\u81EA\u542F\u5DF2\u88AB\u5173\u95ED\uFF08\u542F\u52A8 TUN \u524D\u5173\u95ED\u4EE5\u907F\u514D\u81EA\u542F\u5931\u8D25\u5FAA\u73AF\uFF09\u3002", "\u6062\u590D Mixed \u6A21\u5F0F: mihomo-cli start"] : [];
|
|
7303
|
+
const appendTunHint = (e) => tunHint.length > 0 ? relabelCliError(e, { hint: [...e.hint, ...tunHint] }) : e;
|
|
7232
7304
|
try {
|
|
7233
|
-
|
|
7305
|
+
const sub = requireActiveSubscription();
|
|
7306
|
+
if (!skipUpdate) {
|
|
7307
|
+
await autoUpdateStaleSubscription({ timeout: updateTimeout });
|
|
7308
|
+
}
|
|
7309
|
+
let prepared;
|
|
7310
|
+
try {
|
|
7311
|
+
prepared = await prepareConfigForStart(targetMode, sub.name);
|
|
7312
|
+
} catch (e) {
|
|
7313
|
+
if (e instanceof CliError) throw e;
|
|
7314
|
+
throw new CliError(e.message, { label: "\u914D\u7F6E\u9519\u8BEF" });
|
|
7315
|
+
}
|
|
7316
|
+
const configInfo = commitPreparedConfig(prepared);
|
|
7317
|
+
console.log([colors.cyan(runtimeModeLabel(targetMode)), sub.name, formatProxySummary(configInfo)].join(" \xB7 "));
|
|
7234
7318
|
} catch (e) {
|
|
7235
|
-
if (e instanceof CliError) throw e;
|
|
7236
|
-
throw
|
|
7319
|
+
if (e instanceof CliError) throw appendTunHint(e);
|
|
7320
|
+
throw e;
|
|
7237
7321
|
}
|
|
7238
|
-
const configInfo = commitPreparedConfig(prepared);
|
|
7239
|
-
console.log([colors.cyan(runtimeModeLabel(targetMode)), sub.name, formatProxySummary(configInfo)].join(" \xB7 "));
|
|
7240
7322
|
try {
|
|
7241
7323
|
const pid = await launchOrRestart(targetMode);
|
|
7242
7324
|
console.log(`${colors.green("\u5DF2\u542F\u52A8")}${pid ? ` (PID ${pid})` : ""}`);
|
|
7243
7325
|
} catch (e) {
|
|
7326
|
+
if (e instanceof CliError) throw appendTunHint(e);
|
|
7244
7327
|
const lines = e.message.split("\n");
|
|
7245
|
-
|
|
7246
|
-
if (targetMode === "tun" && disabledAutoStartForTun) {
|
|
7247
|
-
extraHint.push("", "\u670D\u52A1\u81EA\u542F\u5DF2\u88AB\u5173\u95ED\uFF08\u542F\u52A8 TUN \u524D\u5173\u95ED\u4EE5\u907F\u514D\u81EA\u542F\u5931\u8D25\u5FAA\u73AF\uFF09\u3002", "\u6062\u590D Mixed \u6A21\u5F0F: mihomo-cli start");
|
|
7248
|
-
}
|
|
7249
|
-
if (e instanceof CliError) {
|
|
7250
|
-
throw new CliError(e.message, { label: e.label, hint: [...e.hint, ...extraHint] });
|
|
7251
|
-
}
|
|
7252
|
-
throw new CliError(lines[0], { label: "\u542F\u52A8\u5931\u8D25", hint: [...lines.slice(1), ...extraHint] });
|
|
7328
|
+
throw new CliError(lines[0], { label: "\u542F\u52A8\u5931\u8D25", hint: [...lines.slice(1), ...tunHint] });
|
|
7253
7329
|
}
|
|
7254
7330
|
try {
|
|
7255
7331
|
await printStatus();
|
|
7256
7332
|
} catch (e) {
|
|
7257
|
-
console.log(colors.yellow(`\u72B6\u6001\u5C55\u793A\u5931\u8D25\uFF08\u4E0D\u5F71\u54CD\u5DF2\u5B8C\u6210\u7684\u542F\u52A8\uFF09: ${e.message
|
|
7333
|
+
console.log(colors.yellow(`\u72B6\u6001\u5C55\u793A\u5931\u8D25\uFF08\u4E0D\u5F71\u54CD\u5DF2\u5B8C\u6210\u7684\u542F\u52A8\uFF09: ${firstLine(e.message)}`));
|
|
7258
7334
|
}
|
|
7259
7335
|
if (targetMode === "mixed") {
|
|
7260
|
-
printSystemProxyHint(
|
|
7336
|
+
printSystemProxyHint(getPortsOrNull()?.mixed ?? DEFAULT_MIXED_PORT);
|
|
7261
7337
|
} else {
|
|
7262
7338
|
console.log(colors.gray("TUN \u4E3A\u4E34\u65F6\u8FDB\u7A0B\uFF0C\u5173\u95ED\u7EC8\u7AEF\u4E0D\u4F1A\u505C\u6B62\uFF1B\u505C\u6B62: mihomo-cli stop\uFF08\u4E4B\u540E mihomo-cli start \u6062\u590D Mixed\uFF09"));
|
|
7263
7339
|
}
|
|
@@ -7544,7 +7620,9 @@ async function getLatestRelease(repo, opts) {
|
|
|
7544
7620
|
encoding: "utf8",
|
|
7545
7621
|
maxBuffer: 50 * 1024 * 1024,
|
|
7546
7622
|
timeout: KERNEL_HTTP_TIMEOUT + 1e4,
|
|
7547
|
-
signal: opts.signal
|
|
7623
|
+
signal: opts.signal,
|
|
7624
|
+
// no_proxy 例外表会绕过显式 -x——统一出口置空,保 -x 权威(curl-spawn.ts)
|
|
7625
|
+
env: buildCurlSpawnEnv()
|
|
7548
7626
|
});
|
|
7549
7627
|
stdout = result.stdout;
|
|
7550
7628
|
} catch (e) {
|
|
@@ -7622,6 +7700,8 @@ function buildKernelCurlArgs(args) {
|
|
|
7622
7700
|
];
|
|
7623
7701
|
if (args.proxy) {
|
|
7624
7702
|
argv.push("-x", args.proxy);
|
|
7703
|
+
} else {
|
|
7704
|
+
argv.push("--noproxy", "*");
|
|
7625
7705
|
}
|
|
7626
7706
|
argv.push("-o", args.outputPath, args.url);
|
|
7627
7707
|
return argv;
|
|
@@ -7717,7 +7797,8 @@ async function downloadKernel(progressCallback, channel, releaseInfo) {
|
|
|
7717
7797
|
maxBytes,
|
|
7718
7798
|
outputPath: tempPath
|
|
7719
7799
|
}),
|
|
7720
|
-
|
|
7800
|
+
// no_proxy 例外表会绕过显式 -x——统一出口置空,保 -x 权威(curl-spawn.ts)
|
|
7801
|
+
{ stdio: "inherit", env: buildCurlSpawnEnv() }
|
|
7721
7802
|
);
|
|
7722
7803
|
if (curlResult.error) {
|
|
7723
7804
|
if (curlResult.error.code === "ENOENT") {
|
|
@@ -7925,7 +8006,7 @@ async function collectChecks() {
|
|
|
7925
8006
|
currentVersion: getKernelVersion(kernelProbe)
|
|
7926
8007
|
}),
|
|
7927
8008
|
4e3
|
|
7928
|
-
).catch(() => null) : Promise.resolve(null);
|
|
8009
|
+
).catch((e) => e instanceof Error ? e : null) : Promise.resolve(null);
|
|
7929
8010
|
if (!kernelProbe) {
|
|
7930
8011
|
push("\u5185\u6838", "fail", "\u672A\u5B89\u88C5", "mihomo-cli kernel");
|
|
7931
8012
|
} else if (kernelProbe.status === 0 && kernelProbe.version !== null) {
|
|
@@ -8041,7 +8122,7 @@ async function collectChecks() {
|
|
|
8041
8122
|
}
|
|
8042
8123
|
} catch (e) {
|
|
8043
8124
|
const notes = e instanceof CliError ? e.hint.filter((l) => l.trim().length > 0) : void 0;
|
|
8044
|
-
push("\u914D\u7F6E\u6784\u5EFA", "fail", e.message
|
|
8125
|
+
push("\u914D\u7F6E\u6784\u5EFA", "fail", firstLine(e.message), "\u4FEE\u6B63\u8BA2\u9605\u6216\u8986\u5199\u540E mihomo-cli start", notes);
|
|
8045
8126
|
}
|
|
8046
8127
|
} else {
|
|
8047
8128
|
push("\u914D\u7F6E\u6784\u5EFA", "skip", active ? "\u672A\u5B89\u88C5\u5185\u6838\uFF0C\u8DF3\u8FC7\u6821\u9A8C" : "\u65E0\u8BA2\u9605\uFF0C\u8DF3\u8FC7");
|
|
@@ -8057,8 +8138,10 @@ async function collectChecks() {
|
|
|
8057
8138
|
push("\u4EE3\u7406\u8FDE\u901A", "skip", "\u672A\u8FD0\u884C");
|
|
8058
8139
|
}
|
|
8059
8140
|
const kernelInfo = await kernelVersionPromise;
|
|
8060
|
-
|
|
8061
|
-
|
|
8141
|
+
const kernelPresent = hasKernel();
|
|
8142
|
+
if (kernelInfo instanceof Error || kernelInfo === null && kernelPresent) {
|
|
8143
|
+
const detail = kernelInfo instanceof Error && (kernelInfo.name !== "AbortError" || !kernelPresent) ? `\uFF08${firstLine(kernelInfo.message)}\uFF09` : "";
|
|
8144
|
+
push("\u5185\u6838\u7248\u672C", "skip", `${kernelPresent ? "GitHub \u4E0D\u53EF\u8FBE\uFF0C\u8DF3\u8FC7\u68C0\u67E5" : "\u8DF3\u8FC7\u68C0\u67E5"}${detail}`);
|
|
8062
8145
|
} else if (kernelInfo?.needsUpdate) {
|
|
8063
8146
|
push("\u5185\u6838\u7248\u672C", "warn", `\u5F53\u524D ${kernelInfo.current}\uFF0C\u6700\u65B0 ${kernelInfo.latest}`, "mihomo-cli kernel");
|
|
8064
8147
|
} else if (kernelInfo) {
|
|
@@ -8271,7 +8354,7 @@ function printChannelLine(channel, isExplicitProxy) {
|
|
|
8271
8354
|
console.log("");
|
|
8272
8355
|
}
|
|
8273
8356
|
function formatChannelSwitchLine(previousError) {
|
|
8274
|
-
const reason = previousError
|
|
8357
|
+
const reason = previousError ? firstLine(previousError.message) : "";
|
|
8275
8358
|
return reason ? `\u4E0A\u4E00\u901A\u9053\u5931\u8D25\uFF08${reason}\uFF09\uFF0C\u5207\u6362\u4E3A:` : "\u4E0A\u4E00\u901A\u9053\u5931\u8D25\uFF0C\u5207\u6362\u4E3A:";
|
|
8276
8359
|
}
|
|
8277
8360
|
function buildDownloadFailureError(attempts, isExplicitProxy) {
|
|
@@ -8292,7 +8375,7 @@ function buildDownloadFailureError(attempts, isExplicitProxy) {
|
|
|
8292
8375
|
return new CliError("\u5168\u90E8\u4E0B\u8F7D\u901A\u9053\u5747\u5931\u8D25", {
|
|
8293
8376
|
label: "\u4E0B\u8F7D\u5931\u8D25",
|
|
8294
8377
|
hint: [
|
|
8295
|
-
...attempts.map((a) => ` ${channelLabel(a.channel, isExplicitProxy)}: ${a.error.message
|
|
8378
|
+
...attempts.map((a) => ` ${channelLabel(a.channel, isExplicitProxy)}: ${firstLine(a.error.message)}`),
|
|
8296
8379
|
"",
|
|
8297
8380
|
"\u82E5\u4E24\u6761\u901A\u9053\u90FD\u662F\u4F4E\u901F\u5931\u8D25\uFF1A\u95EE\u9898\u5728\u5F53\u524D\u9009\u4E2D\u7684\u673A\u573A\u8282\u70B9\uFF08url-test \u53EA\u6309\u63E1\u624B\u5EF6\u8FDF\u9009\u3001\u4E0D\u6D4B\u5E26\u5BBD\uFF09\uFF0C",
|
|
8298
8381
|
"\u5728\u9762\u677F\u91CC\u624B\u52A8\u7ED9 Default Proxy \u6362\u4E2A\u7EBF\u8DEF\u6216\u8282\u70B9\u540E\u91CD\u8BD5\uFF1B\u4E5F\u53EF\u6362\u4E2A\u65F6\u95F4\u7B49 url-test \u91CD\u9009",
|
|
@@ -8687,6 +8770,9 @@ async function cmdReset(args) {
|
|
|
8687
8770
|
}
|
|
8688
8771
|
recordServiceStopped();
|
|
8689
8772
|
}
|
|
8773
|
+
if (!needsStop && serviceTargeted && cleanup !== null && cleanup.remaining.length > 0) {
|
|
8774
|
+
printResidueWarning(cleanup.remaining);
|
|
8775
|
+
}
|
|
8690
8776
|
const deleted = /* @__PURE__ */ new Set();
|
|
8691
8777
|
for (const target of targets) {
|
|
8692
8778
|
let hadContent = target.id === "service" && (serviceActive || legacy);
|
|
@@ -8764,8 +8850,7 @@ async function cmdInstall(args) {
|
|
|
8764
8850
|
printRestoreSkipped();
|
|
8765
8851
|
return;
|
|
8766
8852
|
}
|
|
8767
|
-
throw
|
|
8768
|
-
label: e.label,
|
|
8853
|
+
throw relabelCliError(e, {
|
|
8769
8854
|
hint: [...e.hint, "", "\u670D\u52A1\u5DF2\u5B89\u88C5\u6210\u529F\uFF0C\u4EC5\u6062\u590D\u8FD0\u884C\u5931\u8D25\uFF1B\u4FEE\u6B63\u914D\u7F6E\u540E\u53EF\u6267\u884C mihomo-cli start \u91CD\u8BD5\u3002"]
|
|
8770
8855
|
});
|
|
8771
8856
|
}
|
|
@@ -8805,8 +8890,7 @@ async function cmdUninstall(args) {
|
|
|
8805
8890
|
if (remaining === null) remaining = getMihomoPids();
|
|
8806
8891
|
if (remaining.length > 0) {
|
|
8807
8892
|
console.log("");
|
|
8808
|
-
|
|
8809
|
-
console.log(MANUAL_PKILL_HINT);
|
|
8893
|
+
printResidueWarning(remaining);
|
|
8810
8894
|
}
|
|
8811
8895
|
console.log(colors.gray("\u91CD\u65B0\u5B89\u88C5: mihomo-cli install"));
|
|
8812
8896
|
console.log(colors.gray("\u5F7B\u5E95\u79FB\u9664 mihomo-cli:"));
|
|
@@ -8851,12 +8935,12 @@ async function cmdStop(args) {
|
|
|
8851
8935
|
import { spawnSync as spawnSync10 } from "child_process";
|
|
8852
8936
|
function printRestartHintIfRunning(variant = "update") {
|
|
8853
8937
|
const state = getRunningState();
|
|
8854
|
-
if (state.running)
|
|
8855
|
-
|
|
8856
|
-
|
|
8857
|
-
|
|
8858
|
-
|
|
8859
|
-
|
|
8938
|
+
if (!state.running) return;
|
|
8939
|
+
const hintCommand = startCommandForCurrentMode(state);
|
|
8940
|
+
const removedSuffix = variant === "removed-last" ? `\uFF08\u8BA2\u9605\u5DF2\u5168\u90E8\u5220\u9664\uFF09\uFF0C\u91CD\u65B0\u6DFB\u52A0\u8BA2\u9605\u540E\u6267\u884C ${hintCommand}` : `\uFF0C\u6267\u884C ${hintCommand} \u5207\u6362\u5230\u65B0\u8BA2\u9605`;
|
|
8941
|
+
const message = variant === "update" ? `\u63D0\u793A: \u8FD0\u884C\u4E2D\u7684\u5B9E\u4F8B\u4ECD\u4F7F\u7528\u65E7\u914D\u7F6E\uFF0C\u6267\u884C ${hintCommand} \u4F7F\u66F4\u65B0\u751F\u6548` : `\u63D0\u793A: \u8FD0\u884C\u4E2D\u7684\u5B9E\u4F8B\u4ECD\u5728\u4F7F\u7528\u5DF2\u5220\u9664\u8BA2\u9605\u7684\u914D\u7F6E${removedSuffix}`;
|
|
8942
|
+
console.log(colors.yellow(message));
|
|
8943
|
+
console.log("");
|
|
8860
8944
|
}
|
|
8861
8945
|
function printSubscriptionList() {
|
|
8862
8946
|
const subs = getSubscriptionsWithCache();
|
|
@@ -8947,7 +9031,7 @@ async function subAdd(args) {
|
|
|
8947
9031
|
console.log(`\u5DF2\u6DFB\u52A0\u5E76\u5207\u6362\u5230 "${name}" (${formatProxySummary(info)})`);
|
|
8948
9032
|
} catch (e) {
|
|
8949
9033
|
removeSubscription(name);
|
|
8950
|
-
if (e instanceof CliError) throw
|
|
9034
|
+
if (e instanceof CliError) throw relabelCliError(e, { label: "\u6DFB\u52A0\u5931\u8D25" });
|
|
8951
9035
|
throw new CliError(e.message, { label: "\u6DFB\u52A0\u5931\u8D25" });
|
|
8952
9036
|
}
|
|
8953
9037
|
console.log("");
|
|
@@ -8991,7 +9075,7 @@ async function subUpdate(args) {
|
|
|
8991
9075
|
console.log(`\u66F4\u65B0\u8BA2\u9605: ${target.name}`);
|
|
8992
9076
|
const result = await withSpinner("\u4E0B\u8F7D\u8BA2\u9605", () => tryUpdateOne(target));
|
|
8993
9077
|
if (!result.success) {
|
|
8994
|
-
throw new CliError((result.error || "")
|
|
9078
|
+
throw new CliError(firstLine(result.error || ""), { label: "\u66F4\u65B0\u5931\u8D25" });
|
|
8995
9079
|
}
|
|
8996
9080
|
console.log(`\u5DF2\u66F4\u65B0 (${formatProxySummary(result)})`);
|
|
8997
9081
|
console.log("");
|
|
@@ -9054,14 +9138,16 @@ async function subRemove(args) {
|
|
|
9054
9138
|
return;
|
|
9055
9139
|
}
|
|
9056
9140
|
}
|
|
9057
|
-
const { found, switchedTo } = removeSubscription(target.name);
|
|
9141
|
+
const { found, switchedTo, wasActive } = removeSubscription(target.name);
|
|
9058
9142
|
if (!found) {
|
|
9059
9143
|
throw new CliError(`\u8BA2\u9605 "${target.name}" \u4E0D\u5B58\u5728\uFF08\u53EF\u80FD\u5DF2\u88AB\u5E76\u53D1\u5220\u9664\uFF09`, { hint: ["\u67E5\u770B\u5F53\u524D\u5217\u8868: mihomo-cli sub"] });
|
|
9060
9144
|
}
|
|
9061
9145
|
console.log(`\u5DF2\u5220\u9664\u8BA2\u9605 "${target.name}"`);
|
|
9062
9146
|
if (switchedTo) {
|
|
9063
9147
|
console.log(`\u5DF2\u81EA\u52A8\u5207\u6362\u5230 "${switchedTo}"`);
|
|
9064
|
-
|
|
9148
|
+
}
|
|
9149
|
+
if (wasActive) {
|
|
9150
|
+
printRestartHintIfRunning(switchedTo ? "removed-active" : "removed-last");
|
|
9065
9151
|
}
|
|
9066
9152
|
console.log("");
|
|
9067
9153
|
printSubscriptionList();
|
|
@@ -9118,12 +9204,12 @@ function cmdUI(args) {
|
|
|
9118
9204
|
console.log("");
|
|
9119
9205
|
}
|
|
9120
9206
|
const url = UI_URLS[uiName];
|
|
9121
|
-
const
|
|
9207
|
+
const endpoint = getControllerEndpoint();
|
|
9122
9208
|
console.log(`\u6253\u5F00 Web UI: ${uiName}`);
|
|
9123
9209
|
console.log(`\u9875\u9762: ${url}`);
|
|
9124
|
-
console.log(`\u63A7\u5236\u5668: http://127.0.0.1:${
|
|
9125
|
-
const secret =
|
|
9126
|
-
if (
|
|
9210
|
+
console.log(`\u63A7\u5236\u5668: http://127.0.0.1:${endpoint.port ?? "\uFF08settings.json \u7684 ports \u914D\u7F6E\u975E\u6CD5\uFF0C\u65E0\u6CD5\u786E\u5B9A\uFF09"}`);
|
|
9211
|
+
const secret = endpoint.secret;
|
|
9212
|
+
if (secret) {
|
|
9127
9213
|
if (copySecret) {
|
|
9128
9214
|
console.log(
|
|
9129
9215
|
copyToClipboard(secret) ? "\u8BBF\u95EE\u5BC6\u94A5\u5DF2\u590D\u5236\u5230\u526A\u8D34\u677F\uFF0CUI \u8FDE\u63A5\u65F6\u7C98\u8D34" : colors.yellow("\u8BBF\u95EE\u5BC6\u94A5\u590D\u5236\u5931\u8D25\uFF0C\u8BF7\u5230 settings.json \u67E5\u770B controller_secret")
|