A local-first multi-agent app development platform, built on PenguinHarness
fix(web): a refused write that has a place to stay no longer also raises a toast
lmliheng3d6d24ec7aee
diff --git a/changelog/unreleased/2026-11-11-refusal-no-duplicate-toast.md b/changelog/unreleased/2026-11-11-refusal-no-duplicate-toast.mdnew file mode 100644index 00000000..811ec015--- /dev/null+++ b/changelog/unreleased/2026-11-11-refusal-no-duplicate-toast.md@@ -0,0 +1,51 @@+# A refused switch, placeholder insert or save is explained once, not twice++- **Date:** 2026-11-11+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文版](2026-11-11-refusal-no-duplicate-toast.zh.md)++The Agent settings page answers a refused write where it was asked: the enable switch at the head of+each tab keeps the server's words under its card, the "insert the placeholder" strip keeps them+under the strip, and the confirm-before-save card keeps them inside the card that retries. Every one+of those surfaces arrived during the long pass that moved a refusal out of a six-second+notification and into the control that asked (7.19's rule), and each of them left the old+`toastError` in place beside the new sentence. So the app said the same thing twice: once where the+person was looking, and once in a notification above the page that then vanished on its own.++This change removes the second copy — seven call sites in three files. A toast still announces every+write that **landed** (the switch moves without saying anything, so that is the only account of a+success); it is only a refusal that has a place of its own that no longer also raises one. Nothing+else about the surfaces changes: the sentences, their slots, their clearing rules and every retry+are the same.++## Details++- `packages/web/src/features/agents/memory-tab.tsx`: the Memory switch (`switchRefusal`), Memory's+ placeholder strip (`insertRefusal`) and the tab's own prompt writer (the save card) no longer call+ `toastError`. Opening a memory keeps its toast: that read has no surface to stay in — the panel+ never got as far as opening — so the notification is still the only account of it.+- `packages/web/src/features/agents/prompt-injection-controls.tsx`: the same three, for the switch,+ the strip and the prompt writer the Skills / Vault / Schedules / Hooks tabs share.+- `packages/web/src/features/agents/agent-settings-page.tsx`: the page's shared `save`, which every+ settings form reaches through `useSaveConfirm`, rethrows to the card without also toasting.+- The comments where each copy used to be say why: the in-place line is the whole account, and a+ copy of it that dismisses itself after six seconds only adds noise above the card it came from.++## Tests++- `packages/web/e2e/agent-switch-refusal.spec.mjs`, `placeholder-insert-refusal.spec.mjs`,+ `agent-save-refusal.spec.mjs`: the "no notification" assertion is now an immediate read+ (`expectNoToast`) instead of `toHaveCount(0)`. The retrying form also passed against a toast that+ simply expired after six seconds — which is exactly the behaviour these files are about — and it+ is why every case used to take fifteen seconds.+- `agent-save-refusal.spec.mjs` gains a case for the shared prompt writer (the Skills tab's prompt+ section), a third shape of the save promise that no browser test covered before.++## Compatibility++No interface change on the wire, no new dependency, no Project config change. Success notifications,+the refusals' own sentences, the delete / import / export surfaces and the Memory tab's read refusal+are unchanged.diff --git a/changelog/unreleased/2026-11-11-refusal-no-duplicate-toast.zh.md b/changelog/unreleased/2026-11-11-refusal-no-duplicate-toast.zh.mdnew file mode 100644index 00000000..5323e23b--- /dev/null+++ b/changelog/unreleased/2026-11-11-refusal-no-duplicate-toast.zh.md@@ -0,0 +1,41 @@+# 被拒的开关、插入占位符与保存只说一遍,不再重复一条通知++- **日期:** 2026-11-11+- **类型:** 修复+- **范围:** `web`+- **破坏性变更:** 否++[English](2026-11-11-refusal-no-duplicate-toast.md)++Agent 设置页把被拒的写入讲在它被问的地方:每个分区的「启用」开关把服务端原话留在卡片下面,「插入占位符」条把+它留在条下面,确认式保存的卡片把它留在那张可以重试的卡片里。这三处都是「把拒绝从六秒通知搬到发问的控件旁边」+那一轮(7.19 的规则)里出现的,而每一处都把旧的 `toastError` 留在了新句子旁边。于是同一件事被说了两遍:一遍在+人正看着的地方,一遍在页面顶部那条随后自己消失的通知里。++这次去掉的是第二遍 —— 三份文件、七个调用点。**写成功**的通知一条没动(开关是静默移动的,所以那是成功唯一的+交代);去掉的只是「已经有地方留着原因」的那些拒绝。这三处本身一字未改:句子、槽、清空规则、以及每一次重试。++## 细节++- `packages/web/src/features/agents/memory-tab.tsx`:记忆开关(`switchRefusal`)、记忆的占位符条+ (`insertRefusal`)、以及这一页自己的提示词保存(保存卡片)不再 `toastError`。**打开一条记忆**仍走通知:+ 那次读取没有可以留住的宿主 —— 面板正是因为读不到才没打开 —— 所以通知仍是它唯一的交代。+- `packages/web/src/features/agents/prompt-injection-controls.tsx`:同样的三处,作用于技能 / 保险柜 / 定时任务 /+ 钩子四个分区共享的开关、占位符条与提示词保存。+- `packages/web/src/features/agents/agent-settings-page.tsx`:页面共享的 `save`(每个设置表单都经+ `useSaveConfirm` 走到它)只把失败交回卡片,不再同时发通知。+- 原来放那条通知的每一处,注释改成了「为什么」:就地那句就是全部交代,六秒后自己收起的副本只是卡片上方的一层噪声。++## 测试++- `packages/web/e2e/agent-switch-refusal.spec.mjs`、`placeholder-insert-refusal.spec.mjs`、+ `agent-save-refusal.spec.mjs`:「通知区没有东西」这条断言从 `toHaveCount(0)` 改成立刻读一次+ (`expectNoToast`)。会重试的那种写法对着一条六秒后自己过期的通知同样会通过 —— 而那正是这三份用例在讲的事,+ 也是它们过去每条都要跑十五秒的原因。+- `agent-save-refusal.spec.mjs` 新增一条共享提示词写入的用例(技能页的提示词区),这是保存 Promise 的第三种+ 形状,之前没有浏览器用例钉过。++## 兼容性++线上接口没变、没有新依赖、Project 配置没变。成功的通知、拒绝自己的句子、删除 / 导入 / 导出那几处、以及记忆页+那次读取失败的通知都一字未改。diff --git a/packages/web/e2e/agent-save-refusal.spec.mjs b/packages/web/e2e/agent-save-refusal.spec.mjsindex 218017b5..f233b204 100644--- a/packages/web/e2e/agent-save-refusal.spec.mjs+++ b/packages/web/e2e/agent-save-refusal.spec.mjs@@ -13,7 +13,12 @@** Two different call sites are covered, because they build the promise differently: the page's* shared `save` (Prompt tab) rethrows from its catch, and the Memory tab's own writer returns its- * chain. Both are refused at `page.route`; the config the tests write to is the server's own.+ * chain. A third case pins the shared prompt writer the Skills / Vault / Schedules tabs use. None+ * of them also raises a notification for a refusal: the card is the thing the person is reading,+ * and a copy of the sentence above it that dismisses itself after six seconds was noise. That is+ * read the moment the refusal appears (see `expectNoToast`) rather than with a retrying assertion,+ * which would also pass once such a toast had expired by itself. Every write is refused at+ * `page.route`; the config the tests write to is the server's own.*/import { test, expect } from "@playwright/test";import { provisionAndLogin } from "./auth.mjs";@@ -31,6 +36,18 @@ const configPath = (projectId) => `/api/projects/${projectId}/agents/${AGENT}/co/** The notification region: a refused save must not be announced there instead of in the card. */const notifications = (page) => page.getByRole("region", { name: "通知" });+/**+ * Nothing was raised in the notification region for this refusal, read at once.+ *+ * `toHaveCount(0)` retries for the whole expect timeout, so it also passes against a toast that+ * simply expired after six seconds — the very behaviour this file is about. This reads the count+ * once, after a short settle so the refusal's own render has landed.+ */+async function expectNoToast(page) {+ await page.waitForTimeout(400);+ expect(await notifications(page).getByRole("button").count()).toBe(0);+}+/*** Provision the user and give the Project a model (the onboarding overlay covers the page without* one), returning the Project id and a reader for the Agent's config as the server holds it.@@ -121,7 +138,7 @@ test("a refused prompt save keeps the card, its sentence, and says why", async (expect(state.sent[0].config.systemPrompt).toBe(NEXT);// The server still holds what it held, and the toast is not the only trace of the refusal.expect((await stored()).config.systemPrompt).toBe(before.config.systemPrompt);- await expect(notifications(page).getByRole("button")).toHaveCount(0);+ await expectNoToast(page);// Seven seconds later the sentence is still in the card (a toast would be long gone by now).await page.waitForTimeout(7000);@@ -163,7 +180,7 @@ test("a refused memory prompt save keeps the card too", async ({ page }) => {expect(state.sent[0].config.memory.prompt).toBe(NEXT);// The Memory tab keeps its own writer, so this pins the second shape of the promise.expect((await stored()).config.memory.prompt).toBe(before.config.memory.prompt);- await expect(notifications(page).getByRole("button")).toHaveCount(0);+ await expectNoToast(page);state.refuse = false;await dialog.getByRole("button", { name: "保存", exact: true }).click();@@ -171,3 +188,43 @@ test("a refused memory prompt save keeps the card too", async ({ page }) => {await expect.poll(async () => (await stored()).config.memory.prompt).toBe(NEXT);expect(state.sent).toHaveLength(2);});++test("a refused skills prompt save keeps the card too", async ({ page }) => {+ const { stored, seed } = await projectWithModel(page, "r224skills");+ const NEXT = "A skills prompt written by the save-refusal test.\n";+ await seed({ config: { skills: { prompt: "A skills prompt left by the baseline seed.\n" } } });+ const before = await stored();+ expect(before.config.skills.prompt).not.toBe(NEXT);++ const state = { sent: [], refuse: true };+ await interceptSave(page, state);++ await page.goto(`/agents/${AGENT}?tab=skills`);+ // The Skills / Vault / Schedules tabs share one prompt writer (`usePromptInjection`), a third+ // shape of the promise: the chain is built there, not in the tab. Same wait as the two above.+ // Addressed by role and name, not `getByLabel`: this field's `<label>` wraps it, so the label's+ // text is the label plus the value the textarea already holds.+ const field = page.getByRole("textbox", { name: "提示词", exact: true });+ await expect(field).toHaveValue(/baseline seed/);+ await field.fill(NEXT);+ await page.getByRole("button", { name: "保存", exact: true }).click();++ const dialog = page.getByRole("dialog", { name: "保存修改" });+ await expect(dialog).toBeVisible();+ const sentence = await cardText(dialog);++ await dialog.getByRole("button", { name: "保存", exact: true }).click();+ await expect(dialog).toBeVisible();+ await expect(dialog.getByText(/^操作被拒绝:agent state is read-only$/)).toBeVisible();+ expect(await cardText(dialog)).toBe(sentence);+ expect(state.sent).toHaveLength(1);+ expect(state.sent[0].config.skills.prompt).toBe(NEXT);+ expect((await stored()).config.skills.prompt).toBe(before.config.skills.prompt);+ await expectNoToast(page);++ state.refuse = false;+ await dialog.getByRole("button", { name: "保存", exact: true }).click();+ await expect(dialog).toBeHidden();+ await expect.poll(async () => (await stored()).config.skills.prompt).toBe(NEXT);+ expect(state.sent).toHaveLength(2);+});diff --git a/packages/web/e2e/agent-switch-refusal.spec.mjs b/packages/web/e2e/agent-switch-refusal.spec.mjsindex 3960dc7b..1cbb9728 100644--- a/packages/web/e2e/agent-switch-refusal.spec.mjs+++ b/packages/web/e2e/agent-switch-refusal.spec.mjs@@ -9,6 +9,12 @@* tab's own card and the card the Skills / Vault / Schedules / Hooks tabs share* (`usePromptInjection`), which are two separate code paths behind the same sentence.*+ * The line is the whole account of the refusal, so nothing is also raised in the notification+ * region: that copy repeated the same words above the card it came from and was gone six seconds+ * later. "No notification" is read immediately after the line appears (see `expectNoToast`),+ * because a retrying `toHaveCount(0)` would also pass once a toast had expired on its own — which+ * is the behaviour this file exists to tell apart.+ ** The refusal is injected where the page's own write is: `page.route` answers the config PUT with* the server's words instead of forwarding it, so the reason proved to be on screen is the one the* failed request carried. The code is one the app has no sentence for, so the server's own words@@ -90,6 +96,18 @@ async function seedMemory(page, projectId, enabled) {/** The notification region: a refusal must not be announced there (that is the old toast). */const notifications = (page) => page.getByRole("region", { name: "通知" });+/**+ * Nothing was raised in the notification region for this refusal, read at once.+ *+ * `toHaveCount(0)` retries for the whole expect timeout, so it also passes against a toast that+ * simply expired after six seconds — the very behaviour this file is about. This reads the count+ * once, after a short settle so the refusal's own render has landed.+ */+async function expectNoToast(page) {+ await page.waitForTimeout(400);+ expect(await notifications(page).getByRole("button").count()).toBe(0);+}+/*** The line the card must draw, from the position the switch was in before the click: the sentence* names the direction that failed, and a refused flip leaves the switch where the server has it, so@@ -129,9 +147,9 @@ test("a refused flip of the Memory switch keeps the reason under the card, and tawait toggle.click();// The reason is under the card that asked, drawn as one sentence and not as a toast: the- // notification region holds no dismissible button while this line is on screen.+ // notification region holds no dismissible button at all, read before any of them could expire.await expect(page.getByRole("alert")).toHaveText(line);- await expect(notifications(page).getByRole("button")).toHaveCount(0);+ await expectNoToast(page);expect(state.seen).toHaveLength(1);// Nothing moved, because nothing was written: the switch is still where the server has it.await expectUnmoved(toggle, wasOn);@@ -167,7 +185,7 @@ test("a refused flip of the shared Skills switch keeps the reason under that car// Same shape as the Memory card above, and the same sentence builder — but a different tab and a// different write path (`usePromptInjection`), which is why both are asserted.await expect(page.getByRole("alert")).toHaveText(line);- await expect(notifications(page).getByRole("button")).toHaveCount(0);+ await expectNoToast(page);expect(state.seen).toHaveLength(1);await expectUnmoved(toggle, wasOn);diff --git a/packages/web/e2e/placeholder-insert-refusal.spec.mjs b/packages/web/e2e/placeholder-insert-refusal.spec.mjsindex 88b30c9f..0650a702 100644--- a/packages/web/e2e/placeholder-insert-refusal.spec.mjs+++ b/packages/web/e2e/placeholder-insert-refusal.spec.mjs@@ -9,6 +9,10 @@* Memory's own strip and the one the Skills / Vault / Schedules tabs share* (`usePromptInjection`) — two different code paths behind the same sentence.*+ * The strip carries the sentence, so nothing is also raised in the notification region; "no+ * notification" is read immediately after the line appears (`expectNoToast`), since a retrying+ * `toHaveCount(0)` would also pass once a toast had expired by itself.+ ** A plain template is written first: the default template already carries every placeholder, so* there would be no strip to press. The refusal is injected where the page's own write is —* `page.route` answers the placeholder POST with the server's words instead of forwarding it — and@@ -85,6 +89,18 @@ async function interceptInsert(page, projectId, feature, state) {/** The notification region: a refusal must not be announced there (that is the old toast). */const notifications = (page) => page.getByRole("region", { name: "通知" });+/**+ * Nothing was raised in the notification region for this refusal, read at once.+ *+ * `toHaveCount(0)` retries for the whole expect timeout, so it also passes against a toast that+ * simply expired after six seconds — the very behaviour this file is about. This reads the count+ * once, after a short settle so the refusal's own render has landed.+ */+async function expectNoToast(page) {+ await page.waitForTimeout(400);+ expect(await notifications(page).getByRole("button").count()).toBe(0);+}+test("a refused Memory placeholder insert keeps the reason under the strip, and the button retries", async ({page,}) => {@@ -103,7 +119,7 @@ test("a refused Memory placeholder insert keeps the reason under the strip, and// that asked are untouched, which is what makes that same button the retry.const line = `插入 {{MEMORY}} 占位符被拒:${REFUSAL.message}`;await expect(page.getByRole("alert")).toHaveText(line);- await expect(notifications(page).getByRole("button")).toHaveCount(0);+ await expectNoToast(page);await expect(insert).toBeVisible();expect(state.seen).toHaveLength(1);@@ -138,7 +154,7 @@ test("a refused Skills placeholder insert keeps the reason under that strip, and// different write path (`usePromptInjection`), which is why both are asserted.const line = `插入 {{SKILLS}} 占位符被拒:${REFUSAL.message}`;await expect(page.getByRole("alert")).toHaveText(line);- await expect(notifications(page).getByRole("button")).toHaveCount(0);+ await expectNoToast(page);await expect(insert).toBeVisible();expect(state.seen).toHaveLength(1);diff --git a/packages/web/src/features/agents/agent-settings-page.tsx b/packages/web/src/features/agents/agent-settings-page.tsxindex e980606e..4bbed716 100644--- a/packages/web/src/features/agents/agent-settings-page.tsx+++ b/packages/web/src/features/agents/agent-settings-page.tsx@@ -46,7 +46,6 @@ import {Tabs,Textarea,UpdateDot,- toastError,toastInfo,toastSuccess,} from "@adelie/ui";@@ -265,9 +264,10 @@ export function AgentSettingsPage() {void reloadAgents();}} catch (e) {- toastError(apiErrorText(e));// The save card asked for this write, so it is the card that says why (save-confirm.tsx):- // it waits on this promise and keeps the refusal under its own sentence.+ // it waits on this promise and keeps the refusal under its own sentence — which is also+ // why nothing is toasted here. The copy used to go to the notification region as well,+ // where it repeated the same words and outlived the card by six seconds.throw e;}},diff --git a/packages/web/src/features/agents/memory-tab.tsx b/packages/web/src/features/agents/memory-tab.tsxindex 86e3474c..252e3bb8 100644--- a/packages/web/src/features/agents/memory-tab.tsx+++ b/packages/web/src/features/agents/memory-tab.tsx@@ -168,7 +168,9 @@ export function MemoryTab({const [templateHasMemory, setTemplateHasMemory] = useState(true);const [memoryDir, setMemoryDir] = useState("");const [groups, setGroups] = useState<ScopeGroup[] | null>(null);- // Tab-level error is the initial load failure only; actions report via toast.+ // Tab-level error is the initial load failure only; an action that has nowhere to keep its+ // refusal — opening a memory, whose panel never got as far as opening — reports via toast, while+ // the ones below that draw the sentence where they asked do not toast as well.const [error, setError] = useState<string | null>(null);const [switchBusy, setSwitchBusy] = useState(false);// The server's words for a flip of the memory switch it refused, drawn under that card: the@@ -301,9 +303,10 @@ export function MemoryTab({onConfigChanged?.();} catch (e) {// Nothing moved: the switch shows what the server answered with, and a refused write has no- // answer — so the reason stays under the card, where the switch that retries it is.+ // answer — so the reason stays under the card, where the switch that retries it is. No toast+ // beside it: that line is the whole account of the refusal, and a second copy of it that+ // dismisses itself after six seconds only adds noise above the card it came from.setSwitchRefusal(featureSwitchRefused(S.memory.switchNoun, next, refusalText(e)));- toastError(apiErrorText(e));} finally {setSwitchBusy(false);}@@ -321,9 +324,9 @@ export function MemoryTab({} catch (e) {// Nothing was written, so the template still has no placeholder and the strip below stays —// that keeps the sentence next to the button that retries it (Memory has no legacy section- // to migrate, so the verb is always "insert").+ // to migrate, so the verb is always "insert"). The strip and this line are on screen, so a+ // notification carrying the same words would say it twice.setInsertRefusal(placeholderInsertRefused(S.memory.placeholderToken, false, refusalText(e)));- toastError(apiErrorText(e));}};@@ -366,9 +369,9 @@ export function MemoryTab({onConfigChanged?.();}).catch((e: unknown) => {- toastError(apiErrorText(e));// Handed back to the save card, which keeps the reason under its own sentence- // (save-confirm.tsx) — the toast above would otherwise be the only trace of it.+ // (save-confirm.tsx) — and nothing is toasted for it: that card is what the person is+ // reading, and a notification beside it would repeat the sentence while outliving it.throw e;});});diff --git a/packages/web/src/features/agents/prompt-injection-controls.tsx b/packages/web/src/features/agents/prompt-injection-controls.tsxindex 04406e21..815d93e9 100644--- a/packages/web/src/features/agents/prompt-injection-controls.tsx+++ b/packages/web/src/features/agents/prompt-injection-controls.tsx@@ -28,19 +28,10 @@ import type {AgentSkillsConfigDto,AgentVaultConfigDto,} from "@adelie/server/api";-import {- Button,- Card,- InfoPopover,- Notice,- Textarea,- ToggleRow,- toastError,- toastSuccess,-} from "@adelie/ui";+import { Button, Card, InfoPopover, Notice, Textarea, ToggleRow, toastSuccess } from "@adelie/ui";import * as api from "../../api/endpoints";import { S } from "../../lib/strings";-import { apiErrorText, refusalText } from "../../lib/api-error";+import { refusalText } from "../../lib/api-error";import { toneInk } from "../../lib/tone";import { useProject } from "../../state/project";import { featureSwitchRefused } from "./feature-switch-refusal";@@ -179,9 +170,10 @@ export function usePromptInjection({onConfigChanged?.();} catch (e) {// The switch never moved (its position comes from the config the server answers with), so- // the reason stays beside it — and the switch itself is the retry.+ // the reason stays beside it — and the switch itself is the retry. Nothing is toasted as+ // well: the line is the whole account, and a copy of it that dismisses itself after six+ // seconds would only be noise above the card it came from.setSwitchRefusal(featureSwitchRefused(strings.switchNoun, next, refusalText(e)));- toastError(apiErrorText(e));} finally {setSwitchBusy(false);}@@ -210,7 +202,8 @@ export function usePromptInjection({onConfigChanged?.();} catch (e) {// Nothing was written — the template the strip is drawn from is unchanged — so the sentence- // belongs under that strip, where the button that retries it still is.+ // belongs under that strip, where the button that retries it still is. The strip carries it,+ // so a notification would say the same thing a second time.setInsertRefusal(placeholderInsertRefused(promptStrings.placeholderToken,@@ -218,7 +211,6 @@ export function usePromptInjection({refusalText(e),),);- toastError(apiErrorText(e));}};@@ -234,9 +226,9 @@ export function usePromptInjection({onConfigChanged?.();}).catch((e: unknown) => {- toastError(apiErrorText(e));// Handed back to the save card, which keeps the reason under its own sentence- // (save-confirm.tsx) — the toast above would otherwise be the only trace of it.+ // (save-confirm.tsx) — and nothing is toasted for it: that card is what the person is+ // reading, and a notification beside it would repeat the sentence while outliving it.throw e;});});