Skip to content

Commit 852c106

Browse files
committed
allow comments in config files
the following styles of comments are supported: - C style block comments /* ... */ - C style line comments // ... - Shell style line comments # ... Signed-off-by: Piotr Ginał <[email protected]>
1 parent 75aad93 commit 852c106

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shai-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ futures = "0.3"
1616
termimad = "0.34"
1717
tree-sitter = "0.25"
1818
tree-sitter-highlight = "0.25"
19+
json_comments = "0.2.2"
1920

2021
[target.'cfg(unix)'.dependencies]
2122
libc = "0.2"

shai-core/src/config/agent.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::collections::HashMap;
22
use std::path::PathBuf;
3+
use json_comments::StripComments;
34
use serde::{Serialize, Deserialize};
45
use shai_llm::ToolCallMethod;
56
use crate::tools::mcp::McpConfig;
@@ -121,8 +122,9 @@ impl AgentConfig {
121122
return Err(format!("Agent config '{}' does not exist", agent_name).into());
122123
}
123124

124-
let content = std::fs::read_to_string(config_path)?;
125-
let config: AgentConfig = serde_json::from_str(&content)?;
125+
let content_bytes = std::fs::read(config_path)?;
126+
let content_stripped = StripComments::new(&content_bytes[..]);
127+
let config: AgentConfig = serde_json::from_reader(content_stripped)?;
126128
Ok(config)
127129
}
128130

shai-core/src/config/config.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::fs;
33
#[cfg(unix)]
44
use std::os::unix::fs::PermissionsExt;
55
use reqwest::Url;
6+
use json_comments::StripComments;
67
use serde::{Serialize, Deserialize};
78
use shai_llm::{LlmClient, ToolCallMethod};
89
use crate::tools::mcp::McpConfig;
@@ -90,9 +91,10 @@ impl ShaiConfig {
9091
return Err("config file does not exist".into());
9192
}
9293

93-
let content = fs::read_to_string(config_path)?;
94-
let mut config: ShaiConfig = serde_json::from_str(&content)?;
95-
94+
let content_bytes = fs::read(config_path)?;
95+
let content_stripped = StripComments::new(&content_bytes[..]);
96+
let mut config: ShaiConfig = serde_json::from_reader(content_stripped)?;
97+
9698
// Validate selected_provider index
9799
if config.providers.is_empty() {
98100
config.selected_provider = 0;

0 commit comments

Comments
 (0)