chore(git): ignore custom documentation files
Add AGENTS.md and CLAUDE.md to .gitignore to exclude project-specific documentation files. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
22
crates/platform/config/.gitignore
vendored
Normal file
22
crates/platform/config/.gitignore
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
/target
|
||||
### Rust template
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
debug/
|
||||
target/
|
||||
|
||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||
Cargo.lock
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||
*.pdb
|
||||
|
||||
### rust-analyzer template
|
||||
# Can be generated by other build systems other than cargo (ex: bazelbuild/rust_rules)
|
||||
rust-project.json
|
||||
|
||||
|
||||
12
crates/platform/config/Cargo.toml
Normal file
12
crates/platform/config/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "config-agent"
|
||||
version = "0.1.0"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
rust-version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
directories = "5"
|
||||
figment = { version = "0.10", features = ["toml", "env"] }
|
||||
tempfile = "3.23.0"
|
||||
62
crates/platform/config/src/lib.rs
Normal file
62
crates/platform/config/src/lib.rs
Normal file
@@ -0,0 +1,62 @@
|
||||
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
|
||||
#[serde(default)]
|
||||
pub api_key: Option<String>, // For Ollama Cloud or other API authentication
|
||||
}
|
||||
|
||||
fn default_ollama_url() -> String {
|
||||
"http://localhost:11434".into()
|
||||
}
|
||||
fn default_model() -> String {
|
||||
"qwen3:8b".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(),
|
||||
api_key: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_settings(project_root: Option<&str>) -> Result<Settings, figment::Error> {
|
||||
let mut fig = Figment::from(Serialized::defaults(Settings::default()));
|
||||
|
||||
// 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")));
|
||||
}
|
||||
|
||||
// Environment variables have highest precedence
|
||||
fig = fig.merge(Env::prefixed("OWLEN_").split("__"));
|
||||
// Support OLLAMA_API_KEY, OLLAMA_MODEL, etc. (without nesting)
|
||||
fig = fig.merge(Env::prefixed("OLLAMA_"));
|
||||
|
||||
fig.extract()
|
||||
}
|
||||
19
crates/platform/config/tests/precedence.rs
Normal file
19
crates/platform/config/tests/precedence.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use config_agent::{load_settings, Settings};
|
||||
use std::{env, fs};
|
||||
|
||||
#[test]
|
||||
fn precedence_env_overrides_files() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let project_file = tmp.path().join(".owlen.toml");
|
||||
fs::write(&project_file, r#"model="local-model""#).unwrap();
|
||||
|
||||
unsafe { env::set_var("OWLEN_MODEL", "env-model"); }
|
||||
let s = load_settings(Some(tmp.path().to_str().unwrap())).unwrap();
|
||||
assert_eq!(s.model, "env-model");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_mode_is_plan() {
|
||||
let s = Settings::default();
|
||||
assert_eq!(s.mode, "plan");
|
||||
}
|
||||
Reference in New Issue
Block a user