@neuroverseos/governance 0.3.4 → 0.4.0
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 +280 -405
- package/dist/adapters/autoresearch.cjs +63 -9
- package/dist/adapters/autoresearch.d.cts +1 -1
- package/dist/adapters/autoresearch.d.ts +1 -1
- package/dist/adapters/autoresearch.js +3 -3
- package/dist/adapters/deep-agents.cjs +63 -9
- package/dist/adapters/deep-agents.d.cts +2 -2
- package/dist/adapters/deep-agents.d.ts +2 -2
- package/dist/adapters/deep-agents.js +3 -3
- package/dist/adapters/express.cjs +63 -9
- package/dist/adapters/express.d.cts +1 -1
- package/dist/adapters/express.d.ts +1 -1
- package/dist/adapters/express.js +3 -3
- package/dist/adapters/index.cjs +896 -9
- package/dist/adapters/index.d.cts +278 -2
- package/dist/adapters/index.d.ts +278 -2
- package/dist/adapters/index.js +45 -8
- package/dist/adapters/langchain.cjs +63 -9
- package/dist/adapters/langchain.d.cts +2 -2
- package/dist/adapters/langchain.d.ts +2 -2
- package/dist/adapters/langchain.js +3 -3
- package/dist/adapters/openai.cjs +63 -9
- package/dist/adapters/openai.d.cts +2 -2
- package/dist/adapters/openai.d.ts +2 -2
- package/dist/adapters/openai.js +3 -3
- package/dist/adapters/openclaw.cjs +63 -9
- package/dist/adapters/openclaw.d.cts +2 -2
- package/dist/adapters/openclaw.d.ts +2 -2
- package/dist/adapters/openclaw.js +3 -3
- package/dist/{add-ROOZLU62.js → add-LYHDZ5RL.js} +1 -1
- package/dist/{behavioral-MJO34S6Q.js → behavioral-SPWPGYXL.js} +2 -2
- package/dist/{bootstrap-CQRZVOXK.js → bootstrap-IP5QMC3Q.js} +2 -2
- package/dist/{bootstrap-emitter-Q7UIJZ2O.js → bootstrap-emitter-GIMOJFOC.js} +1 -1
- package/dist/{bootstrap-parser-EEF36XDU.js → bootstrap-parser-LBLGVEMU.js} +1 -1
- package/dist/browser.global.js +149 -5
- package/dist/{build-ZHPMX5AZ.js → build-THUEYMVT.js} +3 -3
- package/dist/{chunk-G7DJ6VOD.js → chunk-25XHSTPT.js} +2 -2
- package/dist/{chunk-A7GKPPU7.js → chunk-2VAWP6FI.js} +1 -1
- package/dist/{chunk-EMQDLDAF.js → chunk-3NZMMSOW.js} +80 -2
- package/dist/{chunk-B6OXJLJ5.js → chunk-5JUZ4HL7.js} +2 -2
- package/dist/{chunk-VXHSMA3I.js → chunk-6CV4XG3J.js} +1 -1
- package/dist/{chunk-5TPFNWRU.js → chunk-7D7PZLB7.js} +3 -3
- package/dist/{chunk-ZWI3NIXK.js → chunk-7QIAF377.js} +54 -3
- package/dist/chunk-APU4OZIP.js +828 -0
- package/dist/{chunk-CTZHONLA.js → chunk-BXLTEUS4.js} +2 -2
- package/dist/{chunk-O5ABKEA7.js → chunk-DWHUZUEY.js} +2 -2
- package/dist/{chunk-U6U7EJZL.js → chunk-JKGPSFGH.js} +2 -2
- package/dist/{chunk-3WQLXYTP.js → chunk-MFKHTE5R.js} +2 -2
- package/dist/{chunk-TG6SEF24.js → chunk-OQU65525.js} +1 -1
- package/dist/{chunk-YEKMVDWK.js → chunk-QZ666FCV.js} +2 -2
- package/dist/{chunk-4FLICVVA.js → chunk-TD5GKIHP.js} +2 -2
- package/dist/{chunk-IS4WUH6Y.js → chunk-UTH7OXTM.js} +2 -2
- package/dist/{chunk-BNKJPUPQ.js → chunk-V4FZHJQX.js} +2 -2
- package/dist/{chunk-F66BVUYB.js → chunk-Y6WXAPKY.js} +3 -3
- package/dist/{chunk-QXBFT7NI.js → chunk-YNYCQECH.js} +2 -2
- package/dist/{chunk-PVTQQS3Y.js → chunk-YPCVY4GS.js} +31 -0
- package/dist/{chunk-W7LLXRGY.js → chunk-ZAF6JH23.js} +65 -10
- package/dist/cli/neuroverse.cjs +3031 -182
- package/dist/cli/neuroverse.js +39 -23
- package/dist/cli/plan.cjs +176 -12
- package/dist/cli/plan.js +2 -2
- package/dist/cli/run.cjs +63 -9
- package/dist/cli/run.js +2 -2
- package/dist/configure-world-XU2COHOZ.js +705 -0
- package/dist/{decision-flow-M63D47LO.js → decision-flow-3K4D72G4.js} +2 -2
- package/dist/{demo-G43RLCPK.js → demo-66MMJTEH.js} +3 -3
- package/dist/{derive-LMDUTXDD.js → derive-5LOMN7GO.js} +4 -4
- package/dist/{doctor-6BC6X2VO.js → doctor-WIO4FLA3.js} +2 -1
- package/dist/{equity-penalties-SG5IZQ7I.js → equity-penalties-WWC7UDQD.js} +3 -3
- package/dist/{explain-RHBU2GBR.js → explain-MUSGDT67.js} +1 -1
- package/dist/{guard-AEEJNWLD.js → guard-W3BMQPBJ.js} +3 -3
- package/dist/{guard-contract-B7lplwm9.d.ts → guard-contract-CLBbTGK_.d.cts} +91 -1
- package/dist/{guard-contract-B7lplwm9.d.cts → guard-contract-CLBbTGK_.d.ts} +91 -1
- package/dist/{guard-engine-PNR6MHCM.js → guard-engine-N7TUIUU7.js} +5 -3
- package/dist/{impact-3XVDSCBU.js → impact-WIAM66IH.js} +3 -3
- package/dist/{improve-TQP4ECSY.js → improve-PJDAWW4Q.js} +3 -3
- package/dist/index.cjs +230 -14
- package/dist/index.d.cts +72 -3
- package/dist/index.d.ts +72 -3
- package/dist/index.js +24 -22
- package/dist/{init-FYPV4SST.js → init-TKIJDR7I.js} +5 -1
- package/dist/lens-IP6GIZ2Q.js +1017 -0
- package/dist/{mcp-server-5Y3ZM7TV.js → mcp-server-OG3PPVD2.js} +3 -3
- package/dist/mentraos-YFS7FMJH.js +48 -0
- package/dist/{playground-VZBNPPBO.js → playground-4BK2XQ47.js} +2 -2
- package/dist/{redteam-MZPZD3EF.js → redteam-BRZALBPP.js} +2 -2
- package/dist/{session-JYOARW54.js → session-SGRUT2UH.js} +3 -3
- package/dist/{shared-C_zpdvBm.d.cts → shared-BGzmYP5g.d.cts} +1 -1
- package/dist/{shared-Cf7yxx4-.d.ts → shared-CwGpPheR.d.ts} +1 -1
- package/dist/{simulate-LJXYBC6M.js → simulate-FGXKIH7V.js} +17 -4
- package/dist/{test-BOOR4A5F.js → test-PT44BSYG.js} +2 -2
- package/dist/{trace-PKV4KX56.js → trace-2YDNAXMK.js} +2 -2
- package/dist/{validate-RALX7CZS.js → validate-Q5O5TGLT.js} +1 -1
- package/dist/{world-BIP4GZBZ.js → world-V52ZMH26.js} +1 -1
- package/dist/{world-loader-Y6HMQH2D.js → world-loader-C4D3VPP3.js} +1 -1
- package/dist/worlds/mentraos-smartglasses.nv-world.md +423 -0
- package/dist/worlds/user-rules.nv-world.md +328 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -419,6 +419,67 @@ function parseValueLiteral(raw) {
|
|
|
419
419
|
if (!isNaN(num) && raw.trim() !== "") return num;
|
|
420
420
|
return raw;
|
|
421
421
|
}
|
|
422
|
+
function parseLenses(content, startLine, issues) {
|
|
423
|
+
const lenses = [];
|
|
424
|
+
const subSections = splitH2Sections(content, startLine);
|
|
425
|
+
for (const sub of subSections) {
|
|
426
|
+
const props = parseKeyValueBullets(sub.content);
|
|
427
|
+
const lineNum = sub.startLine;
|
|
428
|
+
const directives = [];
|
|
429
|
+
const lines = sub.content.split("\n");
|
|
430
|
+
let directiveIndex = 0;
|
|
431
|
+
for (let i = 0; i < lines.length; i++) {
|
|
432
|
+
const line = lines[i].trim();
|
|
433
|
+
if (line.startsWith(">")) {
|
|
434
|
+
const blockContent = line.slice(1).trim();
|
|
435
|
+
const colonIdx = blockContent.indexOf(":");
|
|
436
|
+
if (colonIdx > 0) {
|
|
437
|
+
const scope = blockContent.slice(0, colonIdx).trim();
|
|
438
|
+
let instruction = blockContent.slice(colonIdx + 1).trim();
|
|
439
|
+
for (let j = i + 1; j < lines.length; j++) {
|
|
440
|
+
const nextLine = lines[j].trim();
|
|
441
|
+
if (nextLine.startsWith(">")) {
|
|
442
|
+
const nextContent = nextLine.slice(1).trim();
|
|
443
|
+
const nextColon = nextContent.indexOf(":");
|
|
444
|
+
if (nextColon > 0 && !nextContent.slice(0, nextColon).includes(" ")) {
|
|
445
|
+
break;
|
|
446
|
+
}
|
|
447
|
+
instruction += " " + nextContent;
|
|
448
|
+
i = j;
|
|
449
|
+
} else {
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
directives.push({
|
|
454
|
+
id: `${sub.name}_directive_${directiveIndex++}`,
|
|
455
|
+
scope,
|
|
456
|
+
instruction,
|
|
457
|
+
line: startLine + i
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
const tags = (props.tags ?? "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
463
|
+
const defaultForRoles = (props.default_for_roles ?? props.roles ?? "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
464
|
+
lenses.push({
|
|
465
|
+
id: sub.name,
|
|
466
|
+
name: props.name ?? sub.name,
|
|
467
|
+
tagline: props.tagline ?? "",
|
|
468
|
+
description: props.description ?? "",
|
|
469
|
+
tags,
|
|
470
|
+
formality: props.formality ?? "neutral",
|
|
471
|
+
verbosity: props.verbosity ?? "balanced",
|
|
472
|
+
emotion: props.emotion ?? "neutral",
|
|
473
|
+
confidence: props.confidence ?? "balanced",
|
|
474
|
+
defaultForRoles,
|
|
475
|
+
directives,
|
|
476
|
+
priority: props.priority ? parseInt(props.priority, 10) : 50,
|
|
477
|
+
stackable: props.stackable === "false" ? false : true,
|
|
478
|
+
line: lineNum
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
return lenses;
|
|
482
|
+
}
|
|
422
483
|
function parseWorldMarkdown(markdown) {
|
|
423
484
|
const issues = [];
|
|
424
485
|
const { frontmatter: fmRaw, sections } = splitSections(markdown);
|
|
@@ -456,8 +517,22 @@ function parseWorldMarkdown(markdown) {
|
|
|
456
517
|
}
|
|
457
518
|
const outcomesSection = findSection("Outcomes");
|
|
458
519
|
const outcomes = outcomesSection ? parseOutcomes(outcomesSection.content, outcomesSection.startLine, issues) : [];
|
|
520
|
+
const lensesSection = findSection("Lenses");
|
|
521
|
+
const lenses = lensesSection ? parseLenses(lensesSection.content, lensesSection.startLine, issues) : [];
|
|
522
|
+
let lensPolicy;
|
|
523
|
+
let lensLockPin;
|
|
524
|
+
if (lensesSection) {
|
|
525
|
+
const topContent = lensesSection.content.split(/^##\s/m)[0];
|
|
526
|
+
const topProps = parseKeyValueBullets(topContent);
|
|
527
|
+
if (topProps.policy === "locked" || topProps.policy === "role_default" || topProps.policy === "user_choice") {
|
|
528
|
+
lensPolicy = topProps.policy;
|
|
529
|
+
}
|
|
530
|
+
if (topProps.lock_pin) {
|
|
531
|
+
lensLockPin = topProps.lock_pin;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
459
534
|
const parsedSections = sections.map((s) => s.name);
|
|
460
|
-
const knownSections = /* @__PURE__ */ new Set(["thesis", "invariants", "state", "assumptions", "rules", "gates", "outcomes"]);
|
|
535
|
+
const knownSections = /* @__PURE__ */ new Set(["thesis", "invariants", "state", "assumptions", "rules", "gates", "outcomes", "lenses"]);
|
|
461
536
|
for (const section of sections) {
|
|
462
537
|
if (!knownSections.has(section.name.toLowerCase())) {
|
|
463
538
|
issues.push({
|
|
@@ -483,7 +558,10 @@ function parseWorldMarkdown(markdown) {
|
|
|
483
558
|
assumptions,
|
|
484
559
|
rules,
|
|
485
560
|
gates,
|
|
486
|
-
outcomes
|
|
561
|
+
outcomes,
|
|
562
|
+
lenses,
|
|
563
|
+
lensPolicy,
|
|
564
|
+
lensLockPin
|
|
487
565
|
},
|
|
488
566
|
issues
|
|
489
567
|
};
|
|
@@ -655,6 +733,36 @@ function emitWorldDefinition(parsed) {
|
|
|
655
733
|
structural_indicators: rules.filter((r) => r.severity === "structural").map((r) => r.id)
|
|
656
734
|
}
|
|
657
735
|
};
|
|
736
|
+
const validScopes = /* @__PURE__ */ new Set(["response_framing", "language_style", "content_filtering", "value_emphasis", "behavior_shaping"]);
|
|
737
|
+
const lensConfigs = parsed.lenses.map((pl) => {
|
|
738
|
+
const directives = pl.directives.map((d) => ({
|
|
739
|
+
id: d.id,
|
|
740
|
+
scope: validScopes.has(d.scope) ? d.scope : "behavior_shaping",
|
|
741
|
+
instruction: d.instruction
|
|
742
|
+
}));
|
|
743
|
+
return {
|
|
744
|
+
id: pl.id,
|
|
745
|
+
name: pl.name,
|
|
746
|
+
tagline: pl.tagline,
|
|
747
|
+
description: pl.description,
|
|
748
|
+
tags: pl.tags,
|
|
749
|
+
tone: {
|
|
750
|
+
formality: pl.formality || "neutral",
|
|
751
|
+
verbosity: pl.verbosity || "balanced",
|
|
752
|
+
emotion: pl.emotion || "neutral",
|
|
753
|
+
confidence: pl.confidence || "balanced"
|
|
754
|
+
},
|
|
755
|
+
directives,
|
|
756
|
+
defaultForRoles: pl.defaultForRoles,
|
|
757
|
+
priority: pl.priority,
|
|
758
|
+
stackable: pl.stackable
|
|
759
|
+
};
|
|
760
|
+
});
|
|
761
|
+
const lensesConfig = lensConfigs.length > 0 ? {
|
|
762
|
+
lenses: lensConfigs,
|
|
763
|
+
...parsed.lensPolicy ? { policy: parsed.lensPolicy } : {},
|
|
764
|
+
...parsed.lensLockPin ? { lockPin: parsed.lensLockPin } : {}
|
|
765
|
+
} : void 0;
|
|
658
766
|
const metadata = {
|
|
659
767
|
format_version: "1.0.0",
|
|
660
768
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -669,6 +777,7 @@ function emitWorldDefinition(parsed) {
|
|
|
669
777
|
rules,
|
|
670
778
|
gates,
|
|
671
779
|
outcomes,
|
|
780
|
+
...lensesConfig ? { lenses: lensesConfig } : {},
|
|
672
781
|
metadata
|
|
673
782
|
};
|
|
674
783
|
return { world: worldDefinition, issues };
|
|
@@ -910,6 +1019,7 @@ __export(index_exports, {
|
|
|
910
1019
|
tickAgentStates: () => tickAgentStates,
|
|
911
1020
|
validateWorld: () => validateWorld,
|
|
912
1021
|
verdictToAuditEvent: () => verdictToAuditEvent,
|
|
1022
|
+
verdictToEvent: () => verdictToEvent,
|
|
913
1023
|
writeTempWorld: () => writeTempWorld
|
|
914
1024
|
});
|
|
915
1025
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -1297,6 +1407,33 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
1297
1407
|
let decidingId;
|
|
1298
1408
|
const guardsMatched = [];
|
|
1299
1409
|
const rulesMatched = [];
|
|
1410
|
+
if (options.emergencyOverride) {
|
|
1411
|
+
checkInvariantCoverage(world, invariantChecks);
|
|
1412
|
+
return buildVerdict(
|
|
1413
|
+
"ALLOW",
|
|
1414
|
+
void 0,
|
|
1415
|
+
"emergency-override",
|
|
1416
|
+
"Emergency override active \u2014 all governance rules suspended. Platform constraints still apply.",
|
|
1417
|
+
world,
|
|
1418
|
+
level,
|
|
1419
|
+
invariantChecks,
|
|
1420
|
+
guardsMatched,
|
|
1421
|
+
rulesMatched,
|
|
1422
|
+
includeTrace ? buildTrace(
|
|
1423
|
+
invariantChecks,
|
|
1424
|
+
safetyChecks,
|
|
1425
|
+
planCheckResult,
|
|
1426
|
+
roleChecks,
|
|
1427
|
+
guardChecks,
|
|
1428
|
+
kernelRuleChecks,
|
|
1429
|
+
levelChecks,
|
|
1430
|
+
"session-allowlist",
|
|
1431
|
+
"emergency-override",
|
|
1432
|
+
startTime
|
|
1433
|
+
) : void 0,
|
|
1434
|
+
event.intent
|
|
1435
|
+
);
|
|
1436
|
+
}
|
|
1300
1437
|
checkInvariantCoverage(world, invariantChecks);
|
|
1301
1438
|
if (event.roleId && options.agentStates) {
|
|
1302
1439
|
const agentState = options.agentStates.get(event.roleId);
|
|
@@ -1361,7 +1498,8 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
1361
1498
|
decidingLayer,
|
|
1362
1499
|
decidingId,
|
|
1363
1500
|
startTime
|
|
1364
|
-
) : void 0
|
|
1501
|
+
) : void 0,
|
|
1502
|
+
event.intent
|
|
1365
1503
|
);
|
|
1366
1504
|
}
|
|
1367
1505
|
}
|
|
@@ -1390,7 +1528,8 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
1390
1528
|
decidingLayer,
|
|
1391
1529
|
decidingId,
|
|
1392
1530
|
startTime
|
|
1393
|
-
) : void 0
|
|
1531
|
+
) : void 0,
|
|
1532
|
+
event.intent
|
|
1394
1533
|
);
|
|
1395
1534
|
}
|
|
1396
1535
|
if (options.plan) {
|
|
@@ -1425,7 +1564,8 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
1425
1564
|
decidingLayer,
|
|
1426
1565
|
decidingId,
|
|
1427
1566
|
startTime
|
|
1428
|
-
) : void 0
|
|
1567
|
+
) : void 0,
|
|
1568
|
+
event.intent
|
|
1429
1569
|
);
|
|
1430
1570
|
}
|
|
1431
1571
|
}
|
|
@@ -1454,7 +1594,8 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
1454
1594
|
decidingLayer,
|
|
1455
1595
|
decidingId,
|
|
1456
1596
|
startTime
|
|
1457
|
-
) : void 0
|
|
1597
|
+
) : void 0,
|
|
1598
|
+
event.intent
|
|
1458
1599
|
);
|
|
1459
1600
|
}
|
|
1460
1601
|
const guardVerdict = checkGuards(event, eventText, world, guardChecks, guardsMatched);
|
|
@@ -1492,7 +1633,8 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
1492
1633
|
decidingLayer,
|
|
1493
1634
|
decidingId,
|
|
1494
1635
|
startTime
|
|
1495
|
-
) : void 0
|
|
1636
|
+
) : void 0,
|
|
1637
|
+
event.intent
|
|
1496
1638
|
);
|
|
1497
1639
|
verdict.intentRecord = intentRecord;
|
|
1498
1640
|
if (guardVerdict.consequence) verdict.consequence = guardVerdict.consequence;
|
|
@@ -1525,7 +1667,8 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
1525
1667
|
decidingLayer,
|
|
1526
1668
|
decidingId,
|
|
1527
1669
|
startTime
|
|
1528
|
-
) : void 0
|
|
1670
|
+
) : void 0,
|
|
1671
|
+
event.intent
|
|
1529
1672
|
);
|
|
1530
1673
|
}
|
|
1531
1674
|
const levelVerdict = checkLevelConstraints(event, level, levelChecks);
|
|
@@ -1553,7 +1696,8 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
1553
1696
|
decidingLayer,
|
|
1554
1697
|
decidingId,
|
|
1555
1698
|
startTime
|
|
1556
|
-
) : void 0
|
|
1699
|
+
) : void 0,
|
|
1700
|
+
event.intent
|
|
1557
1701
|
);
|
|
1558
1702
|
}
|
|
1559
1703
|
const warning = guardVerdict?.warning;
|
|
@@ -1578,7 +1722,8 @@ function evaluateGuard(event, world, options = {}) {
|
|
|
1578
1722
|
decidingLayer,
|
|
1579
1723
|
decidingId,
|
|
1580
1724
|
startTime
|
|
1581
|
-
) : void 0
|
|
1725
|
+
) : void 0,
|
|
1726
|
+
event.intent
|
|
1582
1727
|
);
|
|
1583
1728
|
}
|
|
1584
1729
|
function checkInvariantCoverage(world, checks) {
|
|
@@ -1955,7 +2100,7 @@ function buildTrace(invariantChecks, safetyChecks, planCheck, roleChecks, guardC
|
|
|
1955
2100
|
}
|
|
1956
2101
|
return trace;
|
|
1957
2102
|
}
|
|
1958
|
-
function buildVerdict(status, reason, ruleId, warning, world, level, invariantChecks, guardsMatched, rulesMatched, trace) {
|
|
2103
|
+
function buildVerdict(status, reason, ruleId, warning, world, level, invariantChecks, guardsMatched, rulesMatched, trace, eventIntent) {
|
|
1959
2104
|
const evidence = {
|
|
1960
2105
|
worldId: world.world.world_id,
|
|
1961
2106
|
worldName: world.world.name,
|
|
@@ -1975,8 +2120,27 @@ function buildVerdict(status, reason, ruleId, warning, world, level, invariantCh
|
|
|
1975
2120
|
if (ruleId) verdict.ruleId = ruleId;
|
|
1976
2121
|
if (warning) verdict.warning = warning;
|
|
1977
2122
|
if (trace) verdict.trace = trace;
|
|
2123
|
+
verdict.event = verdictToEvent(status, eventIntent);
|
|
1978
2124
|
return verdict;
|
|
1979
2125
|
}
|
|
2126
|
+
function verdictToEvent(status, intent) {
|
|
2127
|
+
const statusEventMap = {
|
|
2128
|
+
ALLOW: "action_allowed",
|
|
2129
|
+
BLOCK: "action_blocked",
|
|
2130
|
+
PAUSE: "action_paused",
|
|
2131
|
+
MODIFY: "action_modified",
|
|
2132
|
+
PENALIZE: "action_penalized",
|
|
2133
|
+
REWARD: "action_rewarded",
|
|
2134
|
+
NEUTRAL: "action_neutral"
|
|
2135
|
+
};
|
|
2136
|
+
return {
|
|
2137
|
+
type: intent || statusEventMap[status] || "unknown_action",
|
|
2138
|
+
actor: "agent",
|
|
2139
|
+
source: "guard",
|
|
2140
|
+
timestamp: Date.now(),
|
|
2141
|
+
guardStatus: status
|
|
2142
|
+
};
|
|
2143
|
+
}
|
|
1980
2144
|
|
|
1981
2145
|
// src/providers/ai-provider.ts
|
|
1982
2146
|
var ChatCompletionsProvider = class {
|
|
@@ -6663,15 +6827,25 @@ function simulateWorld(world, options = {}) {
|
|
|
6663
6827
|
let collapseStep;
|
|
6664
6828
|
let collapseRule;
|
|
6665
6829
|
const sortedRules = [...world.rules].sort((a, b) => a.order - b.order);
|
|
6830
|
+
const allEvents = options.events ?? [];
|
|
6831
|
+
const eventsByStep = Array.from({ length: steps }, () => []);
|
|
6832
|
+
for (let i = 0; i < allEvents.length; i++) {
|
|
6833
|
+
const stepIdx = Math.min(i, steps - 1);
|
|
6834
|
+
eventsByStep[stepIdx].push(allEvents[i]);
|
|
6835
|
+
}
|
|
6836
|
+
let totalEventsConsumed = 0;
|
|
6666
6837
|
for (let stepNum = 1; stepNum <= steps; stepNum++) {
|
|
6667
6838
|
if (collapsed) break;
|
|
6839
|
+
const stepEvents = eventsByStep[stepNum - 1];
|
|
6668
6840
|
const stepResult = evaluateStep(
|
|
6669
6841
|
stepNum,
|
|
6670
6842
|
sortedRules,
|
|
6671
6843
|
state,
|
|
6672
6844
|
assumptions,
|
|
6673
|
-
world
|
|
6845
|
+
world,
|
|
6846
|
+
stepEvents
|
|
6674
6847
|
);
|
|
6848
|
+
totalEventsConsumed += stepResult.eventsApplied.length;
|
|
6675
6849
|
simulationSteps.push(stepResult);
|
|
6676
6850
|
if (stepResult.collapsed) {
|
|
6677
6851
|
collapsed = true;
|
|
@@ -6690,14 +6864,38 @@ function simulateWorld(world, options = {}) {
|
|
|
6690
6864
|
finalViability,
|
|
6691
6865
|
collapsed,
|
|
6692
6866
|
collapseStep,
|
|
6693
|
-
collapseRule
|
|
6867
|
+
collapseRule,
|
|
6868
|
+
eventsConsumed: totalEventsConsumed
|
|
6694
6869
|
};
|
|
6695
6870
|
}
|
|
6696
|
-
function evaluateStep(stepNum, rules, state, assumptions, world) {
|
|
6871
|
+
function evaluateStep(stepNum, rules, state, assumptions, world, events = []) {
|
|
6697
6872
|
const evaluations = [];
|
|
6873
|
+
const eventApplications = [];
|
|
6698
6874
|
let rulesFired = 0;
|
|
6699
6875
|
let collapsed = false;
|
|
6700
6876
|
const firedRuleIds = /* @__PURE__ */ new Set();
|
|
6877
|
+
for (const evt of events) {
|
|
6878
|
+
const application = {
|
|
6879
|
+
eventType: evt.type,
|
|
6880
|
+
rulesTriggered: [],
|
|
6881
|
+
effects: []
|
|
6882
|
+
};
|
|
6883
|
+
for (const rule of rules) {
|
|
6884
|
+
const eventTrigger = rule.triggers.find(
|
|
6885
|
+
(t) => t.field === "event" && t.source === "state"
|
|
6886
|
+
);
|
|
6887
|
+
if (!eventTrigger) continue;
|
|
6888
|
+
const matches = evaluateOperator(evt.type, eventTrigger.operator, eventTrigger.value);
|
|
6889
|
+
if (!matches) continue;
|
|
6890
|
+
application.rulesTriggered.push(rule.id);
|
|
6891
|
+
firedRuleIds.add(rule.id);
|
|
6892
|
+
for (const effect of rule.effects ?? []) {
|
|
6893
|
+
const applied = applyEffect(effect, state);
|
|
6894
|
+
if (applied) application.effects.push(applied);
|
|
6895
|
+
}
|
|
6896
|
+
}
|
|
6897
|
+
eventApplications.push(application);
|
|
6898
|
+
}
|
|
6701
6899
|
for (const rule of rules) {
|
|
6702
6900
|
if (collapsed) {
|
|
6703
6901
|
evaluations.push({
|
|
@@ -6782,6 +6980,7 @@ function evaluateStep(stepNum, rules, state, assumptions, world) {
|
|
|
6782
6980
|
const viability = classifyViability(state, world);
|
|
6783
6981
|
return {
|
|
6784
6982
|
step: stepNum,
|
|
6983
|
+
eventsApplied: eventApplications,
|
|
6785
6984
|
rulesEvaluated: evaluations,
|
|
6786
6985
|
rulesFired,
|
|
6787
6986
|
stateAfter: { ...state },
|
|
@@ -6903,6 +7102,19 @@ function renderSimulateText(result) {
|
|
|
6903
7102
|
lines.push("");
|
|
6904
7103
|
for (const step of result.steps) {
|
|
6905
7104
|
lines.push(`STEP ${step.step}`);
|
|
7105
|
+
if (step.eventsApplied && step.eventsApplied.length > 0) {
|
|
7106
|
+
for (const evt of step.eventsApplied) {
|
|
7107
|
+
lines.push(` EVENT: ${evt.eventType}`);
|
|
7108
|
+
if (evt.rulesTriggered.length > 0) {
|
|
7109
|
+
lines.push(` Rules triggered: ${evt.rulesTriggered.join(", ")}`);
|
|
7110
|
+
}
|
|
7111
|
+
for (const effect of evt.effects) {
|
|
7112
|
+
const beforeStr = formatValue(effect.before);
|
|
7113
|
+
const afterStr = formatValue(effect.after);
|
|
7114
|
+
lines.push(` ${effect.target}: ${beforeStr} -> ${afterStr}`);
|
|
7115
|
+
}
|
|
7116
|
+
}
|
|
7117
|
+
}
|
|
6906
7118
|
const fired = step.rulesEvaluated.filter((r) => r.triggered);
|
|
6907
7119
|
const skipped = step.rulesEvaluated.filter((r) => !r.triggered && !r.excluded);
|
|
6908
7120
|
const excluded = step.rulesEvaluated.filter((r) => r.excluded);
|
|
@@ -6938,6 +7150,9 @@ function renderSimulateText(result) {
|
|
|
6938
7150
|
lines.push(` ${key}: ${formatValue(value)}${marker}`);
|
|
6939
7151
|
}
|
|
6940
7152
|
lines.push("");
|
|
7153
|
+
if (result.eventsConsumed > 0) {
|
|
7154
|
+
lines.push(`EVENTS CONSUMED: ${result.eventsConsumed}`);
|
|
7155
|
+
}
|
|
6941
7156
|
lines.push(`VIABILITY: ${result.finalViability}`);
|
|
6942
7157
|
if (result.collapsed) {
|
|
6943
7158
|
lines.push(`COLLAPSED at step ${result.collapseStep} (rule: ${result.collapseRule})`);
|
|
@@ -7734,5 +7949,6 @@ function handleCreateCapsule(body) {
|
|
|
7734
7949
|
tickAgentStates,
|
|
7735
7950
|
validateWorld,
|
|
7736
7951
|
verdictToAuditEvent,
|
|
7952
|
+
verdictToEvent,
|
|
7737
7953
|
writeTempWorld
|
|
7738
7954
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { G as GuardEvent, W as WorldDefinition, b as GuardEngineOptions, a as GuardVerdict, P as PlanDefinition, S as StepEvidence, A as AdvanceResult,
|
|
2
|
-
export { E as EvaluationTrace,
|
|
1
|
+
import { G as GuardEvent, W as WorldDefinition, b as GuardEngineOptions, a as GuardVerdict, d as GuardStatus, e as GovernanceEvent, P as PlanDefinition, S as StepEvidence, A as AdvanceResult, f as PlanVerdict, g as PlanCheck, c as PlanProgress, h as AgentBehaviorState, C as Consequence, R as Reward, i as Guard, I as Invariant, j as Rule, V as ViabilityStatus } from './guard-contract-CLBbTGK_.cjs';
|
|
2
|
+
export { E as EvaluationTrace, k as GUARD_EXIT_CODES, l as GuardCheck, m as GuardExitCode, n as IntentRecord, o as InvariantCheck, K as KernelRuleCheck, L as LevelCheck, p as PLAN_EXIT_CODES, q as PlanCompletionMode, r as PlanConstraint, s as PlanExitCode, t as PlanStatus, u as PlanStep, v as PrecedenceResolution, w as RoleCheck, x as SafetyCheck, y as VerdictEvidence } from './guard-contract-CLBbTGK_.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Guard Engine — Deterministic Governance Evaluator
|
|
@@ -43,6 +43,19 @@ declare function evaluateGuard(event: GuardEvent, world: WorldDefinition, option
|
|
|
43
43
|
* rather than constructing keys manually.
|
|
44
44
|
*/
|
|
45
45
|
declare function eventToAllowlistKey(event: GuardEvent): string;
|
|
46
|
+
/**
|
|
47
|
+
* Convert a guard verdict into a GovernanceEvent.
|
|
48
|
+
*
|
|
49
|
+
* The guard evaluation log IS the event stream.
|
|
50
|
+
* No Kafka, no queues — just data flowing from Guard → Simulate.
|
|
51
|
+
*
|
|
52
|
+
* Mapping:
|
|
53
|
+
* ALLOW → "action_allowed"
|
|
54
|
+
* BLOCK → "action_blocked"
|
|
55
|
+
* PAUSE → "action_paused"
|
|
56
|
+
* + semantic type from intent when available
|
|
57
|
+
*/
|
|
58
|
+
declare function verdictToEvent(status: GuardStatus, intent?: string): GovernanceEvent;
|
|
46
59
|
|
|
47
60
|
/**
|
|
48
61
|
* Derive Contract — AI-Assisted World Synthesis Types
|
|
@@ -1572,6 +1585,40 @@ interface ParsedOutcome {
|
|
|
1572
1585
|
assignment?: string;
|
|
1573
1586
|
line: number;
|
|
1574
1587
|
}
|
|
1588
|
+
/**
|
|
1589
|
+
* A parsed lens directive from the Lenses section.
|
|
1590
|
+
*/
|
|
1591
|
+
interface ParsedLensDirective {
|
|
1592
|
+
id: string;
|
|
1593
|
+
scope: string;
|
|
1594
|
+
instruction: string;
|
|
1595
|
+
line: number;
|
|
1596
|
+
}
|
|
1597
|
+
/**
|
|
1598
|
+
* A parsed lens from the Lenses section.
|
|
1599
|
+
* Each lens is an H2 subsection with key-value properties and directives.
|
|
1600
|
+
*/
|
|
1601
|
+
interface ParsedLens {
|
|
1602
|
+
id: string;
|
|
1603
|
+
name: string;
|
|
1604
|
+
tagline: string;
|
|
1605
|
+
description: string;
|
|
1606
|
+
tags: string[];
|
|
1607
|
+
/** Tone: formality, verbosity, emotion, confidence */
|
|
1608
|
+
formality: string;
|
|
1609
|
+
verbosity: string;
|
|
1610
|
+
emotion: string;
|
|
1611
|
+
confidence: string;
|
|
1612
|
+
/** Which roles this lens is the default for */
|
|
1613
|
+
defaultForRoles: string[];
|
|
1614
|
+
/** Behavioral directives */
|
|
1615
|
+
directives: ParsedLensDirective[];
|
|
1616
|
+
/** Priority when stacking (higher = applied later) */
|
|
1617
|
+
priority: number;
|
|
1618
|
+
/** Whether it can be stacked with other lenses */
|
|
1619
|
+
stackable: boolean;
|
|
1620
|
+
line: number;
|
|
1621
|
+
}
|
|
1575
1622
|
/**
|
|
1576
1623
|
* The full parsed intermediate representation.
|
|
1577
1624
|
*/
|
|
@@ -1584,6 +1631,9 @@ interface ParsedWorld {
|
|
|
1584
1631
|
rules: ParsedRule[];
|
|
1585
1632
|
gates: ParsedGate[];
|
|
1586
1633
|
outcomes: ParsedOutcome[];
|
|
1634
|
+
lenses: ParsedLens[];
|
|
1635
|
+
lensPolicy?: 'locked' | 'role_default' | 'user_choice';
|
|
1636
|
+
lensLockPin?: string;
|
|
1587
1637
|
}
|
|
1588
1638
|
declare const BOOTSTRAP_EXIT_CODES: {
|
|
1589
1639
|
readonly SUCCESS: 0;
|
|
@@ -2000,6 +2050,15 @@ interface SimulateOptions {
|
|
|
2000
2050
|
stateOverrides?: Record<string, string | number | boolean>;
|
|
2001
2051
|
/** Assumption profile to use (default: world default) */
|
|
2002
2052
|
profile?: string;
|
|
2053
|
+
/**
|
|
2054
|
+
* Governance events to inject into the simulation.
|
|
2055
|
+
* Events are applied before state-driven rules each step.
|
|
2056
|
+
* This is the bridge: Guard → Events → Simulate → State Evolution.
|
|
2057
|
+
*
|
|
2058
|
+
* Events are distributed across steps (round-robin) or all applied to step 1
|
|
2059
|
+
* if there are fewer steps than events.
|
|
2060
|
+
*/
|
|
2061
|
+
events?: GovernanceEvent[];
|
|
2003
2062
|
}
|
|
2004
2063
|
interface SimulationResult {
|
|
2005
2064
|
worldId: string;
|
|
@@ -2012,15 +2071,25 @@ interface SimulationResult {
|
|
|
2012
2071
|
collapsed: boolean;
|
|
2013
2072
|
collapseStep?: number;
|
|
2014
2073
|
collapseRule?: string;
|
|
2074
|
+
/** Total events consumed during simulation */
|
|
2075
|
+
eventsConsumed: number;
|
|
2015
2076
|
}
|
|
2016
2077
|
interface SimulationStep {
|
|
2017
2078
|
step: number;
|
|
2079
|
+
/** Events applied during this step (before rules) */
|
|
2080
|
+
eventsApplied: EventApplication[];
|
|
2018
2081
|
rulesEvaluated: RuleEvaluation[];
|
|
2019
2082
|
rulesFired: number;
|
|
2020
2083
|
stateAfter: Record<string, string | number | boolean>;
|
|
2021
2084
|
viability: ViabilityStatus;
|
|
2022
2085
|
collapsed: boolean;
|
|
2023
2086
|
}
|
|
2087
|
+
/** Record of an event applied during simulation */
|
|
2088
|
+
interface EventApplication {
|
|
2089
|
+
eventType: string;
|
|
2090
|
+
rulesTriggered: string[];
|
|
2091
|
+
effects: AppliedEffect[];
|
|
2092
|
+
}
|
|
2024
2093
|
interface RuleEvaluation {
|
|
2025
2094
|
ruleId: string;
|
|
2026
2095
|
label: string;
|
|
@@ -2347,4 +2416,4 @@ declare function handleCreateCapsule(body: {
|
|
|
2347
2416
|
createdAt: string;
|
|
2348
2417
|
};
|
|
2349
2418
|
|
|
2350
|
-
export { type AIGuardOptions, type AIGuardVerdict, type AIProvider, type AIProviderConfig, type ActionCategory, type Adaptation, type AddGuardInput, type AddInvariantInput, type AddResult, type AddRuleInput, AdvanceResult, type AgentAction, AgentBehaviorState, type AppliedEffect, type AuditEvent, type AuditLogger, type AuditSummary, BOOTSTRAP_EXIT_CODES, type BehavioralPattern, type BootstrapExitCode, type BootstrapResult, CONFIGURE_AI_EXIT_CODES, type ChatMessage, type ClassifiedIntent, type CollectedSource, CompositeAuditLogger, type Condition, type ConditionOperator, type ConditionResult, Consequence, ConsoleAuditLogger, type ConstructType, type ContentFields, DERIVE_EXIT_CODES, type DecisionFlow, type DecisionFlowMetrics, type DeriveExitCode, type DeriveFinding, type DeriveResult, type ExplainOutput, FileAuditLogger, type FindingCategory, type FindingSeverity, type FlowPath, type FormatVerdictOptions, type GovernanceEngineOptions, type GovernanceHealth, type Governor, type GovernorConfig, GuardEngineOptions, GuardEvent, GuardStatus, GuardVerdict, type ImpactReport, type ImprovementReport, type IntentClassifierOptions, type IntentCluster, type IntentSource, McpGovernanceServer, type McpServerConfig, ModelAdapter, type ModelConfig, type ModelResponse, type NetworkContext, type NormalizationSummary, type OutcomeCluster, PROVIDERS, type ParseIssue, type ParsedAssumptionProfile, type ParsedEffect, type ParsedFrontmatter, type ParsedGate, type ParsedInvariant, type ParsedOutcome, type ParsedRule, type ParsedStateVariable, type ParsedTrigger, type ParsedWorld, PlanCheck, PlanDefinition, type PlanParseResult, PlanProgress, PlanVerdict, type PreventionCategory, type ProviderPreset, Reward, type RuleEvaluation, type RuleObstacle, type SessionConfig, SessionManager, type SessionState, type SimulateOptions, type SimulationResult, type SimulationStep, StepEvidence, type Suggestion, type SuggestionCategory, type SuggestionPriority, type ToolCall, type ToolDefinition, VALIDATE_EXIT_CODES, type ValidateExitCode, type ValidateFinding, type ValidateReport, type ValidateSummary, type ValidationMode, type WorldInfo, type WorldState, actionToGuardEvent, adaptationFromVerdict, addGuard, addInvariant, addRule, advancePlan, applyConsequence, applyReward, buildPlanCheck, classifyAdaptation, classifyIntent, classifyIntentWithAI, createAgentState, createGovernanceEngine, createGovernor, deriveWorld, describeActiveWorld, detectBehavioralPatterns, emitWorldDefinition, evaluateCondition, evaluateGuard, evaluateGuardWithAI, evaluatePlan, eventToAllowlistKey, explainWorld, extractContentFields, extractWorldMarkdown, formatVerdict, formatVerdictOneLine, generateAdaptationNarrative, generateDecisionFlow, generateImpactReport, generateImpactReportFromFile, getActiveWorldName, getPlanProgress, govern, handleCreateCapsule, handleHealthCheck, handleListPresets, handleReasonRequest, improveWorld, listWorlds, loadWorld, loadWorldFromDirectory, normalizeWorldMarkdown, parseGuardDescription, parsePlanMarkdown, parseWorldMarkdown, readAuditLog, renderDecisionFlow, renderExplainText, renderImpactReport, renderImproveText, renderSimulateText, resolveProvider, resolveWorldPath, runInteractiveMode, runPipeMode, setActiveWorld, simulateWorld, summarizeAuditEvents, tickAgentStates, validateWorld, verdictToAuditEvent, writeTempWorld };
|
|
2419
|
+
export { type AIGuardOptions, type AIGuardVerdict, type AIProvider, type AIProviderConfig, type ActionCategory, type Adaptation, type AddGuardInput, type AddInvariantInput, type AddResult, type AddRuleInput, AdvanceResult, type AgentAction, AgentBehaviorState, type AppliedEffect, type AuditEvent, type AuditLogger, type AuditSummary, BOOTSTRAP_EXIT_CODES, type BehavioralPattern, type BootstrapExitCode, type BootstrapResult, CONFIGURE_AI_EXIT_CODES, type ChatMessage, type ClassifiedIntent, type CollectedSource, CompositeAuditLogger, type Condition, type ConditionOperator, type ConditionResult, Consequence, ConsoleAuditLogger, type ConstructType, type ContentFields, DERIVE_EXIT_CODES, type DecisionFlow, type DecisionFlowMetrics, type DeriveExitCode, type DeriveFinding, type DeriveResult, type EventApplication, type ExplainOutput, FileAuditLogger, type FindingCategory, type FindingSeverity, type FlowPath, type FormatVerdictOptions, type GovernanceEngineOptions, GovernanceEvent, type GovernanceHealth, type Governor, type GovernorConfig, GuardEngineOptions, GuardEvent, GuardStatus, GuardVerdict, type ImpactReport, type ImprovementReport, type IntentClassifierOptions, type IntentCluster, type IntentSource, McpGovernanceServer, type McpServerConfig, ModelAdapter, type ModelConfig, type ModelResponse, type NetworkContext, type NormalizationSummary, type OutcomeCluster, PROVIDERS, type ParseIssue, type ParsedAssumptionProfile, type ParsedEffect, type ParsedFrontmatter, type ParsedGate, type ParsedInvariant, type ParsedOutcome, type ParsedRule, type ParsedStateVariable, type ParsedTrigger, type ParsedWorld, PlanCheck, PlanDefinition, type PlanParseResult, PlanProgress, PlanVerdict, type PreventionCategory, type ProviderPreset, Reward, type RuleEvaluation, type RuleObstacle, type SessionConfig, SessionManager, type SessionState, type SimulateOptions, type SimulationResult, type SimulationStep, StepEvidence, type Suggestion, type SuggestionCategory, type SuggestionPriority, type ToolCall, type ToolDefinition, VALIDATE_EXIT_CODES, type ValidateExitCode, type ValidateFinding, type ValidateReport, type ValidateSummary, type ValidationMode, type WorldInfo, type WorldState, actionToGuardEvent, adaptationFromVerdict, addGuard, addInvariant, addRule, advancePlan, applyConsequence, applyReward, buildPlanCheck, classifyAdaptation, classifyIntent, classifyIntentWithAI, createAgentState, createGovernanceEngine, createGovernor, deriveWorld, describeActiveWorld, detectBehavioralPatterns, emitWorldDefinition, evaluateCondition, evaluateGuard, evaluateGuardWithAI, evaluatePlan, eventToAllowlistKey, explainWorld, extractContentFields, extractWorldMarkdown, formatVerdict, formatVerdictOneLine, generateAdaptationNarrative, generateDecisionFlow, generateImpactReport, generateImpactReportFromFile, getActiveWorldName, getPlanProgress, govern, handleCreateCapsule, handleHealthCheck, handleListPresets, handleReasonRequest, improveWorld, listWorlds, loadWorld, loadWorldFromDirectory, normalizeWorldMarkdown, parseGuardDescription, parsePlanMarkdown, parseWorldMarkdown, readAuditLog, renderDecisionFlow, renderExplainText, renderImpactReport, renderImproveText, renderSimulateText, resolveProvider, resolveWorldPath, runInteractiveMode, runPipeMode, setActiveWorld, simulateWorld, summarizeAuditEvents, tickAgentStates, validateWorld, verdictToAuditEvent, verdictToEvent, writeTempWorld };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { G as GuardEvent, W as WorldDefinition, b as GuardEngineOptions, a as GuardVerdict, P as PlanDefinition, S as StepEvidence, A as AdvanceResult,
|
|
2
|
-
export { E as EvaluationTrace,
|
|
1
|
+
import { G as GuardEvent, W as WorldDefinition, b as GuardEngineOptions, a as GuardVerdict, d as GuardStatus, e as GovernanceEvent, P as PlanDefinition, S as StepEvidence, A as AdvanceResult, f as PlanVerdict, g as PlanCheck, c as PlanProgress, h as AgentBehaviorState, C as Consequence, R as Reward, i as Guard, I as Invariant, j as Rule, V as ViabilityStatus } from './guard-contract-CLBbTGK_.js';
|
|
2
|
+
export { E as EvaluationTrace, k as GUARD_EXIT_CODES, l as GuardCheck, m as GuardExitCode, n as IntentRecord, o as InvariantCheck, K as KernelRuleCheck, L as LevelCheck, p as PLAN_EXIT_CODES, q as PlanCompletionMode, r as PlanConstraint, s as PlanExitCode, t as PlanStatus, u as PlanStep, v as PrecedenceResolution, w as RoleCheck, x as SafetyCheck, y as VerdictEvidence } from './guard-contract-CLBbTGK_.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Guard Engine — Deterministic Governance Evaluator
|
|
@@ -43,6 +43,19 @@ declare function evaluateGuard(event: GuardEvent, world: WorldDefinition, option
|
|
|
43
43
|
* rather than constructing keys manually.
|
|
44
44
|
*/
|
|
45
45
|
declare function eventToAllowlistKey(event: GuardEvent): string;
|
|
46
|
+
/**
|
|
47
|
+
* Convert a guard verdict into a GovernanceEvent.
|
|
48
|
+
*
|
|
49
|
+
* The guard evaluation log IS the event stream.
|
|
50
|
+
* No Kafka, no queues — just data flowing from Guard → Simulate.
|
|
51
|
+
*
|
|
52
|
+
* Mapping:
|
|
53
|
+
* ALLOW → "action_allowed"
|
|
54
|
+
* BLOCK → "action_blocked"
|
|
55
|
+
* PAUSE → "action_paused"
|
|
56
|
+
* + semantic type from intent when available
|
|
57
|
+
*/
|
|
58
|
+
declare function verdictToEvent(status: GuardStatus, intent?: string): GovernanceEvent;
|
|
46
59
|
|
|
47
60
|
/**
|
|
48
61
|
* Derive Contract — AI-Assisted World Synthesis Types
|
|
@@ -1572,6 +1585,40 @@ interface ParsedOutcome {
|
|
|
1572
1585
|
assignment?: string;
|
|
1573
1586
|
line: number;
|
|
1574
1587
|
}
|
|
1588
|
+
/**
|
|
1589
|
+
* A parsed lens directive from the Lenses section.
|
|
1590
|
+
*/
|
|
1591
|
+
interface ParsedLensDirective {
|
|
1592
|
+
id: string;
|
|
1593
|
+
scope: string;
|
|
1594
|
+
instruction: string;
|
|
1595
|
+
line: number;
|
|
1596
|
+
}
|
|
1597
|
+
/**
|
|
1598
|
+
* A parsed lens from the Lenses section.
|
|
1599
|
+
* Each lens is an H2 subsection with key-value properties and directives.
|
|
1600
|
+
*/
|
|
1601
|
+
interface ParsedLens {
|
|
1602
|
+
id: string;
|
|
1603
|
+
name: string;
|
|
1604
|
+
tagline: string;
|
|
1605
|
+
description: string;
|
|
1606
|
+
tags: string[];
|
|
1607
|
+
/** Tone: formality, verbosity, emotion, confidence */
|
|
1608
|
+
formality: string;
|
|
1609
|
+
verbosity: string;
|
|
1610
|
+
emotion: string;
|
|
1611
|
+
confidence: string;
|
|
1612
|
+
/** Which roles this lens is the default for */
|
|
1613
|
+
defaultForRoles: string[];
|
|
1614
|
+
/** Behavioral directives */
|
|
1615
|
+
directives: ParsedLensDirective[];
|
|
1616
|
+
/** Priority when stacking (higher = applied later) */
|
|
1617
|
+
priority: number;
|
|
1618
|
+
/** Whether it can be stacked with other lenses */
|
|
1619
|
+
stackable: boolean;
|
|
1620
|
+
line: number;
|
|
1621
|
+
}
|
|
1575
1622
|
/**
|
|
1576
1623
|
* The full parsed intermediate representation.
|
|
1577
1624
|
*/
|
|
@@ -1584,6 +1631,9 @@ interface ParsedWorld {
|
|
|
1584
1631
|
rules: ParsedRule[];
|
|
1585
1632
|
gates: ParsedGate[];
|
|
1586
1633
|
outcomes: ParsedOutcome[];
|
|
1634
|
+
lenses: ParsedLens[];
|
|
1635
|
+
lensPolicy?: 'locked' | 'role_default' | 'user_choice';
|
|
1636
|
+
lensLockPin?: string;
|
|
1587
1637
|
}
|
|
1588
1638
|
declare const BOOTSTRAP_EXIT_CODES: {
|
|
1589
1639
|
readonly SUCCESS: 0;
|
|
@@ -2000,6 +2050,15 @@ interface SimulateOptions {
|
|
|
2000
2050
|
stateOverrides?: Record<string, string | number | boolean>;
|
|
2001
2051
|
/** Assumption profile to use (default: world default) */
|
|
2002
2052
|
profile?: string;
|
|
2053
|
+
/**
|
|
2054
|
+
* Governance events to inject into the simulation.
|
|
2055
|
+
* Events are applied before state-driven rules each step.
|
|
2056
|
+
* This is the bridge: Guard → Events → Simulate → State Evolution.
|
|
2057
|
+
*
|
|
2058
|
+
* Events are distributed across steps (round-robin) or all applied to step 1
|
|
2059
|
+
* if there are fewer steps than events.
|
|
2060
|
+
*/
|
|
2061
|
+
events?: GovernanceEvent[];
|
|
2003
2062
|
}
|
|
2004
2063
|
interface SimulationResult {
|
|
2005
2064
|
worldId: string;
|
|
@@ -2012,15 +2071,25 @@ interface SimulationResult {
|
|
|
2012
2071
|
collapsed: boolean;
|
|
2013
2072
|
collapseStep?: number;
|
|
2014
2073
|
collapseRule?: string;
|
|
2074
|
+
/** Total events consumed during simulation */
|
|
2075
|
+
eventsConsumed: number;
|
|
2015
2076
|
}
|
|
2016
2077
|
interface SimulationStep {
|
|
2017
2078
|
step: number;
|
|
2079
|
+
/** Events applied during this step (before rules) */
|
|
2080
|
+
eventsApplied: EventApplication[];
|
|
2018
2081
|
rulesEvaluated: RuleEvaluation[];
|
|
2019
2082
|
rulesFired: number;
|
|
2020
2083
|
stateAfter: Record<string, string | number | boolean>;
|
|
2021
2084
|
viability: ViabilityStatus;
|
|
2022
2085
|
collapsed: boolean;
|
|
2023
2086
|
}
|
|
2087
|
+
/** Record of an event applied during simulation */
|
|
2088
|
+
interface EventApplication {
|
|
2089
|
+
eventType: string;
|
|
2090
|
+
rulesTriggered: string[];
|
|
2091
|
+
effects: AppliedEffect[];
|
|
2092
|
+
}
|
|
2024
2093
|
interface RuleEvaluation {
|
|
2025
2094
|
ruleId: string;
|
|
2026
2095
|
label: string;
|
|
@@ -2347,4 +2416,4 @@ declare function handleCreateCapsule(body: {
|
|
|
2347
2416
|
createdAt: string;
|
|
2348
2417
|
};
|
|
2349
2418
|
|
|
2350
|
-
export { type AIGuardOptions, type AIGuardVerdict, type AIProvider, type AIProviderConfig, type ActionCategory, type Adaptation, type AddGuardInput, type AddInvariantInput, type AddResult, type AddRuleInput, AdvanceResult, type AgentAction, AgentBehaviorState, type AppliedEffect, type AuditEvent, type AuditLogger, type AuditSummary, BOOTSTRAP_EXIT_CODES, type BehavioralPattern, type BootstrapExitCode, type BootstrapResult, CONFIGURE_AI_EXIT_CODES, type ChatMessage, type ClassifiedIntent, type CollectedSource, CompositeAuditLogger, type Condition, type ConditionOperator, type ConditionResult, Consequence, ConsoleAuditLogger, type ConstructType, type ContentFields, DERIVE_EXIT_CODES, type DecisionFlow, type DecisionFlowMetrics, type DeriveExitCode, type DeriveFinding, type DeriveResult, type ExplainOutput, FileAuditLogger, type FindingCategory, type FindingSeverity, type FlowPath, type FormatVerdictOptions, type GovernanceEngineOptions, type GovernanceHealth, type Governor, type GovernorConfig, GuardEngineOptions, GuardEvent, GuardStatus, GuardVerdict, type ImpactReport, type ImprovementReport, type IntentClassifierOptions, type IntentCluster, type IntentSource, McpGovernanceServer, type McpServerConfig, ModelAdapter, type ModelConfig, type ModelResponse, type NetworkContext, type NormalizationSummary, type OutcomeCluster, PROVIDERS, type ParseIssue, type ParsedAssumptionProfile, type ParsedEffect, type ParsedFrontmatter, type ParsedGate, type ParsedInvariant, type ParsedOutcome, type ParsedRule, type ParsedStateVariable, type ParsedTrigger, type ParsedWorld, PlanCheck, PlanDefinition, type PlanParseResult, PlanProgress, PlanVerdict, type PreventionCategory, type ProviderPreset, Reward, type RuleEvaluation, type RuleObstacle, type SessionConfig, SessionManager, type SessionState, type SimulateOptions, type SimulationResult, type SimulationStep, StepEvidence, type Suggestion, type SuggestionCategory, type SuggestionPriority, type ToolCall, type ToolDefinition, VALIDATE_EXIT_CODES, type ValidateExitCode, type ValidateFinding, type ValidateReport, type ValidateSummary, type ValidationMode, type WorldInfo, type WorldState, actionToGuardEvent, adaptationFromVerdict, addGuard, addInvariant, addRule, advancePlan, applyConsequence, applyReward, buildPlanCheck, classifyAdaptation, classifyIntent, classifyIntentWithAI, createAgentState, createGovernanceEngine, createGovernor, deriveWorld, describeActiveWorld, detectBehavioralPatterns, emitWorldDefinition, evaluateCondition, evaluateGuard, evaluateGuardWithAI, evaluatePlan, eventToAllowlistKey, explainWorld, extractContentFields, extractWorldMarkdown, formatVerdict, formatVerdictOneLine, generateAdaptationNarrative, generateDecisionFlow, generateImpactReport, generateImpactReportFromFile, getActiveWorldName, getPlanProgress, govern, handleCreateCapsule, handleHealthCheck, handleListPresets, handleReasonRequest, improveWorld, listWorlds, loadWorld, loadWorldFromDirectory, normalizeWorldMarkdown, parseGuardDescription, parsePlanMarkdown, parseWorldMarkdown, readAuditLog, renderDecisionFlow, renderExplainText, renderImpactReport, renderImproveText, renderSimulateText, resolveProvider, resolveWorldPath, runInteractiveMode, runPipeMode, setActiveWorld, simulateWorld, summarizeAuditEvents, tickAgentStates, validateWorld, verdictToAuditEvent, writeTempWorld };
|
|
2419
|
+
export { type AIGuardOptions, type AIGuardVerdict, type AIProvider, type AIProviderConfig, type ActionCategory, type Adaptation, type AddGuardInput, type AddInvariantInput, type AddResult, type AddRuleInput, AdvanceResult, type AgentAction, AgentBehaviorState, type AppliedEffect, type AuditEvent, type AuditLogger, type AuditSummary, BOOTSTRAP_EXIT_CODES, type BehavioralPattern, type BootstrapExitCode, type BootstrapResult, CONFIGURE_AI_EXIT_CODES, type ChatMessage, type ClassifiedIntent, type CollectedSource, CompositeAuditLogger, type Condition, type ConditionOperator, type ConditionResult, Consequence, ConsoleAuditLogger, type ConstructType, type ContentFields, DERIVE_EXIT_CODES, type DecisionFlow, type DecisionFlowMetrics, type DeriveExitCode, type DeriveFinding, type DeriveResult, type EventApplication, type ExplainOutput, FileAuditLogger, type FindingCategory, type FindingSeverity, type FlowPath, type FormatVerdictOptions, type GovernanceEngineOptions, GovernanceEvent, type GovernanceHealth, type Governor, type GovernorConfig, GuardEngineOptions, GuardEvent, GuardStatus, GuardVerdict, type ImpactReport, type ImprovementReport, type IntentClassifierOptions, type IntentCluster, type IntentSource, McpGovernanceServer, type McpServerConfig, ModelAdapter, type ModelConfig, type ModelResponse, type NetworkContext, type NormalizationSummary, type OutcomeCluster, PROVIDERS, type ParseIssue, type ParsedAssumptionProfile, type ParsedEffect, type ParsedFrontmatter, type ParsedGate, type ParsedInvariant, type ParsedOutcome, type ParsedRule, type ParsedStateVariable, type ParsedTrigger, type ParsedWorld, PlanCheck, PlanDefinition, type PlanParseResult, PlanProgress, PlanVerdict, type PreventionCategory, type ProviderPreset, Reward, type RuleEvaluation, type RuleObstacle, type SessionConfig, SessionManager, type SessionState, type SimulateOptions, type SimulationResult, type SimulationStep, StepEvidence, type Suggestion, type SuggestionCategory, type SuggestionPriority, type ToolCall, type ToolDefinition, VALIDATE_EXIT_CODES, type ValidateExitCode, type ValidateFinding, type ValidateReport, type ValidateSummary, type ValidationMode, type WorldInfo, type WorldState, actionToGuardEvent, adaptationFromVerdict, addGuard, addInvariant, addRule, advancePlan, applyConsequence, applyReward, buildPlanCheck, classifyAdaptation, classifyIntent, classifyIntentWithAI, createAgentState, createGovernanceEngine, createGovernor, deriveWorld, describeActiveWorld, detectBehavioralPatterns, emitWorldDefinition, evaluateCondition, evaluateGuard, evaluateGuardWithAI, evaluatePlan, eventToAllowlistKey, explainWorld, extractContentFields, extractWorldMarkdown, formatVerdict, formatVerdictOneLine, generateAdaptationNarrative, generateDecisionFlow, generateImpactReport, generateImpactReportFromFile, getActiveWorldName, getPlanProgress, govern, handleCreateCapsule, handleHealthCheck, handleListPresets, handleReasonRequest, improveWorld, listWorlds, loadWorld, loadWorldFromDirectory, normalizeWorldMarkdown, parseGuardDescription, parsePlanMarkdown, parseWorldMarkdown, readAuditLog, renderDecisionFlow, renderExplainText, renderImpactReport, renderImproveText, renderSimulateText, resolveProvider, resolveWorldPath, runInteractiveMode, runPipeMode, setActiveWorld, simulateWorld, summarizeAuditEvents, tickAgentStates, validateWorld, verdictToAuditEvent, verdictToEvent, writeTempWorld };
|