dsh-bash-terminal-ts 0.7.2-compat.2 → 0.8.1

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 (86) hide show
  1. package/README.de.md +3 -2
  2. package/README.en.md +102 -3
  3. package/README.es.md +3 -2
  4. package/README.fr.md +3 -2
  5. package/README.it.md +3 -2
  6. package/README.md +198 -4
  7. package/README.ru.md +3 -2
  8. package/cordis.patch.yml +66 -0
  9. package/dist/client.core.js +7888 -79
  10. package/dist/client.js +7888 -79
  11. package/dsh.plugin.json +22 -22
  12. package/lib/browser-i18n.d.ts +4 -0
  13. package/lib/browser-i18n.js +23 -0
  14. package/lib/client.js +7888 -79
  15. package/lib/dsh-types.d.ts +10 -0
  16. package/lib/dsh.d.ts +2 -0
  17. package/lib/index.d.ts +43 -0
  18. package/lib/index.js +176 -91
  19. package/lib/locales.d.ts +4 -0
  20. package/lib/locales.js +422 -0
  21. package/lib/settings-surface.d.ts +20 -0
  22. package/lib/settings-surface.js +49 -0
  23. package/lib/shell-id.d.ts +2 -0
  24. package/lib/shell-id.js +9 -0
  25. package/lib/shells.d.ts +114 -0
  26. package/lib/shells.js +187 -0
  27. package/lib/terminal.d.ts +30 -1
  28. package/lib/terminal.js +18 -5
  29. package/lib/webterminals/catalog.d.ts +36 -0
  30. package/lib/webterminals/catalog.js +93 -0
  31. package/lib/webterminals/host.d.ts +67 -0
  32. package/lib/webterminals/host.js +278 -0
  33. package/lib/webterminals/mount.d.ts +46 -0
  34. package/lib/webterminals/mount.js +171 -0
  35. package/lib/webterminals/protocol.d.ts +94 -0
  36. package/lib/webterminals/protocol.js +9 -0
  37. package/lib/webterminals/pty.d.ts +42 -0
  38. package/lib/webterminals/pty.js +64 -0
  39. package/lib/webterminals/registry.d.ts +139 -0
  40. package/lib/webterminals/registry.js +353 -0
  41. package/lib/webterminals/ws.d.ts +54 -0
  42. package/lib/webterminals/ws.js +140 -0
  43. package/locale/de.json +4 -0
  44. package/locale/en.json +4 -0
  45. package/locale/es.json +4 -0
  46. package/locale/fr.json +4 -0
  47. package/locale/it.json +4 -0
  48. package/locale/ja.json +4 -0
  49. package/locale/ko.json +4 -0
  50. package/locale/ru.json +4 -0
  51. package/locale/zh.json +4 -0
  52. package/package.json +131 -121
  53. package/scripts/build-browser-tests.mjs +36 -0
  54. package/scripts/build-client.mjs +10 -0
  55. package/scripts/check-artifacts.mjs +93 -0
  56. package/scripts/link-shells.mjs +75 -0
  57. package/src/browser-i18n.ts +27 -0
  58. package/src/client.tsx +539 -134
  59. package/src/dsh-types.ts +6 -0
  60. package/src/dsh.ts +2 -0
  61. package/src/index.ts +146 -35
  62. package/src/locales.ts +434 -0
  63. package/src/settings-surface.ts +59 -0
  64. package/src/shell-id.ts +11 -0
  65. package/src/shells.ts +250 -0
  66. package/src/terminal.ts +34 -5
  67. package/src/webterminals/browser/api.ts +212 -0
  68. package/src/webterminals/browser/bridge.ts +188 -0
  69. package/src/webterminals/browser/css.d.ts +16 -0
  70. package/src/webterminals/browser/face.ts +151 -0
  71. package/src/webterminals/browser/shell-picker.tsx +98 -0
  72. package/src/webterminals/browser/store.ts +40 -0
  73. package/src/webterminals/browser/tab.tsx +136 -0
  74. package/src/webterminals/browser/testkit.ts +21 -0
  75. package/src/webterminals/browser/url.ts +70 -0
  76. package/src/webterminals/browser/view.ts +381 -0
  77. package/src/webterminals/browser/xterm.ts +269 -0
  78. package/src/webterminals/catalog.ts +114 -0
  79. package/src/webterminals/host.ts +361 -0
  80. package/src/webterminals/mount.ts +227 -0
  81. package/src/webterminals/protocol.ts +78 -0
  82. package/src/webterminals/pty.ts +90 -0
  83. package/src/webterminals/registry.ts +447 -0
  84. package/src/webterminals/ws.ts +166 -0
  85. package/tsconfig.client.json +9 -1
  86. package/tsconfig.json +1 -1
package/lib/shells.js ADDED
@@ -0,0 +1,187 @@
1
+ // dsh-bash-terminal-ts: the shell catalog for the browser-side terminal.
2
+ //
3
+ // Why this file exists separately from `buildArgv` / `terminalArgv` / `buildEnv`
4
+ // in index.ts and terminal.ts: those three serve the MODEL tool, where a dumb
5
+ // terminal and a stripped environment are correct (no colour, no pager, one
6
+ // command per call). The browser terminal is the opposite contract - a real
7
+ // xterm emulator driven by a human who expects their profile, their prompt and
8
+ // their colours. Sharing the tool's argv/env would hand the user a shell with
9
+ // `TERM=dumb`, `NO_COLOR=1` and `-NoProfile`.
10
+ //
11
+ // So this module owns the UI-facing rules and REUSES the parts that are
12
+ // genuinely shared: the executable candidate lists (injected by index.ts, which
13
+ // keeps the dependency one-way and this file unit-testable), the MSYS2 `MSYSTEM`
14
+ // rule, and the WSL interactive argv shape.
15
+ //
16
+ // Everything here is pure: no fs, no child_process, no module-level cache. The
17
+ // caller injects `fsProbe` / `distros` and owns the TTL.
18
+ /** Catalog order = fallback order: powershell is BOTH first choice and floor. */
19
+ export const SHELL_PRIORITY = ["powershell", "gitbash", "msys2", "wsl"];
20
+ /** Display labels. The catalog id/label pair is DECIDED BY THIS TABLE. */
21
+ const LABELS = {
22
+ powershell: "PowerShell",
23
+ gitbash: "Git Bash",
24
+ msys2: "MSYS2",
25
+ wsl: "WSL bash",
26
+ };
27
+ /**
28
+ * `<SystemRoot>\System32\bash.exe` (and the sysnative mirror) is the deprecated
29
+ * WSL forwarder, not a shell. `candidateGitBashPaths` already skips it; this
30
+ * guard protects the second way a path reaches the catalog - a user-supplied
31
+ * `gitBashPath` / `msys2Path` config value.
32
+ */
33
+ export function isWslLegacyBash(path) {
34
+ const stem = /([^\\/]+)\.exe$/i.exec(path)?.[1]?.toLowerCase();
35
+ if (stem !== "bash")
36
+ return false;
37
+ return /\\(windows\\system32|sysnative)\\bash\.exe$/i.test(path.replace(/\//g, "\\"));
38
+ }
39
+ /**
40
+ * Console-allocating launchers: `git-bash.exe`, `msys2.exe`, `msys2_shell.cmd`.
41
+ * They open their own window and return zero bytes on a piped stdio (measured
42
+ * against MSYS2 with bash 5.3.15), so they can never host an embedded terminal.
43
+ */
44
+ export function isConsoleLauncher(path) {
45
+ const name = path.slice(Math.max(path.lastIndexOf("/"), path.lastIndexOf("\\")) + 1).toLowerCase();
46
+ return name === "git-bash.exe" || name === "msys2.exe" || name === "msys2_shell.cmd";
47
+ }
48
+ /**
49
+ * Interactive argv for the BROWSER terminal.
50
+ *
51
+ * Differences from the tool's `terminalArgv`: PowerShell keeps its profile (the
52
+ * user's aliases and prompt are the point of a UI terminal), and the three bash
53
+ * families are unchanged because those rules are about the shell itself:
54
+ * Git Bash needs `-i`, MSYS2 needs `-l` and NEVER `-lc` (this argv carries no
55
+ * command, and `bash -lc` with no operand exits 2), WSL needs `-- bash -i` on the
56
+ * default distro (bare `-e` fails under ConPTY with RPC 0x8007072c).
57
+ */
58
+ export function uiArgv(shell, paths, wslDistro = "") {
59
+ switch (shell) {
60
+ case "powershell":
61
+ return [requirePath(paths.pwsh, shell), "-NoLogo"];
62
+ case "gitbash":
63
+ return [requirePath(paths.gitbash, shell), "-i"];
64
+ case "msys2":
65
+ return [requirePath(paths.msys2, shell), "-l"];
66
+ case "wsl": {
67
+ const distro = wslDistro.trim();
68
+ return distro.length > 0
69
+ ? [requirePath(paths.wsl, shell), "-d", distro, "-e", "bash", "-i"]
70
+ : [requirePath(paths.wsl, shell), "--", "bash", "-i"];
71
+ }
72
+ }
73
+ }
74
+ /**
75
+ * Environment for the BROWSER terminal: the host process environment plus a real
76
+ * terminal type. `buildEnv` is deliberately NOT reused - it layers
77
+ * `TERM=dumb`/`NO_COLOR=1`/`PAGER=cat` over an agent-scoped map, which is right
78
+ * for a one-shot tool call and wrong for an interactive screen.
79
+ *
80
+ * The one rule carried over is MSYS2's `MSYSTEM`: without it MSYS2 starts in the
81
+ * bare MSYS environment and `/etc/profile` never puts `/mingw64/bin` on PATH, so
82
+ * gcc/make are missing in the very shell the user chose to get them from. An
83
+ * explicit value in the base environment wins, exactly as in `buildEnv`.
84
+ */
85
+ export function uiEnv(shell, baseEnv) {
86
+ const env = { ...baseEnv };
87
+ // A UI terminal is an xterm: the tool's `dumb` would kill colours, cursor
88
+ // control and full-screen programs.
89
+ env.TERM = "xterm-256color";
90
+ if (shell === "msys2" && env.MSYSTEM === undefined)
91
+ env.MSYSTEM = "MINGW64";
92
+ return env;
93
+ }
94
+ function requirePath(path, shell) {
95
+ if (path === undefined || path.length === 0) {
96
+ throw new Error(`terminal: ${shell} backend unavailable - no executable resolved`);
97
+ }
98
+ return path;
99
+ }
100
+ /** One row's availability, given the injected facts. */
101
+ function probe(id, facts) {
102
+ const path = id === "powershell" ? facts.paths.pwsh : id === "gitbash" ? facts.paths.gitbash : id === "msys2" ? facts.paths.msys2 : facts.paths.wsl;
103
+ if (path === undefined || path.length === 0)
104
+ return { available: false, reason: "not-installed" };
105
+ // A configured path is honoured, but a launcher is not a shell: trusting the
106
+ // config here is how `msys2.exe` ends up in the menu and returns no output.
107
+ if (isConsoleLauncher(path))
108
+ return { available: false, reason: "launcher-only", path };
109
+ if (isWslLegacyBash(path))
110
+ return { available: false, reason: "launcher-only", path };
111
+ if (!facts.fsProbe(path))
112
+ return { available: false, reason: "not-installed", path };
113
+ if (id === "wsl" && facts.distros !== undefined && facts.distros.length === 0)
114
+ return { available: false, reason: "no-distro", path };
115
+ return { available: true, reason: "installed", path };
116
+ }
117
+ /**
118
+ * The catalog the settings page and the spawn path both read.
119
+ *
120
+ * `powershell` is never `activated: false` even if a switch said so: it is the
121
+ * floor of the fallback chain (R2/R6), and a floor that can be removed is not a
122
+ * floor. The caller sees that through `togglable: false`.
123
+ */
124
+ export function buildCatalog(facts) {
125
+ return SHELL_PRIORITY.map((id) => {
126
+ const probed = probe(id, facts);
127
+ const activated = id === "powershell" ? true : probed.available && facts.switches[id] === true;
128
+ const argv = activated && probed.available ? uiArgv(id, facts.paths, facts.wslDistro) : undefined;
129
+ return {
130
+ id,
131
+ label: LABELS[id],
132
+ ...(probed.path !== undefined ? { path: probed.path } : {}),
133
+ available: probed.available,
134
+ reason: probed.reason,
135
+ activated,
136
+ // Only powershell is un-togglable, and that is the floor rule above.
137
+ togglable: id !== "powershell",
138
+ ...(argv !== undefined ? { argv } : {}),
139
+ };
140
+ });
141
+ }
142
+ /**
143
+ * Decide the shell for one allocation (R4/R5/R6).
144
+ *
145
+ * Three distinct outcomes, because the UI has to say different things about them:
146
+ * - `""` means the user never chose: take the first candidate, no notice;
147
+ * - a non-empty value outside the candidates means the choice went stale (a
148
+ * switch was turned off, or a shell was uninstalled): fall back AND report
149
+ * `fellBack` with the original value;
150
+ * - no candidate at all: the floor is PowerShell's own chain (pwsh 7 -> Windows
151
+ * PowerShell), and `cmd.exe` is the last resort when even that is gone.
152
+ *
153
+ * The stored config is never rewritten here - a fallback that persists would
154
+ * silently eat the user's choice.
155
+ */
156
+ export function resolveDefaultShell(catalog, configured, paths) {
157
+ const usable = SHELL_PRIORITY
158
+ .map((id) => catalog.find((entry) => entry.id === id))
159
+ .filter((entry) => entry !== undefined && entry.activated && entry.available && entry.path !== undefined);
160
+ const wanted = configured.trim();
161
+ const chosen = wanted.length === 0 ? undefined : usable.find((entry) => entry.id === wanted);
162
+ const picked = chosen ?? usable[0];
163
+ if (picked !== undefined) {
164
+ return {
165
+ id: picked.id,
166
+ path: picked.path,
167
+ argv: picked.argv ?? uiArgv(picked.id, paths),
168
+ fellBack: chosen === undefined && wanted.length > 0,
169
+ floor: false,
170
+ ...(chosen === undefined && wanted.length > 0 ? { from: wanted } : {}),
171
+ };
172
+ }
173
+ // Nothing activated: the floor. `paths.pwsh` is already the candidate-list
174
+ // winner (pwsh 7 -> PATH pwsh -> Windows PowerShell 5.1), so the only step
175
+ // below it is cmd.exe, which exists on every Windows host and is enough to
176
+ // type in.
177
+ const floorPath = paths.pwsh ?? "C:\\Windows\\System32\\cmd.exe";
178
+ const isCmd = /\cmd\.exe$/i.test(floorPath);
179
+ return {
180
+ id: isCmd ? "cmd" : "powershell",
181
+ path: floorPath,
182
+ argv: isCmd ? [floorPath] : [floorPath, "-NoLogo"],
183
+ fellBack: wanted.length > 0,
184
+ floor: true,
185
+ ...(wanted.length > 0 ? { from: wanted } : {}),
186
+ };
187
+ }
package/lib/terminal.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { BashTerminalContext, ResolvedPaths, TerminalHandle } from "./dsh-types.js";
1
+ import type { BashTerminalContext, ResolvedPaths, TerminalHandle, TerminalSpawnSpec } from "./dsh-types.js";
2
2
  declare const TERMINAL_SIGNALS: readonly ["SIGINT", "SIGTERM", "SIGKILL", "SIGTSTP", "SIGHUP"];
3
3
  export type TerminalSignal = (typeof TERMINAL_SIGNALS)[number];
4
4
  interface TerminalBufferRead {
@@ -15,6 +15,35 @@ interface TerminalBuffer {
15
15
  }
16
16
  /** Interactive-shell argv (no -c: the terminal itself is the session). */
17
17
  export declare function terminalArgv(shell: string, paths: ResolvedPaths, distro?: string): Array<string | undefined>;
18
+ /** Terminal-emulator options for one PTY allocation. */
19
+ export interface PtyStyle {
20
+ /** The terminal type the PTY advertises (and the one `$TERM` should say). */
21
+ readonly name: string;
22
+ /**
23
+ * Variables forced into the child environment. The model tool pins
24
+ * `TERM=dumb`/`NO_COLOR=1` so output stays parseable; the browser terminal
25
+ * passes `{}` because its whole point is a coloured, cursor-controlled screen.
26
+ */
27
+ readonly forceEnv: Readonly<Record<string, string | undefined>>;
28
+ }
29
+ /** The tool's own style: a dumb, colourless, pager-free screen. */
30
+ export declare const TOOL_PTY_STYLE: PtyStyle;
31
+ /** The browser terminal's style: a real xterm, colours and cursor control on. */
32
+ export declare const UI_PTY_STYLE: PtyStyle;
33
+ /**
34
+ * Direct node-pty handle with the same surface the official seam returns:
35
+ * output (stream), pid, done, write / signalForeground / terminate, plus
36
+ * `resize` (which the seam only grew on newer host lines, so callers probe).
37
+ * Used on win32, where the official `spawnTerminal`'s process inspector is
38
+ * unsupported.
39
+ *
40
+ * `style` is a parameter rather than a constant because the ConPTY quirks below
41
+ * are shared by both consumers: a second copy of this function is how the
42
+ * browser terminal would end up with the tool's `TERM=dumb`.
43
+ */
44
+ export declare function spawnPtyHandle(spec: TerminalSpawnSpec, style?: PtyStyle): Promise<TerminalHandle & {
45
+ resize(cols: number, rows: number): void;
46
+ }>;
18
47
  export interface TerminalSessionInfo {
19
48
  sessionId: string;
20
49
  shell: string;
package/lib/terminal.js CHANGED
@@ -108,21 +108,31 @@ async function waitForPid(term, timeoutMs = 5000) {
108
108
  throw new Error("terminal: node-pty did not report a process id within " + timeoutMs + "ms (ConPTY agent did not connect)");
109
109
  }
110
110
  }
111
+ /** The tool's own style: a dumb, colourless, pager-free screen. */
112
+ export const TOOL_PTY_STYLE = { name: "dumb", forceEnv: { TERM: "dumb", NO_COLOR: "1" } };
113
+ /** The browser terminal's style: a real xterm, colours and cursor control on. */
114
+ export const UI_PTY_STYLE = { name: "xterm-256color", forceEnv: {} };
111
115
  /**
112
116
  * Direct node-pty handle with the same surface the official seam returns:
113
- * output (stream), pid, done, write / signalForeground / terminate. Used on
114
- * win32 where the official spawnTerminal's process inspector is unsupported.
117
+ * output (stream), pid, done, write / signalForeground / terminate, plus
118
+ * `resize` (which the seam only grew on newer host lines, so callers probe).
119
+ * Used on win32, where the official `spawnTerminal`'s process inspector is
120
+ * unsupported.
121
+ *
122
+ * `style` is a parameter rather than a constant because the ConPTY quirks below
123
+ * are shared by both consumers: a second copy of this function is how the
124
+ * browser terminal would end up with the tool's `TERM=dumb`.
115
125
  */
116
- async function spawnPtyHandle(spec) {
126
+ export async function spawnPtyHandle(spec, style = TOOL_PTY_STYLE) {
117
127
  const { argv, cwd, env, rows, cols } = spec;
118
128
  const mod = (await import("node-pty"));
119
129
  const nodePty = mod.default ?? mod;
120
130
  const term = nodePty.spawn(argv[0], argv.slice(1), {
121
- name: "dumb",
131
+ name: style.name,
122
132
  cols,
123
133
  rows,
124
134
  cwd,
125
- env: { ...env, TERM: "dumb", NO_COLOR: "1" }
135
+ env: { ...env, ...style.forceEnv },
126
136
  });
127
137
  await waitForPid(term);
128
138
  const output = new PassThrough();
@@ -135,6 +145,9 @@ async function spawnPtyHandle(spec) {
135
145
  output,
136
146
  done,
137
147
  write: (data) => term.write(data),
148
+ // ConPTY honours a real resize; the tool path never calls it, so this is the
149
+ // one seam capability the browser terminal adds on top of the same handle.
150
+ resize: (nextCols, nextRows) => term.resize(nextCols, nextRows),
138
151
  // node-pty accepts no named signals on Windows: Ctrl+C is the \x03 byte
139
152
  // (ConPTY delivers it to the foreground process), other signals degrade
140
153
  // to terminating the session.
@@ -0,0 +1,36 @@
1
+ import type { ShellEntry, ShellSwitches } from "../shells.js";
2
+ import type { ResolvedPaths } from "../dsh-types.js";
3
+ /** How long one catalog answer is trusted. */
4
+ export declare const CATALOG_TTL_MS = 5000;
5
+ /** Is this path a launchable file? */
6
+ export declare function fsProbe(path: string): boolean;
7
+ /**
8
+ * The installed WSL distributions (quiet listing, one per line).
9
+ * @returns [] when wsl.exe is absent; undefined when the probe could not answer
10
+ * (a timeout is NOT "no distro" - reporting it as such would disable a working
11
+ * backend, which is the all-false-positive trap).
12
+ */
13
+ export declare function listWslDistros(wslPath: string | undefined, timeoutMs?: number): Promise<readonly string[] | undefined>;
14
+ /** What the provider reads from the plugin's live config. */
15
+ export interface CatalogSource {
16
+ paths(): ResolvedPaths;
17
+ switches(): ShellSwitches;
18
+ wslDistro(): string;
19
+ /** Cached distro list; undefined means "unknown", [] means "none installed". */
20
+ distros(): readonly string[] | undefined;
21
+ }
22
+ /** The catalog with its TTL, as the routes consume it. */
23
+ export interface CatalogProvider {
24
+ /** The current rows (re-probed when the cache aged out). */
25
+ catalog(): ShellEntry[];
26
+ /** Forget the cached answer (call after any switch/path config write). */
27
+ invalidate(): void;
28
+ /** The UI environment for one backend (process.env plus its own rules). */
29
+ env(id: ShellEntry["id"]): Record<string, string | undefined>;
30
+ }
31
+ /**
32
+ * Build the TTL-backed provider.
33
+ * @param source - live config reads (never a snapshot: settings hot-reload).
34
+ * @param now - injectable clock for specs.
35
+ */
36
+ export declare function createCatalogProvider(source: CatalogSource, now?: () => number): CatalogProvider;
@@ -0,0 +1,93 @@
1
+ // The host-side catalog provider: the filesystem and WSL probes, and the short
2
+ // cache the routes read through.
3
+ //
4
+ // Two decisions worth their comments:
5
+ //
6
+ // - **The cache lives here, not inside `buildCatalog`.** The catalog builder is a
7
+ // pure function so it can be table-tested without a filesystem; discovery hits
8
+ // disk and spawns `wsl.exe`, so the caller owns the TTL and invalidates it after
9
+ // a switch is written (a settings row that reports a stale answer right after
10
+ // the user changed it is worse than a slow one).
11
+ // - **`wsl -l -q` gets a hard timeout.** A WSL service that is starting up can sit
12
+ // on that call for tens of seconds; the settings page must render meanwhile, so
13
+ // an unreachable WSL reports "unknown" rather than blocking the row.
14
+ import { statSync } from "node:fs";
15
+ import { execFile } from "node:child_process";
16
+ import { buildCatalog, uiEnv } from "../shells.js";
17
+ /** How long one catalog answer is trusted. */
18
+ export const CATALOG_TTL_MS = 5000;
19
+ /** Is this path a launchable file? */
20
+ export function fsProbe(path) {
21
+ try {
22
+ return statSync(path).isFile();
23
+ }
24
+ catch {
25
+ return false;
26
+ }
27
+ }
28
+ /**
29
+ * The installed WSL distributions (quiet listing, one per line).
30
+ * @returns [] when wsl.exe is absent; undefined when the probe could not answer
31
+ * (a timeout is NOT "no distro" - reporting it as such would disable a working
32
+ * backend, which is the all-false-positive trap).
33
+ */
34
+ export function listWslDistros(wslPath, timeoutMs = 1500) {
35
+ if (wslPath === undefined)
36
+ return Promise.resolve([]);
37
+ return new Promise((resolve) => {
38
+ let settled = false;
39
+ const child = execFile(wslPath, ["-l", "-q"], { windowsHide: true, timeout: timeoutMs, encoding: "utf8" }, (error, stdout) => {
40
+ if (settled)
41
+ return;
42
+ settled = true;
43
+ if (error !== null && error.signal !== undefined) {
44
+ resolve(undefined);
45
+ return;
46
+ }
47
+ // A non-zero exit with text output still means "reachable"; `wsl -l -q`
48
+ // exits 1 on a machine with no distro installed, which is a real answer.
49
+ const distros = String(stdout ?? "")
50
+ .split(/\r?\n/)
51
+ .map((line) => line.trim())
52
+ .filter((line) => line.length > 0 && !/^<.+>$/i.test(line));
53
+ resolve(distros);
54
+ });
55
+ child.on("error", () => {
56
+ if (settled)
57
+ return;
58
+ settled = true;
59
+ resolve(undefined);
60
+ });
61
+ });
62
+ }
63
+ /**
64
+ * Build the TTL-backed provider.
65
+ * @param source - live config reads (never a snapshot: settings hot-reload).
66
+ * @param now - injectable clock for specs.
67
+ */
68
+ export function createCatalogProvider(source, now = Date.now) {
69
+ let cache;
70
+ const facts = () => ({
71
+ paths: source.paths(),
72
+ fsProbe,
73
+ // Passed through as-is: `undefined` is "the probe could not answer", which the
74
+ // catalog treats as neutral (available), while `[]` is the real "no distro".
75
+ distros: source.distros(),
76
+ switches: source.switches(),
77
+ wslDistro: source.wslDistro(),
78
+ });
79
+ return {
80
+ catalog: () => {
81
+ const at = now();
82
+ if (cache !== undefined && at - cache.at < CATALOG_TTL_MS)
83
+ return cache.rows;
84
+ const rows = buildCatalog(facts());
85
+ cache = { at, rows };
86
+ return rows;
87
+ },
88
+ invalidate: () => {
89
+ cache = undefined;
90
+ },
91
+ env: (id) => uiEnv(id, process.env),
92
+ };
93
+ }
@@ -0,0 +1,67 @@
1
+ import type { CatalogFacts, ShellEntry, ShellSwitches } from "../shells.js";
2
+ import type { SettingsSurface } from "../settings-surface.js";
3
+ import type { ShellId } from "../shell-id.js";
4
+ import type { UiTerminalRegistry } from "./registry.js";
5
+ import { type UpgradeCapableServer } from "./ws.js";
6
+ /** The JSON route path (POST-only, loopback-gated like the config bridge). */
7
+ export declare const TERMINAL_API_PATH = "/api/bash-terminal/terminals";
8
+ /** What the caller must supply; everything fs/session-related stays outside this file. */
9
+ export interface UiBridgeDeps {
10
+ /** A live catalog (the caller owns the TTL cache). */
11
+ catalog(): ShellEntry[];
12
+ /** The catalog facts, for the paths the fallback chain still needs. */
13
+ paths(): CatalogFacts["paths"];
14
+ /** The stored default (`''` when the user never chose). */
15
+ configuredShell(): string;
16
+ /** The stored switches, already defaulted against discovery. */
17
+ switches(): ShellSwitches;
18
+ /** The stored WSL distro (`''` = the WSL default), echoed so the input can show it. */
19
+ wslDistro(): string;
20
+ /** The UI environment for one backend (process.env plus its own rules). */
21
+ env(id: ShellId): Record<string, string | undefined>;
22
+ /**
23
+ * The master switch. Off is not "no shells chosen": the child switches are hidden
24
+ * (a switch for something that cannot run is a lie), and no allocation is served.
25
+ */
26
+ enabled(): boolean;
27
+ /**
28
+ * The opt-in that lets this plugin publish the `webTerminals` service for
29
+ * dsh-better-sidebar's OFFICIAL terminal row. Default false: on a host that ships
30
+ * its own terminal controller, the first client to `provide` that name wins and the
31
+ * loser's entry fails - and the controller's provide is unguarded, so an opt-out
32
+ * default would break the first-party terminal (measured on 0.2.0-rc.2).
33
+ */
34
+ shimOfficialTerminal(): boolean;
35
+ /**
36
+ * Whether this host line renders a settings page at all (`src/settings-surface.ts`).
37
+ * The client cannot probe this and must not guess: on 0.1.0/0.1.1 the `settings.*` slot
38
+ * map exists but no page renders it, so a registered card is unreachable - and those are
39
+ * the only lines where the plugin's own floating panel is the way in.
40
+ */
41
+ settingsSurface(): SettingsSurface;
42
+ /** Persist one config path (the caller wires `settings.mutate`). */
43
+ writeConfig(path: readonly string[], value: unknown): Promise<void>;
44
+ /** Allocate a terminal for one session; the host picks the shell. */
45
+ registry: UiTerminalRegistry;
46
+ /** The session's working directory ('' when the host cannot say). */
47
+ cwdFor(sessionId: string): string;
48
+ /** Why the bridge cannot serve a terminal, or 'ok'. */
49
+ unavailableReason(): string;
50
+ /** Loopback gate, shared with the config bridge's rule. */
51
+ isLoopback(request: {
52
+ socket?: {
53
+ remoteAddress?: string;
54
+ };
55
+ }): boolean;
56
+ log?(level: "info" | "warn", message: string): void;
57
+ }
58
+ /**
59
+ * Register the terminal routes.
60
+ * @param webServer - the host webserver (may lack upgrade support).
61
+ * @param deps - the wiring above.
62
+ * @returns a disposer, plus the reason when the host cannot carry a socket.
63
+ */
64
+ export declare function registerUiTerminalRoutes(webServer: UpgradeCapableServer | undefined, deps: UiBridgeDeps): {
65
+ dispose(): void;
66
+ socket: "mounted" | "no-websocket-route";
67
+ };