@neuroverseos/governance 0.2.1 → 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 (92) 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 +678 -102
  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 +181 -47
  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 +183 -49
  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 +181 -47
  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-ZL4AHY4X.js → chunk-4L6OPKMQ.js} +1 -1
  35. package/dist/chunk-5U2MQO5P.js +57 -0
  36. package/dist/{chunk-UPJNTSVM.js → chunk-6BB55YJI.js} +16 -31
  37. package/dist/{chunk-37JG24WH.js → chunk-6CZSKEY5.js} +3 -0
  38. package/dist/{chunk-5EDDNJU6.js → chunk-AF2VX4AL.js} +52 -10
  39. package/dist/chunk-BQZMOEML.js +43 -0
  40. package/dist/chunk-D2UCV5AK.js +326 -0
  41. package/dist/{chunk-IVPKFJX3.js → chunk-EVDJUSZ2.js} +16 -31
  42. package/dist/{chunk-PQBJBVSW.js → chunk-IZSO75NZ.js} +72 -7
  43. package/dist/chunk-JCKSW2PZ.js +304 -0
  44. package/dist/{chunk-ADV7Q2LJ.js → chunk-KTFTTLTP.js} +25 -4
  45. package/dist/{chunk-MWDQ4MJB.js → chunk-MH7BT4VH.js} +5 -1
  46. package/dist/{chunk-P74Y66ZV.js → chunk-QLPTHTVB.js} +66 -18
  47. package/dist/{chunk-2JQJ5U5X.js → chunk-REXY4LUL.js} +49 -10
  48. package/dist/chunk-T5EUJQE5.js +172 -0
  49. package/dist/{chunk-PAX2P6ZP.js → chunk-TTBKTF3P.js} +15 -8
  50. package/dist/{chunk-TINSRYXQ.js → chunk-ZIVQNSZU.js} +16 -33
  51. package/dist/{chunk-BUWWN2NX.js → chunk-ZJTDUCC2.js} +9 -7
  52. package/dist/cli/neuroverse.cjs +2648 -495
  53. package/dist/cli/neuroverse.js +39 -15
  54. package/dist/cli/plan.cjs +178 -46
  55. package/dist/cli/plan.js +33 -26
  56. package/dist/cli/run.cjs +257 -28
  57. package/dist/cli/run.js +2 -2
  58. package/dist/decision-flow-LETV5NWY.js +61 -0
  59. package/dist/{derive-TLIV4OOU.js → derive-7365SUFU.js} +2 -2
  60. package/dist/{doctor-V72UM2TC.js → doctor-QYISMKEL.js} +5 -2
  61. package/dist/equity-penalties-63FGB3I2.js +244 -0
  62. package/dist/{explain-IDCRWMPX.js → explain-A2EWI2OL.js} +4 -23
  63. package/dist/{guard-WA3FCCIO.js → guard-3BWL3IGH.js} +6 -10
  64. package/dist/{guard-contract-D-2LQInm.d.ts → guard-contract-C9_zKbzd.d.cts} +155 -5
  65. package/dist/{guard-contract-D-2LQInm.d.cts → guard-contract-C9_zKbzd.d.ts} +155 -5
  66. package/dist/{guard-engine-D7X4CVAE.js → guard-engine-QFMIBWJY.js} +2 -2
  67. package/dist/{impact-BWULZ5RP.js → impact-UB6DXKSX.js} +4 -4
  68. package/dist/{improve-GPUBKTEA.js → improve-XZA57GER.js} +5 -24
  69. package/dist/index.cjs +639 -51
  70. package/dist/index.d.cts +235 -7
  71. package/dist/index.d.ts +235 -7
  72. package/dist/index.js +92 -41
  73. package/dist/infer-world-7GVZWFX4.js +543 -0
  74. package/dist/init-world-VWMQZQC7.js +223 -0
  75. package/dist/{mcp-server-YUOQP4M5.js → mcp-server-XWQZXNW7.js} +3 -3
  76. package/dist/{playground-CBXMAW2B.js → playground-ADWZORNV.js} +2 -2
  77. package/dist/{redteam-SSNABQ7W.js → redteam-JRQ7FD2F.js} +2 -2
  78. package/dist/{session-MWRBTCYX.js → session-MMYX5YCF.js} +4 -3
  79. package/dist/shared--Q8wPBVN.d.ts +60 -0
  80. package/dist/shared-HpAG90PX.d.cts +60 -0
  81. package/dist/shared-U2QFV7JH.js +16 -0
  82. package/dist/{simulate-VDOYQFRO.js → simulate-GMIFFXYV.js} +5 -30
  83. package/dist/{test-3GZSG5FR.js → test-JBBZ65X4.js} +2 -2
  84. package/dist/{trace-TM4Z7G73.js → trace-3MYWIDEF.js} +3 -3
  85. package/dist/worlds/autoresearch.nv-world.md +230 -0
  86. package/dist/worlds/coding-agent.nv-world.md +211 -0
  87. package/llms.txt +79 -0
  88. package/openapi.yaml +230 -0
  89. package/package.json +26 -4
  90. package/dist/{chunk-GR6DGCZ2.js → chunk-BMOXICAB.js} +3 -3
  91. package/dist/{chunk-NF5POFCI.js → chunk-ORJ3NOE6.js} +3 -3
  92. 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,
@@ -144,13 +167,40 @@ function getPlanProgress(plan) {
144
167
  percentage: total > 0 ? Math.round(completed / total * 100) : 0
145
168
  };
146
169
  }
147
- function advancePlan(plan, stepId) {
148
- return {
170
+ function advancePlan(plan, stepId, evidence) {
171
+ const step = plan.steps.find((s) => s.id === stepId);
172
+ if (!step) {
173
+ return { success: false, reason: `Step "${stepId}" not found in plan.` };
174
+ }
175
+ if (step.status === "completed") {
176
+ return { success: false, reason: `Step "${stepId}" is already completed.` };
177
+ }
178
+ const mode = plan.completion ?? "trust";
179
+ if (mode === "verified" && step.verify) {
180
+ if (!evidence) {
181
+ return {
182
+ success: false,
183
+ reason: `Step "${step.label}" requires evidence (verify: ${step.verify}). Provide evidence to advance.`
184
+ };
185
+ }
186
+ if (evidence.type !== step.verify) {
187
+ return {
188
+ success: false,
189
+ reason: `Evidence type "${evidence.type}" does not match required verification "${step.verify}".`
190
+ };
191
+ }
192
+ }
193
+ const updatedPlan = {
149
194
  ...plan,
150
195
  steps: plan.steps.map(
151
196
  (s) => s.id === stepId ? { ...s, status: "completed" } : s
152
197
  )
153
198
  };
199
+ return {
200
+ success: true,
201
+ plan: updatedPlan,
202
+ evidence: evidence ?? void 0
203
+ };
154
204
  }
155
205
  function evaluatePlan(event, plan) {
156
206
  const progress = getPlanProgress(plan);
@@ -173,11 +223,7 @@ function evaluatePlan(event, plan) {
173
223
  progress
174
224
  };
175
225
  }
176
- const eventText = [
177
- event.intent,
178
- event.tool ?? "",
179
- event.scope ?? ""
180
- ].join(" ").toLowerCase();
226
+ const eventText = normalizeEventText(event);
181
227
  const { matched, closest, closestScore } = findMatchingStep(eventText, event, plan.steps);
182
228
  if (!matched) {
183
229
  return {
@@ -218,7 +264,7 @@ function evaluatePlan(event, plan) {
218
264
  };
219
265
  }
220
266
  function buildPlanCheck(event, plan, verdict) {
221
- const eventText = [event.intent, event.tool ?? "", event.scope ?? ""].join(" ").toLowerCase();
267
+ const eventText = normalizeEventText(event);
222
268
  const { matched, closest, closestScore } = findMatchingStep(eventText, event, plan.steps);
223
269
  const { checks: constraintChecks } = checkConstraints(event, eventText, plan.constraints);
224
270
  const progress = getPlanProgress(plan);
@@ -324,7 +370,7 @@ function evaluateGuard(event, world, options = {}) {
324
370
  const startTime = performance.now();
325
371
  const level = options.level ?? "standard";
326
372
  const includeTrace = options.trace ?? false;
327
- const eventText = (event.intent + " " + (event.tool ?? "") + " " + (event.scope ?? "")).toLowerCase();
373
+ const eventText = normalizeEventText(event);
328
374
  const invariantChecks = [];
329
375
  const safetyChecks = [];
330
376
  let planCheckResult;
@@ -337,6 +383,43 @@ function evaluateGuard(event, world, options = {}) {
337
383
  const guardsMatched = [];
338
384
  const rulesMatched = [];
339
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
+ }
340
423
  if (options.sessionAllowlist) {
341
424
  const key = eventToAllowlistKey(event);
342
425
  if (options.sessionAllowlist.has(key)) {
@@ -464,7 +547,16 @@ function evaluateGuard(event, world, options = {}) {
464
547
  if (guardVerdict.status !== "ALLOW") {
465
548
  decidingLayer = "guard";
466
549
  decidingId = guardVerdict.ruleId;
467
- 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(
468
560
  guardVerdict.status,
469
561
  guardVerdict.reason,
470
562
  guardVerdict.ruleId,
@@ -487,6 +579,10 @@ function evaluateGuard(event, world, options = {}) {
487
579
  startTime
488
580
  ) : void 0
489
581
  );
582
+ verdict.intentRecord = intentRecord;
583
+ if (guardVerdict.consequence) verdict.consequence = guardVerdict.consequence;
584
+ if (guardVerdict.reward) verdict.reward = guardVerdict.reward;
585
+ return verdict;
490
586
  }
491
587
  }
492
588
  const kernelVerdict = checkKernelRules(eventText, world, kernelRuleChecks, rulesMatched);
@@ -781,6 +877,21 @@ function checkGuards(event, eventText, world, checks, guardsMatched) {
781
877
  if (actionMode === "pause") {
782
878
  return { status: "PAUSE", reason, ruleId: `guard-${guard.id}` };
783
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
+ }
784
895
  if (actionMode === "warn" && !warnResult) {
785
896
  warnResult = { status: "ALLOW", warning: reason, ruleId: `guard-${guard.id}` };
786
897
  }
@@ -890,9 +1001,7 @@ function checkLevelConstraints(event, level, checks) {
890
1001
  return null;
891
1002
  }
892
1003
  function matchesKeywords(eventText, ruleText) {
893
- const keywords = ruleText.toLowerCase().split(/\s+/).filter((w) => w.length > 3);
894
- if (keywords.length === 0) return false;
895
- return keywords.every((kw) => eventText.includes(kw));
1004
+ return matchesAllKeywords(eventText, ruleText);
896
1005
  }
897
1006
  function eventToAllowlistKey(event) {
898
1007
  return `${(event.tool ?? "*").toLowerCase()}::${event.intent.toLowerCase().trim()}`;
@@ -1029,14 +1138,52 @@ async function loadWorld(worldPath) {
1029
1138
  throw new Error(`Cannot load world from: ${worldPath} \u2014 expected a directory or .nv-world.zip`);
1030
1139
  }
1031
1140
 
1032
- // src/adapters/openclaw.ts
1141
+ // src/adapters/shared.ts
1033
1142
  var GovernanceBlockedError = class extends Error {
1034
1143
  verdict;
1035
- action;
1036
- constructor(verdict, action) {
1037
- super(`[NeuroVerse] BLOCKED: ${verdict.reason ?? verdict.ruleId ?? "governance rule"}`);
1144
+ constructor(verdict, message) {
1145
+ super(message ?? `[NeuroVerse] BLOCKED: ${verdict.reason ?? verdict.ruleId ?? "governance rule"}`);
1038
1146
  this.name = "GovernanceBlockedError";
1039
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);
1040
1187
  this.action = action;
1041
1188
  }
1042
1189
  };
@@ -1046,7 +1193,7 @@ function defaultMapAction(action, direction) {
1046
1193
  tool: action.tool ?? action.type,
1047
1194
  args: action.input,
1048
1195
  direction,
1049
- 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
1050
1197
  };
1051
1198
  }
1052
1199
  var NeuroVersePlugin = class {
@@ -1060,11 +1207,7 @@ var NeuroVersePlugin = class {
1060
1207
  this.world = world;
1061
1208
  this.options = options;
1062
1209
  this.activePlan = options.plan;
1063
- this.engineOptions = {
1064
- trace: options.trace ?? false,
1065
- level: options.level,
1066
- plan: this.activePlan
1067
- };
1210
+ this.engineOptions = buildEngineOptions(options, this.activePlan);
1068
1211
  this.mapAction = options.mapAction ?? defaultMapAction;
1069
1212
  }
1070
1213
  /**
@@ -1084,19 +1227,10 @@ var NeuroVersePlugin = class {
1084
1227
  };
1085
1228
  this.options.onEvaluate?.(result);
1086
1229
  if (verdict.status === "BLOCK") {
1087
- throw new GovernanceBlockedError(verdict, action);
1230
+ throw new GovernanceBlockedError2(verdict, action);
1088
1231
  }
1089
- if (verdict.status === "ALLOW" && this.activePlan) {
1090
- const planVerdict = evaluatePlan(event, this.activePlan);
1091
- if (planVerdict.matchedStep) {
1092
- this.activePlan = advancePlan(this.activePlan, planVerdict.matchedStep);
1093
- this.engineOptions.plan = this.activePlan;
1094
- const progress = getPlanProgress(this.activePlan);
1095
- this.options.onPlanProgress?.(progress);
1096
- if (progress.completed === progress.total) {
1097
- this.options.onPlanComplete?.();
1098
- }
1099
- }
1232
+ if (verdict.status === "ALLOW") {
1233
+ trackPlanProgress(event, this, this.options);
1100
1234
  }
1101
1235
  return result;
1102
1236
  }
@@ -1117,7 +1251,7 @@ var NeuroVersePlugin = class {
1117
1251
  };
1118
1252
  this.options.onEvaluate?.(result);
1119
1253
  if (verdict.status === "BLOCK") {
1120
- throw new GovernanceBlockedError(verdict, action);
1254
+ throw new GovernanceBlockedError2(verdict, action);
1121
1255
  }
1122
1256
  return result;
1123
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-D-2LQInm.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-D-2LQInm.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-UPJNTSVM.js";
7
- import "../chunk-PQBJBVSW.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-P74Y66ZV.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-PQBJBVSW.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-PQBJBVSW.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-P74Y66ZV.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,19 +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
- this.activePlan = advancePlan(this.activePlan, planVerdict.matchedStep);
74
- this.engineOptions.plan = this.activePlan;
75
- const progress = getPlanProgress(this.activePlan);
76
- this.options.onPlanProgress?.(progress);
77
- if (progress.completed === progress.total) {
78
- this.options.onPlanComplete?.();
79
- }
80
- }
64
+ if (verdict.status === "ALLOW") {
65
+ trackPlanProgress(event, this, this.options);
81
66
  }
82
67
  return result;
83
68
  }
@@ -98,7 +83,7 @@ var NeuroVersePlugin = class {
98
83
  };
99
84
  this.options.onEvaluate?.(result);
100
85
  if (verdict.status === "BLOCK") {
101
- throw new GovernanceBlockedError(verdict, action);
86
+ throw new GovernanceBlockedError2(verdict, action);
102
87
  }
103
88
  return result;
104
89
  }
@@ -121,7 +106,7 @@ function createNeuroVersePluginFromWorld(world, options) {
121
106
  }
122
107
 
123
108
  export {
124
- GovernanceBlockedError,
109
+ GovernanceBlockedError2 as GovernanceBlockedError,
125
110
  NeuroVersePlugin,
126
111
  createNeuroVersePlugin,
127
112
  createNeuroVersePluginFromWorld
@@ -133,10 +133,13 @@ function parsePlanMarkdown(markdown) {
133
133
  if (frontmatter.expires) {
134
134
  expires_at = new Date(frontmatter.expires).toISOString();
135
135
  }
136
+ const completionRaw = frontmatter.completion?.toLowerCase();
137
+ const completion = completionRaw === "verified" ? "verified" : "trust";
136
138
  const plan = {
137
139
  plan_id: frontmatter.plan_id,
138
140
  objective: frontmatter.objective ?? "",
139
141
  sequential: frontmatter.sequential === "true",
142
+ completion,
140
143
  steps,
141
144
  constraints,
142
145
  world_id: frontmatter.world ?? void 0,