@linxin666/dsh-client-ui-plugin-manager 0.3.2 → 0.3.4

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/lib/index.js CHANGED
@@ -4,10 +4,11 @@ import { copyFile, readFile, rename, writeFile } from "node:fs/promises";
4
4
  import { isAbsolute, join, posix, win32 } from "node:path";
5
5
  import { isMap, isScalar, isSeq, parseDocument } from "yaml";
6
6
  import { homedir } from "node:os";
7
+ import { isAbsolute as isAbsolute$1, join as join$1 } from "node:path/posix";
7
8
  //#region src/mount-once.ts
8
9
  /**
9
10
  * Host single-instance guard shared by the plugin family. The family bundle
10
- * (dsh-web-ui-all / dsh-skins) namespaces every child row id (web-ui-*), so
11
+ * (dsh-web-all / dsh-skins) namespaces every child row id (web-ui-*), so
11
12
  * the loader accepts a standalone install of the same package side by side;
12
13
  * without this guard the second instance would still re-register the same
13
14
  * webserver routes, tools, settings namespaces, and system-prompt sections
@@ -20,7 +21,7 @@ import { homedir } from "node:os";
20
21
  * `ctx.effect` runs its callback immediately and treats the callback's
21
22
  * return value as the fiber disposer, so the unmarker is returned, not run.
22
23
  */
23
- const MOUNTED = Symbol.for("dsh-web-ui.mounted-plugins");
24
+ const MOUNTED = Symbol.for("dsh-web.mounted-plugins");
24
25
  function mountedSet() {
25
26
  const registry = globalThis;
26
27
  return registry[MOUNTED] ??= /* @__PURE__ */ new Set();
@@ -383,8 +384,9 @@ async function duplicateMountBundles(facts, before, beforeBundles, afterBundles)
383
384
  */
384
385
  /** Expand a leading ~ (or ~user) in a path, platform-style. */
385
386
  function expandHome(path, home = homedir()) {
387
+ const j = home.startsWith("/") ? join$1 : join;
386
388
  if (path === "~") return home;
387
- if (path.startsWith("~/") || path.startsWith("~\\")) return join(home, path.slice(2));
389
+ if (path.startsWith("~/") || path.startsWith("~\\")) return j(home, path.slice(2));
388
390
  return path;
389
391
  }
390
392
  /**
@@ -394,12 +396,15 @@ function expandHome(path, home = homedir()) {
394
396
  * @returns the absolute DSH home path.
395
397
  */
396
398
  function resolveDshHome(env = process.env, home = homedir()) {
399
+ const isPosix = home.startsWith("/");
400
+ const j = isPosix ? join$1 : join;
401
+ const isAbs = isPosix ? isAbsolute$1 : isAbsolute;
397
402
  const raw = env.DSH_HOME;
398
403
  if (raw !== void 0 && raw.trim() !== "") {
399
404
  const expanded = expandHome(raw.trim(), home);
400
- return isAbsolute(expanded) ? expanded : join(process.cwd(), expanded);
405
+ return isAbs(expanded) ? expanded : j(process.cwd(), expanded);
401
406
  }
402
- return join(home, ".dsh");
407
+ return j(home, ".dsh");
403
408
  }
404
409
  //#endregion
405
410
  //#region src/host/profile.ts
@@ -505,6 +510,31 @@ async function stripProfileBundles(packageJsonPath, names) {
505
510
  await rename(`${packageJsonPath}.tmp`, packageJsonPath);
506
511
  }
507
512
  /**
513
+ * Move one bundle entry to a position in `dsh.profile.bundles`, preserving
514
+ * every unrelated entry. The plugin-manager migration uses this to keep the
515
+ * renamed aggregate at the same layer position it occupied before the
516
+ * remove/update cycle instead of leaving the CLI append at the end.
517
+ * @param packageJsonPath - absolute path of the profile manifest.
518
+ * @param name - bundle entry to move.
519
+ * @param index - desired zero-based position.
520
+ */
521
+ async function reorderProfileBundle(packageJsonPath, name, index) {
522
+ const text = await readFile(packageJsonPath, "utf8");
523
+ const parsed = JSON.parse(stripBom(text));
524
+ const profile = parsed.dsh?.profile;
525
+ if (profile === void 0 || !Array.isArray(profile.bundles)) return;
526
+ const bundles = profile.bundles.filter((entry) => typeof entry === "string");
527
+ const current = bundles.indexOf(name);
528
+ if (current >= 0) bundles.splice(current, 1);
529
+ const target = Math.max(0, Math.min(index, bundles.length));
530
+ bundles.splice(target, 0, name);
531
+ profile.bundles = bundles;
532
+ await copyFile(packageJsonPath, `${packageJsonPath}.bak-plugin-manager`).catch(() => {});
533
+ await writeFile(`${packageJsonPath}.tmp`, `${JSON.stringify(parsed, null, 2)}
534
+ `, { mode: 384 });
535
+ await rename(`${packageJsonPath}.tmp`, packageJsonPath);
536
+ }
537
+ /**
508
538
  * Read the profile patch text; a missing file is an empty layer.
509
539
  * @param patchPath - absolute path of cordis.patch.yml.
510
540
  * @returns the file text, or `[]` when absent.
@@ -853,6 +883,179 @@ var CliGateway = class {
853
883
  binary() {
854
884
  return this.deps.findBinary !== void 0 ? this.deps.findBinary(this.env) : findDshBinary(this.env);
855
885
  }
886
+ /** Run one CLI command to completion and return the bounded output. */
887
+ async runCli(binary, args, timeoutMs) {
888
+ const output = { value: "" };
889
+ const child = this.spawnCli(binary, args);
890
+ child.stdout?.on("data", (chunk) => {
891
+ capture(chunk, output);
892
+ });
893
+ child.stderr?.on("data", (chunk) => {
894
+ capture(chunk, output);
895
+ });
896
+ const timer = setTimeout(() => {
897
+ child.kill();
898
+ }, timeoutMs);
899
+ const code = await new Promise((resolve) => {
900
+ child.on("close", resolve);
901
+ });
902
+ clearTimeout(timer);
903
+ return {
904
+ code,
905
+ output: output.value.trim()
906
+ };
907
+ }
908
+ /** Full package spec used when restoring a legacy dependency. */
909
+ restoreSpec(name, spec) {
910
+ if (/^(?:link:|file:|git:|git\+|github:|https?:\/\/|npm:)/.test(spec)) return spec;
911
+ if (spec === "") return name;
912
+ return `${name}@${spec}`;
913
+ }
914
+ /** Execute the legacy aggregate migration and settle the job. */
915
+ async runMigration(job) {
916
+ const binary = this.binary();
917
+ if (binary === null) {
918
+ job.phase = "error";
919
+ job.error = "plugin-manager: dsh CLI not found on PATH";
920
+ return;
921
+ }
922
+ const sourceId = job.sourceId;
923
+ const targetId = job.targetId;
924
+ const targetVersion = job.targetVersion;
925
+ const targetSpec = job.targetSpec;
926
+ if (sourceId === void 0 || targetId === void 0 || targetVersion === void 0 || targetSpec === void 0) {
927
+ job.phase = "error";
928
+ job.error = "plugin-manager: migration job is missing source/target identity";
929
+ return;
930
+ }
931
+ const before = await this.capture();
932
+ if (!before.dependencies.includes(sourceId)) {
933
+ job.phase = "error";
934
+ job.error = `plugin-manager: legacy aggregate ${sourceId} is not installed`;
935
+ return;
936
+ }
937
+ const oldSpec = (await readProfileManifest(this.facts.packageJsonPath)).dependencies[sourceId] ?? "";
938
+ const oldIndex = before.bundles.indexOf(sourceId);
939
+ const targetPreviouslyInstalled = before.dependencies.includes(targetId);
940
+ const remove = await this.runCli(binary, [
941
+ "plugin",
942
+ "--profile",
943
+ this.facts.profileName,
944
+ "remove",
945
+ sourceId
946
+ ], REMOVE_TIMEOUT_MS);
947
+ if (remove.code !== 0) {
948
+ job.phase = "error";
949
+ job.error = remove.output === "" ? `plugin-manager: dsh plugin remove ${sourceId} failed with code ${String(remove.code)}` : remove.output;
950
+ return;
951
+ }
952
+ let after = await this.capture();
953
+ if (after.dependencies.includes(sourceId)) {
954
+ job.phase = "error";
955
+ job.error = `plugin-manager: dsh plugin remove 报告成功,但 ${sourceId} 仍在 profile 中`;
956
+ return;
957
+ }
958
+ const targetIsLocal = /^(?:link:|file:)/.test(targetSpec);
959
+ if (targetPreviouslyInstalled ? !targetIsLocal : !after.dependencies.includes(targetId)) {
960
+ const add = await this.runCli(binary, [
961
+ "plugin",
962
+ "--profile",
963
+ this.facts.profileName,
964
+ "add",
965
+ targetSpec
966
+ ], ADD_TIMEOUT_MS);
967
+ if (add.code !== 0) {
968
+ await this.rollbackMigration(job, sourceId, targetId, oldSpec, oldIndex, targetPreviouslyInstalled);
969
+ job.error = `plugin-manager: 迁移安装 ${targetSpec} 失败${add.output === "" ? "" : `:\n${add.output}`}`;
970
+ return;
971
+ }
972
+ after = await this.capture();
973
+ }
974
+ if (!after.dependencies.includes(targetId)) {
975
+ await this.rollbackMigration(job, sourceId, targetId, oldSpec, oldIndex, targetPreviouslyInstalled);
976
+ job.error = `plugin-manager: dsh plugin add 报告成功,但 ${targetId} 未出现在 profile 中`;
977
+ return;
978
+ }
979
+ const stripped = await this.stripDuplicateMounts(job, before, after);
980
+ if (stripped === void 0) {
981
+ await this.rollbackMigration(job, sourceId, targetId, oldSpec, oldIndex, targetPreviouslyInstalled);
982
+ return;
983
+ }
984
+ if (stripped.length > 0) {
985
+ job.notices = stripped.map((name) => ({
986
+ id: name,
987
+ name,
988
+ from: "enabled",
989
+ to: "uninstalled"
990
+ }));
991
+ after = await this.capture();
992
+ }
993
+ if (oldIndex >= 0) await reorderProfileBundle(this.facts.packageJsonPath, targetId, oldIndex);
994
+ after = await this.capture();
995
+ const verify = await this.runCli(binary, [
996
+ "--profile",
997
+ this.facts.profileName,
998
+ "--dump-config"
999
+ ], 9e4);
1000
+ if (verify.code !== 0) {
1001
+ await this.rollbackMigration(job, sourceId, targetId, oldSpec, oldIndex, targetPreviouslyInstalled);
1002
+ job.error = `plugin-manager: 迁移后的启动预检失败${verify.output === "" ? "" : `:\n${verify.output}`}`;
1003
+ return;
1004
+ }
1005
+ const manifest = await readProfileManifest(this.facts.packageJsonPath);
1006
+ const updated = await buildPluginRow(this.facts, targetId, manifest.dependencies[targetId] ?? targetSpec, after.layer.rows);
1007
+ if (!/^(?:link:|file:)/.test(targetSpec) && updated.version !== targetVersion) {
1008
+ await this.rollbackMigration(job, sourceId, targetId, oldSpec, oldIndex, targetPreviouslyInstalled);
1009
+ job.error = `plugin-manager: 迁移后 ${targetId} 版本为 ${updated.version},预期 ${targetVersion}`;
1010
+ return;
1011
+ }
1012
+ job.plugin = updated;
1013
+ job.conflicts = significantChanges(diffLayer(before.layer, after.layer)).map((change) => ({
1014
+ id: change.id,
1015
+ name: change.id,
1016
+ from: change.from,
1017
+ to: change.to
1018
+ }));
1019
+ job.phase = "done";
1020
+ }
1021
+ /** Restore the original legacy package after a failed migration. */
1022
+ async rollbackMigration(job, sourceId, targetId, oldSpec, oldIndex, targetPreviouslyInstalled) {
1023
+ const binary = this.binary();
1024
+ if (binary === null) {
1025
+ job.phase = "error";
1026
+ job.error = "plugin-manager: 迁移失败且无法回滚:dsh CLI not found on PATH";
1027
+ return;
1028
+ }
1029
+ const current = await this.capture();
1030
+ if (!targetPreviouslyInstalled && current.dependencies.includes(targetId)) await this.runCli(binary, [
1031
+ "plugin",
1032
+ "--profile",
1033
+ this.facts.profileName,
1034
+ "remove",
1035
+ targetId
1036
+ ], REMOVE_TIMEOUT_MS);
1037
+ if (targetPreviouslyInstalled) {
1038
+ job.phase = "error";
1039
+ job.error = "plugin-manager: 聚合包迁移失败,已保留当前聚合包并移除旧包";
1040
+ return;
1041
+ }
1042
+ const restoreOld = this.restoreSpec(sourceId, oldSpec);
1043
+ const restored = await this.runCli(binary, [
1044
+ "plugin",
1045
+ "--profile",
1046
+ this.facts.profileName,
1047
+ "add",
1048
+ restoreOld
1049
+ ], ADD_TIMEOUT_MS);
1050
+ if (restored.code !== 0) {
1051
+ job.phase = "error";
1052
+ job.error = `plugin-manager: 迁移失败且回滚到 ${restoreOld} 失败${restored.output === "" ? "" : `:\n${restored.output}`}`;
1053
+ return;
1054
+ }
1055
+ if (oldIndex >= 0) await reorderProfileBundle(this.facts.packageJsonPath, sourceId, oldIndex).catch(() => void 0);
1056
+ job.phase = "error";
1057
+ job.error = "plugin-manager: 聚合包迁移失败,已回滚到旧包";
1058
+ }
856
1059
  /** Spawn the CLI, through the test seam when present. */
857
1060
  spawnCli(binary, args) {
858
1061
  return (this.deps.spawnImpl ?? spawnDsh)(binary, args, this.env);
@@ -910,6 +1113,39 @@ var CliGateway = class {
910
1113
  ], ADD_TIMEOUT_MS));
911
1114
  return { jobId: job.id };
912
1115
  }
1116
+ /** Start a deterministic legacy aggregate migration. */
1117
+ migrate(sourceId, targetId, targetVersion, targetSpec) {
1118
+ const job = {
1119
+ id: `job-${++this.counter}`,
1120
+ action: "migrate",
1121
+ spec: targetSpec,
1122
+ sourceId,
1123
+ targetId,
1124
+ targetVersion,
1125
+ targetSpec,
1126
+ phase: "running"
1127
+ };
1128
+ this.jobs.set(job.id, job);
1129
+ const unsafe = unsafeSpecReason(sourceId) ?? unsafeSpecReason(targetId) ?? unsafeSpecReason(targetSpec);
1130
+ if (unsafe !== void 0) {
1131
+ job.phase = "error";
1132
+ job.error = unsafe;
1133
+ this.retainFinished(job.id);
1134
+ return { jobId: job.id };
1135
+ }
1136
+ this.enqueue(async () => {
1137
+ try {
1138
+ await this.runMigration(job);
1139
+ } catch (error) {
1140
+ if (job.phase !== "error") {
1141
+ job.phase = "error";
1142
+ job.error = `plugin-manager: unexpected migration failure: ${error instanceof Error ? error.message : String(error)}`;
1143
+ }
1144
+ }
1145
+ this.retainFinished(job.id);
1146
+ });
1147
+ return { jobId: job.id };
1148
+ }
913
1149
  /** Start a removal; the caller polls {@link status}. */
914
1150
  remove(id) {
915
1151
  const job = {
@@ -980,6 +1216,7 @@ var CliGateway = class {
980
1216
  rows,
981
1217
  bundles
982
1218
  },
1219
+ bundles,
983
1220
  patchText,
984
1221
  dependencies
985
1222
  };
@@ -1094,7 +1331,7 @@ var CliGateway = class {
1094
1331
  from: change.from,
1095
1332
  to: change.to
1096
1333
  }));
1097
- if (job.action !== "update") job.plugin = await this.rowFor(job.action, job.spec, before, after);
1334
+ if (job.action === "install" || job.action === "remove") job.plugin = await this.rowFor(job.action, job.spec, before, after);
1098
1335
  job.phase = "done";
1099
1336
  }
1100
1337
  /**
@@ -1464,6 +1701,52 @@ function dshRequirementOf(manifest) {
1464
1701
  return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
1465
1702
  }
1466
1703
  //#endregion
1704
+ //#region src/host/legacy-migration.ts
1705
+ /**
1706
+ * Deterministic mapping for the dsh-web aggregate package rename.
1707
+ *
1708
+ * The runtime identifiers (web-ui-* rows, settings section, API paths,
1709
+ * storage keys) stay frozen; only the npm aggregate package name changes.
1710
+ * This module is the single migration map shared by the plugin-manager
1711
+ * update job and the Doctor preflight launcher so they never drift.
1712
+ */
1713
+ /** The previously published aggregate package name. */
1714
+ const LEGACY_AGGREGATE = "@linxin666/dsh-web-ui-all";
1715
+ /** The current aggregate package name. */
1716
+ const CURRENT_AGGREGATE = "@linxin666/dsh-web-all";
1717
+ /** The only supported legacy aggregate migration. */
1718
+ const LEGACY_AGGREGATE_MIGRATION = {
1719
+ from: LEGACY_AGGREGATE,
1720
+ to: CURRENT_AGGREGATE
1721
+ };
1722
+ /** Whether a package name is the legacy aggregate. */
1723
+ function isLegacyAggregate(name) {
1724
+ return name === LEGACY_AGGREGATE;
1725
+ }
1726
+ /** Return the migration for a package name, or undefined when not legacy. */
1727
+ function legacyMigrationFor(name) {
1728
+ return isLegacyAggregate(name) ? LEGACY_AGGREGATE_MIGRATION : void 0;
1729
+ }
1730
+ /**
1731
+ * Build the exact target install spec for one legacy aggregate source.
1732
+ *
1733
+ * Local repository links are rewritten in place so development checkouts
1734
+ * keep using the repository tree; every other source is migrated through the
1735
+ * published package pinned to the family release version.
1736
+ */
1737
+ function targetSpecForLegacy(sourceSpec, familyVersion) {
1738
+ const raw = sourceSpec.trim();
1739
+ if (raw.startsWith("link:") || raw.startsWith("file:")) {
1740
+ const prefix = raw.slice(0, raw.indexOf(":"));
1741
+ const target = raw.slice(prefix.length + 1);
1742
+ const index = target.lastIndexOf("dsh-web-ui-all");
1743
+ if (index === -1) return void 0;
1744
+ return `${prefix}:${target.slice(0, index) + "dsh-web-all" + target.slice(index + 14)}`;
1745
+ }
1746
+ if (familyVersion === "") return void 0;
1747
+ return `${CURRENT_AGGREGATE}@${familyVersion}`;
1748
+ }
1749
+ //#endregion
1467
1750
  //#region src/host/routes.ts
1468
1751
  /** Route prefix the browser half mirrors. */
1469
1752
  const GATEWAY_PREFIX = "/api/plugin-manager";
@@ -1477,6 +1760,11 @@ const VERSION_ESCALATION_TIMEOUT_MS = 5e3;
1477
1760
  const VERSION_PROBE_TTL_MS = 5 * 6e4;
1478
1761
  /** Minimum gap between failed version probes (avoids a spawn per request). */
1479
1762
  const VERSION_PROBE_COOLDOWN_MS = 6e4;
1763
+ /**
1764
+ * Entry ids that must stay mounted so the local plugin-management escape hatch
1765
+ * remains available. Aggregate packages may still disable every other entry.
1766
+ */
1767
+ const SELF_MANAGED_ENTRY_IDS = /* @__PURE__ */ new Set(["ui-plugin-manager", "web-ui-plugin-manager"]);
1480
1768
  /** Error text for a caught request or lifecycle failure. */
1481
1769
  function messageOf(error) {
1482
1770
  return error instanceof Error ? error.message : String(error);
@@ -1661,6 +1949,36 @@ function makeGatewayRoutes(deps) {
1661
1949
  status: 404,
1662
1950
  error: `plugin-manager: plugin ${target} is not installed`
1663
1951
  };
1952
+ const migration = legacyMigrationFor(target);
1953
+ if (migration !== void 0) {
1954
+ const targetManifest = await fetchManifest(migration.to).catch(() => void 0);
1955
+ if (targetManifest === void 0 || targetManifest.version === "") return {
1956
+ status: 502,
1957
+ error: `plugin-manager: cannot resolve the migration target ${migration.to}`
1958
+ };
1959
+ const targetSpec = targetSpecForLegacy(row.source.spec, targetManifest.version);
1960
+ if (targetSpec === void 0) return {
1961
+ status: 400,
1962
+ error: `plugin-manager: cannot derive the migration target spec for ${target}`
1963
+ };
1964
+ const unsafeTarget = unsafeSpecReason(targetSpec);
1965
+ if (unsafeTarget !== void 0) return {
1966
+ status: 400,
1967
+ error: unsafeTarget
1968
+ };
1969
+ const requiresDsh = dshRequirementOf(targetManifest);
1970
+ if (requiresDsh !== void 0) {
1971
+ const { hostVersion, compatible } = await compatibleVerdict(requiresDsh);
1972
+ if (!compatible) return {
1973
+ status: 412,
1974
+ error: hostVersion === void 0 ? `plugin-manager: cannot verify the DSH version for ${migration.to} (dsh --version failed); upgrade DSH before migrating` : `plugin-manager: ${migration.to} requires DSH ${requiresDsh} (current DSH ${hostVersion}); upgrade DSH before migrating`
1975
+ };
1976
+ }
1977
+ return {
1978
+ status: 200,
1979
+ job: gateway.migrate(target, migration.to, targetManifest.version, targetSpec)
1980
+ };
1981
+ }
1664
1982
  if (row.source.kind !== "npm" || !isDirectRegistrySpec(row.source.spec)) return {
1665
1983
  status: 400,
1666
1984
  error: `plugin-manager: ${target} is not a direct npm registry plugin`
@@ -1758,7 +2076,10 @@ function makeGatewayRoutes(deps) {
1758
2076
  if ((await readProfileManifest(facts.packageJsonPath)).dependencies[target] === void 0) return { error: `plugin-manager: plugin ${target} is not installed` };
1759
2077
  const entries = await claimedEntryRowsOf(facts, target);
1760
2078
  let next = patchText;
1761
- for (const entry of entries) next = setRowEnabled(next, facts.patchPath, entry.id, entry.name, enabled);
2079
+ for (const entry of entries) {
2080
+ const entryEnabled = enabled || SELF_MANAGED_ENTRY_IDS.has(entry.id);
2081
+ next = setRowEnabled(next, facts.patchPath, entry.id, entry.name, entryEnabled);
2082
+ }
1762
2083
  if (next !== patchText) await writePatchAtomic(facts.patchPath, next);
1763
2084
  const plugin = (await snapshotGateway(facts, next)).plugins.find((item) => item.id === target);
1764
2085
  return plugin === void 0 ? { error: `plugin-manager: plugin ${target} is not installed` } : { plugin };
@@ -1792,6 +2113,26 @@ function makeGatewayRoutes(deps) {
1792
2113
  const snapshot = await snapshotGateway(facts, patchText);
1793
2114
  const updates = [];
1794
2115
  for (const plugin of snapshot.plugins) {
2116
+ const migration = legacyMigrationFor(plugin.id);
2117
+ if (migration !== void 0) {
2118
+ const targetManifest = await fetchManifest(migration.to).catch(() => void 0);
2119
+ if (targetManifest === void 0 || targetManifest.version === "") continue;
2120
+ const update = {
2121
+ id: plugin.id,
2122
+ current: plugin.version,
2123
+ latest: targetManifest.version,
2124
+ kind: "migrate",
2125
+ target: migration.to,
2126
+ targetVersion: targetManifest.version
2127
+ };
2128
+ const requiresDsh = dshRequirementOf(targetManifest);
2129
+ if (requiresDsh !== void 0) {
2130
+ update.requiresDsh = requiresDsh;
2131
+ update.compatible = (await compatibleVerdict(requiresDsh)).compatible;
2132
+ }
2133
+ updates.push(update);
2134
+ continue;
2135
+ }
1795
2136
  if (plugin.source.kind !== "npm" || !isDirectRegistrySpec(plugin.source.spec)) continue;
1796
2137
  const manifest = await fetchManifest(plugin.id).catch(() => void 0);
1797
2138
  if (manifest === void 0 || manifest.version === plugin.version) continue;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Anonymous install telemetry shared by the DSH Web UI family plugins.
3
+ *
4
+ * Once per UTC day per browser, each wired plugin sends one heartbeat to
5
+ * the dsh-market edge API listing its package name (and version when known).
6
+ * The payload carries no conversation data and no identifiers beyond a random
7
+ * UUID generated in localStorage; the server hashes it with a deployment salt
8
+ * before storage and never persists IP addresses. Sends are fire-and-forget:
9
+ * failures stay silent and simply retry on a later mount or day. The system
10
+ * is documented in docs/telemetry.md.
11
+ */
12
+ export type TelemetryChannel = 'market' | 'npm' | 'unknown';
13
+ export interface TelemetryItem {
14
+ /** npm package name or asset id, e.g. "@linxin666/dsh-pet" or "skin:harbor". */
15
+ name: string;
16
+ /** Installed version when known; omitted otherwise. */
17
+ version?: string;
18
+ /** Install channel when determinable (market = Workshop install). */
19
+ channel?: TelemetryChannel;
20
+ }
21
+ /**
22
+ * Fire the daily heartbeat for the given items at most once per UTC day per
23
+ * browser. Never throws and never blocks the caller. Items without an explicit
24
+ * version inherit the bundle's baked build version.
25
+ */
26
+ export declare function reportDailyHeartbeat(items: readonly TelemetryItem[]): void;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Conflict-ledger diffing. The official host applies structural conflict
3
- * rules at install time (disableControlsOnInstall: installing the dsh-web-ui
3
+ * rules at install time (disableControlsOnInstall: installing the dsh-web
4
4
  * family disables the built-in web-ui product rows so the two never
5
5
  * double-mount), but no UI surfaces what the rules just did. This module
6
6
  * diffs the plugin-control snapshots taken before and after an install and
@@ -30,11 +30,19 @@ export interface InstallProgressItem {
30
30
  stage: 'fetch' | 'download' | 'extract' | 'write';
31
31
  percent?: number;
32
32
  }
33
+ /** Whether an update row is a normal same-name update or a legacy package migration. */
34
+ export type PluginUpdateKind = 'update' | 'migrate';
33
35
  /** One plugin with a newer version available. */
34
36
  export interface PluginUpdateItem {
35
37
  id: string;
36
38
  current: string;
37
39
  latest: string;
40
+ /** Normal same-name update or legacy aggregate migration. Defaults to update. */
41
+ kind?: PluginUpdateKind;
42
+ /** Target package name when kind is migrate. */
43
+ target?: string;
44
+ /** Exact target package version when kind is migrate. */
45
+ targetVersion?: string;
38
46
  /** Declared DSH minimum the update needs (package manifest's `dsh.engines.dsh`). */
39
47
  requiresDsh?: string;
40
48
  /** Whether the running DSH host satisfies requiresDsh; absent when unknown. */
@@ -20,12 +20,16 @@ export declare function unsafeSpecReason(spec: string): string | undefined;
20
20
  /** One CLI-backed operation in flight or settled. */
21
21
  export interface GatewayJob {
22
22
  id: string;
23
- action: 'install' | 'update' | 'remove';
23
+ action: 'install' | 'update' | 'migrate' | 'remove';
24
24
  spec: string;
25
25
  /** Installed package ID for an in-place npm update. */
26
26
  targetId?: string;
27
27
  /** Exact registry version the update must land on. */
28
28
  targetVersion?: string;
29
+ /** Legacy package being migrated away from. */
30
+ sourceId?: string;
31
+ /** Exact install spec for the target package. */
32
+ targetSpec?: string;
29
33
  phase: 'running' | 'done' | 'error';
30
34
  /** The installed row on success (install) or the removed row (remove). */
31
35
  plugin?: InstalledPluginItem;
@@ -110,6 +114,14 @@ export declare class CliGateway {
110
114
  private retainFinished;
111
115
  /** The dsh CLI path, through the test seam when present. */
112
116
  private binary;
117
+ /** Run one CLI command to completion and return the bounded output. */
118
+ private runCli;
119
+ /** Full package spec used when restoring a legacy dependency. */
120
+ private restoreSpec;
121
+ /** Execute the legacy aggregate migration and settle the job. */
122
+ private runMigration;
123
+ /** Restore the original legacy package after a failed migration. */
124
+ private rollbackMigration;
113
125
  /** Spawn the CLI, through the test seam when present. */
114
126
  private spawnCli;
115
127
  /** Start an install; the caller polls {@link status}. */
@@ -120,6 +132,10 @@ export declare class CliGateway {
120
132
  update(id: string, version: string): {
121
133
  jobId: string;
122
134
  };
135
+ /** Start a deterministic legacy aggregate migration. */
136
+ migrate(sourceId: string, targetId: string, targetVersion: string, targetSpec: string): {
137
+ jobId: string;
138
+ };
123
139
  /** Start a removal; the caller polls {@link status}. */
124
140
  remove(id: string): {
125
141
  jobId: string;
@@ -10,7 +10,7 @@
10
10
  * edit this shared source and re-run the sync instead of editing a copy.
11
11
  * Consumer code is migrated onto it in follow-up waves; no call site changes
12
12
  * belong in the same change as its introduction.
13
- * @module dsh-web-ui-shared/host/http
13
+ * @module dsh-web-shared/host/http
14
14
  */
15
15
  import type { IncomingMessage, OutgoingHttpHeaders, ServerResponse } from 'node:http';
16
16
  /**
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Deterministic mapping for the dsh-web aggregate package rename.
3
+ *
4
+ * The runtime identifiers (web-ui-* rows, settings section, API paths,
5
+ * storage keys) stay frozen; only the npm aggregate package name changes.
6
+ * This module is the single migration map shared by the plugin-manager
7
+ * update job and the Doctor preflight launcher so they never drift.
8
+ */
9
+ /** The previously published aggregate package name. */
10
+ export declare const LEGACY_AGGREGATE = "@linxin666/dsh-web-ui-all";
11
+ /** The current aggregate package name. */
12
+ export declare const CURRENT_AGGREGATE = "@linxin666/dsh-web-all";
13
+ /** One deterministic legacy-to-current package migration. */
14
+ export interface LegacyAggregateMigration {
15
+ from: string;
16
+ to: string;
17
+ }
18
+ /** The only supported legacy aggregate migration. */
19
+ export declare const LEGACY_AGGREGATE_MIGRATION: LegacyAggregateMigration;
20
+ /** Whether a package name is the legacy aggregate. */
21
+ export declare function isLegacyAggregate(name: string): boolean;
22
+ /** Whether a package name is the current aggregate. */
23
+ export declare function isCurrentAggregate(name: string): boolean;
24
+ /** Return the migration for a package name, or undefined when not legacy. */
25
+ export declare function legacyMigrationFor(name: string): LegacyAggregateMigration | undefined;
26
+ /**
27
+ * Build the exact target install spec for one legacy aggregate source.
28
+ *
29
+ * Local repository links are rewritten in place so development checkouts
30
+ * keep using the repository tree; every other source is migrated through the
31
+ * published package pinned to the family release version.
32
+ */
33
+ export declare function targetSpecForLegacy(sourceSpec: string, familyVersion: string): string | undefined;
@@ -7,7 +7,7 @@
7
7
  * Semantics: RFC 5735 IPv4 127/8, ::1, IPv4-mapped ::ffff:127/8 (matching the
8
8
  * remote-web-ui gate), localhost hostnames, plus the browser same-origin
9
9
  * markers (sec-fetch-site and Origin) for the request-level fence.
10
- * @module dsh-web-ui-shared/host/loopback
10
+ * @module dsh-web-shared/host/loopback
11
11
  */
12
12
  import type { IncomingMessage } from 'node:http';
13
13
  /** IPv4 127/8 predicate (four decimal octets, first == 127). */
@@ -59,6 +59,16 @@ export declare function readProfileManifest(packageJsonPath: string): Promise<Pr
59
59
  * @param names - bundle entries to strip (package names).
60
60
  */
61
61
  export declare function stripProfileBundles(packageJsonPath: string, names: readonly string[]): Promise<void>;
62
+ /**
63
+ * Move one bundle entry to a position in `dsh.profile.bundles`, preserving
64
+ * every unrelated entry. The plugin-manager migration uses this to keep the
65
+ * renamed aggregate at the same layer position it occupied before the
66
+ * remove/update cycle instead of leaving the CLI append at the end.
67
+ * @param packageJsonPath - absolute path of the profile manifest.
68
+ * @param name - bundle entry to move.
69
+ * @param index - desired zero-based position.
70
+ */
71
+ export declare function reorderProfileBundle(packageJsonPath: string, name: string, index: number): Promise<void>;
62
72
  /**
63
73
  * Read the profile patch text; a missing file is an empty layer.
64
74
  * @param patchPath - absolute path of cordis.patch.yml.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Host single-instance guard shared by the plugin family. The family bundle
3
- * (dsh-web-ui-all / dsh-skins) namespaces every child row id (web-ui-*), so
3
+ * (dsh-web-all / dsh-skins) namespaces every child row id (web-ui-*), so
4
4
  * the loader accepts a standalone install of the same package side by side;
5
5
  * without this guard the second instance would still re-register the same
6
6
  * webserver routes, tools, settings namespaces, and system-prompt sections
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@linxin666/dsh-client-ui-plugin-manager",
3
3
  "description": "Plugin manager tab for the dsh web GUI Plugins settings section: installs plugins from npm or git through the official host channels, lists installed plugins with next-start enablement switches, surfaces install-time conflict actions with undo, and hands failures off to repair conversations.",
4
- "version": "0.3.2",
4
+ "version": "0.3.4",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/types/index.d.ts",