dsh-bash-terminal-ts 0.8.7 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.de.md +152 -0
- package/CHANGELOG.es.md +152 -0
- package/CHANGELOG.fr.md +152 -0
- package/CHANGELOG.it.md +152 -0
- package/CHANGELOG.md +201 -0
- package/CHANGELOG.ru.md +152 -0
- package/README.de.md +1 -1
- package/README.en.md +3 -2
- package/README.es.md +1 -1
- package/README.it.md +1 -1
- package/README.md +4 -3
- package/agent-presets/README.md +171 -170
- package/agent-presets/install-presets.mjs +180 -179
- package/agent-presets/standard-win-niu/agent.cordis.yml +271 -0
- package/agent-presets/standard-win-niu/preset.yml +2 -0
- package/cordis.patch.yml +84 -83
- package/dist/client.core.js +10 -1
- package/dist/client.js +10 -1
- package/docs/dsh-plugin-development.md +169 -0
- package/docs/niu-backend.md +197 -0
- package/dsh.plugin.json +22 -22
- package/lib/client.js +10 -1
- package/lib/dsh-types.d.ts +14 -2
- package/lib/index.d.ts +15 -2
- package/lib/index.js +43 -5
- package/lib/locales.js +9 -0
- package/lib/shell-id.d.ts +1 -1
- package/lib/shells.d.ts +1 -0
- package/lib/shells.js +8 -2
- package/lib/terminal.js +4 -0
- package/lib/webterminals/host.js +2 -2
- package/lib/webterminals/mount.js +1 -0
- package/locale/de.json +6 -4
- package/locale/en.json +6 -4
- package/locale/es.json +6 -4
- package/locale/fr.json +6 -4
- package/locale/it.json +6 -4
- package/locale/ja.json +6 -4
- package/locale/ko.json +6 -4
- package/locale/ru.json +6 -4
- package/locale/zh.json +6 -4
- package/package.json +25 -11
- package/scripts/check-artifacts.mjs +96 -93
- package/src/client.tsx +685 -685
- package/src/dsh-types.ts +332 -320
- package/src/index.ts +1316 -1275
- package/src/locales.ts +461 -452
- package/src/shell-id.ts +11 -11
- package/src/shells.ts +279 -272
- package/src/terminal.ts +616 -612
- package/src/webterminals/host.ts +361 -361
- package/src/webterminals/mount.ts +237 -236
|
@@ -1,236 +1,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
|
-
/**
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
//
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
//
|
|
142
|
-
|
|
143
|
-
let
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
let
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
//
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
//
|
|
195
|
-
//
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
//
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
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
|
+
}
|