feat(workspace): initialize Rust workspace structure for v2
Set up Cargo workspace with initial crates: - cli: main application entry point with chat streaming tests - config: configuration management - llm/ollama: Ollama client integration with NDJSON support Includes .gitignore for Rust and JetBrains IDEs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
55
crates/config/src/lib.rs
Normal file
55
crates/config/src/lib.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
use directories::ProjectDirs;
|
||||
use figment::{
|
||||
Figment,
|
||||
providers::{Env, Format, Serialized, Toml},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Settings {
|
||||
#[serde(default = "default_ollama_url")]
|
||||
pub ollama_url: String,
|
||||
#[serde(default = "default_model")]
|
||||
pub model: String,
|
||||
#[serde(default = "default_mode")]
|
||||
pub mode: String, // "plan" (read-only) for now
|
||||
}
|
||||
|
||||
fn default_ollama_url() -> String {
|
||||
"http://localhost:11434".into()
|
||||
}
|
||||
fn default_model() -> String {
|
||||
"qwen2.5".into()
|
||||
}
|
||||
fn default_mode() -> String {
|
||||
"plan".into()
|
||||
}
|
||||
|
||||
impl Default for Settings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
ollama_url: default_ollama_url(),
|
||||
model: default_model(),
|
||||
mode: default_mode(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_settings(project_root: Option<&str>) -> Result<Settings, figment::Error> {
|
||||
let mut fig = Figment::from(Serialized::defaults(Settings::default()))
|
||||
.merge(Env::prefixed("CODE_").split("__"));
|
||||
|
||||
// User file: ~/.config/owlen/config.toml
|
||||
if let Some(pd) = ProjectDirs::from("dev", "owlibou", "owlen") {
|
||||
let user = pd.config_dir().join("config.toml");
|
||||
fig = fig.merge(Toml::file(user));
|
||||
}
|
||||
|
||||
// Project file: <root>/.owlen.toml
|
||||
if let Some(root) = project_root {
|
||||
fig = fig.merge(Toml::file(PathBuf::from(root).join(".owlen.toml")));
|
||||
}
|
||||
|
||||
fig.extract()
|
||||
}
|
||||
Reference in New Issue
Block a user