intention-coding 0.3.8 → 0.4.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.
- package/package.json +1 -1
- 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
package/dist/server/index.js
DELETED
|
@@ -1,88 +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.createMcpServer = createMcpServer;
|
|
13
|
-
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
14
|
-
const logger_1 = require("../utils/logger");
|
|
15
|
-
const config_1 = require("../utils/config");
|
|
16
|
-
// 导入所有工具
|
|
17
|
-
const world2md_1 = require("../services/world2md");
|
|
18
|
-
const pdf2md_1 = require("../services/pdf2md");
|
|
19
|
-
const project_template_1 = require("../services/project-template");
|
|
20
|
-
const requirement_analyzer_1 = require("../services/requirement-analyzer");
|
|
21
|
-
const change_summarizer_1 = require("../services/change-summarizer");
|
|
22
|
-
const image_analysis_1 = require("../services/image-analysis");
|
|
23
|
-
const image_converter_1 = require("../services/image-converter");
|
|
24
|
-
const bug_fix_agent_1 = require("../services/bug-fix-agent");
|
|
25
|
-
const code_generator_1 = require("../services/code-generator");
|
|
26
|
-
function createMcpServer() {
|
|
27
|
-
// 创建MCP服务器实例
|
|
28
|
-
const server = new mcp_js_1.McpServer({
|
|
29
|
-
name: config_1.SERVICE_CONFIG.name,
|
|
30
|
-
version: config_1.SERVICE_CONFIG.version,
|
|
31
|
-
});
|
|
32
|
-
// 注册所有工具
|
|
33
|
-
const tools = [
|
|
34
|
-
world2md_1.word2mdTool,
|
|
35
|
-
pdf2md_1.pdf2mdTool,
|
|
36
|
-
project_template_1.initProjectStandard,
|
|
37
|
-
requirement_analyzer_1.requirementAnalyzerTool,
|
|
38
|
-
change_summarizer_1.changeSummarizer,
|
|
39
|
-
image_analysis_1.imageAnalysisTool,
|
|
40
|
-
image_converter_1.imageConverterTool,
|
|
41
|
-
bug_fix_agent_1.bugFixAgentTool,
|
|
42
|
-
code_generator_1.codeGeneratorTool,
|
|
43
|
-
];
|
|
44
|
-
tools.forEach(tool => {
|
|
45
|
-
try {
|
|
46
|
-
const schema = tool.parameters;
|
|
47
|
-
const rawShape = schema._def.shape;
|
|
48
|
-
server.registerTool(tool.name, {
|
|
49
|
-
description: tool.description,
|
|
50
|
-
inputSchema: rawShape
|
|
51
|
-
},
|
|
52
|
-
// 使用泛型来处理工具的参数类型
|
|
53
|
-
(args, extra) => __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
try {
|
|
55
|
-
// 使用schema验证参数
|
|
56
|
-
const validatedArgs = schema.parse(args);
|
|
57
|
-
const result = yield tool.execute(validatedArgs);
|
|
58
|
-
return {
|
|
59
|
-
content: [{
|
|
60
|
-
type: "text",
|
|
61
|
-
text: result
|
|
62
|
-
}]
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
logger_1.logger.error(`工具执行失败: ${tool.name}`, {
|
|
67
|
-
error: error instanceof Error ? error.message : String(error),
|
|
68
|
-
args
|
|
69
|
-
});
|
|
70
|
-
return {
|
|
71
|
-
content: [{
|
|
72
|
-
type: "text",
|
|
73
|
-
text: `执行失败: ${error instanceof Error ? error.message : String(error)}`
|
|
74
|
-
}],
|
|
75
|
-
isError: true
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
}));
|
|
79
|
-
logger_1.logger.info(`已注册工具: ${tool.name}`);
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
logger_1.logger.error(`注册工具失败: ${tool.name}`, {
|
|
83
|
-
error: error instanceof Error ? error.message : String(error)
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
return server;
|
|
88
|
-
}
|
|
@@ -1,320 +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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.bugFixAgentTool = exports.BugFixAgentParams = void 0;
|
|
16
|
-
const zod_1 = require("zod");
|
|
17
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
18
|
-
const path_1 = __importDefault(require("path"));
|
|
19
|
-
const logger_1 = require("../../utils/logger");
|
|
20
|
-
const config_1 = require("../../utils/config");
|
|
21
|
-
const project_template_1 = require("../project-template");
|
|
22
|
-
const openai_1 = require("../../utils/openai");
|
|
23
|
-
exports.BugFixAgentParams = zod_1.z.object({
|
|
24
|
-
bug_description: zod_1.z.string().describe("Bug描述信息或问题说明"),
|
|
25
|
-
project_path: zod_1.z.string().optional().describe("项目绝对路径,用于指定要分析的项目目录"),
|
|
26
|
-
project_name: zod_1.z.string().optional().default('current-project').describe("项目名称"),
|
|
27
|
-
output_format: zod_1.z.enum(['markdown', 'json']).optional().default('markdown').describe("输出格式")
|
|
28
|
-
});
|
|
29
|
-
exports.bugFixAgentTool = {
|
|
30
|
-
name: "bug修复智能体",
|
|
31
|
-
description: "根据用户提供的bug描述信息,智能分析项目结构并生成修复方案",
|
|
32
|
-
parameters: exports.BugFixAgentParams,
|
|
33
|
-
execute: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
-
const { bug_description, project_path, project_name = 'current-project', output_format = 'markdown' } = args;
|
|
35
|
-
try {
|
|
36
|
-
logger_1.logger.info('开始Bug修复智能体流程', { project_name, project_path });
|
|
37
|
-
// 1. 项目理解阶段:调用project-template服务分析项目结构
|
|
38
|
-
logger_1.logger.info('1. 项目理解阶段:调用project-template服务分析项目结构');
|
|
39
|
-
const projectTemplateArgs = {
|
|
40
|
-
project_name,
|
|
41
|
-
project_path,
|
|
42
|
-
custom_rules: undefined
|
|
43
|
-
};
|
|
44
|
-
const projectAnalysisResult = yield project_template_1.initProjectStandard.execute(projectTemplateArgs);
|
|
45
|
-
let projectRulesPromptData = null;
|
|
46
|
-
if (projectAnalysisResult) {
|
|
47
|
-
try {
|
|
48
|
-
projectRulesPromptData = JSON.parse(projectAnalysisResult);
|
|
49
|
-
}
|
|
50
|
-
catch (parseError) {
|
|
51
|
-
logger_1.logger.warn('项目分析结果解析失败', { parseError });
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
// 2. 规则匹配阶段:根据project_rules.md定位相关内容
|
|
55
|
-
logger_1.logger.info('2. 规则匹配阶段:根据project_rules.md定位相关内容');
|
|
56
|
-
const projectRules = yield getProjectRules(project_name);
|
|
57
|
-
// 3. 任务规划阶段:创建详细的执行清单
|
|
58
|
-
logger_1.logger.info('3. 任务规划阶段:创建详细的执行清单');
|
|
59
|
-
const taskPlan = yield createTaskExecutionPlan(bug_description, projectRulesPromptData, projectRules);
|
|
60
|
-
// 4. 实施阶段:执行修复任务并生成结果
|
|
61
|
-
logger_1.logger.info('4. 实施阶段:执行修复任务并生成结果');
|
|
62
|
-
const fixResult = yield executeBugFixTask(bug_description, projectRules, taskPlan);
|
|
63
|
-
// 5. 保存结果到文件
|
|
64
|
-
const outputPath = yield saveBugFixResult(fixResult, project_name, output_format);
|
|
65
|
-
logger_1.logger.info('Bug修复智能体流程完成', { outputPath });
|
|
66
|
-
return JSON.stringify({
|
|
67
|
-
success: true,
|
|
68
|
-
message: 'Bug修复分析完成',
|
|
69
|
-
data: {
|
|
70
|
-
project_name,
|
|
71
|
-
task_plan: taskPlan,
|
|
72
|
-
fix_result: fixResult,
|
|
73
|
-
output_path: outputPath
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
79
|
-
logger_1.logger.error('Bug修复智能体执行失败', {
|
|
80
|
-
project_name,
|
|
81
|
-
error: errorMsg
|
|
82
|
-
});
|
|
83
|
-
throw new Error(`Bug修复智能体执行失败: ${errorMsg}`);
|
|
84
|
-
}
|
|
85
|
-
})
|
|
86
|
-
};
|
|
87
|
-
// 获取项目规则文件内容
|
|
88
|
-
function getProjectRules(projectName) {
|
|
89
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
try {
|
|
91
|
-
const storageDir = (0, config_1.getStorageDir)();
|
|
92
|
-
const projectRulesPath = path_1.default.join(storageDir, 'project_rules.md');
|
|
93
|
-
// 检查项目规则文件是否存在
|
|
94
|
-
try {
|
|
95
|
-
yield promises_1.default.access(projectRulesPath);
|
|
96
|
-
const projectRules = yield promises_1.default.readFile(projectRulesPath, 'utf-8');
|
|
97
|
-
logger_1.logger.info('成功读取项目规则文件', { projectRulesPath });
|
|
98
|
-
return projectRules;
|
|
99
|
-
}
|
|
100
|
-
catch (fileError) {
|
|
101
|
-
logger_1.logger.warn('项目规则文件不存在,将使用默认规则', { projectRulesPath });
|
|
102
|
-
return getDefaultProjectRules(projectName);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
catch (error) {
|
|
106
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
107
|
-
logger_1.logger.error('获取项目规则失败', { error: errorMsg });
|
|
108
|
-
return getDefaultProjectRules(projectName);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
// 获取默认项目规则
|
|
113
|
-
function getDefaultProjectRules(projectName) {
|
|
114
|
-
return `# ${projectName} - 项目开发规范
|
|
115
|
-
|
|
116
|
-
## 1. 项目概述
|
|
117
|
-
- 项目名称: ${projectName}
|
|
118
|
-
- 技术栈: 通用Web项目
|
|
119
|
-
- 架构模式: 分层架构
|
|
120
|
-
|
|
121
|
-
## 2. 目录结构规范
|
|
122
|
-
\`\`\`
|
|
123
|
-
src/
|
|
124
|
-
├── controllers/ # 控制器层
|
|
125
|
-
├── services/ # 业务逻辑层
|
|
126
|
-
├── repositories/ # 数据访问层
|
|
127
|
-
├── models/ # 数据模型
|
|
128
|
-
├── middleware/ # 中间件
|
|
129
|
-
├── utils/ # 工具函数
|
|
130
|
-
└── config/ # 配置文件
|
|
131
|
-
\`\`\`
|
|
132
|
-
|
|
133
|
-
## 3. 代码规范
|
|
134
|
-
- 命名规范: 使用camelCase命名变量和函数
|
|
135
|
-
- 代码风格: 使用4空格缩进
|
|
136
|
-
- 注释要求: 函数需添加JSDoc注释
|
|
137
|
-
- 导入规则: 按模块分类导入
|
|
138
|
-
|
|
139
|
-
## 4. 错误处理规范
|
|
140
|
-
- 使用try-catch处理异常
|
|
141
|
-
- 提供有意义的错误信息
|
|
142
|
-
- 记录错误日志
|
|
143
|
-
`;
|
|
144
|
-
}
|
|
145
|
-
// 创建任务执行清单
|
|
146
|
-
function createTaskExecutionPlan(bugDescription, projectAnalysis, projectRules) {
|
|
147
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
-
try {
|
|
149
|
-
const prompt = `你是一位专业的软件Bug修复专家。请基于以下信息创建详细的Bug修复任务执行清单:
|
|
150
|
-
|
|
151
|
-
## Bug描述
|
|
152
|
-
${bugDescription}
|
|
153
|
-
|
|
154
|
-
## 项目分析
|
|
155
|
-
${(projectAnalysis === null || projectAnalysis === void 0 ? void 0 : projectAnalysis.prompt) || '无项目分析信息'}
|
|
156
|
-
|
|
157
|
-
## 项目规则
|
|
158
|
-
${projectRules}
|
|
159
|
-
|
|
160
|
-
## 任务要求
|
|
161
|
-
请按照以下结构创建任务执行清单:
|
|
162
|
-
1. 描述信息与工程内容匹配的对应关系
|
|
163
|
-
- 分析Bug描述信息
|
|
164
|
-
- 解析项目规则文件
|
|
165
|
-
- 建立描述信息与项目文件/模块的映射关系
|
|
166
|
-
- 确定受影响的代码范围
|
|
167
|
-
2. 完成本次描述任务的方法和交付结果
|
|
168
|
-
- 制定修复方案和实施步骤
|
|
169
|
-
- 生成修复代码或修改建议
|
|
170
|
-
- 提供验证方法和测试用例
|
|
171
|
-
- 输出修复报告和相关文档
|
|
172
|
-
|
|
173
|
-
请输出JSON格式的结果,包含以上两个主要部分的详细内容。`;
|
|
174
|
-
const result = yield openai_1.openAIService.generateText({
|
|
175
|
-
prompt,
|
|
176
|
-
system_prompt: "你是一位专业的软件Bug修复专家,善于分析Bug并制定修复方案。",
|
|
177
|
-
temperature: 0.3
|
|
178
|
-
});
|
|
179
|
-
try {
|
|
180
|
-
// 尝试解析JSON结果
|
|
181
|
-
const jsonMatch = result.match(/\{[\s\S]*\}/);
|
|
182
|
-
if (jsonMatch) {
|
|
183
|
-
return JSON.parse(jsonMatch[0]);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
catch (parseError) {
|
|
187
|
-
logger_1.logger.warn('任务执行清单JSON解析失败,使用默认结构', { parseError });
|
|
188
|
-
}
|
|
189
|
-
// 返回默认结构
|
|
190
|
-
return {
|
|
191
|
-
description_mapping: {
|
|
192
|
-
analysis: "基于Bug描述进行分析",
|
|
193
|
-
project_rules_analysis: "解析项目规则文件",
|
|
194
|
-
mapping_relationship: "建立映射关系",
|
|
195
|
-
affected_scope: "确定受影响代码范围"
|
|
196
|
-
},
|
|
197
|
-
task_completion: {
|
|
198
|
-
fix_plan: "制定修复方案",
|
|
199
|
-
implementation_steps: "实施步骤",
|
|
200
|
-
code_changes: "代码修改建议",
|
|
201
|
-
validation_methods: "验证方法",
|
|
202
|
-
test_cases: "测试用例",
|
|
203
|
-
deliverables: "交付文档"
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
catch (error) {
|
|
208
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
209
|
-
logger_1.logger.error('创建任务执行清单失败', { error: errorMsg });
|
|
210
|
-
// 返回默认结构
|
|
211
|
-
return {
|
|
212
|
-
description_mapping: {
|
|
213
|
-
analysis: "基于Bug描述进行分析",
|
|
214
|
-
project_rules_analysis: "解析项目规则文件",
|
|
215
|
-
mapping_relationship: "建立映射关系",
|
|
216
|
-
affected_scope: "确定受影响代码范围"
|
|
217
|
-
},
|
|
218
|
-
task_completion: {
|
|
219
|
-
fix_plan: "制定修复方案",
|
|
220
|
-
implementation_steps: "实施步骤",
|
|
221
|
-
code_changes: "代码修改建议",
|
|
222
|
-
validation_methods: "验证方法",
|
|
223
|
-
test_cases: "测试用例",
|
|
224
|
-
deliverables: "交付文档"
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
// 执行Bug修复任务
|
|
231
|
-
function executeBugFixTask(bugDescription, projectRules, taskPlan) {
|
|
232
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
-
try {
|
|
234
|
-
const prompt = `你是一位专业的软件Bug修复专家。请基于以下信息执行Bug修复任务:
|
|
235
|
-
|
|
236
|
-
## Bug描述
|
|
237
|
-
${bugDescription}
|
|
238
|
-
|
|
239
|
-
## 项目规则
|
|
240
|
-
${projectRules}
|
|
241
|
-
|
|
242
|
-
## 任务执行计划
|
|
243
|
-
${JSON.stringify(taskPlan, null, 2)}
|
|
244
|
-
|
|
245
|
-
## 任务要求
|
|
246
|
-
请完成以下任务:
|
|
247
|
-
1. 分析Bug的根本原因
|
|
248
|
-
2. 制定详细的修复方案
|
|
249
|
-
3. 提供具体的代码修改建议
|
|
250
|
-
4. 编写验证方法和测试用例
|
|
251
|
-
5. 生成修复报告
|
|
252
|
-
|
|
253
|
-
请输出详细的修复方案,包括代码示例和实施步骤。`;
|
|
254
|
-
const result = yield openai_1.openAIService.generateText({
|
|
255
|
-
prompt,
|
|
256
|
-
system_prompt: "你是一位专业的软件Bug修复专家,善于分析Bug并提供详细的修复方案。",
|
|
257
|
-
temperature: 0.3,
|
|
258
|
-
max_tokens: 4000
|
|
259
|
-
});
|
|
260
|
-
return {
|
|
261
|
-
bug_analysis: "已完成Bug分析",
|
|
262
|
-
fix_solution: result,
|
|
263
|
-
implementation_guide: "请按照上述方案实施修复",
|
|
264
|
-
validation_method: "通过单元测试和集成测试验证修复效果"
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
catch (error) {
|
|
268
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
269
|
-
logger_1.logger.error('执行Bug修复任务失败', { error: errorMsg });
|
|
270
|
-
return {
|
|
271
|
-
bug_analysis: "Bug分析失败",
|
|
272
|
-
fix_solution: `修复方案生成失败: ${errorMsg}`,
|
|
273
|
-
implementation_guide: "请手动分析并修复Bug",
|
|
274
|
-
validation_method: "手动验证修复效果"
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
// 保存Bug修复结果
|
|
280
|
-
function saveBugFixResult(fixResult, projectName, outputFormat) {
|
|
281
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
282
|
-
try {
|
|
283
|
-
const storageDir = (0, config_1.getStorageDir)();
|
|
284
|
-
const bugFixDir = path_1.default.join(storageDir, 'bug-fix-results');
|
|
285
|
-
yield promises_1.default.mkdir(bugFixDir, { recursive: true });
|
|
286
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
287
|
-
const fileName = `bug-fix-${projectName}-${timestamp}.${outputFormat}`;
|
|
288
|
-
const outputPath = path_1.default.join(bugFixDir, fileName);
|
|
289
|
-
if (outputFormat === 'json') {
|
|
290
|
-
yield promises_1.default.writeFile(outputPath, JSON.stringify(fixResult, null, 2), 'utf-8');
|
|
291
|
-
}
|
|
292
|
-
else {
|
|
293
|
-
const markdownContent = `# Bug修复报告
|
|
294
|
-
|
|
295
|
-
## 项目名称
|
|
296
|
-
${projectName}
|
|
297
|
-
|
|
298
|
-
## 修复结果
|
|
299
|
-
${fixResult.fix_solution}
|
|
300
|
-
|
|
301
|
-
## 实施指南
|
|
302
|
-
${fixResult.implementation_guide}
|
|
303
|
-
|
|
304
|
-
## 验证方法
|
|
305
|
-
${fixResult.validation_method}
|
|
306
|
-
|
|
307
|
-
## 生成时间
|
|
308
|
-
${new Date().toISOString()}
|
|
309
|
-
`;
|
|
310
|
-
yield promises_1.default.writeFile(outputPath, markdownContent, 'utf-8');
|
|
311
|
-
}
|
|
312
|
-
return outputPath;
|
|
313
|
-
}
|
|
314
|
-
catch (error) {
|
|
315
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
316
|
-
logger_1.logger.error('保存Bug修复结果失败', { error: errorMsg });
|
|
317
|
-
throw new Error(`保存Bug修复结果失败: ${errorMsg}`);
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
}
|
|
@@ -1,123 +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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.changeSummarizer = exports.ChangeSummarizerParams = void 0;
|
|
16
|
-
const fs_1 = __importDefault(require("fs"));
|
|
17
|
-
const path_1 = __importDefault(require("path"));
|
|
18
|
-
const zod_1 = require("zod");
|
|
19
|
-
const logger_1 = require("../../utils/logger");
|
|
20
|
-
const config_1 = require("../../utils/config");
|
|
21
|
-
const change_analysis_1 = require("./prompt/change-analysis");
|
|
22
|
-
exports.ChangeSummarizerParams = zod_1.z.object({
|
|
23
|
-
baseBranch: zod_1.z.string().default('main').describe('基准分支名称,用于对比变更'),
|
|
24
|
-
requirementFile: zod_1.z.string().optional().describe('需求文档文件路径(可选)'),
|
|
25
|
-
includeUncommitted: zod_1.z.boolean().default(true).describe('是否包含未提交的变更'),
|
|
26
|
-
outputFormat: zod_1.z.enum(['markdown', 'json']).default('markdown').describe('输出格式')
|
|
27
|
-
});
|
|
28
|
-
exports.changeSummarizer = {
|
|
29
|
-
name: '代码变更分析智能体',
|
|
30
|
-
description: '分析代码并与需求进行对比,确保实现完整性',
|
|
31
|
-
parameters: exports.ChangeSummarizerParams,
|
|
32
|
-
execute: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
-
try {
|
|
34
|
-
logger_1.logger.info({
|
|
35
|
-
module: 'change-summarizer',
|
|
36
|
-
message: 'Starting code analysis',
|
|
37
|
-
args
|
|
38
|
-
});
|
|
39
|
-
// 读取需求文档(如果提供)
|
|
40
|
-
let requirementContent = '';
|
|
41
|
-
if (args.requirementFile && fs_1.default.existsSync(args.requirementFile)) {
|
|
42
|
-
requirementContent = fs_1.default.readFileSync(args.requirementFile, 'utf-8');
|
|
43
|
-
}
|
|
44
|
-
// 构建分析提示词
|
|
45
|
-
const analysisPrompt = buildAnalysisPrompt(requirementContent);
|
|
46
|
-
// 保存分析结果
|
|
47
|
-
const outputPath = yield saveAnalysisResult(analysisPrompt, args.outputFormat);
|
|
48
|
-
logger_1.logger.info({
|
|
49
|
-
module: 'change-summarizer',
|
|
50
|
-
message: 'Code analysis completed',
|
|
51
|
-
outputPath
|
|
52
|
-
});
|
|
53
|
-
return `# 代码分析完成
|
|
54
|
-
|
|
55
|
-
分析结果已保存到: ${outputPath}
|
|
56
|
-
|
|
57
|
-
## 分析信息
|
|
58
|
-
- 需求文档: ${requirementContent ? '已提供' : '未提供'}
|
|
59
|
-
|
|
60
|
-
请查看生成的分析文件获取详细信息。`;
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
logger_1.logger.error({
|
|
64
|
-
module: 'change-summarizer',
|
|
65
|
-
message: 'Code analysis failed',
|
|
66
|
-
error: error instanceof Error ? error.message : String(error)
|
|
67
|
-
});
|
|
68
|
-
throw new Error(`代码分析失败: ${error instanceof Error ? error.message : String(error)}`);
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
};
|
|
72
|
-
function buildAnalysisPrompt(requirementContent) {
|
|
73
|
-
const changesSection = `
|
|
74
|
-
## 代码上下文分析
|
|
75
|
-
|
|
76
|
-
请基于以下内容进行分析:
|
|
77
|
-
- 当前代码库的整体结构
|
|
78
|
-
- 主要功能模块的实现
|
|
79
|
-
- 关键业务逻辑
|
|
80
|
-
- 接口定义与实现
|
|
81
|
-
- 前端组件与页面
|
|
82
|
-
`;
|
|
83
|
-
const requirementSection = requirementContent ? `
|
|
84
|
-
## 需求文档内容
|
|
85
|
-
${requirementContent}
|
|
86
|
-
` : `
|
|
87
|
-
## 需求文档
|
|
88
|
-
未提供需求文档,请基于代码变更进行分析。
|
|
89
|
-
`;
|
|
90
|
-
return `
|
|
91
|
-
${change_analysis_1.changeAnalysisPrompt}
|
|
92
|
-
|
|
93
|
-
${changesSection}
|
|
94
|
-
|
|
95
|
-
${requirementSection}
|
|
96
|
-
|
|
97
|
-
请基于以上信息进行详细分析。
|
|
98
|
-
`;
|
|
99
|
-
}
|
|
100
|
-
function saveAnalysisResult(prompt, format) {
|
|
101
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
const storageDir = (0, config_1.getStorageDir)();
|
|
103
|
-
const outputDir = path_1.default.join(storageDir, 'change-analysis');
|
|
104
|
-
if (!fs_1.default.existsSync(outputDir)) {
|
|
105
|
-
fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
106
|
-
}
|
|
107
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
108
|
-
const filename = `change-analysis-${timestamp}.${format === 'json' ? 'json' : 'md'}`;
|
|
109
|
-
const outputPath = path_1.default.join(outputDir, filename);
|
|
110
|
-
if (format === 'json') {
|
|
111
|
-
const jsonData = {
|
|
112
|
-
timestamp: new Date().toISOString(),
|
|
113
|
-
prompt,
|
|
114
|
-
type: 'change-analysis'
|
|
115
|
-
};
|
|
116
|
-
fs_1.default.writeFileSync(outputPath, JSON.stringify(jsonData, null, 2), 'utf-8');
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
fs_1.default.writeFileSync(outputPath, prompt, 'utf-8');
|
|
120
|
-
}
|
|
121
|
-
return outputPath;
|
|
122
|
-
});
|
|
123
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.changeAnalysisPrompt = void 0;
|
|
4
|
-
exports.changeAnalysisPrompt = `请分析当前代码库,并与需求进行对比,确保实现的完整性。
|
|
5
|
-
|
|
6
|
-
请按以下步骤进行分析:
|
|
7
|
-
|
|
8
|
-
## 1. 代码库分析
|
|
9
|
-
分析当前代码库,总结:
|
|
10
|
-
- 主要功能模块及其实现
|
|
11
|
-
- 关键业务逻辑流程
|
|
12
|
-
- 重要数据结构
|
|
13
|
-
- 核心算法实现
|
|
14
|
-
|
|
15
|
-
## 2. 接口与需求对应关系表
|
|
16
|
-
根据代码变更,生成接口与需求对应关系表:
|
|
17
|
-
|
|
18
|
-
| 需求功能 | 实现接口 | 请求方式 | URL | 变更状态 |
|
|
19
|
-
|---------|---------|---------|-----|----------|
|
|
20
|
-
| [需求功能描述] | [Controller.method] | [GET/POST/PUT/DELETE] | [/api/path] | [新增/修改/删除] |
|
|
21
|
-
|
|
22
|
-
## 3. 核心逻辑方法表
|
|
23
|
-
分析核心业务逻辑方法:
|
|
24
|
-
|
|
25
|
-
| 方法名称 | 所属类 | 功能说明 | 变更状态 |
|
|
26
|
-
|---------|-------|---------|----------|
|
|
27
|
-
| [methodName] | [ClassName] | [功能描述] | [新增/修改/删除] |
|
|
28
|
-
|
|
29
|
-
## 4. 前端页面与接口对应关系表
|
|
30
|
-
分析前端页面变更:
|
|
31
|
-
|
|
32
|
-
| 页面名称 | 调用接口 | 组件名称 | 路由路径 | 变更状态 |
|
|
33
|
-
|---------|---------|---------|---------|----------|
|
|
34
|
-
| [页面名称] | [Controller.method] | [ComponentName] | [/path] | [新增/修改/删除] |
|
|
35
|
-
|
|
36
|
-
## 5. 前端核心组件表
|
|
37
|
-
分析前端组件变更:
|
|
38
|
-
|
|
39
|
-
| 组件名称 | 所属页面 | 功能说明 | 变更状态 |
|
|
40
|
-
|---------|---------|---------|----------|
|
|
41
|
-
| [ComponentName] | [PageName] | [功能描述] | [新增/修改/删除] |
|
|
42
|
-
|
|
43
|
-
## 6. 需求完整性检查
|
|
44
|
-
对比原始需求,检查:
|
|
45
|
-
- ✅ 已完成的功能
|
|
46
|
-
- ⚠️ 部分完成的功能
|
|
47
|
-
- ❌ 未实现的功能
|
|
48
|
-
- 🔄 需要进一步完善的功能
|
|
49
|
-
|
|
50
|
-
## 7. 建议与总结
|
|
51
|
-
- 实现质量评估
|
|
52
|
-
- 潜在问题识别
|
|
53
|
-
- 后续开发建议
|
|
54
|
-
- 测试建议
|
|
55
|
-
|
|
56
|
-
请确保所有表格上下对齐,内容详实准确。`;
|