A local-first multi-agent app development platform, built on PenguinHarness
feat(web): Trace summary shows average tool calls per round (#681)
Yaowei Zheng3a6de165209d
diff --git a/changelog/unreleased/2026-09-11-trace-avg-tool-calls.md b/changelog/unreleased/2026-09-11-trace-avg-tool-calls.mdnew file mode 100644index 00000000..249015b5--- /dev/null+++ b/changelog/unreleased/2026-09-11-trace-avg-tool-calls.md@@ -0,0 +1,17 @@+# The Trace summary reports average tool calls per round instead of compactions++- **Date:** 2026-09-11+- **Type:** feature+- **Scope:** `web`+- **PR:** [#681](https://github.com/Prism-Shadow/penguin-harness/pull/681)++[中文版](2026-09-11-trace-avg-tool-calls.zh.md)++The Trace view's global summary swapped its compaction count for the average number of tool calls+per round. The average divides the two figures printed directly above it, tool calls ÷ rounds, so+it can be checked by eye and keeps the column's scope: rounds means every card below, compaction+rounds included. A Trace with no rounds leaves the average undefined and shows `—`, the mark the+cost and TPS stats already use for an unavailable figure.++The change is confined to the Web App: the Trace analysis the server returns kept its+`compactionCount` field, which simply stopped being rendered.diff --git a/changelog/unreleased/2026-09-11-trace-avg-tool-calls.zh.md b/changelog/unreleased/2026-09-11-trace-avg-tool-calls.zh.mdnew file mode 100644index 00000000..65125a37--- /dev/null+++ b/changelog/unreleased/2026-09-11-trace-avg-tool-calls.zh.md@@ -0,0 +1,14 @@+# Trace 全局统计改用每轮平均工具调用,取代压缩次数++- **Date:** 2026-09-11+- **Type:** feature+- **Scope:** `web`+- **PR:** [#681](https://github.com/Prism-Shadow/penguin-harness/pull/681)++[English](2026-09-11-trace-avg-tool-calls.md)++Trace 页的全局统计把压缩次数换成了每轮平均工具调用。平均值就是它正上方两项相除,工具调用 ÷ 轮次,一眼+即可核对,并且沿用该列的口径:轮次指下方的每一张卡片,含压缩轮。轮次为 0 的 Trace 上平均值无定义,显示+`—`,与成本、TPS 在数值不可用时的标记一致。++改动只落在 Web App:服务端返回的 Trace 分析保留 `compactionCount` 字段,只是不再被渲染。diff --git a/packages/web/e2e/chat.spec.mjs b/packages/web/e2e/chat.spec.mjsindex 5f0cb955..e3b6b4de 100644--- a/packages/web/e2e/chat.spec.mjs+++ b/packages/web/e2e/chat.spec.mjs@@ -237,7 +237,7 @@ test("chat + tool approval + stats/cost/copy + traces + files", async ({ page })// gone — its label said "duration" while it actually rendered a count.await expect(main.getByText("全局统计")).toBeVisible();await expect(main.getByText("Request 耗时")).toHaveCount(0);- for (const label of ["轮次", "工具调用", "压缩次数", "输入 tokens", "输出 TPS"]) {+ for (const label of ["轮次", "工具调用", "每轮平均工具调用", "输入 tokens", "输出 TPS"]) {await expect(main.getByText(label, { exact: true }).first()).toBeVisible();}// Time-axis zoom: Premiere-style scrubber (role=scrollbar) + −/+ buttons.diff --git a/packages/web/src/features/traces/trace-file-view.tsx b/packages/web/src/features/traces/trace-file-view.tsxindex dec10097..4f3a84de 100644--- a/packages/web/src/features/traces/trace-file-view.tsx+++ b/packages/web/src/features/traces/trace-file-view.tsx@@ -38,6 +38,7 @@ import { apiErrorText } from "../../lib/api-error";import {cacheHitRate,computeTps,+ formatAverage,formatMoney,formatPercent,formatTps,@@ -466,11 +467,17 @@ export function TraceFileView({{/* Rounds = number of cards below (a compaction round counts asa round too): the global summary and the per-round displaybelow share **the same scope** — every figure is the sum- across rounds and must add up; how many of them are- compaction rounds is answered separately by "compaction count". */}+ across rounds and must add up. The average is exactly the two+ rows above it divided, tool calls ÷ rounds, so it holds that+ same scope and a reader can check the division by eye — a+ denominator that skipped compaction rounds would no longer+ match the round count printed here. */}<SummaryRow label={S.traces.tasksLabel} value={String(analysis.tasks.length)} /><SummaryRow label={S.traces.toolCalls} value={String(global.toolCalls)} />- <SummaryRow label={S.traces.compactions} value={String(analysis.compactionCount)} />+ <SummaryRow+ label={S.traces.avgToolCalls}+ value={formatAverage(global.toolCalls, analysis.tasks.length)}+ /></div>{/* Token usage: broken down by category (input / of which cache hit + hit rate / output), never given as a lump sum. */}<div>diff --git a/packages/web/src/lib/format.ts b/packages/web/src/lib/format.tsindex 733a8ddf..a7f56df1 100644--- a/packages/web/src/lib/format.ts+++ b/packages/web/src/lib/format.ts@@ -103,6 +103,19 @@ export function formatPercent(ratio: number | null | undefined): string {return `${Math.round(ratio * 100)}%`;}+/**+ * Average display for a "total ÷ count" figure (the Trace summary's tool calls+ * per round): one decimal place, kept even when it is `.0`, so an average is+ * never mistaken for the whole count printed beside it. A count of 0 leaves the+ * average undefined → `—`, the same mark formatMoney and formatTps use for a+ * figure that is not available, so an empty Trace reads the same way in every+ * column.+ */+export function formatAverage(total: number, count: number): string {+ const avg = total / count;+ return count > 0 && Number.isFinite(avg) ? avg.toFixed(1) : "—";+}+/*** Cost display (converted to the selected currency; prices are stored in* USD): null/undefined → `—`; 1 USD ≈ 7 CNY; decimal places scale withdiff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.tsindex 0821b370..bb72b7fe 100644--- a/packages/web/src/lib/strings-en.ts+++ b/packages/web/src/lib/strings-en.ts@@ -2614,7 +2614,7 @@ Scenarios:taskOutput: "Output tokens this turn",cacheHit: "Cache hits",hitRate: "Hit rate",- compactions: "compactions",+ avgToolCalls: "Avg tools / turn",inProgress: "in progress",systemPrompt: "System prompt",toolDefs: (n: number) => `Tool definitions (${n})`,diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.tsindex 1be3f195..69bc05ff 100644--- a/packages/web/src/lib/strings.ts+++ b/packages/web/src/lib/strings.ts@@ -2570,7 +2570,7 @@ Benchmark:taskOutput: "本轮输出 tokens",cacheHit: "命中缓存",hitRate: "命中率",- compactions: "压缩次数",+ avgToolCalls: "每轮平均工具调用",/** The round-card badge reuses `chat.compactionTitle`, which names the mode (压缩 / 清空) and is the stem of the conversation row's state titles (压缩中 / 压缩完毕), so the Trace view and the conversation cannot drift apart; there is deliberately no Trace-local copy of that word. */inProgress: "进行中",systemPrompt: "系统提示词",diff --git a/packages/web/test/format.test.ts b/packages/web/test/format.test.tsindex f5ab9a9a..fbf98b52 100644--- a/packages/web/test/format.test.ts+++ b/packages/web/test/format.test.ts@@ -5,6 +5,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import {cacheHitRate,computeTps,+ formatAverage,formatBytes,formatDateTime,formatMoney,@@ -166,6 +167,21 @@ describe("cacheHitRate (shared by the Trace summaries and the Cost center's cach});});+describe("formatAverage (the Trace summary's tool calls per round)", () => {+ it("keeps one decimal place, so an average never reads as the count beside it", () => {+ expect(formatAverage(17, 5)).toBe("3.4");+ expect(formatAverage(12, 3)).toBe("4.0");+ expect(formatAverage(0, 3)).toBe("0.0"); // rounds with no tool call at all: a real average+ expect(formatAverage(10, 3)).toBe("3.3"); // 3.33… rounds down+ expect(formatAverage(20, 3)).toBe("6.7"); // 6.66… rounds up+ });++ it("count 0 (an empty Trace) leaves the average undefined and shows —", () => {+ expect(formatAverage(0, 0)).toBe("—");+ expect(formatAverage(7, 0)).toBe("—");+ });+});+describe("formatBytes", () => {it("byte abbreviation", () => {expect(formatBytes(812)).toBe("812B");