myagent-ai 1.23.43 → 1.23.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/executor/engine.py +58 -37
- package/package.json +1 -1
package/executor/engine.py
CHANGED
|
@@ -269,52 +269,73 @@ class ExecutionEngine:
|
|
|
269
269
|
return True
|
|
270
270
|
|
|
271
271
|
def _check_self_run(self, code: str, work_dir: str) -> Optional[str]:
|
|
272
|
-
"""[v1.23.
|
|
272
|
+
"""[v1.23.43] 自保护检查:阻止 Agent 启动 myagent 自身进程
|
|
273
273
|
|
|
274
|
-
|
|
275
|
-
1.
|
|
276
|
-
2.
|
|
277
|
-
3.
|
|
278
|
-
|
|
279
|
-
只在 work_dir 是 myagent 安装目录时拦截。
|
|
274
|
+
检测策略:
|
|
275
|
+
1. work_dir 是 myagent 安装目录 → 拦截任何 main.py / start.sh
|
|
276
|
+
2. 命令中包含 myagent 特征参数 (--tray/--web/--server 等) → 无论目录都拦截
|
|
277
|
+
3. 命令路径指向 myagent 安装目录 → 拦截
|
|
280
278
|
"""
|
|
281
279
|
import os
|
|
282
280
|
code_stripped = code.strip()
|
|
283
|
-
|
|
284
|
-
# 判断 work_dir 是否是 myagent 安装目录(包含 main.py + start.sh/js)
|
|
285
|
-
_is_myagent_dir = (
|
|
286
|
-
work_dir
|
|
287
|
-
and os.path.isfile(os.path.join(work_dir, "main.py"))
|
|
288
|
-
and (
|
|
289
|
-
os.path.isfile(os.path.join(work_dir, "start.sh"))
|
|
290
|
-
or os.path.isfile(os.path.join(work_dir, "start.js"))
|
|
291
|
-
)
|
|
292
|
-
)
|
|
293
|
-
if not _is_myagent_dir:
|
|
294
|
-
return None
|
|
295
|
-
|
|
296
|
-
# 模式 1: python/python3 main.py [args]
|
|
297
281
|
import re
|
|
298
|
-
if re.search(r'\b(?:python3?|\.\/)?\s*main\.py\b', code_stripped):
|
|
299
|
-
return (
|
|
300
|
-
"[自保护] 禁止启动 myagent 自身进程 (main.py)。"
|
|
301
|
-
"如果你需要测试 myagent 的功能,请使用 'myagent-ai' CLI 命令。"
|
|
302
|
-
"如果你在调试 myagent 项目代码,请直接测试具体的 Python 模块,"
|
|
303
|
-
"例如: python -c 'from agents.main_agent import MainAgent; print(MainAgent)'"
|
|
304
|
-
)
|
|
305
282
|
|
|
306
|
-
#
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
"[自保护] 禁止在 myagent 内部启动 myagent 服务。"
|
|
310
|
-
"myagent 服务已经在运行中,请勿重复启动。"
|
|
311
|
-
)
|
|
312
|
-
if re.search(r'\b(?:bash|sh|\.\/)?\s*start\.(?:sh|ps1|bat)\b', code_stripped):
|
|
283
|
+
# 策略 2: myagent 特征参数 — 无论在哪个目录,只要出现就拦截
|
|
284
|
+
_myagent_flags = {"--tray", "--autostart", "--no-autostart", "--setup", "--debug"}
|
|
285
|
+
if re.search(r'\bmain\.py\b', code_stripped) and any(f in code_stripped for f in _myagent_flags):
|
|
313
286
|
return (
|
|
314
|
-
"[自保护]
|
|
315
|
-
"myagent
|
|
287
|
+
"[自保护] 检测到 main.py + myagent 特征参数 (如 --tray/--web/--server)。"
|
|
288
|
+
"禁止启动 myagent 自身进程。"
|
|
289
|
+
"请直接测试具体的 Python 模块,例如: python -c 'from agents.main_agent import MainAgent'"
|
|
316
290
|
)
|
|
317
291
|
|
|
292
|
+
# 策略 1: work_dir 是 myagent 安装目录
|
|
293
|
+
_is_myagent_dir = False
|
|
294
|
+
_myagent_paths = [
|
|
295
|
+
work_dir,
|
|
296
|
+
# 从命令中提取 cd 目标路径
|
|
297
|
+
]
|
|
298
|
+
|
|
299
|
+
# 从命令中提取 cd 目标路径
|
|
300
|
+
for m in re.finditer(r'\bcd\s+(?:["\']?)([^;"\'&\n]+?)(?:["\']?)\s*[;&\n|]', code_stripped + "\n"):
|
|
301
|
+
_myagent_paths.append(m.group(1).strip())
|
|
302
|
+
# 也匹配 && 前的 cd
|
|
303
|
+
for m in re.finditer(r'\bcd\s+([^\s;&|\'"]+)', code_stripped):
|
|
304
|
+
_myagent_paths.append(m.group(1).strip())
|
|
305
|
+
|
|
306
|
+
for _dir in _myagent_paths:
|
|
307
|
+
if not _dir:
|
|
308
|
+
continue
|
|
309
|
+
if (
|
|
310
|
+
os.path.isfile(os.path.join(_dir, "main.py"))
|
|
311
|
+
and (
|
|
312
|
+
os.path.isfile(os.path.join(_dir, "start.sh"))
|
|
313
|
+
or os.path.isfile(os.path.join(_dir, "start.js"))
|
|
314
|
+
)
|
|
315
|
+
):
|
|
316
|
+
_is_myagent_dir = True
|
|
317
|
+
break
|
|
318
|
+
|
|
319
|
+
if _is_myagent_dir:
|
|
320
|
+
# 模式 1: python/python3 main.py [args]
|
|
321
|
+
if re.search(r'\bmain\.py\b', code_stripped):
|
|
322
|
+
return (
|
|
323
|
+
"[自保护] 禁止启动 myagent 自身进程 (main.py)。"
|
|
324
|
+
"如果你在调试 myagent 项目代码,请直接测试具体的 Python 模块,"
|
|
325
|
+
"例如: python -c 'from agents.main_agent import MainAgent; print(MainAgent)'"
|
|
326
|
+
)
|
|
327
|
+
# 模式 2: myagent-ai start / start.sh / start.js
|
|
328
|
+
if re.search(r'\bmyagent-ai\s+(?:start|run|launch)\b', code_stripped):
|
|
329
|
+
return (
|
|
330
|
+
"[自保护] 禁止在 myagent 内部启动 myagent 服务。"
|
|
331
|
+
"myagent 服务已经在运行中,请勿重复启动。"
|
|
332
|
+
)
|
|
333
|
+
if re.search(r'\b(?:bash|sh|\.\/)?\s*start\.(?:sh|ps1|bat)\b', code_stripped):
|
|
334
|
+
return (
|
|
335
|
+
"[自保护] 禁止运行 myagent 启动脚本。"
|
|
336
|
+
"myagent 服务已经在运行中,请直接测试你需要的功能。"
|
|
337
|
+
)
|
|
338
|
+
|
|
318
339
|
return None
|
|
319
340
|
|
|
320
341
|
# ======================================================================
|