@wrongstack/core 0.291.1 → 0.292.0
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/coordination/director-tools.d.ts.map +1 -1
- package/dist/coordination/index.js +113 -113
- package/dist/coordination/index.js.map +3 -3
- package/dist/core/agent-loop.d.ts.map +1 -1
- package/dist/core/agent-response.d.ts.map +1 -1
- package/dist/core/context.d.ts +10 -0
- package/dist/core/context.d.ts.map +1 -1
- package/dist/core/system-prompt-builder.d.ts +20 -1
- package/dist/core/system-prompt-builder.d.ts.map +1 -1
- package/dist/defaults/index.d.ts +1 -0
- package/dist/defaults/index.d.ts.map +1 -1
- package/dist/defaults/index.js +3132 -2440
- package/dist/defaults/index.js.map +4 -4
- package/dist/execution/auto-compaction-middleware.d.ts +34 -2
- package/dist/execution/auto-compaction-middleware.d.ts.map +1 -1
- package/dist/execution/compaction-core.d.ts +59 -0
- package/dist/execution/compaction-core.d.ts.map +1 -1
- package/dist/execution/compactor.d.ts.map +1 -1
- package/dist/execution/error-handler.d.ts +7 -0
- package/dist/execution/error-handler.d.ts.map +1 -1
- package/dist/execution/index.d.ts +1 -0
- package/dist/execution/index.d.ts.map +1 -1
- package/dist/execution/index.js +4677 -3924
- package/dist/execution/index.js.map +4 -4
- package/dist/execution/intelligent-compactor.d.ts.map +1 -1
- package/dist/execution/model-runtime.d.ts.map +1 -1
- package/dist/execution/selective-compactor.d.ts +10 -0
- package/dist/execution/selective-compactor.d.ts.map +1 -1
- package/dist/execution/subagent-compaction.d.ts +24 -0
- package/dist/execution/subagent-compaction.d.ts.map +1 -0
- package/dist/hq/alerts.d.ts +5 -0
- package/dist/hq/alerts.d.ts.map +1 -1
- package/dist/hq/auth-audit.d.ts +115 -0
- package/dist/hq/auth-audit.d.ts.map +1 -0
- package/dist/hq/auth-store.d.ts +98 -2
- package/dist/hq/auth-store.d.ts.map +1 -1
- package/dist/hq/brain-bridge.d.ts +2 -8
- package/dist/hq/brain-bridge.d.ts.map +1 -1
- package/dist/hq/bridge-context.d.ts +74 -0
- package/dist/hq/bridge-context.d.ts.map +1 -0
- package/dist/hq/cost-bridge.d.ts +4 -10
- package/dist/hq/cost-bridge.d.ts.map +1 -1
- package/dist/hq/fleet-bridge.d.ts +2 -8
- package/dist/hq/fleet-bridge.d.ts.map +1 -1
- package/dist/hq/index.d.ts +2 -0
- package/dist/hq/index.d.ts.map +1 -1
- package/dist/hq/index.js +358 -222
- package/dist/hq/index.js.map +4 -4
- package/dist/hq/protocol/session.d.ts +13 -0
- package/dist/hq/protocol/session.d.ts.map +1 -1
- package/dist/hq/tool-bridge.d.ts +2 -8
- package/dist/hq/tool-bridge.d.ts.map +1 -1
- package/dist/hq/worktree-bridge.d.ts +2 -8
- package/dist/hq/worktree-bridge.d.ts.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6054 -4741
- package/dist/index.js.map +4 -4
- package/dist/infrastructure/index.js +32 -15
- package/dist/infrastructure/index.js.map +2 -2
- package/dist/infrastructure/provider-cache-ledger.d.ts +48 -0
- package/dist/infrastructure/provider-cache-ledger.d.ts.map +1 -0
- package/dist/infrastructure/token-counter.d.ts +4 -2
- package/dist/infrastructure/token-counter.d.ts.map +1 -1
- package/dist/kernel/events/brain-events.d.ts +2 -0
- package/dist/kernel/events/brain-events.d.ts.map +1 -1
- package/dist/kernel/events/memory-events.d.ts +102 -0
- package/dist/kernel/events/memory-events.d.ts.map +1 -1
- package/dist/kernel/events/session-events.d.ts +35 -0
- package/dist/kernel/events/session-events.d.ts.map +1 -1
- package/dist/models/index.js +161 -78
- package/dist/models/index.js.map +3 -3
- package/dist/models/llm-selector.d.ts.map +1 -1
- package/dist/notifications/index.d.ts +40 -0
- package/dist/notifications/index.d.ts.map +1 -0
- package/dist/notifications/notifier-impl.d.ts +34 -0
- package/dist/notifications/notifier-impl.d.ts.map +1 -0
- package/dist/notifications/notifier.d.ts +95 -0
- package/dist/notifications/notifier.d.ts.map +1 -0
- package/dist/notifications/types.d.ts +111 -0
- package/dist/notifications/types.d.ts.map +1 -0
- package/dist/plugin/api.d.ts +10 -1
- package/dist/plugin/api.d.ts.map +1 -1
- package/dist/registry/provider-registry.d.ts +1 -1
- package/dist/registry/provider-registry.d.ts.map +1 -1
- package/dist/security/index.js +15 -15
- package/dist/security/index.js.map +3 -3
- package/dist/skills/index.js +80 -80
- package/dist/skills/index.js.map +3 -3
- package/dist/storage/config-loader.d.ts +3 -5
- package/dist/storage/config-loader.d.ts.map +1 -1
- package/dist/storage/index.js +325 -259
- package/dist/storage/index.js.map +4 -4
- package/dist/storage/memory-consolidator.d.ts +14 -2
- package/dist/storage/memory-consolidator.d.ts.map +1 -1
- package/dist/storage/queue-store.d.ts +2 -0
- package/dist/storage/queue-store.d.ts.map +1 -1
- package/dist/tools/index.js +6 -6
- package/dist/tools/index.js.map +3 -3
- package/dist/tools/mcp-control.d.ts +1 -1
- package/dist/types/config.d.ts +64 -20
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/index.js +60 -34
- package/dist/types/index.js.map +3 -3
- package/dist/types/plugin.d.ts +11 -0
- package/dist/types/plugin.d.ts.map +1 -1
- package/dist/types/provider.d.ts +31 -0
- package/dist/types/provider.d.ts.map +1 -1
- package/dist/types/token-counter.d.ts +8 -1
- package/dist/types/token-counter.d.ts.map +1 -1
- package/dist/utils/cache-key.d.ts +19 -0
- package/dist/utils/cache-key.d.ts.map +1 -0
- package/dist/utils/compaction-preview.d.ts +8 -0
- package/dist/utils/compaction-preview.d.ts.map +1 -0
- package/dist/utils/context-breakdown.d.ts +59 -0
- package/dist/utils/context-breakdown.d.ts.map +1 -0
- package/dist/utils/context-evidence.d.ts +22 -0
- package/dist/utils/context-evidence.d.ts.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1730 -1543
- package/dist/utils/index.js.map +4 -4
- package/dist/utils/token-estimate.d.ts +27 -0
- package/dist/utils/token-estimate.d.ts.map +1 -1
- package/instructions/llm/memory-consolidator.md +19 -3
- package/instructions/system.md +10 -2
- 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
|
|
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 &&
|
|
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(
|
|
373
|
+
void this.registry.getModel(providerId, model).then((m) => {
|
|
372
374
|
if (m) {
|
|
373
375
|
const p = priceFromModel(m);
|
|
374
|
-
this.priceCache.set(
|
|
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
|
|
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
|
-
...
|
|
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;
|