config: unify memory and agent config into single module
Both hippocampus/config.rs and agent/config.rs read from the same config file (~/.config/poc-agent/config.json5). Having two separate implementations was a footgun — load_context_groups() was duplicated three times across the codebase. Merged into src/config.rs: - Config (memory settings, global get()/reload()) - AppConfig (agent backend/model settings, figment-based loading) - SessionConfig (resolved agent session, renamed from agent's Config) - Single ContextGroup/ContextSource definition used everywhere Eliminated: duplicate load_context_groups(), duplicate ContextGroup definition in identity.rs, duplicate config file path constants. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
2f3fbb3353
commit
228815d807
7 changed files with 393 additions and 467 deletions
|
|
@ -35,8 +35,8 @@ use poc_memory::dbglog;
|
|||
use poc_memory::agent::*;
|
||||
use poc_memory::agent::runner::{Agent, TurnResult};
|
||||
use poc_memory::agent::api::ApiClient;
|
||||
use poc_memory::agent::config::{AppConfig, Config};
|
||||
use poc_memory::agent::tui::HotkeyAction;
|
||||
use poc_memory::config::{self, AppConfig, SessionConfig};
|
||||
use poc_memory::agent::ui_channel::{ContextInfo, StatusInfo, StreamTarget, UiMessage};
|
||||
|
||||
/// Hard compaction threshold — context is rebuilt immediately.
|
||||
|
|
@ -120,7 +120,7 @@ enum Command {
|
|||
/// and slash commands.
|
||||
struct Session {
|
||||
agent: Arc<Mutex<Agent>>,
|
||||
config: Config,
|
||||
config: SessionConfig,
|
||||
process_tracker: tools::ProcessTracker,
|
||||
ui_tx: ui_channel::UiSender,
|
||||
turn_tx: mpsc::Sender<(Result<TurnResult>, StreamTarget)>,
|
||||
|
|
@ -149,7 +149,7 @@ struct Session {
|
|||
impl Session {
|
||||
fn new(
|
||||
agent: Arc<Mutex<Agent>>,
|
||||
config: Config,
|
||||
config: SessionConfig,
|
||||
process_tracker: tools::ProcessTracker,
|
||||
ui_tx: ui_channel::UiSender,
|
||||
turn_tx: mpsc::Sender<(Result<TurnResult>, StreamTarget)>,
|
||||
|
|
@ -817,25 +817,9 @@ impl Session {
|
|||
self.send_context_info();
|
||||
}
|
||||
|
||||
/// Load context_groups from the shared config file.
|
||||
fn load_context_groups(&self) -> Vec<identity::ContextGroup> {
|
||||
let config_path = dirs::home_dir()
|
||||
.unwrap_or_else(|| PathBuf::from("."))
|
||||
.join(".config/poc-agent/config.json5");
|
||||
|
||||
if let Ok(content) = std::fs::read_to_string(&config_path) {
|
||||
let config: Result<serde_json::Value, _> = json5::from_str(&content);
|
||||
if let Ok(config) = config {
|
||||
if let Some(memory) = config.get("memory") {
|
||||
if let Some(groups) = memory.get("context_groups") {
|
||||
if let Ok(context_groups) = serde_json::from_value(groups.clone()) {
|
||||
return context_groups;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Vec::new()
|
||||
/// Get context_groups from the unified config.
|
||||
fn load_context_groups(&self) -> Vec<config::ContextGroup> {
|
||||
config::get().context_groups.clone()
|
||||
}
|
||||
|
||||
/// Send context loading info to the TUI debug screen.
|
||||
|
|
@ -885,7 +869,7 @@ impl Session {
|
|||
// --- Event loop ---
|
||||
|
||||
async fn run(cli: cli::CliArgs) -> Result<()> {
|
||||
let (config, _figment) = config::load(&cli)?;
|
||||
let (config, _figment) = config::load_session(&cli)?;
|
||||
|
||||
// Wire config.debug to the POC_DEBUG env var so all debug checks
|
||||
// throughout the codebase (API, SSE reader, diagnostics) see it.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue