Files
orca/src/shared/tui-agent-selection.ts
T
Jinjing bda658a364 Add agent enablement controls (#2972)
* Add agent enablement controls

Implements the Enable/Disable Agents Dashboard behavior described in docs/enable-disable-agents-dashboard.md, including persisted agent enablement state, filtered launch surfaces, and settings UI affordances.

* Clarify agent availability controls

* Respect disabled agents across workspace and AI defaults

- Filter disabled TUI agents from mobile and quick workspace selection
- Avoid implicitly choosing disabled agents for commit/PR AI settings
- Broadcast settings changes to open windows for disabled-agent updates

* rm design doc

* fix: complete agent enablement propagation
2026-05-28 17:29:49 -07:00

83 lines
2.0 KiB
TypeScript

import type { TuiAgent } from './types'
import { isTuiAgent } from './tui-agent-config'
// Keep this order in sync with the desktop agent catalog. It defines the
// automatic fallback priority when the user has not chosen a default agent.
export const TUI_AGENT_AUTO_PICK_ORDER = [
'claude',
'codex',
'grok',
'copilot',
'opencode',
'pi',
'omp',
'gemini',
'antigravity',
'aider',
'goose',
'amp',
'kilo',
'kiro',
'crush',
'aug',
'autohand',
'cline',
'codebuff',
'command-code',
'continue',
'cursor',
'droid',
'kimi',
'mistral-vibe',
'qwen-code',
'rovo',
'hermes',
'openclaw'
] as const satisfies readonly TuiAgent[]
export function pickTuiAgent(
preferred: TuiAgent | 'blank' | null | undefined,
detected: Iterable<TuiAgent>,
disabled?: Iterable<unknown> | null
): TuiAgent | null {
if (preferred === 'blank') {
return null
}
const disabledSet = new Set(normalizeDisabledTuiAgents(disabled))
const detectedSet = detected instanceof Set ? detected : new Set(detected)
if (preferred && detectedSet.has(preferred) && !disabledSet.has(preferred)) {
return preferred
}
for (const agent of TUI_AGENT_AUTO_PICK_ORDER) {
if (detectedSet.has(agent) && !disabledSet.has(agent)) {
return agent
}
}
return null
}
export function normalizeDisabledTuiAgents(value: unknown): TuiAgent[] {
if (!Array.isArray(value)) {
return []
}
const seen = new Set<TuiAgent>()
for (const item of value) {
if (isTuiAgent(item)) {
seen.add(item)
}
}
return [...seen]
}
export function isTuiAgentEnabled(agent: TuiAgent, disabled?: Iterable<unknown> | null): boolean {
return !normalizeDisabledTuiAgents(disabled).includes(agent)
}
export function filterEnabledTuiAgents<T extends TuiAgent>(
agents: Iterable<T>,
disabled?: Iterable<unknown> | null
): T[] {
const disabledSet = new Set(normalizeDisabledTuiAgents(disabled))
return [...agents].filter((agent) => !disabledSet.has(agent))
}