Skip to content

Commit a08cf87

Browse files
committed
refactor: enhance issue analysis prompt and add context extraction for user inquiries
1 parent 87a4afb commit a08cf87

File tree

5 files changed

+234
-58
lines changed

5 files changed

+234
-58
lines changed

packages/context-worker/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ export {
2828
SymbolKind
2929
} from './code-context/base/SymbolExtractor';
3030

31+
export {
32+
InstantiationService,
33+
providerContainer
34+
} from './base/common/instantiation/instantiationService';
35+
export * from './base/common/instantiation/instantiation';
36+
3137
// Language utilities
3238
export { inferLanguage } from './base/common/languages/languages';
3339

packages/remote-agent/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"cheerio": "^1.0.0",
7373
"dotenv": "^16.5.0",
7474
"express": "^5.1.0",
75+
"jsdom": "^26.1.0",
7576
"turndown": "^7.2.0"
7677
},
7778
"devDependencies": {
@@ -83,6 +84,7 @@
8384
"@rollup/plugin-typescript": "^11.1.6",
8485
"@types/express": "^5.0.1",
8586
"@types/jest": "^29.5.11",
87+
"@types/jsdom": "^21.1.7",
8688
"@types/node": "^20.17.46",
8789
"@typescript-eslint/eslint-plugin": "^7.1.0",
8890
"@typescript-eslint/parser": "^7.1.0",

packages/remote-agent/quick-test-agent.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ const issuesToTest = [
1717
description: 'Analyze GitHub issue #105 in unit-mesh/autodev-workbench'
1818
},
1919
// Add more issues here, for example:
20-
{
21-
owner: 'unit-mesh',
22-
repo: 'autodev-workbench',
23-
issueNumber: 104,
24-
description: 'Analyze GitHub issue #104 in unit-mesh/autodev-workbench'
25-
}
20+
// {
21+
// owner: 'unit-mesh',
22+
// repo: 'autodev-workbench',
23+
// issueNumber: 104,
24+
// description: 'Analyze GitHub issue #104 in unit-mesh/autodev-workbench'
25+
// }
2626
];
2727

2828
async function quickTest (issueConfig) {
@@ -62,7 +62,7 @@ async function quickTest (issueConfig) {
6262
console.log(`🔧 Tools: ${agent.getAvailableTools().join(', ')}`)
6363

6464
// Simple test
65-
console.log('\n🧪 Running test for current issue...')
65+
console.log('🧪 Running test for current issue...')
6666
const response = await agent.start(
6767
issueConfig.description,
6868
{

packages/remote-agent/src/agent/final-report-generator.ts

Lines changed: 101 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -25,91 +25,124 @@ export class FinalReportGenerator {
2525
toolResultsCount: allToolResults.length
2626
});
2727

28-
const resultsByRound = this.groupResultsByRound(allToolResults);
28+
// const resultsByRound = this.groupResultsByRound(allToolResults);
2929
const successfulResults = allToolResults.filter(r => r.success);
3030
const failedResults = allToolResults.filter(r => !r.success);
3131

3232
// const executionSummary = this.buildExecutionSummary(resultsByRound, totalRounds);
3333
const toolResultsSummary = this.buildToolResultsSummary(successfulResults);
34+
const issueContext = this.extractIssueContext(userInput, toolResultsSummary);
3435

35-
const comprehensivePrompt = `You are an expert GitHub issue analyst tasked with providing a comprehensive PROPOSED ACTION PLAN based on the analysis results. The plan should detail what the user should do next to address their issue.
36+
const comprehensivePrompt = `You are an expert GitHub issue analyst and software architect. Your task is to provide a comprehensive response that DIRECTLY ADDRESSES the user's specific issue/question while also providing a detailed development action plan.
3637
37-
## 📝 Original User Request
38+
## 📝 User's Specific Issue/Question
3839
${userInput}
3940
40-
## 🔍 Analysis Data Available
41+
## 🔍 Analysis Results from Code Investigation
4142
${toolResultsSummary}
4243
4344
${failedResults.length > 0 ? `## ⚠️ Analysis Limitations
44-
Some tools failed to execute:
45+
Some analysis tools encountered issues:
4546
${failedResults.map(r => `- ${r.functionCall.name}: ${r.error}`).join('\n')}
4647
` : ''}
4748
4849
## ✅ Required Response Format
4950
50-
Generate a **proposed action plan** with these sections:
51-
52-
### 1. Executive Summary
53-
A 2-3 sentence summary of what was found and what needs to be done to address the user's request.
54-
55-
### 2. Key Findings from Analysis
56-
List 3-5 concrete, evidence-based findings from the analysis that inform the action plan:
57-
- Each finding should be clearly stated
58-
- Reference specific evidence found (e.g., "Analysis of \`file.js\` reveals...")
59-
- Explain how each finding impacts the proposed solution
60-
61-
### 3. Proposed Action Plan
62-
Present a step-by-step plan of action:
63-
- Numbered steps in recommended sequence
64-
- Each step should be concrete and actionable
65-
- Include code snippets, file paths, or configuration changes when applicable
66-
- Indicate expected outcomes for each step
67-
68-
### 4. Technical Implementation Details
69-
When relevant, provide:
70-
- Specific code changes recommended
71-
- Dependencies to add/remove
72-
- Configuration updates
73-
- Integration points with existing codebase
74-
75-
### 5. Considerations & Alternative Approaches
76-
Briefly note:
77-
- Potential challenges or risks in the proposed approach
78-
- Alternative approaches if the main plan encounters obstacles
79-
- Additional information that might be needed
80-
- Future improvements to consider after implementation
51+
Your response must include these sections in order:
52+
53+
### 1. Direct Answer to User's Question
54+
- **Directly address the user's specific question/issue first**
55+
- Provide a clear, concise answer based on the analysis findings
56+
- If it's a "how to" question, give the specific steps
57+
- If it's a "why" question, explain the root cause
58+
- If it's a "what" question, provide the specific information requested
59+
60+
### 2. Visual Architecture/Flow Diagram
61+
Create a Mermaid diagram that illustrates:
62+
- Current system architecture (if analyzing existing code)
63+
- Proposed solution flow (if implementing new features)
64+
- Data flow or process flow relevant to the user's issue
65+
- Component relationships and dependencies
66+
67+
Use appropriate Mermaid diagram types:
68+
- \`graph TD\` for flowcharts and process flows
69+
- \`sequenceDiagram\` for interaction flows
70+
- \`classDiagram\` for class relationships
71+
- \`gitgraph\` for development workflows
72+
73+
Example format:
74+
\`\`\`mermaid
75+
graph TD
76+
A["Current State"] --> B["Identified Issue"]
77+
B --> C["Proposed Solution"]
78+
C --> D["Expected Outcome"]
79+
\`\`\`
80+
81+
### 3. Evidence-Based Findings
82+
List 3-5 key findings from the code analysis that support your answer:
83+
- Reference specific files, functions, or code patterns found
84+
- Explain how each finding relates to the user's question
85+
- Include relevant code snippets when helpful
86+
87+
### 4. Step-by-Step Development Plan
88+
Provide a detailed, actionable plan:
89+
1. **Immediate Actions** - What to do first
90+
2. **Core Implementation** - Main development tasks
91+
3. **Integration Steps** - How to connect with existing code
92+
4. **Testing Strategy** - How to verify the solution works
93+
5. **Deployment Considerations** - Production readiness steps
94+
95+
For each step, include:
96+
- Specific files to modify/create
97+
- Code examples or templates
98+
- Expected outcomes
99+
- Potential challenges
100+
101+
### 5. Implementation Timeline & Priorities
102+
- **High Priority** (Must do first)
103+
- **Medium Priority** (Important but can wait)
104+
- **Low Priority** (Nice to have)
105+
- **Future Enhancements** (Post-implementation improvements)
106+
107+
### 6. Risk Assessment & Alternatives
108+
- Potential risks in the proposed approach
109+
- Mitigation strategies
110+
- Alternative solutions if the main approach fails
111+
- Rollback plan if needed
81112
82113
## 🎯 Response Guidelines
83114
84-
- **Be specific and actionable** - focus on concrete next steps
85-
- **Reference evidence** discovered during analysis
86-
- **Present a logical sequence** of actions
87-
- **Consider the project context** revealed by the analysis
88-
- **Prioritize practical solutions** that can be implemented immediately
89-
- **Keep it concise** - aim for clarity and usefulness
115+
**CRITICAL**: Start by directly answering the user's question before diving into technical details.
90116
91-
Remember: The response should provide a clear, actionable plan that the user can follow to address their issue.`;
117+
- **Be user-centric** - Address their specific concern first
118+
- **Use visual aids** - Include relevant Mermaid diagrams
119+
- **Provide evidence** - Reference actual code findings
120+
- **Be actionable** - Give concrete next steps
121+
- **Consider context** - Respect the existing codebase architecture
122+
- **Think holistically** - Balance immediate needs with long-term maintainability
123+
124+
Remember: The user asked a specific question - answer it clearly first, then provide the comprehensive development plan to implement the solution.`;
92125

93126
try {
94127
const messages: CoreMessage[] = [
95128
{
96129
role: "system",
97-
content: "You are an expert software architect and GitHub issue analyst. Your role is to provide a clear, actionable plan based on thorough code analysis. Focus on specific next steps the user should take rather than describing the analysis process. Present a logical sequence of actions that addresses the user's request in the context of their project architecture."
130+
content: "You are an expert software architect and GitHub issue analyst. Your primary goal is to directly answer the user's specific question while providing comprehensive technical guidance. Always start with a direct answer to their question, then provide detailed implementation guidance with visual diagrams. Use Mermaid diagrams to illustrate architecture, flows, and relationships. Be specific, actionable, and evidence-based in your recommendations."
98131
},
99132
{ role: "user", content: comprehensivePrompt }
100133
];
101134

102135
this.logger.log('Sending request to LLM', {
103136
messages,
104137
temperature: 0.1,
105-
maxTokens: 3000
138+
maxTokens: 4000
106139
});
107140

108141
const { text } = await generateText({
109142
model: this.llmConfig.openai(this.llmConfig.fullModel),
110143
messages,
111144
temperature: 0.1,
112-
maxTokens: 3000
145+
maxTokens: 4000
113146
});
114147

115148
this.logger.log('Received response from LLM', {
@@ -128,6 +161,28 @@ Remember: The response should provide a clear, actionable plan that the user can
128161
}
129162
}
130163

164+
private extractIssueContext(userInput: string, toolResultsSummary: string): string {
165+
// Extract key context from user input to better understand the issue type
166+
const issueKeywords = {
167+
implementation: ['how to implement', 'how do I', 'how can I', 'implement', 'create', 'build'],
168+
debugging: ['error', 'bug', 'issue', 'problem', 'not working', 'fails', 'broken'],
169+
architecture: ['architecture', 'design', 'structure', 'organize', 'best practice'],
170+
integration: ['integrate', 'connect', 'combine', 'merge', 'link'],
171+
optimization: ['optimize', 'improve', 'performance', 'faster', 'better']
172+
};
173+
174+
const lowerInput = userInput.toLowerCase();
175+
const detectedTypes: string[] = [];
176+
177+
Object.entries(issueKeywords).forEach(([type, keywords]) => {
178+
if (keywords.some(keyword => lowerInput.includes(keyword))) {
179+
detectedTypes.push(type);
180+
}
181+
});
182+
183+
return detectedTypes.length > 0 ? detectedTypes.join(', ') : 'general inquiry';
184+
}
185+
131186
private groupResultsByRound(results: ToolResult[]): Map<number, ToolResult[]> {
132187
const grouped = new Map<number, ToolResult[]>();
133188

0 commit comments

Comments
 (0)