diff --git a/CLAUDE.md b/CLAUDE.md index 4992db9..8922a0c 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -317,13 +317,17 @@ The workflows app now uses a dramatically simplified agent creation process. No #### **Step 2: Create Individual Template** ```bash -# Copy the starter template +# CORRECT: Start with agent template prototype for reference +# Reference: agent_template_prototype.html (perfect UI patterns) +# Then copy the starter template cp workflows/templates/workflows/agent-template-starter.html workflows/templates/workflows/your-agent.html # Customize the template by replacing: # - Form fields section with your agent-specific inputs # - Processing messages and result titles # - How it works steps (optional) + +# ⚠️ NEVER copy from existing agent templates (leads to bloat!) ``` #### **Step 3: Add Template Mapping** @@ -442,12 +446,84 @@ All agents automatically get access to enhanced WorkflowsCore utilities: - ✅ **Dynamic data** - Agent lists update automatically - ✅ **Simple maintenance** - Easy to understand and modify +## Agent Creation Checklist + +Use this checklist to ensure proper component architecture and avoid legacy contamination: + +### ✅ Pre-Development Checklist +- [ ] Read Template Component Architecture section above +- [ ] Review `agent_template_prototype.html` for UI patterns +- [ ] Understand WorkflowsCore utilities available +- [ ] **Never** open existing agent templates for reference + +### ✅ Development Checklist +- [ ] Start with `agent-template-starter.html` as base +- [ ] Use required component includes: + - [ ] `{% include "workflows/components/agent_header.html" %}` + - [ ] `{% include "workflows/components/quick_agents_panel.html" %}` + - [ ] `{% include "workflows/components/processing_status.html" %}` + - [ ] `{% include "workflows/components/results_container.html" %}` +- [ ] Link to shared CSS: `{% static 'css/agent-base.css' %}` +- [ ] Link to WorkflowsCore: `{% static 'js/workflows-core.js' %}` +- [ ] Write only agent-specific form fields (50-100 lines max) +- [ ] Use WorkflowsCore utilities instead of custom JavaScript + +### ✅ Quality Assurance Checklist +- [ ] Template under 500 lines total +- [ ] Inline JavaScript under 100 lines +- [ ] Agent-specific CSS under 200 lines +- [ ] No duplicate utility functions +- [ ] All shared functionality uses components +- [ ] Copy/download/reset buttons work automatically + +### ❌ Red Flags (Reject if Present) +- [ ] Template over 500 lines +- [ ] Custom `copyResults()` function +- [ ] Custom `downloadResults()` function +- [ ] Custom `showToast()` implementation +- [ ] Inline agent header HTML +- [ ] Inline quick agents panel HTML +- [ ] Duplicate CSS from agent-base.css + +### 📋 Review Questions +1. Does this template follow the component architecture? +2. Could this code be maintained by someone else easily? +3. Would adding a new shared feature require updating this template? +4. Does this template look similar to other agent templates? + +**If any answer is "No", refactor using component architecture.** + ### Template Component Architecture **CRITICAL: Always Use Component-Based Architecture** All agent templates MUST use the established component system. Never recreate shared functionality inline. +**⚠️ WARNING: Avoid Legacy System Contamination** + +When creating new agents, NEVER use existing legacy agent templates as reference. This leads to: +- ❌ 1,000+ line templates instead of clean 300-line templates +- ❌ Duplicate JavaScript instead of WorkflowsCore utilities +- ❌ Inline CSS instead of shared component styles +- ❌ Technical debt imported into clean architecture + +**✅ CORRECT Process for New Agents:** +1. Start with `agent_template_prototype.html` for UI patterns +2. Use Template Component Architecture components +3. Add only agent-specific form fields +4. Leverage WorkflowsCore for all utilities +5. Result: Clean, maintainable templates + +**❌ INCORRECT Process (Legacy Contamination):** +1. Copy from existing working agent template +2. Modify inline code for new functionality +3. Result: Bloated, unmaintainable templates + +**📚 Additional Resources:** +- [Legacy Migration Guide](./docs/development/legacy-migration-guide.md) - How to convert existing agents properly +- [Agent Template Prototype](./agent_template_prototype.html) - Perfect UI reference +- [WorkflowsCore Documentation](./static/js/workflows-core.js) - Shared utility functions + **Required Components for Every Agent:** ```django {% extends 'base.html' %} diff --git a/docs/development/legacy-migration-guide.md b/docs/development/legacy-migration-guide.md new file mode 100644 index 0000000..814eae1 --- /dev/null +++ b/docs/development/legacy-migration-guide.md @@ -0,0 +1,160 @@ +# Legacy Agent Migration Guide + +## Overview + +This guide explains how to properly convert legacy agent templates to the new Template Component Architecture without introducing technical debt or code bloat. + +## ⚠️ The Legacy Contamination Problem + +When converting legacy agents, the natural instinct is to copy existing working code. However, this leads to: + +- **Template Bloat**: 1,000+ line templates instead of 300 lines +- **Duplicate Code**: Custom implementations instead of shared utilities +- **Maintenance Issues**: Multiple copies of the same functionality +- **Architecture Violations**: Inline code instead of component system + +## ✅ Correct Migration Process + +### Step 1: Analyze Legacy Functionality (Don't Copy Code!) + +**DO**: List the functional requirements +``` +- File upload for PDF files +- Radio button selection for analysis type +- Display analysis results with formatting +- Copy, download, reset functionality +``` + +**DON'T**: Copy the implementation code +``` +❌ Never copy 500+ lines of inline JavaScript +❌ Never copy 400+ lines of custom CSS +❌ Never copy custom implementations of shared utilities +``` + +### Step 2: Map to Component Architecture + +**Legacy Approach (Wrong)**: +```django + + + + +``` + +**Component Approach (Right)**: +```django +{% include "workflows/components/agent_header.html" %} +{% include "workflows/components/quick_agents_panel.html" %} + +{% include "workflows/components/processing_status.html" %} +{% include "workflows/components/results_container.html" %} +``` + +### Step 3: Use Agent Template Prototype as Reference + +**Start with**: `agent_template_prototype.html` (perfect UI patterns) +**Not with**: Existing legacy agent template + +The prototype shows exactly how components should work together. + +### Step 4: Implement Only Agent-Specific Logic + +**Keep from Legacy**: +- ✅ Business logic requirements +- ✅ Form field definitions +- ✅ Validation rules +- ✅ API integration patterns + +**Replace with Components**: +- ❌ Header implementation → Use `agent_header.html` +- ❌ Navigation panel → Use `quick_agents_panel.html` +- ❌ Processing display → Use `processing_status.html` +- ❌ Results display → Use `results_container.html` +- ❌ Utility functions → Use `WorkflowsCore` + +## 📊 Migration Results Comparison + +| Aspect | Legacy Approach | Component Approach | Improvement | +|--------|----------------|-------------------|-------------| +| **Template Size** | 1,031 lines | 285 lines | 72% reduction | +| **CSS Lines** | 480+ lines | 145 lines | 70% reduction | +| **JavaScript** | 500+ inline | 150 external | 70% reduction | +| **Maintenance** | Individual updates | Shared component updates | Automatic | +| **Consistency** | Varies per agent | Identical across agents | Perfect | + +## 🎯 Real Example: Data Analyzer Migration + +### Before (Legacy Contamination) +```django + + + + +``` + +### After (Component Architecture) +```django + +{% include "workflows/components/agent_header.html" %} +{% include "workflows/components/quick_agents_panel.html" %} + + +
Analysis completed successfully. Your data has been processed.
'; + } + + if (analysisData.timestamp) { + resultsHtml += `Analysis completed: ${new Date(analysisData.timestamp).toLocaleString()}
`; + } + + WorkflowsCore.showResults(resultsHtml, 'Analysis Results'); + WorkflowsCore.showToast('✅ Data analysis completed successfully!', 'success'); +} + +function isFormValid() { + const fileInput = document.getElementById('dataFile'); + const analysisType = document.querySelector('input[name="analysisType"]:checked'); + + // Clear previous errors + WorkflowsCore.clearFieldError('dataFile'); + WorkflowsCore.clearFieldError('analysisType'); + + let isValid = true; + + if (!fileInput.files || fileInput.files.length === 0) { + WorkflowsCore.showFieldError('dataFile', 'Please select a data file'); + WorkflowsCore.showToast('Please select a data file', 'error'); + isValid = false; + } + + if (!analysisType) { + WorkflowsCore.showFieldError('analysisType', 'Please select an analysis type'); + WorkflowsCore.showToast('Please select an analysis type', 'error'); + isValid = false; + } + + return isValid; +} \ No newline at end of file diff --git a/static/js/workflows-core.js b/static/js/workflows-core.js index bb0af11..c2f0fbc 100644 --- a/static/js/workflows-core.js +++ b/static/js/workflows-core.js @@ -206,8 +206,10 @@ class WorkflowsCore { document.body.removeChild(a); window.URL.revokeObjectURL(url); - // Show success message (file download is good feedback but toast confirms) - this.showToast('💾 ' + successMessage, 'success'); + // Show success message only if provided + if (successMessage && successMessage.trim()) { + this.showToast('💾 ' + successMessage, 'success'); + } } catch (error) { console.error('Download error:', error); this.showToast('❌ Failed to download file', 'error'); @@ -369,7 +371,7 @@ class WorkflowsCore { const content = document.getElementById('resultsContent') || document.querySelector('.results-content'); if (content) { const text = content.textContent || content.innerText || ''; - this.downloadAsFile(text, filename, 'Results downloaded!'); + this.downloadAsFile(text, filename, ''); // No toast message } else { this.showToast('❌ No results to download', 'error'); } @@ -414,7 +416,7 @@ class WorkflowsCore { if (input) input.checked = true; } - this.showToast('🔄 Form reset', 'info'); + // Form reset complete - no toast needed (visual feedback is sufficient) } /** diff --git a/workflows/templates/workflows/data-analyzer.html b/workflows/templates/workflows/data-analyzer.html index 44e8ebd..4c50659 100644 --- a/workflows/templates/workflows/data-analyzer.html +++ b/workflows/templates/workflows/data-analyzer.html @@ -1,200 +1,12 @@ {% extends 'base.html' %} {% load static %} -{# -AGENT TEMPLATE STARTER - Copy this file and customize for new agents - -REPLACE THE FOLLOWING: -1. "Agent Template Starter" -> Your agent name -2. "YOUR_AGENT_SLUG" -> your-agent-slug -3. Form fields in the widget-content section -4. How it works steps (optional) -5. Agent-specific JavaScript (optional) - -KEEP THE FOLLOWING: -- All include statements for shared components -- Basic template structure and CSS links -- Processing and results components -#} - {% block title %}Data Analyzer - Quantum Tasks AI{% endblock %} {% block extra_css %} @@ -493,539 +147,131 @@ document.body.setAttribute('data-agent-price', '{{ agent_config.price }}');