@equilateral_ai/mindmeld 3.2.0 → 3.3.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 +4 -4
- package/hooks/README.md +46 -4
- package/hooks/pre-compact.js +87 -1
- package/hooks/session-end.js +292 -0
- package/hooks/session-start.js +292 -23
- package/package.json +4 -2
- package/scripts/auth-login.js +53 -0
- package/scripts/init-project.js +69 -375
- package/src/core/AuthManager.js +498 -0
- package/src/core/CrossReferenceEngine.js +624 -0
- package/src/core/DeprecationScheduler.js +183 -0
- package/src/core/LLMPatternDetector.js +218 -0
- package/src/core/RapportOrchestrator.js +186 -0
- package/src/core/RelevanceDetector.js +32 -2
- package/src/core/StandardLifecycle.js +244 -0
- package/src/core/StandardsIngestion.js +341 -28
- package/src/core/parsers/adrParser.js +479 -0
- package/src/core/parsers/cursorRulesParser.js +564 -0
- package/src/core/parsers/eslintParser.js +439 -0
- package/src/handlers/alerts/alertsAcknowledge.js +4 -3
- package/src/handlers/analytics/activitySummaryGet.js +235 -0
- package/src/handlers/analytics/coachingGet.js +361 -0
- package/src/handlers/analytics/developerScoreGet.js +207 -0
- package/src/handlers/collaborators/collaboratorAdd.js +4 -5
- package/src/handlers/collaborators/collaboratorInvite.js +6 -5
- package/src/handlers/collaborators/collaboratorList.js +3 -3
- package/src/handlers/collaborators/collaboratorRemove.js +5 -4
- package/src/handlers/correlations/correlationsDeveloperGet.js +12 -11
- package/src/handlers/correlations/correlationsGet.js +1 -1
- package/src/handlers/correlations/correlationsProjectGet.js +7 -6
- package/src/handlers/enterprise/enterpriseAuditGet.js +108 -0
- package/src/handlers/enterprise/enterpriseContributorsGet.js +85 -0
- package/src/handlers/enterprise/enterpriseKnowledgeCategoriesGet.js +53 -0
- package/src/handlers/enterprise/enterpriseKnowledgeCreate.js +77 -0
- package/src/handlers/enterprise/enterpriseKnowledgeDelete.js +71 -0
- package/src/handlers/enterprise/enterpriseKnowledgeGet.js +87 -0
- package/src/handlers/enterprise/enterpriseKnowledgeUpdate.js +122 -0
- package/src/handlers/enterprise/enterpriseOnboardingComplete.js +77 -0
- package/src/handlers/enterprise/enterpriseOnboardingInvite.js +138 -0
- package/src/handlers/enterprise/enterpriseOnboardingSetup.js +89 -0
- package/src/handlers/enterprise/enterpriseOnboardingStatus.js +90 -0
- package/src/handlers/github/githubConnectionStatus.js +1 -1
- package/src/handlers/github/githubDiscoverPatterns.js +264 -5
- package/src/handlers/github/githubOAuthCallback.js +14 -2
- package/src/handlers/github/githubOAuthStart.js +1 -1
- package/src/handlers/github/githubPatternsReview.js +1 -1
- package/src/handlers/github/githubReposList.js +1 -1
- package/src/handlers/helpers/auditLogger.js +201 -0
- package/src/handlers/helpers/index.js +19 -1
- package/src/handlers/helpers/lambdaWrapper.js +1 -1
- package/src/handlers/notifications/sendNotification.js +1 -1
- package/src/handlers/projects/projectCreate.js +28 -1
- package/src/handlers/projects/projectDelete.js +3 -3
- package/src/handlers/projects/projectUpdate.js +4 -5
- package/src/handlers/scheduled/analyzeCorrelations.js +3 -3
- package/src/handlers/scheduled/generateAlerts.js +1 -1
- package/src/handlers/standards/catalogGet.js +185 -0
- package/src/handlers/standards/catalogSync.js +120 -0
- package/src/handlers/standards/projectStandardsGet.js +135 -0
- package/src/handlers/standards/projectStandardsPut.js +131 -0
- package/src/handlers/standards/standardsAuditGet.js +65 -0
- package/src/handlers/standards/standardsParseUpload.js +153 -0
- package/src/handlers/standards/standardsRelevantPost.js +213 -0
- package/src/handlers/standards/standardsTransition.js +64 -0
- package/src/handlers/user/userSplashAck.js +91 -0
- package/src/handlers/user/userSplashGet.js +194 -0
- package/src/handlers/users/userProfilePut.js +77 -0
- package/src/index.js +37 -29
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StandardLifecycle.js - State Machine for Standard Lifecycle
|
|
3
|
+
*
|
|
4
|
+
* Manages the full lifecycle of standards from discovery through deletion.
|
|
5
|
+
*
|
|
6
|
+
* States: discovery -> proposed -> active -> disabled -> deprecated -> deleted
|
|
7
|
+
*
|
|
8
|
+
* Valid transitions:
|
|
9
|
+
* discovery -> proposed (when confidence > threshold)
|
|
10
|
+
* proposed -> active (user approves)
|
|
11
|
+
* proposed -> deleted (user rejects)
|
|
12
|
+
* active -> disabled (user disables temporarily)
|
|
13
|
+
* active -> deprecated (scheduled for removal)
|
|
14
|
+
* disabled -> active (user re-enables)
|
|
15
|
+
* deprecated -> deleted (after grace period)
|
|
16
|
+
* deprecated -> active (user cancels deprecation)
|
|
17
|
+
*
|
|
18
|
+
* Records every transition in standards_audit_trail table.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const { executeQuery } = require('../handlers/helpers/dbOperations');
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* All valid lifecycle states
|
|
25
|
+
*/
|
|
26
|
+
const STATES = {
|
|
27
|
+
DISCOVERY: 'discovery',
|
|
28
|
+
PROPOSED: 'proposed',
|
|
29
|
+
ACTIVE: 'active',
|
|
30
|
+
DISABLED: 'disabled',
|
|
31
|
+
DEPRECATED: 'deprecated',
|
|
32
|
+
DELETED: 'deleted'
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* All valid transition actions and their from -> to mappings
|
|
37
|
+
*/
|
|
38
|
+
const TRANSITIONS = {
|
|
39
|
+
propose: { from: STATES.DISCOVERY, to: STATES.PROPOSED },
|
|
40
|
+
approve: { from: STATES.PROPOSED, to: STATES.ACTIVE },
|
|
41
|
+
reject: { from: STATES.PROPOSED, to: STATES.DELETED },
|
|
42
|
+
disable: { from: STATES.ACTIVE, to: STATES.DISABLED },
|
|
43
|
+
deprecate: { from: STATES.ACTIVE, to: STATES.DEPRECATED },
|
|
44
|
+
enable: { from: STATES.DISABLED, to: STATES.ACTIVE },
|
|
45
|
+
delete: { from: STATES.DEPRECATED, to: STATES.DELETED },
|
|
46
|
+
cancel_deprecation: { from: STATES.DEPRECATED, to: STATES.ACTIVE }
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
class StandardLifecycle {
|
|
50
|
+
constructor(config = {}) {
|
|
51
|
+
this.config = {
|
|
52
|
+
confidenceThreshold: config.confidenceThreshold || 0.80,
|
|
53
|
+
...config
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Execute a state transition for a standard
|
|
59
|
+
*
|
|
60
|
+
* @param {string} standardId - The standard identifier
|
|
61
|
+
* @param {string} action - The transition action to perform
|
|
62
|
+
* @param {string} userId - Email of the user performing the action
|
|
63
|
+
* @param {string} reason - Optional reason for the transition
|
|
64
|
+
* @returns {Promise<Object>} The transition result with new state and audit entry
|
|
65
|
+
*/
|
|
66
|
+
async transition(standardId, action, userId, reason) {
|
|
67
|
+
// Validate action exists
|
|
68
|
+
const transitionDef = TRANSITIONS[action];
|
|
69
|
+
if (!transitionDef) {
|
|
70
|
+
const validActions = Object.keys(TRANSITIONS);
|
|
71
|
+
throw new Error(`Invalid action '${action}'. Valid actions: ${validActions.join(', ')}`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Get current state of the standard
|
|
75
|
+
const currentState = await this.getCurrentState(standardId);
|
|
76
|
+
|
|
77
|
+
if (!currentState) {
|
|
78
|
+
throw new Error(`Standard '${standardId}' not found`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Validate the transition is allowed from the current state
|
|
82
|
+
if (currentState !== transitionDef.from) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`Cannot perform '${action}' on standard in '${currentState}' state. ` +
|
|
85
|
+
`Action '${action}' requires state '${transitionDef.from}'.`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const oldState = currentState;
|
|
90
|
+
const newState = transitionDef.to;
|
|
91
|
+
|
|
92
|
+
// Update the standard's lifecycle state
|
|
93
|
+
await executeQuery(`
|
|
94
|
+
UPDATE rapport.patterns
|
|
95
|
+
SET lifecycle_state = $2
|
|
96
|
+
WHERE pattern_id = $1
|
|
97
|
+
`, [standardId, newState]);
|
|
98
|
+
|
|
99
|
+
// Record the transition in the audit trail
|
|
100
|
+
const auditResult = await executeQuery(`
|
|
101
|
+
INSERT INTO rapport.standards_audit_trail (
|
|
102
|
+
standard_id,
|
|
103
|
+
project_id,
|
|
104
|
+
action,
|
|
105
|
+
old_state,
|
|
106
|
+
new_state,
|
|
107
|
+
user_email,
|
|
108
|
+
reason,
|
|
109
|
+
metadata,
|
|
110
|
+
created_at
|
|
111
|
+
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, NOW())
|
|
112
|
+
RETURNING id, standard_id, action, old_state, new_state, user_email, reason, created_at
|
|
113
|
+
`, [
|
|
114
|
+
standardId,
|
|
115
|
+
null,
|
|
116
|
+
action,
|
|
117
|
+
oldState,
|
|
118
|
+
newState,
|
|
119
|
+
userId,
|
|
120
|
+
reason || null,
|
|
121
|
+
JSON.stringify({})
|
|
122
|
+
]);
|
|
123
|
+
|
|
124
|
+
const auditEntry = auditResult.rows[0];
|
|
125
|
+
|
|
126
|
+
console.log(`[StandardLifecycle] ${standardId}: ${oldState} -> ${newState} (${action}) by ${userId}`);
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
standard_id: standardId,
|
|
130
|
+
old_state: oldState,
|
|
131
|
+
new_state: newState,
|
|
132
|
+
action: action,
|
|
133
|
+
audit_entry: auditEntry
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Get valid transitions available from the current state
|
|
139
|
+
*
|
|
140
|
+
* @param {string} currentState - The current lifecycle state
|
|
141
|
+
* @returns {Array<Object>} Available actions with their target states
|
|
142
|
+
*/
|
|
143
|
+
getValidTransitions(currentState) {
|
|
144
|
+
const valid = [];
|
|
145
|
+
|
|
146
|
+
for (const [action, def] of Object.entries(TRANSITIONS)) {
|
|
147
|
+
if (def.from === currentState) {
|
|
148
|
+
valid.push({
|
|
149
|
+
action: action,
|
|
150
|
+
from: def.from,
|
|
151
|
+
to: def.to
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return valid;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Get the full audit trail for a standard
|
|
161
|
+
*
|
|
162
|
+
* @param {string} standardId - The standard identifier
|
|
163
|
+
* @param {Object} options - Pagination options
|
|
164
|
+
* @param {string} options.cursor - Cursor for pagination (audit trail id)
|
|
165
|
+
* @param {number} options.limit - Number of records to return (default 50)
|
|
166
|
+
* @returns {Promise<Object>} Audit trail with entries and pagination info
|
|
167
|
+
*/
|
|
168
|
+
async getHistory(standardId, options = {}) {
|
|
169
|
+
const limit = Math.min(parseInt(options.limit) || 50, 200);
|
|
170
|
+
const cursor = options.cursor ? parseInt(options.cursor) : null;
|
|
171
|
+
|
|
172
|
+
let query = `
|
|
173
|
+
SELECT
|
|
174
|
+
id,
|
|
175
|
+
standard_id,
|
|
176
|
+
project_id,
|
|
177
|
+
action,
|
|
178
|
+
old_state,
|
|
179
|
+
new_state,
|
|
180
|
+
user_email,
|
|
181
|
+
reason,
|
|
182
|
+
metadata,
|
|
183
|
+
created_at
|
|
184
|
+
FROM rapport.standards_audit_trail
|
|
185
|
+
WHERE standard_id = $1
|
|
186
|
+
`;
|
|
187
|
+
|
|
188
|
+
const params = [standardId];
|
|
189
|
+
let paramIndex = 2;
|
|
190
|
+
|
|
191
|
+
if (cursor) {
|
|
192
|
+
query += ` AND id < $${paramIndex}`;
|
|
193
|
+
params.push(cursor);
|
|
194
|
+
paramIndex++;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
query += ` ORDER BY created_at DESC, id DESC LIMIT $${paramIndex}`;
|
|
198
|
+
params.push(limit + 1); // Fetch one extra to determine if there are more
|
|
199
|
+
|
|
200
|
+
const result = await executeQuery(query, params);
|
|
201
|
+
|
|
202
|
+
const hasMore = result.rows.length > limit;
|
|
203
|
+
const entries = hasMore ? result.rows.slice(0, limit) : result.rows;
|
|
204
|
+
const nextCursor = hasMore ? entries[entries.length - 1].id : null;
|
|
205
|
+
|
|
206
|
+
// Get total count
|
|
207
|
+
const countResult = await executeQuery(`
|
|
208
|
+
SELECT COUNT(*) as total
|
|
209
|
+
FROM rapport.standards_audit_trail
|
|
210
|
+
WHERE standard_id = $1
|
|
211
|
+
`, [standardId]);
|
|
212
|
+
|
|
213
|
+
const totalTransitions = parseInt(countResult.rows[0].total);
|
|
214
|
+
|
|
215
|
+
return {
|
|
216
|
+
entries: entries,
|
|
217
|
+
total_transitions: totalTransitions,
|
|
218
|
+
has_more: hasMore,
|
|
219
|
+
next_cursor: nextCursor ? String(nextCursor) : null
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Get the current lifecycle state of a standard
|
|
225
|
+
*
|
|
226
|
+
* @param {string} standardId - The standard identifier
|
|
227
|
+
* @returns {Promise<string|null>} Current state or null if not found
|
|
228
|
+
*/
|
|
229
|
+
async getCurrentState(standardId) {
|
|
230
|
+
const result = await executeQuery(`
|
|
231
|
+
SELECT lifecycle_state
|
|
232
|
+
FROM rapport.patterns
|
|
233
|
+
WHERE pattern_id = $1
|
|
234
|
+
`, [standardId]);
|
|
235
|
+
|
|
236
|
+
if (result.rowCount === 0) {
|
|
237
|
+
return null;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return result.rows[0].lifecycle_state || STATES.ACTIVE;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
module.exports = { StandardLifecycle, STATES, TRANSITIONS };
|