blun-king-cli 9.1.282 → 9.1.284

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.
@@ -7,6 +7,7 @@ function finiteNonNegative(value) {
7
7
  function buildContextInsight(input = {}) {
8
8
  const projectedTokens = finiteNonNegative(input.projectedTokenCount);
9
9
  const maxTokens = finiteNonNegative(input.effectiveMaxContextTokens);
10
+ const systemPromptTokens = finiteNonNegative(input.systemPromptTokens);
10
11
  const conversationTokens = finiteNonNegative(input.conversationTokens);
11
12
  const toolSchemaTokens = finiteNonNegative(input.toolSchemaTokens);
12
13
  const compactionBudgetTokens = Math.min(
@@ -21,6 +22,7 @@ function buildContextInsight(input = {}) {
21
22
  return {
22
23
  projectedTokens,
23
24
  maxTokens,
25
+ systemPromptTokens,
24
26
  conversationTokens,
25
27
  toolSchemaTokens,
26
28
  compactionBudgetTokens,
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ const USAGE_FIELDS = [
4
+ 'inputOther',
5
+ 'output',
6
+ 'inputCacheRead',
7
+ 'inputCacheCreation',
8
+ ];
9
+
10
+ function safeTokenCount(value) {
11
+ return Number.isFinite(value) && value > 0 ? value : 0;
12
+ }
13
+
14
+ function buildSubagentUsageDelta(after, before) {
15
+ if (after === undefined || after === null || typeof after !== 'object') return null;
16
+ const baseline = before !== null && typeof before === 'object' ? before : {};
17
+ if (USAGE_FIELDS.some((field) => safeTokenCount(after[field]) < safeTokenCount(baseline[field]))) {
18
+ return null;
19
+ }
20
+ const delta = Object.fromEntries(USAGE_FIELDS.map((field) => [
21
+ field,
22
+ safeTokenCount(after[field]) - safeTokenCount(baseline[field]),
23
+ ]));
24
+ return USAGE_FIELDS.some((field) => delta[field] > 0) ? delta : null;
25
+ }
26
+
27
+ module.exports = {
28
+ buildSubagentUsageDelta,
29
+ };
package/blun.mjs CHANGED
@@ -75409,7 +75409,7 @@ var init_full = __esmMin((() => {
75409
75409
  }
75410
75410
  estimateProjectedRequestTokens(context = {}) {
75411
75411
  const messages = context.messages ?? this.agent.context.messages;
75412
- return this.estimateRequestTokens(context.additionalMessages === void 0 ? messages : [...messages, ...context.additionalMessages], context.systemPrompt ?? this.agent.config.systemPrompt, context.tools ?? this.agent.tools.loopTools);
75412
+ return this.estimateRequestTokens(context.additionalMessages === void 0 ? messages : [...messages, ...context.additionalMessages], context.systemPrompt ?? this.agent.effectiveSystemPrompt, context.tools ?? this.agent.tools.loopTools);
75413
75413
  }
75414
75414
  shouldRecoverFromContextOverflow(error) {
75415
75415
  return error instanceof APIContextOverflowError;
@@ -252106,7 +252106,7 @@ function shouldSuppressQueuedAttemptFailureEvent(options, error) {
252106
252106
  if (isProviderRateLimitError(error)) return true;
252107
252107
  return isAbortError$4(error) || options.signal.aborted;
252108
252108
  }
252109
- var DEFAULT_SUBAGENT_TIMEOUT_MS, resolveSubagentTimeoutMs, runAgentWithTimeoutContinuation, SUMMARY_MIN_LENGTH, SUMMARY_CONTINUATION_ATTEMPTS, HOOK_TEXT_PREVIEW_LENGTH, SUBAGENT_MAX_TOKENS_ERROR, TOOL_CALL_DISABLED_MESSAGE, SUBAGENT_PROMPT_ORIGIN, SIDE_QUESTION_SYSTEM_REMINDER, SessionSubagentHost;
252109
+ var DEFAULT_SUBAGENT_TIMEOUT_MS, resolveSubagentTimeoutMs, runAgentWithTimeoutContinuation, buildSubagentUsageDelta, SUMMARY_MIN_LENGTH, SUMMARY_CONTINUATION_ATTEMPTS, HOOK_TEXT_PREVIEW_LENGTH, SUBAGENT_MAX_TOKENS_ERROR, TOOL_CALL_DISABLED_MESSAGE, SUBAGENT_PROMPT_ORIGIN, SIDE_QUESTION_SYSTEM_REMINDER, SessionSubagentHost;
252110
252110
  var init_subagent_host = __esmMin((() => {
252111
252111
  init_src$4();
252112
252112
  init_errors$8();
@@ -252119,6 +252119,7 @@ var init_subagent_host = __esmMin((() => {
252119
252119
  init_subagent_batch();
252120
252120
  init_summary_continuation();
252121
252121
  ({ DEFAULT_SUBAGENT_TIMEOUT_MS, resolveSubagentTimeoutMs, runAgentWithTimeoutContinuation } = createRequire(import.meta.url)("./bin/subagent-timeout-policy.cjs"));
252122
+ ({ buildSubagentUsageDelta } = createRequire(import.meta.url)("./bin/subagent-usage-rollup-policy.cjs"));
252122
252123
  SUMMARY_MIN_LENGTH = 200;
252123
252124
  SUMMARY_CONTINUATION_ATTEMPTS = 1;
252124
252125
  HOOK_TEXT_PREVIEW_LENGTH = 500;
@@ -252177,7 +252178,7 @@ IMPORTANT:
252177
252178
  parentAgentId: this.ownerAgentId,
252178
252179
  swarmItem: options.swarmItem
252179
252180
  });
252180
- const completion = this.runWithActiveChild(id, options, async (runOptions) => {
252181
+ const completion = this.runWithTrackedChildUsage(parent, agent, id, options, async (runOptions) => {
252181
252182
  this.emitSubagentSpawned(parent, id, profile.name, runOptions);
252182
252183
  try {
252183
252184
  await this.configureChild(parent, agent, profile);
@@ -252201,7 +252202,7 @@ IMPORTANT:
252201
252202
  agentId,
252202
252203
  profileName,
252203
252204
  resumed: true,
252204
- completion: this.runWithActiveChild(agentId, options, async (runOptions) => {
252205
+ completion: this.runWithTrackedChildUsage(parent, child, agentId, options, async (runOptions) => {
252205
252206
  this.emitSubagentSpawned(parent, agentId, profileName, runOptions);
252206
252207
  try {
252207
252208
  child.config.update({
@@ -252239,7 +252240,7 @@ IMPORTANT:
252239
252240
  agentId,
252240
252241
  profileName,
252241
252242
  resumed: true,
252242
- completion: this.runWithActiveChild(agentId, options, async (runOptions) => {
252243
+ completion: this.runWithTrackedChildUsage(parent, child, agentId, options, async (runOptions) => {
252243
252244
  try {
252244
252245
  runOptions.signal.throwIfAborted();
252245
252246
  child.config.update({
@@ -252354,6 +252355,20 @@ IMPORTANT:
252354
252355
  this.activeChildren.delete(childId);
252355
252356
  });
252356
252357
  }
252358
+ async runWithTrackedChildUsage(parent, child, childId, options, run) {
252359
+ const usageBefore = child.usage.data().total;
252360
+ try {
252361
+ return await this.runWithActiveChild(childId, options, run);
252362
+ } finally {
252363
+ this.recordSubagentUsageDelta(parent, child, usageBefore);
252364
+ }
252365
+ }
252366
+ recordSubagentUsageDelta(parent, child, usageBefore) {
252367
+ const usageDelta = buildSubagentUsageDelta(child.usage.data().total, usageBefore);
252368
+ if (usageDelta === null) return;
252369
+ const model = child.config.modelAlias ?? parent.config.modelAlias ?? "subagent";
252370
+ parent.usage.record(model, usageDelta, "session");
252371
+ }
252357
252372
  async runPromptTurn(parent, childId, child, profileName, options) {
252358
252373
  options.signal.throwIfAborted();
252359
252374
  await this.triggerSubagentStart(parent, profileName, options.prompt, options.signal);
@@ -265265,6 +265280,7 @@ var init_agent = __esmMin((() => {
265265
265280
  projectedTokenCount: this.fullCompaction.estimateCurrentRequestTokens(),
265266
265281
  effectiveMaxContextTokens: this.fullCompaction.getEffectiveMaxContextTokens(),
265267
265282
  compactionBudgetTokens: this.fullCompaction.getCompactionBudgetTokens(),
265283
+ systemPromptTokens: estimateTokens$1(this.effectiveSystemPrompt),
265268
265284
  conversationTokens: estimateTokensForMessages(this.context.messages),
265269
265285
  toolSchemaTokens: estimateTokensForTools(this.tools.loopTools)
265270
265286
  }),
@@ -418113,6 +418129,7 @@ function buildContextInsightLines(insight) {
418113
418129
  const percentage = `${(insight.ratio * 100).toFixed(1)}%`;
418114
418130
  const lines = [
418115
418131
  ` ${barColoured} ${value(percentage.padStart(6, " "))} ${muted(`(${formatExactTokenCount(insight.projectedTokens, locale)} / ${formatExactTokenCount(insight.maxTokens, locale)})`)}`,
418132
+ ` ${muted(`${uiText("export.system")}:`)} ${value(formatExactTokenCount(insight.systemPromptTokens, locale))}`,
418116
418133
  ` ${muted(`${uiText("export.conversation")}:`)} ${value(formatExactTokenCount(insight.conversationTokens, locale))}`,
418117
418134
  ` ${muted(`${uiText("mcp.capability.tools")}:`)} ${value(formatExactTokenCount(insight.toolSchemaTokens, locale))}`,
418118
418135
  ` ${muted(`${uiText("command.compact.description")}:`)} ${value(formatExactTokenCount(insight.compactionBudgetTokens, locale))}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blun-king-cli",
3
- "version": "9.1.282",
3
+ "version": "9.1.284",
4
4
  "description": "BLUN CLI - your own AI agent with a Telegram channel. Get it done. With BLUN.",
5
5
  "license": "MIT",
6
6
  "bin": {