Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

feat(web): the error table copies a whole record, heading and full message

lmlihengc4fd530e13fe
diff --git a/changelog/unreleased/2026-10-27-errors-panel-copy.md b/changelog/unreleased/2026-10-27-errors-panel-copy.md
new file mode 100644
index 00000000..3b77347b
--- /dev/null
+++ b/changelog/unreleased/2026-10-27-errors-panel-copy.md
@@ -0,0 +1,39 @@
+# The cost center's error table can copy a whole record
+
+- **Date:** 2026-10-27
+- **Type:** feat
+- **Scope:** `web`, `docs`
+- **Breaking:** no
+
+[中文](2026-10-27-errors-panel-copy.zh.md)
+
+Every row of the **Errors** panel at the bottom of the cost center now ends with a copy button. It
+puts the whole record on the clipboard as one paste-able block: the latest time, the
+**Source · code**, the type, and — for a row that folds several of a day's records — how many and
+when the first one was; then the message in full, line breaks and all.
+
+What a copy here is for is getting an error *out* of the panel: into a chat, an issue, or to
+another agent. So the block has to stand on its own. The reader on the other end sees none of the
+panel's filters, gets no tooltip, cannot hover a `×4` — and the part of a provider error that
+explains it (a 402's body, a stack's first frames) is usually below the first line, which the row
+truncates. Hand-copying it by dragging across a truncated cell was the only way before this.
+
+## Details
+
+- `packages/web/src/features/usage/errors-panel.tsx`: `errorCopyText(item)` builds the block and is
+ exported for the same reason `errorsClearScopeText` is — this package's vitest runs in `node`, so
+ the text is observable where a click and a clipboard are not. The row draws
+ `CopyButton` (the ui package's existing action, `size="sm"`) with the message cell's own
+ affordances in mind: it is on every row rather than revealed on hover, because a phone has no
+ hover (Tailwind v4 scopes `hover:` to `@media (hover: hover)`) and a hover-only action would
+ simply not exist there. The header cell above it stays empty: the glyph names itself through
+ `aria-label`, and repeating that name per row's column would read it out twice.
+- The table's `min-w` went 720 → 752, the copy column's own width, so the new column costs the
+ message column nothing at the narrowest viewport (the box scrolls sideways there).
+- `packages/web/src/lib/strings.ts` / `strings-en.ts`: one key, `errorsCopy`.
+- Docs: the errors panel in `packages/docs/content/usage.zh.md` / `usage.en.md`.
+
+## Compatibility
+
+- No dependency, on-disk format or API change: the block is built entirely on the client from a row
+ the panel already has. The server is untouched.
diff --git a/changelog/unreleased/2026-10-27-errors-panel-copy.zh.md b/changelog/unreleased/2026-10-27-errors-panel-copy.zh.md
new file mode 100644
index 00000000..92f58990
--- /dev/null
+++ b/changelog/unreleased/2026-10-27-errors-panel-copy.zh.md
@@ -0,0 +1,33 @@
+# 成本中心的异常表能把一整条异常复制走
+
+- **Date:** 2026-10-27
+- **Type:** feat
+- **Scope:** `web`, `docs`
+- **Breaking:** no
+
+[English](2026-10-27-errors-panel-copy.md)
+
+成本中心页面底部的**异常**面板,每一行右端多了一个复制按钮:把这条异常整条复制到剪贴板,成为一段可直接
+粘贴的文字 —— 最近一次的时间、**来源 · 错误码**、类型,合行时还有条数与首次时间;随后是完整消息(换行
+照原样)。
+
+这个复制是为着把异常**送出**面板:粘到聊天里、贴进 issue、或者交给另一个 Agent 排查。所以它得能独立
+成立:对面看不到这里的筛选、拿不到悬停提示、点不开那个 `×4`,而一段 provider 报错里真正说明问题的那
+部分(402 的响应体、栈的头几帧)往往在第二行往后 —— 恰恰是表格里被截掉的部分。此前唯一的办法是在一行
+被截断的单元格里拖选。
+
+## 细节
+
+- `packages/web/src/features/usage/errors-panel.tsx`:`errorCopyText(item)` 生成这段文字,并且导出 ——
+ 与 `errorsClearScopeText` 同样的理由:这个包的 vitest 跑在 `node` 里,点击和剪贴板看不到,文字看得到。
+ 行里用 ui 包既有的 `CopyButton`(`size="sm"`)。它画在每一行、不做悬停才显形:手机没有悬停(Tailwind v4
+ 把 `hover:` 收在 `@media (hover: hover)` 里),悬停才出现的操作在那里等于不存在 —— 消息格本身是个
+ 按钮,也是同一个理由。它上方那格表头留空:图标自己用 `aria-label` 报了名,每行再读一遍列名是重复。
+- 表格的 `min-w` 由 720 改成 752,即复制列自己的宽度:在最窄的视口里这一列不从消息列身上抢宽度(那个
+ 盒子本来就会横向滚动)。
+- `packages/web/src/lib/strings.ts` / `strings-en.ts`:一个新文案键 `errorsCopy`。
+- 文档:`packages/docs/content/usage.zh.md` / `usage.en.md` 的异常面板一节。
+
+## 兼容性
+
+- 不改依赖、不改磁盘格式、不改接口:这段文字完全由客户端从面板已有的一行里拼出来,服务端一行没动。
diff --git a/packages/docs/content/usage.en.md b/packages/docs/content/usage.en.md
index c81aff08..7966b292 100644
--- a/packages/docs/content/usage.en.md
+++ b/packages/docs/content/usage.en.md
@@ -63,6 +63,7 @@ The **Errors** panel at the bottom of the page shows the errors the server recor
- A table of errors with their time, **Source · code**, **Type** and **Message**. Click a message to expand its full text. The table shows 10 rows a page and pages with **Newer** and **Older** instead of scrolling.
- A **Type** filter above the table on the right: **All**, **Unexpected**, **Expected**. It narrows only the table below, its paging and **Clear**; the summary figures always count both categories.
- The same error recorded more than once on one day shares a row. The time is the latest one, hover it for the first, and ×N after the message counts the records. The summary figures count every record.
+- Each row carries a **Copy** button at its end that takes the whole record: the latest time, the **Source · code**, the type, the count and first time for a folded row, and the message in full with its line breaks. To hand an error to someone else, copy it and paste.
The model filter does not apply to this panel.
diff --git a/packages/docs/content/usage.zh.md b/packages/docs/content/usage.zh.md
index 1b32774f..d335ae22 100644
--- a/packages/docs/content/usage.zh.md
+++ b/packages/docs/content/usage.zh.md
@@ -63,6 +63,7 @@ description: 按 Agent、模型和时间范围查看 Token 用量、成本与服
- 异常明细表:时间、**来源 · 错误码**、**类型**和**消息**。点击消息可展开全文。每页 10 行,用**较新**和**更早**翻页,不滚动。
- 表格右上方的**类型**筛选:**全部**、**未预期**、**预期内**。它只收窄下面的表格、翻页和**清空**,上面的汇总数字始终按两类合计。
- 同一天里多次记录的同一个异常合为一行:时间显示最近一次,悬停可看到首次;消息后的 ×N 是记录的条数。汇总数字按每条记录计。
+- 每一行右端有一个**复制**按钮:把这一条异常整条复制走 —— 最近一次的时间、**来源 · 错误码**、类型、合行时的条数与首次时间,以及完整消息(换行照原样)。要把它发给别人排查,复制后直接粘贴即可。
模型筛选对这个面板不起作用。
diff --git a/packages/web/src/features/usage/errors-panel.tsx b/packages/web/src/features/usage/errors-panel.tsx
index c3a1fbc5..b61f2260 100644
--- a/packages/web/src/features/usage/errors-panel.tsx
+++ b/packages/web/src/features/usage/errors-panel.tsx
@@ -15,7 +15,15 @@
*/
import { useEffect, useMemo, useState } from "react";
import type { UsageErrorItem, UsageErrors } from "@adelie/server/api";
-import { Badge, ConfirmModal, Pager, Segmented, toastError, toastSuccess } from "@adelie/ui";
+import {
+ Badge,
+ ConfirmModal,
+ CopyButton,
+ Pager,
+ Segmented,
+ toastError,
+ toastSuccess,
+} from "@adelie/ui";
import * as api from "../../api/endpoints";
import { S } from "../../lib/strings";
import { apiErrorText } from "../../lib/api-error";
@@ -117,6 +125,29 @@ function sourceCode(source: string, code: string): string {
return `[${SOURCE_ABBREV[source] ?? source}] ${code}`;
}
+/**
+ * What a row's copy button puts on the clipboard: one heading line — when it last happened,
+ * where it came from, which category it is in, and, for a row folding several records, how many
+ * and when the first was — followed by the message in full.
+ *
+ * What a copy here is for is getting the error OUT of the panel: pasting it into a chat, an
+ * issue, or to another agent. So the block has to stand on its own — the raw code, the full
+ * message with its newlines (the provider's 402 body is the part that explains it), and the
+ * conditions the panel's two filters would otherwise only imply. Nothing the reader can already
+ * see, nothing they cannot: the row's own tooltip carries the first timestamp too, and this is
+ * the same two facts in text rather than a mouse-only affordance.
+ *
+ * Pure and exported for the reason `errorsClearScopeText` is: this package's vitest runs in
+ * `node`, so a click and a clipboard are not something a test can observe — the text is.
+ */
+export function errorCopyText(e: UsageErrorItem): string {
+ const head = [formatDateTime(e.ts), sourceCode(e.source, e.code), kindLabel(kindOf(e.kind))];
+ if (e.count > 1) {
+ head.push(`×${e.count}`, S.usage.errorsFirstAt(formatDateTime(e.firstTs)));
+ }
+ return `${head.join(" · ")}\n${e.message}`;
+}
+
/** A single small stat: name + value, one row side by side (not turned into a chart). */
function Stat({
label,
@@ -144,7 +175,7 @@ function Stat({
}
/** Header cell: left-aligned, recessive gray. */
-function Th({ children, className = "" }: { children: React.ReactNode; className?: string }) {
+function Th({ children, className = "" }: { children?: React.ReactNode; className?: string }) {
return <th className={`py-1.5 pr-2 font-medium ${className}`}>{children}</th>;
}
@@ -391,13 +422,14 @@ export function ErrorsPanel({
<Empty text={kindFilter === "all" ? S.usage.errorsEmpty : S.usage.errorsEmptyKind} />
) : (
<div className="mt-2.5 overflow-x-auto overflow-y-clip border-t border-gray-200 dark:border-gray-800">
- {/* The three leading columns are fixed-width and the message column takes the rest, so
+ {/* The columns beside the message are fixed-width and the message column takes the rest, so
the table has a minimum below which `table-fixed` starves the message column down to
- zero width and pushes the other three past the edge. `min-w` states that floor, and
+ zero width and pushes the others past the edge. `min-w` states that floor, and
this box scrolls it sideways when the viewport is narrower — the page itself must
never scroll sideways (styles.css). `overflow-y-clip` keeps browsers from reserving
- a vertical scrollbar gutter beside the horizontal one. */}
- <table className="w-full min-w-[720px] table-fixed text-xs">
+ a vertical scrollbar gutter beside the horizontal one. 752 = the old floor plus the
+ copy column's 32, so that column costs the message column nothing. */}
+ <table className="w-full min-w-[752px] table-fixed text-xs">
<thead className="text-left text-gray-400 dark:text-gray-500">
<tr>
<Th className="w-32">{S.common.time}</Th>
@@ -407,6 +439,9 @@ export function ErrorsPanel({
<Th className="w-72">{S.usage.errorsColCode}</Th>
<Th className="w-20">{S.usage.errorsColKind}</Th>
<Th>{S.usage.errorsColMessage}</Th>
+ {/* The copy column: the glyph names its action itself, so the header stays
+ empty rather than repeating it for a screen reader twice per row. */}
+ <Th className="w-8" />
</tr>
</thead>
<tbody>
@@ -461,6 +496,17 @@ export function ErrorsPanel({
)}
</button>
</td>
+ {/* The whole record on the clipboard (see errorCopyText). Drawn on every row
+ rather than revealed on hover: a phone has no hover (Tailwind v4 scopes the
+ hover: variants to `@media (hover: hover)`), so a hover-revealed action would
+ simply not exist there — the reason the message cell is a plain button too. */}
+ <td className="py-1.5 pl-2 align-top">
+ <CopyButton
+ text={() => errorCopyText(e)}
+ label={S.usage.errorsCopy}
+ size="sm"
+ />
+ </td>
</tr>
);
})}
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index 955dd170..f7b11bd2 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -4271,6 +4271,8 @@ export const en: Strings = {
errorsEmptyKind: "No errors of this type",
/** Time cell tooltip on a row that folds several of a day's records: when the first one was. */
errorsFirstAt: (time: string): string => `First at ${time}`,
+ /** Each row's copy action: the whole record — when, source · code, type, count and the full message — as one paste-able block. */
+ errorsCopy: "Copy this error",
/** Detail-table pager: newer/older step back through pages of the same filtered set; it counts rows, not records. */
errorsNewer: "Newer",
errorsOlder: "Older",
diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.ts
index e463b35f..7b69b249 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -4304,6 +4304,8 @@ export const zh = {
errorsEmptyKind: "该类型下暂无异常",
/** Time cell tooltip on a row that folds several of a day's records: when the first one was. */
errorsFirstAt: (time: string): string => `首次出现于 ${time}`,
+ /** Each row's copy action: the whole record — when, source · code, type, count and the full message — as one paste-able block. */
+ errorsCopy: "复制这条异常",
/** Detail-table pager: newer/older step back through pages of the same filtered set; it counts rows, not records. */
errorsNewer: "较新",
errorsOlder: "更早",
diff --git a/packages/web/test/errors-panel.test.ts b/packages/web/test/errors-panel.test.ts
index 0026ea52..7c412240 100644
--- a/packages/web/test/errors-panel.test.ts
+++ b/packages/web/test/errors-panel.test.ts
@@ -15,7 +15,11 @@ import { afterEach, describe, expect, it } from "vitest";
import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import type { UsageErrorItem, UsageErrors } from "@adelie/server/api";
-import { ErrorsPanel, errorsClearScopeText } from "../src/features/usage/errors-panel";
+import {
+ ErrorsPanel,
+ errorCopyText,
+ errorsClearScopeText,
+} from "../src/features/usage/errors-panel";
import type { ErrorsFilters } from "../src/features/usage/errors-panel";
import { formatDateTime } from "../src/lib/format";
import { S, setActiveStrings, zh } from "../src/lib/strings";
@@ -214,3 +218,67 @@ describe("ErrorsPanel category control", () => {
expect(html).toContain(S.usage.errorsUnexpected);
});
});
+
+describe("ErrorsPanel copy action", () => {
+ it("is drawn once per row, named for what it copies", () => {
+ const html = render({ items: [item("internal"), item("tool_failed:exec_command")] });
+ expect(html.split(`aria-label="${S.usage.errorsCopy}"`).length - 1).toBe(2);
+ // An empty table has nothing to copy, so the action goes with the rows.
+ expect(render({ items: [] })).not.toContain(S.usage.errorsCopy);
+ });
+
+ // Where a copy here is for pasting the error somewhere else, the text has to stand alone: the
+ // reader on the other end sees none of the panel's filters, its tooltips, or the row's fold
+ // count. Asserted per locale because the heading reads in the interface's language.
+ for (const [locale, dict] of Object.entries({ zh, en })) {
+ it(`${locale}: carries the time, the source · code, the type and the message in full`, () => {
+ setActiveStrings(dict);
+ const e: UsageErrorItem = {
+ ...item("tool_failed:exec_command"),
+ source: "environment",
+ kind: "unexpected",
+ message: "EBUSY: resource busy or locked, rmdir 'skills/wps-office'\n at rm (node:fs)",
+ };
+ const text = errorCopyText(e);
+ expect(text).toContain(formatDateTime(e.ts));
+ // The bracketed source is abbreviated as the table abbreviates it, and the code is raw:
+ // `[environment]` is the server's spelling, `[env]` the panel's.
+ expect(text).toContain("[env] tool_failed:exec_command");
+ expect(text).toContain(dict.usage.errorsUnexpected);
+ // The message is copied whole, newlines included — the detail after the first line is the
+ // part that explains the error.
+ expect(text.endsWith(`\n${e.message}`)).toBe(true);
+ expect(text).toContain(" at rm (node:fs)");
+ // Heading and message are two parts, not one run-on line.
+ expect(text.split("\n")[0]).not.toContain("EBUSY");
+ });
+
+ it(`${locale}: a folded row also carries how many records and when the first was`, () => {
+ setActiveStrings(dict);
+ const folded: UsageErrorItem = {
+ ...item("messaging_connect_failed"),
+ count: 3,
+ firstTs: "2026-08-27T06:00:00.000Z",
+ };
+ const text = errorCopyText(folded);
+ expect(text.split("\n")[0]).toContain("×3");
+ expect(text.split("\n")[0]).toContain(
+ dict.usage.errorsFirstAt(formatDateTime(folded.firstTs)),
+ );
+ // A single record says neither: the count is already the absence of a fold.
+ const single = errorCopyText(item("internal"));
+ expect(single).not.toContain("×1");
+ expect(single).not.toContain(
+ dict.usage.errorsFirstAt(formatDateTime(item("internal").firstTs)),
+ );
+ });
+ }
+
+ it("reads an unknown category as expected, as the badge beside it does", () => {
+ // The route only writes the two kinds; a row from an older or newer server must still copy
+ // something true rather than the word "undefined".
+ const text = errorCopyText({ ...item("internal"), kind: "something_new" });
+ expect(text).toContain(S.usage.errorsExpected);
+ expect(text).not.toContain("undefined");
+ });
+});