From b0d18f19b7ff648833003f99579db32b64752c1c Mon Sep 17 00:00:00 2001 From: Cameron Pfiffer Date: Tue, 8 Jul 2025 22:47:48 -0700 Subject: [PATCH] Add --no-git command line argument to skip git operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds --no-git flag to bsky.py that skips git operations when exporting agent state. This prevents the automatic git staging of agent backups when the bot needs to export state (e.g., during halt operations). Usage: python bsky.py --no-git ๐Ÿค– Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- CLAUDE.md | 6 ++++++ bsky.py | 44 ++++++++++++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 6bae0cb..a6931d3 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -13,6 +13,12 @@ Void is an autonomous AI agent that operates on the Bluesky social network, expl ac && python bsky.py # OR source .venv/bin/activate && python bsky.py + +# Run with testing mode (no messages sent, queue preserved) +ac && python bsky.py --test + +# Run without git operations for agent backups +ac && python bsky.py --no-git ``` ### Managing Tools diff --git a/bsky.py b/bsky.py index c9feb9a..48d2cc5 100644 --- a/bsky.py +++ b/bsky.py @@ -87,14 +87,20 @@ start_time = time.time() # Testing mode flag TESTING_MODE = False -def export_agent_state(client, agent): +# Skip git operations flag +SKIP_GIT = False + +def export_agent_state(client, agent, skip_git=False): """Export agent state to agent_archive/ (timestamped) and agents/ (current).""" try: - # Confirm export with user - response = input("Export agent state to files and stage with git? (y/n): ").lower().strip() - if response not in ['y', 'yes']: - logger.info("Agent export cancelled by user.") - return + # Confirm export with user unless git is being skipped + if not skip_git: + response = input("Export agent state to files and stage with git? (y/n): ").lower().strip() + if response not in ['y', 'yes']: + logger.info("Agent export cancelled by user.") + return + else: + logger.info("Exporting agent state (git staging disabled)") # Create directories if they don't exist os.makedirs("agent_archive", exist_ok=True) @@ -117,12 +123,13 @@ def export_agent_state(client, agent): logger.info(f"โœ… Agent exported to {archive_file} and {current_file}") - # Git add only the current agent file (archive is ignored) - try: - subprocess.run(["git", "add", current_file], check=True, capture_output=True) - logger.info("Added current agent file to git staging") - except subprocess.CalledProcessError as e: - logger.warning(f"Failed to git add agent file: {e}") + # Git add only the current agent file (archive is ignored) unless skip_git is True + if not skip_git: + try: + subprocess.run(["git", "add", current_file], check=True, capture_output=True) + logger.info("Added current agent file to git staging") + except subprocess.CalledProcessError as e: + logger.warning(f"Failed to git add agent file: {e}") except Exception as e: logger.error(f"Failed to export agent: {e}") @@ -176,7 +183,7 @@ def initialize_void(): # Export agent state logger.info("Exporting agent state...") - export_agent_state(CLIENT, void_agent) + export_agent_state(CLIENT, void_agent, skip_git=SKIP_GIT) # Log agent details logger.info(f"Void agent details - ID: {void_agent.id}") @@ -517,7 +524,7 @@ To reply, use the add_post_to_bluesky_reply_thread tool. Call it multiple times logger.error("Please use add_post_to_bluesky_reply_thread instead.") logger.error("Update the agent's tools using register_tools.py") # Export agent state before terminating - export_agent_state(CLIENT, void_agent) + export_agent_state(CLIENT, void_agent, skip_git=SKIP_GIT) logger.info("=== BOT TERMINATED DUE TO DEPRECATED TOOL USE ===") exit(1) @@ -562,7 +569,7 @@ To reply, use the add_post_to_bluesky_reply_thread tool. Call it multiple times save_processed_notifications(processed_uris) # Export agent state before terminating - export_agent_state(CLIENT, void_agent) + export_agent_state(CLIENT, void_agent, skip_git=SKIP_GIT) # Exit the program logger.info("=== BOT TERMINATED BY AGENT ===") @@ -575,7 +582,7 @@ To reply, use the add_post_to_bluesky_reply_thread tool. Call it multiple times logger.error("Please use add_post_to_bluesky_reply_thread instead.") logger.error("Update the agent's tools using register_tools.py") # Export agent state before terminating - export_agent_state(CLIENT, void_agent) + export_agent_state(CLIENT, void_agent, skip_git=SKIP_GIT) logger.info("=== BOT TERMINATED DUE TO DEPRECATED TOOL USE ===") exit(1) @@ -991,11 +998,16 @@ def main(): # Parse command line arguments parser = argparse.ArgumentParser(description='Void Bot - Bluesky autonomous agent') parser.add_argument('--test', action='store_true', help='Run in testing mode (no messages sent, queue files preserved)') + parser.add_argument('--no-git', action='store_true', help='Skip git operations when exporting agent state') args = parser.parse_args() global TESTING_MODE TESTING_MODE = args.test + # Store no-git flag globally for use in export_agent_state calls + global SKIP_GIT + SKIP_GIT = args.no_git + if TESTING_MODE: logger.info("๐Ÿงช === RUNNING IN TESTING MODE ===") logger.info(" - No messages will be sent to Bluesky") -- 2.51.2