@specverse/engines 4.1.5 → 4.1.7
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/dist/libs/instance-factories/applications/templates/generic/backend-env-generator.js +22 -0
- package/dist/libs/instance-factories/applications/templates/generic/backend-package-json-generator.js +66 -0
- package/dist/libs/instance-factories/applications/templates/generic/backend-tsconfig-generator.js +54 -0
- package/dist/libs/instance-factories/applications/templates/generic/main-generator.js +290 -0
- package/dist/libs/instance-factories/applications/templates/react/_view-components-source.js +530 -0
- package/dist/libs/instance-factories/applications/templates/react/api-client-generator.js +437 -0
- package/dist/libs/instance-factories/applications/templates/react/api-types-generator.js +146 -0
- package/dist/libs/instance-factories/applications/templates/react/app-tsx-generator.js +73 -0
- package/dist/libs/instance-factories/applications/templates/react/env-example-generator.js +18 -0
- package/dist/libs/instance-factories/applications/templates/react/field-helpers-generator.js +99 -0
- package/dist/libs/instance-factories/applications/templates/react/gitignore-generator.js +35 -0
- package/dist/libs/instance-factories/applications/templates/react/index-css-generator.js +9 -0
- package/dist/libs/instance-factories/applications/templates/react/index-html-generator.js +23 -0
- package/dist/libs/instance-factories/applications/templates/react/main-tsx-generator.js +29 -0
- package/dist/libs/instance-factories/applications/templates/react/package-json-generator.js +49 -0
- package/dist/libs/instance-factories/applications/templates/react/pattern-adapter-generator.js +156 -0
- package/dist/libs/instance-factories/applications/templates/react/react-pattern-adapter.js +935 -0
- package/dist/libs/instance-factories/applications/templates/react/relationship-field-generator.js +143 -0
- package/dist/libs/instance-factories/applications/templates/react/runtime-app-tsx-generator.js +101 -0
- package/dist/libs/instance-factories/applications/templates/react/runtime-package-json-generator.js +50 -0
- package/dist/libs/instance-factories/applications/templates/react/tailwind-adapter-generator.js +646 -0
- package/dist/libs/instance-factories/applications/templates/react/tailwind-adapter-wrapper-generator.js +65 -0
- package/dist/libs/instance-factories/applications/templates/react/tsconfig-generator.js +28 -0
- package/dist/libs/instance-factories/applications/templates/react/use-api-hooks-generator.js +132 -0
- package/dist/libs/instance-factories/applications/templates/react/view-dashboard-generator.js +143 -0
- package/dist/libs/instance-factories/applications/templates/react/view-detail-generator.js +143 -0
- package/dist/libs/instance-factories/applications/templates/react/view-form-generator.js +355 -0
- package/dist/libs/instance-factories/applications/templates/react/view-list-generator.js +91 -0
- package/dist/libs/instance-factories/applications/templates/react/view-router-generator.js +79 -0
- package/dist/libs/instance-factories/applications/templates/react/vite-config-generator.js +42 -0
- package/dist/libs/instance-factories/cli/templates/commander/cli-bin-wrapper-generator.js +11 -0
- package/dist/libs/instance-factories/cli/templates/commander/cli-entry-generator.js +111 -0
- package/dist/libs/instance-factories/cli/templates/commander/command-generator.js +928 -0
- package/dist/libs/instance-factories/communication/templates/eventemitter/bus-generator.js +83 -0
- package/dist/libs/instance-factories/communication/templates/eventemitter/publisher-generator.js +91 -0
- package/dist/libs/instance-factories/communication/templates/eventemitter/subscriber-generator.js +86 -0
- package/dist/libs/instance-factories/controllers/templates/fastify/meta-routes-generator.js +93 -0
- package/dist/libs/instance-factories/controllers/templates/fastify/routes-generator.js +280 -0
- package/dist/libs/instance-factories/controllers/templates/fastify/server-generator.js +125 -0
- package/dist/libs/instance-factories/infrastructure/templates/docker-k8s/infrastructure-generator.js +25 -0
- package/dist/libs/instance-factories/orms/templates/prisma/schema-generator.js +371 -0
- package/dist/libs/instance-factories/orms/templates/prisma/services-generator.js +266 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/env-example-generator.js +51 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/env-generator.js +61 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/gitignore-generator.js +59 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/package-json-generator.js +126 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/readme-generator.js +159 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/tsconfig-generator.js +56 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/tsconfig-react-generator.js +37 -0
- package/dist/libs/instance-factories/sdks/templates/python/sdk-generator.js +29 -0
- package/dist/libs/instance-factories/sdks/templates/typescript/sdk-generator.js +28 -0
- package/dist/libs/instance-factories/services/templates/memory/generate-interpreter.js +14 -0
- package/dist/libs/instance-factories/services/templates/memory/step-conventions-memory.js +415 -0
- package/dist/libs/instance-factories/services/templates/prisma/behavior-generator.js +177 -0
- package/dist/libs/instance-factories/services/templates/prisma/controller-generator.js +413 -0
- package/dist/libs/instance-factories/services/templates/prisma/service-generator.js +243 -0
- package/dist/libs/instance-factories/services/templates/prisma/step-conventions.js +264 -0
- package/dist/libs/instance-factories/services/templates/shared-patterns.js +24 -0
- package/dist/libs/instance-factories/shared/path-resolver.js +59 -0
- package/dist/libs/instance-factories/storage/templates/mongodb/config-generator.js +13 -0
- package/dist/libs/instance-factories/storage/templates/mongodb/docker-generator.js +16 -0
- package/dist/libs/instance-factories/storage/templates/postgresql/config-generator.js +45 -0
- package/dist/libs/instance-factories/storage/templates/postgresql/docker-generator.js +46 -0
- package/dist/libs/instance-factories/storage/templates/redis/config-generator.js +14 -0
- package/dist/libs/instance-factories/storage/templates/redis/docker-generator.js +16 -0
- package/dist/libs/instance-factories/test-generation.js +145 -0
- package/dist/libs/instance-factories/testing/templates/vitest/tests-generator.js +30 -0
- package/dist/libs/instance-factories/tools/templates/mcp/mcp-server-generator.js +149 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/controllers/MCPServerController.js +232 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/events/EventEmitter.js +49 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/index.js +18 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/interfaces/ResourceProvider.js +0 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/models/LibrarySuggestion.js +97 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/models/SpecVerseResource.js +64 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/server/mcp-server.js +182 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/CLIProxyService.js +1210 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/EmbeddedResourcesAdapter.js +172 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/EntityModuleService.js +240 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/HybridResourcesProvider.js +147 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/LibraryToolsService.js +281 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/OrchestratorBridge.js +409 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/OrchestratorToolsService.js +414 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/PromptToolsService.js +467 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/ResourcesProviderService.js +135 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/types/index.js +0 -0
- package/dist/libs/instance-factories/tools/templates/vscode/static/extension.js +965 -0
- package/dist/libs/instance-factories/tools/templates/vscode/vscode-extension-generator.js +238 -0
- package/dist/libs/instance-factories/validation/templates/zod/validation-generator.js +25 -0
- package/dist/libs/instance-factories/views/index.js +48 -0
- package/dist/libs/instance-factories/views/templates/react/adapters/antd-adapter.js +742 -0
- package/dist/libs/instance-factories/views/templates/react/adapters/mui-adapter.js +824 -0
- package/dist/libs/instance-factories/views/templates/react/adapters/shadcn-adapter.js +719 -0
- package/dist/libs/instance-factories/views/templates/react/app-generator.js +45 -0
- package/dist/libs/instance-factories/views/templates/react/components-generator.js +779 -0
- package/dist/libs/instance-factories/views/templates/react/forms-generator.js +285 -0
- package/dist/libs/instance-factories/views/templates/react/frontend-package-json-generator.js +46 -0
- package/dist/libs/instance-factories/views/templates/react/hooks-generator.js +111 -0
- package/dist/libs/instance-factories/views/templates/react/index-css-generator.js +9 -0
- package/dist/libs/instance-factories/views/templates/react/index-html-generator.js +23 -0
- package/dist/libs/instance-factories/views/templates/react/main-tsx-generator.js +21 -0
- package/dist/libs/instance-factories/views/templates/react/react-component-generator.js +299 -0
- package/dist/libs/instance-factories/views/templates/react/router-generator.js +136 -0
- package/dist/libs/instance-factories/views/templates/react/router-generic-generator.js +107 -0
- package/dist/libs/instance-factories/views/templates/react/shared-utils-generator.js +179 -0
- package/dist/libs/instance-factories/views/templates/react/spec-json-generator.js +7 -0
- package/dist/libs/instance-factories/views/templates/react/types-generator.js +56 -0
- package/dist/libs/instance-factories/views/templates/react/views-metadata-generator.js +27 -0
- package/dist/libs/instance-factories/views/templates/react/vite-config-generator.js +29 -0
- package/dist/libs/instance-factories/views/templates/runtime/runtime-view-renderer.js +261 -0
- package/dist/libs/instance-factories/views/templates/shared/adapter-types.js +34 -0
- package/dist/libs/instance-factories/views/templates/shared/atomic-components-registry.js +800 -0
- package/dist/libs/instance-factories/views/templates/shared/base-generator.js +305 -0
- package/dist/libs/instance-factories/views/templates/shared/component-metadata.js +517 -0
- package/dist/libs/instance-factories/views/templates/shared/composite-pattern-types.js +0 -0
- package/dist/libs/instance-factories/views/templates/shared/composite-patterns.js +445 -0
- package/dist/libs/instance-factories/views/templates/shared/index.js +80 -0
- package/dist/libs/instance-factories/views/templates/shared/pattern-validator.js +210 -0
- package/dist/libs/instance-factories/views/templates/shared/property-mapper.js +492 -0
- package/dist/libs/instance-factories/views/templates/shared/syntax-mapper.js +321 -0
- package/dist/realize/index.js +36 -12
- package/dist/realize/index.js.map +1 -1
- package/package.json +3 -2
package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/PromptToolsService.js
ADDED
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
import { enhancePrompt } from "@specverse/engine-ai";
|
|
2
|
+
class PromptToolsService {
|
|
3
|
+
resourcesProvider;
|
|
4
|
+
libraryTools;
|
|
5
|
+
constructor(resourcesProvider, libraryTools) {
|
|
6
|
+
this.resourcesProvider = resourcesProvider;
|
|
7
|
+
this.libraryTools = libraryTools;
|
|
8
|
+
}
|
|
9
|
+
async getCreationPrompt(context) {
|
|
10
|
+
try {
|
|
11
|
+
const sanitizedContext = this.sanitizeContext(context);
|
|
12
|
+
const result = await this.callAICommand("enhance", "create", {
|
|
13
|
+
requirements: sanitizedContext.requirements || "",
|
|
14
|
+
scale: this.mapScale(sanitizedContext.scale),
|
|
15
|
+
framework: sanitizedContext.preferredTech,
|
|
16
|
+
technology_preferences: sanitizedContext.preferredTech ? [sanitizedContext.preferredTech] : void 0
|
|
17
|
+
});
|
|
18
|
+
const expandedPrompt = {
|
|
19
|
+
system_prompt: result.systemPrompt,
|
|
20
|
+
user_prompt: result.userPrompt,
|
|
21
|
+
context: result.contextPrompt,
|
|
22
|
+
libraries: result.libraryContext?.suggestions?.slice(0, 5) || [],
|
|
23
|
+
estimated_tokens: result.estimatedTokens,
|
|
24
|
+
execution_options: result.executionOptions
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
content: [{
|
|
28
|
+
type: "text",
|
|
29
|
+
text: JSON.stringify(expandedPrompt, null, 2)
|
|
30
|
+
}]
|
|
31
|
+
};
|
|
32
|
+
} catch (error) {
|
|
33
|
+
return this.createErrorResult("getCreationPrompt", error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async getAnalysisPrompt(context) {
|
|
37
|
+
try {
|
|
38
|
+
const sanitizedContext = this.sanitizeContext(context);
|
|
39
|
+
const result = await this.callAICommand("enhance", "analyse", {
|
|
40
|
+
requirements: sanitizedContext.projectType || "code analysis",
|
|
41
|
+
framework: sanitizedContext.frameworkHint
|
|
42
|
+
});
|
|
43
|
+
const expandedPrompt = {
|
|
44
|
+
system_prompt: result.systemPrompt,
|
|
45
|
+
user_prompt: result.userPrompt,
|
|
46
|
+
context: result.contextPrompt,
|
|
47
|
+
estimated_tokens: result.estimatedTokens,
|
|
48
|
+
execution_options: result.executionOptions
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
content: [{
|
|
52
|
+
type: "text",
|
|
53
|
+
text: JSON.stringify(expandedPrompt, null, 2)
|
|
54
|
+
}]
|
|
55
|
+
};
|
|
56
|
+
} catch (error) {
|
|
57
|
+
return this.createErrorResult("getAnalysisPrompt", error);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async getImplementationPrompt(context) {
|
|
61
|
+
try {
|
|
62
|
+
const sanitizedContext = this.sanitizeContext(context);
|
|
63
|
+
const result = await this.callAICommand("enhance", "materialise", {
|
|
64
|
+
requirements: `implementation planning for ${sanitizedContext.targetFramework || "specified framework"}`,
|
|
65
|
+
framework: sanitizedContext.targetFramework,
|
|
66
|
+
technology_preferences: sanitizedContext.deploymentType ? [sanitizedContext.deploymentType] : void 0
|
|
67
|
+
});
|
|
68
|
+
const expandedPrompt = {
|
|
69
|
+
system_prompt: result.systemPrompt,
|
|
70
|
+
user_prompt: result.userPrompt,
|
|
71
|
+
context: result.contextPrompt,
|
|
72
|
+
estimated_tokens: result.estimatedTokens,
|
|
73
|
+
execution_options: result.executionOptions
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
content: [{
|
|
77
|
+
type: "text",
|
|
78
|
+
text: JSON.stringify(expandedPrompt, null, 2)
|
|
79
|
+
}]
|
|
80
|
+
};
|
|
81
|
+
} catch (error) {
|
|
82
|
+
return this.createErrorResult("getImplementationPrompt", error);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async getRealizationPrompt(context) {
|
|
86
|
+
try {
|
|
87
|
+
const sanitizedContext = this.sanitizeContext(context);
|
|
88
|
+
const result = await this.callAICommand("enhance", "realize", {
|
|
89
|
+
requirements: `code generation for ${sanitizedContext.targetFramework || "specified framework"}`,
|
|
90
|
+
framework: sanitizedContext.targetFramework,
|
|
91
|
+
scale: this.mapScale(sanitizedContext.implementationScope)
|
|
92
|
+
});
|
|
93
|
+
const expandedPrompt = {
|
|
94
|
+
system_prompt: result.systemPrompt,
|
|
95
|
+
user_prompt: result.userPrompt,
|
|
96
|
+
context: result.contextPrompt,
|
|
97
|
+
estimated_tokens: result.estimatedTokens,
|
|
98
|
+
execution_options: result.executionOptions
|
|
99
|
+
};
|
|
100
|
+
return {
|
|
101
|
+
content: [{
|
|
102
|
+
type: "text",
|
|
103
|
+
text: JSON.stringify(expandedPrompt, null, 2)
|
|
104
|
+
}]
|
|
105
|
+
};
|
|
106
|
+
} catch (error) {
|
|
107
|
+
return this.createErrorResult("getRealizationPrompt", error);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async getValidationInstructions(args) {
|
|
111
|
+
try {
|
|
112
|
+
const validationType = args.validationType || "syntax";
|
|
113
|
+
const instructions = this.generateValidationInstructions(validationType);
|
|
114
|
+
return {
|
|
115
|
+
content: [{
|
|
116
|
+
type: "text",
|
|
117
|
+
text: JSON.stringify(instructions, null, 2)
|
|
118
|
+
}]
|
|
119
|
+
};
|
|
120
|
+
} catch (error) {
|
|
121
|
+
return this.createErrorResult("getValidationInstructions", error);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
parseTemplate(template) {
|
|
125
|
+
return {
|
|
126
|
+
systemRole: template?.system?.role || template?.system_role || "",
|
|
127
|
+
systemContext: template?.system?.context || template?.system_context || "",
|
|
128
|
+
userTemplate: template?.user?.template || template?.user_template || ""
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
expandCreationPrompt(template, context) {
|
|
132
|
+
const { requirements, scale = "business", preferredTech = "auto", libraries = [], reasoning = "" } = context;
|
|
133
|
+
const { systemRole, systemContext, userTemplate } = this.parseTemplate(template);
|
|
134
|
+
let systemPrompt = systemRole + "\\n\\n" + systemContext;
|
|
135
|
+
systemPrompt += "\\n\\n" + this.getScaleGuidance(scale);
|
|
136
|
+
if (libraries.length > 0) {
|
|
137
|
+
systemPrompt += "\\n\\nLIBRARY CONTEXT:\\n";
|
|
138
|
+
systemPrompt += `Consider these relevant SpecVerse libraries: ${libraries.map((lib) => lib.name).join(", ")}\\n`;
|
|
139
|
+
systemPrompt += `Library selection reasoning: ${reasoning}`;
|
|
140
|
+
}
|
|
141
|
+
let userPrompt = "";
|
|
142
|
+
try {
|
|
143
|
+
if (userTemplate === null || userTemplate === void 0) {
|
|
144
|
+
userPrompt = "";
|
|
145
|
+
} else if (typeof userTemplate === "string") {
|
|
146
|
+
userPrompt = userTemplate;
|
|
147
|
+
} else {
|
|
148
|
+
userPrompt = String(userTemplate);
|
|
149
|
+
}
|
|
150
|
+
if (userPrompt && userPrompt.length > 0 && typeof userPrompt === "string") {
|
|
151
|
+
userPrompt = userPrompt.replace(/\\{\\{requirements\\}\\}/g, requirements || "Not specified");
|
|
152
|
+
userPrompt = userPrompt.replace(/\\{\\{scale\\}\\}/g, scale);
|
|
153
|
+
userPrompt = userPrompt.replace(/\\{\\{preferredTech\\}\\}/g, preferredTech);
|
|
154
|
+
}
|
|
155
|
+
} catch (error) {
|
|
156
|
+
userPrompt = "";
|
|
157
|
+
}
|
|
158
|
+
const constraints = template.system_constraints?.join("\\n- ") || "";
|
|
159
|
+
const contextSection = constraints ? `\\nCONSTRAINTS:\\n- ${constraints}` : "";
|
|
160
|
+
return {
|
|
161
|
+
system_prompt: systemPrompt,
|
|
162
|
+
user_prompt: userPrompt,
|
|
163
|
+
context: contextSection,
|
|
164
|
+
libraries: libraries.slice(0, 5)
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
expandAnalysisPrompt(template, context) {
|
|
168
|
+
const { projectType, frameworkHint } = context;
|
|
169
|
+
const { systemRole, systemContext, userTemplate } = this.parseTemplate(template);
|
|
170
|
+
let systemPrompt = systemRole + "\\n\\n" + systemContext;
|
|
171
|
+
if (projectType) {
|
|
172
|
+
systemPrompt += `\\n\\nPROJECT TYPE: ${projectType}`;
|
|
173
|
+
systemPrompt += this.getProjectTypeGuidance(projectType);
|
|
174
|
+
}
|
|
175
|
+
let userPrompt = userTemplate || "";
|
|
176
|
+
if (typeof userPrompt !== "string") {
|
|
177
|
+
userPrompt = "";
|
|
178
|
+
}
|
|
179
|
+
if (userPrompt && userPrompt.length > 0) {
|
|
180
|
+
try {
|
|
181
|
+
userPrompt = userPrompt.replace(/\\{\\{frameworkType\\}\\}/g, frameworkHint || "auto-detect");
|
|
182
|
+
} catch (error) {
|
|
183
|
+
console.warn("Error during analysis template replacement:", error);
|
|
184
|
+
userPrompt = `Template expansion failed: ${userTemplate}`;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const analysisInstructions = `
|
|
188
|
+
ANALYSIS INSTRUCTIONS:
|
|
189
|
+
1. Scan the following files for models, controllers, and services
|
|
190
|
+
2. Identify relationships between data models
|
|
191
|
+
3. Extract API endpoints and map to controller actions
|
|
192
|
+
4. Detect business logic patterns and event flows
|
|
193
|
+
5. Generate a clean SpecVerse specification
|
|
194
|
+
|
|
195
|
+
Please provide the directory structure and key file contents for analysis.`;
|
|
196
|
+
return {
|
|
197
|
+
system_prompt: systemPrompt,
|
|
198
|
+
user_prompt: userPrompt,
|
|
199
|
+
context: analysisInstructions
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
expandImplementationPrompt(template, context) {
|
|
203
|
+
const { targetFramework, deploymentType } = context;
|
|
204
|
+
const { systemRole, systemContext, userTemplate } = this.parseTemplate(template);
|
|
205
|
+
let systemPrompt = systemRole + "\\n\\n" + systemContext;
|
|
206
|
+
systemPrompt += `\\n\\nTARGET FRAMEWORK: ${targetFramework}`;
|
|
207
|
+
if (deploymentType) {
|
|
208
|
+
systemPrompt += `\\nDEPLOYMENT TYPE: ${deploymentType}`;
|
|
209
|
+
}
|
|
210
|
+
let userPrompt = userTemplate || "";
|
|
211
|
+
if (typeof userPrompt !== "string") {
|
|
212
|
+
userPrompt = "";
|
|
213
|
+
}
|
|
214
|
+
if (userPrompt && userPrompt.length > 0) {
|
|
215
|
+
try {
|
|
216
|
+
userPrompt = userPrompt.replace(/\\{\\{targetFramework\\}\\}/g, targetFramework);
|
|
217
|
+
} catch (error) {
|
|
218
|
+
console.warn("Error during implementation template replacement:", error);
|
|
219
|
+
userPrompt = `Template expansion failed: ${userTemplate}`;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const implementationContext = `
|
|
223
|
+
IMPLEMENTATION PLANNING FOCUS:
|
|
224
|
+
1. Break down the specification into implementable modules
|
|
225
|
+
2. Define file structure and component organization
|
|
226
|
+
3. Identify dependencies and integration points
|
|
227
|
+
4. Create development workflow and build process
|
|
228
|
+
5. Plan testing strategy and deployment pipeline
|
|
229
|
+
|
|
230
|
+
Framework-specific patterns for ${targetFramework} will be prioritized.`;
|
|
231
|
+
return {
|
|
232
|
+
system_prompt: systemPrompt,
|
|
233
|
+
user_prompt: userPrompt,
|
|
234
|
+
context: implementationContext
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
expandRealizationPrompt(template, context) {
|
|
238
|
+
const { targetFramework, implementationScope = "full" } = context;
|
|
239
|
+
const { systemRole, systemContext, userTemplate } = this.parseTemplate(template);
|
|
240
|
+
let systemPrompt = systemRole + "\\n\\n" + systemContext;
|
|
241
|
+
systemPrompt += `\\n\\nTARGET FRAMEWORK: ${targetFramework}`;
|
|
242
|
+
systemPrompt += `\\nSCOPE: ${implementationScope}`;
|
|
243
|
+
let userPrompt = userTemplate || "";
|
|
244
|
+
if (typeof userPrompt !== "string") {
|
|
245
|
+
userPrompt = "";
|
|
246
|
+
}
|
|
247
|
+
if (userPrompt && userPrompt.length > 0) {
|
|
248
|
+
try {
|
|
249
|
+
userPrompt = userPrompt.replace(/\\{\\{targetFramework\\}\\}/g, targetFramework);
|
|
250
|
+
} catch (error) {
|
|
251
|
+
console.warn("Error during realization template replacement:", error);
|
|
252
|
+
userPrompt = `Template expansion failed: ${userTemplate}`;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
const scopeGuidance = this.getScopeGuidance(implementationScope);
|
|
256
|
+
return {
|
|
257
|
+
system_prompt: systemPrompt,
|
|
258
|
+
user_prompt: userPrompt,
|
|
259
|
+
context: scopeGuidance
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
getScaleGuidance(scale) {
|
|
263
|
+
switch (scale) {
|
|
264
|
+
case "personal":
|
|
265
|
+
return `
|
|
266
|
+
PERSONAL SCALE GUIDANCE:
|
|
267
|
+
- Focus on simplicity and ease of use
|
|
268
|
+
- Minimize dependencies and complexity
|
|
269
|
+
- Single-user scenarios are acceptable
|
|
270
|
+
- SQLite and local storage are preferred
|
|
271
|
+
- Simple authentication patterns`;
|
|
272
|
+
case "enterprise":
|
|
273
|
+
return `
|
|
274
|
+
ENTERPRISE SCALE GUIDANCE:
|
|
275
|
+
- Multi-tenant architecture required
|
|
276
|
+
- Comprehensive audit trails and logging
|
|
277
|
+
- Role-based access control (RBAC)
|
|
278
|
+
- High availability and scalability
|
|
279
|
+
- Compliance considerations (SOX, GDPR, HIPAA)
|
|
280
|
+
- Microservices patterns preferred`;
|
|
281
|
+
default:
|
|
282
|
+
return `
|
|
283
|
+
BUSINESS SCALE GUIDANCE:
|
|
284
|
+
- Multi-user support with role management
|
|
285
|
+
- Professional authentication (OAuth)
|
|
286
|
+
- Relational database (PostgreSQL preferred)
|
|
287
|
+
- API-first architecture
|
|
288
|
+
- Moderate scalability requirements`;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
getProjectTypeGuidance(projectType) {
|
|
292
|
+
switch (projectType.toLowerCase()) {
|
|
293
|
+
case "web":
|
|
294
|
+
return "\\nFocus on: Controllers for pages, Services for business logic, Events for user interactions";
|
|
295
|
+
case "api":
|
|
296
|
+
return "\\nFocus on: RESTful endpoints, Data models, Service layers, Authentication";
|
|
297
|
+
case "mobile":
|
|
298
|
+
return "\\nFocus on: Screen controllers, Local storage, Sync patterns, Offline support";
|
|
299
|
+
default:
|
|
300
|
+
return "\\nUse general analysis patterns for all architectural components";
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
getScopeGuidance(scope) {
|
|
304
|
+
switch (scope) {
|
|
305
|
+
case "mvp":
|
|
306
|
+
return `
|
|
307
|
+
MVP SCOPE:
|
|
308
|
+
- Essential features only
|
|
309
|
+
- Minimal error handling
|
|
310
|
+
- Basic styling and UX
|
|
311
|
+
- Skip advanced features
|
|
312
|
+
- Focus on core user journey`;
|
|
313
|
+
case "prototype":
|
|
314
|
+
return `
|
|
315
|
+
PROTOTYPE SCOPE:
|
|
316
|
+
- Rapid development approach
|
|
317
|
+
- Mock data acceptable
|
|
318
|
+
- Basic functionality demonstration
|
|
319
|
+
- Minimal production considerations`;
|
|
320
|
+
default:
|
|
321
|
+
return `
|
|
322
|
+
FULL IMPLEMENTATION SCOPE:
|
|
323
|
+
- Complete feature set
|
|
324
|
+
- Production-ready code quality
|
|
325
|
+
- Comprehensive error handling
|
|
326
|
+
- Full testing coverage
|
|
327
|
+
- Security best practices`;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
generateValidationInstructions(validationType) {
|
|
331
|
+
switch (validationType) {
|
|
332
|
+
case "syntax":
|
|
333
|
+
return {
|
|
334
|
+
command: "specverse check specs/main.specly",
|
|
335
|
+
description: "Validate SpecVerse specification syntax",
|
|
336
|
+
expected_output: "Specification is valid",
|
|
337
|
+
common_issues: [
|
|
338
|
+
"Invalid YAML syntax",
|
|
339
|
+
"Missing required fields",
|
|
340
|
+
"Incorrect property names",
|
|
341
|
+
"Invalid relationship syntax"
|
|
342
|
+
],
|
|
343
|
+
fix_suggestions: [
|
|
344
|
+
"Check YAML indentation (use spaces, not tabs)",
|
|
345
|
+
"Ensure all required fields are present",
|
|
346
|
+
"Verify property names match schema",
|
|
347
|
+
"Use correct relationship syntax: hasMany, belongsTo, etc."
|
|
348
|
+
]
|
|
349
|
+
};
|
|
350
|
+
case "semantic":
|
|
351
|
+
return {
|
|
352
|
+
command: "specverse check specs/main.specly --semantic",
|
|
353
|
+
description: "Validate semantic consistency and relationships",
|
|
354
|
+
expected_output: "No semantic errors found",
|
|
355
|
+
common_issues: [
|
|
356
|
+
"Circular relationship dependencies",
|
|
357
|
+
"Missing relationship targets",
|
|
358
|
+
"Inconsistent naming conventions",
|
|
359
|
+
"Unreferenced models"
|
|
360
|
+
],
|
|
361
|
+
fix_suggestions: [
|
|
362
|
+
"Check for circular references in relationships",
|
|
363
|
+
"Ensure all relationship targets exist",
|
|
364
|
+
"Use consistent PascalCase for models",
|
|
365
|
+
"Remove unused models or add references"
|
|
366
|
+
]
|
|
367
|
+
};
|
|
368
|
+
default:
|
|
369
|
+
return {
|
|
370
|
+
command: "specverse check specs/main.specly",
|
|
371
|
+
description: "Basic specification validation",
|
|
372
|
+
expected_output: "Validation successful",
|
|
373
|
+
common_issues: ["Syntax errors", "Schema violations"],
|
|
374
|
+
fix_suggestions: ["Fix syntax errors", "Follow SpecVerse schema"]
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
mapScale(scale) {
|
|
379
|
+
switch (scale) {
|
|
380
|
+
case "personal":
|
|
381
|
+
case "mvp":
|
|
382
|
+
case "prototype":
|
|
383
|
+
return "personal";
|
|
384
|
+
case "enterprise":
|
|
385
|
+
case "full":
|
|
386
|
+
return "enterprise";
|
|
387
|
+
default:
|
|
388
|
+
return "business";
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Call AI commands directly using src/ai/ API.
|
|
393
|
+
* This provides better integration and type safety than CLI calls.
|
|
394
|
+
*/
|
|
395
|
+
async callAICommand(action, operation, params) {
|
|
396
|
+
try {
|
|
397
|
+
const requirements = {
|
|
398
|
+
requirements: params.requirements || "",
|
|
399
|
+
scale: params.scale || "business",
|
|
400
|
+
framework: params.framework,
|
|
401
|
+
technology_preferences: params.technology_preferences
|
|
402
|
+
};
|
|
403
|
+
if (action === "enhance") {
|
|
404
|
+
return await enhancePrompt(operation, requirements);
|
|
405
|
+
} else {
|
|
406
|
+
throw new Error(`Unsupported action: ${action}`);
|
|
407
|
+
}
|
|
408
|
+
} catch (error) {
|
|
409
|
+
console.warn("Direct API call failed, falling back to basic prompt:", error);
|
|
410
|
+
return {
|
|
411
|
+
systemPrompt: `You are a SpecVerse specification ${operation} expert.`,
|
|
412
|
+
userPrompt: `Please ${operation} a specification for: ${params.requirements}`,
|
|
413
|
+
contextPrompt: `Scale: ${params.scale || "business"}, Framework: ${params.framework || "auto"}`,
|
|
414
|
+
estimatedTokens: 1e3,
|
|
415
|
+
variables: [],
|
|
416
|
+
libraryContext: {
|
|
417
|
+
total: 0,
|
|
418
|
+
suggestions: [],
|
|
419
|
+
reasoning: "Basic fallback mode - no library suggestions available"
|
|
420
|
+
},
|
|
421
|
+
executionOptions: [
|
|
422
|
+
{ provider: "interactive", description: "Interactive copy-paste (Free)", estimatedCost: 0 },
|
|
423
|
+
{ provider: "openai", description: "OpenAI GPT-3.5 ($0.002)", estimatedCost: 2e-3 },
|
|
424
|
+
{ provider: "openai", description: "OpenAI GPT-4 ($0.03)", estimatedCost: 0.03 }
|
|
425
|
+
]
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
sanitizeContext(context) {
|
|
430
|
+
if (!context || typeof context !== "object") {
|
|
431
|
+
return { requirements: "", scale: "business", preferredTech: "auto" };
|
|
432
|
+
}
|
|
433
|
+
const sanitized = {};
|
|
434
|
+
for (const [key, value] of Object.entries(context)) {
|
|
435
|
+
if (value === null || value === void 0) {
|
|
436
|
+
sanitized[key] = "";
|
|
437
|
+
} else if (typeof value === "string") {
|
|
438
|
+
sanitized[key] = String(value).trim();
|
|
439
|
+
} else {
|
|
440
|
+
sanitized[key] = String(value).trim();
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return {
|
|
444
|
+
requirements: sanitized.requirements || "",
|
|
445
|
+
scale: sanitized.scale || "business",
|
|
446
|
+
preferredTech: sanitized.preferredTech || "auto",
|
|
447
|
+
projectType: sanitized.projectType || "",
|
|
448
|
+
frameworkHint: sanitized.frameworkHint || "",
|
|
449
|
+
targetFramework: sanitized.targetFramework || "",
|
|
450
|
+
deploymentType: sanitized.deploymentType || "",
|
|
451
|
+
implementationScope: sanitized.implementationScope || "full",
|
|
452
|
+
...sanitized
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
createErrorResult(operation, error) {
|
|
456
|
+
return {
|
|
457
|
+
content: [{
|
|
458
|
+
type: "text",
|
|
459
|
+
text: `Error in ${operation}: ${error instanceof Error ? error.message : String(error)}`
|
|
460
|
+
}],
|
|
461
|
+
isError: true
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
export {
|
|
466
|
+
PromptToolsService
|
|
467
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { readFile } from "fs/promises";
|
|
2
|
+
import { existsSync } from "fs";
|
|
3
|
+
import { join, dirname } from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
import { SpecVerseResourceModel } from "../models/SpecVerseResource.js";
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = dirname(__filename);
|
|
8
|
+
class ResourcesProviderService {
|
|
9
|
+
resourceCatalog = /* @__PURE__ */ new Map();
|
|
10
|
+
resourcesPath;
|
|
11
|
+
isInitialized = false;
|
|
12
|
+
constructor(resourcesPath) {
|
|
13
|
+
if (resourcesPath) {
|
|
14
|
+
this.resourcesPath = resourcesPath;
|
|
15
|
+
} else {
|
|
16
|
+
const candidatePaths = [
|
|
17
|
+
join(__dirname, "../resources"),
|
|
18
|
+
// NPM package structure
|
|
19
|
+
join(__dirname, "../../resources")
|
|
20
|
+
// Development structure
|
|
21
|
+
];
|
|
22
|
+
this.resourcesPath = candidatePaths[0];
|
|
23
|
+
try {
|
|
24
|
+
for (const path of candidatePaths) {
|
|
25
|
+
if (existsSync(path)) {
|
|
26
|
+
this.resourcesPath = path;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
} catch (error) {
|
|
31
|
+
this.resourcesPath = candidatePaths[0];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async initializeResources() {
|
|
36
|
+
if (this.isInitialized) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const resources = [
|
|
40
|
+
{
|
|
41
|
+
uri: "specverse://examples/chat-prompts",
|
|
42
|
+
name: "Chat Prompt Examples",
|
|
43
|
+
description: "Example prompts for terminal/chat-based AI interactions",
|
|
44
|
+
mimeType: "text/markdown"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
uri: "specverse://examples/api-calls",
|
|
48
|
+
name: "API Integration Examples",
|
|
49
|
+
description: "Examples for API-based AI integrations",
|
|
50
|
+
mimeType: "application/javascript"
|
|
51
|
+
}
|
|
52
|
+
];
|
|
53
|
+
for (const resourceData of resources) {
|
|
54
|
+
const resource = SpecVerseResourceModel.create(resourceData);
|
|
55
|
+
this.resourceCatalog.set(resource.uri, resource);
|
|
56
|
+
}
|
|
57
|
+
this.isInitialized = true;
|
|
58
|
+
}
|
|
59
|
+
async listResources() {
|
|
60
|
+
await this.initializeResources();
|
|
61
|
+
return Array.from(this.resourceCatalog.values()).map((resource) => ({
|
|
62
|
+
uri: resource.uri,
|
|
63
|
+
name: resource.name,
|
|
64
|
+
description: resource.description,
|
|
65
|
+
mimeType: resource.mimeType,
|
|
66
|
+
content: resource.content,
|
|
67
|
+
metadata: resource.metadata
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
async getResourceContent(uri) {
|
|
71
|
+
await this.initializeResources();
|
|
72
|
+
const resource = this.resourceCatalog.get(uri);
|
|
73
|
+
if (!resource) {
|
|
74
|
+
throw new Error(`Resource not found: ${uri}`);
|
|
75
|
+
}
|
|
76
|
+
if (resource.isLoaded()) {
|
|
77
|
+
return resource.content;
|
|
78
|
+
}
|
|
79
|
+
const filePath = this.resolveResourcePath(uri);
|
|
80
|
+
try {
|
|
81
|
+
const content = await readFile(filePath, "utf-8");
|
|
82
|
+
const updatedResource = resource.withContent(content);
|
|
83
|
+
this.resourceCatalog.set(uri, updatedResource);
|
|
84
|
+
return content;
|
|
85
|
+
} catch (error) {
|
|
86
|
+
throw new Error(`Failed to load resource ${uri}: ${error instanceof Error ? error.message : String(error)}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async readResource(uri) {
|
|
90
|
+
try {
|
|
91
|
+
const content = await this.getResourceContent(uri);
|
|
92
|
+
const resource = this.resourceCatalog.get(uri);
|
|
93
|
+
return {
|
|
94
|
+
content: [{
|
|
95
|
+
type: "resource",
|
|
96
|
+
resource: {
|
|
97
|
+
uri: resource.uri,
|
|
98
|
+
name: resource.name,
|
|
99
|
+
description: resource.description,
|
|
100
|
+
mimeType: resource.mimeType,
|
|
101
|
+
content
|
|
102
|
+
}
|
|
103
|
+
}]
|
|
104
|
+
};
|
|
105
|
+
} catch (error) {
|
|
106
|
+
return {
|
|
107
|
+
content: [{
|
|
108
|
+
type: "text",
|
|
109
|
+
text: `Error reading resource: ${error instanceof Error ? error.message : String(error)}`
|
|
110
|
+
}],
|
|
111
|
+
isError: true
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
resolveResourcePath(uri) {
|
|
116
|
+
switch (uri) {
|
|
117
|
+
// Schemas and catalogs removed - now provided through AI tools
|
|
118
|
+
case "specverse://examples/chat-prompts":
|
|
119
|
+
return join(this.resourcesPath, "examples/chat-prompts/ecommerce-store-example.md");
|
|
120
|
+
case "specverse://examples/api-calls":
|
|
121
|
+
return join(this.resourcesPath, "examples/api-calls/orchestrator-workflow-example.js");
|
|
122
|
+
default:
|
|
123
|
+
throw new Error(`Unknown resource URI: ${uri}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
isResourceAvailable(uri) {
|
|
127
|
+
return this.resourceCatalog.has(uri);
|
|
128
|
+
}
|
|
129
|
+
getCachedResourceCount() {
|
|
130
|
+
return Array.from(this.resourceCatalog.values()).filter((r) => r.isLoaded()).length;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
export {
|
|
134
|
+
ResourcesProviderService
|
|
135
|
+
};
|
|
File without changes
|