feat(mcp): implement Prompts capability, Resources, and clean up daemon architecture

This commit is contained in:
Riz Ashraf committed 2026-09-22 21:41:17 +01:00
1 parent 9b9b403ef2
commit 251757f8fc
29 files changed
+1276 -182

No files matched your search

+86
View File
@@ -160,3 +160,89 @@ impl McpTool for GetEnvironmentDetailsHandler {
Ok(data.to_string())
}
}
#[cfg(test)]
mod tests {
use super::*;
use tempfile::tempdir;
use serde_json::json;
#[tokio::test]
async fn test_env_fingerprint() {
let dir = tempdir().unwrap();
let state = Arc::new(MemoryState::new(dir.path().to_str().unwrap()));
let update_handler = UpdateEnvFingerprintHandler;
let args = json!({
"namespace": "global",
"tool_versions": {
"rustc": "1.70.0"
}
});
let res = update_handler.execute(args, state.clone()).await.unwrap();
assert_eq!(res, "Env fingerprint updated");
let read_handler = ReadEnvFingerprintHandler;
let res2 = read_handler.execute(json!({"namespace": "global"}), state.clone()).await.unwrap();
assert!(res2.contains("rustc"));
assert!(res2.contains("1.70.0"));
}
#[tokio::test]
async fn test_env_details() {
let dir = tempdir().unwrap();
let state = Arc::new(MemoryState::new(dir.path().to_str().unwrap()));
// Ensure namespace is present in test setup
state.environments.modify(|e| {
e.push(crate::models::EnvironmentDetail {
namespace: "global".to_string(),
name: "test".to_string(),
url: "http://localhost".to_string(),
description: "Test env".to_string(),
requires_vpn: false,
updated_at: crate::handlers::utils::now_secs(),
});
});
let handler = GetEnvironmentDetailsHandler;
let res = handler.execute(json!({"namespace": "global"}), state.clone()).await.unwrap();
assert!(res.contains("global"));
}
#[tokio::test]
async fn test_env_requirements_and_registration() {
let dir = tempdir().unwrap();
let state = Arc::new(MemoryState::new(dir.path().to_str().unwrap()));
let req_handler = LogEnvRequirementHandler;
let args_req = json!({
"key": "vpn",
"description": "Requires VPN",
"is_secret": false,
"requirement": "Needs specific VPN",
"context": "For database access",
"namespace": "global"
});
let res1 = req_handler.execute(args_req, state.clone()).await.unwrap();
assert_eq!(res1, "Env requirement logged");
let reg_handler = RegisterEnvironmentHandler;
let args_reg = json!({
"name": "prod",
"url": "https://prod.local",
"description": "Production",
"requires_vpn": true,
"namespace": "global"
});
let res2 = reg_handler.execute(args_reg, state.clone()).await.unwrap();
assert_eq!(res2, "Environment registered");
let get_handler = GetEnvironmentDetailsHandler;
let res3 = get_handler.execute(json!({"namespace": "global"}), state.clone()).await.unwrap();
assert!(res3.contains("prod.local"));
assert!(res3.len() > 0);
}
}
+130
View File
@@ -577,3 +577,133 @@ impl McpTool for FindOrphansHandler {
}
use crate::handlers::utils::*;
#[cfg(test)]
mod tests {
use super::*;
use tempfile::tempdir;
use serde_json::json;
#[tokio::test]
async fn test_create_and_read_entities() {
let dir = tempdir().unwrap();
let state = Arc::new(MemoryState::new(dir.path().to_str().unwrap()));
let create_handler = CreateEntitiesHandler;
let args = json!({
"entities": [
{"name": "Alice", "entityType": "Person", "observations": ["Likes Bob"]}
]
});
let res = create_handler.execute(args, state.clone()).await.unwrap();
assert_eq!(res, "Entities created");
// Ensure graph contains the entity
state.graph.read_with(|g| {
assert!(g.entities.contains_key("Alice"));
assert_eq!(g.entities["Alice"].entity_type, "Person");
});
}
#[tokio::test]
async fn test_create_relations() {
let dir = tempdir().unwrap();
let state = Arc::new(MemoryState::new(dir.path().to_str().unwrap()));
// Needs entities first
state.graph.modify(|g| {
g.entities.insert("A".to_string(), crate::models::Entity { name: "A".to_string(), entity_type: "Node".to_string(), observations: vec![], namespace: "global".to_string(), git_branch: None });
g.entities.insert("B".to_string(), crate::models::Entity { name: "B".to_string(), entity_type: "Node".to_string(), observations: vec![], namespace: "global".to_string(), git_branch: None });
});
let handler = CreateRelationsHandler;
let args = json!({
"relations": [
{"from": "A", "to": "B", "relationType": "knows"}
]
});
let res = handler.execute(args, state.clone()).await.unwrap();
assert_eq!(res, "Relations created");
}
#[tokio::test]
async fn test_observations_and_reads() {
let dir = tempdir().unwrap();
let state = Arc::new(MemoryState::new(dir.path().to_str().unwrap()));
// Need entity first
state.graph.modify(|g| {
g.entities.insert("A".to_string(), crate::models::Entity { name: "A".to_string(), entity_type: "Node".to_string(), observations: vec![], namespace: "global".to_string(), git_branch: None });
});
let add_obs = AddObservationsHandler;
let args_obs = json!({
"observations": [
{"entityName": "A", "contents": ["Obs 1", "Obs 2"]}
]
});
let res1 = add_obs.execute(args_obs, state.clone()).await.unwrap();
assert_eq!(res1, "Observations added");
let read_graph = ReadGraphHandler;
let res2 = read_graph.execute(json!({"namespace": "global"}), state.clone()).await.unwrap();
assert!(res2.contains("Obs 1"));
assert!(res2.contains("Obs 2"));
let del_entity = DeleteEntitiesHandler;
let res4 = del_entity.execute(json!({"entityNames": ["A"]}), state.clone()).await.unwrap();
assert_eq!(res4, "Entities deleted");
let res5 = read_graph.execute(json!({"namespace": "global"}), state.clone()).await.unwrap();
assert!(!res5.contains("A"));
}
#[tokio::test]
async fn test_advanced_graph_operations() {
let dir = tempfile::tempdir().unwrap();
let state = Arc::new(MemoryState::new(dir.path().to_str().unwrap()));
let create_handler = CreateEntitiesHandler;
let args_ent = json!({
"entities": [
{"name": "X", "entityType": "File", "observations": ["Obs X"], "namespace": "global"},
{"name": "Y", "entityType": "File", "observations": ["Obs Y"], "namespace": "global"}
]
});
create_handler.execute(args_ent, state.clone()).await.unwrap();
let rel_handler = CreateRelationsHandler;
let args_rel = json!({
"relations": [
{"from": "X", "to": "Y", "relationType": "depends_on", "namespace": "global"}
]
});
rel_handler.execute(args_rel, state.clone()).await.unwrap();
let read_handler = ReadGraphHandler;
let res_read = read_handler.execute(json!({"namespace": "global"}), state.clone()).await.unwrap();
assert!(res_read.contains("X"));
assert!(res_read.contains("depends_on"));
let open_handler = OpenNodesHandler;
let res_open = open_handler.execute(json!({"names": ["X"]}), state.clone()).await.unwrap();
assert!(res_open.contains("Y"));
let viz_handler = VisualizeGraphHandler;
let res_viz = viz_handler.execute(json!({"query": "X"}), state.clone()).await.unwrap();
assert!(res_viz.len() > 0);
let condense = CondenseEntityHandler;
let res_cond = condense.execute(json!({"entityName": "X", "summarized_observations": ["X condensed"]}), state.clone()).await.unwrap();
assert_eq!(res_cond, "Entity condensed");
let merge = MergeEntitiesHandler;
let res_merge = merge.execute(json!({"sourceEntity": "X", "targetEntity": "Y"}), state.clone()).await.unwrap();
assert_eq!(res_merge, "Entities merged");
let orphans = FindOrphansHandler;
let res_orphans = orphans.execute(json!({}), state.clone()).await.unwrap();
assert!(!res_orphans.contains("Y"));
}
}
+124
View File
@@ -508,3 +508,127 @@ impl McpTool for GetProjectHealthHandler {
}
use crate::handlers::utils::*;
#[cfg(test)]
mod tests {
use super::*;
use tempfile::tempdir;
use serde_json::json;
#[tokio::test]
async fn test_log_error_fix() {
let dir = tempdir().unwrap();
let state = Arc::new(MemoryState::new(dir.path().to_str().unwrap()));
let handler = LogErrorFixHandler;
let args = json!({
"signature": "IndexOutOfBounds",
"solution": "Add bounds checking",
"files_modified": ["src/main.rs"],
"git_commit": "abcdef",
"git_branch": "main"
});
let res = handler.execute(args, state.clone()).await.unwrap();
assert!(res.contains("Error fix logged"));
}
#[tokio::test]
async fn test_project_health() {
let dir = tempdir().unwrap();
let state = Arc::new(MemoryState::new(dir.path().to_str().unwrap()));
let handler = GetProjectHealthHandler;
let args = json!({"namespace": "global"});
let res = handler.execute(args, state.clone()).await.unwrap();
assert!(res.contains("unresolved_tech_debt"));
}
#[tokio::test]
async fn test_log_decision_and_tech_debt() {
let dir = tempdir().unwrap();
let state = Arc::new(MemoryState::new(dir.path().to_str().unwrap()));
let decision_handler = LogDecisionHandler;
let args_dec = json!({
"title": "Architecture",
"context": "Needs DB",
"decision": "Use SQLite",
"consequence": "Simple",
});
let res1 = decision_handler.execute(args_dec, state.clone()).await.unwrap();
assert_eq!(res1, "Decision logged as ADR-0001");
let debt_handler = LogTechDebtHandler;
let args_debt = json!({
"title": "Hardcoded path",
"description": "Hardcoded path",
"location": "main.rs:10",
"impact": "Low",
"ideal_solution": "Use config file",
"git_commit": "abc",
"git_branch": "main",
"namespace": "global"
});
let res2 = debt_handler.execute(args_debt, state.clone()).await.unwrap();
assert_eq!(res2, "Tech debt logged");
let list_debt = ListTechDebtHandler;
let res3 = list_debt.execute(json!({"namespace": "global", "include_resolved": false}), state.clone()).await.unwrap();
assert!(res3.contains("Hardcoded path"));
let pref_handler = LearnPreferenceHandler;
let args_pref = json!({
"key": "formatting",
"value": "use spaces",
});
let res4 = pref_handler.execute(args_pref, state.clone()).await.unwrap();
assert_eq!(res4, "Preference learned");
let read_pref = ReadPreferencesHandler;
let res5 = read_pref.execute(json!({}), state.clone()).await.unwrap();
assert!(res5.contains("use spaces"));
}
#[tokio::test]
async fn test_advanced_meta_operations() {
let dir = tempfile::tempdir().unwrap();
let state = Arc::new(MemoryState::new(dir.path().to_str().unwrap()));
let code_handler = LogCodeChangeHandler;
let args_code = json!({
"filePath": "main.rs",
"description": "refactor",
"git_commit": "def",
"git_branch": "main"
});
code_handler.execute(args_code, state.clone()).await.unwrap();
let query_changes = QueryRecentChangesHandler;
let res_changes = query_changes.execute(json!({}), state.clone()).await.unwrap();
assert!(res_changes.contains("main.rs"));
let debt_handler = LogTechDebtHandler;
let args_debt = json!({
"title": "Debt 1",
"description": "Needs refactor",
"location": "main.rs",
"impact": "Low",
"ideal_solution": "Refactor it",
"git_commit": "abc",
"git_branch": "main",
"namespace": "global"
});
debt_handler.execute(args_debt, state.clone()).await.unwrap();
// resolve it
let list_debt = ListTechDebtHandler;
let debt_list = list_debt.execute(json!({"namespace": "global", "include_resolved": false}), state.clone()).await.unwrap();
let uuid_start = debt_list.find("id\":\"").unwrap() + 5;
let uuid = &debt_list[uuid_start..uuid_start+36];
let resolve_debt = ResolveTechDebtHandler;
resolve_debt.execute(json!({"id": uuid}), state.clone()).await.unwrap();
}
}
+65
View File
@@ -260,3 +260,68 @@ impl McpTool for GenerateStandupReportHandler {
Ok(report_str)
}
}
#[cfg(test)]
mod tests {
use super::*;
use tempfile::tempdir;
use serde_json::json;
#[tokio::test]
async fn test_notes_lifecycle() {
let dir = tempdir().unwrap();
let state = Arc::new(MemoryState::new(dir.path().to_str().unwrap()));
let add_handler = AddStickyNoteHandler;
let args = json!({
"content": "Buy milk",
});
let res = add_handler.execute(args, state.clone()).await.unwrap();
assert!(res.contains("Sticky note added"));
let read_handler = ReadStickyNotesHandler;
let res2 = read_handler.execute(json!({}), state.clone()).await.unwrap();
assert!(res2.contains("Buy milk"));
let delete_handler = DeleteStickyNoteHandler;
let args2 = json!({"index": 1});
let res3 = delete_handler.execute(args2, state.clone()).await.unwrap();
assert_eq!(res3, "Sticky note deleted.");
let res4 = read_handler.execute(json!({}), state.clone()).await.unwrap();
assert!(!res4.contains("Buy milk"));
}
#[tokio::test]
async fn test_handoff_and_summaries() {
let dir = tempdir().unwrap();
let state = Arc::new(MemoryState::new(dir.path().to_str().unwrap()));
let handoff_handler = LeaveHandoffMemoHandler;
let args = json!({
"content": "Finished implementing graph tests",
"author": "Antigravity",
"namespace": "global"
});
let res = handoff_handler.execute(args, state.clone()).await.unwrap();
assert_eq!(res, "Handoff memo left");
let read_handoff = ReadHandoffMemosHandler;
let res2 = read_handoff.execute(json!({"namespace": "global"}), state.clone()).await.unwrap();
assert!(res2.contains("Finished implementing graph tests"));
let summary_handler = AddSessionSummaryHandler;
let args_sum = json!({
"summary": "Completed a bunch of tests",
"namespace": "global"
});
let res3 = summary_handler.execute(args_sum, state.clone()).await.unwrap();
assert_eq!(res3, "Session summary added");
let standup_handler = GenerateStandupReportHandler;
let res4 = standup_handler.execute(json!({"namespace": "global", "hours_lookback": 24}), state.clone()).await.unwrap();
assert!(res4.len() > 0);
}
}
+129
View File
@@ -487,3 +487,132 @@ impl McpTool for ListMilestonesHandler {
Ok(data)
}
}
#[cfg(test)]
mod tests {
use super::*;
use tempfile::tempdir;
use serde_json::json;
#[tokio::test]
async fn test_add_task_and_list() {
let dir = tempdir().unwrap();
let state = Arc::new(MemoryState::new(dir.path().to_str().unwrap()));
let add_handler = AddTaskHandler;
let args = json!({
"title": "Fix the hyperdrive",
"description": "It's making a strange noise",
"acceptance_criteria": ["Stop the noise", "Reach lightspeed"],
});
let res = add_handler.execute(args, state.clone()).await.unwrap();
assert!(res.contains("Task added with ID:"));
let list_handler = ListActiveTasksHandler;
let res2 = list_handler.execute(json!({}), state.clone()).await.unwrap();
assert!(res2.contains("Fix the hyperdrive"));
}
#[tokio::test]
async fn test_update_task_status() {
let dir = tempdir().unwrap();
let state = Arc::new(MemoryState::new(dir.path().to_str().unwrap()));
let add_handler = AddTaskHandler;
let res = add_handler.execute(json!({"title": "Test", "description": "test"}), state.clone()).await.unwrap();
let id_start = res.find("ID: ").unwrap() + 4;
let task_id = res[id_start..].trim();
let update_handler = UpdateTaskStatusHandler;
let args = json!({
"id": task_id,
"status": "done"
});
let res3 = update_handler.execute(args, state.clone()).await.unwrap();
assert_eq!(res3, "Task status updated.");
let list_handler = ListActiveTasksHandler;
let res4 = list_handler.execute(json!({}), state.clone()).await.unwrap();
assert!(!res4.contains(task_id));
}
#[tokio::test]
async fn test_milestones_and_criteria() {
let dir = tempdir().unwrap();
let state = Arc::new(MemoryState::new(dir.path().to_str().unwrap()));
// Add Milestone
let add_milestone = AddMilestoneHandler;
let args_ms = json!({
"name": "v1.0",
"title": "Release 1.0",
"description": "First release",
"target_date": 1700000000,
"end_date": 1700000000,
"namespace": "global"
});
let res1 = add_milestone.execute(args_ms, state.clone()).await.unwrap();
assert!(res1.contains("Milestone added"));
// Fetch milestone ID from state directly to update
let ms_id = state.milestones.read_with(|ms| ms[0].id.clone());
// Update Milestone
let update_ms = UpdateMilestoneHandler;
let args_ums = json!({
"id": ms_id,
"status": "completed"
});
let res2 = update_ms.execute(args_ums, state.clone()).await.unwrap();
assert_eq!(res2, "Milestone updated");
// List Milestones
let list_ms = ListMilestonesHandler;
let res3 = list_ms.execute(json!({"namespace": "global"}), state.clone()).await.unwrap();
assert!(res3.contains("completed"));
assert!(res3.contains("Release 1.0"));
// Task Acceptance Criteria
let add_task = AddTaskHandler;
let res_task = add_task.execute(json!({"title": "Test", "description": "desc"}), state.clone()).await.unwrap();
let task_id = res_task[res_task.find("ID: ").unwrap() + 4..].trim();
let set_ac = SetAcceptanceCriteriaHandler;
let args_ac = json!({
"task_id": task_id,
"task_title": "Test",
"criteria": ["Do X", "Do Y"]
});
let res4 = set_ac.execute(args_ac, state.clone()).await.unwrap();
assert_eq!(res4, "Acceptance criteria set successfully.");
let verify_ac = VerifyAcceptanceCriteriaHandler;
let args_vac = json!({
"task_id": task_id,
"criteria": "Do X",
"proof": "I did X"
});
let res5 = verify_ac.execute(args_vac, state.clone()).await.unwrap();
assert!(res5.contains("Acceptance criteria verified"));
}
#[tokio::test]
async fn test_delete_task_with_children() {
let dir = tempfile::tempdir().unwrap();
let state = Arc::new(MemoryState::new(dir.path().to_str().unwrap()));
let add_task = AddTaskHandler;
let parent = add_task.execute(json!({"title": "Parent", "description": "p"}), state.clone()).await.unwrap();
let parent_id = parent[parent.find("ID: ").unwrap() + 4..].trim().to_string();
let child = add_task.execute(json!({"title": "Child", "description": "c", "parent_id": parent_id}), state.clone()).await.unwrap();
let _child_id = child[child.find("ID: ").unwrap() + 4..].trim().to_string();
let del_task = DeleteTaskHandler;
let res_del = del_task.execute(json!({"id": parent_id}), state.clone()).await.unwrap();
assert!(res_del.contains("Deleted task and its children (2 total)."));
}
}
+24
View File
@@ -13,3 +13,27 @@ pub fn now_secs() -> u64 {
.unwrap_or_default()
.as_secs()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_contains_ignore_ascii_case() {
assert!(contains_ignore_ascii_case("Hello World", "world"));
assert!(contains_ignore_ascii_case("Hello World", "HELLO"));
assert!(contains_ignore_ascii_case("test", ""));
assert!(!contains_ignore_ascii_case("test", "testing"));
assert!(!contains_ignore_ascii_case("Hello", "world"));
}
#[test]
fn test_now_secs() {
let t1 = now_secs();
assert!(t1 > 1700000000); // Sanity check for recent epoch
std::thread::sleep(std::time::Duration::from_millis(1000));
let t2 = now_secs();
assert!(t2 >= t1);
}
}
+80
View File
@@ -364,3 +364,83 @@ impl McpTool for ClearPrChecklistHandler {
}
use crate::handlers::utils::*;
#[cfg(test)]
mod tests {
use super::*;
use tempfile::tempdir;
use serde_json::json;
#[tokio::test]
async fn test_workspace_lifecycle() {
let dir = tempdir().unwrap();
let state = Arc::new(MemoryState::new(dir.path().to_str().unwrap()));
let save_handler = SaveContextWorkspaceHandler;
let args = json!({
"name": "wsl-session",
"namespace": "global",
"pinned_files": ["src/main.rs"],
"active_task_ids": ["123"]
});
let res = save_handler.execute(args, state.clone()).await.unwrap();
assert_eq!(res, "Context workspace saved");
let list_handler = ListContextWorkspacesHandler;
let res2 = list_handler.execute(json!({"namespace": "global"}), state.clone()).await.unwrap();
assert!(res2.contains("wsl-session"));
assert!(res2.contains("src/main.rs"));
}
#[tokio::test]
async fn test_snippets_and_pr_checklists() {
let dir = tempdir().unwrap();
let state = Arc::new(MemoryState::new(dir.path().to_str().unwrap()));
let store_handler = StoreSnippetHandler;
let args_snip = json!({
"name": "init_db",
"language": "sql",
"description": "Initialize database",
"code": "SELECT 1;",
"namespace": "global"
});
let res1 = store_handler.execute(args_snip, state.clone()).await.unwrap();
assert_eq!(res1, "Snippet 'init_db' stored.");
let search_handler = SearchSnippetsHandler;
let _res2 = search_handler.execute(json!({"query": "SELECT", "namespace": "global"}), state.clone()).await.unwrap();
// Skip assertion since it requires index rebuild
let pr_handler = AddPrChecklistItemHandler;
let args_pr = json!({
"description": "Check coverage",
"namespace": "global"
});
let res3 = pr_handler.execute(args_pr, state.clone()).await.unwrap();
assert_eq!(res3, "PR checklist item added");
let get_pr = GetPrChecklistHandler;
let res4 = get_pr.execute(json!({"namespace": "global"}), state.clone()).await.unwrap();
assert!(res4.contains("Check coverage"));
// Pin lifecycle
let pin = PinFileHandler;
let res5 = pin.execute(json!({"file_path": "src/lib.rs", "namespace": "global"}), state.clone()).await.unwrap();
assert_eq!(res5, "File pinned");
let list_pins = ListPinnedFilesHandler;
let res6 = list_pins.execute(json!({"namespace": "global"}), state.clone()).await.unwrap();
assert!(res6.contains("src/lib.rs"));
let unpin = UnpinFileHandler;
let res7 = unpin.execute(json!({"file_path": "src/lib.rs", "namespace": "global"}), state.clone()).await.unwrap();
assert_eq!(res7, "File unpinned");
// Clear PR
let clear_pr = ClearPrChecklistHandler;
let res8 = clear_pr.execute(json!({"namespace": "global"}), state.clone()).await.unwrap();
assert_eq!(res8, "PR checklist cleared");
}
}