dsh-plugin-wsl-env 0.18.0 → 0.21.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 (123) hide show
  1. package/CHANGELOG.md +274 -0
  2. package/CONTRIBUTING.md +37 -5
  3. package/README.md +60 -5
  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/client.d.ts +5 -0
  9. package/client.js +98 -0
  10. package/cordis.patch.yml +66 -1
  11. package/docs/AGENT-PROTOCOL-V7.md +175 -0
  12. package/docs/API.md +25 -0
  13. package/docs/ARCHITECTURE.md +14 -1
  14. package/docs/CONFIGURATION.md +47 -6
  15. package/docs/CONFIGURATION.zh.md +20 -4
  16. package/docs/DIAGNOSTICS.md +83 -0
  17. package/docs/DIAGNOSTICS.zh.md +73 -0
  18. package/docs/LIMITATIONS.md +41 -4
  19. package/docs/LIMITATIONS.zh.md +27 -11
  20. package/docs/MIGRATION.md +4 -4
  21. package/docs/PEER-PARITY.md +50 -33
  22. package/docs/QUICKSTART.md +37 -4
  23. package/docs/QUICKSTART.zh.md +16 -1
  24. package/docs/README.zh.md +43 -4
  25. package/docs/RELEASING.md +4 -1
  26. package/docs/REQUIREMENTS.zh.md +3 -2
  27. package/docs/ROADMAP-1.0.md +75 -19
  28. package/docs/UPSTREAM-FILE-REFERENCE-SEAM.md +8 -1
  29. package/docs/UPSTREAM-OPEN-IN-APP.md +33 -0
  30. package/docs/UPSTREAM-SESSION-NOTICE.md +3 -1
  31. package/docs/UPSTREAM-TERMINAL-TITLE.md +3 -0
  32. package/docs/root-fs-routing.md +3 -3
  33. package/lib/agent-confined.js +4 -4
  34. package/lib/agent-errors.d.ts +1 -1
  35. package/lib/agent-errors.js +1 -1
  36. package/lib/agent-exec.d.ts +1 -1
  37. package/lib/agent-exec.js +1 -1
  38. package/lib/agent-protocol.d.ts +58 -8
  39. package/lib/agent-protocol.js +40 -7
  40. package/lib/agent-shared.d.ts +1 -1
  41. package/lib/agent-shared.js +1 -1
  42. package/lib/agent.d.ts +171 -1
  43. package/lib/agent.js +448 -288
  44. package/lib/auto-preset.d.ts +1 -1
  45. package/lib/auto-preset.js +1 -1
  46. package/lib/bwrap.d.ts +1 -1
  47. package/lib/bwrap.js +1 -1
  48. package/lib/client-host.d.ts +29 -0
  49. package/lib/client-host.js +29 -0
  50. package/lib/cwd-prompt-tool.d.ts +88 -0
  51. package/lib/cwd-prompt-tool.js +94 -0
  52. package/lib/cwd-prompt.d.ts +166 -0
  53. package/lib/cwd-prompt.js +203 -0
  54. package/lib/distro-route.d.ts +1 -1
  55. package/lib/distro-route.js +1 -1
  56. package/lib/doctor-live.d.ts +57 -0
  57. package/lib/doctor-live.js +38 -0
  58. package/lib/file-reference-wsl.d.ts +1 -1
  59. package/lib/file-reference-wsl.js +1 -1
  60. package/lib/fs-decisions.d.ts +1 -1
  61. package/lib/fs-decisions.js +1 -1
  62. package/lib/fs-routing.d.ts +1 -1
  63. package/lib/fs-routing.js +1 -1
  64. package/lib/fs-substrate.d.ts +90 -11
  65. package/lib/fs-substrate.js +202 -1
  66. package/lib/fs.d.ts +1 -1
  67. package/lib/fs.js +1 -1
  68. package/lib/fsio-agent.d.ts +128 -4
  69. package/lib/fsio-agent.js +224 -15
  70. package/lib/fsio-text.d.ts +1 -1
  71. package/lib/fsio-text.js +1 -1
  72. package/lib/git-exec.d.ts +1 -1
  73. package/lib/git-exec.js +1 -1
  74. package/lib/git-route.d.ts +1 -1
  75. package/lib/git-route.js +1 -1
  76. package/lib/index.d.ts +105 -30
  77. package/lib/index.js +272 -130
  78. package/lib/listing.d.ts +1 -1
  79. package/lib/listing.js +1 -1
  80. package/lib/messages.d.ts +157 -0
  81. package/lib/messages.js +199 -0
  82. package/lib/native-agent.d.ts +1 -1
  83. package/lib/native-agent.js +2 -2
  84. package/lib/paths.d.ts +6 -3
  85. package/lib/paths.js +4 -4
  86. package/lib/picker.d.ts +1 -1
  87. package/lib/picker.js +7 -7
  88. package/lib/ports.d.ts +1 -1
  89. package/lib/ports.js +1 -1
  90. package/lib/preflight.d.ts +25 -1
  91. package/lib/preflight.js +112 -12
  92. package/lib/sandbox-core.d.ts +1 -1
  93. package/lib/sandbox-core.js +9 -16
  94. package/lib/sandbox.d.ts +1 -1
  95. package/lib/sandbox.js +1 -1
  96. package/lib/search-exec.d.ts +1 -1
  97. package/lib/search-exec.js +1 -1
  98. package/lib/search-route.d.ts +1 -1
  99. package/lib/search-route.js +1 -1
  100. package/lib/session-runtime.d.ts +1 -1
  101. package/lib/session-runtime.js +2 -2
  102. package/lib/session-scope.d.ts +1 -1
  103. package/lib/session-scope.js +11 -6
  104. package/lib/shell-env.d.ts +26 -1
  105. package/lib/shell-env.js +57 -1
  106. package/lib/shell.d.ts +4 -2
  107. package/lib/shell.js +4 -2
  108. package/lib/subprocess.d.ts +1 -1
  109. package/lib/subprocess.js +2 -2
  110. package/lib/terminal-activity.d.ts +1 -1
  111. package/lib/terminal-activity.js +1 -1
  112. package/lib/terminal-route.d.ts +1 -1
  113. package/lib/terminal-route.js +1 -1
  114. package/lib/update-check.d.ts +197 -0
  115. package/lib/update-check.js +211 -0
  116. package/lib/watcher.d.ts +1 -1
  117. package/lib/watcher.js +1 -1
  118. package/lib/wsl-doctor-tool.d.ts +122 -0
  119. package/lib/wsl-doctor-tool.js +161 -0
  120. package/lib/wsl.d.ts +1 -31
  121. package/lib/wsl.js +1 -21
  122. package/package.json +55 -6
  123. package/scripts/doctor.mjs +1196 -166
@@ -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
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Root host half of `dsh-plugin-wsl-env`: a deliberate no-op plugin.
3
+ *
4
+ * The web client-modules roster only scans Loader rows whose name is an exact
5
+ * package name (`exactPackageSpecifier` rejects subpaths), so the browser half
6
+ * declared under `dsh.client` loads only when this package is mounted at its
7
+ * bare name. The shell executor that used to own `.` cannot serve that role:
8
+ * mounted at the composition root it would shadow the shipped host shell for
9
+ * every session. The two roles therefore split —
10
+ *
11
+ * - `.` (this module): a no-op host half, safe at the composition root; its
12
+ * only job is anchoring the bare-name row whose manifest the roster reads
13
+ * to serve `./client`;
14
+ * - `./shell` (`lib/shell.js`): the session shell executor, mounted inside
15
+ * the WSL agent preset's isolate realm.
16
+ *
17
+ * Compositions that still mount the bare name get the client half (the doctor
18
+ * composer button) and nothing else; the executor keeps its behavior through
19
+ * the explicit subpath. Before 0.20.0 `.` resolved to the executor itself —
20
+ * a profile that relied on that shape must switch to `dsh-plugin-wsl-env/shell`.
21
+ *
22
+ * This is a TypeScript source built to `lib/client-host.js`; edit THIS file and
23
+ * run `pnpm run build` — the artifact under `lib/` is generated, and
24
+ * `pnpm test` fails when it drifts.
25
+ *
26
+ * @module dsh-plugin-wsl-env
27
+ */
28
+ /** A no-op Cordis plugin: no config, no services, no effects. */
29
+ export declare function apply(): void;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Root host half of `dsh-plugin-wsl-env`: a deliberate no-op plugin.
3
+ *
4
+ * The web client-modules roster only scans Loader rows whose name is an exact
5
+ * package name (`exactPackageSpecifier` rejects subpaths), so the browser half
6
+ * declared under `dsh.client` loads only when this package is mounted at its
7
+ * bare name. The shell executor that used to own `.` cannot serve that role:
8
+ * mounted at the composition root it would shadow the shipped host shell for
9
+ * every session. The two roles therefore split —
10
+ *
11
+ * - `.` (this module): a no-op host half, safe at the composition root; its
12
+ * only job is anchoring the bare-name row whose manifest the roster reads
13
+ * to serve `./client`;
14
+ * - `./shell` (`lib/shell.js`): the session shell executor, mounted inside
15
+ * the WSL agent preset's isolate realm.
16
+ *
17
+ * Compositions that still mount the bare name get the client half (the doctor
18
+ * composer button) and nothing else; the executor keeps its behavior through
19
+ * the explicit subpath. Before 0.20.0 `.` resolved to the executor itself —
20
+ * a profile that relied on that shape must switch to `dsh-plugin-wsl-env/shell`.
21
+ *
22
+ * This is a TypeScript source built to `lib/client-host.js`; edit THIS file and
23
+ * run `pnpm run build` — the artifact under `lib/` is generated, and
24
+ * `pnpm test` fails when it drifts.
25
+ *
26
+ * @module dsh-plugin-wsl-env
27
+ */
28
+ /** A no-op Cordis plugin: no config, no services, no effects. */
29
+ export function apply() { }
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Distro-native `working_directory` tool output: serve the model's own
3
+ * read/cd tool with the SAME read/`cd` semantics the harness ships, but with
4
+ * the returned `cwd` rewritten to the distro's POSIX form on a WSL session.
5
+ *
6
+ * The runtime-context rewrite (`lib/cwd-prompt.js`) covers the system-prompt
7
+ * entry and the per-turn snapshot. The `working_directory` tool is the THIRD
8
+ * surface the cwd reaches the model through: `dsh-tool-working-directory`
9
+ * prints `fs.processPath()` verbatim, which on this deployment is the UNC
10
+ * spelling — the one coordinate the distro shell cannot resolve. A model that
11
+ * quotes that path into `bash` fails exactly the failure mode the
12
+ * runtime-context rewrite exists to remove, so the surfaces must agree.
13
+ *
14
+ * This row DISABLES the shipped tool row and mounts a replacement with the
15
+ * same tool name, the same parameters, the same `cd` semantics (the harness's
16
+ * `workingDirectory` service still owns directory validation, resolution, and
17
+ * the durable change), and one difference: the returned `cwd` string has every
18
+ * WSL UNC spelling rewritten to its POSIX form. A non-WSL path passes through
19
+ * byte for byte, so host sessions see the shipped behavior.
20
+ *
21
+ * Advisory by construction. The service reads the harness's
22
+ * `workingDirectory` structurally; a harness without it fails this row's
23
+ * activation loudly (a missing service is a composition error, not a runtime
24
+ * degradation), while every per-call failure is the shipped tool's own — this
25
+ * wrapper adds no I/O and no new failure modes.
26
+ *
27
+ * This is a TypeScript source built to `lib/cwd-prompt-tool.js`; edit THIS
28
+ * file and run `pnpm run build` — the artifact under `lib/` is generated, and
29
+ * `pnpm test` fails when it drifts.
30
+ *
31
+ * @module dsh-plugin-wsl-env/cwd-prompt-tool
32
+ */
33
+ export declare const name = "wsl-cwd-prompt-tool";
34
+ /**
35
+ * The context properties `apply` reads. Cordis 4 refuses an undeclared read —
36
+ * `cannot get property "tools" without inject` — so both the tool registry and
37
+ * the harness's `workingDirectory` service must be named here. Both are
38
+ * required: a host without one fails this row's activation loudly, which is
39
+ * the design (a missing service is a composition error, not a degradation).
40
+ */
41
+ export declare const inject: string[];
42
+ /** The config schema's validated output: the row takes no options. */
43
+ export interface CwdPromptToolConfig {
44
+ /** Reserved; the wrapper has no options today. */
45
+ enabled?: boolean;
46
+ }
47
+ /** The tool registry slice this service consumes. */
48
+ export interface ToolRegistrySlice {
49
+ register: (tool: unknown) => unknown;
50
+ }
51
+ /** The harness's `workingDirectory` service slice the shipped tool uses. */
52
+ export interface WorkingDirectoryToolSlice {
53
+ ensure: (agent: unknown, signal?: unknown) => Promise<string>;
54
+ set: (agent: unknown, path: string, signal?: unknown) => Promise<string>;
55
+ }
56
+ /** The cordis context slice this service consumes. */
57
+ export type CwdPromptToolContext = {
58
+ tools: ToolRegistrySlice;
59
+ workingDirectory: WorkingDirectoryToolSlice;
60
+ };
61
+ /** A resolved tool call: what the shipped tool's `execute` receives. */
62
+ export interface ToolExec {
63
+ /** The live agent, required by the shipped tool too. */
64
+ agent: unknown;
65
+ /** Cancellation for the underlying directory operations. */
66
+ signal?: unknown;
67
+ }
68
+ /** The tool's result: one rewritten absolute path. */
69
+ export interface WorkingDirectoryResult {
70
+ /** The current absolute working directory, distro-native on WSL sessions. */
71
+ cwd: string;
72
+ }
73
+ /**
74
+ * A raw absolute path as the model should see it: the POSIX path a WSL UNC
75
+ * names, and every other path unchanged. This is the single-path sibling of
76
+ * `cwd-prompt.js`'s `rewriteQuotedUnc`, which handles the JSON-quoted texts.
77
+ *
78
+ * @param path - the absolute path the harness produced.
79
+ * @returns the distro-native path, or the input unchanged.
80
+ */
81
+ export declare function rewriteUncPath(path: string): string;
82
+ /**
83
+ * Mount the replacement tool.
84
+ *
85
+ * @param ctx - the cordis context (the composition root, where the shipped
86
+ * tool row is disabled by the patch layer).
87
+ */
88
+ export declare function apply(ctx: CwdPromptToolContext): Promise<void>;
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Distro-native `working_directory` tool output: serve the model's own
3
+ * read/cd tool with the SAME read/`cd` semantics the harness ships, but with
4
+ * the returned `cwd` rewritten to the distro's POSIX form on a WSL session.
5
+ *
6
+ * The runtime-context rewrite (`lib/cwd-prompt.js`) covers the system-prompt
7
+ * entry and the per-turn snapshot. The `working_directory` tool is the THIRD
8
+ * surface the cwd reaches the model through: `dsh-tool-working-directory`
9
+ * prints `fs.processPath()` verbatim, which on this deployment is the UNC
10
+ * spelling — the one coordinate the distro shell cannot resolve. A model that
11
+ * quotes that path into `bash` fails exactly the failure mode the
12
+ * runtime-context rewrite exists to remove, so the surfaces must agree.
13
+ *
14
+ * This row DISABLES the shipped tool row and mounts a replacement with the
15
+ * same tool name, the same parameters, the same `cd` semantics (the harness's
16
+ * `workingDirectory` service still owns directory validation, resolution, and
17
+ * the durable change), and one difference: the returned `cwd` string has every
18
+ * WSL UNC spelling rewritten to its POSIX form. A non-WSL path passes through
19
+ * byte for byte, so host sessions see the shipped behavior.
20
+ *
21
+ * Advisory by construction. The service reads the harness's
22
+ * `workingDirectory` structurally; a harness without it fails this row's
23
+ * activation loudly (a missing service is a composition error, not a runtime
24
+ * degradation), while every per-call failure is the shipped tool's own — this
25
+ * wrapper adds no I/O and no new failure modes.
26
+ *
27
+ * This is a TypeScript source built to `lib/cwd-prompt-tool.js`; edit THIS
28
+ * file and run `pnpm run build` — the artifact under `lib/` is generated, and
29
+ * `pnpm test` fails when it drifts.
30
+ *
31
+ * @module dsh-plugin-wsl-env/cwd-prompt-tool
32
+ */
33
+ import { defineTool } from "@deepseek-ai/dsh-tools";
34
+ import { uncToPosix } from "./paths.js";
35
+ export const name = "wsl-cwd-prompt-tool";
36
+ /**
37
+ * The context properties `apply` reads. Cordis 4 refuses an undeclared read —
38
+ * `cannot get property "tools" without inject` — so both the tool registry and
39
+ * the harness's `workingDirectory` service must be named here. Both are
40
+ * required: a host without one fails this row's activation loudly, which is
41
+ * the design (a missing service is a composition error, not a degradation).
42
+ */
43
+ export const inject = ["tools", "workingDirectory"];
44
+ /**
45
+ * A raw absolute path as the model should see it: the POSIX path a WSL UNC
46
+ * names, and every other path unchanged. This is the single-path sibling of
47
+ * `cwd-prompt.js`'s `rewriteQuotedUnc`, which handles the JSON-quoted texts.
48
+ *
49
+ * @param path - the absolute path the harness produced.
50
+ * @returns the distro-native path, or the input unchanged.
51
+ */
52
+ export function rewriteUncPath(path) {
53
+ const parsed = uncToPosix(path);
54
+ return parsed === undefined ? path : parsed.linuxPath;
55
+ }
56
+ /**
57
+ * Mount the replacement tool.
58
+ *
59
+ * @param ctx - the cordis context (the composition root, where the shipped
60
+ * tool row is disabled by the patch layer).
61
+ */
62
+ export async function apply(ctx) {
63
+ ctx.tools.register(defineTool({
64
+ name: "working_directory",
65
+ description: "Read the current working directory, or change it with cd. Relative paths use the current directory. Existing shells and running processes keep their own directories.",
66
+ parameters: { cd: {
67
+ type: "string",
68
+ description: "Existing directory to enter. Omit to read the current directory.",
69
+ } },
70
+ output: {
71
+ schema: {
72
+ type: "object",
73
+ additionalProperties: false,
74
+ properties: { cwd: {
75
+ type: "string",
76
+ required: true,
77
+ description: "Current absolute working directory.",
78
+ } },
79
+ },
80
+ render: (_args, value) => [{
81
+ type: "text",
82
+ text: value.cwd,
83
+ }],
84
+ },
85
+ async execute(args, exec) {
86
+ if (exec.agent === undefined)
87
+ throw new Error("working_directory requires an agent Session");
88
+ const cwd = args.cd === undefined
89
+ ? await ctx.workingDirectory.ensure(exec.agent, exec.signal)
90
+ : await ctx.workingDirectory.set(exec.agent, args.cd, exec.signal);
91
+ return { cwd: rewriteUncPath(cwd) };
92
+ },
93
+ }));
94
+ }
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Distro-native working directory in the model's runtime context: rewrite the
3
+ * `working-directory:current` entry so a distro session reads its directory as
4
+ * the POSIX path its own commands use, not the host UNC spelling.
5
+ *
6
+ * The harness's `working-directory` service prints the session cwd verbatim,
7
+ * which on this deployment is `\\wsl.localhost\<distro>\...` — the coordinate
8
+ * system of the HOST filesystem, and one the model's tools mostly cannot use
9
+ * directly: the shell executor runs inside the distro, where only the POSIX
10
+ * form resolves. The mismatch is invisible to the harness and costs the model
11
+ * a translation step on every path it quotes back, with a wrong-guess failure
12
+ * mode (a UNC path handed to `bash` names nothing).
13
+ *
14
+ * The value reaches the model through TWO renderings, and both must be
15
+ * covered:
16
+ *
17
+ * 1. the system prompt — the entry as `assemble()` resolves it;
18
+ * 2. the per-turn runtime-context snapshot — `refreshContext()` re-resolves
19
+ * the registry providers DIRECTLY, so a waterfall listener on
20
+ * `system-prompt/assemble` never sees it.
21
+ *
22
+ * Both read the same scoped-layer table, where the nearest scope wins a name
23
+ * (`ScopedLayers.merge`). So the primary mechanism is a session-scoped
24
+ * registration UNDER THE SAME NAME: the entry's provider asks the harness's
25
+ * `workingDirectory` service for the CURRENT directory (so a mid-session `cd`
26
+ * still shows) and rewrites every WSL UNC spelling in it to its POSIX form.
27
+ * A root-level waterfall listener stays as defense in depth for the prompt
28
+ * path on a session where the inject seam is unavailable; the rewrite is
29
+ * idempotent, so the two mechanisms compose without interaction.
30
+ *
31
+ * Advisory by construction. The seams are structural (the plugin's own types
32
+ * spell the slices; docs/UPSTREAM-SESSION-NOTICE.md already relies on the
33
+ * sibling `systemPrompt.context()` seam): a harness without them, an agent
34
+ * whose context is not exposed, or a non-WSL workspace degrades to the
35
+ * shipped behavior — no rewrite, no failure. The rewrite touches one display
36
+ * string; it must never fail a model step.
37
+ *
38
+ * This is a TypeScript source built to `lib/cwd-prompt.js`; edit THIS file and
39
+ * run `pnpm run build` — the artifact under `lib/` is generated, and
40
+ * `pnpm test` fails when it drifts.
41
+ *
42
+ * @module dsh-plugin-wsl-env/cwd-prompt
43
+ */
44
+ import z from "@deepseek-ai/schemastery";
45
+ export declare const name = "wsl-cwd-prompt";
46
+ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
47
+ /** Whether the runtime-context rewrite runs at all. */
48
+ enabled: z<boolean, boolean, "defined">;
49
+ }>>, Schemastery.ObjectT<NoInfer<{
50
+ /** Whether the runtime-context rewrite runs at all. */
51
+ enabled: z<boolean, boolean, "defined">;
52
+ }>>, "plain">;
53
+ /** The config schema's validated output. */
54
+ export interface CwdPromptConfig {
55
+ /** Whether the runtime-context rewrite runs at all. */
56
+ enabled?: boolean;
57
+ }
58
+ /** One named contribution to the assembled system prompt. */
59
+ export interface PromptContextEntry {
60
+ /** The registry name; the harness's entry is `working-directory:current`. */
61
+ name?: string;
62
+ /** The literal contribution text, already resolved by its provider. */
63
+ text?: string;
64
+ /** Present and false on entries that skip prompt-variable interpolation. */
65
+ interpolate?: boolean;
66
+ }
67
+ /** The slice of the assembly the waterfall hands around. */
68
+ export interface PromptAssembly {
69
+ /** The named contributions, ordered by registry order. */
70
+ contexts?: PromptContextEntry[];
71
+ }
72
+ /** The waterfall's continuation; resolves to the (possibly rewritten) assembly. */
73
+ export type AssembleNext = () => Promise<PromptAssembly>;
74
+ /** The waterfall listener's signature, as the harness's own services use it. */
75
+ export type AssembleListener = (assembly: PromptAssembly, context: unknown, next: AssembleNext) => Promise<PromptAssembly>;
76
+ /** The `systemPrompt` slice an injected agent scope exposes. */
77
+ export interface CwdPromptScope {
78
+ systemPrompt: {
79
+ /** Register one context entry in this scope's layer. */
80
+ context: (entry: {
81
+ name: string;
82
+ order: number;
83
+ required: boolean;
84
+ interpolate: boolean;
85
+ text: (context: AssembleRequestContext) => string;
86
+ }) => unknown;
87
+ /** The order constant the harness assigned to a named context family. */
88
+ getContextOrder?: (family: string) => number | undefined;
89
+ };
90
+ }
91
+ /** The assembly request context: what a provider's `text` receives. */
92
+ export interface AssembleRequestContext {
93
+ /** The live agent, when the assembly runs inside one. */
94
+ agent?: {
95
+ session?: {
96
+ header?: {
97
+ cwd?: string | undefined;
98
+ };
99
+ } | undefined;
100
+ } | undefined;
101
+ }
102
+ /** The slice of a created agent this service inspects and injects into. */
103
+ export interface CwdPromptAgent {
104
+ /** The session stub, when mounted. */
105
+ session?: {
106
+ header?: {
107
+ cwd?: string | undefined;
108
+ };
109
+ } | undefined;
110
+ /** The agent's own context, when the harness exposes it. */
111
+ ctx?: {
112
+ inject?: (names: string[], install: (scope: CwdPromptScope) => void) => unknown;
113
+ get?: (name: string) => unknown;
114
+ } | undefined;
115
+ }
116
+ /**
117
+ * The harness's `working-directory` service, read structurally: only `get`
118
+ * is consumed, and its absence degrades to the session header's cwd.
119
+ */
120
+ export interface WorkingDirectorySlice {
121
+ get?: (session: unknown) => string | undefined;
122
+ }
123
+ /** The cordis context slice this service consumes. */
124
+ export type CwdPromptContext = {
125
+ logger?: {
126
+ debug?: (message: string) => void;
127
+ };
128
+ agents?: {
129
+ list: () => CwdPromptAgent[];
130
+ };
131
+ on: ((event: "agent/created", listener: (payload: unknown) => unknown) => () => boolean) & ((event: "system-prompt/assemble", listener: AssembleListener) => () => boolean);
132
+ get?: (name: string) => unknown;
133
+ };
134
+ /**
135
+ * Rewrite every JSON-string-quoted WSL UNC path in one text to its POSIX form.
136
+ * The harness writes the cwd through `JSON.stringify`, so the backslashes are
137
+ * ESCAPED inside the quotes (`"\\\\wsl.localhost\\..."` as rendered text):
138
+ * match a JSON string, parse its inner content, and only rewrite when the raw
139
+ * value is a WSL UNC share. A path that parses to anything else (a drive
140
+ * path, another share, already-POSIX text) passes through unchanged, so the
141
+ * rewrite is safe to re-run.
142
+ *
143
+ * @param text - the contribution text.
144
+ * @returns the text with WSL UNC paths in distro coordinates.
145
+ */
146
+ export declare function rewriteQuotedUnc(text: string): string;
147
+ /**
148
+ * The rewritten entry text for one assembly: ask the harness's service for the
149
+ * CURRENT directory (a mid-session `cd` must show), fall back to the session
150
+ * header's original cwd, and translate only WSL UNC spellings. Everything the
151
+ * regex cannot see passes through untouched, so a host session receives the
152
+ * shipped text byte for byte.
153
+ *
154
+ * @param agent - the agent the assembly runs inside.
155
+ * @param workingDirectory - the harness's service, when resolvable.
156
+ * @returns the entry text.
157
+ */
158
+ export declare function entryText(agent: AssembleRequestContext["agent"], workingDirectory: WorkingDirectorySlice | undefined): string;
159
+ /**
160
+ * Mount the rewrite.
161
+ *
162
+ * @param ctx - the cordis context (the composition root, where the harness's
163
+ * own prompt services register).
164
+ * @param config - the schema-validated plugin config.
165
+ */
166
+ export declare function apply(ctx: CwdPromptContext, config?: CwdPromptConfig): void;
@@ -0,0 +1,203 @@
1
+ /**
2
+ * Distro-native working directory in the model's runtime context: rewrite the
3
+ * `working-directory:current` entry so a distro session reads its directory as
4
+ * the POSIX path its own commands use, not the host UNC spelling.
5
+ *
6
+ * The harness's `working-directory` service prints the session cwd verbatim,
7
+ * which on this deployment is `\\wsl.localhost\<distro>\...` — the coordinate
8
+ * system of the HOST filesystem, and one the model's tools mostly cannot use
9
+ * directly: the shell executor runs inside the distro, where only the POSIX
10
+ * form resolves. The mismatch is invisible to the harness and costs the model
11
+ * a translation step on every path it quotes back, with a wrong-guess failure
12
+ * mode (a UNC path handed to `bash` names nothing).
13
+ *
14
+ * The value reaches the model through TWO renderings, and both must be
15
+ * covered:
16
+ *
17
+ * 1. the system prompt — the entry as `assemble()` resolves it;
18
+ * 2. the per-turn runtime-context snapshot — `refreshContext()` re-resolves
19
+ * the registry providers DIRECTLY, so a waterfall listener on
20
+ * `system-prompt/assemble` never sees it.
21
+ *
22
+ * Both read the same scoped-layer table, where the nearest scope wins a name
23
+ * (`ScopedLayers.merge`). So the primary mechanism is a session-scoped
24
+ * registration UNDER THE SAME NAME: the entry's provider asks the harness's
25
+ * `workingDirectory` service for the CURRENT directory (so a mid-session `cd`
26
+ * still shows) and rewrites every WSL UNC spelling in it to its POSIX form.
27
+ * A root-level waterfall listener stays as defense in depth for the prompt
28
+ * path on a session where the inject seam is unavailable; the rewrite is
29
+ * idempotent, so the two mechanisms compose without interaction.
30
+ *
31
+ * Advisory by construction. The seams are structural (the plugin's own types
32
+ * spell the slices; docs/UPSTREAM-SESSION-NOTICE.md already relies on the
33
+ * sibling `systemPrompt.context()` seam): a harness without them, an agent
34
+ * whose context is not exposed, or a non-WSL workspace degrades to the
35
+ * shipped behavior — no rewrite, no failure. The rewrite touches one display
36
+ * string; it must never fail a model step.
37
+ *
38
+ * This is a TypeScript source built to `lib/cwd-prompt.js`; edit THIS file and
39
+ * run `pnpm run build` — the artifact under `lib/` is generated, and
40
+ * `pnpm test` fails when it drifts.
41
+ *
42
+ * @module dsh-plugin-wsl-env/cwd-prompt
43
+ */
44
+ import z from "@deepseek-ai/schemastery";
45
+ import { isWslUnc, uncToPosix } from "./paths.js";
46
+ export const name = "wsl-cwd-prompt";
47
+ export const Config = z.object({
48
+ /** Whether the runtime-context rewrite runs at all. */
49
+ enabled: z.boolean().default(true),
50
+ });
51
+ /**
52
+ * The context entry name the harness's working-directory service registers.
53
+ * Registering the same name in a session scope shadows it for BOTH renderings
54
+ * (`assemble` and `refreshContext` merge scoped layers over the global one).
55
+ */
56
+ const ENTRY_NAME = "working-directory:current";
57
+ /**
58
+ * Rewrite every JSON-string-quoted WSL UNC path in one text to its POSIX form.
59
+ * The harness writes the cwd through `JSON.stringify`, so the backslashes are
60
+ * ESCAPED inside the quotes (`"\\\\wsl.localhost\\..."` as rendered text):
61
+ * match a JSON string, parse its inner content, and only rewrite when the raw
62
+ * value is a WSL UNC share. A path that parses to anything else (a drive
63
+ * path, another share, already-POSIX text) passes through unchanged, so the
64
+ * rewrite is safe to re-run.
65
+ *
66
+ * @param text - the contribution text.
67
+ * @returns the text with WSL UNC paths in distro coordinates.
68
+ */
69
+ export function rewriteQuotedUnc(text) {
70
+ return String(text).replace(/"((?:[^"\\]|\\.)*)"/gu, (whole, inner) => {
71
+ let raw;
72
+ try {
73
+ // The inner content is a complete JSON string body by construction of
74
+ // the match; a body with an invalid escape fails closed to `whole`.
75
+ raw = JSON.parse(`"${inner}"`);
76
+ }
77
+ catch {
78
+ return whole;
79
+ }
80
+ const parsed = uncToPosix(raw);
81
+ return parsed === undefined ? whole : JSON.stringify(parsed.linuxPath);
82
+ });
83
+ }
84
+ /**
85
+ * The rewritten entry text for one assembly: ask the harness's service for the
86
+ * CURRENT directory (a mid-session `cd` must show), fall back to the session
87
+ * header's original cwd, and translate only WSL UNC spellings. Everything the
88
+ * regex cannot see passes through untouched, so a host session receives the
89
+ * shipped text byte for byte.
90
+ *
91
+ * @param agent - the agent the assembly runs inside.
92
+ * @param workingDirectory - the harness's service, when resolvable.
93
+ * @returns the entry text.
94
+ */
95
+ export function entryText(agent, workingDirectory) {
96
+ const session = agent?.session;
97
+ let directory;
98
+ try {
99
+ directory = session === undefined ? undefined : workingDirectory?.get?.(session);
100
+ }
101
+ catch {
102
+ directory = undefined;
103
+ }
104
+ if (directory === undefined || directory.length === 0)
105
+ directory = session?.header?.cwd ?? "";
106
+ return rewriteQuotedUnc(`Current working directory: ${JSON.stringify(directory)}.`);
107
+ }
108
+ /**
109
+ * Mount the rewrite.
110
+ *
111
+ * @param ctx - the cordis context (the composition root, where the harness's
112
+ * own prompt services register).
113
+ * @param config - the schema-validated plugin config.
114
+ */
115
+ export function apply(ctx, config = {}) {
116
+ const enabled = config.enabled ?? true;
117
+ if (!enabled)
118
+ return;
119
+ const debug = (message) => ctx.logger?.debug?.(message);
120
+ /**
121
+ * Install the session-scoped shadow entry: same name, so it wins the merge;
122
+ * the provider re-reads the current directory on every rendering. Absent on
123
+ * host workspaces (nothing WSL to rewrite) and on agents whose context the
124
+ * harness does not expose (the shipped entry stands).
125
+ *
126
+ * @param agent - the session that just opened.
127
+ */
128
+ const install = (agent) => {
129
+ const cwd = agent.session?.header?.cwd;
130
+ if (cwd === undefined || !isWslUnc(cwd))
131
+ return;
132
+ const agentCtx = agent.ctx;
133
+ if (agentCtx === undefined || typeof agentCtx.inject !== "function")
134
+ return;
135
+ let workingDirectory;
136
+ try {
137
+ const resolved = agentCtx.get?.("workingDirectory");
138
+ if (resolved !== undefined && resolved !== null)
139
+ workingDirectory = /** @type {WorkingDirectorySlice} */ (resolved);
140
+ }
141
+ catch (error) {
142
+ debug(`wsl-cwd-prompt: could not read the workingDirectory service (${error?.message ?? error})`);
143
+ }
144
+ try {
145
+ agentCtx.inject(["systemPrompt"], (scope) => {
146
+ const order = scope.systemPrompt.getContextOrder?.("WORKING_DIRECTORY") ?? 200;
147
+ scope.systemPrompt.context({
148
+ name: ENTRY_NAME,
149
+ order,
150
+ required: true,
151
+ interpolate: false,
152
+ text: (context) => entryText(context?.agent, workingDirectory),
153
+ });
154
+ });
155
+ }
156
+ catch (error) {
157
+ debug(`wsl-cwd-prompt: could not install the shadow entry (${error?.message ?? error})`);
158
+ }
159
+ };
160
+ ctx.on("agent/created", (payload) => {
161
+ // Structural payload: the harness emits { agent } on agent/created.
162
+ const agent = payload?.agent;
163
+ if (agent !== undefined)
164
+ install(agent);
165
+ });
166
+ // Mount order is not a guarantee: a session created during startup can finish
167
+ // before this service mounts and miss the event entirely (dsh-headless does
168
+ // exactly that, and wsl-preflight sweeps for the same reason). `agents` is
169
+ // optional, so read it with `ctx.get`: a property read of an undeclared
170
+ // service throws in cordis 4, and the catch below turns that into a silent
171
+ // no-op — exactly the sweep this block exists to perform.
172
+ try {
173
+ const agents = ctx.get?.("agents");
174
+ for (const agent of agents?.list() ?? [])
175
+ install(agent);
176
+ }
177
+ catch (error) {
178
+ debug(`wsl-cwd-prompt: could not sweep already-live agents: ${error?.message ?? error}`);
179
+ }
180
+ /**
181
+ * Defense in depth for the PROMPT rendering on sessions where the inject
182
+ * seam is unavailable: rewrite the assembled entry in place, then continue
183
+ * the chain. Never throws; an unexpected shape skips the rewrite.
184
+ *
185
+ * @param assembly - the assembly built so far.
186
+ * @param _context - the assembly context (unused).
187
+ * @param next - the waterfall continuation.
188
+ * @returns the downstream assembly.
189
+ */
190
+ const listener = async (assembly, _context, next) => {
191
+ try {
192
+ const entry = assembly?.contexts?.find((candidate) => candidate?.name === ENTRY_NAME);
193
+ if (entry !== undefined && typeof entry.text === "string")
194
+ entry.text = rewriteQuotedUnc(entry.text);
195
+ }
196
+ catch {
197
+ // Display preference, not correctness: skip the rewrite rather than
198
+ // fail the model step this assembly feeds.
199
+ }
200
+ return next();
201
+ };
202
+ ctx.on("system-prompt/assemble", listener);
203
+ }
@@ -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
  /**