dsh-wsl-workspace 0.1.0 → 0.1.2

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/README.md CHANGED
@@ -23,8 +23,21 @@ After restarting `dsh web`, a W button appears beside Settings at the sidebar fo
23
23
 
24
24
  ## Usage
25
25
 
26
- Click the W button beside Settings at the sidebar foot to open the "Add WSL workspace" dialog. Pick a distribution from the list, then browse the directory tree or type an absolute Linux path (for example `/home/me/proj`) — use the Check button to verify the path exists before creating the workspace. The username field is optional: leave it empty to run commands as the distribution's default user, or name a Linux user of that distribution to run the session as that user instead (equivalent to `wsl.exe -u <username>`). The username only changes the bash tool's run identity — the file tools go through the Windows-side WSL share and are unaffected. Each workspace's username is kept in `<dshHome>/wsl-workspaces.json`; delete the entry (or recreate the workspace from the dialog) to return to the default user.
26
+ Click the W button beside Settings at the sidebar foot to open the "Add WSL workspace" dialog. Pick a distribution from the list, then browse the directory tree or type an absolute Linux path (for example `/home/me/proj`) — use the Check button to verify the path exists before creating the workspace. The dialog carries a built-in language switch (中文 / EN), defaulting to Chinese. The username field is optional: leave it empty to run commands as the distribution's default user, or name a Linux user of that distribution to run the session as that user instead (equivalent to `wsl.exe -u <username>`). The username only changes the bash tool's run identity — the file tools go through the Windows-side WSL share and are unaffected. Each workspace's username is kept in `<dshHome>/wsl-workspaces.json`; delete the entry (or recreate the workspace from the dialog) to return to the default user.
27
27
 
28
28
  Click "Create & open" to start a new session in the workspace. In the new session the bash tool executes commands inside the chosen distribution and `read`/`write`/`edit` operate on WSL files, so every path the model sees is a Linux path. The mode picker keeps working as usual: Standard, PTC, Minimal and Creative each land on their WSL variant automatically, and Windows files stay reachable from inside the session under `/mnt/<drive>` (for example `/mnt/c/Users/...`).
29
29
 
30
- License: MIT.
30
+ ## Behavior notes
31
+
32
+ - **bash tool**: runs inside the WSL distribution as the configured username (empty = the distro default user, often `root`), so it can read and write anywhere in the distro. The Windows ACL sandbox cannot wrap `wsl.exe` — its children run on the Linux kernel side — so WSL itself is the isolation boundary and the DSH file policy does not apply to bash.
33
+ - **File tools (`read`/`write`/`edit`)**: go through the Windows-side WSL 9P share and run under the DSH file policy. Under `workspace-write`, reads work anywhere but writes are restricted to the session workspace; switch the file policy to `danger-full-access` to also allow writes outside it. The username field does not affect the file tools.
34
+ - The garbled `localhost` port-forwarding banner `wsl.exe` prints to stderr when the distro was not running yet is harmless.
35
+
36
+ ## License & attribution
37
+
38
+ MIT — see [LICENSE](LICENSE) and [NOTICE](NOTICE). The NOTICE precisely lists:
39
+
40
+ - **Adapted/inherited source code**: DeepSeek Harness (MIT) — `dsh-bash-local` (executor mechanics), `dsh-fs-local` (`WslFileSystem` subclasses it), and the shipped agent presets (read and transformed by the variant generator);
41
+ - **Design references (no source copied)**: [dsh-bash-terminal](https://github.com/MAXeaglet/dsh-bash-terminal) (MIT, wsl argv / WSLENV approach), [dsh-side-panel](https://github.com/ccq1/dsh-side-panel) (BSD-3-Clause, host-route pattern), [vpshub](https://github.com/Sdongmaker/vpshub) (MIT, roadmap reference).
42
+
43
+ Keep `LICENSE` and `NOTICE` when redistributing.
package/README.zh.md CHANGED
@@ -22,9 +22,21 @@ dsh plugin --profile web add D:\path\to\dsh-wsl-workspace
22
22
  重启 `dsh web` 后,侧栏底部 Settings 旁出现 W 按钮。
23
23
 
24
24
  ## 使用
25
-
26
- 点侧栏底部 Settings 旁的 W 按钮,打开「添加 WSL 工作区」对话框。先从下拉框选择一个发行版,再浏览目录树或直接输入 Linux 绝对路径(如 `/home/me/proj`),可以点「检查」确认路径存在。用户名是可选项:留空则以该发行版的默认用户运行,填写该发行版里的某个 Linux 用户名则以该用户运行(等价于 `wsl.exe -u <用户名>`)。用户名只影响 bash 命令的运行身份,文件工具通过 Windows 侧的 WSL 共享访问、不受其影响;每个工作区填写的用户名保存在 `<dshHome>/wsl-workspaces.json`,删除对应条目(或重开对话框重建工作区)即可恢复默认用户。
25
+ 点侧栏底部 Settings 旁的 W 按钮,打开「添加 WSL 工作区」对话框。先从下拉框选择一个发行版,再浏览目录树或直接输入 Linux 绝对路径(如 `/home/me/proj`),可以点「检查」确认路径存在。对话框自带 中文/EN 语言切换,默认中文。用户名是可选项:留空则以该发行版的默认用户运行,填写该发行版里的某个 Linux 用户名则以该用户运行(等价于 `wsl.exe -u <用户名>`)。用户名只影响 bash 命令的运行身份,文件工具通过 Windows 侧的 WSL 共享访问、不受其影响;每个工作区填写的用户名保存在 `<dshHome>/wsl-workspaces.json`,删除对应条目(或重开对话框重建工作区)即可恢复默认用户。
27
26
 
28
27
  点「创建并打开」后,新会话随即运行在 WSL:`bash` 工具在所选发行版内执行命令,`read`/`write`/`edit` 读写 WSL 文件,模型看到的所有路径都是 Linux 形式。模式选择器照常可用——标准、PTC、极简、创造都会自动落到对应的 WSL 变体;会话内仍可通过 `/mnt/<drive>`(如 `/mnt/c/Users/...`)访问 Windows 文件。
28
+ ![alt text](image-1.png)
29
+ ## 行为与权限说明
30
+
31
+ - **bash 工具**:以配置的用户名在 WSL 发行版内运行(留空 = 发行版默认用户,通常为 root),可对发行版内任意路径读写。Windows 的 ACL 沙箱无法包裹 `wsl.exe`(子进程运行在 Linux 内核侧),WSL 自身即隔离边界,DSH 文件策略不作用于 bash。
32
+ - **文件工具(read/write/edit)**:经 Windows 侧的 WSL 9P 共享访问,受 DSH 文件策略约束。`workspace-write` 下读可到任意位置、写仅限会话工作区;改为 `danger-full-access` 后工作区外也可写入。用户名设置不影响文件工具。
33
+ - `wsl.exe` 在发行版尚未启动时向 stderr 打印的 localhost 端口转发提示(乱码但无害)可忽略。
34
+
35
+ ## 许可与出处
36
+
37
+ MIT,详见 [LICENSE](LICENSE) 与 [NOTICE](NOTICE),NOTICE 精确列明:
38
+
39
+ - **改编/继承源码**:DeepSeek Harness(MIT)的 `dsh-bash-local`(执行器机制)、`dsh-fs-local`(`WslFileSystem` 子类化)、shipped agent presets(变体生成读取/变换);
40
+ - **设计参考(未复制源码)**:[dsh-bash-terminal](https://github.com/MAXeaglet/dsh-bash-terminal)(MIT,wsl argv/WSLENV 思路)、[dsh-side-panel](https://github.com/ccq1/dsh-side-panel)(BSD-3-Clause,Host 路由模式)、[vpshub](https://github.com/Sdongmaker/vpshub)(MIT,路线图参考)。
29
41
 
30
- 许可:MIT
42
+ 发布/再分发时请保留 LICENSE 与 NOTICE
package/image-1.png ADDED
Binary file
package/image.png ADDED
Binary file
package/lib/client.js CHANGED
@@ -215,9 +215,10 @@ window.__ModuleLoader__.load({
215
215
  * The "Add WSL workspace…" footer action and its dialog.
216
216
  * @param props - owner share + injected face.
217
217
  */
218
- function AddWslWorkspace({ wide, t, checkPreset, listDistros, listDir, check, createWorkspace }) {
218
+ function AddWslWorkspace({ wide, language, setLanguage, t, checkPreset, listDistros, listDir, check, createWorkspace }) {
219
219
  const [open, setOpen] = (0, react.useState)(false);
220
220
  const [opening, setOpening] = (0, react.useState)(false);
221
+ const [lang, setLang] = (0, react.useState)(language);
221
222
  const [distros, setDistros] = (0, react.useState)([]);
222
223
  const [distro, setDistro] = (0, react.useState)("");
223
224
  const [pathInput, setPathInput] = (0, react.useState)("/home/");
@@ -372,6 +373,10 @@ window.__ModuleLoader__.load({
372
373
  const maskClick = () => {
373
374
  if (!busy) setOpen(false);
374
375
  };
376
+ const onLanguageChange = (next) => {
377
+ setLang(next);
378
+ setLanguage(next);
379
+ };
375
380
  const listScroll = () => {};
376
381
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
377
382
  className: "dww-overlay",
@@ -389,12 +394,32 @@ window.__ModuleLoader__.load({
389
394
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
390
395
  className: "dww-title",
391
396
  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: ""
397
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
398
+ className: "dww-header-actions",
399
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
400
+ className: "dww-lang",
401
+ role: "group",
402
+ "aria-label": "Language",
403
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
404
+ type: "button",
405
+ className: lang === "zh" ? "dww-lang-btn dww-lang-btn--active" : "dww-lang-btn",
406
+ disabled: busy,
407
+ onClick: () => onLanguageChange("zh"),
408
+ children: "中文"
409
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
410
+ type: "button",
411
+ className: lang === "en" ? "dww-lang-btn dww-lang-btn--active" : "dww-lang-btn",
412
+ disabled: busy,
413
+ onClick: () => onLanguageChange("en"),
414
+ children: "EN"
415
+ })]
416
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
417
+ type: "button",
418
+ className: "dww-close",
419
+ "aria-label": t("dialog.cancel"),
420
+ onClick: maskClick,
421
+ children: "✕"
422
+ })]
398
423
  })]
399
424
  }),
400
425
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -616,6 +641,33 @@ window.__ModuleLoader__.load({
616
641
  gap: 8px;
617
642
  padding: 18px 20px 12px;
618
643
  }
644
+ .dww-header-actions {
645
+ display: flex;
646
+ align-items: center;
647
+ gap: 8px;
648
+ }
649
+ /* Built-in dialog language switch (中文 / EN), independent of the app locale. */
650
+ .dww-lang {
651
+ display: inline-flex;
652
+ overflow: hidden;
653
+ border: 1px solid var(--dsw-alias-border-l2);
654
+ border-radius: 8px;
655
+ }
656
+ .dww-lang-btn {
657
+ height: 28px;
658
+ padding: 0 10px;
659
+ border: 0;
660
+ background: transparent;
661
+ color: var(--dsw-alias-label-secondary);
662
+ cursor: pointer;
663
+ font-size: 12px;
664
+ }
665
+ .dww-lang-btn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
666
+ .dww-lang-btn--active {
667
+ background: var(--dsw-alias-button-primary-fill);
668
+ color: var(--dsw-alias-label-primary-foreground);
669
+ }
670
+ .dww-lang-btn:disabled { cursor: default; opacity: 0.6; }
619
671
  .dww-title {
620
672
  margin: 0;
621
673
  font-size: 16px;
@@ -890,8 +942,22 @@ window.__ModuleLoader__.load({
890
942
  zh,
891
943
  en
892
944
  }), "dsh-wsl-workspace: locale dictionaries");
893
- const t = ctx.locale.bind("wslWorkspace");
945
+ let language = "zh";
946
+ const dictionaries = {
947
+ zh,
948
+ en
949
+ };
950
+ const t = (key, params) => {
951
+ let text = dictionaries[language][key] ?? key;
952
+ if (params !== void 0) for (const [name, value] of Object.entries(params)) text = text.replaceAll(`{${name}}`, String(value));
953
+ return text;
954
+ };
955
+ const setLanguage = (next) => {
956
+ language = next;
957
+ };
894
958
  const injected = () => ({
959
+ language,
960
+ setLanguage,
895
961
  t,
896
962
  checkPreset: async () => {
897
963
  let roster;
package/lib/client.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":["listDistrosApi","listDirApi","checkApi","setWorkspaceUserApi"],"sources":["../src/client/api.ts","../src/shared/paths.ts","../src/client/AddWslWorkspace.tsx","../src/client/styles.ts","../src/client/locales.ts","../src/client/index.ts"],"sourcesContent":["/**\n * Thin fetch client for the Host plugin route. The browser calls\n * POST /wsl-workspace/api with a `{ method, params }` envelope and the Host\n * answers `{ ok: true, value }` or `{ ok: false, error }`.\n */\n\n/** Relative route the Host half registers (same-origin with the web server). */\nconst ENDPOINT = '/wsl-workspace/api'\n\n/** One directory entry as the Host lists it. */\nexport interface WslDirEntry {\n name: string\n kind: 'directory' | 'file' | 'other'\n}\n\n/** One directory level plus its breadcrumb ancestry. */\nexport interface WslDirListing {\n /** The listed absolute Linux path. */\n path: string\n /** Parent Linux path, or null at the filesystem root. */\n parent: string | null\n /** The level's children (in name order; the client filters to directories). */\n entries: WslDirEntry[]\n}\n\n/** Existence/directory check result for one Linux path. */\nexport interface WslPathCheck {\n exists: boolean\n isDirectory: boolean\n}\n\n/** Wire envelope the Host route answers with. */\ntype Envelope<T> = { ok: true; value: T } | { ok: false; error: string }\n\n/** Human text for an unknown rejection, reusing the repository's idiom. */\nfunction errorMessage(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n\n/**\n * Perform one POST call and unwrap the envelope.\n * @param method - the Host method name.\n * @param params - the method payload.\n * @returns the unwrapped value, or throws an Error on network or `ok:false`.\n */\nasync function call<T>(method: string, params: Record<string, unknown> = {}): Promise<T> {\n let response: Response\n try {\n response = await fetch(ENDPOINT, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({ method, params }),\n })\n } catch (error) {\n // The transport refused before answering (offline, origin mismatch, 404).\n throw new Error(`wsl-workspace request failed: ${errorMessage(error)}`)\n }\n let envelope: Envelope<T>\n try {\n envelope = (await response.json()) as Envelope<T>\n } catch {\n // A non-JSON body means a proxy/loader answered instead of the Host route.\n throw new Error(`wsl-workspace answered non-JSON (${response.status})`)\n }\n if (!envelope.ok) throw new Error(envelope.error)\n return envelope.value\n}\n\n/**\n * List the WSL distros installed on the host.\n * @returns distro names in registry order.\n */\nexport async function listDistros(): Promise<string[]> {\n return call<string[]>('listDistros', {})\n}\n\n/**\n * List one directory level inside a distro.\n * @param distro - distro name.\n * @param path - absolute Linux directory to list.\n * @returns the level's listing with ancestry.\n */\nexport async function listDir(distro: string, path: string): Promise<WslDirListing> {\n return call<WslDirListing>('listDir', { distro, path })\n}\n\n/**\n * Check whether a Linux path exists and is a directory.\n * @param distro - distro name.\n * @param path - absolute Linux path.\n * @returns existence and directory facts.\n */\nexport async function check(distro: string, path: string): Promise<WslPathCheck> {\n return call<WslPathCheck>('check', { distro, path })\n}\n\n/**\n * Store (or clear, with an empty string) the username of one WSL workspace.\n * @param path - the workspace UNC path.\n * @param username - the Linux username; empty string clears the stored value.\n */\nexport async function setWorkspaceUser(path: string, username: string): Promise<void> {\n return call<void>('setUser', { path, username })\n}\n","/**\n * WSL path helpers shared by the client and host halves. Pure and\n * dependency-free so both planes can import them without a runtime edge.\n */\n\n/** WSL2 default loopback bridge host: `\\\\wsl.localhost\\<distro>\\...`. */\nconst WSL_LOCALHOST_HOST = 'wsl.localhost'\n/** Legacy WSL interop host: `\\\\wsl$\\<distro>\\...`. */\nconst WSL_LEGACY_HOST = 'wsl$'\n\n/** The two UNC hosts WSL exposes a distribution's filesystem under. */\nconst UNC_HOSTS = [WSL_LOCALHOST_HOST, WSL_LEGACY_HOST]\n\n/** One WSL workspace coordinate parsed out of a UNC path. */\nexport interface WslUncTarget {\n /** Distro name (e.g. `Ubuntu`) as `wsl -l -q` reports it. */\n readonly distro: string\n /** Normalized absolute Linux path (leading `/`; no trailing slash except root). */\n readonly linuxPath: string\n}\n\n/**\n * Parse a WSL UNC path into its distro and Linux path. Accepts the WSL2\n * `\\\\wsl.localhost\\<distro>\\<linux>` form, the legacy `\\\\wsl$\\<distro>\\<linux>`\n * interop form, and forward-slash spellings of either.\n * @param raw - candidate absolute path.\n * @returns the parsed target, or null when the path is not a WSL UNC.\n */\nexport function parseWslUnc(raw: string): WslUncTarget | null {\n const normalized = raw.replace(/\\\\/g, '/').replace(/\\/\\/+/g, '//')\n if (!normalized.startsWith('//')) return null\n const segments = normalized.slice(2).split('/')\n const host = (segments[0] ?? '').toLowerCase()\n if (!UNC_HOSTS.includes(host)) return null\n const distro = segments[1] ?? ''\n if (distro === '') return null\n const rest = segments.slice(2).filter(segment => segment.length > 0)\n return { distro, linuxPath: `/${rest.join('/')}` }\n}\n\n/**\n * Whether a path resolves into a WSL distro through either UNC form.\n * @param raw - candidate absolute path.\n * @returns whether the path parses as a WSL UNC.\n */\nexport function isWslUnc(raw: string): boolean {\n return parseWslUnc(raw) !== null\n}\n\n/**\n * Translate a WSL UNC path to the absolute Linux path a process inside the\n * distribution can open. Throws on non-WSL input: callers rely on this\n * conversion to hand paths to the Linux world, so a silent pass-through\n * would hand a Windows path to bash.\n * @param uncPath - a path {@link parseWslUnc} accepts.\n * @returns the absolute Linux path.\n */\nexport function uncToLinux(uncPath: string): string {\n const parts = parseWslUnc(uncPath)\n if (parts === null) {\n throw new Error(`wsl-workspace: \"${uncPath}\" is not a WSL UNC path`)\n }\n return parts.linuxPath\n}\n\n/**\n * Normalize a Linux absolute path for the Host: collapse repeated slashes and\n * strip a trailing slash (root becomes `/`).\n * @param path - absolute Linux path.\n * @returns the normalized path.\n */\nexport function normalizeLinuxPath(path: string): string {\n const collapsed = path.replace(/\\/+/g, '/')\n return collapsed === '/' ? '/' : collapsed.replace(/\\/$/, '')\n}\n\n/**\n * Whether a path is an absolute, non-empty Linux path.\n * @param path - candidate.\n * @returns whether it starts with `/` and contains no NUL.\n */\nexport function isAbsoluteLinuxPath(path: string): boolean {\n return path.startsWith('/') && !path.includes('\\0')\n}\n\n/**\n * Join a distro and a Linux absolute path into the WSL2 UNC form used as the\n * workspace identity (`\\\\wsl.localhost\\<distro>\\<linux>`, backslash segments).\n * @param distro - distro name.\n * @param linuxPath - absolute Linux path (leading `/`).\n * @returns the UNC path.\n */\nexport function joinUnc(distro: string, linuxPath: string): string {\n if (!isAbsoluteLinuxPath(linuxPath)) {\n throw new Error(`wsl-workspace: cannot map a non-absolute Linux path \"${linuxPath}\" to UNC`)\n }\n // Defense in depth: a distribution name with separators or dot-dirs would\n // escape the `\\\\wsl.localhost\\` share structure (the host route validates\n // wire-supplied names too; every other caller passes through here).\n if (distro === '' || distro === '.' || distro === '..' || /[\\\\/]/.test(distro)) {\n throw new Error(`wsl-workspace: invalid distribution name \"${distro}\"`)\n }\n const normalized = linuxPath.replace(/\\/+/g, '/').replace(/\\/$/, '')\n const withoutLeading = normalized.startsWith('/') ? normalized.slice(1) : normalized\n const windowsSegments = withoutLeading.replace(/\\//g, '\\\\')\n const suffix = windowsSegments === '' ? '' : `\\\\${windowsSegments}`\n return `\\\\\\\\wsl.localhost\\\\${distro}${suffix}`\n}\n\n/**\n * Translate a Windows drive path to the drvfs mount path WSL distributions\n * conventionally expose it at (`C:\\foo` → `/mnt/c/foo`). Only single-letter\n * drives under `/mnt` are mapped; custom mount points are out of scope.\n * @param path - the candidate Windows path.\n * @returns the `/mnt/<drive>/…` path, or `null` for non-drive paths.\n */\nexport function windowsToMntPath(path: string): string | null {\n const match = /^([A-Za-z]):[\\\\/](.*)$/.exec(path)\n if (match === null) return null\n const rest = (match[2] ?? '').replace(/\\\\/g, '/').replace(/\\/+/g, '/').replace(/\\/$/, '')\n return `/mnt/${(match[1] ?? '').toLowerCase()}${rest === '' ? '' : `/${rest}`}`\n}\n\n/**\n * Translate a `/mnt/<drive>/…` path back to its Windows drive path.\n * @param linuxPath - the candidate Linux path.\n * @returns the `X:\\…` drive path, or `null` when the path is not a drvfs mount.\n */\nexport function mntToWindowsPath(linuxPath: string): string | null {\n const match = /^\\/mnt\\/([a-zA-Z])(?:\\/(.*))?$/.exec(linuxPath)\n if (match === null) return null\n const rest = (match[2] ?? '').replace(/\\//g, '\\\\')\n return `${(match[1] ?? '').toUpperCase()}:\\\\${rest}`\n}\n\n/**\n * True when a value is a Windows-shaped path (drive or UNC), which is how\n * the shell executor decides the WSLENV `/p` translation flag: only Windows\n * path values need translation when they cross into the Linux process.\n * @param value - the environment value to classify.\n * @returns whether the value looks like a Windows path.\n */\nexport function isWindowsPathShaped(value: string): boolean {\n return /^[A-Za-z]:[\\\\/]/.test(value) || value.startsWith('\\\\\\\\')\n}\n\n/** Linux username shape for `wsl.exe -u`: starts with a letter or underscore, then letters/digits/`_`/`.`/`-` (max 64). */\nconst WSL_USERNAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_.-]{0,63}$/\n\n/**\n * Whether a value is a safe Linux username for `wsl.exe -u`. The check is\n * strict on purpose: a value starting with `-` could be parsed as a wsl.exe\n * option instead of a username.\n * @param value - candidate username.\n * @returns whether it matches the Linux username shape.\n */\nexport function isValidWslUsername(value: string): boolean {\n return WSL_USERNAME_PATTERN.test(value)\n}\n","/**\n * Sidebar footer action that opens the \"Add WSL workspace\" dialog. In the\n * wide sidebar it renders a labeled row; in the 56px rail it collapses to a\n * 36px icon button (both honor the shell's `{ wide }` owner share).\n *\n * Registration omits the typed `locale:` seat (the `wslWorkspace` namespace is\n * not merged into `LocaleNamespaceMap`), so the injected face carries the\n * bound translate function instead.\n */\n\nimport type * as React from 'react'\nimport { useEffect, useRef, useState, type UIEventHandler } from 'react'\nimport { isAbsoluteLinuxPath, isValidWslUsername, joinUnc, normalizeLinuxPath } from '../shared/paths.ts'\nimport type { WslDirListing, WslPathCheck } from './api.ts'\n\n/** Result-level shape of a browse/check/list call we surface uniformly. */\ninterface ApiCall<T> {\n value: T\n}\n\n/** The inject face: plain data + callbacks the dialog drives. */\nexport interface AddWslWorkspaceInjected {\n /**\n * Confirm the deployment exposes a healthy `wsl` preset.\n * @returns undefined when healthy, else a Chinese/English message to show.\n */\n checkPreset(): Promise<string | undefined>\n /** List the WSL distros installed on the host. */\n listDistros(): Promise<string[]>\n /** List one Linux directory level inside a distro. */\n listDir(distro: string, path: string): Promise<WslDirListing>\n /** Check a Linux path's existence/directory facts. */\n check(distro: string, path: string): Promise<WslPathCheck>\n /**\n * Register a workspace over a WSL UNC path and start a session in it.\n * @param path - the `\\\\wsl.localhost\\<distro>\\...` UNC path.\n * @param username - optional Linux user for the session (empty = distro default).\n * @returns undefined on success, else a message to show.\n */\n createWorkspace(path: string, username: string): Promise<string | undefined>\n /** Translate a `wslWorkspace` dictionary key. */\n t: (key: string, params?: Record<string, unknown>) => string\n}\n\n/** Full component props: the owner share plus the injected face. */\nexport interface AddWslWorkspaceProps extends AddWslWorkspaceInjected {\n /** Whether the sidebar renders wide content (false = 56px rail). */\n wide: boolean\n}\n\n/**\n * Build the Linux child path one level below a parent, for the breadcrumb/\n * browse drill.\n * @param parent - the currently listed absolute path (`/` for root).\n * @param name - the child directory name.\n * @returns the child's absolute Linux path.\n */\nexport function dirChildPath(parent: string, name: string): string {\n return parent === '/' ? `/${name}` : `${parent}/${name}`\n}\n\n/** A tiny inline terminal glyph for the dialog's directory rows. */\nfunction WslGlyph({ size = 16 }: { size?: number }): React.ReactElement {\n return (\n <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" aria-hidden=\"true\">\n <rect x=\"2.5\" y=\"4.5\" width=\"19\" height=\"15\" rx=\"2.5\" stroke=\"currentColor\" strokeWidth=\"1.6\" />\n <path d=\"M6 9l3.2 2.6L6 14\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n <path d=\"M12 14h5\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" />\n </svg>\n )\n}\n\n/**\n * The \"Add WSL workspace…\" footer action and its dialog.\n * @param props - owner share + injected face.\n */\nexport function AddWslWorkspace({ wide, t, checkPreset, listDistros, listDir, check, createWorkspace }: AddWslWorkspaceProps): React.ReactElement | null {\n const [open, setOpen] = useState(false)\n const [opening, setOpening] = useState(false)\n const [distros, setDistros] = useState<string[]>([])\n const [distro, setDistro] = useState('')\n const [pathInput, setPathInput] = useState('/home/')\n const [username, setUsername] = useState('')\n const [listing, setListing] = useState<WslDirListing | null>(null)\n const [browsePath, setBrowsePath] = useState('/')\n const [browsing, setBrowsing] = useState(false)\n const [error, setError] = useState<string | null>(null)\n const [busy, setBusy] = useState(false)\n // Monotone browse-request sequence: stale responses for a superseded browse are dropped.\n const browseSeq = useRef(0)\n\n const refreshBrowse = async (root: string, targetDistro: string): Promise<void> => {\n const seq = ++browseSeq.current\n setBrowsing(true)\n setBrowsePath(root)\n try {\n const value = await listDir(targetDistro, root)\n if (seq === browseSeq.current) setListing(value)\n } catch {\n // A failed browse (permission, missing dir) is non-fatal: keep old listing.\n if (seq === browseSeq.current) {\n setListing(null)\n setError((previous) => previous ?? t('error.loadDir'))\n }\n } finally {\n if (seq === browseSeq.current) setBrowsing(false)\n }\n }\n\n useEffect(() => {\n if (!open) return\n let cancelled = false\n setError(null)\n setOpening(true)\n void (async () => {\n let presetIssue: string | undefined\n try {\n presetIssue = await checkPreset()\n } catch {\n presetIssue = t('error.loadDistros')\n }\n let names: string[]\n try {\n names = await listDistros()\n } catch {\n if (cancelled) return\n setOpening(false)\n setError(t('error.loadDistros'))\n return\n }\n if (cancelled) return\n setDistros(names)\n const first = names[0] ?? ''\n setDistro(first)\n // The default browse root walks from `/`; the input defaults to `/home/`.\n setBrowsing(true)\n setOpening(false)\n if (presetIssue !== undefined) setError(presetIssue)\n if (first !== '') void refreshBrowse('/', first)\n })()\n return () => { cancelled = true }\n // eslint-disable-next-line react-hooks/exhaustive-deps -- run once per open against current t.\n }, [open])\n\n useEffect(() => {\n if (!open) return\n const onKey = (event: KeyboardEvent): void => {\n if (event.key === 'Escape' && !busy) setOpen(false)\n }\n window.addEventListener('keydown', onKey)\n return () => window.removeEventListener('keydown', onKey)\n }, [open, busy])\n\n if (!open) {\n // A W-letter action beside Settings at the sidebar foot; the title\n // carries the label in both wide and rail states.\n return (\n <button\n type=\"button\"\n className={wide ? 'dww-action dww-action--wide' : 'dww-action dww-action--rail'}\n title={t('action.title')}\n aria-label={t('action.title')}\n onClick={() => setOpen(true)}\n >\n <span className=\"dww-letter\" aria-hidden=\"true\">W</span>\n </button>\n )\n }\n\n const onDrill = (name: string): void => {\n const next = dirChildPath(listing?.path ?? browsePath, name)\n setPathInput(next)\n void refreshBrowse(next, distro)\n }\n\n const onUp = (): void => {\n const parent = listing?.parent ?? null\n if (parent === null) return\n setPathInput(parent)\n void refreshBrowse(parent, distro)\n }\n\n const onDistroChange = (value: string): void => {\n setDistro(value)\n void refreshBrowse(browsePath, value)\n }\n\n const onCheck = async (): Promise<void> => {\n const path = normalizeLinuxPath(pathInput)\n setError(null)\n if (!isAbsoluteLinuxPath(path) || path === '/') {\n setError(t('error.invalidPath'))\n return\n }\n let facts: WslPathCheck\n try {\n facts = await check(distro, path)\n } catch {\n setError(t('error.pathNotFound'))\n return\n }\n if (!facts.exists || !facts.isDirectory) {\n setError(t('error.pathNotFound'))\n return\n }\n void refreshBrowse(path, distro)\n }\n\n const onConfirm = async (): Promise<void> => {\n const path = normalizeLinuxPath(pathInput)\n setError(null)\n if (!isAbsoluteLinuxPath(path) || path === '/') {\n // A workspace at the distribution root would make every session start\n // at `/`; the check flow rejects it and confirm must agree.\n setError(t('error.invalidPath'))\n return\n }\n const user = username.trim()\n if (user !== '' && !isValidWslUsername(user)) {\n setError(t('error.invalidUsername'))\n return\n }\n setBusy(true)\n try {\n let facts: WslPathCheck\n try {\n facts = await check(distro, path)\n } catch {\n setError(t('error.pathNotFound'))\n return\n }\n if (!facts.exists || !facts.isDirectory) {\n setError(t('error.pathNotFound'))\n return\n }\n const failure = await createWorkspace(joinUnc(distro, path), user)\n if (failure !== undefined) {\n setError(failure)\n return\n }\n setOpen(false)\n } finally {\n setBusy(false)\n }\n }\n\n const children = (listing?.entries.filter(entry => entry.kind === 'directory') ?? []).map(entry => entry.name)\n const maskClick = (): void => { if (!busy) setOpen(false) }\n const listScroll: UIEventHandler<HTMLDivElement> = () => { /* scroll container handles overflow */ }\n\n return (\n <div className=\"dww-overlay\">\n <div className=\"dww-overlay-mask\" onClick={maskClick} />\n <div className=\"dww-card\" role=\"dialog\" aria-modal=\"true\" aria-label={t('dialog.title')}>\n <div className=\"dww-header\">\n <h2 className=\"dww-title\">{t('dialog.title')}</h2>\n <button type=\"button\" className=\"dww-close\" aria-label={t('dialog.cancel')} onClick={maskClick}>\n ✕\n </button>\n </div>\n <div className=\"dww-body\">\n {error !== null ? (\n <div className=\"dww-error\">\n {error}\n <button type=\"button\" className=\"dww-retry\" onClick={() => setError(null)}>{t('dialog.retry')}</button>\n </div>\n ) : null}\n <div className=\"dww-field\">\n <label className=\"dww-field-label\" htmlFor=\"dww-distro\">{t('dialog.distro')}</label>\n <select\n id=\"dww-distro\"\n className=\"dww-select\"\n value={distro}\n disabled={opening || busy}\n onChange={event => onDistroChange(event.target.value)}\n >\n {distros.length === 0\n ? <option value=\"\">{opening ? t('dialog.loading') : ''}</option>\n : distros.map(name => <option key={name} value={name}>{name}</option>)}\n </select>\n </div>\n <div className=\"dww-field\">\n <label className=\"dww-field-label\" htmlFor=\"dww-path\">{t('dialog.path')}</label>\n <div className=\"dww-input-row\">\n <input\n id=\"dww-path\"\n className=\"dww-input\"\n value={pathInput}\n placeholder={t('dialog.pathPlaceholder')}\n disabled={opening || busy}\n onChange={event => setPathInput(event.target.value)}\n />\n <button type=\"button\" className=\"dww-check-btn\" disabled={opening || busy} onClick={() => void onCheck()}>\n {t('dialog.check')}\n </button>\n </div>\n </div>\n <div className=\"dww-field\">\n <label className=\"dww-field-label\" htmlFor=\"dww-username\">{t('dialog.username')}</label>\n <input\n id=\"dww-username\"\n className=\"dww-input\"\n value={username}\n placeholder={t('dialog.usernamePlaceholder')}\n disabled={opening || busy}\n autoComplete=\"off\"\n spellCheck={false}\n onChange={event => setUsername(event.target.value)}\n />\n </div>\n <div className=\"dww-feedback\">\n <div className=\"dww-breadcrumb\">{browsePath}</div>\n <div className=\"dww-dirlist\" onScroll={listScroll}>\n {browsing ? <div className=\"dww-dir-empty\">{t('dialog.loading')}</div> : (\n listing?.parent !== null && listing !== null\n ? (\n <button type=\"button\" className=\"dww-dir-row dww-dir-row--up\" onClick={onUp}>\n <WslGlyph size={14} />\n <span>{t('dialog.upLevel')}</span>\n </button>\n )\n : null\n )}\n {!browsing && (children.length === 0)\n ? <div className=\"dww-dir-empty\">{t('dialog.browseEmpty')}</div>\n : children.map(name => (\n <button type=\"button\" key={name} className=\"dww-dir-row\" onClick={() => onDrill(name)}>\n <WslGlyph size={14} />\n <span>{name}</span>\n </button>\n ))}\n </div>\n </div>\n </div>\n <div className=\"dww-actions\">\n <button type=\"button\" className=\"dww-btn\" disabled={busy} onClick={maskClick}>{t('dialog.cancel')}</button>\n <button type=\"button\" className=\"dww-btn dww-btn--primary\" disabled={busy || opening} onClick={() => void onConfirm()}>\n {busy ? t('dialog.loading') : t('dialog.confirm')}\n </button>\n </div>\n </div>\n </div>\n )\n}\n\nexport type { ApiCall }\n","/**\n * Third-party stylesheet injection for the WSL workspace UI (the plugin\n * builds no CSS bundle, so styles are injected as one idempotent `<style>`).\n * Colors derive exclusively from the `--dsw-*` design tokens.\n */\n\nconst STYLE_TAG_DATA_ATTRIBUTE = 'data-plugin=\"dsh-wsl-workspace\"'\n\nconst STYLES = `\n/* Sidebar-foot icon action beside Settings (28px round in the wide sidebar,\n 36px round in the rail), matching the shell's icon-button language. */\n.dww-action {\n flex: none;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 28px;\n height: 28px;\n border: none;\n border-radius: 50%;\n padding: 0;\n background: transparent;\n cursor: pointer;\n color: var(--dsw-alias-label-secondary);\n transition:\n background-color 120ms var(--dsw-ease-in-out, ease-in-out),\n color 120ms var(--dsw-ease-in-out, ease-in-out);\n}\n.dww-action:hover:not(:disabled) {\n background: var(--dsw-alias-interactive-bg-hover);\n color: var(--dsw-alias-label-secondary);\n}\n.dww-action:active:not(:disabled) {\n background: var(--dsw-alias-interactive-bg-pressed, var(--dsw-alias-interactive-bg-hover));\n}\n.dww-action:focus-visible {\n outline: 2px solid var(--dsw-alias-state-business-primary);\n outline-offset: 1px;\n}\n.dww-action:disabled { cursor: default; opacity: 0.6; }\n.dww-action--rail {\n width: 36px;\n height: 36px;\n color: var(--dsw-alias-label-primary);\n}\n.dww-action svg { flex: none; }\n\n/* The W letter mark of the sidebar action (sized for wide/rail buttons). */\n.dww-letter {\n font-size: 14px;\n font-weight: 600;\n line-height: 1;\n letter-spacing: 0.02em;\n user-select: none;\n}\n.dww-action--rail .dww-letter { font-size: 17px; }\n\n/* Full-viewport overlay + centered card (mirrors the platform Mask/Dialog). */\n.dww-overlay {\n position: fixed;\n inset: 0;\n z-index: 1000;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 24px;\n}\n.dww-overlay-mask {\n position: absolute;\n inset: 0;\n background: var(--dsw-alias-bg-mask-1);\n backdrop-filter: var(--dsw-mask-blur);\n}\n.dww-card {\n position: relative;\n z-index: 1;\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n width: min(440px, 100%);\n max-height: min(640px, 90vh);\n padding: 0 0 20px;\n overflow: hidden;\n border: 1px solid var(--dsw-alias-border-inverted);\n border-radius: 16px;\n background: var(--dsw-alias-bg-layer-2);\n box-shadow: var(--dsw-shadow-lv3);\n font-family: var(--dsw-font-family);\n}\n.dww-header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 8px;\n padding: 18px 20px 12px;\n}\n.dww-title {\n margin: 0;\n font-size: 16px;\n line-height: 24px;\n font-weight: 500;\n color: var(--dsw-alias-label-primary);\n}\n.dww-close {\n flex: none;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 28px;\n height: 28px;\n border: 0;\n border-radius: 8px;\n background: transparent;\n cursor: pointer;\n color: var(--dsw-alias-label-secondary);\n}\n.dww-close:hover { background: var(--dsw-alias-interactive-bg-hover); }\n.dww-body {\n display: flex;\n flex-direction: column;\n gap: 14px;\n min-width: 0;\n padding: 0 20px;\n overflow: auto;\n}\n.dww-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }\n.dww-field-label {\n font-size: 12px;\n line-height: 18px;\n color: var(--dsw-alias-label-secondary);\n}\n.dww-select {\n box-sizing: border-box;\n width: 100%;\n height: 36px;\n padding: 0 10px;\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 8px;\n background: var(--dsw-alias-bg-layer-3);\n color: var(--dsw-alias-label-primary);\n font-size: 14px;\n}\n.dww-input-row { display: flex; gap: 8px; align-items: center; }\n.dww-input {\n box-sizing: border-box;\n flex: 1;\n height: 36px;\n min-width: 0;\n padding: 0 10px;\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 8px;\n background: var(--dsw-alias-bg-layer-3);\n color: var(--dsw-alias-label-primary);\n font-size: 14px;\n}\n.dww-input:focus, .dww-select:focus {\n outline: none;\n border-color: var(--dsw-alias-state-business-primary);\n}\n.dww-check-btn {\n flex: none;\n height: 36px;\n padding: 0 12px;\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 8px;\n background: transparent;\n color: var(--dsw-alias-label-primary);\n cursor: pointer;\n font-size: 12px;\n}\n.dww-check-btn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }\n.dww-check-btn:disabled { cursor: default; }\n\n/* Directory browse list. */\n.dww-dirlist {\n display: flex;\n flex-direction: column;\n gap: 2px;\n box-sizing: border-box;\n min-height: 120px;\n max-height: 200px;\n padding: 4px;\n overflow: auto;\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 8px;\n background: var(--dsw-alias-bg-layer-3);\n}\n.dww-breadcrumb {\n padding: 0 4px;\n font-size: 12px;\n line-height: 18px;\n color: var(--dsw-alias-label-tertiary);\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n}\n.dww-dir-row {\n display: flex;\n align-items: center;\n gap: 8px;\n height: 28px;\n padding: 0 8px;\n border: 0;\n border-radius: 6px;\n background: transparent;\n color: var(--dsw-alias-label-primary);\n cursor: pointer;\n font-size: 13px;\n text-align: left;\n}\n.dww-dir-row:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }\n.dww-dir-row:disabled { cursor: default; color: var(--dsw-alias-label-tertiary); }\n.dww-dir-row--up { color: var(--dsw-alias-label-secondary); }\n.dww-dir-row svg { flex: none; color: var(--dsw-alias-label-tertiary); }\n.dww-dir-empty {\n padding: 8px;\n font-size: 12px;\n line-height: 18px;\n color: var(--dsw-alias-label-tertiary);\n}\n\n/* Error strip. */\n.dww-error {\n box-sizing: border-box;\n width: 100%;\n padding: 8px 10px;\n border: 1px solid var(--dsw-alias-state-error-primary);\n border-radius: 8px;\n color: var(--dsw-alias-state-error-primary);\n font-size: 12px;\n line-height: 18px;\n}\n.dww-retry {\n margin-left: 6px;\n border: 0;\n background: transparent;\n color: var(--dsw-alias-state-business-primary);\n cursor: pointer;\n font-size: 12px;\n text-decoration: underline;\n}\n\n/* Dialog footer actions. */\n.dww-actions {\n display: flex;\n align-items: center;\n justify-content: flex-end;\n gap: 8px;\n padding: 14px 20px 0;\n}\n.dww-btn {\n height: 36px;\n padding: 0 14px;\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 8px;\n background: transparent;\n color: var(--dsw-alias-label-primary);\n cursor: pointer;\n font-size: 14px;\n}\n.dww-btn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }\n.dww-btn--primary {\n border-color: transparent;\n background: var(--dsw-alias-button-primary-fill);\n color: var(--dsw-alias-label-primary-foreground);\n}\n.dww-btn--primary:hover:not(:disabled) { background: var(--dsw-alias-button-primary-hover); }\n.dww-btn:disabled { cursor: default; opacity: 0.6; }\n`\n\n/**\n * Idempotently inject the plugin stylesheet. No-op when a tag with the\n * plugin's data attribute already exists.\n */\nexport function ensureStyles(): void {\n if (typeof document === 'undefined') return\n if (document.querySelector(`style[${STYLE_TAG_DATA_ATTRIBUTE}]`) !== null) return\n const style = document.createElement('style')\n style.setAttribute('data-plugin', 'dsh-wsl-workspace')\n style.textContent = STYLES\n document.head.appendChild(style)\n}\n","/**\n * Bilingual dictionaries for the `wslWorkspace` locale namespace. Product copy\n * is Chinese; English is the parallel export for the standalone bundle.\n */\n\n/**\n * The `wslWorkspace` translations (Chinese, the primary product copy).\n */\nexport const zh: Record<string, string> = {\n 'action.add': 'WSL 工作区',\n 'action.title': '添加 WSL 工作区…',\n\n 'dialog.title': '添加 WSL 工作区',\n 'dialog.distro': '发行版',\n 'dialog.path': '路径',\n 'dialog.pathPlaceholder': '/home/',\n 'dialog.username': '用户名',\n 'dialog.usernamePlaceholder': '留空则使用发行版默认用户',\n 'dialog.loading': '正在加载…',\n 'dialog.browseEmpty': '此目录没有子文件夹',\n 'dialog.upLevel': '..(返回上级)',\n 'dialog.browse': '浏览',\n 'dialog.check': '检查',\n 'dialog.confirm': '创建并打开',\n 'dialog.cancel': '取消',\n 'dialog.retry': '重试',\n\n 'error.loadDistros': '无法获取 WSL 发行版列表,请确认已安装 WSL 且插件宿主端可用',\n 'error.rateLimited': '操作过于频繁,请稍后重试',\n 'error.loadDir': '无法浏览该目录',\n 'error.presetMissing': '未找到健康的 wsl preset,请确认插件宿主端已安装并配置该 preset',\n 'error.invalidPath': '请输入以 / 开头的 Linux 绝对路径',\n 'error.invalidUsername': '用户名无效:需以字母或下划线开头,仅含字母、数字、_、.、-',\n 'error.pathNotFound': '该路径不存在或是文件,请选择一个文件夹',\n 'error.createFailed': '创建工作区失败',\n}\n\n/**\n * The `wslWorkspace` translations (English).\n */\nexport const en: Record<string, string> = {\n 'action.add': 'WSL Workspace',\n 'action.title': 'Add WSL workspace…',\n\n 'dialog.title': 'Add WSL workspace',\n 'dialog.distro': 'Distro',\n 'dialog.path': 'Path',\n 'dialog.pathPlaceholder': '/home/',\n 'dialog.username': 'Username',\n 'dialog.usernamePlaceholder': 'Leave empty to use the distro default user',\n 'dialog.loading': 'Loading…',\n 'dialog.browseEmpty': 'No subdirectories here',\n 'dialog.upLevel': '.. (up)',\n 'dialog.browse': 'Browse',\n 'dialog.check': 'Check',\n 'dialog.confirm': 'Create & open',\n 'dialog.cancel': 'Cancel',\n 'dialog.retry': 'Retry',\n\n 'error.loadDistros': 'Could not list WSL distros; confirm WSL is installed and the plugin host side is reachable',\n 'error.rateLimited': 'Too many attempts; retry in a moment',\n 'error.loadDir': 'Could not browse this directory',\n 'error.presetMissing': 'No healthy \"wsl\" preset found; confirm the plugin host side installed and configured it',\n 'error.invalidPath': 'Enter an absolute Linux path starting with /',\n 'error.invalidUsername': 'Invalid username: start with a letter or underscore; only letters, digits, _ . -',\n 'error.pathNotFound': 'The path does not exist or is a file; choose a folder',\n 'error.createFailed': 'Failed to create the workspace',\n}\n","/**\n * Browser half of dsh-wsl-workspace. Registers the \"Add WSL workspace…\"\n * action beside Settings at the sidebar foot (the official\n * `sidebar.footer.action` slot), and keeps every blank session whose\n * workspace is a WSL UNC path composed from the WSL VARIANT of the mode it\n * currently runs (`standard` → `wsl-standard`, PTC → `wsl-code`, …) — so the\n * WSL execution world composes with any mode instead of being a mode itself.\n *\n * The binding is a watching effect rather than a one-shot dialog action so\n * EVERY creation path (this dialog, the workspace row's New Session, the\n * hero picker) converges on the WSL-backed composition automatically.\n */\n\nimport type { ConnectionHandle } from '@deepseek-ai/dsh-api-remotes/client'\n// Type-only: pulls the locale plugin's Context merge (ctx.locale), the\n// runtime's ClientContext, and the ui-sidebar SlotMap merge (the\n// 'sidebar.footer.action' entry) into this program.\nimport type {} from '@deepseek-ai/dsh-client-locale/client'\nimport type {} from '@deepseek-ai/dsh-client-ui-sidebar/client'\nimport type { ClientContext } from '@deepseek-ai/dsh-client-runtime/client'\nimport { check as checkApi, listDir as listDirApi, listDistros as listDistrosApi, setWorkspaceUser as setWorkspaceUserApi } from './api.ts'\nimport { AddWslWorkspace, type AddWslWorkspaceInjected } from './AddWslWorkspace.tsx'\nimport { ensureStyles } from './styles.ts'\nimport { zh, en } from './locales.ts'\nimport { isWslUnc } from '../shared/paths.ts'\n\n/** Required services (cordis fiber inject). */\nexport const inject = ['slots', 'locale', 'connection', 'sessions', 'workspaces']\n\n/** The legacy standalone WSL preset id (folded into the mode variants). */\nconst LEGACY_WSL_PRESET_ID = 'wsl'\n\n/**\n * Minimal sessions-service face. The renderer-host ctx merge types\n * `ctx.sessions` as its own SessionStore; the service the runtime actually\n * registers under that key satisfies this narrower contract, so the cast is\n * the documented boundary for a third-party plugin.\n */\ninterface WslSessionsFace {\n list: {\n getSnapshot(): { ids: string[]; byId: Record<string, { blank: boolean; cwd?: string; agentPreset?: string }> }\n subscribe(fn: () => void): () => void\n }\n noteAgentPreset(sessionId: string, agentPreset: string): void\n}\n\n/** Minimal workspaces-service face (create + start-session only). */\ninterface WslWorkspacesFace {\n create(input: { path: string }): Promise<{ workspaceId: string }>\n startSession(workspaceId?: string): void\n}\n\n/**\n * Mount the sidebar action and the auto-binding effect.\n * @param ctx - the browser plugin context.\n */\nexport function apply(ctx: ClientContext): void {\n const { api } = ctx.get('connection') as ConnectionHandle\n const workspaces = ctx.get('workspaces') as unknown as WslWorkspacesFace\n const sessions = ctx.get('sessions') as unknown as WslSessionsFace\n\n ensureStyles()\n\n ctx.effect(\n () => ctx.locale.register('wslWorkspace' as never, { zh, en }),\n 'dsh-wsl-workspace: locale dictionaries',\n )\n\n // The injected translate function reads the live locale preference.\n const t = ctx.locale.bind('wslWorkspace' as never) as unknown as (key: string, params?: Record<string, unknown>) => string\n\n const injected = (): AddWslWorkspaceInjected => ({\n t,\n checkPreset: async (): Promise<string | undefined> => {\n let roster\n try {\n const response = await api.agentPresets.list({})\n roster = response.result\n } catch (error) {\n return error instanceof Error ? error.message : String(error)\n }\n if (!roster.ok) return roster.error.message\n const healthy = roster.value.presets.find((entry: { id: string; broken?: string }) =>\n entry.id.startsWith('wsl-') && entry.broken === undefined)\n if (healthy === undefined) return t('error.presetMissing')\n return undefined\n },\n listDistros: () => listDistrosApi(),\n listDir: (distro, path) => listDirApi(distro, path),\n check: (distro, path) => checkApi(distro, path),\n createWorkspace: async (path, username): Promise<string | undefined> => {\n try {\n const view = await workspaces.create({ path })\n await setWorkspaceUserApi(path, username)\n workspaces.startSession(view.workspaceId)\n return undefined\n } catch (error) {\n return error instanceof Error ? error.message : String(error)\n }\n },\n })\n\n ctx.effect(\n () => ctx.slots.inject(\n 'sidebar.footer.action',\n () => ctx.slots.register(\n { name: 'sidebar.footer.action', id: 'wsl-workspace', inject: injected },\n AddWslWorkspace,\n ),\n ),\n 'dsh-wsl-workspace: sidebar footer action',\n )\n\n // Mode-variant binding: a blank session whose workspace is a WSL UNC path\n // is recomposed to the WSL variant of the mode it currently runs — plain\n // 标准 becomes `wsl-standard`, PTC becomes `wsl-code`, and so on — so the\n // WSL execution world composes with ANY mode instead of replacing it. The\n // host refuses non-blank sessions (agent-preset-locked), so the swap is\n // attempted at most a few times per session.\n ctx.effect(() => {\n const inFlight = new Set<string>()\n const attempts = new Map<string, number>()\n const MAX_ATTEMPTS = 3\n // Healthy `wsl-<mode>` variant ids plus the roster's default preset id\n // (what a session with no explicit choice gets). Refreshed periodically\n // so variants generated after this page loaded are picked up.\n let variants = new Set<string>()\n let defaultPreset: string | undefined\n const refreshRoster = (): void => {\n void api.agentPresets.list({}).then((response: {\n result: { ok: boolean; value: { presets: { id: string; broken?: string; isDefault?: boolean }[] } }\n }) => {\n const result = response.result\n if (!result.ok) return\n variants = new Set(result.value.presets\n .filter((entry: { id: string; broken?: string }) =>\n entry.broken === undefined && entry.id.startsWith('wsl-'))\n .map((entry: { id: string }) => entry.id))\n defaultPreset = result.value.presets.find(\n (entry: { id: string; isDefault?: boolean }) => entry.isDefault === true,\n )?.id\n }).catch(() => {\n // A failed roster read leaves the previous mapping; sessions stay on\n // their current composition until the next refresh.\n })\n }\n refreshRoster()\n const maybeBind = (): void => {\n const state = sessions.list.getSnapshot()\n for (const id of state.ids) {\n const summary = state.byId[id]\n if (summary === undefined || !summary.blank || summary.cwd === undefined) continue\n if (!isWslUnc(summary.cwd)) continue\n const current = summary.agentPreset\n if (current !== undefined && current.startsWith('wsl-')) continue\n // Legacy standalone `wsl` (now folded into the variants): remap it to\n // the default mode's variant, since the standalone preset no longer\n // exists in the roster.\n const base = current === LEGACY_WSL_PRESET_ID\n ? (defaultPreset ?? 'standard')\n : (current ?? defaultPreset)\n if (base === undefined || base === LEGACY_WSL_PRESET_ID || base.startsWith('wsl-')) continue\n const target = `wsl-${base.toLowerCase()}`\n if (!variants.has(target)) continue\n if (inFlight.has(id) || (attempts.get(id) ?? 0) >= MAX_ATTEMPTS) continue\n inFlight.add(id)\n void api.agentPresets.select({ sessionId: id, agentPreset: target })\n .then((response: { result: { ok: boolean } }) => {\n if (response.result.ok) sessions.noteAgentPreset(id, target)\n })\n .catch(() => {\n // A refused or aborted swap (session already produced output,\n // roster churn, reconnect) leaves the session on its current\n // composition; count the attempt so a stuck session stops\n // retrying after MAX_ATTEMPTS.\n attempts.set(id, (attempts.get(id) ?? 0) + 1)\n })\n .finally(() => {\n inFlight.delete(id)\n })\n }\n }\n maybeBind()\n const unsubscribe = sessions.list.subscribe(() => maybeBind())\n // Variants are generated at host boot; a page loaded before that would\n // never see them without a periodic refresh.\n const timer = window.setInterval(refreshRoster, 60_000)\n return () => {\n unsubscribe()\n window.clearInterval(timer)\n }\n }, 'dsh-wsl-workspace: WSL mode-variant binding')\n}\n"],"mappings":";;;;;;;;;;;;;;;EAOA,MAAM,WAAW;;EA4BjB,SAAS,aAAa,OAAwB;GAC5C,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;EAC9D;;;;;;;EAQA,eAAe,KAAQ,QAAgB,SAAkC,CAAC,GAAe;GACvF,IAAI;GACJ,IAAI;IACF,WAAW,MAAM,MAAM,UAAU;KAC/B,QAAQ;KACR,SAAS,EAAE,gBAAgB,mBAAmB;KAC9C,MAAM,KAAK,UAAU;MAAE;MAAQ;KAAO,CAAC;IACzC,CAAC;GACH,SAAS,OAAO;IAEd,MAAM,IAAI,MAAM,iCAAiC,aAAa,KAAK,GAAG;GACxE;GACA,IAAI;GACJ,IAAI;IACF,WAAY,MAAM,SAAS,KAAK;GAClC,QAAQ;IAEN,MAAM,IAAI,MAAM,oCAAoC,SAAS,OAAO,EAAE;GACxE;GACA,IAAI,CAAC,SAAS,IAAI,MAAM,IAAI,MAAM,SAAS,KAAK;GAChD,OAAO,SAAS;EAClB;;;;;EAMA,eAAsB,cAAiC;GACrD,OAAO,KAAe,eAAe,CAAC,CAAC;EACzC;;;;;;;EAQA,eAAsB,QAAQ,QAAgB,MAAsC;GAClF,OAAO,KAAoB,WAAW;IAAE;IAAQ;GAAK,CAAC;EACxD;;;;;;;EAQA,eAAsB,MAAM,QAAgB,MAAqC;GAC/E,OAAO,KAAmB,SAAS;IAAE;IAAQ;GAAK,CAAC;EACrD;;;;;;EAOA,eAAsB,iBAAiB,MAAc,UAAiC;GACpF,OAAO,KAAW,WAAW;IAAE;IAAM;GAAS,CAAC;EACjD;;;;EC5FA,MAAM,YAAY,CAAC,iBAAoB,MAAe;;;;;;;;EAiBtD,SAAgB,YAAY,KAAkC;GAC5D,MAAM,aAAa,IAAI,QAAQ,OAA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;OAAE,WAAW;OAAI,aAAa;MAAO,CAAC,CAAC,CACjE,MAAM,aAA0C;OAC/C,IAAI,SAAS,OAAO,IAAI,SAAS,gBAAgB,IAAI,MAAM;MAC7D,CAAC,CAAC,CACD,YAAY;OAKX,SAAS,IAAI,KAAK,SAAS,IAAI,EAAE,KAAK,KAAK,CAAC;MAC9C,CAAC,CAAC,CACD,cAAc;OACb,SAAS,OAAO,EAAE;MACpB,CAAC;KACL;IACF;IACA,UAAU;IACV,MAAM,cAAc,SAAS,KAAK,gBAAgB,UAAU,CAAC;IAG7D,MAAM,QAAQ,OAAO,YAAY,eAAe,GAAM;IACtD,aAAa;KACX,YAAY;KACZ,OAAO,cAAc,KAAK;IAC5B;GACF,GAAG,6CAA6C;EAClD"}
1
+ {"version":3,"file":"client.js","names":["listDistrosApi","listDirApi","checkApi","setWorkspaceUserApi"],"sources":["../src/client/api.ts","../src/shared/paths.ts","../src/client/AddWslWorkspace.tsx","../src/client/styles.ts","../src/client/locales.ts","../src/client/index.ts"],"sourcesContent":["/**\n * Thin fetch client for the Host plugin route. The browser calls\n * POST /wsl-workspace/api with a `{ method, params }` envelope and the Host\n * answers `{ ok: true, value }` or `{ ok: false, error }`.\n */\n\n/** Relative route the Host half registers (same-origin with the web server). */\nconst ENDPOINT = '/wsl-workspace/api'\n\n/** One directory entry as the Host lists it. */\nexport interface WslDirEntry {\n name: string\n kind: 'directory' | 'file' | 'other'\n}\n\n/** One directory level plus its breadcrumb ancestry. */\nexport interface WslDirListing {\n /** The listed absolute Linux path. */\n path: string\n /** Parent Linux path, or null at the filesystem root. */\n parent: string | null\n /** The level's children (in name order; the client filters to directories). */\n entries: WslDirEntry[]\n}\n\n/** Existence/directory check result for one Linux path. */\nexport interface WslPathCheck {\n exists: boolean\n isDirectory: boolean\n}\n\n/** Wire envelope the Host route answers with. */\ntype Envelope<T> = { ok: true; value: T } | { ok: false; error: string }\n\n/** Human text for an unknown rejection, reusing the repository's idiom. */\nfunction errorMessage(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n\n/**\n * Perform one POST call and unwrap the envelope.\n * @param method - the Host method name.\n * @param params - the method payload.\n * @returns the unwrapped value, or throws an Error on network or `ok:false`.\n */\nasync function call<T>(method: string, params: Record<string, unknown> = {}): Promise<T> {\n let response: Response\n try {\n response = await fetch(ENDPOINT, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({ method, params }),\n })\n } catch (error) {\n // The transport refused before answering (offline, origin mismatch, 404).\n throw new Error(`wsl-workspace request failed: ${errorMessage(error)}`)\n }\n let envelope: Envelope<T>\n try {\n envelope = (await response.json()) as Envelope<T>\n } catch {\n // A non-JSON body means a proxy/loader answered instead of the Host route.\n throw new Error(`wsl-workspace answered non-JSON (${response.status})`)\n }\n if (!envelope.ok) throw new Error(envelope.error)\n return envelope.value\n}\n\n/**\n * List the WSL distros installed on the host.\n * @returns distro names in registry order.\n */\nexport async function listDistros(): Promise<string[]> {\n return call<string[]>('listDistros', {})\n}\n\n/**\n * List one directory level inside a distro.\n * @param distro - distro name.\n * @param path - absolute Linux directory to list.\n * @returns the level's listing with ancestry.\n */\nexport async function listDir(distro: string, path: string): Promise<WslDirListing> {\n return call<WslDirListing>('listDir', { distro, path })\n}\n\n/**\n * Check whether a Linux path exists and is a directory.\n * @param distro - distro name.\n * @param path - absolute Linux path.\n * @returns existence and directory facts.\n */\nexport async function check(distro: string, path: string): Promise<WslPathCheck> {\n return call<WslPathCheck>('check', { distro, path })\n}\n\n/**\n * Store (or clear, with an empty string) the username of one WSL workspace.\n * @param path - the workspace UNC path.\n * @param username - the Linux username; empty string clears the stored value.\n */\nexport async function setWorkspaceUser(path: string, username: string): Promise<void> {\n return call<void>('setUser', { path, username })\n}\n","/**\n * WSL path helpers shared by the client and host halves. Pure and\n * dependency-free so both planes can import them without a runtime edge.\n */\n\n/** WSL2 default loopback bridge host: `\\\\wsl.localhost\\<distro>\\...`. */\nconst WSL_LOCALHOST_HOST = 'wsl.localhost'\n/** Legacy WSL interop host: `\\\\wsl$\\<distro>\\...`. */\nconst WSL_LEGACY_HOST = 'wsl$'\n\n/** The two UNC hosts WSL exposes a distribution's filesystem under. */\nconst UNC_HOSTS = [WSL_LOCALHOST_HOST, WSL_LEGACY_HOST]\n\n/** One WSL workspace coordinate parsed out of a UNC path. */\nexport interface WslUncTarget {\n /** Distro name (e.g. `Ubuntu`) as `wsl -l -q` reports it. */\n readonly distro: string\n /** Normalized absolute Linux path (leading `/`; no trailing slash except root). */\n readonly linuxPath: string\n}\n\n/**\n * Parse a WSL UNC path into its distro and Linux path. Accepts the WSL2\n * `\\\\wsl.localhost\\<distro>\\<linux>` form, the legacy `\\\\wsl$\\<distro>\\<linux>`\n * interop form, and forward-slash spellings of either.\n * @param raw - candidate absolute path.\n * @returns the parsed target, or null when the path is not a WSL UNC.\n */\nexport function parseWslUnc(raw: string): WslUncTarget | null {\n const normalized = raw.replace(/\\\\/g, '/').replace(/\\/\\/+/g, '//')\n if (!normalized.startsWith('//')) return null\n const segments = normalized.slice(2).split('/')\n const host = (segments[0] ?? '').toLowerCase()\n if (!UNC_HOSTS.includes(host)) return null\n const distro = segments[1] ?? ''\n if (distro === '') return null\n const rest = segments.slice(2).filter(segment => segment.length > 0)\n return { distro, linuxPath: `/${rest.join('/')}` }\n}\n\n/**\n * Whether a path resolves into a WSL distro through either UNC form.\n * @param raw - candidate absolute path.\n * @returns whether the path parses as a WSL UNC.\n */\nexport function isWslUnc(raw: string): boolean {\n return parseWslUnc(raw) !== null\n}\n\n/**\n * Translate a WSL UNC path to the absolute Linux path a process inside the\n * distribution can open. Throws on non-WSL input: callers rely on this\n * conversion to hand paths to the Linux world, so a silent pass-through\n * would hand a Windows path to bash.\n * @param uncPath - a path {@link parseWslUnc} accepts.\n * @returns the absolute Linux path.\n */\nexport function uncToLinux(uncPath: string): string {\n const parts = parseWslUnc(uncPath)\n if (parts === null) {\n throw new Error(`wsl-workspace: \"${uncPath}\" is not a WSL UNC path`)\n }\n return parts.linuxPath\n}\n\n/**\n * Normalize a Linux absolute path for the Host: collapse repeated slashes and\n * strip a trailing slash (root becomes `/`).\n * @param path - absolute Linux path.\n * @returns the normalized path.\n */\nexport function normalizeLinuxPath(path: string): string {\n const collapsed = path.replace(/\\/+/g, '/')\n return collapsed === '/' ? '/' : collapsed.replace(/\\/$/, '')\n}\n\n/**\n * Whether a path is an absolute, non-empty Linux path.\n * @param path - candidate.\n * @returns whether it starts with `/` and contains no NUL.\n */\nexport function isAbsoluteLinuxPath(path: string): boolean {\n return path.startsWith('/') && !path.includes('\\0')\n}\n\n/**\n * Join a distro and a Linux absolute path into the WSL2 UNC form used as the\n * workspace identity (`\\\\wsl.localhost\\<distro>\\<linux>`, backslash segments).\n * @param distro - distro name.\n * @param linuxPath - absolute Linux path (leading `/`).\n * @returns the UNC path.\n */\nexport function joinUnc(distro: string, linuxPath: string): string {\n if (!isAbsoluteLinuxPath(linuxPath)) {\n throw new Error(`wsl-workspace: cannot map a non-absolute Linux path \"${linuxPath}\" to UNC`)\n }\n // Defense in depth: a distribution name with separators or dot-dirs would\n // escape the `\\\\wsl.localhost\\` share structure (the host route validates\n // wire-supplied names too; every other caller passes through here).\n if (distro === '' || distro === '.' || distro === '..' || /[\\\\/]/.test(distro)) {\n throw new Error(`wsl-workspace: invalid distribution name \"${distro}\"`)\n }\n const normalized = linuxPath.replace(/\\/+/g, '/').replace(/\\/$/, '')\n const withoutLeading = normalized.startsWith('/') ? normalized.slice(1) : normalized\n const windowsSegments = withoutLeading.replace(/\\//g, '\\\\')\n const suffix = windowsSegments === '' ? '' : `\\\\${windowsSegments}`\n return `\\\\\\\\wsl.localhost\\\\${distro}${suffix}`\n}\n\n/**\n * Translate a Windows drive path to the drvfs mount path WSL distributions\n * conventionally expose it at (`C:\\foo` → `/mnt/c/foo`). Only single-letter\n * drives under `/mnt` are mapped; custom mount points are out of scope.\n * @param path - the candidate Windows path.\n * @returns the `/mnt/<drive>/…` path, or `null` for non-drive paths.\n */\nexport function windowsToMntPath(path: string): string | null {\n const match = /^([A-Za-z]):[\\\\/](.*)$/.exec(path)\n if (match === null) return null\n const rest = (match[2] ?? '').replace(/\\\\/g, '/').replace(/\\/+/g, '/').replace(/\\/$/, '')\n return `/mnt/${(match[1] ?? '').toLowerCase()}${rest === '' ? '' : `/${rest}`}`\n}\n\n/**\n * Translate a `/mnt/<drive>/…` path back to its Windows drive path.\n * @param linuxPath - the candidate Linux path.\n * @returns the `X:\\…` drive path, or `null` when the path is not a drvfs mount.\n */\nexport function mntToWindowsPath(linuxPath: string): string | null {\n const match = /^\\/mnt\\/([a-zA-Z])(?:\\/(.*))?$/.exec(linuxPath)\n if (match === null) return null\n const rest = (match[2] ?? '').replace(/\\//g, '\\\\')\n return `${(match[1] ?? '').toUpperCase()}:\\\\${rest}`\n}\n\n/**\n * True when a value is a Windows-shaped path (drive or UNC), which is how\n * the shell executor decides the WSLENV `/p` translation flag: only Windows\n * path values need translation when they cross into the Linux process.\n * @param value - the environment value to classify.\n * @returns whether the value looks like a Windows path.\n */\nexport function isWindowsPathShaped(value: string): boolean {\n return /^[A-Za-z]:[\\\\/]/.test(value) || value.startsWith('\\\\\\\\')\n}\n\n/** Linux username shape for `wsl.exe -u`: starts with a letter or underscore, then letters/digits/`_`/`.`/`-` (max 64). */\nconst WSL_USERNAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_.-]{0,63}$/\n\n/**\n * Whether a value is a safe Linux username for `wsl.exe -u`. The check is\n * strict on purpose: a value starting with `-` could be parsed as a wsl.exe\n * option instead of a username.\n * @param value - candidate username.\n * @returns whether it matches the Linux username shape.\n */\nexport function isValidWslUsername(value: string): boolean {\n return WSL_USERNAME_PATTERN.test(value)\n}\n","/**\n * Sidebar footer action that opens the \"Add WSL workspace\" dialog. In the\n * wide sidebar it renders a labeled row; in the 56px rail it collapses to a\n * 36px icon button (both honor the shell's `{ wide }` owner share).\n *\n * Registration omits the typed `locale:` seat (the `wslWorkspace` namespace is\n * not merged into `LocaleNamespaceMap`), so the injected face carries the\n * bound translate function instead.\n */\n\nimport type * as React from 'react'\nimport { useEffect, useRef, useState, type UIEventHandler } from 'react'\nimport { isAbsoluteLinuxPath, isValidWslUsername, joinUnc, normalizeLinuxPath } from '../shared/paths.ts'\nimport type { WslDirListing, WslPathCheck } from './api.ts'\n\n/** Result-level shape of a browse/check/list call we surface uniformly. */\ninterface ApiCall<T> {\n value: T\n}\n\n/** The inject face: plain data + callbacks the dialog drives. */\nexport interface AddWslWorkspaceInjected {\n /**\n * Confirm the deployment exposes a healthy `wsl` preset.\n * @returns undefined when healthy, else a Chinese/English message to show.\n */\n checkPreset(): Promise<string | undefined>\n /** List the WSL distros installed on the host. */\n listDistros(): Promise<string[]>\n /** List one Linux directory level inside a distro. */\n listDir(distro: string, path: string): Promise<WslDirListing>\n /** Check a Linux path's existence/directory facts. */\n check(distro: string, path: string): Promise<WslPathCheck>\n /**\n * Register a workspace over a WSL UNC path and start a session in it.\n * @param path - the `\\\\wsl.localhost\\<distro>\\...` UNC path.\n * @param username - optional Linux user for the session (empty = distro default).\n * @returns undefined on success, else a message to show.\n */\n createWorkspace(path: string, username: string): Promise<string | undefined>\n /** Translate a `wslWorkspace` dictionary key in the dialog's current language. */\n t: (key: string, params?: Record<string, unknown>) => string\n /** The dialog language at injection time; the component mirrors it as its initial state. */\n language: 'zh' | 'en'\n /** Switch the dialog language for every injected helper (defaults to zh). */\n setLanguage(language: 'zh' | 'en'): void\n}\n\n/** Full component props: the owner share plus the injected face. */\nexport interface AddWslWorkspaceProps extends AddWslWorkspaceInjected {\n /** Whether the sidebar renders wide content (false = 56px rail). */\n wide: boolean\n}\n\n/**\n * Build the Linux child path one level below a parent, for the breadcrumb/\n * browse drill.\n * @param parent - the currently listed absolute path (`/` for root).\n * @param name - the child directory name.\n * @returns the child's absolute Linux path.\n */\nexport function dirChildPath(parent: string, name: string): string {\n return parent === '/' ? `/${name}` : `${parent}/${name}`\n}\n\n/** A tiny inline terminal glyph for the dialog's directory rows. */\nfunction WslGlyph({ size = 16 }: { size?: number }): React.ReactElement {\n return (\n <svg width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" aria-hidden=\"true\">\n <rect x=\"2.5\" y=\"4.5\" width=\"19\" height=\"15\" rx=\"2.5\" stroke=\"currentColor\" strokeWidth=\"1.6\" />\n <path d=\"M6 9l3.2 2.6L6 14\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n <path d=\"M12 14h5\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" />\n </svg>\n )\n}\n\n/**\n * The \"Add WSL workspace…\" footer action and its dialog.\n * @param props - owner share + injected face.\n */\nexport function AddWslWorkspace({ wide, language, setLanguage, t, checkPreset, listDistros, listDir, check, createWorkspace }: AddWslWorkspaceProps): React.ReactElement | null {\n const [open, setOpen] = useState(false)\n const [opening, setOpening] = useState(false)\n const [lang, setLang] = useState<'zh' | 'en'>(language)\n const [distros, setDistros] = useState<string[]>([])\n const [distro, setDistro] = useState('')\n const [pathInput, setPathInput] = useState('/home/')\n const [username, setUsername] = useState('')\n const [listing, setListing] = useState<WslDirListing | null>(null)\n const [browsePath, setBrowsePath] = useState('/')\n const [browsing, setBrowsing] = useState(false)\n const [error, setError] = useState<string | null>(null)\n const [busy, setBusy] = useState(false)\n // Monotone browse-request sequence: stale responses for a superseded browse are dropped.\n const browseSeq = useRef(0)\n\n const refreshBrowse = async (root: string, targetDistro: string): Promise<void> => {\n const seq = ++browseSeq.current\n setBrowsing(true)\n setBrowsePath(root)\n try {\n const value = await listDir(targetDistro, root)\n if (seq === browseSeq.current) setListing(value)\n } catch {\n // A failed browse (permission, missing dir) is non-fatal: keep old listing.\n if (seq === browseSeq.current) {\n setListing(null)\n setError((previous) => previous ?? t('error.loadDir'))\n }\n } finally {\n if (seq === browseSeq.current) setBrowsing(false)\n }\n }\n\n useEffect(() => {\n if (!open) return\n let cancelled = false\n setError(null)\n setOpening(true)\n void (async () => {\n let presetIssue: string | undefined\n try {\n presetIssue = await checkPreset()\n } catch {\n presetIssue = t('error.loadDistros')\n }\n let names: string[]\n try {\n names = await listDistros()\n } catch {\n if (cancelled) return\n setOpening(false)\n setError(t('error.loadDistros'))\n return\n }\n if (cancelled) return\n setDistros(names)\n const first = names[0] ?? ''\n setDistro(first)\n // The default browse root walks from `/`; the input defaults to `/home/`.\n setBrowsing(true)\n setOpening(false)\n if (presetIssue !== undefined) setError(presetIssue)\n if (first !== '') void refreshBrowse('/', first)\n })()\n return () => { cancelled = true }\n // eslint-disable-next-line react-hooks/exhaustive-deps -- run once per open against current t.\n }, [open])\n\n useEffect(() => {\n if (!open) return\n const onKey = (event: KeyboardEvent): void => {\n if (event.key === 'Escape' && !busy) setOpen(false)\n }\n window.addEventListener('keydown', onKey)\n return () => window.removeEventListener('keydown', onKey)\n }, [open, busy])\n\n if (!open) {\n // A W-letter action beside Settings at the sidebar foot; the title\n // carries the label in both wide and rail states.\n return (\n <button\n type=\"button\"\n className={wide ? 'dww-action dww-action--wide' : 'dww-action dww-action--rail'}\n title={t('action.title')}\n aria-label={t('action.title')}\n onClick={() => setOpen(true)}\n >\n <span className=\"dww-letter\" aria-hidden=\"true\">W</span>\n </button>\n )\n }\n\n const onDrill = (name: string): void => {\n const next = dirChildPath(listing?.path ?? browsePath, name)\n setPathInput(next)\n void refreshBrowse(next, distro)\n }\n\n const onUp = (): void => {\n const parent = listing?.parent ?? null\n if (parent === null) return\n setPathInput(parent)\n void refreshBrowse(parent, distro)\n }\n\n const onDistroChange = (value: string): void => {\n setDistro(value)\n void refreshBrowse(browsePath, value)\n }\n\n const onCheck = async (): Promise<void> => {\n const path = normalizeLinuxPath(pathInput)\n setError(null)\n if (!isAbsoluteLinuxPath(path) || path === '/') {\n setError(t('error.invalidPath'))\n return\n }\n let facts: WslPathCheck\n try {\n facts = await check(distro, path)\n } catch {\n setError(t('error.pathNotFound'))\n return\n }\n if (!facts.exists || !facts.isDirectory) {\n setError(t('error.pathNotFound'))\n return\n }\n void refreshBrowse(path, distro)\n }\n\n const onConfirm = async (): Promise<void> => {\n const path = normalizeLinuxPath(pathInput)\n setError(null)\n if (!isAbsoluteLinuxPath(path) || path === '/') {\n // A workspace at the distribution root would make every session start\n // at `/`; the check flow rejects it and confirm must agree.\n setError(t('error.invalidPath'))\n return\n }\n const user = username.trim()\n if (user !== '' && !isValidWslUsername(user)) {\n setError(t('error.invalidUsername'))\n return\n }\n setBusy(true)\n try {\n let facts: WslPathCheck\n try {\n facts = await check(distro, path)\n } catch {\n setError(t('error.pathNotFound'))\n return\n }\n if (!facts.exists || !facts.isDirectory) {\n setError(t('error.pathNotFound'))\n return\n }\n const failure = await createWorkspace(joinUnc(distro, path), user)\n if (failure !== undefined) {\n setError(failure)\n return\n }\n setOpen(false)\n } finally {\n setBusy(false)\n }\n }\n\n const children = (listing?.entries.filter(entry => entry.kind === 'directory') ?? []).map(entry => entry.name)\n const maskClick = (): void => { if (!busy) setOpen(false) }\n const onLanguageChange = (next: 'zh' | 'en'): void => {\n setLang(next)\n setLanguage(next)\n }\n const listScroll: UIEventHandler<HTMLDivElement> = () => { /* scroll container handles overflow */ }\n\n return (\n <div className=\"dww-overlay\">\n <div className=\"dww-overlay-mask\" onClick={maskClick} />\n <div className=\"dww-card\" role=\"dialog\" aria-modal=\"true\" aria-label={t('dialog.title')}>\n <div className=\"dww-header\">\n <h2 className=\"dww-title\">{t('dialog.title')}</h2>\n <div className=\"dww-header-actions\">\n <div className=\"dww-lang\" role=\"group\" aria-label=\"Language\">\n <button\n type=\"button\"\n className={lang === 'zh' ? 'dww-lang-btn dww-lang-btn--active' : 'dww-lang-btn'}\n disabled={busy}\n onClick={() => onLanguageChange('zh')}\n >\n 中文\n </button>\n <button\n type=\"button\"\n className={lang === 'en' ? 'dww-lang-btn dww-lang-btn--active' : 'dww-lang-btn'}\n disabled={busy}\n onClick={() => onLanguageChange('en')}\n >\n EN\n </button>\n </div>\n <button type=\"button\" className=\"dww-close\" aria-label={t('dialog.cancel')} onClick={maskClick}>\n ✕\n </button>\n </div>\n </div>\n <div className=\"dww-body\">\n {error !== null ? (\n <div className=\"dww-error\">\n {error}\n <button type=\"button\" className=\"dww-retry\" onClick={() => setError(null)}>{t('dialog.retry')}</button>\n </div>\n ) : null}\n <div className=\"dww-field\">\n <label className=\"dww-field-label\" htmlFor=\"dww-distro\">{t('dialog.distro')}</label>\n <select\n id=\"dww-distro\"\n className=\"dww-select\"\n value={distro}\n disabled={opening || busy}\n onChange={event => onDistroChange(event.target.value)}\n >\n {distros.length === 0\n ? <option value=\"\">{opening ? t('dialog.loading') : ''}</option>\n : distros.map(name => <option key={name} value={name}>{name}</option>)}\n </select>\n </div>\n <div className=\"dww-field\">\n <label className=\"dww-field-label\" htmlFor=\"dww-path\">{t('dialog.path')}</label>\n <div className=\"dww-input-row\">\n <input\n id=\"dww-path\"\n className=\"dww-input\"\n value={pathInput}\n placeholder={t('dialog.pathPlaceholder')}\n disabled={opening || busy}\n onChange={event => setPathInput(event.target.value)}\n />\n <button type=\"button\" className=\"dww-check-btn\" disabled={opening || busy} onClick={() => void onCheck()}>\n {t('dialog.check')}\n </button>\n </div>\n </div>\n <div className=\"dww-field\">\n <label className=\"dww-field-label\" htmlFor=\"dww-username\">{t('dialog.username')}</label>\n <input\n id=\"dww-username\"\n className=\"dww-input\"\n value={username}\n placeholder={t('dialog.usernamePlaceholder')}\n disabled={opening || busy}\n autoComplete=\"off\"\n spellCheck={false}\n onChange={event => setUsername(event.target.value)}\n />\n </div>\n <div className=\"dww-feedback\">\n <div className=\"dww-breadcrumb\">{browsePath}</div>\n <div className=\"dww-dirlist\" onScroll={listScroll}>\n {browsing ? <div className=\"dww-dir-empty\">{t('dialog.loading')}</div> : (\n listing?.parent !== null && listing !== null\n ? (\n <button type=\"button\" className=\"dww-dir-row dww-dir-row--up\" onClick={onUp}>\n <WslGlyph size={14} />\n <span>{t('dialog.upLevel')}</span>\n </button>\n )\n : null\n )}\n {!browsing && (children.length === 0)\n ? <div className=\"dww-dir-empty\">{t('dialog.browseEmpty')}</div>\n : children.map(name => (\n <button type=\"button\" key={name} className=\"dww-dir-row\" onClick={() => onDrill(name)}>\n <WslGlyph size={14} />\n <span>{name}</span>\n </button>\n ))}\n </div>\n </div>\n </div>\n <div className=\"dww-actions\">\n <button type=\"button\" className=\"dww-btn\" disabled={busy} onClick={maskClick}>{t('dialog.cancel')}</button>\n <button type=\"button\" className=\"dww-btn dww-btn--primary\" disabled={busy || opening} onClick={() => void onConfirm()}>\n {busy ? t('dialog.loading') : t('dialog.confirm')}\n </button>\n </div>\n </div>\n </div>\n )\n}\n\nexport type { ApiCall }\n","/**\n * Third-party stylesheet injection for the WSL workspace UI (the plugin\n * builds no CSS bundle, so styles are injected as one idempotent `<style>`).\n * Colors derive exclusively from the `--dsw-*` design tokens.\n */\n\nconst STYLE_TAG_DATA_ATTRIBUTE = 'data-plugin=\"dsh-wsl-workspace\"'\n\nconst STYLES = `\n/* Sidebar-foot icon action beside Settings (28px round in the wide sidebar,\n 36px round in the rail), matching the shell's icon-button language. */\n.dww-action {\n flex: none;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 28px;\n height: 28px;\n border: none;\n border-radius: 50%;\n padding: 0;\n background: transparent;\n cursor: pointer;\n color: var(--dsw-alias-label-secondary);\n transition:\n background-color 120ms var(--dsw-ease-in-out, ease-in-out),\n color 120ms var(--dsw-ease-in-out, ease-in-out);\n}\n.dww-action:hover:not(:disabled) {\n background: var(--dsw-alias-interactive-bg-hover);\n color: var(--dsw-alias-label-secondary);\n}\n.dww-action:active:not(:disabled) {\n background: var(--dsw-alias-interactive-bg-pressed, var(--dsw-alias-interactive-bg-hover));\n}\n.dww-action:focus-visible {\n outline: 2px solid var(--dsw-alias-state-business-primary);\n outline-offset: 1px;\n}\n.dww-action:disabled { cursor: default; opacity: 0.6; }\n.dww-action--rail {\n width: 36px;\n height: 36px;\n color: var(--dsw-alias-label-primary);\n}\n.dww-action svg { flex: none; }\n\n/* The W letter mark of the sidebar action (sized for wide/rail buttons). */\n.dww-letter {\n font-size: 14px;\n font-weight: 600;\n line-height: 1;\n letter-spacing: 0.02em;\n user-select: none;\n}\n.dww-action--rail .dww-letter { font-size: 17px; }\n\n/* Full-viewport overlay + centered card (mirrors the platform Mask/Dialog). */\n.dww-overlay {\n position: fixed;\n inset: 0;\n z-index: 1000;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 24px;\n}\n.dww-overlay-mask {\n position: absolute;\n inset: 0;\n background: var(--dsw-alias-bg-mask-1);\n backdrop-filter: var(--dsw-mask-blur);\n}\n.dww-card {\n position: relative;\n z-index: 1;\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n width: min(440px, 100%);\n max-height: min(640px, 90vh);\n padding: 0 0 20px;\n overflow: hidden;\n border: 1px solid var(--dsw-alias-border-inverted);\n border-radius: 16px;\n background: var(--dsw-alias-bg-layer-2);\n box-shadow: var(--dsw-shadow-lv3);\n font-family: var(--dsw-font-family);\n}\n.dww-header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 8px;\n padding: 18px 20px 12px;\n}\n.dww-header-actions {\n display: flex;\n align-items: center;\n gap: 8px;\n}\n/* Built-in dialog language switch (中文 / EN), independent of the app locale. */\n.dww-lang {\n display: inline-flex;\n overflow: hidden;\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 8px;\n}\n.dww-lang-btn {\n height: 28px;\n padding: 0 10px;\n border: 0;\n background: transparent;\n color: var(--dsw-alias-label-secondary);\n cursor: pointer;\n font-size: 12px;\n}\n.dww-lang-btn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }\n.dww-lang-btn--active {\n background: var(--dsw-alias-button-primary-fill);\n color: var(--dsw-alias-label-primary-foreground);\n}\n.dww-lang-btn:disabled { cursor: default; opacity: 0.6; }\n.dww-title {\n margin: 0;\n font-size: 16px;\n line-height: 24px;\n font-weight: 500;\n color: var(--dsw-alias-label-primary);\n}\n.dww-close {\n flex: none;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 28px;\n height: 28px;\n border: 0;\n border-radius: 8px;\n background: transparent;\n cursor: pointer;\n color: var(--dsw-alias-label-secondary);\n}\n.dww-close:hover { background: var(--dsw-alias-interactive-bg-hover); }\n.dww-body {\n display: flex;\n flex-direction: column;\n gap: 14px;\n min-width: 0;\n padding: 0 20px;\n overflow: auto;\n}\n.dww-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }\n.dww-field-label {\n font-size: 12px;\n line-height: 18px;\n color: var(--dsw-alias-label-secondary);\n}\n.dww-select {\n box-sizing: border-box;\n width: 100%;\n height: 36px;\n padding: 0 10px;\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 8px;\n background: var(--dsw-alias-bg-layer-3);\n color: var(--dsw-alias-label-primary);\n font-size: 14px;\n}\n.dww-input-row { display: flex; gap: 8px; align-items: center; }\n.dww-input {\n box-sizing: border-box;\n flex: 1;\n height: 36px;\n min-width: 0;\n padding: 0 10px;\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 8px;\n background: var(--dsw-alias-bg-layer-3);\n color: var(--dsw-alias-label-primary);\n font-size: 14px;\n}\n.dww-input:focus, .dww-select:focus {\n outline: none;\n border-color: var(--dsw-alias-state-business-primary);\n}\n.dww-check-btn {\n flex: none;\n height: 36px;\n padding: 0 12px;\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 8px;\n background: transparent;\n color: var(--dsw-alias-label-primary);\n cursor: pointer;\n font-size: 12px;\n}\n.dww-check-btn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }\n.dww-check-btn:disabled { cursor: default; }\n\n/* Directory browse list. */\n.dww-dirlist {\n display: flex;\n flex-direction: column;\n gap: 2px;\n box-sizing: border-box;\n min-height: 120px;\n max-height: 200px;\n padding: 4px;\n overflow: auto;\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 8px;\n background: var(--dsw-alias-bg-layer-3);\n}\n.dww-breadcrumb {\n padding: 0 4px;\n font-size: 12px;\n line-height: 18px;\n color: var(--dsw-alias-label-tertiary);\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n}\n.dww-dir-row {\n display: flex;\n align-items: center;\n gap: 8px;\n height: 28px;\n padding: 0 8px;\n border: 0;\n border-radius: 6px;\n background: transparent;\n color: var(--dsw-alias-label-primary);\n cursor: pointer;\n font-size: 13px;\n text-align: left;\n}\n.dww-dir-row:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }\n.dww-dir-row:disabled { cursor: default; color: var(--dsw-alias-label-tertiary); }\n.dww-dir-row--up { color: var(--dsw-alias-label-secondary); }\n.dww-dir-row svg { flex: none; color: var(--dsw-alias-label-tertiary); }\n.dww-dir-empty {\n padding: 8px;\n font-size: 12px;\n line-height: 18px;\n color: var(--dsw-alias-label-tertiary);\n}\n\n/* Error strip. */\n.dww-error {\n box-sizing: border-box;\n width: 100%;\n padding: 8px 10px;\n border: 1px solid var(--dsw-alias-state-error-primary);\n border-radius: 8px;\n color: var(--dsw-alias-state-error-primary);\n font-size: 12px;\n line-height: 18px;\n}\n.dww-retry {\n margin-left: 6px;\n border: 0;\n background: transparent;\n color: var(--dsw-alias-state-business-primary);\n cursor: pointer;\n font-size: 12px;\n text-decoration: underline;\n}\n\n/* Dialog footer actions. */\n.dww-actions {\n display: flex;\n align-items: center;\n justify-content: flex-end;\n gap: 8px;\n padding: 14px 20px 0;\n}\n.dww-btn {\n height: 36px;\n padding: 0 14px;\n border: 1px solid var(--dsw-alias-border-l2);\n border-radius: 8px;\n background: transparent;\n color: var(--dsw-alias-label-primary);\n cursor: pointer;\n font-size: 14px;\n}\n.dww-btn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }\n.dww-btn--primary {\n border-color: transparent;\n background: var(--dsw-alias-button-primary-fill);\n color: var(--dsw-alias-label-primary-foreground);\n}\n.dww-btn--primary:hover:not(:disabled) { background: var(--dsw-alias-button-primary-hover); }\n.dww-btn:disabled { cursor: default; opacity: 0.6; }\n`\n\n/**\n * Idempotently inject the plugin stylesheet. No-op when a tag with the\n * plugin's data attribute already exists.\n */\nexport function ensureStyles(): void {\n if (typeof document === 'undefined') return\n if (document.querySelector(`style[${STYLE_TAG_DATA_ATTRIBUTE}]`) !== null) return\n const style = document.createElement('style')\n style.setAttribute('data-plugin', 'dsh-wsl-workspace')\n style.textContent = STYLES\n document.head.appendChild(style)\n}\n","/**\n * Bilingual dictionaries for the `wslWorkspace` locale namespace. Product copy\n * is Chinese; English is the parallel export for the standalone bundle.\n */\n\n/**\n * The `wslWorkspace` translations (Chinese, the primary product copy).\n */\nexport const zh: Record<string, string> = {\n 'action.add': 'WSL 工作区',\n 'action.title': '添加 WSL 工作区…',\n\n 'dialog.title': '添加 WSL 工作区',\n 'dialog.distro': '发行版',\n 'dialog.path': '路径',\n 'dialog.pathPlaceholder': '/home/',\n 'dialog.username': '用户名',\n 'dialog.usernamePlaceholder': '留空则使用发行版默认用户',\n 'dialog.loading': '正在加载…',\n 'dialog.browseEmpty': '此目录没有子文件夹',\n 'dialog.upLevel': '..(返回上级)',\n 'dialog.browse': '浏览',\n 'dialog.check': '检查',\n 'dialog.confirm': '创建并打开',\n 'dialog.cancel': '取消',\n 'dialog.retry': '重试',\n\n 'error.loadDistros': '无法获取 WSL 发行版列表,请确认已安装 WSL 且插件宿主端可用',\n 'error.rateLimited': '操作过于频繁,请稍后重试',\n 'error.loadDir': '无法浏览该目录',\n 'error.presetMissing': '未找到健康的 wsl preset,请确认插件宿主端已安装并配置该 preset',\n 'error.invalidPath': '请输入以 / 开头的 Linux 绝对路径',\n 'error.invalidUsername': '用户名无效:需以字母或下划线开头,仅含字母、数字、_、.、-',\n 'error.pathNotFound': '该路径不存在或是文件,请选择一个文件夹',\n 'error.createFailed': '创建工作区失败',\n}\n\n/**\n * The `wslWorkspace` translations (English).\n */\nexport const en: Record<string, string> = {\n 'action.add': 'WSL Workspace',\n 'action.title': 'Add WSL workspace…',\n\n 'dialog.title': 'Add WSL workspace',\n 'dialog.distro': 'Distro',\n 'dialog.path': 'Path',\n 'dialog.pathPlaceholder': '/home/',\n 'dialog.username': 'Username',\n 'dialog.usernamePlaceholder': 'Leave empty to use the distro default user',\n 'dialog.loading': 'Loading…',\n 'dialog.browseEmpty': 'No subdirectories here',\n 'dialog.upLevel': '.. (up)',\n 'dialog.browse': 'Browse',\n 'dialog.check': 'Check',\n 'dialog.confirm': 'Create & open',\n 'dialog.cancel': 'Cancel',\n 'dialog.retry': 'Retry',\n\n 'error.loadDistros': 'Could not list WSL distros; confirm WSL is installed and the plugin host side is reachable',\n 'error.rateLimited': 'Too many attempts; retry in a moment',\n 'error.loadDir': 'Could not browse this directory',\n 'error.presetMissing': 'No healthy \"wsl\" preset found; confirm the plugin host side installed and configured it',\n 'error.invalidPath': 'Enter an absolute Linux path starting with /',\n 'error.invalidUsername': 'Invalid username: start with a letter or underscore; only letters, digits, _ . -',\n 'error.pathNotFound': 'The path does not exist or is a file; choose a folder',\n 'error.createFailed': 'Failed to create the workspace',\n}\n","/**\n * Browser half of dsh-wsl-workspace. Registers the \"Add WSL workspace…\"\n * action beside Settings at the sidebar foot (the official\n * `sidebar.footer.action` slot), and keeps every blank session whose\n * workspace is a WSL UNC path composed from the WSL VARIANT of the mode it\n * currently runs (`standard` → `wsl-standard`, PTC → `wsl-code`, …) — so the\n * WSL execution world composes with any mode instead of being a mode itself.\n *\n * The binding is a watching effect rather than a one-shot dialog action so\n * EVERY creation path (this dialog, the workspace row's New Session, the\n * hero picker) converges on the WSL-backed composition automatically.\n */\n\nimport type { ConnectionHandle } from '@deepseek-ai/dsh-api-remotes/client'\n// Type-only: pulls the locale plugin's Context merge (ctx.locale), the\n// runtime's ClientContext, and the ui-sidebar SlotMap merge (the\n// 'sidebar.footer.action' entry) into this program.\nimport type {} from '@deepseek-ai/dsh-client-locale/client'\nimport type {} from '@deepseek-ai/dsh-client-ui-sidebar/client'\nimport type { ClientContext } from '@deepseek-ai/dsh-client-runtime/client'\nimport { check as checkApi, listDir as listDirApi, listDistros as listDistrosApi, setWorkspaceUser as setWorkspaceUserApi } from './api.ts'\nimport { AddWslWorkspace, type AddWslWorkspaceInjected } from './AddWslWorkspace.tsx'\nimport { ensureStyles } from './styles.ts'\nimport { zh, en } from './locales.ts'\nimport { isWslUnc } from '../shared/paths.ts'\n\n/** Required services (cordis fiber inject). */\nexport const inject = ['slots', 'locale', 'connection', 'sessions', 'workspaces']\n\n/** The legacy standalone WSL preset id (folded into the mode variants). */\nconst LEGACY_WSL_PRESET_ID = 'wsl'\n\n/**\n * Minimal sessions-service face. The renderer-host ctx merge types\n * `ctx.sessions` as its own SessionStore; the service the runtime actually\n * registers under that key satisfies this narrower contract, so the cast is\n * the documented boundary for a third-party plugin.\n */\ninterface WslSessionsFace {\n list: {\n getSnapshot(): { ids: string[]; byId: Record<string, { blank: boolean; cwd?: string; agentPreset?: string }> }\n subscribe(fn: () => void): () => void\n }\n noteAgentPreset(sessionId: string, agentPreset: string): void\n}\n\n/** Minimal workspaces-service face (create + start-session only). */\ninterface WslWorkspacesFace {\n create(input: { path: string }): Promise<{ workspaceId: string }>\n startSession(workspaceId?: string): void\n}\n\n/**\n * Mount the sidebar action and the auto-binding effect.\n * @param ctx - the browser plugin context.\n */\nexport function apply(ctx: ClientContext): void {\n const { api } = ctx.get('connection') as ConnectionHandle\n const workspaces = ctx.get('workspaces') as unknown as WslWorkspacesFace\n const sessions = ctx.get('sessions') as unknown as WslSessionsFace\n\n ensureStyles()\n\n ctx.effect(\n () => ctx.locale.register('wslWorkspace' as never, { zh, en }),\n 'dsh-wsl-workspace: locale dictionaries',\n )\n\n // The dialog owns a built-in language switch (default zh) independent of\n // the app locale. Injected helpers read the current choice through this\n // mutable holder, so their messages (checkPreset etc.) follow the dialog's\n // language too.\n let language: 'zh' | 'en' = 'zh'\n const dictionaries = { zh, en }\n const t = (key: string, params?: Record<string, unknown>): string => {\n let text = dictionaries[language][key] ?? key\n if (params !== undefined) {\n for (const [name, value] of Object.entries(params)) {\n text = text.replaceAll(`{${name}}`, String(value))\n }\n }\n return text\n }\n const setLanguage = (next: 'zh' | 'en'): void => { language = next }\n\n const injected = (): AddWslWorkspaceInjected => ({\n language,\n setLanguage,\n t,\n checkPreset: async (): Promise<string | undefined> => {\n let roster\n try {\n const response = await api.agentPresets.list({})\n roster = response.result\n } catch (error) {\n return error instanceof Error ? error.message : String(error)\n }\n if (!roster.ok) return roster.error.message\n const healthy = roster.value.presets.find((entry: { id: string; broken?: string }) =>\n entry.id.startsWith('wsl-') && entry.broken === undefined)\n if (healthy === undefined) return t('error.presetMissing')\n return undefined\n },\n listDistros: () => listDistrosApi(),\n listDir: (distro, path) => listDirApi(distro, path),\n check: (distro, path) => checkApi(distro, path),\n createWorkspace: async (path, username): Promise<string | undefined> => {\n try {\n const view = await workspaces.create({ path })\n await setWorkspaceUserApi(path, username)\n workspaces.startSession(view.workspaceId)\n return undefined\n } catch (error) {\n return error instanceof Error ? error.message : String(error)\n }\n },\n })\n\n ctx.effect(\n () => ctx.slots.inject(\n 'sidebar.footer.action',\n () => ctx.slots.register(\n { name: 'sidebar.footer.action', id: 'wsl-workspace', inject: injected },\n AddWslWorkspace,\n ),\n ),\n 'dsh-wsl-workspace: sidebar footer action',\n )\n\n // Mode-variant binding: a blank session whose workspace is a WSL UNC path\n // is recomposed to the WSL variant of the mode it currently runs — plain\n // 标准 becomes `wsl-standard`, PTC becomes `wsl-code`, and so on — so the\n // WSL execution world composes with ANY mode instead of replacing it. The\n // host refuses non-blank sessions (agent-preset-locked), so the swap is\n // attempted at most a few times per session.\n ctx.effect(() => {\n const inFlight = new Set<string>()\n const attempts = new Map<string, number>()\n const MAX_ATTEMPTS = 3\n // Healthy `wsl-<mode>` variant ids plus the roster's default preset id\n // (what a session with no explicit choice gets). Refreshed periodically\n // so variants generated after this page loaded are picked up.\n let variants = new Set<string>()\n let defaultPreset: string | undefined\n const refreshRoster = (): void => {\n void api.agentPresets.list({}).then((response: {\n result: { ok: boolean; value: { presets: { id: string; broken?: string; isDefault?: boolean }[] } }\n }) => {\n const result = response.result\n if (!result.ok) return\n variants = new Set(result.value.presets\n .filter((entry: { id: string; broken?: string }) =>\n entry.broken === undefined && entry.id.startsWith('wsl-'))\n .map((entry: { id: string }) => entry.id))\n defaultPreset = result.value.presets.find(\n (entry: { id: string; isDefault?: boolean }) => entry.isDefault === true,\n )?.id\n }).catch(() => {\n // A failed roster read leaves the previous mapping; sessions stay on\n // their current composition until the next refresh.\n })\n }\n refreshRoster()\n const maybeBind = (): void => {\n const state = sessions.list.getSnapshot()\n for (const id of state.ids) {\n const summary = state.byId[id]\n if (summary === undefined || !summary.blank || summary.cwd === undefined) continue\n if (!isWslUnc(summary.cwd)) continue\n const current = summary.agentPreset\n if (current !== undefined && current.startsWith('wsl-')) continue\n // Legacy standalone `wsl` (now folded into the variants): remap it to\n // the default mode's variant, since the standalone preset no longer\n // exists in the roster.\n const base = current === LEGACY_WSL_PRESET_ID\n ? (defaultPreset ?? 'standard')\n : (current ?? defaultPreset)\n if (base === undefined || base === LEGACY_WSL_PRESET_ID || base.startsWith('wsl-')) continue\n const target = `wsl-${base.toLowerCase()}`\n if (!variants.has(target)) continue\n if (inFlight.has(id) || (attempts.get(id) ?? 0) >= MAX_ATTEMPTS) continue\n inFlight.add(id)\n void api.agentPresets.select({ sessionId: id, agentPreset: target })\n .then((response: { result: { ok: boolean } }) => {\n if (response.result.ok) sessions.noteAgentPreset(id, target)\n })\n .catch(() => {\n // A refused or aborted swap (session already produced output,\n // roster churn, reconnect) leaves the session on its current\n // composition; count the attempt so a stuck session stops\n // retrying after MAX_ATTEMPTS.\n attempts.set(id, (attempts.get(id) ?? 0) + 1)\n })\n .finally(() => {\n inFlight.delete(id)\n })\n }\n }\n maybeBind()\n const unsubscribe = sessions.list.subscribe(() => maybeBind())\n // Variants are generated at host boot; a page loaded before that would\n // never see them without a periodic refresh.\n const timer = window.setInterval(refreshRoster, 60_000)\n return () => {\n unsubscribe()\n window.clearInterval(timer)\n }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Aa;KACX,YAAY;KACZ,OAAO,cAAc,KAAK;IAC5B;GACF,GAAG,6CAA6C;EAClD"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-wsl-workspace",
3
3
  "description": "WSL workspace support for DeepSeek Harness: add a WSL workspace from the web GUI and run the whole agent session (bash + file tools) inside the WSL distribution, VS Code Remote-WSL style. No toolchain install inside WSL required.",
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
@@ -52,6 +52,8 @@
52
52
  "LICENSE",
53
53
  "NOTICE",
54
54
  "README.md",
55
- "README.zh.md"
55
+ "README.zh.md",
56
+ "image.png",
57
+ "image-1.png"
56
58
  ]
57
59
  }
@@ -38,8 +38,12 @@ export interface AddWslWorkspaceInjected {
38
38
  * @returns undefined on success, else a message to show.
39
39
  */
40
40
  createWorkspace(path: string, username: string): Promise<string | undefined>
41
- /** Translate a `wslWorkspace` dictionary key. */
41
+ /** Translate a `wslWorkspace` dictionary key in the dialog's current language. */
42
42
  t: (key: string, params?: Record<string, unknown>) => string
43
+ /** The dialog language at injection time; the component mirrors it as its initial state. */
44
+ language: 'zh' | 'en'
45
+ /** Switch the dialog language for every injected helper (defaults to zh). */
46
+ setLanguage(language: 'zh' | 'en'): void
43
47
  }
44
48
 
45
49
  /** Full component props: the owner share plus the injected face. */
@@ -74,9 +78,10 @@ function WslGlyph({ size = 16 }: { size?: number }): React.ReactElement {
74
78
  * The "Add WSL workspace…" footer action and its dialog.
75
79
  * @param props - owner share + injected face.
76
80
  */
77
- export function AddWslWorkspace({ wide, t, checkPreset, listDistros, listDir, check, createWorkspace }: AddWslWorkspaceProps): React.ReactElement | null {
81
+ export function AddWslWorkspace({ wide, language, setLanguage, t, checkPreset, listDistros, listDir, check, createWorkspace }: AddWslWorkspaceProps): React.ReactElement | null {
78
82
  const [open, setOpen] = useState(false)
79
83
  const [opening, setOpening] = useState(false)
84
+ const [lang, setLang] = useState<'zh' | 'en'>(language)
80
85
  const [distros, setDistros] = useState<string[]>([])
81
86
  const [distro, setDistro] = useState('')
82
87
  const [pathInput, setPathInput] = useState('/home/')
@@ -246,6 +251,10 @@ export function AddWslWorkspace({ wide, t, checkPreset, listDistros, listDir, ch
246
251
 
247
252
  const children = (listing?.entries.filter(entry => entry.kind === 'directory') ?? []).map(entry => entry.name)
248
253
  const maskClick = (): void => { if (!busy) setOpen(false) }
254
+ const onLanguageChange = (next: 'zh' | 'en'): void => {
255
+ setLang(next)
256
+ setLanguage(next)
257
+ }
249
258
  const listScroll: UIEventHandler<HTMLDivElement> = () => { /* scroll container handles overflow */ }
250
259
 
251
260
  return (
@@ -254,9 +263,29 @@ export function AddWslWorkspace({ wide, t, checkPreset, listDistros, listDir, ch
254
263
  <div className="dww-card" role="dialog" aria-modal="true" aria-label={t('dialog.title')}>
255
264
  <div className="dww-header">
256
265
  <h2 className="dww-title">{t('dialog.title')}</h2>
257
- <button type="button" className="dww-close" aria-label={t('dialog.cancel')} onClick={maskClick}>
258
-
259
- </button>
266
+ <div className="dww-header-actions">
267
+ <div className="dww-lang" role="group" aria-label="Language">
268
+ <button
269
+ type="button"
270
+ className={lang === 'zh' ? 'dww-lang-btn dww-lang-btn--active' : 'dww-lang-btn'}
271
+ disabled={busy}
272
+ onClick={() => onLanguageChange('zh')}
273
+ >
274
+ 中文
275
+ </button>
276
+ <button
277
+ type="button"
278
+ className={lang === 'en' ? 'dww-lang-btn dww-lang-btn--active' : 'dww-lang-btn'}
279
+ disabled={busy}
280
+ onClick={() => onLanguageChange('en')}
281
+ >
282
+ EN
283
+ </button>
284
+ </div>
285
+ <button type="button" className="dww-close" aria-label={t('dialog.cancel')} onClick={maskClick}>
286
+
287
+ </button>
288
+ </div>
260
289
  </div>
261
290
  <div className="dww-body">
262
291
  {error !== null ? (
@@ -66,10 +66,26 @@ export function apply(ctx: ClientContext): void {
66
66
  'dsh-wsl-workspace: locale dictionaries',
67
67
  )
68
68
 
69
- // The injected translate function reads the live locale preference.
70
- const t = ctx.locale.bind('wslWorkspace' as never) as unknown as (key: string, params?: Record<string, unknown>) => string
69
+ // The dialog owns a built-in language switch (default zh) independent of
70
+ // the app locale. Injected helpers read the current choice through this
71
+ // mutable holder, so their messages (checkPreset etc.) follow the dialog's
72
+ // language too.
73
+ let language: 'zh' | 'en' = 'zh'
74
+ const dictionaries = { zh, en }
75
+ const t = (key: string, params?: Record<string, unknown>): string => {
76
+ let text = dictionaries[language][key] ?? key
77
+ if (params !== undefined) {
78
+ for (const [name, value] of Object.entries(params)) {
79
+ text = text.replaceAll(`{${name}}`, String(value))
80
+ }
81
+ }
82
+ return text
83
+ }
84
+ const setLanguage = (next: 'zh' | 'en'): void => { language = next }
71
85
 
72
86
  const injected = (): AddWslWorkspaceInjected => ({
87
+ language,
88
+ setLanguage,
73
89
  t,
74
90
  checkPreset: async (): Promise<string | undefined> => {
75
91
  let roster
@@ -94,6 +94,33 @@ const STYLES = `
94
94
  gap: 8px;
95
95
  padding: 18px 20px 12px;
96
96
  }
97
+ .dww-header-actions {
98
+ display: flex;
99
+ align-items: center;
100
+ gap: 8px;
101
+ }
102
+ /* Built-in dialog language switch (中文 / EN), independent of the app locale. */
103
+ .dww-lang {
104
+ display: inline-flex;
105
+ overflow: hidden;
106
+ border: 1px solid var(--dsw-alias-border-l2);
107
+ border-radius: 8px;
108
+ }
109
+ .dww-lang-btn {
110
+ height: 28px;
111
+ padding: 0 10px;
112
+ border: 0;
113
+ background: transparent;
114
+ color: var(--dsw-alias-label-secondary);
115
+ cursor: pointer;
116
+ font-size: 12px;
117
+ }
118
+ .dww-lang-btn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
119
+ .dww-lang-btn--active {
120
+ background: var(--dsw-alias-button-primary-fill);
121
+ color: var(--dsw-alias-label-primary-foreground);
122
+ }
123
+ .dww-lang-btn:disabled { cursor: default; opacity: 0.6; }
97
124
  .dww-title {
98
125
  margin: 0;
99
126
  font-size: 16px;