diff --git a/Cargo.lock b/Cargo.lock index 0522924..71ba50b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1689,6 +1689,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "json_comments" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dbbfed4e59ba9750e15ba154fdfd9329cee16ff3df539c2666b70f58cc32105" + [[package]] name = "jwalk" version = "0.8.1" @@ -3173,6 +3179,7 @@ dependencies = [ "dirs", "fs", "futures 0.3.31", + "json_comments", "libc", "oauth2 4.4.2", "openai_dive", diff --git a/shai-core/Cargo.toml b/shai-core/Cargo.toml index 5cbd3ab..54995da 100644 --- a/shai-core/Cargo.toml +++ b/shai-core/Cargo.toml @@ -16,6 +16,7 @@ futures = "0.3" termimad = "0.34" tree-sitter = "0.25" tree-sitter-highlight = "0.25" +json_comments = "0.2.2" [target.'cfg(unix)'.dependencies] libc = "0.2" diff --git a/shai-core/src/config/agent.rs b/shai-core/src/config/agent.rs index e3af23a..ffe4826 100644 --- a/shai-core/src/config/agent.rs +++ b/shai-core/src/config/agent.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; use std::path::PathBuf; +use json_comments::StripComments; use serde::{Serialize, Deserialize}; use shai_llm::ToolCallMethod; use crate::tools::mcp::McpConfig; @@ -121,8 +122,9 @@ impl AgentConfig { return Err(format!("Agent config '{}' does not exist", agent_name).into()); } - let content = std::fs::read_to_string(config_path)?; - let config: AgentConfig = serde_json::from_str(&content)?; + let content_bytes = std::fs::read(config_path)?; + let content_stripped = StripComments::new(&content_bytes[..]); + let config: AgentConfig = serde_json::from_reader(content_stripped)?; Ok(config) } diff --git a/shai-core/src/config/config.rs b/shai-core/src/config/config.rs index c2993b4..7b80082 100644 --- a/shai-core/src/config/config.rs +++ b/shai-core/src/config/config.rs @@ -3,6 +3,7 @@ use std::fs; #[cfg(unix)] use std::os::unix::fs::PermissionsExt; use reqwest::Url; +use json_comments::StripComments; use serde::{Serialize, Deserialize}; use shai_llm::{LlmClient, ToolCallMethod}; use crate::tools::mcp::McpConfig; @@ -90,9 +91,10 @@ impl ShaiConfig { return Err("config file does not exist".into()); } - let content = fs::read_to_string(config_path)?; - let mut config: ShaiConfig = serde_json::from_str(&content)?; - + let content_bytes = fs::read(config_path)?; + let content_stripped = StripComments::new(&content_bytes[..]); + let mut config: ShaiConfig = serde_json::from_reader(content_stripped)?; + // Validate selected_provider index if config.providers.is_empty() { config.selected_provider = 0;