From eb8f283e44844e88a77f4abb3a1777b9d0ca603f Mon Sep 17 00:00:00 2001 From: Andre K Date: Sun, 19 Apr 2026 08:57:58 +0800 Subject: [PATCH] fix: update README for deployment instructions and improve code formatting --- README.md | 7 ++++++- main.py | 27 ++++++++++++++++++--------- tools/site_editing/__init__.py | 8 ++++---- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 550bd73..fb3f5f1 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,12 @@ betterbot-specific files are: | `compose/` | Docker compose for RackNerd with site-dir mounts | | `scripts/deploy-betterbot.sh` | Deploy script targeting RackNerd + Infisical | -To sync upstream changes, copy updated framework files from `code_anywhere/`. +Deploys on RackNerd pull from the BetterBot Forgejo repo only. They do not +pull directly from CodeAnywhere during deploy. + +If CodeAnywhere framework files change, sync those changes into this repo +first, commit them here, and then deploy BetterBot from its own `master` +branch. ## Deployment diff --git a/main.py b/main.py index d8ef5a3..575d3df 100644 --- a/main.py +++ b/main.py @@ -35,9 +35,12 @@ def _get_advisor_usage(thread_id: str | None) -> dict | None: return None try: from tools.advisor import get_advisor_usage + return get_advisor_usage(thread_id) except ImportError: return None + + from local_media_store import LocalMediaStore from model_selection import ( ModelSelection, @@ -912,7 +915,9 @@ async def send_thread_message(thread_id: str, request: Request): getattr(getattr(result, "data", None), "content", None) or getattr(result, "content", None) or "" ) usage = extract_usage_and_cost( - selection.model, selection.provider, result, + selection.model, + selection.provider, + result, advisor_usage=_get_advisor_usage(thread_id), ) web_store.add_usage(thread_id, usage) @@ -1071,15 +1076,19 @@ async def stream_thread_message(thread_id: str, request: Request): # Emit advisor trace events if any try: from tools.advisor import get_advisor_traces + for trace in get_advisor_traces(thread_id): - yield _sse_event("progress", { - "kind": "advisor_trace", - "question": trace.get("question", ""), - "answer": trace.get("answer", ""), - "stakes": trace.get("stakes", "medium"), - "model": trace.get("model", ""), - "duration_ms": trace.get("duration_ms", 0), - }) + yield _sse_event( + "progress", + { + "kind": "advisor_trace", + "question": trace.get("question", ""), + "answer": trace.get("answer", ""), + "stakes": trace.get("stakes", "medium"), + "model": trace.get("model", ""), + "duration_ms": trace.get("duration_ms", 0), + }, + ) except ImportError: pass diff --git a/tools/site_editing/__init__.py b/tools/site_editing/__init__.py index f6e6fd7..7ae6675 100644 --- a/tools/site_editing/__init__.py +++ b/tools/site_editing/__init__.py @@ -23,7 +23,9 @@ logger = logging.getLogger(__name__) def _build_projects() -> dict[str, dict[str, Any]]: """Build the project map from environment-configured directories.""" site_dir = pathlib.Path(settings.SITE_DIR) if hasattr(settings, "SITE_DIR") else pathlib.Path("/site") - memoraiz_dir = pathlib.Path(settings.MEMORAIZ_DIR) if hasattr(settings, "MEMORAIZ_DIR") else pathlib.Path("/memoraiz") + memoraiz_dir = ( + pathlib.Path(settings.MEMORAIZ_DIR) if hasattr(settings, "MEMORAIZ_DIR") else pathlib.Path("/memoraiz") + ) projects: dict[str, dict[str, Any]] = {} if site_dir.exists(): @@ -102,9 +104,7 @@ def handle_tool_call(name: str, args: dict) -> str: target = _resolve(base, subdir) if subdir else base files = [] for p in sorted(target.rglob("*")): - if p.is_file() and not any( - part in (".git", "node_modules", "__pycache__") for part in p.parts - ): + if p.is_file() and not any(part in (".git", "node_modules", "__pycache__") for part in p.parts): files.append(str(p.relative_to(base))) return "\n".join(files[:200]) if files else "(no files found)"