dsh-plugin-wsl-env 0.26.3 → 0.26.4
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 +81 -0
- package/CONTRIBUTING.md +25 -21
- package/SUPPORT.md +2 -2
- package/SUPPORT.zh.md +2 -2
- package/docs/AGENT-PROTOCOL-V7.md +4 -2
- package/docs/API.md +1 -0
- package/docs/API.zh.md +1 -0
- package/docs/CONFIGURATION.md +21 -5
- package/docs/CONFIGURATION.zh.md +17 -3
- package/docs/PARITY.md +3 -1
- package/docs/RELEASING.md +25 -3
- package/docs/REQUIREMENTS.zh.md +4 -4
- package/docs/ROADMAP-1.0.md +11 -7
- package/lib/agent.d.ts +54 -18
- package/lib/agent.js +86 -19
- package/lib/fs-routing.d.ts +3 -0
- package/lib/fs-routing.js +5 -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/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/status.js +8 -5
- package/lib/subprocess.d.ts +3 -0
- package/lib/subprocess.js +5 -0
- package/lib/takeover-report.js +4 -11
- 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-filesystem.d.ts +14 -11
- package/lib/wsl-filesystem.js +39 -27
- package/lib/wsl-shell.d.ts +42 -37
- package/lib/wsl-shell.js +53 -42
- package/package.json +1 -1
package/lib/open-in-app.js
CHANGED
|
@@ -38,6 +38,7 @@ import { spawn } from "node:child_process";
|
|
|
38
38
|
import { existsSync } from "node:fs";
|
|
39
39
|
import { join } from "node:path";
|
|
40
40
|
import z from "@deepseek-ai/schemastery";
|
|
41
|
+
import { installMessagesLocale, t } from "./messages.js";
|
|
41
42
|
import { uncToPosix } from "./paths.js";
|
|
42
43
|
/** The composition row's plugin name. */
|
|
43
44
|
export const name = "wsl-open-in-app";
|
|
@@ -218,25 +219,25 @@ function json(payload, status = 200) {
|
|
|
218
219
|
export function createOpenInAppHandler(deps) {
|
|
219
220
|
return async (request) => {
|
|
220
221
|
if (request.method !== "POST")
|
|
221
|
-
return json({ error: "
|
|
222
|
+
return json({ error: t("openInAppPostOnly", {}) }, 405);
|
|
222
223
|
const essence = request.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase();
|
|
223
224
|
if (essence !== "application/json")
|
|
224
|
-
return json({ error: "
|
|
225
|
+
return json({ error: t("openInAppJsonContentType", {}) }, 415);
|
|
225
226
|
let body;
|
|
226
227
|
try {
|
|
227
228
|
body = await request.json();
|
|
228
229
|
}
|
|
229
230
|
catch {
|
|
230
|
-
return json({ error: "
|
|
231
|
+
return json({ error: t("openInAppInvalidJson", {}) }, 400);
|
|
231
232
|
}
|
|
232
233
|
if (typeof body !== "object" || body === null)
|
|
233
|
-
return json({ error: "
|
|
234
|
+
return json({ error: t("openInAppBodyNotObject", {}) }, 400);
|
|
234
235
|
const path = body.path;
|
|
235
236
|
if (typeof path !== "string")
|
|
236
|
-
return json({ error: "
|
|
237
|
+
return json({ error: t("openInAppPathMustBeString", {}) }, 400);
|
|
237
238
|
const uri = editorUri(path);
|
|
238
239
|
if (uri === undefined)
|
|
239
|
-
return json({ error: "
|
|
240
|
+
return json({ error: t("openInAppNotWslWorkspacePath", {}) }, 400);
|
|
240
241
|
let outcome;
|
|
241
242
|
try {
|
|
242
243
|
outcome = await deps.launch(uri);
|
|
@@ -244,14 +245,14 @@ export function createOpenInAppHandler(deps) {
|
|
|
244
245
|
catch {
|
|
245
246
|
// The launcher is a seam: a rejected promise must become a classified
|
|
246
247
|
// failure, not an unhandled rejection inside the route.
|
|
247
|
-
return json({ error: "
|
|
248
|
+
return json({ error: t("openInAppLaunchFailed", {}) }, 502);
|
|
248
249
|
}
|
|
249
250
|
if (outcome === "launched")
|
|
250
251
|
return json({ ok: true, uri });
|
|
251
252
|
return json({
|
|
252
253
|
error: outcome === "missing"
|
|
253
|
-
? "
|
|
254
|
-
: "
|
|
254
|
+
? t("openInAppExecutableMissing", {})
|
|
255
|
+
: t("openInAppLaunchFailed", {}),
|
|
255
256
|
}, 502);
|
|
256
257
|
};
|
|
257
258
|
}
|
|
@@ -284,6 +285,8 @@ export function createLauncher(config, env = process.env, spawnChild = spawn) {
|
|
|
284
285
|
export function apply(ctx, config = {}) {
|
|
285
286
|
if (typeof ctx.inject !== "function")
|
|
286
287
|
return;
|
|
288
|
+
// The test seam is structural; production hands the row a cordis Context.
|
|
289
|
+
installMessagesLocale(ctx);
|
|
287
290
|
ctx.inject(["connection"], (scope) => {
|
|
288
291
|
const connection = scope.connection ?? scope.get?.("connection");
|
|
289
292
|
if (connection === undefined)
|
package/lib/picker.d.ts
CHANGED
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
*
|
|
48
48
|
* @module dsh-plugin-wsl-env/picker
|
|
49
49
|
*/
|
|
50
|
+
import { PLUGIN_PROVIDER } from "./provider-marker.js";
|
|
50
51
|
import z from "@deepseek-ai/schemastery";
|
|
51
52
|
import { DirectoryPicker } from "@deepseek-ai/dsh-host-directory-picker";
|
|
52
53
|
import type { Context } from "@deepseek-ai/cordis";
|
|
@@ -95,6 +96,8 @@ interface PickerConfig {
|
|
|
95
96
|
* capture it across calls.
|
|
96
97
|
*/
|
|
97
98
|
export declare class WslDirectoryPicker extends DirectoryPicker {
|
|
99
|
+
/** Brand for the in-app takeover report; see `provider-marker`. */
|
|
100
|
+
get [PLUGIN_PROVIDER](): "directoryPicker";
|
|
98
101
|
static Config: z<Schemastery.ObjectS<NoInfer<{
|
|
99
102
|
/** Path to `wsl.exe`; overridable for a non-standard install. */
|
|
100
103
|
wslPath: z<string, string, "defined">;
|
|
@@ -191,7 +194,7 @@ export declare class WslDirectoryPicker extends DirectoryPicker {
|
|
|
191
194
|
*
|
|
192
195
|
* `path` is the Windows home — a real directory — so adopting the level with
|
|
193
196
|
* nothing selected still yields something adoptable; the entries are the two
|
|
194
|
-
* branches, and the
|
|
197
|
+
* branches, and the workspace crumb returns here from either one.
|
|
195
198
|
*
|
|
196
199
|
* @param signal - optional cancellation.
|
|
197
200
|
* @returns the category listing.
|
package/lib/picker.js
CHANGED
|
@@ -48,18 +48,28 @@
|
|
|
48
48
|
* @module dsh-plugin-wsl-env/picker
|
|
49
49
|
*/
|
|
50
50
|
import { mkdir, opendir, stat } from "node:fs/promises";
|
|
51
|
+
import { PLUGIN_PROVIDER } from "./provider-marker.js";
|
|
51
52
|
import { homedir } from "node:os";
|
|
52
53
|
import { join, resolve } from "node:path";
|
|
53
54
|
import z from "@deepseek-ai/schemastery";
|
|
54
55
|
import { DirectoryPicker, DirectoryPickerError } from "@deepseek-ai/dsh-host-directory-picker";
|
|
55
56
|
import { UNC_PROVIDER_ROOT, distroRoot, isProviderRoot, isWslUnc, uncToPosix } from "./paths.js";
|
|
56
57
|
import { breadcrumbs, boundedInsert, dirListingArgv, distroMkdirArgv, fullyQualified, parseDirListing } from "./listing.js";
|
|
58
|
+
import { installMessagesLocale, t } from "./messages.js";
|
|
57
59
|
import { listDistros, linuxHome, runCapture, runCaptureRaw } from "./wsl.js";
|
|
58
60
|
import { sharedAgent } from "./agent-shared.js";
|
|
59
61
|
import { mountTakeover } from "./service-takeover.js";
|
|
60
62
|
import { AgentUnavailableError, CwdError, SpawnError } from "./agent-errors.js";
|
|
61
63
|
/** How long a resolved distro list stays fresh before it is queried again. */
|
|
62
64
|
const DEFAULT_DISTRO_CACHE_MS = 5_000;
|
|
65
|
+
/**
|
|
66
|
+
* Capture ceiling for one distro level's `find` output. A bounded listing is
|
|
67
|
+
* far below this; the cap only keeps a hostile or broken walk from buffering
|
|
68
|
+
* a protocol-sized line in the Host.
|
|
69
|
+
*/
|
|
70
|
+
const LIST_OUTPUT_CAP_BYTES = 4_000_000;
|
|
71
|
+
/** Capture ceiling for `mkdir`'s diagnostics. */
|
|
72
|
+
const MKDIR_OUTPUT_CAP_BYTES = 64_000;
|
|
63
73
|
/**
|
|
64
74
|
* Virtual root of the picker's category level: the Windows world and the WSL
|
|
65
75
|
* world. It is a sentinel, never a filesystem path; `list` recognises it and
|
|
@@ -151,6 +161,10 @@ async function directoryRow(parent, name, isDirectory, isSymbolicLink, signal) {
|
|
|
151
161
|
* capture it across calls.
|
|
152
162
|
*/
|
|
153
163
|
export class WslDirectoryPicker extends DirectoryPicker {
|
|
164
|
+
/** Brand for the in-app takeover report; see `provider-marker`. */
|
|
165
|
+
get [PLUGIN_PROVIDER]() {
|
|
166
|
+
return "directoryPicker";
|
|
167
|
+
}
|
|
154
168
|
static Config = z.object({
|
|
155
169
|
/** Path to `wsl.exe`; overridable for a non-standard install. */
|
|
156
170
|
wslPath: z.string().default("wsl.exe"),
|
|
@@ -177,6 +191,7 @@ export class WslDirectoryPicker extends DirectoryPicker {
|
|
|
177
191
|
*/
|
|
178
192
|
constructor(ctx, config) {
|
|
179
193
|
super(ctx);
|
|
194
|
+
installMessagesLocale(ctx);
|
|
180
195
|
this.config = config;
|
|
181
196
|
this.distroCache = undefined;
|
|
182
197
|
this.homeCache = new Map();
|
|
@@ -257,24 +272,27 @@ export class WslDirectoryPicker extends DirectoryPicker {
|
|
|
257
272
|
*
|
|
258
273
|
* `path` is the Windows home — a real directory — so adopting the level with
|
|
259
274
|
* nothing selected still yields something adoptable; the entries are the two
|
|
260
|
-
* branches, and the
|
|
275
|
+
* branches, and the workspace crumb returns here from either one.
|
|
261
276
|
*
|
|
262
277
|
* @param signal - optional cancellation.
|
|
263
278
|
* @returns the category listing.
|
|
264
279
|
*/
|
|
265
280
|
async categoryLevel(signal) {
|
|
281
|
+
const preferred = await this.preferredDistro(signal);
|
|
282
|
+
const home = preferred.length > 0 ? await this.homeOf(preferred, signal) : homedir();
|
|
283
|
+
// Build every label after the awaits: installMessagesLocale can learn the
|
|
284
|
+
// app's stored preference while this call waits, and labels captured on
|
|
285
|
+
// either side of that switch used to render one level in two languages.
|
|
266
286
|
const entries = [];
|
|
267
287
|
// The key historically meant "also offer Windows paths"; it now gates the
|
|
268
288
|
// whole Windows branch, whose walk starts at the drives.
|
|
269
289
|
if (this.config.includeHostHome)
|
|
270
|
-
entries.push({ name: "
|
|
271
|
-
entries.push({ name: "
|
|
272
|
-
const preferred = await this.preferredDistro(signal);
|
|
273
|
-
const home = preferred.length > 0 ? await this.homeOf(preferred, signal) : homedir();
|
|
290
|
+
entries.push({ name: t("pickerWindowsPaths", {}), path: HOST_ROOT, hidden: false });
|
|
291
|
+
entries.push({ name: t("pickerWslDistros", {}), path: UNC_PROVIDER_ROOT, hidden: false });
|
|
274
292
|
return {
|
|
275
293
|
path: homedir(),
|
|
276
294
|
home,
|
|
277
|
-
crumbs: [{ name: "
|
|
295
|
+
crumbs: [{ name: t("pickerWorkspace", {}), path: PICKER_ROOT, hidden: false }],
|
|
278
296
|
entries,
|
|
279
297
|
truncated: false,
|
|
280
298
|
};
|
|
@@ -300,8 +318,8 @@ export class WslDirectoryPicker extends DirectoryPicker {
|
|
|
300
318
|
path: preferred.length > 0 ? distroRoot(preferred) : homedir(),
|
|
301
319
|
home,
|
|
302
320
|
crumbs: [
|
|
303
|
-
{ name: "
|
|
304
|
-
{ name: "
|
|
321
|
+
{ name: t("pickerWorkspace", {}), path: PICKER_ROOT, hidden: false },
|
|
322
|
+
{ name: t("pickerWslDistros", {}), path: UNC_PROVIDER_ROOT, hidden: false },
|
|
305
323
|
],
|
|
306
324
|
entries,
|
|
307
325
|
truncated: false,
|
|
@@ -330,8 +348,8 @@ export class WslDirectoryPicker extends DirectoryPicker {
|
|
|
330
348
|
path: home,
|
|
331
349
|
home,
|
|
332
350
|
crumbs: [
|
|
333
|
-
{ name: "
|
|
334
|
-
{ name: "
|
|
351
|
+
{ name: t("pickerWorkspace", {}), path: PICKER_ROOT, hidden: false },
|
|
352
|
+
{ name: t("pickerWindowsPaths", {}), path: HOST_ROOT, hidden: false },
|
|
335
353
|
],
|
|
336
354
|
entries,
|
|
337
355
|
truncated: false,
|
|
@@ -414,6 +432,7 @@ export class WslDirectoryPicker extends DirectoryPicker {
|
|
|
414
432
|
cwd: linuxDir,
|
|
415
433
|
argv: dirListingArgv(linuxDir),
|
|
416
434
|
timeoutMs: 15_000,
|
|
435
|
+
maxOutputBytes: LIST_OUTPUT_CAP_BYTES,
|
|
417
436
|
signal,
|
|
418
437
|
});
|
|
419
438
|
if (result.exitCode !== 0) {
|
|
@@ -545,7 +564,12 @@ export class WslDirectoryPicker extends DirectoryPicker {
|
|
|
545
564
|
const parsed = uncToPosix(parent);
|
|
546
565
|
const linuxParent = parsed.linuxPath.length > 0 ? parsed.linuxPath : "/";
|
|
547
566
|
try {
|
|
548
|
-
const result = await sharedAgent(parsed.distro).exec({
|
|
567
|
+
const result = await sharedAgent(parsed.distro).exec({
|
|
568
|
+
cwd: linuxParent,
|
|
569
|
+
argv: distroMkdirArgv(linuxParent, name),
|
|
570
|
+
timeoutMs: 10_000,
|
|
571
|
+
maxOutputBytes: MKDIR_OUTPUT_CAP_BYTES,
|
|
572
|
+
});
|
|
549
573
|
if (result.exitCode === 0)
|
|
550
574
|
return target;
|
|
551
575
|
const detail = result.stderr.toString("utf8");
|
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/status.js
CHANGED
|
@@ -52,6 +52,7 @@ import { listDistros, listRunningDistros } from "./wsl.js";
|
|
|
52
52
|
import { digestReport, sectionOf } from "./wsl-doctor-tool.js";
|
|
53
53
|
import { runDoctorCli } from "./wsl-doctor-command.js";
|
|
54
54
|
import { mergeAutoPresetSeam } from "./doctor-live.js";
|
|
55
|
+
import { installMessagesLocale, t } from "./messages.js";
|
|
55
56
|
import { mergeTakeoverReport, takeoverSnapshot } from "./takeover-report.js";
|
|
56
57
|
export const name = "wsl-status";
|
|
57
58
|
/** The one route the panel fetches; it must live under the `/api` channel. */
|
|
@@ -171,7 +172,7 @@ function viewOf(digest, distro, now, repaired, source) {
|
|
|
171
172
|
const findings = digest.items.filter((item) => !item.id.startsWith("fix."));
|
|
172
173
|
// Which findings the plugin-owned repair can actually act on. A repair
|
|
173
174
|
// button that cannot apply is worse than no button: the user sees warnings,
|
|
174
|
-
// clicks "
|
|
175
|
+
// clicks "Repair", and nothing changes. The cache only explains a failed
|
|
175
176
|
// handshake when the cache is the finding — otherwise the handshake needs a
|
|
176
177
|
// reinstall or a resync, not a purge.
|
|
177
178
|
// A broken cache is `warn` under `agentBackend: auto` and `fail` under
|
|
@@ -337,7 +338,7 @@ export function createStatusHandler(options) {
|
|
|
337
338
|
};
|
|
338
339
|
return async (request) => {
|
|
339
340
|
if (request.method !== "GET" && request.method !== "POST")
|
|
340
|
-
return json({ error: "
|
|
341
|
+
return json({ error: t("statusMethodNotAllowed", {}) }, 405);
|
|
341
342
|
const url = new URL(request.url);
|
|
342
343
|
const repair = request.method === "POST";
|
|
343
344
|
const refresh = url.searchParams.get("refresh") === "1";
|
|
@@ -347,11 +348,11 @@ export function createStatusHandler(options) {
|
|
|
347
348
|
names = await installed(repair || refresh);
|
|
348
349
|
}
|
|
349
350
|
catch (error) {
|
|
350
|
-
return json({ error:
|
|
351
|
+
return json({ error: t("statusDistroListFailed", { detail: error?.message ?? String(error) }) }, 502);
|
|
351
352
|
}
|
|
352
353
|
if (requested === null || requested === "") {
|
|
353
354
|
if (repair)
|
|
354
|
-
return json({ error: "
|
|
355
|
+
return json({ error: t("statusRepairNeedsDistro", {}) }, 400);
|
|
355
356
|
// The running list bounds the panel's background refresh: only a
|
|
356
357
|
// distro that is already up may be re-checked without the user asking,
|
|
357
358
|
// because a probe boots a stopped one. A failed read means no refresh.
|
|
@@ -372,7 +373,7 @@ export function createStatusHandler(options) {
|
|
|
372
373
|
return json(reply);
|
|
373
374
|
}
|
|
374
375
|
if (!names.includes(requested))
|
|
375
|
-
return json({ error:
|
|
376
|
+
return json({ error: t("statusUnknownDistro", { distro: requested }) }, 400);
|
|
376
377
|
const background = !repair && url.searchParams.get("background") === "1";
|
|
377
378
|
return json(await check(requested, refresh || repair, repair, background ? "background" : "user"));
|
|
378
379
|
};
|
|
@@ -413,6 +414,8 @@ function optionsFor(config, providers) {
|
|
|
413
414
|
export function apply(ctx, config = {}) {
|
|
414
415
|
if (typeof ctx.inject !== "function")
|
|
415
416
|
return;
|
|
417
|
+
// The test seam is structural; production hands the row a cordis Context.
|
|
418
|
+
installMessagesLocale(ctx);
|
|
416
419
|
ctx.inject(["connection"], (scope) => {
|
|
417
420
|
const connection = scope.connection ?? scope.get?.("connection");
|
|
418
421
|
if (connection === undefined)
|
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.
|
package/lib/watcher.d.ts
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* rename-over or an in-place write is seen), and a positive `maxDepth` keeps
|
|
19
19
|
* the polling scan because inotify cannot bound its own walk.
|
|
20
20
|
*
|
|
21
|
-
* The loop speaks
|
|
21
|
+
* The loop speaks five one-letter lines, the watcher protocol:
|
|
22
22
|
*
|
|
23
23
|
* - `R` — READY: the activation barrier; the host resolves the watch promise
|
|
24
24
|
* on it, never before.
|
package/lib/watcher.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* rename-over or an in-place write is seen), and a positive `maxDepth` keeps
|
|
19
19
|
* the polling scan because inotify cannot bound its own walk.
|
|
20
20
|
*
|
|
21
|
-
* The loop speaks
|
|
21
|
+
* The loop speaks five one-letter lines, the watcher protocol:
|
|
22
22
|
*
|
|
23
23
|
* - `R` — READY: the activation barrier; the host resolves the watch promise
|
|
24
24
|
* on it, never before.
|
|
@@ -83,8 +83,12 @@ interface ParsedDoctorInput {
|
|
|
83
83
|
}
|
|
84
84
|
/** The doctor CLI this row spawns, resolved from the built module's package root. */
|
|
85
85
|
export declare const DOCTOR_SCRIPT: string;
|
|
86
|
-
/**
|
|
87
|
-
|
|
86
|
+
/**
|
|
87
|
+
* The usage text a grammar violation settles with.
|
|
88
|
+
*
|
|
89
|
+
* @returns the usage block in the active catalog language.
|
|
90
|
+
*/
|
|
91
|
+
export declare function doctorUsage(): string;
|
|
88
92
|
/**
|
|
89
93
|
* Parse the raw input after the command name. Tokens: one mode word or
|
|
90
94
|
* section name, plus an optional `--distro <name>` / `--distro=<name>`; a
|
|
@@ -34,6 +34,7 @@ import { distroOfUnc } from "./distro-route.js";
|
|
|
34
34
|
import { withHostPeerVersions } from "./peer-versions.js";
|
|
35
35
|
import { digestReport, renderDigest, SECTIONS } from "./wsl-doctor-tool.js";
|
|
36
36
|
import { mergeAutoPresetSeam } from "./doctor-live.js";
|
|
37
|
+
import { installMessagesLocale, t } from "./messages.js";
|
|
37
38
|
import { mergeTakeoverReport, takeoverSnapshot } from "./takeover-report.js";
|
|
38
39
|
export const name = "wsl-doctor-command";
|
|
39
40
|
/**
|
|
@@ -65,9 +66,14 @@ export const DOCTOR_CLI_TIMEOUT_MS = 120_000;
|
|
|
65
66
|
export const DOCTOR_CLI_SWEEP_TIMEOUT_MS = 60_000;
|
|
66
67
|
/** The doctor CLI this row spawns, resolved from the built module's package root. */
|
|
67
68
|
export const DOCTOR_SCRIPT = resolve(dirname(fileURLToPath(import.meta.url)), "..", "scripts", "doctor.mjs");
|
|
68
|
-
/**
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
/**
|
|
70
|
+
* The usage text a grammar violation settles with.
|
|
71
|
+
*
|
|
72
|
+
* @returns the usage block in the active catalog language.
|
|
73
|
+
*/
|
|
74
|
+
export function doctorUsage() {
|
|
75
|
+
return t("doctorUsage", { sections: SECTIONS.join(" | ") });
|
|
76
|
+
}
|
|
71
77
|
/**
|
|
72
78
|
* Parse the raw input after the command name. Tokens: one mode word or
|
|
73
79
|
* section name, plus an optional `--distro <name>` / `--distro=<name>`; a
|
|
@@ -108,10 +114,10 @@ export function parseDoctorInput(rawInput) {
|
|
|
108
114
|
parsed.distro = token;
|
|
109
115
|
continue;
|
|
110
116
|
}
|
|
111
|
-
throw new Error(
|
|
117
|
+
throw new Error(t("doctorUnknownToken", { token }));
|
|
112
118
|
}
|
|
113
119
|
if (expectingDistro)
|
|
114
|
-
throw new Error("
|
|
120
|
+
throw new Error(t("doctorDistroNeedsName", {}));
|
|
115
121
|
return parsed;
|
|
116
122
|
}
|
|
117
123
|
/**
|
|
@@ -165,7 +171,7 @@ export function runDoctorCli(argv, signal, timeoutMs = DOCTOR_CLI_TIMEOUT_MS) {
|
|
|
165
171
|
child.on("error", (error) => {
|
|
166
172
|
// An abort arrives here as an AbortError; normalize it so the settled
|
|
167
173
|
// message names the run rather than the DOMException.
|
|
168
|
-
settle(() => rejectPromise(error.name === "AbortError" ? new Error("
|
|
174
|
+
settle(() => rejectPromise(error.name === "AbortError" ? new Error(t("doctorCliCancelled", {})) : error));
|
|
169
175
|
});
|
|
170
176
|
child.on("close", (code, signalName) => {
|
|
171
177
|
const text = stdout.trim();
|
|
@@ -174,10 +180,13 @@ export function runDoctorCli(argv, signal, timeoutMs = DOCTOR_CLI_TIMEOUT_MS) {
|
|
|
174
180
|
return;
|
|
175
181
|
}
|
|
176
182
|
if (timedOut) {
|
|
177
|
-
settle(() => rejectPromise(new Error(
|
|
183
|
+
settle(() => rejectPromise(new Error(t("doctorCliTimeout", { seconds: timeoutMs / 1000 }))));
|
|
178
184
|
return;
|
|
179
185
|
}
|
|
180
|
-
settle(() => rejectPromise(new Error(
|
|
186
|
+
settle(() => rejectPromise(new Error(t("doctorCliNoReport", {
|
|
187
|
+
status: String(code ?? signalName ?? "signal"),
|
|
188
|
+
detail: stderr.trim().length > 0 ? `: ${stderr.trim().slice(0, 400)}` : "",
|
|
189
|
+
}))));
|
|
181
190
|
});
|
|
182
191
|
});
|
|
183
192
|
}
|
|
@@ -329,6 +338,8 @@ export function formatDoctorReport(json, distro, providers = []) {
|
|
|
329
338
|
* registry and the harness cwd service are reachable).
|
|
330
339
|
*/
|
|
331
340
|
export async function apply(ctx) {
|
|
341
|
+
// The test seam is structural; production hands the row a cordis Context.
|
|
342
|
+
installMessagesLocale(ctx);
|
|
332
343
|
const commands = resolveCommands(ctx);
|
|
333
344
|
// No command adapter: nothing to register, nothing to fail. The doctor CLI
|
|
334
345
|
// (`pnpm run doctor`) stays the surface for headless deployments.
|
|
@@ -350,15 +361,15 @@ export async function apply(ctx) {
|
|
|
350
361
|
})();
|
|
351
362
|
commands.register({
|
|
352
363
|
name: "wsl-doctor",
|
|
353
|
-
description: "
|
|
354
|
-
input: { hint: "
|
|
364
|
+
description: t("doctorCommandDescription", {}),
|
|
365
|
+
input: { hint: t("doctorInputHint", {}) },
|
|
355
366
|
handler: async (invocation) => {
|
|
356
367
|
let parsed;
|
|
357
368
|
try {
|
|
358
369
|
parsed = parseDoctorInput(invocation.rawInput);
|
|
359
370
|
}
|
|
360
371
|
catch (error) {
|
|
361
|
-
return { kind: "error", text: `${error instanceof Error ? error.message : String(error)}\n\n${
|
|
372
|
+
return { kind: "error", text: `${error instanceof Error ? error.message : String(error)}\n\n${doctorUsage()}` };
|
|
362
373
|
}
|
|
363
374
|
const distro = await resolveDistro(ctx, invocation, parsed.distro);
|
|
364
375
|
const argv = ["--json"];
|
|
@@ -377,10 +388,8 @@ export async function apply(ctx) {
|
|
|
377
388
|
return { kind: "success", text: formatDoctorReport(json, distro, takeoverSnapshot(ctx)) };
|
|
378
389
|
}
|
|
379
390
|
catch (error) {
|
|
380
|
-
const target = distro.length > 0
|
|
381
|
-
|
|
382
|
-
: "配置指定的目标(未从会话工作目录解析出发行版,auto 会逐个检查所有已安装发行版)";
|
|
383
|
-
return { kind: "error", text: `doctor 运行失败(${target}):${error instanceof Error ? error.message : String(error)}` };
|
|
391
|
+
const target = distro.length > 0 ? t("doctorTargetDistro", { distro }) : t("doctorTargetConfigured", {});
|
|
392
|
+
return { kind: "error", text: t("doctorRunFailed", { target, message: error instanceof Error ? error.message : String(error) }) };
|
|
384
393
|
}
|
|
385
394
|
},
|
|
386
395
|
});
|