dsh-plugin-wsl-env 0.26.1 → 0.26.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +79 -0
- package/README.md +1 -1
- package/docs/ARCHITECTURE.md +8 -1
- package/docs/ARCHITECTURE.zh.md +7 -1
- package/docs/CONFIGURATION.md +2 -1
- package/docs/CONFIGURATION.zh.md +2 -1
- package/docs/DIAGNOSTICS.md +5 -0
- package/docs/DIAGNOSTICS.zh.md +4 -0
- package/docs/LIMITATIONS.md +13 -1
- package/docs/LIMITATIONS.zh.md +12 -2
- package/docs/QUICKSTART.md +2 -1
- package/docs/QUICKSTART.zh.md +2 -1
- package/docs/README.zh.md +1 -1
- package/docs/REQUIREMENTS.zh.md +1 -1
- package/lib/git-exec.d.ts +39 -7
- package/lib/git-exec.js +151 -18
- package/lib/listing.d.ts +17 -0
- package/lib/listing.js +20 -0
- package/lib/messages.d.ts +27 -0
- package/lib/messages.js +26 -2
- package/lib/picker.js +33 -19
- package/lib/search-exec.d.ts +45 -9
- package/lib/search-exec.js +152 -20
- package/lib/subprocess.d.ts +4 -1
- package/lib/subprocess.js +16 -3
- package/lib/wsl.d.ts +21 -0
- package/lib/wsl.js +24 -0
- package/package.json +1 -1
- package/scripts/doctor.mjs +21 -13
package/lib/messages.d.ts
CHANGED
|
@@ -92,6 +92,33 @@ declare const en: {
|
|
|
92
92
|
workdir: string;
|
|
93
93
|
distro: string;
|
|
94
94
|
}) => string;
|
|
95
|
+
/**
|
|
96
|
+
* `search-exec`: the agent could not start the search program. The native
|
|
97
|
+
* agent cannot tell a missing executable from a missing directory, so both
|
|
98
|
+
* causes and the install remedy are named.
|
|
99
|
+
*/
|
|
100
|
+
searchProgramMissing: ({ program, distro, detail }: {
|
|
101
|
+
program: string;
|
|
102
|
+
distro: string;
|
|
103
|
+
detail: string;
|
|
104
|
+
}) => string;
|
|
105
|
+
/** `search-exec`: the working directory a search asked for does not exist. */
|
|
106
|
+
searchWorkdirMissing: ({ path }: {
|
|
107
|
+
path: string;
|
|
108
|
+
}) => string;
|
|
109
|
+
/**
|
|
110
|
+
* `git-exec`: the agent could not start git. The native agent cannot tell a
|
|
111
|
+
* missing executable from a missing directory, so both causes and the
|
|
112
|
+
* install remedy are named.
|
|
113
|
+
*/
|
|
114
|
+
gitProgramMissing: ({ distro, detail }: {
|
|
115
|
+
distro: string;
|
|
116
|
+
detail: string;
|
|
117
|
+
}) => string;
|
|
118
|
+
/** `git-exec`: the working directory a git snapshot asked for does not exist. */
|
|
119
|
+
gitWorkdirMissing: ({ path }: {
|
|
120
|
+
path: string;
|
|
121
|
+
}) => string;
|
|
95
122
|
/**
|
|
96
123
|
* `auto-preset`: a distro workspace is recorded as Windows access (9p), so
|
|
97
124
|
* the session runs the host preset. The model-facing half of the reminder;
|
package/lib/messages.js
CHANGED
|
@@ -69,6 +69,24 @@ const en = {
|
|
|
69
69
|
workdirAnotherDistro: ({ workdir, distro }) => `"${workdir}" names a workspace in another WSL distro, and this profile pins its commands to "${distro}" — ` +
|
|
70
70
|
`running them here would act on a different machine's tree. Open a session in that distro, ` +
|
|
71
71
|
`or point cwd/workdir at this distro.`,
|
|
72
|
+
/**
|
|
73
|
+
* `search-exec`: the agent could not start the search program. The native
|
|
74
|
+
* agent cannot tell a missing executable from a missing directory, so both
|
|
75
|
+
* causes and the install remedy are named.
|
|
76
|
+
*/
|
|
77
|
+
searchProgramMissing: ({ program, distro, detail }) => `${program} could not be started inside distro "${distro}" (${detail}). Commands run with wsl.exe's default PATH, so a user-local install under ~/.local/bin is invisible, and the search directory may also be gone. ` +
|
|
78
|
+
`Install ripgrep with "scripts/bootstrap.sh ${distro} --install" (from the package), or with the distro's own package manager.`,
|
|
79
|
+
/** `search-exec`: the working directory a search asked for does not exist. */
|
|
80
|
+
searchWorkdirMissing: ({ path }) => `The search directory "${path}" does not exist inside the distro. Create it, or point the session's working directory at a directory that exists.`,
|
|
81
|
+
/**
|
|
82
|
+
* `git-exec`: the agent could not start git. The native agent cannot tell a
|
|
83
|
+
* missing executable from a missing directory, so both causes and the
|
|
84
|
+
* install remedy are named.
|
|
85
|
+
*/
|
|
86
|
+
gitProgramMissing: ({ distro, detail }) => `git could not be started inside distro "${distro}" (${detail}). Commands run with wsl.exe's default PATH, so a user-local install under ~/.local/bin is invisible, and the snapshot directory may also be gone. ` +
|
|
87
|
+
`Install git with "scripts/bootstrap.sh ${distro} --install" (from the package), or with the distro's own package manager.`,
|
|
88
|
+
/** `git-exec`: the working directory a git snapshot asked for does not exist. */
|
|
89
|
+
gitWorkdirMissing: ({ path }) => `The git snapshot directory "${path}" does not exist inside the distro. Create it, or point the session's working directory at a directory that exists.`,
|
|
72
90
|
/**
|
|
73
91
|
* `auto-preset`: a distro workspace is recorded as Windows access (9p), so
|
|
74
92
|
* the session runs the host preset. The model-facing half of the reminder;
|
|
@@ -99,7 +117,7 @@ const en = {
|
|
|
99
117
|
/** `wsl_doctor` digest: one summary line for the checks the run's scope never executed; `reason` says why (the run's scope profile). */
|
|
100
118
|
doctorDigestSkipRow: ({ n, reason, ids }) => `[SKIP] not run in this scope — ${reason} (${n}): ${ids}`,
|
|
101
119
|
/** `wsl_doctor` digest: the scope reason for a quick run's skip line. */
|
|
102
|
-
doctorSkipReasonQuick: () => "the quick profile covers
|
|
120
|
+
doctorSkipReasonQuick: () => "the quick profile covers the prerequisites and the optional tools only",
|
|
103
121
|
/** `wsl_doctor` digest: the scope reason for a section-filtered run's skip line. */
|
|
104
122
|
doctorSkipReasonSections: ({ sections }) => `the run covered only: ${sections}`,
|
|
105
123
|
/** `wsl_doctor` digest: the scope reason when the report recorded none. */
|
|
@@ -146,6 +164,12 @@ const zh = {
|
|
|
146
164
|
`请创建该目录,或将 \`cwd\`(或请求的 \`workdir\`)指向一个已存在的目录。`,
|
|
147
165
|
workdirAnotherDistro: ({ workdir, distro }) => `"${workdir}" 指向另一个 WSL 发行版中的工作区,而本 profile 将命令固定在 "${distro}" —— ` +
|
|
148
166
|
`在这里运行会作用于另一台机器的目录树。请在该发行版中打开会话,或将 cwd/workdir 指向本发行版。`,
|
|
167
|
+
searchProgramMissing: ({ program, distro, detail }) => `无法在发行版 "${distro}" 内启动 ${program}(${detail})。命令使用 wsl.exe 给出的默认 PATH,因此安装在 ~/.local/bin 下的用户级版本不可见;搜索目录也可能已不存在。` +
|
|
168
|
+
`请用 "scripts/bootstrap.sh ${distro} --install"(随包提供)安装 ripgrep,或使用该发行版自己的包管理器。`,
|
|
169
|
+
searchWorkdirMissing: ({ path }) => `搜索目录 "${path}" 在发行版中不存在。请创建它,或将会话的工作目录指向一个已存在的目录。`,
|
|
170
|
+
gitProgramMissing: ({ distro, detail }) => `无法在发行版 "${distro}" 内启动 git(${detail})。命令使用 wsl.exe 给出的默认 PATH,因此安装在 ~/.local/bin 下的用户级版本不可见;快照目录也可能已不存在。` +
|
|
171
|
+
`请用 "scripts/bootstrap.sh ${distro} --install"(随包提供)安装 git,或使用该发行版自己的包管理器。`,
|
|
172
|
+
gitWorkdirMissing: ({ path }) => `git 快照目录 "${path}" 在发行版中不存在。请创建它,或将会话的工作目录指向一个已存在的目录。`,
|
|
149
173
|
hostModeWindowsAccess: ({ cwd, distro }) => `工作区 "${cwd}" 位于 WSL 发行版 "${distro}" 内,但被记录为 Windows 访问工作区,` +
|
|
150
174
|
`因此本会话运行在宿主(Windows)环境:命令经 PowerShell 执行,文件访问经过 9p 共享,发行版的 Linux 工具链不可用。` +
|
|
151
175
|
`不要在此假设 Linux 命令、路径或工具;如需在发行版内运行,须由操作者以 WSL preset 在本工作区新开会话。`,
|
|
@@ -160,7 +184,7 @@ const zh = {
|
|
|
160
184
|
doctorDigestNotRunLabel: () => "(不在本次范围)",
|
|
161
185
|
doctorDigestSessionLabel: ({ name }) => `${name}(当前会话的 distro)`,
|
|
162
186
|
doctorDigestSkipRow: ({ n, reason, ids }) => `[SKIP] 不在本次范围——${reason}(${n}):${ids}`,
|
|
163
|
-
doctorSkipReasonQuick: () => "quick
|
|
187
|
+
doctorSkipReasonQuick: () => "quick 档只探前置项与可选工具",
|
|
164
188
|
doctorSkipReasonSections: ({ sections }) => `本次只运行了这些分区:${sections}`,
|
|
165
189
|
doctorSkipReasonGeneric: () => "报告未记录运行范围",
|
|
166
190
|
doctorSkipGated: ({ id, reason }) => `[SKIP] ${id}——被前置阻断:${reason}`,
|
package/lib/picker.js
CHANGED
|
@@ -53,10 +53,10 @@ import { join, resolve } from "node:path";
|
|
|
53
53
|
import z from "@deepseek-ai/schemastery";
|
|
54
54
|
import { DirectoryPicker, DirectoryPickerError } from "@deepseek-ai/dsh-host-directory-picker";
|
|
55
55
|
import { UNC_PROVIDER_ROOT, distroRoot, isProviderRoot, isWslUnc, uncToPosix } from "./paths.js";
|
|
56
|
-
import { breadcrumbs, boundedInsert, dirListingArgv, fullyQualified, parseDirListing } from "./listing.js";
|
|
56
|
+
import { breadcrumbs, boundedInsert, dirListingArgv, distroMkdirArgv, fullyQualified, parseDirListing } from "./listing.js";
|
|
57
57
|
import { listDistros, linuxHome, runCapture } from "./wsl.js";
|
|
58
58
|
import { sharedAgent } from "./agent-shared.js";
|
|
59
|
-
import { AgentUnavailableError } from "./agent-errors.js";
|
|
59
|
+
import { AgentUnavailableError, CwdError, SpawnError } from "./agent-errors.js";
|
|
60
60
|
/** How long a resolved distro list stays fresh before it is queried again. */
|
|
61
61
|
const DEFAULT_DISTRO_CACHE_MS = 5_000;
|
|
62
62
|
/**
|
|
@@ -412,13 +412,21 @@ export class WslDirectoryPicker extends DirectoryPicker {
|
|
|
412
412
|
stdout = result.stdout;
|
|
413
413
|
}
|
|
414
414
|
catch (error) {
|
|
415
|
-
if (
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
415
|
+
if (error instanceof AgentUnavailableError) {
|
|
416
|
+
try {
|
|
417
|
+
stdout = await runCapture([this.config.wslPath, "-d", parsed.distro, "--cd", linuxDir, "--exec", ...dirListingArgv(linuxDir)], signal);
|
|
418
|
+
}
|
|
419
|
+
catch (fallbackError) {
|
|
420
|
+
throw new DirectoryPickerError("directory-unreadable", target, `cannot list "${target}": ${messageOf(fallbackError)}`);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
else if (error instanceof CwdError || error instanceof SpawnError) {
|
|
424
|
+
// The agent could not enter the directory (or start the program): a
|
|
425
|
+
// picker failure with the path, not an opaque provider error.
|
|
426
|
+
throw new DirectoryPickerError("directory-unreadable", target, `cannot list "${target}": ${messageOf(error)}`);
|
|
419
427
|
}
|
|
420
|
-
|
|
421
|
-
throw
|
|
428
|
+
else {
|
|
429
|
+
throw error;
|
|
422
430
|
}
|
|
423
431
|
}
|
|
424
432
|
return parseDirListing(stdout, linuxDir, target, this.config.maxEntries);
|
|
@@ -524,7 +532,7 @@ export class WslDirectoryPicker extends DirectoryPicker {
|
|
|
524
532
|
const parsed = uncToPosix(parent);
|
|
525
533
|
const linuxParent = parsed.linuxPath.length > 0 ? parsed.linuxPath : "/";
|
|
526
534
|
try {
|
|
527
|
-
const result = await sharedAgent(parsed.distro).exec({ cwd: linuxParent, argv:
|
|
535
|
+
const result = await sharedAgent(parsed.distro).exec({ cwd: linuxParent, argv: distroMkdirArgv(linuxParent, name), timeoutMs: 10_000 });
|
|
528
536
|
if (result.exitCode === 0)
|
|
529
537
|
return target;
|
|
530
538
|
const detail = result.stderr.toString("utf8");
|
|
@@ -535,18 +543,24 @@ export class WslDirectoryPicker extends DirectoryPicker {
|
|
|
535
543
|
catch (error) {
|
|
536
544
|
if (error instanceof DirectoryPickerError)
|
|
537
545
|
throw error;
|
|
538
|
-
if (
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
546
|
+
if (error instanceof AgentUnavailableError) {
|
|
547
|
+
try {
|
|
548
|
+
// Absolute target: a `--cd` that silently fell back to `/` must not
|
|
549
|
+
// turn this into a creation somewhere else.
|
|
550
|
+
await runCapture([this.config.wslPath, "-d", parsed.distro, "--cd", linuxParent, "--exec", ...distroMkdirArgv(linuxParent, name)]);
|
|
551
|
+
return target;
|
|
552
|
+
}
|
|
553
|
+
catch (fallbackError) {
|
|
554
|
+
const message = messageOf(fallbackError);
|
|
555
|
+
if (/File exists/i.test(message))
|
|
556
|
+
throw new DirectoryPickerError("directory-exists", target, `${target} already exists`);
|
|
557
|
+
throw new DirectoryPickerError("directory-create-failed", target, `cannot create "${target}": ${message}`);
|
|
558
|
+
}
|
|
543
559
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
if (/File exists/i.test(message))
|
|
547
|
-
throw new DirectoryPickerError("directory-exists", target, `${target} already exists`);
|
|
548
|
-
throw new DirectoryPickerError("directory-create-failed", target, `cannot create "${target}": ${message}`);
|
|
560
|
+
if (error instanceof CwdError || error instanceof SpawnError) {
|
|
561
|
+
throw new DirectoryPickerError("directory-create-failed", target, `cannot create "${target}": ${messageOf(error)}`);
|
|
549
562
|
}
|
|
563
|
+
throw error;
|
|
550
564
|
}
|
|
551
565
|
}
|
|
552
566
|
}
|
package/lib/search-exec.d.ts
CHANGED
|
@@ -10,15 +10,45 @@
|
|
|
10
10
|
*
|
|
11
11
|
* The agent being out is not an error condition here — it is the fallback
|
|
12
12
|
* cue. `spawnFallback` (the shipped one-shot handle the caller builds) is
|
|
13
|
-
* consulted lazily inside `done
|
|
14
|
-
*
|
|
15
|
-
* the
|
|
13
|
+
* consulted lazily inside `done`. Cancellation shares one channel: the
|
|
14
|
+
* caller's `signal` and `kill()` abort the agent exec, which settles `done`
|
|
15
|
+
* as killed (`{exitCode: null, signal: "SIGTERM"}`) — the same shape the
|
|
16
|
+
* one-shot path reports for a killed search.
|
|
16
17
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
18
|
+
* ## Failure surfacing: the tool must read rg's own failure, not a provider blow-up
|
|
19
|
+
*
|
|
20
|
+
* rg's exit codes are a contract the tool reads: `1` is "no matches", `2` is
|
|
21
|
+
* "rg itself failed", and anything else is a provider-class failure. A distro
|
|
22
|
+
* without ripgrep is the common, actionable failure — `docs/LIMITATIONS.md`
|
|
23
|
+
* promises it surfaces as exit 127 with the bootstrap remedy — so this module
|
|
24
|
+
* turns the agent's two local failures into that shape instead of rejecting
|
|
25
|
+
* `done` (which the tool renders as an opaque "ripgrep provider failure", with
|
|
26
|
+
* no program name and no remedy):
|
|
27
|
+
*
|
|
28
|
+
* - A `SpawnError` means the agent could not start the program. The native
|
|
29
|
+
* agent reports both a missing executable and a missing working directory
|
|
30
|
+
* that way, without naming either, so the synthesized message names both
|
|
31
|
+
* possibilities and the install remedy; the exit code is 127.
|
|
32
|
+
* - A `CwdError` names the directory that could not be entered. It is
|
|
33
|
+
* synthesized as rg's own error exit code (`2`) with relay-shaped text —
|
|
34
|
+
* never `1`, which the tool would read as "no matches" and report as an
|
|
35
|
+
* empty success.
|
|
36
|
+
*
|
|
37
|
+
* Neither failure falls back to the one-shot path. A missing program would
|
|
38
|
+
* only produce the relay's `execvpe(rg) failed` at exit `1` (again the
|
|
39
|
+
* "no matches" dialect), and a missing directory is worse: `wsl.exe --cd`
|
|
40
|
+
* does not fail on it — it warns, runs the command in `/`, and exits 0. The
|
|
41
|
+
* shell executor can afford the one-shot retry because it decorates the
|
|
42
|
+
* result with its workdir verdict; this handle has no such decoration point.
|
|
43
|
+
* Everything else — a genuine agent failure that is not `AgentUnavailableError`
|
|
44
|
+
* — still propagates through `done` as a rejection.
|
|
45
|
+
*
|
|
46
|
+
* The one-shot delegate is post-processed the same way, because the agent
|
|
47
|
+
* being out must not change what a broken environment looks like: a missing
|
|
48
|
+
* program's `execvpe(rg) failed` line (exit 1) becomes the same 127, and the
|
|
49
|
+
* relay's `chdir(...) failed` warning — which `wsl.exe` writes while it runs
|
|
50
|
+
* the search in `/` and exits 0/1 — becomes the same explicit directory
|
|
51
|
+
* failure instead of a silent wrong-directory result.
|
|
22
52
|
*
|
|
23
53
|
* Pure shaping over injected collaborators, so the handle semantics are
|
|
24
54
|
* unit-testable without a distro.
|
|
@@ -70,7 +100,7 @@ export interface SearchExecutionHandle {
|
|
|
70
100
|
* @param object - the handle's collaborators.
|
|
71
101
|
* @returns the search handle (`done`, `collected`, `kill`).
|
|
72
102
|
*/
|
|
73
|
-
export declare function searchExecutionHandle({ agent, cwd, argv, maxOutputBytes, signal, spawnFallback }: {
|
|
103
|
+
export declare function searchExecutionHandle({ agent, cwd, argv, distro, maxOutputBytes, signal, spawnFallback }: {
|
|
74
104
|
/**
|
|
75
105
|
* The {@link WslAgent}-like runner: `exec` accepting
|
|
76
106
|
* `{cwd, argv, maxOutputBytes, signal}` and resolving
|
|
@@ -81,6 +111,12 @@ export declare function searchExecutionHandle({ agent, cwd, argv, maxOutputBytes
|
|
|
81
111
|
cwd: string;
|
|
82
112
|
/** The distro-side argv (`rg` and its arguments). */
|
|
83
113
|
argv: string[];
|
|
114
|
+
/**
|
|
115
|
+
* The distro name, for the failures' remedies and the relay
|
|
116
|
+
* post-processing. The synthesized text names the distro so the model can
|
|
117
|
+
* relay an install command without another probe.
|
|
118
|
+
*/
|
|
119
|
+
distro: string;
|
|
84
120
|
/**
|
|
85
121
|
* Per-stream capture ceiling the agent enforces; the tool's own raw-output
|
|
86
122
|
* budget rides here.
|
package/lib/search-exec.js
CHANGED
|
@@ -10,15 +10,45 @@
|
|
|
10
10
|
*
|
|
11
11
|
* The agent being out is not an error condition here — it is the fallback
|
|
12
12
|
* cue. `spawnFallback` (the shipped one-shot handle the caller builds) is
|
|
13
|
-
* consulted lazily inside `done
|
|
14
|
-
*
|
|
15
|
-
* the
|
|
13
|
+
* consulted lazily inside `done`. Cancellation shares one channel: the
|
|
14
|
+
* caller's `signal` and `kill()` abort the agent exec, which settles `done`
|
|
15
|
+
* as killed (`{exitCode: null, signal: "SIGTERM"}`) — the same shape the
|
|
16
|
+
* one-shot path reports for a killed search.
|
|
16
17
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
18
|
+
* ## Failure surfacing: the tool must read rg's own failure, not a provider blow-up
|
|
19
|
+
*
|
|
20
|
+
* rg's exit codes are a contract the tool reads: `1` is "no matches", `2` is
|
|
21
|
+
* "rg itself failed", and anything else is a provider-class failure. A distro
|
|
22
|
+
* without ripgrep is the common, actionable failure — `docs/LIMITATIONS.md`
|
|
23
|
+
* promises it surfaces as exit 127 with the bootstrap remedy — so this module
|
|
24
|
+
* turns the agent's two local failures into that shape instead of rejecting
|
|
25
|
+
* `done` (which the tool renders as an opaque "ripgrep provider failure", with
|
|
26
|
+
* no program name and no remedy):
|
|
27
|
+
*
|
|
28
|
+
* - A `SpawnError` means the agent could not start the program. The native
|
|
29
|
+
* agent reports both a missing executable and a missing working directory
|
|
30
|
+
* that way, without naming either, so the synthesized message names both
|
|
31
|
+
* possibilities and the install remedy; the exit code is 127.
|
|
32
|
+
* - A `CwdError` names the directory that could not be entered. It is
|
|
33
|
+
* synthesized as rg's own error exit code (`2`) with relay-shaped text —
|
|
34
|
+
* never `1`, which the tool would read as "no matches" and report as an
|
|
35
|
+
* empty success.
|
|
36
|
+
*
|
|
37
|
+
* Neither failure falls back to the one-shot path. A missing program would
|
|
38
|
+
* only produce the relay's `execvpe(rg) failed` at exit `1` (again the
|
|
39
|
+
* "no matches" dialect), and a missing directory is worse: `wsl.exe --cd`
|
|
40
|
+
* does not fail on it — it warns, runs the command in `/`, and exits 0. The
|
|
41
|
+
* shell executor can afford the one-shot retry because it decorates the
|
|
42
|
+
* result with its workdir verdict; this handle has no such decoration point.
|
|
43
|
+
* Everything else — a genuine agent failure that is not `AgentUnavailableError`
|
|
44
|
+
* — still propagates through `done` as a rejection.
|
|
45
|
+
*
|
|
46
|
+
* The one-shot delegate is post-processed the same way, because the agent
|
|
47
|
+
* being out must not change what a broken environment looks like: a missing
|
|
48
|
+
* program's `execvpe(rg) failed` line (exit 1) becomes the same 127, and the
|
|
49
|
+
* relay's `chdir(...) failed` warning — which `wsl.exe` writes while it runs
|
|
50
|
+
* the search in `/` and exits 0/1 — becomes the same explicit directory
|
|
51
|
+
* failure instead of a silent wrong-directory result.
|
|
22
52
|
*
|
|
23
53
|
* Pure shaping over injected collaborators, so the handle semantics are
|
|
24
54
|
* unit-testable without a distro.
|
|
@@ -29,20 +59,56 @@
|
|
|
29
59
|
*
|
|
30
60
|
* @module dsh-plugin-wsl-env/search-exec
|
|
31
61
|
*/
|
|
32
|
-
import { AgentUnavailableError } from "./agent-errors.js";
|
|
62
|
+
import { AgentUnavailableError, CwdError, SpawnError } from "./agent-errors.js";
|
|
63
|
+
import { execProgramFailure, workdirFailure } from "./wsl.js";
|
|
64
|
+
import { t } from "./messages.js";
|
|
65
|
+
/** The program the search spawn runs, when the caller's argv does not say. */
|
|
66
|
+
const SEARCH_PROGRAM = "rg";
|
|
67
|
+
/**
|
|
68
|
+
* The exit code the synthesized results use for a failed search. `2` is rg's
|
|
69
|
+
* own error code: `1` belongs to "no matches", which the tool renders as an
|
|
70
|
+
* empty result rather than a failure.
|
|
71
|
+
*/
|
|
72
|
+
const SEARCH_ERROR_EXIT = 2;
|
|
73
|
+
/** The exit code a shell reports for a command it could not run. */
|
|
74
|
+
const COMMAND_NOT_FOUND_EXIT = 127;
|
|
75
|
+
/**
|
|
76
|
+
* The synthesized failure one search settles with when the program could not
|
|
77
|
+
* start: rg's error dialect is not available, so the message carries both
|
|
78
|
+
* plausible causes (a missing program and a missing directory) and the
|
|
79
|
+
* install remedy the docs promise.
|
|
80
|
+
*
|
|
81
|
+
* @param object - the failure facts.
|
|
82
|
+
* @returns the stderr text.
|
|
83
|
+
*/
|
|
84
|
+
function programFailureText({ program, distro, detail }) {
|
|
85
|
+
return t("searchProgramMissing", { program, distro, detail });
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The relay-shaped stderr one search settles with when its working directory
|
|
89
|
+
* is gone — the same line the typed `CwdError` carries into a shell command's
|
|
90
|
+
* synthesized result, plus the directory's own remedy.
|
|
91
|
+
*
|
|
92
|
+
* @param linuxPath - the directory the agent could not enter.
|
|
93
|
+
* @returns the stderr text.
|
|
94
|
+
*/
|
|
95
|
+
function workdirFailureText(linuxPath) {
|
|
96
|
+
return `<3>WSL: CreateProcessCommon: chdir(${linuxPath}) failed: No such file or directory\n${t("searchWorkdirMissing", { path: linuxPath })}`;
|
|
97
|
+
}
|
|
33
98
|
/**
|
|
34
99
|
* Run one search command through the agent and present it as a search handle.
|
|
35
100
|
*
|
|
36
101
|
* @param object - the handle's collaborators.
|
|
37
102
|
* @returns the search handle (`done`, `collected`, `kill`).
|
|
38
103
|
*/
|
|
39
|
-
export function searchExecutionHandle({ agent, cwd, argv, maxOutputBytes = 0, signal, spawnFallback }) {
|
|
104
|
+
export function searchExecutionHandle({ agent, cwd, argv, distro, maxOutputBytes = 0, signal, spawnFallback }) {
|
|
40
105
|
const state = { delegate: undefined, stdout: undefined, stderr: undefined };
|
|
41
106
|
const controller = new AbortController();
|
|
42
107
|
if (signal?.aborted)
|
|
43
108
|
controller.abort(signal.reason);
|
|
44
109
|
else
|
|
45
110
|
signal?.addEventListener("abort", () => controller.abort(signal.reason), { once: true });
|
|
111
|
+
const program = argv[0] ?? SEARCH_PROGRAM;
|
|
46
112
|
const reader = (slot) => ({
|
|
47
113
|
readFrom(from) {
|
|
48
114
|
const buffer = state[slot] ?? Buffer.alloc(0);
|
|
@@ -50,6 +116,63 @@ export function searchExecutionHandle({ agent, cwd, argv, maxOutputBytes = 0, si
|
|
|
50
116
|
return { text: buffer.subarray(start).toString("utf8"), lossy: false, nextOffset: buffer.length };
|
|
51
117
|
},
|
|
52
118
|
});
|
|
119
|
+
/**
|
|
120
|
+
* Settle on a synthesized failure: drop any delegate so `collected` serves
|
|
121
|
+
* the buffers this facade owns, and keep the streams empty on stdout.
|
|
122
|
+
*
|
|
123
|
+
* @param exitCode - rg's dialect exit code for the failure.
|
|
124
|
+
* @param stderr - the model-facing diagnostic, remedy included.
|
|
125
|
+
* @returns the settled outcome.
|
|
126
|
+
*/
|
|
127
|
+
const settleFailure = (exitCode, stderr) => {
|
|
128
|
+
state.delegate = undefined;
|
|
129
|
+
state.stdout = Buffer.alloc(0);
|
|
130
|
+
state.stderr = Buffer.from(stderr, "utf8");
|
|
131
|
+
return { exitCode, signal: null };
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* The 127 result for a program the distro could not start.
|
|
135
|
+
*
|
|
136
|
+
* @param detail - the agent's or the relay's own spawn diagnostic.
|
|
137
|
+
* @returns the settled outcome.
|
|
138
|
+
*/
|
|
139
|
+
const settleProgramMissing = (detail) => settleFailure(COMMAND_NOT_FOUND_EXIT, programFailureText({ program, distro, detail }));
|
|
140
|
+
/**
|
|
141
|
+
* The rg-error result for a directory the distro could not enter.
|
|
142
|
+
*
|
|
143
|
+
* @param linuxPath - the directory that could not be entered.
|
|
144
|
+
* @returns the settled outcome.
|
|
145
|
+
*/
|
|
146
|
+
const settleWorkdirMissing = (linuxPath) => settleFailure(SEARCH_ERROR_EXIT, workdirFailureText(linuxPath));
|
|
147
|
+
/**
|
|
148
|
+
* Delegate one agent-unavailable request to the one-shot handle, translating
|
|
149
|
+
* the relay's missing-program failure into the documented 127 shape. A
|
|
150
|
+
* delegated outcome that names no missing program passes through verbatim
|
|
151
|
+
* (its collected streams stay the delegate's).
|
|
152
|
+
*
|
|
153
|
+
* @returns the settled outcome.
|
|
154
|
+
*/
|
|
155
|
+
const settleDelegate = async () => {
|
|
156
|
+
const delegate = spawnFallback();
|
|
157
|
+
state.delegate = delegate;
|
|
158
|
+
const outcome = await delegate.done;
|
|
159
|
+
if (outcome.exitCode === null)
|
|
160
|
+
return outcome;
|
|
161
|
+
const text = delegate.collected.stderr?.readFrom(0).text ?? "";
|
|
162
|
+
// `wsl.exe --cd <missing>` warns, then runs the command in `/` and exits
|
|
163
|
+
// 0/1 — a silent wrong-directory search. The relay warning is the only
|
|
164
|
+
// evidence, so it becomes the same explicit failure the agent's CwdError
|
|
165
|
+
// produces.
|
|
166
|
+
const missingDir = workdirFailure("", text);
|
|
167
|
+
if (missingDir !== undefined)
|
|
168
|
+
return settleWorkdirMissing(missingDir);
|
|
169
|
+
// A missing program surfaces as `execvpe(rg) failed` at exit 1 — the
|
|
170
|
+
// tool's no-matches dialect. Translate it into the documented 127.
|
|
171
|
+
const relayFailure = execProgramFailure("", text);
|
|
172
|
+
if (relayFailure !== undefined)
|
|
173
|
+
return settleProgramMissing(relayFailure);
|
|
174
|
+
return outcome;
|
|
175
|
+
};
|
|
53
176
|
const handle = {
|
|
54
177
|
get collected() {
|
|
55
178
|
if (state.delegate !== undefined)
|
|
@@ -64,17 +187,26 @@ export function searchExecutionHandle({ agent, cwd, argv, maxOutputBytes = 0, si
|
|
|
64
187
|
state.stderr = result.stderr;
|
|
65
188
|
}
|
|
66
189
|
catch (error) {
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
190
|
+
if (controller.signal.aborted) {
|
|
191
|
+
// Our kill() or the caller's cancellation: the killed outcome the
|
|
192
|
+
// one-shot path reports, not a failure.
|
|
193
|
+
return { exitCode: null, signal: "SIGTERM" };
|
|
194
|
+
}
|
|
195
|
+
if (error instanceof CwdError) {
|
|
196
|
+
// The directory is gone. Synthesize rg's own error code with the
|
|
197
|
+
// relay-shaped line, so the tool reports a failure that names the
|
|
198
|
+
// path instead of rejecting as a provider failure.
|
|
199
|
+
return settleWorkdirMissing(error.linuxPath);
|
|
74
200
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
201
|
+
if (error instanceof SpawnError) {
|
|
202
|
+
// The agent could not start the program. The native agent reports
|
|
203
|
+
// both a missing executable and a missing workdir this way, so the
|
|
204
|
+
// message names both and the remedy makes it actionable.
|
|
205
|
+
return settleProgramMissing(error.message);
|
|
206
|
+
}
|
|
207
|
+
if (!(error instanceof AgentUnavailableError))
|
|
208
|
+
throw error;
|
|
209
|
+
return await settleDelegate();
|
|
78
210
|
}
|
|
79
211
|
return { exitCode: result.exitCode, signal: null };
|
|
80
212
|
})(),
|
package/lib/subprocess.d.ts
CHANGED
|
@@ -295,7 +295,10 @@ export declare class WslSubprocessRuntime extends LocalSubprocessRuntime {
|
|
|
295
295
|
* shipped handle's). Both decisions are pure coordinate functions
|
|
296
296
|
* (`search-route.js`, `git-route.js`); a spawn neither names (any other
|
|
297
297
|
* program, any drive or relative directory) reaches the shipped
|
|
298
|
-
* implementation verbatim.
|
|
298
|
+
* implementation verbatim. A broken distro surfaces the program's own
|
|
299
|
+
* failure instead of a provider rejection: a missing rg or git reports
|
|
300
|
+
* exit 127 with the bootstrap remedy, and a missing workdir reports that
|
|
301
|
+
* directory; `search-exec.js` and `git-exec.js` own those translations.
|
|
299
302
|
*
|
|
300
303
|
* @param spec - the spawn request.
|
|
301
304
|
* @returns the live search handle.
|
package/lib/subprocess.js
CHANGED
|
@@ -332,7 +332,10 @@ export class WslSubprocessRuntime extends LocalSubprocessRuntime {
|
|
|
332
332
|
* shipped handle's). Both decisions are pure coordinate functions
|
|
333
333
|
* (`search-route.js`, `git-route.js`); a spawn neither names (any other
|
|
334
334
|
* program, any drive or relative directory) reaches the shipped
|
|
335
|
-
* implementation verbatim.
|
|
335
|
+
* implementation verbatim. A broken distro surfaces the program's own
|
|
336
|
+
* failure instead of a provider rejection: a missing rg or git reports
|
|
337
|
+
* exit 127 with the bootstrap remedy, and a missing workdir reports that
|
|
338
|
+
* directory; `search-exec.js` and `git-exec.js` own those translations.
|
|
336
339
|
*
|
|
337
340
|
* @param spec - the spawn request.
|
|
338
341
|
* @returns the live search handle.
|
|
@@ -351,7 +354,11 @@ export class WslSubprocessRuntime extends LocalSubprocessRuntime {
|
|
|
351
354
|
...spec,
|
|
352
355
|
argv: gitRewrite.wslArgv,
|
|
353
356
|
cwd: this.hostCwd(),
|
|
354
|
-
|
|
357
|
+
// The relay's own diagnostics are UTF-16LE unless this is set; the
|
|
358
|
+
// snapshot handle reads the `chdir(...) failed` / `execvpe(git)
|
|
359
|
+
// failed` lines to turn a broken distro into git's own failure
|
|
360
|
+
// shape instead of a silent "not a repository".
|
|
361
|
+
env: { ...(wslenv.length > 0 ? { ...env, WSLENV: wslEnvValue(wslenv) } : env), WSL_UTF8: "1" },
|
|
355
362
|
});
|
|
356
363
|
// Agent-first: the warm resident answers a git call in ~2 ms where a
|
|
357
364
|
// one-shot `wsl.exe` spends ~230 ms of process startup, and a snapshot
|
|
@@ -392,6 +399,7 @@ export class WslSubprocessRuntime extends LocalSubprocessRuntime {
|
|
|
392
399
|
agent: sharedAgent(rewrite.distro),
|
|
393
400
|
cwd: rewrite.linuxCwd,
|
|
394
401
|
argv: rewrite.rgArgv,
|
|
402
|
+
distro: rewrite.distro,
|
|
395
403
|
// One budget serves both streams; the stdout budget is the binding one,
|
|
396
404
|
// and a pathological stderr is still bounded by it.
|
|
397
405
|
maxOutputBytes: spec.stdio.stdout?.maxBytes ?? 0,
|
|
@@ -402,7 +410,12 @@ export class WslSubprocessRuntime extends LocalSubprocessRuntime {
|
|
|
402
410
|
// `wsl.exe --cd` carries the Linux directory; the host process itself
|
|
403
411
|
// must start in a Windows directory, as with a terminal launch.
|
|
404
412
|
cwd: this.hostCwd(),
|
|
405
|
-
|
|
413
|
+
// The relay writes its own diagnostics as UTF-16LE unless this is
|
|
414
|
+
// set. The search handle reads the `execvpe(rg) failed` line to turn
|
|
415
|
+
// a missing distro rg into rg's documented exit 127, so the line
|
|
416
|
+
// must arrive as UTF-8 — and a human reading the raw relay text gets
|
|
417
|
+
// a readable message too.
|
|
418
|
+
env: { ...this.forwardedEnv(spec), WSL_UTF8: "1" },
|
|
406
419
|
}),
|
|
407
420
|
});
|
|
408
421
|
}
|
package/lib/wsl.d.ts
CHANGED
|
@@ -146,6 +146,27 @@ export declare function shellArgs(shellPath: string, login: boolean): string[];
|
|
|
146
146
|
* @returns the directory that could not be entered, or undefined.
|
|
147
147
|
*/
|
|
148
148
|
export declare function workdirFailure(stdout?: string, stderr?: string): string | undefined;
|
|
149
|
+
/**
|
|
150
|
+
* The relay line for a program `wsl.exe --exec` could not start, when its
|
|
151
|
+
* output carries one.
|
|
152
|
+
*
|
|
153
|
+
* A missing `--exec` binary does not surface as a shell's `127`: the relay
|
|
154
|
+
* writes a `CreateProcessCommon: execvpe(<program>) failed: No such file or
|
|
155
|
+
* directory` line to STDERR and exits **1** — the exit code callers such as a
|
|
156
|
+
* search or a git snapshot read as "empty result", not as a failure. The line
|
|
157
|
+
* is matched here (on NUL-stripped text, because the relay answers in UTF-16LE
|
|
158
|
+
* unless `WSL_UTF8` was pinned) so a facade can turn a missing distro program
|
|
159
|
+
* into its own actionable failure.
|
|
160
|
+
*
|
|
161
|
+
* The whole matched line is returned, not just the program name: it is the
|
|
162
|
+
* relay's own evidence and reads well as the parenthesized detail of a
|
|
163
|
+
* caller's message.
|
|
164
|
+
*
|
|
165
|
+
* @param stdout - a command's captured stdout; absent reads as empty.
|
|
166
|
+
* @param stderr - its captured stderr; absent reads as empty.
|
|
167
|
+
* @returns the matched relay line, or undefined.
|
|
168
|
+
*/
|
|
169
|
+
export declare function execProgramFailure(stdout?: string, stderr?: string): string | undefined;
|
|
149
170
|
/**
|
|
150
171
|
* The flags that make an interactive shell a login shell.
|
|
151
172
|
*
|
package/lib/wsl.js
CHANGED
|
@@ -214,6 +214,30 @@ export function workdirFailure(stdout, stderr) {
|
|
|
214
214
|
const match = /<3>WSL[^\n]*CreateProcessCommon[^\n]*chdir\(([^)]*)\) failed/.exec(text);
|
|
215
215
|
return match?.[1];
|
|
216
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* The relay line for a program `wsl.exe --exec` could not start, when its
|
|
219
|
+
* output carries one.
|
|
220
|
+
*
|
|
221
|
+
* A missing `--exec` binary does not surface as a shell's `127`: the relay
|
|
222
|
+
* writes a `CreateProcessCommon: execvpe(<program>) failed: No such file or
|
|
223
|
+
* directory` line to STDERR and exits **1** — the exit code callers such as a
|
|
224
|
+
* search or a git snapshot read as "empty result", not as a failure. The line
|
|
225
|
+
* is matched here (on NUL-stripped text, because the relay answers in UTF-16LE
|
|
226
|
+
* unless `WSL_UTF8` was pinned) so a facade can turn a missing distro program
|
|
227
|
+
* into its own actionable failure.
|
|
228
|
+
*
|
|
229
|
+
* The whole matched line is returned, not just the program name: it is the
|
|
230
|
+
* relay's own evidence and reads well as the parenthesized detail of a
|
|
231
|
+
* caller's message.
|
|
232
|
+
*
|
|
233
|
+
* @param stdout - a command's captured stdout; absent reads as empty.
|
|
234
|
+
* @param stderr - its captured stderr; absent reads as empty.
|
|
235
|
+
* @returns the matched relay line, or undefined.
|
|
236
|
+
*/
|
|
237
|
+
export function execProgramFailure(stdout, stderr) {
|
|
238
|
+
const text = `${stdout ?? ""}\n${stderr ?? ""}`.replace(/\0/g, "");
|
|
239
|
+
return /execvpe\([^)\n]*\) failed:[^\n]*No such file or directory/iu.exec(text)?.[0];
|
|
240
|
+
}
|
|
217
241
|
/**
|
|
218
242
|
* Shells whose `-l` flag means a login shell.
|
|
219
243
|
*
|
package/package.json
CHANGED