Skip to content

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

fix(web): 钩子包没有导出成时,原因留在发问的那一行下面,不再只活六秒

lmlihengc6213b920a3d
diff --git a/changelog/unreleased/2026-11-08-hook-export-refusal.md b/changelog/unreleased/2026-11-08-hook-export-refusal.md
new file mode 100644
index 00000000..94118525
--- /dev/null
+++ b/changelog/unreleased/2026-11-08-hook-export-refusal.md
@@ -0,0 +1,56 @@
+# A hook package that failed to export says why under the row that asked
+
+- **Date:** 2026-11-08
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文](2026-11-08-hook-export-refusal.zh.md)
+
+Every row of Agent settings → Hooks has an "Export": it fetches the installed hook package as a zip
+and hands it to the browser through a temporary object URL. When the server refused that download,
+the package was still installed, the row was still on screen, and even the button that was pressed
+was still there — but the only account of why was a notification that dismissed itself after six
+seconds, floating above the list while the reader's eyes were on a row below it.
+
+That is the shape 7.19 bans, and the Skills tab's rows were fixed the same way one round earlier
+(7.101). A failed export is the one moment a reader wonders whether the installed copy was touched,
+so the sentence says the package is still installed on the agent as well as why the export did not
+land.
+
+The reason now renders under the row that asked (`role="alert"`, the danger tone, two lines at most,
+the whole sentence on hover) until the next attempt begins; pressing the same export button is the
+retry. Which row draws it is decided by the package's name, one at a time, and no other row changes
+by a character.
+
+## Details
+
+- `packages/web/src/features/agents/hook-export-refusal.ts` (new): `hookExportRefused(hook, error)`
+ builds the sentence (the reason goes through `refusalText`, the one rule every refusal in the app
+ follows), and `hookExportRefusalFor(refusal, hook)` decides which row this refusal belongs to.
+- `packages/web/src/features/agents/hooks-tab.tsx`: `exportHook` no longer posts a toast on failure;
+ it keeps `{ hook, text }` and hands it to that row, and the start of every attempt clears the
+ previous sentence (it belonged to the attempt before). The list row goes from a single flex line to
+ "row + optional reason line"; the hover background and the divider stay on the outer element, and
+ nothing else about the layout moves.
+- `packages/web/src/lib/strings{,-en}.ts`: one new sentence, `hooks.exportRefused(hook, reason)`.
+
+## Tests
+
+- `packages/web/test/hook-export-refusal.test.ts` (new, 9 cases): the server's reason read through
+ its code (never the wire message), a sentence this codebase raised itself kept as written, the
+ generic text when nothing was said, the package named, the installed copy called out, and the
+ English sentence; plus three on "a refusal belongs only to its own row".
+- `packages/web/e2e/hook-export-refusal.spec.mjs` (new, real server + real browser): the export
+ button of a hook package that really is installed, with the archive route refused at `page.route`
+ with a 500. The sentence appears exactly once, under that row, word for word in the interface's
+ own language; the notification region does not carry it; the row's own line reads exactly as it
+ did before the attempt; it is **still there seven seconds later**; and the server's installed list
+ is unchanged. Allowed, the same button pressed again makes the sentence go and really hands the
+ zip to the browser as a download.
+
+## Compatibility
+
+No interface change, no new dependency, no Project config change. The rest of the Hooks tab — the
+Agent-level enable switch, the import modal (chat import and zip upload, overwrite confirmation),
+the uninstall confirmation and its own refusal line — is unchanged.
diff --git a/changelog/unreleased/2026-11-08-hook-export-refusal.zh.md b/changelog/unreleased/2026-11-08-hook-export-refusal.zh.md
new file mode 100644
index 00000000..dcd69fb7
--- /dev/null
+++ b/changelog/unreleased/2026-11-08-hook-export-refusal.zh.md
@@ -0,0 +1,43 @@
+# 钩子包没有导出成时,原因留在发问的那一行下面
+
+- **日期:** 2026-11-08
+- **类型:** 修复
+- **范围:** `web`
+- **破坏性变更:** 无
+
+[English](2026-11-08-hook-export-refusal.md)
+
+Agent 设置 → 钩子页每一行都有「打包导出」:它拉一次那棵已安装钩子包的 zip,再用一个临时的对象地址把它交给浏览器。
+服务端拒了这次下载时,钩子包还在、那一行还在、连按下去的按钮都还在原地,可唯一解释原因的那句话是一条六秒后自己
+消失的通知 —— 它浮在列表上方,而读者视线落在下面某一行上。
+
+这正是 7.19 禁止的形状,技能页的行在上一轮(7.101)已经照同一个做法改过。导出失败是唯一会让人担心「已安装的那份
+是不是被动了」的时刻,所以句子除了念原因,还明说钩子包仍然装在这个 Agent 上。
+
+原因现在画在发问的那一行下面(`role="alert"`、危险色、最多两行、整句挂悬停),留到下一次尝试开始为止;再按
+一次那颗导出按钮就是重试。哪一行读这句话由包名决定,同一时刻只有一条,别的行一个字都不变。
+
+## 细节
+
+- 新增 `packages/web/src/features/agents/hook-export-refusal.ts`:`hookExportRefused(hook, error)` 造句
+ (原因走 `refusalText`,与全应用每一个拒绝同一个规则),`hookExportRefusalFor(refusal, hook)` 决定这次
+ 拒绝归哪一行。
+- `packages/web/src/features/agents/hooks-tab.tsx`:`exportHook` 失败时不再弹通知,而是记下 `{ hook, text }`
+ 并交给那一行;每次尝试开始先清掉上一句(它属于上一次尝试)。列表行从单行 flex 改成「行 + 可选的拒绝行」,
+ 悬停背景与分隔线留在外层,其余排版不动。
+- `packages/web/src/lib/strings{,-en}.ts`:新增一句 `hooks.exportRefused(hook, reason)`。
+
+## 测试
+
+- `packages/web/test/hook-export-refusal.test.ts`(新增,9 条):服务端的原因按错误码念(绝不念线上原文)、
+ 界面自己抛出的句子原样保留、什么都没说时落到通用文案、念出钩子包名、点明它仍装在这个 Agent 上、英文那一句;
+ 以及「这条拒绝只归它自己那一行」的三条。
+- `packages/web/e2e/hook-export-refusal.spec.mjs`(新增,真服务端 + 真浏览器):从一个真装着的钩子包行点导出,
+ 归档路由被 `page.route` 拒成 500;断言句子只出现一次、就在那一行下面、逐字是界面自己的话、通知区里没有它、
+ 那一行自己的文字与尝试前一模一样、**七秒之后**还在,并且服务端那份已安装列表没有变化。放行后同一颗按钮再按
+ 一次:句子消失,zip 真的作为下载交到浏览器手上。
+
+## 兼容性
+
+不改接口、不引入新依赖、不改 Project 配置。钩子页的其它行为 —— Agent 级启用开关、导入(对话 / zip 两条路与
+覆盖确认)、卸载确认框与其拒绝行 —— 原样不变。
diff --git a/packages/web/e2e/hook-export-refusal.spec.mjs b/packages/web/e2e/hook-export-refusal.spec.mjs
new file mode 100644
index 00000000..b51984ae
--- /dev/null
+++ b/packages/web/e2e/hook-export-refusal.spec.mjs
@@ -0,0 +1,161 @@
+/**
+ * Regression: a hook package's "Export" that the download refused leaves its reason under the row
+ * that asked, instead of only in a notification that dismisses itself after six seconds.
+ *
+ * The export is a plain fetch of the installed directory (`archive-download.ts`): nothing is
+ * written on the server and no client state moves, so a refusal leaves the row, the installed
+ * package and the same button on screen. That is exactly where the reason belongs (7.19's rule) —
+ * before this, `exportHook` answered with `toastError`, and a reader who looked away had no zip
+ * file and nothing saying why. The Skills tab's twin is `skill-export-refusal.spec.mjs`.
+ *
+ * The package is one the base installs on a fresh Agent (read from the API, not spelled out here),
+ * and the refused download is the page's own request as seen by `page.route` — both halves are the
+ * page's contract with the server.
+ */
+import { test, expect } from "@playwright/test";
+import { provisionAndLogin } from "./auth.mjs";
+
+const BASE = process.env.BASE_URL;
+const MOCK = process.env.MOCK_URL;
+const P = "password123";
+const AGENT = "default_agent";
+
+/** The refused archive: its code's own localized sentence is what the row has to draw. */
+const REFUSAL = { code: "internal", message: "the archive could not be read" };
+/** S.errors.byCode.internal — the copy that code stands for in a zh-CN interface. */
+const REASON = "服务器内部错误,请稍后重试。";
+
+/**
+ * Provision the user, give the Project a model (the onboarding overlay covers the page without
+ * one), and return the first hook package the Agent already has — the row under test — plus a
+ * reader for the server's installed list, so "still installed" is checked on both sides.
+ */
+async function agentWithHook(page, user) {
+ await provisionAndLogin(page.request, user, P);
+ const projectId = (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0]
+ .projectId;
+ const models = await page.request.put(`${BASE}/api/projects/${projectId}/models`, {
+ data: {
+ defaultModel: { provider: "custom", modelId: "claude-4-8" },
+ models: [
+ {
+ provider: "custom",
+ modelId: "claude-4-8",
+ apiKey: "sk-mock",
+ baseUrl: MOCK,
+ contextWindow: 200000,
+ },
+ ],
+ },
+ });
+ expect(models.ok(), "put models").toBeTruthy();
+
+ const installed = async () =>
+ (
+ await (
+ await page.request.get(`${BASE}/api/projects/${projectId}/agents/${AGENT}/hooks`)
+ ).json()
+ ).hooks.map((h) => h.name);
+
+ const names = await installed();
+ expect(names.length, "a fresh Agent ships hook packages to export").toBeGreaterThan(0);
+ return { projectId, name: names[0], installed };
+}
+
+/**
+ * Take over the archive download: every GET is kept in `seen`, and while `state.refuse` is set it
+ * is answered with the server's refusal instead of reaching the real route.
+ */
+async function interceptExport(page, state) {
+ await page.route("**/api/projects/*/agents/*/hooks/*/archive", async (route) => {
+ state.seen.push(new URL(route.request().url()).pathname.split("/").at(-2));
+ if (!state.refuse) return route.fallback();
+ await route.fulfill({
+ status: 500,
+ contentType: "application/json",
+ body: JSON.stringify({ error: REFUSAL }),
+ });
+ });
+}
+
+/** The row's own export button (its accessible name is the verb plus the package's name). */
+const rowButton = (page, name) =>
+ page.getByRole("button", { name: `打包导出 ${name}`, exact: true });
+
+/** The reason line under that row. */
+const refusalLine = (page) => page.getByTestId("hook-export-refusal");
+
+/** The notification region: a refusal must not be announced there (that is the old toast). */
+const notifications = (page) => page.getByRole("region", { name: "通知" });
+
+/** The row's line (everything but the reason): the only thing a refusal may change. */
+const rowLine = (page, name) => rowButton(page, name).locator("xpath=../..").locator("div").first();
+
+test("a refused export keeps its reason under the row, and nothing else changes", async ({
+ page,
+}) => {
+ const { name, installed } = await agentWithHook(page, "r214hookexportrefuse");
+ const before = await installed();
+ expect(before).toContain(name);
+
+ const state = { seen: [], refuse: true };
+ await interceptExport(page, state);
+
+ await page.goto(`/agents/${AGENT}?tab=hooks`);
+ await expect(rowButton(page, name)).toBeVisible();
+ const line = await rowLine(page, name).innerText();
+ const rows = await page.getByRole("button", { name: /^打包导出 / }).count();
+ await expect(refusalLine(page)).toHaveCount(0);
+
+ await rowButton(page, name).click();
+
+ // The reason is in the row that asked, and it is not a toast: the notification region holds no
+ // dismissible button, and the row's own line reads exactly as it did before the attempt.
+ await expect(refusalLine(page)).toHaveCount(1);
+ await expect(refusalLine(page)).toHaveText(
+ `钩子包 ${name} 没有导出成 zip,它仍然装在这个 Agent 上:${REASON}`,
+ );
+ expect(await rowLine(page, name).innerText()).toBe(line);
+ await expect(notifications(page).getByRole("button")).toHaveCount(0);
+ expect(state.seen).toEqual([name]);
+
+ // One row, one sentence: no other package's row grew one.
+ await expect(page.getByTestId("hook-export-refusal")).toHaveCount(1);
+ expect(await page.getByRole("button", { name: /^打包导出 / }).count()).toBe(rows);
+
+ // Six seconds is where the old toast gave up; the sentence is still there.
+ await page.waitForTimeout(7000);
+ await expect(refusalLine(page)).toHaveCount(1);
+
+ // Nothing was exported, and the installed copy was not touched.
+ expect(await installed()).toEqual(before);
+});
+
+test("the retry after a refused export lands, and only a new attempt clears the reason", async ({
+ page,
+}) => {
+ const { name, installed } = await agentWithHook(page, "r214hookexportretry");
+
+ const state = { seen: [], refuse: true };
+ await interceptExport(page, state);
+
+ await page.goto(`/agents/${AGENT}?tab=hooks`);
+ await expect(rowButton(page, name)).toBeVisible();
+ await rowButton(page, name).click();
+ await expect(refusalLine(page)).toHaveCount(1);
+ expect(state.seen).toEqual([name]);
+
+ // The retry is the same row; this time the archive really comes back: the sentence goes, and the
+ // file is handed to the browser as a download.
+ state.refuse = false;
+ const download = page.waitForEvent("download");
+ await rowButton(page, name).click();
+ await expect(refusalLine(page)).toHaveCount(0);
+ expect(state.seen).toEqual([name, name]);
+ const file = await download;
+ expect(file.suggestedFilename()).toMatch(/\.zip$/);
+
+ // A refused export changes neither side: the package is still installed and still listed.
+ expect(await installed()).toContain(name);
+ await expect(rowButton(page, name)).toBeVisible();
+});
diff --git a/packages/web/src/features/agents/hook-export-refusal.ts b/packages/web/src/features/agents/hook-export-refusal.ts
new file mode 100644
index 00000000..327953aa
--- /dev/null
+++ b/packages/web/src/features/agents/hook-export-refusal.ts
@@ -0,0 +1,48 @@
+/**
+ * A hook package's "Export" button on the Agent's Hooks tab (`hooks-tab.tsx`), and the sentence
+ * one refused export leaves behind — the twin of `skill-export-refusal.ts` (the Skills tab's row,
+ * 7.101), because both rows call the same shared archive download and have the same shape.
+ *
+ * The export is a plain fetch of the installed directory through `archive-download.ts`: nothing is
+ * written on the server, the package stays installed either way, and no client state moves while
+ * the request is out — so when the request is refused the row that sent it is still on screen, a
+ * line above, with the very button that retries it. The reason used to arrive only as a
+ * notification: it dismissed itself after six seconds, sat above the list, and a reader who had
+ * looked away was left with no zip file and nothing saying why (7.19's rule, app-wide — the
+ * sentence belongs where the attempt was made).
+ *
+ * Which words: `refusalText`, the rule every refusal in the app follows — an answer the server
+ * gave is read through its code's own localized sentence, and a value this codebase raised itself
+ * is shown as it wrote it. The sentence says the package was not exported *and* that it is still
+ * installed, because a failed export is the one moment a reader wonders whether the installed copy
+ * was touched.
+ */
+import { refusalText } from "../../lib/api-error";
+import { S } from "../../lib/strings";
+
+/** The sentence one refused export left, and the hook package it was for. */
+export interface HookExportRefusal {
+ readonly hook: string;
+ readonly text: string;
+}
+
+/** The sentence: which hook package was not exported, and why. */
+export function hookExportRefused(hook: string, error: unknown): string {
+ return S.hooks.exportRefused(hook, refusalText(error));
+}
+
+/**
+ * What this row draws for a refusal, if anything.
+ *
+ * The tab keeps one refusal at a time — the page's actions are serialized by `busy`, and an
+ * attempt supersedes the reason of the attempt before it — so a refusal belongs to the row whose
+ * name it carries and no other row may read it. Rows for other packages in the same list must
+ * stay exactly as they were.
+ */
+export function hookExportRefusalFor(
+ refusal: HookExportRefusal | null,
+ hook: string,
+): string | undefined {
+ if (refusal === null || refusal.hook !== hook) return undefined;
+ return refusal.text;
+}
diff --git a/packages/web/src/features/agents/hooks-tab.tsx b/packages/web/src/features/agents/hooks-tab.tsx
index a2253720..72c8a8f7 100644
--- a/packages/web/src/features/agents/hooks-tab.tsx
+++ b/packages/web/src/features/agents/hooks-tab.tsx
@@ -7,7 +7,8 @@
* glyph when it has none), then the package name with the hook points it answers at right
* beside it (one bare chip each — `stop`, `user_prompt` — wrapping with the name), its
* localized description below, and the trailing slot: the version, export and uninstall.
- * Export downloads the installed directory as a zip; the "Import hook" modal offers the
+ * Export downloads the installed directory as a zip, and a refused one leaves its reason under
+ * the row that asked (hook-export-refusal.ts); the "Import hook" modal offers the
* Skills tab's two paths: the recommended chat import (a source field taking a URL / repo /
* local path / description / another tool's hooks config, whose generated review-then-install
* prompt — hook-import.ts — can be copied or prefilled into a new chat with this Agent) and a
@@ -38,7 +39,6 @@ import {
SettingsEmpty,
SkeletonList,
Textarea,
- toastError,
toastSuccess,
useCopied,
} from "@adelie/ui";
@@ -46,12 +46,15 @@ import * as api from "../../api/endpoints";
import { ApiError } from "../../api/client";
import { S } from "../../lib/strings";
import { apiErrorText } from "../../lib/api-error";
+import { toneInk } from "../../lib/tone";
import { useLocale } from "../../state/locale";
import { agentDisplayName, useProject } from "../../state/project";
import { localizedText } from "../chat/skill-use";
import { SkillTile } from "../skills/skill-icon-view";
import { useAiBridge } from "../ai-create";
import { downloadArchive } from "./archive-download";
+import { hookExportRefusalFor, hookExportRefused } from "./hook-export-refusal";
+import type { HookExportRefusal } from "./hook-export-refusal";
import { buildHookImportPrompt } from "./hook-import";
import { usePromptInjection } from "./prompt-injection-controls";
import { UPLOAD_LABEL_CLASS } from "./skills-tab";
@@ -85,7 +88,8 @@ export function HooksTab({
});
const [hooks, setHooks] = useState<HookItem[] | null>(null);
- // Tab-level error is only the initial list load failure; row actions report via toast.
+ // Tab-level error is only the initial list load failure; row actions report in place (the
+ // export's reason under its row, an uninstall's inside its confirmation) or inside the modal.
const [error, setError] = useState<string | null>(null);
const [busy, setBusy] = useState(false);
// Package name pending uninstall confirmation (non-null shows the confirm modal).
@@ -93,6 +97,9 @@ export function HooksTab({
// The words for an uninstall the server refused, drawn inside the confirmation that asked for
// it (see confirmRemove): retrying is the next thing the person does, and the button is in there.
const [removeRefusal, setRemoveRefusal] = useState<string | null>(null);
+ // The words for an export that did not land, drawn in the row that asked (hook-export-refusal.ts):
+ // the row, the package and the same button are still there, which a six-second toast is not.
+ const [exportRefusal, setExportRefusal] = useState<HookExportRefusal | null>(null);
// Import modal: the source for the chat-import prompt + upload state travel with the modal.
const [importOpen, setImportOpen] = useState(false);
const [source, setSource] = useState("");
@@ -126,13 +133,20 @@ export function HooksTab({
const agent = agents.find((a) => a.agentId === agentId);
const agentName = agent ? agentDisplayName(agent) : agentId;
- /** "Export as zip": the shared archive download (archive-download.ts); a failure surfaces as a toast. */
+ /**
+ * "Export as zip": the shared archive download (archive-download.ts). A refused one leaves its
+ * reason in the row that asked (hook-export-refusal.ts) — the row, the package and the same
+ * button are all still there, so a toast that dismisses itself after six seconds is the one
+ * thing that would carry that reason away. Starting an attempt clears the previous sentence:
+ * it belonged to the attempt before, not to the package this one is about.
+ */
const exportHook = async (name: string) => {
if (!projectId) return;
+ setExportRefusal(null);
try {
await downloadArchive(api.agentHookArchiveUrl(projectId, agentId, name), name);
} catch (e) {
- toastError(apiErrorText(e));
+ setExportRefusal({ hook: name, text: hookExportRefused(name, e) });
}
};
@@ -277,71 +291,91 @@ export function HooksTab({
<Card padding="none">
{hooks.map((hook) => {
const description = localizedText(locale, hook.description, hook.descriptionZh);
+ // One refusal, one row: an attempt supersedes the reason of the attempt before it.
+ const refusal = hookExportRefusalFor(exportRefusal, hook.name);
return (
+ // The row is a column so a refused export can put its reason under the line that
+ // asked for it, without pushing any other row sideways (the Skills tab's shape).
<div
key={hook.name}
- className="flex items-center gap-3 border-b border-gray-100 px-3 py-2.5 transition-colors duration-150 last:border-b-0 hover:bg-gray-50 dark:border-gray-800/60 dark:hover:bg-gray-800/40"
+ className="border-b border-gray-100 last:border-b-0 dark:border-gray-800/60"
>
- <SkillTile
- icon={hook.icon}
- name={hook.name}
- fallback={ICONS.fishHook}
- size={36}
- glyph={20}
- />
- <div className="min-w-0 flex-1">
- {/* Title row: the name with the hook points it answers at right beside it — bare
- point names, wrapping onto a second line rather than truncating. */}
- <div className="flex flex-wrap items-center gap-x-1.5 gap-y-1">
+ <div className="flex items-center gap-3 px-3 py-2.5 transition-colors duration-150 hover:bg-gray-50 dark:hover:bg-gray-800/40">
+ <SkillTile
+ icon={hook.icon}
+ name={hook.name}
+ fallback={ICONS.fishHook}
+ size={36}
+ glyph={20}
+ />
+ <div className="min-w-0 flex-1">
+ {/* Title row: the name with the hook points it answers at right beside it — bare
+ point names, wrapping onto a second line rather than truncating. */}
+ <div className="flex flex-wrap items-center gap-x-1.5 gap-y-1">
+ <span
+ className="max-w-full truncate font-mono text-[length:var(--ui-text-code-size)] font-semibold"
+ data-tooltip={hook.name}
+ data-tooltip-content="code"
+ >
+ {hook.name}
+ </span>
+ {hook.events.map((event) => (
+ <Badge key={event}>{event}</Badge>
+ ))}
+ </div>
+ {/* Description truncates to one line (the full text goes into title for hover reading). */}
+ <p
+ className="mt-0.5 truncate text-xs text-gray-500 dark:text-gray-400"
+ data-tooltip={description}
+ data-tooltip-content="text"
+ >
+ {description}
+ </p>
+ </div>
+ {hook.version !== "" && (
<span
- className="max-w-full truncate font-mono text-[length:var(--ui-text-code-size)] font-semibold"
- data-tooltip={hook.name}
- data-tooltip-content="code"
+ className="hidden shrink-0 text-xs text-gray-400 sm:block dark:text-gray-500"
+ data-tooltip={hook.version}
>
- {hook.name}
+ {hook.version}
</span>
- {hook.events.map((event) => (
- <Badge key={event}>{event}</Badge>
- ))}
- </div>
- {/* Description truncates to one line (the full text goes into title for hover reading). */}
+ )}
+ {/* Icon-only row actions (the Skills tab's pair: neutral bordered icon for export,
+ danger variant with red text/hover for delete); the tooltip + aria-label carry the wording. */}
+ <Button
+ size="icon"
+ title={S.hooks.exportHook}
+ aria-label={`${S.hooks.exportHook} ${hook.name}`}
+ disabled={busy}
+ onClick={() => void exportHook(hook.name)}
+ >
+ <DownloadIcon size={14} className="text-gray-600 dark:text-gray-300" />
+ </Button>
+ <Button
+ size="icon"
+ variant="danger"
+ title={S.skills.uninstall}
+ aria-label={`${S.skills.uninstall} ${hook.name}`}
+ disabled={busy}
+ onClick={() => askRemove(hook.name)}
+ >
+ <GlyphIcon d={ICONS.trash} size={14} />
+ </Button>
+ </div>
+ {/* An export that did not land: this row still holds the button that retries it,
+ so the reason sits under it rather than in a notification that dismisses
+ itself (hook-export-refusal.ts). */}
+ {refusal !== undefined && (
<p
- className="mt-0.5 truncate text-xs text-gray-500 dark:text-gray-400"
- data-tooltip={description}
+ role="alert"
+ data-testid="hook-export-refusal"
+ data-tooltip={refusal}
data-tooltip-content="text"
+ className={`px-3 pb-2.5 line-clamp-2 break-words text-xs ${toneInk.danger}`}
>
- {description}
+ {refusal}
</p>
- </div>
- {hook.version !== "" && (
- <span
- className="hidden shrink-0 text-xs text-gray-400 sm:block dark:text-gray-500"
- data-tooltip={hook.version}
- >
- {hook.version}
- </span>
)}
- {/* Icon-only row actions (the Skills tab's pair: neutral bordered icon for export,
- danger variant with red text/hover for delete); the tooltip + aria-label carry the wording. */}
- <Button
- size="icon"
- title={S.hooks.exportHook}
- aria-label={`${S.hooks.exportHook} ${hook.name}`}
- disabled={busy}
- onClick={() => void exportHook(hook.name)}
- >
- <DownloadIcon size={14} className="text-gray-600 dark:text-gray-300" />
- </Button>
- <Button
- size="icon"
- variant="danger"
- title={S.skills.uninstall}
- aria-label={`${S.skills.uninstall} ${hook.name}`}
- disabled={busy}
- onClick={() => askRemove(hook.name)}
- >
- <GlyphIcon d={ICONS.trash} size={14} />
- </Button>
</div>
);
})}
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index 144d8fba..57369a1d 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -3108,6 +3108,9 @@ export const en: Strings = {
/** The agents page's hook-count stat (hover title / accessible name). */
hookCount: (n: number): string => (n === 1 ? "1 hook package" : `${n} hook packages`),
exportHook: "Export",
+ /** An export the download refused (hook-export-refusal.ts), drawn under the row that asked. */
+ exportRefused: (hook: string, reason: string): string =>
+ `The hook package ${hook} was not exported as a zip — it is still installed on this Agent: ${reason}`,
importHook: "Import hook",
importChatTitle: "Recommended: import it by chatting with the agent",
importChatWhy:
diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.ts
index dbf9ba6c..e0ef274a 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -3150,6 +3150,13 @@ export const zh = {
/** The agents page's hook-count stat (hover title / accessible name). */
hookCount: (n: number): string => `${n} 个钩子包`,
exportHook: "打包导出",
+ /**
+ * An export the download refused (hook-export-refusal.ts), drawn under the row that asked.
+ * Says the package is still installed because a failed export is when a reader wonders whether
+ * the files were touched; the reason goes last, as in every other refusal sentence.
+ */
+ exportRefused: (hook: string, reason: string): string =>
+ `钩子包 ${hook} 没有导出成 zip,它仍然装在这个 Agent 上:${reason}`,
importHook: "导入钩子",
importChatTitle: "推荐:让 Agent 在对话中导入",
importChatWhy:
diff --git a/packages/web/test/hook-export-refusal.test.ts b/packages/web/test/hook-export-refusal.test.ts
new file mode 100644
index 00000000..34334aad
--- /dev/null
+++ b/packages/web/test/hook-export-refusal.test.ts
@@ -0,0 +1,75 @@
+/**
+ * A hook package's export that did not land (src/features/agents/hook-export-refusal.ts): which
+ * words the row that asked draws, and which row draws them.
+ *
+ * The export writes nothing on the server and moves no client state, so a refusal leaves the row,
+ * the installed package and the same button on screen — the sentence is the only thing saying the
+ * zip was not saved. Three things it has to get right: an answer the server gave speaks the
+ * interface's own language rather than the wire message (7.19's rule), a failure this codebase
+ * raised itself keeps what it knows, and a package's refusal never shows up under another
+ * package's row.
+ */
+import { afterEach, describe, expect, it } from "vitest";
+import { ApiError } from "../src/api/client";
+import { S, setActiveStrings, zh as ZH } from "../src/lib/strings";
+import { en as EN } from "../src/lib/strings-en";
+import {
+ hookExportRefusalFor,
+ hookExportRefused,
+} from "../src/features/agents/hook-export-refusal";
+
+afterEach(() => {
+ setActiveStrings(ZH);
+});
+
+describe("hookExportRefused", () => {
+ it("reads a refusal through the code's own sentence, not the wire message", () => {
+ const line = hookExportRefused("shell-warden", new ApiError(500, "internal", "RAW ENGLISH"));
+ expect(line).not.toContain("RAW ENGLISH");
+ expect(line).toBe(S.hooks.exportRefused("shell-warden", S.errors.byCode.internal as string));
+ });
+
+ it("keeps what a failure that never reached the route has to say", () => {
+ expect(hookExportRefused("shell-warden", new Error("Failed to fetch"))).toBe(
+ S.hooks.exportRefused("shell-warden", "Failed to fetch"),
+ );
+ });
+
+ it("falls back to the generic text when the value has nothing to say", () => {
+ expect(hookExportRefused("shell-warden", undefined)).toBe(
+ S.hooks.exportRefused("shell-warden", S.common.unknownError),
+ );
+ });
+
+ it("names the hook package that was not exported", () => {
+ expect(hookExportRefused("shell-warden", new Error("boom"))).toContain("shell-warden");
+ });
+
+ it("says the package is still installed on the Agent", () => {
+ expect(hookExportRefused("shell-warden", new Error("boom"))).toContain("仍然装在这个 Agent 上");
+ });
+
+ it("speaks the active language", () => {
+ setActiveStrings(EN);
+ expect(hookExportRefused("shell-warden", new ApiError(500, "internal", "RAW"))).toBe(
+ EN.hooks.exportRefused("shell-warden", EN.errors.byCode.internal as string),
+ );
+ expect(hookExportRefused("shell-warden", new Error("boom"))).toContain("still installed");
+ });
+});
+
+describe("hookExportRefusalFor", () => {
+ const refusal = { hook: "shell-warden", text: "the sentence" };
+
+ it("gives the refusal to the row whose package it carries", () => {
+ expect(hookExportRefusalFor(refusal, "shell-warden")).toBe("the sentence");
+ });
+
+ it("leaves every other row alone", () => {
+ expect(hookExportRefusalFor(refusal, "session-log")).toBeUndefined();
+ });
+
+ it("draws nothing when the last attempt landed or none was made", () => {
+ expect(hookExportRefusalFor(null, "shell-warden")).toBeUndefined();
+ });
+});