A local-first multi-agent app development platform, built on PenguinHarness
fix(web): 批量更新(插件批次 / 内核批次)没全落地时,确认框留着,原因也留在框里(7.30)
lmliheng4f99fcce2ea4
diff --git a/changelog/unreleased/2026-10-23-bulk-update-refusal.md b/changelog/unreleased/2026-10-23-bulk-update-refusal.mdnew file mode 100644index 00000000..58ac9cde--- /dev/null+++ b/changelog/unreleased/2026-10-23-bulk-update-refusal.md@@ -0,0 +1,52 @@+# Both bulk-update confirmations keep their question — and the reason — when the batch does not all land++- **Date:** 2026-10-23+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文](2026-10-23-bulk-update-refusal.zh.md)++Two page notices offer "update everything at once": **Plugins** reinstalls the library copy of every+outdated plugin on every Agent behind it, and **Agents** runs the kernel update on every Agent behind the+defaults generation. Both confirmations closed in a `finally` after the writes, and a partial failure only+reached a toast that dismissed itself after six seconds and sat above the dialog — so the one thing the+user needs while retrying (which Agents are still behind, and why) was also the first thing to leave.++Both now close only once every target landed. Anything less leaves the confirmation open with the+partial-failure sentence drawn inside it — the line that already names the Agents that did not take it,+followed by the server's own words — so the retry is the same button.++## Details++- The rule is the one the model library, the plugin cards, the Skills and Hooks tabs, session deletion,+ MCP servers and the plugin market's module rows already follow (`ConfirmModal`'s `refusal` slot, 7.19 —+ 7.29): the reason is drawn in the card that asked for the write.+- `lib/bulk-update.ts` grows the two decisions the pages need, both pure and unit tested:+ - `bulkFailureText(outcome, reason, sentence, separator)` — the sentence the card draws, or `null` when+ the batch was clean. It stands on its own rather than behind `S.common.refused`'s "the operation was+ refused" lead-in: a batch that wrote three of five was not refused, and the line already says what+ happened.+ - `remainingTargets(targets, results)` — the part of a plan whose request was rejected, with the names+ left to rewrite recomputed.+- `features/plugins/plugins-page.tsx`: the batch's answer goes into the card (`bulkRefusal`), and+ `pendingBulk` is scoped down with `remainingTargets` — the retry asks about exactly the Agents the+ sentence named, instead of reinstalling the ones that already took it (every reinstall overwrites the+ Agent's installed copy, and the success line afterwards would then count attempts). Opening the batch+ from the notice clears the previous reason; closing the card clears both.+- `features/agents/agents-page.tsx`: the same, without the scoping step — the confirmation lists+ `kernelTodo.items`, which the reload after the batch re-reads from the server, so its retry already+ names the Agents still behind.+- A reload that fails *after* every write landed still closes the card and says so in a toast: the+ decision is taken, and what is left is a stale dot rather than a question this card still has to ask.+- New browser tests `e2e/bulk-update-refusal.spec.mjs` (two: the plugin batch and the kernel batch): a+ refusal keeps the dialog, its sentence, its plan and the server's words, leaves the notification region+ without a toast, and reopening does not carry the old reason; only the retry that lands closes it. Both+ trails are reads of `AgentSummary` (`pluginUpdates` / `kernelOutdated`), so one field is edited into the+ server's own Agent list and the 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. No new copy: the sentence is the existing partial-failure line plus the existing error+ text.diff --git a/changelog/unreleased/2026-10-23-bulk-update-refusal.zh.md b/changelog/unreleased/2026-10-23-bulk-update-refusal.zh.mdnew file mode 100644index 00000000..4205d3b7--- /dev/null+++ b/changelog/unreleased/2026-10-23-bulk-update-refusal.zh.md@@ -0,0 +1,43 @@+# 两条批量更新的确认框:没全落地时框留着,原因也留在框里++- **Date:** 2026-10-23+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[English](2026-10-23-bulk-update-refusal.md)++页面提示条上的「现在升级」有两条:**插件市场**把每份落后插件的库内副本重装到每个落后的智能体,**智能体**对+每个落后于默认内核的智能体跑一次内核更新。两张确认框过去都在写入后的 `finally` 里关,部分失败只落在一条六秒+后自己消失、还浮在框上方的 toast 里 —— 用户重试时最需要的东西(哪些智能体还没成功、为什么)恰好也是最先消失+的那件。++现在两张框都在**每个目标都落地之后**才关;只要有没落地的,框就留着,并把部分失败那句话画在框里 —— 那句话+本来就点名了没成功的智能体,后面接服务端的原话 —— 重试就是同一个按钮。++## 细节++- 规则沿用模型库、插件卡、技能页与钩子页、删除对话、MCP Server、插件市场模块行那几轮(`ConfirmModal` 的+ `refusal` 槽,7.19—7.29):原因画在发起它的那张卡片里。+- `lib/bulk-update.ts` 多出两个页面要的判断,都是纯函数、都有单测:+ - `bulkFailureText(outcome, reason, sentence, separator)` —— 框里要画的那句话,整批都落地时是 `null`。+ 它不套 `S.common.refused` 的「操作被拒绝:」前缀:五个写了三个的批次并不是「被拒绝」,那句话自己已经+ 说清了发生了什么。+ - `remainingTargets(targets, results)` —— 计划里请求被拒的那部分,以及重新算出的「还要重写哪些名字」。+- `features/plugins/plugins-page.tsx`:批次的答复进框(`bulkRefusal`),`pendingBulk` 用+ `remainingTargets` 收窄 —— 重试问的正好是那句话点名的智能体,而不是把已经成功的那几个再重装一遍(每次+ 重装都会覆盖该智能体已装的副本,事后的成功句也会变成在数「尝试了几次」)。从提示条打开批次时先清掉上一次+ 的原因;关框时两个都清。+- `features/agents/agents-page.tsx`:同样处理,只是不需要收窄这一步 —— 框里列的是 `kernelTodo.items`,+ 而批次之后的重新加载会从服务端重读它,所以重试本来就已经是「还没成功的那些」。+- 写入全都落地、但**之后的重新加载失败**时,框仍然关,并在 toast 里说这件事:决定已经做完,剩下的是一个过期的+ 小红点,而不是这张框还要再问一次的问题。+- 新增浏览器用例 `e2e/bulk-update-refusal.spec.mjs`(两条:插件批次与内核批次):被拒时框、句子、计划与服务端+ 原话都在,通知区没有 toast,重新打开不带旧原因;只有放行重试的那次才关框。两条线索读的都是+ `AgentSummary`(`pluginUpdates` / `kernelOutdated`),所以只在服务端自己那份智能体列表里改一个字段,写入由+ `page.route` 接管。++## 兼容性++- 没有接口、传输格式、已存数据或依赖变化:只改了「框什么时候关」与「原因画在哪」。也没有新文案:句子就是既有+ 的部分失败句接既有的错误文本。diff --git a/packages/web/e2e/bulk-update-refusal.spec.mjs b/packages/web/e2e/bulk-update-refusal.spec.mjsnew file mode 100644index 00000000..1fd71ecf--- /dev/null+++ b/packages/web/e2e/bulk-update-refusal.spec.mjs@@ -0,0 +1,182 @@+/**+ * Regression: the two bulk updates a page notice offers — reinstall every outdated plugin on+ * every Agent behind it (Plugins), and run the kernel update on every Agent behind the defaults+ * generation (Agents) — ask first, and a batch the server did not take everywhere keeps that+ * question, with the partial-failure sentence drawn inside it.+ *+ * Both used to settle on the request rather than on the answer: the confirmation closed in a+ * `finally` after the writes, and a partial failure arrived as a toast that dismissed itself+ * after six seconds and sat above the dialog — so the one thing the user needs while retrying+ * (which Agents are still behind, and why) was also the first thing to leave. Each card now+ * closes only once every target landed; anything less leaves it open with `bulkFailureText`'s+ * sentence in `ConfirmModal`'s refusal slot, so the retry is the same button. The plugin batch+ * is additionally scoped down to the Agents that are still behind before it is handed back.+ *+ * The writes the tests measure are the page's own requests — POST …/agents/:id/plugins and POST+ * …/agents/:id/config/kernel-update — taken over with `page.route`; the Agent list is the+ * server's own, with the one field each gate reads edited into it, because both trails are+ * reads of `AgentSummary` and a development data root ships neither an outdated plugin nor an+ * Agent behind the defaults generation.+ */+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 the batch would reinstall: a name only the stubbed list carries. */+const PLUGIN = { name: "probe-plugin", version: "2026.10.22.1" };++/** What each refused write answers: its own words prove the reason came back into the card. */+const PLUGIN_REFUSAL = { code: "agent_state_read_only", message: "agent state is read-only" };+const KERNEL_REFUSAL = { code: "agent_state_read_only", message: "agent state is read-only" };++const notifications = (page) => page.getByRole("region", { name: "通知" });++const refuseWith = (route, refusal) =>+ route.fulfill({+ status: 500,+ contentType: "application/json",+ body: JSON.stringify({ error: refusal }),+ });++/** The Project's first Agent list, as the server sends it (the whole body, `agents` key included). */+async function agentList(page) {+ const projectId = (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0]+ .projectId;+ return await (await page.request.get(`${BASE}/api/projects/${projectId}/agents`)).json();+}++/**+ * Serve the Agent list with one field edited in: `pluginUpdates` raises the Plugins trail,+ * `kernelOutdated` the Agents one. Both gates read these summaries, so the notice above the+ * bulk button appears exactly as it would on a real install that is behind.+ */+async function stubAgents(page, edit) {+ const body = await agentList(page);+ for (const agent of body.agents) if (agent.agentId === AGENT) edit(agent);+ 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 route.fulfill({+ status: 200,+ contentType: "application/json",+ body: JSON.stringify(body),+ });+ });+}++/** Take over the plugin reinstall a bulk update is; `state.refuse` is flipped by the retry half. */+async function stubBulkUpdate(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, PLUGIN_REFUSAL);+ await route.fulfill({+ status: 200,+ contentType: "application/json",+ body: JSON.stringify({ skills: [], hooks: [] }),+ });+ });+}++/** Take over the kernel update. */+async function stubKernelUpdate(page, state) {+ await page.route("**/api/projects/*/agents/*/config/kernel-update", async (route) => {+ if (route.request().method() !== "POST") return route.fallback();+ state.writes.push(new URL(route.request().url()).pathname);+ if (state.refuse) return refuseWith(route, KERNEL_REFUSAL);+ await route.fulfill({+ status: 200,+ contentType: "application/json",+ body: JSON.stringify({ advanced: [], kept: [], kernelVersion: "2026-10-22" }),+ });+ });+}++/**+ * The notice's bulk button. Its accessible name folds the notice's own sentence in after the+ * visible label ("现在升级 · 检测到变更:1 个可升级"), so it is matched by that prefix alone.+ */+const updateNow = (page) => page.getByRole("button", { name: /^现在升级 ·/ });++test("a refused plugin bulk update keeps the question, the reason and the plan", async ({+ page,+}) => {+ await login(page.request, ADMIN_ID, ADMIN_PASSWORD);+ const state = { writes: [], refuse: true };+ await stubAgents(page, (agent) => {+ agent.pluginUpdates = [...(agent.pluginUpdates ?? []), PLUGIN];+ });+ await stubBulkUpdate(page, state);++ await page.goto("/plugins");+ // The notice states the one honest count for this trail: a distinct plugin, not an Agent.+ await expect(page.getByText("检测到变更:1 个可升级")).toBeVisible();+ await updateNow(page).click();+ const dialog = page.getByRole("dialog", { name: "更新 1 个插件" });+ await expect(dialog).toBeVisible();++ await dialog.getByRole("button", { name: "更新", exact: true }).click();++ // The sentence (which names the Agent that did not take it) and the server's words are inside+ // the card that asked, and the notification region holds no dismissible button: no toast.+ await expect(dialog.getByText("以下未成功:")).toBeVisible();+ await expect(dialog.getByText(PLUGIN_REFUSAL.message)).toBeVisible();+ await expect(notifications(page).getByRole("button")).toHaveCount(0);+ expect(state.writes).toEqual([{ names: [PLUGIN.name] }]);+ await expect(dialog).toBeVisible();+ // The card still holds the question it asked: the sentence and the plan, not just the reason.+ await expect(dialog.getByText("将影响以下对象:")).toBeVisible();+ await expect(dialog.getByRole("listitem")).toHaveCount(1);+ await expect(dialog.getByRole("listitem")).toHaveText(PLUGIN.name);++ // Closing decides nothing, and opening the batch again does not carry the old reason over.+ await dialog.getByRole("button", { name: "取消" }).click();+ await expect(dialog).toHaveCount(0);+ await updateNow(page).click();+ const reopened = page.getByRole("dialog", { name: "更新 1 个插件" });+ await expect(reopened).toBeVisible();+ await expect(reopened.getByText(PLUGIN_REFUSAL.message)).toHaveCount(0);++ // The retry is the same card; this time the batch lands and the card closes.+ state.refuse = false;+ await reopened.getByRole("button", { name: "更新", exact: true }).click();+ await expect(reopened).toHaveCount(0);+ expect(state.writes).toHaveLength(2);+});++test("a refused kernel bulk update keeps the question, the reason and the plan", async ({+ page,+}) => {+ await login(page.request, ADMIN_ID, ADMIN_PASSWORD);+ const state = { writes: [], refuse: true };+ await stubAgents(page, (agent) => {+ agent.kernelOutdated = true;+ });+ await stubKernelUpdate(page, state);++ await page.goto("/agents");+ await expect(page.getByText("检测到变更:1 个可升级")).toBeVisible();+ await updateNow(page).click();+ const dialog = page.getByRole("dialog", { name: "更新 1 个 Agent 的内核" });+ await expect(dialog).toBeVisible();++ await dialog.getByRole("button", { name: "更新内核", exact: true }).click();++ await expect(dialog.getByText("以下未成功:")).toBeVisible();+ await expect(dialog.getByText(KERNEL_REFUSAL.message)).toBeVisible();+ await expect(notifications(page).getByRole("button")).toHaveCount(0);+ expect(state.writes).toHaveLength(1);+ expect(state.writes[0].endsWith(`/agents/${AGENT}/config/kernel-update`)).toBe(true);+ await expect(dialog).toBeVisible();+ // The card still holds the question it asked: the sentence and the plan, not just the reason.+ await expect(dialog.getByText("将影响以下对象:")).toBeVisible();+ await expect(dialog.getByRole("listitem")).toHaveCount(1);++ // The retry is the same card; this time every Agent took it 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/src/features/agents/agents-page.tsx b/packages/web/src/features/agents/agents-page.tsxindex 49386502..1001b976 100644--- a/packages/web/src/features/agents/agents-page.tsx+++ b/packages/web/src/features/agents/agents-page.tsx@@ -59,7 +59,7 @@ import { formatDateTime, formatRelativeDays } from "../../lib/format";import { useDocumentTitle } from "../../lib/use-document-title";import { useUpdateBadges } from "../../lib/use-update-badges";import { dismissTodo } from "../../lib/todo-dismissals";-import { bulkOutcome, failedList, firstFailure, noticeCounts } from "../../lib/bulk-update";+import { bulkFailureText, bulkOutcome, firstFailure, noticeCounts } from "../../lib/bulk-update";import { useAuth } from "../../state/auth";import { useLocale } from "../../state/locale";import { agentDisplayName, useProject } from "../../state/project";@@ -165,6 +165,8 @@ export function AgentsPage() {/** The bulk kernel update's confirmation is open. */const [kernelConfirmOpen, setKernelConfirmOpen] = useState(false);const [kernelRunning, setKernelRunning] = useState(false);+ /** The batch's answer when it did not all land: drawn inside the confirmation that asked for it. */+ const [kernelRefusal, setKernelRefusal] = useState<string | null>(null);const [createOpen, setCreateOpen] = useState(false);/** The "Create with AI" dialog, a separate surface from the form above: neither path is a step of the other. */const [aiOpen, setAiOpen] = useState(false);@@ -469,6 +471,11 @@ export function AgentsPage() {* `Promise.allSettled` with a named partial failure, the shape the Skills page's bulk update* uses: a smart merge that lands on three Agents and fails on two must say WHICH two, or the* user is left re-checking every card by hand.+ *+ * Only a batch that landed everywhere dismisses the confirmation. Anything less keeps it open+ * with that same sentence drawn inside it (`bulkFailureText`) rather than in a toast that would+ * leave after six seconds; the dialog lists `kernelTodo.items`, which the reload above re-reads+ * from the server, so its retry already names the Agents still behind.*/const runKernelUpdates = async (targets: readonly string[]) => {if (!projectId || targets.length === 0) return;@@ -483,8 +490,13 @@ export function AgentsPage() {const outcome = bulkOutcome(labels, results);if (outcome.allOk) toastSuccess(S.todo.bulkDone(outcome.ok));else {- toastError(- `${S.todo.bulkPartial(outcome.ok, failedList(outcome.failed, S.todo.listSeparator))} — ${apiErrorText(firstFailure(results))}`,+ setKernelRefusal(+ bulkFailureText(+ outcome,+ apiErrorText(firstFailure(results)),+ S.todo.bulkPartial,+ S.todo.listSeparator,+ ),);}// The gate reads `AgentSummary.kernelOutdated` off the Project's Agent list, so the dot only@@ -498,7 +510,10 @@ export function AgentsPage() {toastError(apiErrorText(e));} finally {setKernelRunning(false);- setKernelConfirmOpen(false);+ // Nothing but a clean batch closes the question. The reload failing afterwards closes it+ // too: every write landed and the toast says so, and what is left is a stale dot, not a+ // decision this card still has to take.+ if (outcome.allOk) setKernelConfirmOpen(false);}};@@ -536,7 +551,11 @@ export function AgentsPage() {text={S.todo.changesUpgradable(noticeCounts(kernelTodo).updated)}actionLabel={S.todo.updateNow}busy={kernelRunning}- onAction={() => setKernelConfirmOpen(true)}+ onAction={() => {+ setKernelConfirmOpen(true);+ // Opening the batch afresh: a reason from the last attempt belongs to that attempt.+ setKernelRefusal(null);+ }}dismissLabel={S.todo.dismiss}onDismiss={() => dismissTodo(projectId ?? null, "agents", kernelTodo.signature)}/>@@ -1030,7 +1049,9 @@ export function AgentsPage() {{/* Bulk kernel update confirmation. The body is the per-Agent confirm's own wording,verbatim — a kernel update is a smart merge that advances the settings tabs the userhas not touched and leaves the customized ones whole — with the list naming every- Agent the batch would write to. Primary (overwrite) tone, like its per-Agent twin. */}+ Agent the batch would write to. Primary (overwrite) tone, like its per-Agent twin. A+ batch that did not land everywhere keeps this card and reports inside it, so the retry+ is the same button. */}{kernelTodo && kernelConfirmOpen && (<ConfirmModalopen@@ -1039,8 +1060,12 @@ export function AgentsPage() {confirmLabel={S.agent.kernelUpdateAction}cancelLabel={S.common.cancel}busy={kernelRunning}- onClose={() => setKernelConfirmOpen(false)}+ onClose={() => {+ setKernelConfirmOpen(false);+ setKernelRefusal(null);+ }}onConfirm={() => void runKernelUpdates(kernelTodo.items)}+ refusal={kernelRefusal === null ? undefined : kernelRefusal}><div className="space-y-3"><p className="text-sm text-gray-600 dark:text-gray-300">diff --git a/packages/web/src/features/plugins/plugins-page.tsx b/packages/web/src/features/plugins/plugins-page.tsxindex cfab4d39..29e33ae2 100644--- a/packages/web/src/features/plugins/plugins-page.tsx+++ b/packages/web/src/features/plugins/plugins-page.tsx@@ -91,7 +91,13 @@ import { apiErrorText } from "../../lib/api-error";import { useDocumentTitle } from "../../lib/use-document-title";import { useUpdateBadges } from "../../lib/use-update-badges";import { dismissTodo } from "../../lib/todo-dismissals";-import { bulkOutcome, failedList, firstFailure, noticeCounts } from "../../lib/bulk-update";+import {+ bulkFailureText,+ bulkOutcome,+ firstFailure,+ noticeCounts,+ remainingTargets,+} from "../../lib/bulk-update";import { useAuth } from "../../state/auth";import { useLocale } from "../../state/locale";import { agentDisplayName, useProject } from "../../state/project";@@ -260,6 +266,8 @@ export function PluginsPage() {/** The bulk update's confirmation is open (null = closed); it holds the plan it will run. */const [pendingBulk, setPendingBulk] = useState<PluginUpdatePlan | null>(null);const [bulkRunning, setBulkRunning] = useState(false);+ /** The batch's answer when it did not all land: drawn inside the confirmation that asked for it. */+ const [bulkRefusal, setBulkRefusal] = useState<string | null>(null);const [groups, setGroups] = useState<PluginGroupItem[] | null>(null);const [error, setError] = useState<string | null>(null);@@ -624,6 +632,11 @@ export function PluginsPage() {* it led the user to. What is new is that a partial failure NAMES the Agents that did not take* it — on a control whose whole point is "all of them at once", a first-error toast leaves the* user unable to tell which half they are looking at.+ *+ * Only a batch that landed everywhere dismisses the confirmation. Anything less keeps it open,+ * with that same sentence drawn inside it (`bulkFailureText`) instead of in a toast that would+ * leave after six seconds, and with `pendingBulk` scoped down to the Agents that are still+ * behind (`remainingTargets`) so the retry button asks about exactly what the sentence named.*/const runBulkUpdate = async (plan: PluginUpdatePlan) => {if (!projectId || plan.perAgent.length === 0) return;@@ -641,9 +654,16 @@ export function PluginsPage() {const outcome = bulkOutcome(labels, results);if (outcome.allOk) toastSuccess(S.todo.bulkDone(outcome.ok));else {- toastError(- `${S.todo.bulkPartial(outcome.ok, failedList(outcome.failed, S.todo.listSeparator))} — ${apiErrorText(firstFailure(results))}`,+ const rest = remainingTargets(plan.perAgent, results);+ setBulkRefusal(+ bulkFailureText(+ outcome,+ apiErrorText(firstFailure(results)),+ S.todo.bulkPartial,+ S.todo.listSeparator,+ ),);+ setPendingBulk({ perAgent: rest.targets, plugins: rest.names });}// Runs after a partial failure too — some Agent moved, and the gate has to see it. Guarded,// because `reloadAgents` rejects on a failed list read and the busy flag disables every@@ -655,7 +675,10 @@ export function PluginsPage() {toastError(apiErrorText(e));} finally {setBulkRunning(false);- setPendingBulk(null);+ // Nothing but a clean batch closes the question: a refusal leaves it (and its retry+ // button) where the user still is. The reload failing afterwards closes it too — every+ // write landed, and the page says so in a toast; the stale dot is the reload's problem.+ if (outcome.allOk) setPendingBulk(null);}};@@ -840,7 +863,11 @@ export function PluginsPage() {text={S.todo.changesUpgradable(noticeCounts(todo).updated)}actionLabel={S.todo.updateNow}busy={bulkRunning}- onAction={() => setPendingBulk(pluginUpdatePlan(agents))}+ onAction={() => {+ setPendingBulk(pluginUpdatePlan(agents));+ // Opening the batch afresh: a reason from the last attempt belongs to that attempt.+ setBulkRefusal(null);+ }}dismissLabel={S.todo.dismiss}onDismiss={() => dismissTodo(projectId, "plugins", todo.signature)}/>@@ -995,7 +1022,9 @@ export function PluginsPage() {{/* Bulk update confirmation. Same warning as the per-plugin confirm — an update is anoverwriting reinstall — and the same primary (overwrite) tone, with the list namingevery plugin the batch would rewrite. Confirm-first is the point of the button: it- overwrites many installs in one press, and a single one already asks. */}+ overwrites many installs in one press, and a single one already asks. A batch that did+ not land everywhere keeps this card and reports inside it: the retry is the same button,+ and the list has already been scoped to the Agents still behind. */}{pendingBulk !== null && (<ConfirmModalopen@@ -1004,8 +1033,12 @@ export function PluginsPage() {confirmLabel={S.skills.updateAction}cancelLabel={S.common.cancel}busy={bulkRunning}- onClose={() => setPendingBulk(null)}+ onClose={() => {+ setPendingBulk(null);+ setBulkRefusal(null);+ }}onConfirm={() => void runBulkUpdate(pendingBulk)}+ refusal={bulkRefusal === null ? undefined : bulkRefusal}><div className="space-y-3"><p className="text-sm text-gray-600 dark:text-gray-300">{S.todo.pluginsConfirmBody}</p>diff --git a/packages/web/src/lib/bulk-update.ts b/packages/web/src/lib/bulk-update.tsindex 31db8ddb..e92d6040 100644--- a/packages/web/src/lib/bulk-update.ts+++ b/packages/web/src/lib/bulk-update.ts@@ -89,3 +89,49 @@ export function firstFailure(results: readonly PromiseSettledResult<unknown>[]):const rejected = results.find((r): r is PromiseRejectedResult => r.status === "rejected");return rejected?.reason;}++/**+ * The sentence a batch's OWN confirmation draws when the batch did not all land, or `null` when+ * it did.+ *+ * A partial failure used to be reported in a toast alone — the right words in the wrong place: a+ * box that dismisses itself after six seconds and sits over the confirmation rather than in it,+ * so the one thing the user needs while retrying is also the first thing to leave. The+ * confirmation now keeps itself open on anything short of every target landing (see+ * `ConfirmModal`'s `refusal` slot), and this is the sentence it draws there: the partial-failure+ * line, which already names the targets that did not land, plus the first rejection's own words.+ *+ * The sentence stands on its own rather than behind `S.common.refused`'s "the operation was+ * refused:" lead-in: a batch that wrote three of five was not refused, and the line already says+ * what happened.+ */+export function bulkFailureText(+ outcome: BulkOutcome,+ reason: string,+ sentence: (ok: number, failed: string) => string,+ separator: string,+): string | null {+ if (outcome.allOk) return null;+ return `${sentence(outcome.ok, failedList(outcome.failed, separator))} — ${reason}`;+}++/**+ * The part of a batch that is still behind: every target whose request was rejected, with the+ * names left to rewrite recomputed from what remains.+ *+ * Handed back to the confirmation that asked for the batch, so its retry asks about exactly the+ * targets the sentence named as not having landed. Re-running the whole plan instead would+ * rewrite the ones that did take it — each one is an overwriting reinstall — and the count in+ * the success line afterwards would be about attempts rather than about what was behind.+ */+export function remainingTargets<T extends { names: readonly string[] }>(+ targets: readonly T[],+ results: readonly PromiseSettledResult<unknown>[],+): { targets: T[]; names: string[] } {+ // `allSettled` preserves input order, which is what makes the pairing sound — the same rule+ // `bulkOutcome` reads its labels by.+ const left = targets.filter((_, i) => results[i]?.status === "rejected");+ const names = new Set<string>();+ for (const target of left) for (const name of target.names) names.add(name);+ return { targets: left, names: [...names].sort() };+}diff --git a/packages/web/test/todo-notice.test.ts b/packages/web/test/todo-notice.test.tsindex e8033c9b..56beb259 100644--- a/packages/web/test/todo-notice.test.ts+++ b/packages/web/test/todo-notice.test.ts@@ -15,10 +15,20 @@* - A batch outcome is clean when every target took the write (an empty batch included), and* otherwise names the failed targets by position, never as a blank; a long list reports its* overflow as a count; the first rejection is surfaced for the error text.+ * - The sentence a batch's own confirmation draws is that partial line plus the first rejection,+ * and it is absent when the batch landed everywhere; what the retry is scoped to is exactly the+ * targets whose request was rejected, with the names left to rewrite recomputed from them.*/import { describe, expect, it } from "vitest";import ts from "typescript";-import { bulkOutcome, failedList, firstFailure, noticeCounts } from "../src/lib/bulk-update";+import {+ bulkFailureText,+ bulkOutcome,+ failedList,+ firstFailure,+ noticeCounts,+ remainingTargets,+} from "../src/lib/bulk-update";import type { Todo } from "../src/lib/todo-badges";import { expectEveryRootScanned, expectSingleHome, scanSources } from "./helpers/roots";@@ -202,3 +212,68 @@ describe("firstFailure", () => {expect(firstFailure([{ status: "fulfilled", value: 1 }])).toBeUndefined();});});++describe("bulkFailureText", () => {+ const ok = { status: "fulfilled", value: undefined } as const;+ const bad = (reason: string) => ({ status: "rejected", reason }) as const;+ // The app's own partial-failure line and its separator, spelled out here so the assertion+ // reads the sentence rather than a second copy of the dictionary.+ const sentence = (n: number, failed: string) => `已更新 ${n} 个 Agent;以下未成功:${failed}`;++ it("is absent when every target took the write, so a clean batch closes its confirmation", () => {+ const outcome = bulkOutcome(["alpha", "beta"], [ok, ok]);+ expect(bulkFailureText(outcome, "boom", sentence, "、")).toBeNull();+ });++ it("names the targets that did not land, then the server's own words", () => {+ const outcome = bulkOutcome(["alpha", "beta", "gamma"], [ok, bad("nope"), bad("boom")]);+ expect(bulkFailureText(outcome, "first refusal", sentence, "、")).toBe(+ "已更新 1 个 Agent;以下未成功:beta、gamma — first refusal",+ );+ });++ it("carries the capped list for a batch too long to read in one line", () => {+ const names = Array.from({ length: 11 }, (_, i) => `a${i}`);+ const outcome = bulkOutcome(+ names,+ names.map((_, i) => (i === 0 ? ok : bad("boom"))),+ );+ expect(bulkFailureText(outcome, "first refusal", sentence, ", ")).toBe(+ "已更新 1 个 Agent;以下未成功:a1, a2, a3, a4, a5, a6, a7, a8, +2 — first refusal",+ );+ });+});++describe("remainingTargets", () => {+ const ok = { status: "fulfilled", value: undefined } as const;+ const bad = (reason: string) => ({ status: "rejected", reason }) as const;+ const plan = [+ { agentId: "a1", names: ["beta", "alpha"] },+ { agentId: "a2", names: ["gamma"] },+ { agentId: "a3", names: ["alpha"] },+ ];++ it("keeps exactly the targets whose request was rejected, so the retry rewrites nothing twice", () => {+ expect(remainingTargets(plan, [ok, bad("boom"), bad("nope")])).toEqual({+ targets: [+ { agentId: "a2", names: ["gamma"] },+ { agentId: "a3", names: ["alpha"] },+ ],+ names: ["alpha", "gamma"],+ });+ });++ it("keeps the whole plan when nothing landed", () => {+ expect(remainingTargets(plan, [bad("x"), bad("y"), bad("z")]).targets).toEqual(plan);+ });++ it("is empty when every target landed — there is nothing left to ask about", () => {+ expect(remainingTargets(plan, [ok, ok, ok])).toEqual({ targets: [], names: [] });+ });++ it("pairs targets to results by position, the rule the labels are read by", () => {+ expect(remainingTargets(plan, [bad("x"), ok, ok]).targets).toEqual([+ { agentId: "a1", names: ["beta", "alpha"] },+ ]);+ });+});