dsh-xdpool 3.0.8 → 3.0.9
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 +2451 -2432
- package/LICENSE +21 -21
- package/README.en.md +308 -308
- package/README.md +5 -21
- package/assets/community-qr-qq.jpg +0 -0
- package/assets/icon.png +0 -0
- package/assets/xdpool-banner.gif +0 -0
- package/cordis.patch.yml +24 -24
- package/lib/bin.js +356 -59
- package/lib/client.js +396 -172
- package/lib/index.d.ts +41 -9
- package/lib/index.js +948 -345
- package/package.json +1 -2
- package/screenshots.json +9 -9
- package/scripts/extract-design-css.mjs +322 -322
- package/scripts/link-host-peers.mjs +359 -359
- package/scripts/make-rail-icons.mjs +46 -46
- package/scripts/probe-channels.mjs +142 -142
- package/vendor/channel-pack/LICENSE +21 -21
- package/vendor/channel-pack/NOTICE.md +53 -53
- package/vendor/channel-pack/pack.js +30 -93
|
@@ -1,359 +1,359 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Link the host-provided peer dependencies into this package's node_modules.
|
|
3
|
-
*
|
|
4
|
-
* WHY THIS EXISTS
|
|
5
|
-
*
|
|
6
|
-
* Seven of this plugin's dependencies are `peerDependencies`: the host supplies them, not
|
|
7
|
-
* npm. A manual copy of the package into `node_modules/dsh-xdpool` resolved them by walking
|
|
8
|
-
* up into the host's tree, so nothing was ever missing. Installing normally breaks that
|
|
9
|
-
* walk, and a top-level import failure prevents `apply()` from ever running — so EVERY web
|
|
10
|
-
* route is unregistered and the card renders empty while blaming the gateway.
|
|
11
|
-
*
|
|
12
|
-
* WHAT IT MAY NOT DO: FAIL THE INSTALL
|
|
13
|
-
*
|
|
14
|
-
* The script links what it can find and then stops. It does not exit non-zero when the
|
|
15
|
-
* host cannot be located, for a reason that two bug reports made concrete:
|
|
16
|
-
*
|
|
17
|
-
* - A PACKAGED host keeps its dependencies inside `app.asar`, and `fs.existsSync` in a
|
|
18
|
-
* plain Node process cannot see inside an asar archive — only Electron's patched `fs`
|
|
19
|
-
* can. So "not found" from here often means "invisible to this process", not "absent".
|
|
20
|
-
* - The host resolves these peers itself at runtime. 2.6.3 shipped with no postinstall at
|
|
21
|
-
* all and loaded fine on macOS for exactly that reason.
|
|
22
|
-
*
|
|
23
|
-
* The previous version treated a failed probe as proof of a broken install and exited 1,
|
|
24
|
-
* which made the plugin manager roll back a working upgrade. That is the worst outcome
|
|
25
|
-
* available: the user loses the new version to protect against a problem they did not have.
|
|
26
|
-
*
|
|
27
|
-
* So the contract is now: link when the host is reachable, otherwise say what was not
|
|
28
|
-
* found and finish successfully. Only an actual failure to CREATE a link is reported, and
|
|
29
|
-
* even then as a warning — the plugin may still load through the host's own resolution.
|
|
30
|
-
*
|
|
31
|
-
* HOW RESOLUTION IS CHECKED
|
|
32
|
-
*
|
|
33
|
-
* With ESM, not CJS. `@earendil-works/pi-ai` is ESM-only: its `exports` map has `types` and
|
|
34
|
-
* `import` but no `require` and no `./package.json` subpath. A `require.resolve()` of it
|
|
35
|
-
* throws ERR_PACKAGE_PATH_NOT_EXPORTED even when the package is installed and importable,
|
|
36
|
-
* which is precisely the false negative the reporter hit. `import.meta.resolve` asks the
|
|
37
|
-
* question the plugin will actually ask.
|
|
38
|
-
*
|
|
39
|
-
* @module dsh-xdpool/scripts/link-host-peers
|
|
40
|
-
*/
|
|
41
|
-
import { existsSync, mkdirSync, readFileSync, rmSync, symlinkSync } from 'node:fs'
|
|
42
|
-
import { dirname, join, resolve } from 'node:path'
|
|
43
|
-
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
44
|
-
|
|
45
|
-
const HERE = dirname(fileURLToPath(import.meta.url))
|
|
46
|
-
const PACKAGE_ROOT = resolve(HERE, '..')
|
|
47
|
-
const ENTRY_URL = pathToFileURL(join(PACKAGE_ROOT, 'lib', 'index.js')).href
|
|
48
|
-
|
|
49
|
-
/** The peer dependencies this plugin imports at runtime. */
|
|
50
|
-
function peerNames() {
|
|
51
|
-
const manifest = JSON.parse(readFileSync(join(PACKAGE_ROOT, 'package.json'), 'utf8'))
|
|
52
|
-
return Object.keys(manifest.peerDependencies ?? {})
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Can the plugin resolve `name` from its own entry point?
|
|
57
|
-
*
|
|
58
|
-
* `import.meta.resolve` answers with ESM conditions, which is what the plugin uses. It
|
|
59
|
-
* never throws for a missing package in current Node — it returns a URL that may not
|
|
60
|
-
* exist — so the answer is checked for existence as well.
|
|
61
|
-
*
|
|
62
|
-
* A `data:` or `node:` result is not a real package file and is treated as unresolved.
|
|
63
|
-
*/
|
|
64
|
-
function resolvesFromEntry(name) {
|
|
65
|
-
try {
|
|
66
|
-
const url = import.meta.resolve(name, ENTRY_URL)
|
|
67
|
-
if (typeof url !== 'string' || url === '') return undefined
|
|
68
|
-
if (url.startsWith('node:') || url.startsWith('data:')) return undefined
|
|
69
|
-
return fileURLToPath(url)
|
|
70
|
-
} catch {
|
|
71
|
-
return undefined
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** The installed version of a package directory, or undefined when unreadable. */
|
|
76
|
-
function versionOf(dir) {
|
|
77
|
-
try {
|
|
78
|
-
const manifest = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'))
|
|
79
|
-
return typeof manifest.version === 'string' ? manifest.version : undefined
|
|
80
|
-
} catch {
|
|
81
|
-
return undefined
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* The host's copy of a peer, if one can be found.
|
|
87
|
-
*
|
|
88
|
-
* Separate from `locate` because the two answer different questions: `locate` asks "is this
|
|
89
|
-
* importable", `hostCopyOf` asks "where is the host's own copy". The second is needed to
|
|
90
|
-
* detect a version MISMATCH, which is a failure mode `locate` cannot see — the package
|
|
91
|
-
* resolves perfectly well at the wrong generation.
|
|
92
|
-
*/
|
|
93
|
-
function hostCopyOf(name) {
|
|
94
|
-
for (const root of hostRoots()) {
|
|
95
|
-
const candidate = join(root, name)
|
|
96
|
-
if (existsSync(join(candidate, 'package.json'))) return candidate
|
|
97
|
-
}
|
|
98
|
-
return undefined
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* The package directory for `name`, whether or not it can be imported right now.
|
|
103
|
-
*
|
|
104
|
-
* The physical check comes FIRST because it is the only one that works for an ESM-only
|
|
105
|
-
* package whose `exports` map omits `./package.json`: `require.resolve(`${name}/package.json`)`
|
|
106
|
-
* throws ERR_PACKAGE_PATH_NOT_EXPORTED for `pi-ai` even with the package sitting on disk.
|
|
107
|
-
* That false negative used to send an already-linked peer back into the missing list, so a
|
|
108
|
-
* second `postinstall` run re-linked what it had just built.
|
|
109
|
-
*/
|
|
110
|
-
function locate(name) {
|
|
111
|
-
// 1. On disk under this package's own node_modules — a junction we made earlier counts.
|
|
112
|
-
const physical = join(PACKAGE_ROOT, 'node_modules', name)
|
|
113
|
-
if (existsSync(join(physical, 'package.json'))) return physical
|
|
114
|
-
// 2. Whatever ESM resolves from the entry, which is the real question.
|
|
115
|
-
const resolved = resolvesFromEntry(name)
|
|
116
|
-
if (resolved !== undefined) {
|
|
117
|
-
// Walk up to the package root: the first directory named like the package.
|
|
118
|
-
const wanted = name.startsWith('@') ? name.split('/')[1] : name
|
|
119
|
-
let dir = dirname(resolved)
|
|
120
|
-
while (dir !== dirname(dir)) {
|
|
121
|
-
if (dir.endsWith(`/${wanted}`) || dir.endsWith(`\\${wanted}`)) return dir
|
|
122
|
-
dir = dirname(dir)
|
|
123
|
-
}
|
|
124
|
-
return dirname(resolved)
|
|
125
|
-
}
|
|
126
|
-
return undefined
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Candidate host module roots.
|
|
131
|
-
*
|
|
132
|
-
* The host SPLITS its tree — `cordis` and the `@deepseek-ai/*` runtime in one place,
|
|
133
|
-
* `pi-ai` in another — so several roots are tried rather than one.
|
|
134
|
-
*
|
|
135
|
-
* `DSH_HOST_ROOT` is honoured when set, but note it is NOT injected by the host: two
|
|
136
|
-
* reporters verified that the plugin manager does not pass it. It exists for an operator
|
|
137
|
-
* who wants to point at a specific tree by hand.
|
|
138
|
-
*
|
|
139
|
-
* On a packaged install most of this is unverifiable from a plain Node process, because the
|
|
140
|
-
* dependencies live inside `app.asar` and `existsSync` cannot see in. That is expected and
|
|
141
|
-
* is why a miss is not an error.
|
|
142
|
-
*/
|
|
143
|
-
function hostRoots() {
|
|
144
|
-
const roots = []
|
|
145
|
-
const env = process.env['DSH_HOST_ROOT']
|
|
146
|
-
if (typeof env === 'string' && env !== '') roots.push(env)
|
|
147
|
-
// When the host loads the plugin from inside its own tree.
|
|
148
|
-
roots.push(resolve(PACKAGE_ROOT, '..'))
|
|
149
|
-
roots.push(resolve(PACKAGE_ROOT, '..', '..', '..'))
|
|
150
|
-
/**
|
|
151
|
-
* Derived from the running executable, which is the only signal that survives a
|
|
152
|
-
* non-default install drive — the reporter's harness sat on `F:` while every hard-coded
|
|
153
|
-
* guess pointed at `C:`. `process.execPath` is the Node or Electron binary doing the
|
|
154
|
-
* install, which for the bundled runtime lives inside the harness directory.
|
|
155
|
-
*/
|
|
156
|
-
for (const up of [1, 2, 3, 4, 5]) {
|
|
157
|
-
const segments = [process.execPath]
|
|
158
|
-
for (let i = 0; i < up; i += 1) segments.push('..')
|
|
159
|
-
const base = resolve(...segments)
|
|
160
|
-
for (const app of ['app', join('app', 'dsh')]) {
|
|
161
|
-
roots.push(join(base, 'resources', app, 'node_modules'))
|
|
162
|
-
}
|
|
163
|
-
roots.push(join(base, 'node_modules'))
|
|
164
|
-
}
|
|
165
|
-
for (const base of HARNESS_BASES) {
|
|
166
|
-
if (typeof base !== 'string' || base === '') continue
|
|
167
|
-
for (const app of ['app', join('app', 'dsh')]) {
|
|
168
|
-
roots.push(join(base, 'resources', app, 'node_modules'))
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
return [...new Set(roots)]
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Where a DSH install commonly sits, per platform.
|
|
176
|
-
*
|
|
177
|
-
* Every entry is a guess and a miss is silent, which is what makes listing several
|
|
178
|
-
* acceptable. `HARNESS_BASES` used to be Windows-only — the macOS reporter's whole
|
|
179
|
-
* `LOCALAPPDATA`/`PROGRAMFILES` loop simply never ran.
|
|
180
|
-
*/
|
|
181
|
-
const HARNESS_BASES = [
|
|
182
|
-
process.env['DSH_HARNESS_ROOT'],
|
|
183
|
-
// macOS: /Applications/DeepSeek Harness.app/Contents/Resources
|
|
184
|
-
'/Applications/DeepSeek Harness.app/Contents/Resources',
|
|
185
|
-
join(process.env['HOME'] ?? '', 'Applications', 'DeepSeek Harness.app', 'Contents', 'Resources'),
|
|
186
|
-
// Linux
|
|
187
|
-
join(process.env['HOME'] ?? '', '.local', 'share', 'deepseek-harness'),
|
|
188
|
-
'/opt/DeepSeek Harness',
|
|
189
|
-
// Windows, default locations
|
|
190
|
-
typeof process.env['LOCALAPPDATA'] === 'string' ? join(process.env['LOCALAPPDATA'], 'Programs', 'DeepSeek Harness') : undefined,
|
|
191
|
-
typeof process.env['LOCALAPPDATA'] === 'string' ? join(process.env['LOCALAPPDATA'], 'DeepSeek Harness') : undefined,
|
|
192
|
-
typeof process.env['ProgramW6432'] === 'string' ? process.env['ProgramW6432'] : undefined,
|
|
193
|
-
typeof process.env['PROGRAMFILES'] === 'string' ? process.env['PROGRAMFILES'] : undefined,
|
|
194
|
-
/**
|
|
195
|
-
* Windows, installed on another drive.
|
|
196
|
-
*
|
|
197
|
-
* Not a guess about this particular machine: it is derived from where the PROFILE lives.
|
|
198
|
-
* A DSH profile sits at `<harness data dir>/profiles/<name>`, and on Windows the data
|
|
199
|
-
* directory is often the harness's own folder — which is exactly the layout this repo
|
|
200
|
-
* was developed against (`<data>\profiles\desktop` beside `<install>`).
|
|
201
|
-
* When they are siblings, the harness is one segment up with a different name, so the
|
|
202
|
-
* sibling of the data dir is tried as a harness root too.
|
|
203
|
-
*
|
|
204
|
-
* A miss costs nothing, which is why deriving is preferable to hard-coding a drive letter.
|
|
205
|
-
*/
|
|
206
|
-
...siblingHarnessBases(),
|
|
207
|
-
]
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Harness roots that can be derived from where this profile lives.
|
|
211
|
-
*
|
|
212
|
-
* `<data>\profiles\desktop\node_modules\dsh-xdpool` → walk up to the data directory,
|
|
213
|
-
* then try every plausible sibling. Cheap, and it is the only way to find a harness on a
|
|
214
|
-
* non-default drive without asking the user to set an environment variable.
|
|
215
|
-
*
|
|
216
|
-
* Several levels are tried because the two layouts in the wild differ:
|
|
217
|
-
*
|
|
218
|
-
* - `<dataDir>/profiles/<name>` — the data dir's PARENT holds the harness
|
|
219
|
-
* (`<data>` beside `<install>`)
|
|
220
|
-
* - the harness IS the data dir's parent — some installs put profiles inside the app
|
|
221
|
-
*
|
|
222
|
-
* A miss costs nothing, which is why deriving beats hard-coding a drive letter.
|
|
223
|
-
*/
|
|
224
|
-
function siblingHarnessBases() {
|
|
225
|
-
const out = []
|
|
226
|
-
let dir = PACKAGE_ROOT
|
|
227
|
-
let dataDir
|
|
228
|
-
for (let i = 0; i < 8; i += 1) {
|
|
229
|
-
dir = dirname(dir)
|
|
230
|
-
if (dir === dirname(dir)) break
|
|
231
|
-
// `<x>/profiles/...` means `<x>` is the data directory.
|
|
232
|
-
if (dirname(dir).endsWith('profiles')) { dataDir = dirname(dir); break }
|
|
233
|
-
if (dir.endsWith('profiles')) { dataDir = dirname(dir); break }
|
|
234
|
-
}
|
|
235
|
-
const start = dataDir ?? resolve(PACKAGE_ROOT, '..', '..', '..')
|
|
236
|
-
// Walk up a few levels from the data directory, offering a sibling at each.
|
|
237
|
-
let cursor = start
|
|
238
|
-
for (let i = 0; i < 3; i += 1) {
|
|
239
|
-
out.push(join(cursor, 'DeepSeek Harness'))
|
|
240
|
-
const parent = dirname(cursor)
|
|
241
|
-
if (parent === cursor) break
|
|
242
|
-
out.push(join(parent, 'DeepSeek Harness'))
|
|
243
|
-
cursor = parent
|
|
244
|
-
}
|
|
245
|
-
return out
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/** Whether this is a source checkout rather than an installed package. */
|
|
249
|
-
const IS_SOURCE_CHECKOUT = existsSync(join(PACKAGE_ROOT, 'src'))
|
|
250
|
-
|
|
251
|
-
const linked = []
|
|
252
|
-
const alreadyResolved = []
|
|
253
|
-
const notFound = []
|
|
254
|
-
const failed = []
|
|
255
|
-
|
|
256
|
-
for (const name of peerNames()) {
|
|
257
|
-
/**
|
|
258
|
-
* A peer that resolves is only acceptable if its VERSION matches the host's.
|
|
259
|
-
*
|
|
260
|
-
* Resolvability alone is not the contract that matters. `@earendil-works/pi-ai` shipped
|
|
261
|
-
* from a `devDependency` at 0.85.1 while the host ran 1.1.0, and the plugin's own
|
|
262
|
-
* `warnOnPiAiGenerationMismatch` documents the result: two copies on one call chain throw
|
|
263
|
-
* at the adapter seam and the host reports every turn as a non-retryable `PI_AI_ERROR`.
|
|
264
|
-
* The package resolved fine — at the wrong generation.
|
|
265
|
-
*
|
|
266
|
-
* So when the host has a copy and ours differs, the host's copy WINS. That is the whole
|
|
267
|
-
* point of treating these as peer dependencies: the host owns them, and a second
|
|
268
|
-
* generation beside it is a defect rather than a choice.
|
|
269
|
-
*/
|
|
270
|
-
const current = locate(name)
|
|
271
|
-
const hostCopy = hostCopyOf(name)
|
|
272
|
-
const hostVersion = hostCopy === undefined ? undefined : versionOf(hostCopy)
|
|
273
|
-
const ours = current === undefined ? undefined : versionOf(current)
|
|
274
|
-
if (current !== undefined && (hostVersion === undefined || ours === hostVersion)) {
|
|
275
|
-
alreadyResolved.push(name)
|
|
276
|
-
continue
|
|
277
|
-
}
|
|
278
|
-
// A mismatch is reported below through `relinked` when the host copy is linked.
|
|
279
|
-
let target = hostCopy
|
|
280
|
-
if (target === undefined) {
|
|
281
|
-
for (const root of hostRoots()) {
|
|
282
|
-
const candidate = join(root, name)
|
|
283
|
-
// `existsSync` cannot see inside `app.asar`; on a packaged host this simply misses and
|
|
284
|
-
// the peer is reported as not found, which is no longer fatal.
|
|
285
|
-
if (existsSync(join(candidate, 'package.json'))) { target = candidate; break }
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
if (target === undefined) { notFound.push(name); continue }
|
|
289
|
-
const dest = join(PACKAGE_ROOT, 'node_modules', name)
|
|
290
|
-
try {
|
|
291
|
-
mkdirSync(dirname(dest), { recursive: true })
|
|
292
|
-
// A previous run may have left a link (or a partial one); replacing it is correct
|
|
293
|
-
// because the resolve check above already skipped anything that works.
|
|
294
|
-
if (existsSync(dest)) rmSync(dest, { recursive: true, force: true })
|
|
295
|
-
// Junction on Windows because creating a real symlink needs elevation there; a
|
|
296
|
-
// junction needs none and behaves the same for directory reads.
|
|
297
|
-
symlinkSync(target, dest, process.platform === 'win32' ? 'junction' : 'dir')
|
|
298
|
-
linked.push(`${name} → ${target}${ours === undefined ? '' : ` (was ${ours}, host has ${hostVersion ?? '?'})`}`)
|
|
299
|
-
} catch (error) {
|
|
300
|
-
failed.push(`${name} (${error instanceof Error ? error.message : String(error)})`)
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
if (linked.length > 0) {
|
|
305
|
-
process.stdout.write(`dsh-xdpool: linked ${String(linked.length)} host dependency(ies)\n`)
|
|
306
|
-
for (const line of linked) process.stdout.write(` ${line}\n`)
|
|
307
|
-
}
|
|
308
|
-
if (alreadyResolved.length > 0 && linked.length === 0) {
|
|
309
|
-
process.stdout.write(`dsh-xdpool: all ${String(alreadyResolved.length)} peer dependencies already resolve\n`)
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* Report, and deliberately do not fail.
|
|
314
|
-
*
|
|
315
|
-
* A packaged host hides these inside `app.asar` (invisible to a bare Node process) and
|
|
316
|
-
* resolves them itself at runtime — 2.6.3 shipped with no postinstall and loaded fine. So
|
|
317
|
-
* "not found from here" is not evidence of a broken install, and exiting non-zero on it
|
|
318
|
-
* rolled back working upgrades for macOS and Windows users alike.
|
|
319
|
-
*/
|
|
320
|
-
if (notFound.length > 0) {
|
|
321
|
-
process.stdout.write(
|
|
322
|
-
`dsh-xdpool: ${String(notFound.length)} peer dependency(ies) not visible from this process:\n`
|
|
323
|
-
+ notFound.map(name => ` ${name}\n`).join('')
|
|
324
|
-
+ (IS_SOURCE_CHECKOUT
|
|
325
|
-
? 'Expected in a source checkout: build and test resolve them from devDependencies.\n'
|
|
326
|
-
: 'This is normal for a packaged host, which keeps them inside app.asar and resolves\n'
|
|
327
|
-
+ 'them itself at runtime. Set DSH_HOST_ROOT to a directory containing node_modules\n'
|
|
328
|
-
+ 'only if the plugin later fails to load.\n'),
|
|
329
|
-
)
|
|
330
|
-
}
|
|
331
|
-
if (failed.length > 0) {
|
|
332
|
-
// A link that could not be CREATED is a real problem, but still not fatal: the host may
|
|
333
|
-
// resolve the peer without our help. Worth a warning, not a rollback.
|
|
334
|
-
process.stdout.write(
|
|
335
|
-
`dsh-xdpool: could not link ${String(failed.length)} dependency(ies):\n`
|
|
336
|
-
+ failed.map(name => ` ${name}\n`).join(''),
|
|
337
|
-
)
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Final self-check, phrased as the plugin would phrase it.
|
|
342
|
-
*
|
|
343
|
-
* Uses ESM resolution rather than CJS: `pi-ai` is ESM-only with no `require` condition and
|
|
344
|
-
* no `./package.json` subpath, so a `require.resolve` of it throws
|
|
345
|
-
* ERR_PACKAGE_PATH_NOT_EXPORTED while the package sits there fully importable. That false
|
|
346
|
-
* negative is what made 2.6.4 uninstallable on Windows.
|
|
347
|
-
*
|
|
348
|
-
* An unresolved peer is reported and the script still exits 0, for the asar reason above.
|
|
349
|
-
*/
|
|
350
|
-
const unresolved = peerNames().filter(name => locate(name) === undefined)
|
|
351
|
-
if (unresolved.length === 0) {
|
|
352
|
-
process.stdout.write('dsh-xdpool: all peer dependencies resolve; the build should load\n')
|
|
353
|
-
} else {
|
|
354
|
-
process.stdout.write(
|
|
355
|
-
`dsh-xdpool: ${String(unresolved.length)} peer dependency(ies) do not resolve here: `
|
|
356
|
-
+ `${unresolved.join(', ')}\n`
|
|
357
|
-
+ ' Not treated as an install failure — see the note above.\n',
|
|
358
|
-
)
|
|
359
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Link the host-provided peer dependencies into this package's node_modules.
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS EXISTS
|
|
5
|
+
*
|
|
6
|
+
* Seven of this plugin's dependencies are `peerDependencies`: the host supplies them, not
|
|
7
|
+
* npm. A manual copy of the package into `node_modules/dsh-xdpool` resolved them by walking
|
|
8
|
+
* up into the host's tree, so nothing was ever missing. Installing normally breaks that
|
|
9
|
+
* walk, and a top-level import failure prevents `apply()` from ever running — so EVERY web
|
|
10
|
+
* route is unregistered and the card renders empty while blaming the gateway.
|
|
11
|
+
*
|
|
12
|
+
* WHAT IT MAY NOT DO: FAIL THE INSTALL
|
|
13
|
+
*
|
|
14
|
+
* The script links what it can find and then stops. It does not exit non-zero when the
|
|
15
|
+
* host cannot be located, for a reason that two bug reports made concrete:
|
|
16
|
+
*
|
|
17
|
+
* - A PACKAGED host keeps its dependencies inside `app.asar`, and `fs.existsSync` in a
|
|
18
|
+
* plain Node process cannot see inside an asar archive — only Electron's patched `fs`
|
|
19
|
+
* can. So "not found" from here often means "invisible to this process", not "absent".
|
|
20
|
+
* - The host resolves these peers itself at runtime. 2.6.3 shipped with no postinstall at
|
|
21
|
+
* all and loaded fine on macOS for exactly that reason.
|
|
22
|
+
*
|
|
23
|
+
* The previous version treated a failed probe as proof of a broken install and exited 1,
|
|
24
|
+
* which made the plugin manager roll back a working upgrade. That is the worst outcome
|
|
25
|
+
* available: the user loses the new version to protect against a problem they did not have.
|
|
26
|
+
*
|
|
27
|
+
* So the contract is now: link when the host is reachable, otherwise say what was not
|
|
28
|
+
* found and finish successfully. Only an actual failure to CREATE a link is reported, and
|
|
29
|
+
* even then as a warning — the plugin may still load through the host's own resolution.
|
|
30
|
+
*
|
|
31
|
+
* HOW RESOLUTION IS CHECKED
|
|
32
|
+
*
|
|
33
|
+
* With ESM, not CJS. `@earendil-works/pi-ai` is ESM-only: its `exports` map has `types` and
|
|
34
|
+
* `import` but no `require` and no `./package.json` subpath. A `require.resolve()` of it
|
|
35
|
+
* throws ERR_PACKAGE_PATH_NOT_EXPORTED even when the package is installed and importable,
|
|
36
|
+
* which is precisely the false negative the reporter hit. `import.meta.resolve` asks the
|
|
37
|
+
* question the plugin will actually ask.
|
|
38
|
+
*
|
|
39
|
+
* @module dsh-xdpool/scripts/link-host-peers
|
|
40
|
+
*/
|
|
41
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, symlinkSync } from 'node:fs'
|
|
42
|
+
import { dirname, join, resolve } from 'node:path'
|
|
43
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
44
|
+
|
|
45
|
+
const HERE = dirname(fileURLToPath(import.meta.url))
|
|
46
|
+
const PACKAGE_ROOT = resolve(HERE, '..')
|
|
47
|
+
const ENTRY_URL = pathToFileURL(join(PACKAGE_ROOT, 'lib', 'index.js')).href
|
|
48
|
+
|
|
49
|
+
/** The peer dependencies this plugin imports at runtime. */
|
|
50
|
+
function peerNames() {
|
|
51
|
+
const manifest = JSON.parse(readFileSync(join(PACKAGE_ROOT, 'package.json'), 'utf8'))
|
|
52
|
+
return Object.keys(manifest.peerDependencies ?? {})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Can the plugin resolve `name` from its own entry point?
|
|
57
|
+
*
|
|
58
|
+
* `import.meta.resolve` answers with ESM conditions, which is what the plugin uses. It
|
|
59
|
+
* never throws for a missing package in current Node — it returns a URL that may not
|
|
60
|
+
* exist — so the answer is checked for existence as well.
|
|
61
|
+
*
|
|
62
|
+
* A `data:` or `node:` result is not a real package file and is treated as unresolved.
|
|
63
|
+
*/
|
|
64
|
+
function resolvesFromEntry(name) {
|
|
65
|
+
try {
|
|
66
|
+
const url = import.meta.resolve(name, ENTRY_URL)
|
|
67
|
+
if (typeof url !== 'string' || url === '') return undefined
|
|
68
|
+
if (url.startsWith('node:') || url.startsWith('data:')) return undefined
|
|
69
|
+
return fileURLToPath(url)
|
|
70
|
+
} catch {
|
|
71
|
+
return undefined
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The installed version of a package directory, or undefined when unreadable. */
|
|
76
|
+
function versionOf(dir) {
|
|
77
|
+
try {
|
|
78
|
+
const manifest = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'))
|
|
79
|
+
return typeof manifest.version === 'string' ? manifest.version : undefined
|
|
80
|
+
} catch {
|
|
81
|
+
return undefined
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The host's copy of a peer, if one can be found.
|
|
87
|
+
*
|
|
88
|
+
* Separate from `locate` because the two answer different questions: `locate` asks "is this
|
|
89
|
+
* importable", `hostCopyOf` asks "where is the host's own copy". The second is needed to
|
|
90
|
+
* detect a version MISMATCH, which is a failure mode `locate` cannot see — the package
|
|
91
|
+
* resolves perfectly well at the wrong generation.
|
|
92
|
+
*/
|
|
93
|
+
function hostCopyOf(name) {
|
|
94
|
+
for (const root of hostRoots()) {
|
|
95
|
+
const candidate = join(root, name)
|
|
96
|
+
if (existsSync(join(candidate, 'package.json'))) return candidate
|
|
97
|
+
}
|
|
98
|
+
return undefined
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The package directory for `name`, whether or not it can be imported right now.
|
|
103
|
+
*
|
|
104
|
+
* The physical check comes FIRST because it is the only one that works for an ESM-only
|
|
105
|
+
* package whose `exports` map omits `./package.json`: `require.resolve(`${name}/package.json`)`
|
|
106
|
+
* throws ERR_PACKAGE_PATH_NOT_EXPORTED for `pi-ai` even with the package sitting on disk.
|
|
107
|
+
* That false negative used to send an already-linked peer back into the missing list, so a
|
|
108
|
+
* second `postinstall` run re-linked what it had just built.
|
|
109
|
+
*/
|
|
110
|
+
function locate(name) {
|
|
111
|
+
// 1. On disk under this package's own node_modules — a junction we made earlier counts.
|
|
112
|
+
const physical = join(PACKAGE_ROOT, 'node_modules', name)
|
|
113
|
+
if (existsSync(join(physical, 'package.json'))) return physical
|
|
114
|
+
// 2. Whatever ESM resolves from the entry, which is the real question.
|
|
115
|
+
const resolved = resolvesFromEntry(name)
|
|
116
|
+
if (resolved !== undefined) {
|
|
117
|
+
// Walk up to the package root: the first directory named like the package.
|
|
118
|
+
const wanted = name.startsWith('@') ? name.split('/')[1] : name
|
|
119
|
+
let dir = dirname(resolved)
|
|
120
|
+
while (dir !== dirname(dir)) {
|
|
121
|
+
if (dir.endsWith(`/${wanted}`) || dir.endsWith(`\\${wanted}`)) return dir
|
|
122
|
+
dir = dirname(dir)
|
|
123
|
+
}
|
|
124
|
+
return dirname(resolved)
|
|
125
|
+
}
|
|
126
|
+
return undefined
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Candidate host module roots.
|
|
131
|
+
*
|
|
132
|
+
* The host SPLITS its tree — `cordis` and the `@deepseek-ai/*` runtime in one place,
|
|
133
|
+
* `pi-ai` in another — so several roots are tried rather than one.
|
|
134
|
+
*
|
|
135
|
+
* `DSH_HOST_ROOT` is honoured when set, but note it is NOT injected by the host: two
|
|
136
|
+
* reporters verified that the plugin manager does not pass it. It exists for an operator
|
|
137
|
+
* who wants to point at a specific tree by hand.
|
|
138
|
+
*
|
|
139
|
+
* On a packaged install most of this is unverifiable from a plain Node process, because the
|
|
140
|
+
* dependencies live inside `app.asar` and `existsSync` cannot see in. That is expected and
|
|
141
|
+
* is why a miss is not an error.
|
|
142
|
+
*/
|
|
143
|
+
function hostRoots() {
|
|
144
|
+
const roots = []
|
|
145
|
+
const env = process.env['DSH_HOST_ROOT']
|
|
146
|
+
if (typeof env === 'string' && env !== '') roots.push(env)
|
|
147
|
+
// When the host loads the plugin from inside its own tree.
|
|
148
|
+
roots.push(resolve(PACKAGE_ROOT, '..'))
|
|
149
|
+
roots.push(resolve(PACKAGE_ROOT, '..', '..', '..'))
|
|
150
|
+
/**
|
|
151
|
+
* Derived from the running executable, which is the only signal that survives a
|
|
152
|
+
* non-default install drive — the reporter's harness sat on `F:` while every hard-coded
|
|
153
|
+
* guess pointed at `C:`. `process.execPath` is the Node or Electron binary doing the
|
|
154
|
+
* install, which for the bundled runtime lives inside the harness directory.
|
|
155
|
+
*/
|
|
156
|
+
for (const up of [1, 2, 3, 4, 5]) {
|
|
157
|
+
const segments = [process.execPath]
|
|
158
|
+
for (let i = 0; i < up; i += 1) segments.push('..')
|
|
159
|
+
const base = resolve(...segments)
|
|
160
|
+
for (const app of ['app', join('app', 'dsh')]) {
|
|
161
|
+
roots.push(join(base, 'resources', app, 'node_modules'))
|
|
162
|
+
}
|
|
163
|
+
roots.push(join(base, 'node_modules'))
|
|
164
|
+
}
|
|
165
|
+
for (const base of HARNESS_BASES) {
|
|
166
|
+
if (typeof base !== 'string' || base === '') continue
|
|
167
|
+
for (const app of ['app', join('app', 'dsh')]) {
|
|
168
|
+
roots.push(join(base, 'resources', app, 'node_modules'))
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return [...new Set(roots)]
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Where a DSH install commonly sits, per platform.
|
|
176
|
+
*
|
|
177
|
+
* Every entry is a guess and a miss is silent, which is what makes listing several
|
|
178
|
+
* acceptable. `HARNESS_BASES` used to be Windows-only — the macOS reporter's whole
|
|
179
|
+
* `LOCALAPPDATA`/`PROGRAMFILES` loop simply never ran.
|
|
180
|
+
*/
|
|
181
|
+
const HARNESS_BASES = [
|
|
182
|
+
process.env['DSH_HARNESS_ROOT'],
|
|
183
|
+
// macOS: /Applications/DeepSeek Harness.app/Contents/Resources
|
|
184
|
+
'/Applications/DeepSeek Harness.app/Contents/Resources',
|
|
185
|
+
join(process.env['HOME'] ?? '', 'Applications', 'DeepSeek Harness.app', 'Contents', 'Resources'),
|
|
186
|
+
// Linux
|
|
187
|
+
join(process.env['HOME'] ?? '', '.local', 'share', 'deepseek-harness'),
|
|
188
|
+
'/opt/DeepSeek Harness',
|
|
189
|
+
// Windows, default locations
|
|
190
|
+
typeof process.env['LOCALAPPDATA'] === 'string' ? join(process.env['LOCALAPPDATA'], 'Programs', 'DeepSeek Harness') : undefined,
|
|
191
|
+
typeof process.env['LOCALAPPDATA'] === 'string' ? join(process.env['LOCALAPPDATA'], 'DeepSeek Harness') : undefined,
|
|
192
|
+
typeof process.env['ProgramW6432'] === 'string' ? process.env['ProgramW6432'] : undefined,
|
|
193
|
+
typeof process.env['PROGRAMFILES'] === 'string' ? process.env['PROGRAMFILES'] : undefined,
|
|
194
|
+
/**
|
|
195
|
+
* Windows, installed on another drive.
|
|
196
|
+
*
|
|
197
|
+
* Not a guess about this particular machine: it is derived from where the PROFILE lives.
|
|
198
|
+
* A DSH profile sits at `<harness data dir>/profiles/<name>`, and on Windows the data
|
|
199
|
+
* directory is often the harness's own folder — which is exactly the layout this repo
|
|
200
|
+
* was developed against (`<data>\profiles\desktop` beside `<install>`).
|
|
201
|
+
* When they are siblings, the harness is one segment up with a different name, so the
|
|
202
|
+
* sibling of the data dir is tried as a harness root too.
|
|
203
|
+
*
|
|
204
|
+
* A miss costs nothing, which is why deriving is preferable to hard-coding a drive letter.
|
|
205
|
+
*/
|
|
206
|
+
...siblingHarnessBases(),
|
|
207
|
+
]
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Harness roots that can be derived from where this profile lives.
|
|
211
|
+
*
|
|
212
|
+
* `<data>\profiles\desktop\node_modules\dsh-xdpool` → walk up to the data directory,
|
|
213
|
+
* then try every plausible sibling. Cheap, and it is the only way to find a harness on a
|
|
214
|
+
* non-default drive without asking the user to set an environment variable.
|
|
215
|
+
*
|
|
216
|
+
* Several levels are tried because the two layouts in the wild differ:
|
|
217
|
+
*
|
|
218
|
+
* - `<dataDir>/profiles/<name>` — the data dir's PARENT holds the harness
|
|
219
|
+
* (`<data>` beside `<install>`)
|
|
220
|
+
* - the harness IS the data dir's parent — some installs put profiles inside the app
|
|
221
|
+
*
|
|
222
|
+
* A miss costs nothing, which is why deriving beats hard-coding a drive letter.
|
|
223
|
+
*/
|
|
224
|
+
function siblingHarnessBases() {
|
|
225
|
+
const out = []
|
|
226
|
+
let dir = PACKAGE_ROOT
|
|
227
|
+
let dataDir
|
|
228
|
+
for (let i = 0; i < 8; i += 1) {
|
|
229
|
+
dir = dirname(dir)
|
|
230
|
+
if (dir === dirname(dir)) break
|
|
231
|
+
// `<x>/profiles/...` means `<x>` is the data directory.
|
|
232
|
+
if (dirname(dir).endsWith('profiles')) { dataDir = dirname(dir); break }
|
|
233
|
+
if (dir.endsWith('profiles')) { dataDir = dirname(dir); break }
|
|
234
|
+
}
|
|
235
|
+
const start = dataDir ?? resolve(PACKAGE_ROOT, '..', '..', '..')
|
|
236
|
+
// Walk up a few levels from the data directory, offering a sibling at each.
|
|
237
|
+
let cursor = start
|
|
238
|
+
for (let i = 0; i < 3; i += 1) {
|
|
239
|
+
out.push(join(cursor, 'DeepSeek Harness'))
|
|
240
|
+
const parent = dirname(cursor)
|
|
241
|
+
if (parent === cursor) break
|
|
242
|
+
out.push(join(parent, 'DeepSeek Harness'))
|
|
243
|
+
cursor = parent
|
|
244
|
+
}
|
|
245
|
+
return out
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** Whether this is a source checkout rather than an installed package. */
|
|
249
|
+
const IS_SOURCE_CHECKOUT = existsSync(join(PACKAGE_ROOT, 'src'))
|
|
250
|
+
|
|
251
|
+
const linked = []
|
|
252
|
+
const alreadyResolved = []
|
|
253
|
+
const notFound = []
|
|
254
|
+
const failed = []
|
|
255
|
+
|
|
256
|
+
for (const name of peerNames()) {
|
|
257
|
+
/**
|
|
258
|
+
* A peer that resolves is only acceptable if its VERSION matches the host's.
|
|
259
|
+
*
|
|
260
|
+
* Resolvability alone is not the contract that matters. `@earendil-works/pi-ai` shipped
|
|
261
|
+
* from a `devDependency` at 0.85.1 while the host ran 1.1.0, and the plugin's own
|
|
262
|
+
* `warnOnPiAiGenerationMismatch` documents the result: two copies on one call chain throw
|
|
263
|
+
* at the adapter seam and the host reports every turn as a non-retryable `PI_AI_ERROR`.
|
|
264
|
+
* The package resolved fine — at the wrong generation.
|
|
265
|
+
*
|
|
266
|
+
* So when the host has a copy and ours differs, the host's copy WINS. That is the whole
|
|
267
|
+
* point of treating these as peer dependencies: the host owns them, and a second
|
|
268
|
+
* generation beside it is a defect rather than a choice.
|
|
269
|
+
*/
|
|
270
|
+
const current = locate(name)
|
|
271
|
+
const hostCopy = hostCopyOf(name)
|
|
272
|
+
const hostVersion = hostCopy === undefined ? undefined : versionOf(hostCopy)
|
|
273
|
+
const ours = current === undefined ? undefined : versionOf(current)
|
|
274
|
+
if (current !== undefined && (hostVersion === undefined || ours === hostVersion)) {
|
|
275
|
+
alreadyResolved.push(name)
|
|
276
|
+
continue
|
|
277
|
+
}
|
|
278
|
+
// A mismatch is reported below through `relinked` when the host copy is linked.
|
|
279
|
+
let target = hostCopy
|
|
280
|
+
if (target === undefined) {
|
|
281
|
+
for (const root of hostRoots()) {
|
|
282
|
+
const candidate = join(root, name)
|
|
283
|
+
// `existsSync` cannot see inside `app.asar`; on a packaged host this simply misses and
|
|
284
|
+
// the peer is reported as not found, which is no longer fatal.
|
|
285
|
+
if (existsSync(join(candidate, 'package.json'))) { target = candidate; break }
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (target === undefined) { notFound.push(name); continue }
|
|
289
|
+
const dest = join(PACKAGE_ROOT, 'node_modules', name)
|
|
290
|
+
try {
|
|
291
|
+
mkdirSync(dirname(dest), { recursive: true })
|
|
292
|
+
// A previous run may have left a link (or a partial one); replacing it is correct
|
|
293
|
+
// because the resolve check above already skipped anything that works.
|
|
294
|
+
if (existsSync(dest)) rmSync(dest, { recursive: true, force: true })
|
|
295
|
+
// Junction on Windows because creating a real symlink needs elevation there; a
|
|
296
|
+
// junction needs none and behaves the same for directory reads.
|
|
297
|
+
symlinkSync(target, dest, process.platform === 'win32' ? 'junction' : 'dir')
|
|
298
|
+
linked.push(`${name} → ${target}${ours === undefined ? '' : ` (was ${ours}, host has ${hostVersion ?? '?'})`}`)
|
|
299
|
+
} catch (error) {
|
|
300
|
+
failed.push(`${name} (${error instanceof Error ? error.message : String(error)})`)
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (linked.length > 0) {
|
|
305
|
+
process.stdout.write(`dsh-xdpool: linked ${String(linked.length)} host dependency(ies)\n`)
|
|
306
|
+
for (const line of linked) process.stdout.write(` ${line}\n`)
|
|
307
|
+
}
|
|
308
|
+
if (alreadyResolved.length > 0 && linked.length === 0) {
|
|
309
|
+
process.stdout.write(`dsh-xdpool: all ${String(alreadyResolved.length)} peer dependencies already resolve\n`)
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Report, and deliberately do not fail.
|
|
314
|
+
*
|
|
315
|
+
* A packaged host hides these inside `app.asar` (invisible to a bare Node process) and
|
|
316
|
+
* resolves them itself at runtime — 2.6.3 shipped with no postinstall and loaded fine. So
|
|
317
|
+
* "not found from here" is not evidence of a broken install, and exiting non-zero on it
|
|
318
|
+
* rolled back working upgrades for macOS and Windows users alike.
|
|
319
|
+
*/
|
|
320
|
+
if (notFound.length > 0) {
|
|
321
|
+
process.stdout.write(
|
|
322
|
+
`dsh-xdpool: ${String(notFound.length)} peer dependency(ies) not visible from this process:\n`
|
|
323
|
+
+ notFound.map(name => ` ${name}\n`).join('')
|
|
324
|
+
+ (IS_SOURCE_CHECKOUT
|
|
325
|
+
? 'Expected in a source checkout: build and test resolve them from devDependencies.\n'
|
|
326
|
+
: 'This is normal for a packaged host, which keeps them inside app.asar and resolves\n'
|
|
327
|
+
+ 'them itself at runtime. Set DSH_HOST_ROOT to a directory containing node_modules\n'
|
|
328
|
+
+ 'only if the plugin later fails to load.\n'),
|
|
329
|
+
)
|
|
330
|
+
}
|
|
331
|
+
if (failed.length > 0) {
|
|
332
|
+
// A link that could not be CREATED is a real problem, but still not fatal: the host may
|
|
333
|
+
// resolve the peer without our help. Worth a warning, not a rollback.
|
|
334
|
+
process.stdout.write(
|
|
335
|
+
`dsh-xdpool: could not link ${String(failed.length)} dependency(ies):\n`
|
|
336
|
+
+ failed.map(name => ` ${name}\n`).join(''),
|
|
337
|
+
)
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Final self-check, phrased as the plugin would phrase it.
|
|
342
|
+
*
|
|
343
|
+
* Uses ESM resolution rather than CJS: `pi-ai` is ESM-only with no `require` condition and
|
|
344
|
+
* no `./package.json` subpath, so a `require.resolve` of it throws
|
|
345
|
+
* ERR_PACKAGE_PATH_NOT_EXPORTED while the package sits there fully importable. That false
|
|
346
|
+
* negative is what made 2.6.4 uninstallable on Windows.
|
|
347
|
+
*
|
|
348
|
+
* An unresolved peer is reported and the script still exits 0, for the asar reason above.
|
|
349
|
+
*/
|
|
350
|
+
const unresolved = peerNames().filter(name => locate(name) === undefined)
|
|
351
|
+
if (unresolved.length === 0) {
|
|
352
|
+
process.stdout.write('dsh-xdpool: all peer dependencies resolve; the build should load\n')
|
|
353
|
+
} else {
|
|
354
|
+
process.stdout.write(
|
|
355
|
+
`dsh-xdpool: ${String(unresolved.length)} peer dependency(ies) do not resolve here: `
|
|
356
|
+
+ `${unresolved.join(', ')}\n`
|
|
357
|
+
+ ' Not treated as an install failure — see the note above.\n',
|
|
358
|
+
)
|
|
359
|
+
}
|