From f86d509a054f21d2c9425d219a3a830cf2723a2a Mon Sep 17 00:00:00 2001 From: banteg <4562643+banteg@users.noreply.github.com> Date: Mon, 29 Dec 2025 02:57:35 +0400 Subject: [PATCH] refactor: simplify with_id formatting --- .../src/codex_telegram_bridge/exec_render.py | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/codex_telegram_bridge/src/codex_telegram_bridge/exec_render.py b/codex_telegram_bridge/src/codex_telegram_bridge/exec_render.py index 098f155..618e037 100644 --- a/codex_telegram_bridge/src/codex_telegram_bridge/exec_render.py +++ b/codex_telegram_bridge/src/codex_telegram_bridge/exec_render.py @@ -88,10 +88,9 @@ def extract_numeric_id(item_id: Optional[object], fallback: Optional[int] = None return fallback -def with_id(item_id: Optional[int], line: str) -> str: - if item_id is not None: - return f"[{item_id}] {line}" - return f"[?] {line}" +def with_id(item_id: Optional[int], *parts: str) -> str: + prefix = f"[{item_id}] " if item_id is not None else "[?] " + return prefix + "".join(parts) def format_item_action_line(etype: str, item_id: Optional[int], item: dict[str, Any]) -> str | None: @@ -99,19 +98,19 @@ def format_item_action_line(etype: str, item_id: Optional[int], item: dict[str, if itype == "command_execution": command = format_command(item["command"]) if etype == "item.started": - return with_id(item_id, f"{STATUS_RUNNING} running: {command}") + return with_id(item_id, STATUS_RUNNING, " running: ", command) if etype == "item.completed": exit_code = item["exit_code"] exit_part = f" (exit {exit_code})" if exit_code is not None else "" - return with_id(item_id, f"{STATUS_DONE} ran: {command}{exit_part}") + return with_id(item_id, STATUS_DONE, " ran: ", command, exit_part) return None if itype == "mcp_tool_call": name = format_tool_call(item["server"], item["tool"]) if etype == "item.started": - return with_id(item_id, f"{STATUS_RUNNING} tool: {name}") + return with_id(item_id, STATUS_RUNNING, " tool: ", name) if etype == "item.completed": - return with_id(item_id, f"{STATUS_DONE} tool: {name}") + return with_id(item_id, STATUS_DONE, " tool: ", name) return None return None @@ -121,12 +120,12 @@ def format_item_completed_line(item_id: Optional[int], item: dict[str, Any]) -> itype = item["type"] if itype == "web_search": query = format_query(item["query"]) - return with_id(item_id, f"{STATUS_DONE} searched: {query}") + return with_id(item_id, STATUS_DONE, " searched: ", query) if itype == "file_change": - return with_id(item_id, f"{STATUS_DONE} {format_file_change(item['changes'])}") + return with_id(item_id, STATUS_DONE, " ", format_file_change(item["changes"])) if itype == "error": warning = truncate(item["message"], 120) - return with_id(item_id, f"{STATUS_DONE} warning: {warning}") + return with_id(item_id, STATUS_DONE, " warning: ", warning) return None