mihomo-cli 4.10.0 → 4.11.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,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.11.0] - 2026-09-13
4
+
5
+ 一处展示层误导的修复:`status` 此前会把「不适用于当前订阅」的覆写文件与真正生效的并排列出。单测 657(+8)。
6
+
7
+ ### 变更
8
+
9
+ - **`status` 的覆写行区分「生效」与「不适用」**:此前括号里列的是「目录里没被 `enabled: false` 停用的文件」,不按 `match` 过滤——只对别的订阅生效的文件会和真正生效的混在一行里,长得一模一样。用户拿它解释自己看到的行为(「我明明覆写了」),排查方向整个跑偏。现主行只列本次真正参与合并的文件,未命中的每个展开一行说明原因:`glados 不适用于当前订阅 mini1(作用域 name=edu*)`——文件名、当前订阅、作用域三者凑齐才看得出为什么没命中。两类失效分开计数而不合并成一个数字:「不适用」要改 `match` 或切订阅,「已禁用」要改文件里的 `enabled`,原因与改法都不同。status 判得了 match 是因为它知道当前活跃订阅,而 `mihomo ow` 列表不绑定某条订阅、判不了也不该判,那里维持原样(`listOverwriteFile` 不传 scope 时 `matched` 为 undefined = 未判定,与「未命中」区分)。判据仍是 `matchesScope` 本身,合并闸门也仍只有 `selectActiveOverwriteFiles`——新增的 `matched` 只供展示。反向验证:让 status 不传 scope,5 条新用例转红,另 2 条(`ow` 列表不判 match、全命中时无补充行)按设计恒绿
10
+
11
+ ### 新增
12
+
13
+ - **`status --json` 新增 `overwrite.applied`**:本次真正参与合并的覆写文件清单,三道过滤与 `buildConfig` 对齐(全局开关 → 文件级 `enabled` → 当前订阅的 `match`)。`overwrite.files` 保持旧契约不变(只滤文件级 `enabled`,不按 match、不随全局开关变空),两者并存以免破坏既有脚本
14
+
15
+ ### 修复
16
+
17
+ - **`applied` 漏了全局开关这道过滤**:上一条提交自引入,复查时实跑发现。`ow off` 之后同一份 JSON 里 `enabled` 是 `false`、`applied` 却列着文件,而人读形态此时只说「已禁用」、一个文件都不列——两种形态对不上,也与 `buildConfig` 的实际行为不符(全局关闭时它压根不加载任何覆写文件)。根因是契约注释先写错、实现照着错契约写,现三道过滤对齐并补回归用例
18
+
3
19
  ## [4.10.0] - 2026-09-13
4
20
 
5
21
  覆写作用域与单文件开关两项增强,并堵上三个相邻的静默失效。单测 649(+46)。
package/README.md CHANGED
@@ -491,6 +491,15 @@ hosts:
491
491
 
492
492
  > `url-domain` 命中该域名下的**所有**订阅。同一机场的多条订阅(如 `edu1`、`mini1`)URL 往往同域名,用 `url-domain` 会一并生效;要在同机场内按套餐区分,用 `name` 通配(如 `name: edu*`)。若只是担心某条订阅没有要改的分组,用 `~?key` 就够了(它会自动跳过),不必为此改作用域;`match` 应当按「这份覆写在语义上属于哪些订阅」来写。
493
493
 
494
+ `mihomo status` 会按当前活跃订阅区分「生效」与「不适用」,括号里只列本次真正参与合并的文件:
495
+
496
+ ```text
497
+ 覆写: 已启用 (seal,1 个不适用,1 个已禁用)
498
+ glados 不适用于当前订阅 mini1(作用域 name=edu*)
499
+ ```
500
+
501
+ 「不适用」指文件本身是启用的,只是 `match` 没命中当前订阅——切到命中的订阅(`sub use`)或改 `match` 才会生效,与 `enabled: false` 的「已禁用」是两回事。`mihomo ow` 列表不做这个判断(它不绑定某条订阅),那里的作用域一栏只说明该文件管哪些订阅。`--json` 形态下 `overwrite.applied` 是生效清单(`ow off` 全局关闭时为空数组),`overwrite.files` 仍是「未被 `enabled: false` 停用」的全部文件
502
+
494
503
  ### 单个文件的开关(enabled)
495
504
 
496
505
  在覆写文件顶部写 `enabled: false`,可**只停用这一个文件**,其余覆写照常生效:
package/dist/index.js CHANGED
@@ -4051,7 +4051,7 @@ function applyOverwrite(baseConfig, files) {
4051
4051
  }
4052
4052
  return { config: result, skipped, operatorShapedKeys };
4053
4053
  }
4054
- function listOverwriteFile() {
4054
+ function listOverwriteFile(scope) {
4055
4055
  const files = loadOverwriteFile();
4056
4056
  const enabled = isOverwriteEnabled();
4057
4057
  return {
@@ -4062,7 +4062,8 @@ function listOverwriteFile() {
4062
4062
  path: f.path,
4063
4063
  keys: Object.keys(f.config || {}),
4064
4064
  scope: summarizeMatch(f.match),
4065
- enabled: f.enabled !== false
4065
+ enabled: f.enabled !== false,
4066
+ ...scope ? { matched: matchesScope(f.match, scope) } : {}
4066
4067
  }))
4067
4068
  };
4068
4069
  }
@@ -6307,7 +6308,13 @@ function buildStatusJson(args) {
6307
6308
  stale: args.cached ? isSubscriptionStale(args.cached) : false,
6308
6309
  urgency
6309
6310
  } : null,
6310
- overwrite: { enabled: args.overwriteEnabled, files: args.overwriteFiles },
6311
+ overwrite: {
6312
+ enabled: args.overwriteEnabled,
6313
+ files: args.overwriteFiles.filter((f) => f.enabled).map((f) => f.name),
6314
+ // 全局关闭时 buildConfig 不加载任何覆写,applied 必须空——只滤 enabled/match
6315
+ // 会列出「生效文件」,与同一份 JSON 里的 enabled:false 自相矛盾
6316
+ applied: args.overwriteEnabled ? args.overwriteFiles.filter((f) => f.enabled && f.matched !== false).map((f) => f.name) : []
6317
+ },
6311
6318
  service: {
6312
6319
  installed: args.service.installed,
6313
6320
  loaded: args.service.loaded,
@@ -6327,8 +6334,8 @@ async function printStatus(args = []) {
6327
6334
  const service = getServiceStatus();
6328
6335
  const state = getRunningState(service);
6329
6336
  const info = getConfigInfo();
6330
- const { enabled: overwriteEnabled, files: overwriteFiles } = listOverwriteFile();
6331
6337
  const activeSub = getActiveSubscription();
6338
+ const { enabled: overwriteEnabled, files: overwriteFiles } = listOverwriteFile(activeSub ? { subName: activeSub.name, subUrl: activeSub.url } : void 0);
6332
6339
  const cached = activeSub ? getSubscriptionsWithCache().find((s) => s.name === activeSub.name) : void 0;
6333
6340
  const legacy = detectLegacySystemInstall();
6334
6341
  const { running, pid, kind } = state;
@@ -6348,11 +6355,9 @@ async function printStatus(args = []) {
6348
6355
  activeSub,
6349
6356
  cached,
6350
6357
  overwriteEnabled,
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),
6358
+ // 两个数组在 buildStatusJson 里分出来:files 仍是旧契约(只滤文件级 enabled,
6359
+ // 不按 match、不随全局开关变空),applied 才是本次真正参与合并的
6360
+ overwriteFiles,
6356
6361
  service,
6357
6362
  legacy
6358
6363
  }),
@@ -6431,20 +6436,35 @@ async function printStatus(args = []) {
6431
6436
  } else {
6432
6437
  console.log(`${colors.gray("\u8BA2\u9605: ")}\u672A\u914D\u7F6E ${colors.gray("(\u6DFB\u52A0: mihomo sub add <url>)")}`);
6433
6438
  }
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})`);
6440
- } else if (overwriteEnabled) {
6441
- console.log(`${colors.gray("\u8986\u5199: ")}${colors.green("\u5DF2\u542F\u7528")} (${disabledOverwriteCount > 0 ? `\u65E0\u751F\u6548\u6587\u4EF6${disabledSuffix}` : "\u65E0\u6587\u4EF6"})`);
6442
- } else {
6443
- console.log(`${colors.gray("\u8986\u5199: ")}${colors.yellow("\u5DF2\u7981\u7528")}`);
6444
- }
6439
+ printOverwriteLines(overwriteEnabled, overwriteFiles, activeSub);
6445
6440
  printServiceLines(service, legacy);
6446
6441
  console.log("");
6447
6442
  }
6443
+ function shortOverwriteName(name) {
6444
+ return name.replace(/^overwrite\.?/, "").replace(/\.ya?ml$/, "") || "\u4E3B\u6587\u4EF6";
6445
+ }
6446
+ function printOverwriteLines(enabled, files, activeSub) {
6447
+ if (!enabled) {
6448
+ console.log(`${colors.gray("\u8986\u5199: ")}${colors.yellow("\u5DF2\u7981\u7528")}`);
6449
+ return;
6450
+ }
6451
+ const active = files.filter((f) => f.enabled && f.matched !== false);
6452
+ const unmatched = files.filter((f) => f.enabled && f.matched === false);
6453
+ const disabledCount = files.filter((f) => !f.enabled).length;
6454
+ const suffixes = [];
6455
+ if (unmatched.length > 0) suffixes.push(`${unmatched.length} \u4E2A\u4E0D\u9002\u7528`);
6456
+ if (disabledCount > 0) suffixes.push(`${disabledCount} \u4E2A\u5DF2\u7981\u7528`);
6457
+ const suffix = suffixes.length > 0 ? `\uFF0C${suffixes.join("\uFF0C")}` : "";
6458
+ if (active.length > 0) {
6459
+ console.log(`${colors.gray("\u8986\u5199: ")}${colors.green("\u5DF2\u542F\u7528")} (${active.map((f) => shortOverwriteName(f.name)).join(", ")}${suffix})`);
6460
+ } else {
6461
+ console.log(`${colors.gray("\u8986\u5199: ")}${colors.green("\u5DF2\u542F\u7528")} (${files.length > 0 ? `\u65E0\u751F\u6548\u6587\u4EF6${suffix}` : "\u65E0\u6587\u4EF6"})`);
6462
+ }
6463
+ for (const f of unmatched) {
6464
+ const scope = f.scope ? `\u4F5C\u7528\u57DF ${f.scope}` : "\u4F5C\u7528\u57DF\u53D7\u9650";
6465
+ console.log(colors.gray(` ${shortOverwriteName(f.name)} \u4E0D\u9002\u7528\u4E8E\u5F53\u524D\u8BA2\u9605${activeSub ? ` ${activeSub.name}` : ""}\uFF08${scope}\uFF09`));
6466
+ }
6467
+ }
6448
6468
  function printServiceLines(service, legacy) {
6449
6469
  if (!service.installed && !service.loaded) {
6450
6470
  console.log(`${colors.gray("\u670D\u52A1: ")}${colors.yellow("\u672A\u5B89\u88C5")} ${colors.gray("(mihomo install \u5B89\u88C5\u540E\u53EF\u7528 Mixed \u6A21\u5F0F)")}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mihomo-cli",
3
- "version": "4.10.0",
3
+ "version": "4.11.0",
4
4
  "type": "module",
5
5
  "description": "A terminal-based mihomo (Clash.Meta) client for macOS",
6
6
  "bin": {