dsh-plugin-wsl-env 0.23.1 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/CHANGELOG.md +212 -0
  2. package/README.md +9 -5
  3. package/SECURITY.md +10 -0
  4. package/client.js +974 -165
  5. package/cordis.patch.yml +28 -3
  6. package/docs/API.md +2 -1
  7. package/docs/ARCHITECTURE.md +36 -13
  8. package/docs/COMPATIBILITY.md +5 -0
  9. package/docs/CONFIGURATION.md +80 -9
  10. package/docs/CONFIGURATION.zh.md +64 -8
  11. package/docs/DIAGNOSTICS.md +48 -20
  12. package/docs/DIAGNOSTICS.zh.md +36 -14
  13. package/docs/LIMITATIONS.md +36 -9
  14. package/docs/LIMITATIONS.zh.md +26 -7
  15. package/docs/MIGRATION.md +1 -1
  16. package/docs/PEER-PARITY.md +4 -4
  17. package/docs/QUICKSTART.md +42 -12
  18. package/docs/QUICKSTART.zh.md +29 -8
  19. package/docs/README.zh.md +9 -5
  20. package/docs/RELEASING.md +17 -13
  21. package/docs/REQUIREMENTS.zh.md +5 -4
  22. package/docs/UPSTREAM-FSIO-EXPORT.md +5 -4
  23. package/docs/UPSTREAM-PROMPT-ADAPTERS.md +85 -0
  24. package/docs/root-fs-routing.md +1 -1
  25. package/lib/agent-confined.d.ts +7 -1
  26. package/lib/agent-confined.js +3 -3
  27. package/lib/auto-preset.d.ts +27 -0
  28. package/lib/auto-preset.js +40 -3
  29. package/lib/bwrap.d.ts +14 -0
  30. package/lib/bwrap.js +11 -0
  31. package/lib/client-host.d.ts +2 -2
  32. package/lib/client-host.js +2 -2
  33. package/lib/cwd-prompt.d.ts +41 -3
  34. package/lib/cwd-prompt.js +125 -8
  35. package/lib/doctor-report.d.ts +50 -0
  36. package/lib/doctor-report.js +172 -0
  37. package/lib/fs-routing.d.ts +1 -1
  38. package/lib/fs-routing.js +1 -1
  39. package/lib/fs.d.ts +1 -1
  40. package/lib/fs.js +1 -1
  41. package/lib/index.d.ts +6 -1464
  42. package/lib/index.js +5 -2120
  43. package/lib/listing.d.ts +21 -9
  44. package/lib/listing.js +25 -21
  45. package/lib/messages.d.ts +1 -1
  46. package/lib/messages.js +3 -3
  47. package/lib/picker.d.ts +50 -16
  48. package/lib/picker.js +103 -23
  49. package/lib/preflight.d.ts +7 -4
  50. package/lib/preflight.js +27 -13
  51. package/lib/preset-choice.d.ts +22 -3
  52. package/lib/preset-choice.js +36 -3
  53. package/lib/provider-common.d.ts +58 -0
  54. package/lib/provider-common.js +123 -0
  55. package/lib/sandbox-core.d.ts +1 -0
  56. package/lib/sandbox-core.js +4 -2
  57. package/lib/session-runtime.d.ts +7 -1
  58. package/lib/session-runtime.js +9 -2
  59. package/lib/shell.d.ts +1 -1
  60. package/lib/shell.js +1 -1
  61. package/lib/status.d.ts +261 -0
  62. package/lib/status.js +425 -0
  63. package/lib/writable-roots.d.ts +109 -0
  64. package/lib/writable-roots.js +257 -0
  65. package/lib/wsl-doctor-tool.d.ts +8 -0
  66. package/lib/wsl-doctor-tool.js +18 -20
  67. package/lib/wsl-filesystem.d.ts +692 -0
  68. package/lib/wsl-filesystem.js +897 -0
  69. package/lib/wsl-shell.d.ts +742 -0
  70. package/lib/wsl-shell.js +965 -0
  71. package/lib/wsl.d.ts +13 -1
  72. package/lib/wsl.js +16 -1
  73. package/locale/doctor/en.json +3 -2
  74. package/locale/doctor/zh.json +3 -2
  75. package/package.json +12 -4
  76. package/scripts/doctor.mjs +436 -226
  77. package/scripts/profile-preset.mjs +17 -5
@@ -0,0 +1,692 @@
1
+ import z from "@deepseek-ai/schemastery";
2
+ import { LocalFileSystem } from "@deepseek-ai/dsh-fs-local";
3
+ import { FsError } from "@deepseek-ai/dsh-fs";
4
+ import { WslSandbox } from "./sandbox.js";
5
+ import type { WslAgent } from "./agent.js";
6
+ import { AgentSubstrate } from "./fs-substrate.js";
7
+ import { SessionRuntimes } from "./session-runtime.js";
8
+ import type { SessionRuntimeEntry } from "./session-runtime.js";
9
+ import type { Context } from "@deepseek-ai/cordis";
10
+ import type { FileSystem, FsDeleteOutcome, FsDirEntry, FsEditOutcome, FsEditRequest, FsInfo, FsMoveOutcome, FsPathInfo, FsTarget, FsVersion, FsWriteIntent, FsWriteOutcome } from "@deepseek-ai/dsh-fs";
11
+ import type { SandboxExecutionPolicy, SandboxMode } from "@deepseek-ai/dsh-sandbox";
12
+ type PatchHunks = Parameters<FileSystem["patchText"]>[1];
13
+ type MoveFileOptions = Parameters<FileSystem["moveFile"]>[2];
14
+ /**
15
+ * The WSL filesystem provider's validated config — the keys of
16
+ * {@link WslFileSystem.Config}, which the upstream `LocalFileSystem` config
17
+ * type does not know. This provider has no volatile fields: every key is read
18
+ * as its plain value.
19
+ */
20
+ interface WslFileSystemConfig {
21
+ /** The pinned distro; empty resolves WSL's default. */
22
+ distro: string;
23
+ /** The base directory for relative input. */
24
+ cwd: string;
25
+ /** The `wsl.exe` path, for default-distro resolution. */
26
+ wslPath: string;
27
+ /**
28
+ * The overwrite-diff byte bound per side; schema-defaulted when mounted
29
+ * through cordis, and defaulted again by the substrate when absent.
30
+ */
31
+ diffBasisMaxBytes?: number;
32
+ /** Whether mutations are fenced by the policy. */
33
+ sandbox: boolean;
34
+ /** Session runtime: `true` requires it, `false` disables it, `"auto"` uses it when usable. */
35
+ sessionSandbox: boolean | "auto";
36
+ /** Whether confined profiles mask `/mnt`. */
37
+ maskWindowsDrive: boolean;
38
+ /** Extra distro directories granted read-write under `workspace-write`. */
39
+ writableRoots?: string[];
40
+ /** Whether paths leaving the distro are refused. */
41
+ restrictToDistro: boolean;
42
+ /** The in-distro watch scan depth bound. */
43
+ watchMaxDepth: number;
44
+ /**
45
+ * Which I/O substrate serves the file tools; schema-defaulted when mounted
46
+ * through cordis, absent on direct construction (the router), which the
47
+ * constructor's refusal treats as `"agent"`.
48
+ */
49
+ substrate?: string;
50
+ }
51
+ /**
52
+ * Filesystem backend over a WSL distro's UNC share.
53
+ *
54
+ * Reads, listings, stats and searches reuse the host backend verbatim: the
55
+ * share is a real filesystem to Node, and the packaged ripgrep walks it too.
56
+ * Two things are deliberately replaced.
57
+ *
58
+ * **Resolution** accepts Linux paths (`/home/andy/proj/src/a.ts`) and shows them
59
+ * back as Linux paths, while `targetKey` stays the UNC path the host I/O uses —
60
+ * the seam treats `targetKey` as opaque and reserves `displayPath` for model and
61
+ * UI output, so this rewrite is contract-legal.
62
+ *
63
+ * **Mutation guards are hoisted.** The host backend publishes a guarded
64
+ * *creation* by hard-linking a staged file into place, and the WSL UNC share
65
+ * rejects hard links with `ENOTSUP`; it also refuses `symlink` with `EPERM`.
66
+ * Guarded creation through the share would therefore fail with `FS_IO_ERROR` on
67
+ * the most common write there is — creating a new file. This backend checks the
68
+ * caller's guard itself and then delegates the unguarded publication, which the
69
+ * share does support. The residual window is the same check-then-act race
70
+ * `dsh-fs-sandbox` already documents and accepts.
71
+ *
72
+ * **Publication is replaced.** Unguarded is not enough on its own: the host
73
+ * backend's Windows branch also copies the replaced file's security descriptor
74
+ * and publishes with `ReplaceFileW`, and neither exists on a 9p share — the
75
+ * descriptor read fails every write to an existing file outright. See the
76
+ * constructor for what runs instead.
77
+ */
78
+ export declare class WslFileSystem extends LocalFileSystem {
79
+ static inject: string[];
80
+ static Config: z<Schemastery.ObjectS<NoInfer<{
81
+ /**
82
+ * Distro mode: empty/`"auto"` follows the target path, `"default"` forces
83
+ * WSL's default, and an explicit name pins the filesystem.
84
+ */
85
+ distro: z<string, string, "defined">;
86
+ /**
87
+ * Default workdir for relative input; accepts a Linux path, a UNC path, or
88
+ * `C:\...`. Empty — the default — means the distro user's home, resolved
89
+ * inside the distro.
90
+ */
91
+ cwd: z<string, string, "defined">;
92
+ /** Path to `wsl.exe`, used only to resolve the default distro. */
93
+ wslPath: z<string, string, "defined">;
94
+ /** UTF-8 byte limit per overwrite-diff side, mirroring the host backend. */
95
+ diffBasisMaxBytes: z<number, number, "defined">;
96
+ /**
97
+ * Fence mutations by `ctx.sandboxPolicy`, and report the mode through
98
+ * {@link sandboxMode}. `false` restores the pre-sandbox behaviour exactly —
99
+ * an unfenced backend that reports `undefined` — for an operator who wants
100
+ * the old posture and accepts what it means: the model is told these
101
+ * operations are unconfined.
102
+ */
103
+ sandbox: z<boolean, boolean, "defined">;
104
+ /**
105
+ * Run confined mutations in the session's systemd user scope — the same
106
+ * runtime the shell executor acquires for the same session, distro,
107
+ * workspace and policy — instead of a per-policy confined resident. A
108
+ * missing session ID keeps the providers separate. The kernel enforcement
109
+ * is the runtime's mount profile; the scope stops when its providers
110
+ * release it. Requires systemd + `Linger`, like `wsl-shell`'s
111
+ * `sessionSandbox`; the preflight refuses with the remedy. Off for direct
112
+ * constructions; on in the shipped preset.
113
+ */
114
+ sessionSandbox: z<boolean | "auto", boolean | "auto", "defined">;
115
+ /**
116
+ * Shadow `/mnt` with an empty tmpfs in every confined profile, hiding the
117
+ * Windows drive from confined commands — same meaning and same honest
118
+ * limits as the `wsl-shell` key of the same name (its doc carries the
119
+ * full story). Confined fs mutations publish through the masked resident;
120
+ * reads and the share substrate are unaffected.
121
+ */
122
+ maskWindowsDrive: z<boolean, boolean, "defined">;
123
+ /**
124
+ * Extra directories under `workspace-write`, in distro spelling — the
125
+ * same list and same rules as `wsl-shell`'s key. Confined writes bind
126
+ * them, and the fs fence accepts them; keep the two rows' lists equal so
127
+ * a command and its write see one mount table.
128
+ */
129
+ writableRoots: z<string[], string[], "defined">;
130
+ /**
131
+ * Refuse any path that leaves the pinned distro. A WSL filesystem is a
132
+ * whole-Linux view whose `/mnt/c` also reaches the Windows disk, so without
133
+ * this the backend would silently widen the session far beyond the
134
+ * workspace the operator selected.
135
+ */
136
+ restrictToDistro: z<boolean, boolean, "defined">;
137
+ /**
138
+ * How deep the in-distro watch scan walks, `1` = the watched directory and
139
+ * its direct children. `0` — the default — walks the whole tree, which is
140
+ * what the invalidation contract asks for but a real cost every poll over
141
+ * a tree containing a `node_modules`; a bound trades that cost for a
142
+ * documented blind spot: a change below the bound is not seen until
143
+ * another change above it fires the same callback.
144
+ */
145
+ watchMaxDepth: z<number, number, "defined">;
146
+ /**
147
+ * Which I/O substrate serves the file tools. Only `"agent"` exists — the
148
+ * resident in-distro agent (`lib/fs-substrate.js`): reads, writes and
149
+ * identities run where the files live, symlinks and mode bits are native,
150
+ * and the mutation guard survives to the write's no-replace publication,
151
+ * kernel-enforced by the confined resident when the policy is confined.
152
+ * The former `"share"` opt-out — the Windows-side host filesystem stack
153
+ * over the distro's 9p share — is retired: it was the one model-facing
154
+ * I/O path that still crossed the share, and the agent has no fallback
155
+ * that needs it. A profile carrying `"share"` is refused at construction
156
+ * with the migration (`shareSubstrateRefusal`). `watch()` rides the
157
+ * in-distro poll loop for the substrate regardless (`lib/watcher.js`) —
158
+ * it never ran through either substrate. The substrate never changes
159
+ * `sandboxMode`'s honesty.
160
+ */
161
+ substrate: z<"agent" | "share", "agent" | "share", "defined">;
162
+ }>>, Schemastery.ObjectT<NoInfer<{
163
+ /**
164
+ * Distro mode: empty/`"auto"` follows the target path, `"default"` forces
165
+ * WSL's default, and an explicit name pins the filesystem.
166
+ */
167
+ distro: z<string, string, "defined">;
168
+ /**
169
+ * Default workdir for relative input; accepts a Linux path, a UNC path, or
170
+ * `C:\...`. Empty — the default — means the distro user's home, resolved
171
+ * inside the distro.
172
+ */
173
+ cwd: z<string, string, "defined">;
174
+ /** Path to `wsl.exe`, used only to resolve the default distro. */
175
+ wslPath: z<string, string, "defined">;
176
+ /** UTF-8 byte limit per overwrite-diff side, mirroring the host backend. */
177
+ diffBasisMaxBytes: z<number, number, "defined">;
178
+ /**
179
+ * Fence mutations by `ctx.sandboxPolicy`, and report the mode through
180
+ * {@link sandboxMode}. `false` restores the pre-sandbox behaviour exactly —
181
+ * an unfenced backend that reports `undefined` — for an operator who wants
182
+ * the old posture and accepts what it means: the model is told these
183
+ * operations are unconfined.
184
+ */
185
+ sandbox: z<boolean, boolean, "defined">;
186
+ /**
187
+ * Run confined mutations in the session's systemd user scope — the same
188
+ * runtime the shell executor acquires for the same session, distro,
189
+ * workspace and policy — instead of a per-policy confined resident. A
190
+ * missing session ID keeps the providers separate. The kernel enforcement
191
+ * is the runtime's mount profile; the scope stops when its providers
192
+ * release it. Requires systemd + `Linger`, like `wsl-shell`'s
193
+ * `sessionSandbox`; the preflight refuses with the remedy. Off for direct
194
+ * constructions; on in the shipped preset.
195
+ */
196
+ sessionSandbox: z<boolean | "auto", boolean | "auto", "defined">;
197
+ /**
198
+ * Shadow `/mnt` with an empty tmpfs in every confined profile, hiding the
199
+ * Windows drive from confined commands — same meaning and same honest
200
+ * limits as the `wsl-shell` key of the same name (its doc carries the
201
+ * full story). Confined fs mutations publish through the masked resident;
202
+ * reads and the share substrate are unaffected.
203
+ */
204
+ maskWindowsDrive: z<boolean, boolean, "defined">;
205
+ /**
206
+ * Extra directories under `workspace-write`, in distro spelling — the
207
+ * same list and same rules as `wsl-shell`'s key. Confined writes bind
208
+ * them, and the fs fence accepts them; keep the two rows' lists equal so
209
+ * a command and its write see one mount table.
210
+ */
211
+ writableRoots: z<string[], string[], "defined">;
212
+ /**
213
+ * Refuse any path that leaves the pinned distro. A WSL filesystem is a
214
+ * whole-Linux view whose `/mnt/c` also reaches the Windows disk, so without
215
+ * this the backend would silently widen the session far beyond the
216
+ * workspace the operator selected.
217
+ */
218
+ restrictToDistro: z<boolean, boolean, "defined">;
219
+ /**
220
+ * How deep the in-distro watch scan walks, `1` = the watched directory and
221
+ * its direct children. `0` — the default — walks the whole tree, which is
222
+ * what the invalidation contract asks for but a real cost every poll over
223
+ * a tree containing a `node_modules`; a bound trades that cost for a
224
+ * documented blind spot: a change below the bound is not seen until
225
+ * another change above it fires the same callback.
226
+ */
227
+ watchMaxDepth: z<number, number, "defined">;
228
+ /**
229
+ * Which I/O substrate serves the file tools. Only `"agent"` exists — the
230
+ * resident in-distro agent (`lib/fs-substrate.js`): reads, writes and
231
+ * identities run where the files live, symlinks and mode bits are native,
232
+ * and the mutation guard survives to the write's no-replace publication,
233
+ * kernel-enforced by the confined resident when the policy is confined.
234
+ * The former `"share"` opt-out — the Windows-side host filesystem stack
235
+ * over the distro's 9p share — is retired: it was the one model-facing
236
+ * I/O path that still crossed the share, and the agent has no fallback
237
+ * that needs it. A profile carrying `"share"` is refused at construction
238
+ * with the migration (`shareSubstrateRefusal`). `watch()` rides the
239
+ * in-distro poll loop for the substrate regardless (`lib/watcher.js`) —
240
+ * it never ran through either substrate. The substrate never changes
241
+ * `sandboxMode`'s honesty.
242
+ */
243
+ substrate: z<"agent" | "share", "agent" | "share", "defined">;
244
+ }>>, "plain">;
245
+ /** Cached default distro, resolved once from `wsl.exe -l -q`. */
246
+ resolvedDistro: string;
247
+ /** Cached distro-user home, the base for relative input when `cwd` is empty. */
248
+ resolvedHome: string | undefined;
249
+ /** Per-distro homes, so two concurrent distros cannot share one. */
250
+ resolvedHomes: Map<string, string>;
251
+ /** The deployment default mode — the capability fact the tool layer reads. */
252
+ defaultMode: SandboxMode;
253
+ /** The lazy default-distro substrate, kept for the legacy accessor and tests. */
254
+ agentSubstrateInstance: AgentSubstrate | undefined;
255
+ /** The per-distro agent-backed substrates. */
256
+ agentSubstrates: Map<string, AgentSubstrate>;
257
+ /** The distro-side bwrap usability probe, shared with the confined agents. */
258
+ sandbox: InstanceType<typeof WslSandbox>;
259
+ /** The resident agent serving publication for the default/pinned distro. */
260
+ agentInstance: WslAgent | undefined;
261
+ /** The per-distro publication agents. */
262
+ agentInstances: Map<string, WslAgent>;
263
+ /** The session-runtime registry; tests substitute it. */
264
+ sessionRuntimes: SessionRuntimes;
265
+ /** The runtimes this provider holds, by registry key. */
266
+ sessionRuntimeEntries: Map<string, SessionRuntimeEntry>;
267
+ /** Isolates calls that have no session identity. */
268
+ sessionRuntimeOwner: string;
269
+ /** The preflight's host runner; tests substitute it. */
270
+ sessionScopeProbe: (argv: string[]) => Promise<string>;
271
+ /** The one-time writable-root check's runner; tests substitute it. */
272
+ writableRootsProbe: (argv: string[]) => Promise<string>;
273
+ /** Distros whose session-runtime preflight has succeeded. */
274
+ sessionRuntimePreflight: Set<string>;
275
+ /** Per-distro `auto` verdicts, re-probed when they were negative and stale. */
276
+ autoSessionScope: Map<string, {
277
+ usable: boolean;
278
+ checkedAt: number;
279
+ }>;
280
+ /**
281
+ * @param ctx - the composition context.
282
+ * @param config - the validated plugin config.
283
+ */
284
+ constructor(ctx: Context, config: WslFileSystemConfig);
285
+ /**
286
+ * The mode this backend fences mutations with, or `undefined` when the
287
+ * operator turned the fence off. This is the capability fact `dsh-tool-fs`
288
+ * reads to advertise the escalation fields honestly, so it must disappear
289
+ * together with the enforcement — never claim a boundary that is not applied.
290
+ *
291
+ * @returns the deployment default mode, or `undefined` when unfenced.
292
+ */
293
+ get sandboxMode(): SandboxMode | undefined;
294
+ /**
295
+ * The resident agent serving the default/pinned distro's in-distro side
296
+ * work, created on first use and kept for the provider's lifetime.
297
+ *
298
+ * @returns the agent for the default/pinned distro.
299
+ */
300
+ publicationAgent(): Promise<WslAgent>;
301
+ /**
302
+ * The resident agent for one distro. The default/pinned distro keeps the
303
+ * legacy {@link publicationAgent} cache; every other distro gets its own
304
+ * entry, because the shared agent is a per-distro process singleton.
305
+ *
306
+ * @param distro - the distro name.
307
+ * @returns the agent for that distro.
308
+ */
309
+ publicationAgentFor(distro: string): Promise<WslAgent>;
310
+ /**
311
+ * The agent-backed substrate for the default/pinned distro, built on first
312
+ * use over the shared resident agent.
313
+ *
314
+ * @returns the substrate.
315
+ */
316
+ agentSubstrate(): Promise<AgentSubstrate>;
317
+ /**
318
+ * The agent-backed substrate for one distro. The default/pinned distro keeps
319
+ * the legacy {@link agentSubstrate} accessor (and its test override); every
320
+ * other distro gets a substrate that mints its own UNC identities and
321
+ * addresses its own resident.
322
+ *
323
+ * @param distro - the distro name.
324
+ * @returns the substrate for that distro.
325
+ */
326
+ agentSubstrateFor(distro: string): Promise<AgentSubstrate>;
327
+ /**
328
+ * The substrate for one resolved target, following the target's UNC identity.
329
+ *
330
+ * @param target - the resolved target.
331
+ * @returns the substrate for the target's distro.
332
+ */
333
+ substrateForTarget(target: FsTarget): Promise<AgentSubstrate>;
334
+ /**
335
+ * The effective extra writable roots for one mutation: the row's
336
+ * `writableRoots` plus the shared policy's `additionalWritableRoots`,
337
+ * resolved to Linux paths and checked once per process. Empty unless the
338
+ * mutation is confined under `workspace-write`.
339
+ *
340
+ * @param distro - the distro the mutation belongs to.
341
+ * @param policy - the per-call file-effect policy, when there is one.
342
+ * @returns the roots every confinement site binds.
343
+ * @throws {SandboxInvalidRootError} when an entry cannot be granted or checked.
344
+ */
345
+ writableRootsFor(distro: string, policy: {
346
+ mode: string;
347
+ workspaceRoot: string;
348
+ additionalWritableRoots?: readonly string[];
349
+ } | undefined, check?: boolean): Promise<string[]>;
350
+ /**
351
+ * The persistent session runtime for one confined mutation, when
352
+ * `sessionSandbox` is on. The key is the shell executor's key for the same
353
+ * session/policy, so the write and the commands share one agent, one mount
354
+ * view and one scope; the provider holds a reference until the session ends.
355
+ *
356
+ * @param policy - the resolved confined policy.
357
+ * @param distro - the resolved distro name.
358
+ * @param writableRoots - the effective extra roots the runtime binds.
359
+ * @returns the runtime entry, or undefined when the mode is off.
360
+ */
361
+ sessionRuntimeFor(policy: {
362
+ mode: string;
363
+ workspaceRoot: string;
364
+ sessionId?: string;
365
+ }, distro: string, writableRoots?: readonly string[]): SessionRuntimeEntry | undefined;
366
+ /**
367
+ * Run the session runtime's preflight once per provider. Only success is
368
+ * cached, so following the remedy does not need an app restart.
369
+ *
370
+ * @param distro - the resolved distro name.
371
+ * @returns resolved once the platform can host the runtime.
372
+ * @throws {Error} with the remedy when it cannot.
373
+ */
374
+ ensureSessionRuntimeUsable(distro: string): Promise<void>;
375
+ /**
376
+ * Whether this provider should use the session runtime for one distro, with
377
+ * the `auto` downgrade and its bounded re-probe. `true` keeps the refusing
378
+ * behavior; `false` stays off.
379
+ *
380
+ * @param distro - the resolved distro.
381
+ * @returns whether to acquire the per-session scope.
382
+ */
383
+ wantsSessionRuntime(distro: string): Promise<boolean>;
384
+ /**
385
+ * Release every runtime this provider holds. Called from the preset's
386
+ * dispose effect; public so tests and shutdown paths can await it.
387
+ *
388
+ * @returns resolved once every reference is released.
389
+ */
390
+ disposeSessionRuntimes(): Promise<void>;
391
+ /**
392
+ * The agent a MUTATION runs on under this resolved policy — stage-two
393
+ * routing. A confined policy addresses the confined resident whose bwrap
394
+ * profile binds exactly what the mode grants, so the kernel enforces what
395
+ * the check decided; an escalated write (`danger-full-access`) or a disabled
396
+ * sandbox addresses the plain resident, which is what those mean. A distro
397
+ * without a usable bwrap refuses confined mutations instead of downgrading
398
+ * them — the same closed failure the command path has.
399
+ *
400
+ * @param policy - the resolved file-effect policy, or undefined when the
401
+ * caller pre-checked.
402
+ * @param forDistro - the distro the mutation belongs to; derived from the
403
+ * policy when the caller does not know it.
404
+ * @returns the agent to publish through.
405
+ */
406
+ mutationAgent(policy: {
407
+ mode: string;
408
+ workspaceRoot: string;
409
+ sessionId?: string;
410
+ additionalWritableRoots?: readonly string[];
411
+ } | undefined, forDistro?: string): Promise<WslAgent>;
412
+ /**
413
+ * Map a substrate error onto the peer's `FsError`, so the tool layer reads
414
+ * the same refusal dialect on both substrates. An agent that is out becomes
415
+ * an I/O error naming the cause — the share backend's "distro is gone" case
416
+ * is the same availability, but the message says which substrate failed.
417
+ *
418
+ * @param error - what the substrate raised.
419
+ * @returns the error to surface.
420
+ */
421
+ peerError(error: unknown): FsError;
422
+ /**
423
+ * One resolved target's Linux path — the substrate's coordinate — falling
424
+ * back to the display spelling when the identity is not a distro share path.
425
+ *
426
+ * @param target - the resolved target.
427
+ * @returns the absolute Linux path.
428
+ */
429
+ linuxOf(target: FsTarget): string;
430
+ /**
431
+ * The distro used when no path supplies evidence: the pinned name, WSL's
432
+ * default, or the default for the automatic modes.
433
+ *
434
+ * @returns the distro name.
435
+ */
436
+ distro(): Promise<string>;
437
+ /**
438
+ * The distro one path belongs to: an explicit pin wins; otherwise the path
439
+ * itself, then the cwd or configured cwd, may name a distro; both absent
440
+ * falls back to WSL's default.
441
+ *
442
+ * @param path - the caller path, in any coordinate system.
443
+ * @param cwd - the caller's optional cwd override.
444
+ * @returns the distro name.
445
+ */
446
+ distroForPath(path: string, cwd?: string): Promise<string>;
447
+ /**
448
+ * The distro a resolved target belongs to. A UNC identity names it outright;
449
+ * a host-coordinate target falls back to the configured/default distro.
450
+ *
451
+ * @param target - the resolved target.
452
+ * @returns the distro name.
453
+ */
454
+ distroForTarget(target: FsTarget): Promise<string>;
455
+ /**
456
+ * The distro a mutation's policy belongs to: the workspace root is the
457
+ * strongest evidence, then the configured cwd, then the default.
458
+ *
459
+ * @param policy - the resolved policy, when the caller has one.
460
+ * @returns the distro name.
461
+ */
462
+ distroForPolicy(policy: {
463
+ mode: string;
464
+ workspaceRoot: string;
465
+ } | undefined): Promise<string>;
466
+ /**
467
+ * Translate one caller path into the world path, enforcing the distro fence.
468
+ *
469
+ * @param path - a Linux, UNC or Windows path.
470
+ * @param cwd - the caller's override of the configured default workdir.
471
+ * @returns the host path to operate on.
472
+ */
473
+ worldPath(path: string, cwd?: string): Promise<string>;
474
+ /**
475
+ * Resolve a path to a target whose `targetKey` is the UNC identity the host
476
+ * I/O stack uses and whose `displayPath` is the Linux path the model sees.
477
+ *
478
+ * @param path - a Linux, UNC or Windows path.
479
+ * @param opts - optional `cwd` override and `signal`.
480
+ * @returns the resolved `FsTarget`.
481
+ */
482
+ resolve(path: string, opts?: {
483
+ cwd?: string;
484
+ signal?: AbortSignal;
485
+ }): Promise<FsTarget>;
486
+ /**
487
+ * Enforce the per-call file-effect policy against one target and return the
488
+ * EXACT target the mutation must use, so the checked identity is the mutated
489
+ * one (no check-here-write-there window).
490
+ *
491
+ * `read-only` denies outright. `workspace-write` re-resolves the target NOW
492
+ * (reflecting a symlink ancestor swapped since the tool resolved it), requires
493
+ * containment under a writable root — the workspace plus the temp area of the
494
+ * world the workspace lives in — and hands back that fresh target.
495
+ * `danger-full-access` is the approved escalation and is not fenced. Refusal
496
+ * is the structured `FS_SANDBOX_DENIED` the tool layer maps to its
497
+ * model-facing `[sandbox: …]` marker and escalation hint.
498
+ *
499
+ * @param target - the resolved target to mutate.
500
+ * @param sandboxPolicy - the per-call mode and workspace root; omit for the
501
+ * deployment policy.
502
+ * @returns the target the mutation must use.
503
+ * @throws {FsError} with `FS_SANDBOX_DENIED` when the policy refuses it.
504
+ */
505
+ checkedTarget(target: FsTarget, sandboxPolicy?: SandboxExecutionPolicy): Promise<FsTarget>;
506
+ /**
507
+ * One target's metadata, answered from the distro.
508
+ *
509
+ * @param target - the resolved target.
510
+ * @param signal - optional cancellation.
511
+ * @returns the metadata, or undefined when absent.
512
+ */
513
+ stat(target: FsTarget, signal?: AbortSignal): Promise<FsInfo | undefined>;
514
+ /**
515
+ * No-follow stat one path. The agent substrate answers from the distro,
516
+ * where a symlink is a first-class entry.
517
+ *
518
+ * @param path - a Linux, UNC or Windows path.
519
+ * @param opts - optional `cwd` override.
520
+ * @param signal - optional cancellation.
521
+ * @returns the path info, or undefined when absent.
522
+ */
523
+ lstat(path: string, opts?: {
524
+ cwd?: string;
525
+ }, signal?: AbortSignal): Promise<FsPathInfo | undefined>;
526
+ /**
527
+ * Read one whole regular UTF-8 file from the distro.
528
+ *
529
+ * @param target - the resolved target.
530
+ * @param signal - optional cancellation.
531
+ * @returns the file text.
532
+ */
533
+ readText(target: FsTarget, signal?: AbortSignal): Promise<string>;
534
+ /**
535
+ * Stream one whole regular UTF-8 file from the distro.
536
+ *
537
+ * @param target - the resolved target.
538
+ * @param signal - optional cancellation.
539
+ * @returns the text chunks.
540
+ */
541
+ streamText(target: FsTarget, signal?: AbortSignal): Promise<AsyncIterable<string>>;
542
+ /**
543
+ * Read one whole regular file as raw bytes, bounded.
544
+ *
545
+ * @param target - the resolved target.
546
+ * @param signal - optional cancellation.
547
+ * @param maxBytes - inclusive byte cap on the content.
548
+ * @returns the bytes.
549
+ */
550
+ readBytes(target: FsTarget, signal: AbortSignal | undefined, maxBytes: number): Promise<Uint8Array>;
551
+ /**
552
+ * Read one byte window of a regular file.
553
+ *
554
+ * @param target - the resolved target.
555
+ * @param range - the window.
556
+ * @param signal - optional cancellation.
557
+ * @returns the window's bytes.
558
+ */
559
+ readByteRange(target: FsTarget, range: {
560
+ offset: number;
561
+ length: number;
562
+ }, signal?: AbortSignal): Promise<Uint8Array>;
563
+ /**
564
+ * List one directory level. The substrate's rows already carry Linux display
565
+ * paths and canonical identities — nothing to rewrite.
566
+ *
567
+ * @param target - the resolved directory.
568
+ * @param signal - optional cancellation.
569
+ * @returns the directory rows.
570
+ */
571
+ listDir(target: FsTarget, signal?: AbortSignal): Promise<FsDirEntry[]>;
572
+ /**
573
+ * Map an absolute host path into this execution world, SYNCHRONOUSLY — the
574
+ * upstream contract (`FileSystem.processPathFromHostPath`) and what its
575
+ * consumers rely on: `packages/spill/spill-policy` passes this method as a
576
+ * plain callback over image attachments, and `packages/api/session-controller`
577
+ * plus the UI's open/reveal path compare the return value against `undefined`
578
+ * without awaiting. The mapping is therefore built from facts that are already
579
+ * known — a UNC host path names its own distro outright; a non-UNC path uses
580
+ * the pinned/config default once `distro()` has resolved it, and the
581
+ * configured `cwd`, or the resolved home for a relative path. A call that
582
+ * would have to ask `wsl.exe` — a cold default distro with no UNC, or a
583
+ * relative path before the home is known — answers `undefined`, which every
584
+ * consumer reads as "no mapping", the same answer the ssh provider gives for
585
+ * a path it cannot map.
586
+ *
587
+ * The VALUE is the world spelling the backend keys on (the UNC identity for a
588
+ * distro path), so the consumers' round trip — map, `resolve`, `processPath`,
589
+ * compare with the original host path — closes exactly as it does for the
590
+ * host backend. Real operations are unaffected: they take the async
591
+ * {@link WslFileSystem.worldPath} and its loud refusals.
592
+ *
593
+ * @param hostPath - an absolute host path (a relative one maps only when the
594
+ * configured `cwd` or a known home gives it a base).
595
+ * @returns the world path for the same file, or undefined when it cannot be
596
+ * mapped with what is already known.
597
+ */
598
+ processPathFromHostPath(hostPath: string): string | undefined;
599
+ /**
600
+ * Watch from inside the distro, where the kernel can actually report change:
601
+ * a long-lived `wsl.exe` poll loop (`lib/watcher.js`) fires the seam's
602
+ * invalidation callback. The seam asks for coarse invalidation, not events,
603
+ * so a poll is honest — and creations and deletions are both seen, because
604
+ * they bump the parent directory's mtime. Replaces the previous flat
605
+ * refusal (`FS_IO_ERROR`), which was the correct answer over 9p only.
606
+ *
607
+ * A target that disappears mid-watch ends the loop with a report through
608
+ * `changed` — never the armed-but-never-fires silence a missing directory
609
+ * would otherwise produce. The scan's depth is `watchMaxDepth`.
610
+ *
611
+ * @param target - the resolved file or directory to observe.
612
+ * @param changed - the invalidation callback.
613
+ * @param signal - cancels initialization; the caller closes an armed watcher.
614
+ * @returns resolves once active, with the async close function.
615
+ */
616
+ watch(target: FsTarget, changed: (error?: Error) => void, signal: AbortSignal): Promise<() => Promise<void>>;
617
+ /**
618
+ * Fence the write by the per-call policy, then publish through the
619
+ * substrate. The fence's fresh target is the one checked and written, so a
620
+ * refusal costs no I/O and cannot be raced by a swapped symlink; the guard
621
+ * rides the write op, where the agent re-verifies it before the rename;
622
+ * the confined resident enforces the mount boundary in the kernel.
623
+ *
624
+ * @param target - the resolved target.
625
+ * @param content - the full new file content.
626
+ * @param expected - the write intent.
627
+ * @param signal - optional cancellation.
628
+ * @param sandboxPolicy - the per-call mode and workspace root; omit for the
629
+ * deployment policy.
630
+ * @returns the write outcome.
631
+ */
632
+ writeText(target: FsTarget, content: string, expected?: FsWriteIntent, signal?: AbortSignal, sandboxPolicy?: SandboxExecutionPolicy): Promise<FsWriteOutcome>;
633
+ /**
634
+ * Fence the edit by the same policy, keeping the guard's observable
635
+ * behaviour.
636
+ *
637
+ * @param target - the resolved target.
638
+ * @param edit - the literal search/replace request.
639
+ * @param expected - the version guard.
640
+ * @param signal - optional cancellation.
641
+ * @param sandboxPolicy - the per-call mode and workspace root; omit for the
642
+ * deployment policy.
643
+ * @returns the edit outcome.
644
+ */
645
+ editText(target: FsTarget, edit: FsEditRequest, expected?: {
646
+ version: FsVersion;
647
+ }, signal?: AbortSignal, sandboxPolicy?: SandboxExecutionPolicy): Promise<FsEditOutcome>;
648
+ /**
649
+ * Apply parsed hunks (protocol 7): hunk matching and application run
650
+ * in-process through the peer's own `applyHunks` (the same dialect and
651
+ * `FS_PATCH_MISMATCH` the peer emits), against the distro's bytes, then
652
+ * publish through the same guarded atomic write an edit takes.
653
+ *
654
+ * @param target - the resolved regular file.
655
+ * @param hunks - ordered hunks from the caller's patch parse.
656
+ * @param expected - the version the patch was based on.
657
+ * @param signal - cancels the patch.
658
+ * @param sandboxPolicy - the per-call policy; omit for the deployment default.
659
+ * @returns the pre/post text and the published version.
660
+ */
661
+ patchText(target: FsTarget, hunks: PatchHunks, expected?: {
662
+ version: FsVersion;
663
+ }, signal?: AbortSignal, sandboxPolicy?: SandboxExecutionPolicy): Promise<FsEditOutcome>;
664
+ /**
665
+ * Remove one regular file (protocol 7) after fencing the target by the
666
+ * per-call policy; the guarded removal re-verifies the expected version
667
+ * distro-side.
668
+ *
669
+ * @param target - the resolved file.
670
+ * @param expected - the version the removal was based on.
671
+ * @param signal - cancels the removal.
672
+ * @param sandboxPolicy - the per-call policy; omit for the deployment default.
673
+ * @returns the bounded pre-removal text basis.
674
+ */
675
+ deleteFile(target: FsTarget, expected?: {
676
+ version: FsVersion;
677
+ }, signal?: AbortSignal, sandboxPolicy?: SandboxExecutionPolicy): Promise<FsDeleteOutcome>;
678
+ /**
679
+ * Move one regular file (protocol 7) after fencing BOTH endpoints by the
680
+ * per-call policy — the destination publishes and the source is removed, so
681
+ * each must be writable under the same roots.
682
+ *
683
+ * @param source - the resolved source.
684
+ * @param destination - the resolved destination.
685
+ * @param options - the hunks and the source/destination guards.
686
+ * @param signal - cancels before publication.
687
+ * @param sandboxPolicy - the per-call policy; omit for the deployment default.
688
+ * @returns the bounded source basis and the destination outcome.
689
+ */
690
+ moveFile(source: FsTarget, destination: FsTarget, options: MoveFileOptions, signal?: AbortSignal, sandboxPolicy?: SandboxExecutionPolicy): Promise<FsMoveOutcome>;
691
+ }
692
+ export {};