config: move user_name/assistant_name to AppConfig (top level)

These are identity settings, not memory-graph settings. Sat inside the
\`memory\` section only because that's where Config started life. Move
to AppConfig alongside the other top-level stuff.

Readers now pull from \`config::app()\` instead of \`config::get()\`.
subconscious/defs.rs's conversation-building pass still needs Config
for surface_conversation_bytes, so both guards coexist there —
AppConfig's guard is dropped before the per-step await loop so we
don't stall the config-watcher's writer.

show_config picks up the two new fields at the top of its output.
Kent's config already has them hoisted to the top level.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-16 16:20:17 -04:00
parent dd551fe551
commit 592a3e2e52
6 changed files with 29 additions and 18 deletions

View file

@ -374,7 +374,7 @@ impl AstNode {
/// Short label for the UI. /// Short label for the UI.
pub fn label(&self) -> String { pub fn label(&self) -> String {
let cfg = crate::config::get(); let app = crate::config::app();
match self { match self {
Self::Branch { role, children, .. } => { Self::Branch { role, children, .. } => {
let preview = children.first() let preview = children.first()
@ -383,8 +383,8 @@ impl AstNode {
.unwrap_or_default(); .unwrap_or_default();
match role { match role {
Role::System => "system".into(), Role::System => "system".into(),
Role::User => format!("{}: {}", cfg.user_name, preview), Role::User => format!("{}: {}", app.user_name, preview),
Role::Assistant => format!("{}: {}", cfg.assistant_name, preview), Role::Assistant => format!("{}: {}", app.assistant_name, preview),
} }
} }
Self::Leaf(leaf) => match &leaf.body { Self::Leaf(leaf) => match &leaf.body {

View file

@ -183,8 +183,8 @@ fn resolve_prompt(
state: &std::collections::BTreeMap<String, String>, state: &std::collections::BTreeMap<String, String>,
recently_written: &[String], recently_written: &[String],
) -> String { ) -> String {
let cfg = crate::config::get(); let template = template.replace("{assistant_name}",
let template = template.replace("{assistant_name}", &cfg.assistant_name); &crate::config::app().assistant_name);
let mut result = String::with_capacity(template.len()); let mut result = String::with_capacity(template.len());
let mut rest = template.as_str(); let mut rest = template.as_str();
while let Some(start) = rest.find("{{") { while let Some(start) = rest.find("{{") {

View file

@ -197,7 +197,7 @@ pub async fn cmd_load_context(stats: bool) -> Result<()> {
return Ok(()); return Ok(());
} }
println!("=== MEMORY SYSTEM ({}) ===", cfg.assistant_name); println!("=== MEMORY SYSTEM ({}) ===", crate::config::app().assistant_name);
if !personality.is_empty() { if !personality.is_empty() {
println!("--- personality_nodes ({}) ---", personality.len()); println!("--- personality_nodes ({}) ---", personality.len());

View file

@ -40,8 +40,6 @@ fn default_identity_dir() -> PathBuf {
#[derive(Debug, Clone, Deserialize)] #[derive(Debug, Clone, Deserialize)]
#[serde(default)] #[serde(default)]
pub struct Config { pub struct Config {
pub user_name: String,
pub assistant_name: String,
#[serde(deserialize_with = "deserialize_path")] #[serde(deserialize_with = "deserialize_path")]
pub data_dir: PathBuf, pub data_dir: PathBuf,
#[serde(default = "default_identity_dir", deserialize_with = "deserialize_path")] #[serde(default = "default_identity_dir", deserialize_with = "deserialize_path")]
@ -91,8 +89,6 @@ impl Default for Config {
fn default() -> Self { fn default() -> Self {
let home = dirs::home_dir().unwrap_or_default(); let home = dirs::home_dir().unwrap_or_default();
Self { Self {
user_name: "User".to_string(),
assistant_name: "Assistant".to_string(),
data_dir: home.join(".consciousness/memory"), data_dir: home.join(".consciousness/memory"),
identity_dir: home.join(".consciousness/identity"), identity_dir: home.join(".consciousness/identity"),
projects_dir: home.join(".claude/projects"), projects_dir: home.join(".claude/projects"),
@ -229,6 +225,10 @@ pub fn watch_config(cli: crate::user::CliArgs) {
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AppConfig { pub struct AppConfig {
#[serde(default = "default_user_name")]
pub user_name: String,
#[serde(default = "default_assistant_name")]
pub assistant_name: String,
/// Named model endpoints — credentials, base URL, and model id bundled /// Named model endpoints — credentials, base URL, and model id bundled
/// into one entry per backend. Keyed by name, selected by /// into one entry per backend. Keyed by name, selected by
/// `default_backend` or by `--model <name>` on the CLI. /// `default_backend` or by `--model <name>` on the CLI.
@ -315,9 +315,14 @@ impl Default for LearnConfig {
} }
} }
fn default_user_name() -> String { "User".into() }
fn default_assistant_name() -> String { "Assistant".into() }
impl Default for AppConfig { impl Default for AppConfig {
fn default() -> Self { fn default() -> Self {
Self { Self {
user_name: default_user_name(),
assistant_name: default_assistant_name(),
backends: HashMap::new(), backends: HashMap::new(),
default_backend: String::new(), default_backend: String::new(),
debug: false, debug: false,
@ -534,7 +539,9 @@ pub fn show_config(app: &AppConfig, figment: &Figment) {
} }
println!("# Effective configuration\n"); println!("# Effective configuration\n");
println!("debug: {} ({})", app.debug, src(figment, "debug")); println!("user_name: {:?} ({})", app.user_name, src(figment, "user_name"));
println!("assistant_name: {:?} ({})", app.assistant_name, src(figment, "assistant_name"));
println!("\ndebug: {} ({})", app.debug, src(figment, "debug"));
println!("\ncompaction:"); println!("\ncompaction:");
println!(" hard_threshold_pct: {} ({})", app.compaction.hard_threshold_pct, src(figment, "compaction.hard_threshold_pct")); println!(" hard_threshold_pct: {} ({})", app.compaction.hard_threshold_pct, src(figment, "compaction.hard_threshold_pct"));
println!(" soft_threshold_pct: {} ({})", app.compaction.soft_threshold_pct, src(figment, "compaction.soft_threshold_pct")); println!(" soft_threshold_pct: {} ({})", app.compaction.soft_threshold_pct, src(figment, "compaction.soft_threshold_pct"));

View file

@ -92,7 +92,8 @@ impl State {
/// Generate the DMN prompt for the current state, informed by /// Generate the DMN prompt for the current state, informed by
/// user presence and error patterns. /// user presence and error patterns.
pub fn prompt(&self, ctx: &DmnContext) -> String { pub fn prompt(&self, ctx: &DmnContext) -> String {
let user = &crate::config::get().user_name; let app = crate::config::app();
let user = &app.user_name;
let idle_info = if ctx.user_idle < Duration::from_secs(60) { let idle_info = if ctx.user_idle < Duration::from_secs(60) {
format!("{} is here (active recently).", user) format!("{} is here (active recently).", user)

View file

@ -396,13 +396,14 @@ fn resolve_conversation(budget: Option<usize>) -> String {
let cfg = crate::config::get(); let cfg = crate::config::get();
let max_bytes = budget.unwrap_or_else(|| cfg.surface_conversation_bytes.unwrap_or(100_000)); let max_bytes = budget.unwrap_or_else(|| cfg.surface_conversation_bytes.unwrap_or(100_000));
let app = crate::config::app();
let mut fragments: Vec<String> = Vec::new(); let mut fragments: Vec<String> = Vec::new();
let mut total_bytes = 0; let mut total_bytes = 0;
let mut oldest_ts = String::new(); let mut oldest_ts = String::new();
for (role, content, ts) in iter { for (role, content, ts) in iter {
if total_bytes >= max_bytes { break; } if total_bytes >= max_bytes { break; }
let name = if role == "user" { &cfg.user_name } else { &cfg.assistant_name }; let name = if role == "user" { &app.user_name } else { &app.assistant_name };
let formatted = if !ts.is_empty() { let formatted = if !ts.is_empty() {
oldest_ts = ts[..ts.floor_char_boundary(ts.len().min(19))].to_string(); oldest_ts = ts[..ts.floor_char_boundary(ts.len().min(19))].to_string();
format!("**{}** {}: {}", name, &oldest_ts, content) format!("**{}** {}: {}", name, &oldest_ts, content)
@ -623,11 +624,13 @@ pub async fn run_agent(
let mut all_keys = keys; let mut all_keys = keys;
let mut resolved_steps = Vec::new(); let mut resolved_steps = Vec::new();
for step in &def.steps { for step in &def.steps {
let cfg = crate::config::get(); let template = {
let template = step.prompt let app = crate::config::app();
.replace("{agent_name}", &def.agent) step.prompt
.replace("{user_name}", &cfg.user_name) .replace("{agent_name}", &def.agent)
.replace("{assistant_name}", &cfg.assistant_name); .replace("{user_name}", &app.user_name)
.replace("{assistant_name}", &app.assistant_name)
};
let (prompt, extra_keys) = resolve_placeholders(&template, &all_keys, count).await; let (prompt, extra_keys) = resolve_placeholders(&template, &all_keys, count).await;
all_keys.extend(extra_keys); all_keys.extend(extra_keys);
resolved_steps.push(super::prompts::ResolvedStep { resolved_steps.push(super::prompts::ResolvedStep {