Build and run agents you can see, understand and trust.
Python agentchatbotlarge-language-modelsllmllm-agentmcpmulti-agentmulti-modalreact-agentrealtime-agentvoice-agentvoice-assistant
fix(tool): stop classifying tee as a read-only command (#2629)
Luochenchen6b43b13a4640
diff --git a/src/agentscope/tool/_builtin/_bash_parser.py b/src/agentscope/tool/_builtin/_bash_parser.pyindex 17cdbc0a8..95fc65e0a 100644--- a/src/agentscope/tool/_builtin/_bash_parser.py+++ b/src/agentscope/tool/_builtin/_bash_parser.py@@ -21,7 +21,8 @@ from tree_sitter import Language, Parser, Nodefrom .._constants import DANGEROUS_NODE_TYPES, DANGEROUS_COMMANDS-# Commands that are considered safe and don't require permission rules+# Commands that are considered safe and don't require permission rules,+# so any command that writes must not be listed hereSAFE_COMMANDS: Set[str] = {"echo","cat",@@ -32,7 +33,6 @@ SAFE_COMMANDS: Set[str] = {"false","printf","grep",- "tee",}# Safe environment variables that can be skipped when extracting command prefixdiff --git a/tests/permission_bash_parser_test.py b/tests/permission_bash_parser_test.pyindex 975bb5c9b..3899af451 100644--- a/tests/permission_bash_parser_test.py+++ b/tests/permission_bash_parser_test.py@@ -123,7 +123,7 @@ class BashCommandParserTest(IsolatedAsyncioTestCase):test_cases = [("cat file.txt | grep error", []),("docker ps | grep nginx", ["docker ps"]),- ("npm run build | tee output.log", ["npm run"]),+ ("npm run build | tee output.log", ["npm run", "tee output.log"]),]for command, expected in test_cases:@@ -140,7 +140,7 @@ class BashCommandParserTest(IsolatedAsyncioTestCase):),("npm install && npm run build | tee log.txt",- ["npm install", "npm run"],+ ["npm install", "npm run", "tee log.txt"],),]@@ -282,6 +282,22 @@ class BashParserReadOnlyTest(IsolatedAsyncioTestCase):f"Expected '{cmd}' to be non-read-only",)+ async def test_tee_writes_through_are_not_read_only(self) -> None:+ """Test commands writing through ``tee`` are not read-only."""+ writing_commands = [+ "echo x | tee out.txt",+ "echo x | tee -a out.txt",+ "echo x | tee /tmp/out.txt",+ "cat README.md | tee /tmp/out.txt",+ "printf hi | tee /tmp/out.txt",+ ]+ for cmd in writing_commands:+ with self.subTest(cmd=cmd):+ self.assertFalse(+ self.parser.is_read_only_command(cmd),+ f"Expected '{cmd}' to be non-read-only",+ )+async def test_single_read_only_docker_commands(self) -> None:"""Test single read-only docker commands."""read_only_commands = [