dsh-bash-terminal-ts 0.9.1 → 0.9.2

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 (70) hide show
  1. package/CHANGELOG.md +205 -205
  2. package/CHANGELOG.pt.md +151 -151
  3. package/README.de.md +206 -206
  4. package/README.en.md +212 -212
  5. package/README.es.md +206 -206
  6. package/README.fr.md +206 -206
  7. package/README.it.md +206 -206
  8. package/README.md +423 -423
  9. package/README.pt.md +212 -212
  10. package/README.ru.md +206 -206
  11. package/agent-presets/README.md +171 -171
  12. package/agent-presets/install-presets.mjs +180 -180
  13. package/agent-presets/standard-win/agent.cordis.yml +271 -271
  14. package/agent-presets/standard-win/preset.yml +2 -2
  15. package/agent-presets/standard-win-gitbash/agent.cordis.yml +271 -271
  16. package/agent-presets/standard-win-gitbash/preset.yml +2 -2
  17. package/agent-presets/standard-win-msys2/agent.cordis.yml +272 -272
  18. package/agent-presets/standard-win-msys2/preset.yml +2 -2
  19. package/agent-presets/standard-win-niu/agent.cordis.yml +270 -270
  20. package/agent-presets/standard-win-niu/preset.yml +2 -2
  21. package/agent-presets/standard-win-payload/agent.cordis.yml +271 -271
  22. package/agent-presets/standard-win-payload/preset.yml +2 -2
  23. package/agent-presets/standard-win-wsl2/agent.cordis.yml +271 -271
  24. package/agent-presets/standard-win-wsl2/preset.yml +2 -2
  25. package/cordis.patch.yml +72 -84
  26. package/dist/client.core.js +6 -16
  27. package/dist/client.js +6 -16
  28. package/docs/niu-backend.md +197 -197
  29. package/dsh.plugin.json +23 -23
  30. package/lib/client.js +6 -16
  31. package/lib/dsh-types.d.ts +0 -2
  32. package/lib/index.d.ts +2 -23
  33. package/lib/index.js +4 -34
  34. package/lib/locales.js +0 -10
  35. package/lib/payload.d.ts +72 -72
  36. package/lib/payload.js +279 -279
  37. package/lib/shell-id.d.ts +2 -2
  38. package/lib/shells.d.ts +2 -11
  39. package/lib/shells.js +4 -14
  40. package/lib/terminal.js +0 -1
  41. package/lib/webterminals/catalog.d.ts +0 -2
  42. package/lib/webterminals/catalog.js +0 -1
  43. package/lib/webterminals/mount.d.ts +0 -5
  44. package/lib/webterminals/mount.js +0 -4
  45. package/locale/de.json +5 -5
  46. package/locale/en.json +5 -5
  47. package/locale/es.json +5 -5
  48. package/locale/fr.json +5 -5
  49. package/locale/it.json +5 -5
  50. package/locale/ja.json +5 -5
  51. package/locale/ko.json +5 -5
  52. package/locale/pt.json +6 -6
  53. package/locale/ru.json +5 -5
  54. package/locale/zh.json +5 -5
  55. package/package.json +1 -5
  56. package/scripts/check-artifacts.mjs +96 -96
  57. package/scripts/link-shells.mjs +0 -21
  58. package/src/client.tsx +685 -685
  59. package/src/dsh-types.ts +330 -332
  60. package/src/index.ts +1267 -1316
  61. package/src/locales.ts +499 -509
  62. package/src/shell-id.ts +11 -11
  63. package/src/shells.ts +263 -279
  64. package/src/terminal.ts +615 -616
  65. package/src/webterminals/catalog.ts +0 -3
  66. package/src/webterminals/host.ts +361 -361
  67. package/src/webterminals/mount.ts +228 -237
  68. package/scripts/payload-alias.mjs +0 -97
  69. package/scripts/provision-payload.mjs +0 -233
  70. package/src/payload.ts +0 -322
package/lib/payload.js CHANGED
@@ -1,279 +1,279 @@
1
- // dsh-bash-terminal-ts: the pinned backup POSIX runtime payload - discovery
2
- // plus a fail-closed digest gate.
3
- //
4
- // Naming policy (operator decision, 2026-10): OUR artifacts never carry the
5
- // tokens `bash`, `gitbash` or `msys` - the bare name `bash` on Windows is the
6
- // WSL forwarder's territory, and dsh-ops ships `@dsh-ops/bash-*`/msys-named
7
- // payloads we must not shadow or be confused with. The runtime inside the
8
- // payload still IS Git-for-Windows (its binary is literally bash.exe - an
9
- // upstream fact, not our name); our namespace is `posix-runtime`.
10
- //
11
- // Why this exists: the plugin otherwise runs whatever Git Bash / MSYS2 the
12
- // machine happens to have, at whatever version the package manager left it at.
13
- // dsh-ops solved that by carrying its own pinned payload and refusing to run
14
- // anything whose digest it had not verified. We absorb the SEMANTICS (only an
15
- // executor whose SHA-256 is in a ledger we control may run), not the shipping
16
- // form: nothing is downloaded at install, no binary rides in the main tarball.
17
- // The payload is provisioned by the operator through
18
- // `scripts/provision-payload.mjs`, which reverse-unpacks a LOCAL PortableGit
19
- // SFX (our own repack of the upstream runtime - we never consume dsh-ops's
20
- // packages), records the digests, and drops a `payload.trust.json` beside it.
21
- //
22
- // The gate (fail-closed, on purpose):
23
- // - a root whose `bin/bash.exe` + `usr/bin/msys-2.0.dll` digests match the
24
- // embedded ledger or the local trust file is USABLE;
25
- // - anything else - unreadable, missing, unknown digest, mismatch after a
26
- // "was fine" state - is NOT. We never run an unverified bash, and we never
27
- // silently fall through to one: the reason surfaces as a note the plugin
28
- // logs once at startup. This matters MORE for us than for a confined
29
- // runner: MSYS bash cannot be wrapped by the DSH ACL restricted-token
30
- // sandbox (CreateFileMapping error 5), so digest verification is the only
31
- // security layer between us and the binary.
32
- //
33
- // The WSL preference rule (revised 2026-10 same day): a real WSL bash IS the
34
- // better POSIX shell, but once the payload became a first-class backend with a
35
- // double opt-in (operator gate + row switch), a hard veto made our own picker
36
- // stricter than the host's official menu, which lists bash-terminal.exe right
37
- // next to WSL's bash. So now: a detected WSL distro is an ADVISORY note, not a
38
- // gate. The digest gate remains the only hard no.
39
- //
40
- // Purity: every OS touch goes through the `PayloadProbe` seam so the whole
41
- // decision table is unit-testable without a payload on disk. The default probe
42
- // is the real fs/spawn one; hash results are memoized on (size, mtimeMs) so a
43
- // stable payload costs one re-read per change, per call.
44
- import { createHash } from "node:crypto";
45
- import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
46
- import { dirname, join } from "node:path";
47
- import { createRequire } from "node:module";
48
- /** npm package name of OUR POSIX runtime repack (optionalDependency-style; absent = simply no payload). */
49
- export const PAYLOAD_PACKAGE = "@drscrewdriver/posix-runtime-win32-x64";
50
- /** Trust record written next to a provisioned payload root by scripts/provision-payload.mjs. */
51
- export const TRUST_FILE_NAME = "payload.trust.json";
52
- /** Files every payload root must expose for verification, normalized to forward slashes, lowercase. */
53
- export const REQUIRED_FILES = ["bin/bash.exe", "usr/bin/msys-2.0.dll"];
54
- /**
55
- * Built-in ledger, keyed by payload build label. Populated by
56
- * `provision-payload.mjs --emit-ledger` at release time (V-flow). EMPTY on a
57
- * fresh checkout by design: with no ledger entry, a root is only usable if the
58
- * operator's local trust file pins it - which is an explicit human act, the
59
- * same posture as `dsh-ops provision-shells` but self-managed.
60
- */
61
- export const PAYLOAD_LEDGER = {};
62
- /** Environment directory carrying auto-discovered payload roots. */
63
- export function payloadStoreDir(env = process.env) {
64
- const localAppData = env.LOCALAPPDATA;
65
- if (typeof localAppData !== "string" || localAppData.trim().length === 0)
66
- return undefined;
67
- return join(localAppData, "dsh-bash-terminal-ts", "payloads");
68
- }
69
- // ---- default probe (real fs / wsl) --------------------------------------------
70
- const defaultProbe = {
71
- exists: (p) => {
72
- try {
73
- return existsSync(p);
74
- }
75
- catch {
76
- return false;
77
- }
78
- },
79
- read: (p) => {
80
- try {
81
- return readFileSync(p);
82
- }
83
- catch {
84
- return undefined;
85
- }
86
- },
87
- stamp: (p) => {
88
- try {
89
- const st = statSync(p);
90
- return `${st.size}|${st.mtimeMs}`;
91
- }
92
- catch {
93
- return undefined;
94
- }
95
- },
96
- readdir: (d) => {
97
- try {
98
- return readdirSync(d);
99
- }
100
- catch {
101
- return [];
102
- }
103
- },
104
- resolvePackageRoot: () => {
105
- try {
106
- const req = createRequire(import.meta.url);
107
- return dirname(req.resolve(`${PAYLOAD_PACKAGE}/package.json`));
108
- }
109
- catch {
110
- return undefined;
111
- }
112
- },
113
- wslDistros: () => {
114
- try {
115
- // The child_process face is loaded lazily so importers that never touch
116
- // the default probe (browser-side graphs, pure unit tests with an
117
- // injected probe) do not pull it in; spawnSync with a short timeout:
118
- // `wsl -l -q` is fast when WSL is present and hangs (or errors) when it
119
- // is a stub, which is exactly the "cannot answer" case.
120
- const { spawnSync } = require_child_process();
121
- // wsl.exe writes UTF-16LE (measured: "Ubuntu" arrives as U\0b\0u\0...),
122
- // so `encoding: "utf8"` would turn an EMPTY distro list into one
123
- // mojibake line - a false "WSL has a distro" that would veto the
124
- // payload on machines that have none. Read bytes and decode by shape:
125
- // NUL interleaving means UTF-16LE, everything else is ascii/utf8.
126
- const r = spawnSync("wsl.exe", ["-l", "-q"], { timeout: 5000, windowsHide: true });
127
- if (r.error !== undefined || r.status === null || !Buffer.isBuffer(r.stdout))
128
- return undefined;
129
- const raw = r.stdout;
130
- const text = raw.includes(0x00) ? raw.toString("utf16le") : raw.toString("utf8");
131
- const names = text.split(/\r?\n/).map((l) => l.replaceAll("\u0000", "").trim()).filter((l) => l.length > 0);
132
- return names;
133
- }
134
- catch {
135
- return undefined;
136
- }
137
- }
138
- };
139
- // Type-only import above, runtime require here: the module reference is erased
140
- // at compile time, so the host graph stays free of a static child_process edge.
141
- function require_child_process() {
142
- return createRequire(import.meta.url)("node:child_process");
143
- }
144
- // ---- hashing -------------------------------------------------------------------
145
- const hashCache = new Map();
146
- /** sha256 hex of one file, memoized on (size, mtimeMs); undefined when unreadable. */
147
- export function hashFile(path, probe = defaultProbe) {
148
- const stamp = probe.stamp(path);
149
- if (stamp === undefined)
150
- return undefined;
151
- const hit = hashCache.get(path);
152
- if (hit !== undefined && hit.stamp === stamp)
153
- return hit.sha;
154
- const buf = probe.read(path);
155
- if (buf === undefined)
156
- return undefined;
157
- const sha = createHash("sha256").update(buf).digest("hex");
158
- hashCache.set(path, { stamp, sha });
159
- return sha;
160
- }
161
- /** Test/backdoor: drop the memo (a payload replaced in place must re-verify). */
162
- export function clearHashCache() {
163
- hashCache.clear();
164
- }
165
- // ---- verification ----------------------------------------------------------------
166
- function normalizeRel(p) {
167
- return p.replaceAll("\\", "/").toLowerCase();
168
- }
169
- function digestMapsMatch(actual, pinned) {
170
- const keys = Object.keys(pinned);
171
- if (keys.length === 0)
172
- return false;
173
- return keys.every((k) => {
174
- const want = pinned[k];
175
- const got = actual[normalizeRel(k)];
176
- return typeof want === "string" && typeof got === "string" && want.toLowerCase() === got;
177
- });
178
- }
179
- /**
180
- * Verify one payload root: both REQUIRED_FILES exist, their digests match the
181
- * built-in ledger OR the root-local trust file. Everything else fails closed.
182
- */
183
- export function verifyPayloadRoot(root, probe = defaultProbe) {
184
- const bashPath = join(root, "bin", "bash.exe");
185
- const dllPath = join(root, "usr", "bin", "msys-2.0.dll");
186
- if (!probe.exists(root))
187
- return { ok: false, reason: `missing-root:${root}` };
188
- if (!probe.exists(bashPath) || !probe.exists(dllPath)) {
189
- return { ok: false, reason: `missing-files:${root}` };
190
- }
191
- const actual = {
192
- "bin/bash.exe": hashFile(bashPath, probe),
193
- "usr/bin/msys-2.0.dll": hashFile(dllPath, probe)
194
- };
195
- if (Object.values(actual).some((v) => v === undefined)) {
196
- return { ok: false, reason: `unreadable:${root}` };
197
- }
198
- for (const pinned of Object.values(PAYLOAD_LEDGER)) {
199
- if (digestMapsMatch(actual, pinned))
200
- return { ok: true, bashPath, source: "ledger" };
201
- }
202
- const trustRaw = probe.read(join(root, TRUST_FILE_NAME));
203
- if (trustRaw !== undefined) {
204
- let trust;
205
- try {
206
- trust = JSON.parse(trustRaw.toString("utf8"));
207
- }
208
- catch {
209
- return { ok: false, reason: `trust-unparsed:${root}` };
210
- }
211
- const files = trust.files;
212
- if (files !== null && typeof files === "object") {
213
- const map = {};
214
- for (const [k, v] of Object.entries(files)) {
215
- if (typeof v === "string")
216
- map[normalizeRel(k)] = v.toLowerCase();
217
- }
218
- // The trust file must pin EVERY required file, or it does not constitute
219
- // an approval of the executor we are about to run.
220
- if (REQUIRED_FILES.every((f) => f in map) && digestMapsMatch(actual, map)) {
221
- return { ok: true, bashPath, source: "trust" };
222
- }
223
- }
224
- return { ok: false, reason: `digest-mismatch:${root}` };
225
- }
226
- return { ok: false, reason: `digest-unknown:${root}` };
227
- }
228
- // ---- root discovery ----------------------------------------------------------------
229
- /** Candidate payload roots in preference order: explicit path, npm package, store dir. */
230
- export function findPayloadRoots(config, probe = defaultProbe, env = process.env) {
231
- const roots = [];
232
- const push = (r) => {
233
- if (typeof r === "string" && r.trim().length > 0 && !roots.includes(r))
234
- roots.push(r);
235
- };
236
- const explicit = (config.payloadBashPath ?? "").trim();
237
- if (explicit.length > 0 && /bash\.exe$/i.test(explicit))
238
- push(dirname(dirname(explicit)));
239
- else if (explicit.length > 0)
240
- push(explicit); // a root directory is also honoured
241
- push(probe.resolvePackageRoot());
242
- const store = payloadStoreDir(env);
243
- if (store !== undefined) {
244
- for (const child of probe.readdir(store)) {
245
- const full = join(store, child);
246
- if (probe.exists(join(full, "bin", "bash.exe")))
247
- push(full);
248
- }
249
- }
250
- return roots;
251
- }
252
- /**
253
- * The whole decision table for one startup. Call ONLY when the payload feature
254
- * is enabled; the caller wires the resulting `bashPath` into the gitbash slot
255
- * of `resolveAllPaths` as the last-resort source.
256
- */
257
- export function resolvePayloadBash(config, probe = defaultProbe, env = process.env) {
258
- const notes = [];
259
- const distros = probe.wslDistros();
260
- const wslPreferred = distros !== undefined && distros.length > 0;
261
- if (wslPreferred) {
262
- notes.push(`posix-payload: WSL distro(s) detected (${distros.slice(0, 3).join(", ")}) - a real WSL bash is usually the better POSIX shell, prefer the "wsl" backend when in doubt. The payload stays selectable; this is a hint, not a gate.`);
263
- }
264
- const roots = findPayloadRoots(config, probe, env);
265
- if (roots.length === 0) {
266
- notes.push("posix-payload: enabled but no payload root found (provision one with scripts/provision-payload.mjs or set payloadPosixPath).");
267
- return { engaged: false, wslPreferred, notes };
268
- }
269
- const failures = [];
270
- for (const root of roots) {
271
- const verdict = verifyPayloadRoot(root, probe);
272
- if (verdict.ok) {
273
- return { engaged: true, bashPath: verdict.bashPath, wslPreferred, notes };
274
- }
275
- failures.push(verdict.reason);
276
- }
277
- notes.push(`posix-payload: every candidate root failed the digest gate, fail-closed (not run): ${failures.join("; ")}`);
278
- return { engaged: false, wslPreferred, notes };
279
- }
1
+ // dsh-bash-terminal-ts: the pinned backup POSIX runtime payload - discovery
2
+ // plus a fail-closed digest gate.
3
+ //
4
+ // Naming policy (operator decision, 2026-10): OUR artifacts never carry the
5
+ // tokens `bash`, `gitbash` or `msys` - the bare name `bash` on Windows is the
6
+ // WSL forwarder's territory, and dsh-ops ships `@dsh-ops/bash-*`/msys-named
7
+ // payloads we must not shadow or be confused with. The runtime inside the
8
+ // payload still IS Git-for-Windows (its binary is literally bash.exe - an
9
+ // upstream fact, not our name); our namespace is `posix-runtime`.
10
+ //
11
+ // Why this exists: the plugin otherwise runs whatever Git Bash / MSYS2 the
12
+ // machine happens to have, at whatever version the package manager left it at.
13
+ // dsh-ops solved that by carrying its own pinned payload and refusing to run
14
+ // anything whose digest it had not verified. We absorb the SEMANTICS (only an
15
+ // executor whose SHA-256 is in a ledger we control may run), not the shipping
16
+ // form: nothing is downloaded at install, no binary rides in the main tarball.
17
+ // The payload is provisioned by the operator through
18
+ // `scripts/provision-payload.mjs`, which reverse-unpacks a LOCAL PortableGit
19
+ // SFX (our own repack of the upstream runtime - we never consume dsh-ops's
20
+ // packages), records the digests, and drops a `payload.trust.json` beside it.
21
+ //
22
+ // The gate (fail-closed, on purpose):
23
+ // - a root whose `bin/bash.exe` + `usr/bin/msys-2.0.dll` digests match the
24
+ // embedded ledger or the local trust file is USABLE;
25
+ // - anything else - unreadable, missing, unknown digest, mismatch after a
26
+ // "was fine" state - is NOT. We never run an unverified bash, and we never
27
+ // silently fall through to one: the reason surfaces as a note the plugin
28
+ // logs once at startup. This matters MORE for us than for a confined
29
+ // runner: MSYS bash cannot be wrapped by the DSH ACL restricted-token
30
+ // sandbox (CreateFileMapping error 5), so digest verification is the only
31
+ // security layer between us and the binary.
32
+ //
33
+ // The WSL preference rule (revised 2026-10 same day): a real WSL bash IS the
34
+ // better POSIX shell, but once the payload became a first-class backend with a
35
+ // double opt-in (operator gate + row switch), a hard veto made our own picker
36
+ // stricter than the host's official menu, which lists bash-terminal.exe right
37
+ // next to WSL's bash. So now: a detected WSL distro is an ADVISORY note, not a
38
+ // gate. The digest gate remains the only hard no.
39
+ //
40
+ // Purity: every OS touch goes through the `PayloadProbe` seam so the whole
41
+ // decision table is unit-testable without a payload on disk. The default probe
42
+ // is the real fs/spawn one; hash results are memoized on (size, mtimeMs) so a
43
+ // stable payload costs one re-read per change, per call.
44
+ import { createHash } from "node:crypto";
45
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
46
+ import { dirname, join } from "node:path";
47
+ import { createRequire } from "node:module";
48
+ /** npm package name of OUR POSIX runtime repack (optionalDependency-style; absent = simply no payload). */
49
+ export const PAYLOAD_PACKAGE = "@drscrewdriver/posix-runtime-win32-x64";
50
+ /** Trust record written next to a provisioned payload root by scripts/provision-payload.mjs. */
51
+ export const TRUST_FILE_NAME = "payload.trust.json";
52
+ /** Files every payload root must expose for verification, normalized to forward slashes, lowercase. */
53
+ export const REQUIRED_FILES = ["bin/bash.exe", "usr/bin/msys-2.0.dll"];
54
+ /**
55
+ * Built-in ledger, keyed by payload build label. Populated by
56
+ * `provision-payload.mjs --emit-ledger` at release time (V-flow). EMPTY on a
57
+ * fresh checkout by design: with no ledger entry, a root is only usable if the
58
+ * operator's local trust file pins it - which is an explicit human act, the
59
+ * same posture as `dsh-ops provision-shells` but self-managed.
60
+ */
61
+ export const PAYLOAD_LEDGER = {};
62
+ /** Environment directory carrying auto-discovered payload roots. */
63
+ export function payloadStoreDir(env = process.env) {
64
+ const localAppData = env.LOCALAPPDATA;
65
+ if (typeof localAppData !== "string" || localAppData.trim().length === 0)
66
+ return undefined;
67
+ return join(localAppData, "dsh-bash-terminal-ts", "payloads");
68
+ }
69
+ // ---- default probe (real fs / wsl) --------------------------------------------
70
+ const defaultProbe = {
71
+ exists: (p) => {
72
+ try {
73
+ return existsSync(p);
74
+ }
75
+ catch {
76
+ return false;
77
+ }
78
+ },
79
+ read: (p) => {
80
+ try {
81
+ return readFileSync(p);
82
+ }
83
+ catch {
84
+ return undefined;
85
+ }
86
+ },
87
+ stamp: (p) => {
88
+ try {
89
+ const st = statSync(p);
90
+ return `${st.size}|${st.mtimeMs}`;
91
+ }
92
+ catch {
93
+ return undefined;
94
+ }
95
+ },
96
+ readdir: (d) => {
97
+ try {
98
+ return readdirSync(d);
99
+ }
100
+ catch {
101
+ return [];
102
+ }
103
+ },
104
+ resolvePackageRoot: () => {
105
+ try {
106
+ const req = createRequire(import.meta.url);
107
+ return dirname(req.resolve(`${PAYLOAD_PACKAGE}/package.json`));
108
+ }
109
+ catch {
110
+ return undefined;
111
+ }
112
+ },
113
+ wslDistros: () => {
114
+ try {
115
+ // The child_process face is loaded lazily so importers that never touch
116
+ // the default probe (browser-side graphs, pure unit tests with an
117
+ // injected probe) do not pull it in; spawnSync with a short timeout:
118
+ // `wsl -l -q` is fast when WSL is present and hangs (or errors) when it
119
+ // is a stub, which is exactly the "cannot answer" case.
120
+ const { spawnSync } = require_child_process();
121
+ // wsl.exe writes UTF-16LE (measured: "Ubuntu" arrives as U\0b\0u\0...),
122
+ // so `encoding: "utf8"` would turn an EMPTY distro list into one
123
+ // mojibake line - a false "WSL has a distro" that would veto the
124
+ // payload on machines that have none. Read bytes and decode by shape:
125
+ // NUL interleaving means UTF-16LE, everything else is ascii/utf8.
126
+ const r = spawnSync("wsl.exe", ["-l", "-q"], { timeout: 5000, windowsHide: true });
127
+ if (r.error !== undefined || r.status === null || !Buffer.isBuffer(r.stdout))
128
+ return undefined;
129
+ const raw = r.stdout;
130
+ const text = raw.includes(0x00) ? raw.toString("utf16le") : raw.toString("utf8");
131
+ const names = text.split(/\r?\n/).map((l) => l.replaceAll("\u0000", "").trim()).filter((l) => l.length > 0);
132
+ return names;
133
+ }
134
+ catch {
135
+ return undefined;
136
+ }
137
+ }
138
+ };
139
+ // Type-only import above, runtime require here: the module reference is erased
140
+ // at compile time, so the host graph stays free of a static child_process edge.
141
+ function require_child_process() {
142
+ return createRequire(import.meta.url)("node:child_process");
143
+ }
144
+ // ---- hashing -------------------------------------------------------------------
145
+ const hashCache = new Map();
146
+ /** sha256 hex of one file, memoized on (size, mtimeMs); undefined when unreadable. */
147
+ export function hashFile(path, probe = defaultProbe) {
148
+ const stamp = probe.stamp(path);
149
+ if (stamp === undefined)
150
+ return undefined;
151
+ const hit = hashCache.get(path);
152
+ if (hit !== undefined && hit.stamp === stamp)
153
+ return hit.sha;
154
+ const buf = probe.read(path);
155
+ if (buf === undefined)
156
+ return undefined;
157
+ const sha = createHash("sha256").update(buf).digest("hex");
158
+ hashCache.set(path, { stamp, sha });
159
+ return sha;
160
+ }
161
+ /** Test/backdoor: drop the memo (a payload replaced in place must re-verify). */
162
+ export function clearHashCache() {
163
+ hashCache.clear();
164
+ }
165
+ // ---- verification ----------------------------------------------------------------
166
+ function normalizeRel(p) {
167
+ return p.replaceAll("\\", "/").toLowerCase();
168
+ }
169
+ function digestMapsMatch(actual, pinned) {
170
+ const keys = Object.keys(pinned);
171
+ if (keys.length === 0)
172
+ return false;
173
+ return keys.every((k) => {
174
+ const want = pinned[k];
175
+ const got = actual[normalizeRel(k)];
176
+ return typeof want === "string" && typeof got === "string" && want.toLowerCase() === got;
177
+ });
178
+ }
179
+ /**
180
+ * Verify one payload root: both REQUIRED_FILES exist, their digests match the
181
+ * built-in ledger OR the root-local trust file. Everything else fails closed.
182
+ */
183
+ export function verifyPayloadRoot(root, probe = defaultProbe) {
184
+ const bashPath = join(root, "bin", "bash.exe");
185
+ const dllPath = join(root, "usr", "bin", "msys-2.0.dll");
186
+ if (!probe.exists(root))
187
+ return { ok: false, reason: `missing-root:${root}` };
188
+ if (!probe.exists(bashPath) || !probe.exists(dllPath)) {
189
+ return { ok: false, reason: `missing-files:${root}` };
190
+ }
191
+ const actual = {
192
+ "bin/bash.exe": hashFile(bashPath, probe),
193
+ "usr/bin/msys-2.0.dll": hashFile(dllPath, probe)
194
+ };
195
+ if (Object.values(actual).some((v) => v === undefined)) {
196
+ return { ok: false, reason: `unreadable:${root}` };
197
+ }
198
+ for (const pinned of Object.values(PAYLOAD_LEDGER)) {
199
+ if (digestMapsMatch(actual, pinned))
200
+ return { ok: true, bashPath, source: "ledger" };
201
+ }
202
+ const trustRaw = probe.read(join(root, TRUST_FILE_NAME));
203
+ if (trustRaw !== undefined) {
204
+ let trust;
205
+ try {
206
+ trust = JSON.parse(trustRaw.toString("utf8"));
207
+ }
208
+ catch {
209
+ return { ok: false, reason: `trust-unparsed:${root}` };
210
+ }
211
+ const files = trust.files;
212
+ if (files !== null && typeof files === "object") {
213
+ const map = {};
214
+ for (const [k, v] of Object.entries(files)) {
215
+ if (typeof v === "string")
216
+ map[normalizeRel(k)] = v.toLowerCase();
217
+ }
218
+ // The trust file must pin EVERY required file, or it does not constitute
219
+ // an approval of the executor we are about to run.
220
+ if (REQUIRED_FILES.every((f) => f in map) && digestMapsMatch(actual, map)) {
221
+ return { ok: true, bashPath, source: "trust" };
222
+ }
223
+ }
224
+ return { ok: false, reason: `digest-mismatch:${root}` };
225
+ }
226
+ return { ok: false, reason: `digest-unknown:${root}` };
227
+ }
228
+ // ---- root discovery ----------------------------------------------------------------
229
+ /** Candidate payload roots in preference order: explicit path, npm package, store dir. */
230
+ export function findPayloadRoots(config, probe = defaultProbe, env = process.env) {
231
+ const roots = [];
232
+ const push = (r) => {
233
+ if (typeof r === "string" && r.trim().length > 0 && !roots.includes(r))
234
+ roots.push(r);
235
+ };
236
+ const explicit = (config.payloadBashPath ?? "").trim();
237
+ if (explicit.length > 0 && /bash\.exe$/i.test(explicit))
238
+ push(dirname(dirname(explicit)));
239
+ else if (explicit.length > 0)
240
+ push(explicit); // a root directory is also honoured
241
+ push(probe.resolvePackageRoot());
242
+ const store = payloadStoreDir(env);
243
+ if (store !== undefined) {
244
+ for (const child of probe.readdir(store)) {
245
+ const full = join(store, child);
246
+ if (probe.exists(join(full, "bin", "bash.exe")))
247
+ push(full);
248
+ }
249
+ }
250
+ return roots;
251
+ }
252
+ /**
253
+ * The whole decision table for one startup. Call ONLY when the payload feature
254
+ * is enabled; the caller wires the resulting `bashPath` into the gitbash slot
255
+ * of `resolveAllPaths` as the last-resort source.
256
+ */
257
+ export function resolvePayloadBash(config, probe = defaultProbe, env = process.env) {
258
+ const notes = [];
259
+ const distros = probe.wslDistros();
260
+ const wslPreferred = distros !== undefined && distros.length > 0;
261
+ if (wslPreferred) {
262
+ notes.push(`posix-payload: WSL distro(s) detected (${distros.slice(0, 3).join(", ")}) - a real WSL bash is usually the better POSIX shell, prefer the "wsl" backend when in doubt. The payload stays selectable; this is a hint, not a gate.`);
263
+ }
264
+ const roots = findPayloadRoots(config, probe, env);
265
+ if (roots.length === 0) {
266
+ notes.push("posix-payload: enabled but no payload root found (provision one with scripts/provision-payload.mjs or set payloadPosixPath).");
267
+ return { engaged: false, wslPreferred, notes };
268
+ }
269
+ const failures = [];
270
+ for (const root of roots) {
271
+ const verdict = verifyPayloadRoot(root, probe);
272
+ if (verdict.ok) {
273
+ return { engaged: true, bashPath: verdict.bashPath, wslPreferred, notes };
274
+ }
275
+ failures.push(verdict.reason);
276
+ }
277
+ notes.push(`posix-payload: every candidate root failed the digest gate, fail-closed (not run): ${failures.join("; ")}`);
278
+ return { engaged: false, wslPreferred, notes };
279
+ }
package/lib/shell-id.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- /** The five backends, in catalog order (`payload` = the pinned POSIX runtime). */
2
- export type ShellId = "powershell" | "gitbash" | "msys2" | "wsl" | "payload" | "niu";
1
+ /** The five backends, in catalog order. */
2
+ export type ShellId = "powershell" | "gitbash" | "msys2" | "wsl" | "niu";
package/lib/shells.d.ts CHANGED
@@ -2,12 +2,10 @@ import type { ResolvedPaths } from "./dsh-types.js";
2
2
  import type { ShellId } from "./shell-id.js";
3
3
  /** Re-exported so existing importers keep working (see shell-id.ts for why). */
4
4
  export type { ShellId };
5
- /** Catalog order = fallback order: powershell is BOTH first choice and floor. The
6
- * pinned POSIX payload sits last: it only earns a seat when the machine's own
7
- * shells are absent, and a detected WSL distro vetoes it before that. */
5
+ /** Catalog order = fallback order: powershell is BOTH first choice and floor. */
8
6
  export declare const SHELL_PRIORITY: readonly ShellId[];
9
7
  /** Why one backend is not launchable (drives the settings-row badge). */
10
- export type ShellUnavailable = "installed" | "not-installed" | "no-distro" | "launcher-only" | "wsl-preferred";
8
+ export type ShellUnavailable = "installed" | "not-installed" | "no-distro" | "launcher-only";
11
9
  /** One catalog row: what the UI shows and what the host would spawn. */
12
10
  export interface ShellEntry {
13
11
  readonly id: ShellId;
@@ -30,7 +28,6 @@ export interface ShellSwitches {
30
28
  msys2: boolean;
31
29
  wsl: boolean;
32
30
  niu: boolean;
33
- payload: boolean;
34
31
  }
35
32
  /** Everything the catalog builder needs from the outside world. */
36
33
  export interface CatalogFacts {
@@ -44,12 +41,6 @@ export interface CatalogFacts {
44
41
  switches: ShellSwitches;
45
42
  /** WSL distro override from config ('' = the WSL default). */
46
43
  wslDistro: string;
47
- /**
48
- * True when the payload gate was vetoed by a positively-detected WSL distro
49
- * (a real Linux bash outranks the MSYS payload). It only colors the payload
50
- * row's badge when no payload path resolved - "why" information, not a gate.
51
- */
52
- payloadSuppressed?: boolean;
53
44
  }
54
45
  /**
55
46
  * `<SystemRoot>\System32\bash.exe` (and the sysnative mirror) is the deprecated
package/lib/shells.js CHANGED
@@ -15,10 +15,8 @@
15
15
  //
16
16
  // Everything here is pure: no fs, no child_process, no module-level cache. The
17
17
  // caller injects `fsProbe` / `distros` and owns the TTL.
18
- /** Catalog order = fallback order: powershell is BOTH first choice and floor. The
19
- * pinned POSIX payload sits last: it only earns a seat when the machine's own
20
- * shells are absent, and a detected WSL distro vetoes it before that. */
21
- export const SHELL_PRIORITY = ["powershell", "gitbash", "msys2", "wsl", "niu", "payload"];
18
+ /** Catalog order = fallback order: powershell is BOTH first choice and floor. */
19
+ export const SHELL_PRIORITY = ["powershell", "gitbash", "msys2", "wsl", "niu"];
22
20
  /** Display labels. The catalog id/label pair is DECIDED BY THIS TABLE. */
23
21
  const LABELS = {
24
22
  powershell: "PowerShell",
@@ -26,7 +24,6 @@ const LABELS = {
26
24
  msys2: "MSYS2",
27
25
  wsl: "WSL bash",
28
26
  niu: "Niubash",
29
- payload: "POSIX payload",
30
27
  };
31
28
  /**
32
29
  * `<SystemRoot>\System32\bash.exe` (and the sysnative mirror) is the deprecated
@@ -67,10 +64,6 @@ export function uiArgv(shell, paths, wslDistro = "") {
67
64
  return [requirePath(paths.gitbash, shell), "-i"];
68
65
  case "msys2":
69
66
  return [requirePath(paths.msys2, shell), "-l"];
70
- case "payload":
71
- // The payload is a Git-for-Windows tree: the interactive rules are the
72
- // gitbash ones (an interactive non-login shell; its /etc still works).
73
- return [requirePath(paths.payload, shell), "-i"];
74
67
  case "niu":
75
68
  // Interactive non-login: niu reads ~/.niubashrc (its only Windows
76
69
  // startup file), so the user's prompt and colours survive.
@@ -114,12 +107,9 @@ function probe(id, facts) {
114
107
  const path = id === "powershell" ? facts.paths.pwsh
115
108
  : id === "gitbash" ? facts.paths.gitbash
116
109
  : id === "msys2" ? facts.paths.msys2
117
- : id === "payload" ? facts.paths.payload
118
- : id === "niu" ? facts.paths.niu
119
- : facts.paths.wsl;
110
+ : id === "niu" ? facts.paths.niu
111
+ : facts.paths.wsl;
120
112
  if (path === undefined || path.length === 0) {
121
- if (id === "payload" && facts.payloadSuppressed === true)
122
- return { available: false, reason: "wsl-preferred" };
123
113
  return { available: false, reason: "not-installed" };
124
114
  }
125
115
  // A configured path is honoured, but a launcher is not a shell: trusting the