Repository navigation
Expand file tree
/
Copy pathlinux-env.ts
More file actions
39 lines (35 loc) · 1.55 KB
/
Copy pathlinux-env.ts
File metadata and controls
39 lines (35 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* Shared Linux input-tool resolution — display server and input tool.
*
* The display decision comes from the resolved provider's bound host, never an ambient read, and
* the chosen tool is memoized on that provider instance — no module state, so two runtimes with
* different hosts resolve and keep their own selection (#3794). A refusal is never cached.
*/
import { AppError } from '@agent-device/kernel/errors';
import { resolveLinuxToolProvider, type LinuxToolProvider } from './tool-provider.ts';
import type { DisplayServer } from './display.ts';
import type { LinuxInputSelection } from './input-tool.ts';
export async function ensureInputTool(
provider: LinuxToolProvider = resolveLinuxToolProvider(),
): Promise<LinuxInputSelection> {
const display: DisplayServer = provider.display.detectDisplayServer();
if (provider.inputSelection?.display === display) return provider.inputSelection;
if (display === 'wayland') {
if (await provider.whichCommand('ydotool')) {
provider.inputSelection = { tool: 'ydotool', display };
return provider.inputSelection;
}
throw new AppError(
'TOOL_MISSING',
'ydotool is required for input synthesis on Wayland (xdotool does not work on Wayland). Install it via your package manager.',
);
}
if (await provider.whichCommand('xdotool')) {
provider.inputSelection = { tool: 'xdotool', display };
return provider.inputSelection;
}
throw new AppError(
'TOOL_MISSING',
'xdotool is required for input synthesis on X11. Install it via your package manager.',
);
}