style: format seluruh workspace dengan cargo fmt
Menyeragamkan format kode sesuai rustfmt (126 file). Sebelumnya lefthook pre-commit 'cargo fmt --check' akan gagal pada commit apa pun.
This commit is contained in:
@@ -3,7 +3,9 @@
|
||||
use std::path::Path;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use zesdex_domain::cms::{AppConfig, AppConfigRepository, ModelRole, ProviderConfig, RepositoryError};
|
||||
use zesdex_domain::cms::{
|
||||
AppConfig, AppConfigRepository, ModelRole, ProviderConfig, RepositoryError,
|
||||
};
|
||||
|
||||
use crate::utils::write_json_atomic;
|
||||
|
||||
@@ -40,12 +42,15 @@ fn claude_settings_from_file() -> Option<ClaudeSettings> {
|
||||
|
||||
fn detect_claude_settings_provider() -> Option<(ProviderConfig, Option<String>)> {
|
||||
let settings = claude_settings_from_file();
|
||||
|
||||
|
||||
let file_creds = settings.as_ref().and_then(|s| {
|
||||
let env = s.env.as_ref()?;
|
||||
Some((env.anthropic_base_url.clone()?, env.anthropic_api_key.clone()?))
|
||||
Some((
|
||||
env.anthropic_base_url.clone()?,
|
||||
env.anthropic_api_key.clone()?,
|
||||
))
|
||||
});
|
||||
|
||||
|
||||
let env_creds = || -> Option<(String, String)> {
|
||||
let base_url = std::env::var("ANTHROPIC_BASE_URL").ok()?;
|
||||
let key = std::env::var("ANTHROPIC_API_KEY").ok()?;
|
||||
@@ -55,7 +60,7 @@ fn detect_claude_settings_provider() -> Option<(ProviderConfig, Option<String>)>
|
||||
let custom_model = settings.and_then(|s| s.custom_model);
|
||||
|
||||
let (base_url, key) = file_creds.or_else(env_creds)?;
|
||||
|
||||
|
||||
Some((
|
||||
ProviderConfig {
|
||||
api_base: base_url,
|
||||
@@ -63,7 +68,7 @@ fn detect_claude_settings_provider() -> Option<(ProviderConfig, Option<String>)>
|
||||
default_model: custom_model.clone(),
|
||||
default_api_key: Some(key),
|
||||
},
|
||||
custom_model
|
||||
custom_model,
|
||||
))
|
||||
}
|
||||
|
||||
@@ -72,9 +77,7 @@ impl AppConfigRepository for JsonAppConfigRepository {
|
||||
let path = base_dir.join("app_config.json");
|
||||
let mut cfg: AppConfig = match std::fs::read_to_string(&path) {
|
||||
Ok(s) => serde_json::from_str(&s)?,
|
||||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
|
||||
AppConfig::default()
|
||||
}
|
||||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => AppConfig::default(),
|
||||
Err(e) => return Err(RepositoryError::Io(e)),
|
||||
};
|
||||
|
||||
@@ -106,15 +109,13 @@ impl AppConfigRepository for JsonAppConfigRepository {
|
||||
}
|
||||
|
||||
if let Some(custom) = &custom_model {
|
||||
cfg.model_roles
|
||||
.entry(custom.clone())
|
||||
.or_insert(ModelRole {
|
||||
provider: "claude".to_string(),
|
||||
model: custom.clone(),
|
||||
max_tokens: Some(8192),
|
||||
context_window: Some(200_000),
|
||||
temperature: Some(0.7),
|
||||
});
|
||||
cfg.model_roles.entry(custom.clone()).or_insert(ModelRole {
|
||||
provider: "claude".to_string(),
|
||||
model: custom.clone(),
|
||||
max_tokens: Some(8192),
|
||||
context_window: Some(200_000),
|
||||
temperature: Some(0.7),
|
||||
});
|
||||
}
|
||||
|
||||
if cfg.default_provider == defaults.default_provider {
|
||||
|
||||
@@ -77,10 +77,7 @@ impl MarkdownMemoryRepository {
|
||||
.lines()
|
||||
.filter_map(|l| {
|
||||
let mut it = l.splitn(2, ':');
|
||||
Some((
|
||||
it.next()?.trim().to_string(),
|
||||
it.next()?.trim().to_string(),
|
||||
))
|
||||
Some((it.next()?.trim().to_string(), it.next()?.trim().to_string()))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@@ -175,7 +172,9 @@ impl MemoryRepository for MarkdownMemoryRepository {
|
||||
|
||||
fn save(&self, memory_dir: &Path, memory: &Memory) -> Result<(), RepositoryError> {
|
||||
let path = Memory::path(memory_dir, &memory.name);
|
||||
let parent = path.parent().expect("memory path always has a parent directory");
|
||||
let parent = path
|
||||
.parent()
|
||||
.expect("memory path always has a parent directory");
|
||||
std::fs::create_dir_all(parent)?;
|
||||
|
||||
let frontmatter = Self::build_frontmatter(memory);
|
||||
|
||||
@@ -21,16 +21,16 @@ impl SettingsRepository for JsonSettingsRepository {
|
||||
fn load(&self, base_dir: &Path) -> Result<Settings, RepositoryError> {
|
||||
let path = base_dir.join("settings.json");
|
||||
match std::fs::read_to_string(&path) {
|
||||
Ok(s) => match serde_json::from_str(&s) {
|
||||
Ok(settings) => Ok(settings),
|
||||
Err(e) => {
|
||||
tracing::warn!("settings.json at '{:?}' failed to parse ({e}); falling back to defaults", path);
|
||||
Ok(Settings::default())
|
||||
Ok(s) => {
|
||||
match serde_json::from_str(&s) {
|
||||
Ok(settings) => Ok(settings),
|
||||
Err(e) => {
|
||||
tracing::warn!("settings.json at '{:?}' failed to parse ({e}); falling back to defaults", path);
|
||||
Ok(Settings::default())
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
|
||||
Ok(Settings::default())
|
||||
}
|
||||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(Settings::default()),
|
||||
Err(e) => Err(RepositoryError::Io(e)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,9 +50,7 @@ impl SessionLockRepository for FileSystemSessionLockRepository {
|
||||
.write(true)
|
||||
.open(&tmp)
|
||||
.map_err(|_| {
|
||||
RepositoryError::Other(
|
||||
"another process is replacing the lock".to_string(),
|
||||
)
|
||||
RepositoryError::Other("another process is replacing the lock".to_string())
|
||||
})?;
|
||||
write!(tmp_file, "{pid}")?;
|
||||
tmp_file.sync_all()?;
|
||||
|
||||
@@ -5,16 +5,12 @@ pub mod cms;
|
||||
pub mod iam;
|
||||
pub mod sqlite;
|
||||
|
||||
pub use cms::{
|
||||
app_config_repo::JsonAppConfigRepository, conversation_repo::JsonConversationRepository,
|
||||
edit_log_repo::JsonlEditLogRepository, memory_repo::MarkdownMemoryRepository,
|
||||
rewind_blob_repo::FileRewindBlobRepository, settings_repo::JsonSettingsRepository,
|
||||
};
|
||||
pub use iam::{
|
||||
oauth_repo::FileSystemOAuthRepository,
|
||||
session_lock_repo::FileSystemSessionLockRepository,
|
||||
oauth_repo::FileSystemOAuthRepository, session_lock_repo::FileSystemSessionLockRepository,
|
||||
session_repo::FileSystemSessionRepository,
|
||||
};
|
||||
pub use cms::{
|
||||
app_config_repo::JsonAppConfigRepository,
|
||||
conversation_repo::JsonConversationRepository,
|
||||
edit_log_repo::JsonlEditLogRepository,
|
||||
memory_repo::MarkdownMemoryRepository,
|
||||
rewind_blob_repo::FileRewindBlobRepository,
|
||||
settings_repo::JsonSettingsRepository,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user