dsh-wsl-workspace 0.2.2 → 0.3.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/README.de.md +49 -0
- package/README.es.md +49 -0
- package/README.fr.md +49 -0
- package/README.ja.md +49 -0
- package/README.ko.md +49 -0
- package/README.md +47 -47
- package/README.pt.md +49 -0
- package/README.ru.md +49 -0
- package/README.zh.md +46 -46
- package/lib/client.js +76 -5
- package/lib/client.js.map +1 -1
- package/lib/fs.js +188 -174
- package/lib/fs.js.map +1 -1
- package/lib/index.js +573 -541
- package/lib/index.js.map +1 -1
- package/lib/{paths-DBaSmi7x.js → paths-BDE1NVOv.js} +17 -2
- package/lib/paths-BDE1NVOv.js.map +1 -0
- package/lib/shell.js +382 -381
- package/lib/shell.js.map +1 -1
- package/lib/wsl-C5_mxGPM.js +228 -0
- package/lib/wsl-C5_mxGPM.js.map +1 -0
- package/lib/wsl-DdNPGaPo.js +1019 -0
- package/lib/wsl-DdNPGaPo.js.map +1 -0
- package/lib/wsl-credentials-BI4v5TNZ.js +109 -0
- package/lib/wsl-credentials-BI4v5TNZ.js.map +1 -0
- package/package.json +71 -61
- package/src/client/AddWslWorkspace.tsx +349 -346
- package/src/client/api.ts +124 -104
- package/src/client/index.ts +233 -194
- package/src/fs.ts +247 -228
- package/src/host/variants.ts +164 -199
- package/src/index.ts +93 -27
- package/src/shared/paths.ts +175 -159
- package/src/shared/wsl-credentials.ts +135 -85
- package/src/shell.ts +451 -441
- package/image-1.png +0 -0
- package/image.png +0 -0
- package/lib/paths-DBaSmi7x.js.map +0 -1
- package/lib/wsl-GjkUifnx.js +0 -179
- package/lib/wsl-GjkUifnx.js.map +0 -1
package/lib/index.js
CHANGED
|
@@ -1,542 +1,574 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as
|
|
3
|
-
import z from "@deepseek-ai/schemastery";
|
|
4
|
-
import {
|
|
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
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"#
|
|
38
|
-
"#
|
|
39
|
-
"#
|
|
40
|
-
"-
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
`
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
let
|
|
109
|
-
for (let index =
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
case "setUser": {
|
|
375
|
-
const path = requireWslUnc(params.path);
|
|
376
|
-
const username = params.username;
|
|
377
|
-
if (username === void 0 || username === "") setWorkspaceUsername(path, void 0);
|
|
378
|
-
else {
|
|
379
|
-
if (typeof username !== "string" || !isValidWslUsername(username)) throw new Error("username must match the Linux username pattern [A-Za-z_][A-Za-z0-9_.-]*");
|
|
380
|
-
setWorkspaceUsername(path, username);
|
|
381
|
-
}
|
|
382
|
-
return null;
|
|
383
|
-
}
|
|
384
|
-
default: throw new Error(`unknown method "${method}"`);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
if (
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
return
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
1
|
+
import { a as isAbsoluteLinuxPath, c as joinUnc, d as parseWslUnc, l as mntToWindowsPath, o as isValidWslUsername, r as listDistros, t as defaultDistro, u as normalizeLinuxPath } from "./wsl-C5_mxGPM.js";
|
|
2
|
+
import { a as registerWindowsWorkspace, i as listWorkspaceKeys, n as getWindowsWorkspace, o as setWorkspaceUsername, r as getWorkspaceUsername, t as canonicalWslUnc } from "./wsl-credentials-BI4v5TNZ.js";
|
|
3
|
+
import z from "@deepseek-ai/schemastery";
|
|
4
|
+
import { cpSync, existsSync, readFileSync, readdirSync, renameSync, 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
|
+
"str-replace-editor",
|
|
29
|
+
"filesystem",
|
|
30
|
+
"persistent-shell",
|
|
31
|
+
"custom-bash",
|
|
32
|
+
"bootstrap-filesystem"
|
|
33
|
+
]);
|
|
34
|
+
/** The injected WSL world group: providers + the bash/fs consumers, entry-local. */
|
|
35
|
+
function wslWorldGroup(shellPath, fsPath, includeEditor) {
|
|
36
|
+
return [
|
|
37
|
+
"# ── WSL execution world (dsh-wsl-workspace variant) ─────────────────────",
|
|
38
|
+
"# The shell and fs services are provided entry-locally (the isolate",
|
|
39
|
+
"# realm); host services (tools registry, shell-env, jobs) fall through.",
|
|
40
|
+
"# tool-fs-search is intentionally absent: the packaged ripgrep runs on",
|
|
41
|
+
"# the Windows host and cannot open Linux paths; WSL sessions search with",
|
|
42
|
+
"# shell tools instead.",
|
|
43
|
+
"- id: wsl-world",
|
|
44
|
+
" name: cordis:group",
|
|
45
|
+
" group: true",
|
|
46
|
+
" isolate:",
|
|
47
|
+
" shell: true",
|
|
48
|
+
" fs: true",
|
|
49
|
+
" config:",
|
|
50
|
+
` - id: shell-wsl`,
|
|
51
|
+
` name: '${shellPath.replace(/'/g, "''")}'`,
|
|
52
|
+
" - id: fs-wsl",
|
|
53
|
+
` name: '${fsPath.replace(/'/g, "''")}'`,
|
|
54
|
+
" - id: tool-bash",
|
|
55
|
+
" name: '@deepseek-ai/dsh-tool-bash'",
|
|
56
|
+
" - id: tool-fs",
|
|
57
|
+
" name: '@deepseek-ai/dsh-tool-fs'",
|
|
58
|
+
...includeEditor ? [
|
|
59
|
+
" - id: str-replace-editor",
|
|
60
|
+
" name: '@deepseek-ai/dsh-tool-str-replace-editor'",
|
|
61
|
+
" config:",
|
|
62
|
+
" maxOutputChars: 16000"
|
|
63
|
+
] : [],
|
|
64
|
+
""
|
|
65
|
+
].join("\n");
|
|
66
|
+
}
|
|
67
|
+
/** The sentence appended to a standard-like persona when the variant runs in WSL. */
|
|
68
|
+
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.";
|
|
69
|
+
/** The top-level rows of one composition, as (startLine, endLineExclusive) spans. */
|
|
70
|
+
function topLevelSpans(lines) {
|
|
71
|
+
const spans = [];
|
|
72
|
+
let start = -1;
|
|
73
|
+
for (let index = 0; index < lines.length; index++) if (lines[index]?.startsWith("- id: ") === true) {
|
|
74
|
+
if (start >= 0) spans.push({
|
|
75
|
+
start,
|
|
76
|
+
end: index
|
|
77
|
+
});
|
|
78
|
+
start = index;
|
|
79
|
+
}
|
|
80
|
+
if (start >= 0) spans.push({
|
|
81
|
+
start,
|
|
82
|
+
end: lines.length
|
|
83
|
+
});
|
|
84
|
+
return spans;
|
|
85
|
+
}
|
|
86
|
+
/** The row id of a top-level span, or undefined when the first line is malformed. */
|
|
87
|
+
function spanId(lines, span) {
|
|
88
|
+
return /^- id: ([A-Za-z0-9_.-]+)/.exec(lines[span.start] ?? "")?.[1];
|
|
89
|
+
}
|
|
90
|
+
/** Whether a top-level span is a `persona` row with an appendable folded text. */
|
|
91
|
+
function appendablePersona(lines, span) {
|
|
92
|
+
const block = lines.slice(span.start, span.end).join("\n");
|
|
93
|
+
if (!block.includes("complete: true") && /text: [>|-]/.test(block)) {
|
|
94
|
+
const textLine = block.split("\n").find((line) => /^(\s*)text: [>|-]/.test(line));
|
|
95
|
+
if (textLine !== void 0) {
|
|
96
|
+
const indent = /^(\s*)/.exec(textLine)?.[1]?.length ?? 0;
|
|
97
|
+
return block.split("\n").some((line) => line.length > indent && /^\s+/.test(line) && !line.includes(":"));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
/** Append the WSL sentence to a persona row's folded text (in place of its last text line). */
|
|
103
|
+
function appendPersona(lines, span) {
|
|
104
|
+
const block = lines.slice(span.start, span.end);
|
|
105
|
+
const textIndex = block.findIndex((line) => /^(\s*)text: [>|-]/.test(line));
|
|
106
|
+
if (textIndex < 0) return [...block];
|
|
107
|
+
const indent = /^(\s*)/.exec(block[textIndex] ?? "")?.[1]?.length ?? 0;
|
|
108
|
+
let lastText = -1;
|
|
109
|
+
for (let index = textIndex + 1; index < block.length; index++) {
|
|
110
|
+
const line = block[index] ?? "";
|
|
111
|
+
if (line.trim() === "") continue;
|
|
112
|
+
if (line.length > indent && /^\s+/.test(line)) lastText = index;
|
|
113
|
+
}
|
|
114
|
+
if (lastText < 0) return [...block];
|
|
115
|
+
const updated = [...block];
|
|
116
|
+
const textIndent = /^(\s*)/.exec(block[lastText] ?? "")?.[1] ?? " ";
|
|
117
|
+
updated.splice(lastText + 1, 0, `${textIndent}${PERSONA_APPEND}`);
|
|
118
|
+
return updated;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Transform one source preset composition into its WSL variant: drop the
|
|
122
|
+
* execution-world rows, keep everything else verbatim, and append the WSL
|
|
123
|
+
* world group. The persistent-shell group is NOT re-added: it registers the
|
|
124
|
+
* same `bash` tool name as the WSL world's `dsh-tool-bash`, and the tools
|
|
125
|
+
* registry rejects duplicates within one preset layer — the whole variant
|
|
126
|
+
* fails to mount and the session falls back to another preset. Its PTY
|
|
127
|
+
* backend additionally cannot run on this plugin's Windows host
|
|
128
|
+
* (`dsh-subprocess-local`: "terminal inspection is unsupported on platform
|
|
129
|
+
* win32"), so the group could never spawn a shell here anyway. The WSL
|
|
130
|
+
* world's ordinary `bash` tool covers command execution for every variant.
|
|
131
|
+
* @param source - the source composition text.
|
|
132
|
+
* @param shellPath - absolute path of the plugin's built WSL shell provider.
|
|
133
|
+
* @param fsPath - absolute path of the plugin's built WSL fs provider.
|
|
134
|
+
* @returns the variant composition text.
|
|
135
|
+
*/
|
|
136
|
+
function transformPresetForWsl(source, shellPath, fsPath) {
|
|
137
|
+
const lines = source.split("\n");
|
|
138
|
+
const spans = topLevelSpans(lines);
|
|
139
|
+
const kept = [];
|
|
140
|
+
let sawEditor = false;
|
|
141
|
+
let personaAppended = false;
|
|
142
|
+
for (const span of spans) {
|
|
143
|
+
const id = spanId(lines, span);
|
|
144
|
+
if (id === void 0) {
|
|
145
|
+
kept.push(...lines.slice(span.start, span.end));
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (WORLD_ROWS.has(id)) continue;
|
|
149
|
+
if (id === "persona" && !personaAppended && appendablePersona(lines, span)) {
|
|
150
|
+
kept.push(...appendPersona(lines, span));
|
|
151
|
+
personaAppended = true;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
kept.push(...lines.slice(span.start, span.end));
|
|
155
|
+
if (id === "str-replace-editor") sawEditor = true;
|
|
156
|
+
}
|
|
157
|
+
if (source.includes("str-replace-editor")) sawEditor = true;
|
|
158
|
+
const result = [...kept];
|
|
159
|
+
if (result.length > 0 && result[result.length - 1] !== "") result.push("");
|
|
160
|
+
result.push(wslWorldGroup(shellPath, fsPath, sawEditor));
|
|
161
|
+
return result.join("\n").replace(/\n{3,}/g, "\n\n").replace(/\n+$/, "\n");
|
|
162
|
+
}
|
|
163
|
+
/** Whether an id is one of this plugin's own preset directories. */
|
|
164
|
+
function isWslVariantId(id) {
|
|
165
|
+
return id === "wsl" || /^wsl-[a-z0-9-]+$/.test(id);
|
|
166
|
+
}
|
|
167
|
+
/** The variant id for one source preset id. */
|
|
168
|
+
function variantIdFor(sourceId) {
|
|
169
|
+
return `wsl-${sourceId.toLowerCase()}`;
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region src/index.ts
|
|
173
|
+
/** The HTTP route this plugin serves (a relative, same-origin path). */
|
|
174
|
+
const DEFAULT_ROUTE = "/wsl-workspace/api";
|
|
175
|
+
/**
|
|
176
|
+
* Bilingual display labels for the shipped source modes, matching the app's
|
|
177
|
+
* own built-in copy in each language — note the `code` preset is "PTC 模式"
|
|
178
|
+
* in the Chinese copy but "Code mode" in English. The DSH picker localizes
|
|
179
|
+
* only the four built-in ids itself; `wsl-*` variant ids render the
|
|
180
|
+
* preset.yml text verbatim, so the plugin writes one bilingual string so
|
|
181
|
+
* both locales can identify each variant. Custom presets keep their own
|
|
182
|
+
* name.
|
|
183
|
+
*/
|
|
184
|
+
const MODE_DISPLAY_LABELS = {
|
|
185
|
+
standard: {
|
|
186
|
+
en: "Standard mode",
|
|
187
|
+
zh: "标准模式"
|
|
188
|
+
},
|
|
189
|
+
code: {
|
|
190
|
+
en: "Code mode",
|
|
191
|
+
zh: "PTC 模式"
|
|
192
|
+
},
|
|
193
|
+
minimal: {
|
|
194
|
+
en: "Minimal mode",
|
|
195
|
+
zh: "极简模式"
|
|
196
|
+
},
|
|
197
|
+
cordis: {
|
|
198
|
+
en: "Creator mode",
|
|
199
|
+
zh: "创造模式"
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Quote a value as a single-line YAML single-quoted scalar. Plain scalars
|
|
204
|
+
* cannot contain `: ` (colon + space), which plain English sentences do —
|
|
205
|
+
* written unquoted they make the whole preset.yml unparsable, dropping the
|
|
206
|
+
* name, description and order together.
|
|
207
|
+
*/
|
|
208
|
+
function yamlScalar(value) {
|
|
209
|
+
return `'${value.replace(/'/g, "''")}'`;
|
|
210
|
+
}
|
|
211
|
+
/** The variant name for one shipped mode (bilingual) or a custom preset. */
|
|
212
|
+
function variantName(presetId, sourceName) {
|
|
213
|
+
const labels = MODE_DISPLAY_LABELS[presetId];
|
|
214
|
+
return labels === void 0 ? `WSL · ${sourceName}` : `WSL · ${labels.en}(${labels.zh})`;
|
|
215
|
+
}
|
|
216
|
+
/** The variant description for one shipped mode (bilingual) or a custom preset. */
|
|
217
|
+
function variantDescription(presetId) {
|
|
218
|
+
const labels = MODE_DISPLAY_LABELS[presetId];
|
|
219
|
+
return `WSL execution world for ${labels === void 0 ? presetId : `${labels.en}(${labels.zh})`}: bash and file tools run inside the WSL distribution.`;
|
|
220
|
+
}
|
|
221
|
+
const MAX_BODY_BYTES = 1024 * 1024;
|
|
222
|
+
/** Valid WSL distribution names: one path-safe segment (no separators, no dot-dirs). */
|
|
223
|
+
const DISTRO_PATTERN = /^[A-Za-z0-9][A-Za-z0-9 ._-]*$/;
|
|
224
|
+
/** The loopback hostnames the data route answers to (DNS-rebinding fence). */
|
|
225
|
+
const LOOPBACK_HOSTNAMES = new Set([
|
|
226
|
+
"localhost",
|
|
227
|
+
"127.0.0.1",
|
|
228
|
+
"::1",
|
|
229
|
+
"::ffff:127.0.0.1"
|
|
230
|
+
]);
|
|
231
|
+
/** True when a socket address is loopback (any IPv4/IPv6 spelling). */
|
|
232
|
+
function isLoopback(address) {
|
|
233
|
+
return address === "127.0.0.1" || address === "::1" || address === "::ffff:127.0.0.1";
|
|
234
|
+
}
|
|
235
|
+
/** The hostname part of a `Host` header value (port and IPv6 brackets stripped). */
|
|
236
|
+
function hostNameOf(host) {
|
|
237
|
+
if (host.startsWith("[")) {
|
|
238
|
+
const end = host.indexOf("]");
|
|
239
|
+
return end >= 0 ? host.slice(1, end) : host;
|
|
240
|
+
}
|
|
241
|
+
return host.split(":")[0] ?? "";
|
|
242
|
+
}
|
|
243
|
+
/** True when the request's `Host` header names a loopback host. */
|
|
244
|
+
function isLoopbackHost(host) {
|
|
245
|
+
return host !== void 0 && LOOPBACK_HOSTNAMES.has(hostNameOf(host).toLowerCase());
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Validate a wire-supplied distribution name before it becomes a UNC segment:
|
|
249
|
+
* an attacker-controlled segment containing separators or `..` would escape
|
|
250
|
+
* the `\\wsl.localhost\` share structure into arbitrary UNC paths.
|
|
251
|
+
* @param value - the raw wire value.
|
|
252
|
+
* @returns the validated distro name.
|
|
253
|
+
*/
|
|
254
|
+
function requireDistro(value) {
|
|
255
|
+
if (typeof value !== "string" || !DISTRO_PATTERN.test(value) || value === "." || value === "..") throw new Error("distro must be a valid WSL distribution name");
|
|
256
|
+
return value;
|
|
257
|
+
}
|
|
258
|
+
/** Human text for an unknown rejection. */
|
|
259
|
+
function messageOf(value) {
|
|
260
|
+
return value instanceof Error ? value.message : String(value);
|
|
261
|
+
}
|
|
262
|
+
/** Write one JSON envelope. */
|
|
263
|
+
function json(res, status, body) {
|
|
264
|
+
res.writeHead(status, {
|
|
265
|
+
"content-type": "application/json; charset=utf-8",
|
|
266
|
+
"cache-control": "no-store",
|
|
267
|
+
"x-content-type-options": "nosniff"
|
|
268
|
+
});
|
|
269
|
+
res.end(JSON.stringify(body));
|
|
270
|
+
}
|
|
271
|
+
/** Collect and parse the request body, bounded. */
|
|
272
|
+
async function readBody(req) {
|
|
273
|
+
const chunks = [];
|
|
274
|
+
let size = 0;
|
|
275
|
+
for await (const chunk of req) {
|
|
276
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
277
|
+
size += buffer.length;
|
|
278
|
+
if (size > MAX_BODY_BYTES) throw new Error("request body is too large");
|
|
279
|
+
chunks.push(buffer);
|
|
280
|
+
}
|
|
281
|
+
const parsed = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
282
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("request body must be a JSON object");
|
|
283
|
+
return parsed;
|
|
284
|
+
}
|
|
285
|
+
/** Normalize a Linux path for the wire (rejecting non-absolute input). */
|
|
286
|
+
function requireLinuxPath(value, label) {
|
|
287
|
+
if (typeof value !== "string" || !isAbsoluteLinuxPath(value)) throw new Error(`${label} must be an absolute Linux path`);
|
|
288
|
+
return normalizeLinuxPath(value);
|
|
289
|
+
}
|
|
290
|
+
/** Validate a wire-supplied workspace path and return its canonical UNC form. */
|
|
291
|
+
function requireWslUnc(value) {
|
|
292
|
+
if (typeof value !== "string") throw new Error("path must be a string");
|
|
293
|
+
const canonical = canonicalWslUnc(value);
|
|
294
|
+
if (canonical === null) throw new Error("path must be a WSL UNC workspace path");
|
|
295
|
+
return canonical;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Resolve one directory listing for the dialog. The 9P share (`\\wsl.localhost\…`)
|
|
299
|
+
* serves only the ext4 volume: `/mnt/<drive>` (drvfs) reads return Access
|
|
300
|
+
* denied, so drvfs paths are read through their Windows drive spelling and
|
|
301
|
+
* `/mnt` itself is synthesized from the drives present on the host.
|
|
302
|
+
*/
|
|
303
|
+
function listWslDir(distro, linuxPath) {
|
|
304
|
+
if (linuxPath === "/mnt") {
|
|
305
|
+
const entries = [];
|
|
306
|
+
for (let i = 0; i < 26; i++) {
|
|
307
|
+
const letter = String.fromCharCode(65 + i);
|
|
308
|
+
try {
|
|
309
|
+
if (statSync(`${letter}:\\`).isDirectory()) entries.push({
|
|
310
|
+
name: letter.toLowerCase(),
|
|
311
|
+
kind: "directory"
|
|
312
|
+
});
|
|
313
|
+
} catch {}
|
|
314
|
+
}
|
|
315
|
+
return {
|
|
316
|
+
path: "/mnt",
|
|
317
|
+
parent: "/",
|
|
318
|
+
entries
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
const winPath = mntToWindowsPath(linuxPath);
|
|
322
|
+
const entries = readdirSync(winPath !== null ? winPath : joinUnc(distro, linuxPath), { withFileTypes: true }).slice(0, 1e3).map((dirent) => {
|
|
323
|
+
const kind = dirent.isDirectory() ? "directory" : dirent.isFile() ? "file" : "other";
|
|
324
|
+
return {
|
|
325
|
+
name: dirent.name,
|
|
326
|
+
kind
|
|
327
|
+
};
|
|
328
|
+
}).sort((a, b) => {
|
|
329
|
+
if (a.kind === "directory" && b.kind !== "directory") return -1;
|
|
330
|
+
if (a.kind !== "directory" && b.kind === "directory") return 1;
|
|
331
|
+
return a.name.localeCompare(b.name);
|
|
332
|
+
});
|
|
333
|
+
return {
|
|
334
|
+
path: linuxPath,
|
|
335
|
+
parent: linuxPath === "/" ? null : linuxPath.split("/").slice(0, -1).join("/") || "/",
|
|
336
|
+
entries
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
/** Route one method dispatch. */
|
|
340
|
+
async function dispatch(method, params) {
|
|
341
|
+
switch (method) {
|
|
342
|
+
case "listDistros": {
|
|
343
|
+
const distros = await listDistros();
|
|
344
|
+
const fallback = await defaultDistro();
|
|
345
|
+
if (fallback !== void 0 && distros.includes(fallback)) return [fallback, ...distros.filter((name) => name !== fallback)];
|
|
346
|
+
return distros;
|
|
347
|
+
}
|
|
348
|
+
case "listDir": return listWslDir(requireDistro(params.distro), requireLinuxPath(params.path, "path"));
|
|
349
|
+
case "check": {
|
|
350
|
+
const distro = requireDistro(params.distro);
|
|
351
|
+
const path = requireLinuxPath(params.path, "path");
|
|
352
|
+
const winPath = mntToWindowsPath(path);
|
|
353
|
+
const readPath = winPath !== null ? winPath : joinUnc(distro, path);
|
|
354
|
+
try {
|
|
355
|
+
return {
|
|
356
|
+
exists: true,
|
|
357
|
+
isDirectory: statSync(readPath).isDirectory()
|
|
358
|
+
};
|
|
359
|
+
} catch {
|
|
360
|
+
return {
|
|
361
|
+
exists: false,
|
|
362
|
+
isDirectory: false
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
case "registerWindows": {
|
|
367
|
+
const distro = requireDistro(params.distro);
|
|
368
|
+
const winPath = mntToWindowsPath(requireLinuxPath(params.linuxPath, "path"));
|
|
369
|
+
if (winPath === null) throw new Error("registerWindows requires a /mnt/<drive> Linux path");
|
|
370
|
+
registerWindowsWorkspace(winPath, distro, typeof params.username === "string" ? params.username : void 0);
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
case "listWorkspaces": return listWorkspaceKeys();
|
|
374
|
+
case "setUser": {
|
|
375
|
+
const path = requireWslUnc(params.path);
|
|
376
|
+
const username = params.username;
|
|
377
|
+
if (username === void 0 || username === "") setWorkspaceUsername(path, void 0);
|
|
378
|
+
else {
|
|
379
|
+
if (typeof username !== "string" || !isValidWslUsername(username)) throw new Error("username must match the Linux username pattern [A-Za-z_][A-Za-z0-9_.-]*");
|
|
380
|
+
setWorkspaceUsername(path, username);
|
|
381
|
+
}
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
default: throw new Error(`unknown method "${method}"`);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Publish a fully staged preset directory while preserving the last complete
|
|
389
|
+
* variant if publication fails. Stable sibling names also let the next boot
|
|
390
|
+
* recover an interrupted old-to-backup rename before doing new work.
|
|
391
|
+
*/
|
|
392
|
+
function publishVariant(staging, dest) {
|
|
393
|
+
const previous = `${dest}.previous`;
|
|
394
|
+
if (!existsSync(dest) && existsSync(previous)) renameSync(previous, dest);
|
|
395
|
+
if (existsSync(previous)) rmSync(previous, {
|
|
396
|
+
recursive: true,
|
|
397
|
+
force: true
|
|
398
|
+
});
|
|
399
|
+
if (existsSync(dest)) renameSync(dest, previous);
|
|
400
|
+
try {
|
|
401
|
+
renameSync(staging, dest);
|
|
402
|
+
} catch (error) {
|
|
403
|
+
if (!existsSync(dest) && existsSync(previous)) renameSync(previous, dest);
|
|
404
|
+
throw error;
|
|
405
|
+
}
|
|
406
|
+
rmSync(previous, {
|
|
407
|
+
recursive: true,
|
|
408
|
+
force: true
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
/** Materialize one WSL variant per healthy source preset. */
|
|
412
|
+
async function materializeVariants(agentPresets, dshHome, shellPath, fsPath) {
|
|
413
|
+
const presets = await agentPresets.list();
|
|
414
|
+
const userRoot = join(dshHome, ".agent-presets");
|
|
415
|
+
const generated = /* @__PURE__ */ new Set();
|
|
416
|
+
for (const preset of presets) {
|
|
417
|
+
if (preset.broken !== void 0) continue;
|
|
418
|
+
if (isWslVariantId(preset.id)) continue;
|
|
419
|
+
const variantId = variantIdFor(preset.id);
|
|
420
|
+
const transformed = transformPresetForWsl(await agentPresets.read(preset.id), shellPath, fsPath);
|
|
421
|
+
const dir = join(userRoot, variantId);
|
|
422
|
+
const staging = `${dir}.staging`;
|
|
423
|
+
rmSync(staging, {
|
|
424
|
+
recursive: true,
|
|
425
|
+
force: true
|
|
426
|
+
});
|
|
427
|
+
cpSync(dirname(preset.path), staging, {
|
|
428
|
+
recursive: true,
|
|
429
|
+
force: true
|
|
430
|
+
});
|
|
431
|
+
writeFileSync(join(staging, "agent.cordis.yml"), transformed, "utf8");
|
|
432
|
+
const labels = MODE_DISPLAY_LABELS[preset.id];
|
|
433
|
+
let name = variantName(preset.id, preset.id);
|
|
434
|
+
let orderLine = "";
|
|
435
|
+
try {
|
|
436
|
+
const meta = readFileSync(join(dirname(preset.path), "preset.yml"), "utf8");
|
|
437
|
+
if (labels === void 0) {
|
|
438
|
+
const match = /^name:\s*(.+)$/m.exec(meta);
|
|
439
|
+
if (match?.[1] !== void 0 && match[1].trim() !== "") name = variantName(preset.id, match[1].trim());
|
|
440
|
+
}
|
|
441
|
+
const orderMatch = /^order:\s*(\d+)\s*$/m.exec(meta);
|
|
442
|
+
if (orderMatch?.[1] !== void 0) orderLine = `order: ${orderMatch[1]}\n`;
|
|
443
|
+
} catch {}
|
|
444
|
+
writeFileSync(join(staging, "preset.yml"), `name: ${yamlScalar(name)}\n` + orderLine + `description: ${yamlScalar(variantDescription(preset.id))}\n`, "utf8");
|
|
445
|
+
publishVariant(staging, dir);
|
|
446
|
+
generated.add(variantId);
|
|
447
|
+
}
|
|
448
|
+
for (const entry of readdirSync(userRoot, { withFileTypes: true })) {
|
|
449
|
+
if (!entry.isDirectory()) continue;
|
|
450
|
+
if (entry.name === "wsl") {
|
|
451
|
+
rmSync(join(userRoot, entry.name), {
|
|
452
|
+
recursive: true,
|
|
453
|
+
force: true
|
|
454
|
+
});
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
if (!/^wsl-[a-z0-9-]+$/.test(entry.name)) continue;
|
|
458
|
+
if (!generated.has(entry.name)) rmSync(join(userRoot, entry.name), {
|
|
459
|
+
recursive: true,
|
|
460
|
+
force: true
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
/** Function-plugin plugin contract. */
|
|
465
|
+
const name = "dsh-wsl-workspace";
|
|
466
|
+
/** Required services. */
|
|
467
|
+
const inject = ["webServer"];
|
|
468
|
+
/** Validated plugin config (schemastery applied the defaults). */
|
|
469
|
+
const Config = z.object({ route: z.string().default(DEFAULT_ROUTE) });
|
|
470
|
+
/**
|
|
471
|
+
* Apply the host half: materialize a `wsl-<mode>` variant for every healthy
|
|
472
|
+
* roster preset, register the data route, and
|
|
473
|
+
* contribute the per-session `DSH_WSL_DISTRO` managed-env fact so the WSL
|
|
474
|
+
* shell executor can resolve a plain Linux `workdir` to the calling
|
|
475
|
+
* session's distribution.
|
|
476
|
+
* @param ctx - the host plugin context.
|
|
477
|
+
* @param config - the validated configuration.
|
|
478
|
+
*/
|
|
479
|
+
function apply(ctx, config) {
|
|
480
|
+
const resolved = config;
|
|
481
|
+
const dshHome = process.env.DSH_HOME ?? join(homedir(), ".dsh");
|
|
482
|
+
const packageRoot = fileURLToPath(new URL("..", import.meta.url));
|
|
483
|
+
const shellPath = join(packageRoot, "lib", "shell.js").replace(/\\/g, "/");
|
|
484
|
+
const fsPath = join(packageRoot, "lib", "fs.js").replace(/\\/g, "/");
|
|
485
|
+
const agentPresets = ctx.get("agentPresets");
|
|
486
|
+
if (agentPresets !== void 0) ctx.effect(() => {
|
|
487
|
+
materializeVariants(agentPresets, dshHome, shellPath, fsPath).catch((error) => {
|
|
488
|
+
console.error(`dsh-wsl-workspace: WSL preset-variant generation failed: ${messageOf(error)}`);
|
|
489
|
+
});
|
|
490
|
+
return () => {};
|
|
491
|
+
}, "dsh-wsl-workspace: WSL preset variants");
|
|
492
|
+
const shellEnv = ctx.get("shellEnv");
|
|
493
|
+
if (shellEnv !== void 0) ctx.effect(() => shellEnv.register({
|
|
494
|
+
name: "wsl-workspace-distro",
|
|
495
|
+
variables: {
|
|
496
|
+
DSH_WSL_DISTRO: { description: "The WSL distribution of the calling session workspace, when the session cwd is a WSL UNC path." },
|
|
497
|
+
DSH_WSL_USER: { description: "The Linux user of the calling session workspace, when the workspace has one configured." }
|
|
498
|
+
},
|
|
499
|
+
resolve(execution) {
|
|
500
|
+
const cwd = execution.agent?.session.header.cwd;
|
|
501
|
+
const unc = cwd === void 0 ? null : parseWslUnc(cwd);
|
|
502
|
+
if (unc !== null) {
|
|
503
|
+
const username = getWorkspaceUsername(joinUnc(unc.distro, unc.linuxPath));
|
|
504
|
+
return username === void 0 || username === "" ? { DSH_WSL_DISTRO: unc.distro } : {
|
|
505
|
+
DSH_WSL_DISTRO: unc.distro,
|
|
506
|
+
DSH_WSL_USER: username
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
if (cwd !== void 0 && /^[A-Za-z]:[\\/]/.test(cwd)) {
|
|
510
|
+
const entry = getWindowsWorkspace(cwd);
|
|
511
|
+
if (entry !== void 0 && entry.distro !== void 0 && entry.distro !== "") return entry.username === void 0 || entry.username === "" ? { DSH_WSL_DISTRO: entry.distro } : {
|
|
512
|
+
DSH_WSL_DISTRO: entry.distro,
|
|
513
|
+
DSH_WSL_USER: entry.username
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
return {};
|
|
517
|
+
}
|
|
518
|
+
}), "dsh-wsl-workspace: per-session distro env fact");
|
|
519
|
+
const webServer = ctx.get("webServer");
|
|
520
|
+
ctx.effect(() => webServer.register({
|
|
521
|
+
kind: "exact",
|
|
522
|
+
path: resolved.route,
|
|
523
|
+
handler: async (req, res) => {
|
|
524
|
+
if (!isLoopback(req.socket.remoteAddress) || !isLoopbackHost(req.headers.host)) {
|
|
525
|
+
json(res, 403, {
|
|
526
|
+
ok: false,
|
|
527
|
+
error: "loopback-only"
|
|
528
|
+
});
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
if (req.method !== "POST") {
|
|
532
|
+
json(res, 405, {
|
|
533
|
+
ok: false,
|
|
534
|
+
error: "method not allowed"
|
|
535
|
+
});
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
let body;
|
|
539
|
+
try {
|
|
540
|
+
body = await readBody(req);
|
|
541
|
+
} catch (error) {
|
|
542
|
+
json(res, 400, {
|
|
543
|
+
ok: false,
|
|
544
|
+
error: messageOf(error)
|
|
545
|
+
});
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
const method = typeof body.method === "string" ? body.method : "";
|
|
549
|
+
const params = body.params === void 0 ? {} : body.params;
|
|
550
|
+
if (params === null || typeof params !== "object" || Array.isArray(params)) {
|
|
551
|
+
json(res, 400, {
|
|
552
|
+
ok: false,
|
|
553
|
+
error: "params must be an object"
|
|
554
|
+
});
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
try {
|
|
558
|
+
json(res, 200, {
|
|
559
|
+
ok: true,
|
|
560
|
+
value: await dispatch(method, params)
|
|
561
|
+
});
|
|
562
|
+
} catch (error) {
|
|
563
|
+
json(res, 200, {
|
|
564
|
+
ok: false,
|
|
565
|
+
error: messageOf(error)
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
}), "dsh-wsl-workspace: dialog data route");
|
|
570
|
+
}
|
|
571
|
+
//#endregion
|
|
572
|
+
export { Config, DEFAULT_ROUTE, apply, inject, name };
|
|
573
|
+
|
|
542
574
|
//# sourceMappingURL=index.js.map
|