PYAE1994 commited on
Commit
ab01d3f
·
verified ·
1 Parent(s): 47a0d84

Create tools_runtime.py

Browse files
Files changed (1) hide show
  1. app/agent/tools_runtime.py +35 -0
app/agent/tools_runtime.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import subprocess
3
+
4
+ def run_shell(cmd: str):
5
+ """Execute shell command safely"""
6
+ result = subprocess.run(
7
+ cmd,
8
+ shell=True,
9
+ capture_output=True,
10
+ text=True
11
+ )
12
+ return {
13
+ "stdout": result.stdout,
14
+ "stderr": result.stderr,
15
+ "code": result.returncode
16
+ }
17
+
18
+ def write_file(path, content):
19
+ os.makedirs(os.path.dirname(path), exist_ok=True)
20
+ with open(path, "w") as f:
21
+ f.write(content)
22
+ return {"status": "written", "path": path}
23
+
24
+ def read_file(path):
25
+ with open(path, "r") as f:
26
+ return f.read()
27
+
28
+ def list_files(path="."):
29
+ return os.listdir(path)
30
+
31
+ def delete_file(path):
32
+ if os.path.exists(path):
33
+ os.remove(path)
34
+ return {"deleted": path}
35
+ return {"error": "not found"}