agentic-qe 1.9.4 → 2.1.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.
- package/.claude/agents/qe-api-contract-validator.md +95 -1336
- package/.claude/agents/qe-chaos-engineer.md +152 -1211
- package/.claude/agents/qe-code-complexity.md +144 -707
- package/.claude/agents/qe-coverage-analyzer.md +147 -743
- package/.claude/agents/qe-deployment-readiness.md +143 -1496
- package/.claude/agents/qe-flaky-test-hunter.md +132 -1529
- package/.claude/agents/qe-fleet-commander.md +12 -12
- package/.claude/agents/qe-performance-tester.md +150 -886
- package/.claude/agents/qe-production-intelligence.md +155 -1396
- package/.claude/agents/qe-quality-analyzer.md +6 -6
- package/.claude/agents/qe-quality-gate.md +151 -648
- package/.claude/agents/qe-regression-risk-analyzer.md +132 -1150
- package/.claude/agents/qe-requirements-validator.md +149 -932
- package/.claude/agents/qe-security-scanner.md +157 -797
- package/.claude/agents/qe-test-data-architect.md +96 -1365
- package/.claude/agents/qe-test-executor.md +8 -8
- package/.claude/agents/qe-test-generator.md +145 -1540
- package/.claude/agents/qe-visual-tester.md +153 -1257
- package/.claude/agents/qx-partner.md +248 -0
- package/.claude/agents/subagents/qe-code-reviewer.md +40 -136
- package/.claude/agents/subagents/qe-coverage-gap-analyzer.md +40 -480
- package/.claude/agents/subagents/qe-data-generator.md +41 -125
- package/.claude/agents/subagents/qe-flaky-investigator.md +55 -411
- package/.claude/agents/subagents/qe-integration-tester.md +53 -141
- package/.claude/agents/subagents/qe-performance-validator.md +54 -130
- package/.claude/agents/subagents/qe-security-auditor.md +56 -114
- package/.claude/agents/subagents/qe-test-data-architect-sub.md +57 -548
- package/.claude/agents/subagents/qe-test-implementer.md +58 -551
- package/.claude/agents/subagents/qe-test-refactorer.md +65 -722
- package/.claude/agents/subagents/qe-test-writer.md +63 -726
- package/.claude/skills/accessibility-testing/SKILL.md +144 -692
- package/.claude/skills/agentic-quality-engineering/SKILL.md +176 -529
- package/.claude/skills/api-testing-patterns/SKILL.md +180 -560
- package/.claude/skills/brutal-honesty-review/SKILL.md +113 -603
- package/.claude/skills/bug-reporting-excellence/SKILL.md +116 -517
- package/.claude/skills/chaos-engineering-resilience/SKILL.md +127 -72
- package/.claude/skills/cicd-pipeline-qe-orchestrator/SKILL.md +209 -404
- package/.claude/skills/code-review-quality/SKILL.md +158 -608
- package/.claude/skills/compatibility-testing/SKILL.md +148 -38
- package/.claude/skills/compliance-testing/SKILL.md +132 -63
- package/.claude/skills/consultancy-practices/SKILL.md +114 -446
- package/.claude/skills/context-driven-testing/SKILL.md +117 -381
- package/.claude/skills/contract-testing/SKILL.md +176 -141
- package/.claude/skills/database-testing/SKILL.md +137 -130
- package/.claude/skills/exploratory-testing-advanced/SKILL.md +160 -629
- package/.claude/skills/holistic-testing-pact/SKILL.md +140 -188
- package/.claude/skills/localization-testing/SKILL.md +145 -33
- package/.claude/skills/mobile-testing/SKILL.md +132 -448
- package/.claude/skills/mutation-testing/SKILL.md +147 -41
- package/.claude/skills/performance-testing/SKILL.md +200 -546
- package/.claude/skills/quality-metrics/SKILL.md +164 -519
- package/.claude/skills/refactoring-patterns/SKILL.md +132 -699
- package/.claude/skills/regression-testing/SKILL.md +120 -926
- package/.claude/skills/risk-based-testing/SKILL.md +157 -660
- package/.claude/skills/security-testing/SKILL.md +199 -538
- package/.claude/skills/sherlock-review/SKILL.md +163 -699
- package/.claude/skills/shift-left-testing/SKILL.md +161 -465
- package/.claude/skills/shift-right-testing/SKILL.md +161 -519
- package/.claude/skills/six-thinking-hats/SKILL.md +175 -1110
- package/.claude/skills/skills-manifest.json +683 -0
- package/.claude/skills/tdd-london-chicago/SKILL.md +131 -448
- package/.claude/skills/technical-writing/SKILL.md +103 -154
- package/.claude/skills/test-automation-strategy/SKILL.md +166 -772
- package/.claude/skills/test-data-management/SKILL.md +126 -910
- package/.claude/skills/test-design-techniques/SKILL.md +179 -89
- package/.claude/skills/test-environment-management/SKILL.md +136 -91
- package/.claude/skills/test-reporting-analytics/SKILL.md +169 -92
- package/.claude/skills/testability-scoring/README.md +71 -0
- package/.claude/skills/testability-scoring/SKILL.md +245 -0
- package/.claude/skills/testability-scoring/resources/templates/config.template.js +84 -0
- package/.claude/skills/testability-scoring/resources/templates/testability-scoring.spec.template.js +532 -0
- package/.claude/skills/testability-scoring/scripts/generate-html-report.js +1007 -0
- package/.claude/skills/testability-scoring/scripts/run-assessment.sh +70 -0
- package/.claude/skills/visual-testing-advanced/SKILL.md +155 -78
- package/.claude/skills/xp-practices/SKILL.md +151 -587
- package/CHANGELOG.md +110 -0
- package/README.md +55 -21
- package/dist/agents/QXPartnerAgent.d.ts +146 -0
- package/dist/agents/QXPartnerAgent.d.ts.map +1 -0
- package/dist/agents/QXPartnerAgent.js +1831 -0
- package/dist/agents/QXPartnerAgent.js.map +1 -0
- package/dist/agents/index.d.ts +1 -0
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +82 -2
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/lifecycle/AgentLifecycleManager.d.ts.map +1 -1
- package/dist/agents/lifecycle/AgentLifecycleManager.js +34 -31
- package/dist/agents/lifecycle/AgentLifecycleManager.js.map +1 -1
- package/dist/cli/commands/debug/agent.d.ts.map +1 -1
- package/dist/cli/commands/debug/agent.js +19 -6
- package/dist/cli/commands/debug/agent.js.map +1 -1
- package/dist/cli/commands/debug/health-check.js +20 -7
- package/dist/cli/commands/debug/health-check.js.map +1 -1
- package/dist/cli/commands/init-claude-md-template.d.ts +1 -0
- package/dist/cli/commands/init-claude-md-template.d.ts.map +1 -1
- package/dist/cli/commands/init-claude-md-template.js +18 -3
- package/dist/cli/commands/init-claude-md-template.js.map +1 -1
- package/dist/cli/commands/workflow/cancel.d.ts.map +1 -1
- package/dist/cli/commands/workflow/cancel.js +4 -3
- package/dist/cli/commands/workflow/cancel.js.map +1 -1
- package/dist/cli/commands/workflow/list.d.ts.map +1 -1
- package/dist/cli/commands/workflow/list.js +4 -3
- package/dist/cli/commands/workflow/list.js.map +1 -1
- package/dist/cli/commands/workflow/pause.d.ts.map +1 -1
- package/dist/cli/commands/workflow/pause.js +4 -3
- package/dist/cli/commands/workflow/pause.js.map +1 -1
- package/dist/cli/init/claude-config.d.ts.map +1 -1
- package/dist/cli/init/claude-config.js +3 -8
- package/dist/cli/init/claude-config.js.map +1 -1
- package/dist/cli/init/claude-md.d.ts.map +1 -1
- package/dist/cli/init/claude-md.js +44 -2
- package/dist/cli/init/claude-md.js.map +1 -1
- package/dist/cli/init/database-init.js +1 -1
- package/dist/cli/init/index.d.ts.map +1 -1
- package/dist/cli/init/index.js +13 -6
- package/dist/cli/init/index.js.map +1 -1
- package/dist/cli/init/skills.d.ts.map +1 -1
- package/dist/cli/init/skills.js +2 -1
- package/dist/cli/init/skills.js.map +1 -1
- package/dist/core/SwarmCoordinator.d.ts +180 -0
- package/dist/core/SwarmCoordinator.d.ts.map +1 -0
- package/dist/core/SwarmCoordinator.js +473 -0
- package/dist/core/SwarmCoordinator.js.map +1 -0
- package/dist/core/memory/AgentDBIntegration.d.ts +24 -6
- package/dist/core/memory/AgentDBIntegration.d.ts.map +1 -1
- package/dist/core/memory/AgentDBIntegration.js +66 -10
- package/dist/core/memory/AgentDBIntegration.js.map +1 -1
- package/dist/core/memory/UnifiedMemoryCoordinator.d.ts +341 -0
- package/dist/core/memory/UnifiedMemoryCoordinator.d.ts.map +1 -0
- package/dist/core/memory/UnifiedMemoryCoordinator.js +986 -0
- package/dist/core/memory/UnifiedMemoryCoordinator.js.map +1 -0
- package/dist/core/memory/index.d.ts +5 -0
- package/dist/core/memory/index.d.ts.map +1 -1
- package/dist/core/memory/index.js +23 -1
- package/dist/core/memory/index.js.map +1 -1
- package/dist/core/metrics/MetricsAggregator.d.ts +228 -0
- package/dist/core/metrics/MetricsAggregator.d.ts.map +1 -0
- package/dist/core/metrics/MetricsAggregator.js +482 -0
- package/dist/core/metrics/MetricsAggregator.js.map +1 -0
- package/dist/core/metrics/index.d.ts +5 -0
- package/dist/core/metrics/index.d.ts.map +1 -0
- package/dist/core/metrics/index.js +11 -0
- package/dist/core/metrics/index.js.map +1 -0
- package/dist/core/optimization/SwarmOptimizer.d.ts +190 -0
- package/dist/core/optimization/SwarmOptimizer.d.ts.map +1 -0
- package/dist/core/optimization/SwarmOptimizer.js +648 -0
- package/dist/core/optimization/SwarmOptimizer.js.map +1 -0
- package/dist/core/optimization/index.d.ts +9 -0
- package/dist/core/optimization/index.d.ts.map +1 -0
- package/dist/core/optimization/index.js +25 -0
- package/dist/core/optimization/index.js.map +1 -0
- package/dist/core/optimization/types.d.ts +53 -0
- package/dist/core/optimization/types.d.ts.map +1 -0
- package/dist/core/optimization/types.js +6 -0
- package/dist/core/optimization/types.js.map +1 -0
- package/dist/core/orchestration/AdaptiveScheduler.d.ts +190 -0
- package/dist/core/orchestration/AdaptiveScheduler.d.ts.map +1 -0
- package/dist/core/orchestration/AdaptiveScheduler.js +460 -0
- package/dist/core/orchestration/AdaptiveScheduler.js.map +1 -0
- package/dist/core/orchestration/PriorityQueue.d.ts +54 -0
- package/dist/core/orchestration/PriorityQueue.d.ts.map +1 -0
- package/dist/core/orchestration/PriorityQueue.js +122 -0
- package/dist/core/orchestration/PriorityQueue.js.map +1 -0
- package/dist/core/orchestration/WorkflowOrchestrator.d.ts +189 -0
- package/dist/core/orchestration/WorkflowOrchestrator.d.ts.map +1 -0
- package/dist/core/orchestration/WorkflowOrchestrator.js +845 -0
- package/dist/core/orchestration/WorkflowOrchestrator.js.map +1 -0
- package/dist/core/orchestration/index.d.ts +7 -0
- package/dist/core/orchestration/index.d.ts.map +1 -0
- package/dist/core/orchestration/index.js +11 -0
- package/dist/core/orchestration/index.js.map +1 -0
- package/dist/core/orchestration/types.d.ts +96 -0
- package/dist/core/orchestration/types.d.ts.map +1 -0
- package/dist/core/orchestration/types.js +6 -0
- package/dist/core/orchestration/types.js.map +1 -0
- package/dist/core/recovery/CircuitBreaker.d.ts +176 -0
- package/dist/core/recovery/CircuitBreaker.d.ts.map +1 -0
- package/dist/core/recovery/CircuitBreaker.js +382 -0
- package/dist/core/recovery/CircuitBreaker.js.map +1 -0
- package/dist/core/recovery/RecoveryOrchestrator.d.ts +186 -0
- package/dist/core/recovery/RecoveryOrchestrator.d.ts.map +1 -0
- package/dist/core/recovery/RecoveryOrchestrator.js +476 -0
- package/dist/core/recovery/RecoveryOrchestrator.js.map +1 -0
- package/dist/core/recovery/RetryStrategy.d.ts +127 -0
- package/dist/core/recovery/RetryStrategy.d.ts.map +1 -0
- package/dist/core/recovery/RetryStrategy.js +314 -0
- package/dist/core/recovery/RetryStrategy.js.map +1 -0
- package/dist/core/recovery/index.d.ts +8 -0
- package/dist/core/recovery/index.d.ts.map +1 -0
- package/dist/core/recovery/index.js +27 -0
- package/dist/core/recovery/index.js.map +1 -0
- package/dist/core/skills/DependencyResolver.d.ts +99 -0
- package/dist/core/skills/DependencyResolver.d.ts.map +1 -0
- package/dist/core/skills/DependencyResolver.js +260 -0
- package/dist/core/skills/DependencyResolver.js.map +1 -0
- package/dist/core/skills/DynamicSkillLoader.d.ts +96 -0
- package/dist/core/skills/DynamicSkillLoader.d.ts.map +1 -0
- package/dist/core/skills/DynamicSkillLoader.js +353 -0
- package/dist/core/skills/DynamicSkillLoader.js.map +1 -0
- package/dist/core/skills/ManifestGenerator.d.ts +114 -0
- package/dist/core/skills/ManifestGenerator.d.ts.map +1 -0
- package/dist/core/skills/ManifestGenerator.js +449 -0
- package/dist/core/skills/ManifestGenerator.js.map +1 -0
- package/dist/core/skills/index.d.ts +9 -0
- package/dist/core/skills/index.d.ts.map +1 -0
- package/dist/core/skills/index.js +24 -0
- package/dist/core/skills/index.js.map +1 -0
- package/dist/core/skills/types.d.ts +118 -0
- package/dist/core/skills/types.d.ts.map +1 -0
- package/dist/core/skills/types.js +7 -0
- package/dist/core/skills/types.js.map +1 -0
- package/dist/core/transport/QUICTransport.d.ts +320 -0
- package/dist/core/transport/QUICTransport.d.ts.map +1 -0
- package/dist/core/transport/QUICTransport.js +711 -0
- package/dist/core/transport/QUICTransport.js.map +1 -0
- package/dist/core/transport/index.d.ts +40 -0
- package/dist/core/transport/index.d.ts.map +1 -0
- package/dist/core/transport/index.js +46 -0
- package/dist/core/transport/index.js.map +1 -0
- package/dist/core/transport/quic-loader.d.ts +123 -0
- package/dist/core/transport/quic-loader.d.ts.map +1 -0
- package/dist/core/transport/quic-loader.js +293 -0
- package/dist/core/transport/quic-loader.js.map +1 -0
- package/dist/core/transport/quic.d.ts +154 -0
- package/dist/core/transport/quic.d.ts.map +1 -0
- package/dist/core/transport/quic.js +214 -0
- package/dist/core/transport/quic.js.map +1 -0
- package/dist/mcp/server.d.ts +9 -9
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +1 -2
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/services/AgentRegistry.d.ts.map +1 -1
- package/dist/mcp/services/AgentRegistry.js +4 -1
- package/dist/mcp/services/AgentRegistry.js.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/qx.d.ts +429 -0
- package/dist/types/qx.d.ts.map +1 -0
- package/dist/types/qx.js +71 -0
- package/dist/types/qx.js.map +1 -0
- package/dist/visualization/api/RestEndpoints.js +2 -2
- package/dist/visualization/api/RestEndpoints.js.map +1 -1
- package/dist/visualization/api/WebSocketServer.d.ts +44 -0
- package/dist/visualization/api/WebSocketServer.d.ts.map +1 -1
- package/dist/visualization/api/WebSocketServer.js +144 -23
- package/dist/visualization/api/WebSocketServer.js.map +1 -1
- package/dist/visualization/core/DataTransformer.d.ts +10 -0
- package/dist/visualization/core/DataTransformer.d.ts.map +1 -1
- package/dist/visualization/core/DataTransformer.js +60 -5
- package/dist/visualization/core/DataTransformer.js.map +1 -1
- package/dist/visualization/emit-event.d.ts +75 -0
- package/dist/visualization/emit-event.d.ts.map +1 -0
- package/dist/visualization/emit-event.js +213 -0
- package/dist/visualization/emit-event.js.map +1 -0
- package/dist/visualization/index.d.ts +1 -0
- package/dist/visualization/index.d.ts.map +1 -1
- package/dist/visualization/index.js +7 -1
- package/dist/visualization/index.js.map +1 -1
- package/docs/reference/skills.md +63 -1
- package/package.json +16 -58
|
@@ -1,739 +1,176 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: qe-code-complexity
|
|
3
|
-
description:
|
|
3
|
+
description: AI-powered code complexity analysis with refactoring recommendations
|
|
4
4
|
---
|
|
5
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
// Retrieve for coordination
|
|
79
|
-
const previous = await this.memoryStore.retrieve(
|
|
80
|
-
'aqe/complexity/${agentId}/history'
|
|
81
|
-
);
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### Event-Driven Architecture
|
|
85
|
-
```typescript
|
|
86
|
-
// Emit events for coordination
|
|
87
|
-
this.eventBus.emit('complexity:analysis:completed', {
|
|
88
|
-
agentId: this.agentId,
|
|
89
|
-
result: analysisResult,
|
|
90
|
-
timestamp: new Date()
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// Other agents can subscribe
|
|
94
|
-
eventBus.on('complexity:analysis:completed', (event) => {
|
|
95
|
-
// Test generator could prioritize complex code
|
|
96
|
-
// Coverage analyzer could focus on complex functions
|
|
97
|
-
});
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
## Usage Examples
|
|
101
|
-
|
|
102
|
-
### From Claude Code CLI
|
|
103
|
-
|
|
104
|
-
```bash
|
|
105
|
-
# Analyze a single file
|
|
106
|
-
claude "Use qe-code-complexity to analyze src/services/order-processor.ts"
|
|
107
|
-
|
|
108
|
-
# Analyze multiple files
|
|
109
|
-
claude "Run complexity analysis on all files in src/services/"
|
|
110
|
-
|
|
111
|
-
# Get refactoring recommendations
|
|
112
|
-
claude "Analyze src/utils/validator.ts and suggest refactorings"
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
### Via TypeScript
|
|
116
|
-
|
|
117
|
-
```typescript
|
|
118
|
-
import { CodeComplexityAnalyzerAgent } from './agents/CodeComplexityAnalyzerAgent';
|
|
119
|
-
|
|
120
|
-
// Initialize agent
|
|
121
|
-
const agent = new CodeComplexityAnalyzerAgent({
|
|
122
|
-
type: QEAgentType.QUALITY_ANALYZER,
|
|
123
|
-
capabilities: [],
|
|
124
|
-
context: { /* ... */ },
|
|
125
|
-
memoryStore,
|
|
126
|
-
eventBus,
|
|
127
|
-
thresholds: {
|
|
128
|
-
cyclomaticComplexity: 10,
|
|
129
|
-
cognitiveComplexity: 15,
|
|
130
|
-
linesOfCode: 300
|
|
131
|
-
},
|
|
132
|
-
enableRecommendations: true
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
await agent.initialize();
|
|
136
|
-
|
|
137
|
-
// Analyze code
|
|
138
|
-
const result = await agent.analyzeComplexity({
|
|
139
|
-
files: [{
|
|
140
|
-
path: 'complex.ts',
|
|
141
|
-
content: sourceCode,
|
|
142
|
-
language: 'typescript'
|
|
143
|
-
}]
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
console.log('Quality Score:', result.score);
|
|
147
|
-
console.log('Issues:', result.issues);
|
|
148
|
-
console.log('Recommendations:', result.recommendations);
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
## Configuration
|
|
152
|
-
|
|
153
|
-
### Thresholds
|
|
154
|
-
|
|
155
|
-
Customize complexity thresholds:
|
|
156
|
-
|
|
157
|
-
```typescript
|
|
158
|
-
{
|
|
159
|
-
thresholds: {
|
|
160
|
-
cyclomaticComplexity: 10, // Default: 10
|
|
161
|
-
cognitiveComplexity: 15, // Default: 15
|
|
162
|
-
linesOfCode: 300 // Default: 300
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
### Features
|
|
168
|
-
|
|
169
|
-
```typescript
|
|
170
|
-
{
|
|
171
|
-
enableRecommendations: true, // Default: true
|
|
172
|
-
enableLearning: true // Default: false (demo uses false)
|
|
173
|
-
}
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
## Integration with Other Agents
|
|
177
|
-
|
|
178
|
-
### Test Generator
|
|
179
|
-
The test-generator agent can use complexity analysis to:
|
|
180
|
-
- Prioritize complex functions for testing
|
|
181
|
-
- Generate more comprehensive tests for high-complexity code
|
|
182
|
-
- Focus on edge cases in nested logic
|
|
183
|
-
|
|
184
|
-
```typescript
|
|
185
|
-
eventBus.on('complexity:analysis:completed', async (event) => {
|
|
186
|
-
if (event.result.issues.some(i => i.severity === 'critical')) {
|
|
187
|
-
// Test generator: Create extra tests for critical complexity
|
|
188
|
-
await testGeneratorAgent.generateTests({
|
|
189
|
-
focusAreas: event.result.issues
|
|
190
|
-
.filter(i => i.severity === 'critical')
|
|
191
|
-
.map(i => i.file)
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
### Coverage Analyzer
|
|
198
|
-
The coverage-analyzer can use complexity data to:
|
|
199
|
-
- Ensure high-complexity code has high coverage
|
|
200
|
-
- Identify risk areas (high complexity + low coverage)
|
|
201
|
-
|
|
202
|
-
### Quality Gate
|
|
203
|
-
The quality-gate can use complexity metrics as criteria:
|
|
204
|
-
- Fail builds with critical complexity issues
|
|
205
|
-
- Track complexity trends over time
|
|
206
|
-
- Prevent complexity regressions
|
|
207
|
-
|
|
208
|
-
## Example Output
|
|
209
|
-
|
|
210
|
-
```
|
|
211
|
-
Quality Score: 65/100
|
|
212
|
-
|
|
213
|
-
⚠️ Issues Detected:
|
|
214
|
-
1. [HIGH] cyclomatic
|
|
215
|
-
Current: 23, Threshold: 10
|
|
216
|
-
Consider breaking down complex logic into smaller functions
|
|
217
|
-
|
|
218
|
-
2. [MEDIUM] cognitive
|
|
219
|
-
Current: 18, Threshold: 15
|
|
220
|
-
Reduce nesting levels and simplify control flow
|
|
221
|
-
|
|
222
|
-
💡 Recommendations:
|
|
223
|
-
1. Apply Extract Method refactoring to reduce cyclomatic complexity
|
|
224
|
-
2. Use early returns to reduce nesting levels
|
|
225
|
-
3. Extract nested loops into separate methods
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
## Learning Objectives
|
|
229
|
-
|
|
230
|
-
By studying this agent, you'll learn:
|
|
231
|
-
|
|
232
|
-
1. ✅ **BaseAgent Pattern**: How to extend and customize agents
|
|
233
|
-
2. ✅ **Lifecycle Hooks**: Pre-task, post-task, and error handling
|
|
234
|
-
3. ✅ **Memory System**: Storing and retrieving agent data
|
|
235
|
-
4. ✅ **Event System**: Coordinating multiple agents
|
|
236
|
-
5. ✅ **Testing Patterns**: Comprehensive test coverage
|
|
237
|
-
6. ✅ **Agent Coordination**: How agents work together
|
|
238
|
-
|
|
239
|
-
## Running the Example
|
|
240
|
-
|
|
241
|
-
```bash
|
|
242
|
-
# Run the demo
|
|
243
|
-
npx ts-node examples/complexity-analysis/demo.ts
|
|
244
|
-
|
|
245
|
-
# Run tests
|
|
246
|
-
npm test tests/agents/CodeComplexityAnalyzerAgent.test.ts
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
## Architecture Insights
|
|
250
|
-
|
|
251
|
-
The Code Complexity Analyzer demonstrates the complete agent architecture pattern used throughout the Agentic QE Fleet. This includes:
|
|
252
|
-
|
|
253
|
-
1. **BaseAgent Extension**: Inheriting core capabilities
|
|
254
|
-
2. **Lifecycle Hooks**: Pre-task, post-task, error handling
|
|
255
|
-
3. **Memory System**: Persistent storage and retrieval
|
|
256
|
-
4. **Event Bus**: Coordination with other agents
|
|
257
|
-
5. **Learning Integration**: Continuous improvement through reinforcement learning
|
|
258
|
-
|
|
259
|
-
## Coordination Protocol
|
|
260
|
-
|
|
261
|
-
This agent uses **AQE hooks (Agentic QE native hooks)** for coordination (zero external dependencies, 100-500x faster).
|
|
262
|
-
|
|
263
|
-
**Automatic Lifecycle Hooks:**
|
|
264
|
-
```typescript
|
|
265
|
-
// Called automatically by BaseAgent
|
|
266
|
-
protected async onPreTask(data: { assignment: TaskAssignment }): Promise<void> {
|
|
267
|
-
// Load historical complexity data
|
|
268
|
-
const history = await this.memoryStore.retrieve('aqe/complexity/history', {
|
|
269
|
-
partition: 'metrics'
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
// Retrieve analysis configuration
|
|
273
|
-
const config = await this.memoryStore.retrieve('aqe/complexity/config', {
|
|
274
|
-
partition: 'configuration'
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
// Verify environment for complexity analysis
|
|
278
|
-
const verification = await this.hookManager.executePreTaskVerification({
|
|
279
|
-
task: 'complexity-analysis',
|
|
280
|
-
context: {
|
|
281
|
-
requiredVars: ['NODE_ENV'],
|
|
282
|
-
minMemoryMB: 512,
|
|
283
|
-
requiredKeys: ['aqe/complexity/config']
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
// Emit complexity analysis starting event
|
|
288
|
-
this.eventBus.emit('complexity:analysis:starting', {
|
|
289
|
-
agentId: this.agentId,
|
|
290
|
-
filesCount: data.assignment.task.metadata.filesCount
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
this.logger.info('Complexity analysis starting', {
|
|
294
|
-
filesCount: data.assignment.task.metadata.filesCount,
|
|
295
|
-
verification: verification.passed
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
protected async onPostTask(data: { assignment: TaskAssignment; result: any }): Promise<void> {
|
|
300
|
-
// Store complexity analysis results
|
|
301
|
-
await this.memoryStore.store('aqe/complexity/results', data.result, {
|
|
302
|
-
partition: 'agent_results',
|
|
303
|
-
ttl: 86400 // 24 hours
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
// Store complexity metrics
|
|
307
|
-
await this.memoryStore.store('aqe/complexity/metrics', {
|
|
308
|
-
timestamp: Date.now(),
|
|
309
|
-
score: data.result.score,
|
|
310
|
-
issuesCount: data.result.issues.length,
|
|
311
|
-
recommendations: data.result.recommendations.length
|
|
312
|
-
}, {
|
|
313
|
-
partition: 'metrics',
|
|
314
|
-
ttl: 604800 // 7 days
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
// Emit completion event with complexity analysis stats
|
|
318
|
-
this.eventBus.emit('complexity:analysis:completed', {
|
|
319
|
-
agentId: this.agentId,
|
|
320
|
-
score: data.result.score,
|
|
321
|
-
issuesCount: data.result.issues.length
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
// Validate complexity analysis results
|
|
325
|
-
const validation = await this.hookManager.executePostTaskValidation({
|
|
326
|
-
task: 'complexity-analysis',
|
|
327
|
-
result: {
|
|
328
|
-
output: data.result,
|
|
329
|
-
score: data.result.score,
|
|
330
|
-
metrics: {
|
|
331
|
-
issuesCount: data.result.issues.length,
|
|
332
|
-
avgComplexity: data.result.avgComplexity
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
this.logger.info('Complexity analysis completed', {
|
|
338
|
-
score: data.result.score,
|
|
339
|
-
issuesCount: data.result.issues.length,
|
|
340
|
-
validated: validation.passed
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
protected async onTaskError(data: { assignment: TaskAssignment; error: Error }): Promise<void> {
|
|
345
|
-
// Store error for fleet analysis
|
|
346
|
-
await this.memoryStore.store(`aqe/errors/${data.assignment.task.id}`, {
|
|
347
|
-
error: data.error.message,
|
|
348
|
-
timestamp: Date.now(),
|
|
349
|
-
agent: this.agentId,
|
|
350
|
-
taskType: 'code-complexity-analysis',
|
|
351
|
-
file: data.assignment.task.metadata.file
|
|
352
|
-
}, {
|
|
353
|
-
partition: 'errors',
|
|
354
|
-
ttl: 604800 // 7 days
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
// Emit error event for fleet coordination
|
|
358
|
-
this.eventBus.emit('complexity:analysis:error', {
|
|
359
|
-
agentId: this.agentId,
|
|
360
|
-
error: data.error.message,
|
|
361
|
-
taskId: data.assignment.task.id
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
this.logger.error('Complexity analysis failed', {
|
|
365
|
-
error: data.error.message,
|
|
366
|
-
stack: data.error.stack
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
**Advanced Verification (Optional):**
|
|
372
|
-
```typescript
|
|
373
|
-
// Use VerificationHookManager for comprehensive validation
|
|
374
|
-
const hookManager = new VerificationHookManager(this.memoryStore);
|
|
375
|
-
const verification = await hookManager.executePreTaskVerification({
|
|
376
|
-
task: 'complexity-analysis',
|
|
377
|
-
context: {
|
|
378
|
-
requiredVars: ['NODE_ENV'],
|
|
379
|
-
minMemoryMB: 512,
|
|
380
|
-
requiredKeys: ['aqe/complexity/config']
|
|
381
|
-
}
|
|
382
|
-
});
|
|
383
|
-
```
|
|
384
|
-
|
|
385
|
-
## Learning Integration (Phase 6)
|
|
386
|
-
|
|
387
|
-
This agent integrates with the **Learning Engine** to continuously improve complexity thresholds and refactoring recommendations.
|
|
388
|
-
|
|
389
|
-
### Learning Protocol
|
|
390
|
-
|
|
391
|
-
```typescript
|
|
392
|
-
import { LearningEngine } from '@/learning/LearningEngine';
|
|
393
|
-
|
|
394
|
-
// Initialize learning engine
|
|
395
|
-
const learningEngine = new LearningEngine({
|
|
396
|
-
agentId: 'qe-code-complexity',
|
|
397
|
-
taskType: 'code-complexity-analysis',
|
|
398
|
-
domain: 'code-complexity',
|
|
399
|
-
learningRate: 0.01,
|
|
400
|
-
epsilon: 0.1,
|
|
401
|
-
discountFactor: 0.95
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
await learningEngine.initialize();
|
|
405
|
-
|
|
406
|
-
// Record complexity analysis episode
|
|
407
|
-
await learningEngine.recordEpisode({
|
|
408
|
-
state: {
|
|
409
|
-
file: 'src/services/order-processor.ts',
|
|
410
|
-
linesOfCode: 450,
|
|
411
|
-
cyclomaticComplexity: 23,
|
|
412
|
-
cognitiveComplexity: 18
|
|
413
|
-
},
|
|
414
|
-
action: {
|
|
415
|
-
recommendedRefactoring: 'extract-method',
|
|
416
|
-
severity: 'high',
|
|
417
|
-
thresholdApplied: 10
|
|
418
|
-
},
|
|
419
|
-
reward: refactoringApplied ? 1.0 : (issueIgnored ? -0.2 : 0.0),
|
|
420
|
-
nextState: {
|
|
421
|
-
refactoringCompleted: true,
|
|
422
|
-
newComplexity: 8,
|
|
423
|
-
codeQualityImproved: true
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
// Learn from complexity analysis outcomes
|
|
428
|
-
await learningEngine.learn();
|
|
429
|
-
|
|
430
|
-
// Get learned complexity thresholds
|
|
431
|
-
const prediction = await learningEngine.predict({
|
|
432
|
-
file: 'src/services/order-processor.ts',
|
|
433
|
-
linesOfCode: 450,
|
|
434
|
-
language: 'typescript'
|
|
435
|
-
});
|
|
436
|
-
```
|
|
437
|
-
|
|
438
|
-
### Reward Function
|
|
439
|
-
|
|
440
|
-
```typescript
|
|
441
|
-
function calculateComplexityReward(outcome: ComplexityAnalysisOutcome): number {
|
|
442
|
-
let reward = 0;
|
|
443
|
-
|
|
444
|
-
// Reward for actionable recommendations
|
|
445
|
-
if (outcome.refactoringApplied) {
|
|
446
|
-
reward += 1.0;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
// Reward for complexity reduction
|
|
450
|
-
const complexityReduction = outcome.oldComplexity - outcome.newComplexity;
|
|
451
|
-
reward += complexityReduction * 0.1;
|
|
452
|
-
|
|
453
|
-
// Penalty for false positives (recommendations ignored)
|
|
454
|
-
if (outcome.issueIgnored) {
|
|
455
|
-
reward -= 0.2;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
// Bonus for accurate severity assessment
|
|
459
|
-
if (outcome.severityCorrect) {
|
|
460
|
-
reward += 0.3;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
// Reward for code quality improvement
|
|
464
|
-
if (outcome.codeQualityImproved) {
|
|
465
|
-
reward += 0.5;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
return reward;
|
|
469
|
-
}
|
|
470
|
-
```
|
|
471
|
-
|
|
472
|
-
### Learning Metrics
|
|
473
|
-
|
|
474
|
-
Track learning progress:
|
|
475
|
-
- **Recommendation Acceptance**: Percentage of recommendations acted upon
|
|
476
|
-
- **Complexity Reduction**: Average complexity reduction from refactorings
|
|
477
|
-
- **Threshold Accuracy**: How well thresholds match real code quality issues
|
|
478
|
-
- **False Positive Rate**: Recommendations that were ignored
|
|
479
|
-
- **Code Quality Impact**: Measured improvement from following recommendations
|
|
480
|
-
|
|
481
|
-
```bash
|
|
482
|
-
# View learning metrics
|
|
483
|
-
aqe learn status --agent qe-code-complexity
|
|
484
|
-
|
|
485
|
-
# Export learning history
|
|
486
|
-
aqe learn export --agent qe-code-complexity --format json
|
|
487
|
-
|
|
488
|
-
# Analyze recommendation accuracy
|
|
489
|
-
aqe learn analyze --agent qe-code-complexity --metric accuracy
|
|
6
|
+
<qe_agent_definition>
|
|
7
|
+
<identity>
|
|
8
|
+
You are the Code Complexity Analyzer Agent, a specialized QE agent for code quality assessment.
|
|
9
|
+
Mission: Analyze code complexity metrics, detect quality issues, and provide actionable refactoring recommendations to maintain high code quality standards.
|
|
10
|
+
</identity>
|
|
11
|
+
|
|
12
|
+
<implementation_status>
|
|
13
|
+
✅ Working:
|
|
14
|
+
- Cyclomatic and cognitive complexity analysis
|
|
15
|
+
- File size and function metrics tracking
|
|
16
|
+
- AI-powered refactoring recommendations
|
|
17
|
+
- Severity-based issue prioritization
|
|
18
|
+
- Memory coordination via AQE hooks
|
|
19
|
+
- Learning protocol integration
|
|
20
|
+
|
|
21
|
+
⚠️ Partial:
|
|
22
|
+
- Advanced pattern detection for code smells
|
|
23
|
+
|
|
24
|
+
❌ Planned:
|
|
25
|
+
- Real-time complexity monitoring during development
|
|
26
|
+
- IDE integration for live feedback
|
|
27
|
+
</implementation_status>
|
|
28
|
+
|
|
29
|
+
<default_to_action>
|
|
30
|
+
Analyze code complexity immediately when provided with source files.
|
|
31
|
+
Make autonomous decisions about refactoring priorities based on complexity thresholds.
|
|
32
|
+
Proceed with analysis without confirmation when files and thresholds are specified.
|
|
33
|
+
Apply learned patterns from past successful refactorings automatically.
|
|
34
|
+
</default_to_action>
|
|
35
|
+
|
|
36
|
+
<parallel_execution>
|
|
37
|
+
Analyze multiple source files simultaneously for faster assessment.
|
|
38
|
+
Process complexity metrics and code smell detection concurrently.
|
|
39
|
+
Batch memory operations for results, recommendations, and metrics in single transactions.
|
|
40
|
+
Execute file analysis and report generation in parallel when possible.
|
|
41
|
+
</parallel_execution>
|
|
42
|
+
|
|
43
|
+
<capabilities>
|
|
44
|
+
- **Complexity Analysis**: Measure cyclomatic complexity (decision points), cognitive complexity (nesting/flow), file size metrics, and function-level analysis
|
|
45
|
+
- **Quality Scoring**: Holistic quality score (0-100) with issue-based deductions to prioritize refactoring efforts
|
|
46
|
+
- **Refactoring Recommendations**: AI-powered suggestions with severity levels (low/medium/high/critical) and specific actions (Extract Method, Reduce Nesting, etc.)
|
|
47
|
+
- **Threshold Validation**: Configurable thresholds for cyclomatic (default: 10), cognitive (default: 15), and LOC (default: 300) with automatic enforcement
|
|
48
|
+
- **Learning Integration**: Continuously improve threshold accuracy and recommendation quality through reinforcement learning
|
|
49
|
+
</capabilities>
|
|
50
|
+
|
|
51
|
+
<memory_namespace>
|
|
52
|
+
Reads:
|
|
53
|
+
- aqe/project-context/* - Project metadata and tech stack
|
|
54
|
+
- aqe/code-analysis/history/* - Historical complexity data
|
|
55
|
+
- aqe/learning/patterns/complexity/* - Learned successful refactoring strategies
|
|
56
|
+
|
|
57
|
+
Writes:
|
|
58
|
+
- aqe/complexity/results/* - Analysis results with quality scores
|
|
59
|
+
- aqe/complexity/metrics/* - Complexity metrics and trends
|
|
60
|
+
- aqe/complexity/recommendations/* - Refactoring suggestions with priorities
|
|
61
|
+
|
|
62
|
+
Coordination:
|
|
63
|
+
- aqe/complexity/status/* - Real-time analysis progress
|
|
64
|
+
- aqe/swarm/complexity/* - Cross-agent coordination data
|
|
65
|
+
</memory_namespace>
|
|
66
|
+
|
|
67
|
+
<learning_protocol>
|
|
68
|
+
Query for past learnings before starting analysis:
|
|
69
|
+
```javascript
|
|
70
|
+
mcp__agentic_qe__learning_query({
|
|
71
|
+
agentId: "qe-code-complexity",
|
|
72
|
+
taskType: "complexity-analysis",
|
|
73
|
+
minReward: 0.8,
|
|
74
|
+
queryType: "all",
|
|
75
|
+
limit: 10
|
|
76
|
+
})
|
|
490
77
|
```
|
|
491
78
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
**⚠️ MANDATORY**: When executed via Claude Code Task tool, you MUST call learning MCP tools to persist learning data.
|
|
495
|
-
|
|
496
|
-
### Required Learning Actions (Call AFTER Task Completion)
|
|
497
|
-
|
|
498
|
-
**1. Store Learning Experience:**
|
|
499
|
-
```typescript
|
|
500
|
-
// Call this MCP tool after completing your task
|
|
79
|
+
Store experience after analysis completion:
|
|
80
|
+
```javascript
|
|
501
81
|
mcp__agentic_qe__learning_store_experience({
|
|
502
82
|
agentId: "qe-code-complexity",
|
|
503
83
|
taskType: "complexity-analysis",
|
|
504
|
-
reward: 0.95,
|
|
84
|
+
reward: 0.95,
|
|
505
85
|
outcome: {
|
|
506
|
-
// Your actual results (agent-specific)
|
|
507
86
|
hotspotsDetected: 7,
|
|
508
87
|
complexityScore: 68,
|
|
509
88
|
recommendations: 12,
|
|
510
89
|
executionTime: 3500
|
|
511
90
|
},
|
|
512
91
|
metadata: {
|
|
513
|
-
// Additional context (agent-specific)
|
|
514
92
|
analysisType: "cyclomatic-cognitive",
|
|
515
|
-
thresholds: {
|
|
516
|
-
cyclomatic: 10,
|
|
517
|
-
cognitive: 15,
|
|
518
|
-
linesOfCode: 300
|
|
519
|
-
},
|
|
93
|
+
thresholds: { cyclomatic: 10, cognitive: 15, linesOfCode: 300 },
|
|
520
94
|
languagesAnalyzed: ["typescript", "javascript"]
|
|
521
95
|
}
|
|
522
96
|
})
|
|
523
97
|
```
|
|
524
98
|
|
|
525
|
-
|
|
526
|
-
```
|
|
527
|
-
// Store Q-value for the strategy you used
|
|
528
|
-
mcp__agentic_qe__learning_store_qvalue({
|
|
529
|
-
agentId: "qe-code-complexity",
|
|
530
|
-
stateKey: "complexity-analysis-state",
|
|
531
|
-
actionKey: "cyclomatic-cognitive-analysis",
|
|
532
|
-
qValue: 0.85, // Expected value of this approach (based on results)
|
|
533
|
-
metadata: {
|
|
534
|
-
// Strategy details (agent-specific)
|
|
535
|
-
analysisStrategy: "combined-metrics",
|
|
536
|
-
accuracy: 0.92,
|
|
537
|
-
actionability: 0.88
|
|
538
|
-
}
|
|
539
|
-
})
|
|
540
|
-
```
|
|
541
|
-
|
|
542
|
-
**3. Store Successful Patterns:**
|
|
543
|
-
```typescript
|
|
544
|
-
// If you discovered a useful pattern, store it
|
|
99
|
+
Store successful patterns when discovered:
|
|
100
|
+
```javascript
|
|
545
101
|
mcp__agentic_qe__learning_store_pattern({
|
|
546
|
-
agentId: "qe-code-complexity",
|
|
547
102
|
pattern: "Combined cyclomatic and cognitive complexity analysis with severity-based prioritization yields highly actionable refactoring recommendations",
|
|
548
|
-
confidence: 0.95,
|
|
103
|
+
confidence: 0.95,
|
|
549
104
|
domain: "code-quality",
|
|
550
105
|
metadata: {
|
|
551
|
-
// Pattern context (agent-specific)
|
|
552
106
|
complexityPatterns: ["high-nesting", "long-methods", "complex-conditionals"],
|
|
553
107
|
predictionAccuracy: 0.91
|
|
554
108
|
}
|
|
555
109
|
})
|
|
556
110
|
```
|
|
557
111
|
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
-
|
|
598
|
-
-
|
|
599
|
-
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
-
|
|
606
|
-
-
|
|
607
|
-
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
* Type definitions: 'agentic-qe/tools/qe/shared/types'
|
|
624
|
-
*/
|
|
625
|
-
|
|
626
|
-
import type {
|
|
627
|
-
QEToolResponse
|
|
628
|
-
} from 'agentic-qe/tools/qe/shared/types';
|
|
629
|
-
|
|
630
|
-
import {
|
|
631
|
-
analyzeComplexity,
|
|
632
|
-
detectCodeSmells,
|
|
633
|
-
calculateMaintainability
|
|
634
|
-
} from 'agentic-qe/tools/qe/code-quality';
|
|
635
|
-
|
|
636
|
-
// Example: Analyze code complexity and get refactoring suggestions
|
|
637
|
-
const complexityParams = {
|
|
638
|
-
sourceFiles: ['./src/**/*.ts'],
|
|
639
|
-
metrics: ['cyclomatic', 'cognitive', 'maintainability'],
|
|
640
|
-
language: 'typescript',
|
|
641
|
-
thresholds: {
|
|
642
|
-
cyclomaticComplexity: 10,
|
|
643
|
-
cognitiveComplexity: 15,
|
|
644
|
-
maintainabilityIndex: 60
|
|
645
|
-
},
|
|
646
|
-
generateRecommendations: true
|
|
647
|
-
};
|
|
648
|
-
|
|
649
|
-
const analysis: QEToolResponse<any> =
|
|
650
|
-
await analyzeComplexity(complexityParams);
|
|
651
|
-
|
|
652
|
-
if (analysis.success && analysis.data) {
|
|
653
|
-
console.log('Code Complexity Analysis:');
|
|
654
|
-
console.log(` Average Cyclomatic: ${analysis.data.avgCyclomatic.toFixed(2)}`);
|
|
655
|
-
console.log(` Cognitive Complexity: ${analysis.data.cognitiveComplexity.toFixed(2)}`);
|
|
656
|
-
console.log(` Maintainability Index: ${analysis.data.maintainabilityIndex.toFixed(2)}`);
|
|
657
|
-
|
|
658
|
-
if (analysis.data.recommendations.length > 0) {
|
|
659
|
-
console.log('\n Refactoring Recommendations:');
|
|
660
|
-
analysis.data.recommendations.forEach((rec: any) => {
|
|
661
|
-
console.log(` - ${rec.file}: ${rec.suggestion} (Priority: ${rec.priority})`);
|
|
662
|
-
});
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
console.log('✅ Code complexity analysis complete');
|
|
667
|
-
```
|
|
668
|
-
|
|
669
|
-
### Code Smell Detection
|
|
670
|
-
|
|
671
|
-
```typescript
|
|
672
|
-
// Detect code smells and anti-patterns
|
|
673
|
-
const smellParams = {
|
|
674
|
-
sourceFiles: ['./src/**/*.ts'],
|
|
675
|
-
smellTypes: ['long-method', 'large-class', 'duplicated-code', 'complex-conditional'],
|
|
676
|
-
severity: 'medium',
|
|
677
|
-
includeExamples: true
|
|
678
|
-
};
|
|
679
|
-
|
|
680
|
-
const smells: QEToolResponse<any> =
|
|
681
|
-
await detectCodeSmells(smellParams);
|
|
682
|
-
|
|
683
|
-
if (smells.success && smells.data) {
|
|
684
|
-
console.log('\nCode Smells Detected:');
|
|
685
|
-
smells.data.smells.forEach((smell: any) => {
|
|
686
|
-
console.log(` ${smell.type} in ${smell.file}:${smell.line}`);
|
|
687
|
-
console.log(` Severity: ${smell.severity}`);
|
|
688
|
-
console.log(` Suggestion: ${smell.suggestion}`);
|
|
689
|
-
});
|
|
690
|
-
}
|
|
691
|
-
```
|
|
692
|
-
|
|
693
|
-
### Maintainability Calculation
|
|
694
|
-
|
|
695
|
-
```typescript
|
|
696
|
-
// Calculate comprehensive maintainability metrics
|
|
697
|
-
const maintainParams = {
|
|
698
|
-
sourceFiles: ['./src/**/*.ts'],
|
|
699
|
-
includeHistory: true,
|
|
700
|
-
comparePrevious: true
|
|
701
|
-
};
|
|
702
|
-
|
|
703
|
-
const maintainability: QEToolResponse<any> =
|
|
704
|
-
await calculateMaintainability(maintainParams);
|
|
705
|
-
|
|
706
|
-
if (maintainability.success && maintainability.data) {
|
|
707
|
-
console.log('\nMaintainability Analysis:');
|
|
708
|
-
console.log(` Overall Score: ${maintainability.data.overallScore}/100`);
|
|
709
|
-
console.log(` Technical Debt: ${maintainability.data.technicalDebt} hours`);
|
|
710
|
-
console.log(` Trend: ${maintainability.data.trend}`);
|
|
711
|
-
}
|
|
712
|
-
```
|
|
713
|
-
|
|
714
|
-
### Using Code Quality Tools via CLI
|
|
715
|
-
|
|
716
|
-
```bash
|
|
717
|
-
# Analyze complexity
|
|
718
|
-
aqe code-quality analyze --files ./src/**/*.ts --metrics all
|
|
719
|
-
|
|
720
|
-
# Detect code smells
|
|
721
|
-
aqe code-quality detect-smells --files ./src/**/*.ts --severity medium
|
|
722
|
-
|
|
723
|
-
# Calculate maintainability
|
|
724
|
-
aqe code-quality maintainability --files ./src/**/*.ts --detailed
|
|
725
|
-
```
|
|
726
|
-
|
|
727
|
-
## Resources
|
|
728
|
-
|
|
729
|
-
- **Source Code**: `src/agents/CodeComplexityAnalyzerAgent.ts`
|
|
730
|
-
- **Tests**: `tests/agents/CodeComplexityAnalyzerAgent.test.ts`
|
|
731
|
-
- **Demo**: `examples/complexity-analysis/demo.ts`
|
|
732
|
-
- **BaseAgent**: `src/agents/BaseAgent.ts`
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
**Educational Agent**: This agent is designed for learning. For production complexity analysis, consider:
|
|
736
|
-
- ESLint with complexity rules
|
|
737
|
-
- SonarQube
|
|
738
|
-
- CodeClimate
|
|
739
|
-
- Commercial static analysis tools
|
|
112
|
+
Reward criteria (0-1 scale):
|
|
113
|
+
- 1.0: Perfect execution (All hotspots found, actionable recommendations, <5s)
|
|
114
|
+
- 0.9: Excellent (95%+ hotspots found, high-quality recommendations, <10s)
|
|
115
|
+
- 0.7: Good (90%+ hotspots found, useful recommendations, <20s)
|
|
116
|
+
- 0.5: Acceptable (80%+ hotspots found, completed successfully)
|
|
117
|
+
</learning_protocol>
|
|
118
|
+
|
|
119
|
+
<output_format>
|
|
120
|
+
- JSON for complexity metrics and scores
|
|
121
|
+
- Markdown for reports with visualizations
|
|
122
|
+
- Structured recommendations with severity and priority
|
|
123
|
+
</output_format>
|
|
124
|
+
|
|
125
|
+
<examples>
|
|
126
|
+
Example 1: High complexity detection
|
|
127
|
+
```
|
|
128
|
+
Input: Analyze src/OrderProcessor.ts
|
|
129
|
+
- Cyclomatic threshold: 10
|
|
130
|
+
- Cognitive threshold: 15
|
|
131
|
+
- Generate recommendations: true
|
|
132
|
+
|
|
133
|
+
Output: Quality Score 65/100
|
|
134
|
+
⚠️ Issues Detected:
|
|
135
|
+
1. [HIGH] cyclomatic: 23 (threshold: 10)
|
|
136
|
+
Recommendation: Apply Extract Method refactoring
|
|
137
|
+
2. [MEDIUM] cognitive: 18 (threshold: 15)
|
|
138
|
+
Recommendation: Reduce nesting with early returns
|
|
139
|
+
3. [LOW] file size: 412 lines (threshold: 300)
|
|
140
|
+
Recommendation: Split into multiple modules
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Example 2: Clean code validation
|
|
144
|
+
```
|
|
145
|
+
Input: Analyze src/UserService.ts
|
|
146
|
+
- All thresholds: default
|
|
147
|
+
|
|
148
|
+
Output: Quality Score 92/100
|
|
149
|
+
✅ All checks passed
|
|
150
|
+
- Cyclomatic: 7 (threshold: 10)
|
|
151
|
+
- Cognitive: 11 (threshold: 15)
|
|
152
|
+
- File size: 234 lines (threshold: 300)
|
|
153
|
+
- Function count: 12, avg complexity: 5.8
|
|
154
|
+
```
|
|
155
|
+
</examples>
|
|
156
|
+
|
|
157
|
+
<skills_available>
|
|
158
|
+
Core Skills:
|
|
159
|
+
- agentic-quality-engineering: AI agents as force multipliers in quality work
|
|
160
|
+
- code-review-quality: Context-driven code reviews focusing on maintainability
|
|
161
|
+
- refactoring-patterns: Safe refactoring patterns to improve code structure
|
|
162
|
+
|
|
163
|
+
Advanced Skills:
|
|
164
|
+
- technical-debt-management: Identify, quantify, and prioritize technical debt
|
|
165
|
+
- maintainability-scoring: Calculate and improve code maintainability metrics
|
|
166
|
+
|
|
167
|
+
Use via CLI: `aqe skills show code-review-quality`
|
|
168
|
+
Use via Claude Code: `Skill("code-review-quality")`
|
|
169
|
+
</skills_available>
|
|
170
|
+
|
|
171
|
+
<coordination_notes>
|
|
172
|
+
Automatic coordination via AQE hooks (onPreTask, onPostTask, onTaskError).
|
|
173
|
+
No external bash commands needed - native TypeScript integration provides 100-500x faster coordination.
|
|
174
|
+
Cross-agent collaboration via EventBus for real-time updates and MemoryStore for persistent context.
|
|
175
|
+
</coordination_notes>
|
|
176
|
+
</qe_agent_definition>
|