Pemisahan script ansicolor dan separator

This commit is contained in:
Dita Aji Pratama 2026-05-12 09:32:16 +07:00
parent 2bdfe52abb
commit 25ec6fd996
3 changed files with 35 additions and 17 deletions

View File

@ -3,10 +3,8 @@ import config
from llm_client import LLMClient from llm_client import LLMClient
from tools import coder from tools import coder
from scripts import gadget from scripts import gadget
from scripts.ansicolor import TEXT_COLOR_YELLOW, TEXT_COLOR_GREEN, TEXT_COLOR_RESET
TEXT_COLOR_YELLOW = '\033[93m' from scripts.separator import separator
TEXT_COLOR_GREEN = '\033[92m'
TEXT_COLOR_RESET = '\033[0m'
tools_definition = [ tools_definition = [
gadget.tools_mapping( coder.schema_read_file, coder.read_file ), gadget.tools_mapping( coder.schema_read_file, coder.read_file ),
@ -21,18 +19,26 @@ TOOLS = gadget.tool_schemas(tools_definition)
TOOL_HANDLERS = gadget.tool_handlers(tools_definition) TOOL_HANDLERS = gadget.tool_handlers(tools_definition)
def interactive_input(): def interactive_input(header_mode='full'):
fd = sys.stdin.fileno() fd = sys.stdin.fileno()
old = termios.tcgetattr(fd) old = termios.tcgetattr(fd)
print() print()
print("\u2500" * 50) if header_mode == 'full':
print("Hendrik AI Agent - Interactive Mode") print(separator())
print("\u2500" * 50) print("Hendrik AI Agent - Interactive Mode")
print(f"Workspace: {os.getcwd()}") print(separator())
print("\u2500" * 50) print(f"Workspace: {os.getcwd()}")
print("[Ctrl+W] Change workspace | :workspace <dir> | [Ctrl+D] Submit") print(separator())
print("\u2500" * 50) print("[Ctrl+W] Change workspace | :workspace <dir> | [Ctrl+D] Submit")
print(separator())
elif header_mode == 'workspace':
print(separator())
print(f"Workspace: {os.getcwd()}")
print(separator())
else:
print("[Ctrl+W] Change workspace | :workspace <dir> | [Ctrl+D] Submit")
print(separator())
buffer = bytearray() buffer = bytearray()
try: try:
@ -56,7 +62,7 @@ def interactive_input():
else: else:
os.chdir(resolved) os.chdir(resolved)
print(f"\u2192 Workspace changed to {os.getcwd()}") print(f"\u2192 Workspace changed to {os.getcwd()}")
return interactive_input() return interactive_input(header_mode='workspace')
elif ch in (b'\r', b'\n'): # Enter elif ch in (b'\r', b'\n'): # Enter
buffer.extend(b'\n') buffer.extend(b'\n')
sys.stdout.buffer.write(b'\r\n') sys.stdout.buffer.write(b'\r\n')
@ -80,10 +86,10 @@ def interactive_input():
resolved = os.path.abspath(ws) resolved = os.path.abspath(ws)
if not os.path.isdir(resolved): if not os.path.isdir(resolved):
print(f"Error: '{resolved}' is not a valid directory") print(f"Error: '{resolved}' is not a valid directory")
return interactive_input() return interactive_input(header_mode=header_mode)
os.chdir(resolved) os.chdir(resolved)
print(f"\u2192 Workspace changed to {os.getcwd()}") print(f"\u2192 Workspace changed to {os.getcwd()}")
return interactive_input() return interactive_input(header_mode='workspace')
return full_query return full_query
@ -167,14 +173,18 @@ def main():
print("No query provided.") print("No query provided.")
return return
messages = [{"role": "system", "content": gadget.build_system_prompt(tools_definition)}] messages = [{"role": "system", "content": gadget.build_system_prompt(tools_definition)}]
print(f"{TEXT_COLOR_YELLOW}Thinking...{TEXT_COLOR_RESET}") print(f"\n{TEXT_COLOR_YELLOW}Thinking...{TEXT_COLOR_RESET}")
final_answer, messages = agent_loop(user_query, messages, llm_client) final_answer, messages = agent_loop(user_query, messages, llm_client)
print(f"\n{TEXT_COLOR_GREEN}Final Answer:{TEXT_COLOR_RESET}") print(f"\n{TEXT_COLOR_GREEN}Final Answer:{TEXT_COLOR_RESET}")
print(final_answer) print(final_answer)
return return
first_interaction = True
while True: while True:
user_query = interactive_input() user_query = interactive_input(
header_mode='full' if first_interaction else 'compact'
)
first_interaction = False
if not user_query: if not user_query:
break break
if user_query.lower() in ('/exit', '/quit'): if user_query.lower() in ('/exit', '/quit'):

3
scripts/ansicolor.py Normal file
View File

@ -0,0 +1,3 @@
TEXT_COLOR_YELLOW = '\033[93m'
TEXT_COLOR_GREEN = '\033[92m'
TEXT_COLOR_RESET = '\033[0m'

5
scripts/separator.py Normal file
View File

@ -0,0 +1,5 @@
import shutil
def separator():
return "\u2500" * shutil.get_terminal_size().columns