@neuroverseos/nv-sim 0.1.6 → 0.1.9
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 +374 -123
- package/dist/assets/index-B64NuIXu.css +1 -0
- package/dist/assets/{index-CHmUN8s0.js → index-BMkPevVr.js} +105 -105
- package/dist/assets/{reportEngine-BVdQ2_nW.js → reportEngine-D2ZrMny8.js} +1 -1
- package/dist/engine/chaosEngine.js +3 -9
- package/dist/engine/cli.js +34 -104
- package/dist/engine/index.js +2 -3
- package/dist/engine/liveVisualizer.js +1530 -230
- package/dist/engine/narrativeInjection.js +78 -89
- package/dist/engine/policyEngine.js +171 -58
- package/dist/engine/scenarioCapsule.js +73 -129
- package/dist/engine/scenarioLibrary.js +52 -131
- package/dist/engine/worldComparison.js +12 -25
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/dist/assets/index-DWgMnB7I.css +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as d,A as m,e as u,a as v}from"./index-
|
|
1
|
+
import{g as d,A as m,e as u,a as v}from"./index-BMkPevVr.js";function p(s){const e=s.governed,i=s.governanceStats,c=e.swarm.rounds.map((a,t)=>{var o;return{round:a.round,reactions:a.reactions.map(n=>({agent:n.stakeholder_id,action:n.reaction,impact:n.impact,verdict:void 0})),interventions:((o=a.emergent_dynamics)==null?void 0:o.filter(n=>n.includes("[BLOCK]")||n.includes("[PAUSE]")||n.includes("CIRCUIT BREAKER")||n.includes("intervention")))??[]}}),r=e.swarm.rounds.flatMap(a=>(a.emergent_dynamics??[]).filter(t=>t.includes("[BLOCK]")||t.includes("[PAUSE]")||t.includes("GATE")||t.includes("Rebalanced")||t.includes("Capped"))),l={avgImpact:e.metrics.avgImpact,collapseProbability:e.metrics.collapseProbability,stabilityScore:e.metrics.stabilityScore,maxVolatility:e.metrics.maxVolatility,peakNegativeSentiment:e.metrics.peakNegativeSentiment};return{scenario:s.scenario,rounds:c,metrics:l,interventions:r,governanceStats:{totalEvaluations:i.totalEvaluations,blocks:i.verdicts.block,pauses:i.verdicts.pause,allows:i.verdicts.allow,rulesFired:i.rulesFired}}}async function y(s,e={}){const i=p(s),c=e.aiEnabled??!1,r=c?e.provider??"deterministic":"deterministic",l=d(r),a=m.find(o=>o.id==="ai_analyst"),t=await u(a,"generate_report",async()=>c&&r!=="deterministic"?l.summarize(i):v(i));return{report:t.result,governance:t,aiUsed:c&&r!=="deterministic",provider:r}}export{p as extractTrace,y as generateGovernedReport};
|
|
@@ -100,16 +100,10 @@ async function runChaosTest(presetId, options = {}) {
|
|
|
100
100
|
return aggregateResults(presetId, results, durationMs);
|
|
101
101
|
}
|
|
102
102
|
function resolvePreset(presetId) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
request: governedSimulation_1.TRADING_DEMO.scenario,
|
|
106
|
-
world: governedSimulation_1.TRADING_DEMO.world,
|
|
107
|
-
paths: governedSimulation_1.TRADING_DEMO.paths,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
const template = scenarioCapsule_1.SCENARIO_TEMPLATES[presetId];
|
|
103
|
+
const resolvedId = (presetId === "trading" || presetId === "flash_crash") ? "social_simulation" : presetId;
|
|
104
|
+
const template = scenarioCapsule_1.SCENARIO_TEMPLATES[resolvedId];
|
|
111
105
|
if (!template) {
|
|
112
|
-
throw new Error(`Unknown preset: ${presetId}. Available:
|
|
106
|
+
throw new Error(`Unknown preset: ${presetId}. Available: ${Object.keys(scenarioCapsule_1.SCENARIO_TEMPLATES).join(", ")}`);
|
|
113
107
|
}
|
|
114
108
|
if (!template.world?.inline_definition) {
|
|
115
109
|
throw new Error(`Preset "${presetId}" has no world definition for chaos testing.`);
|
package/dist/engine/cli.js
CHANGED
|
@@ -81,17 +81,12 @@ async function main() {
|
|
|
81
81
|
console.log(" " + "=".repeat(60));
|
|
82
82
|
let result;
|
|
83
83
|
let worldId;
|
|
84
|
-
|
|
85
|
-
console.log(` Scenario: Flash Crash — Algorithmic Cascade\n`);
|
|
86
|
-
worldId = "trading-flash-crash";
|
|
87
|
-
result = await (0, governedSimulation_1.runGovernedComparison)(governedSimulation_1.TRADING_DEMO.scenario, governedSimulation_1.TRADING_DEMO.world, governedSimulation_1.TRADING_DEMO.paths, narrativeEvents.length > 0 ? narrativeEvents : undefined);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
84
|
+
{
|
|
90
85
|
// Try to use an existing preset
|
|
91
|
-
const template = scenarioCapsule_1.SCENARIO_TEMPLATES[presetId];
|
|
86
|
+
const template = scenarioCapsule_1.SCENARIO_TEMPLATES[presetId] ?? scenarioCapsule_1.SCENARIO_TEMPLATES["social_simulation"];
|
|
92
87
|
if (!template) {
|
|
93
88
|
console.error(` Unknown preset: ${presetId}`);
|
|
94
|
-
console.error(` Available:
|
|
89
|
+
console.error(` Available: ${Object.keys(scenarioCapsule_1.SCENARIO_TEMPLATES).join(", ")}`);
|
|
95
90
|
process.exit(1);
|
|
96
91
|
}
|
|
97
92
|
if (!template.world?.inline_definition) {
|
|
@@ -551,85 +546,32 @@ async function main() {
|
|
|
551
546
|
}
|
|
552
547
|
docText = fs.readFileSync(resolved, "utf-8");
|
|
553
548
|
}
|
|
554
|
-
console.log(`\n NV-SIM — World
|
|
549
|
+
console.log(`\n NV-SIM — World Generator\n`);
|
|
555
550
|
console.log(` Reading: ${docPath === "-" ? "stdin" : docPath}`);
|
|
556
551
|
console.log(" " + "=".repeat(60));
|
|
557
|
-
//
|
|
558
|
-
const
|
|
552
|
+
// Use the full policy engine to parse rules and generate a complete world
|
|
553
|
+
const { parseRulesFromText, policyToWorld } = await Promise.resolve().then(() => __importStar(require("./policyEngine")));
|
|
554
|
+
const parsed = parseRulesFromText(docText);
|
|
555
|
+
const worldDef = policyToWorld(parsed);
|
|
559
556
|
const worldId = args.includes("--id") ? args[args.indexOf("--id") + 1] : path.basename(docPath, path.extname(docPath)).replace(/\s+/g, "_").toLowerCase();
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
const lower = line.toLowerCase();
|
|
569
|
-
// Skip markdown headers but use them for context
|
|
570
|
-
if (line.startsWith("#")) {
|
|
571
|
-
if (!thesis)
|
|
572
|
-
thesis = line.replace(/^#+\s*/, "");
|
|
573
|
-
continue;
|
|
574
|
-
}
|
|
575
|
-
// First non-header line as thesis if not set
|
|
576
|
-
if (!thesis && line.length > 10) {
|
|
577
|
-
thesis = line;
|
|
578
|
-
continue;
|
|
579
|
-
}
|
|
580
|
-
// Detect rules: lines starting with block/prevent/limit/require/allow etc
|
|
581
|
-
if (/^(block|prevent|prohibit|ban|stop|forbid|no\b|don.t|limit|cap|restrict)/i.test(lower)) {
|
|
582
|
-
invCount++;
|
|
583
|
-
invariants.push({
|
|
584
|
-
id: `INV-${String(invCount).padStart(3, "0")}`,
|
|
585
|
-
description: line.replace(/^[-*•]\s*/, ""),
|
|
586
|
-
enforceable: true,
|
|
587
|
-
});
|
|
588
|
-
}
|
|
589
|
-
else if (/^(require|must|shall|ensure|mandate)/i.test(lower)) {
|
|
590
|
-
invCount++;
|
|
591
|
-
invariants.push({
|
|
592
|
-
id: `INV-${String(invCount).padStart(3, "0")}`,
|
|
593
|
-
description: line.replace(/^[-*•]\s*/, ""),
|
|
594
|
-
enforceable: true,
|
|
595
|
-
});
|
|
596
|
-
}
|
|
597
|
-
else if (/^(allow|permit|enable)/i.test(lower)) {
|
|
598
|
-
invCount++;
|
|
599
|
-
invariants.push({
|
|
600
|
-
id: `INV-${String(invCount).padStart(3, "0")}`,
|
|
601
|
-
description: line.replace(/^[-*•]\s*/, ""),
|
|
602
|
-
enforceable: false,
|
|
603
|
-
});
|
|
604
|
-
}
|
|
605
|
-
else if (/^(warn|alert|flag|monitor|watch)/i.test(lower)) {
|
|
606
|
-
gateCount++;
|
|
607
|
-
gates.push({
|
|
608
|
-
id: `GATE-${String(gateCount).padStart(3, "0")}`,
|
|
609
|
-
label: line.replace(/^[-*•]\s*/, ""),
|
|
610
|
-
condition: lower,
|
|
611
|
-
severity: /critical|extreme|emergency/i.test(lower) ? "critical" : "warning",
|
|
612
|
-
});
|
|
613
|
-
}
|
|
614
|
-
else if (/^[-*•]\s*/.test(line)) {
|
|
615
|
-
// Bullet points are probably rules
|
|
616
|
-
invCount++;
|
|
617
|
-
invariants.push({
|
|
618
|
-
id: `INV-${String(invCount).padStart(3, "0")}`,
|
|
619
|
-
description: line.replace(/^[-*•]\s*/, ""),
|
|
620
|
-
enforceable: true,
|
|
621
|
-
});
|
|
622
|
-
}
|
|
557
|
+
console.log(`\n Parsed ${parsed.summary.total} rules (${parsed.summary.enforced} enforced, ${parsed.summary.advisory} advisory)`);
|
|
558
|
+
console.log(`\n GENERATED WORLD: "${worldId}"`);
|
|
559
|
+
console.log(" " + "-".repeat(60));
|
|
560
|
+
console.log(` Thesis: ${worldDef.thesis}`);
|
|
561
|
+
console.log(` State Variables: ${worldDef.state_variables.length}`);
|
|
562
|
+
for (const sv of worldDef.state_variables) {
|
|
563
|
+
const rangeStr = sv.type === "number" && sv.range ? ` (${sv.range.min}-${sv.range.max}, default: ${sv.default_value})` : ` (default: ${sv.default_value})`;
|
|
564
|
+
console.log(` - ${sv.label}${rangeStr}`);
|
|
623
565
|
}
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
}
|
|
632
|
-
// Wrap in SavedWorld format
|
|
566
|
+
console.log(` Invariants: ${worldDef.invariants.length}`);
|
|
567
|
+
for (const inv of worldDef.invariants) {
|
|
568
|
+
console.log(` - [${inv.id}] ${inv.description}${inv.enforceable ? "" : " (advisory)"}`);
|
|
569
|
+
}
|
|
570
|
+
console.log(` Gates: ${worldDef.gates?.length ?? 0}`);
|
|
571
|
+
for (const gate of worldDef.gates ?? []) {
|
|
572
|
+
console.log(` - [${gate.id}] ${gate.label}: ${gate.condition} (${gate.severity})`);
|
|
573
|
+
}
|
|
574
|
+
// Wrap in SavedWorld format
|
|
633
575
|
const { createSavedWorld: createWorld } = await Promise.resolve().then(() => __importStar(require("./worldStorage")));
|
|
634
576
|
const savedWorld = createWorld(worldId, worldDef, "document", {
|
|
635
577
|
description: `Generated from ${docPath === "-" ? "stdin" : docPath}`,
|
|
@@ -639,22 +581,15 @@ async function main() {
|
|
|
639
581
|
const json = JSON.stringify(savedWorld, null, 2);
|
|
640
582
|
if (outputPath) {
|
|
641
583
|
fs.writeFileSync(outputPath, json, "utf-8");
|
|
642
|
-
console.log(`\n
|
|
584
|
+
console.log(`\n Saved: ${outputPath}`);
|
|
643
585
|
}
|
|
644
586
|
else {
|
|
645
587
|
console.log("\n" + json);
|
|
646
588
|
}
|
|
647
|
-
console.log(`\n
|
|
648
|
-
console.log(`
|
|
649
|
-
console.log(`
|
|
650
|
-
console.log(`
|
|
651
|
-
console.log(`\n This world file is saved for reuse.`);
|
|
652
|
-
console.log(` You don't need this step — enforce accepts .txt directly:`);
|
|
653
|
-
console.log(` npx nv-sim enforce trading ${docPath === "-" ? "policy.txt" : docPath}`);
|
|
654
|
-
if (outputPath) {
|
|
655
|
-
console.log(`\n But since you saved it, you can also:`);
|
|
656
|
-
console.log(` npx nv-sim enforce trading ${outputPath}`);
|
|
657
|
-
}
|
|
589
|
+
console.log(`\n Your world is complete — same structure as the built-in templates.`);
|
|
590
|
+
console.log(` Use it:`);
|
|
591
|
+
console.log(` npx nv-sim serve --world ${outputPath ?? worldId + ".json"}`);
|
|
592
|
+
console.log(` npx nv-sim enforce ${worldId} ${docPath === "-" ? "rules.txt" : docPath}`);
|
|
658
593
|
console.log("");
|
|
659
594
|
break;
|
|
660
595
|
}
|
|
@@ -1226,17 +1161,12 @@ async function main() {
|
|
|
1226
1161
|
let basePaths;
|
|
1227
1162
|
let baseWorldDef;
|
|
1228
1163
|
let scenarioTitle;
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
baseWorldDef = governedSimulation_1.TRADING_DEMO.world;
|
|
1233
|
-
scenarioTitle = "Flash Crash — Algorithmic Cascade";
|
|
1234
|
-
}
|
|
1235
|
-
else {
|
|
1236
|
-
const template = scenarioCapsule_1.SCENARIO_TEMPLATES[presetArg];
|
|
1164
|
+
{
|
|
1165
|
+
const resolvedPreset = presetArg === "trading" || presetArg === "flash_crash" ? "social_simulation" : presetArg;
|
|
1166
|
+
const template = scenarioCapsule_1.SCENARIO_TEMPLATES[resolvedPreset];
|
|
1237
1167
|
if (!template || !template.world?.inline_definition) {
|
|
1238
1168
|
console.error(` Unknown preset: ${presetArg}`);
|
|
1239
|
-
console.error(` Available:
|
|
1169
|
+
console.error(` Available: ${Object.keys(scenarioCapsule_1.SCENARIO_TEMPLATES).join(", ")}`);
|
|
1240
1170
|
process.exit(1);
|
|
1241
1171
|
}
|
|
1242
1172
|
baseRequest = {
|
package/dist/engine/index.js
CHANGED
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
* Mirotir helps you decide WHAT TO DO → the brain
|
|
22
22
|
*/
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.policyToWorld = exports.validatePolicy = exports.parseRulesFromText = exports.suggestExperiments = exports.formatPolicyDiagnostics = exports.formatGuidedNextSteps = exports.exportEnforcementReportJSON = exports.formatEnforcementReport = exports.createEnforcementSession = exports.formatCrossRunComparison = exports.formatBehavioralAnalysis = exports.compareBehaviorAcrossRuns = exports.detectBehavioralShifts = exports.computeActionDistributions = exports.buildAgentTrajectories = exports.classifyBehavior = exports.analyzeBehavior = exports.
|
|
25
|
-
exports.EXAMPLE_WORLD_STATES = exports.EXAMPLE_ACTIONS = exports.createGovernor = exports.govern = exports.extractTrace = exports.generateGovernedReport = exports.formatAuditTrail = exports.searchAuditTrails = exports.loadAuditSession = exports.listAuditSessions = exports.AuditTrail = exports.evaluateAIAction = exports.listAIProviders = exports.getDefaultProviderName = exports.getAIProvider = exports.registerAIProvider = exports.generateAIReaction = exports.generateDeterministicReport = exports.OpenAICompatibleProvider = exports.AnthropicProvider = exports.DeterministicProvider = exports.AI_ROLES = exports.parseReasonRequestBody = exports.handleRunPreset = exports.handleGetPreset = exports.handleListPresets = exports.handleHealthCheck = exports.handleCreateCapsule = exports.handleReasonFromCapsule = exports.handleReasonRequest = exports.applyQuickFix =
|
|
24
|
+
exports.runPolicyPipeline = exports.policyToWorld = exports.validatePolicy = exports.parseRulesFromText = exports.suggestExperiments = exports.formatPolicyDiagnostics = exports.formatGuidedNextSteps = exports.exportEnforcementReportJSON = exports.formatEnforcementReport = exports.createEnforcementSession = exports.formatCrossRunComparison = exports.formatBehavioralAnalysis = exports.compareBehaviorAcrossRuns = exports.detectBehavioralShifts = exports.computeActionDistributions = exports.buildAgentTrajectories = exports.classifyBehavior = exports.analyzeBehavior = exports.runGovernedComparison = exports.analyzeMiroFishSimulation = exports.DEFAULT_MIROFISH_CONFIG = exports.buildMiroFishRequest = exports.miroFishResultToSwarmResult = exports.stakeholdersToMiroFishAgents = exports.runUnifiedSimulation = exports.getMiroFishClient = exports.configureMiroFish = exports.MiroFishError = exports.MiroFishClient = exports.runSwarmSimulation = exports.initNeuroverseModule = exports.validationToEnforcedConstraints = exports.simulationToGovernanceSignals = exports.verdictToConstitutionalChecks = exports.validateScenarioWorld = exports.runWorldSimulation = exports.evaluateScenarioGuard = exports.buildWorldFromScenario = exports.runFullGovernanceChecks = exports.runGovernanceChecks = exports.processReasonRequest = exports.SCENARIO_TEMPLATES = exports.getPresetCapsule = exports.extractCapsuleFromUrl = exports.buildShareableUrl = exports.decodeCapsule = exports.encodeCapsule = exports.capsuleToReasonRequest = exports.createCapsule = exports.runGoalReasoning = void 0;
|
|
25
|
+
exports.EXAMPLE_WORLD_STATES = exports.EXAMPLE_ACTIONS = exports.createGovernor = exports.govern = exports.extractTrace = exports.generateGovernedReport = exports.formatAuditTrail = exports.searchAuditTrails = exports.loadAuditSession = exports.listAuditSessions = exports.AuditTrail = exports.evaluateAIAction = exports.listAIProviders = exports.getDefaultProviderName = exports.getAIProvider = exports.registerAIProvider = exports.generateAIReaction = exports.generateDeterministicReport = exports.OpenAICompatibleProvider = exports.AnthropicProvider = exports.DeterministicProvider = exports.AI_ROLES = exports.parseReasonRequestBody = exports.handleRunPreset = exports.handleGetPreset = exports.handleListPresets = exports.handleHealthCheck = exports.handleCreateCapsule = exports.handleReasonFromCapsule = exports.handleReasonRequest = exports.applyQuickFix = void 0;
|
|
26
26
|
// Goal-Directed Strategy Engine
|
|
27
27
|
var goalEngine_1 = require("./goalEngine");
|
|
28
28
|
Object.defineProperty(exports, "runGoalReasoning", { enumerable: true, get: function () { return goalEngine_1.runGoalReasoning; } });
|
|
@@ -70,7 +70,6 @@ var analyzer_1 = require("./analyzer");
|
|
|
70
70
|
Object.defineProperty(exports, "analyzeMiroFishSimulation", { enumerable: true, get: function () { return analyzer_1.analyzeMiroFishSimulation; } });
|
|
71
71
|
var governedSimulation_1 = require("./governedSimulation");
|
|
72
72
|
Object.defineProperty(exports, "runGovernedComparison", { enumerable: true, get: function () { return governedSimulation_1.runGovernedComparison; } });
|
|
73
|
-
Object.defineProperty(exports, "TRADING_DEMO", { enumerable: true, get: function () { return governedSimulation_1.TRADING_DEMO; } });
|
|
74
73
|
var behavioralAnalysis_1 = require("./behavioralAnalysis");
|
|
75
74
|
Object.defineProperty(exports, "analyzeBehavior", { enumerable: true, get: function () { return behavioralAnalysis_1.analyzeBehavior; } });
|
|
76
75
|
Object.defineProperty(exports, "classifyBehavior", { enumerable: true, get: function () { return behavioralAnalysis_1.classifyBehavior; } });
|