@neuroverseos/governance 0.3.1 → 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.
- package/.well-known/ai-plugin.json +34 -9
- package/AGENTS.md +72 -24
- package/README.md +343 -248
- package/dist/adapters/autoresearch.cjs +1345 -0
- package/dist/adapters/autoresearch.d.cts +111 -0
- package/dist/adapters/autoresearch.d.ts +111 -0
- package/dist/adapters/autoresearch.js +12 -0
- package/dist/adapters/deep-agents.cjs +1528 -0
- package/dist/adapters/deep-agents.d.cts +181 -0
- package/dist/adapters/deep-agents.d.ts +181 -0
- package/dist/adapters/deep-agents.js +17 -0
- package/dist/adapters/express.cjs +1253 -0
- package/dist/adapters/express.d.cts +66 -0
- package/dist/adapters/express.d.ts +66 -0
- package/dist/adapters/express.js +12 -0
- package/dist/adapters/index.cjs +2112 -0
- package/dist/adapters/index.d.cts +8 -0
- package/dist/adapters/index.d.ts +8 -0
- package/dist/adapters/index.js +68 -0
- package/dist/adapters/langchain.cjs +1315 -0
- package/dist/adapters/langchain.d.cts +89 -0
- package/dist/adapters/langchain.d.ts +89 -0
- package/dist/adapters/langchain.js +17 -0
- package/dist/adapters/openai.cjs +1345 -0
- package/dist/adapters/openai.d.cts +99 -0
- package/dist/adapters/openai.d.ts +99 -0
- package/dist/adapters/openai.js +17 -0
- package/dist/adapters/openclaw.cjs +1337 -0
- package/dist/adapters/openclaw.d.cts +99 -0
- package/dist/adapters/openclaw.d.ts +99 -0
- package/dist/adapters/openclaw.js +17 -0
- package/dist/add-ROOZLU62.js +314 -0
- package/dist/behavioral-MJO34S6Q.js +118 -0
- package/dist/bootstrap-CQRZVOXK.js +116 -0
- package/dist/bootstrap-emitter-Q7UIJZ2O.js +7 -0
- package/dist/bootstrap-parser-EEF36XDU.js +7 -0
- package/dist/browser.global.js +941 -0
- package/dist/build-ZHPMX5AZ.js +342 -0
- package/dist/chunk-3WQLXYTP.js +91 -0
- package/dist/chunk-4FLICVVA.js +119 -0
- package/dist/chunk-4NGDRRQH.js +10 -0
- package/dist/chunk-5TPFNWRU.js +215 -0
- package/dist/chunk-5U2MQO5P.js +57 -0
- package/dist/chunk-6CZSKEY5.js +164 -0
- package/dist/chunk-7P3S7MAY.js +1090 -0
- package/dist/chunk-A5W4GNQO.js +130 -0
- package/dist/chunk-A7GKPPU7.js +226 -0
- package/dist/chunk-AKW5YVCE.js +96 -0
- package/dist/chunk-B6OXJLJ5.js +622 -0
- package/dist/chunk-BNKJPUPQ.js +113 -0
- package/dist/chunk-BQZMOEML.js +43 -0
- package/dist/chunk-CNSO6XW5.js +207 -0
- package/dist/chunk-CTZHONLA.js +135 -0
- package/dist/chunk-D2UCV5AK.js +326 -0
- package/dist/chunk-EMQDLDAF.js +458 -0
- package/dist/chunk-F66BVUYB.js +340 -0
- package/dist/chunk-FMSTRBBS.js +17 -0
- package/dist/chunk-G7DJ6VOD.js +101 -0
- package/dist/chunk-I3RRAYK2.js +11 -0
- package/dist/chunk-INWQHLPS.js +47 -0
- package/dist/chunk-IS4WUH6Y.js +363 -0
- package/dist/chunk-O5ABKEA7.js +304 -0
- package/dist/chunk-OT6PXH54.js +61 -0
- package/dist/chunk-PVTQQS3Y.js +186 -0
- package/dist/chunk-QLPTHTVB.js +253 -0
- package/dist/chunk-QWGCMQQD.js +16 -0
- package/dist/chunk-QXBFT7NI.js +201 -0
- package/dist/chunk-TG6SEF24.js +246 -0
- package/dist/chunk-U6U7EJZL.js +177 -0
- package/dist/chunk-VXHSMA3I.js +166 -0
- package/dist/chunk-W7LLXRGY.js +830 -0
- package/dist/chunk-YEKMVDWK.js +624 -0
- package/dist/chunk-ZJTDUCC2.js +194 -0
- package/dist/chunk-ZWI3NIXK.js +314 -0
- package/dist/cli/neuroverse.cjs +14379 -0
- package/dist/cli/neuroverse.d.cts +1 -0
- package/dist/cli/neuroverse.d.ts +1 -0
- package/dist/cli/neuroverse.js +227 -0
- package/dist/cli/plan.cjs +2439 -0
- package/dist/cli/plan.d.cts +20 -0
- package/dist/cli/plan.d.ts +20 -0
- package/dist/cli/plan.js +353 -0
- package/dist/cli/run.cjs +2001 -0
- package/dist/cli/run.d.cts +20 -0
- package/dist/cli/run.d.ts +20 -0
- package/dist/cli/run.js +143 -0
- package/dist/configure-ai-5MP5DWTT.js +134 -0
- package/dist/decision-flow-M63D47LO.js +61 -0
- package/dist/demo-G43RLCPK.js +469 -0
- package/dist/derive-LMDUTXDD.js +154 -0
- package/dist/doctor-6BC6X2VO.js +173 -0
- package/dist/equity-penalties-SG5IZQ7I.js +244 -0
- package/dist/explain-RHBU2GBR.js +51 -0
- package/dist/guard-AEEJNWLD.js +126 -0
- package/dist/guard-contract-B7lplwm9.d.cts +837 -0
- package/dist/guard-contract-B7lplwm9.d.ts +837 -0
- package/dist/guard-engine-PNR6MHCM.js +10 -0
- package/dist/impact-3XVDSCBU.js +59 -0
- package/dist/improve-TQP4ECSY.js +66 -0
- package/dist/index.cjs +7738 -0
- package/dist/index.d.cts +2350 -0
- package/dist/index.d.ts +2350 -0
- package/dist/index.js +479 -0
- package/dist/infer-world-IFXCACJ5.js +543 -0
- package/dist/init-FYPV4SST.js +144 -0
- package/dist/init-world-TI7ARHBT.js +223 -0
- package/dist/mcp-server-5Y3ZM7TV.js +13 -0
- package/dist/model-adapter-VXEKB4LS.js +11 -0
- package/dist/playground-VZBNPPBO.js +560 -0
- package/dist/redteam-MZPZD3EF.js +357 -0
- package/dist/session-JYOARW54.js +15 -0
- package/dist/shared-7RLUHNMU.js +16 -0
- package/dist/shared-C_zpdvBm.d.cts +60 -0
- package/dist/shared-Cf7yxx4-.d.ts +60 -0
- package/dist/simulate-LJXYBC6M.js +83 -0
- package/dist/test-BOOR4A5F.js +217 -0
- package/dist/trace-PKV4KX56.js +166 -0
- package/dist/validate-RALX7CZS.js +81 -0
- package/dist/validate-engine-7ZXFVGF2.js +7 -0
- package/dist/viz/assets/index-B8SaeJZZ.js +23 -0
- package/dist/viz/index.html +23 -0
- package/dist/world-BIP4GZBZ.js +376 -0
- package/dist/world-loader-Y6HMQH2D.js +13 -0
- package/dist/worlds/autoresearch.nv-world.md +230 -0
- package/dist/worlds/coding-agent.nv-world.md +211 -0
- package/dist/worlds/derivation-world.nv-world.md +278 -0
- package/dist/worlds/research-agent.nv-world.md +169 -0
- package/dist/worlds/social-media.nv-world.md +198 -0
- package/dist/worlds/trading-agent.nv-world.md +218 -0
- package/examples/social-media-sim/bridge.py +209 -0
- package/examples/social-media-sim/simulation.py +927 -0
- package/package.json +16 -3
- package/simulate.html +4 -336
package/dist/index.js
ADDED
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
import {
|
|
2
|
+
actionToGuardEvent,
|
|
3
|
+
createGovernor,
|
|
4
|
+
govern,
|
|
5
|
+
handleCreateCapsule,
|
|
6
|
+
handleHealthCheck,
|
|
7
|
+
handleListPresets,
|
|
8
|
+
handleReasonRequest,
|
|
9
|
+
writeTempWorld
|
|
10
|
+
} from "./chunk-U6U7EJZL.js";
|
|
11
|
+
import {
|
|
12
|
+
generateImpactReport,
|
|
13
|
+
generateImpactReportFromFile,
|
|
14
|
+
renderImpactReport
|
|
15
|
+
} from "./chunk-TG6SEF24.js";
|
|
16
|
+
import {
|
|
17
|
+
adaptationFromVerdict,
|
|
18
|
+
classifyAdaptation,
|
|
19
|
+
detectBehavioralPatterns,
|
|
20
|
+
generateAdaptationNarrative
|
|
21
|
+
} from "./chunk-CNSO6XW5.js";
|
|
22
|
+
import {
|
|
23
|
+
CompositeAuditLogger,
|
|
24
|
+
ConsoleAuditLogger,
|
|
25
|
+
FileAuditLogger,
|
|
26
|
+
createGovernanceEngine,
|
|
27
|
+
readAuditLog,
|
|
28
|
+
summarizeAuditEvents,
|
|
29
|
+
verdictToAuditEvent
|
|
30
|
+
} from "./chunk-A7GKPPU7.js";
|
|
31
|
+
import {
|
|
32
|
+
improveWorld,
|
|
33
|
+
renderImproveText
|
|
34
|
+
} from "./chunk-F66BVUYB.js";
|
|
35
|
+
import {
|
|
36
|
+
BOOTSTRAP_EXIT_CODES
|
|
37
|
+
} from "./chunk-4NGDRRQH.js";
|
|
38
|
+
import {
|
|
39
|
+
VALIDATE_EXIT_CODES
|
|
40
|
+
} from "./chunk-I3RRAYK2.js";
|
|
41
|
+
import {
|
|
42
|
+
GUARD_EXIT_CODES,
|
|
43
|
+
classifyIntentWithAI,
|
|
44
|
+
evaluateGuardWithAI,
|
|
45
|
+
extractContentFields
|
|
46
|
+
} from "./chunk-VXHSMA3I.js";
|
|
47
|
+
import {
|
|
48
|
+
ModelAdapter,
|
|
49
|
+
PROVIDERS,
|
|
50
|
+
resolveProvider
|
|
51
|
+
} from "./chunk-A5W4GNQO.js";
|
|
52
|
+
import {
|
|
53
|
+
McpGovernanceServer
|
|
54
|
+
} from "./chunk-B6OXJLJ5.js";
|
|
55
|
+
import {
|
|
56
|
+
addGuard,
|
|
57
|
+
addInvariant,
|
|
58
|
+
addRule,
|
|
59
|
+
classifyIntent,
|
|
60
|
+
parseGuardDescription
|
|
61
|
+
} from "./chunk-5TPFNWRU.js";
|
|
62
|
+
import {
|
|
63
|
+
deriveWorld,
|
|
64
|
+
extractWorldMarkdown,
|
|
65
|
+
normalizeWorldMarkdown
|
|
66
|
+
} from "./chunk-YEKMVDWK.js";
|
|
67
|
+
import {
|
|
68
|
+
CONFIGURE_AI_EXIT_CODES,
|
|
69
|
+
DERIVE_EXIT_CODES
|
|
70
|
+
} from "./chunk-FMSTRBBS.js";
|
|
71
|
+
import "./chunk-OT6PXH54.js";
|
|
72
|
+
import "./chunk-INWQHLPS.js";
|
|
73
|
+
import {
|
|
74
|
+
validateWorld
|
|
75
|
+
} from "./chunk-7P3S7MAY.js";
|
|
76
|
+
import {
|
|
77
|
+
explainWorld,
|
|
78
|
+
renderExplainText
|
|
79
|
+
} from "./chunk-ZJTDUCC2.js";
|
|
80
|
+
import {
|
|
81
|
+
renderSimulateText,
|
|
82
|
+
simulateWorld
|
|
83
|
+
} from "./chunk-ZWI3NIXK.js";
|
|
84
|
+
import {
|
|
85
|
+
PLAN_EXIT_CODES,
|
|
86
|
+
parsePlanMarkdown
|
|
87
|
+
} from "./chunk-6CZSKEY5.js";
|
|
88
|
+
import {
|
|
89
|
+
describeActiveWorld,
|
|
90
|
+
getActiveWorldName,
|
|
91
|
+
listWorlds,
|
|
92
|
+
resolveWorldPath,
|
|
93
|
+
setActiveWorld
|
|
94
|
+
} from "./chunk-AKW5YVCE.js";
|
|
95
|
+
import {
|
|
96
|
+
parseWorldMarkdown
|
|
97
|
+
} from "./chunk-EMQDLDAF.js";
|
|
98
|
+
import {
|
|
99
|
+
emitWorldDefinition
|
|
100
|
+
} from "./chunk-PVTQQS3Y.js";
|
|
101
|
+
import {
|
|
102
|
+
SessionManager,
|
|
103
|
+
runInteractiveMode,
|
|
104
|
+
runPipeMode
|
|
105
|
+
} from "./chunk-IS4WUH6Y.js";
|
|
106
|
+
import {
|
|
107
|
+
applyConsequence,
|
|
108
|
+
applyReward,
|
|
109
|
+
createAgentState,
|
|
110
|
+
generateDecisionFlow,
|
|
111
|
+
renderDecisionFlow,
|
|
112
|
+
tickAgentStates
|
|
113
|
+
} from "./chunk-D2UCV5AK.js";
|
|
114
|
+
import {
|
|
115
|
+
evaluateGuard,
|
|
116
|
+
eventToAllowlistKey
|
|
117
|
+
} from "./chunk-W7LLXRGY.js";
|
|
118
|
+
import {
|
|
119
|
+
advancePlan,
|
|
120
|
+
buildPlanCheck,
|
|
121
|
+
evaluatePlan,
|
|
122
|
+
getPlanProgress
|
|
123
|
+
} from "./chunk-QLPTHTVB.js";
|
|
124
|
+
import {
|
|
125
|
+
loadWorld,
|
|
126
|
+
loadWorldFromDirectory
|
|
127
|
+
} from "./chunk-CTZHONLA.js";
|
|
128
|
+
import "./chunk-QWGCMQQD.js";
|
|
129
|
+
|
|
130
|
+
// src/engine/verdict-formatter.ts
|
|
131
|
+
var ANSI = {
|
|
132
|
+
red: "\x1B[31m",
|
|
133
|
+
green: "\x1B[32m",
|
|
134
|
+
yellow: "\x1B[33m",
|
|
135
|
+
blue: "\x1B[34m",
|
|
136
|
+
magenta: "\x1B[35m",
|
|
137
|
+
cyan: "\x1B[36m",
|
|
138
|
+
gray: "\x1B[90m",
|
|
139
|
+
bold: "\x1B[1m",
|
|
140
|
+
dim: "\x1B[2m",
|
|
141
|
+
reset: "\x1B[0m"
|
|
142
|
+
};
|
|
143
|
+
function c(text, ...codes) {
|
|
144
|
+
return codes.join("") + text + ANSI.reset;
|
|
145
|
+
}
|
|
146
|
+
function formatVerdict(verdict, options = {}) {
|
|
147
|
+
const {
|
|
148
|
+
showRuleId = true,
|
|
149
|
+
showEvidence = false,
|
|
150
|
+
showWarning = true,
|
|
151
|
+
color = false,
|
|
152
|
+
compact = false
|
|
153
|
+
} = options;
|
|
154
|
+
if (compact) {
|
|
155
|
+
return formatCompact(verdict, { showRuleId, showWarning, color });
|
|
156
|
+
}
|
|
157
|
+
return formatFull(verdict, { showRuleId, showEvidence, showWarning, color });
|
|
158
|
+
}
|
|
159
|
+
function formatCompact(verdict, opts) {
|
|
160
|
+
const status = formatStatus(verdict.status, opts.color);
|
|
161
|
+
const parts = [status];
|
|
162
|
+
if (opts.showRuleId && verdict.ruleId) {
|
|
163
|
+
parts.push(verdict.ruleId);
|
|
164
|
+
}
|
|
165
|
+
if (verdict.reason) {
|
|
166
|
+
parts.push(verdict.reason);
|
|
167
|
+
}
|
|
168
|
+
if (opts.showWarning && verdict.warning) {
|
|
169
|
+
parts.push(`warning: ${verdict.warning}`);
|
|
170
|
+
}
|
|
171
|
+
return parts.join(" \u2014 ");
|
|
172
|
+
}
|
|
173
|
+
function formatFull(verdict, opts) {
|
|
174
|
+
const lines = [];
|
|
175
|
+
lines.push(formatStatus(verdict.status, opts.color));
|
|
176
|
+
if (opts.showRuleId && verdict.ruleId) {
|
|
177
|
+
lines.push(` Rule: ${verdict.ruleId}`);
|
|
178
|
+
}
|
|
179
|
+
if (verdict.reason) {
|
|
180
|
+
lines.push(` Reason: ${verdict.reason}`);
|
|
181
|
+
}
|
|
182
|
+
if (verdict.consequence) {
|
|
183
|
+
const label = opts.color ? c("Consequence:", ANSI.red) : "Consequence:";
|
|
184
|
+
lines.push(` ${label} ${verdict.consequence.description}`);
|
|
185
|
+
if (verdict.consequence.rounds) {
|
|
186
|
+
lines.push(` Freeze: ${verdict.consequence.rounds} round(s)`);
|
|
187
|
+
}
|
|
188
|
+
if (verdict.consequence.magnitude) {
|
|
189
|
+
lines.push(` Magnitude: ${(verdict.consequence.magnitude * 100).toFixed(0)}%`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (verdict.reward) {
|
|
193
|
+
const label = opts.color ? c("Reward:", ANSI.blue) : "Reward:";
|
|
194
|
+
lines.push(` ${label} ${verdict.reward.description}`);
|
|
195
|
+
if (verdict.reward.rounds) {
|
|
196
|
+
lines.push(` Duration: ${verdict.reward.rounds} round(s)`);
|
|
197
|
+
}
|
|
198
|
+
if (verdict.reward.magnitude) {
|
|
199
|
+
lines.push(` Boost: ${(verdict.reward.magnitude * 100).toFixed(0)}%`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (verdict.intentRecord) {
|
|
203
|
+
const ir = verdict.intentRecord;
|
|
204
|
+
const label = opts.color ? c("Intent Flow:", ANSI.cyan) : "Intent Flow:";
|
|
205
|
+
lines.push(` ${label} ${ir.originalIntent} \u2192 ${ir.finalAction}`);
|
|
206
|
+
}
|
|
207
|
+
if (opts.showWarning && verdict.warning) {
|
|
208
|
+
const label = opts.color ? c("Warning:", ANSI.yellow) : "Warning:";
|
|
209
|
+
lines.push(` ${label} ${verdict.warning}`);
|
|
210
|
+
}
|
|
211
|
+
if (opts.showEvidence) {
|
|
212
|
+
const ev = verdict.evidence;
|
|
213
|
+
lines.push(` World: ${ev.worldName} v${ev.worldVersion}`);
|
|
214
|
+
lines.push(` Invariants: ${ev.invariantsSatisfied}/${ev.invariantsTotal} covered`);
|
|
215
|
+
if (ev.guardsMatched.length > 0) {
|
|
216
|
+
lines.push(` Guards matched: ${ev.guardsMatched.join(", ")}`);
|
|
217
|
+
}
|
|
218
|
+
if (ev.rulesMatched.length > 0) {
|
|
219
|
+
lines.push(` Rules matched: ${ev.rulesMatched.join(", ")}`);
|
|
220
|
+
}
|
|
221
|
+
lines.push(` Enforcement: ${ev.enforcementLevel}`);
|
|
222
|
+
}
|
|
223
|
+
return lines.join("\n");
|
|
224
|
+
}
|
|
225
|
+
function formatStatus(status, color) {
|
|
226
|
+
switch (status) {
|
|
227
|
+
case "ALLOW":
|
|
228
|
+
return color ? c("ALLOWED", ANSI.green, ANSI.bold) : "ALLOWED";
|
|
229
|
+
case "BLOCK":
|
|
230
|
+
return color ? c("BLOCKED", ANSI.red, ANSI.bold) : "BLOCKED";
|
|
231
|
+
case "PAUSE":
|
|
232
|
+
return color ? c("PAUSED", ANSI.yellow, ANSI.bold) : "PAUSED";
|
|
233
|
+
case "MODIFY":
|
|
234
|
+
return color ? c("MODIFIED", ANSI.yellow, ANSI.bold) : "MODIFIED";
|
|
235
|
+
case "PENALIZE":
|
|
236
|
+
return color ? c("PENALIZED", ANSI.red, ANSI.bold) : "PENALIZED";
|
|
237
|
+
case "REWARD":
|
|
238
|
+
return color ? c("REWARDED", ANSI.blue, ANSI.bold) : "REWARDED";
|
|
239
|
+
case "NEUTRAL":
|
|
240
|
+
return color ? c("NEUTRAL", ANSI.gray, ANSI.bold) : "NEUTRAL";
|
|
241
|
+
default:
|
|
242
|
+
return status;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function formatVerdictOneLine(verdict) {
|
|
246
|
+
const parts = [verdict.status];
|
|
247
|
+
if (verdict.ruleId) {
|
|
248
|
+
parts[0] += `: ${verdict.ruleId}`;
|
|
249
|
+
}
|
|
250
|
+
if (verdict.reason) {
|
|
251
|
+
parts.push(verdict.reason);
|
|
252
|
+
}
|
|
253
|
+
return parts.join(" \u2014 ");
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// src/engine/condition-engine.ts
|
|
257
|
+
function getFieldValue(event, field) {
|
|
258
|
+
if (field.startsWith("args.")) {
|
|
259
|
+
const key = field.slice(5);
|
|
260
|
+
return event.args?.[key];
|
|
261
|
+
}
|
|
262
|
+
return event[field];
|
|
263
|
+
}
|
|
264
|
+
function toString(value) {
|
|
265
|
+
if (value === null || value === void 0) return "";
|
|
266
|
+
if (typeof value === "string") return value;
|
|
267
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
268
|
+
return JSON.stringify(value);
|
|
269
|
+
}
|
|
270
|
+
function evaluateCondition(condition, event) {
|
|
271
|
+
const fieldValue = getFieldValue(event, condition.field);
|
|
272
|
+
if (fieldValue === void 0 && condition.operator !== "!=") {
|
|
273
|
+
return { matched: false, evidence: null };
|
|
274
|
+
}
|
|
275
|
+
switch (condition.operator) {
|
|
276
|
+
case "==":
|
|
277
|
+
return evaluateEquals(fieldValue, condition.value);
|
|
278
|
+
case "!=":
|
|
279
|
+
return evaluateNotEquals(fieldValue, condition.value);
|
|
280
|
+
case ">":
|
|
281
|
+
return evaluateComparison(fieldValue, condition.value, (a, b) => a > b);
|
|
282
|
+
case "<":
|
|
283
|
+
return evaluateComparison(fieldValue, condition.value, (a, b) => a < b);
|
|
284
|
+
case ">=":
|
|
285
|
+
return evaluateComparison(fieldValue, condition.value, (a, b) => a >= b);
|
|
286
|
+
case "<=":
|
|
287
|
+
return evaluateComparison(fieldValue, condition.value, (a, b) => a <= b);
|
|
288
|
+
case "in":
|
|
289
|
+
return evaluateIn(fieldValue, condition.value);
|
|
290
|
+
case "contains":
|
|
291
|
+
return evaluateContains(fieldValue, condition.value);
|
|
292
|
+
case "contains_any":
|
|
293
|
+
return evaluateContainsAny(fieldValue, condition.value);
|
|
294
|
+
case "matches_pattern":
|
|
295
|
+
return evaluateMatchesPattern(fieldValue, condition.value);
|
|
296
|
+
case "starts_with":
|
|
297
|
+
return evaluateStartsWith(fieldValue, condition.value);
|
|
298
|
+
case "ends_with":
|
|
299
|
+
return evaluateEndsWith(fieldValue, condition.value);
|
|
300
|
+
default:
|
|
301
|
+
return { matched: false, evidence: null };
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function evaluateEquals(fieldValue, conditionValue) {
|
|
305
|
+
const fieldStr = toString(fieldValue);
|
|
306
|
+
const condStr = toString(conditionValue);
|
|
307
|
+
const matched = fieldStr === condStr;
|
|
308
|
+
return {
|
|
309
|
+
matched,
|
|
310
|
+
evidence: matched ? `${fieldStr} == ${condStr}` : null
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
function evaluateNotEquals(fieldValue, conditionValue) {
|
|
314
|
+
const fieldStr = toString(fieldValue);
|
|
315
|
+
const condStr = toString(conditionValue);
|
|
316
|
+
const matched = fieldStr !== condStr;
|
|
317
|
+
return {
|
|
318
|
+
matched,
|
|
319
|
+
evidence: matched ? `${fieldStr} != ${condStr}` : null
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
function evaluateComparison(fieldValue, conditionValue, comparator) {
|
|
323
|
+
const a = Number(fieldValue);
|
|
324
|
+
const b = Number(conditionValue);
|
|
325
|
+
if (isNaN(a) || isNaN(b)) return { matched: false, evidence: null };
|
|
326
|
+
const matched = comparator(a, b);
|
|
327
|
+
return {
|
|
328
|
+
matched,
|
|
329
|
+
evidence: matched ? `${a} compared to ${b}` : null
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
function evaluateIn(fieldValue, conditionValue) {
|
|
333
|
+
if (!Array.isArray(conditionValue)) return { matched: false, evidence: null };
|
|
334
|
+
const fieldStr = toString(fieldValue);
|
|
335
|
+
const matched = conditionValue.some((v) => toString(v) === fieldStr);
|
|
336
|
+
return {
|
|
337
|
+
matched,
|
|
338
|
+
evidence: matched ? `"${fieldStr}" found in [${conditionValue.join(", ")}]` : null
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
function evaluateContains(fieldValue, conditionValue) {
|
|
342
|
+
const fieldStr = toString(fieldValue).toLowerCase();
|
|
343
|
+
const searchStr = toString(conditionValue).toLowerCase();
|
|
344
|
+
const matched = fieldStr.includes(searchStr);
|
|
345
|
+
return {
|
|
346
|
+
matched,
|
|
347
|
+
evidence: matched ? `"${searchStr}" found in field` : null
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
function evaluateContainsAny(fieldValue, conditionValue) {
|
|
351
|
+
if (!Array.isArray(conditionValue)) return { matched: false, evidence: null };
|
|
352
|
+
const fieldStr = toString(fieldValue).toLowerCase();
|
|
353
|
+
for (const pattern of conditionValue) {
|
|
354
|
+
const patternLower = toString(pattern).toLowerCase();
|
|
355
|
+
if (fieldStr.includes(patternLower)) {
|
|
356
|
+
return {
|
|
357
|
+
matched: true,
|
|
358
|
+
evidence: `"${patternLower}" found in field`
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return { matched: false, evidence: null };
|
|
363
|
+
}
|
|
364
|
+
function evaluateMatchesPattern(fieldValue, conditionValue) {
|
|
365
|
+
const fieldStr = toString(fieldValue);
|
|
366
|
+
const patterns = Array.isArray(conditionValue) ? conditionValue : [toString(conditionValue)];
|
|
367
|
+
for (const pattern of patterns) {
|
|
368
|
+
try {
|
|
369
|
+
const regex = new RegExp(toString(pattern), "i");
|
|
370
|
+
if (regex.test(fieldStr)) {
|
|
371
|
+
return {
|
|
372
|
+
matched: true,
|
|
373
|
+
evidence: `matched pattern /${pattern}/`
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
} catch {
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return { matched: false, evidence: null };
|
|
381
|
+
}
|
|
382
|
+
function evaluateStartsWith(fieldValue, conditionValue) {
|
|
383
|
+
const fieldStr = toString(fieldValue).toLowerCase();
|
|
384
|
+
const prefix = toString(conditionValue).toLowerCase();
|
|
385
|
+
const matched = fieldStr.startsWith(prefix);
|
|
386
|
+
return {
|
|
387
|
+
matched,
|
|
388
|
+
evidence: matched ? `field starts with "${prefix}"` : null
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
function evaluateEndsWith(fieldValue, conditionValue) {
|
|
392
|
+
const fieldStr = toString(fieldValue).toLowerCase();
|
|
393
|
+
const suffix = toString(conditionValue).toLowerCase();
|
|
394
|
+
const matched = fieldStr.endsWith(suffix);
|
|
395
|
+
return {
|
|
396
|
+
matched,
|
|
397
|
+
evidence: matched ? `field ends with "${suffix}"` : null
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
export {
|
|
401
|
+
BOOTSTRAP_EXIT_CODES,
|
|
402
|
+
CONFIGURE_AI_EXIT_CODES,
|
|
403
|
+
CompositeAuditLogger,
|
|
404
|
+
ConsoleAuditLogger,
|
|
405
|
+
DERIVE_EXIT_CODES,
|
|
406
|
+
FileAuditLogger,
|
|
407
|
+
GUARD_EXIT_CODES,
|
|
408
|
+
McpGovernanceServer,
|
|
409
|
+
ModelAdapter,
|
|
410
|
+
PLAN_EXIT_CODES,
|
|
411
|
+
PROVIDERS,
|
|
412
|
+
SessionManager,
|
|
413
|
+
VALIDATE_EXIT_CODES,
|
|
414
|
+
actionToGuardEvent,
|
|
415
|
+
adaptationFromVerdict,
|
|
416
|
+
addGuard,
|
|
417
|
+
addInvariant,
|
|
418
|
+
addRule,
|
|
419
|
+
advancePlan,
|
|
420
|
+
applyConsequence,
|
|
421
|
+
applyReward,
|
|
422
|
+
buildPlanCheck,
|
|
423
|
+
classifyAdaptation,
|
|
424
|
+
classifyIntent,
|
|
425
|
+
classifyIntentWithAI,
|
|
426
|
+
createAgentState,
|
|
427
|
+
createGovernanceEngine,
|
|
428
|
+
createGovernor,
|
|
429
|
+
deriveWorld,
|
|
430
|
+
describeActiveWorld,
|
|
431
|
+
detectBehavioralPatterns,
|
|
432
|
+
emitWorldDefinition,
|
|
433
|
+
evaluateCondition,
|
|
434
|
+
evaluateGuard,
|
|
435
|
+
evaluateGuardWithAI,
|
|
436
|
+
evaluatePlan,
|
|
437
|
+
eventToAllowlistKey,
|
|
438
|
+
explainWorld,
|
|
439
|
+
extractContentFields,
|
|
440
|
+
extractWorldMarkdown,
|
|
441
|
+
formatVerdict,
|
|
442
|
+
formatVerdictOneLine,
|
|
443
|
+
generateAdaptationNarrative,
|
|
444
|
+
generateDecisionFlow,
|
|
445
|
+
generateImpactReport,
|
|
446
|
+
generateImpactReportFromFile,
|
|
447
|
+
getActiveWorldName,
|
|
448
|
+
getPlanProgress,
|
|
449
|
+
govern,
|
|
450
|
+
handleCreateCapsule,
|
|
451
|
+
handleHealthCheck,
|
|
452
|
+
handleListPresets,
|
|
453
|
+
handleReasonRequest,
|
|
454
|
+
improveWorld,
|
|
455
|
+
listWorlds,
|
|
456
|
+
loadWorld,
|
|
457
|
+
loadWorldFromDirectory,
|
|
458
|
+
normalizeWorldMarkdown,
|
|
459
|
+
parseGuardDescription,
|
|
460
|
+
parsePlanMarkdown,
|
|
461
|
+
parseWorldMarkdown,
|
|
462
|
+
readAuditLog,
|
|
463
|
+
renderDecisionFlow,
|
|
464
|
+
renderExplainText,
|
|
465
|
+
renderImpactReport,
|
|
466
|
+
renderImproveText,
|
|
467
|
+
renderSimulateText,
|
|
468
|
+
resolveProvider,
|
|
469
|
+
resolveWorldPath,
|
|
470
|
+
runInteractiveMode,
|
|
471
|
+
runPipeMode,
|
|
472
|
+
setActiveWorld,
|
|
473
|
+
simulateWorld,
|
|
474
|
+
summarizeAuditEvents,
|
|
475
|
+
tickAgentStates,
|
|
476
|
+
validateWorld,
|
|
477
|
+
verdictToAuditEvent,
|
|
478
|
+
writeTempWorld
|
|
479
|
+
};
|