@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.
- package/README.md +300 -0
- package/hooks/README.md +494 -0
- package/hooks/pre-compact.js +392 -0
- package/hooks/session-start.js +264 -0
- package/package.json +90 -0
- package/scripts/harvest.js +561 -0
- package/scripts/init-project.js +437 -0
- package/scripts/inject.js +388 -0
- package/src/collaboration/CollaborationPrompt.js +460 -0
- package/src/core/AlertEngine.js +813 -0
- package/src/core/AlertNotifier.js +363 -0
- package/src/core/CorrelationAnalyzer.js +774 -0
- package/src/core/CurationEngine.js +688 -0
- package/src/core/LLMPatternDetector.js +508 -0
- package/src/core/LoadBearingDetector.js +242 -0
- package/src/core/NotificationService.js +1032 -0
- package/src/core/PatternValidator.js +355 -0
- package/src/core/README.md +160 -0
- package/src/core/RapportOrchestrator.js +446 -0
- package/src/core/RelevanceDetector.js +577 -0
- package/src/core/StandardsIngestion.js +575 -0
- package/src/core/TeamLoadBearingDetector.js +431 -0
- package/src/database/dbOperations.js +105 -0
- package/src/handlers/activity/activityGetMe.js +98 -0
- package/src/handlers/activity/activityGetTeam.js +130 -0
- package/src/handlers/alerts/alertsAcknowledge.js +91 -0
- package/src/handlers/alerts/alertsGet.js +250 -0
- package/src/handlers/collaborators/collaboratorAdd.js +201 -0
- package/src/handlers/collaborators/collaboratorInvite.js +218 -0
- package/src/handlers/collaborators/collaboratorList.js +88 -0
- package/src/handlers/collaborators/collaboratorRemove.js +127 -0
- package/src/handlers/collaborators/inviteAccept.js +122 -0
- package/src/handlers/context/contextGet.js +57 -0
- package/src/handlers/context/invariantsGet.js +74 -0
- package/src/handlers/context/loopsGet.js +82 -0
- package/src/handlers/context/notesCreate.js +74 -0
- package/src/handlers/context/purposeGet.js +78 -0
- package/src/handlers/correlations/correlationsDeveloperGet.js +226 -0
- package/src/handlers/correlations/correlationsGet.js +93 -0
- package/src/handlers/correlations/correlationsProjectGet.js +161 -0
- package/src/handlers/github/githubConnectionStatus.js +49 -0
- package/src/handlers/github/githubDiscoverPatterns.js +364 -0
- package/src/handlers/github/githubOAuthCallback.js +166 -0
- package/src/handlers/github/githubOAuthStart.js +59 -0
- package/src/handlers/github/githubPatternsReview.js +109 -0
- package/src/handlers/github/githubReposList.js +105 -0
- package/src/handlers/helpers/checkSuperAdmin.js +85 -0
- package/src/handlers/helpers/dbOperations.js +53 -0
- package/src/handlers/helpers/errorHandler.js +49 -0
- package/src/handlers/helpers/index.js +106 -0
- package/src/handlers/helpers/lambdaWrapper.js +60 -0
- package/src/handlers/helpers/responseUtil.js +55 -0
- package/src/handlers/helpers/subscriptionTiers.js +1168 -0
- package/src/handlers/notifications/getPreferences.js +84 -0
- package/src/handlers/notifications/sendNotification.js +170 -0
- package/src/handlers/notifications/updatePreferences.js +316 -0
- package/src/handlers/patterns/patternUsagePost.js +182 -0
- package/src/handlers/patterns/patternViolationPost.js +185 -0
- package/src/handlers/projects/projectCreate.js +107 -0
- package/src/handlers/projects/projectDelete.js +82 -0
- package/src/handlers/projects/projectGet.js +95 -0
- package/src/handlers/projects/projectUpdate.js +118 -0
- package/src/handlers/reports/aiLeverage.js +206 -0
- package/src/handlers/reports/engineeringInvestment.js +132 -0
- package/src/handlers/reports/riskForecast.js +186 -0
- package/src/handlers/reports/standardsRoi.js +162 -0
- package/src/handlers/scheduled/analyzeCorrelations.js +178 -0
- package/src/handlers/scheduled/analyzeGitHistory.js +510 -0
- package/src/handlers/scheduled/generateAlerts.js +135 -0
- package/src/handlers/scheduled/refreshActivity.js +21 -0
- package/src/handlers/scheduled/scanCompliance.js +334 -0
- package/src/handlers/sessions/sessionEndPost.js +180 -0
- package/src/handlers/sessions/sessionStandardsPost.js +135 -0
- package/src/handlers/stripe/addonManagePost.js +240 -0
- package/src/handlers/stripe/billingPortalPost.js +93 -0
- package/src/handlers/stripe/enterpriseCheckoutPost.js +272 -0
- package/src/handlers/stripe/seatsUpdatePost.js +185 -0
- package/src/handlers/stripe/subscriptionCancelDelete.js +169 -0
- package/src/handlers/stripe/subscriptionCreatePost.js +221 -0
- package/src/handlers/stripe/subscriptionUpdatePut.js +163 -0
- package/src/handlers/stripe/webhookPost.js +454 -0
- package/src/handlers/users/cognitoPostConfirmation.js +150 -0
- package/src/handlers/users/userEntitlementsGet.js +89 -0
- package/src/handlers/users/userGet.js +114 -0
- package/src/handlers/webhooks/githubWebhook.js +223 -0
- package/src/index.js +969 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standards ROI Report Handler
|
|
3
|
+
* Our key differentiator - correlation between standards and code quality
|
|
4
|
+
*
|
|
5
|
+
* GET /api/reports/standards-roi
|
|
6
|
+
* Query: ?period=7d|30d|90d&Company_ID=xxx
|
|
7
|
+
* Auth: Cognito JWT required, Manager or Admin role
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const { wrapHandler, executeQuery, createSuccessResponse, createErrorResponse } = require('./helpers');
|
|
11
|
+
|
|
12
|
+
exports.handler = wrapHandler(async ({ requestContext, queryStringParameters }) => {
|
|
13
|
+
const email = requestContext.authorizer?.claims?.email || requestContext.authorizer?.jwt?.claims?.email;
|
|
14
|
+
|
|
15
|
+
if (!email) {
|
|
16
|
+
return createErrorResponse(401, 'Unauthorized');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const params = queryStringParameters || {};
|
|
20
|
+
const period = params.period || '30d';
|
|
21
|
+
const companyId = params.Company_ID;
|
|
22
|
+
|
|
23
|
+
// Validate access - must be manager/admin (boolean columns in Tim-Combo schema)
|
|
24
|
+
const accessCheck = await executeQuery(`
|
|
25
|
+
SELECT ue."Company_ID"
|
|
26
|
+
FROM "UserEntitlements" ue
|
|
27
|
+
WHERE ue."Email_Address" = $1
|
|
28
|
+
AND (ue."Admin" = true OR ue."Manager" = true)
|
|
29
|
+
${companyId ? 'AND ue."Company_ID" = $2' : ''}
|
|
30
|
+
LIMIT 1
|
|
31
|
+
`, companyId ? [email, companyId] : [email]);
|
|
32
|
+
|
|
33
|
+
if (accessCheck.rows.length === 0) {
|
|
34
|
+
return createErrorResponse(403, 'Manager or Admin access required');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const userCompanyId = companyId || accessCheck.rows[0].Company_ID;
|
|
38
|
+
const periodDays = parsePeriod(period);
|
|
39
|
+
const periodStart = new Date();
|
|
40
|
+
periodStart.setDate(periodStart.getDate() - periodDays);
|
|
41
|
+
|
|
42
|
+
// Standards compliance by developer (from developer_metrics)
|
|
43
|
+
let compliance = { rows: [] };
|
|
44
|
+
try {
|
|
45
|
+
compliance = await executeQuery(`
|
|
46
|
+
SELECT
|
|
47
|
+
dm.developer_email,
|
|
48
|
+
dm.developer_name,
|
|
49
|
+
SUM(dm.commit_count) as total_commits,
|
|
50
|
+
SUM(dm.standards_compliant_commits) as compliant_commits,
|
|
51
|
+
AVG(dm.compliance_score) as avg_compliance_score,
|
|
52
|
+
SUM(dm.anti_pattern_commits) as anti_pattern_commits
|
|
53
|
+
FROM rapport.developer_metrics dm
|
|
54
|
+
JOIN rapport.git_repositories r ON dm.repo_id = r.repo_id
|
|
55
|
+
WHERE r."Company_ID" = $1
|
|
56
|
+
AND dm.period_start >= $2
|
|
57
|
+
GROUP BY dm.developer_email, dm.developer_name
|
|
58
|
+
HAVING SUM(dm.commit_count) > 0
|
|
59
|
+
ORDER BY avg_compliance_score DESC NULLS LAST
|
|
60
|
+
`, [userCompanyId, periodStart]);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
// Table might not have data yet
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Code patterns detected
|
|
66
|
+
let patterns = { rows: [] };
|
|
67
|
+
try {
|
|
68
|
+
patterns = await executeQuery(`
|
|
69
|
+
SELECT
|
|
70
|
+
cp.pattern_name,
|
|
71
|
+
cp.pattern_type,
|
|
72
|
+
cp.severity,
|
|
73
|
+
cp.language,
|
|
74
|
+
cp.description
|
|
75
|
+
FROM rapport.code_patterns cp
|
|
76
|
+
WHERE cp.enabled = true
|
|
77
|
+
ORDER BY cp.pattern_type, cp.severity
|
|
78
|
+
LIMIT 20
|
|
79
|
+
`, []);
|
|
80
|
+
} catch (e) {
|
|
81
|
+
// Table might not exist
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Calculate summary metrics
|
|
85
|
+
const complianceData = compliance.rows;
|
|
86
|
+
const avgCompliance = complianceData.length > 0
|
|
87
|
+
? complianceData.reduce((sum, r) => sum + parseFloat(r.avg_compliance_score || 0), 0) / complianceData.length
|
|
88
|
+
: 0;
|
|
89
|
+
|
|
90
|
+
const totalCommits = complianceData.reduce((sum, r) => sum + parseInt(r.total_commits || 0), 0);
|
|
91
|
+
const compliantCommits = complianceData.reduce((sum, r) => sum + parseInt(r.compliant_commits || 0), 0);
|
|
92
|
+
const antiPatternCommits = complianceData.reduce((sum, r) => sum + parseInt(r.anti_pattern_commits || 0), 0);
|
|
93
|
+
|
|
94
|
+
return createSuccessResponse({
|
|
95
|
+
report_type: 'standards_roi',
|
|
96
|
+
period: period,
|
|
97
|
+
period_start: periodStart.toISOString(),
|
|
98
|
+
period_end: new Date().toISOString(),
|
|
99
|
+
summary: {
|
|
100
|
+
avg_compliance_score: avgCompliance.toFixed(1),
|
|
101
|
+
total_commits: totalCommits,
|
|
102
|
+
compliant_commits: compliantCommits,
|
|
103
|
+
compliance_rate: totalCommits > 0 ? ((compliantCommits / totalCommits) * 100).toFixed(1) : '0',
|
|
104
|
+
anti_pattern_commits: antiPatternCommits,
|
|
105
|
+
anti_pattern_rate: totalCommits > 0 ? ((antiPatternCommits / totalCommits) * 100).toFixed(1) : '0',
|
|
106
|
+
patterns_configured: patterns.rows.length
|
|
107
|
+
},
|
|
108
|
+
compliance_by_developer: complianceData,
|
|
109
|
+
configured_patterns: patterns.rows.filter(p => p.pattern_type === 'standard'),
|
|
110
|
+
anti_patterns: patterns.rows.filter(p => p.pattern_type === 'anti_pattern'),
|
|
111
|
+
insights: generateInsights(complianceData)
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
function generateInsights(compliance) {
|
|
116
|
+
const insights = [];
|
|
117
|
+
|
|
118
|
+
if (compliance.length === 0) {
|
|
119
|
+
insights.push({
|
|
120
|
+
type: 'info',
|
|
121
|
+
message: 'No developer metrics available yet. Connect a git repository to start tracking.'
|
|
122
|
+
});
|
|
123
|
+
return insights;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Compliance insights
|
|
127
|
+
const highPerformers = compliance.filter(d => parseFloat(d.avg_compliance_score || 0) >= 80);
|
|
128
|
+
const lowPerformers = compliance.filter(d => parseFloat(d.avg_compliance_score || 0) < 50 && parseInt(d.total_commits) > 5);
|
|
129
|
+
|
|
130
|
+
if (highPerformers.length > 0) {
|
|
131
|
+
insights.push({
|
|
132
|
+
type: 'positive',
|
|
133
|
+
message: `${highPerformers.length} developer(s) maintaining >80% compliance score`,
|
|
134
|
+
developers: highPerformers.map(d => d.developer_name || d.developer_email)
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (lowPerformers.length > 0) {
|
|
139
|
+
insights.push({
|
|
140
|
+
type: 'attention',
|
|
141
|
+
message: `${lowPerformers.length} developer(s) below 50% compliance - may benefit from standards training`,
|
|
142
|
+
developers: lowPerformers.map(d => d.developer_name || d.developer_email)
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return insights;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function parsePeriod(period) {
|
|
150
|
+
const match = period.match(/^(\d+)([dwm])$/);
|
|
151
|
+
if (!match) return 30;
|
|
152
|
+
|
|
153
|
+
const [, num, unit] = match;
|
|
154
|
+
const n = parseInt(num);
|
|
155
|
+
|
|
156
|
+
switch (unit) {
|
|
157
|
+
case 'd': return n;
|
|
158
|
+
case 'w': return n * 7;
|
|
159
|
+
case 'm': return n * 30;
|
|
160
|
+
default: return 30;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analyze Correlations Scheduled Job
|
|
3
|
+
* Correlates Claude Code sessions with git commits
|
|
4
|
+
*
|
|
5
|
+
* Schedule: Every 2 hours (or triggered via API)
|
|
6
|
+
* Auth: None (Lambda scheduled event)
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - Session-to-commit correlation by timestamp proximity
|
|
10
|
+
* - Pattern success tracking
|
|
11
|
+
* - Struggle detection (sessions without commits)
|
|
12
|
+
* - Aggregate productivity metrics
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const { wrapHandler, executeQuery, createSuccessResponse } = require('./helpers');
|
|
16
|
+
const { CorrelationAnalyzer } = require('../../core/CorrelationAnalyzer');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Main handler - wrapped with wrapHandler for consistent error handling
|
|
20
|
+
*/
|
|
21
|
+
exports.handler = wrapHandler(async (event, context) => {
|
|
22
|
+
console.log('[AnalyzeCorrelations] Starting correlation analysis job...');
|
|
23
|
+
|
|
24
|
+
// Parse options from event (allows manual triggering with specific parameters)
|
|
25
|
+
const options = parseEventOptions(event);
|
|
26
|
+
|
|
27
|
+
// Initialize analyzer with default config
|
|
28
|
+
const analyzer = new CorrelationAnalyzer();
|
|
29
|
+
|
|
30
|
+
// Run correlation analysis
|
|
31
|
+
const summary = await analyzer.analyzeCorrelations(options);
|
|
32
|
+
|
|
33
|
+
// Log results
|
|
34
|
+
console.log('[AnalyzeCorrelations] Analysis summary:', JSON.stringify(summary, null, 2));
|
|
35
|
+
|
|
36
|
+
// If running for specific company, also generate struggling developer alerts
|
|
37
|
+
if (options.companyId && summary.uncorrelatedSessions > 0) {
|
|
38
|
+
const strugglingDevs = await analyzer.identifyStrugglingDevelopers(
|
|
39
|
+
options.companyId,
|
|
40
|
+
options.lookbackDays || 30
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
if (strugglingDevs.length > 0) {
|
|
44
|
+
console.log(`[AnalyzeCorrelations] Found ${strugglingDevs.length} potentially struggling developers`);
|
|
45
|
+
|
|
46
|
+
// Create alerts for struggling developers
|
|
47
|
+
await createStrugglingDeveloperAlerts(options.companyId, strugglingDevs);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return createSuccessResponse({
|
|
52
|
+
sessionsAnalyzed: summary.sessionsAnalyzed,
|
|
53
|
+
correlationsCreated: summary.correlationsCreated,
|
|
54
|
+
uncorrelatedSessions: summary.uncorrelatedSessions,
|
|
55
|
+
patternCorrelations: summary.patternCorrelations,
|
|
56
|
+
errors: summary.errors.length,
|
|
57
|
+
duration: calculateDuration(summary.startedAt, summary.completedAt)
|
|
58
|
+
}, 'Correlation analysis complete');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Parse options from Lambda event
|
|
63
|
+
*
|
|
64
|
+
* @param {Object} event - Lambda event
|
|
65
|
+
* @returns {Object} Parsed options
|
|
66
|
+
*/
|
|
67
|
+
function parseEventOptions(event) {
|
|
68
|
+
const options = {
|
|
69
|
+
lookbackDays: 30
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// Support both direct invocation and API Gateway trigger
|
|
73
|
+
if (event.body) {
|
|
74
|
+
try {
|
|
75
|
+
const body = typeof event.body === 'string' ? JSON.parse(event.body) : event.body;
|
|
76
|
+
options.projectId = body.projectId;
|
|
77
|
+
options.companyId = body.companyId;
|
|
78
|
+
options.lookbackDays = body.lookbackDays || 30;
|
|
79
|
+
} catch (e) {
|
|
80
|
+
console.log('[AnalyzeCorrelations] Could not parse event body:', e.message);
|
|
81
|
+
}
|
|
82
|
+
} else if (event.projectId || event.companyId) {
|
|
83
|
+
// Direct invocation with parameters
|
|
84
|
+
options.projectId = event.projectId;
|
|
85
|
+
options.companyId = event.companyId;
|
|
86
|
+
options.lookbackDays = event.lookbackDays || 30;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return options;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Create alerts for struggling developers
|
|
94
|
+
*
|
|
95
|
+
* @param {string} companyId - Company ID
|
|
96
|
+
* @param {Array} developers - Struggling developers list
|
|
97
|
+
*/
|
|
98
|
+
async function createStrugglingDeveloperAlerts(companyId, developers) {
|
|
99
|
+
const cooldownHours = 24;
|
|
100
|
+
|
|
101
|
+
for (const dev of developers) {
|
|
102
|
+
try {
|
|
103
|
+
// Check if alert already exists within cooldown period
|
|
104
|
+
const existingCheck = await executeQuery(`
|
|
105
|
+
SELECT 1 FROM rapport.attention_alerts
|
|
106
|
+
WHERE email_address = $1
|
|
107
|
+
AND alert_type = 'low_conversion'
|
|
108
|
+
AND (status = 'active' OR created_at > NOW() - INTERVAL '${cooldownHours} hours')
|
|
109
|
+
LIMIT 1
|
|
110
|
+
`, [dev.email]);
|
|
111
|
+
|
|
112
|
+
if (existingCheck.rows.length > 0) {
|
|
113
|
+
console.log(`[AnalyzeCorrelations] Skipping alert for ${dev.email} - already exists`);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Determine severity based on unproductive rate
|
|
118
|
+
let severity = 'info';
|
|
119
|
+
if (dev.unproductiveRate >= 80) {
|
|
120
|
+
severity = 'critical';
|
|
121
|
+
} else if (dev.unproductiveRate >= 60) {
|
|
122
|
+
severity = 'warning';
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Create alert
|
|
126
|
+
await executeQuery(`
|
|
127
|
+
INSERT INTO rapport.attention_alerts (
|
|
128
|
+
email_address,
|
|
129
|
+
company_id,
|
|
130
|
+
alert_type,
|
|
131
|
+
severity,
|
|
132
|
+
details,
|
|
133
|
+
expires_at
|
|
134
|
+
) VALUES ($1, $2, 'low_conversion', $3, $4, NOW() + INTERVAL '7 days')
|
|
135
|
+
`, [
|
|
136
|
+
dev.email,
|
|
137
|
+
companyId,
|
|
138
|
+
severity,
|
|
139
|
+
JSON.stringify({
|
|
140
|
+
total_sessions: dev.totalSessions,
|
|
141
|
+
unproductive_sessions: dev.unproductiveSessions,
|
|
142
|
+
unproductive_rate: dev.unproductiveRate,
|
|
143
|
+
last_productive_session: dev.lastProductiveSession,
|
|
144
|
+
avg_session_minutes: dev.avgSessionMinutes,
|
|
145
|
+
generated_by: 'CorrelationAnalyzer'
|
|
146
|
+
})
|
|
147
|
+
]);
|
|
148
|
+
|
|
149
|
+
console.log(`[AnalyzeCorrelations] Created ${severity} alert for ${dev.email}`);
|
|
150
|
+
|
|
151
|
+
} catch (error) {
|
|
152
|
+
console.error(`[AnalyzeCorrelations] Error creating alert for ${dev.email}:`, error.message);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Calculate duration between two ISO timestamps
|
|
159
|
+
*
|
|
160
|
+
* @param {string} start - Start timestamp
|
|
161
|
+
* @param {string} end - End timestamp
|
|
162
|
+
* @returns {string} Duration string
|
|
163
|
+
*/
|
|
164
|
+
function calculateDuration(start, end) {
|
|
165
|
+
if (!start || !end) return 'unknown';
|
|
166
|
+
|
|
167
|
+
const startTime = new Date(start);
|
|
168
|
+
const endTime = new Date(end);
|
|
169
|
+
const durationMs = endTime - startTime;
|
|
170
|
+
|
|
171
|
+
if (durationMs < 1000) {
|
|
172
|
+
return `${durationMs}ms`;
|
|
173
|
+
} else if (durationMs < 60000) {
|
|
174
|
+
return `${Math.round(durationMs / 1000)}s`;
|
|
175
|
+
} else {
|
|
176
|
+
return `${Math.round(durationMs / 60000)}m ${Math.round((durationMs % 60000) / 1000)}s`;
|
|
177
|
+
}
|
|
178
|
+
}
|