claude_rust_tools/infrastructure/
task_output_tool.rs1use std::sync::Arc;
2
3use claude_rust_errors::{AppError, AppResult};
4use claude_rust_types::{PermissionLevel, Tool};
5use serde_json::{Value, json};
6
7use super::task_manager::TaskManager;
8
9pub struct TaskOutputTool {
10 manager: Arc<dyn TaskManager>,
11}
12
13impl TaskOutputTool {
14 pub fn new(manager: Arc<dyn TaskManager>) -> Self {
15 Self { manager }
16 }
17}
18
19#[async_trait::async_trait]
20impl Tool for TaskOutputTool {
21 fn name(&self) -> &str {
22 "task_output"
23 }
24
25 fn description(&self) -> &str {
26 "Get the output produced by a task. Returns the captured stdout/stderr from the task's subprocess."
27 }
28
29 fn input_schema(&self) -> Value {
30 json!({
31 "type": "object",
32 "properties": {
33 "task_id": {
34 "type": "string",
35 "description": "The ID of the task whose output to retrieve"
36 }
37 },
38 "required": ["task_id"]
39 })
40 }
41
42 fn permission_level(&self) -> PermissionLevel {
43 PermissionLevel::ReadOnly
44 }
45
46 fn is_read_only(&self, _input: &Value) -> bool { true }
47 fn is_concurrent_safe(&self, _input: &Value) -> bool { true }
48
49 async fn execute(&self, input: Value) -> AppResult<String> {
50 let task_id = input
51 .get("task_id")
52 .and_then(|v| v.as_str())
53 .ok_or_else(|| AppError::Tool("missing 'task_id' field".into()))?;
54
55 let output = self.manager.output(task_id).await?;
56
57 if output.is_empty() {
58 Ok("No output available.".into())
59 } else {
60 Ok(output)
61 }
62 }
63}