@neuroverseos/governance 0.3.1 → 0.3.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 (132) hide show
  1. package/.well-known/ai-plugin.json +34 -9
  2. package/AGENTS.md +72 -24
  3. package/README.md +343 -248
  4. package/dist/adapters/autoresearch.cjs +1345 -0
  5. package/dist/adapters/autoresearch.d.cts +111 -0
  6. package/dist/adapters/autoresearch.d.ts +111 -0
  7. package/dist/adapters/autoresearch.js +12 -0
  8. package/dist/adapters/deep-agents.cjs +1528 -0
  9. package/dist/adapters/deep-agents.d.cts +181 -0
  10. package/dist/adapters/deep-agents.d.ts +181 -0
  11. package/dist/adapters/deep-agents.js +17 -0
  12. package/dist/adapters/express.cjs +1253 -0
  13. package/dist/adapters/express.d.cts +66 -0
  14. package/dist/adapters/express.d.ts +66 -0
  15. package/dist/adapters/express.js +12 -0
  16. package/dist/adapters/index.cjs +2112 -0
  17. package/dist/adapters/index.d.cts +8 -0
  18. package/dist/adapters/index.d.ts +8 -0
  19. package/dist/adapters/index.js +68 -0
  20. package/dist/adapters/langchain.cjs +1315 -0
  21. package/dist/adapters/langchain.d.cts +89 -0
  22. package/dist/adapters/langchain.d.ts +89 -0
  23. package/dist/adapters/langchain.js +17 -0
  24. package/dist/adapters/openai.cjs +1345 -0
  25. package/dist/adapters/openai.d.cts +99 -0
  26. package/dist/adapters/openai.d.ts +99 -0
  27. package/dist/adapters/openai.js +17 -0
  28. package/dist/adapters/openclaw.cjs +1337 -0
  29. package/dist/adapters/openclaw.d.cts +99 -0
  30. package/dist/adapters/openclaw.d.ts +99 -0
  31. package/dist/adapters/openclaw.js +17 -0
  32. package/dist/add-ROOZLU62.js +314 -0
  33. package/dist/behavioral-MJO34S6Q.js +118 -0
  34. package/dist/bootstrap-CQRZVOXK.js +116 -0
  35. package/dist/bootstrap-emitter-Q7UIJZ2O.js +7 -0
  36. package/dist/bootstrap-parser-EEF36XDU.js +7 -0
  37. package/dist/browser.global.js +941 -0
  38. package/dist/build-QKOBBC23.js +341 -0
  39. package/dist/chunk-3WQLXYTP.js +91 -0
  40. package/dist/chunk-4FLICVVA.js +119 -0
  41. package/dist/chunk-4NGDRRQH.js +10 -0
  42. package/dist/chunk-5TPFNWRU.js +215 -0
  43. package/dist/chunk-5U2MQO5P.js +57 -0
  44. package/dist/chunk-6CZSKEY5.js +164 -0
  45. package/dist/chunk-6S5CFQXY.js +624 -0
  46. package/dist/chunk-7P3S7MAY.js +1090 -0
  47. package/dist/chunk-A5W4GNQO.js +130 -0
  48. package/dist/chunk-A7GKPPU7.js +226 -0
  49. package/dist/chunk-AKW5YVCE.js +96 -0
  50. package/dist/chunk-B6OXJLJ5.js +622 -0
  51. package/dist/chunk-BNKJPUPQ.js +113 -0
  52. package/dist/chunk-BQZMOEML.js +43 -0
  53. package/dist/chunk-CNSO6XW5.js +207 -0
  54. package/dist/chunk-CTZHONLA.js +135 -0
  55. package/dist/chunk-D2UCV5AK.js +326 -0
  56. package/dist/chunk-EMQDLDAF.js +458 -0
  57. package/dist/chunk-F66BVUYB.js +340 -0
  58. package/dist/chunk-G7DJ6VOD.js +101 -0
  59. package/dist/chunk-I3RRAYK2.js +11 -0
  60. package/dist/chunk-IS4WUH6Y.js +363 -0
  61. package/dist/chunk-MH7BT4VH.js +15 -0
  62. package/dist/chunk-O5ABKEA7.js +304 -0
  63. package/dist/chunk-OT6PXH54.js +61 -0
  64. package/dist/chunk-PVTQQS3Y.js +186 -0
  65. package/dist/chunk-Q6O7ZLO2.js +62 -0
  66. package/dist/chunk-QLPTHTVB.js +253 -0
  67. package/dist/chunk-QWGCMQQD.js +16 -0
  68. package/dist/chunk-QXBFT7NI.js +201 -0
  69. package/dist/chunk-TG6SEF24.js +246 -0
  70. package/dist/chunk-U6U7EJZL.js +177 -0
  71. package/dist/chunk-W7LLXRGY.js +830 -0
  72. package/dist/chunk-ZJTDUCC2.js +194 -0
  73. package/dist/chunk-ZWI3NIXK.js +314 -0
  74. package/dist/cli/neuroverse.cjs +14191 -0
  75. package/dist/cli/neuroverse.d.cts +1 -0
  76. package/dist/cli/neuroverse.d.ts +1 -0
  77. package/dist/cli/neuroverse.js +227 -0
  78. package/dist/cli/plan.cjs +2439 -0
  79. package/dist/cli/plan.d.cts +20 -0
  80. package/dist/cli/plan.d.ts +20 -0
  81. package/dist/cli/plan.js +353 -0
  82. package/dist/cli/run.cjs +2001 -0
  83. package/dist/cli/run.d.cts +20 -0
  84. package/dist/cli/run.d.ts +20 -0
  85. package/dist/cli/run.js +143 -0
  86. package/dist/configure-ai-6TZ3MCSI.js +132 -0
  87. package/dist/decision-flow-M63D47LO.js +61 -0
  88. package/dist/demo-G43RLCPK.js +469 -0
  89. package/dist/derive-FJZVIPUZ.js +153 -0
  90. package/dist/doctor-6BC6X2VO.js +173 -0
  91. package/dist/equity-penalties-SG5IZQ7I.js +244 -0
  92. package/dist/explain-RHBU2GBR.js +51 -0
  93. package/dist/guard-AJCCGZMF.js +92 -0
  94. package/dist/guard-contract-DqFcTScd.d.cts +821 -0
  95. package/dist/guard-contract-DqFcTScd.d.ts +821 -0
  96. package/dist/guard-engine-PNR6MHCM.js +10 -0
  97. package/dist/impact-3XVDSCBU.js +59 -0
  98. package/dist/improve-TQP4ECSY.js +66 -0
  99. package/dist/index.cjs +7591 -0
  100. package/dist/index.d.cts +2195 -0
  101. package/dist/index.d.ts +2195 -0
  102. package/dist/index.js +472 -0
  103. package/dist/infer-world-IFXCACJ5.js +543 -0
  104. package/dist/init-FYPV4SST.js +144 -0
  105. package/dist/init-world-TI7ARHBT.js +223 -0
  106. package/dist/mcp-server-5Y3ZM7TV.js +13 -0
  107. package/dist/model-adapter-VXEKB4LS.js +11 -0
  108. package/dist/playground-VZBNPPBO.js +560 -0
  109. package/dist/redteam-MZPZD3EF.js +357 -0
  110. package/dist/session-JYOARW54.js +15 -0
  111. package/dist/shared-7RLUHNMU.js +16 -0
  112. package/dist/shared-B8dvUUD8.d.cts +60 -0
  113. package/dist/shared-Dr5Wiay8.d.ts +60 -0
  114. package/dist/simulate-LJXYBC6M.js +83 -0
  115. package/dist/test-BOOR4A5F.js +217 -0
  116. package/dist/trace-PKV4KX56.js +166 -0
  117. package/dist/validate-RALX7CZS.js +81 -0
  118. package/dist/validate-engine-7ZXFVGF2.js +7 -0
  119. package/dist/viz/assets/index-B8SaeJZZ.js +23 -0
  120. package/dist/viz/index.html +23 -0
  121. package/dist/world-BIP4GZBZ.js +376 -0
  122. package/dist/world-loader-Y6HMQH2D.js +13 -0
  123. package/dist/worlds/autoresearch.nv-world.md +230 -0
  124. package/dist/worlds/coding-agent.nv-world.md +211 -0
  125. package/dist/worlds/derivation-world.nv-world.md +278 -0
  126. package/dist/worlds/research-agent.nv-world.md +169 -0
  127. package/dist/worlds/social-media.nv-world.md +198 -0
  128. package/dist/worlds/trading-agent.nv-world.md +218 -0
  129. package/examples/social-media-sim/bridge.py +209 -0
  130. package/examples/social-media-sim/simulation.py +927 -0
  131. package/package.json +16 -3
  132. package/simulate.html +4 -336
@@ -0,0 +1,99 @@
1
+ import { a as GuardVerdict, b as GuardEngineOptions, P as PlanDefinition, W as WorldDefinition, G as GuardEvent, c as PlanProgress } from '../guard-contract-DqFcTScd.cjs';
2
+ import { G as GovernanceBlockedError$1 } from '../shared-B8dvUUD8.cjs';
3
+
4
+ /**
5
+ * NeuroVerse Adapter — OpenClaw
6
+ *
7
+ * Integrates NeuroVerse governance as an OpenClaw plugin.
8
+ * Provides pre-action and post-action governance hooks that
9
+ * evaluate agent actions against a world definition.
10
+ *
11
+ * Usage:
12
+ * import { createNeuroVersePlugin } from 'neuroverse-governance/adapters/openclaw';
13
+ *
14
+ * const plugin = await createNeuroVersePlugin('./world/');
15
+ * agent.use(plugin);
16
+ */
17
+
18
+ /** Generic agent action shape (OpenClaw-compatible). */
19
+ interface AgentAction {
20
+ type: string;
21
+ tool?: string;
22
+ input?: Record<string, unknown>;
23
+ metadata?: Record<string, unknown>;
24
+ }
25
+ /** Plugin hook result. */
26
+ interface HookResult {
27
+ allowed: boolean;
28
+ verdict: GuardVerdict;
29
+ action: AgentAction;
30
+ }
31
+ interface NeuroVersePluginOptions {
32
+ /** Include full evaluation trace. Default: false. */
33
+ trace?: boolean;
34
+ /** Enforcement level override. */
35
+ level?: 'basic' | 'standard' | 'strict';
36
+ /** Called for every evaluation. */
37
+ onEvaluate?: (result: HookResult) => void;
38
+ /** Custom action → GuardEvent mapping. */
39
+ mapAction?: (action: AgentAction, direction: 'input' | 'output') => GuardEvent;
40
+ /** Whether to evaluate output actions (post-action). Default: false. */
41
+ evaluateOutputs?: boolean;
42
+ /** Active plan overlay for task-scoped governance. */
43
+ plan?: PlanDefinition;
44
+ /** Called when plan progress changes. */
45
+ onPlanProgress?: (progress: PlanProgress) => void;
46
+ /** Called when all plan steps are completed. */
47
+ onPlanComplete?: () => void;
48
+ }
49
+ declare class GovernanceBlockedError extends GovernanceBlockedError$1 {
50
+ readonly action: AgentAction;
51
+ constructor(verdict: GuardVerdict, action: AgentAction);
52
+ }
53
+ /**
54
+ * NeuroVerse governance plugin for OpenClaw agents.
55
+ *
56
+ * Provides two hooks:
57
+ * - beforeAction: evaluates before the agent executes an action
58
+ * - afterAction: optionally evaluates outputs for post-action governance
59
+ */
60
+ declare class NeuroVersePlugin {
61
+ readonly name = "neuroverse-governance";
62
+ private world;
63
+ private options;
64
+ engineOptions: GuardEngineOptions;
65
+ private mapAction;
66
+ activePlan?: PlanDefinition;
67
+ constructor(world: WorldDefinition, options?: NeuroVersePluginOptions);
68
+ /**
69
+ * Evaluate an action before execution.
70
+ *
71
+ * @throws GovernanceBlockedError if BLOCKED
72
+ * @returns HookResult with verdict details
73
+ */
74
+ beforeAction(action: AgentAction): HookResult;
75
+ /**
76
+ * Evaluate an action's output (post-execution governance).
77
+ * Only runs if evaluateOutputs is enabled.
78
+ *
79
+ * @returns HookResult or null if output evaluation is disabled
80
+ */
81
+ afterAction(action: AgentAction, _output?: unknown): HookResult | null;
82
+ /**
83
+ * Get the plugin hooks object for agent.use().
84
+ */
85
+ hooks(): {
86
+ beforeAction: (action: AgentAction) => HookResult;
87
+ afterAction: (action: AgentAction, output?: unknown) => HookResult | null;
88
+ };
89
+ }
90
+ /**
91
+ * Create a NeuroVerse plugin from a world path.
92
+ */
93
+ declare function createNeuroVersePlugin(worldPath: string, options?: NeuroVersePluginOptions): Promise<NeuroVersePlugin>;
94
+ /**
95
+ * Create a NeuroVerse plugin from a pre-loaded world.
96
+ */
97
+ declare function createNeuroVersePluginFromWorld(world: WorldDefinition, options?: NeuroVersePluginOptions): NeuroVersePlugin;
98
+
99
+ export { type AgentAction, GovernanceBlockedError, type HookResult, NeuroVersePlugin, type NeuroVersePluginOptions, createNeuroVersePlugin, createNeuroVersePluginFromWorld };
@@ -0,0 +1,99 @@
1
+ import { a as GuardVerdict, b as GuardEngineOptions, P as PlanDefinition, W as WorldDefinition, G as GuardEvent, c as PlanProgress } from '../guard-contract-DqFcTScd.js';
2
+ import { G as GovernanceBlockedError$1 } from '../shared-Dr5Wiay8.js';
3
+
4
+ /**
5
+ * NeuroVerse Adapter — OpenClaw
6
+ *
7
+ * Integrates NeuroVerse governance as an OpenClaw plugin.
8
+ * Provides pre-action and post-action governance hooks that
9
+ * evaluate agent actions against a world definition.
10
+ *
11
+ * Usage:
12
+ * import { createNeuroVersePlugin } from 'neuroverse-governance/adapters/openclaw';
13
+ *
14
+ * const plugin = await createNeuroVersePlugin('./world/');
15
+ * agent.use(plugin);
16
+ */
17
+
18
+ /** Generic agent action shape (OpenClaw-compatible). */
19
+ interface AgentAction {
20
+ type: string;
21
+ tool?: string;
22
+ input?: Record<string, unknown>;
23
+ metadata?: Record<string, unknown>;
24
+ }
25
+ /** Plugin hook result. */
26
+ interface HookResult {
27
+ allowed: boolean;
28
+ verdict: GuardVerdict;
29
+ action: AgentAction;
30
+ }
31
+ interface NeuroVersePluginOptions {
32
+ /** Include full evaluation trace. Default: false. */
33
+ trace?: boolean;
34
+ /** Enforcement level override. */
35
+ level?: 'basic' | 'standard' | 'strict';
36
+ /** Called for every evaluation. */
37
+ onEvaluate?: (result: HookResult) => void;
38
+ /** Custom action → GuardEvent mapping. */
39
+ mapAction?: (action: AgentAction, direction: 'input' | 'output') => GuardEvent;
40
+ /** Whether to evaluate output actions (post-action). Default: false. */
41
+ evaluateOutputs?: boolean;
42
+ /** Active plan overlay for task-scoped governance. */
43
+ plan?: PlanDefinition;
44
+ /** Called when plan progress changes. */
45
+ onPlanProgress?: (progress: PlanProgress) => void;
46
+ /** Called when all plan steps are completed. */
47
+ onPlanComplete?: () => void;
48
+ }
49
+ declare class GovernanceBlockedError extends GovernanceBlockedError$1 {
50
+ readonly action: AgentAction;
51
+ constructor(verdict: GuardVerdict, action: AgentAction);
52
+ }
53
+ /**
54
+ * NeuroVerse governance plugin for OpenClaw agents.
55
+ *
56
+ * Provides two hooks:
57
+ * - beforeAction: evaluates before the agent executes an action
58
+ * - afterAction: optionally evaluates outputs for post-action governance
59
+ */
60
+ declare class NeuroVersePlugin {
61
+ readonly name = "neuroverse-governance";
62
+ private world;
63
+ private options;
64
+ engineOptions: GuardEngineOptions;
65
+ private mapAction;
66
+ activePlan?: PlanDefinition;
67
+ constructor(world: WorldDefinition, options?: NeuroVersePluginOptions);
68
+ /**
69
+ * Evaluate an action before execution.
70
+ *
71
+ * @throws GovernanceBlockedError if BLOCKED
72
+ * @returns HookResult with verdict details
73
+ */
74
+ beforeAction(action: AgentAction): HookResult;
75
+ /**
76
+ * Evaluate an action's output (post-execution governance).
77
+ * Only runs if evaluateOutputs is enabled.
78
+ *
79
+ * @returns HookResult or null if output evaluation is disabled
80
+ */
81
+ afterAction(action: AgentAction, _output?: unknown): HookResult | null;
82
+ /**
83
+ * Get the plugin hooks object for agent.use().
84
+ */
85
+ hooks(): {
86
+ beforeAction: (action: AgentAction) => HookResult;
87
+ afterAction: (action: AgentAction, output?: unknown) => HookResult | null;
88
+ };
89
+ }
90
+ /**
91
+ * Create a NeuroVerse plugin from a world path.
92
+ */
93
+ declare function createNeuroVersePlugin(worldPath: string, options?: NeuroVersePluginOptions): Promise<NeuroVersePlugin>;
94
+ /**
95
+ * Create a NeuroVerse plugin from a pre-loaded world.
96
+ */
97
+ declare function createNeuroVersePluginFromWorld(world: WorldDefinition, options?: NeuroVersePluginOptions): NeuroVersePlugin;
98
+
99
+ export { type AgentAction, GovernanceBlockedError, type HookResult, NeuroVersePlugin, type NeuroVersePluginOptions, createNeuroVersePlugin, createNeuroVersePluginFromWorld };
@@ -0,0 +1,17 @@
1
+ import {
2
+ GovernanceBlockedError,
3
+ NeuroVersePlugin,
4
+ createNeuroVersePlugin,
5
+ createNeuroVersePluginFromWorld
6
+ } from "../chunk-BNKJPUPQ.js";
7
+ import "../chunk-5U2MQO5P.js";
8
+ import "../chunk-W7LLXRGY.js";
9
+ import "../chunk-QLPTHTVB.js";
10
+ import "../chunk-CTZHONLA.js";
11
+ import "../chunk-QWGCMQQD.js";
12
+ export {
13
+ GovernanceBlockedError,
14
+ NeuroVersePlugin,
15
+ createNeuroVersePlugin,
16
+ createNeuroVersePluginFromWorld
17
+ };
@@ -0,0 +1,314 @@
1
+ import {
2
+ addGuard,
3
+ addInvariant,
4
+ addRule,
5
+ classifyIntent,
6
+ parseGuardDescription
7
+ } from "./chunk-5TPFNWRU.js";
8
+ import "./chunk-7P3S7MAY.js";
9
+ import {
10
+ describeActiveWorld,
11
+ resolveWorldPath
12
+ } from "./chunk-AKW5YVCE.js";
13
+ import "./chunk-QWGCMQQD.js";
14
+
15
+ // src/cli/add.ts
16
+ function parseTriggerExpr(expr) {
17
+ const match = expr.match(/^(\S+)\s*(==|!=|>=|<=|>|<|in)\s*(.+?)(?:\s*\[(state|assumption)\])?\s*$/);
18
+ if (!match) {
19
+ throw new Error(`Invalid trigger expression: "${expr}". Expected: "field op value [state|assumption]"`);
20
+ }
21
+ const [, field, operator, rawValue, source] = match;
22
+ let value = rawValue.trim();
23
+ const num = Number(value);
24
+ if (!isNaN(num) && value !== "") value = num;
25
+ else if (value === "true") value = true;
26
+ else if (value === "false") value = false;
27
+ else if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
28
+ value = value.slice(1, -1);
29
+ }
30
+ return {
31
+ field,
32
+ operator,
33
+ value,
34
+ source: source ?? "state"
35
+ };
36
+ }
37
+ function parseEffectExpr(expr) {
38
+ const match = expr.match(/^(\S+)\s*(\*=|\+=|-=|=)\s*(.+)\s*$/);
39
+ if (!match) {
40
+ throw new Error(`Invalid effect expression: "${expr}". Expected: "target op value" (e.g., "viability *= 0.5")`);
41
+ }
42
+ const [, target, op, rawValue] = match;
43
+ const operationMap = {
44
+ "*=": "multiply",
45
+ "+=": "add",
46
+ "-=": "subtract",
47
+ "=": "set"
48
+ };
49
+ let value = rawValue.trim();
50
+ const num = Number(value);
51
+ if (!isNaN(num) && value !== "") value = num;
52
+ else if (value === "true") value = true;
53
+ else if (value === "false") value = false;
54
+ return {
55
+ target,
56
+ operation: operationMap[op],
57
+ value
58
+ };
59
+ }
60
+ function parseArgs(argv) {
61
+ const args = {
62
+ subcommand: "auto",
63
+ worldPath: "",
64
+ label: "",
65
+ json: false,
66
+ patterns: [],
67
+ appliesTo: [],
68
+ triggers: [],
69
+ effects: []
70
+ };
71
+ if (argv.length === 0) {
72
+ throw new Error('Usage: neuroverse add <guard|rule|invariant|"description"> --world <path>');
73
+ }
74
+ const first = argv[0];
75
+ if (first === "guard" || first === "rule" || first === "invariant") {
76
+ args.subcommand = first;
77
+ argv = argv.slice(1);
78
+ } else if (!first.startsWith("--")) {
79
+ args.subcommand = "auto";
80
+ args.rawText = first;
81
+ argv = argv.slice(1);
82
+ }
83
+ for (let i = 0; i < argv.length; i++) {
84
+ const arg = argv[i];
85
+ switch (arg) {
86
+ case "--world":
87
+ args.worldPath = argv[++i];
88
+ break;
89
+ case "--label":
90
+ args.label = argv[++i];
91
+ break;
92
+ case "--id":
93
+ args.id = argv[++i];
94
+ break;
95
+ case "--json":
96
+ args.json = true;
97
+ break;
98
+ case "--enforcement":
99
+ args.enforcement = argv[++i];
100
+ break;
101
+ case "--pattern":
102
+ args.patterns.push(argv[++i]);
103
+ break;
104
+ case "--category":
105
+ args.category = argv[++i];
106
+ break;
107
+ case "--applies-to":
108
+ args.appliesTo.push(argv[++i]);
109
+ break;
110
+ case "--severity":
111
+ args.severity = argv[++i];
112
+ break;
113
+ case "--trigger":
114
+ args.triggers.push(argv[++i]);
115
+ break;
116
+ case "--effect":
117
+ args.effects.push(argv[++i]);
118
+ break;
119
+ case "--description":
120
+ args.description = argv[++i];
121
+ break;
122
+ case "--help":
123
+ case "-h":
124
+ printUsage();
125
+ process.exit(0);
126
+ break;
127
+ default:
128
+ if (!arg.startsWith("--") && args.subcommand === "auto" && !args.rawText) {
129
+ args.rawText = arg;
130
+ }
131
+ }
132
+ }
133
+ return args;
134
+ }
135
+ function printUsage() {
136
+ process.stdout.write(`
137
+ neuroverse add \u2014 Incremental governance authoring
138
+
139
+ Usage:
140
+ neuroverse add "Block dairy orders" --world ./world/
141
+ neuroverse add guard --world ./world/ --label "Block dairy orders" --pattern "*dairy*"
142
+ neuroverse add rule --world ./world/ --label "Cost overrun" --severity degradation --trigger "cost > 100" --effect "viability *= 0.5"
143
+ neuroverse add invariant --world ./world/ --label "Budget must never exceed 1000"
144
+
145
+ Auto mode:
146
+ Pass a quoted description as the first argument. The engine classifies it
147
+ as a guard, rule, or invariant based on the language used.
148
+
149
+ "Block ..." / "Prevent ..." / "Deny ..." \u2192 guard
150
+ "If ... then ..." / "When ... reduce ..." \u2192 rule
151
+ "... must always ..." / "... must never ..." \u2192 invariant
152
+
153
+ Flags:
154
+ --world <path> World directory (required)
155
+ --id <id> Explicit ID (auto-generated if omitted)
156
+ --json Full JSON output
157
+
158
+ Guard:
159
+ --enforcement <type> block | pause | warn (default: block)
160
+ --pattern <glob> Intent pattern (repeatable)
161
+ --category <cat> structural | operational | advisory
162
+
163
+ Rule:
164
+ --severity <level> structural | degradation | advantage
165
+ --trigger <expr> "field op value [state|assumption]" (repeatable)
166
+ --effect <expr> "target op value" e.g. "viability *= 0.5" (repeatable)
167
+ --description <text>
168
+
169
+ Invariant:
170
+ --enforcement <type> structural | prompt (default: structural)
171
+ `.trimStart());
172
+ }
173
+ async function main(argv = process.argv.slice(2)) {
174
+ try {
175
+ const args = parseArgs(argv);
176
+ const worldPath = resolveWorldPath(args.worldPath);
177
+ if (!worldPath) {
178
+ throw new Error(
179
+ "No world specified. Use --world <path>, set NEUROVERSE_WORLD, or run `neuroverse world use <name>`"
180
+ );
181
+ }
182
+ const worldInfo = describeActiveWorld(args.worldPath);
183
+ if (worldInfo) {
184
+ process.stderr.write(`Using world: ${worldInfo.name}
185
+ `);
186
+ }
187
+ let result;
188
+ if (args.subcommand === "auto") {
189
+ const text = args.rawText ?? args.label;
190
+ if (!text) {
191
+ throw new Error('Provide a description: neuroverse add "Block dairy orders" --world ./world/');
192
+ }
193
+ const type = classifyIntent(text);
194
+ switch (type) {
195
+ case "guard": {
196
+ const input = parseGuardDescription(text);
197
+ if (args.id) input.id = args.id;
198
+ process.stderr.write(`Classified as: guard (${input.enforcement})
199
+ `);
200
+ result = await addGuard(worldPath, input);
201
+ break;
202
+ }
203
+ case "invariant": {
204
+ process.stderr.write(`Classified as: invariant
205
+ `);
206
+ result = await addInvariant(worldPath, {
207
+ label: text,
208
+ id: args.id
209
+ });
210
+ break;
211
+ }
212
+ case "rule":
213
+ case "ambiguous": {
214
+ if (type === "ambiguous") {
215
+ process.stderr.write(`Could not auto-classify. Defaulting to guard.
216
+ `);
217
+ process.stderr.write(`Tip: use "neuroverse add guard|rule|invariant" for explicit control.
218
+ `);
219
+ } else {
220
+ process.stderr.write(`Classified as: rule
221
+ `);
222
+ process.stderr.write(`Note: auto-mode creates a minimal rule. Use explicit "neuroverse add rule" with --trigger and --effect for full control.
223
+ `);
224
+ }
225
+ const input = parseGuardDescription(text);
226
+ if (args.id) input.id = args.id;
227
+ result = await addGuard(worldPath, input);
228
+ break;
229
+ }
230
+ default:
231
+ throw new Error(`Unexpected classification: ${type}`);
232
+ }
233
+ } else if (args.subcommand === "guard") {
234
+ const label = args.label;
235
+ if (!label) throw new Error("--label is required for guard");
236
+ const input = {
237
+ label,
238
+ enforcement: args.enforcement ?? "block",
239
+ intentPatterns: args.patterns.length > 0 ? args.patterns : [`*${label.toLowerCase().replace(/\s+/g, "*")}*`],
240
+ description: args.description,
241
+ category: args.category,
242
+ appliesTo: args.appliesTo.length > 0 ? args.appliesTo : void 0,
243
+ id: args.id
244
+ };
245
+ result = await addGuard(worldPath, input);
246
+ } else if (args.subcommand === "rule") {
247
+ const label = args.label;
248
+ if (!label) throw new Error("--label is required for rule");
249
+ if (args.triggers.length === 0) throw new Error("At least one --trigger is required for rule");
250
+ const input = {
251
+ label,
252
+ severity: args.severity ?? "degradation",
253
+ description: args.description,
254
+ triggers: args.triggers.map(parseTriggerExpr),
255
+ effects: args.effects.length > 0 ? args.effects.map(parseEffectExpr) : void 0,
256
+ id: args.id
257
+ };
258
+ result = await addRule(worldPath, input);
259
+ } else if (args.subcommand === "invariant") {
260
+ const label = args.label;
261
+ if (!label) throw new Error("--label is required for invariant");
262
+ result = await addInvariant(worldPath, {
263
+ label,
264
+ enforcement: args.enforcement ?? "structural",
265
+ id: args.id
266
+ });
267
+ } else {
268
+ throw new Error(`Unknown subcommand: ${args.subcommand}`);
269
+ }
270
+ if (args.json) {
271
+ process.stdout.write(JSON.stringify(result, null, 2) + "\n");
272
+ } else {
273
+ const icon = result.type === "guard" ? "GUARD" : result.type === "rule" ? "RULE" : "INVARIANT";
274
+ process.stdout.write(`
275
+ [${icon}] Added: ${result.id}
276
+ `);
277
+ process.stdout.write(` File: ${result.file}
278
+ `);
279
+ process.stdout.write(` Valid: ${result.valid ? "yes" : "no"}
280
+ `);
281
+ const errors = result.findings.filter((f) => f.severity === "error");
282
+ const warnings = result.findings.filter((f) => f.severity === "warning");
283
+ if (errors.length > 0) {
284
+ process.stdout.write(` Errors: ${errors.length}
285
+ `);
286
+ for (const e of errors.slice(0, 3)) {
287
+ process.stdout.write(` - ${e.message}
288
+ `);
289
+ }
290
+ }
291
+ if (warnings.length > 0) {
292
+ process.stdout.write(` Warnings: ${warnings.length}
293
+ `);
294
+ for (const w of warnings.slice(0, 3)) {
295
+ process.stdout.write(` - ${w.message}
296
+ `);
297
+ }
298
+ }
299
+ if (result.valid && errors.length === 0) {
300
+ process.stdout.write(`
301
+ Ready. Guard will be enforced on next evaluation.
302
+ `);
303
+ }
304
+ }
305
+ process.exit(result.valid ? 0 : 1);
306
+ } catch (e) {
307
+ process.stderr.write(`Error: ${e instanceof Error ? e.message : String(e)}
308
+ `);
309
+ process.exit(3);
310
+ }
311
+ }
312
+ export {
313
+ main
314
+ };
@@ -0,0 +1,118 @@
1
+ import {
2
+ adaptationFromVerdict,
3
+ detectBehavioralPatterns,
4
+ generateAdaptationNarrative
5
+ } from "./chunk-CNSO6XW5.js";
6
+ import {
7
+ readAuditLog
8
+ } from "./chunk-A7GKPPU7.js";
9
+ import "./chunk-W7LLXRGY.js";
10
+ import "./chunk-QLPTHTVB.js";
11
+ import "./chunk-QWGCMQQD.js";
12
+
13
+ // src/cli/behavioral.ts
14
+ var USAGE = `
15
+ neuroverse behavioral \u2014 Behavioral analysis from audit log
16
+
17
+ Usage:
18
+ neuroverse behavioral [options]
19
+
20
+ Options:
21
+ --log <path> Path to audit log (default: .neuroverse/audit.ndjson)
22
+ --json Raw JSON output
23
+
24
+ Classifies agent adaptations, detects network-level patterns
25
+ (coordinated silence, misinfo suppression, reward cascades),
26
+ and generates a human-readable narrative.
27
+ `.trim();
28
+ function parseArgs(argv) {
29
+ const args = {};
30
+ for (let i = 0; i < argv.length; i++) {
31
+ const arg = argv[i];
32
+ if (arg === "--json") args.json = true;
33
+ else if (arg === "--help" || arg === "-h") args.help = true;
34
+ else if (arg === "--log" && argv[i + 1]) args.log = argv[++i];
35
+ }
36
+ return args;
37
+ }
38
+ async function main(argv = process.argv.slice(2)) {
39
+ const args = parseArgs(argv);
40
+ if (args.help) {
41
+ process.stdout.write(USAGE + "\n");
42
+ process.exit(0);
43
+ }
44
+ const logPath = args.log ?? ".neuroverse/audit.ndjson";
45
+ const events = await readAuditLog(logPath);
46
+ if (events.length === 0) {
47
+ process.stderr.write(`No audit events found in ${logPath}
48
+ `);
49
+ process.stderr.write("Run governance evaluations with audit logging enabled to generate events.\n");
50
+ process.exit(0);
51
+ }
52
+ const adaptations = events.map((event) => {
53
+ const agentId = event.actor ?? "unknown";
54
+ const intended = event.intent;
55
+ const executed = event.decision === "BLOCK" ? "idle" : intended;
56
+ const verdict = {
57
+ status: event.decision,
58
+ reason: event.reason,
59
+ ruleId: event.ruleId,
60
+ evidence: { worldId: event.worldId, worldName: event.worldName, worldVersion: event.worldVersion, evaluatedAt: Date.now(), invariantsSatisfied: 0, invariantsTotal: 0, guardsMatched: [], rulesMatched: [], enforcementLevel: "standard" }
61
+ };
62
+ return adaptationFromVerdict(agentId, intended, executed, verdict);
63
+ });
64
+ const uniqueAgents = new Set(adaptations.map((a) => a.agentId)).size;
65
+ const patterns = detectBehavioralPatterns(adaptations, uniqueAgents);
66
+ const narrative = generateAdaptationNarrative(patterns);
67
+ if (args.json) {
68
+ process.stdout.write(JSON.stringify({ adaptations: adaptations.length, agents: uniqueAgents, patterns, narrative }, null, 2) + "\n");
69
+ } else {
70
+ process.stdout.write("\nBehavioral Analysis\n");
71
+ process.stdout.write("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n");
72
+ process.stdout.write(` Events analyzed: ${events.length}
73
+ `);
74
+ process.stdout.write(` Agents observed: ${uniqueAgents}
75
+ `);
76
+ process.stdout.write(` Adaptations: ${adaptations.length}
77
+ `);
78
+ process.stdout.write(` Patterns found: ${patterns.length}
79
+
80
+ `);
81
+ if (patterns.length > 0) {
82
+ process.stdout.write("Patterns Detected\n");
83
+ process.stdout.write("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n");
84
+ for (const p of patterns) {
85
+ process.stdout.write(` ${p.type} (${p.agentsAffected} agents)
86
+ `);
87
+ process.stdout.write(` ${p.description}
88
+
89
+ `);
90
+ }
91
+ }
92
+ if (narrative) {
93
+ process.stdout.write("Narrative\n");
94
+ process.stdout.write("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n");
95
+ process.stdout.write(` ${narrative}
96
+
97
+ `);
98
+ }
99
+ const shiftCounts = {};
100
+ for (const a of adaptations) {
101
+ const key = a.shiftType ?? `${a.intendedAction}\u2192${a.executedAction}`;
102
+ shiftCounts[key] = (shiftCounts[key] ?? 0) + 1;
103
+ }
104
+ const sortedShifts = Object.entries(shiftCounts).sort((a, b) => b[1] - a[1]);
105
+ if (sortedShifts.length > 0) {
106
+ process.stdout.write("Shift Breakdown\n");
107
+ process.stdout.write("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n");
108
+ for (const [shift, count] of sortedShifts.slice(0, 10)) {
109
+ process.stdout.write(` ${shift}: ${count}
110
+ `);
111
+ }
112
+ process.stdout.write("\n");
113
+ }
114
+ }
115
+ }
116
+ export {
117
+ main
118
+ };