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
@@ -1,237 +1,228 @@
1
- // The wiring seam between the plugin's live config and the browser terminal.
2
- //
3
- // It lives in its own module because of one hard ordering fact (findings F1): the
4
- // host entry this plugin ships returns early on non-Windows platforms, since the
5
- // *model tool* is Windows-only. The browser terminal is not a Windows-only idea,
6
- // so its mount has to happen before that return - and keeping it in one call makes
7
- // that ordering visible at the call site instead of buried in a 1000-line apply().
8
- //
9
- // Everything environment-dependent arrives as live reads (config fields are
10
- // `.volatile()` on the 0.1.7+ lines, and older lines re-read from the same
11
- // closure), never a snapshot: a switch flipped in the settings page must apply to
12
- // the next allocation without a restart.
13
-
14
- import { createCatalogProvider } from "./catalog.js";
15
- import { listWslDistros } from "./catalog.js";
16
- import { reportSettingsSurface, settingsSurface } from "../settings-surface.js";
17
- import { registerUiTerminalRoutes } from "./host.js";
18
- import { UiTerminalRegistry } from "./registry.js";
19
- import { createUiSpawner, detectBackend } from "./pty.js";
20
- import { SHELL_PRIORITY } from "../shells.js";
21
- import type { ShellSwitches } from "../shells.js";
22
- import type { ResolvedPaths } from "../dsh-types.js";
23
-
24
- /** How many terminals one session may hold, and how many exist host-wide. */
25
- const MAX_PER_SESSION = 6;
26
- const MAX_TOTAL = 12;
27
- /** Detached-shell grace: long enough to survive a page reload, short enough to
28
- * not leak a shell someone abandoned. */
29
- const IDLE_GRACE_MS = 120_000;
30
- /** Replayed screen budget per terminal. */
31
- const SCROLLBACK_BYTES = 200_000;
32
-
33
- /** A live `.volatile()` reference as the 0.1.7+ loader hands it. */
34
- interface VolatileRef<T> {
35
- get(): T;
36
- }
37
-
38
- /** Read a config field that may be a value or a live ref. */
39
- function live<T>(value: T | VolatileRef<T> | undefined, fallback: T): T {
40
- if (typeof value === "object" && value !== null && typeof (value as VolatileRef<T>).get === "function") {
41
- const got = (value as VolatileRef<T>).get();
42
- return got === undefined ? fallback : got;
43
- }
44
- return value === undefined ? fallback : (value as T);
45
- }
46
-
47
- /** The session lookup for one terminal's cwd. */
48
- interface SessionsLike {
49
- get?(id: string): { header?: { cwd?: string } } | undefined;
50
- }
51
-
52
- /** The service-arrival context cordis hands the `inject` callback. */
53
- interface ArrivalContext {
54
- webServer?: unknown;
55
- settings?: unknown;
56
- effect(fn: () => unknown, name?: string): unknown;
57
- }
58
-
59
- /** What the caller passes; all of it comes from the plugin's own context. */
60
- export interface MountInput {
61
- /** The plugin context, widened: only three reads are used. */
62
- ctx: {
63
- subprocess?: { spawnTerminal?: unknown };
64
- get?(name: string): unknown;
65
- effect(fn: () => unknown, name?: string): unknown;
66
- inject?(deps: string[], fn: (svcCtx: ArrivalContext) => void): void;
67
- logger?: { info?(msg: string): void; warn?(msg: string): void };
68
- };
69
- config: Record<string, unknown>;
70
- paths: ResolvedPaths;
71
- /** The stored default shell ('' when the user never chose one). */
72
- configuredShell(): string;
73
- /**
74
- * Persist one config path. index.ts owns this (it holds the settings-service
75
- * dance for every line, including the <=0.1.6 self-registration retry), and the
76
- * service instance only exists here, so it is passed back in.
77
- */
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;
84
- platform?: NodeJS.Platform;
85
- }
86
-
87
- /** The mount outcome, reported through the routes' `unavailable` field. */
88
- export interface BrowserTerminalMount {
89
- /** 'ok', or why a terminal cannot be offered. */
90
- unavailable(): string;
91
- dispose(): void;
92
- }
93
-
94
- /**
95
- * Mount the browser terminal: routes, socket, registry, catalog cache.
96
- * @returns the disposer and the availability answer the settings page reads.
97
- */
98
- export function mountBrowserTerminals(input: MountInput): BrowserTerminalMount {
99
- const platform = input.platform ?? process.platform;
100
- const config = input.config;
101
- /**
102
- * In-process overrides for the fields this feature writes.
103
- *
104
- * Hosts up to 0.1.6 have no config hot-reload: `settings.mutate` persists the
105
- * value, but the object handed to `apply` never changes, so a switch flipped in
106
- * the settings page would only take effect after a restart. The plugin's legacy
107
- * bridge already solves that for `defaultShell` with a `shellOverride`; this is
108
- * the same mechanism for the activation switches. On 0.1.7+ the `.volatile()` ref
109
- * is already live, the map merely shadows it with the value we just wrote - a
110
- * no-op in the good case, the fix in the old one.
111
- */
112
- const overrides = new Map<string, unknown>();
113
- const readField = <T>(key: string, fallback: T): T => {
114
- if (overrides.has(key)) return overrides.get(key) as T;
115
- return live(config[key] as T | VolatileRef<T> | undefined, fallback);
116
- };
117
- const switches = (): ShellSwitches => ({
118
- // Powershell is not in here: it is the floor and has no switch by design (R2).
119
- gitbash: readField("shellGitBash", true),
120
- msys2: readField("shellMsys2", true),
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),
125
- niu: readField("shellNiu", true),
126
- });
127
- const wslDistro = (): string => readField("wslDistro", "").trim();
128
- /** The master switch: off hides the child switches and refuses allocations. */
129
- const enabled = (): boolean => readField("bottomTerminal", true);
130
- /**
131
- * Opt-in to publishing `webTerminals` for the official bottom row. Off by default and
132
- * deliberately NOT derived from "no controller detected": the client-side check that
133
- * would be needed for that is a boot-time race, and losing it takes down the host's
134
- * own terminal (findings D15-1).
135
- */
136
- const shimOfficialTerminal = (): boolean => readField("shimOfficialTerminal", false);
137
-
138
- // The WSL distro list, probed LAZILY on the first catalog read and re-probed
139
- // after a switch write. `undefined` is "still unknown / the probe timed out",
140
- // which the catalog treats as neutral rather than as evidence of absence.
141
- // Lazy matters: mounting the routes must not spawn `wsl.exe` in a process that
142
- // never opens a terminal (unit mocks, headless hosts, non-WSL machines).
143
- let distros: readonly string[] | undefined;
144
- let probing = false;
145
- const reprobe = (): void => {
146
- probing = true;
147
- void listWslDistros(input.paths.wsl).then((found) => {
148
- distros = found;
149
- probing = false;
150
- catalog.invalidate();
151
- }, () => {
152
- probing = false;
153
- });
154
- };
155
-
156
- const catalog = createCatalogProvider({
157
- paths: () => input.paths,
158
- switches,
159
- wslDistro,
160
- payloadSuppressed: input.payloadSuppressed ?? (() => false),
161
- distros: () => {
162
- if (distros === undefined && !probing) reprobe();
163
- return distros;
164
- },
165
- });
166
-
167
- const backend = detectBackend({ platform, seam: input.ctx.subprocess as never });
168
- const spawner = backend === undefined ? undefined : createUiSpawner({ platform, seam: input.ctx.subprocess as never });
169
- const registry = new UiTerminalRegistry({
170
- maxPerSession: MAX_PER_SESSION,
171
- maxTotal: MAX_TOTAL,
172
- idleGraceMs: IDLE_GRACE_MS,
173
- scrollback: SCROLLBACK_BYTES,
174
- spawn: async (spec) => {
175
- if (spawner === undefined) throw new Error("no PTY backend on this host");
176
- return await spawner.spawn(spec);
177
- },
178
- });
179
-
180
- let unavailable = "not-installed";
181
- let routes: { dispose(): void; socket: string } | undefined;
182
- const isLoopback = (request: { socket?: { remoteAddress?: string } }): boolean => {
183
- const addr = request.socket?.remoteAddress ?? "";
184
- return addr === "127.0.0.1" || addr === "::1" || addr === "::ffff:127.0.0.1";
185
- };
186
- const cwdFor = (sessionId: string): string => {
187
- const sessions = (input.ctx.get?.("sessions") ?? undefined) as SessionsLike | undefined;
188
- return sessions?.get?.(sessionId)?.header?.cwd ?? process.cwd();
189
- };
190
-
191
- // webServer arrives only through injection; until then the routes report their
192
- // absence rather than pretending a terminal is available.
193
- input.ctx.inject?.(["webServer", "settings"], (svcCtx) => {
194
- // Classified the moment the settings service arrives: the browser cannot tell which
195
- // generation it is talking to, and the answer decides whether it paints its own
196
- // floating panel or stays out of the way.
197
- reportSettingsSurface(svcCtx.settings as never);
198
- routes = registerUiTerminalRoutes(svcCtx.webServer as Parameters<typeof registerUiTerminalRoutes>[0], {
199
- catalog: () => catalog.catalog(),
200
- paths: () => input.paths,
201
- env: (id) => catalog.env(id),
202
- enabled,
203
- shimOfficialTerminal,
204
- settingsSurface,
205
- configuredShell: input.configuredShell,
206
- switches,
207
- wslDistro,
208
- writeConfig: async (path, value) => {
209
- await input.persist(svcCtx.settings, path, value);
210
- // Remember it for this process too (the ≤0.1.6 hot-reload gap above).
211
- overrides.set(path.join("."), value);
212
- // A write also forgets the cached catalog and the WSL answer, so the
213
- // settings row never reports a stale result immediately after a click.
214
- distros = undefined;
215
- catalog.invalidate();
216
- },
217
- registry,
218
- cwdFor,
219
- unavailableReason: () => unavailable,
220
- isLoopback,
221
- });
222
- unavailable = backend === undefined ? "no-pty-backend" : routes.socket === "mounted" ? "ok" : routes.socket;
223
- input.ctx.logger?.info?.(`dsh-bash-terminal-ts: browser terminal routes ${unavailable} (backend=${backend ?? "none"}, priority=${SHELL_PRIORITY.join(">")})`);
224
- svcCtx.effect(() => () => {
225
- routes?.dispose();
226
- void registry.dispose();
227
- }, "bash-terminal: browser terminal routes");
228
- });
229
-
230
- return {
231
- unavailable: () => unavailable,
232
- dispose: () => {
233
- routes?.dispose();
234
- void registry.dispose();
235
- },
236
- };
237
- }
1
+ // The wiring seam between the plugin's live config and the browser terminal.
2
+ //
3
+ // It lives in its own module because of one hard ordering fact (findings F1): the
4
+ // host entry this plugin ships returns early on non-Windows platforms, since the
5
+ // *model tool* is Windows-only. The browser terminal is not a Windows-only idea,
6
+ // so its mount has to happen before that return - and keeping it in one call makes
7
+ // that ordering visible at the call site instead of buried in a 1000-line apply().
8
+ //
9
+ // Everything environment-dependent arrives as live reads (config fields are
10
+ // `.volatile()` on the 0.1.7+ lines, and older lines re-read from the same
11
+ // closure), never a snapshot: a switch flipped in the settings page must apply to
12
+ // the next allocation without a restart.
13
+
14
+ import { createCatalogProvider } from "./catalog.js";
15
+ import { listWslDistros } from "./catalog.js";
16
+ import { reportSettingsSurface, settingsSurface } from "../settings-surface.js";
17
+ import { registerUiTerminalRoutes } from "./host.js";
18
+ import { UiTerminalRegistry } from "./registry.js";
19
+ import { createUiSpawner, detectBackend } from "./pty.js";
20
+ import { SHELL_PRIORITY } from "../shells.js";
21
+ import type { ShellSwitches } from "../shells.js";
22
+ import type { ResolvedPaths } from "../dsh-types.js";
23
+
24
+ /** How many terminals one session may hold, and how many exist host-wide. */
25
+ const MAX_PER_SESSION = 6;
26
+ const MAX_TOTAL = 12;
27
+ /** Detached-shell grace: long enough to survive a page reload, short enough to
28
+ * not leak a shell someone abandoned. */
29
+ const IDLE_GRACE_MS = 120_000;
30
+ /** Replayed screen budget per terminal. */
31
+ const SCROLLBACK_BYTES = 200_000;
32
+
33
+ /** A live `.volatile()` reference as the 0.1.7+ loader hands it. */
34
+ interface VolatileRef<T> {
35
+ get(): T;
36
+ }
37
+
38
+ /** Read a config field that may be a value or a live ref. */
39
+ function live<T>(value: T | VolatileRef<T> | undefined, fallback: T): T {
40
+ if (typeof value === "object" && value !== null && typeof (value as VolatileRef<T>).get === "function") {
41
+ const got = (value as VolatileRef<T>).get();
42
+ return got === undefined ? fallback : got;
43
+ }
44
+ return value === undefined ? fallback : (value as T);
45
+ }
46
+
47
+ /** The session lookup for one terminal's cwd. */
48
+ interface SessionsLike {
49
+ get?(id: string): { header?: { cwd?: string } } | undefined;
50
+ }
51
+
52
+ /** The service-arrival context cordis hands the `inject` callback. */
53
+ interface ArrivalContext {
54
+ webServer?: unknown;
55
+ settings?: unknown;
56
+ effect(fn: () => unknown, name?: string): unknown;
57
+ }
58
+
59
+ /** What the caller passes; all of it comes from the plugin's own context. */
60
+ export interface MountInput {
61
+ /** The plugin context, widened: only three reads are used. */
62
+ ctx: {
63
+ subprocess?: { spawnTerminal?: unknown };
64
+ get?(name: string): unknown;
65
+ effect(fn: () => unknown, name?: string): unknown;
66
+ inject?(deps: string[], fn: (svcCtx: ArrivalContext) => void): void;
67
+ logger?: { info?(msg: string): void; warn?(msg: string): void };
68
+ };
69
+ config: Record<string, unknown>;
70
+ paths: ResolvedPaths;
71
+ /** The stored default shell ('' when the user never chose one). */
72
+ configuredShell(): string;
73
+ /**
74
+ * Persist one config path. index.ts owns this (it holds the settings-service
75
+ * dance for every line, including the <=0.1.6 self-registration retry), and the
76
+ * service instance only exists here, so it is passed back in.
77
+ */
78
+ persist(svc: unknown, path: readonly string[], value: unknown): Promise<void>;
79
+ platform?: NodeJS.Platform;
80
+ }
81
+
82
+ /** The mount outcome, reported through the routes' `unavailable` field. */
83
+ export interface BrowserTerminalMount {
84
+ /** 'ok', or why a terminal cannot be offered. */
85
+ unavailable(): string;
86
+ dispose(): void;
87
+ }
88
+
89
+ /**
90
+ * Mount the browser terminal: routes, socket, registry, catalog cache.
91
+ * @returns the disposer and the availability answer the settings page reads.
92
+ */
93
+ export function mountBrowserTerminals(input: MountInput): BrowserTerminalMount {
94
+ const platform = input.platform ?? process.platform;
95
+ const config = input.config;
96
+ /**
97
+ * In-process overrides for the fields this feature writes.
98
+ *
99
+ * Hosts up to 0.1.6 have no config hot-reload: `settings.mutate` persists the
100
+ * value, but the object handed to `apply` never changes, so a switch flipped in
101
+ * the settings page would only take effect after a restart. The plugin's legacy
102
+ * bridge already solves that for `defaultShell` with a `shellOverride`; this is
103
+ * the same mechanism for the activation switches. On 0.1.7+ the `.volatile()` ref
104
+ * is already live, the map merely shadows it with the value we just wrote - a
105
+ * no-op in the good case, the fix in the old one.
106
+ */
107
+ const overrides = new Map<string, unknown>();
108
+ const readField = <T>(key: string, fallback: T): T => {
109
+ if (overrides.has(key)) return overrides.get(key) as T;
110
+ return live(config[key] as T | VolatileRef<T> | undefined, fallback);
111
+ };
112
+ const switches = (): ShellSwitches => ({
113
+ // Powershell is not in here: it is the floor and has no switch by design (R2).
114
+ gitbash: readField("shellGitBash", true),
115
+ msys2: readField("shellMsys2", true),
116
+ wsl: readField("shellWsl", true),
117
+ niu: readField("shellNiu", true),
118
+ });
119
+ const wslDistro = (): string => readField("wslDistro", "").trim();
120
+ /** The master switch: off hides the child switches and refuses allocations. */
121
+ const enabled = (): boolean => readField("bottomTerminal", true);
122
+ /**
123
+ * Opt-in to publishing `webTerminals` for the official bottom row. Off by default and
124
+ * deliberately NOT derived from "no controller detected": the client-side check that
125
+ * would be needed for that is a boot-time race, and losing it takes down the host's
126
+ * own terminal (findings D15-1).
127
+ */
128
+ const shimOfficialTerminal = (): boolean => readField("shimOfficialTerminal", false);
129
+
130
+ // The WSL distro list, probed LAZILY on the first catalog read and re-probed
131
+ // after a switch write. `undefined` is "still unknown / the probe timed out",
132
+ // which the catalog treats as neutral rather than as evidence of absence.
133
+ // Lazy matters: mounting the routes must not spawn `wsl.exe` in a process that
134
+ // never opens a terminal (unit mocks, headless hosts, non-WSL machines).
135
+ let distros: readonly string[] | undefined;
136
+ let probing = false;
137
+ const reprobe = (): void => {
138
+ probing = true;
139
+ void listWslDistros(input.paths.wsl).then((found) => {
140
+ distros = found;
141
+ probing = false;
142
+ catalog.invalidate();
143
+ }, () => {
144
+ probing = false;
145
+ });
146
+ };
147
+
148
+ const catalog = createCatalogProvider({
149
+ paths: () => input.paths,
150
+ switches,
151
+ wslDistro,
152
+ distros: () => {
153
+ if (distros === undefined && !probing) reprobe();
154
+ return distros;
155
+ },
156
+ });
157
+
158
+ const backend = detectBackend({ platform, seam: input.ctx.subprocess as never });
159
+ const spawner = backend === undefined ? undefined : createUiSpawner({ platform, seam: input.ctx.subprocess as never });
160
+ const registry = new UiTerminalRegistry({
161
+ maxPerSession: MAX_PER_SESSION,
162
+ maxTotal: MAX_TOTAL,
163
+ idleGraceMs: IDLE_GRACE_MS,
164
+ scrollback: SCROLLBACK_BYTES,
165
+ spawn: async (spec) => {
166
+ if (spawner === undefined) throw new Error("no PTY backend on this host");
167
+ return await spawner.spawn(spec);
168
+ },
169
+ });
170
+
171
+ let unavailable = "not-installed";
172
+ let routes: { dispose(): void; socket: string } | undefined;
173
+ const isLoopback = (request: { socket?: { remoteAddress?: string } }): boolean => {
174
+ const addr = request.socket?.remoteAddress ?? "";
175
+ return addr === "127.0.0.1" || addr === "::1" || addr === "::ffff:127.0.0.1";
176
+ };
177
+ const cwdFor = (sessionId: string): string => {
178
+ const sessions = (input.ctx.get?.("sessions") ?? undefined) as SessionsLike | undefined;
179
+ return sessions?.get?.(sessionId)?.header?.cwd ?? process.cwd();
180
+ };
181
+
182
+ // webServer arrives only through injection; until then the routes report their
183
+ // absence rather than pretending a terminal is available.
184
+ input.ctx.inject?.(["webServer", "settings"], (svcCtx) => {
185
+ // Classified the moment the settings service arrives: the browser cannot tell which
186
+ // generation it is talking to, and the answer decides whether it paints its own
187
+ // floating panel or stays out of the way.
188
+ reportSettingsSurface(svcCtx.settings as never);
189
+ routes = registerUiTerminalRoutes(svcCtx.webServer as Parameters<typeof registerUiTerminalRoutes>[0], {
190
+ catalog: () => catalog.catalog(),
191
+ paths: () => input.paths,
192
+ env: (id) => catalog.env(id),
193
+ enabled,
194
+ shimOfficialTerminal,
195
+ settingsSurface,
196
+ configuredShell: input.configuredShell,
197
+ switches,
198
+ wslDistro,
199
+ writeConfig: async (path, value) => {
200
+ await input.persist(svcCtx.settings, path, value);
201
+ // Remember it for this process too (the ≤0.1.6 hot-reload gap above).
202
+ overrides.set(path.join("."), value);
203
+ // A write also forgets the cached catalog and the WSL answer, so the
204
+ // settings row never reports a stale result immediately after a click.
205
+ distros = undefined;
206
+ catalog.invalidate();
207
+ },
208
+ registry,
209
+ cwdFor,
210
+ unavailableReason: () => unavailable,
211
+ isLoopback,
212
+ });
213
+ unavailable = backend === undefined ? "no-pty-backend" : routes.socket === "mounted" ? "ok" : routes.socket;
214
+ input.ctx.logger?.info?.(`dsh-bash-terminal-ts: browser terminal routes ${unavailable} (backend=${backend ?? "none"}, priority=${SHELL_PRIORITY.join(">")})`);
215
+ svcCtx.effect(() => () => {
216
+ routes?.dispose();
217
+ void registry.dispose();
218
+ }, "bash-terminal: browser terminal routes");
219
+ });
220
+
221
+ return {
222
+ unavailable: () => unavailable,
223
+ dispose: () => {
224
+ routes?.dispose();
225
+ void registry.dispose();
226
+ },
227
+ };
228
+ }
@@ -1,97 +0,0 @@
1
- // scripts/payload-alias.mjs - the payload's entry in the HOST's right-sidebar
2
- // terminal menu, shared by link-shells.mjs and provision-payload.mjs.
3
- //
4
- // Why a hard link with its own name (same rule as git-bash.exe / msys-bash.exe):
5
- // `discoverShells` keys its Map by the executable FILE NAME and keeps the
6
- // earliest entry. The payload's binary is `bash.exe` - the same key the stock
7
- // list spends on `C:\Windows\System32\bash.exe`, the WSL forwarder. A link
8
- // inside the payload's own `bin\` named `bash-terminal.exe` (a) cannot collide
9
- // with the WSL `bash` row, (b) is only ever present after an operator
10
- // provisioned AND digest-verified a payload, and (c) keeps bash's POSIX-root
11
- // derivation intact because it sits next to the original in the same tree.
12
- //
13
- // Why a junction (`payloads\bash-terminal` -> `payloads\posix-<ver>`): the
14
- // bundle patch's candidate path must be a STABLE string - the version dir
15
- // changes with every re-provision, the junction does not. Directory junctions
16
- // need no privilege and may cross volumes, so the store layout is:
17
- //
18
- // %LOCALAPPDATA%\dsh-bash-terminal-ts\payloads\
19
- // posix-5.2.37(1)\ <- the verified root (provision writes here)
20
- // bin\bash.exe <- upstream binary
21
- // bin\bash-terminal.exe <- hard link, the menu's own name
22
- // bash-terminal\ (junction) <- stable path the patch points at
23
- //
24
- // The patch candidate is built with `!!js` from LOCALAPPDATA; a machine with no
25
- // provisioned payload simply has no file at that path and discoverShells skips
26
- // it per-candidate, exactly like a missing git-bash.exe link.
27
- import { existsSync, linkSync, mkdirSync, readdirSync, statSync } from "node:fs";
28
- import { join } from "node:path";
29
- import { spawnSync } from "node:child_process";
30
-
31
- /** The store layout for one env; pure, so tests can fake LOCALAPPDATA. */
32
- export function payloadAliasPaths(env) {
33
- const local = (env.LOCALAPPDATA ?? "").trim();
34
- if (local.length === 0) return undefined;
35
- const store = join(local, "dsh-bash-terminal-ts", "payloads");
36
- return {
37
- store,
38
- junction: join(store, "bash-terminal"),
39
- /** The stable candidate the bundle patch points at (junction + link name). */
40
- candidate: join(store, "bash-terminal", "bin", "bash-terminal.exe"),
41
- };
42
- }
43
-
44
- /** The newest provisioned root under the store (`posix-*` with bin/bash.exe). */
45
- export function findPayloadStoreRoot(store, readdir = readdirSync, exists = existsSync) {
46
- try {
47
- return readdir(store)
48
- .filter((name) => name.startsWith("posix-"))
49
- .filter((name) => exists(join(store, name, "bin", "bash.exe")))
50
- .sort()
51
- .pop();
52
- } catch {
53
- return undefined;
54
- }
55
- }
56
-
57
- /**
58
- * Create (idempotently) the hard link inside the root and the junction.
59
- * @param {{root: string, junction: string}} target root = a verified payload dir.
60
- * @returns {{link: string, junction: string, created: string[] , skipped?: string}}
61
- */
62
- export function ensurePayloadAlias(target, log = console.log) {
63
- const created = [];
64
- const source = join(target.root, "bin", "bash.exe");
65
- const link = join(target.root, "bin", "bash-terminal.exe");
66
- if (!existsSync(source)) {
67
- return { link, junction: target.junction, created, skipped: `no bin/bash.exe under ${target.root}` };
68
- }
69
- if (existsSync(link)) {
70
- const a = statSync(source);
71
- const b = statSync(link);
72
- if (a.ino !== b.ino || a.dev !== b.dev) {
73
- return { link, junction: target.junction, created, skipped: `${link} exists but is NOT a hard link of bash.exe` };
74
- }
75
- } else {
76
- linkSync(source, link);
77
- created.push(link);
78
- log(`created ${link}`);
79
- }
80
- // Junction: mklink /J via cmd (no privilege needed; works cross-volume).
81
- if (existsSync(target.junction)) {
82
- // A junction reads as a directory through existsSync; trust it if the
83
- // candidate resolves through it.
84
- if (existsSync(link.replace(target.root, join(target.junction, ""))) || existsSync(join(target.junction, "bin", "bash-terminal.exe"))) {
85
- return { link, junction: target.junction, created };
86
- }
87
- return { link, junction: target.junction, created, skipped: `${target.junction} exists but does not reach the payload bin` };
88
- }
89
- mkdirSync(target.store ?? join(target.junction, ".."), { recursive: true });
90
- const r = spawnSync("cmd", ["/c", "mklink", "/J", target.junction, target.root], { windowsHide: true, encoding: "utf8" });
91
- if (r.status !== 0) {
92
- return { link, junction: target.junction, created, skipped: `mklink /J failed (exit ${r.status}): ${(r.stderr ?? "").trim()}` };
93
- }
94
- created.push(target.junction);
95
- log(`created junction ${target.junction} -> ${target.root}`);
96
- return { link, junction: target.junction, created };
97
- }