-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskill_executor.py
More file actions
43 lines (34 loc) · 1.12 KB
/
Copy pathskill_executor.py
File metadata and controls
43 lines (34 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import subprocess
import tempfile
from paths import SKILLS_DIR as _SKILLS_DIR
SKILLS_DIR = str(_SKILLS_DIR)
def execute_skill(skill_name: str, code: str) -> str:
try:
skill_dir = os.path.join(SKILLS_DIR, skill_name)
if not os.path.exists(skill_dir):
return f"❌ Skill '{skill_name}' tidak ditemukan."
with tempfile.NamedTemporaryFile(
mode='w',
suffix='.py',
dir=skill_dir,
delete=False
) as f:
f.write(code)
temp_file = f.name
result = subprocess.run(
['python3.11', temp_file],
capture_output=True,
text=True,
timeout=60,
cwd=skill_dir
)
os.unlink(temp_file)
if result.returncode == 0:
return result.stdout.strip() or "✅ Skill berhasil dieksekusi."
else:
return f"❌ Error: {result.stderr.strip()}"
except subprocess.TimeoutExpired:
return "❌ Skill timeout (lebih dari 60 detik)"
except Exception as e:
return f"❌ Gagal eksekusi skill: {str(e)}"