dsh-plugin-wsl-env 0.26.3-rc.0 → 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.
Files changed (48) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/CONTRIBUTING.md +25 -21
  3. package/SUPPORT.md +2 -2
  4. package/SUPPORT.zh.md +2 -2
  5. package/docs/AGENT-PROTOCOL-V7.md +4 -2
  6. package/docs/API.md +1 -0
  7. package/docs/API.zh.md +1 -0
  8. package/docs/CONFIGURATION.md +21 -5
  9. package/docs/CONFIGURATION.zh.md +17 -3
  10. package/docs/MIGRATION.md +1 -1
  11. package/docs/MIGRATION.zh.md +1 -1
  12. package/docs/PARITY.md +3 -1
  13. package/docs/RELEASING.md +25 -3
  14. package/docs/REQUIREMENTS.zh.md +4 -4
  15. package/docs/ROADMAP-1.0.md +11 -7
  16. package/lib/agent.d.ts +54 -18
  17. package/lib/agent.js +86 -19
  18. package/lib/fs-routing.d.ts +3 -0
  19. package/lib/fs-routing.js +5 -0
  20. package/lib/fs-substrate.d.ts +1 -1
  21. package/lib/fs-substrate.js +10 -18
  22. package/lib/fsio-agent.d.ts +4 -0
  23. package/lib/fsio-agent.js +37 -10
  24. package/lib/listing.d.ts +2 -2
  25. package/lib/listing.js +5 -4
  26. package/lib/messages.d.ts +70 -0
  27. package/lib/messages.js +80 -0
  28. package/lib/open-in-app.js +12 -9
  29. package/lib/picker.d.ts +4 -1
  30. package/lib/picker.js +35 -11
  31. package/lib/ports.js +8 -1
  32. package/lib/provider-common.d.ts +22 -0
  33. package/lib/provider-common.js +18 -0
  34. package/lib/provider-marker.d.ts +23 -0
  35. package/lib/provider-marker.js +21 -0
  36. package/lib/status.js +8 -5
  37. package/lib/subprocess.d.ts +3 -0
  38. package/lib/subprocess.js +5 -0
  39. package/lib/takeover-report.js +4 -11
  40. package/lib/watcher.d.ts +1 -1
  41. package/lib/watcher.js +1 -1
  42. package/lib/wsl-doctor-command.d.ts +6 -2
  43. package/lib/wsl-doctor-command.js +24 -15
  44. package/lib/wsl-filesystem.d.ts +14 -11
  45. package/lib/wsl-filesystem.js +39 -27
  46. package/lib/wsl-shell.d.ts +42 -37
  47. package/lib/wsl-shell.js +53 -42
  48. package/package.json +1 -1
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 and POST 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",
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");
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({ cwd: "/", argv: ["sh", "-c", procNetScript(), "ports"], timeoutMs });
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"));
@@ -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 {};
@@ -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 "修复", and nothing changes. The cache only explains a failed
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: "只支持 GET 与 POST" }, 405);
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: `无法读取发行版清单:${error?.message ?? String(error)}` }, 502);
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: "修复需要指定发行版" }, 400);
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: `未知发行版:${requested}` }, 400);
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)
@@ -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"`
@@ -21,9 +21,7 @@
21
21
  *
22
22
  * @module dsh-plugin-wsl-env/takeover-report
23
23
  */
24
- import { WslRoutingFileSystem } from "./fs-routing.js";
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
- switch (service) {
38
- case "subprocess":
39
- return value instanceof WslSubprocessRuntime;
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 three one-letter lines, the watcher protocol:
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 three one-letter lines, the watcher protocol:
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
- /** The usage text a grammar violation settles with. */
87
- export declare const USAGE: string;
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