codeflow-hook 1.4.0 → 2.0.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/README.md +140 -122
- package/bin/codeflow-hook.js +182 -2
- package/lib/cli-integration/dist/index.d.ts +128 -0
- package/lib/cli-integration/dist/index.js +585 -0
- package/lib/cli-integration/dist/pipelineConfigs.d.ts +60 -0
- package/lib/cli-integration/dist/pipelineConfigs.js +549 -0
- package/lib/cli-integration/dist/simulationEngine.d.ts +86 -0
- package/lib/cli-integration/dist/simulationEngine.js +475 -0
- package/lib/cli-integration/dist/types.d.ts +156 -0
- package/lib/cli-integration/dist/types.js +15 -0
- package/lib/cli-integration/src/index.ts +748 -0
- package/lib/cli-integration/src/pipelineConfigs.ts +579 -0
- package/lib/cli-integration/src/simulationEngine.ts +622 -0
- package/lib/cli-integration/src/types.ts +175 -0
- package/package.json +10 -4
package/README.md
CHANGED
|
@@ -1,116 +1,48 @@
|
|
|
1
1
|
# Codeflow Commander — Nexus Gateway CLI
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**AI-Powered Code Analysis and Git Hook Management**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
A lightweight command-line tool that provides AI-driven code analysis, automated git hook installation, and intelligent code review capabilities. This CLI client analyzes your local code changes using advanced AI models and helps maintain code quality through automated pre-commit and pre-push checks.
|
|
6
6
|
|
|
7
|
-
This is the
|
|
7
|
+
**⚠️ Important**: This is the **client-side CLI tool** only. Enterprise features like the Enterprise Knowledge Graph (EKG), Autonomous Agent Network (AAN), and ingestion services are part of the broader Codeflow Commander platform and require separate enterprise deployment.
|
|
8
8
|
|
|
9
|
-
## 🚀
|
|
9
|
+
## 🚀 What This CLI Tool Provides
|
|
10
10
|
|
|
11
|
-
### **
|
|
12
|
-
- **
|
|
13
|
-
- **
|
|
14
|
-
- **
|
|
15
|
-
- **
|
|
11
|
+
### **AI-Powered Code Analysis**
|
|
12
|
+
- **Local Code Diff Analysis**: Analyze git diffs using Gemini, OpenAI GPT, or Claude AI models
|
|
13
|
+
- **Quality Assessment**: Get 1-10 quality ratings with detailed feedback on code changes
|
|
14
|
+
- **Security Detection**: Identify potential security vulnerabilities in code changes
|
|
15
|
+
- **Performance Insights**: Receive suggestions for performance optimizations
|
|
16
16
|
|
|
17
|
-
### **
|
|
18
|
-
- **
|
|
19
|
-
- **
|
|
20
|
-
- **
|
|
21
|
-
- **
|
|
17
|
+
### **Git Hook Automation**
|
|
18
|
+
- **Pre-commit Hooks**: Automatic analysis of staged changes before commits
|
|
19
|
+
- **Pre-push Hooks**: Comprehensive code review simulation before pushing to remote
|
|
20
|
+
- **Quality Gates**: Prevent problematic commits and pushes based on AI analysis
|
|
21
|
+
- **Customizable Thresholds**: Configure when to block commits based on quality scores
|
|
22
22
|
|
|
23
|
-
### **
|
|
24
|
-
- **
|
|
25
|
-
- **
|
|
26
|
-
- **
|
|
27
|
-
- **
|
|
23
|
+
### **Local Knowledge Base (RAG)**
|
|
24
|
+
- **Project Context Indexing**: Build searchable knowledge base from your project files
|
|
25
|
+
- **Context-Aware Analysis**: AI analysis considers your project's documentation and code patterns
|
|
26
|
+
- **Offline Capability**: Works without internet for local analysis (with indexed knowledge)
|
|
27
|
+
- **Incremental Updates**: Automatically update knowledge base as project evolves
|
|
28
28
|
|
|
29
|
-
### **
|
|
30
|
-
- **
|
|
31
|
-
- **
|
|
32
|
-
- **
|
|
33
|
-
- **
|
|
29
|
+
### **Multi-Provider AI Support**
|
|
30
|
+
- **Google Gemini**: Default AI provider with latest models (1.5 Pro, 1.5 Flash, Pro)
|
|
31
|
+
- **OpenAI GPT**: Support for GPT-4, GPT-4 Turbo, GPT-3.5 Turbo
|
|
32
|
+
- **Anthropic Claude**: Integration with Claude 3 Opus, Sonnet, and Haiku
|
|
33
|
+
- **Custom Endpoints**: Connect to self-hosted or custom AI model endpoints
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
- **Autonomous Permissions**: Dynamic access control based on context and risk
|
|
37
|
-
- **Real-time Compliance**: Continuous regulatory and policy validation
|
|
38
|
-
- **Emergency Controls**: System-wide safety mechanisms and overrides
|
|
39
|
-
- **Human-in-the-Loop**: Graduated approval workflows for different risk levels
|
|
35
|
+
## 📦 How It Works
|
|
40
36
|
|
|
41
|
-
|
|
42
|
-
- **Repository Federation**: Coordinate operations across multiple repositories
|
|
43
|
-
- **Workflow Orchestration**: Complex process execution with dependency management
|
|
44
|
-
- **State Synchronization**: Federated data consistency across the enterprise
|
|
45
|
-
- **Resource Optimization**: Intelligent load balancing and execution management
|
|
37
|
+
The CLI tool operates entirely on your local machine and analyzes your code changes using AI. Here's the workflow:
|
|
46
38
|
|
|
47
|
-
|
|
39
|
+
1. **Local Analysis**: When you run analysis, the tool captures your git diff locally
|
|
40
|
+
2. **AI Processing**: Sends the diff to your configured AI provider (Gemini/OpenAI/Claude)
|
|
41
|
+
3. **Context Enhancement**: Optionally includes your project's indexed knowledge for better analysis
|
|
42
|
+
4. **Feedback Generation**: Returns quality scores, issues, and recommendations
|
|
43
|
+
5. **Hook Integration**: Automatically runs during git operations to maintain code quality
|
|
48
44
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
```
|
|
52
|
-
┌─────────────────────────────────────────────────────────┐
|
|
53
|
-
│ MULTI-MODAL INTERFACE LAYER (MMIL) │
|
|
54
|
-
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────┐ │
|
|
55
|
-
│ │ Conversational │ │ Design→Code │ │ IDE │ │
|
|
56
|
-
│ │ Interfaces │ │ Pipeline │ │ Integrations│ │
|
|
57
|
-
│ └─────────────────┘ └─────────────────┘ └─────────────┘ │
|
|
58
|
-
└─────────────────────────────────────────────────────────┘
|
|
59
|
-
│
|
|
60
|
-
▼
|
|
61
|
-
┌─────────────────────────────────────────────────────────┐
|
|
62
|
-
│ AUTONOMOUS AGENT NETWORK (AAN) - ORCHESTRATOR │
|
|
63
|
-
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────┐ │
|
|
64
|
-
│ │ Workflow Agents │ │ Maintenance │ │ Self-Heal │ │
|
|
65
|
-
│ │ │ │ Bots │ │ Agents │ │
|
|
66
|
-
│ └─────────────────┘ └─────────────────┘ └─────────────┘ │
|
|
67
|
-
└─────────────────────────────────────────────────────────┘
|
|
68
|
-
│
|
|
69
|
-
▼
|
|
70
|
-
┌─────────────────────────────────────────────────────────┐
|
|
71
|
-
│ GOVERNANCE & SAFETY FRAMEWORK - RISK CONTROL │
|
|
72
|
-
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────┐ │
|
|
73
|
-
│ │ Permission │ │ Audit & │ │ Emergency │ │
|
|
74
|
-
│ │ Engine │ │ Compliance │ │ Controls │ │
|
|
75
|
-
│ └─────────────────┘ └─────────────────┘ └─────────────┘ │
|
|
76
|
-
└─────────────────────────────────────────────────────────┘
|
|
77
|
-
│
|
|
78
|
-
▼
|
|
79
|
-
┌─────────────────────────────────────────────────────────┐
|
|
80
|
-
│ ENTERPRISE KNOWLEDGE GRAPH (EKG) - INTELLIGENCE │
|
|
81
|
-
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────┐ │
|
|
82
|
-
│ │ Cross-Repo │ │ Semantic │ │ Expert │ │
|
|
83
|
-
│ │ Dependencies │ │ Mapping │ │ Discovery │ │
|
|
84
|
-
│ └─────────────────┘ └─────────────────┘ └─────────────┘ │
|
|
85
|
-
└─────────────────────────────────────────────────────────┘
|
|
86
|
-
│
|
|
87
|
-
▼
|
|
88
|
-
┌─────────────────────────────────────────────────────────┐
|
|
89
|
-
│ PREDICTIVE INTELLIGENCE ENGINE (PIE) - FORECASTING │
|
|
90
|
-
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────┐ │
|
|
91
|
-
│ │ Tech Debt │ │ Performance │ │ Risk │ │
|
|
92
|
-
│ │ Forecasting │ │ Prediction │ │ Analytics │ │
|
|
93
|
-
│ └─────────────────┘ └─────────────────┘ └─────────────┘ │
|
|
94
|
-
└─────────────────────────────────────────────────────────┘
|
|
95
|
-
│
|
|
96
|
-
▼
|
|
97
|
-
┌─────────────────────────────────────────────────────────┐
|
|
98
|
-
│ DISTRIBUTED EXECUTION ENGINE (DEE) - RUNTIME │
|
|
99
|
-
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────┐ │
|
|
100
|
-
│ │ Repository │ │ Workflow │ │ State │ │
|
|
101
|
-
│ │ Federation │ │ Orchestration │ │ Sync │ │
|
|
102
|
-
│ └─────────────────┘ └─────────────────┘ └─────────────┘ │
|
|
103
|
-
└─────────────────────────────────────────────────────────┘
|
|
104
|
-
│
|
|
105
|
-
▼
|
|
106
|
-
┌─────────────────────────────────────────────────────────┐
|
|
107
|
-
│ EXTERNAL SYSTEMS INTEGRATION │
|
|
108
|
-
│ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ │
|
|
109
|
-
│ │GitHub│ │GitLab│ │JIRA │ │Slack│ │Jenkins│ │
|
|
110
|
-
│ │Actions│ │ │ │ │ │ │ │ │ │
|
|
111
|
-
│ └─────┘ └─────┘ └─────┘ └─────┘ └─────┘ │
|
|
112
|
-
└─────────────────────────────────────────────────────────┘
|
|
113
|
-
```
|
|
45
|
+
**No data is sent to external servers** except for AI API calls to your configured provider. Your code stays on your machine.
|
|
114
46
|
|
|
115
47
|
## 📦 Installation
|
|
116
48
|
|
|
@@ -269,33 +201,117 @@ codeflow-hook analyze-diff --help # Analysis options
|
|
|
269
201
|
- Best practice recommendations
|
|
270
202
|
- Maintainability evaluation
|
|
271
203
|
|
|
272
|
-
##
|
|
204
|
+
## 💡 Usage Examples
|
|
205
|
+
|
|
206
|
+
### Standard Development Workflow
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
# Stage your changes
|
|
210
|
+
git add .
|
|
211
|
+
|
|
212
|
+
# Pre-commit hook automatically runs AI analysis
|
|
213
|
+
git commit -m "feat: add new authentication"
|
|
214
|
+
|
|
215
|
+
# Pre-push hook runs tests and full AI review
|
|
216
|
+
git push origin main
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Manual Analysis
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
# Analyze uncommitted changes
|
|
223
|
+
git diff | codeflow-hook analyze-diff
|
|
224
|
+
|
|
225
|
+
# Analyze specific files
|
|
226
|
+
git diff path/to/file.js | codeflow-hook analyze-diff
|
|
227
|
+
|
|
228
|
+
# Analyze between commits
|
|
229
|
+
git diff HEAD~1 HEAD | codeflow-hook analyze-diff
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## 🎯 AI Analysis Output
|
|
233
|
+
|
|
234
|
+
The tool provides:
|
|
235
|
+
|
|
236
|
+
- **Rating**: 1-10 quality score with color coding
|
|
237
|
+
- **Summary**: Brief assessment of changes
|
|
238
|
+
- **Issues**: Specific problems with solutions
|
|
239
|
+
- **Recommendations**: Improvement suggestions
|
|
240
|
+
|
|
241
|
+
Example output:
|
|
242
|
+
```
|
|
243
|
+
⭐ **Rating:** 9/10
|
|
244
|
+
📝 **Summary:** Clean implementation with good separation of concerns
|
|
245
|
+
|
|
246
|
+
⚠️ **Issues:**
|
|
247
|
+
- Consider adding input validation for edge cases
|
|
273
248
|
|
|
274
|
-
|
|
275
|
-
|
|
249
|
+
💡 **Recommendations:**
|
|
250
|
+
- Add comprehensive error handling
|
|
251
|
+
- Consider extracting common logic to a utility function
|
|
252
|
+
```
|
|
276
253
|
|
|
277
|
-
|
|
278
|
-
**🎨 Design-to-Code Pipeline**: Computer vision and ML models for design artifact ingestion
|
|
279
|
-
**📊 Predictive Analytics Engine**: Time-series analysis and machine learning for trend forecasting
|
|
280
|
-
**🔍 Semantic Code Analysis**: Advanced NLP for code understanding and pattern recognition
|
|
254
|
+
## 🔧 Configuration
|
|
281
255
|
|
|
282
|
-
|
|
283
|
-
The core platform intelligence is delivered through specialized agent networks:
|
|
256
|
+
Configuration is stored in `~/.codeflow-hook/config.json`:
|
|
284
257
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
-
|
|
258
|
+
```json
|
|
259
|
+
{
|
|
260
|
+
"provider": "gemini",
|
|
261
|
+
"apiKey": "your-api-key",
|
|
262
|
+
"apiUrl": "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent",
|
|
263
|
+
"model": "gemini-pro"
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Supported AI Providers
|
|
289
268
|
|
|
290
|
-
|
|
291
|
-
-
|
|
292
|
-
-
|
|
293
|
-
|
|
269
|
+
- **Gemini**: `provider: "gemini"` - Default, uses Google AI
|
|
270
|
+
- **OpenAI**: `provider: "openai"` - GPT models
|
|
271
|
+
- **Claude**: `provider: "claude"` - Anthropic models
|
|
272
|
+
|
|
273
|
+
Each provider has optimized prompts and supports custom endpoints.
|
|
294
274
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
-
|
|
298
|
-
-
|
|
275
|
+
## 📋 Requirements
|
|
276
|
+
|
|
277
|
+
- Node.js 16+
|
|
278
|
+
- Git repository
|
|
279
|
+
- Gemini API key
|
|
280
|
+
|
|
281
|
+
## Security
|
|
282
|
+
|
|
283
|
+
- API keys stored locally (not in your repo)
|
|
284
|
+
- Have to make an .env file for the credentials
|
|
285
|
+
- No data sent to third parties except Google Gemini
|
|
286
|
+
- Code diffs analyzed locally before sending
|
|
287
|
+
|
|
288
|
+
## 🐛 Troubleshooting
|
|
289
|
+
|
|
290
|
+
### Common Issues
|
|
291
|
+
|
|
292
|
+
**"No configuration found"**
|
|
293
|
+
```bash
|
|
294
|
+
codeflow-hook config -k YOUR_API_KEY
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
**Hooks not running**
|
|
298
|
+
```bash
|
|
299
|
+
- **Design Pattern Compliance**: Validation against organizational architectural standards
|
|
300
|
+
- **Coupling Analysis**: Detection of tight coupling and circular dependencies
|
|
301
|
+
- **Layer Architecture**: Enforcement of proper separation between presentation, business logic, and data layers
|
|
302
|
+
- **Complexity Assessment**: Monitoring of code complexity and maintainability metrics
|
|
303
|
+
|
|
304
|
+
**⚡ Performance Agent**:
|
|
305
|
+
- **Algorithm Analysis**: Detection of inefficient algorithms and time/space complexity issues
|
|
306
|
+
- **Memory Optimization**: Identification of memory leaks and inefficient data structures
|
|
307
|
+
- **I/O Optimization**: Analysis of database queries, file operations, and network calls
|
|
308
|
+
- **Caching Opportunities**: Recommendations for implementing caching strategies
|
|
309
|
+
|
|
310
|
+
**✨ Quality Agent**:
|
|
311
|
+
- **Code Style Enforcement**: Automated linting and formatting consistency checks
|
|
312
|
+
- **Documentation Analysis**: Validation of code comments, JSDoc, and README completeness
|
|
313
|
+
- **Test Coverage Assessment**: Analysis of unit test coverage and quality
|
|
314
|
+
- **Dead Code Detection**: Identification of unused functions, variables, and imports
|
|
299
315
|
|
|
300
316
|
### **Federated Data Architecture**
|
|
301
317
|
Enterprise-scale data management across distributed repositories:
|
|
@@ -482,7 +498,9 @@ Built with ❤️ using enterprise-grade technologies:
|
|
|
482
498
|
|
|
483
499
|
### **Core Intelligence Stack**
|
|
484
500
|
- **Multi-Modal AI Integration**: Google Gemini, OpenAI GPT-4, Anthropic Claude
|
|
485
|
-
- **Distributed Graph Database**:
|
|
501
|
+
- **Distributed Graph Database**: Amazon Neptune for Enterprise Knowledge Graph operations
|
|
502
|
+
- **Ingestion & Query Services**: Microservices architecture with GraphQL APIs
|
|
503
|
+
- **Autonomous Agent Network**: Specialized agents for Security, Architecture, Performance, and Quality analysis
|
|
486
504
|
- **Federated Learning Infrastructure**: PyTorch and TensorFlow for ML model training
|
|
487
505
|
- **Container Orchestration**: Kubernetes for enterprise-scale deployment
|
|
488
506
|
|
package/bin/codeflow-hook.js
CHANGED
|
@@ -8,11 +8,10 @@ import fs from 'fs';
|
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import os from 'os'; // Make sure os is imported
|
|
10
10
|
import readline from 'readline';
|
|
11
|
-
import { indexProject } from './rag.js';
|
|
12
11
|
import { orchestrateReview } from './agents.js';
|
|
13
12
|
|
|
14
13
|
// Import CLI integration service
|
|
15
|
-
import { indexProject, analyzeDiff } from '../
|
|
14
|
+
import { indexProject, analyzeDiff } from '../lib/cli-integration/dist/index.js';
|
|
16
15
|
|
|
17
16
|
// Export for use in agents module
|
|
18
17
|
export { callAIProvider };
|
|
@@ -344,6 +343,92 @@ program
|
|
|
344
343
|
}
|
|
345
344
|
});
|
|
346
345
|
|
|
346
|
+
// Run pipeline simulation (Enhanced Frontend Integration)
|
|
347
|
+
program
|
|
348
|
+
.command('simulate')
|
|
349
|
+
.description('Run configurable CI/CD pipeline simulation')
|
|
350
|
+
.argument('[template]', 'Pipeline template ID (nodejs-basic, enterprise-advanced, fast-dev, chaotic-test, microservices-parallel)')
|
|
351
|
+
.option('-c, --config <file>', 'Custom pipeline configuration JSON file')
|
|
352
|
+
.option('-o, --output <file>', 'Output results to JSON file')
|
|
353
|
+
.option('-m, --mode <mode>', 'Simulation mode (REALISTIC, FAST, DETERMINISTIC, CHAOTIC)', 'REALISTIC')
|
|
354
|
+
.option('--commit-message <message>', 'Custom commit message for simulation')
|
|
355
|
+
.option('--json', 'Output results as JSON only')
|
|
356
|
+
.action(async (template, options) => {
|
|
357
|
+
try {
|
|
358
|
+
let pipelineConfig;
|
|
359
|
+
|
|
360
|
+
// Load configuration from file or template
|
|
361
|
+
if (options.config) {
|
|
362
|
+
console.log(chalk.blue(`📄 Loading pipeline config from: ${options.config}`));
|
|
363
|
+
const fs = await import('fs/promises');
|
|
364
|
+
const configData = await fs.readFile(options.config, 'utf8');
|
|
365
|
+
pipelineConfig = JSON.parse(configData);
|
|
366
|
+
} else {
|
|
367
|
+
const templateId = template || 'nodejs-basic';
|
|
368
|
+
console.log(chalk.blue(`🎯 Using pipeline template: ${templateId}`));
|
|
369
|
+
|
|
370
|
+
// Import simulation engine and config manager dynamically
|
|
371
|
+
const { PipelineConfigManager } = await import('../lib/cli-integration/dist/pipelineConfigs.js');
|
|
372
|
+
pipelineConfig = PipelineConfigManager.getPipelineById(templateId);
|
|
373
|
+
|
|
374
|
+
if (!pipelineConfig) {
|
|
375
|
+
console.log(chalk.red(`❌ Unknown pipeline template: ${templateId}`));
|
|
376
|
+
console.log(chalk.gray('Available templates:'));
|
|
377
|
+
const templates = PipelineConfigManager.getAvailableTemplates();
|
|
378
|
+
templates.forEach(t => {
|
|
379
|
+
console.log(chalk.gray(` • ${t.id}: ${t.description}`));
|
|
380
|
+
});
|
|
381
|
+
process.exit(1);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// Apply customizations
|
|
386
|
+
if (options.mode) {
|
|
387
|
+
pipelineConfig.settings.mode = options.mode.toUpperCase();
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (options.commitMessage) {
|
|
391
|
+
pipelineConfig.environment = {
|
|
392
|
+
...pipelineConfig.environment,
|
|
393
|
+
COMMIT_MESSAGE: options.commitMessage
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
console.log(chalk.blue(`🚀 Starting pipeline simulation: ${pipelineConfig.name}`));
|
|
398
|
+
console.log(chalk.gray(` Mode: ${pipelineConfig.settings.mode}`));
|
|
399
|
+
console.log(chalk.gray(` Stages: ${pipelineConfig.stages.length}`));
|
|
400
|
+
|
|
401
|
+
const spinner = ora('Running pipeline simulation...').start();
|
|
402
|
+
|
|
403
|
+
// Import and run simulation engine
|
|
404
|
+
const { simulationEngine } = await import('../lib/cli-integration/dist/simulationEngine.js');
|
|
405
|
+
const result = await simulationEngine.executePipeline(pipelineConfig);
|
|
406
|
+
|
|
407
|
+
spinner.succeed('Simulation completed');
|
|
408
|
+
|
|
409
|
+
// Display results
|
|
410
|
+
if (options.json) {
|
|
411
|
+
console.log(JSON.stringify(result, null, 2));
|
|
412
|
+
} else {
|
|
413
|
+
displaySimulationResults(result);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// Save to file if requested
|
|
417
|
+
if (options.output) {
|
|
418
|
+
const fs = await import('fs/promises');
|
|
419
|
+
await fs.writeFile(options.output, JSON.stringify(result, null, 2), 'utf8');
|
|
420
|
+
console.log(chalk.green(`💾 Results saved to: ${options.output}`));
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// Exit with appropriate code
|
|
424
|
+
process.exit(result.status === 'success' ? 0 : 1);
|
|
425
|
+
|
|
426
|
+
} catch (error) {
|
|
427
|
+
console.log(chalk.red(`❌ Simulation failed: ${error.message}`));
|
|
428
|
+
process.exit(1);
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
|
|
347
432
|
// Show status
|
|
348
433
|
program
|
|
349
434
|
.command('status')
|
|
@@ -763,5 +848,100 @@ function displayEKGAnalysisResults(analysis) {
|
|
|
763
848
|
}
|
|
764
849
|
}
|
|
765
850
|
|
|
851
|
+
// Display pipeline simulation results
|
|
852
|
+
function displaySimulationResults(result) {
|
|
853
|
+
if (!result) {
|
|
854
|
+
console.log(chalk.yellow('⚠️ No simulation results available'));
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
// Overall status
|
|
859
|
+
const statusIcon = result.status === 'success' ? '✅' :
|
|
860
|
+
result.status === 'failed' ? '❌' :
|
|
861
|
+
result.status === 'partial' ? '⚠️' : '⏸️';
|
|
862
|
+
const statusColor = result.status === 'success' ? chalk.green :
|
|
863
|
+
result.status === 'failed' ? chalk.red :
|
|
864
|
+
result.status === 'partial' ? chalk.yellow : chalk.gray;
|
|
865
|
+
|
|
866
|
+
console.log(statusColor(`${statusIcon} Pipeline ${result.status.toUpperCase()}`));
|
|
867
|
+
console.log(chalk.blue(`📋 Execution ID: ${result.executionId}`));
|
|
868
|
+
console.log(chalk.gray(`⏱️ Duration: ${(result.metrics.totalDuration / 1000).toFixed(2)}s`));
|
|
869
|
+
console.log();
|
|
870
|
+
|
|
871
|
+
// Pipeline metrics
|
|
872
|
+
console.log(chalk.blue('📊 Pipeline Metrics:'));
|
|
873
|
+
console.log(` 📊 Stages: ${result.metrics.successCount}/${result.metrics.stageCount} passed`);
|
|
874
|
+
if (result.metrics.failureCount > 0) {
|
|
875
|
+
console.log(chalk.red(` ❌ Failed: ${result.metrics.failureCount}`));
|
|
876
|
+
}
|
|
877
|
+
if (result.metrics.skippedCount > 0) {
|
|
878
|
+
console.log(chalk.yellow(` ⏭️ Skipped: ${result.metrics.skippedCount}`));
|
|
879
|
+
}
|
|
880
|
+
console.log(` 📈 Avg Stage Duration: ${(result.metrics.averageStageDuration / 1000).toFixed(2)}s`);
|
|
881
|
+
if (result.metrics.bottleneckStage) {
|
|
882
|
+
console.log(chalk.yellow(` 🐌 Bottleneck: ${result.metrics.bottleneckStage}`));
|
|
883
|
+
}
|
|
884
|
+
console.log();
|
|
885
|
+
|
|
886
|
+
// Resource utilization
|
|
887
|
+
console.log(chalk.blue('💻 Resource Utilization:'));
|
|
888
|
+
console.log(` 🖥️ Avg CPU: ${result.metrics.resourceUtilization.avgCpu}%`);
|
|
889
|
+
console.log(` 🧠 Avg Memory: ${result.metrics.resourceUtilization.avgMemory}MB`);
|
|
890
|
+
console.log(` 🔥 Peak CPU: ${result.metrics.resourceUtilization.peakCpu}%`);
|
|
891
|
+
console.log(` 💾 Peak Memory: ${result.metrics.resourceUtilization.peakMemory}MB`);
|
|
892
|
+
console.log();
|
|
893
|
+
|
|
894
|
+
// Stage details
|
|
895
|
+
console.log(chalk.blue('🔧 Stage Results:'));
|
|
896
|
+
result.stages.forEach(stage => {
|
|
897
|
+
const stageIcon = stage.status === 'SUCCESS' ? '✅' :
|
|
898
|
+
stage.status === 'FAILED' ? '❌' :
|
|
899
|
+
stage.status === 'SKIPPED' ? '⏭️' : '⏳';
|
|
900
|
+
const stageColor = stage.status === 'SUCCESS' ? chalk.green :
|
|
901
|
+
stage.status === 'FAILED' ? chalk.red :
|
|
902
|
+
stage.status === 'SKIPPED' ? chalk.yellow : chalk.gray;
|
|
903
|
+
|
|
904
|
+
const duration = stage.duration ? `${(stage.duration / 1000).toFixed(2)}s` : 'N/A';
|
|
905
|
+
console.log(`${stageColor(` ${stageIcon} ${stage.id}: ${duration}`)}`);
|
|
906
|
+
|
|
907
|
+
// Show metrics if available
|
|
908
|
+
if (stage.metrics) {
|
|
909
|
+
console.log(chalk.gray(` CPU: ${stage.metrics.cpuUsage}%, Mem: ${stage.metrics.memoryUsage}MB`));
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
// Show errors if any
|
|
913
|
+
if (stage.errors && stage.errors.length > 0) {
|
|
914
|
+
stage.errors.forEach(error => {
|
|
915
|
+
console.log(chalk.red(` 💥 ${error.message}`));
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
});
|
|
919
|
+
console.log();
|
|
920
|
+
|
|
921
|
+
// Artifacts
|
|
922
|
+
if (result.artifacts && result.artifacts.length > 0) {
|
|
923
|
+
console.log(chalk.blue('📦 Generated Artifacts:'));
|
|
924
|
+
result.artifacts.forEach(artifact => {
|
|
925
|
+
console.log(` 📄 ${artifact.name} (${(artifact.size / 1024 / 1024).toFixed(2)}MB)`);
|
|
926
|
+
console.log(chalk.gray(` ${artifact.path}`));
|
|
927
|
+
});
|
|
928
|
+
console.log();
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
// Execution logs summary
|
|
932
|
+
if (result.logs && result.logs.length > 0) {
|
|
933
|
+
console.log(chalk.blue('📝 Execution Summary:'));
|
|
934
|
+
// Show last few log lines
|
|
935
|
+
const recentLogs = result.logs.slice(-5);
|
|
936
|
+
recentLogs.forEach(log => {
|
|
937
|
+
console.log(chalk.gray(` ${log}`));
|
|
938
|
+
});
|
|
939
|
+
if (result.logs.length > 5) {
|
|
940
|
+
console.log(chalk.gray(` ... and ${result.logs.length - 5} more log entries`));
|
|
941
|
+
}
|
|
942
|
+
console.log();
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
|
|
766
946
|
// Make sure the final line uses parseAsync
|
|
767
947
|
program.parseAsync(process.argv);
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* CLI Integration Service - Phase 4
|
|
4
|
+
*
|
|
5
|
+
* Bridges the local CLI commands with EKG backend services.
|
|
6
|
+
* Transforms CLI operations from local processing to backend-driven workflows.
|
|
7
|
+
*
|
|
8
|
+
* Key transformations:
|
|
9
|
+
* - `codeflow index` → EKG Ingestion Service webhook simulation
|
|
10
|
+
* - `codeflow analyze-diff` → EKG Query Service context-enhanced analysis
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* CLI Integration Service
|
|
14
|
+
* Provides methods that CLI commands can call to interact with EKG backend
|
|
15
|
+
*/
|
|
16
|
+
export declare class CLIIntegrationService {
|
|
17
|
+
private config;
|
|
18
|
+
private git;
|
|
19
|
+
constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Index repository for EKG - equivalent to `codeflow index`
|
|
22
|
+
*
|
|
23
|
+
* Sends repository URL to EKG Ingestion Service for analysis and graph population
|
|
24
|
+
*/
|
|
25
|
+
indexRepository(options?: {
|
|
26
|
+
repositoryUrl?: string;
|
|
27
|
+
dryRun?: boolean;
|
|
28
|
+
}): Promise<{
|
|
29
|
+
success: boolean;
|
|
30
|
+
repositoryId?: string;
|
|
31
|
+
message: string;
|
|
32
|
+
stats?: {
|
|
33
|
+
indexedFiles: number;
|
|
34
|
+
analysisTime: number;
|
|
35
|
+
webhookAccepted: boolean;
|
|
36
|
+
};
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Analyze code diff with EKG context enhancement
|
|
40
|
+
*
|
|
41
|
+
* Sends diff to Query Service for EKG-enhanced analysis instead of local RAG
|
|
42
|
+
*/
|
|
43
|
+
analyzeDiff(diffContent: string, options?: {
|
|
44
|
+
legacy?: boolean;
|
|
45
|
+
outputFormat?: 'console' | 'json';
|
|
46
|
+
}): Promise<{
|
|
47
|
+
success: boolean;
|
|
48
|
+
analysis: any;
|
|
49
|
+
message: string;
|
|
50
|
+
stats?: {
|
|
51
|
+
ekg_queries: number;
|
|
52
|
+
similar_repos_found: number;
|
|
53
|
+
analysis_time: number;
|
|
54
|
+
};
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* Analyze diff content and extract structured information
|
|
58
|
+
*/
|
|
59
|
+
private analyzeDiffContent;
|
|
60
|
+
/**
|
|
61
|
+
* Query EKG for context on affected files
|
|
62
|
+
*/
|
|
63
|
+
private getEKGContext;
|
|
64
|
+
/**
|
|
65
|
+
* Generate enhanced analysis using EKG context
|
|
66
|
+
*/
|
|
67
|
+
private generateEKGEnhancedAnalysis;
|
|
68
|
+
/**
|
|
69
|
+
* Get current repository information
|
|
70
|
+
*/
|
|
71
|
+
private getRepositoryInfo;
|
|
72
|
+
/**
|
|
73
|
+
* Get list of files that would be indexed
|
|
74
|
+
*/
|
|
75
|
+
private getIndexableFiles;
|
|
76
|
+
/**
|
|
77
|
+
* Make HTTP request to backend service with retry logic
|
|
78
|
+
*/
|
|
79
|
+
private makeBackendRequest;
|
|
80
|
+
/**
|
|
81
|
+
* Make GraphQL request to Query Service
|
|
82
|
+
*/
|
|
83
|
+
private makeGraphQLRequest;
|
|
84
|
+
/**
|
|
85
|
+
* Generate repository ID (similar to ingestion service)
|
|
86
|
+
*/
|
|
87
|
+
private generateRepositoryId;
|
|
88
|
+
/**
|
|
89
|
+
* Get current user information
|
|
90
|
+
*/
|
|
91
|
+
private getCurrentUser;
|
|
92
|
+
/**
|
|
93
|
+
* Detect language from file extension
|
|
94
|
+
*/
|
|
95
|
+
private detectLanguage;
|
|
96
|
+
/**
|
|
97
|
+
* Format error for logging and display
|
|
98
|
+
*/
|
|
99
|
+
private formatError;
|
|
100
|
+
}
|
|
101
|
+
export declare const cliIntegrationService: CLIIntegrationService;
|
|
102
|
+
export declare const indexProject: (options?: {
|
|
103
|
+
repositoryUrl?: string;
|
|
104
|
+
dryRun?: boolean;
|
|
105
|
+
}) => Promise<{
|
|
106
|
+
success: boolean;
|
|
107
|
+
repositoryId?: string;
|
|
108
|
+
message: string;
|
|
109
|
+
stats?: {
|
|
110
|
+
indexedFiles: number;
|
|
111
|
+
analysisTime: number;
|
|
112
|
+
webhookAccepted: boolean;
|
|
113
|
+
};
|
|
114
|
+
}>;
|
|
115
|
+
export declare const analyzeDiff: (diffContent: string, options?: {
|
|
116
|
+
legacy?: boolean;
|
|
117
|
+
outputFormat?: 'console' | 'json';
|
|
118
|
+
}) => Promise<{
|
|
119
|
+
success: boolean;
|
|
120
|
+
analysis: any;
|
|
121
|
+
message: string;
|
|
122
|
+
stats?: {
|
|
123
|
+
ekg_queries: number;
|
|
124
|
+
similar_repos_found: number;
|
|
125
|
+
analysis_time: number;
|
|
126
|
+
};
|
|
127
|
+
}>;
|
|
128
|
+
export default cliIntegrationService;
|