From a3d5696c19996a690b1869296776c00d1bfe08fe Mon Sep 17 00:00:00 2001 From: retoor Date: Fri, 7 Nov 2025 22:07:32 +0100 Subject: [PATCH] maintenance: update project dependencies and improve file handling feat: add autonomous mode with command-line argument refactor: improve assistant output and result tracking refactor: handle autonomous mode in assistant refactor: improve error handling in web tools --- CHANGELOG.md | 8 ++++++++ pyproject.toml | 2 +- rp/__main__.py | 1 + rp/core/assistant.py | 26 +++++++++++++++++++++++--- rp/tools/web.py | 25 ++++++++++++++++--------- 5 files changed, 49 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ecdaa3..2766c47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,14 @@ + + +## Version 1.23.0 - 2025-11-07 + +This release updates project dependencies and improves file handling. The changelog now includes details about the previous version (1.22.0). + +**Changes:** 4 files, 23 lines +**Languages:** Markdown (8 lines), Other (3 lines), TOML (2 lines), Text (10 lines) ## Version 1.22.0 - 2025-11-07 diff --git a/pyproject.toml b/pyproject.toml index b5c7f9e..275bbd0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "rp" -version = "1.22.0" +version = "1.23.0" description = "R python edition. The ultimate autonomous AI CLI." readme = "README.md" requires-python = ">=3.10" diff --git a/rp/__main__.py b/rp/__main__.py index fc72ac2..18d2acb 100644 --- a/rp/__main__.py +++ b/rp/__main__.py @@ -44,6 +44,7 @@ Commands in interactive mode: parser.add_argument("-u", "--api-url", help="API endpoint URL") parser.add_argument("--model-list-url", help="Model list endpoint URL") parser.add_argument("-i", "--interactive", action="store_true", help="Interactive mode") + parser.add_argument("-a", "--autonomous", action="store_true", help="Autonomous mode") parser.add_argument("-v", "--verbose", action="store_true", help="Verbose output") parser.add_argument( "--debug", action="store_true", help="Enable debug mode with detailed logging" diff --git a/rp/core/assistant.py b/rp/core/assistant.py index 97043d3..79f4ed2 100644 --- a/rp/core/assistant.py +++ b/rp/core/assistant.py @@ -105,6 +105,7 @@ class Assistant: self.background_monitoring = False self.usage_tracker = UsageTracker() self.background_tasks = set() + self.last_result = None self.init_database() self.messages.append(init_system_message(args)) try: @@ -405,7 +406,9 @@ class Assistant: # Use enhanced processing if available, otherwise fall back to basic processing if hasattr(self, "enhanced") and self.enhanced: result = self.enhanced.process_with_enhanced_context(user_input) - print(result) + if result != self.last_result: + print(result) + self.last_result = result else: process_message(self, user_input) except EOFError: @@ -423,6 +426,19 @@ class Assistant: message = sys.stdin.read() process_message(self, message) + def run_autonomous(self): + + if self.args.message: + task = self.args.message + else: + self.setup_readline() + task = input("> ").strip() + if not task: + print("No task provided. Exiting.") + return + from rp.autonomous import run_autonomous_mode + run_autonomous_mode(self, task) + def cleanup(self): if hasattr(self, "enhanced") and self.enhanced: try: @@ -446,7 +462,9 @@ class Assistant: def run(self): try: - if self.args.interactive or (not self.args.message and sys.stdin.isatty()): + if self.args.autonomous or (not self.args.interactive and not self.args.message and sys.stdin.isatty()): + self.run_autonomous() + elif self.args.interactive: self.run_repl() else: self.run_single() @@ -482,4 +500,6 @@ def process_message(assistant, message): total_cost = assistant.usage_tracker.session_usage["estimated_cost"] print(f"{Colors.YELLOW}💰 Cost: ${cost:.4f} | Total: ${total_cost:.4f}{Colors.RESET}") result = assistant.process_response(response) - print(f"\n{Colors.GREEN}r:{Colors.RESET} {result}\n") + if result != assistant.last_result: + print(f"\n{Colors.GREEN}r:{Colors.RESET} {result}\n") + assistant.last_result = result diff --git a/rp/tools/web.py b/rp/tools/web.py index da1c06c..fdb0620 100644 --- a/rp/tools/web.py +++ b/rp/tools/web.py @@ -4,6 +4,11 @@ import urllib.parse import urllib.request +import json +import urllib.parse +import urllib.request + + def http_fetch(url, headers=None): """Fetch content from an HTTP URL. @@ -15,25 +20,26 @@ def http_fetch(url, headers=None): Dict with status and content. """ try: - req = urllib.request.Request(url) + request = urllib.request.Request(url) if headers: - for key, value in headers.items(): - req.add_header(key, value) - with urllib.request.urlopen(req) as response: + for header_key, header_value in headers.items(): + request.add_header(header_key, header_value) + with urllib.request.urlopen(request) as response: content = response.read().decode("utf-8") return {"status": "success", "content": content[:10000]} - except Exception as e: - return {"status": "error", "error": str(e)} + except Exception as exception: + return {"status": "error", "error": str(exception)} def _perform_search(base_url, query, params=None): try: - full_url = f"https://static.molodetz.nl/search.cgi?query={query}" + encoded_query = urllib.parse.quote(query) + full_url = f"{base_url}?query={encoded_query}" with urllib.request.urlopen(full_url) as response: content = response.read().decode("utf-8") return {"status": "success", "content": json.loads(content)} - except Exception as e: - return {"status": "error", "error": str(e)} + except Exception as exception: + return {"status": "error", "error": str(exception)} def web_search(query): @@ -60,3 +66,4 @@ def web_search_news(query): """ base_url = "https://search.molodetz.nl/search" return _perform_search(base_url, query) +