1/**
2 * The machine triage runs on: the one on screen, else the primary if it
3 * supports triage, else the first connected machine that does. Without No
4 * project threads the action still shows and explains the terminal fallback,
5 * so this does not check for them.
6 */
7export function pickTriageEnvironment<Id extends string>(input: {
8 readonly onScreen: Id | null;
9 readonly primary: Id | null;
10 readonly connected: ReadonlyArray<Id>;
11 readonly supportsTriage: (environmentId: Id) => boolean;
12}): Id | null {
13 if (input.onScreen !== null) return input.onScreen;
14 if (input.primary !== null && input.supportsTriage(input.primary)) return input.primary;
15 return input.connected.find(input.supportsTriage) ?? null;
16}