Spaces:
Sleeping
Sleeping
File size: 21,067 Bytes
ccb6b75 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | 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;
|