A local-first multi-agent app development platform, built on PenguinHarness
fix(web): 卸载技能被拒时,确认框留着,原因也留在框里(7.27)
lmlihengbe9d96984c55
diff --git a/changelog/unreleased/2026-10-22-skill-uninstall-refusal.md b/changelog/unreleased/2026-10-22-skill-uninstall-refusal.mdnew file mode 100644index 00000000..40bab45c--- /dev/null+++ b/changelog/unreleased/2026-10-22-skill-uninstall-refusal.md@@ -0,0 +1,38 @@+# A refused skill uninstall keeps its confirmation and the reason in it++- **Date:** 2026-10-22+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文版](2026-10-22-skill-uninstall-refusal.zh.md)++The Skills tab of an Agent's settings asks before it uninstalls a skill, and that card used to close in a+`finally` — whatever the answer. When the DELETE was refused, the skill 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, and the uninstall that succeeded closes it, drops the sentence and+re-reads the installed list. Opening the card from a row's Remove button clears the previous reason first.++## Details++- The rule follows the model library, scheduled tasks, evaluation center, plugin market, conversation deletion,+ plugin settings and MCP Server 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/skills-tab.tsx`: `confirmRemove` keeps the card open when `removeAgentSkill` 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/skill-uninstall-refusal.spec.mjs` (two tests): a refused uninstall keeps the card, its+ sentence and the skill, 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 flow on the same tab reports a rejection inside the import dialog (`uploadError`) rather than in the+ overwrite card, so it already keeps the reason next to the retry; the Hooks tab's identical uninstall flow is+ unchanged and noted for its own round.diff --git a/changelog/unreleased/2026-10-22-skill-uninstall-refusal.zh.md b/changelog/unreleased/2026-10-22-skill-uninstall-refusal.zh.mdnew file mode 100644index 00000000..62e7b1cf--- /dev/null+++ b/changelog/unreleased/2026-10-22-skill-uninstall-refusal.zh.md@@ -0,0 +1,30 @@+# 卸载技能被拒时,确认框留着,原因也留在框里++- **Date:** 2026-10-22+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[English](2026-10-22-skill-uninstall-refusal.md)++智能体设置的「技能」页里,卸载一个技能要先确认,而那张卡片过去在 `finally` 里关掉 —— 不管答复是什么。被拒+的时候技能在页面上与磁盘上都还装着,可原因却是一条 toast:六秒,浮在卡片上方,而重试要自己再去把那一行找回来。++现在卡片在**卸载真的落地之后**才关:被拒的请求把服务端的原话画在句子下面,重试就是同一个按钮;卸载成功的那+一次才关框、清掉那句话,并重读一遍已装列表。从行上的「移除」打开卡片时先清掉上一次的原因。++## 细节++- 规则沿用模型库、定时任务、评估中心、插件市场、删除对话、插件设置与 MCP Server 那几轮(`ConfirmModal` 的+ `refusal` 槽):原因画在发起它的那张卡片里,而不是一条会自己消失、还浮在框上方的 toast。+- `features/agents/skills-tab.tsx`:`confirmRemove` 在 `removeAgentSkill` 被拒时留住卡片,把原话交给新的+ `removeRefusal` 状态,由确认框画出来(`S.common.refused(...)`);成功时才清掉待卸载的名字、弹成功提示、+ 重读本页并刷新智能体列表。写入在飞时行上的按钮与卡片本来就标着 `busy`,所以不会被连点。+- 新增浏览器用例 `e2e/skill-uninstall-refusal.spec.mjs`(两条):被拒的卸载留着卡片、句子与那个技能,不弹+ toast,重新打开时不带旧原因;被拒之后再确认一次、这次放行 —— 卡片关掉、行消失、服务器那份已装列表里也没有它。++## 兼容性++- 没有接口、传输格式、已存数据或依赖变化:只改了「框什么时候关」与「原因画在哪」。+- 同一页的导入流程把拒绝报在导入对话框里(`uploadError`),本来就把原因放在重试旁边,未动;钩子页那条同形的+ 卸载流程也照旧,留给它自己一轮。diff --git a/packages/web/e2e/skill-uninstall-refusal.spec.mjs b/packages/web/e2e/skill-uninstall-refusal.spec.mjsnew file mode 100644index 00000000..101d159b--- /dev/null+++ b/packages/web/e2e/skill-uninstall-refusal.spec.mjs@@ -0,0 +1,161 @@+/**+ * Regression: uninstalling a skill on the Agent's Skills 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 skill 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 skill is one the base ships with `default_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 skill 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 agentWithSkill(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}/skills`)+ ).json()+ ).skills.map((s) => s.name);++ const names = await installed();+ expect(names.length, "default_agent ships skills 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/*/skills/*", 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 skill'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 skill", async ({ page }) => {+ const { name, installed } = await agentWithSkill(page, "r109refuse");+ const before = await installed();+ expect(before).toContain(name);++ const state = { seen: [], refuse: true };+ await interceptUninstall(page, state);++ await page.goto(`/agents/${AGENT}?tab=skills`);+ 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 agentWithSkill(page, "r109retry");++ const state = { seen: [], refuse: true };+ await interceptUninstall(page, state);++ await page.goto(`/agents/${AGENT}?tab=skills`);+ 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/skills-tab.tsx b/packages/web/src/features/agents/skills-tab.tsxindex fa0d4312..2c17a05d 100644--- a/packages/web/src/features/agents/skills-tab.tsx+++ b/packages/web/src/features/agents/skills-tab.tsx@@ -92,6 +92,9 @@ export function SkillsTab({const [busy, setBusy] = useState(false);// Skill 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-install prompt + upload state travel with the modal.const [importOpen, setImportOpen] = useState(false);const [source, setSource] = useState("");@@ -135,22 +138,38 @@ export function SkillsTab({}};- /** 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 skill 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 skill+ * 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.removeAgentSkill(projectId, agentId, removing);- toastSuccess(`${S.skills.uninstalledToast(removing, agentName)}${S.agent.takesEffectSuffix}`);- await load();- // The agent card's skill count changed; refresh the list provider too.- void reloadAgents();} catch (e) {- toastError(apiErrorText(e));+ setRemoveRefusal(apiErrorText(e));+ return;} finally {setBusy(false);- setRemoving(null);}+ toastSuccess(`${S.skills.uninstalledToast(removing, agentName)}${S.agent.takesEffectSuffix}`);+ setRemoving(null);+ await load();+ // The agent card's skill count changed; refresh the list provider too.+ void reloadAgents();};/** Open the import modal (reset the form and upload state). */@@ -308,7 +327,7 @@ export function SkillsTab({label={`${S.skills.uninstall} ${skill.name}`}title={S.skills.uninstall}disabled={busy}- onClick={() => setRemoving(skill.name)}+ onClick={() => askRemove(skill.name)}><GlyphIcon d={ICONS.trash} size={14} /></IconButton>@@ -416,6 +435,7 @@ export function SkillsTab({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.skills.uninstallConfirmBody(removing, agentName) : ""}