agentic-qe 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/.claude/agents/.claude-flow/metrics/agent-metrics.json +1 -0
  2. package/.claude/agents/.claude-flow/metrics/performance.json +87 -0
  3. package/.claude/agents/.claude-flow/metrics/task-metrics.json +10 -0
  4. package/.claude/agents/qe-api-contract-validator.md +118 -0
  5. package/.claude/agents/qe-chaos-engineer.md +320 -5
  6. package/.claude/agents/qe-code-complexity.md +360 -0
  7. package/.claude/agents/qe-coverage-analyzer.md +112 -0
  8. package/.claude/agents/qe-deployment-readiness.md +322 -6
  9. package/.claude/agents/qe-flaky-test-hunter.md +115 -0
  10. package/.claude/agents/qe-fleet-commander.md +319 -6
  11. package/.claude/agents/qe-performance-tester.md +234 -0
  12. package/.claude/agents/qe-production-intelligence.md +114 -0
  13. package/.claude/agents/qe-quality-analyzer.md +126 -0
  14. package/.claude/agents/qe-quality-gate.md +119 -0
  15. package/.claude/agents/qe-regression-risk-analyzer.md +114 -0
  16. package/.claude/agents/qe-requirements-validator.md +114 -0
  17. package/.claude/agents/qe-security-scanner.md +118 -0
  18. package/.claude/agents/qe-test-data-architect.md +234 -0
  19. package/.claude/agents/qe-test-executor.md +115 -0
  20. package/.claude/agents/qe-test-generator.md +114 -0
  21. package/.claude/agents/qe-visual-tester.md +305 -6
  22. package/.claude/agents/subagents/qe-code-reviewer.md +0 -4
  23. package/.claude/agents/subagents/qe-data-generator.md +0 -16
  24. package/.claude/agents/subagents/qe-integration-tester.md +0 -17
  25. package/.claude/agents/subagents/qe-performance-validator.md +0 -16
  26. package/.claude/agents/subagents/qe-security-auditor.md +0 -16
  27. package/.claude/agents/subagents/qe-test-implementer.md +0 -17
  28. package/.claude/agents/subagents/qe-test-refactorer.md +0 -17
  29. package/.claude/agents/subagents/qe-test-writer.md +0 -19
  30. package/CHANGELOG.md +290 -0
  31. package/README.md +37 -5
  32. package/dist/adapters/MemoryStoreAdapter.d.ts +38 -0
  33. package/dist/adapters/MemoryStoreAdapter.d.ts.map +1 -1
  34. package/dist/adapters/MemoryStoreAdapter.js +22 -0
  35. package/dist/adapters/MemoryStoreAdapter.js.map +1 -1
  36. package/dist/agents/BaseAgent.d.ts.map +1 -1
  37. package/dist/agents/BaseAgent.js +13 -0
  38. package/dist/agents/BaseAgent.js.map +1 -1
  39. package/dist/cli/commands/init.d.ts.map +1 -1
  40. package/dist/cli/commands/init.js +32 -1
  41. package/dist/cli/commands/init.js.map +1 -1
  42. package/dist/core/memory/AgentDBService.d.ts +33 -28
  43. package/dist/core/memory/AgentDBService.d.ts.map +1 -1
  44. package/dist/core/memory/AgentDBService.js +233 -290
  45. package/dist/core/memory/AgentDBService.js.map +1 -1
  46. package/dist/core/memory/EnhancedAgentDBService.d.ts.map +1 -1
  47. package/dist/core/memory/EnhancedAgentDBService.js +5 -3
  48. package/dist/core/memory/EnhancedAgentDBService.js.map +1 -1
  49. package/dist/core/memory/RealAgentDBAdapter.d.ts +9 -2
  50. package/dist/core/memory/RealAgentDBAdapter.d.ts.map +1 -1
  51. package/dist/core/memory/RealAgentDBAdapter.js +126 -100
  52. package/dist/core/memory/RealAgentDBAdapter.js.map +1 -1
  53. package/dist/core/memory/SwarmMemoryManager.d.ts +58 -0
  54. package/dist/core/memory/SwarmMemoryManager.d.ts.map +1 -1
  55. package/dist/core/memory/SwarmMemoryManager.js +176 -0
  56. package/dist/core/memory/SwarmMemoryManager.js.map +1 -1
  57. package/dist/core/memory/index.d.ts.map +1 -1
  58. package/dist/core/memory/index.js +2 -1
  59. package/dist/core/memory/index.js.map +1 -1
  60. package/dist/learning/LearningEngine.d.ts +14 -27
  61. package/dist/learning/LearningEngine.d.ts.map +1 -1
  62. package/dist/learning/LearningEngine.js +57 -119
  63. package/dist/learning/LearningEngine.js.map +1 -1
  64. package/dist/learning/index.d.ts +0 -1
  65. package/dist/learning/index.d.ts.map +1 -1
  66. package/dist/learning/index.js +0 -1
  67. package/dist/learning/index.js.map +1 -1
  68. package/dist/mcp/handlers/learning/learning-query.d.ts +34 -0
  69. package/dist/mcp/handlers/learning/learning-query.d.ts.map +1 -0
  70. package/dist/mcp/handlers/learning/learning-query.js +156 -0
  71. package/dist/mcp/handlers/learning/learning-query.js.map +1 -0
  72. package/dist/mcp/handlers/learning/learning-store-experience.d.ts +30 -0
  73. package/dist/mcp/handlers/learning/learning-store-experience.d.ts.map +1 -0
  74. package/dist/mcp/handlers/learning/learning-store-experience.js +86 -0
  75. package/dist/mcp/handlers/learning/learning-store-experience.js.map +1 -0
  76. package/dist/mcp/handlers/learning/learning-store-pattern.d.ts +31 -0
  77. package/dist/mcp/handlers/learning/learning-store-pattern.d.ts.map +1 -0
  78. package/dist/mcp/handlers/learning/learning-store-pattern.js +126 -0
  79. package/dist/mcp/handlers/learning/learning-store-pattern.js.map +1 -0
  80. package/dist/mcp/handlers/learning/learning-store-qvalue.d.ts +30 -0
  81. package/dist/mcp/handlers/learning/learning-store-qvalue.d.ts.map +1 -0
  82. package/dist/mcp/handlers/learning/learning-store-qvalue.js +100 -0
  83. package/dist/mcp/handlers/learning/learning-store-qvalue.js.map +1 -0
  84. package/dist/mcp/server.d.ts +11 -0
  85. package/dist/mcp/server.d.ts.map +1 -1
  86. package/dist/mcp/server.js +98 -1
  87. package/dist/mcp/server.js.map +1 -1
  88. package/dist/mcp/services/LearningEventListener.d.ts +123 -0
  89. package/dist/mcp/services/LearningEventListener.d.ts.map +1 -0
  90. package/dist/mcp/services/LearningEventListener.js +322 -0
  91. package/dist/mcp/services/LearningEventListener.js.map +1 -0
  92. package/dist/mcp/tools/qe/security/scan-comprehensive.d.ts.map +1 -1
  93. package/dist/mcp/tools/qe/security/scan-comprehensive.js +40 -18
  94. package/dist/mcp/tools/qe/security/scan-comprehensive.js.map +1 -1
  95. package/dist/mcp/tools.d.ts +4 -0
  96. package/dist/mcp/tools.d.ts.map +1 -1
  97. package/dist/mcp/tools.js +179 -0
  98. package/dist/mcp/tools.js.map +1 -1
  99. package/dist/types/memory-interfaces.d.ts +71 -0
  100. package/dist/types/memory-interfaces.d.ts.map +1 -1
  101. package/dist/utils/Calculator.d.ts +35 -0
  102. package/dist/utils/Calculator.d.ts.map +1 -0
  103. package/dist/utils/Calculator.js +50 -0
  104. package/dist/utils/Calculator.js.map +1 -0
  105. package/dist/utils/Logger.d.ts.map +1 -1
  106. package/dist/utils/Logger.js +4 -1
  107. package/dist/utils/Logger.js.map +1 -1
  108. package/package.json +7 -5
  109. package/.claude/agents/qe-api-contract-validator.md.backup +0 -1148
  110. package/.claude/agents/qe-api-contract-validator.md.backup-20251107-134747 +0 -1148
  111. package/.claude/agents/qe-api-contract-validator.md.backup-phase2-20251107-140039 +0 -1123
  112. package/.claude/agents/qe-chaos-engineer.md.backup +0 -808
  113. package/.claude/agents/qe-chaos-engineer.md.backup-20251107-134747 +0 -808
  114. package/.claude/agents/qe-chaos-engineer.md.backup-phase2-20251107-140039 +0 -787
  115. package/.claude/agents/qe-code-complexity.md.backup +0 -291
  116. package/.claude/agents/qe-code-complexity.md.backup-20251107-134747 +0 -291
  117. package/.claude/agents/qe-code-complexity.md.backup-phase2-20251107-140039 +0 -286
  118. package/.claude/agents/qe-coverage-analyzer.md.backup +0 -467
  119. package/.claude/agents/qe-coverage-analyzer.md.backup-20251107-134747 +0 -467
  120. package/.claude/agents/qe-coverage-analyzer.md.backup-phase2-20251107-140039 +0 -438
  121. package/.claude/agents/qe-deployment-readiness.md.backup +0 -1166
  122. package/.claude/agents/qe-deployment-readiness.md.backup-20251107-134747 +0 -1166
  123. package/.claude/agents/qe-deployment-readiness.md.backup-phase2-20251107-140039 +0 -1140
  124. package/.claude/agents/qe-flaky-test-hunter.md.backup +0 -1195
  125. package/.claude/agents/qe-flaky-test-hunter.md.backup-20251107-134747 +0 -1195
  126. package/.claude/agents/qe-flaky-test-hunter.md.backup-phase2-20251107-140039 +0 -1162
  127. package/.claude/agents/qe-fleet-commander.md.backup +0 -718
  128. package/.claude/agents/qe-fleet-commander.md.backup-20251107-134747 +0 -718
  129. package/.claude/agents/qe-fleet-commander.md.backup-phase2-20251107-140039 +0 -697
  130. package/.claude/agents/qe-performance-tester.md.backup +0 -428
  131. package/.claude/agents/qe-performance-tester.md.backup-20251107-134747 +0 -428
  132. package/.claude/agents/qe-performance-tester.md.backup-phase2-20251107-140039 +0 -372
  133. package/.claude/agents/qe-production-intelligence.md.backup +0 -1219
  134. package/.claude/agents/qe-production-intelligence.md.backup-20251107-134747 +0 -1219
  135. package/.claude/agents/qe-production-intelligence.md.backup-phase2-20251107-140039 +0 -1194
  136. package/.claude/agents/qe-quality-analyzer.md.backup +0 -425
  137. package/.claude/agents/qe-quality-analyzer.md.backup-20251107-134747 +0 -425
  138. package/.claude/agents/qe-quality-analyzer.md.backup-phase2-20251107-140039 +0 -394
  139. package/.claude/agents/qe-quality-gate.md.backup +0 -446
  140. package/.claude/agents/qe-quality-gate.md.backup-20251107-134747 +0 -446
  141. package/.claude/agents/qe-quality-gate.md.backup-phase2-20251107-140039 +0 -415
  142. package/.claude/agents/qe-regression-risk-analyzer.md.backup +0 -1009
  143. package/.claude/agents/qe-regression-risk-analyzer.md.backup-20251107-134747 +0 -1009
  144. package/.claude/agents/qe-regression-risk-analyzer.md.backup-phase2-20251107-140039 +0 -984
  145. package/.claude/agents/qe-requirements-validator.md.backup +0 -748
  146. package/.claude/agents/qe-requirements-validator.md.backup-20251107-134747 +0 -748
  147. package/.claude/agents/qe-requirements-validator.md.backup-phase2-20251107-140039 +0 -723
  148. package/.claude/agents/qe-security-scanner.md.backup +0 -634
  149. package/.claude/agents/qe-security-scanner.md.backup-20251107-134747 +0 -634
  150. package/.claude/agents/qe-security-scanner.md.backup-phase2-20251107-140039 +0 -573
  151. package/.claude/agents/qe-test-data-architect.md.backup +0 -1064
  152. package/.claude/agents/qe-test-data-architect.md.backup-20251107-134747 +0 -1064
  153. package/.claude/agents/qe-test-data-architect.md.backup-phase2-20251107-140039 +0 -1040
  154. package/.claude/agents/qe-test-executor.md.backup +0 -389
  155. package/.claude/agents/qe-test-executor.md.backup-20251107-134747 +0 -389
  156. package/.claude/agents/qe-test-executor.md.backup-phase2-20251107-140039 +0 -369
  157. package/.claude/agents/qe-test-generator.md.backup +0 -997
  158. package/.claude/agents/qe-test-generator.md.backup-20251107-134747 +0 -997
  159. package/.claude/agents/qe-visual-tester.md.backup +0 -777
  160. package/.claude/agents/qe-visual-tester.md.backup-20251107-134747 +0 -777
  161. package/.claude/agents/qe-visual-tester.md.backup-phase2-20251107-140039 +0 -756
@@ -1,291 +0,0 @@
1
- ---
2
- name: qe-code-complexity
3
- version: 1.0.0
4
- description: Educational code complexity analyzer demonstrating the Agentic QE Fleet architecture
5
- tags: [quality-engineering, complexity-analysis, refactoring, learning-example]
6
- capabilities: [complexity-analysis, refactoring-recommendations, pattern-detection]
7
- type: quality-analyzer
8
- ---
9
-
10
- # QE Code Complexity Analyzer
11
-
12
- ## Overview
13
-
14
- The Code Complexity Analyzer is an **educational agent** that demonstrates the complete Agentic QE Fleet architecture. It analyzes code complexity metrics and provides AI-powered refactoring recommendations.
15
-
16
- **Purpose**: Learning tool to understand how agents work in the AQE fleet.
17
-
18
- ## Capabilities
19
-
20
- ### 1. Complexity Analysis
21
- - **Cyclomatic Complexity**: Measures decision point density
22
- - **Cognitive Complexity**: Accounts for nesting and control flow
23
- - **File Size Analysis**: Identifies overly large files
24
- - **Function Metrics**: Tracks function count and average complexity
25
-
26
- ### 2. Refactoring Recommendations
27
- - AI-powered suggestions based on detected patterns
28
- - Severity-based prioritization (low, medium, high, critical)
29
- - Specific actionable advice (e.g., "Extract Method", "Reduce Nesting")
30
-
31
- ### 3. Quality Scoring
32
- - Holistic quality score (0-100)
33
- - Issue-based deductions
34
- - Helps prioritize refactoring efforts
35
-
36
- ## Key Learning Concepts
37
-
38
- ### BaseAgent Pattern
39
- ```typescript
40
- // All agents extend BaseAgent
41
- export class CodeComplexityAnalyzerAgent extends BaseAgent {
42
- // Define capabilities in constructor
43
- constructor(config: CodeComplexityConfig) {
44
- super({
45
- ...config,
46
- type: QEAgentType.QUALITY_ANALYZER,
47
- capabilities: [/* ... */]
48
- });
49
- }
50
- }
51
- ```
52
-
53
- ### Lifecycle Hooks
54
- ```typescript
55
- // Pre-task: Load context before work
56
- protected async onPreTask(data: { assignment: any }): Promise<void> {
57
- const history = await this.memoryStore.retrieve('aqe/complexity/.../history');
58
- // Use historical data to improve analysis
59
- }
60
-
61
- // Post-task: Store results and coordinate
62
- protected async onPostTask(data: PostTaskData): Promise<void> {
63
- await this.memoryStore.store('aqe/complexity/.../results', data.result);
64
- this.eventBus.emit('complexity:analysis:completed', { ... });
65
- }
66
-
67
- // Error handling: Learn from failures
68
- protected async onTaskError(data: { assignment: any; error: Error }): Promise<void> {
69
- await this.memoryStore.store('aqe/complexity/.../errors/...', { ... });
70
- }
71
- ```
72
-
73
- ### Memory System
74
- ```typescript
75
- // Store results for other agents
76
- await this.memoryStore.store(
77
- 'aqe/complexity/${agentId}/latest-result',
78
- result,
79
- 86400 // 24 hour TTL
80
- );
81
-
82
- // Retrieve for coordination
83
- const previous = await this.memoryStore.retrieve(
84
- 'aqe/complexity/${agentId}/history'
85
- );
86
- ```
87
-
88
- ### Event-Driven Architecture
89
- ```typescript
90
- // Emit events for coordination
91
- this.eventBus.emit('complexity:analysis:completed', {
92
- agentId: this.agentId,
93
- result: analysisResult,
94
- timestamp: new Date()
95
- });
96
-
97
- // Other agents can subscribe
98
- eventBus.on('complexity:analysis:completed', (event) => {
99
- // Test generator could prioritize complex code
100
- // Coverage analyzer could focus on complex functions
101
- });
102
- ```
103
-
104
- ## Usage Examples
105
-
106
- ### From Claude Code CLI
107
-
108
- ```bash
109
- # Analyze a single file
110
- claude "Use qe-code-complexity to analyze src/services/order-processor.ts"
111
-
112
- # Analyze multiple files
113
- claude "Run complexity analysis on all files in src/services/"
114
-
115
- # Get refactoring recommendations
116
- claude "Analyze src/utils/validator.ts and suggest refactorings"
117
- ```
118
-
119
- ### Via TypeScript
120
-
121
- ```typescript
122
- import { CodeComplexityAnalyzerAgent } from './agents/CodeComplexityAnalyzerAgent';
123
-
124
- // Initialize agent
125
- const agent = new CodeComplexityAnalyzerAgent({
126
- type: QEAgentType.QUALITY_ANALYZER,
127
- capabilities: [],
128
- context: { /* ... */ },
129
- memoryStore,
130
- eventBus,
131
- thresholds: {
132
- cyclomaticComplexity: 10,
133
- cognitiveComplexity: 15,
134
- linesOfCode: 300
135
- },
136
- enableRecommendations: true
137
- });
138
-
139
- await agent.initialize();
140
-
141
- // Analyze code
142
- const result = await agent.analyzeComplexity({
143
- files: [{
144
- path: 'complex.ts',
145
- content: sourceCode,
146
- language: 'typescript'
147
- }]
148
- });
149
-
150
- console.log('Quality Score:', result.score);
151
- console.log('Issues:', result.issues);
152
- console.log('Recommendations:', result.recommendations);
153
- ```
154
-
155
- ## Configuration
156
-
157
- ### Thresholds
158
-
159
- Customize complexity thresholds:
160
-
161
- ```typescript
162
- {
163
- thresholds: {
164
- cyclomaticComplexity: 10, // Default: 10
165
- cognitiveComplexity: 15, // Default: 15
166
- linesOfCode: 300 // Default: 300
167
- }
168
- }
169
- ```
170
-
171
- ### Features
172
-
173
- ```typescript
174
- {
175
- enableRecommendations: true, // Default: true
176
- enableLearning: true // Default: false (demo uses false)
177
- }
178
- ```
179
-
180
- ## Integration with Other Agents
181
-
182
- ### Test Generator
183
- The test-generator agent can use complexity analysis to:
184
- - Prioritize complex functions for testing
185
- - Generate more comprehensive tests for high-complexity code
186
- - Focus on edge cases in nested logic
187
-
188
- ```typescript
189
- eventBus.on('complexity:analysis:completed', async (event) => {
190
- if (event.result.issues.some(i => i.severity === 'critical')) {
191
- // Test generator: Create extra tests for critical complexity
192
- await testGeneratorAgent.generateTests({
193
- focusAreas: event.result.issues
194
- .filter(i => i.severity === 'critical')
195
- .map(i => i.file)
196
- });
197
- }
198
- });
199
- ```
200
-
201
- ### Coverage Analyzer
202
- The coverage-analyzer can use complexity data to:
203
- - Ensure high-complexity code has high coverage
204
- - Identify risk areas (high complexity + low coverage)
205
-
206
- ### Quality Gate
207
- The quality-gate can use complexity metrics as criteria:
208
- - Fail builds with critical complexity issues
209
- - Track complexity trends over time
210
- - Prevent complexity regressions
211
-
212
- ## Example Output
213
-
214
- ```
215
- Quality Score: 65/100
216
-
217
- ⚠️ Issues Detected:
218
- 1. [HIGH] cyclomatic
219
- Current: 23, Threshold: 10
220
- Consider breaking down complex logic into smaller functions
221
-
222
- 2. [MEDIUM] cognitive
223
- Current: 18, Threshold: 15
224
- Reduce nesting levels and simplify control flow
225
-
226
- 💡 Recommendations:
227
- 1. Apply Extract Method refactoring to reduce cyclomatic complexity
228
- 2. Use early returns to reduce nesting levels
229
- 3. Extract nested loops into separate methods
230
- ```
231
-
232
- ## Learning Objectives
233
-
234
- By studying this agent, you'll learn:
235
-
236
- 1. ✅ **BaseAgent Pattern**: How to extend and customize agents
237
- 2. ✅ **Lifecycle Hooks**: Pre-task, post-task, and error handling
238
- 3. ✅ **Memory System**: Storing and retrieving agent data
239
- 4. ✅ **Event System**: Coordinating multiple agents
240
- 5. ✅ **Testing Patterns**: Comprehensive test coverage
241
- 6. ✅ **Agent Coordination**: How agents work together
242
-
243
- ## Running the Example
244
-
245
- ```bash
246
- # Run the demo
247
- npx ts-node examples/complexity-analysis/demo.ts
248
-
249
- # Run tests
250
- npm test tests/agents/CodeComplexityAnalyzerAgent.test.ts
251
- ```
252
-
253
- ## Architecture Insights
254
-
255
- ### Memory Namespace
256
- - `aqe/complexity/${agentId}/current-request` - Active analysis request
257
- - `aqe/complexity/${agentId}/latest-result` - Most recent result
258
- - `aqe/complexity/${agentId}/history` - Historical analyses (last 100)
259
- - `aqe/complexity/${agentId}/errors/*` - Error tracking
260
-
261
- ### Events Emitted
262
- - `complexity:analysis:completed` - When analysis finishes successfully
263
- - `complexity:analysis:stored` - When results are persisted
264
-
265
- ### Capabilities Provided
266
- - `complexity-analysis` - Core analysis functionality
267
- - `refactoring-recommendations` - AI-powered suggestions
268
- - `pattern-detection` - Complex code pattern recognition
269
-
270
- ## Next Steps
271
-
272
- After understanding this agent, explore:
273
- - **TestGeneratorAgent**: See how it generates tests
274
- - **CoverageAnalyzerAgent**: Learn about O(log n) gap detection
275
- - **FleetManager**: Understand multi-agent coordination
276
- - **LearningEngine**: Discover how agents improve over time
277
-
278
- ## Resources
279
-
280
- - **Source Code**: `src/agents/CodeComplexityAnalyzerAgent.ts`
281
- - **Tests**: `tests/agents/CodeComplexityAnalyzerAgent.test.ts`
282
- - **Demo**: `examples/complexity-analysis/demo.ts`
283
- - **BaseAgent**: `src/agents/BaseAgent.ts`
284
-
285
- ---
286
-
287
- **Educational Agent**: This agent is designed for learning. For production complexity analysis, consider:
288
- - ESLint with complexity rules
289
- - SonarQube
290
- - CodeClimate
291
- - Commercial static analysis tools
@@ -1,291 +0,0 @@
1
- ---
2
- name: qe-code-complexity
3
- version: 1.0.0
4
- description: Educational code complexity analyzer demonstrating the Agentic QE Fleet architecture
5
- tags: [quality-engineering, complexity-analysis, refactoring, learning-example]
6
- capabilities: [complexity-analysis, refactoring-recommendations, pattern-detection]
7
- type: quality-analyzer
8
- ---
9
-
10
- # QE Code Complexity Analyzer
11
-
12
- ## Overview
13
-
14
- The Code Complexity Analyzer is an **educational agent** that demonstrates the complete Agentic QE Fleet architecture. It analyzes code complexity metrics and provides AI-powered refactoring recommendations.
15
-
16
- **Purpose**: Learning tool to understand how agents work in the AQE fleet.
17
-
18
- ## Capabilities
19
-
20
- ### 1. Complexity Analysis
21
- - **Cyclomatic Complexity**: Measures decision point density
22
- - **Cognitive Complexity**: Accounts for nesting and control flow
23
- - **File Size Analysis**: Identifies overly large files
24
- - **Function Metrics**: Tracks function count and average complexity
25
-
26
- ### 2. Refactoring Recommendations
27
- - AI-powered suggestions based on detected patterns
28
- - Severity-based prioritization (low, medium, high, critical)
29
- - Specific actionable advice (e.g., "Extract Method", "Reduce Nesting")
30
-
31
- ### 3. Quality Scoring
32
- - Holistic quality score (0-100)
33
- - Issue-based deductions
34
- - Helps prioritize refactoring efforts
35
-
36
- ## Key Learning Concepts
37
-
38
- ### BaseAgent Pattern
39
- ```typescript
40
- // All agents extend BaseAgent
41
- export class CodeComplexityAnalyzerAgent extends BaseAgent {
42
- // Define capabilities in constructor
43
- constructor(config: CodeComplexityConfig) {
44
- super({
45
- ...config,
46
- type: QEAgentType.QUALITY_ANALYZER,
47
- capabilities: [/* ... */]
48
- });
49
- }
50
- }
51
- ```
52
-
53
- ### Lifecycle Hooks
54
- ```typescript
55
- // Pre-task: Load context before work
56
- protected async onPreTask(data: { assignment: any }): Promise<void> {
57
- const history = await this.memoryStore.retrieve('aqe/complexity/.../history');
58
- // Use historical data to improve analysis
59
- }
60
-
61
- // Post-task: Store results and coordinate
62
- protected async onPostTask(data: PostTaskData): Promise<void> {
63
- await this.memoryStore.store('aqe/complexity/.../results', data.result);
64
- this.eventBus.emit('complexity:analysis:completed', { ... });
65
- }
66
-
67
- // Error handling: Learn from failures
68
- protected async onTaskError(data: { assignment: any; error: Error }): Promise<void> {
69
- await this.memoryStore.store('aqe/complexity/.../errors/...', { ... });
70
- }
71
- ```
72
-
73
- ### Memory System
74
- ```typescript
75
- // Store results for other agents
76
- await this.memoryStore.store(
77
- 'aqe/complexity/${agentId}/latest-result',
78
- result,
79
- 86400 // 24 hour TTL
80
- );
81
-
82
- // Retrieve for coordination
83
- const previous = await this.memoryStore.retrieve(
84
- 'aqe/complexity/${agentId}/history'
85
- );
86
- ```
87
-
88
- ### Event-Driven Architecture
89
- ```typescript
90
- // Emit events for coordination
91
- this.eventBus.emit('complexity:analysis:completed', {
92
- agentId: this.agentId,
93
- result: analysisResult,
94
- timestamp: new Date()
95
- });
96
-
97
- // Other agents can subscribe
98
- eventBus.on('complexity:analysis:completed', (event) => {
99
- // Test generator could prioritize complex code
100
- // Coverage analyzer could focus on complex functions
101
- });
102
- ```
103
-
104
- ## Usage Examples
105
-
106
- ### From Claude Code CLI
107
-
108
- ```bash
109
- # Analyze a single file
110
- claude "Use qe-code-complexity to analyze src/services/order-processor.ts"
111
-
112
- # Analyze multiple files
113
- claude "Run complexity analysis on all files in src/services/"
114
-
115
- # Get refactoring recommendations
116
- claude "Analyze src/utils/validator.ts and suggest refactorings"
117
- ```
118
-
119
- ### Via TypeScript
120
-
121
- ```typescript
122
- import { CodeComplexityAnalyzerAgent } from './agents/CodeComplexityAnalyzerAgent';
123
-
124
- // Initialize agent
125
- const agent = new CodeComplexityAnalyzerAgent({
126
- type: QEAgentType.QUALITY_ANALYZER,
127
- capabilities: [],
128
- context: { /* ... */ },
129
- memoryStore,
130
- eventBus,
131
- thresholds: {
132
- cyclomaticComplexity: 10,
133
- cognitiveComplexity: 15,
134
- linesOfCode: 300
135
- },
136
- enableRecommendations: true
137
- });
138
-
139
- await agent.initialize();
140
-
141
- // Analyze code
142
- const result = await agent.analyzeComplexity({
143
- files: [{
144
- path: 'complex.ts',
145
- content: sourceCode,
146
- language: 'typescript'
147
- }]
148
- });
149
-
150
- console.log('Quality Score:', result.score);
151
- console.log('Issues:', result.issues);
152
- console.log('Recommendations:', result.recommendations);
153
- ```
154
-
155
- ## Configuration
156
-
157
- ### Thresholds
158
-
159
- Customize complexity thresholds:
160
-
161
- ```typescript
162
- {
163
- thresholds: {
164
- cyclomaticComplexity: 10, // Default: 10
165
- cognitiveComplexity: 15, // Default: 15
166
- linesOfCode: 300 // Default: 300
167
- }
168
- }
169
- ```
170
-
171
- ### Features
172
-
173
- ```typescript
174
- {
175
- enableRecommendations: true, // Default: true
176
- enableLearning: true // Default: false (demo uses false)
177
- }
178
- ```
179
-
180
- ## Integration with Other Agents
181
-
182
- ### Test Generator
183
- The test-generator agent can use complexity analysis to:
184
- - Prioritize complex functions for testing
185
- - Generate more comprehensive tests for high-complexity code
186
- - Focus on edge cases in nested logic
187
-
188
- ```typescript
189
- eventBus.on('complexity:analysis:completed', async (event) => {
190
- if (event.result.issues.some(i => i.severity === 'critical')) {
191
- // Test generator: Create extra tests for critical complexity
192
- await testGeneratorAgent.generateTests({
193
- focusAreas: event.result.issues
194
- .filter(i => i.severity === 'critical')
195
- .map(i => i.file)
196
- });
197
- }
198
- });
199
- ```
200
-
201
- ### Coverage Analyzer
202
- The coverage-analyzer can use complexity data to:
203
- - Ensure high-complexity code has high coverage
204
- - Identify risk areas (high complexity + low coverage)
205
-
206
- ### Quality Gate
207
- The quality-gate can use complexity metrics as criteria:
208
- - Fail builds with critical complexity issues
209
- - Track complexity trends over time
210
- - Prevent complexity regressions
211
-
212
- ## Example Output
213
-
214
- ```
215
- Quality Score: 65/100
216
-
217
- ⚠️ Issues Detected:
218
- 1. [HIGH] cyclomatic
219
- Current: 23, Threshold: 10
220
- Consider breaking down complex logic into smaller functions
221
-
222
- 2. [MEDIUM] cognitive
223
- Current: 18, Threshold: 15
224
- Reduce nesting levels and simplify control flow
225
-
226
- 💡 Recommendations:
227
- 1. Apply Extract Method refactoring to reduce cyclomatic complexity
228
- 2. Use early returns to reduce nesting levels
229
- 3. Extract nested loops into separate methods
230
- ```
231
-
232
- ## Learning Objectives
233
-
234
- By studying this agent, you'll learn:
235
-
236
- 1. ✅ **BaseAgent Pattern**: How to extend and customize agents
237
- 2. ✅ **Lifecycle Hooks**: Pre-task, post-task, and error handling
238
- 3. ✅ **Memory System**: Storing and retrieving agent data
239
- 4. ✅ **Event System**: Coordinating multiple agents
240
- 5. ✅ **Testing Patterns**: Comprehensive test coverage
241
- 6. ✅ **Agent Coordination**: How agents work together
242
-
243
- ## Running the Example
244
-
245
- ```bash
246
- # Run the demo
247
- npx ts-node examples/complexity-analysis/demo.ts
248
-
249
- # Run tests
250
- npm test tests/agents/CodeComplexityAnalyzerAgent.test.ts
251
- ```
252
-
253
- ## Architecture Insights
254
-
255
- ### Memory Namespace
256
- - `aqe/complexity/${agentId}/current-request` - Active analysis request
257
- - `aqe/complexity/${agentId}/latest-result` - Most recent result
258
- - `aqe/complexity/${agentId}/history` - Historical analyses (last 100)
259
- - `aqe/complexity/${agentId}/errors/*` - Error tracking
260
-
261
- ### Events Emitted
262
- - `complexity:analysis:completed` - When analysis finishes successfully
263
- - `complexity:analysis:stored` - When results are persisted
264
-
265
- ### Capabilities Provided
266
- - `complexity-analysis` - Core analysis functionality
267
- - `refactoring-recommendations` - AI-powered suggestions
268
- - `pattern-detection` - Complex code pattern recognition
269
-
270
- ## Next Steps
271
-
272
- After understanding this agent, explore:
273
- - **TestGeneratorAgent**: See how it generates tests
274
- - **CoverageAnalyzerAgent**: Learn about O(log n) gap detection
275
- - **FleetManager**: Understand multi-agent coordination
276
- - **LearningEngine**: Discover how agents improve over time
277
-
278
- ## Resources
279
-
280
- - **Source Code**: `src/agents/CodeComplexityAnalyzerAgent.ts`
281
- - **Tests**: `tests/agents/CodeComplexityAnalyzerAgent.test.ts`
282
- - **Demo**: `examples/complexity-analysis/demo.ts`
283
- - **BaseAgent**: `src/agents/BaseAgent.ts`
284
-
285
- ---
286
-
287
- **Educational Agent**: This agent is designed for learning. For production complexity analysis, consider:
288
- - ESLint with complexity rules
289
- - SonarQube
290
- - CodeClimate
291
- - Commercial static analysis tools