diff options
| author | soryu <soryu@soryu.co> | 2026-01-16 18:46:22 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2026-01-17 05:38:07 +0000 |
| commit | 6b94b5895ed27e3aef052a1843fb3f334397d1b4 (patch) | |
| tree | a55ba3ba6b806efc60cf580e6202cf10666b5992 /makima/src/server/handlers/mesh.rs | |
| parent | 4de5b1857c7ac637b8826ce785e1db97cf0e02e3 (diff) | |
| download | soryu-6b94b5895ed27e3aef052a1843fb3f334397d1b4.tar.gz soryu-6b94b5895ed27e3aef052a1843fb3f334397d1b4.zip | |
Update continue task system and daemon IDs
Diffstat (limited to 'makima/src/server/handlers/mesh.rs')
| -rw-r--r-- | makima/src/server/handlers/mesh.rs | 67 |
1 files changed, 42 insertions, 25 deletions
diff --git a/makima/src/server/handlers/mesh.rs b/makima/src/server/handlers/mesh.rs index 3cd38b5..cdda3fd 100644 --- a/makima/src/server/handlers/mesh.rs +++ b/makima/src/server/handlers/mesh.rs @@ -1847,49 +1847,66 @@ pub struct ReassignTaskResponse { /// Build a conversation context summary from task output entries. /// Returns a formatted string that can be prepended to the task plan. +/// Only includes user and assistant messages - tool use is excluded for cleaner context. +/// Limited to ~4000 characters to avoid bloating the plan. fn build_conversation_context(entries: &[TaskOutputEntry]) -> String { + const MAX_CONTEXT_LEN: usize = 4000; + const MAX_MESSAGE_LEN: usize = 500; + if entries.is_empty() { return String::new(); } - let mut context = String::from("\n\n=== PREVIOUS CONVERSATION CONTEXT ===\n"); - context.push_str("The daemon running this task disconnected. Here is what happened so far:\n\n"); - + // Collect only user and assistant messages + let mut messages: Vec<String> = Vec::new(); for entry in entries.iter() { match entry.message_type.as_str() { "assistant" => { - context.push_str("Assistant: "); // Truncate long messages - let content = if entry.content.len() > 500 { - format!("{}... [truncated]", &entry.content[..500]) + let content = if entry.content.len() > MAX_MESSAGE_LEN { + format!("{}... [truncated]", &entry.content[..MAX_MESSAGE_LEN]) } else { entry.content.clone() }; - context.push_str(&content); - context.push_str("\n\n"); - } - "tool_use" => { - if let Some(ref tool_name) = entry.tool_name { - context.push_str(&format!("[Used tool: {}]\n", tool_name)); - } + messages.push(format!("Assistant: {}\n", content)); } - "tool_result" => { - // Summarize tool results briefly - if entry.content.len() > 200 { - context.push_str(&format!("[Tool result: {}... truncated]\n", &entry.content[..200])); - } else if !entry.content.is_empty() { - context.push_str(&format!("[Tool result: {}]\n", entry.content)); - } - } - "user" => { - context.push_str("User: "); - context.push_str(&entry.content); - context.push_str("\n\n"); + "user" | "user_input" => { + let content = if entry.content.len() > MAX_MESSAGE_LEN { + format!("{}... [truncated]", &entry.content[..MAX_MESSAGE_LEN]) + } else { + entry.content.clone() + }; + messages.push(format!("User: {}\n", content)); } + // Skip tool_use, tool_result, and other message types for cleaner context _ => {} } } + if messages.is_empty() { + return String::new(); + } + + // Build context from the end (most recent messages) up to the max length + let mut context_body = String::new(); + let mut included_count = 0; + for msg in messages.iter().rev() { + if context_body.len() + msg.len() > MAX_CONTEXT_LEN { + break; + } + context_body = format!("{}{}\n", msg, context_body); + included_count += 1; + } + + // If we couldn't include all messages, note how many were skipped + let skipped = messages.len() - included_count; + let mut context = String::from("\n\n=== PREVIOUS CONVERSATION CONTEXT ===\n"); + context.push_str("The daemon running this task disconnected. Here is what happened so far:\n"); + if skipped > 0 { + context.push_str(&format!("(Showing last {} of {} messages)\n", included_count, messages.len())); + } + context.push('\n'); + context.push_str(&context_body); context.push_str("=== END PREVIOUS CONTEXT ===\n\n"); context.push_str("Please continue from where the conversation left off. Do not repeat work that was already done.\n\n"); |
