UNPKG

oneie

Version:

🤝 ONE Personal Collaborative Intelligence - Creates personalized AI workspace from your me.md profile. Simple: npx oneie → edit me.md → generate personalized agents, workflows & missions. From students to enterprises, ONE adapts to your context.

661 lines (546 loc) 22.1 kB
#!/usr/bin/env node /** * Enhanced Template Generation System * Dynamic template creation with deep context detection and personalization */ import fs from 'fs-extra'; import path from 'path'; import yaml from 'js-yaml'; export class TemplateGenerator { constructor(context, architecture, projectPath) { this.context = context; this.architecture = architecture; this.projectPath = projectPath; this.templates = new Map(); } async generateAllTemplates() { await this.generateMissionTemplate(); await this.generateStoryTemplate(); await this.generateTaskTemplate(); await this.generateWorkflowTemplate(); await this.generateAgentConfiguration(); await this.generateSpaceConfiguration(); return this.templates; } async generateMissionTemplate() { const template = { context: this.context.type, template: this.createMissionTemplate(), filename: 'mission-template.md' }; this.templates.set('mission', template); const templatePath = path.join(this.projectPath, '.one/templates/mission-template.md'); await fs.writeFile(templatePath, template.template); } createMissionTemplate() { const contextTemplates = { 'elementary-school': this.createSchoolMissionTemplate(), 'university-research': this.createResearchMissionTemplate(), 'professional-business': this.createBusinessMissionTemplate(), 'government-agency': this.createGovernmentMissionTemplate() }; return contextTemplates[this.context.type] || contextTemplates['professional-business']; } createSchoolMissionTemplate() { const detectedSubjects = this.detectSubjects(); const gradeLevel = this.estimateGradeLevel(); return `# 🎯 Learning Mission Template ## Mission Objective **What do you want to learn or achieve?** - [ ] Complete ${detectedSubjects.length > 0 ? detectedSubjects[0] : 'your subject'} assignment - [ ] Understand new concepts - [ ] Practice problem-solving skills - [ ] Prepare for upcoming test ## Learning Partners **Your AI Study Group:** ${this.context.agents.map(agent => `- 🤖 **${agent}**: ${this.getAgentDescription(agent)}`).join('\n')} ## Success Criteria **How will you know you've succeeded?** - [ ] Assignment completed with good understanding - [ ] Can explain concepts to someone else - [ ] Feel confident about the material - [ ] Ready for next lesson ## Learning Plan **Step by step approach:** 1. **Review** - Look at what you already know 2. **Learn** - Study new material with AI helpers 3. **Practice** - Try problems and get feedback 4. **Review** - Make sure you understand everything ## Fun Factor **Make it enjoyable:** - 🎮 Turn difficult concepts into games - 🏆 Celebrate small wins - 👥 Work together with your AI friends - ✨ Discover cool connections --- *Created by your AI Study Group - Learning Helper, Creative Friend & Study Partner*`; } createResearchMissionTemplate() { const researchArea = this.detectResearchArea(); const methodology = this.suggestMethodology(); return `# 📚 Research Mission Template ## Research Objective **Primary research question:** ${researchArea ? `Focus area: ${researchArea}` : 'Define your research question'} **Hypothesis/Expected outcomes:** - [ ] Literature review complete - [ ] Methodology defined - [ ] Data collection strategy established - [ ] Analysis framework ready ## Research Collaboration Team **Your Academic Partners:** ${this.context.agents.map(agent => `- 🎓 **${agent}**: ${this.getAgentDescription(agent)}`).join('\n')} ## Methodology Framework **Suggested approach: ${methodology}** - [ ] Literature review and gap analysis - [ ] Research design validation - [ ] Data collection protocols - [ ] Analysis and interpretation methods ## Academic Standards **Quality gates:** - [ ] Peer review by AI Research Collaborator - [ ] Methodology validation by expert systems - [ ] Statistical significance confirmed - [ ] Ethical considerations addressed ## Timeline & Milestones - **Week 1-2**: Literature review and theoretical framework - **Week 3-4**: Methodology design and validation - **Week 5-6**: Data collection phase - **Week 7-8**: Analysis and interpretation - **Week 9**: Conclusions and recommendations --- *Academic collaboration with Research Collaborator, Data Analyst & Methodology Guide*`; } createBusinessMissionTemplate() { const businessType = this.detectBusinessType(); const industry = this.detectIndustry(); return `# 🚀 Strategic Business Mission Template ## Business Objective **Strategic goal:** ${businessType ? `Business model: ${businessType}` : 'Define your business objective'} ${industry ? `Industry: ${industry}` : ''} **Key results:** - [ ] Market opportunity validated - [ ] Product-market fit achieved - [ ] Revenue targets met - [ ] Customer satisfaction improved ## Executive Partnership **Your AI Co-Founders:** ${this.context.agents.map(agent => `- 💼 **${agent}**: ${this.getAgentDescription(agent)}`).join('\n')} ## Strategic Framework **Business strategy approach:** - [ ] Market analysis and competitive positioning - [ ] Customer discovery and validation - [ ] Product development and iteration - [ ] Go-to-market strategy execution ## Success Metrics **KPIs to track:** - Revenue growth: ___% target - Customer acquisition: ___ new customers - Market share: ___% target - Customer satisfaction: ___/10 rating ## Execution Plan - **Phase 1**: Foundation and strategy - **Phase 2**: Product development and validation - **Phase 3**: Market launch and scaling - **Phase 4**: Optimization and growth ## Risk Management - [ ] Identify key risks and mitigation strategies - [ ] Establish monitoring and alert systems - [ ] Create contingency plans - [ ] Regular strategy review and adjustment --- *Strategic partnership with Executive Partner, Strategy Analyst & Implementation Lead*`; } createGovernmentMissionTemplate() { return `# 🏛️ Public Service Mission Template ## Public Service Objective **Citizen-focused goal:** [Define the public benefit and service improvement] **Stakeholder impact:** - [ ] Citizens served effectively - [ ] Regulatory compliance maintained - [ ] Transparency standards met - [ ] Public accountability ensured ## Institutional Partnership **Your AI Public Service Team:** ${this.context.agents.map(agent => `- 🏢 **${agent}**: ${this.getAgentDescription(agent)}`).join('\n')} ## Governance Framework **Public service standards:** - [ ] Regulatory compliance verification - [ ] Transparency and accountability measures - [ ] Citizen feedback integration - [ ] Performance measurement systems ## Public Accountability **Transparency measures:** - [ ] Public consultation completed - [ ] Impact assessment published - [ ] Progress reports scheduled - [ ] Citizen feedback channels active ## Implementation Timeline - **Planning Phase**: Stakeholder consultation and requirements - **Development Phase**: Solution design and compliance review - **Testing Phase**: Pilot programs and citizen feedback - **Deployment Phase**: Full implementation and monitoring --- *Public service collaboration with Policy Analyst, Compliance Partner & Public Service Guide*`; } async generateStoryTemplate() { const template = { context: this.context.type, template: this.createStoryTemplate(), filename: 'story-template.md' }; this.templates.set('story', template); const templatePath = path.join(this.projectPath, '.one/templates/story-template.md'); await fs.writeFile(templatePath, template.template); } createStoryTemplate() { const contextPrompts = { 'elementary-school': { title: '📖 Learning Story', description: 'A fun learning adventure with your AI study buddies', participants: 'you and your AI friends', outcome: 'master new skills and have fun learning' }, 'university-research': { title: '🔬 Research Story', description: 'Collaborative academic investigation with peer AI researchers', participants: 'research team including AI collaborators', outcome: 'advance knowledge and contribute to your field' }, 'professional-business': { title: '💼 Business Story', description: 'Strategic business initiative with AI co-founders', participants: 'business team with AI executive partners', outcome: 'achieve business objectives and drive growth' }, 'government-agency': { title: '🏛️ Public Service Story', description: 'Citizen-focused initiative with institutional AI partners', participants: 'public service team with AI policy experts', outcome: 'serve citizens effectively and maintain public trust' } }; const context = contextPrompts[this.context.type] || contextPrompts['professional-business']; return `# ${context.title} Template ## Story Overview **Narrative:** ${context.description} **From Mission:** [Link to parent mission] **Participants:** ${context.participants} - Humans: [] ${this.context.agents.map(agent => `- AI: ${agent}`).join('\n')} ## Story Arc **Beginning:** What situation or opportunity starts this story? **Middle:** What challenges and solutions emerge along the way? **End:** What success looks like when the story concludes? ## Collaborative Elements **Human Contributions:** - [ ] Strategic decisions and creative insights - [ ] Domain expertise and intuition - [ ] Stakeholder relationships and communication **AI Contributions:** - [ ] Data analysis and pattern recognition - [ ] 24/7 availability and consistent execution - [ ] Rapid prototyping and iteration ## Success Criteria **Story completion requires:** - [ ] All participants agree on outcomes - [ ] Quality standards met through peer review - [ ] Knowledge captured and documented - [ ] Lessons learned integrated for future stories ## Conversation Threads **Active dialogues:** - Main planning conversation: [link] - Technical discussion: [link] - Review and validation: [link] ## Story Outcome **Expected result:** ${context.outcome} **Next story possibilities:** - [ ] Follow-up story based on results - [ ] Parallel story for related objectives - [ ] Spin-off story for new opportunities --- *${this.context.style.replace('_', ' ')} between humans and AI agents*`; } async generateTaskTemplate() { const template = { context: this.context.type, template: this.createTaskTemplate(), filename: 'task-template.md' }; this.templates.set('task', template); const templatePath = path.join(this.projectPath, '.one/templates/task-template.md'); await fs.writeFile(templatePath, template.template); } createTaskTemplate() { const contextTasks = { 'elementary-school': 'learning activity', 'university-research': 'research task', 'professional-business': 'business task', 'government-agency': 'public service task' }; const taskType = contextTasks[this.context.type] || 'collaborative task'; return `# ✅ Task Template ## Task Details **Type:** ${taskType} **From Story:** [Link to parent story] **Assigned to:** [Human and/or AI agent] **Priority:** [High/Medium/Low] **Estimated effort:** [Time estimate] ## Task Description **What needs to be done:** [Clear, specific description of the task] **Why it matters:** [Connection to story and mission objectives] ## Acceptance Criteria **Task is complete when:** - [ ] Specific deliverable 1 completed - [ ] Specific deliverable 2 completed - [ ] Quality review passed - [ ] Documentation updated ## Collaboration Approach **Human role:** [What the human contributor focuses on] **AI agent role:** [What the AI agent contributes] **Consensus required on:** - [ ] Approach and methodology - [ ] Quality standards met - [ ] Completion criteria satisfied ## Resources Needed - [ ] Information/data: [specify] - [ ] Tools/software: [specify] - [ ] People/expertise: [specify] - [ ] Time/availability: [specify] ## Dependencies **Blocked by:** [Other tasks that must complete first] **Blocking:** [Tasks waiting for this to complete] ## Progress Tracking - **Started:** [date] - **Key milestones:** - [ ] Milestone 1: [description] - [target date] - [ ] Milestone 2: [description] - [target date] - **Completed:** [date] ## Notes & Insights **Conversation log:** [Link to task discussion thread] **Lessons learned:** [Captured during and after completion] **Recommendations:** [For similar future tasks] --- *Collaborative execution with equal human-AI participation*`; } async generateWorkflowTemplate() { const workflow = this.createWorkflowConfiguration(); const templatePath = path.join(this.projectPath, '.one/templates/workflow-template.yaml'); await fs.writeFile(templatePath, yaml.dump(workflow)); this.templates.set('workflow', { context: this.context.type, template: workflow }); } createWorkflowConfiguration() { return { name: `${this.context.type}-workflow`, description: `Collaborative workflow optimized for ${this.context.type} context`, version: '1.0.0', workflow_type: this.context.type, participants: { humans: [], ai_agents: this.context.agents }, phases: this.createWorkflowPhases(), collaboration_rules: { consensus_required: true, equal_participation: true, quality_gates: this.createQualityGates(), communication_style: this.context.tone }, success_metrics: this.createSuccessMetrics() }; } createWorkflowPhases() { const phaseTemplates = { 'elementary-school': [ { name: 'understand', duration: '30 minutes', description: 'Make sure we understand what to learn' }, { name: 'explore', duration: '45 minutes', description: 'Discover and learn new things together' }, { name: 'practice', duration: '60 minutes', description: 'Try problems and get better' }, { name: 'celebrate', duration: '15 minutes', description: 'Share what we learned and celebrate!' } ], 'university-research': [ { name: 'literature_review', duration: '2-3 weeks', description: 'Comprehensive analysis of existing research' }, { name: 'methodology_design', duration: '1-2 weeks', description: 'Research design and validation' }, { name: 'data_collection', duration: '3-4 weeks', description: 'Systematic data gathering' }, { name: 'analysis', duration: '2-3 weeks', description: 'Statistical analysis and interpretation' }, { name: 'publication', duration: '2-3 weeks', description: 'Results documentation and peer review' } ], 'professional-business': [ { name: 'strategy', duration: '1-2 weeks', description: 'Strategic planning and market analysis' }, { name: 'development', duration: '4-6 weeks', description: 'Product/service development' }, { name: 'validation', duration: '2-3 weeks', description: 'Market validation and testing' }, { name: 'launch', duration: '2-3 weeks', description: 'Go-to-market execution' }, { name: 'optimization', duration: 'ongoing', description: 'Performance monitoring and improvement' } ], 'government-agency': [ { name: 'consultation', duration: '3-4 weeks', description: 'Stakeholder engagement and requirements' }, { name: 'compliance_review', duration: '2-3 weeks', description: 'Regulatory and policy compliance' }, { name: 'development', duration: '6-8 weeks', description: 'Solution development and testing' }, { name: 'pilot', duration: '4-6 weeks', description: 'Pilot program and citizen feedback' }, { name: 'deployment', duration: '2-3 weeks', description: 'Full implementation and monitoring' } ] }; return phaseTemplates[this.context.type] || phaseTemplates['professional-business']; } createQualityGates() { const qualityTemplates = { 'elementary-school': [ 'understanding_verified', 'practice_completed', 'ai_helper_approval', 'learning_celebrated' ], 'university-research': [ 'literature_review_complete', 'methodology_validated', 'data_quality_assured', 'peer_review_passed' ], 'professional-business': [ 'market_validation_complete', 'product_quality_verified', 'business_metrics_achieved', 'stakeholder_approval' ], 'government-agency': [ 'regulatory_compliance_verified', 'public_consultation_complete', 'transparency_standards_met', 'citizen_impact_measured' ] }; return qualityTemplates[this.context.type] || qualityTemplates['professional-business']; } createSuccessMetrics() { const metricsTemplates = { 'elementary-school': [ 'understanding_level', 'problem_solving_improvement', 'confidence_gained', 'fun_factor_rating' ], 'university-research': [ 'research_contribution_significance', 'methodology_innovation', 'peer_review_scores', 'citation_potential' ], 'professional-business': [ 'revenue_growth', 'customer_satisfaction', 'market_share_increase', 'team_productivity' ], 'government-agency': [ 'citizen_satisfaction', 'service_efficiency', 'compliance_score', 'transparency_rating' ] }; return metricsTemplates[this.context.type] || metricsTemplates['professional-business']; } // Context detection helpers detectSubjects() { const subjectKeywords = { 'math': ['math', 'algebra', 'geometry', 'calculus', 'statistics'], 'science': ['biology', 'chemistry', 'physics', 'science'], 'english': ['english', 'literature', 'writing', 'essay'], 'history': ['history', 'social', 'studies', 'government'], 'computer': ['programming', 'coding', 'computer', 'technology'] }; const detectedSubjects = []; const fileNames = this.architecture.files.map(f => f.toLowerCase()); for (const [subject, keywords] of Object.entries(subjectKeywords)) { if (keywords.some(keyword => fileNames.some(file => file.includes(keyword)))) { detectedSubjects.push(subject); } } return detectedSubjects; } estimateGradeLevel() { // Simple heuristic based on folder structure and file complexity if (this.architecture.files.some(f => f.includes('elementary') || f.includes('basic'))) { return 'elementary'; } if (this.architecture.files.some(f => f.includes('middle') || f.includes('intermediate'))) { return 'middle_school'; } if (this.architecture.files.some(f => f.includes('high') || f.includes('advanced'))) { return 'high_school'; } return 'general'; } detectResearchArea() { const researchKeywords = [ 'machine-learning', 'artificial-intelligence', 'data-science', 'psychology', 'sociology', 'economics', 'biology', 'chemistry', 'physics', 'computer-science', 'engineering', 'medicine' ]; const fileNames = this.architecture.files.map(f => f.toLowerCase()); const detectedAreas = researchKeywords.filter(area => fileNames.some(file => file.includes(area.replace('-', ''))) ); return detectedAreas[0] || null; } suggestMethodology() { const hasData = this.architecture.files.some(f => f.toLowerCase().includes('data') || f.endsWith('.csv') || f.endsWith('.json') ); const hasCode = this.architecture.files.some(f => f.endsWith('.py') || f.endsWith('.r') || f.endsWith('.js') ); if (hasData && hasCode) return 'quantitative_analysis'; if (hasData) return 'data_driven_research'; if (hasCode) return 'computational_research'; return 'qualitative_research'; } detectBusinessType() { const businessKeywords = { 'saas': ['saas', 'software', 'api', 'platform'], 'ecommerce': ['shop', 'store', 'product', 'inventory', 'cart'], 'consulting': ['consulting', 'service', 'client', 'advisory'], 'startup': ['startup', 'mvp', 'prototype', 'funding'] }; const fileNames = this.architecture.files.map(f => f.toLowerCase()); for (const [type, keywords] of Object.entries(businessKeywords)) { if (keywords.some(keyword => fileNames.some(file => file.includes(keyword)))) { return type; } } return null; } detectIndustry() { const industries = [ 'fintech', 'healthcare', 'education', 'retail', 'manufacturing', 'real-estate', 'entertainment', 'automotive', 'agriculture' ]; const fileNames = this.architecture.files.map(f => f.toLowerCase()); const detectedIndustry = industries.find(industry => fileNames.some(file => file.includes(industry)) ); return detectedIndustry || null; } getAgentDescription(agent) { const descriptions = { 'Learning Helper': 'Patient guide for understanding difficult concepts', 'Creative Friend': 'Makes learning fun with games and creative activities', 'Study Partner': 'Peer-level support for homework and practice', 'Research Collaborator': 'Academic peer for methodology and analysis', 'Data Analyst': 'Statistical analysis and data interpretation expert', 'Methodology Guide': 'Research design and validation specialist', 'Executive Partner': 'Strategic business decisions and leadership', 'Strategy Analyst': 'Market analysis and competitive intelligence', 'Implementation Lead': 'Execution coordination and project management', 'Policy Analyst': 'Regulatory compliance and governance expert', 'Compliance Partner': 'Risk management and audit support', 'Public Service Guide': 'Citizen-focused service delivery optimization' }; return descriptions[agent] || 'Collaborative AI partner'; } }