myagent-ai 1.23.42 → 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.
@@ -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.41] 自保护检查:阻止 Agent 启动 myagent 自身进程
272
+ """[v1.23.43] 自保护检查:阻止 Agent 启动 myagent 自身进程
273
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 安装目录时拦截。
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
- # 模式 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):
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
- "[自保护] 禁止运行 myagent 启动脚本。"
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
  # ======================================================================
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "myagent-ai",
3
- "version": "1.23.42",
3
+ "version": "1.23.44",
4
4
  "description": "本地桌面端执行型AI助手 - Open Interpreter 风格 | Local Desktop Execution-Oriented AI Assistant",
5
5
  "main": "main.py",
6
6
  "bin": {
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.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"}
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
- # 处理 -nPattern 或 --name=Value 格式
355
- if a in _unsupported:
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
- if any(a.startswith(k) for k in _unsupported):
359
- # 带值参数如 --max=50 这种已经在 argparse 处理了
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