mihomo-cli 26.10.96 → 26.10.97

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/README.md CHANGED
@@ -398,6 +398,13 @@ mihomo start --update-timeout=30000 # 长选项 + 等号
398
398
 
399
399
  可通过环境变量 `MIHOMO_CLI_DIR` 自定义数据目录位置。
400
400
 
401
+ 其他环境变量:
402
+
403
+ | 变量 | 用途 |
404
+ | --- | --- |
405
+ | `MIHOMO_CLI_ALLOW_ANY_PLATFORM=1` | 非 macOS 上绕过平台守卫,仅供开发调试(功能不保证可用) |
406
+ | `MIHOMO_CLI_DAEMON_LABEL` | 覆盖服务 label,仅供隔离测试使用(随意改名会遗留无法管理的自启进程,日常勿设) |
407
+
401
408
  ## 覆写配置
402
409
 
403
410
  覆写配置允许你在订阅配置基础上进行自定义修改,原始订阅文件保持独立
package/dist/index.js CHANGED
@@ -3935,7 +3935,7 @@ function parseOverrideKey(key) {
3935
3935
  return { key: actualKey, forceOverwrite, arrayPrepend, arrayAppend };
3936
3936
  }
3937
3937
  function assertValidParsedKey(rawKey, parsed) {
3938
- if (rawKey.startsWith("~")) {
3938
+ if (rawKey.startsWith("~") || parsed.key.includes("~")) {
3939
3939
  throw new CliError(`\u8986\u5199\u952E "${rawKey}" \u7528\u4E86\u5DF2\u79FB\u9664\u7684 ~ \u64CD\u4F5C\u7B26`, {
3940
3940
  label: "\u8986\u5199\u914D\u7F6E\u9519\u8BEF",
3941
3941
  hint: ["\u6309 name \u5408\u5E76/\u8FFD\u52A0\u6570\u7EC4\u5143\u7D20\u7684 ~ \u4E0E ~? \u5DF2\u79FB\u9664\uFF0C\u6539\u7528 JS \u8986\u5199\u811A\u672C\uFF08README\u300C\u8986\u5199\u914D\u7F6E\u300D\u7AE0\u8282\u7684\u811A\u672C\u4E00\u8282\uFF09\u3002"]
@@ -3953,6 +3953,12 @@ function assertValidParsedKey(rawKey, parsed) {
3953
3953
  hint: ["\u64CD\u4F5C\u7B26\uFF08!\u3001+\uFF09\u5FC5\u987B\u4FEE\u9970\u4E00\u4E2A\u771F\u5B9E\u7684\u952E\u540D\uFF0C\u5982 rules+\u3001dns!\u3002"]
3954
3954
  });
3955
3955
  }
3956
+ if (parsed.key.includes("!")) {
3957
+ throw new CliError(`\u8986\u5199\u952E "${rawKey}" \u7684\u64CD\u4F5C\u7B26\u4F4D\u7F6E\u77DB\u76FE`, {
3958
+ label: "\u8986\u5199\u914D\u7F6E\u9519\u8BEF",
3959
+ 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"]
3960
+ });
3961
+ }
3956
3962
  const ops = [];
3957
3963
  if (parsed.forceOverwrite) ops.push("!\uFF08\u6574\u4F53\u8986\u76D6\uFF09");
3958
3964
  if (parsed.arrayPrepend) ops.push("+\u524D\u7F00\uFF08\u6570\u7EC4\u524D\u63D2\uFF09");
@@ -3969,6 +3975,12 @@ function describeValueKind(value) {
3969
3975
  if (typeof value === "object") return "\u6620\u5C04";
3970
3976
  return `\u6807\u91CF\uFF08${typeof value}\uFF09`;
3971
3977
  }
3978
+ function protoKeyInOverwriteError() {
3979
+ return new CliError('\u8986\u5199\u91CC\u51FA\u73B0\u4E86 "__proto__" \u952E', {
3980
+ label: "\u8986\u5199\u914D\u7F6E\u9519\u8BEF",
3981
+ hint: ["\u6B63\u5E38 mihomo \u914D\u7F6E\u6CA1\u6709\u8FD9\u4E2A\u952E\uFF0C\u8BF7\u68C0\u67E5\u8986\u5199\u6587\u4EF6\u7684\u5185\u5BB9\u4E0E\u6765\u6E90\u3002"]
3982
+ });
3983
+ }
3972
3984
  function mergeConfigLevel(target, override, parseOperators) {
3973
3985
  let t = target;
3974
3986
  if (t === null || t === void 0) {
@@ -3994,10 +4006,7 @@ function mergeConfigLevel(target, override, parseOperators) {
3994
4006
  assertValidParsedKey(rawKey, { key, forceOverwrite, arrayPrepend, arrayAppend });
3995
4007
  }
3996
4008
  if (key === "__proto__") {
3997
- throw new CliError('\u8986\u5199\u91CC\u51FA\u73B0\u4E86 "__proto__" \u952E', {
3998
- label: "\u8986\u5199\u914D\u7F6E\u9519\u8BEF",
3999
- hint: ["\u6B63\u5E38 mihomo \u914D\u7F6E\u6CA1\u6709\u8FD9\u4E2A\u952E\uFF0C\u8BF7\u68C0\u67E5\u8986\u5199\u6587\u4EF6\u7684\u5185\u5BB9\u4E0E\u6765\u6E90\u3002"]
4000
- });
4009
+ throw protoKeyInOverwriteError();
4001
4010
  }
4002
4011
  const existingValue = result[key];
4003
4012
  if (arrayPrepend || arrayAppend) {
@@ -4086,22 +4095,22 @@ function normalizeMatch(raw, fileName) {
4086
4095
  problems.push(`\u672A\u77E5\u952E "${key}"`);
4087
4096
  continue;
4088
4097
  }
4089
- const arr = (Array.isArray(value) ? value : [value]).filter((v) => typeof v === "string" && v.length > 0);
4098
+ const arr = (Array.isArray(value) ? value : [value]).map((v) => typeof v === "string" ? v.trim() : v).filter((v) => typeof v === "string" && v.length > 0);
4090
4099
  if (arr.length === 0) {
4091
4100
  problems.push(`\u952E "${key}" \u7684\u503C\u4E3A\u7A7A\u6216\u65E0\u6709\u6548\u5B57\u7B26\u4E32`);
4092
4101
  continue;
4093
4102
  }
4094
4103
  if (key === "url-domain") {
4095
- const wildcard = arr.find((v) => v.includes("*") || v.includes("?"));
4096
- if (wildcard) {
4097
- problems.push(`url-domain \u4E0D\u652F\u6301\u901A\u914D\u7B26\uFF08\u5F53\u524D\u503C "${wildcard}"\uFF09\uFF0C\u53EA\u505A\u5B57\u9762\u540E\u7F00\u6BD4\u5BF9`);
4104
+ const badEntry = arr.map((v) => [v, urlDomainValueProblem(v)]).find(([, p]) => p !== void 0);
4105
+ if (badEntry) {
4106
+ problems.push(badEntry[1]);
4098
4107
  continue;
4099
4108
  }
4100
4109
  }
4101
4110
  if (key === "name") {
4102
- const bad = arr.find((v) => !isValidNamePattern(v));
4103
- if (bad !== void 0) {
4104
- throw new CliError(`\u8986\u5199\u6587\u4EF6 "${fileName}" \u7684 name \u901A\u914D\u5199\u6CD5\u4E0D\u652F\u6301: "${bad}"`, {
4111
+ const badWildcard = arr.find((v) => !isValidNamePattern(v));
4112
+ if (badWildcard !== void 0) {
4113
+ throw new CliError(`\u8986\u5199\u6587\u4EF6 "${fileName}" \u7684 name \u901A\u914D\u5199\u6CD5\u4E0D\u652F\u6301: "${badWildcard}"`, {
4105
4114
  label: "\u8986\u5199\u914D\u7F6E\u9519\u8BEF",
4106
4115
  hint: [
4107
4116
  "\u8BA2\u9605\u540D\u5339\u914D\u53EA\u652F\u6301\u4E24\u79CD\u901A\u914D\uFF1A\u5C3E\u90E8 *\uFF08\u524D\u7F00\uFF0Cedu* \u547D\u4E2D edu1\u3001\u4E0D\u547D\u4E2D xedu1\uFF09\u4E0E\u5934\u90E8 *\uFF08\u540E\u7F00\uFF0C*edu\uFF09\u3002",
@@ -4109,6 +4118,16 @@ function normalizeMatch(raw, fileName) {
4109
4118
  ]
4110
4119
  });
4111
4120
  }
4121
+ const impossible = arr.find((v) => !v.includes("*") && !SAFE_NAME_RE.test(v));
4122
+ if (impossible !== void 0) {
4123
+ throw new CliError(`\u8986\u5199\u6587\u4EF6 "${fileName}" \u7684 name \u503C\u4E0D\u53EF\u80FD\u5339\u914D\u4EFB\u4F55\u8BA2\u9605: "${impossible}"`, {
4124
+ label: "\u8986\u5199\u914D\u7F6E\u9519\u8BEF",
4125
+ hint: [
4126
+ "\u8BA2\u9605\u540D\u53EA\u80FD\u542B\u5B57\u6BCD\u6570\u5B57\u3001\u4E0B\u5212\u7EBF\u3001\u8FDE\u5B57\u7B26\u4E0E\u4E2D\u6587\uFF081-64 \u5B57\u7B26\uFF09\uFF0C\u8BF7\u68C0\u67E5\u662F\u5426\u8BEF\u5E26\u4E86 /\u3001~\u3001\u7A7A\u683C\u3001\u70B9\u53F7\u7B49\u5B57\u7B26\u3002",
4127
+ "\u66F4\u590D\u6742\u7684\u5339\u914D\u5199 JS \u8986\u5199\u811A\u672C\uFF08README\u300C\u8986\u5199\u914D\u7F6E\u300D\u7AE0\u8282\uFF09\u3002"
4128
+ ]
4129
+ });
4130
+ }
4112
4131
  }
4113
4132
  result[key] = arr;
4114
4133
  }
@@ -4137,6 +4156,18 @@ function isValidNamePattern(value) {
4137
4156
  if (value.indexOf("*", star + 1) !== -1) return false;
4138
4157
  return star === 0 || star === value.length - 1;
4139
4158
  }
4159
+ function urlDomainValueProblem(value) {
4160
+ if (value.includes("*") || value.includes("?")) {
4161
+ return `url-domain \u4E0D\u652F\u6301\u901A\u914D\u7B26\uFF08\u5F53\u524D\u503C "${value}"\uFF09\uFF0C\u53EA\u505A\u5B57\u9762\u540E\u7F00\u6BD4\u5BF9`;
4162
+ }
4163
+ if (/[:/]/.test(value)) {
4164
+ return `url-domain \u53EA\u8981\u88F8\u57DF\u540D\uFF08\u5F53\u524D\u503C "${value}"\uFF09\uFF1A\u4E0D\u8981\u5E26\u534F\u8BAE\u3001\u8DEF\u5F84\u6216\u7AEF\u53E3\uFF0C\u8BF7\u53BB\u6389 https://\u3001\u5C3E\u659C\u6760\u4E0E\u7AEF\u53E3`;
4165
+ }
4166
+ if (/\s/.test(value)) {
4167
+ return `url-domain \u53EA\u8981\u88F8\u57DF\u540D\uFF08\u5F53\u524D\u503C "${value}"\uFF09\uFF1A\u503C\u4E2D\u4E0D\u80FD\u542B\u7A7A\u683C`;
4168
+ }
4169
+ return void 0;
4170
+ }
4140
4171
  function summarizeMatch(match) {
4141
4172
  if (!match) return void 0;
4142
4173
  const parts = [];
@@ -4214,6 +4245,7 @@ function assertFileLevelOperatorRules(config, fileName) {
4214
4245
  for (const rawKey of Object.keys(config)) {
4215
4246
  const parsed = parseOverrideKey(rawKey);
4216
4247
  assertValidParsedKey(rawKey, parsed);
4248
+ if (parsed.key === "__proto__") throw protoKeyInOverwriteError();
4217
4249
  if (!parsed.arrayPrepend && !parsed.arrayAppend) continue;
4218
4250
  const base = BASE_CONFIG[parsed.key];
4219
4251
  if (base === void 0 || Array.isArray(base)) continue;
@@ -4729,8 +4761,12 @@ function formatTraffic(upload, download, total) {
4729
4761
  function formatTimestamp(ts) {
4730
4762
  if (ts === void 0 || ts === null) return "\u672A\u77E5";
4731
4763
  if (ts === 0) return "\u6C38\u4E45";
4764
+ const num = Number(ts);
4765
+ if (!Number.isFinite(num) || num < 0) return "\u672A\u77E5";
4732
4766
  try {
4733
- return new Date(ts * 1e3).toLocaleString("zh-CN");
4767
+ const date = new Date(num * 1e3);
4768
+ if (Number.isNaN(date.getTime())) return "\u672A\u77E5";
4769
+ return date.toLocaleString("zh-CN");
4734
4770
  } catch {
4735
4771
  return "\u672A\u77E5";
4736
4772
  }
@@ -5053,6 +5089,9 @@ function sudoExitToError(action, status, codeMessages) {
5053
5089
  const custom = codeMessages?.[status];
5054
5090
  return new Error(custom ?? `${action}\u5931\u8D25\uFF08\u9000\u51FA\u7801 ${status}\uFF09`);
5055
5091
  }
5092
+ function sudoTimeoutError(action) {
5093
+ return new Error(`${action}\u8D85\u65F6\uFF08${SUDO_TIMEOUT_MS / 1e3}s \u672A\u5B8C\u6210\uFF09\uFF1A\u5BC6\u7801\u8F93\u5165\u6216\u811A\u672C\u6267\u884C\u8D85\u8FC7\u65F6\u9650\uFF0C\u64CD\u4F5C\u53EF\u80FD\u53EA\u5B8C\u6210\u4E86\u4E00\u90E8\u5206\uFF0C\u8BF7\u68C0\u67E5\u540E\u91CD\u8BD5`);
5094
+ }
5056
5095
  function runSudoScript(scriptBody, opts) {
5057
5096
  if (!process.stdin.isTTY) {
5058
5097
  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");
@@ -5063,7 +5102,10 @@ function runSudoScript(scriptBody, opts) {
5063
5102
  fs7.chmodSync(scriptPath, 448);
5064
5103
  try {
5065
5104
  const result = spawnSync3("sudo", [scriptPath], { stdio: "inherit", timeout: SUDO_TIMEOUT_MS });
5066
- if (result.error) throw result.error;
5105
+ if (result.error) {
5106
+ if (result.error.code === "ETIMEDOUT") throw sudoTimeoutError(opts.action);
5107
+ throw result.error;
5108
+ }
5067
5109
  if (result.status !== 0) throw sudoExitToError(opts.action, result.status, opts.codeMessages);
5068
5110
  } finally {
5069
5111
  try {
@@ -5104,10 +5146,10 @@ function clearPid() {
5104
5146
  return e;
5105
5147
  }
5106
5148
  }
5107
- async function waitUntilNoMihomo(attempts = PROCESS_WAIT_ATTEMPTS, interval = PROCESS_WAIT_INTERVAL) {
5108
- for (let i = 0; i < attempts; i++) {
5149
+ async function waitUntilNoMihomo() {
5150
+ for (let i = 0; i < PROCESS_WAIT_ATTEMPTS; i++) {
5109
5151
  if (getMihomoPids().length === 0) return;
5110
- await sleep(interval);
5152
+ await sleep(PROCESS_WAIT_INTERVAL);
5111
5153
  }
5112
5154
  }
5113
5155
  async function reapPidWhenQuiet() {
@@ -5212,7 +5254,7 @@ async function stop() {
5212
5254
  return { success: true, remaining };
5213
5255
  }
5214
5256
  clearRuntime();
5215
- return { success: true, killed: result.killed };
5257
+ return { success: true };
5216
5258
  }
5217
5259
 
5218
5260
  // src/service.ts
@@ -7080,7 +7122,7 @@ function assertUniqueTokens(table) {
7080
7122
  }
7081
7123
  async function dispatchSubcommand(args, table, options) {
7082
7124
  assertUniqueTokens(table);
7083
- const action = args[1];
7125
+ const action = args[1]?.toLowerCase();
7084
7126
  if (action) {
7085
7127
  const cmd = table.find((c) => c.name === action || c.aliases?.includes(action));
7086
7128
  if (cmd) return cmd.handler(args);
@@ -8887,7 +8929,7 @@ var COMMANDS = [
8887
8929
  aliases: [],
8888
8930
  handler: cmdLogs,
8889
8931
  group: "interface",
8890
- usage: [{ signature: "logs [-f] [-n N] [\u7F16\u53F7] [-o]", description: "\u65E5\u5FD7\u5217\u8868/\u67E5\u770B\uFF080=\u5F53\u524D\uFF0C1+=\u5F52\u6863\uFF0C-f \u8DDF\u968F\uFF1B\u7701\u7565\u7F16\u53F7\u5373\u5F53\u524D\uFF09" }]
8932
+ usage: [{ signature: "logs [-f] [-n N] [\u7F16\u53F7] [-o]", description: "\u65E5\u5FD7\u5217\u8868/\u67E5\u770B\uFF08\u88F8 logs \u5217\u5217\u8868\uFF1B0=\u5F53\u524D\uFF0C1+=\u5F52\u6863\uFF1B\u7701\u7565\u7F16\u53F7\u4F46\u7ED9 -f/-n/-o \u65F6\u5373\u5F53\u524D\uFF09" }]
8891
8933
  },
8892
8934
  // === 订阅 ===
8893
8935
  {
@@ -8906,7 +8948,7 @@ var COMMANDS = [
8906
8948
  group: "subscription",
8907
8949
  usage: [
8908
8950
  { signature: "subscription", description: "\u5217\u51FA\u6240\u6709\u8BA2\u9605\uFF08\u522B\u540D sub/subs\uFF09" },
8909
- { signature: "subscription use <name>", description: "\u5207\u6362\u5F53\u524D\u8BA2\u9605" },
8951
+ { signature: "subscription use <name>", description: "\u5207\u6362\u5F53\u524D\u8BA2\u9605\uFF08\u81EA\u52A8\u91CD\u542F\uFF1B\u91CD\u542F\u900F\u4F20 -s/-u \u7B49\u542F\u52A8\u9009\u9879\uFF09" },
8910
8952
  { signature: "subscription add <url> [name]", description: "\u6DFB\u52A0\u8BA2\u9605" },
8911
8953
  { signature: "subscription update [name]", description: "\u66F4\u65B0\u8BA2\u9605\uFF08\u65E0\u53C2\u66F4\u65B0\u6240\u6709\uFF09" },
8912
8954
  { signature: "subscription remove <name>", description: "\u5220\u9664\u8BA2\u9605\uFF08\u6A21\u7CCA\u5339\u914D\u9700\u786E\u8BA4\uFF0C-y \u8DF3\u8FC7\uFF09" }
@@ -8982,7 +9024,7 @@ var COMMANDS = [
8982
9024
  aliases: ["-v", "--version"],
8983
9025
  handler: printVersion,
8984
9026
  group: "meta",
8985
- usage: [{ signature: "version, -v", description: "\u663E\u793A\u7248\u672C" }]
9027
+ usage: [{ signature: "version", description: "\u663E\u793A\u7248\u672C" }]
8986
9028
  }
8987
9029
  ];
8988
9030
  var COMMAND_INDEX = (() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mihomo-cli",
3
- "version": "26.10.96",
3
+ "version": "26.10.97",
4
4
  "type": "module",
5
5
  "description": "A terminal-based mihomo (Clash.Meta) client for macOS",
6
6
  "bin": {