dsh-plugin-wsl-env 0.23.1 → 0.25.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 (77) hide show
  1. package/CHANGELOG.md +212 -0
  2. package/README.md +9 -5
  3. package/SECURITY.md +10 -0
  4. package/client.js +974 -165
  5. package/cordis.patch.yml +28 -3
  6. package/docs/API.md +2 -1
  7. package/docs/ARCHITECTURE.md +36 -13
  8. package/docs/COMPATIBILITY.md +5 -0
  9. package/docs/CONFIGURATION.md +80 -9
  10. package/docs/CONFIGURATION.zh.md +64 -8
  11. package/docs/DIAGNOSTICS.md +48 -20
  12. package/docs/DIAGNOSTICS.zh.md +36 -14
  13. package/docs/LIMITATIONS.md +36 -9
  14. package/docs/LIMITATIONS.zh.md +26 -7
  15. package/docs/MIGRATION.md +1 -1
  16. package/docs/PEER-PARITY.md +4 -4
  17. package/docs/QUICKSTART.md +42 -12
  18. package/docs/QUICKSTART.zh.md +29 -8
  19. package/docs/README.zh.md +9 -5
  20. package/docs/RELEASING.md +17 -13
  21. package/docs/REQUIREMENTS.zh.md +5 -4
  22. package/docs/UPSTREAM-FSIO-EXPORT.md +5 -4
  23. package/docs/UPSTREAM-PROMPT-ADAPTERS.md +85 -0
  24. package/docs/root-fs-routing.md +1 -1
  25. package/lib/agent-confined.d.ts +7 -1
  26. package/lib/agent-confined.js +3 -3
  27. package/lib/auto-preset.d.ts +27 -0
  28. package/lib/auto-preset.js +40 -3
  29. package/lib/bwrap.d.ts +14 -0
  30. package/lib/bwrap.js +11 -0
  31. package/lib/client-host.d.ts +2 -2
  32. package/lib/client-host.js +2 -2
  33. package/lib/cwd-prompt.d.ts +41 -3
  34. package/lib/cwd-prompt.js +125 -8
  35. package/lib/doctor-report.d.ts +50 -0
  36. package/lib/doctor-report.js +172 -0
  37. package/lib/fs-routing.d.ts +1 -1
  38. package/lib/fs-routing.js +1 -1
  39. package/lib/fs.d.ts +1 -1
  40. package/lib/fs.js +1 -1
  41. package/lib/index.d.ts +6 -1464
  42. package/lib/index.js +5 -2120
  43. package/lib/listing.d.ts +21 -9
  44. package/lib/listing.js +25 -21
  45. package/lib/messages.d.ts +1 -1
  46. package/lib/messages.js +3 -3
  47. package/lib/picker.d.ts +50 -16
  48. package/lib/picker.js +103 -23
  49. package/lib/preflight.d.ts +7 -4
  50. package/lib/preflight.js +27 -13
  51. package/lib/preset-choice.d.ts +22 -3
  52. package/lib/preset-choice.js +36 -3
  53. package/lib/provider-common.d.ts +58 -0
  54. package/lib/provider-common.js +123 -0
  55. package/lib/sandbox-core.d.ts +1 -0
  56. package/lib/sandbox-core.js +4 -2
  57. package/lib/session-runtime.d.ts +7 -1
  58. package/lib/session-runtime.js +9 -2
  59. package/lib/shell.d.ts +1 -1
  60. package/lib/shell.js +1 -1
  61. package/lib/status.d.ts +261 -0
  62. package/lib/status.js +425 -0
  63. package/lib/writable-roots.d.ts +109 -0
  64. package/lib/writable-roots.js +257 -0
  65. package/lib/wsl-doctor-tool.d.ts +8 -0
  66. package/lib/wsl-doctor-tool.js +18 -20
  67. package/lib/wsl-filesystem.d.ts +692 -0
  68. package/lib/wsl-filesystem.js +897 -0
  69. package/lib/wsl-shell.d.ts +742 -0
  70. package/lib/wsl-shell.js +965 -0
  71. package/lib/wsl.d.ts +13 -1
  72. package/lib/wsl.js +16 -1
  73. package/locale/doctor/en.json +3 -2
  74. package/locale/doctor/zh.json +3 -2
  75. package/package.json +12 -4
  76. package/scripts/doctor.mjs +436 -226
  77. package/scripts/profile-preset.mjs +17 -5
package/lib/listing.d.ts CHANGED
@@ -49,22 +49,34 @@ export declare function fullyQualified(path: string): boolean;
49
49
  * @returns the ancestry, outermost first.
50
50
  */
51
51
  export declare function ancestryCrumbs(target: string): ListingRow[];
52
+ /** The three virtual roots the picker's breadcrumb trail is built from. */
53
+ export interface PickerRoots {
54
+ /** The two-category level ("工作区"): Windows paths and WSL distros. */
55
+ picker: string;
56
+ /** The Windows branch's drive list. */
57
+ windows: string;
58
+ /** The WSL branch's distro list (the share root). */
59
+ wsl: string;
60
+ }
52
61
  /**
53
- * Breadcrumb rows for a level, with the WSL share head prepended for anything
54
- * inside a distro.
62
+ * Breadcrumb rows for a level: the category root, then the world the path
63
+ * belongs to, then the path itself.
64
+ *
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
67
+ * drive never strands the user without a way back to the other world.
55
68
  *
56
- * Two Windows path quirks make this more than a relabel. `win32.dirname` treats
69
+ * Two Windows path quirks need explicit handling. `win32.dirname` treats
57
70
  * `\\server\share` as a volume root and never yields the share itself, so the
58
- * WSL row has to be synthesized; and `win32.basename` of that same share root is
59
- * the empty string, so the distro row is named from the parsed distro instead.
60
- * Without both fixes, browsing into a distro would render a blank breadcrumb and
61
- * offer no way back to the distro list.
71
+ * WSL rows are synthesized from the parsed distro instead of the ancestry walk;
72
+ * and `win32.basename` of a volume root is empty, so {@link ancestryCrumbs}
73
+ * already falls back to the drive's own path.
62
74
  *
63
75
  * @param target - the directory being listed.
64
- * @param providerRoot - the share root acting as the WSL row's jump target.
76
+ * @param roots - the picker, Windows and WSL jump targets.
65
77
  * @returns breadcrumb rows, outermost first.
66
78
  */
67
- export declare function breadcrumbs(target: string, providerRoot: string): ListingRow[];
79
+ export declare function breadcrumbs(target: string, roots: PickerRoots): ListingRow[];
68
80
  /**
69
81
  * Insert a streamed candidate into the name-sorted bounded window, evicting the
70
82
  * name-largest candidate when the window exceeds `keep`. Keeps memory O(keep)
package/lib/listing.js CHANGED
@@ -57,34 +57,38 @@ export function ancestryCrumbs(target) {
57
57
  }
58
58
  }
59
59
  /**
60
- * Breadcrumb rows for a level, with the WSL share head prepended for anything
61
- * inside a distro.
60
+ * Breadcrumb rows for a level: the category root, then the world the path
61
+ * belongs to, then the path itself.
62
62
  *
63
- * Two Windows path quirks make this more than a relabel. `win32.dirname` treats
63
+ * 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
+ * drive never strands the user without a way back to the other world.
66
+ *
67
+ * Two Windows path quirks need explicit handling. `win32.dirname` treats
64
68
  * `\\server\share` as a volume root and never yields the share itself, so the
65
- * WSL row has to be synthesized; and `win32.basename` of that same share root is
66
- * the empty string, so the distro row is named from the parsed distro instead.
67
- * Without both fixes, browsing into a distro would render a blank breadcrumb and
68
- * offer no way back to the distro list.
69
+ * WSL rows are synthesized from the parsed distro instead of the ancestry walk;
70
+ * and `win32.basename` of a volume root is empty, so {@link ancestryCrumbs}
71
+ * already falls back to the drive's own path.
69
72
  *
70
73
  * @param target - the directory being listed.
71
- * @param providerRoot - the share root acting as the WSL row's jump target.
74
+ * @param roots - the picker, Windows and WSL jump targets.
72
75
  * @returns breadcrumb rows, outermost first.
73
76
  */
74
- export function breadcrumbs(target, providerRoot) {
75
- const crumbs = ancestryCrumbs(target);
76
- const head = crumbs[0];
77
- if (head === undefined)
78
- return [{ name: "WSL", path: providerRoot, hidden: false }];
79
- const parsed = isWslUnc(head.path) ? uncToPosix(head.path) : undefined;
80
- if (parsed !== undefined && parsed.linuxPath === "/") {
81
- // `win32.dirname` reports the share root with a trailing separator
82
- // (`\\wsl.localhost\ubuntu\`); rewrite the row to the canonical distro root
83
- // so crumb paths match what distroRoot() and the picker produce elsewhere.
84
- crumbs[0] = { name: parsed.distro, path: `${providerRoot}\\${parsed.distro}`, hidden: false };
85
- crumbs.unshift({ name: "WSL", path: providerRoot, hidden: false });
77
+ export function breadcrumbs(target, roots) {
78
+ const head = [{ name: "工作区", path: roots.picker, hidden: false }];
79
+ const parsed = isWslUnc(target) ? uncToPosix(target) : undefined;
80
+ if (parsed === undefined) {
81
+ return [...head, { name: "Windows 路径", path: roots.windows, hidden: false }, ...ancestryCrumbs(target)];
82
+ }
83
+ const distroRootPath = `${roots.wsl}\\${parsed.distro}`;
84
+ head.push({ name: "WSL 发行版", path: roots.wsl, hidden: false });
85
+ head.push({ name: parsed.distro, path: distroRootPath, hidden: false });
86
+ let current = distroRootPath;
87
+ for (const segment of parsed.linuxPath.split("/").filter((part) => part.length > 0)) {
88
+ current = `${current}\\${segment}`;
89
+ head.push({ name: segment, path: current, hidden: false });
86
90
  }
87
- return crumbs;
91
+ return head;
88
92
  }
89
93
  /**
90
94
  * Insert a streamed candidate into the name-sorted bounded window, evicting the
package/lib/messages.d.ts CHANGED
@@ -146,7 +146,7 @@ declare const en: {
146
146
  doctorDigestFixPrefix: ({ remedy }: {
147
147
  remedy: string;
148
148
  }) => string;
149
- /** `wsl_doctor` digest: the ready note (how to attach the full report). */
149
+ /** `wsl_doctor` digest: the ready note; the report is not a promise about a call. */
150
150
  doctorDigestNoteReady: () => string;
151
151
  /** `wsl_doctor` digest: the blocked note (the rerun is the re-verification). */
152
152
  doctorDigestNoteBlocked: () => string;
package/lib/messages.js CHANGED
@@ -96,8 +96,8 @@ const en = {
96
96
  doctorTallySkipped: ({ n }) => `${n} skipped`,
97
97
  /** `wsl_doctor` digest: the remedy prefix under a failed check. */
98
98
  doctorDigestFixPrefix: ({ remedy }) => ` fix: ${remedy}`,
99
- /** `wsl_doctor` digest: the ready note (how to attach the full report). */
100
- doctorDigestNoteReady: () => "the first command should succeed; run the CLI (pnpm run doctor --bundle <path>) for the attachable file",
99
+ /** `wsl_doctor` digest: the ready note; the report is not a promise about a call. */
100
+ doctorDigestNoteReady: () => "ready covers the checks in this run; it does not promise every command will succeed",
101
101
  /** `wsl_doctor` digest: the blocked note (the rerun is the re-verification). */
102
102
  doctorDigestNoteBlocked: () => "apply each remedy above, then call this tool again — the re-run is the re-verification",
103
103
  /** `wsl_doctor` digest: the blocked summary tail; `noneBlocking` is the fixed clause. */
@@ -143,7 +143,7 @@ const zh = {
143
143
  doctorTallyInfo: ({ n }) => `信息 ${n}`,
144
144
  doctorTallySkipped: ({ n }) => `跳过 ${n}`,
145
145
  doctorDigestFixPrefix: ({ remedy }) => ` 修复: ${remedy}`,
146
- doctorDigestNoteReady: () => "首条命令应能成功;如需可附加的报告文件,运行 CLI(pnpm run doctor --bundle <path>)",
146
+ doctorDigestNoteReady: () => "ready 只覆盖本次检查,不保证每条命令都能成功",
147
147
  doctorDigestNoteBlocked: () => "应用上方每条修复,然后再次调用本工具——重跑即复核",
148
148
  doctorDigestBlockedTail: ({ blockers, warnings, skipped, note }) => `阻断项:${blockers};${warnings} 个警告,${skipped} 个跳过腿——均不阻断;${note}`,
149
149
  };
package/lib/picker.d.ts CHANGED
@@ -51,6 +51,18 @@ import z from "@deepseek-ai/schemastery";
51
51
  import { DirectoryPicker } from "@deepseek-ai/dsh-host-directory-picker";
52
52
  import type { Context } from "@deepseek-ai/cordis";
53
53
  import type { DirectoryEntry, DirectoryListing, DirectoryPickerBrowseCapability } from "@deepseek-ai/dsh-host-directory-picker";
54
+ /**
55
+ * Virtual root of the picker's category level: the Windows world and the WSL
56
+ * world. It is a sentinel, never a filesystem path; `list` recognises it and
57
+ * answers the two-category listing.
58
+ */
59
+ export declare const PICKER_ROOT = "\\\\dsh.localhost\\picker";
60
+ /**
61
+ * Virtual root of the Windows branch: the host's drive roots. Start the
62
+ * Windows walk at the drives rather than at one user's home, so the branch
63
+ * covers every volume and every account.
64
+ */
65
+ export declare const HOST_ROOT = "\\\\dsh.localhost\\windows";
54
66
  /**
55
67
  * The resolved service configuration, as {@link WslDirectoryPicker.Config} yields.
56
68
  */
@@ -63,7 +75,9 @@ interface PickerConfig {
63
75
  */
64
76
  preferredDistro: string;
65
77
  /**
66
- * Whether the Windows home is also offered at the root level.
78
+ * Whether the picker offers the Windows path branch. That branch starts at
79
+ * the drive roots, so it covers every volume and account; without it the
80
+ * category level carries the WSL branch alone.
67
81
  */
68
82
  includeHostHome: boolean;
69
83
  /**
@@ -90,9 +104,10 @@ export declare class WslDirectoryPicker extends DirectoryPicker {
90
104
  */
91
105
  preferredDistro: z<string, string, "defined">;
92
106
  /**
93
- * Also offer the Windows home directory at the root level, so a normal
94
- * host folder stays reachable without typing a path. The dialog's editable
95
- * path zone accepts any Windows path either way.
107
+ * Offer the Windows path branch, starting at the drive roots, so every
108
+ * volume and account stays reachable without typing a path. Without it the
109
+ * category level carries the WSL branch alone; the dialog's editable path
110
+ * zone accepts any Windows path either way.
96
111
  */
97
112
  includeHostHome: z<boolean, boolean, "defined">;
98
113
  /** Bound on the directory rows one `list` call may return; the level is flagged truncated. */
@@ -108,9 +123,10 @@ export declare class WslDirectoryPicker extends DirectoryPicker {
108
123
  */
109
124
  preferredDistro: z<string, string, "defined">;
110
125
  /**
111
- * Also offer the Windows home directory at the root level, so a normal
112
- * host folder stays reachable without typing a path. The dialog's editable
113
- * path zone accepts any Windows path either way.
126
+ * Offer the Windows path branch, starting at the drive roots, so every
127
+ * volume and account stays reachable without typing a path. Without it the
128
+ * category level carries the WSL branch alone; the dialog's editable path
129
+ * zone accepts any Windows path either way.
114
130
  */
115
131
  includeHostHome: z<boolean, boolean, "defined">;
116
132
  /** Bound on the directory rows one `list` call may return; the level is flagged truncated. */
@@ -171,18 +187,34 @@ export declare class WslDirectoryPicker extends DirectoryPicker {
171
187
  */
172
188
  homeOf(distro: string, signal?: AbortSignal): Promise<string>;
173
189
  /**
174
- * The root level: one row per installed distro, plus the Windows home when
175
- * configured. `path` is the preferred distro's root rather than the share
176
- * root, so adopting the level with nothing selected still yields a real
177
- * directory; the breadcrumb's "WSL" row carries the share root and returns
178
- * here.
190
+ * The category level: the Windows world and the WSL world.
191
+ *
192
+ * `path` is the Windows home — a real directory — so adopting the level with
193
+ * nothing selected still yields something adoptable; the entries are the two
194
+ * branches, and the "工作区" crumb returns here from either one.
195
+ *
196
+ * @param signal - optional cancellation.
197
+ * @returns the category listing.
198
+ */
199
+ categoryLevel(signal?: AbortSignal): Promise<DirectoryListing>;
200
+ /**
201
+ * The WSL branch: one row per installed distro. `path` is the preferred
202
+ * distro's root rather than the share root, so adopting the level with
203
+ * nothing selected still yields a real directory.
179
204
  *
180
205
  * @param signal - optional cancellation.
181
- * @returns the root listing.
206
+ * @returns the distro listing.
207
+ */
208
+ distroLevel(signal?: AbortSignal): Promise<DirectoryListing>;
209
+ /**
210
+ * The Windows branch: the host's drive roots, so the walk starts at every
211
+ * volume rather than at one account's home.
212
+ *
213
+ * @returns the drive listing.
182
214
  */
183
- rootLevel(signal?: AbortSignal): Promise<DirectoryListing>;
215
+ driveLevel(): Promise<DirectoryListing>;
184
216
  /**
185
- * Breadcrumb rows for a level, headed by the WSL row.
217
+ * Breadcrumb rows for a level: the category root, its world, then the path.
186
218
  *
187
219
  * @param target - the directory being listed.
188
220
  * @returns breadcrumb rows.
@@ -191,7 +223,9 @@ export declare class WslDirectoryPicker extends DirectoryPicker {
191
223
  /**
192
224
  * List one directory level.
193
225
  *
194
- * @param path - absolute directory; absent or the share root lists the distros.
226
+ * @param path - absent, the picker root or the WSL share root selects a
227
+ * virtual level (categories, distros or drives); anything else is a real
228
+ * directory.
195
229
  * @param signal - caller lifetime.
196
230
  * @returns the level's listing with its ancestry.
197
231
  * @throws DirectoryPickerError with code `directory-unreadable`.
package/lib/picker.js CHANGED
@@ -59,6 +59,20 @@ import { sharedAgent } from "./agent-shared.js";
59
59
  import { AgentUnavailableError } from "./agent-errors.js";
60
60
  /** How long a resolved distro list stays fresh before it is queried again. */
61
61
  const DEFAULT_DISTRO_CACHE_MS = 5_000;
62
+ /**
63
+ * Virtual root of the picker's category level: the Windows world and the WSL
64
+ * world. It is a sentinel, never a filesystem path; `list` recognises it and
65
+ * answers the two-category listing.
66
+ */
67
+ export const PICKER_ROOT = "\\\\dsh.localhost\\picker";
68
+ /**
69
+ * Virtual root of the Windows branch: the host's drive roots. Start the
70
+ * Windows walk at the drives rather than at one user's home, so the branch
71
+ * covers every volume and every account.
72
+ */
73
+ export const HOST_ROOT = "\\\\dsh.localhost\\windows";
74
+ /** The breadcrumb jump targets every listing shares. */
75
+ const PICKER_ROOTS = { picker: PICKER_ROOT, windows: HOST_ROOT, wsl: UNC_PROVIDER_ROOT };
62
76
  /**
63
77
  * Await `operation`, but reject with the signal's reason the moment it aborts.
64
78
  * Node's filesystem reads are not retractable, so the operation itself keeps
@@ -145,9 +159,10 @@ export class WslDirectoryPicker extends DirectoryPicker {
145
159
  */
146
160
  preferredDistro: z.string().default(""),
147
161
  /**
148
- * Also offer the Windows home directory at the root level, so a normal
149
- * host folder stays reachable without typing a path. The dialog's editable
150
- * path zone accepts any Windows path either way.
162
+ * Offer the Windows path branch, starting at the drive roots, so every
163
+ * volume and account stays reachable without typing a path. Without it the
164
+ * category level carries the WSL branch alone; the dialog's editable path
165
+ * zone accepts any Windows path either way.
151
166
  */
152
167
  includeHostHome: z.boolean().default(true),
153
168
  /** Bound on the directory rows one `list` call may return; the level is flagged truncated. */
@@ -237,54 +252,119 @@ export class WslDirectoryPicker extends DirectoryPicker {
237
252
  return home;
238
253
  }
239
254
  /**
240
- * The root level: one row per installed distro, plus the Windows home when
241
- * configured. `path` is the preferred distro's root rather than the share
242
- * root, so adopting the level with nothing selected still yields a real
243
- * directory; the breadcrumb's "WSL" row carries the share root and returns
244
- * here.
255
+ * The category level: the Windows world and the WSL world.
256
+ *
257
+ * `path` is the Windows home — a real directory — so adopting the level with
258
+ * nothing selected still yields something adoptable; the entries are the two
259
+ * branches, and the "工作区" crumb returns here from either one.
260
+ *
261
+ * @param signal - optional cancellation.
262
+ * @returns the category listing.
263
+ */
264
+ async categoryLevel(signal) {
265
+ const entries = [];
266
+ // The key historically meant "also offer Windows paths"; it now gates the
267
+ // whole Windows branch, whose walk starts at the drives.
268
+ if (this.config.includeHostHome)
269
+ entries.push({ name: "Windows 路径", path: HOST_ROOT, hidden: false });
270
+ entries.push({ name: "WSL 发行版", path: UNC_PROVIDER_ROOT, hidden: false });
271
+ const preferred = await this.preferredDistro(signal);
272
+ const home = preferred.length > 0 ? await this.homeOf(preferred, signal) : homedir();
273
+ return {
274
+ path: homedir(),
275
+ home,
276
+ crumbs: [{ name: "工作区", path: PICKER_ROOT, hidden: false }],
277
+ entries,
278
+ truncated: false,
279
+ };
280
+ }
281
+ /**
282
+ * The WSL branch: one row per installed distro. `path` is the preferred
283
+ * distro's root rather than the share root, so adopting the level with
284
+ * nothing selected still yields a real directory.
245
285
  *
246
286
  * @param signal - optional cancellation.
247
- * @returns the root listing.
287
+ * @returns the distro listing.
248
288
  */
249
- async rootLevel(signal) {
289
+ async distroLevel(signal) {
250
290
  const distros = await this.distros(signal);
251
291
  const preferred = await this.preferredDistro(signal);
252
- const entries = [];
253
- if (this.config.includeHostHome) {
254
- const hostHome = homedir();
255
- entries.push({ name: hostHome, path: hostHome, hidden: false });
256
- }
257
- for (const distro of distros)
258
- entries.push({ name: distro, path: distroRoot(distro), hidden: false });
292
+ const entries = distros.map((distro) => ({
293
+ name: distro,
294
+ path: distroRoot(distro),
295
+ hidden: false,
296
+ }));
259
297
  const home = preferred.length > 0 ? await this.homeOf(preferred, signal) : homedir();
260
298
  return {
261
299
  path: preferred.length > 0 ? distroRoot(preferred) : homedir(),
262
300
  home,
263
- crumbs: [{ name: "WSL", path: UNC_PROVIDER_ROOT, hidden: false }],
301
+ crumbs: [
302
+ { name: "工作区", path: PICKER_ROOT, hidden: false },
303
+ { name: "WSL 发行版", path: UNC_PROVIDER_ROOT, hidden: false },
304
+ ],
305
+ entries,
306
+ truncated: false,
307
+ };
308
+ }
309
+ /**
310
+ * The Windows branch: the host's drive roots, so the walk starts at every
311
+ * volume rather than at one account's home.
312
+ *
313
+ * @returns the drive listing.
314
+ */
315
+ async driveLevel() {
316
+ const entries = [];
317
+ for (const letter of "CDEFGHIJKLMNOPQRSTUVWXYZ") {
318
+ const path = `${letter}:\\`;
319
+ try {
320
+ await stat(path);
321
+ }
322
+ catch {
323
+ continue;
324
+ }
325
+ entries.push({ name: path, path, hidden: false });
326
+ }
327
+ const home = homedir();
328
+ return {
329
+ path: home,
330
+ home,
331
+ crumbs: [
332
+ { name: "工作区", path: PICKER_ROOT, hidden: false },
333
+ { name: "Windows 路径", path: HOST_ROOT, hidden: false },
334
+ ],
264
335
  entries,
265
336
  truncated: false,
266
337
  };
267
338
  }
268
339
  /**
269
- * Breadcrumb rows for a level, headed by the WSL row.
340
+ * Breadcrumb rows for a level: the category root, its world, then the path.
270
341
  *
271
342
  * @param target - the directory being listed.
272
343
  * @returns breadcrumb rows.
273
344
  */
274
345
  crumbsFor(target) {
275
- return breadcrumbs(target, UNC_PROVIDER_ROOT);
346
+ return breadcrumbs(target, PICKER_ROOTS);
276
347
  }
277
348
  /**
278
349
  * List one directory level.
279
350
  *
280
- * @param path - absolute directory; absent or the share root lists the distros.
351
+ * @param path - absent, the picker root or the WSL share root selects a
352
+ * virtual level (categories, distros or drives); anything else is a real
353
+ * directory.
281
354
  * @param signal - caller lifetime.
282
355
  * @returns the level's listing with its ancestry.
283
356
  * @throws DirectoryPickerError with code `directory-unreadable`.
284
357
  */
285
358
  async list(path, signal) {
286
- if (path === void 0 || isProviderRoot(path))
287
- return this.rootLevel(signal);
359
+ // Sentinel comparison trims trailing separators; the real-path branch keeps
360
+ // the spelling it was given — `C:\` must stay a volume root, not `C:`.
361
+ const sentinel = path === undefined ? "" : path.replace(/[\\/]+$/, "");
362
+ if (path === undefined || sentinel === "" || sentinel === PICKER_ROOT)
363
+ return this.categoryLevel(signal);
364
+ if (sentinel === HOST_ROOT)
365
+ return this.driveLevel();
366
+ if (isProviderRoot(sentinel))
367
+ return this.distroLevel(signal);
288
368
  if (!fullyQualified(path)) {
289
369
  throw new DirectoryPickerError("directory-unreadable", path, `cannot list "${path}": not a fully qualified path`);
290
370
  }
@@ -14,8 +14,9 @@
14
14
  * The same probes also run once at plugin load (`startup`, on by default) so an
15
15
  * install-plus-restart already carries the verdict in the log — the pinned or
16
16
  * WSL-default distro — before the first session opens. A session on that distro
17
- * repeats only the runtime-context entry; other distros keep the session-open
18
- * check unchanged.
17
+ * repeats only a failing verdict as the runtime-context entry; a ready verdict
18
+ * stays in the log, because "the prerequisite is usable" is not an action the
19
+ * model needs to take. Other distros keep the session-open check unchanged.
19
20
  *
20
21
  * Advisory by construction. A preflight that cannot run (no WSL, a wedged
21
22
  * `wsl.exe`) degrades to a log line; it must never fail a session that has not
@@ -55,7 +56,8 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
55
56
  * against the pinned or WSL-default distro, so the verdict is in the log
56
57
  * before any session opens. Sessions on other distros are still checked at
57
58
  * open, and a session announcement for a message the load pass already
58
- * logged skips the duplicate log line but keeps its runtime-context entry.
59
+ * logged skips the duplicate log line; a failing verdict still lands as the
60
+ * session's runtime-context entry.
59
61
  */
60
62
  startup: z<boolean, boolean, "defined">;
61
63
  }>>, Schemastery.ObjectT<NoInfer<{
@@ -81,7 +83,8 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
81
83
  * against the pinned or WSL-default distro, so the verdict is in the log
82
84
  * before any session opens. Sessions on other distros are still checked at
83
85
  * open, and a session announcement for a message the load pass already
84
- * logged skips the duplicate log line but keeps its runtime-context entry.
86
+ * logged skips the duplicate log line; a failing verdict still lands as the
87
+ * session's runtime-context entry.
85
88
  */
86
89
  startup: z<boolean, boolean, "defined">;
87
90
  }>>, "plain">;
package/lib/preflight.js CHANGED
@@ -14,8 +14,9 @@
14
14
  * The same probes also run once at plugin load (`startup`, on by default) so an
15
15
  * install-plus-restart already carries the verdict in the log — the pinned or
16
16
  * WSL-default distro — before the first session opens. A session on that distro
17
- * repeats only the runtime-context entry; other distros keep the session-open
18
- * check unchanged.
17
+ * repeats only a failing verdict as the runtime-context entry; a ready verdict
18
+ * stays in the log, because "the prerequisite is usable" is not an action the
19
+ * model needs to take. Other distros keep the session-open check unchanged.
19
20
  *
20
21
  * Advisory by construction. A preflight that cannot run (no WSL, a wedged
21
22
  * `wsl.exe`) degrades to a log line; it must never fail a session that has not
@@ -60,12 +61,22 @@ export const Config = z.object({
60
61
  * against the pinned or WSL-default distro, so the verdict is in the log
61
62
  * before any session opens. Sessions on other distros are still checked at
62
63
  * open, and a session announcement for a message the load pass already
63
- * logged skips the duplicate log line but keeps its runtime-context entry.
64
+ * logged skips the duplicate log line; a failing verdict still lands as the
65
+ * session's runtime-context entry.
64
66
  */
65
67
  startup: z.boolean().default(true),
66
68
  });
67
69
  /** Distros whose stale-scope sweep has already run in this process. */
68
70
  const sweptDistros = new Set();
71
+ /** The one instruction a blocked remedy needs; the model must not install packages unasked. */
72
+ const OPERATOR = "operator action: ask the user before running a remedy";
73
+ /**
74
+ * Mark a blocked verdict's remedy as user-owned action.
75
+ *
76
+ * @param message - the composed problem and remedy.
77
+ * @returns the model-facing sentence.
78
+ */
79
+ const blocked = (message) => `${message.replace(/[.\s]+$/u, "")} (${OPERATOR}).`;
69
80
  /**
70
81
  * Stop `dsh-wsl-*.scope` units a crashed app left behind. A scope is stale
71
82
  * when its cgroup has no `wsl-agent.sh`; a live agent means another session
@@ -99,18 +110,20 @@ export async function apply(ctx, config = {}) {
99
110
  const wslPath = config.wslPath ?? "wsl.exe";
100
111
  const warn = (message) => ctx.logger?.warn?.(message);
101
112
  /**
102
- * Publish one advisory: the log line always, plus — when the harness exposes
103
- * the agent's `systemPrompt` — a session-scoped runtime-context entry, so the
104
- * warning is visible to the session instead of only in the app log. DSH
105
- * 0.2.1 has no toast/notice seam; docs/UPSTREAM-SESSION-NOTICE.md records the
106
- * ask, and the runtime context is the available visible channel today.
113
+ * Publish one advisory: the log line always, plus — when the verdict is
114
+ * blocked and the harness exposes the agent's `systemPrompt` — a
115
+ * session-scoped runtime-context entry, so the failure is visible to the
116
+ * session instead of only in the app log. A ready verdict is log-only: it is
117
+ * not an action and does not belong in the model's context.
107
118
  *
108
119
  * @param agent - the session that just opened.
109
120
  * @param message - the advisory, remedy included.
110
- * @param level - `warn` for a blocked environment (the historical shape); `info` for the ready line, which is confirmation, not a complaint.
121
+ * @param level - `warn` for a blocked environment; `info` for the ready line, which is confirmation, not a complaint.
111
122
  */
112
123
  const announce = (agent, message, level = "warn") => {
113
124
  announceLog(message, level);
125
+ if (level !== "warn")
126
+ return;
114
127
  const agentCtx = agent.ctx;
115
128
  if (agentCtx === undefined || typeof agentCtx.inject !== "function")
116
129
  return;
@@ -123,7 +136,7 @@ export async function apply(ctx, config = {}) {
123
136
  ctx.logger?.debug?.(`wsl-preflight: could not publish the notice to the session (${error?.message ?? error})`);
124
137
  }
125
138
  };
126
- /** Messages the load pass already logged; a session announcement repeats only the entry. */
139
+ /** Messages the load pass already logged; a session announcement repeats only a blocked entry. */
127
140
  const startupLogged = new Set();
128
141
  /**
129
142
  * The log-only half of {@link announce}: a blocked environment warns, a ready
@@ -183,14 +196,14 @@ export async function apply(ctx, config = {}) {
183
196
  const flight = (async () => {
184
197
  const usable = await bwrapUsable({ wslPath, distro });
185
198
  if (!usable) {
186
- return { message: `wsl-preflight: ${bwrapFailure(wslPath, distro) ?? missingBwrapRemedy(distro)}`, level: "warn" };
199
+ return { message: blocked(`wsl-preflight: ${bwrapFailure(wslPath, distro) ?? missingBwrapRemedy(distro)}`), level: "warn" };
187
200
  }
188
201
  if (!(config.sessionSandbox ?? true)) {
189
202
  return { message: `wsl-preflight: ready — bwrap is usable inside "${distro}" (the session scope is not checked: sessionSandbox: false)`, level: "info" };
190
203
  }
191
204
  const sessionProblem = await probeSession(distro);
192
205
  if (sessionProblem !== undefined) {
193
- return { message: `wsl-preflight: ${sessionProblem}`, level: "warn" };
206
+ return { message: blocked(`wsl-preflight: ${sessionProblem}`), level: "warn" };
194
207
  }
195
208
  return { message: `wsl-preflight: ready — bwrap and the session scope are usable inside "${distro}"`, level: "info" };
196
209
  })();
@@ -241,7 +254,8 @@ export async function apply(ctx, config = {}) {
241
254
  * The load pass: run the same probes once at mount — install + restart,
242
255
  * before any session — against the pinned or WSL-default distro, and log the
243
256
  * verdict. A session announcement for the same message then skips the
244
- * duplicate log line but keeps its runtime-context entry. Advisory like every
257
+ * duplicate log line; a blocked verdict still lands as the runtime-context
258
+ * entry. Advisory like every
245
259
  * other arm: an unreachable distro degrades to a debug line.
246
260
  */
247
261
  const startupCheck = async () => {
@@ -19,15 +19,34 @@
19
19
  * and run `pnpm run build` — the artifact under `lib/` is generated, and
20
20
  * `pnpm test` fails when it drifts.
21
21
  */
22
+ /**
23
+ * Whether a workspace lies inside one of the directories the operator opened
24
+ * for Windows access (9p) instead of the distro environment.
25
+ *
26
+ * The comparison is prefix-based on whole path segments: `\\wsl.localhost\ubuntu\a`
27
+ * matches the directory itself and everything below it, but not `…\ab`. Paths
28
+ * are Windows/UNC paths, hence case-insensitive.
29
+ *
30
+ * @param cwd - the session's workspace directory.
31
+ * @param windowsAccess - directories opened in Windows access mode.
32
+ * @returns true when this workspace opted out of the distro environment.
33
+ */
34
+ export declare function isWindowsAccessWorkspace(cwd: string, windowsAccess: readonly string[]): boolean;
22
35
  /**
23
36
  * The adoption decision.
24
37
  *
25
- * @param input - the new session's workspace, the preset it currently has, and
26
- * the registry default.
38
+ * `windowsAccess` lists directories the operator explicitly opened for Windows
39
+ * access; a session inside one of them keeps the host preset, so the choice
40
+ * survives every later session in that workspace rather than only the one the
41
+ * operator answered the dialog for.
42
+ *
43
+ * @param input - the new session's workspace, the preset it currently has, the
44
+ * registry default, and the directories reserved for Windows access.
27
45
  * @returns true when the WSL preset should be selected for this session.
28
46
  */
29
- export declare function shouldAdoptWslPreset({ cwd, current, fallback }?: {
47
+ export declare function shouldAdoptWslPreset({ cwd, current, fallback, windowsAccess }?: {
30
48
  cwd?: string;
31
49
  current?: string;
32
50
  fallback?: string;
51
+ windowsAccess?: readonly string[];
33
52
  }): boolean;