@neuroverseos/governance 0.2.2 → 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 (91) 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 +649 -109
  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 +152 -48
  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 +154 -50
  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 +152 -48
  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-2NICNKOM.js → chunk-4L6OPKMQ.js} +1 -1
  35. package/dist/chunk-5U2MQO5P.js +57 -0
  36. package/dist/{chunk-SKU3GAPD.js → chunk-6BB55YJI.js} +16 -34
  37. package/dist/{chunk-KEST3MWO.js → chunk-AF2VX4AL.js} +47 -8
  38. package/dist/chunk-BQZMOEML.js +43 -0
  39. package/dist/chunk-D2UCV5AK.js +326 -0
  40. package/dist/{chunk-RWXVAH6P.js → chunk-EVDJUSZ2.js} +16 -34
  41. package/dist/{chunk-4JRYGIO7.js → chunk-IZSO75NZ.js} +72 -7
  42. package/dist/chunk-JCKSW2PZ.js +304 -0
  43. package/dist/{chunk-PDOZHZWL.js → chunk-KTFTTLTP.js} +25 -4
  44. package/dist/{chunk-MWDQ4MJB.js → chunk-MH7BT4VH.js} +5 -1
  45. package/dist/{chunk-4QXB6PEO.js → chunk-QLPTHTVB.js} +37 -16
  46. package/dist/{chunk-QPASI2BR.js → chunk-REXY4LUL.js} +49 -10
  47. package/dist/chunk-T5EUJQE5.js +172 -0
  48. package/dist/{chunk-DPVS43ZT.js → chunk-TTBKTF3P.js} +5 -5
  49. package/dist/{chunk-OHAC6HJE.js → chunk-ZIVQNSZU.js} +16 -36
  50. package/dist/{chunk-BUWWN2NX.js → chunk-ZJTDUCC2.js} +9 -7
  51. package/dist/cli/neuroverse.cjs +2582 -493
  52. package/dist/cli/neuroverse.js +39 -15
  53. package/dist/cli/plan.cjs +119 -32
  54. package/dist/cli/plan.js +5 -13
  55. package/dist/cli/run.cjs +223 -24
  56. package/dist/cli/run.js +2 -2
  57. package/dist/decision-flow-LETV5NWY.js +61 -0
  58. package/dist/{derive-TLIV4OOU.js → derive-7365SUFU.js} +2 -2
  59. package/dist/{doctor-QV6HELS5.js → doctor-QYISMKEL.js} +5 -2
  60. package/dist/equity-penalties-63FGB3I2.js +244 -0
  61. package/dist/{explain-IDCRWMPX.js → explain-A2EWI2OL.js} +4 -23
  62. package/dist/{guard-GFLQZY6U.js → guard-3BWL3IGH.js} +6 -10
  63. package/dist/{guard-contract-Cm91Kp4j.d.ts → guard-contract-C9_zKbzd.d.cts} +117 -5
  64. package/dist/{guard-contract-Cm91Kp4j.d.cts → guard-contract-C9_zKbzd.d.ts} +117 -5
  65. package/dist/{guard-engine-JLTUARGU.js → guard-engine-QFMIBWJY.js} +2 -2
  66. package/dist/{impact-XPECYRLH.js → impact-UB6DXKSX.js} +4 -4
  67. package/dist/{improve-GPUBKTEA.js → improve-XZA57GER.js} +5 -24
  68. package/dist/index.cjs +592 -44
  69. package/dist/index.d.cts +218 -5
  70. package/dist/index.d.ts +218 -5
  71. package/dist/index.js +92 -41
  72. package/dist/infer-world-7GVZWFX4.js +543 -0
  73. package/dist/init-world-VWMQZQC7.js +223 -0
  74. package/dist/{mcp-server-LZVJHBT5.js → mcp-server-XWQZXNW7.js} +3 -3
  75. package/dist/{playground-FGOMASHN.js → playground-ADWZORNV.js} +2 -2
  76. package/dist/{redteam-SK7AMIG3.js → redteam-JRQ7FD2F.js} +2 -2
  77. package/dist/{session-VISISNWJ.js → session-MMYX5YCF.js} +4 -3
  78. package/dist/shared--Q8wPBVN.d.ts +60 -0
  79. package/dist/shared-HpAG90PX.d.cts +60 -0
  80. package/dist/shared-U2QFV7JH.js +16 -0
  81. package/dist/{simulate-VDOYQFRO.js → simulate-GMIFFXYV.js} +5 -30
  82. package/dist/{test-75AVHC3R.js → test-JBBZ65X4.js} +2 -2
  83. package/dist/{trace-JVF67VR3.js → trace-3MYWIDEF.js} +3 -3
  84. package/dist/worlds/autoresearch.nv-world.md +230 -0
  85. package/dist/worlds/coding-agent.nv-world.md +211 -0
  86. package/llms.txt +79 -0
  87. package/openapi.yaml +230 -0
  88. package/package.json +26 -4
  89. package/dist/{chunk-GR6DGCZ2.js → chunk-BMOXICAB.js} +3 -3
  90. package/dist/{chunk-NF5POFCI.js → chunk-ORJ3NOE6.js} +3 -3
  91. package/dist/{world-LAXO6DOX.js → world-BFJCIQSH.js} +3 -3
@@ -0,0 +1,181 @@
1
+ import { b as GuardEngineOptions, P as PlanDefinition, W as WorldDefinition, a as GuardVerdict, G as GuardEvent, c as PlanProgress } from '../guard-contract-C9_zKbzd.cjs';
2
+ import { G as GovernanceBlockedError$1 } from '../shared-HpAG90PX.cjs';
3
+
4
+ /**
5
+ * Centralized Tool Classification & Risk Pattern Detection
6
+ *
7
+ * Extracted from deep-agents.ts where it was the only adapter
8
+ * with comprehensive tool classification and dangerous command
9
+ * detection. Now available to all adapters and the core engine.
10
+ */
11
+ type ToolCategory = 'file_read' | 'file_write' | 'file_delete' | 'shell' | 'git' | 'network' | 'sub_agent' | 'context' | 'unknown';
12
+
13
+ /**
14
+ * NeuroVerse Adapter — Deep Agents (LangChain)
15
+ *
16
+ * Intercepts tool execution in LangChain's Deep Agents framework
17
+ * and evaluates every action against a NeuroVerse world definition
18
+ * before allowing it to proceed.
19
+ *
20
+ * Deep Agents exposes a coding-agent loop with tools for file I/O,
21
+ * shell execution, sub-agent spawning, and context management.
22
+ * This adapter sits between the agent and those tools, enforcing
23
+ * governance rules deterministically.
24
+ *
25
+ * Usage:
26
+ * import { createDeepAgentsGuard } from '@neuroverseos/governance/adapters/deep-agents';
27
+ *
28
+ * const guard = await createDeepAgentsGuard('./world/');
29
+ *
30
+ * // Wrap the agent's tool executor:
31
+ * agent.use(guard.middleware());
32
+ *
33
+ * // Or evaluate manually:
34
+ * const verdict = guard.evaluate({ tool: 'shell', command: 'rm -rf /' });
35
+ */
36
+
37
+ /** Shape of a Deep Agents tool invocation. */
38
+ interface DeepAgentsToolCall {
39
+ /** Tool name: read_file, write_file, shell, edit_file, sub_agent, etc. */
40
+ tool: string;
41
+ /** Tool arguments as passed by the agent. */
42
+ args: Record<string, unknown>;
43
+ /** Optional run/session identifier. */
44
+ runId?: string;
45
+ }
46
+ /** Categorized tool types recognized by the adapter (re-exported from tool-classifier). */
47
+ type DeepAgentsToolCategory = ToolCategory;
48
+ /** Result of a governed evaluation. */
49
+ interface DeepAgentsGuardResult {
50
+ allowed: boolean;
51
+ verdict: GuardVerdict;
52
+ toolCall: DeepAgentsToolCall;
53
+ category: DeepAgentsToolCategory;
54
+ }
55
+ interface DeepAgentsGuardOptions {
56
+ /** Include full evaluation trace in verdicts. Default: false. */
57
+ trace?: boolean;
58
+ /** Enforcement level override. */
59
+ level?: 'basic' | 'standard' | 'strict';
60
+ /** Called when an action is blocked. */
61
+ onBlock?: (result: DeepAgentsGuardResult) => void;
62
+ /** Called when an action requires approval. Return true to allow. */
63
+ onPause?: (result: DeepAgentsGuardResult) => Promise<boolean> | boolean;
64
+ /** Called for every evaluation (logging hook). */
65
+ onEvaluate?: (result: DeepAgentsGuardResult) => void;
66
+ /** Custom mapping from Deep Agents tool call to GuardEvent. */
67
+ mapToolCall?: (toolCall: DeepAgentsToolCall) => GuardEvent;
68
+ /** Active plan overlay for task-scoped governance. */
69
+ plan?: PlanDefinition;
70
+ /** Called when plan progress changes. */
71
+ onPlanProgress?: (progress: PlanProgress) => void;
72
+ /** Called when all plan steps are completed. */
73
+ onPlanComplete?: () => void;
74
+ }
75
+ declare class GovernanceBlockedError extends GovernanceBlockedError$1 {
76
+ readonly toolCall: DeepAgentsToolCall;
77
+ readonly category: DeepAgentsToolCategory;
78
+ constructor(verdict: GuardVerdict, toolCall: DeepAgentsToolCall, category: DeepAgentsToolCategory);
79
+ }
80
+ /**
81
+ * NeuroVerse governance guard for LangChain Deep Agents.
82
+ *
83
+ * Evaluates every tool invocation against a world definition before
84
+ * allowing execution. Supports blocking, pausing (approval required),
85
+ * and plan-scoped governance.
86
+ */
87
+ declare class DeepAgentsGuard {
88
+ readonly name = "neuroverse-deep-agents-guard";
89
+ private world;
90
+ private options;
91
+ engineOptions: GuardEngineOptions;
92
+ private mapToolCall;
93
+ activePlan?: PlanDefinition;
94
+ constructor(world: WorldDefinition, options?: DeepAgentsGuardOptions);
95
+ /**
96
+ * Evaluate a tool call against governance rules.
97
+ * Returns the result without side effects.
98
+ */
99
+ evaluate(toolCall: DeepAgentsToolCall): DeepAgentsGuardResult;
100
+ /**
101
+ * Evaluate and enforce governance on a tool call.
102
+ *
103
+ * @throws GovernanceBlockedError if BLOCKED
104
+ * @throws GovernanceBlockedError if PAUSED and onPause returns false
105
+ * @returns DeepAgentsGuardResult on ALLOW
106
+ */
107
+ enforce(toolCall: DeepAgentsToolCall): Promise<DeepAgentsGuardResult>;
108
+ /**
109
+ * Evaluate and execute a tool call with governance enforcement.
110
+ *
111
+ * If ALLOW: runs the executor and returns its result.
112
+ * If BLOCK: returns a governance-blocked message.
113
+ * If PAUSE: calls onPause; blocks if not approved.
114
+ *
115
+ * @param toolCall - The Deep Agents tool call to evaluate
116
+ * @param executor - The actual tool execution function
117
+ * @returns The tool execution result or a blocked message
118
+ */
119
+ execute<T>(toolCall: DeepAgentsToolCall, executor: (toolCall: DeepAgentsToolCall) => Promise<T>): Promise<{
120
+ result: T;
121
+ verdict: GuardVerdict;
122
+ } | {
123
+ blocked: true;
124
+ verdict: GuardVerdict;
125
+ reason: string;
126
+ }>;
127
+ /**
128
+ * Returns a middleware function compatible with Deep Agents' tool pipeline.
129
+ *
130
+ * The middleware intercepts tool calls before execution:
131
+ * agent.use(guard.middleware());
132
+ */
133
+ middleware(): (toolCall: DeepAgentsToolCall, next: () => Promise<unknown>) => Promise<unknown>;
134
+ /**
135
+ * Returns a callback-handler-style object for LangChain integration.
136
+ * Compatible with Deep Agents' callback system.
137
+ */
138
+ callbacks(): {
139
+ handleToolStart: (tool: {
140
+ name: string;
141
+ }, input: string) => Promise<void>;
142
+ };
143
+ /**
144
+ * Check if a shell command contains dangerous patterns.
145
+ * Useful for pre-screening before full governance evaluation.
146
+ */
147
+ static isDangerousCommand(command: string): {
148
+ dangerous: boolean;
149
+ labels: string[];
150
+ };
151
+ /**
152
+ * Check if a git command contains dangerous patterns.
153
+ */
154
+ static isDangerousGitCommand(command: string): {
155
+ dangerous: boolean;
156
+ labels: string[];
157
+ };
158
+ /**
159
+ * Classify a tool name into a category.
160
+ */
161
+ static classifyTool(toolName: string): DeepAgentsToolCategory;
162
+ private trackPlanProgressInternal;
163
+ }
164
+ /**
165
+ * Create a Deep Agents guard from a world path.
166
+ *
167
+ * @param worldPath - Path to world directory, .nv-world.md, or .nv-world.zip
168
+ * @param options - Guard configuration
169
+ * @returns A guard ready to plug into Deep Agents
170
+ */
171
+ declare function createDeepAgentsGuard(worldPath: string, options?: DeepAgentsGuardOptions): Promise<DeepAgentsGuard>;
172
+ /**
173
+ * Create a Deep Agents guard from a pre-loaded world.
174
+ *
175
+ * @param world - A loaded WorldDefinition
176
+ * @param options - Guard configuration
177
+ * @returns A guard ready to plug into Deep Agents
178
+ */
179
+ declare function createDeepAgentsGuardFromWorld(world: WorldDefinition, options?: DeepAgentsGuardOptions): DeepAgentsGuard;
180
+
181
+ export { DeepAgentsGuard, type DeepAgentsGuardOptions, type DeepAgentsGuardResult, type DeepAgentsToolCall, type DeepAgentsToolCategory, GovernanceBlockedError, createDeepAgentsGuard, createDeepAgentsGuardFromWorld };
@@ -0,0 +1,181 @@
1
+ import { b as GuardEngineOptions, P as PlanDefinition, W as WorldDefinition, a as GuardVerdict, G as GuardEvent, c as PlanProgress } from '../guard-contract-C9_zKbzd.js';
2
+ import { G as GovernanceBlockedError$1 } from '../shared--Q8wPBVN.js';
3
+
4
+ /**
5
+ * Centralized Tool Classification & Risk Pattern Detection
6
+ *
7
+ * Extracted from deep-agents.ts where it was the only adapter
8
+ * with comprehensive tool classification and dangerous command
9
+ * detection. Now available to all adapters and the core engine.
10
+ */
11
+ type ToolCategory = 'file_read' | 'file_write' | 'file_delete' | 'shell' | 'git' | 'network' | 'sub_agent' | 'context' | 'unknown';
12
+
13
+ /**
14
+ * NeuroVerse Adapter — Deep Agents (LangChain)
15
+ *
16
+ * Intercepts tool execution in LangChain's Deep Agents framework
17
+ * and evaluates every action against a NeuroVerse world definition
18
+ * before allowing it to proceed.
19
+ *
20
+ * Deep Agents exposes a coding-agent loop with tools for file I/O,
21
+ * shell execution, sub-agent spawning, and context management.
22
+ * This adapter sits between the agent and those tools, enforcing
23
+ * governance rules deterministically.
24
+ *
25
+ * Usage:
26
+ * import { createDeepAgentsGuard } from '@neuroverseos/governance/adapters/deep-agents';
27
+ *
28
+ * const guard = await createDeepAgentsGuard('./world/');
29
+ *
30
+ * // Wrap the agent's tool executor:
31
+ * agent.use(guard.middleware());
32
+ *
33
+ * // Or evaluate manually:
34
+ * const verdict = guard.evaluate({ tool: 'shell', command: 'rm -rf /' });
35
+ */
36
+
37
+ /** Shape of a Deep Agents tool invocation. */
38
+ interface DeepAgentsToolCall {
39
+ /** Tool name: read_file, write_file, shell, edit_file, sub_agent, etc. */
40
+ tool: string;
41
+ /** Tool arguments as passed by the agent. */
42
+ args: Record<string, unknown>;
43
+ /** Optional run/session identifier. */
44
+ runId?: string;
45
+ }
46
+ /** Categorized tool types recognized by the adapter (re-exported from tool-classifier). */
47
+ type DeepAgentsToolCategory = ToolCategory;
48
+ /** Result of a governed evaluation. */
49
+ interface DeepAgentsGuardResult {
50
+ allowed: boolean;
51
+ verdict: GuardVerdict;
52
+ toolCall: DeepAgentsToolCall;
53
+ category: DeepAgentsToolCategory;
54
+ }
55
+ interface DeepAgentsGuardOptions {
56
+ /** Include full evaluation trace in verdicts. Default: false. */
57
+ trace?: boolean;
58
+ /** Enforcement level override. */
59
+ level?: 'basic' | 'standard' | 'strict';
60
+ /** Called when an action is blocked. */
61
+ onBlock?: (result: DeepAgentsGuardResult) => void;
62
+ /** Called when an action requires approval. Return true to allow. */
63
+ onPause?: (result: DeepAgentsGuardResult) => Promise<boolean> | boolean;
64
+ /** Called for every evaluation (logging hook). */
65
+ onEvaluate?: (result: DeepAgentsGuardResult) => void;
66
+ /** Custom mapping from Deep Agents tool call to GuardEvent. */
67
+ mapToolCall?: (toolCall: DeepAgentsToolCall) => GuardEvent;
68
+ /** Active plan overlay for task-scoped governance. */
69
+ plan?: PlanDefinition;
70
+ /** Called when plan progress changes. */
71
+ onPlanProgress?: (progress: PlanProgress) => void;
72
+ /** Called when all plan steps are completed. */
73
+ onPlanComplete?: () => void;
74
+ }
75
+ declare class GovernanceBlockedError extends GovernanceBlockedError$1 {
76
+ readonly toolCall: DeepAgentsToolCall;
77
+ readonly category: DeepAgentsToolCategory;
78
+ constructor(verdict: GuardVerdict, toolCall: DeepAgentsToolCall, category: DeepAgentsToolCategory);
79
+ }
80
+ /**
81
+ * NeuroVerse governance guard for LangChain Deep Agents.
82
+ *
83
+ * Evaluates every tool invocation against a world definition before
84
+ * allowing execution. Supports blocking, pausing (approval required),
85
+ * and plan-scoped governance.
86
+ */
87
+ declare class DeepAgentsGuard {
88
+ readonly name = "neuroverse-deep-agents-guard";
89
+ private world;
90
+ private options;
91
+ engineOptions: GuardEngineOptions;
92
+ private mapToolCall;
93
+ activePlan?: PlanDefinition;
94
+ constructor(world: WorldDefinition, options?: DeepAgentsGuardOptions);
95
+ /**
96
+ * Evaluate a tool call against governance rules.
97
+ * Returns the result without side effects.
98
+ */
99
+ evaluate(toolCall: DeepAgentsToolCall): DeepAgentsGuardResult;
100
+ /**
101
+ * Evaluate and enforce governance on a tool call.
102
+ *
103
+ * @throws GovernanceBlockedError if BLOCKED
104
+ * @throws GovernanceBlockedError if PAUSED and onPause returns false
105
+ * @returns DeepAgentsGuardResult on ALLOW
106
+ */
107
+ enforce(toolCall: DeepAgentsToolCall): Promise<DeepAgentsGuardResult>;
108
+ /**
109
+ * Evaluate and execute a tool call with governance enforcement.
110
+ *
111
+ * If ALLOW: runs the executor and returns its result.
112
+ * If BLOCK: returns a governance-blocked message.
113
+ * If PAUSE: calls onPause; blocks if not approved.
114
+ *
115
+ * @param toolCall - The Deep Agents tool call to evaluate
116
+ * @param executor - The actual tool execution function
117
+ * @returns The tool execution result or a blocked message
118
+ */
119
+ execute<T>(toolCall: DeepAgentsToolCall, executor: (toolCall: DeepAgentsToolCall) => Promise<T>): Promise<{
120
+ result: T;
121
+ verdict: GuardVerdict;
122
+ } | {
123
+ blocked: true;
124
+ verdict: GuardVerdict;
125
+ reason: string;
126
+ }>;
127
+ /**
128
+ * Returns a middleware function compatible with Deep Agents' tool pipeline.
129
+ *
130
+ * The middleware intercepts tool calls before execution:
131
+ * agent.use(guard.middleware());
132
+ */
133
+ middleware(): (toolCall: DeepAgentsToolCall, next: () => Promise<unknown>) => Promise<unknown>;
134
+ /**
135
+ * Returns a callback-handler-style object for LangChain integration.
136
+ * Compatible with Deep Agents' callback system.
137
+ */
138
+ callbacks(): {
139
+ handleToolStart: (tool: {
140
+ name: string;
141
+ }, input: string) => Promise<void>;
142
+ };
143
+ /**
144
+ * Check if a shell command contains dangerous patterns.
145
+ * Useful for pre-screening before full governance evaluation.
146
+ */
147
+ static isDangerousCommand(command: string): {
148
+ dangerous: boolean;
149
+ labels: string[];
150
+ };
151
+ /**
152
+ * Check if a git command contains dangerous patterns.
153
+ */
154
+ static isDangerousGitCommand(command: string): {
155
+ dangerous: boolean;
156
+ labels: string[];
157
+ };
158
+ /**
159
+ * Classify a tool name into a category.
160
+ */
161
+ static classifyTool(toolName: string): DeepAgentsToolCategory;
162
+ private trackPlanProgressInternal;
163
+ }
164
+ /**
165
+ * Create a Deep Agents guard from a world path.
166
+ *
167
+ * @param worldPath - Path to world directory, .nv-world.md, or .nv-world.zip
168
+ * @param options - Guard configuration
169
+ * @returns A guard ready to plug into Deep Agents
170
+ */
171
+ declare function createDeepAgentsGuard(worldPath: string, options?: DeepAgentsGuardOptions): Promise<DeepAgentsGuard>;
172
+ /**
173
+ * Create a Deep Agents guard from a pre-loaded world.
174
+ *
175
+ * @param world - A loaded WorldDefinition
176
+ * @param options - Guard configuration
177
+ * @returns A guard ready to plug into Deep Agents
178
+ */
179
+ declare function createDeepAgentsGuardFromWorld(world: WorldDefinition, options?: DeepAgentsGuardOptions): DeepAgentsGuard;
180
+
181
+ export { DeepAgentsGuard, type DeepAgentsGuardOptions, type DeepAgentsGuardResult, type DeepAgentsToolCall, type DeepAgentsToolCategory, GovernanceBlockedError, createDeepAgentsGuard, createDeepAgentsGuardFromWorld };
@@ -0,0 +1,17 @@
1
+ import {
2
+ DeepAgentsGuard,
3
+ GovernanceBlockedError,
4
+ createDeepAgentsGuard,
5
+ createDeepAgentsGuardFromWorld
6
+ } from "../chunk-JCKSW2PZ.js";
7
+ import "../chunk-5U2MQO5P.js";
8
+ import "../chunk-IZSO75NZ.js";
9
+ import "../chunk-QLPTHTVB.js";
10
+ import "../chunk-JZPQGIKR.js";
11
+ import "../chunk-YZFATT7X.js";
12
+ export {
13
+ DeepAgentsGuard,
14
+ GovernanceBlockedError,
15
+ createDeepAgentsGuard,
16
+ createDeepAgentsGuardFromWorld
17
+ };
@@ -35,17 +35,27 @@ __export(express_exports, {
35
35
  });
36
36
  module.exports = __toCommonJS(express_exports);
37
37
 
38
- // src/engine/plan-engine.ts
39
- function keywordMatch(eventText, step) {
40
- const stepText = [
41
- step.label,
42
- step.description ?? "",
43
- ...step.tags ?? []
38
+ // src/engine/text-utils.ts
39
+ function normalizeEventText(event) {
40
+ return [
41
+ event.intent,
42
+ event.tool ?? "",
43
+ event.scope ?? ""
44
44
  ].join(" ").toLowerCase();
45
- const keywords = stepText.split(/\s+/).filter((w) => w.length > 3);
45
+ }
46
+ function extractKeywords(text, minLength = 3) {
47
+ return text.toLowerCase().split(/\s+/).filter((w) => w.length > minLength);
48
+ }
49
+ function matchesAllKeywords(eventText, ruleText) {
50
+ const keywords = extractKeywords(ruleText);
51
+ if (keywords.length === 0) return false;
52
+ return keywords.every((kw) => eventText.includes(kw));
53
+ }
54
+ function matchesKeywordThreshold(eventText, ruleText, threshold = 0.5) {
55
+ const keywords = extractKeywords(ruleText);
46
56
  if (keywords.length === 0) return false;
47
57
  const matched = keywords.filter((kw) => eventText.includes(kw));
48
- return matched.length >= Math.ceil(keywords.length * 0.5);
58
+ return matched.length >= Math.ceil(keywords.length * threshold);
49
59
  }
50
60
  function tokenSimilarity(a, b) {
51
61
  const tokensA = new Set(a.toLowerCase().split(/\s+/).filter((w) => w.length > 2));
@@ -58,6 +68,19 @@ function tokenSimilarity(a, b) {
58
68
  const union = (/* @__PURE__ */ new Set([...tokensA, ...tokensB])).size;
59
69
  return union > 0 ? intersection / union : 0;
60
70
  }
71
+
72
+ // src/engine/plan-engine.ts
73
+ function keywordMatch(eventText, step) {
74
+ const stepText = [
75
+ step.label,
76
+ step.description ?? "",
77
+ ...step.tags ?? []
78
+ ].join(" ");
79
+ return matchesKeywordThreshold(eventText, stepText, 0.5);
80
+ }
81
+ function tokenSimilarity2(a, b) {
82
+ return tokenSimilarity(a, b);
83
+ }
61
84
  function findMatchingStep(eventText, event, steps) {
62
85
  const pendingOrActive = steps.filter((s) => s.status === "pending" || s.status === "active");
63
86
  if (pendingOrActive.length === 0) {
@@ -76,7 +99,7 @@ function findMatchingStep(eventText, event, steps) {
76
99
  let bestScore = 0;
77
100
  for (const step of pendingOrActive) {
78
101
  const stepText = [step.label, step.description ?? "", ...step.tags ?? []].join(" ");
79
- const score = tokenSimilarity(intentText, stepText);
102
+ const score = tokenSimilarity2(intentText, stepText);
80
103
  if (score > bestScore) {
81
104
  bestScore = score;
82
105
  bestStep = step;
@@ -117,7 +140,7 @@ function checkConstraints(event, eventText, constraints) {
117
140
  continue;
118
141
  }
119
142
  if (constraint.type === "scope" && constraint.trigger) {
120
- const keywords = constraint.trigger.split(/\s+/).filter((w) => w.length > 3);
143
+ const keywords = extractKeywords(constraint.trigger);
121
144
  const violated = keywords.length > 0 && keywords.every((kw) => eventText.includes(kw));
122
145
  checks.push({
123
146
  constraintId: constraint.id,
@@ -163,11 +186,7 @@ function evaluatePlan(event, plan) {
163
186
  progress
164
187
  };
165
188
  }
166
- const eventText = [
167
- event.intent,
168
- event.tool ?? "",
169
- event.scope ?? ""
170
- ].join(" ").toLowerCase();
189
+ const eventText = normalizeEventText(event);
171
190
  const { matched, closest, closestScore } = findMatchingStep(eventText, event, plan.steps);
172
191
  if (!matched) {
173
192
  return {
@@ -208,7 +227,7 @@ function evaluatePlan(event, plan) {
208
227
  };
209
228
  }
210
229
  function buildPlanCheck(event, plan, verdict) {
211
- const eventText = [event.intent, event.tool ?? "", event.scope ?? ""].join(" ").toLowerCase();
230
+ const eventText = normalizeEventText(event);
212
231
  const { matched, closest, closestScore } = findMatchingStep(eventText, event, plan.steps);
213
232
  const { checks: constraintChecks } = checkConstraints(event, eventText, plan.constraints);
214
233
  const progress = getPlanProgress(plan);
@@ -314,7 +333,7 @@ function evaluateGuard(event, world, options = {}) {
314
333
  const startTime = performance.now();
315
334
  const level = options.level ?? "standard";
316
335
  const includeTrace = options.trace ?? false;
317
- const eventText = (event.intent + " " + (event.tool ?? "") + " " + (event.scope ?? "")).toLowerCase();
336
+ const eventText = normalizeEventText(event);
318
337
  const invariantChecks = [];
319
338
  const safetyChecks = [];
320
339
  let planCheckResult;
@@ -327,6 +346,43 @@ function evaluateGuard(event, world, options = {}) {
327
346
  const guardsMatched = [];
328
347
  const rulesMatched = [];
329
348
  checkInvariantCoverage(world, invariantChecks);
349
+ if (event.roleId && options.agentStates) {
350
+ const agentState = options.agentStates.get(event.roleId);
351
+ if (agentState && agentState.cooldownRemaining > 0) {
352
+ decidingLayer = "safety";
353
+ decidingId = `penalize-cooldown-${event.roleId}`;
354
+ const verdict = buildVerdict(
355
+ "PENALIZE",
356
+ `Agent "${event.roleId}" is frozen for ${agentState.cooldownRemaining} more round(s) due to prior penalty.`,
357
+ `penalize-cooldown-${event.roleId}`,
358
+ void 0,
359
+ world,
360
+ level,
361
+ invariantChecks,
362
+ guardsMatched,
363
+ rulesMatched,
364
+ includeTrace ? buildTrace(
365
+ invariantChecks,
366
+ safetyChecks,
367
+ planCheckResult,
368
+ roleChecks,
369
+ guardChecks,
370
+ kernelRuleChecks,
371
+ levelChecks,
372
+ decidingLayer,
373
+ decidingId,
374
+ startTime
375
+ ) : void 0
376
+ );
377
+ verdict.intentRecord = {
378
+ originalIntent: event.intent,
379
+ finalAction: "blocked (agent frozen)",
380
+ enforcement: "PENALIZE",
381
+ consequence: { type: "freeze", rounds: agentState.cooldownRemaining, description: "Agent still in cooldown from prior penalty" }
382
+ };
383
+ return verdict;
384
+ }
385
+ }
330
386
  if (options.sessionAllowlist) {
331
387
  const key = eventToAllowlistKey(event);
332
388
  if (options.sessionAllowlist.has(key)) {
@@ -454,7 +510,16 @@ function evaluateGuard(event, world, options = {}) {
454
510
  if (guardVerdict.status !== "ALLOW") {
455
511
  decidingLayer = "guard";
456
512
  decidingId = guardVerdict.ruleId;
457
- return buildVerdict(
513
+ const intentRecord = {
514
+ originalIntent: event.intent,
515
+ 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",
516
+ ruleApplied: guardVerdict.ruleId,
517
+ enforcement: guardVerdict.status,
518
+ modifiedTo: guardVerdict.modifiedTo,
519
+ consequence: guardVerdict.consequence,
520
+ reward: guardVerdict.reward
521
+ };
522
+ const verdict = buildVerdict(
458
523
  guardVerdict.status,
459
524
  guardVerdict.reason,
460
525
  guardVerdict.ruleId,
@@ -477,6 +542,10 @@ function evaluateGuard(event, world, options = {}) {
477
542
  startTime
478
543
  ) : void 0
479
544
  );
545
+ verdict.intentRecord = intentRecord;
546
+ if (guardVerdict.consequence) verdict.consequence = guardVerdict.consequence;
547
+ if (guardVerdict.reward) verdict.reward = guardVerdict.reward;
548
+ return verdict;
480
549
  }
481
550
  }
482
551
  const kernelVerdict = checkKernelRules(eventText, world, kernelRuleChecks, rulesMatched);
@@ -771,6 +840,21 @@ function checkGuards(event, eventText, world, checks, guardsMatched) {
771
840
  if (actionMode === "pause") {
772
841
  return { status: "PAUSE", reason, ruleId: `guard-${guard.id}` };
773
842
  }
843
+ if (actionMode === "penalize") {
844
+ const consequence = guard.consequence ? { ...guard.consequence } : { type: "freeze", rounds: 1, description: `Penalized for violating: ${guard.label}` };
845
+ return { status: "PENALIZE", reason, ruleId: `guard-${guard.id}`, consequence };
846
+ }
847
+ if (actionMode === "reward") {
848
+ const reward = guard.reward ? { ...guard.reward } : { type: "boost_influence", magnitude: 0.1, description: `Rewarded for: ${guard.label}` };
849
+ return { status: "REWARD", reason, ruleId: `guard-${guard.id}`, reward };
850
+ }
851
+ if (actionMode === "modify") {
852
+ const modifiedTo = guard.modify_to ?? guard.redirect ?? "hold";
853
+ return { status: "MODIFY", reason: `${reason} \u2192 Modified to: ${modifiedTo}`, ruleId: `guard-${guard.id}`, modifiedTo };
854
+ }
855
+ if (actionMode === "neutral") {
856
+ return { status: "NEUTRAL", reason, ruleId: `guard-${guard.id}` };
857
+ }
774
858
  if (actionMode === "warn" && !warnResult) {
775
859
  warnResult = { status: "ALLOW", warning: reason, ruleId: `guard-${guard.id}` };
776
860
  }
@@ -880,9 +964,7 @@ function checkLevelConstraints(event, level, checks) {
880
964
  return null;
881
965
  }
882
966
  function matchesKeywords(eventText, ruleText) {
883
- const keywords = ruleText.toLowerCase().split(/\s+/).filter((w) => w.length > 3);
884
- if (keywords.length === 0) return false;
885
- return keywords.every((kw) => eventText.includes(kw));
967
+ return matchesAllKeywords(eventText, ruleText);
886
968
  }
887
969
  function eventToAllowlistKey(event) {
888
970
  return `${(event.tool ?? "*").toLowerCase()}::${event.intent.toLowerCase().trim()}`;
@@ -1,4 +1,4 @@
1
- import { G as GuardVerdict, a as GuardEvent, W as WorldDefinition } from '../guard-contract-Cm91Kp4j.cjs';
1
+ import { a as GuardVerdict, G as GuardEvent, W as WorldDefinition } from '../guard-contract-C9_zKbzd.cjs';
2
2
 
3
3
  /**
4
4
  * NeuroVerse Adapter — Express / Fastify
@@ -1,4 +1,4 @@
1
- import { G as GuardVerdict, a as GuardEvent, W as WorldDefinition } from '../guard-contract-Cm91Kp4j.js';
1
+ import { a as GuardVerdict, G as GuardEvent, W as WorldDefinition } from '../guard-contract-C9_zKbzd.js';
2
2
 
3
3
  /**
4
4
  * NeuroVerse Adapter — Express / Fastify
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  createGovernanceMiddleware,
3
3
  createGovernanceMiddlewareFromWorld
4
- } from "../chunk-2NICNKOM.js";
5
- import "../chunk-4JRYGIO7.js";
4
+ } from "../chunk-4L6OPKMQ.js";
5
+ import "../chunk-IZSO75NZ.js";
6
+ import "../chunk-QLPTHTVB.js";
6
7
  import "../chunk-JZPQGIKR.js";
7
- import "../chunk-4QXB6PEO.js";
8
8
  import "../chunk-YZFATT7X.js";
9
9
  export {
10
10
  createGovernanceMiddleware,