@neuroverseos/nv-sim 0.1.4 → 0.1.7

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.
Files changed (44) hide show
  1. package/README.md +260 -6
  2. package/dist/adapters/mirofish.js +461 -0
  3. package/dist/adapters/scienceclaw.js +750 -0
  4. package/dist/assets/index-CHmUN8s0.js +532 -0
  5. package/dist/assets/index-DWgMnB7I.css +1 -0
  6. package/dist/assets/{reportEngine-BfteK4MN.js → reportEngine-BVdQ2_nW.js} +1 -1
  7. package/dist/components/ConstraintsPanel.js +11 -0
  8. package/dist/components/StakeholderBuilder.js +32 -0
  9. package/dist/components/ui/badge.js +24 -0
  10. package/dist/components/ui/button.js +70 -0
  11. package/dist/components/ui/card.js +57 -0
  12. package/dist/components/ui/input.js +44 -0
  13. package/dist/components/ui/label.js +45 -0
  14. package/dist/components/ui/select.js +70 -0
  15. package/dist/engine/aiProvider.js +427 -2
  16. package/dist/engine/auditTrace.js +352 -0
  17. package/dist/engine/behavioralAnalysis.js +605 -0
  18. package/dist/engine/cli.js +1087 -13
  19. package/dist/engine/dynamicsGovernance.js +588 -0
  20. package/dist/engine/fullGovernedLoop.js +367 -0
  21. package/dist/engine/governedSimulation.js +77 -6
  22. package/dist/engine/index.js +41 -1
  23. package/dist/engine/liveVisualizer.js +1961 -197
  24. package/dist/engine/metrics/science.metrics.js +335 -0
  25. package/dist/engine/policyEnforcement.js +1611 -0
  26. package/dist/engine/policyEngine.js +799 -0
  27. package/dist/engine/primeRadiant.js +540 -0
  28. package/dist/engine/scenarioComparison.js +463 -0
  29. package/dist/engine/swarmSimulation.js +54 -1
  30. package/dist/engine/worldComparison.js +164 -0
  31. package/dist/engine/worldStorage.js +232 -0
  32. package/dist/index.html +2 -2
  33. package/dist/lib/reasoningEngine.js +290 -0
  34. package/dist/lib/simulationAdapter.js +686 -0
  35. package/dist/lib/swarmParser.js +291 -0
  36. package/dist/lib/types.js +2 -0
  37. package/dist/lib/utils.js +8 -0
  38. package/dist/runtime/govern.js +473 -0
  39. package/dist/runtime/index.js +75 -0
  40. package/dist/runtime/types.js +11 -0
  41. package/package.json +5 -2
  42. package/dist/assets/index-DHKd4rcV.js +0 -338
  43. package/dist/assets/index-SyyA3z3U.css +0 -1
  44. package/dist/assets/swarmSimulation-DHDqjfMa.js +0 -1
@@ -0,0 +1,335 @@
1
+ "use strict";
2
+ /**
3
+ * Science Metrics Module — Evaluation Metrics for Autonomous Discovery
4
+ *
5
+ * "ScienceClaw explores possibility. NeuroVerse enforces reality."
6
+ *
7
+ * These metrics evaluate the quality of governed scientific discovery.
8
+ * They plug directly into scenarioComparison.ts as EvaluationMetric[].
9
+ *
10
+ * The five core science metrics:
11
+ * 1. Convergence Quality — are we converging on truth, or on noise?
12
+ * 2. Reproducibility Score — can findings be independently validated?
13
+ * 3. Provenance Depth — how deep is the evidence chain?
14
+ * 4. Compute Efficiency — are we burning cycles on dead ends?
15
+ * 5. False Positive Rate — how much garbage survives the pipeline?
16
+ *
17
+ * Science-specific system state extends the base SystemState with:
18
+ * - artifact_density: how many artifacts per round
19
+ * - validation_gap: how far behind validation lags discovery
20
+ * - citation_circularity: self-referencing chains
21
+ * - hypothesis_diversity: breadth of active investigation
22
+ * - convergence_velocity: how fast hypotheses collapse to consensus
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.SCIENCE_INITIAL_STATE = exports.SCIENCE_POLICY_TEXT = exports.SCIENCE_METRICS = void 0;
26
+ exports.interpretScienceState = interpretScienceState;
27
+ // ============================================
28
+ // METRIC EXTRACTORS
29
+ // ============================================
30
+ /**
31
+ * Extract convergence quality from simulation results.
32
+ *
33
+ * Good convergence:
34
+ * - Low polarization (hypotheses are consolidating, not fragmenting)
35
+ * - Moderate velocity (not too fast = shallow, not too slow = stuck)
36
+ * - High trust (findings are reproducible)
37
+ *
38
+ * Bad convergence:
39
+ * - High polarization (field is fragmenting)
40
+ * - Very high velocity (premature consensus without evidence)
41
+ * - Low trust (findings can't be reproduced)
42
+ */
43
+ function extractConvergenceQuality(result) {
44
+ const state = result.finalState;
45
+ // Low polarization → hypotheses consolidating (good)
46
+ const consolidation = 1 - state.polarization;
47
+ // Moderate velocity is ideal — too fast is shallow, too slow is stuck
48
+ // Sweet spot: 0.3-0.6
49
+ const velocityScore = state.informationVelocity >= 0.3 && state.informationVelocity <= 0.6
50
+ ? 1.0
51
+ : state.informationVelocity < 0.3
52
+ ? state.informationVelocity / 0.3 // too slow
53
+ : 1 - (state.informationVelocity - 0.6) / 0.4; // too fast
54
+ // High trust → reproducible findings
55
+ const reproducibility = state.trust;
56
+ // Low cascade risk → findings aren't propagating unchecked
57
+ const integrityScore = 1 - state.cascadeRisk;
58
+ return (consolidation * 0.3 +
59
+ velocityScore * 0.25 +
60
+ reproducibility * 0.25 +
61
+ integrityScore * 0.2);
62
+ }
63
+ /**
64
+ * Extract reproducibility score.
65
+ *
66
+ * In science mode:
67
+ * trust = can we reproduce findings?
68
+ * low outrage = no publication pressure forcing premature claims
69
+ * low cascade risk = bad results aren't propagating through citations
70
+ */
71
+ function extractReproducibilityScore(result) {
72
+ const state = result.finalState;
73
+ // Trust is the primary indicator of reproducibility
74
+ const trustScore = state.trust;
75
+ // Low publication pressure (outrage = rush to publish)
76
+ const pressureScore = 1 - state.outrage;
77
+ // Low cascade risk = validated results, not propagated noise
78
+ const validationScore = 1 - state.cascadeRisk;
79
+ // Governance effectiveness indicates active quality control
80
+ const govEffectiveness = result.dynamicsGovernance.totalInterventions > 0
81
+ ? Math.min(1, result.dynamicsGovernance.trustBoosts / Math.max(1, result.dynamicsGovernance.totalRounds) + 0.3)
82
+ : 0.3;
83
+ return (trustScore * 0.35 +
84
+ pressureScore * 0.2 +
85
+ validationScore * 0.25 +
86
+ govEffectiveness * 0.2);
87
+ }
88
+ /**
89
+ * Extract provenance depth score.
90
+ *
91
+ * Deeper provenance chains = better evidence foundations.
92
+ * In the simulation, this maps to:
93
+ * - contagionDepth (how deep content propagates = evidence chain depth)
94
+ * - Low amplification (not relying on popularity over evidence)
95
+ * - Multiple rounds of stable findings (temporal depth)
96
+ */
97
+ function extractProvenanceDepth(result) {
98
+ const state = result.finalState;
99
+ const timeline = result.stateTimeline;
100
+ // Contagion depth as proxy for evidence chain depth (normalized)
101
+ // In science: deeper propagation means findings pass through more validation layers
102
+ const depthScore = Math.min(1, state.contagionDepth / 5);
103
+ // Low amplification = findings stand on evidence, not popularity
104
+ const evidenceVsPopularity = Math.max(0, 1 - (state.amplification - 0.5));
105
+ // Temporal depth: how many rounds did findings persist stably?
106
+ let stableRounds = 0;
107
+ for (let i = 1; i < timeline.length; i++) {
108
+ const delta = Math.abs(timeline[i].trust - timeline[i - 1].trust);
109
+ if (delta < 0.05)
110
+ stableRounds++;
111
+ }
112
+ const temporalDepth = timeline.length > 1
113
+ ? stableRounds / (timeline.length - 1)
114
+ : 0.5;
115
+ return (depthScore * 0.35 +
116
+ evidenceVsPopularity * 0.3 +
117
+ temporalDepth * 0.35);
118
+ }
119
+ /**
120
+ * Extract compute efficiency.
121
+ *
122
+ * Efficient discovery:
123
+ * - Not too many governance interventions (focused paths)
124
+ * - Good block rate (filtering noise early, not late)
125
+ * - Low variance in impact (agents working in coordination, not chaos)
126
+ */
127
+ function extractComputeEfficiency(result) {
128
+ const ag = result.actionGovernance;
129
+ const dg = result.dynamicsGovernance;
130
+ // Block rate: some blocking is efficient (filtering noise), too much is wasteful
131
+ const blockRate = ag.totalEvaluations > 0 ? ag.blocked / ag.totalEvaluations : 0;
132
+ let filterEfficiency;
133
+ if (blockRate < 0.1)
134
+ filterEfficiency = 0.4; // too permissive — noise gets through
135
+ else if (blockRate < 0.3)
136
+ filterEfficiency = 0.9; // sweet spot
137
+ else if (blockRate < 0.5)
138
+ filterEfficiency = 0.7; // slightly aggressive
139
+ else
140
+ filterEfficiency = 0.3; // over-filtering — blocking productive work
141
+ // Intervention density: interventions per round
142
+ // Some interventions = course correcting (good)
143
+ // Too many = system is fundamentally unstable
144
+ const interventionDensity = dg.totalRounds > 0
145
+ ? dg.totalInterventions / dg.totalRounds
146
+ : 0;
147
+ const interventionScore = interventionDensity <= 2
148
+ ? 0.8 + interventionDensity * 0.1
149
+ : Math.max(0.2, 1 - (interventionDensity - 2) * 0.15);
150
+ // Impact consistency: low variance in final reactions = coordinated work
151
+ const rounds = result.rounds;
152
+ if (rounds.length === 0)
153
+ return 0.5;
154
+ const lastRound = rounds[rounds.length - 1];
155
+ const impacts = lastRound.finalReactions.map(r => r.impact);
156
+ const mean = impacts.reduce((s, i) => s + i, 0) / impacts.length;
157
+ const variance = impacts.reduce((s, i) => s + (i - mean) ** 2, 0) / impacts.length;
158
+ const coordinationScore = Math.max(0, 1 - variance * 3);
159
+ return (filterEfficiency * 0.35 +
160
+ interventionScore * 0.3 +
161
+ coordinationScore * 0.35);
162
+ }
163
+ /**
164
+ * Extract false positive rate (inverted — higher returned value = fewer false positives = better).
165
+ *
166
+ * False positives in science:
167
+ * - High cascade risk = bad results propagating through citation chains
168
+ * - High amplification = popular but wrong findings being boosted
169
+ * - Low trust = findings can't be reproduced
170
+ * - High outrage = publication pressure creating rushed claims
171
+ */
172
+ function extractFalsePositiveRate(result) {
173
+ const state = result.finalState;
174
+ const dg = result.dynamicsGovernance;
175
+ // Low cascade risk = bad results caught before spreading
176
+ const cascadeControl = 1 - state.cascadeRisk;
177
+ // Low amplification = not amplifying unvalidated findings
178
+ const amplificationControl = Math.max(0, 1 - (state.amplification - 0.5) * 2);
179
+ // High trust = reproducible findings
180
+ const trustScore = state.trust;
181
+ // Cascade breakers fired = system caught and stopped false positives
182
+ const breakerBonus = dg.cascadeBreakers > 0 ? 0.1 : 0;
183
+ // Low publication pressure
184
+ const pressureScore = 1 - state.outrage;
185
+ const raw = (cascadeControl * 0.3 +
186
+ amplificationControl * 0.2 +
187
+ trustScore * 0.25 +
188
+ pressureScore * 0.15 +
189
+ breakerBonus);
190
+ return Math.min(1, raw + 0.1); // slight bias toward positive — governance is working
191
+ }
192
+ // ============================================
193
+ // EXPORTED SCIENCE METRICS
194
+ // ============================================
195
+ /**
196
+ * Science evaluation metrics — plug directly into scenarioComparison.ts.
197
+ *
198
+ * Usage:
199
+ * import { SCIENCE_METRICS } from "./metrics/science.metrics"
200
+ * const result = await runScenarioMatrix({
201
+ * ...config,
202
+ * evaluationMetrics: SCIENCE_METRICS,
203
+ * })
204
+ */
205
+ exports.SCIENCE_METRICS = [
206
+ {
207
+ id: "convergence_quality",
208
+ label: "Convergence Quality",
209
+ weight: 0.25,
210
+ extractor: extractConvergenceQuality,
211
+ },
212
+ {
213
+ id: "reproducibility",
214
+ label: "Reproducibility Score",
215
+ weight: 0.25,
216
+ extractor: extractReproducibilityScore,
217
+ },
218
+ {
219
+ id: "provenance_depth",
220
+ label: "Provenance Depth",
221
+ weight: 0.20,
222
+ extractor: extractProvenanceDepth,
223
+ },
224
+ {
225
+ id: "compute_efficiency",
226
+ label: "Compute Efficiency",
227
+ weight: 0.15,
228
+ extractor: extractComputeEfficiency,
229
+ },
230
+ {
231
+ id: "false_positive_control",
232
+ label: "False Positive Control",
233
+ weight: 0.15,
234
+ extractor: extractFalsePositiveRate,
235
+ },
236
+ ];
237
+ // ============================================
238
+ // SCIENCE-SPECIFIC DYNAMICS RULES (policy text)
239
+ // ============================================
240
+ /**
241
+ * Default policy text for scientific discovery governance.
242
+ * These map to dynamics rules in governDynamics():
243
+ * - propagation rules → hypothesis spread control
244
+ * - amplification rules → citation amplification dampening
245
+ * - cascade rules → false positive cascade breaking
246
+ * - trust rules → reproducibility enforcement
247
+ * - feedback rules → publication pressure dampening
248
+ */
249
+ exports.SCIENCE_POLICY_TEXT = [
250
+ // Propagation control — limit hypothesis spread without evidence
251
+ "Limit propagation of causal claims that lack multi-source evidence",
252
+ "Contain unvalidated hypotheses within originating research group",
253
+ "Quarantine findings that have not passed independent reproduction",
254
+ // Amplification dampening — prevent citation echo chambers
255
+ "Dampen amplification of self-citation loops exceeding 3 generations",
256
+ "Limit influence of popular findings that lack independent validation",
257
+ "Reduce visibility of papers with high citation velocity but low reproduction rate",
258
+ // Cascade breaking — stop false positives from compounding
259
+ "Circuit break when cascade of dependent findings exceeds validation capacity",
260
+ "Halt chain reaction of derivative conclusions from unvalidated premises",
261
+ "Break feedback loops between competing research groups amplifying each other",
262
+ // Trust / reproducibility enforcement
263
+ "Boost visibility of independently reproduced findings",
264
+ "Require transparency in methodology for all published artifacts",
265
+ "Prioritize credibility of findings with transparent provenance chains",
266
+ // Publication pressure dampening
267
+ "Dampen rush-to-publish behavior during high-competition periods",
268
+ "Cool down reactive publication patterns when controversy index rises",
269
+ "Stabilize publication rate during peer review bottlenecks",
270
+ // Compute governance
271
+ "Pause redundant investigation paths when convergence detected",
272
+ "Halt compute-intensive explorations that show no evidence of progress",
273
+ ].join("\n");
274
+ // ============================================
275
+ // SCIENCE STATE INITIALIZATION
276
+ // ============================================
277
+ /**
278
+ * Initial system state tuned for scientific discovery.
279
+ *
280
+ * Differences from behavior simulation:
281
+ * - Higher trust baseline (science starts from credibility)
282
+ * - Lower outrage (publication pressure starts manageable)
283
+ * - Lower amplification (citations start organic)
284
+ * - Moderate velocity (discovery is active but not frantic)
285
+ */
286
+ exports.SCIENCE_INITIAL_STATE = {
287
+ polarization: 0.15, // Some hypothesis diversity (healthy)
288
+ outrage: 0.05, // Low publication pressure initially
289
+ trust: 0.8, // Science starts with high credibility
290
+ informationVelocity: 0.4, // Active discovery pace
291
+ amplification: 0.6, // Organic citation patterns
292
+ cascadeRisk: 0.05, // Low false positive risk initially
293
+ contagionDepth: 3, // Moderate evidence chain depth
294
+ coolingPeriod: 0,
295
+ };
296
+ // ============================================
297
+ // SCIENCE STATE INTERPRETER
298
+ // ============================================
299
+ /**
300
+ * Interpret base SystemState through a science lens.
301
+ * Maps generic governance metrics to science-specific language.
302
+ */
303
+ function interpretScienceState(state) {
304
+ const fragLevel = state.polarization > 0.6 ? "critical" : state.polarization > 0.3 ? "elevated" : "healthy";
305
+ const pressureLevel = state.outrage > 0.5 ? "dangerous" : state.outrage > 0.2 ? "elevated" : "normal";
306
+ const reproLevel = state.trust > 0.7 ? "high" : state.trust > 0.4 ? "moderate" : "crisis";
307
+ const citationLevel = state.amplification > 1.5 ? "echo chamber" : state.amplification > 0.8 ? "amplified" : "organic";
308
+ const fpRisk = state.cascadeRisk > 0.5 ? "high" : state.cascadeRisk > 0.2 ? "moderate" : "controlled";
309
+ const velocity = state.informationVelocity > 0.7 ? "frantic" : state.informationVelocity > 0.3 ? "active" : "stalled";
310
+ let overall;
311
+ if (state.trust > 0.6 && state.cascadeRisk < 0.3 && state.polarization < 0.4) {
312
+ overall = "Healthy discovery — findings are converging with evidence support";
313
+ }
314
+ else if (state.cascadeRisk > 0.6) {
315
+ overall = "False positive cascade risk — unvalidated findings propagating through citations";
316
+ }
317
+ else if (state.polarization > 0.6) {
318
+ overall = "Field fragmentation — competing hypotheses without resolution mechanism";
319
+ }
320
+ else if (state.trust < 0.3) {
321
+ overall = "Reproducibility crisis — institutional credibility collapsing";
322
+ }
323
+ else {
324
+ overall = "Active investigation — governance maintaining discovery quality";
325
+ }
326
+ return {
327
+ hypothesisFragmentation: `${fragLevel} (${(state.polarization * 100).toFixed(0)}%)`,
328
+ publicationPressure: `${pressureLevel} (${(state.outrage * 100).toFixed(0)}%)`,
329
+ reproducibilityConfidence: `${reproLevel} (${(state.trust * 100).toFixed(0)}%)`,
330
+ citationHealth: `${citationLevel} (${state.amplification.toFixed(2)}x)`,
331
+ falsePositiveRisk: `${fpRisk} (${(state.cascadeRisk * 100).toFixed(0)}%)`,
332
+ discoveryVelocity: `${velocity} (${(state.informationVelocity * 100).toFixed(0)}%)`,
333
+ overallAssessment: overall,
334
+ };
335
+ }