dsh-wsl-workspace 0.1.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.
package/lib/client.js ADDED
@@ -0,0 +1,982 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "dsh-wsl-workspace",
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
+ let react = require("react");
8
+ let react_jsx_runtime = require("react/jsx-runtime");
9
+ //#region src/client/api.ts
10
+ /**
11
+ * Thin fetch client for the Host plugin route. The browser calls
12
+ * POST /wsl-workspace/api with a `{ method, params }` envelope and the Host
13
+ * answers `{ ok: true, value }` or `{ ok: false, error }`.
14
+ */
15
+ /** Relative route the Host half registers (same-origin with the web server). */
16
+ const ENDPOINT = "/wsl-workspace/api";
17
+ /** Human text for an unknown rejection, reusing the repository's idiom. */
18
+ function errorMessage(value) {
19
+ return value instanceof Error ? value.message : String(value);
20
+ }
21
+ /**
22
+ * Perform one POST call and unwrap the envelope.
23
+ * @param method - the Host method name.
24
+ * @param params - the method payload.
25
+ * @returns the unwrapped value, or throws an Error on network or `ok:false`.
26
+ */
27
+ async function call(method, params = {}) {
28
+ let response;
29
+ try {
30
+ response = await fetch(ENDPOINT, {
31
+ method: "POST",
32
+ headers: { "content-type": "application/json" },
33
+ body: JSON.stringify({
34
+ method,
35
+ params
36
+ })
37
+ });
38
+ } catch (error) {
39
+ throw new Error(`wsl-workspace request failed: ${errorMessage(error)}`);
40
+ }
41
+ let envelope;
42
+ try {
43
+ envelope = await response.json();
44
+ } catch {
45
+ throw new Error(`wsl-workspace answered non-JSON (${response.status})`);
46
+ }
47
+ if (!envelope.ok) throw new Error(envelope.error);
48
+ return envelope.value;
49
+ }
50
+ /**
51
+ * List the WSL distros installed on the host.
52
+ * @returns distro names in registry order.
53
+ */
54
+ async function listDistros() {
55
+ return call("listDistros", {});
56
+ }
57
+ /**
58
+ * List one directory level inside a distro.
59
+ * @param distro - distro name.
60
+ * @param path - absolute Linux directory to list.
61
+ * @returns the level's listing with ancestry.
62
+ */
63
+ async function listDir(distro, path) {
64
+ return call("listDir", {
65
+ distro,
66
+ path
67
+ });
68
+ }
69
+ /**
70
+ * Check whether a Linux path exists and is a directory.
71
+ * @param distro - distro name.
72
+ * @param path - absolute Linux path.
73
+ * @returns existence and directory facts.
74
+ */
75
+ async function check(distro, path) {
76
+ return call("check", {
77
+ distro,
78
+ path
79
+ });
80
+ }
81
+ /**
82
+ * Store (or clear, with an empty string) the username of one WSL workspace.
83
+ * @param path - the workspace UNC path.
84
+ * @param username - the Linux username; empty string clears the stored value.
85
+ */
86
+ async function setWorkspaceUser(path, username) {
87
+ return call("setUser", {
88
+ path,
89
+ username
90
+ });
91
+ }
92
+ //#endregion
93
+ //#region src/shared/paths.ts
94
+ /** The two UNC hosts WSL exposes a distribution's filesystem under. */
95
+ const UNC_HOSTS = ["wsl.localhost", "wsl$"];
96
+ /**
97
+ * Parse a WSL UNC path into its distro and Linux path. Accepts the WSL2
98
+ * `\\wsl.localhost\<distro>\<linux>` form, the legacy `\\wsl$\<distro>\<linux>`
99
+ * interop form, and forward-slash spellings of either.
100
+ * @param raw - candidate absolute path.
101
+ * @returns the parsed target, or null when the path is not a WSL UNC.
102
+ */
103
+ function parseWslUnc(raw) {
104
+ const normalized = raw.replace(/\\/g, "/").replace(/\/\/+/g, "//");
105
+ if (!normalized.startsWith("//")) return null;
106
+ const segments = normalized.slice(2).split("/");
107
+ const host = (segments[0] ?? "").toLowerCase();
108
+ if (!UNC_HOSTS.includes(host)) return null;
109
+ const distro = segments[1] ?? "";
110
+ if (distro === "") return null;
111
+ return {
112
+ distro,
113
+ linuxPath: `/${segments.slice(2).filter((segment) => segment.length > 0).join("/")}`
114
+ };
115
+ }
116
+ /**
117
+ * Whether a path resolves into a WSL distro through either UNC form.
118
+ * @param raw - candidate absolute path.
119
+ * @returns whether the path parses as a WSL UNC.
120
+ */
121
+ function isWslUnc(raw) {
122
+ return parseWslUnc(raw) !== null;
123
+ }
124
+ /**
125
+ * Normalize a Linux absolute path for the Host: collapse repeated slashes and
126
+ * strip a trailing slash (root becomes `/`).
127
+ * @param path - absolute Linux path.
128
+ * @returns the normalized path.
129
+ */
130
+ function normalizeLinuxPath(path) {
131
+ const collapsed = path.replace(/\/+/g, "/");
132
+ return collapsed === "/" ? "/" : collapsed.replace(/\/$/, "");
133
+ }
134
+ /**
135
+ * Whether a path is an absolute, non-empty Linux path.
136
+ * @param path - candidate.
137
+ * @returns whether it starts with `/` and contains no NUL.
138
+ */
139
+ function isAbsoluteLinuxPath(path) {
140
+ return path.startsWith("/") && !path.includes("\0");
141
+ }
142
+ /**
143
+ * Join a distro and a Linux absolute path into the WSL2 UNC form used as the
144
+ * workspace identity (`\\wsl.localhost\<distro>\<linux>`, backslash segments).
145
+ * @param distro - distro name.
146
+ * @param linuxPath - absolute Linux path (leading `/`).
147
+ * @returns the UNC path.
148
+ */
149
+ function joinUnc(distro, linuxPath) {
150
+ if (!isAbsoluteLinuxPath(linuxPath)) throw new Error(`wsl-workspace: cannot map a non-absolute Linux path "${linuxPath}" to UNC`);
151
+ if (distro === "" || distro === "." || distro === ".." || /[\\/]/.test(distro)) throw new Error(`wsl-workspace: invalid distribution name "${distro}"`);
152
+ const normalized = linuxPath.replace(/\/+/g, "/").replace(/\/$/, "");
153
+ const windowsSegments = (normalized.startsWith("/") ? normalized.slice(1) : normalized).replace(/\//g, "\\");
154
+ return `\\\\wsl.localhost\\${distro}${windowsSegments === "" ? "" : `\\${windowsSegments}`}`;
155
+ }
156
+ /** Linux username shape for `wsl.exe -u`: starts with a letter or underscore, then letters/digits/`_`/`.`/`-` (max 64). */
157
+ const WSL_USERNAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_.-]{0,63}$/;
158
+ /**
159
+ * Whether a value is a safe Linux username for `wsl.exe -u`. The check is
160
+ * strict on purpose: a value starting with `-` could be parsed as a wsl.exe
161
+ * option instead of a username.
162
+ * @param value - candidate username.
163
+ * @returns whether it matches the Linux username shape.
164
+ */
165
+ function isValidWslUsername(value) {
166
+ return WSL_USERNAME_PATTERN.test(value);
167
+ }
168
+ //#endregion
169
+ //#region src/client/AddWslWorkspace.tsx
170
+ /**
171
+ * Build the Linux child path one level below a parent, for the breadcrumb/
172
+ * browse drill.
173
+ * @param parent - the currently listed absolute path (`/` for root).
174
+ * @param name - the child directory name.
175
+ * @returns the child's absolute Linux path.
176
+ */
177
+ function dirChildPath(parent, name) {
178
+ return parent === "/" ? `/${name}` : `${parent}/${name}`;
179
+ }
180
+ /** A tiny inline terminal glyph for the dialog's directory rows. */
181
+ function WslGlyph({ size = 16 }) {
182
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
183
+ width: size,
184
+ height: size,
185
+ viewBox: "0 0 24 24",
186
+ fill: "none",
187
+ "aria-hidden": "true",
188
+ children: [
189
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
190
+ x: "2.5",
191
+ y: "4.5",
192
+ width: "19",
193
+ height: "15",
194
+ rx: "2.5",
195
+ stroke: "currentColor",
196
+ strokeWidth: "1.6"
197
+ }),
198
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
199
+ d: "M6 9l3.2 2.6L6 14",
200
+ stroke: "currentColor",
201
+ strokeWidth: "1.6",
202
+ strokeLinecap: "round",
203
+ strokeLinejoin: "round"
204
+ }),
205
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
206
+ d: "M12 14h5",
207
+ stroke: "currentColor",
208
+ strokeWidth: "1.6",
209
+ strokeLinecap: "round"
210
+ })
211
+ ]
212
+ });
213
+ }
214
+ /**
215
+ * The "Add WSL workspace…" footer action and its dialog.
216
+ * @param props - owner share + injected face.
217
+ */
218
+ function AddWslWorkspace({ wide, t, checkPreset, listDistros, listDir, check, createWorkspace }) {
219
+ const [open, setOpen] = (0, react.useState)(false);
220
+ const [opening, setOpening] = (0, react.useState)(false);
221
+ const [distros, setDistros] = (0, react.useState)([]);
222
+ const [distro, setDistro] = (0, react.useState)("");
223
+ const [pathInput, setPathInput] = (0, react.useState)("/home/");
224
+ const [username, setUsername] = (0, react.useState)("");
225
+ const [listing, setListing] = (0, react.useState)(null);
226
+ const [browsePath, setBrowsePath] = (0, react.useState)("/");
227
+ const [browsing, setBrowsing] = (0, react.useState)(false);
228
+ const [error, setError] = (0, react.useState)(null);
229
+ const [busy, setBusy] = (0, react.useState)(false);
230
+ const browseSeq = (0, react.useRef)(0);
231
+ const refreshBrowse = async (root, targetDistro) => {
232
+ const seq = ++browseSeq.current;
233
+ setBrowsing(true);
234
+ setBrowsePath(root);
235
+ try {
236
+ const value = await listDir(targetDistro, root);
237
+ if (seq === browseSeq.current) setListing(value);
238
+ } catch {
239
+ if (seq === browseSeq.current) {
240
+ setListing(null);
241
+ setError((previous) => previous ?? t("error.loadDir"));
242
+ }
243
+ } finally {
244
+ if (seq === browseSeq.current) setBrowsing(false);
245
+ }
246
+ };
247
+ (0, react.useEffect)(() => {
248
+ if (!open) return;
249
+ let cancelled = false;
250
+ setError(null);
251
+ setOpening(true);
252
+ (async () => {
253
+ let presetIssue;
254
+ try {
255
+ presetIssue = await checkPreset();
256
+ } catch {
257
+ presetIssue = t("error.loadDistros");
258
+ }
259
+ let names;
260
+ try {
261
+ names = await listDistros();
262
+ } catch {
263
+ if (cancelled) return;
264
+ setOpening(false);
265
+ setError(t("error.loadDistros"));
266
+ return;
267
+ }
268
+ if (cancelled) return;
269
+ setDistros(names);
270
+ const first = names[0] ?? "";
271
+ setDistro(first);
272
+ setBrowsing(true);
273
+ setOpening(false);
274
+ if (presetIssue !== void 0) setError(presetIssue);
275
+ if (first !== "") refreshBrowse("/", first);
276
+ })();
277
+ return () => {
278
+ cancelled = true;
279
+ };
280
+ }, [open]);
281
+ (0, react.useEffect)(() => {
282
+ if (!open) return;
283
+ const onKey = (event) => {
284
+ if (event.key === "Escape" && !busy) setOpen(false);
285
+ };
286
+ window.addEventListener("keydown", onKey);
287
+ return () => window.removeEventListener("keydown", onKey);
288
+ }, [open, busy]);
289
+ if (!open) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
290
+ type: "button",
291
+ className: wide ? "dww-action dww-action--wide" : "dww-action dww-action--rail",
292
+ title: t("action.title"),
293
+ "aria-label": t("action.title"),
294
+ onClick: () => setOpen(true),
295
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
296
+ className: "dww-letter",
297
+ "aria-hidden": "true",
298
+ children: "W"
299
+ })
300
+ });
301
+ const onDrill = (name) => {
302
+ const next = dirChildPath(listing?.path ?? browsePath, name);
303
+ setPathInput(next);
304
+ refreshBrowse(next, distro);
305
+ };
306
+ const onUp = () => {
307
+ const parent = listing?.parent ?? null;
308
+ if (parent === null) return;
309
+ setPathInput(parent);
310
+ refreshBrowse(parent, distro);
311
+ };
312
+ const onDistroChange = (value) => {
313
+ setDistro(value);
314
+ refreshBrowse(browsePath, value);
315
+ };
316
+ const onCheck = async () => {
317
+ const path = normalizeLinuxPath(pathInput);
318
+ setError(null);
319
+ if (!isAbsoluteLinuxPath(path) || path === "/") {
320
+ setError(t("error.invalidPath"));
321
+ return;
322
+ }
323
+ let facts;
324
+ try {
325
+ facts = await check(distro, path);
326
+ } catch {
327
+ setError(t("error.pathNotFound"));
328
+ return;
329
+ }
330
+ if (!facts.exists || !facts.isDirectory) {
331
+ setError(t("error.pathNotFound"));
332
+ return;
333
+ }
334
+ refreshBrowse(path, distro);
335
+ };
336
+ const onConfirm = async () => {
337
+ const path = normalizeLinuxPath(pathInput);
338
+ setError(null);
339
+ if (!isAbsoluteLinuxPath(path) || path === "/") {
340
+ setError(t("error.invalidPath"));
341
+ return;
342
+ }
343
+ const user = username.trim();
344
+ if (user !== "" && !isValidWslUsername(user)) {
345
+ setError(t("error.invalidUsername"));
346
+ return;
347
+ }
348
+ setBusy(true);
349
+ try {
350
+ let facts;
351
+ try {
352
+ facts = await check(distro, path);
353
+ } catch {
354
+ setError(t("error.pathNotFound"));
355
+ return;
356
+ }
357
+ if (!facts.exists || !facts.isDirectory) {
358
+ setError(t("error.pathNotFound"));
359
+ return;
360
+ }
361
+ const failure = await createWorkspace(joinUnc(distro, path), user);
362
+ if (failure !== void 0) {
363
+ setError(failure);
364
+ return;
365
+ }
366
+ setOpen(false);
367
+ } finally {
368
+ setBusy(false);
369
+ }
370
+ };
371
+ const children = (listing?.entries.filter((entry) => entry.kind === "directory") ?? []).map((entry) => entry.name);
372
+ const maskClick = () => {
373
+ if (!busy) setOpen(false);
374
+ };
375
+ const listScroll = () => {};
376
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
377
+ className: "dww-overlay",
378
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
379
+ className: "dww-overlay-mask",
380
+ onClick: maskClick
381
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
382
+ className: "dww-card",
383
+ role: "dialog",
384
+ "aria-modal": "true",
385
+ "aria-label": t("dialog.title"),
386
+ children: [
387
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
388
+ className: "dww-header",
389
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
390
+ className: "dww-title",
391
+ children: t("dialog.title")
392
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
393
+ type: "button",
394
+ className: "dww-close",
395
+ "aria-label": t("dialog.cancel"),
396
+ onClick: maskClick,
397
+ children: "✕"
398
+ })]
399
+ }),
400
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
401
+ className: "dww-body",
402
+ children: [
403
+ error !== null ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
404
+ className: "dww-error",
405
+ children: [error, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
406
+ type: "button",
407
+ className: "dww-retry",
408
+ onClick: () => setError(null),
409
+ children: t("dialog.retry")
410
+ })]
411
+ }) : null,
412
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
413
+ className: "dww-field",
414
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
415
+ className: "dww-field-label",
416
+ htmlFor: "dww-distro",
417
+ children: t("dialog.distro")
418
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("select", {
419
+ id: "dww-distro",
420
+ className: "dww-select",
421
+ value: distro,
422
+ disabled: opening || busy,
423
+ onChange: (event) => onDistroChange(event.target.value),
424
+ children: distros.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
425
+ value: "",
426
+ children: opening ? t("dialog.loading") : ""
427
+ }) : distros.map((name) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
428
+ value: name,
429
+ children: name
430
+ }, name))
431
+ })]
432
+ }),
433
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
434
+ className: "dww-field",
435
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
436
+ className: "dww-field-label",
437
+ htmlFor: "dww-path",
438
+ children: t("dialog.path")
439
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
440
+ className: "dww-input-row",
441
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
442
+ id: "dww-path",
443
+ className: "dww-input",
444
+ value: pathInput,
445
+ placeholder: t("dialog.pathPlaceholder"),
446
+ disabled: opening || busy,
447
+ onChange: (event) => setPathInput(event.target.value)
448
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
449
+ type: "button",
450
+ className: "dww-check-btn",
451
+ disabled: opening || busy,
452
+ onClick: () => void onCheck(),
453
+ children: t("dialog.check")
454
+ })]
455
+ })]
456
+ }),
457
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
458
+ className: "dww-field",
459
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
460
+ className: "dww-field-label",
461
+ htmlFor: "dww-username",
462
+ children: t("dialog.username")
463
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
464
+ id: "dww-username",
465
+ className: "dww-input",
466
+ value: username,
467
+ placeholder: t("dialog.usernamePlaceholder"),
468
+ disabled: opening || busy,
469
+ autoComplete: "off",
470
+ spellCheck: false,
471
+ onChange: (event) => setUsername(event.target.value)
472
+ })]
473
+ }),
474
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
475
+ className: "dww-feedback",
476
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
477
+ className: "dww-breadcrumb",
478
+ children: browsePath
479
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
480
+ className: "dww-dirlist",
481
+ onScroll: listScroll,
482
+ children: [browsing ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
483
+ className: "dww-dir-empty",
484
+ children: t("dialog.loading")
485
+ }) : listing?.parent !== null && listing !== null ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
486
+ type: "button",
487
+ className: "dww-dir-row dww-dir-row--up",
488
+ onClick: onUp,
489
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(WslGlyph, { size: 14 }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("dialog.upLevel") })]
490
+ }) : null, !browsing && children.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
491
+ className: "dww-dir-empty",
492
+ children: t("dialog.browseEmpty")
493
+ }) : children.map((name) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
494
+ type: "button",
495
+ className: "dww-dir-row",
496
+ onClick: () => onDrill(name),
497
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(WslGlyph, { size: 14 }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: name })]
498
+ }, name))]
499
+ })]
500
+ })
501
+ ]
502
+ }),
503
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
504
+ className: "dww-actions",
505
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
506
+ type: "button",
507
+ className: "dww-btn",
508
+ disabled: busy,
509
+ onClick: maskClick,
510
+ children: t("dialog.cancel")
511
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
512
+ type: "button",
513
+ className: "dww-btn dww-btn--primary",
514
+ disabled: busy || opening,
515
+ onClick: () => void onConfirm(),
516
+ children: busy ? t("dialog.loading") : t("dialog.confirm")
517
+ })]
518
+ })
519
+ ]
520
+ })]
521
+ });
522
+ }
523
+ //#endregion
524
+ //#region src/client/styles.ts
525
+ /**
526
+ * Third-party stylesheet injection for the WSL workspace UI (the plugin
527
+ * builds no CSS bundle, so styles are injected as one idempotent `<style>`).
528
+ * Colors derive exclusively from the `--dsw-*` design tokens.
529
+ */
530
+ const STYLE_TAG_DATA_ATTRIBUTE = "data-plugin=\"dsh-wsl-workspace\"";
531
+ const STYLES = `
532
+ /* Sidebar-foot icon action beside Settings (28px round in the wide sidebar,
533
+ 36px round in the rail), matching the shell's icon-button language. */
534
+ .dww-action {
535
+ flex: none;
536
+ display: inline-flex;
537
+ align-items: center;
538
+ justify-content: center;
539
+ width: 28px;
540
+ height: 28px;
541
+ border: none;
542
+ border-radius: 50%;
543
+ padding: 0;
544
+ background: transparent;
545
+ cursor: pointer;
546
+ color: var(--dsw-alias-label-secondary);
547
+ transition:
548
+ background-color 120ms var(--dsw-ease-in-out, ease-in-out),
549
+ color 120ms var(--dsw-ease-in-out, ease-in-out);
550
+ }
551
+ .dww-action:hover:not(:disabled) {
552
+ background: var(--dsw-alias-interactive-bg-hover);
553
+ color: var(--dsw-alias-label-secondary);
554
+ }
555
+ .dww-action:active:not(:disabled) {
556
+ background: var(--dsw-alias-interactive-bg-pressed, var(--dsw-alias-interactive-bg-hover));
557
+ }
558
+ .dww-action:focus-visible {
559
+ outline: 2px solid var(--dsw-alias-state-business-primary);
560
+ outline-offset: 1px;
561
+ }
562
+ .dww-action:disabled { cursor: default; opacity: 0.6; }
563
+ .dww-action--rail {
564
+ width: 36px;
565
+ height: 36px;
566
+ color: var(--dsw-alias-label-primary);
567
+ }
568
+ .dww-action svg { flex: none; }
569
+
570
+ /* The W letter mark of the sidebar action (sized for wide/rail buttons). */
571
+ .dww-letter {
572
+ font-size: 14px;
573
+ font-weight: 600;
574
+ line-height: 1;
575
+ letter-spacing: 0.02em;
576
+ user-select: none;
577
+ }
578
+ .dww-action--rail .dww-letter { font-size: 17px; }
579
+
580
+ /* Full-viewport overlay + centered card (mirrors the platform Mask/Dialog). */
581
+ .dww-overlay {
582
+ position: fixed;
583
+ inset: 0;
584
+ z-index: 1000;
585
+ display: flex;
586
+ align-items: center;
587
+ justify-content: center;
588
+ padding: 24px;
589
+ }
590
+ .dww-overlay-mask {
591
+ position: absolute;
592
+ inset: 0;
593
+ background: var(--dsw-alias-bg-mask-1);
594
+ backdrop-filter: var(--dsw-mask-blur);
595
+ }
596
+ .dww-card {
597
+ position: relative;
598
+ z-index: 1;
599
+ box-sizing: border-box;
600
+ display: flex;
601
+ flex-direction: column;
602
+ width: min(440px, 100%);
603
+ max-height: min(640px, 90vh);
604
+ padding: 0 0 20px;
605
+ overflow: hidden;
606
+ border: 1px solid var(--dsw-alias-border-inverted);
607
+ border-radius: 16px;
608
+ background: var(--dsw-alias-bg-layer-2);
609
+ box-shadow: var(--dsw-shadow-lv3);
610
+ font-family: var(--dsw-font-family);
611
+ }
612
+ .dww-header {
613
+ display: flex;
614
+ align-items: center;
615
+ justify-content: space-between;
616
+ gap: 8px;
617
+ padding: 18px 20px 12px;
618
+ }
619
+ .dww-title {
620
+ margin: 0;
621
+ font-size: 16px;
622
+ line-height: 24px;
623
+ font-weight: 500;
624
+ color: var(--dsw-alias-label-primary);
625
+ }
626
+ .dww-close {
627
+ flex: none;
628
+ display: inline-flex;
629
+ align-items: center;
630
+ justify-content: center;
631
+ width: 28px;
632
+ height: 28px;
633
+ border: 0;
634
+ border-radius: 8px;
635
+ background: transparent;
636
+ cursor: pointer;
637
+ color: var(--dsw-alias-label-secondary);
638
+ }
639
+ .dww-close:hover { background: var(--dsw-alias-interactive-bg-hover); }
640
+ .dww-body {
641
+ display: flex;
642
+ flex-direction: column;
643
+ gap: 14px;
644
+ min-width: 0;
645
+ padding: 0 20px;
646
+ overflow: auto;
647
+ }
648
+ .dww-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
649
+ .dww-field-label {
650
+ font-size: 12px;
651
+ line-height: 18px;
652
+ color: var(--dsw-alias-label-secondary);
653
+ }
654
+ .dww-select {
655
+ box-sizing: border-box;
656
+ width: 100%;
657
+ height: 36px;
658
+ padding: 0 10px;
659
+ border: 1px solid var(--dsw-alias-border-l2);
660
+ border-radius: 8px;
661
+ background: var(--dsw-alias-bg-layer-3);
662
+ color: var(--dsw-alias-label-primary);
663
+ font-size: 14px;
664
+ }
665
+ .dww-input-row { display: flex; gap: 8px; align-items: center; }
666
+ .dww-input {
667
+ box-sizing: border-box;
668
+ flex: 1;
669
+ height: 36px;
670
+ min-width: 0;
671
+ padding: 0 10px;
672
+ border: 1px solid var(--dsw-alias-border-l2);
673
+ border-radius: 8px;
674
+ background: var(--dsw-alias-bg-layer-3);
675
+ color: var(--dsw-alias-label-primary);
676
+ font-size: 14px;
677
+ }
678
+ .dww-input:focus, .dww-select:focus {
679
+ outline: none;
680
+ border-color: var(--dsw-alias-state-business-primary);
681
+ }
682
+ .dww-check-btn {
683
+ flex: none;
684
+ height: 36px;
685
+ padding: 0 12px;
686
+ border: 1px solid var(--dsw-alias-border-l2);
687
+ border-radius: 8px;
688
+ background: transparent;
689
+ color: var(--dsw-alias-label-primary);
690
+ cursor: pointer;
691
+ font-size: 12px;
692
+ }
693
+ .dww-check-btn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
694
+ .dww-check-btn:disabled { cursor: default; }
695
+
696
+ /* Directory browse list. */
697
+ .dww-dirlist {
698
+ display: flex;
699
+ flex-direction: column;
700
+ gap: 2px;
701
+ box-sizing: border-box;
702
+ min-height: 120px;
703
+ max-height: 200px;
704
+ padding: 4px;
705
+ overflow: auto;
706
+ border: 1px solid var(--dsw-alias-border-l2);
707
+ border-radius: 8px;
708
+ background: var(--dsw-alias-bg-layer-3);
709
+ }
710
+ .dww-breadcrumb {
711
+ padding: 0 4px;
712
+ font-size: 12px;
713
+ line-height: 18px;
714
+ color: var(--dsw-alias-label-tertiary);
715
+ overflow: hidden;
716
+ white-space: nowrap;
717
+ text-overflow: ellipsis;
718
+ }
719
+ .dww-dir-row {
720
+ display: flex;
721
+ align-items: center;
722
+ gap: 8px;
723
+ height: 28px;
724
+ padding: 0 8px;
725
+ border: 0;
726
+ border-radius: 6px;
727
+ background: transparent;
728
+ color: var(--dsw-alias-label-primary);
729
+ cursor: pointer;
730
+ font-size: 13px;
731
+ text-align: left;
732
+ }
733
+ .dww-dir-row:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
734
+ .dww-dir-row:disabled { cursor: default; color: var(--dsw-alias-label-tertiary); }
735
+ .dww-dir-row--up { color: var(--dsw-alias-label-secondary); }
736
+ .dww-dir-row svg { flex: none; color: var(--dsw-alias-label-tertiary); }
737
+ .dww-dir-empty {
738
+ padding: 8px;
739
+ font-size: 12px;
740
+ line-height: 18px;
741
+ color: var(--dsw-alias-label-tertiary);
742
+ }
743
+
744
+ /* Error strip. */
745
+ .dww-error {
746
+ box-sizing: border-box;
747
+ width: 100%;
748
+ padding: 8px 10px;
749
+ border: 1px solid var(--dsw-alias-state-error-primary);
750
+ border-radius: 8px;
751
+ color: var(--dsw-alias-state-error-primary);
752
+ font-size: 12px;
753
+ line-height: 18px;
754
+ }
755
+ .dww-retry {
756
+ margin-left: 6px;
757
+ border: 0;
758
+ background: transparent;
759
+ color: var(--dsw-alias-state-business-primary);
760
+ cursor: pointer;
761
+ font-size: 12px;
762
+ text-decoration: underline;
763
+ }
764
+
765
+ /* Dialog footer actions. */
766
+ .dww-actions {
767
+ display: flex;
768
+ align-items: center;
769
+ justify-content: flex-end;
770
+ gap: 8px;
771
+ padding: 14px 20px 0;
772
+ }
773
+ .dww-btn {
774
+ height: 36px;
775
+ padding: 0 14px;
776
+ border: 1px solid var(--dsw-alias-border-l2);
777
+ border-radius: 8px;
778
+ background: transparent;
779
+ color: var(--dsw-alias-label-primary);
780
+ cursor: pointer;
781
+ font-size: 14px;
782
+ }
783
+ .dww-btn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
784
+ .dww-btn--primary {
785
+ border-color: transparent;
786
+ background: var(--dsw-alias-button-primary-fill);
787
+ color: var(--dsw-alias-label-primary-foreground);
788
+ }
789
+ .dww-btn--primary:hover:not(:disabled) { background: var(--dsw-alias-button-primary-hover); }
790
+ .dww-btn:disabled { cursor: default; opacity: 0.6; }
791
+ `;
792
+ /**
793
+ * Idempotently inject the plugin stylesheet. No-op when a tag with the
794
+ * plugin's data attribute already exists.
795
+ */
796
+ function ensureStyles() {
797
+ if (typeof document === "undefined") return;
798
+ if (document.querySelector(`style[${STYLE_TAG_DATA_ATTRIBUTE}]`) !== null) return;
799
+ const style = document.createElement("style");
800
+ style.setAttribute("data-plugin", "dsh-wsl-workspace");
801
+ style.textContent = STYLES;
802
+ document.head.appendChild(style);
803
+ }
804
+ //#endregion
805
+ //#region src/client/locales.ts
806
+ /**
807
+ * Bilingual dictionaries for the `wslWorkspace` locale namespace. Product copy
808
+ * is Chinese; English is the parallel export for the standalone bundle.
809
+ */
810
+ /**
811
+ * The `wslWorkspace` translations (Chinese, the primary product copy).
812
+ */
813
+ const zh = {
814
+ "action.add": "WSL 工作区",
815
+ "action.title": "添加 WSL 工作区…",
816
+ "dialog.title": "添加 WSL 工作区",
817
+ "dialog.distro": "发行版",
818
+ "dialog.path": "路径",
819
+ "dialog.pathPlaceholder": "/home/",
820
+ "dialog.username": "用户名",
821
+ "dialog.usernamePlaceholder": "留空则使用发行版默认用户",
822
+ "dialog.loading": "正在加载…",
823
+ "dialog.browseEmpty": "此目录没有子文件夹",
824
+ "dialog.upLevel": "..(返回上级)",
825
+ "dialog.browse": "浏览",
826
+ "dialog.check": "检查",
827
+ "dialog.confirm": "创建并打开",
828
+ "dialog.cancel": "取消",
829
+ "dialog.retry": "重试",
830
+ "error.loadDistros": "无法获取 WSL 发行版列表,请确认已安装 WSL 且插件宿主端可用",
831
+ "error.rateLimited": "操作过于频繁,请稍后重试",
832
+ "error.loadDir": "无法浏览该目录",
833
+ "error.presetMissing": "未找到健康的 wsl preset,请确认插件宿主端已安装并配置该 preset",
834
+ "error.invalidPath": "请输入以 / 开头的 Linux 绝对路径",
835
+ "error.invalidUsername": "用户名无效:需以字母或下划线开头,仅含字母、数字、_、.、-",
836
+ "error.pathNotFound": "该路径不存在或是文件,请选择一个文件夹",
837
+ "error.createFailed": "创建工作区失败"
838
+ };
839
+ /**
840
+ * The `wslWorkspace` translations (English).
841
+ */
842
+ const en = {
843
+ "action.add": "WSL Workspace",
844
+ "action.title": "Add WSL workspace…",
845
+ "dialog.title": "Add WSL workspace",
846
+ "dialog.distro": "Distro",
847
+ "dialog.path": "Path",
848
+ "dialog.pathPlaceholder": "/home/",
849
+ "dialog.username": "Username",
850
+ "dialog.usernamePlaceholder": "Leave empty to use the distro default user",
851
+ "dialog.loading": "Loading…",
852
+ "dialog.browseEmpty": "No subdirectories here",
853
+ "dialog.upLevel": ".. (up)",
854
+ "dialog.browse": "Browse",
855
+ "dialog.check": "Check",
856
+ "dialog.confirm": "Create & open",
857
+ "dialog.cancel": "Cancel",
858
+ "dialog.retry": "Retry",
859
+ "error.loadDistros": "Could not list WSL distros; confirm WSL is installed and the plugin host side is reachable",
860
+ "error.rateLimited": "Too many attempts; retry in a moment",
861
+ "error.loadDir": "Could not browse this directory",
862
+ "error.presetMissing": "No healthy \"wsl\" preset found; confirm the plugin host side installed and configured it",
863
+ "error.invalidPath": "Enter an absolute Linux path starting with /",
864
+ "error.invalidUsername": "Invalid username: start with a letter or underscore; only letters, digits, _ . -",
865
+ "error.pathNotFound": "The path does not exist or is a file; choose a folder",
866
+ "error.createFailed": "Failed to create the workspace"
867
+ };
868
+ //#endregion
869
+ //#region src/client/index.ts
870
+ /** Required services (cordis fiber inject). */
871
+ const inject = [
872
+ "slots",
873
+ "locale",
874
+ "connection",
875
+ "sessions",
876
+ "workspaces"
877
+ ];
878
+ /** The legacy standalone WSL preset id (folded into the mode variants). */
879
+ const LEGACY_WSL_PRESET_ID = "wsl";
880
+ /**
881
+ * Mount the sidebar action and the auto-binding effect.
882
+ * @param ctx - the browser plugin context.
883
+ */
884
+ function apply(ctx) {
885
+ const { api } = ctx.get("connection");
886
+ const workspaces = ctx.get("workspaces");
887
+ const sessions = ctx.get("sessions");
888
+ ensureStyles();
889
+ ctx.effect(() => ctx.locale.register("wslWorkspace", {
890
+ zh,
891
+ en
892
+ }), "dsh-wsl-workspace: locale dictionaries");
893
+ const t = ctx.locale.bind("wslWorkspace");
894
+ const injected = () => ({
895
+ t,
896
+ checkPreset: async () => {
897
+ let roster;
898
+ try {
899
+ roster = (await api.agentPresets.list({})).result;
900
+ } catch (error) {
901
+ return error instanceof Error ? error.message : String(error);
902
+ }
903
+ if (!roster.ok) return roster.error.message;
904
+ if (roster.value.presets.find((entry) => entry.id.startsWith("wsl-") && entry.broken === void 0) === void 0) return t("error.presetMissing");
905
+ },
906
+ listDistros: () => listDistros(),
907
+ listDir: (distro, path) => listDir(distro, path),
908
+ check: (distro, path) => check(distro, path),
909
+ createWorkspace: async (path, username) => {
910
+ try {
911
+ const view = await workspaces.create({ path });
912
+ await setWorkspaceUser(path, username);
913
+ workspaces.startSession(view.workspaceId);
914
+ return;
915
+ } catch (error) {
916
+ return error instanceof Error ? error.message : String(error);
917
+ }
918
+ }
919
+ });
920
+ ctx.effect(() => ctx.slots.inject("sidebar.footer.action", () => ctx.slots.register({
921
+ name: "sidebar.footer.action",
922
+ id: "wsl-workspace",
923
+ inject: injected
924
+ }, AddWslWorkspace)), "dsh-wsl-workspace: sidebar footer action");
925
+ ctx.effect(() => {
926
+ const inFlight = /* @__PURE__ */ new Set();
927
+ const attempts = /* @__PURE__ */ new Map();
928
+ const MAX_ATTEMPTS = 3;
929
+ let variants = /* @__PURE__ */ new Set();
930
+ let defaultPreset;
931
+ const refreshRoster = () => {
932
+ api.agentPresets.list({}).then((response) => {
933
+ const result = response.result;
934
+ if (!result.ok) return;
935
+ variants = new Set(result.value.presets.filter((entry) => entry.broken === void 0 && entry.id.startsWith("wsl-")).map((entry) => entry.id));
936
+ defaultPreset = result.value.presets.find((entry) => entry.isDefault === true)?.id;
937
+ }).catch(() => {});
938
+ };
939
+ refreshRoster();
940
+ const maybeBind = () => {
941
+ const state = sessions.list.getSnapshot();
942
+ for (const id of state.ids) {
943
+ const summary = state.byId[id];
944
+ if (summary === void 0 || !summary.blank || summary.cwd === void 0) continue;
945
+ if (!isWslUnc(summary.cwd)) continue;
946
+ const current = summary.agentPreset;
947
+ if (current !== void 0 && current.startsWith("wsl-")) continue;
948
+ const base = current === LEGACY_WSL_PRESET_ID ? defaultPreset ?? "standard" : current ?? defaultPreset;
949
+ if (base === void 0 || base === LEGACY_WSL_PRESET_ID || base.startsWith("wsl-")) continue;
950
+ const target = `wsl-${base.toLowerCase()}`;
951
+ if (!variants.has(target)) continue;
952
+ if (inFlight.has(id) || (attempts.get(id) ?? 0) >= MAX_ATTEMPTS) continue;
953
+ inFlight.add(id);
954
+ api.agentPresets.select({
955
+ sessionId: id,
956
+ agentPreset: target
957
+ }).then((response) => {
958
+ if (response.result.ok) sessions.noteAgentPreset(id, target);
959
+ }).catch(() => {
960
+ attempts.set(id, (attempts.get(id) ?? 0) + 1);
961
+ }).finally(() => {
962
+ inFlight.delete(id);
963
+ });
964
+ }
965
+ };
966
+ maybeBind();
967
+ const unsubscribe = sessions.list.subscribe(() => maybeBind());
968
+ const timer = window.setInterval(refreshRoster, 6e4);
969
+ return () => {
970
+ unsubscribe();
971
+ window.clearInterval(timer);
972
+ };
973
+ }, "dsh-wsl-workspace: WSL mode-variant binding");
974
+ }
975
+ //#endregion
976
+ exports.apply = apply;
977
+ exports.inject = inject;
978
+ return module.exports;
979
+ }
980
+ });
981
+
982
+ //# sourceMappingURL=client.js.map