const agentDefinition = {
id: "codebase-analyzer",
displayName: "CodeBase Analyzer",
publisher: "codelayer",
version: "0.0.1",
model: "anthropic/claude-4-sonnet-20250522",
toolNames: [
"read_files",
"code_search",
"find_files",
"add_message",
"end_turn",
"set_output"
],
spawnableAgents: [],
inputSchema: {
prompt: {
type: "string",
description: "What specific component, feature, or implementation details you need analyzed. Be as specific as possible about what you want to understand."
}
},
includeMessageHistory: false,
outputMode: "structured_output",
outputSchema: {
type: "object",
required: [
"title",
"overview"
],
properties: {
title: {
type: "string",
description: "Title in format \"Analysis: [Feature/Component Name]\""
},
dataFlow: {
type: "array",
items: {
type: "object",
required: [
"step",
"description",
"location"
],
properties: {
step: {
type: "number",
description: "Step number in the flow"
},
location: {
type: "string",
description: "File path with line number"
},
description: {
type: "string",
description: "What happens at this step"
}
}
},
description: "Step-by-step data flow through the system"
},
overview: {
type: "string",
description: "2-3 sentence summary of how it works"
},
entryPoints: {
type: "array",
items: {
type: "object",
required: [
"location",
"description"
],
properties: {
location: {
type: "string",
description: "File path with line number, e.g. \"api/routes.js:45\""
},
description: {
type: "string",
description: "What this entry point does"
}
}
},
description: "Entry points into the component"
},
keyPatterns: {
type: "array",
items: {
type: "object",
required: [
"patternName",
"description"
],
properties: {
location: {
type: "string",
description: "Where this pattern is found"
},
description: {
type: "string",
description: "How the pattern is implemented"
},
patternName: {
type: "string",
description: "Name of the pattern"
}
}
},
description: "Key architectural patterns identified"
},
configuration: {
type: "array",
items: {
type: "object",
required: [
"setting",
"location",
"description"
],
properties: {
setting: {
type: "string",
description: "What is configured"
},
location: {
type: "string",
description: "File path with line number"
},
description: {
type: "string",
description: "What this configuration controls"
}
}
},
description: "Configuration settings and their locations"
},
errorHandling: {
type: "array",
items: {
type: "object",
required: [
"errorType",
"location",
"mechanism"
],
properties: {
location: {
type: "string",
description: "File path with line number"
},
errorType: {
type: "string",
description: "Type of error or scenario"
},
mechanism: {
type: "string",
description: "How the error is handled"
}
}
},
description: "Error handling mechanisms"
},
coreImplementation: {
type: "array",
items: {
type: "object",
required: [
"stepName",
"location",
"details"
],
properties: {
details: {
type: "array",
items: {
type: "string"
},
description: "Detailed explanation points"
},
location: {
type: "string",
description: "File path with line numbers, e.g. \"handlers/webhook.js:15-32\""
},
stepName: {
type: "string",
description: "Name of the implementation step"
}
}
},
description: "Detailed breakdown of core implementation steps"
}
}
},
spawnerPrompt: `Analyzes codebase implementation details. Call the codebase-analyzer agent when you need to find detailed information about specific components. As always, the more detailed your request prompt, the better! :)`,
systemPrompt: `# Persona: CodeBase Analyzer
You are a specialist at understanding HOW code works. Your job is to analyze implementation details, trace data flow, and explain technical workings with precise file:line references.
## Core Responsibilities
1. **Analyze Implementation Details**
- Read specific files to understand logic
- Identify key functions and their purposes
- Trace method calls and data transformations
- Note important algorithms or patterns
2. **Trace Data Flow**
- Follow data from entry to exit points
- Map transformations and validations
- Identify state changes and side effects
- Document API contracts between components
3. **Identify Architectural Patterns**
- Recognize design patterns in use
- Note architectural decisions
- Identify conventions and best practices
- Find integration points between systems
## Analysis Strategy
### Step 1: Read Entry Points
- Start with main files mentioned in the request
- Look for exports, public methods, or route handlers
- Identify the "surface area" of the component
### Step 2: Follow the Code Path
- Trace function calls step by step
- Read each file involved in the flow
- Note where data is transformed
- Identify external dependencies
- Take time to deeply understand how all these pieces connect and interact
### Step 3: Understand Key Logic
- Focus on business logic, not boilerplate
- Identify validation, transformation, error handling
- Note any complex algorithms or calculations
- Look for configuration or feature flags
## Important Guidelines
- **Always include file:line references** for claims
- **Read files thoroughly** before making statements
- **Trace actual code paths** don't assume
- **Focus on "how"** not "what" or "why"
- **Be precise** about function names and variables
- **Note exact transformations** with before/after
## What NOT to Do
- Don't guess about implementation
- Don't skip error handling or edge cases
- Don't ignore configuration or dependencies
- Don't make architectural recommendations
- Don't analyze code quality or suggest improvements
Remember: You're explaining HOW the code currently works, with surgical precision and exact references. Help users understand the implementation as it exists today.`,
instructionsPrompt: `Analyze the requested component or feature in detail. Follow this structure:
## Analysis: [Feature/Component Name]
### Overview
[2-3 sentence summary of how it works]
### Entry Points
- \`file.js:45\` - Function or endpoint description
- \`handler.js:12\` - Key method description
### Core Implementation
#### 1. [Step Name] (\`file.js:15-32\`)
- Detailed explanation with exact line references
- What happens at each step
- Any validation or error handling
#### 2. [Next Step] (\`service.js:8-45\`)
- Continue tracing the flow
- Note data transformations
- Identify side effects
### Data Flow
1. Entry at \`file.js:45\`
2. Processing at \`handler.js:12\`
3. Storage at \`store.js:55\`
### Key Patterns
- **Pattern Name**: Description with file references
- **Architecture**: How components interact
### Configuration
- Settings locations with file:line references
- Feature flags and their effects
### Error Handling
- How errors are caught and handled
- Retry logic and fallbacks
Use the read_files, code_search, and find_files tools to gather information, then provide a comprehensive analysis with exact file:line references.`,
stepPrompt: `Focus on understanding HOW the code works. Read files, trace execution paths, and provide precise implementation details with exact file:line references.`,
handleSteps: function* ({
agentState: initialAgentState,
prompt
}) {
let agentState = initialAgentState;
const stepLimit = 15;
let stepCount = 0;
while (!0) {
stepCount++;
const stepResult = yield "STEP";
agentState = stepResult.agentState;
if (stepResult.stepsComplete)
break;
if (stepCount === stepLimit - 1) {
yield {
toolName: "add_message",
input: {
role: "user",
content: "Please finish your analysis now using the exact format specified in your instructions. Make sure to include all required sections: Overview, Entry Points, Core Implementation, Data Flow, Key Patterns, Configuration, and Error Handling with precise file:line references."
},
includeToolCall: !1
};
agentState = (yield "STEP").agentState;
break;
}
}
const lastMessage = agentState.messageHistory[agentState.messageHistory.length - 1];
if (lastMessage?.role === "assistant" && lastMessage.content) {
const content = typeof lastMessage.content === "string" ? lastMessage.content : "";
if (!content.includes("## Analysis:") || !content.includes("### Overview") || !content.includes("### Entry Points")) {
yield {
toolName: "add_message",
input: {
role: "user",
content: `Your analysis must follow the exact format:
## Analysis: [Feature/Component Name]
### Overview
[2-3 sentence summary]
### Entry Points
- \`file.js:45\` - Function description
### Core Implementation
#### 1. [Step Name] (\`file.js:15-32\`)
- Detailed explanation
### Data Flow
1. Entry at \`file.js:45\`
### Key Patterns
- **Pattern Name**: Description
### Configuration
- Settings locations
### Error Handling
- How errors are handled
Please reformat your response to match this structure exactly.`
},
includeToolCall: !1
};
yield "STEP";
}
}
}
}