33import asyncio
44import contextlib
55import io
6- import json
76import os
87import sys
98from pathlib import Path
@@ -720,7 +719,7 @@ def _to_current_session_update(params: dict[str, Any]) -> dict[str, Any]:
720719 if update ["kind" ] == "step" and isinstance (raw_input , dict ):
721720 update ["content" ] = raw_input
722721 else :
723- update ["content" ] = AcpStdioServer ._current_tool_content ( raw_input )
722+ update ["content" ] = AcpStdioServer ._current_tool_input_content ( update [ "kind" ], raw_input )
724723 return converted
725724
726725 if update_type == "tool_call_update" :
@@ -732,28 +731,62 @@ def _to_current_session_update(params: dict[str, Any]) -> dict[str, Any]:
732731 if update ["kind" ] == "step" and isinstance (raw_output , dict ):
733732 update ["content" ] = raw_output
734733 else :
735- update ["content" ] = AcpStdioServer ._current_tool_content (raw_output )
734+ update ["content" ] = AcpStdioServer ._current_tool_output_content (raw_output )
736735 return converted
737736
738737 return converted
739738
740739 @staticmethod
741740 def _current_tool_kind (kind : Any ) -> str :
742- if kind in {"read" , "edit" , "delete" , "move" , "search" , "execute" , "think" , "fetch" , "switch_mode" , "other" , "step" }:
743- return str (kind )
744- if kind in {"shell" , "terminal" , "bash" , "command" }:
741+ normalized = str (kind or "" ).strip ()
742+ lowered = normalized .lower ()
743+ if normalized in {"Agent" , "Task" , "AskUserQuestion" }:
744+ return normalized
745+ if lowered in {"read" , "edit" , "delete" , "move" , "search" , "execute" , "think" , "fetch" , "switch_mode" , "step" }:
746+ return lowered
747+ if lowered in {"shell" , "terminal" , "bash" , "command" }:
745748 return "execute"
749+ if "spawn_subagent" in lowered or "subagent" in lowered :
750+ return "Agent"
751+ if "ask_user" in lowered or "question" in lowered :
752+ return "AskUserQuestion"
753+ if lowered .startswith ("task" ) or lowered .endswith ("_task" ):
754+ return "Task"
755+ if lowered :
756+ return "think"
746757 return "other"
747758
748759 @staticmethod
749- def _current_tool_content (value : Any ) -> list [dict [str , Any ]] | None :
750- if value is None :
751- return None
760+ def _current_tool_input_content (kind : str , value : Any ) -> Any :
761+ if kind == "execute" and isinstance (value , dict ):
762+ command_title = AcpStdioServer ._command_title (value .get ("command" ))
763+ if command_title :
764+ content = dict (value )
765+ tool_call = content .get ("toolCall" )
766+ if not isinstance (tool_call , dict ):
767+ tool_call = {}
768+ else :
769+ tool_call = dict (tool_call )
770+ tool_call .setdefault ("title" , command_title )
771+ content ["toolCall" ] = tool_call
772+ return content
752773 if isinstance (value , str ):
753- text = value
754- else :
755- text = json .dumps (value , ensure_ascii = False , sort_keys = True )
756- return [{"type" : "content" , "content" : {"type" : "text" , "text" : text }}]
774+ return {"text" : value }
775+ return value
776+
777+ @staticmethod
778+ def _current_tool_output_content (value : Any ) -> Any :
779+ return value
780+
781+ @staticmethod
782+ def _command_title (command : Any ) -> str | None :
783+ if isinstance (command , str ):
784+ stripped = command .strip ()
785+ return stripped or None
786+ if isinstance (command , list ):
787+ parts = [str (part ).strip () for part in command if str (part ).strip ()]
788+ return " " .join (parts ) or None
789+ return None
757790
758791 async def _ensure_cron_runtime_started (self ) -> None :
759792 if self ._cron_runtime_started :
0 commit comments