import os, sys import config from scripts.llm_client import LLMClient from tools import coder, rag from scripts import gadget from tui import HendrikTUI # Daftar tools yang tersedia tools_definition = [ gadget.tools_mapping( schema = coder.schema_read_file, handler = coder.read_file ), gadget.tools_mapping( schema = coder.schema_write_file, handler = coder.write_file ), gadget.tools_mapping( schema = coder.schema_edit_file, handler = coder.edit_file ), gadget.tools_mapping( schema = coder.schema_run_bash, handler = coder.run_bash ), gadget.tools_mapping( schema = coder.schema_search_code, handler = coder.search_code ), gadget.tools_mapping( schema = coder.schema_git_operation, handler = coder.git_operation ), gadget.tools_mapping( schema = rag.schema_store_knowledge, handler = rag.store_knowledge ), gadget.tools_mapping( schema = rag.schema_search_knowledge, handler = rag.search_knowledge ), gadget.tools_mapping( schema = rag.schema_create_collection, handler = rag.create_collection ), gadget.tools_mapping( schema = rag.schema_delete_collection, handler = rag.delete_collection ), gadget.tools_mapping( schema = rag.schema_list_collections, handler = rag.list_collections ), gadget.tools_mapping( schema = rag.schema_inspect_collection, handler = rag.inspect_collection ), ] # Ekstrak dari tools_definition ke dua format berbeda TOOLS = gadget.tool_schemas (tools_definition) TOOL_HANDLERS = gadget.tool_handlers (tools_definition) def main(): llm_client = LLMClient(config.llm_baseurl, config.llm_model, config.llm_api_key, config.llm_timeout) # Parsing arguments `-w ` atau `--workspace ` workspace = None i = 1 while i < len(sys.argv): if sys.argv[i] in ('-w', '--workspace') and i + 1 < len(sys.argv): workspace = sys.argv[i + 1] i += 2 else: i += 1 # Apply workspace jika ada if workspace: resolved = os.path.abspath(workspace) if not os.path.isdir(resolved): print(f"Error: '{resolved}' is not a valid directory") sys.exit(1) os.chdir(resolved) HendrikTUI( llm_client = llm_client, tools_definition = tools_definition, TOOLS = TOOLS, TOOL_HANDLERS = TOOL_HANDLERS, build_system_prompt = gadget.build_system_prompt, agent_max_iterations = config.AGENT_MAX_ITERATIONS, ).run() # Luncurkan TUI if __name__ == "__main__": main()