A local-first multi-agent app development platform, built on PenguinHarness
fix(web): 卸载钩子包被拒时,确认框留着,原因也留在框里(7.28)
lmlihengf6f82fe79fbe
diff --git a/changelog/unreleased/2026-10-22-hook-uninstall-refusal.md b/changelog/unreleased/2026-10-22-hook-uninstall-refusal.mdnew file mode 100644index 00000000..57ecf90b--- /dev/null+++ b/changelog/unreleased/2026-10-22-hook-uninstall-refusal.md@@ -0,0 +1,39 @@+# A refused hook-package uninstall keeps its confirmation and the reason in it++- **Date:** 2026-10-22+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文版](2026-10-22-hook-uninstall-refusal.zh.md)++The Hooks tab of an Agent's settings asks before it uninstalls a package, and that card used to close in a+`finally` — whatever the answer. When the DELETE was refused, the package was still installed, on the page and+on disk, yet the reason arrived as a toast: six seconds, floating above the card, and the retry meant finding+the row again.++The card now closes only once the uninstall landed: a refusal draws the server's words under the card's+sentence, so the retry is the same button; the uninstall that succeeded closes it, toasts, re-reads the+installed list and refreshes the Agent list. Opening the card from a row's uninstall button clears the previous+reason first.++## Details++- The rule follows the model library, scheduled tasks, evaluation center, plugin market, conversation deletion,+ plugin settings, MCP Server and Skills-tab rounds (`ConfirmModal`'s `refusal` slot): the reason is drawn inside+ the card that asked, not in a toast that dismisses itself and sits above it.+- `features/agents/hooks-tab.tsx`: `confirmRemove` keeps the card open when `uninstallAgentHook` rejects and+ hands the message to a new `removeRefusal` state that the confirmation draws (`S.common.refused(...)`); a+ success clears the pending name, toasts, re-reads the tab and refreshes the Agent list provider. The row+ buttons and the card already carry `busy` while the request is in flight, so nothing can be pressed twice.+- New browser spec `e2e/hook-uninstall-refusal.spec.mjs` (two tests) against the package a fresh Agent ships+ (read from the API): a refused uninstall keeps the card, its sentence and the package, raises no toast, and+ reopening it does not carry the old reason over; confirming again with the request allowed closes the card,+ removes the row, and the server's installed list no longer holds it.++## Compatibility++- No API, wire-format, stored-data or dependency change: this is only when the card closes and where the reason+ is drawn.+- The import and overwrite flows on the same tab already report a rejection inside their own dialogs+ (`uploadError`), so nothing there changed.diff --git a/changelog/unreleased/2026-10-22-hook-uninstall-refusal.zh.md b/changelog/unreleased/2026-10-22-hook-uninstall-refusal.zh.mdnew file mode 100644index 00000000..5fecd6d0--- /dev/null+++ b/changelog/unreleased/2026-10-22-hook-uninstall-refusal.zh.md@@ -0,0 +1,30 @@+# 卸载钩子包被拒时,确认框留着,原因也留在框里++- **Date:** 2026-10-22+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[English](2026-10-22-hook-uninstall-refusal.md)++智能体设置的「钩子」页里,卸载一个钩子包要先确认,而那张卡片过去在 `finally` 里关掉 —— 不管答复是什么。被拒+的时候包在页面上与磁盘上都还装着,可原因却是一条 toast:六秒,浮在卡片上方,而重试要自己再去把那一行找回来。++现在卡片在**卸载真的落地之后**才关:被拒的请求把服务端的原话画在句子下面,重试就是同一个按钮;卸载成功的那+一次才关框、弹成功提示、重读一遍已装列表,并刷新智能体列表。从行上的卸载按钮打开卡片时先清掉上一次的原因。++## 细节++- 规则沿用模型库、定时任务、评估中心、插件市场、删除对话、插件设置、MCP Server 与技能页那几轮(`ConfirmModal`+ 的 `refusal` 槽):原因画在发起它的那张卡片里,而不是一条会自己消失、还浮在框上方的 toast。+- `features/agents/hooks-tab.tsx`:`confirmRemove` 在 `uninstallAgentHook` 被拒时留住卡片,把原话交给新的+ `removeRefusal` 状态,由确认框画出来(`S.common.refused(...)`);成功时才清掉待卸载的名字、弹成功提示、+ 重读本页并刷新智能体列表。写入在飞时行上的按钮与卡片本来就标着 `busy`,所以不会被连点。+- 新增浏览器用例 `e2e/hook-uninstall-refusal.spec.mjs`(两条,用的是新建智能体自带、从接口读出的那个钩子包):+ 被拒的卸载留着卡片、句子与那个包,不弹 toast,重新打开时不带旧原因;被拒之后再确认一次、这次放行 —— 卡片+ 关掉、行消失、服务器那份已装列表里也没有它。++## 兼容性++- 没有接口、传输格式、已存数据或依赖变化:只改了「框什么时候关」与「原因画在哪」。+- 同一页的导入与覆盖导入本来就把握手失败报在自己的对话框里(`uploadError`),未动。diff --git a/packages/web/e2e/hook-uninstall-refusal.spec.mjs b/packages/web/e2e/hook-uninstall-refusal.spec.mjsnew file mode 100644index 00000000..b801f440--- /dev/null+++ b/packages/web/e2e/hook-uninstall-refusal.spec.mjs@@ -0,0 +1,161 @@+/**+ * Regression: uninstalling a hook package on the Agent's Hooks tab asks first, and a refused+ * uninstall keeps that question — with the server's words inside it — instead of closing on the+ * way out of the request.+ *+ * `confirmRemove` used to close the card in `finally`, whatever the answer: when the DELETE was+ * refused, the package was still installed on the page and on disk, yet the reason arrived as a+ * toast that dismissed itself after six seconds and sat above the card. The card now closes only+ * once the uninstall landed; a refusal leaves it open with the reason drawn under its sentence+ * (`ConfirmModal`'s `refusal` slot), so the retry is the same button.+ *+ * The package is one the base installs on a fresh Agent (read from the API, not spelled out+ * here), and the refused DELETE 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 uninstall: its own words prove the reason came back into the card. */+const REFUSAL = {+ code: "agent_state_read_only",+ message: "agent state is read-only",+};++/**+ * 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 uninstall").toBeGreaterThan(0);+ return { projectId, name: names[0], installed };+}++/**+ * Take over the uninstall: every DELETE 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 interceptUninstall(page, state) {+ await page.route("**/api/projects/*/agents/*/hooks/*", async (route) => {+ if (route.request().method() !== "DELETE") return route.fallback();+ state.seen.push(new URL(route.request().url()).pathname.split("/").pop());+ if (!state.refuse) return route.fallback();+ await route.fulfill({+ status: 500,+ contentType: "application/json",+ body: JSON.stringify({ error: REFUSAL }),+ });+ });+}++/** The row's own uninstall button (its accessible name is the verb plus the package's name). */+const rowButton = (page, name) => page.getByRole("button", { name: `卸载 ${name}`, exact: true });++/** The row's button, then the shared confirmation (named by its own title). */+async function askRemove(page, name) {+ await rowButton(page, name).click();+ const dialog = page.getByRole("dialog", { name: `卸载 ${name}` });+ await expect(dialog).toBeVisible();+ return dialog;+}++/** The card's own text with the refusal line dropped — the only thing a refusal may change. */+async function cardText(card) {+ return (await card.innerText()).replace(/\n操作被拒绝:[^\n]*/, "");+}++/** The notification region: a refusal must not be announced there (that is the old toast). */+const notifications = (page) => page.getByRole("region", { name: "通知" });++test("a refused uninstall keeps the card, its sentence and the package", async ({ page }) => {+ const { name, installed } = await agentWithHook(page, "r110hookrefuse");+ const before = await installed();+ expect(before).toContain(name);++ const state = { seen: [], refuse: true };+ await interceptUninstall(page, state);++ await page.goto(`/agents/${AGENT}?tab=hooks`);+ await expect(rowButton(page, name)).toBeVisible();+ const dialog = await askRemove(page, name);+ const sentence = await cardText(dialog);+ expect(sentence).toContain(name);++ await dialog.getByRole("button", { name: "确认" }).click();++ // The reason is in the card that asked, and it is not a toast: the notification region holds+ // no dismissible button, and the card reads exactly as it did before the attempt plus one line.+ await expect(dialog.getByText(REFUSAL.message)).toBeVisible();+ await expect(notifications(page).getByRole("button")).toHaveCount(0);+ expect(state.seen).toEqual([name]);+ await expect(dialog).toBeVisible();+ expect(await cardText(dialog)).toBe(sentence);++ // Nothing was uninstalled anywhere: the row is still on the page and still installed on disk.+ await expect(rowButton(page, name)).toBeVisible();+ expect(await installed()).toEqual(before);++ // Closing the card decides nothing, and opening it again does not carry the old reason over.+ await dialog.getByRole("button", { name: "取消" }).click();+ await expect(dialog).toHaveCount(0);+ const reopened = await askRemove(page, name);+ await expect(reopened.getByText(REFUSAL.message)).toHaveCount(0);+});++test("the retry after a refused uninstall writes it, and only a written one closes the card", async ({+ page,+}) => {+ const { name, installed } = await agentWithHook(page, "r110hookretry");++ const state = { seen: [], refuse: true };+ await interceptUninstall(page, state);++ await page.goto(`/agents/${AGENT}?tab=hooks`);+ await expect(rowButton(page, name)).toBeVisible();+ const dialog = await askRemove(page, name);+ await dialog.getByRole("button", { name: "确认" }).click();+ await expect(dialog.getByText(REFUSAL.message)).toBeVisible();+ await expect(dialog).toBeVisible();+ expect(state.seen).toEqual([name]);++ // The retry is the same card; this time the uninstall lands: card gone, row gone, list without it.+ state.refuse = false;+ await dialog.getByRole("button", { name: "确认" }).click();+ await expect(dialog).toHaveCount(0);+ expect(state.seen).toEqual([name, name]);+ await expect(rowButton(page, name)).toHaveCount(0);+ expect(await installed()).not.toContain(name);+});diff --git a/packages/web/src/features/agents/hooks-tab.tsx b/packages/web/src/features/agents/hooks-tab.tsxindex c3be0b2b..a2253720 100644--- a/packages/web/src/features/agents/hooks-tab.tsx+++ b/packages/web/src/features/agents/hooks-tab.tsx@@ -90,6 +90,9 @@ export function HooksTab({const [busy, setBusy] = useState(false);// Package name pending uninstall confirmation (non-null shows the confirm modal).const [removing, setRemoving] = useState<string | null>(null);+ // 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);// Import modal: the source for the chat-import prompt + upload state travel with the modal.const [importOpen, setImportOpen] = useState(false);const [source, setSource] = useState("");@@ -133,22 +136,38 @@ export function HooksTab({}};- /** Confirm modal's "Confirm": uninstall, then always re-fetch the list from disk. */+ /**+ * A row's uninstall button: opens the confirmation without the previous attempt's reason —+ * that sentence belonged to the attempt before, not to the package this one is about.+ */+ const askRemove = (name: string) => {+ setRemoving(name);+ setRemoveRefusal(null);+ };++ /**+ * Confirm modal's "Confirm": uninstall, then always re-fetch the list from disk — but close the+ * card only once the uninstall landed. A refused one changes nothing on either side (the+ * package is still installed), so the card stays open with the server's words in it and the+ * same button retries; closing it as the request left used to carry that reason into a toast+ * that dismisses itself after six seconds and sits above the card.+ */const confirmRemove = async () => {if (!projectId || removing === null) return;setBusy(true);try {await api.uninstallAgentHook(projectId, agentId, removing);- toastSuccess(S.hooks.uninstalledToast(removing, agentName));- await load();- // The agent card's hook count (and its plugin-update marks) changed; refresh the list provider too.- void reloadAgents();} catch (e) {- toastError(apiErrorText(e));+ setRemoveRefusal(apiErrorText(e));+ return;} finally {setBusy(false);- setRemoving(null);}+ toastSuccess(S.hooks.uninstalledToast(removing, agentName));+ setRemoving(null);+ await load();+ // The agent card's hook count (and its plugin-update marks) changed; refresh the list provider too.+ void reloadAgents();};/** Open the import modal (reset the form and upload state). */@@ -319,7 +338,7 @@ export function HooksTab({title={S.skills.uninstall}aria-label={`${S.skills.uninstall} ${hook.name}`}disabled={busy}- onClick={() => setRemoving(hook.name)}+ onClick={() => askRemove(hook.name)}><GlyphIcon d={ICONS.trash} size={14} /></Button>@@ -420,7 +439,8 @@ export function HooksTab({</p></ConfirmModal>- {/* Uninstall confirmation (shared ConfirmModal, the Skills tab's pattern). */}+ {/* Uninstall confirmation (shared ConfirmModal, the Skills tab's pattern): a refusal keeps+ this card and shows the server's words in it. */}<ConfirmModalopen={removing !== null}title={removing !== null ? S.hooks.uninstallConfirmTitle(removing) : ""}@@ -429,6 +449,7 @@ export function HooksTab({onConfirm={() => void confirmRemove()}confirmLabel={S.common.confirm}cancelLabel={S.common.cancel}+ refusal={removeRefusal === null ? undefined : S.common.refused(removeRefusal)}><p className="text-sm text-gray-600 dark:text-gray-300">{removing !== null ? S.hooks.uninstallConfirmBody(removing, agentName) : ""}