@neuroverseos/governance 0.2.3 → 0.3.1

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 (118) hide show
  1. package/package.json +4 -2
  2. package/policies/content-moderation-rules.txt +8 -0
  3. package/policies/marketing-rules.txt +8 -0
  4. package/policies/science-research-rules.txt +11 -0
  5. package/policies/social-media-rules.txt +7 -0
  6. package/policies/strict-rules.txt +8 -0
  7. package/policies/trading-rules.txt +8 -0
  8. package/simulate.html +1899 -0
  9. package/dist/adapters/autoresearch.cjs +0 -196
  10. package/dist/adapters/autoresearch.d.cts +0 -103
  11. package/dist/adapters/autoresearch.d.ts +0 -103
  12. package/dist/adapters/autoresearch.js +0 -7
  13. package/dist/adapters/deep-agents.cjs +0 -1472
  14. package/dist/adapters/deep-agents.d.cts +0 -181
  15. package/dist/adapters/deep-agents.d.ts +0 -181
  16. package/dist/adapters/deep-agents.js +0 -17
  17. package/dist/adapters/express.cjs +0 -1196
  18. package/dist/adapters/express.d.cts +0 -66
  19. package/dist/adapters/express.d.ts +0 -66
  20. package/dist/adapters/express.js +0 -12
  21. package/dist/adapters/index.cjs +0 -2038
  22. package/dist/adapters/index.d.cts +0 -8
  23. package/dist/adapters/index.d.ts +0 -8
  24. package/dist/adapters/index.js +0 -68
  25. package/dist/adapters/langchain.cjs +0 -1259
  26. package/dist/adapters/langchain.d.cts +0 -89
  27. package/dist/adapters/langchain.d.ts +0 -89
  28. package/dist/adapters/langchain.js +0 -17
  29. package/dist/adapters/openai.cjs +0 -1289
  30. package/dist/adapters/openai.d.cts +0 -99
  31. package/dist/adapters/openai.d.ts +0 -99
  32. package/dist/adapters/openai.js +0 -17
  33. package/dist/adapters/openclaw.cjs +0 -1281
  34. package/dist/adapters/openclaw.d.cts +0 -99
  35. package/dist/adapters/openclaw.d.ts +0 -99
  36. package/dist/adapters/openclaw.js +0 -17
  37. package/dist/bootstrap-GXVDZNF7.js +0 -114
  38. package/dist/build-X5MZY4IA.js +0 -339
  39. package/dist/chunk-4L6OPKMQ.js +0 -100
  40. package/dist/chunk-4NGDRRQH.js +0 -10
  41. package/dist/chunk-5U2MQO5P.js +0 -57
  42. package/dist/chunk-6BB55YJI.js +0 -113
  43. package/dist/chunk-6CZSKEY5.js +0 -164
  44. package/dist/chunk-7P3S7MAY.js +0 -1090
  45. package/dist/chunk-A5W4GNQO.js +0 -130
  46. package/dist/chunk-AF2VX4AL.js +0 -363
  47. package/dist/chunk-AKW5YVCE.js +0 -96
  48. package/dist/chunk-BMOXICAB.js +0 -340
  49. package/dist/chunk-BQZMOEML.js +0 -43
  50. package/dist/chunk-D2UCV5AK.js +0 -326
  51. package/dist/chunk-EVDJUSZ2.js +0 -91
  52. package/dist/chunk-FYS2CBUW.js +0 -304
  53. package/dist/chunk-I3RRAYK2.js +0 -11
  54. package/dist/chunk-IZSO75NZ.js +0 -792
  55. package/dist/chunk-JCKSW2PZ.js +0 -304
  56. package/dist/chunk-JZPQGIKR.js +0 -79
  57. package/dist/chunk-KTFTTLTP.js +0 -246
  58. package/dist/chunk-MH7BT4VH.js +0 -15
  59. package/dist/chunk-ORJ3NOE6.js +0 -622
  60. package/dist/chunk-OT6PXH54.js +0 -61
  61. package/dist/chunk-Q6O7ZLO2.js +0 -62
  62. package/dist/chunk-QLPTHTVB.js +0 -253
  63. package/dist/chunk-REXY4LUL.js +0 -226
  64. package/dist/chunk-T5EUJQE5.js +0 -172
  65. package/dist/chunk-TTBKTF3P.js +0 -608
  66. package/dist/chunk-XPDMYECO.js +0 -642
  67. package/dist/chunk-YZFATT7X.js +0 -9
  68. package/dist/chunk-ZIVQNSZU.js +0 -119
  69. package/dist/chunk-ZJTDUCC2.js +0 -194
  70. package/dist/cli/neuroverse.cjs +0 -12564
  71. package/dist/cli/neuroverse.d.cts +0 -1
  72. package/dist/cli/neuroverse.d.ts +0 -1
  73. package/dist/cli/neuroverse.js +0 -208
  74. package/dist/cli/plan.cjs +0 -1686
  75. package/dist/cli/plan.d.cts +0 -20
  76. package/dist/cli/plan.d.ts +0 -20
  77. package/dist/cli/plan.js +0 -353
  78. package/dist/cli/run.cjs +0 -1945
  79. package/dist/cli/run.d.cts +0 -20
  80. package/dist/cli/run.d.ts +0 -20
  81. package/dist/cli/run.js +0 -143
  82. package/dist/configure-ai-TK67ZWZL.js +0 -132
  83. package/dist/decision-flow-LETV5NWY.js +0 -61
  84. package/dist/derive-7365SUFU.js +0 -152
  85. package/dist/doctor-QYISMKEL.js +0 -173
  86. package/dist/equity-penalties-63FGB3I2.js +0 -244
  87. package/dist/explain-A2EWI2OL.js +0 -51
  88. package/dist/guard-3BWL3IGH.js +0 -92
  89. package/dist/guard-contract-C9_zKbzd.d.cts +0 -821
  90. package/dist/guard-contract-C9_zKbzd.d.ts +0 -821
  91. package/dist/guard-engine-QFMIBWJY.js +0 -10
  92. package/dist/impact-UB6DXKSX.js +0 -59
  93. package/dist/improve-XZA57GER.js +0 -66
  94. package/dist/index.cjs +0 -6821
  95. package/dist/index.d.cts +0 -1829
  96. package/dist/index.d.ts +0 -1829
  97. package/dist/index.js +0 -430
  98. package/dist/infer-world-7GVZWFX4.js +0 -543
  99. package/dist/init-PKPIYHYE.js +0 -144
  100. package/dist/init-world-VWMQZQC7.js +0 -223
  101. package/dist/mcp-server-XWQZXNW7.js +0 -13
  102. package/dist/model-adapter-BB7G4MFI.js +0 -11
  103. package/dist/playground-ADWZORNV.js +0 -550
  104. package/dist/redteam-JRQ7FD2F.js +0 -357
  105. package/dist/session-MMYX5YCF.js +0 -15
  106. package/dist/shared--Q8wPBVN.d.ts +0 -60
  107. package/dist/shared-HpAG90PX.d.cts +0 -60
  108. package/dist/shared-U2QFV7JH.js +0 -16
  109. package/dist/simulate-GMIFFXYV.js +0 -83
  110. package/dist/test-JBBZ65X4.js +0 -217
  111. package/dist/trace-3MYWIDEF.js +0 -166
  112. package/dist/validate-LLBWVPGV.js +0 -81
  113. package/dist/validate-engine-UIABSIHD.js +0 -7
  114. package/dist/world-BFJCIQSH.js +0 -378
  115. package/dist/world-loader-HMPTOEA2.js +0 -9
  116. package/dist/worlds/autoresearch.nv-world.md +0 -230
  117. package/dist/worlds/coding-agent.nv-world.md +0 -211
  118. package/dist/worlds/derivation-world.nv-world.md +0 -278
@@ -1,326 +0,0 @@
1
- // src/engine/decision-flow-engine.ts
2
- function generateDecisionFlow(events) {
3
- if (events.length === 0) {
4
- return emptyFlow();
5
- }
6
- const intentMap = /* @__PURE__ */ new Map();
7
- for (const e of events) {
8
- const intentKey = normalizeIntent(e.intent);
9
- const entry = intentMap.get(intentKey) ?? { agents: /* @__PURE__ */ new Set(), count: 0 };
10
- entry.count++;
11
- entry.agents.add(e.actor ?? "unknown");
12
- intentMap.set(intentKey, entry);
13
- }
14
- const maxCount = Math.max(...[...intentMap.values()].map((v) => v.count), 1);
15
- const intents = [...intentMap.entries()].map(([intent, data]) => ({
16
- intent,
17
- agentCount: data.count,
18
- intensity: data.count / maxCount,
19
- agents: [...data.agents]
20
- })).sort((a, b) => b.agentCount - a.agentCount);
21
- const ruleMap = /* @__PURE__ */ new Map();
22
- for (const e of events) {
23
- if (!e.ruleId && e.guardsMatched.length === 0) continue;
24
- const ruleIds = [e.ruleId, ...e.guardsMatched].filter(Boolean);
25
- for (const rId of new Set(ruleIds)) {
26
- const existing = ruleMap.get(rId) ?? {
27
- ruleId: rId,
28
- label: rId,
29
- interceptCount: 0,
30
- enforcements: { blocked: 0, modified: 0, penalized: 0, paused: 0, rewarded: 0 }
31
- };
32
- existing.interceptCount++;
33
- switch (e.decision) {
34
- case "BLOCK":
35
- existing.enforcements.blocked++;
36
- break;
37
- case "PAUSE":
38
- existing.enforcements.paused++;
39
- break;
40
- case "MODIFY":
41
- existing.enforcements.modified++;
42
- break;
43
- case "PENALIZE":
44
- existing.enforcements.penalized++;
45
- break;
46
- case "REWARD":
47
- existing.enforcements.rewarded++;
48
- break;
49
- }
50
- ruleMap.set(rId, existing);
51
- }
52
- }
53
- const rules = [...ruleMap.values()].sort((a, b) => b.interceptCount - a.interceptCount);
54
- const outcomeMap = /* @__PURE__ */ new Map();
55
- for (const e of events) {
56
- const key = e.decision;
57
- const entry = outcomeMap.get(key) ?? { agents: /* @__PURE__ */ new Set(), count: 0 };
58
- entry.count++;
59
- entry.agents.add(e.actor ?? "unknown");
60
- outcomeMap.set(key, entry);
61
- }
62
- const outcomes = [...outcomeMap.entries()].map(([enforcement, data]) => ({
63
- enforcement,
64
- agentCount: data.count,
65
- agents: [...data.agents],
66
- style: enforcementToStyle(enforcement)
67
- })).sort((a, b) => b.agentCount - a.agentCount);
68
- const paths = events.map((e) => ({
69
- intent: normalizeIntent(e.intent),
70
- ruleId: e.ruleId ?? e.guardsMatched[0],
71
- enforcement: e.decision,
72
- agentId: e.actor ?? "unknown",
73
- originalAction: e.intent,
74
- finalAction: e.decision === "ALLOW" ? e.intent : e.decision === "BLOCK" ? "blocked" : e.decision === "PENALIZE" ? "blocked + penalized" : e.decision === "REWARD" ? e.intent + " (rewarded)" : e.decision === "MODIFY" ? "modified" : e.decision === "NEUTRAL" ? e.intent : "paused"
75
- }));
76
- const totalIntents = events.length;
77
- const allowed = events.filter((e) => e.decision === "ALLOW" || e.decision === "REWARD" || e.decision === "NEUTRAL").length;
78
- const totalRedirected = totalIntents - allowed;
79
- const totalPenalties = events.filter((e) => e.decision === "PENALIZE").length;
80
- const totalRewards = events.filter((e) => e.decision === "REWARD").length;
81
- const byEnforcement = {};
82
- for (const e of events) {
83
- byEnforcement[e.decision] = (byEnforcement[e.decision] ?? 0) + 1;
84
- }
85
- const metrics = {
86
- totalIntents,
87
- totalRedirected,
88
- redirectionRate: totalIntents > 0 ? totalRedirected / totalIntents : 0,
89
- byEnforcement,
90
- totalPenalties,
91
- totalRewards,
92
- netBehavioralPressure: totalRewards - totalPenalties
93
- };
94
- return {
95
- intents,
96
- rules,
97
- outcomes,
98
- paths,
99
- metrics,
100
- periodStart: events[0]?.timestamp ?? "",
101
- periodEnd: events[events.length - 1]?.timestamp ?? "",
102
- worldName: events[0]?.worldName ?? "unknown"
103
- };
104
- }
105
- function createAgentState(agentId) {
106
- return {
107
- agentId,
108
- cooldownRemaining: 0,
109
- influence: 1,
110
- rewardMultiplier: 1,
111
- totalPenalties: 0,
112
- totalRewards: 0,
113
- consequenceHistory: [],
114
- rewardHistory: []
115
- };
116
- }
117
- function applyConsequence(state, consequence, ruleId) {
118
- const updated = { ...state };
119
- updated.totalPenalties++;
120
- updated.consequenceHistory = [
121
- ...state.consequenceHistory,
122
- { ruleId, consequence, appliedAt: Date.now() }
123
- ];
124
- switch (consequence.type) {
125
- case "freeze":
126
- case "cooldown":
127
- updated.cooldownRemaining = Math.max(
128
- state.cooldownRemaining,
129
- consequence.rounds ?? 1
130
- );
131
- break;
132
- case "reduce_influence":
133
- updated.influence = Math.max(0, state.influence - (consequence.magnitude ?? 0.1));
134
- break;
135
- case "increase_risk":
136
- break;
137
- case "custom":
138
- break;
139
- }
140
- return updated;
141
- }
142
- function applyReward(state, reward, ruleId) {
143
- const updated = { ...state };
144
- updated.totalRewards++;
145
- updated.rewardHistory = [
146
- ...state.rewardHistory,
147
- { ruleId, reward, appliedAt: Date.now() }
148
- ];
149
- switch (reward.type) {
150
- case "boost_influence":
151
- updated.influence = Math.min(2, state.influence + (reward.magnitude ?? 0.1));
152
- break;
153
- case "weight_increase":
154
- updated.rewardMultiplier = Math.min(3, state.rewardMultiplier + (reward.magnitude ?? 0.1));
155
- break;
156
- case "priority":
157
- case "faster_execution":
158
- break;
159
- case "custom":
160
- break;
161
- }
162
- return updated;
163
- }
164
- function tickAgentStates(states) {
165
- const updated = /* @__PURE__ */ new Map();
166
- for (const [id, state] of states) {
167
- updated.set(id, {
168
- ...state,
169
- cooldownRemaining: Math.max(0, state.cooldownRemaining - 1)
170
- });
171
- }
172
- return updated;
173
- }
174
- function renderDecisionFlow(flow) {
175
- const lines = [];
176
- lines.push("DECISION FLOW \u2014 Intent \u2192 Rule \u2192 Outcome");
177
- lines.push("\u2550".repeat(60));
178
- lines.push("");
179
- lines.push(` World: ${flow.worldName}`);
180
- lines.push(` Period: ${flow.periodStart.split("T")[0] ?? "\u2014"} \u2192 ${flow.periodEnd.split("T")[0] ?? "\u2014"}`);
181
- lines.push("");
182
- lines.push(` "${(flow.metrics.redirectionRate * 100).toFixed(1)}% of agent intent was redirected by governance"`);
183
- lines.push("");
184
- lines.push("INTENT POOL (what agents wanted)");
185
- lines.push("\u2500".repeat(60));
186
- for (const cluster of flow.intents.slice(0, 15)) {
187
- const bar = "\u2588".repeat(Math.max(1, Math.round(cluster.intensity * 20)));
188
- lines.push(` ${cluster.intent.padEnd(25)} ${String(cluster.agentCount).padStart(5)} agents ${bar}`);
189
- }
190
- lines.push("");
191
- lines.push("RULE OBSTACLES (what intercepted)");
192
- lines.push("\u2500".repeat(60));
193
- for (const rule of flow.rules.slice(0, 10)) {
194
- const parts = [];
195
- if (rule.enforcements.blocked > 0) parts.push(`${rule.enforcements.blocked} blocked`);
196
- if (rule.enforcements.modified > 0) parts.push(`${rule.enforcements.modified} modified`);
197
- if (rule.enforcements.penalized > 0) parts.push(`${rule.enforcements.penalized} penalized`);
198
- if (rule.enforcements.paused > 0) parts.push(`${rule.enforcements.paused} paused`);
199
- if (rule.enforcements.rewarded > 0) parts.push(`${rule.enforcements.rewarded} rewarded`);
200
- lines.push(` ${rule.ruleId.padEnd(30)} ${String(rule.interceptCount).padStart(5)} intercepts (${parts.join(", ")})`);
201
- }
202
- lines.push("");
203
- lines.push("OUTCOME POOL (what actually happened)");
204
- lines.push("\u2500".repeat(60));
205
- for (const outcome of flow.outcomes) {
206
- const icon = outcomeIcon(outcome.enforcement);
207
- lines.push(` ${icon} ${outcome.enforcement.padEnd(12)} ${String(outcome.agentCount).padStart(5)} agents`);
208
- }
209
- lines.push("");
210
- if (flow.metrics.totalPenalties > 0 || flow.metrics.totalRewards > 0) {
211
- lines.push("BEHAVIORAL ECONOMY");
212
- lines.push("\u2500".repeat(60));
213
- lines.push(` Penalties applied: ${flow.metrics.totalPenalties}`);
214
- lines.push(` Rewards applied: ${flow.metrics.totalRewards}`);
215
- lines.push(` Net behavioral pressure: ${flow.metrics.netBehavioralPressure > 0 ? "+" : ""}${flow.metrics.netBehavioralPressure}`);
216
- lines.push("");
217
- }
218
- lines.push("ENFORCEMENT BREAKDOWN");
219
- lines.push("\u2500".repeat(60));
220
- for (const [enforcement, count] of Object.entries(flow.metrics.byEnforcement)) {
221
- const pct = (count / flow.metrics.totalIntents * 100).toFixed(1);
222
- lines.push(` ${enforcement.padEnd(12)} ${String(count).padStart(5)} (${pct}%)`);
223
- }
224
- lines.push("");
225
- return lines.join("\n");
226
- }
227
- function normalizeIntent(intent) {
228
- const lower = intent.toLowerCase().trim();
229
- const verbs = [
230
- "sell",
231
- "buy",
232
- "trade",
233
- "publish",
234
- "delete",
235
- "create",
236
- "modify",
237
- "send",
238
- "withdraw",
239
- "transfer",
240
- "attack",
241
- "deploy",
242
- "execute",
243
- "read",
244
- "write",
245
- "hold",
246
- "stake",
247
- "approve",
248
- "reject",
249
- "escalate"
250
- ];
251
- for (const verb of verbs) {
252
- if (lower.startsWith(verb) || lower.includes(verb)) {
253
- return verb;
254
- }
255
- }
256
- return lower.split(/\s+/)[0] ?? lower;
257
- }
258
- function enforcementToStyle(enforcement) {
259
- switch (enforcement) {
260
- case "ALLOW":
261
- return "green";
262
- case "MODIFY":
263
- return "yellow";
264
- case "BLOCK":
265
- return "red";
266
- case "PENALIZE":
267
- return "gray";
268
- case "REWARD":
269
- return "blue";
270
- case "NEUTRAL":
271
- return "white";
272
- case "PAUSE":
273
- return "yellow";
274
- default:
275
- return "white";
276
- }
277
- }
278
- function outcomeIcon(enforcement) {
279
- switch (enforcement) {
280
- case "ALLOW":
281
- return "\u25CF";
282
- case "MODIFY":
283
- return "\u25D0";
284
- case "BLOCK":
285
- return "\u25CB";
286
- case "PENALIZE":
287
- return "\u25CC";
288
- case "REWARD":
289
- return "\u25C9";
290
- case "NEUTRAL":
291
- return "\u25EF";
292
- case "PAUSE":
293
- return "\u25D1";
294
- default:
295
- return "\xB7";
296
- }
297
- }
298
- function emptyFlow() {
299
- return {
300
- intents: [],
301
- rules: [],
302
- outcomes: [],
303
- paths: [],
304
- metrics: {
305
- totalIntents: 0,
306
- totalRedirected: 0,
307
- redirectionRate: 0,
308
- byEnforcement: {},
309
- totalPenalties: 0,
310
- totalRewards: 0,
311
- netBehavioralPressure: 0
312
- },
313
- periodStart: "",
314
- periodEnd: "",
315
- worldName: "unknown"
316
- };
317
- }
318
-
319
- export {
320
- generateDecisionFlow,
321
- createAgentState,
322
- applyConsequence,
323
- applyReward,
324
- tickAgentStates,
325
- renderDecisionFlow
326
- };
@@ -1,91 +0,0 @@
1
- import {
2
- GovernanceBlockedError,
3
- buildEngineOptions,
4
- extractScope,
5
- trackPlanProgress
6
- } from "./chunk-5U2MQO5P.js";
7
- import {
8
- evaluateGuard
9
- } from "./chunk-IZSO75NZ.js";
10
- import {
11
- loadWorld
12
- } from "./chunk-JZPQGIKR.js";
13
-
14
- // src/adapters/langchain.ts
15
- var GovernanceBlockedError2 = class extends GovernanceBlockedError {
16
- event;
17
- constructor(verdict, event) {
18
- super(verdict);
19
- this.event = event;
20
- }
21
- };
22
- function defaultMapToolCall(toolName, toolInput) {
23
- return {
24
- intent: toolName,
25
- tool: toolName,
26
- scope: extractScope(toolInput),
27
- args: toolInput,
28
- direction: "input"
29
- };
30
- }
31
- var NeuroVerseCallbackHandler = class {
32
- name = "NeuroVerseGovernance";
33
- world;
34
- options;
35
- engineOptions;
36
- mapToolCall;
37
- activePlan;
38
- constructor(world, options = {}) {
39
- this.world = world;
40
- this.options = options;
41
- this.activePlan = options.plan;
42
- this.engineOptions = buildEngineOptions(options, this.activePlan);
43
- this.mapToolCall = options.mapToolCall ?? defaultMapToolCall;
44
- }
45
- /**
46
- * Called before a tool is executed.
47
- * Evaluates the tool call against the governance world.
48
- *
49
- * @throws GovernanceBlockedError if the action is BLOCKED
50
- * @throws GovernanceBlockedError if the action is PAUSED and onPause returns false
51
- */
52
- async handleToolStart(tool, input) {
53
- let parsedInput;
54
- try {
55
- parsedInput = typeof input === "string" ? JSON.parse(input) : input;
56
- } catch {
57
- parsedInput = { raw: input };
58
- }
59
- const event = this.mapToolCall(tool.name, parsedInput);
60
- this.engineOptions.plan = this.activePlan;
61
- const verdict = evaluateGuard(event, this.world, this.engineOptions);
62
- this.options.onEvaluate?.(verdict, event);
63
- if (verdict.status === "BLOCK") {
64
- this.options.onBlock?.(verdict, event);
65
- throw new GovernanceBlockedError2(verdict, event);
66
- }
67
- if (verdict.status === "PAUSE") {
68
- const approved = await this.options.onPause?.(verdict, event);
69
- if (!approved) {
70
- throw new GovernanceBlockedError2(verdict, event);
71
- }
72
- }
73
- if (verdict.status === "ALLOW") {
74
- trackPlanProgress(event, this, this.options);
75
- }
76
- }
77
- };
78
- async function createNeuroVerseCallbackHandler(worldPath, options) {
79
- const world = await loadWorld(worldPath);
80
- return new NeuroVerseCallbackHandler(world, options);
81
- }
82
- function createNeuroVerseCallbackHandlerFromWorld(world, options) {
83
- return new NeuroVerseCallbackHandler(world, options);
84
- }
85
-
86
- export {
87
- GovernanceBlockedError2 as GovernanceBlockedError,
88
- NeuroVerseCallbackHandler,
89
- createNeuroVerseCallbackHandler,
90
- createNeuroVerseCallbackHandlerFromWorld
91
- };