@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,211 +0,0 @@
1
- /**
2
- * EmbeddedResourcesAdapter
3
- * Handles embedded resources for web deployments
4
- */
5
-
6
- import { SpecVerseResourceModel } from '../models/SpecVerseResource.js';
7
- import type { ResourceProvider } from '../interfaces/ResourceProvider.js';
8
- import type { SpecVerseResource, MCPToolResult } from '../types/index.js';
9
-
10
- export interface EmbeddedResourceData {
11
- content: string;
12
- mimeType: string;
13
- size: number;
14
- }
15
-
16
- export interface EmbeddedResourcesMap {
17
- [path: string]: EmbeddedResourceData;
18
- }
19
-
20
- export class EmbeddedResourcesAdapter implements ResourceProvider {
21
- private resourceCatalog: Map<string, SpecVerseResourceModel> = new Map();
22
- private embeddedResources: EmbeddedResourcesMap;
23
- private isInitialized = false;
24
-
25
- constructor(embeddedResources: EmbeddedResourcesMap) {
26
- this.embeddedResources = embeddedResources;
27
- }
28
-
29
- async initializeResources(): Promise<void> {
30
- if (this.isInitialized) {
31
- return;
32
- }
33
-
34
- // Initialize resource catalog with known resources using embedded content
35
- const resources: SpecVerseResource[] = [
36
- {
37
- uri: 'specverse://schema/json',
38
- name: 'SpecVerse v3.1 JSON Schema',
39
- description: 'Complete JSON schema for SpecVerse v3.1 specifications',
40
- mimeType: 'application/json'
41
- },
42
- {
43
- uri: 'specverse://schema/ai-yaml',
44
- name: 'SpecVerse v3.1 AI-Optimized Schema',
45
- description: 'AI-friendly YAML schema with guidance and examples',
46
- mimeType: 'application/x-yaml'
47
- },
48
- {
49
- uri: 'specverse://prompts/create',
50
- name: 'Create Prompt Template',
51
- description: 'Template for generating SpecVerse specifications from requirements',
52
- mimeType: 'application/x-yaml'
53
- },
54
- {
55
- uri: 'specverse://prompts/analyse',
56
- name: 'Analysis Prompt Template',
57
- description: 'Template for extracting specifications from existing code',
58
- mimeType: 'application/x-yaml'
59
- },
60
- {
61
- uri: 'specverse://prompts/materialise',
62
- name: 'Implementation Planning Template',
63
- description: 'Template for creating implementation plans from specifications',
64
- mimeType: 'application/x-yaml'
65
- },
66
- {
67
- uri: 'specverse://prompts/realize',
68
- name: 'Code Generation Template',
69
- description: 'Template for generating source code from specifications',
70
- mimeType: 'application/x-yaml'
71
- },
72
- {
73
- uri: 'specverse://libraries/catalog',
74
- name: 'SpecVerse Library Catalog',
75
- description: 'Complete catalog of available SpecVerse libraries with AI metadata',
76
- mimeType: 'application/x-yaml'
77
- },
78
- {
79
- uri: 'specverse://examples/chat-prompts',
80
- name: 'Chat Prompt Examples',
81
- description: 'Example prompts for terminal/chat-based AI interactions',
82
- mimeType: 'text/markdown'
83
- },
84
- {
85
- uri: 'specverse://examples/api-calls',
86
- name: 'API Integration Examples',
87
- description: 'Examples for API-based AI integrations',
88
- mimeType: 'application/javascript'
89
- }
90
- ];
91
-
92
- for (const resourceData of resources) {
93
- const resource = SpecVerseResourceModel.create(resourceData);
94
- this.resourceCatalog.set(resource.uri, resource);
95
- }
96
-
97
- this.isInitialized = true;
98
- }
99
-
100
- async listResources(): Promise<SpecVerseResource[]> {
101
- await this.initializeResources();
102
-
103
- return Array.from(this.resourceCatalog.values()).map(resource => ({
104
- uri: resource.uri,
105
- name: resource.name,
106
- description: resource.description,
107
- mimeType: resource.mimeType,
108
- content: resource.content,
109
- metadata: resource.metadata
110
- }));
111
- }
112
-
113
- async getResourceContent(uri: string): Promise<string> {
114
- await this.initializeResources();
115
-
116
- const resource = this.resourceCatalog.get(uri);
117
- if (!resource) {
118
- throw new Error(`Resource not found: ${uri}`);
119
- }
120
-
121
- if (resource.isLoaded()) {
122
- return resource.content!;
123
- }
124
-
125
- // Load content from embedded resources
126
- const resourcePath = this.resolveResourcePath(uri);
127
- const embeddedResource = this.embeddedResources[resourcePath];
128
-
129
- if (!embeddedResource) {
130
- throw new Error(`Embedded resource not found: ${resourcePath} for URI: ${uri}`);
131
- }
132
-
133
- // Update resource with loaded content
134
- const updatedResource = resource.withContent(embeddedResource.content);
135
- this.resourceCatalog.set(uri, updatedResource);
136
-
137
- return embeddedResource.content;
138
- }
139
-
140
- async readResource(uri: string): Promise<MCPToolResult> {
141
- try {
142
- const content = await this.getResourceContent(uri);
143
- const resource = this.resourceCatalog.get(uri)!;
144
-
145
- return {
146
- content: [{
147
- type: 'resource',
148
- resource: {
149
- uri: resource.uri,
150
- name: resource.name,
151
- description: resource.description,
152
- mimeType: resource.mimeType,
153
- content
154
- }
155
- }]
156
- };
157
- } catch (error) {
158
- return {
159
- content: [{
160
- type: 'text',
161
- text: `Error reading resource: ${error instanceof Error ? error.message : String(error)}`
162
- }],
163
- isError: true
164
- };
165
- }
166
- }
167
-
168
- private resolveResourcePath(uri: string): string {
169
- switch (uri) {
170
- case 'specverse://schema/json':
171
- return 'schemas/SPECVERSE-SCHEMA.json';
172
- case 'specverse://schema/ai-yaml':
173
- return 'schemas/specverse-ai.yaml';
174
- case 'specverse://prompts/create':
175
- return 'prompts/create.prompt.yaml';
176
- case 'specverse://prompts/analyse':
177
- return 'prompts/analyse.prompt.yaml';
178
- case 'specverse://prompts/materialise':
179
- return 'prompts/materialise.prompt.yaml';
180
- case 'specverse://prompts/realize':
181
- return 'prompts/realize.prompt.yaml';
182
- case 'specverse://libraries/catalog':
183
- return 'libraries/catalog/library-catalog.yaml';
184
- case 'specverse://examples/chat-prompts':
185
- return 'examples/chat-prompts/ecommerce-store-example.md';
186
- case 'specverse://examples/api-calls':
187
- return 'examples/api-calls/orchestrator-workflow-example.js';
188
- default:
189
- throw new Error(`Unknown resource URI: ${uri}`);
190
- }
191
- }
192
-
193
- isResourceAvailable(uri: string): boolean {
194
- return this.resourceCatalog.has(uri);
195
- }
196
-
197
- getCachedResourceCount(): number {
198
- return Array.from(this.resourceCatalog.values()).filter(r => r.isLoaded()).length;
199
- }
200
-
201
- getEmbeddedResourcesInfo(): { count: number; totalSize: number; paths: string[] } {
202
- const paths = Object.keys(this.embeddedResources);
203
- const totalSize = Object.values(this.embeddedResources).reduce((sum, res) => sum + res.size, 0);
204
-
205
- return {
206
- count: paths.length,
207
- totalSize,
208
- paths
209
- };
210
- }
211
- }
@@ -1,308 +0,0 @@
1
- /**
2
- * EntityModuleService
3
- *
4
- * Provides entity module metadata as MCP resources and tools.
5
- * Loads the entity registry from @specverse/engine-entities and exposes:
6
- * - Entity module registry (all modules, their facets, dependencies)
7
- * - Convention grammars per entity (what behavioural constraints are available)
8
- * - Inference rules per entity (what gets generated from what)
9
- * - Diagram plugins per entity
10
- * - Behavioural constraint expansion (tool)
11
- */
12
-
13
- import type { SpecVerseResource, MCPToolResult } from '../types/index.js';
14
-
15
- interface EntityModuleInfo {
16
- name: string;
17
- type: string;
18
- version: string;
19
- dependsOn: string[];
20
- hasConventionProcessor: boolean;
21
- inferenceRuleCount: number;
22
- inferenceRules: Array<{ id: string; description: string; triggeredBy: string; generates?: string[] }>;
23
- diagramPlugins: Array<{ type: string; variants?: string[] }>;
24
- generatorCount: number;
25
- }
26
-
27
- interface ConventionInfo {
28
- entity: string;
29
- domain: string;
30
- conventions: Array<{
31
- name: string;
32
- pattern: string;
33
- description: string;
34
- expandsTo: string;
35
- }>;
36
- }
37
-
38
- export class EntityModuleService {
39
- private registry: any = null;
40
- private behaviouralProcessor: any = null;
41
- private loaded = false;
42
-
43
- /**
44
- * Attempt to load the entity registry from @specverse/engine-entities.
45
- * Fails gracefully if not available.
46
- */
47
- async initialize(): Promise<boolean> {
48
- try {
49
- // Dynamic imports — paths resolved at runtime, not compile time
50
- // The MCP server sits in tools/specverse-mcp/ but needs to reach src/entities/
51
- const { resolve, dirname } = await import('path');
52
- const { fileURLToPath } = await import('url');
53
- const baseDir = resolve(dirname(fileURLToPath(import.meta.url)), '..', '..', '..');
54
-
55
- const entitiesPath = resolve(baseDir, 'dist', 'entities', 'index.js');
56
- const conventionPath = resolve(baseDir, 'dist', 'entities', '_shared', 'behaviour', 'convention-processor.js');
57
-
58
- const entitiesModule = await import(entitiesPath);
59
- entitiesModule.bootstrapEntityModules();
60
- this.registry = entitiesModule.getEntityRegistry();
61
-
62
- const { BehaviouralConventionProcessor } = await import(conventionPath);
63
- this.behaviouralProcessor = new BehaviouralConventionProcessor();
64
-
65
- // Load grammars from entity module source (grammar.yaml files)
66
- const entitiesDir = resolve(baseDir, 'src', 'entities');
67
- this.behaviouralProcessor.loadGrammarsFromEntities(entitiesDir);
68
-
69
- this.loaded = true;
70
- return true;
71
- } catch (error) {
72
- // Entity modules not available in this deployment context
73
- this.loaded = false;
74
- return false;
75
- }
76
- }
77
-
78
- isAvailable(): boolean {
79
- return this.loaded;
80
- }
81
-
82
- /**
83
- * Get entity module metadata for all registered modules.
84
- */
85
- getEntityModules(): EntityModuleInfo[] {
86
- if (!this.registry) return [];
87
-
88
- const modules = this.registry.getInDependencyOrder();
89
- return modules.map((mod: any) => ({
90
- name: mod.name,
91
- type: mod.type,
92
- version: mod.version,
93
- dependsOn: mod.dependsOn || [],
94
- hasConventionProcessor: !!mod.conventionProcessor,
95
- inferenceRuleCount: mod.inferenceRules?.length || 0,
96
- inferenceRules: (mod.inferenceRules || []).map((r: any) => ({
97
- id: r.id,
98
- description: r.description,
99
- triggeredBy: r.triggeredBy,
100
- generates: r.generates,
101
- })),
102
- diagramPlugins: mod.diagramPlugins || [],
103
- generatorCount: mod.generators?.length || 0,
104
- }));
105
- }
106
-
107
- /**
108
- * Get behavioural convention grammars for all entities.
109
- */
110
- getConventionGrammars(): ConventionInfo[] {
111
- if (!this.behaviouralProcessor) return [];
112
-
113
- return this.behaviouralProcessor.getGrammars().map((g: any) => ({
114
- entity: g.entity,
115
- domain: g.domain,
116
- conventions: Object.values(g.conventions).map((c: any) => ({
117
- name: c.name,
118
- pattern: c.pattern,
119
- description: c.description,
120
- expandsTo: c.expandsTo,
121
- })),
122
- }));
123
- }
124
-
125
- /**
126
- * Expand a behavioural constraint string.
127
- */
128
- expandConstraint(input: string): { success: boolean; result?: any; error?: string } {
129
- if (!this.behaviouralProcessor) {
130
- return { success: false, error: 'Behavioural convention processor not available' };
131
- }
132
-
133
- const result = this.behaviouralProcessor.expand(input);
134
- if (result) {
135
- return { success: true, result };
136
- }
137
- return { success: false, error: `No matching convention pattern for: "${input}"` };
138
- }
139
-
140
- /**
141
- * Generate MCP resources from entity module metadata.
142
- */
143
- generateResources(): SpecVerseResource[] {
144
- if (!this.loaded) return [];
145
-
146
- const resources: SpecVerseResource[] = [];
147
-
148
- // 1. Entity registry overview
149
- const modules = this.getEntityModules();
150
- resources.push({
151
- uri: 'specverse://entities/registry',
152
- name: 'Entity Module Registry',
153
- description: `All ${modules.length} registered entity modules with their facets, dependencies, and capabilities`,
154
- mimeType: 'application/json',
155
- content: JSON.stringify({ entityModules: modules }, null, 2),
156
- });
157
-
158
- // 2. Behavioural conventions catalog
159
- const grammars = this.getConventionGrammars();
160
- const totalConventions = grammars.reduce((sum, g) => sum + g.conventions.length, 0);
161
- resources.push({
162
- uri: 'specverse://entities/conventions',
163
- name: 'Behavioural Conventions Catalog',
164
- description: `${totalConventions} behavioural conventions across ${grammars.length} entities. Use in constraints: section of .specly files.`,
165
- mimeType: 'application/json',
166
- content: JSON.stringify({ grammars }, null, 2),
167
- });
168
-
169
- // 3. Inference rules summary
170
- const allRules = modules.flatMap(m => m.inferenceRules);
171
- resources.push({
172
- uri: 'specverse://entities/inference-rules',
173
- name: 'Inference Rules Summary',
174
- description: `${allRules.length} inference rules that generate architecture from specifications`,
175
- mimeType: 'application/json',
176
- content: JSON.stringify({ rules: allRules }, null, 2),
177
- });
178
-
179
- // 4. Diagram plugins summary
180
- const allPlugins = modules.flatMap(m =>
181
- m.diagramPlugins.map(p => ({ ...p, entity: m.name }))
182
- );
183
- resources.push({
184
- uri: 'specverse://entities/diagram-plugins',
185
- name: 'Diagram Plugins',
186
- description: `${allPlugins.length} diagram types available for visualization`,
187
- mimeType: 'application/json',
188
- content: JSON.stringify({ plugins: allPlugins }, null, 2),
189
- });
190
-
191
- return resources;
192
- }
193
-
194
- /**
195
- * Generate MCP tools for entity module interaction.
196
- */
197
- generateTools(): any[] {
198
- if (!this.loaded) return [];
199
-
200
- return [
201
- {
202
- name: 'specverse_expand_constraint',
203
- description: 'Expand a behavioural constraint string into a Quint invariant. Example: "models must have attributes"',
204
- inputSchema: {
205
- type: 'object',
206
- properties: {
207
- constraint: {
208
- type: 'string',
209
- description: 'Human-readable constraint to expand (e.g., "models must have attributes")',
210
- },
211
- },
212
- required: ['constraint'],
213
- },
214
- },
215
- {
216
- name: 'specverse_list_conventions',
217
- description: 'List available behavioural conventions for a specific entity type',
218
- inputSchema: {
219
- type: 'object',
220
- properties: {
221
- entity: {
222
- type: 'string',
223
- description: 'Entity type (e.g., "models", "controllers", "services")',
224
- },
225
- },
226
- required: ['entity'],
227
- },
228
- },
229
- {
230
- name: 'specverse_entity_info',
231
- description: 'Get detailed metadata about an entity module (conventions, inference rules, diagram plugins)',
232
- inputSchema: {
233
- type: 'object',
234
- properties: {
235
- entity: {
236
- type: 'string',
237
- description: 'Entity name (e.g., "models", "controllers", "deployments")',
238
- },
239
- },
240
- required: ['entity'],
241
- },
242
- },
243
- ];
244
- }
245
-
246
- /**
247
- * Execute an entity module tool.
248
- */
249
- async executeTool(name: string, args: Record<string, any>): Promise<MCPToolResult> {
250
- switch (name) {
251
- case 'specverse_expand_constraint': {
252
- const result = this.expandConstraint(args.constraint);
253
- return {
254
- content: [{
255
- type: 'text',
256
- text: JSON.stringify(result, null, 2),
257
- }],
258
- };
259
- }
260
-
261
- case 'specverse_list_conventions': {
262
- const grammars = this.getConventionGrammars();
263
- const grammar = grammars.find(g => g.entity === args.entity);
264
- if (!grammar) {
265
- return {
266
- content: [{
267
- type: 'text',
268
- text: `No conventions found for entity "${args.entity}". Available: ${grammars.map(g => g.entity).join(', ')}`,
269
- }],
270
- };
271
- }
272
- return {
273
- content: [{
274
- type: 'text',
275
- text: JSON.stringify(grammar, null, 2),
276
- }],
277
- };
278
- }
279
-
280
- case 'specverse_entity_info': {
281
- const modules = this.getEntityModules();
282
- const mod = modules.find(m => m.name === args.entity);
283
- if (!mod) {
284
- return {
285
- content: [{
286
- type: 'text',
287
- text: `Entity "${args.entity}" not found. Available: ${modules.map(m => m.name).join(', ')}`,
288
- }],
289
- };
290
- }
291
- return {
292
- content: [{
293
- type: 'text',
294
- text: JSON.stringify(mod, null, 2),
295
- }],
296
- };
297
- }
298
-
299
- default:
300
- return {
301
- content: [{
302
- type: 'text',
303
- text: `Unknown entity module tool: ${name}`,
304
- }],
305
- };
306
- }
307
- }
308
- }