dsh-bash-terminal-ts 0.8.2 → 0.8.4
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.
- package/README.de.md +1 -1
- package/README.en.md +6 -2
- package/README.es.md +1 -1
- package/README.fr.md +1 -1
- package/README.it.md +1 -1
- package/README.md +5 -1
- package/README.ru.md +1 -1
- package/agent-presets/README.md +170 -0
- package/agent-presets/install-presets.mjs +179 -0
- package/agent-presets/standard-win/agent.cordis.yml +271 -0
- package/agent-presets/standard-win/preset.yml +2 -0
- package/agent-presets/standard-win-gitbash/agent.cordis.yml +271 -0
- package/agent-presets/standard-win-gitbash/preset.yml +2 -0
- package/agent-presets/standard-win-msys2/agent.cordis.yml +272 -0
- package/agent-presets/standard-win-msys2/preset.yml +2 -0
- package/agent-presets/standard-win-payload/agent.cordis.yml +271 -0
- package/agent-presets/standard-win-payload/preset.yml +2 -0
- package/agent-presets/standard-win-wsl2/agent.cordis.yml +271 -0
- package/agent-presets/standard-win-wsl2/preset.yml +2 -0
- package/cordis.patch.yml +12 -0
- package/dist/client.core.js +43 -12
- package/dist/client.js +43 -12
- package/dsh.plugin.json +2 -2
- package/lib/client.js +43 -12
- package/lib/dsh-types.d.ts +3 -1
- package/lib/index.d.ts +23 -2
- package/lib/index.js +79 -18
- package/lib/locales.js +27 -9
- package/lib/payload.d.ts +72 -0
- package/lib/payload.js +279 -0
- package/lib/shell-id.d.ts +2 -2
- package/lib/shells.d.ts +11 -2
- package/lib/shells.js +18 -4
- package/lib/terminal.js +1 -0
- package/lib/webterminals/catalog.d.ts +2 -0
- package/lib/webterminals/catalog.js +1 -0
- package/lib/webterminals/host.js +2 -2
- package/lib/webterminals/mount.d.ts +5 -0
- package/lib/webterminals/mount.js +4 -0
- package/package.json +17 -11
- package/scripts/check-artifacts.mjs +1 -1
- package/scripts/link-shells.mjs +22 -0
- package/scripts/payload-alias.mjs +97 -0
- package/scripts/provision-payload.mjs +233 -0
- package/src/client.tsx +29 -4
- package/src/dsh-types.ts +3 -1
- package/src/index.ts +117 -16
- package/src/locales.ts +27 -9
- package/src/payload.ts +322 -0
- package/src/shell-id.ts +2 -2
- package/src/shells.ts +27 -5
- package/src/terminal.ts +1 -0
- package/src/webterminals/browser/api.ts +1 -1
- package/src/webterminals/catalog.ts +3 -0
- package/src/webterminals/host.ts +2 -2
- package/src/webterminals/mount.ts +9 -0
package/src/payload.ts
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
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
|
+
|
|
45
|
+
import { createHash } from "node:crypto";
|
|
46
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
47
|
+
import { dirname, join } from "node:path";
|
|
48
|
+
import { createRequire } from "node:module";
|
|
49
|
+
import type * as ChildProcess from "node:child_process";
|
|
50
|
+
|
|
51
|
+
/** npm package name of OUR POSIX runtime repack (optionalDependency-style; absent = simply no payload). */
|
|
52
|
+
export const PAYLOAD_PACKAGE = "@drscrewdriver/posix-runtime-win32-x64";
|
|
53
|
+
/** Trust record written next to a provisioned payload root by scripts/provision-payload.mjs. */
|
|
54
|
+
export const TRUST_FILE_NAME = "payload.trust.json";
|
|
55
|
+
/** Files every payload root must expose for verification, normalized to forward slashes, lowercase. */
|
|
56
|
+
export const REQUIRED_FILES: readonly string[] = ["bin/bash.exe", "usr/bin/msys-2.0.dll"];
|
|
57
|
+
|
|
58
|
+
/** One pinned payload build = one digest map. Keyed by the `posix-*` label. */
|
|
59
|
+
export type DigestMap = Record<string, string>;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Built-in ledger, keyed by payload build label. Populated by
|
|
63
|
+
* `provision-payload.mjs --emit-ledger` at release time (V-flow). EMPTY on a
|
|
64
|
+
* fresh checkout by design: with no ledger entry, a root is only usable if the
|
|
65
|
+
* operator's local trust file pins it - which is an explicit human act, the
|
|
66
|
+
* same posture as `dsh-ops provision-shells` but self-managed.
|
|
67
|
+
*/
|
|
68
|
+
export const PAYLOAD_LEDGER: Readonly<Record<string, DigestMap>> = {};
|
|
69
|
+
|
|
70
|
+
export type PayloadVerdict =
|
|
71
|
+
| { readonly ok: true; readonly bashPath: string; readonly source: "ledger" | "trust" }
|
|
72
|
+
| { readonly ok: false; readonly reason: string };
|
|
73
|
+
|
|
74
|
+
/** The OS face this module needs; tests substitute a table-driven fake. */
|
|
75
|
+
export interface PayloadProbe {
|
|
76
|
+
exists(path: string): boolean;
|
|
77
|
+
read(path: string): Buffer | undefined;
|
|
78
|
+
/** `size|mtimeMs` fingerprint for the hash cache, or undefined when unstatable. */
|
|
79
|
+
stamp(path: string): string | undefined;
|
|
80
|
+
readdir(dir: string): string[];
|
|
81
|
+
/** Directory holding `package.json` of PAYLOAD_PACKAGE, if installed. */
|
|
82
|
+
resolvePackageRoot(): string | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* WSL distro probe: names of installed distros, or undefined when the probe
|
|
85
|
+
* cannot answer (undefined is NOT "no distro" - absence needs a positive
|
|
86
|
+
* empty list, same three-valued rule as the browser catalog's distros fact).
|
|
87
|
+
*/
|
|
88
|
+
wslDistros(): readonly string[] | undefined;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Environment directory carrying auto-discovered payload roots. */
|
|
92
|
+
export function payloadStoreDir(env: NodeJS.ProcessEnv = process.env): string | undefined {
|
|
93
|
+
const localAppData = env.LOCALAPPDATA;
|
|
94
|
+
if (typeof localAppData !== "string" || localAppData.trim().length === 0) return undefined;
|
|
95
|
+
return join(localAppData, "dsh-bash-terminal-ts", "payloads");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ---- default probe (real fs / wsl) --------------------------------------------
|
|
99
|
+
|
|
100
|
+
const defaultProbe: PayloadProbe = {
|
|
101
|
+
exists: (p) => {
|
|
102
|
+
try {
|
|
103
|
+
return existsSync(p);
|
|
104
|
+
} catch {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
read: (p) => {
|
|
109
|
+
try {
|
|
110
|
+
return readFileSync(p);
|
|
111
|
+
} catch {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
stamp: (p) => {
|
|
116
|
+
try {
|
|
117
|
+
const st = statSync(p);
|
|
118
|
+
return `${st.size}|${st.mtimeMs}`;
|
|
119
|
+
} catch {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
readdir: (d) => {
|
|
124
|
+
try {
|
|
125
|
+
return readdirSync(d);
|
|
126
|
+
} catch {
|
|
127
|
+
return [];
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
resolvePackageRoot: () => {
|
|
131
|
+
try {
|
|
132
|
+
const req = createRequire(import.meta.url);
|
|
133
|
+
return dirname(req.resolve(`${PAYLOAD_PACKAGE}/package.json`));
|
|
134
|
+
} catch {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
wslDistros: () => {
|
|
139
|
+
try {
|
|
140
|
+
// The child_process face is loaded lazily so importers that never touch
|
|
141
|
+
// the default probe (browser-side graphs, pure unit tests with an
|
|
142
|
+
// injected probe) do not pull it in; spawnSync with a short timeout:
|
|
143
|
+
// `wsl -l -q` is fast when WSL is present and hangs (or errors) when it
|
|
144
|
+
// is a stub, which is exactly the "cannot answer" case.
|
|
145
|
+
const { spawnSync } = require_child_process();
|
|
146
|
+
// wsl.exe writes UTF-16LE (measured: "Ubuntu" arrives as U\0b\0u\0...),
|
|
147
|
+
// so `encoding: "utf8"` would turn an EMPTY distro list into one
|
|
148
|
+
// mojibake line - a false "WSL has a distro" that would veto the
|
|
149
|
+
// payload on machines that have none. Read bytes and decode by shape:
|
|
150
|
+
// NUL interleaving means UTF-16LE, everything else is ascii/utf8.
|
|
151
|
+
const r = spawnSync("wsl.exe", ["-l", "-q"], { timeout: 5000, windowsHide: true });
|
|
152
|
+
if (r.error !== undefined || r.status === null || !Buffer.isBuffer(r.stdout)) return undefined;
|
|
153
|
+
const raw: Buffer = r.stdout;
|
|
154
|
+
const text = raw.includes(0x00) ? raw.toString("utf16le") : raw.toString("utf8");
|
|
155
|
+
const names = text.split(/\r?\n/).map((l) => l.replaceAll("\u0000", "").trim()).filter((l) => l.length > 0);
|
|
156
|
+
return names;
|
|
157
|
+
} catch {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// Type-only import above, runtime require here: the module reference is erased
|
|
164
|
+
// at compile time, so the host graph stays free of a static child_process edge.
|
|
165
|
+
function require_child_process(): typeof ChildProcess {
|
|
166
|
+
return createRequire(import.meta.url)("node:child_process") as typeof ChildProcess;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// ---- hashing -------------------------------------------------------------------
|
|
170
|
+
|
|
171
|
+
const hashCache = new Map<string, { stamp: string; sha: string }>();
|
|
172
|
+
|
|
173
|
+
/** sha256 hex of one file, memoized on (size, mtimeMs); undefined when unreadable. */
|
|
174
|
+
export function hashFile(path: string, probe: PayloadProbe = defaultProbe): string | undefined {
|
|
175
|
+
const stamp = probe.stamp(path);
|
|
176
|
+
if (stamp === undefined) return undefined;
|
|
177
|
+
const hit = hashCache.get(path);
|
|
178
|
+
if (hit !== undefined && hit.stamp === stamp) return hit.sha;
|
|
179
|
+
const buf = probe.read(path);
|
|
180
|
+
if (buf === undefined) return undefined;
|
|
181
|
+
const sha = createHash("sha256").update(buf).digest("hex");
|
|
182
|
+
hashCache.set(path, { stamp, sha });
|
|
183
|
+
return sha;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Test/backdoor: drop the memo (a payload replaced in place must re-verify). */
|
|
187
|
+
export function clearHashCache(): void {
|
|
188
|
+
hashCache.clear();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// ---- verification ----------------------------------------------------------------
|
|
192
|
+
|
|
193
|
+
function normalizeRel(p: string): string {
|
|
194
|
+
return p.replaceAll("\\", "/").toLowerCase();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function digestMapsMatch(actual: Record<string, string | undefined>, pinned: DigestMap): boolean {
|
|
198
|
+
const keys = Object.keys(pinned);
|
|
199
|
+
if (keys.length === 0) return false;
|
|
200
|
+
return keys.every((k) => {
|
|
201
|
+
const want = pinned[k];
|
|
202
|
+
const got = actual[normalizeRel(k)];
|
|
203
|
+
return typeof want === "string" && typeof got === "string" && want.toLowerCase() === got;
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Verify one payload root: both REQUIRED_FILES exist, their digests match the
|
|
209
|
+
* built-in ledger OR the root-local trust file. Everything else fails closed.
|
|
210
|
+
*/
|
|
211
|
+
export function verifyPayloadRoot(root: string, probe: PayloadProbe = defaultProbe): PayloadVerdict {
|
|
212
|
+
const bashPath = join(root, "bin", "bash.exe");
|
|
213
|
+
const dllPath = join(root, "usr", "bin", "msys-2.0.dll");
|
|
214
|
+
if (!probe.exists(root)) return { ok: false, reason: `missing-root:${root}` };
|
|
215
|
+
if (!probe.exists(bashPath) || !probe.exists(dllPath)) {
|
|
216
|
+
return { ok: false, reason: `missing-files:${root}` };
|
|
217
|
+
}
|
|
218
|
+
const actual: Record<string, string | undefined> = {
|
|
219
|
+
"bin/bash.exe": hashFile(bashPath, probe),
|
|
220
|
+
"usr/bin/msys-2.0.dll": hashFile(dllPath, probe)
|
|
221
|
+
};
|
|
222
|
+
if (Object.values(actual).some((v) => v === undefined)) {
|
|
223
|
+
return { ok: false, reason: `unreadable:${root}` };
|
|
224
|
+
}
|
|
225
|
+
for (const pinned of Object.values(PAYLOAD_LEDGER)) {
|
|
226
|
+
if (digestMapsMatch(actual, pinned)) return { ok: true, bashPath, source: "ledger" };
|
|
227
|
+
}
|
|
228
|
+
const trustRaw = probe.read(join(root, TRUST_FILE_NAME));
|
|
229
|
+
if (trustRaw !== undefined) {
|
|
230
|
+
let trust: unknown;
|
|
231
|
+
try {
|
|
232
|
+
trust = JSON.parse(trustRaw.toString("utf8"));
|
|
233
|
+
} catch {
|
|
234
|
+
return { ok: false, reason: `trust-unparsed:${root}` };
|
|
235
|
+
}
|
|
236
|
+
const files = (trust as { files?: unknown }).files;
|
|
237
|
+
if (files !== null && typeof files === "object") {
|
|
238
|
+
const map: DigestMap = {};
|
|
239
|
+
for (const [k, v] of Object.entries(files as Record<string, unknown>)) {
|
|
240
|
+
if (typeof v === "string") map[normalizeRel(k)] = v.toLowerCase();
|
|
241
|
+
}
|
|
242
|
+
// The trust file must pin EVERY required file, or it does not constitute
|
|
243
|
+
// an approval of the executor we are about to run.
|
|
244
|
+
if (REQUIRED_FILES.every((f) => f in map) && digestMapsMatch(actual, map)) {
|
|
245
|
+
return { ok: true, bashPath, source: "trust" };
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return { ok: false, reason: `digest-mismatch:${root}` };
|
|
249
|
+
}
|
|
250
|
+
return { ok: false, reason: `digest-unknown:${root}` };
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// ---- root discovery ----------------------------------------------------------------
|
|
254
|
+
|
|
255
|
+
/** Candidate payload roots in preference order: explicit path, npm package, store dir. */
|
|
256
|
+
export function findPayloadRoots(
|
|
257
|
+
config: { payloadBashPath?: string },
|
|
258
|
+
probe: PayloadProbe = defaultProbe,
|
|
259
|
+
env: NodeJS.ProcessEnv = process.env
|
|
260
|
+
): string[] {
|
|
261
|
+
const roots: string[] = [];
|
|
262
|
+
const push = (r: string | undefined) => {
|
|
263
|
+
if (typeof r === "string" && r.trim().length > 0 && !roots.includes(r)) roots.push(r);
|
|
264
|
+
};
|
|
265
|
+
const explicit = (config.payloadBashPath ?? "").trim();
|
|
266
|
+
if (explicit.length > 0 && /bash\.exe$/i.test(explicit)) push(dirname(dirname(explicit)));
|
|
267
|
+
else if (explicit.length > 0) push(explicit); // a root directory is also honoured
|
|
268
|
+
push(probe.resolvePackageRoot());
|
|
269
|
+
const store = payloadStoreDir(env);
|
|
270
|
+
if (store !== undefined) {
|
|
271
|
+
for (const child of probe.readdir(store)) {
|
|
272
|
+
const full = join(store, child);
|
|
273
|
+
if (probe.exists(join(full, "bin", "bash.exe"))) push(full);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return roots;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export interface PayloadOutcome {
|
|
280
|
+
/** True only when a verified payload bash was selected. */
|
|
281
|
+
readonly engaged: boolean;
|
|
282
|
+
readonly bashPath?: string;
|
|
283
|
+
/** True when a WSL distro was positively detected - advisory, not a veto. */
|
|
284
|
+
readonly wslPreferred?: boolean;
|
|
285
|
+
/** One-shot human-readable notes for the plugin log. */
|
|
286
|
+
readonly notes: readonly string[];
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* The whole decision table for one startup. Call ONLY when the payload feature
|
|
291
|
+
* is enabled; the caller wires the resulting `bashPath` into the gitbash slot
|
|
292
|
+
* of `resolveAllPaths` as the last-resort source.
|
|
293
|
+
*/
|
|
294
|
+
export function resolvePayloadBash(
|
|
295
|
+
config: { payloadBashPath?: string },
|
|
296
|
+
probe: PayloadProbe = defaultProbe,
|
|
297
|
+
env: NodeJS.ProcessEnv = process.env
|
|
298
|
+
): PayloadOutcome {
|
|
299
|
+
const notes: string[] = [];
|
|
300
|
+
const distros = probe.wslDistros();
|
|
301
|
+
const wslPreferred = distros !== undefined && distros.length > 0;
|
|
302
|
+
if (wslPreferred) {
|
|
303
|
+
notes.push(
|
|
304
|
+
`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.`
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
const roots = findPayloadRoots(config, probe, env);
|
|
308
|
+
if (roots.length === 0) {
|
|
309
|
+
notes.push("posix-payload: enabled but no payload root found (provision one with scripts/provision-payload.mjs or set payloadPosixPath).");
|
|
310
|
+
return { engaged: false, wslPreferred, notes };
|
|
311
|
+
}
|
|
312
|
+
const failures: string[] = [];
|
|
313
|
+
for (const root of roots) {
|
|
314
|
+
const verdict = verifyPayloadRoot(root, probe);
|
|
315
|
+
if (verdict.ok) {
|
|
316
|
+
return { engaged: true, bashPath: verdict.bashPath, wslPreferred, notes };
|
|
317
|
+
}
|
|
318
|
+
failures.push(verdict.reason);
|
|
319
|
+
}
|
|
320
|
+
notes.push(`posix-payload: every candidate root failed the digest gate, fail-closed (not run): ${failures.join("; ")}`);
|
|
321
|
+
return { engaged: false, wslPreferred, notes };
|
|
322
|
+
}
|
package/src/shell-id.ts
CHANGED
|
@@ -7,5 +7,5 @@
|
|
|
7
7
|
// in both tsconfig graphs without dragging `@types/node` into the client purity
|
|
8
8
|
// gate.
|
|
9
9
|
|
|
10
|
-
/** The
|
|
11
|
-
export type ShellId = "powershell" | "gitbash" | "msys2" | "wsl";
|
|
10
|
+
/** The five backends, in catalog order (`payload` = the pinned POSIX runtime). */
|
|
11
|
+
export type ShellId = "powershell" | "gitbash" | "msys2" | "wsl" | "payload";
|
package/src/shells.ts
CHANGED
|
@@ -22,11 +22,13 @@ import type { ShellId } from "./shell-id.js";
|
|
|
22
22
|
/** Re-exported so existing importers keep working (see shell-id.ts for why). */
|
|
23
23
|
export type { ShellId };
|
|
24
24
|
|
|
25
|
-
/** Catalog order = fallback order: powershell is BOTH first choice and floor.
|
|
26
|
-
|
|
25
|
+
/** Catalog order = fallback order: powershell is BOTH first choice and floor. The
|
|
26
|
+
* pinned POSIX payload sits last: it only earns a seat when the machine's own
|
|
27
|
+
* shells are absent, and a detected WSL distro vetoes it before that. */
|
|
28
|
+
export const SHELL_PRIORITY: readonly ShellId[] = ["powershell", "gitbash", "msys2", "wsl", "payload"];
|
|
27
29
|
|
|
28
30
|
/** Why one backend is not launchable (drives the settings-row badge). */
|
|
29
|
-
export type ShellUnavailable = "installed" | "not-installed" | "no-distro" | "launcher-only";
|
|
31
|
+
export type ShellUnavailable = "installed" | "not-installed" | "no-distro" | "launcher-only" | "wsl-preferred";
|
|
30
32
|
|
|
31
33
|
/** One catalog row: what the UI shows and what the host would spawn. */
|
|
32
34
|
export interface ShellEntry {
|
|
@@ -50,6 +52,7 @@ export interface ShellSwitches {
|
|
|
50
52
|
gitbash: boolean;
|
|
51
53
|
msys2: boolean;
|
|
52
54
|
wsl: boolean;
|
|
55
|
+
payload: boolean;
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
/** Everything the catalog builder needs from the outside world. */
|
|
@@ -64,6 +67,12 @@ export interface CatalogFacts {
|
|
|
64
67
|
switches: ShellSwitches;
|
|
65
68
|
/** WSL distro override from config ('' = the WSL default). */
|
|
66
69
|
wslDistro: string;
|
|
70
|
+
/**
|
|
71
|
+
* True when the payload gate was vetoed by a positively-detected WSL distro
|
|
72
|
+
* (a real Linux bash outranks the MSYS payload). It only colors the payload
|
|
73
|
+
* row's badge when no payload path resolved - "why" information, not a gate.
|
|
74
|
+
*/
|
|
75
|
+
payloadSuppressed?: boolean;
|
|
67
76
|
}
|
|
68
77
|
|
|
69
78
|
/** Display labels. The catalog id/label pair is DECIDED BY THIS TABLE. */
|
|
@@ -72,6 +81,7 @@ const LABELS: Record<ShellId, string> = {
|
|
|
72
81
|
gitbash: "Git Bash",
|
|
73
82
|
msys2: "MSYS2",
|
|
74
83
|
wsl: "WSL bash",
|
|
84
|
+
payload: "POSIX payload",
|
|
75
85
|
};
|
|
76
86
|
|
|
77
87
|
/**
|
|
@@ -114,6 +124,10 @@ export function uiArgv(shell: ShellId, paths: ResolvedPaths, wslDistro = ""): st
|
|
|
114
124
|
return [requirePath(paths.gitbash, shell), "-i"];
|
|
115
125
|
case "msys2":
|
|
116
126
|
return [requirePath(paths.msys2, shell), "-l"];
|
|
127
|
+
case "payload":
|
|
128
|
+
// The payload is a Git-for-Windows tree: the interactive rules are the
|
|
129
|
+
// gitbash ones (an interactive non-login shell; its /etc still works).
|
|
130
|
+
return [requirePath(paths.payload, shell), "-i"];
|
|
117
131
|
case "wsl": {
|
|
118
132
|
const distro = wslDistro.trim();
|
|
119
133
|
return distro.length > 0
|
|
@@ -152,8 +166,16 @@ function requirePath(path: string | undefined, shell: ShellId): string {
|
|
|
152
166
|
|
|
153
167
|
/** One row's availability, given the injected facts. */
|
|
154
168
|
function probe(id: ShellId, facts: CatalogFacts): { available: boolean; reason: ShellUnavailable; path?: string } {
|
|
155
|
-
const path =
|
|
156
|
-
|
|
169
|
+
const path =
|
|
170
|
+
id === "powershell" ? facts.paths.pwsh
|
|
171
|
+
: id === "gitbash" ? facts.paths.gitbash
|
|
172
|
+
: id === "msys2" ? facts.paths.msys2
|
|
173
|
+
: id === "payload" ? facts.paths.payload
|
|
174
|
+
: facts.paths.wsl;
|
|
175
|
+
if (path === undefined || path.length === 0) {
|
|
176
|
+
if (id === "payload" && facts.payloadSuppressed === true) return { available: false, reason: "wsl-preferred" };
|
|
177
|
+
return { available: false, reason: "not-installed" };
|
|
178
|
+
}
|
|
157
179
|
// A configured path is honoured, but a launcher is not a shell: trusting the
|
|
158
180
|
// config here is how `msys2.exe` ends up in the menu and returns no output.
|
|
159
181
|
if (isConsoleLauncher(path)) return { available: false, reason: "launcher-only", path };
|
package/src/terminal.ts
CHANGED
|
@@ -80,6 +80,7 @@ export function terminalArgv(
|
|
|
80
80
|
switch (shell) {
|
|
81
81
|
case "powershell": return [paths.pwsh, "-NoLogo", "-NoProfile"];
|
|
82
82
|
case "gitbash": return [paths.gitbash, "-i"];
|
|
83
|
+
case "payload": return [paths.payload, "-i"];
|
|
83
84
|
case "msys2":
|
|
84
85
|
// -l, NOT -lc: this argv carries no command (the PTY itself is the
|
|
85
86
|
// session), and `bash -lc` with no operand dies immediately with
|
|
@@ -35,7 +35,7 @@ export interface CatalogEntry {
|
|
|
35
35
|
readonly label: string;
|
|
36
36
|
readonly path?: string;
|
|
37
37
|
readonly available: boolean;
|
|
38
|
-
readonly reason: "installed" | "not-installed" | "no-distro" | "launcher-only";
|
|
38
|
+
readonly reason: "installed" | "not-installed" | "no-distro" | "launcher-only" | "wsl-preferred";
|
|
39
39
|
readonly activated: boolean;
|
|
40
40
|
readonly togglable: boolean;
|
|
41
41
|
readonly argv?: readonly string[];
|
|
@@ -68,6 +68,8 @@ export interface CatalogSource {
|
|
|
68
68
|
paths(): ResolvedPaths;
|
|
69
69
|
switches(): ShellSwitches;
|
|
70
70
|
wslDistro(): string;
|
|
71
|
+
/** Why the payload row has no path: vetoed by a detected WSL distro. */
|
|
72
|
+
payloadSuppressed(): boolean;
|
|
71
73
|
/** Cached distro list; undefined means "unknown", [] means "none installed". */
|
|
72
74
|
distros(): readonly string[] | undefined;
|
|
73
75
|
}
|
|
@@ -97,6 +99,7 @@ export function createCatalogProvider(source: CatalogSource, now: () => number =
|
|
|
97
99
|
distros: source.distros(),
|
|
98
100
|
switches: source.switches(),
|
|
99
101
|
wslDistro: source.wslDistro(),
|
|
102
|
+
payloadSuppressed: source.payloadSuppressed(),
|
|
100
103
|
});
|
|
101
104
|
return {
|
|
102
105
|
catalog: () => {
|
package/src/webterminals/host.ts
CHANGED
|
@@ -129,7 +129,7 @@ function num(value: unknown, fallback: number, max: number): number {
|
|
|
129
129
|
* persist nothing, and look fine in the settings page. Two spellings of one fact
|
|
130
130
|
* always drift, so this table is the single place the name appears.
|
|
131
131
|
*/
|
|
132
|
-
const SWITCH_FIELD: Record<string, string> = { gitbash: "shellGitBash", msys2: "shellMsys2", wsl: "shellWsl" };
|
|
132
|
+
const SWITCH_FIELD: Record<string, string> = { gitbash: "shellGitBash", msys2: "shellMsys2", wsl: "shellWsl", payload: "shellPayload" };
|
|
133
133
|
|
|
134
134
|
/**
|
|
135
135
|
* Register the terminal routes.
|
|
@@ -237,7 +237,7 @@ async function dispatch(body: RequestBody, deps: UiBridgeDeps): Promise<unknown>
|
|
|
237
237
|
const next = requested as Record<string, unknown>;
|
|
238
238
|
// Persist first, then answer with a rebuilt catalog: a switch that cannot be
|
|
239
239
|
// stored must not look applied in the settings row.
|
|
240
|
-
for (const key of ["gitbash", "msys2", "wsl"] as const) {
|
|
240
|
+
for (const key of ["gitbash", "msys2", "wsl", "payload"] as const) {
|
|
241
241
|
if (typeof next[key] === "boolean") await deps.writeConfig([SWITCH_FIELD[key]!], next[key]);
|
|
242
242
|
}
|
|
243
243
|
if (typeof body.wslDistro === "string") await deps.writeConfig(["wslDistro"], body.wslDistro);
|
|
@@ -76,6 +76,11 @@ export interface MountInput {
|
|
|
76
76
|
* service instance only exists here, so it is passed back in.
|
|
77
77
|
*/
|
|
78
78
|
persist(svc: unknown, path: readonly string[], value: unknown): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* True when the startup payload gate was vetoed by a detected WSL distro
|
|
81
|
+
* (index.ts owns the answer; the catalog only uses it for the row badge).
|
|
82
|
+
*/
|
|
83
|
+
payloadSuppressed?(): boolean;
|
|
79
84
|
platform?: NodeJS.Platform;
|
|
80
85
|
}
|
|
81
86
|
|
|
@@ -114,6 +119,9 @@ export function mountBrowserTerminals(input: MountInput): BrowserTerminalMount {
|
|
|
114
119
|
gitbash: readField("shellGitBash", true),
|
|
115
120
|
msys2: readField("shellMsys2", true),
|
|
116
121
|
wsl: readField("shellWsl", true),
|
|
122
|
+
// Opt-in twice over: enablePosixPayload provisions the runtime, this
|
|
123
|
+
// switch decides whether a provisioned payload may show in pickers.
|
|
124
|
+
payload: readField("shellPayload", false),
|
|
117
125
|
});
|
|
118
126
|
const wslDistro = (): string => readField("wslDistro", "").trim();
|
|
119
127
|
/** The master switch: off hides the child switches and refuses allocations. */
|
|
@@ -148,6 +156,7 @@ export function mountBrowserTerminals(input: MountInput): BrowserTerminalMount {
|
|
|
148
156
|
paths: () => input.paths,
|
|
149
157
|
switches,
|
|
150
158
|
wslDistro,
|
|
159
|
+
payloadSuppressed: input.payloadSuppressed ?? (() => false),
|
|
151
160
|
distros: () => {
|
|
152
161
|
if (distros === undefined && !probing) reprobe();
|
|
153
162
|
return distros;
|