- 1
use std::path::{Path, PathBuf}; - 2
use std::sync::Arc; - 3
- 4
use tokio_util::sync::CancellationToken; - 5
- 6
#[derive(Clone)] - 7
pub struct ToolContext { - 8
pub cwd: PathBuf, - 9
pub cancel: CancellationToken, - 10
pub sandbox: Option<Arc<dyn crate::sandbox::Sandbox>>, - 11
pub sandbox_sink: Option<crate::sandbox_events::SandboxEventSink>, - 12
pub agent_id: Option<String>, - 13
/// Workspace paths (with `/`) of Office files that are new to the - 14
/// workspace a task copy was made from, though the copy holds them: - 15
/// their Word edits are written clean (docs/design/72, R7). Set by the - 16
/// runtime, never by the model; empty outside a revision's copy. - 17
pub new_documents: Vec<String>, - 18
} - 19
- 20
impl ToolContext { - 21
pub fn new(cwd: PathBuf) -> Self { - 22
ToolContext { - 23
cwd, - 24
cancel: CancellationToken::new(), - 25
sandbox: None, - 26
sandbox_sink: None, - 27
agent_id: None, - 28
new_documents: Vec::new(), - 29
} - 30
} - 31
- 32
pub fn with_sandbox_sink(mut self, sink: crate::sandbox_events::SandboxEventSink) -> Self { - 33
self.sandbox_sink = Some(sink); - 34
self - 35
} - 36
- 37
pub fn with_agent_id(mut self, agent_id: impl Into<String>) -> Self { - 38
self.agent_id = Some(agent_id.into()); - 39
self - 40
} - 41
- 42
pub fn with_new_documents(mut self, paths: Vec<String>) -> Self { - 43
self.new_documents = paths; - 44
self - 45
} - 46
- 47
pub fn resolve(&self, p: &Path) -> PathBuf { - 48
if p.is_absolute() { - 49
p.to_path_buf() - 50
} else { - 51
self.cwd.join(p) - 52
} - 53
} - 54
} - 55
- 56
impl Default for ToolContext { - 57
fn default() -> Self { - 58
Self::new(PathBuf::new()) - 59
} - 60
} - 61
- 62
pub fn shared_ctx(dir: &Path) -> Arc<ToolContext> { - 63
Arc::new(ToolContext::new(dir.to_path_buf())) - 64
} - 65
Indexing the workspace…
Vakyartha documentation is discovering safe artifacts, anchors, and source references.