diff --git a/backend/src/services/mistralClient.js b/backend/src/services/mistralClient.js
index 5d76744..a15005a 100644
--- a/backend/src/services/mistralClient.js
+++ b/backend/src/services/mistralClient.js
@@ -20,10 +20,11 @@ Your responsibilities:
3. Provide your thinking process and reasoning
4. Return ONLY the section (modified or new) with its header, or command to delete, or confirm it's good as-is
-IMPORTANT RULES:
+CRITICAL RULES - FOLLOW THESE EXACTLY:
- Work on exactly ONE section only
-- Never modify the entire document
-- Return only the section you're working on, not the whole document
+- NEVER return the entire document
+- NEVER return multiple sections
+- Return ONLY the section you're working on, not the whole document
- You CAN create a new section if document is missing important content
- You CAN delete a section if it's redundant, duplicate, or not useful
- To delete a section, respond: "DELETE: ## Section Name" (with exact header)
@@ -31,11 +32,21 @@ IMPORTANT RULES:
- Think step-by-step about what could be improved or removed
- Share your reasoning process
-Format your response as:
-THINKING: [Your analysis and reasoning]
-DECISION: [What you'll modify, create, delete, or if keeping as-is]
+RESPONSE FORMAT - FOLLOW THIS EXACTLY:
+THINKING: [Your analysis and reasoning about the current document]
+DECISION: [Exactly what you will do: modify section X, create new section Y, delete section Z, or keep as-is]
SECTION:
-[The modified section, new section, DELETE command, or confirmation that all is good]`
+[ONLY ONE: Either a markdown section starting with # or ##, a DELETE command, or the text "Section is good, no changes needed"]
+
+EXAMPLE OF CORRECT RESPONSE:
+THINKING: The Overview section is too brief and doesn't explain the main purpose.
+DECISION: I will modify the Overview section to be more comprehensive.
+SECTION:
+## Overview
+This is a technical document for designing system architecture...
+
+EXAMPLE OF INCORRECT RESPONSE (DO NOT DO THIS):
+[The entire document repeated here] <- WRONG!`
}
/**
@@ -102,13 +113,32 @@ export async function generateAgentResponseSync(agentName, prompt, currentDocume
/**
* Extract section from AI response
+ * Validates that we get a proper section, not the entire document
*/
export function extractSection(aiResponse) {
- const sectionMatch = aiResponse.match(/SECTION:\s*([\s\S]*?)(?:$|THINKING:|DECISION:)/)
+ const sectionMatch = aiResponse.match(/SECTION:\s*([\s\S]*?)(?:$)/)
if (sectionMatch) {
- return sectionMatch[1].trim()
+ const extracted = sectionMatch[1].trim()
+
+ // Validate: extracted should be either:
+ // 1. A markdown section starting with # (DELETE: or "Section is good...")
+ // 2. OR a single section with < 5000 chars (not entire document)
+ const isMarkdownSection = /^(#|DELETE:|Section is good)/.test(extracted)
+ const isShortEnough = extracted.length < 5000 // Single section should be < 5KB
+
+ if (isMarkdownSection || isShortEnough) {
+ return extracted
+ }
}
- return aiResponse
+
+ // Fallback: if no SECTION: tag found, treat entire response as section
+ // but only if it starts with markdown header or is a command
+ if (/^(#|DELETE:|Section is good)/.test(aiResponse)) {
+ return aiResponse.trim()
+ }
+
+ // If none of the above, return error indicator
+ return "ERROR: Response does not contain a valid section format"
}
/**
diff --git a/frontend/src/components/CollaborativeInput.vue b/frontend/src/components/CollaborativeInput.vue
index 68478a3..54c2e18 100644
--- a/frontend/src/components/CollaborativeInput.vue
+++ b/frontend/src/components/CollaborativeInput.vue
@@ -327,6 +327,46 @@ const removeFile = () => {
+
+