mihomo-cli 26.10.97 → 26.10.98

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
@@ -2,6 +2,17 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [26.10.98] - 2026-10-02
6
+
7
+ ### 新增
8
+
9
+ - **doctor 检查面板自升级残留**:在面板里升级内核(`POST /upgrade`)后,内核会在 kernel 目录留下 `meta-backup`(旧内核备份),异常中断时还会遗留 `meta-update`(下载暂存);doctor 会提示目录位置、区分两者性质(备份可留作回滚、暂存可安全删)并给出删除命令
10
+
11
+ ### 改进
12
+
13
+ - **内核下载本机代理优先、失败自动换通道**:`mihomo kernel` 在本机代理运行时默认经代理下载,失败自动回退 gh;全部失败时汇总各通道原因,并提示可在面板手动换节点。显式 `--mirror`/`--proxy` 仍严格按指定通道、不自动切换
14
+ - **劣质节点下载不再长时间干等**:节点握手延迟低但实际带宽极低时(实测约 20 KB/s),此前 gh 通道会卡满 210 秒;现代理通道在 20 秒内平均速度低于 50 KB/s 即快速失败,gh 通道超时也缩短到 100 秒。超时或低速失败给出可读原因,不再只显示「curl 退出码 28」
15
+
5
16
  ## [26.10.97] - 2026-10-01
6
17
 
7
18
  ### 修复
package/README.md CHANGED
@@ -150,7 +150,7 @@ mihomo ui yacd # YACD
150
150
 
151
151
  | 命令 | 说明 |
152
152
  | --------------------------------- | ------------------------------------------------------------------- |
153
- | `mihomo kernel [--mirror [镜像]]` | 更新内核(自动选择通道:gh > 本机代理 > 直连;`--mirror` 强制镜像,`--mirror direct` 强制直连) |
153
+ | `mihomo kernel [--mirror [镜像]]` | 更新内核(自动选择通道:本机代理优先、回退 gh;`--mirror` 强制镜像,`--mirror direct` 强制直连) |
154
154
  | `mihomo update` | 更新 mihomo-cli(先查 npm 最新版,已是最新则跳过重装) |
155
155
  | `mihomo ui [zash\|dash\|yacd] [-c]` | 打开 Web UI(`-c` 把控制器访问密钥复制到剪贴板;默认只提示、不动剪贴板) |
156
156
  | `mihomo dir` | 显示数据目录位置 |
@@ -296,13 +296,15 @@ mihomo logs 1 # 查看最新的归档
296
296
 
297
297
  `mihomo kernel` 按优先级自动选择下载通道,无需手动指定:
298
298
 
299
- 1. **gh**:检测到 GitHub CLI(`gh`)时,经 `gh release download` 直连 GitHub
300
- 2. **本机代理**:mihomo 代理在跑时,经混合端口直连 GitHub(TLS 端到端)
299
+ 1. **本机代理**:mihomo 在跑时经混合端口下载;速度过低或超时会快速失败并自动回退 gh
300
+ 2. **gh**:代理没跑,或代理通道失败时经 `gh release download` 下载
301
301
  3. **直连**:以上都不可用时
302
302
 
303
303
  镜像不持久化——每次按当前环境独立决策,换网络不会用到上次的镜像。
304
304
 
305
- 版本查询(GitHub API)优先走 **gh 认证通道**(配额 5000 次/时,未认证直连仅 60 次/时——共享出口 IP 撞 403 限流时 gh 是唯一即时出路),gh 失败回退本机代理、再直连;镜像**绝不**作用于 API——
305
+ 回退只换客户端、不换机场节点(url-test 通常仍选中同一个节点);两条通道都因低速失败时,在面板里手动给 Default Proxy 换个线路后重试。
306
+
307
+ 版本查询(GitHub API)在代理可用时直接经代理;无代理才走 **gh 认证通道**(配额 5000 次/时,未认证直连仅 60 次/时——共享出口 IP 撞 403 限流时 gh 是即时出路)。镜像**绝不**作用于 API——
306
308
  内核二进制在 TUN 模式下会以 root 运行,下载地址必须由 GitHub 官方 API 给出,不能让镜像自己指定。
307
309
 
308
310
  手动覆盖:
package/dist/index.js CHANGED
@@ -3445,6 +3445,8 @@ var DIRS = {
3445
3445
  data: path.join(USER_DATA_DIR, "data"),
3446
3446
  runtime: path.join(USER_DATA_DIR, "runtime")
3447
3447
  };
3448
+ var KERNEL_SELF_BACKUP_DIR = path.join(DIRS.kernel, "meta-backup");
3449
+ var KERNEL_SELF_UPDATE_DIR = path.join(DIRS.kernel, "meta-update");
3448
3450
  var PATHS = {
3449
3451
  mihomoBinary: path.join(DIRS.kernel, "mihomo"),
3450
3452
  /**
@@ -7228,6 +7230,7 @@ import { promisify as promisify3 } from "util";
7228
7230
  var GITHUB_REPO = "MetaCubeX/mihomo";
7229
7231
  var KERNEL_HTTP_TIMEOUT = 12e4;
7230
7232
  var KERNEL_DOWNLOAD_TIMEOUT = 18e4;
7233
+ var GH_DOWNLOAD_TIMEOUT = 1e5;
7231
7234
  var HTTP_CLIENT2 = createHttpClient({ timeout: KERNEL_HTTP_TIMEOUT });
7232
7235
  var execFileAsync2 = promisify3(execFile3);
7233
7236
  function withMirror(url, mirror) {
@@ -7253,15 +7256,19 @@ function assertTrustedAssetUrl(rawUrl) {
7253
7256
  \u4EC5\u5141\u8BB8: ${[...ALLOWED_ASSET_HOSTS].join(", ")}`);
7254
7257
  }
7255
7258
  }
7256
- function resolveDownloadChannel(input) {
7257
- if (input.isOverride && !input.mirror) return { kind: "direct" };
7259
+ function resolveDownloadChannels(input) {
7260
+ if (input.isOverride && !input.mirror) return [{ kind: "direct" }];
7258
7261
  if (input.isOverride && input.mirror) {
7259
- return input.proxyOverride ? { kind: "mirror", mirror: input.mirror, proxy: input.proxyOverride } : { kind: "mirror", mirror: input.mirror };
7262
+ return [input.proxyOverride ? { kind: "mirror", mirror: input.mirror, proxy: input.proxyOverride } : { kind: "mirror", mirror: input.mirror }];
7260
7263
  }
7261
- if (input.proxyOverride) return { kind: "proxy", proxy: input.proxyOverride };
7262
- if (input.ghAvailable) return { kind: "gh" };
7263
- if (input.proxyRunning && input.proxyPort !== null) return { kind: "proxy", proxy: `http://127.0.0.1:${input.proxyPort}` };
7264
- return { kind: "direct" };
7264
+ if (input.proxyOverride) return [{ kind: "proxy", proxy: input.proxyOverride }];
7265
+ if (input.proxyRunning && input.proxyPort !== null) {
7266
+ const channels = [{ kind: "proxy", proxy: `http://127.0.0.1:${input.proxyPort}` }];
7267
+ if (input.ghAvailable) channels.push({ kind: "gh" });
7268
+ return channels;
7269
+ }
7270
+ if (input.ghAvailable) return [{ kind: "gh" }];
7271
+ return [{ kind: "direct" }];
7265
7272
  }
7266
7273
  function hasGh() {
7267
7274
  const result = spawnSync7("gh", ["--version"], { stdio: "ignore" });
@@ -7432,6 +7439,13 @@ function buildKernelCurlArgs(args) {
7432
7439
  "--fail-with-body",
7433
7440
  "--max-filesize",
7434
7441
  String(args.maxBytes),
7442
+ // 低速快速失败:url-test 可能选中「握手快但对 Azure 几乎无带宽」的节点(实测约
7443
+ // 20KB/s 慢传),20 秒内平均速度低于 50KB/s 即中止——命令层据此切换下一通道,
7444
+ // 不必干等到 --max-time
7445
+ "--speed-limit",
7446
+ "50000",
7447
+ "--speed-time",
7448
+ "20",
7435
7449
  "--progress-bar",
7436
7450
  "--connect-timeout",
7437
7451
  "30",
@@ -7444,6 +7458,15 @@ function buildKernelCurlArgs(args) {
7444
7458
  argv.push("-o", args.outputPath, args.url);
7445
7459
  return argv;
7446
7460
  }
7461
+ function describeCurlDownloadError(status) {
7462
+ if (status === 22) {
7463
+ return "\u955C\u50CF\u6216\u670D\u52A1\u5668\u8FD4\u56DE HTTP \u9519\u8BEF\uFF084xx/5xx\uFF09\uFF0C\u8BF7\u91CD\u8BD5\u6216\u6539\u7528\u5176\u4ED6\u901A\u9053\uFF08gh/\u672C\u673A\u4EE3\u7406/--mirror direct\uFF09";
7464
+ }
7465
+ if (status === 28) {
7466
+ return "\u8FDE\u63A5\u6216\u4F20\u8F93\u8D85\u65F6\uFF1A\u8282\u70B9\u53EF\u80FD\u4E0D\u53EF\u7528\u3001\u901F\u5EA6\u8FC7\u4F4E\u6216\u88AB\u9650\u901F\uFF08\u7ECF\u4EE3\u7406\u65F6\u901A\u5E38\u662F\u5F53\u524D\u8282\u70B9\u5BF9 GitHub \u5E26\u5BBD\u4E0D\u8DB3\uFF09";
7467
+ }
7468
+ return `\u4E0B\u8F7D\u5931\u8D25 (curl \u9000\u51FA\u7801 ${status})`;
7469
+ }
7447
7470
  function buildGhReleaseDownloadArgs(tag, assetName, dir) {
7448
7471
  return ["release", "download", tag, "--repo", GITHUB_REPO, "--pattern", assetName, "--dir", dir, "--clobber"];
7449
7472
  }
@@ -7480,14 +7503,14 @@ async function downloadKernel(progressCallback, channel, releaseInfo) {
7480
7503
  }
7481
7504
  const ghResult = spawnSync7("gh", buildGhReleaseDownloadArgs(latest.tag_name, asset.name, tempDir), {
7482
7505
  stdio: "inherit",
7483
- timeout: KERNEL_DOWNLOAD_TIMEOUT + 3e4
7506
+ timeout: GH_DOWNLOAD_TIMEOUT
7484
7507
  });
7485
7508
  if (ghResult.error) {
7486
7509
  if (ghResult.error.code === "ENOENT") {
7487
7510
  throw new Error("\u672A\u627E\u5230 gh \u547D\u4EE4\uFF08\u9009\u62E9\u901A\u9053\u65F6\u660E\u660E\u53EF\u7528\uFF09\uFF0C\u8BF7\u91CD\u8BD5\u6216\u6539\u7528\u5176\u4ED6\u901A\u9053");
7488
7511
  }
7489
7512
  if (ghResult.error.code === "ETIMEDOUT") {
7490
- throw new Error(`\u4E0B\u8F7D\u8D85\u65F6\uFF08gh ${Math.floor((KERNEL_DOWNLOAD_TIMEOUT + 3e4) / 1e3)}s \u672A\u5B8C\u6210\uFF09\uFF0CGitHub \u76F4\u8FDE\u8FC7\u6162\u65F6\u6539\u7528: mihomo kernel --mirror`);
7513
+ throw new Error(`\u4E0B\u8F7D\u8D85\u65F6\uFF08gh ${Math.floor(GH_DOWNLOAD_TIMEOUT / 1e3)}s \u672A\u5B8C\u6210\uFF09\uFF0C\u5C06\u5C1D\u8BD5\u4E0B\u4E00\u901A\u9053`);
7491
7514
  }
7492
7515
  throw new Error(`\u4E0B\u8F7D\u5931\u8D25: ${ghResult.error.message}`);
7493
7516
  }
@@ -7513,10 +7536,7 @@ async function downloadKernel(progressCallback, channel, releaseInfo) {
7513
7536
  throw new Error(`\u4E0B\u8F7D\u5931\u8D25: ${curlResult.error.message}`);
7514
7537
  }
7515
7538
  if (curlResult.status !== 0) {
7516
- if (curlResult.status === 22) {
7517
- throw new Error("\u4E0B\u8F7D\u5931\u8D25: \u955C\u50CF\u6216\u670D\u52A1\u5668\u8FD4\u56DE HTTP \u9519\u8BEF\uFF084xx/5xx\uFF09\uFF0C\u8BF7\u91CD\u8BD5\u6216\u6539\u7528\u5176\u4ED6\u901A\u9053\uFF08gh/\u672C\u673A\u4EE3\u7406/--mirror direct\uFF09");
7518
- }
7519
- throw new Error(`\u4E0B\u8F7D\u5931\u8D25 (curl \u9000\u51FA\u7801 ${curlResult.status})`);
7539
+ throw new Error(`\u4E0B\u8F7D\u5931\u8D25: ${describeCurlDownloadError(curlResult.status ?? 1)}`);
7520
7540
  }
7521
7541
  }
7522
7542
  if (!fs11.existsSync(tempPath)) {
@@ -7692,6 +7712,22 @@ async function collectChecks() {
7692
7712
  push("\u5185\u6838", "fail", `\u4E8C\u8FDB\u5236\u65E0\u6CD5\u6267\u884C\uFF08\u9000\u51FA\u7801 ${r.status}\uFF09`, "\u91CD\u65B0\u4E0B\u8F7D: mihomo kernel");
7693
7713
  }
7694
7714
  }
7715
+ const leftovers = [];
7716
+ if (fs12.existsSync(KERNEL_SELF_BACKUP_DIR)) {
7717
+ leftovers.push({ dir: KERNEL_SELF_BACKUP_DIR, note: "\u65E7\u5185\u6838\u5907\u4EFD\uFF1A\u9700\u8981\u624B\u52A8\u56DE\u6EDA\u65F6\u53EF\u4FDD\u7559\uFF0C\u5426\u5219\u53EF\u5220" });
7718
+ }
7719
+ if (fs12.existsSync(KERNEL_SELF_UPDATE_DIR)) {
7720
+ leftovers.push({ dir: KERNEL_SELF_UPDATE_DIR, note: "\u4E2D\u65AD\u7684\u4E0B\u8F7D\u6682\u5B58\uFF1A\u53EF\u5B89\u5168\u5220\u9664" });
7721
+ }
7722
+ if (leftovers.length > 0) {
7723
+ push(
7724
+ "\u5185\u6838\u81EA\u5347\u7EA7\u6B8B\u7559",
7725
+ "warn",
7726
+ `\u53D1\u73B0 ${leftovers.length} \u4E2A\u9762\u677F\u81EA\u5347\u7EA7\u9057\u7559\u76EE\u5F55`,
7727
+ `rm -rf ${leftovers.map((l) => l.dir).join(" ")}`,
7728
+ leftovers.map((l) => ` ${l.dir}\uFF1A${l.note}`)
7729
+ );
7730
+ }
7695
7731
  try {
7696
7732
  fs12.accessSync(USER_DATA_DIR, fs12.constants.W_OK);
7697
7733
  push("\u6570\u636E\u76EE\u5F55", "ok", USER_DATA_DIR);
@@ -7989,6 +8025,29 @@ function parseProxyArg(args) {
7989
8025
 
7990
8026
  // src/commands/kernel.ts
7991
8027
  var KERNEL_VALUE_FLAGS = /* @__PURE__ */ new Set([...VALUE_FLAGS, "--mirror"]);
8028
+ function channelLabel(channel) {
8029
+ switch (channel.kind) {
8030
+ case "gh":
8031
+ return "gh";
8032
+ case "proxy":
8033
+ return `\u4EE3\u7406 ${channel.proxy}`;
8034
+ case "mirror":
8035
+ return `\u955C\u50CF ${channel.mirror}`;
8036
+ case "direct":
8037
+ return "\u76F4\u8FDE";
8038
+ }
8039
+ }
8040
+ function printChannelLine(channel, isExplicitProxy) {
8041
+ if (channel.kind === "gh") {
8042
+ console.log("\u4E0B\u8F7D\u901A\u9053: gh\uFF08GitHub CLI\uFF09");
8043
+ } else if (channel.kind === "proxy") {
8044
+ console.log(`\u4E0B\u8F7D\u901A\u9053: ${isExplicitProxy ? "\u4EE3\u7406" : "\u672C\u673A\u4EE3\u7406"} ${channel.proxy}`);
8045
+ } else if (channel.kind === "mirror") {
8046
+ const host = channel.mirror.replace(/^https?:\/\//, "").replace(/\/$/, "");
8047
+ console.log(`\u955C\u50CF: ${host}${channel.proxy ? `\uFF08\u7ECF\u4EE3\u7406 ${channel.proxy}\uFF09` : ""}`);
8048
+ }
8049
+ console.log("");
8050
+ }
7992
8051
  async function cmdKernel(args) {
7993
8052
  const mirrorInfo = parseMirrorArg(args);
7994
8053
  const proxyInfo = parseProxyArg(args);
@@ -7996,7 +8055,7 @@ async function cmdKernel(args) {
7996
8055
  if (proxyInfo.proxy && mirrorInfo.isOverride && !mirrorInfo.mirror) {
7997
8056
  throw new CliError("--mirror direct \u4E0E --proxy \u4E0D\u80FD\u540C\u65F6\u4F7F\u7528", {
7998
8057
  label: "\u53C2\u6570\u9519\u8BEF",
7999
- hint: ["--mirror direct \u5F3A\u5236\u4E0D\u7ECF\u4EFB\u4F55\u4EE3\u7406\u76F4\u8FDE\uFF0C\u9700\u8D70\u4EE3\u7406\u65F6\u53BB\u6389\u5B83:", " mihomo kernel --proxy <\u7AEF\u53E3|\u5730\u5740>"]
8058
+ hint: ["--mirror direct \u5F3A\u5236\u4E0D\u7ECF\u4EE3\u7406\u76F4\u8FDE\uFF0C\u9700\u8D70\u4EE3\u7406\u65F6\u53BB\u6389\u5B83:", " mihomo kernel --proxy <\u7AEF\u53E3|\u5730\u5740>"]
8000
8059
  });
8001
8060
  }
8002
8061
  const proxyRunning = getRunningState().running;
@@ -8010,7 +8069,7 @@ async function cmdKernel(args) {
8010
8069
  }
8011
8070
  const forceDirect = mirrorInfo.isOverride && !mirrorInfo.mirror;
8012
8071
  const ghAvailable = hasGh();
8013
- const channel = resolveDownloadChannel({
8072
+ const channels = resolveDownloadChannels({
8014
8073
  mirror: mirrorInfo.mirror,
8015
8074
  isOverride: mirrorInfo.isOverride,
8016
8075
  ghAvailable,
@@ -8018,18 +8077,7 @@ async function cmdKernel(args) {
8018
8077
  proxyPort,
8019
8078
  proxyOverride: proxyInfo.proxy
8020
8079
  });
8021
- if (channel.kind === "gh") {
8022
- console.log("\u4E0B\u8F7D\u901A\u9053: gh\uFF08GitHub CLI \u76F4\u8FDE\uFF09");
8023
- console.log("");
8024
- } else if (channel.kind === "proxy") {
8025
- const label = proxyInfo.proxy ? "\u4EE3\u7406" : "\u672C\u673A\u4EE3\u7406";
8026
- console.log(`\u4E0B\u8F7D\u901A\u9053: ${label} ${channel.proxy}`);
8027
- console.log("");
8028
- } else if (channel.kind === "mirror") {
8029
- const host = channel.mirror.replace(/^https?:\/\//, "").replace(/\/$/, "");
8030
- console.log(`\u955C\u50CF: ${host}${channel.proxy ? `\uFF08\u7ECF\u4EE3\u7406 ${channel.proxy}\uFF09` : ""}`);
8031
- console.log("");
8032
- }
8080
+ printChannelLine(channels[0], proxyInfo.proxy !== null);
8033
8081
  const apiProxy = proxyInfo.proxy ?? (proxyRunning && !forceDirect && proxyPort !== null ? `http://127.0.0.1:${proxyPort}` : null);
8034
8082
  const useGh = apiProxy === null && !forceDirect && ghAvailable;
8035
8083
  let info;
@@ -8093,15 +8141,30 @@ async function cmdKernel(args) {
8093
8141
  } else {
8094
8142
  console.log("\n\u6B63\u5728\u4E0B\u8F7D...");
8095
8143
  let result;
8096
- try {
8097
- result = await downloadKernel((msg) => console.log(msg), channel, info.release);
8098
- } catch (e) {
8099
- if (e instanceof CliError) throw e;
8100
- throw new CliError(e.message, {
8144
+ const failures = [];
8145
+ for (let attempt = 0; attempt < channels.length; attempt++) {
8146
+ if (attempt > 0) {
8147
+ console.log("\u4E0A\u4E00\u901A\u9053\u5931\u8D25\uFF0C\u5207\u6362\u4E3A:");
8148
+ printChannelLine(channels[attempt], proxyInfo.proxy !== null);
8149
+ }
8150
+ try {
8151
+ result = await downloadKernel((msg) => console.log(msg), channels[attempt], info.release);
8152
+ } catch (e) {
8153
+ failures.push(` ${channelLabel(channels[attempt])}: ${e.message.split("\n")[0]}`);
8154
+ continue;
8155
+ }
8156
+ break;
8157
+ }
8158
+ if (!result) {
8159
+ throw new CliError("\u5168\u90E8\u4E0B\u8F7D\u901A\u9053\u5747\u5931\u8D25", {
8101
8160
  label: "\u4E0B\u8F7D\u5931\u8D25",
8102
8161
  hint: [
8162
+ ...failures,
8163
+ "",
8164
+ "\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",
8165
+ "\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",
8103
8166
  "",
8104
- "\u4E0B\u8F7D\u901A\u9053\u6309\u4F18\u5148\u7EA7\u81EA\u52A8\u9009\u62E9: gh\uFF08GitHub CLI\uFF09> \u672C\u673A\u4EE3\u7406 > \u76F4\u8FDE",
8167
+ "\u901A\u9053\u9009\u62E9\uFF1A\u672C\u673A\u4EE3\u7406\u5728\u8DD1\u65F6\u81EA\u52A8\u4F18\u5148\uFF08\u542B\u4F4E\u901F\u5FEB\u901F\u5931\u8D25\uFF09\uFF0C\u56DE\u9000 gh\uFF1B",
8105
8168
  "\u624B\u52A8\u6307\u5B9A: mihomo kernel --mirror [\u955C\u50CF]\uFF08\u5F3A\u5236\u955C\u50CF\uFF09/ mihomo kernel --mirror direct\uFF08\u5F3A\u5236\u76F4\u8FDE\uFF09",
8106
8169
  " mihomo kernel --proxy <\u7AEF\u53E3>\uFF08\u7ECF\u672C\u673A\u5176\u4ED6\u4EE3\u7406\u5DE5\u5177\u51FA\u7F51\uFF09"
8107
8170
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mihomo-cli",
3
- "version": "26.10.97",
3
+ "version": "26.10.98",
4
4
  "type": "module",
5
5
  "description": "A terminal-based mihomo (Clash.Meta) client for macOS",
6
6
  "bin": {