dsh-wsl-workspace 0.3.0 → 0.3.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/src/index.ts CHANGED
@@ -34,6 +34,7 @@ import { joinUnc, mntToWindowsPath, normalizeLinuxPath, isAbsoluteLinuxPath, isV
34
34
  import { canonicalWslUnc, getWindowsWorkspace, getWorkspaceUsername, listWorkspaceKeys, registerWindowsWorkspace, setWorkspaceUsername } from './shared/wsl-credentials.ts'
35
35
  import { defaultDistro, listDistros } from './shared/wsl.ts'
36
36
  import { isWslVariantId, transformPresetForWsl, variantIdFor } from './host/variants.ts'
37
+ import { WslSkillsProvider, type WslSkillsRegistryFace } from './host/wsl-skills.ts'
37
38
 
38
39
  /** The HTTP route this plugin serves (a relative, same-origin path). */
39
40
  export const DEFAULT_ROUTE = '/wsl-workspace/api'
@@ -448,6 +449,20 @@ export function apply(ctx: Context, config: Config): void {
448
449
  }, 'dsh-wsl-workspace: WSL preset variants')
449
450
  }
450
451
 
452
+ const skills = ctx.get('skills') as unknown as WslSkillsRegistryFace | undefined
453
+ if (skills !== undefined && typeof skills.registerProvider === 'function') {
454
+ // The shipped skill-filesystem provider scans only the session cwd's
455
+ // project root, so WSL workspaces whose `.dsh/skills` live in nested
456
+ // projects would show an empty skill catalog. This provider mirrors the
457
+ // host's project discovery for WSL UNC workspaces, bounded to the
458
+ // workspace root (issue #10). The method check keeps a host whose
459
+ // `skills` service exists with a different shape from breaking plugin
460
+ // load; the provider is an enhancement, never a load-time requirement.
461
+ ctx.effect(() => skills.registerProvider(
462
+ control => new WslSkillsProvider(control),
463
+ ), 'dsh-wsl-workspace: WSL workspace skills provider')
464
+ }
465
+
451
466
  const shellEnv = ctx.get('shellEnv') as unknown as ShellEnvService | undefined
452
467
  if (shellEnv !== undefined) {
453
468
  ctx.effect(() => shellEnv.register({
@@ -1,120 +0,0 @@
1
- //#region src/shared/paths.ts
2
- /** The two UNC hosts WSL exposes a distribution's filesystem under. */
3
- const UNC_HOSTS = ["wsl.localhost", "wsl$"];
4
- /**
5
- * Parse a WSL UNC path into its distro and Linux path. Accepts the WSL2
6
- * `\\wsl.localhost\<distro>\<linux>` form, the legacy `\\wsl$\<distro>\<linux>`
7
- * interop form, and forward-slash spellings of either.
8
- * @param raw - candidate absolute path.
9
- * @returns the parsed target, or null when the path is not a WSL UNC.
10
- */
11
- function parseWslUnc(raw) {
12
- const normalized = raw.replace(/\\/g, "/").replace(/\/\/+/g, "//");
13
- if (!normalized.startsWith("//")) return null;
14
- const segments = normalized.slice(2).split("/");
15
- const host = (segments[0] ?? "").toLowerCase();
16
- if (!UNC_HOSTS.includes(host)) return null;
17
- const distro = segments[1] ?? "";
18
- if (distro === "") return null;
19
- return {
20
- distro,
21
- linuxPath: `/${segments.slice(2).filter((segment) => segment.length > 0).join("/")}`
22
- };
23
- }
24
- /**
25
- * Normalize a Linux absolute path for the Host: collapse repeated slashes and
26
- * strip a trailing slash (root becomes `/`).
27
- * @param path - absolute Linux path.
28
- * @returns the normalized path.
29
- */
30
- function normalizeLinuxPath(path) {
31
- const collapsed = path.replace(/\/+/g, "/");
32
- return collapsed === "/" ? "/" : collapsed.replace(/\/$/, "");
33
- }
34
- /**
35
- * Whether a path is an absolute, non-empty Linux path.
36
- * @param path - candidate.
37
- * @returns whether it starts with `/` and contains no NUL.
38
- */
39
- function isAbsoluteLinuxPath(path) {
40
- return path.startsWith("/") && !path.includes("\0");
41
- }
42
- /**
43
- * Join a distro and a Linux absolute path into the WSL2 UNC form used as the
44
- * workspace identity (`\\wsl.localhost\<distro>\<linux>`, backslash segments).
45
- * @param distro - distro name.
46
- * @param linuxPath - absolute Linux path (leading `/`).
47
- * @returns the UNC path.
48
- */
49
- function joinUnc(distro, linuxPath) {
50
- if (!isAbsoluteLinuxPath(linuxPath)) throw new Error(`wsl-workspace: cannot map a non-absolute Linux path "${linuxPath}" to UNC`);
51
- if (distro === "" || distro === "." || distro === ".." || /[\\/]/.test(distro)) throw new Error(`wsl-workspace: invalid distribution name "${distro}"`);
52
- const normalized = linuxPath.replace(/\/+/g, "/").replace(/\/$/, "");
53
- const windowsSegments = (normalized.startsWith("/") ? normalized.slice(1) : normalized).replace(/\//g, "\\");
54
- return `\\\\wsl.localhost\\${distro}${windowsSegments === "" ? "" : `\\${windowsSegments}`}`;
55
- }
56
- /**
57
- * Translate a Windows drive path to the drvfs mount path WSL distributions
58
- * conventionally expose it at (`C:\foo` → `/mnt/c/foo`). Only single-letter
59
- * drives under `/mnt` are mapped; custom mount points are out of scope.
60
- * @param path - the candidate Windows path.
61
- * @returns the `/mnt/<drive>/…` path, or `null` for non-drive paths.
62
- */
63
- function windowsToMntPath(path) {
64
- const match = /^([A-Za-z]):[\\/](.*)$/.exec(path);
65
- if (match === null) return null;
66
- const rest = (match[2] ?? "").replace(/\\/g, "/").replace(/\/+/g, "/").replace(/\/$/, "");
67
- return `/mnt/${(match[1] ?? "").toLowerCase()}${rest === "" ? "" : `/${rest}`}`;
68
- }
69
- /**
70
- * Translate a `/mnt/<drive>/…` path back to its Windows drive path.
71
- * @param linuxPath - the candidate Linux path.
72
- * @returns the `X:\…` drive path, or `null` when the path is not a drvfs mount.
73
- */
74
- function mntToWindowsPath(linuxPath) {
75
- const match = /^\/mnt\/([a-zA-Z])(?:\/(.*))?$/.exec(linuxPath);
76
- if (match === null) return null;
77
- const rest = (match[2] ?? "").replace(/\//g, "\\");
78
- return `${(match[1] ?? "").toUpperCase()}:\\${rest}`;
79
- }
80
- /**
81
- * Canonical Windows drive path for store keys and cross-realm identity:
82
- * separators unified to `\`, trailing separator stripped, and the WHOLE path
83
- * lowercased — Windows paths compare case-insensitively, and the workspace
84
- * registry may realpath a different casing than the caller spelled (8.3 or
85
- * on-disk casing), so the store key must collide across casings.
86
- * @param path - candidate Windows drive path.
87
- * @returns the canonical form, or `null` when not drive-shaped.
88
- */
89
- function canonicalWindowsPath(path) {
90
- const match = /^([A-Za-z]):[\\/](.*)$/.exec(path);
91
- if (match === null) return null;
92
- const rest = (match[2] ?? "").replace(/[\\/]+/g, "\\").replace(/\\$/, "").toLowerCase();
93
- return `${(match[1] ?? "").toLowerCase()}:\\${rest}`;
94
- }
95
- /**
96
- * True when a value is a Windows-shaped path (drive or UNC), which is how
97
- * the shell executor decides the WSLENV `/p` translation flag: only Windows
98
- * path values need translation when they cross into the Linux process.
99
- * @param value - the environment value to classify.
100
- * @returns whether the value looks like a Windows path.
101
- */
102
- function isWindowsPathShaped(value) {
103
- return /^[A-Za-z]:[\\/]/.test(value) || value.startsWith("\\\\");
104
- }
105
- /** Linux username shape for `wsl.exe -u`: starts with a letter or underscore, then letters/digits/`_`/`.`/`-` (max 64). */
106
- const WSL_USERNAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_.-]{0,63}$/;
107
- /**
108
- * Whether a value is a safe Linux username for `wsl.exe -u`. The check is
109
- * strict on purpose: a value starting with `-` could be parsed as a wsl.exe
110
- * option instead of a username.
111
- * @param value - candidate username.
112
- * @returns whether it matches the Linux username shape.
113
- */
114
- function isValidWslUsername(value) {
115
- return WSL_USERNAME_PATTERN.test(value);
116
- }
117
- //#endregion
118
- export { joinUnc as a, parseWslUnc as c, isWindowsPathShaped as i, windowsToMntPath as l, isAbsoluteLinuxPath as n, mntToWindowsPath as o, isValidWslUsername as r, normalizeLinuxPath as s, canonicalWindowsPath as t };
119
-
120
- //# sourceMappingURL=paths-BDE1NVOv.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"paths-BDE1NVOv.js","names":[],"sources":["../src/shared/paths.ts"],"sourcesContent":["/**\r\n * WSL path helpers shared by the client and host halves. Pure and\r\n * dependency-free so both planes can import them without a runtime edge.\r\n */\r\n\r\n/** WSL2 default loopback bridge host: `\\\\wsl.localhost\\<distro>\\...`. */\r\nconst WSL_LOCALHOST_HOST = 'wsl.localhost'\r\n/** Legacy WSL interop host: `\\\\wsl$\\<distro>\\...`. */\r\nconst WSL_LEGACY_HOST = 'wsl$'\r\n\r\n/** The two UNC hosts WSL exposes a distribution's filesystem under. */\r\nconst UNC_HOSTS = [WSL_LOCALHOST_HOST, WSL_LEGACY_HOST]\r\n\r\n/** One WSL workspace coordinate parsed out of a UNC path. */\r\nexport interface WslUncTarget {\r\n /** Distro name (e.g. `Ubuntu`) as `wsl -l -q` reports it. */\r\n readonly distro: string\r\n /** Normalized absolute Linux path (leading `/`; no trailing slash except root). */\r\n readonly linuxPath: string\r\n}\r\n\r\n/**\r\n * Parse a WSL UNC path into its distro and Linux path. Accepts the WSL2\r\n * `\\\\wsl.localhost\\<distro>\\<linux>` form, the legacy `\\\\wsl$\\<distro>\\<linux>`\r\n * interop form, and forward-slash spellings of either.\r\n * @param raw - candidate absolute path.\r\n * @returns the parsed target, or null when the path is not a WSL UNC.\r\n */\r\nexport function parseWslUnc(raw: string): WslUncTarget | null {\r\n const normalized = raw.replace(/\\\\/g, '/').replace(/\\/\\/+/g, '//')\r\n if (!normalized.startsWith('//')) return null\r\n const segments = normalized.slice(2).split('/')\r\n const host = (segments[0] ?? '').toLowerCase()\r\n if (!UNC_HOSTS.includes(host)) return null\r\n const distro = segments[1] ?? ''\r\n if (distro === '') return null\r\n const rest = segments.slice(2).filter(segment => segment.length > 0)\r\n return { distro, linuxPath: `/${rest.join('/')}` }\r\n}\r\n\r\n/**\r\n * Whether a path resolves into a WSL distro through either UNC form.\r\n * @param raw - candidate absolute path.\r\n * @returns whether the path parses as a WSL UNC.\r\n */\r\nexport function isWslUnc(raw: string): boolean {\r\n return parseWslUnc(raw) !== null\r\n}\r\n\r\n/**\r\n * Translate a WSL UNC path to the absolute Linux path a process inside the\r\n * distribution can open. Throws on non-WSL input: callers rely on this\r\n * conversion to hand paths to the Linux world, so a silent pass-through\r\n * would hand a Windows path to bash.\r\n * @param uncPath - a path {@link parseWslUnc} accepts.\r\n * @returns the absolute Linux path.\r\n */\r\nexport function uncToLinux(uncPath: string): string {\r\n const parts = parseWslUnc(uncPath)\r\n if (parts === null) {\r\n throw new Error(`wsl-workspace: \"${uncPath}\" is not a WSL UNC path`)\r\n }\r\n return parts.linuxPath\r\n}\r\n\r\n/**\r\n * Normalize a Linux absolute path for the Host: collapse repeated slashes and\r\n * strip a trailing slash (root becomes `/`).\r\n * @param path - absolute Linux path.\r\n * @returns the normalized path.\r\n */\r\nexport function normalizeLinuxPath(path: string): string {\r\n const collapsed = path.replace(/\\/+/g, '/')\r\n return collapsed === '/' ? '/' : collapsed.replace(/\\/$/, '')\r\n}\r\n\r\n/**\r\n * Whether a path is an absolute, non-empty Linux path.\r\n * @param path - candidate.\r\n * @returns whether it starts with `/` and contains no NUL.\r\n */\r\nexport function isAbsoluteLinuxPath(path: string): boolean {\r\n return path.startsWith('/') && !path.includes('\\0')\r\n}\r\n\r\n/**\r\n * Join a distro and a Linux absolute path into the WSL2 UNC form used as the\r\n * workspace identity (`\\\\wsl.localhost\\<distro>\\<linux>`, backslash segments).\r\n * @param distro - distro name.\r\n * @param linuxPath - absolute Linux path (leading `/`).\r\n * @returns the UNC path.\r\n */\r\nexport function joinUnc(distro: string, linuxPath: string): string {\r\n if (!isAbsoluteLinuxPath(linuxPath)) {\r\n throw new Error(`wsl-workspace: cannot map a non-absolute Linux path \"${linuxPath}\" to UNC`)\r\n }\r\n // Defense in depth: a distribution name with separators or dot-dirs would\r\n // escape the `\\\\wsl.localhost\\` share structure (the host route validates\r\n // wire-supplied names too; every other caller passes through here).\r\n if (distro === '' || distro === '.' || distro === '..' || /[\\\\/]/.test(distro)) {\r\n throw new Error(`wsl-workspace: invalid distribution name \"${distro}\"`)\r\n }\r\n const normalized = linuxPath.replace(/\\/+/g, '/').replace(/\\/$/, '')\r\n const withoutLeading = normalized.startsWith('/') ? normalized.slice(1) : normalized\r\n const windowsSegments = withoutLeading.replace(/\\//g, '\\\\')\r\n const suffix = windowsSegments === '' ? '' : `\\\\${windowsSegments}`\r\n return `\\\\\\\\wsl.localhost\\\\${distro}${suffix}`\r\n}\r\n\r\n/**\r\n * Translate a Windows drive path to the drvfs mount path WSL distributions\r\n * conventionally expose it at (`C:\\foo` → `/mnt/c/foo`). Only single-letter\r\n * drives under `/mnt` are mapped; custom mount points are out of scope.\r\n * @param path - the candidate Windows path.\r\n * @returns the `/mnt/<drive>/…` path, or `null` for non-drive paths.\r\n */\r\nexport function windowsToMntPath(path: string): string | null {\r\n const match = /^([A-Za-z]):[\\\\/](.*)$/.exec(path)\r\n if (match === null) return null\r\n const rest = (match[2] ?? '').replace(/\\\\/g, '/').replace(/\\/+/g, '/').replace(/\\/$/, '')\r\n return `/mnt/${(match[1] ?? '').toLowerCase()}${rest === '' ? '' : `/${rest}`}`\r\n}\r\n\r\n/**\r\n * Translate a `/mnt/<drive>/…` path back to its Windows drive path.\r\n * @param linuxPath - the candidate Linux path.\r\n * @returns the `X:\\…` drive path, or `null` when the path is not a drvfs mount.\r\n */\r\nexport function mntToWindowsPath(linuxPath: string): string | null {\r\n const match = /^\\/mnt\\/([a-zA-Z])(?:\\/(.*))?$/.exec(linuxPath)\r\n if (match === null) return null\r\n const rest = (match[2] ?? '').replace(/\\//g, '\\\\')\r\n return `${(match[1] ?? '').toUpperCase()}:\\\\${rest}`\r\n}\r\n\r\n/**\r\n * Canonical Windows drive path for store keys and cross-realm identity:\r\n * separators unified to `\\`, trailing separator stripped, and the WHOLE path\r\n * lowercased — Windows paths compare case-insensitively, and the workspace\r\n * registry may realpath a different casing than the caller spelled (8.3 or\r\n * on-disk casing), so the store key must collide across casings.\r\n * @param path - candidate Windows drive path.\r\n * @returns the canonical form, or `null` when not drive-shaped.\r\n */\r\nexport function canonicalWindowsPath(path: string): string | null {\r\n const match = /^([A-Za-z]):[\\\\/](.*)$/.exec(path)\r\n if (match === null) return null\r\n const rest = (match[2] ?? '').replace(/[\\\\/]+/g, '\\\\').replace(/\\\\$/, '').toLowerCase()\r\n return `${(match[1] ?? '').toLowerCase()}:\\\\${rest}`\r\n}\r\n\r\n/**\r\n * True when a value is a Windows-shaped path (drive or UNC), which is how\r\n * the shell executor decides the WSLENV `/p` translation flag: only Windows\r\n * path values need translation when they cross into the Linux process.\r\n * @param value - the environment value to classify.\r\n * @returns whether the value looks like a Windows path.\r\n */\r\nexport function isWindowsPathShaped(value: string): boolean {\r\n return /^[A-Za-z]:[\\\\/]/.test(value) || value.startsWith('\\\\\\\\')\r\n}\r\n\r\n/** Linux username shape for `wsl.exe -u`: starts with a letter or underscore, then letters/digits/`_`/`.`/`-` (max 64). */\r\nconst WSL_USERNAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_.-]{0,63}$/\r\n\r\n/**\r\n * Whether a value is a safe Linux username for `wsl.exe -u`. The check is\r\n * strict on purpose: a value starting with `-` could be parsed as a wsl.exe\r\n * option instead of a username.\r\n * @param value - candidate username.\r\n * @returns whether it matches the Linux username shape.\r\n */\r\nexport function isValidWslUsername(value: string): boolean {\r\n return WSL_USERNAME_PATTERN.test(value)\r\n}\r\n"],"mappings":";;AAWA,MAAM,YAAY,CAAC,iBAAoB,MAAe;;;;;;;;AAiBtD,SAAgB,YAAY,KAAkC;CAC5D,MAAM,aAAa,IAAI,QAAQ,OAAO,GAAG,CAAC,CAAC,QAAQ,UAAU,IAAI;CACjE,IAAI,CAAC,WAAW,WAAW,IAAI,GAAG,OAAO;CACzC,MAAM,WAAW,WAAW,MAAM,CAAC,CAAC,CAAC,MAAM,GAAG;CAC9C,MAAM,QAAQ,SAAS,MAAM,GAAA,CAAI,YAAY;CAC7C,IAAI,CAAC,UAAU,SAAS,IAAI,GAAG,OAAO;CACtC,MAAM,SAAS,SAAS,MAAM;CAC9B,IAAI,WAAW,IAAI,OAAO;CAE1B,OAAO;EAAE;EAAQ,WAAW,IADf,SAAS,MAAM,CAAC,CAAC,CAAC,QAAO,YAAW,QAAQ,SAAS,CAC/B,CAAC,CAAC,KAAK,GAAG;CAAI;AACnD;;;;;;;AAiCA,SAAgB,mBAAmB,MAAsB;CACvD,MAAM,YAAY,KAAK,QAAQ,QAAQ,GAAG;CAC1C,OAAO,cAAc,MAAM,MAAM,UAA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