@neuroverseos/governance 0.1.5 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +279 -423
  2. package/dist/adapters/express.cjs +242 -2
  3. package/dist/adapters/express.d.cts +1 -1
  4. package/dist/adapters/express.d.ts +1 -1
  5. package/dist/adapters/express.js +5 -3
  6. package/dist/adapters/index.cjs +301 -5
  7. package/dist/adapters/index.d.cts +1 -1
  8. package/dist/adapters/index.d.ts +1 -1
  9. package/dist/adapters/index.js +8 -6
  10. package/dist/adapters/langchain.cjs +267 -3
  11. package/dist/adapters/langchain.d.cts +8 -1
  12. package/dist/adapters/langchain.d.ts +8 -1
  13. package/dist/adapters/langchain.js +5 -3
  14. package/dist/adapters/openai.cjs +267 -3
  15. package/dist/adapters/openai.d.cts +8 -1
  16. package/dist/adapters/openai.d.ts +8 -1
  17. package/dist/adapters/openai.js +5 -3
  18. package/dist/adapters/openclaw.cjs +267 -3
  19. package/dist/adapters/openclaw.d.cts +8 -1
  20. package/dist/adapters/openclaw.d.ts +8 -1
  21. package/dist/adapters/openclaw.js +5 -3
  22. package/dist/{bootstrap-H4HHKQ5G.js → bootstrap-GXVDZNF7.js} +2 -1
  23. package/dist/{build-73KAVHEY.js → build-P42YFKQV.js} +34 -3
  24. package/dist/{chunk-FYPYZFV5.js → chunk-2JQJ5U5X.js} +1 -1
  25. package/dist/chunk-37JG24WH.js +161 -0
  26. package/dist/chunk-5EDDNJU6.js +321 -0
  27. package/dist/{chunk-O5OMJMIE.js → chunk-7P3S7MAY.js} +502 -2
  28. package/dist/chunk-A5W4GNQO.js +130 -0
  29. package/dist/{chunk-ITJ3LCPG.js → chunk-ADV7Q2LJ.js} +1 -1
  30. package/dist/chunk-AKW5YVCE.js +96 -0
  31. package/dist/{chunk-EIUHJXBB.js → chunk-GR6DGCZ2.js} +1 -1
  32. package/dist/{chunk-EQXFOKH2.js → chunk-IVPKFJX3.js} +24 -3
  33. package/dist/{chunk-D7BGWV2J.js → chunk-NF5POFCI.js} +5 -3
  34. package/dist/chunk-OT6PXH54.js +61 -0
  35. package/dist/chunk-P74Y66ZV.js +205 -0
  36. package/dist/chunk-PAX2P6ZP.js +601 -0
  37. package/dist/{chunk-B4NF3OLW.js → chunk-PQBJBVSW.js} +56 -2
  38. package/dist/{chunk-T4X42QXC.js → chunk-Q6O7ZLO2.js} +0 -59
  39. package/dist/{chunk-FZQCRGUU.js → chunk-TINSRYXQ.js} +24 -3
  40. package/dist/{chunk-CROPZ75A.js → chunk-UPJNTSVM.js} +24 -3
  41. package/dist/chunk-YZFATT7X.js +9 -0
  42. package/dist/{chunk-Z2S2HIV5.js → chunk-ZL4AHY4X.js} +2 -2
  43. package/dist/cli/neuroverse.cjs +5287 -740
  44. package/dist/cli/neuroverse.js +69 -13
  45. package/dist/cli/plan.cjs +1554 -0
  46. package/dist/cli/plan.d.cts +20 -0
  47. package/dist/cli/plan.d.ts +20 -0
  48. package/dist/cli/plan.js +346 -0
  49. package/dist/cli/run.cjs +1716 -0
  50. package/dist/cli/run.d.cts +20 -0
  51. package/dist/cli/run.d.ts +20 -0
  52. package/dist/cli/run.js +143 -0
  53. package/dist/{configure-ai-46JVG56I.js → configure-ai-TK67ZWZL.js} +5 -2
  54. package/dist/{derive-6NAEWLM5.js → derive-TLIV4OOU.js} +6 -4
  55. package/dist/doctor-V72UM2TC.js +170 -0
  56. package/dist/{explain-3B3VB6TL.js → explain-IDCRWMPX.js} +2 -1
  57. package/dist/{guard-67Y66P3I.js → guard-WA3FCCIO.js} +20 -6
  58. package/dist/{guard-contract-D_RQz9kt.d.ts → guard-contract-D-2LQInm.d.cts} +144 -2
  59. package/dist/{guard-contract-D_RQz9kt.d.cts → guard-contract-D-2LQInm.d.ts} +144 -2
  60. package/dist/guard-engine-D7X4CVAE.js +10 -0
  61. package/dist/{impact-CHERK3O6.js → impact-BWULZ5RP.js} +5 -3
  62. package/dist/{improve-YG6I6ERG.js → improve-GPUBKTEA.js} +4 -3
  63. package/dist/index.cjs +2095 -89
  64. package/dist/index.d.cts +466 -12
  65. package/dist/index.d.ts +466 -12
  66. package/dist/index.js +70 -20
  67. package/dist/{init-Z66T6TDI.js → init-PKPIYHYE.js} +2 -0
  68. package/dist/mcp-server-YUOQP4M5.js +13 -0
  69. package/dist/model-adapter-BB7G4MFI.js +11 -0
  70. package/dist/playground-CBXMAW2B.js +550 -0
  71. package/dist/redteam-SSNABQ7W.js +357 -0
  72. package/dist/session-MWRBTCYX.js +14 -0
  73. package/dist/{simulate-ETHHINZ4.js → simulate-VDOYQFRO.js} +2 -1
  74. package/dist/test-3GZSG5FR.js +217 -0
  75. package/dist/{trace-3YODSSIP.js → trace-TM4Z7G73.js} +4 -2
  76. package/dist/{validate-UVE6GKQU.js → validate-LLBWVPGV.js} +15 -6
  77. package/dist/validate-engine-UIABSIHD.js +7 -0
  78. package/dist/{world-WLNHL5XC.js → world-LAXO6DOX.js} +87 -7
  79. package/dist/world-loader-HMPTOEA2.js +9 -0
  80. package/package.json +19 -5
  81. package/dist/validate-engine-657D75OG.js +0 -6
  82. /package/dist/{chunk-M3TZFGHO.js → chunk-JZPQGIKR.js} +0 -0
@@ -1,3 +1,8 @@
1
+ import {
2
+ buildPlanCheck,
3
+ evaluatePlan
4
+ } from "./chunk-P74Y66ZV.js";
5
+
1
6
  // src/engine/guard-engine.ts
2
7
  var PROMPT_INJECTION_PATTERNS = [
3
8
  // Instruction override
@@ -89,6 +94,7 @@ function evaluateGuard(event, world, options = {}) {
89
94
  const eventText = (event.intent + " " + (event.tool ?? "") + " " + (event.scope ?? "")).toLowerCase();
90
95
  const invariantChecks = [];
91
96
  const safetyChecks = [];
97
+ let planCheckResult;
92
98
  const roleChecks = [];
93
99
  const guardChecks = [];
94
100
  const kernelRuleChecks = [];
@@ -116,6 +122,7 @@ function evaluateGuard(event, world, options = {}) {
116
122
  includeTrace ? buildTrace(
117
123
  invariantChecks,
118
124
  safetyChecks,
125
+ planCheckResult,
119
126
  roleChecks,
120
127
  guardChecks,
121
128
  kernelRuleChecks,
@@ -144,6 +151,7 @@ function evaluateGuard(event, world, options = {}) {
144
151
  includeTrace ? buildTrace(
145
152
  invariantChecks,
146
153
  safetyChecks,
154
+ planCheckResult,
147
155
  roleChecks,
148
156
  guardChecks,
149
157
  kernelRuleChecks,
@@ -154,6 +162,42 @@ function evaluateGuard(event, world, options = {}) {
154
162
  ) : void 0
155
163
  );
156
164
  }
165
+ if (options.plan) {
166
+ const planVerdict = evaluatePlan(event, options.plan);
167
+ planCheckResult = buildPlanCheck(event, options.plan, planVerdict);
168
+ if (!planVerdict.allowed && planVerdict.status !== "PLAN_COMPLETE") {
169
+ decidingLayer = "plan-enforcement";
170
+ decidingId = `plan-${options.plan.plan_id}`;
171
+ const planStatus = planVerdict.status === "CONSTRAINT_VIOLATED" ? "PAUSE" : "BLOCK";
172
+ let reason = planVerdict.reason ?? "Action blocked by plan.";
173
+ if (planVerdict.status === "OFF_PLAN" && planVerdict.closestStep) {
174
+ reason += ` Closest step: "${planVerdict.closestStep}" (similarity: ${(planVerdict.similarityScore ?? 0).toFixed(2)})`;
175
+ }
176
+ return buildVerdict(
177
+ planStatus,
178
+ reason,
179
+ `plan-${options.plan.plan_id}`,
180
+ void 0,
181
+ world,
182
+ level,
183
+ invariantChecks,
184
+ guardsMatched,
185
+ rulesMatched,
186
+ includeTrace ? buildTrace(
187
+ invariantChecks,
188
+ safetyChecks,
189
+ planCheckResult,
190
+ roleChecks,
191
+ guardChecks,
192
+ kernelRuleChecks,
193
+ levelChecks,
194
+ decidingLayer,
195
+ decidingId,
196
+ startTime
197
+ ) : void 0
198
+ );
199
+ }
200
+ }
157
201
  const roleVerdict = checkRoleRules(event, eventText, world, roleChecks);
158
202
  if (roleVerdict) {
159
203
  decidingLayer = "role";
@@ -171,6 +215,7 @@ function evaluateGuard(event, world, options = {}) {
171
215
  includeTrace ? buildTrace(
172
216
  invariantChecks,
173
217
  safetyChecks,
218
+ planCheckResult,
174
219
  roleChecks,
175
220
  guardChecks,
176
221
  kernelRuleChecks,
@@ -199,6 +244,7 @@ function evaluateGuard(event, world, options = {}) {
199
244
  includeTrace ? buildTrace(
200
245
  invariantChecks,
201
246
  safetyChecks,
247
+ planCheckResult,
202
248
  roleChecks,
203
249
  guardChecks,
204
250
  kernelRuleChecks,
@@ -227,6 +273,7 @@ function evaluateGuard(event, world, options = {}) {
227
273
  includeTrace ? buildTrace(
228
274
  invariantChecks,
229
275
  safetyChecks,
276
+ planCheckResult,
230
277
  roleChecks,
231
278
  guardChecks,
232
279
  kernelRuleChecks,
@@ -254,6 +301,7 @@ function evaluateGuard(event, world, options = {}) {
254
301
  includeTrace ? buildTrace(
255
302
  invariantChecks,
256
303
  safetyChecks,
304
+ planCheckResult,
257
305
  roleChecks,
258
306
  guardChecks,
259
307
  kernelRuleChecks,
@@ -278,6 +326,7 @@ function evaluateGuard(event, world, options = {}) {
278
326
  includeTrace ? buildTrace(
279
327
  invariantChecks,
280
328
  safetyChecks,
329
+ planCheckResult,
281
330
  roleChecks,
282
331
  guardChecks,
283
332
  kernelRuleChecks,
@@ -615,8 +664,8 @@ function matchesKeywords(eventText, ruleText) {
615
664
  function eventToAllowlistKey(event) {
616
665
  return `${(event.tool ?? "*").toLowerCase()}::${event.intent.toLowerCase().trim()}`;
617
666
  }
618
- function buildTrace(invariantChecks, safetyChecks, roleChecks, guardChecks, kernelRuleChecks, levelChecks, decidingLayer, decidingId, startTime) {
619
- return {
667
+ function buildTrace(invariantChecks, safetyChecks, planCheck, roleChecks, guardChecks, kernelRuleChecks, levelChecks, decidingLayer, decidingId, startTime) {
668
+ const trace = {
620
669
  invariantChecks,
621
670
  safetyChecks,
622
671
  roleChecks,
@@ -634,6 +683,7 @@ function buildTrace(invariantChecks, safetyChecks, roleChecks, guardChecks, kern
634
683
  "safety-scope-escape",
635
684
  "safety-execution-claim",
636
685
  "safety-execution-intent",
686
+ "plan-enforcement",
637
687
  "role-rules",
638
688
  "declarative-guards",
639
689
  "kernel-rules",
@@ -643,6 +693,10 @@ function buildTrace(invariantChecks, safetyChecks, roleChecks, guardChecks, kern
643
693
  },
644
694
  durationMs: performance.now() - startTime
645
695
  };
696
+ if (planCheck) {
697
+ trace.planCheck = planCheck;
698
+ }
699
+ return trace;
646
700
  }
647
701
  function buildVerdict(status, reason, ruleId, warning, world, level, invariantChecks, guardsMatched, rulesMatched, trace) {
648
702
  const evidence = {
@@ -42,61 +42,6 @@ function createProvider(config) {
42
42
  return new ChatCompletionsProvider(config);
43
43
  }
44
44
 
45
- // src/providers/config-manager.ts
46
- import { readFile, writeFile, mkdir, chmod } from "fs/promises";
47
- import { join } from "path";
48
- import { homedir } from "os";
49
- function getConfigDir() {
50
- const xdg = process.env.XDG_CONFIG_HOME;
51
- if (xdg) return join(xdg, "neuroverse");
52
- return join(homedir(), ".neuroverse");
53
- }
54
- function getConfigPath() {
55
- return join(getConfigDir(), "config.json");
56
- }
57
- async function loadConfig() {
58
- try {
59
- const raw = await readFile(getConfigPath(), "utf-8");
60
- const parsed = JSON.parse(raw);
61
- if (!parsed.provider || !parsed.model || !parsed.apiKey) {
62
- return null;
63
- }
64
- return {
65
- provider: parsed.provider,
66
- model: parsed.model,
67
- apiKey: parsed.apiKey,
68
- endpoint: parsed.endpoint ?? null
69
- };
70
- } catch {
71
- return null;
72
- }
73
- }
74
- async function saveConfig(config) {
75
- const dir = getConfigDir();
76
- await mkdir(dir, { recursive: true });
77
- const configPath = getConfigPath();
78
- const content = JSON.stringify(
79
- {
80
- provider: config.provider,
81
- model: config.model,
82
- apiKey: config.apiKey,
83
- endpoint: config.endpoint
84
- },
85
- null,
86
- 2
87
- );
88
- await writeFile(configPath, content, { mode: 384 });
89
- await chmod(configPath, 384);
90
- }
91
- function redactConfig(config) {
92
- return {
93
- provider: config.provider,
94
- model: config.model,
95
- apiKey: config.apiKey ? `${config.apiKey.slice(0, 4)}...${config.apiKey.slice(-4)}` : "(not set)",
96
- endpoint: config.endpoint
97
- };
98
- }
99
-
100
45
  // src/contracts/derive-contract.ts
101
46
  var DERIVE_EXIT_CODES = {
102
47
  SUCCESS: 0,
@@ -112,10 +57,6 @@ var CONFIGURE_AI_EXIT_CODES = {
112
57
 
113
58
  export {
114
59
  createProvider,
115
- getConfigPath,
116
- loadConfig,
117
- saveConfig,
118
- redactConfig,
119
60
  DERIVE_EXIT_CODES,
120
61
  CONFIGURE_AI_EXIT_CODES
121
62
  };
@@ -1,9 +1,14 @@
1
1
  import {
2
2
  evaluateGuard
3
- } from "./chunk-B4NF3OLW.js";
3
+ } from "./chunk-PQBJBVSW.js";
4
4
  import {
5
5
  loadWorld
6
- } from "./chunk-M3TZFGHO.js";
6
+ } from "./chunk-JZPQGIKR.js";
7
+ import {
8
+ advancePlan,
9
+ evaluatePlan,
10
+ getPlanProgress
11
+ } from "./chunk-P74Y66ZV.js";
7
12
 
8
13
  // src/adapters/openai.ts
9
14
  var GovernanceBlockedError = class extends Error {
@@ -34,12 +39,15 @@ var GovernedToolExecutor = class {
34
39
  engineOptions;
35
40
  mapFn;
36
41
  blockMsg;
42
+ activePlan;
37
43
  constructor(world, options = {}) {
38
44
  this.world = world;
39
45
  this.options = options;
46
+ this.activePlan = options.plan;
40
47
  this.engineOptions = {
41
48
  trace: options.trace ?? false,
42
- level: options.level
49
+ level: options.level,
50
+ plan: this.activePlan
43
51
  };
44
52
  this.mapFn = options.mapFunctionCall ?? defaultMapFunctionCall;
45
53
  this.blockMsg = options.blockMessage ?? defaultBlockMessage;
@@ -56,8 +64,21 @@ var GovernedToolExecutor = class {
56
64
  args = { raw: toolCall.function.arguments };
57
65
  }
58
66
  const event = this.mapFn(toolCall.function.name, args);
67
+ this.engineOptions.plan = this.activePlan;
59
68
  const verdict = evaluateGuard(event, this.world, this.engineOptions);
60
69
  this.options.onEvaluate?.(verdict, event);
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
+ }
81
+ }
61
82
  return verdict;
62
83
  }
63
84
  /**
@@ -1,9 +1,14 @@
1
1
  import {
2
2
  evaluateGuard
3
- } from "./chunk-B4NF3OLW.js";
3
+ } from "./chunk-PQBJBVSW.js";
4
4
  import {
5
5
  loadWorld
6
- } from "./chunk-M3TZFGHO.js";
6
+ } from "./chunk-JZPQGIKR.js";
7
+ import {
8
+ advancePlan,
9
+ evaluatePlan,
10
+ getPlanProgress
11
+ } from "./chunk-P74Y66ZV.js";
7
12
 
8
13
  // src/adapters/openclaw.ts
9
14
  var GovernanceBlockedError = class extends Error {
@@ -31,12 +36,15 @@ var NeuroVersePlugin = class {
31
36
  options;
32
37
  engineOptions;
33
38
  mapAction;
39
+ activePlan;
34
40
  constructor(world, options = {}) {
35
41
  this.world = world;
36
42
  this.options = options;
43
+ this.activePlan = options.plan;
37
44
  this.engineOptions = {
38
45
  trace: options.trace ?? false,
39
- level: options.level
46
+ level: options.level,
47
+ plan: this.activePlan
40
48
  };
41
49
  this.mapAction = options.mapAction ?? defaultMapAction;
42
50
  }
@@ -48,6 +56,7 @@ var NeuroVersePlugin = class {
48
56
  */
49
57
  beforeAction(action) {
50
58
  const event = this.mapAction(action, "input");
59
+ this.engineOptions.plan = this.activePlan;
51
60
  const verdict = evaluateGuard(event, this.world, this.engineOptions);
52
61
  const result = {
53
62
  allowed: verdict.status === "ALLOW",
@@ -58,6 +67,18 @@ var NeuroVersePlugin = class {
58
67
  if (verdict.status === "BLOCK") {
59
68
  throw new GovernanceBlockedError(verdict, action);
60
69
  }
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
+ }
81
+ }
61
82
  return result;
62
83
  }
63
84
  /**
@@ -0,0 +1,9 @@
1
+ var __glob = (map) => (path) => {
2
+ var fn = map[path];
3
+ if (fn) return fn();
4
+ throw new Error("Module not found in bundle: " + path);
5
+ };
6
+
7
+ export {
8
+ __glob
9
+ };
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  evaluateGuard
3
- } from "./chunk-B4NF3OLW.js";
3
+ } from "./chunk-PQBJBVSW.js";
4
4
  import {
5
5
  loadWorld
6
- } from "./chunk-M3TZFGHO.js";
6
+ } from "./chunk-JZPQGIKR.js";
7
7
 
8
8
  // src/adapters/express.ts
9
9
  function methodToCategory(method) {