@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
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
export { B as BaseAdapterOptions, G as GovernanceBlockedError, P as PlanTrackingCallbacks, a as PlanTrackingState, b as buildEngineOptions, d as defaultBlockMessage, e as extractScope, t as trackPlanProgress } from '../shared-HpAG90PX.cjs';
|
|
1
2
|
export { GovernanceBlockedError as LangChainGovernanceBlockedError, NeuroVerseCallbackHandler, NeuroVerseHandlerOptions, createNeuroVerseCallbackHandler, createNeuroVerseCallbackHandlerFromWorld } from './langchain.cjs';
|
|
2
3
|
export { GovernedExecutorOptions, GovernedToolExecutor, GovernedToolResult, GovernanceBlockedError as OpenAIGovernanceBlockedError, OpenAIToolCall, createGovernedToolExecutor, createGovernedToolExecutorFromWorld } from './openai.cjs';
|
|
3
4
|
export { AgentAction, HookResult, NeuroVersePlugin, NeuroVersePluginOptions, GovernanceBlockedError as OpenClawGovernanceBlockedError, createNeuroVersePlugin, createNeuroVersePluginFromWorld } from './openclaw.cjs';
|
|
4
5
|
export { GovernanceMiddlewareOptions, GovernanceRequest, GovernanceResponse, createGovernanceMiddleware, createGovernanceMiddlewareFromWorld } from './express.cjs';
|
|
5
|
-
|
|
6
|
+
export { AutoresearchGovernor, AutoresearchGovernorConfig, ExperimentProposal, ExperimentResult, ResearchState } from './autoresearch.cjs';
|
|
7
|
+
export { GovernanceBlockedError as DeepAgentsGovernanceBlockedError, DeepAgentsGuard, DeepAgentsGuardOptions, DeepAgentsGuardResult, DeepAgentsToolCall, DeepAgentsToolCategory, createDeepAgentsGuard, createDeepAgentsGuardFromWorld } from './deep-agents.cjs';
|
|
8
|
+
import '../guard-contract-C9_zKbzd.cjs';
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
export { B as BaseAdapterOptions, G as GovernanceBlockedError, P as PlanTrackingCallbacks, a as PlanTrackingState, b as buildEngineOptions, d as defaultBlockMessage, e as extractScope, t as trackPlanProgress } from '../shared--Q8wPBVN.js';
|
|
1
2
|
export { GovernanceBlockedError as LangChainGovernanceBlockedError, NeuroVerseCallbackHandler, NeuroVerseHandlerOptions, createNeuroVerseCallbackHandler, createNeuroVerseCallbackHandlerFromWorld } from './langchain.js';
|
|
2
3
|
export { GovernedExecutorOptions, GovernedToolExecutor, GovernedToolResult, GovernanceBlockedError as OpenAIGovernanceBlockedError, OpenAIToolCall, createGovernedToolExecutor, createGovernedToolExecutorFromWorld } from './openai.js';
|
|
3
4
|
export { AgentAction, HookResult, NeuroVersePlugin, NeuroVersePluginOptions, GovernanceBlockedError as OpenClawGovernanceBlockedError, createNeuroVersePlugin, createNeuroVersePluginFromWorld } from './openclaw.js';
|
|
4
5
|
export { GovernanceMiddlewareOptions, GovernanceRequest, GovernanceResponse, createGovernanceMiddleware, createGovernanceMiddlewareFromWorld } from './express.js';
|
|
5
|
-
|
|
6
|
+
export { AutoresearchGovernor, AutoresearchGovernorConfig, ExperimentProposal, ExperimentResult, ResearchState } from './autoresearch.js';
|
|
7
|
+
export { GovernanceBlockedError as DeepAgentsGovernanceBlockedError, DeepAgentsGuard, DeepAgentsGuardOptions, DeepAgentsGuardResult, DeepAgentsToolCall, DeepAgentsToolCategory, createDeepAgentsGuard, createDeepAgentsGuardFromWorld } from './deep-agents.js';
|
|
8
|
+
import '../guard-contract-C9_zKbzd.js';
|
package/dist/adapters/index.js
CHANGED
|
@@ -1,36 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AutoresearchGovernor
|
|
3
|
+
} from "../chunk-T5EUJQE5.js";
|
|
4
|
+
import {
|
|
5
|
+
DeepAgentsGuard,
|
|
6
|
+
GovernanceBlockedError as GovernanceBlockedError2,
|
|
7
|
+
createDeepAgentsGuard,
|
|
8
|
+
createDeepAgentsGuardFromWorld
|
|
9
|
+
} from "../chunk-JCKSW2PZ.js";
|
|
1
10
|
import {
|
|
2
11
|
createGovernanceMiddleware,
|
|
3
12
|
createGovernanceMiddlewareFromWorld
|
|
4
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-4L6OPKMQ.js";
|
|
5
14
|
import {
|
|
6
|
-
GovernanceBlockedError,
|
|
15
|
+
GovernanceBlockedError as GovernanceBlockedError3,
|
|
7
16
|
NeuroVerseCallbackHandler,
|
|
8
17
|
createNeuroVerseCallbackHandler,
|
|
9
18
|
createNeuroVerseCallbackHandlerFromWorld
|
|
10
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-EVDJUSZ2.js";
|
|
11
20
|
import {
|
|
12
|
-
GovernanceBlockedError as
|
|
21
|
+
GovernanceBlockedError as GovernanceBlockedError4,
|
|
13
22
|
GovernedToolExecutor,
|
|
14
23
|
createGovernedToolExecutor,
|
|
15
24
|
createGovernedToolExecutorFromWorld
|
|
16
|
-
} from "../chunk-
|
|
25
|
+
} from "../chunk-ZIVQNSZU.js";
|
|
17
26
|
import {
|
|
18
|
-
GovernanceBlockedError as
|
|
27
|
+
GovernanceBlockedError as GovernanceBlockedError5,
|
|
19
28
|
NeuroVersePlugin,
|
|
20
29
|
createNeuroVersePlugin,
|
|
21
30
|
createNeuroVersePluginFromWorld
|
|
22
|
-
} from "../chunk-
|
|
23
|
-
import
|
|
31
|
+
} from "../chunk-6BB55YJI.js";
|
|
32
|
+
import {
|
|
33
|
+
GovernanceBlockedError,
|
|
34
|
+
buildEngineOptions,
|
|
35
|
+
defaultBlockMessage,
|
|
36
|
+
extractScope,
|
|
37
|
+
trackPlanProgress
|
|
38
|
+
} from "../chunk-5U2MQO5P.js";
|
|
39
|
+
import "../chunk-IZSO75NZ.js";
|
|
40
|
+
import "../chunk-QLPTHTVB.js";
|
|
24
41
|
import "../chunk-JZPQGIKR.js";
|
|
25
|
-
import "../chunk-4QXB6PEO.js";
|
|
26
42
|
import "../chunk-YZFATT7X.js";
|
|
27
43
|
export {
|
|
44
|
+
AutoresearchGovernor,
|
|
45
|
+
GovernanceBlockedError2 as DeepAgentsGovernanceBlockedError,
|
|
46
|
+
DeepAgentsGuard,
|
|
47
|
+
GovernanceBlockedError,
|
|
28
48
|
GovernedToolExecutor,
|
|
29
|
-
|
|
49
|
+
GovernanceBlockedError3 as LangChainGovernanceBlockedError,
|
|
30
50
|
NeuroVerseCallbackHandler,
|
|
31
51
|
NeuroVersePlugin,
|
|
32
|
-
|
|
33
|
-
|
|
52
|
+
GovernanceBlockedError4 as OpenAIGovernanceBlockedError,
|
|
53
|
+
GovernanceBlockedError5 as OpenClawGovernanceBlockedError,
|
|
54
|
+
buildEngineOptions,
|
|
55
|
+
createDeepAgentsGuard,
|
|
56
|
+
createDeepAgentsGuardFromWorld,
|
|
34
57
|
createGovernanceMiddleware,
|
|
35
58
|
createGovernanceMiddlewareFromWorld,
|
|
36
59
|
createGovernedToolExecutor,
|
|
@@ -38,5 +61,8 @@ export {
|
|
|
38
61
|
createNeuroVerseCallbackHandler,
|
|
39
62
|
createNeuroVerseCallbackHandlerFromWorld,
|
|
40
63
|
createNeuroVersePlugin,
|
|
41
|
-
createNeuroVersePluginFromWorld
|
|
64
|
+
createNeuroVersePluginFromWorld,
|
|
65
|
+
defaultBlockMessage,
|
|
66
|
+
extractScope,
|
|
67
|
+
trackPlanProgress
|
|
42
68
|
};
|
|
@@ -30,24 +30,34 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/adapters/langchain.ts
|
|
31
31
|
var langchain_exports = {};
|
|
32
32
|
__export(langchain_exports, {
|
|
33
|
-
GovernanceBlockedError: () =>
|
|
33
|
+
GovernanceBlockedError: () => GovernanceBlockedError2,
|
|
34
34
|
NeuroVerseCallbackHandler: () => NeuroVerseCallbackHandler,
|
|
35
35
|
createNeuroVerseCallbackHandler: () => createNeuroVerseCallbackHandler,
|
|
36
36
|
createNeuroVerseCallbackHandlerFromWorld: () => createNeuroVerseCallbackHandlerFromWorld
|
|
37
37
|
});
|
|
38
38
|
module.exports = __toCommonJS(langchain_exports);
|
|
39
39
|
|
|
40
|
-
// src/engine/
|
|
41
|
-
function
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
// src/engine/text-utils.ts
|
|
41
|
+
function normalizeEventText(event) {
|
|
42
|
+
return [
|
|
43
|
+
event.intent,
|
|
44
|
+
event.tool ?? "",
|
|
45
|
+
event.scope ?? ""
|
|
46
46
|
].join(" ").toLowerCase();
|
|
47
|
-
|
|
47
|
+
}
|
|
48
|
+
function extractKeywords(text, minLength = 3) {
|
|
49
|
+
return text.toLowerCase().split(/\s+/).filter((w) => w.length > minLength);
|
|
50
|
+
}
|
|
51
|
+
function matchesAllKeywords(eventText, ruleText) {
|
|
52
|
+
const keywords = extractKeywords(ruleText);
|
|
53
|
+
if (keywords.length === 0) return false;
|
|
54
|
+
return keywords.every((kw) => eventText.includes(kw));
|
|
55
|
+
}
|
|
56
|
+
function matchesKeywordThreshold(eventText, ruleText, threshold = 0.5) {
|
|
57
|
+
const keywords = extractKeywords(ruleText);
|
|
48
58
|
if (keywords.length === 0) return false;
|
|
49
59
|
const matched = keywords.filter((kw) => eventText.includes(kw));
|
|
50
|
-
return matched.length >= Math.ceil(keywords.length *
|
|
60
|
+
return matched.length >= Math.ceil(keywords.length * threshold);
|
|
51
61
|
}
|
|
52
62
|
function tokenSimilarity(a, b) {
|
|
53
63
|
const tokensA = new Set(a.toLowerCase().split(/\s+/).filter((w) => w.length > 2));
|
|
@@ -60,6 +70,19 @@ function tokenSimilarity(a, b) {
|
|
|
60
70
|
const union = (/* @__PURE__ */ new Set([...tokensA, ...tokensB])).size;
|
|
61
71
|
return union > 0 ? intersection / union : 0;
|
|
62
72
|
}
|
|
73
|
+
|
|
74
|
+
// src/engine/plan-engine.ts
|
|
75
|
+
function keywordMatch(eventText, step) {
|
|
76
|
+
const stepText = [
|
|
77
|
+
step.label,
|
|
78
|
+
step.description ?? "",
|
|
79
|
+
...step.tags ?? []
|
|
80
|
+
].join(" ");
|
|
81
|
+
return matchesKeywordThreshold(eventText, stepText, 0.5);
|
|
82
|
+
}
|
|
83
|
+
function tokenSimilarity2(a, b) {
|
|
84
|
+
return tokenSimilarity(a, b);
|
|
85
|
+
}
|
|
63
86
|
function findMatchingStep(eventText, event, steps) {
|
|
64
87
|
const pendingOrActive = steps.filter((s) => s.status === "pending" || s.status === "active");
|
|
65
88
|
if (pendingOrActive.length === 0) {
|
|
@@ -78,7 +101,7 @@ function findMatchingStep(eventText, event, steps) {
|
|
|
78
101
|
let bestScore = 0;
|
|
79
102
|
for (const step of pendingOrActive) {
|
|
80
103
|
const stepText = [step.label, step.description ?? "", ...step.tags ?? []].join(" ");
|
|
81
|
-
const score =
|
|
104
|
+
const score = tokenSimilarity2(intentText, stepText);
|
|
82
105
|
if (score > bestScore) {
|
|
83
106
|
bestScore = score;
|
|
84
107
|
bestStep = step;
|
|
@@ -119,7 +142,7 @@ function checkConstraints(event, eventText, constraints) {
|
|
|
119
142
|
continue;
|
|
120
143
|
}
|
|
121
144
|
if (constraint.type === "scope" && constraint.trigger) {
|
|
122
|
-
const keywords = constraint.trigger
|
|
145
|
+
const keywords = extractKeywords(constraint.trigger);
|
|
123
146
|
const violated = keywords.length > 0 && keywords.every((kw) => eventText.includes(kw));
|
|
124
147
|
checks.push({
|
|
125
148
|
constraintId: constraint.id,
|
|
@@ -200,11 +223,7 @@ function evaluatePlan(event, plan) {
|
|
|
200
223
|
progress
|
|
201
224
|
};
|
|
202
225
|
}
|
|
203
|
-
const eventText =
|
|
204
|
-
event.intent,
|
|
205
|
-
event.tool ?? "",
|
|
206
|
-
event.scope ?? ""
|
|
207
|
-
].join(" ").toLowerCase();
|
|
226
|
+
const eventText = normalizeEventText(event);
|
|
208
227
|
const { matched, closest, closestScore } = findMatchingStep(eventText, event, plan.steps);
|
|
209
228
|
if (!matched) {
|
|
210
229
|
return {
|
|
@@ -245,7 +264,7 @@ function evaluatePlan(event, plan) {
|
|
|
245
264
|
};
|
|
246
265
|
}
|
|
247
266
|
function buildPlanCheck(event, plan, verdict) {
|
|
248
|
-
const eventText =
|
|
267
|
+
const eventText = normalizeEventText(event);
|
|
249
268
|
const { matched, closest, closestScore } = findMatchingStep(eventText, event, plan.steps);
|
|
250
269
|
const { checks: constraintChecks } = checkConstraints(event, eventText, plan.constraints);
|
|
251
270
|
const progress = getPlanProgress(plan);
|
|
@@ -351,7 +370,7 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
351
370
|
const startTime = performance.now();
|
|
352
371
|
const level = options.level ?? "standard";
|
|
353
372
|
const includeTrace = options.trace ?? false;
|
|
354
|
-
const eventText = (event
|
|
373
|
+
const eventText = normalizeEventText(event);
|
|
355
374
|
const invariantChecks = [];
|
|
356
375
|
const safetyChecks = [];
|
|
357
376
|
let planCheckResult;
|
|
@@ -364,6 +383,43 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
364
383
|
const guardsMatched = [];
|
|
365
384
|
const rulesMatched = [];
|
|
366
385
|
checkInvariantCoverage(world, invariantChecks);
|
|
386
|
+
if (event.roleId && options.agentStates) {
|
|
387
|
+
const agentState = options.agentStates.get(event.roleId);
|
|
388
|
+
if (agentState && agentState.cooldownRemaining > 0) {
|
|
389
|
+
decidingLayer = "safety";
|
|
390
|
+
decidingId = `penalize-cooldown-${event.roleId}`;
|
|
391
|
+
const verdict = buildVerdict(
|
|
392
|
+
"PENALIZE",
|
|
393
|
+
`Agent "${event.roleId}" is frozen for ${agentState.cooldownRemaining} more round(s) due to prior penalty.`,
|
|
394
|
+
`penalize-cooldown-${event.roleId}`,
|
|
395
|
+
void 0,
|
|
396
|
+
world,
|
|
397
|
+
level,
|
|
398
|
+
invariantChecks,
|
|
399
|
+
guardsMatched,
|
|
400
|
+
rulesMatched,
|
|
401
|
+
includeTrace ? buildTrace(
|
|
402
|
+
invariantChecks,
|
|
403
|
+
safetyChecks,
|
|
404
|
+
planCheckResult,
|
|
405
|
+
roleChecks,
|
|
406
|
+
guardChecks,
|
|
407
|
+
kernelRuleChecks,
|
|
408
|
+
levelChecks,
|
|
409
|
+
decidingLayer,
|
|
410
|
+
decidingId,
|
|
411
|
+
startTime
|
|
412
|
+
) : void 0
|
|
413
|
+
);
|
|
414
|
+
verdict.intentRecord = {
|
|
415
|
+
originalIntent: event.intent,
|
|
416
|
+
finalAction: "blocked (agent frozen)",
|
|
417
|
+
enforcement: "PENALIZE",
|
|
418
|
+
consequence: { type: "freeze", rounds: agentState.cooldownRemaining, description: "Agent still in cooldown from prior penalty" }
|
|
419
|
+
};
|
|
420
|
+
return verdict;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
367
423
|
if (options.sessionAllowlist) {
|
|
368
424
|
const key = eventToAllowlistKey(event);
|
|
369
425
|
if (options.sessionAllowlist.has(key)) {
|
|
@@ -491,7 +547,16 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
491
547
|
if (guardVerdict.status !== "ALLOW") {
|
|
492
548
|
decidingLayer = "guard";
|
|
493
549
|
decidingId = guardVerdict.ruleId;
|
|
494
|
-
|
|
550
|
+
const intentRecord = {
|
|
551
|
+
originalIntent: event.intent,
|
|
552
|
+
finalAction: guardVerdict.status === "MODIFY" ? guardVerdict.modifiedTo ?? "modified" : guardVerdict.status === "PENALIZE" ? "blocked + penalized" : guardVerdict.status === "REWARD" ? event.intent : guardVerdict.status === "NEUTRAL" ? event.intent : guardVerdict.status === "BLOCK" ? "blocked" : "paused",
|
|
553
|
+
ruleApplied: guardVerdict.ruleId,
|
|
554
|
+
enforcement: guardVerdict.status,
|
|
555
|
+
modifiedTo: guardVerdict.modifiedTo,
|
|
556
|
+
consequence: guardVerdict.consequence,
|
|
557
|
+
reward: guardVerdict.reward
|
|
558
|
+
};
|
|
559
|
+
const verdict = buildVerdict(
|
|
495
560
|
guardVerdict.status,
|
|
496
561
|
guardVerdict.reason,
|
|
497
562
|
guardVerdict.ruleId,
|
|
@@ -514,6 +579,10 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
514
579
|
startTime
|
|
515
580
|
) : void 0
|
|
516
581
|
);
|
|
582
|
+
verdict.intentRecord = intentRecord;
|
|
583
|
+
if (guardVerdict.consequence) verdict.consequence = guardVerdict.consequence;
|
|
584
|
+
if (guardVerdict.reward) verdict.reward = guardVerdict.reward;
|
|
585
|
+
return verdict;
|
|
517
586
|
}
|
|
518
587
|
}
|
|
519
588
|
const kernelVerdict = checkKernelRules(eventText, world, kernelRuleChecks, rulesMatched);
|
|
@@ -808,6 +877,21 @@ function checkGuards(event, eventText, world, checks, guardsMatched) {
|
|
|
808
877
|
if (actionMode === "pause") {
|
|
809
878
|
return { status: "PAUSE", reason, ruleId: `guard-${guard.id}` };
|
|
810
879
|
}
|
|
880
|
+
if (actionMode === "penalize") {
|
|
881
|
+
const consequence = guard.consequence ? { ...guard.consequence } : { type: "freeze", rounds: 1, description: `Penalized for violating: ${guard.label}` };
|
|
882
|
+
return { status: "PENALIZE", reason, ruleId: `guard-${guard.id}`, consequence };
|
|
883
|
+
}
|
|
884
|
+
if (actionMode === "reward") {
|
|
885
|
+
const reward = guard.reward ? { ...guard.reward } : { type: "boost_influence", magnitude: 0.1, description: `Rewarded for: ${guard.label}` };
|
|
886
|
+
return { status: "REWARD", reason, ruleId: `guard-${guard.id}`, reward };
|
|
887
|
+
}
|
|
888
|
+
if (actionMode === "modify") {
|
|
889
|
+
const modifiedTo = guard.modify_to ?? guard.redirect ?? "hold";
|
|
890
|
+
return { status: "MODIFY", reason: `${reason} \u2192 Modified to: ${modifiedTo}`, ruleId: `guard-${guard.id}`, modifiedTo };
|
|
891
|
+
}
|
|
892
|
+
if (actionMode === "neutral") {
|
|
893
|
+
return { status: "NEUTRAL", reason, ruleId: `guard-${guard.id}` };
|
|
894
|
+
}
|
|
811
895
|
if (actionMode === "warn" && !warnResult) {
|
|
812
896
|
warnResult = { status: "ALLOW", warning: reason, ruleId: `guard-${guard.id}` };
|
|
813
897
|
}
|
|
@@ -917,9 +1001,7 @@ function checkLevelConstraints(event, level, checks) {
|
|
|
917
1001
|
return null;
|
|
918
1002
|
}
|
|
919
1003
|
function matchesKeywords(eventText, ruleText) {
|
|
920
|
-
|
|
921
|
-
if (keywords.length === 0) return false;
|
|
922
|
-
return keywords.every((kw) => eventText.includes(kw));
|
|
1004
|
+
return matchesAllKeywords(eventText, ruleText);
|
|
923
1005
|
}
|
|
924
1006
|
function eventToAllowlistKey(event) {
|
|
925
1007
|
return `${(event.tool ?? "*").toLowerCase()}::${event.intent.toLowerCase().trim()}`;
|
|
@@ -1056,14 +1138,52 @@ async function loadWorld(worldPath) {
|
|
|
1056
1138
|
throw new Error(`Cannot load world from: ${worldPath} \u2014 expected a directory or .nv-world.zip`);
|
|
1057
1139
|
}
|
|
1058
1140
|
|
|
1059
|
-
// src/adapters/
|
|
1141
|
+
// src/adapters/shared.ts
|
|
1060
1142
|
var GovernanceBlockedError = class extends Error {
|
|
1061
1143
|
verdict;
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
super(`[NeuroVerse] BLOCKED: ${verdict.reason ?? verdict.ruleId ?? "governance rule"}`);
|
|
1144
|
+
constructor(verdict, message) {
|
|
1145
|
+
super(message ?? `[NeuroVerse] BLOCKED: ${verdict.reason ?? verdict.ruleId ?? "governance rule"}`);
|
|
1065
1146
|
this.name = "GovernanceBlockedError";
|
|
1066
1147
|
this.verdict = verdict;
|
|
1148
|
+
}
|
|
1149
|
+
};
|
|
1150
|
+
function trackPlanProgress(event, state, callbacks) {
|
|
1151
|
+
if (!state.activePlan) return;
|
|
1152
|
+
const planVerdict = evaluatePlan(event, state.activePlan);
|
|
1153
|
+
if (planVerdict.matchedStep) {
|
|
1154
|
+
const advResult = advancePlan(state.activePlan, planVerdict.matchedStep);
|
|
1155
|
+
if (advResult.success && advResult.plan) {
|
|
1156
|
+
state.activePlan = advResult.plan;
|
|
1157
|
+
state.engineOptions.plan = state.activePlan;
|
|
1158
|
+
}
|
|
1159
|
+
const progress = getPlanProgress(state.activePlan);
|
|
1160
|
+
callbacks.onPlanProgress?.(progress);
|
|
1161
|
+
if (progress.completed === progress.total) {
|
|
1162
|
+
callbacks.onPlanComplete?.();
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
function extractScope(args) {
|
|
1167
|
+
if (typeof args.path === "string") return args.path;
|
|
1168
|
+
if (typeof args.file_path === "string") return args.file_path;
|
|
1169
|
+
if (typeof args.filename === "string") return args.filename;
|
|
1170
|
+
if (typeof args.url === "string") return args.url;
|
|
1171
|
+
if (typeof args.command === "string") return args.command;
|
|
1172
|
+
return void 0;
|
|
1173
|
+
}
|
|
1174
|
+
function buildEngineOptions(options, plan) {
|
|
1175
|
+
return {
|
|
1176
|
+
trace: options.trace ?? false,
|
|
1177
|
+
level: options.level,
|
|
1178
|
+
plan: plan ?? options.plan
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
// src/adapters/langchain.ts
|
|
1183
|
+
var GovernanceBlockedError2 = class extends GovernanceBlockedError {
|
|
1184
|
+
event;
|
|
1185
|
+
constructor(verdict, event) {
|
|
1186
|
+
super(verdict);
|
|
1067
1187
|
this.event = event;
|
|
1068
1188
|
}
|
|
1069
1189
|
};
|
|
@@ -1071,7 +1191,7 @@ function defaultMapToolCall(toolName, toolInput) {
|
|
|
1071
1191
|
return {
|
|
1072
1192
|
intent: toolName,
|
|
1073
1193
|
tool: toolName,
|
|
1074
|
-
scope:
|
|
1194
|
+
scope: extractScope(toolInput),
|
|
1075
1195
|
args: toolInput,
|
|
1076
1196
|
direction: "input"
|
|
1077
1197
|
};
|
|
@@ -1087,11 +1207,7 @@ var NeuroVerseCallbackHandler = class {
|
|
|
1087
1207
|
this.world = world;
|
|
1088
1208
|
this.options = options;
|
|
1089
1209
|
this.activePlan = options.plan;
|
|
1090
|
-
this.engineOptions =
|
|
1091
|
-
trace: options.trace ?? false,
|
|
1092
|
-
level: options.level,
|
|
1093
|
-
plan: this.activePlan
|
|
1094
|
-
};
|
|
1210
|
+
this.engineOptions = buildEngineOptions(options, this.activePlan);
|
|
1095
1211
|
this.mapToolCall = options.mapToolCall ?? defaultMapToolCall;
|
|
1096
1212
|
}
|
|
1097
1213
|
/**
|
|
@@ -1114,28 +1230,16 @@ var NeuroVerseCallbackHandler = class {
|
|
|
1114
1230
|
this.options.onEvaluate?.(verdict, event);
|
|
1115
1231
|
if (verdict.status === "BLOCK") {
|
|
1116
1232
|
this.options.onBlock?.(verdict, event);
|
|
1117
|
-
throw new
|
|
1233
|
+
throw new GovernanceBlockedError2(verdict, event);
|
|
1118
1234
|
}
|
|
1119
1235
|
if (verdict.status === "PAUSE") {
|
|
1120
1236
|
const approved = await this.options.onPause?.(verdict, event);
|
|
1121
1237
|
if (!approved) {
|
|
1122
|
-
throw new
|
|
1238
|
+
throw new GovernanceBlockedError2(verdict, event);
|
|
1123
1239
|
}
|
|
1124
1240
|
}
|
|
1125
|
-
if (verdict.status === "ALLOW"
|
|
1126
|
-
|
|
1127
|
-
if (planVerdict.matchedStep) {
|
|
1128
|
-
const advResult = advancePlan(this.activePlan, planVerdict.matchedStep);
|
|
1129
|
-
if (advResult.success && advResult.plan) {
|
|
1130
|
-
this.activePlan = advResult.plan;
|
|
1131
|
-
this.engineOptions.plan = this.activePlan;
|
|
1132
|
-
}
|
|
1133
|
-
const progress = getPlanProgress(this.activePlan);
|
|
1134
|
-
this.options.onPlanProgress?.(progress);
|
|
1135
|
-
if (progress.completed === progress.total) {
|
|
1136
|
-
this.options.onPlanComplete?.();
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1241
|
+
if (verdict.status === "ALLOW") {
|
|
1242
|
+
trackPlanProgress(event, this, this.options);
|
|
1139
1243
|
}
|
|
1140
1244
|
}
|
|
1141
1245
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { G as
|
|
1
|
+
import { G as GuardEvent, a as GuardVerdict, b as GuardEngineOptions, P as PlanDefinition, W as WorldDefinition, c as PlanProgress } from '../guard-contract-C9_zKbzd.cjs';
|
|
2
|
+
import { G as GovernanceBlockedError$1 } from '../shared-HpAG90PX.cjs';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* NeuroVerse Adapter — LangChain
|
|
@@ -38,8 +39,7 @@ interface NeuroVerseHandlerOptions {
|
|
|
38
39
|
/** Called when all plan steps are completed. */
|
|
39
40
|
onPlanComplete?: () => void;
|
|
40
41
|
}
|
|
41
|
-
declare class GovernanceBlockedError extends
|
|
42
|
-
readonly verdict: GuardVerdict;
|
|
42
|
+
declare class GovernanceBlockedError extends GovernanceBlockedError$1 {
|
|
43
43
|
readonly event: GuardEvent;
|
|
44
44
|
constructor(verdict: GuardVerdict, event: GuardEvent);
|
|
45
45
|
}
|
|
@@ -54,9 +54,9 @@ declare class NeuroVerseCallbackHandler {
|
|
|
54
54
|
readonly name = "NeuroVerseGovernance";
|
|
55
55
|
private world;
|
|
56
56
|
private options;
|
|
57
|
-
|
|
57
|
+
engineOptions: GuardEngineOptions;
|
|
58
58
|
private mapToolCall;
|
|
59
|
-
|
|
59
|
+
activePlan?: PlanDefinition;
|
|
60
60
|
constructor(world: WorldDefinition, options?: NeuroVerseHandlerOptions);
|
|
61
61
|
/**
|
|
62
62
|
* Called before a tool is executed.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { G as
|
|
1
|
+
import { G as GuardEvent, a as GuardVerdict, b as GuardEngineOptions, P as PlanDefinition, W as WorldDefinition, c as PlanProgress } from '../guard-contract-C9_zKbzd.js';
|
|
2
|
+
import { G as GovernanceBlockedError$1 } from '../shared--Q8wPBVN.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* NeuroVerse Adapter — LangChain
|
|
@@ -38,8 +39,7 @@ interface NeuroVerseHandlerOptions {
|
|
|
38
39
|
/** Called when all plan steps are completed. */
|
|
39
40
|
onPlanComplete?: () => void;
|
|
40
41
|
}
|
|
41
|
-
declare class GovernanceBlockedError extends
|
|
42
|
-
readonly verdict: GuardVerdict;
|
|
42
|
+
declare class GovernanceBlockedError extends GovernanceBlockedError$1 {
|
|
43
43
|
readonly event: GuardEvent;
|
|
44
44
|
constructor(verdict: GuardVerdict, event: GuardEvent);
|
|
45
45
|
}
|
|
@@ -54,9 +54,9 @@ declare class NeuroVerseCallbackHandler {
|
|
|
54
54
|
readonly name = "NeuroVerseGovernance";
|
|
55
55
|
private world;
|
|
56
56
|
private options;
|
|
57
|
-
|
|
57
|
+
engineOptions: GuardEngineOptions;
|
|
58
58
|
private mapToolCall;
|
|
59
|
-
|
|
59
|
+
activePlan?: PlanDefinition;
|
|
60
60
|
constructor(world: WorldDefinition, options?: NeuroVerseHandlerOptions);
|
|
61
61
|
/**
|
|
62
62
|
* Called before a tool is executed.
|
|
@@ -3,10 +3,11 @@ import {
|
|
|
3
3
|
NeuroVerseCallbackHandler,
|
|
4
4
|
createNeuroVerseCallbackHandler,
|
|
5
5
|
createNeuroVerseCallbackHandlerFromWorld
|
|
6
|
-
} from "../chunk-
|
|
7
|
-
import "../chunk-
|
|
6
|
+
} from "../chunk-EVDJUSZ2.js";
|
|
7
|
+
import "../chunk-5U2MQO5P.js";
|
|
8
|
+
import "../chunk-IZSO75NZ.js";
|
|
9
|
+
import "../chunk-QLPTHTVB.js";
|
|
8
10
|
import "../chunk-JZPQGIKR.js";
|
|
9
|
-
import "../chunk-4QXB6PEO.js";
|
|
10
11
|
import "../chunk-YZFATT7X.js";
|
|
11
12
|
export {
|
|
12
13
|
GovernanceBlockedError,
|