@specverse/engines 4.3.4 → 5.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.
Files changed (66) hide show
  1. package/assets/examples/10-api/README.md +3 -3
  2. package/assets/prompts/core/README.md +1 -1
  3. package/dist/inference/core/rule-engine.d.ts +0 -12
  4. package/dist/inference/core/rule-engine.d.ts.map +1 -1
  5. package/dist/inference/core/rule-engine.js +99 -968
  6. package/dist/inference/core/rule-engine.js.map +1 -1
  7. package/dist/inference/core/template-helpers.d.ts +56 -0
  8. package/dist/inference/core/template-helpers.d.ts.map +1 -0
  9. package/dist/inference/core/template-helpers.js +87 -0
  10. package/dist/inference/core/template-helpers.js.map +1 -0
  11. package/dist/inference/logical/generators/service-generator.d.ts.map +1 -1
  12. package/dist/inference/logical/generators/service-generator.js +0 -4
  13. package/dist/inference/logical/generators/service-generator.js.map +1 -1
  14. package/dist/libs/instance-factories/cli/templates/commander/command-generator.js +27 -5
  15. package/dist/libs/instance-factories/scaffolding/templates/generic/package-json-generator.js +1 -1
  16. package/dist/libs/instance-factories/tools/README.md +1 -1
  17. package/dist/libs/instance-factories/tools/mcp.yaml +1 -1
  18. package/dist/libs/instance-factories/tools/templates/mcp/mcp-server-generator.js +336 -116
  19. package/dist/libs/instance-factories/tools/templates/vscode/vscode-extension-generator.js +172 -8
  20. package/dist/libs/instance-factories/tools/vscode.yaml +1 -1
  21. package/libs/instance-factories/cli/templates/commander/command-generator.ts +27 -5
  22. package/libs/instance-factories/scaffolding/templates/generic/package-json-generator.ts +10 -6
  23. package/libs/instance-factories/tools/README.md +1 -1
  24. package/libs/instance-factories/tools/mcp.yaml +1 -1
  25. package/libs/instance-factories/tools/templates/mcp/mcp-server-generator.ts +386 -141
  26. package/libs/instance-factories/tools/templates/vscode/static/extension.ts +9 -2
  27. package/libs/instance-factories/tools/templates/vscode/vscode-extension-generator.ts +246 -10
  28. package/libs/instance-factories/tools/vscode.yaml +1 -1
  29. package/package.json +5 -4
  30. package/libs/instance-factories/tools/templates/mcp/static/docs/DEPLOYMENT_GUIDE.md +0 -630
  31. package/libs/instance-factories/tools/templates/mcp/static/docs/HYBRID_RESOURCE_SYSTEM.md +0 -330
  32. package/libs/instance-factories/tools/templates/mcp/static/docs/deployments/EXTENSION_DEPLOYMENT.md +0 -552
  33. package/libs/instance-factories/tools/templates/mcp/static/docs/deployments/LOCAL_DEPLOYMENT.md +0 -164
  34. package/libs/instance-factories/tools/templates/mcp/static/docs/deployments/WEB_DEPLOYMENT.md +0 -247
  35. package/libs/instance-factories/tools/templates/mcp/static/package.json +0 -94
  36. package/libs/instance-factories/tools/templates/mcp/static/scripts/build-enterprise.js +0 -284
  37. package/libs/instance-factories/tools/templates/mcp/static/scripts/build-extension.js +0 -139
  38. package/libs/instance-factories/tools/templates/mcp/static/scripts/build-local.js +0 -74
  39. package/libs/instance-factories/tools/templates/mcp/static/scripts/build-web.js +0 -156
  40. package/libs/instance-factories/tools/templates/mcp/static/scripts/copy-canonical-files.js +0 -41
  41. package/libs/instance-factories/tools/templates/mcp/static/scripts/test-deployments.js +0 -259
  42. package/libs/instance-factories/tools/templates/mcp/static/scripts/test-hybrid-resources.js +0 -231
  43. package/libs/instance-factories/tools/templates/mcp/static/scripts/test-hybrid-simple.js +0 -196
  44. package/libs/instance-factories/tools/templates/mcp/static/src/controllers/MCPServerController.ts +0 -293
  45. package/libs/instance-factories/tools/templates/mcp/static/src/events/EventEmitter.ts +0 -90
  46. package/libs/instance-factories/tools/templates/mcp/static/src/index.ts +0 -24
  47. package/libs/instance-factories/tools/templates/mcp/static/src/interfaces/ResourceProvider.ts +0 -15
  48. package/libs/instance-factories/tools/templates/mcp/static/src/models/LibrarySuggestion.ts +0 -106
  49. package/libs/instance-factories/tools/templates/mcp/static/src/models/SpecVerseResource.ts +0 -75
  50. package/libs/instance-factories/tools/templates/mcp/static/src/server/mcp-server.ts +0 -239
  51. package/libs/instance-factories/tools/templates/mcp/static/src/services/CLIProxyService.ts +0 -1501
  52. package/libs/instance-factories/tools/templates/mcp/static/src/services/EmbeddedResourcesAdapter.ts +0 -211
  53. package/libs/instance-factories/tools/templates/mcp/static/src/services/EntityModuleService.ts +0 -308
  54. package/libs/instance-factories/tools/templates/mcp/static/src/services/HybridResourcesProvider.ts +0 -210
  55. package/libs/instance-factories/tools/templates/mcp/static/src/services/LibraryToolsService.ts +0 -356
  56. package/libs/instance-factories/tools/templates/mcp/static/src/services/OrchestratorBridge.ts +0 -522
  57. package/libs/instance-factories/tools/templates/mcp/static/src/services/OrchestratorToolsService.ts +0 -530
  58. package/libs/instance-factories/tools/templates/mcp/static/src/services/PromptToolsService.ts +0 -594
  59. package/libs/instance-factories/tools/templates/mcp/static/src/services/ResourcesProviderService.ts +0 -170
  60. package/libs/instance-factories/tools/templates/mcp/static/src/tests/unit/CLIProxyService.init.test.ts +0 -544
  61. package/libs/instance-factories/tools/templates/mcp/static/src/tests/unit/CLIProxyService.test.ts +0 -189
  62. package/libs/instance-factories/tools/templates/mcp/static/src/tests/unit/ResourcesProviderService.test.ts +0 -89
  63. package/libs/instance-factories/tools/templates/mcp/static/src/types/index.ts +0 -110
  64. package/libs/instance-factories/tools/templates/mcp/static/tsconfig.json +0 -28
  65. package/libs/instance-factories/tools/templates/vscode/static/schemas/specverse-v3-schema.json +0 -4279
  66. /package/libs/instance-factories/tools/templates/vscode/static/themes/{specverse-complete-theme.json → specverse-dark-theme.json} +0 -0
@@ -1,522 +0,0 @@
1
- /**
2
- * SpecVerse Orchestrator Bridge for MCP Integration
3
- *
4
- * Provides orchestrator capabilities as MCP tools while maintaining
5
- * compatibility across all deployment environments.
6
- */
7
-
8
- import { EventEmitter } from '../events/EventEmitter.js';
9
-
10
- export interface OrchestratorConfig {
11
- enabled: boolean;
12
- orchestratorPath?: string;
13
- workingDirectory?: string;
14
- autoDetect?: boolean;
15
- logging?: boolean;
16
- mode?: string;
17
- }
18
-
19
- export interface OrchestratorCapabilities {
20
- hasFullOrchestrator: boolean;
21
- availableOperations: string[];
22
- workingDirectory?: string;
23
- sessionSupport: boolean;
24
- inferenceEngine: boolean;
25
- }
26
-
27
- export interface OrchestratorExecutionContext {
28
- operation: 'analyse' | 'create' | 'infer' | 'materialise' | 'realize';
29
- input?: string;
30
- inputPath?: string;
31
- inputType?: 'specification' | 'code' | 'requirements' | 'manifest';
32
- outputPath?: string;
33
- framework?: string;
34
- scale?: 'personal' | 'business' | 'enterprise';
35
- interactive?: boolean;
36
- sessionId?: string;
37
- }
38
-
39
- export interface OrchestratorExecutionResult {
40
- success: boolean;
41
- content: string;
42
- operation: string;
43
- provider?: string;
44
- sessionId?: string;
45
- executionTime: number;
46
- metadata?: {
47
- framework?: string;
48
- scale?: string;
49
- inferenceRules?: number;
50
- processingTime?: number;
51
- error?: boolean;
52
- };
53
- error?: string;
54
- }
55
-
56
- export class OrchestratorBridge {
57
- private config: OrchestratorConfig;
58
- private eventEmitter: EventEmitter;
59
- private capabilities: OrchestratorCapabilities;
60
- private orchestrator: any = null;
61
- private initialized: boolean = false;
62
-
63
- constructor(config: OrchestratorConfig, eventEmitter: EventEmitter) {
64
- this.config = config;
65
- this.eventEmitter = eventEmitter;
66
- this.capabilities = {
67
- hasFullOrchestrator: false,
68
- availableOperations: [],
69
- sessionSupport: false,
70
- inferenceEngine: false
71
- };
72
- }
73
-
74
- /**
75
- * Initialize orchestrator bridge with environment detection
76
- */
77
- async initialize(): Promise<void> {
78
- if (this.initialized) return;
79
-
80
- try {
81
- // Auto-detect orchestrator availability
82
- if (this.config.autoDetect !== false) {
83
- await this.detectOrchestrator();
84
- }
85
-
86
- if (this.config.enabled && this.capabilities.hasFullOrchestrator) {
87
- await this.initializeFullOrchestrator();
88
- } else {
89
- await this.initializeFallbackMode();
90
- }
91
-
92
- this.initialized = true;
93
- this.eventEmitter.emit('orchestrator-initialized', {
94
- type: 'orchestrator-initialized',
95
- capabilities: this.capabilities
96
- });
97
-
98
- } catch (error) {
99
- const errorMessage = error instanceof Error ? error.message : String(error);
100
- if (this.config.logging) {
101
- console.warn(`Orchestrator initialization failed: ${errorMessage}`);
102
- }
103
-
104
- // Fall back to limited mode
105
- await this.initializeFallbackMode();
106
- this.initialized = true;
107
- }
108
- }
109
-
110
- /**
111
- * Execute orchestrator operation
112
- */
113
- async execute(context: OrchestratorExecutionContext): Promise<OrchestratorExecutionResult> {
114
- if (!this.initialized) {
115
- throw new Error('Orchestrator bridge not initialized');
116
- }
117
-
118
- const startTime = Date.now();
119
-
120
- try {
121
- let result: OrchestratorExecutionResult;
122
-
123
- if (this.capabilities.hasFullOrchestrator && this.orchestrator) {
124
- result = await this.executeWithFullOrchestrator(context);
125
- } else {
126
- result = await this.executeWithFallback(context);
127
- }
128
-
129
- const executionTime = Date.now() - startTime;
130
- result.executionTime = executionTime;
131
-
132
- this.eventEmitter.emit('orchestrator-execution-completed', {
133
- type: 'orchestrator-execution-completed',
134
- operation: context.operation,
135
- executionTime,
136
- success: result.success
137
- });
138
-
139
- return result;
140
-
141
- } catch (error) {
142
- const executionTime = Date.now() - startTime;
143
- const errorMessage = error instanceof Error ? error.message : String(error);
144
-
145
- this.eventEmitter.emit('orchestrator-execution-failed', {
146
- type: 'orchestrator-execution-failed',
147
- operation: context.operation,
148
- error: errorMessage,
149
- executionTime
150
- });
151
-
152
- return {
153
- success: false,
154
- content: '',
155
- operation: context.operation,
156
- executionTime,
157
- error: errorMessage
158
- };
159
- }
160
- }
161
-
162
- /**
163
- * Get orchestrator capabilities
164
- */
165
- getCapabilities(): OrchestratorCapabilities {
166
- return { ...this.capabilities };
167
- }
168
-
169
- /**
170
- * Check if orchestrator is available
171
- */
172
- isAvailable(): boolean {
173
- return this.initialized && (this.capabilities.hasFullOrchestrator || true); // Always available in fallback mode
174
- }
175
-
176
- /**
177
- * Get supported operations
178
- */
179
- getSupportedOperations(): string[] {
180
- return [...this.capabilities.availableOperations];
181
- }
182
-
183
- // Private methods
184
-
185
- /**
186
- * Detect orchestrator availability in current environment
187
- */
188
- private async detectOrchestrator(): Promise<void> {
189
- try {
190
- // Method 1: Try importing from engine-ai package
191
- const orchestratorPath = this.config.orchestratorPath || '@specverse/engine-ai';
192
-
193
- try {
194
- const orchestratorModule = await import(orchestratorPath);
195
- if (orchestratorModule.SpecVerseOrchestrator) {
196
- this.capabilities.hasFullOrchestrator = true;
197
- if (this.config.logging && this.config.mode !== 'local') {
198
- console.log('Full orchestrator detected via import');
199
- }
200
- return;
201
- }
202
- } catch (importError) {
203
- // Continue with other detection methods
204
- }
205
-
206
- // Method 2: Check if orchestrator exists in parent project structure
207
- const { existsSync } = await import('fs');
208
- const { resolve, join } = await import('path');
209
-
210
- const possiblePaths = [
211
- resolve(process.cwd(), '../../../src/orchestrator'),
212
- resolve(process.cwd(), '../../src/orchestrator'),
213
- resolve(process.cwd(), '../src/orchestrator'),
214
- resolve(process.cwd(), 'src/orchestrator'),
215
- join(process.cwd(), '../../dist/orchestrator')
216
- ];
217
-
218
- for (const path of possiblePaths) {
219
- if (existsSync(path)) {
220
- this.capabilities.hasFullOrchestrator = true;
221
- this.config.orchestratorPath = path;
222
- if (this.config.logging && this.config.mode !== 'local') {
223
- console.log(`Orchestrator detected at: ${path}`);
224
- }
225
- return;
226
- }
227
- }
228
-
229
- // Method 3: Check for global SpecVerse CLI installation
230
- try {
231
- const { execSync } = await import('child_process');
232
- execSync('specverse --version', { stdio: 'pipe' });
233
- this.capabilities.hasFullOrchestrator = true;
234
- if (this.config.logging && this.config.mode !== 'local') {
235
- console.log('Global SpecVerse CLI detected');
236
- }
237
- return;
238
- } catch (cliError) {
239
- // CLI not available
240
- }
241
-
242
- if (this.config.logging && this.config.mode !== 'local') {
243
- console.log('Full orchestrator not detected, using fallback mode');
244
- }
245
- this.capabilities.hasFullOrchestrator = false;
246
-
247
- } catch (error) {
248
- if (this.config.logging) {
249
- console.warn(`Orchestrator detection failed: ${error instanceof Error ? error.message : String(error)}`);
250
- }
251
- this.capabilities.hasFullOrchestrator = false;
252
- }
253
- }
254
-
255
- /**
256
- * Initialize full orchestrator with all capabilities
257
- */
258
- private async initializeFullOrchestrator(): Promise<void> {
259
- try {
260
- // Import orchestrator dynamically with multiple path attempts
261
- let orchestratorModule;
262
- const possiblePaths = [
263
- this.config.orchestratorPath, // User-specified path
264
- '@specverse/engine-ai', // npm package (primary)
265
- '../../dist/orchestrator/index.js', // local package path (fallback)
266
- ].filter(Boolean);
267
-
268
- for (const path of possiblePaths) {
269
- if (!path) continue; // Skip undefined paths
270
- try {
271
- orchestratorModule = await import(path);
272
- if (orchestratorModule.SpecVerseOrchestrator) {
273
- if (this.config.logging) {
274
- console.log(`Successfully loaded orchestrator from: ${path}`);
275
- }
276
- break;
277
- }
278
- } catch (error) {
279
- if (this.config.logging) {
280
- console.debug(`Failed to load orchestrator from ${path}: ${error instanceof Error ? error.message : String(error)}`);
281
- }
282
- continue;
283
- }
284
- }
285
-
286
- if (!orchestratorModule) {
287
- throw new Error('Could not find orchestrator module in any of the expected locations');
288
- }
289
-
290
- if (!orchestratorModule.SpecVerseOrchestrator) {
291
- throw new Error('SpecVerseOrchestrator not found in module');
292
- }
293
-
294
- // Create orchestrator instance
295
- this.orchestrator = new orchestratorModule.SpecVerseOrchestrator();
296
-
297
- // Initialize with default or specified config
298
- await this.orchestrator.initialize();
299
-
300
- // Set capabilities
301
- this.capabilities = {
302
- hasFullOrchestrator: true,
303
- availableOperations: ['analyse', 'create', 'infer', 'materialise', 'realize'],
304
- workingDirectory: this.config.workingDirectory || process.cwd(),
305
- sessionSupport: true,
306
- inferenceEngine: true
307
- };
308
-
309
- if (this.config.logging) {
310
- if (this.config.logging && this.config.mode !== 'local') {
311
- console.log('Full orchestrator initialized successfully');
312
- }
313
- }
314
- if (this.config.logging) {
315
- if (this.config.logging && this.config.mode !== 'local') {
316
- console.log(`Available operations: ${this.capabilities.availableOperations.join(', ')}`);
317
- }
318
- }
319
-
320
- } catch (error) {
321
- throw new Error(`Failed to initialize full orchestrator: ${error instanceof Error ? error.message : String(error)}`);
322
- }
323
- }
324
-
325
- /**
326
- * Initialize fallback mode with limited capabilities
327
- */
328
- private async initializeFallbackMode(): Promise<void> {
329
- this.capabilities = {
330
- hasFullOrchestrator: false,
331
- availableOperations: ['create', 'analyse'], // Basic operations available via prompts
332
- workingDirectory: this.config.workingDirectory || process.cwd(),
333
- sessionSupport: false,
334
- inferenceEngine: false
335
- };
336
-
337
- if (this.config.logging) {
338
- if (this.config.logging && this.config.mode !== 'local') {
339
- console.log('Orchestrator bridge initialized in fallback mode');
340
- }
341
- }
342
- if (this.config.logging) {
343
- if (this.config.logging && this.config.mode !== 'local') {
344
- console.log(`Limited operations: ${this.capabilities.availableOperations.join(', ')}`);
345
- }
346
- }
347
- }
348
-
349
- /**
350
- * Execute operation with full orchestrator
351
- */
352
- private async executeWithFullOrchestrator(context: OrchestratorExecutionContext): Promise<OrchestratorExecutionResult> {
353
- try {
354
- const orchestrationContext = {
355
- operation: context.operation,
356
- input: context.input,
357
- inputPath: context.inputPath,
358
- inputType: context.inputType,
359
- outputPath: context.outputPath,
360
- framework: context.framework,
361
- scale: context.scale || 'business',
362
- interactive: context.interactive || false,
363
- sessionId: context.sessionId
364
- };
365
-
366
- if (this.config.logging) {
367
- if (this.config.logging && this.config.mode !== 'local') {
368
- console.log(`Executing ${context.operation} with full orchestrator...`);
369
- }
370
- }
371
-
372
- const result = await this.orchestrator.execute(orchestrationContext);
373
-
374
- return {
375
- success: true,
376
- content: result.content,
377
- operation: context.operation,
378
- provider: result.provider,
379
- sessionId: result.sessionId,
380
- executionTime: 0, // Will be set by caller
381
- metadata: result.metadata
382
- };
383
-
384
- } catch (error) {
385
- const errorMessage = error instanceof Error ? error.message : String(error);
386
- if (this.config.logging) {
387
- console.error(`Full orchestrator execution failed: ${errorMessage}`);
388
- }
389
-
390
- return {
391
- success: false,
392
- content: '',
393
- operation: context.operation,
394
- executionTime: 0,
395
- error: errorMessage
396
- };
397
- }
398
- }
399
-
400
- /**
401
- * Execute operation with fallback implementation
402
- */
403
- private async executeWithFallback(context: OrchestratorExecutionContext): Promise<OrchestratorExecutionResult> {
404
- if (this.config.logging) {
405
- if (this.config.logging && this.config.mode !== 'local') {
406
- console.log(`Executing ${context.operation} in fallback mode...`);
407
- }
408
- }
409
-
410
- switch (context.operation) {
411
- case 'create':
412
- return this.executeFallbackCreate(context);
413
- case 'analyse':
414
- return this.executeFallbackAnalyse(context);
415
- case 'infer':
416
- return this.executeFallbackInfer(context);
417
- default:
418
- return {
419
- success: false,
420
- content: '',
421
- operation: context.operation,
422
- executionTime: 0,
423
- error: `Operation '${context.operation}' not supported in fallback mode. Full orchestrator required.`
424
- };
425
- }
426
- }
427
-
428
- private async executeFallbackCreate(context: OrchestratorExecutionContext): Promise<OrchestratorExecutionResult> {
429
- // Fallback create operation - return structured message indicating prompt expansion needed
430
- const content = `# SpecVerse Creation (Fallback Mode)
431
-
432
- **Requirements**: ${context.input || 'No requirements provided'}
433
- **Scale**: ${context.scale || 'business'}
434
- **Framework**: ${context.framework || 'auto-detect'}
435
-
436
- ## Next Steps
437
-
438
- This operation requires the full SpecVerse orchestrator for AI-powered specification creation.
439
-
440
- In fallback mode, you can:
441
- 1. Use the \`get_creation_prompt\` MCP tool to get an expanded prompt
442
- 2. Use that prompt with your AI assistant to create specifications
443
- 3. Use the SpecVerse CLI locally for full orchestrator capabilities
444
-
445
- ## Fallback Specification Template
446
-
447
- \`\`\`yaml
448
- components:
449
- ${context.framework || 'Application'}Component:
450
- models:
451
- # Define your models here based on requirements
452
- ExampleModel:
453
- attributes:
454
- name: String required
455
- description: String optional
456
- relationships:
457
- # Add relationships as needed
458
- \`\`\`
459
-
460
- **Note**: For full AI-powered creation, install the complete SpecVerse toolchain locally.`;
461
-
462
- return {
463
- success: true,
464
- content,
465
- operation: context.operation,
466
- executionTime: 0,
467
- metadata: {
468
- scale: context.scale,
469
- framework: context.framework,
470
- processingTime: 1
471
- }
472
- };
473
- }
474
-
475
- private async executeFallbackAnalyse(context: OrchestratorExecutionContext): Promise<OrchestratorExecutionResult> {
476
- // Fallback analyse operation
477
- const content = `# SpecVerse Analysis (Fallback Mode)
478
-
479
- **Target**: ${context.inputPath || context.input || 'No input provided'}
480
- **Framework**: ${context.framework || 'auto-detect'}
481
-
482
- ## Analysis Summary
483
-
484
- This operation requires the full SpecVerse orchestrator for AI-powered codebase analysis.
485
-
486
- In fallback mode, you can:
487
- 1. Use the \`get_analysis_prompt\` MCP tool to get an expanded analysis prompt
488
- 2. Use that prompt with your AI assistant to analyze codebases
489
- 3. Install the complete SpecVerse toolchain for full orchestrator capabilities
490
-
491
- ## Manual Analysis Steps
492
-
493
- 1. **Identify Models**: Look for data structures, entities, classes
494
- 2. **Map Relationships**: Identify how models relate to each other
495
- 3. **Find Controllers**: Locate API endpoints, request handlers
496
- 4. **Discover Services**: Find business logic, processing functions
497
- 5. **Map Events**: Identify event publishing and handling
498
-
499
- **Note**: For full AI-powered analysis, install the complete SpecVerse toolchain locally.`;
500
-
501
- return {
502
- success: true,
503
- content,
504
- operation: context.operation,
505
- executionTime: 0,
506
- metadata: {
507
- framework: context.framework,
508
- processingTime: 1
509
- }
510
- };
511
- }
512
-
513
- private async executeFallbackInfer(context: OrchestratorExecutionContext): Promise<OrchestratorExecutionResult> {
514
- return {
515
- success: false,
516
- content: '',
517
- operation: context.operation,
518
- executionTime: 0,
519
- error: 'Inference operation requires the full SpecVerse orchestrator with inference engine. Please install the complete SpecVerse toolchain.'
520
- };
521
- }
522
- }