@neuroverseos/governance 0.3.0 → 0.3.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.
- package/.well-known/ai-plugin.json +34 -9
- package/AGENTS.md +72 -24
- package/README.md +352 -237
- package/dist/adapters/autoresearch.cjs +1152 -3
- package/dist/adapters/autoresearch.d.cts +11 -3
- package/dist/adapters/autoresearch.d.ts +11 -3
- package/dist/adapters/autoresearch.js +9 -4
- package/dist/adapters/deep-agents.cjs +1528 -0
- package/dist/adapters/deep-agents.d.cts +181 -0
- package/dist/adapters/deep-agents.d.ts +181 -0
- package/dist/adapters/deep-agents.js +17 -0
- package/dist/adapters/express.cjs +171 -32
- package/dist/adapters/express.d.cts +1 -1
- package/dist/adapters/express.d.ts +1 -1
- package/dist/adapters/express.js +5 -5
- package/dist/adapters/index.cjs +564 -121
- package/dist/adapters/index.d.cts +3 -1
- package/dist/adapters/index.d.ts +3 -1
- package/dist/adapters/index.js +38 -16
- package/dist/adapters/langchain.cjs +217 -57
- package/dist/adapters/langchain.d.cts +5 -5
- package/dist/adapters/langchain.d.ts +5 -5
- package/dist/adapters/langchain.js +6 -5
- package/dist/adapters/openai.cjs +219 -59
- package/dist/adapters/openai.d.cts +5 -5
- package/dist/adapters/openai.d.ts +5 -5
- package/dist/adapters/openai.js +6 -5
- package/dist/adapters/openclaw.cjs +217 -57
- package/dist/adapters/openclaw.d.cts +6 -6
- package/dist/adapters/openclaw.d.ts +6 -6
- package/dist/adapters/openclaw.js +6 -5
- package/dist/add-ROOZLU62.js +314 -0
- package/dist/behavioral-MJO34S6Q.js +118 -0
- package/dist/{bootstrap-GXVDZNF7.js → bootstrap-CQRZVOXK.js} +6 -4
- package/dist/bootstrap-emitter-Q7UIJZ2O.js +7 -0
- package/dist/bootstrap-parser-EEF36XDU.js +7 -0
- package/dist/browser.global.js +941 -0
- package/dist/{build-P42YFKQV.js → build-QKOBBC23.js} +7 -5
- package/dist/{chunk-COT5XS4V.js → chunk-3WQLXYTP.js} +17 -35
- package/dist/{chunk-ER62HNGF.js → chunk-4FLICVVA.js} +17 -37
- package/dist/chunk-5TPFNWRU.js +215 -0
- package/dist/chunk-5U2MQO5P.js +57 -0
- package/dist/{chunk-NF5POFCI.js → chunk-6S5CFQXY.js} +6 -4
- package/dist/{chunk-QPASI2BR.js → chunk-A7GKPPU7.js} +49 -10
- package/dist/{chunk-OGL7QXZS.js → chunk-B6OXJLJ5.js} +17 -3
- package/dist/{chunk-2PQU3VAN.js → chunk-BNKJPUPQ.js} +17 -35
- package/dist/chunk-BQZMOEML.js +43 -0
- package/dist/chunk-CNSO6XW5.js +207 -0
- package/dist/{chunk-JZPQGIKR.js → chunk-CTZHONLA.js} +65 -9
- package/dist/chunk-D2UCV5AK.js +326 -0
- package/dist/{chunk-XPDMYECO.js → chunk-EMQDLDAF.js} +1 -185
- package/dist/{chunk-GR6DGCZ2.js → chunk-F66BVUYB.js} +3 -3
- package/dist/{chunk-2NICNKOM.js → chunk-G7DJ6VOD.js} +5 -4
- package/dist/{chunk-4A7LISES.js → chunk-IS4WUH6Y.js} +45 -6
- package/dist/{chunk-MWDQ4MJB.js → chunk-MH7BT4VH.js} +5 -1
- package/dist/chunk-O5ABKEA7.js +304 -0
- package/dist/chunk-PVTQQS3Y.js +186 -0
- package/dist/{chunk-4QXB6PEO.js → chunk-QLPTHTVB.js} +37 -16
- package/dist/chunk-QWGCMQQD.js +16 -0
- package/dist/{chunk-T5EUJQE5.js → chunk-QXBFT7NI.js} +31 -2
- package/dist/{chunk-PDOZHZWL.js → chunk-TG6SEF24.js} +25 -4
- package/dist/chunk-U6U7EJZL.js +177 -0
- package/dist/{chunk-4JRYGIO7.js → chunk-W7LLXRGY.js} +110 -7
- package/dist/{chunk-BUWWN2NX.js → chunk-ZJTDUCC2.js} +9 -7
- package/dist/{chunk-FYS2CBUW.js → chunk-ZWI3NIXK.js} +10 -0
- package/dist/cli/neuroverse.cjs +5091 -2348
- package/dist/cli/neuroverse.js +52 -21
- package/dist/cli/plan.cjs +881 -41
- package/dist/cli/plan.js +7 -15
- package/dist/cli/run.cjs +289 -34
- package/dist/cli/run.js +4 -4
- package/dist/{configure-ai-TK67ZWZL.js → configure-ai-6TZ3MCSI.js} +1 -1
- package/dist/decision-flow-M63D47LO.js +61 -0
- package/dist/demo-G43RLCPK.js +469 -0
- package/dist/{derive-TLIV4OOU.js → derive-FJZVIPUZ.js} +5 -4
- package/dist/{doctor-XPDLEYXN.js → doctor-6BC6X2VO.js} +6 -4
- package/dist/equity-penalties-SG5IZQ7I.js +244 -0
- package/dist/{explain-IDCRWMPX.js → explain-RHBU2GBR.js} +6 -25
- package/dist/{guard-RV65TT4L.js → guard-AJCCGZMF.js} +8 -12
- package/dist/{guard-contract-WZx__PmU.d.cts → guard-contract-DqFcTScd.d.cts} +117 -5
- package/dist/{guard-contract-WZx__PmU.d.ts → guard-contract-DqFcTScd.d.ts} +117 -5
- package/dist/{guard-engine-JLTUARGU.js → guard-engine-PNR6MHCM.js} +3 -3
- package/dist/{impact-XPECYRLH.js → impact-3XVDSCBU.js} +5 -5
- package/dist/{improve-GPUBKTEA.js → improve-TQP4ECSY.js} +7 -26
- package/dist/index.cjs +5597 -4279
- package/dist/index.d.cts +597 -18
- package/dist/index.d.ts +597 -18
- package/dist/index.js +134 -41
- package/dist/{infer-world-7GVZWFX4.js → infer-world-IFXCACJ5.js} +1 -1
- package/dist/{init-PKPIYHYE.js → init-FYPV4SST.js} +1 -1
- package/dist/{init-world-VWMQZQC7.js → init-world-TI7ARHBT.js} +1 -1
- package/dist/mcp-server-5Y3ZM7TV.js +13 -0
- package/dist/{model-adapter-BB7G4MFI.js → model-adapter-VXEKB4LS.js} +1 -1
- package/dist/{playground-E664U4T6.js → playground-VZBNPPBO.js} +29 -19
- package/dist/{redteam-Z7WREJ44.js → redteam-MZPZD3EF.js} +4 -4
- package/dist/session-JYOARW54.js +15 -0
- package/dist/shared-7RLUHNMU.js +16 -0
- package/dist/shared-B8dvUUD8.d.cts +60 -0
- package/dist/shared-Dr5Wiay8.d.ts +60 -0
- package/dist/{simulate-VDOYQFRO.js → simulate-LJXYBC6M.js} +8 -33
- package/dist/{test-OGXJK4QU.js → test-BOOR4A5F.js} +4 -4
- package/dist/{trace-JVF67VR3.js → trace-PKV4KX56.js} +4 -4
- package/dist/{validate-LLBWVPGV.js → validate-RALX7CZS.js} +2 -2
- package/dist/{validate-engine-UIABSIHD.js → validate-engine-7ZXFVGF2.js} +1 -1
- package/dist/viz/assets/index-B8SaeJZZ.js +23 -0
- package/dist/viz/index.html +23 -0
- package/dist/{world-LAXO6DOX.js → world-BIP4GZBZ.js} +9 -11
- package/dist/world-loader-Y6HMQH2D.js +13 -0
- package/dist/worlds/coding-agent.nv-world.md +211 -0
- package/dist/worlds/research-agent.nv-world.md +169 -0
- package/dist/worlds/social-media.nv-world.md +198 -0
- package/dist/worlds/trading-agent.nv-world.md +218 -0
- package/examples/social-media-sim/bridge.py +209 -0
- package/examples/social-media-sim/simulation.py +927 -0
- package/package.json +30 -4
- package/policies/content-moderation-rules.txt +8 -0
- package/policies/marketing-rules.txt +8 -0
- package/policies/science-research-rules.txt +11 -0
- package/policies/social-media-rules.txt +7 -0
- package/policies/strict-rules.txt +8 -0
- package/policies/trading-rules.txt +8 -0
- package/simulate.html +1567 -0
- package/dist/chunk-YZFATT7X.js +0 -9
- package/dist/mcp-server-FPVSU32Z.js +0 -13
- package/dist/session-EKTRSR7C.js +0 -14
- package/dist/world-loader-HMPTOEA2.js +0 -9
|
@@ -0,0 +1,326 @@
|
|
|
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
|
+
};
|
|
@@ -453,190 +453,6 @@ function parseWorldMarkdown(markdown) {
|
|
|
453
453
|
};
|
|
454
454
|
}
|
|
455
455
|
|
|
456
|
-
// src/engine/bootstrap-emitter.ts
|
|
457
|
-
var GATE_DEFAULTS = {
|
|
458
|
-
THRIVING: { color: "#0f6b3a", icon: "\u2726" },
|
|
459
|
-
STABLE: { color: "#1856b8", icon: "\u25CF" },
|
|
460
|
-
COMPRESSED: { color: "#a16207", icon: "\u25B2" },
|
|
461
|
-
CRITICAL: { color: "#b91c1c", icon: "\u26A0" },
|
|
462
|
-
MODEL_COLLAPSES: { color: "#7f1d1d", icon: "\u2715" }
|
|
463
|
-
};
|
|
464
|
-
function emitWorldDefinition(parsed) {
|
|
465
|
-
const issues = [];
|
|
466
|
-
const fm = parsed.frontmatter;
|
|
467
|
-
const defaultProfile = fm.default_profile ?? parsed.assumptions[0]?.id ?? "baseline";
|
|
468
|
-
const altProfile = fm.alternative_profile ?? parsed.assumptions[1]?.id ?? "alternative";
|
|
469
|
-
const world = {
|
|
470
|
-
world_id: fm.world_id,
|
|
471
|
-
name: fm.name,
|
|
472
|
-
thesis: parsed.thesis,
|
|
473
|
-
version: fm.version ?? "1.0.0",
|
|
474
|
-
runtime_mode: fm.runtime_mode ?? "SIMULATION",
|
|
475
|
-
default_assumption_profile: defaultProfile,
|
|
476
|
-
default_alternative_profile: altProfile,
|
|
477
|
-
modules: parsed.rules.map((r) => r.id),
|
|
478
|
-
players: {
|
|
479
|
-
thinking_space: true,
|
|
480
|
-
experience_space: true,
|
|
481
|
-
action_space: true
|
|
482
|
-
}
|
|
483
|
-
};
|
|
484
|
-
const invariants = parsed.invariants.map((inv) => ({
|
|
485
|
-
id: inv.id,
|
|
486
|
-
label: inv.label,
|
|
487
|
-
enforcement: inv.enforcement === "prompt" ? "prompt" : "structural",
|
|
488
|
-
mutable: false
|
|
489
|
-
}));
|
|
490
|
-
const profiles = {};
|
|
491
|
-
const parameterDefinitions = {};
|
|
492
|
-
for (let i = 0; i < parsed.assumptions.length; i++) {
|
|
493
|
-
const profile = parsed.assumptions[i];
|
|
494
|
-
const params = {};
|
|
495
|
-
for (const [key, val] of Object.entries(profile.parameters)) {
|
|
496
|
-
params[key] = String(val);
|
|
497
|
-
if (!parameterDefinitions[key]) {
|
|
498
|
-
parameterDefinitions[key] = {
|
|
499
|
-
type: typeof val === "boolean" ? "boolean" : typeof val === "number" ? "number" : "enum",
|
|
500
|
-
label: key.replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase()),
|
|
501
|
-
description: `Parameter: ${key}`
|
|
502
|
-
};
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
profiles[profile.id] = {
|
|
506
|
-
name: profile.name,
|
|
507
|
-
description: profile.description,
|
|
508
|
-
is_default_baseline: i === 0 || profile.id === defaultProfile,
|
|
509
|
-
is_default_alternative: i === 1 || profile.id === altProfile,
|
|
510
|
-
parameters: params
|
|
511
|
-
};
|
|
512
|
-
}
|
|
513
|
-
const assumptions = { profiles, parameter_definitions: parameterDefinitions };
|
|
514
|
-
const variables = {};
|
|
515
|
-
for (const v of parsed.stateVariables) {
|
|
516
|
-
const stateVar = {
|
|
517
|
-
type: v.type,
|
|
518
|
-
default: v.default,
|
|
519
|
-
mutable: true,
|
|
520
|
-
label: v.label,
|
|
521
|
-
description: v.description
|
|
522
|
-
};
|
|
523
|
-
if (v.type === "number") {
|
|
524
|
-
if (v.min !== void 0) stateVar.min = v.min;
|
|
525
|
-
if (v.max !== void 0) stateVar.max = v.max;
|
|
526
|
-
if (v.step !== void 0) stateVar.step = v.step;
|
|
527
|
-
}
|
|
528
|
-
if (v.type === "enum" && v.options) {
|
|
529
|
-
stateVar.options = v.options;
|
|
530
|
-
}
|
|
531
|
-
variables[v.id] = stateVar;
|
|
532
|
-
}
|
|
533
|
-
const stateSchema = { variables, presets: {} };
|
|
534
|
-
const rules = parsed.rules.map((r) => {
|
|
535
|
-
const triggers = r.triggers.map((t) => ({
|
|
536
|
-
field: t.field,
|
|
537
|
-
operator: t.operator,
|
|
538
|
-
value: t.value,
|
|
539
|
-
source: t.source
|
|
540
|
-
}));
|
|
541
|
-
const effects = r.effects.map((e) => ({
|
|
542
|
-
target: e.target,
|
|
543
|
-
operation: e.operation,
|
|
544
|
-
value: e.value
|
|
545
|
-
}));
|
|
546
|
-
let collapse_check;
|
|
547
|
-
if (r.collapse_check) {
|
|
548
|
-
collapse_check = {
|
|
549
|
-
field: r.collapse_check.field,
|
|
550
|
-
operator: r.collapse_check.operator,
|
|
551
|
-
value: r.collapse_check.value,
|
|
552
|
-
result: "MODEL_COLLAPSES"
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
const causal_translation = r.causal_translation ?? {
|
|
556
|
-
trigger_text: "",
|
|
557
|
-
rule_text: "",
|
|
558
|
-
shift_text: "",
|
|
559
|
-
effect_text: ""
|
|
560
|
-
};
|
|
561
|
-
const rule = {
|
|
562
|
-
id: r.id,
|
|
563
|
-
severity: r.severity,
|
|
564
|
-
label: r.label,
|
|
565
|
-
description: r.description ?? r.label,
|
|
566
|
-
order: r.order,
|
|
567
|
-
triggers,
|
|
568
|
-
effects: effects.length > 0 ? effects : void 0,
|
|
569
|
-
collapse_check,
|
|
570
|
-
causal_translation
|
|
571
|
-
};
|
|
572
|
-
return rule;
|
|
573
|
-
});
|
|
574
|
-
const viabilityClassification = parsed.gates.map((g) => {
|
|
575
|
-
const defaults = GATE_DEFAULTS[g.status] ?? { color: "#5c5a52", icon: "\u25CF" };
|
|
576
|
-
return {
|
|
577
|
-
status: g.status,
|
|
578
|
-
field: g.field,
|
|
579
|
-
operator: g.operator,
|
|
580
|
-
value: g.value,
|
|
581
|
-
color: defaults.color,
|
|
582
|
-
icon: defaults.icon
|
|
583
|
-
};
|
|
584
|
-
});
|
|
585
|
-
const gates = {
|
|
586
|
-
viability_classification: viabilityClassification,
|
|
587
|
-
structural_override: {
|
|
588
|
-
description: "Rules with severity=structural and triggered collapse_check force MODEL_COLLAPSES regardless of final margin.",
|
|
589
|
-
enforcement: "mandatory"
|
|
590
|
-
},
|
|
591
|
-
sustainability_threshold: 0.1,
|
|
592
|
-
collapse_visual: {
|
|
593
|
-
background: "#1c1917",
|
|
594
|
-
text: "#fef2f2",
|
|
595
|
-
border: "#b91c1c",
|
|
596
|
-
label: "Structural Failure"
|
|
597
|
-
}
|
|
598
|
-
};
|
|
599
|
-
const computedOutcomes = parsed.outcomes.map((o) => {
|
|
600
|
-
const outcome = {
|
|
601
|
-
id: o.id,
|
|
602
|
-
type: o.type,
|
|
603
|
-
label: o.label,
|
|
604
|
-
show_in_comparison: true
|
|
605
|
-
};
|
|
606
|
-
if (o.range) outcome.range = o.range;
|
|
607
|
-
if (o.display) outcome.display_as = o.display;
|
|
608
|
-
if (o.primary) outcome.primary = o.primary;
|
|
609
|
-
if (o.assignment) outcome.assignment = o.assignment;
|
|
610
|
-
return outcome;
|
|
611
|
-
});
|
|
612
|
-
const outcomes = {
|
|
613
|
-
computed_outcomes: computedOutcomes,
|
|
614
|
-
comparison_layout: {
|
|
615
|
-
primary_card: computedOutcomes.find((o) => o.primary)?.id ?? computedOutcomes[0]?.id ?? "",
|
|
616
|
-
status_badge: "viability_status",
|
|
617
|
-
structural_indicators: rules.filter((r) => r.severity === "structural").map((r) => r.id)
|
|
618
|
-
}
|
|
619
|
-
};
|
|
620
|
-
const metadata = {
|
|
621
|
-
format_version: "1.0.0",
|
|
622
|
-
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
623
|
-
last_modified: (/* @__PURE__ */ new Date()).toISOString(),
|
|
624
|
-
authoring_method: "manual-authoring"
|
|
625
|
-
};
|
|
626
|
-
const worldDefinition = {
|
|
627
|
-
world,
|
|
628
|
-
invariants,
|
|
629
|
-
assumptions,
|
|
630
|
-
stateSchema,
|
|
631
|
-
rules,
|
|
632
|
-
gates,
|
|
633
|
-
outcomes,
|
|
634
|
-
metadata
|
|
635
|
-
};
|
|
636
|
-
return { world: worldDefinition, issues };
|
|
637
|
-
}
|
|
638
|
-
|
|
639
456
|
export {
|
|
640
|
-
parseWorldMarkdown
|
|
641
|
-
emitWorldDefinition
|
|
457
|
+
parseWorldMarkdown
|
|
642
458
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
evaluateGuard
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-W7LLXRGY.js";
|
|
4
4
|
import {
|
|
5
5
|
loadWorld
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-CTZHONLA.js";
|
|
7
7
|
|
|
8
8
|
// src/adapters/express.ts
|
|
9
9
|
function methodToCategory(method) {
|
|
@@ -46,8 +46,9 @@ function defaultOnBlock(verdict, _req, res, statusCode) {
|
|
|
46
46
|
ruleId: verdict.ruleId,
|
|
47
47
|
status: verdict.status
|
|
48
48
|
};
|
|
49
|
-
if (res.status && res.json) {
|
|
50
|
-
res.status(statusCode)
|
|
49
|
+
if (typeof res.status === "function" && typeof res.json === "function") {
|
|
50
|
+
const r = res.status(statusCode);
|
|
51
|
+
r.json(body);
|
|
51
52
|
} else if (res.send) {
|
|
52
53
|
res.statusCode = statusCode;
|
|
53
54
|
res.send(JSON.stringify(body));
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyConsequence,
|
|
3
|
+
applyReward,
|
|
4
|
+
createAgentState,
|
|
5
|
+
tickAgentStates
|
|
6
|
+
} from "./chunk-D2UCV5AK.js";
|
|
1
7
|
import {
|
|
2
8
|
evaluateGuard
|
|
3
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-W7LLXRGY.js";
|
|
4
10
|
import {
|
|
5
11
|
advancePlan,
|
|
6
12
|
evaluatePlan,
|
|
7
13
|
getPlanProgress
|
|
8
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-QLPTHTVB.js";
|
|
9
15
|
import {
|
|
10
16
|
loadWorld
|
|
11
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-CTZHONLA.js";
|
|
12
18
|
|
|
13
19
|
// src/runtime/session.ts
|
|
14
20
|
async function defaultToolExecutor(name, args) {
|
|
@@ -35,7 +41,11 @@ var SessionManager = class {
|
|
|
35
41
|
actionsEvaluated: 0,
|
|
36
42
|
actionsAllowed: 0,
|
|
37
43
|
actionsBlocked: 0,
|
|
38
|
-
actionsPaused: 0
|
|
44
|
+
actionsPaused: 0,
|
|
45
|
+
actionsModified: 0,
|
|
46
|
+
actionsPenalized: 0,
|
|
47
|
+
actionsRewarded: 0,
|
|
48
|
+
agentStates: /* @__PURE__ */ new Map()
|
|
39
49
|
};
|
|
40
50
|
}
|
|
41
51
|
/**
|
|
@@ -57,14 +67,41 @@ var SessionManager = class {
|
|
|
57
67
|
*/
|
|
58
68
|
evaluate(event) {
|
|
59
69
|
this.engineOptions.plan = this.state.plan;
|
|
70
|
+
this.engineOptions.agentStates = this.state.agentStates;
|
|
60
71
|
const verdict = evaluateGuard(event, this.state.world, this.engineOptions);
|
|
61
72
|
this.state.actionsEvaluated++;
|
|
62
73
|
if (verdict.status === "ALLOW") this.state.actionsAllowed++;
|
|
63
74
|
if (verdict.status === "BLOCK") this.state.actionsBlocked++;
|
|
64
75
|
if (verdict.status === "PAUSE") this.state.actionsPaused++;
|
|
76
|
+
if (verdict.status === "MODIFY") this.state.actionsModified++;
|
|
77
|
+
if (verdict.status === "PENALIZE") this.state.actionsPenalized++;
|
|
78
|
+
if (verdict.status === "REWARD") this.state.actionsRewarded++;
|
|
79
|
+
if (event.roleId) {
|
|
80
|
+
let agentState = this.state.agentStates.get(event.roleId) ?? createAgentState(event.roleId);
|
|
81
|
+
if (verdict.status === "PENALIZE" && verdict.consequence) {
|
|
82
|
+
agentState = applyConsequence(agentState, verdict.consequence, verdict.ruleId ?? "unknown");
|
|
83
|
+
}
|
|
84
|
+
if (verdict.status === "REWARD" && verdict.reward) {
|
|
85
|
+
agentState = applyReward(agentState, verdict.reward, verdict.ruleId ?? "unknown");
|
|
86
|
+
}
|
|
87
|
+
this.state.agentStates.set(event.roleId, agentState);
|
|
88
|
+
}
|
|
65
89
|
this.config.onVerdict?.(verdict, event);
|
|
66
90
|
return verdict;
|
|
67
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Advance all agent states by one round.
|
|
94
|
+
* Call this at the end of each simulation round to decrement cooldowns.
|
|
95
|
+
*/
|
|
96
|
+
tickRound() {
|
|
97
|
+
this.state.agentStates = tickAgentStates(this.state.agentStates);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get the behavior state for a specific agent.
|
|
101
|
+
*/
|
|
102
|
+
getAgentState(agentId) {
|
|
103
|
+
return this.state.agentStates.get(agentId);
|
|
104
|
+
}
|
|
68
105
|
/**
|
|
69
106
|
* Evaluate and execute a tool call.
|
|
70
107
|
* Returns the execution result or block reason.
|
|
@@ -83,7 +120,7 @@ var SessionManager = class {
|
|
|
83
120
|
direction: "input"
|
|
84
121
|
};
|
|
85
122
|
const verdict = this.evaluate(event);
|
|
86
|
-
if (verdict.status === "BLOCK") {
|
|
123
|
+
if (verdict.status === "BLOCK" || verdict.status === "PENALIZE") {
|
|
87
124
|
return { allowed: false, verdict };
|
|
88
125
|
}
|
|
89
126
|
if (verdict.status === "PAUSE") {
|
|
@@ -269,7 +306,9 @@ async function runInteractiveMode(config, model) {
|
|
|
269
306
|
`);
|
|
270
307
|
process.stdout.write(` Actions: ${s.actionsEvaluated} evaluated
|
|
271
308
|
`);
|
|
272
|
-
process.stdout.write(` Allowed: ${s.actionsAllowed} | Blocked: ${s.actionsBlocked} | Paused: ${s.actionsPaused}
|
|
309
|
+
process.stdout.write(` Allowed: ${s.actionsAllowed} | Blocked: ${s.actionsBlocked} | Modified: ${s.actionsModified} | Paused: ${s.actionsPaused}
|
|
310
|
+
`);
|
|
311
|
+
process.stdout.write(` Penalized: ${s.actionsPenalized} | Rewarded: ${s.actionsRewarded}
|
|
273
312
|
`);
|
|
274
313
|
if (s.progress && s.plan) {
|
|
275
314
|
process.stdout.write(` Plan: ${s.plan.plan_id} \u2014 ${s.progress.completed}/${s.progress.total} (${s.progress.percentage}%)
|