intention-coding 0.4.0 → 0.4.3
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/package.json +2 -3
- package/dist/db/file-storage.js +0 -638
- package/dist/index.js +0 -26
- package/dist/server/index.js +0 -88
- package/dist/services/bug-fix-agent/index.js +0 -320
- package/dist/services/change-summarizer/index.js +0 -123
- package/dist/services/change-summarizer/prompt/change-analysis.js +0 -56
- package/dist/services/code-generator/index.js +0 -403
- package/dist/services/code-generator/stages/execution-stage.js +0 -549
- package/dist/services/code-generator/stages/ideation-stage.js +0 -267
- package/dist/services/code-generator/stages/optimization-stage.js +0 -334
- package/dist/services/code-generator/stages/planning-stage.js +0 -295
- package/dist/services/code-generator/stages/research-stage.js +0 -283
- package/dist/services/code-generator/stages/review-stage.js +0 -270
- package/dist/services/code-generator/types.js +0 -37
- package/dist/services/code-generator/utils/instruction-executor.js +0 -207
- package/dist/services/code-generator/workflow-manager.js +0 -252
- package/dist/services/image-analysis/analyzer.js +0 -530
- package/dist/services/image-analysis/index.js +0 -406
- package/dist/services/image-analysis/types.js +0 -46
- package/dist/services/image-converter/converter.js +0 -310
- package/dist/services/image-converter/index.js +0 -262
- package/dist/services/image-converter/types.js +0 -31
- package/dist/services/integrated-generator/index.js +0 -1297
- package/dist/services/pdf2md/index.js +0 -180
- package/dist/services/project-template/index.js +0 -83
- package/dist/services/project-template/prompt/project-rules.js +0 -98
- package/dist/services/requirement-analyzer/chunk-reader.js +0 -218
- package/dist/services/requirement-analyzer/core/document-generator.js +0 -254
- package/dist/services/requirement-analyzer/core/intelligent-analyzer.js +0 -169
- package/dist/services/requirement-analyzer/core/project-analyzer.js +0 -199
- package/dist/services/requirement-analyzer/core/requirement-analyzer-service.js +0 -191
- package/dist/services/requirement-analyzer/core/template-selector.js +0 -124
- package/dist/services/requirement-analyzer/core/types.js +0 -23
- package/dist/services/requirement-analyzer/index.js +0 -177
- package/dist/services/requirement-analyzer/prompt/api-template.js +0 -302
- package/dist/services/requirement-analyzer/prompt/app-template.js +0 -455
- package/dist/services/requirement-analyzer/prompt/intelligent-requirement-analysis.js +0 -92
- package/dist/services/requirement-analyzer/prompt/pc-page-template.js +0 -582
- package/dist/services/requirement-analyzer/prompt/requirement-analysis.js +0 -664
- package/dist/services/requirement-analyzer/prompt/sdk-template.js +0 -582
- package/dist/services/requirement-analyzer/utils/file-reader.js +0 -169
- package/dist/services/world2md/index.js +0 -157
- package/dist/types/index.js +0 -2
- package/dist/utils/common.js +0 -72
- package/dist/utils/config.js +0 -163
- package/dist/utils/context-manager.js +0 -114
- package/dist/utils/dify.js +0 -243
- package/dist/utils/logger.js +0 -129
- package/dist/utils/openai.js +0 -225
- package/dist/utils/pack.js +0 -75
|
@@ -1,549 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ExecutionStage = void 0;
|
|
13
|
-
const logger_1 = require("../../../utils/logger");
|
|
14
|
-
const types_1 = require("../types");
|
|
15
|
-
/**
|
|
16
|
-
* 执行阶段处理器
|
|
17
|
-
* 职责:根据批准的计划实施代码开发
|
|
18
|
-
*/
|
|
19
|
-
class ExecutionStage {
|
|
20
|
-
/**
|
|
21
|
-
* 执行实施阶段
|
|
22
|
-
*/
|
|
23
|
-
execute(task, _input) {
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
try {
|
|
26
|
-
logger_1.logger.info("开始执行实施阶段", { taskId: task.id });
|
|
27
|
-
// 检查用户批准
|
|
28
|
-
if (!(_input === null || _input === void 0 ? void 0 : _input.approval)) {
|
|
29
|
-
return {
|
|
30
|
-
stage: types_1.WorkflowStage.EXECUTION,
|
|
31
|
-
status: "pending_approval",
|
|
32
|
-
message: "⚠️ 需要用户批准才能开始执行代码实施。\n\n请确认批准执行计划?",
|
|
33
|
-
data: {},
|
|
34
|
-
nextActions: ["批准执行", "修改计划", "返回计划阶段"],
|
|
35
|
-
requiresUserConfirmation: true,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
// 获取执行计划
|
|
39
|
-
const executionPlan = this.getExecutionPlan(task);
|
|
40
|
-
// 生成执行指令
|
|
41
|
-
const executionInstructions = yield this.generateExecutionInstructions(executionPlan);
|
|
42
|
-
// 生成响应
|
|
43
|
-
const response = this.generateResponse(executionInstructions);
|
|
44
|
-
logger_1.logger.info("实施阶段执行完成", {
|
|
45
|
-
taskId: task.id,
|
|
46
|
-
instructionCount: executionInstructions.length,
|
|
47
|
-
});
|
|
48
|
-
return response;
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
logger_1.logger.error("实施阶段执行失败", { error, taskId: task.id });
|
|
52
|
-
throw new types_1.CodeGeneratorError("代码实施过程中发生错误,请检查执行环境", types_1.ErrorCodes.EXECUTION_FAILED, types_1.WorkflowStage.EXECUTION, { taskId: task.id, originalError: error });
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* 获取执行计划
|
|
58
|
-
*/
|
|
59
|
-
getExecutionPlan(task) {
|
|
60
|
-
var _a;
|
|
61
|
-
const planningStage = task.stages.find((s) => s.stage === types_1.WorkflowStage.PLANNING);
|
|
62
|
-
if (!((_a = planningStage === null || planningStage === void 0 ? void 0 : planningStage.output) === null || _a === void 0 ? void 0 : _a.executionPlan)) {
|
|
63
|
-
throw new Error("未找到执行计划");
|
|
64
|
-
}
|
|
65
|
-
return planningStage.output.executionPlan;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* 生成执行指令
|
|
69
|
-
*/
|
|
70
|
-
generateExecutionInstructions(executionPlan) {
|
|
71
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
const instructions = [];
|
|
73
|
-
let priority = 1;
|
|
74
|
-
// 首先添加计划文档保存指令
|
|
75
|
-
instructions.push(this.createPlanDocumentInstruction(executionPlan, priority++));
|
|
76
|
-
// 为每个步骤生成对应的执行指令
|
|
77
|
-
for (const step of executionPlan.steps) {
|
|
78
|
-
const stepInstructions = yield this.generateStepInstructions(step, priority);
|
|
79
|
-
instructions.push(...stepInstructions);
|
|
80
|
-
priority += stepInstructions.length;
|
|
81
|
-
}
|
|
82
|
-
return instructions;
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* 创建计划文档保存指令
|
|
87
|
-
*/
|
|
88
|
-
createPlanDocumentInstruction(executionPlan, priority) {
|
|
89
|
-
const planContent = this.generatePlanDocument(executionPlan);
|
|
90
|
-
const fileName = this.sanitizeFileName(executionPlan.solutionId || "execution-plan");
|
|
91
|
-
return {
|
|
92
|
-
id: `save_plan_${Date.now()}`,
|
|
93
|
-
type: "file_operation",
|
|
94
|
-
operation: "create",
|
|
95
|
-
targetPath: `.claude/plan/${fileName}.md`,
|
|
96
|
-
content: planContent,
|
|
97
|
-
description: "保存执行计划文档",
|
|
98
|
-
priority,
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* 为单个步骤生成执行指令
|
|
103
|
-
*/
|
|
104
|
-
generateStepInstructions(step, startPriority) {
|
|
105
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
const instructions = [];
|
|
107
|
-
let priority = startPriority;
|
|
108
|
-
switch (step.type) {
|
|
109
|
-
case "file_creation":
|
|
110
|
-
instructions.push(...this.generateFileCreationInstructions(step, priority));
|
|
111
|
-
break;
|
|
112
|
-
case "file_modification":
|
|
113
|
-
instructions.push(...this.generateFileModificationInstructions(step, priority));
|
|
114
|
-
break;
|
|
115
|
-
case "function_implementation":
|
|
116
|
-
instructions.push(...this.generateFunctionImplementationInstructions(step, priority));
|
|
117
|
-
break;
|
|
118
|
-
case "class_implementation":
|
|
119
|
-
instructions.push(...this.generateClassImplementationInstructions(step, priority));
|
|
120
|
-
break;
|
|
121
|
-
case "test_creation":
|
|
122
|
-
instructions.push(...this.generateTestCreationInstructions(step, priority));
|
|
123
|
-
break;
|
|
124
|
-
case "configuration":
|
|
125
|
-
instructions.push(...this.generateConfigurationInstructions(step, priority));
|
|
126
|
-
break;
|
|
127
|
-
default:
|
|
128
|
-
logger_1.logger.warn(`不支持的步骤类型: ${step.type}`);
|
|
129
|
-
}
|
|
130
|
-
return instructions;
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* 生成文件创建指令
|
|
135
|
-
*/
|
|
136
|
-
generateFileCreationInstructions(step, priority) {
|
|
137
|
-
const instructions = [];
|
|
138
|
-
for (const [index, targetFile] of step.targetFiles.entries()) {
|
|
139
|
-
// 从原子操作中获取文件内容
|
|
140
|
-
const createOperation = step.atomicOperations.find((op) => op.type === "create_file" && op.target.includes(targetFile));
|
|
141
|
-
instructions.push({
|
|
142
|
-
id: `create_file_${step.id}_${index}`,
|
|
143
|
-
type: "file_operation",
|
|
144
|
-
operation: "create",
|
|
145
|
-
targetPath: targetFile,
|
|
146
|
-
content: (createOperation === null || createOperation === void 0 ? void 0 : createOperation.content) ||
|
|
147
|
-
this.generateDefaultFileContent(targetFile),
|
|
148
|
-
description: `创建文件: ${targetFile}`,
|
|
149
|
-
priority: priority + index,
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
return instructions;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* 生成文件修改指令
|
|
156
|
-
*/
|
|
157
|
-
generateFileModificationInstructions(step, priority) {
|
|
158
|
-
const instructions = [];
|
|
159
|
-
for (const [index, targetFile] of step.targetFiles.entries()) {
|
|
160
|
-
const modifyOperation = step.atomicOperations.find((op) => op.type === "modify_file" && op.target.includes(targetFile));
|
|
161
|
-
instructions.push({
|
|
162
|
-
id: `modify_file_${step.id}_${index}`,
|
|
163
|
-
type: "file_operation",
|
|
164
|
-
operation: "modify",
|
|
165
|
-
targetPath: targetFile,
|
|
166
|
-
newContent: (modifyOperation === null || modifyOperation === void 0 ? void 0 : modifyOperation.content) || `// ${step.description}`,
|
|
167
|
-
description: `修改文件: ${targetFile}`,
|
|
168
|
-
priority: priority + index,
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
return instructions;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* 生成函数实现指令
|
|
175
|
-
*/
|
|
176
|
-
generateFunctionImplementationInstructions(step, priority) {
|
|
177
|
-
const instructions = [];
|
|
178
|
-
for (const [index, targetFile] of step.targetFiles.entries()) {
|
|
179
|
-
const functionOperation = step.atomicOperations.find((op) => op.type === "create_function");
|
|
180
|
-
const functionContent = this.generateFunctionContent(functionOperation, step);
|
|
181
|
-
instructions.push({
|
|
182
|
-
id: `implement_function_${step.id}_${index}`,
|
|
183
|
-
type: "file_operation",
|
|
184
|
-
operation: targetFile.includes("new") ? "create" : "modify",
|
|
185
|
-
targetPath: targetFile,
|
|
186
|
-
content: functionContent,
|
|
187
|
-
description: `实现函数: ${step.name}`,
|
|
188
|
-
priority: priority + index,
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
return instructions;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* 生成类实现指令
|
|
195
|
-
*/
|
|
196
|
-
generateClassImplementationInstructions(step, priority) {
|
|
197
|
-
const instructions = [];
|
|
198
|
-
for (const [index, targetFile] of step.targetFiles.entries()) {
|
|
199
|
-
const classOperation = step.atomicOperations.find((op) => op.type === "create_class");
|
|
200
|
-
const classContent = this.generateClassContent(classOperation, step);
|
|
201
|
-
instructions.push({
|
|
202
|
-
id: `implement_class_${step.id}_${index}`,
|
|
203
|
-
type: "file_operation",
|
|
204
|
-
operation: targetFile.includes("new") ? "create" : "modify",
|
|
205
|
-
targetPath: targetFile,
|
|
206
|
-
content: classContent,
|
|
207
|
-
description: `实现类: ${step.name}`,
|
|
208
|
-
priority: priority + index,
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
return instructions;
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* 生成测试创建指令
|
|
215
|
-
*/
|
|
216
|
-
generateTestCreationInstructions(step, priority) {
|
|
217
|
-
const instructions = [];
|
|
218
|
-
for (const [index, targetFile] of step.targetFiles.entries()) {
|
|
219
|
-
const testContent = this.generateTestContent(step);
|
|
220
|
-
instructions.push({
|
|
221
|
-
id: `create_test_${step.id}_${index}`,
|
|
222
|
-
type: "file_operation",
|
|
223
|
-
operation: "create",
|
|
224
|
-
targetPath: targetFile,
|
|
225
|
-
content: testContent,
|
|
226
|
-
description: `创建测试文件: ${targetFile}`,
|
|
227
|
-
priority: priority + index,
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
return instructions;
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* 生成配置指令
|
|
234
|
-
*/
|
|
235
|
-
generateConfigurationInstructions(step, priority) {
|
|
236
|
-
const instructions = [];
|
|
237
|
-
// 检查是否有依赖安装需求
|
|
238
|
-
const dependencyOperation = step.atomicOperations.find((op) => op.type === "install_dependency");
|
|
239
|
-
if (dependencyOperation) {
|
|
240
|
-
instructions.push({
|
|
241
|
-
id: `install_deps_${step.id}`,
|
|
242
|
-
type: "dependency_install",
|
|
243
|
-
packageManager: "npm", // 可以根据项目类型动态确定
|
|
244
|
-
packages: dependencyOperation.content.split(", "),
|
|
245
|
-
isDev: false,
|
|
246
|
-
description: `安装依赖: ${dependencyOperation.content}`,
|
|
247
|
-
priority: priority,
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
// 处理配置文件修改
|
|
251
|
-
for (const [index, targetFile] of step.targetFiles.entries()) {
|
|
252
|
-
if (targetFile.endsWith(".json")) {
|
|
253
|
-
instructions.push({
|
|
254
|
-
id: `config_${step.id}_${index}`,
|
|
255
|
-
type: "configuration",
|
|
256
|
-
configType: this.getConfigType(targetFile),
|
|
257
|
-
configPath: targetFile,
|
|
258
|
-
changes: this.extractConfigChanges(step),
|
|
259
|
-
description: `配置文件: ${targetFile}`,
|
|
260
|
-
priority: priority + index + 1,
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
return instructions;
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* 生成响应 - MCP 架构版本
|
|
268
|
-
*/
|
|
269
|
-
generateResponse(executionInstructions) {
|
|
270
|
-
return {
|
|
271
|
-
stage: types_1.WorkflowStage.EXECUTION,
|
|
272
|
-
status: "success",
|
|
273
|
-
message: this.formatExecutionMessage(executionInstructions),
|
|
274
|
-
data: {
|
|
275
|
-
instructionCount: executionInstructions.length,
|
|
276
|
-
executionInstructions: executionInstructions, // MCP 客户端将执行这些指令
|
|
277
|
-
mcpMode: true, // 标识为 MCP 模式
|
|
278
|
-
},
|
|
279
|
-
nextActions: [
|
|
280
|
-
"等待 MCP 客户端执行指令",
|
|
281
|
-
"查看指令详情",
|
|
282
|
-
"修改指令",
|
|
283
|
-
"跳过执行",
|
|
284
|
-
],
|
|
285
|
-
requiresUserConfirmation: false,
|
|
286
|
-
executionInstructions: executionInstructions, // 直接提供给 MCP 客户端
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* 生成默认文件内容
|
|
291
|
-
*/
|
|
292
|
-
generateDefaultFileContent(filePath) {
|
|
293
|
-
var _a, _b;
|
|
294
|
-
const ext = (_a = filePath.split(".").pop()) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
295
|
-
switch (ext) {
|
|
296
|
-
case "ts":
|
|
297
|
-
case "js":
|
|
298
|
-
return `// ${filePath}\n// 自动生成的文件\n\nexport {};\n`;
|
|
299
|
-
case "json":
|
|
300
|
-
return "{\n \n}\n";
|
|
301
|
-
case "md":
|
|
302
|
-
return `# ${(_b = filePath.split("/").pop()) === null || _b === void 0 ? void 0 : _b.replace(".md", "")}\n\n`;
|
|
303
|
-
case "css":
|
|
304
|
-
return `/* ${filePath} */\n\n`;
|
|
305
|
-
case "html":
|
|
306
|
-
return `<!DOCTYPE html>\n<html>\n<head>\n <title>${filePath}</title>\n</head>\n<body>\n \n</body>\n</html>\n`;
|
|
307
|
-
default:
|
|
308
|
-
return `// ${filePath}\n`;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* 生成函数内容
|
|
313
|
-
*/
|
|
314
|
-
generateFunctionContent(operation, step) {
|
|
315
|
-
const functionName = (operation === null || operation === void 0 ? void 0 : operation.target) || "newFunction";
|
|
316
|
-
const description = step.description || "新函数";
|
|
317
|
-
return `
|
|
318
|
-
/**
|
|
319
|
-
* ${description}
|
|
320
|
-
*/
|
|
321
|
-
export function ${functionName}() {
|
|
322
|
-
// TODO: 实现 ${description}
|
|
323
|
-
throw new Error('Function not implemented');
|
|
324
|
-
}
|
|
325
|
-
`.trim();
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* 生成类内容
|
|
329
|
-
*/
|
|
330
|
-
generateClassContent(operation, step) {
|
|
331
|
-
const className = (operation === null || operation === void 0 ? void 0 : operation.target) || "NewClass";
|
|
332
|
-
const description = step.description || "新类";
|
|
333
|
-
return `
|
|
334
|
-
/**
|
|
335
|
-
* ${description}
|
|
336
|
-
*/
|
|
337
|
-
export class ${className} {
|
|
338
|
-
constructor() {
|
|
339
|
-
// TODO: 实现构造函数
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
// TODO: 添加类方法
|
|
343
|
-
}
|
|
344
|
-
`.trim();
|
|
345
|
-
}
|
|
346
|
-
/**
|
|
347
|
-
* 生成测试内容
|
|
348
|
-
*/
|
|
349
|
-
generateTestContent(step) {
|
|
350
|
-
const testName = step.name || "test";
|
|
351
|
-
return `
|
|
352
|
-
import { describe, it, expect } from 'vitest';
|
|
353
|
-
|
|
354
|
-
describe('${testName}', () => {
|
|
355
|
-
it('should work correctly', () => {
|
|
356
|
-
// TODO: 实现测试用例
|
|
357
|
-
expect(true).toBe(true);
|
|
358
|
-
});
|
|
359
|
-
});
|
|
360
|
-
`.trim();
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* 获取配置文件类型
|
|
364
|
-
*/
|
|
365
|
-
getConfigType(filePath) {
|
|
366
|
-
if (filePath.includes("package.json"))
|
|
367
|
-
return "package.json";
|
|
368
|
-
if (filePath.includes("tsconfig.json"))
|
|
369
|
-
return "tsconfig.json";
|
|
370
|
-
if (filePath.includes("eslint"))
|
|
371
|
-
return "eslint";
|
|
372
|
-
if (filePath.includes("prettier"))
|
|
373
|
-
return "prettier";
|
|
374
|
-
return "custom";
|
|
375
|
-
}
|
|
376
|
-
/**
|
|
377
|
-
* 提取配置变更
|
|
378
|
-
*/
|
|
379
|
-
extractConfigChanges(step) {
|
|
380
|
-
// 从步骤的原子操作中提取配置变更
|
|
381
|
-
const changes = {};
|
|
382
|
-
for (const operation of step.atomicOperations) {
|
|
383
|
-
if (operation.parameters) {
|
|
384
|
-
Object.assign(changes, operation.parameters);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
return changes;
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* 格式化执行消息
|
|
391
|
-
*/
|
|
392
|
-
formatExecutionMessage(instructions) {
|
|
393
|
-
const fileOps = instructions.filter((i) => i.type === "file_operation");
|
|
394
|
-
const shellCmds = instructions.filter((i) => i.type === "shell_command");
|
|
395
|
-
const depInstalls = instructions.filter((i) => i.type === "dependency_install");
|
|
396
|
-
const configs = instructions.filter((i) => i.type === "configuration");
|
|
397
|
-
return `
|
|
398
|
-
# [模式:执行] 执行指令已生成 🚀
|
|
399
|
-
|
|
400
|
-
## 📊 指令统计
|
|
401
|
-
|
|
402
|
-
- **总指令数**: ${instructions.length}
|
|
403
|
-
- **文件操作**: ${fileOps.length}个
|
|
404
|
-
- **Shell命令**: ${shellCmds.length}个
|
|
405
|
-
- **依赖安装**: ${depInstalls.length}个
|
|
406
|
-
- **配置修改**: ${configs.length}个
|
|
407
|
-
|
|
408
|
-
## 📋 执行指令概览
|
|
409
|
-
|
|
410
|
-
${this.formatInstructionsByType(instructions)}
|
|
411
|
-
|
|
412
|
-
## 🎯 执行说明
|
|
413
|
-
|
|
414
|
-
这些指令将由 MCP 客户端按优先级顺序执行:
|
|
415
|
-
|
|
416
|
-
1. **文件操作** - 创建、修改项目文件
|
|
417
|
-
2. **依赖安装** - 安装必要的包和库
|
|
418
|
-
3. **配置修改** - 更新配置文件
|
|
419
|
-
4. **Shell命令** - 执行构建和测试命令
|
|
420
|
-
|
|
421
|
-
## ⚡ MCP 客户端执行
|
|
422
|
-
|
|
423
|
-
这些指令将由 MCP 客户端自动执行:
|
|
424
|
-
|
|
425
|
-
1. **指令验证** - 客户端验证指令有效性
|
|
426
|
-
2. **环境检查** - 确认执行环境就绪
|
|
427
|
-
3. **按序执行** - 根据优先级顺序执行指令
|
|
428
|
-
4. **结果报告** - 向服务器报告执行结果
|
|
429
|
-
5. **错误处理** - 处理执行失败的指令
|
|
430
|
-
|
|
431
|
-
**🔄 MCP 执行流程已启动,等待客户端处理...**
|
|
432
|
-
`.trim();
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* 按类型格式化指令
|
|
436
|
-
*/
|
|
437
|
-
formatInstructionsByType(instructions) {
|
|
438
|
-
const sections = [];
|
|
439
|
-
// 文件操作
|
|
440
|
-
const fileOps = instructions.filter((i) => i.type === "file_operation");
|
|
441
|
-
if (fileOps.length > 0) {
|
|
442
|
-
sections.push(`
|
|
443
|
-
### 📄 文件操作 (${fileOps.length}个)
|
|
444
|
-
|
|
445
|
-
${fileOps
|
|
446
|
-
.map((inst, index) => `${index + 1}. **${inst.operation.toUpperCase()}** \`${inst.targetPath}\` - ${inst.description}`)
|
|
447
|
-
.join("\n")}
|
|
448
|
-
`.trim());
|
|
449
|
-
}
|
|
450
|
-
// 依赖安装
|
|
451
|
-
const depInstalls = instructions.filter((i) => i.type === "dependency_install");
|
|
452
|
-
if (depInstalls.length > 0) {
|
|
453
|
-
sections.push(`
|
|
454
|
-
### 📦 依赖安装 (${depInstalls.length}个)
|
|
455
|
-
|
|
456
|
-
${depInstalls
|
|
457
|
-
.map((inst, index) => `${index + 1}. **${inst.packageManager}** install ${inst.packages.join(" ")} - ${inst.description}`)
|
|
458
|
-
.join("\n")}
|
|
459
|
-
`.trim());
|
|
460
|
-
}
|
|
461
|
-
// 配置修改
|
|
462
|
-
const configs = instructions.filter((i) => i.type === "configuration");
|
|
463
|
-
if (configs.length > 0) {
|
|
464
|
-
sections.push(`
|
|
465
|
-
### ⚙️ 配置修改 (${configs.length}个)
|
|
466
|
-
|
|
467
|
-
${configs
|
|
468
|
-
.map((inst, index) => `${index + 1}. **${inst.configType}** \`${inst.configPath}\` - ${inst.description}`)
|
|
469
|
-
.join("\n")}
|
|
470
|
-
`.trim());
|
|
471
|
-
}
|
|
472
|
-
// Shell命令
|
|
473
|
-
const shellCmds = instructions.filter((i) => i.type === "shell_command");
|
|
474
|
-
if (shellCmds.length > 0) {
|
|
475
|
-
sections.push(`
|
|
476
|
-
### 💻 Shell命令 (${shellCmds.length}个)
|
|
477
|
-
|
|
478
|
-
${shellCmds
|
|
479
|
-
.map((inst, index) => `${index + 1}. \`${inst.command}\` - ${inst.description}`)
|
|
480
|
-
.join("\n")}
|
|
481
|
-
`.trim());
|
|
482
|
-
}
|
|
483
|
-
return sections.join("\n\n");
|
|
484
|
-
}
|
|
485
|
-
/**
|
|
486
|
-
* 生成计划文档
|
|
487
|
-
*/
|
|
488
|
-
generatePlanDocument(executionPlan) {
|
|
489
|
-
return `
|
|
490
|
-
# 执行计划文档
|
|
491
|
-
|
|
492
|
-
## 方案信息
|
|
493
|
-
|
|
494
|
-
- **方案ID**: ${executionPlan.solutionId}
|
|
495
|
-
- **预估时间**: ${executionPlan.estimatedDuration}
|
|
496
|
-
- **生成时间**: ${new Date().toISOString()}
|
|
497
|
-
|
|
498
|
-
## 执行步骤
|
|
499
|
-
|
|
500
|
-
${executionPlan.steps
|
|
501
|
-
.map((step, index) => `
|
|
502
|
-
### ${index + 1}. ${step.name}
|
|
503
|
-
|
|
504
|
-
- **类型**: ${step.type}
|
|
505
|
-
- **描述**: ${step.description}
|
|
506
|
-
- **目标文件**: ${step.targetFiles.join(", ")}
|
|
507
|
-
- **预期结果**: ${step.expectedResult}
|
|
508
|
-
- **预估时间**: ${step.estimatedTime}
|
|
509
|
-
- **依赖**: ${step.dependencies.join(", ") || "无"}
|
|
510
|
-
|
|
511
|
-
#### 原子操作
|
|
512
|
-
${step.atomicOperations
|
|
513
|
-
.map((op) => `- ${op.type}: ${op.target}`)
|
|
514
|
-
.join("\n")}
|
|
515
|
-
`)
|
|
516
|
-
.join("\n")}
|
|
517
|
-
|
|
518
|
-
## 风险评估
|
|
519
|
-
|
|
520
|
-
${executionPlan.riskAssessment}
|
|
521
|
-
|
|
522
|
-
## 回滚计划
|
|
523
|
-
|
|
524
|
-
${executionPlan.rollbackPlan}
|
|
525
|
-
|
|
526
|
-
## 执行说明
|
|
527
|
-
|
|
528
|
-
此计划将通过 MCP 客户端自动执行,包括:
|
|
529
|
-
1. 文件创建和修改
|
|
530
|
-
2. 依赖包安装
|
|
531
|
-
3. 配置文件更新
|
|
532
|
-
4. 必要的构建命令
|
|
533
|
-
|
|
534
|
-
---
|
|
535
|
-
*此文档由代码生成智能体自动生成*
|
|
536
|
-
`.trim();
|
|
537
|
-
}
|
|
538
|
-
/**
|
|
539
|
-
* 清理文件名
|
|
540
|
-
*/
|
|
541
|
-
sanitizeFileName(name) {
|
|
542
|
-
return name
|
|
543
|
-
.replace(/[^a-zA-Z0-9\u4e00-\u9fa5]/g, "_")
|
|
544
|
-
.replace(/_+/g, "_")
|
|
545
|
-
.replace(/^_|_$/g, "")
|
|
546
|
-
.substring(0, 50);
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
exports.ExecutionStage = ExecutionStage;
|