@agiflowai/scaffold-mcp 1.0.11 → 1.0.12

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 (32) hide show
  1. package/dist/ListScaffoldingMethodsTool-D3ecmSLf.mjs +994 -0
  2. package/dist/ListScaffoldingMethodsTool-D7S3xpJE.cjs +1082 -0
  3. package/dist/cli.cjs +11 -16
  4. package/dist/cli.mjs +5 -9
  5. package/dist/index.cjs +7 -11
  6. package/dist/index.mjs +2 -6
  7. package/dist/{stdio-AbTm52SJ.mjs → stdio-DqZJsqKM.mjs} +15 -18
  8. package/dist/{stdio-baUp7xGL.cjs → stdio-ohQyWnxq.cjs} +24 -28
  9. package/dist/{useScaffoldMethod-CPgJIBHx.mjs → useScaffoldMethod-B-q_yBnX.mjs} +1 -2
  10. package/dist/{useScaffoldMethod-BMWhFebp.mjs → useScaffoldMethod-CC8ARsl9.mjs} +7 -5
  11. package/dist/{useScaffoldMethod-CcrpFEPv.cjs → useScaffoldMethod-DqF6pT1A.cjs} +1 -3
  12. package/dist/{useScaffoldMethod-DOvwnNOJ.cjs → useScaffoldMethod-fzsnprJs.cjs} +10 -9
  13. package/package.json +5 -5
  14. package/dist/ListScaffoldingMethodsTool-B49G_iLj.mjs +0 -350
  15. package/dist/ListScaffoldingMethodsTool-DuYGFDwJ.cjs +0 -376
  16. package/dist/ScaffoldConfigLoader-8YI7v2GJ.mjs +0 -142
  17. package/dist/ScaffoldConfigLoader-BWpNpMx-.cjs +0 -150
  18. package/dist/ScaffoldConfigLoader-DKJtnrWT.mjs +0 -3
  19. package/dist/ScaffoldConfigLoader-HutEtfaH.cjs +0 -3
  20. package/dist/ScaffoldService-DSQBnAHm.cjs +0 -308
  21. package/dist/ScaffoldService-DcsGLMuD.mjs +0 -295
  22. package/dist/ScaffoldService-DfXjmrNT.cjs +0 -3
  23. package/dist/ScaffoldService-dL74anIv.mjs +0 -3
  24. package/dist/TemplateService-7QcWREot.cjs +0 -85
  25. package/dist/TemplateService-B1bd6iHw.mjs +0 -3
  26. package/dist/TemplateService-CVDL2uqt.mjs +0 -79
  27. package/dist/TemplateService-DUbdBOFs.cjs +0 -3
  28. package/dist/VariableReplacementService-B9RA8D0a.mjs +0 -66
  29. package/dist/VariableReplacementService-BO-UYgcf.mjs +0 -3
  30. package/dist/VariableReplacementService-DNYx0Dym.cjs +0 -73
  31. package/dist/VariableReplacementService-wuYKgeui.cjs +0 -3
  32. package/dist/chunk-CbDLau6x.cjs +0 -34
@@ -1,350 +0,0 @@
1
- import { t as TemplateService } from "./TemplateService-CVDL2uqt.mjs";
2
- import path from "node:path";
3
- import { ProjectConfigResolver, copy, ensureDir, log, pathExists, readFile, readJson, readdir, stat, writeFile } from "@agiflowai/aicode-utils";
4
- import yaml from "js-yaml";
5
-
6
- //#region src/utils/pagination.ts
7
- var PaginationHelper = class PaginationHelper {
8
- /**
9
- * Default page size for pagination
10
- */
11
- static DEFAULT_PAGE_SIZE = 10;
12
- /**
13
- * Decodes a cursor string to extract the start index
14
- * @param cursor - String representing the start index (e.g., "10")
15
- * @returns Start index or 0 if invalid/undefined
16
- */
17
- static decodeCursor(cursor) {
18
- if (!cursor) return 0;
19
- const index = Number.parseInt(cursor, 10);
20
- if (Number.isNaN(index) || index < 0) return 0;
21
- return index;
22
- }
23
- /**
24
- * Encodes an index into a cursor string
25
- * @param index - Start index to encode
26
- * @returns Cursor string (e.g., "10")
27
- */
28
- static encodeCursor(index) {
29
- return index.toString();
30
- }
31
- /**
32
- * Paginates an array of items
33
- * @param items - All items to paginate
34
- * @param cursor - Optional cursor representing the start index
35
- * @param pageSize - Number of items per page (default: 10)
36
- * @param includeMeta - Whether to include metadata in response (default: true)
37
- * @returns Paginated result with items and optional nextCursor
38
- */
39
- static paginate(items, cursor, pageSize = PaginationHelper.DEFAULT_PAGE_SIZE, includeMeta = true) {
40
- const startIndex = PaginationHelper.decodeCursor(cursor);
41
- const endIndex = startIndex + pageSize;
42
- const result = {
43
- items: items.slice(startIndex, endIndex),
44
- nextCursor: endIndex < items.length ? PaginationHelper.encodeCursor(endIndex) : void 0
45
- };
46
- if (includeMeta) result._meta = {
47
- total: items.length,
48
- offset: startIndex,
49
- limit: pageSize
50
- };
51
- return result;
52
- }
53
- };
54
-
55
- //#endregion
56
- //#region src/services/FileSystemService.ts
57
- var FileSystemService = class {
58
- async pathExists(path$1) {
59
- return pathExists(path$1);
60
- }
61
- async readFile(path$1, encoding = "utf8") {
62
- return readFile(path$1, encoding);
63
- }
64
- async readJson(path$1) {
65
- return readJson(path$1);
66
- }
67
- async writeFile(path$1, content, encoding = "utf8") {
68
- return writeFile(path$1, content, encoding);
69
- }
70
- async ensureDir(path$1) {
71
- return ensureDir(path$1);
72
- }
73
- async copy(src, dest) {
74
- return copy(src, dest);
75
- }
76
- async readdir(path$1) {
77
- return readdir(path$1);
78
- }
79
- async stat(path$1) {
80
- return stat(path$1);
81
- }
82
- };
83
-
84
- //#endregion
85
- //#region src/services/ScaffoldingMethodsService.ts
86
- var ScaffoldingMethodsService = class {
87
- templateService;
88
- constructor(fileSystem, templatesRootPath) {
89
- this.fileSystem = fileSystem;
90
- this.templatesRootPath = templatesRootPath;
91
- this.templateService = new TemplateService();
92
- }
93
- async listScaffoldingMethods(projectPath, cursor) {
94
- const absoluteProjectPath = path.resolve(projectPath);
95
- const sourceTemplate = (await ProjectConfigResolver.resolveProjectConfig(absoluteProjectPath)).sourceTemplate;
96
- return this.listScaffoldingMethodsByTemplate(sourceTemplate, cursor);
97
- }
98
- async listScaffoldingMethodsByTemplate(templateName, cursor) {
99
- const templatePath = await this.findTemplatePath(templateName);
100
- if (!templatePath) throw new Error(`Template not found for sourceTemplate: ${templateName}`);
101
- const fullTemplatePath = path.join(this.templatesRootPath, templatePath);
102
- const scaffoldYamlPath = path.join(fullTemplatePath, "scaffold.yaml");
103
- if (!await this.fileSystem.pathExists(scaffoldYamlPath)) throw new Error(`scaffold.yaml not found at ${scaffoldYamlPath}`);
104
- const scaffoldContent = await this.fileSystem.readFile(scaffoldYamlPath, "utf8");
105
- const architectConfig = yaml.load(scaffoldContent);
106
- const methods = [];
107
- if (architectConfig.features && Array.isArray(architectConfig.features)) architectConfig.features.forEach((feature) => {
108
- const featureName = feature.name || `scaffold-${templateName}`;
109
- methods.push({
110
- name: featureName,
111
- description: feature.description || "",
112
- instruction: feature.instruction || "",
113
- variables_schema: feature.variables_schema || {
114
- type: "object",
115
- properties: {},
116
- required: [],
117
- additionalProperties: false
118
- },
119
- generator: feature.generator
120
- });
121
- });
122
- const paginatedResult = PaginationHelper.paginate(methods, cursor);
123
- return {
124
- sourceTemplate: templateName,
125
- templatePath,
126
- methods: paginatedResult.items,
127
- nextCursor: paginatedResult.nextCursor,
128
- _meta: paginatedResult._meta
129
- };
130
- }
131
- /**
132
- * Gets scaffolding methods with instructions rendered using provided variables
133
- */
134
- async listScaffoldingMethodsWithVariables(projectPath, variables, cursor) {
135
- const result = await this.listScaffoldingMethods(projectPath, cursor);
136
- const processedMethods = result.methods.map((method) => ({
137
- ...method,
138
- instruction: method.instruction ? this.processScaffoldInstruction(method.instruction, variables) : void 0
139
- }));
140
- return {
141
- ...result,
142
- methods: processedMethods
143
- };
144
- }
145
- /**
146
- * Processes scaffold instruction with template service
147
- */
148
- processScaffoldInstruction(instruction, variables) {
149
- if (this.templateService.containsTemplateVariables(instruction)) return this.templateService.renderString(instruction, variables);
150
- return instruction;
151
- }
152
- async findTemplatePath(sourceTemplate) {
153
- const templateDirs = await this.discoverTemplateDirs();
154
- if (templateDirs.includes(sourceTemplate)) return sourceTemplate;
155
- for (const templateDir of templateDirs) {
156
- const templatePath = path.join(this.templatesRootPath, templateDir);
157
- const scaffoldYamlPath = path.join(templatePath, "scaffold.yaml");
158
- if (await this.fileSystem.pathExists(scaffoldYamlPath)) try {
159
- const scaffoldContent = await this.fileSystem.readFile(scaffoldYamlPath, "utf8");
160
- const architectConfig = yaml.load(scaffoldContent);
161
- if (architectConfig.boilerplate && Array.isArray(architectConfig.boilerplate)) {
162
- for (const boilerplate of architectConfig.boilerplate) if (boilerplate.name?.includes(sourceTemplate)) return templateDir;
163
- }
164
- } catch (error) {
165
- log.warn(`Failed to read scaffold.yaml at ${scaffoldYamlPath}:`, error);
166
- }
167
- }
168
- return null;
169
- }
170
- /**
171
- * Resolves the project path, handling both monorepo and monolith cases
172
- * Uses ProjectConfigResolver to find the correct workspace/project root
173
- */
174
- async resolveProjectPath(projectPath) {
175
- const absolutePath = path.resolve(projectPath);
176
- return (await ProjectConfigResolver.resolveProjectConfig(absolutePath)).workspaceRoot || absolutePath;
177
- }
178
- /**
179
- * Dynamically discovers all template directories
180
- * Supports both flat structure (templates/nextjs-15) and nested structure (templates/apps/nextjs-15)
181
- **/
182
- async discoverTemplateDirs() {
183
- const templateDirs = [];
184
- try {
185
- const items = await this.fileSystem.readdir(this.templatesRootPath);
186
- for (const item of items) {
187
- const itemPath = path.join(this.templatesRootPath, item);
188
- if (!(await this.fileSystem.stat(itemPath)).isDirectory()) continue;
189
- const scaffoldYamlPath = path.join(itemPath, "scaffold.yaml");
190
- if (await this.fileSystem.pathExists(scaffoldYamlPath)) {
191
- templateDirs.push(item);
192
- continue;
193
- }
194
- try {
195
- const subItems = await this.fileSystem.readdir(itemPath);
196
- for (const subItem of subItems) {
197
- const subItemPath = path.join(itemPath, subItem);
198
- if (!(await this.fileSystem.stat(subItemPath)).isDirectory()) continue;
199
- const subScaffoldYamlPath = path.join(subItemPath, "scaffold.yaml");
200
- if (await this.fileSystem.pathExists(subScaffoldYamlPath)) {
201
- const relativePath = path.join(item, subItem);
202
- templateDirs.push(relativePath);
203
- }
204
- }
205
- } catch (error) {
206
- log.warn(`Failed to read subdirectories in ${itemPath}:`, error);
207
- }
208
- }
209
- } catch (error) {
210
- log.warn(`Failed to read templates root directory ${this.templatesRootPath}:`, error);
211
- }
212
- return templateDirs;
213
- }
214
- async useScaffoldMethod(request) {
215
- const { projectPath, scaffold_feature_name, variables, sessionId } = request;
216
- const absoluteProjectPath = await this.resolveProjectPath(projectPath);
217
- const scaffoldingMethods = await this.listScaffoldingMethods(absoluteProjectPath);
218
- const method = scaffoldingMethods.methods.find((m) => m.name === scaffold_feature_name);
219
- if (!method) {
220
- const availableMethods = scaffoldingMethods.methods.map((m) => m.name).join(", ");
221
- throw new Error(`Scaffold method '${scaffold_feature_name}' not found. Available methods: ${availableMethods}`);
222
- }
223
- const ScaffoldService = (await import("./ScaffoldService-dL74anIv.mjs")).ScaffoldService;
224
- const ScaffoldConfigLoader = (await import("./ScaffoldConfigLoader-DKJtnrWT.mjs")).ScaffoldConfigLoader;
225
- const VariableReplacementService = (await import("./VariableReplacementService-BO-UYgcf.mjs")).VariableReplacementService;
226
- const TemplateService$1 = (await import("./TemplateService-B1bd6iHw.mjs")).TemplateService;
227
- const templateService = new TemplateService$1();
228
- const scaffoldConfigLoader = new ScaffoldConfigLoader(this.fileSystem, templateService);
229
- const variableReplacer = new VariableReplacementService(this.fileSystem, templateService);
230
- const scaffoldService = new ScaffoldService(this.fileSystem, scaffoldConfigLoader, variableReplacer, this.templatesRootPath);
231
- const projectName = path.basename(absoluteProjectPath);
232
- const result = await scaffoldService.useFeature({
233
- projectPath: absoluteProjectPath,
234
- templateFolder: scaffoldingMethods.templatePath,
235
- featureName: scaffold_feature_name,
236
- variables: {
237
- ...variables,
238
- appPath: absoluteProjectPath,
239
- appName: projectName
240
- }
241
- });
242
- if (!result.success) throw new Error(result.message);
243
- if (sessionId && result.createdFiles && result.createdFiles.length > 0) try {
244
- const { ExecutionLogService, DECISION_ALLOW } = await import("@agiflowai/hooks-adapter");
245
- await new ExecutionLogService(sessionId).logExecution({
246
- filePath: absoluteProjectPath,
247
- operation: "scaffold",
248
- decision: DECISION_ALLOW,
249
- generatedFiles: result.createdFiles
250
- });
251
- } catch (error) {
252
- log.warn("Failed to log scaffold execution:", error);
253
- }
254
- return {
255
- success: true,
256
- message: `
257
- Successfully scaffolded ${scaffold_feature_name} in ${projectPath}.
258
- Please follow this **instruction**: \n ${method.instruction ? this.processScaffoldInstruction(method.instruction, variables) : ""}.
259
- -> Create or update the plan based on the instruction.
260
- `,
261
- warnings: result.warnings,
262
- createdFiles: result.createdFiles,
263
- existingFiles: result.existingFiles
264
- };
265
- }
266
- };
267
-
268
- //#endregion
269
- //#region src/instructions/tools/list-scaffolding-methods/description.md?raw
270
- var description_default = "Lists all available scaffolding methods (features) that can be added to an existing project{% if not isMonolith %} or for a specific template{% endif %}.\n\nThis tool:\n{% if isMonolith %}\n- Reads your project's sourceTemplate from toolkit.yaml at workspace root\n{% else %}\n- Reads the project's sourceTemplate from project.json (monorepo) or toolkit.yaml (monolith), OR\n- Directly uses the provided templateName to list available features\n{% endif %}\n- Returns available features for that template type\n- Provides variable schemas for each scaffolding method\n- Shows descriptions of what each method creates\n\nUse this FIRST when adding features to understand:\n- What scaffolding methods are available\n- What variables each method requires\n- What files/features will be generated\n\nExample methods might include:\n- Adding new React routes (for React apps)\n- Creating API endpoints (for backend projects)\n- Adding new components (for frontend projects)\n- Setting up database models (for API projects)\n";
271
-
272
- //#endregion
273
- //#region src/tools/ListScaffoldingMethodsTool.ts
274
- var ListScaffoldingMethodsTool = class ListScaffoldingMethodsTool {
275
- static TOOL_NAME = "list-scaffolding-methods";
276
- fileSystemService;
277
- scaffoldingMethodsService;
278
- templateService;
279
- isMonolith;
280
- constructor(templatesPath, isMonolith = false) {
281
- this.fileSystemService = new FileSystemService();
282
- this.scaffoldingMethodsService = new ScaffoldingMethodsService(this.fileSystemService, templatesPath);
283
- this.templateService = new TemplateService();
284
- this.isMonolith = isMonolith;
285
- }
286
- /**
287
- * Get the tool definition for MCP
288
- */
289
- getDefinition() {
290
- const description = this.templateService.renderString(description_default, { isMonolith: this.isMonolith });
291
- const properties = { cursor: {
292
- type: "string",
293
- description: "Optional pagination cursor to fetch the next page of results. Omit to fetch the first page."
294
- } };
295
- if (!this.isMonolith) {
296
- properties.projectPath = {
297
- type: "string",
298
- description: "Absolute path to the project directory (for monorepo: containing project.json; for monolith: workspace root with toolkit.yaml). Either projectPath or templateName is required."
299
- };
300
- properties.templateName = {
301
- type: "string",
302
- description: "Name of the template to list scaffolding methods for (e.g., \"nextjs-15\", \"typescript-mcp-package\"). Either projectPath or templateName is required."
303
- };
304
- }
305
- return {
306
- name: ListScaffoldingMethodsTool.TOOL_NAME,
307
- description: description.trim(),
308
- inputSchema: {
309
- type: "object",
310
- properties,
311
- additionalProperties: false
312
- }
313
- };
314
- }
315
- /**
316
- * Execute the tool
317
- */
318
- async execute(args) {
319
- try {
320
- const { projectPath, templateName, cursor } = args;
321
- let result;
322
- if (this.isMonolith) try {
323
- const resolvedTemplateName = (await ProjectConfigResolver.resolveProjectConfig(process.cwd())).sourceTemplate;
324
- result = await this.scaffoldingMethodsService.listScaffoldingMethodsByTemplate(resolvedTemplateName, cursor);
325
- } catch (error) {
326
- throw new Error(`Failed to read template name from configuration: ${error instanceof Error ? error.message : String(error)}`);
327
- }
328
- else {
329
- if (!projectPath && !templateName) throw new Error("Either projectPath or templateName must be provided");
330
- if (projectPath) result = await this.scaffoldingMethodsService.listScaffoldingMethods(projectPath, cursor);
331
- else result = await this.scaffoldingMethodsService.listScaffoldingMethodsByTemplate(templateName, cursor);
332
- }
333
- return { content: [{
334
- type: "text",
335
- text: JSON.stringify(result, null, 2)
336
- }] };
337
- } catch (error) {
338
- return {
339
- content: [{
340
- type: "text",
341
- text: `Error listing scaffolding methods: ${error instanceof Error ? error.message : String(error)}`
342
- }],
343
- isError: true
344
- };
345
- }
346
- }
347
- };
348
-
349
- //#endregion
350
- export { PaginationHelper as i, ScaffoldingMethodsService as n, FileSystemService as r, ListScaffoldingMethodsTool as t };