@neuroverseos/governance 0.3.3 → 0.3.4

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 (34) hide show
  1. package/dist/adapters/autoresearch.d.cts +1 -1
  2. package/dist/adapters/autoresearch.d.ts +1 -1
  3. package/dist/adapters/deep-agents.d.cts +2 -2
  4. package/dist/adapters/deep-agents.d.ts +2 -2
  5. package/dist/adapters/express.d.cts +1 -1
  6. package/dist/adapters/express.d.ts +1 -1
  7. package/dist/adapters/index.d.cts +2 -2
  8. package/dist/adapters/index.d.ts +2 -2
  9. package/dist/adapters/langchain.d.cts +2 -2
  10. package/dist/adapters/langchain.d.ts +2 -2
  11. package/dist/adapters/openai.d.cts +2 -2
  12. package/dist/adapters/openai.d.ts +2 -2
  13. package/dist/adapters/openclaw.d.cts +2 -2
  14. package/dist/adapters/openclaw.d.ts +2 -2
  15. package/dist/{build-QKOBBC23.js → build-ZHPMX5AZ.js} +3 -2
  16. package/dist/chunk-FMSTRBBS.js +17 -0
  17. package/dist/{chunk-Q6O7ZLO2.js → chunk-INWQHLPS.js} +1 -16
  18. package/dist/chunk-VXHSMA3I.js +166 -0
  19. package/dist/{chunk-6S5CFQXY.js → chunk-YEKMVDWK.js} +3 -3
  20. package/dist/cli/neuroverse.cjs +191 -3
  21. package/dist/cli/neuroverse.js +4 -4
  22. package/dist/{configure-ai-6TZ3MCSI.js → configure-ai-5MP5DWTT.js} +5 -3
  23. package/dist/{derive-FJZVIPUZ.js → derive-LMDUTXDD.js} +3 -2
  24. package/dist/{guard-AJCCGZMF.js → guard-AEEJNWLD.js} +39 -5
  25. package/dist/{guard-contract-DqFcTScd.d.cts → guard-contract-B7lplwm9.d.cts} +16 -0
  26. package/dist/{guard-contract-DqFcTScd.d.ts → guard-contract-B7lplwm9.d.ts} +16 -0
  27. package/dist/index.cjs +195 -48
  28. package/dist/index.d.cts +221 -66
  29. package/dist/index.d.ts +221 -66
  30. package/dist/index.js +11 -4
  31. package/dist/{shared-B8dvUUD8.d.cts → shared-C_zpdvBm.d.cts} +1 -1
  32. package/dist/{shared-Dr5Wiay8.d.ts → shared-Cf7yxx4-.d.ts} +1 -1
  33. package/package.json +1 -1
  34. package/dist/chunk-MH7BT4VH.js +0 -15
@@ -1,4 +1,4 @@
1
- import { W as WorldDefinition, G as GuardEvent, a as GuardVerdict } from '../guard-contract-DqFcTScd.cjs';
1
+ import { W as WorldDefinition, G as GuardEvent, a as GuardVerdict } from '../guard-contract-B7lplwm9.cjs';
2
2
 
3
3
  /**
4
4
  * Autoresearch Adapter — Bridge between NeuroVerse governance and autoresearch loops
@@ -1,4 +1,4 @@
1
- import { W as WorldDefinition, G as GuardEvent, a as GuardVerdict } from '../guard-contract-DqFcTScd.js';
1
+ import { W as WorldDefinition, G as GuardEvent, a as GuardVerdict } from '../guard-contract-B7lplwm9.js';
2
2
 
3
3
  /**
4
4
  * Autoresearch Adapter — Bridge between NeuroVerse governance and autoresearch loops
@@ -1,5 +1,5 @@
1
- import { b as GuardEngineOptions, P as PlanDefinition, W as WorldDefinition, a as GuardVerdict, G as GuardEvent, c as PlanProgress } from '../guard-contract-DqFcTScd.cjs';
2
- import { G as GovernanceBlockedError$1 } from '../shared-B8dvUUD8.cjs';
1
+ import { b as GuardEngineOptions, P as PlanDefinition, W as WorldDefinition, a as GuardVerdict, G as GuardEvent, c as PlanProgress } from '../guard-contract-B7lplwm9.cjs';
2
+ import { G as GovernanceBlockedError$1 } from '../shared-C_zpdvBm.cjs';
3
3
 
4
4
  /**
5
5
  * Centralized Tool Classification & Risk Pattern Detection
@@ -1,5 +1,5 @@
1
- import { b as GuardEngineOptions, P as PlanDefinition, W as WorldDefinition, a as GuardVerdict, G as GuardEvent, c as PlanProgress } from '../guard-contract-DqFcTScd.js';
2
- import { G as GovernanceBlockedError$1 } from '../shared-Dr5Wiay8.js';
1
+ import { b as GuardEngineOptions, P as PlanDefinition, W as WorldDefinition, a as GuardVerdict, G as GuardEvent, c as PlanProgress } from '../guard-contract-B7lplwm9.js';
2
+ import { G as GovernanceBlockedError$1 } from '../shared-Cf7yxx4-.js';
3
3
 
4
4
  /**
5
5
  * Centralized Tool Classification & Risk Pattern Detection
@@ -1,4 +1,4 @@
1
- import { a as GuardVerdict, G as GuardEvent, W as WorldDefinition } from '../guard-contract-DqFcTScd.cjs';
1
+ import { a as GuardVerdict, G as GuardEvent, W as WorldDefinition } from '../guard-contract-B7lplwm9.cjs';
2
2
 
3
3
  /**
4
4
  * NeuroVerse Adapter — Express / Fastify
@@ -1,4 +1,4 @@
1
- import { a as GuardVerdict, G as GuardEvent, W as WorldDefinition } from '../guard-contract-DqFcTScd.js';
1
+ import { a as GuardVerdict, G as GuardEvent, W as WorldDefinition } from '../guard-contract-B7lplwm9.js';
2
2
 
3
3
  /**
4
4
  * NeuroVerse Adapter — Express / Fastify
@@ -1,8 +1,8 @@
1
- export { B as BaseAdapterOptions, G as GovernanceBlockedError, P as PlanTrackingCallbacks, a as PlanTrackingState, b as buildEngineOptions, d as defaultBlockMessage, e as extractScope, t as trackPlanProgress } from '../shared-B8dvUUD8.cjs';
1
+ export { B as BaseAdapterOptions, G as GovernanceBlockedError, P as PlanTrackingCallbacks, a as PlanTrackingState, b as buildEngineOptions, d as defaultBlockMessage, e as extractScope, t as trackPlanProgress } from '../shared-C_zpdvBm.cjs';
2
2
  export { GovernanceBlockedError as LangChainGovernanceBlockedError, NeuroVerseCallbackHandler, NeuroVerseHandlerOptions, createNeuroVerseCallbackHandler, createNeuroVerseCallbackHandlerFromWorld } from './langchain.cjs';
3
3
  export { GovernedExecutorOptions, GovernedToolExecutor, GovernedToolResult, GovernanceBlockedError as OpenAIGovernanceBlockedError, OpenAIToolCall, createGovernedToolExecutor, createGovernedToolExecutorFromWorld } from './openai.cjs';
4
4
  export { AgentAction, HookResult, NeuroVersePlugin, NeuroVersePluginOptions, GovernanceBlockedError as OpenClawGovernanceBlockedError, createNeuroVersePlugin, createNeuroVersePluginFromWorld } from './openclaw.cjs';
5
5
  export { GovernanceMiddlewareOptions, GovernanceRequest, GovernanceResponse, createGovernanceMiddleware, createGovernanceMiddlewareFromWorld } from './express.cjs';
6
6
  export { AutoresearchGovernor, AutoresearchGovernorConfig, ExperimentProposal, ExperimentResult, ResearchState } from './autoresearch.cjs';
7
7
  export { GovernanceBlockedError as DeepAgentsGovernanceBlockedError, DeepAgentsGuard, DeepAgentsGuardOptions, DeepAgentsGuardResult, DeepAgentsToolCall, DeepAgentsToolCategory, createDeepAgentsGuard, createDeepAgentsGuardFromWorld } from './deep-agents.cjs';
8
- import '../guard-contract-DqFcTScd.cjs';
8
+ import '../guard-contract-B7lplwm9.cjs';
@@ -1,8 +1,8 @@
1
- export { B as BaseAdapterOptions, G as GovernanceBlockedError, P as PlanTrackingCallbacks, a as PlanTrackingState, b as buildEngineOptions, d as defaultBlockMessage, e as extractScope, t as trackPlanProgress } from '../shared-Dr5Wiay8.js';
1
+ export { B as BaseAdapterOptions, G as GovernanceBlockedError, P as PlanTrackingCallbacks, a as PlanTrackingState, b as buildEngineOptions, d as defaultBlockMessage, e as extractScope, t as trackPlanProgress } from '../shared-Cf7yxx4-.js';
2
2
  export { GovernanceBlockedError as LangChainGovernanceBlockedError, NeuroVerseCallbackHandler, NeuroVerseHandlerOptions, createNeuroVerseCallbackHandler, createNeuroVerseCallbackHandlerFromWorld } from './langchain.js';
3
3
  export { GovernedExecutorOptions, GovernedToolExecutor, GovernedToolResult, GovernanceBlockedError as OpenAIGovernanceBlockedError, OpenAIToolCall, createGovernedToolExecutor, createGovernedToolExecutorFromWorld } from './openai.js';
4
4
  export { AgentAction, HookResult, NeuroVersePlugin, NeuroVersePluginOptions, GovernanceBlockedError as OpenClawGovernanceBlockedError, createNeuroVersePlugin, createNeuroVersePluginFromWorld } from './openclaw.js';
5
5
  export { GovernanceMiddlewareOptions, GovernanceRequest, GovernanceResponse, createGovernanceMiddleware, createGovernanceMiddlewareFromWorld } from './express.js';
6
6
  export { AutoresearchGovernor, AutoresearchGovernorConfig, ExperimentProposal, ExperimentResult, ResearchState } from './autoresearch.js';
7
7
  export { GovernanceBlockedError as DeepAgentsGovernanceBlockedError, DeepAgentsGuard, DeepAgentsGuardOptions, DeepAgentsGuardResult, DeepAgentsToolCall, DeepAgentsToolCategory, createDeepAgentsGuard, createDeepAgentsGuardFromWorld } from './deep-agents.js';
8
- import '../guard-contract-DqFcTScd.js';
8
+ import '../guard-contract-B7lplwm9.js';
@@ -1,5 +1,5 @@
1
- import { G as GuardEvent, a as GuardVerdict, b as GuardEngineOptions, P as PlanDefinition, W as WorldDefinition, c as PlanProgress } from '../guard-contract-DqFcTScd.cjs';
2
- import { G as GovernanceBlockedError$1 } from '../shared-B8dvUUD8.cjs';
1
+ import { G as GuardEvent, a as GuardVerdict, b as GuardEngineOptions, P as PlanDefinition, W as WorldDefinition, c as PlanProgress } from '../guard-contract-B7lplwm9.cjs';
2
+ import { G as GovernanceBlockedError$1 } from '../shared-C_zpdvBm.cjs';
3
3
 
4
4
  /**
5
5
  * NeuroVerse Adapter — LangChain
@@ -1,5 +1,5 @@
1
- import { G as GuardEvent, a as GuardVerdict, b as GuardEngineOptions, P as PlanDefinition, W as WorldDefinition, c as PlanProgress } from '../guard-contract-DqFcTScd.js';
2
- import { G as GovernanceBlockedError$1 } from '../shared-Dr5Wiay8.js';
1
+ import { G as GuardEvent, a as GuardVerdict, b as GuardEngineOptions, P as PlanDefinition, W as WorldDefinition, c as PlanProgress } from '../guard-contract-B7lplwm9.js';
2
+ import { G as GovernanceBlockedError$1 } from '../shared-Cf7yxx4-.js';
3
3
 
4
4
  /**
5
5
  * NeuroVerse Adapter — LangChain
@@ -1,5 +1,5 @@
1
- import { a as GuardVerdict, G as GuardEvent, P as PlanDefinition, c as PlanProgress, b as GuardEngineOptions, W as WorldDefinition } from '../guard-contract-DqFcTScd.cjs';
2
- import { G as GovernanceBlockedError$1 } from '../shared-B8dvUUD8.cjs';
1
+ import { a as GuardVerdict, G as GuardEvent, P as PlanDefinition, c as PlanProgress, b as GuardEngineOptions, W as WorldDefinition } from '../guard-contract-B7lplwm9.cjs';
2
+ import { G as GovernanceBlockedError$1 } from '../shared-C_zpdvBm.cjs';
3
3
 
4
4
  /**
5
5
  * NeuroVerse Adapter — OpenAI
@@ -1,5 +1,5 @@
1
- import { a as GuardVerdict, G as GuardEvent, P as PlanDefinition, c as PlanProgress, b as GuardEngineOptions, W as WorldDefinition } from '../guard-contract-DqFcTScd.js';
2
- import { G as GovernanceBlockedError$1 } from '../shared-Dr5Wiay8.js';
1
+ import { a as GuardVerdict, G as GuardEvent, P as PlanDefinition, c as PlanProgress, b as GuardEngineOptions, W as WorldDefinition } from '../guard-contract-B7lplwm9.js';
2
+ import { G as GovernanceBlockedError$1 } from '../shared-Cf7yxx4-.js';
3
3
 
4
4
  /**
5
5
  * NeuroVerse Adapter — OpenAI
@@ -1,5 +1,5 @@
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';
1
+ import { a as GuardVerdict, b as GuardEngineOptions, P as PlanDefinition, W as WorldDefinition, G as GuardEvent, c as PlanProgress } from '../guard-contract-B7lplwm9.cjs';
2
+ import { G as GovernanceBlockedError$1 } from '../shared-C_zpdvBm.cjs';
3
3
 
4
4
  /**
5
5
  * NeuroVerse Adapter — OpenClaw
@@ -1,5 +1,5 @@
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';
1
+ import { a as GuardVerdict, b as GuardEngineOptions, P as PlanDefinition, W as WorldDefinition, G as GuardEvent, c as PlanProgress } from '../guard-contract-B7lplwm9.js';
2
+ import { G as GovernanceBlockedError$1 } from '../shared-Cf7yxx4-.js';
3
3
 
4
4
  /**
5
5
  * NeuroVerse Adapter — OpenClaw
@@ -2,11 +2,12 @@ import {
2
2
  DeriveInputError,
3
3
  DeriveProviderError,
4
4
  deriveWorld
5
- } from "./chunk-6S5CFQXY.js";
5
+ } from "./chunk-YEKMVDWK.js";
6
6
  import {
7
7
  DERIVE_EXIT_CODES
8
- } from "./chunk-Q6O7ZLO2.js";
8
+ } from "./chunk-FMSTRBBS.js";
9
9
  import "./chunk-OT6PXH54.js";
10
+ import "./chunk-INWQHLPS.js";
10
11
  import "./chunk-7P3S7MAY.js";
11
12
  import {
12
13
  parseWorldMarkdown
@@ -0,0 +1,17 @@
1
+ // src/contracts/derive-contract.ts
2
+ var DERIVE_EXIT_CODES = {
3
+ SUCCESS: 0,
4
+ VALIDATION_FAIL: 1,
5
+ INPUT_ERROR: 2,
6
+ PROVIDER_ERROR: 3
7
+ };
8
+ var CONFIGURE_AI_EXIT_CODES = {
9
+ SUCCESS: 0,
10
+ VALIDATION_FAIL: 1,
11
+ ERROR: 3
12
+ };
13
+
14
+ export {
15
+ DERIVE_EXIT_CODES,
16
+ CONFIGURE_AI_EXIT_CODES
17
+ };
@@ -42,21 +42,6 @@ function createProvider(config) {
42
42
  return new ChatCompletionsProvider(config);
43
43
  }
44
44
 
45
- // src/contracts/derive-contract.ts
46
- var DERIVE_EXIT_CODES = {
47
- SUCCESS: 0,
48
- VALIDATION_FAIL: 1,
49
- INPUT_ERROR: 2,
50
- PROVIDER_ERROR: 3
51
- };
52
- var CONFIGURE_AI_EXIT_CODES = {
53
- SUCCESS: 0,
54
- VALIDATION_FAIL: 1,
55
- ERROR: 3
56
- };
57
-
58
45
  export {
59
- createProvider,
60
- DERIVE_EXIT_CODES,
61
- CONFIGURE_AI_EXIT_CODES
46
+ createProvider
62
47
  };
@@ -0,0 +1,166 @@
1
+ import {
2
+ createProvider
3
+ } from "./chunk-INWQHLPS.js";
4
+ import {
5
+ evaluateGuard
6
+ } from "./chunk-W7LLXRGY.js";
7
+
8
+ // src/engine/intent-classifier.ts
9
+ function buildSystemPrompt(knownIntents) {
10
+ let prompt = `You are an intent classifier for an AI governance system. Your job is to analyze structured content fields and produce a clean, semantic intent label.
11
+
12
+ CRITICAL RULES:
13
+ 1. Distinguish WHO is performing the action. If the AI agent says "I am escalating your request", that is the AI being polite \u2014 NOT the customer demanding escalation.
14
+ 2. Focus on the CUSTOMER'S actual intent, not the AI's response language.
15
+ 3. Return a short, snake_case intent label (e.g. "shipping_inquiry", "complaint_escalation", "password_reset").
16
+ 4. Assess the actor: who initiated this action? The customer, the AI agent, or the system?
17
+
18
+ You must respond with ONLY valid JSON in this exact format:
19
+ {"intent": "<label>", "confidence": <0-1>, "actor": "<customer|ai_agent|system|unknown>", "reasoning": "<one sentence>"}`;
20
+ if (knownIntents && knownIntents.length > 0) {
21
+ prompt += `
22
+
23
+ Preferred intent labels (use these when applicable, but you may create new ones if none fit):
24
+ ${knownIntents.map((i) => `- ${i}`).join("\n")}`;
25
+ }
26
+ return prompt;
27
+ }
28
+ function buildUserPrompt(fields) {
29
+ const parts = [];
30
+ if (fields.customer_input) {
31
+ parts.push(`CUSTOMER INPUT:
32
+ ${fields.customer_input}`);
33
+ }
34
+ if (fields.draft_reply) {
35
+ parts.push(`AI DRAFT REPLY:
36
+ ${fields.draft_reply}`);
37
+ }
38
+ if (fields.tool) {
39
+ parts.push(`TOOL: ${fields.tool}`);
40
+ }
41
+ if (fields.context) {
42
+ parts.push(`CONTEXT: ${fields.context}`);
43
+ }
44
+ if (fields.raw && parts.length === 0) {
45
+ parts.push(`RAW TEXT:
46
+ ${fields.raw}`);
47
+ }
48
+ return parts.join("\n\n");
49
+ }
50
+ async function classifyIntentWithAI(fields, options) {
51
+ const provider = createProvider(options.ai);
52
+ const systemPrompt = buildSystemPrompt(options.knownIntents);
53
+ const userPrompt = buildUserPrompt(fields);
54
+ const response = await provider.complete(systemPrompt, userPrompt);
55
+ const jsonMatch = response.match(/\{[\s\S]*\}/);
56
+ if (!jsonMatch) {
57
+ throw new Error("Intent classifier returned non-JSON response");
58
+ }
59
+ const parsed = JSON.parse(jsonMatch[0]);
60
+ if (!parsed.intent || typeof parsed.intent !== "string") {
61
+ throw new Error("Intent classifier returned invalid intent label");
62
+ }
63
+ return {
64
+ intent: parsed.intent,
65
+ confidence: typeof parsed.confidence === "number" ? parsed.confidence : 0.5,
66
+ actor: ["customer", "ai_agent", "system", "unknown"].includes(
67
+ parsed.actor
68
+ ) ? parsed.actor : "unknown",
69
+ reasoning: parsed.reasoning ?? ""
70
+ };
71
+ }
72
+ var OUTPUT_CONTENT_FIELDS = /* @__PURE__ */ new Set([
73
+ "draft_reply",
74
+ "content",
75
+ "body",
76
+ "message",
77
+ "text",
78
+ "reply",
79
+ "response",
80
+ "output",
81
+ "html",
82
+ "template"
83
+ ]);
84
+ function extractContentFields(intent, args) {
85
+ if (!args) {
86
+ return { raw: intent };
87
+ }
88
+ const fields = {};
89
+ let hasStructuredContent = false;
90
+ for (const [key, value] of Object.entries(args)) {
91
+ if (typeof value !== "string") continue;
92
+ const lowerKey = key.toLowerCase();
93
+ if (OUTPUT_CONTENT_FIELDS.has(lowerKey)) {
94
+ fields.draft_reply = fields.draft_reply ? `${fields.draft_reply}
95
+
96
+ ${value}` : value;
97
+ hasStructuredContent = true;
98
+ }
99
+ }
100
+ if (hasStructuredContent) {
101
+ fields.customer_input = intent;
102
+ } else {
103
+ fields.raw = intent;
104
+ }
105
+ return fields;
106
+ }
107
+
108
+ // src/engine/ai-guard.ts
109
+ async function evaluateGuardWithAI(event, world, options = {}) {
110
+ if (!options.ai) {
111
+ const verdict = evaluateGuard(event, world, options);
112
+ verdict.intent_source = "raw";
113
+ return verdict;
114
+ }
115
+ const fallbackOnError = options.fallbackOnError ?? true;
116
+ const originalIntent = event.intent;
117
+ const knownIntents = options.knownIntents ?? extractKnownIntents(world);
118
+ const contentFields = options.contentFields ?? extractContentFields(event.intent, event.args);
119
+ try {
120
+ const classification = await classifyIntentWithAI(contentFields, {
121
+ ai: options.ai,
122
+ knownIntents
123
+ });
124
+ const classifiedEvent = {
125
+ ...event,
126
+ intent: classification.intent
127
+ };
128
+ const verdict = evaluateGuard(classifiedEvent, world, options);
129
+ verdict.intent_source = "ai";
130
+ verdict.classification = classification;
131
+ verdict.originalIntent = originalIntent;
132
+ return verdict;
133
+ } catch (err) {
134
+ if (fallbackOnError) {
135
+ const verdict = evaluateGuard(event, world, options);
136
+ verdict.intent_source = "fallback";
137
+ verdict.originalIntent = originalIntent;
138
+ return verdict;
139
+ }
140
+ throw err;
141
+ }
142
+ }
143
+ function extractKnownIntents(world) {
144
+ const vocab = world.guards?.intent_vocabulary;
145
+ if (!vocab) return [];
146
+ return Object.keys(vocab);
147
+ }
148
+
149
+ // src/contracts/guard-contract.ts
150
+ var GUARD_EXIT_CODES = {
151
+ ALLOW: 0,
152
+ BLOCK: 1,
153
+ PAUSE: 2,
154
+ ERROR: 3,
155
+ MODIFY: 4,
156
+ PENALIZE: 5,
157
+ REWARD: 6,
158
+ NEUTRAL: 7
159
+ };
160
+
161
+ export {
162
+ classifyIntentWithAI,
163
+ extractContentFields,
164
+ evaluateGuardWithAI,
165
+ GUARD_EXIT_CODES
166
+ };
@@ -1,9 +1,9 @@
1
- import {
2
- createProvider
3
- } from "./chunk-Q6O7ZLO2.js";
4
1
  import {
5
2
  loadConfig
6
3
  } from "./chunk-OT6PXH54.js";
4
+ import {
5
+ createProvider
6
+ } from "./chunk-INWQHLPS.js";
7
7
  import {
8
8
  validateWorld
9
9
  } from "./chunk-7P3S7MAY.js";
@@ -6959,6 +6959,161 @@ var init_guard_engine = __esm({
6959
6959
  }
6960
6960
  });
6961
6961
 
6962
+ // src/engine/intent-classifier.ts
6963
+ function buildSystemPrompt2(knownIntents) {
6964
+ let prompt = `You are an intent classifier for an AI governance system. Your job is to analyze structured content fields and produce a clean, semantic intent label.
6965
+
6966
+ CRITICAL RULES:
6967
+ 1. Distinguish WHO is performing the action. If the AI agent says "I am escalating your request", that is the AI being polite \u2014 NOT the customer demanding escalation.
6968
+ 2. Focus on the CUSTOMER'S actual intent, not the AI's response language.
6969
+ 3. Return a short, snake_case intent label (e.g. "shipping_inquiry", "complaint_escalation", "password_reset").
6970
+ 4. Assess the actor: who initiated this action? The customer, the AI agent, or the system?
6971
+
6972
+ You must respond with ONLY valid JSON in this exact format:
6973
+ {"intent": "<label>", "confidence": <0-1>, "actor": "<customer|ai_agent|system|unknown>", "reasoning": "<one sentence>"}`;
6974
+ if (knownIntents && knownIntents.length > 0) {
6975
+ prompt += `
6976
+
6977
+ Preferred intent labels (use these when applicable, but you may create new ones if none fit):
6978
+ ${knownIntents.map((i) => `- ${i}`).join("\n")}`;
6979
+ }
6980
+ return prompt;
6981
+ }
6982
+ function buildUserPrompt2(fields) {
6983
+ const parts = [];
6984
+ if (fields.customer_input) {
6985
+ parts.push(`CUSTOMER INPUT:
6986
+ ${fields.customer_input}`);
6987
+ }
6988
+ if (fields.draft_reply) {
6989
+ parts.push(`AI DRAFT REPLY:
6990
+ ${fields.draft_reply}`);
6991
+ }
6992
+ if (fields.tool) {
6993
+ parts.push(`TOOL: ${fields.tool}`);
6994
+ }
6995
+ if (fields.context) {
6996
+ parts.push(`CONTEXT: ${fields.context}`);
6997
+ }
6998
+ if (fields.raw && parts.length === 0) {
6999
+ parts.push(`RAW TEXT:
7000
+ ${fields.raw}`);
7001
+ }
7002
+ return parts.join("\n\n");
7003
+ }
7004
+ async function classifyIntentWithAI(fields, options) {
7005
+ const provider = createProvider(options.ai);
7006
+ const systemPrompt = buildSystemPrompt2(options.knownIntents);
7007
+ const userPrompt = buildUserPrompt2(fields);
7008
+ const response = await provider.complete(systemPrompt, userPrompt);
7009
+ const jsonMatch = response.match(/\{[\s\S]*\}/);
7010
+ if (!jsonMatch) {
7011
+ throw new Error("Intent classifier returned non-JSON response");
7012
+ }
7013
+ const parsed = JSON.parse(jsonMatch[0]);
7014
+ if (!parsed.intent || typeof parsed.intent !== "string") {
7015
+ throw new Error("Intent classifier returned invalid intent label");
7016
+ }
7017
+ return {
7018
+ intent: parsed.intent,
7019
+ confidence: typeof parsed.confidence === "number" ? parsed.confidence : 0.5,
7020
+ actor: ["customer", "ai_agent", "system", "unknown"].includes(
7021
+ parsed.actor
7022
+ ) ? parsed.actor : "unknown",
7023
+ reasoning: parsed.reasoning ?? ""
7024
+ };
7025
+ }
7026
+ function extractContentFields(intent, args) {
7027
+ if (!args) {
7028
+ return { raw: intent };
7029
+ }
7030
+ const fields = {};
7031
+ let hasStructuredContent = false;
7032
+ for (const [key, value] of Object.entries(args)) {
7033
+ if (typeof value !== "string") continue;
7034
+ const lowerKey = key.toLowerCase();
7035
+ if (OUTPUT_CONTENT_FIELDS.has(lowerKey)) {
7036
+ fields.draft_reply = fields.draft_reply ? `${fields.draft_reply}
7037
+
7038
+ ${value}` : value;
7039
+ hasStructuredContent = true;
7040
+ }
7041
+ }
7042
+ if (hasStructuredContent) {
7043
+ fields.customer_input = intent;
7044
+ } else {
7045
+ fields.raw = intent;
7046
+ }
7047
+ return fields;
7048
+ }
7049
+ var OUTPUT_CONTENT_FIELDS;
7050
+ var init_intent_classifier = __esm({
7051
+ "src/engine/intent-classifier.ts"() {
7052
+ "use strict";
7053
+ init_ai_provider();
7054
+ OUTPUT_CONTENT_FIELDS = /* @__PURE__ */ new Set([
7055
+ "draft_reply",
7056
+ "content",
7057
+ "body",
7058
+ "message",
7059
+ "text",
7060
+ "reply",
7061
+ "response",
7062
+ "output",
7063
+ "html",
7064
+ "template"
7065
+ ]);
7066
+ }
7067
+ });
7068
+
7069
+ // src/engine/ai-guard.ts
7070
+ async function evaluateGuardWithAI(event, world, options = {}) {
7071
+ if (!options.ai) {
7072
+ const verdict = evaluateGuard(event, world, options);
7073
+ verdict.intent_source = "raw";
7074
+ return verdict;
7075
+ }
7076
+ const fallbackOnError = options.fallbackOnError ?? true;
7077
+ const originalIntent = event.intent;
7078
+ const knownIntents = options.knownIntents ?? extractKnownIntents(world);
7079
+ const contentFields = options.contentFields ?? extractContentFields(event.intent, event.args);
7080
+ try {
7081
+ const classification = await classifyIntentWithAI(contentFields, {
7082
+ ai: options.ai,
7083
+ knownIntents
7084
+ });
7085
+ const classifiedEvent = {
7086
+ ...event,
7087
+ intent: classification.intent
7088
+ };
7089
+ const verdict = evaluateGuard(classifiedEvent, world, options);
7090
+ verdict.intent_source = "ai";
7091
+ verdict.classification = classification;
7092
+ verdict.originalIntent = originalIntent;
7093
+ return verdict;
7094
+ } catch (err) {
7095
+ if (fallbackOnError) {
7096
+ const verdict = evaluateGuard(event, world, options);
7097
+ verdict.intent_source = "fallback";
7098
+ verdict.originalIntent = originalIntent;
7099
+ return verdict;
7100
+ }
7101
+ throw err;
7102
+ }
7103
+ }
7104
+ function extractKnownIntents(world) {
7105
+ const vocab = world.guards?.intent_vocabulary;
7106
+ if (!vocab) return [];
7107
+ return Object.keys(vocab);
7108
+ }
7109
+ var init_ai_guard = __esm({
7110
+ "src/engine/ai-guard.ts"() {
7111
+ "use strict";
7112
+ init_guard_engine();
7113
+ init_intent_classifier();
7114
+ }
7115
+ });
7116
+
6962
7117
  // src/contracts/guard-contract.ts
6963
7118
  var GUARD_EXIT_CODES;
6964
7119
  var init_guard_contract = __esm({
@@ -6986,12 +7141,15 @@ function parseArgs11(argv) {
6986
7141
  let worldPath = "";
6987
7142
  let trace = false;
6988
7143
  let level;
7144
+ let aiClassify = false;
6989
7145
  for (let i = 0; i < argv.length; i++) {
6990
7146
  const arg = argv[i];
6991
7147
  if (arg === "--world" && i + 1 < argv.length) {
6992
7148
  worldPath = argv[++i];
6993
7149
  } else if (arg === "--trace") {
6994
7150
  trace = true;
7151
+ } else if (arg === "--ai-classify") {
7152
+ aiClassify = true;
6995
7153
  } else if (arg === "--level" && i + 1 < argv.length) {
6996
7154
  const val = argv[++i];
6997
7155
  if (val === "basic" || val === "standard" || val === "strict") {
@@ -7001,7 +7159,7 @@ function parseArgs11(argv) {
7001
7159
  }
7002
7160
  }
7003
7161
  }
7004
- return { worldPath, trace, level };
7162
+ return { worldPath, trace, level, aiClassify };
7005
7163
  }
7006
7164
  async function main11(argv = process.argv.slice(2)) {
7007
7165
  try {
@@ -7040,8 +7198,27 @@ async function main11(argv = process.argv.slice(2)) {
7040
7198
  process.exit(GUARD_EXIT_CODES.ERROR);
7041
7199
  }
7042
7200
  const world = await loadWorld(worldPath);
7043
- const options = { trace: args.trace, level: args.level };
7044
- const verdict = evaluateGuard(event, world, options);
7201
+ let verdict;
7202
+ if (args.aiClassify) {
7203
+ const aiConfig = resolveAIConfig();
7204
+ if (!aiConfig) {
7205
+ const errorResult = {
7206
+ error: "AI classification requires an API key. Set NEUROVERSE_AI_API_KEY and optionally NEUROVERSE_AI_MODEL, NEUROVERSE_AI_ENDPOINT."
7207
+ };
7208
+ process.stdout.write(JSON.stringify(errorResult, null, 2) + "\n");
7209
+ process.exit(GUARD_EXIT_CODES.ERROR);
7210
+ }
7211
+ process.stderr.write("AI intent classification enabled\n");
7212
+ verdict = await evaluateGuardWithAI(event, world, {
7213
+ trace: args.trace,
7214
+ level: args.level,
7215
+ ai: aiConfig,
7216
+ contentFields: event.contentFields
7217
+ });
7218
+ } else {
7219
+ const options = { trace: args.trace, level: args.level };
7220
+ verdict = evaluateGuard(event, world, options);
7221
+ }
7045
7222
  process.stdout.write(JSON.stringify(verdict, null, 2) + "\n");
7046
7223
  const exitCode = GUARD_EXIT_CODES[verdict.status];
7047
7224
  process.exit(exitCode);
@@ -7051,10 +7228,21 @@ async function main11(argv = process.argv.slice(2)) {
7051
7228
  process.exit(GUARD_EXIT_CODES.ERROR);
7052
7229
  }
7053
7230
  }
7231
+ function resolveAIConfig() {
7232
+ const apiKey = process.env.NEUROVERSE_AI_API_KEY;
7233
+ if (!apiKey) return null;
7234
+ return {
7235
+ provider: "openai",
7236
+ model: process.env.NEUROVERSE_AI_MODEL ?? "gpt-4o-mini",
7237
+ apiKey,
7238
+ endpoint: process.env.NEUROVERSE_AI_ENDPOINT ?? null
7239
+ };
7240
+ }
7054
7241
  var init_guard = __esm({
7055
7242
  "src/cli/guard.ts"() {
7056
7243
  "use strict";
7057
7244
  init_guard_engine();
7245
+ init_ai_guard();
7058
7246
  init_world_loader();
7059
7247
  init_world_resolver();
7060
7248
  init_guard_contract();
@@ -96,7 +96,7 @@ async function main() {
96
96
  return addMain(subArgs);
97
97
  }
98
98
  case "build": {
99
- const { main: buildMain } = await import("../build-QKOBBC23.js");
99
+ const { main: buildMain } = await import("../build-ZHPMX5AZ.js");
100
100
  return buildMain(subArgs);
101
101
  }
102
102
  case "explain": {
@@ -132,7 +132,7 @@ async function main() {
132
132
  return validateMain(subArgs);
133
133
  }
134
134
  case "guard": {
135
- const { main: guardMain } = await import("../guard-AJCCGZMF.js");
135
+ const { main: guardMain } = await import("../guard-AEEJNWLD.js");
136
136
  return guardMain(subArgs);
137
137
  }
138
138
  case "test": {
@@ -188,7 +188,7 @@ async function main() {
188
188
  return worldMain(subArgs);
189
189
  }
190
190
  case "derive": {
191
- const { main: deriveMain } = await import("../derive-FJZVIPUZ.js");
191
+ const { main: deriveMain } = await import("../derive-LMDUTXDD.js");
192
192
  return deriveMain(subArgs);
193
193
  }
194
194
  case "decision-flow": {
@@ -200,7 +200,7 @@ async function main() {
200
200
  return equityPenaltiesMain(subArgs);
201
201
  }
202
202
  case "configure-ai": {
203
- const { main: configureAiMain } = await import("../configure-ai-6TZ3MCSI.js");
203
+ const { main: configureAiMain } = await import("../configure-ai-5MP5DWTT.js");
204
204
  return configureAiMain(subArgs);
205
205
  }
206
206
  case "--help":
@@ -1,13 +1,15 @@
1
1
  import {
2
- CONFIGURE_AI_EXIT_CODES,
3
- createProvider
4
- } from "./chunk-Q6O7ZLO2.js";
2
+ CONFIGURE_AI_EXIT_CODES
3
+ } from "./chunk-FMSTRBBS.js";
5
4
  import {
6
5
  getConfigPath,
7
6
  loadConfig,
8
7
  redactConfig,
9
8
  saveConfig
10
9
  } from "./chunk-OT6PXH54.js";
10
+ import {
11
+ createProvider
12
+ } from "./chunk-INWQHLPS.js";
11
13
  import "./chunk-QWGCMQQD.js";
12
14
 
13
15
  // src/cli/configure-ai.ts