steer_tools/
context.rs

1use std::collections::HashMap;
2use tokio_util::sync::CancellationToken;
3
4/// Execution context passed to tools during execution
5#[derive(Debug, Clone)]
6pub struct ExecutionContext {
7    /// Unique identifier for this tool call
8    pub tool_call_id: String,
9
10    /// Cancellation token for early termination
11    pub cancellation_token: CancellationToken,
12
13    /// Current working directory
14    pub working_directory: std::path::PathBuf,
15
16    /// Environment variables available to the tool
17    pub environment: HashMap<String, String>,
18
19    /// Execution metadata
20    pub metadata: HashMap<String, String>,
21}
22
23impl ExecutionContext {
24    pub fn new(tool_call_id: String) -> Self {
25        Self {
26            tool_call_id,
27            cancellation_token: CancellationToken::new(),
28            working_directory: std::env::current_dir().unwrap_or_else(|_| "/".into()),
29            environment: std::env::vars().collect(),
30            metadata: HashMap::new(),
31        }
32    }
33
34    pub fn with_cancellation_token(mut self, token: CancellationToken) -> Self {
35        self.cancellation_token = token;
36        self
37    }
38
39    pub fn with_working_directory(mut self, dir: std::path::PathBuf) -> Self {
40        self.working_directory = dir;
41        self
42    }
43
44    pub fn is_cancelled(&self) -> bool {
45        self.cancellation_token.is_cancelled()
46    }
47}