Skip to content

Use Claude Code, Codex, VSCode, Pi, and OpenCode (and 6 other harnesses) for free (1.3B+ free tokens) from your terminal, app, IDE, or phone, and now from the browser with native browser sessions (multi-harness + multi-model) like OpenClaw (voice supported + ToS friendly)

Python

Fixed truncation errors in telegram and added subagent display

Alishahryar14247f411b06f
diff --git a/messaging/handler.py b/messaging/handler.py
index e028266a..e636ef2d 100644
--- a/messaging/handler.py
+++ b/messaging/handler.py
@@ -10,6 +10,7 @@ import time
import asyncio
import logging
import re
+import os
from typing import List, Optional
from markdown_it import MarkdownIt
@@ -630,6 +631,7 @@ class ClaudeMessageHandler:
had_transcript_events = False
captured_session_id = None
temp_session_id = None
+ last_status: Optional[str] = None
# Get parent session ID for forking (if child node)
parent_session_id = None
@@ -639,7 +641,7 @@ class ClaudeMessageHandler:
logger.info(f"Will fork from parent session: {parent_session_id}")
async def update_ui(status: Optional[str] = None, force: bool = False) -> None:
- nonlocal last_ui_update, last_displayed_text
+ nonlocal last_ui_update, last_displayed_text, last_status
now = time.time()
# Small 1s debounce for UI sanity - we still want to avoid
@@ -648,8 +650,29 @@ class ClaudeMessageHandler:
return
last_ui_update = now
+ if status is not None:
+ last_status = status
display = transcript.render(render_ctx, limit_chars=3900, status=status)
if display and display != last_displayed_text:
+ # Debug logging: capture what we are sending to Telegram.
+ # Full text logging can be noisy and may include sensitive content, so gate it.
+ logger.debug(
+ "TELEGRAM_EDIT: node_id=%s chat_id=%s msg_id=%s force=%s status=%r chars=%d",
+ node_id,
+ chat_id,
+ status_msg_id,
+ bool(force),
+ status,
+ len(display),
+ )
+ if os.getenv("DEBUG_TELEGRAM_EDITS") == "1":
+ logger.debug("TELEGRAM_EDIT_TEXT:\n%s", display)
+ else:
+ head = display[:500]
+ tail = display[-500:] if len(display) > 500 else ""
+ logger.debug("TELEGRAM_EDIT_PREVIEW_HEAD:\n%s", head)
+ if tail:
+ logger.debug("TELEGRAM_EDIT_PREVIEW_TAIL:\n%s", tail)
last_displayed_text = display
await self.platform.queue_edit_message(
chat_id, status_msg_id, display, parse_mode="MarkdownV2"
@@ -753,6 +776,10 @@ class ClaudeMessageHandler:
await update_ui(format_status("⏳", "Executing tools..."))
elif ptype == "tool_result":
await update_ui(format_status("⏳", "Executing tools..."))
+ elif ptype == "block_stop":
+ # Force-flush at block boundaries so we don't get stuck showing
+ # the last partial line if deltas landed inside the debounce window.
+ await update_ui(last_status, force=True)
elif parsed["type"] == "complete":
# If nothing happened (rare), still show a completion marker.
diff --git a/messaging/transcript.py b/messaging/transcript.py
index 99c58403..4f70c690 100644
--- a/messaging/transcript.py
+++ b/messaging/transcript.py
@@ -71,11 +71,13 @@ class ToolCallSegment(Segment):
name: str
input_text: str = ""
closed: bool = False
+ indent_level: int = 0
- def __init__(self, tool_use_id: str, name: str) -> None:
+ def __init__(self, tool_use_id: str, name: str, *, indent_level: int = 0) -> None:
super().__init__(kind="tool_call")
self.tool_use_id = str(tool_use_id or "")
self.name = str(name or "tool")
+ self.indent_level = max(0, int(indent_level))
def set_initial_input(self, inp: Any) -> None:
if inp is None:
@@ -90,12 +92,10 @@ class ToolCallSegment(Segment):
self.input_text += partial
def render(self, ctx: "RenderCtx") -> str:
- raw = self.input_text or ""
- if ctx.tool_input_tail_max is not None and len(raw) > ctx.tool_input_tail_max:
- raw = "..." + raw[-(ctx.tool_input_tail_max - 3) :]
- inner = ctx.escape_code(raw)
name = ctx.code_inline(self.name)
- return f"🛠 {ctx.bold('Tool call:')} {name}\n```\n{inner}\n```"
+ # Per UX requirement: do not display tool args/results, only the tool call.
+ prefix = " " * self.indent_level
+ return f"{prefix}🛠 {ctx.bold('Tool call:')} {name}"
@dataclass
@@ -192,6 +192,9 @@ class TranscriptBuffer:
def _in_subagent(self) -> bool:
return bool(self._subagent_stack)
+ def _subagent_depth(self) -> int:
+ return len(self._subagent_stack)
+
def _ensure_thinking(self) -> ThinkingSegment:
seg = ThinkingSegment()
self._segments.append(seg)
@@ -263,7 +266,10 @@ class TranscriptBuffer:
idx = int(ev.get("index", -1))
tool_id = str(ev.get("id", "") or "")
name = str(ev.get("name", "") or "tool")
- seg = ToolCallSegment(tool_id, name)
+ indent = 0
+ if name != "Task" and self._in_subagent():
+ indent = self._subagent_depth()
+ seg = ToolCallSegment(tool_id, name, indent_level=indent)
seg.set_initial_input(ev.get("input"))
self._segments.append(seg)
if idx >= 0:
@@ -315,7 +321,10 @@ class TranscriptBuffer:
if et == "tool_use":
tool_id = str(ev.get("id", "") or "")
name = str(ev.get("name", "") or "tool")
- seg = ToolCallSegment(tool_id, name)
+ indent = 0
+ if name != "Task" and self._in_subagent():
+ indent = self._subagent_depth()
+ seg = ToolCallSegment(tool_id, name, indent_level=indent)
seg.set_initial_input(ev.get("input"))
seg.closed = True
self._segments.append(seg)
@@ -384,7 +393,7 @@ class TranscriptBuffer:
if len(candidate) <= limit_chars:
return candidate
- # Drop oldest segments until under limit.
+ # Drop oldest segments until under limit (keep the tail).
parts = list(rendered)
dropped = False
while parts:
diff --git a/tests/test_transcript.py b/tests/test_transcript.py
index c4c7e0ad..9af3bd10 100644
--- a/tests/test_transcript.py
+++ b/tests/test_transcript.py
@@ -64,6 +64,8 @@ def test_transcript_subagent_suppresses_thinking_and_text_inside():
assert "Subagent:" in out
assert "secret" not in out
assert "visible?" not in out
+ # Tool calls inside a subagent should be indented.
+ assert "\n 🛠" in out or out.startswith(" 🛠") or " 🛠" in out
assert "after" in out
@@ -80,5 +82,6 @@ def test_transcript_truncates_by_dropping_oldest_segments():
out = t.render(_ctx(), limit_chars=600, status="status")
assert escape_md_v2("... (truncated)") in out
+ # We keep the tail and drop the oldest segments when truncating.
assert escape_md_v2("segment_59") in out
assert escape_md_v2("segment_0") not in out