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.
Files changed (51) hide show
  1. package/package.json +1 -1
  2. package/dist/db/file-storage.js +0 -638
  3. package/dist/index.js +0 -26
  4. package/dist/server/index.js +0 -88
  5. package/dist/services/bug-fix-agent/index.js +0 -320
  6. package/dist/services/change-summarizer/index.js +0 -123
  7. package/dist/services/change-summarizer/prompt/change-analysis.js +0 -56
  8. package/dist/services/code-generator/index.js +0 -403
  9. package/dist/services/code-generator/stages/execution-stage.js +0 -549
  10. package/dist/services/code-generator/stages/ideation-stage.js +0 -267
  11. package/dist/services/code-generator/stages/optimization-stage.js +0 -334
  12. package/dist/services/code-generator/stages/planning-stage.js +0 -295
  13. package/dist/services/code-generator/stages/research-stage.js +0 -283
  14. package/dist/services/code-generator/stages/review-stage.js +0 -270
  15. package/dist/services/code-generator/types.js +0 -37
  16. package/dist/services/code-generator/utils/instruction-executor.js +0 -207
  17. package/dist/services/code-generator/workflow-manager.js +0 -252
  18. package/dist/services/image-analysis/analyzer.js +0 -530
  19. package/dist/services/image-analysis/index.js +0 -406
  20. package/dist/services/image-analysis/types.js +0 -46
  21. package/dist/services/image-converter/converter.js +0 -310
  22. package/dist/services/image-converter/index.js +0 -262
  23. package/dist/services/image-converter/types.js +0 -31
  24. package/dist/services/integrated-generator/index.js +0 -1297
  25. package/dist/services/pdf2md/index.js +0 -180
  26. package/dist/services/project-template/index.js +0 -83
  27. package/dist/services/project-template/prompt/project-rules.js +0 -98
  28. package/dist/services/requirement-analyzer/chunk-reader.js +0 -218
  29. package/dist/services/requirement-analyzer/core/document-generator.js +0 -254
  30. package/dist/services/requirement-analyzer/core/intelligent-analyzer.js +0 -169
  31. package/dist/services/requirement-analyzer/core/project-analyzer.js +0 -199
  32. package/dist/services/requirement-analyzer/core/requirement-analyzer-service.js +0 -191
  33. package/dist/services/requirement-analyzer/core/template-selector.js +0 -124
  34. package/dist/services/requirement-analyzer/core/types.js +0 -23
  35. package/dist/services/requirement-analyzer/index.js +0 -177
  36. package/dist/services/requirement-analyzer/prompt/api-template.js +0 -302
  37. package/dist/services/requirement-analyzer/prompt/app-template.js +0 -455
  38. package/dist/services/requirement-analyzer/prompt/intelligent-requirement-analysis.js +0 -92
  39. package/dist/services/requirement-analyzer/prompt/pc-page-template.js +0 -582
  40. package/dist/services/requirement-analyzer/prompt/requirement-analysis.js +0 -664
  41. package/dist/services/requirement-analyzer/prompt/sdk-template.js +0 -582
  42. package/dist/services/requirement-analyzer/utils/file-reader.js +0 -169
  43. package/dist/services/world2md/index.js +0 -157
  44. package/dist/types/index.js +0 -2
  45. package/dist/utils/common.js +0 -72
  46. package/dist/utils/config.js +0 -163
  47. package/dist/utils/context-manager.js +0 -114
  48. package/dist/utils/dify.js +0 -243
  49. package/dist/utils/logger.js +0 -129
  50. package/dist/utils/openai.js +0 -225
  51. package/dist/utils/pack.js +0 -75
@@ -1,254 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- var __importDefault = (this && this.__importDefault) || function (mod) {
45
- return (mod && mod.__esModule) ? mod : { "default": mod };
46
- };
47
- Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.DocumentGenerator = void 0;
49
- const fs = __importStar(require("fs/promises"));
50
- const path_1 = __importDefault(require("path"));
51
- const openai_1 = require("../../../utils/openai");
52
- const logger_1 = require("../../../utils/logger");
53
- const config_1 = require("../../../utils/config");
54
- const common_1 = require("../../../utils/common");
55
- const types_1 = require("./types");
56
- const template_selector_1 = require("./template-selector");
57
- /**
58
- * 文档生成器
59
- * 职责:生成统一的技术需求文档
60
- */
61
- class DocumentGenerator {
62
- constructor() {
63
- this.templateSelector = new template_selector_1.TemplateSelector();
64
- }
65
- /**
66
- * 生成统一的技术需求文档
67
- */
68
- generateUnifiedDocument(analysis, projectInfo, featureName, sourceInfo, customPrompt) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- try {
71
- logger_1.logger.info('开始生成统一技术文档', {
72
- featureName,
73
- requirementType: analysis.requirementType,
74
- featureCount: analysis.requirements.length
75
- });
76
- // 准备输出目录和文件路径
77
- const { outputPath, requirementDir } = yield this.prepareOutputPath(featureName);
78
- // 构建统一的文档内容
79
- const unifiedContent = this.buildUnifiedContent(analysis, projectInfo, featureName, sourceInfo);
80
- // 选择合适的模板并生成文档
81
- const document = yield this.generateDocument(unifiedContent, featureName, analysis.requirementType, projectInfo, customPrompt);
82
- // 保存文档
83
- yield fs.writeFile(outputPath, document, 'utf8');
84
- // 构建结果
85
- const result = this.buildAnalysisResult(analysis, projectInfo, outputPath, sourceInfo);
86
- logger_1.logger.info('统一技术文档生成完成', {
87
- outputPath,
88
- documentLength: document.length
89
- });
90
- return result;
91
- }
92
- catch (error) {
93
- if (error instanceof types_1.RequirementAnalysisError) {
94
- throw error;
95
- }
96
- logger_1.logger.error('文档生成失败', { error, featureName });
97
- throw new types_1.RequirementAnalysisError('技术文档生成过程中发生错误,请检查需求内容和项目配置', types_1.ErrorCodes.DOCUMENT_GENERATION_FAILED, { featureName, originalError: error });
98
- }
99
- });
100
- }
101
- /**
102
- * 准备输出路径
103
- */
104
- prepareOutputPath(featureName) {
105
- return __awaiter(this, void 0, void 0, function* () {
106
- const requirementDir = path_1.default.join((0, config_1.getStorageDir)(), 'requirements', (0, common_1.sanitizeFileName)(featureName));
107
- yield fs.mkdir(requirementDir, { recursive: true });
108
- const sanitizedFeatureName = (0, common_1.sanitizeFileName)(featureName);
109
- const outputFileName = `${sanitizedFeatureName}.md`;
110
- const outputPath = path_1.default.join(requirementDir, outputFileName);
111
- return { outputPath, requirementDir };
112
- });
113
- }
114
- /**
115
- * 构建统一的文档内容
116
- */
117
- buildUnifiedContent(analysis, projectInfo, featureName, sourceInfo) {
118
- var _a, _b, _c;
119
- // 获取功能点列表
120
- const featuresToProcess = ((_a = analysis.featureDependencies) === null || _a === void 0 ? void 0 : _a.mergedFeatures) ||
121
- analysis.requirements;
122
- // 合并所有功能点内容
123
- const combinedFeatureContent = featuresToProcess.map((feature, index) => {
124
- const featureTitle = 'title' in feature ? feature.title : feature.featureName;
125
- const featureContent = 'fullContent' in feature ? feature.fullContent : feature.description;
126
- return `## 功能点${index + 1}:${featureTitle}\n\n${featureContent}`;
127
- }).join('\n\n');
128
- return `# ${featureName} - 统一需求分析
129
-
130
- ## 项目基本信息
131
- - **项目类型**: ${(projectInfo === null || projectInfo === void 0 ? void 0 : projectInfo.projectType) || '通用项目'}
132
- - **主要技术栈**: ${((_b = projectInfo === null || projectInfo === void 0 ? void 0 : projectInfo.techStack) === null || _b === void 0 ? void 0 : _b.join(', ')) || '待确定'}
133
- - **开发框架**: ${((_c = projectInfo === null || projectInfo === void 0 ? void 0 : projectInfo.frameworks) === null || _c === void 0 ? void 0 : _c.join(', ')) || '待确定'}
134
- - **编程语言**: ${(projectInfo === null || projectInfo === void 0 ? void 0 : projectInfo.language) || '待确定'}
135
-
136
- ## 需求类型分析
137
- - **识别类型**: ${analysis.requirementType}
138
- - **推荐模板**: ${analysis.templateRecommendation.primaryTemplate}
139
- - **功能点数量**: ${featuresToProcess.length}个
140
- - **置信度**: ${analysis.confidence || 'medium'}
141
-
142
- ## 功能点详细描述
143
-
144
- ${combinedFeatureContent}
145
-
146
- ## 数据来源
147
- - **输入来源**: ${sourceInfo}
148
- - **分析时间**: ${new Date().toISOString()}
149
- `;
150
- }
151
- /**
152
- * 生成技术文档
153
- */
154
- generateDocument(content, title, requirementType, projectInfo, customPrompt) {
155
- return __awaiter(this, void 0, void 0, function* () {
156
- try {
157
- // 选择合适的模板
158
- const template = this.templateSelector.selectTemplate(requirementType);
159
- this.templateSelector.validateTemplate(template, requirementType);
160
- // 构建完整的prompt
161
- const fullPrompt = this.buildDocumentPrompt(template, content, title, projectInfo, customPrompt);
162
- // 调用AI服务生成文档
163
- const document = yield openai_1.openAIService.generateText({
164
- prompt: fullPrompt,
165
- system_prompt: "你是一位专业的技术文档编写专家,请生成完整、详细的技术需求文档。"
166
- });
167
- this.validateGeneratedDocument(document, title);
168
- return document;
169
- }
170
- catch (error) {
171
- logger_1.logger.error('技术文档生成失败', { error, requirementType });
172
- throw new types_1.RequirementAnalysisError(`无法生成${requirementType}类型的技术文档,请检查需求描述是否完整`, types_1.ErrorCodes.DOCUMENT_GENERATION_FAILED, { requirementType, originalError: error });
173
- }
174
- });
175
- }
176
- /**
177
- * 构建文档生成prompt
178
- */
179
- buildDocumentPrompt(template, content, title, projectInfo, customPrompt) {
180
- let prompt = template
181
- .replace(/\{featureName\}/g, title)
182
- .replace(/\{inputContent\}/g, content)
183
- .replace(/\{currentTime\}/g, new Date().toISOString())
184
- .replace(/\{businessDomain\}/g, (projectInfo === null || projectInfo === void 0 ? void 0 : projectInfo.projectType) || '通用业务')
185
- .replace(/\{generateSequenceDiagram\}/g, 'true');
186
- if (customPrompt) {
187
- prompt += `\n\n## 自定义要求\n${customPrompt}`;
188
- }
189
- return prompt;
190
- }
191
- /**
192
- * 验证生成的文档
193
- */
194
- validateGeneratedDocument(document, title) {
195
- if (!document || document.trim().length < 100) {
196
- throw new types_1.RequirementAnalysisError('生成的技术文档内容过短,可能存在问题', types_1.ErrorCodes.DOCUMENT_GENERATION_FAILED, { title, documentLength: (document === null || document === void 0 ? void 0 : document.length) || 0 });
197
- }
198
- if (!document.includes(title)) {
199
- logger_1.logger.warn('生成的文档可能与需求标题不匹配', { title });
200
- }
201
- }
202
- /**
203
- * 构建分析结果
204
- */
205
- buildAnalysisResult(analysis, projectInfo, outputPath, sourceInfo) {
206
- var _a;
207
- const featuresToProcess = ((_a = analysis.featureDependencies) === null || _a === void 0 ? void 0 : _a.mergedFeatures) ||
208
- analysis.requirements;
209
- return {
210
- success: true,
211
- message: `
212
- # ✅ 统一技术文档生成完成
213
-
214
- ## 📊 智能分析结果
215
- - **项目类型**: ${(projectInfo === null || projectInfo === void 0 ? void 0 : projectInfo.projectType) || '通用项目'}
216
- - **需求类型**: ${analysis.requirementType}
217
- - **推荐模板**: ${analysis.templateRecommendation.primaryTemplate}
218
- - **总计功能点**: ${featuresToProcess.length} 个
219
- - **输入来源**: ${sourceInfo}
220
- - **分析模式**: 统一技术文档生成
221
- - **生成文档**: 1 个统一技术需求文档
222
-
223
- ## 🎯 功能点清单
224
- ${featuresToProcess.map((f, i) => {
225
- const featureTitle = 'title' in f ? f.title : f.featureName;
226
- const priority = 'priority' in f ? f.priority : 'medium';
227
- const complexity = 'complexity' in f ? f.complexity : f.estimatedComplexity;
228
- const techType = 'technologyType' in f ? f.technologyType : analysis.requirementType;
229
- return `- ${i + 1}. **${featureTitle}** (${priority}优先级, ${complexity}复杂度, ${techType}类型)`;
230
- }).join('\n')}
231
-
232
- ## 📁 生成文件
233
- - \`${path_1.default.resolve(outputPath)}\`
234
-
235
- ## 💡 优化说明
236
- 1. **项目分析**: 自动分析项目基本情况,提取技术栈、框架等信息
237
- 2. **智能识别**: 根据需求内容智能识别为**${analysis.requirementType}**类型
238
- 3. **模板匹配**: 自动选择**${analysis.templateRecommendation.primaryTemplate}**技术模板
239
- 4. **统一文档**: 将多个功能点合并生成一个完整的技术需求文档
240
-
241
- 您可以在上述路径查看统一的技术需求分析文档。
242
- `.trim(),
243
- outputPath,
244
- generatedFiles: [path_1.default.resolve(outputPath)],
245
- analysisInfo: {
246
- requirementType: analysis.requirementType,
247
- recommendedTemplate: analysis.templateRecommendation.primaryTemplate,
248
- featureCount: featuresToProcess.length,
249
- projectType: projectInfo === null || projectInfo === void 0 ? void 0 : projectInfo.projectType
250
- }
251
- };
252
- }
253
- }
254
- exports.DocumentGenerator = DocumentGenerator;
@@ -1,169 +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.IntelligentAnalyzer = void 0;
13
- const openai_1 = require("../../../utils/openai");
14
- const logger_1 = require("../../../utils/logger");
15
- const types_1 = require("./types");
16
- const intelligent_requirement_analysis_1 = require("../prompt/intelligent-requirement-analysis");
17
- /**
18
- * 智能需求分析器
19
- * 职责:使用AI进行智能需求分析,识别需求类型和功能点
20
- */
21
- class IntelligentAnalyzer {
22
- /**
23
- * 执行智能需求分析
24
- */
25
- analyzeRequirements(inputContent, projectInfo, customPrompt) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- var _a;
28
- try {
29
- logger_1.logger.info('开始智能需求分析', {
30
- contentLength: inputContent.length,
31
- hasProjectInfo: !!projectInfo,
32
- projectType: projectInfo === null || projectInfo === void 0 ? void 0 : projectInfo.projectType
33
- });
34
- // 构建增强的分析prompt
35
- const enhancedPrompt = this.buildEnhancedPrompt(inputContent, projectInfo);
36
- // 调用AI服务进行分析
37
- const result = yield this.callAIService(enhancedPrompt);
38
- // 解析和验证结果
39
- const analysis = this.parseAnalysisResult(result);
40
- this.validateAnalysisResult(analysis);
41
- logger_1.logger.info('智能需求分析成功', {
42
- analysisType: analysis.analysisType,
43
- requirementType: analysis.requirementType,
44
- requirementCount: analysis.requirements.length,
45
- primaryTemplate: (_a = analysis.templateRecommendation) === null || _a === void 0 ? void 0 : _a.primaryTemplate
46
- });
47
- return analysis;
48
- }
49
- catch (error) {
50
- if (error instanceof types_1.RequirementAnalysisError) {
51
- throw error;
52
- }
53
- logger_1.logger.error('智能需求分析失败', { error });
54
- throw new types_1.RequirementAnalysisError('需求分析过程中发生错误,请检查输入内容是否完整', types_1.ErrorCodes.REQUIREMENT_PARSING_FAILED, { inputContent: inputContent.substring(0, 200) + '...' });
55
- }
56
- });
57
- }
58
- /**
59
- * 构建包含项目信息的增强prompt
60
- */
61
- buildEnhancedPrompt(inputContent, projectInfo) {
62
- let enhancedPrompt = intelligent_requirement_analysis_1.intelligentRequirementAnalysisPrompt.replace('{inputContent}', inputContent);
63
- if (projectInfo && projectInfo.projectType !== '通用项目') {
64
- const projectContext = this.buildProjectContext(projectInfo);
65
- enhancedPrompt = enhancedPrompt.replace('## 输入内容', projectContext + '## 输入内容');
66
- }
67
- return enhancedPrompt;
68
- }
69
- /**
70
- * 构建项目上下文信息
71
- */
72
- buildProjectContext(projectInfo) {
73
- var _a, _b, _c;
74
- return `
75
- ## 项目基本信息
76
- - **项目类型**: ${projectInfo.projectType}
77
- - **主要技术栈**: ${((_a = projectInfo.techStack) === null || _a === void 0 ? void 0 : _a.join(', ')) || '待确定'}
78
- - **开发框架**: ${((_b = projectInfo.frameworks) === null || _b === void 0 ? void 0 : _b.join(', ')) || '待确定'}
79
- - **编程语言**: ${projectInfo.language || '待确定'}
80
- - **主要依赖**: ${((_c = projectInfo.dependencies) === null || _c === void 0 ? void 0 : _c.slice(0, 5).join(', ')) || '待确定'}
81
-
82
- 请结合以上项目信息进行需求分析,确保生成的技术文档与项目技术栈匹配。
83
-
84
- `;
85
- }
86
- /**
87
- * 调用AI服务
88
- */
89
- callAIService(prompt) {
90
- return __awaiter(this, void 0, void 0, function* () {
91
- try {
92
- return yield openai_1.openAIService.generateText({
93
- prompt,
94
- system_prompt: "你是一个专业的需求分析师,请严格按照JSON格式输出分析结果。"
95
- });
96
- }
97
- catch (error) {
98
- logger_1.logger.error('AI服务调用失败', { error });
99
- throw new types_1.RequirementAnalysisError('AI分析服务暂时不可用,请稍后重试', types_1.ErrorCodes.REQUIREMENT_PARSING_FAILED, { originalError: error });
100
- }
101
- });
102
- }
103
- /**
104
- * 解析AI分析结果
105
- */
106
- parseAnalysisResult(result) {
107
- try {
108
- const jsonMatch = result.match(/\{[\s\S]*\}/);
109
- if (!jsonMatch) {
110
- throw new Error('未找到有效的JSON格式结果');
111
- }
112
- const analysis = JSON.parse(jsonMatch[0]);
113
- // 如果是多功能点分析,构造依赖分析结果
114
- if (analysis.analysisType === 'multi_general' || analysis.analysisType === 'multi_specific_features') {
115
- analysis.featureDependencies = this.buildFeatureDependencies(analysis);
116
- }
117
- return analysis;
118
- }
119
- catch (parseError) {
120
- logger_1.logger.error('解析AI分析结果失败', { parseError, result: result.substring(0, 500) });
121
- throw new types_1.RequirementAnalysisError('分析结果格式异常,请重新尝试或简化需求描述', types_1.ErrorCodes.REQUIREMENT_PARSING_FAILED, { parseError });
122
- }
123
- }
124
- /**
125
- * 构建功能依赖关系
126
- */
127
- buildFeatureDependencies(analysis) {
128
- var _a;
129
- return {
130
- requirementType: analysis.requirementType,
131
- primaryTemplate: ((_a = analysis.templateRecommendation) === null || _a === void 0 ? void 0 : _a.primaryTemplate) || 'api',
132
- mergedFeatures: analysis.requirements.map((req) => ({
133
- featureName: req.title,
134
- description: req.fullContent,
135
- priority: req.priority,
136
- estimatedComplexity: req.complexity,
137
- type: '核心功能点',
138
- businessValue: `${req.title}的业务价值`,
139
- technologyType: req.type,
140
- subFeatures: []
141
- })),
142
- dependencies: []
143
- };
144
- }
145
- /**
146
- * 验证分析结果
147
- */
148
- validateAnalysisResult(analysis) {
149
- var _a;
150
- // 验证必要字段
151
- if (!analysis.analysisType) {
152
- throw new types_1.RequirementAnalysisError('分析结果缺少分析类型信息', types_1.ErrorCodes.REQUIREMENT_PARSING_FAILED);
153
- }
154
- if (!analysis.requirements || analysis.requirements.length === 0) {
155
- throw new types_1.RequirementAnalysisError('未能识别出有效的需求功能点,请检查需求描述是否清晰', types_1.ErrorCodes.REQUIREMENT_PARSING_FAILED);
156
- }
157
- if (!((_a = analysis.templateRecommendation) === null || _a === void 0 ? void 0 : _a.primaryTemplate)) {
158
- throw new types_1.RequirementAnalysisError('无法确定合适的技术模板,请明确需求的技术类型', types_1.ErrorCodes.TEMPLATE_SELECTION_FAILED);
159
- }
160
- // 验证需求类型的合理性
161
- const validTypes = ['接口', 'PC页面', 'APP', 'SDK集成', '混合类型'];
162
- if (analysis.requirementType && !validTypes.includes(analysis.requirementType)) {
163
- logger_1.logger.warn('检测到非标准需求类型', {
164
- requirementType: analysis.requirementType
165
- });
166
- }
167
- }
168
- }
169
- exports.IntelligentAnalyzer = IntelligentAnalyzer;
@@ -1,199 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.ProjectAnalyzer = void 0;
46
- exports.extractProjectInfo = extractProjectInfo;
47
- const pack_1 = require("../../../utils/pack");
48
- const logger_1 = require("../../../utils/logger");
49
- const types_1 = require("./types");
50
- const fs = __importStar(require("fs/promises"));
51
- /**
52
- * 项目分析服务
53
- * 职责:分析项目基本情况,提取技术栈信息
54
- */
55
- class ProjectAnalyzer {
56
- /**
57
- * 分析项目基本情况
58
- */
59
- analyzeProject() {
60
- return __awaiter(this, void 0, void 0, function* () {
61
- try {
62
- logger_1.logger.info('开始分析项目基本情况');
63
- const projectAnalysisPath = yield (0, pack_1.packProject)();
64
- logger_1.logger.info('项目分析完成', { analysisPath: projectAnalysisPath });
65
- const projectAnalysisContent = yield fs.readFile(projectAnalysisPath, 'utf8');
66
- const projectInfo = this.extractProjectInfo(projectAnalysisContent);
67
- logger_1.logger.info('项目信息提取完成', { projectInfo });
68
- return projectInfo;
69
- }
70
- catch (error) {
71
- logger_1.logger.warn('项目分析失败,使用默认配置', { error });
72
- // 提供默认的项目信息而不是抛出异常
73
- return this.getDefaultProjectInfo();
74
- }
75
- });
76
- }
77
- /**
78
- * 从项目分析内容中提取关键信息
79
- */
80
- extractProjectInfo(projectAnalysis) {
81
- const projectInfo = {
82
- techStack: [],
83
- frameworks: [],
84
- language: '',
85
- projectType: '',
86
- dependencies: []
87
- };
88
- // 提取技术栈信息
89
- const techStackKeywords = [
90
- 'React', 'Vue', 'Angular', 'Svelte',
91
- 'Node.js', 'Express', 'Koa', 'Fastify',
92
- 'Python', 'Django', 'Flask',
93
- 'Java', 'Spring', 'Spring Boot',
94
- 'TypeScript', 'JavaScript',
95
- 'PostgreSQL', 'MySQL', 'MongoDB', 'Redis',
96
- 'Docker', 'Kubernetes'
97
- ];
98
- // 提取框架信息
99
- const frameworkKeywords = [
100
- 'React', 'Vue', 'Angular', 'Svelte',
101
- 'Express', 'Koa', 'Fastify',
102
- 'Django', 'Flask',
103
- 'Spring', 'Spring Boot',
104
- 'Next.js', 'Nuxt.js'
105
- ];
106
- // 提取编程语言
107
- const languageKeywords = [
108
- 'TypeScript', 'JavaScript', 'Python', 'Java', 'Go', 'Rust', 'C#'
109
- ];
110
- // 在项目分析内容中查找匹配的关键词
111
- for (const keyword of techStackKeywords) {
112
- if (projectAnalysis.includes(keyword)) {
113
- projectInfo.techStack.push(keyword);
114
- }
115
- }
116
- for (const keyword of frameworkKeywords) {
117
- if (projectAnalysis.includes(keyword)) {
118
- projectInfo.frameworks.push(keyword);
119
- }
120
- }
121
- for (const keyword of languageKeywords) {
122
- if (projectAnalysis.includes(keyword)) {
123
- projectInfo.language = keyword;
124
- break;
125
- }
126
- }
127
- // 判断项目类型
128
- projectInfo.projectType = this.determineProjectType(projectAnalysis);
129
- // 提取依赖信息
130
- projectInfo.dependencies = this.extractDependencies(projectAnalysis);
131
- return projectInfo;
132
- }
133
- /**
134
- * 确定项目类型
135
- */
136
- determineProjectType(projectAnalysis) {
137
- if (projectAnalysis.includes('package.json')) {
138
- return 'Node.js项目';
139
- }
140
- else if (projectAnalysis.includes('requirements.txt') || projectAnalysis.includes('pyproject.toml')) {
141
- return 'Python项目';
142
- }
143
- else if (projectAnalysis.includes('pom.xml') || projectAnalysis.includes('build.gradle')) {
144
- return 'Java项目';
145
- }
146
- else if (projectAnalysis.includes('Cargo.toml')) {
147
- return 'Rust项目';
148
- }
149
- else if (projectAnalysis.includes('go.mod')) {
150
- return 'Go项目';
151
- }
152
- else {
153
- return '通用项目';
154
- }
155
- }
156
- /**
157
- * 提取依赖信息
158
- */
159
- extractDependencies(projectAnalysis) {
160
- const dependencyMatch = projectAnalysis.match(/## 依赖.*?```.*?\n([\s\S]*?)\n```/);
161
- if (dependencyMatch && dependencyMatch[1]) {
162
- return dependencyMatch[1]
163
- .split('\n')
164
- .filter(line => line.trim() !== '')
165
- .map(line => line.trim())
166
- .slice(0, 10); // 限制依赖数量
167
- }
168
- return [];
169
- }
170
- /**
171
- * 获取默认项目信息
172
- */
173
- getDefaultProjectInfo() {
174
- return {
175
- techStack: [],
176
- frameworks: [],
177
- language: '',
178
- projectType: '通用项目',
179
- dependencies: []
180
- };
181
- }
182
- /**
183
- * 验证项目信息的完整性
184
- */
185
- validateProjectInfo(projectInfo) {
186
- if (!projectInfo.projectType) {
187
- throw new types_1.RequirementAnalysisError('无法确定项目类型,请检查项目结构', types_1.ErrorCodes.PROJECT_ANALYSIS_FAILED, { projectInfo });
188
- }
189
- }
190
- }
191
- exports.ProjectAnalyzer = ProjectAnalyzer;
192
- /**
193
- * 从项目分析内容中提取项目信息的工具函数
194
- * 保持向后兼容性
195
- */
196
- function extractProjectInfo(projectAnalysis) {
197
- const analyzer = new ProjectAnalyzer();
198
- return analyzer.extractProjectInfo(projectAnalysis);
199
- }