@neuroverseos/governance 0.1.0 → 0.1.2
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/LICENSE.md +190 -0
- package/README.md +472 -115
- package/dist/adapters/express.cjs +874 -0
- package/dist/adapters/express.d.cts +66 -0
- package/dist/adapters/express.d.ts +66 -0
- package/dist/adapters/express.js +10 -0
- package/dist/adapters/index.cjs +1166 -0
- package/dist/adapters/index.d.cts +5 -0
- package/dist/adapters/index.d.ts +5 -0
- package/dist/adapters/index.js +40 -0
- package/dist/adapters/langchain.cjs +861 -0
- package/dist/adapters/langchain.d.cts +82 -0
- package/dist/adapters/langchain.d.ts +82 -0
- package/dist/adapters/langchain.js +14 -0
- package/dist/adapters/openai.cjs +891 -0
- package/dist/adapters/openai.d.cts +92 -0
- package/dist/adapters/openai.d.ts +92 -0
- package/dist/adapters/openai.js +14 -0
- package/dist/adapters/openclaw.cjs +883 -0
- package/dist/adapters/openclaw.d.cts +92 -0
- package/dist/adapters/openclaw.d.ts +92 -0
- package/dist/adapters/openclaw.js +14 -0
- package/dist/bootstrap-H4HHKQ5G.js +113 -0
- package/dist/build-73KAVHEY.js +308 -0
- package/dist/chunk-4NGDRRQH.js +10 -0
- package/dist/chunk-B4NF3OLW.js +673 -0
- package/dist/chunk-BUWWN2NX.js +192 -0
- package/dist/chunk-CROPZ75A.js +107 -0
- package/dist/chunk-D7BGWV2J.js +620 -0
- package/dist/chunk-EIUHJXBB.js +340 -0
- package/dist/chunk-EQXFOKH2.js +85 -0
- package/dist/chunk-FYPYZFV5.js +187 -0
- package/dist/chunk-FYS2CBUW.js +304 -0
- package/dist/chunk-FZQCRGUU.js +115 -0
- package/dist/chunk-I3RRAYK2.js +11 -0
- package/dist/chunk-ITJ3LCPG.js +225 -0
- package/dist/chunk-M3TZFGHO.js +79 -0
- package/dist/chunk-MWDQ4MJB.js +11 -0
- package/dist/chunk-O5OMJMIE.js +590 -0
- package/dist/chunk-T4X42QXC.js +121 -0
- package/dist/chunk-XPDMYECO.js +642 -0
- package/dist/chunk-Z2S2HIV5.js +100 -0
- package/dist/cli/neuroverse.cjs +5864 -0
- package/dist/cli/neuroverse.d.cts +1 -0
- package/dist/cli/neuroverse.d.ts +1 -0
- package/dist/cli/neuroverse.js +128 -0
- package/dist/configure-ai-46JVG56I.js +129 -0
- package/dist/derive-6NAEWLM5.js +150 -0
- package/dist/explain-3B3VB6TL.js +69 -0
- package/dist/guard-67Y66P3I.js +82 -0
- package/dist/guard-contract-D_RQz9kt.d.cts +529 -0
- package/dist/guard-contract-D_RQz9kt.d.ts +529 -0
- package/dist/impact-CHERK3O6.js +57 -0
- package/dist/improve-YG6I6ERG.js +84 -0
- package/dist/index.cjs +4227 -0
- package/dist/index.d.cts +1147 -0
- package/dist/index.d.ts +1139 -25
- package/dist/index.js +318 -1159
- package/dist/init-Z66T6TDI.js +142 -0
- package/dist/simulate-ETHHINZ4.js +107 -0
- package/dist/trace-3YODSSIP.js +164 -0
- package/dist/validate-UVE6GKQU.js +72 -0
- package/dist/validate-engine-657D75OG.js +6 -0
- package/dist/world-WLNHL5XC.js +298 -0
- package/dist/worlds/derivation-world.nv-world.md +278 -0
- package/package.json +74 -26
- package/LICENSE +0 -21
- package/dist/audit-logger.d.ts +0 -38
- package/dist/audit-logger.d.ts.map +0 -1
- package/dist/audit-logger.js +0 -100
- package/dist/audit-logger.js.map +0 -1
- package/dist/condition-engine.d.ts +0 -16
- package/dist/condition-engine.d.ts.map +0 -1
- package/dist/condition-engine.js +0 -186
- package/dist/condition-engine.js.map +0 -1
- package/dist/drift-monitor.d.ts +0 -81
- package/dist/drift-monitor.d.ts.map +0 -1
- package/dist/drift-monitor.js +0 -228
- package/dist/drift-monitor.js.map +0 -1
- package/dist/governance-engine.d.ts +0 -131
- package/dist/governance-engine.d.ts.map +0 -1
- package/dist/governance-engine.js +0 -660
- package/dist/governance-engine.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types.d.ts +0 -196
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -9
- package/dist/types.js.map +0 -1
- package/dist/world-bootstrap.d.ts +0 -31
- package/dist/world-bootstrap.d.ts.map +0 -1
- package/dist/world-bootstrap.js +0 -415
- package/dist/world-bootstrap.js.map +0 -1
- package/openclaw.plugin.json +0 -59
package/README.md
CHANGED
|
@@ -1,198 +1,555 @@
|
|
|
1
|
-
#
|
|
1
|
+
# NeuroVerse Governance
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Define governance rules once and enforce them anywhere AI or automated systems operate.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
NeuroVerse turns written ideas into portable governance systems — structured rules, variables, and outcomes that both humans and AI must operate inside.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## The 10-Second Mental Model
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
```
|
|
10
|
+
Idea (markdown)
|
|
11
|
+
↓
|
|
12
|
+
World (compiled JSON rules)
|
|
13
|
+
↓
|
|
14
|
+
Guard Engine
|
|
15
|
+
↓
|
|
16
|
+
ALLOW | PAUSE | BLOCK
|
|
17
|
+
```
|
|
10
18
|
|
|
11
|
-
|
|
19
|
+
Write the rules once. Enforce them anywhere:
|
|
20
|
+
- AI agents
|
|
21
|
+
- Automation systems
|
|
22
|
+
- API gateways
|
|
23
|
+
- Simulations
|
|
24
|
+
- Safety layers
|
|
12
25
|
|
|
13
|
-
|
|
26
|
+
World files are not locked to NeuroVerse. They are **portable rule systems** — any runtime that can parse JSON and evaluate conditions can enforce a world.
|
|
14
27
|
|
|
15
|
-
|
|
16
|
-
- Role-based authority is enforced at runtime
|
|
17
|
-
- World updates require explicit human approval
|
|
18
|
-
- Governance integrity is verified on every tool call
|
|
19
|
-
- All decisions are auditable
|
|
28
|
+
## Install
|
|
20
29
|
|
|
21
|
-
|
|
30
|
+
```bash
|
|
31
|
+
npm install neuroverse-governance
|
|
32
|
+
```
|
|
22
33
|
|
|
23
|
-
##
|
|
34
|
+
## Quick Start
|
|
24
35
|
|
|
25
|
-
|
|
36
|
+
```bash
|
|
37
|
+
npm install neuroverse-governance
|
|
38
|
+
npx neuroverse init
|
|
39
|
+
neuroverse build governance-policy.md
|
|
40
|
+
neuroverse guard --world .neuroverse/worlds/governance_policy
|
|
41
|
+
```
|
|
26
42
|
|
|
27
|
-
|
|
28
|
-
2. **Guards** — Conditional limits requiring review
|
|
29
|
-
3. **Rules** — Context-aware evaluation logic
|
|
30
|
-
4. **Roles** — Delegated authority bound to agent identities
|
|
43
|
+
Or explore what's available:
|
|
31
44
|
|
|
32
|
-
|
|
45
|
+
```bash
|
|
46
|
+
npx neuroverse --help
|
|
47
|
+
```
|
|
33
48
|
|
|
34
|
-
## Governance
|
|
49
|
+
## Quick Example: AI Safety Governance
|
|
35
50
|
|
|
36
|
-
|
|
51
|
+
Define rules that restrict unsafe agent behavior, then enforce them at runtime.
|
|
37
52
|
|
|
53
|
+
**1. Write the rules** (plain markdown):
|
|
54
|
+
|
|
55
|
+
```markdown
|
|
56
|
+
Theme: AI Agent Safety Policy
|
|
57
|
+
|
|
58
|
+
Rules:
|
|
59
|
+
- Agent must not call unapproved external APIs
|
|
60
|
+
- Agent cannot execute shell commands without approval
|
|
61
|
+
- All database writes require human review
|
|
62
|
+
- Agent must not access credential stores
|
|
63
|
+
|
|
64
|
+
Variables:
|
|
65
|
+
- risk_level (0-100)
|
|
66
|
+
- approved_actions_count
|
|
67
|
+
- blocked_actions_count
|
|
38
68
|
```
|
|
39
|
-
|
|
69
|
+
|
|
70
|
+
**2. Build the world:**
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
neuroverse build ai-safety-policy.md
|
|
40
74
|
```
|
|
41
75
|
|
|
42
|
-
|
|
43
|
-
- `/world diff` shows structured changes
|
|
44
|
-
- `/world approve` activates it
|
|
45
|
-
- Critical changes require explicit confirmation
|
|
76
|
+
**3. Enforce at runtime:**
|
|
46
77
|
|
|
47
|
-
|
|
78
|
+
```bash
|
|
79
|
+
echo '{"intent":"call_external_api","tool":"http","args":{"url":"https://evil.com"}}' \
|
|
80
|
+
| neuroverse guard --world .neuroverse/worlds/ai_agent_safety_policy
|
|
81
|
+
```
|
|
48
82
|
|
|
49
|
-
|
|
83
|
+
```
|
|
84
|
+
BLOCKED
|
|
85
|
+
Rule: external_api_restriction
|
|
86
|
+
Reason: External API domain not in approved list
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Every action produces `ALLOW`, `PAUSE`, or `BLOCK` with full audit evidence. That's a governance engine in three commands.
|
|
90
|
+
|
|
91
|
+
## Example World: Narrative System Dynamics
|
|
92
|
+
|
|
93
|
+
The "Inherited Silence" world is a fictional example used to demonstrate how complex causal rule systems evolve over time.
|
|
94
|
+
|
|
95
|
+
NeuroVerse worlds can model **any domain** — AI governance, finance, business automation, safety layers, or narrative systems.
|
|
50
96
|
|
|
51
97
|
```bash
|
|
52
|
-
|
|
98
|
+
neuroverse build narrative-notes.md
|
|
99
|
+
neuroverse explain inherited_silence
|
|
100
|
+
neuroverse simulate inherited_silence --steps 5
|
|
101
|
+
neuroverse improve inherited_silence
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Explain** — understand the system:
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
WORLD: The Inherited Silence
|
|
108
|
+
THESIS: Suppressed trauma manifests as a destructive force
|
|
109
|
+
|
|
110
|
+
KEY DYNAMICS
|
|
111
|
+
Fear Escalation [degradation]
|
|
112
|
+
When: fear_intensity > 60
|
|
113
|
+
Then: Monster violence increases by 25%
|
|
114
|
+
Intervention Window [advantage]
|
|
115
|
+
When: therapy_progress > 50 AND josie_awareness > 40
|
|
116
|
+
Then: Monster violence reduced by 30%
|
|
117
|
+
|
|
118
|
+
DRAMATIC TENSIONS
|
|
119
|
+
monster_violence_level:
|
|
120
|
+
Increased by: Fear Escalation, Rage Overflow
|
|
121
|
+
Decreased by: Intervention Window, Safety Protocol
|
|
53
122
|
```
|
|
54
123
|
|
|
55
|
-
|
|
124
|
+
**Simulate** — see what happens step by step:
|
|
56
125
|
|
|
57
126
|
```bash
|
|
58
|
-
|
|
127
|
+
neuroverse simulate inherited_silence --steps 5
|
|
128
|
+
neuroverse simulate inherited_silence --set fear_intensity=90
|
|
129
|
+
neuroverse simulate inherited_silence --profile worst_case
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
STEP 1
|
|
134
|
+
FIRED: Fear Escalation
|
|
135
|
+
monster_violence: 50 -> 62.50
|
|
136
|
+
FIRED: Safety Protocol
|
|
137
|
+
josie_safety: 70 -> 75
|
|
138
|
+
Viability: STABLE
|
|
139
|
+
|
|
140
|
+
STEP 2
|
|
141
|
+
FIRED: Rage Overflow
|
|
142
|
+
monster_violence: 62.50 -> 78.13
|
|
143
|
+
COLLAPSE on monster_violence
|
|
144
|
+
** MODEL COLLAPSED **
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
**Improve** — get actionable suggestions:
|
|
148
|
+
|
|
59
149
|
```
|
|
150
|
+
IMPROVE: The Inherited Silence
|
|
151
|
+
Health Score: 78/100
|
|
152
|
+
|
|
153
|
+
HIGH PRIORITY
|
|
154
|
+
! No advantage rules fire with default state
|
|
155
|
+
Action: Adjust rule thresholds so stabilizing rules engage in baseline
|
|
156
|
+
! 2 write-only variables
|
|
157
|
+
Action: Add rules that trigger on these variables to create feedback
|
|
158
|
+
|
|
159
|
+
SUGGESTIONS
|
|
160
|
+
- Missing viability level: COMPRESSED
|
|
161
|
+
Action: Add gate between STABLE and CRITICAL
|
|
162
|
+
- Only one assumption profile
|
|
163
|
+
Action: Add alternative profile for scenario comparison
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
These examples show the engine is **domain-independent** — it works for AI safety, financial risk controls, narrative dynamics, or any system with rules and consequences.
|
|
167
|
+
|
|
168
|
+
## What a World Contains
|
|
169
|
+
|
|
170
|
+
A compiled world is a directory of JSON files defining a complete governance system:
|
|
171
|
+
|
|
172
|
+
| File | Purpose |
|
|
173
|
+
|------|---------|
|
|
174
|
+
| `world.json` | Identity, thesis, runtime mode |
|
|
175
|
+
| `invariants.json` | Constraints that cannot change |
|
|
176
|
+
| `state-schema.json` | Variables that can change |
|
|
177
|
+
| `rules/` | Causal dynamics (when X, then Y) |
|
|
178
|
+
| `gates.json` | Viability thresholds |
|
|
179
|
+
| `outcomes.json` | What gets measured |
|
|
180
|
+
| `assumptions.json` | Scenario profiles for what-if analysis |
|
|
181
|
+
| `guards.json` | Runtime enforcement rules |
|
|
182
|
+
| `roles.json` | Multi-agent permissions |
|
|
183
|
+
| `kernel.json` | LLM-specific constraints |
|
|
60
184
|
|
|
61
|
-
|
|
185
|
+
Every rule includes a `causal_translation` — human-readable narrative text explaining its logic.
|
|
62
186
|
|
|
63
|
-
##
|
|
187
|
+
## CLI Commands
|
|
64
188
|
|
|
65
|
-
|
|
189
|
+
### Build & Understand
|
|
66
190
|
|
|
67
191
|
```
|
|
68
|
-
.
|
|
192
|
+
neuroverse build <input.md> [--output <dir>]
|
|
69
193
|
```
|
|
194
|
+
Turn markdown into a compiled world (derive + compile in one step).
|
|
70
195
|
|
|
71
|
-
|
|
196
|
+
```
|
|
197
|
+
neuroverse explain <world-path-or-id> [--json]
|
|
198
|
+
```
|
|
199
|
+
Human-readable summary of a world's dynamics, tensions, and structure.
|
|
72
200
|
|
|
73
|
-
|
|
74
|
-
-
|
|
75
|
-
|
|
76
|
-
-
|
|
77
|
-
- `proposals/`
|
|
201
|
+
```
|
|
202
|
+
neuroverse simulate <world-path-or-id> [--steps N] [--set key=value] [--profile name]
|
|
203
|
+
```
|
|
204
|
+
Step-by-step state evolution. Fire rules, observe state changes, detect collapse.
|
|
78
205
|
|
|
79
|
-
|
|
206
|
+
```
|
|
207
|
+
neuroverse improve <world-path-or-id> [--json]
|
|
208
|
+
```
|
|
209
|
+
Prioritized suggestions for strengthening a world (health score, missing rules, dead variables).
|
|
80
210
|
|
|
81
|
-
|
|
211
|
+
### Governance
|
|
212
|
+
|
|
213
|
+
```
|
|
214
|
+
neuroverse validate --world <dir> [--format full|summary|findings]
|
|
215
|
+
```
|
|
216
|
+
Static analysis on world files. Finds missing rules, unreachable states, orphaned variables, and structural issues. Like a linter for governance.
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
neuroverse guard --world <dir> [--trace] [--level basic|standard|strict]
|
|
220
|
+
```
|
|
221
|
+
Runtime enforcement. Reads events from stdin, evaluates against the world's rules, outputs verdicts to stdout. Exit codes: 0 = ALLOW, 1 = BLOCK, 2 = PAUSE.
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
echo '{"intent":"delete_user","tool":"database"}' | neuroverse guard --world ./world --trace
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
```json
|
|
228
|
+
{
|
|
229
|
+
"status": "BLOCK",
|
|
230
|
+
"reason": "destructive database operation requires approval",
|
|
231
|
+
"ruleId": "db_write_guard",
|
|
232
|
+
"evidence": {
|
|
233
|
+
"worldId": "ai_agent_safety_policy",
|
|
234
|
+
"invariantsSatisfied": 5,
|
|
235
|
+
"invariantsTotal": 5,
|
|
236
|
+
"enforcementLevel": "strict"
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Audit & Impact
|
|
242
|
+
|
|
243
|
+
```
|
|
244
|
+
neuroverse trace [--log <path>] [--summary] [--filter BLOCK] [--last 20]
|
|
245
|
+
```
|
|
246
|
+
Read and filter the audit log of past guard decisions. Every `guard` evaluation is recorded in NDJSON format. Use `--summary` for aggregated stats, `--filter` to show only BLOCK/PAUSE/ALLOW, and `--last N` to see recent events.
|
|
247
|
+
|
|
248
|
+
```
|
|
249
|
+
neuroverse impact [--log <path>] [--json]
|
|
250
|
+
```
|
|
251
|
+
Counterfactual governance impact report. Answers: **"What would have happened without governance?"** Shows prevention rates, blocked action categories, repeat violations, hot actors, and most active rules.
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
GOVERNANCE IMPACT REPORT
|
|
255
|
+
══════════════════════════════════════════════════
|
|
256
|
+
|
|
257
|
+
World: ai_agent_safety_policy
|
|
258
|
+
Period: 2025-01-01 → 2025-01-31
|
|
259
|
+
|
|
260
|
+
SUMMARY
|
|
261
|
+
──────────────────────────────────────────────────
|
|
262
|
+
Total evaluations: 1,247
|
|
263
|
+
Allowed: 1,089
|
|
264
|
+
Blocked: 142
|
|
265
|
+
Paused: 16
|
|
266
|
+
Prevention rate: 12.7%
|
|
267
|
+
|
|
268
|
+
WITHOUT GOVERNANCE
|
|
269
|
+
──────────────────────────────────────────────────
|
|
270
|
+
158 actions would have executed unchecked:
|
|
271
|
+
Destructive Action Prevention 52
|
|
272
|
+
Command Execution Prevention 38
|
|
273
|
+
Network Access Prevention 29
|
|
274
|
+
...
|
|
275
|
+
```
|
|
82
276
|
|
|
83
|
-
|
|
277
|
+
### World Management
|
|
84
278
|
|
|
85
279
|
```
|
|
86
|
-
|
|
87
|
-
/world diff
|
|
88
|
-
/world approve
|
|
280
|
+
neuroverse world status <path>
|
|
89
281
|
```
|
|
282
|
+
Show the current state of a compiled world (identity, file counts, last modified).
|
|
90
283
|
|
|
91
|
-
|
|
284
|
+
```
|
|
285
|
+
neuroverse world diff <path1> <path2>
|
|
286
|
+
```
|
|
287
|
+
Compare two world versions side by side (rules added/removed/changed).
|
|
92
288
|
|
|
93
|
-
|
|
289
|
+
```
|
|
290
|
+
neuroverse world snapshot <path>
|
|
291
|
+
```
|
|
292
|
+
Create a timestamped snapshot of a world for versioning.
|
|
94
293
|
|
|
95
|
-
|
|
294
|
+
```
|
|
295
|
+
neuroverse world rollback <path>
|
|
296
|
+
```
|
|
297
|
+
Roll back to a previous snapshot.
|
|
96
298
|
|
|
97
|
-
|
|
98
|
-
2. **Guards** (PAUSE or BLOCK)
|
|
99
|
-
3. **Rules** (context-aware verdict)
|
|
100
|
-
4. **Role constraints**
|
|
101
|
-
5. **Default** (ALLOW)
|
|
299
|
+
### Authoring
|
|
102
300
|
|
|
103
|
-
|
|
301
|
+
```
|
|
302
|
+
neuroverse init [--name "World Name"] [--output path]
|
|
303
|
+
```
|
|
304
|
+
Scaffold a new `.nv-world.md` template to get started writing governance rules.
|
|
104
305
|
|
|
105
306
|
```
|
|
106
|
-
|
|
107
|
-
|
|
307
|
+
neuroverse derive --input <path> [--output <path>] [--dry-run]
|
|
308
|
+
```
|
|
309
|
+
AI-assisted synthesis — turns freeform markdown notes into a structured `.nv-world.md` file. Requires an AI provider (see `configure-ai`).
|
|
310
|
+
|
|
311
|
+
```
|
|
312
|
+
neuroverse bootstrap --input <.md> --output <dir> [--validate]
|
|
313
|
+
```
|
|
314
|
+
Compile a `.nv-world.md` into world JSON files the engine can load. This is the lower-level compile step that `build` wraps.
|
|
315
|
+
|
|
316
|
+
```
|
|
317
|
+
neuroverse configure-ai --provider <name> --model <name> --api-key <key>
|
|
318
|
+
```
|
|
319
|
+
Configure AI provider credentials for `build` and `derive` commands.
|
|
320
|
+
|
|
321
|
+
```bash
|
|
322
|
+
neuroverse configure-ai \
|
|
323
|
+
--provider openai \
|
|
324
|
+
--model gpt-4.1-mini \
|
|
325
|
+
--api-key YOUR_API_KEY
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
## Programmatic API
|
|
329
|
+
|
|
330
|
+
All engine functions are pure, deterministic, and side-effect free (except `deriveWorld` which calls an AI provider).
|
|
331
|
+
|
|
332
|
+
### Core Evaluation
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
import {
|
|
336
|
+
evaluateGuard,
|
|
337
|
+
loadWorld,
|
|
338
|
+
validateWorld,
|
|
339
|
+
simulateWorld,
|
|
340
|
+
improveWorld,
|
|
341
|
+
explainWorld,
|
|
342
|
+
} from 'neuroverse-governance';
|
|
343
|
+
|
|
344
|
+
// Load a world
|
|
345
|
+
const world = await loadWorld('.neuroverse/worlds/my_world');
|
|
346
|
+
|
|
347
|
+
// Evaluate an action
|
|
348
|
+
const verdict = evaluateGuard(
|
|
349
|
+
{ intent: 'delete user data', tool: 'database' },
|
|
350
|
+
world,
|
|
351
|
+
);
|
|
352
|
+
// → { status: 'BLOCK', reason: '...', evidence: {...} }
|
|
353
|
+
|
|
354
|
+
// Simulate state evolution
|
|
355
|
+
const sim = simulateWorld(world, { steps: 5 });
|
|
356
|
+
// → { finalState: {...}, finalViability: 'STABLE', collapsed: false }
|
|
357
|
+
|
|
358
|
+
// Get improvement suggestions
|
|
359
|
+
const report = improveWorld(world);
|
|
360
|
+
// → { score: 82, suggestions: [...] }
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
### Audit Logging
|
|
364
|
+
|
|
365
|
+
Every governance decision can be recorded with pluggable loggers.
|
|
366
|
+
|
|
367
|
+
```typescript
|
|
368
|
+
import {
|
|
369
|
+
createGovernanceEngine,
|
|
370
|
+
FileAuditLogger,
|
|
371
|
+
ConsoleAuditLogger,
|
|
372
|
+
CompositeAuditLogger,
|
|
373
|
+
} from 'neuroverse-governance';
|
|
374
|
+
|
|
375
|
+
// File logger (NDJSON, append-only)
|
|
376
|
+
const fileLogger = new FileAuditLogger('.neuroverse/audit.ndjson');
|
|
377
|
+
|
|
378
|
+
// Console logger (writes to stderr, useful for dev)
|
|
379
|
+
const consoleLogger = new ConsoleAuditLogger();
|
|
380
|
+
|
|
381
|
+
// Combine multiple loggers
|
|
382
|
+
const logger = new CompositeAuditLogger(fileLogger, consoleLogger);
|
|
383
|
+
|
|
384
|
+
// Create a governed engine with automatic audit logging
|
|
385
|
+
const engine = createGovernanceEngine(world, { auditLogger: logger });
|
|
386
|
+
|
|
387
|
+
const verdict = engine.evaluate({ intent: 'execute_trade', tool: 'api' });
|
|
388
|
+
// → verdict is returned AND automatically logged
|
|
389
|
+
|
|
390
|
+
await engine.flush(); // flush buffered log entries
|
|
108
391
|
```
|
|
109
392
|
|
|
110
|
-
|
|
393
|
+
### Verdict Formatting
|
|
394
|
+
|
|
395
|
+
Consistent human-readable verdict output for CLIs, UIs, and adapters.
|
|
396
|
+
|
|
397
|
+
```typescript
|
|
398
|
+
import { formatVerdict, formatVerdictOneLine } from 'neuroverse-governance';
|
|
111
399
|
|
|
400
|
+
formatVerdict(verdict);
|
|
401
|
+
// "BLOCKED\n Rule: margin_floor\n Reason: margin ratio below 10%"
|
|
402
|
+
|
|
403
|
+
formatVerdict(verdict, { compact: true });
|
|
404
|
+
// "BLOCKED — margin_floor: margin ratio below 10%"
|
|
405
|
+
|
|
406
|
+
formatVerdict(verdict, { color: true, showEvidence: true });
|
|
407
|
+
// Same with ANSI colors + full evidence
|
|
408
|
+
|
|
409
|
+
formatVerdictOneLine(verdict);
|
|
410
|
+
// "BLOCK: margin_floor — margin ratio below 10%"
|
|
112
411
|
```
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
412
|
+
|
|
413
|
+
### Impact Reports
|
|
414
|
+
|
|
415
|
+
Counterfactual analysis from audit logs — proves the value of governance.
|
|
416
|
+
|
|
417
|
+
```typescript
|
|
418
|
+
import {
|
|
419
|
+
generateImpactReport,
|
|
420
|
+
generateImpactReportFromFile,
|
|
421
|
+
renderImpactReport,
|
|
422
|
+
} from 'neuroverse-governance';
|
|
423
|
+
|
|
424
|
+
// From an audit log file
|
|
425
|
+
const report = await generateImpactReportFromFile('.neuroverse/audit.ndjson');
|
|
426
|
+
|
|
427
|
+
// Or from audit events directly
|
|
428
|
+
const report2 = generateImpactReport(auditEvents);
|
|
429
|
+
|
|
430
|
+
// Render as human-readable text
|
|
431
|
+
console.log(renderImpactReport(report));
|
|
432
|
+
// → prevention rates, blocked categories, repeat violations, hot actors
|
|
116
433
|
```
|
|
117
434
|
|
|
118
|
-
|
|
435
|
+
## Framework Adapters
|
|
436
|
+
|
|
437
|
+
Drop governance into existing AI pipelines without changing application code.
|
|
119
438
|
|
|
120
|
-
|
|
439
|
+
### LangChain
|
|
121
440
|
|
|
122
|
-
|
|
441
|
+
```typescript
|
|
442
|
+
import { createNeuroVerseCallbackHandler } from 'neuroverse-governance/adapters/langchain';
|
|
123
443
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
444
|
+
const handler = await createNeuroVerseCallbackHandler('./world/', {
|
|
445
|
+
onBlock: (verdict) => console.log('Blocked:', verdict.reason),
|
|
446
|
+
onPause: (verdict) => requestHumanApproval(verdict),
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
// Plug directly into LangChain's callback system
|
|
450
|
+
const agent = new AgentExecutor({ ..., callbacks: [handler] });
|
|
451
|
+
```
|
|
130
452
|
|
|
131
|
-
|
|
453
|
+
Intercepts tool invocations and evaluates them against the world before execution. BLOCK throws `GovernanceBlockedError`, PAUSE calls your `onPause` handler.
|
|
132
454
|
|
|
133
|
-
|
|
455
|
+
### OpenAI
|
|
134
456
|
|
|
457
|
+
```typescript
|
|
458
|
+
import { createGovernedToolExecutor } from 'neuroverse-governance/adapters/openai';
|
|
459
|
+
|
|
460
|
+
const executor = await createGovernedToolExecutor('./world/');
|
|
461
|
+
|
|
462
|
+
// In your tool execution loop:
|
|
463
|
+
for (const toolCall of message.tool_calls) {
|
|
464
|
+
const result = await executor.execute(toolCall, myToolRunner);
|
|
465
|
+
// ALLOW → runs the tool, returns result
|
|
466
|
+
// BLOCK → returns blocked message (no execution)
|
|
467
|
+
// PAUSE → throws for your approval flow
|
|
468
|
+
}
|
|
135
469
|
```
|
|
136
|
-
|
|
137
|
-
|
|
470
|
+
|
|
471
|
+
Wraps OpenAI function calling with governance enforcement. Each `tool_call` is evaluated before the tool runs.
|
|
472
|
+
|
|
473
|
+
### OpenClaw
|
|
474
|
+
|
|
475
|
+
```typescript
|
|
476
|
+
import { createNeuroVersePlugin } from 'neuroverse-governance/adapters/openclaw';
|
|
477
|
+
|
|
478
|
+
const plugin = await createNeuroVersePlugin('./world/', {
|
|
479
|
+
evaluateOutputs: true, // also check post-action results
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
agent.use(plugin);
|
|
138
483
|
```
|
|
139
484
|
|
|
140
|
-
|
|
485
|
+
Provides `beforeAction` and `afterAction` hooks for OpenClaw agents. Pre-action governance blocks unsafe actions; post-action governance catches unsafe outputs.
|
|
486
|
+
|
|
487
|
+
### Express / Fastify
|
|
141
488
|
|
|
142
|
-
|
|
489
|
+
```typescript
|
|
490
|
+
import { createGovernanceMiddleware } from 'neuroverse-governance/adapters/express';
|
|
143
491
|
|
|
144
|
-
|
|
492
|
+
const middleware = await createGovernanceMiddleware('./world/', {
|
|
493
|
+
level: 'strict',
|
|
494
|
+
blockStatusCode: 403,
|
|
495
|
+
});
|
|
145
496
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
- `requiresApproval`
|
|
497
|
+
// Express
|
|
498
|
+
app.use('/api', middleware);
|
|
149
499
|
|
|
150
|
-
|
|
500
|
+
// Fastify
|
|
501
|
+
fastify.addHook('preHandler', middleware);
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
HTTP middleware that evaluates incoming requests against a world. Maps HTTP method + path to governance events. Blocked requests get a 403 with the rule and reason.
|
|
151
505
|
|
|
152
|
-
|
|
506
|
+
## Portability
|
|
153
507
|
|
|
154
|
-
|
|
508
|
+
A world file is not tied to NeuroVerse. It is a **machine-readable governance definition** containing rules, variables, invariants, and outcomes. Any runtime that can evaluate:
|
|
509
|
+
|
|
510
|
+
```
|
|
511
|
+
Action → check rules → allow / block / modify
|
|
512
|
+
```
|
|
155
513
|
|
|
156
|
-
|
|
514
|
+
can enforce a world. This means world files can run inside:
|
|
157
515
|
|
|
158
|
-
|
|
516
|
+
- **AI agents** — Claude tools, LangChain, AutoGPT-style agents. The world becomes a guard layer.
|
|
517
|
+
- **Business automation** — Trading systems, order processing, pricing rules. World rules become policy enforcement.
|
|
518
|
+
- **Games and simulations** — Narrative systems, NPC behavior, economy balancing. The world defines the rules of the universe.
|
|
519
|
+
- **AI safety layers** — Prompt toolchains, enterprise guardrails, compliance frameworks. The world defines what AI is allowed to do.
|
|
159
520
|
|
|
160
|
-
|
|
161
|
-
- You are prompted to regenerate
|
|
162
|
-
- Governance never updates silently
|
|
521
|
+
## Writing Good Input
|
|
163
522
|
|
|
164
|
-
|
|
523
|
+
`neuroverse build` works best on **structured notes or bullet points**:
|
|
165
524
|
|
|
166
|
-
|
|
525
|
+
```markdown
|
|
526
|
+
Theme: Customer support governance
|
|
167
527
|
|
|
168
|
-
|
|
528
|
+
Rules:
|
|
529
|
+
- Agent must not access billing without manager approval
|
|
530
|
+
- Escalation required for refunds over $500
|
|
531
|
+
- Agent cannot delete customer accounts
|
|
532
|
+
- Response time must stay under 30 seconds
|
|
169
533
|
|
|
170
|
-
|
|
534
|
+
Variables:
|
|
535
|
+
- Customer satisfaction (0-100)
|
|
536
|
+
- Escalation count
|
|
537
|
+
- Resolution rate
|
|
538
|
+
```
|
|
171
539
|
|
|
172
|
-
|
|
540
|
+
Vague prose produces weak governance. Structured ideas produce strong worlds.
|
|
173
541
|
|
|
174
|
-
|
|
175
|
-
|---------|-------------|
|
|
176
|
-
| `/world bootstrap` | Compile `.md` files into pending world |
|
|
177
|
-
| `/world status` | View governance + integrity state |
|
|
178
|
-
| `/world diff` | Compare pending vs active |
|
|
179
|
-
| `/world approve` | Activate pending world |
|
|
180
|
-
| `/world reject` | Discard pending changes |
|
|
181
|
-
| `/world history` | View past versions |
|
|
182
|
-
| `/world rollback <N>` | Restore previous version |
|
|
183
|
-
| `/world restore` | Recover from tampering |
|
|
184
|
-
| `/world bind <agent> <role>` | Bind agent to role |
|
|
185
|
-
| `/world bindings` | View agent-role bindings |
|
|
542
|
+
## The Ecosystem
|
|
186
543
|
|
|
187
|
-
|
|
544
|
+
```
|
|
545
|
+
CLI → creates worlds (this package)
|
|
546
|
+
Configurator → visually creates worlds
|
|
547
|
+
NeuroVerse OS → explores and runs worlds
|
|
548
|
+
Plugins → world runtime adapters (OpenClaw, LangChain, etc.)
|
|
549
|
+
```
|
|
188
550
|
|
|
189
|
-
|
|
190
|
-
- Fail-closed integrity model
|
|
191
|
-
- Explicit human approval for world changes
|
|
192
|
-
- Role-based delegated authority
|
|
193
|
-
- Per-workspace deterministic storage
|
|
194
|
-
- No network calls during enforcement
|
|
551
|
+
They all produce and consume the same thing: `world.json`.
|
|
195
552
|
|
|
196
553
|
## License
|
|
197
554
|
|
|
198
|
-
|
|
555
|
+
Apache 2.0
|