dsh-plugin-wsl-env 0.29.0 → 0.29.1

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 (78) hide show
  1. package/CHANGELOG.md +342 -0
  2. package/CONTRIBUTING.md +68 -12
  3. package/CONTRIBUTING.zh.md +34 -4
  4. package/README.md +1 -1
  5. package/agent/native/linux-aarch64/dsh-wsl-agent +0 -0
  6. package/agent/native/linux-x86_64/dsh-wsl-agent +0 -0
  7. package/agent/wsl-agent.sh +15 -4
  8. package/client.js +454 -110
  9. package/cordis.patch.yml +28 -7
  10. package/docs/AGENT-PROTOCOL-V7.md +4 -2
  11. package/docs/ARCHITECTURE.md +3 -1
  12. package/docs/ARCHITECTURE.zh.md +3 -1
  13. package/docs/COMPATIBILITY.md +1 -1
  14. package/docs/COMPATIBILITY.zh.md +1 -1
  15. package/docs/CONFIGURATION.md +19 -7
  16. package/docs/CONFIGURATION.zh.md +13 -5
  17. package/docs/DIAGNOSTICS.md +31 -5
  18. package/docs/DIAGNOSTICS.zh.md +22 -5
  19. package/docs/LIMITATIONS.md +65 -6
  20. package/docs/LIMITATIONS.zh.md +51 -6
  21. package/docs/PERFORMANCE.md +29 -1
  22. package/docs/PERFORMANCE.zh.md +23 -1
  23. package/docs/QUICKSTART.md +1 -1
  24. package/docs/QUICKSTART.zh.md +1 -1
  25. package/docs/README.zh.md +1 -1
  26. package/docs/RELEASING.md +29 -6
  27. package/docs/RELEASING.zh.md +9 -0
  28. package/docs/adr/0002-native-agent.md +50 -2
  29. package/lib/agent-confined.js +15 -4
  30. package/lib/agent-errors.d.ts +16 -0
  31. package/lib/agent-errors.js +19 -0
  32. package/lib/agent-exec.d.ts +8 -1
  33. package/lib/agent-exec.js +2 -1
  34. package/lib/agent-shared.d.ts +85 -2
  35. package/lib/agent-shared.js +167 -38
  36. package/lib/agent.d.ts +60 -6
  37. package/lib/agent.js +177 -28
  38. package/lib/auto-preset.js +7 -2
  39. package/lib/doctor-live.d.ts +36 -7
  40. package/lib/doctor-live.js +61 -12
  41. package/lib/doctor-process.d.ts +68 -0
  42. package/lib/doctor-process.js +139 -0
  43. package/lib/doctor-report.js +11 -109
  44. package/lib/fs-substrate.js +3 -3
  45. package/lib/fsio-agent.d.ts +57 -6
  46. package/lib/fsio-agent.js +168 -75
  47. package/lib/git-exec.d.ts +7 -1
  48. package/lib/git-exec.js +14 -2
  49. package/lib/native-agent.d.ts +25 -4
  50. package/lib/native-agent.js +52 -9
  51. package/lib/picker.d.ts +2 -1
  52. package/lib/picker.js +30 -13
  53. package/lib/plugin-update.js +18 -14
  54. package/lib/provider-common.d.ts +112 -0
  55. package/lib/provider-common.js +171 -0
  56. package/lib/sandbox-core.js +52 -13
  57. package/lib/search-exec.d.ts +6 -0
  58. package/lib/search-exec.js +10 -2
  59. package/lib/session-runtime.d.ts +46 -1
  60. package/lib/session-runtime.js +57 -7
  61. package/lib/session-scope.d.ts +22 -1
  62. package/lib/session-scope.js +33 -7
  63. package/lib/shell-env.js +125 -12
  64. package/lib/socket-isolation.d.ts +12 -4
  65. package/lib/socket-isolation.js +27 -10
  66. package/lib/status.js +53 -4
  67. package/lib/subprocess.js +3 -3
  68. package/lib/terminal-activity.js +6 -9
  69. package/lib/wsl-doctor-command.js +36 -80
  70. package/lib/wsl-filesystem.d.ts +9 -4
  71. package/lib/wsl-filesystem.js +26 -10
  72. package/lib/wsl-shell.d.ts +27 -17
  73. package/lib/wsl-shell.js +83 -24
  74. package/lib/wsl.d.ts +3 -1
  75. package/lib/wsl.js +82 -7
  76. package/package.json +5 -4
  77. package/scripts/bootstrap.sh +36 -12
  78. package/scripts/doctor.mjs +514 -201
package/client.js CHANGED
@@ -51,13 +51,248 @@
51
51
  * (`wsl-env-client-host`, mounting the no-op root export) is what puts this
52
52
  * package on the web bundle list.
53
53
  */
54
- window.__ModuleLoader__.load({
54
+
55
+ // The browser surface the client program touches, declared here rather than
56
+ // via a DOM lib: the shared type gate runs with Node's globals, and a global
57
+ // `window`/`document` there would let Node-side typos pass. One `globalThis`
58
+ // sample, cast once, mirrors the harness loader's own delivery: both a browser
59
+ // and the VM the client tests load this file in expose `window` and `document`
60
+ // as properties of that same object.
61
+ /** @typedef {object} ClientStorage
62
+ * @property {(key: string) => string | null} getItem
63
+ * @property {(key: string, value: string) => void} setItem
64
+ */
65
+ /** @typedef {{ key?: string, shiftKey?: boolean, preventDefault?: () => void }} ClientKeyEvent */
66
+ /** @typedef {{ target?: unknown, currentTarget?: unknown }} ClientMouseEvent */
67
+ /** @typedef {{ focus?: () => void, querySelector?: (selector: string) => ClientElement | null, querySelectorAll?: (selector: string) => ArrayLike<ClientElement> }} ClientElement */
68
+ /** @typedef {{ load: (module: { id: string, factory: (require: (name: string) => unknown) => unknown }) => void }} ClientModuleLoader */
69
+ /**
70
+ * @typedef {object} ClientWindow
71
+ * @property {ClientModuleLoader} __ModuleLoader__
72
+ * @property {ClientStorage} sessionStorage
73
+ */
74
+ /**
75
+ * @typedef {object} ClientDocument
76
+ * @property {ClientElement | null} [activeElement]
77
+ * @property {(type: string, listener: (event: ClientKeyEvent) => void) => void} addEventListener
78
+ * @property {(type: string, listener: (event: ClientKeyEvent) => void) => void} removeEventListener
79
+ */
80
+ /**
81
+ * @typedef {object} ClientPlatform
82
+ * @property {ClientWindow} window
83
+ * @property {ClientDocument} document
84
+ */
85
+ /**
86
+ * The slice of React's API the panel uses. The harness hands the real React
87
+ * through the loader's `require`; no typings ship for it, so this is the
88
+ * contract the client is written against.
89
+ * @typedef {object} ReactApi
90
+ * @property {(type: unknown, props?: Record<string, unknown> | null, ...children: unknown[]) => unknown} createElement
91
+ * @property {<T>(initial: T | (() => T)) => [T, (next: T | ((prev: T) => T)) => void]} useState
92
+ * @property {(effect: () => void | (() => void), deps?: readonly unknown[]) => void} useEffect
93
+ * @property {<T>(initial: T) => { current: T }} useRef
94
+ */
95
+ const platform = /** @type {ClientPlatform} */ (/** @type {unknown} */ (globalThis));
96
+
97
+ // ── The plugin's wire and state shapes ─────────────────────────────────────
98
+ // The routes' answers mirror the built modules, so the types come from them;
99
+ // the panel's own state shapes are spelled out where the client adds to them.
100
+
101
+ /** @typedef {import("./lib/status.js").DistroStatusView} DistroStatusView */
102
+ /** @typedef {import("./lib/status.js").StatusCheck} StatusCheck */
103
+ /** @typedef {import("./lib/status.js").StatusRepair} StatusRepair */
104
+ /** @typedef {import("./lib/status.js").StatusWarning} StatusWarning */
105
+ /** @typedef {import("./lib/plugin-update.js").PluginVersionView} PluginVersionView */
106
+ /** @typedef {import("./lib/plugin-update.js").PluginUpdateReply} PluginUpdateReply */
107
+ /** @typedef {import("./lib/plugin-update.js").ChangeApplication} ChangeApplication */
108
+ /** @typedef {import("./lib/update-check.js").ListedVersion} ListedVersion */
109
+
110
+ /**
111
+ * The status route's answers. The `GET` list answer carries the stored rows
112
+ * under `cached`, while a single-check answer carries a boolean there, so the
113
+ * field is the union of both shapes.
114
+ * @typedef {object} ClientStatusReply
115
+ * @property {string[]} [distros]
116
+ * @property {string[]} [running]
117
+ * @property {DistroStatusView[] | boolean} [cached]
118
+ * @property {number} [cleared]
119
+ * @property {string} [distro]
120
+ * @property {DistroStatusView["verdict"]} [verdict]
121
+ * @property {boolean} [full]
122
+ * @property {boolean} [repaired]
123
+ * @property {StatusRepair[]} [repairs]
124
+ * @property {string[]} [repairable]
125
+ * @property {number} [checkedAt]
126
+ * @property {DistroStatusView["failures"]} [failures]
127
+ * @property {StatusWarning[]} [warnings]
128
+ * @property {DistroStatusView["counts"]} [counts]
129
+ * @property {DistroStatusView["sections"]} [sections]
130
+ * @property {StatusCheck[]} [checks]
131
+ * @property {number} [notRun]
132
+ * @property {string[]} [blockers]
133
+ * @property {DistroStatusView["source"]} [source]
134
+ * @property {string} [error]
135
+ */
136
+ /**
137
+ * One distro row as the panel keeps it: the last answer plus the panel's own
138
+ * phase. Every verdict field is optional because a row exists before any
139
+ * answer arrives (`{ phase: "checking" }`).
140
+ * @typedef {object} ClientCheckRow
141
+ * @property {string} [phase]
142
+ * @property {string} [distro]
143
+ * @property {DistroStatusView["verdict"]} [verdict]
144
+ * @property {boolean} [full]
145
+ * @property {boolean} [repaired]
146
+ * @property {StatusRepair[]} [repairs]
147
+ * @property {string[]} [repairable]
148
+ * @property {number} [checkedAt]
149
+ * @property {DistroStatusView["failures"]} [failures]
150
+ * @property {StatusWarning[]} [warnings]
151
+ * @property {Partial<DistroStatusView["counts"]>} [counts]
152
+ * @property {DistroStatusView["sections"]} [sections]
153
+ * @property {StatusCheck[]} [checks]
154
+ * @property {number} [notRun]
155
+ * @property {string[]} [blockers]
156
+ * @property {DistroStatusView["source"]} [source]
157
+ * @property {DistroStatusView[] | boolean} [cached]
158
+ * @property {string} [error]
159
+ */
160
+ /** The panel's row table, keyed by distro name. @typedef {Record<string, ClientCheckRow | undefined>} ClientCheckTable */
161
+ /** One finding row: a failing check or a warning. @typedef {{ id: string, detail?: string, remedy?: string }} ClientFinding */
162
+ /** One transient panel notice. @typedef {{ kind: "ok" | "info" | "warn" | "error", text: string }} ClientNotice */
163
+ /** The access record the reminder reads. @typedef {{ target: string, paths: string[] }} ClientAccess */
164
+ /** The access read's answer: the record, or why it is unavailable. @typedef {{ ok: true, paths: string[], preset: string } | { ok: false, message?: string }} ClientAccessRead */
165
+
166
+ /**
167
+ * The plugin route's answers: the version view on `GET`, the host's upgrade
168
+ * outcome on `POST`.
169
+ * @typedef {object} ClientPluginReply
170
+ * @property {string} [installed]
171
+ * @property {string} [running]
172
+ * @property {PluginVersionView["status"]} [status]
173
+ * @property {number} [checkedAt]
174
+ * @property {boolean} [cached]
175
+ * @property {boolean} [updateSupported]
176
+ * @property {boolean} [canUpdate]
177
+ * @property {string | null} [registry]
178
+ * @property {ListedVersion} [latest]
179
+ * @property {string} [problem]
180
+ * @property {string} [reason]
181
+ * @property {boolean} [updated]
182
+ * @property {ChangeApplication} [application]
183
+ * @property {string} [from]
184
+ * @property {string} [to]
185
+ * @property {PluginUpdateReply["step"]} [step]
186
+ * @property {string} [restartReason]
187
+ * @property {boolean} [restored]
188
+ * @property {{ code?: string, diagnostic?: string }} [error]
189
+ * @property {readonly string[]} [pendingBuilds]
190
+ * @property {{ code?: string, diagnostic?: string }} [restoreError]
191
+ */
192
+ /**
193
+ * The version card's state: the last answer plus the panel's own phase. The
194
+ * panel's `error` is the display string a failed request stores, which is why
195
+ * the route's structured `error` is also allowed here.
196
+ * @typedef {object} ClientPluginState
197
+ * @property {string} [phase]
198
+ * @property {string} [installed]
199
+ * @property {string} [running]
200
+ * @property {PluginVersionView["status"]} [status]
201
+ * @property {number} [checkedAt]
202
+ * @property {boolean} [cached]
203
+ * @property {boolean} [updateSupported]
204
+ * @property {boolean} [canUpdate]
205
+ * @property {string | null} [registry]
206
+ * @property {ListedVersion | null} [latest]
207
+ * @property {string} [problem]
208
+ * @property {string} [reason]
209
+ * @property {string | { code?: string, diagnostic?: string }} [error]
210
+ * @property {ClientPluginReply} [upgrade]
211
+ */
212
+
213
+ // ── The client services the panel consumes ────────────────────────────────
214
+ // The harness's browser services have no declarations visible here, so each
215
+ // slice is spelled structurally for exactly what the client reads.
216
+
217
+ /** @typedef {{ get: (name: string) => unknown }} ClientServiceHost */
218
+ /** @typedef {{ message?: string }} ClientServiceError */
219
+ /**
220
+ * @typedef {object} ClientSettingsNamespace
221
+ * @property {string} ns
222
+ * @property {number} revision
223
+ * @property {Record<string, unknown>} [value]
224
+ */
225
+ /**
226
+ * @typedef {object} ClientSettingsReply
227
+ * @property {boolean} [ok]
228
+ * @property {{ writable?: boolean, namespaces?: ClientSettingsNamespace[] }} [value]
229
+ * @property {ClientServiceError} [error]
230
+ */
231
+ /**
232
+ * @typedef {object} ClientSettingsService
233
+ * @property {() => Promise<ClientSettingsReply>} describe
234
+ * @property {(ns: string, patch: Record<string, unknown>, revision: number) => Promise<{ ok?: boolean, error?: ClientServiceError }>} update
235
+ */
236
+ /** A preset row from the agent-preset roster. @typedef {{ id?: string, isDefault?: boolean }} ClientPresetEntry */
237
+ /**
238
+ * @typedef {object} ClientPresetService
239
+ * @property {(sessionId: string, presetId: string) => Promise<{ ok?: boolean, error?: ClientServiceError }>} select
240
+ * @property {() => Promise<{ ok?: boolean, error?: ClientServiceError, value?: { presets?: ClientPresetEntry[] } }>} list
241
+ */
242
+ /** One session summary as the list hook exposes it. @typedef {{ cwd?: string, parentId?: string, origin?: string, blank?: boolean }} ClientSessionSummary */
243
+ /** @typedef {{ byId: Record<string, ClientSessionSummary> }} ClientSessionSnapshot */
244
+ /** @typedef {{ list: { getSnapshot: () => ClientSessionSnapshot } }} ClientSessionsService */
245
+ /** One workspace catalog entry. @typedef {{ workspaceId: string, path: string, sessionIds: string[] }} ClientWorkspaceEntry */
246
+ /** @typedef {{ phase?: string, items: ClientWorkspaceEntry[] }} ClientWorkspaceSnapshot */
247
+ /**
248
+ * @typedef {object} ClientWorkspacesService
249
+ * @property {{ getSnapshot: () => ClientWorkspaceSnapshot, subscribe: (listener: () => void) => (() => void) }} list
250
+ */
251
+ /** The slot's session-list and projection hooks. @typedef {<T>(selector: (state: ClientSessionSnapshot) => T) => T} UseSessions */
252
+ /** @typedef {(name: string) => unknown} UseProjection */
253
+ /** The props every component this client registers receives. @typedef {{ ctx: ClientContext }} ClientPanelProps */
254
+ /** The composer/header reminder components' props. @typedef {{ ctx: ClientContext, sessionId: string, useSessions: UseSessions, useProjection: UseProjection }} ClientReminderProps */
255
+ /** Props of one slot's renderer. @typedef {{ size?: number, active?: boolean, sessionId?: string, useSessions?: UseSessions, useProjection?: UseProjection }} ClientSlotProps */
256
+ /** @typedef {{ label: string, tone: "ready" | "blocked" | "error" | "idle", title?: string }} ClientPillProps */
257
+ /** @typedef {{ label: string, onClick?: () => void, primary?: boolean, disabled?: boolean, small?: boolean }} ClientBtnProps */
258
+ /** @typedef {{ title?: unknown, actions?: unknown, children?: unknown }} ClientCardProps */
259
+ /**
260
+ * @typedef {object} ClientSlots
261
+ * @property {(name: string, install: () => Generator<unknown, void, unknown>) => void} inject
262
+ * @property {(spec: Record<string, unknown>, render: (props: ClientSlotProps) => unknown) => unknown} register
263
+ */
264
+ /** One session-header menu item the client offers. @typedef {{ id: string, label: string, failureLabel: string, run: () => Promise<void> }} ClientMenuItem */
265
+ /**
266
+ * @typedef {object} ClientMenuDefinition
267
+ * @property {string} id
268
+ * @property {string} target
269
+ * @property {number} order
270
+ * @property {() => unknown[]} observe
271
+ * @property {(context: { sessionId: string }) => ClientMenuItem[]} resolve
272
+ */
273
+ /** @typedef {{ register: (definition: ClientMenuDefinition) => unknown }} ClientContextMenuRegistry */
274
+ /** The scope a service injection hands its callback. @typedef {{ get: (name: string) => unknown, effect: (callback: () => unknown, label?: string) => unknown, contextMenus: ClientContextMenuRegistry, sessions: ClientSessionsService }} ClientScope */
275
+ /** @typedef {ClientServiceHost & { slots: ClientSlots, inject: (dependencies: readonly string[], callback: (scope: ClientScope) => void) => unknown }} ClientContext */
276
+ /** One pending access-mode prompt. @typedef {{ workspaceId: string, path: string }} ClientPromptRequest */
277
+ /**
278
+ * The prompt slot shared by the watcher and the overlay occupant.
279
+ * @typedef {object} ClientAccessPrompt
280
+ * @property {ClientPromptRequest | null} value
281
+ * @property {Set<() => void>} listeners
282
+ * @property {() => ClientPromptRequest | null} get
283
+ * @property {(next: ClientPromptRequest | null) => void} set
284
+ * @property {(listener: () => void) => () => void} subscribe
285
+ */
286
+ /** The browser services this client reads, keyed by their registered names. @typedef {{ "remote.settings": ClientSettingsService, "remote.agentPresets": ClientPresetService, sessions: ClientSessionsService, workspaces: ClientWorkspacesService }} ClientServiceMap */
287
+
288
+ platform.window.__ModuleLoader__.load({
55
289
  id: "dsh-plugin-wsl-env",
56
290
  factory(require) {
57
- const React = require("react");
291
+ const React = /** @type {ReactApi} */ (require("react"));
58
292
  const h = React.createElement;
59
293
  const useState = React.useState;
60
294
  const useEffect = React.useEffect;
295
+ const useRef = React.useRef;
61
296
 
62
297
  /** The plugin's status route (checks on GET, repair on POST, clear on DELETE); the row registers this exact path. */
63
298
  const STATUS_PATH = "/api/wsl-env/status";
@@ -73,52 +308,79 @@ window.__ModuleLoader__.load({
73
308
  const WINDOWS_FIELD = "windowsWorkspaces";
74
309
  const UNC_RE = /^\\\\wsl(?:\.localhost|\$)\\([^\\]+)(?:\\([\s\S]*))?$/i;
75
310
 
311
+ /**
312
+ * Resolve one browser service by its registered name.
313
+ * @template {keyof ClientServiceMap} Name
314
+ * @param {ClientServiceHost} ctx - client root context.
315
+ * @param {Name} name - the service's registered name.
316
+ * @returns {ClientServiceMap[Name] | undefined} the service, or undefined when the host provides none.
317
+ */
76
318
  const service = (ctx, name) => {
77
319
  try {
78
- return ctx.get(name);
320
+ return /** @type {ClientServiceMap[Name] | undefined} */ (ctx.get(name));
79
321
  } catch (error) {
80
322
  return undefined;
81
323
  }
82
324
  };
83
325
 
84
- const messageOf = (error) => (error && typeof error.message === "string" ? error.message : String(error));
326
+ /**
327
+ * One error's message, whatever value was thrown.
328
+ * @param {unknown} error - the thrown value.
329
+ * @returns {string} its message, or the value stringified.
330
+ */
331
+ const messageOf = (error) => (error && typeof (/** @type {ClientServiceError} */ (error)).message === "string"
332
+ ? /** @type {{ message: string }} */ (error).message
333
+ : String(error));
85
334
 
335
+ /** @type {(value: unknown) => value is string} */
86
336
  const isWslUnc = (value) => typeof value === "string" && UNC_RE.test(value);
87
337
 
338
+ /**
339
+ * @param {string} value - a workspace path.
340
+ * @returns {string} the comparable form: separators unified, trailing ones dropped, lowercased.
341
+ */
88
342
  const normalize = (value) => value.trim().replace(/[\\/]+$/, "").replace(/\//g, "\\").toLowerCase();
89
343
 
344
+ /**
345
+ * @param {unknown} a - one path.
346
+ * @param {unknown} b - the other path.
347
+ * @returns {boolean} whether both are strings naming the same path.
348
+ */
90
349
  const samePath = (a, b) => typeof a === "string" && typeof b === "string" && normalize(a) === normalize(b);
91
350
 
92
351
  /**
93
352
  * Fetch one exact route and decode its JSON answer.
94
- * @param path - the route's absolute path.
95
- * @param query - the query string, including `?`, or empty.
96
- * @param method - `GET` to read, `POST` to act, `DELETE` to clear.
97
- * @returns the decoded body.
98
- * @throws with the route's own error message.
353
+ * @template Reply
354
+ * @param {string} path - the route's absolute path.
355
+ * @param {string} query - the query string, including `?`, or empty.
356
+ * @param {string} [method] - `GET` to read, `POST` to act, `DELETE` to clear.
357
+ * @returns {Promise<Reply>} the decoded body.
358
+ * @throws with the route's own error message. The status routes answer a
359
+ * string `error`; the plugin route answers a structured one, which this
360
+ * transport has never rendered as anything but its string form.
99
361
  */
100
362
  const jsonRequest = async (path, query, method = "GET") => {
101
363
  const answer = await fetch(path + (query ?? ""), { method });
102
- const body = await answer.json().catch(() => ({}));
103
- if (!answer.ok) throw new Error(body.error ?? `接口返回 ${answer.status}`);
364
+ const body = /** @type {Reply} */ (await answer.json().catch(() => ({})));
365
+ if (!answer.ok) throw new Error(/** @type {{ error?: string }} */ (body).error ?? `接口返回 ${answer.status}`);
104
366
  return body;
105
367
  };
106
368
 
107
369
  /**
108
370
  * The doctor route: list/quick/full read-only checks on GET, the explicit
109
371
  * plugin-owned repair on POST, and clearing stored results on DELETE.
110
- * @param query - the query string, including `?`, or empty.
111
- * @param method - `GET` for a check, `POST` for repair,
372
+ * @param {string} query - the query string, including `?`, or empty.
373
+ * @param {string} [method] - `GET` for a check, `POST` for repair,
112
374
  * `DELETE` to clear one distro's result (named by `distro`) or all.
113
- * @returns the decoded body.
375
+ * @returns {Promise<ClientStatusReply>} the decoded body.
114
376
  */
115
377
  const statusRequest = (query, method = "GET") => jsonRequest(STATUS_PATH, query, method);
116
378
 
117
379
  /**
118
380
  * The plugin version route: read on GET, confirmed one-click upgrade on POST.
119
- * @param query - the query string, including `?`, or empty.
120
- * @param method - `GET` for a check, `POST` for the upgrade.
121
- * @returns the decoded body.
381
+ * @param {string} query - the query string, including `?`, or empty.
382
+ * @param {string} [method] - `GET` for a check, `POST` for the upgrade.
383
+ * @returns {Promise<ClientPluginReply>} the decoded body.
122
384
  */
123
385
  const pluginRequest = (query, method = "GET") => jsonRequest(PLUGIN_UPDATE_PATH, query, method);
124
386
 
@@ -130,8 +392,8 @@ window.__ModuleLoader__.load({
130
392
 
131
393
  /**
132
394
  * Find the auto-preset settings view and its Windows-access paths.
133
- * @param describe - the `settings.describe` answer.
134
- * @returns the namespace view and the paths it currently carries.
395
+ * @param {ClientSettingsReply} describe - the `settings.describe` answer.
396
+ * @returns {{ entry: ClientSettingsNamespace, paths: string[], preset: string } | undefined} the namespace view and the paths it currently carries.
135
397
  */
136
398
  const accessViewOf = (describe) => {
137
399
  if (!describe || describe.ok !== true) return undefined;
@@ -142,17 +404,17 @@ window.__ModuleLoader__.load({
142
404
  const entry = value.namespaces.find((row) => row
143
405
  && (row.ns === AUTO_PRESET_ENTRY || row.ns.endsWith("/" + AUTO_PRESET_ENTRY)));
144
406
  if (entry === undefined) return undefined;
145
- const configured = entry.value && Array.isArray(entry.value[WINDOWS_FIELD]) ? entry.value[WINDOWS_FIELD] : [];
407
+ const configured = /** @type {unknown[]} */ (entry.value && Array.isArray(entry.value[WINDOWS_FIELD]) ? entry.value[WINDOWS_FIELD] : []);
146
408
  // The row's `preset` field is the preset auto-preset adopts for distro
147
409
  // workspaces; the reminder compares the session's projection against it.
148
410
  const preset = entry.value && typeof entry.value.preset === "string" ? entry.value.preset : "";
149
- return { entry, paths: configured.filter((path) => typeof path === "string"), preset };
411
+ return { entry, paths: /** @type {string[]} */ (configured.filter((path) => typeof path === "string")), preset };
150
412
  };
151
413
 
152
414
  /**
153
415
  * Read the current Windows-access paths and the target preset.
154
- * @param ctx - client root context.
155
- * @returns `{ ok: true, paths, preset }`, or the reason the record is unavailable.
416
+ * @param {ClientServiceHost} ctx - client root context.
417
+ * @returns {Promise<ClientAccessRead>} `{ ok: true, paths, preset }`, or the reason the record is unavailable.
156
418
  */
157
419
  const readAccess = async (ctx) => {
158
420
  const settings = service(ctx, "remote.settings");
@@ -165,9 +427,9 @@ window.__ModuleLoader__.load({
165
427
 
166
428
  /**
167
429
  * Persist a complete Windows-access list.
168
- * @param ctx - client root context.
169
- * @param paths - the new list.
170
- * @returns `undefined` on success, or the failure message.
430
+ * @param {ClientServiceHost} ctx - client root context.
431
+ * @param {string[]} paths - the new list.
432
+ * @returns {Promise<string | undefined>} `undefined` on success, or the failure message.
171
433
  */
172
434
  const writeAccess = async (ctx, paths) => {
173
435
  const settings = service(ctx, "remote.settings");
@@ -196,9 +458,9 @@ window.__ModuleLoader__.load({
196
458
  /**
197
459
  * Whether a workspace is one of the recorded Windows-access directories or
198
460
  * below one (whole-segment, case-insensitive, like the host's comparison).
199
- * @param cwd - the session workspace.
200
- * @param paths - the configured directories.
201
- * @returns true when the workspace opted out of the distro environment.
461
+ * @param {string} cwd - the session workspace.
462
+ * @param {readonly string[]} paths - the configured directories.
463
+ * @returns {boolean} true when the workspace opted out of the distro environment.
202
464
  */
203
465
  const isWindowsAccessPath = (cwd, paths) => {
204
466
  const target = normalize(cwd);
@@ -211,8 +473,8 @@ window.__ModuleLoader__.load({
211
473
 
212
474
  /**
213
475
  * The distro a UNC workspace names.
214
- * @param cwd - the session workspace.
215
- * @returns the distro name, or undefined for a non-UNC path.
476
+ * @param {unknown} cwd - the session workspace.
477
+ * @returns {string | undefined} the distro name, or undefined for a non-UNC path.
216
478
  */
217
479
  const distroOf = (cwd) => {
218
480
  const match = typeof cwd === "string" ? UNC_RE.exec(cwd) : null;
@@ -223,9 +485,8 @@ window.__ModuleLoader__.load({
223
485
  * The reminder state for one session, or null when its environment is right.
224
486
  * A missing projection and a matching preset both mean "nothing to say": the
225
487
  * banner never guesses an environment.
226
- * @param input - the session workspace, its projected preset, the configured
227
- * target preset, the Windows-access list, and subagent membership.
228
- * @returns `{ target, windowsAccess }` for a distro workspace on a non-WSL preset.
488
+ * @param {{ cwd?: string, preset?: unknown, target: string, paths?: string[], subagent?: boolean }} input - the session workspace, its projected preset, the configured target preset, the Windows-access list, and subagent membership.
489
+ * @returns {{ target: string, windowsAccess: boolean } | null} `{ target, windowsAccess }` for a distro workspace on a non-WSL preset.
229
490
  */
230
491
  const hostModeOf = ({ cwd, preset, target, paths, subagent }) => {
231
492
  if (subagent === true || !isWslUnc(cwd)) return null;
@@ -233,10 +494,14 @@ window.__ModuleLoader__.load({
233
494
  return { target, windowsAccess: isWindowsAccessPath(cwd, paths ?? []) };
234
495
  };
235
496
 
236
- /** The sessionStorage key that collapses the warning for one session. */
497
+ /**
498
+ * The sessionStorage key that collapses the warning for one session.
499
+ * @param {string} sessionId - the session the warning belongs to.
500
+ * @returns {string} the storage key.
501
+ */
237
502
  const dismissedKey = (sessionId) => "wsl-env.access-mode.dismissed:" + String(sessionId);
238
503
 
239
- /** Reminder components that must re-read the collapse fact when it changes. */
504
+ /** Reminder components that must re-read the collapse fact when it changes. @type {Set<() => void>} */
240
505
  const dismissedListeners = new Set();
241
506
 
242
507
  /**
@@ -252,12 +517,12 @@ window.__ModuleLoader__.load({
252
517
 
253
518
  /**
254
519
  * Whether the operator collapsed the reminder for this session.
255
- * @param sessionId - the session to ask about.
256
- * @returns true when the warning was dismissed in this browser session.
520
+ * @param {string} sessionId - the session to ask about.
521
+ * @returns {boolean} true when the warning was dismissed in this browser session.
257
522
  */
258
523
  const readDismissed = (sessionId) => {
259
524
  try {
260
- return window.sessionStorage.getItem(dismissedKey(sessionId)) === "1";
525
+ return platform.window.sessionStorage.getItem(dismissedKey(sessionId)) === "1";
261
526
  } catch {
262
527
  return false;
263
528
  }
@@ -265,11 +530,11 @@ window.__ModuleLoader__.load({
265
530
 
266
531
  /**
267
532
  * Collapse the reminder for this session only; a new session asks again.
268
- * @param sessionId - the session to collapse.
533
+ * @param {string} sessionId - the session to collapse.
269
534
  */
270
535
  const rememberDismissed = (sessionId) => {
271
536
  try {
272
- window.sessionStorage.setItem(dismissedKey(sessionId), "1");
537
+ platform.window.sessionStorage.setItem(dismissedKey(sessionId), "1");
273
538
  } catch {
274
539
  /* a browser without storage keeps the reminder visible */
275
540
  }
@@ -278,17 +543,17 @@ window.__ModuleLoader__.load({
278
543
 
279
544
  /**
280
545
  * Follow one session's host-mode state.
281
- * @param ctx - client root context.
282
- * @param sessionId - the active session.
283
- * @param useSessions - the slot's session-list hook.
284
- * @param useProjection - the slot's projection hook.
285
- * @returns the session summary and the reminder state (null while loading or correct).
546
+ * @param {ClientServiceHost} ctx - client root context.
547
+ * @param {string} sessionId - the active session.
548
+ * @param {UseSessions} useSessions - the slot's session-list hook.
549
+ * @param {UseProjection} useProjection - the slot's projection hook.
550
+ * @returns {{ summary: ClientSessionSummary | undefined, state: { target: string, windowsAccess: boolean } | null }} the session summary and the reminder state (null while loading or correct).
286
551
  */
287
552
  const useHostMode = (ctx, sessionId, useSessions, useProjection) => {
288
553
  const summary = useSessions((state) => state.byId[sessionId]);
289
554
  const preset = useProjection("agentPreset");
290
555
  const cwd = summary?.cwd;
291
- const [access, setAccess] = useState(null);
556
+ const [access, setAccess] = useState(/** @type {ClientAccess | null} */ (null));
292
557
 
293
558
  useEffect(() => {
294
559
  let live = true;
@@ -299,6 +564,7 @@ window.__ModuleLoader__.load({
299
564
  return () => { live = false; };
300
565
  }
301
566
  void (async () => {
567
+ /** @type {ClientAccessRead} */
302
568
  let answer;
303
569
  try {
304
570
  answer = await readAccess(ctx);
@@ -333,15 +599,15 @@ window.__ModuleLoader__.load({
333
599
  * host environment. The primary action is the one that works for this
334
600
  * session: a blank session can be switched in place; a session that already
335
601
  * started a turn keeps its history, so the durable fix is the access record.
336
- * @param props - slot standard props plus the client root context.
337
- * @returns the warning bar, or null when the environment is right or collapsed.
602
+ * @param {ClientReminderProps} props - slot standard props plus the client root context.
603
+ * @returns {unknown} the warning bar, or null when the environment is right or collapsed.
338
604
  */
339
605
  function AccessModeBanner({ ctx, sessionId, useSessions, useProjection }) {
340
606
  const { summary, state } = useHostMode(ctx, sessionId, useSessions, useProjection);
341
607
  const [dismissed, setDismissed] = useState(() => readDismissed(sessionId));
342
608
  const [removed, setRemoved] = useState(false);
343
609
  const [busy, setBusy] = useState(false);
344
- const [notice, setNotice] = useState(null);
610
+ const [notice, setNotice] = useState(/** @type {ClientNotice | null} */ (null));
345
611
 
346
612
  useEffect(() => {
347
613
  const sync = () => { setDismissed(readDismissed(sessionId)); };
@@ -439,8 +705,8 @@ window.__ModuleLoader__.load({
439
705
 
440
706
  /**
441
707
  * The quiet session-header marker that survives collapsing the banner.
442
- * @param props - slot standard props plus the client root context.
443
- * @returns the badge, or null when the environment is right or the banner shows.
708
+ * @param {ClientReminderProps} props - slot standard props plus the client root context.
709
+ * @returns {unknown} the badge, or null when the environment is right or the banner shows.
444
710
  */
445
711
  function AccessModeBadge({ ctx, sessionId, useSessions, useProjection }) {
446
712
  const { summary, state } = useHostMode(ctx, sessionId, useSessions, useProjection);
@@ -463,9 +729,9 @@ window.__ModuleLoader__.load({
463
729
 
464
730
  /**
465
731
  * Switch one workspace's still-blank sessions to the host default preset.
466
- * @param ctx - client root context.
467
- * @param workspaceId - the workspace whose sessions to revisit.
468
- * @returns the first failure message, or undefined when every eligible session moved.
732
+ * @param {ClientServiceHost} ctx - client root context.
733
+ * @param {string} workspaceId - the workspace whose sessions to revisit.
734
+ * @returns {Promise<string | undefined>} the first failure message, or undefined when every eligible session moved.
469
735
  */
470
736
  const switchWorkspaceSessions = async (ctx, workspaceId) => {
471
737
  const presets = service(ctx, "remote.agentPresets");
@@ -479,6 +745,7 @@ window.__ModuleLoader__.load({
479
745
  if (fallback === undefined || typeof fallback.id !== "string") return "找不到宿主默认 preset";
480
746
  const workspace = workspaces.list.getSnapshot().items.find((item) => item.workspaceId === workspaceId);
481
747
  if (workspace === undefined) return undefined;
748
+ /** @type {string | undefined} */
482
749
  let failure;
483
750
  for (const sessionId of workspace.sessionIds) {
484
751
  const summary = sessions.list.getSnapshot().byId[sessionId];
@@ -629,7 +896,7 @@ window.__ModuleLoader__.load({
629
896
  checkRemedy: { opacity: 0.6 },
630
897
  };
631
898
 
632
- /** Verdict colors: ready / blocked / error / idle. */
899
+ /** Verdict colors: ready / blocked / error / idle. @type {Record<"ready" | "blocked" | "error" | "idle", { fg: string, bg: string }>} */
633
900
  const verdictColors = {
634
901
  ready: { fg: "#5ecf86", bg: "rgba(94, 207, 134, 0.14)" },
635
902
  blocked: { fg: "#ff8f6b", bg: "rgba(255, 143, 107, 0.14)" },
@@ -639,8 +906,8 @@ window.__ModuleLoader__.load({
639
906
 
640
907
  /**
641
908
  * One status pill.
642
- * @param props - label, tone, and optional tooltip.
643
- * @returns the pill element.
909
+ * @param {ClientPillProps} props - label, tone, and optional tooltip.
910
+ * @returns {unknown} the pill element.
644
911
  */
645
912
  function Pill({ label, tone, title }) {
646
913
  const color = verdictColors[tone] ?? verdictColors.idle;
@@ -664,8 +931,8 @@ window.__ModuleLoader__.load({
664
931
 
665
932
  /**
666
933
  * One neutral button; the caller supplies emphasis.
667
- * @param props - label, click handler, and optional emphasis/disabled.
668
- * @returns the button element.
934
+ * @param {ClientBtnProps} props - label, click handler, and optional emphasis/disabled.
935
+ * @returns {unknown} the button element.
669
936
  */
670
937
  function Btn({ label, onClick, primary, disabled, small }) {
671
938
  return h(
@@ -692,8 +959,8 @@ window.__ModuleLoader__.load({
692
959
 
693
960
  /**
694
961
  * The sidebar glyph: a terminal window.
695
- * @param props - requested size and selection state.
696
- * @returns the icon element.
962
+ * @param {{ size?: number, active?: boolean }} props - requested size and selection state.
963
+ * @returns {unknown} the icon element.
697
964
  */
698
965
  function WslIcon({ size, active }) {
699
966
  const edge = typeof size === "number" ? size : 16;
@@ -719,8 +986,8 @@ window.__ModuleLoader__.load({
719
986
 
720
987
  /**
721
988
  * A titled card.
722
- * @param props - title, optional head actions, and children.
723
- * @returns the card element.
989
+ * @param {ClientCardProps} props - title, optional head actions, and children.
990
+ * @returns {unknown} the card element.
724
991
  */
725
992
  function Card({ title, actions, children }) {
726
993
  return h(
@@ -733,8 +1000,8 @@ window.__ModuleLoader__.load({
733
1000
 
734
1001
  /**
735
1002
  * The pill for one distro's check state.
736
- * @param props - the cached check state, if any.
737
- * @returns the pill element.
1003
+ * @param {{ state?: ClientCheckRow }} props - the cached check state, if any.
1004
+ * @returns {unknown} the pill element.
738
1005
  */
739
1006
  function CheckPill({ state }) {
740
1007
  if (state === undefined || state.phase === undefined) return h(Pill, { label: "未检查", tone: "idle" });
@@ -760,9 +1027,8 @@ window.__ModuleLoader__.load({
760
1027
 
761
1028
  /**
762
1029
  * A numbered list of doctor findings.
763
- * @param props - heading, findings, whether they block, and the ids the
764
- * explicit repair can repair.
765
- * @returns the list, or null when there is nothing to show.
1030
+ * @param {{ heading: string, items?: ClientFinding[], severity?: string, repairable?: string[] }} props - heading, findings, whether they block, and the ids the explicit repair can repair.
1031
+ * @returns {unknown} the list, or null when there is nothing to show.
766
1032
  */
767
1033
  function IssueList({ heading, items, severity, repairable }) {
768
1034
  if (!Array.isArray(items) || items.length === 0) return null;
@@ -790,8 +1056,8 @@ window.__ModuleLoader__.load({
790
1056
 
791
1057
  /**
792
1058
  * The repair action's rows: what the doctor did, with its status mark.
793
- * @param props - the `fix.*` rows the repair answered with.
794
- * @returns the list, or null when the run has no repair rows.
1059
+ * @param {{ items?: StatusRepair[] }} props - the `fix.*` rows the repair answered with.
1060
+ * @returns {unknown} the list, or null when the run has no repair rows.
795
1061
  */
796
1062
  function RepairList({ items }) {
797
1063
  if (!Array.isArray(items) || items.length === 0) return null;
@@ -825,8 +1091,8 @@ window.__ModuleLoader__.load({
825
1091
  * shows the same rows the failures came from, so nothing is hidden. The
826
1092
  * catalog rows a quick run never executed are counted in one line instead
827
1093
  * of listed as fake "not run" checks.
828
- * @param props - the cached check state.
829
- * @returns the toggle and, open, the grouped list.
1094
+ * @param {{ state: ClientCheckRow }} props - the cached check state.
1095
+ * @returns {unknown} the toggle and, open, the grouped list.
830
1096
  */
831
1097
  function CheckDetails({ state }) {
832
1098
  const [open, setOpen] = useState(false);
@@ -838,7 +1104,15 @@ window.__ModuleLoader__.load({
838
1104
  .filter((group) => group.rows.length > 0);
839
1105
  const other = checks.filter((row) => !order.includes(row.section));
840
1106
  if (other.length > 0) groups.push({ section: "other", rows: other });
1107
+ /**
1108
+ * @param {string} status - the doctor's check status.
1109
+ * @returns {string} the status mark.
1110
+ */
841
1111
  const mark = (status) => status === "ok" ? "✓" : status === "fail" ? "✗" : status === "warn" ? "!" : status === "unknown" ? "?" : status === "skipped" ? "-" : "i";
1112
+ /**
1113
+ * @param {string} status - the doctor's check status.
1114
+ * @returns {Record<string, unknown>} the mark's color for that status.
1115
+ */
842
1116
  const tone = (status) => status === "ok" ? styles.countOk : status === "fail" ? styles.countFail : status === "warn" || status === "unknown" ? styles.countWarn : styles.summaryMuted;
843
1117
  return h(
844
1118
  "div",
@@ -876,8 +1150,8 @@ window.__ModuleLoader__.load({
876
1150
 
877
1151
  /**
878
1152
  * Format a check timestamp with a relative hint.
879
- * @param at - epoch milliseconds.
880
- * @returns the display label.
1153
+ * @param {number} at - epoch milliseconds.
1154
+ * @returns {string} the display label.
881
1155
  */
882
1156
  const checkedLabel = (at) => {
883
1157
  const date = new Date(at);
@@ -896,8 +1170,8 @@ window.__ModuleLoader__.load({
896
1170
 
897
1171
  /**
898
1172
  * The result's structure: when the check ran and how its rows landed.
899
- * @param props - the cached check state.
900
- * @returns the summary block.
1173
+ * @param {{ state: ClientCheckRow }} props - the cached check state.
1174
+ * @returns {unknown} the summary block.
901
1175
  */
902
1176
  function ResultSummary({ state }) {
903
1177
  const counts = state.counts ?? {};
@@ -954,19 +1228,26 @@ window.__ModuleLoader__.load({
954
1228
 
955
1229
  // ── The panel ──────────────────────────────────────────────────────────
956
1230
 
1231
+ /**
1232
+ * The row phases in which a request is still in flight: a list read must
1233
+ * leave such a row alone (see `loadDistros`).
1234
+ * @type {Set<string | undefined>}
1235
+ */
1236
+ const IN_FLIGHT = new Set(["checking", "fullChecking", "repairing", "refreshing"]);
1237
+
957
1238
  /**
958
1239
  * The WSL environment page: the installed distros, their quick verdicts, and
959
1240
  * the directories recorded for Windows access.
960
- * @param props - the client root context.
961
- * @returns the page element.
1241
+ * @param {ClientPanelProps} props - the client root context.
1242
+ * @returns {unknown} the page element.
962
1243
  */
963
1244
  function WslPanel({ ctx }) {
964
1245
  const [phase, setPhase] = useState("loading");
965
- const [distros, setDistros] = useState([]);
966
- const [checks, setChecks] = useState({});
967
- const [notice, setNotice] = useState(null);
968
- const [accessPaths, setAccessPaths] = useState(null);
969
- const [plugin, setPlugin] = useState({ phase: "loading" });
1246
+ const [distros, setDistros] = useState(/** @type {string[]} */ ([]));
1247
+ const [checks, setChecks] = useState(/** @type {ClientCheckTable} */ ({}));
1248
+ const [notice, setNotice] = useState(/** @type {ClientNotice | null} */ (null));
1249
+ const [accessPaths, setAccessPaths] = useState(/** @type {string[] | null} */ (null));
1250
+ const [plugin, setPlugin] = useState(/** @type {ClientPluginState} */ ({ phase: "loading" }));
970
1251
 
971
1252
  /** Re-read the Windows-access record (best effort; the panel still works without it). */
972
1253
  const loadAccessPaths = async () => {
@@ -983,7 +1264,7 @@ window.__ModuleLoader__.load({
983
1264
  * host's cache TTL ask the host's plugin-manager for a fresh answer; a
984
1265
  * click forces one. The installed version stays visible while a later
985
1266
  * check fails, so the card never turns into a bare error.
986
- * @param refresh - whether to bypass the host's version cache.
1267
+ * @param {boolean} [refresh] - whether to bypass the host's version cache.
987
1268
  */
988
1269
  const loadPlugin = async (refresh = false) => {
989
1270
  setPlugin((previous) => ({
@@ -1062,7 +1343,7 @@ window.__ModuleLoader__.load({
1062
1343
  * keeps its previous summary until the answer arrives; a doctor failure
1063
1344
  * comes back as a normal error verdict (and is stored), while a
1064
1345
  * transport failure leaves the row with the reason it has no result.
1065
- * @param distro - the distro to re-check.
1346
+ * @param {string} distro - the distro to re-check.
1066
1347
  */
1067
1348
  const refreshBackground = async (distro) => {
1068
1349
  setChecks((previous) => {
@@ -1080,7 +1361,7 @@ window.__ModuleLoader__.load({
1080
1361
 
1081
1362
  /**
1082
1363
  * Load the distro list and the stored results.
1083
- * @param allowBackground - whether running distros' stored results may be
1364
+ * @param {boolean} [allowBackground] - whether running distros' stored results may be
1084
1365
  * re-checked in the background (the initial load only, not a manual
1085
1366
  * refresh: a refresh is a list read, not a probe).
1086
1367
  */
@@ -1090,20 +1371,39 @@ window.__ModuleLoader__.load({
1090
1371
  try {
1091
1372
  const answer = await statusRequest("");
1092
1373
  setDistros(Array.isArray(answer.distros) ? answer.distros : []);
1093
- const cached = {};
1094
- for (const entry of Array.isArray(answer.cached) ? answer.cached : []) {
1095
- cached[entry.distro] = { phase: "done", ...entry, cached: true };
1096
- }
1097
- setChecks(cached);
1374
+ const stored = Array.isArray(answer.cached) ? answer.cached : [];
1375
+ // The list read MERGES into the rows: one whose check is still in
1376
+ // flight keeps its state. Replacing the whole table reset such a
1377
+ // row to its stored result, which re-enabled the row's buttons (a
1378
+ // second doctor could start beside the first) and let the first
1379
+ // check's late answer land over whatever had replaced it.
1380
+ setChecks((previous) => {
1381
+ /** @type {ClientCheckTable} */
1382
+ const next = {};
1383
+ for (const [distro, state] of Object.entries(previous)) {
1384
+ if (state !== undefined && IN_FLIGHT.has(state.phase)) next[distro] = state;
1385
+ }
1386
+ for (const entry of stored) {
1387
+ if (next[entry.distro] === undefined) next[entry.distro] = { phase: "done", ...entry, cached: true };
1388
+ }
1389
+ return next;
1390
+ });
1098
1391
  setPhase("ready");
1099
1392
  if (allowBackground) {
1100
1393
  const running = new Set(Array.isArray(answer.running) ? answer.running : []);
1101
- for (const entry of Array.isArray(answer.cached) ? answer.cached : []) {
1394
+ for (const entry of stored) {
1102
1395
  // A result from the last minute is already current; an error is
1103
1396
  // not retried automatically (the row's check button is the way
1104
1397
  // back), so a persistent failure cannot spin on every load.
1105
1398
  const recent = typeof entry.checkedAt === "number" && Date.now() - entry.checkedAt < 60_000;
1106
- if (running.has(entry.distro) && entry.verdict !== "error" && !recent) void refreshBackground(entry.distro);
1399
+ // A full diagnosis or a repair is the user's own result. A
1400
+ // background re-check is a QUICK one: it would drop the repair
1401
+ // button and the repair's before → after evidence, sixty
1402
+ // seconds after the user last opened the panel. (The route
1403
+ // answers such a stored result as it is, for a client that
1404
+ // asks anyway.)
1405
+ const userOwn = entry.full === true || entry.repaired === true;
1406
+ if (running.has(entry.distro) && entry.verdict !== "error" && !recent && !userOwn) void refreshBackground(entry.distro);
1107
1407
  }
1108
1408
  }
1109
1409
  } catch (error) {
@@ -1122,6 +1422,10 @@ window.__ModuleLoader__.load({
1122
1422
  void loadPlugin();
1123
1423
  }, []);
1124
1424
 
1425
+ /**
1426
+ * Run the quick check against one distro.
1427
+ * @param {string} distro - the distro to check.
1428
+ */
1125
1429
  const check = async (distro) => {
1126
1430
  setNotice(null);
1127
1431
  setChecks((previous) => ({ ...previous, [distro]: { phase: "checking" } }));
@@ -1135,7 +1439,7 @@ window.__ModuleLoader__.load({
1135
1439
 
1136
1440
  /**
1137
1441
  * Run a full, read-only doctor report.
1138
- * @param distro - the distro to run against.
1442
+ * @param {string} distro - the distro to run against.
1139
1443
  */
1140
1444
  const fullCheck = async (distro) => {
1141
1445
  setNotice(null);
@@ -1162,7 +1466,7 @@ window.__ModuleLoader__.load({
1162
1466
  /**
1163
1467
  * Run the explicit plugin-owned repair after a full report identifies
1164
1468
  * repairable findings.
1165
- * @param distro - the distro to repair.
1469
+ * @param {string} distro - the distro to repair.
1166
1470
  */
1167
1471
  const repair = async (distro) => {
1168
1472
  setNotice(null);
@@ -1198,7 +1502,7 @@ window.__ModuleLoader__.load({
1198
1502
  * when `wsl.exe` or the doctor is unavailable. The rows are removed only
1199
1503
  * after the route confirms, so a failed request leaves the last result
1200
1504
  * visible with the reason.
1201
- * @param distro - the distro whose result is cleared, or null for all.
1505
+ * @param {string | null} distro - the distro whose result is cleared, or null for all.
1202
1506
  */
1203
1507
  const clearResults = async (distro) => {
1204
1508
  setNotice(null);
@@ -1238,6 +1542,7 @@ window.__ModuleLoader__.load({
1238
1542
  && !Number.isNaN(new Date(latest.publishedAt).getTime())
1239
1543
  ? new Date(latest.publishedAt).toLocaleDateString()
1240
1544
  : undefined;
1545
+ /** @type {string} */
1241
1546
  let pluginStatusLine;
1242
1547
  if (plugin.phase === "loading") {
1243
1548
  pluginStatusLine = "正在读取版本信息…";
@@ -1371,15 +1676,18 @@ window.__ModuleLoader__.load({
1371
1676
  onClick: () => { void clearResults(null); },
1372
1677
  }),
1373
1678
  h(Btn, {
1374
- label: "刷新",
1679
+ label: phase === "loading" ? "刷新中…" : "刷新",
1375
1680
  small: true,
1681
+ // A list read while a row's check is in flight would show
1682
+ // that row's stale stored result under re-enabled buttons.
1683
+ disabled: phase !== "ready" || busyAny,
1376
1684
  onClick: () => { void loadDistros(false); void loadAccessPaths(); },
1377
1685
  }),
1378
1686
  ),
1379
1687
  },
1380
1688
  h("details", null,
1381
1689
  h("summary", { style: { ...styles.hint, cursor: "pointer" } }, "检查与修复说明"),
1382
- h("div", { style: styles.hint }, "“快速检查”验证首条命令的前置项;“完整诊断”运行完整 doctor,二者均只读。完整诊断发现可修复的插件自有状态(残留 session scope、损坏的 agent 缓存)后,才显示独立的“修复插件状态”按钮;修复后复检并显示 before→after。修复不安装软件包、不改写 Windows 配置;其余告警按各自处理办法手动处理。检查会启动已停止的发行版,所以只在点击时执行;页面加载的后台复核只针对正在运行的发行版,失败会按实际观测覆盖并标为“后台”来源。“清除”删除该发行版本机保存的检测结果,“清除全部”清空所有结果;两者都不探测、不修改发行版,但清除后需再次检查。"),
1690
+ h("div", { style: styles.hint }, "“快速检查”验证首条命令的前置项;“完整诊断”运行完整 doctor,二者均只读。完整诊断发现可修复的插件自有状态(残留 session scope、损坏的 agent 缓存)后,才显示独立的“修复插件状态”按钮;修复后复检并显示 before→after。修复不安装软件包、不改写 Windows 配置;其余告警按各自处理办法手动处理。检查会启动已停止的发行版,所以只在点击时执行;页面加载的后台复核只针对正在运行的发行版,不会覆盖“完整诊断”和“修复”的结果,失败会按实际观测覆盖并标为“后台”来源。“清除”删除该发行版本机保存的检测结果,“清除全部”清空所有结果;两者都不探测、不修改发行版,但清除后需再次检查。"),
1383
1691
  ),
1384
1692
  phase === "loading"
1385
1693
  ? h("div", { style: styles.empty }, "加载中…")
@@ -1511,7 +1819,7 @@ window.__ModuleLoader__.load({
1511
1819
 
1512
1820
  // ── The access-mode prompt ─────────────────────────────────────────────
1513
1821
 
1514
- /** One pending prompt, shared by the watcher and the overlay occupant. */
1822
+ /** One pending prompt, shared by the watcher and the overlay occupant. @type {ClientAccessPrompt} */
1515
1823
  const accessPrompt = {
1516
1824
  value: null,
1517
1825
  listeners: new Set(),
@@ -1528,13 +1836,14 @@ window.__ModuleLoader__.load({
1528
1836
 
1529
1837
  /**
1530
1838
  * The modal that asks how a newly added distro workspace is opened.
1531
- * @param props - the client root context.
1532
- * @returns the modal, or null while nothing is pending.
1839
+ * @param {ClientPanelProps} props - the client root context.
1840
+ * @returns {unknown} the modal, or null while nothing is pending.
1533
1841
  */
1534
1842
  function AccessPrompt({ ctx }) {
1535
1843
  const [request, setRequest] = useState(accessPrompt.get());
1536
1844
  const [busy, setBusy] = useState(false);
1537
- const [error, setError] = useState(null);
1845
+ const [error, setError] = useState(/** @type {string | null} */ (null));
1846
+ const dialogRef = useRef(/** @type {ClientElement | null} */ (null));
1538
1847
 
1539
1848
  useEffect(() => accessPrompt.subscribe(() => {
1540
1849
  setRequest(accessPrompt.get());
@@ -1542,13 +1851,44 @@ window.__ModuleLoader__.load({
1542
1851
  setBusy(false);
1543
1852
  }), []);
1544
1853
 
1545
- // Dismissing the prompt takes the default: Remote WSL. Nothing is written,
1854
+ // A modal that owns the keyboard: focus moves to the recommended choice
1855
+ // when it opens, Tab/Shift+Tab cycle its buttons instead of walking into
1856
+ // the page behind it, and closing returns focus where it was. Escape and
1857
+ // the backdrop keep taking the default: Remote WSL. Nothing is written,
1546
1858
  // which is exactly what "keep the default" means for this record.
1547
1859
  useEffect(() => {
1548
1860
  if (request === null) return undefined;
1549
- const onKey = (event) => { if (event.key === "Escape") accessPrompt.set(null); };
1550
- document.addEventListener("keydown", onKey);
1551
- return () => document.removeEventListener("keydown", onKey);
1861
+ const previous = platform.document.activeElement ?? null;
1862
+ const dialog = dialogRef.current;
1863
+ /** @returns {ClientElement[]} the dialog's enabled buttons, in DOM order. */
1864
+ const focusables = () => Array.from(dialog?.querySelectorAll?.("button:not([disabled])") ?? []);
1865
+ const first = focusables()[0];
1866
+ first?.focus?.();
1867
+ /** @param {ClientKeyEvent} event - the key event on the document. */
1868
+ const onKey = (event) => {
1869
+ if (event.key === "Escape") {
1870
+ accessPrompt.set(null);
1871
+ return;
1872
+ }
1873
+ if (event.key !== "Tab") return;
1874
+ const items = focusables();
1875
+ if (items.length === 0) return;
1876
+ const active = platform.document.activeElement ?? null;
1877
+ const index = active === null ? -1 : items.indexOf(active);
1878
+ const backwards = event.shiftKey === true;
1879
+ const next = index < 0
1880
+ ? items[backwards ? items.length - 1 : 0]
1881
+ : items[(index + (backwards ? -1 : 1) + items.length) % items.length];
1882
+ if (next !== undefined) {
1883
+ event.preventDefault?.();
1884
+ next.focus?.();
1885
+ }
1886
+ };
1887
+ platform.document.addEventListener("keydown", onKey);
1888
+ return () => {
1889
+ platform.document.removeEventListener("keydown", onKey);
1890
+ previous?.focus?.();
1891
+ };
1552
1892
  }, [request]);
1553
1893
 
1554
1894
  if (request === null) return null;
@@ -1580,6 +1920,7 @@ window.__ModuleLoader__.load({
1580
1920
  return h(
1581
1921
  "div",
1582
1922
  {
1923
+ /** @param {ClientMouseEvent} event - the click on the backdrop. */
1583
1924
  onClick: (event) => { if (event.target === event.currentTarget) close(); },
1584
1925
  style: {
1585
1926
  position: "fixed",
@@ -1596,6 +1937,7 @@ window.__ModuleLoader__.load({
1596
1937
  h(
1597
1938
  "div",
1598
1939
  {
1940
+ ref: dialogRef,
1599
1941
  role: "dialog",
1600
1942
  "aria-modal": "true",
1601
1943
  "aria-label": "选择 WSL 工作区的打开方式",
@@ -1650,12 +1992,13 @@ window.__ModuleLoader__.load({
1650
1992
  * Watch for newly added WSL workspaces and raise the access-mode prompt.
1651
1993
  * Existing workspaces are the baseline: startup restoration must not ask
1652
1994
  * again for a workspace the operator already opened.
1653
- * @param ctx - client root context.
1654
- * @returns a disposer owned by the plugin fiber.
1995
+ * @param {ClientServiceHost} ctx - client root context.
1996
+ * @returns {(() => void) | undefined} a disposer owned by the plugin fiber.
1655
1997
  */
1656
1998
  const watchWorkspaces = (ctx) => {
1657
1999
  const workspaces = service(ctx, "workspaces");
1658
2000
  if (workspaces === undefined) return undefined;
2001
+ /** @type {Set<string> | undefined} */
1659
2002
  let known;
1660
2003
  const consider = () => {
1661
2004
  const snapshot = workspaces.list.getSnapshot();
@@ -1679,6 +2022,7 @@ window.__ModuleLoader__.load({
1679
2022
 
1680
2023
  return {
1681
2024
  inject: ["slots"],
2025
+ /** @param {ClientContext} ctx - the client root context. */
1682
2026
  apply(ctx) {
1683
2027
  // Sidebar panel: icon in the navigation column, page in the main seat.
1684
2028
  ctx.slots.inject("sidebar.panellist", function* () {
@@ -1746,7 +2090,7 @@ window.__ModuleLoader__.load({
1746
2090
  headers: { "content-type": "application/json" },
1747
2091
  body: JSON.stringify({ path: cwd }),
1748
2092
  });
1749
- const body = await answer.json().catch(() => ({}));
2093
+ const body = /** @type {{ error?: string }} */ (await answer.json().catch(() => ({})));
1750
2094
  if (!answer.ok) throw new Error(body.error ?? ("打开失败(HTTP " + answer.status + ")"));
1751
2095
  },
1752
2096
  }];