Delete pygmyclaw_multitool.py
Browse files- pygmyclaw_multitool.py +0 -138
pygmyclaw_multitool.py
DELETED
|
@@ -1,138 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""
|
| 3 |
-
PygmyClaw Multitool – Contains the actual tool implementations.
|
| 4 |
-
"""
|
| 5 |
-
import json
|
| 6 |
-
import sys
|
| 7 |
-
import os
|
| 8 |
-
import platform
|
| 9 |
-
import time
|
| 10 |
-
from pathlib import Path
|
| 11 |
-
|
| 12 |
-
SCRIPT_DIR = Path(__file__).parent.resolve()
|
| 13 |
-
ERROR_LOG = SCRIPT_DIR / "error_log.json"
|
| 14 |
-
MAX_LOG_ENTRIES = 1000
|
| 15 |
-
|
| 16 |
-
# ----------------------------------------------------------------------
|
| 17 |
-
# Tool definitions
|
| 18 |
-
TOOLS = {
|
| 19 |
-
"list_tools_detailed": {
|
| 20 |
-
"name": "list_tools_detailed",
|
| 21 |
-
"description": "List all available tools with their descriptions and parameters.",
|
| 22 |
-
"parameters": {},
|
| 23 |
-
"func": "do_list_tools"
|
| 24 |
-
},
|
| 25 |
-
"sys_info": {
|
| 26 |
-
"name": "sys_info",
|
| 27 |
-
"description": "Get system information (OS, Python version, etc.).",
|
| 28 |
-
"parameters": {},
|
| 29 |
-
"func": "do_sys_info"
|
| 30 |
-
},
|
| 31 |
-
"log_error": {
|
| 32 |
-
"name": "log_error",
|
| 33 |
-
"description": "Log an error message to the error log.",
|
| 34 |
-
"parameters": {
|
| 35 |
-
"msg": "string",
|
| 36 |
-
"trace": "string (optional)"
|
| 37 |
-
},
|
| 38 |
-
"func": "do_log_error"
|
| 39 |
-
},
|
| 40 |
-
"echo": {
|
| 41 |
-
"name": "echo",
|
| 42 |
-
"description": "Echo the input text (for testing).",
|
| 43 |
-
"parameters": {"text": "string"},
|
| 44 |
-
"func": "do_echo"
|
| 45 |
-
}
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
def do_list_tools():
|
| 49 |
-
"""Return the list of tools with their metadata."""
|
| 50 |
-
tools_list = []
|
| 51 |
-
for name, info in TOOLS.items():
|
| 52 |
-
tools_list.append({
|
| 53 |
-
"name": name,
|
| 54 |
-
"description": info["description"],
|
| 55 |
-
"parameters": info["parameters"]
|
| 56 |
-
})
|
| 57 |
-
return {"tools": tools_list}
|
| 58 |
-
|
| 59 |
-
def do_sys_info():
|
| 60 |
-
"""Return system information."""
|
| 61 |
-
return {
|
| 62 |
-
"os": platform.system(),
|
| 63 |
-
"os_release": platform.release(),
|
| 64 |
-
"python_version": platform.python_version(),
|
| 65 |
-
"hostname": platform.node()
|
| 66 |
-
}
|
| 67 |
-
|
| 68 |
-
def do_log_error(msg, trace=""):
|
| 69 |
-
"""Append an error to the error log file."""
|
| 70 |
-
entry = {
|
| 71 |
-
"timestamp": time.time(),
|
| 72 |
-
"msg": msg,
|
| 73 |
-
"trace": trace
|
| 74 |
-
}
|
| 75 |
-
try:
|
| 76 |
-
if ERROR_LOG.exists():
|
| 77 |
-
with open(ERROR_LOG) as f:
|
| 78 |
-
log = json.load(f)
|
| 79 |
-
else:
|
| 80 |
-
log = []
|
| 81 |
-
log.append(entry)
|
| 82 |
-
# Keep only last MAX_LOG_ENTRIES
|
| 83 |
-
if len(log) > MAX_LOG_ENTRIES:
|
| 84 |
-
log = log[-MAX_LOG_ENTRIES:]
|
| 85 |
-
with open(ERROR_LOG, 'w') as f:
|
| 86 |
-
json.dump(log, f, indent=2)
|
| 87 |
-
return {"status": "logged"}
|
| 88 |
-
except Exception as e:
|
| 89 |
-
return {"error": f"Failed to write log: {e}"}
|
| 90 |
-
|
| 91 |
-
def do_echo(text):
|
| 92 |
-
"""Echo the input."""
|
| 93 |
-
return {"echo": text}
|
| 94 |
-
|
| 95 |
-
# ----------------------------------------------------------------------
|
| 96 |
-
# Main dispatcher
|
| 97 |
-
def main():
|
| 98 |
-
try:
|
| 99 |
-
data = json.loads(sys.stdin.read())
|
| 100 |
-
action = data.get("action")
|
| 101 |
-
if not action:
|
| 102 |
-
print(json.dumps({"error": "No action specified"}))
|
| 103 |
-
return
|
| 104 |
-
|
| 105 |
-
# Find the tool
|
| 106 |
-
tool_info = TOOLS.get(action)
|
| 107 |
-
if not tool_info:
|
| 108 |
-
print(json.dumps({"error": f"Unknown action '{action}'"}))
|
| 109 |
-
return
|
| 110 |
-
|
| 111 |
-
# Call the corresponding function
|
| 112 |
-
func_name = tool_info["func"]
|
| 113 |
-
if func_name == "do_list_tools":
|
| 114 |
-
result = do_list_tools()
|
| 115 |
-
elif func_name == "do_sys_info":
|
| 116 |
-
result = do_sys_info()
|
| 117 |
-
elif func_name == "do_log_error":
|
| 118 |
-
msg = data.get("msg")
|
| 119 |
-
trace = data.get("trace", "")
|
| 120 |
-
if msg is None:
|
| 121 |
-
result = {"error": "Missing 'msg' parameter"}
|
| 122 |
-
else:
|
| 123 |
-
result = do_log_error(msg, trace)
|
| 124 |
-
elif func_name == "do_echo":
|
| 125 |
-
text = data.get("text")
|
| 126 |
-
if text is None:
|
| 127 |
-
result = {"error": "Missing 'text' parameter"}
|
| 128 |
-
else:
|
| 129 |
-
result = do_echo(text)
|
| 130 |
-
else:
|
| 131 |
-
result = {"error": f"Internal error: unknown function {func_name}"}
|
| 132 |
-
|
| 133 |
-
print(json.dumps(result))
|
| 134 |
-
except Exception as e:
|
| 135 |
-
print(json.dumps({"error": f"Multitool exception: {e}"}))
|
| 136 |
-
|
| 137 |
-
if __name__ == "__main__":
|
| 138 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|