@neuroverseos/governance 0.1.6 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +279 -423
- package/dist/adapters/express.cjs +242 -2
- package/dist/adapters/express.d.cts +1 -1
- package/dist/adapters/express.d.ts +1 -1
- package/dist/adapters/express.js +5 -3
- package/dist/adapters/index.cjs +301 -5
- package/dist/adapters/index.d.cts +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.js +8 -6
- package/dist/adapters/langchain.cjs +267 -3
- package/dist/adapters/langchain.d.cts +8 -1
- package/dist/adapters/langchain.d.ts +8 -1
- package/dist/adapters/langchain.js +5 -3
- package/dist/adapters/openai.cjs +267 -3
- package/dist/adapters/openai.d.cts +8 -1
- package/dist/adapters/openai.d.ts +8 -1
- package/dist/adapters/openai.js +5 -3
- package/dist/adapters/openclaw.cjs +267 -3
- package/dist/adapters/openclaw.d.cts +8 -1
- package/dist/adapters/openclaw.d.ts +8 -1
- package/dist/adapters/openclaw.js +5 -3
- package/dist/{bootstrap-H4HHKQ5G.js → bootstrap-GXVDZNF7.js} +2 -1
- package/dist/{build-73KAVHEY.js → build-P42YFKQV.js} +34 -3
- package/dist/{chunk-FYPYZFV5.js → chunk-2JQJ5U5X.js} +1 -1
- package/dist/chunk-37JG24WH.js +161 -0
- package/dist/chunk-5EDDNJU6.js +321 -0
- package/dist/{chunk-O5OMJMIE.js → chunk-7P3S7MAY.js} +502 -2
- package/dist/chunk-A5W4GNQO.js +130 -0
- package/dist/{chunk-ITJ3LCPG.js → chunk-ADV7Q2LJ.js} +1 -1
- package/dist/chunk-AKW5YVCE.js +96 -0
- package/dist/{chunk-EIUHJXBB.js → chunk-GR6DGCZ2.js} +1 -1
- package/dist/{chunk-EQXFOKH2.js → chunk-IVPKFJX3.js} +24 -3
- package/dist/{chunk-D7BGWV2J.js → chunk-NF5POFCI.js} +5 -3
- package/dist/chunk-OT6PXH54.js +61 -0
- package/dist/chunk-P74Y66ZV.js +205 -0
- package/dist/chunk-PAX2P6ZP.js +601 -0
- package/dist/{chunk-B4NF3OLW.js → chunk-PQBJBVSW.js} +56 -2
- package/dist/{chunk-T4X42QXC.js → chunk-Q6O7ZLO2.js} +0 -59
- package/dist/{chunk-FZQCRGUU.js → chunk-TINSRYXQ.js} +24 -3
- package/dist/{chunk-CROPZ75A.js → chunk-UPJNTSVM.js} +24 -3
- package/dist/chunk-YZFATT7X.js +9 -0
- package/dist/{chunk-Z2S2HIV5.js → chunk-ZL4AHY4X.js} +2 -2
- package/dist/cli/neuroverse.cjs +5287 -740
- package/dist/cli/neuroverse.js +69 -13
- package/dist/cli/plan.cjs +1554 -0
- package/dist/cli/plan.d.cts +20 -0
- package/dist/cli/plan.d.ts +20 -0
- package/dist/cli/plan.js +346 -0
- package/dist/cli/run.cjs +1716 -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-46JVG56I.js → configure-ai-TK67ZWZL.js} +5 -2
- package/dist/{derive-6NAEWLM5.js → derive-TLIV4OOU.js} +6 -4
- package/dist/doctor-V72UM2TC.js +170 -0
- package/dist/{explain-3B3VB6TL.js → explain-IDCRWMPX.js} +2 -1
- package/dist/{guard-67Y66P3I.js → guard-WA3FCCIO.js} +20 -6
- package/dist/{guard-contract-D_RQz9kt.d.ts → guard-contract-D-2LQInm.d.cts} +144 -2
- package/dist/{guard-contract-D_RQz9kt.d.cts → guard-contract-D-2LQInm.d.ts} +144 -2
- package/dist/guard-engine-D7X4CVAE.js +10 -0
- package/dist/{impact-CHERK3O6.js → impact-BWULZ5RP.js} +5 -3
- package/dist/{improve-YG6I6ERG.js → improve-GPUBKTEA.js} +4 -3
- package/dist/index.cjs +2095 -89
- package/dist/index.d.cts +466 -12
- package/dist/index.d.ts +466 -12
- package/dist/index.js +70 -20
- package/dist/{init-Z66T6TDI.js → init-PKPIYHYE.js} +2 -0
- package/dist/mcp-server-YUOQP4M5.js +13 -0
- package/dist/model-adapter-BB7G4MFI.js +11 -0
- package/dist/playground-CBXMAW2B.js +550 -0
- package/dist/redteam-SSNABQ7W.js +357 -0
- package/dist/session-MWRBTCYX.js +14 -0
- package/dist/{simulate-ETHHINZ4.js → simulate-VDOYQFRO.js} +2 -1
- package/dist/test-3GZSG5FR.js +217 -0
- package/dist/{trace-3YODSSIP.js → trace-TM4Z7G73.js} +4 -2
- package/dist/{validate-UVE6GKQU.js → validate-LLBWVPGV.js} +15 -6
- package/dist/validate-engine-UIABSIHD.js +7 -0
- package/dist/{world-WLNHL5XC.js → world-LAXO6DOX.js} +87 -7
- package/dist/world-loader-HMPTOEA2.js +9 -0
- package/package.json +19 -5
- package/dist/validate-engine-657D75OG.js +0 -6
- /package/dist/{chunk-M3TZFGHO.js → chunk-JZPQGIKR.js} +0 -0
package/dist/adapters/openai.cjs
CHANGED
|
@@ -37,6 +37,205 @@ __export(openai_exports, {
|
|
|
37
37
|
});
|
|
38
38
|
module.exports = __toCommonJS(openai_exports);
|
|
39
39
|
|
|
40
|
+
// src/engine/plan-engine.ts
|
|
41
|
+
function keywordMatch(eventText, step) {
|
|
42
|
+
const stepText = [
|
|
43
|
+
step.label,
|
|
44
|
+
step.description ?? "",
|
|
45
|
+
...step.tags ?? []
|
|
46
|
+
].join(" ").toLowerCase();
|
|
47
|
+
const keywords = stepText.split(/\s+/).filter((w) => w.length > 3);
|
|
48
|
+
if (keywords.length === 0) return false;
|
|
49
|
+
const matched = keywords.filter((kw) => eventText.includes(kw));
|
|
50
|
+
return matched.length >= Math.ceil(keywords.length * 0.5);
|
|
51
|
+
}
|
|
52
|
+
function tokenSimilarity(a, b) {
|
|
53
|
+
const tokensA = new Set(a.toLowerCase().split(/\s+/).filter((w) => w.length > 2));
|
|
54
|
+
const tokensB = new Set(b.toLowerCase().split(/\s+/).filter((w) => w.length > 2));
|
|
55
|
+
if (tokensA.size === 0 || tokensB.size === 0) return 0;
|
|
56
|
+
let intersection = 0;
|
|
57
|
+
for (const t of tokensA) {
|
|
58
|
+
if (tokensB.has(t)) intersection++;
|
|
59
|
+
}
|
|
60
|
+
const union = (/* @__PURE__ */ new Set([...tokensA, ...tokensB])).size;
|
|
61
|
+
return union > 0 ? intersection / union : 0;
|
|
62
|
+
}
|
|
63
|
+
function findMatchingStep(eventText, event, steps) {
|
|
64
|
+
const pendingOrActive = steps.filter((s) => s.status === "pending" || s.status === "active");
|
|
65
|
+
if (pendingOrActive.length === 0) {
|
|
66
|
+
return { matched: null, closest: null, closestScore: 0 };
|
|
67
|
+
}
|
|
68
|
+
for (const step of pendingOrActive) {
|
|
69
|
+
if (keywordMatch(eventText, step)) {
|
|
70
|
+
if (step.tools && event.tool && !step.tools.includes(event.tool)) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
return { matched: step, closest: step, closestScore: 1 };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const intentText = [event.intent, event.tool ?? "", event.scope ?? ""].join(" ");
|
|
77
|
+
let bestStep = null;
|
|
78
|
+
let bestScore = 0;
|
|
79
|
+
for (const step of pendingOrActive) {
|
|
80
|
+
const stepText = [step.label, step.description ?? "", ...step.tags ?? []].join(" ");
|
|
81
|
+
const score = tokenSimilarity(intentText, stepText);
|
|
82
|
+
if (score > bestScore) {
|
|
83
|
+
bestScore = score;
|
|
84
|
+
bestStep = step;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const SIMILARITY_THRESHOLD = 0.35;
|
|
88
|
+
if (bestScore >= SIMILARITY_THRESHOLD && bestStep) {
|
|
89
|
+
if (bestStep.tools && event.tool && !bestStep.tools.includes(event.tool)) {
|
|
90
|
+
return { matched: null, closest: bestStep, closestScore: bestScore };
|
|
91
|
+
}
|
|
92
|
+
return { matched: bestStep, closest: bestStep, closestScore: bestScore };
|
|
93
|
+
}
|
|
94
|
+
return { matched: null, closest: bestStep, closestScore: bestScore };
|
|
95
|
+
}
|
|
96
|
+
function isSequenceValid(step, plan) {
|
|
97
|
+
if (!plan.sequential) return true;
|
|
98
|
+
if (!step.requires || step.requires.length === 0) return true;
|
|
99
|
+
return step.requires.every((reqId) => {
|
|
100
|
+
const reqStep = plan.steps.find((s) => s.id === reqId);
|
|
101
|
+
return reqStep?.status === "completed";
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function checkConstraints(event, eventText, constraints) {
|
|
105
|
+
const checks = [];
|
|
106
|
+
for (const constraint of constraints) {
|
|
107
|
+
if (constraint.type === "approval") {
|
|
108
|
+
if (constraint.trigger && eventText.includes(constraint.trigger.substring(0, 10).toLowerCase())) {
|
|
109
|
+
checks.push({ constraintId: constraint.id, passed: false, reason: constraint.description });
|
|
110
|
+
return { violated: constraint, checks };
|
|
111
|
+
}
|
|
112
|
+
const keywords = constraint.description.toLowerCase().split(/\s+/).filter((w) => w.length > 3);
|
|
113
|
+
const relevant = keywords.some((kw) => eventText.includes(kw));
|
|
114
|
+
if (relevant) {
|
|
115
|
+
checks.push({ constraintId: constraint.id, passed: false, reason: constraint.description });
|
|
116
|
+
return { violated: constraint, checks };
|
|
117
|
+
}
|
|
118
|
+
checks.push({ constraintId: constraint.id, passed: true });
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (constraint.type === "scope" && constraint.trigger) {
|
|
122
|
+
const keywords = constraint.trigger.split(/\s+/).filter((w) => w.length > 3);
|
|
123
|
+
const violated = keywords.length > 0 && keywords.every((kw) => eventText.includes(kw));
|
|
124
|
+
checks.push({
|
|
125
|
+
constraintId: constraint.id,
|
|
126
|
+
passed: !violated,
|
|
127
|
+
reason: violated ? constraint.description : void 0
|
|
128
|
+
});
|
|
129
|
+
if (violated) {
|
|
130
|
+
return { violated: constraint, checks };
|
|
131
|
+
}
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
checks.push({ constraintId: constraint.id, passed: true });
|
|
135
|
+
}
|
|
136
|
+
return { violated: null, checks };
|
|
137
|
+
}
|
|
138
|
+
function getPlanProgress(plan) {
|
|
139
|
+
const completed = plan.steps.filter((s) => s.status === "completed").length;
|
|
140
|
+
const total = plan.steps.length;
|
|
141
|
+
return {
|
|
142
|
+
completed,
|
|
143
|
+
total,
|
|
144
|
+
percentage: total > 0 ? Math.round(completed / total * 100) : 0
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function advancePlan(plan, stepId) {
|
|
148
|
+
return {
|
|
149
|
+
...plan,
|
|
150
|
+
steps: plan.steps.map(
|
|
151
|
+
(s) => s.id === stepId ? { ...s, status: "completed" } : s
|
|
152
|
+
)
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function evaluatePlan(event, plan) {
|
|
156
|
+
const progress = getPlanProgress(plan);
|
|
157
|
+
if (plan.expires_at) {
|
|
158
|
+
const expiresAt = new Date(plan.expires_at).getTime();
|
|
159
|
+
if (Date.now() > expiresAt) {
|
|
160
|
+
return {
|
|
161
|
+
allowed: true,
|
|
162
|
+
status: "PLAN_COMPLETE",
|
|
163
|
+
reason: "Plan has expired.",
|
|
164
|
+
progress
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (progress.completed === progress.total) {
|
|
169
|
+
return {
|
|
170
|
+
allowed: true,
|
|
171
|
+
status: "PLAN_COMPLETE",
|
|
172
|
+
reason: "All plan steps are completed.",
|
|
173
|
+
progress
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
const eventText = [
|
|
177
|
+
event.intent,
|
|
178
|
+
event.tool ?? "",
|
|
179
|
+
event.scope ?? ""
|
|
180
|
+
].join(" ").toLowerCase();
|
|
181
|
+
const { matched, closest, closestScore } = findMatchingStep(eventText, event, plan.steps);
|
|
182
|
+
if (!matched) {
|
|
183
|
+
return {
|
|
184
|
+
allowed: false,
|
|
185
|
+
status: "OFF_PLAN",
|
|
186
|
+
reason: "Action does not match any plan step.",
|
|
187
|
+
closestStep: closest?.label,
|
|
188
|
+
similarityScore: closestScore,
|
|
189
|
+
progress
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
if (!isSequenceValid(matched, plan)) {
|
|
193
|
+
const pendingDeps = (matched.requires ?? []).filter((reqId) => plan.steps.find((s) => s.id === reqId)?.status !== "completed").join(", ");
|
|
194
|
+
return {
|
|
195
|
+
allowed: false,
|
|
196
|
+
status: "OFF_PLAN",
|
|
197
|
+
reason: `Step "${matched.label}" requires completion of: ${pendingDeps}`,
|
|
198
|
+
matchedStep: matched.id,
|
|
199
|
+
progress
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
const { violated } = checkConstraints(event, eventText, plan.constraints);
|
|
203
|
+
if (violated) {
|
|
204
|
+
return {
|
|
205
|
+
allowed: false,
|
|
206
|
+
status: "CONSTRAINT_VIOLATED",
|
|
207
|
+
reason: violated.description,
|
|
208
|
+
matchedStep: matched.id,
|
|
209
|
+
progress
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
allowed: true,
|
|
214
|
+
status: "ON_PLAN",
|
|
215
|
+
reason: `Matches step: ${matched.label}`,
|
|
216
|
+
matchedStep: matched.id,
|
|
217
|
+
progress
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function buildPlanCheck(event, plan, verdict) {
|
|
221
|
+
const eventText = [event.intent, event.tool ?? "", event.scope ?? ""].join(" ").toLowerCase();
|
|
222
|
+
const { matched, closest, closestScore } = findMatchingStep(eventText, event, plan.steps);
|
|
223
|
+
const { checks: constraintChecks } = checkConstraints(event, eventText, plan.constraints);
|
|
224
|
+
const progress = getPlanProgress(plan);
|
|
225
|
+
return {
|
|
226
|
+
planId: plan.plan_id,
|
|
227
|
+
matched: !!matched,
|
|
228
|
+
matchedStepId: matched?.id,
|
|
229
|
+
matchedStepLabel: matched?.label,
|
|
230
|
+
closestStepId: !matched ? closest?.id : void 0,
|
|
231
|
+
closestStepLabel: !matched ? closest?.label : void 0,
|
|
232
|
+
similarityScore: !matched ? closestScore : void 0,
|
|
233
|
+
sequenceValid: matched ? isSequenceValid(matched, plan) : void 0,
|
|
234
|
+
constraintsChecked: constraintChecks,
|
|
235
|
+
progress: { completed: progress.completed, total: progress.total }
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
40
239
|
// src/engine/guard-engine.ts
|
|
41
240
|
var PROMPT_INJECTION_PATTERNS = [
|
|
42
241
|
// Instruction override
|
|
@@ -128,6 +327,7 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
128
327
|
const eventText = (event.intent + " " + (event.tool ?? "") + " " + (event.scope ?? "")).toLowerCase();
|
|
129
328
|
const invariantChecks = [];
|
|
130
329
|
const safetyChecks = [];
|
|
330
|
+
let planCheckResult;
|
|
131
331
|
const roleChecks = [];
|
|
132
332
|
const guardChecks = [];
|
|
133
333
|
const kernelRuleChecks = [];
|
|
@@ -155,6 +355,7 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
155
355
|
includeTrace ? buildTrace(
|
|
156
356
|
invariantChecks,
|
|
157
357
|
safetyChecks,
|
|
358
|
+
planCheckResult,
|
|
158
359
|
roleChecks,
|
|
159
360
|
guardChecks,
|
|
160
361
|
kernelRuleChecks,
|
|
@@ -183,6 +384,7 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
183
384
|
includeTrace ? buildTrace(
|
|
184
385
|
invariantChecks,
|
|
185
386
|
safetyChecks,
|
|
387
|
+
planCheckResult,
|
|
186
388
|
roleChecks,
|
|
187
389
|
guardChecks,
|
|
188
390
|
kernelRuleChecks,
|
|
@@ -193,6 +395,42 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
193
395
|
) : void 0
|
|
194
396
|
);
|
|
195
397
|
}
|
|
398
|
+
if (options.plan) {
|
|
399
|
+
const planVerdict = evaluatePlan(event, options.plan);
|
|
400
|
+
planCheckResult = buildPlanCheck(event, options.plan, planVerdict);
|
|
401
|
+
if (!planVerdict.allowed && planVerdict.status !== "PLAN_COMPLETE") {
|
|
402
|
+
decidingLayer = "plan-enforcement";
|
|
403
|
+
decidingId = `plan-${options.plan.plan_id}`;
|
|
404
|
+
const planStatus = planVerdict.status === "CONSTRAINT_VIOLATED" ? "PAUSE" : "BLOCK";
|
|
405
|
+
let reason = planVerdict.reason ?? "Action blocked by plan.";
|
|
406
|
+
if (planVerdict.status === "OFF_PLAN" && planVerdict.closestStep) {
|
|
407
|
+
reason += ` Closest step: "${planVerdict.closestStep}" (similarity: ${(planVerdict.similarityScore ?? 0).toFixed(2)})`;
|
|
408
|
+
}
|
|
409
|
+
return buildVerdict(
|
|
410
|
+
planStatus,
|
|
411
|
+
reason,
|
|
412
|
+
`plan-${options.plan.plan_id}`,
|
|
413
|
+
void 0,
|
|
414
|
+
world,
|
|
415
|
+
level,
|
|
416
|
+
invariantChecks,
|
|
417
|
+
guardsMatched,
|
|
418
|
+
rulesMatched,
|
|
419
|
+
includeTrace ? buildTrace(
|
|
420
|
+
invariantChecks,
|
|
421
|
+
safetyChecks,
|
|
422
|
+
planCheckResult,
|
|
423
|
+
roleChecks,
|
|
424
|
+
guardChecks,
|
|
425
|
+
kernelRuleChecks,
|
|
426
|
+
levelChecks,
|
|
427
|
+
decidingLayer,
|
|
428
|
+
decidingId,
|
|
429
|
+
startTime
|
|
430
|
+
) : void 0
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
196
434
|
const roleVerdict = checkRoleRules(event, eventText, world, roleChecks);
|
|
197
435
|
if (roleVerdict) {
|
|
198
436
|
decidingLayer = "role";
|
|
@@ -210,6 +448,7 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
210
448
|
includeTrace ? buildTrace(
|
|
211
449
|
invariantChecks,
|
|
212
450
|
safetyChecks,
|
|
451
|
+
planCheckResult,
|
|
213
452
|
roleChecks,
|
|
214
453
|
guardChecks,
|
|
215
454
|
kernelRuleChecks,
|
|
@@ -238,6 +477,7 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
238
477
|
includeTrace ? buildTrace(
|
|
239
478
|
invariantChecks,
|
|
240
479
|
safetyChecks,
|
|
480
|
+
planCheckResult,
|
|
241
481
|
roleChecks,
|
|
242
482
|
guardChecks,
|
|
243
483
|
kernelRuleChecks,
|
|
@@ -266,6 +506,7 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
266
506
|
includeTrace ? buildTrace(
|
|
267
507
|
invariantChecks,
|
|
268
508
|
safetyChecks,
|
|
509
|
+
planCheckResult,
|
|
269
510
|
roleChecks,
|
|
270
511
|
guardChecks,
|
|
271
512
|
kernelRuleChecks,
|
|
@@ -293,6 +534,7 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
293
534
|
includeTrace ? buildTrace(
|
|
294
535
|
invariantChecks,
|
|
295
536
|
safetyChecks,
|
|
537
|
+
planCheckResult,
|
|
296
538
|
roleChecks,
|
|
297
539
|
guardChecks,
|
|
298
540
|
kernelRuleChecks,
|
|
@@ -317,6 +559,7 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
317
559
|
includeTrace ? buildTrace(
|
|
318
560
|
invariantChecks,
|
|
319
561
|
safetyChecks,
|
|
562
|
+
planCheckResult,
|
|
320
563
|
roleChecks,
|
|
321
564
|
guardChecks,
|
|
322
565
|
kernelRuleChecks,
|
|
@@ -654,8 +897,8 @@ function matchesKeywords(eventText, ruleText) {
|
|
|
654
897
|
function eventToAllowlistKey(event) {
|
|
655
898
|
return `${(event.tool ?? "*").toLowerCase()}::${event.intent.toLowerCase().trim()}`;
|
|
656
899
|
}
|
|
657
|
-
function buildTrace(invariantChecks, safetyChecks, roleChecks, guardChecks, kernelRuleChecks, levelChecks, decidingLayer, decidingId, startTime) {
|
|
658
|
-
|
|
900
|
+
function buildTrace(invariantChecks, safetyChecks, planCheck, roleChecks, guardChecks, kernelRuleChecks, levelChecks, decidingLayer, decidingId, startTime) {
|
|
901
|
+
const trace = {
|
|
659
902
|
invariantChecks,
|
|
660
903
|
safetyChecks,
|
|
661
904
|
roleChecks,
|
|
@@ -673,6 +916,7 @@ function buildTrace(invariantChecks, safetyChecks, roleChecks, guardChecks, kern
|
|
|
673
916
|
"safety-scope-escape",
|
|
674
917
|
"safety-execution-claim",
|
|
675
918
|
"safety-execution-intent",
|
|
919
|
+
"plan-enforcement",
|
|
676
920
|
"role-rules",
|
|
677
921
|
"declarative-guards",
|
|
678
922
|
"kernel-rules",
|
|
@@ -682,6 +926,10 @@ function buildTrace(invariantChecks, safetyChecks, roleChecks, guardChecks, kern
|
|
|
682
926
|
},
|
|
683
927
|
durationMs: performance.now() - startTime
|
|
684
928
|
};
|
|
929
|
+
if (planCheck) {
|
|
930
|
+
trace.planCheck = planCheck;
|
|
931
|
+
}
|
|
932
|
+
return trace;
|
|
685
933
|
}
|
|
686
934
|
function buildVerdict(status, reason, ruleId, warning, world, level, invariantChecks, guardsMatched, rulesMatched, trace) {
|
|
687
935
|
const evidence = {
|
|
@@ -810,12 +1058,15 @@ var GovernedToolExecutor = class {
|
|
|
810
1058
|
engineOptions;
|
|
811
1059
|
mapFn;
|
|
812
1060
|
blockMsg;
|
|
1061
|
+
activePlan;
|
|
813
1062
|
constructor(world, options = {}) {
|
|
814
1063
|
this.world = world;
|
|
815
1064
|
this.options = options;
|
|
1065
|
+
this.activePlan = options.plan;
|
|
816
1066
|
this.engineOptions = {
|
|
817
1067
|
trace: options.trace ?? false,
|
|
818
|
-
level: options.level
|
|
1068
|
+
level: options.level,
|
|
1069
|
+
plan: this.activePlan
|
|
819
1070
|
};
|
|
820
1071
|
this.mapFn = options.mapFunctionCall ?? defaultMapFunctionCall;
|
|
821
1072
|
this.blockMsg = options.blockMessage ?? defaultBlockMessage;
|
|
@@ -832,8 +1083,21 @@ var GovernedToolExecutor = class {
|
|
|
832
1083
|
args = { raw: toolCall.function.arguments };
|
|
833
1084
|
}
|
|
834
1085
|
const event = this.mapFn(toolCall.function.name, args);
|
|
1086
|
+
this.engineOptions.plan = this.activePlan;
|
|
835
1087
|
const verdict = evaluateGuard(event, this.world, this.engineOptions);
|
|
836
1088
|
this.options.onEvaluate?.(verdict, event);
|
|
1089
|
+
if (verdict.status === "ALLOW" && this.activePlan) {
|
|
1090
|
+
const planVerdict = evaluatePlan(event, this.activePlan);
|
|
1091
|
+
if (planVerdict.matchedStep) {
|
|
1092
|
+
this.activePlan = advancePlan(this.activePlan, planVerdict.matchedStep);
|
|
1093
|
+
this.engineOptions.plan = this.activePlan;
|
|
1094
|
+
const progress = getPlanProgress(this.activePlan);
|
|
1095
|
+
this.options.onPlanProgress?.(progress);
|
|
1096
|
+
if (progress.completed === progress.total) {
|
|
1097
|
+
this.options.onPlanComplete?.();
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
837
1101
|
return verdict;
|
|
838
1102
|
}
|
|
839
1103
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { G as GuardVerdict, a as GuardEvent, W as WorldDefinition } from '../guard-contract-
|
|
1
|
+
import { G as GuardVerdict, a as GuardEvent, P as PlanDefinition, b as PlanProgress, W as WorldDefinition } from '../guard-contract-D-2LQInm.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* NeuroVerse Adapter — OpenAI
|
|
@@ -45,6 +45,12 @@ interface GovernedExecutorOptions {
|
|
|
45
45
|
mapFunctionCall?: (name: string, args: Record<string, unknown>) => GuardEvent;
|
|
46
46
|
/** Message returned to the model when a tool call is blocked. */
|
|
47
47
|
blockMessage?: (verdict: GuardVerdict) => string;
|
|
48
|
+
/** Active plan overlay for task-scoped governance. */
|
|
49
|
+
plan?: PlanDefinition;
|
|
50
|
+
/** Called when plan progress changes. */
|
|
51
|
+
onPlanProgress?: (progress: PlanProgress) => void;
|
|
52
|
+
/** Called when all plan steps are completed. */
|
|
53
|
+
onPlanComplete?: () => void;
|
|
48
54
|
}
|
|
49
55
|
declare class GovernanceBlockedError extends Error {
|
|
50
56
|
readonly verdict: GuardVerdict;
|
|
@@ -61,6 +67,7 @@ declare class GovernedToolExecutor {
|
|
|
61
67
|
private engineOptions;
|
|
62
68
|
private mapFn;
|
|
63
69
|
private blockMsg;
|
|
70
|
+
private activePlan?;
|
|
64
71
|
constructor(world: WorldDefinition, options?: GovernedExecutorOptions);
|
|
65
72
|
/**
|
|
66
73
|
* Evaluate a single tool call against governance rules.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { G as GuardVerdict, a as GuardEvent, W as WorldDefinition } from '../guard-contract-
|
|
1
|
+
import { G as GuardVerdict, a as GuardEvent, P as PlanDefinition, b as PlanProgress, W as WorldDefinition } from '../guard-contract-D-2LQInm.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* NeuroVerse Adapter — OpenAI
|
|
@@ -45,6 +45,12 @@ interface GovernedExecutorOptions {
|
|
|
45
45
|
mapFunctionCall?: (name: string, args: Record<string, unknown>) => GuardEvent;
|
|
46
46
|
/** Message returned to the model when a tool call is blocked. */
|
|
47
47
|
blockMessage?: (verdict: GuardVerdict) => string;
|
|
48
|
+
/** Active plan overlay for task-scoped governance. */
|
|
49
|
+
plan?: PlanDefinition;
|
|
50
|
+
/** Called when plan progress changes. */
|
|
51
|
+
onPlanProgress?: (progress: PlanProgress) => void;
|
|
52
|
+
/** Called when all plan steps are completed. */
|
|
53
|
+
onPlanComplete?: () => void;
|
|
48
54
|
}
|
|
49
55
|
declare class GovernanceBlockedError extends Error {
|
|
50
56
|
readonly verdict: GuardVerdict;
|
|
@@ -61,6 +67,7 @@ declare class GovernedToolExecutor {
|
|
|
61
67
|
private engineOptions;
|
|
62
68
|
private mapFn;
|
|
63
69
|
private blockMsg;
|
|
70
|
+
private activePlan?;
|
|
64
71
|
constructor(world: WorldDefinition, options?: GovernedExecutorOptions);
|
|
65
72
|
/**
|
|
66
73
|
* Evaluate a single tool call against governance rules.
|
package/dist/adapters/openai.js
CHANGED
|
@@ -3,9 +3,11 @@ import {
|
|
|
3
3
|
GovernedToolExecutor,
|
|
4
4
|
createGovernedToolExecutor,
|
|
5
5
|
createGovernedToolExecutorFromWorld
|
|
6
|
-
} from "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
6
|
+
} from "../chunk-TINSRYXQ.js";
|
|
7
|
+
import "../chunk-PQBJBVSW.js";
|
|
8
|
+
import "../chunk-JZPQGIKR.js";
|
|
9
|
+
import "../chunk-P74Y66ZV.js";
|
|
10
|
+
import "../chunk-YZFATT7X.js";
|
|
9
11
|
export {
|
|
10
12
|
GovernanceBlockedError,
|
|
11
13
|
GovernedToolExecutor,
|