dsh-plugin-wsl-env 0.24.0 → 0.26.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 (94) hide show
  1. package/CHANGELOG.md +136 -0
  2. package/CODE_OF_CONDUCT.md +85 -0
  3. package/CODE_OF_CONDUCT.zh.md +85 -0
  4. package/CONTRIBUTING.md +19 -3
  5. package/CONTRIBUTING.zh.md +200 -0
  6. package/README.md +18 -6
  7. package/SECURITY.md +12 -0
  8. package/SECURITY.zh.md +108 -0
  9. package/SUPPORT.md +2 -0
  10. package/SUPPORT.zh.md +99 -0
  11. package/client.js +409 -8
  12. package/cordis.patch.yml +17 -0
  13. package/docs/AGENT-PROTOCOL-V7.md +2 -2
  14. package/docs/API.md +2 -0
  15. package/docs/API.zh.md +38 -0
  16. package/docs/ARCHITECTURE.md +30 -9
  17. package/docs/ARCHITECTURE.zh.md +511 -0
  18. package/docs/COMPATIBILITY.md +2 -0
  19. package/docs/COMPATIBILITY.zh.md +117 -0
  20. package/docs/CONFIGURATION.md +45 -2
  21. package/docs/CONFIGURATION.zh.md +39 -3
  22. package/docs/DIAGNOSTICS.md +12 -2
  23. package/docs/DIAGNOSTICS.zh.md +5 -1
  24. package/docs/LIMITATIONS.md +60 -9
  25. package/docs/LIMITATIONS.zh.md +45 -9
  26. package/docs/MIGRATION.md +6 -3
  27. package/docs/MIGRATION.zh.md +91 -0
  28. package/docs/PEER-PARITY.md +63 -51
  29. package/docs/PERFORMANCE.md +2 -0
  30. package/docs/PERFORMANCE.zh.md +59 -0
  31. package/docs/QUICKSTART.md +21 -6
  32. package/docs/QUICKSTART.zh.md +16 -4
  33. package/docs/README.zh.md +28 -19
  34. package/docs/RELEASING.md +19 -14
  35. package/docs/REQUIREMENTS.zh.md +6 -3
  36. package/docs/ROADMAP-1.0.md +1 -1
  37. package/docs/UPSTREAM-FILE-REFERENCE-SEAM.md +1 -1
  38. package/docs/UPSTREAM-FSIO-EXPORT.md +5 -4
  39. package/docs/UPSTREAM-OPEN-IN-APP.md +33 -11
  40. package/docs/UPSTREAM-PROMPT-ADAPTERS.md +85 -0
  41. package/docs/UPSTREAM-SESSION-NOTICE.md +7 -0
  42. package/docs/VALUE.md +146 -0
  43. package/docs/VALUE.zh.md +15 -13
  44. package/docs/root-fs-routing.md +1 -1
  45. package/lib/agent-confined.d.ts +7 -1
  46. package/lib/agent-confined.js +3 -3
  47. package/lib/auto-preset-seam.d.ts +45 -0
  48. package/lib/auto-preset-seam.js +47 -0
  49. package/lib/auto-preset.d.ts +33 -10
  50. package/lib/auto-preset.js +148 -44
  51. package/lib/bwrap.d.ts +14 -0
  52. package/lib/bwrap.js +11 -0
  53. package/lib/cwd-prompt.d.ts +41 -3
  54. package/lib/cwd-prompt.js +125 -8
  55. package/lib/doctor-live.d.ts +30 -0
  56. package/lib/doctor-live.js +37 -0
  57. package/lib/doctor-report.d.ts +50 -0
  58. package/lib/doctor-report.js +172 -0
  59. package/lib/fs-routing.d.ts +1 -1
  60. package/lib/fs-routing.js +1 -1
  61. package/lib/fs.d.ts +1 -1
  62. package/lib/fs.js +1 -1
  63. package/lib/index.d.ts +6 -1464
  64. package/lib/index.js +5 -2120
  65. package/lib/messages.d.ts +20 -1
  66. package/lib/messages.js +31 -3
  67. package/lib/open-in-app.d.ts +206 -0
  68. package/lib/open-in-app.js +300 -0
  69. package/lib/preflight.d.ts +7 -4
  70. package/lib/preflight.js +27 -13
  71. package/lib/preset-choice.d.ts +13 -0
  72. package/lib/preset-choice.js +18 -1
  73. package/lib/provider-common.d.ts +58 -0
  74. package/lib/provider-common.js +123 -0
  75. package/lib/sandbox-core.d.ts +1 -0
  76. package/lib/sandbox-core.js +4 -2
  77. package/lib/session-runtime.d.ts +7 -1
  78. package/lib/session-runtime.js +9 -2
  79. package/lib/shell.d.ts +1 -1
  80. package/lib/shell.js +1 -1
  81. package/lib/status.js +2 -1
  82. package/lib/writable-roots.d.ts +109 -0
  83. package/lib/writable-roots.js +257 -0
  84. package/lib/wsl-doctor-command.js +2 -1
  85. package/lib/wsl-doctor-tool.js +2 -2
  86. package/lib/wsl-filesystem.d.ts +692 -0
  87. package/lib/wsl-filesystem.js +897 -0
  88. package/lib/wsl-shell.d.ts +742 -0
  89. package/lib/wsl-shell.js +965 -0
  90. package/lib/wsl.d.ts +1 -1
  91. package/lib/wsl.js +1 -1
  92. package/package.json +48 -24
  93. package/scripts/doctor.mjs +1 -1
  94. package/scripts/profile-preset.mjs +17 -5
package/client.js CHANGED
@@ -48,6 +48,8 @@ window.__ModuleLoader__.load({
48
48
 
49
49
  /** The plugin's status route (checks on GET, repair on POST); the row registers this exact path. */
50
50
  const STATUS_PATH = "/api/wsl-env/status";
51
+ /** The launch route for opening a distro workspace in VS Code through Remote-WSL. */
52
+ const OPEN_IN_APP_PATH = "/api/wsl-env/open-in-app";
51
53
  /** Sidebar panel id and order: below the shipped plugin/schedule entries. */
52
54
  const PANEL_ID = "wsl-env";
53
55
  const PANEL_ORDER = 25;
@@ -107,13 +109,16 @@ window.__ModuleLoader__.load({
107
109
  && (row.ns === AUTO_PRESET_ENTRY || row.ns.endsWith("/" + AUTO_PRESET_ENTRY)));
108
110
  if (entry === undefined) return undefined;
109
111
  const configured = entry.value && Array.isArray(entry.value[WINDOWS_FIELD]) ? entry.value[WINDOWS_FIELD] : [];
110
- return { entry, paths: configured.filter((path) => typeof path === "string") };
112
+ // The row's `preset` field is the preset auto-preset adopts for distro
113
+ // workspaces; the reminder compares the session's projection against it.
114
+ const preset = entry.value && typeof entry.value.preset === "string" ? entry.value.preset : "";
115
+ return { entry, paths: configured.filter((path) => typeof path === "string"), preset };
111
116
  };
112
117
 
113
118
  /**
114
- * Read the current Windows-access paths.
119
+ * Read the current Windows-access paths and the target preset.
115
120
  * @param ctx - client root context.
116
- * @returns `{ ok: true, paths }`, or the reason the record is unavailable.
121
+ * @returns `{ ok: true, paths, preset }`, or the reason the record is unavailable.
117
122
  */
118
123
  const readAccess = async (ctx) => {
119
124
  const settings = service(ctx, "remote.settings");
@@ -121,7 +126,7 @@ window.__ModuleLoader__.load({
121
126
  const describe = await settings.describe();
122
127
  const view = accessViewOf(describe);
123
128
  if (view === undefined) return { ok: false, message: "auto-preset 配置不可写(或未装配)" };
124
- return { ok: true, paths: view.paths };
129
+ return { ok: true, paths: view.paths, preset: view.preset };
125
130
  };
126
131
 
127
132
  /**
@@ -142,6 +147,286 @@ window.__ModuleLoader__.load({
142
147
  return undefined;
143
148
  };
144
149
 
150
+ // ── The host-mode reminder ─────────────────────────────────────────────
151
+ // A distro workspace can run the host preset without the operator meaning
152
+ // to: it was recorded as Windows access (9p), the session began before
153
+ // auto-preset could switch it, or the profile composes no WSL preset. In
154
+ // each case the session runs PowerShell with 9p file access while its path
155
+ // still says "WSL"; the composer dock carries a persistent warning with the
156
+ // fix that actually applies, and the session header keeps a quiet badge after
157
+ // the warning is collapsed.
158
+
159
+ /** The preset auto-preset adopts when the row does not name one. */
160
+ const PRESET_FALLBACK = "wsl";
161
+
162
+ /**
163
+ * Whether a workspace is one of the recorded Windows-access directories or
164
+ * below one (whole-segment, case-insensitive, like the host's comparison).
165
+ * @param cwd - the session workspace.
166
+ * @param paths - the configured directories.
167
+ * @returns true when the workspace opted out of the distro environment.
168
+ */
169
+ const isWindowsAccessPath = (cwd, paths) => {
170
+ const target = normalize(cwd);
171
+ return paths.some((entry) => {
172
+ if (typeof entry !== "string" || entry.trim() === "") return false;
173
+ const base = normalize(entry);
174
+ return target === base || target.startsWith(base + "\\");
175
+ });
176
+ };
177
+
178
+ /**
179
+ * The distro a UNC workspace names.
180
+ * @param cwd - the session workspace.
181
+ * @returns the distro name, or undefined for a non-UNC path.
182
+ */
183
+ const distroOf = (cwd) => {
184
+ const match = typeof cwd === "string" ? UNC_RE.exec(cwd) : null;
185
+ return match === null ? undefined : match[1];
186
+ };
187
+
188
+ /**
189
+ * The reminder state for one session, or null when its environment is right.
190
+ * A missing projection and a matching preset both mean "nothing to say": the
191
+ * banner never guesses an environment.
192
+ * @param input - the session workspace, its projected preset, the configured
193
+ * target preset, the Windows-access list, and subagent membership.
194
+ * @returns `{ target, windowsAccess }` for a distro workspace on a non-WSL preset.
195
+ */
196
+ const hostModeOf = ({ cwd, preset, target, paths, subagent }) => {
197
+ if (subagent === true || !isWslUnc(cwd)) return null;
198
+ if (typeof preset !== "string" || preset === "" || preset === target) return null;
199
+ return { target, windowsAccess: isWindowsAccessPath(cwd, paths ?? []) };
200
+ };
201
+
202
+ /** The sessionStorage key that collapses the warning for one session. */
203
+ const dismissedKey = (sessionId) => "wsl-env.access-mode.dismissed:" + String(sessionId);
204
+
205
+ /** Reminder components that must re-read the collapse fact when it changes. */
206
+ const dismissedListeners = new Set();
207
+
208
+ /**
209
+ * Subscribe to collapse changes so a badge that is already mounted updates
210
+ * when the banner's "收起" button records the dismissal.
211
+ * @param {() => void} listener - called after the dismissal fact changes.
212
+ * @returns {() => void} the unsubscribe function.
213
+ */
214
+ const subscribeDismissed = (listener) => {
215
+ dismissedListeners.add(listener);
216
+ return () => { dismissedListeners.delete(listener); };
217
+ };
218
+
219
+ /**
220
+ * Whether the operator collapsed the reminder for this session.
221
+ * @param sessionId - the session to ask about.
222
+ * @returns true when the warning was dismissed in this browser session.
223
+ */
224
+ const readDismissed = (sessionId) => {
225
+ try {
226
+ return window.sessionStorage.getItem(dismissedKey(sessionId)) === "1";
227
+ } catch {
228
+ return false;
229
+ }
230
+ };
231
+
232
+ /**
233
+ * Collapse the reminder for this session only; a new session asks again.
234
+ * @param sessionId - the session to collapse.
235
+ */
236
+ const rememberDismissed = (sessionId) => {
237
+ try {
238
+ window.sessionStorage.setItem(dismissedKey(sessionId), "1");
239
+ } catch {
240
+ /* a browser without storage keeps the reminder visible */
241
+ }
242
+ for (const listener of dismissedListeners) listener();
243
+ };
244
+
245
+ /**
246
+ * Follow one session's host-mode state.
247
+ * @param ctx - client root context.
248
+ * @param sessionId - the active session.
249
+ * @param useSessions - the slot's session-list hook.
250
+ * @param useProjection - the slot's projection hook.
251
+ * @returns the session summary and the reminder state (null while loading or correct).
252
+ */
253
+ const useHostMode = (ctx, sessionId, useSessions, useProjection) => {
254
+ const summary = useSessions((state) => state.byId[sessionId]);
255
+ const preset = useProjection("agentPreset");
256
+ const cwd = summary?.cwd;
257
+ const [access, setAccess] = useState(null);
258
+
259
+ useEffect(() => {
260
+ let live = true;
261
+ // Read the record only when the projection already says "not the WSL
262
+ // preset": a normal distro session never pays the settings round trip.
263
+ if (!isWslUnc(cwd) || typeof preset !== "string" || preset === "" || preset === PRESET_FALLBACK) {
264
+ setAccess(null);
265
+ return () => { live = false; };
266
+ }
267
+ void (async () => {
268
+ let answer;
269
+ try {
270
+ answer = await readAccess(ctx);
271
+ } catch {
272
+ // A settings read that throws is the same "record unavailable"
273
+ // state as one that answers `ok: false`: warn visibly with the
274
+ // fallback target instead of leaving the session silent.
275
+ answer = { ok: false };
276
+ }
277
+ if (!live) return;
278
+ setAccess(answer.ok === true
279
+ ? {
280
+ target: typeof answer.preset === "string" && answer.preset !== "" ? answer.preset : PRESET_FALLBACK,
281
+ paths: answer.paths,
282
+ }
283
+ : { target: PRESET_FALLBACK, paths: [] });
284
+ })();
285
+ return () => { live = false; };
286
+ }, [cwd, preset]);
287
+
288
+ const subagent = summary?.parentId !== undefined || summary?.origin === "subagent";
289
+ return {
290
+ summary,
291
+ state: access === null
292
+ ? null
293
+ : hostModeOf({ cwd, preset, target: access.target, paths: access.paths, subagent }),
294
+ };
295
+ };
296
+
297
+ /**
298
+ * The persistent composer-dock warning for a distro workspace running the
299
+ * host environment. The primary action is the one that works for this
300
+ * session: a blank session can be switched in place; a session that already
301
+ * started a turn keeps its history, so the durable fix is the access record.
302
+ * @param props - slot standard props plus the client root context.
303
+ * @returns the warning bar, or null when the environment is right or collapsed.
304
+ */
305
+ function AccessModeBanner({ ctx, sessionId, useSessions, useProjection }) {
306
+ const { summary, state } = useHostMode(ctx, sessionId, useSessions, useProjection);
307
+ const [dismissed, setDismissed] = useState(() => readDismissed(sessionId));
308
+ const [removed, setRemoved] = useState(false);
309
+ const [busy, setBusy] = useState(false);
310
+ const [notice, setNotice] = useState(null);
311
+
312
+ useEffect(() => {
313
+ const sync = () => { setDismissed(readDismissed(sessionId)); };
314
+ sync();
315
+ setRemoved(false);
316
+ setNotice(null);
317
+ return subscribeDismissed(sync);
318
+ }, [sessionId]);
319
+
320
+ if (state === null || dismissed) return null;
321
+ const blank = summary?.blank === true;
322
+
323
+ /** Switch this blank session to the configured WSL preset, in place. */
324
+ const switchToWsl = async () => {
325
+ setBusy(true);
326
+ setNotice(null);
327
+ try {
328
+ const presets = service(ctx, "remote.agentPresets");
329
+ if (presets === undefined) throw new Error("会话服务不可用");
330
+ const answer = await presets.select(sessionId, state.target);
331
+ if (answer.ok !== true) throw new Error(answer.error?.message ?? "preset 切换失败");
332
+ // The projection flips to the WSL preset and the banner unmounts; also
333
+ // drop the recorded Windows-access path so later sessions start right.
334
+ if (state.windowsAccess && summary?.cwd !== undefined) {
335
+ const current = await readAccess(ctx);
336
+ if (current.ok === true) {
337
+ const failure = await writeAccess(ctx, current.paths.filter((entry) => !samePath(entry, summary.cwd)));
338
+ if (failure !== undefined) setNotice({ kind: "warn", text: `已切换,但写入访问方式失败:${failure}` });
339
+ }
340
+ }
341
+ } catch (error) {
342
+ setNotice({ kind: "error", text: `切换失败:${messageOf(error)}(若 WSL preset 未装配,请运行 /wsl-doctor 检查)` });
343
+ } finally {
344
+ setBusy(false);
345
+ }
346
+ };
347
+
348
+ /** Drop the recorded Windows-access directory; this session keeps its history. */
349
+ const forgetWindowsAccess = async () => {
350
+ setBusy(true);
351
+ setNotice(null);
352
+ try {
353
+ const cwd = summary?.cwd;
354
+ if (typeof cwd !== "string") throw new Error("工作目录未知");
355
+ const current = await readAccess(ctx);
356
+ if (current.ok !== true) throw new Error(current.message);
357
+ const failure = await writeAccess(ctx, current.paths.filter((entry) => !samePath(entry, cwd)));
358
+ if (failure !== undefined) throw new Error(failure);
359
+ setRemoved(true);
360
+ setNotice({ kind: "ok", text: "已记录:本工作区新开的会话将使用 WSL 模式;本会话仍保持宿主模式。" });
361
+ } catch (error) {
362
+ setNotice({ kind: "error", text: `写入失败:${messageOf(error)}` });
363
+ } finally {
364
+ setBusy(false);
365
+ }
366
+ };
367
+
368
+ const collapse = () => {
369
+ rememberDismissed(sessionId);
370
+ setDismissed(true);
371
+ };
372
+
373
+ return h(
374
+ "div",
375
+ { role: "status", style: styles.accessBanner },
376
+ h(
377
+ "div",
378
+ { style: styles.accessBannerBody },
379
+ h("div", { style: styles.accessBannerTitle }, "当前会话运行在 Windows 宿主模式"),
380
+ h("div", { style: styles.accessBannerText },
381
+ `此工作区在 WSL 发行版 ${distroOf(summary?.cwd) ?? "WSL"} 内,但没有使用 WSL 环境:命令走 Windows PowerShell,文件访问经 9p 共享,没有 Linux 工具链。`,
382
+ state.windowsAccess ? "该目录记录为“Windows 访问”。" : null),
383
+ notice === null ? null : h(
384
+ "div",
385
+ { style: notice.kind === "ok" ? styles.noticeOk : styles.notice },
386
+ notice.text,
387
+ ),
388
+ ),
389
+ h(
390
+ "div",
391
+ { style: styles.accessBannerActions },
392
+ blank && !busy
393
+ ? h(Btn, { label: "切换为 WSL 模式", primary: true, onClick: () => { void switchToWsl(); } })
394
+ : null,
395
+ !blank && state.windowsAccess && !removed && !busy
396
+ ? h(Btn, { label: "以后用 WSL 打开", onClick: () => { void forgetWindowsAccess(); } })
397
+ : null,
398
+ !blank && !state.windowsAccess
399
+ ? h("span", { style: styles.hint }, "本会话已固定为宿主模式;新建会话时选择 WSL 模式。")
400
+ : null,
401
+ h(Btn, { label: "收起", small: true, onClick: collapse }),
402
+ ),
403
+ );
404
+ }
405
+
406
+ /**
407
+ * The quiet session-header marker that survives collapsing the banner.
408
+ * @param props - slot standard props plus the client root context.
409
+ * @returns the badge, or null when the environment is right or the banner shows.
410
+ */
411
+ function AccessModeBadge({ ctx, sessionId, useSessions, useProjection }) {
412
+ const { summary, state } = useHostMode(ctx, sessionId, useSessions, useProjection);
413
+ const [dismissed, setDismissed] = useState(() => readDismissed(sessionId));
414
+ useEffect(() => {
415
+ const sync = () => { setDismissed(readDismissed(sessionId)); };
416
+ sync();
417
+ return subscribeDismissed(sync);
418
+ }, [sessionId]);
419
+ if (state === null || !dismissed) return null;
420
+ return h(
421
+ "span",
422
+ {
423
+ style: styles.accessBadge,
424
+ title: `此工作区在 WSL 发行版 ${distroOf(summary?.cwd) ?? "WSL"} 内,但当前会话运行在 Windows 宿主模式(PowerShell、9p 共享,没有 Linux 工具链)。`,
425
+ },
426
+ "WSL工作区正以Windows模式打开",
427
+ );
428
+ }
429
+
145
430
  /**
146
431
  * Switch one workspace's still-blank sessions to the host default preset.
147
432
  * @param ctx - client root context.
@@ -226,6 +511,35 @@ window.__ModuleLoader__.load({
226
511
  repair: { fontSize: 12, wordBreak: "break-word" },
227
512
  failure: { fontSize: 12, opacity: 0.85, wordBreak: "break-word" },
228
513
  warning: { fontSize: 12, opacity: 0.75, wordBreak: "break-word" },
514
+ accessBanner: {
515
+ display: "flex",
516
+ alignItems: "flex-start",
517
+ gap: 10,
518
+ margin: "0 12px 8px",
519
+ padding: "8px 12px",
520
+ borderRadius: 8,
521
+ border: "1px solid rgba(224, 176, 74, 0.55)",
522
+ background: "rgba(224, 176, 74, 0.12)",
523
+ fontSize: 12,
524
+ lineHeight: 1.45,
525
+ pointerEvents: "auto",
526
+ },
527
+ accessBannerBody: { flex: 1, minWidth: 0, display: "flex", flexDirection: "column", gap: 3 },
528
+ accessBannerTitle: { fontWeight: 600 },
529
+ accessBannerText: { opacity: 0.85, wordBreak: "break-word" },
530
+ accessBannerActions: { display: "flex", alignItems: "center", gap: 6, flexWrap: "wrap", justifyContent: "flex-end" },
531
+ accessBadge: {
532
+ display: "inline-flex",
533
+ alignItems: "center",
534
+ padding: "1px 8px",
535
+ borderRadius: 999,
536
+ fontSize: 11,
537
+ border: "1px solid rgba(224, 176, 74, 0.55)",
538
+ background: "rgba(224, 176, 74, 0.12)",
539
+ color: "#e0b04a",
540
+ whiteSpace: "nowrap",
541
+ cursor: "default",
542
+ },
229
543
  code: { fontFamily: "var(--dsh-font-family-code, ui-monospace, monospace)", opacity: 0.9 },
230
544
  fixableTag: { fontSize: 11, color: "#5ecf86", marginLeft: 4, marginRight: 4 },
231
545
  summary: { display: "flex", flexDirection: "column", gap: 3, fontSize: 12 },
@@ -588,14 +902,27 @@ window.__ModuleLoader__.load({
588
902
  // ── The panel ──────────────────────────────────────────────────────────
589
903
 
590
904
  /**
591
- * The WSL environment page: the installed distros and their quick verdicts.
905
+ * The WSL environment page: the installed distros, their quick verdicts, and
906
+ * the directories recorded for Windows access.
907
+ * @param props - the client root context.
592
908
  * @returns the page element.
593
909
  */
594
- function WslPanel() {
910
+ function WslPanel({ ctx }) {
595
911
  const [phase, setPhase] = useState("loading");
596
912
  const [distros, setDistros] = useState([]);
597
913
  const [checks, setChecks] = useState({});
598
914
  const [notice, setNotice] = useState(null);
915
+ const [accessPaths, setAccessPaths] = useState(null);
916
+
917
+ /** Re-read the Windows-access record (best effort; the panel still works without it). */
918
+ const loadAccessPaths = async () => {
919
+ try {
920
+ const current = await readAccess(ctx);
921
+ setAccessPaths(current.ok === true ? current.paths : []);
922
+ } catch {
923
+ setAccessPaths([]);
924
+ }
925
+ };
599
926
 
600
927
  /**
601
928
  * Re-check one already-running distro without the user asking. The row
@@ -656,6 +983,7 @@ window.__ModuleLoader__.load({
656
983
  // The first load may refresh stored results for running distros; the
657
984
  // manual 刷新 button only re-reads the list.
658
985
  void loadDistros(true);
986
+ void loadAccessPaths();
659
987
  }, []);
660
988
 
661
989
  const check = async (distro) => {
@@ -722,7 +1050,7 @@ window.__ModuleLoader__.load({
722
1050
  actions: h(Btn, {
723
1051
  label: "刷新",
724
1052
  small: true,
725
- onClick: () => { void loadDistros(false); },
1053
+ onClick: () => { void loadDistros(false); void loadAccessPaths(); },
726
1054
  }),
727
1055
  },
728
1056
  h(
@@ -813,6 +1141,31 @@ window.__ModuleLoader__.load({
813
1141
  );
814
1142
  }),
815
1143
  ),
1144
+ // The audit half of the reminder: the directories whose sessions keep
1145
+ // the host preset. The composer banner is the moment-of-use warning;
1146
+ // this list is how the choice stays visible after it is collapsed.
1147
+ h(
1148
+ Card,
1149
+ { title: "Windows 访问工作区" },
1150
+ accessPaths === null
1151
+ ? h("div", { style: styles.empty }, "加载中…")
1152
+ : accessPaths.length === 0
1153
+ ? h("div", { style: styles.empty }, "没有以 Windows 访问方式打开的发行版目录。")
1154
+ : accessPaths.map((path) => h(
1155
+ "div",
1156
+ { key: path, style: styles.row },
1157
+ h(
1158
+ "div",
1159
+ { style: styles.rowHead },
1160
+ h("span", { style: styles.rowName, title: path }, path),
1161
+ ),
1162
+ )),
1163
+ h(
1164
+ "div",
1165
+ { style: styles.hint },
1166
+ "这些发行版目录按 Windows 共享(9p)打开:其中的会话保留宿主 preset,命令走 PowerShell,没有 Linux 工具链;会话内的常驻警示条可一键切回 WSL 模式。此列表存放在 auto-preset 的 windowsWorkspaces 中,也可在设置里修改。",
1167
+ ),
1168
+ ),
816
1169
  ),
817
1170
  );
818
1171
  }
@@ -1003,7 +1356,23 @@ window.__ModuleLoader__.load({
1003
1356
  ctx.slots.inject("main", function* () {
1004
1357
  yield ctx.slots.register(
1005
1358
  { name: "main", key: PANEL_ID },
1006
- () => h(WslPanel),
1359
+ () => h(WslPanel, { ctx }),
1360
+ );
1361
+ });
1362
+ // The host-mode reminder rides the composer dock (a list slot above the
1363
+ // composer, alongside the shipped queue/todo/goal docks), so it is
1364
+ // visible for the whole conversation without shadowing shipped UI; the
1365
+ // session header keeps a quiet badge after it is collapsed.
1366
+ ctx.slots.inject("conversation.input.dock", function* () {
1367
+ yield ctx.slots.register(
1368
+ { name: "conversation.input.dock", id: "wsl-env.access-mode", order: 90 },
1369
+ (props) => h(AccessModeBanner, Object.assign({}, props, { ctx })),
1370
+ );
1371
+ });
1372
+ ctx.slots.inject("conversation.session.header.utilities", function* () {
1373
+ yield ctx.slots.register(
1374
+ { name: "conversation.session.header.utilities", id: "wsl-env.access-mode-badge", order: 90 },
1375
+ (props) => h(AccessModeBadge, Object.assign({}, props, { ctx })),
1007
1376
  );
1008
1377
  });
1009
1378
  // The post-add prompt rides the frame-wide overlay seat.
@@ -1013,6 +1382,38 @@ window.__ModuleLoader__.load({
1013
1382
  () => h(AccessPrompt, { ctx }),
1014
1383
  );
1015
1384
  });
1385
+ // Session-header menu: open a distro workspace in VS Code through
1386
+ // Remote-WSL. The shipped "Open in app" item launches the same editor,
1387
+ // but a WSL UNC workspace opens there as a plain 9p folder; this route
1388
+ // builds the `vscode-remote` URI instead. The Host row also clears
1389
+ // ELECTRON_RUN_AS_NODE, so the shipped item stops failing.
1390
+ ctx.inject(["contextMenus", "sessions"], (scope) => {
1391
+ scope.effect(() => scope.contextMenus.register({
1392
+ id: "wsl-env.openInVSCode",
1393
+ target: "sessionHeader",
1394
+ order: 505,
1395
+ observe: () => [scope.sessions.list],
1396
+ resolve: ({ sessionId }) => {
1397
+ const snapshot = scope.sessions.list.getSnapshot();
1398
+ const cwd = snapshot && snapshot.byId ? snapshot.byId[sessionId]?.cwd : undefined;
1399
+ if (!isWslUnc(cwd)) return [];
1400
+ return [{
1401
+ id: "vscode",
1402
+ label: "在 VS Code 中打开(WSL)",
1403
+ failureLabel: "在 VS Code 中打开失败",
1404
+ run: async () => {
1405
+ const answer = await fetch(OPEN_IN_APP_PATH, {
1406
+ method: "POST",
1407
+ headers: { "content-type": "application/json" },
1408
+ body: JSON.stringify({ path: cwd }),
1409
+ });
1410
+ const body = await answer.json().catch(() => ({}));
1411
+ if (!answer.ok) throw new Error(body.error ?? ("打开失败(HTTP " + answer.status + ")"));
1412
+ },
1413
+ }];
1414
+ },
1415
+ }), "wsl-env: open workspace in VS Code");
1416
+ });
1016
1417
  // The workspace catalog activates independently of this module; the
1017
1418
  // prompt watcher waits for it instead of sampling a missing service.
1018
1419
  ctx.inject(["workspaces"], (scope) => {
package/cordis.patch.yml CHANGED
@@ -188,6 +188,19 @@
188
188
  - id: wsl-doctor-command
189
189
  name: 'dsh-plugin-wsl-env/wsl-doctor-command'
190
190
 
191
+ # Durable replacement for the local app.asar open-in-app patch. The row
192
+ # registers an authenticated route that scrubs ELECTRON_RUN_AS_NODE from
193
+ # the editor child's environment (never the Host's: a Host-wide deletion
194
+ # breaks Node-mode helpers such as the Windows Job runner) and launches VS
195
+ # Code with the WSL workspace's `vscode-remote` URI, so it lands in
196
+ # Remote-WSL instead of a 9p folder. The shipped "Open in app" item still
197
+ # inherits the flag and remains broken until upstream scrubs its own child.
198
+ - id: wsl-open-in-app
199
+ name: 'dsh-plugin-wsl-env/open-in-app'
200
+ config:
201
+ executable: ''
202
+ watchMs: 1500
203
+
191
204
  - id: fs-routing
192
205
  name: 'dsh-plugin-wsl-env/fs-routing'
193
206
  config:
@@ -341,6 +354,8 @@
341
354
  # shipped shell agent. native fails the first command instead
342
355
  # of falling back; shell forces the shell agent.
343
356
  agentBackend: auto
357
+ # 工具链缓存等额外可写目录;默认空。示例(与 wsl-fs 配同一列表):
358
+ # writableRoots: ['~/.npm', '~/.cache', '~/.local/share/pnpm']
344
359
  - id: wsl-fs
345
360
  name: 'dsh-plugin-wsl-env/fs'
346
361
  config:
@@ -357,6 +372,8 @@
357
372
  # Confined writes ride the session runtime (ADR 0001), so they
358
373
  # share the command's real /tmp and workspace mounts.
359
374
  sessionSandbox: true
375
+ # 与 wsl-shell 的 writableRoots 保持同一列表;见 CONFIGURATION。
376
+ # writableRoots: ['~/.npm', '~/.cache', '~/.local/share/pnpm']
360
377
  - id: persona
361
378
  name: '@deepseek-ai/dsh-persona'
362
379
  config:
@@ -20,7 +20,7 @@ negotiation rule, four capabilities.
20
20
  | `delete` / `move` FS ops | new op names in the FS frame vocabulary | yes | yes | guarded, mapped to `FsDeleteOutcome` / `FsMoveOutcome` |
21
21
  | `patchText` | **no wire change** — host-side hunk application + a guarded `replace` write | n/a | n/a | hunks applied in-process via `@deepseek-ai/dsh-fs-patch` (a new peer dependency, the peer's own `applyHunks` — perfect error parity, `FS_PATCH_MISMATCH` free) |
22
22
 
23
- `PROTOCOL_VERSION` becomes 7. `@deepseek-ai/dsh-fs-patch@0.2.2-rc.1` is added
23
+ `PROTOCOL_VERSION` becomes 7. `@deepseek-ai/dsh-fs-patch@0.2.2-rc.2` is added
24
24
  to `peerDependencies` (the host imports `applyHunks` at runtime) and pinned in
25
25
  `devDependencies`.
26
26
 
@@ -131,7 +131,7 @@ the parity way:
131
131
  trip).
132
132
 
133
133
  Two round trips, zero new wire semantics, zero second implementation. The
134
- `dsh-fs-patch` peer floor is `0.2.2-rc.1`, the same line the plugin already
134
+ `dsh-fs-patch` peer floor is `0.2.2-rc.2`, the same line the plugin already
135
135
  targets.
136
136
 
137
137
  ## What breaks
package/docs/API.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # API surface
2
2
 
3
+ [中文](API.zh.md)
4
+
3
5
  The published API is the generated `lib/*.d.ts` next to each compiled module
4
6
  (`pnpm run build` keeps them byte-fresh; `lint:build` fails on drift). The
5
7
  `exports` map in `package.json` is the authority on what a consumer can import;
package/docs/API.zh.md ADDED
@@ -0,0 +1,38 @@
1
+ # API 表面
2
+
3
+ [English](API.md)
4
+
5
+ 已发布的 API 就是每个编译模块旁生成的 `lib/*.d.ts`(`pnpm run build` 保持
6
+ 其逐字节最新;`lint:build` 在发生漂移时失败)。`package.json` 中的
7
+ `exports` 映射是消费者可导入内容的权威;本页是快速导览。
8
+
9
+ | 子路径 | 导出 | 角色 |
10
+ |---|---|---|
11
+ | `.` | — | 有意为之的空操作根宿主半边:一个在裸包名处挂载的空操作插件,用于锚定其下的浏览器客户端(0.21.0 之前这里解析到执行器本身——见 `./shell`) |
12
+ | `./shell` | `WslShellExecutor` | 面向模型的 shell 执行器(`ctx.shell`),挂载在 WSL preset 的 isolate realm 内 |
13
+ | `./client` | —(无可导入表面) | harness 的 web 客户端加载器为裸包名行提供的浏览器半边:侧边栏状态面板与访问模式提示 |
14
+ | `./fs` | `WslFileSystem` | 发行版之上的文件系统提供者(`ctx.fs`) |
15
+ | `./index` | `WslShellExecutor`、`WslFileSystem`、`doctorReport`、`effectiveMaskWindowsDrive`、… | 组合根完整的具名表面——集成 API(`doctorReport` 供需要 doctor 版本化报告的工具体使用) |
16
+ | `./fs-routing` | `WslRoutingFileSystem` | 根平面坐标路由器 |
17
+ | `./wsl` | `defaultShell`、`listDistros`、`shellArgs`、`wslTerminalArgv`、… | `wsl.exe` 互操作原语 |
18
+ | `./agent` | `WslAgent` | 常驻 agent 传输层 |
19
+ | `./subprocess` | `WslSubprocessRuntime` | 终端/子进程运行时 |
20
+ | `./preflight` | `wsl-preflight` 行 | 会话启动提示(以及在插件加载时以 `startup: true` 执行一次) |
21
+ | `./cwd-prompt` | `wsl-cwd-prompt` 行 | 将运行时上下文的工作目录改写为发行版的 POSIX 形式 |
22
+ | `./cwd-prompt-tool` | `wsl-cwd-prompt-tool` 行 | 为模型的读取/`cd` 工具提供以发行版 POSIX 形式表示的 `cwd` 输出 |
23
+ | `./file-reference-wsl` | `traversalArgv`、`parseTraversalListing`、`FileReferenceTraversal`、… | 用于 `@` 补全的发行版侧遍历策略(纯库——已构建并测试,尚未接入行;见 ARCHITECTURE) |
24
+ | `./wsl-doctor-tool` | `wsl-doctor-tool` 行 | `wsl_doctor` 模型工具:带作用域(`depth`、`section`)的进程内诊断 |
25
+ | `./wsl-doctor-command` | `wsl-doctor-command` 行 | `/wsl-doctor` UI 命令:启动独立 doctor CLI,渲染结果不进入模型历史 |
26
+ | `./status` | `wsl-status` 行 | 侧栏面板经 `/api` 的路由:已安装发行版、单个发行版的快速 doctor,以及 `--fix-owned` 完整运行(可修复时修复,否则完整检查);最近结果跨重载保留,运行中发行版的已存结果在后台刷新 |
27
+ | `./paths` | `uncToPosix`、`toLinuxPath`、`toWorldPath`、… | 坐标映射器 |
28
+ | `./picker` | `WslDirectoryPicker` | 能感知发行版的目录选择器 |
29
+ | `./auto-preset` | `auto-preset` 行 | 首次运行的 profile 引导 |
30
+ | `./shell-env` | `wsl-shell-env` 行 | `DSH_WSL_*` 事实注册表 |
31
+ | `./update-check` | `wsl-update-check` 行 | 每天一次的更新提示(事实存储 + 委托宿主的检查) |
32
+
33
+ `./<name>/locale/*.json` 子路径承载 Plugins 页面的显示元数据和运行时消息
34
+ 目录;`./package.json` 重新导出 manifest。
35
+
36
+ 稳定性:工具名和错误码属于 API([MIGRATION.zh.md](MIGRATION.zh.md));
37
+ 运行时行的配置键记录在
38
+ [CONFIGURATION.zh.md](CONFIGURATION.zh.md) 中。