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
package/lib/session-runtime.d.ts
CHANGED
|
@@ -61,6 +61,15 @@ interface SessionRuntimeRequest {
|
|
|
61
61
|
* because the mount table is fixed for the runtime's lifetime.
|
|
62
62
|
*/
|
|
63
63
|
writableRoots?: readonly string[];
|
|
64
|
+
/**
|
|
65
|
+
* Existing socket paths the runtime's bwrap profile masks: the user systemd
|
|
66
|
+
* manager's sockets and, for `strict`, the system bus and container
|
|
67
|
+
* sockets. Resolved by the provider (`lib/socket-isolation.js`); part of
|
|
68
|
+
* the key because the mount table is fixed for the runtime's lifetime.
|
|
69
|
+
*/
|
|
70
|
+
socketMasks?: readonly string[];
|
|
71
|
+
/** Shadow `/run/WSL`, the WSL interop transport, inside the runtime. */
|
|
72
|
+
maskInterop?: boolean;
|
|
64
73
|
/** The agent's client lease; 0 disables. */
|
|
65
74
|
leaseMs?: number;
|
|
66
75
|
}
|
|
@@ -140,7 +149,7 @@ export declare class SessionRuntimes {
|
|
|
140
149
|
* @param request - the runtime request.
|
|
141
150
|
* @returns the registry key.
|
|
142
151
|
*/
|
|
143
|
-
static key(request: Pick<SessionRuntimeRequest, "distro" | "workspaceRoot" | "mode" | "maskWindowsDrive" | "sessionId" | "writableRoots">): string;
|
|
152
|
+
static key(request: Pick<SessionRuntimeRequest, "distro" | "workspaceRoot" | "mode" | "maskWindowsDrive" | "sessionId" | "writableRoots" | "socketMasks" | "maskInterop">): string;
|
|
144
153
|
/**
|
|
145
154
|
* Acquire the runtime for one key, creating it on first use.
|
|
146
155
|
*
|
package/lib/session-runtime.js
CHANGED
|
@@ -153,6 +153,8 @@ export class SessionRuntimes {
|
|
|
153
153
|
request.mode,
|
|
154
154
|
request.maskWindowsDrive === true ? "masked" : "visible",
|
|
155
155
|
(request.writableRoots ?? []).join("\u0000"),
|
|
156
|
+
(request.socketMasks ?? []).join("\u0000"),
|
|
157
|
+
request.maskInterop === true ? "interop-masked" : "interop-visible",
|
|
156
158
|
].join("\u0000");
|
|
157
159
|
}
|
|
158
160
|
/**
|
|
@@ -172,7 +174,7 @@ export class SessionRuntimes {
|
|
|
172
174
|
const unit = sessionScopeUnit(request.distro, this.token());
|
|
173
175
|
const prefix = sessionScopePrefix(unit);
|
|
174
176
|
if (request.mode !== "danger-full-access") {
|
|
175
|
-
prefix.push(...bwrapArgvPrefix({ mode: request.mode, workspaceRoot: toLinuxPath(request.workspaceRoot) }, { maskWindowsDrive: request.maskWindowsDrive, realTmp: true, pidNamespace: false, writableRoots: request.writableRoots }));
|
|
177
|
+
prefix.push(...bwrapArgvPrefix({ mode: request.mode, workspaceRoot: toLinuxPath(request.workspaceRoot) }, { maskWindowsDrive: request.maskWindowsDrive, realTmp: true, pidNamespace: false, writableRoots: request.writableRoots, socketMasks: request.socketMasks, maskInterop: request.maskInterop }));
|
|
176
178
|
}
|
|
177
179
|
const agent = this.spawnAgent({
|
|
178
180
|
distro: request.distro,
|
package/lib/shell-env.js
CHANGED
|
@@ -155,7 +155,7 @@ export async function apply(ctx, config = {}) {
|
|
|
155
155
|
description: `Ports with a listener inside that distro (comma-separated, ascending), as of the last snapshot — refreshed every ${Math.round(portsRefreshMs / 1000)}s, so a dev server started moments ago may not be listed yet. Empty means none were listening at the last successful scan (or no scan has succeeded yet); a failed scan keeps the last successful list.`,
|
|
156
156
|
},
|
|
157
157
|
DSH_WSL_PLUGIN_UPDATE: {
|
|
158
|
-
description: "A newer release of this plugin (dsh-plugin-wsl-env), as of the last update check — checked against the registry about once a day. Empty means the installed version is current (or the check has not run yet).
|
|
158
|
+
description: "A newer release of this plugin (dsh-plugin-wsl-env), as of the last update check — checked against the registry about once a day. Empty means the installed version is current (or the check has not run yet). Upgrade from the sidebar WSL environment panel's version card (one-click upgrade), or from the Plugins page's Versions section; restart DSH or reload the page when the host reports it.",
|
|
159
159
|
},
|
|
160
160
|
DSH_WSL_DOCTOR: {
|
|
161
161
|
description: "Ready-to-run command that executes this plugin's environment doctor (scripts/doctor.mjs) from inside a session, using the app's own runtime as Node — no terminal or separate Node install needed. Run it as: sh -c \"$DSH_WSL_DOCTOR --json\" (drop --json for the human report). The output ends in a verdict (ready, or blocked with per-failure copy-paste remedies).",
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The socket surfaces a confined COMMAND must not reach, and the bwrap masks
|
|
3
|
+
* that close them.
|
|
4
|
+
*
|
|
5
|
+
* The sandbox's mount profile confines file effects; it does not confine
|
|
6
|
+
* process authority. A confined command can still talk to the user's systemd
|
|
7
|
+
* manager (`$XDG_RUNTIME_DIR/bus`, `$XDG_RUNTIME_DIR/systemd/private`) and ask
|
|
8
|
+
* it to start a unit outside the mount namespace, or connect to a container
|
|
9
|
+
* daemon's socket and start a container outside it. Both are documented
|
|
10
|
+
* escapes from the write fence ([SECURITY.md](../SECURITY.md)); `session-bus`
|
|
11
|
+
* masks the user manager, `strict` adds the system bus and the container
|
|
12
|
+
* sockets that exist and are writable for the distro user.
|
|
13
|
+
*
|
|
14
|
+
* The module is peer-free and splits into three pure pieces plus one probe:
|
|
15
|
+
*
|
|
16
|
+
* 1. {@link socketIsolationProbeScript} runs inside the distro and reports
|
|
17
|
+
* the runtime directory, the user-manager sockets, and the strict
|
|
18
|
+
* sockets that exist and the user can use.
|
|
19
|
+
* 2. {@link parseSocketIsolationFacts} turns that output into facts.
|
|
20
|
+
* 3. {@link socketMaskPaths} maps a mode plus facts to the absolute paths
|
|
21
|
+
* bwrap binds `/dev/null` over.
|
|
22
|
+
* 4. {@link socketMasksFor} runs the probe once per `(wslPath, distro)` and
|
|
23
|
+
* caches the facts; a probe failure is thrown, never read as "nothing to
|
|
24
|
+
* mask" — a configured isolation that silently disappears is worse than
|
|
25
|
+
* no isolation.
|
|
26
|
+
*
|
|
27
|
+
* The masks are a narrowing, not a closure. The distro user's other IPC
|
|
28
|
+
* (`/proc`, a same-user process's sockets, the interop transport) remains;
|
|
29
|
+
* `sandbox` enforcement stays `partial`, and [SECURITY.md](../SECURITY.md) says
|
|
30
|
+
* so.
|
|
31
|
+
*
|
|
32
|
+
* This is a TypeScript source built to `lib/socket-isolation.js`; edit THIS
|
|
33
|
+
* file and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
34
|
+
* `pnpm test` fails when it drifts.
|
|
35
|
+
*
|
|
36
|
+
* @module dsh-plugin-wsl-env/socket-isolation
|
|
37
|
+
*/
|
|
38
|
+
/** The three socket-isolation stances a confined command profile can take. */
|
|
39
|
+
export type SocketIsolation = "off" | "session-bus" | "strict";
|
|
40
|
+
/** The values the config schema accepts, in display order. */
|
|
41
|
+
export declare const SOCKET_ISOLATION_VALUES: readonly SocketIsolation[];
|
|
42
|
+
/** What one in-distro probe learned about the socket surfaces. */
|
|
43
|
+
export interface SocketIsolationFacts {
|
|
44
|
+
/** The distro user's runtime directory (`$XDG_RUNTIME_DIR` or `/run/user/<uid>`). */
|
|
45
|
+
runtimeDir: string;
|
|
46
|
+
/** The user systemd manager's sockets that exist (`bus`, `systemd/private`). */
|
|
47
|
+
userSockets: string[];
|
|
48
|
+
/** The strict-mode sockets that exist and the distro user can connect to. */
|
|
49
|
+
strictSockets: string[];
|
|
50
|
+
}
|
|
51
|
+
/** A configured isolation that could not be resolved; the provider turns this into a fail-closed sandbox refusal. */
|
|
52
|
+
export declare class SocketIsolationError extends Error {
|
|
53
|
+
/** The configured stance. */
|
|
54
|
+
readonly mode: SocketIsolation;
|
|
55
|
+
/**
|
|
56
|
+
* @param mode - the configured stance.
|
|
57
|
+
* @param message - the model-facing reason.
|
|
58
|
+
*/
|
|
59
|
+
constructor(mode: SocketIsolation, message: string);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The shell script the probe runs inside the distro. It prints one fact per
|
|
63
|
+
* line: `R <runtimeDir>`, `U <user-manager socket>`, `S <strict socket>`.
|
|
64
|
+
* A strict socket is emitted only when it exists and the user can use it;
|
|
65
|
+
* a symlinked container socket is emitted as its resolved target, because
|
|
66
|
+
* binding `/dev/null` over a symlink path fails and the target is the socket
|
|
67
|
+
* a client actually reaches.
|
|
68
|
+
*
|
|
69
|
+
* @returns the `sh -c` body.
|
|
70
|
+
*/
|
|
71
|
+
export declare function socketIsolationProbeScript(): string;
|
|
72
|
+
/**
|
|
73
|
+
* Parse the probe's lines into facts.
|
|
74
|
+
*
|
|
75
|
+
* @param text - the probe's stdout.
|
|
76
|
+
* @returns the facts; empty lists when a section is absent.
|
|
77
|
+
*/
|
|
78
|
+
export declare function parseSocketIsolationFacts(text: string): SocketIsolationFacts;
|
|
79
|
+
/**
|
|
80
|
+
* The absolute paths a profile binds `/dev/null` over for one stance.
|
|
81
|
+
*
|
|
82
|
+
* @param mode - the configured stance.
|
|
83
|
+
* @param facts - the distro's socket facts.
|
|
84
|
+
* @returns the masks, deduplicated; empty for `off`.
|
|
85
|
+
*/
|
|
86
|
+
export declare function socketMaskPaths(mode: SocketIsolation, facts: SocketIsolationFacts): string[];
|
|
87
|
+
/** Test hook: forget the remembered facts. */
|
|
88
|
+
export declare function resetSocketIsolationCache(): void;
|
|
89
|
+
/**
|
|
90
|
+
* Resolve the socket masks for one distro and stance, running the in-distro
|
|
91
|
+
* probe once per `(wslPath, distro)`.
|
|
92
|
+
*
|
|
93
|
+
* @param options - the stance, transport, distro and host runner.
|
|
94
|
+
* @returns the masks; empty for `off`.
|
|
95
|
+
* @throws {SocketIsolationError} when the stance is on and the probe cannot answer.
|
|
96
|
+
*/
|
|
97
|
+
export declare function socketMasksFor(options: {
|
|
98
|
+
mode: SocketIsolation;
|
|
99
|
+
wslPath: string;
|
|
100
|
+
distro: string;
|
|
101
|
+
run: (argv: string[]) => Promise<string>;
|
|
102
|
+
signal?: AbortSignal | undefined;
|
|
103
|
+
}): Promise<string[]>;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The socket surfaces a confined COMMAND must not reach, and the bwrap masks
|
|
3
|
+
* that close them.
|
|
4
|
+
*
|
|
5
|
+
* The sandbox's mount profile confines file effects; it does not confine
|
|
6
|
+
* process authority. A confined command can still talk to the user's systemd
|
|
7
|
+
* manager (`$XDG_RUNTIME_DIR/bus`, `$XDG_RUNTIME_DIR/systemd/private`) and ask
|
|
8
|
+
* it to start a unit outside the mount namespace, or connect to a container
|
|
9
|
+
* daemon's socket and start a container outside it. Both are documented
|
|
10
|
+
* escapes from the write fence ([SECURITY.md](../SECURITY.md)); `session-bus`
|
|
11
|
+
* masks the user manager, `strict` adds the system bus and the container
|
|
12
|
+
* sockets that exist and are writable for the distro user.
|
|
13
|
+
*
|
|
14
|
+
* The module is peer-free and splits into three pure pieces plus one probe:
|
|
15
|
+
*
|
|
16
|
+
* 1. {@link socketIsolationProbeScript} runs inside the distro and reports
|
|
17
|
+
* the runtime directory, the user-manager sockets, and the strict
|
|
18
|
+
* sockets that exist and the user can use.
|
|
19
|
+
* 2. {@link parseSocketIsolationFacts} turns that output into facts.
|
|
20
|
+
* 3. {@link socketMaskPaths} maps a mode plus facts to the absolute paths
|
|
21
|
+
* bwrap binds `/dev/null` over.
|
|
22
|
+
* 4. {@link socketMasksFor} runs the probe once per `(wslPath, distro)` and
|
|
23
|
+
* caches the facts; a probe failure is thrown, never read as "nothing to
|
|
24
|
+
* mask" — a configured isolation that silently disappears is worse than
|
|
25
|
+
* no isolation.
|
|
26
|
+
*
|
|
27
|
+
* The masks are a narrowing, not a closure. The distro user's other IPC
|
|
28
|
+
* (`/proc`, a same-user process's sockets, the interop transport) remains;
|
|
29
|
+
* `sandbox` enforcement stays `partial`, and [SECURITY.md](../SECURITY.md) says
|
|
30
|
+
* so.
|
|
31
|
+
*
|
|
32
|
+
* This is a TypeScript source built to `lib/socket-isolation.js`; edit THIS
|
|
33
|
+
* file and run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
34
|
+
* `pnpm test` fails when it drifts.
|
|
35
|
+
*
|
|
36
|
+
* @module dsh-plugin-wsl-env/socket-isolation
|
|
37
|
+
*/
|
|
38
|
+
/** The values the config schema accepts, in display order. */
|
|
39
|
+
export const SOCKET_ISOLATION_VALUES = ["off", "session-bus", "strict"];
|
|
40
|
+
/** A configured isolation that could not be resolved; the provider turns this into a fail-closed sandbox refusal. */
|
|
41
|
+
export class SocketIsolationError extends Error {
|
|
42
|
+
/** The configured stance. */
|
|
43
|
+
mode;
|
|
44
|
+
/**
|
|
45
|
+
* @param mode - the configured stance.
|
|
46
|
+
* @param message - the model-facing reason.
|
|
47
|
+
*/
|
|
48
|
+
constructor(mode, message) {
|
|
49
|
+
super(message);
|
|
50
|
+
this.name = "SocketIsolationError";
|
|
51
|
+
this.mode = mode;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The shell script the probe runs inside the distro. It prints one fact per
|
|
56
|
+
* line: `R <runtimeDir>`, `U <user-manager socket>`, `S <strict socket>`.
|
|
57
|
+
* A strict socket is emitted only when it exists and the user can use it;
|
|
58
|
+
* a symlinked container socket is emitted as its resolved target, because
|
|
59
|
+
* binding `/dev/null` over a symlink path fails and the target is the socket
|
|
60
|
+
* a client actually reaches.
|
|
61
|
+
*
|
|
62
|
+
* @returns the `sh -c` body.
|
|
63
|
+
*/
|
|
64
|
+
export function socketIsolationProbeScript() {
|
|
65
|
+
return [
|
|
66
|
+
'rt="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"',
|
|
67
|
+
'printf \'R %s\\n\' "$rt"',
|
|
68
|
+
'for p in "$rt/bus" "$rt/systemd/private"; do',
|
|
69
|
+
' [ -S "$p" ] && printf \'U %s\\n\' "$p"',
|
|
70
|
+
"done",
|
|
71
|
+
'for p in /run/dbus/system_bus_socket /run/docker.sock /var/run/docker.sock /run/podman/podman.sock /var/run/podman/podman.sock /run/containerd/containerd.sock /var/run/containerd/containerd.sock /run/crio/crio.sock /run/k3s/containerd/containerd.sock; do',
|
|
72
|
+
' [ -S "$p" ] || continue',
|
|
73
|
+
' [ -w "$p" ] || continue',
|
|
74
|
+
' t=$(readlink -f "$p" 2>/dev/null || true)',
|
|
75
|
+
' [ -n "$t" ] || t="$p"',
|
|
76
|
+
' printf \'S %s\\n\' "$t"',
|
|
77
|
+
"done",
|
|
78
|
+
].join("\n");
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Parse the probe's lines into facts.
|
|
82
|
+
*
|
|
83
|
+
* @param text - the probe's stdout.
|
|
84
|
+
* @returns the facts; empty lists when a section is absent.
|
|
85
|
+
*/
|
|
86
|
+
export function parseSocketIsolationFacts(text) {
|
|
87
|
+
const facts = { runtimeDir: "", userSockets: [], strictSockets: [] };
|
|
88
|
+
for (const raw of text.split(/\r?\n/u)) {
|
|
89
|
+
const line = raw.trim();
|
|
90
|
+
if (line.length === 0)
|
|
91
|
+
continue;
|
|
92
|
+
const space = line.indexOf(" ");
|
|
93
|
+
if (space < 0)
|
|
94
|
+
continue;
|
|
95
|
+
const tag = line.slice(0, space);
|
|
96
|
+
const value = line.slice(space + 1).trim();
|
|
97
|
+
if (value.length === 0 || !value.startsWith("/"))
|
|
98
|
+
continue;
|
|
99
|
+
if (tag === "R")
|
|
100
|
+
facts.runtimeDir = value;
|
|
101
|
+
else if (tag === "U" && !facts.userSockets.includes(value))
|
|
102
|
+
facts.userSockets.push(value);
|
|
103
|
+
else if (tag === "S" && !facts.strictSockets.includes(value))
|
|
104
|
+
facts.strictSockets.push(value);
|
|
105
|
+
}
|
|
106
|
+
return facts;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The absolute paths a profile binds `/dev/null` over for one stance.
|
|
110
|
+
*
|
|
111
|
+
* @param mode - the configured stance.
|
|
112
|
+
* @param facts - the distro's socket facts.
|
|
113
|
+
* @returns the masks, deduplicated; empty for `off`.
|
|
114
|
+
*/
|
|
115
|
+
export function socketMaskPaths(mode, facts) {
|
|
116
|
+
if (mode === "off")
|
|
117
|
+
return [];
|
|
118
|
+
const paths = [...facts.userSockets];
|
|
119
|
+
if (mode === "strict")
|
|
120
|
+
paths.push(...facts.strictSockets);
|
|
121
|
+
return [...new Set(paths)];
|
|
122
|
+
}
|
|
123
|
+
/** The successful facts, keyed by the exact transport + distro pair; a failure is not remembered. */
|
|
124
|
+
const factsCache = new Map();
|
|
125
|
+
/** Test hook: forget the remembered facts. */
|
|
126
|
+
export function resetSocketIsolationCache() {
|
|
127
|
+
factsCache.clear();
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Resolve the socket masks for one distro and stance, running the in-distro
|
|
131
|
+
* probe once per `(wslPath, distro)`.
|
|
132
|
+
*
|
|
133
|
+
* @param options - the stance, transport, distro and host runner.
|
|
134
|
+
* @returns the masks; empty for `off`.
|
|
135
|
+
* @throws {SocketIsolationError} when the stance is on and the probe cannot answer.
|
|
136
|
+
*/
|
|
137
|
+
export async function socketMasksFor(options) {
|
|
138
|
+
if (options.mode === "off")
|
|
139
|
+
return [];
|
|
140
|
+
options.signal?.throwIfAborted();
|
|
141
|
+
const key = `${options.wslPath}\u0000${options.distro}`;
|
|
142
|
+
let pending = factsCache.get(key);
|
|
143
|
+
if (pending === undefined) {
|
|
144
|
+
const argv = [
|
|
145
|
+
options.wslPath,
|
|
146
|
+
...(options.distro.length > 0 ? ["-d", options.distro] : []),
|
|
147
|
+
"--exec",
|
|
148
|
+
"sh",
|
|
149
|
+
"-c",
|
|
150
|
+
socketIsolationProbeScript(),
|
|
151
|
+
];
|
|
152
|
+
pending = options.run(argv).then(parseSocketIsolationFacts);
|
|
153
|
+
factsCache.set(key, pending);
|
|
154
|
+
pending.catch(() => factsCache.delete(key));
|
|
155
|
+
}
|
|
156
|
+
let facts;
|
|
157
|
+
try {
|
|
158
|
+
facts = await pending;
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
162
|
+
throw new SocketIsolationError(options.mode, `socketIsolation: ${options.mode} could not read the distro's socket facts (${reason}); fix the distro access or set socketIsolation: off to accept the partial boundary`);
|
|
163
|
+
}
|
|
164
|
+
options.signal?.throwIfAborted();
|
|
165
|
+
return socketMaskPaths(options.mode, facts);
|
|
166
|
+
}
|
package/lib/status.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The sidebar panel's diagnostic route (`GET`/`POST /api/wsl-env/status`).
|
|
2
|
+
* The sidebar panel's diagnostic route (`GET`/`POST`/`DELETE /api/wsl-env/status`).
|
|
3
3
|
*
|
|
4
4
|
* The panel is a status/config surface, and the authoritative environment
|
|
5
5
|
* verdict is the doctor's. A browser plugin cannot reach a plugin-private Host
|
|
@@ -7,26 +7,32 @@
|
|
|
7
7
|
* it can reach an **authenticated exact Fetch route** on the `/api` channel:
|
|
8
8
|
* `ctx.connection.fetch.register` is the same seam the shipped Session-log and
|
|
9
9
|
* file routes use, it admits only the owner Peer, and it needs no generated
|
|
10
|
-
* wire schema. This row therefore publishes
|
|
10
|
+
* wire schema. This row therefore publishes three answers:
|
|
11
11
|
*
|
|
12
12
|
* - `GET /api/wsl-env/status` — the installed distros (from `wsl.exe -l -q`,
|
|
13
13
|
* which starts nothing) plus the last successful verdict per distro,
|
|
14
14
|
* restored from the store below;
|
|
15
15
|
* - `GET /api/wsl-env/status?distro=<name>` — one distro's quick doctor
|
|
16
16
|
* report, digested to the same shape the `/wsl-doctor` command renders;
|
|
17
|
-
* - `POST /api/wsl-env/status?distro=<name>` — the panel's
|
|
18
|
-
* full doctor run with `--fix-owned`, which sweeps stale session scopes
|
|
17
|
+
* - `POST /api/wsl-env/status?distro=<name>` — the panel's full-check action:
|
|
18
|
+
* a full doctor run with `--fix-owned`, which sweeps stale session scopes
|
|
19
19
|
* and purges a broken agent cache, then re-verifies both and answers with
|
|
20
20
|
* the same digest plus the `fix.*` rows. Nothing outside the plugin's own
|
|
21
21
|
* state is touched (no packages, no Windows git config), so the panel
|
|
22
|
-
* stays a diagnostic surface that can heal its own residue
|
|
22
|
+
* stays a diagnostic surface that can heal its own residue;
|
|
23
|
+
* - `DELETE /api/wsl-env/status[?distro=<name>]` — the panel's clear action:
|
|
24
|
+
* drops one distro's stored verdict, or every stored verdict when no distro
|
|
25
|
+
* is named, and answers `{ cleared: <count> }`. Clearing is host-local on
|
|
26
|
+
* purpose: it reads no distro list and probes nothing, so it still works
|
|
27
|
+
* while `wsl.exe` or the doctor is unavailable. The next GET runs the
|
|
28
|
+
* doctor again instead of serving a removed entry.
|
|
23
29
|
*
|
|
24
30
|
* The doctor runs as the standalone CLI subprocess, exactly as the command row
|
|
25
31
|
* runs it, so a diagnosis still answers when the plugin's own module graph is
|
|
26
32
|
* what is broken. Runs are cached per distro for `cacheMs`; `refresh=1` drops
|
|
27
33
|
* the entry. A check is only ever started by an explicit click in the panel:
|
|
28
34
|
* probing a stopped distro boots it, which a page load must not do to every
|
|
29
|
-
* installed distro.
|
|
35
|
+
* installed distro. Clearing starts nothing.
|
|
30
36
|
*
|
|
31
37
|
* The last result per distro — success or failure — is persisted to
|
|
32
38
|
* `$DSH_HOME/cache/dsh-plugin-wsl-env/status.json` (falling back to `~/.dsh`),
|
|
@@ -34,7 +40,7 @@
|
|
|
34
40
|
* when. `source` records whether that run came from an explicit panel action
|
|
35
41
|
* or from the page-load background refresh; a failed background run overwrites
|
|
36
42
|
* the stored result exactly as it was observed. Results are never labeled
|
|
37
|
-
* expired: the timestamp is the timestamp, and the row's check
|
|
43
|
+
* expired: the timestamp is the timestamp, and the row's check buttons are the
|
|
38
44
|
* next step. Writing is best-effort — a read-only home degrades to the
|
|
39
45
|
* in-memory cache rather than failing the diagnosis.
|
|
40
46
|
*
|
|
@@ -119,7 +125,7 @@ export interface DistroStatusView {
|
|
|
119
125
|
distro: string;
|
|
120
126
|
/** `ready` and `blocked` come from the report; `error` means the run failed. */
|
|
121
127
|
verdict: "ready" | "blocked" | "error";
|
|
122
|
-
/** Whether this answer came from the
|
|
128
|
+
/** Whether this answer came from the full-check action (a full `--fix-owned` run). */
|
|
123
129
|
repaired: boolean;
|
|
124
130
|
/** The doctor's fix rows: what the repair did and whether it verified. */
|
|
125
131
|
repairs: StatusRepair[];
|
|
@@ -190,6 +196,13 @@ export interface DistroListReply {
|
|
|
190
196
|
/** The last stored verdict per installed distro, complete so a reload keeps its details. */
|
|
191
197
|
cached: DistroStatusView[];
|
|
192
198
|
}
|
|
199
|
+
/** The answer to a clear request. */
|
|
200
|
+
export interface ClearReply {
|
|
201
|
+
/** How many stored verdicts the request removed; 0 when the entry was already absent. */
|
|
202
|
+
cleared: number;
|
|
203
|
+
/** The distro whose verdict was removed; absent when every stored verdict was removed. */
|
|
204
|
+
distro?: string;
|
|
205
|
+
}
|
|
193
206
|
/** The route handler this module publishes. */
|
|
194
207
|
export type StatusHandler = (request: Request) => Promise<Response>;
|
|
195
208
|
/** One exact route's registration shape. */
|
package/lib/status.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The sidebar panel's diagnostic route (`GET`/`POST /api/wsl-env/status`).
|
|
2
|
+
* The sidebar panel's diagnostic route (`GET`/`POST`/`DELETE /api/wsl-env/status`).
|
|
3
3
|
*
|
|
4
4
|
* The panel is a status/config surface, and the authoritative environment
|
|
5
5
|
* verdict is the doctor's. A browser plugin cannot reach a plugin-private Host
|
|
@@ -7,26 +7,32 @@
|
|
|
7
7
|
* it can reach an **authenticated exact Fetch route** on the `/api` channel:
|
|
8
8
|
* `ctx.connection.fetch.register` is the same seam the shipped Session-log and
|
|
9
9
|
* file routes use, it admits only the owner Peer, and it needs no generated
|
|
10
|
-
* wire schema. This row therefore publishes
|
|
10
|
+
* wire schema. This row therefore publishes three answers:
|
|
11
11
|
*
|
|
12
12
|
* - `GET /api/wsl-env/status` — the installed distros (from `wsl.exe -l -q`,
|
|
13
13
|
* which starts nothing) plus the last successful verdict per distro,
|
|
14
14
|
* restored from the store below;
|
|
15
15
|
* - `GET /api/wsl-env/status?distro=<name>` — one distro's quick doctor
|
|
16
16
|
* report, digested to the same shape the `/wsl-doctor` command renders;
|
|
17
|
-
* - `POST /api/wsl-env/status?distro=<name>` — the panel's
|
|
18
|
-
* full doctor run with `--fix-owned`, which sweeps stale session scopes
|
|
17
|
+
* - `POST /api/wsl-env/status?distro=<name>` — the panel's full-check action:
|
|
18
|
+
* a full doctor run with `--fix-owned`, which sweeps stale session scopes
|
|
19
19
|
* and purges a broken agent cache, then re-verifies both and answers with
|
|
20
20
|
* the same digest plus the `fix.*` rows. Nothing outside the plugin's own
|
|
21
21
|
* state is touched (no packages, no Windows git config), so the panel
|
|
22
|
-
* stays a diagnostic surface that can heal its own residue
|
|
22
|
+
* stays a diagnostic surface that can heal its own residue;
|
|
23
|
+
* - `DELETE /api/wsl-env/status[?distro=<name>]` — the panel's clear action:
|
|
24
|
+
* drops one distro's stored verdict, or every stored verdict when no distro
|
|
25
|
+
* is named, and answers `{ cleared: <count> }`. Clearing is host-local on
|
|
26
|
+
* purpose: it reads no distro list and probes nothing, so it still works
|
|
27
|
+
* while `wsl.exe` or the doctor is unavailable. The next GET runs the
|
|
28
|
+
* doctor again instead of serving a removed entry.
|
|
23
29
|
*
|
|
24
30
|
* The doctor runs as the standalone CLI subprocess, exactly as the command row
|
|
25
31
|
* runs it, so a diagnosis still answers when the plugin's own module graph is
|
|
26
32
|
* what is broken. Runs are cached per distro for `cacheMs`; `refresh=1` drops
|
|
27
33
|
* the entry. A check is only ever started by an explicit click in the panel:
|
|
28
34
|
* probing a stopped distro boots it, which a page load must not do to every
|
|
29
|
-
* installed distro.
|
|
35
|
+
* installed distro. Clearing starts nothing.
|
|
30
36
|
*
|
|
31
37
|
* The last result per distro — success or failure — is persisted to
|
|
32
38
|
* `$DSH_HOME/cache/dsh-plugin-wsl-env/status.json` (falling back to `~/.dsh`),
|
|
@@ -34,7 +40,7 @@
|
|
|
34
40
|
* when. `source` records whether that run came from an explicit panel action
|
|
35
41
|
* or from the page-load background refresh; a failed background run overwrites
|
|
36
42
|
* the stored result exactly as it was observed. Results are never labeled
|
|
37
|
-
* expired: the timestamp is the timestamp, and the row's check
|
|
43
|
+
* expired: the timestamp is the timestamp, and the row's check buttons are the
|
|
38
44
|
* next step. Writing is best-effort — a read-only home degrades to the
|
|
39
45
|
* in-memory cache rather than failing the diagnosis.
|
|
40
46
|
*
|
|
@@ -45,13 +51,14 @@
|
|
|
45
51
|
* @module dsh-plugin-wsl-env/status
|
|
46
52
|
*/
|
|
47
53
|
import z from "@deepseek-ai/schemastery";
|
|
48
|
-
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
54
|
+
import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
49
55
|
import { homedir } from "node:os";
|
|
50
56
|
import { dirname, join } from "node:path";
|
|
51
57
|
import { listDistros, listRunningDistros } from "./wsl.js";
|
|
52
58
|
import { digestReport, sectionOf } from "./wsl-doctor-tool.js";
|
|
53
59
|
import { runDoctorCli } from "./wsl-doctor-command.js";
|
|
54
60
|
import { mergeAutoPresetSeam } from "./doctor-live.js";
|
|
61
|
+
import { installMessagesLocale, t } from "./messages.js";
|
|
55
62
|
import { mergeTakeoverReport, takeoverSnapshot } from "./takeover-report.js";
|
|
56
63
|
export const name = "wsl-status";
|
|
57
64
|
/** The one route the panel fetches; it must live under the `/api` channel. */
|
|
@@ -101,20 +108,26 @@ function readStored(path) {
|
|
|
101
108
|
/**
|
|
102
109
|
* Write the last successful verdicts atomically. A read-only or missing home
|
|
103
110
|
* must not fail the diagnosis that produced them, so a write error is
|
|
104
|
-
* swallowed: the in-memory answer still reaches the panel.
|
|
111
|
+
* swallowed: the in-memory answer still reaches the panel. An empty map removes
|
|
112
|
+
* the store instead of leaving an empty file behind, so "clear all" leaves no
|
|
113
|
+
* history for the next load to restore.
|
|
105
114
|
* @param path - the store path; empty disables persistence.
|
|
106
115
|
* @param verdicts - the verdicts to persist, keyed by distro.
|
|
107
116
|
*/
|
|
108
117
|
function writeStored(path, verdicts) {
|
|
109
118
|
if (path.length === 0)
|
|
110
119
|
return;
|
|
111
|
-
const distros = {};
|
|
112
|
-
for (const [distro, entry] of verdicts) {
|
|
113
|
-
const stored = { ...entry.view };
|
|
114
|
-
delete stored.cached;
|
|
115
|
-
distros[distro] = stored;
|
|
116
|
-
}
|
|
117
120
|
try {
|
|
121
|
+
if (verdicts.size === 0) {
|
|
122
|
+
rmSync(path, { force: true });
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const distros = {};
|
|
126
|
+
for (const [distro, entry] of verdicts) {
|
|
127
|
+
const stored = { ...entry.view };
|
|
128
|
+
delete stored.cached;
|
|
129
|
+
distros[distro] = stored;
|
|
130
|
+
}
|
|
118
131
|
mkdirSync(dirname(path), { recursive: true });
|
|
119
132
|
const temporary = `${path}.tmp`;
|
|
120
133
|
writeFileSync(temporary, `${JSON.stringify({ version: STORE_VERSION, distros }, null, 2)}\n`, { mode: 0o600 });
|
|
@@ -171,7 +184,7 @@ function viewOf(digest, distro, now, repaired, source) {
|
|
|
171
184
|
const findings = digest.items.filter((item) => !item.id.startsWith("fix."));
|
|
172
185
|
// Which findings the plugin-owned repair can actually act on. A repair
|
|
173
186
|
// button that cannot apply is worse than no button: the user sees warnings,
|
|
174
|
-
// clicks "
|
|
187
|
+
// clicks "Repair", and nothing changes. The cache only explains a failed
|
|
175
188
|
// handshake when the cache is the finding — otherwise the handshake needs a
|
|
176
189
|
// reinstall or a resync, not a purge.
|
|
177
190
|
// A broken cache is `warn` under `agentBackend: auto` and `fail` under
|
|
@@ -335,23 +348,46 @@ export function createStatusHandler(options) {
|
|
|
335
348
|
writeStored(statePath, verdicts);
|
|
336
349
|
return present(view, false);
|
|
337
350
|
};
|
|
351
|
+
/**
|
|
352
|
+
* Drop stored verdicts and persist the change. Clearing is deliberately
|
|
353
|
+
* independent of `wsl.exe`: it is local housekeeping, and must still work
|
|
354
|
+
* when the distro list or the doctor is unavailable.
|
|
355
|
+
* @param distro - the distro to clear; `null` clears every stored verdict.
|
|
356
|
+
* @returns the count the route reports.
|
|
357
|
+
*/
|
|
358
|
+
const clear = (distro) => {
|
|
359
|
+
let cleared;
|
|
360
|
+
if (distro === null) {
|
|
361
|
+
cleared = verdicts.size;
|
|
362
|
+
verdicts.clear();
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
cleared = verdicts.delete(distro) ? 1 : 0;
|
|
366
|
+
}
|
|
367
|
+
writeStored(statePath, verdicts);
|
|
368
|
+
return distro === null ? { cleared } : { cleared, distro };
|
|
369
|
+
};
|
|
338
370
|
return async (request) => {
|
|
339
|
-
if (request.method !== "GET" && request.method !== "POST")
|
|
340
|
-
return json({ error: "
|
|
371
|
+
if (request.method !== "GET" && request.method !== "POST" && request.method !== "DELETE") {
|
|
372
|
+
return json({ error: t("statusMethodNotAllowed", {}) }, 405);
|
|
373
|
+
}
|
|
341
374
|
const url = new URL(request.url);
|
|
375
|
+
const requested = url.searchParams.get("distro");
|
|
376
|
+
if (request.method === "DELETE") {
|
|
377
|
+
return json(clear(requested === null || requested === "" ? null : requested));
|
|
378
|
+
}
|
|
342
379
|
const repair = request.method === "POST";
|
|
343
380
|
const refresh = url.searchParams.get("refresh") === "1";
|
|
344
|
-
const requested = url.searchParams.get("distro");
|
|
345
381
|
let names;
|
|
346
382
|
try {
|
|
347
383
|
names = await installed(repair || refresh);
|
|
348
384
|
}
|
|
349
385
|
catch (error) {
|
|
350
|
-
return json({ error:
|
|
386
|
+
return json({ error: t("statusDistroListFailed", { detail: error?.message ?? String(error) }) }, 502);
|
|
351
387
|
}
|
|
352
388
|
if (requested === null || requested === "") {
|
|
353
389
|
if (repair)
|
|
354
|
-
return json({ error: "
|
|
390
|
+
return json({ error: t("statusRepairNeedsDistro", {}) }, 400);
|
|
355
391
|
// The running list bounds the panel's background refresh: only a
|
|
356
392
|
// distro that is already up may be re-checked without the user asking,
|
|
357
393
|
// because a probe boots a stopped one. A failed read means no refresh.
|
|
@@ -372,7 +408,7 @@ export function createStatusHandler(options) {
|
|
|
372
408
|
return json(reply);
|
|
373
409
|
}
|
|
374
410
|
if (!names.includes(requested))
|
|
375
|
-
return json({ error:
|
|
411
|
+
return json({ error: t("statusUnknownDistro", { distro: requested }) }, 400);
|
|
376
412
|
const background = !repair && url.searchParams.get("background") === "1";
|
|
377
413
|
return json(await check(requested, refresh || repair, repair, background ? "background" : "user"));
|
|
378
414
|
};
|
|
@@ -413,6 +449,8 @@ function optionsFor(config, providers) {
|
|
|
413
449
|
export function apply(ctx, config = {}) {
|
|
414
450
|
if (typeof ctx.inject !== "function")
|
|
415
451
|
return;
|
|
452
|
+
// The test seam is structural; production hands the row a cordis Context.
|
|
453
|
+
installMessagesLocale(ctx);
|
|
416
454
|
ctx.inject(["connection"], (scope) => {
|
|
417
455
|
const connection = scope.connection ?? scope.get?.("connection");
|
|
418
456
|
if (connection === undefined)
|
|
@@ -420,7 +458,7 @@ export function apply(ctx, config = {}) {
|
|
|
420
458
|
const handler = createStatusHandler(optionsFor(config, () => takeoverSnapshot(ctx)));
|
|
421
459
|
const dispose = connection.fetch.register({
|
|
422
460
|
path: STATUS_PATH,
|
|
423
|
-
methods: ["GET", "POST"],
|
|
461
|
+
methods: ["GET", "POST", "DELETE"],
|
|
424
462
|
requestBody: "buffered",
|
|
425
463
|
fetch: handler,
|
|
426
464
|
});
|
package/lib/subprocess.d.ts
CHANGED
|
@@ -82,6 +82,7 @@
|
|
|
82
82
|
*
|
|
83
83
|
* @module dsh-plugin-wsl-env/subprocess
|
|
84
84
|
*/
|
|
85
|
+
import { PLUGIN_PROVIDER } from "./provider-marker.js";
|
|
85
86
|
import z from "@deepseek-ai/schemastery";
|
|
86
87
|
import { LocalSubprocessRuntime } from "@deepseek-ai/dsh-subprocess-local";
|
|
87
88
|
import type { Context } from "@deepseek-ai/cordis";
|
|
@@ -127,6 +128,8 @@ interface WslSubprocessConfig {
|
|
|
127
128
|
* literally the shipped implementation.
|
|
128
129
|
*/
|
|
129
130
|
export declare class WslSubprocessRuntime extends LocalSubprocessRuntime {
|
|
131
|
+
/** Brand for the in-app takeover report; see `provider-marker`. */
|
|
132
|
+
get [PLUGIN_PROVIDER](): "subprocess";
|
|
130
133
|
static Config: z<Schemastery.ObjectS<NoInfer<{
|
|
131
134
|
/**
|
|
132
135
|
* Distro mode: empty/`"auto"` follows the launch directory, `"default"`
|
package/lib/subprocess.js
CHANGED
|
@@ -83,6 +83,7 @@
|
|
|
83
83
|
* @module dsh-plugin-wsl-env/subprocess
|
|
84
84
|
*/
|
|
85
85
|
import { randomUUID } from "node:crypto";
|
|
86
|
+
import { PLUGIN_PROVIDER } from "./provider-marker.js";
|
|
86
87
|
import { Buffer } from "node:buffer";
|
|
87
88
|
import z from "@deepseek-ai/schemastery";
|
|
88
89
|
import { LocalSubprocessRuntime } from "@deepseek-ai/dsh-subprocess-local";
|
|
@@ -118,6 +119,10 @@ const WSL_PROGRAM = "wsl";
|
|
|
118
119
|
* literally the shipped implementation.
|
|
119
120
|
*/
|
|
120
121
|
export class WslSubprocessRuntime extends LocalSubprocessRuntime {
|
|
122
|
+
/** Brand for the in-app takeover report; see `provider-marker`. */
|
|
123
|
+
get [PLUGIN_PROVIDER]() {
|
|
124
|
+
return "subprocess";
|
|
125
|
+
}
|
|
121
126
|
static Config = z.object({
|
|
122
127
|
/**
|
|
123
128
|
* Distro mode: empty/`"auto"` follows the launch directory, `"default"`
|
package/lib/takeover-report.js
CHANGED
|
@@ -21,9 +21,7 @@
|
|
|
21
21
|
*
|
|
22
22
|
* @module dsh-plugin-wsl-env/takeover-report
|
|
23
23
|
*/
|
|
24
|
-
import {
|
|
25
|
-
import { WslDirectoryPicker } from "./picker.js";
|
|
26
|
-
import { WslSubprocessRuntime } from "./subprocess.js";
|
|
24
|
+
import { PLUGIN_PROVIDER } from "./provider-marker.js";
|
|
27
25
|
/** The service names this plugin replaces with its own providers. */
|
|
28
26
|
export const TAKEOVER_SERVICES = ["subprocess", "fs", "directoryPicker"];
|
|
29
27
|
/**
|
|
@@ -34,14 +32,9 @@ export const TAKEOVER_SERVICES = ["subprocess", "fs", "directoryPicker"];
|
|
|
34
32
|
* @returns true for this plugin's class of that service.
|
|
35
33
|
*/
|
|
36
34
|
function isPluginProvider(service, value) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
case "fs":
|
|
41
|
-
return value instanceof WslRoutingFileSystem;
|
|
42
|
-
case "directoryPicker":
|
|
43
|
-
return value instanceof WslDirectoryPicker;
|
|
44
|
-
}
|
|
35
|
+
if (typeof value !== "object" || value === null)
|
|
36
|
+
return false;
|
|
37
|
+
return value[PLUGIN_PROVIDER] === service;
|
|
45
38
|
}
|
|
46
39
|
/**
|
|
47
40
|
* Read which provider serves each takeover name in this context.
|