mihomo-cli 26.10.105 → 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 +26 -62
- package/README.md +3 -4
- package/dist/index.js +234 -156
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
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
|
+
|
|
20
|
+
## [26.10.106] - 2026-10-03
|
|
21
|
+
|
|
22
|
+
### 修复(覆写提示降噪)
|
|
23
|
+
|
|
24
|
+
- **未命中覆写脚本不再进配置告警**:start/update 顶部的黄色「配置提示: 覆写脚本 xxx 未返回 true…」与 status 的展示重复,措辞是脚本作者视角、使用者无事可做;`mh config` 提示段与 doctor 计数同步安静,配置告警只留真异常(脚本 ctx.warn、锁定键被剥除、TUN 强制开 DNS)
|
|
25
|
+
- **status 覆写区块收敛为一行**:不适用文件只计数不点名(`覆写: 已启用 (mini, seal,1 个不适用)`),逐行点名与「脚本未返回 true」术语不再暴露——想知道是哪个文件,对照 `mh ow` 列表的作用域栏;`status --json` 的 applied/files 契约不变
|
|
26
|
+
- **内部清理**:删除零消费的 `BuildConfigResult.scriptMatches` 字段与过期契约注释;status 用例负断言从锁句子改为锁文件名(换措辞恢复点名也能被测试拦住)
|
|
27
|
+
|
|
28
|
+
|
|
3
29
|
## [26.10.105] - 2026-10-03
|
|
4
30
|
|
|
5
31
|
### 变更(质量清理:测试基建单点化与白名单派生收单)
|
|
@@ -190,65 +216,3 @@
|
|
|
190
216
|
|
|
191
217
|
- **内核下载本机代理优先、失败自动换通道**:`mihomo kernel` 在本机代理运行时默认经代理下载,失败自动回退 gh;全部失败时汇总各通道原因,并提示可在面板手动换节点。显式 `--mirror`/`--proxy` 仍严格按指定通道、不自动切换
|
|
192
218
|
- **劣质节点下载不再长时间干等**:节点握手延迟低但实际带宽极低时(实测约 20 KB/s),此前 gh 通道会卡满 210 秒;现代理通道在 20 秒内平均速度低于 50 KB/s 即快速失败,gh 通道超时也缩短到 100 秒。超时或低速失败给出可读原因,不再只显示「curl 退出码 28」
|
|
193
|
-
|
|
194
|
-
## [26.10.97] - 2026-10-01
|
|
195
|
-
|
|
196
|
-
### 修复
|
|
197
|
-
|
|
198
|
-
- **sudo 执行超时不再漏出内部错误串**:密码提示停留或脚本执行超过 60 秒时,此前用户看到的是 `spawnSync sudo ETIMEDOUT`,现改为超时提示并点明操作可能只完成了一部分
|
|
199
|
-
- **覆写 match 值加载期校验补齐**:`url-domain` 带协议、尾斜杠、端口、空格,或 `name` 精确值含非法字符时,文件会静默永不生效,现一律加载时报错;`rules!+`、`+~rules` 等操作符漏网形态同样拦下
|
|
200
|
-
- **帮助文案与实际行为对齐**:logs 用法行更正裸命令语义、version 用法不再内嵌别名、subscription use 补上自动重启说明;子命令名(如 `sub USE`)改为大小写不敏感
|
|
201
|
-
- **到期时间戳对非法值返回「未知」**:手工改坏缓存(非数字、负数、超出日期上限)时此前漏出字面 `Invalid Date` 或 1970 日期
|
|
202
|
-
|
|
203
|
-
## [26.10.96] - 2026-10-01
|
|
204
|
-
|
|
205
|
-
### 修复
|
|
206
|
-
|
|
207
|
-
- **裸 `-` 一律按未知选项报错**:此前被 argv 校验豁免、取位置参数时又跳过,两头不认等于静默丢弃——`sub update -`(短横线笔误)会被当成无参形态批量更新全部订阅,`start -` 静默起默认代理,`sub add <url> -` 更会建出 remove/use 都无法指定的订阅(只剩 reset 能收拾)
|
|
208
|
-
- **pid 文件清理免提权**:文件在 runtime/ 下(用户属主目录),目录可写即可删其中任意文件、与文件属主无关——root 属主的 TUN 残留文件也直接删,不再走 sudo rm。此前零进程的 `mihomo stop` 会为一个没有进程读的无害文件弹管理员密码(取消后还警告「未能清理」,而文件随后就被免提权的 runtime 清理删掉);sudo 清理脚本被取消后也不再紧接着弹第二次密码
|
|
209
|
-
- **进程还活着时不再删 pid 文件**:sudo 清理被取消、root TUN 内核仍在路由时,pid 文件是 status/isRunning 的真相源——免提权化初版在此场景把它删掉,status 从此对活着的内核报「未运行」;现改为复核确认进程清零后才清理
|
|
210
|
-
- **legacy 迁移脚本不再删活进程的 pid**:清理旧 v3–v4 root LaunchDaemon 的脚本在 `bootout` 后无条件 `rm pid`,机器残留旧 plist(检测只看文件存在)却另有一个无关活 root TUN 时,bootout 返回 113(未装载)仍会删掉活 TUN 的 pid——之后并发 `mihomo status` 对仍在路由的内核误报「未运行」,此刻 Ctrl+C 凝固成「活 TUN + 无 pid」。脚本不再碰 pid,改为拆除成功、复核进程清零后免提权清理;有并存的活 TUN 时保留其 pid
|
|
211
|
-
- `mihomo reset` 遇 root 残留清理的 sudo 未走通(取消/非 TTY/脚本失败)时不再完全静默:进程复核已清空则继续重置,但黄字告知可能有残留未清及重试入口(26.10.95 统一后该场景的警告通道被丢弃)
|
|
212
|
-
- `mihomo stop` 收尾警告归因修正:进程在死亡等待内自行退光、而 sudo 清理脚本被取消/失败时,旧逻辑把它说成「root 属主的 pid 文件未能清理」(文件可能根本没出过问题),现按「清理未完成、进程目前已不在」归因;两类收尾错误(脚本/pid 文件)拆为独立字段,服务路径的提示同步按字段分开
|
|
213
|
-
- 残留清理报错不再把 surviving 进程一概说成「root 属主」:没进过 root 分支(用户态 SIGKILL 未能终止)时按「用户态未能终止」描述,root 断言只跟随 sudo 脚本失败出现;pid 文件清理失败的文案也不再断言「root 属主」(免提权 unlink 失败与属主无关),且「用户态残留 + pid 文件小错」不再被拦成命令失败(错误消息会是 unlink 报错、与「进程未终止」的提示自相矛盾),归外层残留处置
|
|
214
|
-
- pid 文件清理失败的警告不再连打两遍(clearPid 内部遗留的 console.warn 与调用方警告叠加);sudo 失败短语全仓统一为 describeSudoFailure(非鉴权错误保留原始消息——非交互环境的具体原因不再被「sudo 执行失败」笼统盖掉),pid 文件短语统一 describePidCleanupFailure
|
|
215
|
-
- 空环境裸 `mihomo sub remove`(未给名称)改报「没有订阅」,与带名称形态及 use/update 同口径(旧报「请指定名称」并引导补一个不存在的参数)
|
|
216
|
-
- 混合属主时 root 残留清理的预告只列 root 属主的 PID:用户态游离内核混在其中时,旧消息把全部 PID 都标成「root 属主的内核残留」,与实际属主不符
|
|
217
|
-
|
|
218
|
-
### 内部
|
|
219
|
-
|
|
220
|
-
- root 残留清理脚本 buildKernelCleanupScript 不再 `rm pid`:cleanupAll 路径的 pid 删除统一在末尾、复核 remaining 为空才免提权 unlink,消除该路径「活进程不删 isRunning 真相源」在提权脚本内的字面例外(此前仅靠「sudo 取消脚本不执行 + pkill 失败 exit 2」两道时序间接保证;legacy 迁移脚本 buildLegacyCleanupScript 的同款 `rm pid` 也已收口,见上方修复段);buildRootResidueCleanupError 在 scriptError 与 pidError 并存时改为 scriptError 优先(主归因「清理未走完」、pid 错误仅附带,手动命令给 pkill 而非 rm,防漏掉潜在存活进程);reset 的警告理由去掉 `as Error` 断言、改显式空值守卫;补「脚本不得含 rm」的结构断言、只读文件免提权删除与双错误并存象限用例
|
|
221
|
-
- `CleanupResult.sudoError` 拆为 `scriptError`(pkill 脚本)与 `pidError`(pid 文件删除)两个字段:进程死光但脚本没走完与仅 pid 文件残留是两种归因,合并字段让调用方提示说错事;处置判据 classifyResidueCleanup 同步(throw 档只看 scriptError,pidError 不参与拦截),reset 的警告判据也收口到它
|
|
222
|
-
- `StaleState` 删除无消费方的 `needsSudo`/`hasRootPidFile`/`hasRootProcess` 字段;`clearPid` 的三态返回值(cancelled/failed/null)随免提权化收敛为 `Error | null`
|
|
223
|
-
- 覆写数组拼接误用的「值类型描述」抽为 describeValueKind:文件级(系统默认值)与合并级(订阅现值)两处检查共用,消除已漂移的双实现
|
|
224
|
-
- 测试注释清理:三处历史叙事(引入版本、旧实现去向)改为只留判据,历史留在 CHANGELOG/git
|
|
225
|
-
|
|
226
|
-
## [26.10.95] - 2026-10-01
|
|
227
|
-
|
|
228
|
-
### 修复
|
|
229
|
-
|
|
230
|
-
- **README 承诺的覆写反例现在真的报错**:`log-level+: warning`(数组操作符作用于系统默认的标量键)此前静默产出 `log-level: [warning]`,配置一路存活到内核 `-t`——类型检查只看得到订阅层,而该键只存在于系统默认配置(在合并之后才注入)。现在文件加载阶段即报错并给出改写指引
|
|
231
|
-
- **坏覆写文件在 `ow` / `status` 的结论与启动硬失败不再自相矛盾**:`~dns` 这类已移除操作符此前在 `ow`/status 被列为「已生效」(`status --json` 的 `applied` 也带着它),而 `start`/`config`/`doctor` 对同一文件硬失败。操作符形态错误(`~`/尖括号/互斥/空键)提前到加载阶段校验,诊断与合并两条路径看到同一份坏文件清单;坏文件的修复/迁移指引(hint)此前只在启动报错时可见,现在 `ow`、status 文本与 `status --json` 都带出
|
|
232
|
-
- `mihomo status` 里 JS 覆写脚本的短名显示修复:`overwrite.js` 不再显示成 `js`(正确是「主文件」),`overwrite.dns.js` 不再带 `.js` 尾巴(26.9.93 引入脚本时漏改)
|
|
233
|
-
- `mihomo doctor` 订阅新鲜度不再输出「N 分钟前**前**更新」;未来时间戳(时钟偏移)单独显示「更新时间记录异常」
|
|
234
|
-
- 自动更新整体超时后,没赶上的订阅显示灰色「跳过(更新超时,使用本地缓存)」,不再与真实网络失败同刷红叉英文(`The operation was aborted...`),也不计入失败数——超时用缓存启动本是正常降级
|
|
235
|
-
- 内核下载/解压中被强制终止后,`kernel/.tmp-*` 临时目录(可能几十 MB)不再永久残留:与原子写 `*.tmp` 同受按 1 小时龄的崩溃残留清扫,旧内核完好时无需手动 `reset kernel`
|
|
236
|
-
- 空环境 `mihomo sub remove <名字>` 改报「没有订阅」,与 `use`/`update` 同口径(旧报「未找到匹配」)
|
|
237
|
-
- `mihomo start -u 5s` 等非法选项值现在先报参数错误,不再先撞「未找到内核」
|
|
238
|
-
- 服务路径清理 root 残留内核后偶发误报「部分进程未终止」(重跑一次又正常)消除:杀进程统一走带死亡等待轮询的同一实现,不再在发出 SIGKILL 后立刻复核 pgrep;三处 root 提权(start/stop/uninstall)前都补了「为什么需要管理员密码」的预告,不再无预警弹英文 `Password:`
|
|
239
|
-
- 非交互终端(或取消密码)下 `mihomo stop`/`uninstall` 不再因一个无害的 root 属主 pid 文件残留而整体失败:无残留进程时该文件清理失败只警告(无进程读它、下次自愈),与旧服务路径「无进程不弹密码」的语义对齐;root 进程确实没杀掉仍照常报错
|
|
240
|
-
- `uninstall` 不再重复执行第二次 disable(锁内已写入并经 `print-disabled` 复核成功,第二次必成功,纯冗余)
|
|
241
|
-
|
|
242
|
-
### 新增
|
|
243
|
-
|
|
244
|
-
- `mihomo reset overwrites` 完成后,若目录里还有不被加载的疑似覆写文件(`overwrite.yml`、`overwrite.ts`、大小写变体),点名告知「N 个疑似文件保留未删」及原因(保守起见这些近失文件仍不自动删)
|
|
245
|
-
- `mihomo kernel` 首选 gh 认证查询但回退直连成功时,打印一行实际来源(spinner 说的「gh 认证通道」与实际响应不再可能悄悄不一致)
|
|
246
|
-
- 连续查看状态时连通性探测结果按端口缓存 3 秒:代理不通时连敲 `status`/`doctor` 不再每次干等 2 秒(代理状态秒级不可能翻转;`--no-probe` 不受影响)
|
|
247
|
-
- README 修正 JS 脚本可见性描述:`ctx.warn()` 与脚本执行期抛错只在 `config`/`doctor`/`start` 可见,`status` 只加载脚本、不执行函数体
|
|
248
|
-
|
|
249
|
-
### 内部
|
|
250
|
-
|
|
251
|
-
- 残留内核清理收敛为唯一入口 `cleanupAll`(服务启停/卸载/重置/游离内核共用),删除 service.ts 内与之重复的约 100 行实现(`killResidualKernels`/`cleanupRootResidue` 等);`cleanupAll`/`stop` 的 `forceSudo` 死参删除(无任何调用方传值)
|
|
252
|
-
- 删除 `withFileLock` 的 deadline 分支:过线后重新核对的还是循环顶部微秒前算过的同一个锁龄谓词,该分支永不产生行为差异;锁的心智模型回到「强夺唯一依据是锁龄」
|
|
253
|
-
- 健康轮询(每 100ms 一次、最坏 31 轮)不再白跑 `print-disabled`:健康判定从不读 disabled 字段,`getServiceStatus` 新增 `withDisabled` 选项,轮询关闭该查询以减少阻塞事件循环的 spawnSync;循环外从未被消费的首次快照一并删除
|
|
254
|
-
- 删除测试专用的第二合并入口 `deepMergeWithOverrides`,相关用例改走生产唯一入口 `applyOverwrite`
|
package/README.md
CHANGED
|
@@ -482,7 +482,7 @@ export default function (config, ctx) {
|
|
|
482
482
|
约定与边界:
|
|
483
483
|
|
|
484
484
|
- **必须同步**:返回 Promise 会报错。脚本是纯数据变换,没有要等网络的场景
|
|
485
|
-
- **`return true` = 命中当前订阅**:脚本没有 `match` 声明,`status`
|
|
485
|
+
- **`return true` = 命中当前订阅**:脚本没有 `match` 声明,`status` 靠返回值区分「生效中」与「不适用于当前订阅」——判据过了就在最后 `return true`,不中就提前退出。判定严格认 `true`(返回别的 truthy 值不算),也不影响合并本身
|
|
486
486
|
- **全信任**:脚本以你的用户身份运行(和 `.zshrc` 一个待遇),不做沙箱与超时——别装来路不明的覆写脚本
|
|
487
487
|
- **改不动系统锁定项**:`mixed-port`、`external-controller`、`allow-lan` 等入站与控制面键由 CLI 管理,脚本设置了会被剥除并提示(与 YAML 覆写同一条边界)
|
|
488
488
|
- **脚本先于 YAML 执行**:脚本看到的是订阅原始配置,读不到 YAML 覆写注入的内容;需要脚本处理 YAML 注入项时,把那段逻辑也写进脚本
|
|
@@ -511,16 +511,15 @@ export default function (config, ctx) {
|
|
|
511
511
|
|
|
512
512
|
`match` 块**写错会直接报错**(键名拼错、值为空、空块、写已移除的 `subscription` 键),而不是静默忽略后对所有订阅生效——写了 `match` 显然是想限定作用域,悄悄放宽比报错危险得多。历史写法 `subscription` 与 `name` 同义、已收掉,写它直接报错指明改写 `name`。
|
|
513
513
|
|
|
514
|
-
> `url-domain` 命中该域名下的**所有**订阅。同一机场的多条订阅(如 `edu1`、`mini1`)URL 往往同域名,用 `url-domain` 会一并生效;要在同机场内按套餐区分,用 `name: edu*`。若只是担心某条订阅没有要改的分组,在 JS 脚本里判(找不到就 `ctx.warn` 跳过),不必为此改作用域;`match` 应当按「这份覆写在语义上属于哪些订阅」来写。JS 脚本没有 match 机制——作用域判断写在脚本开头(`if (!ctx.subscription.name.startsWith('edu')) return;`),判据过了在函数末尾 `return true`,`status`
|
|
514
|
+
> `url-domain` 命中该域名下的**所有**订阅。同一机场的多条订阅(如 `edu1`、`mini1`)URL 往往同域名,用 `url-domain` 会一并生效;要在同机场内按套餐区分,用 `name: edu*`。若只是担心某条订阅没有要改的分组,在 JS 脚本里判(找不到就 `ctx.warn` 跳过),不必为此改作用域;`match` 应当按「这份覆写在语义上属于哪些订阅」来写。JS 脚本没有 match 机制——作用域判断写在脚本开头(`if (!ctx.subscription.name.startsWith('edu')) return;`),判据过了在函数末尾 `return true`,`status` 便能把命中的脚本列进「生效」、未命中的计入「不适用」。
|
|
515
515
|
|
|
516
516
|
`mihomo-cli status` 会按当前活跃订阅区分「生效」与「不适用」,括号里只列本次真正参与合并的文件:
|
|
517
517
|
|
|
518
518
|
```text
|
|
519
519
|
覆写: 已启用 (seal,1 个不适用,1 个已禁用)
|
|
520
|
-
glados 不适用于当前订阅 mini1(作用域 name=edu*)
|
|
521
520
|
```
|
|
522
521
|
|
|
523
|
-
「不适用」指文件本身是启用的,只是 `match` 没命中当前订阅(JS 脚本则是没走到 `return true`)——切到命中的订阅(`sub use`)、改 `match` 或脚本判据才会生效,与 `enabled: false`
|
|
522
|
+
「不适用」指文件本身是启用的,只是 `match` 没命中当前订阅(JS 脚本则是没走到 `return true`)——切到命中的订阅(`sub use`)、改 `match` 或脚本判据才会生效,与 `enabled: false` 的「已禁用」是两回事。不适用与已禁用都只计数、不逐行点名:想知道是哪个文件,对照 `mihomo-cli ow` 列表的作用域一栏(它说明该文件管哪些订阅)。`--json` 形态下 `overwrite.applied` 是生效清单(`ow off` 全局关闭时为空数组),`overwrite.files` 仍是「未被 `enabled: false` 停用」的全部文件;语法或元数据键写错的文件进 `overwrite.errors`(不混进 files/applied)。
|
|
524
523
|
|
|
525
524
|
**坏文件不阻断诊断、但阻断启动**:YAML 语法错误(含 `enabled: no` 这类元数据键错误)的文件在 `mihomo-cli ow` 与 `status` 中以「加载失败」红字标出,诊断命令永远可用;但该文件不参与合并,`mihomo-cli start`/`doctor` 会硬失败并给出原因——曾经语法错只警告一行就跳过、退出码 0,启动成功但覆写根本没生效。
|
|
526
525
|
|
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" });
|
|
@@ -4614,8 +4638,7 @@ function buildConfig(subRawContent, mode, scope) {
|
|
|
4614
4638
|
const {
|
|
4615
4639
|
config: withOverwrites,
|
|
4616
4640
|
scriptWarnings,
|
|
4617
|
-
scriptLockedHits
|
|
4618
|
-
scriptMatches
|
|
4641
|
+
scriptLockedHits
|
|
4619
4642
|
} = applyOverwrite(subscriptionConfig, overwriteFiles, {
|
|
4620
4643
|
mode,
|
|
4621
4644
|
scope
|
|
@@ -4623,9 +4646,6 @@ function buildConfig(subRawContent, mode, scope) {
|
|
|
4623
4646
|
const overwriteSummaries = overwriteFiles.map(describeOverwriteScope);
|
|
4624
4647
|
const systemConfig = {};
|
|
4625
4648
|
const lockedWarnings = [...scriptWarnings];
|
|
4626
|
-
for (const m of scriptMatches.filter((s) => !s.matched)) {
|
|
4627
|
-
lockedWarnings.push(`\u8986\u5199\u811A\u672C ${m.file} \u672A\u8FD4\u56DE true\uFF0C\u4E0D\u89C6\u4E3A\u547D\u4E2D\u5F53\u524D\u8BA2\u9605${scope?.subName ? ` ${scope.subName}` : ""}`);
|
|
4628
|
-
}
|
|
4629
4649
|
for (const hit of scriptLockedHits) {
|
|
4630
4650
|
lockedWarnings.push(renderLockedWarning(`\u8986\u5199\u811A\u672C ${hit.file} \u4E2D\u7684`, hit.keys));
|
|
4631
4651
|
}
|
|
@@ -4692,7 +4712,7 @@ function buildConfig(subRawContent, mode, scope) {
|
|
|
4692
4712
|
};
|
|
4693
4713
|
}
|
|
4694
4714
|
assertConfigShape(merged);
|
|
4695
|
-
return { config: merged, warnings: lockedWarnings, overwriteSummaries
|
|
4715
|
+
return { config: merged, warnings: lockedWarnings, overwriteSummaries };
|
|
4696
4716
|
}
|
|
4697
4717
|
function renderLockedWarning(source, keys) {
|
|
4698
4718
|
return `${source}\u7CFB\u7EDF\u9501\u5B9A\u9879\u5DF2\u5FFD\u7565: ${keys.join("\u3001")}\uFF08\u5165\u7AD9\u7AEF\u53E3\u3001\u63A7\u5236\u9762\u3001\u63A7\u5236\u5668\u8BC1\u4E66\u4E0E\u5C40\u57DF\u7F51/\u5165\u7AD9\u9274\u6743\u7531 mihomo-cli \u7BA1\u7406\uFF1B\u7AEF\u53E3\u4E0E controller secret \u5728 settings.json \u914D\u7F6E\uFF0C\u5165\u7AD9\u56FA\u5B9A\u53EA\u76D1\u542C\u56DE\u73AF\uFF0C\u9700\u8981\u5C40\u57DF\u7F51\u5165\u7AD9\u8BF7\u5728\u672C\u673A\u53E6\u8D77\u4E00\u4E2A mihomo-cli \u5B9E\u4F8B\uFF09`;
|
|
@@ -4708,7 +4728,7 @@ function judgeScriptMatches(subRawContent, mode, scope, entries) {
|
|
|
4708
4728
|
});
|
|
4709
4729
|
return { matches: scriptMatches };
|
|
4710
4730
|
} catch (e) {
|
|
4711
|
-
return { matches: [], error: e.message
|
|
4731
|
+
return { matches: [], error: firstLine(e.message ?? String(e)) };
|
|
4712
4732
|
}
|
|
4713
4733
|
}
|
|
4714
4734
|
function deriveRuntimeMode(info) {
|
|
@@ -4753,7 +4773,7 @@ function buildKernelRejectHint(detail, overwriteSummaries, opts = {}) {
|
|
|
4753
4773
|
async function validateConfigWithKernel(config, overwriteSummaries) {
|
|
4754
4774
|
assertKernelInstalled();
|
|
4755
4775
|
ensureDirs();
|
|
4756
|
-
const stageDir = fs4.mkdtempSync(path4.join(
|
|
4776
|
+
const stageDir = fs4.mkdtempSync(path4.join(USER_DATA_DIR, "check-"));
|
|
4757
4777
|
const stageFile = path4.join(stageDir, "config.yaml");
|
|
4758
4778
|
try {
|
|
4759
4779
|
fs4.writeFileSync(stageFile, dumpYaml(config), { mode: 384 });
|
|
@@ -4821,7 +4841,7 @@ function getKernelVersion(probe) {
|
|
|
4821
4841
|
try {
|
|
4822
4842
|
const p = probe ?? probeKernelVersion();
|
|
4823
4843
|
if (!p.output) return "unknown";
|
|
4824
|
-
return p.version ?? p.output
|
|
4844
|
+
return p.version ?? firstLine(p.output);
|
|
4825
4845
|
} catch {
|
|
4826
4846
|
return "unknown";
|
|
4827
4847
|
}
|
|
@@ -4968,6 +4988,10 @@ function parseDisabledList(output, label) {
|
|
|
4968
4988
|
return value === "true" || value === "disabled";
|
|
4969
4989
|
}
|
|
4970
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
|
+
}
|
|
4971
4995
|
function runLaunchctl(args, timeoutMs = LAUNCHCTL_TIMEOUT_MS) {
|
|
4972
4996
|
try {
|
|
4973
4997
|
const result = spawnSync2("launchctl", args, { encoding: "utf8", timeout: timeoutMs });
|
|
@@ -5062,6 +5086,14 @@ async function waitUntilUnloaded(target = serviceTarget()) {
|
|
|
5062
5086
|
import { execFile as execFile2, spawnSync as spawnSync4 } from "child_process";
|
|
5063
5087
|
import { promisify as promisify2 } from "util";
|
|
5064
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
|
+
|
|
5065
5097
|
// src/process-probe.ts
|
|
5066
5098
|
import { spawnSync as spawnSync3 } from "child_process";
|
|
5067
5099
|
import fs6 from "fs";
|
|
@@ -5176,7 +5208,11 @@ async function probeProxyConnectivity(port) {
|
|
|
5176
5208
|
const { stdout } = await execFileAsync(
|
|
5177
5209
|
"curl",
|
|
5178
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],
|
|
5179
|
-
{
|
|
5211
|
+
{
|
|
5212
|
+
timeout: PROBE_TIMEOUT_MS + 2e3,
|
|
5213
|
+
// 例外表会绕过显式 -x、让探测考成直连(绿灯作废),置空兜住统一走 curl-spawn.ts 出口
|
|
5214
|
+
env: buildCurlSpawnEnv()
|
|
5215
|
+
}
|
|
5180
5216
|
);
|
|
5181
5217
|
const code = Number.parseInt(stdout.trim(), 10);
|
|
5182
5218
|
const statusCode = Number.isFinite(code) ? code : null;
|
|
@@ -5244,18 +5280,18 @@ async function tryHotReload(prefetched) {
|
|
|
5244
5280
|
try {
|
|
5245
5281
|
const status = prefetched ?? getServiceStatus({ withDisabled: false });
|
|
5246
5282
|
if (!status.running || status.pid === null) return false;
|
|
5247
|
-
const
|
|
5248
|
-
|
|
5249
|
-
const
|
|
5283
|
+
const endpoint = getControllerEndpoint();
|
|
5284
|
+
if (endpoint.port === null) return false;
|
|
5285
|
+
const baseUrl = `http://127.0.0.1:${endpoint.port}`;
|
|
5250
5286
|
const headers = { "Content-Type": "application/json" };
|
|
5251
|
-
if (
|
|
5287
|
+
if (endpoint.secret) headers.Authorization = `Bearer ${endpoint.secret}`;
|
|
5252
5288
|
const timer = setTimeout(() => controller.abort(), HOT_RELOAD_TIMEOUT_MS);
|
|
5253
5289
|
try {
|
|
5254
5290
|
const probe = await fetch(`${baseUrl}/version`, { headers, signal: controller.signal });
|
|
5255
5291
|
if (!probe.ok) return false;
|
|
5256
5292
|
const info = await probe.json();
|
|
5257
5293
|
if (typeof info?.version !== "string") return false;
|
|
5258
|
-
const listenerPids = lsofListenPids(
|
|
5294
|
+
const listenerPids = lsofListenPids(endpoint.port);
|
|
5259
5295
|
if (listenerPids === null || listenerPids[0] !== status.pid) return false;
|
|
5260
5296
|
const res = await fetch(`${baseUrl}/configs?force=true`, {
|
|
5261
5297
|
method: "PUT",
|
|
@@ -5310,7 +5346,7 @@ function runSudoScript(scriptBody, opts) {
|
|
|
5310
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");
|
|
5311
5347
|
}
|
|
5312
5348
|
ensureDirs();
|
|
5313
|
-
const scriptPath = path5.join(USER_DATA_DIR, opts.file);
|
|
5349
|
+
const scriptPath = path5.join(USER_DATA_DIR, `${opts.file}.${process.pid}.tmp`);
|
|
5314
5350
|
fs9.writeFileSync(scriptPath, scriptBody, { mode: 448 });
|
|
5315
5351
|
fs9.chmodSync(scriptPath, 448);
|
|
5316
5352
|
try {
|
|
@@ -5342,6 +5378,10 @@ function describePidCleanupFailure(err) {
|
|
|
5342
5378
|
return `pid \u6587\u4EF6\u672A\u80FD\u6E05\u7406\uFF08${err.message}\uFF09`;
|
|
5343
5379
|
}
|
|
5344
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
|
+
}
|
|
5345
5385
|
function warnPidCleanupFailed(err) {
|
|
5346
5386
|
if (!err) return;
|
|
5347
5387
|
console.warn(colors.yellow(`\u8B66\u544A: ${describePidCleanupFailure(err)}\uFF0C\u4E0B\u6B21 stop \u4F1A\u518D\u6B21\u5C1D\u8BD5`));
|
|
@@ -5511,13 +5551,14 @@ async function cleanupKernelsOrThrow(ctx) {
|
|
|
5511
5551
|
return result;
|
|
5512
5552
|
}
|
|
5513
5553
|
function buildLegacyCleanupScript() {
|
|
5554
|
+
const toleratedBootoutCodes = [0, ...BOOTOUT_NOT_LOADED_CODES].map((code) => `[ $bootout_code -ne ${code} ]`).join(" && ");
|
|
5514
5555
|
return [
|
|
5515
5556
|
"#!/bin/bash",
|
|
5516
|
-
// bootout 退出码分级:113=未装载(daemon
|
|
5517
|
-
//
|
|
5557
|
+
// bootout 退出码分级:0=成功,3/113=未装载(daemon 已不在,正常);其余是真实
|
|
5558
|
+
// 失败,不能 || true 吞掉后照样 rm plist 报「已清理」
|
|
5518
5559
|
`bootout_code=0`,
|
|
5519
5560
|
`launchctl bootout ${shellQuote(`system/${SERVICE_LABEL}`)} 2>/dev/null || bootout_code=$?`,
|
|
5520
|
-
`if
|
|
5561
|
+
`if ${toleratedBootoutCodes}; then`,
|
|
5521
5562
|
` echo "launchctl bootout \u5931\u8D25\uFF08\u9000\u51FA\u7801 $bootout_code\uFF09" >&2`,
|
|
5522
5563
|
` exit 3`,
|
|
5523
5564
|
`fi`,
|
|
@@ -5826,7 +5867,7 @@ function bootstrapServiceIdempotentOrThrow(what) {
|
|
|
5826
5867
|
}
|
|
5827
5868
|
function bootoutService(timeoutMs = LAUNCHCTL_TIMEOUT_MS) {
|
|
5828
5869
|
const result = runLaunchctl(["bootout", serviceTarget()], timeoutMs);
|
|
5829
|
-
if (result.status === 0 || result.status
|
|
5870
|
+
if (result.status === 0 || isBootoutNotLoaded(result.status)) return;
|
|
5830
5871
|
const detail = result.stderr.trim();
|
|
5831
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`, {
|
|
5832
5873
|
hint: [detail, `\u624B\u52A8\u786E\u8BA4: launchctl print ${serviceTarget()}`].filter(Boolean)
|
|
@@ -6167,6 +6208,8 @@ function redactConfigSecrets(config) {
|
|
|
6167
6208
|
|
|
6168
6209
|
// src/http.ts
|
|
6169
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]);
|
|
6170
6213
|
var MAX_ERROR_BODY_BYTES = 64 * 1024;
|
|
6171
6214
|
function isHttpsUrl(url) {
|
|
6172
6215
|
try {
|
|
@@ -6192,12 +6235,26 @@ function createHttpClient(options = {}) {
|
|
|
6192
6235
|
const timer = setTimeout(() => controller.abort(), timeout);
|
|
6193
6236
|
const signal = config?.signal ? AbortSignal.any([controller.signal, config.signal]) : controller.signal;
|
|
6194
6237
|
try {
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
|
|
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;
|
|
6201
6258
|
}
|
|
6202
6259
|
if (!response.ok) {
|
|
6203
6260
|
let text2 = "";
|
|
@@ -6461,7 +6518,17 @@ async function downloadSubscription(url, subName = "default", signal) {
|
|
|
6461
6518
|
return { proxies, proxyGroups };
|
|
6462
6519
|
}
|
|
6463
6520
|
async function prepareConfigForStart(mode, subName = "default") {
|
|
6464
|
-
|
|
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
|
+
}
|
|
6465
6532
|
const subUrl = getSubscriptions().find((s) => s.name === subName)?.url;
|
|
6466
6533
|
const buildResult = buildConfig(rawContent, mode, { subName, subUrl });
|
|
6467
6534
|
await validateConfigWithKernel(buildResult.config, buildResult.overwriteSummaries);
|
|
@@ -6504,7 +6571,7 @@ function printUpdateResult(r) {
|
|
|
6504
6571
|
} else if (r.aborted) {
|
|
6505
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")}`);
|
|
6506
6573
|
} else {
|
|
6507
|
-
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 || "")})`);
|
|
6508
6575
|
}
|
|
6509
6576
|
}
|
|
6510
6577
|
async function autoUpdateStaleSubscription(options = {}) {
|
|
@@ -7020,13 +7087,17 @@ async function printStatus(args = []) {
|
|
|
7020
7087
|
broken: overwriteBroken
|
|
7021
7088
|
} = listOverwriteFile(activeSub ? { subName: activeSub.name, subUrl: activeSub.url } : void 0);
|
|
7022
7089
|
if (activeSub && overwriteEnabled && overwriteFiles.some((f) => f.kind === "script")) {
|
|
7023
|
-
|
|
7024
|
-
|
|
7025
|
-
|
|
7026
|
-
|
|
7027
|
-
|
|
7028
|
-
|
|
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
|
+
}
|
|
7029
7098
|
}
|
|
7099
|
+
} catch (e) {
|
|
7100
|
+
if (!(e instanceof CliError)) throw e;
|
|
7030
7101
|
}
|
|
7031
7102
|
}
|
|
7032
7103
|
const cached = activeSub ? getSubscriptionsWithCache().find((s) => s.name === activeSub.name) : void 0;
|
|
@@ -7133,23 +7204,23 @@ async function printStatus(args = []) {
|
|
|
7133
7204
|
} else {
|
|
7134
7205
|
console.log(`${colors.gray("\u8BA2\u9605: ")}\u672A\u914D\u7F6E ${colors.gray("(\u6DFB\u52A0: mihomo-cli sub add <url>)")}`);
|
|
7135
7206
|
}
|
|
7136
|
-
printOverwriteLines(overwriteEnabled, overwriteFiles, overwriteBroken
|
|
7207
|
+
printOverwriteLines(overwriteEnabled, overwriteFiles, overwriteBroken);
|
|
7137
7208
|
printServiceLines(service, legacy);
|
|
7138
7209
|
if (kind === "tun") {
|
|
7139
7210
|
console.log(colors.gray("TUN \u4E3A\u4E34\u65F6\u8FDB\u7A0B\uFF1B\u505C\u6B62: mihomo-cli stop\uFF08\u4E4B\u540E mihomo-cli start \u6062\u590D Mixed\uFF09"));
|
|
7140
7211
|
}
|
|
7141
7212
|
console.log("");
|
|
7142
7213
|
}
|
|
7143
|
-
function printOverwriteLines(enabled, files, broken
|
|
7214
|
+
function printOverwriteLines(enabled, files, broken) {
|
|
7144
7215
|
if (!enabled) {
|
|
7145
7216
|
console.log(`${colors.gray("\u8986\u5199: ")}${colors.yellow("\u5DF2\u7981\u7528")}`);
|
|
7146
7217
|
return;
|
|
7147
7218
|
}
|
|
7148
7219
|
const active = files.filter(isActiveOverwrite);
|
|
7149
|
-
const
|
|
7220
|
+
const unmatchedCount = files.filter((f) => f.enabled && f.matched === false).length;
|
|
7150
7221
|
const disabledCount = files.filter((f) => !f.enabled).length;
|
|
7151
7222
|
const suffixes = [];
|
|
7152
|
-
if (
|
|
7223
|
+
if (unmatchedCount > 0) suffixes.push(`${unmatchedCount} \u4E2A\u4E0D\u9002\u7528`);
|
|
7153
7224
|
if (disabledCount > 0) suffixes.push(`${disabledCount} \u4E2A\u5DF2\u7981\u7528`);
|
|
7154
7225
|
const suffix = suffixes.length > 0 ? `\uFF0C${suffixes.join("\uFF0C")}` : "";
|
|
7155
7226
|
if (active.length > 0) {
|
|
@@ -7157,10 +7228,6 @@ function printOverwriteLines(enabled, files, broken, activeSub) {
|
|
|
7157
7228
|
} else {
|
|
7158
7229
|
console.log(`${colors.gray("\u8986\u5199: ")}${colors.green("\u5DF2\u542F\u7528")} (${files.length > 0 ? `\u65E0\u751F\u6548\u6587\u4EF6${suffix}` : "\u65E0\u6587\u4EF6"})`);
|
|
7159
7230
|
}
|
|
7160
|
-
for (const f of unmatched) {
|
|
7161
|
-
const reason = f.kind === "script" ? "\u811A\u672C\u672A\u8FD4\u56DE true" : f.scope ? `\u4F5C\u7528\u57DF ${f.scope}` : "\u4F5C\u7528\u57DF\u53D7\u9650";
|
|
7162
|
-
console.log(colors.gray(` ${shortOverwriteName(f.name)} \u4E0D\u9002\u7528\u4E8E\u5F53\u524D\u8BA2\u9605${activeSub ? ` ${activeSub.name}` : ""}\uFF08${reason}\uFF09`));
|
|
7163
|
-
}
|
|
7164
7231
|
for (const b of broken) {
|
|
7165
7232
|
console.log(colors.red(` ${b.message}`));
|
|
7166
7233
|
for (const line of b.hint) console.log(colors.gray(` ${line}`));
|
|
@@ -7232,40 +7299,41 @@ async function cmdStart(args) {
|
|
|
7232
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"]
|
|
7233
7300
|
});
|
|
7234
7301
|
}
|
|
7235
|
-
const
|
|
7236
|
-
|
|
7237
|
-
await autoUpdateStaleSubscription({ timeout: updateTimeout });
|
|
7238
|
-
}
|
|
7239
|
-
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;
|
|
7240
7304
|
try {
|
|
7241
|
-
|
|
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 "));
|
|
7242
7318
|
} catch (e) {
|
|
7243
|
-
if (e instanceof CliError) throw e;
|
|
7244
|
-
throw
|
|
7319
|
+
if (e instanceof CliError) throw appendTunHint(e);
|
|
7320
|
+
throw e;
|
|
7245
7321
|
}
|
|
7246
|
-
const configInfo = commitPreparedConfig(prepared);
|
|
7247
|
-
console.log([colors.cyan(runtimeModeLabel(targetMode)), sub.name, formatProxySummary(configInfo)].join(" \xB7 "));
|
|
7248
7322
|
try {
|
|
7249
7323
|
const pid = await launchOrRestart(targetMode);
|
|
7250
7324
|
console.log(`${colors.green("\u5DF2\u542F\u52A8")}${pid ? ` (PID ${pid})` : ""}`);
|
|
7251
7325
|
} catch (e) {
|
|
7326
|
+
if (e instanceof CliError) throw appendTunHint(e);
|
|
7252
7327
|
const lines = e.message.split("\n");
|
|
7253
|
-
|
|
7254
|
-
if (targetMode === "tun" && disabledAutoStartForTun) {
|
|
7255
|
-
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");
|
|
7256
|
-
}
|
|
7257
|
-
if (e instanceof CliError) {
|
|
7258
|
-
throw new CliError(e.message, { label: e.label, hint: [...e.hint, ...extraHint] });
|
|
7259
|
-
}
|
|
7260
|
-
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] });
|
|
7261
7329
|
}
|
|
7262
7330
|
try {
|
|
7263
7331
|
await printStatus();
|
|
7264
7332
|
} catch (e) {
|
|
7265
|
-
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)}`));
|
|
7266
7334
|
}
|
|
7267
7335
|
if (targetMode === "mixed") {
|
|
7268
|
-
printSystemProxyHint(
|
|
7336
|
+
printSystemProxyHint(getPortsOrNull()?.mixed ?? DEFAULT_MIXED_PORT);
|
|
7269
7337
|
} else {
|
|
7270
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"));
|
|
7271
7339
|
}
|
|
@@ -7552,7 +7620,9 @@ async function getLatestRelease(repo, opts) {
|
|
|
7552
7620
|
encoding: "utf8",
|
|
7553
7621
|
maxBuffer: 50 * 1024 * 1024,
|
|
7554
7622
|
timeout: KERNEL_HTTP_TIMEOUT + 1e4,
|
|
7555
|
-
signal: opts.signal
|
|
7623
|
+
signal: opts.signal,
|
|
7624
|
+
// no_proxy 例外表会绕过显式 -x——统一出口置空,保 -x 权威(curl-spawn.ts)
|
|
7625
|
+
env: buildCurlSpawnEnv()
|
|
7556
7626
|
});
|
|
7557
7627
|
stdout = result.stdout;
|
|
7558
7628
|
} catch (e) {
|
|
@@ -7630,6 +7700,8 @@ function buildKernelCurlArgs(args) {
|
|
|
7630
7700
|
];
|
|
7631
7701
|
if (args.proxy) {
|
|
7632
7702
|
argv.push("-x", args.proxy);
|
|
7703
|
+
} else {
|
|
7704
|
+
argv.push("--noproxy", "*");
|
|
7633
7705
|
}
|
|
7634
7706
|
argv.push("-o", args.outputPath, args.url);
|
|
7635
7707
|
return argv;
|
|
@@ -7725,7 +7797,8 @@ async function downloadKernel(progressCallback, channel, releaseInfo) {
|
|
|
7725
7797
|
maxBytes,
|
|
7726
7798
|
outputPath: tempPath
|
|
7727
7799
|
}),
|
|
7728
|
-
|
|
7800
|
+
// no_proxy 例外表会绕过显式 -x——统一出口置空,保 -x 权威(curl-spawn.ts)
|
|
7801
|
+
{ stdio: "inherit", env: buildCurlSpawnEnv() }
|
|
7729
7802
|
);
|
|
7730
7803
|
if (curlResult.error) {
|
|
7731
7804
|
if (curlResult.error.code === "ENOENT") {
|
|
@@ -7933,7 +8006,7 @@ async function collectChecks() {
|
|
|
7933
8006
|
currentVersion: getKernelVersion(kernelProbe)
|
|
7934
8007
|
}),
|
|
7935
8008
|
4e3
|
|
7936
|
-
).catch(() => null) : Promise.resolve(null);
|
|
8009
|
+
).catch((e) => e instanceof Error ? e : null) : Promise.resolve(null);
|
|
7937
8010
|
if (!kernelProbe) {
|
|
7938
8011
|
push("\u5185\u6838", "fail", "\u672A\u5B89\u88C5", "mihomo-cli kernel");
|
|
7939
8012
|
} else if (kernelProbe.status === 0 && kernelProbe.version !== null) {
|
|
@@ -8049,7 +8122,7 @@ async function collectChecks() {
|
|
|
8049
8122
|
}
|
|
8050
8123
|
} catch (e) {
|
|
8051
8124
|
const notes = e instanceof CliError ? e.hint.filter((l) => l.trim().length > 0) : void 0;
|
|
8052
|
-
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);
|
|
8053
8126
|
}
|
|
8054
8127
|
} else {
|
|
8055
8128
|
push("\u914D\u7F6E\u6784\u5EFA", "skip", active ? "\u672A\u5B89\u88C5\u5185\u6838\uFF0C\u8DF3\u8FC7\u6821\u9A8C" : "\u65E0\u8BA2\u9605\uFF0C\u8DF3\u8FC7");
|
|
@@ -8065,8 +8138,10 @@ async function collectChecks() {
|
|
|
8065
8138
|
push("\u4EE3\u7406\u8FDE\u901A", "skip", "\u672A\u8FD0\u884C");
|
|
8066
8139
|
}
|
|
8067
8140
|
const kernelInfo = await kernelVersionPromise;
|
|
8068
|
-
|
|
8069
|
-
|
|
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}`);
|
|
8070
8145
|
} else if (kernelInfo?.needsUpdate) {
|
|
8071
8146
|
push("\u5185\u6838\u7248\u672C", "warn", `\u5F53\u524D ${kernelInfo.current}\uFF0C\u6700\u65B0 ${kernelInfo.latest}`, "mihomo-cli kernel");
|
|
8072
8147
|
} else if (kernelInfo) {
|
|
@@ -8279,7 +8354,7 @@ function printChannelLine(channel, isExplicitProxy) {
|
|
|
8279
8354
|
console.log("");
|
|
8280
8355
|
}
|
|
8281
8356
|
function formatChannelSwitchLine(previousError) {
|
|
8282
|
-
const reason = previousError
|
|
8357
|
+
const reason = previousError ? firstLine(previousError.message) : "";
|
|
8283
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:";
|
|
8284
8359
|
}
|
|
8285
8360
|
function buildDownloadFailureError(attempts, isExplicitProxy) {
|
|
@@ -8300,7 +8375,7 @@ function buildDownloadFailureError(attempts, isExplicitProxy) {
|
|
|
8300
8375
|
return new CliError("\u5168\u90E8\u4E0B\u8F7D\u901A\u9053\u5747\u5931\u8D25", {
|
|
8301
8376
|
label: "\u4E0B\u8F7D\u5931\u8D25",
|
|
8302
8377
|
hint: [
|
|
8303
|
-
...attempts.map((a) => ` ${channelLabel(a.channel, isExplicitProxy)}: ${a.error.message
|
|
8378
|
+
...attempts.map((a) => ` ${channelLabel(a.channel, isExplicitProxy)}: ${firstLine(a.error.message)}`),
|
|
8304
8379
|
"",
|
|
8305
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",
|
|
8306
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",
|
|
@@ -8695,6 +8770,9 @@ async function cmdReset(args) {
|
|
|
8695
8770
|
}
|
|
8696
8771
|
recordServiceStopped();
|
|
8697
8772
|
}
|
|
8773
|
+
if (!needsStop && serviceTargeted && cleanup !== null && cleanup.remaining.length > 0) {
|
|
8774
|
+
printResidueWarning(cleanup.remaining);
|
|
8775
|
+
}
|
|
8698
8776
|
const deleted = /* @__PURE__ */ new Set();
|
|
8699
8777
|
for (const target of targets) {
|
|
8700
8778
|
let hadContent = target.id === "service" && (serviceActive || legacy);
|
|
@@ -8772,8 +8850,7 @@ async function cmdInstall(args) {
|
|
|
8772
8850
|
printRestoreSkipped();
|
|
8773
8851
|
return;
|
|
8774
8852
|
}
|
|
8775
|
-
throw
|
|
8776
|
-
label: e.label,
|
|
8853
|
+
throw relabelCliError(e, {
|
|
8777
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"]
|
|
8778
8855
|
});
|
|
8779
8856
|
}
|
|
@@ -8813,8 +8890,7 @@ async function cmdUninstall(args) {
|
|
|
8813
8890
|
if (remaining === null) remaining = getMihomoPids();
|
|
8814
8891
|
if (remaining.length > 0) {
|
|
8815
8892
|
console.log("");
|
|
8816
|
-
|
|
8817
|
-
console.log(MANUAL_PKILL_HINT);
|
|
8893
|
+
printResidueWarning(remaining);
|
|
8818
8894
|
}
|
|
8819
8895
|
console.log(colors.gray("\u91CD\u65B0\u5B89\u88C5: mihomo-cli install"));
|
|
8820
8896
|
console.log(colors.gray("\u5F7B\u5E95\u79FB\u9664 mihomo-cli:"));
|
|
@@ -8859,12 +8935,12 @@ async function cmdStop(args) {
|
|
|
8859
8935
|
import { spawnSync as spawnSync10 } from "child_process";
|
|
8860
8936
|
function printRestartHintIfRunning(variant = "update") {
|
|
8861
8937
|
const state = getRunningState();
|
|
8862
|
-
if (state.running)
|
|
8863
|
-
|
|
8864
|
-
|
|
8865
|
-
|
|
8866
|
-
|
|
8867
|
-
|
|
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("");
|
|
8868
8944
|
}
|
|
8869
8945
|
function printSubscriptionList() {
|
|
8870
8946
|
const subs = getSubscriptionsWithCache();
|
|
@@ -8955,7 +9031,7 @@ async function subAdd(args) {
|
|
|
8955
9031
|
console.log(`\u5DF2\u6DFB\u52A0\u5E76\u5207\u6362\u5230 "${name}" (${formatProxySummary(info)})`);
|
|
8956
9032
|
} catch (e) {
|
|
8957
9033
|
removeSubscription(name);
|
|
8958
|
-
if (e instanceof CliError) throw
|
|
9034
|
+
if (e instanceof CliError) throw relabelCliError(e, { label: "\u6DFB\u52A0\u5931\u8D25" });
|
|
8959
9035
|
throw new CliError(e.message, { label: "\u6DFB\u52A0\u5931\u8D25" });
|
|
8960
9036
|
}
|
|
8961
9037
|
console.log("");
|
|
@@ -8999,7 +9075,7 @@ async function subUpdate(args) {
|
|
|
8999
9075
|
console.log(`\u66F4\u65B0\u8BA2\u9605: ${target.name}`);
|
|
9000
9076
|
const result = await withSpinner("\u4E0B\u8F7D\u8BA2\u9605", () => tryUpdateOne(target));
|
|
9001
9077
|
if (!result.success) {
|
|
9002
|
-
throw new CliError((result.error || "")
|
|
9078
|
+
throw new CliError(firstLine(result.error || ""), { label: "\u66F4\u65B0\u5931\u8D25" });
|
|
9003
9079
|
}
|
|
9004
9080
|
console.log(`\u5DF2\u66F4\u65B0 (${formatProxySummary(result)})`);
|
|
9005
9081
|
console.log("");
|
|
@@ -9062,14 +9138,16 @@ async function subRemove(args) {
|
|
|
9062
9138
|
return;
|
|
9063
9139
|
}
|
|
9064
9140
|
}
|
|
9065
|
-
const { found, switchedTo } = removeSubscription(target.name);
|
|
9141
|
+
const { found, switchedTo, wasActive } = removeSubscription(target.name);
|
|
9066
9142
|
if (!found) {
|
|
9067
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"] });
|
|
9068
9144
|
}
|
|
9069
9145
|
console.log(`\u5DF2\u5220\u9664\u8BA2\u9605 "${target.name}"`);
|
|
9070
9146
|
if (switchedTo) {
|
|
9071
9147
|
console.log(`\u5DF2\u81EA\u52A8\u5207\u6362\u5230 "${switchedTo}"`);
|
|
9072
|
-
|
|
9148
|
+
}
|
|
9149
|
+
if (wasActive) {
|
|
9150
|
+
printRestartHintIfRunning(switchedTo ? "removed-active" : "removed-last");
|
|
9073
9151
|
}
|
|
9074
9152
|
console.log("");
|
|
9075
9153
|
printSubscriptionList();
|
|
@@ -9126,12 +9204,12 @@ function cmdUI(args) {
|
|
|
9126
9204
|
console.log("");
|
|
9127
9205
|
}
|
|
9128
9206
|
const url = UI_URLS[uiName];
|
|
9129
|
-
const
|
|
9207
|
+
const endpoint = getControllerEndpoint();
|
|
9130
9208
|
console.log(`\u6253\u5F00 Web UI: ${uiName}`);
|
|
9131
9209
|
console.log(`\u9875\u9762: ${url}`);
|
|
9132
|
-
console.log(`\u63A7\u5236\u5668: http://127.0.0.1:${
|
|
9133
|
-
const secret =
|
|
9134
|
-
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) {
|
|
9135
9213
|
if (copySecret) {
|
|
9136
9214
|
console.log(
|
|
9137
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")
|