@deepseek-harness-tui/dsh-tui 0.20.0 → 0.20.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 (180) hide show
  1. package/README.md +18 -3
  2. package/bin/dsh-tui.js +26 -8
  3. package/guide/dsh-tui-guide/claude-backend.en.md +6 -5
  4. package/guide/dsh-tui-guide/claude-backend.md +5 -5
  5. package/guide/dsh-tui-guide/configuration.en.md +26 -12
  6. package/guide/dsh-tui-guide/configuration.md +18 -9
  7. package/guide/dsh-tui-guide/getting-started.en.md +17 -9
  8. package/guide/dsh-tui-guide/getting-started.md +11 -7
  9. package/guide/dsh-tui-guide/interaction.en.md +1 -0
  10. package/guide/dsh-tui-guide/interaction.md +1 -0
  11. package/guide/dsh-tui-guide/migrate.en.md +5 -0
  12. package/guide/dsh-tui-guide/migrate.md +4 -0
  13. package/guide/dsh-tui-guide/plugins.en.md +17 -1
  14. package/guide/dsh-tui-guide/plugins.md +12 -1
  15. package/guide/dsh-tui-guide/themes.en.md +1 -1
  16. package/guide/dsh-tui-guide/themes.md +1 -1
  17. package/guide/dsh-tui-guide/user-guide.en.md +8 -2
  18. package/guide/dsh-tui-guide/user-guide.md +8 -2
  19. package/lib/settings.json +19 -3
  20. package/lib/types/adapter/kernel/host-facade.d.ts +3 -1
  21. package/lib/types/adapter/kernel/host-facade.d.ts.map +1 -1
  22. package/lib/types/adapter/kernel/host-facade.js +6 -0
  23. package/lib/types/adapter/kernel/runtime.d.ts.map +1 -1
  24. package/lib/types/adapter/kernel/runtime.js +5 -0
  25. package/lib/types/adapter/kernel/slices/extensions.d.ts +1 -0
  26. package/lib/types/adapter/kernel/slices/extensions.d.ts.map +1 -1
  27. package/lib/types/adapter/kernel/slices/extensions.js +6 -1
  28. package/lib/types/adapter/kernel/slices/index.d.ts +1 -1
  29. package/lib/types/adapter/kernel/slices/index.d.ts.map +1 -1
  30. package/lib/types/adapter/kernel/slices/index.js +3 -2
  31. package/lib/types/adapter/ports/channel-catalog.d.ts +19 -0
  32. package/lib/types/adapter/ports/channel-catalog.d.ts.map +1 -1
  33. package/lib/types/adapter/ports/channel-settings.d.ts +6 -0
  34. package/lib/types/adapter/ports/channel-settings.d.ts.map +1 -1
  35. package/lib/types/adapter/ports/channel-view.d.ts +28 -2
  36. package/lib/types/adapter/ports/channel-view.d.ts.map +1 -1
  37. package/lib/types/adapter/ports/extensions.d.ts +9 -0
  38. package/lib/types/adapter/ports/extensions.d.ts.map +1 -1
  39. package/lib/types/adapter/ports/index.d.ts +1 -1
  40. package/lib/types/adapter/ports/index.d.ts.map +1 -1
  41. package/lib/types/adapter/upstream/extensions-driver.d.ts +4 -1
  42. package/lib/types/adapter/upstream/extensions-driver.d.ts.map +1 -1
  43. package/lib/types/adapter/upstream/extensions-driver.js +111 -1
  44. package/lib/types/adapter/upstream/index.d.ts +1 -1
  45. package/lib/types/adapter/upstream/index.d.ts.map +1 -1
  46. package/lib/types/adapter/upstream/index.js +1 -1
  47. package/lib/types/api.d.ts +1 -1
  48. package/lib/types/api.d.ts.map +1 -1
  49. package/lib/types/backends/claude/backend.d.ts.map +1 -1
  50. package/lib/types/backends/claude/backend.js +7 -2
  51. package/lib/types/backends/claude/session/lifecycle.d.ts.map +1 -1
  52. package/lib/types/backends/claude/session/lifecycle.js +11 -9
  53. package/lib/types/backends/claude/side-query.d.ts +2 -0
  54. package/lib/types/backends/claude/side-query.d.ts.map +1 -1
  55. package/lib/types/backends/claude/side-query.js +30 -13
  56. package/lib/types/components/FileSuggestions.d.ts +2 -2
  57. package/lib/types/components/FileSuggestions.d.ts.map +1 -1
  58. package/lib/types/components/FileSuggestions.js +25 -5
  59. package/lib/types/components/PromptInput.d.ts +7 -1
  60. package/lib/types/components/PromptInput.d.ts.map +1 -1
  61. package/lib/types/components/PromptInput.js +81 -23
  62. package/lib/types/components/messages/AssistantToolUseMessage.d.ts +1 -1
  63. package/lib/types/components/messages/AssistantToolUseMessage.d.ts.map +1 -1
  64. package/lib/types/components/messages/AssistantToolUseMessage.js +228 -27
  65. package/lib/types/components/messages/presentCardBackground.d.ts +28 -0
  66. package/lib/types/components/messages/presentCardBackground.d.ts.map +1 -0
  67. package/lib/types/components/messages/presentCardBackground.js +23 -0
  68. package/lib/types/dsh-adapter/backend/translate.d.ts.map +1 -1
  69. package/lib/types/dsh-adapter/backend/translate.js +28 -1
  70. package/lib/types/dsh-adapter/channel/core/compose.d.ts.map +1 -1
  71. package/lib/types/dsh-adapter/channel/core/files.d.ts.map +1 -1
  72. package/lib/types/dsh-adapter/channel/file-actions.d.ts +1 -1
  73. package/lib/types/dsh-adapter/channel/file-actions.d.ts.map +1 -1
  74. package/lib/types/dsh-adapter/channel/file-actions.js +11 -4
  75. package/lib/types/dsh-adapter/channel/settings-host.d.ts.map +1 -1
  76. package/lib/types/dsh-adapter/channel/settings-host.js +78 -12
  77. package/lib/types/dsh-adapter/channel/state.d.ts +4 -3
  78. package/lib/types/dsh-adapter/channel/state.d.ts.map +1 -1
  79. package/lib/types/dsh-adapter/channel/state.js +4 -3
  80. package/lib/types/dsh-adapter/channel/types.d.ts +1 -1
  81. package/lib/types/dsh-adapter/channel/types.d.ts.map +1 -1
  82. package/lib/types/dsh-adapter/channel.d.ts +1 -1
  83. package/lib/types/dsh-adapter/channel.d.ts.map +1 -1
  84. package/lib/types/dsh-adapter/childStderr.d.ts +1 -1
  85. package/lib/types/dsh-adapter/childStderr.d.ts.map +1 -1
  86. package/lib/types/dsh-adapter/childStderr.js +5 -0
  87. package/lib/types/dsh-adapter/contract.d.ts +23 -8
  88. package/lib/types/dsh-adapter/contract.d.ts.map +1 -1
  89. package/lib/types/dsh-adapter/contract.js +27 -7
  90. package/lib/types/dsh-adapter/extensions.d.ts +3 -2
  91. package/lib/types/dsh-adapter/extensions.d.ts.map +1 -1
  92. package/lib/types/dsh-adapter/extensions.js +5 -2
  93. package/lib/types/dsh-adapter/host-contract.d.ts +1 -1
  94. package/lib/types/dsh-adapter/host-contract.js +1 -1
  95. package/lib/types/dsh-adapter/host-dsh.d.ts +4 -0
  96. package/lib/types/dsh-adapter/host-dsh.d.ts.map +1 -1
  97. package/lib/types/dsh-adapter/host-dsh.js +26 -0
  98. package/lib/types/dsh-adapter/host-entry.js +4 -2
  99. package/lib/types/dsh-adapter/host-service-diagnostics.d.ts +61 -0
  100. package/lib/types/dsh-adapter/host-service-diagnostics.d.ts.map +1 -0
  101. package/lib/types/dsh-adapter/host-service-diagnostics.js +103 -0
  102. package/lib/types/dsh-adapter/index.d.ts +5 -0
  103. package/lib/types/dsh-adapter/index.d.ts.map +1 -1
  104. package/lib/types/dsh-adapter/index.js +1 -0
  105. package/lib/types/dsh-adapter/mention-providers.d.ts +91 -0
  106. package/lib/types/dsh-adapter/mention-providers.d.ts.map +1 -0
  107. package/lib/types/dsh-adapter/mention-providers.js +214 -0
  108. package/lib/types/dsh-adapter/migrate/entry.d.ts +2 -0
  109. package/lib/types/dsh-adapter/migrate/entry.d.ts.map +1 -0
  110. package/lib/types/dsh-adapter/migrate/entry.js +46 -0
  111. package/lib/types/dsh-adapter/plugin.d.ts.map +1 -1
  112. package/lib/types/dsh-adapter/plugin.js +42 -2
  113. package/lib/types/dsh-adapter/present-tool.d.ts +20 -0
  114. package/lib/types/dsh-adapter/present-tool.d.ts.map +1 -0
  115. package/lib/types/dsh-adapter/present-tool.js +96 -0
  116. package/lib/types/extensions.d.ts +2 -0
  117. package/lib/types/extensions.d.ts.map +1 -1
  118. package/lib/types/extensions.js +4 -1
  119. package/lib/types/i18n.d.ts +21 -2
  120. package/lib/types/i18n.d.ts.map +1 -1
  121. package/lib/types/i18n.js +9 -1
  122. package/lib/types/ink/components/ScrollBox.d.ts.map +1 -1
  123. package/lib/types/ink/components/ScrollBox.js +13 -0
  124. package/lib/types/ink/dom.d.ts +3 -0
  125. package/lib/types/ink/dom.d.ts.map +1 -1
  126. package/lib/types/ink/ink.d.ts.map +1 -1
  127. package/lib/types/ink/ink.js +30 -34
  128. package/lib/types/ink/render-node-to-output.d.ts +3 -0
  129. package/lib/types/ink/render-node-to-output.d.ts.map +1 -1
  130. package/lib/types/ink/render-node-to-output.js +54 -40
  131. package/lib/types/ink/selection.d.ts +38 -28
  132. package/lib/types/ink/selection.d.ts.map +1 -1
  133. package/lib/types/ink/selection.js +201 -130
  134. package/lib/types/kernelPrefs.d.ts +5 -2
  135. package/lib/types/kernelPrefs.d.ts.map +1 -1
  136. package/lib/types/kernelPrefs.js +5 -2
  137. package/lib/types/screens/Chat.d.ts +4 -1
  138. package/lib/types/screens/Chat.d.ts.map +1 -1
  139. package/lib/types/screens/Chat.js +2 -2
  140. package/lib/types/settings/definitions.d.ts +12 -0
  141. package/lib/types/settings/definitions.d.ts.map +1 -1
  142. package/lib/types/settings/definitions.js +10 -2
  143. package/lib/types/theme.d.ts +4 -0
  144. package/lib/types/theme.d.ts.map +1 -1
  145. package/lib/types/theme.js +20 -2
  146. package/lib/types/tuiDisplayPrefs.d.ts +3 -0
  147. package/lib/types/tuiDisplayPrefs.d.ts.map +1 -1
  148. package/lib/types/tuiDisplayPrefs.js +10 -0
  149. package/lib/types/update.d.ts +74 -5
  150. package/lib/types/update.d.ts.map +1 -1
  151. package/lib/types/update.js +297 -46
  152. package/lib/types/updateHost.d.ts.map +1 -1
  153. package/lib/types/updateHost.js +16 -5
  154. package/lib/types/usageStats.d.ts +6 -0
  155. package/lib/types/usageStats.d.ts.map +1 -1
  156. package/lib/types/usageStats.js +8 -0
  157. package/lib/types/utils/colorMix.d.ts +19 -0
  158. package/lib/types/utils/colorMix.d.ts.map +1 -0
  159. package/lib/types/utils/colorMix.js +51 -0
  160. package/lib/types/utils/commandLine.d.ts +8 -0
  161. package/lib/types/utils/commandLine.d.ts.map +1 -0
  162. package/lib/types/utils/commandLine.js +37 -0
  163. package/lib/types/utils/desktopEntry.d.ts +32 -0
  164. package/lib/types/utils/desktopEntry.d.ts.map +1 -0
  165. package/lib/types/utils/desktopEntry.js +302 -0
  166. package/lib/types/utils/externalEditor.d.ts +2 -5
  167. package/lib/types/utils/externalEditor.d.ts.map +1 -1
  168. package/lib/types/utils/externalEditor.js +4 -36
  169. package/lib/types/utils/fileSuggestions.d.ts +14 -3
  170. package/lib/types/utils/fileSuggestions.d.ts.map +1 -1
  171. package/lib/types/utils/fileSuggestions.js +33 -0
  172. package/lib/types/utils/openExternal.d.ts +9 -0
  173. package/lib/types/utils/openExternal.d.ts.map +1 -1
  174. package/lib/types/utils/openExternal.js +87 -3
  175. package/lib/types/utils/terminalLaunch.d.ts +16 -0
  176. package/lib/types/utils/terminalLaunch.d.ts.map +1 -0
  177. package/lib/types/utils/terminalLaunch.js +121 -0
  178. package/package.json +116 -110
  179. package/tui-profile/feed/README.md +1 -1
  180. package/tui-profile/feed/first-party.json +1 -1
@@ -20,12 +20,24 @@
20
20
  * works) — `windowsHide` alone (CREATE_NO_WINDOW) keeps it invisible
21
21
  * AND functional.
22
22
  * - macOS: `open` (reveal adds `-R`).
23
- * - Linux/other: `xdg-open`.
23
+ * - Linux/other: `xdg-open`, except a local file whose resolved handler is
24
+ * `Terminal=true` (e.g. `vim.desktop`). The generic `xdg-open` path executes
25
+ * `Exec=` directly without a terminal wrapper, so such an app inherits the
26
+ * TUI's non-tty stdio and exits immediately. For those targets the default entry
27
+ * is resolved through `xdg-mime`, its Exec is expanded, and the command is
28
+ * spawned inside a terminal (desktopEntry.ts / terminalLaunch.ts). Missing
29
+ * tools, an unsupported Exec or terminal startup errors fall back to
30
+ * `xdg-open`. Non-empty `Path=` is outside this wrapper's scope and stays
31
+ * with the system launcher; generic xdg-open may still lack a tty and
32
+ * ignore the working directory for those entries.
24
33
  */
25
34
  import { spawn } from 'node:child_process';
26
35
  import { dirname } from 'node:path';
27
- import { existsSync, statSync } from 'node:fs';
36
+ import { existsSync, readFileSync, statSync } from 'node:fs';
37
+ import { expandExec, findDesktopEntry, parseDesktopEntry } from './desktopEntry.js';
38
+ import { execFileNoThrow } from './execFileNoThrow.js';
28
39
  import { cmdEscapeArgument } from './shellQuote.js';
40
+ import { buildTerminalSpawn, isExecutableOnPath, resolveTerminal } from './terminalLaunch.js';
29
41
  import { logError } from './log.js';
30
42
  /**
31
43
  * Spawn a fire-and-forget child: no stdio pipes, no wait, unref'd so the
@@ -108,6 +120,65 @@ export function buildWin32OpenSpawn(target) {
108
120
  }
109
121
  return buildWin32StartSpawn(target);
110
122
  }
123
+ const URL_SCHEME = /^[a-z][a-z0-9+.-]*:\/\//i;
124
+ /** Whether a Linux target is a URL rather than a local path. */
125
+ function isUrlTarget(target) {
126
+ return URL_SCHEME.test(target) || /^mailto:/i.test(target);
127
+ }
128
+ /** One bounded `xdg-mime query` call; undefined on failure/empty output. */
129
+ async function queryXdgMime(kind, value) {
130
+ const result = await execFileNoThrow('xdg-mime', ['query', kind, value], { timeout: 800 });
131
+ if (result.code !== 0)
132
+ return undefined;
133
+ const line = result.stdout.trim().split(/\r?\n/, 1)[0]?.trim();
134
+ return line === undefined || line === '' ? undefined : line;
135
+ }
136
+ /**
137
+ * Resolve a local file's default handler and, when it is `Terminal=true`,
138
+ * build the terminal-wrapped spawn descriptor. Exported for the regression
139
+ * script; `undefined` means "keep using xdg-open".
140
+ */
141
+ export async function resolveLinuxFileOpen(target, env = process.env) {
142
+ if (target === '' || isUrlTarget(target) || isDirectory(target))
143
+ return undefined;
144
+ const mime = await queryXdgMime('filetype', target);
145
+ if (mime === undefined)
146
+ return undefined;
147
+ const id = await queryXdgMime('default', mime);
148
+ if (id === undefined)
149
+ return undefined;
150
+ const path = findDesktopEntry(id, env);
151
+ if (path === undefined)
152
+ return undefined;
153
+ let entry;
154
+ try {
155
+ entry = parseDesktopEntry(readFileSync(path, 'utf8'), id, path);
156
+ }
157
+ catch {
158
+ return undefined;
159
+ }
160
+ if (entry === undefined || entry.hidden || !entry.terminal)
161
+ return undefined;
162
+ // Path= is outside this wrapper's scope. Keep the system launcher's
163
+ // existing behavior instead of substituting the TUI's working directory.
164
+ if (entry.workingDirectory !== undefined)
165
+ return undefined;
166
+ if (entry.tryExec !== undefined && !isExecutableOnPath(entry.tryExec, env)) {
167
+ logError(`dsh-tui: ${entry.id} is Terminal=true but TryExec "${entry.tryExec}" is not available; falling back to xdg-open`);
168
+ return undefined;
169
+ }
170
+ const argv = expandExec(entry.exec, target, entry);
171
+ if (argv === undefined) {
172
+ logError(`dsh-tui: ${entry.id} is Terminal=true but its Exec line is unsupported; falling back to xdg-open`);
173
+ return undefined;
174
+ }
175
+ const terminal = resolveTerminal(env);
176
+ if (terminal === undefined) {
177
+ logError(`dsh-tui: ${entry.id} is Terminal=true but no terminal emulator was found; falling back to xdg-open`);
178
+ return undefined;
179
+ }
180
+ return buildTerminalSpawn(terminal, argv);
181
+ }
111
182
  /** Open a URL, file or directory with the platform's default handler. */
112
183
  export function openExternal(target) {
113
184
  if (target === '')
@@ -130,9 +201,22 @@ export function openExternal(target) {
130
201
  else if (process.platform === 'darwin') {
131
202
  spawnDetached('open', [target]);
132
203
  }
133
- else {
204
+ else if (isDirectory(target) || isUrlTarget(target)) {
134
205
  spawnDetached('xdg-open', [target]);
135
206
  }
207
+ else {
208
+ void resolveLinuxFileOpen(target).then(spec => {
209
+ if (spec === undefined)
210
+ spawnDetached('xdg-open', [target]);
211
+ else
212
+ spawnDetached(spec.file, spec.args, {
213
+ onError: () => spawnDetached('xdg-open', [target]),
214
+ });
215
+ }, error => {
216
+ logError(error);
217
+ spawnDetached('xdg-open', [target]);
218
+ });
219
+ }
136
220
  }
137
221
  /** Open a file with its associated application (openExternal with a file). */
138
222
  export function openFile(path) {
@@ -0,0 +1,16 @@
1
+ /** A terminal command split into the emulator args and the program separator. */
2
+ export interface TerminalSpec {
3
+ readonly file: string;
4
+ readonly args: readonly string[];
5
+ readonly separator: readonly string[];
6
+ }
7
+ /** Whether `command` resolves to an executable on PATH (or is an executable path). */
8
+ export declare function isExecutableOnPath(command: string, env?: NodeJS.ProcessEnv): boolean;
9
+ /** Resolve the terminal command, or undefined when none is available. */
10
+ export declare function resolveTerminal(env?: NodeJS.ProcessEnv): TerminalSpec | undefined;
11
+ /** Assemble the final argv: terminal args, separator, then the handler argv. */
12
+ export declare function buildTerminalSpawn(terminal: TerminalSpec, argv: readonly string[]): {
13
+ file: string;
14
+ args: string[];
15
+ };
16
+ //# sourceMappingURL=terminalLaunch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"terminalLaunch.d.ts","sourceRoot":"","sources":["../../../src/utils/terminalLaunch.ts"],"names":[],"mappings":"AAiBA,iFAAiF;AACjF,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;IAChC,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAA;CACtC;AAWD,sFAAsF;AACtF,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,OAAO,CAQjG;AAyDD,yEAAyE;AACzE,wBAAgB,eAAe,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,YAAY,GAAG,SAAS,CAiB9F;AAED,gFAAgF;AAChF,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,SAAS,MAAM,EAAE,GACtB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAElC"}
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Pick a terminal emulator for the Linux `Terminal=true` open path and build
3
+ * the spawn descriptor. The TUI itself owns a tty but hands child processes
4
+ * `stdio: 'ignore'`, so a terminal application must get its own window; this
5
+ * is the piece the generic `xdg-open` path lacks (it executes `Exec=` directly).
6
+ *
7
+ * Selection order: `$TERMINAL` (may carry arguments, e.g. `kitty -1`) → KDE's
8
+ * `kdeglobals` `[General] TerminalApplication` → `xdg-terminal-exec` → the
9
+ * first known terminal on PATH. Each terminal gets its own command separator
10
+ * (`kitty`/`foot` take the program directly, `konsole`/`xterm` use `-e`,
11
+ * GNOME Terminal uses `--`, wezterm uses `start --`, XFCE/MATE/Terminator use `-x`).
12
+ */
13
+ import { readFileSync, statSync } from 'node:fs';
14
+ import { homedir } from 'node:os';
15
+ import { basename, delimiter, join } from 'node:path';
16
+ import { splitCommandLine } from './commandLine.js';
17
+ function isExecutableFile(path) {
18
+ try {
19
+ const stat = statSync(path);
20
+ return stat.isFile() && (stat.mode & 0o111) !== 0;
21
+ }
22
+ catch {
23
+ return false;
24
+ }
25
+ }
26
+ /** Whether `command` resolves to an executable on PATH (or is an executable path). */
27
+ export function isExecutableOnPath(command, env = process.env) {
28
+ if (command === '')
29
+ return false;
30
+ if (command.includes('/'))
31
+ return isExecutableFile(command);
32
+ for (const dir of (env.PATH ?? '').split(delimiter)) {
33
+ if (dir === '')
34
+ continue;
35
+ if (isExecutableFile(join(dir, command)))
36
+ return true;
37
+ }
38
+ return false;
39
+ }
40
+ /** How a terminal takes the program to run. */
41
+ function separatorFor(file) {
42
+ switch (basename(file).replace(/\.exe$/i, '')) {
43
+ case 'kitty':
44
+ case 'foot':
45
+ case 'xdg-terminal-exec':
46
+ return [];
47
+ case 'wezterm':
48
+ return ['start', '--'];
49
+ case 'gnome-terminal':
50
+ return ['--'];
51
+ case 'xfce4-terminal':
52
+ case 'mate-terminal':
53
+ case 'terminator':
54
+ return ['-x'];
55
+ default:
56
+ return ['-e'];
57
+ }
58
+ }
59
+ function specFor(commandLine) {
60
+ const argv = splitCommandLine(commandLine);
61
+ const file = argv[0];
62
+ if (file === undefined || file === '')
63
+ return undefined;
64
+ return { file, args: argv.slice(1), separator: separatorFor(file) };
65
+ }
66
+ /** KDE stores its terminal choice in `~/.config/kdeglobals` (`[General]`). */
67
+ function readKdeTerminal(env) {
68
+ const configHome = env.XDG_CONFIG_HOME?.trim() || join(env.HOME?.trim() || homedir(), '.config');
69
+ let text;
70
+ try {
71
+ text = readFileSync(join(configHome, 'kdeglobals'), 'utf8');
72
+ }
73
+ catch {
74
+ return undefined;
75
+ }
76
+ let inGeneral = false;
77
+ for (const raw of text.split(/\r?\n/)) {
78
+ const line = raw.trim();
79
+ if (line.startsWith('[') && line.endsWith(']')) {
80
+ inGeneral = line === '[General]';
81
+ continue;
82
+ }
83
+ if (!inGeneral)
84
+ continue;
85
+ const eq = line.indexOf('=');
86
+ if (eq <= 0)
87
+ continue;
88
+ if (line.slice(0, eq).trim() !== 'TerminalApplication')
89
+ continue;
90
+ const value = line.slice(eq + 1).trim();
91
+ return value === '' ? undefined : specFor(value);
92
+ }
93
+ return undefined;
94
+ }
95
+ const FALLBACK_TERMINALS = ['kitty', 'ghostty', 'konsole', 'alacritty', 'wezterm', 'foot', 'rio', 'gnome-terminal', 'xterm'];
96
+ /** Resolve the terminal command, or undefined when none is available. */
97
+ export function resolveTerminal(env = process.env) {
98
+ const explicit = env.TERMINAL?.trim() ?? '';
99
+ if (explicit !== '') {
100
+ const spec = specFor(explicit);
101
+ if (spec !== undefined && isExecutableOnPath(spec.file, env))
102
+ return spec;
103
+ }
104
+ // A stale kdeglobals value must not shadow a working xdg-terminal-exec or
105
+ // the known-terminal fallbacks below.
106
+ const kde = readKdeTerminal(env);
107
+ if (kde !== undefined && isExecutableOnPath(kde.file, env))
108
+ return kde;
109
+ if (isExecutableOnPath('xdg-terminal-exec', env)) {
110
+ return { file: 'xdg-terminal-exec', args: [], separator: [] };
111
+ }
112
+ for (const file of FALLBACK_TERMINALS) {
113
+ if (isExecutableOnPath(file, env))
114
+ return { file, args: [], separator: separatorFor(file) };
115
+ }
116
+ return undefined;
117
+ }
118
+ /** Assemble the final argv: terminal args, separator, then the handler argv. */
119
+ export function buildTerminalSpawn(terminal, argv) {
120
+ return { file: terminal.file, args: [...terminal.args, ...terminal.separator, ...argv] };
121
+ }