@equilateral_ai/mindmeld 3.0.0

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 (86) hide show
  1. package/README.md +300 -0
  2. package/hooks/README.md +494 -0
  3. package/hooks/pre-compact.js +392 -0
  4. package/hooks/session-start.js +264 -0
  5. package/package.json +90 -0
  6. package/scripts/harvest.js +561 -0
  7. package/scripts/init-project.js +437 -0
  8. package/scripts/inject.js +388 -0
  9. package/src/collaboration/CollaborationPrompt.js +460 -0
  10. package/src/core/AlertEngine.js +813 -0
  11. package/src/core/AlertNotifier.js +363 -0
  12. package/src/core/CorrelationAnalyzer.js +774 -0
  13. package/src/core/CurationEngine.js +688 -0
  14. package/src/core/LLMPatternDetector.js +508 -0
  15. package/src/core/LoadBearingDetector.js +242 -0
  16. package/src/core/NotificationService.js +1032 -0
  17. package/src/core/PatternValidator.js +355 -0
  18. package/src/core/README.md +160 -0
  19. package/src/core/RapportOrchestrator.js +446 -0
  20. package/src/core/RelevanceDetector.js +577 -0
  21. package/src/core/StandardsIngestion.js +575 -0
  22. package/src/core/TeamLoadBearingDetector.js +431 -0
  23. package/src/database/dbOperations.js +105 -0
  24. package/src/handlers/activity/activityGetMe.js +98 -0
  25. package/src/handlers/activity/activityGetTeam.js +130 -0
  26. package/src/handlers/alerts/alertsAcknowledge.js +91 -0
  27. package/src/handlers/alerts/alertsGet.js +250 -0
  28. package/src/handlers/collaborators/collaboratorAdd.js +201 -0
  29. package/src/handlers/collaborators/collaboratorInvite.js +218 -0
  30. package/src/handlers/collaborators/collaboratorList.js +88 -0
  31. package/src/handlers/collaborators/collaboratorRemove.js +127 -0
  32. package/src/handlers/collaborators/inviteAccept.js +122 -0
  33. package/src/handlers/context/contextGet.js +57 -0
  34. package/src/handlers/context/invariantsGet.js +74 -0
  35. package/src/handlers/context/loopsGet.js +82 -0
  36. package/src/handlers/context/notesCreate.js +74 -0
  37. package/src/handlers/context/purposeGet.js +78 -0
  38. package/src/handlers/correlations/correlationsDeveloperGet.js +226 -0
  39. package/src/handlers/correlations/correlationsGet.js +93 -0
  40. package/src/handlers/correlations/correlationsProjectGet.js +161 -0
  41. package/src/handlers/github/githubConnectionStatus.js +49 -0
  42. package/src/handlers/github/githubDiscoverPatterns.js +364 -0
  43. package/src/handlers/github/githubOAuthCallback.js +166 -0
  44. package/src/handlers/github/githubOAuthStart.js +59 -0
  45. package/src/handlers/github/githubPatternsReview.js +109 -0
  46. package/src/handlers/github/githubReposList.js +105 -0
  47. package/src/handlers/helpers/checkSuperAdmin.js +85 -0
  48. package/src/handlers/helpers/dbOperations.js +53 -0
  49. package/src/handlers/helpers/errorHandler.js +49 -0
  50. package/src/handlers/helpers/index.js +106 -0
  51. package/src/handlers/helpers/lambdaWrapper.js +60 -0
  52. package/src/handlers/helpers/responseUtil.js +55 -0
  53. package/src/handlers/helpers/subscriptionTiers.js +1168 -0
  54. package/src/handlers/notifications/getPreferences.js +84 -0
  55. package/src/handlers/notifications/sendNotification.js +170 -0
  56. package/src/handlers/notifications/updatePreferences.js +316 -0
  57. package/src/handlers/patterns/patternUsagePost.js +182 -0
  58. package/src/handlers/patterns/patternViolationPost.js +185 -0
  59. package/src/handlers/projects/projectCreate.js +107 -0
  60. package/src/handlers/projects/projectDelete.js +82 -0
  61. package/src/handlers/projects/projectGet.js +95 -0
  62. package/src/handlers/projects/projectUpdate.js +118 -0
  63. package/src/handlers/reports/aiLeverage.js +206 -0
  64. package/src/handlers/reports/engineeringInvestment.js +132 -0
  65. package/src/handlers/reports/riskForecast.js +186 -0
  66. package/src/handlers/reports/standardsRoi.js +162 -0
  67. package/src/handlers/scheduled/analyzeCorrelations.js +178 -0
  68. package/src/handlers/scheduled/analyzeGitHistory.js +510 -0
  69. package/src/handlers/scheduled/generateAlerts.js +135 -0
  70. package/src/handlers/scheduled/refreshActivity.js +21 -0
  71. package/src/handlers/scheduled/scanCompliance.js +334 -0
  72. package/src/handlers/sessions/sessionEndPost.js +180 -0
  73. package/src/handlers/sessions/sessionStandardsPost.js +135 -0
  74. package/src/handlers/stripe/addonManagePost.js +240 -0
  75. package/src/handlers/stripe/billingPortalPost.js +93 -0
  76. package/src/handlers/stripe/enterpriseCheckoutPost.js +272 -0
  77. package/src/handlers/stripe/seatsUpdatePost.js +185 -0
  78. package/src/handlers/stripe/subscriptionCancelDelete.js +169 -0
  79. package/src/handlers/stripe/subscriptionCreatePost.js +221 -0
  80. package/src/handlers/stripe/subscriptionUpdatePut.js +163 -0
  81. package/src/handlers/stripe/webhookPost.js +454 -0
  82. package/src/handlers/users/cognitoPostConfirmation.js +150 -0
  83. package/src/handlers/users/userEntitlementsGet.js +89 -0
  84. package/src/handlers/users/userGet.js +114 -0
  85. package/src/handlers/webhooks/githubWebhook.js +223 -0
  86. package/src/index.js +969 -0
@@ -0,0 +1,242 @@
1
+ /**
2
+ * Load-Bearing Detector
3
+ *
4
+ * Detects context elements that correlate with handoff success/failure.
5
+ * Load-bearing context = context that must be present for successful handoffs.
6
+ *
7
+ * Algorithm:
8
+ * 1. Track context elements present in each handoff
9
+ * 2. Correlate presence/absence with success/failure
10
+ * 3. Elements with high correlation to success = load-bearing
11
+ *
12
+ * Based on: Phase 6 Multi-Agent Integration
13
+ */
14
+
15
+ class LoadBearingDetector {
16
+ constructor(config = {}) {
17
+ this.config = {
18
+ correlationThreshold: config.correlationThreshold || 0.7,
19
+ minObservations: config.minObservations || 5,
20
+ ...config
21
+ };
22
+
23
+ // Track context elements and their correlation with outcomes
24
+ this.contextElements = new Map(); // key -> { element, observations, presentAndSuccess, presentAndFailure, totalPresent }
25
+
26
+ // Track handoff analysis history
27
+ this.handoffAnalysis = [];
28
+ }
29
+
30
+ /**
31
+ * Analyze a handoff and update correlations
32
+ *
33
+ * @param {Object} handoff - The handoff context
34
+ * @param {Object} outcome - The outcome { success: boolean, metrics: {} }
35
+ * @returns {Object} Analysis result
36
+ */
37
+ analyzeHandoff(handoff, outcome) {
38
+ const elements = this.extractContextElements(handoff);
39
+ const success = outcome.success;
40
+
41
+ // Update statistics for each element
42
+ for (const element of elements) {
43
+ this.updateElementStats(element, success);
44
+ }
45
+
46
+ // Record handoff
47
+ this.handoffAnalysis.push({
48
+ timestamp: new Date().toISOString(),
49
+ elements: elements.map(e => e.key),
50
+ success,
51
+ metrics: outcome.metrics || {}
52
+ });
53
+
54
+ return {
55
+ elements,
56
+ success,
57
+ loadBearing: this.getLoadBearing()
58
+ };
59
+ }
60
+
61
+ /**
62
+ * Extract context elements from handoff
63
+ */
64
+ extractContextElements(handoff) {
65
+ const elements = [];
66
+
67
+ // Extract constraints
68
+ if (handoff.constraints) {
69
+ for (const constraint of handoff.constraints) {
70
+ elements.push({
71
+ type: 'constraint',
72
+ key: `constraint:${constraint}`,
73
+ value: constraint
74
+ });
75
+ }
76
+ }
77
+
78
+ // Extract context keys
79
+ if (handoff.context) {
80
+ for (const [key, value] of Object.entries(handoff.context)) {
81
+ elements.push({
82
+ type: 'context_key',
83
+ key: `context:${key}`,
84
+ value: key,
85
+ hasValue: value !== null && value !== undefined
86
+ });
87
+ }
88
+ }
89
+
90
+ // Extract missing context (for correlation with failure)
91
+ if (handoff.missing) {
92
+ for (const key of handoff.missing) {
93
+ elements.push({
94
+ type: 'missing',
95
+ key: `missing:${key}`,
96
+ value: key
97
+ });
98
+ }
99
+ }
100
+
101
+ return elements;
102
+ }
103
+
104
+ /**
105
+ * Update statistics for an element
106
+ */
107
+ updateElementStats(element, success) {
108
+ const key = element.key;
109
+
110
+ if (!this.contextElements.has(key)) {
111
+ this.contextElements.set(key, {
112
+ element,
113
+ observations: 0,
114
+ presentAndSuccess: 0,
115
+ presentAndFailure: 0,
116
+ totalPresent: 0
117
+ });
118
+ }
119
+
120
+ const stats = this.contextElements.get(key);
121
+ stats.observations++;
122
+ stats.totalPresent++;
123
+
124
+ if (success) {
125
+ stats.presentAndSuccess++;
126
+ } else {
127
+ stats.presentAndFailure++;
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Get load-bearing elements
133
+ */
134
+ getLoadBearing() {
135
+ const loadBearing = [];
136
+
137
+ for (const [key, stats] of this.contextElements.entries()) {
138
+ if (stats.observations < this.config.minObservations) {
139
+ continue;
140
+ }
141
+
142
+ const correlation = stats.totalPresent > 0
143
+ ? stats.presentAndSuccess / stats.totalPresent
144
+ : 0;
145
+
146
+ if (correlation >= this.config.correlationThreshold) {
147
+ loadBearing.push({
148
+ element: stats.element,
149
+ correlation,
150
+ observations: stats.observations,
151
+ recommendation: 'LOAD_BEARING'
152
+ });
153
+ }
154
+ }
155
+
156
+ return loadBearing.sort((a, b) => b.correlation - a.correlation);
157
+ }
158
+
159
+ /**
160
+ * Apply recommendations to a decision frame
161
+ */
162
+ applyRecommendations(decisionFrame, recommendations) {
163
+ const applied = [];
164
+
165
+ for (const rec of recommendations) {
166
+ if (rec.type === 'mark_constraint_load_bearing') {
167
+ applied.push({
168
+ action: 'marked_load_bearing',
169
+ constraint: rec.constraint,
170
+ reason: rec.reason
171
+ });
172
+ }
173
+
174
+ if (rec.type === 'always_include_context') {
175
+ applied.push({
176
+ action: 'required_context',
177
+ key: rec.key,
178
+ reason: rec.reason
179
+ });
180
+ }
181
+
182
+ if (rec.type === 'prevent_missing_context') {
183
+ applied.push({
184
+ action: 'prevent_missing',
185
+ key: rec.key,
186
+ reason: rec.reason
187
+ });
188
+ }
189
+ }
190
+
191
+ return {
192
+ decisionFrame,
193
+ appliedRecommendations: applied
194
+ };
195
+ }
196
+
197
+ /**
198
+ * Get summary statistics
199
+ */
200
+ getSummary() {
201
+ const totalHandoffs = this.handoffAnalysis.length;
202
+ const successfulHandoffs = this.handoffAnalysis.filter(h => h.success).length;
203
+
204
+ return {
205
+ totalHandoffs,
206
+ successfulHandoffs,
207
+ successRate: totalHandoffs > 0 ? successfulHandoffs / totalHandoffs : 0,
208
+ loadBearingDetected: this.getLoadBearing().length,
209
+ trackedElements: this.contextElements.size
210
+ };
211
+ }
212
+
213
+ /**
214
+ * Export data for persistence
215
+ */
216
+ exportData() {
217
+ return {
218
+ handoffAnalysis: this.handoffAnalysis,
219
+ contextElements: Array.from(this.contextElements.entries()).map(([key, stats]) => ({
220
+ key,
221
+ ...stats
222
+ }))
223
+ };
224
+ }
225
+
226
+ /**
227
+ * Import data from persistence
228
+ */
229
+ importData(data) {
230
+ if (data.handoffAnalysis) {
231
+ this.handoffAnalysis = data.handoffAnalysis;
232
+ }
233
+
234
+ if (data.contextElements) {
235
+ for (const elem of data.contextElements) {
236
+ this.contextElements.set(elem.key, elem);
237
+ }
238
+ }
239
+ }
240
+ }
241
+
242
+ module.exports = LoadBearingDetector;