claude_rust_tools/infrastructure/
config_tool.rs1use claude_rust_errors::AppResult;
2use claude_rust_types::{PermissionLevel, Tool};
3use serde_json::{Value, json};
4
5pub struct ConfigTool;
9
10impl ConfigTool {
11 pub fn new() -> Self {
12 Self
13 }
14}
15
16#[async_trait::async_trait]
17impl Tool for ConfigTool {
18 fn name(&self) -> &str {
19 "config"
20 }
21
22 fn description(&self) -> &str {
23 "Get, set, or list configuration values."
24 }
25
26 fn input_schema(&self) -> Value {
27 json!({
28 "type": "object",
29 "properties": {
30 "operation": {
31 "type": "string",
32 "description": "Config operation: \"get\", \"set\", or \"list\"",
33 "enum": ["get", "set", "list"]
34 },
35 "key": {
36 "type": "string",
37 "description": "Configuration key (required for get/set)"
38 },
39 "value": {
40 "type": "string",
41 "description": "Configuration value (required for set)"
42 }
43 },
44 "required": ["operation"]
45 })
46 }
47
48 fn permission_level(&self) -> PermissionLevel {
49 PermissionLevel::Dangerous
50 }
51
52 async fn execute(&self, input: Value) -> AppResult<String> {
53 let operation = input
54 .get("operation")
55 .and_then(|v| v.as_str())
56 .ok_or_else(|| claude_rust_errors::AppError::Tool("missing 'operation' field".into()))?;
57
58 let key = input.get("key").and_then(|v| v.as_str());
59 let value = input.get("value").and_then(|v| v.as_str());
60
61 tracing::info!(operation, key, value, "config operation (stub)");
63
64 match operation {
65 "get" => {
66 let key = key.ok_or_else(|| {
67 claude_rust_errors::AppError::Tool("'key' is required for get".into())
68 })?;
69 Ok(format!("Config '{key}': (not set — stub)"))
70 }
71 "set" => {
72 let key = key.ok_or_else(|| {
73 claude_rust_errors::AppError::Tool("'key' is required for set".into())
74 })?;
75 let value = value.ok_or_else(|| {
76 claude_rust_errors::AppError::Tool("'value' is required for set".into())
77 })?;
78 Ok(format!("Config '{key}' set to '{value}'. (stub)"))
79 }
80 "list" => Ok("Configuration (stub):\n (no entries)".to_string()),
81 other => Err(claude_rust_errors::AppError::Tool(
82 format!("unknown config operation: {other}")
83 )),
84 }
85 }
86}