dsh-clash-subscription 0.2.2 → 0.2.3
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 +97 -1
- package/index.js +36 -4
- package/lib/install.js +106 -18
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
# dsh-clash-
|
|
1
|
+
# dsh-clash-subscription
|
|
2
|
+
|
|
3
|
+
> Package `dsh-clash-subscription`, loader row id `clash-proxy` (kept stable so an
|
|
4
|
+
> existing profile's saved config keeps applying). Settings page: **Settings → Clash proxy**.
|
|
2
5
|
|
|
3
6
|
Give DeepSeek Harness its own outbound proxy: import a Clash/mihomo subscription,
|
|
4
7
|
and the plugin runs a **private core** and points the Harness' outbound policy at it.
|
|
@@ -6,6 +9,42 @@ and the plugin runs a **private core** and points the Harness' outbound policy a
|
|
|
6
9
|
sites automatically — **no desktop Clash app, no system proxy, no per-command
|
|
7
10
|
`HTTPS_PROXY`**.
|
|
8
11
|
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
The bundle must be present in **two** places in the profile manifest. Only one of them is
|
|
15
|
+
enough to make the settings page appear to exist, and the plugin then silently does nothing.
|
|
16
|
+
|
|
17
|
+
```jsonc
|
|
18
|
+
// ~/.dsh/profiles/<profile>/package.json
|
|
19
|
+
{
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"dsh-clash-subscription": "0.2.3" // ← the package must be installed
|
|
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
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
With only the `bundles` entry the host fails at startup with:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
dsh: cannot resolve profile bundle "dsh-clash-subscription" from the dsh installation or
|
|
38
|
+
<profile dir>; run 'dsh plugin --profile <profile> install' if its dependency is not installed
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Then install and **fully restart the Harness** — the host loads plugin code at boot:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
cd ~/.dsh/profiles/<profile>
|
|
45
|
+
pnpm install --config.minimumReleaseAge=0
|
|
46
|
+
```
|
|
47
|
+
|
|
9
48
|
## Split routing
|
|
10
49
|
|
|
11
50
|
| Destination | Path |
|
|
@@ -56,6 +95,41 @@ It does not reimplement transport. It reuses the Harness' own outbound policy mo
|
|
|
56
95
|
establish — so an existing copy is reused and a missing one is reported instead of
|
|
57
96
|
retried.
|
|
58
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:
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
<install dir>\resources\app.asar\dsh\node_modules\@deepseek-ai\dsh-desktop-host\lib\index.js
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Note `app.asar`, not `app`. 0.2.2 only recognised `resources/app/dsh` and `app/dsh`, so on
|
|
109
|
+
every packaged build it reported `cannot locate the dsh installation root from the process
|
|
110
|
+
arguments`, never spawned the core, and — because the readiness check did not inspect the
|
|
111
|
+
installation root — retried the same failure on every boot with nothing on the panel.
|
|
112
|
+
|
|
113
|
+
0.2.3 tries four sources in order:
|
|
114
|
+
|
|
115
|
+
| # | Source | Use |
|
|
116
|
+
| --- | --- | --- |
|
|
117
|
+
| 1 | `DSH_INSTALL_ROOT` / `DSH_APP_ROOT` | explicit override, always wins |
|
|
118
|
+
| 2 | `process.argv` | the host passes its own entry script, which lives in the installation |
|
|
119
|
+
| 3 | `process.execPath` | a launcher may omit the entry script entirely |
|
|
120
|
+
| 4 | fixed positions beside the executable | `<exe dir>/resources/app.asar/dsh`, `resources/app/dsh`, `app.asar.unpacked/dsh` |
|
|
121
|
+
|
|
122
|
+
The first release also failed here in a second way: `Config` is derived from the same
|
|
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.
|
|
125
|
+
|
|
126
|
+
If your layout is none of the above, point the variable at the directory that holds the
|
|
127
|
+
dsh package manifest and the plugin will use it:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
export DSH_INSTALL_ROOT="/opt/deepseek-harness/resources/app.asar/dsh"
|
|
131
|
+
```
|
|
132
|
+
|
|
59
133
|
## Configuration
|
|
60
134
|
|
|
61
135
|
Install the bundle, then set the subscription in **Settings → Clash proxy**.
|
|
@@ -96,6 +170,23 @@ One model-facing tool, `clash_proxy`:
|
|
|
96
170
|
- `test` — measure one node, or the current one
|
|
97
171
|
- `refresh` — re-download the subscription
|
|
98
172
|
|
|
173
|
+
## Verification
|
|
174
|
+
|
|
175
|
+
One judgement counts:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
curl -s http://127.0.0.1:<host port>/clash-proxy/status \
|
|
179
|
+
| grep -o '"routingVerified":"[a-z]*"'
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
- `active` — this plugin's dispatcher is live: outbound requests really go through it.
|
|
183
|
+
- `none` — no policy installed yet (no subscription, or `start` never ran).
|
|
184
|
+
- `lost` — something replaced the dispatcher afterwards (a restart, another plugin).
|
|
185
|
+
|
|
186
|
+
`routingVerified` compares undici's live global dispatcher with the instance this plugin
|
|
187
|
+
installed, so it cannot be satisfied by a flag. A successful `import`, or being able to
|
|
188
|
+
fetch a foreign host, is **not** sufficient proof on its own.
|
|
189
|
+
|
|
99
190
|
## Tests
|
|
100
191
|
|
|
101
192
|
```bash
|
|
@@ -122,6 +213,11 @@ direct.
|
|
|
122
213
|
- **Node quality is the subscription's.** Automatic selection measures latency once;
|
|
123
214
|
later congestion still needs a manual `select` or `test`.
|
|
124
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.
|
|
125
221
|
|
|
126
222
|
## License
|
|
127
223
|
|
package/index.js
CHANGED
|
@@ -131,6 +131,9 @@ export class Runtime {
|
|
|
131
131
|
this.config = config
|
|
132
132
|
this.log = logger
|
|
133
133
|
this.dataDir = resolveDataDir(config.dataDir)
|
|
134
|
+
/** Resolved once: the answer cannot change mid-process, and a stable value keeps
|
|
135
|
+
* `blocker` and `ensurePolicyModule` from disagreeing. */
|
|
136
|
+
this.installRoot = locateInstallRoot(process.argv)
|
|
134
137
|
this.binary = findCoreBinary(config.corePath)
|
|
135
138
|
this.core = this.binary === undefined ? undefined : new Core({ binary: this.binary, workDir: this.dataDir, logger })
|
|
136
139
|
this.routing = undefined
|
|
@@ -344,22 +347,45 @@ export class Runtime {
|
|
|
344
347
|
return String(this.config.node ?? '').trim()
|
|
345
348
|
}
|
|
346
349
|
|
|
347
|
-
/**
|
|
350
|
+
/**
|
|
351
|
+
* A one-line reason the runtime cannot start, or undefined when it can.
|
|
352
|
+
*
|
|
353
|
+
* The installation root is part of this list on purpose. The first release omitted it,
|
|
354
|
+
* so a packaged build whose layout the locator did not recognise kept `autoStart`
|
|
355
|
+
* firing on every boot and failing at the same throw — with `blocker` still reporting
|
|
356
|
+
* "ready" and the panel showing nothing but a stale lastError.
|
|
357
|
+
*/
|
|
348
358
|
get blocker() {
|
|
349
359
|
if (this.binary === undefined) {
|
|
350
360
|
return 'no mihomo core binary found: install Clash Verge or set corePath to a mihomo/clash executable'
|
|
351
361
|
}
|
|
362
|
+
if (this.installRoot === undefined) {
|
|
363
|
+
return 'cannot locate the dsh installation root: set DSH_INSTALL_ROOT to the directory holding the dsh package.json (a packaged build keeps it inside resources/app.asar)'
|
|
364
|
+
}
|
|
352
365
|
if (this.subscriptionUrl === '') {
|
|
353
366
|
return 'no subscription: paste a subscription URL in Settings → Clash proxy'
|
|
354
367
|
}
|
|
355
368
|
return undefined
|
|
356
369
|
}
|
|
357
370
|
|
|
358
|
-
/**
|
|
371
|
+
/**
|
|
372
|
+
* Load the shared policy module once, from the installation the host runs from.
|
|
373
|
+
*
|
|
374
|
+
* Resolution order lives in `lib/install.js`: an explicit environment variable, then
|
|
375
|
+
* the process arguments, then the executable path, then well-known positions beside
|
|
376
|
+
* the executable. A failure here is fatal for routing, so the message names the
|
|
377
|
+
* executable and the variable that fixes it rather than repeating "from the process
|
|
378
|
+
* arguments" — which was the only hint the first release offered, and it was wrong for
|
|
379
|
+
* every packaged build.
|
|
380
|
+
*/
|
|
359
381
|
async ensurePolicyModule() {
|
|
360
382
|
if (this.routing !== undefined) return this.routing
|
|
361
|
-
const root =
|
|
362
|
-
if (root === undefined)
|
|
383
|
+
const root = this.installRoot
|
|
384
|
+
if (root === undefined) {
|
|
385
|
+
throw new Error(
|
|
386
|
+
`cannot locate the dsh installation root: no known layout matched process.argv or ${process.execPath}; set DSH_INSTALL_ROOT to the directory holding the dsh package.json`,
|
|
387
|
+
)
|
|
388
|
+
}
|
|
363
389
|
const proxyModule = await loadHttpProxyModule(root)
|
|
364
390
|
const undiciPath = resolveFromInstall(root, 'undici')
|
|
365
391
|
this.log(`policy module from ${root} (${installName(root) ?? 'unnamed'})`)
|
|
@@ -535,6 +561,12 @@ export async function apply(ctx, rawConfig) {
|
|
|
535
561
|
}, 'clash-proxy: speed test cycle')
|
|
536
562
|
})
|
|
537
563
|
|
|
564
|
+
if (runtime.installRoot === undefined) {
|
|
565
|
+
// Say it once, at load: everything downstream (the panel, routing, the tool) needs
|
|
566
|
+
// this root, and a silent failure here is indistinguishable from "not configured".
|
|
567
|
+
log(`outbound policy unavailable: ${runtime.blocker}`)
|
|
568
|
+
}
|
|
569
|
+
|
|
538
570
|
if (config.autoStart === true && runtime.blocker === undefined) {
|
|
539
571
|
// Boot in the background: a slow subscription must not delay the Harness' own startup.
|
|
540
572
|
void runtime.start().catch((error) => {
|
package/lib/install.js
CHANGED
|
@@ -8,37 +8,125 @@
|
|
|
8
8
|
* same module instance the host loaded, which is what makes a proxy policy installed
|
|
9
9
|
* here visible to `ctx.web`, the LLM transports, and every spawned child.
|
|
10
10
|
*
|
|
11
|
+
* A packaged Desktop build nests the app package inside `resources/app.asar` (a single
|
|
12
|
+
* archive file the Electron runtime exposes as a directory), while a source checkout
|
|
13
|
+
* puts it at the checkout root. Neither shape is guaranteed, so the locator walks a
|
|
14
|
+
* candidate list instead of testing one hard-coded tail: mistaking the shape stops the
|
|
15
|
+
* whole chain before the core is ever spawned, and it does so silently.
|
|
16
|
+
*
|
|
11
17
|
* @module dsh-clash-proxy/install
|
|
12
18
|
*/
|
|
13
19
|
import { createRequire } from 'node:module'
|
|
14
20
|
import { existsSync, readFileSync } from 'node:fs'
|
|
15
|
-
import { join, normalize } from 'node:path'
|
|
21
|
+
import { dirname, join, normalize } from 'node:path'
|
|
16
22
|
import { pathToFileURL } from 'node:url'
|
|
17
23
|
|
|
18
|
-
/**
|
|
19
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Candidate installation-root tails inside one `argv` entry or an executable path.
|
|
26
|
+
*
|
|
27
|
+
* Order matters only for reporting; every entry is tried. `app.asar` must come first
|
|
28
|
+
* because a packaged build has no unpacked `app` directory, yet the string
|
|
29
|
+
* `/resources/app/dsh/` does not occur in its arguments, so the older tails simply miss.
|
|
30
|
+
*/
|
|
31
|
+
const INSTALL_TAILS = [
|
|
32
|
+
'resources/app.asar/dsh',
|
|
33
|
+
'app.asar/dsh',
|
|
34
|
+
'resources/app/dsh',
|
|
35
|
+
'app/dsh',
|
|
36
|
+
'resources/app.asar.unpacked/dsh',
|
|
37
|
+
'app.asar.unpacked/dsh',
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
/** Environment variables an operator may set to name the root explicitly. */
|
|
41
|
+
const INSTALL_ROOT_ENV = ['DSH_INSTALL_ROOT', 'DSH_APP_ROOT']
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Whether a directory really is a dsh app package.
|
|
45
|
+
*
|
|
46
|
+
* `package.json` presence is the only stable signature: it holds both the desktop
|
|
47
|
+
* runtime manifest and the `node_modules` the host boots from.
|
|
48
|
+
*
|
|
49
|
+
* @param candidate - directory to test.
|
|
50
|
+
* @returns true when the candidate holds a manifest.
|
|
51
|
+
*/
|
|
52
|
+
function isInstallRoot(candidate) {
|
|
53
|
+
if (typeof candidate !== 'string' || candidate === '') return false
|
|
54
|
+
try {
|
|
55
|
+
return existsSync(join(candidate, 'package.json'))
|
|
56
|
+
} catch {
|
|
57
|
+
return false
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Turn one path into the installation root it contains, if any.
|
|
63
|
+
*
|
|
64
|
+
* @param entry - argument, executable path, or directory to inspect.
|
|
65
|
+
* @returns the root ending in a known tail, or undefined.
|
|
66
|
+
*/
|
|
67
|
+
function rootFromPath(entry) {
|
|
68
|
+
if (typeof entry !== 'string' || entry === '') return undefined
|
|
69
|
+
const path = normalize(entry).replaceAll('\\', '/')
|
|
70
|
+
for (const tail of INSTALL_TAILS) {
|
|
71
|
+
const at = path.indexOf(`/${tail}/`)
|
|
72
|
+
if (at < 0) continue
|
|
73
|
+
const root = path.slice(0, at + tail.length + 1)
|
|
74
|
+
if (isInstallRoot(root)) return root
|
|
75
|
+
}
|
|
76
|
+
// An entry may end exactly at the tail (argv sometimes carries the directory).
|
|
77
|
+
for (const tail of INSTALL_TAILS) {
|
|
78
|
+
if (path.endsWith(`/${tail}`)) {
|
|
79
|
+
const root = `${path}/`
|
|
80
|
+
if (isInstallRoot(root)) return root
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return undefined
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Roots implied by an executable path, for a packaged Desktop build.
|
|
88
|
+
*
|
|
89
|
+
* @param executable - absolute path of the running executable.
|
|
90
|
+
* @returns candidate roots, whether or not they exist.
|
|
91
|
+
*/
|
|
92
|
+
function rootsFromExecutable(executable) {
|
|
93
|
+
if (typeof executable !== 'string' || executable === '') return []
|
|
94
|
+
const home = dirname(executable)
|
|
95
|
+
return [
|
|
96
|
+
join(home, 'resources', 'app.asar', 'dsh'),
|
|
97
|
+
join(home, 'resources', 'app', 'dsh'),
|
|
98
|
+
join(home, 'resources', 'app.asar.unpacked', 'dsh'),
|
|
99
|
+
]
|
|
100
|
+
}
|
|
20
101
|
|
|
21
102
|
/**
|
|
22
|
-
* Find the dsh installation root
|
|
103
|
+
* Find the dsh installation root.
|
|
23
104
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
105
|
+
* Four sources are tried in order, so a packaged build, an unpacked build, a source
|
|
106
|
+
* checkout and an exotic launcher all resolve:
|
|
107
|
+
*
|
|
108
|
+
* 1. an explicit `DSH_INSTALL_ROOT` / `DSH_APP_ROOT`;
|
|
109
|
+
* 2. a known tail inside any process argument (the host passes its own entry script);
|
|
110
|
+
* 3. a tail inside `process.execPath` (a launcher may omit its entry script);
|
|
111
|
+
* 4. well-known positions relative to the executable (packaged Desktop layout).
|
|
28
112
|
*
|
|
29
113
|
* @param argv - process argument list to inspect.
|
|
114
|
+
* @param executable - executable path; defaults to `process.execPath`.
|
|
30
115
|
* @returns the absolute installation root, or undefined when nothing matches.
|
|
31
116
|
*/
|
|
32
|
-
export function locateInstallRoot(argv) {
|
|
33
|
-
for (const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
117
|
+
export function locateInstallRoot(argv, executable = process.execPath) {
|
|
118
|
+
for (const name of INSTALL_ROOT_ENV) {
|
|
119
|
+
const value = process.env[name]
|
|
120
|
+
if (value !== undefined && isInstallRoot(value)) return normalize(value)
|
|
121
|
+
}
|
|
122
|
+
for (const entry of Array.isArray(argv) ? argv : []) {
|
|
123
|
+
const root = rootFromPath(entry)
|
|
124
|
+
if (root !== undefined) return root
|
|
125
|
+
}
|
|
126
|
+
const fromExe = rootFromPath(executable)
|
|
127
|
+
if (fromExe !== undefined) return fromExe
|
|
128
|
+
for (const candidate of rootsFromExecutable(executable)) {
|
|
129
|
+
if (isInstallRoot(candidate)) return candidate
|
|
42
130
|
}
|
|
43
131
|
return undefined
|
|
44
132
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-clash-subscription",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Import a Clash/mihomo subscription and route the Harness' outbound traffic through a private core, so blocked sites work while domestic traffic stays direct.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|
|
@@ -34,11 +34,6 @@
|
|
|
34
34
|
"engines": {
|
|
35
35
|
"node": ">=22"
|
|
36
36
|
},
|
|
37
|
-
"scripts": {
|
|
38
|
-
"test": "node test/unit.mjs",
|
|
39
|
-
"test:client": "node test/client-sim.mjs",
|
|
40
|
-
"test:e2e": "node test/e2e.mjs"
|
|
41
|
-
},
|
|
42
37
|
"dsh": {
|
|
43
38
|
"bundle": {
|
|
44
39
|
"patch": "./cordis.patch.yml"
|
|
@@ -64,5 +59,10 @@
|
|
|
64
59
|
"bugs": {
|
|
65
60
|
"url": "https://github.com/lc297948801/dsh-clash-subscription/issues"
|
|
66
61
|
},
|
|
67
|
-
"homepage": "https://github.com/lc297948801/dsh-clash-subscription#readme"
|
|
68
|
-
|
|
62
|
+
"homepage": "https://github.com/lc297948801/dsh-clash-subscription#readme",
|
|
63
|
+
"scripts": {
|
|
64
|
+
"test": "node test/unit.mjs",
|
|
65
|
+
"test:client": "node test/client-sim.mjs",
|
|
66
|
+
"test:e2e": "node test/e2e.mjs"
|
|
67
|
+
}
|
|
68
|
+
}
|