myagent-ai 1.23.40 → 1.23.42
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 +25 -1
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,13 +340,37 @@ async def cmd_rm(args):
|
|
|
340
340
|
async def cmd_grep(args):
|
|
341
341
|
"""搜索文件内容"""
|
|
342
342
|
import argparse
|
|
343
|
+
# [v1.23.40] 预过滤不支持的参数,防止 Agent 把系统 grep 参数传进来
|
|
344
|
+
_unsupported = {"-n", "--line-number", "-l", "--files-with-matches",
|
|
345
|
+
"-r", "-R", "--recursive", "-i", "--ignore-case",
|
|
346
|
+
"-c", "--count", "-w", "--word-regexp", "-v", "--invert-match",
|
|
347
|
+
"-e", "--regexp", "--include", "--exclude", "-E", "-F", "-P"}
|
|
348
|
+
_filtered = []
|
|
349
|
+
_skip_next = False
|
|
350
|
+
for i, a in enumerate(args):
|
|
351
|
+
if _skip_next:
|
|
352
|
+
_skip_next = False
|
|
353
|
+
continue
|
|
354
|
+
# 处理 -nPattern 或 --name=Value 格式
|
|
355
|
+
if a in _unsupported:
|
|
356
|
+
_skip_next = True
|
|
357
|
+
continue
|
|
358
|
+
if any(a.startswith(k) for k in _unsupported):
|
|
359
|
+
# 带值参数如 --max=50 这种已经在 argparse 处理了
|
|
360
|
+
if "=" not in a:
|
|
361
|
+
_skip_next = True
|
|
362
|
+
continue
|
|
363
|
+
_filtered.append(a)
|
|
364
|
+
if not _filtered:
|
|
365
|
+
_filtered = args # fallback
|
|
366
|
+
|
|
343
367
|
p = argparse.ArgumentParser(prog="myagent-ai grep", description="在目录中搜索文件内容")
|
|
344
368
|
p.add_argument("query", help="搜索关键词")
|
|
345
369
|
p.add_argument("path", help="搜索目录路径")
|
|
346
370
|
p.add_argument("-p", "--pattern", default="*", help="文件匹配模式 (如 *.py)")
|
|
347
371
|
p.add_argument("--max", type=int, default=50, help="最大结果数 (默认50)")
|
|
348
372
|
p.add_argument("--depth", type=int, default=10, help="最大递归深度 (默认10)")
|
|
349
|
-
a = p.parse_args(
|
|
373
|
+
a = p.parse_args(_filtered)
|
|
350
374
|
|
|
351
375
|
from skills.file_skill import FileSearchSkill
|
|
352
376
|
skill = FileSearchSkill()
|