VineGuard Core - Orchestration Engine 🍇

Core orchestration engine for VineGuard AI testing system
VineGuard Core v2.0.1 provides the foundational orchestration engine that powers both the VineGuard CLI and MCP server. It handles task coordination, file monitoring, queue management, and provides a unified interface for all VineGuard operations.
🎯 What is VineGuard Core?
VineGuard Core is the central orchestration engine that:
- ✅ Task Orchestration: Coordinates complex testing workflows across multiple tools
- ✅ File Monitoring: Watches project files for changes and triggers appropriate actions
- ✅ Queue Management: Handles concurrent operations with priority-based task queuing
- ✅ Event System: Provides event-driven architecture for loosely coupled components
- ✅ Configuration Management: Centralized configuration handling across all VineGuard packages
🚀 Installation
npm install vineguard-core
npm install vineguard
npm install vineguard-mcp
📋 Core Features
Orchestration Engine
The core orchestration system manages complex testing workflows:
import { OrchestrationEngine } from 'vineguard-core';
const engine = new OrchestrationEngine({
projectRoot: process.cwd(),
concurrency: 4,
enableFileWatcher: true
});
await engine.initialize();
const result = await engine.executeWorkflow('test-generation', {
target: './src/components',
framework: 'jest'
});
File Monitoring
Automatic file watching and change detection:
import { FileWatcher } from 'vineguard-core';
const watcher = new FileWatcher({
paths: ['src/**/*.{js,ts,tsx}'],
ignore: ['node_modules', 'dist']
});
watcher.on('change', (file) => {
console.log(`File changed: ${file}`);
});
watcher.on('add', (file) => {
console.log(`File added: ${file}`);
});
Task Queue Management
Priority-based task queuing with concurrency control:
import { TaskQueue } from 'vineguard-core';
const queue = new TaskQueue({
concurrency: 3,
defaultPriority: 5
});
await queue.add('security-scan', {
target: './src/auth'
}, { priority: 10 });
await queue.add('test-generation', {
component: './src/Button.tsx'
});
await queue.start();
Event System
Event-driven architecture for component communication:
import { EventBus } from 'vineguard-core';
const events = new EventBus();
events.on('test:generated', (data) => {
console.log(`Tests generated for ${data.component}`);
});
events.on('scan:complete', (results) => {
console.log(`Scan found ${results.issues.length} issues`);
});
events.emit('test:requested', {
component: './src/Button.tsx',
framework: 'jest'
});
Configuration Management
Centralized configuration with validation:
import { ConfigManager } from 'vineguard-core';
const config = new ConfigManager({
configFile: 'vineguard.config.js',
schema: {
frameworks: ['jest', 'playwright'],
analysis: {
depth: 'deep',
includeTests: true
}
}
});
const testFrameworks = config.get('frameworks');
const analysisDepth = config.get('analysis.depth');
config.on('change', (newConfig) => {
console.log('Configuration updated');
});
🛠️ API Reference
OrchestrationEngine
Main orchestration class that coordinates all VineGuard operations.
class OrchestrationEngine {
constructor(options: OrchestrationOptions)
async initialize(): Promise<void>
async executeWorkflow(
workflowName: string,
params: any
): Promise<WorkflowResult>
registerWorkflow(
name: string,
workflow: WorkflowDefinition
): void
getStatus(): EngineStatus
async shutdown(): Promise<void>
}
FileWatcher
File system monitoring with glob pattern support.
class FileWatcher extends EventEmitter {
constructor(options: WatcherOptions)
start(): void
stop(): void
addPaths(patterns: string[]): void
removePaths(patterns: string[]): void
}
TaskQueue
Priority-based task queue with concurrency control.
class TaskQueue extends EventEmitter {
constructor(options: QueueOptions)
async add(
name: string,
data: any,
options?: TaskOptions
): Promise<string>
async start(): Promise<void>
pause(): void
resume(): void
getStats(): QueueStats
}
EventBus
Event system for component communication.
class EventBus extends EventEmitter {
emit(event: string, data?: any): boolean
on(event: string, listener: Function): this
once(event: string, listener: Function): this
off(event: string, listener: Function): this
listenerCount(event: string): number
}
ConfigManager
Configuration management with validation and watching.
class ConfigManager extends EventEmitter {
constructor(options: ConfigOptions)
get(path: string): any
set(path: string, value: any): void
async load(): Promise<void>
async save(): Promise<void>
validate(): ValidationResult
}
⚙️ Configuration
Engine Configuration
Configure the orchestration engine:
export default {
core: {
orchestration: {
concurrency: 4,
defaultTimeout: 30000,
enableFileWatcher: true,
watchPatterns: ['src/**/*.{js,ts,tsx}']
},
queue: {
maxConcurrency: 3,
defaultPriority: 5,
retryAttempts: 3
},
watcher: {
ignorePatterns: [
'node_modules/**',
'dist/**',
'*.log'
],
debounceMs: 100
},
events: {
maxListeners: 20,
enableLogging: true
}
}
};
Environment Variables
export VINEGUARD_CORE_CONCURRENCY="4"
export VINEGUARD_CORE_TIMEOUT="30000"
export VINEGUARD_ENABLE_FILE_WATCHER="true"
export VINEGUARD_QUEUE_CONCURRENCY="3"
export VINEGUARD_QUEUE_RETRY_ATTEMPTS="3"
export VINEGUARD_CORE_DEBUG="true"
export VINEGUARD_CORE_LOG_LEVEL="info"
🔄 Workflow System
Built-in Workflows
VineGuard Core includes several built-in workflows:
project-analysis: Comprehensive project structure and dependency analysis
test-generation: Intelligent test creation based on code analysis
security-scan: Security vulnerability detection and reporting
bug-detection: Code quality and potential bug identification
fix-generation: Automated fix suggestions with regression tests
🐘 PHP Framework Support
VineGuard Core includes comprehensive support for PHP frameworks (Laravel and Phalcon):
Supported Frameworks
-
Laravel (v8.x - v11.x)
- Eloquent models with relationships
- Route detection (web.php, api.php)
- Sanctum/Passport authentication
- Exception handlers
- Middleware detection
-
Phalcon (v4.x - v5.x)
- Phalcon ORM models
- Micro and MVC routing
- Security component detection
- Event-based error handling
PHP Framework Detection
import { PhpFrameworkDetector } from 'vineguard-core';
const detector = new PhpFrameworkDetector();
const info = await detector.detectFramework('./my-laravel-app');
console.log(info.framework);
console.log(info.version);
console.log(info.detectedBy);
PHP Code Parsing
import {
parseLaravelRoutes,
extractEloquentModelProperties,
extractEloquentRelationships
} from 'vineguard-core';
const routes = parseLaravelRoutes(routeFileContent);
console.log(routes);
const properties = extractEloquentModelProperties(modelContent);
console.log(properties.fillable);
console.log(properties.casts);
const relationships = extractEloquentRelationships(modelContent);
console.log(relationships);
PHP Detection in Project Scanner
VineGuard automatically detects PHP frameworks during project scanning:
import { ProjectScanner } from 'vineguard-core';
const scanner = new ProjectScanner();
const result = await scanner.scan('./my-php-project');
console.log(result.framework);
console.log(result.phpRoutes);
console.log(result.authProviders);
console.log(result.dataModels);
console.log(result.errorHandlers);
Custom Workflows
Create custom workflows:
import { OrchestrationEngine, WorkflowDefinition } from 'vineguard-core';
const customWorkflow: WorkflowDefinition = {
name: 'custom-analysis',
description: 'Custom code analysis workflow',
steps: [
{
name: 'scan-files',
tool: 'vineyard-scanner',
params: { depth: 'deep' }
},
{
name: 'analyze-patterns',
tool: 'vine-inspector',
params: { includeMetrics: true }
},
{
name: 'generate-report',
tool: 'harvest-planner',
params: { format: 'detailed' }
}
]
};
const engine = new OrchestrationEngine();
engine.registerWorkflow('custom-analysis', customWorkflow);
🧪 Testing
Running Tests
npm test
npm run test:coverage
npm run test:watch
npm test -- file-watcher.test.ts
Testing Utilities
VineGuard Core provides testing utilities:
import { TestHelper } from 'vineguard-core/testing';
describe('Custom Workflow', () => {
let engine: OrchestrationEngine;
let helper: TestHelper;
beforeEach(async () => {
helper = new TestHelper();
engine = helper.createEngine({
projectRoot: helper.createTempProject()
});
});
it('should execute workflow', async () => {
const result = await engine.executeWorkflow('test-generation', {
target: './test-component.tsx'
});
expect(result.success).toBe(true);
expect(result.generatedTests).toBeDefined();
});
});
🔍 Debugging
Debug Logging
Enable debug logging:
DEBUG=vineguard:core:* npm test
DEBUG=vineguard:core:orchestration npm test
DEBUG=vineguard:core:queue npm test
DEBUG=vineguard:core:watcher npm test
Performance Monitoring
Monitor engine performance:
import { OrchestrationEngine } from 'vineguard-core';
const engine = new OrchestrationEngine({
enableMetrics: true
});
const metrics = engine.getMetrics();
console.log(`Tasks processed: ${metrics.tasksProcessed}`);
console.log(`Average execution time: ${metrics.avgExecutionTime}ms`);
console.log(`Memory usage: ${metrics.memoryUsage}MB`);
🔗 Integration Examples
CLI Integration
How VineGuard CLI uses the core:
import { OrchestrationEngine } from 'vineguard-core';
class VineGuardCLI {
private engine: OrchestrationEngine;
async initialize() {
this.engine = new OrchestrationEngine({
projectRoot: process.cwd(),
enableFileWatcher: false
});
await this.engine.initialize();
}
async analyze(path: string) {
return await this.engine.executeWorkflow('project-analysis', {
target: path
});
}
}
MCP Integration
How VineGuard MCP uses the core:
import { OrchestrationEngine } from 'vineguard-core';
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
class VineGuardMCP {
private engine: OrchestrationEngine;
private server: Server;
async initialize() {
this.engine = new OrchestrationEngine({
projectRoot: process.env.VINEGUARD_PROJECT_ROOT || '.',
enableFileWatcher: true
});
await this.engine.initialize();
this.setupMCPTools();
}
private setupMCPTools() {
this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
tools: [
{
name: 'scan_project',
description: 'Comprehensive project analysis',
inputSchema: { }
}
]
}));
}
}
🤝 Contributing
We welcome contributions to VineGuard Core! Please see our Contributing Guide for details.
Development Setup
git clone https://github.com/idvd20/vineguard.git
cd vineguard/packages/core
npm install
npm run build
npm test
📄 License
MIT License - see LICENSE file for details.
🔗 Related Packages
🔗 Links