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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -7,7 +7,7 @@ import { homedir } from "node:os";
7
7
  //#region src/mount-once.ts
8
8
  /**
9
9
  * 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
10
+ * (dsh-web-all / dsh-skins) namespaces every child row id (web-ui-*), so
11
11
  * the loader accepts a standalone install of the same package side by side;
12
12
  * without this guard the second instance would still re-register the same
13
13
  * webserver routes, tools, settings namespaces, and system-prompt sections
@@ -20,7 +20,7 @@ import { homedir } from "node:os";
20
20
  * `ctx.effect` runs its callback immediately and treats the callback's
21
21
  * return value as the fiber disposer, so the unmarker is returned, not run.
22
22
  */
23
- const MOUNTED = Symbol.for("dsh-web-ui.mounted-plugins");
23
+ const MOUNTED = Symbol.for("dsh-web.mounted-plugins");
24
24
  function mountedSet() {
25
25
  const registry = globalThis;
26
26
  return registry[MOUNTED] ??= /* @__PURE__ */ new Set();
@@ -505,6 +505,31 @@ async function stripProfileBundles(packageJsonPath, names) {
505
505
  await rename(`${packageJsonPath}.tmp`, packageJsonPath);
506
506
  }
507
507
  /**
508
+ * Move one bundle entry to a position in `dsh.profile.bundles`, preserving
509
+ * every unrelated entry. The plugin-manager migration uses this to keep the
510
+ * renamed aggregate at the same layer position it occupied before the
511
+ * remove/update cycle instead of leaving the CLI append at the end.
512
+ * @param packageJsonPath - absolute path of the profile manifest.
513
+ * @param name - bundle entry to move.
514
+ * @param index - desired zero-based position.
515
+ */
516
+ async function reorderProfileBundle(packageJsonPath, name, index) {
517
+ const text = await readFile(packageJsonPath, "utf8");
518
+ const parsed = JSON.parse(stripBom(text));
519
+ const profile = parsed.dsh?.profile;
520
+ if (profile === void 0 || !Array.isArray(profile.bundles)) return;
521
+ const bundles = profile.bundles.filter((entry) => typeof entry === "string");
522
+ const current = bundles.indexOf(name);
523
+ if (current >= 0) bundles.splice(current, 1);
524
+ const target = Math.max(0, Math.min(index, bundles.length));
525
+ bundles.splice(target, 0, name);
526
+ profile.bundles = bundles;
527
+ await copyFile(packageJsonPath, `${packageJsonPath}.bak-plugin-manager`).catch(() => {});
528
+ await writeFile(`${packageJsonPath}.tmp`, `${JSON.stringify(parsed, null, 2)}
529
+ `, { mode: 384 });
530
+ await rename(`${packageJsonPath}.tmp`, packageJsonPath);
531
+ }
532
+ /**
508
533
  * Read the profile patch text; a missing file is an empty layer.
509
534
  * @param patchPath - absolute path of cordis.patch.yml.
510
535
  * @returns the file text, or `[]` when absent.
@@ -853,6 +878,179 @@ var CliGateway = class {
853
878
  binary() {
854
879
  return this.deps.findBinary !== void 0 ? this.deps.findBinary(this.env) : findDshBinary(this.env);
855
880
  }
881
+ /** Run one CLI command to completion and return the bounded output. */
882
+ async runCli(binary, args, timeoutMs) {
883
+ const output = { value: "" };
884
+ const child = this.spawnCli(binary, args);
885
+ child.stdout?.on("data", (chunk) => {
886
+ capture(chunk, output);
887
+ });
888
+ child.stderr?.on("data", (chunk) => {
889
+ capture(chunk, output);
890
+ });
891
+ const timer = setTimeout(() => {
892
+ child.kill();
893
+ }, timeoutMs);
894
+ const code = await new Promise((resolve) => {
895
+ child.on("close", resolve);
896
+ });
897
+ clearTimeout(timer);
898
+ return {
899
+ code,
900
+ output: output.value.trim()
901
+ };
902
+ }
903
+ /** Full package spec used when restoring a legacy dependency. */
904
+ restoreSpec(name, spec) {
905
+ if (/^(?:link:|file:|git:|git\+|github:|https?:\/\/|npm:)/.test(spec)) return spec;
906
+ if (spec === "") return name;
907
+ return `${name}@${spec}`;
908
+ }
909
+ /** Execute the legacy aggregate migration and settle the job. */
910
+ async runMigration(job) {
911
+ const binary = this.binary();
912
+ if (binary === null) {
913
+ job.phase = "error";
914
+ job.error = "plugin-manager: dsh CLI not found on PATH";
915
+ return;
916
+ }
917
+ const sourceId = job.sourceId;
918
+ const targetId = job.targetId;
919
+ const targetVersion = job.targetVersion;
920
+ const targetSpec = job.targetSpec;
921
+ if (sourceId === void 0 || targetId === void 0 || targetVersion === void 0 || targetSpec === void 0) {
922
+ job.phase = "error";
923
+ job.error = "plugin-manager: migration job is missing source/target identity";
924
+ return;
925
+ }
926
+ const before = await this.capture();
927
+ if (!before.dependencies.includes(sourceId)) {
928
+ job.phase = "error";
929
+ job.error = `plugin-manager: legacy aggregate ${sourceId} is not installed`;
930
+ return;
931
+ }
932
+ const oldSpec = (await readProfileManifest(this.facts.packageJsonPath)).dependencies[sourceId] ?? "";
933
+ const oldIndex = before.bundles.indexOf(sourceId);
934
+ const targetPreviouslyInstalled = before.dependencies.includes(targetId);
935
+ const remove = await this.runCli(binary, [
936
+ "plugin",
937
+ "--profile",
938
+ this.facts.profileName,
939
+ "remove",
940
+ sourceId
941
+ ], REMOVE_TIMEOUT_MS);
942
+ if (remove.code !== 0) {
943
+ job.phase = "error";
944
+ job.error = remove.output === "" ? `plugin-manager: dsh plugin remove ${sourceId} failed with code ${String(remove.code)}` : remove.output;
945
+ return;
946
+ }
947
+ let after = await this.capture();
948
+ if (after.dependencies.includes(sourceId)) {
949
+ job.phase = "error";
950
+ job.error = `plugin-manager: dsh plugin remove 报告成功,但 ${sourceId} 仍在 profile 中`;
951
+ return;
952
+ }
953
+ const targetIsLocal = /^(?:link:|file:)/.test(targetSpec);
954
+ if (targetPreviouslyInstalled ? !targetIsLocal : !after.dependencies.includes(targetId)) {
955
+ const add = await this.runCli(binary, [
956
+ "plugin",
957
+ "--profile",
958
+ this.facts.profileName,
959
+ "add",
960
+ targetSpec
961
+ ], ADD_TIMEOUT_MS);
962
+ if (add.code !== 0) {
963
+ await this.rollbackMigration(job, sourceId, targetId, oldSpec, oldIndex, targetPreviouslyInstalled);
964
+ job.error = `plugin-manager: 迁移安装 ${targetSpec} 失败${add.output === "" ? "" : `:\n${add.output}`}`;
965
+ return;
966
+ }
967
+ after = await this.capture();
968
+ }
969
+ if (!after.dependencies.includes(targetId)) {
970
+ await this.rollbackMigration(job, sourceId, targetId, oldSpec, oldIndex, targetPreviouslyInstalled);
971
+ job.error = `plugin-manager: dsh plugin add 报告成功,但 ${targetId} 未出现在 profile 中`;
972
+ return;
973
+ }
974
+ const stripped = await this.stripDuplicateMounts(job, before, after);
975
+ if (stripped === void 0) {
976
+ await this.rollbackMigration(job, sourceId, targetId, oldSpec, oldIndex, targetPreviouslyInstalled);
977
+ return;
978
+ }
979
+ if (stripped.length > 0) {
980
+ job.notices = stripped.map((name) => ({
981
+ id: name,
982
+ name,
983
+ from: "enabled",
984
+ to: "uninstalled"
985
+ }));
986
+ after = await this.capture();
987
+ }
988
+ if (oldIndex >= 0) await reorderProfileBundle(this.facts.packageJsonPath, targetId, oldIndex);
989
+ after = await this.capture();
990
+ const verify = await this.runCli(binary, [
991
+ "--profile",
992
+ this.facts.profileName,
993
+ "--dump-config"
994
+ ], 9e4);
995
+ if (verify.code !== 0) {
996
+ await this.rollbackMigration(job, sourceId, targetId, oldSpec, oldIndex, targetPreviouslyInstalled);
997
+ job.error = `plugin-manager: 迁移后的启动预检失败${verify.output === "" ? "" : `:\n${verify.output}`}`;
998
+ return;
999
+ }
1000
+ const manifest = await readProfileManifest(this.facts.packageJsonPath);
1001
+ const updated = await buildPluginRow(this.facts, targetId, manifest.dependencies[targetId] ?? targetSpec, after.layer.rows);
1002
+ if (!/^(?:link:|file:)/.test(targetSpec) && updated.version !== targetVersion) {
1003
+ await this.rollbackMigration(job, sourceId, targetId, oldSpec, oldIndex, targetPreviouslyInstalled);
1004
+ job.error = `plugin-manager: 迁移后 ${targetId} 版本为 ${updated.version},预期 ${targetVersion}`;
1005
+ return;
1006
+ }
1007
+ job.plugin = updated;
1008
+ job.conflicts = significantChanges(diffLayer(before.layer, after.layer)).map((change) => ({
1009
+ id: change.id,
1010
+ name: change.id,
1011
+ from: change.from,
1012
+ to: change.to
1013
+ }));
1014
+ job.phase = "done";
1015
+ }
1016
+ /** Restore the original legacy package after a failed migration. */
1017
+ async rollbackMigration(job, sourceId, targetId, oldSpec, oldIndex, targetPreviouslyInstalled) {
1018
+ const binary = this.binary();
1019
+ if (binary === null) {
1020
+ job.phase = "error";
1021
+ job.error = "plugin-manager: 迁移失败且无法回滚:dsh CLI not found on PATH";
1022
+ return;
1023
+ }
1024
+ const current = await this.capture();
1025
+ if (!targetPreviouslyInstalled && current.dependencies.includes(targetId)) await this.runCli(binary, [
1026
+ "plugin",
1027
+ "--profile",
1028
+ this.facts.profileName,
1029
+ "remove",
1030
+ targetId
1031
+ ], REMOVE_TIMEOUT_MS);
1032
+ if (targetPreviouslyInstalled) {
1033
+ job.phase = "error";
1034
+ job.error = "plugin-manager: 聚合包迁移失败,已保留当前聚合包并移除旧包";
1035
+ return;
1036
+ }
1037
+ const restoreOld = this.restoreSpec(sourceId, oldSpec);
1038
+ const restored = await this.runCli(binary, [
1039
+ "plugin",
1040
+ "--profile",
1041
+ this.facts.profileName,
1042
+ "add",
1043
+ restoreOld
1044
+ ], ADD_TIMEOUT_MS);
1045
+ if (restored.code !== 0) {
1046
+ job.phase = "error";
1047
+ job.error = `plugin-manager: 迁移失败且回滚到 ${restoreOld} 失败${restored.output === "" ? "" : `:\n${restored.output}`}`;
1048
+ return;
1049
+ }
1050
+ if (oldIndex >= 0) await reorderProfileBundle(this.facts.packageJsonPath, sourceId, oldIndex).catch(() => void 0);
1051
+ job.phase = "error";
1052
+ job.error = "plugin-manager: 聚合包迁移失败,已回滚到旧包";
1053
+ }
856
1054
  /** Spawn the CLI, through the test seam when present. */
857
1055
  spawnCli(binary, args) {
858
1056
  return (this.deps.spawnImpl ?? spawnDsh)(binary, args, this.env);
@@ -910,6 +1108,39 @@ var CliGateway = class {
910
1108
  ], ADD_TIMEOUT_MS));
911
1109
  return { jobId: job.id };
912
1110
  }
1111
+ /** Start a deterministic legacy aggregate migration. */
1112
+ migrate(sourceId, targetId, targetVersion, targetSpec) {
1113
+ const job = {
1114
+ id: `job-${++this.counter}`,
1115
+ action: "migrate",
1116
+ spec: targetSpec,
1117
+ sourceId,
1118
+ targetId,
1119
+ targetVersion,
1120
+ targetSpec,
1121
+ phase: "running"
1122
+ };
1123
+ this.jobs.set(job.id, job);
1124
+ const unsafe = unsafeSpecReason(sourceId) ?? unsafeSpecReason(targetId) ?? unsafeSpecReason(targetSpec);
1125
+ if (unsafe !== void 0) {
1126
+ job.phase = "error";
1127
+ job.error = unsafe;
1128
+ this.retainFinished(job.id);
1129
+ return { jobId: job.id };
1130
+ }
1131
+ this.enqueue(async () => {
1132
+ try {
1133
+ await this.runMigration(job);
1134
+ } catch (error) {
1135
+ if (job.phase !== "error") {
1136
+ job.phase = "error";
1137
+ job.error = `plugin-manager: unexpected migration failure: ${error instanceof Error ? error.message : String(error)}`;
1138
+ }
1139
+ }
1140
+ this.retainFinished(job.id);
1141
+ });
1142
+ return { jobId: job.id };
1143
+ }
913
1144
  /** Start a removal; the caller polls {@link status}. */
914
1145
  remove(id) {
915
1146
  const job = {
@@ -980,6 +1211,7 @@ var CliGateway = class {
980
1211
  rows,
981
1212
  bundles
982
1213
  },
1214
+ bundles,
983
1215
  patchText,
984
1216
  dependencies
985
1217
  };
@@ -1094,7 +1326,7 @@ var CliGateway = class {
1094
1326
  from: change.from,
1095
1327
  to: change.to
1096
1328
  }));
1097
- if (job.action !== "update") job.plugin = await this.rowFor(job.action, job.spec, before, after);
1329
+ if (job.action === "install" || job.action === "remove") job.plugin = await this.rowFor(job.action, job.spec, before, after);
1098
1330
  job.phase = "done";
1099
1331
  }
1100
1332
  /**
@@ -1464,6 +1696,52 @@ function dshRequirementOf(manifest) {
1464
1696
  return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
1465
1697
  }
1466
1698
  //#endregion
1699
+ //#region src/host/legacy-migration.ts
1700
+ /**
1701
+ * Deterministic mapping for the dsh-web aggregate package rename.
1702
+ *
1703
+ * The runtime identifiers (web-ui-* rows, settings section, API paths,
1704
+ * storage keys) stay frozen; only the npm aggregate package name changes.
1705
+ * This module is the single migration map shared by the plugin-manager
1706
+ * update job and the Doctor preflight launcher so they never drift.
1707
+ */
1708
+ /** The previously published aggregate package name. */
1709
+ const LEGACY_AGGREGATE = "@linxin666/dsh-web-ui-all";
1710
+ /** The current aggregate package name. */
1711
+ const CURRENT_AGGREGATE = "@linxin666/dsh-web-all";
1712
+ /** The only supported legacy aggregate migration. */
1713
+ const LEGACY_AGGREGATE_MIGRATION = {
1714
+ from: LEGACY_AGGREGATE,
1715
+ to: CURRENT_AGGREGATE
1716
+ };
1717
+ /** Whether a package name is the legacy aggregate. */
1718
+ function isLegacyAggregate(name) {
1719
+ return name === LEGACY_AGGREGATE;
1720
+ }
1721
+ /** Return the migration for a package name, or undefined when not legacy. */
1722
+ function legacyMigrationFor(name) {
1723
+ return isLegacyAggregate(name) ? LEGACY_AGGREGATE_MIGRATION : void 0;
1724
+ }
1725
+ /**
1726
+ * Build the exact target install spec for one legacy aggregate source.
1727
+ *
1728
+ * Local repository links are rewritten in place so development checkouts
1729
+ * keep using the repository tree; every other source is migrated through the
1730
+ * published package pinned to the family release version.
1731
+ */
1732
+ function targetSpecForLegacy(sourceSpec, familyVersion) {
1733
+ const raw = sourceSpec.trim();
1734
+ if (raw.startsWith("link:") || raw.startsWith("file:")) {
1735
+ const prefix = raw.slice(0, raw.indexOf(":"));
1736
+ const target = raw.slice(prefix.length + 1);
1737
+ const index = target.lastIndexOf("dsh-web-ui-all");
1738
+ if (index === -1) return void 0;
1739
+ return `${prefix}:${target.slice(0, index) + "dsh-web-all" + target.slice(index + 14)}`;
1740
+ }
1741
+ if (familyVersion === "") return void 0;
1742
+ return `${CURRENT_AGGREGATE}@${familyVersion}`;
1743
+ }
1744
+ //#endregion
1467
1745
  //#region src/host/routes.ts
1468
1746
  /** Route prefix the browser half mirrors. */
1469
1747
  const GATEWAY_PREFIX = "/api/plugin-manager";
@@ -1477,6 +1755,11 @@ const VERSION_ESCALATION_TIMEOUT_MS = 5e3;
1477
1755
  const VERSION_PROBE_TTL_MS = 5 * 6e4;
1478
1756
  /** Minimum gap between failed version probes (avoids a spawn per request). */
1479
1757
  const VERSION_PROBE_COOLDOWN_MS = 6e4;
1758
+ /**
1759
+ * Entry ids that must stay mounted so the local plugin-management escape hatch
1760
+ * remains available. Aggregate packages may still disable every other entry.
1761
+ */
1762
+ const SELF_MANAGED_ENTRY_IDS = /* @__PURE__ */ new Set(["ui-plugin-manager", "web-ui-plugin-manager"]);
1480
1763
  /** Error text for a caught request or lifecycle failure. */
1481
1764
  function messageOf(error) {
1482
1765
  return error instanceof Error ? error.message : String(error);
@@ -1661,6 +1944,36 @@ function makeGatewayRoutes(deps) {
1661
1944
  status: 404,
1662
1945
  error: `plugin-manager: plugin ${target} is not installed`
1663
1946
  };
1947
+ const migration = legacyMigrationFor(target);
1948
+ if (migration !== void 0) {
1949
+ const targetManifest = await fetchManifest(migration.to).catch(() => void 0);
1950
+ if (targetManifest === void 0 || targetManifest.version === "") return {
1951
+ status: 502,
1952
+ error: `plugin-manager: cannot resolve the migration target ${migration.to}`
1953
+ };
1954
+ const targetSpec = targetSpecForLegacy(row.source.spec, targetManifest.version);
1955
+ if (targetSpec === void 0) return {
1956
+ status: 400,
1957
+ error: `plugin-manager: cannot derive the migration target spec for ${target}`
1958
+ };
1959
+ const unsafeTarget = unsafeSpecReason(targetSpec);
1960
+ if (unsafeTarget !== void 0) return {
1961
+ status: 400,
1962
+ error: unsafeTarget
1963
+ };
1964
+ const requiresDsh = dshRequirementOf(targetManifest);
1965
+ if (requiresDsh !== void 0) {
1966
+ const { hostVersion, compatible } = await compatibleVerdict(requiresDsh);
1967
+ if (!compatible) return {
1968
+ status: 412,
1969
+ 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`
1970
+ };
1971
+ }
1972
+ return {
1973
+ status: 200,
1974
+ job: gateway.migrate(target, migration.to, targetManifest.version, targetSpec)
1975
+ };
1976
+ }
1664
1977
  if (row.source.kind !== "npm" || !isDirectRegistrySpec(row.source.spec)) return {
1665
1978
  status: 400,
1666
1979
  error: `plugin-manager: ${target} is not a direct npm registry plugin`
@@ -1758,7 +2071,10 @@ function makeGatewayRoutes(deps) {
1758
2071
  if ((await readProfileManifest(facts.packageJsonPath)).dependencies[target] === void 0) return { error: `plugin-manager: plugin ${target} is not installed` };
1759
2072
  const entries = await claimedEntryRowsOf(facts, target);
1760
2073
  let next = patchText;
1761
- for (const entry of entries) next = setRowEnabled(next, facts.patchPath, entry.id, entry.name, enabled);
2074
+ for (const entry of entries) {
2075
+ const entryEnabled = enabled || SELF_MANAGED_ENTRY_IDS.has(entry.id);
2076
+ next = setRowEnabled(next, facts.patchPath, entry.id, entry.name, entryEnabled);
2077
+ }
1762
2078
  if (next !== patchText) await writePatchAtomic(facts.patchPath, next);
1763
2079
  const plugin = (await snapshotGateway(facts, next)).plugins.find((item) => item.id === target);
1764
2080
  return plugin === void 0 ? { error: `plugin-manager: plugin ${target} is not installed` } : { plugin };
@@ -1792,6 +2108,26 @@ function makeGatewayRoutes(deps) {
1792
2108
  const snapshot = await snapshotGateway(facts, patchText);
1793
2109
  const updates = [];
1794
2110
  for (const plugin of snapshot.plugins) {
2111
+ const migration = legacyMigrationFor(plugin.id);
2112
+ if (migration !== void 0) {
2113
+ const targetManifest = await fetchManifest(migration.to).catch(() => void 0);
2114
+ if (targetManifest === void 0 || targetManifest.version === "") continue;
2115
+ const update = {
2116
+ id: plugin.id,
2117
+ current: plugin.version,
2118
+ latest: targetManifest.version,
2119
+ kind: "migrate",
2120
+ target: migration.to,
2121
+ targetVersion: targetManifest.version
2122
+ };
2123
+ const requiresDsh = dshRequirementOf(targetManifest);
2124
+ if (requiresDsh !== void 0) {
2125
+ update.requiresDsh = requiresDsh;
2126
+ update.compatible = (await compatibleVerdict(requiresDsh)).compatible;
2127
+ }
2128
+ updates.push(update);
2129
+ continue;
2130
+ }
1795
2131
  if (plugin.source.kind !== "npm" || !isDirectRegistrySpec(plugin.source.spec)) continue;
1796
2132
  const manifest = await fetchManifest(plugin.id).catch(() => void 0);
1797
2133
  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.3",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "types": "lib/types/index.d.ts",