Skip to content

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

fix(web): 删除插件、单 Agent 卸载与更新被拒时,确认框留着,原因也留在框里(7.29)

lmlihengd1ac2d277d5b
diff --git a/changelog/unreleased/2026-10-22-plugin-card-refusal.md b/changelog/unreleased/2026-10-22-plugin-card-refusal.md
new file mode 100644
index 00000000..e1b505cc
--- /dev/null
+++ b/changelog/unreleased/2026-10-22-plugin-card-refusal.md
@@ -0,0 +1,53 @@
+# A plugin card's three confirmations keep their question — and the reason — when the write is refused
+
+- **Date:** 2026-10-22
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文](2026-10-22-plugin-card-refusal.zh.md)
+
+Every card in the plugin library has three writes that ask first: **uninstall** this plugin from one Agent,
+**update** the copies that fell behind the library, and **delete** a user plugin from disk. All three
+confirmations used to settle on the request — two of them closed before it even went out — so a refusal
+left the installed files and the plugin's directory exactly as they were, while the reason only landed in
+a toast that dismissed itself after six seconds and sat above the card.
+
+All three now close only once the write landed; a refusal leaves the card open with the server's words
+drawn under its sentence, so the retry is the same button. Opening one from a card action clears the
+previous reason first — one attempt, one reason.
+
+## Details
+
+- The rule is the one the model library, schedules, the benchmark centre, the plugin market's module rows,
+ session deletion, MCP servers, the Skills tab and the Hooks tab already follow (`ConfirmModal`'s
+ `refusal` slot): the reason is drawn in the card that asked for the write.
+- `features/plugins/plugins-page.tsx`: `toggleInstall`, `updateOutdated` and `removePlugin` answer with a
+ `WriteOutcome` (the pair the model library introduced in 7.19) instead of raising a toast of their own —
+ the caller places the words in the card it still has. The card's paths without a confirmation (the
+ one-click install to an Agent, a manage-installs row's Install) raise the toast themselves, because
+ there is no card to keep there.
+- **Two writes are no longer optimistic**, both because an optimistic move unmounts the very card that
+ asked:
+ - Deleting a plugin no longer takes the card off the listing first. Removing it while the request is in
+ flight takes the question — and a refusal's reason — with it; the card goes once the directory is
+ gone, and the confirm button reads `busy` meanwhile.
+ - Uninstalling no longer moves the install snapshot before the answer. Dropping the current Agent's copy
+ flips the card to "not installed" and carries it into the other section, which remounts the card — and
+ that remount is the confirmation, and its reason, gone. The snapshot now moves after the answer; the
+ row reads "Installed" while it waits, which is also what a refused one leaves it at.
+- An update is a partial success: the Agents that took it keep their new installed state, the first
+ failure's words come back into the card, the ones still behind stay marked behind on the cards and in
+ the notice, and the retry sends the same set again.
+- New browser tests `e2e/plugin-card-refusal.spec.mjs` (three: delete / uninstall / update): a refusal
+ keeps the dialog, its sentence and the card or row, leaves the notification region without a toast, and
+ reopening does not carry the old reason; only the retry that lands closes the dialog (and takes the card
+ with it, in the delete case). The library and the installed list are fixtures (a development data root
+ ships no user plugin) and the three writes are taken over by `page.route`.
+
+## Compatibility
+
+- No interface, wire-format, stored-data or dependency change: only *when* the card closes and *where* the
+ reason is drawn.
+- The plugin market's bulk-update confirmation is not part of this change: it is a partial success, and
+ naming which Agents did not take it is a separate piece of work.
diff --git a/changelog/unreleased/2026-10-22-plugin-card-refusal.zh.md b/changelog/unreleased/2026-10-22-plugin-card-refusal.zh.md
new file mode 100644
index 00000000..fa171c8b
--- /dev/null
+++ b/changelog/unreleased/2026-10-22-plugin-card-refusal.zh.md
@@ -0,0 +1,39 @@
+# 插件卡上的三张确认框:被拒时框留着,原因也留在框里
+
+- **Date:** 2026-10-22
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[English](2026-10-22-plugin-card-refusal.md)
+
+插件市场每张卡片有三个要先问一声的写入:从某个智能体**卸载**这份插件、把落在后面的副本**更新**、把用户插件
+从磁盘上**删除**。三张确认框过去都在请求发出时(或发出之前)就关:被拒的时候装上/装着的文件、以及插件目录
+一点没变,原因却只在一条六秒后自己消失、还浮在框上方的 toast 里。
+
+现在三张框都在**写入真的落地之后**才关:被拒的请求把服务端的原话画在句子下面,重试就是同一个按钮;从卡片
+上的按钮打开框时先清掉上一次的原因(一次尝试一条原因)。
+
+## 细节
+
+- 规则沿用模型库、定时任务、评估中心、插件市场模块行、删除对话、MCP Server、技能页与钩子页那几轮
+ (`ConfirmModal` 的 `refusal` 槽):原因画在发起它的那张卡片里。
+- `features/plugins/plugins-page.tsx`:`toggleInstall`、`updateOutdated`、`removePlugin` 三个写入改为回
+ `WriteOutcome`(模型库 7.19 那一对类型)而不是自己弹 toast —— 原因由调用方放在它手里那张卡片里。卡片上
+ 没有确认的那条路(一键安装到某个智能体、管理安装里的一行「安装」)自己弹 toast,因为那里没有框可留。
+- **两处不再「先斩后奏」**,都是因为优化更新会把发起它的那张框掀掉:
+ - 删除插件不再先把卡片从列表里抹掉。卡片就是发问的那张,请求在飞时把它摘掉等于把问题(和被拒的原因)
+ 一起摘掉;现在目录真的删掉之后卡片才走,等待期间确认按钮标 `busy`。
+ - 卸载不再在请求发出时先动已装快照。把它从当前智能体的快照里抹掉会让卡片翻成「未安装」并挪到另一个
+ 分区,卡片随之重挂 —— 重挂的那一瞬确认框与原因都没了。现在快照在答复之后才动,行在等待期间保持
+ 「已安装」,被拒时也正是它该在的状态。
+- 更新是部分成功:落地的那几个智能体保留新的已装状态,第一个失败的原话回到框里,落后的那几个在卡片与
+ 提示条上仍旧标着落后,重试发的还是同一批。
+- 新增浏览器用例 `e2e/plugin-card-refusal.spec.mjs`(三条:删除 / 卸载 / 更新):被拒时框、句子与
+ 卡片/行都在,通知区没有 toast,重新打开不带旧原因;放行重试时框才关(删除时卡片也会消失)。
+ 插件库与已装列表用夹具(开发数据根没有用户插件),三条写入由 `page.route` 接管。
+
+## 兼容性
+
+- 没有接口、传输格式、已存数据或依赖变化:只改了「框什么时候关」与「原因画在哪」。
+- 插件市场那张「批量更新」的确认框不在这一笔里:它是部分成功,要讲清「哪些没更新」是另一件事。
diff --git a/packages/web/e2e/plugin-card-refusal.spec.mjs b/packages/web/e2e/plugin-card-refusal.spec.mjs
new file mode 100644
index 00000000..192d9b5f
--- /dev/null
+++ b/packages/web/e2e/plugin-card-refusal.spec.mjs
@@ -0,0 +1,284 @@
+/**
+ * Regression: a plugin card's three confirmations — uninstall a copy from one Agent, update the
+ * copies that are behind the library, delete the plugin from disk — ask first, and a write the
+ * server refused keeps that question, with the server's words inside it, instead of closing on
+ * the way out of the request.
+ *
+ * All three used to settle on the request rather than on the answer (`confirmUninstall` and
+ * `confirmDelete` closed the card before the write went out, `confirmUpdate` in sequence with
+ * it): when the server refused, the installed files and the plugin's directory were exactly as
+ * they were, yet the reason arrived as a toast that dismissed itself after six seconds and sat
+ * above the card. Each card now closes only once the write 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 library listing is stubbed: a development data root ships no user plugin, and the delete
+ * (admin-only) needs one. The writes the tests measure are the page's own requests — DELETE /api/
+ * plugins/:name, DELETE …/skills/:name and POST …/plugins — while everything else stays real.
+ */
+import { test, expect } from "@playwright/test";
+import { ADMIN_ID, ADMIN_PASSWORD, login } from "./auth.mjs";
+
+const BASE = process.env.BASE_URL;
+const AGENT = "default_agent";
+
+/** The plugin under test: a user plugin, so its card carries the admin's delete. */
+const PLUGIN = {
+ source: "user",
+ name: "probe-plugin",
+ description: "A probe plugin.",
+ descriptionZh: "一个探针插件。",
+ version: "2026.10.22.1",
+ skills: [
+ {
+ name: "probe-skill",
+ description: "A probe skill.",
+ descriptionZh: "一个探针技能。",
+ version: "2026.10.22.1",
+ },
+ ],
+ hooks: [],
+};
+
+/** What each refused write answers: its own words prove the reason came back into the card. */
+const DELETE_REFUSAL = { code: "plugin_store_read_only", message: "plugin store is read-only" };
+const AGENT_REFUSAL = { code: "agent_state_read_only", message: "agent state is read-only" };
+
+const notifications = (page) => page.getByRole("region", { name: "通知" });
+
+/** The page's own text with a refusal line dropped — the only thing a refusal may add. */
+async function cardText(card) {
+ return (await card.innerText()).replace(/\n操作被拒绝:[^\n]*/g, "");
+}
+
+const refuseWith = (route, refusal) =>
+ route.fulfill({
+ status: 500,
+ contentType: "application/json",
+ body: JSON.stringify({ error: refusal }),
+ });
+
+/** A read answered from a fixture. */
+const answer = (route, body) =>
+ route.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify(body) });
+
+/** The library as the page reads it: one user plugin, which is the card the tests act on. */
+async function stubLibrary(page) {
+ await page.route("**/api/plugins", async (route) => {
+ if (new URL(route.request().url()).pathname !== "/api/plugins") return route.fallback();
+ if (route.request().method() !== "GET") return route.fallback();
+ await answer(route, {
+ groups: [{ id: "probe", title: "Probe", titleZh: "探针", plugins: [PLUGIN] }],
+ });
+ });
+}
+
+/**
+ * The plugin's copies, as the page's install snapshot reads them: the skill is installed on every
+ * Agent, so the card's state, its manage-installs rows and its update reminder all describe a
+ * plugin this Project holds.
+ */
+async function stubInstalled(page) {
+ await page.route("**/api/projects/*/agents/*/skills", async (route) => {
+ if (route.request().method() !== "GET") return route.fallback();
+ await answer(route, { skills: PLUGIN.skills });
+ });
+}
+
+/**
+ * Take over the plugin delete; `state.refuse` is flipped by the retry half, and `state.writes`
+ * keeps every delete so the tests can tell how many were sent. A written one answers 204, which
+ * is what the real route returns.
+ */
+async function stubDelete(page, state) {
+ await page.route("**/api/plugins/*", async (route) => {
+ if (route.request().method() !== "DELETE") return route.fallback();
+ state.writes.push(new URL(route.request().url()).pathname);
+ if (state.refuse) return refuseWith(route, DELETE_REFUSAL);
+ await route.fulfill({ status: 204 });
+ });
+}
+
+/** Take over the per-Agent uninstall (one DELETE per part; this plugin ships one skill). */
+async function stubUninstall(page, state) {
+ await page.route("**/api/projects/*/agents/*/skills/*", async (route) => {
+ if (route.request().method() !== "DELETE") return route.fallback();
+ state.writes.push(new URL(route.request().url()).pathname);
+ if (state.refuse) return refuseWith(route, AGENT_REFUSAL);
+ await route.fulfill({ status: 204 });
+ });
+}
+
+/** Take over the reinstall that an update is. */
+async function stubUpdate(page, state) {
+ await page.route("**/api/projects/*/agents/*/plugins", async (route) => {
+ if (route.request().method() !== "POST") return route.fallback();
+ state.writes.push(route.request().postDataJSON());
+ if (state.refuse) return refuseWith(route, AGENT_REFUSAL);
+ await answer(route, { skills: PLUGIN.skills, hooks: [] });
+ });
+}
+
+/**
+ * Serve the Agent list with this plugin marked as behind the library on `AGENT`: `pluginUpdates`
+ * is the server's own comparison of an installed copy against ITS plugin directory, which the
+ * stubbed library above cannot move, so it is edited into the real summaries here. Everything
+ * else on those summaries stays as the server sent it.
+ */
+async function stubOutdatedAgent(page) {
+ const projectId = (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0]
+ .projectId;
+ const list = await (await page.request.get(`${BASE}/api/projects/${projectId}/agents`)).json();
+ for (const agent of list.agents) {
+ if (agent.agentId !== AGENT) continue;
+ agent.pluginUpdates = [
+ ...(agent.pluginUpdates ?? []),
+ { name: PLUGIN.name, version: PLUGIN.version },
+ ];
+ }
+ await page.route("**/api/projects/*/agents**", async (route) => {
+ if (route.request().method() !== "GET") return route.fallback();
+ if (!new URL(route.request().url()).pathname.endsWith("/agents")) return route.fallback();
+ await answer(route, list);
+ });
+}
+
+/** The card's own actions (their accessible names are the verb plus the plugin's name). */
+const deleteButton = (page) =>
+ page.getByRole("button", { name: `删除插件 ${PLUGIN.name}`, exact: true });
+const manageButton = (page) =>
+ page.getByRole("button", { name: `管理安装 ${PLUGIN.name}`, exact: true });
+const updateButton = (page) =>
+ page.getByRole("button", {
+ name: `有新版本:更新 1 个 Agent 的安装 ${PLUGIN.name}`,
+ exact: true,
+ });
+const search = (page) => page.getByRole("searchbox", { name: "搜索插件" });
+
+/** The confirmation a card action opens, named by its own title. */
+async function openDialog(page, click, title) {
+ await click();
+ const dialog = page.getByRole("dialog", { name: title });
+ await expect(dialog).toBeVisible();
+ return dialog;
+}
+
+test("a refused plugin delete keeps the question, the reason and the card", async ({ page }) => {
+ await login(page.request, ADMIN_ID, ADMIN_PASSWORD);
+ const state = { writes: [], refuse: true };
+ await stubLibrary(page);
+ await stubDelete(page, state);
+
+ await page.goto("/plugins");
+ await expect(deleteButton(page)).toBeVisible();
+ const dialog = await openDialog(page, () => deleteButton(page).click(), `删除 ${PLUGIN.name}`);
+ const sentence = await cardText(dialog);
+ expect(sentence).toContain(PLUGIN.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(DELETE_REFUSAL.message)).toBeVisible();
+ await expect(notifications(page).getByRole("button")).toHaveCount(0);
+ expect(state.writes).toEqual([`/api/plugins/${PLUGIN.name}`]);
+ await expect(dialog).toBeVisible();
+ expect(await cardText(dialog)).toBe(sentence);
+
+ // Nothing was deleted: the card is still on the page, so the plugin is still there to retry on.
+ await expect(deleteButton(page)).toBeVisible();
+
+ // 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 openDialog(page, () => deleteButton(page).click(), `删除 ${PLUGIN.name}`);
+ await expect(reopened.getByText(DELETE_REFUSAL.message)).toHaveCount(0);
+
+ // The retry is the same card; this time the delete lands: card gone, action gone.
+ state.refuse = false;
+ await reopened.getByRole("button", { name: "删除插件" }).click();
+ await expect(reopened).toHaveCount(0);
+ expect(state.writes).toHaveLength(2);
+ await expect(deleteButton(page)).toHaveCount(0);
+});
+
+test("a refused uninstall keeps the question, the reason and the installed copy", async ({
+ page,
+}) => {
+ await login(page.request, ADMIN_ID, ADMIN_PASSWORD);
+ const state = { writes: [], refuse: true };
+ await stubLibrary(page);
+ await stubInstalled(page);
+ await stubUninstall(page, state);
+
+ await page.goto("/plugins");
+ // The plugin is installed, so its card sits in the folded section: a search opens both.
+ await search(page).fill(PLUGIN.name);
+ await expect(manageButton(page)).toBeVisible();
+ await manageButton(page).click();
+ const row = page.getByRole("dialog", { name: `管理安装:${PLUGIN.name}` });
+ await expect(row).toBeVisible();
+ const dialog = await openDialog(
+ page,
+ () => row.getByRole("button", { name: `卸载 ${AGENT}`, exact: true }).click(),
+ `卸载 ${PLUGIN.name}`,
+ );
+ const sentence = await cardText(dialog);
+ expect(sentence).toContain(PLUGIN.name);
+
+ await dialog.getByRole("button", { name: "卸载", exact: true }).click();
+
+ await expect(dialog.getByText(AGENT_REFUSAL.message)).toBeVisible();
+ await expect(notifications(page).getByRole("button")).toHaveCount(0);
+ // One DELETE for the plugin's one skill, aimed at the Agent the row named.
+ expect(state.writes).toHaveLength(1);
+ expect(state.writes[0].endsWith(`/agents/${AGENT}/skills/${PLUGIN.skills[0].name}`)).toBe(true);
+ await expect(dialog).toBeVisible();
+ expect(await cardText(dialog)).toBe(sentence);
+
+ // Nothing was uninstalled: the row still offers the uninstall the card just refused.
+ await expect(row.getByRole("button", { name: `卸载 ${AGENT}`, exact: true })).toBeVisible();
+
+ // The retry is the same card; this time the uninstall lands and the card closes.
+ state.refuse = false;
+ await dialog.getByRole("button", { name: "卸载", exact: true }).click();
+ await expect(dialog).toHaveCount(0);
+ expect(state.writes).toHaveLength(2);
+ // The copy left the Agent the page works with, so the card itself moved to the other section —
+ // that remount is why the manage-installs list closes with it, and the card now offers to
+ // install the plugin to that Agent instead.
+ await expect(row).toHaveCount(0);
+ await expect(
+ page.getByRole("button", { name: new RegExp(`^安装到 .+ ${PLUGIN.name}$`) }),
+ ).toBeVisible();
+});
+
+test("a refused update keeps the question, the reason and the installed copy", async ({ page }) => {
+ await login(page.request, ADMIN_ID, ADMIN_PASSWORD);
+ const state = { writes: [], refuse: true };
+ await stubLibrary(page);
+ await stubInstalled(page);
+ await stubOutdatedAgent(page);
+ await stubUpdate(page, state);
+
+ await page.goto("/plugins");
+ await search(page).fill(PLUGIN.name);
+ await expect(updateButton(page)).toBeVisible();
+ const dialog = await openDialog(page, () => updateButton(page).click(), `更新 ${PLUGIN.name}`);
+ const sentence = await cardText(dialog);
+ expect(sentence).toContain(PLUGIN.name);
+
+ await dialog.getByRole("button", { name: "更新", exact: true }).click();
+
+ await expect(dialog.getByText(AGENT_REFUSAL.message)).toBeVisible();
+ await expect(notifications(page).getByRole("button")).toHaveCount(0);
+ expect(state.writes).toEqual([{ names: [PLUGIN.name] }]);
+ await expect(dialog).toBeVisible();
+ expect(await cardText(dialog)).toBe(sentence);
+
+ // The retry is the same card; this time the reinstall lands and the card closes.
+ state.refuse = false;
+ await dialog.getByRole("button", { name: "更新", exact: true }).click();
+ await expect(dialog).toHaveCount(0);
+ expect(state.writes).toHaveLength(2);
+});
diff --git a/packages/web/e2e/skills.spec.mjs b/packages/web/e2e/skills.spec.mjs
index 75fb2e98..4619c077 100644
--- a/packages/web/e2e/skills.spec.mjs
+++ b/packages/web/e2e/skills.spec.mjs
@@ -185,8 +185,13 @@ test("skills: library list and cards -> manage-install Modal -> quick-invoke pre
// Clicking "已安装" ("Installed") uninstalls: it deletes installed files, so the row
// button only opens the confirmation; confirming flips back to "安装" ("Install").
await uninstallHelper.click();
- await page.getByRole("dialog").getByRole("button", { name: "卸载", exact: true }).click();
+ const uninstallConfirm = page.getByRole("dialog", { name: "卸载 data-analysis" });
+ await uninstallConfirm.getByRole("button", { name: "卸载", exact: true }).click();
await expect(page.getByRole("button", { name: "安装 agent_helper" })).toBeVisible();
+ // The confirmation closes on the ANSWER, not on the request (see plugin-card-refusal.spec.mjs),
+ // so the row flipping and the card leaving are two commits: wait the card out before Escape,
+ // otherwise that press closes the confirmation and leaves this Modal standing.
+ await expect(uninstallConfirm).toHaveCount(0);
// Escape closes the Modal (built into the Modal).
await page.keyboard.press("Escape");
await expect(dialog).toHaveCount(0);
diff --git a/packages/web/src/features/plugins/plugins-page.tsx b/packages/web/src/features/plugins/plugins-page.tsx
index 75b87f01..cfab4d39 100644
--- a/packages/web/src/features/plugins/plugins-page.tsx
+++ b/packages/web/src/features/plugins/plugins-page.tsx
@@ -39,8 +39,11 @@
* not-installed shows "Install", installed shows "Installed" (hover switches to
* "Uninstall", click to uninstall); any member can operate it; optimistic update, a
* top-level toast on success for install/uninstall, rollback plus a toast on failure.
- * Installed means the whole plugin is: every one of its skills is in the Agent's installed
- * skills and, when it ships a hook package, that package is in the Agent's installed hooks —
+ * A refusal is not always a toast: the two writes the card asks about first (uninstall,
+ * update) keep their confirmation open with the server's words inside it — see the
+ * PluginCard's three confirmations. Installed means the whole plugin is: every one of its
+ * skills is in the Agent's installed skills and, when it ships a hook package, that package is
+ * in the Agent's installed hooks —
* which is why the page fetches both lists per Agent. Uninstall takes the plugin apart the
* same way: one DELETE per skill and one for the hook package.
*/
@@ -100,6 +103,7 @@ import { draftKey, loadDraft, saveDraft } from "../chat/draft-cache";
import { prepareNewChatDraft } from "../chat/new-chat";
import { localizedShortText, localizedText } from "../chat/skill-use";
import { downloadArchive } from "../agents/archive-download";
+import type { WriteOutcome } from "../models/write-outcome";
import { PluginDetailModal } from "./plugin-detail";
import { PluginImportActions } from "./plugin-import-dialog";
import { pluginImportErrorText } from "./plugin-import";
@@ -517,16 +521,33 @@ export function PluginsPage() {
/**
* Install / uninstall on one Agent (any member can do this): optimistic update, a
- * confirmation toast on success, rollback plus a toast on failure. Install is one request for
+ * confirmation toast on success, rollback on failure. Install is one request for
* the whole plugin; uninstall takes it apart — one DELETE per skill and one for the hook
* package — since the server offers no plugin-level delete, and a plugin's parts are what an
* Agent actually holds. The Agent list is re-read afterwards either way: the card's counts
* and its `pluginUpdates` moved, and both are read off that list.
+ *
+ * The answer is a {@link WriteOutcome} rather than a toast: uninstall is asked about first, so
+ * a refusal belongs in the card that asked (its retry button is there). The install paths have
+ * no card to keep — the card's one-click button and a manage-installs row's toggle — and they
+ * add the toast themselves; nothing is toasted here.
+ *
+ * Only an install moves the snapshot before the answer. An uninstall waits for it: removing the
+ * current Agent's copy on the way out flips the card to "not installed" and carries it into the
+ * other section, which unmounts the very confirmation that asked — and with it a refusal's
+ * reason. The row reads "Installed" until the answer arrives, which is also what a refused one
+ * leaves it at.
*/
- const toggleInstall = async (agentId: string, plugin: PluginItem, on: boolean) => {
- if (!projectId) return;
+ const toggleInstall = async (
+ agentId: string,
+ plugin: PluginItem,
+ on: boolean,
+ ): Promise<WriteOutcome> => {
+ // Unreachable through the page (it renders nothing without a Project, and every caller is
+ // behind that gate). The generic sentence is what a write that never left would report.
+ if (!projectId) return { ok: false, reason: S.common.unknownError };
const prev = installed.get(agentId) ?? NO_INSTALLS;
- setAgentInstalls(agentId, withPlugin(prev, plugin, on));
+ if (on) setAgentInstalls(agentId, withPlugin(prev, plugin, on));
const target = agents.find((a) => a.agentId === agentId);
const agentName = target ? agentDisplayName(target) : agentId;
try {
@@ -552,39 +573,44 @@ export function PluginsPage() {
? [api.uninstallAgentHook(projectId, agentId, plugin.name).catch(gone)]
: []),
]);
+ setAgentInstalls(agentId, withPlugin(prev, plugin, false));
toastSuccess(
`${S.plugins.uninstalledToast(plugin.name, agentName)}${S.agent.takesEffectSuffix}`,
);
}
} catch (e) {
setAgentInstalls(agentId, prev);
- toastError(apiErrorText(e));
- return;
+ return { ok: false, reason: apiErrorText(e) };
}
void reloadAgents();
+ return { ok: true };
};
/**
* Update reminder action: reinstall the current library copy on every outdated Agent
* (install-again-is-update semantics). One success toast for the whole batch; on partial
- * failure the succeeded Agents keep their calibrated state and the first error is toasted.
+ * failure the Agents that took it keep their calibrated state, and the first error comes back
+ * to the card that asked for the update — the ones that stayed behind are still marked behind
+ * on the cards and in the notice, and retrying sends the same set again.
*/
- const updateOutdated = async (name: string, agentIds: string[]) => {
- if (!projectId || agentIds.length === 0) return;
+ const updateOutdated = async (name: string, agentIds: string[]): Promise<WriteOutcome> => {
+ // Unreachable through the page (the card only draws an update with an Agent behind it).
+ if (!projectId || agentIds.length === 0) return { ok: true };
const results = await Promise.allSettled(
agentIds.map(async (agentId) => {
const res = await api.installAgentPlugins(projectId, agentId, [name]);
setAgentInstalls(agentId, installsOf(res.skills, res.hooks));
}),
);
- const failed = results.find((r): r is PromiseRejectedResult => r.status === "rejected");
- if (!failed) toastSuccess(S.plugins.updatedToast(name, agentIds.length));
- else toastError(apiErrorText(failed.reason));
// The outdated marks and the nav badge are both read off `AgentSummary.pluginUpdates`,
// which this page's install map does not feed: without reloading the Agent list the dot
// would survive the very update it led the user to. Runs after a partial failure too —
// some Agent moved.
void reloadAgents();
+ const failed = results.find((r): r is PromiseRejectedResult => r.status === "rejected");
+ if (failed) return { ok: false, reason: apiErrorText(failed.reason) };
+ toastSuccess(S.plugins.updatedToast(name, agentIds.length));
+ return { ok: true };
};
/**
@@ -679,13 +705,23 @@ export function PluginsPage() {
};
/**
- * Delete one user plugin (admin-only server-side): optimistic on the local listing — the card
- * goes at once, the way install/uninstall move the install snapshot — and rolled back with a
- * toast when the server refuses (a built-in name, or a right the account no longer has). The
- * directory line is re-read afterwards, since the on-disk directory is what it reports.
+ * Delete one user plugin (admin-only server-side). The directory line is re-read afterwards,
+ * since the on-disk directory is what it reports.
+ *
+ * The card leaves the listing only once the directory is gone — no longer optimistically on the
+ * way out: it is the card that asked for the delete, and taking it off the page as the request
+ * left unmounts that confirmation, so a refusal had nothing left to put its reason in. The
+ * confirm button reads busy meanwhile, which is what the wait looks like.
+ *
+ * The refusal comes back as a {@link WriteOutcome} instead of a toast for the same reason: the
+ * card that asked still has the button that retries it.
*/
- const removePlugin = async (plugin: PluginItem) => {
- const prev = groups;
+ const removePlugin = async (plugin: PluginItem): Promise<WriteOutcome> => {
+ try {
+ await api.deletePlugin(plugin.name);
+ } catch (e) {
+ return { ok: false, reason: pluginImportErrorText(e) };
+ }
setGroups(
(current) =>
current
@@ -697,15 +733,9 @@ export function PluginsPage() {
// the server's, and an empty section would stand under the title until the next load.
.filter((group) => group.plugins.length > 0) ?? current,
);
- try {
- await api.deletePlugin(plugin.name);
- toastSuccess(S.plugins.deletedToast(plugin.name));
- } catch (e) {
- setGroups(prev);
- toastError(pluginImportErrorText(e));
- return;
- }
+ toastSuccess(S.plugins.deletedToast(plugin.name));
await reloadDirectory();
+ return { ok: true };
};
// The library's rows, divided by what the Agent the page is working with holds (the value
@@ -1520,10 +1550,10 @@ function PluginCard({
/** Whether this account may delete, which is the account's admin right and not a Project role (see the page header). */
canDelete: boolean;
onQuickInvoke: (skillName: string) => void;
- onToggleInstall: (agentId: string, plugin: PluginItem, on: boolean) => Promise<void>;
- onUpdateOutdated: (name: string, agentIds: string[]) => Promise<void>;
+ onToggleInstall: (agentId: string, plugin: PluginItem, on: boolean) => Promise<WriteOutcome>;
+ onUpdateOutdated: (name: string, agentIds: string[]) => Promise<WriteOutcome>;
onExport: (name: string) => Promise<void>;
- onDelete: (plugin: PluginItem) => Promise<void>;
+ onDelete: (plugin: PluginItem) => Promise<WriteOutcome>;
}) {
const { locale } = useLocale();
const { agents, currentAgent } = useProject();
@@ -1533,17 +1563,77 @@ function PluginCard({
const [updating, setUpdating] = useState(false);
// Agent pending an uninstall confirmation (null = none): uninstalling deletes the installed files, local edits included.
const [pendingUninstall, setPendingUninstall] = useState<string | null>(null);
+ const [uninstalling, setUninstalling] = useState(false);
// Whether this card's delete confirmation is open: deleting a user plugin removes its directory from disk, so it confirms first, like the uninstall above.
const [deleteOpen, setDeleteOpen] = useState(false);
+ const [deleting, setDeleting] = useState(false);
+ /**
+ * The server's words for the last write each of this card's three confirmations asked for and
+ * did not get. They are drawn inside the confirmation that asked (its `refusal` slot): the
+ * plugin, the update or the delete changed nothing, so retrying is the next thing the person
+ * does, and the button that retries it is in that card. A toast says the same thing, but it
+ * dismisses itself after six seconds and sits over the card rather than in it.
+ */
+ const [updateRefusal, setUpdateRefusal] = useState<string | null>(null);
+ const [uninstallRefusal, setUninstallRefusal] = useState<string | null>(null);
+ const [deleteRefusal, setDeleteRefusal] = useState<string | null>(null);
/** A user plugin, i.e. one from the server's plugin directory: the only kind the library can delete, and the only kind that carries a "user" mark. */
const isUser = plugin.source === "user";
+ /** Open a confirmation, without the previous refusal: that sentence belonged to the attempt before (one attempt, one reason). */
+ const askUpdate = (agentIds: string[]) => {
+ setPendingUpdate(agentIds);
+ setUpdateRefusal(null);
+ };
+ const askUninstall = (agentId: string) => {
+ setPendingUninstall(agentId);
+ setUninstallRefusal(null);
+ };
+ const askDelete = () => {
+ setDeleteOpen(true);
+ setDeleteRefusal(null);
+ };
+
+ /**
+ * The card's install paths — no confirmation, so no card to keep a refusal in: the reason
+ * takes the toast here (the same sentence a refused confirm would draw inside its dialog).
+ */
+ const installNow = async (agentId: string) => {
+ const outcome = await onToggleInstall(agentId, plugin, true);
+ if (!outcome.ok) toastError(outcome.reason);
+ };
+
+ /**
+ * The three confirmations close on the answer, not on the request: a refused write changes
+ * nothing on either side (the same files are still installed, the same plugin is still on
+ * disk), 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 confirmUpdate = async () => {
if (!pendingUpdate) return;
setUpdating(true);
- await onUpdateOutdated(plugin.name, pendingUpdate);
+ const outcome = await onUpdateOutdated(plugin.name, pendingUpdate);
setUpdating(false);
- setPendingUpdate(null);
+ if (outcome.ok) setPendingUpdate(null);
+ else setUpdateRefusal(outcome.reason);
+ };
+
+ const confirmUninstall = async () => {
+ if (pendingUninstall === null) return;
+ setUninstalling(true);
+ const outcome = await onToggleInstall(pendingUninstall, plugin, false);
+ setUninstalling(false);
+ if (outcome.ok) setPendingUninstall(null);
+ else setUninstallRefusal(outcome.reason);
+ };
+
+ const confirmDelete = async () => {
+ setDeleting(true);
+ const outcome = await onDelete(plugin);
+ setDeleting(false);
+ if (outcome.ok) setDeleteOpen(false);
+ else setDeleteRefusal(outcome.reason);
};
/** Display name of the Agent pending uninstall (falls back to the raw id below). */
@@ -1689,7 +1779,7 @@ function PluginCard({
className="h-8 shrink-0"
aria-label={`${S.plugins.marketInstall(marketAgentName ?? "")} ${plugin.name}`}
title={S.plugins.marketInstall(marketAgentName ?? "")}
- onClick={() => void onToggleInstall(marketAgent.agentId, plugin, true)}
+ onClick={() => void installNow(marketAgent.agentId)}
>
{S.plugins.install}
</Button>
@@ -1701,7 +1791,7 @@ function PluginCard({
className="h-8 shrink-0"
aria-label={`${S.plugins.marketUpdate(marketAgentName ?? "")} ${plugin.name}`}
title={S.plugins.marketUpdate(marketAgentName ?? "")}
- onClick={() => setPendingUpdate([marketAgent.agentId])}
+ onClick={() => askUpdate([marketAgent.agentId])}
>
{S.skills.updateAction}
</Button>
@@ -1718,7 +1808,7 @@ function PluginCard({
className="relative h-8 w-8 shrink-0 justify-center p-0"
aria-label={`${S.plugins.updateOutdated(outdated.length)} ${plugin.name}`}
title={S.plugins.updateOutdated(outdated.length)}
- onClick={() => setPendingUpdate(outdated)}
+ onClick={() => askUpdate(outdated)}
>
<GlyphIcon d={ICONS.rotateCw} size={ICON_SIZE.iconButton} />
<UpdateDot
@@ -1774,7 +1864,7 @@ function PluginCard({
className="h-8 w-8 shrink-0 justify-center p-0"
aria-label={`${S.plugins.deletePluginAction} ${plugin.name}`}
title={S.plugins.deletePluginAction}
- onClick={() => setDeleteOpen(true)}
+ onClick={askDelete}
>
<GlyphIcon d={ICONS.trash} size={ICON_SIZE.iconButton} />
</Button>
@@ -1799,10 +1889,10 @@ function PluginCard({
outdated={outdated.includes(a.agentId)}
onToggle={(on) => {
// Install runs directly; uninstall deletes the installed files, so it confirms first.
- if (on) void onToggleInstall(a.agentId, plugin, true);
- else setPendingUninstall(a.agentId);
+ if (on) void installNow(a.agentId);
+ else askUninstall(a.agentId);
}}
- onUpdate={() => setPendingUpdate([a.agentId])}
+ onUpdate={() => askUpdate([a.agentId])}
/>
))}
</div>
@@ -1818,6 +1908,7 @@ function PluginCard({
busy={updating}
onClose={() => setPendingUpdate(null)}
onConfirm={() => void confirmUpdate()}
+ refusal={updateRefusal === null ? undefined : S.common.refused(updateRefusal)}
>
<div className="space-y-3">
<p className="text-sm text-gray-600 dark:text-gray-300">
@@ -1852,12 +1943,10 @@ function PluginCard({
title={S.plugins.uninstallConfirmTitle(plugin.name)}
confirmLabel={S.skills.uninstall}
cancelLabel={S.common.cancel}
+ busy={uninstalling}
onClose={() => setPendingUninstall(null)}
- onConfirm={() => {
- const agentId = pendingUninstall;
- setPendingUninstall(null);
- void onToggleInstall(agentId, plugin, false);
- }}
+ onConfirm={() => void confirmUninstall()}
+ refusal={uninstallRefusal === null ? undefined : S.common.refused(uninstallRefusal)}
>
<p className="text-sm text-gray-600 dark:text-gray-300">
{S.plugins.uninstallConfirmBody(plugin.name, uninstallAgentName ?? pendingUninstall)}
@@ -1872,11 +1961,10 @@ function PluginCard({
title={S.plugins.deleteConfirmTitle(plugin.name)}
confirmLabel={S.plugins.deletePluginAction}
cancelLabel={S.common.cancel}
+ busy={deleting}
onClose={() => setDeleteOpen(false)}
- onConfirm={() => {
- setDeleteOpen(false);
- void onDelete(plugin);
- }}
+ onConfirm={() => void confirmDelete()}
+ refusal={deleteRefusal === null ? undefined : S.common.refused(deleteRefusal)}
>
<p className="text-sm text-gray-600 dark:text-gray-300">
{S.plugins.deleteConfirmBody(plugin.name)}