Files
sol/src/context.rs
Sienna Meridian Satterwhite 4949e70ecc feat: per-user auto-memory with ResponseContext
Three memory channels: hidden tool (sol.memory.set/get in scripts),
pre-response injection (relevant memories loaded into system prompt),
and post-response extraction (ministral-3b extracts facts after each
response). User isolation enforced at Rust level — user_id derived
from Matrix sender, never from script arguments.

New modules: context (ResponseContext), memory (schema, store, extractor).
ResponseContext threaded through responder → tools → script runtime.
OpenSearch index sol_user_memory created on startup alongside archive.
2026-03-21 15:51:31 +00:00

57 lines
1.5 KiB
Rust

/// Per-message response context, threading the sender's identity from Matrix
/// through the tool loop and memory system.
#[derive(Debug, Clone)]
pub struct ResponseContext {
/// Full Matrix user ID, e.g. `@sienna:sunbeam.pt`
pub matrix_user_id: String,
/// Derived portable ID, e.g. `sienna@sunbeam.pt`
pub user_id: String,
/// Display name if available
pub display_name: Option<String>,
/// Whether this message was sent in a DM
pub is_dm: bool,
/// Whether this message is a reply to Sol
pub is_reply: bool,
/// The room this message was sent in
pub room_id: String,
}
/// Derive a portable user ID from a Matrix user ID.
///
/// `@sienna:sunbeam.pt` → `sienna@sunbeam.pt`
pub fn derive_user_id(matrix_user_id: &str) -> String {
let stripped = matrix_user_id.strip_prefix('@').unwrap_or(matrix_user_id);
stripped.replacen(':', "@", 1)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_derive_user_id_standard() {
assert_eq!(derive_user_id("@sienna:sunbeam.pt"), "sienna@sunbeam.pt");
}
#[test]
fn test_derive_user_id_no_at_prefix() {
assert_eq!(derive_user_id("sienna:sunbeam.pt"), "sienna@sunbeam.pt");
}
#[test]
fn test_derive_user_id_complex() {
assert_eq!(
derive_user_id("@user.name:matrix.org"),
"user.name@matrix.org"
);
}
#[test]
fn test_derive_user_id_only_first_colon() {
assert_eq!(
derive_user_id("@user:server:8448"),
"user@server:8448"
);
}
}