feat(server): refactor handlers, router, state management, and memory tools

This commit is contained in:
Riz Ashraf committed 2026-10-02 07:27:37 +01:00
1 parent 87ddb01063
commit a083719cf1
36 files changed
+1899 -597

No files matched your search

+37 -11
View File
@@ -49,7 +49,8 @@ impl McpTool for ReadStickyNotesHandler {
async fn execute(&self, _args: Value, state: Arc<MemoryState>) -> crate::error::Result<String> {
let data = state
.code.sticky
.code
.sticky
.read_with(|s| Ok::<String, crate::error::AppError>(serde_json::to_string(s)?))?;
Ok(data)
}
@@ -82,7 +83,9 @@ impl McpTool for DeleteStickyNoteHandler {
if success {
Ok("Sticky note deleted.".to_string())
} else {
Err(crate::error::AppError::Internal("Invalid sticky note index.".to_string()))
Err(crate::error::AppError::Internal(
"Invalid sticky note index.".to_string(),
))
}
}
}
@@ -194,7 +197,8 @@ impl McpTool for ClearHandoffMemosHandler {
let req: ClearHandoffMemosTool = serde_json::from_value(args).map_err(|e| e.to_string())?;
let ids: HashSet<_> = req.ids.into_iter().collect();
state
.telemetry.handoff_memos
.telemetry
.handoff_memos
.modify(|memos| memos.retain(|m| !ids.contains(&m.id)));
Ok("Handoff memos cleared".to_string())
}
@@ -280,23 +284,35 @@ mod tests {
"content": "Buy milk",
});
let res = add_handler.execute(args, state.clone()).await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
let res = add_handler
.execute(args, state.clone())
.await
.map_err(|e| crate::error::AppError::Internal(e.to_string()))
.unwrap();
assert!(res.contains("Sticky note added"));
let read_handler = ReadStickyNotesHandler;
let res2 = read_handler
.execute(json!({}), state.clone())
.await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
.await
.map_err(|e| crate::error::AppError::Internal(e.to_string()))
.unwrap();
assert!(res2.contains("Buy milk"));
let delete_handler = DeleteStickyNoteHandler;
let args2 = json!({"index": 1});
let res3 = delete_handler.execute(args2, state.clone()).await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
let res3 = delete_handler
.execute(args2, state.clone())
.await
.map_err(|e| crate::error::AppError::Internal(e.to_string()))
.unwrap();
assert_eq!(res3, "Sticky note deleted.");
let res4 = read_handler
.execute(json!({}), state.clone())
.await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
.await
.map_err(|e| crate::error::AppError::Internal(e.to_string()))
.unwrap();
assert!(!res4.contains("Buy milk"));
}
@@ -312,13 +328,19 @@ mod tests {
"namespace": "global"
});
let res = handoff_handler.execute(args, state.clone()).await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
let res = handoff_handler
.execute(args, state.clone())
.await
.map_err(|e| crate::error::AppError::Internal(e.to_string()))
.unwrap();
assert_eq!(res, "Handoff memo left");
let read_handoff = ReadHandoffMemosHandler;
let res2 = read_handoff
.execute(json!({"namespace": "global"}), state.clone())
.await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
.await
.map_err(|e| crate::error::AppError::Internal(e.to_string()))
.unwrap();
assert!(res2.contains("Finished implementing graph tests"));
let summary_handler = AddSessionSummaryHandler;
@@ -328,7 +350,9 @@ mod tests {
});
let res3 = summary_handler
.execute(args_sum, state.clone())
.await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
.await
.map_err(|e| crate::error::AppError::Internal(e.to_string()))
.unwrap();
assert_eq!(res3, "Session summary added");
let standup_handler = GenerateStandupReportHandler;
@@ -337,7 +361,9 @@ mod tests {
json!({"namespace": "global", "hours_lookback": 24}),
state.clone(),
)
.await.map_err(|e| crate::error::AppError::Internal(e.to_string())).unwrap();
.await
.map_err(|e| crate::error::AppError::Internal(e.to_string()))
.unwrap();
assert!(!res4.is_empty());
}
}