@@ -101,7 +101,10 @@ impl DirectToolRuntime {
101101 }
102102
103103 pub ( super ) async fn call ( & self , name : & str , args : serde_json:: Value ) -> Result < ToolCallResult > {
104- let result = self . tool_executor . execute ( name, & args) . await ?;
104+ let result = self
105+ . tool_executor
106+ . execute_with_context ( name, & args, & self . tool_context )
107+ . await ?;
105108 Ok ( ToolCallResult {
106109 name : name. to_string ( ) ,
107110 output : result. output ,
@@ -123,6 +126,36 @@ fn parse_glob_output(output: &str) -> Vec<String> {
123126#[ cfg( test) ]
124127mod tests {
125128 use super :: * ;
129+ use crate :: tools:: { Tool , ToolOutput } ;
130+ use anyhow:: Result ;
131+ use async_trait:: async_trait;
132+
133+ struct ContextProbeTool ;
134+
135+ #[ async_trait]
136+ impl Tool for ContextProbeTool {
137+ fn name ( & self ) -> & str {
138+ "context_probe"
139+ }
140+
141+ fn description ( & self ) -> & str {
142+ "Reports direct tool context for tests."
143+ }
144+
145+ fn parameters ( & self ) -> serde_json:: Value {
146+ serde_json:: json!( { "type" : "object" } )
147+ }
148+
149+ async fn execute (
150+ & self ,
151+ _args : & serde_json:: Value ,
152+ ctx : & ToolContext ,
153+ ) -> Result < ToolOutput > {
154+ Ok ( ToolOutput :: success (
155+ ctx. session_id . as_deref ( ) . unwrap_or ( "missing-session" ) ,
156+ ) )
157+ }
158+ }
126159
127160 #[ test]
128161 fn parse_glob_output_ignores_empty_lines ( ) {
@@ -131,4 +164,22 @@ mod tests {
131164 vec![ "src/lib.rs" . to_string( ) , "src/main.rs" . to_string( ) ]
132165 ) ;
133166 }
167+
168+ #[ tokio:: test]
169+ async fn direct_tool_call_uses_session_tool_context ( ) {
170+ let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
171+ let tool_executor = Arc :: new ( ToolExecutor :: new ( dir. path ( ) . to_string_lossy ( ) . to_string ( ) ) ) ;
172+ tool_executor. register_dynamic_tool ( Arc :: new ( ContextProbeTool ) ) ;
173+ let runtime = DirectToolRuntime {
174+ tool_executor,
175+ tool_context : ToolContext :: new ( dir. path ( ) . to_path_buf ( ) ) . with_session_id ( "session-123" ) ,
176+ } ;
177+
178+ let output = runtime
179+ . call ( "context_probe" , serde_json:: json!( { } ) )
180+ . await
181+ . unwrap ( ) ;
182+
183+ assert_eq ! ( output. output, "session-123" ) ;
184+ }
134185}
0 commit comments