Skip to content

Commit 181f392

Browse files
committed
refactor(remote-agent): 精简代码并删除多余注释
删除了多个文件中的冗余注释和未使用的代码,提高了代码可读性和可维护性。特别是: - 移除了bug-fix-agent.ts中的内联注释 - 清理了bug-fix-playbook.ts中的格式和多余文档 - 优化了feature-analysis-agent.ts的导入,移除了未使用的generateFeatureAnalysisReport方法 代码整体结构保持不变,只是清理了不必要的实现细节注释和未使用代码。
1 parent 197db9b commit 181f392

File tree

3 files changed

+6
-82
lines changed

3 files changed

+6
-82
lines changed

packages/remote-agent/src/agents/bug-fix-agent.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,8 @@ export class BugFixAgent extends AIAgent {
8686
* 适用于简单更改或用户提供具体指令的情况
8787
*/
8888
private async processDirectFix(userInput: string, startTime: number, context?: any): Promise<BugFixAgentResponse> {
89-
// 增强用户输入,添加特定的代码修复指令
9089
const directFixPrompt = this.bugFixPlaybook.preparePrompt(userInput, context);
91-
92-
// 使用现有的工具链处理流程,但使用修改后的提示
9390
const response = await super.processInputWithToolChaining(directFixPrompt, startTime, context) as AgentResponse;
94-
95-
// 提取有关修改文件的信息
9691
const modifiedFiles = this.extractModifiedFiles(response.toolResults);
9792

9893
return {
@@ -107,54 +102,41 @@ export class BugFixAgent extends AIAgent {
107102
* 更彻底的方法,适用于复杂重构
108103
*/
109104
private async processAnalysisFirstFix(userInput: string, startTime: number, context?: any): Promise<BugFixAgentResponse> {
110-
// 阶段 1: 分析阶段
111105
this.log('阶段 1: 在修复前分析代码库');
112106
const analysisMessages = await this.bugFixPlaybook.buildMessagesForRound(userInput, context, 1);
113107

114-
// 调用 LLM 进行分析
115108
const analysisResponse = await this.callLLM(analysisMessages);
116109
const parsedAnalysis = FunctionParser.parseResponse(analysisResponse);
117110

118-
// 执行分析工具
119111
const analysisResults = await this.toolExecutor.executeToolsWithContext({
120112
round: 1,
121113
previousResults: [],
122114
userInput,
123115
workspacePath: this.config.workspacePath || process.cwd()
124116
}, parsedAnalysis.functionCalls);
125117

126-
// 阶段 2: 修复阶段
127118
this.log('阶段 2: 基于分析应用代码修复');
128119
const fixMessages = await this.bugFixPlaybook.buildMessagesForRound(userInput, context, 2);
129120

130-
// 调用 LLM 创建修复方案
131121
const fixResponse = await this.callLLM(fixMessages);
132122
const parsedFix = FunctionParser.parseResponse(fixResponse);
133123

134-
// 执行修复工具
135124
const fixResults = await this.toolExecutor.executeToolsWithContext({
136125
round: 2,
137126
previousResults: analysisResults,
138127
userInput,
139128
workspacePath: this.config.workspacePath || process.cwd()
140129
}, parsedFix.functionCalls);
141130

142-
// 组合所有工具结果
143131
const allToolResults = [...analysisResults, ...fixResults];
144132

145-
// 阶段 3: 验证(如果启用)
146133
if (this.bugFixConfig.verifyChanges) {
147134
this.log('阶段 3: 验证代码修复');
148-
const verificationPrompt = this.bugFixPlaybook.prepareVerificationPrompt(userInput, allToolResults);
149-
150-
// 从 LLM 获取验证响应
151135
const verificationMessages = await this.bugFixPlaybook.buildMessagesForRound(userInput, context, 3);
152136
const verificationResponse = await this.callLLM(verificationMessages);
153137

154-
// 生成最终响应
155138
const finalText = await this.generateBugFixFinalResponse(userInput, verificationResponse, allToolResults, 3);
156139

157-
// 提取有关修改文件的信息
158140
const modifiedFiles = this.extractModifiedFiles(allToolResults);
159141

160142
return {
@@ -168,7 +150,6 @@ export class BugFixAgent extends AIAgent {
168150
};
169151
}
170152

171-
// 如果未启用验证,生成最终响应
172153
const summaryPrompt = this.bugFixPlaybook.prepareSummaryPrompt(
173154
userInput,
174155
allToolResults,
@@ -181,8 +162,6 @@ export class BugFixAgent extends AIAgent {
181162
] as CoreMessage[];
182163

183164
const summaryResponse = await this.callLLM(summaryMessages);
184-
185-
// 提取有关修改文件的信息
186165
const modifiedFiles = this.extractModifiedFiles(allToolResults);
187166

188167
return {
@@ -196,9 +175,6 @@ export class BugFixAgent extends AIAgent {
196175
};
197176
}
198177

199-
/**
200-
* 从工具结果中提取修改的文件列表
201-
*/
202178
private extractModifiedFiles(toolResults: ToolResult[]): string[] {
203179
const modifiedFiles = new Set<string>();
204180

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,34 @@
1-
import { CoreMessage } from "ai";
2-
import { AIAgent, AgentConfig, AgentResponse } from "../agent";
3-
import { ToolResult } from "../agent/tool-definition";
1+
import { AgentConfig, AgentResponse, AIAgent } from "../agent";
42
import { FeatureRequestPlaybook } from "../playbooks/feature-request-playbook";
5-
import { generateText } from "ai";
63

7-
/**
8-
* FeatureAnalysisAgent 配置选项
9-
*/
104
export interface FeatureAnalysisAgentConfig extends AgentConfig {
11-
// 分析策略: 'requirements-first' (默认) 或 'technical-first'
125
analysisStrategy?: 'requirements-first' | 'technical-first';
13-
14-
// 是否生成详细的技术文档
156
generateTechnicalDocs?: boolean;
16-
17-
// 是否进行代码兼容性分析
187
analyzeCompatibility?: boolean;
198
}
209

21-
/**
22-
* FeatureAnalysisAgent 专注于功能请求分析和澄清的 Agent
23-
* 扩展了基础 AIAgent,添加了功能分析的专用功能
24-
*/
2510
export class FeatureAnalysisAgent extends AIAgent {
2611
protected featureAnalysisConfig: FeatureAnalysisAgentConfig;
2712
protected featureRequestPlaybook: FeatureRequestPlaybook;
2813

2914
constructor(config: FeatureAnalysisAgentConfig = {}) {
30-
// 初始化基础 AIAgent
3115
super(config);
32-
33-
// 设置 FeatureAnalysis 配置的默认值
3416
this.featureAnalysisConfig = {
3517
analysisStrategy: 'requirements-first',
3618
generateTechnicalDocs: true,
3719
analyzeCompatibility: true,
3820
...config
3921
};
4022

41-
// 初始化 FeatureRequestPlaybook
4223
this.featureRequestPlaybook = new FeatureRequestPlaybook();
43-
4424
this.log('FeatureAnalysisAgent 已初始化,使用策略:', this.featureAnalysisConfig.analysisStrategy);
4525
}
4626

4727
/**
4828
* 重写 start 方法以使用特定的 Playbook
4929
*/
5030
async start(input: string): Promise<AgentResponse> {
51-
// 使用 FeatureRequestPlaybook 替换默认的 Playbook
5231
this.playbook = this.featureRequestPlaybook;
5332
return super.start(input);
5433
}
55-
56-
/**
57-
* 生成功能分析报告
58-
*/
59-
private async generateFeatureAnalysisReport(
60-
userInput: string,
61-
lastLLMResponse: string,
62-
toolResults: ToolResult[],
63-
totalRounds: number
64-
): Promise<string> {
65-
const summaryPrompt = this.featureRequestPlaybook.prepareSummaryPrompt(userInput, toolResults, lastLLMResponse);
66-
const verificationPrompt = this.featureRequestPlaybook.prepareVerificationPrompt(userInput, toolResults);
67-
68-
const messages: CoreMessage[] = [
69-
{ role: "system", content: this.featureRequestPlaybook.getSystemPrompt() },
70-
{ role: "user", content: summaryPrompt },
71-
{ role: "user", content: verificationPrompt }
72-
];
73-
74-
const { text } = await generateText({
75-
model: this.llmConfig.openai(this.llmConfig.fullModel),
76-
messages,
77-
temperature: 0.3,
78-
maxTokens: 4000
79-
});
80-
81-
return text;
82-
}
83-
}
34+
}

packages/remote-agent/src/playbooks/bug-fix-playbook.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import { CoreMessage } from "ai";
22
import { Playbook } from "./base-playbook";
33
import { ToolResult } from "../agent/tool-definition";
44

5-
/**
6-
* BugFixPlaybook 专注于管理代码修复和bug修复相关的提示词策略
7-
*/
85
export class BugFixPlaybook extends Playbook {
96
constructor() {
107
super(`你是一个专业的代码修复专家,擅长分析和修复代码中的缺陷。
@@ -103,10 +100,10 @@ ${this.preparePrompt(input, context)}
103100
*/
104101
prepareSummaryPrompt(userInput: string, toolResults: ToolResult[], currentState: string): string {
105102
const modifiedFiles = toolResults
106-
.filter(r => r.success &&
103+
.filter(r => r.success &&
107104
(r.functionCall.name === 'str-replace-editor' || r.functionCall.name === 'fs-write-file'))
108105
.map(r => r.functionCall.parameters.targetFile);
109-
106+
110107
const uniqueModifiedFiles = [...new Set(modifiedFiles)];
111108

112109
return `请基于以下信息,生成一个关于代码修复的详细技术报告:
@@ -133,10 +130,10 @@ ${uniqueModifiedFiles.map(file => `- ${file}`).join('\n')}
133130
*/
134131
prepareVerificationPrompt(userInput: string, results: ToolResult[]): string {
135132
const modifiedFiles = results
136-
.filter(r => r.success &&
133+
.filter(r => r.success &&
137134
(r.functionCall.name === 'str-replace-editor' || r.functionCall.name === 'fs-write-file'))
138135
.map(r => r.functionCall.parameters.targetFile);
139-
136+
140137
const uniqueModifiedFiles = [...new Set(modifiedFiles)];
141138

142139
return `验证阶段:检查代码修复的质量和完整性。

0 commit comments

Comments
 (0)