acp-kernel 0.0.52 → 0.0.53-pr.203.54

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.js CHANGED
@@ -2909,7 +2909,7 @@ function formatTokens2(n) {
2909
2909
  }
2910
2910
  function pct(n, total) {
2911
2911
  if (n <= 0 || total <= 0) return 0;
2912
- return Math.max(1, Math.round(n / total * 100));
2912
+ return Math.round(n / total * 100);
2913
2913
  }
2914
2914
  function numericPart2(blockId) {
2915
2915
  const match = /^b(\d+)$/.exec(blockId);
@@ -2948,12 +2948,18 @@ function collectVisible(messages, state, countTokens) {
2948
2948
  if (block.active) summaryTokens += summaryTokensOf(block, countTokens);
2949
2949
  }
2950
2950
  const visible = [];
2951
+ const toolCallNames = /* @__PURE__ */ new Map();
2952
+ for (const message of messages) {
2953
+ if (message.contentType === "tool-call" && message.toolCallId && message.toolName) {
2954
+ toolCallNames.set(message.toolCallId, message.toolName);
2955
+ }
2956
+ }
2951
2957
  messages.forEach((message, index) => {
2952
2958
  if (coveredIds.has(message.id)) return;
2953
2959
  const ref = refForRaw(state.messageRefs, message.id);
2954
2960
  if (!ref) return;
2955
2961
  const tokens = countTokens(message.text ?? "");
2956
- const tool = message.toolName ?? "text";
2962
+ const tool = isToolMessage(message) ? message.toolName ?? (message.toolCallId ? toolCallNames.get(message.toolCallId) : void 0) ?? "tool" : "text";
2957
2963
  if (tokens > 0) visible.push({ ref, tokens, tool, index });
2958
2964
  });
2959
2965
  return { visible, summaryTokens };
@@ -3041,6 +3047,17 @@ function renderUncompressedRanges(visible) {
3041
3047
  const m = ref.match(/\d+/);
3042
3048
  return m ? parseInt(m[0], 10) : 0;
3043
3049
  };
3050
+ const dominantTool = (toolTokens) => {
3051
+ let best = "text";
3052
+ let bestN = -1;
3053
+ for (const [tool, n] of toolTokens) {
3054
+ if (n > bestN) {
3055
+ best = tool;
3056
+ bestN = n;
3057
+ }
3058
+ }
3059
+ return best;
3060
+ };
3044
3061
  const merged = [];
3045
3062
  for (const m of visible) {
3046
3063
  const num = refNum2(m.ref);
@@ -3049,13 +3066,15 @@ function renderUncompressedRanges(visible) {
3049
3066
  last.endRef = m.ref;
3050
3067
  last.count += 1;
3051
3068
  last.tokens += m.tokens;
3069
+ last.toolTokens.set(m.tool, (last.toolTokens.get(m.tool) ?? 0) + m.tokens);
3052
3070
  } else {
3053
- merged.push({ startRef: m.ref, endRef: m.ref, startNum: num, count: 1, tokens: m.tokens, tool: m.tool });
3071
+ const toolTokens = /* @__PURE__ */ new Map([[m.tool, m.tokens]]);
3072
+ merged.push({ startRef: m.ref, endRef: m.ref, startNum: num, count: 1, tokens: m.tokens, toolTokens });
3054
3073
  }
3055
3074
  }
3056
3075
  for (const r of merged.slice(0, 30)) {
3057
3076
  const range = r.count === 1 ? r.startRef : `${r.startRef}\u2013${r.endRef}`;
3058
- lines.push(` ${range} (${r.count} msgs, ${formatTokens2(r.tokens)}${r.count > 1 ? ` (${Math.round(r.tokens / r.count)}/msg)` : ""}) ${r.tool}`);
3077
+ lines.push(` ${range} (${r.count} msgs, ${formatTokens2(r.tokens)}${r.count > 1 ? ` (${Math.round(r.tokens / r.count)}/msg)` : ""}) ${dominantTool(r.toolTokens)}`);
3059
3078
  }
3060
3079
  if (merged.length > 30) {
3061
3080
  lines.push(` ... and ${merged.length - 30} more ranges`);