mihomo-cli 4.4.0 → 4.5.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,32 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.5.0] - 2026-09-05
4
+
5
+ 产品面打磨:补齐「服务常驻」与「用户会回来敲命令」假设之间的缺口。单测 229 → 234。
6
+
7
+ ### 新增
8
+
9
+ - **`status` 订阅新鲜度**:订阅块新增「更新: N 小时前」行,超过更新间隔时黄标并建议 `mihomo sub update`——服务常驻期间订阅不会自动更新(launchd 只拉起内核,不跑 `start`),陈旧订阅是「运行中(代理不通)」的高频根因。`--json` 的 `subscription` 补 `updatedAt`/`stale` 字段。判断收敛为 `isSubscriptionStale` 纯函数,与 doctor 订阅新鲜度共用口径
10
+
11
+ - **`sub add` 剪贴板**:交互下不带 URL 参数时自动读取剪贴板(pbpaste),`maskUrl` 遮蔽展示 + y/N 确认后添加——「机场页面点复制 → 终端粘贴」不再需要重打一遍命令。剪贴板非 URL / 非 TTY 环境维持原有报错
12
+
13
+ - **端口逃生口**:`settings.json` 新增 `ports: { mixed, controller }`,可覆盖默认 7890/9090(与其他代理工具并存的场景)。`getPorts()` 为唯一解析入口,非法值(非 1-65535 整数、两端口相同)直接抛错而非静默回退默认——端口突降会让热重载/UI 连错地址且毫无线索。配置构建、热重载、`ui` 提示、`start` 系统代理提示、doctor 端口检查全部跟随实际值;订阅/覆写仍不可改端口(系统锁定语义不变)
14
+
15
+ - **`completion install <shell>`**:一键安装补全到对应 shell 的默认位置(zsh → `~/.zsh/completions/_mihomo`,bash → 追加 `~/.bash_completion` 含幂等标记、不覆盖已有内容,fish → `~/.config/fish/completions/mihomo.fish`)。zsh 不自动改 `.zshrc`,fpath 缺失时提示用户补一行。三 shell 的补全词表同步支持 `install` 子命令
16
+
17
+ - **doctor CLI 版本检查**:落后于 npm latest 时 warn 并提示 `mihomo update`(短超时 4s,registry 不可达静默跳过,不产生红色噪音)——本项目连修多个高危缺陷,老用户需要被提醒升级
18
+
19
+ ### 变更
20
+
21
+ - **doctor 增加 ports 合法性检查**:`settings.ports` 非法(超范围/非整数/两端口相同/非对象)时报 ✗ 检查项并给修复指引,而不是让整个体检崩在半路
22
+ - **`uninstall` 收尾提示彻底清理**:卸载只移除 launchd 托管,结束时提示 `mihomo reset --full`(删数据)与 `npm uninstall -g mihomo-cli`(删包)两步
23
+ - **`start` 系统代理提示跟随实际端口**:文案硬编码的 7890 改为 `getPorts().mixed`(配置逃生口后提示不会指错端口)
24
+ - **README**:「订阅自动更新」节写实「服务常驻期间不会自动更新」及对策;覆写配置节新增「同时使用多个机场」的 `proxy-providers` 完整示例(单活跃订阅模型下并入第二机场的正路)
25
+
26
+ ### 决策记录
27
+
28
+ - **不自动配置系统代理、不提供 `proxy on/off` 开关**(owner 决策,记入 CLAUDE.md 服务模型既定决策):owner 的用法是「日常只有部分程序需要代理,需要者各自配置」,全局代理是错误状态。Mixed 启动保持只提示端口
29
+
3
30
  ## [4.4.0] - 2026-09-05
4
31
 
5
32
  工程去重与安全加固:消除补全词表的第二真相源,doctor 连通性/设置校验复用核心模块,quickstart.sh 对齐 CLI 的安全水位。单测 225 → 229。
package/README.md CHANGED
@@ -14,8 +14,9 @@
14
14
  - 🚀 **进程管理** - 启动/停止/切换模式,自动清理残留进程
15
15
  - 🛡️ **服务托管** - 基于 launchd,崩溃/登录自动拉起,代理后台常驻;日常 `start`/`stop` **全程免密**
16
16
  - 🔄 **双模式支持** - Mixed 模式和 TUN 透明代理模式
17
- - 📊 **状态监控** - 查看运行状态、内存占用、订阅流量与到期时间(到期/流量紧急度着色,`--json` 机器可读)
18
- - 🩺 **体检诊断** - `mihomo doctor` 一键检查内核/服务/端口/订阅/配置/连通性并给修复指引
17
+ - 📊 **状态监控** - 查看运行状态、内存占用、订阅流量、到期时间与更新新鲜度(紧急度着色,`--json` 机器可读)
18
+ - 🩺 **体检诊断** - `mihomo doctor` 一键检查内核/服务/端口/订阅/配置/连通性/CLI 版本并给修复指引
19
+ - 🔌 **端口逃生口** - 默认 7890/9090 可经 `settings.json` 的 `ports` 覆盖,与其他代理工具并存
19
20
  - 🔌 **连通性探测** - 启动与状态展示独立确认「代理真的通」,不通时归因到订阅过期/流量用尽/节点失效
20
21
  - ⌨️ **Shell 补全** - `mihomo completion zsh|bash|fish` 生成补全脚本
21
22
  - 📝 **日志管理** - 每次启动归档上一次日志,保留 7 天,支持列表/跟随/编号查看
@@ -63,6 +64,9 @@ mihomo kernel --mirror hk.gh-proxy.org
63
64
 
64
65
  ```bash
65
66
  mihomo sub add "https://your-subscription-url" "my-proxy"
67
+
68
+ # 或先在机场页面复制订阅链接,再运行(交互下自动读取剪贴板,确认后添加)
69
+ mihomo sub add
66
70
  ```
67
71
 
68
72
  ### 3. 安装服务
@@ -107,7 +111,7 @@ mihomo ui yacd # YACD
107
111
  | `mihomo start [tun\|mixed]` | 启动代理并开启登录自启(`-s` 跳过订阅更新,`-u` 更新超时) |
108
112
  | `mihomo stop` | 停止代理并关闭登录自启 |
109
113
  | `mihomo uninstall` | 卸载服务 |
110
- | `mihomo status` | 查看运行状态(含订阅流量、到期时间;`--json` 机器可读,`--no-probe` 跳过连通性探测) |
114
+ | `mihomo status` | 查看运行状态(含订阅流量、到期、更新新鲜度;`--json` 机器可读,`--no-probe` 跳过连通性探测) |
111
115
  | `mihomo logs` | 列出所有日志(当前 + 历史归档) |
112
116
  | `mihomo logs <编号>` | 查看指定日志(`0`=当前,`1+`=归档,`-f` 实时跟随,`-n N` 行数,`-o` 打开) |
113
117
  | `mihomo logs -f` | 跟随当前日志(省略编号时默认当前,等价 `logs 0 -f`) |
@@ -118,7 +122,7 @@ mihomo ui yacd # YACD
118
122
  | ----------------------------- | -------------------------------------- |
119
123
  | `mihomo sub` | 列出所有订阅(含流量、到期时间) |
120
124
  | `mihomo sub use <name>` | 切换当前订阅(支持模糊匹配,自动重启) |
121
- | `mihomo sub add <url> [name]` | 添加订阅并自动切换(名称不可重复) |
125
+ | `mihomo sub add [url] [name]` | 添加订阅并自动切换(名称不可重复;交互下不带 URL 时自动读剪贴板并确认) |
122
126
  | `mihomo sub update` | 更新所有订阅 |
123
127
  | `mihomo sub update <name>` | 更新指定订阅(支持模糊匹配) |
124
128
  | `mihomo sub remove <name>` | 删除订阅(别名 `rm`/`delete`;精确名直接删,模糊匹配需确认,`-y` 跳过) |
@@ -144,8 +148,9 @@ mihomo ui yacd # YACD
144
148
  | `mihomo dir` | 显示数据目录位置 |
145
149
  | `mihomo dir open [target]` | 打开指定目录(`root`, `subs`, `logs`, `data`, `runtime`, `kernel`) |
146
150
  | `mihomo reset [目标...] [--full] [-y]` | 重置用户数据(可用目标:`subs`, `logs`, `data`, `runtime`, `settings`, `kernel`, `overwrites`, `service`;`--full` 删全部,`-y` 跳过确认) |
147
- | `mihomo doctor` | 体检诊断(内核/服务/端口/订阅/配置/连通性,有异常退出码 1) |
148
- | `mihomo completion <shell>` | 输出 shell 补全脚本(`zsh`/`bash`/`fish`) |
151
+ | `mihomo doctor` | 体检诊断(内核/服务/端口/订阅/配置/连通性/CLI 版本,有异常退出码 1) |
152
+ | `mihomo completion install <shell>` | 安装 shell 补全到默认位置(`zsh`/`bash`/`fish`) |
153
+ | `mihomo completion <shell>` | 输出 shell 补全脚本(重定向或 eval 使用) |
149
154
  | `mihomo version` | 显示版本信息 |
150
155
  | `mihomo help` | 显示帮助信息 |
151
156
 
@@ -175,16 +180,19 @@ mihomo ui yacd # YACD
175
180
  ## Shell 补全
176
181
 
177
182
  ```bash
178
- # zsh(写入补全目录,或 eval "$(mihomo completion zsh)")
179
- mihomo completion zsh > ~/.zsh/completions/_mihomo
180
-
181
- # bash
182
- eval "$(mihomo completion bash)" # 或写入 ~/.bash_completion
183
+ # 一键安装到对应 shell 的默认补全位置(推荐)
184
+ mihomo completion install zsh # → ~/.zsh/completions/_mihomo
185
+ mihomo completion install bash # → 追加到 ~/.bash_completion(幂等,不覆盖已有内容)
186
+ mihomo completion install fish # → ~/.config/fish/completions/mihomo.fish
183
187
 
184
- # fish
188
+ # 或临时启用(不落盘)
189
+ eval "$(mihomo completion zsh)" # bash 同理
185
190
  mihomo completion fish | source
186
191
  ```
187
192
 
193
+ > zsh 的 `~/.zsh/completions` 不在默认 `fpath` 里(oh-my-zsh 默认已包含):
194
+ > 补全不生效时在 `~/.zshrc` 加一行 `fpath=(~/.zsh/completions $fpath)`,重新打开终端。
195
+
188
196
  覆盖全部命令、订阅/覆写/目录子命令与常用选项(`logs` 的 `-f`/`-n`、`kernel` 的 `--mirror` 等)。
189
197
 
190
198
  ## 模式说明
@@ -229,6 +237,8 @@ mihomo status # 查看状态
229
237
 
230
238
  `stop` 会一并关闭自启,这是它与「杀掉进程」的区别——只停不关的话,下次登录代理又自己回来了,而 CLI 已经告诉你「已停止」。
231
239
 
240
+ > `uninstall` 只卸服务,订阅/内核/日志仍留在数据目录(重装后可继续用)。要彻底移除 mihomo-cli:`mihomo reset --full` 删全部数据,再 `npm uninstall -g mihomo-cli`——`uninstall` 结束时也会提示这两步。
241
+
232
242
  - **`KeepAlive`** — 内核崩溃或被杀后由 launchd 自动拉起(约 10 秒节流后重启)
233
243
  - **`RunAtLoad`** — 登录后自动启动
234
244
  - 常驻的是系统 launchd 进程本身,**不额外占用资源、无轮询**
@@ -324,6 +334,7 @@ mihomo kernel --no-mirror
324
334
 
325
335
  - 默认更新间隔:12 小时(订阅服务端可通过 `profile-update-interval` 覆盖)
326
336
  - 触发时机:`start` 命令(`sub` 列表为纯只读,不再触发更新)
337
+ - **服务常驻期间不会自动更新**:launchd 只负责拉起内核,不会跑 `start`。`status` 会在订阅超过更新间隔时黄标提醒(`已超过 N 小时间隔,建议 mihomo sub update`),此时手动跑 `mihomo sub update` 或 `mihomo start` 即可
327
338
  - 更新失败时继续使用本地缓存,不影响使用
328
339
  - 自动更新默认超时 10 秒,可通过 `-u <ms>` 调整;使用 `-s` 可完全跳过自动更新
329
340
 
@@ -359,7 +370,7 @@ mihomo start --update-timeout=30000 # 长选项 + 等号
359
370
 
360
371
  ```
361
372
  ~/.mihomo-cli/
362
- ├── settings.json # 用户设置(订阅列表等)
373
+ ├── settings.json # 用户设置(订阅列表、端口覆盖、镜像偏好等)
363
374
  ├── overwrite.yaml # 覆写配置(主文件,可选)
364
375
  ├── overwrite.*.yaml # 覆写配置(扩展文件,如 overwrite.dns.yaml)
365
376
  ├── subscriptions/
@@ -450,6 +461,36 @@ match:
450
461
 
451
462
  > 注:`default-selected` 由 mihomo 内核决定默认选中项,优先级低于 `store-selected` 缓存的历史选择。若之前手动选过、且开启了 `store-selected`,需 `mihomo reset data` 清缓存后才能看到默认值接管。
452
463
 
464
+ ### 同时使用多个机场
465
+
466
+ 本 CLI 是单活跃订阅模型(`sub use` 切换),不合并多条订阅。要把第二个机场的节点并进当前订阅,用覆写引入 mihomo 原生的 `proxy-providers`——节点池由内核按 `interval` 自动刷新,不受单订阅模型限制:
467
+
468
+ ```yaml
469
+ # ~/.mihomo-cli/overwrite.providers.yaml
470
+ proxy-providers:
471
+ second-airport:
472
+ type: http
473
+ url: https://second-airport.example.com/api/v1/client/subscribe?token=xxx
474
+ interval: 86400 # 节点池自动刷新间隔(秒)
475
+ path: ./second-airport.yaml # 缓存文件(mihomo 管理,相对运行时配置目录)
476
+ health-check:
477
+ enable: true
478
+ url: https://www.gstatic.com/generate_204
479
+ interval: 300
480
+
481
+ # 新增一个走第二机场的分组(+ 是数组前置插入,订阅分组不动)
482
+ +proxy-groups:
483
+ - name: SecondAirport
484
+ type: select
485
+ use: [second-airport]
486
+
487
+ # 需要分流到它时加规则
488
+ rules+:
489
+ - 'DOMAIN-SUFFIX,corp.example.com,SecondAirport'
490
+ ```
491
+
492
+ provider 节点与订阅节点同池参与分组选择;节点延迟与手动切换在 Web UI(`mihomo ui`)里操作。若想让订阅里已有的某个分组也纳入第二机场的节点,用 `~proxy-groups` 按 name 就地 patch 该分组、加 `use` 字段
493
+
453
494
  ## Web UI
454
495
 
455
496
  内置三个常用 Web UI:
@@ -468,8 +509,9 @@ match:
468
509
  mihomo doctor
469
510
  ```
470
511
 
471
- 逐项检查内核可执行性、数据目录可写、settings 有效性、订阅配置与新鲜度、服务状态、端口占用、
472
- 配置可构建性、代理连通性,每项给出 ✓/!/✗ 与修复命令;存在异常项时退出码为 1,可接入脚本。
512
+ 逐项检查内核可执行性、数据目录可写、settings 有效性(含端口覆盖合法性)、订阅配置与新鲜度、服务状态、端口占用、
513
+ 配置可构建性、代理连通性、CLI 版本(落后时提示 `mihomo update`;npm registry 不可达则跳过),
514
+ 每项给出 ✓/!/✗ 与修复命令;存在异常项时退出码为 1,可接入脚本。
473
515
 
474
516
  ### 启动失败
475
517
 
@@ -502,11 +544,21 @@ sudo pkill -9 mihomo
502
544
 
503
545
  ### 端口被占用
504
546
 
505
- 默认端口(系统强制,不受订阅配置影响):
547
+ 默认端口(CLI 强制,不受订阅/覆写影响):
506
548
 
507
549
  - 混合端口 (HTTP + SOCKS5): `7890`
508
550
  - 外部控制器: `127.0.0.1:9090`
509
551
 
552
+ 与其他代理工具冲突或需要并存时,可在 `settings.json` 中覆盖端口(两键均可选,需为 1-65535 的整数且互不相同):
553
+
554
+ ```json
555
+ {
556
+ "ports": { "mixed": 17890, "controller": 19090 }
557
+ }
558
+ ```
559
+
560
+ 改动后 `mihomo start` 重新生成配置即生效;Web UI 连接地址与系统代理里的端口请使用新值(`mihomo status` 会显示实际端口)
561
+
510
562
  ## 安全特性
511
563
 
512
564
  - **URL 脱敏**:订阅 URL 中的 token、key、password 等敏感参数(含 query、userinfo 及路径型令牌)自动替换为 `***`。按整条 URL 处理、不按逗号切分——逗号在 query 中合法,切开会让 `?nodes=us,hk&token=xxx` 的 token 参数识别不出而明文输出
package/dist/index.js CHANGED
@@ -3076,9 +3076,8 @@ var RAW_SERVICE_LABEL = process.env.MIHOMO_CLI_DAEMON_LABEL;
3076
3076
  var RAW_SERVICE_LABEL_INPUT = RAW_SERVICE_LABEL;
3077
3077
  var SERVICE_LABEL = RAW_SERVICE_LABEL && isValidServiceLabel(RAW_SERVICE_LABEL) ? RAW_SERVICE_LABEL : DEFAULT_SERVICE_LABEL;
3078
3078
  var SERVICE_BINARY_NAME = "mihomo-cli-service";
3079
+ var DEFAULT_MIXED_PORT = 7890;
3079
3080
  var CONTROLLER_PORT = 9090;
3080
- var CONTROLLER_ADDR = `127.0.0.1:${CONTROLLER_PORT}`;
3081
- var CONTROLLER_BASE_URL = `http://${CONTROLLER_ADDR}`;
3082
3081
  var TUN_CONFIG = {
3083
3082
  tun: {
3084
3083
  enable: true,
@@ -3090,9 +3089,9 @@ var TUN_CONFIG = {
3090
3089
  }
3091
3090
  };
3092
3091
  var BASE_CONFIG = {
3093
- "mixed-port": 7890,
3092
+ // 注意:mixed-port 与 external-controller 不在此表——它们来自 settings.ports(getPorts),
3093
+ // config.ts 单独写入 systemConfig,订阅/覆写恒不可改
3094
3094
  "allow-lan": false,
3095
- "external-controller": CONTROLLER_ADDR,
3096
3095
  "unified-delay": true,
3097
3096
  "tcp-concurrent": true,
3098
3097
  "geo-auto-update": true,
@@ -3360,6 +3359,32 @@ function updateSettings(mutate) {
3360
3359
  function invalidateSettingsCache() {
3361
3360
  settingsCache = null;
3362
3361
  }
3362
+ function validatePort(value, key) {
3363
+ if (value === void 0) return void 0;
3364
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 1 || value > 65535) {
3365
+ throw new CliError(`settings.json \u7684 ${key} \u9700\u4E3A 1-65535 \u7684\u6574\u6570\uFF0C\u5F53\u524D\u662F ${JSON.stringify(value)}`, {
3366
+ label: "\u914D\u7F6E\u9519\u8BEF",
3367
+ hint: ["\u793A\u4F8B:", ' "ports": { "mixed": 17890, "controller": 19090 }', "\u4E24\u4E2A\u952E\u5747\u53EF\u9009\uFF1B\u5220\u6389 ports \u5219\u56DE\u5230\u9ED8\u8BA4\u7AEF\u53E3 7890/9090"]
3368
+ });
3369
+ }
3370
+ return value;
3371
+ }
3372
+ function getPorts() {
3373
+ const ports = readSettings().ports;
3374
+ if (ports === void 0) return { mixed: DEFAULT_MIXED_PORT, controller: CONTROLLER_PORT };
3375
+ if (ports === null || typeof ports !== "object" || Array.isArray(ports)) {
3376
+ throw new CliError('settings.json \u7684 ports \u9700\u4E3A\u5BF9\u8C61\uFF0C\u5982 { "mixed": 17890, "controller": 19090 }', { label: "\u914D\u7F6E\u9519\u8BEF" });
3377
+ }
3378
+ const mixed = validatePort(ports.mixed, "ports.mixed");
3379
+ const controller = validatePort(ports.controller, "ports.controller");
3380
+ if (mixed !== void 0 && controller !== void 0 && mixed === controller) {
3381
+ throw new CliError(`ports.mixed \u4E0E ports.controller \u4E0D\u80FD\u76F8\u540C\uFF08\u5F53\u524D\u5747\u4E3A ${mixed}\uFF09`, {
3382
+ label: "\u914D\u7F6E\u9519\u8BEF",
3383
+ hint: ["\u6DF7\u5408\u7AEF\u53E3\u4E0E\u63A7\u5236\u5668\u7AEF\u53E3\u5404\u9700\u72EC\u7ACB\u7AEF\u53E3\uFF0C\u76F8\u540C\u4F1A\u5BFC\u81F4\u5185\u6838\u542F\u52A8\u5931\u8D25"]
3384
+ });
3385
+ }
3386
+ return { mixed: mixed ?? DEFAULT_MIXED_PORT, controller: controller ?? CONTROLLER_PORT };
3387
+ }
3363
3388
  function maskSingleUrl(url) {
3364
3389
  try {
3365
3390
  const parsed = new URL(url);
@@ -4282,8 +4307,9 @@ function buildConfig(subRawContent, mode, scope) {
4282
4307
  systemConfig[key] = value;
4283
4308
  }
4284
4309
  }
4285
- systemConfig["external-controller"] = BASE_CONFIG["external-controller"];
4286
- systemConfig["mixed-port"] = BASE_CONFIG["mixed-port"];
4310
+ const ports = getPorts();
4311
+ systemConfig["external-controller"] = `127.0.0.1:${ports.controller}`;
4312
+ systemConfig["mixed-port"] = ports.mixed;
4287
4313
  delete withOverwrites["mixed-port"];
4288
4314
  delete withOverwrites.port;
4289
4315
  delete withOverwrites["socks-port"];
@@ -4997,17 +5023,18 @@ function logOversized() {
4997
5023
  async function tryHotReload() {
4998
5024
  const status = getServiceStatus();
4999
5025
  if (!status.running || status.pid === null) return false;
5026
+ const baseUrl = `http://127.0.0.1:${getPorts().controller}`;
5000
5027
  const controller = new AbortController();
5001
5028
  const timer = setTimeout(() => controller.abort(), HOT_RELOAD_TIMEOUT_MS);
5002
5029
  const secret = readSettings().controller_secret;
5003
5030
  const headers = { "Content-Type": "application/json" };
5004
5031
  if (secret) headers.Authorization = `Bearer ${secret}`;
5005
5032
  try {
5006
- const probe = await fetch(`${CONTROLLER_BASE_URL}/version`, { headers, signal: controller.signal });
5033
+ const probe = await fetch(`${baseUrl}/version`, { headers, signal: controller.signal });
5007
5034
  if (!probe.ok) return false;
5008
5035
  const info = await probe.json();
5009
5036
  if (typeof info?.version !== "string") return false;
5010
- const res = await fetch(`${CONTROLLER_BASE_URL}/configs?force=true`, {
5037
+ const res = await fetch(`${baseUrl}/configs?force=true`, {
5011
5038
  method: "PUT",
5012
5039
  headers,
5013
5040
  body: "{}",
@@ -5125,6 +5152,11 @@ function printVersion() {
5125
5152
  console.log(`${colors.gray("\u6570\u636E\u76EE\u5F55: ")}${USER_DATA_DIR}`);
5126
5153
  }
5127
5154
 
5155
+ // src/commands/completion.ts
5156
+ import fs10 from "fs";
5157
+ import os2 from "os";
5158
+ import path8 from "path";
5159
+
5128
5160
  // src/open.ts
5129
5161
  import { spawn } from "child_process";
5130
5162
 
@@ -5430,6 +5462,13 @@ async function withSpinner(label, fn) {
5430
5462
  function resolveUpdateInterval(cachedInterval) {
5431
5463
  return cachedInterval && cachedInterval > 0 ? cachedInterval : DEFAULT_UPDATE_INTERVAL_HOURS;
5432
5464
  }
5465
+ function isSubscriptionStale(cached, nowMs = Date.now()) {
5466
+ if (!cached.updated_at) return false;
5467
+ const t = new Date(cached.updated_at).getTime();
5468
+ if (Number.isNaN(t) || t > nowMs) return false;
5469
+ const ageHours = (nowMs - t) / 36e5;
5470
+ return ageHours > resolveUpdateInterval(cached.update_interval);
5471
+ }
5433
5472
  var HTTP_CLIENT = createHttpClient({ timeout: 6e4 });
5434
5473
  function isValidHttpUrl(url) {
5435
5474
  try {
@@ -5782,6 +5821,8 @@ function buildStatusJson(args) {
5782
5821
  ...args.cached?.download !== void 0 ? { download: args.cached.download } : {},
5783
5822
  ...args.cached?.total !== void 0 ? { total: args.cached.total } : {},
5784
5823
  ...args.cached?.expire !== void 0 ? { expire: args.cached.expire } : {},
5824
+ ...args.cached?.updated_at !== void 0 ? { updatedAt: args.cached.updated_at } : {},
5825
+ stale: args.cached ? isSubscriptionStale(args.cached) : false,
5785
5826
  urgency
5786
5827
  } : null,
5787
5828
  overwrite: { enabled: args.overwriteEnabled, files: args.overwriteFiles },
@@ -5886,6 +5927,14 @@ async function printStatus(args = []) {
5886
5927
  subLine += ` (${formatProxySummary(info)})`;
5887
5928
  }
5888
5929
  console.log(subLine);
5930
+ if (cached?.updated_at) {
5931
+ const rel = formatRelativeTime(cached.updated_at) || formatDate(cached.updated_at);
5932
+ if (isSubscriptionStale(cached)) {
5933
+ console.log(colors.yellow(`\u66F4\u65B0: ${rel}\uFF08\u5DF2\u8D85\u8FC7 ${resolveUpdateInterval(cached.update_interval)} \u5C0F\u65F6\u95F4\u9694\uFF0C\u5EFA\u8BAE mihomo sub update\uFF09`));
5934
+ } else {
5935
+ console.log(`${colors.gray("\u66F4\u65B0: ")}${rel}`);
5936
+ }
5937
+ }
5889
5938
  const traffic = cached ? formatTraffic(cached.upload, cached.download, cached.total) : null;
5890
5939
  if (traffic) {
5891
5940
  console.log(`${colors.gray("\u6D41\u91CF: ")}${trafficColor(traffic, urgency, cached?.total, cached?.upload, cached?.download)}`);
@@ -5999,7 +6048,7 @@ async function cmdStart(args) {
5999
6048
  }
6000
6049
  await printStatus();
6001
6050
  if (targetMode === "mixed") {
6002
- console.log(colors.gray("\u63D0\u793A: Mixed \u6A21\u5F0F\u9700\u5728\u7CFB\u7EDF\u8BBE\u7F6E\u914D\u7F6E HTTP/SOCKS \u4EE3\u7406 127.0.0.1:7890\uFF08TUN \u6A21\u5F0F\u65E0\u9700\uFF09"));
6051
+ console.log(colors.gray(`\u63D0\u793A: Mixed \u6A21\u5F0F\u9700\u5728\u7CFB\u7EDF\u8BBE\u7F6E\u914D\u7F6E HTTP/SOCKS \u4EE3\u7406 127.0.0.1:${getPorts().mixed}\uFF08TUN \u6A21\u5F0F\u65E0\u9700\uFF09`));
6003
6052
  console.log("");
6004
6053
  }
6005
6054
  }
@@ -6177,6 +6226,7 @@ async function cmdOverwrite(args) {
6177
6226
  }
6178
6227
 
6179
6228
  // src/commands/subscription.ts
6229
+ import { spawnSync as spawnSync5 } from "child_process";
6180
6230
  function printRestartHintIfRunning() {
6181
6231
  if (getRunningState().running) {
6182
6232
  console.log(colors.yellow("\u63D0\u793A: \u8FD0\u884C\u4E2D\u7684\u5B9E\u4F8B\u4ECD\u4F7F\u7528\u65E7\u914D\u7F6E\uFF0C\u6267\u884C mihomo start \u4F7F\u66F4\u65B0\u751F\u6548"));
@@ -6230,11 +6280,37 @@ function assertNotFlagLike(name, usage) {
6230
6280
  });
6231
6281
  }
6232
6282
  }
6283
+ function readUrlFromClipboard() {
6284
+ if (!process.stdin.isTTY) return null;
6285
+ try {
6286
+ const r = spawnSync5("pbpaste", [], { encoding: "utf8", timeout: 3e3 });
6287
+ if (r.status !== 0) return null;
6288
+ const text = (r.stdout || "").trim();
6289
+ return isValidHttpUrl(text) ? text : null;
6290
+ } catch {
6291
+ return null;
6292
+ }
6293
+ }
6233
6294
  async function subAdd(args) {
6234
- const url = args[2]?.trim();
6295
+ let url = args[2]?.trim();
6235
6296
  const name = args[3] || "default";
6236
6297
  if (!url) {
6237
- throw new CliError("\u8BF7\u63D0\u4F9B\u6709\u6548\u7684\u8BA2\u9605 URL");
6298
+ const clipped = readUrlFromClipboard();
6299
+ if (clipped) {
6300
+ console.log("\u672A\u63D0\u4F9B URL\uFF0C\u4ECE\u526A\u8D34\u677F\u8BFB\u53D6\u5230:");
6301
+ console.log(` ${maskUrl(clipped)}`);
6302
+ if (!await confirmPrompt(`\u6DFB\u52A0\u4E3A\u8BA2\u9605 "${name}"?`)) {
6303
+ console.log("\u5DF2\u53D6\u6D88");
6304
+ return;
6305
+ }
6306
+ url = clipped;
6307
+ } else if (process.stdin.isTTY) {
6308
+ throw new CliError("\u526A\u8D34\u677F\u4E2D\u6CA1\u6709\u6709\u6548\u7684\u8BA2\u9605 URL", {
6309
+ hint: ["\u5148\u590D\u5236\u8BA2\u9605\u94FE\u63A5\u540E\u91CD\u8BD5\uFF0C\u6216\u663E\u5F0F\u4F20\u5165:", " mihomo sub add <url> [name]"]
6310
+ });
6311
+ } else {
6312
+ throw new CliError("\u8BF7\u63D0\u4F9B\u6709\u6548\u7684\u8BA2\u9605 URL", { hint: ["\u7528\u6CD5: mihomo sub add <url> [name]"] });
6313
+ }
6238
6314
  }
6239
6315
  if (!isValidHttpUrl(url)) {
6240
6316
  throw new CliError("\u8BF7\u63D0\u4F9B\u6709\u6548\u7684\u8BA2\u9605 URL\uFF08\u9700\u4EE5 http:// \u6216 https:// \u5F00\u5934\uFF09");
@@ -6384,7 +6460,7 @@ function buildZsh(commands, groups) {
6384
6460
  const lines = [
6385
6461
  "#compdef mihomo mhm mh mihomo-cli",
6386
6462
  "",
6387
- '# mihomo-cli zsh \u8865\u5168\uFF08mihomo completion zsh \u751F\u6210\uFF1B\u5B89\u88C5: \u5199\u5165 ~/.zsh/completions/_mihomo \u6216 eval "$(mihomo completion zsh)"\uFF09',
6463
+ '# mihomo-cli zsh \u8865\u5168\uFF08mihomo completion zsh \u751F\u6210\uFF1B\u5B89\u88C5: mihomo completion install zsh\uFF0C\u6216 eval "$(mihomo completion zsh)"\uFF09',
6388
6464
  "",
6389
6465
  "_mihomo() {",
6390
6466
  " local -a commands subcmds",
@@ -6436,7 +6512,11 @@ function buildZsh(commands, groups) {
6436
6512
  " _arguments '-y[\u8DF3\u8FC7\u786E\u8BA4]' '--full[\u5220\u5168\u90E8]'",
6437
6513
  " ;;",
6438
6514
  " completion)",
6439
- ` _values 'shell' ${SHELLS.join(" ")}`,
6515
+ " if (( CURRENT == 2 )); then",
6516
+ " _values 'action' install",
6517
+ " elif (( CURRENT == 3 )) && [[ ${words[2]} == install ]]; then",
6518
+ ` _values 'shell' ${SHELLS.join(" ")}`,
6519
+ " fi",
6440
6520
  " ;;",
6441
6521
  " *)",
6442
6522
  " _files",
@@ -6470,7 +6550,7 @@ function buildBash(commands, groups) {
6470
6550
  fi
6471
6551
  ;;`;
6472
6552
  }).join("\n");
6473
- return `# mihomo-cli bash \u8865\u5168\uFF08mihomo completion bash \u751F\u6210\uFF1B\u5B89\u88C5: eval "$(mihomo completion bash)"\uFF09
6553
+ return `# mihomo-cli bash \u8865\u5168\uFF08mihomo completion bash \u751F\u6210\uFF1B\u5B89\u88C5: mihomo completion install bash\uFF0C\u6216 eval "$(mihomo completion bash)"\uFF09
6474
6554
 
6475
6555
  _mihomo_completions() {
6476
6556
  local cur prev
@@ -6498,7 +6578,11 @@ ${subCase}
6498
6578
  COMPREPLY=( $(compgen -W "subs logs data runtime settings kernel overwrites service --full -y" -- "\${cur}") )
6499
6579
  ;;
6500
6580
  completion)
6501
- COMPREPLY=( $(compgen -W "${SHELLS.join(" ")}" -- "\${cur}") )
6581
+ if [[ \${COMP_CWORD} -eq 2 ]]; then
6582
+ COMPREPLY=( $(compgen -W "install" -- "\${cur}") )
6583
+ elif [[ \${COMP_CWORD} -eq 3 ]] && [[ "\${COMP_WORDS[2]}" == install ]]; then
6584
+ COMPREPLY=( $(compgen -W "${SHELLS.join(" ")}" -- "\${cur}") )
6585
+ fi
6502
6586
  ;;
6503
6587
  esac
6504
6588
  }
@@ -6507,7 +6591,7 @@ complete -F _mihomo_completions mihomo mhm mh mihomo-cli
6507
6591
  }
6508
6592
  function buildFish(commands, groups) {
6509
6593
  const lines = [
6510
- "# mihomo-cli fish \u8865\u5168\uFF08mihomo completion fish \u751F\u6210\uFF1B\u5B89\u88C5: mihomo completion fish | source\uFF09",
6594
+ "# mihomo-cli fish \u8865\u5168\uFF08mihomo completion fish \u751F\u6210\uFF1B\u5B89\u88C5: mihomo completion install fish\uFF0C\u6216 mihomo completion fish | source\uFF09",
6511
6595
  "",
6512
6596
  "for cmd in mihomo mhm mh mihomo-cli"
6513
6597
  ];
@@ -6522,7 +6606,8 @@ function buildFish(commands, groups) {
6522
6606
  }
6523
6607
  lines.push(` complete -c $cmd -n "__fish_seen_subcommand_from directory dir dirs directories open" -a '${DIR_TARGETS.join(" ")}'`);
6524
6608
  lines.push(` complete -c $cmd -n "__fish_seen_subcommand_from ui" -a '${UI_NAMES.join(" ")}'`);
6525
- lines.push(` complete -c $cmd -n "__fish_seen_subcommand_from completion" -a '${SHELLS.join(" ")}'`);
6609
+ lines.push(` complete -c $cmd -n "__fish_seen_subcommand_from completion" -a 'install' -d '\u5B89\u88C5\u8865\u5168\u5230\u9ED8\u8BA4\u4F4D\u7F6E'`);
6610
+ lines.push(` complete -c $cmd -n "__fish_seen_subcommand_from completion; and __fish_seen_subcommand_from install" -a '${SHELLS.join(" ")}'`);
6526
6611
  lines.push(` complete -c $cmd -n "__fish_seen_subcommand_from kernel" -a '\\--mirror' -d '\u8D70\u955C\u50CF\u4E0B\u8F7D'`);
6527
6612
  lines.push(` complete -c $cmd -n "__fish_seen_subcommand_from kernel" -a '\\--no-mirror' -d '\u76F4\u8FDE\u4E0B\u8F7D'`);
6528
6613
  lines.push("end");
@@ -6546,22 +6631,193 @@ function buildCompletionScript(shell, commands) {
6546
6631
  }
6547
6632
  }
6548
6633
  }
6634
+ var BASH_MARKER = "# >>> mihomo-cli completion (append)";
6635
+ function completionInstallPath(shell) {
6636
+ const home = os2.homedir();
6637
+ switch (shell) {
6638
+ case "zsh":
6639
+ return path8.join(home, ".zsh", "completions", "_mihomo");
6640
+ case "bash":
6641
+ return path8.join(home, ".bash_completion");
6642
+ case "fish":
6643
+ return path8.join(home, ".config", "fish", "completions", "mihomo.fish");
6644
+ default:
6645
+ return null;
6646
+ }
6647
+ }
6648
+ function installCompletion(shell, commands) {
6649
+ if (!shell) {
6650
+ throw new CliError("\u8BF7\u6307\u5B9A shell", { hint: [`\u7528\u6CD5: mihomo completion install <${SHELLS.join("|")}>`] });
6651
+ }
6652
+ const target = completionInstallPath(shell);
6653
+ if (!target) {
6654
+ buildCompletionScript(shell, commands);
6655
+ return;
6656
+ }
6657
+ const script = buildCompletionScript(shell, commands);
6658
+ console.log(`\u5B89\u88C5 ${shell} \u8865\u5168: ${target}`);
6659
+ if (shell === "bash") {
6660
+ const existing = fs10.existsSync(target) ? fs10.readFileSync(target, "utf8") : "";
6661
+ if (existing.includes(BASH_MARKER)) {
6662
+ console.log("\u5DF2\u5B89\u88C5\u8FC7\uFF08~/.bash_completion \u5DF2\u5305\u542B mihomo \u8865\u5168\uFF09\uFF0C\u8DF3\u8FC7");
6663
+ return;
6664
+ }
6665
+ fs10.mkdirSync(path8.dirname(target), { recursive: true });
6666
+ fs10.appendFileSync(target, `
6667
+ ${BASH_MARKER}
6668
+ ${script}${BASH_MARKER.replace(">>>", "<<<")}
6669
+ `);
6670
+ console.log(colors.green("\u5DF2\u8FFD\u52A0\u5230 ~/.bash_completion\uFF08\u91CD\u65B0\u6253\u5F00\u7EC8\u7AEF\u751F\u6548\uFF09"));
6671
+ return;
6672
+ }
6673
+ fs10.mkdirSync(path8.dirname(target), { recursive: true });
6674
+ fs10.writeFileSync(target, script, { mode: 420 });
6675
+ console.log(colors.green("\u5DF2\u5199\u5165\uFF08\u91CD\u65B0\u6253\u5F00\u7EC8\u7AEF\u751F\u6548\uFF09"));
6676
+ if (shell === "zsh") {
6677
+ console.log(colors.gray("\u82E5\u8865\u5168\u4E0D\u751F\u6548\uFF0C\u5728 ~/.zshrc \u4E2D\u52A0\u4E00\u884C: fpath=(~/.zsh/completions $fpath)"));
6678
+ }
6679
+ }
6549
6680
  function cmdCompletion(args, commands) {
6681
+ if (args[1] === "install") {
6682
+ installCompletion(args[2], commands);
6683
+ return;
6684
+ }
6550
6685
  const shell = args[1];
6551
6686
  if (!shell) {
6552
6687
  throw new CliError("\u8BF7\u6307\u5B9A shell", {
6553
- hint: [`\u7528\u6CD5: mihomo completion <${SHELLS.join("|")}>`, '\u5B89\u88C5: eval "$(mihomo completion zsh)"\uFF0C\u6216\u5199\u5165\u5BF9\u5E94 shell \u7684\u8865\u5168\u76EE\u5F55']
6688
+ hint: [
6689
+ `\u7528\u6CD5: mihomo completion <${SHELLS.join("|")}>`,
6690
+ `\u5B89\u88C5\u5230\u9ED8\u8BA4\u4F4D\u7F6E: mihomo completion install <${SHELLS.join("|")}>`,
6691
+ '\u4E34\u65F6\u542F\u7528: eval "$(mihomo completion zsh)"'
6692
+ ]
6554
6693
  });
6555
6694
  }
6556
6695
  console.log(buildCompletionScript(shell, commands));
6557
6696
  }
6558
6697
 
6559
6698
  // src/commands/doctor.ts
6560
- import { spawnSync as spawnSync5 } from "child_process";
6561
- import fs10 from "fs";
6699
+ import { spawnSync as spawnSync6 } from "child_process";
6700
+ import fs11 from "fs";
6701
+
6702
+ // node_modules/compare-versions/lib/esm/utils.js
6703
+ var semver = /^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;
6704
+ var validateAndParse = (version) => {
6705
+ if (typeof version !== "string") {
6706
+ throw new TypeError("Invalid argument expected string");
6707
+ }
6708
+ const match = version.match(semver);
6709
+ if (!match) {
6710
+ throw new Error(`Invalid argument not valid semver ('${version}' received)`);
6711
+ }
6712
+ match.shift();
6713
+ return match;
6714
+ };
6715
+ var isWildcard = (s) => s === "*" || s === "x" || s === "X";
6716
+ var tryParse = (v) => {
6717
+ const n = parseInt(v, 10);
6718
+ return isNaN(n) ? v : n;
6719
+ };
6720
+ var forceType = (a, b) => typeof a !== typeof b ? [String(a), String(b)] : [a, b];
6721
+ var compareStrings = (a, b) => {
6722
+ if (isWildcard(a) || isWildcard(b))
6723
+ return 0;
6724
+ const [ap, bp] = forceType(tryParse(a), tryParse(b));
6725
+ if (ap > bp)
6726
+ return 1;
6727
+ if (ap < bp)
6728
+ return -1;
6729
+ return 0;
6730
+ };
6731
+ var compareSegments = (a, b) => {
6732
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
6733
+ const r = compareStrings(a[i] || "0", b[i] || "0");
6734
+ if (r !== 0)
6735
+ return r;
6736
+ }
6737
+ return 0;
6738
+ };
6739
+
6740
+ // node_modules/compare-versions/lib/esm/compareVersions.js
6741
+ var compareVersions = (v1, v2) => {
6742
+ const n1 = validateAndParse(v1);
6743
+ const n2 = validateAndParse(v2);
6744
+ const p1 = n1.pop();
6745
+ const p2 = n2.pop();
6746
+ const r = compareSegments(n1, n2);
6747
+ if (r !== 0)
6748
+ return r;
6749
+ if (p1 && p2) {
6750
+ return compareSegments(p1.split("."), p2.split("."));
6751
+ } else if (p1 || p2) {
6752
+ return p1 ? -1 : 1;
6753
+ }
6754
+ return 0;
6755
+ };
6756
+
6757
+ // src/commands/update.ts
6758
+ import { execFile as execFile2, spawn as spawn2 } from "child_process";
6759
+ import { promisify as promisify2 } from "util";
6760
+ var execFileAsync2 = promisify2(execFile2);
6761
+ var NPM_VIEW_TIMEOUT_MS = 15e3;
6762
+ async function getLatestNpmVersion(timeoutMs = NPM_VIEW_TIMEOUT_MS) {
6763
+ try {
6764
+ const { stdout } = await execFileAsync2("npm", ["view", PKG_NAME, "version"], { timeout: timeoutMs });
6765
+ const version = stdout.trim().split("\n").pop()?.trim();
6766
+ return version || null;
6767
+ } catch {
6768
+ return null;
6769
+ }
6770
+ }
6771
+ async function cmdUpdate() {
6772
+ console.log(`\u5F53\u524D\u7248\u672C: ${colors.cyan(VERSION)}`);
6773
+ console.log("");
6774
+ const latest = await withSpinner("\u67E5\u8BE2 npm \u6700\u65B0\u7248\u672C", getLatestNpmVersion);
6775
+ if (latest && latest === VERSION) {
6776
+ console.log(`\u5DF2\u662F\u6700\u65B0\u7248\u672C (${colors.green(VERSION)})\uFF0C\u65E0\u9700\u66F4\u65B0`);
6777
+ return;
6778
+ }
6779
+ if (latest) {
6780
+ console.log(`\u6700\u65B0\u7248\u672C: ${colors.cyan(latest)}`);
6781
+ } else {
6782
+ console.log(colors.yellow("\u65E0\u6CD5\u67E5\u8BE2\u6700\u65B0\u7248\u672C\uFF08\u7F51\u7EDC\u95EE\u9898\uFF1F\uFF09\uFF0C\u5C06\u76F4\u63A5\u5C1D\u8BD5\u91CD\u65B0\u5B89\u88C5"));
6783
+ }
6784
+ console.log("");
6785
+ console.log("\u6B63\u5728\u66F4\u65B0 mihomo-cli...");
6786
+ console.log("");
6787
+ await new Promise((resolve, reject) => {
6788
+ const npm = spawn2("npm", ["install", "-g", PKG_NAME], { stdio: "inherit" });
6789
+ npm.on("close", (code) => {
6790
+ if (code === 0) {
6791
+ resolve();
6792
+ } else {
6793
+ reject(new CliError("\u66F4\u65B0\u5931\u8D25\u3002\u82E5\u4E3A\u6743\u9650\u95EE\u9898\uFF08EACCES\uFF09\uFF0C\u8BF7\u68C0\u67E5 npm \u5168\u5C40\u76EE\u5F55\u6743\u9650\u6216\u4F7F\u7528 nvm \u7BA1\u7406 Node", { exitCode: code || 1 }));
6794
+ }
6795
+ });
6796
+ npm.on("error", (e) => {
6797
+ const perm = e.message.includes("EACCES") || e.message.includes("permission");
6798
+ reject(perm ? new CliError("\u6743\u9650\u4E0D\u8DB3\uFF08EACCES\uFF09\uFF0C\u8BF7\u68C0\u67E5 npm \u5168\u5C40\u76EE\u5F55\u6743\u9650\u6216\u4F7F\u7528 nvm \u7BA1\u7406 Node") : new CliError(`\u6267\u884C\u5931\u8D25: ${e.message}`));
6799
+ });
6800
+ });
6801
+ try {
6802
+ const { stdout } = await execFileAsync2("npm", ["list", "-g", PKG_NAME, "--json", "--depth=0"]);
6803
+ const result = JSON.parse(stdout);
6804
+ const newVersion = result.dependencies?.[PKG_NAME]?.version;
6805
+ console.log("");
6806
+ if (newVersion) {
6807
+ console.log(`\u66F4\u65B0\u5B8C\u6210\uFF0C\u6700\u65B0\u7248\u672C: ${colors.green(newVersion)}`);
6808
+ } else {
6809
+ console.log("\u66F4\u65B0\u5B8C\u6210");
6810
+ }
6811
+ } catch {
6812
+ console.log("");
6813
+ console.log("\u66F4\u65B0\u5B8C\u6210");
6814
+ }
6815
+ }
6816
+
6817
+ // src/commands/doctor.ts
6562
6818
  function isPortListening(port) {
6563
6819
  try {
6564
- const r = spawnSync5("lsof", ["-nP", `-iTCP:${port}`, "-sTCP:LISTEN"], { encoding: "utf8", timeout: 5e3 });
6820
+ const r = spawnSync6("lsof", ["-nP", `-iTCP:${port}`, "-sTCP:LISTEN"], { encoding: "utf8", timeout: 5e3 });
6565
6821
  return r.status === 0 && (r.stdout || "").trim().length > 0;
6566
6822
  } catch {
6567
6823
  return false;
@@ -6576,7 +6832,7 @@ async function collectChecks() {
6576
6832
  push("\u5185\u6838", "fail", "\u672A\u5B89\u88C5", "mihomo kernel");
6577
6833
  } else {
6578
6834
  const v = getKernelVersion();
6579
- const r = spawnSync5(PATHS.mihomoBinary, ["-v"], { encoding: "utf8", timeout: 5e3 });
6835
+ const r = spawnSync6(PATHS.mihomoBinary, ["-v"], { encoding: "utf8", timeout: 5e3 });
6580
6836
  if (r.status === 0 && /v?\d+\.\d+\.\d+/.test(`${r.stdout}${r.stderr}`)) {
6581
6837
  push("\u5185\u6838", "ok", v || "\u53EF\u6267\u884C");
6582
6838
  } else {
@@ -6584,13 +6840,13 @@ async function collectChecks() {
6584
6840
  }
6585
6841
  }
6586
6842
  try {
6587
- fs10.accessSync(USER_DATA_DIR, fs10.constants.W_OK);
6843
+ fs11.accessSync(USER_DATA_DIR, fs11.constants.W_OK);
6588
6844
  push("\u6570\u636E\u76EE\u5F55", "ok", USER_DATA_DIR);
6589
6845
  } catch {
6590
6846
  push("\u6570\u636E\u76EE\u5F55", "fail", `\u4E0D\u53EF\u5199: ${USER_DATA_DIR}`, "\u68C0\u67E5\u76EE\u5F55\u6743\u9650");
6591
6847
  }
6592
- if (fs10.existsSync(PATHS.settingsFile)) {
6593
- if (isValidSettingsContent(fs10.readFileSync(PATHS.settingsFile, "utf8"))) {
6848
+ if (fs11.existsSync(PATHS.settingsFile)) {
6849
+ if (isValidSettingsContent(fs11.readFileSync(PATHS.settingsFile, "utf8"))) {
6594
6850
  push("\u8BBE\u7F6E\u6587\u4EF6", "ok", "\u683C\u5F0F\u6709\u6548");
6595
6851
  } else {
6596
6852
  push("\u8BBE\u7F6E\u6587\u4EF6", "warn", "\u683C\u5F0F\u635F\u574F\u6216\u975E\u5BF9\u8C61\uFF0C\u8BFB\u53D6\u65F6\u4F1A\u56DE\u9000\u9ED8\u8BA4\u5E76\u5907\u4EFD\u4E3A .bak", "\u5220\u9664\u6216\u4FEE\u590D settings.json");
@@ -6613,10 +6869,8 @@ async function collectChecks() {
6613
6869
  const cached = subs.find((s) => s.name === active.name);
6614
6870
  if (cached?.updated_at) {
6615
6871
  const rel = formatRelativeTime(cached.updated_at);
6616
- const intervalH = resolveUpdateInterval(cached.update_interval);
6617
- const ageH = (Date.now() - new Date(cached.updated_at).getTime()) / 36e5;
6618
- if (ageH > intervalH) {
6619
- push("\u8BA2\u9605\u65B0\u9C9C\u5EA6", "warn", `${rel ?? "\u672A\u77E5"}\u524D\u66F4\u65B0\uFF0C\u5DF2\u8D85\u8FC7 ${intervalH} \u5C0F\u65F6\u95F4\u9694`, "mihomo sub update");
6872
+ if (isSubscriptionStale(cached)) {
6873
+ push("\u8BA2\u9605\u65B0\u9C9C\u5EA6", "warn", `${rel ?? "\u672A\u77E5"}\u524D\u66F4\u65B0\uFF0C\u5DF2\u8D85\u8FC7 ${resolveUpdateInterval(cached.update_interval)} \u5C0F\u65F6\u95F4\u9694`, "mihomo sub update");
6620
6874
  } else {
6621
6875
  push("\u8BA2\u9605\u65B0\u9C9C\u5EA6", "ok", `${rel ?? "\u672A\u77E5"}\u524D\u66F4\u65B0`);
6622
6876
  }
@@ -6646,7 +6900,14 @@ async function collectChecks() {
6646
6900
  }
6647
6901
  const state = getRunningState();
6648
6902
  const info = getConfigInfo();
6649
- const mixedPort = info?.mixedPort ?? 7890;
6903
+ let mixedPortDefault = DEFAULT_MIXED_PORT;
6904
+ try {
6905
+ const ports = getPorts();
6906
+ mixedPortDefault = ports.mixed;
6907
+ } catch (e) {
6908
+ push("\u7AEF\u53E3\u914D\u7F6E", "fail", e.message, "\u4FEE\u6B63 settings.json \u7684 ports\uFF081-65535 \u6574\u6570\uFF0Cmixed \u4E0E controller \u4E0D\u80FD\u76F8\u540C\uFF09");
6909
+ }
6910
+ const mixedPort = info?.mixedPort ?? mixedPortDefault;
6650
6911
  if (state.running) {
6651
6912
  if (isPortListening(mixedPort)) {
6652
6913
  push("\u7AEF\u53E3", "ok", `${mixedPort} \u6B63\u5728\u76D1\u542C`);
@@ -6679,6 +6940,14 @@ async function collectChecks() {
6679
6940
  } else {
6680
6941
  push("\u4EE3\u7406\u8FDE\u901A", "skip", "\u672A\u8FD0\u884C");
6681
6942
  }
6943
+ const latest = await getLatestNpmVersion(4e3);
6944
+ if (latest === null) {
6945
+ push("CLI \u7248\u672C", "skip", "npm registry \u4E0D\u53EF\u8FBE\uFF0C\u8DF3\u8FC7\u68C0\u67E5");
6946
+ } else if (compareVersions(latest, VERSION) > 0) {
6947
+ push("CLI \u7248\u672C", "warn", `\u5F53\u524D ${VERSION}\uFF0C\u6700\u65B0 ${latest}`, "mihomo update");
6948
+ } else {
6949
+ push("CLI \u7248\u672C", "ok", `${VERSION}\uFF08\u6700\u65B0\uFF09`);
6950
+ }
6682
6951
  return checks;
6683
6952
  }
6684
6953
  async function cmdDoctor() {
@@ -6707,66 +6976,9 @@ async function cmdDoctor() {
6707
6976
  }
6708
6977
 
6709
6978
  // src/kernel.ts
6710
- import { spawnSync as spawnSync6 } from "child_process";
6711
- import fs11 from "fs";
6712
- import path8 from "path";
6713
-
6714
- // node_modules/compare-versions/lib/esm/utils.js
6715
- var semver = /^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;
6716
- var validateAndParse = (version) => {
6717
- if (typeof version !== "string") {
6718
- throw new TypeError("Invalid argument expected string");
6719
- }
6720
- const match = version.match(semver);
6721
- if (!match) {
6722
- throw new Error(`Invalid argument not valid semver ('${version}' received)`);
6723
- }
6724
- match.shift();
6725
- return match;
6726
- };
6727
- var isWildcard = (s) => s === "*" || s === "x" || s === "X";
6728
- var tryParse = (v) => {
6729
- const n = parseInt(v, 10);
6730
- return isNaN(n) ? v : n;
6731
- };
6732
- var forceType = (a, b) => typeof a !== typeof b ? [String(a), String(b)] : [a, b];
6733
- var compareStrings = (a, b) => {
6734
- if (isWildcard(a) || isWildcard(b))
6735
- return 0;
6736
- const [ap, bp] = forceType(tryParse(a), tryParse(b));
6737
- if (ap > bp)
6738
- return 1;
6739
- if (ap < bp)
6740
- return -1;
6741
- return 0;
6742
- };
6743
- var compareSegments = (a, b) => {
6744
- for (let i = 0; i < Math.max(a.length, b.length); i++) {
6745
- const r = compareStrings(a[i] || "0", b[i] || "0");
6746
- if (r !== 0)
6747
- return r;
6748
- }
6749
- return 0;
6750
- };
6751
-
6752
- // node_modules/compare-versions/lib/esm/compareVersions.js
6753
- var compareVersions = (v1, v2) => {
6754
- const n1 = validateAndParse(v1);
6755
- const n2 = validateAndParse(v2);
6756
- const p1 = n1.pop();
6757
- const p2 = n2.pop();
6758
- const r = compareSegments(n1, n2);
6759
- if (r !== 0)
6760
- return r;
6761
- if (p1 && p2) {
6762
- return compareSegments(p1.split("."), p2.split("."));
6763
- } else if (p1 || p2) {
6764
- return p1 ? -1 : 1;
6765
- }
6766
- return 0;
6767
- };
6768
-
6769
- // src/kernel.ts
6979
+ import { spawnSync as spawnSync7 } from "child_process";
6980
+ import fs12 from "fs";
6981
+ import path9 from "path";
6770
6982
  var GITHUB_REPO = "MetaCubeX/mihomo";
6771
6983
  var KERNEL_HTTP_TIMEOUT = 12e4;
6772
6984
  var KERNEL_DOWNLOAD_TIMEOUT = 18e4;
@@ -6847,10 +7059,10 @@ async function checkUpdate() {
6847
7059
  }
6848
7060
  function findBinaryInDir(dir, maxDepth = 4) {
6849
7061
  if (maxDepth <= 0) return null;
6850
- const files = fs11.readdirSync(dir);
7062
+ const files = fs12.readdirSync(dir);
6851
7063
  for (const f of files) {
6852
- const fullPath = path8.join(dir, f);
6853
- const stat = fs11.lstatSync(fullPath);
7064
+ const fullPath = path9.join(dir, f);
7065
+ const stat = fs12.lstatSync(fullPath);
6854
7066
  if (stat.isDirectory()) {
6855
7067
  const found = findBinaryInDir(fullPath, maxDepth - 1);
6856
7068
  if (found) return found;
@@ -6878,7 +7090,7 @@ async function downloadKernel(progressCallback, mirror, releaseInfo) {
6878
7090
  }
6879
7091
  assertTrustedAssetUrl(asset.browser_download_url);
6880
7092
  const downloadUrl = withMirror(asset.browser_download_url, mirror);
6881
- const tempPath = path8.join(DIRS.kernel, path8.basename(asset.name));
7093
+ const tempPath = path9.join(DIRS.kernel, path9.basename(asset.name));
6882
7094
  const sizeMB = (asset.size / 1024 / 1024).toFixed(2);
6883
7095
  if (mirror && progressCallback) {
6884
7096
  progressCallback("\u63D0\u793A: \u7ECF\u7B2C\u4E09\u65B9\u955C\u50CF\u4E2D\u8F6C\u4E0B\u8F7D\uFF0C\u65E0\u6CD5\u9A8C\u8BC1\u6765\u6E90\u5B8C\u6574\u6027\uFF0C\u5EFA\u8BAE\u76F4\u8FDE\u6216\u81EA\u884C\u6821\u9A8C\u4EA7\u7269");
@@ -6887,7 +7099,7 @@ async function downloadKernel(progressCallback, mirror, releaseInfo) {
6887
7099
  progressCallback(`\u4E0B\u8F7D\u5185\u6838: ${asset.name} (${sizeMB} MB)`);
6888
7100
  }
6889
7101
  const maxBytes = Number.isFinite(asset.size) && asset.size > 0 ? Math.floor(asset.size * 2 + 1024 * 1024) : 512 * 1024 * 1024;
6890
- const curlResult = spawnSync6(
7102
+ const curlResult = spawnSync7(
6891
7103
  "curl",
6892
7104
  [
6893
7105
  "-L",
@@ -6916,19 +7128,19 @@ async function downloadKernel(progressCallback, mirror, releaseInfo) {
6916
7128
  }
6917
7129
  if (curlResult.status !== 0) {
6918
7130
  try {
6919
- fs11.unlinkSync(tempPath);
7131
+ fs12.unlinkSync(tempPath);
6920
7132
  } catch {
6921
7133
  }
6922
7134
  throw new Error(`\u4E0B\u8F7D\u5931\u8D25 (curl \u9000\u51FA\u7801 ${curlResult.status})`);
6923
7135
  }
6924
- if (!fs11.existsSync(tempPath)) {
7136
+ if (!fs12.existsSync(tempPath)) {
6925
7137
  throw new Error("\u4E0B\u8F7D\u5931\u8D25: \u6587\u4EF6\u672A\u751F\u6210");
6926
7138
  }
6927
7139
  if (Number.isFinite(asset.size) && asset.size > 0) {
6928
- const actual = fs11.statSync(tempPath).size;
7140
+ const actual = fs12.statSync(tempPath).size;
6929
7141
  if (actual !== asset.size) {
6930
7142
  try {
6931
- fs11.unlinkSync(tempPath);
7143
+ fs12.unlinkSync(tempPath);
6932
7144
  } catch {
6933
7145
  }
6934
7146
  throw new Error(
@@ -6944,7 +7156,7 @@ async function downloadKernel(progressCallback, mirror, releaseInfo) {
6944
7156
  let extractedBinary = null;
6945
7157
  try {
6946
7158
  if (tempPath.endsWith(".tar.gz") || tempPath.endsWith(".tgz")) {
6947
- const listResult = spawnSync6("tar", ["-tzf", tempPath], { encoding: "utf8", timeout: 6e4 });
7159
+ const listResult = spawnSync7("tar", ["-tzf", tempPath], { encoding: "utf8", timeout: 6e4 });
6948
7160
  if (listResult.error) throw listResult.error;
6949
7161
  if (listResult.status !== 0) throw new Error(`tar \u5217\u8868\u9000\u51FA\u7801 ${listResult.status}`);
6950
7162
  for (const entry of (listResult.stdout || "").split("\n").filter(Boolean)) {
@@ -6952,7 +7164,7 @@ async function downloadKernel(progressCallback, mirror, releaseInfo) {
6952
7164
  throw new Error(`\u5F52\u6863\u542B\u975E\u6CD5\u8DEF\u5F84\u6761\u76EE: ${entry}`);
6953
7165
  }
6954
7166
  }
6955
- const typeResult = spawnSync6("tar", ["-tvzf", tempPath], { encoding: "utf8", timeout: 6e4 });
7167
+ const typeResult = spawnSync7("tar", ["-tvzf", tempPath], { encoding: "utf8", timeout: 6e4 });
6956
7168
  if (typeResult.error) throw typeResult.error;
6957
7169
  if (typeResult.status !== 0) throw new Error(`tar \u5217\u8868\u9000\u51FA\u7801 ${typeResult.status}`);
6958
7170
  for (const line of (typeResult.stdout || "").split("\n").filter(Boolean)) {
@@ -6961,24 +7173,24 @@ async function downloadKernel(progressCallback, mirror, releaseInfo) {
6961
7173
  throw new Error(`\u5F52\u6863\u542B\u975E\u666E\u901A\u6587\u4EF6\u6761\u76EE\uFF08\u7C7B\u578B "${typeChar}"\uFF09: ${line}`);
6962
7174
  }
6963
7175
  }
6964
- const tarResult = spawnSync6("tar", ["--no-same-owner", "-xzf", tempPath, "-C", extractPath], {
7176
+ const tarResult = spawnSync7("tar", ["--no-same-owner", "-xzf", tempPath, "-C", extractPath], {
6965
7177
  stdio: ["ignore", "ignore", "inherit"],
6966
7178
  timeout: 6e4
6967
7179
  });
6968
7180
  if (tarResult.error) throw tarResult.error;
6969
7181
  if (tarResult.status !== 0) throw new Error(`tar \u9000\u51FA\u7801 ${tarResult.status}`);
6970
7182
  } else if (tempPath.endsWith(".gz")) {
6971
- const baseName = path8.basename(tempPath, ".gz");
6972
- const outputPath = path8.join(extractPath, baseName);
6973
- const gzipResult = spawnSync6("gzip", ["-dc", tempPath], { maxBuffer: 256 * 1024 * 1024, timeout: 6e4 });
7183
+ const baseName = path9.basename(tempPath, ".gz");
7184
+ const outputPath = path9.join(extractPath, baseName);
7185
+ const gzipResult = spawnSync7("gzip", ["-dc", tempPath], { maxBuffer: 256 * 1024 * 1024, timeout: 6e4 });
6974
7186
  if (gzipResult.error) throw gzipResult.error;
6975
7187
  if (gzipResult.status !== 0) throw new Error(`gzip \u9000\u51FA\u7801 ${gzipResult.status}`);
6976
- fs11.writeFileSync(outputPath, gzipResult.stdout, { mode: 493 });
7188
+ fs12.writeFileSync(outputPath, gzipResult.stdout, { mode: 493 });
6977
7189
  extractedBinary = outputPath;
6978
7190
  }
6979
7191
  } catch (e) {
6980
7192
  try {
6981
- fs11.unlinkSync(tempPath);
7193
+ fs12.unlinkSync(tempPath);
6982
7194
  } catch {
6983
7195
  }
6984
7196
  throw new Error(`\u89E3\u538B\u5931\u8D25: ${e.message}`);
@@ -6986,35 +7198,35 @@ async function downloadKernel(progressCallback, mirror, releaseInfo) {
6986
7198
  const foundBinary = extractedBinary || findBinaryInDir(extractPath);
6987
7199
  if (!foundBinary) {
6988
7200
  try {
6989
- fs11.unlinkSync(tempPath);
7201
+ fs12.unlinkSync(tempPath);
6990
7202
  } catch {
6991
7203
  }
6992
7204
  throw new Error("\u89E3\u538B\u540E\u672A\u627E\u5230\u53EF\u6267\u884C\u6587\u4EF6");
6993
7205
  }
6994
7206
  const targetPath = PATHS.mihomoBinary;
6995
7207
  if (foundBinary !== targetPath) {
6996
- if (fs11.existsSync(targetPath)) {
6997
- fs11.chmodSync(targetPath, 493);
7208
+ if (fs12.existsSync(targetPath)) {
7209
+ fs12.chmodSync(targetPath, 493);
6998
7210
  try {
6999
- fs11.unlinkSync(targetPath);
7211
+ fs12.unlinkSync(targetPath);
7000
7212
  } catch {
7001
7213
  }
7002
7214
  }
7003
- fs11.renameSync(foundBinary, targetPath);
7215
+ fs12.renameSync(foundBinary, targetPath);
7004
7216
  }
7005
- fs11.chmodSync(targetPath, 493);
7217
+ fs12.chmodSync(targetPath, 493);
7006
7218
  if (progressCallback) {
7007
7219
  progressCallback("\u6821\u9A8C\u5185\u6838...");
7008
7220
  }
7009
- const check = spawnSync6(targetPath, ["-v"], { encoding: "utf8", timeout: 5e3 });
7221
+ const check = spawnSync7(targetPath, ["-v"], { encoding: "utf8", timeout: 5e3 });
7010
7222
  const checkOutput = `${check.stdout || ""}${check.stderr || ""}`.trim();
7011
7223
  if (check.error || check.status !== 0 || !/v?\d+\.\d+\.\d+/.test(checkOutput)) {
7012
7224
  try {
7013
- fs11.unlinkSync(targetPath);
7225
+ fs12.unlinkSync(targetPath);
7014
7226
  } catch {
7015
7227
  }
7016
7228
  try {
7017
- fs11.unlinkSync(tempPath);
7229
+ fs12.unlinkSync(tempPath);
7018
7230
  } catch {
7019
7231
  }
7020
7232
  throw new Error(`\u5185\u6838\u81EA\u68C0\u5931\u8D25\uFF08\u53EF\u80FD\u4E0B\u8F7D\u635F\u574F\u6216\u67B6\u6784\u4E0D\u5339\u914D\uFF09\uFF0C\u5DF2\u5220\u9664
@@ -7022,7 +7234,7 @@ async function downloadKernel(progressCallback, mirror, releaseInfo) {
7022
7234
  \u8F93\u51FA: ${checkOutput || "(\u7A7A)"}`);
7023
7235
  }
7024
7236
  try {
7025
- fs11.unlinkSync(tempPath);
7237
+ fs12.unlinkSync(tempPath);
7026
7238
  } catch {
7027
7239
  }
7028
7240
  clearKernelVersionCache();
@@ -7177,30 +7389,30 @@ function removedCommand(name, version, hint) {
7177
7389
  }
7178
7390
 
7179
7391
  // src/commands/reset.ts
7180
- import fs13 from "fs";
7392
+ import fs14 from "fs";
7181
7393
 
7182
7394
  // src/process-stop.ts
7183
- import { spawnSync as spawnSync7 } from "child_process";
7184
- import fs12 from "fs";
7395
+ import { spawnSync as spawnSync8 } from "child_process";
7396
+ import fs13 from "fs";
7185
7397
  var PROCESS_WAIT_ATTEMPTS = 50;
7186
7398
  var PROCESS_WAIT_INTERVAL = 100;
7187
7399
  var BATCH_KILL_THRESHOLD = 3;
7188
7400
  function clearRuntime() {
7189
- if (fs12.existsSync(DIRS.runtime)) {
7401
+ if (fs13.existsSync(DIRS.runtime)) {
7190
7402
  rmrf(DIRS.runtime);
7191
7403
  }
7192
7404
  ensureDirs();
7193
7405
  }
7194
7406
  function clearPid() {
7195
- if (!fs12.existsSync(PATHS.pidFile)) return;
7407
+ if (!fs13.existsSync(PATHS.pidFile)) return;
7196
7408
  if (isPidFileOwnedByRoot()) {
7197
7409
  try {
7198
- spawnSync7("sudo", ["rm", "-f", PATHS.pidFile], { stdio: "inherit", timeout: 1e4 });
7410
+ spawnSync8("sudo", ["rm", "-f", PATHS.pidFile], { stdio: "inherit", timeout: 1e4 });
7199
7411
  } catch {
7200
7412
  }
7201
7413
  } else {
7202
7414
  try {
7203
- fs12.unlinkSync(PATHS.pidFile);
7415
+ fs13.unlinkSync(PATHS.pidFile);
7204
7416
  } catch {
7205
7417
  }
7206
7418
  }
@@ -7218,7 +7430,7 @@ function killAllMihomo(forceSudo = false) {
7218
7430
  const argv = forceSudo ? ["sudo", ["pkill", "-9", "-f", pattern]] : ["pkill", ["-9", "-f", pattern]];
7219
7431
  const options = forceSudo ? { stdio: "inherit", timeout: 15e3 } : { timeout: 1e4 };
7220
7432
  try {
7221
- const result = spawnSync7(argv[0], argv[1], options);
7433
+ const result = spawnSync8(argv[0], argv[1], options);
7222
7434
  if (result.error) return false;
7223
7435
  return result.status === 0 || result.status === 1;
7224
7436
  } catch {
@@ -7347,8 +7559,8 @@ var RESET_TARGETS = [
7347
7559
  label: "\u8986\u5199",
7348
7560
  paths: () => {
7349
7561
  const dir = USER_DATA_DIR;
7350
- if (!fs13.existsSync(dir)) return [];
7351
- return fs13.readdirSync(dir).filter(isOverwriteFilename).map((f) => `${dir}/${f}`);
7562
+ if (!fs14.existsSync(dir)) return [];
7563
+ return fs14.readdirSync(dir).filter(isOverwriteFilename).map((f) => `${dir}/${f}`);
7352
7564
  },
7353
7565
  needsStop: false
7354
7566
  },
@@ -7489,7 +7701,7 @@ async function cmdReset(args) {
7489
7701
  }
7490
7702
  for (const t of targets) {
7491
7703
  for (const p of t.paths()) {
7492
- if (fs13.existsSync(p)) {
7704
+ if (fs14.existsSync(p)) {
7493
7705
  try {
7494
7706
  rmrf(p);
7495
7707
  } catch (e) {
@@ -7507,7 +7719,7 @@ async function cmdReset(args) {
7507
7719
  }
7508
7720
 
7509
7721
  // src/commands/service.ts
7510
- import fs14 from "fs";
7722
+ import fs15 from "fs";
7511
7723
  async function handleLegacyInstall() {
7512
7724
  if (!detectLegacySystemInstall()) return;
7513
7725
  console.log(colors.yellow("\u68C0\u6D4B\u5230\u65E7\u7248\u672C\u5B89\u88C5\u7684\u7CFB\u7EDF\u7EA7\u670D\u52A1\uFF08root LaunchDaemon\uFF09"));
@@ -7542,7 +7754,7 @@ async function cmdInstall(_args) {
7542
7754
  console.log(colors.green("\u5DF2\u6309\u539F\u72B6\u6001\u91CD\u65B0\u542F\u52A8"));
7543
7755
  } else {
7544
7756
  console.log("\u542F\u52A8: mihomo start");
7545
- if (!fs14.existsSync(PATHS.configFile)) {
7757
+ if (!fs15.existsSync(PATHS.configFile)) {
7546
7758
  console.log(colors.gray(" \u5C1A\u65E0\u8FD0\u884C\u65F6\u914D\u7F6E\uFF0Cstart \u4F1A\u5148\u8981\u6C42\u6DFB\u52A0\u8BA2\u9605"));
7547
7759
  }
7548
7760
  }
@@ -7576,6 +7788,9 @@ async function cmdUninstall(_args) {
7576
7788
  console.log("\u624B\u52A8\u6E05\u7406: sudo pkill -9 mihomo");
7577
7789
  }
7578
7790
  console.log(colors.gray("\u91CD\u65B0\u5B89\u88C5: mihomo install"));
7791
+ console.log(colors.gray("\u5F7B\u5E95\u79FB\u9664 mihomo-cli:"));
7792
+ console.log(colors.gray(" mihomo reset --full # \u5220\u9664\u5168\u90E8\u6570\u636E\uFF08\u8BA2\u9605/\u5185\u6838/\u65E5\u5FD7\u7B49\uFF09"));
7793
+ console.log(colors.gray(" npm uninstall -g mihomo-cli"));
7579
7794
  console.log("");
7580
7795
  }
7581
7796
 
@@ -7619,10 +7834,10 @@ async function cmdStop(args) {
7619
7834
  }
7620
7835
 
7621
7836
  // src/commands/ui.ts
7622
- import { spawnSync as spawnSync8 } from "child_process";
7837
+ import { spawnSync as spawnSync9 } from "child_process";
7623
7838
  function copyToClipboard(text) {
7624
7839
  try {
7625
- return spawnSync8("pbcopy", [], { input: text }).status === 0;
7840
+ return spawnSync9("pbcopy", [], { input: text }).status === 0;
7626
7841
  } catch {
7627
7842
  return false;
7628
7843
  }
@@ -7642,7 +7857,7 @@ function cmdUI(args) {
7642
7857
  const secret = readSettings().controller_secret;
7643
7858
  if (secret) {
7644
7859
  console.log(
7645
- copyToClipboard(secret) ? "\u5DF2\u914D\u7F6E\u8BBF\u95EE\u5BC6\u94A5\uFF08\u5DF2\u590D\u5236\u5230\u526A\u8D34\u677F\uFF0CUI \u8FDE\u63A5\u65F6\u7C98\u8D34\uFF09" : "\u5DF2\u914D\u7F6E\u8BBF\u95EE\u5BC6\u94A5\uFF08UI \u8FDE\u63A5 127.0.0.1:9090 \u65F6\u9700\u8F93\u5165\uFF0C\u5BC6\u94A5\u89C1 settings.json\uFF09"
7860
+ copyToClipboard(secret) ? "\u5DF2\u914D\u7F6E\u8BBF\u95EE\u5BC6\u94A5\uFF08\u5DF2\u590D\u5236\u5230\u526A\u8D34\u677F\uFF0CUI \u8FDE\u63A5\u65F6\u7C98\u8D34\uFF09" : `\u5DF2\u914D\u7F6E\u8BBF\u95EE\u5BC6\u94A5\uFF08UI \u8FDE\u63A5 127.0.0.1:${getPorts().controller} \u65F6\u9700\u8F93\u5165\uFF0C\u5BC6\u94A5\u89C1 settings.json\uFF09`
7646
7861
  );
7647
7862
  }
7648
7863
  const success = openUrl(url);
@@ -7651,66 +7866,6 @@ function cmdUI(args) {
7651
7866
  }
7652
7867
  }
7653
7868
 
7654
- // src/commands/update.ts
7655
- import { execFile as execFile2, spawn as spawn2 } from "child_process";
7656
- import { promisify as promisify2 } from "util";
7657
- var execFileAsync2 = promisify2(execFile2);
7658
- var NPM_VIEW_TIMEOUT_MS = 15e3;
7659
- async function getLatestNpmVersion() {
7660
- try {
7661
- const { stdout } = await execFileAsync2("npm", ["view", PKG_NAME, "version"], { timeout: NPM_VIEW_TIMEOUT_MS });
7662
- const version = stdout.trim().split("\n").pop()?.trim();
7663
- return version || null;
7664
- } catch {
7665
- return null;
7666
- }
7667
- }
7668
- async function cmdUpdate() {
7669
- console.log(`\u5F53\u524D\u7248\u672C: ${colors.cyan(VERSION)}`);
7670
- console.log("");
7671
- const latest = await withSpinner("\u67E5\u8BE2 npm \u6700\u65B0\u7248\u672C", getLatestNpmVersion);
7672
- if (latest && latest === VERSION) {
7673
- console.log(`\u5DF2\u662F\u6700\u65B0\u7248\u672C (${colors.green(VERSION)})\uFF0C\u65E0\u9700\u66F4\u65B0`);
7674
- return;
7675
- }
7676
- if (latest) {
7677
- console.log(`\u6700\u65B0\u7248\u672C: ${colors.cyan(latest)}`);
7678
- } else {
7679
- console.log(colors.yellow("\u65E0\u6CD5\u67E5\u8BE2\u6700\u65B0\u7248\u672C\uFF08\u7F51\u7EDC\u95EE\u9898\uFF1F\uFF09\uFF0C\u5C06\u76F4\u63A5\u5C1D\u8BD5\u91CD\u65B0\u5B89\u88C5"));
7680
- }
7681
- console.log("");
7682
- console.log("\u6B63\u5728\u66F4\u65B0 mihomo-cli...");
7683
- console.log("");
7684
- await new Promise((resolve, reject) => {
7685
- const npm = spawn2("npm", ["install", "-g", PKG_NAME], { stdio: "inherit" });
7686
- npm.on("close", (code) => {
7687
- if (code === 0) {
7688
- resolve();
7689
- } else {
7690
- reject(new CliError("\u66F4\u65B0\u5931\u8D25\u3002\u82E5\u4E3A\u6743\u9650\u95EE\u9898\uFF08EACCES\uFF09\uFF0C\u8BF7\u68C0\u67E5 npm \u5168\u5C40\u76EE\u5F55\u6743\u9650\u6216\u4F7F\u7528 nvm \u7BA1\u7406 Node", { exitCode: code || 1 }));
7691
- }
7692
- });
7693
- npm.on("error", (e) => {
7694
- const perm = e.message.includes("EACCES") || e.message.includes("permission");
7695
- reject(perm ? new CliError("\u6743\u9650\u4E0D\u8DB3\uFF08EACCES\uFF09\uFF0C\u8BF7\u68C0\u67E5 npm \u5168\u5C40\u76EE\u5F55\u6743\u9650\u6216\u4F7F\u7528 nvm \u7BA1\u7406 Node") : new CliError(`\u6267\u884C\u5931\u8D25: ${e.message}`));
7696
- });
7697
- });
7698
- try {
7699
- const { stdout } = await execFileAsync2("npm", ["list", "-g", PKG_NAME, "--json", "--depth=0"]);
7700
- const result = JSON.parse(stdout);
7701
- const newVersion = result.dependencies?.[PKG_NAME]?.version;
7702
- console.log("");
7703
- if (newVersion) {
7704
- console.log(`\u66F4\u65B0\u5B8C\u6210\uFF0C\u6700\u65B0\u7248\u672C: ${colors.green(newVersion)}`);
7705
- } else {
7706
- console.log("\u66F4\u65B0\u5B8C\u6210");
7707
- }
7708
- } catch {
7709
- console.log("");
7710
- console.log("\u66F4\u65B0\u5B8C\u6210");
7711
- }
7712
- }
7713
-
7714
7869
  // src/commands/registry.ts
7715
7870
  var COMMANDS = [
7716
7871
  // === 控制 ===
@@ -7885,14 +8040,17 @@ var COMMANDS = [
7885
8040
  aliases: [],
7886
8041
  handler: cmdDoctor,
7887
8042
  group: "system",
7888
- usage: [{ signature: "doctor", description: "\u4F53\u68C0\u8BCA\u65AD\uFF08\u5185\u6838/\u670D\u52A1/\u7AEF\u53E3/\u8BA2\u9605/\u914D\u7F6E/\u8FDE\u901A\u6027\uFF0C\u6709\u5F02\u5E38\u9000\u51FA\u7801 1\uFF09" }]
8043
+ usage: [{ signature: "doctor", description: "\u4F53\u68C0\u8BCA\u65AD\uFF08\u5185\u6838/\u670D\u52A1/\u7AEF\u53E3/\u8BA2\u9605/\u914D\u7F6E/\u8FDE\u901A\u6027/CLI \u7248\u672C\uFF0C\u6709\u5F02\u5E38\u9000\u51FA\u7801 1\uFF09" }]
7889
8044
  },
7890
8045
  {
7891
8046
  name: "completion",
7892
8047
  aliases: [],
7893
8048
  handler: (args) => cmdCompletion(args, COMMANDS),
7894
8049
  group: "system",
7895
- usage: [{ signature: "completion <zsh|bash|fish>", description: "\u8F93\u51FA shell \u8865\u5168\u811A\u672C\uFF08eval \u6216\u5199\u5165\u8865\u5168\u76EE\u5F55\uFF09" }]
8050
+ usage: [
8051
+ { signature: "completion install <zsh|bash|fish>", description: "\u5B89\u88C5\u8865\u5168\u5230\u5BF9\u5E94 shell \u7684\u9ED8\u8BA4\u4F4D\u7F6E" },
8052
+ { signature: "completion <zsh|bash|fish>", description: "\u8F93\u51FA\u8865\u5168\u811A\u672C\uFF08\u91CD\u5B9A\u5411\u6216 eval \u4F7F\u7528\uFF09" }
8053
+ ]
7896
8054
  },
7897
8055
  // === meta(不在分组清单展示,help 末尾单列) ===
7898
8056
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mihomo-cli",
3
- "version": "4.4.0",
3
+ "version": "4.5.0",
4
4
  "type": "module",
5
5
  "description": "A terminal-based mihomo (Clash.Meta) client for macOS",
6
6
  "bin": {