Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,22 @@ import time
|
|
| 9 |
import zipfile
|
| 10 |
import shutil
|
| 11 |
import traceback
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
"""
|
| 14 |
Clawdbot Unified Command Center
|
|
@@ -25,7 +41,7 @@ FIXED: Increased Loop Stamina to 15 (Prevents silence).
|
|
| 25 |
AVAILABLE_TOOLS = {
|
| 26 |
"list_files", "read_file", "search_code", "write_file",
|
| 27 |
"create_shadow_branch", "shell_execute", "get_stats",
|
| 28 |
-
"search_conversations", "search_testament"
|
| 29 |
}
|
| 30 |
|
| 31 |
TEXT_EXTENSIONS = {
|
|
@@ -94,6 +110,12 @@ def build_system_prompt() -> str:
|
|
| 94 |
System Stats: {stats.get('total_files', 0)} files, {stats.get('conversations', 0)} memories.
|
| 95 |
{tools_doc}
|
| 96 |
Output Format: Use [TOOL: tool_name(arg="value")] for tools.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
"""
|
| 98 |
|
| 99 |
def parse_tool_calls(text: str) -> list:
|
|
@@ -167,11 +189,17 @@ def execute_tool(tool_name: str, args: dict) -> dict:
|
|
| 167 |
# BYPASS GATE: Execute immediately
|
| 168 |
result = ctx.write_file(args.get('path', ''), args.get('content', ''))
|
| 169 |
return {"status": "executed", "tool": tool_name, "result": result}
|
|
|
|
|
|
|
|
|
|
| 170 |
elif tool_name == 'shell_execute':
|
| 171 |
# BYPASS GATE: Execute immediately
|
| 172 |
result = ctx.shell_execute(args.get('command', ''))
|
| 173 |
return {"status": "executed", "tool": tool_name, "result": result}
|
| 174 |
-
|
|
|
|
|
|
|
|
|
|
| 175 |
elif tool_name == 'create_shadow_branch':
|
| 176 |
return {"status": "staged", "tool": tool_name, "args": args, "description": "🛡️ Create shadow branch"}
|
| 177 |
return {"status": "error", "result": f"Unknown tool: {tool_name}"}
|
|
|
|
| 9 |
import zipfile
|
| 10 |
import shutil
|
| 11 |
import traceback
|
| 12 |
+
import logging
|
| 13 |
+
|
| 14 |
+
# Configure Logging to file AND console
|
| 15 |
+
logging.basicConfig(
|
| 16 |
+
level=logging.INFO,
|
| 17 |
+
format='%(asctime)s - %(levelname)s - %(message)s',
|
| 18 |
+
handlers=[
|
| 19 |
+
logging.FileHandler("clawdbot_system.log"),
|
| 20 |
+
logging.StreamHandler()
|
| 21 |
+
]
|
| 22 |
+
)
|
| 23 |
+
logger = logging.getLogger("Clawdbot")
|
| 24 |
+
|
| 25 |
+
def log_action(action: str, details: str):
|
| 26 |
+
"""Records critical system events."""
|
| 27 |
+
logger.info(f"ACTION: {action} | DETAILS: {details}")
|
| 28 |
|
| 29 |
"""
|
| 30 |
Clawdbot Unified Command Center
|
|
|
|
| 41 |
AVAILABLE_TOOLS = {
|
| 42 |
"list_files", "read_file", "search_code", "write_file",
|
| 43 |
"create_shadow_branch", "shell_execute", "get_stats",
|
| 44 |
+
"search_conversations", "search_testament", "push_to_github"
|
| 45 |
}
|
| 46 |
|
| 47 |
TEXT_EXTENSIONS = {
|
|
|
|
| 110 |
System Stats: {stats.get('total_files', 0)} files, {stats.get('conversations', 0)} memories.
|
| 111 |
{tools_doc}
|
| 112 |
Output Format: Use [TOOL: tool_name(arg="value")] for tools.
|
| 113 |
+
|
| 114 |
+
## CRITICAL PROTOCOLS:
|
| 115 |
+
1. **RECURSIVE MEMORY FIRST**: If the user asks about past context (e.g., "the new UI"), you MUST use `search_conversations` BEFORE you answer. Do not ask the user for context you already have.
|
| 116 |
+
2. **THINK OUT LOUD**: When writing code, output the full code block in the chat BEFORE calling `write_file`. This ensures a backup exists in memory if the write fails.
|
| 117 |
+
3. **CHECK BEFORE WRITE**: Before writing code, use `read_file` or `list_files` to ensure you aren't overwriting good code with bad.
|
| 118 |
+
4. **NO SILENCE**: If you perform an action, report the result.
|
| 119 |
"""
|
| 120 |
|
| 121 |
def parse_tool_calls(text: str) -> list:
|
|
|
|
| 189 |
# BYPASS GATE: Execute immediately
|
| 190 |
result = ctx.write_file(args.get('path', ''), args.get('content', ''))
|
| 191 |
return {"status": "executed", "tool": tool_name, "result": result}
|
| 192 |
+
elif tool_name == 'write_file':
|
| 193 |
+
log_action("WRITE_ATTEMPT", f"Writing to {args.get('path')}")
|
| 194 |
+
# ... existing write logic ...
|
| 195 |
elif tool_name == 'shell_execute':
|
| 196 |
# BYPASS GATE: Execute immediately
|
| 197 |
result = ctx.shell_execute(args.get('command', ''))
|
| 198 |
return {"status": "executed", "tool": tool_name, "result": result}
|
| 199 |
+
elif tool_name == 'push_to_github':
|
| 200 |
+
# BYPASS GATE: Immediate backup is always safe
|
| 201 |
+
result = ctx.push_to_github(args.get('message', 'Manual Backup'))
|
| 202 |
+
return {"status": "executed", "tool": tool_name, "result": result}
|
| 203 |
elif tool_name == 'create_shadow_branch':
|
| 204 |
return {"status": "staged", "tool": tool_name, "args": args, "description": "🛡️ Create shadow branch"}
|
| 205 |
return {"status": "error", "result": f"Unknown tool: {tool_name}"}
|