dsh-wsl-workspace 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/NOTICE +68 -0
- package/README.md +30 -0
- package/README.zh.md +30 -0
- package/cordis.patch.yml +7 -0
- package/lib/client.js +982 -0
- package/lib/client.js.map +1 -0
- package/lib/fs.js +175 -0
- package/lib/fs.js.map +1 -0
- package/lib/index.js +493 -0
- package/lib/index.js.map +1 -0
- package/lib/paths-DBaSmi7x.js +105 -0
- package/lib/paths-DBaSmi7x.js.map +1 -0
- package/lib/shell.js +382 -0
- package/lib/shell.js.map +1 -0
- package/lib/wsl-GjkUifnx.js +179 -0
- package/lib/wsl-GjkUifnx.js.map +1 -0
- package/package.json +57 -0
- package/src/client/AddWslWorkspace.tsx +346 -0
- package/src/client/api.ts +104 -0
- package/src/client/index.ts +193 -0
- package/src/client/locales.ts +68 -0
- package/src/client/styles.ts +282 -0
- package/src/fs.ts +228 -0
- package/src/host/variants.ts +199 -0
- package/src/index.ts +410 -0
- package/src/shared/paths.ts +159 -0
- package/src/shared/wsl-credentials.ts +85 -0
- package/src/shared/wsl.ts +105 -0
- package/src/shell.ts +441 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
import { i as joinUnc, n as isValidWslUsername, o as normalizeLinuxPath, s as parseWslUnc, t as isAbsoluteLinuxPath } from "./paths-DBaSmi7x.js";
|
|
2
|
+
import { a as getWorkspaceUsername, i as canonicalWslUnc, o as setWorkspaceUsername, r as listDistros, t as defaultDistro } from "./wsl-GjkUifnx.js";
|
|
3
|
+
import z from "@deepseek-ai/schemastery";
|
|
4
|
+
import { mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
|
+
import { homedir } from "node:os";
|
|
8
|
+
//#region src/host/variants.ts
|
|
9
|
+
/**
|
|
10
|
+
* WSL preset-variant generator. For every healthy source preset the roster
|
|
11
|
+
* supplies, a `wsl-<id>` variant is materialized under the roster's user
|
|
12
|
+
* root: the source composition with its shell/filesystem world replaced by
|
|
13
|
+
* the WSL providers, so any mode (standard, minimal, code, cordis, user
|
|
14
|
+
* presets) can run on top of a WSL execution world. The execution world is
|
|
15
|
+
* therefore orthogonal to the mode instead of a mode itself.
|
|
16
|
+
*
|
|
17
|
+
* The transformation is text-level on the top-level rows of the composition
|
|
18
|
+
* (the shape all shipped presets share), with surgical edits for the known
|
|
19
|
+
* special groups; unknown shapes are kept verbatim where possible.
|
|
20
|
+
* @module dsh-wsl-workspace/host/variants
|
|
21
|
+
*/
|
|
22
|
+
/** Top-level rows that name the execution world and are replaced by the variant's own. */
|
|
23
|
+
const WORLD_ROWS = new Set([
|
|
24
|
+
"tool-bash",
|
|
25
|
+
"tool-pwsh",
|
|
26
|
+
"tool-fs",
|
|
27
|
+
"tool-fs-search",
|
|
28
|
+
"filesystem",
|
|
29
|
+
"persistent-shell"
|
|
30
|
+
]);
|
|
31
|
+
/** The injected WSL world group: providers + the bash/fs consumers, entry-local. */
|
|
32
|
+
function wslWorldGroup(shellPath, fsPath, includeEditor) {
|
|
33
|
+
return [
|
|
34
|
+
"# ── WSL execution world (dsh-wsl-workspace variant) ─────────────────────",
|
|
35
|
+
"# The shell and fs services are provided entry-locally (the isolate",
|
|
36
|
+
"# realm); host services (tools registry, shell-env, jobs) fall through.",
|
|
37
|
+
"# tool-fs-search is intentionally absent: the packaged ripgrep runs on",
|
|
38
|
+
"# the Windows host and cannot open Linux paths; WSL sessions search with",
|
|
39
|
+
"# shell tools instead.",
|
|
40
|
+
"- id: wsl-world",
|
|
41
|
+
" name: cordis:group",
|
|
42
|
+
" group: true",
|
|
43
|
+
" isolate:",
|
|
44
|
+
" shell: true",
|
|
45
|
+
" fs: true",
|
|
46
|
+
" config:",
|
|
47
|
+
` - id: shell-wsl`,
|
|
48
|
+
` name: '${shellPath.replace(/'/g, "''")}'`,
|
|
49
|
+
" - id: fs-wsl",
|
|
50
|
+
` name: '${fsPath.replace(/'/g, "''")}'`,
|
|
51
|
+
" - id: tool-bash",
|
|
52
|
+
" name: '@deepseek-ai/dsh-tool-bash'",
|
|
53
|
+
" - id: tool-fs",
|
|
54
|
+
" name: '@deepseek-ai/dsh-tool-fs'",
|
|
55
|
+
...includeEditor ? [
|
|
56
|
+
" - id: str-replace-editor",
|
|
57
|
+
" name: '@deepseek-ai/dsh-tool-str-replace-editor'",
|
|
58
|
+
" config:",
|
|
59
|
+
" maxOutputChars: 16000"
|
|
60
|
+
] : [],
|
|
61
|
+
""
|
|
62
|
+
].join("\n");
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The persistent-shell group re-pointed at WSL: the PTY spawns wsl.exe's
|
|
66
|
+
* bash instead of a host `bash` (which does not exist on Windows).
|
|
67
|
+
*/
|
|
68
|
+
function persistentShellGroup() {
|
|
69
|
+
return [
|
|
70
|
+
"# ── persistent shell over WSL (variant) ─────────────────────────────────",
|
|
71
|
+
"- id: persistent-shell",
|
|
72
|
+
" name: cordis:group",
|
|
73
|
+
" group: true",
|
|
74
|
+
" isolate:",
|
|
75
|
+
" terminals: true",
|
|
76
|
+
" config:",
|
|
77
|
+
" - id: pty",
|
|
78
|
+
" name: '@deepseek-ai/dsh-terminal'",
|
|
79
|
+
"",
|
|
80
|
+
" - id: terminal-bash",
|
|
81
|
+
" name: '@deepseek-ai/dsh-terminal-bash'",
|
|
82
|
+
" config:",
|
|
83
|
+
" timeoutMs: 300000",
|
|
84
|
+
" shellPath: 'wsl.exe'",
|
|
85
|
+
" shellArgs: ['-e', 'bash', '-l']",
|
|
86
|
+
"",
|
|
87
|
+
" - id: persistent-bash",
|
|
88
|
+
" name: '@deepseek-ai/dsh-tool-bash-persistent'",
|
|
89
|
+
" config:",
|
|
90
|
+
" timeoutMs: 300000",
|
|
91
|
+
" description: |-",
|
|
92
|
+
" Run commands in a bash shell inside the WSL distribution",
|
|
93
|
+
" * When invoking this tool, the contents of the \"command\" parameter does NOT need to be XML-escaped.",
|
|
94
|
+
" * You don't have access to the internet via this tool.",
|
|
95
|
+
" * You do have access to a mirror of common linux and python packages via apt and pip.",
|
|
96
|
+
" * State is persistent across command calls and discussions with the user.",
|
|
97
|
+
" * To inspect a particular line range of a file, e.g. lines 10-25, try 'sed -n 10,25p /path/to/the/file'.",
|
|
98
|
+
" * Please avoid commands that may produce a very large amount of output.",
|
|
99
|
+
" * Please run long lived commands in the background, e.g. 'sleep 10 &' or start a server in the background.",
|
|
100
|
+
""
|
|
101
|
+
].join("\n");
|
|
102
|
+
}
|
|
103
|
+
/** The sentence appended to a standard-like persona when the variant runs in WSL. */
|
|
104
|
+
const PERSONA_APPEND = " Your working directory {{cwd}} is inside a WSL (Windows Subsystem for Linux) distribution: the bash tool and the file read/write/edit tools use Linux paths, and the Windows filesystem is reachable as /mnt/<drive> for file migration.";
|
|
105
|
+
/** The top-level rows of one composition, as (startLine, endLineExclusive) spans. */
|
|
106
|
+
function topLevelSpans(lines) {
|
|
107
|
+
const spans = [];
|
|
108
|
+
let start = -1;
|
|
109
|
+
for (let index = 0; index < lines.length; index++) if (lines[index]?.startsWith("- id: ") === true) {
|
|
110
|
+
if (start >= 0) spans.push({
|
|
111
|
+
start,
|
|
112
|
+
end: index
|
|
113
|
+
});
|
|
114
|
+
start = index;
|
|
115
|
+
}
|
|
116
|
+
if (start >= 0) spans.push({
|
|
117
|
+
start,
|
|
118
|
+
end: lines.length
|
|
119
|
+
});
|
|
120
|
+
return spans;
|
|
121
|
+
}
|
|
122
|
+
/** The row id of a top-level span, or undefined when the first line is malformed. */
|
|
123
|
+
function spanId(lines, span) {
|
|
124
|
+
return /^- id: ([A-Za-z0-9_.-]+)/.exec(lines[span.start] ?? "")?.[1];
|
|
125
|
+
}
|
|
126
|
+
/** Whether a top-level span is a `persona` row with an appendable folded text. */
|
|
127
|
+
function appendablePersona(lines, span) {
|
|
128
|
+
const block = lines.slice(span.start, span.end).join("\n");
|
|
129
|
+
if (!block.includes("complete: true") && /text: [>|-]/.test(block)) {
|
|
130
|
+
const textLine = block.split("\n").find((line) => /^(\s*)text: [>|-]/.test(line));
|
|
131
|
+
if (textLine !== void 0) {
|
|
132
|
+
const indent = /^(\s*)/.exec(textLine)?.[1]?.length ?? 0;
|
|
133
|
+
return block.split("\n").some((line) => line.length > indent && /^\s+/.test(line) && !line.includes(":"));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
/** Append the WSL sentence to a persona row's folded text (in place of its last text line). */
|
|
139
|
+
function appendPersona(lines, span) {
|
|
140
|
+
const block = lines.slice(span.start, span.end);
|
|
141
|
+
const textIndex = block.findIndex((line) => /^(\s*)text: [>|-]/.test(line));
|
|
142
|
+
if (textIndex < 0) return [...block];
|
|
143
|
+
const indent = /^(\s*)/.exec(block[textIndex] ?? "")?.[1]?.length ?? 0;
|
|
144
|
+
let lastText = -1;
|
|
145
|
+
for (let index = textIndex + 1; index < block.length; index++) {
|
|
146
|
+
const line = block[index] ?? "";
|
|
147
|
+
if (line.trim() === "") continue;
|
|
148
|
+
if (line.length > indent && /^\s+/.test(line)) lastText = index;
|
|
149
|
+
}
|
|
150
|
+
if (lastText < 0) return [...block];
|
|
151
|
+
const updated = [...block];
|
|
152
|
+
const textIndent = /^(\s*)/.exec(block[lastText] ?? "")?.[1] ?? " ";
|
|
153
|
+
updated.splice(lastText + 1, 0, `${textIndent}${PERSONA_APPEND}`);
|
|
154
|
+
return updated;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Transform one source preset composition into its WSL variant: drop the
|
|
158
|
+
* execution-world rows, keep everything else verbatim, and append the WSL
|
|
159
|
+
* world group (plus the persistent-shell group when the source had one).
|
|
160
|
+
* @param source - the source composition text.
|
|
161
|
+
* @param shellPath - absolute path of the plugin's built WSL shell provider.
|
|
162
|
+
* @param fsPath - absolute path of the plugin's built WSL fs provider.
|
|
163
|
+
* @returns the variant composition text.
|
|
164
|
+
*/
|
|
165
|
+
function transformPresetForWsl(source, shellPath, fsPath) {
|
|
166
|
+
const lines = source.split("\n");
|
|
167
|
+
const spans = topLevelSpans(lines);
|
|
168
|
+
const kept = [];
|
|
169
|
+
let sawEditor = false;
|
|
170
|
+
let sawPersistent = false;
|
|
171
|
+
let personaAppended = false;
|
|
172
|
+
for (const span of spans) {
|
|
173
|
+
const id = spanId(lines, span);
|
|
174
|
+
if (id === void 0) {
|
|
175
|
+
kept.push(...lines.slice(span.start, span.end));
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (WORLD_ROWS.has(id)) {
|
|
179
|
+
if (id === "persistent-shell") sawPersistent = true;
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
if (id === "persona" && !personaAppended && appendablePersona(lines, span)) {
|
|
183
|
+
kept.push(...appendPersona(lines, span));
|
|
184
|
+
personaAppended = true;
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
kept.push(...lines.slice(span.start, span.end));
|
|
188
|
+
if (id === "str-replace-editor") sawEditor = true;
|
|
189
|
+
}
|
|
190
|
+
if (source.includes("str-replace-editor")) sawEditor = true;
|
|
191
|
+
const result = [...kept];
|
|
192
|
+
if (result.length > 0 && result[result.length - 1] !== "") result.push("");
|
|
193
|
+
result.push(wslWorldGroup(shellPath, fsPath, sawEditor));
|
|
194
|
+
if (sawPersistent) result.push(persistentShellGroup());
|
|
195
|
+
return result.join("\n").replace(/\n{3,}/g, "\n\n").replace(/\n+$/, "\n");
|
|
196
|
+
}
|
|
197
|
+
/** Whether an id is one of this plugin's own preset directories. */
|
|
198
|
+
function isWslVariantId(id) {
|
|
199
|
+
return id === "wsl" || /^wsl-[a-z0-9-]+$/.test(id);
|
|
200
|
+
}
|
|
201
|
+
/** The variant id for one source preset id. */
|
|
202
|
+
function variantIdFor(sourceId) {
|
|
203
|
+
return `wsl-${sourceId.toLowerCase()}`;
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region src/index.ts
|
|
207
|
+
/** The HTTP route this plugin serves (a relative, same-origin path). */
|
|
208
|
+
const DEFAULT_ROUTE = "/wsl-workspace/api";
|
|
209
|
+
const MAX_BODY_BYTES = 1024 * 1024;
|
|
210
|
+
/** Valid WSL distribution names: one path-safe segment (no separators, no dot-dirs). */
|
|
211
|
+
const DISTRO_PATTERN = /^[A-Za-z0-9][A-Za-z0-9 ._-]*$/;
|
|
212
|
+
/** The loopback hostnames the data route answers to (DNS-rebinding fence). */
|
|
213
|
+
const LOOPBACK_HOSTNAMES = new Set([
|
|
214
|
+
"localhost",
|
|
215
|
+
"127.0.0.1",
|
|
216
|
+
"::1",
|
|
217
|
+
"::ffff:127.0.0.1"
|
|
218
|
+
]);
|
|
219
|
+
/** True when a socket address is loopback (any IPv4/IPv6 spelling). */
|
|
220
|
+
function isLoopback(address) {
|
|
221
|
+
return address === "127.0.0.1" || address === "::1" || address === "::ffff:127.0.0.1";
|
|
222
|
+
}
|
|
223
|
+
/** The hostname part of a `Host` header value (port and IPv6 brackets stripped). */
|
|
224
|
+
function hostNameOf(host) {
|
|
225
|
+
if (host.startsWith("[")) {
|
|
226
|
+
const end = host.indexOf("]");
|
|
227
|
+
return end >= 0 ? host.slice(1, end) : host;
|
|
228
|
+
}
|
|
229
|
+
return host.split(":")[0] ?? "";
|
|
230
|
+
}
|
|
231
|
+
/** True when the request's `Host` header names a loopback host. */
|
|
232
|
+
function isLoopbackHost(host) {
|
|
233
|
+
return host !== void 0 && LOOPBACK_HOSTNAMES.has(hostNameOf(host).toLowerCase());
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Validate a wire-supplied distribution name before it becomes a UNC segment:
|
|
237
|
+
* an attacker-controlled segment containing separators or `..` would escape
|
|
238
|
+
* the `\\wsl.localhost\` share structure into arbitrary UNC paths.
|
|
239
|
+
* @param value - the raw wire value.
|
|
240
|
+
* @returns the validated distro name.
|
|
241
|
+
*/
|
|
242
|
+
function requireDistro(value) {
|
|
243
|
+
if (typeof value !== "string" || !DISTRO_PATTERN.test(value) || value === "." || value === "..") throw new Error("distro must be a valid WSL distribution name");
|
|
244
|
+
return value;
|
|
245
|
+
}
|
|
246
|
+
/** Human text for an unknown rejection. */
|
|
247
|
+
function messageOf(value) {
|
|
248
|
+
return value instanceof Error ? value.message : String(value);
|
|
249
|
+
}
|
|
250
|
+
/** Write one JSON envelope. */
|
|
251
|
+
function json(res, status, body) {
|
|
252
|
+
res.writeHead(status, {
|
|
253
|
+
"content-type": "application/json; charset=utf-8",
|
|
254
|
+
"cache-control": "no-store",
|
|
255
|
+
"x-content-type-options": "nosniff"
|
|
256
|
+
});
|
|
257
|
+
res.end(JSON.stringify(body));
|
|
258
|
+
}
|
|
259
|
+
/** Collect and parse the request body, bounded. */
|
|
260
|
+
async function readBody(req) {
|
|
261
|
+
const chunks = [];
|
|
262
|
+
let size = 0;
|
|
263
|
+
for await (const chunk of req) {
|
|
264
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
265
|
+
size += buffer.length;
|
|
266
|
+
if (size > MAX_BODY_BYTES) throw new Error("request body is too large");
|
|
267
|
+
chunks.push(buffer);
|
|
268
|
+
}
|
|
269
|
+
const parsed = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
270
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("request body must be a JSON object");
|
|
271
|
+
return parsed;
|
|
272
|
+
}
|
|
273
|
+
/** Normalize a Linux path for the wire (rejecting non-absolute input). */
|
|
274
|
+
function requireLinuxPath(value, label) {
|
|
275
|
+
if (typeof value !== "string" || !isAbsoluteLinuxPath(value)) throw new Error(`${label} must be an absolute Linux path`);
|
|
276
|
+
return normalizeLinuxPath(value);
|
|
277
|
+
}
|
|
278
|
+
/** Validate a wire-supplied workspace path and return its canonical UNC form. */
|
|
279
|
+
function requireWslUnc(value) {
|
|
280
|
+
if (typeof value !== "string") throw new Error("path must be a string");
|
|
281
|
+
const canonical = canonicalWslUnc(value);
|
|
282
|
+
if (canonical === null) throw new Error("path must be a WSL UNC workspace path");
|
|
283
|
+
return canonical;
|
|
284
|
+
}
|
|
285
|
+
/** Resolve one directory listing over the 9P share. */
|
|
286
|
+
function listWslDir(distro, linuxPath) {
|
|
287
|
+
const entries = readdirSync(joinUnc(distro, linuxPath), { withFileTypes: true }).slice(0, 1e3).map((dirent) => {
|
|
288
|
+
const kind = dirent.isDirectory() ? "directory" : dirent.isFile() ? "file" : "other";
|
|
289
|
+
return {
|
|
290
|
+
name: dirent.name,
|
|
291
|
+
kind
|
|
292
|
+
};
|
|
293
|
+
}).sort((a, b) => {
|
|
294
|
+
if (a.kind === "directory" && b.kind !== "directory") return -1;
|
|
295
|
+
if (a.kind !== "directory" && b.kind === "directory") return 1;
|
|
296
|
+
return a.name.localeCompare(b.name);
|
|
297
|
+
});
|
|
298
|
+
return {
|
|
299
|
+
path: linuxPath,
|
|
300
|
+
parent: linuxPath === "/" ? null : linuxPath.split("/").slice(0, -1).join("/") || "/",
|
|
301
|
+
entries
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
/** Route one method dispatch. */
|
|
305
|
+
async function dispatch(method, params) {
|
|
306
|
+
switch (method) {
|
|
307
|
+
case "listDistros": {
|
|
308
|
+
const distros = await listDistros();
|
|
309
|
+
const fallback = await defaultDistro();
|
|
310
|
+
if (fallback !== void 0 && distros.includes(fallback)) return [fallback, ...distros.filter((name) => name !== fallback)];
|
|
311
|
+
return distros;
|
|
312
|
+
}
|
|
313
|
+
case "listDir": return listWslDir(requireDistro(params.distro), requireLinuxPath(params.path, "path"));
|
|
314
|
+
case "check": {
|
|
315
|
+
const unc = joinUnc(requireDistro(params.distro), requireLinuxPath(params.path, "path"));
|
|
316
|
+
try {
|
|
317
|
+
return {
|
|
318
|
+
exists: true,
|
|
319
|
+
isDirectory: statSync(unc).isDirectory()
|
|
320
|
+
};
|
|
321
|
+
} catch {
|
|
322
|
+
return {
|
|
323
|
+
exists: false,
|
|
324
|
+
isDirectory: false
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
case "setUser": {
|
|
329
|
+
const path = requireWslUnc(params.path);
|
|
330
|
+
const username = params.username;
|
|
331
|
+
if (username === void 0 || username === "") setWorkspaceUsername(path, void 0);
|
|
332
|
+
else {
|
|
333
|
+
if (typeof username !== "string" || !isValidWslUsername(username)) throw new Error("username must match the Linux username pattern [A-Za-z_][A-Za-z0-9_.-]*");
|
|
334
|
+
setWorkspaceUsername(path, username);
|
|
335
|
+
}
|
|
336
|
+
return null;
|
|
337
|
+
}
|
|
338
|
+
default: throw new Error(`unknown method "${method}"`);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Materialize a `wsl-<mode>` variant for every healthy source preset, and
|
|
343
|
+
* remove this plugin's managed residue: stale variants whose source
|
|
344
|
+
* disappeared, plus the legacy standalone `wsl` preset directory (the
|
|
345
|
+
* execution world now composes with modes; a standalone WSL mode no longer
|
|
346
|
+
* exists). Managed files: rewritten on every boot.
|
|
347
|
+
* @param agentPresets - the roster service.
|
|
348
|
+
* @param dshHome - the harness home (user preset root parent).
|
|
349
|
+
* @param shellPath - absolute path of the plugin's built WSL shell provider.
|
|
350
|
+
* @param fsPath - absolute path of the plugin's built WSL fs provider.
|
|
351
|
+
*/
|
|
352
|
+
async function materializeVariants(agentPresets, dshHome, shellPath, fsPath) {
|
|
353
|
+
const presets = await agentPresets.list();
|
|
354
|
+
const userRoot = join(dshHome, ".agent-presets");
|
|
355
|
+
const generated = /* @__PURE__ */ new Set();
|
|
356
|
+
for (const preset of presets) {
|
|
357
|
+
if (preset.broken !== void 0) continue;
|
|
358
|
+
if (isWslVariantId(preset.id)) continue;
|
|
359
|
+
const variantId = variantIdFor(preset.id);
|
|
360
|
+
const transformed = transformPresetForWsl(await agentPresets.read(preset.id), shellPath, fsPath);
|
|
361
|
+
const dir = join(userRoot, variantId);
|
|
362
|
+
mkdirSync(dir, { recursive: true });
|
|
363
|
+
writeFileSync(join(dir, "agent.cordis.yml"), transformed, "utf8");
|
|
364
|
+
let name = `WSL · ${preset.id}`;
|
|
365
|
+
let orderLine = "";
|
|
366
|
+
try {
|
|
367
|
+
const meta = readFileSync(join(dirname(preset.path), "preset.yml"), "utf8");
|
|
368
|
+
const match = /^name:\s*(.+)$/m.exec(meta);
|
|
369
|
+
if (match?.[1] !== void 0 && match[1].trim() !== "") name = `WSL · ${match[1].trim()}`;
|
|
370
|
+
const orderMatch = /^order:\s*(\d+)\s*$/m.exec(meta);
|
|
371
|
+
if (orderMatch?.[1] !== void 0) orderLine = `order: ${orderMatch[1]}\n`;
|
|
372
|
+
} catch {}
|
|
373
|
+
writeFileSync(join(dir, "preset.yml"), `name: ${name}\n` + orderLine + `description: ${preset.id} 模式叠加 WSL 执行世界:bash 与文件工具运行在 WSL 发行版内。\n`, "utf8");
|
|
374
|
+
generated.add(variantId);
|
|
375
|
+
}
|
|
376
|
+
for (const entry of readdirSync(userRoot, { withFileTypes: true })) {
|
|
377
|
+
if (!entry.isDirectory()) continue;
|
|
378
|
+
if (entry.name === "wsl") {
|
|
379
|
+
rmSync(join(userRoot, entry.name), {
|
|
380
|
+
recursive: true,
|
|
381
|
+
force: true
|
|
382
|
+
});
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
if (!/^wsl-[a-z0-9-]+$/.test(entry.name)) continue;
|
|
386
|
+
if (!generated.has(entry.name)) rmSync(join(userRoot, entry.name), {
|
|
387
|
+
recursive: true,
|
|
388
|
+
force: true
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
/** Function-plugin plugin contract. */
|
|
393
|
+
const name = "dsh-wsl-workspace";
|
|
394
|
+
/** Required services. */
|
|
395
|
+
const inject = ["webServer"];
|
|
396
|
+
/** Validated plugin config (schemastery applied the defaults). */
|
|
397
|
+
const Config = z.object({ route: z.string().default(DEFAULT_ROUTE) });
|
|
398
|
+
/**
|
|
399
|
+
* Apply the host half: materialize the `wsl` preset plus a `wsl-<mode>`
|
|
400
|
+
* variant for every healthy roster preset, register the data route, and
|
|
401
|
+
* contribute the per-session `DSH_WSL_DISTRO` managed-env fact so the WSL
|
|
402
|
+
* shell executor can resolve a plain Linux `workdir` to the calling
|
|
403
|
+
* session's distribution.
|
|
404
|
+
* @param ctx - the host plugin context.
|
|
405
|
+
* @param config - the validated configuration.
|
|
406
|
+
*/
|
|
407
|
+
function apply(ctx, config) {
|
|
408
|
+
const resolved = config;
|
|
409
|
+
const dshHome = process.env.DSH_HOME ?? join(homedir(), ".dsh");
|
|
410
|
+
const packageRoot = fileURLToPath(new URL("..", import.meta.url));
|
|
411
|
+
const shellPath = join(packageRoot, "lib", "shell.js").replace(/\\/g, "/");
|
|
412
|
+
const fsPath = join(packageRoot, "lib", "fs.js").replace(/\\/g, "/");
|
|
413
|
+
const agentPresets = ctx.get("agentPresets");
|
|
414
|
+
if (agentPresets !== void 0) ctx.effect(() => {
|
|
415
|
+
materializeVariants(agentPresets, dshHome, shellPath, fsPath).catch((error) => {
|
|
416
|
+
console.error(`dsh-wsl-workspace: WSL preset-variant generation failed: ${messageOf(error)}`);
|
|
417
|
+
});
|
|
418
|
+
return () => {};
|
|
419
|
+
}, "dsh-wsl-workspace: WSL preset variants");
|
|
420
|
+
const shellEnv = ctx.get("shellEnv");
|
|
421
|
+
if (shellEnv !== void 0) ctx.effect(() => shellEnv.register({
|
|
422
|
+
name: "wsl-workspace-distro",
|
|
423
|
+
variables: {
|
|
424
|
+
DSH_WSL_DISTRO: { description: "The WSL distribution of the calling session workspace, when the session cwd is a WSL UNC path." },
|
|
425
|
+
DSH_WSL_USER: { description: "The Linux user of the calling session workspace, when the workspace has one configured." }
|
|
426
|
+
},
|
|
427
|
+
resolve(execution) {
|
|
428
|
+
const cwd = execution.agent?.session.header.cwd;
|
|
429
|
+
const unc = cwd === void 0 ? null : parseWslUnc(cwd);
|
|
430
|
+
if (unc === null) return {};
|
|
431
|
+
const username = getWorkspaceUsername(joinUnc(unc.distro, unc.linuxPath));
|
|
432
|
+
return username === void 0 || username === "" ? { DSH_WSL_DISTRO: unc.distro } : {
|
|
433
|
+
DSH_WSL_DISTRO: unc.distro,
|
|
434
|
+
DSH_WSL_USER: username
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
}), "dsh-wsl-workspace: per-session distro env fact");
|
|
438
|
+
const webServer = ctx.get("webServer");
|
|
439
|
+
ctx.effect(() => webServer.register({
|
|
440
|
+
kind: "exact",
|
|
441
|
+
path: resolved.route,
|
|
442
|
+
handler: async (req, res) => {
|
|
443
|
+
if (!isLoopback(req.socket.remoteAddress) || !isLoopbackHost(req.headers.host)) {
|
|
444
|
+
json(res, 403, {
|
|
445
|
+
ok: false,
|
|
446
|
+
error: "loopback-only"
|
|
447
|
+
});
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
if (req.method !== "POST") {
|
|
451
|
+
json(res, 405, {
|
|
452
|
+
ok: false,
|
|
453
|
+
error: "method not allowed"
|
|
454
|
+
});
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
let body;
|
|
458
|
+
try {
|
|
459
|
+
body = await readBody(req);
|
|
460
|
+
} catch (error) {
|
|
461
|
+
json(res, 400, {
|
|
462
|
+
ok: false,
|
|
463
|
+
error: messageOf(error)
|
|
464
|
+
});
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
const method = typeof body.method === "string" ? body.method : "";
|
|
468
|
+
const params = body.params === void 0 ? {} : body.params;
|
|
469
|
+
if (params === null || typeof params !== "object" || Array.isArray(params)) {
|
|
470
|
+
json(res, 400, {
|
|
471
|
+
ok: false,
|
|
472
|
+
error: "params must be an object"
|
|
473
|
+
});
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
try {
|
|
477
|
+
json(res, 200, {
|
|
478
|
+
ok: true,
|
|
479
|
+
value: await dispatch(method, params)
|
|
480
|
+
});
|
|
481
|
+
} catch (error) {
|
|
482
|
+
json(res, 200, {
|
|
483
|
+
ok: false,
|
|
484
|
+
error: messageOf(error)
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}), "dsh-wsl-workspace: dialog data route");
|
|
489
|
+
}
|
|
490
|
+
//#endregion
|
|
491
|
+
export { Config, DEFAULT_ROUTE, apply, inject, name };
|
|
492
|
+
|
|
493
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/host/variants.ts","../src/index.ts"],"sourcesContent":["/**\n * WSL preset-variant generator. For every healthy source preset the roster\n * supplies, a `wsl-<id>` variant is materialized under the roster's user\n * root: the source composition with its shell/filesystem world replaced by\n * the WSL providers, so any mode (standard, minimal, code, cordis, user\n * presets) can run on top of a WSL execution world. The execution world is\n * therefore orthogonal to the mode instead of a mode itself.\n *\n * The transformation is text-level on the top-level rows of the composition\n * (the shape all shipped presets share), with surgical edits for the known\n * special groups; unknown shapes are kept verbatim where possible.\n * @module dsh-wsl-workspace/host/variants\n */\n\n/** Top-level rows that name the execution world and are replaced by the variant's own. */\nconst WORLD_ROWS = new Set(['tool-bash', 'tool-pwsh', 'tool-fs', 'tool-fs-search', 'filesystem', 'persistent-shell'])\n\n/** The injected WSL world group: providers + the bash/fs consumers, entry-local. */\nfunction wslWorldGroup(shellPath: string, fsPath: string, includeEditor: boolean): string {\n return [\n '# ── WSL execution world (dsh-wsl-workspace variant) ─────────────────────',\n '# The shell and fs services are provided entry-locally (the isolate',\n '# realm); host services (tools registry, shell-env, jobs) fall through.',\n '# tool-fs-search is intentionally absent: the packaged ripgrep runs on',\n '# the Windows host and cannot open Linux paths; WSL sessions search with',\n '# shell tools instead.',\n '- id: wsl-world',\n \" name: cordis:group\",\n ' group: true',\n ' isolate:',\n ' shell: true',\n ' fs: true',\n ' config:',\n ` - id: shell-wsl`,\n ` name: '${shellPath.replace(/'/g, \"''\")}'`,\n ' - id: fs-wsl',\n ` name: '${fsPath.replace(/'/g, \"''\")}'`,\n ' - id: tool-bash',\n \" name: '@deepseek-ai/dsh-tool-bash'\",\n ' - id: tool-fs',\n \" name: '@deepseek-ai/dsh-tool-fs'\",\n ...(includeEditor\n ? [\n ' - id: str-replace-editor',\n \" name: '@deepseek-ai/dsh-tool-str-replace-editor'\",\n ' config:',\n ' maxOutputChars: 16000',\n ]\n : []),\n '',\n ].join('\\n')\n}\n\n/**\n * The persistent-shell group re-pointed at WSL: the PTY spawns wsl.exe's\n * bash instead of a host `bash` (which does not exist on Windows).\n */\nfunction persistentShellGroup(): string {\n return [\n '# ── persistent shell over WSL (variant) ─────────────────────────────────',\n '- id: persistent-shell',\n ' name: cordis:group',\n ' group: true',\n ' isolate:',\n ' terminals: true',\n ' config:',\n ' - id: pty',\n \" name: '@deepseek-ai/dsh-terminal'\",\n '',\n ' - id: terminal-bash',\n \" name: '@deepseek-ai/dsh-terminal-bash'\",\n ' config:',\n ' timeoutMs: 300000',\n \" shellPath: 'wsl.exe'\",\n \" shellArgs: ['-e', 'bash', '-l']\",\n '',\n ' - id: persistent-bash',\n \" name: '@deepseek-ai/dsh-tool-bash-persistent'\",\n ' config:',\n ' timeoutMs: 300000',\n ' description: |-',\n ' Run commands in a bash shell inside the WSL distribution',\n ' * When invoking this tool, the contents of the \"command\" parameter does NOT need to be XML-escaped.',\n \" * You don't have access to the internet via this tool.\",\n ' * You do have access to a mirror of common linux and python packages via apt and pip.',\n ' * State is persistent across command calls and discussions with the user.',\n \" * To inspect a particular line range of a file, e.g. lines 10-25, try 'sed -n 10,25p /path/to/the/file'.\",\n ' * Please avoid commands that may produce a very large amount of output.',\n \" * Please run long lived commands in the background, e.g. 'sleep 10 &' or start a server in the background.\",\n '',\n ].join('\\n')\n}\n\n/** The sentence appended to a standard-like persona when the variant runs in WSL. */\nconst PERSONA_APPEND = ' Your working directory {{cwd}} is inside a WSL (Windows Subsystem for Linux) distribution: the bash tool and the file read/write/edit tools use Linux paths, and the Windows filesystem is reachable as /mnt/<drive> for file migration.'\n\n/** The top-level rows of one composition, as (startLine, endLineExclusive) spans. */\nfunction topLevelSpans(lines: readonly string[]): { start: number; end: number }[] {\n const spans: { start: number; end: number }[] = []\n let start = -1\n for (let index = 0; index < lines.length; index++) {\n if (lines[index]?.startsWith('- id: ') === true) {\n if (start >= 0) spans.push({ start, end: index })\n start = index\n }\n }\n if (start >= 0) spans.push({ start, end: lines.length })\n return spans\n}\n\n/** The row id of a top-level span, or undefined when the first line is malformed. */\nfunction spanId(lines: readonly string[], span: { start: number; end: number }): string | undefined {\n return /^- id: ([A-Za-z0-9_.-]+)/.exec(lines[span.start] ?? '')?.[1]\n}\n\n/** Whether a top-level span is a `persona` row with an appendable folded text. */\nfunction appendablePersona(lines: readonly string[], span: { start: number; end: number }): boolean {\n const block = lines.slice(span.start, span.end).join('\\n')\n if (!block.includes('complete: true') && /text: [>|-]/.test(block)) {\n // Append only when the folded text actually has content lines.\n const textLine = block.split('\\n').find(line => /^(\\s*)text: [>|-]/.test(line))\n if (textLine !== undefined) {\n const indent = /^(\\s*)/.exec(textLine)?.[1]?.length ?? 0\n return block.split('\\n').some(line => line.length > indent && /^\\s+/.test(line) && !line.includes(':'))\n }\n }\n return false\n}\n\n/** Append the WSL sentence to a persona row's folded text (in place of its last text line). */\nfunction appendPersona(lines: readonly string[], span: { start: number; end: number }): string[] {\n const block = lines.slice(span.start, span.end)\n const textIndex = block.findIndex(line => /^(\\s*)text: [>|-]/.test(line))\n if (textIndex < 0) return [...block]\n const indent = /^(\\s*)/.exec(block[textIndex] ?? '')?.[1]?.length ?? 0\n let lastText = -1\n for (let index = textIndex + 1; index < block.length; index++) {\n const line = block[index] ?? ''\n if (line.trim() === '') continue\n if (line.length > indent && /^\\s+/.test(line)) lastText = index\n }\n if (lastText < 0) return [...block]\n const updated = [...block]\n const textIndent = /^(\\s*)/.exec(block[lastText] ?? '')?.[1] ?? ' '\n updated.splice(lastText + 1, 0, `${textIndent}${PERSONA_APPEND}`)\n return updated\n}\n\n/**\n * Transform one source preset composition into its WSL variant: drop the\n * execution-world rows, keep everything else verbatim, and append the WSL\n * world group (plus the persistent-shell group when the source had one).\n * @param source - the source composition text.\n * @param shellPath - absolute path of the plugin's built WSL shell provider.\n * @param fsPath - absolute path of the plugin's built WSL fs provider.\n * @returns the variant composition text.\n */\nexport function transformPresetForWsl(source: string, shellPath: string, fsPath: string): string {\n const lines = source.split('\\n')\n const spans = topLevelSpans(lines)\n const kept: string[] = []\n let sawEditor = false\n let sawPersistent = false\n let personaAppended = false\n for (const span of spans) {\n const id = spanId(lines, span)\n if (id === undefined) {\n kept.push(...lines.slice(span.start, span.end))\n continue\n }\n if (WORLD_ROWS.has(id)) {\n if (id === 'persistent-shell') sawPersistent = true\n continue\n }\n if (id === 'persona' && !personaAppended && appendablePersona(lines, span)) {\n kept.push(...appendPersona(lines, span))\n personaAppended = true\n continue\n }\n kept.push(...lines.slice(span.start, span.end))\n if (id === 'str-replace-editor') sawEditor = true\n }\n if (source.includes('str-replace-editor')) sawEditor = true\n const result = [...kept]\n if (result.length > 0 && result[result.length - 1] !== '') result.push('')\n result.push(wslWorldGroup(shellPath, fsPath, sawEditor))\n if (sawPersistent) result.push(persistentShellGroup())\n return result.join('\\n').replace(/\\n{3,}/g, '\\n\\n').replace(/\\n+$/, '\\n')\n}\n\n/** Whether an id is one of this plugin's own preset directories. */\nexport function isWslVariantId(id: string): boolean {\n return id === 'wsl' || /^wsl-[a-z0-9-]+$/.test(id)\n}\n\n/** The variant id for one source preset id. */\nexport function variantIdFor(sourceId: string): string {\n return `wsl-${sourceId.toLowerCase()}`\n}\n","/**\r\n * Host half of dsh-wsl-workspace. Three responsibilities:\r\n *\r\n * 1. Materialize a `wsl-<mode>` variant for every healthy roster preset\r\n * under `<dshHome>/.agent-presets/` (the roster's auto-scanned user\r\n * root), so the WSL execution world — `shell-wsl` + `fs-wsl` behind one\r\n * entry-local realm, with `tool-bash`/`tool-fs` consumers — composes with\r\n * ANY mode instead of being a mode itself; the legacy standalone `wsl`\r\n * preset directory and stale variants are removed on boot. The preset\r\n * rows name THIS package's built lib files by absolute path, which the\r\n * preset mount resolves to `file:` URLs without relying on bare specifier\r\n * resolution from the preset's home directory.\r\n *\r\n * 2. Serve the browser dialog's data route (`/wsl-workspace/api`):\r\n * distribution discovery, one-level directory listing, path checks, and\r\n * the per-workspace username store — all over the 9P UNC share.\r\n * Loopback-only, matching the sensitivity of the privileged configuration\r\n * surface.\r\n *\r\n * 3. Contribute the per-session `DSH_WSL_DISTRO` managed-env fact so the WSL\r\n * shell executor can resolve a plain Linux `workdir` to the calling\r\n * session's distribution.\r\n * @module dsh-wsl-workspace\r\n */\r\n\r\nimport { Context } from '@deepseek-ai/cordis'\r\nimport z from '@deepseek-ai/schemastery'\r\nimport { mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs'\r\nimport { fileURLToPath } from 'node:url'\r\nimport { dirname, join } from 'node:path'\r\nimport type { IncomingMessage, ServerResponse } from 'node:http'\r\nimport { homedir } from 'node:os'\r\nimport { joinUnc, normalizeLinuxPath, isAbsoluteLinuxPath, isValidWslUsername, parseWslUnc } from './shared/paths.ts'\r\nimport { canonicalWslUnc, getWorkspaceUsername, setWorkspaceUsername } from './shared/wsl-credentials.ts'\r\nimport { defaultDistro, listDistros } from './shared/wsl.ts'\r\nimport { isWslVariantId, transformPresetForWsl, variantIdFor } from './host/variants.ts'\r\n\r\n/** The HTTP route this plugin serves (a relative, same-origin path). */\r\nexport const DEFAULT_ROUTE = '/wsl-workspace/api'\r\n\r\n/** Plugin config. */\r\nexport interface Config {\r\n /** The route under which the dialog data API is served. */\r\n route?: string\r\n}\r\n\r\n/** The shape after schemastery applied the defaults. */\r\ntype ResolvedConfig = Required<Config>\r\n\r\n/** The `webServer.register` route contract this plugin consumes. */\r\ninterface WebServerRoute {\r\n kind: 'exact'\r\n path: string\r\n handler(req: IncomingMessage, res: ServerResponse): Promise<void>\r\n}\r\n\r\ninterface WebServerService {\r\n register(route: WebServerRoute): () => void\r\n}\r\n\r\n/** The `ctx.shellEnv` registry face this plugin consumes (optional service). */\r\ninterface ShellEnvService {\r\n register(contributor: {\r\n name: string\r\n variables: Readonly<Record<string, { description: string }>>\r\n resolve(execution: {\r\n agent?: { session: { header: { cwd?: string } } }\r\n }): Readonly<Partial<Record<string, string>>>\r\n }): () => void\r\n}\r\n\r\n/** One directory entry the dialog lists. */\r\ninterface WslDirEntryWire {\r\n name: string\r\n kind: 'directory' | 'file' | 'other'\r\n}\r\n\r\n/** One directory level plus its breadcrumb ancestry. */\r\ninterface WslDirListingWire {\r\n path: string\r\n parent: string | null\r\n entries: WslDirEntryWire[]\r\n}\r\n\r\n/** The wire envelope every method answers with. */\r\ntype Envelope<T> = { ok: true; value: T } | { ok: false; error: string }\r\n\r\nconst MAX_BODY_BYTES = 1024 * 1024\r\n\r\n/** Valid WSL distribution names: one path-safe segment (no separators, no dot-dirs). */\r\nconst DISTRO_PATTERN = /^[A-Za-z0-9][A-Za-z0-9 ._-]*$/\r\n\r\n/** The loopback hostnames the data route answers to (DNS-rebinding fence). */\r\nconst LOOPBACK_HOSTNAMES = new Set(['localhost', '127.0.0.1', '::1', '::ffff:127.0.0.1'])\r\n\r\n/** True when a socket address is loopback (any IPv4/IPv6 spelling). */\r\nfunction isLoopback(address: string | undefined): boolean {\r\n return address === '127.0.0.1' || address === '::1' || address === '::ffff:127.0.0.1'\r\n}\r\n\r\n/** The hostname part of a `Host` header value (port and IPv6 brackets stripped). */\r\nfunction hostNameOf(host: string): string {\r\n if (host.startsWith('[')) {\r\n const end = host.indexOf(']')\r\n return end >= 0 ? host.slice(1, end) : host\r\n }\r\n return host.split(':')[0] ?? ''\r\n}\r\n\r\n/** True when the request's `Host` header names a loopback host. */\r\nfunction isLoopbackHost(host: string | undefined): boolean {\r\n return host !== undefined && LOOPBACK_HOSTNAMES.has(hostNameOf(host).toLowerCase())\r\n}\r\n\r\n/**\r\n * Validate a wire-supplied distribution name before it becomes a UNC segment:\r\n * an attacker-controlled segment containing separators or `..` would escape\r\n * the `\\\\wsl.localhost\\` share structure into arbitrary UNC paths.\r\n * @param value - the raw wire value.\r\n * @returns the validated distro name.\r\n */\r\nfunction requireDistro(value: unknown): string {\r\n if (typeof value !== 'string' || !DISTRO_PATTERN.test(value) || value === '.' || value === '..') {\r\n throw new Error('distro must be a valid WSL distribution name')\r\n }\r\n return value\r\n}\r\n\r\n/** Human text for an unknown rejection. */\r\nfunction messageOf(value: unknown): string {\r\n return value instanceof Error ? value.message : String(value)\r\n}\r\n\r\n/** Write one JSON envelope. */\r\nfunction json(res: ServerResponse, status: number, body: Envelope<unknown>): void {\r\n res.writeHead(status, {\r\n 'content-type': 'application/json; charset=utf-8',\r\n 'cache-control': 'no-store',\r\n 'x-content-type-options': 'nosniff',\r\n })\r\n res.end(JSON.stringify(body))\r\n}\r\n\r\n/** Collect and parse the request body, bounded. */\r\nasync function readBody(req: IncomingMessage): Promise<Record<string, unknown>> {\r\n const chunks: Buffer[] = []\r\n let size = 0\r\n for await (const chunk of req) {\r\n const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)\r\n size += buffer.length\r\n if (size > MAX_BODY_BYTES) throw new Error('request body is too large')\r\n chunks.push(buffer)\r\n }\r\n const parsed = JSON.parse(Buffer.concat(chunks).toString('utf8')) as unknown\r\n if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {\r\n throw new Error('request body must be a JSON object')\r\n }\r\n return parsed as Record<string, unknown>\r\n}\r\n\r\n/** Normalize a Linux path for the wire (rejecting non-absolute input). */\r\nfunction requireLinuxPath(value: unknown, label: string): string {\r\n if (typeof value !== 'string' || !isAbsoluteLinuxPath(value)) {\r\n throw new Error(`${label} must be an absolute Linux path`)\r\n }\r\n return normalizeLinuxPath(value)\r\n}\r\n\r\n/** Validate a wire-supplied workspace path and return its canonical UNC form. */\r\nfunction requireWslUnc(value: unknown): string {\r\n if (typeof value !== 'string') throw new Error('path must be a string')\r\n const canonical = canonicalWslUnc(value)\r\n if (canonical === null) throw new Error('path must be a WSL UNC workspace path')\r\n return canonical\r\n}\r\n\r\n/** Resolve one directory listing over the 9P share. */\r\nfunction listWslDir(distro: string, linuxPath: string): WslDirListingWire {\r\n const unc = joinUnc(distro, linuxPath)\r\n const dirents = readdirSync(unc, { withFileTypes: true })\r\n const entries: WslDirEntryWire[] = dirents\r\n .slice(0, 1000)\r\n .map((dirent): WslDirEntryWire => {\r\n const kind: WslDirEntryWire['kind'] = dirent.isDirectory()\r\n ? 'directory'\r\n : dirent.isFile() ? 'file' : 'other'\r\n return { name: dirent.name, kind }\r\n })\r\n .sort((a, b) => {\r\n if (a.kind === 'directory' && b.kind !== 'directory') return -1\r\n if (a.kind !== 'directory' && b.kind === 'directory') return 1\r\n return a.name.localeCompare(b.name)\r\n })\r\n const parent = linuxPath === '/' ? null : linuxPath.split('/').slice(0, -1).join('/') || '/'\r\n return { path: linuxPath, parent, entries }\r\n}\r\n\r\n/** Route one method dispatch. */\r\nasync function dispatch(method: string, params: Record<string, unknown>): Promise<unknown> {\r\n switch (method) {\r\n case 'listDistros': {\r\n const distros = await listDistros()\r\n const fallback = await defaultDistro()\r\n if (fallback !== undefined && distros.includes(fallback)) {\r\n return [fallback, ...distros.filter(name => name !== fallback)]\r\n }\r\n return distros\r\n }\r\n case 'listDir': {\r\n const distro = requireDistro(params.distro)\r\n const path = requireLinuxPath(params.path, 'path')\r\n return listWslDir(distro, path)\r\n }\r\n case 'check': {\r\n const distro = requireDistro(params.distro)\r\n const path = requireLinuxPath(params.path, 'path')\r\n const unc = joinUnc(distro, path)\r\n try {\r\n const info = statSync(unc)\r\n return { exists: true, isDirectory: info.isDirectory() }\r\n } catch {\r\n return { exists: false, isDirectory: false }\r\n }\r\n }\r\n case 'setUser': {\r\n const path = requireWslUnc(params.path)\r\n const username = params.username\r\n if (username === undefined || username === '') {\r\n setWorkspaceUsername(path, undefined)\r\n } else {\r\n if (typeof username !== 'string' || !isValidWslUsername(username)) {\r\n throw new Error('username must match the Linux username pattern [A-Za-z_][A-Za-z0-9_.-]*')\r\n }\r\n setWorkspaceUsername(path, username)\r\n }\r\n return null\r\n }\r\n default:\r\n throw new Error(`unknown method \"${method}\"`)\r\n }\r\n}\r\n\r\n/** The `ctx.agentPresets` roster face this plugin consumes (optional service). */\r\ninterface AgentPresetsService {\r\n list(): Promise<{ id: string; broken?: string; path: string }[]>\r\n read(id: string): Promise<string>\r\n}\r\n\r\n/**\r\n * Materialize a `wsl-<mode>` variant for every healthy source preset, and\r\n * remove this plugin's managed residue: stale variants whose source\r\n * disappeared, plus the legacy standalone `wsl` preset directory (the\r\n * execution world now composes with modes; a standalone WSL mode no longer\r\n * exists). Managed files: rewritten on every boot.\r\n * @param agentPresets - the roster service.\r\n * @param dshHome - the harness home (user preset root parent).\r\n * @param shellPath - absolute path of the plugin's built WSL shell provider.\r\n * @param fsPath - absolute path of the plugin's built WSL fs provider.\r\n */\r\nasync function materializeVariants(\r\n agentPresets: AgentPresetsService,\r\n dshHome: string,\r\n shellPath: string,\r\n fsPath: string,\r\n): Promise<void> {\r\n const presets = await agentPresets.list()\r\n const userRoot = join(dshHome, '.agent-presets')\r\n const generated = new Set<string>()\r\n for (const preset of presets) {\r\n if (preset.broken !== undefined) continue\r\n if (isWslVariantId(preset.id)) continue\r\n const variantId = variantIdFor(preset.id)\r\n const source = await agentPresets.read(preset.id)\r\n const transformed = transformPresetForWsl(source, shellPath, fsPath)\r\n const dir = join(userRoot, variantId)\r\n mkdirSync(dir, { recursive: true })\r\n writeFileSync(join(dir, 'agent.cordis.yml'), transformed, 'utf8')\r\n let name = `WSL · ${preset.id}`\r\n let orderLine = ''\r\n try {\r\n const meta = readFileSync(join(dirname(preset.path), 'preset.yml'), 'utf8')\r\n const match = /^name:\\s*(.+)$/m.exec(meta)\r\n if (match?.[1] !== undefined && match[1].trim() !== '') name = `WSL · ${match[1].trim()}`\r\n // Inherit the source's declared order so the WSL variants line up with\r\n // the local modes in the roster (standard, PTC, minimal, cordis).\r\n const orderMatch = /^order:\\s*(\\d+)\\s*$/m.exec(meta)\r\n if (orderMatch?.[1] !== undefined) orderLine = `order: ${orderMatch[1]}\\n`\r\n } catch {\r\n // Absent or unreadable display metadata falls back to the id-based name.\r\n }\r\n writeFileSync(\r\n join(dir, 'preset.yml'),\r\n `name: ${name}\\n`\r\n + orderLine\r\n + `description: ${preset.id} 模式叠加 WSL 执行世界:bash 与文件工具运行在 WSL 发行版内。\\n`,\r\n 'utf8',\r\n )\r\n generated.add(variantId)\r\n }\r\n for (const entry of readdirSync(userRoot, { withFileTypes: true })) {\r\n if (!entry.isDirectory()) continue\r\n if (entry.name === 'wsl') {\r\n // The legacy standalone WSL mode: folded into the variants above.\r\n rmSync(join(userRoot, entry.name), { recursive: true, force: true })\r\n continue\r\n }\r\n if (!/^wsl-[a-z0-9-]+$/.test(entry.name)) continue\r\n if (!generated.has(entry.name)) rmSync(join(userRoot, entry.name), { recursive: true, force: true })\r\n }\r\n}\r\n\r\n/** Function-plugin plugin contract. */\r\nexport const name = 'dsh-wsl-workspace'\r\n\r\n/** Required services. */\r\nexport const inject = ['webServer']\r\n\r\n/** Validated plugin config (schemastery applied the defaults). */\r\nexport const Config: z<Config> = z.object({\r\n route: z.string().default(DEFAULT_ROUTE),\r\n})\r\n\r\n/**\r\n * Apply the host half: materialize the `wsl` preset plus a `wsl-<mode>`\r\n * variant for every healthy roster preset, register the data route, and\r\n * contribute the per-session `DSH_WSL_DISTRO` managed-env fact so the WSL\r\n * shell executor can resolve a plain Linux `workdir` to the calling\r\n * session's distribution.\r\n * @param ctx - the host plugin context.\r\n * @param config - the validated configuration.\r\n */\r\nexport function apply(ctx: Context, config: Config): void {\r\n const resolved = config as ResolvedConfig\r\n const dshHome = process.env.DSH_HOME ?? join(homedir(), '.dsh')\r\n const packageRoot = fileURLToPath(new URL('..', import.meta.url))\r\n const shellPath = join(packageRoot, 'lib', 'shell.js').replace(/\\\\/g, '/')\r\n const fsPath = join(packageRoot, 'lib', 'fs.js').replace(/\\\\/g, '/')\r\n\r\n const agentPresets = ctx.get('agentPresets') as unknown as AgentPresetsService | undefined\r\n if (agentPresets !== undefined) {\r\n ctx.effect(() => {\r\n void materializeVariants(agentPresets, dshHome, shellPath, fsPath).catch((error) => {\r\n // Variant generation is best-effort over a live roster: a missing or\r\n // unreadable source preset must not take the whole plugin down, but\r\n // the failure is surfaced loudly rather than hidden.\r\n console.error(`dsh-wsl-workspace: WSL preset-variant generation failed: ${messageOf(error)}`)\r\n })\r\n return () => {}\r\n }, 'dsh-wsl-workspace: WSL preset variants')\r\n }\r\n\r\n const shellEnv = ctx.get('shellEnv') as unknown as ShellEnvService | undefined\r\n if (shellEnv !== undefined) {\r\n ctx.effect(() => shellEnv.register({\r\n name: 'wsl-workspace-distro',\r\n variables: {\r\n DSH_WSL_DISTRO: {\r\n description: 'The WSL distribution of the calling session workspace, when the session cwd is a WSL UNC path.',\r\n },\r\n DSH_WSL_USER: {\r\n description: 'The Linux user of the calling session workspace, when the workspace has one configured.',\r\n },\r\n },\r\n resolve(execution) {\r\n const cwd = execution.agent?.session.header.cwd\r\n const unc = cwd === undefined ? null : parseWslUnc(cwd)\r\n if (unc === null) return {}\r\n const username = getWorkspaceUsername(joinUnc(unc.distro, unc.linuxPath))\r\n return username === undefined || username === ''\r\n ? { DSH_WSL_DISTRO: unc.distro }\r\n : { DSH_WSL_DISTRO: unc.distro, DSH_WSL_USER: username }\r\n },\r\n }), 'dsh-wsl-workspace: per-session distro env fact')\r\n }\r\n\r\n const webServer = ctx.get('webServer') as unknown as WebServerService\r\n ctx.effect(() => webServer.register({\r\n kind: 'exact',\r\n path: resolved.route,\r\n handler: async (req, res) => {\r\n if (!isLoopback(req.socket.remoteAddress) || !isLoopbackHost(req.headers.host)) {\r\n json(res, 403, { ok: false, error: 'loopback-only' })\r\n return\r\n }\r\n if (req.method !== 'POST') {\r\n json(res, 405, { ok: false, error: 'method not allowed' })\r\n return\r\n }\r\n let body: Record<string, unknown>\r\n try {\r\n body = await readBody(req)\r\n } catch (error) {\r\n json(res, 400, { ok: false, error: messageOf(error) })\r\n return\r\n }\r\n const method = typeof body.method === 'string' ? body.method : ''\r\n const params = body.params === undefined ? {} : body.params\r\n if (params === null || typeof params !== 'object' || Array.isArray(params)) {\r\n json(res, 400, { ok: false, error: 'params must be an object' })\r\n return\r\n }\r\n try {\r\n const value = await dispatch(method, params as Record<string, unknown>)\r\n json(res, 200, { ok: true, value })\r\n } catch (error) {\r\n json(res, 200, { ok: false, error: messageOf(error) })\r\n }\r\n },\r\n }), 'dsh-wsl-workspace: dialog data route')\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAeA,MAAM,aAAa,IAAI,IAAI;CAAC;CAAa;CAAa;CAAW;CAAkB;CAAc;AAAkB,CAAC;;AAGpH,SAAS,cAAc,WAAmB,QAAgB,eAAgC;CACxF,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,gBAAgB,UAAU,QAAQ,MAAM,IAAI,EAAE;EAC9C;EACA,gBAAgB,OAAO,QAAQ,MAAM,IAAI,EAAE;EAC3C;EACA;EACA;EACA;EACA,GAAI,gBACA;GACE;GACA;GACA;GACA;EACF,IACA,CAAC;EACL;CACF,CAAC,CAAC,KAAK,IAAI;AACb;;;;;AAMA,SAAS,uBAA+B;CACtC,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC,CAAC,KAAK,IAAI;AACb;;AAGA,MAAM,iBAAiB;;AAGvB,SAAS,cAAc,OAA4D;CACjF,MAAM,QAA0C,CAAC;CACjD,IAAI,QAAQ;CACZ,KAAK,IAAI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