monora-ai 2.0.0 → 2.1.3

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 (202) hide show
  1. package/README.md +441 -150
  2. package/dist/aims_governance.d.ts +238 -0
  3. package/dist/aims_governance.d.ts.map +1 -0
  4. package/dist/aims_governance.js +922 -0
  5. package/dist/alerts.d.ts +16 -0
  6. package/dist/alerts.d.ts.map +1 -1
  7. package/dist/alerts.js +16 -0
  8. package/dist/api.d.ts +6 -0
  9. package/dist/api.d.ts.map +1 -1
  10. package/dist/api.js +6 -0
  11. package/dist/assessment.d.ts +269 -0
  12. package/dist/assessment.d.ts.map +1 -0
  13. package/dist/assessment.js +1232 -0
  14. package/dist/attestation.js +23 -1
  15. package/dist/attribution.d.ts +349 -0
  16. package/dist/attribution.d.ts.map +1 -0
  17. package/dist/attribution.js +987 -0
  18. package/dist/autodetect.d.ts +69 -1
  19. package/dist/autodetect.d.ts.map +1 -1
  20. package/dist/autodetect.js +644 -1
  21. package/dist/bias.d.ts +130 -0
  22. package/dist/bias.d.ts.map +1 -0
  23. package/dist/bias.js +223 -0
  24. package/dist/circuit_breaker.js +3 -3
  25. package/dist/cli/diagnostics.d.ts +5 -1
  26. package/dist/cli/diagnostics.d.ts.map +1 -1
  27. package/dist/cli/diagnostics.js +31 -8
  28. package/dist/cli/doctor.d.ts +25 -0
  29. package/dist/cli/doctor.d.ts.map +1 -0
  30. package/dist/cli/doctor.js +381 -0
  31. package/dist/cli/fix.d.ts +16 -0
  32. package/dist/cli/fix.d.ts.map +1 -0
  33. package/dist/cli/fix.js +284 -0
  34. package/dist/cli/init.d.ts +57 -0
  35. package/dist/cli/init.d.ts.map +1 -0
  36. package/dist/cli/init.js +205 -0
  37. package/dist/cli.js +1611 -126
  38. package/dist/complianceTargets.d.ts +111 -0
  39. package/dist/complianceTargets.d.ts.map +1 -0
  40. package/dist/complianceTargets.js +521 -0
  41. package/dist/config.d.ts +301 -17
  42. package/dist/config.d.ts.map +1 -1
  43. package/dist/config.js +428 -36
  44. package/dist/config_migrations.d.ts +41 -0
  45. package/dist/config_migrations.d.ts.map +1 -1
  46. package/dist/config_migrations.js +205 -0
  47. package/dist/config_schema.d.ts +2900 -731
  48. package/dist/config_schema.d.ts.map +1 -1
  49. package/dist/config_schema.js +257 -55
  50. package/dist/context.d.ts +34 -0
  51. package/dist/context.d.ts.map +1 -1
  52. package/dist/context.js +118 -7
  53. package/dist/control_backbone.d.ts +122 -0
  54. package/dist/control_backbone.d.ts.map +1 -0
  55. package/dist/control_backbone.js +698 -0
  56. package/dist/data-governance.d.ts +187 -0
  57. package/dist/data-governance.d.ts.map +1 -0
  58. package/dist/data-governance.js +424 -0
  59. package/dist/dataResidency.d.ts +44 -0
  60. package/dist/dataResidency.d.ts.map +1 -0
  61. package/dist/dataResidency.js +203 -0
  62. package/dist/dispatcher.d.ts +32 -0
  63. package/dist/dispatcher.d.ts.map +1 -1
  64. package/dist/dispatcher.js +91 -4
  65. package/dist/events.d.ts.map +1 -1
  66. package/dist/events.js +38 -0
  67. package/dist/evidence_store.d.ts +103 -0
  68. package/dist/evidence_store.d.ts.map +1 -0
  69. package/dist/evidence_store.js +459 -0
  70. package/dist/executiveSummary.d.ts +65 -8
  71. package/dist/executiveSummary.d.ts.map +1 -1
  72. package/dist/executiveSummary.js +289 -26
  73. package/dist/identity.d.ts +143 -0
  74. package/dist/identity.d.ts.map +1 -0
  75. package/dist/identity.js +231 -0
  76. package/dist/impact-assessment.d.ts +350 -0
  77. package/dist/impact-assessment.d.ts.map +1 -0
  78. package/dist/impact-assessment.js +580 -0
  79. package/dist/index.d.ts +25 -5
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +300 -4
  82. package/dist/instrumentation.d.ts +1 -1
  83. package/dist/instrumentation.d.ts.map +1 -1
  84. package/dist/instrumentation.js +243 -27
  85. package/dist/integrations/anthropic.d.ts +3 -0
  86. package/dist/integrations/anthropic.d.ts.map +1 -1
  87. package/dist/integrations/anthropic.js +284 -79
  88. package/dist/integrations/governance.d.ts +33 -0
  89. package/dist/integrations/governance.d.ts.map +1 -0
  90. package/dist/integrations/governance.js +208 -0
  91. package/dist/integrations/langchain.d.ts +7 -0
  92. package/dist/integrations/langchain.d.ts.map +1 -1
  93. package/dist/integrations/langchain.js +387 -143
  94. package/dist/integrations/openai.d.ts +9 -0
  95. package/dist/integrations/openai.d.ts.map +1 -1
  96. package/dist/integrations/openai.js +673 -73
  97. package/dist/iso42001_consolidation.d.ts +16 -0
  98. package/dist/iso42001_consolidation.d.ts.map +1 -0
  99. package/dist/iso42001_consolidation.js +413 -0
  100. package/dist/iso42001_workflows.d.ts +263 -0
  101. package/dist/iso42001_workflows.d.ts.map +1 -0
  102. package/dist/iso42001_workflows.js +781 -0
  103. package/dist/lifecycle.d.ts +299 -0
  104. package/dist/lifecycle.d.ts.map +1 -0
  105. package/dist/lifecycle.js +624 -0
  106. package/dist/lineage.d.ts +2 -2
  107. package/dist/lineage.d.ts.map +1 -1
  108. package/dist/lineage.js +12 -17
  109. package/dist/middleware/express.d.ts.map +1 -1
  110. package/dist/middleware/express.js +33 -3
  111. package/dist/middleware/nextjs.d.ts.map +1 -1
  112. package/dist/middleware/nextjs.js +42 -68
  113. package/dist/model.d.ts +143 -0
  114. package/dist/model.d.ts.map +1 -0
  115. package/dist/model.js +371 -0
  116. package/dist/onboarding.d.ts +42 -0
  117. package/dist/onboarding.d.ts.map +1 -0
  118. package/dist/onboarding.js +1022 -0
  119. package/dist/oversight.d.ts +264 -0
  120. package/dist/oversight.d.ts.map +1 -0
  121. package/dist/oversight.js +497 -0
  122. package/dist/pdf_report.d.ts.map +1 -1
  123. package/dist/pdf_report.js +42 -21
  124. package/dist/presets.d.ts +88 -0
  125. package/dist/presets.d.ts.map +1 -0
  126. package/dist/presets.js +520 -0
  127. package/dist/propagation.d.ts.map +1 -1
  128. package/dist/propagation.js +34 -2
  129. package/dist/quotas.d.ts +171 -0
  130. package/dist/quotas.d.ts.map +1 -0
  131. package/dist/quotas.js +259 -0
  132. package/dist/register.d.ts +13 -0
  133. package/dist/register.d.ts.map +1 -0
  134. package/dist/register.js +99 -0
  135. package/dist/registry.d.ts +1 -0
  136. package/dist/registry.d.ts.map +1 -1
  137. package/dist/registry.js +7 -0
  138. package/dist/registryData.json +43 -6
  139. package/dist/report.d.ts +2 -1
  140. package/dist/report.d.ts.map +1 -1
  141. package/dist/report.js +189 -2
  142. package/dist/reporting.d.ts +125 -0
  143. package/dist/reporting.d.ts.map +1 -1
  144. package/dist/reporting.js +196 -5
  145. package/dist/resources.d.ts +285 -0
  146. package/dist/resources.d.ts.map +1 -0
  147. package/dist/resources.js +643 -0
  148. package/dist/risk.d.ts +120 -0
  149. package/dist/risk.d.ts.map +1 -0
  150. package/dist/risk.js +220 -0
  151. package/dist/runtime.d.ts +74 -1
  152. package/dist/runtime.d.ts.map +1 -1
  153. package/dist/runtime.js +598 -22
  154. package/dist/schemaInference.d.ts +92 -0
  155. package/dist/schemaInference.d.ts.map +1 -0
  156. package/dist/schemaInference.js +466 -0
  157. package/dist/schema_validation.js +2 -2
  158. package/dist/schemas/config.schema.json +169 -6
  159. package/dist/schemas/event.schema.json +4 -0
  160. package/dist/security_report.js +4 -4
  161. package/dist/signing.d.ts +1 -1
  162. package/dist/signing.d.ts.map +1 -1
  163. package/dist/signing.js +4 -0
  164. package/dist/sinks/file.d.ts +19 -1
  165. package/dist/sinks/file.d.ts.map +1 -1
  166. package/dist/sinks/file.js +82 -13
  167. package/dist/sinks/https.d.ts +10 -0
  168. package/dist/sinks/https.d.ts.map +1 -1
  169. package/dist/sinks/https.js +76 -16
  170. package/dist/sinks/stdout.d.ts +1 -0
  171. package/dist/sinks/stdout.d.ts.map +1 -1
  172. package/dist/sinks/stdout.js +12 -1
  173. package/dist/spec.d.ts +159 -0
  174. package/dist/spec.d.ts.map +1 -0
  175. package/dist/spec.js +391 -0
  176. package/dist/stakeholders.d.ts +199 -0
  177. package/dist/stakeholders.d.ts.map +1 -0
  178. package/dist/stakeholders.js +398 -0
  179. package/dist/standards.d.ts.map +1 -1
  180. package/dist/standards.js +160 -2
  181. package/dist/standards_ingest.d.ts +2 -2
  182. package/dist/standards_ingest.d.ts.map +1 -1
  183. package/dist/standards_ingest.js +105 -23
  184. package/dist/streaming.d.ts.map +1 -1
  185. package/dist/streaming.js +7 -2
  186. package/dist/telemetry.d.ts +16 -2
  187. package/dist/telemetry.d.ts.map +1 -1
  188. package/dist/telemetry.js +79 -14
  189. package/dist/templates/controls/iso42001_control_catalog.json +1443 -0
  190. package/dist/traced_emitter.d.ts +3 -0
  191. package/dist/traced_emitter.d.ts.map +1 -1
  192. package/dist/traced_emitter.js +142 -25
  193. package/dist/trust_package.d.ts +21 -1
  194. package/dist/trust_package.d.ts.map +1 -1
  195. package/dist/trust_package.js +101 -4
  196. package/dist/verify.d.ts.map +1 -1
  197. package/dist/verify.js +9 -2
  198. package/dist/wal.d.ts.map +1 -1
  199. package/dist/wal.js +2 -1
  200. package/package.json +14 -1
  201. package/scripts/postinstall.js +119 -97
  202. package/templates/controls/iso42001_control_catalog.json +1443 -0
@@ -0,0 +1,624 @@
1
+ "use strict";
2
+ /**
3
+ * AI System Life Cycle Registry for ISO 42001 A.6 compliance.
4
+ *
5
+ * This module provides AI System Life Cycle tracking supporting ISO 42001 controls:
6
+ * - A.6.1.2: Objectives for responsible development
7
+ * - A.6.1.3: Processes for responsible design
8
+ * - A.6.2.2: System requirements and specification
9
+ * - A.6.2.4: Verification and validation
10
+ * - A.6.2.5: Deployment documentation
11
+ *
12
+ * Cross-SDK Parity:
13
+ * Both Python and Node.js SDKs provide identical lifecycle APIs:
14
+ * - createSystemRecord() / create_system_record()
15
+ * - registerSystem() / register_system()
16
+ * - addRequirement() / add_requirement()
17
+ * - recordVerification() / record_verification()
18
+ * - transitionStage() / transition_stage()
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.objectiveToDict = objectiveToDict;
22
+ exports.documentRefToDict = documentRefToDict;
23
+ exports.requirementToDict = requirementToDict;
24
+ exports.verificationRecordToDict = verificationRecordToDict;
25
+ exports.validationRecordToDict = validationRecordToDict;
26
+ exports.checklistItemToDict = checklistItemToDict;
27
+ exports.deploymentPlanToDict = deploymentPlanToDict;
28
+ exports.stageTransitionToDict = stageTransitionToDict;
29
+ exports.systemRecordToDict = systemRecordToDict;
30
+ exports.createSystemRecord = createSystemRecord;
31
+ exports.registerSystem = registerSystem;
32
+ exports.getSystemRecord = getSystemRecord;
33
+ exports.getAllSystems = getAllSystems;
34
+ exports.clearSystems = clearSystems;
35
+ exports.addObjective = addObjective;
36
+ exports.addDocument = addDocument;
37
+ exports.addRequirement = addRequirement;
38
+ exports.recordVerification = recordVerification;
39
+ exports.recordValidation = recordValidation;
40
+ exports.setDeploymentPlan = setDeploymentPlan;
41
+ exports.approveDeployment = approveDeployment;
42
+ exports.addChecklistItem = addChecklistItem;
43
+ exports.completeChecklistItem = completeChecklistItem;
44
+ exports.validateStageTransition = validateStageTransition;
45
+ exports.transitionStage = transitionStage;
46
+ exports.getRequirementsTraceability = getRequirementsTraceability;
47
+ exports.getLifecycleSummary = getLifecycleSummary;
48
+ exports.getLifecycleReport = getLifecycleReport;
49
+ exports.emitSystemRecord = emitSystemRecord;
50
+ const crypto_1 = require("crypto");
51
+ const logger_1 = require("./logger");
52
+ /**
53
+ * Generate a deterministic ID from parts.
54
+ */
55
+ function generateId(prefix, ...parts) {
56
+ const combined = parts.join(':');
57
+ const hash = (0, crypto_1.createHash)('sha256').update(combined).digest('hex').slice(0, 12);
58
+ return `${prefix}_${hash}`;
59
+ }
60
+ /**
61
+ * Get current UTC timestamp in ISO format.
62
+ */
63
+ function nowIso() {
64
+ return new Date().toISOString();
65
+ }
66
+ function objectiveToDict(obj) {
67
+ return {
68
+ objective_id: obj.objectiveId,
69
+ description: obj.description,
70
+ rationale: obj.rationale,
71
+ success_criteria: obj.successCriteria,
72
+ status: obj.status,
73
+ };
74
+ }
75
+ function documentRefToDict(doc) {
76
+ return {
77
+ doc_id: doc.docId,
78
+ title: doc.title,
79
+ doc_type: doc.docType,
80
+ path_or_url: doc.pathOrUrl,
81
+ version: doc.version,
82
+ last_updated: doc.lastUpdated,
83
+ };
84
+ }
85
+ function requirementToDict(req) {
86
+ return {
87
+ req_id: req.reqId,
88
+ type: req.type,
89
+ description: req.description,
90
+ acceptance_criteria: req.acceptanceCriteria,
91
+ verification_method: req.verificationMethod,
92
+ status: req.status,
93
+ linked_tests: req.linkedTests,
94
+ };
95
+ }
96
+ function verificationRecordToDict(rec) {
97
+ const result = {
98
+ verification_id: rec.verificationId,
99
+ requirement_id: rec.requirementId,
100
+ method: rec.method,
101
+ result: rec.result,
102
+ evidence_refs: rec.evidenceRefs,
103
+ verified_at: rec.verifiedAt,
104
+ verified_by: rec.verifiedBy,
105
+ };
106
+ if (rec.notes) {
107
+ result.notes = rec.notes;
108
+ }
109
+ return result;
110
+ }
111
+ function validationRecordToDict(rec) {
112
+ return {
113
+ validation_id: rec.validationId,
114
+ requirement_id: rec.requirementId,
115
+ method: rec.method,
116
+ result: rec.result,
117
+ findings: rec.findings,
118
+ validated_at: rec.validatedAt,
119
+ validated_by: rec.validatedBy,
120
+ };
121
+ }
122
+ function checklistItemToDict(item) {
123
+ const result = {
124
+ item_id: item.itemId,
125
+ description: item.description,
126
+ required: item.required,
127
+ completed: item.completed,
128
+ };
129
+ if (item.completedAt)
130
+ result.completed_at = item.completedAt;
131
+ if (item.completedBy)
132
+ result.completed_by = item.completedBy;
133
+ if (item.evidenceRef)
134
+ result.evidence_ref = item.evidenceRef;
135
+ return result;
136
+ }
137
+ function deploymentPlanToDict(plan) {
138
+ const result = {
139
+ plan_id: plan.planId,
140
+ target_environment: plan.targetEnvironment,
141
+ rollback_procedure: plan.rollbackProcedure,
142
+ monitoring_setup: plan.monitoringSetup,
143
+ approval_status: plan.approvalStatus,
144
+ };
145
+ if (plan.deploymentDate)
146
+ result.deployment_date = plan.deploymentDate;
147
+ if (plan.approvedBy)
148
+ result.approved_by = plan.approvedBy;
149
+ if (plan.approvedAt)
150
+ result.approved_at = plan.approvedAt;
151
+ return result;
152
+ }
153
+ function stageTransitionToDict(trans) {
154
+ return {
155
+ from_stage: trans.fromStage,
156
+ to_stage: trans.toStage,
157
+ transitioned_at: trans.transitionedAt,
158
+ transitioned_by: trans.transitionedBy,
159
+ rationale: trans.rationale,
160
+ };
161
+ }
162
+ function systemRecordToDict(system) {
163
+ const result = {
164
+ system_id: system.systemId,
165
+ name: system.name,
166
+ version: system.version,
167
+ stage: system.stage,
168
+ objectives: system.objectives.map(objectiveToDict),
169
+ design_documents: system.designDocuments.map(documentRefToDict),
170
+ requirements: system.requirements.map(requirementToDict),
171
+ verification_results: system.verificationResults.map(verificationRecordToDict),
172
+ validation_results: system.validationResults.map(validationRecordToDict),
173
+ deployment_checklist: system.deploymentChecklist.map(checklistItemToDict),
174
+ created_at: system.createdAt,
175
+ updated_at: system.updatedAt,
176
+ stage_history: system.stageHistory.map(stageTransitionToDict),
177
+ };
178
+ if (system.deploymentPlan) {
179
+ result.deployment_plan = deploymentPlanToDict(system.deploymentPlan);
180
+ }
181
+ return result;
182
+ }
183
+ // Runtime system registry
184
+ const systems = new Map();
185
+ function createSystemRecord(options) {
186
+ const record = {
187
+ systemId: options.systemId,
188
+ name: options.name,
189
+ version: options.version || '1.0.0',
190
+ stage: options.stage || 'design',
191
+ objectives: [],
192
+ designDocuments: [],
193
+ requirements: [],
194
+ verificationResults: [],
195
+ validationResults: [],
196
+ deploymentChecklist: [],
197
+ createdAt: nowIso(),
198
+ updatedAt: nowIso(),
199
+ stageHistory: [],
200
+ };
201
+ systems.set(options.systemId, record);
202
+ return record;
203
+ }
204
+ /**
205
+ * Register an existing system record.
206
+ */
207
+ function registerSystem(record) {
208
+ systems.set(record.systemId, record);
209
+ }
210
+ /**
211
+ * Get a system record by ID.
212
+ */
213
+ function getSystemRecord(systemId) {
214
+ return systems.get(systemId);
215
+ }
216
+ /**
217
+ * Get all registered system records.
218
+ */
219
+ function getAllSystems() {
220
+ return Array.from(systems.values());
221
+ }
222
+ /**
223
+ * Clear all system records from the registry.
224
+ */
225
+ function clearSystems() {
226
+ systems.clear();
227
+ }
228
+ function addObjective(options) {
229
+ const system = systems.get(options.systemId);
230
+ if (!system) {
231
+ throw new Error(`System ${options.systemId} not found`);
232
+ }
233
+ const objectiveId = generateId('obj', options.systemId, options.description.slice(0, 20));
234
+ const objective = {
235
+ objectiveId,
236
+ description: options.description,
237
+ rationale: options.rationale,
238
+ successCriteria: options.successCriteria || [],
239
+ status: 'defined',
240
+ };
241
+ system.objectives.push(objective);
242
+ system.updatedAt = nowIso();
243
+ return objective;
244
+ }
245
+ function addDocument(options) {
246
+ const system = systems.get(options.systemId);
247
+ if (!system) {
248
+ throw new Error(`System ${options.systemId} not found`);
249
+ }
250
+ const docId = generateId('doc', options.systemId, options.title.slice(0, 20));
251
+ const doc = {
252
+ docId,
253
+ title: options.title,
254
+ docType: options.docType,
255
+ pathOrUrl: options.pathOrUrl,
256
+ version: options.version || '1.0',
257
+ lastUpdated: nowIso(),
258
+ };
259
+ system.designDocuments.push(doc);
260
+ system.updatedAt = nowIso();
261
+ return doc;
262
+ }
263
+ function addRequirement(options) {
264
+ const system = systems.get(options.systemId);
265
+ if (!system) {
266
+ throw new Error(`System ${options.systemId} not found`);
267
+ }
268
+ const reqId = generateId('req', options.systemId, options.reqType, options.description.slice(0, 20));
269
+ const req = {
270
+ reqId,
271
+ type: options.reqType,
272
+ description: options.description,
273
+ acceptanceCriteria: options.acceptanceCriteria || [],
274
+ verificationMethod: options.verificationMethod || 'unit_test',
275
+ status: 'defined',
276
+ linkedTests: [],
277
+ };
278
+ system.requirements.push(req);
279
+ system.updatedAt = nowIso();
280
+ return req;
281
+ }
282
+ function recordVerification(options) {
283
+ const system = systems.get(options.systemId);
284
+ if (!system) {
285
+ throw new Error(`System ${options.systemId} not found`);
286
+ }
287
+ // Update requirement status
288
+ let reqFound = false;
289
+ for (const req of system.requirements) {
290
+ if (req.reqId === options.requirementId) {
291
+ reqFound = true;
292
+ if (options.result === 'pass') {
293
+ req.status = 'verified';
294
+ }
295
+ break;
296
+ }
297
+ }
298
+ if (!reqFound) {
299
+ throw new Error(`Requirement ${options.requirementId} not found in system ${options.systemId}`);
300
+ }
301
+ const verificationId = generateId('ver', options.systemId, options.requirementId);
302
+ const verification = {
303
+ verificationId,
304
+ requirementId: options.requirementId,
305
+ method: options.method,
306
+ result: options.result,
307
+ evidenceRefs: options.evidenceRefs || [],
308
+ verifiedAt: nowIso(),
309
+ verifiedBy: options.verifiedBy,
310
+ notes: options.notes,
311
+ };
312
+ system.verificationResults.push(verification);
313
+ system.updatedAt = nowIso();
314
+ return verification;
315
+ }
316
+ function recordValidation(options) {
317
+ const system = systems.get(options.systemId);
318
+ if (!system) {
319
+ throw new Error(`System ${options.systemId} not found`);
320
+ }
321
+ // Update requirement status
322
+ let reqFound = false;
323
+ for (const req of system.requirements) {
324
+ if (req.reqId === options.requirementId) {
325
+ reqFound = true;
326
+ if (options.result === 'pass') {
327
+ req.status = 'validated';
328
+ }
329
+ break;
330
+ }
331
+ }
332
+ if (!reqFound) {
333
+ throw new Error(`Requirement ${options.requirementId} not found in system ${options.systemId}`);
334
+ }
335
+ const validationId = generateId('val', options.systemId, options.requirementId);
336
+ const validation = {
337
+ validationId,
338
+ requirementId: options.requirementId,
339
+ method: options.method,
340
+ result: options.result,
341
+ findings: options.findings || [],
342
+ validatedAt: nowIso(),
343
+ validatedBy: options.validatedBy,
344
+ };
345
+ system.validationResults.push(validation);
346
+ system.updatedAt = nowIso();
347
+ return validation;
348
+ }
349
+ function setDeploymentPlan(options) {
350
+ const system = systems.get(options.systemId);
351
+ if (!system) {
352
+ throw new Error(`System ${options.systemId} not found`);
353
+ }
354
+ const planId = generateId('plan', options.systemId, options.targetEnvironment);
355
+ const plan = {
356
+ planId,
357
+ targetEnvironment: options.targetEnvironment,
358
+ deploymentDate: options.deploymentDate,
359
+ rollbackProcedure: options.rollbackProcedure || '',
360
+ monitoringSetup: options.monitoringSetup || '',
361
+ approvalStatus: 'pending',
362
+ };
363
+ system.deploymentPlan = plan;
364
+ system.updatedAt = nowIso();
365
+ return plan;
366
+ }
367
+ /**
368
+ * Approve a deployment plan (A.6.2.5).
369
+ */
370
+ function approveDeployment(systemId, approvedBy) {
371
+ const system = systems.get(systemId);
372
+ if (!system) {
373
+ throw new Error(`System ${systemId} not found`);
374
+ }
375
+ if (!system.deploymentPlan) {
376
+ throw new Error(`System ${systemId} has no deployment plan`);
377
+ }
378
+ system.deploymentPlan.approvalStatus = 'approved';
379
+ system.deploymentPlan.approvedBy = approvedBy;
380
+ system.deploymentPlan.approvedAt = nowIso();
381
+ system.updatedAt = nowIso();
382
+ return system.deploymentPlan;
383
+ }
384
+ function addChecklistItem(options) {
385
+ const system = systems.get(options.systemId);
386
+ if (!system) {
387
+ throw new Error(`System ${options.systemId} not found`);
388
+ }
389
+ const itemId = generateId('chk', options.systemId, options.description.slice(0, 20));
390
+ const item = {
391
+ itemId,
392
+ description: options.description,
393
+ required: options.required !== false,
394
+ completed: false,
395
+ };
396
+ system.deploymentChecklist.push(item);
397
+ system.updatedAt = nowIso();
398
+ return item;
399
+ }
400
+ function completeChecklistItem(options) {
401
+ const system = systems.get(options.systemId);
402
+ if (!system) {
403
+ throw new Error(`System ${options.systemId} not found`);
404
+ }
405
+ for (const item of system.deploymentChecklist) {
406
+ if (item.itemId === options.itemId) {
407
+ item.completed = true;
408
+ item.completedAt = nowIso();
409
+ item.completedBy = options.completedBy;
410
+ item.evidenceRef = options.evidenceRef;
411
+ system.updatedAt = nowIso();
412
+ return item;
413
+ }
414
+ }
415
+ throw new Error(`Checklist item ${options.itemId} not found in system ${options.systemId}`);
416
+ }
417
+ /**
418
+ * Validate prerequisites for a stage transition.
419
+ */
420
+ function validateStageTransition(system, newStage, config) {
421
+ const errors = [];
422
+ const lifecycleConfig = config?.lifecycle;
423
+ const prerequisites = lifecycleConfig?.stage_prerequisites || {};
424
+ const stagePrereqs = prerequisites[newStage] || [];
425
+ for (const prereq of stagePrereqs) {
426
+ if (prereq === 'requirements_defined') {
427
+ if (system.requirements.length === 0) {
428
+ errors.push('No requirements defined');
429
+ }
430
+ }
431
+ else if (prereq === 'verification_complete') {
432
+ const verifiedReqs = new Set(system.verificationResults.filter(v => v.result === 'pass').map(v => v.requirementId));
433
+ const unverified = system.requirements.filter(r => !verifiedReqs.has(r.reqId)).map(r => r.reqId);
434
+ if (unverified.length > 0) {
435
+ errors.push(`Requirements not verified: ${unverified.join(', ')}`);
436
+ }
437
+ }
438
+ else if (prereq === 'validation_complete') {
439
+ const validatedReqs = new Set(system.validationResults.filter(v => v.result === 'pass').map(v => v.requirementId));
440
+ const unvalidated = system.requirements.filter(r => !validatedReqs.has(r.reqId)).map(r => r.reqId);
441
+ if (unvalidated.length > 0) {
442
+ errors.push(`Requirements not validated: ${unvalidated.join(', ')}`);
443
+ }
444
+ }
445
+ else if (prereq === 'deployment_approved') {
446
+ if (!system.deploymentPlan || system.deploymentPlan.approvalStatus !== 'approved') {
447
+ errors.push('Deployment plan not approved');
448
+ }
449
+ }
450
+ else if (prereq === 'decommission_plan') {
451
+ const decomDocs = system.designDocuments.filter(d => d.docType === 'decommission_plan');
452
+ if (decomDocs.length === 0) {
453
+ errors.push('No decommission plan document');
454
+ }
455
+ }
456
+ }
457
+ return errors;
458
+ }
459
+ function transitionStage(options) {
460
+ const system = systems.get(options.systemId);
461
+ if (!system) {
462
+ throw new Error(`System ${options.systemId} not found`);
463
+ }
464
+ const oldStage = system.stage;
465
+ // Validate prerequisites unless forced
466
+ if (!options.force) {
467
+ const errors = validateStageTransition(system, options.newStage, options.config);
468
+ if (errors.length > 0) {
469
+ throw new Error(`Prerequisites not met for ${options.newStage}: ${errors.join('; ')}`);
470
+ }
471
+ }
472
+ // Record the transition
473
+ const transition = {
474
+ fromStage: oldStage,
475
+ toStage: options.newStage,
476
+ transitionedAt: nowIso(),
477
+ transitionedBy: options.transitionedBy,
478
+ rationale: options.rationale,
479
+ };
480
+ system.stageHistory.push(transition);
481
+ system.stage = options.newStage;
482
+ system.updatedAt = nowIso();
483
+ // Update deployment plan status if transitioning to production
484
+ if (options.newStage === 'production' && system.deploymentPlan) {
485
+ system.deploymentPlan.approvalStatus = 'deployed';
486
+ }
487
+ // Emit lifecycle event
488
+ emitLifecycleEvent(system, 'system_stage_transition', options.config);
489
+ return system;
490
+ }
491
+ /**
492
+ * Get requirements traceability matrix for a system.
493
+ */
494
+ function getRequirementsTraceability(systemId) {
495
+ const system = systems.get(systemId);
496
+ if (!system) {
497
+ return {};
498
+ }
499
+ const verifiedReqs = new Map(system.verificationResults.map(v => [v.requirementId, v]));
500
+ const validatedReqs = new Map(system.validationResults.map(v => [v.requirementId, v]));
501
+ const matrix = system.requirements.map(req => {
502
+ const entry = {
503
+ req_id: req.reqId,
504
+ type: req.type,
505
+ description: req.description,
506
+ status: req.status,
507
+ verified: verifiedReqs.has(req.reqId),
508
+ validated: validatedReqs.has(req.reqId),
509
+ };
510
+ const verRec = verifiedReqs.get(req.reqId);
511
+ if (verRec) {
512
+ entry.verification = {
513
+ method: verRec.method,
514
+ result: verRec.result,
515
+ verified_at: verRec.verifiedAt,
516
+ };
517
+ }
518
+ const valRec = validatedReqs.get(req.reqId);
519
+ if (valRec) {
520
+ entry.validation = {
521
+ method: valRec.method,
522
+ result: valRec.result,
523
+ validated_at: valRec.validatedAt,
524
+ };
525
+ }
526
+ return entry;
527
+ });
528
+ return {
529
+ system_id: systemId,
530
+ system_name: system.name,
531
+ stage: system.stage,
532
+ requirements: matrix,
533
+ total_requirements: system.requirements.length,
534
+ verified_count: matrix.filter(m => m.verified).length,
535
+ validated_count: matrix.filter(m => m.validated).length,
536
+ };
537
+ }
538
+ /**
539
+ * Get a summary of a system's lifecycle status.
540
+ */
541
+ function getLifecycleSummary(systemId) {
542
+ const system = systems.get(systemId);
543
+ if (!system) {
544
+ return {};
545
+ }
546
+ const checklistComplete = system.deploymentChecklist
547
+ .filter(item => item.required)
548
+ .every(item => item.completed);
549
+ const verifiedCount = system.verificationResults.filter(v => v.result === 'pass').length;
550
+ const validatedCount = system.validationResults.filter(v => v.result === 'pass').length;
551
+ return {
552
+ system_id: system.systemId,
553
+ name: system.name,
554
+ version: system.version,
555
+ stage: system.stage,
556
+ objectives_count: system.objectives.length,
557
+ objectives_achieved: system.objectives.filter(o => o.status === 'achieved').length,
558
+ documents_count: system.designDocuments.length,
559
+ requirements_count: system.requirements.length,
560
+ verified_requirements: verifiedCount,
561
+ validated_requirements: validatedCount,
562
+ deployment_plan_status: system.deploymentPlan?.approvalStatus || 'none',
563
+ checklist_items: system.deploymentChecklist.length,
564
+ checklist_complete: checklistComplete,
565
+ stage_transitions: system.stageHistory.length,
566
+ };
567
+ }
568
+ /**
569
+ * Get aggregate report of all system lifecycles.
570
+ */
571
+ function getLifecycleReport(config) {
572
+ if (systems.size === 0) {
573
+ return {
574
+ total_systems: 0,
575
+ by_stage: {},
576
+ systems: [],
577
+ };
578
+ }
579
+ const byStage = {};
580
+ const systemsSummary = [];
581
+ systems.forEach(system => {
582
+ byStage[system.stage] = (byStage[system.stage] || 0) + 1;
583
+ systemsSummary.push({
584
+ system_id: system.systemId,
585
+ name: system.name,
586
+ version: system.version,
587
+ stage: system.stage,
588
+ });
589
+ });
590
+ return {
591
+ total_systems: systems.size,
592
+ by_stage: byStage,
593
+ systems: systemsSummary,
594
+ };
595
+ }
596
+ /**
597
+ * Emit a lifecycle event.
598
+ */
599
+ function emitLifecycleEvent(system, eventType, config) {
600
+ try {
601
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
602
+ const { getState } = require('./runtime');
603
+ const state = getState();
604
+ if (state && typeof state.emitInternal === 'function') {
605
+ state.emitInternal({
606
+ event_type: eventType,
607
+ timestamp: nowIso(),
608
+ body: systemRecordToDict(system),
609
+ });
610
+ }
611
+ }
612
+ catch (err) {
613
+ logger_1.logger.warning('Failed to emit lifecycle event:', err);
614
+ }
615
+ }
616
+ /**
617
+ * Emit the current state of a system record as an event.
618
+ */
619
+ function emitSystemRecord(systemId, config) {
620
+ const system = getSystemRecord(systemId);
621
+ if (system) {
622
+ emitLifecycleEvent(system, 'system_lifecycle', config);
623
+ }
624
+ }
package/dist/lineage.d.ts CHANGED
@@ -5,13 +5,14 @@
5
5
  * automatic capture of parent events and input events in the trace graph.
6
6
  */
7
7
  import { AsyncLocalStorage } from 'async_hooks';
8
- interface LineageContext {
8
+ export interface LineageContext {
9
9
  currentEventId: string | null;
10
10
  inputEventIds: string[];
11
11
  promptId: string | null;
12
12
  templateId: string | null;
13
13
  dataSourceIds: string[];
14
14
  }
15
+ export declare function createLineageContext(): LineageContext;
15
16
  /**
16
17
  * Set the current event ID for lineage tracking.
17
18
  *
@@ -174,5 +175,4 @@ export declare function withPrompt<T extends (...args: any[]) => any>(options: {
174
175
  * @returns The AsyncLocalStorage instance.
175
176
  */
176
177
  export declare function getLineageStorage(): AsyncLocalStorage<LineageContext>;
177
- export {};
178
178
  //# sourceMappingURL=lineage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lineage.d.ts","sourceRoot":"","sources":["../src/lineage.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,UAAU,cAAc;IACtB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB;AAuBD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAKrD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,IAAI,CAGhD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aA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