MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / validateAgent

Function validateAgent

source code/components/agents/validateAgent.ts:37–111  ·  view source on GitHub ↗
(
  agent: Omit<CustomAgentDefinition, 'location'>,
  availableTools: Tools,
  existingAgents: AgentDefinition[],
)

Source from the content-addressed store, hash-verified

35}
36
37export function validateAgent(
38 agent: Omit<CustomAgentDefinition, 'location'>,
39 availableTools: Tools,
40 existingAgents: AgentDefinition[],
41): AgentValidationResult {
42 const errors: string[] = []
43 const warnings: string[] = []
44
45 // Validate agent type
46 if (!agent.agentType) {
47 errors.push('Agent type is required')
48 } else {
49 const typeError = validateAgentType(agent.agentType)
50 if (typeError) {
51 errors.push(typeError)
52 }
53
54 // Check for duplicates (excluding self for editing)
55 const duplicate = existingAgents.find(
56 a => a.agentType === agent.agentType && a.source !== agent.source,
57 )
58 if (duplicate) {
59 errors.push(
60 `Agent type "${agent.agentType}" already exists in ${getAgentSourceDisplayName(duplicate.source)}`,
61 )
62 }
63 }
64
65 // Validate description
66 if (!agent.whenToUse) {
67 errors.push('Description (description) is required')
68 } else if (agent.whenToUse.length < 10) {
69 warnings.push(
70 'Description should be more descriptive (at least 10 characters)',
71 )
72 } else if (agent.whenToUse.length > 5000) {
73 warnings.push('Description is very long (over 5000 characters)')
74 }
75
76 // Validate tools
77 if (agent.tools !== undefined && !Array.isArray(agent.tools)) {
78 errors.push('Tools must be an array')
79 } else {
80 if (agent.tools === undefined) {
81 warnings.push('Agent has access to all tools')
82 } else if (agent.tools.length === 0) {
83 warnings.push(
84 'No tools selected - agent will have very limited capabilities',
85 )
86 }
87
88 // Check for invalid tools
89 const resolvedTools = resolveAgentTools(agent, availableTools, false)
90
91 if (resolvedTools.invalidTools.length > 0) {
92 errors.push(`Invalid tools: ${resolvedTools.invalidTools.join(', ')}`)
93 }
94 }

Callers 1

ConfirmStepFunction · 0.85

Calls 3

validateAgentTypeFunction · 0.85
resolveAgentToolsFunction · 0.85

Tested by

no test coverage detected