The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(terminal): blocked-command errors carry a concrete recovery recipe
Tekniumb1711c6f2e96
diff --git a/tests/tools/test_blocked_command_guidance.py b/tests/tools/test_blocked_command_guidance.pynew file mode 100644index 00000000000..324f08838f2--- /dev/null+++ b/tests/tools/test_blocked_command_guidance.py@@ -0,0 +1,44 @@+"""Tests for blocked-command recovery guidance (parser-limit + backgrounding)."""++import pytest++from tools.approval import _hardline_block_result, _PARSER_LIMIT_DESCRIPTION, _MALFORMED_EXEC_DESCRIPTION+from tools.terminal_tool import _foreground_background_guidance+++class TestParserLimitRecovery:+ def test_parser_limit_block_has_recovery_recipe(self):+ r = _hardline_block_result(_PARSER_LIMIT_DESCRIPTION)+ assert r["approved"] is False+ assert "RECOVERY" in r["message"]+ assert "write_file" in r["message"]+ assert "bash /path/script.sh" in r["message"]++ def test_malformed_exec_block_has_recovery_recipe(self):+ r = _hardline_block_result(_MALFORMED_EXEC_DESCRIPTION)+ assert "RECOVERY" in r["message"]++ def test_real_hardline_blocks_unchanged(self):+ r = _hardline_block_result("recursive delete of root filesystem")+ assert "RECOVERY" not in r["message"]+ assert "unconditional blocklist" in r["message"]+++class TestBackgroundGuidanceRecipes:+ def test_ampersand_block_names_exact_call_shape(self):+ msg = _foreground_background_guidance("python3 server.py &")+ assert msg is not None+ assert "WITHOUT the '&'" in msg+ assert "background=true" in msg++ def test_nohup_block_names_exact_call_shape(self):+ msg = _foreground_background_guidance("nohup ./worker.sh > /dev/null 2>&1")+ assert msg is not None+ assert "WITHOUT the wrapper" in msg+ assert "notify_on_complete=true" in msg++ def test_plain_command_unaffected(self):+ assert _foreground_background_guidance("echo hello") is None++ def test_quoted_ampersand_not_flagged(self):+ assert _foreground_background_guidance('git commit -m "a & b"') is Nonediff --git a/tools/approval.py b/tools/approval.pyindex 629c6747ff6..451588a2cfa 100644--- a/tools/approval.py+++ b/tools/approval.py@@ -587,17 +587,31 @@ def _user_deny_block_result(pattern: str) -> dict:def _hardline_block_result(description: str) -> dict:"""Build the standard block result for a hardline match."""+ message = (+ f"BLOCKED (hardline): {description}. "+ "This command is on the unconditional blocklist and cannot "+ "be executed via the agent — not even with --yolo, /yolo, "+ "approvals.mode=off, or cron approve mode. If you genuinely "+ "need to run it, run it yourself in a terminal outside the "+ "agent."+ )+ # The parser-limit block is almost always a giant inline payload+ # (heredoc script, base64 blob, one-line python -c program) — not a+ # genuinely forbidden operation. 198 occurrences in a 250k-call+ # production window, typically followed by blind rephrase retries.+ # Tell the model the working alternative explicitly.+ if description in (_PARSER_LIMIT_DESCRIPTION, _MALFORMED_EXEC_DESCRIPTION):+ message += (+ " RECOVERY: this block fires on oversized/unparseable inline "+ "command payloads (heredocs, giant one-liners), not on the "+ "operation itself. Write the script to a file with write_file, "+ "then run it: terminal(command=\"bash /path/script.sh\") or "+ "\"python3 /path/script.py\". Do not retry inline."+ )return {"approved": False,"hardline": True,- "message": (- f"BLOCKED (hardline): {description}. "- "This command is on the unconditional blocklist and cannot "- "be executed via the agent — not even with --yolo, /yolo, "- "approvals.mode=off, or cron approve mode. If you genuinely "- "need to run it, run it yourself in a terminal outside the "- "agent."- ),+ "message": message,}diff --git a/tools/terminal_tool.py b/tools/terminal_tool.pyindex d8302fe1878..c585c71d5e2 100644--- a/tools/terminal_tool.py+++ b/tools/terminal_tool.py@@ -2164,14 +2164,16 @@ def _foreground_background_guidance(command: str) -> str | None:if _SHELL_LEVEL_BACKGROUND_RE.search(unquoted):return ("Foreground command uses shell-level background wrappers (nohup/disown/setsid). "- "Use terminal(background=true) so Hermes can track the process, then run "- "readiness checks and tests in separate commands."+ "Re-send WITHOUT the wrapper as terminal(command=\"<cmd>\", background=true, "+ "notify_on_complete=true) so Hermes tracks the process, then run readiness "+ "checks and tests in separate commands.")if _INLINE_BACKGROUND_AMP_RE.search(unquoted) or _TRAILING_BACKGROUND_AMP_RE.search(unquoted):return (- "Foreground command uses '&' backgrounding. Use terminal(background=true) for long-lived "- "processes, then run health checks and tests in follow-up terminal calls."+ "Foreground command uses '&' backgrounding. Re-send WITHOUT the '&' as "+ "terminal(command=\"<cmd>\", background=true) — add notify_on_complete=true "+ "for bounded jobs — then run health checks and tests in follow-up terminal calls.")for pattern in _LONG_LIVED_FOREGROUND_PATTERNS: