@neuroverseos/governance 0.1.6 → 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
@@ -0,0 +1,20 @@
1
+ /**
2
+ * neuroverse plan — Plan Enforcement CLI
3
+ *
4
+ * Subcommands:
5
+ * compile Parse plan markdown into plan.json
6
+ * check Check an action against a plan (stdin → stdout)
7
+ * status Show plan progress
8
+ * advance Mark a step as completed
9
+ * derive Generate a full world from a plan
10
+ *
11
+ * Usage:
12
+ * neuroverse plan compile <plan.md> [--output plan.json]
13
+ * echo '{"intent":"..."}' | neuroverse plan check --plan plan.json [--world ./world/]
14
+ * neuroverse plan status --plan plan.json
15
+ * neuroverse plan advance <step_id> --plan plan.json
16
+ * neuroverse plan derive <plan.md> [--output ./world/]
17
+ */
18
+ declare function main(args: string[]): Promise<void>;
19
+
20
+ export { main };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * neuroverse plan — Plan Enforcement CLI
3
+ *
4
+ * Subcommands:
5
+ * compile Parse plan markdown into plan.json
6
+ * check Check an action against a plan (stdin → stdout)
7
+ * status Show plan progress
8
+ * advance Mark a step as completed
9
+ * derive Generate a full world from a plan
10
+ *
11
+ * Usage:
12
+ * neuroverse plan compile <plan.md> [--output plan.json]
13
+ * echo '{"intent":"..."}' | neuroverse plan check --plan plan.json [--world ./world/]
14
+ * neuroverse plan status --plan plan.json
15
+ * neuroverse plan advance <step_id> --plan plan.json
16
+ * neuroverse plan derive <plan.md> [--output ./world/]
17
+ */
18
+ declare function main(args: string[]): Promise<void>;
19
+
20
+ export { main };
@@ -0,0 +1,346 @@
1
+ import {
2
+ PLAN_EXIT_CODES,
3
+ parsePlanMarkdown
4
+ } from "../chunk-37JG24WH.js";
5
+ import {
6
+ advancePlan,
7
+ evaluatePlan,
8
+ getPlanProgress
9
+ } from "../chunk-P74Y66ZV.js";
10
+ import "../chunk-YZFATT7X.js";
11
+
12
+ // src/cli/plan.ts
13
+ import { readFileSync, writeFileSync } from "fs";
14
+ function parseArg(args, flag) {
15
+ const idx = args.indexOf(flag);
16
+ return idx >= 0 && idx + 1 < args.length ? args[idx + 1] : void 0;
17
+ }
18
+ function readStdin() {
19
+ return new Promise((resolve, reject) => {
20
+ let data = "";
21
+ process.stdin.setEncoding("utf-8");
22
+ process.stdin.on("data", (chunk) => {
23
+ data += chunk;
24
+ });
25
+ process.stdin.on("end", () => resolve(data));
26
+ process.stdin.on("error", reject);
27
+ });
28
+ }
29
+ async function compileCommand(args) {
30
+ const inputPath = args.find((a) => !a.startsWith("--"));
31
+ if (!inputPath) {
32
+ process.stderr.write("Usage: neuroverse plan compile <plan.md> [--output plan.json]\n");
33
+ process.exit(PLAN_EXIT_CODES.ERROR);
34
+ return;
35
+ }
36
+ const outputPath = parseArg(args, "--output") ?? inputPath.replace(/\.md$/, ".json");
37
+ let markdown;
38
+ try {
39
+ markdown = readFileSync(inputPath, "utf-8");
40
+ } catch (err) {
41
+ process.stderr.write(`Error reading ${inputPath}: ${err}
42
+ `);
43
+ process.exit(PLAN_EXIT_CODES.ERROR);
44
+ return;
45
+ }
46
+ const result = parsePlanMarkdown(markdown);
47
+ if (!result.success || !result.plan) {
48
+ process.stderr.write(`Parse errors:
49
+ `);
50
+ for (const error of result.errors) {
51
+ process.stderr.write(` - ${error}
52
+ `);
53
+ }
54
+ process.exit(PLAN_EXIT_CODES.ERROR);
55
+ return;
56
+ }
57
+ writeFileSync(outputPath, JSON.stringify(result.plan, null, 2) + "\n");
58
+ const plan = result.plan;
59
+ process.stdout.write(`Plan compiled: ${plan.plan_id}
60
+ `);
61
+ process.stdout.write(` Objective: ${plan.objective}
62
+ `);
63
+ process.stdout.write(` Steps: ${plan.steps.length}
64
+ `);
65
+ process.stdout.write(` Constraints: ${plan.constraints.length}
66
+ `);
67
+ process.stdout.write(` Sequential: ${plan.sequential}
68
+ `);
69
+ if (plan.world_id) process.stdout.write(` World: ${plan.world_id}
70
+ `);
71
+ if (plan.expires_at) process.stdout.write(` Expires: ${plan.expires_at}
72
+ `);
73
+ process.stdout.write(` Output: ${outputPath}
74
+ `);
75
+ }
76
+ async function checkCommand(args) {
77
+ const planPath = parseArg(args, "--plan");
78
+ if (!planPath) {
79
+ process.stderr.write(`Usage: echo '{"intent":"..."}' | neuroverse plan check --plan plan.json
80
+ `);
81
+ process.exit(PLAN_EXIT_CODES.ERROR);
82
+ return;
83
+ }
84
+ let plan;
85
+ try {
86
+ plan = JSON.parse(readFileSync(planPath, "utf-8"));
87
+ } catch (err) {
88
+ process.stderr.write(`Error reading plan: ${err}
89
+ `);
90
+ process.exit(PLAN_EXIT_CODES.ERROR);
91
+ return;
92
+ }
93
+ const stdinData = await readStdin();
94
+ let event;
95
+ try {
96
+ event = JSON.parse(stdinData);
97
+ } catch {
98
+ process.stderr.write('Error: stdin must be valid JSON with an "intent" field.\n');
99
+ process.exit(PLAN_EXIT_CODES.ERROR);
100
+ return;
101
+ }
102
+ if (!event.intent) {
103
+ process.stderr.write('Error: event must have an "intent" field.\n');
104
+ process.exit(PLAN_EXIT_CODES.ERROR);
105
+ return;
106
+ }
107
+ const worldPath = parseArg(args, "--world");
108
+ if (worldPath) {
109
+ const { loadWorld } = await import("../world-loader-HMPTOEA2.js");
110
+ const { evaluateGuard } = await import("../guard-engine-D7X4CVAE.js");
111
+ const world = await loadWorld(worldPath);
112
+ const verdict2 = evaluateGuard(event, world, { plan });
113
+ process.stdout.write(JSON.stringify(verdict2, null, 2) + "\n");
114
+ const exitCode2 = verdict2.status === "ALLOW" ? 0 : verdict2.status === "BLOCK" ? 1 : 2;
115
+ process.exit(exitCode2);
116
+ return;
117
+ }
118
+ const verdict = evaluatePlan(event, plan);
119
+ process.stdout.write(JSON.stringify(verdict, null, 2) + "\n");
120
+ const exitCode = PLAN_EXIT_CODES[verdict.status] ?? PLAN_EXIT_CODES.ERROR;
121
+ process.exit(exitCode);
122
+ }
123
+ async function statusCommand(args) {
124
+ const planPath = parseArg(args, "--plan");
125
+ if (!planPath) {
126
+ process.stderr.write("Usage: neuroverse plan status --plan plan.json\n");
127
+ process.exit(PLAN_EXIT_CODES.ERROR);
128
+ return;
129
+ }
130
+ let plan;
131
+ try {
132
+ plan = JSON.parse(readFileSync(planPath, "utf-8"));
133
+ } catch (err) {
134
+ process.stderr.write(`Error reading plan: ${err}
135
+ `);
136
+ process.exit(PLAN_EXIT_CODES.ERROR);
137
+ return;
138
+ }
139
+ const progress = getPlanProgress(plan);
140
+ process.stdout.write(`Plan: ${plan.plan_id}
141
+ `);
142
+ process.stdout.write(`Objective: ${plan.objective}
143
+ `);
144
+ process.stdout.write(`Progress: ${progress.completed}/${progress.total} (${progress.percentage}%)
145
+ `);
146
+ process.stdout.write(`
147
+ Steps:
148
+ `);
149
+ for (const step of plan.steps) {
150
+ const status = step.status === "completed" ? "[x]" : step.status === "active" ? "[>]" : step.status === "skipped" ? "[-]" : "[ ]";
151
+ let line = ` ${status} ${step.label}`;
152
+ if (step.tags?.length) line += ` [tag: ${step.tags.join(", ")}]`;
153
+ if (step.verify) line += ` [verify: ${step.verify}]`;
154
+ if (step.requires?.length) line += ` (after: ${step.requires.join(", ")})`;
155
+ process.stdout.write(line + "\n");
156
+ }
157
+ if (plan.constraints.length > 0) {
158
+ process.stdout.write(`
159
+ Constraints:
160
+ `);
161
+ for (const c of plan.constraints) {
162
+ process.stdout.write(` - ${c.description} [${c.type}/${c.enforcement}]
163
+ `);
164
+ }
165
+ }
166
+ }
167
+ async function advanceCommand(args) {
168
+ const stepId = args.find((a) => !a.startsWith("--"));
169
+ const planPath = parseArg(args, "--plan");
170
+ if (!stepId || !planPath) {
171
+ process.stderr.write("Usage: neuroverse plan advance <step_id> --plan plan.json\n");
172
+ process.exit(PLAN_EXIT_CODES.ERROR);
173
+ return;
174
+ }
175
+ let plan;
176
+ try {
177
+ plan = JSON.parse(readFileSync(planPath, "utf-8"));
178
+ } catch (err) {
179
+ process.stderr.write(`Error reading plan: ${err}
180
+ `);
181
+ process.exit(PLAN_EXIT_CODES.ERROR);
182
+ return;
183
+ }
184
+ const step = plan.steps.find((s) => s.id === stepId);
185
+ if (!step) {
186
+ process.stderr.write(`Error: step "${stepId}" not found in plan.
187
+ `);
188
+ process.stderr.write(`Available steps: ${plan.steps.map((s) => s.id).join(", ")}
189
+ `);
190
+ process.exit(PLAN_EXIT_CODES.ERROR);
191
+ return;
192
+ }
193
+ if (step.status === "completed") {
194
+ process.stdout.write(`Step "${stepId}" is already completed.
195
+ `);
196
+ return;
197
+ }
198
+ const updated = advancePlan(plan, stepId);
199
+ writeFileSync(planPath, JSON.stringify(updated, null, 2) + "\n");
200
+ const progress = getPlanProgress(updated);
201
+ process.stdout.write(`Step completed: ${step.label}
202
+ `);
203
+ process.stdout.write(`Progress: ${progress.completed}/${progress.total} (${progress.percentage}%)
204
+ `);
205
+ if (progress.completed === progress.total) {
206
+ process.stdout.write(`
207
+ Plan complete!
208
+ `);
209
+ }
210
+ }
211
+ async function deriveCommand(args) {
212
+ const inputPath = args.find((a) => !a.startsWith("--"));
213
+ if (!inputPath) {
214
+ process.stderr.write("Usage: neuroverse plan derive <plan.md> [--output ./world/]\n");
215
+ process.exit(PLAN_EXIT_CODES.ERROR);
216
+ return;
217
+ }
218
+ const outputDir = parseArg(args, "--output") ?? "./derived-world/";
219
+ let markdown;
220
+ try {
221
+ markdown = readFileSync(inputPath, "utf-8");
222
+ } catch (err) {
223
+ process.stderr.write(`Error reading ${inputPath}: ${err}
224
+ `);
225
+ process.exit(PLAN_EXIT_CODES.ERROR);
226
+ return;
227
+ }
228
+ const result = parsePlanMarkdown(markdown);
229
+ if (!result.success || !result.plan) {
230
+ process.stderr.write(`Parse errors:
231
+ `);
232
+ for (const error of result.errors) {
233
+ process.stderr.write(` - ${error}
234
+ `);
235
+ }
236
+ process.exit(PLAN_EXIT_CODES.ERROR);
237
+ return;
238
+ }
239
+ const plan = result.plan;
240
+ const { mkdirSync } = await import("fs");
241
+ mkdirSync(outputDir, { recursive: true });
242
+ const worldJson = {
243
+ world_id: `plan_${plan.plan_id}`,
244
+ name: `Derived: ${plan.objective}`,
245
+ thesis: plan.objective,
246
+ version: "1.0.0",
247
+ runtime_mode: "COMPLIANCE",
248
+ default_assumption_profile: "default",
249
+ default_alternative_profile: "default",
250
+ modules: ["governance"],
251
+ players: { thinking_space: true, experience_space: false, action_space: true }
252
+ };
253
+ const invariants = plan.constraints.map((c, i) => ({
254
+ id: `inv_${c.id}`,
255
+ label: c.description,
256
+ type: "structural",
257
+ enforcement: c.enforcement === "block" ? "hard" : "soft"
258
+ }));
259
+ const guards = {
260
+ intent_vocabulary: {},
261
+ guards: plan.steps.map((step) => {
262
+ const patternKey = `plan_step_${step.id}`;
263
+ return {
264
+ id: `guard_${step.id}`,
265
+ label: `Plan step: ${step.label}`,
266
+ description: `Governs execution of plan step: ${step.label}`,
267
+ category: "operational",
268
+ enforcement: "warn",
269
+ intent_patterns: [patternKey],
270
+ appliesTo: step.tools ?? [],
271
+ default_enabled: true,
272
+ immutable: false
273
+ };
274
+ })
275
+ };
276
+ for (const step of plan.steps) {
277
+ const keywords = step.label.toLowerCase().split(/\s+/).filter((w) => w.length > 3);
278
+ const pattern = keywords.map((k) => `(?=.*${k})`).join("") + ".*";
279
+ guards.intent_vocabulary[`plan_step_${step.id}`] = {
280
+ pattern,
281
+ description: step.label
282
+ };
283
+ }
284
+ writeFileSync(`${outputDir}/world.json`, JSON.stringify(worldJson, null, 2) + "\n");
285
+ writeFileSync(`${outputDir}/invariants.json`, JSON.stringify(invariants, null, 2) + "\n");
286
+ writeFileSync(`${outputDir}/guards.json`, JSON.stringify(guards, null, 2) + "\n");
287
+ process.stdout.write(`World derived from plan: ${plan.plan_id}
288
+ `);
289
+ process.stdout.write(` Output: ${outputDir}
290
+ `);
291
+ process.stdout.write(` Files: world.json, invariants.json, guards.json
292
+ `);
293
+ process.stdout.write(` Guards: ${plan.steps.length} (one per step)
294
+ `);
295
+ process.stdout.write(` Invariants: ${plan.constraints.length} (one per constraint)
296
+ `);
297
+ }
298
+ var PLAN_USAGE = `
299
+ neuroverse plan \u2014 Plan enforcement for AI agents.
300
+
301
+ Subcommands:
302
+ compile Parse plan markdown into plan.json
303
+ check Check an action against a plan (stdin \u2192 stdout)
304
+ status Show plan progress
305
+ advance Mark a step as completed
306
+ derive Generate a full world from a plan
307
+
308
+ Usage:
309
+ neuroverse plan compile <plan.md> [--output plan.json]
310
+ echo '{"intent":"..."}' | neuroverse plan check --plan plan.json [--world ./world/]
311
+ neuroverse plan status --plan plan.json
312
+ neuroverse plan advance <step_id> --plan plan.json
313
+ neuroverse plan derive <plan.md> [--output ./world/]
314
+ `.trim();
315
+ async function main(args) {
316
+ const subcommand = args[0];
317
+ const subArgs = args.slice(1);
318
+ switch (subcommand) {
319
+ case "compile":
320
+ return compileCommand(subArgs);
321
+ case "check":
322
+ return checkCommand(subArgs);
323
+ case "status":
324
+ return statusCommand(subArgs);
325
+ case "advance":
326
+ return advanceCommand(subArgs);
327
+ case "derive":
328
+ return deriveCommand(subArgs);
329
+ case "--help":
330
+ case "-h":
331
+ case "help":
332
+ case void 0:
333
+ process.stdout.write(PLAN_USAGE + "\n");
334
+ process.exit(0);
335
+ break;
336
+ default:
337
+ process.stderr.write(`Unknown plan subcommand: "${subcommand}"
338
+
339
+ `);
340
+ process.stdout.write(PLAN_USAGE + "\n");
341
+ process.exit(1);
342
+ }
343
+ }
344
+ export {
345
+ main
346
+ };