mihomo-cli 26.11.119 → 26.11.120

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,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [26.11.120] - 2026-11-27
4
+
5
+ ### 修复
6
+
7
+ - **冷启动不再被 3 秒观察窗误报为失败**:已装载但尚未运行的服务最长等待 90 秒,重复执行 `start` 会附着等待而非 bootout 重排;等待完成后仍热重载本次配置。超时报告「启动待确认」,真实异常退出仍立即报错。重装遇到这种待启动状态时也会恢复运行,不再误关自启
8
+
3
9
  ## [26.11.119] - 2026-11-22
4
10
 
5
11
  ### 变更
@@ -99,14 +105,3 @@
99
105
  ### 变更(内部清理,无用户可见变化)
100
106
 
101
107
  - 删除一批从不被读取的返回字段与从不传值的函数参数;订阅下载与配置准备的订阅名参数去掉 `default` 静默回退改为必传——新调用方漏传不再悄悄写进 default.yaml。测试并发基建统一进 `src/test-support/`(新增 spawn-eval、poll 两个夹具),各 spec 私抄的七处子进程骨架与两份逐字重复的帮助函数随之收敛。957 用例全绿
102
-
103
- ## [26.10.110] - 2026-10-11
104
-
105
- ### 修复
106
-
107
- - **帮助与报错文案的准确性收口**:`sub use` / `use` / `ow on|off` 的「自动重启」统一为「运行中自动重启」——停止状态下这些命令只切换、不重启也不启动,原描述让用户预期落空;平台守卫报错与 README 统一为「适配尚无时间表」;reset 帮助行的「留空保留」清单补上此前遗漏的「服务」
108
- - **`ui` 在 ports 配置非法时不再输出畸形控制器行**:原输出把说明文字拼进 URL 冒号后面(`http://127.0.0.1:(settings.json 的 ports…)`),形似坏数据;改为整行「控制器: 端口无法确定(settings.json 的 ports 配置非法)」
109
-
110
- ### 变更
111
-
112
- - **README 与帮助文案的可读性修订**:「端口逃生口」改「端口可配置」、「紧急度着色」改「按紧急程度着色」、内核低速失败的换节点指引不再假设订阅主分组名(改「主分组(通常名为 Default Proxy 或 PROXY)」)、「重启透传」改「重启时可用/可带」;布尔开关清单把同一开关的 `-s`/`--no-update` 合并为一项,README 交叉引用补锚点链接
package/README.md CHANGED
@@ -523,7 +523,9 @@ mihomo-cli doctor
523
523
 
524
524
  清单按总开关、文件开关和 `match` 选择;脚本列入只表示会被调用,不证明它实际修改了配置。没有文件参与时不显示这一段。若订阅与覆写都看似正常,也可能是内核过旧,可尝试 `mihomo-cli kernel`
525
525
 
526
- 校验通过后仍需确认进程运行,端口占用、权限等启动问题会报错并附日志信息:
526
+ 校验通过后仍需确认进程运行。开机等慢启动场景中,如果 launchd 已装载服务但尚未进入运行状态,`start` 会等待而不是卸载重试;等待超时显示「启动待确认」,服务仍由 launchd 继续启动,无需重复执行 `start`,可稍后运行 `mihomo-cli status` 确认
527
+
528
+ 端口占用、权限问题或内核异常退出会报错并附日志信息:
527
529
 
528
530
  ```bash
529
531
  mihomo-cli logs 0 # 查看日志
package/dist/index.js CHANGED
@@ -6474,14 +6474,22 @@ function startAbortedByConcurrentStop() {
6474
6474
  // src/service.ts
6475
6475
  var SERVICE_HEALTH_INTERVAL_MS = 100;
6476
6476
  var SERVICE_OBSERVE_MS = 1200;
6477
- var SERVICE_HEALTH_GRACE_MS = 1800;
6478
- async function waitServiceHealthy() {
6479
- const deadline = Date.now() + SERVICE_OBSERVE_MS;
6480
- const graceDeadline = deadline + SERVICE_HEALTH_GRACE_MS;
6477
+ var SERVICE_STARTUP_TIMEOUT_MS = 9e4;
6478
+ var SERVICE_STARTUP_MAX_INTERVAL_MS = 1e3;
6479
+ var SERVICE_QUERY_STALE_MS = 3e3;
6480
+ function healthyResult(pid) {
6481
+ return { healthy: true, crashed: false, pending: false, pid, exitCode: null, terminatingSignal: null };
6482
+ }
6483
+ async function waitServiceHealthy(options = {}) {
6484
+ const startedAt = Date.now();
6485
+ const deadline = startedAt + SERVICE_OBSERVE_MS;
6486
+ const startupDeadline = startedAt + (options.startupTimeoutMs ?? SERVICE_STARTUP_TIMEOUT_MS);
6487
+ let lastSuccessfulQueryAt = startedAt;
6481
6488
  let last = null;
6482
6489
  const unhealthy = (state, crashed, pid = null) => ({
6483
6490
  healthy: false,
6484
6491
  crashed,
6492
+ pending: !crashed && state.loaded,
6485
6493
  pid,
6486
6494
  exitCode: state.lastExitCode,
6487
6495
  terminatingSignal: state.lastTerminatingSignal
@@ -6490,6 +6498,7 @@ async function waitServiceHealthy() {
6490
6498
  await sleep3(SERVICE_HEALTH_INTERVAL_MS);
6491
6499
  try {
6492
6500
  last = getServiceStatus({ withDisabled: false });
6501
+ lastSuccessfulQueryAt = Date.now();
6493
6502
  } catch {
6494
6503
  continue;
6495
6504
  }
@@ -6501,32 +6510,33 @@ async function waitServiceHealthy() {
6501
6510
  }
6502
6511
  } while (Date.now() < deadline);
6503
6512
  if (last === null) return healthViaProcessProbe();
6504
- if (last.running) return { healthy: true, crashed: false, pid: last.pid, exitCode: null, terminatingSignal: null };
6505
- let graceQueried = false;
6506
- while (Date.now() < graceDeadline) {
6507
- await sleep3(SERVICE_HEALTH_INTERVAL_MS);
6513
+ if (last.running) return healthyResult(last.pid);
6514
+ let startupIntervalMs = SERVICE_HEALTH_INTERVAL_MS;
6515
+ while (Date.now() < startupDeadline) {
6516
+ await sleep3(startupIntervalMs);
6517
+ startupIntervalMs = Math.min(startupIntervalMs * 2, SERVICE_STARTUP_MAX_INTERVAL_MS);
6508
6518
  try {
6509
6519
  last = getServiceStatus({ withDisabled: false });
6520
+ lastSuccessfulQueryAt = Date.now();
6510
6521
  } catch {
6522
+ if (Date.now() - lastSuccessfulQueryAt >= SERVICE_QUERY_STALE_MS) return healthViaProcessProbe();
6511
6523
  continue;
6512
6524
  }
6513
- graceQueried = true;
6514
6525
  if (isCrashed(last)) {
6515
6526
  return unhealthy(last, true);
6516
6527
  }
6517
- if (!last.loaded) break;
6518
- if (last.running) return { healthy: true, crashed: false, pid: last.pid, exitCode: null, terminatingSignal: null };
6528
+ if (!last.loaded) return unhealthy(last, false);
6529
+ if (last.running) return healthyResult(last.pid);
6519
6530
  }
6520
- if (!graceQueried) return healthViaProcessProbe();
6521
6531
  return unhealthy(last, false, last.pid);
6522
6532
  }
6523
6533
  function healthViaProcessProbe() {
6524
6534
  try {
6525
6535
  const pids = getMihomoPids();
6526
- if (pids.length > 0) return { healthy: true, crashed: false, pid: pids[0], exitCode: null, terminatingSignal: null };
6536
+ if (pids.length > 0) return healthyResult(pids[0]);
6527
6537
  } catch {
6528
6538
  }
6529
- return { healthy: false, crashed: false, pid: null, exitCode: null, terminatingSignal: null };
6539
+ return { healthy: false, crashed: false, pending: false, pid: null, exitCode: null, terminatingSignal: null };
6530
6540
  }
6531
6541
  function describeExitCause(exitCode, terminatingSignal) {
6532
6542
  if (terminatingSignal !== null) return `\u88AB\u4FE1\u53F7\u7EC8\u6B62\uFF08${terminatingSignal}\uFF09`;
@@ -6537,6 +6547,9 @@ function isCrashed(status) {
6537
6547
  if (status.running) return false;
6538
6548
  return describeExitCause(status.lastExitCode, status.lastTerminatingSignal) !== null;
6539
6549
  }
6550
+ function isServiceLaunchPending(status) {
6551
+ return status.loaded && !status.running && !status.disabled && !isCrashed(status);
6552
+ }
6540
6553
  function describeAbnormalExit(status) {
6541
6554
  return describeExitCause(status.lastExitCode, status.lastTerminatingSignal);
6542
6555
  }
@@ -6600,7 +6613,7 @@ function bootoutService(timeoutMs = LAUNCHCTL_TIMEOUT_MS) {
6600
6613
  hint: [detail, `\u624B\u52A8\u786E\u8BA4: launchctl print ${serviceTarget()}`].filter(Boolean)
6601
6614
  });
6602
6615
  }
6603
- async function installService(wasRunning) {
6616
+ async function installService(restoreAfterInstall) {
6604
6617
  assertServiceLabelSafe();
6605
6618
  ensureDirs();
6606
6619
  ensureServiceSymlink();
@@ -6618,7 +6631,7 @@ async function installService(wasRunning) {
6618
6631
  await waitUntilUnloaded();
6619
6632
  fs11.mkdirSync(path7.dirname(PATHS.userAgentPlist), { recursive: true });
6620
6633
  atomicWriteFileSync(PATHS.userAgentPlist, fs11.readFileSync(stagePath, "utf8"), { mode: 420 });
6621
- if (wasRunning) {
6634
+ if (restoreAfterInstall) {
6622
6635
  withFileLock(PATHS.serviceLock, () => {
6623
6636
  if (startAbortedByConcurrentStop()) {
6624
6637
  restoreSkipped = true;
@@ -6634,7 +6647,7 @@ async function installService(wasRunning) {
6634
6647
  } catch {
6635
6648
  }
6636
6649
  }
6637
- if (!wasRunning) {
6650
+ if (!restoreAfterInstall) {
6638
6651
  disableServiceAutoStart();
6639
6652
  }
6640
6653
  return { restoreSkipped };
@@ -6826,7 +6839,15 @@ async function launchOrRestart(mode) {
6826
6839
  await throwIfTunStartCancelled();
6827
6840
  return pid;
6828
6841
  }
6829
- const status = getServiceStatus();
6842
+ let status = getServiceStatus();
6843
+ if (isServiceLaunchPending(status)) {
6844
+ const pendingPid = await confirmServiceHealth();
6845
+ try {
6846
+ status = getServiceStatus();
6847
+ } catch {
6848
+ }
6849
+ if (isServiceLaunchPending(status)) status = { ...status, running: true, pid: pendingPid };
6850
+ }
6830
6851
  let hotReloaded = false;
6831
6852
  let started;
6832
6853
  if (status.running && !status.disabled) {
@@ -6842,6 +6863,9 @@ async function launchOrRestart(mode) {
6842
6863
  return null;
6843
6864
  }
6844
6865
  }
6866
+ return await confirmServiceHealth();
6867
+ }
6868
+ async function confirmServiceHealth() {
6845
6869
  try {
6846
6870
  return await assertServiceHealthy();
6847
6871
  } catch (e) {
@@ -6882,9 +6906,22 @@ function assertTunStartNotRaced() {
6882
6906
  function startCommandForCurrentMode(state) {
6883
6907
  return state.kind === "tun" ? "mihomo-cli start tun" : "mihomo-cli start";
6884
6908
  }
6885
- async function assertServiceHealthy(label = "\u542F\u52A8\u5931\u8D25") {
6886
- const health = await waitServiceHealthy();
6909
+ var ServiceLaunchPendingError = class extends CliError {
6910
+ };
6911
+ async function assertServiceHealthy(label = "\u542F\u52A8\u5931\u8D25", options = {}) {
6912
+ const health = await waitServiceHealthy(options);
6887
6913
  if (health.healthy) return health.pid;
6914
+ if (health.pending) {
6915
+ throw new ServiceLaunchPendingError("\u670D\u52A1\u4ECD\u5728\u542F\u52A8\uFF0C\u6682\u672A\u786E\u8BA4\u53EF\u7528", {
6916
+ label: "\u542F\u52A8\u5F85\u786E\u8BA4",
6917
+ hint: [
6918
+ "launchd \u4ECD\u5728\u542F\u52A8\u8BE5\u670D\u52A1\uFF1B\u672C\u6B21\u7B49\u5F85\u5DF2\u7ED3\u675F\uFF0C\u4F46\u670D\u52A1\u672A\u88AB\u505C\u6B62\u6216\u91CD\u542F\u3002",
6919
+ "\u65E0\u9700\u91CD\u590D\u6267\u884C mihomo-cli start\uFF0C\u7A0D\u540E\u786E\u8BA4: mihomo-cli status",
6920
+ "",
6921
+ "\u5B8C\u6574\u65E5\u5FD7: mihomo-cli logs 0"
6922
+ ]
6923
+ });
6924
+ }
6888
6925
  const tail = readLogTail();
6889
6926
  const cause = describeExitCause(health.exitCode, health.terminatingSignal);
6890
6927
  const reason = health.crashed ? `\u5185\u6838\u542F\u52A8\u540E\u7ACB\u5373\u9000\u51FA\uFF08${cause ?? "\u6B7B\u56E0\u672A\u8BB0\u5F55"}\uFF09` : "\u5185\u6838\u672A\u80FD\u8FDB\u5165\u8FD0\u884C\u72B6\u6001";
@@ -8836,8 +8873,9 @@ async function cmdInstall(args) {
8836
8873
  assertKnownFlags(args.slice(1), [], "install");
8837
8874
  assertPositionalCount(args, 0, 1, "mihomo-cli install");
8838
8875
  assertKernelInstalled();
8839
- const wasRunning = getServiceStatus().running;
8840
- const { restoreSkipped } = await installService(wasRunning);
8876
+ const serviceBefore = getServiceStatus();
8877
+ const restoreAfterInstall = serviceBefore.running || isServiceLaunchPending(serviceBefore);
8878
+ const { restoreSkipped } = await installService(restoreAfterInstall);
8841
8879
  console.log(`${colors.green("\u5DF2\u5B89\u88C5\u670D\u52A1")}`);
8842
8880
  console.log(colors.gray(` plist: ${PATHS.userAgentPlist}`));
8843
8881
  console.log(colors.gray(` \u767B\u5F55\u9879\u4E0E\u6269\u5C55\u4E2D\u663E\u793A\u4E3A: ${SERVICE_BINARY_NAME}`));
@@ -8846,7 +8884,7 @@ async function cmdInstall(args) {
8846
8884
  printRestoreSkipped();
8847
8885
  return;
8848
8886
  }
8849
- if (wasRunning) {
8887
+ if (restoreAfterInstall) {
8850
8888
  try {
8851
8889
  await assertServiceHealthy("\u6062\u590D\u8FD0\u884C\u5931\u8D25");
8852
8890
  } catch (e) {
@@ -8856,7 +8894,7 @@ async function cmdInstall(args) {
8856
8894
  return;
8857
8895
  }
8858
8896
  throw relabelCliError(e, {
8859
- hint: [...e.hint, "", "\u670D\u52A1\u5DF2\u5B89\u88C5\u6210\u529F\uFF0C\u4EC5\u6062\u590D\u8FD0\u884C\u5931\u8D25\uFF1B\u4FEE\u6B63\u914D\u7F6E\u540E\u53EF\u6267\u884C mihomo-cli start \u91CD\u8BD5\u3002"]
8897
+ hint: e instanceof ServiceLaunchPendingError ? [...e.hint, "", "\u670D\u52A1\u5DF2\u5B89\u88C5\u6210\u529F\uFF1B\u6062\u590D\u8FD0\u884C\u5C1A\u672A\u786E\u8BA4\uFF0C\u4E0D\u5F71\u54CD launchd \u7EE7\u7EED\u542F\u52A8\u3002"] : [...e.hint, "", "\u670D\u52A1\u5DF2\u5B89\u88C5\u6210\u529F\uFF0C\u4EC5\u6062\u590D\u8FD0\u884C\u5931\u8D25\uFF1B\u4FEE\u6B63\u914D\u7F6E\u540E\u53EF\u6267\u884C mihomo-cli start \u91CD\u8BD5\u3002"]
8860
8898
  });
8861
8899
  }
8862
8900
  console.log(colors.green("\u5DF2\u6309\u539F\u72B6\u6001\u91CD\u65B0\u542F\u52A8"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mihomo-cli",
3
- "version": "26.11.119",
3
+ "version": "26.11.120",
4
4
  "type": "module",
5
5
  "description": "A terminal-based mihomo (Clash.Meta) client for macOS",
6
6
  "bin": {