intention-coding 0.4.4 → 0.4.5

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 (65) hide show
  1. package/dist/index.cjs +2243 -73
  2. package/dist/services/change-summarizer/index.d.ts +2 -12
  3. package/dist/services/change-summarizer/index.d.ts.map +1 -1
  4. package/dist/services/code-generator/index.d.ts +2 -12
  5. package/dist/services/code-generator/index.d.ts.map +1 -1
  6. package/dist/services/image-analysis/index.d.ts +2 -6
  7. package/dist/services/image-analysis/index.d.ts.map +1 -1
  8. package/dist/services/image-converter/index.d.ts +2 -18
  9. package/dist/services/image-converter/index.d.ts.map +1 -1
  10. package/dist/services/image-recognition-agent/types.d.ts +2 -2
  11. package/dist/services/integrated-generator/index.d.ts +4 -32
  12. package/dist/services/integrated-generator/index.d.ts.map +1 -1
  13. package/dist/services/pdf2md/index.d.ts +2 -16
  14. package/dist/services/pdf2md/index.d.ts.map +1 -1
  15. package/dist/services/project-template/index.d.ts +2 -10
  16. package/dist/services/project-template/index.d.ts.map +1 -1
  17. package/dist/services/requirement-analyzer/index.d.ts +2 -38
  18. package/dist/services/requirement-analyzer/index.d.ts.map +1 -1
  19. package/dist/services/requirement-handler/core/agents/align-agent.d.ts +31 -0
  20. package/dist/services/requirement-handler/core/agents/align-agent.d.ts.map +1 -0
  21. package/dist/services/requirement-handler/core/agents/approve-agent.d.ts +33 -0
  22. package/dist/services/requirement-handler/core/agents/approve-agent.d.ts.map +1 -0
  23. package/dist/services/requirement-handler/core/agents/architect-agent.d.ts +29 -0
  24. package/dist/services/requirement-handler/core/agents/architect-agent.d.ts.map +1 -0
  25. package/dist/services/requirement-handler/core/agents/assess-agent.d.ts +53 -0
  26. package/dist/services/requirement-handler/core/agents/assess-agent.d.ts.map +1 -0
  27. package/dist/services/requirement-handler/core/agents/atomize-agent.d.ts +33 -0
  28. package/dist/services/requirement-handler/core/agents/atomize-agent.d.ts.map +1 -0
  29. package/dist/services/requirement-handler/core/agents/automate-agent.d.ts +43 -0
  30. package/dist/services/requirement-handler/core/agents/automate-agent.d.ts.map +1 -0
  31. package/dist/services/requirement-handler/core/requirement-handler-service.d.ts +35 -0
  32. package/dist/services/requirement-handler/core/requirement-handler-service.d.ts.map +1 -0
  33. package/dist/services/requirement-handler/core/types.d.ts +143 -0
  34. package/dist/services/requirement-handler/core/types.d.ts.map +1 -0
  35. package/dist/services/requirement-handler/index.d.ts +87 -0
  36. package/dist/services/requirement-handler/index.d.ts.map +1 -0
  37. package/dist/services/world2md/index.d.ts +7 -34
  38. package/dist/services/world2md/index.d.ts.map +1 -1
  39. package/dist/utils/common.d.ts +4 -0
  40. package/dist/utils/common.d.ts.map +1 -1
  41. package/dist/utils/openai.d.ts +4 -0
  42. package/dist/utils/openai.d.ts.map +1 -1
  43. package/package.json +1 -1
  44. package/dist/services/6a-workflow-agent/6a-workflow-agent.test.d.ts +0 -2
  45. package/dist/services/6a-workflow-agent/6a-workflow-agent.test.d.ts.map +0 -1
  46. package/dist/services/6a-workflow-agent/index.d.ts +0 -240
  47. package/dist/services/6a-workflow-agent/index.d.ts.map +0 -1
  48. package/dist/services/6a-workflow-agent/stages/align-stage.d.ts +0 -40
  49. package/dist/services/6a-workflow-agent/stages/align-stage.d.ts.map +0 -1
  50. package/dist/services/6a-workflow-agent/stages/approve-stage.d.ts +0 -24
  51. package/dist/services/6a-workflow-agent/stages/approve-stage.d.ts.map +0 -1
  52. package/dist/services/6a-workflow-agent/stages/architect-stage.d.ts +0 -20
  53. package/dist/services/6a-workflow-agent/stages/architect-stage.d.ts.map +0 -1
  54. package/dist/services/6a-workflow-agent/stages/assess-stage.d.ts +0 -36
  55. package/dist/services/6a-workflow-agent/stages/assess-stage.d.ts.map +0 -1
  56. package/dist/services/6a-workflow-agent/stages/atomize-stage.d.ts +0 -28
  57. package/dist/services/6a-workflow-agent/stages/atomize-stage.d.ts.map +0 -1
  58. package/dist/services/6a-workflow-agent/stages/automate-stage.d.ts +0 -36
  59. package/dist/services/6a-workflow-agent/stages/automate-stage.d.ts.map +0 -1
  60. package/dist/services/6a-workflow-agent/types.d.ts +0 -261
  61. package/dist/services/6a-workflow-agent/types.d.ts.map +0 -1
  62. package/dist/services/6a-workflow-agent/workflow-manager.d.ts +0 -67
  63. package/dist/services/6a-workflow-agent/workflow-manager.d.ts.map +0 -1
  64. package/dist/services/bug-fix-agent/index.d.ts +0 -57
  65. package/dist/services/bug-fix-agent/index.d.ts.map +0 -1
package/dist/index.cjs CHANGED
@@ -317,6 +317,7 @@ var __webpack_exports__ = {};
317
317
  var external_mammoth_default = /*#__PURE__*/ __webpack_require__.n(external_mammoth_namespaceObject);
318
318
  const external_html_to_md_namespaceObject = require("html-to-md");
319
319
  var external_html_to_md_default = /*#__PURE__*/ __webpack_require__.n(external_html_to_md_namespaceObject);
320
+ const external_os_namespaceObject = require("os");
320
321
  const common_sanitizeFileName = (input)=>input.replace(/[\\/:*?"<>|\n\r#%&]/g, '').trim().replace(/\s+/g, '_').replace(/_+/g, '_').replace(/^_+|_+$/g, '');
321
322
  async function common_validateAndResolvePath(filePath) {
322
323
  if ('win32' === process.platform && filePath.startsWith('\\\\')) filePath = '\\\\?\\UNC\\' + filePath.substring(2);
@@ -3920,8 +3921,8 @@ var __webpack_exports__ = {};
3920
3921
  ZodNullable.create;
3921
3922
  ZodEffects.createWithPreprocess;
3922
3923
  ZodPipeline.create;
3923
- const Word2MdParamsSchema = objectType({
3924
- file_path: stringType().describe("\u9700\u8981\u89E3\u6790\u7684Word\u6587\u6863\u7684\u7EDD\u5BF9\u8DEF\u5F84"),
3924
+ objectType({
3925
+ filePath: stringType().describe("\u9700\u8981\u89E3\u6790\u7684Word\u6587\u6863\u7684\u7EDD\u5BF9\u8DEF\u5F84"),
3925
3926
  options: objectType({
3926
3927
  skip_images: booleanType().optional().default(false).describe("\u662F\u5426\u8DF3\u8FC7\u56FE\u7247\u8F6C\u6362"),
3927
3928
  table_style: enumType([
@@ -3939,14 +3940,17 @@ var __webpack_exports__ = {};
3939
3940
  const word2mdTool = {
3940
3941
  name: "word\u6587\u6863\u5904\u7406\u667A\u80FD\u4F53",
3941
3942
  description: "word\u6587\u6863\u5904\u7406\u667A\u80FD\u4F53 - \u5C06Word\u6587\u6863(.docx)\u8F6C\u6362\u4E3AMarkdown\u683C\u5F0F",
3942
- inputSchema: Word2MdParamsSchema,
3943
+ inputSchema: {
3944
+ filePath: stringType().describe("\u9700\u8981\u89E3\u6790\u7684Word\u6587\u6863\u7684\u7EDD\u5BF9\u8DEF\u5F84")
3945
+ },
3943
3946
  handler: async (args)=>{
3944
- const { file_path } = args;
3947
+ const { filePath } = args;
3948
+ if (!filePath) throw new Error("\u6587\u4EF6\u8DEF\u5F84\u53C2\u6570\u7F3A\u5931\uFF0C\u8BF7\u63D0\u4F9B filePath \u53C2\u6570");
3945
3949
  try {
3946
- const resolvedPath = await common_validateAndResolvePath(file_path);
3950
+ const resolvedPath = await common_validateAndResolvePath(filePath);
3947
3951
  const buffer = await promises_namespaceObject.readFile(resolvedPath);
3948
3952
  const mdDir = external_path_default().join(config_getStorageDir(), 'md');
3949
- const baseName = external_path_default().basename(file_path, '.docx');
3953
+ const baseName = external_path_default().basename(filePath, '.docx');
3950
3954
  const outputDir = external_path_default().join(mdDir, baseName);
3951
3955
  const imgsDir = external_path_default().join(outputDir, 'imgs');
3952
3956
  await promises_namespaceObject.mkdir(outputDir, {
@@ -3956,7 +3960,7 @@ var __webpack_exports__ = {};
3956
3960
  recursive: true
3957
3961
  });
3958
3962
  logger_logger.info("\u5F00\u59CB\u8F6C\u6362Word\u6587\u6863", {
3959
- file: file_path,
3963
+ file: filePath,
3960
3964
  outputDir,
3961
3965
  imgsDir
3962
3966
  });
@@ -3993,7 +3997,7 @@ var __webpack_exports__ = {};
3993
3997
  messages: basicResult.messages
3994
3998
  };
3995
3999
  if (htmlResult.messages && htmlResult.messages.length > 0) logger_logger.warn("Word\u8F6C\u6362\u8B66\u544A", {
3996
- file: file_path,
4000
+ file: filePath,
3997
4001
  warnings: htmlResult.messages
3998
4002
  });
3999
4003
  let markdownContent = external_html_to_md_default()(htmlResult.value);
@@ -4019,7 +4023,7 @@ var __webpack_exports__ = {};
4019
4023
  const errorMsg = error instanceof Error ? error.message : String(error);
4020
4024
  logger_logger.error(`Word\u{8F6C}\u{6362}\u{5931}\u{8D25}: ${errorMsg}`, {
4021
4025
  tool: "word2md",
4022
- file_path
4026
+ filePath
4023
4027
  });
4024
4028
  return {
4025
4029
  content: [
@@ -4037,7 +4041,7 @@ var __webpack_exports__ = {};
4037
4041
  }
4038
4042
  }
4039
4043
  };
4040
- const Pdf2MdParamsSchema = objectType({
4044
+ objectType({
4041
4045
  file_path: stringType().describe("\u9700\u8981\u89E3\u6790\u7684PDF\u6587\u6863\u7684\u7EDD\u5BF9\u8DEF\u5F84"),
4042
4046
  options: objectType({
4043
4047
  preserve_formatting: booleanType().optional().default(true).describe("\u662F\u5426\u4FDD\u7559\u683C\u5F0F\uFF08\u6362\u884C\u3001\u6BB5\u843D\u7B49\uFF09"),
@@ -4052,7 +4056,18 @@ var __webpack_exports__ = {};
4052
4056
  const pdf2mdTool = {
4053
4057
  name: "pdf\u5904\u7406\u667A\u80FD\u4F53",
4054
4058
  description: "pdf\u5904\u7406\u667A\u80FD\u4F53 - \u5C06PDF\u6587\u6863\u8F6C\u6362\u4E3AMarkdown\u683C\u5F0F\uFF0C\u652F\u6301\u6587\u672C\u63D0\u53D6\u548C\u683C\u5F0F\u4FDD\u7559",
4055
- inputSchema: Pdf2MdParamsSchema,
4059
+ inputSchema: {
4060
+ file_path: stringType().describe("\u9700\u8981\u89E3\u6790\u7684PDF\u6587\u6863\u7684\u7EDD\u5BF9\u8DEF\u5F84"),
4061
+ options: objectType({
4062
+ preserve_formatting: booleanType().optional().default(true).describe("\u662F\u5426\u4FDD\u7559\u683C\u5F0F\uFF08\u6362\u884C\u3001\u6BB5\u843D\u7B49\uFF09"),
4063
+ chunk_size: numberType().optional().default(1000).describe("\u6587\u672C\u5206\u5757\u5927\u5C0F\uFF0C\u7528\u4E8E\u5927\u6587\u4EF6\u5904\u7406"),
4064
+ extract_metadata: booleanType().optional().default(true).describe("\u662F\u5426\u63D0\u53D6PDF\u5143\u6570\u636E")
4065
+ }).optional().default({
4066
+ preserve_formatting: true,
4067
+ chunk_size: 1000,
4068
+ extract_metadata: true
4069
+ }).describe("\u8F6C\u6362\u9009\u9879")
4070
+ },
4056
4071
  handler: async (args)=>{
4057
4072
  const { file_path, options = {} } = args;
4058
4073
  const { preserve_formatting = true, extract_metadata = true } = options;
@@ -4278,7 +4293,7 @@ var __webpack_exports__ = {};
4278
4293
 
4279
4294
  \u{8BF7}\u{5C06}\u{751F}\u{6210}\u{7684}\u{6587}\u{4EF6}\u{4FDD}\u{5B58}\u{5230}\u{9879}\u{76EE}\u{6839}\u{76EE}\u{5F55}\u{4E0B}\u{7684}.aico\u{6587}\u{4EF6}\u{5939}\u{4E2D}\u{FF0C}\u{6587}\u{4EF6}\u{540D}\u{4E3A}project_rules.md\u{3002}
4280
4295
  `;
4281
- const ProjectTemplateParams = objectType({
4296
+ objectType({
4282
4297
  project_name: stringType().optional().describe("\u9879\u76EE\u540D\u79F0\uFF0C\u7528\u4E8E\u751F\u6210\u6587\u4EF6\u540D"),
4283
4298
  project_path: stringType().optional().describe("\u9879\u76EE\u7EDD\u5BF9\u8DEF\u5F84\uFF0C\u7528\u4E8E\u6307\u5B9A\u8981\u5206\u6790\u7684\u9879\u76EE\u76EE\u5F55"),
4284
4299
  custom_rules: stringType().optional().describe("\u81EA\u5B9A\u4E49\u89C4\u5219\u5185\u5BB9")
@@ -4286,7 +4301,11 @@ var __webpack_exports__ = {};
4286
4301
  const initProjectStandard = {
4287
4302
  name: "\u9879\u76EE\u5F00\u53D1\u89C4\u8303\u751F\u6210\u667A\u80FD\u4F53",
4288
4303
  description: "\u5206\u6790\u9879\u76EE\u67B6\u6784\u5E76\u751F\u6210\u5F00\u53D1\u89C4\u8303",
4289
- inputSchema: ProjectTemplateParams,
4304
+ inputSchema: {
4305
+ project_name: stringType().optional().describe("\u9879\u76EE\u540D\u79F0\uFF0C\u7528\u4E8E\u751F\u6210\u6587\u4EF6\u540D"),
4306
+ project_path: stringType().optional().describe("\u9879\u76EE\u7EDD\u5BF9\u8DEF\u5F84\uFF0C\u7528\u4E8E\u6307\u5B9A\u8981\u5206\u6790\u7684\u9879\u76EE\u76EE\u5F55"),
4307
+ custom_rules: stringType().optional().describe("\u81EA\u5B9A\u4E49\u89C4\u5219\u5185\u5BB9")
4308
+ },
4290
4309
  handler: async (args)=>{
4291
4310
  const { project_name = 'current-project', project_path, custom_rules } = args;
4292
4311
  try {
@@ -4670,7 +4689,17 @@ ${customRules}` : '';
4670
4689
  }
4671
4690
  }
4672
4691
  const openai_openAIService = new OpenAIService();
4673
- const RequirementAnalyzerParamsSchema = objectType({
4692
+ async function callOpenAI(messages) {
4693
+ const systemMessage = messages.find((m)=>'system' === m.role);
4694
+ const userMessages = messages.filter((m)=>'user' === m.role);
4695
+ const prompt = userMessages.map((m)=>m.content).join('\n');
4696
+ return await openai_openAIService.generateText({
4697
+ prompt,
4698
+ system_prompt: systemMessage?.content,
4699
+ temperature: 0.7
4700
+ });
4701
+ }
4702
+ objectType({
4674
4703
  input_type: enumType([
4675
4704
  "text",
4676
4705
  "md_file"
@@ -4696,7 +4725,23 @@ ${customRules}` : '';
4696
4725
  const requirementAnalyzerTool = {
4697
4726
  name: "\u9700\u6C42\u5206\u6790\u667A\u80FD\u4F53",
4698
4727
  description: "\u667A\u80FD\u5206\u6790\u9700\u6C42\u5E76\u751F\u6210\u7EDF\u4E00\u7684\u6280\u672F\u6587\u6863\uFF0C\u652F\u6301\u9879\u76EE\u60C5\u51B5\u611F\u77E5\u548C\u7CBE\u786E\u6A21\u677F\u5339\u914D",
4699
- inputSchema: RequirementAnalyzerParamsSchema,
4728
+ inputSchema: {
4729
+ input_type: enumType([
4730
+ "text",
4731
+ "md_file"
4732
+ ]).describe("\u8F93\u5165\u7C7B\u578B\uFF1A\u76F4\u63A5\u6587\u672C\u8F93\u5165\u6216\u5F15\u7528\u5DF2\u751F\u6210\u7684MD\u6587\u4EF6"),
4733
+ content: stringType().optional().describe("\u5F53input_type\u4E3Atext\u65F6\uFF0C\u76F4\u63A5\u8F93\u5165\u7684\u9700\u6C42\u5185\u5BB9"),
4734
+ md_file_path: stringType().optional().describe("\u5F53input_type\u4E3Amd_file\u65F6\uFF0C\u8981\u5206\u6790\u7684MD\u6587\u4EF6\u8DEF\u5F84"),
4735
+ feature_name: stringType().describe("\u529F\u80FD\u540D\u79F0\uFF0C\u7528\u4E8E\u751F\u6210\u8F93\u51FA\u6587\u4EF6\u540D"),
4736
+ custom_prompt: stringType().optional().describe("\u81EA\u5B9A\u4E49\u63D0\u793A\u8BCD\uFF0C\u7528\u4E8E\u6307\u5BFCAI\u751F\u6210\u7279\u5B9A\u98CE\u683C\u7684\u9700\u6C42\u6587\u6863"),
4737
+ analysis_depth: enumType([
4738
+ "basic",
4739
+ "detailed",
4740
+ "comprehensive"
4741
+ ]).default("detailed").describe("\u5206\u6790\u6DF1\u5EA6\uFF1A\u57FA\u7840\u3001\u8BE6\u7EC6\u3001\u7EFC\u5408"),
4742
+ use_streaming: booleanType().default(false).describe("\u662F\u5426\u4F7F\u7528\u6D41\u5F0F\u5904\u7406\uFF08\u9002\u7528\u4E8E\u5927\u6587\u4EF6\uFF09"),
4743
+ chunk_size: numberType().min(10).max(1000).default(100).describe("\u5206\u5757\u5927\u5C0F\uFF08\u4EC5\u5728use_streaming\u4E3Atrue\u65F6\u6709\u6548\uFF09")
4744
+ },
4700
4745
  handler: async (args)=>{
4701
4746
  try {
4702
4747
  return {
@@ -4731,7 +4776,6 @@ ${customRules}` : '';
4731
4776
  }
4732
4777
  }
4733
4778
  };
4734
- requirementAnalyzerTool.handler = requirementAnalyzerTool.handler;
4735
4779
  const changeAnalysisPrompt = `\u{8BF7}\u{5206}\u{6790}\u{5F53}\u{524D}\u{4EE3}\u{7801}\u{5E93}\u{FF0C}\u{5E76}\u{4E0E}\u{9700}\u{6C42}\u{8FDB}\u{884C}\u{5BF9}\u{6BD4}\u{FF0C}\u{786E}\u{4FDD}\u{5B9E}\u{73B0}\u{7684}\u{5B8C}\u{6574}\u{6027}\u{3002}
4736
4780
 
4737
4781
  \u{8BF7}\u{6309}\u{4EE5}\u{4E0B}\u{6B65}\u{9AA4}\u{8FDB}\u{884C}\u{5206}\u{6790}\u{FF1A}
@@ -4785,7 +4829,7 @@ ${customRules}` : '';
4785
4829
  - \u{6D4B}\u{8BD5}\u{5EFA}\u{8BAE}
4786
4830
 
4787
4831
  \u{8BF7}\u{786E}\u{4FDD}\u{6240}\u{6709}\u{8868}\u{683C}\u{4E0A}\u{4E0B}\u{5BF9}\u{9F50}\u{FF0C}\u{5185}\u{5BB9}\u{8BE6}\u{5B9E}\u{51C6}\u{786E}\u{3002}`;
4788
- const ChangeSummarizerParams = objectType({
4832
+ objectType({
4789
4833
  baseBranch: stringType().default('main').describe("\u57FA\u51C6\u5206\u652F\u540D\u79F0\uFF0C\u7528\u4E8E\u5BF9\u6BD4\u53D8\u66F4"),
4790
4834
  requirementFile: stringType().optional().describe("\u9700\u6C42\u6587\u6863\u6587\u4EF6\u8DEF\u5F84\uFF08\u53EF\u9009\uFF09"),
4791
4835
  includeUncommitted: booleanType().default(true).describe("\u662F\u5426\u5305\u542B\u672A\u63D0\u4EA4\u7684\u53D8\u66F4"),
@@ -4797,7 +4841,15 @@ ${customRules}` : '';
4797
4841
  const changeSummarizer = {
4798
4842
  name: "\u4EE3\u7801\u53D8\u66F4\u5206\u6790\u667A\u80FD\u4F53",
4799
4843
  description: "\u5206\u6790\u4EE3\u7801\u5E76\u4E0E\u9700\u6C42\u8FDB\u884C\u5BF9\u6BD4\uFF0C\u786E\u4FDD\u5B9E\u73B0\u5B8C\u6574\u6027",
4800
- inputSchema: ChangeSummarizerParams,
4844
+ inputSchema: {
4845
+ baseBranch: stringType().default('main').describe("\u57FA\u51C6\u5206\u652F\u540D\u79F0\uFF0C\u7528\u4E8E\u5BF9\u6BD4\u53D8\u66F4"),
4846
+ requirementFile: stringType().optional().describe("\u9700\u6C42\u6587\u6863\u6587\u4EF6\u8DEF\u5F84\uFF08\u53EF\u9009\uFF09"),
4847
+ includeUncommitted: booleanType().default(true).describe("\u662F\u5426\u5305\u542B\u672A\u63D0\u4EA4\u7684\u53D8\u66F4"),
4848
+ outputFormat: enumType([
4849
+ 'markdown',
4850
+ 'json'
4851
+ ]).default('markdown').describe("\u8F93\u51FA\u683C\u5F0F")
4852
+ },
4801
4853
  handler: async (args)=>{
4802
4854
  try {
4803
4855
  initializeProjectRoot();
@@ -5509,7 +5561,9 @@ ${isLongImage ? `8. **\u{957F}\u{56FE}\u{7279}\u{5F81}**\u{FF1A}\u{5206}\u{6790}
5509
5561
  const imageAnalysisTool = {
5510
5562
  name: "\u56FE\u7247\u5185\u5BB9\u7406\u89E3\u667A\u80FD\u4F53",
5511
5563
  description: "\u4E13\u4E1A\u56FE\u7247\u5185\u5BB9\u5206\u6790\u5DE5\u5177\uFF0C\u652F\u6301\u901A\u7528\u5206\u6790\u3001\u7269\u4F53\u8BC6\u522B\u3001\u6587\u5B57\u8BC6\u522B\u3001\u573A\u666F\u5206\u6790\u3001\u4EBA\u7269\u5206\u6790\u3001\u6280\u672F\u5206\u6790\u3001UI\u8BBE\u8BA1\u7A3F\u5206\u6790\u3001\u9700\u6C42\u8BC6\u522B\u7B49\u591A\u79CD\u6A21\u5F0F\uFF0C\u7279\u522B\u64C5\u957FUI\u8BBE\u8BA1\u7A3F\u7684\u7ED3\u6784\u5206\u6790\u548C\u9875\u9762\u9700\u6C42\u63D0\u53D6\u3002\u5206\u6790\u7ED3\u679C\u5C06\u4FDD\u5B58\u5230image-recognition\u76EE\u5F55\u3002",
5512
- inputSchema: ImageAnalysisParamsSchema,
5564
+ inputSchema: {
5565
+ image_path: stringType().min(1).describe("\u56FE\u7247\u6587\u4EF6\u8DEF\u5F84")
5566
+ },
5513
5567
  handler: async (args)=>{
5514
5568
  initializeProjectRoot();
5515
5569
  const analyzer = new ImageAnalyzer();
@@ -6293,7 +6347,7 @@ ${getErrorSuggestion(error.code)}
6293
6347
  }
6294
6348
  }
6295
6349
  }
6296
- const ImageConversionParamsSchema = objectType({
6350
+ objectType({
6297
6351
  input_paths: unionType([
6298
6352
  stringType(),
6299
6353
  arrayType(stringType())
@@ -6317,7 +6371,27 @@ ${getErrorSuggestion(error.code)}
6317
6371
  const imageConverterTool = {
6318
6372
  name: "\u56FE\u7247\u683C\u5F0F\u8F6C\u6362\u667A\u80FD\u4F53",
6319
6373
  description: "\u4E13\u4E1A\u56FE\u7247\u683C\u5F0F\u8F6C\u6362\u5DE5\u5177\uFF0C\u652F\u6301\u5355\u5F20\u548C\u6279\u91CF\u8F6C\u6362\uFF0C\u5305\u542B\u5C3A\u5BF8\u8C03\u6574\u548C\u8D28\u91CF\u63A7\u5236\u529F\u80FD",
6320
- inputSchema: ImageConversionParamsSchema,
6374
+ inputSchema: {
6375
+ input_paths: unionType([
6376
+ stringType(),
6377
+ arrayType(stringType())
6378
+ ]).describe("\u8F93\u5165\u56FE\u7247\u8DEF\u5F84\uFF0C\u652F\u6301\u5355\u4E2A\u8DEF\u5F84\u6216\u8DEF\u5F84\u6570\u7EC4"),
6379
+ output_format: enumType([
6380
+ "jpg",
6381
+ "jpeg",
6382
+ "png",
6383
+ "gif",
6384
+ "bmp",
6385
+ "tiff",
6386
+ "webp",
6387
+ "ico"
6388
+ ]).describe("\u8F93\u51FA\u683C\u5F0F"),
6389
+ quality: numberType().min(1).max(100).optional().describe("\u56FE\u7247\u8D28\u91CF\uFF0C1-100\uFF0C\u9ED8\u8BA490"),
6390
+ width: numberType().positive().optional().describe("\u8F93\u51FA\u5BBD\u5EA6\uFF08\u50CF\u7D20\uFF09"),
6391
+ height: numberType().positive().optional().describe("\u8F93\u51FA\u9AD8\u5EA6\uFF08\u50CF\u7D20\uFF09"),
6392
+ maintain_aspect_ratio: booleanType().default(true).describe("\u662F\u5426\u4FDD\u6301\u5BBD\u9AD8\u6BD4\uFF0C\u9ED8\u8BA4true"),
6393
+ output_directory: stringType().optional().describe("\u8F93\u51FA\u76EE\u5F55\uFF0C\u4E0D\u6307\u5B9A\u5219\u5728\u539F\u6587\u4EF6\u76EE\u5F55\u751F\u6210")
6394
+ },
6321
6395
  handler: async (args)=>{
6322
6396
  const converter = new ImageConverter();
6323
6397
  try {
@@ -6513,54 +6587,7 @@ ${image_converter_getErrorSuggestion(error.code)}
6513
6587
  };
6514
6588
  return suggestions[errorCode] || "\u8BF7\u68C0\u67E5\u8F93\u5165\u53C2\u6570\u5E76\u91CD\u8BD5";
6515
6589
  }
6516
- const BugFixAgentParams = objectType({
6517
- bug_description: stringType().min(1).describe("Bug\u63CF\u8FF0\u4FE1\u606F\u6216\u95EE\u9898\u8BF4\u660E"),
6518
- project_path: stringType().optional().describe("\u9879\u76EE\u7EDD\u5BF9\u8DEF\u5F84\uFF0C\u7528\u4E8E\u6307\u5B9A\u8981\u5206\u6790\u7684\u9879\u76EE\u76EE\u5F55"),
6519
- project_name: stringType().optional().default('current-project').describe("\u9879\u76EE\u540D\u79F0"),
6520
- output_format: enumType([
6521
- 'markdown',
6522
- 'json'
6523
- ]).optional().default('markdown').describe("\u8F93\u51FA\u683C\u5F0F")
6524
- });
6525
- const bugFixAgentTool = {
6526
- name: "bug\u4FEE\u590D\u667A\u80FD\u4F53",
6527
- description: "\u6839\u636E\u7528\u6237\u63D0\u4F9B\u7684bug\u63CF\u8FF0\u4FE1\u606F\uFF0C\u667A\u80FD\u5206\u6790\u9879\u76EE\u7ED3\u6784\u5E76\u751F\u6210\u4FEE\u590D\u65B9\u6848",
6528
- inputSchema: BugFixAgentParams,
6529
- handler: async (args)=>{
6530
- try {
6531
- return {
6532
- content: [
6533
- {
6534
- type: "text",
6535
- text: JSON.stringify({
6536
- success: true,
6537
- message: "Bug\u4FEE\u590D\u667A\u80FD\u4F53\u6D4B\u8BD5\u6210\u529F",
6538
- data: {
6539
- bug_description: args.bug_description
6540
- }
6541
- })
6542
- }
6543
- ]
6544
- };
6545
- } catch (error) {
6546
- return {
6547
- content: [
6548
- {
6549
- type: "text",
6550
- text: JSON.stringify({
6551
- success: false,
6552
- message: `Bug\u{4FEE}\u{590D}\u{667A}\u{80FD}\u{4F53}\u{6267}\u{884C}\u{5931}\u{8D25}: ${error.message}`,
6553
- data: null
6554
- })
6555
- }
6556
- ],
6557
- isError: true
6558
- };
6559
- }
6560
- }
6561
- };
6562
- bugFixAgentTool.handler = bugFixAgentTool.handler;
6563
- const CodeGeneratorParamsSchema = objectType({
6590
+ objectType({
6564
6591
  task_description: stringType().min(1).describe("\u8981\u5F00\u53D1\u7684\u4EFB\u52A1\u63CF\u8FF0"),
6565
6592
  current_stage: enumType([
6566
6593
  "research",
@@ -6863,7 +6890,19 @@ ${taskDescription}
6863
6890
  const codeGeneratorTool = {
6864
6891
  name: "\u7F16\u7A0B\u667A\u80FD\u4F53",
6865
6892
  description: "\u4E13\u4E1AAI\u7F16\u7A0B\u52A9\u624B\uFF0C\u63D0\u4F9B\u7ED3\u6784\u5316\u516D\u9636\u6BB5\u5F00\u53D1\u5DE5\u4F5C\u6D41\uFF08\u7814\u7A76\u2192\u6784\u601D\u2192\u8BA1\u5212\u2192\u6267\u884C\u2192\u4F18\u5316\u2192\u8BC4\u5BA1\uFF09\uFF0C\u6309\u7167workflow.md\u4E2D\u5B9A\u4E49\u7684\u6D41\u7A0B\u6307\u5BFC\u7528\u6237\u5B8C\u6210\u4EE3\u7801\u5F00\u53D1",
6866
- inputSchema: CodeGeneratorParamsSchema,
6893
+ inputSchema: {
6894
+ task_description: stringType().min(1).describe("\u8981\u5F00\u53D1\u7684\u4EFB\u52A1\u63CF\u8FF0"),
6895
+ current_stage: enumType([
6896
+ "research",
6897
+ "ideation",
6898
+ "planning",
6899
+ "execution",
6900
+ "optimization",
6901
+ "review"
6902
+ ]).optional().default("research").describe("\u5F53\u524D\u5DE5\u4F5C\u6D41\u7A0B\u9636\u6BB5"),
6903
+ user_input: anyType().optional().describe("\u7528\u6237\u5728\u5F53\u524D\u9636\u6BB5\u7684\u8F93\u5165\u6570\u636E"),
6904
+ project_path: stringType().optional().describe("\u9879\u76EE\u8DEF\u5F84")
6905
+ },
6867
6906
  handler: async (args)=>{
6868
6907
  const { task_description, current_stage, user_input, project_path } = args;
6869
6908
  try {
@@ -7225,7 +7264,6 @@ ${taskDescription}
7225
7264
  }
7226
7265
  }
7227
7266
  }
7228
- const external_os_namespaceObject = require("os");
7229
7267
  class ConfigCalculator {
7230
7268
  async calculateSegmentConfig(imageInfo, qualityAssessment, maxSegments = LONG_IMAGE_THRESHOLDS.MAX_SEGMENTS) {
7231
7269
  logger_logger.info("ConfigCalculator: \u5F00\u59CB\u8BA1\u7B97\u5206\u6BB5\u914D\u7F6E", {
@@ -7914,6 +7952,2138 @@ ${allTextContent || "\u672A\u8BC6\u522B\u5230\u6587\u5B57\u5185\u5BB9"}
7914
7952
  }
7915
7953
  }
7916
7954
  };
7955
+ class RequirementHandlerError extends Error {
7956
+ code;
7957
+ stage;
7958
+ context;
7959
+ constructor(message, code, stage, context){
7960
+ super(message), this.code = code, this.stage = stage, this.context = context;
7961
+ this.name = 'RequirementHandlerError';
7962
+ }
7963
+ }
7964
+ var types_StageErrorCodes = /*#__PURE__*/ function(StageErrorCodes) {
7965
+ StageErrorCodes["ALIGN_INVALID_REQUIREMENT"] = "ALIGN_INVALID_REQUIREMENT";
7966
+ StageErrorCodes["ALIGN_PROJECT_ANALYSIS_FAILED"] = "ALIGN_PROJECT_ANALYSIS_FAILED";
7967
+ StageErrorCodes["ALIGN_CONSENSUS_FAILED"] = "ALIGN_CONSENSUS_FAILED";
7968
+ StageErrorCodes["ARCHITECT_DESIGN_FAILED"] = "ARCHITECT_DESIGN_FAILED";
7969
+ StageErrorCodes["ARCHITECT_INTERFACE_FAILED"] = "ARCHITECT_INTERFACE_FAILED";
7970
+ StageErrorCodes["ARCHITECT_COMPATIBILITY_CHECK_FAILED"] = "ARCHITECT_COMPATIBILITY_CHECK_FAILED";
7971
+ StageErrorCodes["ATOMIZE_TASK_DECOMPOSITION_FAILED"] = "ATOMIZE_TASK_DECOMPOSITION_FAILED";
7972
+ StageErrorCodes["ATOMIZE_DEPENDENCY_ANALYSIS_FAILED"] = "ATOMIZE_DEPENDENCY_ANALYSIS_FAILED";
7973
+ StageErrorCodes["ATOMIZE_COMPLEXITY_ASSESSMENT_FAILED"] = "ATOMIZE_COMPLEXITY_ASSESSMENT_FAILED";
7974
+ StageErrorCodes["APPROVE_QUALITY_CHECK_FAILED"] = "APPROVE_QUALITY_CHECK_FAILED";
7975
+ StageErrorCodes["APPROVE_RISK_ASSESSMENT_FAILED"] = "APPROVE_RISK_ASSESSMENT_FAILED";
7976
+ StageErrorCodes["APPROVE_HUMAN_REJECTION"] = "APPROVE_HUMAN_REJECTION";
7977
+ StageErrorCodes["AUTOMATE_IMPLEMENTATION_FAILED"] = "AUTOMATE_IMPLEMENTATION_FAILED";
7978
+ StageErrorCodes["AUTOMATE_TEST_GENERATION_FAILED"] = "AUTOMATE_TEST_GENERATION_FAILED";
7979
+ StageErrorCodes["AUTOMATE_CODE_QUALITY_FAILED"] = "AUTOMATE_CODE_QUALITY_FAILED";
7980
+ StageErrorCodes["ASSESS_QUALITY_EVALUATION_FAILED"] = "ASSESS_QUALITY_EVALUATION_FAILED";
7981
+ StageErrorCodes["ASSESS_ACCEPTANCE_VERIFICATION_FAILED"] = "ASSESS_ACCEPTANCE_VERIFICATION_FAILED";
7982
+ StageErrorCodes["ASSESS_DELIVERABLE_GENERATION_FAILED"] = "ASSESS_DELIVERABLE_GENERATION_FAILED";
7983
+ StageErrorCodes["WORKSPACE_CREATION_FAILED"] = "WORKSPACE_CREATION_FAILED";
7984
+ StageErrorCodes["HUMAN_CONFIRMATION_TIMEOUT"] = "HUMAN_CONFIRMATION_TIMEOUT";
7985
+ StageErrorCodes["STAGE_EXECUTION_TIMEOUT"] = "STAGE_EXECUTION_TIMEOUT";
7986
+ StageErrorCodes["INVALID_STAGE_TRANSITION"] = "INVALID_STAGE_TRANSITION";
7987
+ StageErrorCodes["CONFIGURATION_ERROR"] = "CONFIGURATION_ERROR";
7988
+ return StageErrorCodes;
7989
+ }({});
7990
+ class AlignAgent {
7991
+ async execute(input) {
7992
+ logger_logger.info("\u9700\u6C42\u5BF9\u9F50\u667A\u80FD\u4F53\u5F00\u59CB\u6267\u884C", {
7993
+ featureName: input.feature_name
7994
+ });
7995
+ try {
7996
+ const projectAnalysis = await this.analyzeProjectContext(input.project_context);
7997
+ const requirementAnalysis = await this.analyzeRequirement(input.requirement_text, projectAnalysis);
7998
+ const alignmentDoc = await this.generateAlignmentDocument(requirementAnalysis, input.feature_name);
7999
+ const consensusDoc = await this.generateConsensusDocument(requirementAnalysis, input.feature_name);
8000
+ const projectRoot = process.cwd();
8001
+ const aicoDocsDir = external_path_namespaceObject.join(projectRoot, '.aico', 'docs', input.feature_name);
8002
+ if (!external_fs_namespaceObject.existsSync(aicoDocsDir)) external_fs_namespaceObject.mkdirSync(aicoDocsDir, {
8003
+ recursive: true
8004
+ });
8005
+ const alignmentPath = external_path_namespaceObject.join(aicoDocsDir, `ALIGNMENT_${input.feature_name}.md`);
8006
+ const consensusPath = external_path_namespaceObject.join(aicoDocsDir, `CONSENSUS_${input.feature_name}.md`);
8007
+ external_fs_namespaceObject.writeFileSync(alignmentPath, alignmentDoc);
8008
+ external_fs_namespaceObject.writeFileSync(consensusPath, consensusDoc);
8009
+ logger_logger.info("\u9700\u6C42\u5BF9\u9F50\u6587\u6863\u5DF2\u4FDD\u5B58", {
8010
+ alignmentPath,
8011
+ consensusPath
8012
+ });
8013
+ const result = {
8014
+ stage: "align",
8015
+ requirements_specification: alignmentDoc,
8016
+ consensus_document: consensusDoc,
8017
+ clarification_questions: requirementAnalysis.clarifications,
8018
+ boundary_definition: requirementAnalysis.boundaries,
8019
+ acceptance_criteria: requirementAnalysis.acceptanceCriteria,
8020
+ human_confirmation_required: true
8021
+ };
8022
+ logger_logger.info("\u9700\u6C42\u5BF9\u9F50\u667A\u80FD\u4F53\u6267\u884C\u5B8C\u6210", {
8023
+ featureName: input.feature_name
8024
+ });
8025
+ return result;
8026
+ } catch (error) {
8027
+ logger_logger.error("\u9700\u6C42\u5BF9\u9F50\u667A\u80FD\u4F53\u6267\u884C\u5931\u8D25", error);
8028
+ throw new RequirementHandlerError(`\u{9700}\u{6C42}\u{5BF9}\u{9F50}\u{9636}\u{6BB5}\u{5931}\u{8D25}: ${error.message}`, types_StageErrorCodes.ALIGN_CONSENSUS_FAILED, 'align', {
8029
+ input,
8030
+ error: error.message
8031
+ });
8032
+ }
8033
+ }
8034
+ async analyzeProjectContext(projectContext) {
8035
+ const prompt = `
8036
+ \u{4F5C}\u{4E3A}\u{9700}\u{6C42}\u{5BF9}\u{9F50}\u{667A}\u{80FD}\u{4F53}\u{FF0C}\u{8BF7}\u{5206}\u{6790}\u{4EE5}\u{4E0B}\u{9879}\u{76EE}\u{4E0A}\u{4E0B}\u{6587}\u{4FE1}\u{606F}\u{FF1A}
8037
+
8038
+ \u{9879}\u{76EE}\u{4E0A}\u{4E0B}\u{6587}\u{FF1A}
8039
+ ${projectContext || "\u672A\u63D0\u4F9B\u9879\u76EE\u4E0A\u4E0B\u6587\u4FE1\u606F"}
8040
+
8041
+ \u{8BF7}\u{5206}\u{6790}\u{FF1A}
8042
+ 1. \u{73B0}\u{6709}\u{9879}\u{76EE}\u{6280}\u{672F}\u{6808}
8043
+ 2. \u{67B6}\u{6784}\u{6A21}\u{5F0F}\u{548C}\u{7EA6}\u{675F}
8044
+ 3. \u{4E1A}\u{52A1}\u{57DF}\u{7279}\u{5F81}
8045
+ 4. \u{6280}\u{672F}\u{9650}\u{5236}\u{548C}\u{4F9D}\u{8D56}
8046
+
8047
+ \u{8F93}\u{51FA}\u{683C}\u{5F0F}\u{4E3A}JSON\u{FF1A}
8048
+ {
8049
+ "techStack": ["\u{6280}\u{672F}1", "\u{6280}\u{672F}2"],
8050
+ "architecture": "\u{67B6}\u{6784}\u{6A21}\u{5F0F}\u{63CF}\u{8FF0}",
8051
+ "businessDomain": "\u{4E1A}\u{52A1}\u{57DF}\u{63CF}\u{8FF0}",
8052
+ "constraints": ["\u{7EA6}\u{675F}1", "\u{7EA6}\u{675F}2"]
8053
+ }
8054
+ `;
8055
+ try {
8056
+ const response = await callOpenAI([
8057
+ {
8058
+ role: 'system',
8059
+ content: "\u4F60\u662F\u9879\u76EE\u4E0A\u4E0B\u6587\u5206\u6790\u4E13\u5BB6\uFF0C\u4E13\u6CE8\u4E8E\u7406\u89E3\u6280\u672F\u73AF\u5883\u548C\u4E1A\u52A1\u7EA6\u675F\u3002"
8060
+ },
8061
+ {
8062
+ role: 'user',
8063
+ content: prompt
8064
+ }
8065
+ ]);
8066
+ return JSON.parse(response);
8067
+ } catch (error) {
8068
+ logger_logger.warn("\u9879\u76EE\u4E0A\u4E0B\u6587\u5206\u6790\u5931\u8D25\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u5206\u6790", error);
8069
+ return {
8070
+ techStack: [
8071
+ "Node.js",
8072
+ "TypeScript"
8073
+ ],
8074
+ architecture: "\u6A21\u5757\u5316\u67B6\u6784",
8075
+ businessDomain: "\u901A\u7528\u4E1A\u52A1\u7CFB\u7EDF",
8076
+ constraints: []
8077
+ };
8078
+ }
8079
+ }
8080
+ async analyzeRequirement(requirementText, projectAnalysis) {
8081
+ const prompt = `
8082
+ \u{4F5C}\u{4E3A}\u{9700}\u{6C42}\u{5BF9}\u{9F50}\u{667A}\u{80FD}\u{4F53}\u{FF0C}\u{8BF7}\u{6DF1}\u{5EA6}\u{5206}\u{6790}\u{4EE5}\u{4E0B}\u{7528}\u{6237}\u{9700}\u{6C42}\u{FF1A}
8083
+
8084
+ \u{7528}\u{6237}\u{9700}\u{6C42}\u{FF1A}
8085
+ ${requirementText}
8086
+
8087
+ \u{9879}\u{76EE}\u{4E0A}\u{4E0B}\u{6587}\u{FF1A}
8088
+ ${JSON.stringify(projectAnalysis, null, 2)}
8089
+
8090
+ \u{8BF7}\u{8FDB}\u{884C}\u{5168}\u{9762}\u{7684}\u{9700}\u{6C42}\u{5206}\u{6790}\u{FF1A}
8091
+
8092
+ 1. \u{9700}\u{6C42}\u{7406}\u{89E3}\u{786E}\u{8BA4}
8093
+ - \u{6838}\u{5FC3}\u{529F}\u{80FD}\u{63CF}\u{8FF0}
8094
+ - \u{4E1A}\u{52A1}\u{4EF7}\u{503C}\u{5206}\u{6790}
8095
+ - \u{7528}\u{6237}\u{573A}\u{666F}\u{8BC6}\u{522B}
8096
+
8097
+ 2. \u{8FB9}\u{754C}\u{786E}\u{8BA4}
8098
+ - \u{529F}\u{80FD}\u{8303}\u{56F4}\u{754C}\u{5B9A}
8099
+ - \u{4E0D}\u{5305}\u{542B}\u{7684}\u{529F}\u{80FD}
8100
+ - \u{4F9D}\u{8D56}\u{5173}\u{7CFB}
8101
+
8102
+ 3. \u{6280}\u{672F}\u{65B9}\u{6848}\u{521D}\u{6B65}\u{8BC4}\u{4F30}
8103
+ - \u{63A8}\u{8350}\u{6280}\u{672F}\u{8DEF}\u{5F84}
8104
+ - \u{67B6}\u{6784}\u{517C}\u{5BB9}\u{6027}
8105
+ - \u{5B9E}\u{73B0}\u{590D}\u{6742}\u{5EA6}
8106
+
8107
+ 4. \u{6F84}\u{6E05}\u{95EE}\u{9898}\u{8BC6}\u{522B}
8108
+ - \u{9700}\u{8981}\u{660E}\u{786E}\u{7684}\u{6B67}\u{4E49}\u{70B9}
8109
+ - \u{6280}\u{672F}\u{9009}\u{578B}\u{7591}\u{95EE}
8110
+ - \u{4E1A}\u{52A1}\u{903B}\u{8F91}\u{5F85}\u{786E}\u{8BA4}
8111
+
8112
+ 5. \u{9A8C}\u{6536}\u{6807}\u{51C6}\u{5B9A}\u{4E49}
8113
+ - \u{529F}\u{80FD}\u{9A8C}\u{6536}\u{70B9}
8114
+ - \u{6027}\u{80FD}\u{6307}\u{6807}
8115
+ - \u{8D28}\u{91CF}\u{6807}\u{51C6}
8116
+
8117
+ \u{8F93}\u{51FA}\u{683C}\u{5F0F}\u{4E3A}JSON\u{FF1A}
8118
+ {
8119
+ "coreFunction": "\u{6838}\u{5FC3}\u{529F}\u{80FD}\u{63CF}\u{8FF0}",
8120
+ "businessValue": "\u{4E1A}\u{52A1}\u{4EF7}\u{503C}",
8121
+ "userScenarios": ["\u{573A}\u{666F}1", "\u{573A}\u{666F}2"],
8122
+ "boundaries": "\u{529F}\u{80FD}\u{8FB9}\u{754C}\u{63CF}\u{8FF0}",
8123
+ "exclusions": ["\u{4E0D}\u{5305}\u{542B}1", "\u{4E0D}\u{5305}\u{542B}2"],
8124
+ "techApproach": "\u{6280}\u{672F}\u{65B9}\u{6848}\u{63CF}\u{8FF0}",
8125
+ "complexity": "\u{7B80}\u{5355}|\u{4E2D}\u{7B49}|\u{590D}\u{6742}",
8126
+ "clarifications": ["\u{6F84}\u{6E05}\u{95EE}\u{9898}1", "\u{6F84}\u{6E05}\u{95EE}\u{9898}2"],
8127
+ "acceptanceCriteria": ["\u{9A8C}\u{6536}\u{6807}\u{51C6}1", "\u{9A8C}\u{6536}\u{6807}\u{51C6}2"]
8128
+ }
8129
+ `;
8130
+ const response = await callOpenAI([
8131
+ {
8132
+ role: 'system',
8133
+ content: "\u4F60\u662F\u9700\u6C42\u5206\u6790\u4E13\u5BB6\uFF0C\u4E13\u6CE8\u4E8E\u5C06\u6A21\u7CCA\u9700\u6C42\u8F6C\u5316\u4E3A\u7CBE\u786E\u7684\u6280\u672F\u89C4\u8303\u3002"
8134
+ },
8135
+ {
8136
+ role: 'user',
8137
+ content: prompt
8138
+ }
8139
+ ]);
8140
+ return JSON.parse(response);
8141
+ }
8142
+ async generateAlignmentDocument(analysis, featureName) {
8143
+ return `# \u{9700}\u{6C42}\u{5BF9}\u{9F50}\u{6587}\u{6863} - ${featureName}
8144
+
8145
+ ## \u{9879}\u{76EE}\u{7279}\u{6027}\u{89C4}\u{8303}
8146
+
8147
+ ### \u{6838}\u{5FC3}\u{529F}\u{80FD}
8148
+ ${analysis.coreFunction}
8149
+
8150
+ ### \u{4E1A}\u{52A1}\u{4EF7}\u{503C}
8151
+ ${analysis.businessValue}
8152
+
8153
+ ### \u{7528}\u{6237}\u{573A}\u{666F}
8154
+ ${analysis.userScenarios.map((scenario, index)=>`${index + 1}. ${scenario}`).join('\n')}
8155
+
8156
+ ## \u{9700}\u{6C42}\u{7406}\u{89E3}
8157
+
8158
+ ### \u{529F}\u{80FD}\u{8FB9}\u{754C}
8159
+ ${analysis.boundaries}
8160
+
8161
+ ### \u{6392}\u{9664}\u{529F}\u{80FD}
8162
+ ${analysis.exclusions.map((exclusion)=>`- ${exclusion}`).join('\n')}
8163
+
8164
+ ### \u{6280}\u{672F}\u{65B9}\u{6848}
8165
+ ${analysis.techApproach}
8166
+
8167
+ ### \u{590D}\u{6742}\u{5EA6}\u{8BC4}\u{4F30}
8168
+ ${analysis.complexity}
8169
+
8170
+ ## \u{7591}\u{95EE}\u{6F84}\u{6E05}
8171
+
8172
+ ${analysis.clarifications.map((question, index)=>`### \u{95EE}\u{9898} ${index + 1}
8173
+ ${question}
8174
+
8175
+ **\u{5EFA}\u{8BAE}\u{89E3}\u{51B3}\u{65B9}\u{6848}**: \u{57FA}\u{4E8E}\u{884C}\u{4E1A}\u{6700}\u{4F73}\u{5B9E}\u{8DF5}\u{548C}\u{9879}\u{76EE}\u{73B0}\u{72B6}\u{8FDB}\u{884C}\u{51B3}\u{7B56}
8176
+
8177
+ `).join('\n')}
8178
+
8179
+ ## \u{751F}\u{6210}\u{65F6}\u{95F4}
8180
+ ${new Date().toISOString()}
8181
+ `;
8182
+ }
8183
+ async generateConsensusDocument(analysis, featureName) {
8184
+ return `# \u{9700}\u{6C42}\u{5171}\u{8BC6}\u{6587}\u{6863} - ${featureName}
8185
+
8186
+ ## \u{660E}\u{786E}\u{7684}\u{9700}\u{6C42}\u{63CF}\u{8FF0}
8187
+ ${analysis.coreFunction}
8188
+
8189
+ ## \u{9A8C}\u{6536}\u{6807}\u{51C6}
8190
+ ${analysis.acceptanceCriteria.map((criteria, index)=>`${index + 1}. ${criteria}`).join('\n')}
8191
+
8192
+ ## \u{6280}\u{672F}\u{5B9E}\u{73B0}\u{65B9}\u{6848}
8193
+ ${analysis.techApproach}
8194
+
8195
+ ## \u{6280}\u{672F}\u{7EA6}\u{675F}\u{548C}\u{96C6}\u{6210}\u{65B9}\u{6848}
8196
+ - \u{590D}\u{6742}\u{5EA6}: ${analysis.complexity}
8197
+ - \u{9700}\u{8981}\u{8003}\u{8651}\u{73B0}\u{6709}\u{7CFB}\u{7EDF}\u{517C}\u{5BB9}\u{6027}
8198
+ - \u{9075}\u{5FAA}\u{9879}\u{76EE}\u{73B0}\u{6709}\u{67B6}\u{6784}\u{6A21}\u{5F0F}
8199
+
8200
+ ## \u{4EFB}\u{52A1}\u{8FB9}\u{754C}\u{9650}\u{5236}
8201
+ ### \u{5305}\u{542B}\u{8303}\u{56F4}
8202
+ ${analysis.boundaries}
8203
+
8204
+ ### \u{6392}\u{9664}\u{8303}\u{56F4}
8205
+ ${analysis.exclusions.map((exclusion)=>`- ${exclusion}`).join('\n')}
8206
+
8207
+ ## \u{786E}\u{8BA4}\u{72B6}\u{6001}
8208
+ - [x] \u{9700}\u{6C42}\u{7406}\u{89E3}\u{51C6}\u{786E}\u{65E0}\u{8BEF}
8209
+ - [x] \u{6280}\u{672F}\u{65B9}\u{6848}\u{53EF}\u{884C}
8210
+ - [x] \u{8FB9}\u{754C}\u{5B9A}\u{4E49}\u{5408}\u{7406}
8211
+ - [x] \u{9A8C}\u{6536}\u{6807}\u{51C6}\u{660E}\u{786E}
8212
+ - [ ] \u{7B49}\u{5F85}\u{4EBA}\u{5DE5}\u{786E}\u{8BA4}
8213
+
8214
+ ## \u{751F}\u{6210}\u{65F6}\u{95F4}
8215
+ ${new Date().toISOString()}
8216
+ `;
8217
+ }
8218
+ }
8219
+ class ArchitectAgent {
8220
+ async execute(input) {
8221
+ logger_logger.info("\u7CFB\u7EDF\u67B6\u6784\u667A\u80FD\u4F53\u5F00\u59CB\u6267\u884C");
8222
+ try {
8223
+ const alignmentResult = input.previous_stage_output;
8224
+ if ('align' !== alignmentResult.stage) throw new Error("\u671F\u671B\u83B7\u5F97\u5BF9\u9F50\u9636\u6BB5\u7684\u8F93\u51FA");
8225
+ const architectureDesign = await this.designSystemArchitecture(alignmentResult);
8226
+ const moduleDesign = await this.designModules(architectureDesign);
8227
+ const designDoc = await this.generateDesignDocument(architectureDesign, moduleDesign);
8228
+ const featureName = this.extractFeatureName(input.workspace_dir);
8229
+ const projectRoot = process.cwd();
8230
+ const aicoDocsDir = external_path_namespaceObject.join(projectRoot, '.aico', 'docs', featureName);
8231
+ if (!external_fs_namespaceObject.existsSync(aicoDocsDir)) external_fs_namespaceObject.mkdirSync(aicoDocsDir, {
8232
+ recursive: true
8233
+ });
8234
+ const designPath = external_path_namespaceObject.join(aicoDocsDir, `DESIGN_${featureName}.md`);
8235
+ external_fs_namespaceObject.writeFileSync(designPath, designDoc);
8236
+ logger_logger.info("\u7CFB\u7EDF\u8BBE\u8BA1\u6587\u6863\u5DF2\u4FDD\u5B58", {
8237
+ designPath
8238
+ });
8239
+ const result = {
8240
+ stage: "architect",
8241
+ system_architecture: architectureDesign.overview,
8242
+ module_design: moduleDesign.modules,
8243
+ interface_specifications: moduleDesign.interfaces,
8244
+ data_flow_diagram: architectureDesign.dataFlow,
8245
+ component_dependencies: architectureDesign.dependencies,
8246
+ human_confirmation_required: true
8247
+ };
8248
+ logger_logger.info("\u7CFB\u7EDF\u67B6\u6784\u667A\u80FD\u4F53\u6267\u884C\u5B8C\u6210");
8249
+ return result;
8250
+ } catch (error) {
8251
+ logger_logger.error("\u7CFB\u7EDF\u67B6\u6784\u667A\u80FD\u4F53\u6267\u884C\u5931\u8D25", error);
8252
+ throw new RequirementHandlerError(`\u{7CFB}\u{7EDF}\u{67B6}\u{6784}\u{8BBE}\u{8BA1}\u{9636}\u{6BB5}\u{5931}\u{8D25}: ${error.message}`, types_StageErrorCodes.ARCHITECT_DESIGN_FAILED, 'architect', {
8253
+ input,
8254
+ error: error.message
8255
+ });
8256
+ }
8257
+ }
8258
+ async designSystemArchitecture(alignmentResult) {
8259
+ const prompt = `
8260
+ \u{4F5C}\u{4E3A}\u{7CFB}\u{7EDF}\u{67B6}\u{6784}\u{667A}\u{80FD}\u{4F53}\u{FF0C}\u{57FA}\u{4E8E}\u{4EE5}\u{4E0B}\u{9700}\u{6C42}\u{5171}\u{8BC6}\u{8BBE}\u{8BA1}\u{7CFB}\u{7EDF}\u{67B6}\u{6784}\u{FF1A}
8261
+
8262
+ \u{9700}\u{6C42}\u{5171}\u{8BC6}\u{FF1A}
8263
+ ${alignmentResult.consensus_document}
8264
+
8265
+ \u{9700}\u{6C42}\u{89C4}\u{8303}\u{FF1A}
8266
+ ${alignmentResult.requirements_specification}
8267
+
8268
+ \u{8BF7}\u{8BBE}\u{8BA1}\u{7CFB}\u{7EDF}\u{67B6}\u{6784}\u{FF0C}\u{5305}\u{62EC}\u{FF1A}
8269
+
8270
+ 1. \u{6574}\u{4F53}\u{67B6}\u{6784}\u{56FE}(\u{4F7F}\u{7528}mermaid\u{8BED}\u{6CD5})
8271
+ 2. \u{5206}\u{5C42}\u{8BBE}\u{8BA1}\u{548C}\u{6838}\u{5FC3}\u{7EC4}\u{4EF6}
8272
+ 3. \u{6A21}\u{5757}\u{4F9D}\u{8D56}\u{5173}\u{7CFB}\u{56FE}(\u{4F7F}\u{7528}mermaid\u{8BED}\u{6CD5})
8273
+ 4. \u{6570}\u{636E}\u{6D41}\u{5411}\u{56FE}(\u{4F7F}\u{7528}mermaid\u{8BED}\u{6CD5})
8274
+ 5. \u{5F02}\u{5E38}\u{5904}\u{7406}\u{7B56}\u{7565}
8275
+
8276
+ \u{8981}\u{6C42}\u{FF1A}
8277
+ - \u{786E}\u{4FDD}\u{4E0E}\u{73B0}\u{6709}\u{7CFB}\u{7EDF}\u{67B6}\u{6784}\u{4E00}\u{81F4}
8278
+ - \u{590D}\u{7528}\u{73B0}\u{6709}\u{7EC4}\u{4EF6}\u{548C}\u{6A21}\u{5F0F}
8279
+ - \u{907F}\u{514D}\u{8FC7}\u{5EA6}\u{8BBE}\u{8BA1}
8280
+ - \u{8003}\u{8651}\u{53EF}\u{7EF4}\u{62A4}\u{6027}\u{548C}\u{6269}\u{5C55}\u{6027}
8281
+
8282
+ \u{8F93}\u{51FA}\u{683C}\u{5F0F}\u{4E3A}JSON\u{FF1A}
8283
+ {
8284
+ "overview": "\u{6574}\u{4F53}\u{67B6}\u{6784}\u{63CF}\u{8FF0}",
8285
+ "architectureDiagram": "mermaid\u{67B6}\u{6784}\u{56FE}\u{4EE3}\u{7801}",
8286
+ "layers": ["\u{5C42}\u{6B21}1", "\u{5C42}\u{6B21}2"],
8287
+ "coreComponents": ["\u{7EC4}\u{4EF6}1", "\u{7EC4}\u{4EF6}2"],
8288
+ "dependencyDiagram": "mermaid\u{4F9D}\u{8D56}\u{5173}\u{7CFB}\u{56FE}\u{4EE3}\u{7801}",
8289
+ "dataFlow": "\u{6570}\u{636E}\u{6D41}\u{5411}\u{63CF}\u{8FF0}",
8290
+ "dataFlowDiagram": "mermaid\u{6570}\u{636E}\u{6D41}\u{56FE}\u{4EE3}\u{7801}",
8291
+ "exceptionHandling": "\u{5F02}\u{5E38}\u{5904}\u{7406}\u{7B56}\u{7565}",
8292
+ "dependencies": "\u{4F9D}\u{8D56}\u{5173}\u{7CFB}\u{63CF}\u{8FF0}"
8293
+ }
8294
+ `;
8295
+ const response = await callOpenAI([
8296
+ {
8297
+ role: 'system',
8298
+ content: "\u4F60\u662F\u7CFB\u7EDF\u67B6\u6784\u8BBE\u8BA1\u4E13\u5BB6\uFF0C\u4E13\u6CE8\u4E8E\u8BBE\u8BA1\u53EF\u7EF4\u62A4\u3001\u53EF\u6269\u5C55\u7684\u7CFB\u7EDF\u67B6\u6784\u3002"
8299
+ },
8300
+ {
8301
+ role: 'user',
8302
+ content: prompt
8303
+ }
8304
+ ]);
8305
+ return JSON.parse(response);
8306
+ }
8307
+ async designModules(architectureDesign) {
8308
+ const prompt = `
8309
+ \u{57FA}\u{4E8E}\u{4EE5}\u{4E0B}\u{7CFB}\u{7EDF}\u{67B6}\u{6784}\u{8BBE}\u{8BA1}\u{FF0C}\u{8BE6}\u{7EC6}\u{8BBE}\u{8BA1}\u{6A21}\u{5757}\u{548C}\u{63A5}\u{53E3}\u{FF1A}
8310
+
8311
+ \u{7CFB}\u{7EDF}\u{67B6}\u{6784}\u{FF1A}
8312
+ ${JSON.stringify(architectureDesign, null, 2)}
8313
+
8314
+ \u{8BF7}\u{8BBE}\u{8BA1}\u{FF1A}
8315
+
8316
+ 1. \u{8BE6}\u{7EC6}\u{7684}\u{6A21}\u{5757}\u{5212}\u{5206}
8317
+ 2. \u{6BCF}\u{4E2A}\u{6A21}\u{5757}\u{7684}\u{804C}\u{8D23}
8318
+ 3. \u{6A21}\u{5757}\u{95F4}\u{7684}\u{63A5}\u{53E3}\u{5B9A}\u{4E49}
8319
+ 4. \u{6570}\u{636E}\u{4F20}\u{8F93}\u{534F}\u{8BAE}
8320
+ 5. API\u{89C4}\u{8303}
8321
+
8322
+ \u{8F93}\u{51FA}\u{683C}\u{5F0F}\u{4E3A}JSON\u{FF1A}
8323
+ {
8324
+ "modules": [
8325
+ {
8326
+ "name": "\u{6A21}\u{5757}\u{540D}",
8327
+ "responsibility": "\u{6A21}\u{5757}\u{804C}\u{8D23}",
8328
+ "interfaces": ["\u{63A5}\u{53E3}1", "\u{63A5}\u{53E3}2"],
8329
+ "dependencies": ["\u{4F9D}\u{8D56}\u{6A21}\u{5757}1"]
8330
+ }
8331
+ ],
8332
+ "interfaces": [
8333
+ {
8334
+ "name": "\u{63A5}\u{53E3}\u{540D}",
8335
+ "type": "\u{8F93}\u{5165}|\u{8F93}\u{51FA}|\u{53CC}\u{5411}",
8336
+ "format": "\u{6570}\u{636E}\u{683C}\u{5F0F}",
8337
+ "specification": "\u{8BE6}\u{7EC6}\u{89C4}\u{8303}"
8338
+ }
8339
+ ],
8340
+ "dataProtocols": "\u{6570}\u{636E}\u{4F20}\u{8F93}\u{534F}\u{8BAE}\u{63CF}\u{8FF0}",
8341
+ "apiSpecification": "API\u{89C4}\u{8303}\u{63CF}\u{8FF0}"
8342
+ }
8343
+ `;
8344
+ const response = await callOpenAI([
8345
+ {
8346
+ role: 'system',
8347
+ content: "\u4F60\u662F\u6A21\u5757\u8BBE\u8BA1\u4E13\u5BB6\uFF0C\u4E13\u6CE8\u4E8E\u8BBE\u8BA1\u6E05\u6670\u7684\u6A21\u5757\u8FB9\u754C\u548C\u63A5\u53E3\u3002"
8348
+ },
8349
+ {
8350
+ role: 'user',
8351
+ content: prompt
8352
+ }
8353
+ ]);
8354
+ return JSON.parse(response);
8355
+ }
8356
+ async generateDesignDocument(architectureDesign, moduleDesign) {
8357
+ return `# \u{7CFB}\u{7EDF}\u{8BBE}\u{8BA1}\u{6587}\u{6863}
8358
+
8359
+ ## \u{6574}\u{4F53}\u{67B6}\u{6784}
8360
+
8361
+ ### \u{67B6}\u{6784}\u{6982}\u{8FF0}
8362
+ ${architectureDesign.overview}
8363
+
8364
+ ### \u{67B6}\u{6784}\u{56FE}
8365
+ \`\`\`mermaid
8366
+ ${architectureDesign.architectureDiagram}
8367
+ \`\`\`
8368
+
8369
+ ### \u{5206}\u{5C42}\u{8BBE}\u{8BA1}
8370
+ ${architectureDesign.layers.map((layer, index)=>`${index + 1}. ${layer}`).join('\n')}
8371
+
8372
+ ### \u{6838}\u{5FC3}\u{7EC4}\u{4EF6}
8373
+ ${architectureDesign.coreComponents.map((component)=>`- ${component}`).join('\n')}
8374
+
8375
+ ## \u{6A21}\u{5757}\u{8BBE}\u{8BA1}
8376
+
8377
+ ${moduleDesign.modules.map((module)=>`### ${module.name}
8378
+ **\u{804C}\u{8D23}**: ${module.responsibility}
8379
+ **\u{63A5}\u{53E3}**: ${module.interfaces.join(', ')}
8380
+ **\u{4F9D}\u{8D56}**: ${module.dependencies.join(', ')}
8381
+ `).join('\n')}
8382
+
8383
+ ## \u{63A5}\u{53E3}\u{89C4}\u{8303}
8384
+
8385
+ ${moduleDesign.interfaces.map((interfaceItem)=>`### ${interfaceItem.name}
8386
+ - **\u{7C7B}\u{578B}**: ${interfaceItem.type}
8387
+ - **\u{683C}\u{5F0F}**: ${interfaceItem.format}
8388
+ - **\u{89C4}\u{8303}**: ${interfaceItem.specification}
8389
+ `).join('\n')}
8390
+
8391
+ ## \u{4F9D}\u{8D56}\u{5173}\u{7CFB}
8392
+
8393
+ ### \u{6A21}\u{5757}\u{4F9D}\u{8D56}\u{56FE}
8394
+ \`\`\`mermaid
8395
+ ${architectureDesign.dependencyDiagram}
8396
+ \`\`\`
8397
+
8398
+ ### \u{4F9D}\u{8D56}\u{8BF4}\u{660E}
8399
+ ${architectureDesign.dependencies}
8400
+
8401
+ ## \u{6570}\u{636E}\u{6D41}\u{5411}
8402
+
8403
+ ### \u{6570}\u{636E}\u{6D41}\u{56FE}
8404
+ \`\`\`mermaid
8405
+ ${architectureDesign.dataFlowDiagram}
8406
+ \`\`\`
8407
+
8408
+ ### \u{6570}\u{636E}\u{6D41}\u{8BF4}\u{660E}
8409
+ ${architectureDesign.dataFlow}
8410
+
8411
+ ## \u{5F02}\u{5E38}\u{5904}\u{7406}\u{7B56}\u{7565}
8412
+ ${architectureDesign.exceptionHandling}
8413
+
8414
+ ## \u{6570}\u{636E}\u{4F20}\u{8F93}\u{534F}\u{8BAE}
8415
+ ${moduleDesign.dataProtocols}
8416
+
8417
+ ## API\u{89C4}\u{8303}
8418
+ ${moduleDesign.apiSpecification}
8419
+
8420
+ ## \u{751F}\u{6210}\u{65F6}\u{95F4}
8421
+ ${new Date().toISOString()}
8422
+ `;
8423
+ }
8424
+ extractFeatureName(workspaceDir) {
8425
+ return external_path_namespaceObject.basename(workspaceDir);
8426
+ }
8427
+ }
8428
+ class AtomizeAgent {
8429
+ async execute(input) {
8430
+ logger_logger.info("\u4EFB\u52A1\u62C6\u5206\u667A\u80FD\u4F53\u5F00\u59CB\u6267\u884C");
8431
+ try {
8432
+ const architectureResult = input.previous_stage_output;
8433
+ if ('architect' !== architectureResult.stage) throw new Error("\u671F\u671B\u83B7\u5F97\u67B6\u6784\u9636\u6BB5\u7684\u8F93\u51FA");
8434
+ const taskDecomposition = await this.decomposeToAtomicTasks(architectureResult);
8435
+ const dependencyAnalysis = await this.analyzeDependencies(taskDecomposition);
8436
+ const complexityAssessment = await this.assessComplexity(taskDecomposition);
8437
+ const taskDoc = await this.generateTaskDocument(taskDecomposition, dependencyAnalysis, complexityAssessment);
8438
+ const featureName = this.extractFeatureName(input.workspace_dir);
8439
+ const projectRoot = process.cwd();
8440
+ const aicoDocsDir = external_path_namespaceObject.join(projectRoot, '.aico', 'docs', featureName);
8441
+ if (!external_fs_namespaceObject.existsSync(aicoDocsDir)) external_fs_namespaceObject.mkdirSync(aicoDocsDir, {
8442
+ recursive: true
8443
+ });
8444
+ const taskPath = external_path_namespaceObject.join(aicoDocsDir, `TASK_${featureName}.md`);
8445
+ external_fs_namespaceObject.writeFileSync(taskPath, taskDoc);
8446
+ logger_logger.info("\u4EFB\u52A1\u62C6\u5206\u6587\u6863\u5DF2\u4FDD\u5B58", {
8447
+ taskPath
8448
+ });
8449
+ const result = {
8450
+ stage: "atomize",
8451
+ atomic_tasks: taskDecomposition.tasks,
8452
+ task_dependency_graph: dependencyAnalysis.dependencyGraph,
8453
+ complexity_assessment: complexityAssessment.summary,
8454
+ human_confirmation_required: true
8455
+ };
8456
+ logger_logger.info("\u4EFB\u52A1\u62C6\u5206\u667A\u80FD\u4F53\u6267\u884C\u5B8C\u6210");
8457
+ return result;
8458
+ } catch (error) {
8459
+ logger_logger.error("\u4EFB\u52A1\u62C6\u5206\u667A\u80FD\u4F53\u6267\u884C\u5931\u8D25", error);
8460
+ throw new RequirementHandlerError(`\u{4EFB}\u{52A1}\u{62C6}\u{5206}\u{9636}\u{6BB5}\u{5931}\u{8D25}: ${error.message}`, types_StageErrorCodes.ATOMIZE_TASK_DECOMPOSITION_FAILED, 'atomize', {
8461
+ input,
8462
+ error: error.message
8463
+ });
8464
+ }
8465
+ }
8466
+ async decomposeToAtomicTasks(architectureResult) {
8467
+ const prompt = `
8468
+ \u{4F5C}\u{4E3A}\u{4EFB}\u{52A1}\u{62C6}\u{5206}\u{667A}\u{80FD}\u{4F53}\u{FF0C}\u{57FA}\u{4E8E}\u{4EE5}\u{4E0B}\u{7CFB}\u{7EDF}\u{67B6}\u{6784}\u{8BBE}\u{8BA1}\u{FF0C}\u{5C06}\u{5176}\u{5206}\u{89E3}\u{4E3A}\u{539F}\u{5B50}\u{4EFB}\u{52A1}\u{FF1A}
8469
+
8470
+ \u{7CFB}\u{7EDF}\u{67B6}\u{6784}\u{FF1A}
8471
+ ${architectureResult.system_architecture}
8472
+
8473
+ \u{6A21}\u{5757}\u{8BBE}\u{8BA1}\u{FF1A}
8474
+ ${architectureResult.module_design}
8475
+
8476
+ \u{63A5}\u{53E3}\u{89C4}\u{8303}\u{FF1A}
8477
+ ${architectureResult.interface_specifications}
8478
+
8479
+ \u{8BF7}\u{5206}\u{89E3}\u{4EFB}\u{52A1}\u{FF0C}\u{786E}\u{4FDD}\u{FF1A}
8480
+
8481
+ 1. \u{6BCF}\u{4E2A}\u{4EFB}\u{52A1}\u{590D}\u{6742}\u{5EA6}\u{53EF}\u{63A7}\u{FF0C}\u{4FBF}\u{4E8E}AI\u{9AD8}\u{6210}\u{529F}\u{7387}\u{4EA4}\u{4ED8}
8482
+ 2. \u{6309}\u{529F}\u{80FD}\u{6A21}\u{5757}\u{5206}\u{89E3}\u{FF0C}\u{786E}\u{4FDD}\u{4EFB}\u{52A1}\u{539F}\u{5B50}\u{6027}\u{548C}\u{72EC}\u{7ACB}\u{6027}
8483
+ 3. \u{6709}\u{660E}\u{786E}\u{7684}\u{9A8C}\u{6536}\u{6807}\u{51C6}\u{FF0C}\u{5C3D}\u{91CF}\u{53EF}\u{4EE5}\u{72EC}\u{7ACB}\u{7F16}\u{8BD1}\u{548C}\u{6D4B}\u{8BD5}
8484
+ 4. \u{4F9D}\u{8D56}\u{5173}\u{7CFB}\u{6E05}\u{6670}
8485
+
8486
+ \u{6BCF}\u{4E2A}\u{539F}\u{5B50}\u{4EFB}\u{52A1}\u{5305}\u{542B}\u{FF1A}
8487
+ - \u{8F93}\u{5165}\u{5951}\u{7EA6}(\u{524D}\u{7F6E}\u{4F9D}\u{8D56}\u{3001}\u{8F93}\u{5165}\u{6570}\u{636E}\u{3001}\u{73AF}\u{5883}\u{4F9D}\u{8D56})
8488
+ - \u{8F93}\u{51FA}\u{5951}\u{7EA6}(\u{8F93}\u{51FA}\u{6570}\u{636E}\u{3001}\u{4EA4}\u{4ED8}\u{7269}\u{3001}\u{9A8C}\u{6536}\u{6807}\u{51C6})
8489
+ - \u{5B9E}\u{73B0}\u{7EA6}\u{675F}(\u{6280}\u{672F}\u{6808}\u{3001}\u{63A5}\u{53E3}\u{89C4}\u{8303}\u{3001}\u{8D28}\u{91CF}\u{8981}\u{6C42})
8490
+ - \u{4F9D}\u{8D56}\u{5173}\u{7CFB}(\u{540E}\u{7F6E}\u{4EFB}\u{52A1}\u{3001}\u{5E76}\u{884C}\u{4EFB}\u{52A1})
8491
+
8492
+ \u{8F93}\u{51FA}\u{683C}\u{5F0F}\u{4E3A}JSON\u{FF1A}
8493
+ {
8494
+ "tasks": [
8495
+ {
8496
+ "id": "TASK_001",
8497
+ "name": "\u{4EFB}\u{52A1}\u{540D}\u{79F0}",
8498
+ "description": "\u{8BE6}\u{7EC6}\u{63CF}\u{8FF0}",
8499
+ "input_contract": "\u{8F93}\u{5165}\u{5951}\u{7EA6}\u{63CF}\u{8FF0}",
8500
+ "output_contract": "\u{8F93}\u{51FA}\u{5951}\u{7EA6}\u{63CF}\u{8FF0}",
8501
+ "implementation_constraints": "\u{5B9E}\u{73B0}\u{7EA6}\u{675F}",
8502
+ "dependencies": ["TASK_002"],
8503
+ "acceptance_criteria": ["\u{9A8C}\u{6536}\u{6807}\u{51C6}1", "\u{9A8C}\u{6536}\u{6807}\u{51C6}2"],
8504
+ "complexity": "\u{7B80}\u{5355}|\u{4E2D}\u{7B49}|\u{590D}\u{6742}",
8505
+ "estimated_hours": 4
8506
+ }
8507
+ ],
8508
+ "total_tasks": 5,
8509
+ "estimated_duration": "\u{603B}\u{9884}\u{4F30}\u{65F6}\u{957F}"
8510
+ }
8511
+ `;
8512
+ const response = await callOpenAI([
8513
+ {
8514
+ role: 'system',
8515
+ content: "\u4F60\u662F\u4EFB\u52A1\u5206\u89E3\u4E13\u5BB6\uFF0C\u4E13\u6CE8\u4E8E\u5C06\u590D\u6742\u7CFB\u7EDF\u5206\u89E3\u4E3A\u53EF\u7BA1\u7406\u7684\u539F\u5B50\u4EFB\u52A1\u3002"
8516
+ },
8517
+ {
8518
+ role: 'user',
8519
+ content: prompt
8520
+ }
8521
+ ]);
8522
+ return JSON.parse(response);
8523
+ }
8524
+ async analyzeDependencies(taskDecomposition) {
8525
+ const prompt = `
8526
+ \u{57FA}\u{4E8E}\u{4EE5}\u{4E0B}\u{4EFB}\u{52A1}\u{5206}\u{89E3}\u{7ED3}\u{679C}\u{FF0C}\u{5206}\u{6790}\u{4EFB}\u{52A1}\u{95F4}\u{7684}\u{4F9D}\u{8D56}\u{5173}\u{7CFB}\u{FF1A}
8527
+
8528
+ \u{4EFB}\u{52A1}\u{5217}\u{8868}\u{FF1A}
8529
+ ${JSON.stringify(taskDecomposition.tasks, null, 2)}
8530
+
8531
+ \u{8BF7}\u{5206}\u{6790}\u{FF1A}
8532
+ 1. \u{4EFB}\u{52A1}\u{6267}\u{884C}\u{987A}\u{5E8F}
8533
+ 2. \u{5E76}\u{884C}\u{6267}\u{884C}\u{7684}\u{53EF}\u{80FD}\u{6027}
8534
+ 3. \u{5173}\u{952E}\u{8DEF}\u{5F84}\u{8BC6}\u{522B}
8535
+ 4. \u{4F9D}\u{8D56}\u{5173}\u{7CFB}\u{56FE}(mermaid\u{683C}\u{5F0F})
8536
+
8537
+ \u{786E}\u{4FDD}\u{FF1A}
8538
+ - \u{4F9D}\u{8D56}\u{5173}\u{7CFB}\u{65E0}\u{5FAA}\u{73AF}
8539
+ - \u{8BC6}\u{522B}\u{53EF}\u{5E76}\u{884C}\u{6267}\u{884C}\u{7684}\u{4EFB}\u{52A1}
8540
+ - \u{660E}\u{786E}\u{5173}\u{952E}\u{8DEF}\u{5F84}
8541
+
8542
+ \u{8F93}\u{51FA}\u{683C}\u{5F0F}\u{4E3A}JSON\u{FF1A}
8543
+ {
8544
+ "executionOrder": [
8545
+ {
8546
+ "phase": "\u{9636}\u{6BB5}1",
8547
+ "tasks": ["TASK_001", "TASK_002"],
8548
+ "canParallel": true
8549
+ }
8550
+ ],
8551
+ "dependencyGraph": "mermaid\u{4EE3}\u{7801}",
8552
+ "criticalPath": ["TASK_001", "TASK_003", "TASK_005"],
8553
+ "parallelGroups": [
8554
+ {
8555
+ "group": "\u{7EC4}1",
8556
+ "tasks": ["TASK_001", "TASK_002"]
8557
+ }
8558
+ ]
8559
+ }
8560
+ `;
8561
+ const response = await callOpenAI([
8562
+ {
8563
+ role: 'system',
8564
+ content: "\u4F60\u662F\u4F9D\u8D56\u5173\u7CFB\u5206\u6790\u4E13\u5BB6\uFF0C\u4E13\u6CE8\u4E8E\u4F18\u5316\u4EFB\u52A1\u6267\u884C\u987A\u5E8F\u3002"
8565
+ },
8566
+ {
8567
+ role: 'user',
8568
+ content: prompt
8569
+ }
8570
+ ]);
8571
+ return JSON.parse(response);
8572
+ }
8573
+ async assessComplexity(taskDecomposition) {
8574
+ const prompt = `
8575
+ \u{8BC4}\u{4F30}\u{4EE5}\u{4E0B}\u{4EFB}\u{52A1}\u{5206}\u{89E3}\u{7684}\u{590D}\u{6742}\u{5EA6}\u{FF1A}
8576
+
8577
+ \u{4EFB}\u{52A1}\u{5206}\u{89E3}\u{FF1A}
8578
+ ${JSON.stringify(taskDecomposition, null, 2)}
8579
+
8580
+ \u{8BF7}\u{8BC4}\u{4F30}\u{FF1A}
8581
+ 1. \u{6574}\u{4F53}\u{590D}\u{6742}\u{5EA6}
8582
+ 2. \u{5355}\u{4E2A}\u{4EFB}\u{52A1}\u{590D}\u{6742}\u{5EA6}\u{5408}\u{7406}\u{6027}
8583
+ 3. \u{98CE}\u{9669}\u{8BC6}\u{522B}
8584
+ 4. \u{5EFA}\u{8BAE}\u{4F18}\u{5316}
8585
+
8586
+ \u{8F93}\u{51FA}\u{683C}\u{5F0F}\u{4E3A}JSON\u{FF1A}
8587
+ {
8588
+ "overallComplexity": "\u{7B80}\u{5355}|\u{4E2D}\u{7B49}|\u{590D}\u{6742}",
8589
+ "taskComplexityDistribution": {
8590
+ "\u{7B80}\u{5355}": 3,
8591
+ "\u{4E2D}\u{7B49}": 2,
8592
+ "\u{590D}\u{6742}": 0
8593
+ },
8594
+ "riskAssessment": [
8595
+ {
8596
+ "risk": "\u{98CE}\u{9669}\u{63CF}\u{8FF0}",
8597
+ "level": "\u{9AD8}|\u{4E2D}|\u{4F4E}",
8598
+ "mitigation": "\u{7F13}\u{89E3}\u{63AA}\u{65BD}"
8599
+ }
8600
+ ],
8601
+ "optimizationSuggestions": ["\u{5EFA}\u{8BAE}1", "\u{5EFA}\u{8BAE}2"],
8602
+ "summary": "\u{590D}\u{6742}\u{5EA6}\u{8BC4}\u{4F30}\u{603B}\u{7ED3}"
8603
+ }
8604
+ `;
8605
+ const response = await callOpenAI([
8606
+ {
8607
+ role: 'system',
8608
+ content: "\u4F60\u662F\u590D\u6742\u5EA6\u8BC4\u4F30\u4E13\u5BB6\uFF0C\u4E13\u6CE8\u4E8E\u9879\u76EE\u98CE\u9669\u8BC4\u4F30\u548C\u4F18\u5316\u5EFA\u8BAE\u3002"
8609
+ },
8610
+ {
8611
+ role: 'user',
8612
+ content: prompt
8613
+ }
8614
+ ]);
8615
+ return JSON.parse(response);
8616
+ }
8617
+ async generateTaskDocument(taskDecomposition, dependencyAnalysis, complexityAssessment) {
8618
+ return `# \u{4EFB}\u{52A1}\u{62C6}\u{5206}\u{6587}\u{6863}
8619
+
8620
+ ## \u{4EFB}\u{52A1}\u{6982}\u{89C8}
8621
+
8622
+ - **\u{603B}\u{4EFB}\u{52A1}\u{6570}**: ${taskDecomposition.total_tasks}
8623
+ - **\u{9884}\u{4F30}\u{603B}\u{65F6}\u{957F}**: ${taskDecomposition.estimated_duration}
8624
+ - **\u{6574}\u{4F53}\u{590D}\u{6742}\u{5EA6}**: ${complexityAssessment.overallComplexity}
8625
+
8626
+ ## \u{539F}\u{5B50}\u{4EFB}\u{52A1}\u{5217}\u{8868}
8627
+
8628
+ ${taskDecomposition.tasks.map((task, index)=>`### ${task.id}: ${task.name}
8629
+
8630
+ **\u{63CF}\u{8FF0}**: ${task.description}
8631
+
8632
+ **\u{8F93}\u{5165}\u{5951}\u{7EA6}**:
8633
+ ${task.input_contract}
8634
+
8635
+ **\u{8F93}\u{51FA}\u{5951}\u{7EA6}**:
8636
+ ${task.output_contract}
8637
+
8638
+ **\u{5B9E}\u{73B0}\u{7EA6}\u{675F}**:
8639
+ ${task.implementation_constraints}
8640
+
8641
+ **\u{4F9D}\u{8D56}\u{5173}\u{7CFB}**: ${task.dependencies.length > 0 ? task.dependencies.join(', ') : "\u65E0"}
8642
+
8643
+ **\u{9A8C}\u{6536}\u{6807}\u{51C6}**:
8644
+ ${task.acceptance_criteria.map((criteria)=>`- ${criteria}`).join('\n')}
8645
+
8646
+ **\u{590D}\u{6742}\u{5EA6}**: ${task.complexity}
8647
+ **\u{9884}\u{4F30}\u{65F6}\u{95F4}**: ${task.estimated_hours}\u{5C0F}\u{65F6}
8648
+
8649
+ ---
8650
+ `).join('\n')}
8651
+
8652
+ ## \u{4EFB}\u{52A1}\u{4F9D}\u{8D56}\u{5173}\u{7CFB}
8653
+
8654
+ ### \u{4F9D}\u{8D56}\u{5173}\u{7CFB}\u{56FE}
8655
+ \`\`\`mermaid
8656
+ ${dependencyAnalysis.dependencyGraph}
8657
+ \`\`\`
8658
+
8659
+ ### \u{6267}\u{884C}\u{9636}\u{6BB5}
8660
+ ${dependencyAnalysis.executionOrder.map((phase, index)=>`#### ${phase.phase}
8661
+ \u{4EFB}\u{52A1}: ${phase.tasks.join(', ')}
8662
+ \u{5E76}\u{884C}\u{6267}\u{884C}: ${phase.canParallel ? "\u662F" : "\u5426"}
8663
+ `).join('\n')}
8664
+
8665
+ ### \u{5173}\u{952E}\u{8DEF}\u{5F84}
8666
+ ${dependencyAnalysis.criticalPath.join(" \u2192 ")}
8667
+
8668
+ ### \u{5E76}\u{884C}\u{4EFB}\u{52A1}\u{7EC4}
8669
+ ${dependencyAnalysis.parallelGroups.map((group)=>`- **${group.group}**: ${group.tasks.join(', ')}`).join('\n')}
8670
+
8671
+ ## \u{590D}\u{6742}\u{5EA6}\u{8BC4}\u{4F30}
8672
+
8673
+ ### \u{4EFB}\u{52A1}\u{590D}\u{6742}\u{5EA6}\u{5206}\u{5E03}
8674
+ ${Object.entries(complexityAssessment.taskComplexityDistribution).map(([level, count])=>`- ${level}: ${count}\u{4E2A}\u{4EFB}\u{52A1}`).join('\n')}
8675
+
8676
+ ### \u{98CE}\u{9669}\u{8BC4}\u{4F30}
8677
+ ${complexityAssessment.riskAssessment.map((risk)=>`#### ${risk.risk}
8678
+ - **\u{98CE}\u{9669}\u{7B49}\u{7EA7}**: ${risk.level}
8679
+ - **\u{7F13}\u{89E3}\u{63AA}\u{65BD}**: ${risk.mitigation}
8680
+ `).join('\n')}
8681
+
8682
+ ### \u{4F18}\u{5316}\u{5EFA}\u{8BAE}
8683
+ ${complexityAssessment.optimizationSuggestions.map((suggestion)=>`- ${suggestion}`).join('\n')}
8684
+
8685
+ ### \u{8BC4}\u{4F30}\u{603B}\u{7ED3}
8686
+ ${complexityAssessment.summary}
8687
+
8688
+ ## \u{751F}\u{6210}\u{65F6}\u{95F4}
8689
+ ${new Date().toISOString()}
8690
+ `;
8691
+ }
8692
+ extractFeatureName(workspaceDir) {
8693
+ return external_path_namespaceObject.basename(workspaceDir);
8694
+ }
8695
+ }
8696
+ class ApproveAgent {
8697
+ async execute(input) {
8698
+ logger_logger.info("\u5BA1\u67E5\u8BC4\u4F30\u667A\u80FD\u4F53\u5F00\u59CB\u6267\u884C");
8699
+ try {
8700
+ const qualityChecklist = await this.executeQualityChecklist(input.all_previous_outputs);
8701
+ const riskAssessment = await this.assessRisks(input.all_previous_outputs);
8702
+ const finalApproval = await this.makeFinalApproval(qualityChecklist, riskAssessment);
8703
+ const approvalDoc = await this.generateApprovalDocument(qualityChecklist, riskAssessment, finalApproval);
8704
+ const featureName = this.extractFeatureName(input.workspace_dir);
8705
+ const projectRoot = process.cwd();
8706
+ const aicoDocsDir = external_path_namespaceObject.join(projectRoot, '.aico', 'docs', featureName);
8707
+ if (!external_fs_namespaceObject.existsSync(aicoDocsDir)) external_fs_namespaceObject.mkdirSync(aicoDocsDir, {
8708
+ recursive: true
8709
+ });
8710
+ const approvalPath = external_path_namespaceObject.join(aicoDocsDir, `APPROVAL_${featureName}.md`);
8711
+ external_fs_namespaceObject.writeFileSync(approvalPath, approvalDoc);
8712
+ logger_logger.info("\u5BA1\u67E5\u8BC4\u4F30\u6587\u6863\u5DF2\u4FDD\u5B58", {
8713
+ approvalPath
8714
+ });
8715
+ const result = {
8716
+ stage: "approve",
8717
+ quality_checklist: qualityChecklist.items,
8718
+ risk_assessment: riskAssessment.risks,
8719
+ final_approval_status: finalApproval.status,
8720
+ revision_requirements: finalApproval.revisions,
8721
+ human_confirmation_required: true
8722
+ };
8723
+ logger_logger.info("\u5BA1\u67E5\u8BC4\u4F30\u667A\u80FD\u4F53\u6267\u884C\u5B8C\u6210");
8724
+ return result;
8725
+ } catch (error) {
8726
+ logger_logger.error("\u5BA1\u67E5\u8BC4\u4F30\u667A\u80FD\u4F53\u6267\u884C\u5931\u8D25", error);
8727
+ throw new RequirementHandlerError(`\u{5BA1}\u{67E5}\u{8BC4}\u{4F30}\u{9636}\u{6BB5}\u{5931}\u{8D25}: ${error.message}`, types_StageErrorCodes.APPROVE_QUALITY_CHECK_FAILED, 'approve', {
8728
+ input,
8729
+ error: error.message
8730
+ });
8731
+ }
8732
+ }
8733
+ async executeQualityChecklist(allOutputs) {
8734
+ const prompt = `
8735
+ \u{4F5C}\u{4E3A}\u{5BA1}\u{67E5}\u{8BC4}\u{4F30}\u{667A}\u{80FD}\u{4F53}\u{FF0C}\u{5BF9}\u{4EE5}\u{4E0B}\u{6240}\u{6709}\u{9636}\u{6BB5}\u{8F93}\u{51FA}\u{8FDB}\u{884C}\u{8D28}\u{91CF}\u{68C0}\u{67E5}\u{FF1A}
8736
+
8737
+ \u{9636}\u{6BB5}\u{8F93}\u{51FA}\u{FF1A}
8738
+ ${JSON.stringify(allOutputs, null, 2)}
8739
+
8740
+ \u{8BF7}\u{6267}\u{884C}\u{5168}\u{9762}\u{7684}\u{8D28}\u{91CF}\u{68C0}\u{67E5}\u{FF1A}
8741
+
8742
+ 1. \u{5B8C}\u{6574}\u{6027}\u{68C0}\u{67E5}
8743
+ - \u{4EFB}\u{52A1}\u{8BA1}\u{5212}\u{662F}\u{5426}\u{8986}\u{76D6}\u{6240}\u{6709}\u{9700}\u{6C42}
8744
+ - \u{6587}\u{6863}\u{662F}\u{5426}\u{5B8C}\u{6574}
8745
+ - \u{63A5}\u{53E3}\u{5B9A}\u{4E49}\u{662F}\u{5426}\u{9F50}\u{5168}
8746
+
8747
+ 2. \u{4E00}\u{81F4}\u{6027}\u{68C0}\u{67E5}
8748
+ - \u{5404}\u{9636}\u{6BB5}\u{8F93}\u{51FA}\u{662F}\u{5426}\u{4E00}\u{81F4}
8749
+ - \u{67B6}\u{6784}\u{8BBE}\u{8BA1}\u{4E0E}\u{9700}\u{6C42}\u{5BF9}\u{9F50}
8750
+ - \u{4EFB}\u{52A1}\u{5206}\u{89E3}\u{4E0E}\u{67B6}\u{6784}\u{5339}\u{914D}
8751
+
8752
+ 3. \u{53EF}\u{884C}\u{6027}\u{68C0}\u{67E5}
8753
+ - \u{6280}\u{672F}\u{65B9}\u{6848}\u{662F}\u{5426}\u{786E}\u{5B9E}\u{53EF}\u{884C}
8754
+ - \u{4F9D}\u{8D56}\u{5173}\u{7CFB}\u{662F}\u{5426}\u{5408}\u{7406}
8755
+ - \u{8D44}\u{6E90}\u{9700}\u{6C42}\u{662F}\u{5426}\u{73B0}\u{5B9E}
8756
+
8757
+ 4. \u{53EF}\u{63A7}\u{6027}\u{68C0}\u{67E5}
8758
+ - \u{98CE}\u{9669}\u{662F}\u{5426}\u{5728}\u{53EF}\u{63A5}\u{53D7}\u{8303}\u{56F4}
8759
+ - \u{590D}\u{6742}\u{5EA6}\u{662F}\u{5426}\u{53EF}\u{63A7}
8760
+ - \u{65F6}\u{95F4}\u{4F30}\u{7B97}\u{662F}\u{5426}\u{5408}\u{7406}
8761
+
8762
+ 5. \u{53EF}\u{6D4B}\u{6027}\u{68C0}\u{67E5}
8763
+ - \u{9A8C}\u{6536}\u{6807}\u{51C6}\u{662F}\u{5426}\u{660E}\u{786E}\u{53EF}\u{6267}\u{884C}
8764
+ - \u{6D4B}\u{8BD5}\u{7B56}\u{7565}\u{662F}\u{5426}\u{5B8C}\u{6574}
8765
+ - \u{8D28}\u{91CF}\u{6307}\u{6807}\u{662F}\u{5426}\u{53EF}\u{8861}\u{91CF}
8766
+
8767
+ \u{8F93}\u{51FA}\u{683C}\u{5F0F}\u{4E3A}JSON\u{FF1A}
8768
+ {
8769
+ "items": [
8770
+ {
8771
+ "item": "\u{68C0}\u{67E5}\u{9879}\u{76EE}",
8772
+ "status": "pass|fail|pending",
8773
+ "comments": "\u{8BE6}\u{7EC6}\u{8BF4}\u{660E}",
8774
+ "evidence": "\u{4F9D}\u{636E}\u{4FE1}\u{606F}"
8775
+ }
8776
+ ],
8777
+ "overallScore": 85,
8778
+ "passRate": 0.8,
8779
+ "criticalIssues": ["\u{5173}\u{952E}\u{95EE}\u{9898}1"],
8780
+ "recommendations": ["\u{5EFA}\u{8BAE}1", "\u{5EFA}\u{8BAE}2"]
8781
+ }
8782
+ `;
8783
+ const response = await callOpenAI([
8784
+ {
8785
+ role: 'system',
8786
+ content: "\u4F60\u662F\u8D28\u91CF\u68C0\u67E5\u4E13\u5BB6\uFF0C\u4E13\u6CE8\u4E8E\u5168\u9762\u8BC4\u4F30\u9879\u76EE\u8D28\u91CF\u548C\u53EF\u884C\u6027\u3002"
8787
+ },
8788
+ {
8789
+ role: 'user',
8790
+ content: prompt
8791
+ }
8792
+ ]);
8793
+ return JSON.parse(response);
8794
+ }
8795
+ async assessRisks(allOutputs) {
8796
+ const prompt = `
8797
+ \u{57FA}\u{4E8E}\u{6240}\u{6709}\u{9636}\u{6BB5}\u{8F93}\u{51FA}\u{FF0C}\u{8FDB}\u{884C}\u{5168}\u{9762}\u{7684}\u{98CE}\u{9669}\u{8BC4}\u{4F30}\u{FF1A}
8798
+
8799
+ \u{9636}\u{6BB5}\u{8F93}\u{51FA}\u{FF1A}
8800
+ ${JSON.stringify(allOutputs, null, 2)}
8801
+
8802
+ \u{8BF7}\u{8BC6}\u{522B}\u{548C}\u{8BC4}\u{4F30}\u{FF1A}
8803
+
8804
+ 1. \u{6280}\u{672F}\u{98CE}\u{9669}
8805
+ - \u{6280}\u{672F}\u{590D}\u{6742}\u{5EA6}\u{98CE}\u{9669}
8806
+ - \u{6280}\u{672F}\u{9009}\u{578B}\u{98CE}\u{9669}
8807
+ - \u{96C6}\u{6210}\u{98CE}\u{9669}
8808
+
8809
+ 2. \u{9879}\u{76EE}\u{98CE}\u{9669}
8810
+ - \u{65F6}\u{95F4}\u{4F30}\u{7B97}\u{98CE}\u{9669}
8811
+ - \u{8D44}\u{6E90}\u{98CE}\u{9669}
8812
+ - \u{4F9D}\u{8D56}\u{98CE}\u{9669}
8813
+
8814
+ 3. \u{8D28}\u{91CF}\u{98CE}\u{9669}
8815
+ - \u{6D4B}\u{8BD5}\u{8986}\u{76D6}\u{98CE}\u{9669}
8816
+ - \u{6027}\u{80FD}\u{98CE}\u{9669}
8817
+ - \u{7EF4}\u{62A4}\u{6027}\u{98CE}\u{9669}
8818
+
8819
+ 4. \u{4E1A}\u{52A1}\u{98CE}\u{9669}
8820
+ - \u{9700}\u{6C42}\u{53D8}\u{66F4}\u{98CE}\u{9669}
8821
+ - \u{7528}\u{6237}\u{63A5}\u{53D7}\u{5EA6}\u{98CE}\u{9669}
8822
+ - \u{5546}\u{4E1A}\u{4EF7}\u{503C}\u{98CE}\u{9669}
8823
+
8824
+ \u{5BF9}\u{6BCF}\u{4E2A}\u{98CE}\u{9669}\u{63D0}\u{4F9B}\u{FF1A}
8825
+ - \u{98CE}\u{9669}\u{63CF}\u{8FF0}
8826
+ - \u{5F71}\u{54CD}\u{7A0B}\u{5EA6}
8827
+ - \u{53D1}\u{751F}\u{6982}\u{7387}
8828
+ - \u{7F13}\u{89E3}\u{63AA}\u{65BD}
8829
+
8830
+ \u{8F93}\u{51FA}\u{683C}\u{5F0F}\u{4E3A}JSON\u{FF1A}
8831
+ {
8832
+ "risks": [
8833
+ {
8834
+ "risk": "\u{98CE}\u{9669}\u{63CF}\u{8FF0}",
8835
+ "category": "\u{6280}\u{672F}|\u{9879}\u{76EE}|\u{8D28}\u{91CF}|\u{4E1A}\u{52A1}",
8836
+ "level": "low|medium|high",
8837
+ "impact": "\u{5F71}\u{54CD}\u{63CF}\u{8FF0}",
8838
+ "probability": "low|medium|high",
8839
+ "mitigation": "\u{7F13}\u{89E3}\u{63AA}\u{65BD}"
8840
+ }
8841
+ ],
8842
+ "overallRiskLevel": "low|medium|high",
8843
+ "highRiskCount": 2,
8844
+ "riskMatrix": {
8845
+ "high_impact_high_prob": 1,
8846
+ "high_impact_low_prob": 2,
8847
+ "low_impact_high_prob": 1,
8848
+ "low_impact_low_prob": 3
8849
+ }
8850
+ }
8851
+ `;
8852
+ const response = await callOpenAI([
8853
+ {
8854
+ role: 'system',
8855
+ content: "\u4F60\u662F\u98CE\u9669\u8BC4\u4F30\u4E13\u5BB6\uFF0C\u4E13\u6CE8\u4E8E\u8BC6\u522B\u548C\u7F13\u89E3\u9879\u76EE\u98CE\u9669\u3002"
8856
+ },
8857
+ {
8858
+ role: 'user',
8859
+ content: prompt
8860
+ }
8861
+ ]);
8862
+ return JSON.parse(response);
8863
+ }
8864
+ async makeFinalApproval(qualityChecklist, riskAssessment) {
8865
+ const prompt = `
8866
+ \u{57FA}\u{4E8E}\u{8D28}\u{91CF}\u{68C0}\u{67E5}\u{548C}\u{98CE}\u{9669}\u{8BC4}\u{4F30}\u{7ED3}\u{679C}\u{FF0C}\u{505A}\u{51FA}\u{6700}\u{7EC8}\u{6279}\u{51C6}\u{51B3}\u{5B9A}\u{FF1A}
8867
+
8868
+ \u{8D28}\u{91CF}\u{68C0}\u{67E5}\u{7ED3}\u{679C}\u{FF1A}
8869
+ ${JSON.stringify(qualityChecklist, null, 2)}
8870
+
8871
+ \u{98CE}\u{9669}\u{8BC4}\u{4F30}\u{7ED3}\u{679C}\u{FF1A}
8872
+ ${JSON.stringify(riskAssessment, null, 2)}
8873
+
8874
+ \u{8BF7}\u{7EFC}\u{5408}\u{8BC4}\u{4F30}\u{5E76}\u{505A}\u{51FA}\u{51B3}\u{5B9A}\u{FF1A}
8875
+
8876
+ 1. \u{5982}\u{679C}\u{8D28}\u{91CF}\u{5206}\u{6570} >= 80 \u{4E14}\u{9AD8}\u{98CE}\u{9669}\u{6570}\u{91CF} <= 2\u{FF1A}\u{6279}\u{51C6}
8877
+ 2. \u{5982}\u{679C}\u{8D28}\u{91CF}\u{5206}\u{6570} >= 60 \u{4E14}\u{9AD8}\u{98CE}\u{9669}\u{53EF}\u{63A7}\u{FF1A}\u{9700}\u{8981}\u{4FEE}\u{8BA2}
8878
+ 3. \u{5176}\u{4ED6}\u{60C5}\u{51B5}\u{FF1A}\u{62D2}\u{7EDD}
8879
+
8880
+ \u{8F93}\u{51FA}\u{683C}\u{5F0F}\u{4E3A}JSON\u{FF1A}
8881
+ {
8882
+ "status": "approved|needs_revision|rejected",
8883
+ "reasoning": "\u{51B3}\u{5B9A}\u{7406}\u{7531}",
8884
+ "revisions": ["\u{4FEE}\u{8BA2}\u{8981}\u{6C42}1", "\u{4FEE}\u{8BA2}\u{8981}\u{6C42}2"],
8885
+ "conditions": ["\u{6279}\u{51C6}\u{6761}\u{4EF6}1"],
8886
+ "nextSteps": ["\u{4E0B}\u{4E00}\u{6B65}\u{884C}\u{52A8}1"],
8887
+ "confidence": 0.85
8888
+ }
8889
+ `;
8890
+ const response = await callOpenAI([
8891
+ {
8892
+ role: 'system',
8893
+ content: "\u4F60\u662F\u9879\u76EE\u5BA1\u6279\u4E13\u5BB6\uFF0C\u4E13\u6CE8\u4E8E\u57FA\u4E8E\u5BA2\u89C2\u6807\u51C6\u505A\u51FA\u5BA1\u6279\u51B3\u5B9A\u3002"
8894
+ },
8895
+ {
8896
+ role: 'user',
8897
+ content: prompt
8898
+ }
8899
+ ]);
8900
+ return JSON.parse(response);
8901
+ }
8902
+ async generateApprovalDocument(qualityChecklist, riskAssessment, finalApproval) {
8903
+ return `# \u{5BA1}\u{67E5}\u{8BC4}\u{4F30}\u{62A5}\u{544A}
8904
+
8905
+ ## \u{6267}\u{884C}\u{68C0}\u{67E5}\u{6E05}\u{5355}
8906
+
8907
+ ### \u{8D28}\u{91CF}\u{8BC4}\u{5206}
8908
+ - **\u{603B}\u{4F53}\u{8BC4}\u{5206}**: ${qualityChecklist.overallScore}/100
8909
+ - **\u{901A}\u{8FC7}\u{7387}**: ${(100 * qualityChecklist.passRate).toFixed(1)}%
8910
+
8911
+ ### \u{68C0}\u{67E5}\u{9879}\u{76EE}\u{8BE6}\u{60C5}
8912
+ ${qualityChecklist.items.map((item)=>`#### ${item.item}
8913
+ - **\u{72B6}\u{6001}**: ${'pass' === item.status ? "\u2705 \u901A\u8FC7" : 'fail' === item.status ? "\u274C \u5931\u8D25" : "\u23F3 \u5F85\u5B9A"}
8914
+ - **\u{8BF4}\u{660E}**: ${item.comments}
8915
+ - **\u{4F9D}\u{636E}**: ${item.evidence}
8916
+ `).join('\n')}
8917
+
8918
+ ### \u{5173}\u{952E}\u{95EE}\u{9898}
8919
+ ${qualityChecklist.criticalIssues.length > 0 ? qualityChecklist.criticalIssues.map((issue)=>`- \u{26A0}\u{FE0F} ${issue}`).join('\n') : "\u65E0\u5173\u952E\u95EE\u9898"}
8920
+
8921
+ ### \u{6539}\u{8FDB}\u{5EFA}\u{8BAE}
8922
+ ${qualityChecklist.recommendations.map((rec)=>`- \u{1F4A1} ${rec}`).join('\n')}
8923
+
8924
+ ## \u{98CE}\u{9669}\u{8BC4}\u{4F30}
8925
+
8926
+ ### \u{98CE}\u{9669}\u{6982}\u{89C8}
8927
+ - **\u{6574}\u{4F53}\u{98CE}\u{9669}\u{7B49}\u{7EA7}**: ${riskAssessment.overallRiskLevel}
8928
+ - **\u{9AD8}\u{98CE}\u{9669}\u{9879}\u{76EE}\u{6570}**: ${riskAssessment.highRiskCount}
8929
+
8930
+ ### \u{98CE}\u{9669}\u{77E9}\u{9635}
8931
+ | \u{5F71}\u{54CD}\u{7A0B}\u{5EA6} | \u{9AD8}\u{6982}\u{7387} | \u{4F4E}\u{6982}\u{7387} |
8932
+ |---------|--------|--------|
8933
+ | \u{9AD8}\u{5F71}\u{54CD} | ${riskAssessment.riskMatrix.high_impact_high_prob} | ${riskAssessment.riskMatrix.high_impact_low_prob} |
8934
+ | \u{4F4E}\u{5F71}\u{54CD} | ${riskAssessment.riskMatrix.low_impact_high_prob} | ${riskAssessment.riskMatrix.low_impact_low_prob} |
8935
+
8936
+ ### \u{98CE}\u{9669}\u{8BE6}\u{60C5}
8937
+ ${riskAssessment.risks.map((risk)=>`#### ${risk.risk}
8938
+ - **\u{7C7B}\u{522B}**: ${risk.category}
8939
+ - **\u{7B49}\u{7EA7}**: ${'high' === risk.level ? "\uD83D\uDD34 \u9AD8" : 'medium' === risk.level ? "\uD83D\uDFE1 \u4E2D" : "\uD83D\uDFE2 \u4F4E"}
8940
+ - **\u{5F71}\u{54CD}**: ${risk.impact}
8941
+ - **\u{6982}\u{7387}**: ${risk.probability}
8942
+ - **\u{7F13}\u{89E3}\u{63AA}\u{65BD}**: ${risk.mitigation}
8943
+ `).join('\n')}
8944
+
8945
+ ## \u{6700}\u{7EC8}\u{786E}\u{8BA4}
8946
+
8947
+ ### \u{6279}\u{51C6}\u{72B6}\u{6001}
8948
+ **${'approved' === finalApproval.status ? "\u2705 \u6279\u51C6\u901A\u8FC7" : 'needs_revision' === finalApproval.status ? "\u26A0\uFE0F \u9700\u8981\u4FEE\u8BA2" : "\u274C \u62D2\u7EDD"}**
8949
+
8950
+ ### \u{51B3}\u{5B9A}\u{7406}\u{7531}
8951
+ ${finalApproval.reasoning}
8952
+
8953
+ ### \u{7F6E}\u{4FE1}\u{5EA6}
8954
+ ${(100 * finalApproval.confidence).toFixed(1)}%
8955
+
8956
+ ${'needs_revision' === finalApproval.status ? `
8957
+ ### \u{4FEE}\u{8BA2}\u{8981}\u{6C42}
8958
+ ${finalApproval.revisions?.map((rev)=>`- ${rev}`).join('\n') || "\u65E0"}
8959
+ ` : ''}
8960
+
8961
+ ${'approved' === finalApproval.status ? `
8962
+ ### \u{6279}\u{51C6}\u{6761}\u{4EF6}
8963
+ ${finalApproval.conditions?.map((cond)=>`- ${cond}`).join('\n') || "\u65E0\u6761\u4EF6"}
8964
+ ` : ''}
8965
+
8966
+ ### \u{4E0B}\u{4E00}\u{6B65}\u{884C}\u{52A8}
8967
+ ${finalApproval.nextSteps?.map((step)=>`- ${step}`).join('\n') || "\u65E0"}
8968
+
8969
+ ## \u{751F}\u{6210}\u{65F6}\u{95F4}
8970
+ ${new Date().toISOString()}
8971
+ `;
8972
+ }
8973
+ extractFeatureName(workspaceDir) {
8974
+ return external_path_namespaceObject.basename(workspaceDir);
8975
+ }
8976
+ }
8977
+ class AutomateAgent {
8978
+ async execute(input) {
8979
+ logger_logger.info("\u6267\u884C\u5B9E\u65BD\u667A\u80FD\u4F53\u5F00\u59CB\u6267\u884C");
8980
+ try {
8981
+ const featureName = this.extractFeatureName(input.workspace_dir);
8982
+ const projectRoot = process.cwd();
8983
+ const aicoDocsDir = external_path_namespaceObject.join(projectRoot, '.aico', 'docs', featureName);
8984
+ const implementationDir = external_path_namespaceObject.join(aicoDocsDir, 'implementation');
8985
+ if (!external_fs_namespaceObject.existsSync(aicoDocsDir)) external_fs_namespaceObject.mkdirSync(aicoDocsDir, {
8986
+ recursive: true
8987
+ });
8988
+ if (!external_fs_namespaceObject.existsSync(implementationDir)) external_fs_namespaceObject.mkdirSync(implementationDir, {
8989
+ recursive: true
8990
+ });
8991
+ const atomizeResult = input.all_previous_outputs.find((r)=>'atomize' === r.stage);
8992
+ if (!atomizeResult || 'atomize' !== atomizeResult.stage) throw new Error("\u672A\u627E\u5230\u4EFB\u52A1\u62C6\u5206\u9636\u6BB5\u7684\u8F93\u51FA");
8993
+ const implementationProgress = await this.implementTasks(atomizeResult.atomic_tasks, implementationDir, input);
8994
+ const qualityMetrics = await this.assessCodeQuality(implementationProgress);
8995
+ const executionDoc = await this.generateExecutionDocument(implementationProgress, qualityMetrics);
8996
+ const executionPath = external_path_namespaceObject.join(aicoDocsDir, `EXECUTION_${featureName}.md`);
8997
+ external_fs_namespaceObject.writeFileSync(executionPath, executionDoc);
8998
+ logger_logger.info("\u6267\u884C\u5B9E\u65BD\u6587\u6863\u5DF2\u4FDD\u5B58", {
8999
+ executionPath
9000
+ });
9001
+ const result = {
9002
+ stage: "automate",
9003
+ implementation_progress: implementationProgress,
9004
+ code_quality_metrics: qualityMetrics,
9005
+ human_confirmation_required: true
9006
+ };
9007
+ logger_logger.info("\u6267\u884C\u5B9E\u65BD\u667A\u80FD\u4F53\u6267\u884C\u5B8C\u6210");
9008
+ return result;
9009
+ } catch (error) {
9010
+ logger_logger.error("\u6267\u884C\u5B9E\u65BD\u667A\u80FD\u4F53\u6267\u884C\u5931\u8D25", error);
9011
+ throw new RequirementHandlerError(`\u{6267}\u{884C}\u{5B9E}\u{65BD}\u{9636}\u{6BB5}\u{5931}\u{8D25}: ${error.message}`, types_StageErrorCodes.AUTOMATE_IMPLEMENTATION_FAILED, 'automate', {
9012
+ input,
9013
+ error: error.message
9014
+ });
9015
+ }
9016
+ }
9017
+ async implementTasks(tasks, implementationDir, input) {
9018
+ const progress = [];
9019
+ for (const task of tasks){
9020
+ logger_logger.info(`\u{5F00}\u{59CB}\u{5B9E}\u{65BD}\u{4EFB}\u{52A1}: ${task.name}`);
9021
+ try {
9022
+ const taskDir = external_path_namespaceObject.join(implementationDir, task.id);
9023
+ if (!external_fs_namespaceObject.existsSync(taskDir)) external_fs_namespaceObject.mkdirSync(taskDir, {
9024
+ recursive: true
9025
+ });
9026
+ const codeFiles = await this.generateCodeFiles(task, taskDir);
9027
+ const testFiles = input.include_tests ? await this.generateTestFiles(task, taskDir) : [];
9028
+ const documentationFiles = input.include_docs ? await this.generateDocumentation(task, taskDir) : [];
9029
+ progress.push({
9030
+ task_id: task.id,
9031
+ status: "completed",
9032
+ code_files: codeFiles,
9033
+ test_files: testFiles,
9034
+ documentation: documentationFiles
9035
+ });
9036
+ logger_logger.info(`\u{4EFB}\u{52A1} ${task.name} \u{5B9E}\u{65BD}\u{5B8C}\u{6210}`);
9037
+ } catch (error) {
9038
+ logger_logger.error(`\u{4EFB}\u{52A1} ${task.name} \u{5B9E}\u{65BD}\u{5931}\u{8D25}`, error);
9039
+ progress.push({
9040
+ task_id: task.id,
9041
+ status: "failed",
9042
+ code_files: [],
9043
+ test_files: [],
9044
+ documentation: [],
9045
+ error: error.message
9046
+ });
9047
+ }
9048
+ }
9049
+ return progress;
9050
+ }
9051
+ async generateCodeFiles(task, taskDir) {
9052
+ const prompt = `
9053
+ \u{4F5C}\u{4E3A}\u{6267}\u{884C}\u{5B9E}\u{65BD}\u{667A}\u{80FD}\u{4F53}\u{FF0C}\u{4E3A}\u{4EE5}\u{4E0B}\u{4EFB}\u{52A1}\u{751F}\u{6210}\u{9AD8}\u{8D28}\u{91CF}\u{7684}\u{4EE3}\u{7801}\u{FF1A}
9054
+
9055
+ \u{4EFB}\u{52A1}\u{4FE1}\u{606F}\u{FF1A}
9056
+ ${JSON.stringify(task, null, 2)}
9057
+
9058
+ \u{8981}\u{6C42}\u{FF1A}
9059
+ 1. \u{4E25}\u{683C}\u{9075}\u{5FAA}\u{9879}\u{76EE}\u{73B0}\u{6709}\u{4EE3}\u{7801}\u{89C4}\u{8303}
9060
+ 2. \u{4FDD}\u{6301}\u{4E0E}\u{73B0}\u{6709}\u{4EE3}\u{7801}\u{98CE}\u{683C}\u{4E00}\u{81F4}
9061
+ 3. \u{4F7F}\u{7528}\u{9879}\u{76EE}\u{73B0}\u{6709}\u{7684}\u{5DE5}\u{5177}\u{548C}\u{5E93}
9062
+ 4. \u{590D}\u{7528}\u{9879}\u{76EE}\u{73B0}\u{6709}\u{7EC4}\u{4EF6}
9063
+ 5. \u{4EE3}\u{7801}\u{5C3D}\u{91CF}\u{7CBE}\u{7B80}\u{6613}\u{8BFB}
9064
+ 6. \u{5305}\u{542B}\u{5FC5}\u{8981}\u{7684}\u{9519}\u{8BEF}\u{5904}\u{7406}
9065
+ 7. \u{6DFB}\u{52A0}\u{9002}\u{5F53}\u{7684}\u{6CE8}\u{91CA}
9066
+
9067
+ \u{8BF7}\u{751F}\u{6210}\u{4EE3}\u{7801}\u{6587}\u{4EF6}\u{FF0C}\u{8F93}\u{51FA}\u{683C}\u{5F0F}\u{4E3A}JSON\u{FF1A}
9068
+ {
9069
+ "files": [
9070
+ {
9071
+ "filename": "\u{6587}\u{4EF6}\u{540D}.ts",
9072
+ "content": "\u{6587}\u{4EF6}\u{5185}\u{5BB9}",
9073
+ "description": "\u{6587}\u{4EF6}\u{8BF4}\u{660E}"
9074
+ }
9075
+ ]
9076
+ }
9077
+ `;
9078
+ try {
9079
+ const response = await callOpenAI([
9080
+ {
9081
+ role: 'system',
9082
+ content: "\u4F60\u662F\u9AD8\u7EA7\u8F6F\u4EF6\u5DE5\u7A0B\u5E08\uFF0C\u4E13\u6CE8\u4E8E\u751F\u6210\u9AD8\u8D28\u91CF\u3001\u53EF\u7EF4\u62A4\u7684\u4EE3\u7801\u3002"
9083
+ },
9084
+ {
9085
+ role: 'user',
9086
+ content: prompt
9087
+ }
9088
+ ]);
9089
+ const result = JSON.parse(response);
9090
+ const codeFiles = [];
9091
+ for (const file of result.files){
9092
+ const filePath = external_path_namespaceObject.join(taskDir, file.filename);
9093
+ external_fs_namespaceObject.writeFileSync(filePath, file.content);
9094
+ codeFiles.push(filePath);
9095
+ }
9096
+ return codeFiles;
9097
+ } catch (error) {
9098
+ logger_logger.error("\u4EE3\u7801\u751F\u6210\u5931\u8D25", error);
9099
+ return [];
9100
+ }
9101
+ }
9102
+ async generateTestFiles(task, taskDir) {
9103
+ const prompt = `
9104
+ \u{4E3A}\u{4EE5}\u{4E0B}\u{4EFB}\u{52A1}\u{751F}\u{6210}\u{5168}\u{9762}\u{7684}\u{6D4B}\u{8BD5}\u{7528}\u{4F8B}\u{FF1A}
9105
+
9106
+ \u{4EFB}\u{52A1}\u{4FE1}\u{606F}\u{FF1A}
9107
+ ${JSON.stringify(task, null, 2)}
9108
+
9109
+ \u{6D4B}\u{8BD5}\u{8981}\u{6C42}\u{FF1A}
9110
+ 1. \u{8986}\u{76D6}\u{6B63}\u{5E38}\u{6D41}\u{7A0B}
9111
+ 2. \u{8986}\u{76D6}\u{8FB9}\u{754C}\u{6761}\u{4EF6}
9112
+ 3. \u{8986}\u{76D6}\u{5F02}\u{5E38}\u{60C5}\u{51B5}
9113
+ 4. \u{4F7F}\u{7528}\u{9879}\u{76EE}\u{7684}\u{6D4B}\u{8BD5}\u{6846}\u{67B6}(vitest)
9114
+ 5. \u{6D4B}\u{8BD5}\u{7528}\u{4F8B}\u{6E05}\u{6670}\u{6613}\u{7406}\u{89E3}
9115
+
9116
+ \u{8F93}\u{51FA}\u{683C}\u{5F0F}\u{4E3A}JSON\u{FF1A}
9117
+ {
9118
+ "files": [
9119
+ {
9120
+ "filename": "\u{6587}\u{4EF6}\u{540D}.test.ts",
9121
+ "content": "\u{6D4B}\u{8BD5}\u{6587}\u{4EF6}\u{5185}\u{5BB9}",
9122
+ "description": "\u{6D4B}\u{8BD5}\u{8BF4}\u{660E}"
9123
+ }
9124
+ ]
9125
+ }
9126
+ `;
9127
+ try {
9128
+ const response = await callOpenAI([
9129
+ {
9130
+ role: 'system',
9131
+ content: "\u4F60\u662F\u6D4B\u8BD5\u5DE5\u7A0B\u5E08\uFF0C\u4E13\u6CE8\u4E8E\u7F16\u5199\u5168\u9762\u3001\u53EF\u9760\u7684\u6D4B\u8BD5\u7528\u4F8B\u3002"
9132
+ },
9133
+ {
9134
+ role: 'user',
9135
+ content: prompt
9136
+ }
9137
+ ]);
9138
+ const result = JSON.parse(response);
9139
+ const testFiles = [];
9140
+ for (const file of result.files){
9141
+ const filePath = external_path_namespaceObject.join(taskDir, file.filename);
9142
+ external_fs_namespaceObject.writeFileSync(filePath, file.content);
9143
+ testFiles.push(filePath);
9144
+ }
9145
+ return testFiles;
9146
+ } catch (error) {
9147
+ logger_logger.error("\u6D4B\u8BD5\u751F\u6210\u5931\u8D25", error);
9148
+ return [];
9149
+ }
9150
+ }
9151
+ async generateDocumentation(task, taskDir) {
9152
+ const prompt = `
9153
+ \u{4E3A}\u{4EE5}\u{4E0B}\u{4EFB}\u{52A1}\u{751F}\u{6210}\u{6280}\u{672F}\u{6587}\u{6863}\u{FF1A}
9154
+
9155
+ \u{4EFB}\u{52A1}\u{4FE1}\u{606F}\u{FF1A}
9156
+ ${JSON.stringify(task, null, 2)}
9157
+
9158
+ \u{6587}\u{6863}\u{8981}\u{6C42}\u{FF1A}
9159
+ 1. API\u{8BF4}\u{660E}\u{6587}\u{6863}
9160
+ 2. \u{4F7F}\u{7528}\u{793A}\u{4F8B}
9161
+ 3. \u{6CE8}\u{610F}\u{4E8B}\u{9879}
9162
+ 4. \u{6545}\u{969C}\u{6392}\u{9664}
9163
+
9164
+ \u{8F93}\u{51FA}\u{683C}\u{5F0F}\u{4E3A}JSON\u{FF1A}
9165
+ {
9166
+ "files": [
9167
+ {
9168
+ "filename": "README.md",
9169
+ "content": "\u{6587}\u{6863}\u{5185}\u{5BB9}",
9170
+ "description": "\u{6587}\u{6863}\u{8BF4}\u{660E}"
9171
+ }
9172
+ ]
9173
+ }
9174
+ `;
9175
+ try {
9176
+ const response = await callOpenAI([
9177
+ {
9178
+ role: 'system',
9179
+ content: "\u4F60\u662F\u6280\u672F\u6587\u6863\u5DE5\u7A0B\u5E08\uFF0C\u4E13\u6CE8\u4E8E\u7F16\u5199\u6E05\u6670\u3001\u5B9E\u7528\u7684\u6280\u672F\u6587\u6863\u3002"
9180
+ },
9181
+ {
9182
+ role: 'user',
9183
+ content: prompt
9184
+ }
9185
+ ]);
9186
+ const result = JSON.parse(response);
9187
+ const docFiles = [];
9188
+ for (const file of result.files){
9189
+ const filePath = external_path_namespaceObject.join(taskDir, file.filename);
9190
+ external_fs_namespaceObject.writeFileSync(filePath, file.content);
9191
+ docFiles.push(filePath);
9192
+ }
9193
+ return docFiles;
9194
+ } catch (error) {
9195
+ logger_logger.error("\u6587\u6863\u751F\u6210\u5931\u8D25", error);
9196
+ return [];
9197
+ }
9198
+ }
9199
+ async assessCodeQuality(implementationProgress) {
9200
+ const completedTasks = implementationProgress.filter((p)=>'completed' === p.status);
9201
+ const failedTasks = implementationProgress.filter((p)=>'failed' === p.status);
9202
+ const totalCodeFiles = completedTasks.reduce((sum, task)=>sum + task.code_files.length, 0);
9203
+ const totalTestFiles = completedTasks.reduce((sum, task)=>sum + task.test_files.length, 0);
9204
+ const coverage = totalTestFiles > 0 ? Math.min(100, totalTestFiles / totalCodeFiles * 100) : 0;
9205
+ const successRate = completedTasks.length / implementationProgress.length;
9206
+ return {
9207
+ coverage: Math.round(coverage),
9208
+ complexity: failedTasks.length > 0 ? "\u9AD8" : completedTasks.length > 5 ? "\u4E2D\u7B49" : "\u7B80\u5355",
9209
+ standards_compliance: successRate >= 0.8,
9210
+ success_rate: successRate,
9211
+ total_files: totalCodeFiles + totalTestFiles,
9212
+ failed_tasks: failedTasks.length
9213
+ };
9214
+ }
9215
+ async generateExecutionDocument(implementationProgress, qualityMetrics) {
9216
+ return `# \u{5B9E}\u{65BD}\u{6267}\u{884C}\u{62A5}\u{544A}
9217
+
9218
+ ## \u{6267}\u{884C}\u{6982}\u{89C8}
9219
+
9220
+ - **\u{603B}\u{4EFB}\u{52A1}\u{6570}**: ${implementationProgress.length}
9221
+ - **\u{5B8C}\u{6210}\u{4EFB}\u{52A1}**: ${implementationProgress.filter((p)=>'completed' === p.status).length}
9222
+ - **\u{5931}\u{8D25}\u{4EFB}\u{52A1}**: ${implementationProgress.filter((p)=>'failed' === p.status).length}
9223
+ - **\u{6210}\u{529F}\u{7387}**: ${(100 * qualityMetrics.success_rate).toFixed(1)}%
9224
+
9225
+ ## \u{4EFB}\u{52A1}\u{6267}\u{884C}\u{8BE6}\u{60C5}
9226
+
9227
+ ${implementationProgress.map((progress, index)=>`### ${progress.task_id}
9228
+ - **\u{72B6}\u{6001}**: ${'completed' === progress.status ? "\u2705 \u5B8C\u6210" : 'failed' === progress.status ? "\u274C \u5931\u8D25" : "\u23F3 \u8FDB\u884C\u4E2D"}
9229
+ - **\u{4EE3}\u{7801}\u{6587}\u{4EF6}**: ${progress.code_files.length}\u{4E2A}
9230
+ - **\u{6D4B}\u{8BD5}\u{6587}\u{4EF6}**: ${progress.test_files.length}\u{4E2A}
9231
+ - **\u{6587}\u{6863}\u{6587}\u{4EF6}**: ${progress.documentation.length}\u{4E2A}
9232
+ ${'failed' === progress.status ? `- **\u{9519}\u{8BEF}\u{4FE1}\u{606F}**: ${progress.error || "\u672A\u77E5\u9519\u8BEF"}` : ''}
9233
+
9234
+ #### \u{751F}\u{6210}\u{7684}\u{6587}\u{4EF6}
9235
+ ${progress.code_files.map((file)=>`- \u{1F4DD} ${external_path_namespaceObject.basename(file)}`).join('\n')}
9236
+ ${progress.test_files.map((file)=>`- \u{1F9EA} ${external_path_namespaceObject.basename(file)}`).join('\n')}
9237
+ ${progress.documentation.map((file)=>`- \u{1F4DA} ${external_path_namespaceObject.basename(file)}`).join('\n')}
9238
+
9239
+ ---
9240
+ `).join('\n')}
9241
+
9242
+ ## \u{4EE3}\u{7801}\u{8D28}\u{91CF}\u{6307}\u{6807}
9243
+
9244
+ ### \u{6D4B}\u{8BD5}\u{8986}\u{76D6}\u{7387}
9245
+ ${qualityMetrics.coverage}%
9246
+
9247
+ ### \u{590D}\u{6742}\u{5EA6}\u{8BC4}\u{4F30}
9248
+ ${qualityMetrics.complexity}
9249
+
9250
+ ### \u{89C4}\u{8303}\u{5408}\u{89C4}\u{6027}
9251
+ ${qualityMetrics.standards_compliance ? "\u2705 \u7B26\u5408\u89C4\u8303" : "\u274C \u9700\u8981\u6539\u8FDB"}
9252
+
9253
+ ### \u{8BE6}\u{7EC6}\u{6307}\u{6807}
9254
+ - **\u{603B}\u{6587}\u{4EF6}\u{6570}**: ${qualityMetrics.total_files}
9255
+ - **\u{5931}\u{8D25}\u{4EFB}\u{52A1}\u{6570}**: ${qualityMetrics.failed_tasks}
9256
+ - **\u{6210}\u{529F}\u{7387}**: ${(100 * qualityMetrics.success_rate).toFixed(1)}%
9257
+
9258
+ ## \u{8D28}\u{91CF}\u{5EFA}\u{8BAE}
9259
+
9260
+ ${qualityMetrics.coverage < 80 ? "- \u26A0\uFE0F \u5EFA\u8BAE\u589E\u52A0\u6D4B\u8BD5\u8986\u76D6\u7387" : "- \u2705 \u6D4B\u8BD5\u8986\u76D6\u7387\u826F\u597D"}
9261
+ ${qualityMetrics.failed_tasks > 0 ? "- \u26A0\uFE0F \u9700\u8981\u4FEE\u590D\u5931\u8D25\u7684\u4EFB\u52A1" : "- \u2705 \u6240\u6709\u4EFB\u52A1\u6267\u884C\u6210\u529F"}
9262
+ ${qualityMetrics.standards_compliance ? "- \u2705 \u4EE3\u7801\u89C4\u8303\u7B26\u5408\u8981\u6C42" : "- \u26A0\uFE0F \u9700\u8981\u6539\u8FDB\u4EE3\u7801\u89C4\u8303"}
9263
+
9264
+ ## \u{751F}\u{6210}\u{65F6}\u{95F4}
9265
+ ${new Date().toISOString()}
9266
+ `;
9267
+ }
9268
+ extractFeatureName(workspaceDir) {
9269
+ return external_path_namespaceObject.basename(workspaceDir);
9270
+ }
9271
+ }
9272
+ class AssessAgent {
9273
+ async execute(input) {
9274
+ logger_logger.info("\u8D28\u91CF\u8BC4\u4F30\u667A\u80FD\u4F53\u5F00\u59CB\u6267\u884C");
9275
+ try {
9276
+ const executionValidation = await this.validateExecution(input.all_previous_outputs);
9277
+ const qualityAssessment = await this.assessQuality(input.all_previous_outputs, input.workspace_dir);
9278
+ const deliverables = await this.generateDeliverables(input.workspace_dir);
9279
+ const todoItems = await this.generateTodoItems(qualityAssessment, executionValidation);
9280
+ const finalReport = await this.generateFinalReport(qualityAssessment, deliverables, todoItems);
9281
+ const projectSummary = await this.generateProjectSummary(input.all_previous_outputs);
9282
+ const featureName = this.extractFeatureName(input.workspace_dir);
9283
+ const projectRoot = process.cwd();
9284
+ const aicoDocsDir = external_path_namespaceObject.join(projectRoot, '.aico', 'docs', featureName);
9285
+ if (!external_fs_namespaceObject.existsSync(aicoDocsDir)) external_fs_namespaceObject.mkdirSync(aicoDocsDir, {
9286
+ recursive: true
9287
+ });
9288
+ const acceptancePath = external_path_namespaceObject.join(aicoDocsDir, `ACCEPTANCE_${featureName}.md`);
9289
+ const finalPath = external_path_namespaceObject.join(aicoDocsDir, `FINAL_${featureName}.md`);
9290
+ const todoPath = external_path_namespaceObject.join(aicoDocsDir, `TODO_${featureName}.md`);
9291
+ const acceptanceDoc = await this.generateAcceptanceDocument(qualityAssessment, executionValidation);
9292
+ const todoDoc = await this.generateTodoDocument(todoItems);
9293
+ external_fs_namespaceObject.writeFileSync(acceptancePath, acceptanceDoc);
9294
+ external_fs_namespaceObject.writeFileSync(finalPath, finalReport);
9295
+ external_fs_namespaceObject.writeFileSync(todoPath, todoDoc);
9296
+ logger_logger.info("\u8D28\u91CF\u8BC4\u4F30\u6587\u6863\u5DF2\u4FDD\u5B58", {
9297
+ acceptancePath,
9298
+ finalPath,
9299
+ todoPath
9300
+ });
9301
+ const result = {
9302
+ stage: "assess",
9303
+ quality_assessment: qualityAssessment,
9304
+ deliverables: deliverables,
9305
+ todo_items: todoItems,
9306
+ final_report: finalReport,
9307
+ project_summary: projectSummary,
9308
+ human_confirmation_required: true
9309
+ };
9310
+ logger_logger.info("\u8D28\u91CF\u8BC4\u4F30\u667A\u80FD\u4F53\u6267\u884C\u5B8C\u6210");
9311
+ return result;
9312
+ } catch (error) {
9313
+ logger_logger.error("\u8D28\u91CF\u8BC4\u4F30\u667A\u80FD\u4F53\u6267\u884C\u5931\u8D25", error);
9314
+ throw new RequirementHandlerError(`\u{8D28}\u{91CF}\u{8BC4}\u{4F30}\u{9636}\u{6BB5}\u{5931}\u{8D25}: ${error.message}`, types_StageErrorCodes.ASSESS_QUALITY_EVALUATION_FAILED, 'assess', {
9315
+ input,
9316
+ error: error.message
9317
+ });
9318
+ }
9319
+ }
9320
+ async validateExecution(allOutputs) {
9321
+ const executionResult = allOutputs.find((r)=>'automate' === r.stage);
9322
+ const alignResult = allOutputs.find((r)=>'align' === r.stage);
9323
+ if (!executionResult || !alignResult) throw new Error("\u7F3A\u5C11\u5FC5\u8981\u7684\u9636\u6BB5\u8F93\u51FA");
9324
+ const prompt = `
9325
+ \u{4F5C}\u{4E3A}\u{8D28}\u{91CF}\u{8BC4}\u{4F30}\u{667A}\u{80FD}\u{4F53}\u{FF0C}\u{9A8C}\u{8BC1}\u{6267}\u{884C}\u{7ED3}\u{679C}\u{662F}\u{5426}\u{6EE1}\u{8DB3}\u{539F}\u{59CB}\u{9700}\u{6C42}\u{FF1A}
9326
+
9327
+ \u{539F}\u{59CB}\u{9700}\u{6C42}\u{548C}\u{9A8C}\u{6536}\u{6807}\u{51C6}\u{FF1A}
9328
+ ${JSON.stringify(alignResult, null, 2)}
9329
+
9330
+ \u{6267}\u{884C}\u{7ED3}\u{679C}\u{FF1A}
9331
+ ${JSON.stringify(executionResult, null, 2)}
9332
+
9333
+ \u{8BF7}\u{9A8C}\u{8BC1}\u{FF1A}
9334
+ 1. \u{6240}\u{6709}\u{9700}\u{6C42}\u{662F}\u{5426}\u{5DF2}\u{5B9E}\u{73B0}
9335
+ 2. \u{9A8C}\u{6536}\u{6807}\u{51C6}\u{662F}\u{5426}\u{5168}\u{90E8}\u{6EE1}\u{8DB3}
9336
+ 3. \u{9879}\u{76EE}\u{662F}\u{5426}\u{53EF}\u{4EE5}\u{7F16}\u{8BD1}\u{901A}\u{8FC7}
9337
+ 4. \u{6240}\u{6709}\u{6D4B}\u{8BD5}\u{662F}\u{5426}\u{901A}\u{8FC7}
9338
+ 5. \u{529F}\u{80FD}\u{5B8C}\u{6574}\u{6027}\u{9A8C}\u{8BC1}
9339
+ 6. \u{5B9E}\u{73B0}\u{4E0E}\u{8BBE}\u{8BA1}\u{6587}\u{6863}\u{662F}\u{5426}\u{4E00}\u{81F4}
9340
+
9341
+ \u{8F93}\u{51FA}\u{683C}\u{5F0F}\u{4E3A}JSON\u{FF1A}
9342
+ {
9343
+ "requirements_met": true,
9344
+ "acceptance_criteria_status": [
9345
+ {
9346
+ "criteria": "\u{9A8C}\u{6536}\u{6807}\u{51C6}1",
9347
+ "met": true,
9348
+ "evidence": "\u{6EE1}\u{8DB3}\u{4F9D}\u{636E}"
9349
+ }
9350
+ ],
9351
+ "compilation_status": "success|warning|error",
9352
+ "test_status": "all_passed|some_failed|no_tests",
9353
+ "functionality_validation": {
9354
+ "core_features": "\u{5B8C}\u{6574}|\u{90E8}\u{5206}|\u{7F3A}\u{5931}",
9355
+ "edge_cases": "\u{8986}\u{76D6}|\u{90E8}\u{5206}\u{8986}\u{76D6}|\u{672A}\u{8986}\u{76D6}",
9356
+ "error_handling": "\u{5B8C}\u{5584}|\u{57FA}\u{672C}|\u{4E0D}\u{8DB3}"
9357
+ },
9358
+ "design_consistency": true,
9359
+ "overall_validation": "\u{901A}\u{8FC7}|\u{6709}\u{95EE}\u{9898}|\u{5931}\u{8D25}"
9360
+ }
9361
+ `;
9362
+ const response = await callOpenAI([
9363
+ {
9364
+ role: 'system',
9365
+ content: "\u4F60\u662F\u9A8C\u6536\u6D4B\u8BD5\u4E13\u5BB6\uFF0C\u4E13\u6CE8\u4E8E\u9A8C\u8BC1\u9879\u76EE\u4EA4\u4ED8\u7269\u662F\u5426\u6EE1\u8DB3\u9700\u6C42\u3002"
9366
+ },
9367
+ {
9368
+ role: 'user',
9369
+ content: prompt
9370
+ }
9371
+ ]);
9372
+ return JSON.parse(response);
9373
+ }
9374
+ async assessQuality(allOutputs, workspaceDir) {
9375
+ const files = this.collectAllFiles(workspaceDir);
9376
+ const prompt = `
9377
+ \u{7EFC}\u{5408}\u{8BC4}\u{4F30}\u{9879}\u{76EE}\u{8D28}\u{91CF}\u{FF1A}
9378
+
9379
+ \u{6240}\u{6709}\u{9636}\u{6BB5}\u{8F93}\u{51FA}\u{FF1A}
9380
+ ${JSON.stringify(allOutputs, null, 2)}
9381
+
9382
+ \u{751F}\u{6210}\u{7684}\u{6587}\u{4EF6}\u{FF1A}
9383
+ ${JSON.stringify(files, null, 2)}
9384
+
9385
+ \u{8BF7}\u{4ECE}\u{4EE5}\u{4E0B}\u{7EF4}\u{5EA6}\u{8BC4}\u{4F30}\u{8D28}\u{91CF}\u{FF1A}
9386
+
9387
+ 1. \u{4EE3}\u{7801}\u{8D28}\u{91CF}
9388
+ - \u{4EE3}\u{7801}\u{89C4}\u{8303}\u{6027}
9389
+ - \u{53EF}\u{8BFB}\u{6027}
9390
+ - \u{590D}\u{6742}\u{5EA6}
9391
+ - \u{9519}\u{8BEF}\u{5904}\u{7406}
9392
+
9393
+ 2. \u{6D4B}\u{8BD5}\u{8D28}\u{91CF}
9394
+ - \u{6D4B}\u{8BD5}\u{8986}\u{76D6}\u{7387}
9395
+ - \u{6D4B}\u{8BD5}\u{7528}\u{4F8B}\u{8D28}\u{91CF}
9396
+ - \u{8FB9}\u{754C}\u{6761}\u{4EF6}\u{8986}\u{76D6}
9397
+
9398
+ 3. \u{6587}\u{6863}\u{8D28}\u{91CF}
9399
+ - \u{6587}\u{6863}\u{5B8C}\u{6574}\u{6027}
9400
+ - \u{6587}\u{6863}\u{51C6}\u{786E}\u{6027}
9401
+ - \u{6587}\u{6863}\u{4E00}\u{81F4}\u{6027}
9402
+
9403
+ 4. \u{67B6}\u{6784}\u{8D28}\u{91CF}
9404
+ - \u{6A21}\u{5757}\u{5316}\u{7A0B}\u{5EA6}
9405
+ - \u{53EF}\u{7EF4}\u{62A4}\u{6027}
9406
+ - \u{53EF}\u{6269}\u{5C55}\u{6027}
9407
+
9408
+ \u{8F93}\u{51FA}\u{683C}\u{5F0F}\u{4E3A}JSON\u{FF1A}
9409
+ {
9410
+ "code_quality": "excellent|good|acceptable|needs_improvement",
9411
+ "test_coverage": 85,
9412
+ "documentation_completeness": 90,
9413
+ "acceptance_criteria_met": true,
9414
+ "detailed_scores": {
9415
+ "code_standards": 90,
9416
+ "readability": 85,
9417
+ "complexity": 80,
9418
+ "error_handling": 75,
9419
+ "test_quality": 85,
9420
+ "doc_accuracy": 90,
9421
+ "modularity": 88
9422
+ },
9423
+ "strengths": ["\u{4F18}\u{70B9}1", "\u{4F18}\u{70B9}2"],
9424
+ "areas_for_improvement": ["\u{6539}\u{8FDB}\u{70B9}1", "\u{6539}\u{8FDB}\u{70B9}2"]
9425
+ }
9426
+ `;
9427
+ const response = await callOpenAI([
9428
+ {
9429
+ role: 'system',
9430
+ content: "\u4F60\u662F\u4EE3\u7801\u8D28\u91CF\u8BC4\u4F30\u4E13\u5BB6\uFF0C\u4E13\u6CE8\u4E8E\u5168\u9762\u8BC4\u4F30\u8F6F\u4EF6\u8D28\u91CF\u3002"
9431
+ },
9432
+ {
9433
+ role: 'user',
9434
+ content: prompt
9435
+ }
9436
+ ]);
9437
+ return JSON.parse(response);
9438
+ }
9439
+ async generateDeliverables(workspaceDir) {
9440
+ const deliverables = [];
9441
+ try {
9442
+ if (external_fs_namespaceObject.existsSync(workspaceDir)) {
9443
+ const items = external_fs_namespaceObject.readdirSync(workspaceDir, {
9444
+ withFileTypes: true
9445
+ });
9446
+ for (const item of items)if (item.isFile()) deliverables.push(external_path_namespaceObject.join(workspaceDir, item.name));
9447
+ else if (item.isDirectory()) {
9448
+ const subFiles = this.collectAllFiles(external_path_namespaceObject.join(workspaceDir, item.name));
9449
+ deliverables.push(...subFiles.map((f)=>f.path));
9450
+ }
9451
+ }
9452
+ } catch (error) {
9453
+ logger_logger.warn("\u6536\u96C6\u4EA4\u4ED8\u7269\u65F6\u51FA\u9519", error);
9454
+ }
9455
+ return deliverables;
9456
+ }
9457
+ async generateTodoItems(qualityAssessment, executionValidation) {
9458
+ const prompt = `
9459
+ \u{57FA}\u{4E8E}\u{8D28}\u{91CF}\u{8BC4}\u{4F30}\u{548C}\u{6267}\u{884C}\u{9A8C}\u{8BC1}\u{7ED3}\u{679C}\u{FF0C}\u{751F}\u{6210}TODO\u{6E05}\u{5355}\u{FF1A}
9460
+
9461
+ \u{8D28}\u{91CF}\u{8BC4}\u{4F30}\u{FF1A}
9462
+ ${JSON.stringify(qualityAssessment, null, 2)}
9463
+
9464
+ \u{6267}\u{884C}\u{9A8C}\u{8BC1}\u{FF1A}
9465
+ ${JSON.stringify(executionValidation, null, 2)}
9466
+
9467
+ \u{8BF7}\u{751F}\u{6210}\u{5F85}\u{529E}\u{4E8B}\u{9879}\u{FF0C}\u{5305}\u{62EC}\u{FF1A}
9468
+ 1. \u{4EE3}\u{7801}\u{6539}\u{8FDB}\u{4E8B}\u{9879}
9469
+ 2. \u{914D}\u{7F6E}\u{5B8C}\u{5584}\u{4E8B}\u{9879}
9470
+ 3. \u{6587}\u{6863}\u{8865}\u{5145}\u{4E8B}\u{9879}
9471
+ 4. \u{6D4B}\u{8BD5}\u{589E}\u{5F3A}\u{4E8B}\u{9879}
9472
+ 5. \u{90E8}\u{7F72}\u{51C6}\u{5907}\u{4E8B}\u{9879}
9473
+
9474
+ \u{8F93}\u{51FA}\u{683C}\u{5F0F}\u{4E3A}JSON\u{FF1A}
9475
+ {
9476
+ "items": [
9477
+ {
9478
+ "item": "\u{5F85}\u{529E}\u{4E8B}\u{9879}\u{63CF}\u{8FF0}",
9479
+ "priority": "high|medium|low",
9480
+ "category": "\u{4EE3}\u{7801}|\u{914D}\u{7F6E}|\u{6587}\u{6863}|\u{6D4B}\u{8BD5}|\u{90E8}\u{7F72}",
9481
+ "description": "\u{8BE6}\u{7EC6}\u{8BF4}\u{660E}",
9482
+ "estimated_effort": "\u{65F6}\u{95F4}\u{4F30}\u{7B97}"
9483
+ }
9484
+ ]
9485
+ }
9486
+ `;
9487
+ const response = await callOpenAI([
9488
+ {
9489
+ role: 'system',
9490
+ content: "\u4F60\u662F\u9879\u76EE\u7BA1\u7406\u4E13\u5BB6\uFF0C\u4E13\u6CE8\u4E8E\u8BC6\u522B\u9879\u76EE\u5B8C\u5584\u673A\u4F1A\u3002"
9491
+ },
9492
+ {
9493
+ role: 'user',
9494
+ content: prompt
9495
+ }
9496
+ ]);
9497
+ const result = JSON.parse(response);
9498
+ return result.items;
9499
+ }
9500
+ async generateFinalReport(qualityAssessment, deliverables, todoItems) {
9501
+ return `# \u{9879}\u{76EE}\u{6700}\u{7EC8}\u{62A5}\u{544A}
9502
+
9503
+ ## \u{9879}\u{76EE}\u{6982}\u{51B5}
9504
+
9505
+ - **\u{4EA4}\u{4ED8}\u{7269}\u{6570}\u{91CF}**: ${deliverables.length}
9506
+ - **\u{8D28}\u{91CF}\u{7B49}\u{7EA7}**: ${qualityAssessment.code_quality}
9507
+ - **\u{6D4B}\u{8BD5}\u{8986}\u{76D6}\u{7387}**: ${qualityAssessment.test_coverage}%
9508
+ - **\u{6587}\u{6863}\u{5B8C}\u{6574}\u{5EA6}**: ${qualityAssessment.documentation_completeness}%
9509
+ - **\u{9A8C}\u{6536}\u{6807}\u{51C6}**: ${qualityAssessment.acceptance_criteria_met ? "\u2705 \u5DF2\u6EE1\u8DB3" : "\u274C \u672A\u6EE1\u8DB3"}
9510
+
9511
+ ## \u{8D28}\u{91CF}\u{8BC4}\u{4F30}\u{8BE6}\u{60C5}
9512
+
9513
+ ### \u{4EE3}\u{7801}\u{8D28}\u{91CF}
9514
+ - **\u{6574}\u{4F53}\u{8BC4}\u{7EA7}**: ${qualityAssessment.code_quality}
9515
+ - **\u{4EE3}\u{7801}\u{89C4}\u{8303}**: ${qualityAssessment.detailed_scores.code_standards}/100
9516
+ - **\u{53EF}\u{8BFB}\u{6027}**: ${qualityAssessment.detailed_scores.readability}/100
9517
+ - **\u{590D}\u{6742}\u{5EA6}**: ${qualityAssessment.detailed_scores.complexity}/100
9518
+ - **\u{9519}\u{8BEF}\u{5904}\u{7406}**: ${qualityAssessment.detailed_scores.error_handling}/100
9519
+
9520
+ ### \u{6D4B}\u{8BD5}\u{8D28}\u{91CF}
9521
+ - **\u{6D4B}\u{8BD5}\u{8986}\u{76D6}\u{7387}**: ${qualityAssessment.test_coverage}%
9522
+ - **\u{6D4B}\u{8BD5}\u{8D28}\u{91CF}\u{5206}\u{6570}**: ${qualityAssessment.detailed_scores.test_quality}/100
9523
+
9524
+ ### \u{6587}\u{6863}\u{8D28}\u{91CF}
9525
+ - **\u{6587}\u{6863}\u{5B8C}\u{6574}\u{5EA6}**: ${qualityAssessment.documentation_completeness}%
9526
+ - **\u{6587}\u{6863}\u{51C6}\u{786E}\u{6027}**: ${qualityAssessment.detailed_scores.doc_accuracy}/100
9527
+
9528
+ ### \u{67B6}\u{6784}\u{8D28}\u{91CF}
9529
+ - **\u{6A21}\u{5757}\u{5316}\u{7A0B}\u{5EA6}**: ${qualityAssessment.detailed_scores.modularity}/100
9530
+
9531
+ ## \u{9879}\u{76EE}\u{4F18}\u{52BF}
9532
+
9533
+ ${qualityAssessment.strengths.map((strength)=>`- \u{2705} ${strength}`).join('\n')}
9534
+
9535
+ ## \u{6539}\u{8FDB}\u{5EFA}\u{8BAE}
9536
+
9537
+ ${qualityAssessment.areas_for_improvement.map((improvement)=>`- \u{1F4A1} ${improvement}`).join('\n')}
9538
+
9539
+ ## \u{4EA4}\u{4ED8}\u{7269}\u{6E05}\u{5355}
9540
+
9541
+ ${deliverables.map((file, index)=>`${index + 1}. ${external_path_namespaceObject.basename(file)}`).join('\n')}
9542
+
9543
+ ## \u{5F85}\u{529E}\u{4E8B}\u{9879}\u{6982}\u{51B5}
9544
+
9545
+ - **\u{9AD8}\u{4F18}\u{5148}\u{7EA7}**: ${todoItems.filter((item)=>'high' === item.priority).length}\u{9879}
9546
+ - **\u{4E2D}\u{4F18}\u{5148}\u{7EA7}**: ${todoItems.filter((item)=>'medium' === item.priority).length}\u{9879}
9547
+ - **\u{4F4E}\u{4F18}\u{5148}\u{7EA7}**: ${todoItems.filter((item)=>'low' === item.priority).length}\u{9879}
9548
+
9549
+ ## \u{9879}\u{76EE}\u{72B6}\u{6001}
9550
+
9551
+ ### \u{603B}\u{4F53}\u{8BC4}\u{4EF7}
9552
+ ${qualityAssessment.acceptance_criteria_met ? "\u2705 \u9879\u76EE\u5DF2\u6210\u529F\u5B8C\u6210\uFF0C\u6EE1\u8DB3\u6240\u6709\u9A8C\u6536\u6807\u51C6\uFF0C\u53EF\u4EE5\u4EA4\u4ED8\u4F7F\u7528\u3002" : "\u26A0\uFE0F \u9879\u76EE\u57FA\u672C\u5B8C\u6210\uFF0C\u4F46\u4ECD\u6709\u90E8\u5206\u9A8C\u6536\u6807\u51C6\u9700\u8981\u5B8C\u5584\u3002"}
9553
+
9554
+ ### \u{5EFA}\u{8BAE}\u{4E0B}\u{4E00}\u{6B65}
9555
+ ${'excellent' === qualityAssessment.code_quality ? "\u9879\u76EE\u8D28\u91CF\u4F18\u79C0\uFF0C\u53EF\u4EE5\u76F4\u63A5\u6295\u5165\u751F\u4EA7\u4F7F\u7528\u3002" : 'good' === qualityAssessment.code_quality ? "\u9879\u76EE\u8D28\u91CF\u826F\u597D\uFF0C\u5EFA\u8BAE\u5B8C\u6210\u9AD8\u4F18\u5148\u7EA7TODO\u9879\u540E\u6295\u5165\u4F7F\u7528\u3002" : "\u5EFA\u8BAE\u5148\u5B8C\u6210\u4EE3\u7801\u8D28\u91CF\u6539\u8FDB\u540E\u518D\u6295\u5165\u4F7F\u7528\u3002"}
9556
+
9557
+ ## \u{751F}\u{6210}\u{65F6}\u{95F4}
9558
+ ${new Date().toISOString()}
9559
+ `;
9560
+ }
9561
+ async generateProjectSummary(allOutputs) {
9562
+ return `\u{9879}\u{76EE}\u{5DF2}\u{901A}\u{8FC7}6A\u{5DE5}\u{4F5C}\u{6D41}\u{5B8C}\u{6210}\u{FF0C}\u{5305}\u{542B}${allOutputs.length}\u{4E2A}\u{6267}\u{884C}\u{9636}\u{6BB5}\u{FF0C}\u{5B9E}\u{73B0}\u{4E86}\u{4ECE}\u{9700}\u{6C42}\u{5206}\u{6790}\u{5230}\u{6700}\u{7EC8}\u{4EA4}\u{4ED8}\u{7684}\u{5B8C}\u{6574}\u{6D41}\u{7A0B}\u{3002}\u{9879}\u{76EE}\u{8D28}\u{91CF}\u{8BC4}\u{4F30}\u{663E}\u{793A}\u{5404}\u{9879}\u{6307}\u{6807}\u{5747}\u{8FBE}\u{5230}\u{9884}\u{671F}\u{6807}\u{51C6}\u{FF0C}\u{53EF}\u{4EE5}\u{6309}\u{8BA1}\u{5212}\u{4EA4}\u{4ED8}\u{4F7F}\u{7528}\u{3002}`;
9563
+ }
9564
+ async generateAcceptanceDocument(qualityAssessment, executionValidation) {
9565
+ return `# \u{9A8C}\u{6536}\u{62A5}\u{544A}
9566
+
9567
+ ## \u{9A8C}\u{6536}\u{6982}\u{51B5}
9568
+
9569
+ - **\u{9A8C}\u{6536}\u{72B6}\u{6001}**: ${"\u901A\u8FC7" === executionValidation.overall_validation ? "\u2705 \u901A\u8FC7" : "\u26A0\uFE0F \u6709\u6761\u4EF6\u901A\u8FC7"}
9570
+ - **\u{9700}\u{6C42}\u{6EE1}\u{8DB3}\u{5EA6}**: ${executionValidation.requirements_met ? "\u2705 \u5B8C\u5168\u6EE1\u8DB3" : "\u274C \u90E8\u5206\u6EE1\u8DB3"}
9571
+ - **\u{7F16}\u{8BD1}\u{72B6}\u{6001}**: ${executionValidation.compilation_status}
9572
+ - **\u{6D4B}\u{8BD5}\u{72B6}\u{6001}**: ${executionValidation.test_status}
9573
+
9574
+ ## \u{9A8C}\u{6536}\u{6807}\u{51C6}\u{68C0}\u{67E5}
9575
+
9576
+ ${executionValidation.acceptance_criteria_status.map((criteria)=>`### ${criteria.criteria}
9577
+ - **\u{72B6}\u{6001}**: ${criteria.met ? "\u2705 \u6EE1\u8DB3" : "\u274C \u4E0D\u6EE1\u8DB3"}
9578
+ - **\u{4F9D}\u{636E}**: ${criteria.evidence}
9579
+ `).join('\n')}
9580
+
9581
+ ## \u{529F}\u{80FD}\u{9A8C}\u{8BC1}
9582
+
9583
+ ### \u{6838}\u{5FC3}\u{529F}\u{80FD}
9584
+ ${executionValidation.functionality_validation.core_features}
9585
+
9586
+ ### \u{8FB9}\u{754C}\u{6761}\u{4EF6}
9587
+ ${executionValidation.functionality_validation.edge_cases}
9588
+
9589
+ ### \u{9519}\u{8BEF}\u{5904}\u{7406}
9590
+ ${executionValidation.functionality_validation.error_handling}
9591
+
9592
+ ## \u{8BBE}\u{8BA1}\u{4E00}\u{81F4}\u{6027}
9593
+ ${executionValidation.design_consistency ? "\u2705 \u4E0E\u8BBE\u8BA1\u6587\u6863\u4E00\u81F4" : "\u274C \u4E0E\u8BBE\u8BA1\u6587\u6863\u6709\u504F\u5DEE"}
9594
+
9595
+ ## \u{9A8C}\u{6536}\u{7ED3}\u{8BBA}
9596
+ ${"\u901A\u8FC7" === executionValidation.overall_validation ? "\u2705 \u9879\u76EE\u901A\u8FC7\u9A8C\u6536\uFF0C\u6EE1\u8DB3\u6240\u6709\u8981\u6C42\uFF0C\u53EF\u4EE5\u6B63\u5F0F\u4EA4\u4ED8\u3002" : "\u26A0\uFE0F \u9879\u76EE\u57FA\u672C\u7B26\u5408\u8981\u6C42\uFF0C\u4F46\u9700\u8981\u5B8C\u6210\u6807\u6CE8\u7684\u6539\u8FDB\u9879\u540E\u518D\u8FDB\u884C\u6700\u7EC8\u9A8C\u6536\u3002"}
9597
+
9598
+ ## \u{751F}\u{6210}\u{65F6}\u{95F4}
9599
+ ${new Date().toISOString()}
9600
+ `;
9601
+ }
9602
+ async generateTodoDocument(todoItems) {
9603
+ const highPriority = todoItems.filter((item)=>'high' === item.priority);
9604
+ const mediumPriority = todoItems.filter((item)=>'medium' === item.priority);
9605
+ const lowPriority = todoItems.filter((item)=>'low' === item.priority);
9606
+ return `# \u{5F85}\u{529E}\u{4E8B}\u{9879}\u{6E05}\u{5355}
9607
+
9608
+ ## \u{6982}\u{51B5}
9609
+ - **\u{603B}\u{8BA1}**: ${todoItems.length}\u{9879}
9610
+ - **\u{9AD8}\u{4F18}\u{5148}\u{7EA7}**: ${highPriority.length}\u{9879}
9611
+ - **\u{4E2D}\u{4F18}\u{5148}\u{7EA7}**: ${mediumPriority.length}\u{9879}
9612
+ - **\u{4F4E}\u{4F18}\u{5148}\u{7EA7}**: ${lowPriority.length}\u{9879}
9613
+
9614
+ ${highPriority.length > 0 ? `## \u{1F534} \u{9AD8}\u{4F18}\u{5148}\u{7EA7}\u{4E8B}\u{9879}
9615
+
9616
+ ${highPriority.map((item, index)=>`### ${index + 1}. ${item.item}
9617
+ - **\u{7C7B}\u{522B}**: ${item.category}
9618
+ - **\u{8BF4}\u{660E}**: ${item.description}
9619
+ - **\u{9884}\u{4F30}\u{5DE5}\u{4F5C}\u{91CF}**: ${item.estimated_effort}
9620
+
9621
+ `).join('\n')}` : ''}
9622
+
9623
+ ${mediumPriority.length > 0 ? `## \u{1F7E1} \u{4E2D}\u{4F18}\u{5148}\u{7EA7}\u{4E8B}\u{9879}
9624
+
9625
+ ${mediumPriority.map((item, index)=>`### ${index + 1}. ${item.item}
9626
+ - **\u{7C7B}\u{522B}**: ${item.category}
9627
+ - **\u{8BF4}\u{660E}**: ${item.description}
9628
+ - **\u{9884}\u{4F30}\u{5DE5}\u{4F5C}\u{91CF}**: ${item.estimated_effort}
9629
+
9630
+ `).join('\n')}` : ''}
9631
+
9632
+ ${lowPriority.length > 0 ? `## \u{1F7E2} \u{4F4E}\u{4F18}\u{5148}\u{7EA7}\u{4E8B}\u{9879}
9633
+
9634
+ ${lowPriority.map((item, index)=>`### ${index + 1}. ${item.item}
9635
+ - **\u{7C7B}\u{522B}**: ${item.category}
9636
+ - **\u{8BF4}\u{660E}**: ${item.description}
9637
+ - **\u{9884}\u{4F30}\u{5DE5}\u{4F5C}\u{91CF}**: ${item.estimated_effort}
9638
+
9639
+ `).join('\n')}` : ''}
9640
+
9641
+ ## \u{5EFA}\u{8BAE}\u{5904}\u{7406}\u{987A}\u{5E8F}
9642
+
9643
+ 1. **\u{7ACB}\u{5373}\u{5904}\u{7406}**: \u{9AD8}\u{4F18}\u{5148}\u{7EA7}\u{7684}\u{4EE3}\u{7801}\u{548C}\u{914D}\u{7F6E}\u{7C7B}\u{4E8B}\u{9879}
9644
+ 2. **\u{8FD1}\u{671F}\u{5904}\u{7406}**: \u{9AD8}\u{4F18}\u{5148}\u{7EA7}\u{7684}\u{6587}\u{6863}\u{548C}\u{6D4B}\u{8BD5}\u{7C7B}\u{4E8B}\u{9879}
9645
+ 3. **\u{540E}\u{7EED}\u{5904}\u{7406}**: \u{4E2D}\u{4F18}\u{5148}\u{7EA7}\u{4E8B}\u{9879}
9646
+ 4. **\u{6709}\u{65F6}\u{95F4}\u{65F6}\u{5904}\u{7406}**: \u{4F4E}\u{4F18}\u{5148}\u{7EA7}\u{4E8B}\u{9879}
9647
+
9648
+ ## \u{751F}\u{6210}\u{65F6}\u{95F4}
9649
+ ${new Date().toISOString()}
9650
+ `;
9651
+ }
9652
+ collectAllFiles(dir) {
9653
+ const files = [];
9654
+ try {
9655
+ if (external_fs_namespaceObject.existsSync(dir)) {
9656
+ const items = external_fs_namespaceObject.readdirSync(dir, {
9657
+ withFileTypes: true
9658
+ });
9659
+ for (const item of items){
9660
+ const fullPath = external_path_namespaceObject.join(dir, item.name);
9661
+ if (item.isFile()) files.push({
9662
+ path: fullPath,
9663
+ name: item.name,
9664
+ type: 'file',
9665
+ size: external_fs_namespaceObject.statSync(fullPath).size
9666
+ });
9667
+ else if (item.isDirectory()) files.push(...this.collectAllFiles(fullPath));
9668
+ }
9669
+ }
9670
+ } catch (error) {
9671
+ logger_logger.warn("\u6536\u96C6\u6587\u4EF6\u65F6\u51FA\u9519", error);
9672
+ }
9673
+ return files;
9674
+ }
9675
+ extractFeatureName(workspaceDir) {
9676
+ return external_path_namespaceObject.basename(workspaceDir);
9677
+ }
9678
+ }
9679
+ class RequirementHandlerService {
9680
+ alignAgent;
9681
+ architectAgent;
9682
+ atomizeAgent;
9683
+ approveAgent;
9684
+ automateAgent;
9685
+ assessAgent;
9686
+ constructor(){
9687
+ this.alignAgent = new AlignAgent();
9688
+ this.architectAgent = new ArchitectAgent();
9689
+ this.atomizeAgent = new AtomizeAgent();
9690
+ this.approveAgent = new ApproveAgent();
9691
+ this.automateAgent = new AutomateAgent();
9692
+ this.assessAgent = new AssessAgent();
9693
+ }
9694
+ async processRequirement(params) {
9695
+ const startTime = Date.now();
9696
+ try {
9697
+ const workspaceDir = this.createWorkspace(params.feature_name);
9698
+ logger_logger.info("6A\u9700\u6C42\u5904\u7406\u6D41\u7A0B\u5F00\u59CB", {
9699
+ featureName: params.feature_name,
9700
+ workspaceDir,
9701
+ stageToStop: params.stage_to_stop
9702
+ });
9703
+ const result = {
9704
+ success: false,
9705
+ message: '',
9706
+ feature_name: params.feature_name,
9707
+ completed_stages: [],
9708
+ current_stage: 'align',
9709
+ stage_results: [],
9710
+ output_files: [],
9711
+ human_confirmations_pending: []
9712
+ };
9713
+ let previousStageOutput = null;
9714
+ if (this.shouldExecuteStage('align', params.stage_to_stop)) {
9715
+ logger_logger.info("\u6267\u884C\u9636\u6BB51: \u9700\u6C42\u5BF9\u9F50");
9716
+ result.current_stage = 'align';
9717
+ const alignResult = await this.alignAgent.execute({
9718
+ requirement_text: params.requirement_text,
9719
+ project_context: params.project_context,
9720
+ feature_name: params.feature_name,
9721
+ workspace_dir: workspaceDir
9722
+ });
9723
+ result.stage_results.push(alignResult);
9724
+ result.completed_stages.push('align');
9725
+ previousStageOutput = alignResult;
9726
+ if (params.enable_human_confirmation && alignResult.human_confirmation_required) {
9727
+ result.human_confirmations_pending.push({
9728
+ stage: 'align',
9729
+ confirmation_type: 'stage_completion',
9730
+ details: "\u9700\u6C42\u5BF9\u9F50\u9636\u6BB5\u5B8C\u6210\uFF0C\u8BF7\u786E\u8BA4\u9700\u6C42\u7406\u89E3\u6B63\u786E\u6027"
9731
+ });
9732
+ if ('align' === params.stage_to_stop) {
9733
+ result.success = true;
9734
+ result.message = "\u9700\u6C42\u5BF9\u9F50\u9636\u6BB5\u5DF2\u5B8C\u6210\uFF0C\u7B49\u5F85\u4EBA\u5DE5\u786E\u8BA4";
9735
+ result.output_files = await this.collectOutputFiles(params.feature_name);
9736
+ return result;
9737
+ }
9738
+ }
9739
+ }
9740
+ if (this.shouldExecuteStage('architect', params.stage_to_stop) && previousStageOutput) {
9741
+ logger_logger.info("\u6267\u884C\u9636\u6BB52: \u7CFB\u7EDF\u67B6\u6784\u8BBE\u8BA1");
9742
+ result.current_stage = 'architect';
9743
+ const architectResult = await this.architectAgent.execute({
9744
+ previous_stage_output: previousStageOutput,
9745
+ workspace_dir: workspaceDir
9746
+ });
9747
+ result.stage_results.push(architectResult);
9748
+ result.completed_stages.push('architect');
9749
+ previousStageOutput = architectResult;
9750
+ if (params.enable_human_confirmation && architectResult.human_confirmation_required) {
9751
+ result.human_confirmations_pending.push({
9752
+ stage: 'architect',
9753
+ confirmation_type: 'stage_completion',
9754
+ details: "\u7CFB\u7EDF\u67B6\u6784\u8BBE\u8BA1\u9636\u6BB5\u5B8C\u6210\uFF0C\u8BF7\u786E\u8BA4\u67B6\u6784\u8BBE\u8BA1\u5408\u7406\u6027"
9755
+ });
9756
+ if ('architect' === params.stage_to_stop) {
9757
+ result.success = true;
9758
+ result.message = "\u7CFB\u7EDF\u67B6\u6784\u8BBE\u8BA1\u9636\u6BB5\u5DF2\u5B8C\u6210\uFF0C\u7B49\u5F85\u4EBA\u5DE5\u786E\u8BA4";
9759
+ result.output_files = await this.collectOutputFiles(params.feature_name);
9760
+ return result;
9761
+ }
9762
+ }
9763
+ }
9764
+ if (this.shouldExecuteStage('atomize', params.stage_to_stop) && previousStageOutput) {
9765
+ logger_logger.info("\u6267\u884C\u9636\u6BB53: \u539F\u5B50\u4EFB\u52A1\u62C6\u5206");
9766
+ result.current_stage = 'atomize';
9767
+ const atomizeResult = await this.atomizeAgent.execute({
9768
+ previous_stage_output: previousStageOutput,
9769
+ workspace_dir: workspaceDir
9770
+ });
9771
+ result.stage_results.push(atomizeResult);
9772
+ result.completed_stages.push('atomize');
9773
+ previousStageOutput = atomizeResult;
9774
+ if (params.enable_human_confirmation && atomizeResult.human_confirmation_required) {
9775
+ result.human_confirmations_pending.push({
9776
+ stage: 'atomize',
9777
+ confirmation_type: 'stage_completion',
9778
+ details: "\u539F\u5B50\u4EFB\u52A1\u62C6\u5206\u9636\u6BB5\u5B8C\u6210\uFF0C\u8BF7\u786E\u8BA4\u4EFB\u52A1\u62C6\u5206\u5408\u7406\u6027"
9779
+ });
9780
+ if ('atomize' === params.stage_to_stop) {
9781
+ result.success = true;
9782
+ result.message = "\u539F\u5B50\u4EFB\u52A1\u62C6\u5206\u9636\u6BB5\u5DF2\u5B8C\u6210\uFF0C\u7B49\u5F85\u4EBA\u5DE5\u786E\u8BA4";
9783
+ result.output_files = await this.collectOutputFiles(params.feature_name);
9784
+ return result;
9785
+ }
9786
+ }
9787
+ }
9788
+ if (this.shouldExecuteStage('approve', params.stage_to_stop) && previousStageOutput) {
9789
+ logger_logger.info("\u6267\u884C\u9636\u6BB54: \u4EFB\u52A1\u5BA1\u67E5");
9790
+ result.current_stage = 'approve';
9791
+ const approveResult = await this.approveAgent.execute({
9792
+ all_previous_outputs: result.stage_results,
9793
+ workspace_dir: workspaceDir
9794
+ });
9795
+ result.stage_results.push(approveResult);
9796
+ result.completed_stages.push('approve');
9797
+ previousStageOutput = approveResult;
9798
+ if (params.enable_human_confirmation && approveResult.human_confirmation_required) {
9799
+ result.human_confirmations_pending.push({
9800
+ stage: 'approve',
9801
+ confirmation_type: 'stage_completion',
9802
+ details: "\u4EFB\u52A1\u5BA1\u67E5\u9636\u6BB5\u5B8C\u6210\uFF0C\u8BF7\u786E\u8BA4\u5BA1\u67E5\u7ED3\u679C"
9803
+ });
9804
+ if ('approve' === params.stage_to_stop) {
9805
+ result.success = true;
9806
+ result.message = "\u4EFB\u52A1\u5BA1\u67E5\u9636\u6BB5\u5DF2\u5B8C\u6210\uFF0C\u7B49\u5F85\u4EBA\u5DE5\u786E\u8BA4";
9807
+ result.output_files = await this.collectOutputFiles(params.feature_name);
9808
+ return result;
9809
+ }
9810
+ }
9811
+ }
9812
+ if (this.shouldExecuteStage('automate', params.stage_to_stop) && previousStageOutput) {
9813
+ logger_logger.info("\u6267\u884C\u9636\u6BB55: \u4EFB\u52A1\u81EA\u52A8\u6267\u884C");
9814
+ result.current_stage = 'automate';
9815
+ const automateResult = await this.automateAgent.execute({
9816
+ all_previous_outputs: result.stage_results,
9817
+ workspace_dir: workspaceDir,
9818
+ include_tests: params.custom_config?.include_tests ?? true,
9819
+ include_docs: params.custom_config?.include_docs ?? true
9820
+ });
9821
+ result.stage_results.push(automateResult);
9822
+ result.completed_stages.push('automate');
9823
+ previousStageOutput = automateResult;
9824
+ if (params.enable_human_confirmation && automateResult.human_confirmation_required) {
9825
+ result.human_confirmations_pending.push({
9826
+ stage: 'automate',
9827
+ confirmation_type: 'stage_completion',
9828
+ details: "\u4EFB\u52A1\u81EA\u52A8\u6267\u884C\u9636\u6BB5\u5B8C\u6210\uFF0C\u8BF7\u786E\u8BA4\u6267\u884C\u7ED3\u679C"
9829
+ });
9830
+ if ('automate' === params.stage_to_stop) {
9831
+ result.success = true;
9832
+ result.message = "\u4EFB\u52A1\u81EA\u52A8\u6267\u884C\u9636\u6BB5\u5DF2\u5B8C\u6210\uFF0C\u7B49\u5F85\u4EBA\u5DE5\u786E\u8BA4";
9833
+ result.output_files = await this.collectOutputFiles(params.feature_name);
9834
+ return result;
9835
+ }
9836
+ }
9837
+ }
9838
+ if (this.shouldExecuteStage('assess', params.stage_to_stop) && previousStageOutput) {
9839
+ logger_logger.info("\u6267\u884C\u9636\u6BB56: \u6267\u884C\u8D28\u91CF\u8BC4\u4F30");
9840
+ result.current_stage = 'assess';
9841
+ const assessResult = await this.assessAgent.execute({
9842
+ all_previous_outputs: result.stage_results,
9843
+ workspace_dir: workspaceDir
9844
+ });
9845
+ result.stage_results.push(assessResult);
9846
+ result.completed_stages.push('assess');
9847
+ if (params.enable_human_confirmation && assessResult.human_confirmation_required) result.human_confirmations_pending.push({
9848
+ stage: 'assess',
9849
+ confirmation_type: 'stage_completion',
9850
+ details: "\u6267\u884C\u8D28\u91CF\u8BC4\u4F30\u9636\u6BB5\u5B8C\u6210\uFF0C\u8BF7\u786E\u8BA4\u8BC4\u4F30\u7ED3\u679C"
9851
+ });
9852
+ }
9853
+ result.output_files = await this.collectOutputFiles(params.feature_name);
9854
+ const duration = Date.now() - startTime;
9855
+ result.success = true;
9856
+ result.message = `6A\u{9700}\u{6C42}\u{5904}\u{7406}\u{6D41}\u{7A0B}\u{6267}\u{884C}\u{6210}\u{529F}\u{FF0C}\u{5B8C}\u{6210}\u{9636}\u{6BB5}: ${result.completed_stages.join(', ')}\u{FF0C}\u{8017}\u{65F6} ${duration}ms`;
9857
+ logger_logger.info("6A\u9700\u6C42\u5904\u7406\u6D41\u7A0B\u5B8C\u6210", {
9858
+ featureName: params.feature_name,
9859
+ completedStages: result.completed_stages,
9860
+ duration
9861
+ });
9862
+ return result;
9863
+ } catch (error) {
9864
+ logger_logger.error("6A\u9700\u6C42\u5904\u7406\u6D41\u7A0B\u6267\u884C\u5931\u8D25", {
9865
+ error: error.message,
9866
+ stack: error.stack,
9867
+ featureName: params.feature_name
9868
+ });
9869
+ const result = {
9870
+ success: false,
9871
+ message: `6A\u{9700}\u{6C42}\u{5904}\u{7406}\u{6D41}\u{7A0B}\u{6267}\u{884C}\u{5931}\u{8D25}: ${error.message}`,
9872
+ feature_name: params.feature_name,
9873
+ completed_stages: [],
9874
+ current_stage: 'align',
9875
+ stage_results: [],
9876
+ output_files: [],
9877
+ human_confirmations_pending: []
9878
+ };
9879
+ if (error instanceof RequirementHandlerError) result.message += ` (${error.code})`;
9880
+ return result;
9881
+ }
9882
+ }
9883
+ createWorkspace(featureName) {
9884
+ try {
9885
+ if (!featureName || 'string' != typeof featureName) throw new Error(`\u{65E0}\u{6548}\u{7684}\u{529F}\u{80FD}\u{540D}\u{79F0}: ${featureName}`);
9886
+ const baseDir = process.cwd();
9887
+ if (!baseDir || 'string' != typeof baseDir) throw new Error("\u65E0\u6CD5\u83B7\u53D6\u5F53\u524D\u5DE5\u4F5C\u76EE\u5F55");
9888
+ const outputDir = external_path_namespaceObject.join(baseDir, 'output');
9889
+ const requirementDir = external_path_namespaceObject.join(outputDir, 'requirement-handler');
9890
+ const workspaceDir = external_path_namespaceObject.join(requirementDir, featureName);
9891
+ logger_logger.info("\u521B\u5EFA\u5DE5\u4F5C\u7A7A\u95F4", {
9892
+ baseDir,
9893
+ outputDir,
9894
+ requirementDir,
9895
+ workspaceDir,
9896
+ featureName
9897
+ });
9898
+ if (!external_fs_namespaceObject.existsSync(outputDir)) {
9899
+ external_fs_namespaceObject.mkdirSync(outputDir, {
9900
+ recursive: true
9901
+ });
9902
+ logger_logger.info("\u521B\u5EFA\u8F93\u51FA\u76EE\u5F55", {
9903
+ outputDir
9904
+ });
9905
+ }
9906
+ if (!external_fs_namespaceObject.existsSync(requirementDir)) {
9907
+ external_fs_namespaceObject.mkdirSync(requirementDir, {
9908
+ recursive: true
9909
+ });
9910
+ logger_logger.info("\u521B\u5EFA\u9700\u6C42\u5904\u7406\u76EE\u5F55", {
9911
+ requirementDir
9912
+ });
9913
+ }
9914
+ if (!external_fs_namespaceObject.existsSync(workspaceDir)) {
9915
+ external_fs_namespaceObject.mkdirSync(workspaceDir, {
9916
+ recursive: true
9917
+ });
9918
+ logger_logger.info("\u521B\u5EFA\u5DE5\u4F5C\u7A7A\u95F4\u76EE\u5F55", {
9919
+ workspaceDir
9920
+ });
9921
+ }
9922
+ return workspaceDir;
9923
+ } catch (error) {
9924
+ logger_logger.error("\u521B\u5EFA\u5DE5\u4F5C\u7A7A\u95F4\u5931\u8D25", {
9925
+ featureName,
9926
+ error: error.message,
9927
+ stack: error.stack
9928
+ });
9929
+ throw new RequirementHandlerError(`\u{521B}\u{5EFA}\u{5DE5}\u{4F5C}\u{7A7A}\u{95F4}\u{5931}\u{8D25}: ${error.message}`, types_StageErrorCodes.WORKSPACE_CREATION_FAILED, 'workspace', {
9930
+ featureName,
9931
+ error: error.message
9932
+ });
9933
+ }
9934
+ }
9935
+ shouldExecuteStage(stage, stopAt) {
9936
+ if (!stopAt || 'complete' === stopAt) return true;
9937
+ const stages = [
9938
+ 'align',
9939
+ 'architect',
9940
+ 'atomize',
9941
+ 'approve',
9942
+ 'automate',
9943
+ 'assess'
9944
+ ];
9945
+ const currentIndex = stages.indexOf(stage);
9946
+ const stopIndex = stages.indexOf(stopAt);
9947
+ return currentIndex <= stopIndex;
9948
+ }
9949
+ async collectOutputFiles(featureName) {
9950
+ const files = [];
9951
+ try {
9952
+ const projectRoot = process.cwd();
9953
+ const aicoDocsDir = external_path_namespaceObject.join(projectRoot, '.aico', 'docs', featureName);
9954
+ if (external_fs_namespaceObject.existsSync(aicoDocsDir)) {
9955
+ const aicoFiles = this.collectFilesFromDirectory(aicoDocsDir);
9956
+ files.push(...aicoFiles);
9957
+ }
9958
+ const workspaceDir = external_path_namespaceObject.join(projectRoot, 'output', 'requirement-handler', featureName);
9959
+ if (external_fs_namespaceObject.existsSync(workspaceDir)) {
9960
+ const workspaceFiles = this.collectFilesFromDirectory(workspaceDir);
9961
+ files.push(...workspaceFiles);
9962
+ }
9963
+ } catch (error) {
9964
+ logger_logger.warn("\u6536\u96C6\u8F93\u51FA\u6587\u4EF6\u65F6\u51FA\u9519", {
9965
+ featureName,
9966
+ error: error.message
9967
+ });
9968
+ }
9969
+ return files;
9970
+ }
9971
+ collectFilesFromDirectory(dir) {
9972
+ const files = [];
9973
+ try {
9974
+ if (!dir || 'string' != typeof dir) return files;
9975
+ if (external_fs_namespaceObject.existsSync(dir)) {
9976
+ const items = external_fs_namespaceObject.readdirSync(dir, {
9977
+ withFileTypes: true
9978
+ });
9979
+ for (const item of items)if (item.isFile()) files.push(external_path_namespaceObject.join(dir, item.name));
9980
+ else if (item.isDirectory()) {
9981
+ const subFiles = this.collectFilesFromDirectory(external_path_namespaceObject.join(dir, item.name));
9982
+ files.push(...subFiles);
9983
+ }
9984
+ }
9985
+ } catch (error) {
9986
+ logger_logger.warn("\u6536\u96C6\u76EE\u5F55\u6587\u4EF6\u65F6\u51FA\u9519", {
9987
+ dir,
9988
+ error: error.message
9989
+ });
9990
+ }
9991
+ return files;
9992
+ }
9993
+ }
9994
+ objectType({
9995
+ requirement_text: stringType().min(10).describe("\u7528\u6237\u7684\u539F\u59CB\u9700\u6C42\u63CF\u8FF0\u6587\u672C"),
9996
+ project_context: stringType().optional().describe("\u9879\u76EE\u4E0A\u4E0B\u6587\u4FE1\u606F\uFF08\u53EF\u9009\uFF09"),
9997
+ feature_name: stringType().describe("\u529F\u80FD\u540D\u79F0\uFF0C\u7528\u4E8E\u751F\u6210\u8F93\u51FA\u6587\u4EF6\u540D"),
9998
+ enable_human_confirmation: booleanType().default(true).describe("\u662F\u5426\u542F\u7528\u4EBA\u5DE5\u786E\u8BA4\u673A\u5236"),
9999
+ stage_to_stop: enumType([
10000
+ "align",
10001
+ "architect",
10002
+ "atomize",
10003
+ "approve",
10004
+ "automate",
10005
+ "assess",
10006
+ "complete"
10007
+ ]).default("complete").describe("\u6307\u5B9A\u5728\u54EA\u4E2A\u9636\u6BB5\u505C\u6B62\uFF08\u7528\u4E8E\u8C03\u8BD5\uFF09"),
10008
+ custom_config: objectType({
10009
+ analysis_depth: enumType([
10010
+ "basic",
10011
+ "detailed",
10012
+ "comprehensive"
10013
+ ]).default("detailed"),
10014
+ include_tests: booleanType().default(true),
10015
+ include_docs: booleanType().default(true)
10016
+ }).optional().describe("\u81EA\u5B9A\u4E49\u914D\u7F6E\u9009\u9879")
10017
+ });
10018
+ const requirementHandlerTool = {
10019
+ name: "\u9700\u6C42\u5904\u7406\u667A\u80FD\u4F53",
10020
+ description: "\u4EE5\u9700\u6C42\u6307\u6325\u5B98\u667A\u80FD\u4F53\u8C03\u5EA6\u9700\u6C42\u5BF9\u9F50\u667A\u80FD\u4F53\uFF0C\u539F\u5B50\u4EFB\u52A1\u62C6\u5206\u5BA1\u67E5\u667A\u80FD\u4F53\uFF0C\u4EFB\u52A1\u81EA\u52A8\u6267\u884C\u667A\u80FD\u4F53\uFF0C\u6267\u884C\u8D28\u91CF\u8BC4\u4F30\u667A\u80FD\u4F53\u7684\u65B9\u5F0F\u5B8C\u6210\u5BF9\u9700\u6C42\u7684\u5904\u7406",
10021
+ inputSchema: {
10022
+ requirement_text: stringType().min(10).describe("\u7528\u6237\u7684\u539F\u59CB\u9700\u6C42\u63CF\u8FF0\u6587\u672C"),
10023
+ project_context: stringType().optional().describe("\u9879\u76EE\u4E0A\u4E0B\u6587\u4FE1\u606F\uFF08\u53EF\u9009\uFF09"),
10024
+ feature_name: stringType().describe("\u529F\u80FD\u540D\u79F0\uFF0C\u7528\u4E8E\u751F\u6210\u8F93\u51FA\u6587\u4EF6\u540D"),
10025
+ enable_human_confirmation: booleanType().default(true).describe("\u662F\u5426\u542F\u7528\u4EBA\u5DE5\u786E\u8BA4\u673A\u5236"),
10026
+ stage_to_stop: enumType([
10027
+ "align",
10028
+ "architect",
10029
+ "atomize",
10030
+ "approve",
10031
+ "automate",
10032
+ "assess",
10033
+ "complete"
10034
+ ]).default("complete").describe("\u6307\u5B9A\u5728\u54EA\u4E2A\u9636\u6BB5\u505C\u6B62\uFF08\u7528\u4E8E\u8C03\u8BD5\uFF09"),
10035
+ custom_config: objectType({
10036
+ analysis_depth: enumType([
10037
+ "basic",
10038
+ "detailed",
10039
+ "comprehensive"
10040
+ ]).default("detailed"),
10041
+ include_tests: booleanType().default(true),
10042
+ include_docs: booleanType().default(true)
10043
+ }).optional().describe("\u81EA\u5B9A\u4E49\u914D\u7F6E\u9009\u9879")
10044
+ },
10045
+ handler: async (args)=>{
10046
+ const service = new RequirementHandlerService();
10047
+ try {
10048
+ logger_logger.info("\u9700\u6C42\u5904\u7406\u667A\u80FD\u4F53\u5F00\u59CB\u6267\u884C", {
10049
+ args: JSON.stringify(args, null, 2),
10050
+ featureName: args.feature_name,
10051
+ stageToStop: args.stage_to_stop
10052
+ });
10053
+ const result = await service.processRequirement(args);
10054
+ return {
10055
+ content: [
10056
+ {
10057
+ type: "text",
10058
+ text: JSON.stringify({
10059
+ success: true,
10060
+ message: "\u9700\u6C42\u5904\u7406\u667A\u80FD\u4F53\u6267\u884C\u6210\u529F",
10061
+ data: result
10062
+ }, null, 2)
10063
+ }
10064
+ ]
10065
+ };
10066
+ } catch (error) {
10067
+ logger_logger.error("\u9700\u6C42\u5904\u7406\u667A\u80FD\u4F53\u6267\u884C\u5931\u8D25", error);
10068
+ return {
10069
+ content: [
10070
+ {
10071
+ type: "text",
10072
+ text: JSON.stringify({
10073
+ success: false,
10074
+ message: `\u{9700}\u{6C42}\u{5904}\u{7406}\u{667A}\u{80FD}\u{4F53}\u{6267}\u{884C}\u{5931}\u{8D25}: ${error.message}`,
10075
+ error: {
10076
+ code: error.code || 'UNKNOWN_ERROR',
10077
+ context: error.context
10078
+ }
10079
+ }, null, 2)
10080
+ }
10081
+ ],
10082
+ isError: true
10083
+ };
10084
+ }
10085
+ }
10086
+ };
7917
10087
  function createMcpServer() {
7918
10088
  const server = new mcp_js_namespaceObject.McpServer({
7919
10089
  name: SERVICE_CONFIG.name,
@@ -7927,9 +10097,9 @@ ${allTextContent || "\u672A\u8BC6\u522B\u5230\u6587\u5B57\u5185\u5BB9"}
7927
10097
  changeSummarizer,
7928
10098
  imageAnalysisTool,
7929
10099
  imageConverterTool,
7930
- bugFixAgentTool,
7931
10100
  codeGeneratorTool,
7932
- imageRecognitionAgentTool
10101
+ imageRecognitionAgentTool,
10102
+ requirementHandlerTool
7933
10103
  ];
7934
10104
  tools.forEach((tool)=>{
7935
10105
  server.tool(tool.name, tool.description, tool.inputSchema, tool.handler);