30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { isAnteHeadlessOneShotCommand } from './ante-headless-command'
|
|
import { isPrintModeHeadlessOneShotCommand } from './print-mode-headless-command'
|
|
import type { TuiAgent } from './types'
|
|
|
|
// Why: a table (not an if-chain) so adding an agent is one entry; Claude and Trae share
|
|
// the same `--print` one-shot contract, Ante's `--prompt` form needs its own matcher.
|
|
const HEADLESS_ONE_SHOT_MATCHERS: Partial<
|
|
Record<TuiAgent, (tokens: readonly string[]) => boolean>
|
|
> = {
|
|
claude: isPrintModeHeadlessOneShotCommand,
|
|
trae: isPrintModeHeadlessOneShotCommand,
|
|
ante: isAnteHeadlessOneShotCommand
|
|
}
|
|
|
|
export function isHeadlessOneShotAgentCommand(agent: TuiAgent, tokens: readonly string[]): boolean {
|
|
return HEADLESS_ONE_SHOT_MATCHERS[agent]?.(tokens) ?? false
|
|
}
|
|
|
|
type AgentCommandRecognition = { agent: TuiAgent } | null
|
|
|
|
export function filterHeadlessOneShotAgentCommand<T extends AgentCommandRecognition>(
|
|
recognition: T,
|
|
tokens: readonly string[]
|
|
): T | null {
|
|
if (recognition && isHeadlessOneShotAgentCommand(recognition.agent, tokens)) {
|
|
return null
|
|
}
|
|
return recognition
|
|
}
|