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+
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+
2042 # Example Java code
2143 legacy_code = """
2244 public class ApplicationManager {
@@ -55,7 +77,8 @@ def run_code_snippet_workflow(settings, db_manager, prompt_manager, langgraph):
5577 }
5678 }
5779 """
58-
80+
81+ # Initial workflow state
5982 initial_state = {
6083 "code" : legacy_code ,
6184 "context" : None ,
@@ -66,58 +89,12 @@ def run_code_snippet_workflow(settings, db_manager, prompt_manager, langgraph):
6689 "code_review_results" : None ,
6790 "code_review_times" : 0 ,
6891 "msgs" : [],
69- "answer" : None
70- }
71-
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 )
92+ "answer" : None ,
11193
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 ()
94+ # ExplainerAgent fields
95+ "explanation_response_raw" : None ,
96+ "explanation_json" : None ,
97+ }
12198
12299 # Setup Database
123100 if db_choice == "2" :
@@ -133,11 +110,22 @@ def main():
133110 retriever = db_manager .as_retriever ()
134111 langgraph = CreateGraph (db_manager , prompt_manager , retriever = retriever ).workflow
135112
136- # Run the selected workflow
137- if mode_choice == "1" :
138- run_code_snippet_workflow (settings , db_manager , prompt_manager , langgraph )
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 ))
139126 else :
140- run_full_repo_workflow (settings , db_manager , prompt_manager , langgraph )
127+ print (Fore .RED + "\n No explanation was generated." + Style .RESET_ALL )
128+
141129
142130if __name__ == "__main__" :
143131 main ()
0 commit comments