1+
12"""
23Main entry point - Legacy Code Migration Tool
34"""
45from config .settings import initialize_settings
6+ # from scripts import seed_database
57from dotenv import load_dotenv
68load_dotenv ()
79from colorama import Fore , Style
1012from full_repo_workflow import run_full_repo_workflow
1113
1214
13-
14- def main ():
15- """Main function: Run antipattern analysis"""
16-
17- # Let user select provider
18- print ("Available providers: 1) ollama 2) ibm 3) vllm" )
19- choice = input ("Select provider (1-3): " ).strip ()
20-
21- provider_map = {"1" : "ollama" , "2" : "ibm" , "3" : "vllm" }
22- provider = provider_map .get (choice , "ollama" ) # default to ollama
23-
24- # Let us choose which DB to interact with
25- print ("Choose your trove: 1) ChromaDB (VectorDB) 2) TinyDB (DocumentDB)" )
26- db_choice = input ("Choose 1 or 2: " ).strip ()
27-
28- # Initialize global settings with selected provider
29- settings = initialize_settings (provider )
30- print (Fore .GREEN + f"Using { settings .LLM_PROVIDER } with model { settings .LLM_MODEL } " + Style .RESET_ALL )
31-
32- # Temporary Lazy Imports
33- from src .core .graph import CreateGraph
34- from src .data .database import VectorDBManager , TinyDBManager
35- from src .core .prompt import PromptManager
36- from scripts import seed_database
37-
38- # Initialize PromptManager
39- print ("Initializing PromptManager..." )
40- prompt_manager = PromptManager ()
41-
15+ def run_code_snippet_workflow (settings , db_manager , prompt_manager , langgraph ):
16+ """Run the original workflow with a hardcoded Java code snippet."""
17+ print (Fore .BLUE + "\n === Code Snippet Analysis Workflow ===" + Style .RESET_ALL )
18+ print ("Analyzing the provided Java code snippet..." )
19+
4220 # Example Java code
4321 legacy_code = """
4422 public class ApplicationManager {
@@ -77,8 +55,7 @@ def main():
7755 }
7856 }
7957 """
80-
81- # Initial workflow state
58+
8259 initial_state = {
8360 "code" : legacy_code ,
8461 "context" : None ,
@@ -89,13 +66,59 @@ def main():
8966 "code_review_results" : None ,
9067 "code_review_times" : 0 ,
9168 "msgs" : [],
92- "answer" : None ,
93-
94- # ExplainerAgent fields
95- "explanation_response_raw" : None ,
96- "explanation_json" : None ,
69+ "answer" : None
9770 }
9871
72+ final_state = langgraph .invoke (initial_state )
73+
74+ print (Fore .GREEN + f"\n Analysis Complete!" + Style .RESET_ALL )
75+ print (f"Final state keys: { list (final_state .keys ())} " )
76+ print (f"Context retrieved: { 'Yes' if final_state .get ('context' ) else 'No' } " )
77+ print (f"Analysis completed: { 'Yes' if final_state .get ('antipatterns_scanner_results' ) else 'No' } " )
78+ print (f"Refactored code: { 'Yes' if final_state .get ('refactored_code' ) else 'No' } " )
79+ print (f"Code review results: { final_state .get ('code_review_times' )} " )
80+
81+
82+ def main ():
83+ """Main function: Choose between code snippet analysis or full repository run"""
84+
85+ print (Fore .BLUE + "=== AntiPattern Remediator Tool ===" + Style .RESET_ALL )
86+ print ("Choose your analysis mode:" )
87+ print ("1) Code Snippet Analysis - Analyze a sample Java code snippet" )
88+ print ("2) Full Repository Run - Process files with 100% test coverage from JaCoCo results" )
89+
90+ # Let user choose analysis mode
91+ mode_choice = input ("\n Select mode (1-2): " ).strip ()
92+
93+ if mode_choice not in ["1" , "2" ]:
94+ print (Fore .RED + "Invalid choice. Defaulting to Code Snippet Analysis." + Style .RESET_ALL )
95+ mode_choice = "1"
96+
97+ # Let user select provider
98+ print ("\n Available providers: 1) ollama 2) ibm 3) vllm" )
99+ choice = input ("Select provider (1-3): " ).strip ()
100+
101+ provider_map = {"1" : "ollama" , "2" : "ibm" , "3" : "vllm" }
102+ provider = provider_map .get (choice , "ollama" ) # default to ollama
103+
104+ # Let us choose which DB to interact with
105+ print ("Choose your trove: 1) ChromaDB (VectorDB) 2) TinyDB (DocumentDB)" )
106+ db_choice = input ("Choose 1 or 2: " ).strip ()
107+
108+ # Initialize global settings with selected provider
109+ settings = initialize_settings (provider )
110+ print (Fore .GREEN + f"Using { settings .LLM_PROVIDER } with model { settings .LLM_MODEL } " + Style .RESET_ALL )
111+
112+ # Temporary Lazy Imports
113+ from src .core .graph import CreateGraph
114+ from src .data .database import VectorDBManager , TinyDBManager
115+ from src .core .prompt import PromptManager
116+ from scripts import seed_database
117+
118+ # Initialize PromptManager
119+ print ("Initializing PromptManager..." )
120+ prompt_manager = PromptManager ()
121+
99122 # Setup Database
100123 if db_choice == "2" :
101124 print ("Seeding TinyDB with AntiPattern Dataset" )
@@ -110,22 +133,11 @@ def main():
110133 retriever = db_manager .as_retriever ()
111134 langgraph = CreateGraph (db_manager , prompt_manager , retriever = retriever ).workflow
112135
113- # Final results summary
114- print (Fore .GREEN + f"\n Analysis Complete!" + Style .RESET_ALL )
115- print (f"Final state keys: { list (final_state .keys ())} " )
116- print (f"Context retrieved: { 'Yes' if final_state .get ('context' ) else 'No' } " )
117- print (f"Analysis completed: { 'Yes' if final_state .get ('antipatterns_scanner_results' ) else 'No' } " )
118- print (f"Refactored code: { 'Yes' if final_state .get ('refactored_code' ) else 'No' } " )
119- print (f"Code review results: { final_state .get ('code_review_times' )} " )
120-
121- # Show explanation from ExplainerAgent
122- if final_state .get ("explanation_json" ):
123- import json
124- print (Fore .CYAN + "\n === Explanation (JSON) ===" + Style .RESET_ALL )
125- print (json .dumps (final_state ["explanation_json" ], indent = 2 , ensure_ascii = False ))
136+ # Run the selected workflow
137+ if mode_choice == "1" :
138+ run_code_snippet_workflow (settings , db_manager , prompt_manager , langgraph )
126139 else :
127- print (Fore .RED + "\n No explanation was generated." + Style .RESET_ALL )
128-
140+ run_full_repo_workflow (settings , db_manager , prompt_manager , langgraph )
129141
130142if __name__ == "__main__" :
131143 main ()
0 commit comments