@specverse/engines 4.3.5 → 5.0.1

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 (68) 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/inference/ui-contracts/rules/lifecycle-state-visible-in-detail.d.ts +9 -7
  15. package/dist/inference/ui-contracts/rules/lifecycle-state-visible-in-detail.d.ts.map +1 -1
  16. package/dist/inference/ui-contracts/rules/lifecycle-state-visible-in-detail.js +27 -9
  17. package/dist/inference/ui-contracts/rules/lifecycle-state-visible-in-detail.js.map +1 -1
  18. package/dist/libs/instance-factories/cli/templates/commander/command-generator.js +27 -5
  19. package/dist/libs/instance-factories/tools/README.md +1 -1
  20. package/dist/libs/instance-factories/tools/mcp.yaml +1 -1
  21. package/dist/libs/instance-factories/tools/templates/mcp/mcp-server-generator.js +342 -116
  22. package/dist/libs/instance-factories/tools/templates/vscode/vscode-extension-generator.js +172 -8
  23. package/dist/libs/instance-factories/tools/vscode.yaml +1 -1
  24. package/libs/instance-factories/cli/templates/commander/command-generator.ts +27 -5
  25. package/libs/instance-factories/tools/README.md +1 -1
  26. package/libs/instance-factories/tools/mcp.yaml +1 -1
  27. package/libs/instance-factories/tools/templates/mcp/mcp-server-generator.ts +392 -141
  28. package/libs/instance-factories/tools/templates/vscode/static/extension.ts +9 -2
  29. package/libs/instance-factories/tools/templates/vscode/vscode-extension-generator.ts +246 -10
  30. package/libs/instance-factories/tools/vscode.yaml +1 -1
  31. package/package.json +5 -4
  32. package/libs/instance-factories/tools/templates/mcp/static/docs/DEPLOYMENT_GUIDE.md +0 -630
  33. package/libs/instance-factories/tools/templates/mcp/static/docs/HYBRID_RESOURCE_SYSTEM.md +0 -330
  34. package/libs/instance-factories/tools/templates/mcp/static/docs/deployments/EXTENSION_DEPLOYMENT.md +0 -552
  35. package/libs/instance-factories/tools/templates/mcp/static/docs/deployments/LOCAL_DEPLOYMENT.md +0 -164
  36. package/libs/instance-factories/tools/templates/mcp/static/docs/deployments/WEB_DEPLOYMENT.md +0 -247
  37. package/libs/instance-factories/tools/templates/mcp/static/package.json +0 -94
  38. package/libs/instance-factories/tools/templates/mcp/static/scripts/build-enterprise.js +0 -284
  39. package/libs/instance-factories/tools/templates/mcp/static/scripts/build-extension.js +0 -139
  40. package/libs/instance-factories/tools/templates/mcp/static/scripts/build-local.js +0 -74
  41. package/libs/instance-factories/tools/templates/mcp/static/scripts/build-web.js +0 -156
  42. package/libs/instance-factories/tools/templates/mcp/static/scripts/copy-canonical-files.js +0 -41
  43. package/libs/instance-factories/tools/templates/mcp/static/scripts/test-deployments.js +0 -259
  44. package/libs/instance-factories/tools/templates/mcp/static/scripts/test-hybrid-resources.js +0 -231
  45. package/libs/instance-factories/tools/templates/mcp/static/scripts/test-hybrid-simple.js +0 -196
  46. package/libs/instance-factories/tools/templates/mcp/static/src/controllers/MCPServerController.ts +0 -293
  47. package/libs/instance-factories/tools/templates/mcp/static/src/events/EventEmitter.ts +0 -90
  48. package/libs/instance-factories/tools/templates/mcp/static/src/index.ts +0 -24
  49. package/libs/instance-factories/tools/templates/mcp/static/src/interfaces/ResourceProvider.ts +0 -15
  50. package/libs/instance-factories/tools/templates/mcp/static/src/models/LibrarySuggestion.ts +0 -106
  51. package/libs/instance-factories/tools/templates/mcp/static/src/models/SpecVerseResource.ts +0 -75
  52. package/libs/instance-factories/tools/templates/mcp/static/src/server/mcp-server.ts +0 -239
  53. package/libs/instance-factories/tools/templates/mcp/static/src/services/CLIProxyService.ts +0 -1501
  54. package/libs/instance-factories/tools/templates/mcp/static/src/services/EmbeddedResourcesAdapter.ts +0 -211
  55. package/libs/instance-factories/tools/templates/mcp/static/src/services/EntityModuleService.ts +0 -308
  56. package/libs/instance-factories/tools/templates/mcp/static/src/services/HybridResourcesProvider.ts +0 -210
  57. package/libs/instance-factories/tools/templates/mcp/static/src/services/LibraryToolsService.ts +0 -356
  58. package/libs/instance-factories/tools/templates/mcp/static/src/services/OrchestratorBridge.ts +0 -522
  59. package/libs/instance-factories/tools/templates/mcp/static/src/services/OrchestratorToolsService.ts +0 -530
  60. package/libs/instance-factories/tools/templates/mcp/static/src/services/PromptToolsService.ts +0 -594
  61. package/libs/instance-factories/tools/templates/mcp/static/src/services/ResourcesProviderService.ts +0 -170
  62. package/libs/instance-factories/tools/templates/mcp/static/src/tests/unit/CLIProxyService.init.test.ts +0 -544
  63. package/libs/instance-factories/tools/templates/mcp/static/src/tests/unit/CLIProxyService.test.ts +0 -189
  64. package/libs/instance-factories/tools/templates/mcp/static/src/tests/unit/ResourcesProviderService.test.ts +0 -89
  65. package/libs/instance-factories/tools/templates/mcp/static/src/types/index.ts +0 -110
  66. package/libs/instance-factories/tools/templates/mcp/static/tsconfig.json +0 -28
  67. package/libs/instance-factories/tools/templates/vscode/static/schemas/specverse-v3-schema.json +0 -4279
  68. /package/libs/instance-factories/tools/templates/vscode/static/themes/{specverse-complete-theme.json → specverse-dark-theme.json} +0 -0
@@ -1,293 +0,0 @@
1
- /**
2
- * MCPServerController
3
- * Clean implementation with only dynamic CLI tools
4
- */
5
-
6
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
7
- import {
8
- ListResourcesRequestSchema,
9
- ReadResourceRequestSchema,
10
- ListToolsRequestSchema,
11
- CallToolRequestSchema
12
- } from '@modelcontextprotocol/sdk/types.js';
13
-
14
- import { HybridResourcesProvider } from '../services/HybridResourcesProvider.js';
15
- import { CLIProxyService } from '../services/CLIProxyService.js';
16
- import { EntityModuleService } from '../services/EntityModuleService.js';
17
- import { EventEmitter } from '../events/EventEmitter.js';
18
- import type {
19
- MCPServerConfig,
20
- SpecVerseResource,
21
- ServerStartedEvent,
22
- ResourceRequestedEvent,
23
- ErrorOccurredEvent
24
- } from '../types/index.js';
25
-
26
- export class MCPServerController {
27
- private server: Server;
28
- private config: MCPServerConfig;
29
- private resourcesProvider: HybridResourcesProvider;
30
- private cliProxy: CLIProxyService;
31
- private entityModuleService: EntityModuleService;
32
- private eventEmitter: EventEmitter;
33
-
34
- constructor(config: MCPServerConfig) {
35
- this.config = config;
36
- this.eventEmitter = new EventEmitter();
37
-
38
- // Initialize server
39
- this.server = new Server({
40
- name: 'specverse-dynamic-cli',
41
- version: '1.0.0'
42
- }, {
43
- capabilities: {
44
- resources: {},
45
- tools: {}
46
- }
47
- });
48
-
49
- // Initialize services
50
- this.resourcesProvider = new HybridResourcesProvider({
51
- mode: 'auto',
52
- resourcesPath: config.resources_path
53
- });
54
-
55
- // Initialize CLI proxy for dynamic command discovery - this is our main service!
56
- this.cliProxy = new CLIProxyService();
57
-
58
- // Initialize entity module service for metadata exposure
59
- this.entityModuleService = new EntityModuleService();
60
-
61
- this.setupHandlers();
62
- }
63
-
64
- async listResources(): Promise<SpecVerseResource[]> {
65
- try {
66
- const startTime = Date.now();
67
- const resources = await this.resourcesProvider.listResources();
68
-
69
- // Add entity module resources if available
70
- if (this.entityModuleService.isAvailable()) {
71
- resources.push(...this.entityModuleService.generateResources());
72
- }
73
-
74
- this.eventEmitter.emit('resource-requested', {
75
- uri: 'LIST_ALL',
76
- requestTime: new Date()
77
- } as ResourceRequestedEvent);
78
-
79
- if (this.config.logging && this.config.mode !== 'local' && process.env.MCP_DEBUG) {
80
- console.error(`Listed ${resources.length} resources in ${Date.now() - startTime}ms`);
81
- }
82
-
83
- return resources;
84
- } catch (error) {
85
- this.eventEmitter.emit('error-occurred', {
86
- operation: 'listResources',
87
- error: error instanceof Error ? error.message : String(error)
88
- } as ErrorOccurredEvent);
89
- throw error;
90
- }
91
- }
92
-
93
- async readResource(uri: string): Promise<SpecVerseResource> {
94
- try {
95
- const startTime = Date.now();
96
-
97
- // Check entity module resources first
98
- if (uri.startsWith('specverse://entities/') && this.entityModuleService.isAvailable()) {
99
- const entityResources = this.entityModuleService.generateResources();
100
- const resource = entityResources.find(r => r.uri === uri);
101
- if (resource) {
102
- this.eventEmitter.emit('resource-requested', { uri, requestTime: new Date() } as ResourceRequestedEvent);
103
- return resource;
104
- }
105
- }
106
-
107
- const content = await this.resourcesProvider.getResourceContent(uri);
108
- const resources = await this.resourcesProvider.listResources();
109
- const resource = resources.find(r => r.uri === uri);
110
-
111
- if (!resource) {
112
- throw new Error(`Resource not found: ${uri}`);
113
- }
114
-
115
- this.eventEmitter.emit('resource-requested', {
116
- uri,
117
- requestTime: new Date()
118
- } as ResourceRequestedEvent);
119
-
120
- if (this.config.logging && this.config.mode !== 'local' && process.env.MCP_DEBUG) {
121
- console.error(`Read resource ${uri} in ${Date.now() - startTime}ms`);
122
- }
123
-
124
- return {
125
- ...resource,
126
- content
127
- };
128
- } catch (error) {
129
- this.eventEmitter.emit('error-occurred', {
130
- operation: 'readResource',
131
- error: error instanceof Error ? error.message : String(error),
132
- context: { uri }
133
- } as ErrorOccurredEvent);
134
- throw error;
135
- }
136
- }
137
-
138
- private setupHandlers(): void {
139
- // List resources handler
140
- this.server.setRequestHandler(ListResourcesRequestSchema, async () => {
141
- const resources = await this.listResources();
142
- return { resources };
143
- });
144
-
145
- // Read resource handler
146
- this.server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
147
- const resource = await this.readResource(request.params.uri);
148
- return {
149
- contents: [{
150
- uri: resource.uri,
151
- mimeType: resource.mimeType,
152
- text: resource.content
153
- }]
154
- };
155
- });
156
-
157
- // List tools handler - dynamic CLI tools + entity module tools
158
- this.server.setRequestHandler(ListToolsRequestSchema, async () => {
159
- let dynamicCliTools: any[] = [];
160
- try {
161
- dynamicCliTools = await this.cliProxy.generateMCPTools();
162
- if (this.config.logging && this.config.mode !== 'local' && process.env.MCP_DEBUG) {
163
- console.error(`🔧 Generated ${dynamicCliTools.length} dynamic CLI tools`);
164
- }
165
- } catch (error) {
166
- if (this.config.logging && process.env.MCP_DEBUG) {
167
- console.error('⚠️ Failed to generate dynamic CLI tools:', error);
168
- }
169
- }
170
-
171
- // Add entity module tools
172
- if (this.entityModuleService.isAvailable()) {
173
- dynamicCliTools.push(...this.entityModuleService.generateTools());
174
- }
175
-
176
- return { tools: dynamicCliTools };
177
- });
178
-
179
- // Call tool handler - dynamic CLI tools + entity module tools
180
- this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
181
- try {
182
- const { name, arguments: args } = request.params;
183
-
184
- // Entity module tools
185
- const entityToolNames = ['specverse_expand_constraint', 'specverse_list_conventions', 'specverse_entity_info'];
186
- if (entityToolNames.includes(name) && this.entityModuleService.isAvailable()) {
187
- return await this.entityModuleService.executeTool(name, args || {}) as any;
188
- }
189
-
190
- // Dynamic CLI tools
191
- if (name.startsWith('specverse_')) {
192
- const result = await this.cliProxy.executeCommand(name, args || {});
193
- return { content: result.content };
194
- } else {
195
- return {
196
- content: [{
197
- type: 'text',
198
- text: `Error: Unknown tool '${name}'. Only dynamic CLI tools (prefixed with 'specverse_') are supported.`
199
- }]
200
- };
201
- }
202
- } catch (error) {
203
- return {
204
- content: [{
205
- type: 'text',
206
- text: `Error in tool handler: ${error instanceof Error ? error.message : String(error)}`
207
- }]
208
- };
209
- }
210
- });
211
- }
212
-
213
- /**
214
- * Start the MCP server
215
- */
216
- async start(): Promise<void> {
217
- try {
218
- await this.resourcesProvider.initializeResources();
219
-
220
- // Initialize entity module service (non-blocking, fails gracefully)
221
- const entityAvailable = await this.entityModuleService.initialize();
222
- if (this.config.logging && process.env.MCP_DEBUG) {
223
- if (entityAvailable) {
224
- const modules = this.entityModuleService.getEntityModules();
225
- console.error(`🧩 Entity modules loaded: ${modules.length} modules, ${modules.reduce((s, m) => s + m.inferenceRuleCount, 0)} rules`);
226
- } else {
227
- console.error('⚠️ Entity modules not available in this deployment');
228
- }
229
- }
230
-
231
- this.eventEmitter.emit('server-started', {
232
- serverName: 'SpecVerse Dynamic CLI',
233
- mode: this.config.mode,
234
- timestamp: new Date(),
235
- featuresEnabled: this.config.features,
236
- pid: process.pid
237
- } as ServerStartedEvent);
238
-
239
- if (this.config.logging && process.env.MCP_DEBUG) {
240
- const mode = this.config.mode || 'local';
241
- const resourceCount = this.resourcesProvider.getCachedResourceCount();
242
- console.error(`🚀 SpecVerse MCP Server started in ${mode} mode`);
243
- console.error(`📚 Loaded ${resourceCount} resources`);
244
- console.error(`🔧 Dynamic CLI integration enabled - all tools from CLI`);
245
- }
246
- } catch (error) {
247
- this.eventEmitter.emit('error-occurred', {
248
- operation: 'start',
249
- error: error instanceof Error ? error.message : String(error)
250
- } as ErrorOccurredEvent);
251
- throw error;
252
- }
253
- }
254
-
255
- /**
256
- * Stop the MCP server
257
- */
258
- async stop(): Promise<void> {
259
- try {
260
- await this.server.close();
261
-
262
- if (this.config.logging && process.env.MCP_DEBUG) {
263
- console.error('🛑 SpecVerse MCP Server stopped');
264
- }
265
- } catch (error) {
266
- this.eventEmitter.emit('error-occurred', {
267
- operation: 'stop',
268
- error: error instanceof Error ? error.message : String(error)
269
- } as ErrorOccurredEvent);
270
- throw error;
271
- }
272
- }
273
-
274
- // Methods expected by the main server
275
- getEventEmitter() {
276
- return this.eventEmitter;
277
- }
278
-
279
- async initialize(): Promise<void> {
280
- await this.start();
281
- }
282
-
283
- getServer() {
284
- return this.server;
285
- }
286
-
287
- getMetrics() {
288
- return {
289
- resourceCount: this.resourcesProvider.getCachedResourceCount(),
290
- cliIntegration: true
291
- };
292
- }
293
- }
@@ -1,90 +0,0 @@
1
- /**
2
- * EventEmitter
3
- * Clean implementation for handling application events
4
- */
5
-
6
- import type {
7
- ServerStartedEvent,
8
- ToolCalledEvent,
9
- ResourceRequestedEvent,
10
- ErrorOccurredEvent
11
- } from '../types/index.js';
12
-
13
- export type EventType = 'server-started' | 'tool-called' | 'resource-requested' | 'error-occurred' | 'orchestrator-initialized' | 'orchestrator-execution-completed' | 'orchestrator-execution-failed';
14
-
15
- export interface OrchestratorInitializedEvent {
16
- type: 'orchestrator-initialized';
17
- capabilities: any;
18
- }
19
-
20
- export interface OrchestratorExecutionCompletedEvent {
21
- type: 'orchestrator-execution-completed';
22
- operation: string;
23
- executionTime: number;
24
- success: boolean;
25
- }
26
-
27
- export interface OrchestratorExecutionFailedEvent {
28
- type: 'orchestrator-execution-failed';
29
- operation: string;
30
- error: string;
31
- executionTime: number;
32
- }
33
-
34
- export type EventData = ServerStartedEvent | ToolCalledEvent | ResourceRequestedEvent | ErrorOccurredEvent | OrchestratorInitializedEvent | OrchestratorExecutionCompletedEvent | OrchestratorExecutionFailedEvent;
35
-
36
- export type EventHandler<T = EventData> = (event: T) => void | Promise<void>;
37
-
38
- export class EventEmitter {
39
- private listeners: Map<EventType, EventHandler[]> = new Map();
40
-
41
- on<T extends EventData>(eventType: EventType, handler: EventHandler<T>): void {
42
- if (!this.listeners.has(eventType)) {
43
- this.listeners.set(eventType, []);
44
- }
45
- this.listeners.get(eventType)!.push(handler as EventHandler);
46
- }
47
-
48
- off<T extends EventData>(eventType: EventType, handler: EventHandler<T>): void {
49
- const handlers = this.listeners.get(eventType);
50
- if (handlers) {
51
- const index = handlers.indexOf(handler as EventHandler);
52
- if (index !== -1) {
53
- handlers.splice(index, 1);
54
- }
55
- }
56
- }
57
-
58
- async emit(eventType: EventType, data: EventData): Promise<void> {
59
- const handlers = this.listeners.get(eventType);
60
- if (handlers) {
61
- const promises = handlers.map(handler => {
62
- try {
63
- const result = handler(data);
64
- return Promise.resolve(result);
65
- } catch (error) {
66
- console.error(`Error in event handler for ${eventType}:`, error);
67
- return Promise.resolve();
68
- }
69
- });
70
-
71
- await Promise.allSettled(promises);
72
- }
73
- }
74
-
75
- removeAllListeners(eventType?: EventType): void {
76
- if (eventType) {
77
- this.listeners.delete(eventType);
78
- } else {
79
- this.listeners.clear();
80
- }
81
- }
82
-
83
- listenerCount(eventType: EventType): number {
84
- return this.listeners.get(eventType)?.length || 0;
85
- }
86
-
87
- eventNames(): EventType[] {
88
- return Array.from(this.listeners.keys());
89
- }
90
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * SpecVerse AI Support MCP Server - Clean Implementation
3
- * Main exports for the clean implementation
4
- */
5
-
6
- // Core exports
7
- export { SpecVerseCleanMCPServer } from './server/mcp-server.js';
8
- export { MCPServerController } from './controllers/MCPServerController.js';
9
-
10
- // Service exports
11
- export { ResourcesProviderService } from './services/ResourcesProviderService.js';
12
- export { LibraryToolsService } from './services/LibraryToolsService.js';
13
- export { PromptToolsService } from './services/PromptToolsService.js';
14
-
15
- // Model exports
16
- export { SpecVerseResourceModel } from './models/SpecVerseResource.js';
17
- export { LibrarySuggestionModel } from './models/LibrarySuggestion.js';
18
-
19
- // Event system exports
20
- export { EventEmitter } from './events/EventEmitter.js';
21
- export type { EventType, EventData, EventHandler } from './events/EventEmitter.js';
22
-
23
- // Type exports
24
- export type * from './types/index.js';
@@ -1,15 +0,0 @@
1
- /**
2
- * ResourceProvider Interface
3
- * Common interface for resource providers (filesystem, embedded, hybrid)
4
- */
5
-
6
- import type { SpecVerseResource, MCPToolResult } from '../types/index.js';
7
-
8
- export interface ResourceProvider {
9
- initializeResources(): Promise<void>;
10
- listResources(): Promise<SpecVerseResource[]>;
11
- getResourceContent(uri: string): Promise<string>;
12
- readResource(uri: string): Promise<MCPToolResult>;
13
- isResourceAvailable(uri: string): boolean;
14
- getCachedResourceCount(): number;
15
- }
@@ -1,106 +0,0 @@
1
- /**
2
- * LibrarySuggestion Model
3
- * Clean implementation from extracted specification
4
- */
5
-
6
- import { z } from 'zod';
7
- import type { LibrarySuggestion } from '../types/index.js';
8
-
9
- export const LibrarySuggestionSchema = z.object({
10
- name: z.string().min(1, 'Name is required'),
11
- path: z.string().min(1, 'Path is required'),
12
- type: z.enum(['deployment', 'domain', 'manifest', 'type', 'standard']),
13
- description: z.string().min(1, 'Description is required'),
14
- ai_description: z.string().min(1, 'AI description is required'),
15
- expansion_factor: z.number().min(1, 'Expansion factor must be >= 1'),
16
- complexity_level: z.enum(['low', 'medium', 'high']),
17
- best_for: z.array(z.string()).min(1, 'Must specify at least one use case')
18
- });
19
-
20
- export class LibrarySuggestionModel {
21
- private constructor(
22
- public readonly name: string,
23
- public readonly path: string,
24
- public readonly type: 'deployment' | 'domain' | 'manifest' | 'type' | 'standard',
25
- public readonly description: string,
26
- public readonly ai_description: string,
27
- public readonly expansion_factor: number,
28
- public readonly complexity_level: 'low' | 'medium' | 'high',
29
- public readonly best_for: string[]
30
- ) {}
31
-
32
- static create(data: LibrarySuggestion): LibrarySuggestionModel {
33
- const validated = LibrarySuggestionSchema.parse(data);
34
-
35
- return new LibrarySuggestionModel(
36
- validated.name,
37
- validated.path,
38
- validated.type,
39
- validated.description,
40
- validated.ai_description,
41
- validated.expansion_factor,
42
- validated.complexity_level,
43
- validated.best_for
44
- );
45
- }
46
-
47
- static fromJson(json: string): LibrarySuggestionModel {
48
- const data = JSON.parse(json);
49
- return this.create(data);
50
- }
51
-
52
- toJson(): string {
53
- return JSON.stringify({
54
- name: this.name,
55
- path: this.path,
56
- type: this.type,
57
- description: this.description,
58
- ai_description: this.ai_description,
59
- expansion_factor: this.expansion_factor,
60
- complexity_level: this.complexity_level,
61
- best_for: this.best_for
62
- });
63
- }
64
-
65
- matchesContext(context: string, scale: string): number {
66
- let score = 0;
67
- const contextLower = context.toLowerCase();
68
-
69
- // Check if library type matches context
70
- for (const useCase of this.best_for) {
71
- if (contextLower.includes(useCase.toLowerCase())) {
72
- score += 2;
73
- }
74
- }
75
-
76
- // Check complexity match with scale
77
- const scaleComplexity = this.getScaleComplexity(scale);
78
- const complexityScore = this.getComplexityScore();
79
- const complexityMatch = Math.abs(complexityScore - scaleComplexity);
80
- score += Math.max(0, 3 - complexityMatch);
81
-
82
- return score;
83
- }
84
-
85
- private getScaleComplexity(scale: string): number {
86
- switch (scale) {
87
- case 'personal': return 1;
88
- case 'business': return 2;
89
- case 'enterprise': return 3;
90
- default: return 2;
91
- }
92
- }
93
-
94
- private getComplexityScore(): number {
95
- switch (this.complexity_level) {
96
- case 'low': return 1;
97
- case 'medium': return 2;
98
- case 'high': return 3;
99
- default: return 2;
100
- }
101
- }
102
-
103
- getRelevanceScore(): number {
104
- return this.expansion_factor * this.getComplexityScore();
105
- }
106
- }
@@ -1,75 +0,0 @@
1
- /**
2
- * SpecVerseResource Model
3
- * Clean implementation from extracted specification
4
- */
5
-
6
- import { z } from 'zod';
7
- import type { SpecVerseResource } from '../types/index.js';
8
-
9
- export const SpecVerseResourceSchema = z.object({
10
- uri: z.string().min(1, 'URI is required').regex(/^specverse:\/\//, 'URI must start with specverse://'),
11
- name: z.string().min(1, 'Name is required'),
12
- description: z.string().min(1, 'Description is required'),
13
- mimeType: z.string().min(1, 'MIME type is required'),
14
- content: z.string().optional(),
15
- metadata: z.record(z.any()).optional()
16
- });
17
-
18
- export class SpecVerseResourceModel {
19
- private constructor(
20
- public readonly uri: string,
21
- public readonly name: string,
22
- public readonly description: string,
23
- public readonly mimeType: string,
24
- public readonly content?: string,
25
- public readonly metadata?: Record<string, any>
26
- ) {}
27
-
28
- static create(data: SpecVerseResource): SpecVerseResourceModel {
29
- const validated = SpecVerseResourceSchema.parse(data);
30
-
31
- return new SpecVerseResourceModel(
32
- validated.uri,
33
- validated.name,
34
- validated.description,
35
- validated.mimeType,
36
- validated.content,
37
- validated.metadata
38
- );
39
- }
40
-
41
- static fromJson(json: string): SpecVerseResourceModel {
42
- const data = JSON.parse(json);
43
- return this.create(data);
44
- }
45
-
46
- toJson(): string {
47
- return JSON.stringify({
48
- uri: this.uri,
49
- name: this.name,
50
- description: this.description,
51
- mimeType: this.mimeType,
52
- content: this.content,
53
- metadata: this.metadata
54
- });
55
- }
56
-
57
- withContent(content: string): SpecVerseResourceModel {
58
- return new SpecVerseResourceModel(
59
- this.uri,
60
- this.name,
61
- this.description,
62
- this.mimeType,
63
- content,
64
- this.metadata
65
- );
66
- }
67
-
68
- matches(uri: string): boolean {
69
- return this.uri === uri;
70
- }
71
-
72
- isLoaded(): boolean {
73
- return this.content !== undefined;
74
- }
75
- }