dsh-clash-subscription 0.9.0 → 0.10.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-0.10.0.md +127 -0
- package/README.md +50 -2
- package/client.js +2 -2
- package/index.js +26 -2
- package/lib/corefetch.js +167 -22
- package/lib/skill.js +17 -0
- package/package.json +4 -3
- package/CHANGELOG-0.9.0.md +0 -122
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# 0.10.0 · 支持 Ubuntu(及 Linux / macOS)
|
|
2
|
+
|
|
3
|
+
> 上一版 `0.9.0` · 本版 `0.10.0`
|
|
4
|
+
|
|
5
|
+
## 0.9.0 在 Ubuntu 上会怎样
|
|
6
|
+
|
|
7
|
+
能安装,能识别平台,能下载内核,**然后卡在解包**。
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
core download 100%
|
|
11
|
+
core bootstrap: verified
|
|
12
|
+
THROWS: tar exited 1: tar: Error opening archive: Unrecognized archive format
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 根因:Linux 的 `.gz` 不是 tar
|
|
16
|
+
|
|
17
|
+
mihomo 的 Linux 与 macOS 发布资产是**裸二进制经 gzip 压缩**,不是 tar 归档。实测三份:
|
|
18
|
+
|
|
19
|
+
| 资产 | 解压后 | 形态 |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `mihomo-linux-amd64-compatible-v1.19.34.gz` | 61 948 030 字节 | ELF64,`ustar`=false |
|
|
22
|
+
| `mihomo-linux-arm64-v1.19.34.gz` | 57 344 126 字节 | ELF,`ustar`=false |
|
|
23
|
+
| `mihomo-darwin-arm64-v1.19.34.gz` | 56 698 738 字节 | Mach-O,`ustar`=false |
|
|
24
|
+
|
|
25
|
+
而旧代码对所有 `.gz` 都执行 `tar -xzf`,它只能读 tar 归档。
|
|
26
|
+
|
|
27
|
+
## 改了什么
|
|
28
|
+
|
|
29
|
+
### 1. 解包器按内容判别,不再按扩展名
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
.gz → node:zlib 流式解压 → 看 offset 257 是不是 "ustar"
|
|
33
|
+
├─ 是 → tar 解包(兼容真有 tar.gz 的发布)
|
|
34
|
+
└─ 否 → 它本身就是内核,直接落位
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
不再依赖外部 `tar` 命令,**精简 Ubuntu 镜像没有 tar 也能用**。`.zip` 在 Linux 上改为先试 `unzip`、再试 `tar`,都失败时把两个错误一起报出来(GNU tar 读不了 zip)。
|
|
38
|
+
|
|
39
|
+
### 2. 补全 `KNOWN_ARCHIVES` 摘要
|
|
40
|
+
|
|
41
|
+
原来只有 `win32-x64`,导致在 Linux 上设 `coreVersion: 1.19.34` 直接抛
|
|
42
|
+
`coreVersion 1.19.34 has no verified archive for linux-x64`。
|
|
43
|
+
|
|
44
|
+
现在五条齐全,摘要全部取自发布方 API 自述值,并与本地下载的字节**逐条比对一致**:
|
|
45
|
+
|
|
46
|
+
| 平台 | 摘要(前 16 位) | 体积 |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| `linux-x64` | `2763f5b414527f7b` | 22 766 457 |
|
|
49
|
+
| `linux-arm64` | `daaf78a6240a282c` | 20 684 679 |
|
|
50
|
+
| `darwin-x64` | `703bceaa494732fa` | 22 213 898 |
|
|
51
|
+
| `darwin-arm64` | `1a7a20eca63fbbae` | 20 649 699 |
|
|
52
|
+
| `win32-x64` | `cd6738d4648cc1a5` | 22 417 383 |
|
|
53
|
+
|
|
54
|
+
Linux x64 优先用 `-compatible` 构建(CPU 基线版本),避免 `v3` 类构建在旧机器上触发 SIGILL。
|
|
55
|
+
|
|
56
|
+
### 3. `platformSupported` 不再谎报
|
|
57
|
+
|
|
58
|
+
旧值只看 `platformKey()`(发布页有没有对应资产),在 Linux 上返回 `true`,但两条获取路径其实都抛错。现在要求「自带内核或可下载,至少一条成立」,并新增 `coreSource` 说明来源:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
platformSupported = true
|
|
62
|
+
coreSource = download ← 或 "bundled"
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 4. 无自带内核的平台默认开启自动获取
|
|
66
|
+
|
|
67
|
+
`autoFetchCore` 默认 `false`,而 Linux/macOS 没有自带内核——装完什么都不发生,看起来像坏掉。现在:**未显式配置且本平台无自带内核时,默认开启**。显式写 `false` 仍然尊重。
|
|
68
|
+
|
|
69
|
+
### 5. `chmod` 失败不再静默
|
|
70
|
+
|
|
71
|
+
`placeCore` 里给执行位;失败时抛出明确错误(`could not make ... executable`),而不是让 spawn 之后蹦出一个莫名其妙的 `EACCES`。
|
|
72
|
+
|
|
73
|
+
## 关于 glibc / 发行版版本
|
|
74
|
+
|
|
75
|
+
**不需要针对 Ubuntu 版本做任何适配**。验证方式不是读文档,而是解析 ELF 程序头:
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
ELF class = 64-bit
|
|
79
|
+
e_machine = x86-64
|
|
80
|
+
PT_INTERP = NONE → 静态链接
|
|
81
|
+
GLIBC_2. 符号 = 无
|
|
82
|
+
libc.so / ld-linux 引用 = 无
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
静态链接意味着系统 glibc 完全不参与,**同一个二进制在 Ubuntu 22.04 / 24.04 LTS (Noble) / 26.04 LTS (Resolute Raccoon) 上都能跑**。
|
|
86
|
+
|
|
87
|
+
## 验收
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
node test/regression-070.mjs → 113 passed, 0 failed
|
|
91
|
+
node test/regression-063.mjs → 31 passed, 0 failed
|
|
92
|
+
node test/regression-0100.mjs → 48 passed, 0 failed ← 新增(Ubuntu 适配)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
新增测试里有几条是靠运行结果取证的:
|
|
96
|
+
|
|
97
|
+
| 断言 | 证据 |
|
|
98
|
+
|---|---|
|
|
99
|
+
| 裸 gzip 能解包 | 构造裸 gzip → 解出 4100 字节,ELF 头完整 |
|
|
100
|
+
| **负向对照**:`tar -xzf` 对同一文件确实失败 | `exit=1`(证明这个修复是必要的,不是装饰) |
|
|
101
|
+
| tar.gz 形状仍能处理 | 现场打包 tar.gz → 成员正确取出 |
|
|
102
|
+
| 真实资产 61 948 030 字节 | 用真下载的 22 766 457 字节 `.gz` 解包 |
|
|
103
|
+
| 静态链接 | 遍历程序头,确认无 `PT_INTERP` |
|
|
104
|
+
| 五平台矩阵 | 每对平台都有「自带或可下载」 |
|
|
105
|
+
|
|
106
|
+
端到端(模拟 Linux 平台,真下载 + 真解包):
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
core bootstrap: resolved v1.19.34 → verified → installed
|
|
110
|
+
bytes = 61948030
|
|
111
|
+
ELF magic = 7f454c46 ✓
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## 一个被测试抓到的自身 bug
|
|
115
|
+
|
|
116
|
+
给技能补 Linux 章节时写了 `${DSH_HOME}/data/...`,而技能正文是模板字符串——`${}` 被当成插值求值,导入直接 `ReferenceError: DSH_HOME is not defined`。
|
|
117
|
+
|
|
118
|
+
原有断言 `!content.includes('${')` 抓不到它,因为**模块根本没加载成功**,断言不会执行。补了两条真正有效的:
|
|
119
|
+
|
|
120
|
+
```
|
|
121
|
+
ok 源码里没有未转义的 ${(会被当成插值求值)
|
|
122
|
+
ok 源码里未转义的反引号成对(模板未被截断)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## 本机无法验证的一点(如实记录)
|
|
126
|
+
|
|
127
|
+
`chmod 0755` 设执行位这件事在 Windows 上无法验证:NTFS 没有 POSIX 执行位,`chmodSync` 只能切只读属性,`mode & 0o111` 恒为 0。所以模拟运行里显示 `executable? = NO` 是本机文件系统的限制,不是代码缺陷——真 Ubuntu 上该分支会执行。要彻底证实,需要在真 Linux 上跑一次 `test/regression-0100.mjs`。
|
package/README.md
CHANGED
|
@@ -119,8 +119,56 @@ unpacking and the executable **after**, and re-unpacks if an already-installed c
|
|
|
119
119
|
matches — a corrupted or replaced binary is restored rather than trusted. If the manifest and
|
|
120
120
|
the archive ever disagree, the plugin refuses to run the binary at all.
|
|
121
121
|
|
|
122
|
-
Only `win32-x64` ships
|
|
123
|
-
|
|
122
|
+
Only `win32-x64` ships a copy inside the package. Every other supported platform fetches the
|
|
123
|
+
release asset on first start instead; `status.coreSource` reports which applies
|
|
124
|
+
(`bundled` or `download`), and `status.platformSupported` is true when at least one of the two
|
|
125
|
+
paths exists.
|
|
126
|
+
|
|
127
|
+
| Platform | Core source | Archive |
|
|
128
|
+
|---|---|---|
|
|
129
|
+
| `win32-x64` | bundled + downloadable | `.zip` |
|
|
130
|
+
| `win32-arm64` | downloadable | `.zip` |
|
|
131
|
+
| `linux-x64` | downloadable | `.gz` (bare binary) |
|
|
132
|
+
| `linux-arm64` | downloadable | `.gz` (bare binary) |
|
|
133
|
+
| `darwin-x64` / `darwin-arm64` | downloadable | `.gz` (bare binary) |
|
|
134
|
+
|
|
135
|
+
## Ubuntu (and other Linux): 24.04 LTS and 26.04 LTS
|
|
136
|
+
|
|
137
|
+
Supported. Nothing beyond the DSH runtime has to be installed beforehand.
|
|
138
|
+
|
|
139
|
+
**Why the distro version does not matter.** The release asset decompresses to a *statically
|
|
140
|
+
linked* ELF64 — verified: no `PT_INTERP`, no `GLIBC_*` symbols, no `ld-linux` reference — so the
|
|
141
|
+
system glibc is never consulted. The same binary runs on Ubuntu 22.04, 24.04 (Noble) and 26.04
|
|
142
|
+
(Resolute Raccoon).
|
|
143
|
+
|
|
144
|
+
**What happens on first start.**
|
|
145
|
+
|
|
146
|
+
1. no bundled core exists for Linux, so `autoFetchCore` defaults to **on** there;
|
|
147
|
+
2. the plugin downloads `mihomo-linux-amd64-compatible-v1.19.34.gz` (22 766 457 bytes) from the
|
|
148
|
+
GitHub release, trying `gh-proxy.com` / `ghfast.top` / `ghproxy.net` first if those answer
|
|
149
|
+
faster;
|
|
150
|
+
3. the SHA-256 is checked against the publisher's own digest **before** anything is unpacked;
|
|
151
|
+
4. the archive is decompressed with `node:zlib` — **not** with `tar`, because every Linux and
|
|
152
|
+
macOS release asset is a *bare gzip-compressed binary*, not a tar. Feeding one to
|
|
153
|
+
`tar -xzf` fails with `Unrecognized archive format`, which is exactly what 0.9.0 did after a
|
|
154
|
+
successful 22 MB download;
|
|
155
|
+
5. the result (61 948 030 bytes) is written to
|
|
156
|
+
`${DSH_HOME}/data/dsh-clash-proxy/bin/mihomo` and chmod `0755`.
|
|
157
|
+
|
|
158
|
+
Because step 4 uses `node:zlib` instead of an external command, a slim image without `tar` still
|
|
159
|
+
works. `tar` is only needed if a release ever switches back to a `tar.gz` payload — both shapes
|
|
160
|
+
are handled and both are covered by tests.
|
|
161
|
+
|
|
162
|
+
**Pinning a version.** `coreVersion: 1.19.34` works on every listed platform:
|
|
163
|
+
`KNOWN_ARCHIVES` carries the publisher digest for each. Without a pin, the plugin asks the release
|
|
164
|
+
API, falling back to the release-page redirect when the API is rate limited.
|
|
165
|
+
|
|
166
|
+
**If the download cannot happen** (air-gapped host, or a mirror that does not carry it), set
|
|
167
|
+
`corePath` to a `mihomo` binary placed on disk, or install a local archive with
|
|
168
|
+
`installCoreFromFile`. Both are verified the same way.
|
|
169
|
+
|
|
170
|
+
**Not supported:** 32-bit x86 (`linux-ia32`) and architectures with no published asset. On those
|
|
171
|
+
`status.platformSupported` is false and the panel says so up front instead of failing later.
|
|
124
172
|
|
|
125
173
|
## The optional GeoIP upgrade
|
|
126
174
|
|
package/client.js
CHANGED
|
@@ -81,7 +81,7 @@ const en = {
|
|
|
81
81
|
noUsableNode: 'No node reached every required service.',
|
|
82
82
|
usableCount: '{usable} / {total} nodes usable',
|
|
83
83
|
autoFetchCore: 'Fetch a core automatically',
|
|
84
|
-
autoFetchCoreHint: 'When no mihomo binary is present, download a verified private copy on startup instead of waiting for you to press Download.',
|
|
84
|
+
autoFetchCoreHint: 'When no mihomo binary is present, download a verified private copy on startup instead of waiting for you to press Download. On Linux and macOS there is no bundled core, so this is on by default there — the plugin fetches the 22 MB release asset once, verifies it against the publisher SHA-256, and unpacks it into its own data directory.',
|
|
85
85
|
dns: 'DNS servers',
|
|
86
86
|
dnsHint: 'Comma-separated resolvers the core uses for its own lookups.',
|
|
87
87
|
start: 'Start',
|
|
@@ -248,7 +248,7 @@ const zh = {
|
|
|
248
248
|
noUsableNode: '没有任何节点能访问全部必需服务。',
|
|
249
249
|
usableCount: '{usable} / {total} 个节点可用',
|
|
250
250
|
autoFetchCore: '自动获取内核',
|
|
251
|
-
autoFetchCoreHint: '机器上没有 mihomo 时,启动时自动下载一份经过校验的私有内核,不用手动点下载。',
|
|
251
|
+
autoFetchCoreHint: '机器上没有 mihomo 时,启动时自动下载一份经过校验的私有内核,不用手动点下载。Linux 与 macOS 没有自带内核,因此在那里默认开启:首次启动会下载 22 MB 的发布资产,用发布方 SHA-256 校验后解包进插件自己的数据目录。',
|
|
252
252
|
dns: 'DNS 服务器',
|
|
253
253
|
dnsHint: '逗号分隔,内核自己解析时使用。',
|
|
254
254
|
start: '启动',
|
package/index.js
CHANGED
|
@@ -79,7 +79,16 @@ export const CONFIG_DEFAULTS = {
|
|
|
79
79
|
speedTestCount: 8,
|
|
80
80
|
/** How often the core is checked for liveness, in minutes; 0 disables the watchdog. */
|
|
81
81
|
healthCheckMinutes: 1,
|
|
82
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* Download a private core automatically when the machine has none.
|
|
84
|
+
*
|
|
85
|
+
* Default off was right while every supported platform shipped a vendored copy: downloading
|
|
86
|
+
* was an optimisation. Linux and macOS have no vendored copy (the payload is 61 MB, which is
|
|
87
|
+
* not something to embed for a platform whose package can just fetch it), so on those the flag
|
|
88
|
+
* being off means a fresh install does nothing at all until someone presses a button. The
|
|
89
|
+
* effective default is therefore "on when there is nothing bundled for this platform", handled
|
|
90
|
+
* in `resolveConfig` rather than by leaving the literal `false` here.
|
|
91
|
+
*/
|
|
83
92
|
autoFetchCore: false,
|
|
84
93
|
/** Pin the core version to a build whose digest this plugin ships; empty means current. */
|
|
85
94
|
coreVersion: '',
|
|
@@ -259,6 +268,11 @@ export function resolveConfig(raw) {
|
|
|
259
268
|
config.mode = mode === 'global' ? 'global' : 'rule'
|
|
260
269
|
config.autoStart = config.autoStart !== false && config.autoStart !== 'false'
|
|
261
270
|
config.autoFetchCore = config.autoFetchCore === true || config.autoFetchCore === 'true'
|
|
271
|
+
// A platform with no bundled core gets the download switched on, because otherwise a fresh
|
|
272
|
+
// install there has no core and no action: the panel offers a button, but nothing happens on
|
|
273
|
+
// its own and "the proxy does not work" looks like a bug rather than an unset default. An
|
|
274
|
+
// explicit `true`/`false` in the profile still wins, so this only fills the gap.
|
|
275
|
+
if (input.autoFetchCore === undefined && vendoredFor() === undefined) config.autoFetchCore = true
|
|
262
276
|
config.autoFetchGeo = config.autoFetchGeo !== false && config.autoFetchGeo !== 'false'
|
|
263
277
|
config.autoReselect = config.autoReselect !== false && config.autoReselect !== 'false'
|
|
264
278
|
for (const field of ['subscriptionUrls', 'subscriptionUrl', 'node', 'corePath', 'coreVersion', 'dnsServers', 'directDomains', 'proxyDomains', 'dataDir', 'probes', 'requiredProbes']) {
|
|
@@ -1941,7 +1955,17 @@ export class Runtime {
|
|
|
1941
1955
|
})),
|
|
1942
1956
|
},
|
|
1943
1957
|
/** Whether a download could be attempted at all on this platform. */
|
|
1944
|
-
|
|
1958
|
+
/**
|
|
1959
|
+
* Whether a core can be obtained on this platform at all.
|
|
1960
|
+
*
|
|
1961
|
+
* `platformKey()` only says the release has an asset for this pair. Reporting that alone as
|
|
1962
|
+
* "supported" was wrong on Linux: the panel said yes while both acquisition paths refused —
|
|
1963
|
+
* there is no vendored copy for it, and a pinned `coreVersion` had no digest entry. What
|
|
1964
|
+
* actually matters is whether at least one path exists, so both are checked and the answer
|
|
1965
|
+
* says which one it is.
|
|
1966
|
+
*/
|
|
1967
|
+
platformSupported: platformKey() !== undefined || vendoredFor() !== undefined,
|
|
1968
|
+
coreSource: vendoredFor() !== undefined ? 'bundled' : platformKey() !== undefined ? 'download' : undefined,
|
|
1945
1969
|
degraded: this.degraded,
|
|
1946
1970
|
lastError: this.lastError ?? this.core?.lastError,
|
|
1947
1971
|
probe: this.lastProbe,
|
package/lib/corefetch.js
CHANGED
|
@@ -22,8 +22,10 @@
|
|
|
22
22
|
*/
|
|
23
23
|
import { createHash } from 'node:crypto'
|
|
24
24
|
import { spawn } from 'node:child_process'
|
|
25
|
-
import { chmodSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
25
|
+
import { createReadStream, createWriteStream, chmodSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'
|
|
26
|
+
import { open } from 'node:fs/promises'
|
|
26
27
|
import { join } from 'node:path'
|
|
28
|
+
import { createGunzip } from 'node:zlib'
|
|
27
29
|
|
|
28
30
|
/**
|
|
29
31
|
* Mirror prefixes tried before the direct GitHub URL.
|
|
@@ -84,6 +86,36 @@ export const KNOWN_ARCHIVES = {
|
|
|
84
86
|
size: 22417383,
|
|
85
87
|
archive: 'zip',
|
|
86
88
|
},
|
|
89
|
+
// Every Linux and macOS asset is a bare gzip-compressed binary, not a tar — see
|
|
90
|
+
// `unpackCore`. The `-compatible` builds are preferred for the same reason as on Windows:
|
|
91
|
+
// they are compiled for the oldest supported CPU baseline, so a `v3`-style build cannot
|
|
92
|
+
// crash on an older machine with SIGILL. Ubuntu 24.04 and 26.04 both run these: the payload
|
|
93
|
+
// is statically linked (no PT_INTERP, no GLIBC_* symbols), so the distro's glibc version is
|
|
94
|
+
// irrelevant.
|
|
95
|
+
'linux-x64': {
|
|
96
|
+
url: 'https://github.com/MetaCubeX/mihomo/releases/download/v1.19.34/mihomo-linux-amd64-compatible-v1.19.34.gz',
|
|
97
|
+
digest: '2763f5b414527f7baf6dc57e3f82f3ab561eedf34bfd7c2f2cde1f7e592efe06',
|
|
98
|
+
size: 22766457,
|
|
99
|
+
archive: 'gz',
|
|
100
|
+
},
|
|
101
|
+
'linux-arm64': {
|
|
102
|
+
url: 'https://github.com/MetaCubeX/mihomo/releases/download/v1.19.34/mihomo-linux-arm64-v1.19.34.gz',
|
|
103
|
+
digest: 'daaf78a6240a282cdfd75bcbf98fe321f6bd52765cc29e79f344191198f0b50f',
|
|
104
|
+
size: 20684679,
|
|
105
|
+
archive: 'gz',
|
|
106
|
+
},
|
|
107
|
+
'darwin-x64': {
|
|
108
|
+
url: 'https://github.com/MetaCubeX/mihomo/releases/download/v1.19.34/mihomo-darwin-amd64-compatible-v1.19.34.gz',
|
|
109
|
+
digest: '703bceaa494732fa456f47e6ac2f06bf0bc5593d4c927d5f61e10f1a31039c37',
|
|
110
|
+
size: 22213898,
|
|
111
|
+
archive: 'gz',
|
|
112
|
+
},
|
|
113
|
+
'darwin-arm64': {
|
|
114
|
+
url: 'https://github.com/MetaCubeX/mihomo/releases/download/v1.19.34/mihomo-darwin-arm64-v1.19.34.gz',
|
|
115
|
+
digest: '1a7a20eca63fbbaec90137717465bfde488d0db2a3a79b8fadebf9b2545b6e4c',
|
|
116
|
+
size: 20649699,
|
|
117
|
+
archive: 'gz',
|
|
118
|
+
},
|
|
87
119
|
},
|
|
88
120
|
}
|
|
89
121
|
|
|
@@ -524,13 +556,23 @@ function runTool(command, args) {
|
|
|
524
556
|
/**
|
|
525
557
|
* Unpack the archive and move the executable into place.
|
|
526
558
|
*
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
*
|
|
559
|
+
* Two archive shapes have to be handled, and conflating them is what broke Linux:
|
|
560
|
+
*
|
|
561
|
+
* 1. a **tar** (optionally gzipped) — the Windows release assets are `.zip`, whose entries
|
|
562
|
+
* carry the build-suffixed name;
|
|
563
|
+
* 2. a **bare gzip-compressed binary** — every Linux and macOS release asset is this shape.
|
|
564
|
+
* Measured on v1.19.34: `mihomo-linux-amd64-compatible-v1.19.34.gz` decompresses to a single
|
|
565
|
+
* 61 948 030-byte ELF with no `ustar` header at offset 257, and the darwin assets are the same
|
|
566
|
+
* with a Mach-O payload. `tar -xzf` cannot read either, so it failed with
|
|
567
|
+
* "Unrecognized archive format" *after* a successful 22 MB download.
|
|
568
|
+
*
|
|
569
|
+
* So a `.gz` is decompressed with `node:zlib` (no external tool, present on every Node ≥ 22
|
|
570
|
+
* build) and then classified: a tar payload is extracted with `tar`, a bare payload *is* the
|
|
571
|
+
* core and is moved straight into place. That also removes the dependency on `tar` being
|
|
572
|
+
* installed for the common Linux case, which matters on slim Ubuntu images.
|
|
530
573
|
*
|
|
531
|
-
* The archive's own file name is not trusted to equal the final name: whichever file
|
|
532
|
-
*
|
|
533
|
-
* working.
|
|
574
|
+
* The archive's own file name is not trusted to equal the final name: whichever file looks like
|
|
575
|
+
* the core is renamed, so a release that changes its internal name keeps working.
|
|
534
576
|
*
|
|
535
577
|
* @param archivePath - downloaded archive.
|
|
536
578
|
* @param kind - `zip` or `gz`.
|
|
@@ -541,34 +583,137 @@ function runTool(command, args) {
|
|
|
541
583
|
export async function unpackCore(archivePath, kind, workDir, finalPath) {
|
|
542
584
|
mkdirSync(workDir, { recursive: true })
|
|
543
585
|
if (kind === 'gz') {
|
|
544
|
-
//
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
586
|
+
// 1. Decompress once, to a file. Streaming keeps the 61 MB payload off the heap.
|
|
587
|
+
const inflated = join(workDir, 'payload.bin')
|
|
588
|
+
await gunzipFile(archivePath, inflated)
|
|
589
|
+
// 2. Is the payload a tar? A POSIX tar carries "ustar" at offset 257 of its header block.
|
|
590
|
+
if (await isTarArchive(inflated)) {
|
|
591
|
+
// Some releases ship `mihomo-linux-amd64-v1.19.34.gz` where the .gz wraps a tar.
|
|
592
|
+
await runTool('tar', ['-xf', inflated, '-C', workDir])
|
|
593
|
+
const source = pickCoreFrom(workDir)
|
|
594
|
+
return await placeCore(source, finalPath)
|
|
595
|
+
}
|
|
596
|
+
// 3. A bare binary: it is the core, already fully decompressed.
|
|
597
|
+
return await placeCore(inflated, finalPath)
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
if (kind === 'zip') {
|
|
601
|
+
// `.zip` only ever arrives on Windows (its assets are the only zip ones), where the bundled
|
|
602
|
+
// `bsdtar` reads it. On Linux `unzip` is tried first and `tar` second, because GNU tar cannot
|
|
603
|
+
// read zip and a stock Ubuntu image may have either tool or neither — the error names both.
|
|
604
|
+
if (process.platform === 'win32') {
|
|
605
|
+
await runTool('tar', ['-xf', archivePath, '-C', workDir])
|
|
606
|
+
} else {
|
|
607
|
+
try {
|
|
608
|
+
await runTool('unzip', ['-o', '-q', archivePath, '-d', workDir])
|
|
609
|
+
} catch (first) {
|
|
610
|
+
try {
|
|
611
|
+
await runTool('tar', ['-xf', archivePath, '-C', workDir])
|
|
612
|
+
} catch (second) {
|
|
613
|
+
throw new Error(
|
|
614
|
+
`could not unpack ${archivePath}: neither \`unzip\` nor a zip-capable \`tar\` worked ` +
|
|
615
|
+
`(unzip: ${first?.message ?? first}; tar: ${second?.message ?? second}). ` +
|
|
616
|
+
`Install unzip, or download the .gz asset for this platform instead.`,
|
|
617
|
+
)
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
return await placeCore(pickCoreFrom(workDir), finalPath)
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
throw new Error(`unsupported archive kind "${kind}"`)
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* Stream a gzip file into a plain file.
|
|
629
|
+
*
|
|
630
|
+
* @param archivePath - the `.gz` file.
|
|
631
|
+
* @param destination - where the decompressed bytes go.
|
|
632
|
+
*/
|
|
633
|
+
function gunzipFile(archivePath, destination) {
|
|
634
|
+
return new Promise((resolve, reject) => {
|
|
635
|
+
const input = createReadStream(archivePath)
|
|
636
|
+
const output = createWriteStream(destination)
|
|
637
|
+
const gunzip = createGunzip()
|
|
638
|
+
const fail = (error) => {
|
|
639
|
+
input.destroy()
|
|
640
|
+
output.destroy()
|
|
641
|
+
gunzip.destroy()
|
|
642
|
+
reject(error)
|
|
643
|
+
}
|
|
644
|
+
input.once('error', fail)
|
|
645
|
+
output.once('error', fail)
|
|
646
|
+
gunzip.once('error', fail)
|
|
647
|
+
output.once('finish', resolve)
|
|
648
|
+
input.pipe(gunzip).pipe(output)
|
|
649
|
+
})
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* Whether a file is a POSIX tar archive.
|
|
654
|
+
*
|
|
655
|
+
* @param path - file to test.
|
|
656
|
+
* @returns true when `ustar` sits at offset 257, which is where every tar variant puts it.
|
|
657
|
+
*/
|
|
658
|
+
async function isTarArchive(path) {
|
|
659
|
+
const handle = await open(path, 'r')
|
|
660
|
+
try {
|
|
661
|
+
const buffer = Buffer.alloc(262)
|
|
662
|
+
const { bytesRead } = await handle.read(buffer, 0, 262, 0)
|
|
663
|
+
if (bytesRead < 262) return false
|
|
664
|
+
return buffer.subarray(257, 262).toString('latin1') === 'ustar'
|
|
665
|
+
} finally {
|
|
666
|
+
await handle.close()
|
|
550
667
|
}
|
|
668
|
+
}
|
|
551
669
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
670
|
+
/**
|
|
671
|
+
* Find the core executable among unpacked entries.
|
|
672
|
+
*
|
|
673
|
+
* @param workDir - directory holding unpacked files.
|
|
674
|
+
* @returns the path of the best candidate.
|
|
675
|
+
*/
|
|
676
|
+
function pickCoreFrom(workDir) {
|
|
677
|
+
const entries = readdirSync(workDir).filter((name) => name !== 'payload.bin')
|
|
678
|
+
// The archive names its payload after the build, not after the fixed name this plugin stores it
|
|
679
|
+
// under: the Windows zip holds `mihomo-windows-amd64-compatible.exe`. Match the build suffix
|
|
680
|
+
// rather than only the bare name, or a correct download is reported as holding no core at all.
|
|
557
681
|
const isCore = (name) =>
|
|
558
682
|
/^(verge-)?mihomo([-.][\w.-]+)?(\.exe)?$/i.test(name) ||
|
|
559
683
|
/^(verge-)?mihomo(-[\w.-]+)?\.exe$/i.test(name) ||
|
|
560
684
|
/^clash(-meta)?([-.][\w.-]+)?(\.exe)?$/i.test(name)
|
|
561
685
|
const wanted = entries.filter(isCore)
|
|
562
|
-
// Prefer an exact `mihomo` / `mihomo.exe` when the archive ships several matches.
|
|
563
686
|
wanted.sort((a, b) => Number(!/^(verge-)?mihomo(\.exe)?$/i.test(a)) - Number(!/^(verge-)?mihomo(\.exe)?$/i.test(b)))
|
|
564
|
-
|
|
565
|
-
if (source === undefined) {
|
|
687
|
+
if (wanted.length === 0) {
|
|
566
688
|
throw new Error(`the archive held no core executable (found: ${entries.slice(0, 5).join(', ') || 'nothing'})`)
|
|
567
689
|
}
|
|
690
|
+
return join(workDir, wanted[0])
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Move a candidate into its final location and make it executable.
|
|
695
|
+
*
|
|
696
|
+
* @param source - the unpacked binary.
|
|
697
|
+
* @param finalPath - where it must live.
|
|
698
|
+
* @returns the path and its size.
|
|
699
|
+
*/
|
|
700
|
+
async function placeCore(source, finalPath) {
|
|
568
701
|
mkdirSync(join(finalPath, '..'), { recursive: true })
|
|
569
702
|
if (existsSync(finalPath)) rmSync(finalPath, { force: true })
|
|
570
703
|
renameSync(source, finalPath)
|
|
571
|
-
|
|
704
|
+
// Linux and macOS refuse to exec a file without the execute bit, and the failure surfaces much
|
|
705
|
+
// later as an opaque EACCES from spawn. Applied on every non-Windows platform — and keyed on
|
|
706
|
+
// `process.platform`, which is genuinely the platform whose filesystem is being written, since
|
|
707
|
+
// the chmod has to land on the machine actually holding the file.
|
|
708
|
+
if (process.platform !== 'win32') {
|
|
709
|
+
try {
|
|
710
|
+
chmodSync(finalPath, 0o755)
|
|
711
|
+
} catch (error) {
|
|
712
|
+
// A read-only or noexec mount reports this; the caller's spawn will fail with a clearer
|
|
713
|
+
// message than a silent success would produce.
|
|
714
|
+
throw new Error(`could not make ${finalPath} executable: ${error?.message ?? error}`)
|
|
715
|
+
}
|
|
716
|
+
}
|
|
572
717
|
return { path: finalPath, bytes: statSync(finalPath).size }
|
|
573
718
|
}
|
|
574
719
|
|
package/lib/skill.js
CHANGED
|
@@ -151,6 +151,23 @@ clash_proxy action=select node=<精确节点名>
|
|
|
151
151
|
| \`web_fetch\` 全部失败 | \`routingHealthy\` | 内核死了,级别 1 |
|
|
152
152
|
| 只有某个 AI 服务连不上 | 该节点的 \`usable\` 与失败探针 | 该服务的地区/机房限制,换节点 |
|
|
153
153
|
| 面板显示节点「限流」但还能上网 | —— | 正常,配额是单服务限制 |
|
|
154
|
+
| Linux 上首次启动很久没反应 | \`status.bootstrap\` | 正在下载 22 MB 内核,不是卡死 |
|
|
155
|
+
|
|
156
|
+
## 五之二、Linux / Ubuntu 特有的事
|
|
157
|
+
|
|
158
|
+
Ubuntu 22.04 / 24.04 LTS / 26.04 LTS 都支持,且**不需要预装任何东西**。二进制是静态链接的(无 \`PT_INTERP\`、无 \`GLIBC_*\`),所以发行版 glibc 版本无关。
|
|
159
|
+
|
|
160
|
+
| 现象 | 真因 | 动作 |
|
|
161
|
+
|---|---|---|
|
|
162
|
+
| 首次启动什么都不发生,面板显示"未运行" | Linux 没有自带内核,需要下载 22 MB | 等首次下载完成(\`status.bootstrap\` 有进度),或点「下载内核」 |
|
|
163
|
+
| \`bootstrap\` 显示 \`Unrecognized archive format\` | 旧版用 \`tar -xzf\` 解 Linux 资产,而那是**裸 gzip 二进制**不是 tar | 升级到 0.10.0+(改用 \`node:zlib\` 解压) |
|
|
164
|
+
| \`no vendored core for linux-x64\` | 同上,旧版没有 Linux 自带内核且未开自动下载 | 升级,或设 \`corePath\` 指向已有的 \`mihomo\` |
|
|
165
|
+
| 内核文件存在但 \`spawn EACCES\` | 缺执行位 | \`chmod 755\` 那个 \`bin/mihomo\`;0.10.0+ 会自动设 |
|
|
166
|
+
| 下载卡住 | GitHub 在境内慢 | 插件会先试 gh-proxy.com / ghfast.top / ghproxy.net |
|
|
167
|
+
|
|
168
|
+
内核落点固定为 \`\${DSH_HOME}/data/dsh-clash-proxy/bin/mihomo\`(Linux 上不带 \`.exe\`)。
|
|
169
|
+
|
|
170
|
+
**不要**用 \`apt install mihomo\` 之类的路径替换它:插件只认自己的二进制(或你显式配置的 \`corePath\`),混用系统的 Clash 会重演"两层代理互相抢"的老问题。
|
|
154
171
|
|
|
155
172
|
## 六、边界
|
|
156
173
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-clash-subscription",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Import one or more Clash/mihomo subscriptions and route the Harness outbound traffic through the private core bundled with this plugin.
|
|
3
|
+
"version": "0.10.0",
|
|
4
|
+
"description": "Import one or more Clash/mihomo subscriptions and route the Harness outbound traffic through the private core bundled with this plugin. Runs on Windows, Linux (Ubuntu 22.04/24.04/26.04 LTS) and macOS: the core is fetched and SHA-256 verified on platforms without a bundled copy, from a bare gzip asset unpacked with node:zlib. Every 30 seconds the live node gets up to three immediate real-request attempts; after three failures every unblocked node is measured and the fastest usable one is selected.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|
|
7
7
|
"dsh-plugin",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"locale/*.json",
|
|
35
35
|
"icon.svg",
|
|
36
36
|
"README.md",
|
|
37
|
-
"CHANGELOG-0.
|
|
37
|
+
"CHANGELOG-0.10.0.md",
|
|
38
38
|
"LICENSE"
|
|
39
39
|
],
|
|
40
40
|
"engines": {
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
"scripts": {
|
|
70
70
|
"test": "node test/regression-070.mjs",
|
|
71
71
|
"test:legacy": "node test/regression-063.mjs",
|
|
72
|
+
"test:linux": "node test/regression-0100.mjs",
|
|
72
73
|
"test:e2e": "node test/e2e-090.mjs"
|
|
73
74
|
}
|
|
74
75
|
}
|
package/CHANGELOG-0.9.0.md
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
# 0.9.0 · 一轮内连续 3 次尝试;不合格就测遍全部节点
|
|
2
|
-
|
|
3
|
-
> 上一版 `0.8.0` · 本版 `0.9.0`
|
|
4
|
-
|
|
5
|
-
## 为什么改
|
|
6
|
-
|
|
7
|
-
0.8.0 把「连续 3 轮不合格」实现成了**跨轮累积**:每 30 秒记一次 strike,攒满 3 次才切换。
|
|
8
|
-
后果是一个坏节点要占着 90 秒以上才被处理,而且中途只要有一次抖动通过,计数清零、从头再攒。
|
|
9
|
-
|
|
10
|
-
用户要的是:**一次检测不合格就立刻再测,还不合格就立刻再测一次,三次都不合格才切换。**
|
|
11
|
-
|
|
12
|
-
## 改了什么
|
|
13
|
-
|
|
14
|
-
### 1. 三次尝试在一轮内连续完成
|
|
15
|
-
|
|
16
|
-
```
|
|
17
|
-
每 30 秒触发一轮:
|
|
18
|
-
attempt 1 → 不合格
|
|
19
|
-
attempt 2 → 立即重试(不等下一个 30 秒)→ 不合格
|
|
20
|
-
attempt 3 → 立即再试 → 不合格
|
|
21
|
-
↓
|
|
22
|
-
测遍【全部未被屏蔽的节点】,切到最优
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
只要任何一次合格就保持,**剩下的次数不再浪费**(省配额)。
|
|
26
|
-
实测间隔:**7.4 秒 / 7.9 秒**,三次总跨度 15.4 秒。
|
|
27
|
-
|
|
28
|
-
| 字段 | 默认 | 说明 |
|
|
29
|
-
|---|---|---|
|
|
30
|
-
| `healthAttempts` | **3** | 一轮内最多试几次;合格即停 |
|
|
31
|
-
| `healthRoundSeconds` | 30 | 多久触发一轮 |
|
|
32
|
-
| `healthStrikeLimit` | 3 | 保留作为跨轮兜底,正常路径不再依赖它 |
|
|
33
|
-
|
|
34
|
-
### 2. 不合格的定义:不可用 **或** 真实延迟过高
|
|
35
|
-
|
|
36
|
-
| 判定 | 条件 |
|
|
37
|
-
|---|---|
|
|
38
|
-
| 不可用 | 某个门槛探针没通(gstatic 非 204 / GitHub 配额 0 / git 拉不到) |
|
|
39
|
-
| 延迟过高 | Google 实测中位延迟 > `healthMaxDelayMs`(默认 400 ms) |
|
|
40
|
-
|
|
41
|
-
两者都写进 `verdict.failed`,所以面板能说清是哪一条。
|
|
42
|
-
|
|
43
|
-
### 3. 切换时测遍全部未被屏蔽节点
|
|
44
|
-
|
|
45
|
-
`healthSwitchCandidates` 默认从 **12 改成 0 = 全部**。上限会把「找最优出口」变成
|
|
46
|
-
「在前 12 个里找最优」,54 节点的订阅可能因此错过更好的节点。
|
|
47
|
-
|
|
48
|
-
实测:8 节点订阅,去掉当前节点与被屏蔽的,**7/7 全测**。
|
|
49
|
-
|
|
50
|
-
排序规则(这是"最优"的定义):
|
|
51
|
-
|
|
52
|
-
1. 可用优先;
|
|
53
|
-
2. **真实延迟最低**(Google 中位);
|
|
54
|
-
3. 失败探针更少;
|
|
55
|
-
4. 限流优先于不通(配额会重置,线路坏不会)。
|
|
56
|
-
|
|
57
|
-
被屏蔽的节点不参与(`group.all` 本身已排除,代码里再用 `isBlocked` 兜一层)。
|
|
58
|
-
|
|
59
|
-
## 两个被真机测试逼出来的修正
|
|
60
|
-
|
|
61
|
-
### A. 单次延迟采样不可信 → 改中位数
|
|
62
|
-
|
|
63
|
-
同一节点同一分钟连续测 Google:
|
|
64
|
-
|
|
65
|
-
```
|
|
66
|
-
2256, 967, 1412, 179, 1190, 180 ms
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
拿一次采样比 400 ms 阈值,基本是掷骰子——慢但没坏的节点会被判死,快但很差的会被放过。
|
|
70
|
-
|
|
71
|
-
改成 **3 次采样取中位数**,且**丢掉第一次**(新内核首次要付 DNS+TCP+TLS,实测 513 ms vs 82 ms)。
|
|
72
|
-
新增 `healthLatencySamples`(默认 3,范围 2–5)。
|
|
73
|
-
|
|
74
|
-
### B. 测不到延迟时阈值会静默失效 → 加回落链
|
|
75
|
-
|
|
76
|
-
`latency === undefined` 时,`tooSlow` 恒为 false,阈值**形同不存在**,一个 Google 不通的慢节点会被永久保留。
|
|
77
|
-
|
|
78
|
-
回落顺序:warm Google 中位 → cold Google → **最快的那条已通过的门槛探针**。
|
|
79
|
-
只有全都没答时才留 undefined,而那种节点已经因为门槛探针失败而被判不合格。
|
|
80
|
-
|
|
81
|
-
`latencySource` 会标 `warm-median` / `cold` / `fallback-probe` / `unreachable`,面板能解释这个数从哪来。
|
|
82
|
-
|
|
83
|
-
## 验收
|
|
84
|
-
|
|
85
|
-
```
|
|
86
|
-
node test/regression-070.mjs → 112 passed, 0 failed
|
|
87
|
-
node test/regression-063.mjs → 31 passed, 0 failed
|
|
88
|
-
node test/e2e-090.mjs → 13 passed, 0 failed(真内核 + 真订阅 + 真请求)
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
e2e 真实输出:
|
|
92
|
-
|
|
93
|
-
```
|
|
94
|
-
strict round: attempts=3
|
|
95
|
-
attempt 1: usable=false latency=3544
|
|
96
|
-
attempt 2: usable=false latency=3090
|
|
97
|
-
attempt 3: usable=false latency=3445
|
|
98
|
-
gaps between attempts: 7427, 7935 ms ← 立即重试,不是等 30 秒
|
|
99
|
-
三次尝试总跨度: 15362 ms(整轮含全节点实测 74622 ms)
|
|
100
|
-
tested 7 candidate(s) of 7 unblocked non-live node(s) ← 全测
|
|
101
|
-
|
|
102
|
-
measured (usable first, fastest first):
|
|
103
|
-
🇸🇬 新加坡01 usable=true latency=274
|
|
104
|
-
🇺🇸 美国01 usable=true latency=340
|
|
105
|
-
🇸🇬 新加坡02 usable=true latency=346
|
|
106
|
-
🇲🇾 马来西亚01 usable=true latency=352
|
|
107
|
-
🇹🇼 台湾02 usable=true latency=384
|
|
108
|
-
🇺🇸 美国02 usable=false latency=577
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
## 附带更新
|
|
112
|
-
|
|
113
|
-
- 插件自带的 `clash-proxy-egress` 技能:把「连续 3 轮」改成「一轮内连续 3 次」,
|
|
114
|
-
判据从 `health.lastRound.strikes` 改成 `health.lastRound.attempt`,并写明
|
|
115
|
-
「不合格 = 不可用 或 延迟过高」与「三次全败会测遍全部未屏蔽节点」。
|
|
116
|
-
- `status.health` 新增 `attempts`、`baselineProbe`、`switchCandidates` 字段。
|
|
117
|
-
|
|
118
|
-
## 遗留
|
|
119
|
-
|
|
120
|
-
- `healthStrikeLimit` 仍然存在但正常路径不再驱动切换(同一轮内 3 次尝试已经取代它)。
|
|
121
|
-
保留是为了兼容旧配置不报错,后续版本可以考虑移除。
|
|
122
|
-
- 面板新增字段(`healthAttempts`、`healthLatencySamples`)已接配置层,未在真浏览器里核对渲染。
|