@@ -2836,14 +2836,25 @@ async def handle_pending_permission_request(self, params: SessionPermissionsHand
28362836
28372837
28382838class ShellApi :
2839- def __init__ (self , client : "JsonRpcClient" , session_id : str ):
2839+ def __init__ (
2840+ self ,
2841+ client : "JsonRpcClient" ,
2842+ session_id : str ,
2843+ on_exec : Callable [[str ], None ] | None = None ,
2844+ ):
28402845 self ._client = client
28412846 self ._session_id = session_id
2847+ self ._on_exec = on_exec
28422848
28432849 async def exec (self , params : SessionShellExecParams , * , timeout : float | None = None ) -> SessionShellExecResult :
28442850 params_dict = {k : v for k , v in params .to_dict ().items () if v is not None }
28452851 params_dict ["sessionId" ] = self ._session_id
2846- return SessionShellExecResult .from_dict (await self ._client .request ("session.shell.exec" , params_dict , ** _timeout_kwargs (timeout )))
2852+ result = SessionShellExecResult .from_dict (
2853+ await self ._client .request ("session.shell.exec" , params_dict , ** _timeout_kwargs (timeout ))
2854+ )
2855+ if self ._on_exec is not None :
2856+ self ._on_exec (result .process_id )
2857+ return result
28472858
28482859 async def kill (self , params : SessionShellKillParams , * , timeout : float | None = None ) -> SessionShellKillResult :
28492860 params_dict = {k : v for k , v in params .to_dict ().items () if v is not None }
@@ -2853,7 +2864,12 @@ async def kill(self, params: SessionShellKillParams, *, timeout: float | None =
28532864
28542865class SessionRpc :
28552866 """Typed session-scoped RPC methods."""
2856- def __init__ (self , client : "JsonRpcClient" , session_id : str ):
2867+ def __init__ (
2868+ self ,
2869+ client : "JsonRpcClient" ,
2870+ session_id : str ,
2871+ on_shell_exec : Callable [[str ], None ] | None = None ,
2872+ ):
28572873 self ._client = client
28582874 self ._session_id = session_id
28592875 self .model = ModelApi (client , session_id )
@@ -2871,10 +2887,9 @@ def __init__(self, client: "JsonRpcClient", session_id: str):
28712887 self .commands = CommandsApi (client , session_id )
28722888 self .ui = UiApi (client , session_id )
28732889 self .permissions = PermissionsApi (client , session_id )
2874- self .shell = ShellApi (client , session_id )
2890+ self .shell = ShellApi (client , session_id , on_shell_exec )
28752891
28762892 async def log (self , params : SessionLogParams , * , timeout : float | None = None ) -> SessionLogResult :
28772893 params_dict = {k : v for k , v in params .to_dict ().items () if v is not None }
28782894 params_dict ["sessionId" ] = self ._session_id
28792895 return SessionLogResult .from_dict (await self ._client .request ("session.log" , params_dict , ** _timeout_kwargs (timeout )))
2880-
0 commit comments