summaryrefslogtreecommitdiff
path: root/makima/src/server/handlers/chat.rs
diff options
context:
space:
mode:
Diffstat (limited to 'makima/src/server/handlers/chat.rs')
-rw-r--r--makima/src/server/handlers/chat.rs45
1 files changed, 43 insertions, 2 deletions
diff --git a/makima/src/server/handlers/chat.rs b/makima/src/server/handlers/chat.rs
index dfdb64e..9d8cd19 100644
--- a/makima/src/server/handlers/chat.rs
+++ b/makima/src/server/handlers/chat.rs
@@ -245,11 +245,12 @@ pub async fn chat_handler(
## Your Capabilities
You have access to tools for:
- **Viewing content**: view_body (see all elements), read_element (inspect specific element), view_transcript (read full transcript)
-- **Adding content**: add_heading, add_paragraph, add_chart
+- **Adding content**: add_heading, add_paragraph, add_code, add_list, add_chart
- **Modifying content**: update_element, remove_element, reorder_elements, clear_body
- **Document metadata**: set_summary
- **Data processing**: parse_csv (convert CSV to JSON), jq (transform JSON data)
- **Version history**: list_versions, read_version, restore_version
+- **Templates**: suggest_templates (get phase-appropriate templates), apply_template (apply a template structure)
## Agentic Behavior Guidelines
@@ -611,6 +612,7 @@ You have access to tools for:
summary: current_summary.clone(),
body: Some(current_body.clone()),
version: None, // Internal update, skip version check
+ repo_file_path: None,
};
match repository::update_file(pool, id, update_req).await {
@@ -687,7 +689,27 @@ fn build_file_context(file: &crate::db::models::File) -> String {
context.push_str(&format!("Summary: {}\n", summary));
}
- context.push_str(&format!("Transcript entries: {}\n", file.transcript.len()));
+ // Include contract phase context if file belongs to a contract
+ if let Some(ref phase) = file.contract_phase {
+ context.push_str(&format!("\n## Contract Context\n"));
+ context.push_str(&format!("This file belongs to a contract in the '{}' phase.\n", phase));
+ context.push_str("You can use 'suggest_templates' to get phase-appropriate templates, ");
+ context.push_str("or 'apply_template' to apply a template structure.\n");
+ context.push_str(&format!(
+ "Templates for '{}' phase include: {}\n",
+ phase,
+ match phase.as_str() {
+ "research" => "research-notes, competitor-analysis, user-research",
+ "specify" => "requirements, user-stories, acceptance-criteria",
+ "plan" => "architecture, technical-design, task-breakdown",
+ "execute" => "dev-notes, test-plan, implementation-log",
+ "review" => "review-checklist, release-notes, retrospective",
+ _ => "(use suggest_templates to see available)",
+ }
+ ));
+ }
+
+ context.push_str(&format!("\nTranscript entries: {}\n", file.transcript.len()));
context.push_str(&format!("Body elements: {}\n", file.body.len()));
// Add body overview
@@ -727,6 +749,14 @@ fn build_file_context(file: &crate::db::models::File) -> String {
BodyElement::Image { alt, .. } => {
format!("Image{}", alt.as_ref().map(|a| format!(": {}", a)).unwrap_or_default())
}
+ BodyElement::Markdown { content } => {
+ let preview: String = content.chars().take(50).collect();
+ if content.chars().count() > 50 {
+ format!("Markdown: {}...", preview)
+ } else {
+ format!("Markdown: {}", preview)
+ }
+ }
};
context.push_str(&format!(" [{}] {}\n", i, desc));
}
@@ -788,6 +818,9 @@ fn build_focused_element_context(body: &[BodyElement], focused_index: Option<usi
let desc = alt.as_deref().or(caption.as_deref()).unwrap_or("no description");
("Image".to_string(), desc.to_string())
}
+ BodyElement::Markdown { content } => {
+ ("Markdown".to_string(), content.clone())
+ }
};
format!(
@@ -903,6 +936,14 @@ async fn handle_version_request(
BodyElement::Image { alt, .. } => {
format!("Image{}", alt.as_ref().map(|a| format!(": {}", a)).unwrap_or_default())
}
+ BodyElement::Markdown { content } => {
+ let preview: String = content.chars().take(100).collect();
+ if content.chars().count() > 100 {
+ format!("Markdown: {}...", preview)
+ } else {
+ format!("Markdown: {}", preview)
+ }
+ }
};
format!("[{}] {}", i, desc)
})