From 2b0a3b11676ca9c641ecf88e34ab6045217ed028 Mon Sep 17 00:00:00 2001 From: AI Christianson Date: Tue, 17 Dec 2024 15:06:51 -0500 Subject: [PATCH] allow enabling of cowboy mode from approval prompt; print tool error panels --- CHANGELOG.md | 3 +++ ra_aid/console/output.py | 4 ++++ ra_aid/prompts.py | 1 + ra_aid/tools/shell.py | 19 +++++++++++++++++-- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3a3b87..d968914 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - Allow shell commands to be run in read-only mode. +- When asking for shell command approval, allow cowboy mode to be enabled. +- Update prompt to suggest commands be run in non-interactive mode if possible, e.g. using --no-pager git flag. +- Show tool errors in a panel. ## [0.6.1] - 2024-12-17 diff --git a/ra_aid/console/output.py b/ra_aid/console/output.py index acaeb50..c97c7b5 100644 --- a/ra_aid/console/output.py +++ b/ra_aid/console/output.py @@ -25,3 +25,7 @@ def print_agent_output(chunk: Dict[str, Any]) -> None: else: if msg.content.strip(): console.print(Panel(Markdown(msg.content), title="🤖 Assistant")) + elif 'tools' in chunk and 'messages' in chunk['tools']: + for msg in chunk['tools']['messages']: + if msg.status == 'error' and msg.content: + console.print(Panel(Markdown(msg.content), title="❌ Tool Error", border_style="red bold")) \ No newline at end of file diff --git a/ra_aid/prompts.py b/ra_aid/prompts.py index dea3266..941f6b3 100644 --- a/ra_aid/prompts.py +++ b/ra_aid/prompts.py @@ -69,6 +69,7 @@ If the task requires *ANY* compilation, unit tests, or any other non-trivial cha If this is a trival task that can be completed in one shot, do the change using tools available and call one_shot_completed. Remember, many tasks are more complex and nuanced than they seem and still require requesting implementation. For one shot tasks, still take some time to consider whether compilation, testing, or additional validation should be done to check your work. + If implement the task yourself, do not request implementation. Thoroughness and Completeness diff --git a/ra_aid/tools/shell.py b/ra_aid/tools/shell.py index 8f29f31..fcc7114 100644 --- a/ra_aid/tools/shell.py +++ b/ra_aid/tools/shell.py @@ -2,7 +2,7 @@ from typing import Dict, Union from langchain_core.tools import tool from rich.console import Console from rich.panel import Panel -from rich.prompt import Confirm +from rich.prompt import Prompt from ra_aid.tools.memory import _global_memory from ra_aid.proc.interactive import run_interactive_command from ra_aid.text.processing import truncate_output @@ -39,12 +39,27 @@ def run_shell_command(command: str) -> Dict[str, Union[str, int, bool]]: console.print(Panel(command, title="🐚 Shell", border_style="bright_yellow")) if not cowboy_mode: - if not Confirm.ask("Execute this command?", default=True): + choices = ["y", "n", "c"] + response = Prompt.ask( + "Execute this command? (y=yes, n=no, c=enable cowboy mode for session)", + choices=choices, + default="y", + show_choices=True, + show_default=True + ) + + if response == "n": + print() return { "output": "Command execution cancelled by user", "return_code": 1, "success": False } + elif response == "c": + _global_memory['config']['cowboy_mode'] = True + console.print("") + console.print(" " + get_cowboy_message()) + console.print("") try: print()