Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix: reserve space for ellipsis in truncation to stay within byte limit

cyhhaoa2c2cce61d04
diff --git a/core/controller.py b/core/controller.py
index 22eda24bd..e950295b2 100644
--- a/core/controller.py
+++ b/core/controller.py
@@ -261,16 +261,14 @@ class Controller:
"""Truncate text to fit within max_bytes (UTF-8 encoded)."""
if self._get_text_byte_length(text) <= max_bytes:
return text
- # Binary search for the right character position
- encoded = text.encode("utf-8")
- if len(encoded) <= max_bytes:
- return text
+ # Reserve space for ellipsis (3 bytes for "…")
+ ellipsis = "…"
+ ellipsis_bytes = len(ellipsis.encode("utf-8")) # 3 bytes
+ target_bytes = max_bytes - ellipsis_bytes
# Truncate bytes and decode, handling partial characters
- truncated = encoded[:max_bytes].decode("utf-8", errors="ignore")
- return truncated.rstrip() + "…"
- prefix = "…(truncated)…\n\n"
- keep = max(0, max_chars - len(prefix))
- return f"{prefix}{text[-keep:]}"
+ encoded = text.encode("utf-8")
+ truncated = encoded[:target_bytes].decode("utf-8", errors="ignore")
+ return truncated.rstrip() + ellipsis
def resolve_agent_for_context(self, context: MessageContext) -> str:
"""Unified agent resolution with dynamic override support.