dsh-wsl-workspace 0.2.2 → 0.2.3

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.
@@ -1,159 +1,175 @@
1
- /**
2
- * WSL path helpers shared by the client and host halves. Pure and
3
- * dependency-free so both planes can import them without a runtime edge.
4
- */
5
-
6
- /** WSL2 default loopback bridge host: `\\wsl.localhost\<distro>\...`. */
7
- const WSL_LOCALHOST_HOST = 'wsl.localhost'
8
- /** Legacy WSL interop host: `\\wsl$\<distro>\...`. */
9
- const WSL_LEGACY_HOST = 'wsl$'
10
-
11
- /** The two UNC hosts WSL exposes a distribution's filesystem under. */
12
- const UNC_HOSTS = [WSL_LOCALHOST_HOST, WSL_LEGACY_HOST]
13
-
14
- /** One WSL workspace coordinate parsed out of a UNC path. */
15
- export interface WslUncTarget {
16
- /** Distro name (e.g. `Ubuntu`) as `wsl -l -q` reports it. */
17
- readonly distro: string
18
- /** Normalized absolute Linux path (leading `/`; no trailing slash except root). */
19
- readonly linuxPath: string
20
- }
21
-
22
- /**
23
- * Parse a WSL UNC path into its distro and Linux path. Accepts the WSL2
24
- * `\\wsl.localhost\<distro>\<linux>` form, the legacy `\\wsl$\<distro>\<linux>`
25
- * interop form, and forward-slash spellings of either.
26
- * @param raw - candidate absolute path.
27
- * @returns the parsed target, or null when the path is not a WSL UNC.
28
- */
29
- export function parseWslUnc(raw: string): WslUncTarget | null {
30
- const normalized = raw.replace(/\\/g, '/').replace(/\/\/+/g, '//')
31
- if (!normalized.startsWith('//')) return null
32
- const segments = normalized.slice(2).split('/')
33
- const host = (segments[0] ?? '').toLowerCase()
34
- if (!UNC_HOSTS.includes(host)) return null
35
- const distro = segments[1] ?? ''
36
- if (distro === '') return null
37
- const rest = segments.slice(2).filter(segment => segment.length > 0)
38
- return { distro, linuxPath: `/${rest.join('/')}` }
39
- }
40
-
41
- /**
42
- * Whether a path resolves into a WSL distro through either UNC form.
43
- * @param raw - candidate absolute path.
44
- * @returns whether the path parses as a WSL UNC.
45
- */
46
- export function isWslUnc(raw: string): boolean {
47
- return parseWslUnc(raw) !== null
48
- }
49
-
50
- /**
51
- * Translate a WSL UNC path to the absolute Linux path a process inside the
52
- * distribution can open. Throws on non-WSL input: callers rely on this
53
- * conversion to hand paths to the Linux world, so a silent pass-through
54
- * would hand a Windows path to bash.
55
- * @param uncPath - a path {@link parseWslUnc} accepts.
56
- * @returns the absolute Linux path.
57
- */
58
- export function uncToLinux(uncPath: string): string {
59
- const parts = parseWslUnc(uncPath)
60
- if (parts === null) {
61
- throw new Error(`wsl-workspace: "${uncPath}" is not a WSL UNC path`)
62
- }
63
- return parts.linuxPath
64
- }
65
-
66
- /**
67
- * Normalize a Linux absolute path for the Host: collapse repeated slashes and
68
- * strip a trailing slash (root becomes `/`).
69
- * @param path - absolute Linux path.
70
- * @returns the normalized path.
71
- */
72
- export function normalizeLinuxPath(path: string): string {
73
- const collapsed = path.replace(/\/+/g, '/')
74
- return collapsed === '/' ? '/' : collapsed.replace(/\/$/, '')
75
- }
76
-
77
- /**
78
- * Whether a path is an absolute, non-empty Linux path.
79
- * @param path - candidate.
80
- * @returns whether it starts with `/` and contains no NUL.
81
- */
82
- export function isAbsoluteLinuxPath(path: string): boolean {
83
- return path.startsWith('/') && !path.includes('\0')
84
- }
85
-
86
- /**
87
- * Join a distro and a Linux absolute path into the WSL2 UNC form used as the
88
- * workspace identity (`\\wsl.localhost\<distro>\<linux>`, backslash segments).
89
- * @param distro - distro name.
90
- * @param linuxPath - absolute Linux path (leading `/`).
91
- * @returns the UNC path.
92
- */
93
- export function joinUnc(distro: string, linuxPath: string): string {
94
- if (!isAbsoluteLinuxPath(linuxPath)) {
95
- throw new Error(`wsl-workspace: cannot map a non-absolute Linux path "${linuxPath}" to UNC`)
96
- }
97
- // Defense in depth: a distribution name with separators or dot-dirs would
98
- // escape the `\\wsl.localhost\` share structure (the host route validates
99
- // wire-supplied names too; every other caller passes through here).
100
- if (distro === '' || distro === '.' || distro === '..' || /[\\/]/.test(distro)) {
101
- throw new Error(`wsl-workspace: invalid distribution name "${distro}"`)
102
- }
103
- const normalized = linuxPath.replace(/\/+/g, '/').replace(/\/$/, '')
104
- const withoutLeading = normalized.startsWith('/') ? normalized.slice(1) : normalized
105
- const windowsSegments = withoutLeading.replace(/\//g, '\\')
106
- const suffix = windowsSegments === '' ? '' : `\\${windowsSegments}`
107
- return `\\\\wsl.localhost\\${distro}${suffix}`
108
- }
109
-
110
- /**
111
- * Translate a Windows drive path to the drvfs mount path WSL distributions
112
- * conventionally expose it at (`C:\foo` → `/mnt/c/foo`). Only single-letter
113
- * drives under `/mnt` are mapped; custom mount points are out of scope.
114
- * @param path - the candidate Windows path.
115
- * @returns the `/mnt/<drive>/…` path, or `null` for non-drive paths.
116
- */
117
- export function windowsToMntPath(path: string): string | null {
118
- const match = /^([A-Za-z]):[\\/](.*)$/.exec(path)
119
- if (match === null) return null
120
- const rest = (match[2] ?? '').replace(/\\/g, '/').replace(/\/+/g, '/').replace(/\/$/, '')
121
- return `/mnt/${(match[1] ?? '').toLowerCase()}${rest === '' ? '' : `/${rest}`}`
122
- }
123
-
124
- /**
125
- * Translate a `/mnt/<drive>/…` path back to its Windows drive path.
126
- * @param linuxPath - the candidate Linux path.
127
- * @returns the `X:\…` drive path, or `null` when the path is not a drvfs mount.
128
- */
129
- export function mntToWindowsPath(linuxPath: string): string | null {
130
- const match = /^\/mnt\/([a-zA-Z])(?:\/(.*))?$/.exec(linuxPath)
131
- if (match === null) return null
132
- const rest = (match[2] ?? '').replace(/\//g, '\\')
133
- return `${(match[1] ?? '').toUpperCase()}:\\${rest}`
134
- }
135
-
136
- /**
137
- * True when a value is a Windows-shaped path (drive or UNC), which is how
138
- * the shell executor decides the WSLENV `/p` translation flag: only Windows
139
- * path values need translation when they cross into the Linux process.
140
- * @param value - the environment value to classify.
141
- * @returns whether the value looks like a Windows path.
142
- */
143
- export function isWindowsPathShaped(value: string): boolean {
144
- return /^[A-Za-z]:[\\/]/.test(value) || value.startsWith('\\\\')
145
- }
146
-
147
- /** Linux username shape for `wsl.exe -u`: starts with a letter or underscore, then letters/digits/`_`/`.`/`-` (max 64). */
148
- const WSL_USERNAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_.-]{0,63}$/
149
-
150
- /**
151
- * Whether a value is a safe Linux username for `wsl.exe -u`. The check is
152
- * strict on purpose: a value starting with `-` could be parsed as a wsl.exe
153
- * option instead of a username.
154
- * @param value - candidate username.
155
- * @returns whether it matches the Linux username shape.
156
- */
157
- export function isValidWslUsername(value: string): boolean {
158
- return WSL_USERNAME_PATTERN.test(value)
159
- }
1
+ /**
2
+ * WSL path helpers shared by the client and host halves. Pure and
3
+ * dependency-free so both planes can import them without a runtime edge.
4
+ */
5
+
6
+ /** WSL2 default loopback bridge host: `\\wsl.localhost\<distro>\...`. */
7
+ const WSL_LOCALHOST_HOST = 'wsl.localhost'
8
+ /** Legacy WSL interop host: `\\wsl$\<distro>\...`. */
9
+ const WSL_LEGACY_HOST = 'wsl$'
10
+
11
+ /** The two UNC hosts WSL exposes a distribution's filesystem under. */
12
+ const UNC_HOSTS = [WSL_LOCALHOST_HOST, WSL_LEGACY_HOST]
13
+
14
+ /** One WSL workspace coordinate parsed out of a UNC path. */
15
+ export interface WslUncTarget {
16
+ /** Distro name (e.g. `Ubuntu`) as `wsl -l -q` reports it. */
17
+ readonly distro: string
18
+ /** Normalized absolute Linux path (leading `/`; no trailing slash except root). */
19
+ readonly linuxPath: string
20
+ }
21
+
22
+ /**
23
+ * Parse a WSL UNC path into its distro and Linux path. Accepts the WSL2
24
+ * `\\wsl.localhost\<distro>\<linux>` form, the legacy `\\wsl$\<distro>\<linux>`
25
+ * interop form, and forward-slash spellings of either.
26
+ * @param raw - candidate absolute path.
27
+ * @returns the parsed target, or null when the path is not a WSL UNC.
28
+ */
29
+ export function parseWslUnc(raw: string): WslUncTarget | null {
30
+ const normalized = raw.replace(/\\/g, '/').replace(/\/\/+/g, '//')
31
+ if (!normalized.startsWith('//')) return null
32
+ const segments = normalized.slice(2).split('/')
33
+ const host = (segments[0] ?? '').toLowerCase()
34
+ if (!UNC_HOSTS.includes(host)) return null
35
+ const distro = segments[1] ?? ''
36
+ if (distro === '') return null
37
+ const rest = segments.slice(2).filter(segment => segment.length > 0)
38
+ return { distro, linuxPath: `/${rest.join('/')}` }
39
+ }
40
+
41
+ /**
42
+ * Whether a path resolves into a WSL distro through either UNC form.
43
+ * @param raw - candidate absolute path.
44
+ * @returns whether the path parses as a WSL UNC.
45
+ */
46
+ export function isWslUnc(raw: string): boolean {
47
+ return parseWslUnc(raw) !== null
48
+ }
49
+
50
+ /**
51
+ * Translate a WSL UNC path to the absolute Linux path a process inside the
52
+ * distribution can open. Throws on non-WSL input: callers rely on this
53
+ * conversion to hand paths to the Linux world, so a silent pass-through
54
+ * would hand a Windows path to bash.
55
+ * @param uncPath - a path {@link parseWslUnc} accepts.
56
+ * @returns the absolute Linux path.
57
+ */
58
+ export function uncToLinux(uncPath: string): string {
59
+ const parts = parseWslUnc(uncPath)
60
+ if (parts === null) {
61
+ throw new Error(`wsl-workspace: "${uncPath}" is not a WSL UNC path`)
62
+ }
63
+ return parts.linuxPath
64
+ }
65
+
66
+ /**
67
+ * Normalize a Linux absolute path for the Host: collapse repeated slashes and
68
+ * strip a trailing slash (root becomes `/`).
69
+ * @param path - absolute Linux path.
70
+ * @returns the normalized path.
71
+ */
72
+ export function normalizeLinuxPath(path: string): string {
73
+ const collapsed = path.replace(/\/+/g, '/')
74
+ return collapsed === '/' ? '/' : collapsed.replace(/\/$/, '')
75
+ }
76
+
77
+ /**
78
+ * Whether a path is an absolute, non-empty Linux path.
79
+ * @param path - candidate.
80
+ * @returns whether it starts with `/` and contains no NUL.
81
+ */
82
+ export function isAbsoluteLinuxPath(path: string): boolean {
83
+ return path.startsWith('/') && !path.includes('\0')
84
+ }
85
+
86
+ /**
87
+ * Join a distro and a Linux absolute path into the WSL2 UNC form used as the
88
+ * workspace identity (`\\wsl.localhost\<distro>\<linux>`, backslash segments).
89
+ * @param distro - distro name.
90
+ * @param linuxPath - absolute Linux path (leading `/`).
91
+ * @returns the UNC path.
92
+ */
93
+ export function joinUnc(distro: string, linuxPath: string): string {
94
+ if (!isAbsoluteLinuxPath(linuxPath)) {
95
+ throw new Error(`wsl-workspace: cannot map a non-absolute Linux path "${linuxPath}" to UNC`)
96
+ }
97
+ // Defense in depth: a distribution name with separators or dot-dirs would
98
+ // escape the `\\wsl.localhost\` share structure (the host route validates
99
+ // wire-supplied names too; every other caller passes through here).
100
+ if (distro === '' || distro === '.' || distro === '..' || /[\\/]/.test(distro)) {
101
+ throw new Error(`wsl-workspace: invalid distribution name "${distro}"`)
102
+ }
103
+ const normalized = linuxPath.replace(/\/+/g, '/').replace(/\/$/, '')
104
+ const withoutLeading = normalized.startsWith('/') ? normalized.slice(1) : normalized
105
+ const windowsSegments = withoutLeading.replace(/\//g, '\\')
106
+ const suffix = windowsSegments === '' ? '' : `\\${windowsSegments}`
107
+ return `\\\\wsl.localhost\\${distro}${suffix}`
108
+ }
109
+
110
+ /**
111
+ * Translate a Windows drive path to the drvfs mount path WSL distributions
112
+ * conventionally expose it at (`C:\foo` → `/mnt/c/foo`). Only single-letter
113
+ * drives under `/mnt` are mapped; custom mount points are out of scope.
114
+ * @param path - the candidate Windows path.
115
+ * @returns the `/mnt/<drive>/…` path, or `null` for non-drive paths.
116
+ */
117
+ export function windowsToMntPath(path: string): string | null {
118
+ const match = /^([A-Za-z]):[\\/](.*)$/.exec(path)
119
+ if (match === null) return null
120
+ const rest = (match[2] ?? '').replace(/\\/g, '/').replace(/\/+/g, '/').replace(/\/$/, '')
121
+ return `/mnt/${(match[1] ?? '').toLowerCase()}${rest === '' ? '' : `/${rest}`}`
122
+ }
123
+
124
+ /**
125
+ * Translate a `/mnt/<drive>/…` path back to its Windows drive path.
126
+ * @param linuxPath - the candidate Linux path.
127
+ * @returns the `X:\…` drive path, or `null` when the path is not a drvfs mount.
128
+ */
129
+ export function mntToWindowsPath(linuxPath: string): string | null {
130
+ const match = /^\/mnt\/([a-zA-Z])(?:\/(.*))?$/.exec(linuxPath)
131
+ if (match === null) return null
132
+ const rest = (match[2] ?? '').replace(/\//g, '\\')
133
+ return `${(match[1] ?? '').toUpperCase()}:\\${rest}`
134
+ }
135
+
136
+ /**
137
+ * Canonical Windows drive path for store keys and cross-realm identity:
138
+ * separators unified to `\`, trailing separator stripped, and the WHOLE path
139
+ * lowercased — Windows paths compare case-insensitively, and the workspace
140
+ * registry may realpath a different casing than the caller spelled (8.3 or
141
+ * on-disk casing), so the store key must collide across casings.
142
+ * @param path - candidate Windows drive path.
143
+ * @returns the canonical form, or `null` when not drive-shaped.
144
+ */
145
+ export function canonicalWindowsPath(path: string): string | null {
146
+ const match = /^([A-Za-z]):[\\/](.*)$/.exec(path)
147
+ if (match === null) return null
148
+ const rest = (match[2] ?? '').replace(/[\\/]+/g, '\\').replace(/\\$/, '').toLowerCase()
149
+ return `${(match[1] ?? '').toLowerCase()}:\\${rest}`
150
+ }
151
+
152
+ /**
153
+ * True when a value is a Windows-shaped path (drive or UNC), which is how
154
+ * the shell executor decides the WSLENV `/p` translation flag: only Windows
155
+ * path values need translation when they cross into the Linux process.
156
+ * @param value - the environment value to classify.
157
+ * @returns whether the value looks like a Windows path.
158
+ */
159
+ export function isWindowsPathShaped(value: string): boolean {
160
+ return /^[A-Za-z]:[\\/]/.test(value) || value.startsWith('\\\\')
161
+ }
162
+
163
+ /** Linux username shape for `wsl.exe -u`: starts with a letter or underscore, then letters/digits/`_`/`.`/`-` (max 64). */
164
+ const WSL_USERNAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_.-]{0,63}$/
165
+
166
+ /**
167
+ * Whether a value is a safe Linux username for `wsl.exe -u`. The check is
168
+ * strict on purpose: a value starting with `-` could be parsed as a wsl.exe
169
+ * option instead of a username.
170
+ * @param value - candidate username.
171
+ * @returns whether it matches the Linux username shape.
172
+ */
173
+ export function isValidWslUsername(value: string): boolean {
174
+ return WSL_USERNAME_PATTERN.test(value)
175
+ }
@@ -1,85 +1,135 @@
1
- /**
2
- * Per-workspace WSL credentials (host side only). The dialog stores the
3
- * optional Linux username of a WSL workspace under the harness home; the
4
- * per-session env contributor and the WSL shell executor read it back so
5
- * `wsl.exe -u <username>` can run commands as that user. Keys are canonical
6
- * UNC workspace paths. This module touches node builtins, so the browser
7
- * half never imports it.
8
- * @module dsh-wsl-workspace/shared/wsl-credentials
9
- */
10
-
11
- import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
12
- import { homedir } from 'node:os'
13
- import { dirname, join } from 'node:path'
14
- import { isValidWslUsername, joinUnc, parseWslUnc } from './paths.ts'
15
-
16
- /** One workspace's stored credentials. */
17
- interface WorkspaceEntry {
18
- /** The Linux user bash runs as inside the distribution (absent = distro default). */
19
- username?: string
20
- }
21
-
22
- /** The stored form: canonical UNC workspace path → credentials. */
23
- type WorkspaceStore = Record<string, WorkspaceEntry>
24
-
25
- /** The store file lives under the harness home so both host halves share it. */
26
- function storePath(): string {
27
- const dshHome = process.env.DSH_HOME ?? join(homedir(), '.dsh')
28
- return join(dshHome, 'wsl-workspaces.json')
29
- }
30
-
31
- /** Read the store; a missing or corrupt file reads as empty (never throws). */
32
- function readStore(): WorkspaceStore {
33
- try {
34
- const parsed: unknown = JSON.parse(readFileSync(storePath(), 'utf8'))
35
- if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return {}
36
- return parsed as WorkspaceStore
37
- } catch {
38
- return {}
39
- }
40
- }
41
-
42
- /**
43
- * Canonicalize any accepted WSL UNC spelling into the store's key form.
44
- * @param path - candidate workspace path (either UNC host form).
45
- * @returns the canonical UNC path, or null when the path is not a WSL UNC.
46
- */
47
- export function canonicalWslUnc(path: string): string | null {
48
- const parsed = parseWslUnc(path)
49
- return parsed === null ? null : joinUnc(parsed.distro, parsed.linuxPath)
50
- }
51
-
52
- /**
53
- * Read the stored username for a WSL workspace.
54
- * @param uncPath - the workspace path (any accepted WSL UNC spelling).
55
- * @returns the username, or undefined when none is stored.
56
- */
57
- export function getWorkspaceUsername(uncPath: string): string | undefined {
58
- const key = canonicalWslUnc(uncPath)
59
- if (key === null) return undefined
60
- const username = readStore()[key]?.username
61
- return username === undefined || username === '' ? undefined : username
62
- }
63
-
64
- /**
65
- * Store (or clear) the username of a WSL workspace.
66
- * @param uncPath - the workspace path (any accepted WSL UNC spelling).
67
- * @param username - the username; empty or undefined clears the stored value.
68
- */
69
- export function setWorkspaceUsername(uncPath: string, username: string | undefined): void {
70
- const key = canonicalWslUnc(uncPath)
71
- if (key === null) throw new Error('wsl-workspace: workspace path is not a WSL UNC path')
72
- const store = readStore()
73
- if (username === undefined || username.trim() === '') {
74
- delete store[key]
75
- } else {
76
- const trimmed = username.trim()
77
- if (!isValidWslUsername(trimmed)) {
78
- throw new Error('wsl-workspace: username must match the Linux username pattern [A-Za-z_][A-Za-z0-9_.-]*')
79
- }
80
- store[key] = { username: trimmed }
81
- }
82
- const path = storePath()
83
- mkdirSync(dirname(path), { recursive: true })
84
- writeFileSync(path, JSON.stringify(store, null, 2) + '\n', 'utf8')
85
- }
1
+ /**
2
+ * Per-workspace WSL credentials (host side only). The dialog stores the
3
+ * optional Linux username of a WSL workspace under the harness home; the
4
+ * per-session env contributor and the WSL shell executor read it back so
5
+ * `wsl.exe -u <username>` can run commands as that user. Keys are canonical
6
+ * UNC workspace paths. This module touches node builtins, so the browser
7
+ * half never imports it.
8
+ * @module dsh-wsl-workspace/shared/wsl-credentials
9
+ */
10
+
11
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
12
+ import { homedir } from 'node:os'
13
+ import { dirname, join } from 'node:path'
14
+ import { canonicalWindowsPath, isValidWslUsername, joinUnc, parseWslUnc } from './paths.ts'
15
+
16
+ /** One workspace's stored credentials. */
17
+ interface WorkspaceEntry {
18
+ /** The Linux user bash runs as inside the distribution (absent = distro default). */
19
+ username?: string
20
+ /**
21
+ * The WSL distribution of a Windows-drive workspace (`/mnt/<drive>` path).
22
+ * 9P cannot serve drvfs mounts, so such workspaces register under their
23
+ * Windows drive path; this entry is what the per-session env contributor
24
+ * uses to hand a distro to the shell executor.
25
+ */
26
+ distro?: string
27
+ }
28
+
29
+ /** The stored form: canonical UNC or Windows drive workspace path → credentials. */
30
+ type WorkspaceStore = Record<string, WorkspaceEntry>
31
+
32
+ /** The store file lives under the harness home so both host halves share it. */
33
+ function storePath(): string {
34
+ const dshHome = process.env.DSH_HOME ?? join(homedir(), '.dsh')
35
+ return join(dshHome, 'wsl-workspaces.json')
36
+ }
37
+
38
+ /** Read the store; a missing or corrupt file reads as empty (never throws). */
39
+ function readStore(): WorkspaceStore {
40
+ try {
41
+ const parsed: unknown = JSON.parse(readFileSync(storePath(), 'utf8'))
42
+ if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return {}
43
+ return parsed as WorkspaceStore
44
+ } catch {
45
+ return {}
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Canonicalize any accepted WSL UNC spelling into the store's key form.
51
+ * @param path - candidate workspace path (either UNC host form).
52
+ * @returns the canonical UNC path, or null when the path is not a WSL UNC.
53
+ */
54
+ export function canonicalWslUnc(path: string): string | null {
55
+ const parsed = parseWslUnc(path)
56
+ return parsed === null ? null : joinUnc(parsed.distro, parsed.linuxPath)
57
+ }
58
+
59
+ /**
60
+ * Read the stored username for a WSL workspace.
61
+ * @param uncPath - the workspace path (any accepted WSL UNC spelling).
62
+ * @returns the username, or undefined when none is stored.
63
+ */
64
+ export function getWorkspaceUsername(uncPath: string): string | undefined {
65
+ const key = canonicalWslUnc(uncPath)
66
+ if (key === null) return undefined
67
+ const username = readStore()[key]?.username
68
+ return username === undefined || username === '' ? undefined : username
69
+ }
70
+
71
+ /**
72
+ * Store (or clear) the username of a WSL workspace.
73
+ * @param uncPath - the workspace path (any accepted WSL UNC spelling).
74
+ * @param username - the username; empty or undefined clears the stored value.
75
+ */
76
+ export function setWorkspaceUsername(uncPath: string, username: string | undefined): void {
77
+ const key = canonicalWslUnc(uncPath)
78
+ if (key === null) throw new Error('wsl-workspace: workspace path is not a WSL UNC path')
79
+ const store = readStore()
80
+ if (username === undefined || username.trim() === '') {
81
+ delete store[key]
82
+ } else {
83
+ const trimmed = username.trim()
84
+ if (!isValidWslUsername(trimmed)) {
85
+ throw new Error('wsl-workspace: username must match the Linux username pattern [A-Za-z_][A-Za-z0-9_.-]*')
86
+ }
87
+ store[key] = { username: trimmed }
88
+ }
89
+ const path = storePath()
90
+ mkdirSync(dirname(path), { recursive: true })
91
+ writeFileSync(path, JSON.stringify(store, null, 2) + '\n', 'utf8')
92
+ }
93
+
94
+ /**
95
+ * Register the WSL distribution (and optional Linux username) of a
96
+ * Windows-drive workspace (`/mnt/<drive>` path). Keys are canonical Windows
97
+ * drive paths; the per-session env contributor reads the entry back so
98
+ * `wsl.exe -d <distro>` can run when the session cwd is a drive path.
99
+ * @param winPath - the Windows drive path (any spelling).
100
+ * @param distro - the WSL distribution the workspace belongs to.
101
+ * @param username - optional Linux username (distro default when absent).
102
+ */
103
+ export function registerWindowsWorkspace(winPath: string, distro: string, username: string | undefined): void {
104
+ const key = canonicalWindowsPath(winPath)
105
+ if (key === null) throw new Error('wsl-workspace: workspace path is not a Windows drive path')
106
+ const entry: WorkspaceEntry = { distro }
107
+ if (username !== undefined && username.trim() !== '') {
108
+ const trimmed = username.trim()
109
+ if (!isValidWslUsername(trimmed)) {
110
+ throw new Error('wsl-workspace: username must match the Linux username pattern [A-Za-z_][A-Za-z0-9_.-]*')
111
+ }
112
+ entry.username = trimmed
113
+ }
114
+ const store = readStore()
115
+ store[key] = entry
116
+ const path = storePath()
117
+ mkdirSync(dirname(path), { recursive: true })
118
+ writeFileSync(path, JSON.stringify(store, null, 2) + '\n', 'utf8')
119
+ }
120
+
121
+ /**
122
+ * Read the stored credentials of a Windows-drive workspace.
123
+ * @param winPath - the Windows drive path (any spelling).
124
+ * @returns the stored entry, or undefined when none is registered.
125
+ */
126
+ export function getWindowsWorkspace(winPath: string): WorkspaceEntry | undefined {
127
+ const key = canonicalWindowsPath(winPath)
128
+ if (key === null) return undefined
129
+ return readStore()[key]
130
+ }
131
+
132
+ /** Every stored workspace key (canonical UNC and Windows drive paths). */
133
+ export function listWorkspaceKeys(): string[] {
134
+ return Object.keys(readStore())
135
+ }
package/image-1.png DELETED
Binary file
package/image.png DELETED
Binary file
@@ -1 +0,0 @@
1
- {"version":3,"file":"paths-DBaSmi7x.js","names":[],"sources":["../src/shared/paths.ts"],"sourcesContent":["/**\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"],"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,UAAU,QAAQ,OAAO,EAAE;AAC9D;;;;;;AAOA,SAAgB,oBAAoB,MAAuB;CACzD,OAAO,KAAK,WAAW,GAAG,KAAK,CAAC,KAAK,SAAS,IAAI;AACpD;;;;;;;;AASA,SAAgB,QAAQ,QAAgB,WAA2B;CACjE,IAAI,CAAC,oBAAoB,SAAS,GAChC,MAAM,IAAI,MAAM,wDAAwD,UAAU,SAAS;CAK7F,IAAI,WAAW,MAAM,WAAW,OAAO,WAAW,QAAQ,QAAQ,KAAK,MAAM,GAC3E,MAAM,IAAI,MAAM,6CAA6C,OAAO,EAAE;CAExE,MAAM,aAAa,UAAU,QAAQ,QAAQ,GAAG,CAAC,CAAC,QAAQ,OAAO,EAAE;CAEnE,MAAM,mBADiB,WAAW,WAAW,GAAG,IAAI,WAAW,MAAM,CAAC,IAAI,WAAA,CACnC,QAAQ,OAAO,IAAI;CAE1D,OAAO,sBAAsB,SADd,oBAAoB,KAAK,KAAK,KAAK;AAEpD;;;;;;;;AASA,SAAgB,iBAAiB,MAA6B;CAC5D,MAAM,QAAQ,yBAAyB,KAAK,IAAI;CAChD,IAAI,UAAU,MAAM,OAAO;CAC3B,MAAM,QAAQ,MAAM,MAAM,GAAA,CAAI,QAAQ,OAAO,GAAG,CAAC,CAAC,QAAQ,QAAQ,GAAG,CAAC,CAAC,QAAQ,OAAO,EAAE;CACxF,OAAO,SAAS,MAAM,MAAM,GAAA,CAAI,YAAY,IAAI,SAAS,KAAK,KAAK,IAAI;AACzE;;;;;;AAOA,SAAgB,iBAAiB,WAAkC;CACjE,MAAM,QAAQ,iCAAiC,KAAK,SAAS;CAC7D,IAAI,UAAU,MAAM,OAAO;CAC3B,MAAM,QAAQ,MAAM,MAAM,GAAA,CAAI,QAAQ,OAAO,IAAI;CACjD,OAAO,IAAI,MAAM,MAAM,GAAA,CAAI,YAAY,EAAE,KAAK;AAChD;;;;;;;;AASA,SAAgB,oBAAoB,OAAwB;CAC1D,OAAO,kBAAkB,KAAK,KAAK,KAAK,MAAM,WAAW,MAAM;AACjE;;AAGA,MAAM,uBAAuB;;;;;;;;AAS7B,SAAgB,mBAAmB,OAAwB;CACzD,OAAO,qBAAqB,KAAK,KAAK;AACxC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"wsl-GjkUifnx.js","names":[],"sources":["../src/shared/wsl-credentials.ts","../src/shared/wsl.ts"],"sourcesContent":["/**\n * Per-workspace WSL credentials (host side only). The dialog stores the\n * optional Linux username of a WSL workspace under the harness home; the\n * per-session env contributor and the WSL shell executor read it back so\n * `wsl.exe -u <username>` can run commands as that user. Keys are canonical\n * UNC workspace paths. This module touches node builtins, so the browser\n * half never imports it.\n * @module dsh-wsl-workspace/shared/wsl-credentials\n */\n\nimport { mkdirSync, readFileSync, writeFileSync } from 'node:fs'\nimport { homedir } from 'node:os'\nimport { dirname, join } from 'node:path'\nimport { isValidWslUsername, joinUnc, parseWslUnc } from './paths.ts'\n\n/** One workspace's stored credentials. */\ninterface WorkspaceEntry {\n /** The Linux user bash runs as inside the distribution (absent = distro default). */\n username?: string\n}\n\n/** The stored form: canonical UNC workspace path → credentials. */\ntype WorkspaceStore = Record<string, WorkspaceEntry>\n\n/** The store file lives under the harness home so both host halves share it. */\nfunction storePath(): string {\n const dshHome = process.env.DSH_HOME ?? join(homedir(), '.dsh')\n return join(dshHome, 'wsl-workspaces.json')\n}\n\n/** Read the store; a missing or corrupt file reads as empty (never throws). */\nfunction readStore(): WorkspaceStore {\n try {\n const parsed: unknown = JSON.parse(readFileSync(storePath(), 'utf8'))\n if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return {}\n return parsed as WorkspaceStore\n } catch {\n return {}\n }\n}\n\n/**\n * Canonicalize any accepted WSL UNC spelling into the store's key form.\n * @param path - candidate workspace path (either UNC host form).\n * @returns the canonical UNC path, or null when the path is not a WSL UNC.\n */\nexport function canonicalWslUnc(path: string): string | null {\n const parsed = parseWslUnc(path)\n return parsed === null ? null : joinUnc(parsed.distro, parsed.linuxPath)\n}\n\n/**\n * Read the stored username for a WSL workspace.\n * @param uncPath - the workspace path (any accepted WSL UNC spelling).\n * @returns the username, or undefined when none is stored.\n */\nexport function getWorkspaceUsername(uncPath: string): string | undefined {\n const key = canonicalWslUnc(uncPath)\n if (key === null) return undefined\n const username = readStore()[key]?.username\n return username === undefined || username === '' ? undefined : username\n}\n\n/**\n * Store (or clear) the username of a WSL workspace.\n * @param uncPath - the workspace path (any accepted WSL UNC spelling).\n * @param username - the username; empty or undefined clears the stored value.\n */\nexport function setWorkspaceUsername(uncPath: string, username: string | undefined): void {\n const key = canonicalWslUnc(uncPath)\n if (key === null) throw new Error('wsl-workspace: workspace path is not a WSL UNC path')\n const store = readStore()\n if (username === undefined || username.trim() === '') {\n delete store[key]\n } else {\n const trimmed = username.trim()\n if (!isValidWslUsername(trimmed)) {\n throw new Error('wsl-workspace: username must match the Linux username pattern [A-Za-z_][A-Za-z0-9_.-]*')\n }\n store[key] = { username: trimmed }\n }\n const path = storePath()\n mkdirSync(dirname(path), { recursive: true })\n writeFileSync(path, JSON.stringify(store, null, 2) + '\\n', 'utf8')\n}\n","/**\n * WSL discovery helpers (host side): enumerate installed distributions\n * through `wsl.exe -l -q` and read the default distribution from the Lxss\n * registry key. `wsl.exe` output is UTF-16LE on most builds, so decoding\n * sniffs for NUL bytes before choosing an encoding.\n * @module dsh-wsl-workspace/shared/wsl\n */\n\nimport { execFile, execFileSync } from 'node:child_process'\nimport { promisify } from 'node:util'\n\nconst execFileAsync = promisify(execFile)\n\n/** Executable timeout for the short discovery calls. */\nconst DISCOVERY_TIMEOUT_MS = 10_000\n\nconst LXSS_KEY = 'HKCU\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Lxss'\n\n/** Human text for an unknown rejection. */\nfunction messageOf(value: unknown): string {\n return value instanceof Error ? value.message : String(value)\n}\n\n/**\n * Decode `wsl.exe -l -q` output. Newer builds emit UTF-8; most emit UTF-16LE\n * with NUL bytes interleaved — the NUL probe picks the right one.\n * @param buffer - the raw captured output.\n * @returns the decoded text.\n */\nexport function decodeWslOutput(buffer: Buffer): string {\n return buffer.includes(0) ? buffer.toString('utf16le') : buffer.toString('utf8')\n}\n\n/**\n * List installed WSL distributions in `wsl.exe` order.\n * @param wslPath - the `wsl.exe` executable (absolute or PATH name).\n * @returns distribution names, blank lines dropped.\n */\nexport async function listDistros(wslPath = 'wsl.exe'): Promise<string[]> {\n let stdout: Buffer\n try {\n const result = await execFileAsync(wslPath, ['-l', '-q'], { encoding: 'buffer', timeout: DISCOVERY_TIMEOUT_MS })\n stdout = result.stdout as Buffer\n } catch (error) {\n throw new Error(`wsl-workspace: cannot list WSL distributions (${messageOf(error)}); is WSL installed?`)\n }\n return decodeWslOutput(stdout)\n .split(/\\r?\\n/)\n .map(line => line.trim())\n .filter(line => line.length > 0)\n}\n\n/**\n * Read the user's default distribution from the Lxss registry. Non-fatal:\n * returns `undefined` when the value is absent or unreadable (the caller\n * falls back to list order).\n * @returns the default distribution name, or `undefined`.\n */\nexport async function defaultDistro(): Promise<string | undefined> {\n try {\n const value = await execFileAsync('reg.exe', ['query', LXSS_KEY, '/v', 'DefaultDistribution'], {\n timeout: DISCOVERY_TIMEOUT_MS,\n })\n const guid = /DefaultDistribution\\s+REG_SZ\\s+(\\{[0-9a-fA-F-]+\\})/i.exec(value.stdout)?.[1]\n if (guid === undefined) return undefined\n const name = await execFileAsync('reg.exe', ['query', `${LXSS_KEY}\\\\${guid}`, '/v', 'DistributionName'], {\n timeout: DISCOVERY_TIMEOUT_MS,\n })\n const distro = /DistributionName\\s+REG_SZ\\s+(.+)/i.exec(name.stdout)?.[1]?.trim()\n return distro === undefined || distro === '' ? undefined : distro\n } catch {\n return undefined\n }\n}\n\n/** Module-level cache for {@link defaultDistroSync} (one registry read per process). */\nlet syncDefaultResolved = false\nlet syncDefault: string | undefined\n\n/**\n * Synchronous variant of {@link defaultDistro} for executors that must\n * resolve a distribution inside a synchronous plan step. Cached after the\n * first read; non-fatal (returns `undefined` when the registry is\n * unreadable, letting the caller fail loud with its own message).\n * @returns the default distribution name, or `undefined`.\n */\nexport function defaultDistroSync(): string | undefined {\n if (syncDefaultResolved) return syncDefault\n syncDefaultResolved = true\n try {\n const value = execFileSync('reg.exe', ['query', LXSS_KEY, '/v', 'DefaultDistribution'], {\n timeout: DISCOVERY_TIMEOUT_MS,\n })\n const guid = /DefaultDistribution\\s+REG_SZ\\s+(\\{[0-9a-fA-F-]+\\})/i.exec(String(value))?.[1]\n if (guid === undefined) return undefined\n const name = execFileSync('reg.exe', ['query', `${LXSS_KEY}\\\\${guid}`, '/v', 'DistributionName'], {\n timeout: DISCOVERY_TIMEOUT_MS,\n })\n const distro = /DistributionName\\s+REG_SZ\\s+(.+)/i.exec(String(name))?.[1]?.trim()\n syncDefault = distro === undefined || distro === '' ? undefined : distro\n } catch {\n syncDefault = undefined\n }\n return syncDefault\n}\n"],"mappings":"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"}