@neuroverseos/nv-sim 0.1.4 → 0.1.7

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 (44) hide show
  1. package/README.md +260 -6
  2. package/dist/adapters/mirofish.js +461 -0
  3. package/dist/adapters/scienceclaw.js +750 -0
  4. package/dist/assets/index-CHmUN8s0.js +532 -0
  5. package/dist/assets/index-DWgMnB7I.css +1 -0
  6. package/dist/assets/{reportEngine-BfteK4MN.js → reportEngine-BVdQ2_nW.js} +1 -1
  7. package/dist/components/ConstraintsPanel.js +11 -0
  8. package/dist/components/StakeholderBuilder.js +32 -0
  9. package/dist/components/ui/badge.js +24 -0
  10. package/dist/components/ui/button.js +70 -0
  11. package/dist/components/ui/card.js +57 -0
  12. package/dist/components/ui/input.js +44 -0
  13. package/dist/components/ui/label.js +45 -0
  14. package/dist/components/ui/select.js +70 -0
  15. package/dist/engine/aiProvider.js +427 -2
  16. package/dist/engine/auditTrace.js +352 -0
  17. package/dist/engine/behavioralAnalysis.js +605 -0
  18. package/dist/engine/cli.js +1087 -13
  19. package/dist/engine/dynamicsGovernance.js +588 -0
  20. package/dist/engine/fullGovernedLoop.js +367 -0
  21. package/dist/engine/governedSimulation.js +77 -6
  22. package/dist/engine/index.js +41 -1
  23. package/dist/engine/liveVisualizer.js +1961 -197
  24. package/dist/engine/metrics/science.metrics.js +335 -0
  25. package/dist/engine/policyEnforcement.js +1611 -0
  26. package/dist/engine/policyEngine.js +799 -0
  27. package/dist/engine/primeRadiant.js +540 -0
  28. package/dist/engine/scenarioComparison.js +463 -0
  29. package/dist/engine/swarmSimulation.js +54 -1
  30. package/dist/engine/worldComparison.js +164 -0
  31. package/dist/engine/worldStorage.js +232 -0
  32. package/dist/index.html +2 -2
  33. package/dist/lib/reasoningEngine.js +290 -0
  34. package/dist/lib/simulationAdapter.js +686 -0
  35. package/dist/lib/swarmParser.js +291 -0
  36. package/dist/lib/types.js +2 -0
  37. package/dist/lib/utils.js +8 -0
  38. package/dist/runtime/govern.js +473 -0
  39. package/dist/runtime/index.js +75 -0
  40. package/dist/runtime/types.js +11 -0
  41. package/package.json +5 -2
  42. package/dist/assets/index-DHKd4rcV.js +0 -338
  43. package/dist/assets/index-SyyA3z3U.css +0 -1
  44. package/dist/assets/swarmSimulation-DHDqjfMa.js +0 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  **Change the rules. See why the system changed.**
4
4
 
5
- NV-SIM doesn't predict outcomes — it shows how they change when you change the rules.
5
+ NV-SIM doesn't predict outcomes — it shows how systems change when you change the rules.
6
6
 
7
7
  Define a world. Set the constraints. Run the agents. Then change one rule and watch the entire system reorganize. Not in theory. You see exactly which agents shifted, what patterns emerged, and why the outcome changed.
8
8
 
@@ -33,6 +33,38 @@ Rule changed
33
33
 
34
34
  That's the loop. Every time.
35
35
 
36
+ ## This Is a Runtime, Not Just a Simulator
37
+
38
+ NV-SIM runs in two modes:
39
+
40
+ - **Simulate** — explore how systems behave under different rules
41
+ - **Act** — govern real agents, real workflows, and real decisions
42
+
43
+ The interface is the same. The difference is where the behavior comes from.
44
+
45
+ ```
46
+ Simulate → internal swarm engine
47
+ Act → external systems (agents, APIs, frameworks like OpenClaw)
48
+ ```
49
+
50
+ In both cases:
51
+
52
+ ```
53
+ Action → Governance → Decision → Behavioral Shift → System Outcome
54
+ ```
55
+
56
+ You're not switching tools. You're switching the source of reality.
57
+
58
+ That's what makes this a runtime.
59
+
60
+ The same world file can:
61
+
62
+ - simulate a crisis
63
+ - govern a live system
64
+ - produce comparable outcomes across both
65
+
66
+ Design the rules once. Run them anywhere.
67
+
36
68
  ## The Demo Moment
37
69
 
38
70
  **Before:**
@@ -61,9 +93,61 @@ system: unstable
61
93
 
62
94
  You didn't predict this. You caused it — by changing one rule — and watched the system tell you why.
63
95
 
96
+ ## Behavioral Analysis — The Proof Layer
97
+
98
+ Blocking actions is easy. The hard part is proving what changed and why. NV-SIM doesn't just count blocked actions — it tracks how agents actually reorganized.
99
+
100
+ Every simulation produces behavioral evidence:
101
+
102
+ - **Action classification** — each agent action is categorized as aggressive, defensive, cautious, cooperative, opportunistic, or neutral
103
+ - **Agent trajectories** — traces each agent's behavior across rounds, showing when and how they shifted
104
+ - **Behavioral shifts** — detects the moment agents change strategy in response to governance
105
+ - **Cross-run comparison** — same agents under different rules, measured side by side
106
+
107
+ ```
108
+ BEHAVIORAL ANALYSIS
109
+
110
+ Action Distribution (governed):
111
+ aggressive: 12% (was 67%)
112
+ cooperative: 41% (was 8%)
113
+ cautious: 31% (was 11%)
114
+ defensive: 16% (was 14%)
115
+
116
+ Shifts Detected:
117
+ → 80% of aggressive agents shifted to cooperative after round 3
118
+ → Panic selling replaced by coordinated holding
119
+ → New pattern: quality_competition (not present in baseline)
120
+
121
+ Trajectory: agent_hedge_fund_1
122
+ Round 1: aggressive → Round 2: aggressive → Round 3: [BLOCK] → Round 4: cautious → Round 5: cooperative
123
+ ```
124
+
125
+ The governance isn't the insight. The behavioral shift is the insight. You changed a rule, and the system tells you exactly who changed, when they changed, and what they changed to.
126
+
127
+ ## Audit Trail — Full Evidence Chain
128
+
129
+ Every governance decision is recorded in an append-only audit log. Every rule firing, every agent action, every verdict — persistent and queryable.
130
+
131
+ ```
132
+ AUDIT TRAIL (session: 2026-03-18T14:22:00)
133
+
134
+ [GOVERNANCE] agent_hedge_fund_1 → panic_sell → BLOCK
135
+ rule: no_panic_selling (invariant)
136
+ evidence: action matches blocked pattern during high volatility
137
+
138
+ [AGENT] agent_hedge_fund_1 → hold
139
+ adapted: true (shifted from aggressive to defensive)
140
+
141
+ [BEHAVIORAL_SHIFT] agent_hedge_fund_1
142
+ before: aggressive | after: cautious
143
+ trigger: governance block at round 3
144
+ ```
145
+
146
+ Stored as JSONL — one JSON object per line, human-readable, pipeable through `jq`. No cloud, no deletion. Complete evidence for governance accountability.
147
+
64
148
  ## Worlds — Where the Power Lives
65
149
 
66
- Integration is one line. Worlds are where you define what your system allows.
150
+ Integration is one line. The world file controls everything.
67
151
 
68
152
  The `world` you pass to `/api/evaluate` determines how actions are judged. Change the world, change the outcome.
69
153
 
@@ -192,7 +276,35 @@ Adjust rules → Inject events → Run → See the shift → Save as variant
192
276
 
193
277
  Variants capture the base world, state overrides, narrative events, and results. Store them in git. Share them. Replay them. This turns experiments into assets.
194
278
 
195
- ## Works With Anything
279
+ ## Governance Runtime — Run It For Your Own System
280
+
281
+ ```bash
282
+ npx @neuroverseos/nv-sim serve
283
+ ```
284
+
285
+ This starts a local governance server. Any simulator, agent framework, or application can POST actions and get governance decisions back.
286
+
287
+ ```
288
+ Endpoint: http://localhost:3456/api/evaluate
289
+ Method: POST
290
+ Contract: { actor, action, payload?, state?, world? }
291
+ Response: { decision: ALLOW|BLOCK|MODIFY, reason, evidence }
292
+ ```
293
+
294
+ Your agents call localhost. The world file decides what's allowed. No cloud. No cost.
295
+
296
+ Additional endpoints:
297
+
298
+ | Endpoint | What It Does |
299
+ |----------|-------------|
300
+ | `POST /api/evaluate` | Submit an action for governance |
301
+ | `GET /api/session` | Current session stats |
302
+ | `GET /api/session/report` | Full governance report |
303
+ | `POST /api/session/reset` | Reset session state |
304
+ | `POST /api/session/save` | Save session as experiment |
305
+ | `GET /api/events` | SSE stream of governance events |
306
+
307
+ ### Works With Anything
196
308
 
197
309
  If your system has actions, you can govern it. One API call.
198
310
 
@@ -266,6 +378,44 @@ Most systems generate behavior. This one shapes it.
266
378
 
267
379
  See [INTEGRATION.md](./INTEGRATION.md) for the full API contract and decision types.
268
380
 
381
+ ## AI Providers — Bring Your Own Model
382
+
383
+ AI is optional. AI is governed. AI is pluggable.
384
+
385
+ NV-SIM works without any AI — the deterministic engine runs on math, not tokens. But when you bring your own model, AI becomes a governed actor inside the system — subject to the same rules as every other agent.
386
+
387
+ ### How AI fits in
388
+
389
+ AI plays two governed roles:
390
+
391
+ | Role | What It Does | Constraints |
392
+ |------|-------------|-------------|
393
+ | `ai_translator` | Converts unstructured input into normalized events | Must output valid schema, no invention of events, must include confidence |
394
+ | `ai_analyst` | Generates reports from simulation traces | Must reference trace data, must include blocked actions, no unverifiable claims |
395
+
396
+ Both roles go through `/api/evaluate` like any other actor. The AI doesn't control the system — the system controls the AI.
397
+
398
+ ### Supported providers
399
+
400
+ NV-SIM auto-detects the best available provider from your environment:
401
+
402
+ | Provider | Env Var | What It Connects To |
403
+ |----------|---------|---------------------|
404
+ | Anthropic (Claude) | `ANTHROPIC_API_KEY` | Claude Sonnet, Opus, Haiku |
405
+ | OpenAI | `OPENAI_API_KEY` | GPT-4, GPT-4o, o1 |
406
+ | Groq | `GROQ_API_KEY` | Llama 3 70B |
407
+ | Together | `TOGETHER_API_KEY` | Llama, Mixtral |
408
+ | Mistral | `MISTRAL_API_KEY` | Mistral Large |
409
+ | Deepseek | `DEEPSEEK_API_KEY` | Deepseek Chat |
410
+ | Fireworks | `FIREWORKS_API_KEY` | Llama, custom models |
411
+ | Ollama | `OLLAMA_BASE_URL` | Any local model |
412
+ | Local LLM | `LOCAL_LLM_URL` | LM Studio, vLLM, llama.cpp |
413
+ | (none) | — | Deterministic fallback (no AI, no cost) |
414
+
415
+ Set the env var and run. No configuration files. No provider lock-in.
416
+
417
+ Any endpoint that speaks the OpenAI chat completions format (`POST /v1/chat/completions`) works out of the box.
418
+
269
419
  ## Quick Start
270
420
 
271
421
  ```bash
@@ -291,10 +441,104 @@ npx @neuroverseos/nv-sim chaos --runs 500
291
441
  npx @neuroverseos/nv-sim serve
292
442
  ```
293
443
 
444
+ ## Policy Enforcement — The Product Loop
445
+
446
+ Write rules in plain English. Run the same scenario. See what changes. Adjust and repeat.
447
+
448
+ ### Step 1: See it work (zero config)
449
+
450
+ ```bash
451
+ npx nv-sim enforce
452
+ ```
453
+
454
+ Runs three iterations automatically: no rules → light rules → full rules. You see divergence immediately.
455
+
456
+ ### Step 2: Write your own rules
457
+
458
+ Create a text file. That's it.
459
+
460
+ ```
461
+ # my-rules.txt
462
+
463
+ Block panic selling during high volatility
464
+ Limit leverage to 5x
465
+ Maintain minimum liquidity floor
466
+ Slow down algorithmic trading when contagion spreads
467
+ ```
468
+
469
+ ### Step 3: Run it
470
+
471
+ ```bash
472
+ npx nv-sim enforce trading my-rules.txt
473
+ ```
474
+
475
+ The engine parses your plain English into governance rules, runs the scenario, and shows what changed.
476
+
477
+ ### Step 4: Change a rule. Run again.
478
+
479
+ Remove "Limit leverage to 5x". Run again. Did stability drop? That rule was load-bearing.
480
+
481
+ Add "Require transparency for all large trades". Run again. Did effectiveness improve?
482
+
483
+ The report tracks every change:
484
+
485
+ ```
486
+ RULE CHANGES
487
+ Run 2:
488
+ + Block panic selling during high volatility
489
+ + Slow down algorithmic trading when contagion spreads
490
+ - Limit leverage to 5x
491
+
492
+ DIVERGENCE ANALYSIS
493
+ Stability trend: 79% → 98%
494
+ Effectiveness trend: 11% → 32%
495
+
496
+ KEY INSIGHT
497
+ Enforcement gates are the key differentiator. Rules alone: 11%. Rules + gates: 32%.
498
+
499
+ TRY THIS EXPERIMENT
500
+ Remove this rule and see what happens:
501
+ Remove "Block panic selling during high volatility" from your rules file, then run again.
502
+ If stability drops, that rule was load-bearing. If nothing changes, it was noise.
503
+ ```
504
+
505
+ ### Step 5: Compare two rule sets side by side
506
+
507
+ ```bash
508
+ npx nv-sim enforce trading light-rules.txt strict-rules.txt
509
+ ```
510
+
511
+ ### Rule patterns
512
+
513
+ The engine understands these patterns in plain English:
514
+
515
+ | Pattern | What it does | Example |
516
+ |---------|-------------|---------|
517
+ | `Block X` | Hard suppression of matching actions | `Block panic selling` |
518
+ | `Limit X` / `Cap X` | Caps extreme positions | `Limit leverage to 5x` |
519
+ | `Slow X` / `Dampen X` | Reduces large movements | `Slow down algorithmic trading` |
520
+ | `Maintain X` / `Floor X` | Enforces minimum thresholds | `Maintain minimum liquidity` |
521
+ | `Rebalance X` | Pulls extremes toward equilibrium | `Rebalance correlated positions` |
522
+ | `Require X` | Enforceable structural constraint | `Require transparency for large trades` |
523
+ | `Monitor X` | Generates a circuit breaker gate | `Monitor contagion spread` |
524
+
525
+ ### Other scenarios
526
+
527
+ ```bash
528
+ npx nv-sim enforce strait_of_hormuz my-rules.txt # Same rules, different scenario
529
+ npx nv-sim enforce ai_regulation_crisis # Default progressive run
530
+ npx nv-sim enforce trading --output=report.json # Save as JSON
531
+ ```
532
+
533
+ ### Advanced: JSON world files
534
+
535
+ For full control over gates, state variables, and thesis, use JSON world files. See `examples/worlds/` for templates. Enforce accepts both `.txt` and `.json` — mix and match.
536
+
294
537
  ## Commands
295
538
 
296
539
  | Command | What It Does |
297
540
  |---------|-------------|
541
+ | `nv-sim enforce [preset]` | Policy enforcement lab — iterative rule testing |
298
542
  | `nv-sim visualize` | Interactive control platform |
299
543
  | `nv-sim compare [preset]` | Baseline vs governed simulation |
300
544
  | `nv-sim compare --inject event@round,...` | With narrative shocks |
@@ -304,21 +548,23 @@ npx @neuroverseos/nv-sim serve
304
548
  | `nv-sim worlds <a> <b>` | Compare two rule environments |
305
549
  | `nv-sim chaos [preset] --runs N` | Stress test across randomized scenarios |
306
550
  | `nv-sim serve --port N` | Local governance runtime for any simulator |
551
+ | `nv-sim run <simulator>` | Connect external simulator to governance |
307
552
  | `nv-sim analyze <file>` | Analyze simulation from file or stdin |
308
553
  | `nv-sim presets` | List available world presets |
309
554
 
310
555
  ## How It Works
311
556
 
312
557
  ```
313
- event → narrative propagation → belief shift → agent action → governance → outcome
558
+ event → narrative propagation → belief shift → agent action → governance → behavioral analysis → outcome
314
559
  ```
315
560
 
316
- Four forces shape every simulation:
561
+ Five forces shape every simulation:
317
562
 
318
563
  1. **Agent behavior** — traders, voters, regulators, media
319
564
  2. **World rules** — leverage caps, circuit breakers, chokepoints
320
565
  3. **Narrative events** — information shocks that propagate through the system
321
566
  4. **Perception propagation** — different agents react differently to the same event
567
+ 5. **Behavioral analysis** — tracks how agents reorganize under governance, producing the evidence that rules actually changed the system
322
568
 
323
569
  This lets you ask compound questions:
324
570
 
@@ -333,15 +579,23 @@ That combination produces very different outcomes than any single factor alone.
333
579
 
334
580
  nv-sim engine ← world rules + narrative injection + swarm simulation
335
581
 
336
- nv-sim CLI scenarios, comparison, chaos testing
582
+ behavioral analysis shift detection, trajectory tracking, cross-run comparison
583
+
584
+ audit trail ← append-only evidence chain (JSONL)
585
+
586
+ nv-sim CLI ← scenarios, comparison, chaos testing, governance runtime
337
587
 
338
588
  control platform ← interactive browser UI + System Shift card
339
589
 
590
+ AI providers (optional) ← BYOM: Anthropic, OpenAI, Groq, local LLMs, or none
591
+
340
592
  world variants ← saved experiments as shareable assets
341
593
  ```
342
594
 
343
595
  Everything runs locally. NV-SIM uses [`@neuroverseos/governance`](https://www.npmjs.com/package/@neuroverseos/governance) for deterministic guard evaluation — no LLM, no cloud, no cost. Your agents call `localhost`, and the world file decides what's allowed.
344
596
 
597
+ AI is optional. When present, it's governed — subject to the same rules as any other actor in the system.
598
+
345
599
  ## License
346
600
 
347
601
  Apache 2.0