dsh-plugin-wsl-env 0.19.0 → 0.22.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/CHANGELOG.md +188 -1
- package/README.md +2 -2
- package/client.d.ts +5 -0
- package/client.js +218 -0
- package/cordis.patch.yml +75 -1
- package/docs/API.md +1 -0
- package/docs/CONFIGURATION.md +48 -5
- package/docs/CONFIGURATION.zh.md +15 -1
- package/docs/DIAGNOSTICS.md +110 -0
- package/docs/DIAGNOSTICS.zh.md +96 -0
- package/docs/LIMITATIONS.md +25 -0
- package/docs/LIMITATIONS.zh.md +7 -0
- package/docs/MIGRATION.md +1 -1
- package/docs/QUICKSTART.md +19 -3
- package/docs/RELEASING.md +3 -0
- package/docs/ROADMAP-1.0.md +49 -4
- package/docs/UPSTREAM-FILE-REFERENCE-SEAM.md +5 -0
- package/docs/UPSTREAM-OPEN-IN-APP.md +33 -0
- package/lib/client-host.d.ts +29 -0
- package/lib/client-host.js +29 -0
- package/lib/cwd-prompt-tool.d.ts +88 -0
- package/lib/cwd-prompt-tool.js +94 -0
- package/lib/cwd-prompt.d.ts +166 -0
- package/lib/cwd-prompt.js +203 -0
- package/lib/doctor-live.d.ts +5 -1
- package/lib/doctor-live.js +3 -2
- package/lib/index.d.ts +11 -0
- package/lib/index.js +10 -8
- package/lib/messages.d.ts +238 -0
- package/lib/messages.js +292 -0
- package/lib/preflight.d.ts +24 -0
- package/lib/preflight.js +111 -11
- package/lib/sandbox-core.js +7 -14
- package/lib/session-scope.js +10 -5
- package/lib/shell-env.d.ts +25 -0
- package/lib/shell-env.js +56 -0
- package/lib/shell.d.ts +3 -1
- package/lib/shell.js +3 -1
- package/lib/update-check.d.ts +197 -0
- package/lib/update-check.js +211 -0
- package/lib/wsl-doctor-command.d.ts +105 -0
- package/lib/wsl-doctor-command.js +240 -0
- package/lib/wsl-doctor-tool.d.ts +214 -0
- package/lib/wsl-doctor-tool.js +423 -0
- package/locale/doctor/en.json +30 -0
- package/locale/doctor/zh.json +30 -0
- package/package.json +47 -5
- package/scripts/doctor.mjs +1606 -171
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The language the plugin's runtime refusal and remedy messages render in,
|
|
3
|
+
* following the harness app's locale setting.
|
|
4
|
+
*
|
|
5
|
+
* The preference lives in the host composition as the `locale` entry's
|
|
6
|
+
* `preference` field (`@deepseek-ai/dsh-client-locale`'s host half declares it
|
|
7
|
+
* volatile), persisted through the host `settings` service. This module reads
|
|
8
|
+
* it through an OPTIONAL `settings` injection — the service belongs to the
|
|
9
|
+
* base bundle, and a profile without it (or a `settings` that never resolves)
|
|
10
|
+
* keeps the English defaults, which is also every test's default. A language
|
|
11
|
+
* switch re-reads on the service's `settings/document-updated` event, so
|
|
12
|
+
* following the remedy or switching language needs no app restart.
|
|
13
|
+
*
|
|
14
|
+
* Only plugin-authored text is cataloged here. The `fs-decisions` refusals and
|
|
15
|
+
* the fsio replica stay byte-identical English — the tool layer matches on
|
|
16
|
+
* those strings (see `src/fs-decisions.ts` and `docs/UPSTREAM-FSIO-EXPORT.md`).
|
|
17
|
+
*
|
|
18
|
+
* This is a TypeScript source built to `lib/messages.js`; edit THIS file and
|
|
19
|
+
* run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
20
|
+
* `pnpm test` fails when it drifts.
|
|
21
|
+
*
|
|
22
|
+
* @module dsh-plugin-wsl-env/messages
|
|
23
|
+
*/
|
|
24
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
25
|
+
/** The languages the catalogs ship. More locales are additive: add a table and widen the resolver. */
|
|
26
|
+
export type MessagesLocale = "en" | "zh";
|
|
27
|
+
/**
|
|
28
|
+
* The message templates, keyed by call site. Each entry owns its parameter
|
|
29
|
+
* shape; the `zh` table is type-checked against the `en` table's key and
|
|
30
|
+
* parameter union, so the two catalogs cannot drift apart silently.
|
|
31
|
+
*/
|
|
32
|
+
declare const en: {
|
|
33
|
+
/** `sessionScopeProblem`: systemd is not PID 1 in the distro. */
|
|
34
|
+
sessionScopeNoSystemd: ({ distro }: {
|
|
35
|
+
distro: string;
|
|
36
|
+
}) => string;
|
|
37
|
+
/** `sessionScopeProblem`: `systemctl --user` does not answer. */
|
|
38
|
+
sessionScopeNoUserManager: ({ distro }: {
|
|
39
|
+
distro: string;
|
|
40
|
+
}) => string;
|
|
41
|
+
/** `sessionScopeProblem`: the `systemd-run` binary is missing. */
|
|
42
|
+
sessionScopeNoSystemdRun: ({ distro }: {
|
|
43
|
+
distro: string;
|
|
44
|
+
}) => string;
|
|
45
|
+
/** `sessionScopeProblem`: the user manager would stop with the last session. */
|
|
46
|
+
sessionScopeNoLinger: ({ distro }: {
|
|
47
|
+
distro: string;
|
|
48
|
+
}) => string;
|
|
49
|
+
/**
|
|
50
|
+
* `sessionScopeProblem`: the probe's answer is empty or unrecognized. The
|
|
51
|
+
* caller renders `answer` (the quoted word, or `(nothing)`) and `errorSuffix`
|
|
52
|
+
* (`""` or `": <error>"`) so both languages keep one sentence shape.
|
|
53
|
+
*/
|
|
54
|
+
sessionScopeUnknownAnswer: ({ distro, answer, errorSuffix }: {
|
|
55
|
+
distro: string;
|
|
56
|
+
answer: string;
|
|
57
|
+
errorSuffix: string;
|
|
58
|
+
}) => string;
|
|
59
|
+
/** `missingBwrapRemedy` without a detected package family. */
|
|
60
|
+
bwrapMissingGeneric: ({ distro }: {
|
|
61
|
+
distro: string;
|
|
62
|
+
}) => string;
|
|
63
|
+
/** `missingBwrapRemedy` with a family's direct install command. */
|
|
64
|
+
bwrapMissingFamily: ({ distro, direct }: {
|
|
65
|
+
distro: string;
|
|
66
|
+
direct: string;
|
|
67
|
+
}) => string;
|
|
68
|
+
/** `composeBwrapFailure`: bwrap ran and refused — present but unusable. */
|
|
69
|
+
bwrapBroken: ({ distro, output }: {
|
|
70
|
+
distro: string;
|
|
71
|
+
output: string;
|
|
72
|
+
}) => string;
|
|
73
|
+
/** `bwrapInstallHint`: bwrap probed healthy but failed a real command. */
|
|
74
|
+
bwrapRuntimeFailure: ({ distro }: {
|
|
75
|
+
distro: string;
|
|
76
|
+
}) => string;
|
|
77
|
+
/** `composeBwrapFailure`: the unclassified probe's raw output, appended to a remedy. */
|
|
78
|
+
bwrapProbeFailedSuffix: ({ output }: {
|
|
79
|
+
output: string;
|
|
80
|
+
}) => string;
|
|
81
|
+
/** `throwIfDistroUnavailable`: wsl.exe says the distro is gone. */
|
|
82
|
+
distroUnavailable: ({ code, distro }: {
|
|
83
|
+
code: string;
|
|
84
|
+
distro: string;
|
|
85
|
+
}) => string;
|
|
86
|
+
/** `throwIfWorkdirMissing`: `wsl.exe --cd` fell back to `/`. */
|
|
87
|
+
workdirMissing: ({ missing }: {
|
|
88
|
+
missing: string;
|
|
89
|
+
}) => string;
|
|
90
|
+
/** `throwIfWorkdirInAnotherDistro`: the workspace names a pinned-against distro. */
|
|
91
|
+
workdirAnotherDistro: ({ workdir, distro }: {
|
|
92
|
+
workdir: string;
|
|
93
|
+
distro: string;
|
|
94
|
+
}) => string;
|
|
95
|
+
/** `wsl_doctor` digest: the verdict line. `verdict` is the report's own `ready`/`blocked`. */
|
|
96
|
+
doctorDigestVerdict: ({ verdict }: {
|
|
97
|
+
verdict: string;
|
|
98
|
+
}) => string;
|
|
99
|
+
/** `wsl_doctor` digest: the host-wide group heading. */
|
|
100
|
+
doctorDigestHostLabel: () => string;
|
|
101
|
+
/** `wsl_doctor` digest: the heading for checks the run's scope never executed. */
|
|
102
|
+
doctorDigestNotRunLabel: () => string;
|
|
103
|
+
/** `wsl_doctor` digest: marks which distro group is the session's own. */
|
|
104
|
+
doctorDigestSessionLabel: ({ name }: {
|
|
105
|
+
name: string;
|
|
106
|
+
}) => string;
|
|
107
|
+
/** `wsl_doctor` digest: one summary line for the checks the run's scope never executed; `reason` says why (the run's scope profile). */
|
|
108
|
+
doctorDigestSkipRow: ({ n, reason, ids }: {
|
|
109
|
+
n: number;
|
|
110
|
+
reason: string;
|
|
111
|
+
ids: string;
|
|
112
|
+
}) => string;
|
|
113
|
+
/** `wsl_doctor` digest: the scope reason for a quick run's skip line. */
|
|
114
|
+
doctorSkipReasonQuick: () => string;
|
|
115
|
+
/** `wsl_doctor` digest: the scope reason for a section-filtered run's skip line. */
|
|
116
|
+
doctorSkipReasonSections: ({ sections }: {
|
|
117
|
+
sections: string;
|
|
118
|
+
}) => string;
|
|
119
|
+
/** `wsl_doctor` digest: the scope reason when the report recorded none. */
|
|
120
|
+
doctorSkipReasonGeneric: () => string;
|
|
121
|
+
/** `wsl_doctor` digest: one line per check a failed prerequisite gated out; `reason` names the blocker. */
|
|
122
|
+
doctorSkipGated: ({ id, reason }: {
|
|
123
|
+
id: string;
|
|
124
|
+
reason: string;
|
|
125
|
+
}) => string;
|
|
126
|
+
/** `wsl_doctor` digest: per-group tallies, one entry per non-zero status. */
|
|
127
|
+
doctorTallyOk: ({ n }: {
|
|
128
|
+
n: number;
|
|
129
|
+
}) => string;
|
|
130
|
+
doctorTallyWarn: ({ n }: {
|
|
131
|
+
n: number;
|
|
132
|
+
}) => string;
|
|
133
|
+
doctorTallyFail: ({ n }: {
|
|
134
|
+
n: number;
|
|
135
|
+
}) => string;
|
|
136
|
+
doctorTallyUnknown: ({ n }: {
|
|
137
|
+
n: number;
|
|
138
|
+
}) => string;
|
|
139
|
+
doctorTallyInfo: ({ n }: {
|
|
140
|
+
n: number;
|
|
141
|
+
}) => string;
|
|
142
|
+
doctorTallySkipped: ({ n }: {
|
|
143
|
+
n: number;
|
|
144
|
+
}) => string;
|
|
145
|
+
/** `wsl_doctor` digest: the remedy prefix under a failed check. */
|
|
146
|
+
doctorDigestFixPrefix: ({ remedy }: {
|
|
147
|
+
remedy: string;
|
|
148
|
+
}) => string;
|
|
149
|
+
/** `wsl_doctor` digest: the ready note (how to attach the full report). */
|
|
150
|
+
doctorDigestNoteReady: () => string;
|
|
151
|
+
/** `wsl_doctor` digest: the blocked note (the rerun is the re-verification). */
|
|
152
|
+
doctorDigestNoteBlocked: () => string;
|
|
153
|
+
/** `wsl_doctor` digest: the blocked summary tail; `noneBlocking` is the fixed clause. */
|
|
154
|
+
doctorDigestBlockedTail: ({ blockers, warnings, skipped, note }: {
|
|
155
|
+
blockers: string;
|
|
156
|
+
warnings: number;
|
|
157
|
+
skipped: number;
|
|
158
|
+
note: string;
|
|
159
|
+
}) => string;
|
|
160
|
+
};
|
|
161
|
+
type Catalog = typeof en;
|
|
162
|
+
type MessageKey = keyof Catalog;
|
|
163
|
+
/**
|
|
164
|
+
* The locale the message builders render in.
|
|
165
|
+
*
|
|
166
|
+
* @returns the active catalog language.
|
|
167
|
+
*/
|
|
168
|
+
export declare function messagesLocale(): MessagesLocale;
|
|
169
|
+
/**
|
|
170
|
+
* Force the message language. The wiring calls this from the resolved
|
|
171
|
+
* `locale.preference`; tests call it directly and reset afterwards.
|
|
172
|
+
*
|
|
173
|
+
* @param locale - the language to render in.
|
|
174
|
+
*/
|
|
175
|
+
export declare function configureMessagesLocale(locale: MessagesLocale): void;
|
|
176
|
+
/**
|
|
177
|
+
* Render one message in the active language, falling back to the English
|
|
178
|
+
* template when the active catalog somehow lacks the key (the catalogs are
|
|
179
|
+
* type-checked against each other, so this guards runtime drift only).
|
|
180
|
+
*
|
|
181
|
+
* The `params` type correlates the parameters with the key: the conditional
|
|
182
|
+
* resolves per call site, so `t("sessionScopeNoLinger", { distro })`
|
|
183
|
+
* typechecks while `t("sessionScopeNoLinger", { missing })` does not. It
|
|
184
|
+
* lives in the JSDoc because a comment between the parameters would have the
|
|
185
|
+
* type-stripping build emit a line with trailing whitespace, which the style
|
|
186
|
+
* gate refuses.
|
|
187
|
+
*
|
|
188
|
+
* @typeParam K - the message key.
|
|
189
|
+
* @param key - the message to render.
|
|
190
|
+
* @param params - the key's parameters, as the template declares them.
|
|
191
|
+
* @returns the rendered message.
|
|
192
|
+
*/
|
|
193
|
+
export declare function t<K extends MessageKey>(key: K, params: Catalog[K] extends (first: infer P) => string ? P : never): string;
|
|
194
|
+
/**
|
|
195
|
+
* Map one `locale.preference` value onto a catalog language. The app's
|
|
196
|
+
* language ids are BCP 47-style tags (`zh`, `en`, `ja`, …); the plugin ships
|
|
197
|
+
* zh and en, and every other id renders English.
|
|
198
|
+
*
|
|
199
|
+
* @param preference - the stored preference, or anything else when unset.
|
|
200
|
+
* @returns the catalog language the preference selects.
|
|
201
|
+
*/
|
|
202
|
+
export declare function resolveMessagesLocale(preference: unknown): MessagesLocale;
|
|
203
|
+
/**
|
|
204
|
+
* Follow the harness locale for the caller's composition. Every row wires its
|
|
205
|
+
* own injection (the shell executor, the fs provider and the preflight all
|
|
206
|
+
* call this), so a hot-reloaded row re-wires too; the redundant reads converge
|
|
207
|
+
* on the same app-wide preference and the events are rare.
|
|
208
|
+
*
|
|
209
|
+
* The `settings` service is optional — a profile without it (some CLI
|
|
210
|
+
* compositions) keeps English. When it is present, the preference is read once
|
|
211
|
+
* the service resolves and again on every `settings/document-updated` event,
|
|
212
|
+
* which also covers the `locale` entry activating after this row did. A read
|
|
213
|
+
* that throws keeps the previous language: this is presentation, not gating.
|
|
214
|
+
*
|
|
215
|
+
* A browser whose user never picked a language in Settings has NO persisted
|
|
216
|
+
* `locale.preference` — its Chinese UI came from the navigator's provisional
|
|
217
|
+
* match, which the Host settings never record. For that case the fallback
|
|
218
|
+
* reads the process's ICU default locale (Electron: the OS UI language), so
|
|
219
|
+
* a zh-CN Windows with a provisional-Chinese UI still renders Chinese. An
|
|
220
|
+
* explicit Settings choice always wins over the fallback.
|
|
221
|
+
*
|
|
222
|
+
* @param ctx - the row's composition context.
|
|
223
|
+
*/
|
|
224
|
+
export declare function installMessagesLocale(ctx: Context): void;
|
|
225
|
+
/**
|
|
226
|
+
* Restore English. Tests only: production wiring is process-wide by design.
|
|
227
|
+
*/
|
|
228
|
+
export declare function resetMessagesLocaleForTests(): void;
|
|
229
|
+
/**
|
|
230
|
+
* The no-settings fallback: the process's ICU default locale, which in the
|
|
231
|
+
* desktop app follows the OS UI language (a zh-CN Windows yields `zh-CN`).
|
|
232
|
+
* Under Node's small-icu builds this is `en-US`, which maps to English — the
|
|
233
|
+
* previous default. Exported for tests.
|
|
234
|
+
*
|
|
235
|
+
* @returns {"en" | "zh"} the language the OS-level locale selects.
|
|
236
|
+
*/
|
|
237
|
+
export declare function hostFallbackLocale(): MessagesLocale;
|
|
238
|
+
export {};
|
package/lib/messages.js
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The language the plugin's runtime refusal and remedy messages render in,
|
|
3
|
+
* following the harness app's locale setting.
|
|
4
|
+
*
|
|
5
|
+
* The preference lives in the host composition as the `locale` entry's
|
|
6
|
+
* `preference` field (`@deepseek-ai/dsh-client-locale`'s host half declares it
|
|
7
|
+
* volatile), persisted through the host `settings` service. This module reads
|
|
8
|
+
* it through an OPTIONAL `settings` injection — the service belongs to the
|
|
9
|
+
* base bundle, and a profile without it (or a `settings` that never resolves)
|
|
10
|
+
* keeps the English defaults, which is also every test's default. A language
|
|
11
|
+
* switch re-reads on the service's `settings/document-updated` event, so
|
|
12
|
+
* following the remedy or switching language needs no app restart.
|
|
13
|
+
*
|
|
14
|
+
* Only plugin-authored text is cataloged here. The `fs-decisions` refusals and
|
|
15
|
+
* the fsio replica stay byte-identical English — the tool layer matches on
|
|
16
|
+
* those strings (see `src/fs-decisions.ts` and `docs/UPSTREAM-FSIO-EXPORT.md`).
|
|
17
|
+
*
|
|
18
|
+
* This is a TypeScript source built to `lib/messages.js`; edit THIS file and
|
|
19
|
+
* run `pnpm run build` — the artifact under `lib/` is generated, and
|
|
20
|
+
* `pnpm test` fails when it drifts.
|
|
21
|
+
*
|
|
22
|
+
* @module dsh-plugin-wsl-env/messages
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* The message templates, keyed by call site. Each entry owns its parameter
|
|
26
|
+
* shape; the `zh` table is type-checked against the `en` table's key and
|
|
27
|
+
* parameter union, so the two catalogs cannot drift apart silently.
|
|
28
|
+
*/
|
|
29
|
+
const en = {
|
|
30
|
+
/** `sessionScopeProblem`: systemd is not PID 1 in the distro. */
|
|
31
|
+
sessionScopeNoSystemd: ({ distro }) => `sessionSandbox needs systemd as PID 1 in "${distro}": set [boot] systemd=true in /etc/wsl.conf, run "wsl --shutdown", and reopen the session.`,
|
|
32
|
+
/** `sessionScopeProblem`: `systemctl --user` does not answer. */
|
|
33
|
+
sessionScopeNoUserManager: ({ distro }) => `sessionSandbox needs a reachable systemd user manager in "${distro}": log in to the distro once, or enable lingering (see the next refusal).`,
|
|
34
|
+
/** `sessionScopeProblem`: the `systemd-run` binary is missing. */
|
|
35
|
+
sessionScopeNoSystemdRun: ({ distro }) => `sessionSandbox needs "systemd-run" in "${distro}"; the distro's systemd package is incomplete or missing.`,
|
|
36
|
+
/** `sessionScopeProblem`: the user manager would stop with the last session. */
|
|
37
|
+
sessionScopeNoLinger: ({ distro }) => `sessionSandbox needs the user manager to outlive a login session: run "loginctl enable-linger $USER" in "${distro}" and retry.`,
|
|
38
|
+
/**
|
|
39
|
+
* `sessionScopeProblem`: the probe's answer is empty or unrecognized. The
|
|
40
|
+
* caller renders `answer` (the quoted word, or `(nothing)`) and `errorSuffix`
|
|
41
|
+
* (`""` or `": <error>"`) so both languages keep one sentence shape.
|
|
42
|
+
*/
|
|
43
|
+
sessionScopeUnknownAnswer: ({ distro, answer, errorSuffix }) => `the sessionSandbox preflight in "${distro}" answered ${answer}${errorSuffix}; see docs/adr/0001-session-scoped-sandbox.md.`,
|
|
44
|
+
/** `missingBwrapRemedy` without a detected package family. */
|
|
45
|
+
bwrapMissingGeneric: ({ distro }) => `bwrap is not usable inside distro "${distro}". Install it with ` +
|
|
46
|
+
`"scripts/bootstrap.sh ${distro} --install" (from the package), or install the ` +
|
|
47
|
+
`"bubblewrap" package with the distro's package manager.`,
|
|
48
|
+
/** `missingBwrapRemedy` with a family's direct install command. */
|
|
49
|
+
bwrapMissingFamily: ({ distro, direct }) => `bwrap is not usable inside distro "${distro}". Install it with ` +
|
|
50
|
+
`"scripts/bootstrap.sh ${distro} --install" (from the package), or directly: ` +
|
|
51
|
+
`wsl.exe -d ${distro} -u root -- ${direct}`,
|
|
52
|
+
/** `composeBwrapFailure`: bwrap ran and refused — present but unusable. */
|
|
53
|
+
bwrapBroken: ({ distro, output }) => `bwrap is installed inside distro "${distro}" but failed the usability probe: ${output}. ` +
|
|
54
|
+
`This is usually the kernel (unprivileged user namespaces disabled) or an unusable bwrap build rather than a missing package, so reinstalling will not help. ` +
|
|
55
|
+
`Check \`wsl.exe -d ${distro} --exec bwrap --version\` inside the distro, or set \`sandbox: false\` on the wsl-shell and wsl-fs rows to run unconfined.`,
|
|
56
|
+
/** `bwrapInstallHint`: bwrap probed healthy but failed a real command. */
|
|
57
|
+
bwrapRuntimeFailure: ({ distro }) => `bwrap failed at run time inside distro "${distro}". Check \`bwrap --version\` there, ` +
|
|
58
|
+
`or reinstall it: "scripts/bootstrap.sh ${distro} --install".`,
|
|
59
|
+
/** `composeBwrapFailure`: the unclassified probe's raw output, appended to a remedy. */
|
|
60
|
+
bwrapProbeFailedSuffix: ({ output }) => ` The probe failed with: ${output}`,
|
|
61
|
+
/** `throwIfDistroUnavailable`: wsl.exe says the distro is gone. */
|
|
62
|
+
distroUnavailable: ({ code, distro }) => `wsl.exe reported ${code} for distro "${distro}": it is not installed, or not running. ` +
|
|
63
|
+
`Start it with \`wsl.exe -d ${distro}\`, check \`wsl.exe -l -v\`, or point \`distro\` at another one. ` +
|
|
64
|
+
`This is not a sandbox denial, so running with wider permissions will not help.`,
|
|
65
|
+
/** `throwIfWorkdirMissing`: `wsl.exe --cd` fell back to `/`. */
|
|
66
|
+
workdirMissing: ({ missing }) => `wsl.exe could not enter the working directory "${missing}" inside the distro, so the command ran from "/" instead. ` +
|
|
67
|
+
`Create it, or point \`cwd\` (or the request's \`workdir\`) at a directory that exists.`,
|
|
68
|
+
/** `throwIfWorkdirInAnotherDistro`: the workspace names a pinned-against distro. */
|
|
69
|
+
workdirAnotherDistro: ({ workdir, distro }) => `"${workdir}" names a workspace in another WSL distro, and this profile pins its commands to "${distro}" — ` +
|
|
70
|
+
`running them here would act on a different machine's tree. Open a session in that distro, ` +
|
|
71
|
+
`or point cwd/workdir at this distro.`,
|
|
72
|
+
/** `wsl_doctor` digest: the verdict line. `verdict` is the report's own `ready`/`blocked`. */
|
|
73
|
+
doctorDigestVerdict: ({ verdict }) => `wsl doctor verdict: ${verdict}`,
|
|
74
|
+
/** `wsl_doctor` digest: the host-wide group heading. */
|
|
75
|
+
doctorDigestHostLabel: () => "(host — Windows and global checks)",
|
|
76
|
+
/** `wsl_doctor` digest: the heading for checks the run's scope never executed. */
|
|
77
|
+
doctorDigestNotRunLabel: () => "(not run in this scope)",
|
|
78
|
+
/** `wsl_doctor` digest: marks which distro group is the session's own. */
|
|
79
|
+
doctorDigestSessionLabel: ({ name }) => `${name} (this session's distro)`,
|
|
80
|
+
/** `wsl_doctor` digest: one summary line for the checks the run's scope never executed; `reason` says why (the run's scope profile). */
|
|
81
|
+
doctorDigestSkipRow: ({ n, reason, ids }) => `[SKIP] not run in this scope — ${reason} (${n}): ${ids}`,
|
|
82
|
+
/** `wsl_doctor` digest: the scope reason for a quick run's skip line. */
|
|
83
|
+
doctorSkipReasonQuick: () => "the quick profile covers first-command prerequisites only",
|
|
84
|
+
/** `wsl_doctor` digest: the scope reason for a section-filtered run's skip line. */
|
|
85
|
+
doctorSkipReasonSections: ({ sections }) => `the run covered only: ${sections}`,
|
|
86
|
+
/** `wsl_doctor` digest: the scope reason when the report recorded none. */
|
|
87
|
+
doctorSkipReasonGeneric: () => "no scope recorded for this report",
|
|
88
|
+
/** `wsl_doctor` digest: one line per check a failed prerequisite gated out; `reason` names the blocker. */
|
|
89
|
+
doctorSkipGated: ({ id, reason }) => `[SKIP] ${id} — skipped: ${reason}`,
|
|
90
|
+
/** `wsl_doctor` digest: per-group tallies, one entry per non-zero status. */
|
|
91
|
+
doctorTallyOk: ({ n }) => `${n} ok`,
|
|
92
|
+
doctorTallyWarn: ({ n }) => `${n} warn`,
|
|
93
|
+
doctorTallyFail: ({ n }) => `${n} fail`,
|
|
94
|
+
doctorTallyUnknown: ({ n }) => `${n} unknown`,
|
|
95
|
+
doctorTallyInfo: ({ n }) => `${n} info`,
|
|
96
|
+
doctorTallySkipped: ({ n }) => `${n} skipped`,
|
|
97
|
+
/** `wsl_doctor` digest: the remedy prefix under a failed check. */
|
|
98
|
+
doctorDigestFixPrefix: ({ remedy }) => ` fix: ${remedy}`,
|
|
99
|
+
/** `wsl_doctor` digest: the ready note (how to attach the full report). */
|
|
100
|
+
doctorDigestNoteReady: () => "the first command should succeed; run the CLI (pnpm run doctor --bundle <path>) for the attachable file",
|
|
101
|
+
/** `wsl_doctor` digest: the blocked note (the rerun is the re-verification). */
|
|
102
|
+
doctorDigestNoteBlocked: () => "apply each remedy above, then call this tool again — the re-run is the re-verification",
|
|
103
|
+
/** `wsl_doctor` digest: the blocked summary tail; `noneBlocking` is the fixed clause. */
|
|
104
|
+
doctorDigestBlockedTail: ({ blockers, warnings, skipped, note }) => `blocked by: ${blockers}; ${warnings} warning(s), ${skipped} skipped leg(s) — none blocking; ${note}`,
|
|
105
|
+
};
|
|
106
|
+
/** The Chinese catalog; the type keeps every key and parameter in step with `en`. */
|
|
107
|
+
const zh = {
|
|
108
|
+
sessionScopeNoSystemd: ({ distro }) => `sessionSandbox 需要在 "${distro}" 中以 systemd 作为 PID 1:在 /etc/wsl.conf 中设置 [boot] systemd=true,运行 "wsl --shutdown",然后重新打开会话。`,
|
|
109
|
+
sessionScopeNoUserManager: ({ distro }) => `sessionSandbox 需要能访问 "${distro}" 中的 systemd 用户管理器:先在发行版中登录一次,或启用 lingering(见下一条拒绝说明)。`,
|
|
110
|
+
sessionScopeNoSystemdRun: ({ distro }) => `sessionSandbox 需要 "${distro}" 中存在 "systemd-run";该发行版的 systemd 软件包不完整或缺失。`,
|
|
111
|
+
sessionScopeNoLinger: ({ distro }) => `sessionSandbox 需要用户管理器在登录会话结束后继续存活:在 "${distro}" 中运行 "loginctl enable-linger $USER",然后重试。`,
|
|
112
|
+
sessionScopeUnknownAnswer: ({ distro, answer, errorSuffix }) => `"${distro}" 中的 sessionSandbox 预检应答为 ${answer}${errorSuffix};参见 docs/adr/0001-session-scoped-sandbox.md。`,
|
|
113
|
+
bwrapMissingGeneric: ({ distro }) => `bwrap 在发行版 "${distro}" 中不可用。请用 "scripts/bootstrap.sh ${distro} --install"(随包提供)安装,` +
|
|
114
|
+
`或用发行版的包管理器安装 "bubblewrap" 软件包。`,
|
|
115
|
+
bwrapMissingFamily: ({ distro, direct }) => `bwrap 在发行版 "${distro}" 中不可用。请用 "scripts/bootstrap.sh ${distro} --install"(随包提供)安装,` +
|
|
116
|
+
`或直接执行:wsl.exe -d ${distro} -u root -- ${direct}`,
|
|
117
|
+
bwrapBroken: ({ distro, output }) => `bwrap 已安装在发行版 "${distro}" 中,但未通过可用性探测:${output}。` +
|
|
118
|
+
`这通常是内核原因(未特权用户命名空间被禁用)或 bwrap 构建不可用,而不是缺少软件包,重新安装不会有帮助。` +
|
|
119
|
+
`请在发行版内检查 \`wsl.exe -d ${distro} --exec bwrap --version\`,或将 wsl-shell 与 wsl-fs 行设为 \`sandbox: false\` 以无隔离运行。`,
|
|
120
|
+
bwrapRuntimeFailure: ({ distro }) => `bwrap 在发行版 "${distro}" 中运行时失败。请在该发行版内检查 \`bwrap --version\`,` +
|
|
121
|
+
`或重新安装:"scripts/bootstrap.sh ${distro} --install"。`,
|
|
122
|
+
bwrapProbeFailedSuffix: ({ output }) => `(探测失败输出:${output})`,
|
|
123
|
+
distroUnavailable: ({ code, distro }) => `wsl.exe 对发行版 "${distro}" 报告了 ${code}:该发行版未安装或未在运行。` +
|
|
124
|
+
`用 \`wsl.exe -d ${distro}\` 启动它,用 \`wsl.exe -l -v\` 检查,或将 \`distro\` 指向另一个发行版。` +
|
|
125
|
+
`这不是沙箱拒绝,放宽权限也不会有帮助。`,
|
|
126
|
+
workdirMissing: ({ missing }) => `wsl.exe 无法进入发行版中的工作目录 "${missing}",命令改从 "/" 运行。` +
|
|
127
|
+
`请创建该目录,或将 \`cwd\`(或请求的 \`workdir\`)指向一个已存在的目录。`,
|
|
128
|
+
workdirAnotherDistro: ({ workdir, distro }) => `"${workdir}" 指向另一个 WSL 发行版中的工作区,而本 profile 将命令固定在 "${distro}" —— ` +
|
|
129
|
+
`在这里运行会作用于另一台机器的目录树。请在该发行版中打开会话,或将 cwd/workdir 指向本发行版。`,
|
|
130
|
+
doctorDigestVerdict: ({ verdict }) => `wsl doctor 裁决:${verdict}`,
|
|
131
|
+
doctorDigestHostLabel: () => "(宿主——Windows 与全局检查)",
|
|
132
|
+
doctorDigestNotRunLabel: () => "(不在本次范围)",
|
|
133
|
+
doctorDigestSessionLabel: ({ name }) => `${name}(当前会话的 distro)`,
|
|
134
|
+
doctorDigestSkipRow: ({ n, reason, ids }) => `[SKIP] 不在本次范围——${reason}(${n}):${ids}`,
|
|
135
|
+
doctorSkipReasonQuick: () => "quick 档只探首条命令的前置项",
|
|
136
|
+
doctorSkipReasonSections: ({ sections }) => `本次只运行了这些分区:${sections}`,
|
|
137
|
+
doctorSkipReasonGeneric: () => "报告未记录运行范围",
|
|
138
|
+
doctorSkipGated: ({ id, reason }) => `[SKIP] ${id}——被前置阻断:${reason}`,
|
|
139
|
+
doctorTallyOk: ({ n }) => `通过 ${n}`,
|
|
140
|
+
doctorTallyWarn: ({ n }) => `警告 ${n}`,
|
|
141
|
+
doctorTallyFail: ({ n }) => `失败 ${n}`,
|
|
142
|
+
doctorTallyUnknown: ({ n }) => `未知 ${n}`,
|
|
143
|
+
doctorTallyInfo: ({ n }) => `信息 ${n}`,
|
|
144
|
+
doctorTallySkipped: ({ n }) => `跳过 ${n}`,
|
|
145
|
+
doctorDigestFixPrefix: ({ remedy }) => ` 修复: ${remedy}`,
|
|
146
|
+
doctorDigestNoteReady: () => "首条命令应能成功;如需可附加的报告文件,运行 CLI(pnpm run doctor --bundle <path>)",
|
|
147
|
+
doctorDigestNoteBlocked: () => "应用上方每条修复,然后再次调用本工具——重跑即复核",
|
|
148
|
+
doctorDigestBlockedTail: ({ blockers, warnings, skipped, note }) => `阻断项:${blockers};${warnings} 个警告,${skipped} 个跳过腿——均不阻断;${note}`,
|
|
149
|
+
};
|
|
150
|
+
/** The active language; English until a settings service reports otherwise. */
|
|
151
|
+
let current = "en";
|
|
152
|
+
/**
|
|
153
|
+
* The locale the message builders render in.
|
|
154
|
+
*
|
|
155
|
+
* @returns the active catalog language.
|
|
156
|
+
*/
|
|
157
|
+
export function messagesLocale() {
|
|
158
|
+
return current;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Force the message language. The wiring calls this from the resolved
|
|
162
|
+
* `locale.preference`; tests call it directly and reset afterwards.
|
|
163
|
+
*
|
|
164
|
+
* @param locale - the language to render in.
|
|
165
|
+
*/
|
|
166
|
+
export function configureMessagesLocale(locale) {
|
|
167
|
+
current = locale;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Render one message in the active language, falling back to the English
|
|
171
|
+
* template when the active catalog somehow lacks the key (the catalogs are
|
|
172
|
+
* type-checked against each other, so this guards runtime drift only).
|
|
173
|
+
*
|
|
174
|
+
* The `params` type correlates the parameters with the key: the conditional
|
|
175
|
+
* resolves per call site, so `t("sessionScopeNoLinger", { distro })`
|
|
176
|
+
* typechecks while `t("sessionScopeNoLinger", { missing })` does not. It
|
|
177
|
+
* lives in the JSDoc because a comment between the parameters would have the
|
|
178
|
+
* type-stripping build emit a line with trailing whitespace, which the style
|
|
179
|
+
* gate refuses.
|
|
180
|
+
*
|
|
181
|
+
* @typeParam K - the message key.
|
|
182
|
+
* @param key - the message to render.
|
|
183
|
+
* @param params - the key's parameters, as the template declares them.
|
|
184
|
+
* @returns the rendered message.
|
|
185
|
+
*/
|
|
186
|
+
export function t(key, params) {
|
|
187
|
+
// Key and parameter parity between the catalogs is the type system's job
|
|
188
|
+
// (`zh` is `typeof en`), so the lookup needs no runtime fallback.
|
|
189
|
+
const template = current === "zh" ? zh[key] : en[key];
|
|
190
|
+
return template(params);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Map one `locale.preference` value onto a catalog language. The app's
|
|
194
|
+
* language ids are BCP 47-style tags (`zh`, `en`, `ja`, …); the plugin ships
|
|
195
|
+
* zh and en, and every other id renders English.
|
|
196
|
+
*
|
|
197
|
+
* @param preference - the stored preference, or anything else when unset.
|
|
198
|
+
* @returns the catalog language the preference selects.
|
|
199
|
+
*/
|
|
200
|
+
export function resolveMessagesLocale(preference) {
|
|
201
|
+
return typeof preference === "string" && /^zh/iu.test(preference) ? "zh" : "en";
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Follow the harness locale for the caller's composition. Every row wires its
|
|
205
|
+
* own injection (the shell executor, the fs provider and the preflight all
|
|
206
|
+
* call this), so a hot-reloaded row re-wires too; the redundant reads converge
|
|
207
|
+
* on the same app-wide preference and the events are rare.
|
|
208
|
+
*
|
|
209
|
+
* The `settings` service is optional — a profile without it (some CLI
|
|
210
|
+
* compositions) keeps English. When it is present, the preference is read once
|
|
211
|
+
* the service resolves and again on every `settings/document-updated` event,
|
|
212
|
+
* which also covers the `locale` entry activating after this row did. A read
|
|
213
|
+
* that throws keeps the previous language: this is presentation, not gating.
|
|
214
|
+
*
|
|
215
|
+
* A browser whose user never picked a language in Settings has NO persisted
|
|
216
|
+
* `locale.preference` — its Chinese UI came from the navigator's provisional
|
|
217
|
+
* match, which the Host settings never record. For that case the fallback
|
|
218
|
+
* reads the process's ICU default locale (Electron: the OS UI language), so
|
|
219
|
+
* a zh-CN Windows with a provisional-Chinese UI still renders Chinese. An
|
|
220
|
+
* explicit Settings choice always wins over the fallback.
|
|
221
|
+
*
|
|
222
|
+
* @param ctx - the row's composition context.
|
|
223
|
+
*/
|
|
224
|
+
export function installMessagesLocale(ctx) {
|
|
225
|
+
// Provisional fallback first: the settings read below is asynchronous (it
|
|
226
|
+
// waits for the injection), and the OS language is the best guess until a
|
|
227
|
+
// stored preference replaces it.
|
|
228
|
+
configureMessagesLocale(hostFallbackLocale());
|
|
229
|
+
if (typeof ctx.inject !== "function")
|
|
230
|
+
return;
|
|
231
|
+
ctx.inject(["settings"], (scope) => {
|
|
232
|
+
// Narrow once to the shape this module reads; see `SettingsScope`.
|
|
233
|
+
const view = scope;
|
|
234
|
+
const settings = view.settings;
|
|
235
|
+
if (settings?.describe === undefined)
|
|
236
|
+
return;
|
|
237
|
+
const read = () => {
|
|
238
|
+
try {
|
|
239
|
+
const row = settings.describe().find((entry) => entry.ns === "locale");
|
|
240
|
+
if (row === undefined) {
|
|
241
|
+
// No stored preference (the provisional-UI case): the OS fallback
|
|
242
|
+
// stands. It was already applied above; keep it.
|
|
243
|
+
configureMessagesLocale(hostFallbackLocale());
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
// The descriptor's value is the entry's projected volatile form —
|
|
247
|
+
// `{ preference?: string }` for the locale entry.
|
|
248
|
+
const preference = row.value?.preference;
|
|
249
|
+
configureMessagesLocale(resolveMessagesLocale(preference));
|
|
250
|
+
}
|
|
251
|
+
catch {
|
|
252
|
+
// A describe failure must never fail a row's load; keep the last language.
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
read();
|
|
256
|
+
// The event name lives in the host's own `Events` augmentation, which this
|
|
257
|
+
// plugin's typings do not carry; widen the registration to a plain string.
|
|
258
|
+
view.on("settings/document-updated", () => read());
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Restore English. Tests only: production wiring is process-wide by design.
|
|
263
|
+
*/
|
|
264
|
+
export function resetMessagesLocaleForTests() {
|
|
265
|
+
current = "en";
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* The no-settings fallback: the process's ICU default locale, which in the
|
|
269
|
+
* desktop app follows the OS UI language (a zh-CN Windows yields `zh-CN`).
|
|
270
|
+
* Under Node's small-icu builds this is `en-US`, which maps to English — the
|
|
271
|
+
* previous default. Exported for tests.
|
|
272
|
+
*
|
|
273
|
+
* @returns {"en" | "zh"} the language the OS-level locale selects.
|
|
274
|
+
*/
|
|
275
|
+
export function hostFallbackLocale() {
|
|
276
|
+
try {
|
|
277
|
+
return localeFromTag(Intl.DateTimeFormat().resolvedOptions().locale);
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
return "en";
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Map one BCP 47-style tag onto a catalog language: `zh*` renders Chinese,
|
|
285
|
+
* everything else English.
|
|
286
|
+
*
|
|
287
|
+
* @param tag - the locale tag (may be empty).
|
|
288
|
+
* @returns {"en" | "zh"} the catalog language the tag selects.
|
|
289
|
+
*/
|
|
290
|
+
function localeFromTag(tag) {
|
|
291
|
+
return /^zh/iu.test(tag) ? "zh" : "en";
|
|
292
|
+
}
|
package/lib/preflight.d.ts
CHANGED
|
@@ -11,6 +11,12 @@
|
|
|
11
11
|
* command after it pays nothing. Nothing else changes: the failure semantics
|
|
12
12
|
* stay exactly as fail-closed as before, this service only MOVES THE NEWS.
|
|
13
13
|
*
|
|
14
|
+
* The same probes also run once at plugin load (`startup`, on by default) so an
|
|
15
|
+
* install-plus-restart already carries the verdict in the log — the pinned or
|
|
16
|
+
* WSL-default distro — before the first session opens. A session on that distro
|
|
17
|
+
* repeats only the runtime-context entry; other distros keep the session-open
|
|
18
|
+
* check unchanged.
|
|
19
|
+
*
|
|
14
20
|
* Advisory by construction. A preflight that cannot run (no WSL, a wedged
|
|
15
21
|
* `wsl.exe`) degrades to a log line; it must never fail a session that has not
|
|
16
22
|
* even asked for confinement yet. It also never installs anything: the remedy
|
|
@@ -44,6 +50,14 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
|
44
50
|
* that profile does not use.
|
|
45
51
|
*/
|
|
46
52
|
sessionSandbox: z<boolean, boolean, "defined">;
|
|
53
|
+
/**
|
|
54
|
+
* Whether the same checks also run once at plugin load — install + restart —
|
|
55
|
+
* against the pinned or WSL-default distro, so the verdict is in the log
|
|
56
|
+
* before any session opens. Sessions on other distros are still checked at
|
|
57
|
+
* open, and a session announcement for a message the load pass already
|
|
58
|
+
* logged skips the duplicate log line but keeps its runtime-context entry.
|
|
59
|
+
*/
|
|
60
|
+
startup: z<boolean, boolean, "defined">;
|
|
47
61
|
}>>, Schemastery.ObjectT<NoInfer<{
|
|
48
62
|
/**
|
|
49
63
|
* Distro to preflight. Empty/`"auto"` follows the session workspace; an
|
|
@@ -62,6 +76,14 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
|
62
76
|
* that profile does not use.
|
|
63
77
|
*/
|
|
64
78
|
sessionSandbox: z<boolean, boolean, "defined">;
|
|
79
|
+
/**
|
|
80
|
+
* Whether the same checks also run once at plugin load — install + restart —
|
|
81
|
+
* against the pinned or WSL-default distro, so the verdict is in the log
|
|
82
|
+
* before any session opens. Sessions on other distros are still checked at
|
|
83
|
+
* open, and a session announcement for a message the load pass already
|
|
84
|
+
* logged skips the duplicate log line but keeps its runtime-context entry.
|
|
85
|
+
*/
|
|
86
|
+
startup: z<boolean, boolean, "defined">;
|
|
65
87
|
}>>, "plain">;
|
|
66
88
|
/** The config schema's validated output. */
|
|
67
89
|
export interface PreflightConfig {
|
|
@@ -73,6 +95,8 @@ export interface PreflightConfig {
|
|
|
73
95
|
sandbox?: boolean;
|
|
74
96
|
/** Whether the session-runtime prerequisites are preflighted too. */
|
|
75
97
|
sessionSandbox?: boolean;
|
|
98
|
+
/** Whether the checks also run once at plugin load, before any session. */
|
|
99
|
+
startup?: boolean;
|
|
76
100
|
}
|
|
77
101
|
/**
|
|
78
102
|
* The slice of a created agent this service inspects; the harness's agent
|