use saya_agent::ProposedClaimDto;
use saya_types::ClaimStatus;
pub(crate) fn knowledge_learned_text(claim: &ProposedClaimDto) -> String {
let phrase = describe(claim);
if phrase.is_empty() {
return String::new();
}
match claim.status {
ClaimStatus::Confirmed => {
format!("memory learned · {phrase} for {}\n", claim.object)
}
_ => format!(
"memory noted · {phrase} for {} — unconfirmed, review with /queue\n",
claim.object
),
}
}
fn describe(claim: &ProposedClaimDto) -> String {
let value = elide(&claim.value);
match (claim.kind.as_str(), claim.column.as_deref()) {
("table_alias", _) => format!("the alias \"{value}\""),
("table_grain", _) => format!("the grain \"{value}\""),
("table_description", _) => format!("the description \"{value}\""),
("default_time_column", _) => format!("{value} as the default time column"),
("column_role", Some(column)) => format!("{column} as {value}"),
("column_description", Some(column)) => format!("{column} described as \"{value}\""),
_ => String::new(),
}
}
fn elide(value: &str) -> String {
const MAX: usize = 60;
if value.chars().count() <= MAX {
return value.to_string();
}
let kept: String = value.chars().take(MAX).collect();
format!("{}…", kept.trim_end())
}
#[cfg(test)]
#[path = "render_learned_tests.rs"]
mod tests;