Spaces:
Sleeping
Sleeping
| import logger from '../utils/logger.js'; | |
| class MultiRoleDeveloper { | |
| constructor(config, memory) { | |
| this.config = config; | |
| this.memory = memory; | |
| this.roles = { | |
| frontend: { | |
| name: 'Frontend Developer', | |
| level: 'senior', | |
| focus: ['UI components', 'styling', 'user experience', 'accessibility', 'responsive design', 'state management', 'performance optimization'], | |
| technologies: ['React', 'Vue', 'Angular', 'CSS', 'HTML', 'TypeScript', 'Tailwind', 'Webpack', 'Vite', 'Next.js'], | |
| personality: 'يهتم بالتفاصيل البصرية وتجربة المستخدم، يتحدث عن design systems و accessibility', | |
| phrases: [ | |
| 'The UX feels much better now', | |
| 'Added proper ARIA labels for accessibility', | |
| 'Made it responsive for mobile', | |
| 'The design system is consistent now', | |
| 'Improved the component reusability', | |
| 'Added proper loading states', | |
| 'Optimized the render performance', | |
| 'Fixed the layout shift issue', | |
| ], | |
| workingHours: { start: 9, end: 18, peak: [10, 11, 14, 15] }, | |
| communicationStyle: 'visual', | |
| }, | |
| backend: { | |
| name: 'Backend Developer', | |
| level: 'senior', | |
| focus: ['APIs', 'databases', 'authentication', 'performance', 'scalability', 'microservices', 'caching'], | |
| technologies: ['Node.js', 'Express', 'PostgreSQL', 'MongoDB', 'Redis', 'GraphQL', 'REST', 'Docker', 'Kafka'], | |
| personality: 'يركز على البنية والأداء والأمان، يتحدث عن architecture patterns', | |
| phrases: [ | |
| 'Optimized the query to reduce N+1', | |
| 'Added proper error handling', | |
| 'The API response time improved', | |
| 'Database indexing should help', | |
| 'Added proper input validation', | |
| 'Implemented caching layer', | |
| 'Refactored the service layer', | |
| 'Added rate limiting', | |
| ], | |
| workingHours: { start: 8, end: 17, peak: [9, 10, 14, 15] }, | |
| communicationStyle: 'technical', | |
| }, | |
| devops: { | |
| name: 'DevOps Engineer', | |
| level: 'senior', | |
| focus: ['CI/CD', 'infrastructure', 'monitoring', 'automation', 'containers', 'cloud', 'observability'], | |
| technologies: ['Docker', 'Kubernetes', 'GitHub Actions', 'Terraform', 'AWS', 'Nginx', 'Prometheus', 'Grafana'], | |
| personality: 'يهتم بالبنية التحتية والأتمتة، يتحدث عن reliability و deployment', | |
| phrases: [ | |
| 'CI pipeline is green now', | |
| 'Docker image size reduced', | |
| 'Added health checks', | |
| 'Deployment should be smoother', | |
| 'Infrastructure as code updated', | |
| 'Monitoring alerts configured', | |
| 'Auto-scaling is working', | |
| 'Rollback plan is ready', | |
| ], | |
| workingHours: { start: 7, end: 16, peak: [8, 9, 13, 14] }, | |
| communicationStyle: 'practical', | |
| }, | |
| data: { | |
| name: 'Data Engineer/Scientist', | |
| level: 'senior', | |
| focus: ['data pipelines', 'analytics', 'ML models', 'visualization', 'ETL', 'data quality', 'feature engineering'], | |
| technologies: ['Python', 'Pandas', 'TensorFlow', 'SQL', 'Spark', 'Airflow', 'dbt', 'Tableau'], | |
| personality: 'يفكر في البيانات والتحليلات، يتحدث عن data quality و model performance', | |
| phrases: [ | |
| 'Data quality checks pass', | |
| 'The pipeline handles edge cases', | |
| 'Model accuracy improved', | |
| 'Added proper data validation', | |
| 'ETL job optimized', | |
| 'Dashboard updated with new metrics', | |
| 'Feature engineering complete', | |
| 'Data schema migrated', | |
| ], | |
| workingHours: { start: 9, end: 18, peak: [10, 11, 15, 16] }, | |
| communicationStyle: 'analytical', | |
| }, | |
| cybersecurity: { | |
| name: 'Security Engineer', | |
| level: 'senior', | |
| focus: ['vulnerability assessment', 'penetration testing', 'security audits', 'compliance', 'incident response', 'threat modeling'], | |
| technologies: ['OWASP', 'SAST', 'DAST', 'encryption', 'firewalls', 'SIEM', 'Burp Suite', 'Metasploit'], | |
| personality: 'دائماً قلق من الثغرات الأمنية، يتحدث عن best practices و compliance', | |
| phrases: [ | |
| 'Fixed the XSS vulnerability', | |
| 'Added input sanitization', | |
| 'Dependencies are up to date', | |
| 'Security audit passed', | |
| 'Rate limiting implemented', | |
| 'CSRF protection added', | |
| 'Encryption at rest enabled', | |
| 'Security headers configured', | |
| ], | |
| workingHours: { start: 8, end: 17, peak: [9, 10, 14, 15] }, | |
| communicationStyle: 'cautious', | |
| }, | |
| ai: { | |
| name: 'AI/ML Engineer', | |
| level: 'senior', | |
| focus: ['model training', 'prompt engineering', 'LLM integration', 'RAG', 'agents', 'fine-tuning', 'evaluation'], | |
| technologies: ['PyTorch', 'Transformers', 'LangChain', 'Ollama', 'OpenAI API', 'HuggingFace', 'Weights & Biases'], | |
| personality: 'متحمس للذكاء الاصطناعي، يتحدث عن model capabilities و limitations', | |
| phrases: [ | |
| 'The model handles edge cases better', | |
| 'Prompt engineering improved results', | |
| 'RAG pipeline is working', | |
| 'Added proper fallbacks', | |
| 'Context window optimized', | |
| 'Vector search improved', | |
| 'Model evaluation complete', | |
| 'Fine-tuning results look good', | |
| ], | |
| workingHours: { start: 10, end: 19, peak: [11, 12, 15, 16] }, | |
| communicationStyle: 'innovative', | |
| }, | |
| analyst: { | |
| name: 'Business Analyst', | |
| level: 'senior', | |
| focus: ['requirements', 'user stories', 'documentation', 'processes', 'stakeholders', 'metrics', 'roadmap'], | |
| technologies: ['Jira', 'Confluence', 'diagrams', 'user research', 'A/B testing', 'SQL', 'Looker'], | |
| personality: 'يركز على احتياجات العمل والمستخدمين، يتحدث عن requirements و priorities', | |
| phrases: [ | |
| 'Requirements are clear now', | |
| 'Added acceptance criteria', | |
| 'Documentation is up to date', | |
| 'User stories are ready', | |
| 'Stakeholder feedback incorporated', | |
| 'Process flow documented', | |
| 'Metrics dashboard ready', | |
| 'Sprint planning complete', | |
| ], | |
| workingHours: { start: 9, end: 17, peak: [10, 11, 14, 15] }, | |
| communicationStyle: 'organized', | |
| }, | |
| mobile: { | |
| name: 'Mobile Developer', | |
| level: 'senior', | |
| focus: ['iOS', 'Android', 'cross-platform', 'app performance', 'offline support', 'push notifications'], | |
| technologies: ['React Native', 'Flutter', 'Swift', 'Kotlin', 'Xcode', 'Android Studio', 'Firebase'], | |
| personality: 'يهتم بتجربة المستخدم على الموبايل، يتحدث عن app store guidelines', | |
| phrases: [ | |
| 'App bundle size optimized', | |
| 'Offline mode is working', | |
| 'Push notifications configured', | |
| 'App store submission ready', | |
| 'Memory leak fixed', | |
| 'Animation performance improved', | |
| 'Deep linking implemented', | |
| 'Battery usage optimized', | |
| ], | |
| workingHours: { start: 9, end: 18, peak: [10, 11, 14, 15] }, | |
| communicationStyle: 'mobile-focused', | |
| }, | |
| qa: { | |
| name: 'QA Engineer', | |
| level: 'senior', | |
| focus: ['test automation', 'manual testing', 'performance testing', 'regression testing', 'test coverage'], | |
| technologies: ['Jest', 'Cypress', 'Playwright', 'Selenium', 'Postman', 'k6', 'TestRail'], | |
| personality: 'دقيق ومهتم بالجودة، يبحث عن edge cases و bugs', | |
| phrases: [ | |
| 'Test coverage increased to 85%', | |
| 'Found 3 edge cases', | |
| 'Regression tests pass', | |
| 'Performance benchmarks updated', | |
| 'E2E tests are stable', | |
| 'Bug report filed', | |
| 'Test data refreshed', | |
| 'CI tests are green', | |
| ], | |
| workingHours: { start: 9, end: 17, peak: [10, 11, 14, 15] }, | |
| communicationStyle: 'detail-oriented', | |
| }, | |
| architect: { | |
| name: 'Software Architect', | |
| level: 'principal', | |
| focus: ['system design', 'architecture patterns', 'technical decisions', 'scalability', 'trade-offs'], | |
| technologies: ['microservices', 'event-driven', 'CQRS', 'DDD', 'design patterns', 'cloud architecture'], | |
| personality: 'يفكر في الصورة الكبيرة، يتحدث عن trade-offs و long-term decisions', | |
| phrases: [ | |
| 'Architecture decision recorded', | |
| 'Trade-offs documented', | |
| 'System design reviewed', | |
| 'Scalability plan ready', | |
| 'Technical debt tracked', | |
| 'Migration strategy defined', | |
| 'API contract finalized', | |
| 'Service boundaries clear', | |
| ], | |
| workingHours: { start: 8, end: 17, peak: [9, 10, 14, 15] }, | |
| communicationStyle: 'strategic', | |
| }, | |
| fullstack: { | |
| name: 'Full-Stack Developer', | |
| level: 'senior', | |
| focus: ['end-to-end features', 'API design', 'UI/UX', 'database', 'deployment'], | |
| technologies: ['React', 'Node.js', 'PostgreSQL', 'Docker', 'AWS', 'TypeScript', 'GraphQL'], | |
| personality: 'يعمل على كل شيء من الواجهة لقاعدة البيانات، يتحدث عن complete solutions', | |
| phrases: [ | |
| 'Full implementation is done', | |
| 'Both frontend and backend are ready', | |
| 'Integration tests pass', | |
| 'End-to-end flow works', | |
| 'Database migration complete', | |
| 'API and UI are in sync', | |
| 'Deployment pipeline ready', | |
| 'Feature flag configured', | |
| ], | |
| workingHours: { start: 9, end: 18, peak: [10, 11, 14, 15] }, | |
| communicationStyle: 'versatile', | |
| }, | |
| techlead: { | |
| name: 'Tech Lead', | |
| level: 'lead', | |
| focus: ['team coordination', 'code reviews', 'technical direction', 'mentoring', 'project planning'], | |
| technologies: ['all-stack', 'project management', 'code review tools', 'CI/CD'], | |
| personality: 'يقود الفريق تقنياً، يتحدث عن team goals و technical excellence', | |
| phrases: [ | |
| 'Code review complete', | |
| 'Technical direction set', | |
| 'Team sync done', | |
| 'Sprint goals met', | |
| 'Mentoring session complete', | |
| 'Architecture review done', | |
| 'Release plan ready', | |
| 'Tech debt prioritized', | |
| ], | |
| workingHours: { start: 8, end: 17, peak: [9, 10, 14, 15] }, | |
| communicationStyle: 'leadership', | |
| }, | |
| platform: { | |
| name: 'Platform Engineer', | |
| level: 'senior', | |
| focus: ['developer experience', 'internal tools', 'platform reliability', 'self-service'], | |
| technologies: ['Kubernetes', 'Terraform', 'Backstage', 'ArgoCD', 'Helm', 'GitHub Actions'], | |
| personality: 'يبني المنصات الداخلية، يتحدث عن developer productivity', | |
| phrases: [ | |
| 'Developer portal updated', | |
| 'Self-service pipeline ready', | |
| 'Platform reliability improved', | |
| 'Internal tool deployed', | |
| 'Onboarding process streamlined', | |
| 'Infrastructure templates ready', | |
| 'Platform metrics dashboard live', | |
| 'Golden path documented', | |
| ], | |
| workingHours: { start: 8, end: 17, peak: [9, 10, 14, 15] }, | |
| communicationStyle: 'platform-focused', | |
| }, | |
| sre: { | |
| name: 'Site Reliability Engineer', | |
| level: 'senior', | |
| focus: ['reliability', 'incident management', 'SLOs', 'capacity planning', 'chaos engineering'], | |
| technologies: ['Prometheus', 'Grafana', 'PagerDuty', 'Terraform', 'Kubernetes', 'Chaos Monkey'], | |
| personality: 'مهتم بالموثوقية والاستقرار، يتحدث عن SLOs و incident response', | |
| phrases: [ | |
| 'SLOs are met', | |
| 'Incident response plan updated', | |
| 'Capacity planning complete', | |
| 'Chaos test passed', | |
| 'Alert fatigue reduced', | |
| 'Runbook documented', | |
| 'Post-mortem complete', | |
| 'Error budget healthy', | |
| ], | |
| workingHours: { start: 7, end: 16, peak: [8, 9, 13, 14] }, | |
| communicationStyle: 'reliability-focused', | |
| }, | |
| }; | |
| this.currentRole = 'fullstack'; | |
| this.roleWeights = {}; | |
| this._personalityTraits = { | |
| communicationFrequency: 0.5, | |
| codeReviewStrictness: 0.5, | |
| riskTolerance: 0.5, | |
| collaborationLevel: 0.7, | |
| documentationHabit: 0.6, | |
| testingHabit: 0.5, | |
| }; | |
| } | |
| async initialize() { | |
| const savedRole = this.memory.recall('currentRole'); | |
| if (savedRole && this.roles[savedRole]) { | |
| this.currentRole = savedRole; | |
| } else { | |
| this.currentRole = 'fullstack'; | |
| } | |
| this.roleWeights = this.memory.recall('roleWeights') || this._getDefaultWeights(); | |
| const savedTraits = this.memory.recall('personalityTraits'); | |
| if (savedTraits) { | |
| this._personalityTraits = { ...this._personalityTraits, ...savedTraits }; | |
| } | |
| logger.info(`Developer role initialized: ${this.currentRole} (${this.roles[this.currentRole].level})`); | |
| } | |
| _getDefaultWeights() { | |
| return { | |
| frontend: 0.1, | |
| backend: 0.15, | |
| devops: 0.1, | |
| data: 0.05, | |
| cybersecurity: 0.05, | |
| ai: 0.1, | |
| analyst: 0.05, | |
| mobile: 0.05, | |
| qa: 0.05, | |
| architect: 0.05, | |
| fullstack: 0.15, | |
| techlead: 0.05, | |
| platform: 0.03, | |
| sre: 0.02, | |
| }; | |
| } | |
| getRole(roleName = null) { | |
| const role = roleName || this.currentRole; | |
| return this.roles[role] || this.roles.fullstack; | |
| } | |
| getCurrentRole() { | |
| return this.getRole(); | |
| } | |
| async adaptRoleFromContext(projectType, recentActivity) { | |
| const typeMap = { | |
| react: 'frontend', | |
| vue: 'frontend', | |
| angular: 'frontend', | |
| nextjs: 'frontend', | |
| 'react-native': 'mobile', | |
| flutter: 'mobile', | |
| swift: 'mobile', | |
| kotlin: 'mobile', | |
| express: 'backend', | |
| django: 'backend', | |
| flask: 'backend', | |
| spring: 'backend', | |
| docker: 'devops', | |
| kubernetes: 'devops', | |
| terraform: 'devops', | |
| tensorflow: 'ai', | |
| pytorch: 'ai', | |
| pandas: 'data', | |
| spark: 'data', | |
| security: 'cybersecurity', | |
| owasp: 'cybersecurity', | |
| jest: 'qa', | |
| cypress: 'qa', | |
| playwright: 'qa', | |
| prometheus: 'sre', | |
| grafana: 'sre', | |
| backstage: 'platform', | |
| argocd: 'platform', | |
| }; | |
| let detectedRole = 'fullstack'; | |
| if (projectType) { | |
| for (const [keyword, role] of Object.entries(typeMap)) { | |
| if (projectType.toLowerCase().includes(keyword)) { | |
| detectedRole = role; | |
| break; | |
| } | |
| } | |
| } | |
| if (recentActivity?.length > 0) { | |
| const recentFiles = recentActivity.slice(0, 10); | |
| const filePatterns = { | |
| frontend: [/\.css$/, /\.tsx?$/, /\.vue$/, /components\//, /pages\//, /styles\//], | |
| backend: [/api\//, /controllers\//, /models\//, /routes\//, /services\//], | |
| devops: [/Dockerfile/, /\.yml$/, /\.yaml$/, /terraform/, /k8s\//, /deploy\//], | |
| data: [/\.ipynb$/, /data\//, /notebooks\//, /analysis\//, /etl\//], | |
| cybersecurity: [/security\//, /auth\//, /middleware\//, /validation\//], | |
| ai: [/models\//, /prompts\//, /agents\//, /llm\//, /training\//], | |
| mobile: [/\.swift$/, /\.kt$/, /ios\//, /android\//, /mobile\//], | |
| qa: [/\.test\./, /\.spec\./, /tests\//, /cypress\//, /e2e\//], | |
| sre: [/monitoring\//, /alerting\//, /slo\//, /incident\//], | |
| platform: [/platform\//, /internal\//, /backstage\//, /templates\//], | |
| }; | |
| const roleCounts = {}; | |
| for (const file of recentFiles) { | |
| const filePath = file.path || file.filename || ''; | |
| for (const [role, patterns] of Object.entries(filePatterns)) { | |
| if (patterns.some(p => p.test(filePath))) { | |
| roleCounts[role] = (roleCounts[role] || 0) + 1; | |
| } | |
| } | |
| } | |
| if (Object.keys(roleCounts).length > 0) { | |
| detectedRole = Object.entries(roleCounts).sort((a, b) => b[1] - a[1])[0][0]; | |
| } | |
| } | |
| if (detectedRole !== this.currentRole && this.roles[detectedRole]) { | |
| logger.info(`Role adapting: ${this.currentRole} → ${detectedRole}`); | |
| this.currentRole = detectedRole; | |
| this.memory.remember('currentRole', detectedRole); | |
| this.updateRoleWeights(detectedRole, 'up'); | |
| } | |
| return this.currentRole; | |
| } | |
| getRoleContext() { | |
| const role = this.getCurrentRole(); | |
| return { | |
| role: role.name, | |
| level: role.level, | |
| focus: role.focus, | |
| technologies: role.technologies, | |
| personality: role.personality, | |
| phrases: role.phrases || [], | |
| workingHours: role.workingHours, | |
| communicationStyle: role.communicationStyle, | |
| }; | |
| } | |
| getRoleBasedAction() { | |
| const role = this.getCurrentRole(); | |
| const actions = { | |
| frontend: ['create-component', 'fix-ui-bug', 'improve-accessibility', 'add-styling', 'optimize-render', 'add-loading-state', 'fix-layout-shift'], | |
| backend: ['add-api-endpoint', 'fix-database-query', 'add-validation', 'optimize-performance', 'add-auth', 'add-caching', 'refactor-service'], | |
| devops: ['update-ci-cd', 'fix-docker-config', 'add-monitoring', 'update-infra', 'optimize-build', 'add-health-checks', 'configure-alerts'], | |
| data: ['add-pipeline', 'fix-data-quality', 'add-analysis', 'update-model', 'create-visualization', 'optimize-etl', 'add-data-validation'], | |
| cybersecurity: ['fix-vulnerability', 'add-security-check', 'update-dependencies', 'audit-code', 'add-encryption', 'add-rate-limiting', 'fix-csrf'], | |
| ai: ['add-model', 'improve-prompt', 'add-rag-pipeline', 'fine-tune-model', 'add-agent', 'add-evaluation', 'optimize-context'], | |
| analyst: ['add-documentation', 'update-requirements', 'create-user-story', 'add-test-cases', 'update-process', 'add-metrics', 'update-roadmap'], | |
| mobile: ['add-screen', 'fix-memory-leak', 'optimize-bundle', 'add-offline-mode', 'configure-push', 'fix-animation', 'add-deep-linking'], | |
| qa: ['add-test', 'fix-flaky-test', 'increase-coverage', 'add-e2e-test', 'update-test-data', 'add-performance-test', 'fix-regression'], | |
| architect: ['design-service', 'document-tradeoffs', 'review-architecture', 'define-api-contract', 'plan-migration', 'track-tech-debt'], | |
| fullstack: ['add-feature', 'fix-bug', 'refactor-code', 'add-tests', 'update-docs', 'add-api-endpoint', 'create-component'], | |
| techlead: ['review-code', 'update-direction', 'sync-team', 'plan-sprint', 'mentor', 'review-architecture', 'prioritize-debt'], | |
| platform: ['update-portal', 'add-self-service', 'improve-reliability', 'deploy-tool', 'streamline-onboarding', 'add-template'], | |
| sre: ['update-slo', 'improve-incident', 'plan-capacity', 'run-chaos', 'reduce-alert-fatigue', 'document-runbook', 'check-error-budget'], | |
| }; | |
| const roleActions = actions[this.currentRole] || actions.fullstack; | |
| return roleActions[Math.floor(Math.random() * roleActions.length)]; | |
| } | |
| shouldReviewCode() { | |
| return Math.random() < this._personalityTraits.codeReviewStrictness; | |
| } | |
| shouldWriteTests() { | |
| return Math.random() < this._personalityTraits.testingHabit; | |
| } | |
| shouldDocument() { | |
| return Math.random() < this._personalityTraits.documentationHabit; | |
| } | |
| shouldCollaborate() { | |
| return Math.random() < this._personalityTraits.collaborationLevel; | |
| } | |
| getRiskLevel() { | |
| const risk = this._personalityTraits.riskTolerance; | |
| if (risk > 0.7) return 'high'; | |
| if (risk > 0.4) return 'medium'; | |
| return 'low'; | |
| } | |
| updateRoleWeights(role, direction = 'up') { | |
| if (!this.roleWeights[role]) return; | |
| if (direction === 'up') { | |
| this.roleWeights[role] = Math.min(1, (this.roleWeights[role] || 0) + 0.05); | |
| } else { | |
| this.roleWeights[role] = Math.max(0, (this.roleWeights[role] || 0) - 0.02); | |
| } | |
| this.memory.remember('roleWeights', this.roleWeights); | |
| } | |
| adjustPersonality(trait, value) { | |
| if (this._personalityTraits.hasOwnProperty(trait)) { | |
| this._personalityTraits[trait] = Math.max(0, Math.min(1, value)); | |
| this.memory.remember('personalityTraits', this._personalityTraits); | |
| } | |
| } | |
| getAllRoles() { | |
| return Object.entries(this.roles).map(([key, value]) => ({ | |
| id: key, | |
| ...value, | |
| weight: this.roleWeights[key] || 0, | |
| })); | |
| } | |
| getStats() { | |
| return { | |
| currentRole: this.currentRole, | |
| level: this.roles[this.currentRole]?.level || 'unknown', | |
| roleWeights: this.roleWeights, | |
| availableRoles: Object.keys(this.roles), | |
| personalityTraits: this._personalityTraits, | |
| riskLevel: this.getRiskLevel(), | |
| }; | |
| } | |
| } | |
| export default MultiRoleDeveloper; | |