dsh-plugin-wsl-env 0.26.4 → 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 +61 -0
- package/CONTRIBUTING.md +7 -4
- package/CONTRIBUTING.zh.md +3 -2
- package/README.md +1 -1
- package/SECURITY.md +21 -7
- package/SECURITY.zh.md +18 -5
- package/client.js +351 -48
- package/cordis.patch.yml +26 -10
- package/docs/API.md +2 -1
- package/docs/API.zh.md +2 -1
- package/docs/ARCHITECTURE.md +22 -4
- package/docs/ARCHITECTURE.zh.md +18 -4
- package/docs/CONFIGURATION.md +96 -12
- package/docs/CONFIGURATION.zh.md +80 -8
- 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/QUICKSTART.md +31 -20
- package/docs/QUICKSTART.zh.md +16 -9
- package/docs/README.zh.md +1 -1
- package/docs/REQUIREMENTS.zh.md +3 -2
- package/lib/agent-confined.d.ts +9 -1
- package/lib/agent-confined.js +3 -3
- package/lib/bwrap.d.ts +16 -0
- package/lib/bwrap.js +9 -0
- package/lib/fs-routing.d.ts +3 -0
- package/lib/fs-routing.js +2 -0
- package/lib/messages.js +2 -2
- package/lib/plugin-update.d.ts +212 -0
- package/lib/plugin-update.js +283 -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 +53 -18
- package/lib/update-check.d.ts +49 -9
- package/lib/update-check.js +81 -28
- package/lib/wsl-doctor-tool.js +2 -0
- package/lib/wsl-filesystem.d.ts +39 -1
- package/lib/wsl-filesystem.js +51 -4
- package/lib/wsl-shell.d.ts +67 -3
- package/lib/wsl-shell.js +75 -12
- package/package.json +8 -3
- package/scripts/doctor.mjs +199 -3
- package/scripts/profile-preset.mjs +10 -2
|
@@ -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,7 +51,7 @@
|
|
|
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";
|
|
@@ -102,20 +108,26 @@ function readStored(path) {
|
|
|
102
108
|
/**
|
|
103
109
|
* Write the last successful verdicts atomically. A read-only or missing home
|
|
104
110
|
* must not fail the diagnosis that produced them, so a write error is
|
|
105
|
-
* 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.
|
|
106
114
|
* @param path - the store path; empty disables persistence.
|
|
107
115
|
* @param verdicts - the verdicts to persist, keyed by distro.
|
|
108
116
|
*/
|
|
109
117
|
function writeStored(path, verdicts) {
|
|
110
118
|
if (path.length === 0)
|
|
111
119
|
return;
|
|
112
|
-
const distros = {};
|
|
113
|
-
for (const [distro, entry] of verdicts) {
|
|
114
|
-
const stored = { ...entry.view };
|
|
115
|
-
delete stored.cached;
|
|
116
|
-
distros[distro] = stored;
|
|
117
|
-
}
|
|
118
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
|
+
}
|
|
119
131
|
mkdirSync(dirname(path), { recursive: true });
|
|
120
132
|
const temporary = `${path}.tmp`;
|
|
121
133
|
writeFileSync(temporary, `${JSON.stringify({ version: STORE_VERSION, distros }, null, 2)}\n`, { mode: 0o600 });
|
|
@@ -336,13 +348,36 @@ export function createStatusHandler(options) {
|
|
|
336
348
|
writeStored(statePath, verdicts);
|
|
337
349
|
return present(view, false);
|
|
338
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
|
+
};
|
|
339
370
|
return async (request) => {
|
|
340
|
-
if (request.method !== "GET" && request.method !== "POST")
|
|
371
|
+
if (request.method !== "GET" && request.method !== "POST" && request.method !== "DELETE") {
|
|
341
372
|
return json({ error: t("statusMethodNotAllowed", {}) }, 405);
|
|
373
|
+
}
|
|
342
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
|
+
}
|
|
343
379
|
const repair = request.method === "POST";
|
|
344
380
|
const refresh = url.searchParams.get("refresh") === "1";
|
|
345
|
-
const requested = url.searchParams.get("distro");
|
|
346
381
|
let names;
|
|
347
382
|
try {
|
|
348
383
|
names = await installed(repair || refresh);
|
|
@@ -423,7 +458,7 @@ export function apply(ctx, config = {}) {
|
|
|
423
458
|
const handler = createStatusHandler(optionsFor(config, () => takeoverSnapshot(ctx)));
|
|
424
459
|
const dispose = connection.fetch.register({
|
|
425
460
|
path: STATUS_PATH,
|
|
426
|
-
methods: ["GET", "POST"],
|
|
461
|
+
methods: ["GET", "POST", "DELETE"],
|
|
427
462
|
requestBody: "buffered",
|
|
428
463
|
fetch: handler,
|
|
429
464
|
});
|
package/lib/update-check.d.ts
CHANGED
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
* the host's `pluginManager` for this package's version list and, when the
|
|
11
11
|
* stable channel has moved, publishes one fact. Applying the update stays a
|
|
12
12
|
* user action — a plugin that silently replaces its own code under a running
|
|
13
|
-
* harness is a posture this plugin rejects
|
|
14
|
-
*
|
|
13
|
+
* harness is a posture this plugin rejects. The sidebar's plugin-update row
|
|
14
|
+
* exposes the same answer and a confirmed one-click upgrade; this module owns
|
|
15
|
+
* the check itself and the fact the shell-env row serves.
|
|
15
16
|
*
|
|
16
17
|
* Delegation is the whole network story: the check spawns nothing and fetches
|
|
17
18
|
* nothing itself. `pluginManager` is read with `ctx.get`, the sanctioned read
|
|
@@ -29,6 +30,8 @@
|
|
|
29
30
|
import z from "@deepseek-ai/schemastery";
|
|
30
31
|
import type { Context } from "@deepseek-ai/cordis";
|
|
31
32
|
export declare const name = "wsl-update-check";
|
|
33
|
+
/** The checked package: this plugin, by its npm name. */
|
|
34
|
+
export declare const PACKAGE = "dsh-plugin-wsl-env";
|
|
32
35
|
/** The interval the row ships with. */
|
|
33
36
|
export declare const DEFAULT_INTERVAL_MS: number;
|
|
34
37
|
/** The smallest interval a config may ask for; one check spawns `pnpm view` in the profile. */
|
|
@@ -52,7 +55,7 @@ interface UpdateCheckConfig {
|
|
|
52
55
|
intervalMs?: number;
|
|
53
56
|
}
|
|
54
57
|
/** One published version, reduced to what the fact reads (host plugin-manager types). */
|
|
55
|
-
interface ListedVersion {
|
|
58
|
+
export interface ListedVersion {
|
|
56
59
|
readonly version: string;
|
|
57
60
|
readonly publishedAt?: string;
|
|
58
61
|
readonly tags: readonly string[];
|
|
@@ -71,7 +74,7 @@ interface ListedVersion {
|
|
|
71
74
|
export type VersionList = {
|
|
72
75
|
readonly status: "listed";
|
|
73
76
|
readonly installed: string;
|
|
74
|
-
readonly registry: string;
|
|
77
|
+
readonly registry: string | null;
|
|
75
78
|
readonly attempts: readonly unknown[];
|
|
76
79
|
/** Published versions newer than `installed`, newest first. */
|
|
77
80
|
readonly versions: readonly ListedVersion[];
|
|
@@ -82,6 +85,33 @@ export type VersionList = {
|
|
|
82
85
|
readonly reason: string;
|
|
83
86
|
readonly attempts: readonly unknown[];
|
|
84
87
|
};
|
|
88
|
+
/** Why a check could not produce a version list. */
|
|
89
|
+
export type VersionProblem = "no-manager" | Extract<VersionList, {
|
|
90
|
+
status: "refused";
|
|
91
|
+
}>["problem"];
|
|
92
|
+
/**
|
|
93
|
+
* What one version check learned, for the panel's version card. Unlike
|
|
94
|
+
* {@link UpdateFact}, this keeps the "up to date" answer and the reasons a
|
|
95
|
+
* check learned nothing, so the panel can say which of the three happened.
|
|
96
|
+
*/
|
|
97
|
+
export type VersionCheck = {
|
|
98
|
+
readonly status: "available";
|
|
99
|
+
readonly installed: string;
|
|
100
|
+
readonly checkedAt: number;
|
|
101
|
+
readonly registry: string | null;
|
|
102
|
+
readonly latest: ListedVersion;
|
|
103
|
+
} | {
|
|
104
|
+
readonly status: "current";
|
|
105
|
+
readonly installed: string;
|
|
106
|
+
readonly checkedAt: number;
|
|
107
|
+
readonly registry: string | null;
|
|
108
|
+
} | {
|
|
109
|
+
readonly status: "unavailable";
|
|
110
|
+
readonly installed: string;
|
|
111
|
+
readonly checkedAt: number;
|
|
112
|
+
readonly problem: VersionProblem;
|
|
113
|
+
readonly reason: string;
|
|
114
|
+
};
|
|
85
115
|
/**
|
|
86
116
|
* The slice of the host's plugin-manager this row calls. The service belongs
|
|
87
117
|
* to the harness and its declaration is not visible to this plugin, so it is
|
|
@@ -155,12 +185,22 @@ export declare function updateTarget(list: Extract<VersionList, {
|
|
|
155
185
|
status: "listed";
|
|
156
186
|
}>): ListedVersion | undefined;
|
|
157
187
|
/**
|
|
158
|
-
* Run one check
|
|
188
|
+
* Run one version check and publish (or clear) the shell-environment fact.
|
|
159
189
|
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
190
|
+
* The fact is the only observable for the periodic check, so the three
|
|
191
|
+
* outcomes are handled together: an available target publishes it, an
|
|
192
|
+
* up-to-date list clears a stale one, and a non-answer (no manager, a refused
|
|
193
|
+
* list, a throwing service) leaves the previous fact standing. A check must
|
|
194
|
+
* never become the noisiest thing in the app, so none of these throws.
|
|
195
|
+
*
|
|
196
|
+
* @param manager - the host plugin-manager, or undefined when the host has none.
|
|
197
|
+
* @param installed - the installed version to name when the host has no manager.
|
|
198
|
+
* @param now - the check's timestamp, injectable for tests.
|
|
199
|
+
* @returns what the check learned.
|
|
200
|
+
*/
|
|
201
|
+
export declare function inspectVersions(manager: PluginManagerSlice | undefined, installed: string, now?: number): Promise<VersionCheck>;
|
|
202
|
+
/**
|
|
203
|
+
* Run one check against the host's plugin-manager and publish the fact.
|
|
164
204
|
*
|
|
165
205
|
* @param manager - the host plugin-manager, or undefined when the host has none.
|
|
166
206
|
* @returns the published fact, or undefined when the check learned nothing.
|