dsh-bash-terminal-ts 0.8.1 → 0.8.3
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/lib/payload.js
ADDED
|
@@ -0,0 +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
|
+
}
|
package/lib/shell-id.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/** The
|
|
2
|
-
export type ShellId = "powershell" | "gitbash" | "msys2" | "wsl";
|
|
1
|
+
/** The five backends, in catalog order (`payload` = the pinned POSIX runtime). */
|
|
2
|
+
export type ShellId = "powershell" | "gitbash" | "msys2" | "wsl" | "payload";
|
package/lib/shells.d.ts
CHANGED
|
@@ -2,10 +2,12 @@ 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.
|
|
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. */
|
|
6
8
|
export declare const SHELL_PRIORITY: readonly ShellId[];
|
|
7
9
|
/** Why one backend is not launchable (drives the settings-row badge). */
|
|
8
|
-
export type ShellUnavailable = "installed" | "not-installed" | "no-distro" | "launcher-only";
|
|
10
|
+
export type ShellUnavailable = "installed" | "not-installed" | "no-distro" | "launcher-only" | "wsl-preferred";
|
|
9
11
|
/** One catalog row: what the UI shows and what the host would spawn. */
|
|
10
12
|
export interface ShellEntry {
|
|
11
13
|
readonly id: ShellId;
|
|
@@ -27,6 +29,7 @@ export interface ShellSwitches {
|
|
|
27
29
|
gitbash: boolean;
|
|
28
30
|
msys2: boolean;
|
|
29
31
|
wsl: boolean;
|
|
32
|
+
payload: boolean;
|
|
30
33
|
}
|
|
31
34
|
/** Everything the catalog builder needs from the outside world. */
|
|
32
35
|
export interface CatalogFacts {
|
|
@@ -40,6 +43,12 @@ export interface CatalogFacts {
|
|
|
40
43
|
switches: ShellSwitches;
|
|
41
44
|
/** WSL distro override from config ('' = the WSL default). */
|
|
42
45
|
wslDistro: string;
|
|
46
|
+
/**
|
|
47
|
+
* True when the payload gate was vetoed by a positively-detected WSL distro
|
|
48
|
+
* (a real Linux bash outranks the MSYS payload). It only colors the payload
|
|
49
|
+
* row's badge when no payload path resolved - "why" information, not a gate.
|
|
50
|
+
*/
|
|
51
|
+
payloadSuppressed?: boolean;
|
|
43
52
|
}
|
|
44
53
|
/**
|
|
45
54
|
* `<SystemRoot>\System32\bash.exe` (and the sysnative mirror) is the deprecated
|
package/lib/shells.js
CHANGED
|
@@ -15,14 +15,17 @@
|
|
|
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.
|
|
19
|
-
|
|
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", "payload"];
|
|
20
22
|
/** Display labels. The catalog id/label pair is DECIDED BY THIS TABLE. */
|
|
21
23
|
const LABELS = {
|
|
22
24
|
powershell: "PowerShell",
|
|
23
25
|
gitbash: "Git Bash",
|
|
24
26
|
msys2: "MSYS2",
|
|
25
27
|
wsl: "WSL bash",
|
|
28
|
+
payload: "POSIX payload",
|
|
26
29
|
};
|
|
27
30
|
/**
|
|
28
31
|
* `<SystemRoot>\System32\bash.exe` (and the sysnative mirror) is the deprecated
|
|
@@ -63,6 +66,10 @@ export function uiArgv(shell, paths, wslDistro = "") {
|
|
|
63
66
|
return [requirePath(paths.gitbash, shell), "-i"];
|
|
64
67
|
case "msys2":
|
|
65
68
|
return [requirePath(paths.msys2, shell), "-l"];
|
|
69
|
+
case "payload":
|
|
70
|
+
// The payload is a Git-for-Windows tree: the interactive rules are the
|
|
71
|
+
// gitbash ones (an interactive non-login shell; its /etc still works).
|
|
72
|
+
return [requirePath(paths.payload, shell), "-i"];
|
|
66
73
|
case "wsl": {
|
|
67
74
|
const distro = wslDistro.trim();
|
|
68
75
|
return distro.length > 0
|
|
@@ -99,9 +106,16 @@ function requirePath(path, shell) {
|
|
|
99
106
|
}
|
|
100
107
|
/** One row's availability, given the injected facts. */
|
|
101
108
|
function probe(id, facts) {
|
|
102
|
-
const path = id === "powershell" ? facts.paths.pwsh
|
|
103
|
-
|
|
109
|
+
const path = id === "powershell" ? facts.paths.pwsh
|
|
110
|
+
: id === "gitbash" ? facts.paths.gitbash
|
|
111
|
+
: id === "msys2" ? facts.paths.msys2
|
|
112
|
+
: id === "payload" ? facts.paths.payload
|
|
113
|
+
: facts.paths.wsl;
|
|
114
|
+
if (path === undefined || path.length === 0) {
|
|
115
|
+
if (id === "payload" && facts.payloadSuppressed === true)
|
|
116
|
+
return { available: false, reason: "wsl-preferred" };
|
|
104
117
|
return { available: false, reason: "not-installed" };
|
|
118
|
+
}
|
|
105
119
|
// A configured path is honoured, but a launcher is not a shell: trusting the
|
|
106
120
|
// config here is how `msys2.exe` ends up in the menu and returns no output.
|
|
107
121
|
if (isConsoleLauncher(path))
|
package/lib/terminal.js
CHANGED
|
@@ -49,6 +49,7 @@ export function terminalArgv(shell, paths, distro) {
|
|
|
49
49
|
switch (shell) {
|
|
50
50
|
case "powershell": return [paths.pwsh, "-NoLogo", "-NoProfile"];
|
|
51
51
|
case "gitbash": return [paths.gitbash, "-i"];
|
|
52
|
+
case "payload": return [paths.payload, "-i"];
|
|
52
53
|
case "msys2":
|
|
53
54
|
// -l, NOT -lc: this argv carries no command (the PTY itself is the
|
|
54
55
|
// session), and `bash -lc` with no operand dies immediately with
|
|
@@ -16,6 +16,8 @@ export interface CatalogSource {
|
|
|
16
16
|
paths(): ResolvedPaths;
|
|
17
17
|
switches(): ShellSwitches;
|
|
18
18
|
wslDistro(): string;
|
|
19
|
+
/** Why the payload row has no path: vetoed by a detected WSL distro. */
|
|
20
|
+
payloadSuppressed(): boolean;
|
|
19
21
|
/** Cached distro list; undefined means "unknown", [] means "none installed". */
|
|
20
22
|
distros(): readonly string[] | undefined;
|
|
21
23
|
}
|
package/lib/webterminals/host.js
CHANGED
|
@@ -51,7 +51,7 @@ function num(value, fallback, max) {
|
|
|
51
51
|
* persist nothing, and look fine in the settings page. Two spellings of one fact
|
|
52
52
|
* always drift, so this table is the single place the name appears.
|
|
53
53
|
*/
|
|
54
|
-
const SWITCH_FIELD = { gitbash: "shellGitBash", msys2: "shellMsys2", wsl: "shellWsl" };
|
|
54
|
+
const SWITCH_FIELD = { gitbash: "shellGitBash", msys2: "shellMsys2", wsl: "shellWsl", payload: "shellPayload" };
|
|
55
55
|
/**
|
|
56
56
|
* Register the terminal routes.
|
|
57
57
|
* @param webServer - the host webserver (may lack upgrade support).
|
|
@@ -159,7 +159,7 @@ async function dispatch(body, deps) {
|
|
|
159
159
|
const next = requested;
|
|
160
160
|
// Persist first, then answer with a rebuilt catalog: a switch that cannot be
|
|
161
161
|
// stored must not look applied in the settings row.
|
|
162
|
-
for (const key of ["gitbash", "msys2", "wsl"]) {
|
|
162
|
+
for (const key of ["gitbash", "msys2", "wsl", "payload"]) {
|
|
163
163
|
if (typeof next[key] === "boolean")
|
|
164
164
|
await deps.writeConfig([SWITCH_FIELD[key]], next[key]);
|
|
165
165
|
}
|
|
@@ -30,6 +30,11 @@ export interface MountInput {
|
|
|
30
30
|
* service instance only exists here, so it is passed back in.
|
|
31
31
|
*/
|
|
32
32
|
persist(svc: unknown, path: readonly string[], value: unknown): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* True when the startup payload gate was vetoed by a detected WSL distro
|
|
35
|
+
* (index.ts owns the answer; the catalog only uses it for the row badge).
|
|
36
|
+
*/
|
|
37
|
+
payloadSuppressed?(): boolean;
|
|
33
38
|
platform?: NodeJS.Platform;
|
|
34
39
|
}
|
|
35
40
|
/** The mount outcome, reported through the routes' `unavailable` field. */
|
|
@@ -62,6 +62,9 @@ export function mountBrowserTerminals(input) {
|
|
|
62
62
|
gitbash: readField("shellGitBash", true),
|
|
63
63
|
msys2: readField("shellMsys2", true),
|
|
64
64
|
wsl: readField("shellWsl", true),
|
|
65
|
+
// Opt-in twice over: enablePosixPayload provisions the runtime, this
|
|
66
|
+
// switch decides whether a provisioned payload may show in pickers.
|
|
67
|
+
payload: readField("shellPayload", false),
|
|
65
68
|
});
|
|
66
69
|
const wslDistro = () => readField("wslDistro", "").trim();
|
|
67
70
|
/** The master switch: off hides the child switches and refuses allocations. */
|
|
@@ -94,6 +97,7 @@ export function mountBrowserTerminals(input) {
|
|
|
94
97
|
paths: () => input.paths,
|
|
95
98
|
switches,
|
|
96
99
|
wslDistro,
|
|
100
|
+
payloadSuppressed: input.payloadSuppressed ?? (() => false),
|
|
97
101
|
distros: () => {
|
|
98
102
|
if (distros === undefined && !probing)
|
|
99
103
|
reprobe();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-bash-terminal-ts",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"tag": "latest"
|
|
6
6
|
},
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
],
|
|
32
32
|
"engines": {
|
|
33
33
|
"node": ">=22",
|
|
34
|
-
"dsh": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1"
|
|
34
|
+
"dsh": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3"
|
|
35
35
|
},
|
|
36
36
|
"type": "module",
|
|
37
37
|
"main": "lib/index.js",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"src",
|
|
48
48
|
"scripts",
|
|
49
49
|
"template",
|
|
50
|
+
"agent-presets",
|
|
50
51
|
"locale",
|
|
51
52
|
"tsconfig.json",
|
|
52
53
|
"tsconfig.client.json",
|
|
@@ -64,7 +65,9 @@
|
|
|
64
65
|
"build:client": "node scripts/build-client.mjs",
|
|
65
66
|
"test": "node test-dist/unit.js && node test-dist/apply.js && node test-dist/client.js && node test-dist/terminal.js && node test-dist/shells.js && node test-dist/webterminals.js && node test/browser.mjs",
|
|
66
67
|
"lint": "eslint .",
|
|
67
|
-
"link:shells": "node scripts/link-shells.mjs"
|
|
68
|
+
"link:shells": "node scripts/link-shells.mjs",
|
|
69
|
+
"payload:provision": "node scripts/provision-payload.mjs",
|
|
70
|
+
"presets:install": "node agent-presets/install-presets.mjs"
|
|
68
71
|
},
|
|
69
72
|
"dsh": {
|
|
70
73
|
"bundle": {
|
|
@@ -78,16 +81,19 @@
|
|
|
78
81
|
]
|
|
79
82
|
}
|
|
80
83
|
},
|
|
84
|
+
"optionalDependencies": {
|
|
85
|
+
"@drscrewdriver/posix-runtime-win32-x64": "0.1.2"
|
|
86
|
+
},
|
|
81
87
|
"peerDependencies": {
|
|
82
88
|
"@deepseek-ai/cordis": "^4.0.2",
|
|
83
|
-
"@deepseek-ai/dsh-client-locale": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1",
|
|
84
|
-
"@deepseek-ai/dsh-client-ui-slots": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1",
|
|
85
|
-
"@deepseek-ai/dsh-llm": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1",
|
|
86
|
-
"@deepseek-ai/dsh-sandbox": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1",
|
|
87
|
-
"@deepseek-ai/dsh-settings": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1",
|
|
88
|
-
"@deepseek-ai/dsh-shell": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1",
|
|
89
|
-
"@deepseek-ai/dsh-timeout": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1",
|
|
90
|
-
"@deepseek-ai/dsh-tools": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1",
|
|
89
|
+
"@deepseek-ai/dsh-client-locale": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3",
|
|
90
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3",
|
|
91
|
+
"@deepseek-ai/dsh-llm": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3",
|
|
92
|
+
"@deepseek-ai/dsh-sandbox": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3",
|
|
93
|
+
"@deepseek-ai/dsh-settings": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3",
|
|
94
|
+
"@deepseek-ai/dsh-shell": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3",
|
|
95
|
+
"@deepseek-ai/dsh-timeout": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3",
|
|
96
|
+
"@deepseek-ai/dsh-tools": "0.1.0-rc.2 || 0.1.0-rc.3 || 0.1.0-rc.6 || 0.1.0-rc.7 || 0.1.0-rc.8 || 0.1.1-rc.1 || 0.1.1-rc.2 || 0.1.2-rc.1 || 0.1.5-rc.1 || 0.1.5-rc.2 || 0.1.5-rc.3 || 0.1.7-rc.1 || 0.1.7-rc.2 || 0.2.0-rc.1 || 0.2.0-rc.2 || 0.2.1-rc.1 || 0.2.1-rc.2 || 0.2.1-rc.3",
|
|
91
97
|
"react": "^18.2.0"
|
|
92
98
|
},
|
|
93
99
|
"dependencies": {
|
|
@@ -87,7 +87,7 @@ const zhKeys = [...new Set([...locales.matchAll(/"((?:shell|dock|tab)\.[A-Za-z0-
|
|
|
87
87
|
assert.ok(zhKeys.length >= 30, `expected the full key set in lib/locales.js, found ${zhKeys.length}`);
|
|
88
88
|
const unusedKeys = zhKeys.filter((key) => !consumers.some((text) => text.includes(`"${key}"`)));
|
|
89
89
|
// `shell.<id>` is built by concatenation in the preference row, so those are wired.
|
|
90
|
-
const trulyUnused = unusedKeys.filter((key) => !/^shell\.(powershell|gitbash|msys2|wsl)$/.test(key));
|
|
90
|
+
const trulyUnused = unusedKeys.filter((key) => !/^shell\.(powershell|gitbash|msys2|wsl|payload)$/.test(key));
|
|
91
91
|
assert.deepStrictEqual(trulyUnused, [], `dictionary keys rendered by nothing: ${trulyUnused.join(", ")}`);
|
|
92
92
|
|
|
93
93
|
console.log(`ARTIFACT GATES PASS: id=${idMatch[1]} | client ${(bundle.length / 1024).toFixed(0)}KB, no node leaks, xterm bundled, css inlined | ws external | ${langs.length} locale files | ${zhKeys.length} dictionary keys, none dead`);
|
package/scripts/link-shells.mjs
CHANGED
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
// as Administrator: same command, to also create the Git one.
|
|
19
19
|
|
|
20
20
|
import { existsSync, linkSync, statSync } from "node:fs";
|
|
21
|
+
import { join } from "node:path";
|
|
22
|
+
import { ensurePayloadAlias, findPayloadStoreRoot, payloadAliasPaths } from "./payload-alias.mjs";
|
|
21
23
|
|
|
22
24
|
/** Each alias: the link to create and the shell it must point at. */
|
|
23
25
|
const ALIASES = [
|
|
@@ -66,6 +68,26 @@ for (const alias of ALIASES) {
|
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
|
|
71
|
+
// The pinned POSIX payload's menu entry: a hard link inside its own bin\ named
|
|
72
|
+
// bash-terminal.exe plus the stable `payloads\bash-terminal` junction the bundle
|
|
73
|
+
// patch points at. Absent payload = nothing to do (the candidate is skipped by
|
|
74
|
+
// the host per-candidate), so this never counts as blocked.
|
|
75
|
+
{
|
|
76
|
+
const paths = payloadAliasPaths(process.env);
|
|
77
|
+
if (paths === undefined) {
|
|
78
|
+
console.log("skip payload LOCALAPPDATA unset; no payload alias target");
|
|
79
|
+
} else {
|
|
80
|
+
const rootName = findPayloadStoreRoot(paths.store);
|
|
81
|
+
if (rootName === undefined) {
|
|
82
|
+
console.log(`skip payload no provisioned root under ${paths.store} (run scripts/provision-payload.mjs first)`);
|
|
83
|
+
} else {
|
|
84
|
+
const done = ensurePayloadAlias({ root: join(paths.store, rootName), junction: paths.junction });
|
|
85
|
+
if (done.skipped !== undefined) console.log(`BAD payload ${done.skipped}`);
|
|
86
|
+
else console.log(`ok payload ${done.link} + junction`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
69
91
|
console.log("");
|
|
70
92
|
if (blocked > 0) {
|
|
71
93
|
console.log(`${blocked} alias(es) still missing - the official shell menu will not offer them until they exist.`);
|