dsh-plugin-wsl-env 0.25.0 → 0.26.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 +84 -0
- package/CODE_OF_CONDUCT.md +85 -0
- package/CODE_OF_CONDUCT.zh.md +85 -0
- package/CONTRIBUTING.md +19 -3
- package/CONTRIBUTING.zh.md +200 -0
- package/README.md +12 -3
- package/SECURITY.md +2 -0
- package/SECURITY.zh.md +108 -0
- package/SUPPORT.md +2 -0
- package/SUPPORT.zh.md +99 -0
- package/client.js +409 -8
- package/cordis.patch.yml +13 -0
- package/docs/AGENT-PROTOCOL-V7.md +2 -2
- package/docs/API.md +2 -0
- package/docs/API.zh.md +38 -0
- package/docs/ARCHITECTURE.md +2 -0
- package/docs/ARCHITECTURE.zh.md +511 -0
- package/docs/COMPATIBILITY.md +2 -0
- package/docs/COMPATIBILITY.zh.md +117 -0
- package/docs/CONFIGURATION.md +2 -2
- package/docs/CONFIGURATION.zh.md +3 -3
- package/docs/DIAGNOSTICS.md +8 -0
- package/docs/DIAGNOSTICS.zh.md +2 -0
- package/docs/LIMITATIONS.md +43 -5
- package/docs/LIMITATIONS.zh.md +34 -6
- package/docs/MIGRATION.md +6 -3
- package/docs/MIGRATION.zh.md +91 -0
- package/docs/PEER-PARITY.md +59 -47
- package/docs/PERFORMANCE.md +2 -0
- package/docs/PERFORMANCE.zh.md +59 -0
- package/docs/QUICKSTART.md +9 -1
- package/docs/QUICKSTART.zh.md +8 -2
- package/docs/README.zh.md +22 -16
- package/docs/RELEASING.md +2 -1
- package/docs/REQUIREMENTS.zh.md +3 -1
- package/docs/ROADMAP-1.0.md +1 -1
- package/docs/UPSTREAM-FILE-REFERENCE-SEAM.md +1 -1
- package/docs/UPSTREAM-OPEN-IN-APP.md +33 -11
- package/docs/UPSTREAM-SESSION-NOTICE.md +7 -0
- package/docs/VALUE.md +146 -0
- package/docs/VALUE.zh.md +15 -13
- package/lib/auto-preset-seam.d.ts +45 -0
- package/lib/auto-preset-seam.js +47 -0
- package/lib/auto-preset.d.ts +33 -10
- package/lib/auto-preset.js +148 -44
- package/lib/doctor-live.d.ts +30 -0
- package/lib/doctor-live.js +37 -0
- package/lib/doctor-report.js +2 -2
- package/lib/messages.d.ts +19 -0
- package/lib/messages.js +28 -0
- package/lib/open-in-app.d.ts +206 -0
- package/lib/open-in-app.js +300 -0
- package/lib/preset-choice.d.ts +13 -0
- package/lib/preset-choice.js +18 -1
- package/lib/status.js +2 -1
- package/lib/wsl-doctor-command.js +2 -1
- package/package.json +47 -24
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The live state of auto-preset's creation-time preset seam.
|
|
3
|
+
*
|
|
4
|
+
* The seam is host-process state: `auto-preset` wraps
|
|
5
|
+
* `sessionController.agents.createSession(request)` so a distro workspace's
|
|
6
|
+
* very first mount is the WSL preset. Whether that method exists is a property
|
|
7
|
+
* of the running host, not of any file on disk — the standalone doctor CLI
|
|
8
|
+
* cannot see it, exactly as it cannot see a live resident's `deaths` or
|
|
9
|
+
* `lastError` (see doctor-live). The in-app doctor surfaces therefore read this
|
|
10
|
+
* module singleton and merge the state into their reports.
|
|
11
|
+
*
|
|
12
|
+
* `unknown` means the row has not mounted in this process yet (or this is a
|
|
13
|
+
* composition without it); `inactive` means the row mounted but the host's
|
|
14
|
+
* controller exposed no `agents.createSession` — the case that must not stay
|
|
15
|
+
* silent.
|
|
16
|
+
*
|
|
17
|
+
* @module dsh-plugin-wsl-env/auto-preset-seam
|
|
18
|
+
*/
|
|
19
|
+
/** Whether the creation-time seam is available in this process. */
|
|
20
|
+
export type AutoPresetSeamState = "active" | "inactive" | "unknown";
|
|
21
|
+
/** One publication of the seam state. */
|
|
22
|
+
export interface AutoPresetSeam {
|
|
23
|
+
/** The seam's availability. */
|
|
24
|
+
readonly state: AutoPresetSeamState;
|
|
25
|
+
/** The wrapped method, when the seam is active. */
|
|
26
|
+
readonly method?: string;
|
|
27
|
+
/** Why the state is what it is, in one line. */
|
|
28
|
+
readonly reason: string;
|
|
29
|
+
/** When the state was published, in epoch milliseconds. */
|
|
30
|
+
readonly at: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Publish the seam state for the in-app doctor surfaces.
|
|
34
|
+
*
|
|
35
|
+
* @param state - the availability to record.
|
|
36
|
+
* @param reason - one line explaining the state.
|
|
37
|
+
* @param method - the wrapped method, when active.
|
|
38
|
+
*/
|
|
39
|
+
export declare function publishAutoPresetSeam(state: AutoPresetSeamState, reason: string, method?: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* Read the current seam state.
|
|
42
|
+
*
|
|
43
|
+
* @returns the last published state.
|
|
44
|
+
*/
|
|
45
|
+
export declare function autoPresetSeam(): AutoPresetSeam;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The live state of auto-preset's creation-time preset seam.
|
|
3
|
+
*
|
|
4
|
+
* The seam is host-process state: `auto-preset` wraps
|
|
5
|
+
* `sessionController.agents.createSession(request)` so a distro workspace's
|
|
6
|
+
* very first mount is the WSL preset. Whether that method exists is a property
|
|
7
|
+
* of the running host, not of any file on disk — the standalone doctor CLI
|
|
8
|
+
* cannot see it, exactly as it cannot see a live resident's `deaths` or
|
|
9
|
+
* `lastError` (see doctor-live). The in-app doctor surfaces therefore read this
|
|
10
|
+
* module singleton and merge the state into their reports.
|
|
11
|
+
*
|
|
12
|
+
* `unknown` means the row has not mounted in this process yet (or this is a
|
|
13
|
+
* composition without it); `inactive` means the row mounted but the host's
|
|
14
|
+
* controller exposed no `agents.createSession` — the case that must not stay
|
|
15
|
+
* silent.
|
|
16
|
+
*
|
|
17
|
+
* @module dsh-plugin-wsl-env/auto-preset-seam
|
|
18
|
+
*/
|
|
19
|
+
/** The state before the row mounts; a report that sees it says so instead of guessing. */
|
|
20
|
+
let seam = {
|
|
21
|
+
state: "unknown",
|
|
22
|
+
reason: "the auto-preset row has not mounted in this process",
|
|
23
|
+
at: 0,
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Publish the seam state for the in-app doctor surfaces.
|
|
27
|
+
*
|
|
28
|
+
* @param state - the availability to record.
|
|
29
|
+
* @param reason - one line explaining the state.
|
|
30
|
+
* @param method - the wrapped method, when active.
|
|
31
|
+
*/
|
|
32
|
+
export function publishAutoPresetSeam(state, reason, method) {
|
|
33
|
+
seam = {
|
|
34
|
+
state,
|
|
35
|
+
reason,
|
|
36
|
+
at: Date.now(),
|
|
37
|
+
...(method === undefined ? {} : { method }),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Read the current seam state.
|
|
42
|
+
*
|
|
43
|
+
* @returns the last published state.
|
|
44
|
+
*/
|
|
45
|
+
export function autoPresetSeam() {
|
|
46
|
+
return seam;
|
|
47
|
+
}
|
package/lib/auto-preset.d.ts
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Why an event hook and not configuration: the environment is chosen in
|
|
6
6
|
* `dsh-api-session-controller`'s `composeAgent(presetId)`, whose signature has no
|
|
7
|
-
* working directory
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* working directory. The creation API above it — `createSession({ cwd,
|
|
8
|
+
* agentPreset, ... })` — holds both, so this row wraps that frame to fill the
|
|
9
|
+
* preset before the first mount; the `agent/created` event below is the
|
|
10
|
+
* fallback for flows that do not pass through it:
|
|
10
11
|
*
|
|
11
12
|
* ctx.serial(carrier, "agent/created", { agent, source, signal })
|
|
12
13
|
*
|
|
@@ -16,9 +17,10 @@
|
|
|
16
17
|
*
|
|
17
18
|
* 1. **Respect an explicit choice.** By the time the event fires, the resolved
|
|
18
19
|
* preset is already mounted (`composeAgent` mounts request-or-default in
|
|
19
|
-
* `setup`).
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* `setup`). A non-default preset id is an operator's pick and is never
|
|
21
|
+
* overridden. The default id (or no id at all) is not a pick of another
|
|
22
|
+
* environment: the client may send it explicitly, so the creation-time hook
|
|
23
|
+
* treats it as automatic for a distro workspace.
|
|
22
24
|
*
|
|
23
25
|
* 2. **Switch after creation, not during.** Switching inside the listener
|
|
24
26
|
* collides with the previous generation's tools:
|
|
@@ -99,11 +101,34 @@ interface CreatedAgentView {
|
|
|
99
101
|
session?: {
|
|
100
102
|
header?: {
|
|
101
103
|
cwd?: string | undefined;
|
|
102
|
-
|
|
104
|
+
/** A subagent session inherits its parent's environment; it gets no advisory of its own. */
|
|
105
|
+
origin?: string | undefined;
|
|
106
|
+
parentSession?: string | undefined;
|
|
107
|
+
} | undefined;
|
|
103
108
|
} | undefined;
|
|
104
109
|
/** The agent's own context. */
|
|
105
110
|
ctx: Context;
|
|
106
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* The create request the host's session-agent controller accepts (0.2.2+).
|
|
114
|
+
* Only the fields this row reads are spelled here; the wrapper forwards the
|
|
115
|
+
* whole object, so a newer host field survives untouched.
|
|
116
|
+
*/
|
|
117
|
+
interface SessionCreateRequestLike {
|
|
118
|
+
/** The blank session to reuse, when the caller named one. */
|
|
119
|
+
readonly sessionId?: string;
|
|
120
|
+
/** The workspace the session owns. */
|
|
121
|
+
readonly cwd: string;
|
|
122
|
+
/** The preset the caller requested, or undefined for the default. */
|
|
123
|
+
readonly agentPreset?: string;
|
|
124
|
+
/** The caller's reuse policy, forwarded untouched. */
|
|
125
|
+
readonly reusable: (sessionId: string) => boolean;
|
|
126
|
+
}
|
|
127
|
+
/** The controller slice this row wraps. */
|
|
128
|
+
interface SessionAgentFacade {
|
|
129
|
+
/** Create or reuse the session for one request; the creation-time seam. */
|
|
130
|
+
createSession?: (request: SessionCreateRequestLike) => Promise<unknown>;
|
|
131
|
+
}
|
|
107
132
|
/**
|
|
108
133
|
* The cordis context extended with the agent-service slices this plugin
|
|
109
134
|
* consumes. `agents` and `agentPresets` come from the harness's agent
|
|
@@ -123,9 +148,7 @@ type AutoPresetContext = Context & {
|
|
|
123
148
|
agent?: CreatedAgentView;
|
|
124
149
|
} | undefined) => void) => () => boolean;
|
|
125
150
|
sessionController?: {
|
|
126
|
-
agents?:
|
|
127
|
-
ensureSession: (this: unknown, sessionId: string, cwd: string | undefined, checkPersistedIdentity: boolean, presetId: string | undefined) => Promise<unknown>;
|
|
128
|
-
};
|
|
151
|
+
agents?: SessionAgentFacade;
|
|
129
152
|
};
|
|
130
153
|
};
|
|
131
154
|
/**
|
package/lib/auto-preset.js
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Why an event hook and not configuration: the environment is chosen in
|
|
6
6
|
* `dsh-api-session-controller`'s `composeAgent(presetId)`, whose signature has no
|
|
7
|
-
* working directory
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* working directory. The creation API above it — `createSession({ cwd,
|
|
8
|
+
* agentPreset, ... })` — holds both, so this row wraps that frame to fill the
|
|
9
|
+
* preset before the first mount; the `agent/created` event below is the
|
|
10
|
+
* fallback for flows that do not pass through it:
|
|
10
11
|
*
|
|
11
12
|
* ctx.serial(carrier, "agent/created", { agent, source, signal })
|
|
12
13
|
*
|
|
@@ -16,9 +17,10 @@
|
|
|
16
17
|
*
|
|
17
18
|
* 1. **Respect an explicit choice.** By the time the event fires, the resolved
|
|
18
19
|
* preset is already mounted (`composeAgent` mounts request-or-default in
|
|
19
|
-
* `setup`).
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* `setup`). A non-default preset id is an operator's pick and is never
|
|
21
|
+
* overridden. The default id (or no id at all) is not a pick of another
|
|
22
|
+
* environment: the client may send it explicitly, so the creation-time hook
|
|
23
|
+
* treats it as automatic for a distro workspace.
|
|
22
24
|
*
|
|
23
25
|
* 2. **Switch after creation, not during.** Switching inside the listener
|
|
24
26
|
* collides with the previous generation's tools:
|
|
@@ -35,8 +37,11 @@
|
|
|
35
37
|
*/
|
|
36
38
|
import { appendFileSync } from "node:fs";
|
|
37
39
|
import z from "@deepseek-ai/schemastery";
|
|
40
|
+
import { distroOfUnc } from "./distro-route.js";
|
|
41
|
+
import { installMessagesLocale, t } from "./messages.js";
|
|
38
42
|
import { isWslUnc } from "./paths.js";
|
|
39
|
-
import {
|
|
43
|
+
import { publishAutoPresetSeam } from "./auto-preset-seam.js";
|
|
44
|
+
import { isDefaultPresetChoice, isWindowsAccessWorkspace, shouldAdoptWslPreset } from "./preset-choice.js";
|
|
40
45
|
/**
|
|
41
46
|
* Set `DSH_WSL_TRACE` to a file path to record every decision this plugin makes.
|
|
42
47
|
*
|
|
@@ -60,6 +65,35 @@ function trace(message) {
|
|
|
60
65
|
/* a trace is never worth failing a session over */
|
|
61
66
|
}
|
|
62
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Read the registry's default preset id, tolerating a service without one.
|
|
70
|
+
*
|
|
71
|
+
* @param ctx - the plugin context.
|
|
72
|
+
* @returns the default id, or undefined when the registry cannot name one.
|
|
73
|
+
*/
|
|
74
|
+
function defaultPresetId(ctx) {
|
|
75
|
+
try {
|
|
76
|
+
return ctx.agentPresets.defaultId;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Whether a create failure is the preset registry refusing the target — the
|
|
84
|
+
* one error class adoption may fall back on. A failed adoption must not turn
|
|
85
|
+
* into a failed session creation; anything else still propagates.
|
|
86
|
+
*
|
|
87
|
+
* @param error - the rejection from the host's create call.
|
|
88
|
+
* @returns true when the caller may retry with the recorded preset.
|
|
89
|
+
*/
|
|
90
|
+
function isPresetAdoptionError(error) {
|
|
91
|
+
const code = error?.code;
|
|
92
|
+
if (typeof code === "string" && code.startsWith("agent-preset/"))
|
|
93
|
+
return true;
|
|
94
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
95
|
+
return message.toLowerCase().includes("agent preset");
|
|
96
|
+
}
|
|
63
97
|
export const name = "auto-preset";
|
|
64
98
|
export const inject = ["agents", "agentPresets"];
|
|
65
99
|
export const Config = z.object({
|
|
@@ -93,8 +127,16 @@ function windowsAccessList(value) {
|
|
|
93
127
|
if (value === undefined)
|
|
94
128
|
return [];
|
|
95
129
|
if (typeof value.get === "function") {
|
|
96
|
-
|
|
97
|
-
|
|
130
|
+
try {
|
|
131
|
+
const current = value.get();
|
|
132
|
+
return Array.isArray(current) ? current : [];
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
// A volatile read is config, not session state: a throwing field must not
|
|
136
|
+
// fail a session creation or an adoption decision. An unreadable record
|
|
137
|
+
// means "no recorded Windows-access directory".
|
|
138
|
+
return [];
|
|
139
|
+
}
|
|
98
140
|
}
|
|
99
141
|
return Array.isArray(value) ? value : [];
|
|
100
142
|
}
|
|
@@ -108,6 +150,9 @@ export async function apply(ctx, config = {}) {
|
|
|
108
150
|
const target = config.preset ?? "wsl";
|
|
109
151
|
const attempts = config.attempts ?? 6;
|
|
110
152
|
const retryMs = config.retryMs ?? 150;
|
|
153
|
+
// The advisory below is model-facing text; follow the app's language like the
|
|
154
|
+
// other rows do (a profile without `settings` keeps English).
|
|
155
|
+
installMessagesLocale(ctx);
|
|
111
156
|
const warn = (message) => {
|
|
112
157
|
trace(`WARN ${message}`);
|
|
113
158
|
// `logger` is not injectable here, so an unavailable or throwing logger must
|
|
@@ -129,6 +174,47 @@ export async function apply(ctx, config = {}) {
|
|
|
129
174
|
}
|
|
130
175
|
}
|
|
131
176
|
};
|
|
177
|
+
/**
|
|
178
|
+
* Say, once, that a distro workspace is running the host environment.
|
|
179
|
+
*
|
|
180
|
+
* The model gets a runtime-context entry because otherwise it believes its
|
|
181
|
+
* commands run in the distro (they run in Windows PowerShell, and file access
|
|
182
|
+
* crosses the 9p share). The operator gets the log line; the web client's
|
|
183
|
+
* banner is the human-facing half of the same fact. Nothing here can fail a
|
|
184
|
+
* session: the whole plugin is advisory at this point.
|
|
185
|
+
*
|
|
186
|
+
* @param agent - the session that just opened.
|
|
187
|
+
* @param cwd - its workspace, a `\\wsl.localhost\…` path.
|
|
188
|
+
* @param message - the already-localized advisory.
|
|
189
|
+
*/
|
|
190
|
+
const advised = new Set();
|
|
191
|
+
const adviseHostMode = (agent, cwd, message) => {
|
|
192
|
+
if (advised.has(agent.id) || !isWslUnc(cwd))
|
|
193
|
+
return;
|
|
194
|
+
// A subagent inherits the environment its parent was told about; repeating
|
|
195
|
+
// the advisory in every child context is noise, not information.
|
|
196
|
+
const header = agent.session?.header;
|
|
197
|
+
if (header?.origin === "subagent" || header?.parentSession !== undefined)
|
|
198
|
+
return;
|
|
199
|
+
advised.add(agent.id);
|
|
200
|
+
warn(`"${cwd}" runs the host (Windows) environment: commands use PowerShell and file access crosses the 9p share`);
|
|
201
|
+
// The harness's agent context carries `systemPrompt`; the service is not in
|
|
202
|
+
// this plugin's typings, so the injection is spelled structurally. A host
|
|
203
|
+
// payload without a context still gets the log line, not a crash.
|
|
204
|
+
const context = agent.ctx;
|
|
205
|
+
const inject = context?.inject;
|
|
206
|
+
if (typeof inject !== "function" || context === undefined)
|
|
207
|
+
return;
|
|
208
|
+
try {
|
|
209
|
+
inject.call(context, ["systemPrompt"], (scope) => {
|
|
210
|
+
scope.systemPrompt.context({ name: "wsl-access-mode", order: 200, text: () => message });
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
// A missing seam degrades to the log line above, never to a failed session.
|
|
215
|
+
trace(` -> could not publish the host-mode advisory: ${error?.message ?? error}`);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
132
218
|
const consider = (agent) => {
|
|
133
219
|
if (agent === void 0)
|
|
134
220
|
return;
|
|
@@ -147,27 +233,25 @@ export async function apply(ctx, config = {}) {
|
|
|
147
233
|
// registry default (i.e. the operator did not ask for one). `undefined` means
|
|
148
234
|
// the creating caller mounted nothing at all — the headless runner does this
|
|
149
235
|
// — which is likewise "no explicit choice".
|
|
150
|
-
|
|
151
|
-
try {
|
|
152
|
-
fallback = ctx.agentPresets.defaultId;
|
|
153
|
-
}
|
|
154
|
-
catch {
|
|
155
|
-
fallback = void 0;
|
|
156
|
-
}
|
|
236
|
+
const fallback = defaultPresetId(ctx);
|
|
157
237
|
const windowsAccess = windowsAccessList(config.windowsWorkspaces);
|
|
158
238
|
if (!shouldAdoptWslPreset({ cwd, current, fallback, windowsAccess })) {
|
|
159
|
-
if (cwd !== undefined && windowsAccess
|
|
239
|
+
if (cwd !== undefined && isWindowsAccessWorkspace(cwd, windowsAccess)) {
|
|
160
240
|
trace(` -> skipped: Windows-access workspace ${JSON.stringify(cwd)}`);
|
|
241
|
+
adviseHostMode(agent, cwd, t("hostModeWindowsAccess", { cwd, distro: distroOfUnc(cwd) ?? "WSL" }));
|
|
161
242
|
}
|
|
162
243
|
return;
|
|
163
244
|
}
|
|
164
|
-
|
|
245
|
+
if (cwd === undefined)
|
|
246
|
+
return;
|
|
247
|
+
const workspace = cwd;
|
|
248
|
+
trace(` -> acting: fallback=${String(fallback)} isWsl=${isWslUnc(workspace)}`);
|
|
165
249
|
// Deferred on purpose — see the module comment.
|
|
166
250
|
void (async () => {
|
|
167
251
|
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
168
252
|
try {
|
|
169
253
|
const chosen = await ctx.agentPresets.select(agent, target);
|
|
170
|
-
ctx.logger?.debug?.(`auto-preset: "${
|
|
254
|
+
ctx.logger?.debug?.(`auto-preset: "${workspace}" -> preset "${chosen}"`);
|
|
171
255
|
return;
|
|
172
256
|
}
|
|
173
257
|
catch (error) {
|
|
@@ -175,15 +259,17 @@ export async function apply(ctx, config = {}) {
|
|
|
175
259
|
// The session already started a turn: its preset is fixed, and that is
|
|
176
260
|
// a legitimate outcome (the operator drove it before we got here).
|
|
177
261
|
if (code === "agent-preset/locked") {
|
|
178
|
-
warn(`"${
|
|
262
|
+
warn(`"${workspace}" already began its first turn; leaving the preset as "${String(current)}"`);
|
|
263
|
+
adviseHostMode(agent, workspace, t("hostModeLocked", { cwd: workspace, distro: distroOfUnc(workspace) ?? "WSL" }));
|
|
179
264
|
return;
|
|
180
265
|
}
|
|
181
266
|
if (code === "agent-preset/not-found") {
|
|
182
|
-
warn(`preset "${target}" is not composed in this profile; skipping "${
|
|
267
|
+
warn(`preset "${target}" is not composed in this profile; skipping "${workspace}"`);
|
|
268
|
+
adviseHostMode(agent, workspace, t("hostModePresetUnavailable", { cwd: workspace, distro: distroOfUnc(workspace) ?? "WSL" }));
|
|
183
269
|
return;
|
|
184
270
|
}
|
|
185
271
|
if (attempt === attempts) {
|
|
186
|
-
warn(`could not bind preset "${target}" for "${
|
|
272
|
+
warn(`could not bind preset "${target}" for "${workspace}": ${code ?? error?.name}: ${error?.message}`);
|
|
187
273
|
return;
|
|
188
274
|
}
|
|
189
275
|
await new Promise((resolve) => setTimeout(resolve, retryMs));
|
|
@@ -200,41 +286,59 @@ export async function apply(ctx, config = {}) {
|
|
|
200
286
|
// failed (Win32 1)`) and the workspace is unusable — not merely mis-labelled.
|
|
201
287
|
// Correcting the preset after creation loses whenever the first turn does not
|
|
202
288
|
// wait, so the choice is made where the cwd still exists: the controller
|
|
203
|
-
// resolves the preset in `composeAgent(presetId)`, which has no cwd, but
|
|
204
|
-
//
|
|
205
|
-
//
|
|
206
|
-
//
|
|
289
|
+
// resolves the preset in `composeAgent(presetId)`, which has no cwd, but its
|
|
290
|
+
// caller `createSession({ cwd, agentPreset, … })` holds both. Filling the
|
|
291
|
+
// preset there makes the very first mount already correct, so the host sandbox
|
|
292
|
+
// never meets the distro path at all.
|
|
293
|
+
//
|
|
294
|
+
// The host renamed this frame: 0.2.0-rc.2 exposed
|
|
295
|
+
// `ensureSession(sessionId, cwd, …, presetId)`; 0.2.1 replaced it with the
|
|
296
|
+
// request object below. Wrapping the request keeps any field a newer host adds
|
|
297
|
+
// intact, and a missing method is reported through the warning and the
|
|
298
|
+
// doctor's `session.preset-seam` check instead of failing silently.
|
|
207
299
|
ctx.inject(["sessionController"], (controllerCtx) => {
|
|
208
300
|
const facade = controllerCtx.sessionController?.agents;
|
|
209
|
-
if (facade === void 0 || typeof facade.
|
|
210
|
-
|
|
301
|
+
if (facade === void 0 || typeof facade.createSession !== "function") {
|
|
302
|
+
publishAutoPresetSeam("inactive", "the host's sessionController exposes no agents.createSession()");
|
|
303
|
+
warn("sessionController exposes no agents.createSession(); the creation-time preset fix is inactive");
|
|
211
304
|
return;
|
|
212
305
|
}
|
|
213
|
-
const original = facade.
|
|
214
|
-
facade.
|
|
215
|
-
//
|
|
216
|
-
//
|
|
217
|
-
//
|
|
218
|
-
// so skipping it is what the
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
306
|
+
const original = facade.createSession;
|
|
307
|
+
facade.createSession = async function (request) {
|
|
308
|
+
// A non-default preset id always wins; the default id (or no id) is
|
|
309
|
+
// automatic. Only a distro workspace is affected. A workspace the operator
|
|
310
|
+
// opened for Windows access keeps the host preset even here: this is the
|
|
311
|
+
// frame that makes the first mount correct, so skipping it is what the
|
|
312
|
+
// choice means.
|
|
313
|
+
const candidate = request;
|
|
314
|
+
if (candidate === null || typeof candidate !== "object" || typeof candidate.cwd !== "string") {
|
|
315
|
+
return original.call(this, request);
|
|
316
|
+
}
|
|
317
|
+
const requested = typeof candidate.agentPreset === "string" ? candidate.agentPreset : undefined;
|
|
318
|
+
const fallback = defaultPresetId(ctx);
|
|
319
|
+
if (!isDefaultPresetChoice(requested, fallback) || !isWslUnc(candidate.cwd)
|
|
320
|
+
|| isWindowsAccessWorkspace(candidate.cwd, windowsAccessList(config.windowsWorkspaces))) {
|
|
321
|
+
return original.call(this, request);
|
|
222
322
|
}
|
|
223
323
|
try {
|
|
224
|
-
return await original.call(this,
|
|
324
|
+
return await original.call(this, { ...request, agentPreset: target });
|
|
225
325
|
}
|
|
226
326
|
catch (error) {
|
|
227
|
-
// A session already stored under another preset
|
|
228
|
-
//
|
|
229
|
-
|
|
327
|
+
// A session already stored under another preset, or a profile without
|
|
328
|
+
// the WSL preset, must not turn adoption into a failed creation: retry
|
|
329
|
+
// with the caller's own choice and let the event path report the state.
|
|
330
|
+
if (!isPresetAdoptionError(error))
|
|
230
331
|
throw error;
|
|
231
|
-
|
|
232
|
-
|
|
332
|
+
const named = typeof candidate.sessionId === "string" ? candidate.sessionId : "(new session)";
|
|
333
|
+
trace(`creation-time preset "${target}" refused for ${named}; falling back to the recorded one`);
|
|
334
|
+
return original.call(this, request);
|
|
233
335
|
}
|
|
234
336
|
};
|
|
337
|
+
publishAutoPresetSeam("active", "agents.createSession is wrapped; distro sessions mount the WSL preset first", "createSession");
|
|
235
338
|
trace("creation-time preset fix installed");
|
|
236
339
|
controllerCtx.effect(() => () => {
|
|
237
|
-
facade.
|
|
340
|
+
facade.createSession = original;
|
|
341
|
+
publishAutoPresetSeam("inactive", "the auto-preset row was disposed");
|
|
238
342
|
});
|
|
239
343
|
});
|
|
240
344
|
// Mount order is not a guarantee: a runner that creates its session during
|
package/lib/doctor-live.d.ts
CHANGED
|
@@ -55,4 +55,34 @@ export interface DoctorReport {
|
|
|
55
55
|
* there is nothing to merge.
|
|
56
56
|
*/
|
|
57
57
|
export declare function mergeLiveResidentStatus(report: DoctorReport, status: AgentStatus | undefined): DoctorReport;
|
|
58
|
+
/** The report fields {@link mergeAutoPresetSeam} needs; the strict and loose report types both fit. */
|
|
59
|
+
interface SeamMergeReport {
|
|
60
|
+
/** The report's check rows. */
|
|
61
|
+
checks?: Array<{
|
|
62
|
+
id: string;
|
|
63
|
+
status: string;
|
|
64
|
+
title?: string;
|
|
65
|
+
detail?: string;
|
|
66
|
+
remedy?: string;
|
|
67
|
+
distro?: string;
|
|
68
|
+
blocksFirstCommand?: boolean;
|
|
69
|
+
}>;
|
|
70
|
+
/** The per-status tally. */
|
|
71
|
+
summary?: Record<string, number>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Fold auto-preset's creation-time seam state into a doctor report.
|
|
75
|
+
*
|
|
76
|
+
* The seam is host-process state — whether the running session controller
|
|
77
|
+
* exposes `agents.createSession` — so the standalone CLI cannot see it, just as
|
|
78
|
+
* it cannot see a live resident's lifecycle (see {@link mergeLiveResidentStatus}).
|
|
79
|
+
* The in-app surfaces (the `wsl_doctor` tool, the `/wsl-doctor` command and the
|
|
80
|
+
* sidebar panel) call this merge, so the silent-degradation case that motivated
|
|
81
|
+
* the check appears as a warning instead of a log line only. A `warn` does not
|
|
82
|
+
* block the first command: adoption after creation still runs.
|
|
83
|
+
*
|
|
84
|
+
* @param report - the collected doctor report (not mutated).
|
|
85
|
+
* @returns the report with the `session.preset-seam` row appended.
|
|
86
|
+
*/
|
|
87
|
+
export declare function mergeAutoPresetSeam<T extends SeamMergeReport>(report: T): T;
|
|
58
88
|
export {};
|
package/lib/doctor-live.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { autoPresetSeam } from "./auto-preset-seam.js";
|
|
1
2
|
/**
|
|
2
3
|
* Fold an in-process resident's lifecycle snapshot into a doctor report's
|
|
3
4
|
* `agent.handshake` check.
|
|
@@ -36,3 +37,39 @@ export function mergeLiveResidentStatus(report, status) {
|
|
|
36
37
|
}
|
|
37
38
|
return { ...report, checks, summary };
|
|
38
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Fold auto-preset's creation-time seam state into a doctor report.
|
|
42
|
+
*
|
|
43
|
+
* The seam is host-process state — whether the running session controller
|
|
44
|
+
* exposes `agents.createSession` — so the standalone CLI cannot see it, just as
|
|
45
|
+
* it cannot see a live resident's lifecycle (see {@link mergeLiveResidentStatus}).
|
|
46
|
+
* The in-app surfaces (the `wsl_doctor` tool, the `/wsl-doctor` command and the
|
|
47
|
+
* sidebar panel) call this merge, so the silent-degradation case that motivated
|
|
48
|
+
* the check appears as a warning instead of a log line only. A `warn` does not
|
|
49
|
+
* block the first command: adoption after creation still runs.
|
|
50
|
+
*
|
|
51
|
+
* @param report - the collected doctor report (not mutated).
|
|
52
|
+
* @returns the report with the `session.preset-seam` row appended.
|
|
53
|
+
*/
|
|
54
|
+
export function mergeAutoPresetSeam(report) {
|
|
55
|
+
const seam = autoPresetSeam();
|
|
56
|
+
const status = seam.state === "active" ? "ok" : seam.state === "inactive" ? "warn" : "info";
|
|
57
|
+
const detail = seam.state === "active"
|
|
58
|
+
? `the creation-time preset seam is active (${seam.method ?? "agents.createSession"})`
|
|
59
|
+
: seam.state === "inactive"
|
|
60
|
+
? `the creation-time preset seam is inactive: ${seam.reason}; a distro session still adopts the WSL preset after creation, but its first mount can use the host environment`
|
|
61
|
+
: `the auto-preset row has not initialized in this process (${seam.reason}); the check applies only where the plugin's root composition is mounted`;
|
|
62
|
+
const check = {
|
|
63
|
+
id: "session.preset-seam",
|
|
64
|
+
status,
|
|
65
|
+
title: "Environment auto-binding",
|
|
66
|
+
detail,
|
|
67
|
+
...(status === "warn"
|
|
68
|
+
? { remedy: "update the plugin (or the host) so the session controller exposes agents.createSession, then restart DSH — see docs/DIAGNOSTICS.md" }
|
|
69
|
+
: {}),
|
|
70
|
+
};
|
|
71
|
+
const checks = [...(report.checks ?? []), check];
|
|
72
|
+
const summary = { ...report.summary };
|
|
73
|
+
summary[status] = (summary[status] ?? 0) + 1;
|
|
74
|
+
return { ...report, checks, summary };
|
|
75
|
+
}
|
package/lib/doctor-report.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sharedAgent } from "./agent-shared.js";
|
|
2
|
-
import { mergeLiveResidentStatus } from "./doctor-live.js";
|
|
2
|
+
import { mergeAutoPresetSeam, mergeLiveResidentStatus } from "./doctor-live.js";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
@@ -168,5 +168,5 @@ export async function doctorReport(distro, options) {
|
|
|
168
168
|
throw new Error(`doctor run failed: ${cause}${run.stderr.length > 0 ? ` — ${run.stderr.trim().slice(-400)}` : ""}`);
|
|
169
169
|
}
|
|
170
170
|
const status = options?.liveStatus ?? sharedAgent(distro).status();
|
|
171
|
-
return mergeLiveResidentStatus(report, status);
|
|
171
|
+
return mergeAutoPresetSeam(mergeLiveResidentStatus(report, status));
|
|
172
172
|
}
|
package/lib/messages.d.ts
CHANGED
|
@@ -92,6 +92,25 @@ declare const en: {
|
|
|
92
92
|
workdir: string;
|
|
93
93
|
distro: string;
|
|
94
94
|
}) => string;
|
|
95
|
+
/**
|
|
96
|
+
* `auto-preset`: a distro workspace is recorded as Windows access (9p), so
|
|
97
|
+
* the session runs the host preset. The model-facing half of the reminder;
|
|
98
|
+
* the human sees the web client's banner.
|
|
99
|
+
*/
|
|
100
|
+
hostModeWindowsAccess: ({ cwd, distro }: {
|
|
101
|
+
cwd: string;
|
|
102
|
+
distro: string;
|
|
103
|
+
}) => string;
|
|
104
|
+
/** `auto-preset`: the session began its first turn before the WSL preset could be selected. */
|
|
105
|
+
hostModeLocked: ({ cwd, distro }: {
|
|
106
|
+
cwd: string;
|
|
107
|
+
distro: string;
|
|
108
|
+
}) => string;
|
|
109
|
+
/** `auto-preset`: the profile composes no WSL preset, so the session keeps the host environment. */
|
|
110
|
+
hostModePresetUnavailable: ({ cwd, distro }: {
|
|
111
|
+
cwd: string;
|
|
112
|
+
distro: string;
|
|
113
|
+
}) => string;
|
|
95
114
|
/** `wsl_doctor` digest: the verdict line. `verdict` is the report's own `ready`/`blocked`. */
|
|
96
115
|
doctorDigestVerdict: ({ verdict }: {
|
|
97
116
|
verdict: string;
|
package/lib/messages.js
CHANGED
|
@@ -69,6 +69,25 @@ 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
|
+
* `auto-preset`: a distro workspace is recorded as Windows access (9p), so
|
|
74
|
+
* the session runs the host preset. The model-facing half of the reminder;
|
|
75
|
+
* the human sees the web client's banner.
|
|
76
|
+
*/
|
|
77
|
+
hostModeWindowsAccess: ({ cwd, distro }) => `The workspace "${cwd}" is inside WSL distro "${distro}" but is recorded as a Windows-access workspace, ` +
|
|
78
|
+
`so this session runs the host (Windows) environment: commands execute in Windows PowerShell, file access ` +
|
|
79
|
+
`crosses the 9p share, and the distro's Linux toolchain is unavailable. Do not assume Linux commands, paths, ` +
|
|
80
|
+
`or tooling here; using the distro requires opening a new session in this workspace with the WSL preset.`,
|
|
81
|
+
/** `auto-preset`: the session began its first turn before the WSL preset could be selected. */
|
|
82
|
+
hostModeLocked: ({ cwd, distro }) => `The workspace "${cwd}" is inside WSL distro "${distro}", but this session became interactive before the WSL ` +
|
|
83
|
+
`preset could be selected, so it keeps the host (Windows) environment: commands execute in Windows PowerShell, ` +
|
|
84
|
+
`file access crosses the 9p share, and the distro's Linux toolchain is unavailable. Do not assume Linux commands, ` +
|
|
85
|
+
`paths, or tooling here; a new session in this workspace adopts the WSL preset.`,
|
|
86
|
+
/** `auto-preset`: the profile composes no WSL preset, so the session keeps the host environment. */
|
|
87
|
+
hostModePresetUnavailable: ({ cwd, distro }) => `The workspace "${cwd}" is inside WSL distro "${distro}", but this profile composes no WSL preset, so this ` +
|
|
88
|
+
`session runs the host (Windows) environment: commands execute in Windows PowerShell, file access crosses the ` +
|
|
89
|
+
`9p share, and the distro's Linux toolchain is unavailable. Do not assume Linux commands, paths, or tooling ` +
|
|
90
|
+
`here; the operator can run /wsl-doctor to diagnose the profile.`,
|
|
72
91
|
/** `wsl_doctor` digest: the verdict line. `verdict` is the report's own `ready`/`blocked`. */
|
|
73
92
|
doctorDigestVerdict: ({ verdict }) => `wsl doctor verdict: ${verdict}`,
|
|
74
93
|
/** `wsl_doctor` digest: the host-wide group heading. */
|
|
@@ -127,6 +146,15 @@ const zh = {
|
|
|
127
146
|
`请创建该目录,或将 \`cwd\`(或请求的 \`workdir\`)指向一个已存在的目录。`,
|
|
128
147
|
workdirAnotherDistro: ({ workdir, distro }) => `"${workdir}" 指向另一个 WSL 发行版中的工作区,而本 profile 将命令固定在 "${distro}" —— ` +
|
|
129
148
|
`在这里运行会作用于另一台机器的目录树。请在该发行版中打开会话,或将 cwd/workdir 指向本发行版。`,
|
|
149
|
+
hostModeWindowsAccess: ({ cwd, distro }) => `工作区 "${cwd}" 位于 WSL 发行版 "${distro}" 内,但被记录为 Windows 访问工作区,` +
|
|
150
|
+
`因此本会话运行在宿主(Windows)环境:命令经 PowerShell 执行,文件访问经过 9p 共享,发行版的 Linux 工具链不可用。` +
|
|
151
|
+
`不要在此假设 Linux 命令、路径或工具;如需在发行版内运行,须由操作者以 WSL preset 在本工作区新开会话。`,
|
|
152
|
+
hostModeLocked: ({ cwd, distro }) => `工作区 "${cwd}" 位于 WSL 发行版 "${distro}" 内,但本会话在选中 WSL preset 之前就已开始交互,` +
|
|
153
|
+
`因此保留宿主(Windows)环境:命令经 PowerShell 执行,文件访问经过 9p 共享,发行版的 Linux 工具链不可用。` +
|
|
154
|
+
`不要在此假设 Linux 命令、路径或工具;在本工作区新开的会话会采用 WSL preset。`,
|
|
155
|
+
hostModePresetUnavailable: ({ cwd, distro }) => `工作区 "${cwd}" 位于 WSL 发行版 "${distro}" 内,但本 profile 未装配 WSL preset,` +
|
|
156
|
+
`因此本会话运行在宿主(Windows)环境:命令经 PowerShell 执行,文件访问经过 9p 共享,发行版的 Linux 工具链不可用。` +
|
|
157
|
+
`不要在此假设 Linux 命令、路径或工具;操作者可运行 /wsl-doctor 诊断该 profile。`,
|
|
130
158
|
doctorDigestVerdict: ({ verdict }) => `wsl doctor 裁决:${verdict}`,
|
|
131
159
|
doctorDigestHostLabel: () => "(宿主——Windows 与全局检查)",
|
|
132
160
|
doctorDigestNotRunLabel: () => "(不在本次范围)",
|