-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathselect-agent.ts
More file actions
73 lines (60 loc) · 1.93 KB
/
select-agent.ts
File metadata and controls
73 lines (60 loc) · 1.93 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import * as p from '@clack/prompts'
import type { AgentType, CliArgs } from '../types.js'
type AgentChoice = {
/** File to write at project root pointing agents to the skill */
configFile: 'AGENTS.md' | 'CLAUDE.md'
label: string
skillsDir: string
value: AgentType
}
export const agentChoices: AgentChoice[] = [
{ configFile: 'CLAUDE.md', label: 'Claude Code', skillsDir: '.claude/skills', value: 'claude' },
{ configFile: 'AGENTS.md', label: 'Codex', skillsDir: '.agents/skills', value: 'codex' },
{ configFile: 'AGENTS.md', label: 'Cursor', skillsDir: '.agents/skills', value: 'cursor' },
]
const validAgentValues = agentChoices.map((c) => c.value)
export function getAgentChoice(agentType: AgentType): AgentChoice {
const choice = agentChoices.find((c) => c.value === agentType)
if (!choice) {
throw new Error(`Unknown agent type: ${agentType}`)
}
return choice
}
export function getSkillsDir(agentType: AgentType): string {
return getAgentChoice(agentType).skillsDir
}
export async function selectAgent(args: { cliArgs: CliArgs }): Promise<AgentType | undefined> {
const { cliArgs } = args
if (cliArgs['--no-agent']) {
return undefined
}
if (cliArgs['--agent']) {
const value = cliArgs['--agent'] as AgentType
if (!validAgentValues.includes(value)) {
throw new Error(
`Invalid agent type: ${cliArgs['--agent']}. Valid types are: ${validAgentValues.join(', ')}`,
)
}
return value
}
const selected = await p.select<
{ label: string; value: 'none' | AgentType }[],
'none' | AgentType
>({
message: 'Select a coding agent to install the Payload skill for',
options: [
...agentChoices.map((choice) => ({
label: choice.label,
value: choice.value,
})),
{ label: 'None', value: 'none' as const },
],
})
if (p.isCancel(selected)) {
process.exit(0)
}
if (selected === 'none') {
return undefined
}
return selected
}