From ab6ceef1a1c1347a489358a4039c188bda7007c5 Mon Sep 17 00:00:00 2001 From: chengyongru Date: Wed, 1 Jul 2026 14:38:40 +0800 Subject: [PATCH] refactor: simplify ampersand segment check Maintainer edit: keep the single-ampersand guard behavior, but fold the redirect exceptions into one condition instead of carrying temporary previous/next character variables. --- nanobot/agent/tools/shell.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/nanobot/agent/tools/shell.py b/nanobot/agent/tools/shell.py index d37bb949..565b38eb 100644 --- a/nanobot/agent/tools/shell.py +++ b/nanobot/agent/tools/shell.py @@ -879,11 +879,10 @@ class ExecTool(Tool): if paren_depth == 0: if command.startswith(("&&", "||"), i): operator_len = 2 - elif ch == "&": - prev_ch = command[i - 1] if i > 0 else "" - next_ch = command[i + 1] if i + 1 < len(command) else "" - if prev_ch not in {"<", ">"} and next_ch != ">": - operator_len = 1 + elif ch == "&" and not ( + (i > 0 and command[i - 1] in "<>") or command.startswith("&>", i) + ): + operator_len = 1 elif ch in {";", "|"}: operator_len = 1