hendrik/hendrik.py

55 lines
2.0 KiB
Python

import os, sys
import config
from scripts.llm_client import LLMClient
from tools import coder
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 ),
]
# 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 <dir>` atau `--workspace <dir>`
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()