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