mihomo-cli 26.10.110 → 26.10.111

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,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [26.10.111] - 2026-10-12
4
+
5
+ ### 修复
6
+
7
+ - **没有订阅时的报错文案统一**:`config` 从「尚无订阅,无法推导配置」改为与 `sub use`/`update`/`remove` 一致的「没有订阅,请先添加订阅」;`sub update` 在空订阅下原本只抛一句「没有订阅」,现同样附上 `sub add` 指引
8
+
9
+ ### 变更
10
+
11
+ - **SECURITY.md 修正与去重**:删除已在 v26.10.109 移除的旧 root 服务清理条目(该能力不复存在,文档仍把它列为现行行为);「不要用 sudo」「文件权限」的细节统一由 README「安全特性」承载,SECURITY 改为引用,不再两处各写一份
12
+
13
+ ### 变更(内部清理,无用户可见变化)
14
+
15
+ - 删除一批从不被读取的返回字段与从不传值的函数参数;订阅下载与配置准备的订阅名参数去掉 `default` 静默回退改为必传——新调用方漏传不再悄悄写进 default.yaml。测试并发基建统一进 `src/test-support/`(新增 spawn-eval、poll 两个夹具),各 spec 私抄的七处子进程骨架与两份逐字重复的帮助函数随之收敛。957 用例全绿
16
+
3
17
  ## [26.10.110] - 2026-10-11
4
18
 
5
19
  ### 修复
package/README.md CHANGED
@@ -219,7 +219,7 @@ mihomo-cli status # 查看状态
219
219
 
220
220
  > `uninstall` 只卸服务,订阅/内核/日志仍留在数据目录(重装后可继续用)。要彻底移除 mihomo-cli:`mihomo-cli reset --full` 删全部数据,再 `npm uninstall -g mihomo-cli`——`uninstall` 结束时也会提示这两步。
221
221
  >
222
- > **顺序别反**:先 `npm uninstall -g` 的话,LaunchAgent plist 会留下来,而能清理它的命令已经没了(plist 带 `KeepAlive`,仍会尝试拉起一个不存在的内核)。npm 现代版本**不会执行** uninstall 生命周期钩子(实测 npm 11.19.0 三种卸载场景均不触发,官方文档亦注明 uninstall lifecycle scripts 未实现),所以别指望卸载时看到任何提醒——按上面的顺序来。真反了也能救,手动执行:
222
+ > **顺序别反**:先 `npm uninstall -g` 的话,LaunchAgent plist 会留下来,而能清理它的命令已经没了(plist 带 `KeepAlive`,仍会尝试拉起一个不存在的内核)。npm 现代版本**不会执行** uninstall 生命周期钩子,所以别指望卸载时看到任何提醒——按上面的顺序来。真反了也能救,手动执行:
223
223
  >
224
224
  > ```bash
225
225
  > launchctl bootout gui/$(id -u)/com.mihomo-cli.daemon 2>/dev/null
package/dist/index.js CHANGED
@@ -304,13 +304,13 @@ function assertKnownFlags(args, known, command) {
304
304
  });
305
305
  }
306
306
  }
307
- function assertPositionalCount(args, max, startIdx, usage, valueFlags = VALUE_FLAGS) {
307
+ function assertPositionalCount(args, max, startIdx, usage) {
308
308
  if (!args) return;
309
309
  let count = 0;
310
310
  for (let i = startIdx; i < args.length; i++) {
311
311
  const a = args[i];
312
312
  if (a.startsWith("-")) {
313
- if (valueFlags.has(a) && i + 1 < args.length && !args[i + 1].startsWith("-")) i++;
313
+ if (VALUE_FLAGS.has(a) && i + 1 < args.length && !args[i + 1].startsWith("-")) i++;
314
314
  continue;
315
315
  }
316
316
  count++;
@@ -3832,7 +3832,8 @@ function getPortsOrNull(settings = readSettings()) {
3832
3832
  return null;
3833
3833
  }
3834
3834
  }
3835
- function getControllerEndpoint(settings = readSettings()) {
3835
+ function getControllerEndpoint() {
3836
+ const settings = readSettings();
3836
3837
  const port = getPortsOrNull(settings)?.controller ?? null;
3837
3838
  const secret = settings.controller_secret;
3838
3839
  return { port, secret: typeof secret === "string" && secret ? secret : null };
@@ -3917,7 +3918,7 @@ function validateSubscriptionName(name) {
3917
3918
  throw new CliError(`\u8BA2\u9605\u540D\u79F0\u65E0\u6548: "${name}"\uFF0C\u53EA\u5141\u8BB8\u5B57\u6BCD\u3001\u6570\u5B57\u3001\u4E0B\u5212\u7EBF\u3001\u77ED\u6A2A\u7EBF\u548C\u4E2D\u6587\uFF08\u6700\u957F 64 \u5B57\u7B26\uFF09`);
3918
3919
  }
3919
3920
  }
3920
- function addSubscription(url, name = "default") {
3921
+ function addSubscription(url, name) {
3921
3922
  validateSubscriptionName(name);
3922
3923
  updateSettings((settings) => {
3923
3924
  const subs = getSubscriptions(settings);
@@ -4790,8 +4791,8 @@ function judgeScriptMatches(subRawContent, mode, scope, entries) {
4790
4791
  scope
4791
4792
  });
4792
4793
  return { matches: scriptMatches };
4793
- } catch (e) {
4794
- return { matches: [], error: firstLine(e.message ?? String(e)) };
4794
+ } catch {
4795
+ return { matches: [] };
4795
4796
  }
4796
4797
  }
4797
4798
  function deriveRuntimeMode(info) {
@@ -4865,11 +4866,8 @@ ${error.stderr || ""}`).trim();
4865
4866
  fs4.rmSync(stageDir, { recursive: true, force: true });
4866
4867
  }
4867
4868
  }
4868
- function hasConfig() {
4869
- return fs4.existsSync(PATHS.configFile);
4870
- }
4871
4869
  function getConfigInfo() {
4872
- if (!hasConfig()) return null;
4870
+ if (!fs4.existsSync(PATHS.configFile)) return null;
4873
4871
  try {
4874
4872
  const content = fs4.readFileSync(PATHS.configFile, "utf8");
4875
4873
  const cfg = loadYamlSafe(content);
@@ -4963,7 +4961,8 @@ function formatTimestamp(ts) {
4963
4961
  return "\u672A\u77E5";
4964
4962
  }
4965
4963
  }
4966
- function formatLocalTimestamp(d = /* @__PURE__ */ new Date()) {
4964
+ function formatLocalTimestamp() {
4965
+ const d = /* @__PURE__ */ new Date();
4967
4966
  const p = (n) => String(n).padStart(2, "0");
4968
4967
  return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}_${p(d.getHours())}-${p(d.getMinutes())}-${p(d.getSeconds())}`;
4969
4968
  }
@@ -5226,26 +5225,15 @@ function isPidFileOwnedByRoot() {
5226
5225
  return false;
5227
5226
  }
5228
5227
  }
5229
- function checkStaleState() {
5230
- const allPids = getMihomoPids();
5231
- return {
5232
- needsCleanup: allPids.length > 0 || isPidFileOwnedByRoot(),
5233
- allPids
5234
- };
5235
- }
5236
5228
  function getStatus() {
5237
5229
  const pid = getPid();
5238
- if (!pid) return { running: false, pid: null, processInfo: null };
5230
+ if (!pid) return { running: false, pid: null, memory: null };
5239
5231
  const p = probeProcess(pid);
5240
- if (!isProbedMihomo(p)) return { running: false, pid: null, processInfo: null };
5232
+ if (!isProbedMihomo(p)) return { running: false, pid: null, memory: null };
5241
5233
  return {
5242
5234
  running: true,
5243
5235
  pid,
5244
- processInfo: {
5245
- pid,
5246
- memory: p.rss ? `${(p.rss / 1024).toFixed(1)} MB` : "\u672A\u77E5",
5247
- isRoot: p.uid === "0"
5248
- }
5236
+ memory: p.rss ? `${(p.rss / 1024).toFixed(1)} MB` : "\u672A\u77E5"
5249
5237
  };
5250
5238
  }
5251
5239
 
@@ -6259,7 +6247,7 @@ function createHttpClient(options = {}) {
6259
6247
  }
6260
6248
  const text = await readBodyWithLimit(response, controller, MAX_RESPONSE_BYTES);
6261
6249
  const data = config?.responseType === "json" ? JSON.parse(text) : text;
6262
- return { data, headers: response.headers, status: response.status };
6250
+ return { data, headers: response.headers };
6263
6251
  } catch (e) {
6264
6252
  if (controller.signal.aborted && e.name === "AbortError") {
6265
6253
  throw new Error(`\u8BF7\u6C42\u8D85\u65F6\uFF08${Math.round(timeout / 1e3)}s\uFF09: ${maskUrl(url)}`);
@@ -6409,14 +6397,17 @@ function getActiveSubscription() {
6409
6397
  }
6410
6398
  return subs[0];
6411
6399
  }
6400
+ function noSubscriptionsError() {
6401
+ return new CliError("\u6CA1\u6709\u8BA2\u9605\uFF0C\u8BF7\u5148\u6DFB\u52A0\u8BA2\u9605", { hint: "\u6DFB\u52A0\u8BA2\u9605: mihomo-cli sub add <url>" });
6402
+ }
6412
6403
  function requireActiveSubscription() {
6413
6404
  const sub = getActiveSubscription();
6414
6405
  if (!sub) {
6415
- throw new CliError("\u6CA1\u6709\u8BA2\u9605\uFF0C\u8BF7\u5148\u6DFB\u52A0\u8BA2\u9605", { hint: "\u6DFB\u52A0\u8BA2\u9605: mihomo-cli sub add <url>" });
6406
+ throw noSubscriptionsError();
6416
6407
  }
6417
6408
  return sub;
6418
6409
  }
6419
- function findSubscriptionFuzzy(subs, pattern) {
6410
+ function resolveSubscription(subs, pattern) {
6420
6411
  const lowerPattern = pattern.toLowerCase();
6421
6412
  const exact = [];
6422
6413
  const prefix = [];
@@ -6431,22 +6422,15 @@ function findSubscriptionFuzzy(subs, pattern) {
6431
6422
  includes.push(s);
6432
6423
  }
6433
6424
  }
6434
- if (exact.length > 0) return exact;
6435
- if (prefix.length > 0) return prefix;
6436
- return includes;
6437
- }
6438
- function pickSingleSubscription(subs, pattern) {
6439
- if (subs.length === 0) {
6425
+ const matched = exact.length > 0 ? exact : prefix.length > 0 ? prefix : includes;
6426
+ if (matched.length === 0) {
6440
6427
  throw new CliError(`\u672A\u627E\u5230\u5339\u914D "${pattern}" \u7684\u8BA2\u9605`);
6441
6428
  }
6442
- if (subs.length === 1) return subs[0];
6429
+ if (matched.length === 1) return matched[0];
6443
6430
  throw new CliError("\u5339\u914D\u5230\u591A\u4E2A\u8BA2\u9605\uFF0C\u8BF7\u66F4\u7CBE\u786E\u6307\u5B9A", {
6444
- hint: ["", "\u5339\u914D\u7684\u8BA2\u9605:", ...subs.map((s) => ` ${s.name}`)]
6431
+ hint: ["", "\u5339\u914D\u7684\u8BA2\u9605:", ...matched.map((s) => ` ${s.name}`)]
6445
6432
  });
6446
6433
  }
6447
- function resolveSubscription(subs, pattern) {
6448
- return pickSingleSubscription(findSubscriptionFuzzy(subs, pattern), pattern);
6449
- }
6450
6434
  function assertLooksLikeSubscription(parsed, maskedUrl) {
6451
6435
  const hasProxies = Array.isArray(parsed.proxies) && parsed.proxies.length > 0;
6452
6436
  const hasGroups = Array.isArray(parsed["proxy-groups"]) && parsed["proxy-groups"].length > 0;
@@ -6466,7 +6450,7 @@ function assertLooksLikeSubscription(parsed, maskedUrl) {
6466
6450
  ]
6467
6451
  });
6468
6452
  }
6469
- async function downloadSubscription(url, subName = "default", signal) {
6453
+ async function downloadSubscription(url, subName, signal) {
6470
6454
  let response;
6471
6455
  try {
6472
6456
  response = await HTTP_CLIENT.get(url, { responseType: "text", signal });
@@ -6506,7 +6490,7 @@ async function downloadSubscription(url, subName = "default", signal) {
6506
6490
  const { proxies, proxyGroups } = countConfigNodes(parsed);
6507
6491
  return { proxies, proxyGroups };
6508
6492
  }
6509
- async function prepareConfigForStart(mode, subName = "default") {
6493
+ async function prepareConfigForStart(mode, subName) {
6510
6494
  let rawContent;
6511
6495
  try {
6512
6496
  rawContent = requireSubscriptionRawConfig(subName);
@@ -6609,7 +6593,7 @@ function cmdConfig(args = []) {
6609
6593
  const reveal = hasFlag(args, "--reveal");
6610
6594
  const active = getActiveSubscription();
6611
6595
  if (!active) {
6612
- throw new CliError("\u5C1A\u65E0\u8BA2\u9605\uFF0C\u65E0\u6CD5\u63A8\u5BFC\u914D\u7F6E", { hint: "\u6DFB\u52A0\u8BA2\u9605: mihomo-cli sub add <url>" });
6596
+ throw noSubscriptionsError();
6613
6597
  }
6614
6598
  const rawContent = requireSubscriptionRawConfig(active.name);
6615
6599
  const mode = deriveRuntimeMode(getConfigInfo());
@@ -6655,10 +6639,6 @@ function openUrl(url) {
6655
6639
  } catch {
6656
6640
  }
6657
6641
  }
6658
- function openLogFile(logPath) {
6659
- console.log(`\u7528\u7CFB\u7EDF\u9ED8\u8BA4\u7A0B\u5E8F\u6253\u5F00: ${logPath}`);
6660
- openUrl(logPath);
6661
- }
6662
6642
  function viewLogWithTail(logPath, options) {
6663
6643
  const follow = options?.follow;
6664
6644
  const lines = options?.lines || 100;
@@ -6771,13 +6751,11 @@ async function startTun(prefetched) {
6771
6751
  }
6772
6752
  }
6773
6753
  }
6774
- const staleState = checkStaleState();
6775
- if (staleState.needsCleanup) {
6776
- if (staleState.allPids.length > 0) {
6777
- console.log(`\u6E05\u7406 ${staleState.allPids.length} \u4E2A\u6B8B\u7559\u8FDB\u7A0B...`);
6778
- } else {
6779
- console.log("\u6E05\u7406\u6B8B\u7559\u7684 root pid \u6587\u4EF6...");
6780
- }
6754
+ const stalePids = getMihomoPids();
6755
+ if (stalePids.length > 0) {
6756
+ console.log(`\u6E05\u7406 ${stalePids.length} \u4E2A\u6B8B\u7559\u8FDB\u7A0B...`);
6757
+ } else if (isPidFileOwnedByRoot()) {
6758
+ console.log("\u6E05\u7406\u6B8B\u7559\u7684 root pid \u6587\u4EF6...");
6781
6759
  }
6782
6760
  console.log("TUN \u6A21\u5F0F\u9700\u8981 sudo \u6743\u9650...");
6783
6761
  runSudoScript(buildTunLaunchScript(), {
@@ -6804,13 +6782,13 @@ function getRuntimeMode() {
6804
6782
  function getRunningState(serviceStatus) {
6805
6783
  const service = serviceStatus ?? getServiceStatus({ withDisabled: false });
6806
6784
  if (service.running) {
6807
- return { running: true, pid: service.pid, kind: "service", processInfo: null };
6785
+ return { running: true, pid: service.pid, kind: "service", memory: null };
6808
6786
  }
6809
6787
  const status = getStatus();
6810
6788
  if (status.running) {
6811
- return { running: true, pid: status.pid, kind: "tun", processInfo: status.processInfo };
6789
+ return { running: true, pid: status.pid, kind: "tun", memory: status.memory };
6812
6790
  }
6813
- return { running: false, pid: null, kind: null, processInfo: null };
6791
+ return { running: false, pid: null, kind: null, memory: null };
6814
6792
  }
6815
6793
  function restartModeFor(state, fallbackMode) {
6816
6794
  return state.kind === "tun" ? "tun" : fallbackMode;
@@ -7151,8 +7129,8 @@ async function printStatus(args = []) {
7151
7129
  );
7152
7130
  if (pid) {
7153
7131
  console.log(`${colors.gray("PID: ")}${pid}`);
7154
- if (kind === "tun" && state.processInfo) {
7155
- console.log(`${colors.gray("\u5185\u5B58: ")}${state.processInfo.memory}`);
7132
+ if (kind === "tun" && state.memory) {
7133
+ console.log(`${colors.gray("\u5185\u5B58: ")}${state.memory}`);
7156
7134
  }
7157
7135
  }
7158
7136
  if (info) {
@@ -8511,7 +8489,8 @@ function cmdLogs(args) {
8511
8489
  hint: "\u8DDF\u968F\u8F93\u51FA\u8BF7\u53BB\u6389 -o: mihomo-cli logs 0 -f"
8512
8490
  });
8513
8491
  }
8514
- openLogFile(logPath);
8492
+ console.log(`\u7528\u7CFB\u7EDF\u9ED8\u8BA4\u7A0B\u5E8F\u6253\u5F00: ${logPath}`);
8493
+ openUrl(logPath);
8515
8494
  return;
8516
8495
  }
8517
8496
  viewLogWithTail(logPath, { follow, lines });
@@ -9002,7 +8981,7 @@ async function subUpdate(args) {
9002
8981
  const nameArg = getNonFlagArg(args, 2);
9003
8982
  const subs = getSubscriptions();
9004
8983
  if (subs.length === 0) {
9005
- throw new CliError("\u6CA1\u6709\u8BA2\u9605");
8984
+ throw noSubscriptionsError();
9006
8985
  }
9007
8986
  if (nameArg === "") {
9008
8987
  throw new CliError("\u8BF7\u6307\u5B9A\u8BA2\u9605\u540D\u79F0", { hint: ["\u66F4\u65B0\u6240\u6709\u8BA2\u9605\u76F4\u63A5\u6267\u884C: mihomo-cli sub update", `\u66F4\u65B0\u6307\u5B9A\u8BA2\u9605: mihomo-cli sub update <\u540D\u79F0>`] });
@@ -9047,7 +9026,7 @@ async function subUse(args) {
9047
9026
  const name = getNonFlagArg(args, 2);
9048
9027
  const subs = getSubscriptions();
9049
9028
  if (subs.length === 0) {
9050
- throw new CliError("\u6CA1\u6709\u8BA2\u9605\uFF0C\u8BF7\u5148\u6DFB\u52A0\u8BA2\u9605", { hint: "mihomo-cli sub add <url> [name]" });
9029
+ throw noSubscriptionsError();
9051
9030
  }
9052
9031
  if (!name) {
9053
9032
  throw new CliError("\u8BF7\u6307\u5B9A\u8BA2\u9605\u540D\u79F0", {
@@ -9077,7 +9056,7 @@ async function subRemove(args) {
9077
9056
  const name = getNonFlagArg(args, 2);
9078
9057
  const subs = getSubscriptions();
9079
9058
  if (subs.length === 0) {
9080
- throw new CliError("\u6CA1\u6709\u8BA2\u9605\uFF0C\u8BF7\u5148\u6DFB\u52A0\u8BA2\u9605", { hint: "mihomo-cli sub add <url> [name]" });
9059
+ throw noSubscriptionsError();
9081
9060
  }
9082
9061
  if (!name) {
9083
9062
  throw new CliError("\u8BF7\u6307\u5B9A\u8981\u5220\u9664\u7684\u8BA2\u9605\u540D\u79F0", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mihomo-cli",
3
- "version": "26.10.110",
3
+ "version": "26.10.111",
4
4
  "type": "module",
5
5
  "description": "A terminal-based mihomo (Clash.Meta) client for macOS",
6
6
  "bin": {