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
package/README.md CHANGED
@@ -1,40 +1,117 @@
1
- # Monora SDK for Node.js v1.9.3
1
+ # Monora SDK for Node.js v2.1.3
2
2
 
3
3
  Lightweight governance and trace SDK for AI systems.
4
4
 
5
5
  ![Monora SDK screenshot](assets/sdk-screenshot.png)
6
6
 
7
- ## Features
7
+ ---
8
8
 
9
- - **Immutable Event Logs**: SHA-256 hash chains for tamper-evident audit trails
10
- - **Policy Enforcement**: Model allowlist/denylist with classification-based rules
11
- - **Model Registry**: Centralized model and provider metadata
12
- - **Tracing**: Distributed tracing for AI system observability
13
- - **Event Processing**: Background event dispatcher with batching and buffering
14
- - **Multiple Sinks**: Output to stdout, file (JSON-lines), or HTTPS endpoints
15
- - **Durable HTTPS Delivery**: Retry queue + idempotency headers for HTTP sinks
16
- - **Event Enrichment**: Automatic metadata (timestamp, host, process, environment)
9
+ ## Streamlined Setup (Recommended)
10
+
11
+ Use this local-first onboarding flow to get production-ready governance/reporting quickly:
12
+
13
+ ```bash
14
+ # 1. Install and generate a base config
15
+ npm install monora-ai
16
+ npx monora-ai init --preset production
17
+
18
+ # 2. Initialize onboarding contract + model spec + enrichment bundles
19
+ npx monora-ai onboard init --config monora.yml
20
+
21
+ # 3. Validate logs + schema mapping + role mapping
22
+ npx monora-ai onboard validate --config monora.yml --pretty
23
+
24
+ # 4. Complete onboarding and auto-generate baseline reports
25
+ npx monora-ai onboard complete --config monora.yml --completed-by "platform-team" --pretty
17
26
 
18
- ### New in v1.9.0
27
+ # 5. Check onboarding status and generated artifacts
28
+ npx monora-ai onboard status --config monora.yml --pretty
29
+ ```
30
+
31
+ On completion, Monora writes baseline reports and summaries under `onboarding.artifacts.baseline_reports_dir` (default `./monora_reports/onboarding`):
32
+
33
+ - `soc2_baseline_report.json`
34
+ - `gdpr_baseline_report.json`
35
+ - `iso27001_baseline_report.json`
36
+ - `onboarding_validation.json`
37
+ - `onboarding_summary.json`
38
+
39
+ Each baseline report includes:
19
40
 
20
- - **🔄 Circuit Breaker**: Fault tolerance for HTTPS sinks with automatic recovery
21
- - **📊 Telemetry/Analytics**: Prometheus and StatsD metrics export for observability
22
- - **📄 PDF Reports**: Generate compliance and EU AI Act PDF reports
23
- - **🌐 Next.js Middleware**: W3C Trace Context propagation for Next.js applications
41
+ - `claims[].severity`
42
+ - `claims[].remediation`
43
+ - `findings_summary` (totals, status breakdown, remediation recommendations)
24
44
 
25
- ## Installation
45
+ ---
46
+
47
+ ## CLI Reference
26
48
 
27
49
  ```bash
28
- npm install monora-ai
50
+ # Configuration
51
+ npx monora-ai init # Interactive setup wizard
52
+ npx monora-ai init --yes # Quick setup with defaults
53
+ npx monora-ai init --preset minimal # Minimal preset
54
+ npx monora-ai init --preset dev # Dev preset (file + pretty stdout)
55
+ npx monora-ai init --preset production # Production preset
56
+ npx monora-ai validate # Validate config file
57
+ npx monora-ai validate --mode lenient # Lenient validation
58
+ npx monora-ai doctor # Diagnose configuration issues
59
+ npx monora-ai config fix # Auto-fix common config issues
60
+
61
+ # Onboarding lifecycle
62
+ npx monora-ai onboard init --config monora.yml
63
+ npx monora-ai onboard validate --config monora.yml --input ./monora_events.jsonl --pretty
64
+ npx monora-ai onboard complete --config monora.yml --completed-by "platform-team" --pretty
65
+ npx monora-ai onboard status --config monora.yml --pretty
66
+
67
+ # Schema/model bootstrapping
68
+ npx monora-ai schema infer \
69
+ --input ./monora_events.jsonl \
70
+ --output ./monora_spec.json \
71
+ --compliance-target gdpr \
72
+ --compliance-target soc2 \
73
+ --compliance-target iso42001 \
74
+ --report ./monora_inference_report.json \
75
+ --contract ./onboarding/schema_contract.json
76
+
77
+ npx monora-ai model create \
78
+ --input ./monora_events.jsonl \
79
+ --output ./monora_model.json \
80
+ --model-name support-bot \
81
+ --risk-category high \
82
+ --compliance-target gdpr \
83
+ --compliance-target soc2 \
84
+ --compliance-target iso42001 \
85
+ --config-out ./monora_model_config.json \
86
+ --config-format json \
87
+ --contract-out ./onboarding/schema_contract.json
88
+
89
+ # Reports
90
+ npx monora-ai report --input events.jsonl --output report.json
91
+ npx monora-ai report --input events.jsonl --output report.md --format markdown
92
+
93
+ # Security & Verification
94
+ npx monora-ai security-review --input events.jsonl --output security.json
95
+ npx monora-ai verify --input events.jsonl --config monora.yml --pretty
96
+
97
+ # Trust Packages
98
+ npx monora-ai trust-package --input events.jsonl --trace-id trc_123 --output trust.json
99
+
100
+ # HTTP Queue Management
101
+ npx monora-ai retry-queue --config monora.yml
102
+ npx monora-ai retry-queue --path ./monora_http_queue --clear
29
103
  ```
30
104
 
105
+ ---
106
+
31
107
  ## Quick Start
32
108
 
109
+ After setup, initialize Monora in your app:
110
+
33
111
  ```typescript
34
112
  import { init, llmCall, trace } from 'monora-ai';
35
113
 
36
- // Initialize SDK
37
- init({ configPath: './monora.yml' });
114
+ await init({ configPath: './monora.yml' });
38
115
 
39
116
  const ask = llmCall({ purpose: 'support' })(function ask(
40
117
  question: string,
@@ -50,6 +127,180 @@ trace('my-ai-task', (span) => {
50
127
  });
51
128
  ```
52
129
 
130
+ Production gate behavior:
131
+
132
+ - If `defaults.environment=production`
133
+ - And `onboarding.enabled=true`
134
+ - And `onboarding.required_in_production=true`
135
+ - And `onboarding.status!=completed`
136
+
137
+ `init()` fails fast with an onboarding-required error.
138
+
139
+ ---
140
+
141
+ ## Presets
142
+
143
+ Use presets to generate opinionated configs:
144
+
145
+ - minimal: file sink only, relaxed validation, minimal setup
146
+ - dev: file + pretty stdout, relaxed validation for local development
147
+ - production: file sink with daily rotation + symlink, strict validation
148
+
149
+ Example:
150
+
151
+ ```bash
152
+ npx monora-ai init --preset dev
153
+ ```
154
+
155
+ ---
156
+
157
+ ## Configuration
158
+
159
+ `monora.yml` is the default config path (`monora.json` is also supported). For onboarding-driven production setup:
160
+
161
+ ```yaml
162
+ defaults:
163
+ data_classification: internal
164
+ environment: production
165
+
166
+ onboarding:
167
+ enabled: true
168
+ required_in_production: true
169
+ status: draft # draft | validated | completed
170
+ standards: [SOC2, GDPR, ISO27001]
171
+ artifacts:
172
+ production_logs_path: ./monora_events.jsonl
173
+ schema_contract_path: ./onboarding/schema_contract.json
174
+ dataset_sample_path: ./onboarding/dataset_sample.jsonl # optional
175
+ baseline_reports_dir: ./monora_reports/onboarding
176
+ validation:
177
+ min_log_records: 100
178
+ required_field_presence_threshold: 0.95
179
+ type_conformance_threshold: 0.90
180
+
181
+ model_spec:
182
+ name: monora_default
183
+ version: v1
184
+ event_ts_field: timestamp
185
+ schema_ref: ./onboarding/schema_contract.json
186
+ roles:
187
+ inputs: [body.prompt]
188
+ outputs: [body.response]
189
+ metadata: [event_type, service_name, timestamp]
190
+ identifiers: [event_id, trace_id, span_id]
191
+
192
+ enrichments:
193
+ profile: recommended
194
+ bundles: [core_observability, soc2_access, gdpr_privacy, iso27001_security]
195
+ toggles:
196
+ identity_tracking: true
197
+ risk_tracking: true
198
+ bias_tracking: false
199
+ oversight_tracking: true
200
+ data_governance_tracking: true
201
+ lifecycle_tracking: true
202
+ ```
203
+
204
+ Notes:
205
+
206
+ - `onboard validate` returns `coverage.profiling` and `coverage.inference` (field profiles, role suggestions, timestamp suggestion, schema mapping gaps).
207
+ - `onboard complete` generates one report per selected standard and records outputs in `artifacts.baseline_reports`.
208
+ - Enrichment bundles map to existing Monora observability, access, privacy, and security controls.
209
+
210
+ ### Programmatic Onboarding API
211
+
212
+ ```typescript
213
+ import {
214
+ buildModelSpec,
215
+ validateOnboarding,
216
+ completeOnboarding,
217
+ } from 'monora-ai';
218
+
219
+ const modelSpec = buildModelSpec({
220
+ schemaRef: './onboarding/schema_contract.json',
221
+ roles: {
222
+ inputs: ['body.prompt'],
223
+ outputs: ['body.response'],
224
+ metadata: ['event_type', 'service_name', 'timestamp'],
225
+ identifiers: ['event_id', 'trace_id', 'span_id'],
226
+ },
227
+ });
228
+
229
+ const validation = validateOnboarding({ configPath: './monora.yml' });
230
+ if (validation.status === 'validated') {
231
+ const completion = completeOnboarding({
232
+ configPath: './monora.yml',
233
+ completedBy: 'platform-team',
234
+ });
235
+ console.log(completion.status);
236
+ }
237
+ ```
238
+
239
+ Allowlist/denylist patterns use glob syntax (minimatch), for example `gpt-*` matches `gpt-4o-mini`.
240
+
241
+ ### HTTP Retry Queue + Idempotency
242
+
243
+ ```yaml
244
+ sinks:
245
+ - type: https
246
+ endpoint: https://api.example.com/events # replace with your endpoint
247
+ retry_queue:
248
+ enabled: true
249
+ path: ./monora_http_queue
250
+ max_items: 10000
251
+ flush_interval_sec: 5.0
252
+ idempotency:
253
+ enabled: true
254
+ header_name: Idempotency-Key
255
+ ```
256
+
257
+ Idempotency keys are computed per batch as a SHA-256 digest of the canonical event JSON in order.
258
+
259
+ ```bash
260
+ npx monora-ai retry-queue --config monora.yml
261
+ npx monora-ai retry-queue --path ./monora_http_queue --clear
262
+ ```
263
+
264
+ ---
265
+
266
+ ### File Sink Rotation
267
+
268
+ ```yaml
269
+ sinks:
270
+ - type: file
271
+ path: ./monora_events.jsonl
272
+ rotation: daily # none | daily | size
273
+ symlink: true # keeps monora_events.jsonl and monora_events.latest.jsonl pointing to the newest file
274
+ ```
275
+
276
+ When rotation is enabled, use `./monora_events.latest.jsonl` in scripts to always read the current file.
277
+
278
+ ---
279
+
280
+ ## Features
281
+
282
+ - **Immutable Event Logs**: SHA-256 hash chains for tamper-evident audit trails
283
+ - **Policy Enforcement**: Model allowlist/denylist with classification-based rules
284
+ - **Model Registry**: Centralized model and provider metadata
285
+ - **Tracing**: Distributed tracing for AI system observability
286
+ - **Event Processing**: Background event dispatcher with batching and buffering
287
+ - **Multiple Sinks**: Output to stdout, file (JSON-lines), or HTTPS endpoints
288
+ - **Durable HTTPS Delivery**: Retry queue + idempotency headers for HTTP sinks
289
+ - **Event Enrichment**: Automatic metadata (timestamp, host, process, environment)
290
+ - **Attribution + Usage Telemetry**: Optional project registration and anonymous usage stats (opt-in)
291
+ - **Compliance Assessment Hooks**: Built-in checks and usage profiles for audits
292
+
293
+ ### New in v2.1.3
294
+
295
+ - **Circuit Breaker**: Fault tolerance for HTTPS sinks with automatic recovery
296
+ - **Telemetry/Analytics**: Prometheus and StatsD metrics export for observability
297
+ - **PDF Reports**: Generate compliance and EU AI Act PDF reports
298
+ - **Next.js Middleware**: W3C Trace Context propagation for Next.js applications
299
+
300
+ ---
301
+
302
+ ## Usage Examples
303
+
53
304
  ### Decorator Helpers (TypeScript)
54
305
 
55
306
  ```typescript
@@ -85,32 +336,32 @@ Enable decorators in your `tsconfig.json`:
85
336
  }
86
337
  ```
87
338
 
88
- ### Guided Setup (Wizard)
89
-
90
- ```bash
91
- npx monora-ai init
92
- # or
93
- ./node_modules/.bin/monora init
94
- ```
339
+ ### High-level Runtime Helpers
95
340
 
96
- This generates a `monora.yml` you can load with `loadConfig({ configPath: './monora.yml' })`.
341
+ ```typescript
342
+ import { init, logEvent, toolCall, agentStep, setViolationHandler } from 'monora-ai';
97
343
 
98
- ### Reports & Security Review
344
+ init({ configPath: './monora.yml' });
99
345
 
100
- The runtime automatically generates compliance reports at trace completion (default: `./monora_reports/<trace_id>/compliance.json`) and emits a `trust_summary` event. Configure behavior with the `reporting` section in `monora.yml`.
346
+ setViolationHandler((violation) => {
347
+ console.error('Violation:', violation.message);
348
+ });
101
349
 
102
- ```bash
103
- npx monora-ai report --input events.jsonl --output report.json
104
- npx monora-ai report --input events.jsonl --output report.md --format markdown
350
+ const fetchTool = toolCall({ toolName: 'fetch', purpose: 'integration' })(async (url: string) => {
351
+ return { ok: true, url };
352
+ });
105
353
 
106
- npx monora-ai security-review --input events.jsonl --output security.json
107
- npx monora-ai security-review --input events.jsonl --output security.json --sign gpg --gpg-key "you@example.com"
354
+ const plan = agentStep({ agentName: 'planner', stepType: 'planning', purpose: 'analysis' })(
355
+ (goal: string) => [`step for ${goal}`]
356
+ );
108
357
 
109
- npx monora-ai trust-package --input events.jsonl --trace-id trc_123 --output trust.json --config monora.yml
110
- npx monora-ai verify --input events.jsonl --config monora.yml --pretty
111
- npx monora-ai retry-queue --config monora.yml
358
+ logEvent('custom', { message: 'hello' }, { purpose: 'manual' });
112
359
  ```
113
360
 
361
+ ### Reports & Trust Packages
362
+
363
+ The runtime automatically generates compliance reports at trace completion (default: `./monora_reports/<trace_id>/compliance.json`) and emits a `trust_summary` event.
364
+
114
365
  ```typescript
115
366
  import { exportTrustPackage } from 'monora-ai';
116
367
 
@@ -123,7 +374,7 @@ const trustPackage = exportTrustPackage('trc_123', {
123
374
  ### Data Handling + Alerts
124
375
 
125
376
  ```typescript
126
- import { DataHandlingEngine, buildDataViolation, ViolationWebhookDispatcher } from 'monora-ai';
377
+ import { DataHandlingEngine, ViolationWebhookDispatcher } from 'monora-ai';
127
378
 
128
379
  const dataHandling = new DataHandlingEngine({
129
380
  enabled: true,
@@ -144,77 +395,7 @@ dispatcher.start();
144
395
  dispatcher.send({ event_type: 'policy_violation', message: 'Example violation' });
145
396
  ```
146
397
 
147
- ### High-level Runtime Helpers
148
-
149
- ```typescript
150
- import { init, logEvent, toolCall, agentStep, setViolationHandler } from 'monora-ai';
151
-
152
- init({ configPath: './monora.yml' });
153
-
154
- setViolationHandler((violation) => {
155
- console.error('Violation:', violation.message);
156
- });
157
-
158
- const fetchTool = toolCall({ toolName: 'fetch', purpose: 'integration' })(async (url: string) => {
159
- return { ok: true, url };
160
- });
161
-
162
- const plan = agentStep({ agentName: 'planner', stepType: 'planning', purpose: 'analysis' })(
163
- (goal: string) => [`step for ${goal}`]
164
- );
165
-
166
- logEvent('custom', { message: 'hello' }, { purpose: 'manual' });
167
- ```
168
-
169
- ## Configuration
170
-
171
- Create a `monora.json` or `monora.yaml` file:
172
-
173
- ```json
174
- {
175
- "defaults": {
176
- "data_classification": "internal",
177
- "environment": "production"
178
- },
179
- "policies": {
180
- "model_allowlist": ["gpt-4*", "claude-3-*"],
181
- "model_denylist": ["deepseek:*"],
182
- "enforce": true
183
- },
184
- "immutability": {
185
- "enabled": true,
186
- "scope": "per_trace",
187
- "hash_algorithm": "sha256"
188
- }
189
- }
190
- ```
191
-
192
- ### HTTP Retry Queue + Idempotency
193
-
194
- ```yaml
195
- sinks:
196
- - type: https
197
- endpoint: https://api.example.com/events
198
- retry_queue:
199
- enabled: true
200
- path: ./monora_http_queue
201
- max_items: 10000
202
- flush_interval_sec: 5.0
203
- idempotency:
204
- enabled: true
205
- header_name: Idempotency-Key
206
- ```
207
-
208
- Idempotency keys are computed per batch as a SHA-256 digest of the canonical
209
- event JSON in order. Reordering events or changing batch boundaries changes the
210
- idempotency key.
211
-
212
- Inspect or clear the local retry queue:
213
-
214
- ```bash
215
- npx monora-ai retry-queue --config monora.yml
216
- npx monora-ai retry-queue --path ./monora_http_queue --clear
217
- ```
398
+ ---
218
399
 
219
400
  ## API Documentation
220
401
 
@@ -224,7 +405,7 @@ npx monora-ai retry-queue --path ./monora_http_queue --clear
224
405
  import { PolicyEngine } from 'monora-ai';
225
406
 
226
407
  const engine = new PolicyEngine({
227
- model_allowlist: ['gpt-4*'],
408
+ model_allowlist: ['gpt-*', 'claude-*', 'o1-*', 'gemini-*'],
228
409
  model_denylist: ['deepseek:*'],
229
410
  enforce: true
230
411
  });
@@ -293,23 +474,10 @@ const gaps = detectSequenceGaps(events);
293
474
  console.log('Sequence gaps:', gaps);
294
475
  ```
295
476
 
296
- ### Security Reports
297
-
298
- Generate JSON security review reports locally with CLI:
299
-
300
- Auth: none (local CLI). Errors: invalid JSONL/config or GPG signing failures.
301
-
302
- ```bash
303
- npx monora-ai security-review --input events.jsonl --output security.json
304
- npx monora-ai security-review --input events.jsonl --output security.json --config monora.yml
305
- ```
306
-
307
477
  ### Data Handling
308
478
 
309
479
  Use the data handling engine for redaction or blocking decisions (modes: `redact`, `block`, `allow`):
310
480
 
311
- Auth: none. Errors: `DataHandlingViolation` in block mode or invalid regex patterns.
312
-
313
481
  ```typescript
314
482
  import { DataHandlingEngine } from 'monora-ai';
315
483
 
@@ -325,8 +493,6 @@ const { value, applied } = engine.sanitizePayload('request', payload, 'confident
325
493
 
326
494
  Send policy violation payloads to a webhook:
327
495
 
328
- Auth: set headers such as `Authorization`. Errors: network failures, non-2xx responses, or queue overflow.
329
-
330
496
  ```typescript
331
497
  import { ViolationWebhookDispatcher } from 'monora-ai';
332
498
 
@@ -349,8 +515,6 @@ dispatcher.send({ event_type: 'policy_violation', message: 'Blocked model' });
349
515
 
350
516
  ### Event Building and Dispatching
351
517
 
352
- Event builder and dispatcher classes are available in the current Node SDK.
353
-
354
518
  ```typescript
355
519
  import { EventBuilder, EventDispatcher, StdoutSink, FileSink } from 'monora-ai';
356
520
 
@@ -372,7 +536,7 @@ const event = builder.build('llm_call', {
372
536
 
373
537
  // Setup event dispatcher with sinks
374
538
  const sinks = [
375
- new StdoutSink('json'),
539
+ new StdoutSink('pretty'),
376
540
  new FileSink('./events.jsonl', { batchSize: 100 }),
377
541
  ];
378
542
 
@@ -388,8 +552,6 @@ dispatcher.close();
388
552
 
389
553
  ### Sink Options
390
554
 
391
- These sink implementations are exported and ready for use.
392
-
393
555
  ```typescript
394
556
  // Stdout Sink
395
557
  const stdoutSink = new StdoutSink('pretty'); // or 'json'
@@ -402,7 +564,8 @@ const fileSink = new FileSink('./logs/events.jsonl', {
402
564
  maxSizeMb: 100,
403
565
  });
404
566
 
405
- // HTTPS Sink with retry
567
+ // HTTPS sinks are optional; the wizard will not enable them unless you provide an endpoint.
568
+ // HTTPS Sink with retry (example only)
406
569
  const httpsSink = new HttpSink(
407
570
  'https://api.example.com/events',
408
571
  { 'Authorization': 'Bearer token' },
@@ -415,7 +578,9 @@ const httpsSink = new HttpSink(
415
578
  );
416
579
  ```
417
580
 
418
- ## v1.9.0 Features
581
+ ---
582
+
583
+ ## Advanced Features
419
584
 
420
585
  ### Circuit Breaker
421
586
 
@@ -440,21 +605,19 @@ const httpsSink = new HttpSink(
440
605
 
441
606
  ### Telemetry/Analytics
442
607
 
443
- Telemetry is enabled by default with a minimal in-memory backend (queue depth,
444
- sink errors, retry queue size). Opt out with `telemetry.enabled: false`.
608
+ Telemetry is enabled by default with a minimal in-memory backend (queue depth, sink errors, retry queue size). Set `telemetry.backend` to `minimal`, `memory`, `prometheus`, `statsd`, or `none`. Opt out with `telemetry.backend: none` (or `telemetry.enabled: false`).
445
609
 
446
610
  Export metrics to Prometheus or StatsD:
447
611
 
448
612
  ```typescript
449
- import { init, initMetrics, recordEvent, recordViolation } from 'monora-ai';
613
+ import { init } from 'monora-ai';
450
614
 
451
- // Configure telemetry
452
615
  init({
453
616
  configPath: './monora.yml',
454
617
  config: {
455
618
  telemetry: {
456
619
  enabled: true,
457
- backend: 'prometheus', // or 'statsd'
620
+ backend: 'prometheus', // or 'statsd' | 'memory' | 'minimal' | 'none'
458
621
  prometheus: {
459
622
  port: 9090,
460
623
  start_server: true,
@@ -470,6 +633,79 @@ init({
470
633
  // - monora_tokens_total
471
634
  ```
472
635
 
636
+ ### Attribution & Usage Telemetry (Opt-In)
637
+
638
+ Collect optional attribution details and anonymous usage stats with explicit opt-in. No data leaves your environment unless `send_data` is enabled.
639
+
640
+ ```typescript
641
+ import { init } from 'monora-ai';
642
+
643
+ init({
644
+ configPath: './monora.yml',
645
+ config: {
646
+ attribution: {
647
+ enabled: true,
648
+ project: {
649
+ company: 'Acme Corp',
650
+ role: 'ML Engineer',
651
+ email: 'dev@acme.com',
652
+ source: 'npm',
653
+ use_case: 'Customer Support AI',
654
+ team_size: 'small',
655
+ business_owner: 'Jane Smith',
656
+ data_categories: ['PII']
657
+ },
658
+ telemetry: {
659
+ enabled: true,
660
+ send_data: true,
661
+ data_residency: 'us'
662
+ }
663
+ }
664
+ }
665
+ });
666
+ ```
667
+
668
+ You can also call `registerProject(...)` and `reportUsage(...)` directly.
669
+
670
+ ### Environment-Aware Presets
671
+
672
+ Monora can auto-select presets based on environment, or you can pick explicitly:
673
+
674
+ ```typescript
675
+ import { init } from 'monora-ai';
676
+
677
+ await init(); // auto-detect env (dev/poc/production)
678
+ await init({ preset: 'poc' }); // low-friction POC mode
679
+ await init({ preset: 'production' });
680
+ await init({ preset: 'strict_enterprise' });
681
+ ```
682
+
683
+ Additional presets: `default_secure`, `experimental`, `audit_first`, `low_latency`.
684
+
685
+ ### Migration Guidance (POC -> Production)
686
+
687
+ When you promote a POC to production, Monora will warn if you use a POC/dev preset in a production environment. You can also run the readiness checks directly:
688
+
689
+ ```typescript
690
+ import {
691
+ validateProductionReadiness,
692
+ checkPresetEnvironmentMismatch,
693
+ logProductionWarnings,
694
+ loadConfig,
695
+ } from 'monora-ai';
696
+
697
+ const config = loadConfig({ configPath: './monora.yml' });
698
+ let warnings = validateProductionReadiness(config);
699
+ const mismatch = checkPresetEnvironmentMismatch(
700
+ 'poc',
701
+ config.defaults?.environment || 'development'
702
+ );
703
+ if (mismatch) {
704
+ warnings = [mismatch, ...warnings];
705
+ }
706
+ logProductionWarnings(warnings);
707
+ ```
708
+
473
709
  ### Production Profiles
474
710
 
475
711
  Ship-ready templates with clear tradeoffs:
@@ -477,12 +713,51 @@ Ship-ready templates with clear tradeoffs:
477
713
  - Audit-first: `templates/monora_audit_first.yml` (strongest auditability, higher I/O and shutdown checks).
478
714
  - Low-latency: `templates/monora_low_latency.yml` (lowest overhead, weaker audit trail and reports).
479
715
 
716
+ ### Audit Hooks (onEvent)
717
+
718
+ Capture every emitted event for external audit systems or SIEM pipelines:
719
+
720
+ ```typescript
721
+ import { onEvent } from 'monora-ai';
722
+
723
+ const unsubscribe = onEvent((event) => {
724
+ console.log('Audit:', event.event_type, event.event_id);
725
+ // Forward to your audit sink
726
+ });
727
+
728
+ // Later: unsubscribe();
729
+ ```
730
+
731
+ ### Compliance Assessment & Audit Metadata
732
+
733
+ Capture audit metadata and run compliance checks for certification workflows:
734
+
735
+ ```typescript
736
+ import { setAuditMetadata, runComplianceCheck, reportUsageProfile } from 'monora-ai';
737
+
738
+ setAuditMetadata({
739
+ useCaseName: 'Customer Support AI',
740
+ businessOwner: 'Jane Smith',
741
+ dataCategories: ['PII', 'customer_data'],
742
+ riskLevel: 'medium',
743
+ complianceFrameworks: ['SOC2', 'ISO42001'],
744
+ });
745
+
746
+ const result = await runComplianceCheck({
747
+ eventsPath: './monora_events.jsonl',
748
+ configPath: './monora.yml',
749
+ });
750
+ const profile = reportUsageProfile();
751
+ ```
752
+
753
+ Compliance scores are weighted by framework and control category (integrity, auditability, privacy, and governance) instead of a flat pass rate.
754
+
480
755
  ### Standards Mapping (SOC 2 / GDPR / ISO)
481
756
 
482
757
  Evaluate external claims against Monora evidence (event IDs, causal paths, guardrails):
483
758
 
484
759
  ```bash
485
- monora standards-check \
760
+ npx monora-ai standards-check \
486
761
  --input ./monora_events.jsonl \
487
762
  --report ./SOC2_Report.pdf \
488
763
  --claims ./claims.json \
@@ -493,37 +768,32 @@ monora standards-check \
493
768
  Generate a claims manifest interactively (with optional coverage preview):
494
769
 
495
770
  ```bash
496
- monora standards-wizard \
771
+ npx monora-ai standards-wizard \
497
772
  --standard SOC2 \
498
773
  --output ./claims.json \
499
774
  --input ./monora_events.jsonl \
500
775
  --config ./monora.yml
501
776
  ```
502
777
 
503
- Start with `templates/standards_claims_template.json` and customize the claims to
504
- match the sections you care about. Packaged standards templates are also available:
778
+ Start with `templates/standards_claims_template.json` and customize the claims. Packaged standards templates:
505
779
 
506
780
  - SOC 2: `templates/standards/soc2_claims.json`
507
781
  - GDPR: `templates/standards/gdpr_claims.json`
508
782
  - ISO 27001: `templates/standards/iso27001_claims.json`
509
783
 
510
- If your report is JSON and already contains a `claims` list, you can pass it via
511
- `--report` without `--claims`.
512
-
513
- Supported checks: `policy_violations_max`, `unknown_models_max`, `forbidden_models_max`,
514
- `hash_chain_status`, `signatures_status`, `sequence_gaps_max`, `errors_max`, `config_required`.
784
+ Supported checks: `policy_violations_max`, `unknown_models_max`, `forbidden_models_max`, `hash_chain_status`, `signatures_status`, `sequence_gaps_max`, `errors_max`, `config_required`.
515
785
 
516
786
  ### Report Ingestion + Excerpts (SOC 2 / GDPR / ISO)
517
787
 
518
788
  Ingest a report, extract text, and attach verified excerpts to your claims manifest:
519
789
 
520
790
  ```bash
521
- monora standards-ingest \
791
+ npx monora-ai standards-ingest \
522
792
  --report ./SOC2_Report.pdf \
523
793
  --output ./report_ingest.json \
524
794
  --text-out ./SOC2_Report.txt
525
795
 
526
- monora standards-excerpt \
796
+ npx monora-ai standards-excerpt \
527
797
  --ingest ./report_ingest.json \
528
798
  --claims ./claims.json \
529
799
  --excerpts ./excerpts.json \
@@ -534,7 +804,7 @@ monora standards-excerpt \
534
804
  Auto-suggest and approve excerpts interactively:
535
805
 
536
806
  ```bash
537
- monora standards-review \
807
+ npx monora-ai standards-review \
538
808
  --ingest ./report_ingest.json \
539
809
  --claims ./claims.json \
540
810
  --output ./claims_with_excerpts.json
@@ -543,7 +813,7 @@ monora standards-review \
543
813
  Or produce suggestions as JSON:
544
814
 
545
815
  ```bash
546
- monora standards-suggest \
816
+ npx monora-ai standards-suggest \
547
817
  --ingest ./report_ingest.json \
548
818
  --claims ./claims.json \
549
819
  --output ./suggestions.json \
@@ -654,6 +924,27 @@ export const createUser = withMonoraAction(
654
924
  );
655
925
  ```
656
926
 
927
+ ---
928
+
929
+ ## Troubleshooting
930
+
931
+ - Validation fails due to null values: run `npx monora-ai config fix --config monora.yml` or validate with `npx monora-ai validate --mode lenient`.
932
+ - Telemetry backend errors: set `telemetry.backend` to `minimal`, `memory`, `prometheus`, `statsd`, or `none`.
933
+ - Daily rotation changed filenames: use `./monora_events.latest.jsonl` or set `rotation: none`.
934
+ - CLI command not found: use `npx monora-ai <command>` (or `npm exec -- monora <command>`).
935
+ - Console flooded with JSON: remove the stdout sink, set `format: pretty`, or export `MONORA_QUIET=1`.
936
+ - HTTPS sink errors: only enable HTTPS sinks when you have a real endpoint; the wizard leaves them off by default.
937
+
938
+ ---
939
+
940
+ ## Migration Guide (Verbose/Null-Heavy Configs)
941
+
942
+ 1. Run `npx monora-ai config fix --config monora.yml` (creates a `.bak` backup).
943
+ 2. Optionally regenerate a minimal baseline with `npx monora-ai init --preset minimal` and copy over only the sections you use.
944
+ 3. Validate with `npx monora-ai validate --mode lenient`, then switch to `--mode strict` for production.
945
+
946
+ ---
947
+
657
948
  ## License
658
949
 
659
950
  MIT