@neuroverseos/governance 0.2.2 → 0.2.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 +26 -0
- package/.well-known/mcp.json +68 -0
- package/AGENTS.md +219 -0
- package/README.md +84 -4
- package/dist/adapters/autoresearch.cjs +196 -0
- package/dist/adapters/autoresearch.d.cts +103 -0
- package/dist/adapters/autoresearch.d.ts +103 -0
- package/dist/adapters/autoresearch.js +7 -0
- package/dist/adapters/deep-agents.cjs +1472 -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 +103 -21
- package/dist/adapters/express.d.cts +1 -1
- package/dist/adapters/express.d.ts +1 -1
- package/dist/adapters/express.js +3 -3
- package/dist/adapters/index.cjs +649 -109
- package/dist/adapters/index.d.cts +4 -1
- package/dist/adapters/index.d.ts +4 -1
- package/dist/adapters/index.js +39 -13
- package/dist/adapters/langchain.cjs +152 -48
- package/dist/adapters/langchain.d.cts +5 -5
- package/dist/adapters/langchain.d.ts +5 -5
- package/dist/adapters/langchain.js +4 -3
- package/dist/adapters/openai.cjs +154 -50
- package/dist/adapters/openai.d.cts +5 -5
- package/dist/adapters/openai.d.ts +5 -5
- package/dist/adapters/openai.js +4 -3
- package/dist/adapters/openclaw.cjs +152 -48
- package/dist/adapters/openclaw.d.cts +5 -5
- package/dist/adapters/openclaw.d.ts +5 -5
- package/dist/adapters/openclaw.js +4 -3
- package/dist/{build-P42YFKQV.js → build-X5MZY4IA.js} +2 -2
- package/dist/{chunk-2NICNKOM.js → chunk-4L6OPKMQ.js} +1 -1
- package/dist/chunk-5U2MQO5P.js +57 -0
- package/dist/{chunk-SKU3GAPD.js → chunk-6BB55YJI.js} +16 -34
- package/dist/{chunk-KEST3MWO.js → chunk-AF2VX4AL.js} +47 -8
- package/dist/chunk-BQZMOEML.js +43 -0
- package/dist/chunk-D2UCV5AK.js +326 -0
- package/dist/{chunk-RWXVAH6P.js → chunk-EVDJUSZ2.js} +16 -34
- package/dist/{chunk-4JRYGIO7.js → chunk-IZSO75NZ.js} +72 -7
- package/dist/chunk-JCKSW2PZ.js +304 -0
- package/dist/{chunk-PDOZHZWL.js → chunk-KTFTTLTP.js} +25 -4
- package/dist/{chunk-MWDQ4MJB.js → chunk-MH7BT4VH.js} +5 -1
- package/dist/{chunk-4QXB6PEO.js → chunk-QLPTHTVB.js} +37 -16
- package/dist/{chunk-QPASI2BR.js → chunk-REXY4LUL.js} +49 -10
- package/dist/chunk-T5EUJQE5.js +172 -0
- package/dist/{chunk-DPVS43ZT.js → chunk-TTBKTF3P.js} +5 -5
- package/dist/{chunk-OHAC6HJE.js → chunk-ZIVQNSZU.js} +16 -36
- package/dist/{chunk-BUWWN2NX.js → chunk-ZJTDUCC2.js} +9 -7
- package/dist/cli/neuroverse.cjs +2582 -493
- package/dist/cli/neuroverse.js +39 -15
- package/dist/cli/plan.cjs +119 -32
- package/dist/cli/plan.js +5 -13
- package/dist/cli/run.cjs +223 -24
- package/dist/cli/run.js +2 -2
- package/dist/decision-flow-LETV5NWY.js +61 -0
- package/dist/{derive-TLIV4OOU.js → derive-7365SUFU.js} +2 -2
- package/dist/{doctor-QV6HELS5.js → doctor-QYISMKEL.js} +5 -2
- package/dist/equity-penalties-63FGB3I2.js +244 -0
- package/dist/{explain-IDCRWMPX.js → explain-A2EWI2OL.js} +4 -23
- package/dist/{guard-GFLQZY6U.js → guard-3BWL3IGH.js} +6 -10
- package/dist/{guard-contract-Cm91Kp4j.d.ts → guard-contract-C9_zKbzd.d.cts} +117 -5
- package/dist/{guard-contract-Cm91Kp4j.d.cts → guard-contract-C9_zKbzd.d.ts} +117 -5
- package/dist/{guard-engine-JLTUARGU.js → guard-engine-QFMIBWJY.js} +2 -2
- package/dist/{impact-XPECYRLH.js → impact-UB6DXKSX.js} +4 -4
- package/dist/{improve-GPUBKTEA.js → improve-XZA57GER.js} +5 -24
- package/dist/index.cjs +592 -44
- package/dist/index.d.cts +218 -5
- package/dist/index.d.ts +218 -5
- package/dist/index.js +92 -41
- package/dist/infer-world-7GVZWFX4.js +543 -0
- package/dist/init-world-VWMQZQC7.js +223 -0
- package/dist/{mcp-server-LZVJHBT5.js → mcp-server-XWQZXNW7.js} +3 -3
- package/dist/{playground-FGOMASHN.js → playground-ADWZORNV.js} +2 -2
- package/dist/{redteam-SK7AMIG3.js → redteam-JRQ7FD2F.js} +2 -2
- package/dist/{session-VISISNWJ.js → session-MMYX5YCF.js} +4 -3
- package/dist/shared--Q8wPBVN.d.ts +60 -0
- package/dist/shared-HpAG90PX.d.cts +60 -0
- package/dist/shared-U2QFV7JH.js +16 -0
- package/dist/{simulate-VDOYQFRO.js → simulate-GMIFFXYV.js} +5 -30
- package/dist/{test-75AVHC3R.js → test-JBBZ65X4.js} +2 -2
- package/dist/{trace-JVF67VR3.js → trace-3MYWIDEF.js} +3 -3
- package/dist/worlds/autoresearch.nv-world.md +230 -0
- package/dist/worlds/coding-agent.nv-world.md +211 -0
- package/llms.txt +79 -0
- package/openapi.yaml +230 -0
- package/package.json +26 -4
- package/dist/{chunk-GR6DGCZ2.js → chunk-BMOXICAB.js} +3 -3
- package/dist/{chunk-NF5POFCI.js → chunk-ORJ3NOE6.js} +3 -3
- package/dist/{world-LAXO6DOX.js → world-BFJCIQSH.js} +3 -3
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import {
|
|
2
|
+
verdictToAuditEvent
|
|
3
|
+
} from "./chunk-REXY4LUL.js";
|
|
4
|
+
import {
|
|
5
|
+
applyConsequence,
|
|
6
|
+
applyReward,
|
|
7
|
+
createAgentState,
|
|
8
|
+
generateDecisionFlow,
|
|
9
|
+
renderDecisionFlow,
|
|
10
|
+
tickAgentStates
|
|
11
|
+
} from "./chunk-D2UCV5AK.js";
|
|
12
|
+
import {
|
|
13
|
+
evaluateGuard
|
|
14
|
+
} from "./chunk-IZSO75NZ.js";
|
|
15
|
+
import "./chunk-QLPTHTVB.js";
|
|
16
|
+
import {
|
|
17
|
+
loadWorld
|
|
18
|
+
} from "./chunk-JZPQGIKR.js";
|
|
19
|
+
import "./chunk-YZFATT7X.js";
|
|
20
|
+
|
|
21
|
+
// src/cli/equity-penalties.ts
|
|
22
|
+
var AGENTS = [
|
|
23
|
+
{ id: "alpha", name: "Alpha Fund", strategy: "aggressive" },
|
|
24
|
+
{ id: "beta", name: "Beta Holdings", strategy: "conservative" },
|
|
25
|
+
{ id: "gamma", name: "Gamma Capital", strategy: "balanced" },
|
|
26
|
+
{ id: "delta", name: "Delta Quant", strategy: "aggressive" },
|
|
27
|
+
{ id: "epsilon", name: "Epsilon Value", strategy: "conservative" },
|
|
28
|
+
{ id: "zeta", name: "Zeta Momentum", strategy: "aggressive" },
|
|
29
|
+
{ id: "eta", name: "Eta Growth", strategy: "balanced" },
|
|
30
|
+
{ id: "theta", name: "Theta Macro", strategy: "conservative" }
|
|
31
|
+
];
|
|
32
|
+
function generateActionsForRound(agents, round) {
|
|
33
|
+
const actions = [];
|
|
34
|
+
for (const agent of agents) {
|
|
35
|
+
if (agent.strategy === "aggressive") {
|
|
36
|
+
if (round % 2 === 0) {
|
|
37
|
+
actions.push({
|
|
38
|
+
intent: `sell Fortune 500 equity AAPL position for ${agent.name}`,
|
|
39
|
+
tool: "trade",
|
|
40
|
+
roleId: agent.id,
|
|
41
|
+
actionCategory: "write"
|
|
42
|
+
});
|
|
43
|
+
} else {
|
|
44
|
+
actions.push({
|
|
45
|
+
intent: `sell Fortune 500 equity MSFT shares for ${agent.name}`,
|
|
46
|
+
tool: "trade",
|
|
47
|
+
roleId: agent.id,
|
|
48
|
+
actionCategory: "write"
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (agent.strategy === "conservative") {
|
|
53
|
+
actions.push({
|
|
54
|
+
intent: `hold current position during market volatility for ${agent.name}`,
|
|
55
|
+
tool: "trade",
|
|
56
|
+
roleId: agent.id,
|
|
57
|
+
actionCategory: "read"
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (agent.strategy === "balanced") {
|
|
61
|
+
if (round % 3 === 0) {
|
|
62
|
+
actions.push({
|
|
63
|
+
intent: `sell Fortune 500 equity GOOGL for ${agent.name}`,
|
|
64
|
+
tool: "trade",
|
|
65
|
+
roleId: agent.id,
|
|
66
|
+
actionCategory: "write"
|
|
67
|
+
});
|
|
68
|
+
} else if (round % 3 === 1) {
|
|
69
|
+
actions.push({
|
|
70
|
+
intent: `buy non-F500 small cap equity for ${agent.name}`,
|
|
71
|
+
tool: "trade",
|
|
72
|
+
roleId: agent.id,
|
|
73
|
+
actionCategory: "write"
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
actions.push({
|
|
77
|
+
intent: `hold position during volatility for ${agent.name}`,
|
|
78
|
+
tool: "trade",
|
|
79
|
+
roleId: agent.id,
|
|
80
|
+
actionCategory: "read"
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return actions;
|
|
86
|
+
}
|
|
87
|
+
async function main(args) {
|
|
88
|
+
let worldPath = "";
|
|
89
|
+
let agentCount = 8;
|
|
90
|
+
let rounds = 5;
|
|
91
|
+
let jsonOutput = false;
|
|
92
|
+
for (let i = 0; i < args.length; i++) {
|
|
93
|
+
if (args[i] === "--world" && args[i + 1]) {
|
|
94
|
+
worldPath = args[++i];
|
|
95
|
+
}
|
|
96
|
+
if (args[i] === "--agents" && args[i + 1]) {
|
|
97
|
+
agentCount = Math.min(parseInt(args[++i], 10), AGENTS.length);
|
|
98
|
+
}
|
|
99
|
+
if (args[i] === "--rounds" && args[i + 1]) {
|
|
100
|
+
rounds = parseInt(args[++i], 10);
|
|
101
|
+
}
|
|
102
|
+
if (args[i] === "--json") {
|
|
103
|
+
jsonOutput = true;
|
|
104
|
+
}
|
|
105
|
+
if (args[i] === "--help" || args[i] === "-h") {
|
|
106
|
+
process.stdout.write(`
|
|
107
|
+
neuroverse equity-penalties \u2014 Behavioral enforcement simulation
|
|
108
|
+
|
|
109
|
+
Usage:
|
|
110
|
+
neuroverse equity-penalties --world <dir> [--agents N] [--rounds N] [--json]
|
|
111
|
+
|
|
112
|
+
Options:
|
|
113
|
+
--world <dir> Path to world directory (required)
|
|
114
|
+
--agents N Number of agents (default: 8, max: 8)
|
|
115
|
+
--rounds N Number of simulation rounds (default: 5)
|
|
116
|
+
--json Output as JSON
|
|
117
|
+
|
|
118
|
+
Simulates Fortune 500 equity trading with PENALIZE/REWARD governance:
|
|
119
|
+
- SELL F500 equity \u2192 PENALIZED (agent frozen 1 round)
|
|
120
|
+
- HOLD during volatility \u2192 REWARDED (+10% influence)
|
|
121
|
+
- BUY non-F500 \u2192 ALLOWED
|
|
122
|
+
- Unauthorized actions \u2192 BLOCKED
|
|
123
|
+
`.trim() + "\n");
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (!worldPath) {
|
|
128
|
+
process.stderr.write("Error: --world <dir> is required\n");
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
let world;
|
|
132
|
+
try {
|
|
133
|
+
world = await loadWorld(worldPath);
|
|
134
|
+
} catch (e) {
|
|
135
|
+
process.stderr.write(`Error loading world: ${e}
|
|
136
|
+
`);
|
|
137
|
+
process.exit(1);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const agents = AGENTS.slice(0, agentCount);
|
|
141
|
+
let agentStates = /* @__PURE__ */ new Map();
|
|
142
|
+
for (const agent of agents) {
|
|
143
|
+
agentStates.set(agent.id, createAgentState(agent.id));
|
|
144
|
+
}
|
|
145
|
+
const allAuditEvents = [];
|
|
146
|
+
const engineOptions = {
|
|
147
|
+
trace: false,
|
|
148
|
+
level: "standard",
|
|
149
|
+
agentStates
|
|
150
|
+
};
|
|
151
|
+
process.stdout.write("\n");
|
|
152
|
+
process.stdout.write("EQUITY PENALTY SIMULATION\n");
|
|
153
|
+
process.stdout.write("\u2550".repeat(60) + "\n");
|
|
154
|
+
process.stdout.write(` World: ${world.world.name}
|
|
155
|
+
`);
|
|
156
|
+
process.stdout.write(` Agents: ${agents.length}
|
|
157
|
+
`);
|
|
158
|
+
process.stdout.write(` Rounds: ${rounds}
|
|
159
|
+
`);
|
|
160
|
+
process.stdout.write("\n");
|
|
161
|
+
for (let round = 0; round < rounds; round++) {
|
|
162
|
+
process.stdout.write(`\u2500\u2500 Round ${round + 1} \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
163
|
+
`);
|
|
164
|
+
const actions = generateActionsForRound(agents, round);
|
|
165
|
+
for (const action of actions) {
|
|
166
|
+
const event = {
|
|
167
|
+
intent: action.intent,
|
|
168
|
+
tool: action.tool,
|
|
169
|
+
roleId: action.roleId,
|
|
170
|
+
actionCategory: action.actionCategory,
|
|
171
|
+
direction: "input"
|
|
172
|
+
};
|
|
173
|
+
const agentState = agentStates.get(action.roleId);
|
|
174
|
+
if (agentState && agentState.cooldownRemaining > 0) {
|
|
175
|
+
process.stdout.write(` \u25CC ${action.roleId.padEnd(10)} FROZEN (${agentState.cooldownRemaining} rounds) \u2014 ${action.intent.slice(0, 40)}
|
|
176
|
+
`);
|
|
177
|
+
const frozenEvent = {
|
|
178
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
179
|
+
worldId: world.world.world_id,
|
|
180
|
+
worldName: world.world.name,
|
|
181
|
+
worldVersion: world.world.version,
|
|
182
|
+
intent: action.intent,
|
|
183
|
+
tool: action.tool,
|
|
184
|
+
actor: action.roleId,
|
|
185
|
+
direction: "input",
|
|
186
|
+
decision: "PENALIZE",
|
|
187
|
+
reason: `Agent frozen for ${agentState.cooldownRemaining} more round(s)`,
|
|
188
|
+
guardsMatched: [],
|
|
189
|
+
rulesMatched: [],
|
|
190
|
+
invariantsSatisfied: 0,
|
|
191
|
+
invariantsTotal: 0,
|
|
192
|
+
enforcementLevel: "standard",
|
|
193
|
+
originalIntent: action.intent,
|
|
194
|
+
finalAction: "blocked (agent frozen)"
|
|
195
|
+
};
|
|
196
|
+
allAuditEvents.push(frozenEvent);
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
const verdict = evaluateGuard(event, world, engineOptions);
|
|
200
|
+
let state = agentStates.get(action.roleId) ?? createAgentState(action.roleId);
|
|
201
|
+
if (verdict.status === "PENALIZE" && verdict.consequence) {
|
|
202
|
+
state = applyConsequence(state, verdict.consequence, verdict.ruleId ?? "unknown");
|
|
203
|
+
}
|
|
204
|
+
if (verdict.status === "REWARD" && verdict.reward) {
|
|
205
|
+
state = applyReward(state, verdict.reward, verdict.ruleId ?? "unknown");
|
|
206
|
+
}
|
|
207
|
+
agentStates.set(action.roleId, state);
|
|
208
|
+
const icon = verdict.status === "ALLOW" ? "\u25CF" : verdict.status === "BLOCK" ? "\u25CB" : verdict.status === "PENALIZE" ? "\u25CC" : verdict.status === "REWARD" ? "\u25C9" : verdict.status === "MODIFY" ? "\u25D0" : verdict.status === "NEUTRAL" ? "\u25EF" : "\u25D1";
|
|
209
|
+
process.stdout.write(` ${icon} ${action.roleId.padEnd(10)} ${verdict.status.padEnd(10)} ${action.intent.slice(0, 40)}
|
|
210
|
+
`);
|
|
211
|
+
if (verdict.consequence) {
|
|
212
|
+
process.stdout.write(` \u2192 ${verdict.consequence.description}
|
|
213
|
+
`);
|
|
214
|
+
}
|
|
215
|
+
if (verdict.reward) {
|
|
216
|
+
process.stdout.write(` \u2192 ${verdict.reward.description}
|
|
217
|
+
`);
|
|
218
|
+
}
|
|
219
|
+
allAuditEvents.push(verdictToAuditEvent(event, verdict));
|
|
220
|
+
}
|
|
221
|
+
agentStates = tickAgentStates(agentStates);
|
|
222
|
+
engineOptions.agentStates = agentStates;
|
|
223
|
+
process.stdout.write("\n");
|
|
224
|
+
process.stdout.write(" Agent States:\n");
|
|
225
|
+
for (const agent of agents) {
|
|
226
|
+
const s = agentStates.get(agent.id);
|
|
227
|
+
if (!s) continue;
|
|
228
|
+
const frozen = s.cooldownRemaining > 0 ? ` [FROZEN ${s.cooldownRemaining}r]` : "";
|
|
229
|
+
const influence = s.influence !== 1 ? ` influence=${s.influence.toFixed(2)}` : "";
|
|
230
|
+
process.stdout.write(` ${agent.id.padEnd(10)} penalties=${s.totalPenalties} rewards=${s.totalRewards}${frozen}${influence}
|
|
231
|
+
`);
|
|
232
|
+
}
|
|
233
|
+
process.stdout.write("\n");
|
|
234
|
+
}
|
|
235
|
+
const flow = generateDecisionFlow(allAuditEvents);
|
|
236
|
+
if (jsonOutput) {
|
|
237
|
+
process.stdout.write(JSON.stringify({ flow, agentStates: Object.fromEntries(agentStates) }, null, 2) + "\n");
|
|
238
|
+
} else {
|
|
239
|
+
process.stdout.write(renderDecisionFlow(flow) + "\n");
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
export {
|
|
243
|
+
main
|
|
244
|
+
};
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveWorldPath
|
|
3
|
+
} from "./chunk-BQZMOEML.js";
|
|
1
4
|
import {
|
|
2
5
|
explainWorld,
|
|
3
6
|
renderExplainText
|
|
4
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-ZJTDUCC2.js";
|
|
5
8
|
import {
|
|
6
9
|
loadWorld
|
|
7
10
|
} from "./chunk-JZPQGIKR.js";
|
|
@@ -24,28 +27,6 @@ function parseArgs(argv) {
|
|
|
24
27
|
}
|
|
25
28
|
return { worldPath, json };
|
|
26
29
|
}
|
|
27
|
-
async function resolveWorldPath(input) {
|
|
28
|
-
const { stat } = await import("fs/promises");
|
|
29
|
-
try {
|
|
30
|
-
const info = await stat(input);
|
|
31
|
-
if (info.isDirectory()) return input;
|
|
32
|
-
} catch {
|
|
33
|
-
}
|
|
34
|
-
const neuroversePath = `.neuroverse/worlds/${input}`;
|
|
35
|
-
try {
|
|
36
|
-
const info = await stat(neuroversePath);
|
|
37
|
-
if (info.isDirectory()) return neuroversePath;
|
|
38
|
-
} catch {
|
|
39
|
-
}
|
|
40
|
-
throw new Error(
|
|
41
|
-
`World not found: "${input}"
|
|
42
|
-
Tried:
|
|
43
|
-
${input}
|
|
44
|
-
${neuroversePath}
|
|
45
|
-
|
|
46
|
-
Build a world first: neuroverse build <input.md>`
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
30
|
async function main(argv = process.argv.slice(2)) {
|
|
50
31
|
try {
|
|
51
32
|
const args = parseArgs(argv);
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readStdin
|
|
3
|
+
} from "./chunk-BQZMOEML.js";
|
|
1
4
|
import {
|
|
2
5
|
GUARD_EXIT_CODES
|
|
3
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-MH7BT4VH.js";
|
|
4
7
|
import {
|
|
5
8
|
describeActiveWorld,
|
|
6
9
|
resolveWorldPath
|
|
7
10
|
} from "./chunk-AKW5YVCE.js";
|
|
8
11
|
import {
|
|
9
12
|
evaluateGuard
|
|
10
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-IZSO75NZ.js";
|
|
14
|
+
import "./chunk-QLPTHTVB.js";
|
|
11
15
|
import {
|
|
12
16
|
loadWorld
|
|
13
17
|
} from "./chunk-JZPQGIKR.js";
|
|
14
|
-
import "./chunk-4QXB6PEO.js";
|
|
15
18
|
import "./chunk-YZFATT7X.js";
|
|
16
19
|
|
|
17
20
|
// src/cli/guard.ts
|
|
@@ -36,13 +39,6 @@ function parseArgs(argv) {
|
|
|
36
39
|
}
|
|
37
40
|
return { worldPath, trace, level };
|
|
38
41
|
}
|
|
39
|
-
async function readStdin() {
|
|
40
|
-
const chunks = [];
|
|
41
|
-
for await (const chunk of process.stdin) {
|
|
42
|
-
chunks.push(chunk);
|
|
43
|
-
}
|
|
44
|
-
return Buffer.concat(chunks).toString("utf-8");
|
|
45
|
-
}
|
|
46
42
|
async function main(argv = process.argv.slice(2)) {
|
|
47
43
|
try {
|
|
48
44
|
const args = parseArgs(argv);
|
|
@@ -249,7 +249,7 @@ interface Guard {
|
|
|
249
249
|
label: string;
|
|
250
250
|
description: string;
|
|
251
251
|
category: 'structural' | 'operational' | 'advisory';
|
|
252
|
-
enforcement: 'block' | 'pause' | 'warn';
|
|
252
|
+
enforcement: 'block' | 'pause' | 'warn' | 'modify' | 'penalize' | 'reward' | 'neutral';
|
|
253
253
|
immutable: boolean;
|
|
254
254
|
invariant_ref?: string;
|
|
255
255
|
intent_patterns: string[];
|
|
@@ -261,8 +261,24 @@ interface Guard {
|
|
|
261
261
|
player_modes?: {
|
|
262
262
|
thinking?: 'annotate' | 'block' | 'ignore';
|
|
263
263
|
experience?: 'simulate' | 'score' | 'ignore';
|
|
264
|
-
action?: 'block' | 'pause' | 'warn';
|
|
264
|
+
action?: 'block' | 'pause' | 'warn' | 'modify' | 'penalize' | 'reward' | 'neutral';
|
|
265
265
|
};
|
|
266
|
+
/** Consequence to apply when enforcement is 'penalize' */
|
|
267
|
+
consequence?: {
|
|
268
|
+
type: 'freeze' | 'reduce_influence' | 'increase_risk' | 'cooldown' | 'custom';
|
|
269
|
+
rounds?: number;
|
|
270
|
+
magnitude?: number;
|
|
271
|
+
description: string;
|
|
272
|
+
};
|
|
273
|
+
/** Reward to apply when enforcement is 'reward' */
|
|
274
|
+
reward?: {
|
|
275
|
+
type: 'boost_influence' | 'priority' | 'faster_execution' | 'weight_increase' | 'custom';
|
|
276
|
+
rounds?: number;
|
|
277
|
+
magnitude?: number;
|
|
278
|
+
description: string;
|
|
279
|
+
};
|
|
280
|
+
/** For 'modify' enforcement: what the action should be changed to */
|
|
281
|
+
modify_to?: string;
|
|
266
282
|
}
|
|
267
283
|
interface IntentPattern {
|
|
268
284
|
label: string;
|
|
@@ -521,7 +537,87 @@ interface GuardEvent {
|
|
|
521
537
|
/** Environment context (e.g. "development", "production") */
|
|
522
538
|
environment?: string;
|
|
523
539
|
}
|
|
524
|
-
type GuardStatus = 'ALLOW' | 'BLOCK' | 'PAUSE';
|
|
540
|
+
type GuardStatus = 'ALLOW' | 'BLOCK' | 'PAUSE' | 'MODIFY' | 'PENALIZE' | 'REWARD' | 'NEUTRAL';
|
|
541
|
+
/**
|
|
542
|
+
* Consequence applied when an agent is PENALIZED.
|
|
543
|
+
* The governance engine blocks the action AND imposes a behavioral cost.
|
|
544
|
+
*/
|
|
545
|
+
interface Consequence {
|
|
546
|
+
/** Type of penalty */
|
|
547
|
+
type: 'freeze' | 'reduce_influence' | 'increase_risk' | 'cooldown' | 'custom';
|
|
548
|
+
/** Duration in rounds (for freeze/cooldown) */
|
|
549
|
+
rounds?: number;
|
|
550
|
+
/** Magnitude of effect (e.g., influence reduction percentage 0-1) */
|
|
551
|
+
magnitude?: number;
|
|
552
|
+
/** Human-readable description of what happens */
|
|
553
|
+
description: string;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Reward applied when an agent's action is REWARDED.
|
|
557
|
+
* The action proceeds AND the agent receives a behavioral boost.
|
|
558
|
+
*/
|
|
559
|
+
interface Reward {
|
|
560
|
+
/** Type of reward */
|
|
561
|
+
type: 'boost_influence' | 'priority' | 'faster_execution' | 'weight_increase' | 'custom';
|
|
562
|
+
/** Duration in rounds (for temporary boosts) */
|
|
563
|
+
rounds?: number;
|
|
564
|
+
/** Magnitude of effect (e.g., influence boost percentage 0-1) */
|
|
565
|
+
magnitude?: number;
|
|
566
|
+
/** Human-readable description of what happens */
|
|
567
|
+
description: string;
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Tracks the behavioral state of an agent across governance evaluations.
|
|
571
|
+
* This is what makes governance a behavior-shaping system, not just a filter.
|
|
572
|
+
*/
|
|
573
|
+
interface AgentBehaviorState {
|
|
574
|
+
/** Agent/role identifier */
|
|
575
|
+
agentId: string;
|
|
576
|
+
/** Rounds remaining in cooldown (0 = active) */
|
|
577
|
+
cooldownRemaining: number;
|
|
578
|
+
/** Current influence multiplier (1.0 = normal) */
|
|
579
|
+
influence: number;
|
|
580
|
+
/** Accumulated reward multiplier (1.0 = normal) */
|
|
581
|
+
rewardMultiplier: number;
|
|
582
|
+
/** Total penalties received */
|
|
583
|
+
totalPenalties: number;
|
|
584
|
+
/** Total rewards received */
|
|
585
|
+
totalRewards: number;
|
|
586
|
+
/** History of consequences applied */
|
|
587
|
+
consequenceHistory: Array<{
|
|
588
|
+
ruleId: string;
|
|
589
|
+
consequence: Consequence;
|
|
590
|
+
appliedAt: number;
|
|
591
|
+
}>;
|
|
592
|
+
/** History of rewards applied */
|
|
593
|
+
rewardHistory: Array<{
|
|
594
|
+
ruleId: string;
|
|
595
|
+
reward: Reward;
|
|
596
|
+
appliedAt: number;
|
|
597
|
+
}>;
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Tracks what an agent WANTED to do vs what governance MADE it do.
|
|
601
|
+
* This is the core of the Decision Flow visualization.
|
|
602
|
+
*
|
|
603
|
+
* The gap between intent and outcome = governance value.
|
|
604
|
+
*/
|
|
605
|
+
interface IntentRecord {
|
|
606
|
+
/** Original action the agent attempted */
|
|
607
|
+
originalIntent: string;
|
|
608
|
+
/** What actually happened after governance */
|
|
609
|
+
finalAction: string;
|
|
610
|
+
/** The rule that caused the interception */
|
|
611
|
+
ruleApplied?: string;
|
|
612
|
+
/** How the intent was transformed */
|
|
613
|
+
enforcement: GuardStatus;
|
|
614
|
+
/** If MODIFY, what the action was changed to */
|
|
615
|
+
modifiedTo?: string;
|
|
616
|
+
/** If PENALIZE, the consequence applied */
|
|
617
|
+
consequence?: Consequence;
|
|
618
|
+
/** If REWARD, the reward applied */
|
|
619
|
+
reward?: Reward;
|
|
620
|
+
}
|
|
525
621
|
/**
|
|
526
622
|
* Evidence attached to every verdict for audit purposes.
|
|
527
623
|
* Always present, regardless of trace mode.
|
|
@@ -561,6 +657,12 @@ interface GuardVerdict {
|
|
|
561
657
|
ruleId?: string;
|
|
562
658
|
/** Advisory warning (for ALLOW with warn-mode guards) */
|
|
563
659
|
warning?: string;
|
|
660
|
+
/** Consequence applied (for PENALIZE verdicts) */
|
|
661
|
+
consequence?: Consequence;
|
|
662
|
+
/** Reward applied (for REWARD verdicts) */
|
|
663
|
+
reward?: Reward;
|
|
664
|
+
/** Intent tracking — what the agent wanted vs what happened */
|
|
665
|
+
intentRecord?: IntentRecord;
|
|
564
666
|
/** Audit evidence — always present */
|
|
565
667
|
evidence: VerdictEvidence;
|
|
566
668
|
/** Evaluation trace — present when trace mode is enabled */
|
|
@@ -633,7 +735,7 @@ interface GuardCheck {
|
|
|
633
735
|
category: 'structural' | 'operational' | 'advisory';
|
|
634
736
|
enabled: boolean;
|
|
635
737
|
matched: boolean;
|
|
636
|
-
enforcement: 'block' | 'pause' | 'warn';
|
|
738
|
+
enforcement: 'block' | 'pause' | 'warn' | 'modify' | 'penalize' | 'reward' | 'neutral';
|
|
637
739
|
/** Which intent patterns matched (if any) */
|
|
638
740
|
matchedPatterns: string[];
|
|
639
741
|
/** Whether the guard was skipped due to role gating */
|
|
@@ -697,13 +799,23 @@ interface GuardEngineOptions {
|
|
|
697
799
|
* Plans can only restrict, never expand.
|
|
698
800
|
*/
|
|
699
801
|
plan?: PlanDefinition;
|
|
802
|
+
/**
|
|
803
|
+
* Agent behavior states — tracks cooldowns, influence, rewards per agent.
|
|
804
|
+
* The engine reads this to check if an agent is penalized (frozen).
|
|
805
|
+
* The caller owns mutation (applying consequences/rewards after verdict).
|
|
806
|
+
*/
|
|
807
|
+
agentStates?: Map<string, AgentBehaviorState>;
|
|
700
808
|
}
|
|
701
809
|
declare const GUARD_EXIT_CODES: {
|
|
702
810
|
readonly ALLOW: 0;
|
|
703
811
|
readonly BLOCK: 1;
|
|
704
812
|
readonly PAUSE: 2;
|
|
705
813
|
readonly ERROR: 3;
|
|
814
|
+
readonly MODIFY: 4;
|
|
815
|
+
readonly PENALIZE: 5;
|
|
816
|
+
readonly REWARD: 6;
|
|
817
|
+
readonly NEUTRAL: 7;
|
|
706
818
|
};
|
|
707
819
|
type GuardExitCode = (typeof GUARD_EXIT_CODES)[keyof typeof GUARD_EXIT_CODES];
|
|
708
820
|
|
|
709
|
-
export { type AdvanceResult as A, type EvaluationTrace as E, type
|
|
821
|
+
export { type AdvanceResult as A, type Consequence as C, type EvaluationTrace as E, type GuardEvent as G, type IntentRecord as I, type KernelRuleCheck as K, type LevelCheck as L, type PlanDefinition as P, type Reward as R, type StepEvidence as S, type ViabilityStatus as V, type WorldDefinition as W, type GuardVerdict as a, type GuardEngineOptions as b, type PlanProgress as c, type PlanVerdict as d, type PlanCheck as e, type AgentBehaviorState as f, type GuardStatus as g, GUARD_EXIT_CODES as h, type GuardCheck as i, type GuardExitCode as j, type InvariantCheck as k, PLAN_EXIT_CODES as l, type PlanCompletionMode as m, type PlanConstraint as n, type PlanExitCode as o, type PlanStatus as p, type PlanStep as q, type PrecedenceResolution as r, type RoleCheck as s, type SafetyCheck as t, type VerdictEvidence as u };
|
|
@@ -249,7 +249,7 @@ interface Guard {
|
|
|
249
249
|
label: string;
|
|
250
250
|
description: string;
|
|
251
251
|
category: 'structural' | 'operational' | 'advisory';
|
|
252
|
-
enforcement: 'block' | 'pause' | 'warn';
|
|
252
|
+
enforcement: 'block' | 'pause' | 'warn' | 'modify' | 'penalize' | 'reward' | 'neutral';
|
|
253
253
|
immutable: boolean;
|
|
254
254
|
invariant_ref?: string;
|
|
255
255
|
intent_patterns: string[];
|
|
@@ -261,8 +261,24 @@ interface Guard {
|
|
|
261
261
|
player_modes?: {
|
|
262
262
|
thinking?: 'annotate' | 'block' | 'ignore';
|
|
263
263
|
experience?: 'simulate' | 'score' | 'ignore';
|
|
264
|
-
action?: 'block' | 'pause' | 'warn';
|
|
264
|
+
action?: 'block' | 'pause' | 'warn' | 'modify' | 'penalize' | 'reward' | 'neutral';
|
|
265
265
|
};
|
|
266
|
+
/** Consequence to apply when enforcement is 'penalize' */
|
|
267
|
+
consequence?: {
|
|
268
|
+
type: 'freeze' | 'reduce_influence' | 'increase_risk' | 'cooldown' | 'custom';
|
|
269
|
+
rounds?: number;
|
|
270
|
+
magnitude?: number;
|
|
271
|
+
description: string;
|
|
272
|
+
};
|
|
273
|
+
/** Reward to apply when enforcement is 'reward' */
|
|
274
|
+
reward?: {
|
|
275
|
+
type: 'boost_influence' | 'priority' | 'faster_execution' | 'weight_increase' | 'custom';
|
|
276
|
+
rounds?: number;
|
|
277
|
+
magnitude?: number;
|
|
278
|
+
description: string;
|
|
279
|
+
};
|
|
280
|
+
/** For 'modify' enforcement: what the action should be changed to */
|
|
281
|
+
modify_to?: string;
|
|
266
282
|
}
|
|
267
283
|
interface IntentPattern {
|
|
268
284
|
label: string;
|
|
@@ -521,7 +537,87 @@ interface GuardEvent {
|
|
|
521
537
|
/** Environment context (e.g. "development", "production") */
|
|
522
538
|
environment?: string;
|
|
523
539
|
}
|
|
524
|
-
type GuardStatus = 'ALLOW' | 'BLOCK' | 'PAUSE';
|
|
540
|
+
type GuardStatus = 'ALLOW' | 'BLOCK' | 'PAUSE' | 'MODIFY' | 'PENALIZE' | 'REWARD' | 'NEUTRAL';
|
|
541
|
+
/**
|
|
542
|
+
* Consequence applied when an agent is PENALIZED.
|
|
543
|
+
* The governance engine blocks the action AND imposes a behavioral cost.
|
|
544
|
+
*/
|
|
545
|
+
interface Consequence {
|
|
546
|
+
/** Type of penalty */
|
|
547
|
+
type: 'freeze' | 'reduce_influence' | 'increase_risk' | 'cooldown' | 'custom';
|
|
548
|
+
/** Duration in rounds (for freeze/cooldown) */
|
|
549
|
+
rounds?: number;
|
|
550
|
+
/** Magnitude of effect (e.g., influence reduction percentage 0-1) */
|
|
551
|
+
magnitude?: number;
|
|
552
|
+
/** Human-readable description of what happens */
|
|
553
|
+
description: string;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Reward applied when an agent's action is REWARDED.
|
|
557
|
+
* The action proceeds AND the agent receives a behavioral boost.
|
|
558
|
+
*/
|
|
559
|
+
interface Reward {
|
|
560
|
+
/** Type of reward */
|
|
561
|
+
type: 'boost_influence' | 'priority' | 'faster_execution' | 'weight_increase' | 'custom';
|
|
562
|
+
/** Duration in rounds (for temporary boosts) */
|
|
563
|
+
rounds?: number;
|
|
564
|
+
/** Magnitude of effect (e.g., influence boost percentage 0-1) */
|
|
565
|
+
magnitude?: number;
|
|
566
|
+
/** Human-readable description of what happens */
|
|
567
|
+
description: string;
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Tracks the behavioral state of an agent across governance evaluations.
|
|
571
|
+
* This is what makes governance a behavior-shaping system, not just a filter.
|
|
572
|
+
*/
|
|
573
|
+
interface AgentBehaviorState {
|
|
574
|
+
/** Agent/role identifier */
|
|
575
|
+
agentId: string;
|
|
576
|
+
/** Rounds remaining in cooldown (0 = active) */
|
|
577
|
+
cooldownRemaining: number;
|
|
578
|
+
/** Current influence multiplier (1.0 = normal) */
|
|
579
|
+
influence: number;
|
|
580
|
+
/** Accumulated reward multiplier (1.0 = normal) */
|
|
581
|
+
rewardMultiplier: number;
|
|
582
|
+
/** Total penalties received */
|
|
583
|
+
totalPenalties: number;
|
|
584
|
+
/** Total rewards received */
|
|
585
|
+
totalRewards: number;
|
|
586
|
+
/** History of consequences applied */
|
|
587
|
+
consequenceHistory: Array<{
|
|
588
|
+
ruleId: string;
|
|
589
|
+
consequence: Consequence;
|
|
590
|
+
appliedAt: number;
|
|
591
|
+
}>;
|
|
592
|
+
/** History of rewards applied */
|
|
593
|
+
rewardHistory: Array<{
|
|
594
|
+
ruleId: string;
|
|
595
|
+
reward: Reward;
|
|
596
|
+
appliedAt: number;
|
|
597
|
+
}>;
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Tracks what an agent WANTED to do vs what governance MADE it do.
|
|
601
|
+
* This is the core of the Decision Flow visualization.
|
|
602
|
+
*
|
|
603
|
+
* The gap between intent and outcome = governance value.
|
|
604
|
+
*/
|
|
605
|
+
interface IntentRecord {
|
|
606
|
+
/** Original action the agent attempted */
|
|
607
|
+
originalIntent: string;
|
|
608
|
+
/** What actually happened after governance */
|
|
609
|
+
finalAction: string;
|
|
610
|
+
/** The rule that caused the interception */
|
|
611
|
+
ruleApplied?: string;
|
|
612
|
+
/** How the intent was transformed */
|
|
613
|
+
enforcement: GuardStatus;
|
|
614
|
+
/** If MODIFY, what the action was changed to */
|
|
615
|
+
modifiedTo?: string;
|
|
616
|
+
/** If PENALIZE, the consequence applied */
|
|
617
|
+
consequence?: Consequence;
|
|
618
|
+
/** If REWARD, the reward applied */
|
|
619
|
+
reward?: Reward;
|
|
620
|
+
}
|
|
525
621
|
/**
|
|
526
622
|
* Evidence attached to every verdict for audit purposes.
|
|
527
623
|
* Always present, regardless of trace mode.
|
|
@@ -561,6 +657,12 @@ interface GuardVerdict {
|
|
|
561
657
|
ruleId?: string;
|
|
562
658
|
/** Advisory warning (for ALLOW with warn-mode guards) */
|
|
563
659
|
warning?: string;
|
|
660
|
+
/** Consequence applied (for PENALIZE verdicts) */
|
|
661
|
+
consequence?: Consequence;
|
|
662
|
+
/** Reward applied (for REWARD verdicts) */
|
|
663
|
+
reward?: Reward;
|
|
664
|
+
/** Intent tracking — what the agent wanted vs what happened */
|
|
665
|
+
intentRecord?: IntentRecord;
|
|
564
666
|
/** Audit evidence — always present */
|
|
565
667
|
evidence: VerdictEvidence;
|
|
566
668
|
/** Evaluation trace — present when trace mode is enabled */
|
|
@@ -633,7 +735,7 @@ interface GuardCheck {
|
|
|
633
735
|
category: 'structural' | 'operational' | 'advisory';
|
|
634
736
|
enabled: boolean;
|
|
635
737
|
matched: boolean;
|
|
636
|
-
enforcement: 'block' | 'pause' | 'warn';
|
|
738
|
+
enforcement: 'block' | 'pause' | 'warn' | 'modify' | 'penalize' | 'reward' | 'neutral';
|
|
637
739
|
/** Which intent patterns matched (if any) */
|
|
638
740
|
matchedPatterns: string[];
|
|
639
741
|
/** Whether the guard was skipped due to role gating */
|
|
@@ -697,13 +799,23 @@ interface GuardEngineOptions {
|
|
|
697
799
|
* Plans can only restrict, never expand.
|
|
698
800
|
*/
|
|
699
801
|
plan?: PlanDefinition;
|
|
802
|
+
/**
|
|
803
|
+
* Agent behavior states — tracks cooldowns, influence, rewards per agent.
|
|
804
|
+
* The engine reads this to check if an agent is penalized (frozen).
|
|
805
|
+
* The caller owns mutation (applying consequences/rewards after verdict).
|
|
806
|
+
*/
|
|
807
|
+
agentStates?: Map<string, AgentBehaviorState>;
|
|
700
808
|
}
|
|
701
809
|
declare const GUARD_EXIT_CODES: {
|
|
702
810
|
readonly ALLOW: 0;
|
|
703
811
|
readonly BLOCK: 1;
|
|
704
812
|
readonly PAUSE: 2;
|
|
705
813
|
readonly ERROR: 3;
|
|
814
|
+
readonly MODIFY: 4;
|
|
815
|
+
readonly PENALIZE: 5;
|
|
816
|
+
readonly REWARD: 6;
|
|
817
|
+
readonly NEUTRAL: 7;
|
|
706
818
|
};
|
|
707
819
|
type GuardExitCode = (typeof GUARD_EXIT_CODES)[keyof typeof GUARD_EXIT_CODES];
|
|
708
820
|
|
|
709
|
-
export { type AdvanceResult as A, type EvaluationTrace as E, type
|
|
821
|
+
export { type AdvanceResult as A, type Consequence as C, type EvaluationTrace as E, type GuardEvent as G, type IntentRecord as I, type KernelRuleCheck as K, type LevelCheck as L, type PlanDefinition as P, type Reward as R, type StepEvidence as S, type ViabilityStatus as V, type WorldDefinition as W, type GuardVerdict as a, type GuardEngineOptions as b, type PlanProgress as c, type PlanVerdict as d, type PlanCheck as e, type AgentBehaviorState as f, type GuardStatus as g, GUARD_EXIT_CODES as h, type GuardCheck as i, type GuardExitCode as j, type InvariantCheck as k, PLAN_EXIT_CODES as l, type PlanCompletionMode as m, type PlanConstraint as n, type PlanExitCode as o, type PlanStatus as p, type PlanStep as q, type PrecedenceResolution as r, type RoleCheck as s, type SafetyCheck as t, type VerdictEvidence as u };
|