@linxin666/dsh-client-ui-plugin-manager 0.4.6 → 0.4.8
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/README.i18n.yaml +2 -2
- package/README.md +4 -4
- package/README.zh.md +4 -4
- package/lib/client.js +76 -35
- package/lib/client.js.map +1 -1
- package/lib/index.js +859 -123
- package/lib/types/client/PluginUpdatePatch.d.ts +25 -0
- package/lib/types/client/locales.d.ts +3 -0
- package/lib/types/client/telemetry.d.ts +14 -2
- package/lib/types/core/protocol.d.ts +5 -3
- package/lib/types/core/version.d.ts +20 -22
- package/lib/types/host/dsh-compat.d.ts +47 -0
- package/lib/types/host/gateway.d.ts +283 -6
- package/lib/types/host/loopback.d.ts +20 -1
- package/lib/types/host/restart.d.ts +23 -0
- package/lib/types/host/rows.d.ts +83 -0
- package/lib/types/host/state.d.ts +10 -6
- package/package.json +17 -15
|
@@ -61,6 +61,31 @@ export interface PluginUpdatePatchInjected {
|
|
|
61
61
|
}
|
|
62
62
|
/** Full component props assembled by the Plugins page's section renderer. */
|
|
63
63
|
export type PluginUpdatePatchProps = PropsRuntime<'plugins.detail.section'> & PropsLocale<'settings.pluginManager'> & InjectFace<PluginUpdatePatchInjected>;
|
|
64
|
+
/**
|
|
65
|
+
* What the host's compatibility verdict amounts to for one update row.
|
|
66
|
+
*
|
|
67
|
+
* `compatible === false` on its own does not mean "this DSH is too old": the
|
|
68
|
+
* host leaves `hostVersion` off a blocked row whenever it could not read its
|
|
69
|
+
* own runtime version (issue #1819) and whenever it could not evaluate the
|
|
70
|
+
* declared range at all — an empty declaration, a range node-semver rejects, a
|
|
71
|
+
* host string that is not one version (issue #1899). Only a row that carries a
|
|
72
|
+
* host version was actually compared against that version, so only that row
|
|
73
|
+
* may send the user to upgrade DSH.
|
|
74
|
+
*
|
|
75
|
+
* The verdict is derived here once and shared by both surfaces that render it
|
|
76
|
+
* (this section and the list-level toolbar) so the two cannot drift apart:
|
|
77
|
+
* that drift is what left the "cannot verify" case telling users to upgrade a
|
|
78
|
+
* DSH the host never checked.
|
|
79
|
+
*/
|
|
80
|
+
export type DshGate = 'open' | 'below-minimum' | 'unverified';
|
|
81
|
+
/**
|
|
82
|
+
* Read the gate state out of one wire row.
|
|
83
|
+
* @param item - the update row, or undefined when no check has answered yet.
|
|
84
|
+
* @returns `open` when nothing blocks the update, otherwise the reason it is
|
|
85
|
+
* held back: `below-minimum` only when the host compared a version it read,
|
|
86
|
+
* `unverified` when it could not make that comparison.
|
|
87
|
+
*/
|
|
88
|
+
export declare function dshGateOf(item: Pick<PluginUpdateItem, 'compatible' | 'hostVersion'> | undefined): DshGate;
|
|
64
89
|
/**
|
|
65
90
|
* The update block on one official Plugins page: one check action, the verdict
|
|
66
91
|
* for this page's bundle, and the update action it unlocks. The check is
|
|
@@ -21,6 +21,7 @@ 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;
|
|
@@ -59,6 +60,7 @@ export declare const zh: {
|
|
|
59
60
|
updateRequiresDsh: string;
|
|
60
61
|
updateBlockedDsh: string;
|
|
61
62
|
updateUnverifiedDsh: string;
|
|
63
|
+
updateUnverifiedDshUnknownRange: string;
|
|
62
64
|
restartHint: string;
|
|
63
65
|
updatesAvailable: string;
|
|
64
66
|
updateAll: string;
|
|
@@ -97,6 +99,7 @@ export declare const en: {
|
|
|
97
99
|
updateRequiresDsh: string;
|
|
98
100
|
updateBlockedDsh: string;
|
|
99
101
|
updateUnverifiedDsh: string;
|
|
102
|
+
updateUnverifiedDshUnknownRange: string;
|
|
100
103
|
restartHint: string;
|
|
101
104
|
updatesAvailable: string;
|
|
102
105
|
updateAll: 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.
|
|
10
|
-
* is
|
|
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
|
|
@@ -74,9 +74,11 @@ export interface PluginUpdateItem {
|
|
|
74
74
|
/** Whether the running DSH host satisfies requiresDsh; absent when unknown. */
|
|
75
75
|
compatible?: boolean;
|
|
76
76
|
/**
|
|
77
|
-
* The running DSH version the verdict was made from, when the
|
|
78
|
-
*
|
|
79
|
-
*
|
|
77
|
+
* The running DSH version the verdict was made from, present only when the
|
|
78
|
+
* host compared it and found it below the declaration. Its absence is what
|
|
79
|
+
* separates "this host is too old" from "we could not verify" — a host that
|
|
80
|
+
* could not be read, or a declaration that could not be parsed; different
|
|
81
|
+
* problems, with different copy (issues #1819 and #1899).
|
|
80
82
|
*/
|
|
81
83
|
hostVersion?: string;
|
|
82
84
|
}
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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
|
|
5
|
-
*
|
|
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
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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`.
|
|
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;
|
|
@@ -13,9 +13,11 @@
|
|
|
13
13
|
* plugin manager instead (see {@link NativePluginManager}).
|
|
14
14
|
* @module @linxin666/dsh-client-ui-plugin-manager/host
|
|
15
15
|
*/
|
|
16
|
+
import { type ChildProcess } from 'node:child_process';
|
|
16
17
|
import type { InstalledPluginItem } from '../core/protocol.ts';
|
|
17
18
|
import type { ControlChange } from '../core/conflict.ts';
|
|
18
19
|
import { type ProfileFacts } from './profile.ts';
|
|
20
|
+
import { type OutputCapture } from './console-output.ts';
|
|
19
21
|
/**
|
|
20
22
|
* Validate an install spec or package id against shell metacharacters.
|
|
21
23
|
* @param spec - the user-supplied spec or id.
|
|
@@ -94,6 +96,24 @@ export declare function dshSpawnCommand(binary: string, platform?: string, local
|
|
|
94
96
|
command: string;
|
|
95
97
|
argsPrefix: string[];
|
|
96
98
|
};
|
|
99
|
+
/**
|
|
100
|
+
* Absolute path of the Windows command processor, resolved from an environment
|
|
101
|
+
* rather than from PATH.
|
|
102
|
+
*
|
|
103
|
+
* Every `.cmd` shim still has to be executed through cmd.exe, and a bare
|
|
104
|
+
* `cmd.exe` spawn resolves through the host PATH: a GUI-launched host whose PATH
|
|
105
|
+
* carries no `%SystemRoot%\system32` (a packaged Desktop launch, a service, a
|
|
106
|
+
* stripped environment) gets ENOENT for a name that is present on disk, and the
|
|
107
|
+
* whole feature fails with it (issue #1857). ComSpec is the variable Windows
|
|
108
|
+
* itself uses for this and names the real binary, so it is preferred; otherwise
|
|
109
|
+
* the system root is read from `SystemRoot` or `windir`, with the conventional
|
|
110
|
+
* `C:\Windows` as the last resort.
|
|
111
|
+
*
|
|
112
|
+
* Only the Windows branch needs it — a POSIX host spawns the CLI directly.
|
|
113
|
+
* @param env - the environment to resolve from.
|
|
114
|
+
* @returns the absolute cmd.exe path.
|
|
115
|
+
*/
|
|
116
|
+
export declare function windowsCmdPath(env?: NodeJS.ProcessEnv): string;
|
|
97
117
|
/** Build the exact cmd.exe command line required to execute a trusted .cmd shim. */
|
|
98
118
|
export declare function windowsCmdShimArgs(binary: string, args: readonly string[]): string[];
|
|
99
119
|
/**
|
|
@@ -108,6 +128,53 @@ export declare function windowsCmdShimArgs(binary: string, args: readonly string
|
|
|
108
128
|
* @returns a new environment with one normalized, prepended PATH.
|
|
109
129
|
*/
|
|
110
130
|
export declare function withPrependedPath(env: NodeJS.ProcessEnv, dir: string, platform?: string): NodeJS.ProcessEnv;
|
|
131
|
+
/**
|
|
132
|
+
* Exit code reported for a child that never became a process. Node delivers a
|
|
133
|
+
* failed spawn as an `error` event whose `close` may never follow, and every
|
|
134
|
+
* consumer of a spawned child waits for `close` alone.
|
|
135
|
+
*/
|
|
136
|
+
export declare const SPAWN_FAILURE_EXIT_CODE = -1;
|
|
137
|
+
/**
|
|
138
|
+
* Attach the error fallback every spawn outlet needs.
|
|
139
|
+
*
|
|
140
|
+
* A ChildProcess without an `error` listener turns a spawn failure into an
|
|
141
|
+
* unhandled `error` event, which is an uncaught exception: the failure of one
|
|
142
|
+
* CLI call took the whole dsh host process down with it. This records the
|
|
143
|
+
* reason and, when the child never closed, settles it as a failed exit so a
|
|
144
|
+
* caller that only waits for `close` neither hangs nor crashes (issue #1857).
|
|
145
|
+
* @param child - the spawned child.
|
|
146
|
+
* @returns the same child, guarded.
|
|
147
|
+
*/
|
|
148
|
+
export declare function guardSpawnFailure(child: ChildProcess): ChildProcess;
|
|
149
|
+
/** One spawned child's exit verdict. */
|
|
150
|
+
export interface ChildExit {
|
|
151
|
+
/** The process exit code, or {@link SPAWN_FAILURE_EXIT_CODE} when it never started. */
|
|
152
|
+
code: number | null;
|
|
153
|
+
/** The spawn failure reason, present only when no process was created. */
|
|
154
|
+
spawnError?: string;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Wait for a spawned child to close, settling on a spawn failure as well.
|
|
158
|
+
*
|
|
159
|
+
* The listener pair is attached to every child this package waits on, so the
|
|
160
|
+
* wait is safe for a child that arrived through a seam ({@link guardSpawnFailure}
|
|
161
|
+
* guards the real spawn outlets, an injected one may skip it).
|
|
162
|
+
* @param child - the spawned child.
|
|
163
|
+
* @returns the exit verdict.
|
|
164
|
+
*/
|
|
165
|
+
export declare function awaitChildExit(child: ChildProcess): Promise<ChildExit>;
|
|
166
|
+
/**
|
|
167
|
+
* Wait for one spawned CLI child, folding a spawn failure into its output.
|
|
168
|
+
*
|
|
169
|
+
* Every caller already reports a non-zero exit through the captured output, so
|
|
170
|
+
* a process that never started is reported the same readable way instead of as
|
|
171
|
+
* a silent failure or a hang.
|
|
172
|
+
* @param child - the spawned child.
|
|
173
|
+
* @param output - the bounded capture the failure text is appended to.
|
|
174
|
+
* @param timeoutMs - kill the child after this long; omitted for no deadline.
|
|
175
|
+
* @returns the exit code, or null when a signal ended the child.
|
|
176
|
+
*/
|
|
177
|
+
export declare function awaitCliExit(child: ChildProcess, output: OutputCapture, timeoutMs?: number): Promise<number | null>;
|
|
111
178
|
/**
|
|
112
179
|
* Spawn the dsh CLI with piped stdio and no shell parsing (see
|
|
113
180
|
* {@link dshSpawnCommand}).
|
|
@@ -118,12 +185,26 @@ export declare function withPrependedPath(env: NodeJS.ProcessEnv, dir: string, p
|
|
|
118
185
|
* `dsh plugin` to pnpm, so without this the update would start and then fail on
|
|
119
186
|
* a missing pnpm instead. This mirrors the packaged Desktop launcher, which
|
|
120
187
|
* prepends its bundled runtime bin to the host it spawns.
|
|
188
|
+
*
|
|
189
|
+
* Every child leaves here guarded ({@link guardSpawnFailure}), so a spawn that
|
|
190
|
+
* fails settles as a non-zero exit instead of raising an unhandled error.
|
|
121
191
|
* @param binary - the resolved dsh CLI path.
|
|
122
192
|
* @param args - arguments after the interpreter/script prefix.
|
|
123
193
|
* @param env - the host environment.
|
|
124
194
|
* @returns the spawned child process.
|
|
125
195
|
*/
|
|
126
|
-
export declare function spawnDsh(binary: string, args: string[], env: NodeJS.ProcessEnv):
|
|
196
|
+
export declare function spawnDsh(binary: string, args: string[], env: NodeJS.ProcessEnv): ChildProcess;
|
|
197
|
+
/**
|
|
198
|
+
* The entry ids of a composed profile dump (`dsh --profile <name>
|
|
199
|
+
* --dump-config`). The dump prints one YAML block per patch layer under a
|
|
200
|
+
* `# ==` header, with the composed entries as column-0 `- id:` items — an
|
|
201
|
+
* entry a profile patch overrides appears once, carrying the override's keys,
|
|
202
|
+
* so those lines are exactly the loader's own entry set. Nested config keeps
|
|
203
|
+
* its own `id` keys indented and is never mistaken for an entry.
|
|
204
|
+
* @param dump - the dump's captured text.
|
|
205
|
+
* @returns the composed entry ids, or undefined when the dump carried none.
|
|
206
|
+
*/
|
|
207
|
+
export declare function composedEntryIdsOf(dump: string): Set<string> | undefined;
|
|
127
208
|
/**
|
|
128
209
|
* Detect whether the official installer channels exist on this runtime by
|
|
129
210
|
* dumping the boot composition once: the npm-published web never contains
|
|
@@ -149,7 +230,10 @@ export declare function detectOfficialChannels(binary: string, profileName: stri
|
|
|
149
230
|
*/
|
|
150
231
|
export interface NativePluginManager {
|
|
151
232
|
/**
|
|
152
|
-
* Install
|
|
233
|
+
* Install one package spec through the official manager. Since 0.2.1-rc.2 it
|
|
234
|
+
* refuses a package the profile already carries while the host mounts the `hmr`
|
|
235
|
+
* service (`already-installed`), which is every profile host, so an in-place
|
|
236
|
+
* update cannot be one call there.
|
|
153
237
|
* @param spec - package spec (e.g. `@scope/pkg@1.2.3`).
|
|
154
238
|
* @param options - activation choice and the request id the run is tracked under.
|
|
155
239
|
* @returns the manager's own verdict ({@link NativeManagerOutcome}); the caller
|
|
@@ -166,6 +250,17 @@ export interface NativePluginManager {
|
|
|
166
250
|
* re-reads the profile as well, but must read this first — a refusal resolves.
|
|
167
251
|
*/
|
|
168
252
|
removeBundle(name: string): Promise<unknown>;
|
|
253
|
+
/**
|
|
254
|
+
* Select or deselect a bundle layer while keeping the installed dependency.
|
|
255
|
+
* Present on every published manager (the official Plugins page drives it),
|
|
256
|
+
* and read here only to undo the deselection a refused removal leaves behind.
|
|
257
|
+
* Optional because the undo is best-effort: a manager without it still
|
|
258
|
+
* refuses the removal, and the report says what to do instead.
|
|
259
|
+
* @param name - installed bundle name.
|
|
260
|
+
* @param enabled - whether the bundle contributes its patch layer.
|
|
261
|
+
* @returns the manager's own verdict ({@link NativeManagerOutcome}).
|
|
262
|
+
*/
|
|
263
|
+
setBundleEnabled?(name: string, enabled: boolean): Promise<unknown>;
|
|
169
264
|
}
|
|
170
265
|
/**
|
|
171
266
|
* The verdict the official in-process manager returns for one mutation. Its
|
|
@@ -205,6 +300,16 @@ export interface NativeManagerOutcome {
|
|
|
205
300
|
* @returns the failure text to report, or undefined for a run that did not fail.
|
|
206
301
|
*/
|
|
207
302
|
export declare function nativeManagerFailure(outcome: unknown): string | undefined;
|
|
303
|
+
/**
|
|
304
|
+
* The official manager's own refusal code for one run, or undefined when its
|
|
305
|
+
* verdict is not a failure. {@link nativeManagerFailure} renders the code for the
|
|
306
|
+
* person; this is the same verdict read for a decision, which is how the update
|
|
307
|
+
* path recognises the `already-installed` refusal it has to answer with a
|
|
308
|
+
* two-phase replacement.
|
|
309
|
+
* @param outcome - the resolved value of `installBundle` / `removeBundle`.
|
|
310
|
+
* @returns the manager's failure code, or undefined for a run that did not fail.
|
|
311
|
+
*/
|
|
312
|
+
export declare function nativeManagerRefusalCode(outcome: unknown): string | undefined;
|
|
208
313
|
/** The gateway: serializes CLI operations through one job table and one mutation queue. */
|
|
209
314
|
export declare class CliGateway {
|
|
210
315
|
private readonly facts;
|
|
@@ -319,10 +424,92 @@ export declare class CliGateway {
|
|
|
319
424
|
* run (pnpm exited non-zero, an incompatible version, a cancellation) resolves
|
|
320
425
|
* with `application: 'failed'`, and only that verdict carries the reason — the
|
|
321
426
|
* profile re-read can only show that the version did not move.
|
|
427
|
+
*
|
|
428
|
+
* An `already-installed` refusal is answered by {@link replaceInstalled}: the
|
|
429
|
+
* manager refuses to install a dependency the profile already carries while the
|
|
430
|
+
* host mounts `hmr` (0.2.1-rc.2, and dsh-base mounts that service on every
|
|
431
|
+
* profile host), so an in-place update there is only expressible as its two
|
|
432
|
+
* phases. The single call stays first so the day the manager accepts an
|
|
433
|
+
* in-place update this path needs no change.
|
|
322
434
|
* @param job - the update job being settled.
|
|
323
435
|
* @param native - the official manager.
|
|
324
436
|
*/
|
|
325
437
|
private runNativeUpdate;
|
|
438
|
+
/**
|
|
439
|
+
* Replace an installed bundle with the update job's target spec through the
|
|
440
|
+
* official manager, the only writer an application-owned profile accepts.
|
|
441
|
+
* Removing first is what makes the install possible: the manager's
|
|
442
|
+
* `already-installed` guard reads the profile, so the same name is a fresh
|
|
443
|
+
* dependency once the old one is gone.
|
|
444
|
+
*
|
|
445
|
+
* A failed second phase reinstalls the spec the profile carried before the run,
|
|
446
|
+
* so an update that cannot land leaves a working plugin behind instead of an
|
|
447
|
+
* empty slot; the report says which of the two happened.
|
|
448
|
+
*
|
|
449
|
+
* Two facts make the replacement safe to repeat in one session:
|
|
450
|
+
*
|
|
451
|
+
* - **The bundle keeps its layer index.** A removal drops the name from
|
|
452
|
+
* `dsh.profile.bundles` and the reinstall appends it, so a plain
|
|
453
|
+
* remove-then-install moves the bundle behind every bundle that followed it
|
|
454
|
+
* and its patch layer starts overriding rows it never overrode
|
|
455
|
+
* ({@link restoreBundleIndex} puts it back).
|
|
456
|
+
* - **A `bundle-in-use` refusal is answered once, not repeated.** The
|
|
457
|
+
* official guard deselects the bundle and reloads before it checks whether
|
|
458
|
+
* the bundle's rows still run, so a refusal means the session still holds
|
|
459
|
+
* them: the update is retried exactly once against that settled state, and a
|
|
460
|
+
* second refusal restores the selection and names the restart the person has
|
|
461
|
+
* to do ({@link removeForReplacement}).
|
|
462
|
+
*
|
|
463
|
+
* @param job - the update job whose spec is installed.
|
|
464
|
+
* @param native - the official manager.
|
|
465
|
+
* @param targetId - the installed bundle being replaced.
|
|
466
|
+
* @param previousSpec - the dependency spec the profile carried before the run.
|
|
467
|
+
* @returns the failure to report, or undefined once the target spec landed.
|
|
468
|
+
*/
|
|
469
|
+
private replaceInstalled;
|
|
470
|
+
/**
|
|
471
|
+
* Where a bundle sits in the layer order, read before the removal drops it.
|
|
472
|
+
* @param name - the installed bundle name.
|
|
473
|
+
* @returns the index in `dsh.profile.bundles`, or undefined when the profile
|
|
474
|
+
* does not list it (nothing to restore in that case).
|
|
475
|
+
*/
|
|
476
|
+
private bundleIndexOf;
|
|
477
|
+
/**
|
|
478
|
+
* Put a replaced bundle back at the layer index it had before the removal.
|
|
479
|
+
*
|
|
480
|
+
* The loader applies one patch layer per entry of `dsh.profile.bundles`, in
|
|
481
|
+
* that order, so the index is behavior: a bundle that is removed and
|
|
482
|
+
* reinstalled without this lands behind every bundle that followed it, and
|
|
483
|
+
* whole rows start inheriting from a layer that used to come first. The write
|
|
484
|
+
* is the manifest's own backup + tmp + rename path, and nothing is written
|
|
485
|
+
* when the profile already lists the bundle where it belongs.
|
|
486
|
+
* @param name - the reinstalled bundle.
|
|
487
|
+
* @param spec - the dependency spec the reinstall recorded (unused when the bundle is absent).
|
|
488
|
+
* @param index - the position captured before the removal.
|
|
489
|
+
*/
|
|
490
|
+
private restoreBundleIndex;
|
|
491
|
+
/**
|
|
492
|
+
* Remove a bundle for the two-phase replacement, answering the official
|
|
493
|
+
* manager's in-use refusal instead of repeating it.
|
|
494
|
+
*
|
|
495
|
+
* Read the official `removeBundle` guard in order: it deselects the bundle,
|
|
496
|
+
* reloads the profile, and only then checks whether the bundle's own rows
|
|
497
|
+
* still hold a running fiber, which it reports as `bundle-in-use`. The
|
|
498
|
+
* deselection is therefore already on disk when the refusal arrives — the
|
|
499
|
+
* guard re-reads the selection on entry, so asking once more after that
|
|
500
|
+
* settled state is idempotent and is the only way an update can continue
|
|
501
|
+
* without a restart. A second refusal means the rows really are still
|
|
502
|
+
* loaded, and the report then names the restart instead of a bare code.
|
|
503
|
+
* @param native - the official manager.
|
|
504
|
+
* @param name - the bundle to remove.
|
|
505
|
+
* @returns the refusal to report, whether the profile lost the selection on the
|
|
506
|
+
* way, and the remedy text for that refusal.
|
|
507
|
+
*/
|
|
508
|
+
private removeForReplacement;
|
|
509
|
+
/** Whether a bundle is still an installed dependency but no longer selected. */
|
|
510
|
+
private bundleSelectionLost;
|
|
511
|
+
/** Put a selection back after a refused removal, so the profile is as it was found. */
|
|
512
|
+
private restoreBundleSelection;
|
|
326
513
|
/** Start a deterministic legacy aggregate migration. */
|
|
327
514
|
migrate(sourceId: string, targetId: string, targetVersion: string, targetSpec: string): {
|
|
328
515
|
jobId: string;
|
|
@@ -376,6 +563,91 @@ export declare class CliGateway {
|
|
|
376
563
|
* @returns the stripped entries, or undefined when the job failed.
|
|
377
564
|
*/
|
|
378
565
|
private stripDuplicateMounts;
|
|
566
|
+
/**
|
|
567
|
+
* Compose the profile with the CLI's read-only `--dump-config` probe and
|
|
568
|
+
* return the dump text. Composition writes nothing and binds no port, so it
|
|
569
|
+
* is safe on every runtime — including an application-owned profile whose
|
|
570
|
+
* *writes* the CLI refuses. A run that cannot compose (no CLI on this
|
|
571
|
+
* runtime, a non-zero exit, a spawn failure) reports undefined, and the
|
|
572
|
+
* caller must then leave the profile alone instead of guessing at the entry
|
|
573
|
+
* set.
|
|
574
|
+
* @returns the composed dump text, or undefined when it is unavailable.
|
|
575
|
+
*/
|
|
576
|
+
private compositionOf;
|
|
577
|
+
/**
|
|
578
|
+
* The entry ids a user-layer override may still point at: the composed ids
|
|
579
|
+
* plus every id the profile's own bundle layers still declare.
|
|
580
|
+
*
|
|
581
|
+
* The composition alone does not prove a row is retired. A host that
|
|
582
|
+
* composes while a bundle is being replaced — the remove-then-install half of
|
|
583
|
+
* an application-owned update, or an upgrade whose packages are half
|
|
584
|
+
* installed — composes *without* the rows of the bundle that is momentarily
|
|
585
|
+
* gone, and pruning on that probe deletes the user's override for a row that
|
|
586
|
+
* still exists (0.4.7 lost `web-ui-remote-web-ui` and `ui-schedule` this
|
|
587
|
+
* way). Declarations live in the bundle layers, so they survive that window.
|
|
588
|
+
* @param composed - the entry ids of the composition probe.
|
|
589
|
+
* @returns the ids to keep, or undefined when a declared layer cannot be
|
|
590
|
+
* read, which proves nothing either way and must leave the file alone.
|
|
591
|
+
*/
|
|
592
|
+
private liveOverrideIds;
|
|
593
|
+
/**
|
|
594
|
+
* The entry names the installed bundles' own rows carry, by entry id.
|
|
595
|
+
*
|
|
596
|
+
* The loader inserts one row per id and takes that row's name from the
|
|
597
|
+
* bundle's own patch file, so this map is the very fact the loader composes:
|
|
598
|
+
* a profile row naming something else is a row the loader skips.
|
|
599
|
+
*
|
|
600
|
+
* @returns the live names, or undefined when a bundle's patch cannot be read
|
|
601
|
+
* (which proves nothing either way and must leave the profile alone).
|
|
602
|
+
*/
|
|
603
|
+
private liveEntryNames;
|
|
604
|
+
/**
|
|
605
|
+
* Point the profile's own rows at the packages that now carry those entry ids.
|
|
606
|
+
*
|
|
607
|
+
* A bundle that renames a row's package leaves every profile row that named
|
|
608
|
+
* the old one dead: the include patch semantics skip a row whose name does
|
|
609
|
+
* not match the inserted row, and the skip takes the whole row with it — a
|
|
610
|
+
* config row stops configuring and a `disabled` override stops disabling,
|
|
611
|
+
* both without a word in the browser. Issue #1901 moved the aggregate's
|
|
612
|
+
* family rows from the `@linxin666/dsh-web-all/<family>` subpath to the
|
|
613
|
+
* real package, so every profile row written before that upgrade went dead
|
|
614
|
+
* with it.
|
|
615
|
+
*
|
|
616
|
+
* The repair is idempotent and writes only when a row actually changed, so a
|
|
617
|
+
* healthy profile is never rewritten.
|
|
618
|
+
*
|
|
619
|
+
* @returns the repaired rows, in file order.
|
|
620
|
+
*/
|
|
621
|
+
repairProfileRowNames(): Promise<Array<{
|
|
622
|
+
id: string;
|
|
623
|
+
from: string;
|
|
624
|
+
to: string;
|
|
625
|
+
}>>;
|
|
626
|
+
/**
|
|
627
|
+
* Post-update orphan guard: drop this package's own enablement overrides
|
|
628
|
+
* whose entry id neither the composed *target* profile nor any bundle layer
|
|
629
|
+
* still declares. The composition is the loader's own after the update
|
|
630
|
+
* ({@link composedEntryIdsOf}), widened by the bundle layers' declarations
|
|
631
|
+
* ({@link liveOverrideIds}) because a composition taken mid-upgrade omits
|
|
632
|
+
* rows that still exist. A retired row would otherwise leave a stale
|
|
633
|
+
* override that the loader reports on every boot as
|
|
634
|
+
* `patch: entry "<id>" not found`.
|
|
635
|
+
*
|
|
636
|
+
* The stale-row-name repair ({@link repairProfileRowNames}) runs first and
|
|
637
|
+
* on its own authority, so a profile whose bundle declarations cannot be
|
|
638
|
+
* resolved is repaired even though the prune then writes nothing.
|
|
639
|
+
*
|
|
640
|
+
* Nothing is written when nothing is orphaned — a second run over a pruned
|
|
641
|
+
* profile returns the input text untouched, so no write and no second backup
|
|
642
|
+
* happen — and an unobtainable composition leaves the file as it is instead
|
|
643
|
+
* of emptying it. A write that does fail settles the job as an error the way
|
|
644
|
+
* every other post-mutation patch write in this transaction does, with the
|
|
645
|
+
* backup the write helper takes first left in place.
|
|
646
|
+
* @param job - the settling job (error target on write failure).
|
|
647
|
+
* @param dumpText - an already captured composition, when the caller has one.
|
|
648
|
+
* @returns the pruned entry ids, or undefined when the job failed.
|
|
649
|
+
*/
|
|
650
|
+
private pruneOrphanOverrides;
|
|
379
651
|
/**
|
|
380
652
|
* Roll back a freshly installed dependency through the official remove
|
|
381
653
|
* path (which also drops its bundle), then settle the job as an error.
|
|
@@ -398,10 +670,15 @@ export declare class CliGateway {
|
|
|
398
670
|
/** Whether the new install claims an entry id another plugin already holds. */
|
|
399
671
|
private detectDuplicateClaims;
|
|
400
672
|
/**
|
|
401
|
-
* Boot preflight after an install: compose the profile with the
|
|
402
|
-
* `--dump-config` (resolves every entry without binding the port). A
|
|
403
|
-
* that implicates the new plugin disables it so the next start
|
|
404
|
-
* an unrelated failure is reported without touching anything.
|
|
673
|
+
* Boot preflight after an install or update: compose the profile with the
|
|
674
|
+
* CLI's `--dump-config` (resolves every entry without binding the port). A
|
|
675
|
+
* failure that implicates the new plugin disables it so the next start
|
|
676
|
+
* cannot fail; an unrelated failure is reported without touching anything.
|
|
677
|
+
* The captured dump is returned on success so the update path can read the
|
|
678
|
+
* composed entry set from the same probe (see {@link pruneOrphanOverrides}).
|
|
679
|
+
* @returns the composed dump text, or undefined when the preflight did not
|
|
680
|
+
* produce one (no CLI on this runtime, or a failure the caller must read
|
|
681
|
+
* from `job`).
|
|
405
682
|
*/
|
|
406
683
|
private verifyBoot;
|
|
407
684
|
}
|
|
@@ -7,6 +7,14 @@
|
|
|
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).
|
|
10
18
|
* @module dsh-web-shared/host/loopback
|
|
11
19
|
*/
|
|
12
20
|
import type { IncomingMessage } from 'node:http';
|
|
@@ -16,9 +24,20 @@ export declare function isIPv4Loopback(v4: string): boolean;
|
|
|
16
24
|
export declare function isLoopbackAddress(address: string | undefined): boolean;
|
|
17
25
|
/** Whether a normalized URL hostname names the loopback authority (localhost, [::1], 127/8). */
|
|
18
26
|
export declare function isLoopbackHostname(hostname: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Whether a reverse proxy stood between the client and this host: the request
|
|
29
|
+
* carries CF-Connecting-IP or X-Forwarded-For. Either header is stamped by a
|
|
30
|
+
* hop that forwards traffic, so the request did not originate on this machine.
|
|
31
|
+
* @param request - node HTTP request.
|
|
32
|
+
* @returns true when a forwarding header is present.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isProxiedRequest(request: IncomingMessage): boolean;
|
|
19
35
|
/**
|
|
20
36
|
* Request-level trust fence: a loopback socket address AND a loopback Host
|
|
21
37
|
* header, plus browser same-origin markers. The socket address is
|
|
22
|
-
* authoritative;
|
|
38
|
+
* authoritative for a direct connection; a request that carries a forwarding
|
|
39
|
+
* header is refused outright, because a proxy in front of the host makes both
|
|
40
|
+
* the socket address and the Host header describe the proxy rather than the
|
|
41
|
+
* client. X-Forwarded-For is therefore never evidence *for* loopback.
|
|
23
42
|
*/
|
|
24
43
|
export declare function isLoopbackRequest(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
|
/**
|