1-
21"""
32Main entry point - Legacy Code Migration Tool
43"""
54from config .settings import initialize_settings
6- # from scripts import seed_database
75from dotenv import load_dotenv
86load_dotenv ()
97from colorama import Fore , Style
1210from full_repo_workflow import run_full_repo_workflow
1311
1412
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-
13+ def main ():
14+ """Main function: Run antipattern analysis"""
15+
16+ # Let user select provider
17+ print ("Available providers: 1) ollama 2) ibm 3) vllm" )
18+ choice = input ("Select provider (1-3): " ).strip ()
19+
20+ provider_map = {"1" : "ollama" , "2" : "ibm" , "3" : "vllm" }
21+ provider = provider_map .get (choice , "ollama" ) # default to ollama
22+
23+ # Let us choose which DB to interact with
24+ print ("Choose your trove: 1) ChromaDB (VectorDB) 2) TinyDB (DocumentDB)" )
25+ db_choice = input ("Choose 1 or 2: " ).strip ()
26+
27+ # Initialize global settings with selected provider
28+ settings = initialize_settings (provider )
29+ print (Fore .GREEN + f"Using { settings .LLM_PROVIDER } with model { settings .LLM_MODEL } " + Style .RESET_ALL )
30+
31+ # Temporary Lazy Imports
32+ from src .core .graph import CreateGraph
33+ from src .data .database import VectorDBManager , TinyDBManager
34+ from src .core .prompt import PromptManager
35+ from scripts import seed_database
36+
37+ # Initialize PromptManager
38+ print ("Initializing PromptManager..." )
39+ prompt_manager = PromptManager ()
40+
2041 # Example Java code
2142 legacy_code = """
2243 public class ApplicationManager {
@@ -55,7 +76,8 @@ def run_code_snippet_workflow(settings, db_manager, prompt_manager, langgraph):
5576 }
5677 }
5778 """
58-
79+
80+ # Initial workflow state
5981 initial_state = {
6082 "code" : legacy_code ,
6183 "context" : None ,
@@ -66,58 +88,12 @@ def run_code_snippet_workflow(settings, db_manager, prompt_manager, langgraph):
6688 "code_review_results" : None ,
6789 "code_review_times" : 0 ,
6890 "msgs" : [],
69- "answer" : None
70- }
71-
72- final_state = langgraph .invoke (initial_state )
91+ "answer" : None ,
7392
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 ()
93+ # ExplainerAgent fields
94+ "explanation_response_raw" : None ,
95+ "explanation_json" : None ,
96+ }
12197
12298 # Setup Database
12399 if db_choice == "2" :
@@ -133,11 +109,22 @@ def main():
133109 retriever = db_manager .as_retriever ()
134110 langgraph = CreateGraph (db_manager , prompt_manager , retriever = retriever ).workflow
135111
136- # Run the selected workflow
137- if mode_choice == "1" :
138- run_code_snippet_workflow (settings , db_manager , prompt_manager , langgraph )
112+ # Final results summary
113+ print (Fore .GREEN + f"\n Analysis Complete!" + Style .RESET_ALL )
114+ print (f"Final state keys: { list (final_state .keys ())} " )
115+ print (f"Context retrieved: { 'Yes' if final_state .get ('context' ) else 'No' } " )
116+ print (f"Analysis completed: { 'Yes' if final_state .get ('antipatterns_scanner_results' ) else 'No' } " )
117+ print (f"Refactored code: { 'Yes' if final_state .get ('refactored_code' ) else 'No' } " )
118+ print (f"Code review results: { final_state .get ('code_review_times' )} " )
119+
120+ # Show explanation from ExplainerAgent
121+ if final_state .get ("explanation_json" ):
122+ import json
123+ print (Fore .CYAN + "\n === Explanation (JSON) ===" + Style .RESET_ALL )
124+ print (json .dumps (final_state ["explanation_json" ], indent = 2 , ensure_ascii = False ))
139125 else :
140- run_full_repo_workflow (settings , db_manager , prompt_manager , langgraph )
126+ print (Fore .RED + "\n No explanation was generated." + Style .RESET_ALL )
127+
141128
142129if __name__ == "__main__" :
143130 main ()
0 commit comments