summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--makima/src/server/handlers/mesh_chat.rs81
1 files changed, 81 insertions, 0 deletions
diff --git a/makima/src/server/handlers/mesh_chat.rs b/makima/src/server/handlers/mesh_chat.rs
index 638a4d3..134eaa2 100644
--- a/makima/src/server/handlers/mesh_chat.rs
+++ b/makima/src/server/handlers/mesh_chat.rs
@@ -118,6 +118,87 @@ pub async fn mesh_toplevel_chat_handler(
.into_response();
};
+ // Direct message forwarding for task-context messages.
+ // When the user is viewing a specific running task, send their message directly
+ // to the task's Claude instance instead of going through the LLM agentic loop.
+ let context_type = request.context_type.as_deref().unwrap_or("mesh");
+ if context_type == "task" || context_type == "subtask" {
+ if let Some(task_id) = request.context_task_id {
+ if let Ok(Some(task)) =
+ repository::get_task_for_owner(pool, task_id, auth.owner_id).await
+ {
+ if task.status == "running" {
+ if let Some(daemon_id) = task.daemon_id {
+ tracing::info!(
+ task_id = %task_id,
+ daemon_id = %daemon_id,
+ "Direct-sending user message to running task"
+ );
+
+ // Send message directly to running task's Claude instance
+ let cmd = DaemonCommand::SendMessage {
+ task_id,
+ message: request.message.clone(),
+ };
+ let send_result = state.send_daemon_command(daemon_id, cmd).await;
+
+ // Save to chat history
+ let conversation =
+ repository::get_or_create_active_conversation(pool, auth.owner_id)
+ .await;
+ if let Ok(conversation) = conversation {
+ let _ = repository::add_chat_message(
+ pool,
+ conversation.id,
+ "user",
+ &request.message,
+ context_type,
+ Some(task_id),
+ None,
+ None,
+ )
+ .await;
+
+ let response_msg = match &send_result {
+ Ok(_) => format!(
+ "Message sent directly to task {}",
+ &task_id.to_string()[..8]
+ ),
+ Err(e) => format!("Failed to send message to task: {}", e),
+ };
+
+ let _ = repository::add_chat_message(
+ pool,
+ conversation.id,
+ "assistant",
+ &response_msg,
+ context_type,
+ Some(task_id),
+ None,
+ None,
+ )
+ .await;
+ }
+
+ return (
+ StatusCode::OK,
+ Json(MeshChatResponse {
+ response: match send_result {
+ Ok(_) => "Message sent to task".to_string(),
+ Err(e) => format!("Failed to send: {}", e),
+ },
+ tool_calls: vec![],
+ pending_questions: None,
+ }),
+ )
+ .into_response();
+ }
+ }
+ // If task is not running or has no daemon_id, fall through to LLM agentic loop
+ }
+ }
+ }
+
// Parse model selection (default to Claude Sonnet)
let model = request
.model