@neuroverseos/nv-sim 0.1.4 → 0.1.5
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 +346 -68
- package/dist/adapters/mirofish.js +461 -0
- package/dist/adapters/scienceclaw.js +750 -0
- package/dist/assets/index-B64NuIXu.css +1 -0
- package/dist/assets/index-DbzSnYxr.js +532 -0
- package/dist/assets/{reportEngine-BfteK4MN.js → reportEngine-DKWTrP6-.js} +1 -1
- package/dist/components/ConstraintsPanel.js +11 -0
- package/dist/components/StakeholderBuilder.js +32 -0
- package/dist/components/ui/badge.js +24 -0
- package/dist/components/ui/button.js +70 -0
- package/dist/components/ui/card.js +57 -0
- package/dist/components/ui/input.js +44 -0
- package/dist/components/ui/label.js +45 -0
- package/dist/components/ui/select.js +70 -0
- package/dist/engine/aiProvider.js +427 -2
- package/dist/engine/auditTrace.js +352 -0
- package/dist/engine/behavioralAnalysis.js +605 -0
- package/dist/engine/cli.js +1087 -13
- package/dist/engine/dynamicsGovernance.js +588 -0
- package/dist/engine/fullGovernedLoop.js +367 -0
- package/dist/engine/governedSimulation.js +77 -6
- package/dist/engine/index.js +41 -1
- package/dist/engine/liveVisualizer.js +2787 -360
- package/dist/engine/metrics/science.metrics.js +335 -0
- package/dist/engine/narrativeInjection.js +55 -0
- package/dist/engine/policyEnforcement.js +1611 -0
- package/dist/engine/policyEngine.js +799 -0
- package/dist/engine/primeRadiant.js +540 -0
- package/dist/engine/scenarioCapsule.js +56 -0
- package/dist/engine/scenarioComparison.js +463 -0
- package/dist/engine/scenarioLibrary.js +17 -0
- package/dist/engine/swarmSimulation.js +54 -1
- package/dist/engine/worldComparison.js +164 -0
- package/dist/engine/worldStorage.js +232 -0
- package/dist/index.html +2 -2
- package/dist/lib/reasoningEngine.js +290 -0
- package/dist/lib/simulationAdapter.js +686 -0
- package/dist/lib/swarmParser.js +291 -0
- package/dist/lib/types.js +2 -0
- package/dist/lib/utils.js +8 -0
- package/dist/runtime/govern.js +473 -0
- package/dist/runtime/index.js +75 -0
- package/dist/runtime/types.js +11 -0
- package/package.json +5 -2
- package/dist/assets/index-DHKd4rcV.js +0 -338
- package/dist/assets/index-SyyA3z3U.css +0 -1
- package/dist/assets/swarmSimulation-DHDqjfMa.js +0 -1
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* UI Adapter for the Echelon Reasoning Engine
|
|
4
|
+
*
|
|
5
|
+
* Bridges the engine's processReasonRequest() API to the UI component types.
|
|
6
|
+
* Also generates preset scenarios from SCENARIO_TEMPLATES.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.presetScenarios = void 0;
|
|
10
|
+
exports.generateReasoning = generateReasoning;
|
|
11
|
+
const index_1 = require("../engine/index");
|
|
12
|
+
// ============================================
|
|
13
|
+
// PRESET SCENARIOS (from SCENARIO_TEMPLATES)
|
|
14
|
+
// ============================================
|
|
15
|
+
function templateIdToType(id) {
|
|
16
|
+
if (id.includes('hormuz') || id.includes('strait'))
|
|
17
|
+
return 'geopolitical';
|
|
18
|
+
if (id.includes('gas') || id.includes('price'))
|
|
19
|
+
return 'economic';
|
|
20
|
+
if (id.includes('ai') || id.includes('regulation'))
|
|
21
|
+
return 'regulation';
|
|
22
|
+
return 'custom';
|
|
23
|
+
}
|
|
24
|
+
function assumptionsToSliders(assumptions) {
|
|
25
|
+
const severityMap = { low: 20, moderate: 40, high: 70, critical: 90 };
|
|
26
|
+
const hostilityMap = { low: 20, moderate: 50, high: 80 };
|
|
27
|
+
const timeMap = { none: 10, low: 25, moderate: 50, urgent: 75, immediate: 95 };
|
|
28
|
+
const regMap = { permissive: 20, neutral: 40, strict: 70, adversarial: 90 };
|
|
29
|
+
return {
|
|
30
|
+
severity: severityMap[assumptions.severity ?? 'moderate'] ?? 50,
|
|
31
|
+
environmentalHostility: hostilityMap[assumptions.environmental_hostility ?? 'moderate'] ?? 50,
|
|
32
|
+
timePressure: timeMap[assumptions.time_pressure ?? 'moderate'] ?? 50,
|
|
33
|
+
regulatoryClimate: regMap[assumptions.regulatory_climate ?? 'neutral'] ?? 50,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function slidersToAssumptions(sliders) {
|
|
37
|
+
const severity = sliders.severity >= 80 ? 'critical' : sliders.severity >= 60 ? 'high' : sliders.severity >= 35 ? 'moderate' : 'low';
|
|
38
|
+
const hostility = sliders.environmentalHostility >= 60 ? 'high' : sliders.environmentalHostility >= 35 ? 'moderate' : 'low';
|
|
39
|
+
const time = sliders.timePressure >= 85 ? 'immediate' : sliders.timePressure >= 65 ? 'urgent' : sliders.timePressure >= 40 ? 'moderate' : sliders.timePressure >= 20 ? 'low' : 'none';
|
|
40
|
+
const reg = sliders.regulatoryClimate >= 80 ? 'adversarial' : sliders.regulatoryClimate >= 60 ? 'strict' : sliders.regulatoryClimate >= 35 ? 'neutral' : 'permissive';
|
|
41
|
+
return {
|
|
42
|
+
severity: severity,
|
|
43
|
+
environmental_hostility: hostility,
|
|
44
|
+
time_pressure: time,
|
|
45
|
+
regulatory_climate: reg,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
exports.presetScenarios = Object.entries(index_1.SCENARIO_TEMPLATES).map(([id, template]) => ({
|
|
49
|
+
id,
|
|
50
|
+
title: template.title,
|
|
51
|
+
description: template.scenario.slice(0, 120) + (template.scenario.length > 120 ? '...' : ''),
|
|
52
|
+
tags: [...(template.tags ?? [])],
|
|
53
|
+
stakeholderCount: template.stakeholders.length,
|
|
54
|
+
type: templateIdToType(id),
|
|
55
|
+
defaultSliders: assumptionsToSliders(template.assumptions),
|
|
56
|
+
}));
|
|
57
|
+
// ============================================
|
|
58
|
+
// ENGINE RESPONSE → UI TYPES MAPPING
|
|
59
|
+
// ============================================
|
|
60
|
+
function mapRiskLevel(risk) {
|
|
61
|
+
if (risk === 'critical' || risk === 'high')
|
|
62
|
+
return 'high';
|
|
63
|
+
if (risk === 'moderate')
|
|
64
|
+
return 'medium';
|
|
65
|
+
return 'low';
|
|
66
|
+
}
|
|
67
|
+
function mapPaths(response) {
|
|
68
|
+
const paths = response.analysis.paths;
|
|
69
|
+
const sorted = [...paths].sort((a, b) => {
|
|
70
|
+
const order = { low: 0, moderate: 1, high: 2, critical: 3 };
|
|
71
|
+
return order[a.risk] - order[b.risk];
|
|
72
|
+
});
|
|
73
|
+
const recommendedId = sorted[0]?.id;
|
|
74
|
+
return paths.map(p => ({
|
|
75
|
+
name: p.label,
|
|
76
|
+
description: p.description,
|
|
77
|
+
probability: Math.round(p.probability * 100),
|
|
78
|
+
riskLevel: mapRiskLevel(p.risk),
|
|
79
|
+
tradeoffs: [...p.tradeoffs],
|
|
80
|
+
recommended: p.id === recommendedId,
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
function mapMatrix(response) {
|
|
84
|
+
const paths = response.analysis.paths.slice(0, 3);
|
|
85
|
+
const stakeholderIds = [
|
|
86
|
+
...new Set([
|
|
87
|
+
...paths.flatMap(p => [...(p.benefits_stakeholders ?? []), ...(p.harms_stakeholders ?? [])]),
|
|
88
|
+
]),
|
|
89
|
+
].slice(0, 6);
|
|
90
|
+
const strategies = paths.map(p => p.label);
|
|
91
|
+
const stakeholders = stakeholderIds.length > 0 ? stakeholderIds : ['Stakeholder A', 'Stakeholder B', 'Stakeholder C'];
|
|
92
|
+
const reactions = stakeholders.map((sh) => paths.map(p => {
|
|
93
|
+
if (p.benefits_stakeholders?.includes(sh))
|
|
94
|
+
return 'positive';
|
|
95
|
+
if (p.harms_stakeholders?.includes(sh))
|
|
96
|
+
return 'negative';
|
|
97
|
+
return 'neutral';
|
|
98
|
+
}));
|
|
99
|
+
return { strategies, stakeholders, reactions };
|
|
100
|
+
}
|
|
101
|
+
function mapOutcomes(response) {
|
|
102
|
+
const impactToRating = {
|
|
103
|
+
very_positive: 2, positive: 4, neutral: 5, negative: 7, very_negative: 9,
|
|
104
|
+
};
|
|
105
|
+
return response.analysis.projected_outcomes.map(o => ({
|
|
106
|
+
label: o.label,
|
|
107
|
+
type: (o.label.toLowerCase().includes('best') ? 'best' :
|
|
108
|
+
o.label.toLowerCase().includes('likely') ? 'likely' :
|
|
109
|
+
o.label.toLowerCase().includes('worst') ? 'worst' : 'tail'),
|
|
110
|
+
conditions: o.conditions,
|
|
111
|
+
description: o.outcome,
|
|
112
|
+
likelihood: Math.round(o.likelihood * 100),
|
|
113
|
+
impactRating: impactToRating[o.impact] ?? 5,
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
function mapChallenges(response) {
|
|
117
|
+
return response.analysis.assumption_challenges.map(c => ({
|
|
118
|
+
assumption: c.assumption,
|
|
119
|
+
whyItMightFail: c.challenge,
|
|
120
|
+
whatChanges: c.impact_if_wrong,
|
|
121
|
+
severity: c.severity === 'critical' ? 'critical' : c.severity,
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
function mapRecommendations(response) {
|
|
125
|
+
return response.analysis.recommendations.map(r => ({
|
|
126
|
+
priority: r.priority,
|
|
127
|
+
action: r.action,
|
|
128
|
+
rationale: r.rationale,
|
|
129
|
+
timeframe: r.timeframe,
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
function mapGovernance(response) {
|
|
133
|
+
const g = response.governance;
|
|
134
|
+
if (!g)
|
|
135
|
+
return undefined;
|
|
136
|
+
return {
|
|
137
|
+
traceId: g.trace_id,
|
|
138
|
+
constitutionalChecks: g.constitutional_checks.map(c => ({
|
|
139
|
+
ruleId: c.rule_id,
|
|
140
|
+
rule: c.rule,
|
|
141
|
+
passed: c.passed,
|
|
142
|
+
detail: c.detail,
|
|
143
|
+
})),
|
|
144
|
+
authorityLevel: g.authority_level,
|
|
145
|
+
enforcedConstraints: [...g.enforced_constraints],
|
|
146
|
+
timestamp: g.timestamp,
|
|
147
|
+
engineVersion: g.engine_version,
|
|
148
|
+
neuroverse: g.neuroverse ? {
|
|
149
|
+
guardStatus: g.neuroverse.guard_status,
|
|
150
|
+
worldViability: g.neuroverse.world_viability,
|
|
151
|
+
worldCollapsed: g.neuroverse.world_collapsed,
|
|
152
|
+
collapseRisk: g.neuroverse.collapse_risk,
|
|
153
|
+
rulesFired: g.neuroverse.rules_fired,
|
|
154
|
+
worldHealthScore: g.neuroverse.world_health_score,
|
|
155
|
+
invariantCoverage: g.neuroverse.invariant_coverage,
|
|
156
|
+
} : undefined,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function deriveConfidence(response) {
|
|
160
|
+
const paths = response.analysis.paths;
|
|
161
|
+
const challenges = response.analysis.assumption_challenges;
|
|
162
|
+
const highRiskPaths = paths.filter(p => p.risk === 'high' || p.risk === 'critical').length;
|
|
163
|
+
const avgProbability = paths.reduce((s, p) => s + p.probability, 0) / Math.max(paths.length, 1);
|
|
164
|
+
// Factor in governance signals when available
|
|
165
|
+
const nv = response.governance?.neuroverse;
|
|
166
|
+
const worldHealth = nv?.world_health_score;
|
|
167
|
+
const collapseRisk = nv?.collapse_risk;
|
|
168
|
+
let level = 'medium';
|
|
169
|
+
let reason;
|
|
170
|
+
// Adjust thresholds based on simulation dynamics
|
|
171
|
+
const simPenalty = collapseRisk === 'high' ? 0.15 : collapseRisk === 'moderate' ? 0.08 : 0;
|
|
172
|
+
const adjustedAvgProb = avgProbability - simPenalty;
|
|
173
|
+
if (challenges.length <= 1 && highRiskPaths === 0 && adjustedAvgProb > 0.6) {
|
|
174
|
+
level = 'high';
|
|
175
|
+
reason = `Analysis covers ${paths.length} paths with low assumption risk and strong probability signals.`;
|
|
176
|
+
if (worldHealth && worldHealth < 70) {
|
|
177
|
+
level = 'medium';
|
|
178
|
+
reason += ` System stability at ${worldHealth}% — moderate uncertainty from simulation dynamics.`;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else if (challenges.length >= 4 || highRiskPaths >= 2 || adjustedAvgProb < 0.3) {
|
|
182
|
+
level = 'low';
|
|
183
|
+
reason = `High uncertainty: ${challenges.length} assumptions challenged, ${highRiskPaths} high-risk paths, average probability ${(avgProbability * 100).toFixed(0)}%.`;
|
|
184
|
+
if (collapseRisk === 'high') {
|
|
185
|
+
reason += ` Elevated collapse risk detected in simulation.`;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
reason = `Moderate confidence: ${paths.length} paths analyzed, ${challenges.length} assumptions challenged.`;
|
|
190
|
+
if (worldHealth) {
|
|
191
|
+
reason += ` System stability: ${worldHealth}%.`;
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
reason += ` Some uncertainty remains.`;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return { level, reason };
|
|
198
|
+
}
|
|
199
|
+
function deriveKeyAssumptions(request, response) {
|
|
200
|
+
const assumptions = [];
|
|
201
|
+
// Caller-provided assumptions
|
|
202
|
+
if (request.assumptions?.severity) {
|
|
203
|
+
assumptions.push({ text: `Severity is ${request.assumptions.severity}`, source: 'caller' });
|
|
204
|
+
}
|
|
205
|
+
if (request.assumptions?.time_pressure) {
|
|
206
|
+
assumptions.push({ text: `Time pressure is ${request.assumptions.time_pressure}`, source: 'caller' });
|
|
207
|
+
}
|
|
208
|
+
if (request.assumptions?.environmental_hostility) {
|
|
209
|
+
assumptions.push({ text: `Environmental hostility is ${request.assumptions.environmental_hostility}`, source: 'caller' });
|
|
210
|
+
}
|
|
211
|
+
if (request.assumptions?.regulatory_climate) {
|
|
212
|
+
assumptions.push({ text: `Regulatory climate is ${request.assumptions.regulatory_climate}`, source: 'caller' });
|
|
213
|
+
}
|
|
214
|
+
// Inferred assumptions
|
|
215
|
+
if (request.stakeholders && request.stakeholders.length > 0) {
|
|
216
|
+
assumptions.push({ text: `${request.stakeholders.length} stakeholders identified with known dispositions`, source: 'inferred' });
|
|
217
|
+
}
|
|
218
|
+
// Default assumptions
|
|
219
|
+
if (!request.constraints?.time_horizon) {
|
|
220
|
+
assumptions.push({ text: 'No explicit time horizon — using general framework', source: 'default' });
|
|
221
|
+
}
|
|
222
|
+
if (!request.constraints?.risk_tolerance) {
|
|
223
|
+
assumptions.push({ text: 'Risk tolerance not specified — assuming moderate', source: 'default' });
|
|
224
|
+
}
|
|
225
|
+
return assumptions;
|
|
226
|
+
}
|
|
227
|
+
function mapResponseToResult(response, request) {
|
|
228
|
+
return {
|
|
229
|
+
paths: mapPaths(response),
|
|
230
|
+
matrix: mapMatrix(response),
|
|
231
|
+
outcomes: mapOutcomes(response),
|
|
232
|
+
challenges: mapChallenges(response),
|
|
233
|
+
recommendations: mapRecommendations(response),
|
|
234
|
+
governance: mapGovernance(response),
|
|
235
|
+
confidence: deriveConfidence(response),
|
|
236
|
+
keyAssumptions: deriveKeyAssumptions(request, response),
|
|
237
|
+
goalResult: response.goal_reasoning,
|
|
238
|
+
mode: response.mode,
|
|
239
|
+
lastRequest: request,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Generate reasoning using the Echelon engine.
|
|
244
|
+
* Maps UI types (Scenario + SliderValues) → engine ReasonRequest → UI ReasoningResult.
|
|
245
|
+
*/
|
|
246
|
+
async function generateReasoning(scenario, sliders, options) {
|
|
247
|
+
const scenarioText = typeof scenario === 'string'
|
|
248
|
+
? scenario
|
|
249
|
+
: index_1.SCENARIO_TEMPLATES[scenario.id]?.scenario ?? scenario.description;
|
|
250
|
+
const assumptions = slidersToAssumptions(sliders);
|
|
251
|
+
// Get stakeholders from template if available, or from options
|
|
252
|
+
const templateId = typeof scenario === 'object' ? scenario.id : undefined;
|
|
253
|
+
const template = templateId ? index_1.SCENARIO_TEMPLATES[templateId] : undefined;
|
|
254
|
+
let stakeholders;
|
|
255
|
+
if (options?.stakeholders && options.stakeholders.length > 0) {
|
|
256
|
+
stakeholders = options.stakeholders.map(s => ({
|
|
257
|
+
id: s.id,
|
|
258
|
+
disposition: s.disposition,
|
|
259
|
+
}));
|
|
260
|
+
}
|
|
261
|
+
else if (template?.stakeholders) {
|
|
262
|
+
stakeholders = [...template.stakeholders];
|
|
263
|
+
}
|
|
264
|
+
const request = {
|
|
265
|
+
scenario: scenarioText,
|
|
266
|
+
stakeholders,
|
|
267
|
+
assumptions,
|
|
268
|
+
constraints: options?.constraints ? {
|
|
269
|
+
time_horizon: options.constraints.timeHorizon || undefined,
|
|
270
|
+
risk_tolerance: options.constraints.riskTolerance,
|
|
271
|
+
budget: options.constraints.budget || undefined,
|
|
272
|
+
} : template?.constraints,
|
|
273
|
+
depth: options?.depth ?? 'full',
|
|
274
|
+
perspective: 'strategic_advisor',
|
|
275
|
+
swarm: template?.swarm ?? { enabled: true, rounds: 3, reaction_model: 'mixed' },
|
|
276
|
+
mode: options?.mode,
|
|
277
|
+
goal: options?.goal,
|
|
278
|
+
};
|
|
279
|
+
const response = await (0, index_1.processReasonRequest)(request);
|
|
280
|
+
if (response.status === 'error') {
|
|
281
|
+
return {
|
|
282
|
+
paths: [],
|
|
283
|
+
matrix: { strategies: [], stakeholders: [], reactions: [] },
|
|
284
|
+
outcomes: [],
|
|
285
|
+
challenges: [],
|
|
286
|
+
recommendations: [],
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
return mapResponseToResult(response, request);
|
|
290
|
+
}
|