@linxin666/dsh-client-ui-plugin-manager 0.4.7 → 0.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,15 +16,19 @@
16
16
  * @module @linxin666/dsh-client-ui-plugin-manager/client
17
17
  */
18
18
  import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
19
- import type { PluginUpdateItem, RestartMode } from '../core/protocol.ts';
19
+ import type { PluginUpdateItem, PluginUpdateResult, RestartMode } from '../core/protocol.ts';
20
20
  /** The operations the toolbar drives (the package's dual-channel face). */
21
21
  export interface PluginListToolbarInjected {
22
22
  /** Whether this browser has loopback authority to use the host routes. */
23
23
  isLoopback: boolean;
24
24
  /** Compare every installed plugin against the version its source serves. */
25
25
  checkUpdates: () => Promise<PluginUpdateItem[]>;
26
- /** Re-install one plugin from its recorded source. */
27
- update: (id: string) => Promise<unknown>;
26
+ /**
27
+ * Re-install one plugin from its recorded source. Resolves with what landed:
28
+ * the row at the new version, plus the bundles only a restart loads. A landed
29
+ * update that needs a restart keeps the batch running instead of failing it.
30
+ */
31
+ update: (id: string) => Promise<PluginUpdateResult>;
28
32
  /**
29
33
  * Read how a restart would be carried out, without carrying it out: the
30
34
  * confirmation must name the same consequence the host will produce (an
@@ -1,5 +1,5 @@
1
1
  import type { InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
2
- import type { InstallProgressItem, PluginUpdateItem } from '../core/protocol.ts';
2
+ import type { InstallProgressItem, PluginUpdateItem, PluginUpdateResult } from '../core/protocol.ts';
3
3
  /** One loader row of a bundle, as the official page's subject carries it. */
4
4
  export interface PluginPageRowRef {
5
5
  rowId: string;
@@ -54,13 +54,42 @@ export interface PluginUpdatePatchInjected {
54
54
  isLoopback: boolean;
55
55
  /** Compare every installed plugin against the version its source serves. */
56
56
  checkUpdates: () => Promise<PluginUpdateItem[]>;
57
- /** Re-install one plugin from its recorded source. */
58
- update: (id: string) => Promise<unknown>;
57
+ /**
58
+ * Re-install one plugin from its recorded source. Resolves with what landed:
59
+ * the row at the new version, plus the bundles only a restart loads. A landed
60
+ * update that needs a restart is not a failure and must not be reported as one.
61
+ */
62
+ update: (id: string) => Promise<PluginUpdateResult>;
59
63
  /** Read the current install/update progress. */
60
64
  status: () => Promise<InstallProgressItem>;
61
65
  }
62
66
  /** Full component props assembled by the Plugins page's section renderer. */
63
67
  export type PluginUpdatePatchProps = PropsRuntime<'plugins.detail.section'> & PropsLocale<'settings.pluginManager'> & InjectFace<PluginUpdatePatchInjected>;
68
+ /**
69
+ * What the host's compatibility verdict amounts to for one update row.
70
+ *
71
+ * `compatible === false` on its own does not mean "this DSH is too old": the
72
+ * host leaves `hostVersion` off a blocked row whenever it could not read its
73
+ * own runtime version (issue #1819) and whenever it could not evaluate the
74
+ * declared range at all — an empty declaration, a range node-semver rejects, a
75
+ * host string that is not one version (issue #1899). Only a row that carries a
76
+ * host version was actually compared against that version, so only that row
77
+ * may send the user to upgrade DSH.
78
+ *
79
+ * The verdict is derived here once and shared by both surfaces that render it
80
+ * (this section and the list-level toolbar) so the two cannot drift apart:
81
+ * that drift is what left the "cannot verify" case telling users to upgrade a
82
+ * DSH the host never checked.
83
+ */
84
+ export type DshGate = 'open' | 'below-minimum' | 'unverified';
85
+ /**
86
+ * Read the gate state out of one wire row.
87
+ * @param item - the update row, or undefined when no check has answered yet.
88
+ * @returns `open` when nothing blocks the update, otherwise the reason it is
89
+ * held back: `below-minimum` only when the host compared a version it read,
90
+ * `unverified` when it could not make that comparison.
91
+ */
92
+ export declare function dshGateOf(item: Pick<PluginUpdateItem, 'compatible' | 'hostVersion'> | undefined): DshGate;
64
93
  /**
65
94
  * The update block on one official Plugins page: one check action, the verdict
66
95
  * for this page's bundle, and the update action it unlocks. The check is
@@ -21,11 +21,13 @@ declare const STATIC_ZH: {
21
21
  updateRequiresDsh: string;
22
22
  updateBlockedDsh: string;
23
23
  updateUnverifiedDsh: string;
24
+ updateUnverifiedDshUnknownRange: string;
24
25
  restartHint: string;
25
26
  updatesAvailable: string;
26
27
  updateAll: string;
27
28
  updatingAll: string;
28
29
  updateAllDone: string;
30
+ updateRestartRequired: string;
29
31
  updatesPanelTitle: string;
30
32
  thirdPartyOnly: string;
31
33
  restartNow: string;
@@ -59,11 +61,13 @@ export declare const zh: {
59
61
  updateRequiresDsh: string;
60
62
  updateBlockedDsh: string;
61
63
  updateUnverifiedDsh: string;
64
+ updateUnverifiedDshUnknownRange: string;
62
65
  restartHint: string;
63
66
  updatesAvailable: string;
64
67
  updateAll: string;
65
68
  updatingAll: string;
66
69
  updateAllDone: string;
70
+ updateRestartRequired: string;
67
71
  updatesPanelTitle: string;
68
72
  thirdPartyOnly: string;
69
73
  restartNow: string;
@@ -97,11 +101,13 @@ export declare const en: {
97
101
  updateRequiresDsh: string;
98
102
  updateBlockedDsh: string;
99
103
  updateUnverifiedDsh: string;
104
+ updateUnverifiedDshUnknownRange: string;
100
105
  restartHint: string;
101
106
  updatesAvailable: string;
102
107
  updateAll: string;
103
108
  updatingAll: string;
104
109
  updateAllDone: string;
110
+ updateRestartRequired: string;
105
111
  updatesPanelTitle: string;
106
112
  thirdPartyOnly: string;
107
113
  restartNow: string;
@@ -6,8 +6,12 @@
6
6
  * The payload carries no conversation data and no identifiers beyond a random
7
7
  * UUID generated in localStorage; the server hashes it with a deployment salt
8
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.
9
+ * failures stay silent and simply retry on a later mount or day. Frames where
10
+ * storage is unavailable report nothing.
11
+ *
12
+ * The family-wide opt-out and the browser's Do Not Track signal both suppress
13
+ * the heartbeat; the Web Plugins settings switch writes the same localStorage
14
+ * key. The system is documented in docs/telemetry.md.
11
15
  */
12
16
  export type TelemetryChannel = 'market' | 'npm' | 'unknown';
13
17
  export interface TelemetryItem {
@@ -18,6 +22,14 @@ export interface TelemetryItem {
18
22
  /** Install channel when determinable (market = Workshop install). */
19
23
  channel?: TelemetryChannel;
20
24
  }
25
+ /** localStorage key carrying the family-wide telemetry opt-out ('1' = off). */
26
+ export declare const TELEMETRY_OPT_OUT_KEY = "dsh-web-ui-telemetry-opt-out";
27
+ /** Whether the user switched the family-wide opt-out on (reads storage only). */
28
+ export declare function isTelemetryOptedOut(): boolean;
29
+ /** Turn the family-wide opt-out on or off (writing '1' / removing the key); never throws. */
30
+ export declare function setTelemetryOptedOut(optedOut: boolean): void;
31
+ /** Whether a heartbeat must be suppressed right now: opt-out stored, or the browser asks not to be tracked. */
32
+ export declare function isTelemetrySuppressed(): boolean;
21
33
  /**
22
34
  * Fire the daily heartbeat for the given items at most once per UTC day per
23
35
  * browser. Never throws and never blocks the caller. Items without an explicit
@@ -50,6 +50,28 @@ export interface InstalledPluginItem {
50
50
  * neither is safe here, the user restarts DSH themselves.
51
51
  */
52
52
  export type RestartMode = 'relaunch' | 'shell' | 'manual';
53
+ /**
54
+ * The result of one applied update: the installed row, plus the host's verdict
55
+ * on whether this process can serve it without a restart.
56
+ *
57
+ * The two facts are separate because they answer different questions and must
58
+ * not be folded into one: the version landed (the row carries it), and the
59
+ * running host may still not have loaded it. Reporting the second as an error
60
+ * would be wrong twice over — the update did apply, and a batch update stops on
61
+ * the first error it sees — so it travels as an accompanying fact instead.
62
+ */
63
+ export interface PluginUpdateResult {
64
+ /** The installed row, at the version the update landed on. */
65
+ plugin: InstalledPluginItem;
66
+ /**
67
+ * Bundles whose new version is on disk but which the running host has not
68
+ * loaded, empty when the update took effect in place. The official manager
69
+ * reports this as `application: 'restart-required'` (issue #1905); the
70
+ * official installer channel carries no such fact, so it answers an empty
71
+ * list.
72
+ */
73
+ restartRequired: string[];
74
+ }
53
75
  /** Point-in-time install/update progress reported by the host. */
54
76
  export interface InstallProgressItem {
55
77
  kind: 'idle' | 'install' | 'update';
@@ -74,9 +96,11 @@ export interface PluginUpdateItem {
74
96
  /** Whether the running DSH host satisfies requiresDsh; absent when unknown. */
75
97
  compatible?: boolean;
76
98
  /**
77
- * The running DSH version the verdict was made from, when the host could read
78
- * it. Its absence is what separates "this host is too old" from "this host
79
- * could not be asked" — different problems, with different copy (issue #1819).
99
+ * The running DSH version the verdict was made from, present only when the
100
+ * host compared it and found it below the declaration. Its absence is what
101
+ * separates "this host is too old" from "we could not verify" — a host that
102
+ * could not be read, or a declaration that could not be parsed; different
103
+ * problems, with different copy (issues #1819 and #1899).
80
104
  */
81
105
  hostVersion?: string;
82
106
  }
@@ -110,6 +134,18 @@ export declare function parsePluginList(value: unknown): InstalledPluginItem[];
110
134
  * @returns the typed installed-plugin row.
111
135
  */
112
136
  export declare function parseInstalledPlugin(value: unknown): InstalledPluginItem;
137
+ /**
138
+ * Read the restart-required list off one gateway job (or off anything else
139
+ * carrying it).
140
+ *
141
+ * Deliberately tolerant where the other parsers in this module throw: this list
142
+ * is a hint attached to an update that already landed, so an unreadable value
143
+ * must cost the user the hint only. Throwing would reject an applied update and
144
+ * stop a batch run — the exact outcome the fact exists to avoid.
145
+ * @param value - decoded but untrusted job value.
146
+ * @returns the bundle names, empty when the value is absent or unusable.
147
+ */
148
+ export declare function parseRestartRequired(value: unknown): string[];
113
149
  /**
114
150
  * Validate and normalize a `status` response value.
115
151
  * @param value - decoded but untrusted response value.
@@ -1,17 +1,23 @@
1
1
  /**
2
- * DSH host version parsing and comparison for the update compatibility
2
+ * Version parsing plus the requirement reader for the update compatibility
3
3
  * check. The declared minimum lives in the published package manifest under
4
- * `dsh.engines.dsh`, falling back to the top-level `engines.dsh`; the only
5
- * supported form is `>=X.Y.Z[-prerelease]`.
4
+ * `dsh.engines.dsh`, falling back to the top-level `engines.dsh` and then to
5
+ * the `@deepseek-ai/dsh` peer; the range forms a manifest may use are the
6
+ * full node-semver range grammar.
6
7
  *
7
- * Comparison deliberately uses plain semver ordering instead of
8
- * `semver.satisfies`: npm's prerelease rule only allows a prerelease version
9
- * to satisfy a comparator set carrying a prerelease on the same
10
- * major.minor.patch tuple, which would reject a newer host line (0.1.1-rc.2)
11
- * against a declared `>=0.1.0-rc.8` — exactly the cross-cohort upgrade path
12
- * this check must allow. Everything here is pure and tolerant of untrusted
13
- * input: a malformed value means "cannot verify", which the callers treat as
14
- * a fail-closed verdict when a requirement was declared (issue #754).
8
+ * This module is shared by both halves and therefore stays free of `semver`,
9
+ * which is a node package: it parses and compares a single `X.Y.Z[-pre]`
10
+ * version, which is all the browser half needs to render a declared range
11
+ * (`displayMinimumVersion`) and all the host half needs to accept a probed
12
+ * host version (`parseDshVersion`). The range verdict itself lives in the
13
+ * host-only `../host/dsh-compat.ts`, which evaluates the declaration with
14
+ * `semver.satisfies(host, range, { includePrerelease: true })` — the exact
15
+ * call the official boot gate makes, so `||`, `^`, `~`, multi-comparator
16
+ * and x-ranges all decide the same way here as they do at boot.
17
+ *
18
+ * Everything here is pure and tolerant of untrusted input: a malformed value
19
+ * means "cannot verify", which the callers treat as a fail-closed verdict
20
+ * when a requirement was declared (issue #754).
15
21
  * @module @linxin666/dsh-client-ui-plugin-manager/core
16
22
  */
17
23
  /** One parsed DSH host or package version. */
@@ -34,21 +40,13 @@ export declare function parseDshVersion(value: string): DshVersion | undefined;
34
40
  * @returns -1 / 0 / 1, or undefined when either side is malformed.
35
41
  */
36
42
  export declare function compareVersions(left: string, right: string): number | undefined;
37
- /**
38
- * Whether a host version satisfies a declared `>=X.Y.Z[-prerelease]` minimum.
39
- * @param host - the running DSH host version.
40
- * @param minimum - the declared minimum; any form other than `>=<semver>`
41
- * (plain semver, `^`, `~`, multi-comparator ranges, empty) returns undefined.
42
- * @returns true / false, or undefined when the host version is malformed or
43
- * the minimum uses an unsupported form — callers treat undefined as
44
- * "cannot verify" and fail closed for declared requirements.
45
- */
46
- export declare function meetsMinimumDsh(host: string, minimum: string): boolean | undefined;
47
43
  /**
48
44
  * The bare minimum version for display: strips the `>=` operator (and an
49
45
  * optional leading `v`) from a declared requirement so UI copy that already
50
46
  * contains the comparison operator renders `0.1.1-rc.1` instead of
51
- * `>= >=0.1.1-rc.1`. Unsupported range forms render unchanged.
47
+ * `>= >=0.1.1-rc.1`. Every other range form renders unchanged — the browser
48
+ * half does not evaluate a range (the host does, in `../host/dsh-compat.ts`),
49
+ * so it must not pull a range parser into the client bundle to shorten copy.
52
50
  * @param minimum - the declared minimum range.
53
51
  * @returns the version portion for display.
54
52
  */
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The DSH runtime compatibility verdict for one declared plugin requirement,
3
+ * evaluated the way the official boot gate evaluates it
4
+ * (`evaluatePluginCompatibility` in app-boot's `plugin-compatibility.ts`):
5
+ * the requirement is a node-semver range and the host satisfies it when
6
+ * `semver.satisfies(host, range, { includePrerelease: true })` holds. Every
7
+ * legal range form therefore decides: `||` alternatives, `^` and `~`,
8
+ * whitespace-separated comparators, x-ranges, and prerelease tags compared as
9
+ * ordinary versions.
10
+ *
11
+ * The requirement itself comes from `dshRequirementOf` in
12
+ * `../core/version.ts`, which owns the field priority (this module only
13
+ * decides the verdict). Host-only on purpose: `semver` is a node package and
14
+ * must never be reachable from the browser half, which renders the same
15
+ * declaration through the regex-only `displayMinimumVersion`.
16
+ * @module @linxin666/dsh-client-ui-plugin-manager/host
17
+ */
18
+ /**
19
+ * The verdict for one declared requirement, with its cause kept apart so
20
+ * callers can tell "this host is too old" from "we could not check".
21
+ *
22
+ * The distinction is user-visible: a `host-too-low` verdict is the only one
23
+ * that may tell the user to upgrade DSH, because it is the only one where a
24
+ * running version was actually compared and lost. An `unverifiable` verdict
25
+ * means the question was never answered — an absent declaration, a range
26
+ * node-semver rejects, or a host string that is not one valid version — so
27
+ * telling the user to upgrade would send them after a fix nobody confirmed was
28
+ * needed (issue #1819), and reporting it as "below the minimum" contradicts a
29
+ * declaration that may well be satisfied (issue #1899).
30
+ */
31
+ export type DshCompatibility = {
32
+ verdict: 'satisfied';
33
+ } | {
34
+ verdict: 'host-too-low';
35
+ } | {
36
+ verdict: 'unverifiable';
37
+ };
38
+ /**
39
+ * Decide whether the running DSH host satisfies a declared requirement range.
40
+ * @param host - the running DSH host version.
41
+ * @param range - the declared requirement, in any node-semver range form.
42
+ * @returns `satisfied` when the host satisfies the declaration,
43
+ * `host-too-low` when it was compared and does not, and `unverifiable` when
44
+ * no comparison could be made. Callers fail closed on the last two (issue
45
+ * #754) but must not describe them with the same words.
46
+ */
47
+ export declare function evaluateDshCompatibility(host: string, range: string): DshCompatibility;
@@ -51,6 +51,16 @@ export interface GatewayJob {
51
51
  * the package itself stays installed and row-mounted.
52
52
  */
53
53
  notices?: ControlChange[];
54
+ /**
55
+ * Bundles whose new version is on disk but not loaded in this process: the
56
+ * official manager answered `application: 'restart-required'` for the run
57
+ * that applied it, so the plugin is installed and its rows are gone until the
58
+ * host restarts (issue #1905). Absent on an update that took effect in place.
59
+ * The job is still `done` either way — the version landed — and this fact
60
+ * rides the same job wire as `plugin`, so the caller can say so instead of
61
+ * reporting a clean in-place update.
62
+ */
63
+ restartRequired?: string[];
54
64
  error?: string;
55
65
  }
56
66
  /** The binary search roots for the dsh CLI. */
@@ -250,6 +260,17 @@ export interface NativePluginManager {
250
260
  * re-reads the profile as well, but must read this first — a refusal resolves.
251
261
  */
252
262
  removeBundle(name: string): Promise<unknown>;
263
+ /**
264
+ * Select or deselect a bundle layer while keeping the installed dependency.
265
+ * Present on every published manager (the official Plugins page drives it),
266
+ * and read here only to undo the deselection a refused removal leaves behind.
267
+ * Optional because the undo is best-effort: a manager without it still
268
+ * refuses the removal, and the report says what to do instead.
269
+ * @param name - installed bundle name.
270
+ * @param enabled - whether the bundle contributes its patch layer.
271
+ * @returns the manager's own verdict ({@link NativeManagerOutcome}).
272
+ */
273
+ setBundleEnabled?(name: string, enabled: boolean): Promise<unknown>;
253
274
  }
254
275
  /**
255
276
  * The verdict the official in-process manager returns for one mutation. Its
@@ -299,6 +320,21 @@ export declare function nativeManagerFailure(outcome: unknown): string | undefin
299
320
  * @returns the manager's failure code, or undefined for a run that did not fail.
300
321
  */
301
322
  export declare function nativeManagerRefusalCode(outcome: unknown): string | undefined;
323
+ /**
324
+ * Whether the official manager's verdict says the run landed but this process
325
+ * does not hold it yet. The manager answers `application: 'restart-required'`
326
+ * when the profile moved while the running host still carries the old state;
327
+ * on a two-phase replacement the removal alone can produce it, because the
328
+ * replaced bundle's rows are already gone from the running fiber tree by the
329
+ * time the guard reports the removal applied (issue #1905).
330
+ *
331
+ * Read as a success that carries a fact, never as a failure: the version did
332
+ * land on disk, so turning it into an error would send the caller into a
333
+ * rollback the profile does not need and stop a batch update on its first item.
334
+ * @param outcome - the resolved value of `installBundle` / `removeBundle`.
335
+ * @returns true when the run landed and a restart is what loads it.
336
+ */
337
+ export declare function nativeManagerRestartRequired(outcome: unknown): boolean;
302
338
  /** The gateway: serializes CLI operations through one job table and one mutation queue. */
303
339
  export declare class CliGateway {
304
340
  private readonly facts;
@@ -434,13 +470,81 @@ export declare class CliGateway {
434
470
  * A failed second phase reinstalls the spec the profile carried before the run,
435
471
  * so an update that cannot land leaves a working plugin behind instead of an
436
472
  * empty slot; the report says which of the two happened.
473
+ *
474
+ * Two facts make the replacement safe to repeat in one session:
475
+ *
476
+ * - **The bundle keeps its layer index.** A removal drops the name from
477
+ * `dsh.profile.bundles` and the reinstall appends it, so a plain
478
+ * remove-then-install moves the bundle behind every bundle that followed it
479
+ * and its patch layer starts overriding rows it never overrode
480
+ * ({@link restoreBundleIndex} puts it back).
481
+ * - **A `bundle-in-use` refusal is answered once, not repeated.** The
482
+ * official guard deselects the bundle and reloads before it checks whether
483
+ * the bundle's rows still run, so a real occupant cleared by that reload is
484
+ * gone on the second call: the update is retried exactly once against that
485
+ * settled state, and a second refusal restores the selection and names the
486
+ * restart the person has to do ({@link removeForReplacement}).
487
+ * - **A landed replacement can still need a restart.** The guard answers
488
+ * `application: 'restart-required'` when the removal applied and the
489
+ * replaced bundle's rows are already gone from the running process (issue
490
+ * #1905). The version does land, so that is a fact to report, not a failure:
491
+ * the update is `done` and names what only a restart loads.
492
+ *
437
493
  * @param job - the update job whose spec is installed.
438
494
  * @param native - the official manager.
439
495
  * @param targetId - the installed bundle being replaced.
440
496
  * @param previousSpec - the dependency spec the profile carried before the run.
441
- * @returns the failure to report, or undefined once the target spec landed.
497
+ * @returns the failure to report, or the restart fact once the target landed.
442
498
  */
443
499
  private replaceInstalled;
500
+ /**
501
+ * Where a bundle sits in the layer order, read before the removal drops it.
502
+ * @param name - the installed bundle name.
503
+ * @returns the index in `dsh.profile.bundles`, or undefined when the profile
504
+ * does not list it (nothing to restore in that case).
505
+ */
506
+ private bundleIndexOf;
507
+ /**
508
+ * Put a replaced bundle back at the layer index it had before the removal.
509
+ *
510
+ * The loader applies one patch layer per entry of `dsh.profile.bundles`, in
511
+ * that order, so the index is behavior: a bundle that is removed and
512
+ * reinstalled without this lands behind every bundle that followed it, and
513
+ * whole rows start inheriting from a layer that used to come first. The write
514
+ * is the manifest's own backup + tmp + rename path, and nothing is written
515
+ * when the profile already lists the bundle where it belongs.
516
+ * @param name - the reinstalled bundle.
517
+ * @param spec - the dependency spec the reinstall recorded (unused when the bundle is absent).
518
+ * @param index - the position captured before the removal.
519
+ */
520
+ private restoreBundleIndex;
521
+ /**
522
+ * Remove a bundle for the two-phase replacement, answering the official
523
+ * manager's in-use refusal instead of repeating it.
524
+ *
525
+ * Read the official `removeBundle` guard in order: it deselects the bundle,
526
+ * reloads the profile, and only then checks whether the bundle's own rows
527
+ * still hold a running fiber, which it reports as `bundle-in-use`. A refusal
528
+ * is therefore answered exactly once, against the state that reload left on
529
+ * disk: that covers a real occupant whose fiber the reload did clear.
530
+ *
531
+ * It does not cover a reload that rebuilds the very rows it just unloaded —
532
+ * the fresh fiber matches the guard again — so the retry is worth exactly one
533
+ * call and never a loop, and the second refusal names the restart instead of
534
+ * a bare code. A removal the guard does apply while the rows are already gone
535
+ * resolves as `application: 'restart-required'`; that is a success carrying a
536
+ * restart fact, which is reported as such rather than as a refusal.
537
+ * @param native - the official manager.
538
+ * @param name - the bundle to remove.
539
+ * @returns the refusal to report, whether the profile lost the selection on the
540
+ * way, the remedy text for that refusal, and whether the applied removal still
541
+ * needs a restart to load.
542
+ */
543
+ private removeForReplacement;
544
+ /** Whether a bundle is still an installed dependency but no longer selected. */
545
+ private bundleSelectionLost;
546
+ /** Put a selection back after a refused removal, so the profile is as it was found. */
547
+ private restoreBundleSelection;
444
548
  /** Start a deterministic legacy aggregate migration. */
445
549
  migrate(sourceId: string, targetId: string, targetVersion: string, targetSpec: string): {
446
550
  jobId: string;
@@ -505,15 +609,68 @@ export declare class CliGateway {
505
609
  * @returns the composed dump text, or undefined when it is unavailable.
506
610
  */
507
611
  private compositionOf;
612
+ /**
613
+ * The entry ids a user-layer override may still point at: the composed ids
614
+ * plus every id the profile's own bundle layers still declare.
615
+ *
616
+ * The composition alone does not prove a row is retired. A host that
617
+ * composes while a bundle is being replaced — the remove-then-install half of
618
+ * an application-owned update, or an upgrade whose packages are half
619
+ * installed — composes *without* the rows of the bundle that is momentarily
620
+ * gone, and pruning on that probe deletes the user's override for a row that
621
+ * still exists (0.4.7 lost `web-ui-remote-web-ui` and `ui-schedule` this
622
+ * way). Declarations live in the bundle layers, so they survive that window.
623
+ * @param composed - the entry ids of the composition probe.
624
+ * @returns the ids to keep, or undefined when a declared layer cannot be
625
+ * read, which proves nothing either way and must leave the file alone.
626
+ */
627
+ private liveOverrideIds;
628
+ /**
629
+ * The entry names the installed bundles' own rows carry, by entry id.
630
+ *
631
+ * The loader inserts one row per id and takes that row's name from the
632
+ * bundle's own patch file, so this map is the very fact the loader composes:
633
+ * a profile row naming something else is a row the loader skips.
634
+ *
635
+ * @returns the live names, or undefined when a bundle's patch cannot be read
636
+ * (which proves nothing either way and must leave the profile alone).
637
+ */
638
+ private liveEntryNames;
639
+ /**
640
+ * Point the profile's own rows at the packages that now carry those entry ids.
641
+ *
642
+ * A bundle that renames a row's package leaves every profile row that named
643
+ * the old one dead: the include patch semantics skip a row whose name does
644
+ * not match the inserted row, and the skip takes the whole row with it — a
645
+ * config row stops configuring and a `disabled` override stops disabling,
646
+ * both without a word in the browser. Issue #1901 moved the aggregate's
647
+ * family rows from the `@linxin666/dsh-web-all/<family>` subpath to the
648
+ * real package, so every profile row written before that upgrade went dead
649
+ * with it.
650
+ *
651
+ * The repair is idempotent and writes only when a row actually changed, so a
652
+ * healthy profile is never rewritten.
653
+ *
654
+ * @returns the repaired rows, in file order.
655
+ */
656
+ repairProfileRowNames(): Promise<Array<{
657
+ id: string;
658
+ from: string;
659
+ to: string;
660
+ }>>;
508
661
  /**
509
662
  * Post-update orphan guard: drop this package's own enablement overrides
510
- * whose entry id the composed *target* profile no longer carries. The
511
- * authority is the loader's own composition after the update
512
- * ({@link composedEntryIdsOf}), not the profile patch and not the source
513
- * profile: an override is only orphaned once the target composition stops
514
- * declaring that id, and ids the official base or another bundle still
515
- * mounts stay valid. A retired row would otherwise leave a stale override
516
- * that the loader reports on every boot as `patch: entry "<id>" not found`.
663
+ * whose entry id neither the composed *target* profile nor any bundle layer
664
+ * still declares. The composition is the loader's own after the update
665
+ * ({@link composedEntryIdsOf}), widened by the bundle layers' declarations
666
+ * ({@link liveOverrideIds}) because a composition taken mid-upgrade omits
667
+ * rows that still exist. A retired row would otherwise leave a stale
668
+ * override that the loader reports on every boot as
669
+ * `patch: entry "<id>" not found`.
670
+ *
671
+ * The stale-row-name repair ({@link repairProfileRowNames}) runs first and
672
+ * on its own authority, so a profile whose bundle declarations cannot be
673
+ * resolved is repaired even though the prune then writes nothing.
517
674
  *
518
675
  * Nothing is written when nothing is orphaned — a second run over a pruned
519
676
  * profile returns the input text untouched, so no write and no second backup
@@ -7,6 +7,19 @@
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
+ *
11
+ * A reverse proxy in front of the host rewrites the Host header to its own
12
+ * upstream literal (a Cloudflare tunnel, frp and an nginx reverse proxy all
13
+ * dial 127.0.0.1:<port>), and the socket the origin sees is the proxy's, which
14
+ * is loopback by construction. Both halves of the fence then hold for a public
15
+ * request. Forwarding headers are the signal that a hop stands in between: a
16
+ * request that carries CF-Connecting-IP or X-Forwarded-For is answered through
17
+ * a proxy and is never treated as a local one (issue #1906).
18
+ *
19
+ * An operator who runs that proxy or tunnel themselves can opt into the
20
+ * narrower case: isForwardedLoopbackRequest describes a forwarded request that
21
+ * still landed on this machine's loopback upstream, and a route family admits
22
+ * it only behind its own default-off switch (issue #1918).
10
23
  * @module dsh-web-shared/host/loopback
11
24
  */
12
25
  import type { IncomingMessage } from 'node:http';
@@ -16,9 +29,36 @@ export declare function isIPv4Loopback(v4: string): boolean;
16
29
  export declare function isLoopbackAddress(address: string | undefined): boolean;
17
30
  /** Whether a normalized URL hostname names the loopback authority (localhost, [::1], 127/8). */
18
31
  export declare function isLoopbackHostname(hostname: string): boolean;
32
+ /**
33
+ * Whether a reverse proxy stood between the client and this host: the request
34
+ * carries CF-Connecting-IP or X-Forwarded-For. Either header is stamped by a
35
+ * hop that forwards traffic, so the request did not originate on this machine.
36
+ * @param request - node HTTP request.
37
+ * @returns true when a forwarding header is present.
38
+ */
39
+ export declare function isProxiedRequest(request: IncomingMessage): boolean;
19
40
  /**
20
41
  * Request-level trust fence: a loopback socket address AND a loopback Host
21
42
  * header, plus browser same-origin markers. The socket address is
22
- * authoritative; X-Forwarded-For is never trusted.
43
+ * authoritative for a direct connection; a request that carries a forwarding
44
+ * header is refused outright, because a proxy in front of the host makes both
45
+ * the socket address and the Host header describe the proxy rather than the
46
+ * client. X-Forwarded-For is therefore never evidence *for* loopback.
23
47
  */
24
48
  export declare function isLoopbackRequest(request: IncomingMessage): boolean;
49
+ /**
50
+ * Whether a forwarded request landed on this machine's loopback upstream: a
51
+ * forwarding header (the proxy's own stamp), a loopback socket address (the
52
+ * proxy dials 127.0.0.1:<port>), and a loopback Host header (the proxy rewrote
53
+ * the authority to its upstream literal).
54
+ *
55
+ * This is a fact about the route, not a trust decision. A public request to a
56
+ * tunnel satisfies all three by construction, because the proxy is the client
57
+ * of this process: only a caller that operates the proxy can decide it stands
58
+ * for the browser, which is why every consumer keeps this behind an explicit
59
+ * default-off switch and its own browser markers. isLoopbackRequest is
60
+ * unchanged and still refuses a forwarded request (issue #1906).
61
+ * @param request - node HTTP request.
62
+ * @returns true when a forwarding header, a loopback socket, and a loopback Host all hold.
63
+ */
64
+ export declare function isForwardedLoopbackRequest(request: IncomingMessage): boolean;
@@ -13,6 +13,12 @@
13
13
  * crashed. The plugin therefore stops the host and lets the shell run the
14
14
  * restart it already owns (app.relaunch(), the same recovery action the
15
15
  * Desktop app offers after installing a downloaded update). Mode 'shell'.
16
+ * That only holds for a shell that ACTUALLY restarts a host that exits. A
17
+ * shell that merely reports the stop leaves a dead window with no host —
18
+ * strictly worse than not restarting at all — so the shell must announce the
19
+ * guarantee in {@link SHELL_RESTART_CAPABILITY_ENV}; a host that sees no such
20
+ * marker answers 'manual' instead of stopping itself (see
21
+ * {@link shellRestartIsSupported}).
16
22
  * - A host this plugin can prove is a terminal launch (an interactive stdio
17
23
  * pair, no Electron in the environment) is restarted in place: a detached
18
24
  * helper waits for this process to exit and re-executes the same command
@@ -59,6 +65,23 @@ export interface RestartFacts {
59
65
  }
60
66
  /** Grace period between answering the restart request and leaving the process. */
61
67
  export declare const RESTART_EXIT_DELAY_MS = 400;
68
+ /**
69
+ * Environment marker a Desktop shell sets when it guarantees that a host which
70
+ * exits is replaced by a fresh host (rather than reported as stopped).
71
+ *
72
+ * The packaged Desktop shell owns the process tree but has no obligation to
73
+ * respawn it: the shipped shell in this repository's compat matrix answers a
74
+ * host exit with `desktop host stopped` and an error page. Stopping ourselves
75
+ * under such a shell turns the restart button into "kill the app", so the mode
76
+ * requires proof of the opposite behaviour.
77
+ */
78
+ export declare const SHELL_RESTART_CAPABILITY_ENV = "DSH_SHELL_RESTARTS_HOST";
79
+ /**
80
+ * Whether the launching shell promises to bring the host back after it exits.
81
+ * @param env - the environment the host was launched with.
82
+ * @returns true only for an opt-in marker value of `1`.
83
+ */
84
+ export declare function shellRestartIsSupported(env: NodeJS.ProcessEnv): boolean;
62
85
  /** How long the helper waits for this process to disappear before giving up on the wait. */
63
86
  export declare const RESTART_WAIT_MS = 30000;
64
87
  /**