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
@@ -0,0 +1,157 @@
1
+ /**
2
+ * The language the plugin's runtime refusal and remedy messages render in,
3
+ * following the harness app's locale setting.
4
+ *
5
+ * The preference lives in the host composition as the `locale` entry's
6
+ * `preference` field (`@deepseek-ai/dsh-client-locale`'s host half declares it
7
+ * volatile), persisted through the host `settings` service. This module reads
8
+ * it through an OPTIONAL `settings` injection — the service belongs to the
9
+ * base bundle, and a profile without it (or a `settings` that never resolves)
10
+ * keeps the English defaults, which is also every test's default. A language
11
+ * switch re-reads on the service's `settings/document-updated` event, so
12
+ * following the remedy or switching language needs no app restart.
13
+ *
14
+ * Only plugin-authored text is cataloged here. The `fs-decisions` refusals and
15
+ * the fsio replica stay byte-identical English — the tool layer matches on
16
+ * those strings (see `src/fs-decisions.ts` and `docs/UPSTREAM-FSIO-EXPORT.md`).
17
+ *
18
+ * This is a TypeScript source built to `lib/messages.js`; edit THIS file and
19
+ * run `pnpm run build` — the artifact under `lib/` is generated, and
20
+ * `pnpm test` fails when it drifts.
21
+ *
22
+ * @module dsh-plugin-wsl-env/messages
23
+ */
24
+ import type { Context } from "@deepseek-ai/cordis";
25
+ /** The languages the catalogs ship. More locales are additive: add a table and widen the resolver. */
26
+ export type MessagesLocale = "en" | "zh";
27
+ /**
28
+ * The message templates, keyed by call site. Each entry owns its parameter
29
+ * shape; the `zh` table is type-checked against the `en` table's key and
30
+ * parameter union, so the two catalogs cannot drift apart silently.
31
+ */
32
+ declare const en: {
33
+ /** `sessionScopeProblem`: systemd is not PID 1 in the distro. */
34
+ sessionScopeNoSystemd: ({ distro }: {
35
+ distro: string;
36
+ }) => string;
37
+ /** `sessionScopeProblem`: `systemctl --user` does not answer. */
38
+ sessionScopeNoUserManager: ({ distro }: {
39
+ distro: string;
40
+ }) => string;
41
+ /** `sessionScopeProblem`: the `systemd-run` binary is missing. */
42
+ sessionScopeNoSystemdRun: ({ distro }: {
43
+ distro: string;
44
+ }) => string;
45
+ /** `sessionScopeProblem`: the user manager would stop with the last session. */
46
+ sessionScopeNoLinger: ({ distro }: {
47
+ distro: string;
48
+ }) => string;
49
+ /**
50
+ * `sessionScopeProblem`: the probe's answer is empty or unrecognized. The
51
+ * caller renders `answer` (the quoted word, or `(nothing)`) and `errorSuffix`
52
+ * (`""` or `": <error>"`) so both languages keep one sentence shape.
53
+ */
54
+ sessionScopeUnknownAnswer: ({ distro, answer, errorSuffix }: {
55
+ distro: string;
56
+ answer: string;
57
+ errorSuffix: string;
58
+ }) => string;
59
+ /** `missingBwrapRemedy` without a detected package family. */
60
+ bwrapMissingGeneric: ({ distro }: {
61
+ distro: string;
62
+ }) => string;
63
+ /** `missingBwrapRemedy` with a family's direct install command. */
64
+ bwrapMissingFamily: ({ distro, direct }: {
65
+ distro: string;
66
+ direct: string;
67
+ }) => string;
68
+ /** `composeBwrapFailure`: bwrap ran and refused — present but unusable. */
69
+ bwrapBroken: ({ distro, output }: {
70
+ distro: string;
71
+ output: string;
72
+ }) => string;
73
+ /** `bwrapInstallHint`: bwrap probed healthy but failed a real command. */
74
+ bwrapRuntimeFailure: ({ distro }: {
75
+ distro: string;
76
+ }) => string;
77
+ /** `composeBwrapFailure`: the unclassified probe's raw output, appended to a remedy. */
78
+ bwrapProbeFailedSuffix: ({ output }: {
79
+ output: string;
80
+ }) => string;
81
+ /** `throwIfDistroUnavailable`: wsl.exe says the distro is gone. */
82
+ distroUnavailable: ({ code, distro }: {
83
+ code: string;
84
+ distro: string;
85
+ }) => string;
86
+ /** `throwIfWorkdirMissing`: `wsl.exe --cd` fell back to `/`. */
87
+ workdirMissing: ({ missing }: {
88
+ missing: string;
89
+ }) => string;
90
+ /** `throwIfWorkdirInAnotherDistro`: the workspace names a pinned-against distro. */
91
+ workdirAnotherDistro: ({ workdir, distro }: {
92
+ workdir: string;
93
+ distro: string;
94
+ }) => string;
95
+ };
96
+ type Catalog = typeof en;
97
+ type MessageKey = keyof Catalog;
98
+ /**
99
+ * The locale the message builders render in.
100
+ *
101
+ * @returns the active catalog language.
102
+ */
103
+ export declare function messagesLocale(): MessagesLocale;
104
+ /**
105
+ * Force the message language. The wiring calls this from the resolved
106
+ * `locale.preference`; tests call it directly and reset afterwards.
107
+ *
108
+ * @param locale - the language to render in.
109
+ */
110
+ export declare function configureMessagesLocale(locale: MessagesLocale): void;
111
+ /**
112
+ * Render one message in the active language, falling back to the English
113
+ * template when the active catalog somehow lacks the key (the catalogs are
114
+ * type-checked against each other, so this guards runtime drift only).
115
+ *
116
+ * The `params` type correlates the parameters with the key: the conditional
117
+ * resolves per call site, so `t("sessionScopeNoLinger", { distro })`
118
+ * typechecks while `t("sessionScopeNoLinger", { missing })` does not. It
119
+ * lives in the JSDoc because a comment between the parameters would have the
120
+ * type-stripping build emit a line with trailing whitespace, which the style
121
+ * gate refuses.
122
+ *
123
+ * @typeParam K - the message key.
124
+ * @param key - the message to render.
125
+ * @param params - the key's parameters, as the template declares them.
126
+ * @returns the rendered message.
127
+ */
128
+ export declare function t<K extends MessageKey>(key: K, params: Catalog[K] extends (first: infer P) => string ? P : never): string;
129
+ /**
130
+ * Map one `locale.preference` value onto a catalog language. The app's
131
+ * language ids are BCP 47-style tags (`zh`, `en`, `ja`, …); the plugin ships
132
+ * zh and en, and every other id renders English.
133
+ *
134
+ * @param preference - the stored preference, or anything else when unset.
135
+ * @returns the catalog language the preference selects.
136
+ */
137
+ export declare function resolveMessagesLocale(preference: unknown): MessagesLocale;
138
+ /**
139
+ * Follow the harness locale for the caller's composition. Every row wires its
140
+ * own injection (the shell executor, the fs provider and the preflight all
141
+ * call this), so a hot-reloaded row re-wires too; the redundant reads converge
142
+ * on the same app-wide preference and the events are rare.
143
+ *
144
+ * The `settings` service is optional — a profile without it (some CLI
145
+ * compositions) keeps English. When it is present, the preference is read once
146
+ * the service resolves and again on every `settings/document-updated` event,
147
+ * which also covers the `locale` entry activating after this row did. A read
148
+ * that throws keeps the previous language: this is presentation, not gating.
149
+ *
150
+ * @param ctx - the row's composition context.
151
+ */
152
+ export declare function installMessagesLocale(ctx: Context): void;
153
+ /**
154
+ * Restore English. Tests only: production wiring is process-wide by design.
155
+ */
156
+ export declare function resetMessagesLocaleForTests(): void;
157
+ export {};
@@ -0,0 +1,199 @@
1
+ /**
2
+ * The language the plugin's runtime refusal and remedy messages render in,
3
+ * following the harness app's locale setting.
4
+ *
5
+ * The preference lives in the host composition as the `locale` entry's
6
+ * `preference` field (`@deepseek-ai/dsh-client-locale`'s host half declares it
7
+ * volatile), persisted through the host `settings` service. This module reads
8
+ * it through an OPTIONAL `settings` injection — the service belongs to the
9
+ * base bundle, and a profile without it (or a `settings` that never resolves)
10
+ * keeps the English defaults, which is also every test's default. A language
11
+ * switch re-reads on the service's `settings/document-updated` event, so
12
+ * following the remedy or switching language needs no app restart.
13
+ *
14
+ * Only plugin-authored text is cataloged here. The `fs-decisions` refusals and
15
+ * the fsio replica stay byte-identical English — the tool layer matches on
16
+ * those strings (see `src/fs-decisions.ts` and `docs/UPSTREAM-FSIO-EXPORT.md`).
17
+ *
18
+ * This is a TypeScript source built to `lib/messages.js`; edit THIS file and
19
+ * run `pnpm run build` — the artifact under `lib/` is generated, and
20
+ * `pnpm test` fails when it drifts.
21
+ *
22
+ * @module dsh-plugin-wsl-env/messages
23
+ */
24
+ /**
25
+ * The message templates, keyed by call site. Each entry owns its parameter
26
+ * shape; the `zh` table is type-checked against the `en` table's key and
27
+ * parameter union, so the two catalogs cannot drift apart silently.
28
+ */
29
+ const en = {
30
+ /** `sessionScopeProblem`: systemd is not PID 1 in the distro. */
31
+ sessionScopeNoSystemd: ({ distro }) => `sessionSandbox needs systemd as PID 1 in "${distro}": set [boot] systemd=true in /etc/wsl.conf, run "wsl --shutdown", and reopen the session.`,
32
+ /** `sessionScopeProblem`: `systemctl --user` does not answer. */
33
+ sessionScopeNoUserManager: ({ distro }) => `sessionSandbox needs a reachable systemd user manager in "${distro}": log in to the distro once, or enable lingering (see the next refusal).`,
34
+ /** `sessionScopeProblem`: the `systemd-run` binary is missing. */
35
+ sessionScopeNoSystemdRun: ({ distro }) => `sessionSandbox needs "systemd-run" in "${distro}"; the distro's systemd package is incomplete or missing.`,
36
+ /** `sessionScopeProblem`: the user manager would stop with the last session. */
37
+ sessionScopeNoLinger: ({ distro }) => `sessionSandbox needs the user manager to outlive a login session: run "loginctl enable-linger $USER" in "${distro}" and retry.`,
38
+ /**
39
+ * `sessionScopeProblem`: the probe's answer is empty or unrecognized. The
40
+ * caller renders `answer` (the quoted word, or `(nothing)`) and `errorSuffix`
41
+ * (`""` or `": <error>"`) so both languages keep one sentence shape.
42
+ */
43
+ sessionScopeUnknownAnswer: ({ distro, answer, errorSuffix }) => `the sessionSandbox preflight in "${distro}" answered ${answer}${errorSuffix}; see docs/adr/0001-session-scoped-sandbox.md.`,
44
+ /** `missingBwrapRemedy` without a detected package family. */
45
+ bwrapMissingGeneric: ({ distro }) => `bwrap is not usable inside distro "${distro}". Install it with ` +
46
+ `"scripts/bootstrap.sh ${distro} --install" (from the package), or install the ` +
47
+ `"bubblewrap" package with the distro's package manager.`,
48
+ /** `missingBwrapRemedy` with a family's direct install command. */
49
+ bwrapMissingFamily: ({ distro, direct }) => `bwrap is not usable inside distro "${distro}". Install it with ` +
50
+ `"scripts/bootstrap.sh ${distro} --install" (from the package), or directly: ` +
51
+ `wsl.exe -d ${distro} -u root -- ${direct}`,
52
+ /** `composeBwrapFailure`: bwrap ran and refused — present but unusable. */
53
+ bwrapBroken: ({ distro, output }) => `bwrap is installed inside distro "${distro}" but failed the usability probe: ${output}. ` +
54
+ `This is usually the kernel (unprivileged user namespaces disabled) or an unusable bwrap build rather than a missing package, so reinstalling will not help. ` +
55
+ `Check \`wsl.exe -d ${distro} --exec bwrap --version\` inside the distro, or set \`sandbox: false\` on the wsl-shell and wsl-fs rows to run unconfined.`,
56
+ /** `bwrapInstallHint`: bwrap probed healthy but failed a real command. */
57
+ bwrapRuntimeFailure: ({ distro }) => `bwrap failed at run time inside distro "${distro}". Check \`bwrap --version\` there, ` +
58
+ `or reinstall it: "scripts/bootstrap.sh ${distro} --install".`,
59
+ /** `composeBwrapFailure`: the unclassified probe's raw output, appended to a remedy. */
60
+ bwrapProbeFailedSuffix: ({ output }) => ` The probe failed with: ${output}`,
61
+ /** `throwIfDistroUnavailable`: wsl.exe says the distro is gone. */
62
+ distroUnavailable: ({ code, distro }) => `wsl.exe reported ${code} for distro "${distro}": it is not installed, or not running. ` +
63
+ `Start it with \`wsl.exe -d ${distro}\`, check \`wsl.exe -l -v\`, or point \`distro\` at another one. ` +
64
+ `This is not a sandbox denial, so running with wider permissions will not help.`,
65
+ /** `throwIfWorkdirMissing`: `wsl.exe --cd` fell back to `/`. */
66
+ workdirMissing: ({ missing }) => `wsl.exe could not enter the working directory "${missing}" inside the distro, so the command ran from "/" instead. ` +
67
+ `Create it, or point \`cwd\` (or the request's \`workdir\`) at a directory that exists.`,
68
+ /** `throwIfWorkdirInAnotherDistro`: the workspace names a pinned-against distro. */
69
+ workdirAnotherDistro: ({ workdir, distro }) => `"${workdir}" names a workspace in another WSL distro, and this profile pins its commands to "${distro}" — ` +
70
+ `running them here would act on a different machine's tree. Open a session in that distro, ` +
71
+ `or point cwd/workdir at this distro.`,
72
+ };
73
+ /** The Chinese catalog; the type keeps every key and parameter in step with `en`. */
74
+ const zh = {
75
+ sessionScopeNoSystemd: ({ distro }) => `sessionSandbox 需要在 "${distro}" 中以 systemd 作为 PID 1:在 /etc/wsl.conf 中设置 [boot] systemd=true,运行 "wsl --shutdown",然后重新打开会话。`,
76
+ sessionScopeNoUserManager: ({ distro }) => `sessionSandbox 需要能访问 "${distro}" 中的 systemd 用户管理器:先在发行版中登录一次,或启用 lingering(见下一条拒绝说明)。`,
77
+ sessionScopeNoSystemdRun: ({ distro }) => `sessionSandbox 需要 "${distro}" 中存在 "systemd-run";该发行版的 systemd 软件包不完整或缺失。`,
78
+ sessionScopeNoLinger: ({ distro }) => `sessionSandbox 需要用户管理器在登录会话结束后继续存活:在 "${distro}" 中运行 "loginctl enable-linger $USER",然后重试。`,
79
+ sessionScopeUnknownAnswer: ({ distro, answer, errorSuffix }) => `"${distro}" 中的 sessionSandbox 预检应答为 ${answer}${errorSuffix};参见 docs/adr/0001-session-scoped-sandbox.md。`,
80
+ bwrapMissingGeneric: ({ distro }) => `bwrap 在发行版 "${distro}" 中不可用。请用 "scripts/bootstrap.sh ${distro} --install"(随包提供)安装,` +
81
+ `或用发行版的包管理器安装 "bubblewrap" 软件包。`,
82
+ bwrapMissingFamily: ({ distro, direct }) => `bwrap 在发行版 "${distro}" 中不可用。请用 "scripts/bootstrap.sh ${distro} --install"(随包提供)安装,` +
83
+ `或直接执行:wsl.exe -d ${distro} -u root -- ${direct}`,
84
+ bwrapBroken: ({ distro, output }) => `bwrap 已安装在发行版 "${distro}" 中,但未通过可用性探测:${output}。` +
85
+ `这通常是内核原因(未特权用户命名空间被禁用)或 bwrap 构建不可用,而不是缺少软件包,重新安装不会有帮助。` +
86
+ `请在发行版内检查 \`wsl.exe -d ${distro} --exec bwrap --version\`,或将 wsl-shell 与 wsl-fs 行设为 \`sandbox: false\` 以无隔离运行。`,
87
+ bwrapRuntimeFailure: ({ distro }) => `bwrap 在发行版 "${distro}" 中运行时失败。请在该发行版内检查 \`bwrap --version\`,` +
88
+ `或重新安装:"scripts/bootstrap.sh ${distro} --install"。`,
89
+ bwrapProbeFailedSuffix: ({ output }) => `(探测失败输出:${output})`,
90
+ distroUnavailable: ({ code, distro }) => `wsl.exe 对发行版 "${distro}" 报告了 ${code}:该发行版未安装或未在运行。` +
91
+ `用 \`wsl.exe -d ${distro}\` 启动它,用 \`wsl.exe -l -v\` 检查,或将 \`distro\` 指向另一个发行版。` +
92
+ `这不是沙箱拒绝,放宽权限也不会有帮助。`,
93
+ workdirMissing: ({ missing }) => `wsl.exe 无法进入发行版中的工作目录 "${missing}",命令改从 "/" 运行。` +
94
+ `请创建该目录,或将 \`cwd\`(或请求的 \`workdir\`)指向一个已存在的目录。`,
95
+ workdirAnotherDistro: ({ workdir, distro }) => `"${workdir}" 指向另一个 WSL 发行版中的工作区,而本 profile 将命令固定在 "${distro}" —— ` +
96
+ `在这里运行会作用于另一台机器的目录树。请在该发行版中打开会话,或将 cwd/workdir 指向本发行版。`,
97
+ };
98
+ /** The active language; English until a settings service reports otherwise. */
99
+ let current = "en";
100
+ /**
101
+ * The locale the message builders render in.
102
+ *
103
+ * @returns the active catalog language.
104
+ */
105
+ export function messagesLocale() {
106
+ return current;
107
+ }
108
+ /**
109
+ * Force the message language. The wiring calls this from the resolved
110
+ * `locale.preference`; tests call it directly and reset afterwards.
111
+ *
112
+ * @param locale - the language to render in.
113
+ */
114
+ export function configureMessagesLocale(locale) {
115
+ current = locale;
116
+ }
117
+ /**
118
+ * Render one message in the active language, falling back to the English
119
+ * template when the active catalog somehow lacks the key (the catalogs are
120
+ * type-checked against each other, so this guards runtime drift only).
121
+ *
122
+ * The `params` type correlates the parameters with the key: the conditional
123
+ * resolves per call site, so `t("sessionScopeNoLinger", { distro })`
124
+ * typechecks while `t("sessionScopeNoLinger", { missing })` does not. It
125
+ * lives in the JSDoc because a comment between the parameters would have the
126
+ * type-stripping build emit a line with trailing whitespace, which the style
127
+ * gate refuses.
128
+ *
129
+ * @typeParam K - the message key.
130
+ * @param key - the message to render.
131
+ * @param params - the key's parameters, as the template declares them.
132
+ * @returns the rendered message.
133
+ */
134
+ export function t(key, params) {
135
+ // Key and parameter parity between the catalogs is the type system's job
136
+ // (`zh` is `typeof en`), so the lookup needs no runtime fallback.
137
+ const template = current === "zh" ? zh[key] : en[key];
138
+ return template(params);
139
+ }
140
+ /**
141
+ * Map one `locale.preference` value onto a catalog language. The app's
142
+ * language ids are BCP 47-style tags (`zh`, `en`, `ja`, …); the plugin ships
143
+ * zh and en, and every other id renders English.
144
+ *
145
+ * @param preference - the stored preference, or anything else when unset.
146
+ * @returns the catalog language the preference selects.
147
+ */
148
+ export function resolveMessagesLocale(preference) {
149
+ return typeof preference === "string" && /^zh/iu.test(preference) ? "zh" : "en";
150
+ }
151
+ /**
152
+ * Follow the harness locale for the caller's composition. Every row wires its
153
+ * own injection (the shell executor, the fs provider and the preflight all
154
+ * call this), so a hot-reloaded row re-wires too; the redundant reads converge
155
+ * on the same app-wide preference and the events are rare.
156
+ *
157
+ * The `settings` service is optional — a profile without it (some CLI
158
+ * compositions) keeps English. When it is present, the preference is read once
159
+ * the service resolves and again on every `settings/document-updated` event,
160
+ * which also covers the `locale` entry activating after this row did. A read
161
+ * that throws keeps the previous language: this is presentation, not gating.
162
+ *
163
+ * @param ctx - the row's composition context.
164
+ */
165
+ export function installMessagesLocale(ctx) {
166
+ if (typeof ctx.inject !== "function")
167
+ return;
168
+ ctx.inject(["settings"], (scope) => {
169
+ // Narrow once to the shape this module reads; see `SettingsScope`.
170
+ const view = scope;
171
+ const settings = view.settings;
172
+ if (settings?.describe === undefined)
173
+ return;
174
+ const read = () => {
175
+ try {
176
+ const row = settings.describe().find((entry) => entry.ns === "locale");
177
+ if (row === undefined)
178
+ return;
179
+ // The descriptor's value is the entry's projected volatile form —
180
+ // `{ preference?: string }` for the locale entry.
181
+ const preference = row.value?.preference;
182
+ configureMessagesLocale(resolveMessagesLocale(preference));
183
+ }
184
+ catch {
185
+ // A describe failure must never fail a row's load; keep the last language.
186
+ }
187
+ };
188
+ read();
189
+ // The event name lives in the host's own `Events` augmentation, which this
190
+ // plugin's typings do not carry; widen the registration to a plain string.
191
+ view.on("settings/document-updated", () => read());
192
+ });
193
+ }
194
+ /**
195
+ * Restore English. Tests only: production wiring is process-wide by design.
196
+ */
197
+ export function resetMessagesLocaleForTests() {
198
+ current = "en";
199
+ }
@@ -19,7 +19,7 @@
19
19
  * and run `pnpm run build` — the artifact under `lib/` is generated, and
20
20
  * `pnpm test` fails when it drifts.
21
21
  *
22
- * @module dsh-plugin-wsl/native-agent
22
+ * @module dsh-plugin-wsl-env/native-agent
23
23
  */
24
24
  /** The host environment variable naming the native binary to opt in. */
25
25
  export declare const NATIVE_AGENT_ENV = "DSH_WSL_AGENT_NATIVE";
@@ -19,7 +19,7 @@
19
19
  * and run `pnpm run build` — the artifact under `lib/` is generated, and
20
20
  * `pnpm test` fails when it drifts.
21
21
  *
22
- * @module dsh-plugin-wsl/native-agent
22
+ * @module dsh-plugin-wsl-env/native-agent
23
23
  */
24
24
  import { spawn } from "node:child_process";
25
25
  import { createHash } from "node:crypto";
@@ -190,7 +190,7 @@ export async function ensureNativeSessionAgent({ wslPath, distro, setNative, ens
190
190
  const result = await ensure({ wslPath, distro, source: process.env[NATIVE_AGENT_ENV] ?? "" });
191
191
  if (result === undefined) {
192
192
  if (backend === "native") {
193
- throw new Error(`agentBackend: "native" could not prepare a native binary: the packaged binary for this architecture is missing or failed the copy/digest/execute check, and ${NATIVE_AGENT_ENV} is unset or unusable; set a valid ${NATIVE_AGENT_ENV}, or use "auto"/"shell".`);
193
+ throw new Error(`dsh-plugin-wsl-env: agentBackend: "native" could not prepare a native binary: the packaged binary for this architecture is missing or failed the copy/digest/execute check, and ${NATIVE_AGENT_ENV} is unset or unusable; set a valid ${NATIVE_AGENT_ENV}, or use "auto"/"shell".`);
194
194
  }
195
195
  return;
196
196
  }
package/lib/paths.d.ts CHANGED
@@ -17,7 +17,7 @@
17
17
  * `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
18
18
  * fails when it drifts.
19
19
  *
20
- * @module dsh-plugin-wsl/paths
20
+ * @module dsh-plugin-wsl-env/paths
21
21
  */
22
22
  /** A distro identity and the Linux path inside it, as {@link uncToPosix} returns. */
23
23
  export interface DistroPath {
@@ -134,10 +134,13 @@ export declare function windowsToLinuxMount(winPath: string): string | undefined
134
134
  * editing the profile is likely to write a plain Linux path.
135
135
  *
136
136
  * @param value - the path to translate.
137
- * @param options - the pinned distro and the fallback directory for relative input.
137
+ * @param options - the fallback directory for relative input (the pinned distro is
138
+ * not an input: the mapping is coordinate-only and reads no pin).
138
139
  * @returns an absolute Linux path, or the input unchanged when it cannot be mapped.
139
140
  */
140
- export declare function toLinuxPath(value: string, options?: WorldPathOptions): string;
141
+ export declare function toLinuxPath(value: string, options?: {
142
+ cwd?: string;
143
+ }): string;
141
144
  /**
142
145
  * Join a requested path onto a workspace root in the distro's Linux
143
146
  * coordinate system: UNC absolutes map to their Linux paths, POSIX absolutes
package/lib/paths.js CHANGED
@@ -17,7 +17,7 @@
17
17
  * `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
18
18
  * fails when it drifts.
19
19
  *
20
- * @module dsh-plugin-wsl/paths
20
+ * @module dsh-plugin-wsl-env/paths
21
21
  */
22
22
  /** The WSL UNC share prefix Node can read. `\\wsl$\<distro>\...` is the legacy spelling. */
23
23
  const UNC_RE = /^\\\\wsl(?:\.localhost|\$)\\([^\\]+)(?:\\([\s\S]*))?$/i;
@@ -218,7 +218,8 @@ export function windowsToLinuxMount(winPath) {
218
218
  * editing the profile is likely to write a plain Linux path.
219
219
  *
220
220
  * @param value - the path to translate.
221
- * @param options - the pinned distro and the fallback directory for relative input.
221
+ * @param options - the fallback directory for relative input (the pinned distro is
222
+ * not an input: the mapping is coordinate-only and reads no pin).
222
223
  * @returns an absolute Linux path, or the input unchanged when it cannot be mapped.
223
224
  */
224
225
  export function toLinuxPath(value, options) {
@@ -233,9 +234,8 @@ export function toLinuxPath(value, options) {
233
234
  const mounted = windowsToLinuxMount(text);
234
235
  if (mounted !== undefined)
235
236
  return mounted;
236
- // Relative input is resolved against the configured default workdir.
237
237
  const base = options?.cwd ?? "/";
238
- const baseLinux = toLinuxPath(base, { distro: options?.distro });
238
+ const baseLinux = toLinuxPath(base);
239
239
  return `${baseLinux.replace(/\/+$/, "")}/${text.replace(/^\.\//, "")}`;
240
240
  }
241
241
  /**
package/lib/picker.d.ts CHANGED
@@ -45,7 +45,7 @@
45
45
  * `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
46
46
  * fails when it drifts.
47
47
  *
48
- * @module dsh-plugin-wsl/picker
48
+ * @module dsh-plugin-wsl-env/picker
49
49
  */
50
50
  import z from "@deepseek-ai/schemastery";
51
51
  import { DirectoryPicker } from "@deepseek-ai/dsh-host-directory-picker";
package/lib/picker.js CHANGED
@@ -45,7 +45,7 @@
45
45
  * `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
46
46
  * fails when it drifts.
47
47
  *
48
- * @module dsh-plugin-wsl/picker
48
+ * @module dsh-plugin-wsl-env/picker
49
49
  */
50
50
  import { mkdir, opendir, stat } from "node:fs/promises";
51
51
  import { homedir } from "node:os";
@@ -327,7 +327,7 @@ export class WslDirectoryPicker extends DirectoryPicker {
327
327
  });
328
328
  if (result.exitCode !== 0) {
329
329
  const detail = result.stderr.toString("utf8").trim();
330
- throw new DirectoryPickerError("directory-unreadable", target, `cannot list ${target}: ${detail.length > 0 ? detail : `ls exited ${result.exitCode}`}`);
330
+ throw new DirectoryPickerError("directory-unreadable", target, `cannot list "${target}": ${detail.length > 0 ? detail : `ls exited ${result.exitCode}`}`);
331
331
  }
332
332
  stdout = result.stdout;
333
333
  }
@@ -338,7 +338,7 @@ export class WslDirectoryPicker extends DirectoryPicker {
338
338
  stdout = await runCapture([this.config.wslPath, "-d", parsed.distro, "--cd", linuxDir, "--exec", ...dirListingArgv(linuxDir)], signal);
339
339
  }
340
340
  catch (fallbackError) {
341
- throw new DirectoryPickerError("directory-unreadable", target, `cannot list ${target}: ${messageOf(fallbackError)}`);
341
+ throw new DirectoryPickerError("directory-unreadable", target, `cannot list "${target}": ${messageOf(fallbackError)}`);
342
342
  }
343
343
  }
344
344
  return parseDirListing(stdout, linuxDir, target, this.config.maxEntries);
@@ -377,7 +377,7 @@ export class WslDirectoryPicker extends DirectoryPicker {
377
377
  }
378
378
  catch (error) {
379
379
  signal?.throwIfAborted();
380
- throw new DirectoryPickerError("directory-unreadable", target, `cannot list ${target}: ${messageOf(error)}`);
380
+ throw new DirectoryPickerError("directory-unreadable", target, `cannot list "${target}": ${messageOf(error)}`);
381
381
  }
382
382
  finally {
383
383
  if (level !== undefined)
@@ -425,7 +425,7 @@ export class WslDirectoryPicker extends DirectoryPicker {
425
425
  if (typeof error === "object" && error !== null && "code" in error && error.code === "EEXIST") {
426
426
  throw new DirectoryPickerError("directory-exists", target, `${target} already exists`);
427
427
  }
428
- throw new DirectoryPickerError("directory-create-failed", target, `cannot create ${target}: ${messageOf(error)}`);
428
+ throw new DirectoryPickerError("directory-create-failed", target, `cannot create "${target}": ${messageOf(error)}`);
429
429
  }
430
430
  }
431
431
  /**
@@ -450,7 +450,7 @@ export class WslDirectoryPicker extends DirectoryPicker {
450
450
  const detail = result.stderr.toString("utf8");
451
451
  if (/File exists/i.test(detail))
452
452
  throw new DirectoryPickerError("directory-exists", target, `${target} already exists`);
453
- throw new DirectoryPickerError("directory-create-failed", target, `cannot create ${target}: ${detail.trim().length > 0 ? detail.trim() : `mkdir exited ${result.exitCode}`}`);
453
+ throw new DirectoryPickerError("directory-create-failed", target, `cannot create "${target}": ${detail.trim().length > 0 ? detail.trim() : `mkdir exited ${result.exitCode}`}`);
454
454
  }
455
455
  catch (error) {
456
456
  if (error instanceof DirectoryPickerError)
@@ -465,7 +465,7 @@ export class WslDirectoryPicker extends DirectoryPicker {
465
465
  const message = messageOf(fallbackError);
466
466
  if (/File exists/i.test(message))
467
467
  throw new DirectoryPickerError("directory-exists", target, `${target} already exists`);
468
- throw new DirectoryPickerError("directory-create-failed", target, `cannot create ${target}: ${message}`);
468
+ throw new DirectoryPickerError("directory-create-failed", target, `cannot create "${target}": ${message}`);
469
469
  }
470
470
  }
471
471
  }
package/lib/ports.d.ts CHANGED
@@ -17,7 +17,7 @@
17
17
  * `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
18
18
  * fails when it drifts.
19
19
  *
20
- * @module dsh-plugin-wsl/ports
20
+ * @module dsh-plugin-wsl-env/ports
21
21
  */
22
22
  import type { AgentExecRunner } from "./agent-exec.js";
23
23
  /**
package/lib/ports.js CHANGED
@@ -17,7 +17,7 @@
17
17
  * `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test`
18
18
  * fails when it drifts.
19
19
  *
20
- * @module dsh-plugin-wsl/ports
20
+ * @module dsh-plugin-wsl-env/ports
21
21
  */
22
22
  /**
23
23
  * Parse one `/proc/net/tcp{,6}` body into listening ports.
@@ -11,6 +11,12 @@
11
11
  * command after it pays nothing. Nothing else changes: the failure semantics
12
12
  * stay exactly as fail-closed as before, this service only MOVES THE NEWS.
13
13
  *
14
+ * The same probes also run once at plugin load (`startup`, on by default) so an
15
+ * install-plus-restart already carries the verdict in the log — the pinned or
16
+ * WSL-default distro — before the first session opens. A session on that distro
17
+ * repeats only the runtime-context entry; other distros keep the session-open
18
+ * check unchanged.
19
+ *
14
20
  * Advisory by construction. A preflight that cannot run (no WSL, a wedged
15
21
  * `wsl.exe`) degrades to a log line; it must never fail a session that has not
16
22
  * even asked for confinement yet. It also never installs anything: the remedy
@@ -21,7 +27,7 @@
21
27
  * run `pnpm run build` — the artifact under `lib/` is generated, and
22
28
  * `pnpm test` fails when it drifts.
23
29
  *
24
- * @module dsh-plugin-wsl/preflight
30
+ * @module dsh-plugin-wsl-env/preflight
25
31
  */
26
32
  import z from "@deepseek-ai/schemastery";
27
33
  import type { Context } from "@deepseek-ai/cordis";
@@ -44,6 +50,14 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
44
50
  * that profile does not use.
45
51
  */
46
52
  sessionSandbox: z<boolean, boolean, "defined">;
53
+ /**
54
+ * Whether the same checks also run once at plugin load — install + restart —
55
+ * against the pinned or WSL-default distro, so the verdict is in the log
56
+ * before any session opens. Sessions on other distros are still checked at
57
+ * open, and a session announcement for a message the load pass already
58
+ * logged skips the duplicate log line but keeps its runtime-context entry.
59
+ */
60
+ startup: z<boolean, boolean, "defined">;
47
61
  }>>, Schemastery.ObjectT<NoInfer<{
48
62
  /**
49
63
  * Distro to preflight. Empty/`"auto"` follows the session workspace; an
@@ -62,6 +76,14 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
62
76
  * that profile does not use.
63
77
  */
64
78
  sessionSandbox: z<boolean, boolean, "defined">;
79
+ /**
80
+ * Whether the same checks also run once at plugin load — install + restart —
81
+ * against the pinned or WSL-default distro, so the verdict is in the log
82
+ * before any session opens. Sessions on other distros are still checked at
83
+ * open, and a session announcement for a message the load pass already
84
+ * logged skips the duplicate log line but keeps its runtime-context entry.
85
+ */
86
+ startup: z<boolean, boolean, "defined">;
65
87
  }>>, "plain">;
66
88
  /** The config schema's validated output. */
67
89
  export interface PreflightConfig {
@@ -73,6 +95,8 @@ export interface PreflightConfig {
73
95
  sandbox?: boolean;
74
96
  /** Whether the session-runtime prerequisites are preflighted too. */
75
97
  sessionSandbox?: boolean;
98
+ /** Whether the checks also run once at plugin load, before any session. */
99
+ startup?: boolean;
76
100
  }
77
101
  /**
78
102
  * The slice of a created agent this service inspects; the harness's agent