myagent-ai 1.23.41 → 1.23.43
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 +60 -0
- package/package.json +1 -1
- package/scripts/cli.py +19 -9
package/executor/engine.py
CHANGED
|
@@ -268,6 +268,55 @@ class ExecutionEngine:
|
|
|
268
268
|
except Exception:
|
|
269
269
|
return True
|
|
270
270
|
|
|
271
|
+
def _check_self_run(self, code: str, work_dir: str) -> Optional[str]:
|
|
272
|
+
"""[v1.23.41] 自保护检查:阻止 Agent 启动 myagent 自身进程
|
|
273
|
+
|
|
274
|
+
检测模式:
|
|
275
|
+
1. 直接运行 main.py / main.pyc(python main.py, python3 main.py, ./main.py 等)
|
|
276
|
+
2. 通过 myagent-ai start 等命令启动服务
|
|
277
|
+
3. 运行 start.sh / start.js / start.ps1 等启动脚本
|
|
278
|
+
|
|
279
|
+
只在 work_dir 是 myagent 安装目录时拦截。
|
|
280
|
+
"""
|
|
281
|
+
import os
|
|
282
|
+
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
|
+
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
|
+
|
|
306
|
+
# 模式 2: myagent-ai start / start.sh / start.js
|
|
307
|
+
if re.search(r'\bmyagent-ai\s+(?:start|run|launch)\b', code_stripped):
|
|
308
|
+
return (
|
|
309
|
+
"[自保护] 禁止在 myagent 内部启动 myagent 服务。"
|
|
310
|
+
"myagent 服务已经在运行中,请勿重复启动。"
|
|
311
|
+
)
|
|
312
|
+
if re.search(r'\b(?:bash|sh|\.\/)?\s*start\.(?:sh|ps1|bat)\b', code_stripped):
|
|
313
|
+
return (
|
|
314
|
+
"[自保护] 禁止运行 myagent 启动脚本。"
|
|
315
|
+
"myagent 服务已经在运行中,请直接测试你需要的功能。"
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
return None
|
|
319
|
+
|
|
271
320
|
# ======================================================================
|
|
272
321
|
# 启动时一次性检测
|
|
273
322
|
# ======================================================================
|
|
@@ -534,6 +583,17 @@ class ExecutionEngine:
|
|
|
534
583
|
metadata={**metadata, "mode": self.execution_mode},
|
|
535
584
|
)
|
|
536
585
|
|
|
586
|
+
# [v1.23.41] 自保护检查:阻止 Agent 启动 myagent 自身进程
|
|
587
|
+
_self_check = self._check_self_run(code, work_dir)
|
|
588
|
+
if _self_check:
|
|
589
|
+
return ExecResult(
|
|
590
|
+
success=False,
|
|
591
|
+
error=_self_check,
|
|
592
|
+
language=language,
|
|
593
|
+
code=code,
|
|
594
|
+
metadata={**metadata, "mode": self.execution_mode, "self_protect": True},
|
|
595
|
+
)
|
|
596
|
+
|
|
537
597
|
self._execution_count += 1
|
|
538
598
|
exec_id = f"exec_{self._execution_count}"
|
|
539
599
|
|
package/package.json
CHANGED
package/scripts/cli.py
CHANGED
|
@@ -340,23 +340,33 @@ async def cmd_rm(args):
|
|
|
340
340
|
async def cmd_grep(args):
|
|
341
341
|
"""搜索文件内容"""
|
|
342
342
|
import argparse
|
|
343
|
-
# [v1.23.
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
343
|
+
# [v1.23.42] 预过滤不支持的参数,防止 Agent 把系统 grep 参数传进来
|
|
344
|
+
# 区分标志(无参数)和选项(带参数)
|
|
345
|
+
_unsupported_flags = {"-n", "--line-number", "-l", "--files-with-matches",
|
|
346
|
+
"-r", "-R", "--recursive", "-i", "--ignore-case",
|
|
347
|
+
"-c", "--count", "-w", "--word-regexp", "-v",
|
|
348
|
+
"--invert-match", "-E", "-F", "-P", "-m"}
|
|
349
|
+
_unsupported_opts = {"-e", "--regexp", "--include", "--exclude",
|
|
350
|
+
"--after-context", "--before-context", "--context",
|
|
351
|
+
"-A", "-B", "-C", "--max-count", "--color"}
|
|
348
352
|
_filtered = []
|
|
349
353
|
_skip_next = False
|
|
350
354
|
for i, a in enumerate(args):
|
|
351
355
|
if _skip_next:
|
|
352
356
|
_skip_next = False
|
|
353
357
|
continue
|
|
354
|
-
|
|
355
|
-
|
|
358
|
+
if a in _unsupported_flags:
|
|
359
|
+
# 标志参数,不跳过下一个
|
|
360
|
+
continue
|
|
361
|
+
if a in _unsupported_opts:
|
|
362
|
+
# 带参数选项,跳过下一个
|
|
356
363
|
_skip_next = True
|
|
357
364
|
continue
|
|
358
|
-
|
|
359
|
-
|
|
365
|
+
# 处理组合标志如 -rn、长选项 --name=Value
|
|
366
|
+
if any(a.startswith(k) for k in _unsupported_flags):
|
|
367
|
+
# -rn 或 -ni 等组合标志,不跳过下一个
|
|
368
|
+
continue
|
|
369
|
+
if any(a.startswith(k) for k in _unsupported_opts):
|
|
360
370
|
if "=" not in a:
|
|
361
371
|
_skip_next = True
|
|
362
372
|
continue
|