dsh-clash-subscription 0.7.0 → 0.9.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.
@@ -0,0 +1,122 @@
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`)已接配置层,未在真浏览器里核对渲染。
package/client.js CHANGED
@@ -117,16 +117,20 @@ const en = {
117
117
  healthTitle: 'Health watch and automatic switching',
118
118
  autoSwitch: 'Watch the node with real requests',
119
119
  autoSwitchHint: 'Every round sends real requests through the live node: GitHub API (including the remaining quota), a git fetch, and a 204 endpoint. A node counts as usable only when all of those answer. This is what catches a rate-limited node, which a plain latency check reports as healthy.',
120
- healthRound: 'Round interval (minutes)',
121
- healthRoundHint: 'How often the real-request round runs. 0 turns it off.',
120
+ healthRound: 'Round interval (seconds)',
121
+ healthRoundHint: 'How often the real-request round runs. Default 30. 0 turns it off. Each round sends a few real requests through the live node, so very short intervals cost quota.',
122
122
  healthStrikes: 'Bad rounds before switching',
123
- healthStrikesHint: 'Consecutive failed rounds before the node is given up on. Any good round resets the count, so one noisy sample never causes a switch. Default 3.',
123
+ healthStrikesHint: 'Consecutive failed rounds before the node is given up on. A round fails when a required request does not answer, OR when the node is slower than the latency ceiling. Any good round resets the count. Default 3.',
124
+ healthMaxDelay: 'Latency ceiling (ms)',
125
+ healthMaxDelayHint: 'A node slower than this does not stay selected. 0 disables the ceiling and only reachability decides. Default 400 ms.',
126
+ healthSurvey: 'Survey other nodes every N rounds',
127
+ healthSurveyHint: 'In the background, once every N rounds, measure the other nodes for real so a switch picks from a ranked list instead of starting a slow search when the line is already broken. 0 disables the survey. Default 20 rounds (about 10 minutes at 30 s).',
124
128
  healthCandidates: 'Nodes tried per switch',
125
129
  healthCandidatesHint: 'How many alternatives one switch tests, fastest first. 0 tests every node, which on a 54-node subscription takes minutes.',
126
130
  switchWhileBusy: 'Switch even with connections open',
127
131
  switchWhileBusyHint: 'Off by default: a switch aborts whatever is in flight. On means a broken node is abandoned immediately instead of waiting for the line to go quiet.',
128
132
  limitedNote: '{count} limited, {blocked} blocked',
129
- healthRoundNote: 'Last round: {state} · streak {strikes}/{limit}',
133
+ healthRoundNote: 'Every {every}s · last round {state} at {latency} ms (ceiling {ceiling} ms) · streak {strikes}/{limit}',
130
134
  lastSwitchNote: 'Switched {from} → {to} at {time}',
131
135
  runHealth: 'Check the live node now',
132
136
  healthRunning: 'Checking the live node…',
@@ -211,16 +215,20 @@ const zh = {
211
215
  healthTitle: '可用性监视与自动切换',
212
216
  autoSwitch: '用真实请求监视当前节点',
213
217
  autoSwitchHint: '每轮都通过当前节点实发请求:GitHub API(连剩余配额一起看)、git 拉取、以及一个 204 连通性端点。全部通过才算可用。这正是「限流节点被判成可用」的那个缺口——普通延迟检测对 403 也报成功。',
214
- healthRound: '检测间隔(分钟)',
215
- healthRoundHint: '多久跑一轮真实请求检测。0 = 关闭。',
218
+ healthRound: '检测间隔(秒)',
219
+ healthRoundHint: '多久跑一轮真实请求检测,默认 30 秒。0 = 关闭。每轮都会通过当前节点发几次真实请求,间隔太短会消耗服务配额。',
216
220
  healthStrikes: '连续几轮失败才切换',
217
- healthStrikesHint: '节点连续失败多少轮才放弃。任何一轮通过都会把计数清零,所以单次抖动不会触发切换。默认 3。',
221
+ healthStrikesHint: '节点连续失败多少轮才放弃。记为失败有两种情况:必需的请求没通,或者节点延迟超过上面那条阈值。任何一轮通过都会把计数清零。默认 3。',
222
+ healthMaxDelay: '延迟阈值(毫秒)',
223
+ healthMaxDelayHint: '超过这个延迟的节点不会被保留。填 0 表示只看连通性,不管快慢。默认 400 毫秒。',
224
+ healthSurvey: '每几轮巡测一次其他节点',
225
+ healthSurveyHint: '后台每 N 轮真实测一次其他节点,切换时直接从排好序的候选里挑,不用等线路已经坏了才开始慢慢搜。0 = 关闭巡测。默认 20 轮(30 秒间隔下约 10 分钟)。',
218
226
  healthCandidates: '每次切换试几个节点',
219
227
  healthCandidatesHint: '一次切换最多试多少个候选,按延迟从低到高。0 = 全试,54 个节点要几分钟。',
220
228
  switchWhileBusy: '有连接在进行时也切换',
221
229
  switchWhileBusyHint: '默认关闭:切换会中断正在进行的请求。打开后坏节点会被立刻丢弃,不等线路空闲。',
222
230
  limitedNote: '{count} 个限流,{blocked} 个不通',
223
- healthRoundNote: '最近一轮:{state} · 连续 {strikes}/{limit}',
231
+ healthRoundNote: '每 {every} 秒 · 最近一轮 {state},{latency} ms(阈值 {ceiling} ms)· 连续 {strikes}/{limit}',
224
232
  lastSwitchNote: '已于 {time} 从「{from}」切到「{to}」',
225
233
  runHealth: '立刻检测当前节点',
226
234
  healthRunning: '正在检测当前节点…',
@@ -439,8 +447,10 @@ function sections(t) {
439
447
  title: t('healthTitle'),
440
448
  fields: [
441
449
  { key: 'autoSwitch', kind: 'switch', label: t('autoSwitch'), hint: t('autoSwitchHint') },
442
- { key: 'healthRoundMinutes', kind: 'number', label: t('healthRound'), hint: t('healthRoundHint'), min: 0, max: 120, step: 1 },
450
+ { key: 'healthRoundSeconds', kind: 'number', label: t('healthRound'), hint: t('healthRoundHint'), min: 0, max: 3600, step: 5 },
443
451
  { key: 'healthStrikeLimit', kind: 'number', label: t('healthStrikes'), hint: t('healthStrikesHint'), min: 1, max: 20, step: 1 },
452
+ { key: 'healthMaxDelayMs', kind: 'number', label: t('healthMaxDelay'), hint: t('healthMaxDelayHint'), min: 0, max: 30000, step: 50 },
453
+ { key: 'healthSurveyEvery', kind: 'number', label: t('healthSurvey'), hint: t('healthSurveyHint'), min: 0, max: 10000, step: 5 },
444
454
  { key: 'healthSwitchCandidates', kind: 'number', label: t('healthCandidates'), hint: t('healthCandidatesHint'), min: 0, max: 100, step: 1 },
445
455
  { key: 'switchWhileBusy', kind: 'switch', label: t('switchWhileBusy'), hint: t('switchWhileBusyHint') },
446
456
  ],
@@ -877,9 +887,12 @@ function Panel(props) {
877
887
  live.health.enabled === false
878
888
  ? t('healthOff')
879
889
  : fill(t('healthRoundNote'), {
890
+ every: live.health.everySeconds ?? 30,
880
891
  state: live.health.lastRound?.state ?? t('never'),
881
892
  strikes: live.health.lastRound?.strikes ?? 0,
882
893
  limit: live.health.strikeLimit ?? 3,
894
+ latency: live.health.lastRound?.latency ?? '—',
895
+ ceiling: live.health.maxDelayMs ?? 400,
883
896
  }),
884
897
  live.health.lastSwitch?.state === 'switched'
885
898
  ? ' · ' + fill(t('lastSwitchNote'), {