@wrongstack/core 0.291.2 → 0.292.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.
Files changed (136) hide show
  1. package/dist/coordination/director-tools.d.ts.map +1 -1
  2. package/dist/coordination/index.d.ts +1 -1
  3. package/dist/coordination/index.d.ts.map +1 -1
  4. package/dist/coordination/index.js +276 -152
  5. package/dist/coordination/index.js.map +4 -4
  6. package/dist/coordination/mailbox-http-router.d.ts +38 -0
  7. package/dist/coordination/mailbox-http-router.d.ts.map +1 -1
  8. package/dist/coordination/provider-status-tracker.d.ts.map +1 -1
  9. package/dist/core/agent-loop.d.ts.map +1 -1
  10. package/dist/core/agent-response.d.ts.map +1 -1
  11. package/dist/core/context.d.ts +10 -0
  12. package/dist/core/context.d.ts.map +1 -1
  13. package/dist/core/fallback-model.d.ts.map +1 -1
  14. package/dist/core/system-prompt-builder.d.ts +20 -1
  15. package/dist/core/system-prompt-builder.d.ts.map +1 -1
  16. package/dist/defaults/index.d.ts +1 -0
  17. package/dist/defaults/index.d.ts.map +1 -1
  18. package/dist/defaults/index.js +3137 -2441
  19. package/dist/defaults/index.js.map +4 -4
  20. package/dist/execution/auto-compaction-middleware.d.ts +34 -2
  21. package/dist/execution/auto-compaction-middleware.d.ts.map +1 -1
  22. package/dist/execution/compaction-core.d.ts +59 -0
  23. package/dist/execution/compaction-core.d.ts.map +1 -1
  24. package/dist/execution/compactor.d.ts.map +1 -1
  25. package/dist/execution/error-handler.d.ts +7 -0
  26. package/dist/execution/error-handler.d.ts.map +1 -1
  27. package/dist/execution/index.d.ts +1 -0
  28. package/dist/execution/index.d.ts.map +1 -1
  29. package/dist/execution/index.js +4684 -3924
  30. package/dist/execution/index.js.map +4 -4
  31. package/dist/execution/intelligent-compactor.d.ts.map +1 -1
  32. package/dist/execution/model-runtime.d.ts.map +1 -1
  33. package/dist/execution/one-shot-llm.d.ts.map +1 -1
  34. package/dist/execution/selective-compactor.d.ts +10 -0
  35. package/dist/execution/selective-compactor.d.ts.map +1 -1
  36. package/dist/execution/subagent-compaction.d.ts +24 -0
  37. package/dist/execution/subagent-compaction.d.ts.map +1 -0
  38. package/dist/hq/alerts.d.ts +5 -0
  39. package/dist/hq/alerts.d.ts.map +1 -1
  40. package/dist/hq/auth-audit.d.ts +115 -0
  41. package/dist/hq/auth-audit.d.ts.map +1 -0
  42. package/dist/hq/auth-store.d.ts +98 -2
  43. package/dist/hq/auth-store.d.ts.map +1 -1
  44. package/dist/hq/brain-bridge.d.ts +2 -8
  45. package/dist/hq/brain-bridge.d.ts.map +1 -1
  46. package/dist/hq/bridge-context.d.ts +74 -0
  47. package/dist/hq/bridge-context.d.ts.map +1 -0
  48. package/dist/hq/cost-bridge.d.ts +4 -10
  49. package/dist/hq/cost-bridge.d.ts.map +1 -1
  50. package/dist/hq/fleet-bridge.d.ts +2 -8
  51. package/dist/hq/fleet-bridge.d.ts.map +1 -1
  52. package/dist/hq/index.d.ts +2 -0
  53. package/dist/hq/index.d.ts.map +1 -1
  54. package/dist/hq/index.js +358 -222
  55. package/dist/hq/index.js.map +4 -4
  56. package/dist/hq/protocol/session.d.ts +13 -0
  57. package/dist/hq/protocol/session.d.ts.map +1 -1
  58. package/dist/hq/tool-bridge.d.ts +2 -8
  59. package/dist/hq/tool-bridge.d.ts.map +1 -1
  60. package/dist/hq/worktree-bridge.d.ts +2 -8
  61. package/dist/hq/worktree-bridge.d.ts.map +1 -1
  62. package/dist/index.d.ts +4 -2
  63. package/dist/index.d.ts.map +1 -1
  64. package/dist/index.js +6332 -4853
  65. package/dist/index.js.map +4 -4
  66. package/dist/infrastructure/index.js +32 -15
  67. package/dist/infrastructure/index.js.map +2 -2
  68. package/dist/infrastructure/provider-cache-ledger.d.ts +48 -0
  69. package/dist/infrastructure/provider-cache-ledger.d.ts.map +1 -0
  70. package/dist/infrastructure/token-counter.d.ts +4 -2
  71. package/dist/infrastructure/token-counter.d.ts.map +1 -1
  72. package/dist/kernel/events/brain-events.d.ts +2 -0
  73. package/dist/kernel/events/brain-events.d.ts.map +1 -1
  74. package/dist/kernel/events/memory-events.d.ts +102 -0
  75. package/dist/kernel/events/memory-events.d.ts.map +1 -1
  76. package/dist/kernel/events/session-events.d.ts +35 -0
  77. package/dist/kernel/events/session-events.d.ts.map +1 -1
  78. package/dist/models/index.js +161 -78
  79. package/dist/models/index.js.map +3 -3
  80. package/dist/models/llm-selector.d.ts.map +1 -1
  81. package/dist/notifications/index.d.ts +40 -0
  82. package/dist/notifications/index.d.ts.map +1 -0
  83. package/dist/notifications/notifier-impl.d.ts +34 -0
  84. package/dist/notifications/notifier-impl.d.ts.map +1 -0
  85. package/dist/notifications/notifier.d.ts +95 -0
  86. package/dist/notifications/notifier.d.ts.map +1 -0
  87. package/dist/notifications/types.d.ts +111 -0
  88. package/dist/notifications/types.d.ts.map +1 -0
  89. package/dist/plugin/api.d.ts +10 -1
  90. package/dist/plugin/api.d.ts.map +1 -1
  91. package/dist/registry/provider-registry.d.ts +1 -1
  92. package/dist/registry/provider-registry.d.ts.map +1 -1
  93. package/dist/security/index.js +15 -15
  94. package/dist/security/index.js.map +3 -3
  95. package/dist/skills/index.js +80 -80
  96. package/dist/skills/index.js.map +3 -3
  97. package/dist/storage/config-loader.d.ts +3 -5
  98. package/dist/storage/config-loader.d.ts.map +1 -1
  99. package/dist/storage/index.js +325 -259
  100. package/dist/storage/index.js.map +4 -4
  101. package/dist/storage/memory-consolidator.d.ts +14 -2
  102. package/dist/storage/memory-consolidator.d.ts.map +1 -1
  103. package/dist/storage/queue-store.d.ts +2 -0
  104. package/dist/storage/queue-store.d.ts.map +1 -1
  105. package/dist/tools/index.js +14 -7
  106. package/dist/tools/index.js.map +3 -3
  107. package/dist/tools/mcp-control.d.ts +1 -1
  108. package/dist/types/config.d.ts +64 -20
  109. package/dist/types/config.d.ts.map +1 -1
  110. package/dist/types/index.js +65 -35
  111. package/dist/types/index.js.map +3 -3
  112. package/dist/types/plugin.d.ts +11 -0
  113. package/dist/types/plugin.d.ts.map +1 -1
  114. package/dist/types/provider.d.ts +31 -0
  115. package/dist/types/provider.d.ts.map +1 -1
  116. package/dist/types/token-counter.d.ts +8 -1
  117. package/dist/types/token-counter.d.ts.map +1 -1
  118. package/dist/utils/cache-key.d.ts +19 -0
  119. package/dist/utils/cache-key.d.ts.map +1 -0
  120. package/dist/utils/compaction-preview.d.ts +8 -0
  121. package/dist/utils/compaction-preview.d.ts.map +1 -0
  122. package/dist/utils/connectivity.d.ts +36 -0
  123. package/dist/utils/connectivity.d.ts.map +1 -0
  124. package/dist/utils/context-breakdown.d.ts +59 -0
  125. package/dist/utils/context-breakdown.d.ts.map +1 -0
  126. package/dist/utils/context-evidence.d.ts +22 -0
  127. package/dist/utils/context-evidence.d.ts.map +1 -1
  128. package/dist/utils/index.d.ts +3 -0
  129. package/dist/utils/index.d.ts.map +1 -1
  130. package/dist/utils/index.js +1761 -1541
  131. package/dist/utils/index.js.map +4 -4
  132. package/dist/utils/token-estimate.d.ts +27 -0
  133. package/dist/utils/token-estimate.d.ts.map +1 -1
  134. package/instructions/llm/memory-consolidator.md +19 -3
  135. package/instructions/system.md +10 -2
  136. package/package.json +2 -2
@@ -330,6 +330,7 @@ var DefaultTokenCounter = class {
330
330
  cacheWrite = 0;
331
331
  costInput = 0;
332
332
  costOutput = 0;
333
+ cacheSaved = 0;
333
334
  registry;
334
335
  providerId;
335
336
  events;
@@ -348,7 +349,7 @@ var DefaultTokenCounter = class {
348
349
  setSessionId(sessionId) {
349
350
  this.sessionId = sessionId;
350
351
  }
351
- account(usage, model) {
352
+ account(usage, model, providerId = this.currentProviderId()) {
352
353
  const eventSessionId = this.currentSessionId();
353
354
  this.input += usage.input;
354
355
  this.output += usage.output;
@@ -357,35 +358,36 @@ var DefaultTokenCounter = class {
357
358
  this.lastInput = usage.input;
358
359
  this.lastCacheRead = usage.cacheRead ?? 0;
359
360
  this.lastCacheWrite = usage.cacheWrite ?? 0;
360
- const price = model ? this.priceCache.get(model) : void 0;
361
+ const priceKey = providerId && model ? `${providerId}\0${model}` : void 0;
362
+ const price = priceKey ? this.priceCache.get(priceKey) : void 0;
361
363
  if (price) {
362
364
  this.applyPrice(usage, price);
363
- this.emitAccounted(eventSessionId, model);
365
+ this.emitAccounted(eventSessionId, model, providerId, usage);
364
366
  return;
365
367
  }
366
- if (this.registry && this.providerId && model) {
368
+ if (this.registry && providerId && model) {
367
369
  if (this.priceCache.size >= PRICE_CACHE_MAX_SIZE) {
368
370
  const keys = [...this.priceCache.keys()];
369
371
  this.priceCache.delete(keys[0] ?? "");
370
372
  }
371
- void this.registry.getModel(this.providerId, model).then((m) => {
373
+ void this.registry.getModel(providerId, model).then((m) => {
372
374
  if (m) {
373
375
  const p = priceFromModel(m);
374
- this.priceCache.set(model, p);
376
+ this.priceCache.set(priceKey, p);
375
377
  this.applyPrice(usage, p);
376
378
  }
377
- this.emitAccounted(eventSessionId, model);
379
+ this.emitAccounted(eventSessionId, model, providerId, usage);
378
380
  }).catch(() => {
379
381
  this.events?.emit("token.cost_estimate_unavailable", {
380
382
  ...eventSessionId ? { sessionId: eventSessionId } : {},
381
383
  model: model ?? "<unknown>"
382
384
  });
383
- this.emitAccounted(eventSessionId, model);
385
+ this.emitAccounted(eventSessionId, model, providerId, usage);
384
386
  return void 0;
385
387
  });
386
388
  return;
387
389
  }
388
- this.emitAccounted(eventSessionId, model);
390
+ this.emitAccounted(eventSessionId, model, providerId, usage);
389
391
  }
390
392
  /** Synchronous variant for code paths that have already resolved the model. */
391
393
  accountWithModel(usage, resolved) {
@@ -402,9 +404,9 @@ var DefaultTokenCounter = class {
402
404
  const keys = [...this.priceCache.keys()];
403
405
  this.priceCache.delete(keys[0] ?? "");
404
406
  }
405
- this.priceCache.set(resolved.modelId, price);
407
+ this.priceCache.set(`${resolved.providerId}\0${resolved.modelId}`, price);
406
408
  this.applyPrice(usage, price);
407
- this.emitAccounted(eventSessionId, resolved.modelId);
409
+ this.emitAccounted(eventSessionId, resolved.modelId, resolved.providerId, usage);
408
410
  }
409
411
  total() {
410
412
  return {
@@ -435,19 +437,21 @@ var DefaultTokenCounter = class {
435
437
  return {
436
438
  readTokens: this.cacheRead,
437
439
  writeTokens: this.cacheWrite,
438
- hitRatio: denom === 0 ? 0 : this.cacheRead / denom
440
+ hitRatio: denom === 0 ? 0 : this.cacheRead / denom,
441
+ savedUsd: round4(this.cacheSaved)
439
442
  };
440
443
  }
441
444
  /** Invalidate cached prices so the next account() call fetches fresh data. */
442
445
  invalidateCache() {
443
446
  this.priceCache.clear();
444
447
  }
445
- emitAccounted(sessionId = this.currentSessionId(), model) {
448
+ emitAccounted(sessionId = this.currentSessionId(), model, providerId = this.currentProviderId(), deltaUsage) {
446
449
  this.events?.emit("token.accounted", {
447
450
  ...sessionId ? { sessionId } : {},
448
451
  usage: this.total(),
452
+ ...deltaUsage ? { deltaUsage: { ...deltaUsage } } : {},
449
453
  cost: { input: this.costInput, output: this.costOutput, total: this.costInput + this.costOutput },
450
- ...this.providerId ? { provider: this.providerId } : {},
454
+ ...providerId ? { provider: providerId } : {},
451
455
  ...model ? { model } : {}
452
456
  });
453
457
  }
@@ -455,6 +459,10 @@ var DefaultTokenCounter = class {
455
459
  const value = typeof this.sessionId === "function" ? this.sessionId() : this.sessionId;
456
460
  return typeof value === "string" && value.length > 0 ? value : void 0;
457
461
  }
462
+ currentProviderId() {
463
+ const value = typeof this.providerId === "function" ? this.providerId() : this.providerId;
464
+ return typeof value === "string" && value.length > 0 ? value : void 0;
465
+ }
458
466
  reset() {
459
467
  this.input = 0;
460
468
  this.output = 0;
@@ -462,10 +470,16 @@ var DefaultTokenCounter = class {
462
470
  this.cacheWrite = 0;
463
471
  this.costInput = 0;
464
472
  this.costOutput = 0;
473
+ this.cacheSaved = 0;
465
474
  this.lastInput = 0;
466
475
  this.lastCacheRead = 0;
467
476
  this.lastCacheWrite = 0;
468
- this.emitAccounted();
477
+ this.emitAccounted(void 0, void 0, void 0, {
478
+ input: 0,
479
+ output: 0,
480
+ cacheRead: 0,
481
+ cacheWrite: 0
482
+ });
469
483
  }
470
484
  applyPrice(usage, price) {
471
485
  if (price.input) this.costInput += usage.input / 1e6 * price.input;
@@ -473,6 +487,9 @@ var DefaultTokenCounter = class {
473
487
  if (usage.cacheRead && price.cacheRead) {
474
488
  this.costInput += usage.cacheRead / 1e6 * price.cacheRead;
475
489
  }
490
+ if (usage.cacheRead && price.input !== void 0) {
491
+ this.cacheSaved += usage.cacheRead / 1e6 * (price.input - (price.cacheRead ?? 0));
492
+ }
476
493
  const hasCacheWriteSplit = usage.cacheWrite5m !== void 0 || usage.cacheWrite1h !== void 0;
477
494
  const cacheWrite5m = usage.cacheWrite5m ?? (hasCacheWriteSplit ? 0 : usage.cacheWrite);
478
495
  const cacheWrite1h = usage.cacheWrite1h ?? 0;