@neuroverseos/nv-sim 0.1.2 → 0.1.4

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.
package/README.md CHANGED
@@ -1,130 +1,346 @@
1
- # NV-SIM — Governed Agent Simulation
1
+ # NV-SIM
2
2
 
3
- What happens when you run the **same simulation twice**, but change the **rules of the world**?
3
+ **Change the rules. See why the system changed.**
4
4
 
5
- NV-SIM is a lightweight simulation tool that lets developers compare emergent outcomes **with and without governance constraints**.
5
+ NV-SIM doesn't predict outcomes it shows how they change when you change the rules.
6
6
 
7
- Instead of prompting AI systems to behave, NV-SIM applies **explicit world rules** that shape how agents interact and evolve over time.
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
 
9
- Run a governed vs baseline simulation in one command:
9
+ It feels a lot like a Prime Radiant except instead of psychohistory, you're running controlled behavioral experiments on complex systems.
10
10
 
11
11
  ```bash
12
- npx @neuroverseos/nv-sim compare
12
+ npx @neuroverseos/nv-sim visualize
13
13
  ```
14
14
 
15
- You'll see how structural constraints — liquidity floors, leverage limits, circuit breakers, coalition balancing — change the behavior of the entire system.
15
+ ## What This Actually Is
16
16
 
17
- Because governance doesn't just block bad actions.
18
- It changes the structure of the system itself.
17
+ Most simulation tools answer: *"What will happen?"*
19
18
 
20
- ## Quick Start
19
+ NV-SIM answers: *"What changes when I change the rules?"*
20
+
21
+ You're not forecasting. You're experimenting. You change a constraint — no panic selling, cap leverage at 3x, close a shipping lane — and the system shows you:
22
+
23
+ - **How agents reorganize** (80% shifted from panic selling to coordinated holding)
24
+ - **What patterns emerge** (panic suppression, stability shift)
25
+ - **What the system became** (volatility dropped 21%, cascade avoided)
26
+
27
+ ```
28
+ Rule changed
29
+ → Behavior shifted
30
+ → Pattern emerged
31
+ → System outcome changed
32
+ ```
33
+
34
+ That's the loop. Every time.
35
+
36
+ ## The Demo Moment
37
+
38
+ **Before:**
39
+ ```
40
+ panic_sell → panic_sell → panic_sell
41
+ pressure: 0.94
42
+ system: unstable
43
+ ```
44
+
45
+ **Rule added:** no panic selling
46
+
47
+ **After:**
48
+ ```
49
+ 80% of agents adapted
50
+
51
+ panic_sell → hold
52
+ panic_sell → hold
53
+ panic_sell → hold
54
+
55
+ Pattern: coordinated_holding
56
+ Pattern: panic_suppression
57
+
58
+ pressure: 0.54
59
+ cascade: avoided
60
+ ```
61
+
62
+ You didn't predict this. You caused it — by changing one rule — and watched the system tell you why.
63
+
64
+ ## Worlds — Where the Power Lives
21
65
 
22
- Run a comparison simulation:
66
+ Integration is one line. Worlds are where you define what your system allows.
67
+
68
+ The `world` you pass to `/api/evaluate` determines how actions are judged. Change the world, change the outcome.
69
+
70
+ ```
71
+ verdict = evaluate(actor="agent_1", action="panic_sell", world="trading")
72
+ ^^^^^^^^
73
+ this controls everything
74
+ ```
75
+
76
+ ### Built-in Worlds
77
+
78
+ | World | Domain | What You Can Change |
79
+ |-------|--------|---------------------|
80
+ | `trading` | Financial markets | Leverage ratio, liquidity index, volatility, circuit breakers |
81
+ | `strait_of_hormuz` | Geopolitical energy | Oil supply disruption, military escalation, diplomatic channels |
82
+ | `gas_price_spike` | Economic energy | Gas price, consumer sentiment, EV demand, grid capacity |
83
+ | `ai_regulation_crisis` | Tech regulation | AI regulation impact on markets and sector alignment |
84
+
85
+ ### Same Agents, Different Rules
23
86
 
24
87
  ```bash
25
- npx @neuroverseos/nv-sim compare
88
+ npx @neuroverseos/nv-sim worlds trading strait_of_hormuz
89
+ ```
90
+
91
+ Same agents. Different rules. Different outcomes. That's the experiment.
92
+
93
+ ## Narrative Shocks
94
+
95
+ Inject events into running simulations. Watch them propagate differently through different agents — a bank collapse hits retail investors and algorithmic traders in completely different ways.
96
+
97
+ ```bash
98
+ npx @neuroverseos/nv-sim compare --inject tanker_explosion@3,sanctions@5
26
99
  ```
27
100
 
28
- Stress-test a system:
101
+ The `@` syntax sets when the event hits. Events have severity, propagation speed, and directional impact.
102
+
103
+ ## Named Scenarios
104
+
105
+ Pre-built crisis sequences — a world + ordered narrative events:
29
106
 
30
107
  ```bash
31
- npx @neuroverseos/nv-sim chaos
108
+ npx @neuroverseos/nv-sim scenario taiwan_crisis
109
+ npx @neuroverseos/nv-sim scenario bank_run --compare
110
+ npx @neuroverseos/nv-sim scenarios # list all
32
111
  ```
33
112
 
34
- Launch the visual inspector:
113
+ | Scenario | Events | What It Tests |
114
+ |----------|--------|---------------|
115
+ | `taiwan_crisis` | 4 | Military escalation + sanctions + shipping disruption |
116
+ | `hormuz_blockade` | 3 | Tanker attack escalates to full shipping disruption |
117
+ | `bank_run` | 4 | Bank insolvency triggers contagion cascade |
118
+ | `flash_cascade` | 3 | Algorithmic failure chain reaction |
119
+ | `oil_shock` | 4 | Tanker attack + sanctions compound crisis |
120
+ | `energy_transition_shock` | 3 | Grid failure during rapid transition |
121
+ | `election_shock` | 4 | Political shock cascades into markets |
122
+ | `ai_crackdown` | 3 | Overnight AI regulation triggers panic |
123
+ | `perfect_storm` | 6 | Geopolitical + financial + energy convergence |
124
+ | `black_swan` | 5 | Extreme low-probability events in succession |
125
+
126
+ The `--compare` flag runs the same scenario across multiple worlds — which rule environment is more resilient?
127
+
128
+ ## Interactive Control Platform
35
129
 
36
130
  ```bash
37
131
  npx @neuroverseos/nv-sim visualize
38
132
  ```
39
133
 
40
- ## Why This Exists
134
+ This opens a control surface where you can:
41
135
 
42
- AI agents are starting to act inside real systems.
136
+ - Switch between rule environments
137
+ - Adjust state variables with auto-generated controls
138
+ - Inject narrative events at specific rounds
139
+ - Load crisis scenarios with one click
140
+ - Watch the **System Shift card** — not a log of what happened, but a story of what the system became
141
+ - Save any experiment as a reusable variant
43
142
 
44
- Most AI control today happens through prompts.
143
+ ### The System Shift Card
45
144
 
46
- Prompts can suggest behavior.
47
- But they cannot enforce rules.
145
+ When rules reshape behavior, you don't get a log. You get this:
48
146
 
49
- NV-SIM explores a different idea:
147
+ ```
148
+ ◆ SYSTEM SHIFT
149
+
150
+ No panic selling allowed
151
+ 437 actions reshaped out of 1,247 total
152
+
153
+ Rule → Behavioral Shift → What Emerged → System Outcome
154
+
155
+ ┌─ Behavioral Shift ─────────────────┐
156
+ │ 80% │
157
+ │ adaptation across 1,247 agents │
158
+ │ → BLOCK: hold (312 agents) │
159
+ │ → MODIFY: sell_slowly (87 agents) │
160
+ └────────────────────────────────────┘
161
+
162
+ ┌─ What Emerged ─────────────────────┐
163
+ │ Coordinated Holding │
164
+ │ Panic Suppression │
165
+ └────────────────────────────────────┘
166
+
167
+ ┌─ System Outcome ───────────────────┐
168
+ │ Volatility 47% → 26% │
169
+ │ Stability 58% → 79% │
170
+ │ Cascade Avoided │
171
+ └────────────────────────────────────┘
172
+
173
+ ┌─ What Actually Happened ───────────┐
174
+ │ No panic selling allowed. 437 of │
175
+ │ 1,247 agents reorganized — most │
176
+ │ shifted to hold. Volatility │
177
+ │ dropped 21%. │
178
+ └────────────────────────────────────┘
179
+
180
+ ▶ View raw detail
181
+ ```
50
182
 
51
- **What if we define the world an AI operates inside?**
52
- **And let governance shape the outcomes.**
183
+ We don't show you what every agent did. We show you what the system became.
53
184
 
54
- ## Commands
185
+ ### World Variants
55
186
 
56
- | Command | Description |
57
- |---------|-------------|
58
- | `nv-sim compare [preset]` | Run baseline vs governed simulation |
59
- | `nv-sim chaos [preset]` | Stress test across hundreds of randomized scenarios |
60
- | `nv-sim visualize [preset]` | Launch local simulation inspector in browser |
61
- | `nv-sim analyze <file>` | Analyze a simulation from file or stdin |
62
- | `nv-sim presets` | List available scenario presets |
187
+ Save any experiment as a named variant:
63
188
 
64
- ## Presets
189
+ ```
190
+ Adjust rules → Inject events → Run → See the shift → Save as variant
191
+ ```
192
+
193
+ 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
+
195
+ ## Works With Anything
196
+
197
+ If your system has actions, you can govern it. One API call.
198
+
199
+ ```
200
+ Agent decides → POST /api/evaluate → verdict → agent adapts
201
+ ```
202
+
203
+ The entire integration:
204
+
205
+ ```
206
+ Before: action = agent.decide()
207
+ After: action = govern(agent.decide())
208
+ ```
209
+
210
+ No SDK required. No framework required. Just an HTTP call.
211
+
212
+ **curl** (zero dependencies):
213
+
214
+ ```bash
215
+ curl -X POST http://localhost:3456/api/evaluate \
216
+ -H "Content-Type: application/json" \
217
+ -d '{"actor":"agent_1","action":"panic_sell","world":"trading"}'
218
+ ```
219
+
220
+ **Python:**
221
+
222
+ ```python
223
+ import requests
224
+
225
+ verdict = requests.post("http://localhost:3456/api/evaluate", json={
226
+ "actor": "agent_1",
227
+ "action": "panic_sell",
228
+ "world": "trading"
229
+ }).json()
230
+
231
+ if verdict["decision"] == "BLOCK":
232
+ action = "hold"
233
+ ```
65
234
 
66
- | Preset | Scenario |
67
- |--------|----------|
68
- | `trading` | Flash crash — algorithmic cascade (default) |
69
- | `strait_of_hormuz` | Geopolitical energy crisis |
70
- | `gas_price_spike` | Economic energy shock |
71
- | `ai_regulation_crisis` | AI regulation impact |
235
+ **JavaScript:**
72
236
 
73
- ## Example Output
237
+ ```js
238
+ const verdict = await fetch("http://localhost:3456/api/evaluate", {
239
+ method: "POST",
240
+ headers: { "Content-Type": "application/json" },
241
+ body: JSON.stringify({ actor: "agent_1", action: "panic_sell", world: "trading" })
242
+ }).then(r => r.json());
74
243
 
244
+ if (verdict.decision === "BLOCK") action = "hold";
75
245
  ```
76
- NV-SIM — Governed Simulation Comparison
77
246
 
78
- SIMULATION A — No Governance (Baseline)
79
- Stability: 80%
80
- Volatility: 56%
81
- Coalition risks: 2
247
+ **Any agent loop:**
82
248
 
83
- SIMULATION B — With World Rules (Governed)
84
- Stability: 91%
85
- Volatility: 42%
86
- Coalition risks: 0
249
+ ```python
250
+ for agent in agents:
251
+ action = agent.decide()
87
252
 
88
- GOVERNANCE IMPACT
89
- Stability: +9 percentage points
90
- Volatility: -25%
91
- Coalition risks: 2 eliminated
253
+ verdict = evaluate(actor=agent.id, action=action, world="trading")
254
+
255
+ if verdict["decision"] == "BLOCK":
256
+ action = "hold"
257
+ elif verdict["decision"] == "MODIFY":
258
+ action = verdict["modified_action"]
259
+
260
+ environment.apply(agent, action)
92
261
  ```
93
262
 
94
- ## Chaos Testing
263
+ If your system can make an HTTP request, it can be governed.
264
+
265
+ Most systems generate behavior. This one shapes it.
95
266
 
96
- Find the breaking point:
267
+ See [INTEGRATION.md](./INTEGRATION.md) for the full API contract and decision types.
268
+
269
+ ## Quick Start
97
270
 
98
271
  ```bash
272
+ # See it
273
+ npx @neuroverseos/nv-sim visualize
274
+
275
+ # Compare governed vs ungoverned
276
+ npx @neuroverseos/nv-sim compare
277
+
278
+ # Run a crisis
279
+ npx @neuroverseos/nv-sim scenario taiwan_crisis
280
+
281
+ # Same crisis, different worlds — which rules hold?
282
+ npx @neuroverseos/nv-sim scenario bank_run --compare
283
+
284
+ # Inject shocks
285
+ npx @neuroverseos/nv-sim compare --inject tanker_explosion@3,sanctions@5
286
+
287
+ # Stress test (500 randomized runs)
99
288
  npx @neuroverseos/nv-sim chaos --runs 500
289
+
290
+ # Run local governance runtime for your own simulator
291
+ npx @neuroverseos/nv-sim serve
100
292
  ```
101
293
 
102
- Runs hundreds of randomized simulations with perturbed agent behavior, market shocks, and coalition dynamics. Outputs aggregate collapse probability, worst-case scenarios, and most triggered governance rules.
294
+ ## Commands
295
+
296
+ | Command | What It Does |
297
+ |---------|-------------|
298
+ | `nv-sim visualize` | Interactive control platform |
299
+ | `nv-sim compare [preset]` | Baseline vs governed simulation |
300
+ | `nv-sim compare --inject event@round,...` | With narrative shocks |
301
+ | `nv-sim scenario <id>` | Run a named stress scenario |
302
+ | `nv-sim scenario <id> --compare` | Cross-world scenario comparison |
303
+ | `nv-sim scenarios` | List all available scenarios |
304
+ | `nv-sim worlds <a> <b>` | Compare two rule environments |
305
+ | `nv-sim chaos [preset] --runs N` | Stress test across randomized scenarios |
306
+ | `nv-sim serve --port N` | Local governance runtime for any simulator |
307
+ | `nv-sim analyze <file>` | Analyze simulation from file or stdin |
308
+ | `nv-sim presets` | List available world presets |
309
+
310
+ ## How It Works
103
311
 
104
312
  ```
105
- NV-SIM CHAOS TEST
106
- Scenarios tested: 500
313
+ event narrative propagation → belief shift → agent action → governance → outcome
314
+ ```
107
315
 
108
- Baseline collapse probability: 34%
109
- Governed collapse probability: 8%
316
+ Four forces shape every simulation:
110
317
 
111
- Most triggered rule:
112
- Market Panic Circuit Breaker (247 times)
318
+ 1. **Agent behavior** — traders, voters, regulators, media
319
+ 2. **World rules** leverage caps, circuit breakers, chokepoints
320
+ 3. **Narrative events** — information shocks that propagate through the system
321
+ 4. **Perception propagation** — different agents react differently to the same event
113
322
 
114
- Governance reduced catastrophic failure risk by 76%.
115
- ```
323
+ This lets you ask compound questions:
324
+
325
+ > What happens if a tanker explodes while Hormuz is closed and leverage is capped at 3x?
326
+
327
+ That combination produces very different outcomes than any single factor alone. And when you change one rule — uncap leverage, open a diplomatic channel, add a circuit breaker — you see exactly why the outcome changed.
116
328
 
117
329
  ## Architecture
118
330
 
119
331
  ```
120
332
  @neuroverseos/governance ← deterministic rule engine
121
333
 
122
- nv-sim CLI simulation runner + comparison
334
+ nv-sim engine world rules + narrative injection + swarm simulation
335
+
336
+ nv-sim CLI ← scenarios, comparison, chaos testing
337
+
338
+ control platform ← interactive browser UI + System Shift card
123
339
 
124
- developer simulators MiroFish, Mesa, NetLogo, custom
340
+ world variants saved experiments as shareable assets
125
341
  ```
126
342
 
127
- NV-SIM uses [`@neuroverseos/governance`](https://www.npmjs.com/package/@neuroverseos/governance) for deterministic guard evaluation. Every agent action is evaluated against world rules no LLM in the loop.
343
+ 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.
128
344
 
129
345
  ## License
130
346
 
@@ -132,6 +348,6 @@ Apache 2.0
132
348
 
133
349
  ---
134
350
 
135
- Simulate the future. Govern the outcomes.
351
+ Change the rules. See why the system changed.
136
352
 
137
353
  [@neuroverseos](https://github.com/NeuroverseOS)