dsh-claude-project-ui 0.4.3 → 0.5.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.md +100 -0
- package/README.md +259 -61
- package/THIRD_PARTY_NOTICES.md +71 -0
- package/docs/about-drafts.md +27 -55
- package/docs/dsh-threads-baseline.md +119 -0
- package/docs/optional-threads-0.4.4.md +139 -0
- package/docs/store-copy-0.4.4.md +86 -0
- package/docs/two-installs-problem.md +256 -0
- package/docs/vendoring-feasibility.md +179 -0
- package/package.json +54 -5
- package/src/client.js +4689 -9
- package/src/config.js +3 -0
- package/src/index.js +276 -3
- package/src/threads-install.js +174 -0
- package/src/threads-probe.js +255 -0
- package/src/threads-vendor.js +123 -0
- package/vendor/dsh-threads/CHANGELOG.md +174 -0
- package/vendor/dsh-threads/LICENSE +21 -0
- package/vendor/dsh-threads/README.en.md +113 -0
- package/vendor/dsh-threads/README.md +113 -0
- package/vendor/dsh-threads/VENDORED.md +66 -0
- package/vendor/dsh-threads/cordis.patch.yml +6 -0
- package/vendor/dsh-threads/dist/client.js +4260 -0
- package/vendor/dsh-threads/dist/index.js +2773 -0
- package/vendor/dsh-threads/icon.svg +1 -0
- package/vendor/dsh-threads/locale/en.json +6 -0
- package/vendor/dsh-threads/locale/zh.json +6 -0
- package/vendor/dsh-threads/package.json +122 -0
package/src/config.js
CHANGED
|
@@ -4,6 +4,9 @@ export const DEFAULTS = {
|
|
|
4
4
|
dataDir: "",
|
|
5
5
|
/** dsh-threads storage file, read only, to learn which sessions belong to which project. */
|
|
6
6
|
threadsStorage: "",
|
|
7
|
+
/** Profile root used to read which dsh-threads version is installed (the panel only
|
|
8
|
+
* warns when it differs from the verified baseline). Empty = ~/.dsh/profiles. */
|
|
9
|
+
threadsProfilesDir: "",
|
|
7
10
|
/** DSH workspace storage file, written only when switching a project's main folder.
|
|
8
11
|
* Empty = workspace.json next to threadsStorage. */
|
|
9
12
|
workspaceStorage: "",
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { appendFileSync, mkdirSync } from "node:fs";
|
|
1
|
+
import { appendFileSync, existsSync, mkdirSync } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
4
5
|
import { resolveConfig } from "./config.js";
|
|
5
6
|
import { defaultThreadsStorage, projectActivity, ProjectRegistry } from "./project.js";
|
|
6
7
|
import { ProjectStore } from "./store.js";
|
|
@@ -27,6 +28,19 @@ import { loadSettings, saveSettings } from "./settings.js";
|
|
|
27
28
|
import { kbIndexText, loadKb, loadKbSync } from "./kb.js";
|
|
28
29
|
import { boardContextText, boardView, convergeThreads, loadBoard, loadBoardSync } from "./board.js";
|
|
29
30
|
import { digestText, eventsOf, loadNotes, loadNotesSync } from "./digest.js";
|
|
31
|
+
import { probeThreads, profileInstallState, readInstalledVersion, registrySignal, threadsCapability } from "./threads-probe.js";
|
|
32
|
+
import { installThreads, threadsInstallPlan } from "./threads-install.js";
|
|
33
|
+
import {
|
|
34
|
+
OWNER_UNKNOWN,
|
|
35
|
+
OWNER_UPSTREAM,
|
|
36
|
+
OWNER_VENDORED,
|
|
37
|
+
VENDORED_THREADS_COMMIT,
|
|
38
|
+
VENDORED_THREADS_CONFIG,
|
|
39
|
+
VENDORED_THREADS_VERSION,
|
|
40
|
+
loadVendoredThreads,
|
|
41
|
+
profileDependencyState,
|
|
42
|
+
vendorDecision
|
|
43
|
+
} from "./threads-vendor.js";
|
|
30
44
|
|
|
31
45
|
export const name = "dsh-claude-project-ui";
|
|
32
46
|
// webServer is declared because Cordis refuses `ctx.get("webServer")` / `ctx.webServer`
|
|
@@ -85,6 +99,20 @@ function lookupService(scope, serviceName) {
|
|
|
85
99
|
}
|
|
86
100
|
}
|
|
87
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Cordis mixes its plugin registry into every context as a plain property, so
|
|
104
|
+
* this needs no `inject` entry and a host that does not expose it (tests, a
|
|
105
|
+
* foreign runtime) simply yields `undefined` instead of keeping the plugin
|
|
106
|
+
* pending.
|
|
107
|
+
*/
|
|
108
|
+
function lookupRegistry(scope) {
|
|
109
|
+
try {
|
|
110
|
+
return scope?.registry;
|
|
111
|
+
} catch {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
88
116
|
export async function apply(ctx, config) {
|
|
89
117
|
breadcrumb("apply start");
|
|
90
118
|
const resolved = resolveConfig(config);
|
|
@@ -103,7 +131,22 @@ export async function apply(ctx, config) {
|
|
|
103
131
|
// The storage-domain facility (see src/mainfolder.js): a main-folder switch
|
|
104
132
|
// must go through the domain handle dsh-threads and DSH already opened, or the
|
|
105
133
|
// next write from either of them overwrites it. Absent => file fallback.
|
|
106
|
-
storageDomain: () => lookupService(ctx, "storageDomain")
|
|
134
|
+
storageDomain: () => lookupService(ctx, "storageDomain"),
|
|
135
|
+
// dsh-threads is optional: the panel must be able to say "not installed"
|
|
136
|
+
// instead of "no projects yet". Read lazily, on every snapshot, so a profile
|
|
137
|
+
// that installs or disables it needs no reload of this plugin (src/threads-probe.js).
|
|
138
|
+
threads: () =>
|
|
139
|
+
probeThreads({
|
|
140
|
+
storageDomain: lookupService(ctx, "storageDomain"),
|
|
141
|
+
registry: lookupRegistry(ctx)
|
|
142
|
+
}),
|
|
143
|
+
// The DSH plugin manager (@deepseek-ai/dsh-plugin-manager): the service the in-app
|
|
144
|
+
// plugin market and `dsh plugin add` both go through. Read lazily and never
|
|
145
|
+
// injected — a host without it (headless, an older DSH) must keep loading this
|
|
146
|
+
// plugin, and the panel shows the manual path instead of an install button.
|
|
147
|
+
pluginManager: () => lookupService(ctx, "pluginManager"),
|
|
148
|
+
// The running profile's directory and name: what the manager would write into.
|
|
149
|
+
profileContext: () => lookupService(ctx, "profileContext")
|
|
107
150
|
};
|
|
108
151
|
|
|
109
152
|
// Panel preferences (this plugin's own file, never dsh-threads' storage). The
|
|
@@ -132,12 +175,71 @@ export async function apply(ctx, config) {
|
|
|
132
175
|
}
|
|
133
176
|
};
|
|
134
177
|
|
|
178
|
+
// ---- the vendored discussion-thread half (vendor/dsh-threads) ----
|
|
179
|
+
//
|
|
180
|
+
// One package, a complete experience: this package carries
|
|
181
|
+
// @kyf-eng/dsh-threads@0.2.0 itself instead of asking the user to install it.
|
|
182
|
+
// The decision is taken once, before anything opens `dsh_threads`: when the
|
|
183
|
+
// real package is enabled in this profile we yield and never touch the domain,
|
|
184
|
+
// because a second owner is DomainError('already-open') at best and a duplicate
|
|
185
|
+
// UI at worst (docs/vendoring-feasibility.md). An unreadable profile yields too.
|
|
186
|
+
const vendor = { decision: null, mounted: false, error: null };
|
|
187
|
+
/** The running profile's directory; "" when it cannot be named (the decision then yields). */
|
|
188
|
+
const profileDir = () => {
|
|
189
|
+
const known = runtime.profileContext();
|
|
190
|
+
if (typeof known?.dir === "string" && known.dir.length > 0) return known.dir;
|
|
191
|
+
// Fallback: the loader points baseUrl at the directory of the config file it
|
|
192
|
+
// is running, which for a profile IS the profile directory.
|
|
193
|
+
try {
|
|
194
|
+
const base = ctx.baseUrl;
|
|
195
|
+
if (typeof base === "string" && base.length > 0) return fileURLToPath(base);
|
|
196
|
+
} catch {
|
|
197
|
+
// still nothing: "unknown" below makes the decision yield
|
|
198
|
+
}
|
|
199
|
+
return "";
|
|
200
|
+
};
|
|
201
|
+
try {
|
|
202
|
+
vendor.decision = vendorDecision({
|
|
203
|
+
profile: profileDependencyState(profileDir()),
|
|
204
|
+
domainOpen: runtime.storageDomain()?.get?.("dsh_threads") !== undefined,
|
|
205
|
+
runtimeRegistered: registrySignal(lookupRegistry(ctx))
|
|
206
|
+
});
|
|
207
|
+
} catch (error) {
|
|
208
|
+
vendor.decision = { mount: false, owner: OWNER_UNKNOWN, reason: "probe-failed" };
|
|
209
|
+
warn("cannot decide whether to mount the vendored dsh-threads: " + String(error));
|
|
210
|
+
}
|
|
211
|
+
if (vendor.decision.mount === true) {
|
|
212
|
+
// Lazy import: a profile that runs the real package never reads these bytes,
|
|
213
|
+
// and a broken copy degrades to "no thread half" instead of failing us.
|
|
214
|
+
try {
|
|
215
|
+
ctx.plugin(await loadVendoredThreads(), VENDORED_THREADS_CONFIG);
|
|
216
|
+
vendor.mounted = true;
|
|
217
|
+
info("vendored @kyf-eng/dsh-threads " + VENDORED_THREADS_VERSION + " mounted (" + vendor.decision.reason + ")");
|
|
218
|
+
breadcrumb("vendored threads mounted: " + vendor.decision.reason);
|
|
219
|
+
} catch (error) {
|
|
220
|
+
vendor.error = error;
|
|
221
|
+
warn("the vendored dsh-threads did not mount: " + String(error));
|
|
222
|
+
breadcrumb("vendored threads failed: " + String(error));
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
info("discussion threads come from the installed @kyf-eng/dsh-threads (" + vendor.decision.reason + ")");
|
|
226
|
+
breadcrumb("vendored threads yielded: " + vendor.decision.reason);
|
|
227
|
+
}
|
|
228
|
+
/** Who owns the thread half right now — the board says this instead of guessing. */
|
|
229
|
+
const threadsOwner = () => {
|
|
230
|
+
if (vendor.mounted) return OWNER_VENDORED;
|
|
231
|
+
if (vendor.decision?.owner === OWNER_UPSTREAM) return OWNER_UPSTREAM;
|
|
232
|
+
// Mounted-to-be but the import failed: nothing owns it.
|
|
233
|
+
return OWNER_UNKNOWN;
|
|
234
|
+
};
|
|
235
|
+
|
|
135
236
|
// ---- browser half: read-only JSON the board panel fetches ----
|
|
136
237
|
// Registered on the web server when this profile has one (the web GUI does).
|
|
137
238
|
// Optional on purpose: headless / tui profiles load this plugin too.
|
|
138
239
|
const BOARD_ROUTE = "/project-hub/board";
|
|
139
240
|
const FOLDERS_ROUTE = "/project-hub/folders";
|
|
140
241
|
const SETTINGS_ROUTE = "/project-hub/settings";
|
|
242
|
+
const THREADS_INSTALL_ROUTE = "/project-hub/threads-install";
|
|
141
243
|
const readBody = (req) =>
|
|
142
244
|
new Promise((resolve, reject) => {
|
|
143
245
|
let size = 0;
|
|
@@ -157,6 +259,25 @@ export async function apply(ctx, config) {
|
|
|
157
259
|
|
|
158
260
|
const workspaceFile = () =>
|
|
159
261
|
resolved.workspaceStorage.trim().length > 0 ? resolved.workspaceStorage : defaultWorkspaceStorage(registry.path);
|
|
262
|
+
/**
|
|
263
|
+
* What the panel's install button would do (src/threads-install.js).
|
|
264
|
+
*
|
|
265
|
+
* Computed on every snapshot and on every install response: the profile
|
|
266
|
+
* manifest changes under us, and a cached answer would either hide the button
|
|
267
|
+
* after a successful install or show it again after a manual one.
|
|
268
|
+
*/
|
|
269
|
+
const threadsInstallSnapshot = () => {
|
|
270
|
+
const profile = runtime.profileContext();
|
|
271
|
+
return threadsInstallPlan({
|
|
272
|
+
manager: runtime.pluginManager(),
|
|
273
|
+
profile: typeof profile?.name === "string" ? profile.name : "",
|
|
274
|
+
...profileInstallState(typeof profile?.dir === "string" ? profile.dir : "")
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
/** One POST per install; a second click while pnpm runs is a duplicate, not a retry. */
|
|
279
|
+
let installInFlight = false;
|
|
280
|
+
|
|
160
281
|
/** The whole panel's data, plus which project the requesting session belongs to. */
|
|
161
282
|
const boardSnapshot = async (sessionId) => {
|
|
162
283
|
const projects = await registry.projects();
|
|
@@ -207,14 +328,39 @@ export async function apply(ctx, config) {
|
|
|
207
328
|
await listWorkspaces(workspaceFile()),
|
|
208
329
|
out.map((project) => ({ ...project, extraFolderCount: project.extraFolders.length }))
|
|
209
330
|
);
|
|
331
|
+
// Whether the optional board provider is here at all. Three panel states hang
|
|
332
|
+
// off this (see boardState() in src/client.js): "dsh-threads missing",
|
|
333
|
+
// "installed but no projects", "normal board". A host without dsh-threads
|
|
334
|
+
// still gets projects/settings/workspaces — nothing else in this route reads it.
|
|
335
|
+
// Which release is installed, best effort: only the profile running this
|
|
336
|
+
// plugin is considered, and an unreadable answer stays null (no remark).
|
|
337
|
+
// Where the thread half comes from: our own vendored copy, the user's installed
|
|
338
|
+
// package, or neither. The panel needs this to explain a missing board instead
|
|
339
|
+
// of blaming the wrong package (see boardState() in src/client.js).
|
|
340
|
+
const owner = threadsOwner();
|
|
341
|
+
const installedVersion = readInstalledVersion({ profilesDir: resolved.threadsProfilesDir.trim() });
|
|
342
|
+
const threads = threadsCapability(runtime.threads(), {
|
|
343
|
+
projects: out.length,
|
|
344
|
+
// Corroboration only, never a signal: the file also survives an uninstall.
|
|
345
|
+
storageFile: existsSync(registry.path),
|
|
346
|
+
// A vendored copy has no npm record in the profile, so it reports its own
|
|
347
|
+
// version — the panel then knows it was checked against the baseline.
|
|
348
|
+
version: owner === OWNER_VENDORED ? VENDORED_THREADS_VERSION : installedVersion.version,
|
|
349
|
+
owner,
|
|
350
|
+
reason: vendor.decision?.reason ?? null
|
|
351
|
+
});
|
|
210
352
|
return {
|
|
211
353
|
projects: out,
|
|
212
354
|
workspaces,
|
|
213
355
|
currentProjectId,
|
|
356
|
+
threads,
|
|
214
357
|
// The panel renders itself from these, so a toggle takes effect on the very
|
|
215
358
|
// next snapshot without a restart.
|
|
216
359
|
settings: currentPreferences(),
|
|
217
|
-
sandbox: { available: runtime.sandboxAvailable() }
|
|
360
|
+
sandbox: { available: runtime.sandboxAvailable() },
|
|
361
|
+
// The optional second install: what a click would do, and what to paste
|
|
362
|
+
// instead when this host cannot do it (src/threads-install.js).
|
|
363
|
+
install: threadsInstallSnapshot()
|
|
218
364
|
};
|
|
219
365
|
};
|
|
220
366
|
|
|
@@ -261,6 +407,58 @@ export async function apply(ctx, config) {
|
|
|
261
407
|
breadcrumb("route failed: " + String(error));
|
|
262
408
|
}
|
|
263
409
|
|
|
410
|
+
// ---- who owns the discussion threads (the browser half's gate) ----
|
|
411
|
+
//
|
|
412
|
+
// The client bundle carries both halves, so it has to ask before it mounts the
|
|
413
|
+
// vendored one: "vendored" means mount, anything else means leave the thread
|
|
414
|
+
// tabs to whoever owns them. A deliberately tiny route, because the panel asks
|
|
415
|
+
// once at page load and must not pay for a full snapshot just to learn this.
|
|
416
|
+
const RUNTIME_ROUTE = "/project-hub/runtime";
|
|
417
|
+
try {
|
|
418
|
+
const webServer = ctx.webServer;
|
|
419
|
+
if (webServer !== undefined && webServer !== null && typeof webServer.register === "function") {
|
|
420
|
+
const off = webServer.register({
|
|
421
|
+
kind: "exact",
|
|
422
|
+
path: RUNTIME_ROUTE,
|
|
423
|
+
handler: async (req, res) => {
|
|
424
|
+
try {
|
|
425
|
+
const owner = threadsOwner();
|
|
426
|
+
const threads = runtime.threads();
|
|
427
|
+
res.writeHead(200, { "content-type": "application/json; charset=utf-8" });
|
|
428
|
+
res.end(
|
|
429
|
+
JSON.stringify({
|
|
430
|
+
ok: true,
|
|
431
|
+
threads: {
|
|
432
|
+
owner,
|
|
433
|
+
reason: vendor.decision?.reason ?? null,
|
|
434
|
+
// `installed` is the live probe: "a provider is running now". The
|
|
435
|
+
// board's own payload adds the project count and the storage
|
|
436
|
+
// corroboration on top of it.
|
|
437
|
+
installed: owner === OWNER_VENDORED || threads.installed === true,
|
|
438
|
+
version: owner === OWNER_VENDORED ? VENDORED_THREADS_VERSION : null
|
|
439
|
+
},
|
|
440
|
+
vendored: {
|
|
441
|
+
version: VENDORED_THREADS_VERSION,
|
|
442
|
+
commit: VENDORED_THREADS_COMMIT,
|
|
443
|
+
mounted: vendor.mounted,
|
|
444
|
+
error: vendor.error === null ? null : String(vendor.error?.message ?? vendor.error)
|
|
445
|
+
}
|
|
446
|
+
})
|
|
447
|
+
);
|
|
448
|
+
} catch (error) {
|
|
449
|
+
res.writeHead(500, { "content-type": "application/json; charset=utf-8" });
|
|
450
|
+
res.end(JSON.stringify({ ok: false, error: String(error?.message ?? error) }));
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
if (typeof off === "function") ctx.effect?.(() => off, "dsh-claude-project-ui: runtime route");
|
|
455
|
+
breadcrumb("runtime route registered at " + RUNTIME_ROUTE);
|
|
456
|
+
}
|
|
457
|
+
} catch (error) {
|
|
458
|
+
warn("cannot register the runtime route: " + String(error));
|
|
459
|
+
breadcrumb("runtime route failed: " + String(error));
|
|
460
|
+
}
|
|
461
|
+
|
|
264
462
|
// ---- mounts: add / remove an auxiliary folder (the panel's only write path) ----
|
|
265
463
|
try {
|
|
266
464
|
const webServer = ctx.webServer;
|
|
@@ -426,6 +624,81 @@ export async function apply(ctx, config) {
|
|
|
426
624
|
breadcrumb("settings route failed: " + String(error));
|
|
427
625
|
}
|
|
428
626
|
|
|
627
|
+
// ---- the optional second install: one click installs/enables dsh-threads ----
|
|
628
|
+
//
|
|
629
|
+
// This is the whole point of src/threads-install.js: the same Cordis service the
|
|
630
|
+
// in-app plugin market uses, called from our own panel, so a user who installed
|
|
631
|
+
// only this package can get the provider without leaving the page. Nothing here
|
|
632
|
+
// writes the profile: DSH's installBundle does the pnpm add, appends
|
|
633
|
+
// dsh.profile.bundles, reloads through HMR, and restores package.json +
|
|
634
|
+
// pnpm-lock.yaml if the run fails.
|
|
635
|
+
try {
|
|
636
|
+
const webServer = ctx.webServer;
|
|
637
|
+
if (webServer !== undefined && webServer !== null && typeof webServer.register === "function") {
|
|
638
|
+
const off = webServer.register({
|
|
639
|
+
kind: "exact",
|
|
640
|
+
path: THREADS_INSTALL_ROUTE,
|
|
641
|
+
handler: async (req, res) => {
|
|
642
|
+
const reply = (status, payload) => {
|
|
643
|
+
res.writeHead(status, { "content-type": "application/json; charset=utf-8" });
|
|
644
|
+
res.end(JSON.stringify(payload));
|
|
645
|
+
};
|
|
646
|
+
try {
|
|
647
|
+
if (req.method !== "POST") return reply(405, { ok: false, code: "method", error: "只支持 POST" });
|
|
648
|
+
// Same non-simple-request guard as the other two write routes.
|
|
649
|
+
if (req.headers["x-project-hub"] !== "1") {
|
|
650
|
+
return reply(403, { ok: false, code: "header", error: "缺少 x-project-hub 请求头" });
|
|
651
|
+
}
|
|
652
|
+
await readBody(req);
|
|
653
|
+
if (installInFlight) {
|
|
654
|
+
return reply(409, { ok: false, code: "busy", error: "另一次安装正在进行", install: threadsInstallSnapshot() });
|
|
655
|
+
}
|
|
656
|
+
installInFlight = true;
|
|
657
|
+
let outcome;
|
|
658
|
+
try {
|
|
659
|
+
const profile = runtime.profileContext();
|
|
660
|
+
const dir = typeof profile?.dir === "string" ? profile.dir : "";
|
|
661
|
+
outcome = await installThreads({
|
|
662
|
+
manager: runtime.pluginManager(),
|
|
663
|
+
profile: typeof profile?.name === "string" ? profile.name : "",
|
|
664
|
+
state: profileInstallState(dir)
|
|
665
|
+
});
|
|
666
|
+
} finally {
|
|
667
|
+
installInFlight = false;
|
|
668
|
+
}
|
|
669
|
+
// The snapshot is recomputed here: the panel gets the new state with the
|
|
670
|
+
// answer instead of guessing it, and a manual install from the terminal
|
|
671
|
+
// shows up on the next click too.
|
|
672
|
+
const install = threadsInstallSnapshot();
|
|
673
|
+
if (outcome.code === "no-api") return reply(501, { ...outcome, install });
|
|
674
|
+
if (outcome.ok !== true) {
|
|
675
|
+
warn("threads install failed: " + String(outcome.code ?? "") + " " + String(outcome.message ?? ""));
|
|
676
|
+
return reply(400, { ...outcome, install });
|
|
677
|
+
}
|
|
678
|
+
info("threads install: " + outcome.action + " -> " + String(outcome.application ?? ""));
|
|
679
|
+
breadcrumb("threads install " + outcome.action + " " + String(outcome.application ?? ""));
|
|
680
|
+
// dsh-threads' own rows just started; the next sweep picks its domain
|
|
681
|
+
// handle up, so the board can show real projects without a reload.
|
|
682
|
+
try {
|
|
683
|
+
syncAll();
|
|
684
|
+
} catch {
|
|
685
|
+
// a failed sweep is not an install failure
|
|
686
|
+
}
|
|
687
|
+
return reply(200, { ...outcome, install });
|
|
688
|
+
} catch (error) {
|
|
689
|
+
reply(400, { ok: false, code: "operation-error", error: String(error?.message ?? error) });
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
if (typeof off === "function") ctx.effect?.(() => off, "dsh-claude-project-ui: threads install route");
|
|
694
|
+
info("dsh-threads install route at " + THREADS_INSTALL_ROUTE);
|
|
695
|
+
breadcrumb("threads install route at " + THREADS_INSTALL_ROUTE);
|
|
696
|
+
}
|
|
697
|
+
} catch (error) {
|
|
698
|
+
warn("cannot register the threads install route: " + String(error));
|
|
699
|
+
breadcrumb("threads install route failed: " + String(error));
|
|
700
|
+
}
|
|
701
|
+
|
|
429
702
|
/** sessionId -> { kb, board, digest, folders } prompt text, read synchronously by the host. */
|
|
430
703
|
const textCache = new Map();
|
|
431
704
|
/** agent -> disposer for its sections and tools. */
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { THREADS_BUNDLE } from "./threads-probe.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One-click install of the optional dsh-threads bundle.
|
|
5
|
+
*
|
|
6
|
+
* Why this file exists: this plugin's board is built on top of
|
|
7
|
+
* @kyf-eng/dsh-threads, which is deliberately NOT a dependency of this package
|
|
8
|
+
* (a user's own copy, at their own version, must win). Installing THIS plugin
|
|
9
|
+
* therefore never installs dsh-threads, and the two-install surprise became the
|
|
10
|
+
* single biggest drop-off for new users. DSH itself already ships the whole
|
|
11
|
+
* install path as a Cordis service - the same one the in-app plugin market and
|
|
12
|
+
* the `dsh plugin add` CLI go through - so the panel only has to call it.
|
|
13
|
+
*
|
|
14
|
+
* The service is `pluginManager` (@deepseek-ai/dsh-plugin-manager): the base
|
|
15
|
+
* bundle mounts it for every profile-based host, and it is NOT declared in this
|
|
16
|
+
* plugin's `inject` on purpose - a host without it (headless, an older DSH) must
|
|
17
|
+
* keep working, so it is read lazily per request and its absence is a state the
|
|
18
|
+
* panel shows, not an error. See docs/two-installs-problem.md for the evidence.
|
|
19
|
+
*
|
|
20
|
+
* Three states, decided from the profile's own manifest, not from the running
|
|
21
|
+
* process (a bundle can be installed yet not selected, which is exactly the case
|
|
22
|
+
* "install twice" gets wrong):
|
|
23
|
+
*
|
|
24
|
+
* install no dependency on dsh-threads -> pluginManager.installBundle(spec)
|
|
25
|
+
* (pnpm add + save the dependency + append dsh.profile.bundles + reload)
|
|
26
|
+
* enable dependency saved, not selected -> pluginManager.setBundleEnabled(name, true)
|
|
27
|
+
* (append dsh.profile.bundles + reload; no package manager, no network)
|
|
28
|
+
* done saved AND selected -> nothing to do; a restart is the
|
|
29
|
+
* only remaining step if it still is not loaded in this process
|
|
30
|
+
*
|
|
31
|
+
* Nothing here writes the profile itself: DSH owns that file, and its own
|
|
32
|
+
* installBundle restores package.json + pnpm-lock.yaml when a run fails. Writing
|
|
33
|
+
* it from here would race the running process and lose that rollback.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/** The pinned fork tag: same bytes as npm 0.2.0, but a source upstream cannot move. */
|
|
37
|
+
export const THREADS_PIN_SPEC = "github:lanechenhku/dsh-threads#v0.2.0-baseline";
|
|
38
|
+
|
|
39
|
+
/** The tag alone, for copy that has to fit in one line. */
|
|
40
|
+
export const THREADS_PIN_TAG = "v0.2.0-baseline";
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The terminal command that installs the pinned build, or null when there is none.
|
|
44
|
+
*
|
|
45
|
+
* The desktop profile is reserved: the installed CLI refuses it outright
|
|
46
|
+
* ("profile \"desktop\" is managed exclusively by the Electron application"),
|
|
47
|
+
* so telling a Desktop user to paste `dsh plugin --profile desktop add ...`
|
|
48
|
+
* would hand them a command that cannot work. Desktop's own paths are the
|
|
49
|
+
* in-app plugin market and this panel's button.
|
|
50
|
+
*/
|
|
51
|
+
export function installCommand(profile) {
|
|
52
|
+
const name = typeof profile === "string" ? profile.trim() : "";
|
|
53
|
+
if (name.length === 0 || name === "desktop") return null;
|
|
54
|
+
return "dsh plugin --profile " + name + " add '" + THREADS_PIN_SPEC + "'";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Decide what the install button would do, without doing it.
|
|
59
|
+
*
|
|
60
|
+
* @param input.manager The `pluginManager` service, or undefined.
|
|
61
|
+
* @param input.profile The running profile's name (plugin-manager writes into it).
|
|
62
|
+
* @param input.dependency The saved dependency spec, or null (any spec counts).
|
|
63
|
+
* @param input.bundled Whether the name is listed in `dsh.profile.bundles`.
|
|
64
|
+
* @param input.version The version found in the profile's node_modules, or null.
|
|
65
|
+
* @returns The plan the panel renders and the host executes.
|
|
66
|
+
*/
|
|
67
|
+
export function threadsInstallPlan(input = {}) {
|
|
68
|
+
const manager = input === null || typeof input !== "object" ? undefined : input.manager;
|
|
69
|
+
const dependency = typeof input?.dependency === "string" && input.dependency.length > 0 ? input.dependency : null;
|
|
70
|
+
const bundled = input?.bundled === true;
|
|
71
|
+
const profile = typeof input?.profile === "string" && input.profile.length > 0 ? input.profile : null;
|
|
72
|
+
const mode = dependency !== null && bundled ? "done" : dependency !== null ? "enable" : "install";
|
|
73
|
+
// installBundle is what makes the package exist; setBundleEnabled only selects
|
|
74
|
+
// an existing one. Each state needs exactly one of them.
|
|
75
|
+
const hasInstall = manager !== null && typeof manager === "object" && typeof manager.installBundle === "function";
|
|
76
|
+
const hasEnable = manager !== null && typeof manager === "object" && typeof manager.setBundleEnabled === "function";
|
|
77
|
+
const available = mode === "done" ? false : mode === "install" ? hasInstall : hasEnable;
|
|
78
|
+
return {
|
|
79
|
+
mode,
|
|
80
|
+
available,
|
|
81
|
+
via: available ? "pluginManager" : null,
|
|
82
|
+
reason: available ? null : mode === "done" ? "already-installed" : "no-plugin-manager",
|
|
83
|
+
spec: THREADS_PIN_SPEC,
|
|
84
|
+
tag: THREADS_PIN_TAG,
|
|
85
|
+
bundle: THREADS_BUNDLE,
|
|
86
|
+
profile,
|
|
87
|
+
command: installCommand(profile),
|
|
88
|
+
dependency,
|
|
89
|
+
bundled,
|
|
90
|
+
version: typeof input?.version === "string" && input.version.length > 0 ? input.version : null
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The parts of a plan the panel needs back with a result (never the manager itself). */
|
|
95
|
+
function planEcho(plan) {
|
|
96
|
+
return {
|
|
97
|
+
mode: plan.mode,
|
|
98
|
+
spec: plan.spec,
|
|
99
|
+
tag: plan.tag,
|
|
100
|
+
bundle: plan.bundle,
|
|
101
|
+
profile: plan.profile,
|
|
102
|
+
command: plan.command
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Normalise DSH's ChangeResult into the small shape the panel renders.
|
|
108
|
+
*
|
|
109
|
+
* A ChangeResult is `{ application, changed, bundle, version, restartReason,
|
|
110
|
+
* error, pendingBuilds }` where `application` is applied | cancelled |
|
|
111
|
+
* overridden | restart-required | failed. Only "applied" needs nothing from the
|
|
112
|
+
* user; "restart-required" and "overridden" are saved-but-not-live, and the rest
|
|
113
|
+
* are failures with a code (ERROR_STEPS in the manager's own tool lists them).
|
|
114
|
+
*/
|
|
115
|
+
export function threadsInstallResult(plan, result) {
|
|
116
|
+
const application = typeof result?.application === "string" ? result.application : "failed";
|
|
117
|
+
const failed = application === "failed" || application === "cancelled";
|
|
118
|
+
const code = typeof result?.error?.code === "string" ? result.error.code : null;
|
|
119
|
+
const kind = typeof result?.packageResult?.kind === "string" ? result.packageResult.kind : null;
|
|
120
|
+
return {
|
|
121
|
+
ok: !failed,
|
|
122
|
+
...planEcho(plan),
|
|
123
|
+
application,
|
|
124
|
+
restartRequired: application === "restart-required",
|
|
125
|
+
overridden: application === "overridden",
|
|
126
|
+
cancelled: application === "cancelled",
|
|
127
|
+
changed: result?.changed === true,
|
|
128
|
+
code,
|
|
129
|
+
kind,
|
|
130
|
+
message: typeof result?.error?.message === "string" ? result.error.message : null,
|
|
131
|
+
restartReason: typeof result?.restartReason === "string" ? result.restartReason : null,
|
|
132
|
+
version: typeof result?.version === "string" ? result.version : plan.version ?? null,
|
|
133
|
+
// Build scripts pnpm refused to run: the one failure the user can unblock.
|
|
134
|
+
pendingBuilds: Array.isArray(result?.pendingBuilds) ? result.pendingBuilds.slice(0, 10).map(String) : []
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Run the plan through DSH's plugin manager.
|
|
140
|
+
*
|
|
141
|
+
* Never throws: every failure becomes `{ ok: false, code }` so a panel click can
|
|
142
|
+
* never take the host route (or the user's DSH) down. `no-api` means this host
|
|
143
|
+
* has no plugin manager and the panel must fall back to the manual path.
|
|
144
|
+
*
|
|
145
|
+
* @param input.manager The service, or undefined.
|
|
146
|
+
* @param input.state `{ dependency, bundled, version }` read fresh from the profile.
|
|
147
|
+
* @param input.profile The running profile's name.
|
|
148
|
+
*/
|
|
149
|
+
export async function installThreads(input = {}) {
|
|
150
|
+
const plan = threadsInstallPlan({ manager: input?.manager, profile: input?.profile, ...(input?.state ?? {}) });
|
|
151
|
+
if (plan.mode === "done") return { ok: true, action: "skip", ...planEcho(plan), application: "applied", restartRequired: false, code: null };
|
|
152
|
+
if (!plan.available) {
|
|
153
|
+
return { ok: false, action: plan.mode, code: "no-api", message: "no plugin manager in this host", ...planEcho(plan) };
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
const result =
|
|
157
|
+
plan.mode === "enable"
|
|
158
|
+
? await input.manager.setBundleEnabled(THREADS_BUNDLE, true)
|
|
159
|
+
: await input.manager.installBundle(THREADS_PIN_SPEC, {});
|
|
160
|
+
return { ...threadsInstallResult(plan, result), action: plan.mode };
|
|
161
|
+
} catch (error) {
|
|
162
|
+
// A thrown rejection (rather than a failed ChangeResult) is still the
|
|
163
|
+
// manager's answer: a lock timeout, a service torn down mid-install, or a
|
|
164
|
+
// profile directory the process cannot write.
|
|
165
|
+
return {
|
|
166
|
+
ok: false,
|
|
167
|
+
action: plan.mode,
|
|
168
|
+
...planEcho(plan),
|
|
169
|
+
application: "failed",
|
|
170
|
+
code: typeof error?.code === "string" ? error.code : "operation-error",
|
|
171
|
+
message: String(error?.message ?? error)
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
}
|