Skip to content

Commit 2d2cf7e

Browse files
committed
Add Codelayer agent collection
1 parent a2505bc commit 2d2cf7e

23 files changed

+3953
-0
lines changed

.agents/codelayer/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Codelayer Agent Collection
2+
3+
This folder contains the Codelayer collection of specialized agents. Each agent in this collection is designed to work together as part of a cohesive system.
4+
5+
## Agents
6+
7+
- `codelayer-base.ts` - The foundational agent for the Codelayer collection
8+
- `codebase-analyzer.ts` - Analyzes codebase implementation details
9+
- `codebase-locator.ts` - Locates files and directories relevant to features
10+
- `codebase-pattern-finder.ts` - Finds similar implementations and usage patterns
11+
- `thoughts-analyzer.ts` - Analyzes thoughts documents for insights
12+
- `thoughts-locator.ts` - Discovers relevant documents in thoughts/ directory
13+
- `web-search-researcher.ts` - Comprehensive web research specialist
14+
15+
## Getting Started
16+
17+
To use any Codelayer agent:
18+
19+
```bash
20+
codebuff --agent codelayer-base
21+
```
22+
23+
## Purpose
24+
25+
The Codelayer collection is designed to provide specialized functionality for comprehensive codebase analysis, research, and development support. The agents work together to provide deep insights into code structure, patterns, and documentation.
26+
27+
## Adding New Agents
28+
29+
When adding new agents to this collection:
30+
31+
1. Use the publisher: `codelayer`
32+
2. Import shared types from `../types/agent-definition`
33+
3. Update this README with the new agent
34+
4. Follow established naming conventions
35+
36+
Each agent should have a clear, specific purpose within the Codelayer ecosystem.
Lines changed: 342 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,342 @@
1+
import type {
2+
AgentDefinition,
3+
AgentStepContext,
4+
} from '../types/agent-definition'
5+
6+
const definition: AgentDefinition = {
7+
id: 'codebase-analyzer',
8+
publisher: 'codelayer',
9+
displayName: 'CodeBase Analyzer',
10+
model: 'anthropic/claude-4-sonnet-20250522',
11+
12+
spawnerPrompt:
13+
'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! :)',
14+
15+
inputSchema: {
16+
prompt: {
17+
type: 'string',
18+
description:
19+
'What specific component, feature, or implementation details you need analyzed. Be as specific as possible about what you want to understand.',
20+
},
21+
},
22+
23+
outputMode: 'structured_output',
24+
includeMessageHistory: false,
25+
26+
outputSchema: {
27+
type: 'object',
28+
properties: {
29+
title: {
30+
type: 'string',
31+
description: 'Title in format "Analysis: [Feature/Component Name]"',
32+
},
33+
overview: {
34+
type: 'string',
35+
description: '2-3 sentence summary of how it works',
36+
},
37+
entryPoints: {
38+
type: 'array',
39+
description: 'Entry points into the component',
40+
items: {
41+
type: 'object',
42+
properties: {
43+
location: {
44+
type: 'string',
45+
description:
46+
'File path with line number, e.g. "api/routes.js:45"',
47+
},
48+
description: {
49+
type: 'string',
50+
description: 'What this entry point does',
51+
},
52+
},
53+
required: ['location', 'description'],
54+
},
55+
},
56+
coreImplementation: {
57+
type: 'array',
58+
description: 'Detailed breakdown of core implementation steps',
59+
items: {
60+
type: 'object',
61+
properties: {
62+
stepName: {
63+
type: 'string',
64+
description: 'Name of the implementation step',
65+
},
66+
location: {
67+
type: 'string',
68+
description:
69+
'File path with line numbers, e.g. "handlers/webhook.js:15-32"',
70+
},
71+
details: {
72+
type: 'array',
73+
description: 'Detailed explanation points',
74+
items: { type: 'string' },
75+
},
76+
},
77+
required: ['stepName', 'location', 'details'],
78+
},
79+
},
80+
dataFlow: {
81+
type: 'array',
82+
description: 'Step-by-step data flow through the system',
83+
items: {
84+
type: 'object',
85+
properties: {
86+
step: { type: 'number', description: 'Step number in the flow' },
87+
description: {
88+
type: 'string',
89+
description: 'What happens at this step',
90+
},
91+
location: {
92+
type: 'string',
93+
description: 'File path with line number',
94+
},
95+
},
96+
required: ['step', 'description', 'location'],
97+
},
98+
},
99+
keyPatterns: {
100+
type: 'array',
101+
description: 'Key architectural patterns identified',
102+
items: {
103+
type: 'object',
104+
properties: {
105+
patternName: { type: 'string', description: 'Name of the pattern' },
106+
description: {
107+
type: 'string',
108+
description: 'How the pattern is implemented',
109+
},
110+
location: {
111+
type: 'string',
112+
description: 'Where this pattern is found',
113+
},
114+
},
115+
required: ['patternName', 'description'],
116+
},
117+
},
118+
configuration: {
119+
type: 'array',
120+
description: 'Configuration settings and their locations',
121+
items: {
122+
type: 'object',
123+
properties: {
124+
setting: { type: 'string', description: 'What is configured' },
125+
location: {
126+
type: 'string',
127+
description: 'File path with line number',
128+
},
129+
description: {
130+
type: 'string',
131+
description: 'What this configuration controls',
132+
},
133+
},
134+
required: ['setting', 'location', 'description'],
135+
},
136+
},
137+
errorHandling: {
138+
type: 'array',
139+
description: 'Error handling mechanisms',
140+
items: {
141+
type: 'object',
142+
properties: {
143+
errorType: {
144+
type: 'string',
145+
description: 'Type of error or scenario',
146+
},
147+
location: {
148+
type: 'string',
149+
description: 'File path with line number',
150+
},
151+
mechanism: {
152+
type: 'string',
153+
description: 'How the error is handled',
154+
},
155+
},
156+
required: ['errorType', 'location', 'mechanism'],
157+
},
158+
},
159+
},
160+
required: ['title', 'overview'],
161+
},
162+
163+
toolNames: [
164+
'read_files',
165+
'code_search',
166+
'find_files',
167+
'add_message',
168+
'end_turn',
169+
'set_output',
170+
],
171+
spawnableAgents: [],
172+
173+
systemPrompt: `# Persona: CodeBase Analyzer
174+
175+
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.
176+
177+
## Core Responsibilities
178+
179+
1. **Analyze Implementation Details**
180+
- Read specific files to understand logic
181+
- Identify key functions and their purposes
182+
- Trace method calls and data transformations
183+
- Note important algorithms or patterns
184+
185+
2. **Trace Data Flow**
186+
- Follow data from entry to exit points
187+
- Map transformations and validations
188+
- Identify state changes and side effects
189+
- Document API contracts between components
190+
191+
3. **Identify Architectural Patterns**
192+
- Recognize design patterns in use
193+
- Note architectural decisions
194+
- Identify conventions and best practices
195+
- Find integration points between systems
196+
197+
## Analysis Strategy
198+
199+
### Step 1: Read Entry Points
200+
- Start with main files mentioned in the request
201+
- Look for exports, public methods, or route handlers
202+
- Identify the "surface area" of the component
203+
204+
### Step 2: Follow the Code Path
205+
- Trace function calls step by step
206+
- Read each file involved in the flow
207+
- Note where data is transformed
208+
- Identify external dependencies
209+
- Take time to deeply understand how all these pieces connect and interact
210+
211+
### Step 3: Understand Key Logic
212+
- Focus on business logic, not boilerplate
213+
- Identify validation, transformation, error handling
214+
- Note any complex algorithms or calculations
215+
- Look for configuration or feature flags
216+
217+
## Important Guidelines
218+
219+
- **Always include file:line references** for claims
220+
- **Read files thoroughly** before making statements
221+
- **Trace actual code paths** don't assume
222+
- **Focus on "how"** not "what" or "why"
223+
- **Be precise** about function names and variables
224+
- **Note exact transformations** with before/after
225+
226+
## What NOT to Do
227+
228+
- Don't guess about implementation
229+
- Don't skip error handling or edge cases
230+
- Don't ignore configuration or dependencies
231+
- Don't make architectural recommendations
232+
- Don't analyze code quality or suggest improvements
233+
234+
Remember: You're explaining HOW the code currently works, with surgical precision and exact references. Help users understand the implementation as it exists today.`,
235+
236+
instructionsPrompt: `Analyze the requested component or feature in detail. Follow this structure:
237+
238+
## Analysis: [Feature/Component Name]
239+
240+
### Overview
241+
[2-3 sentence summary of how it works]
242+
243+
### Entry Points
244+
- \`file.js:45\` - Function or endpoint description
245+
- \`handler.js:12\` - Key method description
246+
247+
### Core Implementation
248+
249+
#### 1. [Step Name] (\`file.js:15-32\`)
250+
- Detailed explanation with exact line references
251+
- What happens at each step
252+
- Any validation or error handling
253+
254+
#### 2. [Next Step] (\`service.js:8-45\`)
255+
- Continue tracing the flow
256+
- Note data transformations
257+
- Identify side effects
258+
259+
### Data Flow
260+
1. Entry at \`file.js:45\`
261+
2. Processing at \`handler.js:12\`
262+
3. Storage at \`store.js:55\`
263+
264+
### Key Patterns
265+
- **Pattern Name**: Description with file references
266+
- **Architecture**: How components interact
267+
268+
### Configuration
269+
- Settings locations with file:line references
270+
- Feature flags and their effects
271+
272+
### Error Handling
273+
- How errors are caught and handled
274+
- Retry logic and fallbacks
275+
276+
Use the read_files, code_search, and find_files tools to gather information, then provide a comprehensive analysis with exact file:line references.`,
277+
278+
stepPrompt: `Focus on understanding HOW the code works. Read files, trace execution paths, and provide precise implementation details with exact file:line references.`,
279+
280+
handleSteps: function* ({
281+
agentState: initialAgentState,
282+
prompt,
283+
}: AgentStepContext) {
284+
let agentState = initialAgentState
285+
const stepLimit = 15
286+
let stepCount = 0
287+
288+
while (true) {
289+
stepCount++
290+
291+
const stepResult = yield 'STEP'
292+
agentState = stepResult.agentState
293+
294+
if (stepResult.stepsComplete) {
295+
break
296+
}
297+
298+
if (stepCount === stepLimit - 1) {
299+
yield {
300+
toolName: 'add_message',
301+
input: {
302+
role: 'user',
303+
content:
304+
'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.',
305+
},
306+
includeToolCall: false,
307+
}
308+
309+
const finalStepResult = yield 'STEP'
310+
agentState = finalStepResult.agentState
311+
break
312+
}
313+
}
314+
315+
// Final enforcement message if analysis doesn't follow format
316+
const lastMessage =
317+
agentState.messageHistory[agentState.messageHistory.length - 1]
318+
if (lastMessage?.role === 'assistant' && lastMessage.content) {
319+
const content =
320+
typeof lastMessage.content === 'string' ? lastMessage.content : ''
321+
if (
322+
!content.includes('## Analysis:') ||
323+
!content.includes('### Overview') ||
324+
!content.includes('### Entry Points')
325+
) {
326+
yield {
327+
toolName: 'add_message',
328+
input: {
329+
role: 'user',
330+
content:
331+
'Your analysis must follow the exact format:\n\n## Analysis: [Feature/Component Name]\n\n### Overview\n[2-3 sentence summary]\n\n### Entry Points\n- `file.js:45` - Function description\n\n### Core Implementation\n\n#### 1. [Step Name] (`file.js:15-32`)\n- Detailed explanation\n\n### Data Flow\n1. Entry at `file.js:45`\n\n### Key Patterns\n- **Pattern Name**: Description\n\n### Configuration\n- Settings locations\n\n### Error Handling\n- How errors are handled\n\nPlease reformat your response to match this structure exactly.',
332+
},
333+
includeToolCall: false,
334+
}
335+
336+
yield 'STEP'
337+
}
338+
}
339+
},
340+
}
341+
342+
export default definition

0 commit comments

Comments
 (0)