monora-ai 2.1.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 (184) hide show
  1. package/README.md +333 -159
  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 +85 -0
  12. package/dist/assessment.d.ts.map +1 -1
  13. package/dist/assessment.js +506 -13
  14. package/dist/attribution.d.ts +44 -3
  15. package/dist/attribution.d.ts.map +1 -1
  16. package/dist/attribution.js +197 -10
  17. package/dist/autodetect.d.ts +68 -0
  18. package/dist/autodetect.d.ts.map +1 -1
  19. package/dist/autodetect.js +639 -0
  20. package/dist/bias.d.ts +130 -0
  21. package/dist/bias.d.ts.map +1 -0
  22. package/dist/bias.js +223 -0
  23. package/dist/cli/diagnostics.d.ts +5 -1
  24. package/dist/cli/diagnostics.d.ts.map +1 -1
  25. package/dist/cli/diagnostics.js +23 -6
  26. package/dist/cli/doctor.d.ts +25 -0
  27. package/dist/cli/doctor.d.ts.map +1 -0
  28. package/dist/cli/doctor.js +381 -0
  29. package/dist/cli/fix.d.ts +16 -0
  30. package/dist/cli/fix.d.ts.map +1 -0
  31. package/dist/cli/fix.js +284 -0
  32. package/dist/cli/init.d.ts +57 -0
  33. package/dist/cli/init.d.ts.map +1 -0
  34. package/dist/cli/init.js +205 -0
  35. package/dist/cli.js +1550 -176
  36. package/dist/complianceTargets.d.ts +111 -0
  37. package/dist/complianceTargets.d.ts.map +1 -0
  38. package/dist/complianceTargets.js +521 -0
  39. package/dist/config.d.ts +261 -16
  40. package/dist/config.d.ts.map +1 -1
  41. package/dist/config.js +381 -32
  42. package/dist/config_migrations.d.ts.map +1 -1
  43. package/dist/config_migrations.js +38 -1
  44. package/dist/config_schema.d.ts +2490 -1035
  45. package/dist/config_schema.d.ts.map +1 -1
  46. package/dist/config_schema.js +233 -64
  47. package/dist/context.d.ts +34 -0
  48. package/dist/context.d.ts.map +1 -1
  49. package/dist/context.js +118 -7
  50. package/dist/control_backbone.d.ts +122 -0
  51. package/dist/control_backbone.d.ts.map +1 -0
  52. package/dist/control_backbone.js +698 -0
  53. package/dist/data-governance.d.ts +187 -0
  54. package/dist/data-governance.d.ts.map +1 -0
  55. package/dist/data-governance.js +424 -0
  56. package/dist/dataResidency.d.ts +44 -0
  57. package/dist/dataResidency.d.ts.map +1 -0
  58. package/dist/dataResidency.js +203 -0
  59. package/dist/dispatcher.d.ts.map +1 -1
  60. package/dist/dispatcher.js +17 -5
  61. package/dist/evidence_store.d.ts +103 -0
  62. package/dist/evidence_store.d.ts.map +1 -0
  63. package/dist/evidence_store.js +459 -0
  64. package/dist/executiveSummary.d.ts +15 -0
  65. package/dist/executiveSummary.d.ts.map +1 -1
  66. package/dist/executiveSummary.js +135 -22
  67. package/dist/identity.d.ts +143 -0
  68. package/dist/identity.d.ts.map +1 -0
  69. package/dist/identity.js +231 -0
  70. package/dist/impact-assessment.d.ts +350 -0
  71. package/dist/impact-assessment.d.ts.map +1 -0
  72. package/dist/impact-assessment.js +580 -0
  73. package/dist/index.d.ts +20 -4
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +247 -5
  76. package/dist/instrumentation.d.ts +1 -1
  77. package/dist/instrumentation.d.ts.map +1 -1
  78. package/dist/instrumentation.js +123 -22
  79. package/dist/integrations/anthropic.d.ts +3 -0
  80. package/dist/integrations/anthropic.d.ts.map +1 -1
  81. package/dist/integrations/anthropic.js +282 -80
  82. package/dist/integrations/governance.d.ts +33 -0
  83. package/dist/integrations/governance.d.ts.map +1 -0
  84. package/dist/integrations/governance.js +208 -0
  85. package/dist/integrations/langchain.d.ts +4 -0
  86. package/dist/integrations/langchain.d.ts.map +1 -1
  87. package/dist/integrations/langchain.js +362 -142
  88. package/dist/integrations/openai.d.ts +9 -0
  89. package/dist/integrations/openai.d.ts.map +1 -1
  90. package/dist/integrations/openai.js +673 -73
  91. package/dist/iso42001_consolidation.d.ts +16 -0
  92. package/dist/iso42001_consolidation.d.ts.map +1 -0
  93. package/dist/iso42001_consolidation.js +413 -0
  94. package/dist/iso42001_workflows.d.ts +263 -0
  95. package/dist/iso42001_workflows.d.ts.map +1 -0
  96. package/dist/iso42001_workflows.js +781 -0
  97. package/dist/lifecycle.d.ts +299 -0
  98. package/dist/lifecycle.d.ts.map +1 -0
  99. package/dist/lifecycle.js +624 -0
  100. package/dist/lineage.d.ts +2 -2
  101. package/dist/lineage.d.ts.map +1 -1
  102. package/dist/lineage.js +9 -16
  103. package/dist/middleware/express.d.ts.map +1 -1
  104. package/dist/middleware/express.js +18 -3
  105. package/dist/middleware/nextjs.js +2 -2
  106. package/dist/model.d.ts +143 -0
  107. package/dist/model.d.ts.map +1 -0
  108. package/dist/model.js +371 -0
  109. package/dist/onboarding.d.ts +42 -0
  110. package/dist/onboarding.d.ts.map +1 -0
  111. package/dist/onboarding.js +1022 -0
  112. package/dist/oversight.d.ts +264 -0
  113. package/dist/oversight.d.ts.map +1 -0
  114. package/dist/oversight.js +497 -0
  115. package/dist/presets.js +7 -7
  116. package/dist/quotas.d.ts +171 -0
  117. package/dist/quotas.d.ts.map +1 -0
  118. package/dist/quotas.js +259 -0
  119. package/dist/register.d.ts +13 -0
  120. package/dist/register.d.ts.map +1 -0
  121. package/dist/register.js +99 -0
  122. package/dist/registry.d.ts +1 -0
  123. package/dist/registry.d.ts.map +1 -1
  124. package/dist/registry.js +7 -0
  125. package/dist/registryData.json +43 -6
  126. package/dist/report.d.ts +2 -1
  127. package/dist/report.d.ts.map +1 -1
  128. package/dist/report.js +189 -2
  129. package/dist/reporting.d.ts +125 -0
  130. package/dist/reporting.d.ts.map +1 -1
  131. package/dist/reporting.js +192 -2
  132. package/dist/resources.d.ts +285 -0
  133. package/dist/resources.d.ts.map +1 -0
  134. package/dist/resources.js +643 -0
  135. package/dist/risk.d.ts +120 -0
  136. package/dist/risk.d.ts.map +1 -0
  137. package/dist/risk.js +220 -0
  138. package/dist/runtime.d.ts +73 -0
  139. package/dist/runtime.d.ts.map +1 -1
  140. package/dist/runtime.js +415 -18
  141. package/dist/schemaInference.d.ts +92 -0
  142. package/dist/schemaInference.d.ts.map +1 -0
  143. package/dist/schemaInference.js +466 -0
  144. package/dist/schema_validation.js +2 -2
  145. package/dist/schemas/config.schema.json +118 -4
  146. package/dist/security_report.js +4 -4
  147. package/dist/signing.d.ts +1 -1
  148. package/dist/signing.d.ts.map +1 -1
  149. package/dist/signing.js +4 -0
  150. package/dist/sinks/file.d.ts +19 -1
  151. package/dist/sinks/file.d.ts.map +1 -1
  152. package/dist/sinks/file.js +82 -13
  153. package/dist/sinks/https.d.ts +10 -0
  154. package/dist/sinks/https.d.ts.map +1 -1
  155. package/dist/sinks/https.js +76 -16
  156. package/dist/sinks/stdout.d.ts +1 -0
  157. package/dist/sinks/stdout.d.ts.map +1 -1
  158. package/dist/sinks/stdout.js +12 -1
  159. package/dist/spec.d.ts +159 -0
  160. package/dist/spec.d.ts.map +1 -0
  161. package/dist/spec.js +391 -0
  162. package/dist/stakeholders.d.ts +199 -0
  163. package/dist/stakeholders.d.ts.map +1 -0
  164. package/dist/stakeholders.js +398 -0
  165. package/dist/standards.d.ts.map +1 -1
  166. package/dist/standards.js +160 -2
  167. package/dist/standards_ingest.d.ts.map +1 -1
  168. package/dist/standards_ingest.js +1 -4
  169. package/dist/telemetry.d.ts +16 -2
  170. package/dist/telemetry.d.ts.map +1 -1
  171. package/dist/telemetry.js +77 -14
  172. package/dist/templates/controls/iso42001_control_catalog.json +1443 -0
  173. package/dist/traced_emitter.d.ts.map +1 -1
  174. package/dist/traced_emitter.js +19 -9
  175. package/dist/trust_package.d.ts +19 -1
  176. package/dist/trust_package.d.ts.map +1 -1
  177. package/dist/trust_package.js +89 -2
  178. package/dist/verify.d.ts.map +1 -1
  179. package/dist/verify.js +9 -2
  180. package/dist/wal.d.ts.map +1 -1
  181. package/dist/wal.js +2 -1
  182. package/package.json +14 -1
  183. package/scripts/postinstall.js +105 -210
  184. package/templates/controls/iso42001_control_catalog.json +1443 -0
package/dist/config.js CHANGED
@@ -36,11 +36,13 @@ var __importStar = (this && this.__importStar) || (function () {
36
36
  };
37
37
  })();
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.PRESETS = void 0;
39
+ exports.DEFAULT_CONFIG = exports.PRESETS = void 0;
40
40
  exports.loadConfig = loadConfig;
41
41
  exports.parseSinkConfig = parseSinkConfig;
42
42
  exports.getPresetConfig = getPresetConfig;
43
43
  exports.buildConfigFromOptions = buildConfigFromOptions;
44
+ exports.detectEnvironment = detectEnvironment;
45
+ exports.suggestPreset = suggestPreset;
44
46
  const fs = __importStar(require("fs"));
45
47
  const yaml = __importStar(require("js-yaml"));
46
48
  const logger_1 = require("./logger");
@@ -49,32 +51,39 @@ const presets_1 = require("./presets");
49
51
  /**
50
52
  * Preset configurations for quick setup.
51
53
  */
54
+ const MINIMAL_PRESET = {
55
+ sinks: [{ type: 'file', path: './monora_events.jsonl', rotation: 'none' }],
56
+ immutability: { enabled: false },
57
+ reporting: { enabled: false },
58
+ instrumentation: { enabled: false },
59
+ telemetry: { enabled: true, backend: 'minimal' },
60
+ };
61
+ const DEV_PRESET = {
62
+ defaults: { environment: 'dev' },
63
+ sinks: [
64
+ { type: 'file', path: './monora_events.jsonl', rotation: 'none' },
65
+ { type: 'stdout', format: 'pretty' },
66
+ ],
67
+ immutability: { enabled: true, verify_on_emit: false },
68
+ reporting: { enabled: true, output_dir: './monora_reports' },
69
+ instrumentation: { enabled: true, auto_patch: true },
70
+ telemetry: { enabled: true, backend: 'minimal' },
71
+ };
72
+ const PRODUCTION_PRESET = {
73
+ defaults: { environment: 'production' },
74
+ sinks: [{ type: 'file', path: './logs/monora_events.jsonl', rotation: 'daily', symlink: true }],
75
+ immutability: { enabled: true, verify_on_shutdown: true },
76
+ reporting: { enabled: true, output_dir: './monora_reports' },
77
+ wal: { enabled: true, path: './monora_wal' },
78
+ instrumentation: { enabled: true, auto_patch: true },
79
+ error_handling: { sink_failure_mode: 'warn' },
80
+ telemetry: { enabled: true, backend: 'minimal' },
81
+ };
52
82
  exports.PRESETS = {
53
- minimal: {
54
- sinks: [{ type: 'stdout', format: 'json' }],
55
- immutability: { enabled: false },
56
- reporting: { enabled: false },
57
- instrumentation: { enabled: false },
58
- },
59
- development: {
60
- defaults: { environment: 'dev' },
61
- sinks: [
62
- { type: 'stdout', format: 'json' },
63
- { type: 'file', path: './monora_events.jsonl' },
64
- ],
65
- immutability: { enabled: true, verify_on_emit: false },
66
- reporting: { enabled: true, output_dir: './monora_reports' },
67
- instrumentation: { enabled: true, auto_patch: true },
68
- },
69
- production: {
70
- defaults: { environment: 'production' },
71
- sinks: [{ type: 'file', path: './logs/monora_events.jsonl' }],
72
- immutability: { enabled: true, verify_on_shutdown: true },
73
- reporting: { enabled: true, output_dir: './monora_reports' },
74
- wal: { enabled: true, path: './monora_wal' },
75
- instrumentation: { enabled: true, auto_patch: true },
76
- error_handling: { sink_failure_mode: 'warn' },
77
- },
83
+ minimal: MINIMAL_PRESET,
84
+ development: DEV_PRESET,
85
+ dev: DEV_PRESET,
86
+ production: PRODUCTION_PRESET,
78
87
  compliance: {
79
88
  defaults: { environment: 'production' },
80
89
  sinks: [{ type: 'file', path: './logs/monora_events.jsonl' }],
@@ -95,7 +104,7 @@ exports.PRESETS = {
95
104
  telemetry: {
96
105
  enabled: false,
97
106
  send_data: false,
98
- data_residency: 'none',
107
+ data_residency: null,
99
108
  },
100
109
  },
101
110
  },
@@ -119,7 +128,7 @@ exports.PRESETS = {
119
128
  instrumentation: { enabled: true, auto_patch: true },
120
129
  },
121
130
  };
122
- const DEFAULT_CONFIG = {
131
+ exports.DEFAULT_CONFIG = {
123
132
  config_version: '1.0.0',
124
133
  defaults: {
125
134
  data_classification: 'internal',
@@ -127,7 +136,7 @@ const DEFAULT_CONFIG = {
127
136
  service_name: undefined,
128
137
  environment: 'dev',
129
138
  },
130
- sinks: [{ type: 'stdout', format: 'json' }],
139
+ sinks: [{ type: 'file', path: './monora_events.jsonl', rotation: 'none' }],
131
140
  immutability: {
132
141
  enabled: true,
133
142
  scope: 'per_trace',
@@ -287,10 +296,161 @@ const DEFAULT_CONFIG = {
287
296
  },
288
297
  },
289
298
  audit: {},
299
+ quotas: {
300
+ enabled: false,
301
+ max_tokens_per_trace: 100000,
302
+ max_llm_calls_per_trace: 50,
303
+ max_trace_duration_sec: 3600,
304
+ max_cost_per_trace: 10.0,
305
+ action: 'warn',
306
+ },
307
+ identity: {
308
+ enabled: false,
309
+ require_user_id: false,
310
+ capture_roles: false,
311
+ capture_org: false,
312
+ redact_user_id: false,
313
+ },
314
+ risk_register: {
315
+ enabled: false,
316
+ models: {},
317
+ default_risk_level: 'high',
318
+ block_unassessed: false,
319
+ },
320
+ bias: {
321
+ enabled: false,
322
+ dimensions: [],
323
+ thresholds: {
324
+ demographic_parity_ratio: 0.8,
325
+ disparate_impact: 0.8,
326
+ },
327
+ alert_on_violation: true,
328
+ measurement_callback: null,
329
+ },
330
+ human_oversight: {
331
+ enabled: false,
332
+ require_review_for: [],
333
+ review_timeout_hours: 24,
334
+ escalation_policy: {
335
+ timeout_action: 'alert',
336
+ escalate_to: null,
337
+ },
338
+ },
339
+ // ISO 42001 A.5 - AI Impact Assessment
340
+ impact_assessment: {
341
+ enabled: false,
342
+ require_before_production: true,
343
+ review_interval_days: 365,
344
+ categories: ['fairness', 'privacy', 'safety', 'autonomy', 'economic', 'environmental'],
345
+ require_approvals: [
346
+ { role: 'ai_governance' },
347
+ { role: 'legal' },
348
+ { role: 'ethics_board' },
349
+ ],
350
+ risk_matrix: {
351
+ likelihood_weights: { rare: 1, unlikely: 2, possible: 3, likely: 4, certain: 5 },
352
+ severity_weights: { minimal: 1, minor: 2, moderate: 3, major: 4, catastrophic: 5 },
353
+ },
354
+ },
355
+ // ISO 42001 A.6 - AI System Life Cycle
356
+ lifecycle: {
357
+ enabled: false,
358
+ require_objectives: true,
359
+ require_requirements: true,
360
+ require_v_and_v: true,
361
+ stage_prerequisites: {
362
+ testing: ['requirements_defined'],
363
+ staging: ['verification_complete'],
364
+ production: ['validation_complete', 'deployment_approved'],
365
+ deprecated: ['decommission_plan'],
366
+ },
367
+ },
368
+ // ISO 42001 A.7 - Data Governance
369
+ data_governance: {
370
+ enabled: false,
371
+ require_quality_assessment: true,
372
+ default_quality_thresholds: {
373
+ completeness: 0.95,
374
+ accuracy: 0.90,
375
+ consistency: 0.95,
376
+ timeliness: 0.80,
377
+ uniqueness: 0.99,
378
+ representativeness: 0.70,
379
+ },
380
+ require_bias_assessment_for: ['training', 'validation'],
381
+ },
382
+ // ISO 42001 A.8/A.10 - Stakeholder & Third-Party Management
383
+ stakeholders: {
384
+ enabled: false,
385
+ require_supplier_assessment: true,
386
+ supplier_review_interval_days: 365,
387
+ risk_thresholds: {
388
+ critical_requires_approval: true,
389
+ high_requires_review: true,
390
+ },
391
+ },
392
+ // ISO 42001 A.4/A.2 - Resource Inventory & Policy Review
393
+ resources: {
394
+ enabled: false,
395
+ require_tooling_approval: true,
396
+ policy_review_interval_days: 365,
397
+ track_competencies: true,
398
+ },
399
+ onboarding: {
400
+ enabled: false,
401
+ required_in_production: true,
402
+ status: 'draft',
403
+ standards: ['SOC2', 'GDPR', 'ISO27001'],
404
+ artifacts: {
405
+ production_logs_path: './monora_events.jsonl',
406
+ schema_contract_path: './onboarding/schema_contract.json',
407
+ dataset_sample_path: null,
408
+ baseline_reports_dir: './monora_reports/onboarding',
409
+ },
410
+ validation: {
411
+ min_log_records: 100,
412
+ required_field_presence_threshold: 0.95,
413
+ type_conformance_threshold: 0.90,
414
+ },
415
+ completion: {
416
+ completed_at: null,
417
+ completed_by: null,
418
+ last_validated_at: null,
419
+ },
420
+ },
421
+ model_spec: {
422
+ name: 'monora_default',
423
+ version: 'v1',
424
+ event_ts_field: 'timestamp',
425
+ schema_ref: './onboarding/schema_contract.json',
426
+ roles: {
427
+ inputs: [],
428
+ outputs: [],
429
+ metadata: [],
430
+ identifiers: ['event_id', 'trace_id', 'span_id'],
431
+ },
432
+ },
433
+ enrichments: {
434
+ profile: 'recommended',
435
+ bundles: [
436
+ 'core_observability',
437
+ 'soc2_access',
438
+ 'gdpr_privacy',
439
+ 'iso27001_security',
440
+ ],
441
+ toggles: {
442
+ identity_tracking: true,
443
+ risk_tracking: true,
444
+ bias_tracking: false,
445
+ oversight_tracking: true,
446
+ data_governance_tracking: true,
447
+ lifecycle_tracking: true,
448
+ },
449
+ },
290
450
  };
291
451
  function loadConfig(options) {
292
452
  const { configPath, configDict, envPrefix = 'MONORA_' } = options || {};
293
- let config = deepCopy(DEFAULT_CONFIG);
453
+ let config = deepCopy(exports.DEFAULT_CONFIG);
294
454
  // Load from environment variables
295
455
  const envConfig = configFromEnv(envPrefix);
296
456
  mergeDicts(config, envConfig);
@@ -608,7 +768,7 @@ function parseSinkConfig(sink) {
608
768
  return [{
609
769
  type: 'file',
610
770
  path: sinkStr,
611
- rotation: 'daily',
771
+ rotation: 'none',
612
772
  max_size_mb: 100,
613
773
  }];
614
774
  }
@@ -633,7 +793,7 @@ function getPresetConfig(preset) {
633
793
  function buildConfigFromOptions(options = {}) {
634
794
  const { preset, serviceName, sink, policies, configPath, configDict } = options;
635
795
  // Start with defaults
636
- let config = deepCopy(DEFAULT_CONFIG);
796
+ let config = deepCopy(exports.DEFAULT_CONFIG);
637
797
  // Apply preset if specified
638
798
  if (preset && preset !== 'auto') {
639
799
  const presetConfig = getPresetConfig(preset);
@@ -668,3 +828,192 @@ function buildConfigFromOptions(options = {}) {
668
828
  (0, config_migrations_1.applyConfigMigrations)(config);
669
829
  return config;
670
830
  }
831
+ /**
832
+ * Detect the runtime environment from common signals.
833
+ *
834
+ * Checks in order of priority:
835
+ * 1. Explicit NODE_ENV
836
+ * 2. CI/CD environment variables
837
+ * 3. Container orchestrator hints
838
+ * 4. Framework-specific variables
839
+ *
840
+ * @returns Detection result with environment, source, and confidence
841
+ */
842
+ function detectEnvironment() {
843
+ const context = {};
844
+ // 1. Check explicit NODE_ENV (highest priority)
845
+ const nodeEnv = process.env.NODE_ENV?.toLowerCase();
846
+ if (nodeEnv) {
847
+ context.NODE_ENV = nodeEnv;
848
+ if (nodeEnv === 'production' || nodeEnv === 'prod') {
849
+ return {
850
+ environment: 'production',
851
+ source: 'NODE_ENV',
852
+ confidence: 'high',
853
+ context,
854
+ };
855
+ }
856
+ if (nodeEnv === 'staging' || nodeEnv === 'stage') {
857
+ return {
858
+ environment: 'staging',
859
+ source: 'NODE_ENV',
860
+ confidence: 'high',
861
+ context,
862
+ };
863
+ }
864
+ if (nodeEnv === 'test' || nodeEnv === 'testing') {
865
+ return {
866
+ environment: 'test',
867
+ source: 'NODE_ENV',
868
+ confidence: 'high',
869
+ context,
870
+ };
871
+ }
872
+ if (nodeEnv === 'development' || nodeEnv === 'dev') {
873
+ return {
874
+ environment: 'development',
875
+ source: 'NODE_ENV',
876
+ confidence: 'high',
877
+ context,
878
+ };
879
+ }
880
+ }
881
+ // 2. Check CI/CD environment variables
882
+ const ciVars = {
883
+ CI: process.env.CI,
884
+ GITHUB_ACTIONS: process.env.GITHUB_ACTIONS,
885
+ GITLAB_CI: process.env.GITLAB_CI,
886
+ CIRCLECI: process.env.CIRCLECI,
887
+ TRAVIS: process.env.TRAVIS,
888
+ JENKINS_URL: process.env.JENKINS_URL,
889
+ BUILDKITE: process.env.BUILDKITE,
890
+ AZURE_PIPELINES: process.env.TF_BUILD,
891
+ TEAMCITY_VERSION: process.env.TEAMCITY_VERSION,
892
+ BITBUCKET_PIPELINES: process.env.BITBUCKET_BUILD_NUMBER,
893
+ };
894
+ for (const [varName, value] of Object.entries(ciVars)) {
895
+ if (value && value !== 'false' && value !== '0') {
896
+ context[varName] = value;
897
+ return {
898
+ environment: 'ci',
899
+ source: varName,
900
+ confidence: 'high',
901
+ context,
902
+ };
903
+ }
904
+ }
905
+ // 3. Check container orchestrator hints
906
+ if (process.env.KUBERNETES_SERVICE_HOST) {
907
+ context.KUBERNETES_SERVICE_HOST = process.env.KUBERNETES_SERVICE_HOST;
908
+ // K8s typically means production or staging
909
+ return {
910
+ environment: 'production',
911
+ source: 'KUBERNETES_SERVICE_HOST',
912
+ confidence: 'medium',
913
+ context,
914
+ };
915
+ }
916
+ if (process.env.ECS_CONTAINER_METADATA_URI || process.env.AWS_EXECUTION_ENV) {
917
+ context.AWS = process.env.ECS_CONTAINER_METADATA_URI || process.env.AWS_EXECUTION_ENV || '';
918
+ return {
919
+ environment: 'production',
920
+ source: 'AWS_ECS',
921
+ confidence: 'medium',
922
+ context,
923
+ };
924
+ }
925
+ if (process.env.CLOUD_RUN_JOB || process.env.K_SERVICE) {
926
+ context.GCP = process.env.CLOUD_RUN_JOB || process.env.K_SERVICE || '';
927
+ return {
928
+ environment: 'production',
929
+ source: 'GCP_CLOUD_RUN',
930
+ confidence: 'medium',
931
+ context,
932
+ };
933
+ }
934
+ // 4. Check for common cloud platform variables
935
+ if (process.env.VERCEL) {
936
+ context.VERCEL = process.env.VERCEL;
937
+ const vercelEnv = process.env.VERCEL_ENV?.toLowerCase();
938
+ if (vercelEnv === 'production') {
939
+ return { environment: 'production', source: 'VERCEL_ENV', confidence: 'high', context };
940
+ }
941
+ if (vercelEnv === 'preview') {
942
+ return { environment: 'staging', source: 'VERCEL_ENV', confidence: 'high', context };
943
+ }
944
+ return { environment: 'development', source: 'VERCEL', confidence: 'medium', context };
945
+ }
946
+ if (process.env.RAILWAY_ENVIRONMENT) {
947
+ context.RAILWAY_ENVIRONMENT = process.env.RAILWAY_ENVIRONMENT;
948
+ const railwayEnv = process.env.RAILWAY_ENVIRONMENT.toLowerCase();
949
+ if (railwayEnv === 'production') {
950
+ return { environment: 'production', source: 'RAILWAY_ENVIRONMENT', confidence: 'high', context };
951
+ }
952
+ return { environment: 'staging', source: 'RAILWAY_ENVIRONMENT', confidence: 'medium', context };
953
+ }
954
+ if (process.env.HEROKU_APP_NAME) {
955
+ context.HEROKU_APP_NAME = process.env.HEROKU_APP_NAME;
956
+ // Heroku typically indicates production deployment
957
+ return {
958
+ environment: 'production',
959
+ source: 'HEROKU',
960
+ confidence: 'medium',
961
+ context,
962
+ };
963
+ }
964
+ if (process.env.FLY_APP_NAME) {
965
+ context.FLY_APP_NAME = process.env.FLY_APP_NAME;
966
+ return {
967
+ environment: 'production',
968
+ source: 'FLY_IO',
969
+ confidence: 'medium',
970
+ context,
971
+ };
972
+ }
973
+ // 5. Check for test runners
974
+ if (process.env.JEST_WORKER_ID) {
975
+ context.JEST_WORKER_ID = process.env.JEST_WORKER_ID;
976
+ return {
977
+ environment: 'test',
978
+ source: 'JEST_WORKER_ID',
979
+ confidence: 'high',
980
+ context,
981
+ };
982
+ }
983
+ if (process.env.VITEST) {
984
+ context.VITEST = process.env.VITEST;
985
+ return {
986
+ environment: 'test',
987
+ source: 'VITEST',
988
+ confidence: 'high',
989
+ context,
990
+ };
991
+ }
992
+ // 6. Default to development with low confidence
993
+ return {
994
+ environment: 'development',
995
+ source: 'default',
996
+ confidence: 'low',
997
+ context,
998
+ };
999
+ }
1000
+ /**
1001
+ * Get a suggested preset based on detected environment.
1002
+ *
1003
+ * @returns Recommended preset name for the detected environment
1004
+ */
1005
+ function suggestPreset() {
1006
+ const detection = detectEnvironment();
1007
+ switch (detection.environment) {
1008
+ case 'production':
1009
+ return 'strict_enterprise';
1010
+ case 'staging':
1011
+ return 'poc';
1012
+ case 'ci':
1013
+ case 'test':
1014
+ return 'minimal';
1015
+ case 'development':
1016
+ default:
1017
+ return 'development';
1018
+ }
1019
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"config_migrations.d.ts","sourceRoot":"","sources":["../src/config_migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG7C,eAAO,MAAM,qBAAqB,UAAU,CAAC;AAG7C,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAwBxE;AA0JD;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,YAAY,GAAG,0BAA0B,EAAE,CA6G9F;AAED;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAC5C,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACrC,WAAW,EAAE,MAAM,GAClB,0BAA0B,GAAG,IAAI,CA2BnC;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,0BAA0B,EAAE,GAAG,IAAI,CAalF"}
1
+ {"version":3,"file":"config_migrations.d.ts","sourceRoot":"","sources":["../src/config_migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG7C,eAAO,MAAM,qBAAqB,UAAU,CAAC;AAG7C,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CA2BxE;AA+LD;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,YAAY,GAAG,0BAA0B,EAAE,CA6G9F;AAED;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAC5C,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACrC,WAAW,EAAE,MAAM,GAClB,0BAA0B,GAAG,IAAI,CA2BnC;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,0BAA0B,EAAE,GAAG,IAAI,CAalF"}
@@ -18,12 +18,14 @@ function applyConfigMigrations(config) {
18
18
  if (!config.config_version) {
19
19
  config.config_version = exports.LATEST_CONFIG_VERSION;
20
20
  }
21
+ normalizeOnboarding(config);
21
22
  return config;
22
23
  }
23
24
  if (compareVersions(version, '1.0.0') < 0) {
24
25
  migrate000To100(config);
25
26
  config.config_version = exports.LATEST_CONFIG_VERSION;
26
27
  }
28
+ normalizeOnboarding(config);
27
29
  return config;
28
30
  }
29
31
  function compareVersions(left, right) {
@@ -162,6 +164,41 @@ function normalizeErrorHandling(config) {
162
164
  }
163
165
  }
164
166
  }
167
+ function normalizeOnboarding(config) {
168
+ const cfg = config;
169
+ if (!cfg.onboarding && cfg.onboard && typeof cfg.onboard === 'object') {
170
+ cfg.onboarding = cfg.onboard;
171
+ delete cfg.onboard;
172
+ }
173
+ if (cfg.onboarding && typeof cfg.onboarding === 'object') {
174
+ const onboarding = cfg.onboarding;
175
+ if (onboarding.require_in_production !== undefined && onboarding.required_in_production === undefined) {
176
+ onboarding.required_in_production = onboarding.require_in_production;
177
+ }
178
+ if (typeof onboarding.status === 'string') {
179
+ const status = onboarding.status.toLowerCase();
180
+ if (['draft', 'validated', 'completed'].includes(status)) {
181
+ onboarding.status = status;
182
+ }
183
+ else {
184
+ onboarding.status = 'draft';
185
+ }
186
+ }
187
+ const artifacts = onboarding.artifacts;
188
+ if (artifacts && typeof artifacts === 'object') {
189
+ if (artifacts.input_path && !artifacts.production_logs_path) {
190
+ artifacts.production_logs_path = artifacts.input_path;
191
+ }
192
+ if (artifacts.schema_path && !artifacts.schema_contract_path) {
193
+ artifacts.schema_contract_path = artifacts.schema_path;
194
+ }
195
+ }
196
+ }
197
+ if (!cfg.enrichments && cfg.enrichment && typeof cfg.enrichment === 'object') {
198
+ cfg.enrichments = cfg.enrichment;
199
+ delete cfg.enrichment;
200
+ }
201
+ }
165
202
  /**
166
203
  * Validate configuration against production best practices.
167
204
  *
@@ -237,7 +274,7 @@ function validateProductionReadiness(config) {
237
274
  warnings.push({
238
275
  category: 'durability',
239
276
  message: "WAL sync mode is 'none' (data may be lost on crash)",
240
- recommendation: "Set wal.sync_mode='normal' or 'full' for durability",
277
+ recommendation: "Set wal.sync_mode='fsync' (avoid 'none') for durability",
241
278
  });
242
279
  }
243
280
  // Check error handling