2026-01-22 19:36:23 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
"""
|
|
|
|
|
Upgrade Repo Script
|
2026-01-23 19:50:48 +00:00
|
|
|
Reads market research and suggests code upgrades using Gemini and Jules.
|
2026-01-22 19:36:23 +00:00
|
|
|
"""
|
|
|
|
|
|
2026-02-10 05:36:36 +00:00
|
|
|
import concurrent.futures
|
2026-01-22 19:36:23 +00:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
2026-02-11 08:36:58 +00:00
|
|
|
# Use shared utilities to reduce code duplication
|
|
|
|
|
from common.logger_config import setup_basic_logging
|
|
|
|
|
from common.paths import REPO_ROOT, DOCS_DIR
|
|
|
|
|
from common.config_loader import load_env
|
|
|
|
|
from common.ai_client import ask_gemini, ask_jules
|
2026-01-22 19:36:23 +00:00
|
|
|
|
2026-02-11 08:36:58 +00:00
|
|
|
# Setup logging using shared config
|
|
|
|
|
logger = setup_basic_logging()
|
2026-01-28 20:07:51 +00:00
|
|
|
|
2026-02-11 08:36:58 +00:00
|
|
|
# Load environment variables
|
|
|
|
|
load_env()
|
2026-01-23 19:50:48 +00:00
|
|
|
|
2026-01-22 19:36:23 +00:00
|
|
|
def main():
|
|
|
|
|
logger.info("Starting Code Upgrade Analysis...")
|
|
|
|
|
|
|
|
|
|
report_path = DOCS_DIR / "market_research_report.md"
|
|
|
|
|
if not report_path.exists():
|
|
|
|
|
logger.warning("No market research report found. Skipping upgrade analysis.")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
with open(report_path, 'r') as f:
|
|
|
|
|
research_content = f.read()
|
|
|
|
|
|
2026-01-25 19:44:13 +00:00
|
|
|
# Read NotebookLM context if available
|
|
|
|
|
notebook_context = ""
|
|
|
|
|
notebook_path = DOCS_DIR / "NOTEBOOK_LM_CONTEXT.txt"
|
|
|
|
|
if notebook_path.exists():
|
|
|
|
|
with open(notebook_path, 'r') as f:
|
|
|
|
|
notebook_context = f.read()
|
2026-01-28 20:07:51 +00:00
|
|
|
logger.info("Loaded NotebookLM context.")
|
2026-01-25 19:44:13 +00:00
|
|
|
|
2026-01-23 19:50:48 +00:00
|
|
|
# Get EA code context
|
|
|
|
|
ea_path = REPO_ROOT / "mt5/MQL5/Experts/SMC_TrendBreakout_MTF_EA.mq5"
|
|
|
|
|
ea_code = ""
|
|
|
|
|
if ea_path.exists():
|
|
|
|
|
with open(ea_path, 'r') as f:
|
|
|
|
|
ea_code = f.read()[:5000]
|
2026-01-22 19:36:23 +00:00
|
|
|
|
2026-01-23 19:50:48 +00:00
|
|
|
prompt = f"""
|
2026-01-25 19:44:13 +00:00
|
|
|
Based on the following market research and optional NotebookLM context, suggest 3 specific code upgrades or parameter adjustments for the trading bot.
|
2026-01-22 19:36:23 +00:00
|
|
|
|
2026-01-23 19:50:48 +00:00
|
|
|
Market Research:
|
|
|
|
|
{research_content}
|
2026-01-22 19:36:23 +00:00
|
|
|
|
2026-01-25 19:44:13 +00:00
|
|
|
NotebookLM Context:
|
|
|
|
|
{notebook_context}
|
|
|
|
|
|
2026-01-23 19:50:48 +00:00
|
|
|
Current EA Code Snippet (Top 5000 chars):
|
|
|
|
|
{ea_code}
|
2026-01-22 19:36:23 +00:00
|
|
|
|
2026-01-23 19:50:48 +00:00
|
|
|
Output format:
|
|
|
|
|
1. [File Name]: [Suggestion] - [Reasoning]
|
|
|
|
|
"""
|
2026-01-22 19:36:23 +00:00
|
|
|
|
2026-02-10 05:36:36 +00:00
|
|
|
# ⚡ Optimization: Parallelize AI requests (~2x speedup)
|
|
|
|
|
with concurrent.futures.ThreadPoolExecutor() as executor:
|
|
|
|
|
future_gemini = executor.submit(ask_gemini, prompt)
|
|
|
|
|
future_jules = executor.submit(ask_jules, prompt)
|
|
|
|
|
|
|
|
|
|
gemini_suggestions = future_gemini.result()
|
|
|
|
|
jules_suggestions = future_jules.result()
|
2026-01-22 19:36:23 +00:00
|
|
|
|
2026-01-23 19:50:48 +00:00
|
|
|
if not gemini_suggestions and not jules_suggestions:
|
|
|
|
|
logger.warning("Both AI providers failed or keys missing.")
|
|
|
|
|
return
|
2026-01-22 19:36:23 +00:00
|
|
|
|
2026-01-23 19:50:48 +00:00
|
|
|
suggestion_path = DOCS_DIR / "upgrade_suggestions.md"
|
|
|
|
|
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
2026-01-22 19:36:23 +00:00
|
|
|
|
2026-01-23 19:50:48 +00:00
|
|
|
content = f"# Upgrade Suggestions\n\nGenerated: {timestamp}\n\n"
|
2026-01-22 19:36:23 +00:00
|
|
|
|
2026-01-23 19:50:48 +00:00
|
|
|
if gemini_suggestions:
|
|
|
|
|
content += f"## Gemini Suggestions\n\n{gemini_suggestions}\n\n"
|
2026-01-22 19:36:23 +00:00
|
|
|
|
2026-01-23 19:50:48 +00:00
|
|
|
if jules_suggestions:
|
|
|
|
|
content += f"## Jules Suggestions\n\n{jules_suggestions}\n\n"
|
2026-01-22 19:36:23 +00:00
|
|
|
|
2026-01-23 19:50:48 +00:00
|
|
|
with open(suggestion_path, 'w') as f:
|
|
|
|
|
f.write(content)
|
2026-01-22 19:36:23 +00:00
|
|
|
|
2026-01-23 19:50:48 +00:00
|
|
|
logger.info(f"Suggestions saved to {suggestion_path}")
|
2026-01-22 19:36:23 +00:00
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|