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.
Files changed (48) hide show
  1. package/CHANGELOG.md +188 -1
  2. package/README.md +2 -2
  3. package/client.d.ts +5 -0
  4. package/client.js +218 -0
  5. package/cordis.patch.yml +75 -1
  6. package/docs/API.md +1 -0
  7. package/docs/CONFIGURATION.md +48 -5
  8. package/docs/CONFIGURATION.zh.md +15 -1
  9. package/docs/DIAGNOSTICS.md +110 -0
  10. package/docs/DIAGNOSTICS.zh.md +96 -0
  11. package/docs/LIMITATIONS.md +25 -0
  12. package/docs/LIMITATIONS.zh.md +7 -0
  13. package/docs/MIGRATION.md +1 -1
  14. package/docs/QUICKSTART.md +19 -3
  15. package/docs/RELEASING.md +3 -0
  16. package/docs/ROADMAP-1.0.md +49 -4
  17. package/docs/UPSTREAM-FILE-REFERENCE-SEAM.md +5 -0
  18. package/docs/UPSTREAM-OPEN-IN-APP.md +33 -0
  19. package/lib/client-host.d.ts +29 -0
  20. package/lib/client-host.js +29 -0
  21. package/lib/cwd-prompt-tool.d.ts +88 -0
  22. package/lib/cwd-prompt-tool.js +94 -0
  23. package/lib/cwd-prompt.d.ts +166 -0
  24. package/lib/cwd-prompt.js +203 -0
  25. package/lib/doctor-live.d.ts +5 -1
  26. package/lib/doctor-live.js +3 -2
  27. package/lib/index.d.ts +11 -0
  28. package/lib/index.js +10 -8
  29. package/lib/messages.d.ts +238 -0
  30. package/lib/messages.js +292 -0
  31. package/lib/preflight.d.ts +24 -0
  32. package/lib/preflight.js +111 -11
  33. package/lib/sandbox-core.js +7 -14
  34. package/lib/session-scope.js +10 -5
  35. package/lib/shell-env.d.ts +25 -0
  36. package/lib/shell-env.js +56 -0
  37. package/lib/shell.d.ts +3 -1
  38. package/lib/shell.js +3 -1
  39. package/lib/update-check.d.ts +197 -0
  40. package/lib/update-check.js +211 -0
  41. package/lib/wsl-doctor-command.d.ts +105 -0
  42. package/lib/wsl-doctor-command.js +240 -0
  43. package/lib/wsl-doctor-tool.d.ts +214 -0
  44. package/lib/wsl-doctor-tool.js +423 -0
  45. package/locale/doctor/en.json +30 -0
  46. package/locale/doctor/zh.json +30 -0
  47. package/package.json +47 -5
  48. package/scripts/doctor.mjs +1606 -171
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Distro-native `working_directory` tool output: serve the model's own
3
+ * read/cd tool with the SAME read/`cd` semantics the harness ships, but with
4
+ * the returned `cwd` rewritten to the distro's POSIX form on a WSL session.
5
+ *
6
+ * The runtime-context rewrite (`lib/cwd-prompt.js`) covers the system-prompt
7
+ * entry and the per-turn snapshot. The `working_directory` tool is the THIRD
8
+ * surface the cwd reaches the model through: `dsh-tool-working-directory`
9
+ * prints `fs.processPath()` verbatim, which on this deployment is the UNC
10
+ * spelling — the one coordinate the distro shell cannot resolve. A model that
11
+ * quotes that path into `bash` fails exactly the failure mode the
12
+ * runtime-context rewrite exists to remove, so the surfaces must agree.
13
+ *
14
+ * This row DISABLES the shipped tool row and mounts a replacement with the
15
+ * same tool name, the same parameters, the same `cd` semantics (the harness's
16
+ * `workingDirectory` service still owns directory validation, resolution, and
17
+ * the durable change), and one difference: the returned `cwd` string has every
18
+ * WSL UNC spelling rewritten to its POSIX form. A non-WSL path passes through
19
+ * byte for byte, so host sessions see the shipped behavior.
20
+ *
21
+ * Advisory by construction. The service reads the harness's
22
+ * `workingDirectory` structurally; a harness without it fails this row's
23
+ * activation loudly (a missing service is a composition error, not a runtime
24
+ * degradation), while every per-call failure is the shipped tool's own — this
25
+ * wrapper adds no I/O and no new failure modes.
26
+ *
27
+ * This is a TypeScript source built to `lib/cwd-prompt-tool.js`; edit THIS
28
+ * file and run `pnpm run build` — the artifact under `lib/` is generated, and
29
+ * `pnpm test` fails when it drifts.
30
+ *
31
+ * @module dsh-plugin-wsl-env/cwd-prompt-tool
32
+ */
33
+ import { defineTool } from "@deepseek-ai/dsh-tools";
34
+ import { uncToPosix } from "./paths.js";
35
+ export const name = "wsl-cwd-prompt-tool";
36
+ /**
37
+ * The context properties `apply` reads. Cordis 4 refuses an undeclared read —
38
+ * `cannot get property "tools" without inject` — so both the tool registry and
39
+ * the harness's `workingDirectory` service must be named here. Both are
40
+ * required: a host without one fails this row's activation loudly, which is
41
+ * the design (a missing service is a composition error, not a degradation).
42
+ */
43
+ export const inject = ["tools", "workingDirectory"];
44
+ /**
45
+ * A raw absolute path as the model should see it: the POSIX path a WSL UNC
46
+ * names, and every other path unchanged. This is the single-path sibling of
47
+ * `cwd-prompt.js`'s `rewriteQuotedUnc`, which handles the JSON-quoted texts.
48
+ *
49
+ * @param path - the absolute path the harness produced.
50
+ * @returns the distro-native path, or the input unchanged.
51
+ */
52
+ export function rewriteUncPath(path) {
53
+ const parsed = uncToPosix(path);
54
+ return parsed === undefined ? path : parsed.linuxPath;
55
+ }
56
+ /**
57
+ * Mount the replacement tool.
58
+ *
59
+ * @param ctx - the cordis context (the composition root, where the shipped
60
+ * tool row is disabled by the patch layer).
61
+ */
62
+ export async function apply(ctx) {
63
+ ctx.tools.register(defineTool({
64
+ name: "working_directory",
65
+ description: "Read the current working directory, or change it with cd. Relative paths use the current directory. Existing shells and running processes keep their own directories.",
66
+ parameters: { cd: {
67
+ type: "string",
68
+ description: "Existing directory to enter. Omit to read the current directory.",
69
+ } },
70
+ output: {
71
+ schema: {
72
+ type: "object",
73
+ additionalProperties: false,
74
+ properties: { cwd: {
75
+ type: "string",
76
+ required: true,
77
+ description: "Current absolute working directory.",
78
+ } },
79
+ },
80
+ render: (_args, value) => [{
81
+ type: "text",
82
+ text: value.cwd,
83
+ }],
84
+ },
85
+ async execute(args, exec) {
86
+ if (exec.agent === undefined)
87
+ throw new Error("working_directory requires an agent Session");
88
+ const cwd = args.cd === undefined
89
+ ? await ctx.workingDirectory.ensure(exec.agent, exec.signal)
90
+ : await ctx.workingDirectory.set(exec.agent, args.cd, exec.signal);
91
+ return { cwd: rewriteUncPath(cwd) };
92
+ },
93
+ }));
94
+ }
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Distro-native working directory in the model's runtime context: rewrite the
3
+ * `working-directory:current` entry so a distro session reads its directory as
4
+ * the POSIX path its own commands use, not the host UNC spelling.
5
+ *
6
+ * The harness's `working-directory` service prints the session cwd verbatim,
7
+ * which on this deployment is `\\wsl.localhost\<distro>\...` — the coordinate
8
+ * system of the HOST filesystem, and one the model's tools mostly cannot use
9
+ * directly: the shell executor runs inside the distro, where only the POSIX
10
+ * form resolves. The mismatch is invisible to the harness and costs the model
11
+ * a translation step on every path it quotes back, with a wrong-guess failure
12
+ * mode (a UNC path handed to `bash` names nothing).
13
+ *
14
+ * The value reaches the model through TWO renderings, and both must be
15
+ * covered:
16
+ *
17
+ * 1. the system prompt — the entry as `assemble()` resolves it;
18
+ * 2. the per-turn runtime-context snapshot — `refreshContext()` re-resolves
19
+ * the registry providers DIRECTLY, so a waterfall listener on
20
+ * `system-prompt/assemble` never sees it.
21
+ *
22
+ * Both read the same scoped-layer table, where the nearest scope wins a name
23
+ * (`ScopedLayers.merge`). So the primary mechanism is a session-scoped
24
+ * registration UNDER THE SAME NAME: the entry's provider asks the harness's
25
+ * `workingDirectory` service for the CURRENT directory (so a mid-session `cd`
26
+ * still shows) and rewrites every WSL UNC spelling in it to its POSIX form.
27
+ * A root-level waterfall listener stays as defense in depth for the prompt
28
+ * path on a session where the inject seam is unavailable; the rewrite is
29
+ * idempotent, so the two mechanisms compose without interaction.
30
+ *
31
+ * Advisory by construction. The seams are structural (the plugin's own types
32
+ * spell the slices; docs/UPSTREAM-SESSION-NOTICE.md already relies on the
33
+ * sibling `systemPrompt.context()` seam): a harness without them, an agent
34
+ * whose context is not exposed, or a non-WSL workspace degrades to the
35
+ * shipped behavior — no rewrite, no failure. The rewrite touches one display
36
+ * string; it must never fail a model step.
37
+ *
38
+ * This is a TypeScript source built to `lib/cwd-prompt.js`; edit THIS file and
39
+ * run `pnpm run build` — the artifact under `lib/` is generated, and
40
+ * `pnpm test` fails when it drifts.
41
+ *
42
+ * @module dsh-plugin-wsl-env/cwd-prompt
43
+ */
44
+ import z from "@deepseek-ai/schemastery";
45
+ export declare const name = "wsl-cwd-prompt";
46
+ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
47
+ /** Whether the runtime-context rewrite runs at all. */
48
+ enabled: z<boolean, boolean, "defined">;
49
+ }>>, Schemastery.ObjectT<NoInfer<{
50
+ /** Whether the runtime-context rewrite runs at all. */
51
+ enabled: z<boolean, boolean, "defined">;
52
+ }>>, "plain">;
53
+ /** The config schema's validated output. */
54
+ export interface CwdPromptConfig {
55
+ /** Whether the runtime-context rewrite runs at all. */
56
+ enabled?: boolean;
57
+ }
58
+ /** One named contribution to the assembled system prompt. */
59
+ export interface PromptContextEntry {
60
+ /** The registry name; the harness's entry is `working-directory:current`. */
61
+ name?: string;
62
+ /** The literal contribution text, already resolved by its provider. */
63
+ text?: string;
64
+ /** Present and false on entries that skip prompt-variable interpolation. */
65
+ interpolate?: boolean;
66
+ }
67
+ /** The slice of the assembly the waterfall hands around. */
68
+ export interface PromptAssembly {
69
+ /** The named contributions, ordered by registry order. */
70
+ contexts?: PromptContextEntry[];
71
+ }
72
+ /** The waterfall's continuation; resolves to the (possibly rewritten) assembly. */
73
+ export type AssembleNext = () => Promise<PromptAssembly>;
74
+ /** The waterfall listener's signature, as the harness's own services use it. */
75
+ export type AssembleListener = (assembly: PromptAssembly, context: unknown, next: AssembleNext) => Promise<PromptAssembly>;
76
+ /** The `systemPrompt` slice an injected agent scope exposes. */
77
+ export interface CwdPromptScope {
78
+ systemPrompt: {
79
+ /** Register one context entry in this scope's layer. */
80
+ context: (entry: {
81
+ name: string;
82
+ order: number;
83
+ required: boolean;
84
+ interpolate: boolean;
85
+ text: (context: AssembleRequestContext) => string;
86
+ }) => unknown;
87
+ /** The order constant the harness assigned to a named context family. */
88
+ getContextOrder?: (family: string) => number | undefined;
89
+ };
90
+ }
91
+ /** The assembly request context: what a provider's `text` receives. */
92
+ export interface AssembleRequestContext {
93
+ /** The live agent, when the assembly runs inside one. */
94
+ agent?: {
95
+ session?: {
96
+ header?: {
97
+ cwd?: string | undefined;
98
+ };
99
+ } | undefined;
100
+ } | undefined;
101
+ }
102
+ /** The slice of a created agent this service inspects and injects into. */
103
+ export interface CwdPromptAgent {
104
+ /** The session stub, when mounted. */
105
+ session?: {
106
+ header?: {
107
+ cwd?: string | undefined;
108
+ };
109
+ } | undefined;
110
+ /** The agent's own context, when the harness exposes it. */
111
+ ctx?: {
112
+ inject?: (names: string[], install: (scope: CwdPromptScope) => void) => unknown;
113
+ get?: (name: string) => unknown;
114
+ } | undefined;
115
+ }
116
+ /**
117
+ * The harness's `working-directory` service, read structurally: only `get`
118
+ * is consumed, and its absence degrades to the session header's cwd.
119
+ */
120
+ export interface WorkingDirectorySlice {
121
+ get?: (session: unknown) => string | undefined;
122
+ }
123
+ /** The cordis context slice this service consumes. */
124
+ export type CwdPromptContext = {
125
+ logger?: {
126
+ debug?: (message: string) => void;
127
+ };
128
+ agents?: {
129
+ list: () => CwdPromptAgent[];
130
+ };
131
+ on: ((event: "agent/created", listener: (payload: unknown) => unknown) => () => boolean) & ((event: "system-prompt/assemble", listener: AssembleListener) => () => boolean);
132
+ get?: (name: string) => unknown;
133
+ };
134
+ /**
135
+ * Rewrite every JSON-string-quoted WSL UNC path in one text to its POSIX form.
136
+ * The harness writes the cwd through `JSON.stringify`, so the backslashes are
137
+ * ESCAPED inside the quotes (`"\\\\wsl.localhost\\..."` as rendered text):
138
+ * match a JSON string, parse its inner content, and only rewrite when the raw
139
+ * value is a WSL UNC share. A path that parses to anything else (a drive
140
+ * path, another share, already-POSIX text) passes through unchanged, so the
141
+ * rewrite is safe to re-run.
142
+ *
143
+ * @param text - the contribution text.
144
+ * @returns the text with WSL UNC paths in distro coordinates.
145
+ */
146
+ export declare function rewriteQuotedUnc(text: string): string;
147
+ /**
148
+ * The rewritten entry text for one assembly: ask the harness's service for the
149
+ * CURRENT directory (a mid-session `cd` must show), fall back to the session
150
+ * header's original cwd, and translate only WSL UNC spellings. Everything the
151
+ * regex cannot see passes through untouched, so a host session receives the
152
+ * shipped text byte for byte.
153
+ *
154
+ * @param agent - the agent the assembly runs inside.
155
+ * @param workingDirectory - the harness's service, when resolvable.
156
+ * @returns the entry text.
157
+ */
158
+ export declare function entryText(agent: AssembleRequestContext["agent"], workingDirectory: WorkingDirectorySlice | undefined): string;
159
+ /**
160
+ * Mount the rewrite.
161
+ *
162
+ * @param ctx - the cordis context (the composition root, where the harness's
163
+ * own prompt services register).
164
+ * @param config - the schema-validated plugin config.
165
+ */
166
+ export declare function apply(ctx: CwdPromptContext, config?: CwdPromptConfig): void;
@@ -0,0 +1,203 @@
1
+ /**
2
+ * Distro-native working directory in the model's runtime context: rewrite the
3
+ * `working-directory:current` entry so a distro session reads its directory as
4
+ * the POSIX path its own commands use, not the host UNC spelling.
5
+ *
6
+ * The harness's `working-directory` service prints the session cwd verbatim,
7
+ * which on this deployment is `\\wsl.localhost\<distro>\...` — the coordinate
8
+ * system of the HOST filesystem, and one the model's tools mostly cannot use
9
+ * directly: the shell executor runs inside the distro, where only the POSIX
10
+ * form resolves. The mismatch is invisible to the harness and costs the model
11
+ * a translation step on every path it quotes back, with a wrong-guess failure
12
+ * mode (a UNC path handed to `bash` names nothing).
13
+ *
14
+ * The value reaches the model through TWO renderings, and both must be
15
+ * covered:
16
+ *
17
+ * 1. the system prompt — the entry as `assemble()` resolves it;
18
+ * 2. the per-turn runtime-context snapshot — `refreshContext()` re-resolves
19
+ * the registry providers DIRECTLY, so a waterfall listener on
20
+ * `system-prompt/assemble` never sees it.
21
+ *
22
+ * Both read the same scoped-layer table, where the nearest scope wins a name
23
+ * (`ScopedLayers.merge`). So the primary mechanism is a session-scoped
24
+ * registration UNDER THE SAME NAME: the entry's provider asks the harness's
25
+ * `workingDirectory` service for the CURRENT directory (so a mid-session `cd`
26
+ * still shows) and rewrites every WSL UNC spelling in it to its POSIX form.
27
+ * A root-level waterfall listener stays as defense in depth for the prompt
28
+ * path on a session where the inject seam is unavailable; the rewrite is
29
+ * idempotent, so the two mechanisms compose without interaction.
30
+ *
31
+ * Advisory by construction. The seams are structural (the plugin's own types
32
+ * spell the slices; docs/UPSTREAM-SESSION-NOTICE.md already relies on the
33
+ * sibling `systemPrompt.context()` seam): a harness without them, an agent
34
+ * whose context is not exposed, or a non-WSL workspace degrades to the
35
+ * shipped behavior — no rewrite, no failure. The rewrite touches one display
36
+ * string; it must never fail a model step.
37
+ *
38
+ * This is a TypeScript source built to `lib/cwd-prompt.js`; edit THIS file and
39
+ * run `pnpm run build` — the artifact under `lib/` is generated, and
40
+ * `pnpm test` fails when it drifts.
41
+ *
42
+ * @module dsh-plugin-wsl-env/cwd-prompt
43
+ */
44
+ import z from "@deepseek-ai/schemastery";
45
+ import { isWslUnc, uncToPosix } from "./paths.js";
46
+ export const name = "wsl-cwd-prompt";
47
+ export const Config = z.object({
48
+ /** Whether the runtime-context rewrite runs at all. */
49
+ enabled: z.boolean().default(true),
50
+ });
51
+ /**
52
+ * The context entry name the harness's working-directory service registers.
53
+ * Registering the same name in a session scope shadows it for BOTH renderings
54
+ * (`assemble` and `refreshContext` merge scoped layers over the global one).
55
+ */
56
+ const ENTRY_NAME = "working-directory:current";
57
+ /**
58
+ * Rewrite every JSON-string-quoted WSL UNC path in one text to its POSIX form.
59
+ * The harness writes the cwd through `JSON.stringify`, so the backslashes are
60
+ * ESCAPED inside the quotes (`"\\\\wsl.localhost\\..."` as rendered text):
61
+ * match a JSON string, parse its inner content, and only rewrite when the raw
62
+ * value is a WSL UNC share. A path that parses to anything else (a drive
63
+ * path, another share, already-POSIX text) passes through unchanged, so the
64
+ * rewrite is safe to re-run.
65
+ *
66
+ * @param text - the contribution text.
67
+ * @returns the text with WSL UNC paths in distro coordinates.
68
+ */
69
+ export function rewriteQuotedUnc(text) {
70
+ return String(text).replace(/"((?:[^"\\]|\\.)*)"/gu, (whole, inner) => {
71
+ let raw;
72
+ try {
73
+ // The inner content is a complete JSON string body by construction of
74
+ // the match; a body with an invalid escape fails closed to `whole`.
75
+ raw = JSON.parse(`"${inner}"`);
76
+ }
77
+ catch {
78
+ return whole;
79
+ }
80
+ const parsed = uncToPosix(raw);
81
+ return parsed === undefined ? whole : JSON.stringify(parsed.linuxPath);
82
+ });
83
+ }
84
+ /**
85
+ * The rewritten entry text for one assembly: ask the harness's service for the
86
+ * CURRENT directory (a mid-session `cd` must show), fall back to the session
87
+ * header's original cwd, and translate only WSL UNC spellings. Everything the
88
+ * regex cannot see passes through untouched, so a host session receives the
89
+ * shipped text byte for byte.
90
+ *
91
+ * @param agent - the agent the assembly runs inside.
92
+ * @param workingDirectory - the harness's service, when resolvable.
93
+ * @returns the entry text.
94
+ */
95
+ export function entryText(agent, workingDirectory) {
96
+ const session = agent?.session;
97
+ let directory;
98
+ try {
99
+ directory = session === undefined ? undefined : workingDirectory?.get?.(session);
100
+ }
101
+ catch {
102
+ directory = undefined;
103
+ }
104
+ if (directory === undefined || directory.length === 0)
105
+ directory = session?.header?.cwd ?? "";
106
+ return rewriteQuotedUnc(`Current working directory: ${JSON.stringify(directory)}.`);
107
+ }
108
+ /**
109
+ * Mount the rewrite.
110
+ *
111
+ * @param ctx - the cordis context (the composition root, where the harness's
112
+ * own prompt services register).
113
+ * @param config - the schema-validated plugin config.
114
+ */
115
+ export function apply(ctx, config = {}) {
116
+ const enabled = config.enabled ?? true;
117
+ if (!enabled)
118
+ return;
119
+ const debug = (message) => ctx.logger?.debug?.(message);
120
+ /**
121
+ * Install the session-scoped shadow entry: same name, so it wins the merge;
122
+ * the provider re-reads the current directory on every rendering. Absent on
123
+ * host workspaces (nothing WSL to rewrite) and on agents whose context the
124
+ * harness does not expose (the shipped entry stands).
125
+ *
126
+ * @param agent - the session that just opened.
127
+ */
128
+ const install = (agent) => {
129
+ const cwd = agent.session?.header?.cwd;
130
+ if (cwd === undefined || !isWslUnc(cwd))
131
+ return;
132
+ const agentCtx = agent.ctx;
133
+ if (agentCtx === undefined || typeof agentCtx.inject !== "function")
134
+ return;
135
+ let workingDirectory;
136
+ try {
137
+ const resolved = agentCtx.get?.("workingDirectory");
138
+ if (resolved !== undefined && resolved !== null)
139
+ workingDirectory = /** @type {WorkingDirectorySlice} */ (resolved);
140
+ }
141
+ catch (error) {
142
+ debug(`wsl-cwd-prompt: could not read the workingDirectory service (${error?.message ?? error})`);
143
+ }
144
+ try {
145
+ agentCtx.inject(["systemPrompt"], (scope) => {
146
+ const order = scope.systemPrompt.getContextOrder?.("WORKING_DIRECTORY") ?? 200;
147
+ scope.systemPrompt.context({
148
+ name: ENTRY_NAME,
149
+ order,
150
+ required: true,
151
+ interpolate: false,
152
+ text: (context) => entryText(context?.agent, workingDirectory),
153
+ });
154
+ });
155
+ }
156
+ catch (error) {
157
+ debug(`wsl-cwd-prompt: could not install the shadow entry (${error?.message ?? error})`);
158
+ }
159
+ };
160
+ ctx.on("agent/created", (payload) => {
161
+ // Structural payload: the harness emits { agent } on agent/created.
162
+ const agent = payload?.agent;
163
+ if (agent !== undefined)
164
+ install(agent);
165
+ });
166
+ // Mount order is not a guarantee: a session created during startup can finish
167
+ // before this service mounts and miss the event entirely (dsh-headless does
168
+ // exactly that, and wsl-preflight sweeps for the same reason). `agents` is
169
+ // optional, so read it with `ctx.get`: a property read of an undeclared
170
+ // service throws in cordis 4, and the catch below turns that into a silent
171
+ // no-op — exactly the sweep this block exists to perform.
172
+ try {
173
+ const agents = ctx.get?.("agents");
174
+ for (const agent of agents?.list() ?? [])
175
+ install(agent);
176
+ }
177
+ catch (error) {
178
+ debug(`wsl-cwd-prompt: could not sweep already-live agents: ${error?.message ?? error}`);
179
+ }
180
+ /**
181
+ * Defense in depth for the PROMPT rendering on sessions where the inject
182
+ * seam is unavailable: rewrite the assembled entry in place, then continue
183
+ * the chain. Never throws; an unexpected shape skips the rewrite.
184
+ *
185
+ * @param assembly - the assembly built so far.
186
+ * @param _context - the assembly context (unused).
187
+ * @param next - the waterfall continuation.
188
+ * @returns the downstream assembly.
189
+ */
190
+ const listener = async (assembly, _context, next) => {
191
+ try {
192
+ const entry = assembly?.contexts?.find((candidate) => candidate?.name === ENTRY_NAME);
193
+ if (entry !== undefined && typeof entry.text === "string")
194
+ entry.text = rewriteQuotedUnc(entry.text);
195
+ }
196
+ catch {
197
+ // Display preference, not correctness: skip the rewrite rather than
198
+ // fail the model step this assembly feeds.
199
+ }
200
+ return next();
201
+ };
202
+ ctx.on("system-prompt/assemble", listener);
203
+ }
@@ -18,12 +18,16 @@ import type { AgentStatus } from "./agent.js";
18
18
  export interface DoctorCheck {
19
19
  /** The stable check id, e.g. `agent.handshake`. */
20
20
  id: string;
21
- /** `ok` | `warn` | `fail` | `info`. */
21
+ /** `ok` | `warn` | `fail` | `info` | `skipped`. */
22
22
  status: string;
23
23
  /** The human detail line. */
24
24
  detail?: string;
25
25
  /** The copy-paste remedy, when the status is not `ok`. */
26
26
  remedy?: string;
27
+ /** The distro the check ran against (schema 2, distro-scoped checks). */
28
+ distro?: string;
29
+ /** Whether a `fail` here blocks the first command (schema 2). */
30
+ blocksFirstCommand?: boolean;
27
31
  }
28
32
  /** The doctor's versioned JSON report shape (`schemaVersion`). */
29
33
  export interface DoctorReport {
@@ -21,11 +21,12 @@ export function mergeLiveResidentStatus(report, status) {
21
21
  if (!fresh)
22
22
  return report;
23
23
  const errorLine = status.lastError.length > 0 ? `; lastError: ${status.lastError}` : "";
24
+ // The fresh check's shape fields (distro, blocksFirstCommand) ride through:
25
+ // the merge rewrites the verdict and the evidence, never the schema.
24
26
  const merged = {
25
- id: fresh.id,
27
+ ...fresh,
26
28
  status: status.state === "dead" ? "fail" : status.lastError.length > 0 ? "warn" : fresh.status,
27
29
  detail: `probed: the live resident (pid ${status.pid}, state ${status.state}, deaths ${status.deaths}, pending ${status.pending})${errorLine}; fresh-probe facts: ${fresh.detail ?? ""}`,
28
- ...(fresh.remedy !== undefined ? { remedy: fresh.remedy } : {}),
29
30
  };
30
31
  const checks = report.checks.map((check) => (check === fresh ? merged : check));
31
32
  const summary = { ...report.summary };
package/lib/index.d.ts CHANGED
@@ -108,6 +108,17 @@ export declare function doctorReport(distro: string, options?: {
108
108
  doctorPath?: string;
109
109
  /** The `wsl.exe` the doctor probes with; forwarded as `--wsl <path>`. */
110
110
  wslPath?: string;
111
+ /**
112
+ * Run the quick profile instead of the full scan: first-command
113
+ * prerequisites only (host/session/sandbox, no smokes, no registry query,
114
+ * no port survey) — forwarded as `--quick`.
115
+ */
116
+ quick?: boolean;
117
+ /**
118
+ * Restrict the run to these doctor sections (host, sandbox, session, conf,
119
+ * net, agent); forwarded as `--sections <csv>`. Undefined runs everything.
120
+ */
121
+ sections?: readonly string[];
111
122
  /**
112
123
  * Prepended to the doctor subprocess's PATH — a caller that stages a fake
113
124
  * `wsl.exe` (tests) passes the staging directory here instead of mutating
package/lib/index.js CHANGED
@@ -59,6 +59,7 @@ import { FsCodedError } from "./fsio-text.js";
59
59
  import { confinedAgent } from "./agent-confined.js";
60
60
  import { SessionRuntimes, probeSessionRuntime, sessionRuntimes, setSessionNativeAgent } from "./session-runtime.js";
61
61
  import { configureAgentBackend, ensureNativeSessionAgent } from "./native-agent.js";
62
+ import { installMessagesLocale, t } from "./messages.js";
62
63
  import { mergeLiveResidentStatus } from "./doctor-live.js";
63
64
  import { spawnSync } from "node:child_process";
64
65
  import { fileURLToPath } from "node:url";
@@ -203,6 +204,10 @@ const DOCTOR_SCRIPT = join(dirname(fileURLToPath(import.meta.url)), "..", "scrip
203
204
  export async function doctorReport(distro, options) {
204
205
  const script = options?.doctorPath ?? DOCTOR_SCRIPT;
205
206
  const argv = [script, distro, "--json"];
207
+ if (options?.quick === true)
208
+ argv.push("--quick");
209
+ if (options?.sections !== undefined && options.sections.length > 0)
210
+ argv.push("--sections", [...options.sections].join(","));
206
211
  if (options?.wslPath !== undefined)
207
212
  argv.push("--wsl", options.wslPath);
208
213
  // A nonzero doctor exit usually means an environment check FAILED on the
@@ -452,6 +457,7 @@ export class WslShellExecutor extends LocalBashExecutor {
452
457
  constructor(ctx, config) {
453
458
  super(ctx, config);
454
459
  configureAgentBackend(config.agentBackend ?? "auto");
460
+ installMessagesLocale(ctx);
455
461
  this.resolvedDistro = pinnedDistro(config.distro) ?? "";
456
462
  this.resolvedShell = config.shell;
457
463
  this.resolvedShells = new Map();
@@ -888,9 +894,7 @@ export class WslShellExecutor extends LocalBashExecutor {
888
894
  const code = wslErrorCode(result?.stdout?.text, result?.stderr?.text);
889
895
  if (code === undefined)
890
896
  return;
891
- throw new Error(`wsl.exe reported ${code} for distro "${distro}": it is not installed, or not running. ` +
892
- `Start it with \`wsl.exe -d ${distro}\`, check \`wsl.exe -l -v\`, or point \`distro\` at another one. ` +
893
- `This is not a sandbox denial, so running with wider permissions will not help.`);
897
+ throw new Error(t("distroUnavailable", { code, distro }));
894
898
  }
895
899
  /**
896
900
  * Reject a command that ran in the wrong directory.
@@ -908,8 +912,7 @@ export class WslShellExecutor extends LocalBashExecutor {
908
912
  const missing = workdirFailure(result?.stdout?.text, result?.stderr?.text);
909
913
  if (missing === undefined)
910
914
  return;
911
- throw new Error(`wsl.exe could not enter the working directory "${missing}" inside the distro, so the command ran from "/" instead. ` +
912
- `Create it, or point \`cwd\` (or the request's \`workdir\`) at a directory that exists.`);
915
+ throw new Error(t("workdirMissing", { missing }));
913
916
  }
914
917
  /**
915
918
  * Execute one resolved spec inside the distro, confined by the per-call policy
@@ -958,9 +961,7 @@ export class WslShellExecutor extends LocalBashExecutor {
958
961
  throwIfWorkdirInAnotherDistro(workdir, distro) {
959
962
  if (!isAnotherDistrosUnc(workdir, distro))
960
963
  return;
961
- throw new Error(`"${workdir}" names a workspace in another WSL distro, and this profile pins its commands to "${distro}" — ` +
962
- `running them here would act on a different machine's tree. Open a session in that distro, ` +
963
- `or point cwd/workdir at this distro.`);
964
+ throw new Error(t("workdirAnotherDistro", { workdir, distro }));
964
965
  }
965
966
  /**
966
967
  * The agent-backed execution path: one long-lived in-distro process, the
@@ -1295,6 +1296,7 @@ export class WslFileSystem extends LocalFileSystem {
1295
1296
  if (refusal !== null)
1296
1297
  throw new Error(refusal.message);
1297
1298
  super(ctx, config);
1299
+ installMessagesLocale(ctx);
1298
1300
  this.resolvedDistro = pinnedDistro(config.distro) ?? "";
1299
1301
  this.resolvedHome = undefined;
1300
1302
  this.resolvedHomes = new Map();