dsh-plugin-wsl-env 0.26.3 → 0.27.0
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/CHANGELOG.md +142 -0
- package/CONTRIBUTING.md +32 -25
- package/CONTRIBUTING.zh.md +3 -2
- package/README.md +1 -1
- package/SECURITY.md +21 -7
- package/SECURITY.zh.md +18 -5
- package/SUPPORT.md +2 -2
- package/SUPPORT.zh.md +2 -2
- package/client.js +351 -48
- package/cordis.patch.yml +26 -10
- package/docs/AGENT-PROTOCOL-V7.md +4 -2
- package/docs/API.md +3 -1
- package/docs/API.zh.md +3 -1
- package/docs/ARCHITECTURE.md +22 -4
- package/docs/ARCHITECTURE.zh.md +18 -4
- package/docs/CONFIGURATION.md +117 -17
- package/docs/CONFIGURATION.zh.md +97 -11
- package/docs/DIAGNOSTICS.md +22 -11
- package/docs/DIAGNOSTICS.zh.md +17 -9
- package/docs/LIMITATIONS.md +27 -4
- package/docs/LIMITATIONS.zh.md +20 -3
- package/docs/MIGRATION.md +2 -2
- package/docs/MIGRATION.zh.md +2 -2
- package/docs/PARITY.md +3 -1
- package/docs/QUICKSTART.md +31 -20
- package/docs/QUICKSTART.zh.md +16 -9
- package/docs/README.zh.md +1 -1
- package/docs/RELEASING.md +25 -3
- package/docs/REQUIREMENTS.zh.md +7 -6
- package/docs/ROADMAP-1.0.md +11 -7
- package/lib/agent-confined.d.ts +9 -1
- package/lib/agent-confined.js +3 -3
- package/lib/agent.d.ts +54 -18
- package/lib/agent.js +86 -19
- package/lib/bwrap.d.ts +16 -0
- package/lib/bwrap.js +9 -0
- package/lib/fs-routing.d.ts +6 -0
- package/lib/fs-routing.js +7 -0
- package/lib/fs-substrate.d.ts +1 -1
- package/lib/fs-substrate.js +10 -18
- package/lib/fsio-agent.d.ts +4 -0
- package/lib/fsio-agent.js +37 -10
- package/lib/listing.d.ts +2 -2
- package/lib/listing.js +5 -4
- package/lib/messages.d.ts +70 -0
- package/lib/messages.js +80 -0
- package/lib/open-in-app.js +12 -9
- package/lib/picker.d.ts +4 -1
- package/lib/picker.js +35 -11
- package/lib/plugin-update.d.ts +212 -0
- package/lib/plugin-update.js +283 -0
- package/lib/ports.js +8 -1
- package/lib/provider-common.d.ts +22 -0
- package/lib/provider-common.js +18 -0
- package/lib/provider-marker.d.ts +23 -0
- package/lib/provider-marker.js +21 -0
- package/lib/sandbox-core.d.ts +2 -0
- package/lib/sandbox-core.js +5 -3
- package/lib/session-runtime.d.ts +10 -1
- package/lib/session-runtime.js +3 -1
- package/lib/shell-env.js +1 -1
- package/lib/socket-isolation.d.ts +103 -0
- package/lib/socket-isolation.js +166 -0
- package/lib/status.d.ts +21 -8
- package/lib/status.js +61 -23
- package/lib/subprocess.d.ts +3 -0
- package/lib/subprocess.js +5 -0
- package/lib/takeover-report.js +4 -11
- package/lib/update-check.d.ts +49 -9
- package/lib/update-check.js +81 -28
- package/lib/watcher.d.ts +1 -1
- package/lib/watcher.js +1 -1
- package/lib/wsl-doctor-command.d.ts +6 -2
- package/lib/wsl-doctor-command.js +24 -15
- package/lib/wsl-doctor-tool.js +2 -0
- package/lib/wsl-filesystem.d.ts +53 -12
- package/lib/wsl-filesystem.js +90 -31
- package/lib/wsl-shell.d.ts +109 -40
- package/lib/wsl-shell.js +128 -54
- package/package.json +8 -3
- package/scripts/doctor.mjs +199 -3
- package/scripts/profile-preset.mjs +10 -2
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sidebar panel's plugin route: version information, update availability,
|
|
3
|
+
* and the confirmed one-click upgrade.
|
|
4
|
+
*
|
|
5
|
+
* The version answer is the host plugin-manager's, not ours: `listVersions`
|
|
6
|
+
* resolves dist-tags, deprecation, and the `engines.dsh`/peer compatibility of
|
|
7
|
+
* every candidate against the running DSH, and `updateBundle` performs the
|
|
8
|
+
* replacement with the profile's normal package manager rules (bundle
|
|
9
|
+
* selection, exact version, rollback). This row only gives the panel a
|
|
10
|
+
* browser-reachable, authenticated exact-Fetch route to that service:
|
|
11
|
+
*
|
|
12
|
+
* - `GET /api/wsl-env/plugin-update` — the installed and running version,
|
|
13
|
+
* the latest stable release that can replace it, and the last check's
|
|
14
|
+
* outcome. A stale answer is re-read; `refresh=1` forces a fresh check.
|
|
15
|
+
* - `POST /api/wsl-env/plugin-update` — install that release through
|
|
16
|
+
* `updateBundle`. It is one click in the panel, never automatic: a plugin
|
|
17
|
+
* that silently replaces its own code under a running harness is a
|
|
18
|
+
* posture this plugin rejects.
|
|
19
|
+
*
|
|
20
|
+
* Nothing here fetches the registry or runs pnpm directly. A host without a
|
|
21
|
+
* plugin-manager (or one from before `updateBundle` existed) still gets the
|
|
22
|
+
* installed version and an explanation; a linked checkout is refused by the
|
|
23
|
+
* host as `not-updatable` and the panel points at the Plugins page instead.
|
|
24
|
+
*
|
|
25
|
+
* This is a TypeScript source built to `lib/plugin-update.js`; edit THIS file
|
|
26
|
+
* and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
27
|
+
* `pnpm test` fails when it drifts.
|
|
28
|
+
*
|
|
29
|
+
* @module dsh-plugin-wsl-env/plugin-update
|
|
30
|
+
*/
|
|
31
|
+
import z from "@deepseek-ai/schemastery";
|
|
32
|
+
import { type ListedVersion, type PluginManagerSlice, type VersionCheck } from "./update-check.js";
|
|
33
|
+
export declare const name = "wsl-plugin-update";
|
|
34
|
+
/** The one route the panel fetches; it must live under the `/api` channel. */
|
|
35
|
+
export declare const PLUGIN_UPDATE_PATH = "/api/wsl-env/plugin-update";
|
|
36
|
+
/** How long a version answer stays fresh before a panel load re-reads it. */
|
|
37
|
+
export declare const DEFAULT_CACHE_MS: number;
|
|
38
|
+
export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
39
|
+
/** How long a version answer stays fresh, in milliseconds. */
|
|
40
|
+
cacheMs: z<number, number, "defined">;
|
|
41
|
+
}>>, Schemastery.ObjectT<NoInfer<{
|
|
42
|
+
/** How long a version answer stays fresh, in milliseconds. */
|
|
43
|
+
cacheMs: z<number, number, "defined">;
|
|
44
|
+
}>>, "plain">;
|
|
45
|
+
/** The config schema's validated output. */
|
|
46
|
+
export interface PluginUpdateConfig {
|
|
47
|
+
/** How long a version answer stays fresh, in milliseconds. */
|
|
48
|
+
cacheMs?: number;
|
|
49
|
+
}
|
|
50
|
+
/** One application outcome, as the host's plugin-manager reports it. */
|
|
51
|
+
export type ChangeApplication = "applied" | "restart-required" | "overridden" | "failed" | "cancelled";
|
|
52
|
+
/** One host change result, reduced to what this route reads. */
|
|
53
|
+
interface ChangeOutcome {
|
|
54
|
+
readonly changed: boolean;
|
|
55
|
+
readonly application: ChangeApplication;
|
|
56
|
+
readonly restartReason?: string;
|
|
57
|
+
readonly stage: string;
|
|
58
|
+
readonly target: string;
|
|
59
|
+
readonly error?: {
|
|
60
|
+
readonly code?: string;
|
|
61
|
+
readonly diagnostic?: string;
|
|
62
|
+
} | undefined;
|
|
63
|
+
readonly pendingBuilds?: readonly string[];
|
|
64
|
+
}
|
|
65
|
+
/** What `updateBundle` answers (host plugin-manager types). */
|
|
66
|
+
export interface UpdateBundleResult {
|
|
67
|
+
readonly from: string;
|
|
68
|
+
readonly to: string;
|
|
69
|
+
readonly step: "check" | "remove" | "install";
|
|
70
|
+
readonly result: ChangeOutcome;
|
|
71
|
+
readonly restore?: ChangeOutcome | undefined;
|
|
72
|
+
}
|
|
73
|
+
/** The slice of the host's plugin-manager the one-click upgrade needs. */
|
|
74
|
+
export interface UpdateManagerSlice extends PluginManagerSlice {
|
|
75
|
+
/** Replace an installed bundle with one newer exact version. */
|
|
76
|
+
updateBundle: (name: string, version: string, options?: {
|
|
77
|
+
readonly registry?: string | null;
|
|
78
|
+
}) => Promise<UpdateBundleResult>;
|
|
79
|
+
}
|
|
80
|
+
/** The version answer the panel renders. */
|
|
81
|
+
export interface PluginVersionView {
|
|
82
|
+
/** The version installed on disk now. */
|
|
83
|
+
installed: string;
|
|
84
|
+
/** The version this process loaded; it lags `installed` until a reload. */
|
|
85
|
+
running: string;
|
|
86
|
+
/** What the last check learned. */
|
|
87
|
+
status: VersionCheck["status"];
|
|
88
|
+
/** When that check ran, in epoch milliseconds. */
|
|
89
|
+
checkedAt: number;
|
|
90
|
+
/** Whether that answer came from the in-process cache. */
|
|
91
|
+
cached: boolean;
|
|
92
|
+
/** Whether the host's plugin-manager can perform an update. */
|
|
93
|
+
updateSupported: boolean;
|
|
94
|
+
/** Whether the panel may offer the one-click upgrade. */
|
|
95
|
+
canUpdate: boolean;
|
|
96
|
+
/** The registry that answered the check. */
|
|
97
|
+
registry?: string | null;
|
|
98
|
+
/** The installable stable release, when one is available. */
|
|
99
|
+
latest?: ListedVersion;
|
|
100
|
+
/** Why a check produced no answer. */
|
|
101
|
+
problem?: string;
|
|
102
|
+
/** The host's explanation for an unavailable check. */
|
|
103
|
+
reason?: string;
|
|
104
|
+
}
|
|
105
|
+
/** The POST answer: the host's outcome plus the versions now on disk and in memory. */
|
|
106
|
+
export interface PluginUpdateReply {
|
|
107
|
+
/** Whether the target version is now installed. */
|
|
108
|
+
updated: boolean;
|
|
109
|
+
/** The last step's application outcome. */
|
|
110
|
+
application: ChangeApplication;
|
|
111
|
+
/** The version the update started from. */
|
|
112
|
+
from: string;
|
|
113
|
+
/** The version it targeted. */
|
|
114
|
+
to: string;
|
|
115
|
+
/** The last step that ran. */
|
|
116
|
+
step: UpdateBundleResult["step"];
|
|
117
|
+
/** The version installed on disk after the attempt. */
|
|
118
|
+
installed: string;
|
|
119
|
+
/** The version this process still runs. */
|
|
120
|
+
running: string;
|
|
121
|
+
/** When the attempt settled, in epoch milliseconds. */
|
|
122
|
+
checkedAt: number;
|
|
123
|
+
/** Why a successful install needs a restart, when it does. */
|
|
124
|
+
restartReason?: string;
|
|
125
|
+
/** Whether the old version was reinstalled after a failed target install. */
|
|
126
|
+
restored?: boolean;
|
|
127
|
+
/** Why the update could not install its target. */
|
|
128
|
+
error?: {
|
|
129
|
+
code?: string;
|
|
130
|
+
diagnostic?: string;
|
|
131
|
+
};
|
|
132
|
+
/** Package scripts awaiting explicit approval in the profile. */
|
|
133
|
+
pendingBuilds?: readonly string[];
|
|
134
|
+
/** Why the reinstallation of the old version failed, when it did. */
|
|
135
|
+
restoreError?: {
|
|
136
|
+
code?: string;
|
|
137
|
+
diagnostic?: string;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/** The route handler this module publishes. */
|
|
141
|
+
export type PluginUpdateHandler = (request: Request) => Promise<Response>;
|
|
142
|
+
/** One exact route's registration shape. */
|
|
143
|
+
interface ConnectionRoute {
|
|
144
|
+
readonly path: string;
|
|
145
|
+
readonly methods: readonly string[];
|
|
146
|
+
readonly requestBody: "buffered" | "streaming";
|
|
147
|
+
readonly fetch: (request: Request) => Promise<Response>;
|
|
148
|
+
}
|
|
149
|
+
/** The connection slice this row registers into. */
|
|
150
|
+
interface ConnectionFace {
|
|
151
|
+
/** The exact-Fetch route registry. */
|
|
152
|
+
readonly fetch: {
|
|
153
|
+
/** Register one exact route; the returned disposer withdraws it. */
|
|
154
|
+
register: (route: ConnectionRoute) => () => Promise<void> | void;
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/** The context slice this row consumes. */
|
|
158
|
+
interface PluginUpdateContext {
|
|
159
|
+
/** Optional cordis-style lookup: how production resolves the connection. */
|
|
160
|
+
get?: (name: string) => unknown;
|
|
161
|
+
/** Wait for a service, then run the callback in its scope. */
|
|
162
|
+
inject?: (deps: readonly string[], callback: (scope: PluginUpdateContext) => void) => unknown;
|
|
163
|
+
/** Own one disposer on the calling fiber. */
|
|
164
|
+
effect?: (callback: () => () => void, label?: string) => unknown;
|
|
165
|
+
/** The Host connection whose `/api` channel carries the route. */
|
|
166
|
+
connection?: ConnectionFace;
|
|
167
|
+
}
|
|
168
|
+
/** The handler options a test builds directly. */
|
|
169
|
+
export interface PluginUpdateHandlerOptions {
|
|
170
|
+
/** The host plugin-manager, or undefined when the host has none. */
|
|
171
|
+
manager: () => PluginManagerSlice | undefined;
|
|
172
|
+
/** How long a version answer stays fresh. */
|
|
173
|
+
cacheMs: number;
|
|
174
|
+
/** Clock seam. */
|
|
175
|
+
now?: () => number;
|
|
176
|
+
/** The installed version, read from this package's manifest. */
|
|
177
|
+
installed?: () => string;
|
|
178
|
+
/** The version this process loaded. */
|
|
179
|
+
running?: string;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The version installed on disk now; it moves after an upgrade while
|
|
183
|
+
* {@link RUNNING_VERSION} stays at the loaded generation until a reload.
|
|
184
|
+
*
|
|
185
|
+
* @returns the manifest's version, or the loaded one when the file cannot be read.
|
|
186
|
+
*/
|
|
187
|
+
export declare function installedVersion(): string;
|
|
188
|
+
/** The version this process loaded. */
|
|
189
|
+
export declare function runningVersion(): string;
|
|
190
|
+
/**
|
|
191
|
+
* Build the route handler.
|
|
192
|
+
*
|
|
193
|
+
* One handler owns one cache and one update slot, so the row registers exactly
|
|
194
|
+
* one instance and an unload drops both. The version check is cached for
|
|
195
|
+
* `cacheMs` because one answer costs several `pnpm view` calls in the profile;
|
|
196
|
+
* an update is never cached.
|
|
197
|
+
*
|
|
198
|
+
* @param options - the manager, clock, and cache seams.
|
|
199
|
+
* @returns the request handler.
|
|
200
|
+
*/
|
|
201
|
+
export declare function createPluginUpdateHandler(options: PluginUpdateHandlerOptions): PluginUpdateHandler;
|
|
202
|
+
/**
|
|
203
|
+
* Mount the row: register the route once the Host connection is available.
|
|
204
|
+
*
|
|
205
|
+
* A composition without `connection` (headless, ACP) leaves the row inert —
|
|
206
|
+
* the same posture the status row takes.
|
|
207
|
+
*
|
|
208
|
+
* @param ctx - the cordis context.
|
|
209
|
+
* @param config - the schema-validated plugin config.
|
|
210
|
+
*/
|
|
211
|
+
export declare function apply(ctx: PluginUpdateContext, config?: PluginUpdateConfig): void;
|
|
212
|
+
export {};
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sidebar panel's plugin route: version information, update availability,
|
|
3
|
+
* and the confirmed one-click upgrade.
|
|
4
|
+
*
|
|
5
|
+
* The version answer is the host plugin-manager's, not ours: `listVersions`
|
|
6
|
+
* resolves dist-tags, deprecation, and the `engines.dsh`/peer compatibility of
|
|
7
|
+
* every candidate against the running DSH, and `updateBundle` performs the
|
|
8
|
+
* replacement with the profile's normal package manager rules (bundle
|
|
9
|
+
* selection, exact version, rollback). This row only gives the panel a
|
|
10
|
+
* browser-reachable, authenticated exact-Fetch route to that service:
|
|
11
|
+
*
|
|
12
|
+
* - `GET /api/wsl-env/plugin-update` — the installed and running version,
|
|
13
|
+
* the latest stable release that can replace it, and the last check's
|
|
14
|
+
* outcome. A stale answer is re-read; `refresh=1` forces a fresh check.
|
|
15
|
+
* - `POST /api/wsl-env/plugin-update` — install that release through
|
|
16
|
+
* `updateBundle`. It is one click in the panel, never automatic: a plugin
|
|
17
|
+
* that silently replaces its own code under a running harness is a
|
|
18
|
+
* posture this plugin rejects.
|
|
19
|
+
*
|
|
20
|
+
* Nothing here fetches the registry or runs pnpm directly. A host without a
|
|
21
|
+
* plugin-manager (or one from before `updateBundle` existed) still gets the
|
|
22
|
+
* installed version and an explanation; a linked checkout is refused by the
|
|
23
|
+
* host as `not-updatable` and the panel points at the Plugins page instead.
|
|
24
|
+
*
|
|
25
|
+
* This is a TypeScript source built to `lib/plugin-update.js`; edit THIS file
|
|
26
|
+
* and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
27
|
+
* `pnpm test` fails when it drifts.
|
|
28
|
+
*
|
|
29
|
+
* @module dsh-plugin-wsl-env/plugin-update
|
|
30
|
+
*/
|
|
31
|
+
import z from "@deepseek-ai/schemastery";
|
|
32
|
+
import { readFileSync } from "node:fs";
|
|
33
|
+
import { inspectVersions, PACKAGE, setUpdateFact, } from "./update-check.js";
|
|
34
|
+
export const name = "wsl-plugin-update";
|
|
35
|
+
/** The one route the panel fetches; it must live under the `/api` channel. */
|
|
36
|
+
export const PLUGIN_UPDATE_PATH = "/api/wsl-env/plugin-update";
|
|
37
|
+
/** How long a version answer stays fresh before a panel load re-reads it. */
|
|
38
|
+
export const DEFAULT_CACHE_MS = 10 * 60 * 1000;
|
|
39
|
+
export const Config = z.object({
|
|
40
|
+
/** How long a version answer stays fresh, in milliseconds. */
|
|
41
|
+
cacheMs: z.natural().default(DEFAULT_CACHE_MS),
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* Read this package's version from the manifest beside `lib/`.
|
|
45
|
+
* @returns the version, or undefined when the manifest is unreadable.
|
|
46
|
+
*/
|
|
47
|
+
function packageVersion() {
|
|
48
|
+
try {
|
|
49
|
+
const parsed = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
50
|
+
return typeof parsed.version === "string" ? parsed.version : undefined;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The version this process loaded. A successful one-click upgrade replaces
|
|
58
|
+
* the manifest before the old module graph is gone, so the panel must be able
|
|
59
|
+
* to say "installed X, running Y" until the app reloads.
|
|
60
|
+
*/
|
|
61
|
+
const RUNNING_VERSION = packageVersion() ?? "unknown";
|
|
62
|
+
/**
|
|
63
|
+
* The version installed on disk now; it moves after an upgrade while
|
|
64
|
+
* {@link RUNNING_VERSION} stays at the loaded generation until a reload.
|
|
65
|
+
*
|
|
66
|
+
* @returns the manifest's version, or the loaded one when the file cannot be read.
|
|
67
|
+
*/
|
|
68
|
+
export function installedVersion() {
|
|
69
|
+
return packageVersion() ?? RUNNING_VERSION;
|
|
70
|
+
}
|
|
71
|
+
/** The version this process loaded. */
|
|
72
|
+
export function runningVersion() {
|
|
73
|
+
return RUNNING_VERSION;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The update-capable slice of a manager, when it has one. A host from before
|
|
77
|
+
* `updateBundle` still answers version checks; it just cannot offer the click.
|
|
78
|
+
* @param manager - the host plugin-manager, or undefined.
|
|
79
|
+
* @returns the manager with its updater, or undefined.
|
|
80
|
+
*/
|
|
81
|
+
function updaterOf(manager) {
|
|
82
|
+
if (manager === undefined)
|
|
83
|
+
return undefined;
|
|
84
|
+
const candidate = manager;
|
|
85
|
+
return typeof candidate.updateBundle === "function" ? candidate : undefined;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* One JSON response with the route's own no-store policy.
|
|
89
|
+
* @param body - the JSON-serializable value.
|
|
90
|
+
* @param status - the HTTP status.
|
|
91
|
+
* @returns a JSON response.
|
|
92
|
+
*/
|
|
93
|
+
function json(body, status = 200) {
|
|
94
|
+
return Response.json(body, { status, headers: { "cache-control": "no-store" } });
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Build the route handler.
|
|
98
|
+
*
|
|
99
|
+
* One handler owns one cache and one update slot, so the row registers exactly
|
|
100
|
+
* one instance and an unload drops both. The version check is cached for
|
|
101
|
+
* `cacheMs` because one answer costs several `pnpm view` calls in the profile;
|
|
102
|
+
* an update is never cached.
|
|
103
|
+
*
|
|
104
|
+
* @param options - the manager, clock, and cache seams.
|
|
105
|
+
* @returns the request handler.
|
|
106
|
+
*/
|
|
107
|
+
export function createPluginUpdateHandler(options) {
|
|
108
|
+
const now = options.now ?? (() => Date.now());
|
|
109
|
+
const installed = options.installed ?? installedVersion;
|
|
110
|
+
const running = options.running ?? RUNNING_VERSION;
|
|
111
|
+
/** One cached check; `at` is the clock read when the check started. */
|
|
112
|
+
let cache;
|
|
113
|
+
/** A check already in flight, so two panel loads share one registry round-trip. */
|
|
114
|
+
let inflight;
|
|
115
|
+
/** One update at a time; a second click must not start a second removal/install pair. */
|
|
116
|
+
let updating = false;
|
|
117
|
+
const currentCheck = async (refresh) => {
|
|
118
|
+
if (!refresh && cache !== undefined && now() - cache.at < options.cacheMs) {
|
|
119
|
+
return { check: cache.check, cached: true };
|
|
120
|
+
}
|
|
121
|
+
if (inflight !== undefined)
|
|
122
|
+
return { check: await inflight, cached: false };
|
|
123
|
+
const manager = options.manager();
|
|
124
|
+
const at = now();
|
|
125
|
+
const pending = inspectVersions(manager, installed(), at);
|
|
126
|
+
inflight = pending;
|
|
127
|
+
try {
|
|
128
|
+
const check = await pending;
|
|
129
|
+
// A missing manager is cheap to re-read, and a host can gain one at
|
|
130
|
+
// runtime; everything else (including a registry refusal) is cached.
|
|
131
|
+
if (!(check.status === "unavailable" && check.problem === "no-manager"))
|
|
132
|
+
cache = { at, check };
|
|
133
|
+
return { check, cached: false };
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
inflight = undefined;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
const viewOf = (check, cached, updateSupported) => ({
|
|
140
|
+
installed: installed(),
|
|
141
|
+
running,
|
|
142
|
+
status: check.status,
|
|
143
|
+
checkedAt: check.checkedAt,
|
|
144
|
+
cached,
|
|
145
|
+
updateSupported,
|
|
146
|
+
canUpdate: check.status === "available" && updateSupported && check.latest.incompatible === undefined,
|
|
147
|
+
...(check.status === "unavailable" ? { problem: check.problem, reason: check.reason } : {}),
|
|
148
|
+
...(check.status === "available" ? { registry: check.registry, latest: check.latest } : {}),
|
|
149
|
+
...(check.status === "current" ? { registry: check.registry } : {}),
|
|
150
|
+
});
|
|
151
|
+
/**
|
|
152
|
+
* Read the version answer, including the panel's auto-check on first load.
|
|
153
|
+
* @param refresh - whether to ignore a fresh cache entry.
|
|
154
|
+
* @returns the session's JSON response.
|
|
155
|
+
*/
|
|
156
|
+
const read = async (refresh) => {
|
|
157
|
+
try {
|
|
158
|
+
const { check, cached } = await currentCheck(refresh);
|
|
159
|
+
return json(viewOf(check, cached, updaterOf(options.manager()) !== undefined));
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
return json({ error: error instanceof Error ? error.message : String(error) }, 500);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* Run the one-click upgrade. The target is the check's installable stable
|
|
167
|
+
* release; `updateBundle` re-validates existence, bundle declaration, and
|
|
168
|
+
* compatibility, and performs the removal/install/rollback itself.
|
|
169
|
+
* @returns the session's JSON response.
|
|
170
|
+
*/
|
|
171
|
+
const update = async () => {
|
|
172
|
+
if (updating)
|
|
173
|
+
return json({ error: "An update is already running" }, 409);
|
|
174
|
+
const manager = options.manager();
|
|
175
|
+
if (manager === undefined) {
|
|
176
|
+
return json({ error: "The host has no plugin-manager; update from the Plugins page" }, 503);
|
|
177
|
+
}
|
|
178
|
+
const updater = updaterOf(manager);
|
|
179
|
+
if (updater === undefined) {
|
|
180
|
+
return json({ error: "This plugin-manager cannot update bundles; update from the Plugins page" }, 501);
|
|
181
|
+
}
|
|
182
|
+
let check;
|
|
183
|
+
try {
|
|
184
|
+
check = (await currentCheck(false)).check;
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
return json({ error: error instanceof Error ? error.message : String(error) }, 500);
|
|
188
|
+
}
|
|
189
|
+
if (check.status === "current")
|
|
190
|
+
return json({ error: "The installed version is up to date" }, 409);
|
|
191
|
+
if (check.status === "unavailable")
|
|
192
|
+
return json({ error: `No update target: ${check.reason}` }, 409);
|
|
193
|
+
if (check.latest.incompatible !== undefined) {
|
|
194
|
+
return json({ error: "The latest release requires a newer DSH; upgrade DeepSeek Harness first" }, 409);
|
|
195
|
+
}
|
|
196
|
+
updating = true;
|
|
197
|
+
try {
|
|
198
|
+
const result = await updater.updateBundle(PACKAGE, check.latest.version, { registry: check.registry });
|
|
199
|
+
cache = undefined;
|
|
200
|
+
const application = result.result.application;
|
|
201
|
+
// `overridden` still installed the target; the host reports it when a
|
|
202
|
+
// higher-priority profile layer overrides the bundle selection.
|
|
203
|
+
const updated = result.step === "install" && application !== "failed" && application !== "cancelled";
|
|
204
|
+
if (updated)
|
|
205
|
+
setUpdateFact(undefined);
|
|
206
|
+
const restoreError = result.restore?.error;
|
|
207
|
+
return json({
|
|
208
|
+
updated,
|
|
209
|
+
application,
|
|
210
|
+
from: result.from,
|
|
211
|
+
to: result.to,
|
|
212
|
+
step: result.step,
|
|
213
|
+
installed: installed(),
|
|
214
|
+
running,
|
|
215
|
+
checkedAt: now(),
|
|
216
|
+
...(result.result.restartReason === undefined ? {} : { restartReason: result.result.restartReason }),
|
|
217
|
+
...(result.restore === undefined ? {} : { restored: result.restore.application === "applied" }),
|
|
218
|
+
...(result.result.error === undefined ? {} : {
|
|
219
|
+
error: {
|
|
220
|
+
...(result.result.error.code === undefined ? {} : { code: result.result.error.code }),
|
|
221
|
+
...(result.result.error.diagnostic === undefined ? {} : { diagnostic: result.result.error.diagnostic }),
|
|
222
|
+
},
|
|
223
|
+
}),
|
|
224
|
+
...(result.result.pendingBuilds === undefined ? {} : { pendingBuilds: result.result.pendingBuilds }),
|
|
225
|
+
...(restoreError === undefined ? {} : {
|
|
226
|
+
restoreError: {
|
|
227
|
+
...(restoreError.code === undefined ? {} : { code: restoreError.code }),
|
|
228
|
+
...(restoreError.diagnostic === undefined ? {} : { diagnostic: restoreError.diagnostic }),
|
|
229
|
+
},
|
|
230
|
+
}),
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
cache = undefined;
|
|
235
|
+
return json({ error: error instanceof Error ? error.message : String(error) }, 502);
|
|
236
|
+
}
|
|
237
|
+
finally {
|
|
238
|
+
updating = false;
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
return async (request) => {
|
|
242
|
+
if (request.method !== "GET" && request.method !== "POST") {
|
|
243
|
+
return json({ error: "Only GET and POST are supported" }, 405);
|
|
244
|
+
}
|
|
245
|
+
if (request.method === "GET") {
|
|
246
|
+
const refresh = new URL(request.url).searchParams.get("refresh") === "1";
|
|
247
|
+
return read(refresh);
|
|
248
|
+
}
|
|
249
|
+
return update();
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Mount the row: register the route once the Host connection is available.
|
|
254
|
+
*
|
|
255
|
+
* A composition without `connection` (headless, ACP) leaves the row inert —
|
|
256
|
+
* the same posture the status row takes.
|
|
257
|
+
*
|
|
258
|
+
* @param ctx - the cordis context.
|
|
259
|
+
* @param config - the schema-validated plugin config.
|
|
260
|
+
*/
|
|
261
|
+
export function apply(ctx, config = {}) {
|
|
262
|
+
if (typeof ctx.inject !== "function")
|
|
263
|
+
return;
|
|
264
|
+
ctx.inject(["connection"], (scope) => {
|
|
265
|
+
const connection = scope.connection ?? scope.get?.("connection");
|
|
266
|
+
if (connection === undefined || typeof connection.fetch?.register !== "function")
|
|
267
|
+
return;
|
|
268
|
+
const manager = () => (ctx.get?.("pluginManager") ?? scope.get?.("pluginManager"));
|
|
269
|
+
const handler = createPluginUpdateHandler({
|
|
270
|
+
manager,
|
|
271
|
+
cacheMs: config.cacheMs ?? DEFAULT_CACHE_MS,
|
|
272
|
+
installed: installedVersion,
|
|
273
|
+
running: RUNNING_VERSION,
|
|
274
|
+
});
|
|
275
|
+
const dispose = connection.fetch.register({
|
|
276
|
+
path: PLUGIN_UPDATE_PATH,
|
|
277
|
+
methods: ["GET", "POST"],
|
|
278
|
+
requestBody: "buffered",
|
|
279
|
+
fetch: handler,
|
|
280
|
+
});
|
|
281
|
+
scope.effect?.(() => () => { void dispose(); }, `wsl-plugin-update: ${PLUGIN_UPDATE_PATH}`);
|
|
282
|
+
});
|
|
283
|
+
}
|
package/lib/ports.js
CHANGED
|
@@ -50,6 +50,8 @@ export function parseListeningPorts(text) {
|
|
|
50
50
|
export function procNetScript() {
|
|
51
51
|
return "cat /proc/net/tcp /proc/net/tcp6 2>/dev/null";
|
|
52
52
|
}
|
|
53
|
+
/** Capture ceiling for the `/proc/net` survey; the file is kilobytes, the cap is a transport guard. */
|
|
54
|
+
const PORTS_OUTPUT_CAP_BYTES = 1_000_000;
|
|
53
55
|
/**
|
|
54
56
|
* Snapshot the distro's listening ports through the agent.
|
|
55
57
|
*
|
|
@@ -60,7 +62,12 @@ export function procNetScript() {
|
|
|
60
62
|
*/
|
|
61
63
|
export async function scanListeningPorts(runner, timeoutMs = 10000) {
|
|
62
64
|
try {
|
|
63
|
-
const result = await runner.exec({
|
|
65
|
+
const result = await runner.exec({
|
|
66
|
+
cwd: "/",
|
|
67
|
+
argv: ["sh", "-c", procNetScript(), "ports"],
|
|
68
|
+
timeoutMs,
|
|
69
|
+
maxOutputBytes: PORTS_OUTPUT_CAP_BYTES,
|
|
70
|
+
});
|
|
64
71
|
if (result.exitCode !== 0)
|
|
65
72
|
return undefined;
|
|
66
73
|
return parseListeningPorts(result.stdout.toString("utf8"));
|
package/lib/provider-common.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SandboxExecutionPolicy } from "@deepseek-ai/dsh-sandbox";
|
|
2
|
+
import type { SessionRuntimeEntry } from "./session-runtime.js";
|
|
2
3
|
interface DistroHomeOwner {
|
|
3
4
|
config: unknown;
|
|
4
5
|
resolvedDistro: string;
|
|
@@ -55,4 +56,25 @@ export declare function sessionRuntimeWanted(value: boolean | "auto", distro: st
|
|
|
55
56
|
usable: boolean;
|
|
56
57
|
checkedAt: number;
|
|
57
58
|
}>): Promise<boolean>;
|
|
59
|
+
/**
|
|
60
|
+
* The per-provider bookkeeping the filesystem and shell providers share.
|
|
61
|
+
*
|
|
62
|
+
* Both rows cache distro homes, hold session runtimes by registry key, cache
|
|
63
|
+
* the session-runtime preflight that succeeded per distro, and cache the
|
|
64
|
+
* `auto` preflight verdict. Own the state in one place so a semantic change
|
|
65
|
+
* (the last one was the session-runtime move) is made once, not twice.
|
|
66
|
+
*/
|
|
67
|
+
export declare class ProviderRuntimeBook {
|
|
68
|
+
/** Per-distro homes, so two concurrent distros cannot share one. */
|
|
69
|
+
readonly homes: Map<string, string>;
|
|
70
|
+
/** The runtimes this provider holds, by registry key. */
|
|
71
|
+
readonly sessionRuntimeEntries: Map<string, SessionRuntimeEntry>;
|
|
72
|
+
/** Distros whose session-runtime preflight has succeeded. */
|
|
73
|
+
readonly sessionRuntimePreflight: Set<string>;
|
|
74
|
+
/** Per-distro `auto` verdicts, re-probed when they were negative and stale. */
|
|
75
|
+
readonly autoSessionScope: Map<string, {
|
|
76
|
+
usable: boolean;
|
|
77
|
+
checkedAt: number;
|
|
78
|
+
}>;
|
|
79
|
+
}
|
|
58
80
|
export {};
|
package/lib/provider-common.js
CHANGED
|
@@ -121,3 +121,21 @@ export async function sessionRuntimeWanted(value, distro, ensure, cache) {
|
|
|
121
121
|
return false;
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* The per-provider bookkeeping the filesystem and shell providers share.
|
|
126
|
+
*
|
|
127
|
+
* Both rows cache distro homes, hold session runtimes by registry key, cache
|
|
128
|
+
* the session-runtime preflight that succeeded per distro, and cache the
|
|
129
|
+
* `auto` preflight verdict. Own the state in one place so a semantic change
|
|
130
|
+
* (the last one was the session-runtime move) is made once, not twice.
|
|
131
|
+
*/
|
|
132
|
+
export class ProviderRuntimeBook {
|
|
133
|
+
/** Per-distro homes, so two concurrent distros cannot share one. */
|
|
134
|
+
homes = new Map();
|
|
135
|
+
/** The runtimes this provider holds, by registry key. */
|
|
136
|
+
sessionRuntimeEntries = new Map();
|
|
137
|
+
/** Distros whose session-runtime preflight has succeeded. */
|
|
138
|
+
sessionRuntimePreflight = new Set();
|
|
139
|
+
/** Per-distro `auto` verdicts, re-probed when they were negative and stale. */
|
|
140
|
+
autoSessionScope = new Map();
|
|
141
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The brand the root-plane takeover providers carry for the in-app doctor.
|
|
3
|
+
*
|
|
4
|
+
* `takeover-report` needs to tell this plugin's `subprocess`, `fs` and
|
|
5
|
+
* `directoryPicker` providers from the shipped ones. `instanceof` did that at
|
|
6
|
+
* the cost of an import edge into the whole provider graph — and that graph
|
|
7
|
+
* loads `agent-shared`, which hashes the agent script at module load. A
|
|
8
|
+
* symbol-valued brand on each provider's prototype answers the same question
|
|
9
|
+
* without importing the classes: the diagnostic surface stays small, including
|
|
10
|
+
* in the preset realm where `wsl-doctor-tool` mounts.
|
|
11
|
+
*
|
|
12
|
+
* `Symbol.for` (not `Symbol`) is deliberate: a profile can load two copies of
|
|
13
|
+
* this package, and both should agree on the marker's identity.
|
|
14
|
+
*
|
|
15
|
+
* This is a TypeScript source built to `lib/provider-marker.js`; edit THIS file
|
|
16
|
+
* and run `pnpm run build`.
|
|
17
|
+
*
|
|
18
|
+
* @module dsh-plugin-wsl-env/provider-marker
|
|
19
|
+
*/
|
|
20
|
+
/** The marker key the takeover providers and the report share. */
|
|
21
|
+
export declare const PLUGIN_PROVIDER: unique symbol;
|
|
22
|
+
/** The service names a plugin provider can carry. */
|
|
23
|
+
export type PluginProviderService = "subprocess" | "fs" | "directoryPicker";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The brand the root-plane takeover providers carry for the in-app doctor.
|
|
3
|
+
*
|
|
4
|
+
* `takeover-report` needs to tell this plugin's `subprocess`, `fs` and
|
|
5
|
+
* `directoryPicker` providers from the shipped ones. `instanceof` did that at
|
|
6
|
+
* the cost of an import edge into the whole provider graph — and that graph
|
|
7
|
+
* loads `agent-shared`, which hashes the agent script at module load. A
|
|
8
|
+
* symbol-valued brand on each provider's prototype answers the same question
|
|
9
|
+
* without importing the classes: the diagnostic surface stays small, including
|
|
10
|
+
* in the preset realm where `wsl-doctor-tool` mounts.
|
|
11
|
+
*
|
|
12
|
+
* `Symbol.for` (not `Symbol`) is deliberate: a profile can load two copies of
|
|
13
|
+
* this package, and both should agree on the marker's identity.
|
|
14
|
+
*
|
|
15
|
+
* This is a TypeScript source built to `lib/provider-marker.js`; edit THIS file
|
|
16
|
+
* and run `pnpm run build`.
|
|
17
|
+
*
|
|
18
|
+
* @module dsh-plugin-wsl-env/provider-marker
|
|
19
|
+
*/
|
|
20
|
+
/** The marker key the takeover providers and the report share. */
|
|
21
|
+
export const PLUGIN_PROVIDER = Symbol.for("dsh-plugin-wsl-env/provider");
|
package/lib/sandbox-core.d.ts
CHANGED
|
@@ -119,6 +119,8 @@ export interface WslSandboxCoreInstance {
|
|
|
119
119
|
distro: string;
|
|
120
120
|
signal?: AbortSignal | undefined;
|
|
121
121
|
writableRoots?: readonly string[] | undefined;
|
|
122
|
+
socketMasks?: readonly string[] | undefined;
|
|
123
|
+
maskInterop?: boolean | undefined;
|
|
122
124
|
}) => Promise<WslConfined>;
|
|
123
125
|
}
|
|
124
126
|
/**
|
package/lib/sandbox-core.js
CHANGED
|
@@ -277,9 +277,11 @@ export function createSandboxCore({ SandboxUnavailableError }) {
|
|
|
277
277
|
* @param argv - the argv to run INSIDE the distro (shell, its flags, command).
|
|
278
278
|
* @param policy - the resolved confined policy (`mode` is never
|
|
279
279
|
* `danger-full-access`; the caller does not confine that case at all).
|
|
280
|
-
* @param options - the distro to run in, optional cancellation,
|
|
280
|
+
* @param options - the distro to run in, optional cancellation, the
|
|
281
281
|
* resolved extra writable roots (already Linux paths, filtered and
|
|
282
|
-
* physically checked by the provider)
|
|
282
|
+
* physically checked by the provider), and the existing socket paths
|
|
283
|
+
* the profile masks (resolved by the provider), and whether to shadow
|
|
284
|
+
* the WSL interop transport at `/run/WSL`.
|
|
283
285
|
* @returns the wrapped argv plus the settlement-classification facts, in the
|
|
284
286
|
* seam's `ConfinedArgv` shape.
|
|
285
287
|
* @throws SandboxUnavailableError when the distro has no usable `bwrap`, so a
|
|
@@ -291,7 +293,7 @@ export function createSandboxCore({ SandboxUnavailableError }) {
|
|
|
291
293
|
throw new SandboxUnavailableError(policy.mode, bwrapFailure(this.wslPath, distro) ?? missingBwrapRemedy(distro));
|
|
292
294
|
}
|
|
293
295
|
const workspaceRoot = toLinuxPath(policy.workspaceRoot);
|
|
294
|
-
const prefix = bwrapArgvPrefix({ ...policy, workspaceRoot }, { maskWindowsDrive: this.maskWindowsDrive, writableRoots: options.writableRoots });
|
|
296
|
+
const prefix = bwrapArgvPrefix({ ...policy, workspaceRoot }, { maskWindowsDrive: this.maskWindowsDrive, writableRoots: options.writableRoots, socketMasks: options.socketMasks, maskInterop: options.maskInterop });
|
|
295
297
|
return {
|
|
296
298
|
argv: [...prefix, ...argv],
|
|
297
299
|
enforcement: ENFORCEMENT,
|