@linxin666/dsh-client-ui-plugin-manager 0.4.13 → 0.4.15
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 +3 -3
- package/README.zh.md +3 -3
- package/lib/client.js +71 -13
- package/lib/client.js.map +1 -1
- package/lib/index.js +615 -127
- package/lib/types/client/PluginListToolbar.d.ts +5 -4
- package/lib/types/client/index.d.ts +5 -4
- package/lib/types/client/locales.d.ts +3 -0
- package/lib/types/core/protocol.d.ts +33 -4
- package/lib/types/host/bundle-guard.d.ts +12 -1
- package/lib/types/host/gateway.d.ts +148 -2
- package/lib/types/host/restart.d.ts +96 -4
- package/package.json +14 -14
|
@@ -16,7 +16,7 @@
|
|
|
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, PluginUpdateResult, RestartMode } from '../core/protocol.ts';
|
|
19
|
+
import type { PluginUpdateItem, PluginUpdateResult, RestartMode, RestartPlanWire } 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. */
|
|
@@ -32,10 +32,11 @@ export interface PluginListToolbarInjected {
|
|
|
32
32
|
/**
|
|
33
33
|
* Read how a restart would be carried out, without carrying it out: the
|
|
34
34
|
* confirmation must name the same consequence the host will produce (an
|
|
35
|
-
* in-place relaunch, the packaged Desktop shell's own recovery dialog,
|
|
36
|
-
* manual restart), and a plan read has no side
|
|
35
|
+
* in-place relaunch, the packaged Desktop shell's own recovery dialog, a
|
|
36
|
+
* systemd unit restart, or a manual restart), and a plan read has no side
|
|
37
|
+
* effects. A systemd plan carries the unit it would restart.
|
|
37
38
|
*/
|
|
38
|
-
restartPlan: () => Promise<
|
|
39
|
+
restartPlan: () => Promise<RestartPlanWire>;
|
|
39
40
|
/** Restart the host so an applied update is loaded. */
|
|
40
41
|
restart: () => Promise<RestartMode>;
|
|
41
42
|
}
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
import type { Context as ClientContext } from '@deepseek-ai/cordis';
|
|
26
26
|
import { type PluginUpdatePatchInjected } from './PluginUpdatePatch.tsx';
|
|
27
27
|
import { type PluginManagerKey } from './locales.ts';
|
|
28
|
-
import { type RestartMode } from '../core/protocol.ts';
|
|
28
|
+
import { type RestartMode, type RestartPlanWire } from '../core/protocol.ts';
|
|
29
29
|
import { type PluginManagerService } from '../core/service.ts';
|
|
30
30
|
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
31
31
|
interface LocaleNamespaceMap {
|
|
@@ -53,10 +53,11 @@ export type PluginManagerFace = PluginUpdatePatchInjected & PluginManagerService
|
|
|
53
53
|
/**
|
|
54
54
|
* Read how a restart would be carried out without triggering it (the same
|
|
55
55
|
* route's plan read). The toolbar words its confirmation from this, so a
|
|
56
|
-
* packaged Desktop host can say what its system dialog will do
|
|
57
|
-
*
|
|
56
|
+
* packaged Desktop host can say what its system dialog will do, and a
|
|
57
|
+
* systemd host can name the unit that restarts, instead of surprising the
|
|
58
|
+
* user with either.
|
|
58
59
|
*/
|
|
59
|
-
restartPlan: () => Promise<
|
|
60
|
+
restartPlan: () => Promise<RestartPlanWire>;
|
|
60
61
|
};
|
|
61
62
|
/**
|
|
62
63
|
* Build the dual-channel face once: official-channel and gateway-channel
|
|
@@ -35,6 +35,7 @@ declare const STATIC_ZH: {
|
|
|
35
35
|
restartConfirm: string;
|
|
36
36
|
restartPlanRelaunch: string;
|
|
37
37
|
restartPlanShell: string;
|
|
38
|
+
restartPlanSystemd: string;
|
|
38
39
|
restartPlanManual: string;
|
|
39
40
|
restartShellWarning: string;
|
|
40
41
|
restartDesktopHint: string;
|
|
@@ -105,6 +106,7 @@ export declare const zh: {
|
|
|
105
106
|
restartConfirm: string;
|
|
106
107
|
restartPlanRelaunch: string;
|
|
107
108
|
restartPlanShell: string;
|
|
109
|
+
restartPlanSystemd: string;
|
|
108
110
|
restartPlanManual: string;
|
|
109
111
|
restartShellWarning: string;
|
|
110
112
|
restartDesktopHint: string;
|
|
@@ -175,6 +177,7 @@ export declare const en: {
|
|
|
175
177
|
restartConfirm: string;
|
|
176
178
|
restartPlanRelaunch: string;
|
|
177
179
|
restartPlanShell: string;
|
|
180
|
+
restartPlanSystemd: string;
|
|
178
181
|
restartPlanManual: string;
|
|
179
182
|
restartShellWarning: string;
|
|
180
183
|
restartDesktopHint: string;
|
|
@@ -46,10 +46,27 @@ export interface InstalledPluginItem {
|
|
|
46
46
|
/**
|
|
47
47
|
* How the host carried out (or refused) a restart request:
|
|
48
48
|
* `relaunch` — this host re-executes itself in place; `shell` — the packaged
|
|
49
|
-
* Desktop shell owns the process tree and runs its own restart; `
|
|
50
|
-
*
|
|
49
|
+
* Desktop shell owns the process tree and runs its own restart; `systemd` —
|
|
50
|
+
* this host runs as a systemd service and asks its own unit to restart it;
|
|
51
|
+
* `manual` — none of these is possible here, the user restarts DSH themselves.
|
|
51
52
|
*/
|
|
52
|
-
export type RestartMode = 'relaunch' | 'shell' | 'manual';
|
|
53
|
+
export type RestartMode = 'relaunch' | 'shell' | 'systemd' | 'manual';
|
|
54
|
+
/** Whether a value is a systemd unit name this package asks systemd to restart. */
|
|
55
|
+
export declare function isSystemdUnitName(value: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* What the host would do with a restart request, as the plan read answers it.
|
|
58
|
+
*
|
|
59
|
+
* A discriminated union rather than a mode beside an optional unit: a systemd
|
|
60
|
+
* plan always names the unit it restarts (the parser refuses one that does
|
|
61
|
+
* not) and no other mode carries a unit at all, so the confirmation reads the
|
|
62
|
+
* unit off the plan instead of guarding a field that cannot be missing.
|
|
63
|
+
*/
|
|
64
|
+
export type RestartPlanWire = {
|
|
65
|
+
mode: 'systemd';
|
|
66
|
+
unit: string;
|
|
67
|
+
} | {
|
|
68
|
+
mode: 'relaunch' | 'shell' | 'manual';
|
|
69
|
+
};
|
|
53
70
|
/**
|
|
54
71
|
* The result of one applied update: the installed row, plus the host's verdict
|
|
55
72
|
* on whether this process can serve it without a restart.
|
|
@@ -159,11 +176,23 @@ export declare function parseInstallStatus(value: unknown): InstallProgressItem;
|
|
|
159
176
|
*/
|
|
160
177
|
export declare function parseUpdateList(value: unknown): PluginUpdateItem[];
|
|
161
178
|
/**
|
|
162
|
-
* Validate and normalize a `restart` response value
|
|
179
|
+
* Validate and normalize a `restart` response value, reading the mode a POST
|
|
180
|
+
* answer carries.
|
|
163
181
|
* @param value - decoded but untrusted response value.
|
|
164
182
|
* @returns the mode the host actually used.
|
|
165
183
|
*/
|
|
166
184
|
export declare function parseRestartMode(value: unknown): RestartMode;
|
|
185
|
+
/**
|
|
186
|
+
* Validate and normalize a restart PLAN response value (the GET answer).
|
|
187
|
+
*
|
|
188
|
+
* The plan is read before the confirmation is shown, so this parser fails
|
|
189
|
+
* closed: an unknown mode, or a systemd plan that does not name a unit of the
|
|
190
|
+
* accepted shape, throws instead of letting the panel promise a restart the
|
|
191
|
+
* host cannot actually perform.
|
|
192
|
+
* @param value - decoded but untrusted response value.
|
|
193
|
+
* @returns the plan the host would carry out.
|
|
194
|
+
*/
|
|
195
|
+
export declare function parseRestartPlan(value: unknown): RestartPlanWire;
|
|
167
196
|
/**
|
|
168
197
|
* Validate and normalize a `failures` response value.
|
|
169
198
|
* @param value - decoded but untrusted response value.
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* such duplicate mounts; the gateway strips exactly those entries back out.
|
|
13
13
|
* @module @linxin666/dsh-client-ui-plugin-manager/host
|
|
14
14
|
*/
|
|
15
|
-
import type
|
|
15
|
+
import { type ProfileFacts } from './profile.ts';
|
|
16
16
|
/** The before-state composition facts the guard reads. */
|
|
17
17
|
export interface GuardSnapshot {
|
|
18
18
|
/** The profile patch text captured before the mutation. */
|
|
@@ -51,3 +51,14 @@ export declare function rowMountedPackageNames(facts: ProfileFacts, before: Guar
|
|
|
51
51
|
* @returns the entries to remove from `dsh.profile.bundles`.
|
|
52
52
|
*/
|
|
53
53
|
export declare function duplicateMountBundles(facts: ProfileFacts, before: GuardSnapshot, beforeBundles: readonly string[], afterBundles: readonly string[]): Promise<string[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Whether an installed dependency declares its own bundle patch (`dsh.bundle`
|
|
56
|
+
* in its package.json) — the fact the official CLI's reconciliation selects a
|
|
57
|
+
* dependency on. A package that declares none is a plain dependency of some
|
|
58
|
+
* mounted bundle and never enters the selection.
|
|
59
|
+
* @param facts - resolved profile locations.
|
|
60
|
+
* @param name - dependency name (possibly scoped).
|
|
61
|
+
* @returns whether the installed package declares `dsh.bundle`; a package that
|
|
62
|
+
* cannot be read proves nothing and answers false.
|
|
63
|
+
*/
|
|
64
|
+
export declare function declaresBundle(facts: ProfileFacts, name: string): Promise<boolean>;
|
|
@@ -95,6 +95,31 @@ export interface GatewayJob {
|
|
|
95
95
|
}
|
|
96
96
|
/** The binary search roots for the dsh CLI. */
|
|
97
97
|
export declare function findDshBinary(env?: NodeJS.ProcessEnv, platform?: string, exists?: (path: string) => boolean, hostEntryPath?: string | undefined, resourcesPath?: string | undefined): string | null;
|
|
98
|
+
/**
|
|
99
|
+
* The installation copy of one bundle package, when the DSH installation this
|
|
100
|
+
* runtime runs out of carries it.
|
|
101
|
+
*
|
|
102
|
+
* A CLI-created profile names the official bundles in `dsh.profile.bundles`
|
|
103
|
+
* without ever installing them: `@deepseek-ai/dsh-base` and
|
|
104
|
+
* `@deepseek-ai/dsh-web-app` are mounted from the DSH installation the loader
|
|
105
|
+
* runs out of, so no profile copy exists and their rows are declared by the
|
|
106
|
+
* installation's own package. That copy is the one whose rows mount, so a
|
|
107
|
+
* missing profile copy is not proof of an unknown declaration set (see
|
|
108
|
+
* {@link CliGateway.liveOverrideIds}).
|
|
109
|
+
*
|
|
110
|
+
* Resolution follows Node's own lookup from the CLI entry: every ancestor
|
|
111
|
+
* directory contributes `node_modules/<name>`, plus the npm-global and
|
|
112
|
+
* homebrew `<ancestor>/lib/node_modules/<name>`. The entry is resolved through
|
|
113
|
+
* its symlinks first, because npm-global and homebrew install the `dsh` shim
|
|
114
|
+
* as a link into the package tree while the shim's own directory carries no
|
|
115
|
+
* packages.
|
|
116
|
+
* @param binary - the resolved dsh CLI path, or null when this runtime has none.
|
|
117
|
+
* @param name - the bundle package name from `dsh.profile.bundles`.
|
|
118
|
+
* @param exists - existence probe (test seam).
|
|
119
|
+
* @param resolveReal - symlink resolver (test seam).
|
|
120
|
+
* @returns the installation package directory, or undefined when it has none.
|
|
121
|
+
*/
|
|
122
|
+
export declare function hostBundleDir(binary: string | null, name: string, exists?: (path: string) => boolean, resolveReal?: (path: string) => string | undefined): string | undefined;
|
|
98
123
|
/**
|
|
99
124
|
* Read a file's leading bytes for the shebang probe. Every failure — a missing
|
|
100
125
|
* file, a directory, a permission error, an unreadable asar entry — reads as
|
|
@@ -425,8 +450,40 @@ export declare class CliGateway {
|
|
|
425
450
|
private restoreSpec;
|
|
426
451
|
/** Execute the legacy aggregate migration and settle the job. */
|
|
427
452
|
private runMigration;
|
|
428
|
-
/**
|
|
453
|
+
/**
|
|
454
|
+
* Restore the original legacy package after a failed migration.
|
|
455
|
+
*
|
|
456
|
+
* The forward migration removed the legacy package first, so the way back is
|
|
457
|
+
* a remove-then-add in the other direction — and each half has to be read, not
|
|
458
|
+
* assumed. A removal that does not take the new aggregate back out leaves the
|
|
459
|
+
* profile carrying it with the legacy package gone, and re-adding the legacy
|
|
460
|
+
* package on top of it is exactly the dual-mount shape this path exists to
|
|
461
|
+
* avoid: both bundles declare the same row ids, the loader mounts one of them
|
|
462
|
+
* without a word, and the next update resolves against a profile that no
|
|
463
|
+
* longer describes itself. Such a rollback is reported as incomplete
|
|
464
|
+
* ({@link incompleteRollback}) instead of claimed as done.
|
|
465
|
+
* @returns true when the rollback finished — the legacy package is back, or
|
|
466
|
+
* the profile deliberately keeps the single current aggregate — and false
|
|
467
|
+
* when it could not run or could not finish, in which case `job.error`
|
|
468
|
+
* already carries the report and the caller must not replace it with its
|
|
469
|
+
* own reason.
|
|
470
|
+
*/
|
|
429
471
|
private rollbackMigration;
|
|
472
|
+
/**
|
|
473
|
+
* The report for a rollback that could not take the new aggregate back out.
|
|
474
|
+
*
|
|
475
|
+
* The profile is left carrying the new package with the legacy one gone,
|
|
476
|
+
* which is neither the migration nor a rollback, and it is not a state the
|
|
477
|
+
* legacy package may be re-added into: both bundles declare the same row ids,
|
|
478
|
+
* so keeping one of them is the only safe outcome. The message therefore says
|
|
479
|
+
* what actually happened, never claims a rollback that did not run, and names
|
|
480
|
+
* the two commands that carry it out by hand.
|
|
481
|
+
* @param targetId - the new aggregate this migration installed.
|
|
482
|
+
* @param restoreOld - the exact spec that reinstalls the legacy package.
|
|
483
|
+
* @param reason - the CLI's own words, or the exit it reported.
|
|
484
|
+
* @returns the job error text.
|
|
485
|
+
*/
|
|
486
|
+
private incompleteRollback;
|
|
430
487
|
/** Spawn the CLI, through the test seam when present. */
|
|
431
488
|
private spawnCli;
|
|
432
489
|
/**
|
|
@@ -606,6 +663,33 @@ export declare class CliGateway {
|
|
|
606
663
|
* existed.
|
|
607
664
|
*/
|
|
608
665
|
status(jobId: string): GatewayJob | undefined;
|
|
666
|
+
/**
|
|
667
|
+
* Whether this gateway's own record says the last in-place update of one
|
|
668
|
+
* plugin at one version never settled.
|
|
669
|
+
*
|
|
670
|
+
* The update path writes the profile before it verifies it: the CLI puts the
|
|
671
|
+
* target version on disk, and the boot preflight (`--dump-config`, see
|
|
672
|
+
* {@link verifyBoot}) then decides whether the run is reported as landed. A
|
|
673
|
+
* preflight failure the plugin is not implicated in settles the job as an
|
|
674
|
+
* error with the new version already installed, which leaves the profile at
|
|
675
|
+
* the target version while the update itself failed. That state cannot be
|
|
676
|
+
* reached again through the update action — the row already carries the
|
|
677
|
+
* latest version, so the route answers 409 "already at <version>" and the
|
|
678
|
+
* only way out is a reinstall run by hand. This is the fact that lets that
|
|
679
|
+
* route tell the state apart from a plugin that is genuinely up to date,
|
|
680
|
+
* which must keep its 409.
|
|
681
|
+
*
|
|
682
|
+
* Only the most recent update of the plugin counts. A settled run — a later
|
|
683
|
+
* success, or a run that landed nothing and rolled back — is the plugin's
|
|
684
|
+
* current standing, whatever an older failed attempt said, so the scan starts
|
|
685
|
+
* at the newest settled job and stops at the first one that is this plugin's
|
|
686
|
+
* update. Jobs this gateway no longer holds (the ring cap, a restart) are
|
|
687
|
+
* unknown rather than failed, and answer false.
|
|
688
|
+
* @param id - the installed package name.
|
|
689
|
+
* @param version - the version the profile currently carries.
|
|
690
|
+
* @returns true when the newest recorded update of `id` failed at `version`.
|
|
691
|
+
*/
|
|
692
|
+
lastUpdateFailed(id: string, version: string): boolean;
|
|
609
693
|
/** Capture the layer snapshot and the dependency names (tolerant parse). */
|
|
610
694
|
private capture;
|
|
611
695
|
/** The plugin row a finished operation produced (installed or removed). */
|
|
@@ -652,7 +736,7 @@ export declare class CliGateway {
|
|
|
652
736
|
private compositionOf;
|
|
653
737
|
/**
|
|
654
738
|
* The entry ids a user-layer override may still point at: the composed ids
|
|
655
|
-
* plus every id the
|
|
739
|
+
* plus every id the bundles the profile lists still declare.
|
|
656
740
|
*
|
|
657
741
|
* The composition alone does not prove a row is retired. A host that
|
|
658
742
|
* composes while a bundle is being replaced — the remove-then-install half of
|
|
@@ -661,11 +745,41 @@ export declare class CliGateway {
|
|
|
661
745
|
* gone, and pruning on that probe deletes the user's override for a row that
|
|
662
746
|
* still exists (0.4.7 lost `web-ui-remote-web-ui` and `ui-schedule` this
|
|
663
747
|
* way). Declarations live in the bundle layers, so they survive that window.
|
|
748
|
+
*
|
|
749
|
+
* Every listed bundle therefore has to answer with the declarations the
|
|
750
|
+
* loader will actually mount, which for an installation-provided bundle is
|
|
751
|
+
* the installation's copy rather than a profile copy that never existed
|
|
752
|
+
* ({@link bundleLayerDir}).
|
|
664
753
|
* @param composed - the entry ids of the composition probe.
|
|
665
754
|
* @returns the ids to keep, or undefined when a declared layer cannot be
|
|
666
755
|
* read, which proves nothing either way and must leave the file alone.
|
|
667
756
|
*/
|
|
668
757
|
private liveOverrideIds;
|
|
758
|
+
/**
|
|
759
|
+
* The directory whose `cordis.patch.yml` declares one listed bundle's rows,
|
|
760
|
+
* or undefined when those declarations cannot be known.
|
|
761
|
+
*
|
|
762
|
+
* The profile's own copy answers whenever it is installed. A profile that
|
|
763
|
+
* lists a bundle its own `node_modules` does not carry is normally a
|
|
764
|
+
* CLI-created profile naming the installation's bundles — it never installs
|
|
765
|
+
* `@deepseek-ai/dsh-base` or `@deepseek-ai/dsh-web-app`, the loader mounts
|
|
766
|
+
* them out of the DSH installation, and {@link hostBundleDir} names that copy,
|
|
767
|
+
* whose rows are by construction the ones this boot carries.
|
|
768
|
+
*
|
|
769
|
+
* Everything else that reads as missing is a package this profile installs
|
|
770
|
+
* itself, caught mid-install or mid-replace. Its rows can be declared by the
|
|
771
|
+
* copy that is gone and by no other, so they are unknown, never empty:
|
|
772
|
+
* pruning on that guess is how 0.4.7 lost the user's `web-ui-remote-web-ui`
|
|
773
|
+
* and `ui-schedule` overrides. The profile's own dependency list separates
|
|
774
|
+
* the two cases, because it is written by the same pnpm call that creates the
|
|
775
|
+
* directory: a dependency is this profile's package, so a missing directory
|
|
776
|
+
* there is unfinished work rather than an installation-provided bundle.
|
|
777
|
+
* @param name - one entry of `dsh.profile.bundles`.
|
|
778
|
+
* @param dependencies - the profile manifest's dependency map.
|
|
779
|
+
* @param binary - the dsh CLI path, or null when this runtime has none.
|
|
780
|
+
* @returns the declaring package directory, or undefined when unknown.
|
|
781
|
+
*/
|
|
782
|
+
private bundleLayerDir;
|
|
669
783
|
/**
|
|
670
784
|
* The entry names the installed bundles' own rows carry, by entry id.
|
|
671
785
|
*
|
|
@@ -741,6 +855,38 @@ export declare class CliGateway {
|
|
|
741
855
|
private unresolvableInsertNames;
|
|
742
856
|
/** The new dependency of an install, when one exists. */
|
|
743
857
|
private newDependency;
|
|
858
|
+
/**
|
|
859
|
+
* Whether a run wrote a package that declares its own bundle without the
|
|
860
|
+
* profile selecting it.
|
|
861
|
+
*
|
|
862
|
+
* The landing reads in {@link runInner} look at `dependencies` alone, and
|
|
863
|
+
* pnpm writes that line before the build-script gate decides the exit: a
|
|
864
|
+
* dependency is not a mount. A package declaring `dsh.bundle` is only
|
|
865
|
+
* reachable through `dsh.profile.bundles`, so a selection that never landed
|
|
866
|
+
* (a fresh install) or left with the run (a replacement of a selected
|
|
867
|
+
* package) is a half mount: the composition carries not one row of it while
|
|
868
|
+
* every other check passes.
|
|
869
|
+
* @param name - the dependency the run added or targeted.
|
|
870
|
+
* @param bundles - the selection the CLI's own run left behind, read before
|
|
871
|
+
* the duplicate-mount strip can correct its entries.
|
|
872
|
+
* @param required - whether the selection has to be present: always for a
|
|
873
|
+
* fresh install, and for a replacement only when the profile already
|
|
874
|
+
* selected the package (a patch-row mount was never selected to lose).
|
|
875
|
+
* @returns whether a bundle-declaring package ended up unselected.
|
|
876
|
+
*/
|
|
877
|
+
private bundleSelectionMissing;
|
|
878
|
+
/**
|
|
879
|
+
* The diagnostic for {@link bundleSelectionMissing}: which package the
|
|
880
|
+
* composition does not mount, and the two steps that repair it. Repeating the
|
|
881
|
+
* same command cannot — the CLI reconciles only the dependencies it newly
|
|
882
|
+
* added — so the remedy is an approval followed by remove and add.
|
|
883
|
+
* @param name - the dependency left unselected.
|
|
884
|
+
* @param lead - the run's own prefix for the sentence.
|
|
885
|
+
* @param tolerated - the accepted non-zero exit, whose pnpm tail names the
|
|
886
|
+
* build scripts it skipped.
|
|
887
|
+
* @returns the error text.
|
|
888
|
+
*/
|
|
889
|
+
private halfMountError;
|
|
744
890
|
/** The claimed entry ids of one installed dependency (its own bundle patch, or its name). */
|
|
745
891
|
private claimedEntriesOf;
|
|
746
892
|
/** Whether the new install claims an entry id another plugin already holds. */
|
|
@@ -19,6 +19,13 @@
|
|
|
19
19
|
* guarantee in {@link SHELL_RESTART_CAPABILITY_ENV}; a host that sees no such
|
|
20
20
|
* marker answers 'manual' instead of stopping itself (see
|
|
21
21
|
* {@link shellRestartIsSupported}).
|
|
22
|
+
* - A host that systemd started is restarted by systemd: the manager owns this
|
|
23
|
+
* process tree, so asking it to restart the unit is the one action that
|
|
24
|
+
* survives this process stopping. The host proves that case from its own
|
|
25
|
+
* cgroup and environment ({@link readSystemdFacts}) and names the unit it
|
|
26
|
+
* asks; the request goes out after the response, because the stop job starts
|
|
27
|
+
* the moment the request is queued. Mode 'systemd'. A system unit keeps the
|
|
28
|
+
* manual answer: restarting it needs privileges this process does not have.
|
|
22
29
|
* - A host this plugin can prove is a terminal launch (an interactive stdio
|
|
23
30
|
* pair, no Electron in the environment) is restarted in place: a detached
|
|
24
31
|
* helper waits for this process to exit and re-executes the same command
|
|
@@ -32,8 +39,10 @@
|
|
|
32
39
|
* spawning anything; {@link performRestart} is the effectful half.
|
|
33
40
|
* @module @linxin666/dsh-client-ui-plugin-manager/host
|
|
34
41
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
import { type ChildProcess, type SpawnOptions } from 'node:child_process';
|
|
43
|
+
import { type RestartMode } from '../core/protocol.ts';
|
|
44
|
+
/** How a restart request is carried out (single source: core/protocol.ts). */
|
|
45
|
+
export type { RestartMode };
|
|
37
46
|
/** The command line a relaunch re-executes. */
|
|
38
47
|
export interface RelaunchCommand {
|
|
39
48
|
/** Absolute path of the executable (Node, or the Electron binary in Node mode). */
|
|
@@ -50,6 +59,8 @@ export interface RestartPlan {
|
|
|
50
59
|
mode: RestartMode;
|
|
51
60
|
/** Present exactly when mode is 'relaunch'. */
|
|
52
61
|
command?: RelaunchCommand;
|
|
62
|
+
/** Present exactly when mode is 'systemd': the unit systemd is asked to restart. */
|
|
63
|
+
unit?: string;
|
|
53
64
|
}
|
|
54
65
|
/** The process facts the verdict is derived from. */
|
|
55
66
|
export interface RestartFacts {
|
|
@@ -62,7 +73,59 @@ export interface RestartFacts {
|
|
|
62
73
|
cwd: string;
|
|
63
74
|
/** Whether stdio is a terminal (a launch a human can see and stop). */
|
|
64
75
|
interactive: boolean;
|
|
76
|
+
/** The systemd unit this process runs as, when it runs as one. */
|
|
77
|
+
systemd?: SystemdFacts;
|
|
65
78
|
}
|
|
79
|
+
/** The systemd unit this host was started as, when it was started as one. */
|
|
80
|
+
export interface SystemdFacts {
|
|
81
|
+
/** Unit name as the cgroup spells it, e.g. `dsh-web.service`. */
|
|
82
|
+
unit: string;
|
|
83
|
+
/** Which manager owns the unit: this user's own manager, or the system manager. */
|
|
84
|
+
scope: 'user' | 'system';
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Read the systemd-service facts out of a cgroup path and a launch environment,
|
|
88
|
+
* without touching the system.
|
|
89
|
+
*
|
|
90
|
+
* All three markers must hold, and each one is what makes a false positive a
|
|
91
|
+
* real hazard rather than a wrong label:
|
|
92
|
+
* - The cgroup's last segment is the decisive one: only a `*.service` unit of
|
|
93
|
+
* the conservative shape this package accepts on the wire names a service,
|
|
94
|
+
* while a scope, a session, or a container path is not a unit. A process this
|
|
95
|
+
* host starts by hand lands in a scope of its own or shares the host's
|
|
96
|
+
* cgroup, so this segment is what separates a service from what runs inside
|
|
97
|
+
* one.
|
|
98
|
+
* - `INVOCATION_ID` rules a launch out but proves nothing on its own: every
|
|
99
|
+
* process this host starts inherits the host's own marker unchanged, so its
|
|
100
|
+
* presence is indistinguishable from the host's. It is what rejects a cgroup
|
|
101
|
+
* path that ends in a service unit only because some other tool put the
|
|
102
|
+
* process there, which is not a service any manager restarts on request.
|
|
103
|
+
* - The slice says which manager owns it. Only this user's manager is
|
|
104
|
+
* reachable without privileges, and it is reachable only through its own
|
|
105
|
+
* socket ({@link readSystemdFacts} checks that; this parser takes the answer).
|
|
106
|
+
*
|
|
107
|
+
* The user manager's own cgroup ends in `user@<uid>.service`. That is a unit
|
|
108
|
+
* name of this shape, and restarting it takes down every service the manager
|
|
109
|
+
* runs, so it is refused rather than read as this host's own unit.
|
|
110
|
+
* @param cgroup - the cgroup path (or a whole `/proc/self/cgroup` line).
|
|
111
|
+
* @param env - the launch environment.
|
|
112
|
+
* @param managerSocket - whether this user's systemd manager socket exists.
|
|
113
|
+
* @returns the unit and its scope, or undefined when this is not a service
|
|
114
|
+
* this package can ask for a restart.
|
|
115
|
+
*/
|
|
116
|
+
export declare function parseSystemdFacts(cgroup: string, env: NodeJS.ProcessEnv, managerSocket: boolean): SystemdFacts | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Read this process's own systemd-service facts (Linux only).
|
|
119
|
+
*
|
|
120
|
+
* Every step is a read that fails on another platform, in a container, or
|
|
121
|
+
* under an init that is not systemd, and each failure answers "not a systemd
|
|
122
|
+
* service" instead of throwing: the route that reads this must keep answering
|
|
123
|
+
* 'manual' rather than turning a restart plan into a 500.
|
|
124
|
+
* @param env - the launch environment (INVOCATION_ID, XDG_RUNTIME_DIR).
|
|
125
|
+
* @param cgroupFile - the file carrying this process's cgroup (test seam).
|
|
126
|
+
* @returns the unit and scope, or undefined when this host is not a service.
|
|
127
|
+
*/
|
|
128
|
+
export declare function readSystemdFacts(env?: NodeJS.ProcessEnv, cgroupFile?: string): SystemdFacts | undefined;
|
|
66
129
|
/** Grace period between answering the restart request and leaving the process. */
|
|
67
130
|
export declare const RESTART_EXIT_DELAY_MS = 400;
|
|
68
131
|
/**
|
|
@@ -87,7 +150,8 @@ export declare const RESTART_WAIT_MS = 30000;
|
|
|
87
150
|
/**
|
|
88
151
|
* Decide how a restart request is carried out.
|
|
89
152
|
* @param facts - the running process's launch facts.
|
|
90
|
-
* @returns the planned mode, with the relaunch command when one is used
|
|
153
|
+
* @returns the planned mode, with the relaunch command when one is used and
|
|
154
|
+
* the systemd unit when systemd performs the restart.
|
|
91
155
|
*/
|
|
92
156
|
export declare function planRestart(facts: RestartFacts): RestartPlan;
|
|
93
157
|
/** Absolute path of the relaunch journal this plugin appends to. */
|
|
@@ -99,10 +163,35 @@ export declare function restartLogPath(home?: string): string;
|
|
|
99
163
|
* @returns true when a helper process was actually created.
|
|
100
164
|
*/
|
|
101
165
|
export declare function startRelaunchHelper(command: RelaunchCommand, logPath?: string): boolean;
|
|
166
|
+
/** Effect seams for {@link requestUnitRestart} (tests replace them). */
|
|
167
|
+
export interface UnitRestartRuntime {
|
|
168
|
+
/** Start the manager command; the default is node's own `spawn`. */
|
|
169
|
+
spawn?: (executable: string, args: readonly string[], options: SpawnOptions) => ChildProcess;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Ask this user's systemd manager to restart one unit.
|
|
173
|
+
*
|
|
174
|
+
* `--no-block` returns as soon as the request is queued, so the caller is never
|
|
175
|
+
* held by a stop job it just started and the manager owns the rest. What the
|
|
176
|
+
* command itself says goes to the journal, and so does a deterministic non-zero
|
|
177
|
+
* exit code; a signal death is not, because it is the stop job this request
|
|
178
|
+
* queued (the note beside the exit handler spells that out). From here a
|
|
179
|
+
* refused request looks exactly like a queued one, and the journal is the only
|
|
180
|
+
* place that difference can be read. Nothing is thrown: by the time
|
|
181
|
+
* this runs the route has already answered 202, so an exception here would be
|
|
182
|
+
* an unhandled event in a host nobody is left watching.
|
|
183
|
+
* @param unit - the unit to restart.
|
|
184
|
+
* @param logPath - journal that records what the command said and how it ended.
|
|
185
|
+
* @param runtime - effect seams; the default spawns systemctl detached.
|
|
186
|
+
* @returns true when a systemctl process was actually created.
|
|
187
|
+
*/
|
|
188
|
+
export declare function requestUnitRestart(unit: string, logPath?: string, runtime?: UnitRestartRuntime): boolean;
|
|
102
189
|
/** Effect seams for {@link performRestart} (tests replace them). */
|
|
103
190
|
export interface RestartRuntime {
|
|
104
191
|
/** Start the relaunch helper; false means no replacement was created. */
|
|
105
192
|
startHelper?: (command: RelaunchCommand) => boolean;
|
|
193
|
+
/** Ask systemd to restart one unit. */
|
|
194
|
+
requestUnit?: (unit: string) => void;
|
|
106
195
|
/** Leave this process. */
|
|
107
196
|
exit?: () => void;
|
|
108
197
|
/** Schedule the exit (delay seam). */
|
|
@@ -111,8 +200,11 @@ export interface RestartRuntime {
|
|
|
111
200
|
/**
|
|
112
201
|
* Carry out one restart plan.
|
|
113
202
|
* @param plan - the verdict from {@link planRestart}.
|
|
114
|
-
* @param runtime - effect seams; the defaults spawn the helper
|
|
203
|
+
* @param runtime - effect seams; the defaults spawn the helper, ask systemd,
|
|
204
|
+
* and exit.
|
|
115
205
|
* @returns the mode actually used: 'relaunch' degrades to 'manual' when the
|
|
116
206
|
* helper could not be started, so a process that cannot be replaced stays up.
|
|
207
|
+
* A systemd request goes out after the answer and is not awaited, so it keeps
|
|
208
|
+
* the mode it was planned with; a failed request is journaled, not reported.
|
|
117
209
|
*/
|
|
118
210
|
export declare function performRestart(plan: RestartPlan, runtime?: RestartRuntime): RestartMode;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@linxin666/dsh-client-ui-plugin-manager",
|
|
3
3
|
"description": "Update checking for the dsh web GUI's official Plugins page: compares installed plugins against the version their registry source serves, gates the update on the DSH runtime minimum the release declares, and drives the update through the official installer channel or this package's loopback CLI gateway.",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.15",
|
|
5
5
|
"icon": "icon.svg",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "lib/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dsh": {
|
|
24
24
|
"engines": {
|
|
25
|
-
"dsh": ">=0.2.
|
|
25
|
+
"dsh": ">=0.2.2-rc.1"
|
|
26
26
|
},
|
|
27
27
|
"bundle": {
|
|
28
28
|
"patch": "./cordis.patch.yml"
|
|
@@ -36,21 +36,21 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@deepseek-ai/dsh": ">=0.2.
|
|
39
|
+
"@deepseek-ai/dsh": ">=0.2.2-rc.1",
|
|
40
40
|
"react": "^18.2.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@deepseek-ai/cordis": "^4.0
|
|
44
|
-
"@deepseek-ai/dsh-api-session-controller": "^0.2.
|
|
45
|
-
"@deepseek-ai/dsh-api-workspace-controller": "^0.2.
|
|
46
|
-
"@deepseek-ai/dsh-client-connection": "^0.2.
|
|
47
|
-
"@deepseek-ai/dsh-client-locale": "^0.2.
|
|
48
|
-
"@deepseek-ai/dsh-client-ui-primitives": "^0.2.
|
|
49
|
-
"@deepseek-ai/dsh-client-ui-renderer": "^0.2.
|
|
50
|
-
"@deepseek-ai/dsh-client-ui-settings": "^0.2.
|
|
51
|
-
"@deepseek-ai/dsh-client-ui-slots": "^0.2.
|
|
52
|
-
"@deepseek-ai/dsh-client-ui-workspace": "^0.2.
|
|
53
|
-
"@deepseek-ai/dsh-host-webserver": "^0.2.
|
|
43
|
+
"@deepseek-ai/cordis": "^4.1.0",
|
|
44
|
+
"@deepseek-ai/dsh-api-session-controller": "^0.2.2-rc.1",
|
|
45
|
+
"@deepseek-ai/dsh-api-workspace-controller": "^0.2.2-rc.1",
|
|
46
|
+
"@deepseek-ai/dsh-client-connection": "^0.2.2-rc.1",
|
|
47
|
+
"@deepseek-ai/dsh-client-locale": "^0.2.2-rc.1",
|
|
48
|
+
"@deepseek-ai/dsh-client-ui-primitives": "^0.2.2-rc.1",
|
|
49
|
+
"@deepseek-ai/dsh-client-ui-renderer": "^0.2.2-rc.1",
|
|
50
|
+
"@deepseek-ai/dsh-client-ui-settings": "^0.2.2-rc.1",
|
|
51
|
+
"@deepseek-ai/dsh-client-ui-slots": "^0.2.2-rc.1",
|
|
52
|
+
"@deepseek-ai/dsh-client-ui-workspace": "^0.2.2-rc.1",
|
|
53
|
+
"@deepseek-ai/dsh-host-webserver": "^0.2.2-rc.1",
|
|
54
54
|
"@testing-library/react": "^16.1.0",
|
|
55
55
|
"@types/node": "^22.20.0",
|
|
56
56
|
"@types/react": "~18.3.1",
|