@agent-e/core 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -360,6 +360,7 @@ declare class Observer {
360
360
 
361
361
  declare class Simulator {
362
362
  private diagnoser;
363
+ private beforeViolationsCache;
363
364
  /**
364
365
  * Simulate the effect of applying `action` to the current economy forward `forwardTicks`.
365
366
  * Runs `iterations` Monte Carlo trials and returns the outcome distribution.
package/dist/index.d.ts CHANGED
@@ -360,6 +360,7 @@ declare class Observer {
360
360
 
361
361
  declare class Simulator {
362
362
  private diagnoser;
363
+ private beforeViolationsCache;
363
364
  /**
364
365
  * Simulate the effect of applying `action` to the current economy forward `forwardTicks`.
365
366
  * Runs `iterations` Monte Carlo trials and returns the outcome distribution.
package/dist/index.js CHANGED
@@ -203,14 +203,38 @@ var Observer = class {
203
203
  const balances = Object.values(state.agentBalances);
204
204
  const roles = Object.values(state.agentRoles);
205
205
  const totalAgents = balances.length;
206
+ let faucetVolume = 0;
207
+ let sinkVolume = 0;
208
+ const tradeEvents = [];
209
+ const roleChangeEvents = [];
210
+ let churnCount = 0;
211
+ for (const e of recentEvents) {
212
+ switch (e.type) {
213
+ case "mint":
214
+ case "spawn":
215
+ faucetVolume += e.amount ?? 0;
216
+ break;
217
+ case "burn":
218
+ case "consume":
219
+ sinkVolume += e.amount ?? 0;
220
+ break;
221
+ case "trade":
222
+ tradeEvents.push(e);
223
+ break;
224
+ case "churn":
225
+ churnCount++;
226
+ roleChangeEvents.push(e);
227
+ break;
228
+ case "role_change":
229
+ roleChangeEvents.push(e);
230
+ break;
231
+ }
232
+ }
206
233
  const totalSupply = balances.reduce((s, b) => s + b, 0);
207
- const faucetVolume = recentEvents.filter((e) => e.type === "mint" || e.type === "spawn").reduce((s, e) => s + (e.amount ?? 0), 0);
208
- const sinkVolume = recentEvents.filter((e) => e.type === "burn" || e.type === "consume").reduce((s, e) => s + (e.amount ?? 0), 0);
209
234
  const netFlow = faucetVolume - sinkVolume;
210
235
  const tapSinkRatio = sinkVolume > 0 ? faucetVolume / sinkVolume : faucetVolume > 0 ? Infinity : 1;
211
236
  const prevSupply = this.previousMetrics?.totalSupply ?? totalSupply;
212
237
  const inflationRate = prevSupply > 0 ? (totalSupply - prevSupply) / prevSupply : 0;
213
- const tradeEvents = recentEvents.filter((e) => e.type === "trade");
214
238
  const velocity = totalSupply > 0 ? tradeEvents.length / totalSupply : 0;
215
239
  const sortedBalances = [...balances].sort((a, b) => a - b);
216
240
  const meanBalance = totalAgents > 0 ? totalSupply / totalAgents : 0;
@@ -229,12 +253,10 @@ var Observer = class {
229
253
  roleShares[role] = count / Math.max(1, totalAgents);
230
254
  }
231
255
  const churnByRole = {};
232
- const roleChanges = recentEvents.filter((e) => e.type === "churn" || e.type === "role_change");
233
- for (const e of roleChanges) {
256
+ for (const e of roleChangeEvents) {
234
257
  const role = e.role ?? "unknown";
235
258
  churnByRole[role] = (churnByRole[role] ?? 0) + 1;
236
259
  }
237
- const churnCount = recentEvents.filter((e) => e.type === "churn").length;
238
260
  const churnRate = churnCount / Math.max(1, totalAgents);
239
261
  const prices = { ...state.marketPrices };
240
262
  const priceVolatility = {};
@@ -297,7 +319,8 @@ var Observer = class {
297
319
  for (let j = i + 1; j < priceKeys.length; j++) {
298
320
  const pA = prices[priceKeys[i]];
299
321
  const pB = prices[priceKeys[j]];
300
- const ratio = pA / pB;
322
+ let ratio = pA / pB;
323
+ ratio = Math.max(1e-3, Math.min(1e3, ratio));
301
324
  totalDivergence += Math.abs(Math.log(ratio));
302
325
  pairCount++;
303
326
  }
@@ -1666,7 +1689,7 @@ var P57_CombinatorialPriceSpace = {
1666
1689
  magnitude: 0.1,
1667
1690
  reasoning: `Only ${(convergenceRate * 100).toFixed(0)}% of ${relativePriceCount} relative prices have converged (target: ${(thresholds.relativePriceConvergenceTarget * 100).toFixed(0)}%). Price space too complex for distributed discovery. Lower friction to help.`
1668
1691
  },
1669
- confidence: 0.6,
1692
+ confidence: 0.55,
1670
1693
  estimatedLag: thresholds.priceDiscoveryWindowTicks
1671
1694
  };
1672
1695
  }
@@ -1752,7 +1775,7 @@ var P55_ArbitrageThermometer = {
1752
1775
  magnitude: 0.15,
1753
1776
  reasoning: `Arbitrage index ${arbitrageIndex.toFixed(2)} exceeds critical threshold (${thresholds.arbitrageIndexCritical}). Relative prices are diverging \u2014 economy destabilizing. Lower trading friction to accelerate price convergence.`
1754
1777
  },
1755
- confidence: 0.8,
1778
+ confidence: 0.75,
1756
1779
  estimatedLag: 8
1757
1780
  };
1758
1781
  }
@@ -2499,7 +2522,7 @@ var P56_ContentDropShock = {
2499
2522
  magnitude: 0.1,
2500
2523
  reasoning: `Content drop ${contentDropAge} ticks ago \u2014 arbitrage at ${arbitrageIndex.toFixed(2)} exceeds post-drop max (${thresholds.postDropArbitrageMax}). Price discovery struggling. Lower trading friction temporarily.`
2501
2524
  },
2502
- confidence: 0.7,
2525
+ confidence: 0.6,
2503
2526
  estimatedLag: 5
2504
2527
  };
2505
2528
  }
@@ -2553,6 +2576,7 @@ var ALL_PRINCIPLES = [
2553
2576
  var Simulator = class {
2554
2577
  constructor() {
2555
2578
  this.diagnoser = new Diagnoser(ALL_PRINCIPLES);
2579
+ this.beforeViolationsCache = /* @__PURE__ */ new Map();
2556
2580
  }
2557
2581
  /**
2558
2582
  * Simulate the effect of applying `action` to the current economy forward `forwardTicks`.
@@ -2575,9 +2599,14 @@ var Simulator = class {
2575
2599
  const p90 = sorted[Math.floor(actualIterations * 0.9)] ?? emptyMetrics();
2576
2600
  const mean = this.averageMetrics(outcomes);
2577
2601
  const netImprovement = this.checkImprovement(currentMetrics, p50, action);
2578
- const beforeViolations = new Set(
2579
- this.diagnoser.diagnose(currentMetrics, thresholds).map((d) => d.principle.id)
2580
- );
2602
+ const tick = currentMetrics.tick;
2603
+ let beforeViolations = this.beforeViolationsCache.get(tick);
2604
+ if (!beforeViolations) {
2605
+ beforeViolations = new Set(
2606
+ this.diagnoser.diagnose(currentMetrics, thresholds).map((d) => d.principle.id)
2607
+ );
2608
+ this.beforeViolationsCache.set(tick, beforeViolations);
2609
+ }
2581
2610
  const afterViolations = new Set(
2582
2611
  this.diagnoser.diagnose(p50, thresholds).map((d) => d.principle.id)
2583
2612
  );