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/README.md CHANGED
@@ -1,42 +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)
17
- - **Attribution + Usage Telemetry**: Optional project registration and anonymous usage stats (opt-in)
18
- - **Compliance Assessment Hooks**: Built-in checks and usage profiles for audits
9
+ ## Streamlined Setup (Recommended)
19
10
 
20
- ### New in v1.9.0
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
21
17
 
22
- - **🔄 Circuit Breaker**: Fault tolerance for HTTPS sinks with automatic recovery
23
- - **📊 Telemetry/Analytics**: Prometheus and StatsD metrics export for observability
24
- - **📄 PDF Reports**: Generate compliance and EU AI Act PDF reports
25
- - **🌐 Next.js Middleware**: W3C Trace Context propagation for Next.js applications
18
+ # 2. Initialize onboarding contract + model spec + enrichment bundles
19
+ npx monora-ai onboard init --config monora.yml
26
20
 
27
- ## Installation
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
26
+
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:
40
+
41
+ - `claims[].severity`
42
+ - `claims[].remediation`
43
+ - `findings_summary` (totals, status breakdown, remediation recommendations)
44
+
45
+ ---
46
+
47
+ ## CLI Reference
28
48
 
29
49
  ```bash
30
- 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
31
103
  ```
32
104
 
105
+ ---
106
+
33
107
  ## Quick Start
34
108
 
109
+ After setup, initialize Monora in your app:
110
+
35
111
  ```typescript
36
112
  import { init, llmCall, trace } from 'monora-ai';
37
113
 
38
- // Initialize SDK
39
- init({ configPath: './monora.yml' });
114
+ await init({ configPath: './monora.yml' });
40
115
 
41
116
  const ask = llmCall({ purpose: 'support' })(function ask(
42
117
  question: string,
@@ -52,6 +127,180 @@ trace('my-ai-task', (span) => {
52
127
  });
53
128
  ```
54
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
+
55
304
  ### Decorator Helpers (TypeScript)
56
305
 
57
306
  ```typescript
@@ -87,32 +336,32 @@ Enable decorators in your `tsconfig.json`:
87
336
  }
88
337
  ```
89
338
 
90
- ### Guided Setup (Wizard)
91
-
92
- ```bash
93
- npx monora-ai init
94
- # or
95
- ./node_modules/.bin/monora init
96
- ```
339
+ ### High-level Runtime Helpers
97
340
 
98
- 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';
99
343
 
100
- ### Reports & Security Review
344
+ init({ configPath: './monora.yml' });
101
345
 
102
- 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
+ });
103
349
 
104
- ```bash
105
- npx monora-ai report --input events.jsonl --output report.json
106
- 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
+ });
107
353
 
108
- npx monora-ai security-review --input events.jsonl --output security.json
109
- 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
+ );
110
357
 
111
- npx monora-ai trust-package --input events.jsonl --trace-id trc_123 --output trust.json --config monora.yml
112
- npx monora-ai verify --input events.jsonl --config monora.yml --pretty
113
- npx monora-ai retry-queue --config monora.yml
358
+ logEvent('custom', { message: 'hello' }, { purpose: 'manual' });
114
359
  ```
115
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
+
116
365
  ```typescript
117
366
  import { exportTrustPackage } from 'monora-ai';
118
367
 
@@ -125,7 +374,7 @@ const trustPackage = exportTrustPackage('trc_123', {
125
374
  ### Data Handling + Alerts
126
375
 
127
376
  ```typescript
128
- import { DataHandlingEngine, buildDataViolation, ViolationWebhookDispatcher } from 'monora-ai';
377
+ import { DataHandlingEngine, ViolationWebhookDispatcher } from 'monora-ai';
129
378
 
130
379
  const dataHandling = new DataHandlingEngine({
131
380
  enabled: true,
@@ -146,77 +395,7 @@ dispatcher.start();
146
395
  dispatcher.send({ event_type: 'policy_violation', message: 'Example violation' });
147
396
  ```
148
397
 
149
- ### High-level Runtime Helpers
150
-
151
- ```typescript
152
- import { init, logEvent, toolCall, agentStep, setViolationHandler } from 'monora-ai';
153
-
154
- init({ configPath: './monora.yml' });
155
-
156
- setViolationHandler((violation) => {
157
- console.error('Violation:', violation.message);
158
- });
159
-
160
- const fetchTool = toolCall({ toolName: 'fetch', purpose: 'integration' })(async (url: string) => {
161
- return { ok: true, url };
162
- });
163
-
164
- const plan = agentStep({ agentName: 'planner', stepType: 'planning', purpose: 'analysis' })(
165
- (goal: string) => [`step for ${goal}`]
166
- );
167
-
168
- logEvent('custom', { message: 'hello' }, { purpose: 'manual' });
169
- ```
170
-
171
- ## Configuration
172
-
173
- Create a `monora.json` or `monora.yaml` file:
174
-
175
- ```json
176
- {
177
- "defaults": {
178
- "data_classification": "internal",
179
- "environment": "production"
180
- },
181
- "policies": {
182
- "model_allowlist": ["gpt-4*", "claude-3-*"],
183
- "model_denylist": ["deepseek:*"],
184
- "enforce": true
185
- },
186
- "immutability": {
187
- "enabled": true,
188
- "scope": "per_trace",
189
- "hash_algorithm": "sha256"
190
- }
191
- }
192
- ```
193
-
194
- ### HTTP Retry Queue + Idempotency
195
-
196
- ```yaml
197
- sinks:
198
- - type: https
199
- endpoint: https://api.example.com/events
200
- retry_queue:
201
- enabled: true
202
- path: ./monora_http_queue
203
- max_items: 10000
204
- flush_interval_sec: 5.0
205
- idempotency:
206
- enabled: true
207
- header_name: Idempotency-Key
208
- ```
209
-
210
- Idempotency keys are computed per batch as a SHA-256 digest of the canonical
211
- event JSON in order. Reordering events or changing batch boundaries changes the
212
- idempotency key.
213
-
214
- Inspect or clear the local retry queue:
215
-
216
- ```bash
217
- npx monora-ai retry-queue --config monora.yml
218
- npx monora-ai retry-queue --path ./monora_http_queue --clear
219
- ```
398
+ ---
220
399
 
221
400
  ## API Documentation
222
401
 
@@ -226,7 +405,7 @@ npx monora-ai retry-queue --path ./monora_http_queue --clear
226
405
  import { PolicyEngine } from 'monora-ai';
227
406
 
228
407
  const engine = new PolicyEngine({
229
- model_allowlist: ['gpt-4*'],
408
+ model_allowlist: ['gpt-*', 'claude-*', 'o1-*', 'gemini-*'],
230
409
  model_denylist: ['deepseek:*'],
231
410
  enforce: true
232
411
  });
@@ -295,23 +474,10 @@ const gaps = detectSequenceGaps(events);
295
474
  console.log('Sequence gaps:', gaps);
296
475
  ```
297
476
 
298
- ### Security Reports
299
-
300
- Generate JSON security review reports locally with CLI:
301
-
302
- Auth: none (local CLI). Errors: invalid JSONL/config or GPG signing failures.
303
-
304
- ```bash
305
- npx monora-ai security-review --input events.jsonl --output security.json
306
- npx monora-ai security-review --input events.jsonl --output security.json --config monora.yml
307
- ```
308
-
309
477
  ### Data Handling
310
478
 
311
479
  Use the data handling engine for redaction or blocking decisions (modes: `redact`, `block`, `allow`):
312
480
 
313
- Auth: none. Errors: `DataHandlingViolation` in block mode or invalid regex patterns.
314
-
315
481
  ```typescript
316
482
  import { DataHandlingEngine } from 'monora-ai';
317
483
 
@@ -327,8 +493,6 @@ const { value, applied } = engine.sanitizePayload('request', payload, 'confident
327
493
 
328
494
  Send policy violation payloads to a webhook:
329
495
 
330
- Auth: set headers such as `Authorization`. Errors: network failures, non-2xx responses, or queue overflow.
331
-
332
496
  ```typescript
333
497
  import { ViolationWebhookDispatcher } from 'monora-ai';
334
498
 
@@ -351,8 +515,6 @@ dispatcher.send({ event_type: 'policy_violation', message: 'Blocked model' });
351
515
 
352
516
  ### Event Building and Dispatching
353
517
 
354
- Event builder and dispatcher classes are available in the current Node SDK.
355
-
356
518
  ```typescript
357
519
  import { EventBuilder, EventDispatcher, StdoutSink, FileSink } from 'monora-ai';
358
520
 
@@ -374,7 +536,7 @@ const event = builder.build('llm_call', {
374
536
 
375
537
  // Setup event dispatcher with sinks
376
538
  const sinks = [
377
- new StdoutSink('json'),
539
+ new StdoutSink('pretty'),
378
540
  new FileSink('./events.jsonl', { batchSize: 100 }),
379
541
  ];
380
542
 
@@ -390,8 +552,6 @@ dispatcher.close();
390
552
 
391
553
  ### Sink Options
392
554
 
393
- These sink implementations are exported and ready for use.
394
-
395
555
  ```typescript
396
556
  // Stdout Sink
397
557
  const stdoutSink = new StdoutSink('pretty'); // or 'json'
@@ -404,7 +564,8 @@ const fileSink = new FileSink('./logs/events.jsonl', {
404
564
  maxSizeMb: 100,
405
565
  });
406
566
 
407
- // 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)
408
569
  const httpsSink = new HttpSink(
409
570
  'https://api.example.com/events',
410
571
  { 'Authorization': 'Bearer token' },
@@ -417,7 +578,9 @@ const httpsSink = new HttpSink(
417
578
  );
418
579
  ```
419
580
 
420
- ## v1.9.0 Features
581
+ ---
582
+
583
+ ## Advanced Features
421
584
 
422
585
  ### Circuit Breaker
423
586
 
@@ -442,21 +605,19 @@ const httpsSink = new HttpSink(
442
605
 
443
606
  ### Telemetry/Analytics
444
607
 
445
- Telemetry is enabled by default with a minimal in-memory backend (queue depth,
446
- 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`).
447
609
 
448
610
  Export metrics to Prometheus or StatsD:
449
611
 
450
612
  ```typescript
451
- import { init, initMetrics, recordEvent, recordViolation } from 'monora-ai';
613
+ import { init } from 'monora-ai';
452
614
 
453
- // Configure telemetry
454
615
  init({
455
616
  configPath: './monora.yml',
456
617
  config: {
457
618
  telemetry: {
458
619
  enabled: true,
459
- backend: 'prometheus', // or 'statsd'
620
+ backend: 'prometheus', // or 'statsd' | 'memory' | 'minimal' | 'none'
460
621
  prometheus: {
461
622
  port: 9090,
462
623
  start_server: true,
@@ -474,8 +635,7 @@ init({
474
635
 
475
636
  ### Attribution & Usage Telemetry (Opt-In)
476
637
 
477
- Collect optional attribution details and anonymous usage stats with explicit opt-in.
478
- No data leaves your environment unless `send_data` is enabled.
638
+ Collect optional attribution details and anonymous usage stats with explicit opt-in. No data leaves your environment unless `send_data` is enabled.
479
639
 
480
640
  ```typescript
481
641
  import { init } from 'monora-ai';
@@ -498,7 +658,7 @@ init({
498
658
  telemetry: {
499
659
  enabled: true,
500
660
  send_data: true,
501
- data_residency: 'eu'
661
+ data_residency: 'us'
502
662
  }
503
663
  }
504
664
  }
@@ -524,8 +684,7 @@ Additional presets: `default_secure`, `experimental`, `audit_first`, `low_latenc
524
684
 
525
685
  ### Migration Guidance (POC -> Production)
526
686
 
527
- When you promote a POC to production, Monora will warn if you use a POC/dev preset
528
- in a production environment. You can also run the readiness checks directly:
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:
529
688
 
530
689
  ```typescript
531
690
  import {
@@ -591,15 +750,14 @@ const result = await runComplianceCheck({
591
750
  const profile = reportUsageProfile();
592
751
  ```
593
752
 
594
- Compliance scores are weighted by framework and control category (integrity,
595
- auditability, privacy, and governance) instead of a flat pass rate.
753
+ Compliance scores are weighted by framework and control category (integrity, auditability, privacy, and governance) instead of a flat pass rate.
596
754
 
597
755
  ### Standards Mapping (SOC 2 / GDPR / ISO)
598
756
 
599
757
  Evaluate external claims against Monora evidence (event IDs, causal paths, guardrails):
600
758
 
601
759
  ```bash
602
- monora standards-check \
760
+ npx monora-ai standards-check \
603
761
  --input ./monora_events.jsonl \
604
762
  --report ./SOC2_Report.pdf \
605
763
  --claims ./claims.json \
@@ -610,37 +768,32 @@ monora standards-check \
610
768
  Generate a claims manifest interactively (with optional coverage preview):
611
769
 
612
770
  ```bash
613
- monora standards-wizard \
771
+ npx monora-ai standards-wizard \
614
772
  --standard SOC2 \
615
773
  --output ./claims.json \
616
774
  --input ./monora_events.jsonl \
617
775
  --config ./monora.yml
618
776
  ```
619
777
 
620
- Start with `templates/standards_claims_template.json` and customize the claims to
621
- 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:
622
779
 
623
780
  - SOC 2: `templates/standards/soc2_claims.json`
624
781
  - GDPR: `templates/standards/gdpr_claims.json`
625
782
  - ISO 27001: `templates/standards/iso27001_claims.json`
626
783
 
627
- If your report is JSON and already contains a `claims` list, you can pass it via
628
- `--report` without `--claims`.
629
-
630
- Supported checks: `policy_violations_max`, `unknown_models_max`, `forbidden_models_max`,
631
- `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`.
632
785
 
633
786
  ### Report Ingestion + Excerpts (SOC 2 / GDPR / ISO)
634
787
 
635
788
  Ingest a report, extract text, and attach verified excerpts to your claims manifest:
636
789
 
637
790
  ```bash
638
- monora standards-ingest \
791
+ npx monora-ai standards-ingest \
639
792
  --report ./SOC2_Report.pdf \
640
793
  --output ./report_ingest.json \
641
794
  --text-out ./SOC2_Report.txt
642
795
 
643
- monora standards-excerpt \
796
+ npx monora-ai standards-excerpt \
644
797
  --ingest ./report_ingest.json \
645
798
  --claims ./claims.json \
646
799
  --excerpts ./excerpts.json \
@@ -651,7 +804,7 @@ monora standards-excerpt \
651
804
  Auto-suggest and approve excerpts interactively:
652
805
 
653
806
  ```bash
654
- monora standards-review \
807
+ npx monora-ai standards-review \
655
808
  --ingest ./report_ingest.json \
656
809
  --claims ./claims.json \
657
810
  --output ./claims_with_excerpts.json
@@ -660,7 +813,7 @@ monora standards-review \
660
813
  Or produce suggestions as JSON:
661
814
 
662
815
  ```bash
663
- monora standards-suggest \
816
+ npx monora-ai standards-suggest \
664
817
  --ingest ./report_ingest.json \
665
818
  --claims ./claims.json \
666
819
  --output ./suggestions.json \
@@ -771,6 +924,27 @@ export const createUser = withMonoraAction(
771
924
  );
772
925
  ```
773
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
+
774
948
  ## License
775
949
 
776
950
  MIT