dsh-clash-subscription 0.2.3 → 0.4.2
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/README.md +132 -167
- package/client.js +223 -29
- package/index.js +687 -83
- package/lib/cn-cidr.js +5526 -0
- package/lib/core.js +323 -85
- package/lib/corefetch.js +618 -0
- package/lib/discovery.js +31 -73
- package/lib/geo.js +130 -0
- package/lib/routes.js +47 -3
- package/lib/subscription.js +196 -0
- package/lib/vendored.js +167 -0
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +8 -3
- package/vendor/SHA256SUMS.json +7 -0
- package/vendor/mihomo.exe.gz +0 -0
package/README.md
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
# dsh-clash-subscription
|
|
2
2
|
|
|
3
|
-
> Package `dsh-clash-subscription
|
|
4
|
-
> existing profile's saved config keeps applying)
|
|
3
|
+
> Package `dsh-clash-subscription` · loader row id `clash-proxy` (kept stable so an
|
|
4
|
+
> existing profile's saved config keeps applying) · Settings → **Clash 代理**
|
|
5
5
|
|
|
6
|
-
Give DeepSeek Harness its own outbound proxy: import
|
|
7
|
-
and the plugin
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
Give DeepSeek Harness its own outbound proxy: import **one or more** Clash/mihomo
|
|
7
|
+
subscriptions and the plugin routes foreign traffic through a node while Chinese traffic
|
|
8
|
+
stays direct — **no desktop Clash app, no system proxy, no per-command `HTTPS_PROXY`, and no
|
|
9
|
+
other software to install**.
|
|
10
|
+
|
|
11
|
+
## What 0.4 changes
|
|
12
|
+
|
|
13
|
+
**The core now ships with the plugin.** That is the difference between "installs" and
|
|
14
|
+
"works". The core is itself on the internet, so downloading it lazily made a machine that
|
|
15
|
+
installed this plugin *because* it could not reach the internet need the internet to become
|
|
16
|
+
able to reach the internet. Now:
|
|
17
|
+
|
|
18
|
+
| | Before | 0.4 |
|
|
19
|
+
|---|---|---|
|
|
20
|
+
| Core | searched for, else "install Clash Verge" | **vendored** (22 MB gzip), unpacked and verified on first use — measured 0.9 s to routing |
|
|
21
|
+
| Domestic classification | needed `Country.mmdb`, else a 30-domain list that sent meituan.com through a node | **5500 embedded CN CIDR blocks** in a generated rule set; no database required |
|
|
22
|
+
| GeoIP database | fetched during startup, over a tunnel that did not exist yet | fetched **after routing is healthy**, in the background, as an upgrade |
|
|
23
|
+
| Missing core | was a `blocker` — the panel said "cannot start" | not a blocker; configuration works without one |
|
|
11
24
|
|
|
12
25
|
## Install
|
|
13
26
|
|
|
@@ -17,208 +30,160 @@ enough to make the settings page appear to exist, and the plugin then silently d
|
|
|
17
30
|
```jsonc
|
|
18
31
|
// ~/.dsh/profiles/<profile>/package.json
|
|
19
32
|
{
|
|
20
|
-
"dependencies": {
|
|
21
|
-
|
|
22
|
-
},
|
|
23
|
-
"dsh": {
|
|
24
|
-
"profile": {
|
|
25
|
-
"bundles": [
|
|
26
|
-
// ... other bundles ...
|
|
27
|
-
"dsh-clash-subscription" // ← and it must be listed as a bundle
|
|
28
|
-
]
|
|
29
|
-
}
|
|
30
|
-
}
|
|
33
|
+
"dependencies": { "dsh-clash-subscription": "0.4.0" },
|
|
34
|
+
"dsh": { "profile": { "bundles": ["dsh-clash-subscription"] } }
|
|
31
35
|
}
|
|
32
36
|
```
|
|
33
37
|
|
|
34
|
-
|
|
38
|
+
```bash
|
|
39
|
+
cd ~/.dsh/profiles/<profile>
|
|
40
|
+
pnpm install --config.minimumReleaseAge=0
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Then **fully restart the Harness** — the host loads plugin code at boot.
|
|
44
|
+
|
|
45
|
+
The package is ~22 MB because it carries the core. That is deliberate: it is the only way
|
|
46
|
+
"install, configure, works" holds on a machine with no working outbound route.
|
|
47
|
+
|
|
48
|
+
## Subscriptions
|
|
49
|
+
|
|
50
|
+
One per line in **订阅链接 / Import links**. Blank lines and lines starting with `#` or `//`
|
|
51
|
+
are ignored.
|
|
35
52
|
|
|
36
53
|
```
|
|
37
|
-
|
|
38
|
-
|
|
54
|
+
主用 https://api.example.com/api/v1/client/subscribe?token=…
|
|
55
|
+
备用 https://backup.example.com/sub?token=…
|
|
56
|
+
clash://install-config?url=https%3A%2F%2Fthird.example.com%2Fsub
|
|
39
57
|
```
|
|
40
58
|
|
|
41
|
-
|
|
59
|
+
- A leading `name` is optional; without one the entry is called `订阅 N`.
|
|
60
|
+
- Bare `https://` and `clash://install-config?url=…` are both accepted, on any line.
|
|
61
|
+
- A duplicate URL is dropped and *reported*; a malformed line is named by line number.
|
|
62
|
+
- An existing 0.2 profile's single `subscriptionUrl` is read as the first line; the next save
|
|
63
|
+
moves the profile onto the list field.
|
|
42
64
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
65
|
+
Every subscription becomes its own core provider feeding one `PROXY` group, so the node table
|
|
66
|
+
is the union. With more than one subscription each provider's nodes are prefixed with its
|
|
67
|
+
name — two providers routinely both name a node `香港01`, and without a prefix the group holds
|
|
68
|
+
duplicate names. A provider that fails to download shows `未拉到节点` on its own row and does
|
|
69
|
+
not stop the others.
|
|
47
70
|
|
|
48
71
|
## Split routing
|
|
49
72
|
|
|
50
73
|
| Destination | Path |
|
|
51
74
|
| --- | --- |
|
|
52
|
-
| Loopback `127.0.0.1`, `::1`, localhost | direct
|
|
75
|
+
| Loopback `127.0.0.1`, `::1`, localhost | direct |
|
|
53
76
|
| LAN `10/8`, `172.16/12`, `192.168/16`, `169.254/16` | direct |
|
|
54
|
-
| Chinese addresses
|
|
55
|
-
| Everything else | proxy
|
|
56
|
-
|
|
57
|
-
Domestic sites therefore behave exactly as before; only traffic that would otherwise
|
|
58
|
-
be blocked reaches a node.
|
|
59
|
-
|
|
60
|
-
## No defaults, no borrowed configuration
|
|
61
|
-
|
|
62
|
-
The subscription URL has **no default value and no fallback**. The plugin never reads
|
|
63
|
-
another client's profile, subscription, or node selection. The only machine-level
|
|
64
|
-
information it uses is:
|
|
65
|
-
|
|
66
|
-
- an existing mihomo-compatible executable, so you need not type a path to a core the
|
|
67
|
-
machine already has; and
|
|
68
|
-
- downloaded GeoIP/GeoSite databases, because the core needs them before it can
|
|
69
|
-
classify a single connection — the alternative is a download over the very tunnel
|
|
70
|
-
those databases are required to establish.
|
|
71
|
-
|
|
72
|
-
Both are optional. Without them you point `corePath` at a binary and the core falls
|
|
73
|
-
back to a built-in domestic domain list.
|
|
74
|
-
|
|
75
|
-
## How it works
|
|
76
|
-
|
|
77
|
-
It does not reimplement transport. It reuses the Harness' own outbound policy module
|
|
78
|
-
`@deepseek-ai/dsh-http-proxy`:
|
|
79
|
-
|
|
80
|
-
1. **The core parses the subscription.** The config carries a `proxy-providers` entry
|
|
81
|
-
and mihomo downloads it itself, so anytls / hysteria2 / vless / ss / trojan all work
|
|
82
|
-
without a parser or a schema to track.
|
|
83
|
-
2. **The policy is loaded from the installation, not the profile.** A profile-installed
|
|
84
|
-
plugin resolves bare specifiers from its own `node_modules`; resolving
|
|
85
|
-
`dsh-http-proxy` from the dsh installation's manifest yields the *same module
|
|
86
|
-
instance the host loaded*. Node's `fetch` resolves undici's global dispatcher, and
|
|
87
|
-
`dsh-subprocess` asks this same module for a child's environment — one instance, so
|
|
88
|
-
one install covers `ctx.web`, the LLM transports and every spawned child.
|
|
89
|
-
3. **A working node is chosen at startup.** A fresh `PROXY` group starts on `DIRECT`,
|
|
90
|
-
which would send foreign traffic straight out, so the plugin measures latency in
|
|
91
|
-
batches, skips dead nodes (a provider can report a node alive long after it stopped
|
|
92
|
-
serving), and never selects `DIRECT`.
|
|
93
|
-
4. **Geo databases are reused, never re-downloaded.** A missing database makes the core
|
|
94
|
-
fetch one from GitHub at startup — the exact connection it needs the database to
|
|
95
|
-
establish — so an existing copy is reused and a missing one is reported instead of
|
|
96
|
-
retried.
|
|
97
|
-
|
|
98
|
-
## Packaged builds and the installation root
|
|
99
|
-
|
|
100
|
-
The plugin must load its proxy policy from the **Harness installation**, not from the
|
|
101
|
-
profile: that is what makes it the same `undici` instance the host already routes through.
|
|
102
|
-
A packaged Desktop build keeps the app inside a single archive file:
|
|
77
|
+
| Chinese domains and addresses | direct |
|
|
78
|
+
| Everything else | proxy |
|
|
103
79
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
80
|
+
Domestic is decided in three layers, in order: an explicit `directDomains` list, a built-in
|
|
81
|
+
domain list (`.cn`, baidu, qq, taobao…), then a **5500-block CN address rule set generated
|
|
82
|
+
from the plugin's own data**. No GeoIP database is needed for any of it.
|
|
83
|
+
|
|
84
|
+
Two measured details are worth knowing because they are easy to get wrong:
|
|
107
85
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
86
|
+
- The address rule must **not** carry `no-resolve`. A CONNECT to a hostname has no address
|
|
87
|
+
until the core resolves it; with `no-resolve` every domestic site fell through to `MATCH`,
|
|
88
|
+
i.e. straight into the tunnel.
|
|
89
|
+
- A core with no `Country.mmdb` logs `MMDB invalid, remove and download` and tries to fetch
|
|
90
|
+
one. That is why the database is an *upgrade* now and never a startup dependency.
|
|
112
91
|
|
|
113
|
-
|
|
92
|
+
## Configuration
|
|
114
93
|
|
|
115
|
-
|
|
|
94
|
+
| Field | Default | Meaning |
|
|
116
95
|
| --- | --- | --- |
|
|
117
|
-
|
|
|
118
|
-
|
|
|
119
|
-
|
|
|
120
|
-
|
|
|
96
|
+
| `subscriptionUrls` | empty | One subscription per line, optional `name ` prefix |
|
|
97
|
+
| `node` | empty | Preferred exit node; empty means automatic |
|
|
98
|
+
| `mode` | `rule` | `rule` keeps Chinese sites direct; `global` sends everything through the node |
|
|
99
|
+
| `autoStart` | `true` | Bring routing up when the plugin loads |
|
|
100
|
+
| `autoFetchCore` | `false` | Download a core from the internet when this platform has no bundled one |
|
|
101
|
+
| `autoFetchGeo` | `true` | Fetch GeoIP databases after routing works; an upgrade, never a requirement |
|
|
102
|
+
| `speedTestMinutes` | `30` | Node re-measurement cycle; `0` disables |
|
|
103
|
+
| `speedTestCount` | `8` | Nodes measured per cycle |
|
|
104
|
+
| `healthCheckMinutes` | `1` | Liveness/watchdog cycle; `0` disables |
|
|
105
|
+
| `directDomains` / `proxyDomains` | empty | Comma-separated suffixes, always direct / always proxied |
|
|
106
|
+
| `dnsServers` | empty | Resolvers the core uses for its own lookups |
|
|
107
|
+
| `corePath` | empty | Use this executable instead of the bundled/search one |
|
|
108
|
+
| `coreVersion` | empty | Pin a download to a version whose digest ships with this build |
|
|
109
|
+
| `dataDir` | `<DSH_HOME>/data/dsh-clash-proxy` | Core, its config, provider cache, rule set |
|
|
121
110
|
|
|
122
|
-
The
|
|
123
|
-
locator, so when it returned nothing the config schema was `undefined` and the settings
|
|
124
|
-
section never appeared. Both come from one root cause.
|
|
111
|
+
## The bundled core
|
|
125
112
|
|
|
126
|
-
|
|
127
|
-
|
|
113
|
+
`vendor/mihomo.exe.gz` is mihomo v1.19.34 (windows-amd64-compatible — the CPU-baseline build,
|
|
114
|
+
so it runs on older machines that a `v3` build would crash with an illegal instruction).
|
|
128
115
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
116
|
+
`vendor/SHA256SUMS.json` is generated when the package is built and records the SHA-256 of
|
|
117
|
+
both the archive and the unpacked executable. `lib/vendored.js` checks the archive **before**
|
|
118
|
+
unpacking and the executable **after**, and re-unpacks if an already-installed copy no longer
|
|
119
|
+
matches — a corrupted or replaced binary is restored rather than trusted. If the manifest and
|
|
120
|
+
the archive ever disagree, the plugin refuses to run the binary at all.
|
|
132
121
|
|
|
133
|
-
|
|
122
|
+
Only `win32-x64` ships. Other platforms report `platformSupported: false` and use `corePath`
|
|
123
|
+
or `autoFetchCore` instead.
|
|
134
124
|
|
|
135
|
-
|
|
125
|
+
## The optional GeoIP upgrade
|
|
136
126
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
| `subscriptionUrl` | empty | Subscription URL. `clash://install-config?url=…` import links are accepted. Required. |
|
|
140
|
-
| `node` | empty | Preferred node name; empty picks the lowest-latency working node |
|
|
141
|
-
| `corePath` | empty | mihomo/clash executable; empty searches the usual install locations |
|
|
142
|
-
| `mode` | `rule` | `rule` keeps domestic traffic direct; `global` proxies everything |
|
|
143
|
-
| `autoStart` | `true` | Start the core and install the policy when the plugin loads |
|
|
144
|
-
| `speedTestMinutes` | `30` | Re-measure interval; `0` disables the cycle |
|
|
145
|
-
| `speedTestCount` | `8` | Nodes measured per cycle |
|
|
146
|
-
| `dnsServers` | empty | Resolvers for the core's own lookups, comma separated |
|
|
147
|
-
| `directDomains` | empty | Domain suffixes that must stay direct |
|
|
148
|
-
| `proxyDomains` | empty | Domain suffixes that must always use the node |
|
|
149
|
-
| `dataDir` | `<DSH_HOME>/data/dsh-clash-proxy` | Core config, subscription cache, geo databases |
|
|
127
|
+
After routing is confirmed healthy, the plugin tries to fetch `Country.mmdb` (and `geoip.dat`)
|
|
128
|
+
from jsDelivr first, then GitHub raw. Progress is visible as `status.geoUpgrade`:
|
|
150
129
|
|
|
151
|
-
|
|
152
|
-
|
|
130
|
+
| `phase` | Meaning |
|
|
131
|
+
| --- | --- |
|
|
132
|
+
| `present` | a database is already on disk (seeded from a local Clash install, or fetched earlier) |
|
|
133
|
+
| `fetching` | in flight |
|
|
134
|
+
| `done` / `partial` / `unavailable` | outcome; the domestic bypass works in every case |
|
|
135
|
+
| `disabled` | `autoFetchGeo: false` |
|
|
136
|
+
|
|
137
|
+
A fetched database applies from the next core start.
|
|
153
138
|
|
|
154
139
|
## UI
|
|
155
140
|
|
|
156
|
-
|
|
157
|
-
latency, the subscription field with a pre-save reachability check, and the
|
|
158
|
-
speed-test cycle. Saving writes through the Harness config editor, so the rest of the
|
|
159
|
-
profile patch stays intact; a routing-relevant change restarts the core, a timing
|
|
160
|
-
change only re-arms the cycle.
|
|
141
|
+
Settings → **Clash proxy**:
|
|
161
142
|
|
|
162
|
-
|
|
143
|
+
- live state: endpoint, whether the policy is installed, and whether it is actually healthy
|
|
144
|
+
- one row per subscription: name, node count, last fetch time, its own refresh button
|
|
145
|
+
- exit-node table with per-node latency (not measured / measured / no answer)
|
|
146
|
+
- a multi-line subscription editor with **检测全部** reporting every line
|
|
147
|
+
- when no core is present: a **下载内核** button, with the download's progress and outcome
|
|
163
148
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
- `status` — core, policy, node table, current node, live traffic
|
|
167
|
-
- `import` — probe a URL, restart the core on it, install the policy
|
|
168
|
-
- `start` / `stop` — bring routing up or take it down
|
|
169
|
-
- `select` — switch the exit node by name
|
|
170
|
-
- `test` — measure one node, or the current one
|
|
171
|
-
- `refresh` — re-download the subscription
|
|
149
|
+
## Tool
|
|
172
150
|
|
|
173
|
-
|
|
151
|
+
`clash_proxy`:
|
|
174
152
|
|
|
175
|
-
|
|
153
|
+
| Action | Effect |
|
|
154
|
+
| --- | --- |
|
|
155
|
+
| `status` | Core, policy, subscriptions, node table, traffic, rule-set state, GeoIP phase |
|
|
156
|
+
| `import` | `url` (one or more lines) replaces the list; `append: true` adds. Probes, **saves**, restarts |
|
|
157
|
+
| `bootstrap` | Download and verify a core when this platform has no bundled one |
|
|
158
|
+
| `start` / `stop` | Bring routing up (unpacking the bundled core if needed) / return to direct |
|
|
159
|
+
| `select` / `test` | Switch the exit node / measure latency |
|
|
160
|
+
| `refresh` | Re-download every subscription |
|
|
176
161
|
|
|
177
|
-
|
|
178
|
-
curl -s http://127.0.0.1:<host port>/clash-proxy/status \
|
|
179
|
-
| grep -o '"routingVerified":"[a-z]*"'
|
|
180
|
-
```
|
|
162
|
+
## HTTP routes
|
|
181
163
|
|
|
182
|
-
|
|
183
|
-
- `
|
|
184
|
-
|
|
164
|
+
All `exact`, same-origin, JSON: `/clash-proxy/status` (GET), `/clash-proxy/config` (GET/POST),
|
|
165
|
+
`/clash-proxy/action` (POST: `start` `stop` `refresh` `refreshOne` `bootstrap` `probe` `test`
|
|
166
|
+
`select`), `/clash-proxy/probe` (POST).
|
|
185
167
|
|
|
186
|
-
`
|
|
187
|
-
|
|
188
|
-
fetch a foreign host, is **not** sufficient proof on its own.
|
|
168
|
+
Tokens are masked (`token=***`) in every response and in the log. The profile patch and the
|
|
169
|
+
core's own `config.json` necessarily hold the real value.
|
|
189
170
|
|
|
190
171
|
## Tests
|
|
191
172
|
|
|
192
173
|
```bash
|
|
193
|
-
node test/unit.mjs
|
|
194
|
-
node test/client-sim.mjs
|
|
174
|
+
node test/unit.mjs # 77 offline assertions: no network, no core, no profile writes
|
|
175
|
+
node test/client-sim.mjs # the panel bundle in a simulated module loader
|
|
195
176
|
node test/e2e.mjs "<subscription url>" # real core + real subscription
|
|
196
177
|
```
|
|
197
178
|
|
|
198
|
-
`test/e2e.mjs` asserts the three promises above: the core boots, `fetch` reaches
|
|
199
|
-
foreign hosts once the policy is installed, and domestic plus loopback traffic stays
|
|
200
|
-
direct.
|
|
201
|
-
|
|
202
179
|
## Known limits
|
|
203
180
|
|
|
204
|
-
- **
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
- **Node quality is the subscription's.** Automatic selection measures latency once;
|
|
214
|
-
later congestion still needs a manual `select` or `test`.
|
|
215
|
-
- **No bundled core.** Bring a mihomo/clash binary; the plugin does not redistribute one.
|
|
216
|
-
- **An unrecognised installation layout stops routing, not just the panel.** If
|
|
217
|
-
`status.blocker` mentions the installation root, set `DSH_INSTALL_ROOT`; everything
|
|
218
|
-
downstream (routing, the tool, the settings section) needs that root.
|
|
219
|
-
- **One profile at a time.** Each profile has its own `dependencies` and `bundles`; a
|
|
220
|
-
machine with several profiles needs the package installed in each of them.
|
|
221
|
-
|
|
222
|
-
## License
|
|
223
|
-
|
|
224
|
-
MIT
|
|
181
|
+
- **Only windows-x64 is vendored.** macOS and Linux need `corePath` or `autoFetchCore`.
|
|
182
|
+
- **22 MB package.** The alternative is a download that cannot work on the machine that needs
|
|
183
|
+
it most.
|
|
184
|
+
- `directDomains` / `proxyDomains` are `DOMAIN-SUFFIX` rules only; CIDR there is not accepted
|
|
185
|
+
(the loopback/LAN CIDRs are built in).
|
|
186
|
+
- A provider health check answers `503` for a node whose server is unreachable — that is the
|
|
187
|
+
measurement working, not a plugin error.
|
|
188
|
+
- The bundled rule set covers IPv4. IPv6 stays direct via the loopback/LAN rules and is
|
|
189
|
+
otherwise classified by the optional GeoIP database.
|