@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
@@ -271,6 +271,10 @@ interface IntentPattern {
271
271
  interface GuardsConfig {
272
272
  guards: Guard[];
273
273
  intent_vocabulary: Record<string, IntentPattern>;
274
+ /** All known action surfaces (e.g. "shell", "http", "db", "email", "deploy").
275
+ * When declared, the validator checks that every surface has at least one
276
+ * governing guard — surfaces without guards are reported as fail-open. */
277
+ tool_surfaces?: string[];
274
278
  }
275
279
  interface WorldDefinition {
276
280
  world: WorldIdentity;
@@ -287,6 +291,136 @@ interface WorldDefinition {
287
291
  metadata: WorldMetadata;
288
292
  }
289
293
 
294
+ /**
295
+ * Plan Contract — Plan Enforcement Types
296
+ *
297
+ * Defines the input/output contract for plan-based governance.
298
+ *
299
+ * Plans are temporary guard overlays — "mom's rules for this trip."
300
+ * They define what an agent should do (steps) and what it must not
301
+ * exceed (constraints). Plans layer on top of worlds, narrowing
302
+ * behavior without overriding safety or world-level governance.
303
+ *
304
+ * INVARIANTS:
305
+ * - Plans can only restrict, never expand. A plan cannot override a world BLOCK.
306
+ * - Plan enforcement is deterministic: same event + same plan → same verdict.
307
+ * - No AI in the evaluation loop. Parsing and evaluation are pure functions.
308
+ */
309
+ interface PlanStep {
310
+ /** Auto-generated slug from label (e.g., "write_announcement_blog_post"). */
311
+ id: string;
312
+ /** Human-readable step name. */
313
+ label: string;
314
+ /** Optional detail about the step. */
315
+ description?: string;
316
+ /** Restrict this step to specific tools (optional). */
317
+ tools?: string[];
318
+ /** Step IDs that must complete first (optional). */
319
+ requires?: string[];
320
+ /** Semantic tags for action mapping (e.g., ["deploy", "marketing"]). */
321
+ tags?: string[];
322
+ /** Completion condition name (optional). */
323
+ verify?: string;
324
+ /** Current step status. */
325
+ status: 'pending' | 'active' | 'completed' | 'skipped';
326
+ }
327
+ interface PlanConstraint {
328
+ /** Auto-generated constraint ID. */
329
+ id: string;
330
+ /** Constraint type. 'approval' always returns PAUSE until human confirms. */
331
+ type: 'budget' | 'time' | 'scope' | 'approval' | 'custom';
332
+ /** Human-readable description. */
333
+ description: string;
334
+ /** Enforcement mode. */
335
+ enforcement: 'block' | 'pause';
336
+ /** Numeric limit (for budget/time). */
337
+ limit?: number;
338
+ /** Unit for the limit (e.g., "USD", "minutes"). */
339
+ unit?: string;
340
+ /** Pattern that activates this constraint. */
341
+ trigger?: string;
342
+ }
343
+ interface PlanDefinition {
344
+ /** Unique plan identifier. */
345
+ plan_id: string;
346
+ /** Human-readable objective. */
347
+ objective: string;
348
+ /** Whether steps must run in order. */
349
+ sequential: boolean;
350
+ /** The steps in this plan. */
351
+ steps: PlanStep[];
352
+ /** Constraints that apply to this plan. */
353
+ constraints: PlanConstraint[];
354
+ /** Optional parent world ID. */
355
+ world_id?: string;
356
+ /** When this plan was created. */
357
+ created_at: string;
358
+ /** Optional expiry time. */
359
+ expires_at?: string;
360
+ }
361
+ type PlanStatus = 'ON_PLAN' | 'OFF_PLAN' | 'CONSTRAINT_VIOLATED' | 'PLAN_COMPLETE';
362
+ interface PlanVerdict {
363
+ /** Whether the action is allowed by this plan. */
364
+ allowed: boolean;
365
+ /** Plan verdict status. */
366
+ status: PlanStatus;
367
+ /** Why the action was blocked or paused. */
368
+ reason?: string;
369
+ /** Which step this action matched (if any). */
370
+ matchedStep?: string;
371
+ /** Nearest step when OFF_PLAN (for agent self-correction). */
372
+ closestStep?: string;
373
+ /** How close the action was to the nearest step (0-1). */
374
+ similarityScore?: number;
375
+ /** Current plan progress. */
376
+ progress: PlanProgress;
377
+ }
378
+ interface PlanProgress {
379
+ /** Number of completed steps. */
380
+ completed: number;
381
+ /** Total number of steps. */
382
+ total: number;
383
+ /** Completion percentage. */
384
+ percentage: number;
385
+ }
386
+ interface PlanCheck {
387
+ /** The plan being enforced. */
388
+ planId: string;
389
+ /** Whether the action matched a plan step. */
390
+ matched: boolean;
391
+ /** Which step was matched. */
392
+ matchedStepId?: string;
393
+ /** Label of the matched step. */
394
+ matchedStepLabel?: string;
395
+ /** Nearest step when no match (for self-correction). */
396
+ closestStepId?: string;
397
+ /** Label of the nearest step. */
398
+ closestStepLabel?: string;
399
+ /** Similarity score to the nearest step. */
400
+ similarityScore?: number;
401
+ /** Whether step sequence requirements are satisfied. */
402
+ sequenceValid?: boolean;
403
+ /** Results of constraint checks. */
404
+ constraintsChecked: Array<{
405
+ constraintId: string;
406
+ passed: boolean;
407
+ reason?: string;
408
+ }>;
409
+ /** Current progress. */
410
+ progress: {
411
+ completed: number;
412
+ total: number;
413
+ };
414
+ }
415
+ declare const PLAN_EXIT_CODES: {
416
+ readonly ON_PLAN: 0;
417
+ readonly OFF_PLAN: 1;
418
+ readonly CONSTRAINT_VIOLATED: 2;
419
+ readonly ERROR: 3;
420
+ readonly PLAN_COMPLETE: 4;
421
+ };
422
+ type PlanExitCode = (typeof PLAN_EXIT_CODES)[keyof typeof PLAN_EXIT_CODES];
423
+
290
424
  /**
291
425
  * Guard Contract — CLI Governance Evaluation Types
292
426
  *
@@ -406,6 +540,8 @@ interface EvaluationTrace {
406
540
  invariantChecks: InvariantCheck[];
407
541
  /** Safety checks (injection, scope escape) */
408
542
  safetyChecks: SafetyCheck[];
543
+ /** Plan enforcement check (Phase 1.5) — present when a plan is active */
544
+ planCheck?: PlanCheck;
409
545
  /** Every role rule checked */
410
546
  roleChecks: RoleCheck[];
411
547
  /** Every declarative guard checked */
@@ -490,7 +626,7 @@ interface LevelCheck {
490
626
  */
491
627
  interface PrecedenceResolution {
492
628
  /** Which check category produced the final verdict */
493
- decidingLayer: 'session-allowlist' | 'safety' | 'role' | 'guard' | 'kernel-rule' | 'level-constraint' | 'default-allow';
629
+ decidingLayer: 'session-allowlist' | 'safety' | 'plan-enforcement' | 'role' | 'guard' | 'kernel-rule' | 'level-constraint' | 'default-allow';
494
630
  /** Specific ID of the deciding check (guard ID, rule ID, etc.) */
495
631
  decidingId?: string;
496
632
  /** Resolution strategy used */
@@ -517,6 +653,12 @@ interface GuardEngineOptions {
517
653
  * The caller owns persistence (allow-once, allow-always, etc.).
518
654
  */
519
655
  sessionAllowlist?: Set<string>;
656
+ /**
657
+ * Active plan overlay — temporary task-scoped governance.
658
+ * When set, plan enforcement runs at Phase 1.5 (after safety, before roles).
659
+ * Plans can only restrict, never expand.
660
+ */
661
+ plan?: PlanDefinition;
520
662
  }
521
663
  declare const GUARD_EXIT_CODES: {
522
664
  readonly ALLOW: 0;
@@ -526,4 +668,4 @@ declare const GUARD_EXIT_CODES: {
526
668
  };
527
669
  type GuardExitCode = (typeof GUARD_EXIT_CODES)[keyof typeof GUARD_EXIT_CODES];
528
670
 
529
- export { type EvaluationTrace as E, type GuardVerdict as G, type InvariantCheck as I, type KernelRuleCheck as K, type LevelCheck as L, type PrecedenceResolution as P, type RoleCheck as R, type SafetyCheck as S, type ViabilityStatus as V, type WorldDefinition as W, type GuardEvent as a, type GuardEngineOptions as b, GUARD_EXIT_CODES as c, type GuardCheck as d, type GuardExitCode as e, type GuardStatus as f, type VerdictEvidence as g };
671
+ export { type EvaluationTrace as E, type GuardVerdict as G, type InvariantCheck as I, type KernelRuleCheck as K, type LevelCheck as L, type PlanDefinition as P, type RoleCheck as R, type SafetyCheck as S, type ViabilityStatus as V, type WorldDefinition as W, type GuardEvent as a, type PlanProgress as b, type GuardEngineOptions as c, type PlanVerdict as d, type PlanCheck as e, GUARD_EXIT_CODES as f, type GuardCheck as g, type GuardExitCode as h, type GuardStatus as i, PLAN_EXIT_CODES as j, type PlanConstraint as k, type PlanExitCode as l, type PlanStatus as m, type PlanStep as n, type PrecedenceResolution as o, type VerdictEvidence as p };
@@ -0,0 +1,10 @@
1
+ import {
2
+ evaluateGuard,
3
+ eventToAllowlistKey
4
+ } from "./chunk-PQBJBVSW.js";
5
+ import "./chunk-P74Y66ZV.js";
6
+ import "./chunk-YZFATT7X.js";
7
+ export {
8
+ evaluateGuard,
9
+ eventToAllowlistKey
10
+ };
@@ -1,11 +1,13 @@
1
1
  import {
2
2
  generateImpactReport,
3
3
  renderImpactReport
4
- } from "./chunk-ITJ3LCPG.js";
4
+ } from "./chunk-ADV7Q2LJ.js";
5
5
  import {
6
6
  readAuditLog
7
- } from "./chunk-FYPYZFV5.js";
8
- import "./chunk-B4NF3OLW.js";
7
+ } from "./chunk-2JQJ5U5X.js";
8
+ import "./chunk-PQBJBVSW.js";
9
+ import "./chunk-P74Y66ZV.js";
10
+ import "./chunk-YZFATT7X.js";
9
11
 
10
12
  // src/cli/impact.ts
11
13
  var USAGE = `
@@ -1,12 +1,13 @@
1
1
  import {
2
2
  improveWorld,
3
3
  renderImproveText
4
- } from "./chunk-EIUHJXBB.js";
4
+ } from "./chunk-GR6DGCZ2.js";
5
5
  import "./chunk-FYS2CBUW.js";
6
+ import "./chunk-7P3S7MAY.js";
6
7
  import {
7
8
  loadWorld
8
- } from "./chunk-M3TZFGHO.js";
9
- import "./chunk-O5OMJMIE.js";
9
+ } from "./chunk-JZPQGIKR.js";
10
+ import "./chunk-YZFATT7X.js";
10
11
 
11
12
  // src/cli/improve.ts
12
13
  function parseArgs(argv) {