diff --git a/src/tools/mod.rs b/src/tools/mod.rs index a70fae7..6a9ad73 100644 --- a/src/tools/mod.rs +++ b/src/tools/mod.rs @@ -4,6 +4,7 @@ pub mod batch_store; pub mod purge; pub mod query; pub mod store; +pub mod truth_status; use anyhow::Result; use serde_json::{json, Value}; @@ -139,6 +140,15 @@ pub fn get_tool_definitions() -> Vec { "required": ["confirm"] } }), + json!({ + "name": "truth_status", + "description": "Get aggregated truth scoring statistics for the memory store", + "inputSchema": { + "type": "object", + "properties": {}, + "required": [] + } + }), ] } @@ -152,6 +162,7 @@ pub async fn execute_tool( "batch_store" => batch_store::execute(state, arguments).await, "query" => query::execute(state, arguments).await, "purge" => purge::execute(state, arguments).await, + "truth_status" => truth_status::execute(state, arguments).await, _ => anyhow::bail!("Unknown tool: {}", tool_name), } } diff --git a/src/tools/truth_status.rs b/src/tools/truth_status.rs new file mode 100644 index 0000000..39b7cd3 --- /dev/null +++ b/src/tools/truth_status.rs @@ -0,0 +1,52 @@ +//! Truth Status Tool - Return aggregated truth scoring statistics + +use anyhow::{Context, Result}; +use serde_json::Value; +use std::sync::Arc; +use tracing::debug; + +use crate::AppState; + +/// Execute the truth_status tool +pub async fn execute(state: &Arc, _arguments: Value) -> Result { + // Check if truth scoring is enabled + if !state.config.truth.enabled { + debug!("Truth status requested but truth scoring is not enabled"); + return Ok(serde_json::json!({ + "enabled": false, + "message": "Truth scoring is not enabled" + }) + .to_string()); + } + + // Fetch aggregated stats from the database + let stats = state + .db + .get_truth_stats() + .await + .context("Failed to get truth scoring statistics")?; + + debug!( + "Truth stats: total={}, scored={}, coverage={:.1}%", + stats.total_memories, stats.scored_memories, stats.coverage_pct + ); + + Ok(serde_json::json!({ + "enabled": true, + "total_memories": stats.total_memories, + "scored_memories": stats.scored_memories, + "unscored_memories": stats.unscored_memories, + "coverage_pct": stats.coverage_pct, + "avg_truth_value": stats.avg_truth_value, + "avg_confidence": stats.avg_confidence, + "categories": { + "verified": stats.category_verified, + "plausible": stats.category_plausible, + "unverified": stats.category_unverified, + "contradicted": stats.category_contradicted + }, + "scoring_interval_seconds": state.config.truth.scoring_interval_seconds, + "batch_size": state.config.truth.batch_size + }) + .to_string()) +}