hendrik/tools/syshendrik.py
2026-10-03 21:31:07 +07:00

50 lines
1.8 KiB
Python

import os
from lib import workspace
# Tools untuk membantu sistem Hendrik.
# State workspace sesi dimiliki lib.workspace dan dipakai bersama oleh
# tool coding, vision, dan TUI -- di sini hanya dibungkus sebagai tool aksi.
schema_workspace_change = {
"type": "function",
"function": {
"name": "workspace_change",
"description": "Change the current working directory of the agent session. Supports tilde (~) expansion for the user home directory (/home/aji/).",
"parameters": {
"type": "object",
"properties": {
"path": {"type": "string", "description": "The target directory path to change to."}
},
"required": ["path"]
}
}
}
def workspace_change(path):
previous_path = workspace.get_current_workspace()
try:
if path.startswith("~"):
target_path = os.path.expanduser(path)
else:
target_path = os.path.abspath(path)
if os.path.exists(target_path) and os.path.isdir(target_path):
workspace.set_current_workspace(target_path)
return (
f"Successfully changed workspace.\n"
f"previous workspace: {previous_path}\n"
f"current workspace : {target_path}"
)
else:
return (
f"Error: The path {target_path} does not exist or is not a directory.\n"
f"previous workspace: {previous_path}\n"
f"current workspace : {previous_path} (unchanged)"
)
except Exception as e:
return (
f"Error changing workspace: {str(e)}\n"
f"previous workspace: {previous_path}\n"
f"current workspace : {workspace.get_current_workspace()}"
)