mihomo-cli 4.9.2 → 4.10.0

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 CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.10.0] - 2026-09-13
4
+
5
+ 覆写作用域与单文件开关两项增强,并堵上三个相邻的静默失效。单测 649(+46)。
6
+
7
+ ### 新增
8
+
9
+ - **`match` 支持按订阅名通配限定作用域**:新增 `name` 键(与既有 `subscription` 同义,推荐写法),值支持 shell 风格 `*` / `?` 通配,如 `match: {name: edu*}`。此前同机场的多条订阅(`edu1`/`mini1` URL 同域名)只能逐条列举订阅名,或退回 `url-domain` 把整个机场一并命中,无法按套餐系列区分。通配为**全串匹配**(`edu*` 不命中 `xedu1`,半匹配会让作用域悄悄放宽),不含通配字符时退化为精确比对、老写法行为完全不变,`.`/`+` 等字符按字面处理。匹配走双指针贪心回溯而非正则——初版转义成正则的写法有灾难性回溯,`*a`×20 配 64 字符订阅名实测 70 秒,而 64 正是 `SAFE_NAME_RE` 的长度上限,合法输入就能挂死 CLI(复审时实测发现,新实现同组输入 0ms,与旧版做过 30 万组差分测试结果一致)。两个同义键内部归一到单一字段,判据只有一处;同时出现直接报错(无法判断以谁为准),但展示层回显用户实际写的键名——`ow list` 与内核拒绝提示若显示一个在文件里搜不到的键名,用户无从按图索骥。反向验证:去掉全串锚定 3 条转红、换回正则实现整个测试文件 60s 跑不完
10
+ - **覆写文件顶层 `enabled: false` 可单独停用一个文件**:此前只有 `ow off` 全局总开关,或把文件改名成 `.bak`——后者会让文件从 `ow` 列表里消失,过阵子就忘了还有这份配置。被停用的文件仍完整加载、校验 match 并列在 `ow` 中标注 `[已禁用]`(避免停用期间藏着错误、一启用就炸),只是不参与合并。**只认真布尔**:YAML 1.2 里 `no`/`off` 解析为**字符串**而非布尔(实测 js-yaml 5.3.0),按 truthy 处理会让 `enabled: no` 悄悄保持启用——用户以为停用了、配置却照常生效,故非布尔一律报错并指明写 `false`。与 `match` 同为元数据键、加载时剥离:内核对未知顶层键宽松(实测 `mihomo -t` 放行 `enabled: false`),拦不住要靠 CLI 自己。反向验证:去掉过滤 2 条转红、非布尔按 truthy 1 条转红
11
+
12
+ ### 修复
13
+
14
+ - **元数据键带操作符可绕过剥离**:`enabled!: false` 既不会停用文件,又会被 `parseOverrideKey` 规范成键 `enabled` 落进最终运行配置——剥离发生在解构、早于操作符解析,两头落空,正是本次新功能要消灭的那类「以为停用了其实生效」。`match!` 是同族存量洞(在 `match` 引入时就在,一直没人写过这种形态所以没暴露)。现统一报错并指明直接写 `match:` / `enabled:`;嵌套层同名普通键(如 `dns.enabled`)不受影响
15
+ - **元数据键的大小写/空白变体同样绕过剥离**:YAML 键区分大小写,`Enabled: false` 既不停用文件(剥离用精确键名)又不是任何 mihomo 原生键,会原样写进运行配置,而内核对未知顶层键不报错——用户完全没有反馈。与上一条是同一种静默失效,只是走大小写这条路。判据为「小写去空白后等于 `match`/`enabled`、但原样不等于」,与 `isOverwriteFilenameTypo` 同一思路(只认整体近失,`enabled-by`、`matcher` 这类形近无关键不误伤)
16
+ - **`*` 开头的通配值会让整个覆写文件被静默跳过**:YAML 里 `*` 开头是别名语法,`name: *edu` 解析失败后只打一行「解析失败」、文件不加载。推广订阅名 glob 后前缀通配是很自然的写法,故在解析失败提示里针对 alias 错误追加「请加引号写成 `name: \"*edu\"`」
17
+
18
+ ### 变更
19
+
20
+ - `filterOverwriteFilesByScope` 更名 `selectActiveOverwriteFiles`,`enabled` 与 match 两道过滤合在这一个出口。并列两个导出函数迟早有调用方只调一个,停用文件就会照常合并进配置、还出现在「当前生效的覆写文件」清单里;这类「防线消费点不止一处」的缺口在本仓并发状态机上连修三版才补齐,不想在覆写侧重演一遍。`listOverwriteFile` 是有意的旁路(列表要显示全部文件)
21
+ - `status` 的覆写行与 `--json` 的 `overwrite.files` 只报生效文件(JSON 契约仍是 `string[]`),有停用文件时人读形态补一句「N 个已禁用」;`ow` 列表在有停用文件时于标题补出未禁用数,并补一行「停用单个文件」的用法提示——看到 `[已禁用]` 却不知道怎么改回来是最直接的死路。计数措辞用「未禁用」而非「生效」:该列表看不到活跃订阅、无从判断 match 是否命中,与内核拒绝提示里那份真·生效清单刻意区分
22
+
23
+ ### 测试
24
+
25
+ - 新增 `src/commands/overwrite.spec.ts`(CLI 级,8 条):`ow` 列表与 `status` 的展示此前完全无覆盖,而「被停用的文件仍要列出并标注」是产品承诺——若日后改成加载时直接丢弃,纯单元层面 `selectActiveOverwriteFiles` 照样为空、测不出来。反向验证:改成丢弃后 4 条转红
26
+
3
27
  ## [4.9.2] - 2026-09-12
4
28
 
5
29
  复核 v4.9.1 的 CODE_REVIEW 声明本身时发现的锁定清单遗漏。单测 603(+4)。
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  - 🌐 **订阅管理** - 添加/更新订阅,支持流量统计和到期时间显示
10
10
  - 🔄 **自动更新** - 启动时自动检查并更新过期订阅
11
11
  - 🔍 **模糊匹配** - `sub use` / `update` / `remove` 均支持订阅名称模糊匹配(大小写不敏感)
12
- - 📝 **覆写配置** - 在订阅基础上进行自定义覆写,支持强制覆盖、数组合并、按 name 就地 patch、按订阅限定作用域
12
+ - 📝 **覆写配置** - 在订阅基础上进行自定义覆写,支持强制覆盖、数组合并、按 name 就地 patch、按订阅名通配限定作用域、单文件启停
13
13
  - 🔄 **智能重启** - `sub use` 切换订阅、`ow on/off` 切换覆写后自动重启
14
14
  - 🚀 **进程管理** - 启动/停止/切换模式,自动清理残留进程
15
15
  - 🛡️ **服务托管** - 基于 launchd,崩溃/登录自动拉起,代理后台常驻;日常 `start`/`stop` **全程免密**
@@ -140,6 +140,8 @@ mihomo ui yacd # YACD
140
140
  | `mihomo ow off` | 禁用覆写配置(自动重启) |
141
141
  | `mihomo config [--json]` | 查看当前生效的运行配置(由订阅与覆写推导,停止状态下同样可用;`secret` 脱敏) |
142
142
 
143
+ > `ow on`/`ow off` 是**全局总开关**(一次开关所有覆写)。只想停用某一个文件,在该文件里写 `enabled: false`,见[单个文件的开关](#单个文件的开关enabled)
144
+
143
145
  ### 其他命令
144
146
 
145
147
  | 命令 | 说明 |
@@ -469,12 +471,45 @@ hosts:
469
471
 
470
472
  | 匹配键 | 作用 |
471
473
  | ------------- | ----------------------------- |
472
- | `subscription` | 按订阅名匹配(大小写不敏感,与 `sub use` 口径一致) |
474
+ | `name` | 按订阅名匹配,支持 `*` / `?` 通配(大小写不敏感,与 `sub use` 口径一致) |
475
+ | `subscription` | `name` 的同义写法,能力完全相同;两者不可同时出现 |
473
476
  | `url-domain` | 按订阅 URL 的 hostname 后缀匹配(大小写不敏感) |
474
477
 
475
- `match` 块**写错会直接报错**(键名拼错、值为空、空块),而不是静默忽略后对所有订阅生效——写了 `match` 显然是想限定作用域,悄悄放宽比报错危险得多。
478
+ 订阅名支持 shell 风格通配,**全串匹配**:
479
+
480
+ | 写法 | 命中 | 不命中 |
481
+ | ---- | ---- | ------ |
482
+ | `edu*` | `edu1`、`edu2`、`edu-hk` | `mini1`、`xedu1`(不是半匹配) |
483
+ | `edu?` | `edu1`、`edu2` | `edu-hk`(`?` 只顶一个字符) |
484
+ | `edu1` | `edu1` | `edu10`(不含通配符时就是精确匹配) |
485
+
486
+ 只有 `*` 和 `?` 是通配符,`.`、`+`、`[` 等字符一律按字面处理(不是正则)。
487
+
488
+ > **以 `*` 开头的值必须加引号**:YAML 里 `*` 开头是别名语法,`name: *edu` 会解析失败、整个文件被跳过(CLI 会提示加引号)。写成 `name: "*edu"` 即可。结尾的 `*`(`edu*`)不受影响
489
+
490
+ `match` 块**写错会直接报错**(键名拼错、值为空、空块、`name` 与 `subscription` 同时出现),而不是静默忽略后对所有订阅生效——写了 `match` 显然是想限定作用域,悄悄放宽比报错危险得多。
491
+
492
+ > `url-domain` 命中该域名下的**所有**订阅。同一机场的多条订阅(如 `edu1`、`mini1`)URL 往往同域名,用 `url-domain` 会一并生效;要在同机场内按套餐区分,用 `name` 通配(如 `name: edu*`)。若只是担心某条订阅没有要改的分组,用 `~?key` 就够了(它会自动跳过),不必为此改作用域;`match` 应当按「这份覆写在语义上属于哪些订阅」来写。
493
+
494
+ ### 单个文件的开关(enabled)
495
+
496
+ 在覆写文件顶部写 `enabled: false`,可**只停用这一个文件**,其余覆写照常生效:
497
+
498
+ ```yaml
499
+ # ~/.mihomo-cli/overwrite.seal.yaml
500
+ enabled: false # 暂时停用这份覆写,不用改名或删除
501
+
502
+ +proxies:
503
+ - name: Seal-Host
504
+ type: socks5
505
+ server: 127.0.0.1
506
+ port: 1080
507
+ ```
476
508
 
477
- > `url-domain` 命中该域名下的**所有**订阅。同一机场的多条订阅(如 `edu1`、`mini1`)URL 往往同域名,用 `url-domain` 会一并生效。若只是担心某条订阅没有要改的分组,用 `~?key` 就够了(它会自动跳过),不必为此改作用域;`match` 应当按「这份覆写在语义上属于哪些订阅」来写。
509
+ - 不写该键即启用;被停用的文件**仍会出现在 `mihomo ow` 列表里**并标注 `[已禁用]`(改名成 `.bak` 则会从列表里消失,不知道自己还有这份配置)
510
+ - 与 `mihomo ow off` 是两层:后者是全局总开关,一次关掉所有覆写
511
+ - **必须写 `false`,不能写 `no` / `off`**:YAML 里这两个是字符串而非布尔值,CLI 会直接报错而不是按「真值」放行——否则你以为停用了、配置却照常生效
512
+ - `enabled` 与 `match` 同属元数据键,不会进入最终的 mihomo 运行配置;它们**不接受操作符,也必须小写**(`enabled!`、`+match`、`Enabled` 都会直接报错——那些写法既不停用文件,还会把键当普通配置写进运行配置,而内核对未知顶层键不报错、你不会收到任何提示)
478
513
 
479
514
  ### 示例
480
515
 
@@ -495,9 +530,10 @@ dns!:
495
530
 
496
531
  ```yaml
497
532
  # ~/.mihomo-cli/overwrite.glados.yaml
498
- # 对该机场的所有订阅生效:把订阅下发的 Developer 分组默认选中改为 TW Fixed IP
533
+ # 只对该机场 edu 系列的订阅生效:把订阅下发的 Developer 分组默认选中改为 TW Fixed IP
499
534
  match:
500
- url-domain: glados-config.com
535
+ name: edu* # edu1、edu2 命中;同机场的 mini1 不命中
536
+ url-domain: glados-config.com # 与上一条同时满足才生效(AND)
501
537
 
502
538
  # 用 ~? 而非 ~:该机场的精简套餐没有 Developer 分组,
503
539
  # ~ 会把这段补丁追加成一个缺 type 的残缺分组、导致内核拒绝加载;
@@ -592,7 +628,7 @@ mihomo doctor
592
628
  请修正订阅或覆写;当前运行时配置未改动。
593
629
  ```
594
630
 
595
- 清单已按 `ow` 开关与 `match` 过滤,即**本次真正参与合并**的文件;`(全局)` 表示该文件没有 `match`、对所有订阅生效。没有覆写生效时不显示这一段(问题就在订阅本身)。`mihomo doctor` 给出同样的信息,`mihomo ow list` 可看全部覆写文件
631
+ 清单已按 `ow` 开关、文件内 `enabled` 与 `match` 过滤,即**本次真正参与合并**的文件;`(全局)` 表示该文件没有 `match`、对所有订阅生效,有 `match` 时按你写的键名回显(如 `name=edu*`)。没有覆写生效时不显示这一段(问题就在订阅本身)。`mihomo doctor` 给出同样的信息,`mihomo ow` 可看全部覆写文件(含被停用的)
596
632
 
597
633
  校验通过后仍需确认内核已运行:端口占用、系统权限等启动问题会报错并附日志尾部,退出码非 0。异常退出原因与 `status` 使用同一口径(`退出码 N` 或 `被信号终止(Killed: 9)`)
598
634
 
package/dist/index.js CHANGED
@@ -3844,15 +3844,24 @@ function isOverwriteFilenameTypo(filename) {
3844
3844
  const lower = filename.toLowerCase();
3845
3845
  return lower === "overwrite.yml" || lower === "overwrite.yaml" || /^overwrite\..+\.ya?ml$/.test(lower);
3846
3846
  }
3847
- var MATCH_KEYS = /* @__PURE__ */ new Set(["subscription", "url-domain"]);
3847
+ var MATCH_KEYS = /* @__PURE__ */ new Set(["name", "subscription", "url-domain"]);
3848
+ var SUBSCRIPTION_KEYS = ["name", "subscription"];
3848
3849
  function normalizeMatch(raw, fileName) {
3849
3850
  if (raw == null) return void 0;
3850
3851
  if (typeof raw !== "object" || Array.isArray(raw)) {
3851
- throw new CliError(`\u8986\u5199\u6587\u4EF6 "${fileName}" \u7684 match \u5FC5\u987B\u662F\u5BF9\u8C61\uFF08subscription / url-domain\uFF09`, { label: "\u8986\u5199\u914D\u7F6E\u9519\u8BEF" });
3852
+ throw new CliError(`\u8986\u5199\u6587\u4EF6 "${fileName}" \u7684 match \u5FC5\u987B\u662F\u5BF9\u8C61\uFF08name / url-domain\uFF09`, { label: "\u8986\u5199\u914D\u7F6E\u9519\u8BEF" });
3853
+ }
3854
+ const rawEntries = raw;
3855
+ const writtenSubscriptionKeys = SUBSCRIPTION_KEYS.filter((k) => k in rawEntries);
3856
+ if (writtenSubscriptionKeys.length > 1) {
3857
+ throw new CliError(`\u8986\u5199\u6587\u4EF6 "${fileName}" \u7684 match \u540C\u65F6\u5199\u4E86 name \u4E0E subscription\uFF08\u4E24\u8005\u540C\u4E49\uFF09`, {
3858
+ label: "\u8986\u5199\u914D\u7F6E\u9519\u8BEF",
3859
+ hint: ["\u4E24\u4E2A\u952E\u542B\u4E49\u76F8\u540C\uFF0C\u540C\u65F6\u51FA\u73B0\u65E0\u6CD5\u5224\u65AD\u4EE5\u54EA\u4E2A\u4E3A\u51C6\uFF0C\u8BF7\u53EA\u4FDD\u7559\u4E00\u4E2A\u3002", "\u63A8\u8350\u7528 name\uFF0C\u5982 match: {name: edu*}\u3002"]
3860
+ });
3852
3861
  }
3853
3862
  const result = {};
3854
3863
  const problems = [];
3855
- for (const [key, value] of Object.entries(raw)) {
3864
+ for (const [key, value] of Object.entries(rawEntries)) {
3856
3865
  if (!MATCH_KEYS.has(key)) {
3857
3866
  problems.push(`\u672A\u77E5\u952E "${key}"`);
3858
3867
  continue;
@@ -3862,6 +3871,11 @@ function normalizeMatch(raw, fileName) {
3862
3871
  problems.push(`\u952E "${key}" \u7684\u503C\u4E3A\u7A7A\u6216\u65E0\u6709\u6548\u5B57\u7B26\u4E32`);
3863
3872
  continue;
3864
3873
  }
3874
+ if (key === "name" || key === "subscription") {
3875
+ result.subscription = arr;
3876
+ result.subscriptionKey = key;
3877
+ continue;
3878
+ }
3865
3879
  result[key] = arr;
3866
3880
  }
3867
3881
  if (problems.length > 0) {
@@ -3869,15 +3883,15 @@ function normalizeMatch(raw, fileName) {
3869
3883
  label: "\u8986\u5199\u914D\u7F6E\u9519\u8BEF",
3870
3884
  hint: [
3871
3885
  "match \u5199\u9519\u65F6\u8BE5\u6587\u4EF6\u4E0D\u4F1A\u9650\u5B9A\u4F5C\u7528\u57DF\u3001\u800C\u662F\u5BF9\u6240\u6709\u8BA2\u9605\u751F\u6548\uFF0C\u6545\u76F4\u63A5\u62A5\u9519\u800C\u975E\u5FFD\u7565\u3002",
3872
- `\u53EF\u7528\u952E: ${[...MATCH_KEYS].join(", ")}`,
3873
- "\u793A\u4F8B: match: {subscription: work} \u6216 match: {url-domain: [corp.com, github.com]}"
3886
+ `\u53EF\u7528\u952E: ${[...MATCH_KEYS].join(", ")}\uFF08name \u4E0E subscription \u540C\u4E49\uFF09`,
3887
+ "\u793A\u4F8B: match: {name: edu*} \u6216 match: {url-domain: [corp.com, github.com]}"
3874
3888
  ]
3875
3889
  });
3876
3890
  }
3877
3891
  if (Object.keys(result).length === 0) {
3878
3892
  throw new CliError(`\u8986\u5199\u6587\u4EF6 "${fileName}" \u7684 match \u4E3A\u7A7A\uFF08\u6CA1\u6709\u4EFB\u4F55\u6761\u4EF6\uFF09`, {
3879
3893
  label: "\u8986\u5199\u914D\u7F6E\u9519\u8BEF",
3880
- hint: [`\u53EF\u7528\u952E: ${[...MATCH_KEYS].join(", ")}`, "\u793A\u4F8B: match: {subscription: work}"]
3894
+ hint: [`\u53EF\u7528\u952E: ${[...MATCH_KEYS].join(", ")}\uFF08name \u4E0E subscription \u540C\u4E49\uFF09`, "\u793A\u4F8B: match: {name: work}"]
3881
3895
  });
3882
3896
  }
3883
3897
  return result;
@@ -3886,8 +3900,10 @@ function summarizeMatch(match) {
3886
3900
  if (!match) return void 0;
3887
3901
  const parts = [];
3888
3902
  for (const [key, value] of Object.entries(match)) {
3903
+ if (key === "subscriptionKey") continue;
3904
+ const displayKey = key === "subscription" ? match.subscriptionKey ?? "subscription" : key;
3889
3905
  const vals = Array.isArray(value) ? value : [value];
3890
- parts.push(`${key}=${vals.join("/")}`);
3906
+ parts.push(`${displayKey}=${vals.join("/")}`);
3891
3907
  }
3892
3908
  return parts.length > 0 ? parts.join(", ") : void 0;
3893
3909
  }
@@ -3899,13 +3915,38 @@ function hostMatchesDomain(host, domain) {
3899
3915
  const d = domain.toLowerCase();
3900
3916
  return h === d || h.endsWith(`.${d}`);
3901
3917
  }
3918
+ function nameMatchesPattern(name, pattern) {
3919
+ const n = name.toLowerCase();
3920
+ const p = pattern.toLowerCase();
3921
+ if (!/[*?]/.test(p)) return n === p;
3922
+ let nameIndex = 0;
3923
+ let patternIndex = 0;
3924
+ let starPatternIndex = -1;
3925
+ let starNameIndex = 0;
3926
+ while (nameIndex < n.length) {
3927
+ if (patternIndex < p.length && p[patternIndex] !== "*" && (p[patternIndex] === "?" || p[patternIndex] === n[nameIndex])) {
3928
+ nameIndex++;
3929
+ patternIndex++;
3930
+ } else if (patternIndex < p.length && p[patternIndex] === "*") {
3931
+ starPatternIndex = patternIndex++;
3932
+ starNameIndex = nameIndex;
3933
+ } else if (starPatternIndex !== -1) {
3934
+ patternIndex = starPatternIndex + 1;
3935
+ nameIndex = ++starNameIndex;
3936
+ } else {
3937
+ return false;
3938
+ }
3939
+ }
3940
+ while (patternIndex < p.length && p[patternIndex] === "*") patternIndex++;
3941
+ return patternIndex === p.length;
3942
+ }
3902
3943
  function matchesScope(match, scope) {
3903
3944
  if (!match) return true;
3904
3945
  if (match.subscription) {
3905
3946
  const names = Array.isArray(match.subscription) ? match.subscription : [match.subscription];
3906
3947
  if (!scope?.subName) return false;
3907
- const subName = scope.subName.toLowerCase();
3908
- if (!names.some((n) => n.toLowerCase() === subName)) return false;
3948
+ const subName = scope.subName;
3949
+ if (!names.some((n) => nameMatchesPattern(subName, n))) return false;
3909
3950
  }
3910
3951
  if (match["url-domain"]) {
3911
3952
  const domains = Array.isArray(match["url-domain"]) ? match["url-domain"] : [match["url-domain"]];
@@ -3920,8 +3961,47 @@ function matchesScope(match, scope) {
3920
3961
  }
3921
3962
  return true;
3922
3963
  }
3923
- function filterOverwriteFilesByScope(files, scope) {
3924
- return files.filter((f) => matchesScope(f.match, scope));
3964
+ function selectActiveOverwriteFiles(files, scope) {
3965
+ return files.filter((f) => f.enabled !== false && matchesScope(f.match, scope));
3966
+ }
3967
+ var METADATA_KEYS = /* @__PURE__ */ new Set(["match", "enabled"]);
3968
+ function assertNoMetadataKeyLookalikes(config, fileName) {
3969
+ for (const rawKey of Object.keys(config)) {
3970
+ const parsed = parseOverrideKey(rawKey).key;
3971
+ if (parsed !== rawKey && METADATA_KEYS.has(parsed)) {
3972
+ throw new CliError(`\u8986\u5199\u6587\u4EF6 "${fileName}" \u7684\u5143\u6570\u636E\u952E "${rawKey}" \u4E0D\u652F\u6301\u64CD\u4F5C\u7B26`, {
3973
+ label: "\u8986\u5199\u914D\u7F6E\u9519\u8BEF",
3974
+ hint: [
3975
+ `match \u4E0E enabled \u662F\u672C CLI \u7684\u5143\u6570\u636E\u952E\uFF0C\u5728\u5408\u5E76\u524D\u5C31\u88AB\u5265\u79BB\uFF0C\u5E26\u64CD\u4F5C\u7B26\u5199\u6CD5\uFF08\u5982 ${rawKey}\uFF09\u4E0D\u4F1A\u751F\u6548\uFF0C\u53CD\u800C\u4F1A\u628A ${parsed} \u5F53\u666E\u901A\u914D\u7F6E\u952E\u5199\u8FDB\u8FD0\u884C\u914D\u7F6E\u3002`,
3976
+ `\u8BF7\u76F4\u63A5\u5199 ${parsed}: <\u503C>\u3002`
3977
+ ]
3978
+ });
3979
+ }
3980
+ const normalized = rawKey.trim().toLowerCase();
3981
+ if (normalized !== rawKey && METADATA_KEYS.has(normalized)) {
3982
+ throw new CliError(`\u8986\u5199\u6587\u4EF6 "${fileName}" \u7684 "${rawKey}" \u7591\u4F3C\u60F3\u5199\u5143\u6570\u636E\u952E ${normalized}`, {
3983
+ label: "\u8986\u5199\u914D\u7F6E\u9519\u8BEF",
3984
+ hint: [
3985
+ `YAML \u952E\u533A\u5206\u5927\u5C0F\u5199\u4E0E\u7A7A\u767D\uFF0C"${rawKey}" \u4E0D\u4F1A\u88AB\u8BC6\u522B\u4E3A ${normalized}\u2014\u2014\u6587\u4EF6\u4E0D\u4F1A\u88AB\u505C\u7528/\u9650\u5B9A\u4F5C\u7528\u57DF\uFF0C\u8BE5\u952E\u53CD\u800C\u4F1A\u5F53\u666E\u901A\u914D\u7F6E\u5199\u8FDB\u8FD0\u884C\u914D\u7F6E\uFF08\u5185\u6838\u5BF9\u672A\u77E5\u9876\u5C42\u952E\u4E0D\u62A5\u9519\uFF0C\u4E0D\u4F1A\u6709\u4EFB\u4F55\u63D0\u793A\uFF09\u3002`,
3986
+ `\u8BF7\u5199\u6210 ${normalized}: <\u503C>\u3002`
3987
+ ]
3988
+ });
3989
+ }
3990
+ }
3991
+ }
3992
+ function normalizeEnabled(raw, fileName) {
3993
+ if (raw === void 0) return true;
3994
+ if (typeof raw === "boolean") return raw;
3995
+ throw new CliError(
3996
+ `\u8986\u5199\u6587\u4EF6 "${fileName}" \u7684 enabled \u5FC5\u987B\u662F\u5E03\u5C14\u503C\uFF08true / false\uFF09\uFF0C\u5F53\u524D\u662F ${raw === null ? "null\uFF08\u7A7A\u503C\uFF09" : `${typeof raw}\uFF08${JSON.stringify(raw)}\uFF09`}`,
3997
+ {
3998
+ label: "\u8986\u5199\u914D\u7F6E\u9519\u8BEF",
3999
+ hint: [
4000
+ 'YAML \u4E2D no / off / "false" \u90FD\u4E0D\u662F\u5E03\u5C14\u503C\uFF08\u524D\u4E24\u8005\u88AB\u89E3\u6790\u4E3A\u5B57\u7B26\u4E32\uFF09\uFF0C\u6309\u771F\u503C\u5904\u7406\u4F1A\u8BA9\u672C\u8BE5\u505C\u7528\u7684\u6587\u4EF6\u7EE7\u7EED\u751F\u6548\u3002',
4001
+ "\u505C\u7528\u8BE5\u6587\u4EF6\u8BF7\u5199 enabled: false\uFF0C\u542F\u7528\u53EF\u5199 enabled: true \u6216\u76F4\u63A5\u5220\u6389\u8FD9\u4E00\u884C\u3002"
4002
+ ]
4003
+ }
4004
+ );
3925
4005
  }
3926
4006
  function loadOverwriteFile() {
3927
4007
  const dir = USER_DATA_DIR;
@@ -3944,14 +4024,17 @@ function loadOverwriteFile() {
3944
4024
  const content = fs3.readFileSync(filePath, "utf8");
3945
4025
  const parsed = load(content, { maxAliases: 200 });
3946
4026
  if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
3947
- const { match, ...config } = parsed;
3948
- results.push({ name: file, path: filePath, config, match: normalizeMatch(match, file) });
4027
+ const { match, enabled, ...config } = parsed;
4028
+ assertNoMetadataKeyLookalikes(config, file);
4029
+ results.push({ name: file, path: filePath, config, match: normalizeMatch(match, file), enabled: normalizeEnabled(enabled, file) });
3949
4030
  } else if (parsed !== null) {
3950
4031
  console.warn(`\u8B66\u544A: \u8986\u5199\u6587\u4EF6 "${file}" \u9876\u5C42\u5FC5\u987B\u662F\u5BF9\u8C61\uFF0C\u5DF2\u8DF3\u8FC7`);
3951
4032
  }
3952
4033
  } catch (e) {
3953
4034
  if (e instanceof CliError) throw e;
3954
- console.warn(`\u8B66\u544A: \u8986\u5199\u6587\u4EF6 "${file}" \u89E3\u6790\u5931\u8D25: ${e.message}`);
4035
+ const message = e.message;
4036
+ const aliasHint = /alias/i.test(message) ? '\uFF1B\u82E5\u662F\u4EE5 * \u5F00\u5934\u7684\u901A\u914D\u503C\uFF08\u5982 name: *edu\uFF09\uFF0CYAML \u4F1A\u628A\u5B83\u5F53\u522B\u540D\u8BED\u6CD5\uFF0C\u8BF7\u52A0\u5F15\u53F7\u5199\u6210 name: "*edu"' : "";
4037
+ console.warn(`\u8B66\u544A: \u8986\u5199\u6587\u4EF6 "${file}" \u89E3\u6790\u5931\u8D25: ${message}${aliasHint}`);
3955
4038
  }
3956
4039
  }
3957
4040
  return results;
@@ -3978,7 +4061,8 @@ function listOverwriteFile() {
3978
4061
  name: f.name,
3979
4062
  path: f.path,
3980
4063
  keys: Object.keys(f.config || {}),
3981
- scope: summarizeMatch(f.match)
4064
+ scope: summarizeMatch(f.match),
4065
+ enabled: f.enabled !== false
3982
4066
  }))
3983
4067
  };
3984
4068
  }
@@ -4430,7 +4514,7 @@ function buildConfig(subRawContent, mode, scope) {
4430
4514
  const subscriptionConfig = parseConfigContent(subRawContent, "\u8BA2\u9605\u5185\u5BB9");
4431
4515
  const settings = readSettings();
4432
4516
  const allFiles = settings.overwrite_enabled !== false ? loadOverwriteFile() : [];
4433
- const overwriteFiles = filterOverwriteFilesByScope(allFiles, scope);
4517
+ const overwriteFiles = selectActiveOverwriteFiles(allFiles, scope);
4434
4518
  const { config: withOverwrites, skipped: skippedMerges, operatorShapedKeys } = applyOverwrite(subscriptionConfig, overwriteFiles);
4435
4519
  const overwriteSummaries = overwriteFiles.map(describeOverwriteScope);
4436
4520
  const systemConfig = {};
@@ -6264,7 +6348,11 @@ async function printStatus(args = []) {
6264
6348
  activeSub,
6265
6349
  cached,
6266
6350
  overwriteEnabled,
6267
- overwriteFiles: overwriteFiles.map((f) => f.name),
6351
+ // 只滤掉被 `enabled: false` 停用的文件。**不是**「当前生效的覆写」——这里拿不到
6352
+ // 活跃订阅的 scope(listOverwriteFile 不做 match 过滤),也不受同级 enabled 字段
6353
+ // (全局开关)影响:全局 off 时本数组照样列出文件。真·生效清单只有 buildConfig
6354
+ // 侧的 overwriteSummaries(已按 match 与全局开关过滤)。契约仍是 string[]
6355
+ overwriteFiles: overwriteFiles.filter((f) => f.enabled).map((f) => f.name),
6268
6356
  service,
6269
6357
  legacy
6270
6358
  }),
@@ -6343,11 +6431,14 @@ async function printStatus(args = []) {
6343
6431
  } else {
6344
6432
  console.log(`${colors.gray("\u8BA2\u9605: ")}\u672A\u914D\u7F6E ${colors.gray("(\u6DFB\u52A0: mihomo sub add <url>)")}`);
6345
6433
  }
6346
- if (overwriteEnabled && overwriteFiles.length > 0) {
6347
- const names = overwriteFiles.map((f) => f.name.replace(/^overwrite\.?/, "").replace(/\.ya?ml$/, "") || "\u4E3B\u6587\u4EF6").join(", ");
6348
- console.log(`${colors.gray("\u8986\u5199: ")}${colors.green("\u5DF2\u542F\u7528")} (${names})`);
6434
+ const activeOverwriteFiles = overwriteFiles.filter((f) => f.enabled);
6435
+ const disabledOverwriteCount = overwriteFiles.length - activeOverwriteFiles.length;
6436
+ const disabledSuffix = disabledOverwriteCount > 0 ? `\uFF0C${disabledOverwriteCount} \u4E2A\u5DF2\u7981\u7528` : "";
6437
+ if (overwriteEnabled && activeOverwriteFiles.length > 0) {
6438
+ const names = activeOverwriteFiles.map((f) => f.name.replace(/^overwrite\.?/, "").replace(/\.ya?ml$/, "") || "\u4E3B\u6587\u4EF6").join(", ");
6439
+ console.log(`${colors.gray("\u8986\u5199: ")}${colors.green("\u5DF2\u542F\u7528")} (${names}${disabledSuffix})`);
6349
6440
  } else if (overwriteEnabled) {
6350
- console.log(`${colors.gray("\u8986\u5199: ")}${colors.green("\u5DF2\u542F\u7528")} (\u65E0\u6587\u4EF6)`);
6441
+ console.log(`${colors.gray("\u8986\u5199: ")}${colors.green("\u5DF2\u542F\u7528")} (${disabledOverwriteCount > 0 ? `\u65E0\u751F\u6548\u6587\u4EF6${disabledSuffix}` : "\u65E0\u6587\u4EF6"})`);
6351
6442
  } else {
6352
6443
  console.log(`${colors.gray("\u8986\u5199: ")}${colors.yellow("\u5DF2\u7981\u7528")}`);
6353
6444
  }
@@ -6580,11 +6671,14 @@ function printOverwriteList() {
6580
6671
  console.log(` \u6216 ${path8.join(info.dir, "overwrite.dns.yaml")}`);
6581
6672
  console.log("");
6582
6673
  } else {
6583
- console.log(`${colors.cyan("\u8986\u5199\u6587\u4EF6")} (${info.files.length} \u4E2A\uFF0C\u6309\u987A\u5E8F\u52A0\u8F7D):`);
6674
+ const disabledCount = info.files.filter((f) => !f.enabled).length;
6675
+ const countText = disabledCount > 0 ? `${info.files.length} \u4E2A\uFF0C${info.files.length - disabledCount} \u4E2A\u672A\u7981\u7528\uFF0C\u6309\u987A\u5E8F\u52A0\u8F7D` : `${info.files.length} \u4E2A\uFF0C\u6309\u987A\u5E8F\u52A0\u8F7D`;
6676
+ console.log(`${colors.cyan("\u8986\u5199\u6587\u4EF6")} (${countText}):`);
6584
6677
  console.log("");
6585
6678
  info.files.forEach((f, i) => {
6586
6679
  const num = i < 10 ? ` ${i}` : `${i}`;
6587
- console.log(` ${num}. ${f.name}`);
6680
+ const mark = f.enabled ? "" : ` ${colors.yellow("[\u5DF2\u7981\u7528]")}`;
6681
+ console.log(` ${num}. ${f.name}${mark}`);
6588
6682
  if (f.scope) {
6589
6683
  console.log(` ${colors.gray("\u4F5C\u7528\u57DF: ")}${f.scope}`);
6590
6684
  }
@@ -6596,6 +6690,7 @@ function printOverwriteList() {
6596
6690
  }
6597
6691
  console.log("\u542F\u7528\u8986\u5199: mihomo ow on");
6598
6692
  console.log("\u7981\u7528\u8986\u5199: mihomo ow off");
6693
+ console.log("\u505C\u7528\u5355\u4E2A\u6587\u4EF6: \u5728\u8BE5\u6587\u4EF6\u9876\u90E8\u5199 enabled: false");
6599
6694
  console.log("");
6600
6695
  }
6601
6696
  async function setOverwrite(enabled, args) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mihomo-cli",
3
- "version": "4.9.2",
3
+ "version": "4.10.0",
4
4
  "type": "module",
5
5
  "description": "A terminal-based mihomo (Clash.Meta) client for macOS",
6
6
  "bin": {