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.
Files changed (82) hide show
  1. package/CHANGELOG.md +142 -0
  2. package/CONTRIBUTING.md +32 -25
  3. package/CONTRIBUTING.zh.md +3 -2
  4. package/README.md +1 -1
  5. package/SECURITY.md +21 -7
  6. package/SECURITY.zh.md +18 -5
  7. package/SUPPORT.md +2 -2
  8. package/SUPPORT.zh.md +2 -2
  9. package/client.js +351 -48
  10. package/cordis.patch.yml +26 -10
  11. package/docs/AGENT-PROTOCOL-V7.md +4 -2
  12. package/docs/API.md +3 -1
  13. package/docs/API.zh.md +3 -1
  14. package/docs/ARCHITECTURE.md +22 -4
  15. package/docs/ARCHITECTURE.zh.md +18 -4
  16. package/docs/CONFIGURATION.md +117 -17
  17. package/docs/CONFIGURATION.zh.md +97 -11
  18. package/docs/DIAGNOSTICS.md +22 -11
  19. package/docs/DIAGNOSTICS.zh.md +17 -9
  20. package/docs/LIMITATIONS.md +27 -4
  21. package/docs/LIMITATIONS.zh.md +20 -3
  22. package/docs/MIGRATION.md +2 -2
  23. package/docs/MIGRATION.zh.md +2 -2
  24. package/docs/PARITY.md +3 -1
  25. package/docs/QUICKSTART.md +31 -20
  26. package/docs/QUICKSTART.zh.md +16 -9
  27. package/docs/README.zh.md +1 -1
  28. package/docs/RELEASING.md +25 -3
  29. package/docs/REQUIREMENTS.zh.md +7 -6
  30. package/docs/ROADMAP-1.0.md +11 -7
  31. package/lib/agent-confined.d.ts +9 -1
  32. package/lib/agent-confined.js +3 -3
  33. package/lib/agent.d.ts +54 -18
  34. package/lib/agent.js +86 -19
  35. package/lib/bwrap.d.ts +16 -0
  36. package/lib/bwrap.js +9 -0
  37. package/lib/fs-routing.d.ts +6 -0
  38. package/lib/fs-routing.js +7 -0
  39. package/lib/fs-substrate.d.ts +1 -1
  40. package/lib/fs-substrate.js +10 -18
  41. package/lib/fsio-agent.d.ts +4 -0
  42. package/lib/fsio-agent.js +37 -10
  43. package/lib/listing.d.ts +2 -2
  44. package/lib/listing.js +5 -4
  45. package/lib/messages.d.ts +70 -0
  46. package/lib/messages.js +80 -0
  47. package/lib/open-in-app.js +12 -9
  48. package/lib/picker.d.ts +4 -1
  49. package/lib/picker.js +35 -11
  50. package/lib/plugin-update.d.ts +212 -0
  51. package/lib/plugin-update.js +283 -0
  52. package/lib/ports.js +8 -1
  53. package/lib/provider-common.d.ts +22 -0
  54. package/lib/provider-common.js +18 -0
  55. package/lib/provider-marker.d.ts +23 -0
  56. package/lib/provider-marker.js +21 -0
  57. package/lib/sandbox-core.d.ts +2 -0
  58. package/lib/sandbox-core.js +5 -3
  59. package/lib/session-runtime.d.ts +10 -1
  60. package/lib/session-runtime.js +3 -1
  61. package/lib/shell-env.js +1 -1
  62. package/lib/socket-isolation.d.ts +103 -0
  63. package/lib/socket-isolation.js +166 -0
  64. package/lib/status.d.ts +21 -8
  65. package/lib/status.js +61 -23
  66. package/lib/subprocess.d.ts +3 -0
  67. package/lib/subprocess.js +5 -0
  68. package/lib/takeover-report.js +4 -11
  69. package/lib/update-check.d.ts +49 -9
  70. package/lib/update-check.js +81 -28
  71. package/lib/watcher.d.ts +1 -1
  72. package/lib/watcher.js +1 -1
  73. package/lib/wsl-doctor-command.d.ts +6 -2
  74. package/lib/wsl-doctor-command.js +24 -15
  75. package/lib/wsl-doctor-tool.js +2 -0
  76. package/lib/wsl-filesystem.d.ts +53 -12
  77. package/lib/wsl-filesystem.js +90 -31
  78. package/lib/wsl-shell.d.ts +109 -40
  79. package/lib/wsl-shell.js +128 -54
  80. package/package.json +8 -3
  81. package/scripts/doctor.mjs +199 -3
  82. package/scripts/profile-preset.mjs +10 -2
package/lib/fs-routing.js CHANGED
@@ -31,6 +31,7 @@
31
31
  * @module dsh-plugin-wsl-env/fs-routing
32
32
  */
33
33
  import { isWslUnc, uncToPosix } from "./paths.js";
34
+ import { PLUGIN_PROVIDER } from "./provider-marker.js";
34
35
  import z from "@deepseek-ai/schemastery";
35
36
  import { LocalFileSystem } from "@deepseek-ai/dsh-fs-local";
36
37
  import { WslFileSystem } from "./wsl-filesystem.js";
@@ -103,6 +104,10 @@ export function inputIsDistro(value) {
103
104
  * mode the distro side reports through `sandboxMode`).
104
105
  */
105
106
  export class WslRoutingFileSystem extends LocalFileSystem {
107
+ /** Brand for the in-app takeover report; see `provider-marker`. */
108
+ get [PLUGIN_PROVIDER]() {
109
+ return "fs";
110
+ }
106
111
  static Config = z.intersect([
107
112
  LocalFileSystem.Config,
108
113
  z.object({
@@ -111,6 +116,7 @@ export class WslRoutingFileSystem extends LocalFileSystem {
111
116
  distroCwd: z.string().default(""),
112
117
  sandbox: z.boolean().default(true),
113
118
  maskWindowsDrive: z.boolean().default(false),
119
+ socketIsolation: z.union(["off", "session-bus", "strict"]).default("off"),
114
120
  restrictToDistro: z.boolean().default(true),
115
121
  watchMaxDepth: z.natural().default(0),
116
122
  }),
@@ -161,6 +167,7 @@ export class WslRoutingFileSystem extends LocalFileSystem {
161
167
  diffBasisMaxBytes: config.diffBasisMaxBytes,
162
168
  sandbox: config.sandbox ?? true,
163
169
  maskWindowsDrive: config.maskWindowsDrive ?? false,
170
+ socketIsolation: config.socketIsolation ?? "off",
164
171
  restrictToDistro: config.restrictToDistro ?? true,
165
172
  watchMaxDepth: config.watchMaxDepth ?? 0,
166
173
  // The root router is app-level, not session-owned: its backend must not
@@ -31,7 +31,7 @@
31
31
  * @module dsh-plugin-wsl-env/fs-substrate
32
32
  */
33
33
  import type { PatchHunk } from "@deepseek-ai/dsh-fs-patch";
34
- import { ResolvedTarget } from "./fsio-agent.js";
34
+ import { type ResolvedTarget } from "./fsio-agent.js";
35
35
  import { DistroFs } from "./fsio-agent.js";
36
36
  import type { WslAgent } from "./agent.js";
37
37
  /**
@@ -35,10 +35,6 @@ import { reasonToCode } from "./fsio-agent.js";
35
35
  import { applyLiteralEdit, FsCodedError, normalizeLineEndings, restoreLineEndings } from "./fsio-text.js";
36
36
  import { DistroFs } from "./fsio-agent.js";
37
37
  import { posixToUnc, uncToPosix } from "./paths.js";
38
- /**
39
- * A resolved target: the Linux spelling the model sees and the UNC identity
40
- * the harness keys on, as returned by {@linkcode AgentSubstrate#resolve}.
41
- */
42
38
  /**
43
39
  * The provider's stat/lstat row, type-spelled the way the tool layer reads it.
44
40
  *
@@ -434,20 +430,15 @@ export class AgentSubstrate {
434
430
  let destinationRow;
435
431
  let sourceFailure;
436
432
  if (options.hunks !== undefined) {
437
- try {
438
- await this.fs.writeFileAtomic(destinationPath, content, {
439
- mode: sourceInfo.mode,
440
- createIfAbsent: options.expectedDestination?.kind === "createIfAbsent" ? { displayPath: destination.displayPath } : undefined,
441
- expectedVersion: options.expectedDestination?.kind === "replaceIfVersion" ? options.expectedDestination.version : undefined,
442
- signal,
443
- agent: mutationAgent,
444
- });
445
- const published = await this.fs.stat(destinationPath, { signal });
446
- destinationRow = { version: published ? published.version : `missing:${destination.targetKey}` };
447
- }
448
- catch (error) {
449
- throw error;
450
- }
433
+ await this.fs.writeFileAtomic(destinationPath, content, {
434
+ mode: sourceInfo.mode,
435
+ createIfAbsent: options.expectedDestination?.kind === "createIfAbsent" ? { displayPath: destination.displayPath } : undefined,
436
+ expectedVersion: options.expectedDestination?.kind === "replaceIfVersion" ? options.expectedDestination.version : undefined,
437
+ signal,
438
+ agent: mutationAgent,
439
+ });
440
+ const published = await this.fs.stat(destinationPath, { signal });
441
+ destinationRow = { version: published ? published.version : `missing:${destination.targetKey}` };
451
442
  try {
452
443
  await this.fs.removeFile(sourcePath, sourceInfo.version, signal, mutationAgent);
453
444
  }
@@ -464,6 +455,7 @@ export class AgentSubstrate {
464
455
  guard: options.expectedDestination?.kind === "createIfAbsent" ? "no-replace" : "replace",
465
456
  sourceVersion: sourceInfo.version,
466
457
  destinationVersion: options.expectedDestination?.kind === "replaceIfVersion" ? options.expectedDestination.version : undefined,
458
+ size: sourceInfo.size,
467
459
  signal,
468
460
  agent: mutationAgent,
469
461
  });
@@ -376,6 +376,10 @@ export declare class DistroFs {
376
376
  sourceVersion?: string;
377
377
  /** The destination version the move was based on. */
378
378
  destinationVersion?: string;
379
+ /** The source size in bytes, when known, so the budget scales with the copy. */
380
+ size?: number;
381
+ /** Explicit budget override in ms; takes precedence over `size`. */
382
+ timeoutMs?: number;
379
383
  signal?: AbortSignal;
380
384
  agent?: WslAgent;
381
385
  }): Promise<{
package/lib/fsio-agent.js CHANGED
@@ -24,8 +24,24 @@
24
24
  import { FS_READ_CHUNK_BYTES } from "./agent-protocol.js";
25
25
  import { BINARY_SAMPLE_BYTES, FsCodedError, decodeUtf8, decodeUtf8Stream, detectLineEndings, normalizeLineEndings, throwIfAborted, } from "./fsio-text.js";
26
26
  import { posixToUnc, uncToPosix } from "./paths.js";
27
- /** One FS frame's in-distro watchdog; fs ops are short, writes bounded by content size. */
27
+ /** Base in-distro watchdog for one FS frame. */
28
28
  const FS_OP_TIMEOUT_MS = 30_000;
29
+ /** Extra in-distro budget per MiB of content the op must copy, write or move. */
30
+ const FS_OP_TIMEOUT_PER_MIB_MS = 1_000;
31
+ /** Ceiling on the size-scaled budget; a stuck op must still fail in bounded time. */
32
+ const FS_OP_TIMEOUT_MAX_MS = 10 * 60_000;
33
+ /**
34
+ * The in-distro budget for an op whose cost scales with `bytes`: a fixed 30 s
35
+ * was a false `FS_IO_ERROR` for a multi-GB `move` (the agent copies with
36
+ * `cat > tmp`) or write on a slow 9p-backed distro path.
37
+ *
38
+ * @param bytes - the content size the op must handle, when known.
39
+ * @returns the frame's timeout budget in ms, capped at ten minutes.
40
+ */
41
+ function fsOpTimeoutMs(bytes = 0) {
42
+ const scaled = FS_OP_TIMEOUT_MS + Math.ceil(bytes / (1024 * 1024)) * FS_OP_TIMEOUT_PER_MIB_MS;
43
+ return Math.min(scaled, FS_OP_TIMEOUT_MAX_MS);
44
+ }
29
45
  /**
30
46
  * Normalize one agent timestamp ("seconds.frac", 9 or 10 fractional digits
31
47
  * depending on whether stat or find produced it) into the peer's nanosecond
@@ -122,9 +138,9 @@ export class DistroFs {
122
138
  * @param agent - the agent that must run the op; the plain resident by default.
123
139
  * @returns the op's result.
124
140
  */
125
- async request(op, args, signal, agent = this.agent) {
141
+ async request(op, args, signal, agent = this.agent, timeoutMs = FS_OP_TIMEOUT_MS) {
126
142
  try {
127
- return await agent.fs({ op, args: args, timeoutMs: FS_OP_TIMEOUT_MS, signal });
143
+ return await agent.fs({ op, args: args, timeoutMs, signal });
128
144
  }
129
145
  catch (error) {
130
146
  if (signal?.aborted) {
@@ -533,7 +549,7 @@ export class DistroFs {
533
549
  createIfAbsent ? "no-replace" : "replace",
534
550
  expectedVersion ?? "-",
535
551
  content,
536
- ], signal, agent);
552
+ ], signal, agent, fsOpTimeoutMs(typeof content === "string" ? Buffer.byteLength(content, "utf8") : content.byteLength));
537
553
  if (result.exitCode === 0)
538
554
  return;
539
555
  const failure = this.fail("write", result, displayPath);
@@ -580,17 +596,28 @@ export class DistroFs {
580
596
  if (result.exitCode !== 0)
581
597
  throw this.fail("batch", result, ops.map((op) => op.op).join(","));
582
598
  const records = [];
599
+ let expected = 1;
583
600
  for (const line of result.stdout.toString("utf8").split("\n")) {
584
601
  if (line.length === 0)
585
602
  continue;
586
- if (line.startsWith("OK ")) {
587
- const bar = line.indexOf("|");
588
- records.push({ ok: true, payload: Buffer.from(line.slice(bar + 1), "base64") });
603
+ const bad = line.startsWith("BAD ");
604
+ if (!bad && !line.startsWith("OK "))
605
+ continue;
606
+ const bar = line.indexOf("|");
607
+ const indexText = line.slice(bad ? 4 : 3, bar);
608
+ const index = Number(indexText);
609
+ if (bar < 0 || !Number.isInteger(index) || index !== expected) {
610
+ throw new FsCodedError(`cannot run the batch (${ops.map((op) => op.op).join(",")}): record ${expected} was answered as "${line.slice(0, bar < 0 ? 40 : bar)}"`, "FS_IO_ERROR");
611
+ }
612
+ const rest = line.slice(bar + 1);
613
+ if (!bad) {
614
+ records.push({ ok: true, payload: Buffer.from(rest, "base64") });
589
615
  }
590
- else if (line.startsWith("BAD ")) {
591
- const [, reason, message] = line.split("|");
616
+ else {
617
+ const [reason, message] = rest.split("|");
592
618
  records.push({ ok: false, reason: reason ?? "io", message: Buffer.from(message ?? "", "base64").toString("utf8") });
593
619
  }
620
+ expected += 1;
594
621
  }
595
622
  return records;
596
623
  }
@@ -633,7 +660,7 @@ export class DistroFs {
633
660
  options.guard,
634
661
  options.sourceVersion ?? "-",
635
662
  options.destinationVersion ?? "-",
636
- ], options.signal, options.agent ?? this.agent);
663
+ ], options.signal, options.agent ?? this.agent, options.timeoutMs ?? fsOpTimeoutMs(options.size));
637
664
  if (result.exitCode !== 0)
638
665
  throw this.fail("move", result, source);
639
666
  const lines = result.stdout.toString("utf8").split("\n").filter((line) => line.length > 0);
package/lib/listing.d.ts CHANGED
@@ -51,7 +51,7 @@ export declare function fullyQualified(path: string): boolean;
51
51
  export declare function ancestryCrumbs(target: string): ListingRow[];
52
52
  /** The three virtual roots the picker's breadcrumb trail is built from. */
53
53
  export interface PickerRoots {
54
- /** The two-category level ("工作区"): Windows paths and WSL distros. */
54
+ /** The two-category level ("Workspace"): Windows paths and WSL distros. */
55
55
  picker: string;
56
56
  /** The Windows branch's drive list. */
57
57
  windows: string;
@@ -63,7 +63,7 @@ export interface PickerRoots {
63
63
  * belongs to, then the path itself.
64
64
  *
65
65
  * The trail is what makes the two top-level categories reachable from anywhere:
66
- * every level keeps "工作区" as its first crumb, so a browse into a distro or a
66
+ * every level keeps the workspace crumb as its first, so a browse into a distro or a
67
67
  * drive never strands the user without a way back to the other world.
68
68
  *
69
69
  * Two Windows path quirks need explicit handling. `win32.dirname` treats
package/lib/listing.js CHANGED
@@ -11,6 +11,7 @@
11
11
  * @module dsh-plugin-wsl-env/listing
12
12
  */
13
13
  import { win32 } from "node:path";
14
+ import { t } from "./messages.js";
14
15
  import { isWslUnc, uncToPosix } from "./paths.js";
15
16
  /**
16
17
  * Whether a path names one fixed filesystem location regardless of process
@@ -61,7 +62,7 @@ export function ancestryCrumbs(target) {
61
62
  * belongs to, then the path itself.
62
63
  *
63
64
  * The trail is what makes the two top-level categories reachable from anywhere:
64
- * every level keeps "工作区" as its first crumb, so a browse into a distro or a
65
+ * every level keeps the workspace crumb as its first, so a browse into a distro or a
65
66
  * drive never strands the user without a way back to the other world.
66
67
  *
67
68
  * Two Windows path quirks need explicit handling. `win32.dirname` treats
@@ -75,13 +76,13 @@ export function ancestryCrumbs(target) {
75
76
  * @returns breadcrumb rows, outermost first.
76
77
  */
77
78
  export function breadcrumbs(target, roots) {
78
- const head = [{ name: "工作区", path: roots.picker, hidden: false }];
79
+ const head = [{ name: t("pickerWorkspace", {}), path: roots.picker, hidden: false }];
79
80
  const parsed = isWslUnc(target) ? uncToPosix(target) : undefined;
80
81
  if (parsed === undefined) {
81
- return [...head, { name: "Windows 路径", path: roots.windows, hidden: false }, ...ancestryCrumbs(target)];
82
+ return [...head, { name: t("pickerWindowsPaths", {}), path: roots.windows, hidden: false }, ...ancestryCrumbs(target)];
82
83
  }
83
84
  const distroRootPath = `${roots.wsl}\\${parsed.distro}`;
84
- head.push({ name: "WSL 发行版", path: roots.wsl, hidden: false });
85
+ head.push({ name: t("pickerWslDistros", {}), path: roots.wsl, hidden: false });
85
86
  head.push({ name: parsed.distro, path: distroRootPath, hidden: false });
86
87
  let current = distroRootPath;
87
88
  for (const segment of parsed.linuxPath.split("/").filter((part) => part.length > 0)) {
package/lib/messages.d.ts CHANGED
@@ -138,6 +138,76 @@ declare const en: {
138
138
  cwd: string;
139
139
  distro: string;
140
140
  }) => string;
141
+ /** `wsl-status`: the route's method guard. */
142
+ statusMethodNotAllowed: () => string;
143
+ /** `wsl-status`: `wsl.exe -l -q` did not answer. */
144
+ statusDistroListFailed: ({ detail }: {
145
+ detail: string;
146
+ }) => string;
147
+ /** `wsl-status`: a repair POST named no distro. */
148
+ statusRepairNeedsDistro: () => string;
149
+ /** `wsl-status`: the requested name is not in `wsl.exe -l -q`. */
150
+ statusUnknownDistro: ({ distro }: {
151
+ distro: string;
152
+ }) => string;
153
+ /** `wsl-open-in-app`: the route's method guard. */
154
+ openInAppPostOnly: () => string;
155
+ /** `wsl-open-in-app`: the route requires a JSON content type. */
156
+ openInAppJsonContentType: () => string;
157
+ /** `wsl-open-in-app`: the request body did not parse as JSON. */
158
+ openInAppInvalidJson: () => string;
159
+ /** `wsl-open-in-app`: the body parsed but is not an object. */
160
+ openInAppBodyNotObject: () => string;
161
+ /** `wsl-open-in-app`: the body's `path` is not a string. */
162
+ openInAppPathMustBeString: () => string;
163
+ /** `wsl-open-in-app`: the path is not a WSL UNC workspace. */
164
+ openInAppNotWslWorkspacePath: () => string;
165
+ /** `wsl-open-in-app`: the detached launch failed. */
166
+ openInAppLaunchFailed: () => string;
167
+ /** `wsl-open-in-app`: no editor executable could be resolved. */
168
+ openInAppExecutableMissing: () => string;
169
+ /** The directory picker's root crumb, shared by every level. */
170
+ pickerWorkspace: () => string;
171
+ /** The directory picker's Windows branch label. */
172
+ pickerWindowsPaths: () => string;
173
+ /** The directory picker's WSL branch label. */
174
+ pickerWslDistros: () => string;
175
+ /** `/wsl-doctor`: the usage block a grammar violation settles with. */
176
+ doctorUsage: ({ sections }: {
177
+ sections: string;
178
+ }) => string;
179
+ /** `/wsl-doctor`: a token that matches no mode, section or distro spelling. */
180
+ doctorUnknownToken: ({ token }: {
181
+ token: string;
182
+ }) => string;
183
+ /** `/wsl-doctor`: `--distro` was not followed by a name. */
184
+ doctorDistroNeedsName: () => string;
185
+ /** `/wsl-doctor`: the CLI run was cancelled. */
186
+ doctorCliCancelled: () => string;
187
+ /** `/wsl-doctor`: the CLI produced no report before the deadline. */
188
+ doctorCliTimeout: ({ seconds }: {
189
+ seconds: number;
190
+ }) => string;
191
+ /** `/wsl-doctor`: the CLI exited without a report. `detail` is "" or ": <stderr>". */
192
+ doctorCliNoReport: ({ status, detail }: {
193
+ status: string;
194
+ detail: string;
195
+ }) => string;
196
+ /** `/wsl-doctor`: the resolved target is one named distro. */
197
+ doctorTargetDistro: ({ distro }: {
198
+ distro: string;
199
+ }) => string;
200
+ /** `/wsl-doctor`: no distro resolved, so the CLI's configured target decides. */
201
+ doctorTargetConfigured: () => string;
202
+ /** `/wsl-doctor`: the CLI run failed; `target` is the localized target phrase. */
203
+ doctorRunFailed: ({ target, message }: {
204
+ target: string;
205
+ message: string;
206
+ }) => string;
207
+ /** `/wsl-doctor`: the command-plane description. */
208
+ doctorCommandDescription: () => string;
209
+ /** `/wsl-doctor`: the input hint under the command name. */
210
+ doctorInputHint: () => string;
141
211
  /** `wsl_doctor` digest: the verdict line. `verdict` is the report's own `ready`/`blocked`. */
142
212
  doctorDigestVerdict: ({ verdict }: {
143
213
  verdict: string;
package/lib/messages.js CHANGED
@@ -106,6 +106,59 @@ const en = {
106
106
  `session runs the host (Windows) environment: commands execute in Windows PowerShell, file access crosses the ` +
107
107
  `9p share, and the distro's Linux toolchain is unavailable. Do not assume Linux commands, paths, or tooling ` +
108
108
  `here; the operator can run /wsl-doctor to diagnose the profile.`,
109
+ /** `wsl-status`: the route's method guard. */
110
+ statusMethodNotAllowed: () => "Only GET, POST and DELETE are supported",
111
+ /** `wsl-status`: `wsl.exe -l -q` did not answer. */
112
+ statusDistroListFailed: ({ detail }) => `Cannot read the distro list: ${detail}`,
113
+ /** `wsl-status`: a repair POST named no distro. */
114
+ statusRepairNeedsDistro: () => "Repair requires a distro",
115
+ /** `wsl-status`: the requested name is not in `wsl.exe -l -q`. */
116
+ statusUnknownDistro: ({ distro }) => `Unknown distro: ${distro}`,
117
+ /** `wsl-open-in-app`: the route's method guard. */
118
+ openInAppPostOnly: () => "Only POST is supported",
119
+ /** `wsl-open-in-app`: the route requires a JSON content type. */
120
+ openInAppJsonContentType: () => "content-type must be application/json",
121
+ /** `wsl-open-in-app`: the request body did not parse as JSON. */
122
+ openInAppInvalidJson: () => "The request body is not valid JSON",
123
+ /** `wsl-open-in-app`: the body parsed but is not an object. */
124
+ openInAppBodyNotObject: () => "The request body must be an object",
125
+ /** `wsl-open-in-app`: the body's `path` is not a string. */
126
+ openInAppPathMustBeString: () => "path must be a string",
127
+ /** `wsl-open-in-app`: the path is not a WSL UNC workspace. */
128
+ openInAppNotWslWorkspacePath: () => "Not a WSL workspace path",
129
+ /** `wsl-open-in-app`: the detached launch failed. */
130
+ openInAppLaunchFailed: () => "VS Code failed to launch",
131
+ /** `wsl-open-in-app`: no editor executable could be resolved. */
132
+ openInAppExecutableMissing: () => "VS Code was not found; configure executable on the wsl-open-in-app row",
133
+ /** The directory picker's root crumb, shared by every level. */
134
+ pickerWorkspace: () => "Workspace",
135
+ /** The directory picker's Windows branch label. */
136
+ pickerWindowsPaths: () => "Windows paths",
137
+ /** The directory picker's WSL branch label. */
138
+ pickerWslDistros: () => "WSL distros",
139
+ /** `/wsl-doctor`: the usage block a grammar violation settles with. */
140
+ doctorUsage: ({ sections }) => `Usage: /wsl-doctor [quick|full|<section>] [--distro <name>]\n` +
141
+ `section ∈ ${sections}; an empty input means quick. Without --distro the distro is inferred from the session's working directory.`,
142
+ /** `/wsl-doctor`: a token that matches no mode, section or distro spelling. */
143
+ doctorUnknownToken: ({ token }) => `Unrecognized argument: ${token}`,
144
+ /** `/wsl-doctor`: `--distro` was not followed by a name. */
145
+ doctorDistroNeedsName: () => "--distro needs a name",
146
+ /** `/wsl-doctor`: the CLI run was cancelled. */
147
+ doctorCliCancelled: () => "the doctor CLI was cancelled",
148
+ /** `/wsl-doctor`: the CLI produced no report before the deadline. */
149
+ doctorCliTimeout: ({ seconds }) => `the doctor CLI produced no report within ${seconds} seconds; narrow to one distro with --distro <name>, or retry with quick / <section>`,
150
+ /** `/wsl-doctor`: the CLI exited without a report. `detail` is "" or ": <stderr>". */
151
+ doctorCliNoReport: ({ status, detail }) => `the doctor CLI produced no report (exit ${status})${detail}`,
152
+ /** `/wsl-doctor`: the resolved target is one named distro. */
153
+ doctorTargetDistro: ({ distro }) => `distro ${distro}`,
154
+ /** `/wsl-doctor`: no distro resolved, so the CLI's configured target decides. */
155
+ doctorTargetConfigured: () => "the configured target (no distro was resolved from the session working directory; auto checks every installed distro)",
156
+ /** `/wsl-doctor`: the CLI run failed; `target` is the localized target phrase. */
157
+ doctorRunFailed: ({ target, message }) => `doctor run failed (${target}): ${message}`,
158
+ /** `/wsl-doctor`: the command-plane description. */
159
+ doctorCommandDescription: () => "Run the WSL environment doctor (standalone CLI): the report appears here and stays out of the model conversation. No arguments means a quick check.",
160
+ /** `/wsl-doctor`: the input hint under the command name. */
161
+ doctorInputHint: () => "[quick|full|<section>] [--distro <name>]",
109
162
  /** `wsl_doctor` digest: the verdict line. `verdict` is the report's own `ready`/`blocked`. */
110
163
  doctorDigestVerdict: ({ verdict }) => `wsl doctor verdict: ${verdict}`,
111
164
  /** `wsl_doctor` digest: the host-wide group heading. */
@@ -179,6 +232,33 @@ const zh = {
179
232
  hostModePresetUnavailable: ({ cwd, distro }) => `工作区 "${cwd}" 位于 WSL 发行版 "${distro}" 内,但本 profile 未装配 WSL preset,` +
180
233
  `因此本会话运行在宿主(Windows)环境:命令经 PowerShell 执行,文件访问经过 9p 共享,发行版的 Linux 工具链不可用。` +
181
234
  `不要在此假设 Linux 命令、路径或工具;操作者可运行 /wsl-doctor 诊断该 profile。`,
235
+ statusMethodNotAllowed: () => "只支持 GET、POST 与 DELETE",
236
+ statusDistroListFailed: ({ detail }) => `无法读取发行版清单:${detail}`,
237
+ statusRepairNeedsDistro: () => "修复需要指定发行版",
238
+ statusUnknownDistro: ({ distro }) => `未知发行版:${distro}`,
239
+ openInAppPostOnly: () => "只支持 POST",
240
+ openInAppJsonContentType: () => "content-type 必须是 application/json",
241
+ openInAppInvalidJson: () => "请求体不是合法 JSON",
242
+ openInAppBodyNotObject: () => "请求体必须是对象",
243
+ openInAppPathMustBeString: () => "path 必须是字符串",
244
+ openInAppNotWslWorkspacePath: () => "不是 WSL 工作区路径",
245
+ openInAppLaunchFailed: () => "VS Code 启动失败",
246
+ openInAppExecutableMissing: () => "找不到 VS Code;可在 wsl-open-in-app 行配置 executable",
247
+ pickerWorkspace: () => "工作区",
248
+ pickerWindowsPaths: () => "Windows 路径",
249
+ pickerWslDistros: () => "WSL 发行版",
250
+ doctorUsage: ({ sections }) => `用法:/wsl-doctor [quick|full|<section>] [--distro <名称>]\n` +
251
+ `section ∈ ${sections};空输入等价 quick。省略 --distro 时用当前会话的工作目录推断 distro。`,
252
+ doctorUnknownToken: ({ token }) => `无法识别的参数:${token}`,
253
+ doctorDistroNeedsName: () => "--distro 需要一个名称",
254
+ doctorCliCancelled: () => "doctor CLI 已取消",
255
+ doctorCliTimeout: ({ seconds }) => `doctor CLI 在 ${seconds} 秒内没有给出报告;用 --distro <名称> 收窄到单个发行版,或改用 quick / <分区> 重试`,
256
+ doctorCliNoReport: ({ status, detail }) => `doctor CLI 未能给出报告(exit ${status})${detail}`,
257
+ doctorTargetDistro: ({ distro }) => `发行版 ${distro}`,
258
+ doctorTargetConfigured: () => "配置指定的目标(未从会话工作目录解析出发行版,auto 会逐个检查所有已安装发行版)",
259
+ doctorRunFailed: ({ target, message }) => `doctor 运行失败(${target}):${message}`,
260
+ doctorCommandDescription: () => "运行 WSL 环境诊断(独立 doctor CLI):结果直接显示在此,不进入模型对话。省略参数为快速诊断。",
261
+ doctorInputHint: () => "[quick|full|<section>] [--distro <名称>]",
182
262
  doctorDigestVerdict: ({ verdict }) => `wsl doctor 裁决:${verdict}`,
183
263
  doctorDigestHostLabel: () => "(宿主——Windows 与全局检查)",
184
264
  doctorDigestNotRunLabel: () => "(不在本次范围)",
@@ -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: "只支持 POST" }, 405);
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: "content-type 必须是 application/json" }, 415);
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: "请求体不是合法 JSON" }, 400);
231
+ return json({ error: t("openInAppInvalidJson", {}) }, 400);
231
232
  }
232
233
  if (typeof body !== "object" || body === null)
233
- return json({ error: "请求体必须是对象" }, 400);
234
+ return json({ error: t("openInAppBodyNotObject", {}) }, 400);
234
235
  const path = body.path;
235
236
  if (typeof path !== "string")
236
- return json({ error: "path 必须是字符串" }, 400);
237
+ return json({ error: t("openInAppPathMustBeString", {}) }, 400);
237
238
  const uri = editorUri(path);
238
239
  if (uri === undefined)
239
- return json({ error: "不是 WSL 工作区路径" }, 400);
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: "VS Code 启动失败" }, 502);
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
- ? "找不到 VS Code;可在 wsl-open-in-app 行配置 executable"
254
- : "VS Code 启动失败",
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 "工作区" crumb returns here from either one.
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 "工作区" crumb returns here from either one.
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: "Windows 路径", path: HOST_ROOT, hidden: false });
271
- entries.push({ name: "WSL 发行版", path: UNC_PROVIDER_ROOT, hidden: false });
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: "工作区", path: PICKER_ROOT, hidden: false }],
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: "工作区", path: PICKER_ROOT, hidden: false },
304
- { name: "WSL 发行版", path: UNC_PROVIDER_ROOT, hidden: false },
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: "工作区", path: PICKER_ROOT, hidden: false },
334
- { name: "Windows 路径", path: HOST_ROOT, hidden: false },
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({ cwd: linuxParent, argv: distroMkdirArgv(linuxParent, name), timeoutMs: 10_000 });
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");