@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.
Files changed (91) hide show
  1. package/.well-known/ai-plugin.json +26 -0
  2. package/.well-known/mcp.json +68 -0
  3. package/AGENTS.md +219 -0
  4. package/README.md +84 -4
  5. package/dist/adapters/autoresearch.cjs +196 -0
  6. package/dist/adapters/autoresearch.d.cts +103 -0
  7. package/dist/adapters/autoresearch.d.ts +103 -0
  8. package/dist/adapters/autoresearch.js +7 -0
  9. package/dist/adapters/deep-agents.cjs +1472 -0
  10. package/dist/adapters/deep-agents.d.cts +181 -0
  11. package/dist/adapters/deep-agents.d.ts +181 -0
  12. package/dist/adapters/deep-agents.js +17 -0
  13. package/dist/adapters/express.cjs +103 -21
  14. package/dist/adapters/express.d.cts +1 -1
  15. package/dist/adapters/express.d.ts +1 -1
  16. package/dist/adapters/express.js +3 -3
  17. package/dist/adapters/index.cjs +649 -109
  18. package/dist/adapters/index.d.cts +4 -1
  19. package/dist/adapters/index.d.ts +4 -1
  20. package/dist/adapters/index.js +39 -13
  21. package/dist/adapters/langchain.cjs +152 -48
  22. package/dist/adapters/langchain.d.cts +5 -5
  23. package/dist/adapters/langchain.d.ts +5 -5
  24. package/dist/adapters/langchain.js +4 -3
  25. package/dist/adapters/openai.cjs +154 -50
  26. package/dist/adapters/openai.d.cts +5 -5
  27. package/dist/adapters/openai.d.ts +5 -5
  28. package/dist/adapters/openai.js +4 -3
  29. package/dist/adapters/openclaw.cjs +152 -48
  30. package/dist/adapters/openclaw.d.cts +5 -5
  31. package/dist/adapters/openclaw.d.ts +5 -5
  32. package/dist/adapters/openclaw.js +4 -3
  33. package/dist/{build-P42YFKQV.js → build-X5MZY4IA.js} +2 -2
  34. package/dist/{chunk-2NICNKOM.js → chunk-4L6OPKMQ.js} +1 -1
  35. package/dist/chunk-5U2MQO5P.js +57 -0
  36. package/dist/{chunk-SKU3GAPD.js → chunk-6BB55YJI.js} +16 -34
  37. package/dist/{chunk-KEST3MWO.js → chunk-AF2VX4AL.js} +47 -8
  38. package/dist/chunk-BQZMOEML.js +43 -0
  39. package/dist/chunk-D2UCV5AK.js +326 -0
  40. package/dist/{chunk-RWXVAH6P.js → chunk-EVDJUSZ2.js} +16 -34
  41. package/dist/{chunk-4JRYGIO7.js → chunk-IZSO75NZ.js} +72 -7
  42. package/dist/chunk-JCKSW2PZ.js +304 -0
  43. package/dist/{chunk-PDOZHZWL.js → chunk-KTFTTLTP.js} +25 -4
  44. package/dist/{chunk-MWDQ4MJB.js → chunk-MH7BT4VH.js} +5 -1
  45. package/dist/{chunk-4QXB6PEO.js → chunk-QLPTHTVB.js} +37 -16
  46. package/dist/{chunk-QPASI2BR.js → chunk-REXY4LUL.js} +49 -10
  47. package/dist/chunk-T5EUJQE5.js +172 -0
  48. package/dist/{chunk-DPVS43ZT.js → chunk-TTBKTF3P.js} +5 -5
  49. package/dist/{chunk-OHAC6HJE.js → chunk-ZIVQNSZU.js} +16 -36
  50. package/dist/{chunk-BUWWN2NX.js → chunk-ZJTDUCC2.js} +9 -7
  51. package/dist/cli/neuroverse.cjs +2582 -493
  52. package/dist/cli/neuroverse.js +39 -15
  53. package/dist/cli/plan.cjs +119 -32
  54. package/dist/cli/plan.js +5 -13
  55. package/dist/cli/run.cjs +223 -24
  56. package/dist/cli/run.js +2 -2
  57. package/dist/decision-flow-LETV5NWY.js +61 -0
  58. package/dist/{derive-TLIV4OOU.js → derive-7365SUFU.js} +2 -2
  59. package/dist/{doctor-QV6HELS5.js → doctor-QYISMKEL.js} +5 -2
  60. package/dist/equity-penalties-63FGB3I2.js +244 -0
  61. package/dist/{explain-IDCRWMPX.js → explain-A2EWI2OL.js} +4 -23
  62. package/dist/{guard-GFLQZY6U.js → guard-3BWL3IGH.js} +6 -10
  63. package/dist/{guard-contract-Cm91Kp4j.d.ts → guard-contract-C9_zKbzd.d.cts} +117 -5
  64. package/dist/{guard-contract-Cm91Kp4j.d.cts → guard-contract-C9_zKbzd.d.ts} +117 -5
  65. package/dist/{guard-engine-JLTUARGU.js → guard-engine-QFMIBWJY.js} +2 -2
  66. package/dist/{impact-XPECYRLH.js → impact-UB6DXKSX.js} +4 -4
  67. package/dist/{improve-GPUBKTEA.js → improve-XZA57GER.js} +5 -24
  68. package/dist/index.cjs +592 -44
  69. package/dist/index.d.cts +218 -5
  70. package/dist/index.d.ts +218 -5
  71. package/dist/index.js +92 -41
  72. package/dist/infer-world-7GVZWFX4.js +543 -0
  73. package/dist/init-world-VWMQZQC7.js +223 -0
  74. package/dist/{mcp-server-LZVJHBT5.js → mcp-server-XWQZXNW7.js} +3 -3
  75. package/dist/{playground-FGOMASHN.js → playground-ADWZORNV.js} +2 -2
  76. package/dist/{redteam-SK7AMIG3.js → redteam-JRQ7FD2F.js} +2 -2
  77. package/dist/{session-VISISNWJ.js → session-MMYX5YCF.js} +4 -3
  78. package/dist/shared--Q8wPBVN.d.ts +60 -0
  79. package/dist/shared-HpAG90PX.d.cts +60 -0
  80. package/dist/shared-U2QFV7JH.js +16 -0
  81. package/dist/{simulate-VDOYQFRO.js → simulate-GMIFFXYV.js} +5 -30
  82. package/dist/{test-75AVHC3R.js → test-JBBZ65X4.js} +2 -2
  83. package/dist/{trace-JVF67VR3.js → trace-3MYWIDEF.js} +3 -3
  84. package/dist/worlds/autoresearch.nv-world.md +230 -0
  85. package/dist/worlds/coding-agent.nv-world.md +211 -0
  86. package/llms.txt +79 -0
  87. package/openapi.yaml +230 -0
  88. package/package.json +26 -4
  89. package/dist/{chunk-GR6DGCZ2.js → chunk-BMOXICAB.js} +3 -3
  90. package/dist/{chunk-NF5POFCI.js → chunk-ORJ3NOE6.js} +3 -3
  91. package/dist/{world-LAXO6DOX.js → world-BFJCIQSH.js} +3 -3
@@ -30,24 +30,34 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/adapters/openclaw.ts
31
31
  var openclaw_exports = {};
32
32
  __export(openclaw_exports, {
33
- GovernanceBlockedError: () => GovernanceBlockedError,
33
+ GovernanceBlockedError: () => GovernanceBlockedError2,
34
34
  NeuroVersePlugin: () => NeuroVersePlugin,
35
35
  createNeuroVersePlugin: () => createNeuroVersePlugin,
36
36
  createNeuroVersePluginFromWorld: () => createNeuroVersePluginFromWorld
37
37
  });
38
38
  module.exports = __toCommonJS(openclaw_exports);
39
39
 
40
- // src/engine/plan-engine.ts
41
- function keywordMatch(eventText, step) {
42
- const stepText = [
43
- step.label,
44
- step.description ?? "",
45
- ...step.tags ?? []
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
- const keywords = stepText.split(/\s+/).filter((w) => w.length > 3);
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 * 0.5);
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 = tokenSimilarity(intentText, stepText);
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.split(/\s+/).filter((w) => w.length > 3);
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 = [event.intent, event.tool ?? "", event.scope ?? ""].join(" ").toLowerCase();
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.intent + " " + (event.tool ?? "") + " " + (event.scope ?? "")).toLowerCase();
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
- return buildVerdict(
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
- const keywords = ruleText.toLowerCase().split(/\s+/).filter((w) => w.length > 3);
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/openclaw.ts
1141
+ // src/adapters/shared.ts
1060
1142
  var GovernanceBlockedError = class extends Error {
1061
1143
  verdict;
1062
- action;
1063
- constructor(verdict, action) {
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/openclaw.ts
1183
+ var GovernanceBlockedError2 = class extends GovernanceBlockedError {
1184
+ action;
1185
+ constructor(verdict, action) {
1186
+ super(verdict);
1067
1187
  this.action = action;
1068
1188
  }
1069
1189
  };
@@ -1073,7 +1193,7 @@ function defaultMapAction(action, direction) {
1073
1193
  tool: action.tool ?? action.type,
1074
1194
  args: action.input,
1075
1195
  direction,
1076
- scope: typeof action.input?.path === "string" ? action.input.path : typeof action.input?.url === "string" ? action.input.url : void 0
1196
+ scope: action.input ? extractScope(action.input) : void 0
1077
1197
  };
1078
1198
  }
1079
1199
  var NeuroVersePlugin = class {
@@ -1087,11 +1207,7 @@ var NeuroVersePlugin = 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.mapAction = options.mapAction ?? defaultMapAction;
1096
1212
  }
1097
1213
  /**
@@ -1111,22 +1227,10 @@ var NeuroVersePlugin = class {
1111
1227
  };
1112
1228
  this.options.onEvaluate?.(result);
1113
1229
  if (verdict.status === "BLOCK") {
1114
- throw new GovernanceBlockedError(verdict, action);
1230
+ throw new GovernanceBlockedError2(verdict, action);
1115
1231
  }
1116
- if (verdict.status === "ALLOW" && this.activePlan) {
1117
- const planVerdict = evaluatePlan(event, this.activePlan);
1118
- if (planVerdict.matchedStep) {
1119
- const advResult = advancePlan(this.activePlan, planVerdict.matchedStep);
1120
- if (advResult.success && advResult.plan) {
1121
- this.activePlan = advResult.plan;
1122
- this.engineOptions.plan = this.activePlan;
1123
- }
1124
- const progress = getPlanProgress(this.activePlan);
1125
- this.options.onPlanProgress?.(progress);
1126
- if (progress.completed === progress.total) {
1127
- this.options.onPlanComplete?.();
1128
- }
1129
- }
1232
+ if (verdict.status === "ALLOW") {
1233
+ trackPlanProgress(event, this, this.options);
1130
1234
  }
1131
1235
  return result;
1132
1236
  }
@@ -1147,7 +1251,7 @@ var NeuroVersePlugin = class {
1147
1251
  };
1148
1252
  this.options.onEvaluate?.(result);
1149
1253
  if (verdict.status === "BLOCK") {
1150
- throw new GovernanceBlockedError(verdict, action);
1254
+ throw new GovernanceBlockedError2(verdict, action);
1151
1255
  }
1152
1256
  return result;
1153
1257
  }
@@ -1,4 +1,5 @@
1
- import { G as GuardVerdict, W as WorldDefinition, a as GuardEvent, P as PlanDefinition, b as PlanProgress } from '../guard-contract-Cm91Kp4j.cjs';
1
+ import { a as GuardVerdict, b as GuardEngineOptions, P as PlanDefinition, W as WorldDefinition, G as GuardEvent, 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 — OpenClaw
@@ -45,8 +46,7 @@ interface NeuroVersePluginOptions {
45
46
  /** Called when all plan steps are completed. */
46
47
  onPlanComplete?: () => void;
47
48
  }
48
- declare class GovernanceBlockedError extends Error {
49
- readonly verdict: GuardVerdict;
49
+ declare class GovernanceBlockedError extends GovernanceBlockedError$1 {
50
50
  readonly action: AgentAction;
51
51
  constructor(verdict: GuardVerdict, action: AgentAction);
52
52
  }
@@ -61,9 +61,9 @@ declare class NeuroVersePlugin {
61
61
  readonly name = "neuroverse-governance";
62
62
  private world;
63
63
  private options;
64
- private engineOptions;
64
+ engineOptions: GuardEngineOptions;
65
65
  private mapAction;
66
- private activePlan?;
66
+ activePlan?: PlanDefinition;
67
67
  constructor(world: WorldDefinition, options?: NeuroVersePluginOptions);
68
68
  /**
69
69
  * Evaluate an action before execution.
@@ -1,4 +1,5 @@
1
- import { G as GuardVerdict, W as WorldDefinition, a as GuardEvent, P as PlanDefinition, b as PlanProgress } from '../guard-contract-Cm91Kp4j.js';
1
+ import { a as GuardVerdict, b as GuardEngineOptions, P as PlanDefinition, W as WorldDefinition, G as GuardEvent, 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 — OpenClaw
@@ -45,8 +46,7 @@ interface NeuroVersePluginOptions {
45
46
  /** Called when all plan steps are completed. */
46
47
  onPlanComplete?: () => void;
47
48
  }
48
- declare class GovernanceBlockedError extends Error {
49
- readonly verdict: GuardVerdict;
49
+ declare class GovernanceBlockedError extends GovernanceBlockedError$1 {
50
50
  readonly action: AgentAction;
51
51
  constructor(verdict: GuardVerdict, action: AgentAction);
52
52
  }
@@ -61,9 +61,9 @@ declare class NeuroVersePlugin {
61
61
  readonly name = "neuroverse-governance";
62
62
  private world;
63
63
  private options;
64
- private engineOptions;
64
+ engineOptions: GuardEngineOptions;
65
65
  private mapAction;
66
- private activePlan?;
66
+ activePlan?: PlanDefinition;
67
67
  constructor(world: WorldDefinition, options?: NeuroVersePluginOptions);
68
68
  /**
69
69
  * Evaluate an action before execution.
@@ -3,10 +3,11 @@ import {
3
3
  NeuroVersePlugin,
4
4
  createNeuroVersePlugin,
5
5
  createNeuroVersePluginFromWorld
6
- } from "../chunk-SKU3GAPD.js";
7
- import "../chunk-4JRYGIO7.js";
6
+ } from "../chunk-6BB55YJI.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,
@@ -2,15 +2,15 @@ import {
2
2
  DeriveInputError,
3
3
  DeriveProviderError,
4
4
  deriveWorld
5
- } from "./chunk-NF5POFCI.js";
5
+ } from "./chunk-ORJ3NOE6.js";
6
6
  import {
7
7
  DERIVE_EXIT_CODES
8
8
  } from "./chunk-Q6O7ZLO2.js";
9
- import "./chunk-OT6PXH54.js";
10
9
  import {
11
10
  emitWorldDefinition,
12
11
  parseWorldMarkdown
13
12
  } from "./chunk-XPDMYECO.js";
13
+ import "./chunk-OT6PXH54.js";
14
14
  import "./chunk-7P3S7MAY.js";
15
15
  import "./chunk-YZFATT7X.js";
16
16
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  evaluateGuard
3
- } from "./chunk-4JRYGIO7.js";
3
+ } from "./chunk-IZSO75NZ.js";
4
4
  import {
5
5
  loadWorld
6
6
  } from "./chunk-JZPQGIKR.js";
@@ -0,0 +1,57 @@
1
+ import {
2
+ advancePlan,
3
+ evaluatePlan,
4
+ getPlanProgress
5
+ } from "./chunk-QLPTHTVB.js";
6
+
7
+ // src/adapters/shared.ts
8
+ var GovernanceBlockedError = class extends Error {
9
+ verdict;
10
+ constructor(verdict, message) {
11
+ super(message ?? `[NeuroVerse] BLOCKED: ${verdict.reason ?? verdict.ruleId ?? "governance rule"}`);
12
+ this.name = "GovernanceBlockedError";
13
+ this.verdict = verdict;
14
+ }
15
+ };
16
+ function trackPlanProgress(event, state, callbacks) {
17
+ if (!state.activePlan) return;
18
+ const planVerdict = evaluatePlan(event, state.activePlan);
19
+ if (planVerdict.matchedStep) {
20
+ const advResult = advancePlan(state.activePlan, planVerdict.matchedStep);
21
+ if (advResult.success && advResult.plan) {
22
+ state.activePlan = advResult.plan;
23
+ state.engineOptions.plan = state.activePlan;
24
+ }
25
+ const progress = getPlanProgress(state.activePlan);
26
+ callbacks.onPlanProgress?.(progress);
27
+ if (progress.completed === progress.total) {
28
+ callbacks.onPlanComplete?.();
29
+ }
30
+ }
31
+ }
32
+ function extractScope(args) {
33
+ if (typeof args.path === "string") return args.path;
34
+ if (typeof args.file_path === "string") return args.file_path;
35
+ if (typeof args.filename === "string") return args.filename;
36
+ if (typeof args.url === "string") return args.url;
37
+ if (typeof args.command === "string") return args.command;
38
+ return void 0;
39
+ }
40
+ function buildEngineOptions(options, plan) {
41
+ return {
42
+ trace: options.trace ?? false,
43
+ level: options.level,
44
+ plan: plan ?? options.plan
45
+ };
46
+ }
47
+ function defaultBlockMessage(verdict) {
48
+ return `Action blocked by governance policy: ${verdict.reason ?? "rule violation"}. Rule: ${verdict.ruleId ?? "unknown"}.`;
49
+ }
50
+
51
+ export {
52
+ GovernanceBlockedError,
53
+ trackPlanProgress,
54
+ extractScope,
55
+ buildEngineOptions,
56
+ defaultBlockMessage
57
+ };
@@ -1,23 +1,21 @@
1
+ import {
2
+ GovernanceBlockedError,
3
+ buildEngineOptions,
4
+ extractScope,
5
+ trackPlanProgress
6
+ } from "./chunk-5U2MQO5P.js";
1
7
  import {
2
8
  evaluateGuard
3
- } from "./chunk-4JRYGIO7.js";
9
+ } from "./chunk-IZSO75NZ.js";
4
10
  import {
5
11
  loadWorld
6
12
  } from "./chunk-JZPQGIKR.js";
7
- import {
8
- advancePlan,
9
- evaluatePlan,
10
- getPlanProgress
11
- } from "./chunk-4QXB6PEO.js";
12
13
 
13
14
  // src/adapters/openclaw.ts
14
- var GovernanceBlockedError = class extends Error {
15
- verdict;
15
+ var GovernanceBlockedError2 = class extends GovernanceBlockedError {
16
16
  action;
17
17
  constructor(verdict, action) {
18
- super(`[NeuroVerse] BLOCKED: ${verdict.reason ?? verdict.ruleId ?? "governance rule"}`);
19
- this.name = "GovernanceBlockedError";
20
- this.verdict = verdict;
18
+ super(verdict);
21
19
  this.action = action;
22
20
  }
23
21
  };
@@ -27,7 +25,7 @@ function defaultMapAction(action, direction) {
27
25
  tool: action.tool ?? action.type,
28
26
  args: action.input,
29
27
  direction,
30
- scope: typeof action.input?.path === "string" ? action.input.path : typeof action.input?.url === "string" ? action.input.url : void 0
28
+ scope: action.input ? extractScope(action.input) : void 0
31
29
  };
32
30
  }
33
31
  var NeuroVersePlugin = class {
@@ -41,11 +39,7 @@ var NeuroVersePlugin = class {
41
39
  this.world = world;
42
40
  this.options = options;
43
41
  this.activePlan = options.plan;
44
- this.engineOptions = {
45
- trace: options.trace ?? false,
46
- level: options.level,
47
- plan: this.activePlan
48
- };
42
+ this.engineOptions = buildEngineOptions(options, this.activePlan);
49
43
  this.mapAction = options.mapAction ?? defaultMapAction;
50
44
  }
51
45
  /**
@@ -65,22 +59,10 @@ var NeuroVersePlugin = class {
65
59
  };
66
60
  this.options.onEvaluate?.(result);
67
61
  if (verdict.status === "BLOCK") {
68
- throw new GovernanceBlockedError(verdict, action);
62
+ throw new GovernanceBlockedError2(verdict, action);
69
63
  }
70
- if (verdict.status === "ALLOW" && this.activePlan) {
71
- const planVerdict = evaluatePlan(event, this.activePlan);
72
- if (planVerdict.matchedStep) {
73
- const advResult = advancePlan(this.activePlan, planVerdict.matchedStep);
74
- if (advResult.success && advResult.plan) {
75
- this.activePlan = advResult.plan;
76
- this.engineOptions.plan = this.activePlan;
77
- }
78
- const progress = getPlanProgress(this.activePlan);
79
- this.options.onPlanProgress?.(progress);
80
- if (progress.completed === progress.total) {
81
- this.options.onPlanComplete?.();
82
- }
83
- }
64
+ if (verdict.status === "ALLOW") {
65
+ trackPlanProgress(event, this, this.options);
84
66
  }
85
67
  return result;
86
68
  }
@@ -101,7 +83,7 @@ var NeuroVersePlugin = class {
101
83
  };
102
84
  this.options.onEvaluate?.(result);
103
85
  if (verdict.status === "BLOCK") {
104
- throw new GovernanceBlockedError(verdict, action);
86
+ throw new GovernanceBlockedError2(verdict, action);
105
87
  }
106
88
  return result;
107
89
  }
@@ -124,7 +106,7 @@ function createNeuroVersePluginFromWorld(world, options) {
124
106
  }
125
107
 
126
108
  export {
127
- GovernanceBlockedError,
109
+ GovernanceBlockedError2 as GovernanceBlockedError,
128
110
  NeuroVersePlugin,
129
111
  createNeuroVersePlugin,
130
112
  createNeuroVersePluginFromWorld
@@ -1,14 +1,20 @@
1
1
  import {
2
- evaluateGuard
3
- } from "./chunk-4JRYGIO7.js";
2
+ applyConsequence,
3
+ applyReward,
4
+ createAgentState,
5
+ tickAgentStates
6
+ } from "./chunk-D2UCV5AK.js";
4
7
  import {
5
- loadWorld
6
- } from "./chunk-JZPQGIKR.js";
8
+ evaluateGuard
9
+ } from "./chunk-IZSO75NZ.js";
7
10
  import {
8
11
  advancePlan,
9
12
  evaluatePlan,
10
13
  getPlanProgress
11
- } from "./chunk-4QXB6PEO.js";
14
+ } from "./chunk-QLPTHTVB.js";
15
+ import {
16
+ loadWorld
17
+ } from "./chunk-JZPQGIKR.js";
12
18
 
13
19
  // src/runtime/session.ts
14
20
  async function defaultToolExecutor(name, args) {
@@ -35,7 +41,11 @@ var SessionManager = class {
35
41
  actionsEvaluated: 0,
36
42
  actionsAllowed: 0,
37
43
  actionsBlocked: 0,
38
- actionsPaused: 0
44
+ actionsPaused: 0,
45
+ actionsModified: 0,
46
+ actionsPenalized: 0,
47
+ actionsRewarded: 0,
48
+ agentStates: /* @__PURE__ */ new Map()
39
49
  };
40
50
  }
41
51
  /**
@@ -57,14 +67,41 @@ var SessionManager = class {
57
67
  */
58
68
  evaluate(event) {
59
69
  this.engineOptions.plan = this.state.plan;
70
+ this.engineOptions.agentStates = this.state.agentStates;
60
71
  const verdict = evaluateGuard(event, this.state.world, this.engineOptions);
61
72
  this.state.actionsEvaluated++;
62
73
  if (verdict.status === "ALLOW") this.state.actionsAllowed++;
63
74
  if (verdict.status === "BLOCK") this.state.actionsBlocked++;
64
75
  if (verdict.status === "PAUSE") this.state.actionsPaused++;
76
+ if (verdict.status === "MODIFY") this.state.actionsModified++;
77
+ if (verdict.status === "PENALIZE") this.state.actionsPenalized++;
78
+ if (verdict.status === "REWARD") this.state.actionsRewarded++;
79
+ if (event.roleId) {
80
+ let agentState = this.state.agentStates.get(event.roleId) ?? createAgentState(event.roleId);
81
+ if (verdict.status === "PENALIZE" && verdict.consequence) {
82
+ agentState = applyConsequence(agentState, verdict.consequence, verdict.ruleId ?? "unknown");
83
+ }
84
+ if (verdict.status === "REWARD" && verdict.reward) {
85
+ agentState = applyReward(agentState, verdict.reward, verdict.ruleId ?? "unknown");
86
+ }
87
+ this.state.agentStates.set(event.roleId, agentState);
88
+ }
65
89
  this.config.onVerdict?.(verdict, event);
66
90
  return verdict;
67
91
  }
92
+ /**
93
+ * Advance all agent states by one round.
94
+ * Call this at the end of each simulation round to decrement cooldowns.
95
+ */
96
+ tickRound() {
97
+ this.state.agentStates = tickAgentStates(this.state.agentStates);
98
+ }
99
+ /**
100
+ * Get the behavior state for a specific agent.
101
+ */
102
+ getAgentState(agentId) {
103
+ return this.state.agentStates.get(agentId);
104
+ }
68
105
  /**
69
106
  * Evaluate and execute a tool call.
70
107
  * Returns the execution result or block reason.
@@ -83,7 +120,7 @@ var SessionManager = class {
83
120
  direction: "input"
84
121
  };
85
122
  const verdict = this.evaluate(event);
86
- if (verdict.status === "BLOCK") {
123
+ if (verdict.status === "BLOCK" || verdict.status === "PENALIZE") {
87
124
  return { allowed: false, verdict };
88
125
  }
89
126
  if (verdict.status === "PAUSE") {
@@ -269,7 +306,9 @@ async function runInteractiveMode(config, model) {
269
306
  `);
270
307
  process.stdout.write(` Actions: ${s.actionsEvaluated} evaluated
271
308
  `);
272
- process.stdout.write(` Allowed: ${s.actionsAllowed} | Blocked: ${s.actionsBlocked} | Paused: ${s.actionsPaused}
309
+ process.stdout.write(` Allowed: ${s.actionsAllowed} | Blocked: ${s.actionsBlocked} | Modified: ${s.actionsModified} | Paused: ${s.actionsPaused}
310
+ `);
311
+ process.stdout.write(` Penalized: ${s.actionsPenalized} | Rewarded: ${s.actionsRewarded}
273
312
  `);
274
313
  if (s.progress && s.plan) {
275
314
  process.stdout.write(` Plan: ${s.plan.plan_id} \u2014 ${s.progress.completed}/${s.progress.total} (${s.progress.percentage}%)