@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.
- package/package.json +4 -2
- 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 +1899 -0
- package/dist/adapters/autoresearch.cjs +0 -196
- package/dist/adapters/autoresearch.d.cts +0 -103
- package/dist/adapters/autoresearch.d.ts +0 -103
- package/dist/adapters/autoresearch.js +0 -7
- package/dist/adapters/deep-agents.cjs +0 -1472
- package/dist/adapters/deep-agents.d.cts +0 -181
- package/dist/adapters/deep-agents.d.ts +0 -181
- package/dist/adapters/deep-agents.js +0 -17
- package/dist/adapters/express.cjs +0 -1196
- package/dist/adapters/express.d.cts +0 -66
- package/dist/adapters/express.d.ts +0 -66
- package/dist/adapters/express.js +0 -12
- package/dist/adapters/index.cjs +0 -2038
- package/dist/adapters/index.d.cts +0 -8
- package/dist/adapters/index.d.ts +0 -8
- package/dist/adapters/index.js +0 -68
- package/dist/adapters/langchain.cjs +0 -1259
- package/dist/adapters/langchain.d.cts +0 -89
- package/dist/adapters/langchain.d.ts +0 -89
- package/dist/adapters/langchain.js +0 -17
- package/dist/adapters/openai.cjs +0 -1289
- package/dist/adapters/openai.d.cts +0 -99
- package/dist/adapters/openai.d.ts +0 -99
- package/dist/adapters/openai.js +0 -17
- package/dist/adapters/openclaw.cjs +0 -1281
- package/dist/adapters/openclaw.d.cts +0 -99
- package/dist/adapters/openclaw.d.ts +0 -99
- package/dist/adapters/openclaw.js +0 -17
- package/dist/bootstrap-GXVDZNF7.js +0 -114
- package/dist/build-X5MZY4IA.js +0 -339
- package/dist/chunk-4L6OPKMQ.js +0 -100
- package/dist/chunk-4NGDRRQH.js +0 -10
- package/dist/chunk-5U2MQO5P.js +0 -57
- package/dist/chunk-6BB55YJI.js +0 -113
- package/dist/chunk-6CZSKEY5.js +0 -164
- package/dist/chunk-7P3S7MAY.js +0 -1090
- package/dist/chunk-A5W4GNQO.js +0 -130
- package/dist/chunk-AF2VX4AL.js +0 -363
- package/dist/chunk-AKW5YVCE.js +0 -96
- package/dist/chunk-BMOXICAB.js +0 -340
- package/dist/chunk-BQZMOEML.js +0 -43
- package/dist/chunk-D2UCV5AK.js +0 -326
- package/dist/chunk-EVDJUSZ2.js +0 -91
- package/dist/chunk-FYS2CBUW.js +0 -304
- package/dist/chunk-I3RRAYK2.js +0 -11
- package/dist/chunk-IZSO75NZ.js +0 -792
- package/dist/chunk-JCKSW2PZ.js +0 -304
- package/dist/chunk-JZPQGIKR.js +0 -79
- package/dist/chunk-KTFTTLTP.js +0 -246
- package/dist/chunk-MH7BT4VH.js +0 -15
- package/dist/chunk-ORJ3NOE6.js +0 -622
- package/dist/chunk-OT6PXH54.js +0 -61
- package/dist/chunk-Q6O7ZLO2.js +0 -62
- package/dist/chunk-QLPTHTVB.js +0 -253
- package/dist/chunk-REXY4LUL.js +0 -226
- package/dist/chunk-T5EUJQE5.js +0 -172
- package/dist/chunk-TTBKTF3P.js +0 -608
- package/dist/chunk-XPDMYECO.js +0 -642
- package/dist/chunk-YZFATT7X.js +0 -9
- package/dist/chunk-ZIVQNSZU.js +0 -119
- package/dist/chunk-ZJTDUCC2.js +0 -194
- package/dist/cli/neuroverse.cjs +0 -12564
- package/dist/cli/neuroverse.d.cts +0 -1
- package/dist/cli/neuroverse.d.ts +0 -1
- package/dist/cli/neuroverse.js +0 -208
- package/dist/cli/plan.cjs +0 -1686
- package/dist/cli/plan.d.cts +0 -20
- package/dist/cli/plan.d.ts +0 -20
- package/dist/cli/plan.js +0 -353
- package/dist/cli/run.cjs +0 -1945
- package/dist/cli/run.d.cts +0 -20
- package/dist/cli/run.d.ts +0 -20
- package/dist/cli/run.js +0 -143
- package/dist/configure-ai-TK67ZWZL.js +0 -132
- package/dist/decision-flow-LETV5NWY.js +0 -61
- package/dist/derive-7365SUFU.js +0 -152
- package/dist/doctor-QYISMKEL.js +0 -173
- package/dist/equity-penalties-63FGB3I2.js +0 -244
- package/dist/explain-A2EWI2OL.js +0 -51
- package/dist/guard-3BWL3IGH.js +0 -92
- package/dist/guard-contract-C9_zKbzd.d.cts +0 -821
- package/dist/guard-contract-C9_zKbzd.d.ts +0 -821
- package/dist/guard-engine-QFMIBWJY.js +0 -10
- package/dist/impact-UB6DXKSX.js +0 -59
- package/dist/improve-XZA57GER.js +0 -66
- package/dist/index.cjs +0 -6821
- package/dist/index.d.cts +0 -1829
- package/dist/index.d.ts +0 -1829
- package/dist/index.js +0 -430
- package/dist/infer-world-7GVZWFX4.js +0 -543
- package/dist/init-PKPIYHYE.js +0 -144
- package/dist/init-world-VWMQZQC7.js +0 -223
- package/dist/mcp-server-XWQZXNW7.js +0 -13
- package/dist/model-adapter-BB7G4MFI.js +0 -11
- package/dist/playground-ADWZORNV.js +0 -550
- package/dist/redteam-JRQ7FD2F.js +0 -357
- package/dist/session-MMYX5YCF.js +0 -15
- package/dist/shared--Q8wPBVN.d.ts +0 -60
- package/dist/shared-HpAG90PX.d.cts +0 -60
- package/dist/shared-U2QFV7JH.js +0 -16
- package/dist/simulate-GMIFFXYV.js +0 -83
- package/dist/test-JBBZ65X4.js +0 -217
- package/dist/trace-3MYWIDEF.js +0 -166
- package/dist/validate-LLBWVPGV.js +0 -81
- package/dist/validate-engine-UIABSIHD.js +0 -7
- package/dist/world-BFJCIQSH.js +0 -378
- package/dist/world-loader-HMPTOEA2.js +0 -9
- package/dist/worlds/autoresearch.nv-world.md +0 -230
- package/dist/worlds/coding-agent.nv-world.md +0 -211
- package/dist/worlds/derivation-world.nv-world.md +0 -278
package/dist/chunk-JCKSW2PZ.js
DELETED
|
@@ -1,304 +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/engine/tool-classifier.ts
|
|
15
|
-
var TOOL_CATEGORY_MAP = {
|
|
16
|
-
// File operations
|
|
17
|
-
read_file: "file_read",
|
|
18
|
-
read: "file_read",
|
|
19
|
-
glob: "file_read",
|
|
20
|
-
grep: "file_read",
|
|
21
|
-
list_files: "file_read",
|
|
22
|
-
write_file: "file_write",
|
|
23
|
-
write: "file_write",
|
|
24
|
-
create_file: "file_write",
|
|
25
|
-
edit_file: "file_write",
|
|
26
|
-
edit: "file_write",
|
|
27
|
-
patch: "file_write",
|
|
28
|
-
delete_file: "file_delete",
|
|
29
|
-
remove_file: "file_delete",
|
|
30
|
-
// Shell
|
|
31
|
-
shell: "shell",
|
|
32
|
-
bash: "shell",
|
|
33
|
-
execute: "shell",
|
|
34
|
-
run_command: "shell",
|
|
35
|
-
terminal: "shell",
|
|
36
|
-
// Git
|
|
37
|
-
git: "git",
|
|
38
|
-
git_commit: "git",
|
|
39
|
-
git_push: "git",
|
|
40
|
-
git_checkout: "git",
|
|
41
|
-
// Network
|
|
42
|
-
http: "network",
|
|
43
|
-
fetch: "network",
|
|
44
|
-
curl: "network",
|
|
45
|
-
web_search: "network",
|
|
46
|
-
// Sub-agents
|
|
47
|
-
sub_agent: "sub_agent",
|
|
48
|
-
spawn_agent: "sub_agent",
|
|
49
|
-
delegate: "sub_agent",
|
|
50
|
-
// Context management
|
|
51
|
-
summarize: "context",
|
|
52
|
-
compress_context: "context"
|
|
53
|
-
};
|
|
54
|
-
function classifyTool(toolName) {
|
|
55
|
-
const normalized = toolName.toLowerCase().replace(/[-\s]/g, "_");
|
|
56
|
-
return TOOL_CATEGORY_MAP[normalized] ?? "unknown";
|
|
57
|
-
}
|
|
58
|
-
var DANGEROUS_SHELL_PATTERNS = [
|
|
59
|
-
{ pattern: /rm\s+(-[a-zA-Z]*f[a-zA-Z]*\s+|.*-rf\s+|.*--force)/, label: "force-delete" },
|
|
60
|
-
{ pattern: /rm\s+-[a-zA-Z]*r/, label: "recursive-delete" },
|
|
61
|
-
{ pattern: />\s*\/dev\/sd/, label: "disk-overwrite" },
|
|
62
|
-
{ pattern: /mkfs\./, label: "format-disk" },
|
|
63
|
-
{ pattern: /dd\s+if=/, label: "disk-dump" },
|
|
64
|
-
{ pattern: /chmod\s+(-R\s+)?777/, label: "world-writable" },
|
|
65
|
-
{ pattern: /curl\s+.*\|\s*(bash|sh|zsh)/, label: "pipe-to-shell" },
|
|
66
|
-
{ pattern: /wget\s+.*\|\s*(bash|sh|zsh)/, label: "pipe-to-shell" },
|
|
67
|
-
{ pattern: /:(){ :\|:& };:/, label: "fork-bomb" },
|
|
68
|
-
{ pattern: />\s*\/etc\//, label: "system-config-overwrite" },
|
|
69
|
-
{ pattern: /shutdown|reboot|halt|poweroff/, label: "system-shutdown" },
|
|
70
|
-
{ pattern: /kill\s+-9\s+1\b/, label: "kill-init" }
|
|
71
|
-
];
|
|
72
|
-
var DANGEROUS_GIT_PATTERNS = [
|
|
73
|
-
{ pattern: /push\s+.*--force/, label: "force-push" },
|
|
74
|
-
{ pattern: /push\s+.*-f\b/, label: "force-push" },
|
|
75
|
-
{ pattern: /push\s+(origin\s+)?main\b/, label: "push-main" },
|
|
76
|
-
{ pattern: /push\s+(origin\s+)?master\b/, label: "push-master" },
|
|
77
|
-
{ pattern: /reset\s+--hard/, label: "hard-reset" },
|
|
78
|
-
{ pattern: /clean\s+-fd/, label: "clean-force" },
|
|
79
|
-
{ pattern: /branch\s+-D/, label: "force-delete-branch" }
|
|
80
|
-
];
|
|
81
|
-
function isDangerousCommand(command) {
|
|
82
|
-
const matched = DANGEROUS_SHELL_PATTERNS.filter((p) => p.pattern.test(command)).map((p) => p.label);
|
|
83
|
-
return { dangerous: matched.length > 0, labels: matched };
|
|
84
|
-
}
|
|
85
|
-
function isDangerousGitCommand(command) {
|
|
86
|
-
const matched = DANGEROUS_GIT_PATTERNS.filter((p) => p.pattern.test(command)).map((p) => p.label);
|
|
87
|
-
return { dangerous: matched.length > 0, labels: matched };
|
|
88
|
-
}
|
|
89
|
-
function assessRiskLevel(category) {
|
|
90
|
-
if (category === "file_read" || category === "context") return "low";
|
|
91
|
-
if (category === "file_write" || category === "sub_agent") return "medium";
|
|
92
|
-
if (category === "shell" || category === "file_delete" || category === "git" || category === "network") return "high";
|
|
93
|
-
return void 0;
|
|
94
|
-
}
|
|
95
|
-
function categoryToActionCategory(category) {
|
|
96
|
-
if (category === "file_read" || category === "context") return "read";
|
|
97
|
-
if (category === "file_write") return "write";
|
|
98
|
-
if (category === "file_delete") return "delete";
|
|
99
|
-
if (category === "shell") return "shell";
|
|
100
|
-
if (category === "network") return "network";
|
|
101
|
-
return "other";
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// src/adapters/deep-agents.ts
|
|
105
|
-
var GovernanceBlockedError2 = class extends GovernanceBlockedError {
|
|
106
|
-
toolCall;
|
|
107
|
-
category;
|
|
108
|
-
constructor(verdict, toolCall, category) {
|
|
109
|
-
super(verdict);
|
|
110
|
-
this.toolCall = toolCall;
|
|
111
|
-
this.category = category;
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
function defaultMapToolCall(toolCall) {
|
|
115
|
-
const category = classifyTool(toolCall.tool);
|
|
116
|
-
const args = toolCall.args;
|
|
117
|
-
const scope = extractScope(args);
|
|
118
|
-
let intent = toolCall.tool;
|
|
119
|
-
if (category === "shell" && typeof args.command === "string") {
|
|
120
|
-
intent = `shell: ${args.command}`;
|
|
121
|
-
} else if (category === "git" && typeof args.command === "string") {
|
|
122
|
-
intent = `git ${args.command}`;
|
|
123
|
-
} else if (category === "file_write" && scope) {
|
|
124
|
-
intent = `write ${scope}`;
|
|
125
|
-
} else if (category === "file_delete" && scope) {
|
|
126
|
-
intent = `delete ${scope}`;
|
|
127
|
-
}
|
|
128
|
-
const riskLevel = assessRiskLevel(category);
|
|
129
|
-
let irreversible = false;
|
|
130
|
-
if (category === "shell" && typeof args.command === "string") {
|
|
131
|
-
irreversible = DANGEROUS_SHELL_PATTERNS.some((p) => p.pattern.test(args.command));
|
|
132
|
-
} else if (category === "git" && typeof args.command === "string") {
|
|
133
|
-
irreversible = DANGEROUS_GIT_PATTERNS.some((p) => p.pattern.test(args.command));
|
|
134
|
-
} else if (category === "file_delete") {
|
|
135
|
-
irreversible = true;
|
|
136
|
-
}
|
|
137
|
-
return {
|
|
138
|
-
intent,
|
|
139
|
-
tool: toolCall.tool,
|
|
140
|
-
scope,
|
|
141
|
-
args,
|
|
142
|
-
direction: "input",
|
|
143
|
-
actionCategory: categoryToActionCategory(category),
|
|
144
|
-
riskLevel,
|
|
145
|
-
irreversible
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
var DeepAgentsGuard = class {
|
|
149
|
-
name = "neuroverse-deep-agents-guard";
|
|
150
|
-
world;
|
|
151
|
-
options;
|
|
152
|
-
engineOptions;
|
|
153
|
-
mapToolCall;
|
|
154
|
-
activePlan;
|
|
155
|
-
constructor(world, options = {}) {
|
|
156
|
-
this.world = world;
|
|
157
|
-
this.options = options;
|
|
158
|
-
this.activePlan = options.plan;
|
|
159
|
-
this.engineOptions = buildEngineOptions(options, this.activePlan);
|
|
160
|
-
this.mapToolCall = options.mapToolCall ?? defaultMapToolCall;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Evaluate a tool call against governance rules.
|
|
164
|
-
* Returns the result without side effects.
|
|
165
|
-
*/
|
|
166
|
-
evaluate(toolCall) {
|
|
167
|
-
const event = this.mapToolCall(toolCall);
|
|
168
|
-
this.engineOptions.plan = this.activePlan;
|
|
169
|
-
const verdict = evaluateGuard(event, this.world, this.engineOptions);
|
|
170
|
-
const category = classifyTool(toolCall.tool);
|
|
171
|
-
const result = {
|
|
172
|
-
allowed: verdict.status === "ALLOW",
|
|
173
|
-
verdict,
|
|
174
|
-
toolCall,
|
|
175
|
-
category
|
|
176
|
-
};
|
|
177
|
-
this.options.onEvaluate?.(result);
|
|
178
|
-
if (verdict.status === "ALLOW" && this.activePlan) {
|
|
179
|
-
this.trackPlanProgressInternal(event);
|
|
180
|
-
}
|
|
181
|
-
return result;
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Evaluate and enforce governance on a tool call.
|
|
185
|
-
*
|
|
186
|
-
* @throws GovernanceBlockedError if BLOCKED
|
|
187
|
-
* @throws GovernanceBlockedError if PAUSED and onPause returns false
|
|
188
|
-
* @returns DeepAgentsGuardResult on ALLOW
|
|
189
|
-
*/
|
|
190
|
-
async enforce(toolCall) {
|
|
191
|
-
const result = this.evaluate(toolCall);
|
|
192
|
-
if (result.verdict.status === "BLOCK") {
|
|
193
|
-
this.options.onBlock?.(result);
|
|
194
|
-
throw new GovernanceBlockedError2(result.verdict, toolCall, result.category);
|
|
195
|
-
}
|
|
196
|
-
if (result.verdict.status === "PAUSE") {
|
|
197
|
-
const approved = await this.options.onPause?.(result);
|
|
198
|
-
if (!approved) {
|
|
199
|
-
throw new GovernanceBlockedError2(result.verdict, toolCall, result.category);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return result;
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Evaluate and execute a tool call with governance enforcement.
|
|
206
|
-
*
|
|
207
|
-
* If ALLOW: runs the executor and returns its result.
|
|
208
|
-
* If BLOCK: returns a governance-blocked message.
|
|
209
|
-
* If PAUSE: calls onPause; blocks if not approved.
|
|
210
|
-
*
|
|
211
|
-
* @param toolCall - The Deep Agents tool call to evaluate
|
|
212
|
-
* @param executor - The actual tool execution function
|
|
213
|
-
* @returns The tool execution result or a blocked message
|
|
214
|
-
*/
|
|
215
|
-
async execute(toolCall, executor) {
|
|
216
|
-
const guardResult = this.evaluate(toolCall);
|
|
217
|
-
if (guardResult.verdict.status === "BLOCK") {
|
|
218
|
-
this.options.onBlock?.(guardResult);
|
|
219
|
-
return {
|
|
220
|
-
blocked: true,
|
|
221
|
-
verdict: guardResult.verdict,
|
|
222
|
-
reason: guardResult.verdict.reason ?? "Action blocked by governance policy."
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
if (guardResult.verdict.status === "PAUSE") {
|
|
226
|
-
const approved = await this.options.onPause?.(guardResult);
|
|
227
|
-
if (!approved) {
|
|
228
|
-
return {
|
|
229
|
-
blocked: true,
|
|
230
|
-
verdict: guardResult.verdict,
|
|
231
|
-
reason: guardResult.verdict.reason ?? "Action requires approval."
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
const result = await executor(toolCall);
|
|
236
|
-
return { result, verdict: guardResult.verdict };
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Returns a middleware function compatible with Deep Agents' tool pipeline.
|
|
240
|
-
*
|
|
241
|
-
* The middleware intercepts tool calls before execution:
|
|
242
|
-
* agent.use(guard.middleware());
|
|
243
|
-
*/
|
|
244
|
-
middleware() {
|
|
245
|
-
return async (toolCall, next) => {
|
|
246
|
-
await this.enforce(toolCall);
|
|
247
|
-
return next();
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Returns a callback-handler-style object for LangChain integration.
|
|
252
|
-
* Compatible with Deep Agents' callback system.
|
|
253
|
-
*/
|
|
254
|
-
callbacks() {
|
|
255
|
-
return {
|
|
256
|
-
handleToolStart: async (tool, input) => {
|
|
257
|
-
let parsedInput;
|
|
258
|
-
try {
|
|
259
|
-
parsedInput = typeof input === "string" ? JSON.parse(input) : input;
|
|
260
|
-
} catch {
|
|
261
|
-
parsedInput = { raw: input };
|
|
262
|
-
}
|
|
263
|
-
await this.enforce({ tool: tool.name, args: parsedInput });
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Check if a shell command contains dangerous patterns.
|
|
269
|
-
* Useful for pre-screening before full governance evaluation.
|
|
270
|
-
*/
|
|
271
|
-
static isDangerousCommand(command) {
|
|
272
|
-
return isDangerousCommand(command);
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Check if a git command contains dangerous patterns.
|
|
276
|
-
*/
|
|
277
|
-
static isDangerousGitCommand(command) {
|
|
278
|
-
return isDangerousGitCommand(command);
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Classify a tool name into a category.
|
|
282
|
-
*/
|
|
283
|
-
static classifyTool(toolName) {
|
|
284
|
-
return classifyTool(toolName);
|
|
285
|
-
}
|
|
286
|
-
// ─── Private ──────────────────────────────────────────────────────────────
|
|
287
|
-
trackPlanProgressInternal(event) {
|
|
288
|
-
trackPlanProgress(event, this, this.options);
|
|
289
|
-
}
|
|
290
|
-
};
|
|
291
|
-
async function createDeepAgentsGuard(worldPath, options) {
|
|
292
|
-
const world = await loadWorld(worldPath);
|
|
293
|
-
return new DeepAgentsGuard(world, options);
|
|
294
|
-
}
|
|
295
|
-
function createDeepAgentsGuardFromWorld(world, options) {
|
|
296
|
-
return new DeepAgentsGuard(world, options);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
export {
|
|
300
|
-
GovernanceBlockedError2 as GovernanceBlockedError,
|
|
301
|
-
DeepAgentsGuard,
|
|
302
|
-
createDeepAgentsGuard,
|
|
303
|
-
createDeepAgentsGuardFromWorld
|
|
304
|
-
};
|
package/dist/chunk-JZPQGIKR.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
// src/loader/world-loader.ts
|
|
2
|
-
async function loadWorldFromDirectory(dirPath) {
|
|
3
|
-
const { readFile } = await import("fs/promises");
|
|
4
|
-
const { join } = await import("path");
|
|
5
|
-
const { readdirSync } = await import("fs");
|
|
6
|
-
async function readJson(filename) {
|
|
7
|
-
try {
|
|
8
|
-
const content = await readFile(join(dirPath, filename), "utf-8");
|
|
9
|
-
return JSON.parse(content);
|
|
10
|
-
} catch {
|
|
11
|
-
return void 0;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
const worldJson = await readJson("world.json");
|
|
15
|
-
if (!worldJson) {
|
|
16
|
-
throw new Error(`Cannot read world.json in ${dirPath}`);
|
|
17
|
-
}
|
|
18
|
-
const invariantsJson = await readJson("invariants.json");
|
|
19
|
-
const assumptionsJson = await readJson("assumptions.json");
|
|
20
|
-
const stateSchemaJson = await readJson("state-schema.json");
|
|
21
|
-
const gatesJson = await readJson("gates.json");
|
|
22
|
-
const outcomesJson = await readJson("outcomes.json");
|
|
23
|
-
const guardsJson = await readJson("guards.json");
|
|
24
|
-
const rolesJson = await readJson("roles.json");
|
|
25
|
-
const kernelJson = await readJson("kernel.json");
|
|
26
|
-
const metadataJson = await readJson("metadata.json");
|
|
27
|
-
const rules = [];
|
|
28
|
-
try {
|
|
29
|
-
const rulesDir = join(dirPath, "rules");
|
|
30
|
-
const ruleFiles = readdirSync(rulesDir).filter((f) => f.endsWith(".json")).sort();
|
|
31
|
-
for (const file of ruleFiles) {
|
|
32
|
-
const content = await readFile(join(rulesDir, file), "utf-8");
|
|
33
|
-
rules.push(JSON.parse(content));
|
|
34
|
-
}
|
|
35
|
-
} catch {
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
world: worldJson,
|
|
39
|
-
invariants: invariantsJson?.invariants ?? [],
|
|
40
|
-
assumptions: assumptionsJson ?? { profiles: {}, parameter_definitions: {} },
|
|
41
|
-
stateSchema: stateSchemaJson ?? { variables: {}, presets: {} },
|
|
42
|
-
rules,
|
|
43
|
-
gates: gatesJson ?? {
|
|
44
|
-
viability_classification: [],
|
|
45
|
-
structural_override: { description: "", enforcement: "mandatory" },
|
|
46
|
-
sustainability_threshold: 0,
|
|
47
|
-
collapse_visual: { background: "", text: "", border: "", label: "" }
|
|
48
|
-
},
|
|
49
|
-
outcomes: outcomesJson ?? {
|
|
50
|
-
computed_outcomes: [],
|
|
51
|
-
comparison_layout: { primary_card: "", status_badge: "", structural_indicators: [] }
|
|
52
|
-
},
|
|
53
|
-
guards: guardsJson,
|
|
54
|
-
roles: rolesJson,
|
|
55
|
-
kernel: kernelJson,
|
|
56
|
-
metadata: metadataJson ?? {
|
|
57
|
-
format_version: "1.0.0",
|
|
58
|
-
created_at: "",
|
|
59
|
-
last_modified: "",
|
|
60
|
-
authoring_method: "manual-authoring"
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
async function loadWorld(worldPath) {
|
|
65
|
-
const { stat } = await import("fs/promises");
|
|
66
|
-
const info = await stat(worldPath);
|
|
67
|
-
if (info.isDirectory()) {
|
|
68
|
-
return loadWorldFromDirectory(worldPath);
|
|
69
|
-
}
|
|
70
|
-
if (worldPath.endsWith(".nv-world.zip")) {
|
|
71
|
-
throw new Error(".nv-world.zip loading not yet implemented \u2014 use a world directory");
|
|
72
|
-
}
|
|
73
|
-
throw new Error(`Cannot load world from: ${worldPath} \u2014 expected a directory or .nv-world.zip`);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export {
|
|
77
|
-
loadWorldFromDirectory,
|
|
78
|
-
loadWorld
|
|
79
|
-
};
|
package/dist/chunk-KTFTTLTP.js
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
readAuditLog
|
|
3
|
-
} from "./chunk-REXY4LUL.js";
|
|
4
|
-
|
|
5
|
-
// src/engine/impact-report.ts
|
|
6
|
-
function generateImpactReport(events) {
|
|
7
|
-
if (events.length === 0) {
|
|
8
|
-
return emptyReport();
|
|
9
|
-
}
|
|
10
|
-
const blocked = events.filter((e) => e.decision === "BLOCK");
|
|
11
|
-
const paused = events.filter((e) => e.decision === "PAUSE");
|
|
12
|
-
const modified = events.filter((e) => e.decision === "MODIFY");
|
|
13
|
-
const penalized = events.filter((e) => e.decision === "PENALIZE");
|
|
14
|
-
const rewarded = events.filter((e) => e.decision === "REWARD");
|
|
15
|
-
const neutralEvents = events.filter((e) => e.decision === "NEUTRAL");
|
|
16
|
-
const prevented = [...blocked, ...paused, ...modified, ...penalized];
|
|
17
|
-
const categoryMap = /* @__PURE__ */ new Map();
|
|
18
|
-
for (const e of prevented) {
|
|
19
|
-
const cat = classifyPreventionCategory(e);
|
|
20
|
-
if (!categoryMap.has(cat)) categoryMap.set(cat, /* @__PURE__ */ new Set());
|
|
21
|
-
categoryMap.get(cat).add(e.intent);
|
|
22
|
-
}
|
|
23
|
-
const preventedByCategory = [...categoryMap.entries()].map(([category, intents]) => ({
|
|
24
|
-
category,
|
|
25
|
-
count: prevented.filter((e) => classifyPreventionCategory(e) === category).length,
|
|
26
|
-
examples: [...intents].slice(0, 5)
|
|
27
|
-
})).sort((a, b) => b.count - a.count);
|
|
28
|
-
const intentMap = /* @__PURE__ */ new Map();
|
|
29
|
-
for (const e of prevented) {
|
|
30
|
-
const entry = intentMap.get(e.intent) ?? { count: 0, rules: /* @__PURE__ */ new Map() };
|
|
31
|
-
entry.count++;
|
|
32
|
-
if (e.ruleId) {
|
|
33
|
-
entry.rules.set(e.ruleId, (entry.rules.get(e.ruleId) ?? 0) + 1);
|
|
34
|
-
}
|
|
35
|
-
for (const g of e.guardsMatched) {
|
|
36
|
-
entry.rules.set(g, (entry.rules.get(g) ?? 0) + 1);
|
|
37
|
-
}
|
|
38
|
-
intentMap.set(e.intent, entry);
|
|
39
|
-
}
|
|
40
|
-
const topPreventedIntents = [...intentMap.entries()].map(([intent, data]) => {
|
|
41
|
-
let topRule = "";
|
|
42
|
-
let topCount = 0;
|
|
43
|
-
for (const [rule, count] of data.rules) {
|
|
44
|
-
if (count > topCount) {
|
|
45
|
-
topRule = rule;
|
|
46
|
-
topCount = count;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return { intent, count: data.count, topRule };
|
|
50
|
-
}).sort((a, b) => b.count - a.count).slice(0, 15);
|
|
51
|
-
const actorMap = /* @__PURE__ */ new Map();
|
|
52
|
-
for (const e of events) {
|
|
53
|
-
const actor = e.actor ?? "unknown";
|
|
54
|
-
const entry = actorMap.get(actor) ?? { blocked: 0, paused: 0, total: 0 };
|
|
55
|
-
entry.total++;
|
|
56
|
-
if (e.decision === "BLOCK") entry.blocked++;
|
|
57
|
-
if (e.decision === "PAUSE") entry.paused++;
|
|
58
|
-
actorMap.set(actor, entry);
|
|
59
|
-
}
|
|
60
|
-
const hotActors = [...actorMap.entries()].filter(([, data]) => data.blocked > 0 || data.paused > 0).map(([actor, data]) => ({ actor, ...data })).sort((a, b) => b.blocked + b.paused - (a.blocked + a.paused)).slice(0, 10);
|
|
61
|
-
const ruleMap = /* @__PURE__ */ new Map();
|
|
62
|
-
for (const e of prevented) {
|
|
63
|
-
const ruleIds = [e.ruleId, ...e.guardsMatched, ...e.rulesMatched].filter(Boolean);
|
|
64
|
-
for (const rId of new Set(ruleIds)) {
|
|
65
|
-
const entry = ruleMap.get(rId) ?? { blockCount: 0, pauseCount: 0 };
|
|
66
|
-
if (e.decision === "BLOCK") entry.blockCount++;
|
|
67
|
-
if (e.decision === "PAUSE") entry.pauseCount++;
|
|
68
|
-
ruleMap.set(rId, entry);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
const mostActiveRules = [...ruleMap.entries()].map(([ruleId, data]) => ({ ruleId, ...data })).sort((a, b) => b.blockCount + b.pauseCount - (a.blockCount + a.pauseCount)).slice(0, 10);
|
|
72
|
-
const hourMap = /* @__PURE__ */ new Map();
|
|
73
|
-
for (const e of events) {
|
|
74
|
-
const hour = new Date(e.timestamp).getHours();
|
|
75
|
-
const entry = hourMap.get(hour) ?? { total: 0, blocked: 0 };
|
|
76
|
-
entry.total++;
|
|
77
|
-
if (e.decision === "BLOCK") entry.blocked++;
|
|
78
|
-
hourMap.set(hour, entry);
|
|
79
|
-
}
|
|
80
|
-
const hourlyDistribution = Array.from({ length: 24 }, (_, hour) => ({
|
|
81
|
-
hour,
|
|
82
|
-
total: hourMap.get(hour)?.total ?? 0,
|
|
83
|
-
blocked: hourMap.get(hour)?.blocked ?? 0
|
|
84
|
-
}));
|
|
85
|
-
const violationKey = (e) => `${e.actor ?? "unknown"}::${e.intent}`;
|
|
86
|
-
const violationMap = /* @__PURE__ */ new Map();
|
|
87
|
-
for (const e of blocked) {
|
|
88
|
-
const key = violationKey(e);
|
|
89
|
-
const entry = violationMap.get(key) ?? {
|
|
90
|
-
intent: e.intent,
|
|
91
|
-
actor: e.actor ?? "unknown",
|
|
92
|
-
attempts: 0,
|
|
93
|
-
firstSeen: e.timestamp,
|
|
94
|
-
lastSeen: e.timestamp
|
|
95
|
-
};
|
|
96
|
-
entry.attempts++;
|
|
97
|
-
entry.lastSeen = e.timestamp;
|
|
98
|
-
violationMap.set(key, entry);
|
|
99
|
-
}
|
|
100
|
-
const repeatViolations = [...violationMap.values()].filter((v) => v.attempts > 1).sort((a, b) => b.attempts - a.attempts).slice(0, 10);
|
|
101
|
-
const allowedCount = events.filter((e) => e.decision === "ALLOW").length;
|
|
102
|
-
const redirected = events.length - allowedCount - neutralEvents.length;
|
|
103
|
-
return {
|
|
104
|
-
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
105
|
-
periodStart: events[0].timestamp,
|
|
106
|
-
periodEnd: events[events.length - 1].timestamp,
|
|
107
|
-
worldName: events[0].worldName ?? "unknown",
|
|
108
|
-
totalEvaluations: events.length,
|
|
109
|
-
totalBlocked: blocked.length,
|
|
110
|
-
totalPaused: paused.length,
|
|
111
|
-
totalAllowed: allowedCount,
|
|
112
|
-
totalModified: modified.length,
|
|
113
|
-
totalPenalized: penalized.length,
|
|
114
|
-
totalRewarded: rewarded.length,
|
|
115
|
-
totalNeutral: neutralEvents.length,
|
|
116
|
-
preventionRate: events.length > 0 ? prevented.length / events.length : 0,
|
|
117
|
-
redirectionRate: events.length > 0 ? redirected / events.length : 0,
|
|
118
|
-
preventedByCategory,
|
|
119
|
-
topPreventedIntents,
|
|
120
|
-
hotActors,
|
|
121
|
-
mostActiveRules,
|
|
122
|
-
hourlyDistribution,
|
|
123
|
-
repeatViolations
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
function classifyPreventionCategory(event) {
|
|
127
|
-
const intent = event.intent.toLowerCase();
|
|
128
|
-
const rule = (event.ruleId ?? "").toLowerCase();
|
|
129
|
-
const combined = `${intent} ${rule}`;
|
|
130
|
-
if (combined.match(/inject|prompt|jailbreak|bypass/)) return "Prompt Injection Prevention";
|
|
131
|
-
if (combined.match(/scope|escape|traversal|path/)) return "Scope Escape Prevention";
|
|
132
|
-
if (combined.match(/delete|drop|destroy|remove|purge/)) return "Destructive Action Prevention";
|
|
133
|
-
if (combined.match(/trade|margin|position|leverage/)) return "Financial Risk Prevention";
|
|
134
|
-
if (combined.match(/withdraw|transfer|payment|fund/)) return "Unauthorized Transfer Prevention";
|
|
135
|
-
if (combined.match(/credential|secret|key|password|token/)) return "Credential Access Prevention";
|
|
136
|
-
if (combined.match(/shell|exec|command|script/)) return "Command Execution Prevention";
|
|
137
|
-
if (combined.match(/network|http|api|external/)) return "Network Access Prevention";
|
|
138
|
-
if (combined.match(/write|modify|update|alter/)) return "Unauthorized Modification Prevention";
|
|
139
|
-
if (combined.match(/approval|review|confirm/)) return "Approval Gate";
|
|
140
|
-
return "Policy Violation Prevention";
|
|
141
|
-
}
|
|
142
|
-
function renderImpactReport(report) {
|
|
143
|
-
const lines = [];
|
|
144
|
-
lines.push("GOVERNANCE IMPACT REPORT");
|
|
145
|
-
lines.push("\u2550".repeat(50));
|
|
146
|
-
lines.push("");
|
|
147
|
-
lines.push(` World: ${report.worldName}`);
|
|
148
|
-
lines.push(` Period: ${report.periodStart.split("T")[0]} \u2192 ${report.periodEnd.split("T")[0]}`);
|
|
149
|
-
lines.push(` Generated: ${report.generatedAt}`);
|
|
150
|
-
lines.push("");
|
|
151
|
-
lines.push("SUMMARY");
|
|
152
|
-
lines.push("\u2500".repeat(50));
|
|
153
|
-
lines.push(` Total evaluations: ${report.totalEvaluations}`);
|
|
154
|
-
lines.push(` Allowed: ${report.totalAllowed}`);
|
|
155
|
-
lines.push(` Blocked: ${report.totalBlocked}`);
|
|
156
|
-
lines.push(` Modified: ${report.totalModified}`);
|
|
157
|
-
lines.push(` Paused: ${report.totalPaused}`);
|
|
158
|
-
lines.push(` Penalized: ${report.totalPenalized}`);
|
|
159
|
-
lines.push(` Rewarded: ${report.totalRewarded}`);
|
|
160
|
-
lines.push(` Neutral: ${report.totalNeutral}`);
|
|
161
|
-
lines.push(` Prevention rate: ${(report.preventionRate * 100).toFixed(1)}%`);
|
|
162
|
-
lines.push(` Redirection rate: ${(report.redirectionRate * 100).toFixed(1)}%`);
|
|
163
|
-
lines.push("");
|
|
164
|
-
if (report.totalBlocked > 0 || report.totalPaused > 0) {
|
|
165
|
-
lines.push("WITHOUT GOVERNANCE");
|
|
166
|
-
lines.push("\u2500".repeat(50));
|
|
167
|
-
lines.push(` ${report.totalBlocked + report.totalPaused} actions would have executed unchecked:`);
|
|
168
|
-
for (const cat of report.preventedByCategory) {
|
|
169
|
-
lines.push(` ${cat.category.padEnd(38)} ${String(cat.count).padStart(5)}`);
|
|
170
|
-
if (cat.examples.length > 0) {
|
|
171
|
-
lines.push(` e.g. ${cat.examples.slice(0, 3).join(", ")}`);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
lines.push("");
|
|
175
|
-
}
|
|
176
|
-
if (report.topPreventedIntents.length > 0) {
|
|
177
|
-
lines.push("TOP PREVENTED ACTIONS");
|
|
178
|
-
lines.push("\u2500".repeat(50));
|
|
179
|
-
for (const entry of report.topPreventedIntents.slice(0, 10)) {
|
|
180
|
-
lines.push(` ${entry.intent.padEnd(30)} ${String(entry.count).padStart(5)} (rule: ${entry.topRule || "\u2014"})`);
|
|
181
|
-
}
|
|
182
|
-
lines.push("");
|
|
183
|
-
}
|
|
184
|
-
if (report.hotActors.length > 0) {
|
|
185
|
-
lines.push("ACTORS WITH MOST VIOLATIONS");
|
|
186
|
-
lines.push("\u2500".repeat(50));
|
|
187
|
-
for (const actor of report.hotActors) {
|
|
188
|
-
const violations = actor.blocked + actor.paused;
|
|
189
|
-
const rate = (violations / actor.total * 100).toFixed(0);
|
|
190
|
-
lines.push(` ${actor.actor.padEnd(25)} ${String(violations).padStart(5)} violations / ${actor.total} total (${rate}%)`);
|
|
191
|
-
}
|
|
192
|
-
lines.push("");
|
|
193
|
-
}
|
|
194
|
-
if (report.mostActiveRules.length > 0) {
|
|
195
|
-
lines.push("MOST ACTIVE RULES");
|
|
196
|
-
lines.push("\u2500".repeat(50));
|
|
197
|
-
for (const rule of report.mostActiveRules) {
|
|
198
|
-
lines.push(` ${rule.ruleId.padEnd(30)} ${String(rule.blockCount).padStart(5)} blocked ${String(rule.pauseCount).padStart(5)} paused`);
|
|
199
|
-
}
|
|
200
|
-
lines.push("");
|
|
201
|
-
}
|
|
202
|
-
if (report.repeatViolations.length > 0) {
|
|
203
|
-
lines.push("REPEAT VIOLATIONS");
|
|
204
|
-
lines.push("\u2500".repeat(50));
|
|
205
|
-
lines.push(" Actions attempted multiple times after being blocked:");
|
|
206
|
-
for (const v of report.repeatViolations) {
|
|
207
|
-
lines.push(` ${v.actor.padEnd(20)} ${v.intent.padEnd(25)} ${v.attempts}x (${v.firstSeen.split("T")[0]} \u2192 ${v.lastSeen.split("T")[0]})`);
|
|
208
|
-
}
|
|
209
|
-
lines.push("");
|
|
210
|
-
}
|
|
211
|
-
return lines.join("\n");
|
|
212
|
-
}
|
|
213
|
-
async function generateImpactReportFromFile(logPath) {
|
|
214
|
-
const events = await readAuditLog(logPath);
|
|
215
|
-
return generateImpactReport(events);
|
|
216
|
-
}
|
|
217
|
-
function emptyReport() {
|
|
218
|
-
return {
|
|
219
|
-
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
220
|
-
periodStart: "",
|
|
221
|
-
periodEnd: "",
|
|
222
|
-
worldName: "unknown",
|
|
223
|
-
totalEvaluations: 0,
|
|
224
|
-
totalBlocked: 0,
|
|
225
|
-
totalPaused: 0,
|
|
226
|
-
totalAllowed: 0,
|
|
227
|
-
totalModified: 0,
|
|
228
|
-
totalPenalized: 0,
|
|
229
|
-
totalRewarded: 0,
|
|
230
|
-
totalNeutral: 0,
|
|
231
|
-
preventionRate: 0,
|
|
232
|
-
redirectionRate: 0,
|
|
233
|
-
preventedByCategory: [],
|
|
234
|
-
topPreventedIntents: [],
|
|
235
|
-
hotActors: [],
|
|
236
|
-
mostActiveRules: [],
|
|
237
|
-
hourlyDistribution: [],
|
|
238
|
-
repeatViolations: []
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
export {
|
|
243
|
-
generateImpactReport,
|
|
244
|
-
renderImpactReport,
|
|
245
|
-
generateImpactReportFromFile
|
|
246
|
-
};
|