dsh-plugin-wsl-env 0.17.1 → 0.19.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 (110) hide show
  1. package/CHANGELOG.md +225 -0
  2. package/CONTRIBUTING.md +37 -5
  3. package/README.md +61 -6
  4. package/SUPPORT.md +3 -3
  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 +331 -11
  8. package/cordis.patch.yml +10 -5
  9. package/docs/AGENT-PROTOCOL-V7.md +175 -0
  10. package/docs/API.md +24 -0
  11. package/docs/ARCHITECTURE.md +20 -6
  12. package/docs/COMPATIBILITY.md +1 -1
  13. package/docs/CONFIGURATION.md +33 -5
  14. package/docs/CONFIGURATION.zh.md +25 -4
  15. package/docs/LIMITATIONS.md +39 -7
  16. package/docs/LIMITATIONS.zh.md +31 -6
  17. package/docs/MIGRATION.md +4 -4
  18. package/docs/PEER-PARITY.md +94 -35
  19. package/docs/QUICKSTART.md +19 -2
  20. package/docs/QUICKSTART.zh.md +16 -1
  21. package/docs/README.zh.md +47 -7
  22. package/docs/RELEASING.md +3 -2
  23. package/docs/REQUIREMENTS.zh.md +11 -6
  24. package/docs/ROADMAP-1.0.md +40 -29
  25. package/docs/ROADMAP.md +10 -6
  26. package/docs/UPSTREAM-FILE-REFERENCE-SEAM.md +6 -1
  27. package/docs/UPSTREAM-FSIO-EXPORT.md +2 -2
  28. package/docs/UPSTREAM-SERVICE-SWAP.md +124 -0
  29. package/docs/UPSTREAM-SESSION-NOTICE.md +3 -1
  30. package/docs/UPSTREAM-TERMINAL-TITLE.md +3 -0
  31. package/docs/root-fs-routing.md +3 -3
  32. package/lib/agent-confined.js +4 -4
  33. package/lib/agent-errors.d.ts +1 -1
  34. package/lib/agent-errors.js +1 -1
  35. package/lib/agent-exec.d.ts +1 -1
  36. package/lib/agent-exec.js +1 -1
  37. package/lib/agent-protocol.d.ts +58 -8
  38. package/lib/agent-protocol.js +40 -7
  39. package/lib/agent-shared.d.ts +1 -1
  40. package/lib/agent-shared.js +1 -1
  41. package/lib/agent.d.ts +171 -1
  42. package/lib/agent.js +448 -288
  43. package/lib/auto-preset.d.ts +1 -1
  44. package/lib/auto-preset.js +1 -1
  45. package/lib/bwrap.d.ts +1 -1
  46. package/lib/bwrap.js +1 -1
  47. package/lib/distro-route.d.ts +1 -1
  48. package/lib/distro-route.js +1 -1
  49. package/lib/doctor-live.d.ts +53 -0
  50. package/lib/doctor-live.js +37 -0
  51. package/lib/file-reference-wsl.d.ts +1 -1
  52. package/lib/file-reference-wsl.js +1 -1
  53. package/lib/fs-decisions.d.ts +1 -1
  54. package/lib/fs-decisions.js +1 -1
  55. package/lib/fs-routing.d.ts +52 -2
  56. package/lib/fs-routing.js +56 -1
  57. package/lib/fs-substrate.d.ts +90 -11
  58. package/lib/fs-substrate.js +202 -1
  59. package/lib/fs.d.ts +1 -1
  60. package/lib/fs.js +1 -1
  61. package/lib/fsio-agent.d.ts +128 -4
  62. package/lib/fsio-agent.js +224 -15
  63. package/lib/fsio-text.d.ts +1 -1
  64. package/lib/fsio-text.js +1 -1
  65. package/lib/git-exec.d.ts +1 -1
  66. package/lib/git-exec.js +1 -1
  67. package/lib/git-route.d.ts +1 -1
  68. package/lib/git-route.js +1 -1
  69. package/lib/index.d.ts +127 -3
  70. package/lib/index.js +301 -99
  71. package/lib/listing.d.ts +1 -1
  72. package/lib/listing.js +1 -1
  73. package/lib/native-agent.d.ts +1 -1
  74. package/lib/native-agent.js +2 -2
  75. package/lib/paths.d.ts +6 -3
  76. package/lib/paths.js +4 -4
  77. package/lib/picker.d.ts +1 -1
  78. package/lib/picker.js +7 -7
  79. package/lib/ports.d.ts +1 -1
  80. package/lib/ports.js +1 -1
  81. package/lib/preflight.d.ts +1 -1
  82. package/lib/preflight.js +1 -1
  83. package/lib/sandbox-core.d.ts +1 -1
  84. package/lib/sandbox-core.js +2 -2
  85. package/lib/sandbox.d.ts +1 -1
  86. package/lib/sandbox.js +1 -1
  87. package/lib/search-exec.d.ts +1 -1
  88. package/lib/search-exec.js +1 -1
  89. package/lib/search-route.d.ts +1 -1
  90. package/lib/search-route.js +1 -1
  91. package/lib/session-runtime.d.ts +1 -1
  92. package/lib/session-runtime.js +2 -2
  93. package/lib/session-scope.d.ts +1 -1
  94. package/lib/session-scope.js +1 -1
  95. package/lib/shell-env.d.ts +1 -1
  96. package/lib/shell-env.js +1 -1
  97. package/lib/shell.d.ts +1 -1
  98. package/lib/shell.js +1 -1
  99. package/lib/subprocess.d.ts +1 -1
  100. package/lib/subprocess.js +2 -2
  101. package/lib/terminal-activity.d.ts +1 -1
  102. package/lib/terminal-activity.js +1 -1
  103. package/lib/terminal-route.d.ts +1 -1
  104. package/lib/terminal-route.js +1 -1
  105. package/lib/watcher.d.ts +1 -1
  106. package/lib/watcher.js +1 -1
  107. package/lib/wsl.d.ts +1 -31
  108. package/lib/wsl.js +1 -21
  109. package/package.json +41 -28
  110. package/scripts/doctor.mjs +34 -11
@@ -31,7 +31,7 @@
31
31
  * run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
32
32
  * fails when it drifts.
33
33
  *
34
- * @module dsh-plugin-wsl/auto-preset
34
+ * @module dsh-plugin-wsl-env/auto-preset
35
35
  */
36
36
  import z from "@deepseek-ai/schemastery";
37
37
  import type { Context } from "@deepseek-ai/cordis";
@@ -31,7 +31,7 @@
31
31
  * run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
32
32
  * fails when it drifts.
33
33
  *
34
- * @module dsh-plugin-wsl/auto-preset
34
+ * @module dsh-plugin-wsl-env/auto-preset
35
35
  */
36
36
  import { appendFileSync } from "node:fs";
37
37
  import z from "@deepseek-ai/schemastery";
package/lib/bwrap.d.ts CHANGED
@@ -21,7 +21,7 @@
21
21
  * `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
22
22
  * fails when it drifts.
23
23
  *
24
- * @module dsh-plugin-wsl/bwrap
24
+ * @module dsh-plugin-wsl-env/bwrap
25
25
  */
26
26
  /** Profile options shared by the two confinement sites. */
27
27
  export interface BwrapProfileOptions {
package/lib/bwrap.js CHANGED
@@ -21,7 +21,7 @@
21
21
  * `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
22
22
  * fails when it drifts.
23
23
  *
24
- * @module dsh-plugin-wsl/bwrap
24
+ * @module dsh-plugin-wsl-env/bwrap
25
25
  */
26
26
  /**
27
27
  * Build the bwrap profile arguments for one file-effect policy, exactly as
@@ -14,7 +14,7 @@
14
14
  * run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
15
15
  * fails when it drifts.
16
16
  *
17
- * @module dsh-plugin-wsl/distro-route
17
+ * @module dsh-plugin-wsl-env/distro-route
18
18
  */
19
19
  /** Why a distro was selected, for diagnostics and for the docs. */
20
20
  export type DistroSource = "pinned" | "workspace" | "default";
@@ -14,7 +14,7 @@
14
14
  * run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
15
15
  * fails when it drifts.
16
16
  *
17
- * @module dsh-plugin-wsl/distro-route
17
+ * @module dsh-plugin-wsl-env/distro-route
18
18
  */
19
19
  import { uncToPosix } from "./paths.js";
20
20
  /**
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The doctor's live-resident merge (WSL-313): the one place where an
3
+ * in-process {@link AgentStatus} may be folded into a doctor report.
4
+ *
5
+ * The doctor CLI (`scripts/doctor.mjs`) is a separate process from the app,
6
+ * so its handshake check can only ever probe a fresh resident; a live
7
+ * resident's `deaths` and `lastError` are host-process state with no IPC to
8
+ * reach them. This module is the sanctioned alternative: callers that hold
9
+ * the plugin's context (the app process itself, through
10
+ * {@link doctorReport}) merge the resident's own `status()` snapshot into a
11
+ * collected report — no transport is invented, and a status that answers for
12
+ * no resident (pid unknown) changes nothing.
13
+ *
14
+ * @module dsh-plugin-wsl-env/doctor-live
15
+ */
16
+ import type { AgentStatus } from "./agent.js";
17
+ /** One check line of the doctor's versioned JSON report. */
18
+ export interface DoctorCheck {
19
+ /** The stable check id, e.g. `agent.handshake`. */
20
+ id: string;
21
+ /** `ok` | `warn` | `fail` | `info`. */
22
+ status: string;
23
+ /** The human detail line. */
24
+ detail?: string;
25
+ /** The copy-paste remedy, when the status is not `ok`. */
26
+ remedy?: string;
27
+ }
28
+ /** The doctor's versioned JSON report shape (`schemaVersion`). */
29
+ export interface DoctorReport {
30
+ /** The report schema version. */
31
+ schemaVersion: number;
32
+ /** Every check, in report order. */
33
+ checks: DoctorCheck[];
34
+ /** Per-status tally. */
35
+ summary: Record<string, number>;
36
+ }
37
+ /**
38
+ * Fold an in-process resident's lifecycle snapshot into a doctor report's
39
+ * `agent.handshake` check.
40
+ *
41
+ * The merge fires only when the status answers for a resident this process
42
+ * actually holds (`pid` known) — a never-started singleton's snapshot says
43
+ * nothing about the app's resident and is ignored, keeping the fresh-probe
44
+ * report honest. A `dead` resident fails the check; a `lastError` on a
45
+ * running resident surfaces as `warn` (the revival budget may already have
46
+ * recovered it); the digest facts the fresh probe established are kept.
47
+ *
48
+ * @param report - the collected doctor report (not mutated).
49
+ * @param status - the in-process `status()` snapshot, when reachable.
50
+ * @returns the report with the merged handshake check; the input object when
51
+ * there is nothing to merge.
52
+ */
53
+ export declare function mergeLiveResidentStatus(report: DoctorReport, status: AgentStatus | undefined): DoctorReport;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Fold an in-process resident's lifecycle snapshot into a doctor report's
3
+ * `agent.handshake` check.
4
+ *
5
+ * The merge fires only when the status answers for a resident this process
6
+ * actually holds (`pid` known) — a never-started singleton's snapshot says
7
+ * nothing about the app's resident and is ignored, keeping the fresh-probe
8
+ * report honest. A `dead` resident fails the check; a `lastError` on a
9
+ * running resident surfaces as `warn` (the revival budget may already have
10
+ * recovered it); the digest facts the fresh probe established are kept.
11
+ *
12
+ * @param report - the collected doctor report (not mutated).
13
+ * @param status - the in-process `status()` snapshot, when reachable.
14
+ * @returns the report with the merged handshake check; the input object when
15
+ * there is nothing to merge.
16
+ */
17
+ export function mergeLiveResidentStatus(report, status) {
18
+ if (!status || status.pid == null)
19
+ return report;
20
+ const fresh = report.checks.find((check) => check.id === "agent.handshake");
21
+ if (!fresh)
22
+ return report;
23
+ const errorLine = status.lastError.length > 0 ? `; lastError: ${status.lastError}` : "";
24
+ const merged = {
25
+ id: fresh.id,
26
+ status: status.state === "dead" ? "fail" : status.lastError.length > 0 ? "warn" : fresh.status,
27
+ detail: `probed: the live resident (pid ${status.pid}, state ${status.state}, deaths ${status.deaths}, pending ${status.pending})${errorLine}; fresh-probe facts: ${fresh.detail ?? ""}`,
28
+ ...(fresh.remedy !== undefined ? { remedy: fresh.remedy } : {}),
29
+ };
30
+ const checks = report.checks.map((check) => (check === fresh ? merged : check));
31
+ const summary = { ...report.summary };
32
+ if (merged.status !== fresh.status) {
33
+ summary[fresh.status] = Math.max(0, (summary[fresh.status] ?? 0) - 1);
34
+ summary[merged.status] = (summary[merged.status] ?? 0) + 1;
35
+ }
36
+ return { ...report, checks, summary };
37
+ }
@@ -42,7 +42,7 @@
42
42
  * file and run `pnpm run build` — the artifact under `lib/` is generated, and
43
43
  * `pnpm test` fails when it drifts.
44
44
  *
45
- * @module dsh-plugin-wsl/file-reference-wsl
45
+ * @module dsh-plugin-wsl-env/file-reference-wsl
46
46
  */
47
47
  import type { WslAgent } from "./agent.js";
48
48
  /**
@@ -42,7 +42,7 @@
42
42
  * file and run `pnpm run build` — the artifact under `lib/` is generated, and
43
43
  * `pnpm test` fails when it drifts.
44
44
  *
45
- * @module dsh-plugin-wsl/file-reference-wsl
45
+ * @module dsh-plugin-wsl-env/file-reference-wsl
46
46
  */
47
47
  import { isWslUnc, posixToUnc, uncToPosix } from "./paths.js";
48
48
  /** Upstream's default cap on one workspace index; the per-directory listing
@@ -15,7 +15,7 @@
15
15
  * and run `pnpm run build` — the artifact under `lib/` is generated, and
16
16
  * `pnpm test` fails when it drifts.
17
17
  *
18
- * @module dsh-plugin-wsl/fs-decisions
18
+ * @module dsh-plugin-wsl-env/fs-decisions
19
19
  */
20
20
  /** A refusal descriptor the provider wraps in `FsError` at one choke point. */
21
21
  export interface Refusal {
@@ -15,7 +15,7 @@
15
15
  * and run `pnpm run build` — the artifact under `lib/` is generated, and
16
16
  * `pnpm test` fails when it drifts.
17
17
  *
18
- * @module dsh-plugin-wsl/fs-decisions
18
+ * @module dsh-plugin-wsl-env/fs-decisions
19
19
  */
20
20
  import { isAnotherDistrosUnc } from "./paths.js";
21
21
  /**
@@ -28,14 +28,20 @@
28
28
  * run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
29
29
  * fails when it drifts.
30
30
  *
31
- * @module dsh-plugin-wsl/fs-routing
31
+ * @module dsh-plugin-wsl-env/fs-routing
32
32
  */
33
33
  import z from "@deepseek-ai/schemastery";
34
34
  import { LocalFileSystem } from "@deepseek-ai/dsh-fs-local";
35
35
  import { WslFileSystem } from "./index.js";
36
36
  import type { Context } from "@deepseek-ai/cordis";
37
- import type { FsTarget, FsVersion, FsWriteIntent, FsEditRequest } from "@deepseek-ai/dsh-fs";
37
+ import type { FileSystem, FsEditRequest, FsTarget, FsVersion, FsWriteIntent } from "@deepseek-ai/dsh-fs";
38
38
  import type { SandboxExecutionPolicy } from "@deepseek-ai/dsh-sandbox";
39
+ /**
40
+ * The 0.2.2-rc.1 patch/move parameter shapes, derived from the peer's abstract
41
+ * surface so this file needs no dependency on `@deepseek-ai/dsh-fs-patch`.
42
+ */
43
+ type PatchHunks = Parameters<FileSystem["patchText"]>[1];
44
+ type MoveFileOptions = Parameters<FileSystem["moveFile"]>[2];
39
45
  /**
40
46
  * The router's config: the host backend's own knobs plus the distro knobs the
41
47
  * routed backend reads. The distro keys are `??`-defaulted, so a host-only
@@ -203,6 +209,50 @@ export declare class WslRoutingFileSystem extends LocalFileSystem {
203
209
  editText(target: FsTarget, edit: FsEditRequest, expected?: {
204
210
  version: FsVersion;
205
211
  }, signal?: AbortSignal, sandboxPolicy?: SandboxExecutionPolicy): Promise<import("@deepseek-ai/dsh-fs").FsEditOutcome>;
212
+ /**
213
+ * Route the peer's 0.2.2-rc.1 patch operation by the same coordinate rule
214
+ * as {@link editText}: a distro target reaches the distro backend (which
215
+ * refuses the operation honestly — the agent substrate has no patch op),
216
+ * a Windows target keeps the inherited host implementation.
217
+ *
218
+ * @param target - the resolved target.
219
+ * @param hunks - ordered hunks from the caller's patch parse.
220
+ * @param expected - the version the patch was based on.
221
+ * @param signal - cancels the patch.
222
+ * @param sandboxPolicy - the confined policy the distro side honors; the
223
+ * host backend takes no such parameter.
224
+ */
225
+ patchText(target: FsTarget, hunks: PatchHunks, expected?: {
226
+ version: FsVersion;
227
+ }, signal?: AbortSignal, sandboxPolicy?: SandboxExecutionPolicy): Promise<import("@deepseek-ai/dsh-fs").FsEditOutcome>;
228
+ /**
229
+ * Route the peer's 0.2.2-rc.1 delete operation like {@link patchText}:
230
+ * distro targets refuse at the distro backend, Windows targets keep the
231
+ * inherited host implementation.
232
+ *
233
+ * @param target - the resolved target.
234
+ * @param expected - the version the removal was based on.
235
+ * @param signal - cancels the removal.
236
+ * @param sandboxPolicy - the confined policy the distro side honors; the
237
+ * host backend takes no such parameter.
238
+ */
239
+ deleteFile(target: FsTarget, expected?: {
240
+ version: FsVersion;
241
+ }, signal?: AbortSignal, sandboxPolicy?: SandboxExecutionPolicy): Promise<import("@deepseek-ai/dsh-fs").FsDeleteOutcome>;
242
+ /**
243
+ * Route the peer's 0.2.2-rc.1 move operation like {@link patchText}: any
244
+ * distro-side endpoint sends the call to the distro backend (which refuses
245
+ * it honestly), two Windows endpoints keep the inherited host
246
+ * implementation.
247
+ *
248
+ * @param source - the resolved source.
249
+ * @param destination - the resolved destination.
250
+ * @param options - the hunks and the source/destination guards.
251
+ * @param signal - checked before the destination stages.
252
+ * @param sandboxPolicy - the confined policy the distro side honors; the
253
+ * host backend takes no such parameter.
254
+ */
255
+ moveFile(source: FsTarget, destination: FsTarget, options: MoveFileOptions, signal?: AbortSignal, sandboxPolicy?: SandboxExecutionPolicy): Promise<import("@deepseek-ai/dsh-fs").FsMoveOutcome>;
206
256
  /**
207
257
  * @param target - the resolved target.
208
258
  * @param changed - the change callback.
package/lib/fs-routing.js CHANGED
@@ -28,7 +28,7 @@
28
28
  * run `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
29
29
  * fails when it drifts.
30
30
  *
31
- * @module dsh-plugin-wsl/fs-routing
31
+ * @module dsh-plugin-wsl-env/fs-routing
32
32
  */
33
33
  import { isWslUnc, uncToPosix } from "./paths.js";
34
34
  import z from "@deepseek-ai/schemastery";
@@ -281,6 +281,61 @@ export class WslRoutingFileSystem extends LocalFileSystem {
281
281
  }
282
282
  return super.editText(target, edit, expected, signal);
283
283
  }
284
+ /**
285
+ * Route the peer's 0.2.2-rc.1 patch operation by the same coordinate rule
286
+ * as {@link editText}: a distro target reaches the distro backend (which
287
+ * refuses the operation honestly — the agent substrate has no patch op),
288
+ * a Windows target keeps the inherited host implementation.
289
+ *
290
+ * @param target - the resolved target.
291
+ * @param hunks - ordered hunks from the caller's patch parse.
292
+ * @param expected - the version the patch was based on.
293
+ * @param signal - cancels the patch.
294
+ * @param sandboxPolicy - the confined policy the distro side honors; the
295
+ * host backend takes no such parameter.
296
+ */
297
+ async patchText(target, hunks, expected, signal, sandboxPolicy) {
298
+ if (targetIsDistro(target.targetKey)) {
299
+ return (await this.distro()).patchText(target, hunks, expected, signal, sandboxPolicy);
300
+ }
301
+ return super.patchText(target, hunks, expected, signal);
302
+ }
303
+ /**
304
+ * Route the peer's 0.2.2-rc.1 delete operation like {@link patchText}:
305
+ * distro targets refuse at the distro backend, Windows targets keep the
306
+ * inherited host implementation.
307
+ *
308
+ * @param target - the resolved target.
309
+ * @param expected - the version the removal was based on.
310
+ * @param signal - cancels the removal.
311
+ * @param sandboxPolicy - the confined policy the distro side honors; the
312
+ * host backend takes no such parameter.
313
+ */
314
+ async deleteFile(target, expected, signal, sandboxPolicy) {
315
+ if (targetIsDistro(target.targetKey)) {
316
+ return (await this.distro()).deleteFile(target, expected, signal, sandboxPolicy);
317
+ }
318
+ return super.deleteFile(target, expected, signal);
319
+ }
320
+ /**
321
+ * Route the peer's 0.2.2-rc.1 move operation like {@link patchText}: any
322
+ * distro-side endpoint sends the call to the distro backend (which refuses
323
+ * it honestly), two Windows endpoints keep the inherited host
324
+ * implementation.
325
+ *
326
+ * @param source - the resolved source.
327
+ * @param destination - the resolved destination.
328
+ * @param options - the hunks and the source/destination guards.
329
+ * @param signal - checked before the destination stages.
330
+ * @param sandboxPolicy - the confined policy the distro side honors; the
331
+ * host backend takes no such parameter.
332
+ */
333
+ async moveFile(source, destination, options, signal, sandboxPolicy) {
334
+ if (targetIsDistro(source.targetKey) || targetIsDistro(destination.targetKey)) {
335
+ return (await this.distro()).moveFile(source, destination, options, signal, sandboxPolicy);
336
+ }
337
+ return super.moveFile(source, destination, options, signal);
338
+ }
284
339
  /**
285
340
  * @param target - the resolved target.
286
341
  * @param changed - the change callback.
@@ -28,20 +28,12 @@
28
28
  * and run `pnpm run build` — the artifact under `lib/` is generated, and
29
29
  * `pnpm test` fails when it drifts.
30
30
  *
31
- * @module dsh-plugin-wsl/fs-substrate
31
+ * @module dsh-plugin-wsl-env/fs-substrate
32
32
  */
33
+ import type { PatchHunk } from "@deepseek-ai/dsh-fs-patch";
34
+ import { ResolvedTarget } from "./fsio-agent.js";
33
35
  import { DistroFs } from "./fsio-agent.js";
34
36
  import type { WslAgent } from "./agent.js";
35
- /**
36
- * A resolved target: the Linux spelling the model sees and the UNC identity
37
- * the harness keys on, as returned by {@linkcode AgentSubstrate#resolve}.
38
- */
39
- export interface ResolvedTarget {
40
- /** The canonical Linux path spelling. */
41
- displayPath: string;
42
- /** The UNC identity this target keys on. */
43
- targetKey: string;
44
- }
45
37
  /**
46
38
  * One distro's provider-shaped filesystem face.
47
39
  */
@@ -256,5 +248,92 @@ export declare class AgentSubstrate {
256
248
  before: string;
257
249
  after: string;
258
250
  }>;
251
+ /**
252
+ * Apply parsed hunks to a text file (protocol 7): the peer's `patchText`
253
+ * semantics, using the peer's own `applyHunks` for matching and its exact
254
+ * `FS_PATCH_MISMATCH` dialect, then the same guarded atomic publication a
255
+ * write takes. The hunks travel in-process; the distro sees one read and
256
+ * one guarded replace.
257
+ *
258
+ * @param target - the resolved regular file.
259
+ * @param hunks - ordered hunks from the caller's patch parse.
260
+ * @param expected - the version the patch was based on.
261
+ * @param signal - cancels the patch.
262
+ * @param policy - the resolved policy this patch was fenced with.
263
+ * @returns the pre/post text and the published version.
264
+ */
265
+ patchText(target: ResolvedTarget, hunks: readonly PatchHunk[], expected: {
266
+ version: string;
267
+ } | undefined, signal?: AbortSignal, policy?: {
268
+ mode: string;
269
+ workspaceRoot: string;
270
+ sessionId?: string;
271
+ } | undefined): Promise<{
272
+ version: string;
273
+ before: string;
274
+ after: string;
275
+ }>;
276
+ /**
277
+ * Remove one regular file (protocol 7), mirroring the peer's
278
+ * `deleteFile`: missing/stale/mismatched targets refuse, the read-basis is
279
+ * best effort and bounded by `diffBasisMaxBytes`, and the removal itself is
280
+ * re-guarded distro-side by the expected version.
281
+ *
282
+ * @param target - the resolved file.
283
+ * @param expected - the version the removal was based on.
284
+ * @param signal - cancels the removal.
285
+ * @param policy - the resolved policy this removal was fenced with.
286
+ * @returns the bounded pre-removal text basis.
287
+ */
288
+ deleteFile(target: ResolvedTarget, expected: {
289
+ version: string;
290
+ } | undefined, signal?: AbortSignal, policy?: {
291
+ mode: string;
292
+ workspaceRoot: string;
293
+ sessionId?: string;
294
+ } | undefined): Promise<{
295
+ before: string | null;
296
+ }>;
297
+ /**
298
+ * Move a regular file (protocol 7), mirroring the peer's `moveFile`: the
299
+ * source passes `requireFile`, the destination `writeTarget`, an optional
300
+ * hunk set transforms the text on the way, and the two effects (publish,
301
+ * remove) are reported separately — a destination that landed while the
302
+ * source survived returns `sourceDeleted: false` plus the failure.
303
+ *
304
+ * @param source - the resolved source.
305
+ * @param destination - the resolved destination.
306
+ * @param options - the hunks and the source/destination guards.
307
+ * @param signal - cancels before publication.
308
+ * @param policy - the resolved policy both paths run under.
309
+ * @returns the bounded source basis and the destination outcome.
310
+ */
311
+ moveFile(source: ResolvedTarget, destination: ResolvedTarget, options: {
312
+ hunks?: readonly PatchHunk[];
313
+ expectedSource?: {
314
+ version: string;
315
+ };
316
+ expectedDestination?: {
317
+ kind: string;
318
+ version?: string;
319
+ };
320
+ }, signal?: AbortSignal, policy?: {
321
+ mode: string;
322
+ workspaceRoot: string;
323
+ sessionId?: string;
324
+ } | undefined): Promise<{
325
+ sourceBefore: string | null;
326
+ sourceDeleted: boolean;
327
+ sourceFailure?: {
328
+ code: string;
329
+ message: string;
330
+ };
331
+ destination: {
332
+ operation: string;
333
+ version: string;
334
+ before: string | null;
335
+ after: string;
336
+ };
337
+ }>;
259
338
  }
260
339
  export default AgentSubstrate;