Repository navigation
Expand file tree
/
Copy pathtest_full_detailed_logging.py
More file actions
444 lines (379 loc) · 20 KB
/
Copy pathtest_full_detailed_logging.py
File metadata and controls
444 lines (379 loc) · 20 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
"""
Complete Agent Pipeline with FULL Detailed Logging
This test:
1. Increases token limits to prevent truncation
2. Logs EVERY agent input and output to a TXT file
3. Shows complete JSON data (no truncation)
4. Creates human-readable logs with all details
"""
import asyncio
import json
import sys
import os
from datetime import datetime
class DetailedLogger:
"""Comprehensive logger for all agent interactions"""
def __init__(self, filename):
self.filename = filename
self.file = open(filename, 'w', encoding='utf-8')
self.log_count = 0
def write(self, message):
"""Write to both console and file"""
print(message)
self.file.write(message + '\n')
self.file.flush()
def log_section(self, title, char='='):
"""Log a section header"""
line = char * 100
self.write(f"\n{line}")
self.write(f" {title}")
self.write(f"{line}\n")
def log_agent_input(self, agent_name, input_data):
"""Log complete agent input"""
self.log_count += 1
self.write(f"\n{'─'*100}")
self.write(f"[{self.log_count}] AGENT INPUT: {agent_name}")
self.write(f"{'─'*100}")
self.write(json.dumps(input_data, indent=2))
self.write(f"{'─'*100}\n")
def log_agent_output(self, agent_name, output_data):
"""Log complete agent output"""
self.write(f"\n{'─'*100}")
self.write(f"[{self.log_count}] AGENT OUTPUT: {agent_name}")
self.write(f"{'─'*100}")
self.write(json.dumps(output_data, indent=2))
self.write(f"{'─'*100}\n")
def close(self):
"""Close the log file"""
self.file.close()
async def run_full_detailed_test():
"""Run complete test with full detailed logging"""
# Create detailed logger
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
log_file = f"FULL_AGENT_LOGS_{timestamp}.txt"
logger = DetailedLogger(log_file)
logger.log_section("ACTUALCODE - COMPLETE AGENT PIPELINE TEST WITH FULL LOGGING")
logger.write(f"Started at: {datetime.now().isoformat()}")
logger.write(f"Log file: {log_file}")
# Load actual Test_Repo files
logger.log_section("STEP 1: LOADING ACTUAL REPOSITORY FILES")
test_repo_path = "/Users/muratcankoylan/ActualCode/Test_Repo/Ayurvedic-Remedy-main"
file_contents = {}
try:
for filename in ["index.html", "app.js", "app.css", "README.md"]:
filepath = os.path.join(test_repo_path, filename)
if os.path.exists(filepath):
with open(filepath, 'r', encoding='utf-8') as f:
file_contents[filename] = f.read()
logger.write(f"✅ Loaded {filename}: {len(file_contents[filename])} characters")
except Exception as e:
logger.write(f"⚠️ Error loading files: {e}")
return
# Import agents
logger.log_section("STEP 2: INITIALIZING ALL AGENTS")
from agents.code_analyzer_agent import code_analyzer
from agents.pr_analyzer_agent import pr_analyzer
from agents.issue_analyzer_agent import issue_analyzer
from agents.dependency_analyzer_agent import dependency_analyzer
from agents.problem_creator_agent import problem_creator
from agents.qa_validator_agent import qa_validator
conversation_id = f"full_test_{timestamp}"
logger.write(f"✅ All 6 agents initialized")
logger.write(f"📋 Conversation ID: {conversation_id}")
# Create comprehensive repository data with ACTUAL files
logger.log_section("STEP 3: PREPARING REPOSITORY DATA WITH ACTUAL FILES")
repo_data = {
"repository": {
"name": "Ayurvedic-Remedy",
"description": "AI-powered Ayurvedic remedy generator using Google Gemini API",
"language": "JavaScript",
"url": "https://github.com/test/Ayurvedic-Remedy",
"stars": 5,
"tech_stack": "Vanilla JS, HTML5, CSS3, Google Gemini AI"
},
"codebase": {
"files": file_contents, # ACTUAL file contents
"file_list": list(file_contents.keys()),
"total_files": len(file_contents),
"summary": {
"index.html": f"{len(file_contents.get('index.html', ''))} chars - Main HTML with Gemini AI import",
"app.js": f"{len(file_contents.get('app.js', ''))} chars - JavaScript with Gemini API integration",
"app.css": f"{len(file_contents.get('app.css', ''))} chars - Styling with animations",
"README.md": f"{len(file_contents.get('README.md', ''))} chars - Project description"
}
},
"pullRequests": [
{
"title": "Add error handling for API failures",
"description": "Handle Gemini API errors gracefully with user-friendly messages",
"files": ["app.js"],
"code_reference": "Around line 47 in generateText function"
},
{
"title": "Optimize typing animation",
"description": "Improve performance of character-by-character display",
"files": ["app.js"],
"current_implementation": "setTimeout with 28ms delay"
},
{
"title": "Add loading indicator",
"description": "Show spinner while waiting for AI response",
"files": ["index.html", "app.css", "app.js"]
}
],
"issues": [
{
"title": "Add remedy history with localStorage",
"description": "Save past searches for user reference",
"priority": "high",
"technical_details": "Use localStorage.setItem/getItem with JSON.stringify"
},
{
"title": "Typing animation stutters on mobile",
"description": "Performance issue on slower devices",
"priority": "medium",
"affected_code": "typeAnswer() function with setTimeout"
},
{
"title": "Multilingual support (Hindi/Sanskrit)",
"description": "Support Indian languages in remedy responses",
"priority": "low",
"implementation": "Add language parameter to Gemini prompt"
}
],
"dependencies": [
{
"name": "@google/generative-ai",
"version": "latest",
"usage": "Core AI functionality via Gemini Pro model"
},
{
"name": "dotenv",
"version": "16.0.0",
"usage": "Environment variable management for API keys"
}
]
}
logger.write(f"✅ Repository data prepared with {len(file_contents)} actual files")
logger.log_agent_input("REPOSITORY_DATA", repo_data)
try:
# =====================================================================
# AGENT 2: CODE ANALYZER
# =====================================================================
logger.log_section("AGENT 2: CODE ANALYZER - ANALYZING ACTUAL CODE")
logger.write("📥 Sending repository data to Code Analyzer...")
code_analysis_input = repo_data.copy()
logger.log_agent_input("Code Analyzer", code_analysis_input)
logger.write("⚙️ Executing Code Analyzer Agent...")
code_analysis = await code_analyzer.analyze(
repo_data=code_analysis_input,
conversation_id=conversation_id
)
logger.log_agent_output("Code Analyzer", code_analysis)
logger.write(f"✅ Code analysis complete")
logger.write(f" Architecture: {code_analysis.get('architecture', {}).get('pattern', 'N/A')}")
logger.write(f" Quality Score: {code_analysis.get('code_quality', {}).get('score', 0)}/100")
logger.write(f" Opportunities: {len(code_analysis.get('opportunities', {}).get('features', []))}")
# =====================================================================
# AGENT 3: PR ANALYZER
# =====================================================================
logger.log_section("AGENT 3: PR ANALYZER - ANALYZING PULL REQUESTS")
logger.write("📥 Sending PR data to PR Analyzer...")
pr_analysis_input = repo_data.copy()
logger.log_agent_input("PR Analyzer", pr_analysis_input)
logger.write("⚙️ Executing PR Analyzer Agent...")
pr_analysis = await pr_analyzer.analyze(
repo_data=pr_analysis_input,
conversation_id=conversation_id
)
logger.log_agent_output("PR Analyzer", pr_analysis)
logger.write(f"✅ PR analysis complete")
logger.write(f" Patterns: {len(pr_analysis.get('patterns', {}).get('common_change_types', []))}")
logger.write(f" Insights: {len(pr_analysis.get('insights', {}).get('recent_features', []))}")
logger.write(f" Suggestions: {len(pr_analysis.get('suggested_problems', []))}")
# =====================================================================
# AGENT 4: ISSUE ANALYZER
# =====================================================================
logger.log_section("AGENT 4: ISSUE ANALYZER - ANALYZING ISSUES")
logger.write("📥 Sending issue data to Issue Analyzer...")
issue_analysis_input = repo_data.copy()
logger.log_agent_input("Issue Analyzer", issue_analysis_input)
logger.write("⚙️ Executing Issue Analyzer Agent...")
issue_analysis = await issue_analyzer.analyze(
repo_data=issue_analysis_input,
conversation_id=conversation_id
)
logger.log_agent_output("Issue Analyzer", issue_analysis)
logger.write(f"✅ Issue analysis complete")
logger.write(f" Categories: {len(issue_analysis.get('categories', {}).keys())}")
logger.write(f" Patterns: {len(issue_analysis.get('problem_patterns', []))}")
logger.write(f" Suggestions: {len(issue_analysis.get('suggested_problems', []))}")
# =====================================================================
# AGENT 5: DEPENDENCY ANALYZER
# =====================================================================
logger.log_section("AGENT 5: DEPENDENCY ANALYZER - ANALYZING TECH STACK")
logger.write("📥 Sending dependency data to Dependency Analyzer...")
dep_analysis_input = repo_data.copy()
logger.log_agent_input("Dependency Analyzer", dep_analysis_input)
logger.write("⚙️ Executing Dependency Analyzer Agent...")
dep_analysis = await dependency_analyzer.analyze(
repo_data=dep_analysis_input,
conversation_id=conversation_id
)
logger.log_agent_output("Dependency Analyzer", dep_analysis)
logger.write(f"✅ Dependency analysis complete")
logger.write(f" Tech Stack: {dep_analysis.get('tech_stack', {})}")
logger.write(f" Integration Opportunities: {len(dep_analysis.get('integration_opportunities', []))}")
# =====================================================================
# SYNTHESIZE COMBINED REPORT
# =====================================================================
logger.log_section("SYNTHESIZING COMBINED ANALYSIS REPORT")
combined_report = {
"repository_profile": {
"name": "Ayurvedic Remedy Generator",
"architecture": code_analysis.get('architecture', {}),
"quality": code_analysis.get('code_quality', {}),
"tech_stack": dep_analysis.get('tech_stack', {}),
"actual_files_analyzed": list(file_contents.keys())
},
"opportunities": code_analysis.get('opportunities', {}),
"pr_insights": pr_analysis.get('insights', {}),
"issue_patterns": issue_analysis.get('problem_patterns', []),
"ranked_suggestions": (
pr_analysis.get('suggested_problems', [])[:5] +
issue_analysis.get('suggested_problems', [])[:5]
)
}
logger.log_agent_output("COMBINED_REPORT", combined_report)
logger.write(f"✅ Combined report synthesized with {len(combined_report['ranked_suggestions'])} suggestions")
# =====================================================================
# AGENT 6: PROBLEM CREATOR
# =====================================================================
logger.log_section("AGENT 6: PROBLEM CREATOR - GENERATING CODING PROBLEM")
problem_input = {
"repository_report": combined_report,
"difficulty": "medium",
"problem_type": "feature",
"focus_area": "Based on Ayurvedic Remedy codebase - 180 minutes",
"context": f"Actual files analyzed: {', '.join(file_contents.keys())}"
}
logger.write("📥 Sending combined report to Problem Creator...")
logger.log_agent_input("Problem Creator", problem_input)
logger.write("⚙️ Executing Problem Creator Agent...")
problem = await problem_creator.create_problem(
repository_report=combined_report,
difficulty="medium",
problem_type="feature",
focus_area="Based on Ayurvedic Remedy codebase - 180 minutes",
conversation_id=conversation_id
)
logger.log_agent_output("Problem Creator", problem)
logger.write(f"✅ Problem created:")
logger.write(f" Title: {problem.get('title', 'N/A')}")
logger.write(f" Difficulty: {problem.get('difficulty', 'N/A')}")
logger.write(f" Requirements: {len(problem.get('requirements', []))}")
logger.write(f" Acceptance Criteria: {len(problem.get('acceptance_criteria', []))}")
logger.write(f" Starter Code Files: {len(problem.get('starter_code', []))}")
# =====================================================================
# AGENT 7: QA VALIDATOR (SINGLE PASS)
# =====================================================================
logger.log_section("AGENT 7: QA VALIDATOR - VALIDATING PROBLEM QUALITY (SINGLE PASS)")
validation_input = {
"problem": problem,
"repository_report": combined_report
}
logger.write("📥 Sending problem to QA Validator for single-pass validation...")
logger.log_agent_input("QA Validator", validation_input)
logger.write("⚙️ Executing QA Validator Agent (validation only, no loop)...")
is_approved, validation = await qa_validator.validate_problem(
problem=problem,
repository_report=combined_report,
conversation_id=conversation_id
)
logger.log_agent_output("QA Validator", validation)
logger.write(f"✅ Validation complete:")
logger.write(f" Overall Score: {validation.get('overall_score', 0)}/100")
logger.write(f" Status: {'✅ APPROVED' if is_approved else '⚠️ NEEDS REFINEMENT'}")
logger.write(f" Feasibility: {validation.get('scores', {}).get('feasibility', 0)}/100")
logger.write(f" Quality: {validation.get('scores', {}).get('quality', 0)}/100")
logger.write(f" Technical: {validation.get('scores', {}).get('technical', 0)}/100")
logger.write(f" Educational: {validation.get('scores', {}).get('educational', 0)}/100")
# =====================================================================
# REFINEMENT: SEND FEEDBACK BACK TO PROBLEM CREATOR
# =====================================================================
logger.log_section("REFINEMENT: PROBLEM CREATOR IMPROVES BASED ON QA FEEDBACK")
improvement_instructions = {
"original_problem": problem,
"validation_feedback": validation,
"issues": validation.get('issues', []),
"suggestions": validation.get('suggestions', []),
"target_score": 100,
"current_score": validation.get('overall_score', 0)
}
logger.write("📥 Sending QA feedback to Problem Creator for refinement...")
logger.log_agent_input("Problem Creator (Refinement)", improvement_instructions)
logger.write("⚙️ Problem Creator refining problem based on QA feedback...")
refined_problem = await problem_creator.create_problem(
repository_report={
**combined_report,
"improvement_context": improvement_instructions
},
difficulty=problem.get('difficulty', 'medium'),
problem_type="improvement",
focus_area=f"Refined version - {problem.get('estimated_time', 180)} minutes",
conversation_id=conversation_id
)
logger.log_agent_output("Problem Creator (Refined)", refined_problem)
logger.write(f"✅ Problem refined:")
logger.write(f" Original Title: {problem.get('title', 'N/A')}")
logger.write(f" Refined Title: {refined_problem.get('title', 'N/A')}")
logger.write(f" Original Requirements: {len(problem.get('requirements', []))}")
logger.write(f" Refined Requirements: {len(refined_problem.get('requirements', []))}")
# =====================================================================
# FINAL SUMMARY
# =====================================================================
logger.log_section("FINAL TEST SUMMARY")
logger.write(f"\n✅ ALL AGENTS TESTED SUCCESSFULLY\n")
logger.write(f"Test Summary:")
logger.write(f" • Repository files analyzed: {len(file_contents)}")
logger.write(f" • Total file content: {sum(len(c) for c in file_contents.values())} characters")
logger.write(f" • Code quality score: {code_analysis.get('code_quality', {}).get('score', 0)}/100")
logger.write(f" • Problem suggestions generated: {len(combined_report['ranked_suggestions'])}")
logger.write(f" • Initial problem validation: {validation.get('overall_score', 0)}/100")
logger.write(f" • Problem refined: YES (single-pass improvement)")
logger.write(f" • Final problem: {refined_problem.get('title', 'N/A')}")
logger.write(f"\nWorkflow:")
logger.write(f" 1. Repository scanned → 2. Multi-agent analysis → 3. Problem created")
logger.write(f" 4. QA validated (single pass) → 5. Problem refined with feedback → 6. Final output")
logger.write(f"\nAll agent inputs and outputs logged to: {log_file}")
logger.write(f"Total log entries: {logger.log_count}")
logger.close()
print(f"\n{'='*100}")
print(f"✅ COMPLETE TEST FINISHED")
print(f"{'='*100}")
print(f"\n📄 FULL DETAILED LOG SAVED TO: {log_file}")
print(f" File contains ALL agent inputs and outputs (no truncation)")
print(f" Total entries logged: {logger.log_count}")
print(f"\n{'='*100}\n")
return {
"log_file": log_file,
"code_analysis": code_analysis,
"pr_analysis": pr_analysis,
"issue_analysis": issue_analysis,
"dependency_analysis": dep_analysis,
"combined_report": combined_report,
"initial_problem": problem,
"validation": validation,
"refined_problem": refined_problem,
"workflow": "Single-pass QA validation with feedback-driven refinement"
}
except Exception as e:
logger.write(f"\n❌ ERROR: {type(e).__name__}: {str(e)}")
import traceback
logger.write(traceback.format_exc())
logger.close()
raise
if __name__ == "__main__":
print("\n" * 2)
asyncio.run(run_full_detailed_test())
print("\n" * 2)