@equilateral_ai/mindmeld 3.5.3 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/hooks/session-start.js +312 -85
  2. package/package.json +20 -14
  3. package/scripts/init-project.js +9 -23
  4. package/src/client/dbShim.js +16 -0
  5. package/src/core/AuthManager.js +3 -2
  6. package/src/handlers/helpers/dbOperations.js +9 -46
  7. package/src/index.js +2 -217
  8. package/src/utils/piiMask.js +16 -0
  9. package/scripts/harvest.js +0 -601
  10. package/scripts/inject.js +0 -409
  11. package/scripts/mcp-bridge.js +0 -220
  12. package/scripts/repo-analyzer.js +0 -870
  13. package/scripts/standards.js +0 -285
  14. package/src/collaboration/CollaborationPrompt.js +0 -460
  15. package/src/core/AlertEngine.js +0 -813
  16. package/src/core/AlertNotifier.js +0 -363
  17. package/src/core/CorrelationAnalyzer.js +0 -931
  18. package/src/core/CrossReferenceEngine.js +0 -624
  19. package/src/core/CurationEngine.js +0 -688
  20. package/src/core/DeprecationScheduler.js +0 -183
  21. package/src/core/LoadBearingDetector.js +0 -242
  22. package/src/core/NotificationService.js +0 -1032
  23. package/src/core/RapportOrchestrator.js +0 -632
  24. package/src/core/RelevanceDetector.js +0 -694
  25. package/src/core/StandardLifecycle.js +0 -244
  26. package/src/core/StandardsIngestion.js +0 -991
  27. package/src/core/TeamLoadBearingDetector.js +0 -431
  28. package/src/core/parsers/adrParser.js +0 -479
  29. package/src/core/parsers/cursorRulesParser.js +0 -564
  30. package/src/core/parsers/eslintParser.js +0 -439
  31. package/src/database/dbOperations.js +0 -105
  32. package/src/handlers/activity/activityGetMe.js +0 -98
  33. package/src/handlers/activity/activityGetTeam.js +0 -175
  34. package/src/handlers/admin/adminSetup.js +0 -216
  35. package/src/handlers/alerts/alertsAcknowledge.js +0 -92
  36. package/src/handlers/alerts/alertsGet.js +0 -250
  37. package/src/handlers/analytics/activitySummaryGet.js +0 -234
  38. package/src/handlers/analytics/coachingGet.js +0 -361
  39. package/src/handlers/analytics/convergenceGet.js +0 -236
  40. package/src/handlers/analytics/developerScoreGet.js +0 -137
  41. package/src/handlers/collaborators/collaboratorAdd.js +0 -200
  42. package/src/handlers/collaborators/collaboratorInvite.js +0 -219
  43. package/src/handlers/collaborators/collaboratorList.js +0 -82
  44. package/src/handlers/collaborators/collaboratorRemove.js +0 -128
  45. package/src/handlers/collaborators/inviteAccept.js +0 -122
  46. package/src/handlers/company/companyUsersDelete.js +0 -141
  47. package/src/handlers/company/companyUsersGet.js +0 -90
  48. package/src/handlers/company/companyUsersPost.js +0 -267
  49. package/src/handlers/company/companyUsersPut.js +0 -76
  50. package/src/handlers/context/contextGet.js +0 -57
  51. package/src/handlers/context/invariantsGet.js +0 -74
  52. package/src/handlers/context/loopsGet.js +0 -82
  53. package/src/handlers/context/notesCreate.js +0 -74
  54. package/src/handlers/context/purposeGet.js +0 -78
  55. package/src/handlers/correlations/correlationsDeveloperGet.js +0 -227
  56. package/src/handlers/correlations/correlationsGet.js +0 -93
  57. package/src/handlers/correlations/correlationsProjectGet.js +0 -153
  58. package/src/handlers/enterprise/controlTowerGet.js +0 -224
  59. package/src/handlers/enterprise/enterpriseAuditGet.js +0 -108
  60. package/src/handlers/enterprise/enterpriseContributorsGet.js +0 -85
  61. package/src/handlers/enterprise/enterpriseKnowledgeCategoriesGet.js +0 -53
  62. package/src/handlers/enterprise/enterpriseKnowledgeCreate.js +0 -77
  63. package/src/handlers/enterprise/enterpriseKnowledgeDelete.js +0 -71
  64. package/src/handlers/enterprise/enterpriseKnowledgeGet.js +0 -87
  65. package/src/handlers/enterprise/enterpriseKnowledgeUpdate.js +0 -122
  66. package/src/handlers/enterprise/enterpriseOnboardingComplete.js +0 -77
  67. package/src/handlers/enterprise/enterpriseOnboardingInvite.js +0 -138
  68. package/src/handlers/enterprise/enterpriseOnboardingSetup.js +0 -128
  69. package/src/handlers/enterprise/enterpriseOnboardingStatus.js +0 -88
  70. package/src/handlers/github/githubConnectionStatus.js +0 -49
  71. package/src/handlers/github/githubDiscoverPatterns.js +0 -621
  72. package/src/handlers/github/githubOAuthCallback.js +0 -178
  73. package/src/handlers/github/githubOAuthStart.js +0 -59
  74. package/src/handlers/github/githubPatternsReview.js +0 -76
  75. package/src/handlers/github/githubReposList.js +0 -105
  76. package/src/handlers/health/healthGet.js +0 -55
  77. package/src/handlers/helpers/auditLogger.js +0 -201
  78. package/src/handlers/helpers/checkSuperAdmin.js +0 -84
  79. package/src/handlers/helpers/decisionFrames.js +0 -29
  80. package/src/handlers/helpers/errorHandler.js +0 -49
  81. package/src/handlers/helpers/index.js +0 -138
  82. package/src/handlers/helpers/lambdaWrapper.js +0 -60
  83. package/src/handlers/helpers/mindmeldMcpCore.js +0 -1103
  84. package/src/handlers/helpers/predictiveCache.js +0 -51
  85. package/src/handlers/helpers/projectAccess.js +0 -88
  86. package/src/handlers/helpers/responseUtil.js +0 -55
  87. package/src/handlers/helpers/subscriptionTiers.js +0 -1168
  88. package/src/handlers/mcp/mcpHandler.js +0 -569
  89. package/src/handlers/mcp/mindmeldMcpHandler.js +0 -124
  90. package/src/handlers/mcp/mindmeldMcpStreamHandler.js +0 -342
  91. package/src/handlers/notifications/getPreferences.js +0 -84
  92. package/src/handlers/notifications/sendNotification.js +0 -170
  93. package/src/handlers/notifications/updatePreferences.js +0 -316
  94. package/src/handlers/patterns/patternEvaluatePromotionPost.js +0 -173
  95. package/src/handlers/patterns/patternUsagePost.js +0 -182
  96. package/src/handlers/patterns/patternViolationPost.js +0 -185
  97. package/src/handlers/projects/projectCreate.js +0 -248
  98. package/src/handlers/projects/projectDelete.js +0 -82
  99. package/src/handlers/projects/projectGet.js +0 -95
  100. package/src/handlers/projects/projectUpdate.js +0 -117
  101. package/src/handlers/reports/aiLeverage.js +0 -210
  102. package/src/handlers/reports/engineeringInvestment.js +0 -132
  103. package/src/handlers/reports/riskForecast.js +0 -206
  104. package/src/handlers/reports/standardsRoi.js +0 -254
  105. package/src/handlers/scheduled/analyzeCorrelations.js +0 -178
  106. package/src/handlers/scheduled/analyzeGitHistory.js +0 -510
  107. package/src/handlers/scheduled/generateAlerts.js +0 -135
  108. package/src/handlers/scheduled/maturityUpdateJob.js +0 -166
  109. package/src/handlers/scheduled/refreshActivity.js +0 -21
  110. package/src/handlers/scheduled/scanCompliance.js +0 -334
  111. package/src/handlers/sessions/sessionEndPost.js +0 -180
  112. package/src/handlers/sessions/sessionStandardsPost.js +0 -171
  113. package/src/handlers/standards/catalogGet.js +0 -185
  114. package/src/handlers/standards/catalogSync.js +0 -120
  115. package/src/handlers/standards/discoveriesGet.js +0 -89
  116. package/src/handlers/standards/projectStandardsGet.js +0 -129
  117. package/src/handlers/standards/projectStandardsPut.js +0 -151
  118. package/src/handlers/standards/standardsAuditGet.js +0 -65
  119. package/src/handlers/standards/standardsParseUpload.js +0 -149
  120. package/src/handlers/standards/standardsRelevantPost.js +0 -405
  121. package/src/handlers/standards/standardsTransition.js +0 -161
  122. package/src/handlers/stripe/addonManagePost.js +0 -240
  123. package/src/handlers/stripe/billingPortalPost.js +0 -93
  124. package/src/handlers/stripe/enterpriseCheckoutPost.js +0 -272
  125. package/src/handlers/stripe/seatsUpdatePost.js +0 -185
  126. package/src/handlers/stripe/subscriptionCancelDelete.js +0 -169
  127. package/src/handlers/stripe/subscriptionCreatePost.js +0 -221
  128. package/src/handlers/stripe/subscriptionUpdatePut.js +0 -163
  129. package/src/handlers/stripe/webhookPost.js +0 -482
  130. package/src/handlers/user/apiTokenCreate.js +0 -71
  131. package/src/handlers/user/apiTokenList.js +0 -64
  132. package/src/handlers/user/userSplashAck.js +0 -91
  133. package/src/handlers/user/userSplashGet.js +0 -211
  134. package/src/handlers/users/cognitoPostConfirmation.js +0 -186
  135. package/src/handlers/users/cognitoPreSignUp.js +0 -114
  136. package/src/handlers/users/userEntitlementsGet.js +0 -89
  137. package/src/handlers/users/userGet.js +0 -118
  138. package/src/handlers/users/userProfilePut.js +0 -77
  139. package/src/handlers/webhooks/githubWebhook.js +0 -215
@@ -1,632 +0,0 @@
1
- /**
2
- * Rapport Orchestrator - Multi-Agent Integration Layer
3
- * Integrates Rapport's pattern discovery with existing 63-agent ecosystem
4
- *
5
- * Phase 6: Multi-Agent Orchestration
6
- *
7
- * Key Integration:
8
- * - Leverages existing PatternHarvestingAgent, AuditorAgent, SecurityReviewerAgent, KnowledgeSynthesisAgent
9
- * - Creates RapportCurationWorkflow for pattern -> standard pipeline
10
- * - Background sync daemon for .equilateral-standards monitoring
11
- * - Event-driven architecture for real-time updates
12
- */
13
-
14
- const EventEmitter = require('events');
15
- const fs = require('fs').promises;
16
- const path = require('path');
17
- const { watch } = require('fs');
18
-
19
- class RapportOrchestrator extends EventEmitter {
20
- constructor(config = {}) {
21
- super();
22
-
23
- this.config = {
24
- rapportRoot: config.rapportRoot || process.cwd(),
25
- equilateralAgentsPath: config.equilateralAgentsPath || path.join(__dirname, '../../../EquilateralAgents'),
26
- standardsPath: config.standardsPath || '.equilateral-standards',
27
- enableBackgroundSync: config.enableBackgroundSync !== false,
28
- syncInterval: config.syncInterval || 300000, // 5 minutes
29
- ...config
30
- };
31
-
32
- this.agents = new Map();
33
- this.workflows = new Map();
34
- this.backgroundJobs = new Map();
35
- this.standardsWatcher = null;
36
- this.initialized = false;
37
- }
38
-
39
- /**
40
- * Initialize Rapport Orchestrator with agent system integration
41
- */
42
- async initialize() {
43
- try {
44
- console.log('[RapportOrchestrator] Initializing with multi-agent integration...');
45
-
46
- // 1. Connect to existing EquilateralAgents system
47
- await this.connectToAgentSystem();
48
-
49
- // 2. Register Rapport-specific workflows
50
- await this.registerWorkflows();
51
-
52
- // 3. Start background sync daemon (if enabled)
53
- if (this.config.enableBackgroundSync) {
54
- await this.startBackgroundSync();
55
- }
56
-
57
- this.initialized = true;
58
- this.emit('initialized', {
59
- agents: Array.from(this.agents.keys()),
60
- workflows: Array.from(this.workflows.keys()),
61
- backgroundSync: this.config.enableBackgroundSync
62
- });
63
-
64
- console.log('[RapportOrchestrator] Initialization complete');
65
- return { success: true, status: 'initialized' };
66
-
67
- } catch (error) {
68
- console.error('[RapportOrchestrator] Initialization failed:', error);
69
- this.emit('error', { component: 'orchestrator', error });
70
- throw error;
71
- }
72
- }
73
-
74
- /**
75
- * Connect to existing EquilateralAgents system
76
- * Leverages the 63-agent infrastructure without recreating it
77
- */
78
- async connectToAgentSystem() {
79
- try {
80
- // Import core agents from EquilateralAgents (if available)
81
- const agentsPath = path.join(this.config.equilateralAgentsPath, 'src/agents/specialists');
82
-
83
- // Core agents needed for Rapport curation workflow
84
- const coreAgents = [
85
- 'PatternHarvestingAgent',
86
- 'AuditorAgent',
87
- 'SecurityReviewerAgent',
88
- 'KnowledgeSynthesisAgent'
89
- ];
90
-
91
- for (const agentName of coreAgents) {
92
- try {
93
- const agentPath = path.join(agentsPath, `${agentName}.js`);
94
- const AgentClass = require(agentPath);
95
-
96
- // Register agent (lazy instantiation)
97
- this.agents.set(agentName, {
98
- name: agentName,
99
- class: AgentClass,
100
- instance: null,
101
- status: 'registered'
102
- });
103
-
104
- console.log(`[RapportOrchestrator] Registered agent: ${agentName}`);
105
- } catch (error) {
106
- console.warn(`[RapportOrchestrator] Could not load ${agentName}:`, error.message);
107
- }
108
- }
109
-
110
- // If no agents found, use fallback mode
111
- if (this.agents.size === 0) {
112
- console.warn('[RapportOrchestrator] No EquilateralAgents found, using standalone mode');
113
- }
114
-
115
- } catch (error) {
116
- console.warn('[RapportOrchestrator] Agent system connection failed, using standalone mode:', error.message);
117
- }
118
- }
119
-
120
- /**
121
- * Get or instantiate an agent (lazy loading)
122
- */
123
- getAgent(agentName) {
124
- if (!this.agents.has(agentName)) {
125
- throw new Error(`Agent ${agentName} not registered`);
126
- }
127
-
128
- const agentInfo = this.agents.get(agentName);
129
-
130
- // Return cached instance if available
131
- if (agentInfo.instance) {
132
- return agentInfo.instance;
133
- }
134
-
135
- // Instantiate agent
136
- const AgentClass = agentInfo.class;
137
- const instance = new AgentClass({
138
- projectRoot: this.config.rapportRoot
139
- });
140
-
141
- // Cache instance
142
- agentInfo.instance = instance;
143
- agentInfo.status = 'active';
144
-
145
- console.log(`[RapportOrchestrator] Instantiated agent: ${agentName}`);
146
- return instance;
147
- }
148
-
149
- /**
150
- * Register Rapport-specific workflows
151
- */
152
- async registerWorkflows() {
153
- // Workflow 1: Pattern Curation Pipeline
154
- this.workflows.set('rapport-curate-pattern', {
155
- name: 'rapport-curate-pattern',
156
- description: 'Curate discovered pattern into standard',
157
- steps: [
158
- { agent: 'PatternHarvestingAgent', method: 'gatherEvidence', parallel: false },
159
- { agent: 'AuditorAgent', method: 'validateCompliance', parallel: false },
160
- { agent: 'SecurityReviewerAgent', method: 'reviewPattern', parallel: false },
161
- { agent: 'KnowledgeSynthesisAgent', method: 'generateStandard', parallel: false }
162
- ]
163
- });
164
-
165
- // Workflow 2: Standards Validation
166
- this.workflows.set('rapport-validate-standards', {
167
- name: 'rapport-validate-standards',
168
- description: 'Validate code against ingested standards',
169
- steps: [
170
- { agent: 'PatternHarvestingAgent', method: 'detectPatterns', parallel: false },
171
- { agent: 'AuditorAgent', method: 'validateStandards', parallel: false }
172
- ]
173
- });
174
-
175
- // Workflow 3: Standards Sync
176
- this.workflows.set('rapport-sync-standards', {
177
- name: 'rapport-sync-standards',
178
- description: 'Sync .equilateral-standards into Rapport',
179
- steps: [
180
- { agent: 'PatternHarvestingAgent', method: 'discoverStandards', parallel: false },
181
- { agent: 'KnowledgeSynthesisAgent', method: 'synthesizeStandards', parallel: false }
182
- ]
183
- });
184
-
185
- console.log(`[RapportOrchestrator] Registered ${this.workflows.size} workflows`);
186
- }
187
-
188
- /**
189
- * Execute a workflow
190
- */
191
- async executeWorkflow(workflowName, params = {}) {
192
- if (!this.workflows.has(workflowName)) {
193
- throw new Error(`Workflow ${workflowName} not found`);
194
- }
195
-
196
- const workflow = this.workflows.get(workflowName);
197
- const workflowId = `${workflowName}_${Date.now()}`;
198
-
199
- this.emit('workflow:started', { workflowId, workflow: workflowName, params });
200
-
201
- try {
202
- const results = {
203
- workflowId,
204
- workflowName,
205
- steps: [],
206
- startedAt: new Date().toISOString(),
207
- status: 'running'
208
- };
209
-
210
- // Execute workflow steps sequentially (for now)
211
- for (const step of workflow.steps) {
212
- const stepResult = await this.executeWorkflowStep(step, params, workflowId);
213
- results.steps.push(stepResult);
214
-
215
- // Fail workflow if critical step fails
216
- if (!stepResult.success && step.required !== false) {
217
- results.status = 'failed';
218
- results.failedAt = step.agent;
219
- this.emit('workflow:failed', results);
220
- return results;
221
- }
222
- }
223
-
224
- results.status = 'completed';
225
- results.completedAt = new Date().toISOString();
226
-
227
- this.emit('workflow:completed', results);
228
- return results;
229
-
230
- } catch (error) {
231
- this.emit('workflow:failed', { workflowId, error: error.message });
232
- throw error;
233
- }
234
- }
235
-
236
- /**
237
- * Execute a single workflow step
238
- */
239
- async executeWorkflowStep(step, params, workflowId) {
240
- const { agent: agentName, method, parallel } = step;
241
-
242
- this.emit('step:started', { workflowId, agent: agentName, method });
243
-
244
- try {
245
- // Get agent instance (lazy load if needed)
246
- const agent = this.getAgent(agentName);
247
-
248
- // Execute agent method
249
- let result;
250
- if (typeof agent[method] === 'function') {
251
- result = await agent[method](params);
252
- } else {
253
- // Fallback to generic execute method
254
- result = await agent.execute({ task: method, ...params });
255
- }
256
-
257
- this.emit('step:completed', { workflowId, agent: agentName, method, result });
258
-
259
- return {
260
- agent: agentName,
261
- method,
262
- success: true,
263
- result,
264
- completedAt: new Date().toISOString()
265
- };
266
-
267
- } catch (error) {
268
- this.emit('step:failed', { workflowId, agent: agentName, method, error: error.message });
269
-
270
- return {
271
- agent: agentName,
272
- method,
273
- success: false,
274
- error: error.message,
275
- failedAt: new Date().toISOString()
276
- };
277
- }
278
- }
279
-
280
- /**
281
- * Start background sync daemon for .equilateral-standards monitoring
282
- */
283
- async startBackgroundSync() {
284
- console.log('[RapportOrchestrator] Starting background sync daemon...');
285
-
286
- // 1. Initial sync
287
- await this.syncStandards();
288
-
289
- // 2. Set up file watcher for .equilateral-standards/
290
- const standardsPath = path.join(this.config.rapportRoot, this.config.standardsPath);
291
-
292
- try {
293
- this.standardsWatcher = watch(standardsPath, { recursive: true }, async (eventType, filename) => {
294
- if (filename && filename.endsWith('.md')) {
295
- console.log(`[RapportOrchestrator] Standards change detected: ${filename}`);
296
- this.emit('standards:changed', { filename, eventType });
297
-
298
- // Debounce sync to avoid rapid-fire updates
299
- if (this.syncDebounceTimer) {
300
- clearTimeout(this.syncDebounceTimer);
301
- }
302
-
303
- this.syncDebounceTimer = setTimeout(async () => {
304
- await this.syncStandards();
305
- }, 5000); // 5 second debounce
306
- }
307
- });
308
-
309
- console.log('[RapportOrchestrator] File watcher active on:', standardsPath);
310
- } catch (error) {
311
- console.warn('[RapportOrchestrator] Could not watch standards directory:', error.message);
312
- }
313
-
314
- // 3. Set up periodic sync interval
315
- this.backgroundJobs.set('standards-sync', setInterval(async () => {
316
- console.log('[RapportOrchestrator] Running periodic standards sync...');
317
- await this.syncStandards();
318
- }, this.config.syncInterval));
319
- }
320
-
321
- /**
322
- * Sync .equilateral-standards into Rapport database
323
- */
324
- async syncStandards() {
325
- try {
326
- console.log('[RapportOrchestrator] Syncing standards...');
327
-
328
- const result = await this.executeWorkflow('rapport-sync-standards', {
329
- standardsPath: path.join(this.config.rapportRoot, this.config.standardsPath)
330
- });
331
-
332
- if (result.status === 'completed') {
333
- this.emit('standards:synced', {
334
- timestamp: new Date().toISOString(),
335
- result
336
- });
337
- console.log('[RapportOrchestrator] Standards sync completed');
338
- } else {
339
- console.warn('[RapportOrchestrator] Standards sync failed:', result);
340
- }
341
-
342
- return result;
343
-
344
- } catch (error) {
345
- console.error('[RapportOrchestrator] Standards sync error:', error);
346
- this.emit('standards:sync-failed', { error: error.message });
347
- }
348
- }
349
-
350
- /**
351
- * Curate a pattern into a standard
352
- * Main entry point for pattern -> standard promotion
353
- */
354
- async curatePattern(patternId, options = {}) {
355
- console.log(`[RapportOrchestrator] Curating pattern: ${patternId}`);
356
-
357
- try {
358
- const result = await this.executeWorkflow('rapport-curate-pattern', {
359
- patternId,
360
- ...options
361
- });
362
-
363
- if (result.status === 'completed') {
364
- this.emit('pattern:curated', {
365
- patternId,
366
- result
367
- });
368
- }
369
-
370
- return result;
371
-
372
- } catch (error) {
373
- console.error('[RapportOrchestrator] Pattern curation failed:', error);
374
- throw error;
375
- }
376
- }
377
-
378
- /**
379
- * Validate code against standards
380
- */
381
- async validateStandards(codeContext) {
382
- console.log('[RapportOrchestrator] Validating standards...');
383
-
384
- try {
385
- const result = await this.executeWorkflow('rapport-validate-standards', {
386
- codeContext
387
- });
388
-
389
- return result;
390
-
391
- } catch (error) {
392
- console.error('[RapportOrchestrator] Standards validation failed:', error);
393
- throw error;
394
- }
395
- }
396
-
397
- // =============================================
398
- // Roadmap Team Dispatch (TeamOrchestrator)
399
- // =============================================
400
-
401
- /**
402
- * Roadmap team templates — each team gets isolated agents and phased workflow
403
- */
404
- getRoadmapTeams() {
405
- return {
406
- 'standards-parsers': {
407
- description: 'Standards parsers for onboarding upload (ADR, ESLint, Cursor rules)',
408
- agents: ['CodeGenerationAgent', 'PatternHarvestingAgent'],
409
- phases: ['ADR_PARSER', 'ESLINT_PARSER', 'CURSOR_RULES_PARSER', 'CROSS_REFERENCE']
410
- },
411
- 'frontend-curation': {
412
- description: 'Frontend curation dashboard (review queue, rejection flow, conflict resolution)',
413
- agents: ['UIUXSpecialistAgent', 'CodeGenerationAgent'],
414
- phases: ['REVIEW_QUEUE', 'REJECTION_FLOW', 'CONFLICT_RESOLUTION', 'STANDARD_EDITOR']
415
- },
416
- 'standard-lifecycle': {
417
- description: 'Standard lifecycle state machine, audit trail, deprecation',
418
- agents: ['DatabaseAgent', 'AuditorAgent'],
419
- phases: ['STATE_MACHINE', 'AUDIT_TRAIL_TABLE', 'DEPRECATION_SCHEDULER']
420
- },
421
- 'weekly-splash-cli': {
422
- description: 'Weekly splash screen, activity summary, /mm slash commands',
423
- agents: ['CodeGenerationAgent', 'KnowledgeSynthesisAgent'],
424
- phases: ['SPLASH_SCREEN', 'ACTIVITY_SUMMARY', 'SLASH_COMMANDS']
425
- },
426
- 'developer-insights': {
427
- description: 'Enterprise developer insights (quality scoring, trends, coaching)',
428
- agents: ['BusinessIntelligenceAgent', 'DataGovernanceAgent'],
429
- phases: ['QUALITY_SCORING', 'TEAM_TRENDS', 'COACHING_ENGINE']
430
- }
431
- };
432
- }
433
-
434
- /**
435
- * Dispatch all roadmap teams in parallel
436
- * Each team runs with isolated context, dedicated agents, phased workflow
437
- *
438
- * @param {Object} options - Dispatch options
439
- * @param {string} options.team - Dispatch a single team by name (optional)
440
- * @returns {Promise<Object>} Results from all teams
441
- */
442
- async dispatchRoadmap(options = {}) {
443
- const allTeams = this.getRoadmapTeams();
444
- const teamsToRun = options.team
445
- ? { [options.team]: allTeams[options.team] }
446
- : allTeams;
447
-
448
- if (options.team && !allTeams[options.team]) {
449
- throw new Error(`Unknown team: ${options.team}. Available: ${Object.keys(allTeams).join(', ')}`);
450
- }
451
-
452
- console.log(`[RapportOrchestrator] Dispatching ${Object.keys(teamsToRun).length} roadmap teams in parallel...`);
453
- this.emit('roadmap:started', { teams: Object.keys(teamsToRun), startedAt: new Date().toISOString() });
454
-
455
- // Connect to extended agent set for roadmap work
456
- await this.connectRoadmapAgents(teamsToRun);
457
-
458
- // Dispatch all teams in parallel
459
- const teamPromises = Object.entries(teamsToRun).map(([teamName, template]) =>
460
- this.dispatchTeam(teamName, template, options)
461
- .then(result => ({ team: teamName, status: 'fulfilled', result }))
462
- .catch(error => ({ team: teamName, status: 'rejected', error: error.message }))
463
- );
464
-
465
- const results = await Promise.all(teamPromises);
466
-
467
- const summary = {
468
- total: results.length,
469
- fulfilled: results.filter(r => r.status === 'fulfilled').length,
470
- rejected: results.filter(r => r.status === 'rejected').length,
471
- teams: results,
472
- completedAt: new Date().toISOString()
473
- };
474
-
475
- console.log(`[RapportOrchestrator] Roadmap dispatch complete: ${summary.fulfilled}/${summary.total} teams succeeded`);
476
- this.emit('roadmap:completed', summary);
477
-
478
- return summary;
479
- }
480
-
481
- /**
482
- * Dispatch a single team with isolated context
483
- */
484
- async dispatchTeam(teamName, template, options = {}) {
485
- const teamId = `team_${teamName}_${Date.now()}`;
486
- console.log(`[RapportOrchestrator] Dispatching team: ${teamName} (${teamId})`);
487
- this.emit('team:started', { teamId, teamName, phases: template.phases });
488
-
489
- const teamContext = {
490
- teamId,
491
- teamName,
492
- startedAt: new Date().toISOString(),
493
- projectRoot: this.config.rapportRoot,
494
- standardsPath: path.join(this.config.rapportRoot, this.config.standardsPath),
495
- phaseResults: {}
496
- };
497
-
498
- // Execute phases sequentially within team
499
- for (const phase of template.phases) {
500
- console.log(` [${teamName}] Phase: ${phase}`);
501
- this.emit('phase:started', { teamId, teamName, phase });
502
-
503
- try {
504
- const phaseResult = await this.executeTeamPhase(teamName, phase, template.agents, teamContext);
505
- teamContext.phaseResults[phase] = { success: true, result: phaseResult };
506
- this.emit('phase:completed', { teamId, teamName, phase, result: phaseResult });
507
- } catch (error) {
508
- console.error(` [${teamName}] Phase ${phase} failed:`, error.message);
509
- teamContext.phaseResults[phase] = { success: false, error: error.message };
510
- this.emit('phase:failed', { teamId, teamName, phase, error: error.message });
511
- }
512
- }
513
-
514
- teamContext.completedAt = new Date().toISOString();
515
- this.emit('team:completed', { teamId, teamName, context: teamContext });
516
-
517
- return teamContext;
518
- }
519
-
520
- /**
521
- * Execute a single phase within a team, using assigned agents
522
- */
523
- async executeTeamPhase(teamName, phase, agentNames, teamContext) {
524
- // Try each assigned agent for this phase
525
- for (const agentName of agentNames) {
526
- if (!this.agents.has(agentName)) continue;
527
-
528
- try {
529
- const agent = this.getAgent(agentName);
530
-
531
- // Try phase-specific method first, then generic execute
532
- const methodName = `execute${phase.replace(/_/g, '')}`;
533
- if (typeof agent[methodName] === 'function') {
534
- return await agent[methodName](teamContext);
535
- } else if (typeof agent.execute === 'function') {
536
- return await agent.execute({
537
- task: phase,
538
- team: teamName,
539
- context: teamContext
540
- });
541
- }
542
- } catch (error) {
543
- console.warn(` [${teamName}] Agent ${agentName} failed on ${phase}:`, error.message);
544
- }
545
- }
546
-
547
- // Fallback: emit phase for external handling
548
- return { status: 'pending_implementation', phase, team: teamName };
549
- }
550
-
551
- /**
552
- * Connect additional agents needed for roadmap work
553
- */
554
- async connectRoadmapAgents(teams) {
555
- const agentsPath = path.join(this.config.equilateralAgentsPath, 'src/agents/specialists');
556
- const neededAgents = new Set();
557
-
558
- for (const template of Object.values(teams)) {
559
- for (const agentName of template.agents) {
560
- if (!this.agents.has(agentName)) {
561
- neededAgents.add(agentName);
562
- }
563
- }
564
- }
565
-
566
- for (const agentName of neededAgents) {
567
- try {
568
- const agentPath = path.join(agentsPath, `${agentName}.js`);
569
- const AgentClass = require(agentPath);
570
- this.agents.set(agentName, {
571
- name: agentName,
572
- class: AgentClass,
573
- instance: null,
574
- status: 'registered'
575
- });
576
- console.log(`[RapportOrchestrator] Registered roadmap agent: ${agentName}`);
577
- } catch (error) {
578
- console.warn(`[RapportOrchestrator] Could not load roadmap agent ${agentName}:`, error.message);
579
- }
580
- }
581
- }
582
-
583
- /**
584
- * Get orchestrator status
585
- */
586
- getStatus() {
587
- return {
588
- initialized: this.initialized,
589
- agents: {
590
- registered: this.agents.size,
591
- active: Array.from(this.agents.values()).filter(a => a.status === 'active').length,
592
- list: Array.from(this.agents.keys())
593
- },
594
- workflows: {
595
- registered: this.workflows.size,
596
- list: Array.from(this.workflows.keys())
597
- },
598
- backgroundSync: {
599
- enabled: this.config.enableBackgroundSync,
600
- watching: !!this.standardsWatcher,
601
- jobs: Array.from(this.backgroundJobs.keys())
602
- }
603
- };
604
- }
605
-
606
- /**
607
- * Shutdown orchestrator and cleanup
608
- */
609
- async shutdown() {
610
- console.log('[RapportOrchestrator] Shutting down...');
611
-
612
- // Close file watcher
613
- if (this.standardsWatcher) {
614
- this.standardsWatcher.close();
615
- }
616
-
617
- // Clear background jobs
618
- for (const [name, job] of this.backgroundJobs) {
619
- clearInterval(job);
620
- console.log(`[RapportOrchestrator] Stopped background job: ${name}`);
621
- }
622
-
623
- this.backgroundJobs.clear();
624
- this.agents.clear();
625
- this.workflows.clear();
626
-
627
- this.emit('shutdown');
628
- console.log('[RapportOrchestrator] Shutdown complete');
629
- }
630
- }
631
-
632
- module.exports = RapportOrchestrator;