@equilateral_ai/mindmeld 3.5.3 → 4.0.2
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.
- package/hooks/session-start.js +312 -85
- package/package.json +21 -13
- package/scripts/init-project.js +9 -23
- package/scripts/repo-analyzer.js +118 -2
- package/src/client/dbShim.js +16 -0
- package/src/core/AuthManager.js +3 -2
- package/src/handlers/helpers/dbOperations.js +9 -46
- package/src/index.js +2 -217
- package/src/utils/piiMask.js +16 -0
- package/scripts/inject.js +0 -409
- package/scripts/mcp-bridge.js +0 -220
- package/scripts/standards.js +0 -285
- package/src/collaboration/CollaborationPrompt.js +0 -460
- package/src/core/AlertEngine.js +0 -813
- package/src/core/AlertNotifier.js +0 -363
- package/src/core/CorrelationAnalyzer.js +0 -931
- package/src/core/CrossReferenceEngine.js +0 -624
- package/src/core/CurationEngine.js +0 -688
- package/src/core/DeprecationScheduler.js +0 -183
- package/src/core/LoadBearingDetector.js +0 -242
- package/src/core/NotificationService.js +0 -1032
- package/src/core/RapportOrchestrator.js +0 -632
- package/src/core/RelevanceDetector.js +0 -694
- package/src/core/StandardLifecycle.js +0 -244
- package/src/core/StandardsIngestion.js +0 -991
- package/src/core/TeamLoadBearingDetector.js +0 -431
- package/src/core/parsers/adrParser.js +0 -479
- package/src/core/parsers/cursorRulesParser.js +0 -564
- package/src/core/parsers/eslintParser.js +0 -439
- package/src/database/dbOperations.js +0 -105
- package/src/handlers/activity/activityGetMe.js +0 -98
- package/src/handlers/activity/activityGetTeam.js +0 -175
- package/src/handlers/admin/adminSetup.js +0 -216
- package/src/handlers/alerts/alertsAcknowledge.js +0 -92
- package/src/handlers/alerts/alertsGet.js +0 -250
- package/src/handlers/analytics/activitySummaryGet.js +0 -234
- package/src/handlers/analytics/coachingGet.js +0 -361
- package/src/handlers/analytics/convergenceGet.js +0 -236
- package/src/handlers/analytics/developerScoreGet.js +0 -137
- package/src/handlers/collaborators/collaboratorAdd.js +0 -200
- package/src/handlers/collaborators/collaboratorInvite.js +0 -219
- package/src/handlers/collaborators/collaboratorList.js +0 -82
- package/src/handlers/collaborators/collaboratorRemove.js +0 -128
- package/src/handlers/collaborators/inviteAccept.js +0 -122
- package/src/handlers/company/companyUsersDelete.js +0 -141
- package/src/handlers/company/companyUsersGet.js +0 -90
- package/src/handlers/company/companyUsersPost.js +0 -267
- package/src/handlers/company/companyUsersPut.js +0 -76
- package/src/handlers/context/contextGet.js +0 -57
- package/src/handlers/context/invariantsGet.js +0 -74
- package/src/handlers/context/loopsGet.js +0 -82
- package/src/handlers/context/notesCreate.js +0 -74
- package/src/handlers/context/purposeGet.js +0 -78
- package/src/handlers/correlations/correlationsDeveloperGet.js +0 -227
- package/src/handlers/correlations/correlationsGet.js +0 -93
- package/src/handlers/correlations/correlationsProjectGet.js +0 -153
- package/src/handlers/enterprise/controlTowerGet.js +0 -224
- package/src/handlers/enterprise/enterpriseAuditGet.js +0 -108
- package/src/handlers/enterprise/enterpriseContributorsGet.js +0 -85
- package/src/handlers/enterprise/enterpriseKnowledgeCategoriesGet.js +0 -53
- package/src/handlers/enterprise/enterpriseKnowledgeCreate.js +0 -77
- package/src/handlers/enterprise/enterpriseKnowledgeDelete.js +0 -71
- package/src/handlers/enterprise/enterpriseKnowledgeGet.js +0 -87
- package/src/handlers/enterprise/enterpriseKnowledgeUpdate.js +0 -122
- package/src/handlers/enterprise/enterpriseOnboardingComplete.js +0 -77
- package/src/handlers/enterprise/enterpriseOnboardingInvite.js +0 -138
- package/src/handlers/enterprise/enterpriseOnboardingSetup.js +0 -128
- package/src/handlers/enterprise/enterpriseOnboardingStatus.js +0 -88
- package/src/handlers/github/githubConnectionStatus.js +0 -49
- package/src/handlers/github/githubDiscoverPatterns.js +0 -621
- package/src/handlers/github/githubOAuthCallback.js +0 -178
- package/src/handlers/github/githubOAuthStart.js +0 -59
- package/src/handlers/github/githubPatternsReview.js +0 -76
- package/src/handlers/github/githubReposList.js +0 -105
- package/src/handlers/health/healthGet.js +0 -55
- package/src/handlers/helpers/auditLogger.js +0 -201
- package/src/handlers/helpers/checkSuperAdmin.js +0 -84
- package/src/handlers/helpers/decisionFrames.js +0 -29
- package/src/handlers/helpers/errorHandler.js +0 -49
- package/src/handlers/helpers/index.js +0 -138
- package/src/handlers/helpers/lambdaWrapper.js +0 -60
- package/src/handlers/helpers/mindmeldMcpCore.js +0 -1103
- package/src/handlers/helpers/predictiveCache.js +0 -51
- package/src/handlers/helpers/projectAccess.js +0 -88
- package/src/handlers/helpers/responseUtil.js +0 -55
- package/src/handlers/helpers/subscriptionTiers.js +0 -1168
- package/src/handlers/mcp/mcpHandler.js +0 -569
- package/src/handlers/mcp/mindmeldMcpHandler.js +0 -124
- package/src/handlers/mcp/mindmeldMcpStreamHandler.js +0 -342
- package/src/handlers/notifications/getPreferences.js +0 -84
- package/src/handlers/notifications/sendNotification.js +0 -170
- package/src/handlers/notifications/updatePreferences.js +0 -316
- package/src/handlers/patterns/patternEvaluatePromotionPost.js +0 -173
- package/src/handlers/patterns/patternUsagePost.js +0 -182
- package/src/handlers/patterns/patternViolationPost.js +0 -185
- package/src/handlers/projects/projectCreate.js +0 -248
- package/src/handlers/projects/projectDelete.js +0 -82
- package/src/handlers/projects/projectGet.js +0 -95
- package/src/handlers/projects/projectUpdate.js +0 -117
- package/src/handlers/reports/aiLeverage.js +0 -210
- package/src/handlers/reports/engineeringInvestment.js +0 -132
- package/src/handlers/reports/riskForecast.js +0 -206
- package/src/handlers/reports/standardsRoi.js +0 -254
- package/src/handlers/scheduled/analyzeCorrelations.js +0 -178
- package/src/handlers/scheduled/analyzeGitHistory.js +0 -510
- package/src/handlers/scheduled/generateAlerts.js +0 -135
- package/src/handlers/scheduled/maturityUpdateJob.js +0 -166
- package/src/handlers/scheduled/refreshActivity.js +0 -21
- package/src/handlers/scheduled/scanCompliance.js +0 -334
- package/src/handlers/sessions/sessionEndPost.js +0 -180
- package/src/handlers/sessions/sessionStandardsPost.js +0 -171
- package/src/handlers/standards/catalogGet.js +0 -185
- package/src/handlers/standards/catalogSync.js +0 -120
- package/src/handlers/standards/discoveriesGet.js +0 -89
- package/src/handlers/standards/projectStandardsGet.js +0 -129
- package/src/handlers/standards/projectStandardsPut.js +0 -151
- package/src/handlers/standards/standardsAuditGet.js +0 -65
- package/src/handlers/standards/standardsParseUpload.js +0 -149
- package/src/handlers/standards/standardsRelevantPost.js +0 -405
- package/src/handlers/standards/standardsTransition.js +0 -161
- package/src/handlers/stripe/addonManagePost.js +0 -240
- package/src/handlers/stripe/billingPortalPost.js +0 -93
- package/src/handlers/stripe/enterpriseCheckoutPost.js +0 -272
- package/src/handlers/stripe/seatsUpdatePost.js +0 -185
- package/src/handlers/stripe/subscriptionCancelDelete.js +0 -169
- package/src/handlers/stripe/subscriptionCreatePost.js +0 -221
- package/src/handlers/stripe/subscriptionUpdatePut.js +0 -163
- package/src/handlers/stripe/webhookPost.js +0 -482
- package/src/handlers/user/apiTokenCreate.js +0 -71
- package/src/handlers/user/apiTokenList.js +0 -64
- package/src/handlers/user/userSplashAck.js +0 -91
- package/src/handlers/user/userSplashGet.js +0 -211
- package/src/handlers/users/cognitoPostConfirmation.js +0 -186
- package/src/handlers/users/cognitoPreSignUp.js +0 -114
- package/src/handlers/users/userEntitlementsGet.js +0 -89
- package/src/handlers/users/userGet.js +0 -118
- package/src/handlers/users/userProfilePut.js +0 -77
- package/src/handlers/webhooks/githubWebhook.js +0 -215
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DeprecationScheduler.js - Scheduled Deprecation Management
|
|
3
|
-
*
|
|
4
|
-
* Handles the scheduled deprecation workflow for standards:
|
|
5
|
-
* 1. scheduleDeprecation - Marks a standard as deprecated with a grace period
|
|
6
|
-
* 2. processScheduledDeprecations - Deletes standards past their grace period
|
|
7
|
-
* 3. cancelDeprecation - Restores a deprecated standard back to active
|
|
8
|
-
*
|
|
9
|
-
* Called by scheduled Lambda / EventBridge for automatic cleanup,
|
|
10
|
-
* or directly by handlers for user-initiated actions.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
const { executeQuery } = require('../handlers/helpers/dbOperations');
|
|
14
|
-
const { StandardLifecycle, STATES } = require('./StandardLifecycle');
|
|
15
|
-
|
|
16
|
-
class DeprecationScheduler {
|
|
17
|
-
constructor(config = {}) {
|
|
18
|
-
this.config = {
|
|
19
|
-
defaultGracePeriodDays: config.defaultGracePeriodDays || 30,
|
|
20
|
-
...config
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
this.lifecycle = config.lifecycle || new StandardLifecycle();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Schedule a standard for deprecation with a grace period
|
|
28
|
-
*
|
|
29
|
-
* Sets deprecated_at and deprecation_reason on the standard,
|
|
30
|
-
* transitions state to 'deprecated', and records in audit trail.
|
|
31
|
-
*
|
|
32
|
-
* @param {string} standardId - The standard identifier
|
|
33
|
-
* @param {number} gracePeriodDays - Days before automatic deletion
|
|
34
|
-
* @param {string} userId - Email of the user scheduling deprecation
|
|
35
|
-
* @param {string} reason - Reason for deprecation
|
|
36
|
-
* @returns {Promise<Object>} Deprecation result
|
|
37
|
-
*/
|
|
38
|
-
async scheduleDeprecation(standardId, gracePeriodDays, userId, reason) {
|
|
39
|
-
const days = gracePeriodDays || this.config.defaultGracePeriodDays;
|
|
40
|
-
|
|
41
|
-
// Execute the lifecycle transition to deprecated
|
|
42
|
-
const transitionResult = await this.lifecycle.transition(
|
|
43
|
-
standardId,
|
|
44
|
-
'deprecate',
|
|
45
|
-
userId,
|
|
46
|
-
reason
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
// Set deprecation metadata on the standard
|
|
50
|
-
const deprecatedAt = new Date();
|
|
51
|
-
const deletionDate = new Date(deprecatedAt.getTime() + (days * 24 * 60 * 60 * 1000));
|
|
52
|
-
|
|
53
|
-
await executeQuery(`
|
|
54
|
-
UPDATE rapport.patterns
|
|
55
|
-
SET
|
|
56
|
-
deprecated_at = $2,
|
|
57
|
-
deprecation_reason = $3
|
|
58
|
-
WHERE pattern_id = $1
|
|
59
|
-
`, [standardId, deprecatedAt, reason]);
|
|
60
|
-
|
|
61
|
-
console.log(
|
|
62
|
-
`[DeprecationScheduler] Scheduled ${standardId} for deletion on ${deletionDate.toISOString()} ` +
|
|
63
|
-
`(${days} day grace period)`
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
standard_id: standardId,
|
|
68
|
-
old_state: transitionResult.old_state,
|
|
69
|
-
new_state: transitionResult.new_state,
|
|
70
|
-
deprecated_at: deprecatedAt.toISOString(),
|
|
71
|
-
grace_period_days: days,
|
|
72
|
-
scheduled_deletion: deletionDate.toISOString(),
|
|
73
|
-
reason: reason,
|
|
74
|
-
audit_entry: transitionResult.audit_entry
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Process all standards that have passed their grace period
|
|
80
|
-
*
|
|
81
|
-
* Finds deprecated standards where deprecated_at + grace period < now,
|
|
82
|
-
* and transitions them to 'deleted'.
|
|
83
|
-
*
|
|
84
|
-
* Intended to be called by a scheduled Lambda / EventBridge rule.
|
|
85
|
-
*
|
|
86
|
-
* @returns {Promise<Object>} Processing results
|
|
87
|
-
*/
|
|
88
|
-
async processScheduledDeprecations() {
|
|
89
|
-
const gracePeriodDays = this.config.defaultGracePeriodDays;
|
|
90
|
-
|
|
91
|
-
// Find standards past their grace period
|
|
92
|
-
const result = await executeQuery(`
|
|
93
|
-
SELECT pattern_id, deprecated_at, deprecation_reason
|
|
94
|
-
FROM rapport.patterns
|
|
95
|
-
WHERE lifecycle_state = $1
|
|
96
|
-
AND deprecated_at IS NOT NULL
|
|
97
|
-
AND deprecated_at + ($2 || ' days')::INTERVAL < NOW()
|
|
98
|
-
`, [STATES.DEPRECATED, gracePeriodDays]);
|
|
99
|
-
|
|
100
|
-
const standards = result.rows;
|
|
101
|
-
|
|
102
|
-
console.log(`[DeprecationScheduler] Found ${standards.length} standards past grace period`);
|
|
103
|
-
|
|
104
|
-
const processed = [];
|
|
105
|
-
const errors = [];
|
|
106
|
-
|
|
107
|
-
for (const standard of standards) {
|
|
108
|
-
try {
|
|
109
|
-
const transitionResult = await this.lifecycle.transition(
|
|
110
|
-
standard.pattern_id,
|
|
111
|
-
'delete',
|
|
112
|
-
'system@mindmeld.dev',
|
|
113
|
-
`Automatic deletion after ${gracePeriodDays}-day grace period. ` +
|
|
114
|
-
`Original reason: ${standard.deprecation_reason || 'Not specified'}`
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
processed.push({
|
|
118
|
-
standard_id: standard.pattern_id,
|
|
119
|
-
deprecated_at: standard.deprecated_at,
|
|
120
|
-
deleted_at: new Date().toISOString()
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
console.log(`[DeprecationScheduler] Deleted ${standard.pattern_id} (deprecated ${standard.deprecated_at})`);
|
|
124
|
-
} catch (error) {
|
|
125
|
-
console.error(`[DeprecationScheduler] Failed to delete ${standard.pattern_id}:`, error.message);
|
|
126
|
-
errors.push({
|
|
127
|
-
standard_id: standard.pattern_id,
|
|
128
|
-
error: error.message
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return {
|
|
134
|
-
total_found: standards.length,
|
|
135
|
-
processed: processed.length,
|
|
136
|
-
errors: errors.length,
|
|
137
|
-
deleted: processed,
|
|
138
|
-
failed: errors
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Cancel a scheduled deprecation and restore to active
|
|
144
|
-
*
|
|
145
|
-
* Transitions the standard back to 'active', clears deprecated_at
|
|
146
|
-
* and deprecation_reason, and records in audit trail.
|
|
147
|
-
*
|
|
148
|
-
* @param {string} standardId - The standard identifier
|
|
149
|
-
* @param {string} userId - Email of the user cancelling deprecation
|
|
150
|
-
* @param {string} reason - Reason for cancelling deprecation
|
|
151
|
-
* @returns {Promise<Object>} Cancellation result
|
|
152
|
-
*/
|
|
153
|
-
async cancelDeprecation(standardId, userId, reason) {
|
|
154
|
-
// Execute the lifecycle transition back to active
|
|
155
|
-
const transitionResult = await this.lifecycle.transition(
|
|
156
|
-
standardId,
|
|
157
|
-
'cancel_deprecation',
|
|
158
|
-
userId,
|
|
159
|
-
reason
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
// Clear deprecation metadata
|
|
163
|
-
await executeQuery(`
|
|
164
|
-
UPDATE rapport.patterns
|
|
165
|
-
SET
|
|
166
|
-
deprecated_at = NULL,
|
|
167
|
-
deprecation_reason = NULL
|
|
168
|
-
WHERE pattern_id = $1
|
|
169
|
-
`, [standardId]);
|
|
170
|
-
|
|
171
|
-
console.log(`[DeprecationScheduler] Cancelled deprecation for ${standardId} by ${userId}`);
|
|
172
|
-
|
|
173
|
-
return {
|
|
174
|
-
standard_id: standardId,
|
|
175
|
-
old_state: transitionResult.old_state,
|
|
176
|
-
new_state: transitionResult.new_state,
|
|
177
|
-
reason: reason,
|
|
178
|
-
audit_entry: transitionResult.audit_entry
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
module.exports = { DeprecationScheduler };
|
|
@@ -1,242 +0,0 @@
|
|
|
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;
|