Skip to content

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

fix(web): Agent 各分区的「启用」开关被拒时,原因留在卡片下面

lmlihenga1b5138c5587
diff --git a/changelog/unreleased/2026-11-03-agent-switch-refusal.md b/changelog/unreleased/2026-11-03-agent-switch-refusal.md
new file mode 100644
index 00000000..9b8b2d66
--- /dev/null
+++ b/changelog/unreleased/2026-11-03-agent-switch-refusal.md
@@ -0,0 +1,54 @@
+# A refused flip of an Agent tab's enable switch says so under its card, past the toast it used to be
+
+- **Date:** 2026-11-03
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文](2026-11-03-agent-switch-refusal.zh.md)
+
+Agent settings opens each tab with an enable switch: Memory has its own card, and Skills, Vault,
+Schedules and Hooks share one (`usePromptInjection`). None of them writes optimistically — the card
+is drawn from the config the server answered with — so a refused flip left the switch exactly where
+it was, with the reason in a six-second notification. Six seconds later the tab looked as if the
+switch had been pressed and come back on its own, and that switch is what gates the whole feature
+below it: memory entering the context, a vault the agent can reach, hooks assembled into a new
+Session.
+
+The reason now stays under the switch's card, as `role="alert"` — the only account of a switch that
+did not move — and it names the direction that failed, since the switch is still in the other
+position. It nods to the feature by its own noun ("记忆" / "hooks"), not by the card's label, which
+already begins with "启用" / "Enable" and would read twice inside a sentence about turning it on. It
+stays until the next flip is sent; the same switch is the retry.
+
+## Details
+
+- `packages/web/src/features/agents/feature-switch-refusal.ts` (new):
+ `featureSwitchRefused(noun, enabled, reason)` — the feature, the direction the flip asked for, and
+ the server's reason as given. Both code paths draw the same sentence from it.
+- `packages/web/src/lib/strings{,-en}.ts`: `agent.switchOnRefused` / `agent.switchOffRefused`, plus
+ the noun beside each card's own label (`memory.switchNoun` and `{skills,vault,schedule,hooks}.
+ injection.switchNoun`).
+- `packages/web/src/features/agents/prompt-injection-controls.tsx`: one `switchRefusal` state,
+ cleared when a flip is sent and set when the write is refused; the line is drawn directly under
+ the shared card. The failure notification stays — this adds the account that outlives it.
+- `packages/web/src/features/agents/memory-tab.tsx`: the same state and the same line under the
+ Memory card, which renders its switch before the overview has loaded and therefore also needs
+ nothing else to say why it would not move.
+
+## Tests
+
+- `packages/web/test/feature-switch-refusal.test.ts` (new, 6 cases): each direction, the reason
+ travelling verbatim, every feature's own noun (and that the label's "启用" is not repeated), the
+ active language.
+- `packages/web/e2e/agent-switch-refusal.spec.mjs` (new, two cases on a real server): the config
+ write is stubbed at `page.route`, once for the Memory card and once for the shared Skills card.
+ A refused flip puts one sentence under that card, the notification region holds no dismissal for
+ it, the switch does not move, and seven seconds later the sentence is still there; with the
+ refusal lifted the same switch goes through and the sentence goes.
+
+## Compatibility
+
+- No interface, request or storage change: the same `PUT …/agents/:id/config`, and the same
+ positions. Only where a refused flip is drawn has moved — from a notification alone to a line
+ under the card, which the notification no longer has to carry on its own.
diff --git a/changelog/unreleased/2026-11-03-agent-switch-refusal.zh.md b/changelog/unreleased/2026-11-03-agent-switch-refusal.zh.md
new file mode 100644
index 00000000..87510284
--- /dev/null
+++ b/changelog/unreleased/2026-11-03-agent-switch-refusal.zh.md
@@ -0,0 +1,43 @@
+# Agent 各分区的「启用」开关被拒时,原因留在卡片下面,不再只活六秒
+
+- **日期:** 2026-11-03
+- **类型:** 修复
+- **范围:** `web`
+- **不兼容变更:** 无
+
+[English](2026-11-03-agent-switch-refusal.md)
+
+Agent 设置的每个标签页都以一颗「启用」开关开头:记忆有自己的卡片,技能 / 密钥保险柜 / 定时任务 /
+钩子共用一颗(`usePromptInjection`)。这些开关都不做乐观写入 —— 卡片显示的是服务端答回来的配置 ——
+所以被拒之后开关静静地停在原处,解释只有一条六秒的通知。六秒过后,这个标签页看上去像「按了一下又自己
+弹回去」,而这颗开关正是它下面整个功能的闸门:记忆会不会进入上下文、Agent 能不能读到密钥保险柜、
+新会话要不要装配钩子。
+
+现在那句话留在开关卡片下面,带 `role="alert"` —— 开关没动,它是唯一的解释 —— 并且点名**这一次**
+想去的是哪一边(开关仍未移动,不说方向等于什么都没说)。它说的是功能自己的名词(「记忆」/「钩子」),
+不是卡片上那个已经以「启用」开头的标签,免得一句话里说两遍「启用」。这句话留到下一次同一种写为止,
+同一颗开关就是重试。
+
+## 细节
+
+- `packages/web/src/features/agents/feature-switch-refusal.ts`(新):`featureSwitchRefused(noun,
+ enabled, reason)` —— 功能、这次请求的方向、以及服务端给出的原话。两条代码路径画的是同一句话。
+- `packages/web/src/lib/strings{,-en}.ts`:`agent.switchOnRefused` / `agent.switchOffRefused`,以及
+ 每张卡片标签旁边的名词(`memory.switchNoun` 与 `{skills,vault,schedule,hooks}.injection.switchNoun`)。
+- `packages/web/src/features/agents/prompt-injection-controls.tsx`:一个 `switchRefusal` 状态,发出写
+ 请求时清掉、被拒时写上;那句话画在共享卡片的正下方。失败通知保留 —— 这一笔只是补上活得比它久的那一条。
+- `packages/web/src/features/agents/memory-tab.tsx`:同样的状态与同样的一句话,画在记忆卡片下面;这颗
+ 开关在概览读完之前就已经画出来了,所以更需要一句话说明它为什么不动。
+
+## 测试
+
+- `packages/web/test/feature-switch-refusal.test.ts`(新,6 条):两个方向、原话逐字透传、每个功能
+ 自己的名词(并断言没有重复标签里的「启用」)、当前界面语言。
+- `packages/web/e2e/agent-switch-refusal.spec.mjs`(新,真服务端上两条):配置写在 `page.route` 上
+ 被桩掉,一条测记忆卡片、一条测共享的技能卡片。被拒后卡片下面一条句子、通知区没有这条原因、开关没动,
+ 七秒后句子仍在;放开拒绝后再按同一颗开关就通过,句子归零。
+
+## 兼容性
+
+- 接口、请求与存储都没变:仍是同一个 `PUT …/agents/:id/config`,位置也照旧。变的只是「被拒之后画在
+ 哪里」—— 从只有一条通知,到卡片下面的一行字,通知因此不必再独自承担解释。
diff --git a/packages/web/e2e/agent-switch-refusal.spec.mjs b/packages/web/e2e/agent-switch-refusal.spec.mjs
new file mode 100644
index 00000000..3960dc7b
--- /dev/null
+++ b/packages/web/e2e/agent-switch-refusal.spec.mjs
@@ -0,0 +1,176 @@
+/**
+ * Regression: the enable switch at the head of an Agent settings tab says why a flip did not
+ * settle, under that switch's card — instead of leaving the card untouched with the reason in a
+ * toast that dismissed itself after six seconds.
+ *
+ * Both switches here write nothing optimistically: the card shows the position the config the
+ * server answers with holds, so a refused flip used to leave the tab exactly as it was — the switch
+ * did not move — and six seconds later nothing on screen said why. The two cases are the Memory
+ * 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 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
+ * are what must appear. Every user is seeded through the API; provisioning is idempotent, so a
+ * rerun of this file alone shares one data root with earlier runs.
+ */
+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 save: a 500 the app has no code for, so its own message reaches the screen. */
+const REFUSAL = { code: "agent_config_read_only", message: "agent config is read-only" };
+
+const configPath = (projectId) => `/api/projects/${projectId}/agents/${AGENT}/config`;
+/** The Memory tab's own read: what the switch's real position comes from. */
+const memoryPath = (projectId) => `/api/projects/${projectId}/agents/${AGENT}/memory`;
+
+/**
+ * Provision the user and give the Project a model — the onboarding overlay covers the page without
+ * one, and the cards this spec presses sit under it.
+ */
+async function projectWithModel(page, user) {
+ await provisionAndLogin(page.request, user, P);
+ const projectId = (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0]
+ .projectId;
+ const put = 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(put.ok(), "put models").toBeTruthy();
+ return projectId;
+}
+
+/**
+ * Take over the config write: every PUT is kept in `state.seen`, and while `state.refuse` is set it
+ * is answered with the server's refusal instead of reaching the real route.
+ */
+async function interceptConfigPut(page, projectId, state) {
+ await page.route(`**${configPath(projectId)}`, async (route) => {
+ if (route.request().method() !== "PUT") return route.fallback();
+ state.seen.push(route.request().postDataJSON());
+ if (!state.refuse) return route.fallback();
+ await route.fulfill({
+ status: 500,
+ contentType: "application/json",
+ body: JSON.stringify({ error: REFUSAL }),
+ });
+ });
+}
+
+/**
+ * Put the Memory switch in a known position before the page opens. The tab renders that switch on
+ * its own default while the overview is still loading, so a spec that reads it first would measure
+ * whichever state happened to be on screen; seeding makes the read and the load agree — and this
+ * test writes `false` at the end, so a rerun on the same (idempotently provisioned) user would
+ * otherwise start from the other position.
+ */
+async function seedMemory(page, projectId, enabled) {
+ const put = await page.request.put(`${BASE}${configPath(projectId)}`, {
+ data: { config: { memory: { enabled } } },
+ });
+ expect(put.ok(), "seed memory switch").toBeTruthy();
+}
+
+/** The notification region: a refusal must not be announced there (that is the old toast). */
+const notifications = (page) => page.getByRole("region", { name: "通知" });
+
+/**
+ * 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
+ * the direction is never inferable from the screen afterwards.
+ */
+const refusedLine = (noun, wasOn) =>
+ `${wasOn ? "关闭" : "开启"}${noun}的开关被拒:${REFUSAL.message}`;
+
+/** The switch must still be in the position the server holds — the one it had before the click. */
+async function expectUnmoved(toggle, wasOn) {
+ if (wasOn) await expect(toggle).toBeChecked();
+ else await expect(toggle).not.toBeChecked();
+}
+
+test("a refused flip of the Memory switch keeps the reason under the card, and the retry clears it", async ({
+ page,
+}) => {
+ const projectId = await projectWithModel(page, "r186memory");
+ await seedMemory(page, projectId, true);
+ const state = { seen: [], refuse: true };
+ await interceptConfigPut(page, projectId, state);
+
+ // The switch is drawn from a default until the overview lands; that read is what proves the tab
+ // has loaded, so the position read below is the server's and not the placeholder.
+ const loaded = page.waitForResponse(
+ (res) =>
+ res.request().method() === "GET" && new URL(res.url()).pathname === memoryPath(projectId),
+ );
+ await page.goto(`/agents/${AGENT}?tab=memory`);
+ const toggle = page.getByRole("switch", { name: "启用记忆" });
+ await expect(toggle).toBeVisible();
+ await loaded;
+ const wasOn = await toggle.isChecked();
+ expect(wasOn, "the seeded position").toBe(true);
+ const line = refusedLine("记忆", wasOn);
+
+ await 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.
+ await expect(page.getByRole("alert")).toHaveText(line);
+ await expect(notifications(page).getByRole("button")).toHaveCount(0);
+ expect(state.seen).toHaveLength(1);
+ // Nothing moved, because nothing was written: the switch is still where the server has it.
+ await expectUnmoved(toggle, wasOn);
+
+ // Six seconds is how long a toast lives; this line has to still be there after it.
+ await page.waitForTimeout(7_000);
+ await expect(page.getByRole("alert")).toHaveText(line);
+
+ // The same switch is the retry: this time the write lands, so the line goes and the switch moves.
+ state.refuse = false;
+ await toggle.click();
+ await expect(page.getByRole("alert")).toHaveCount(0);
+ await expectUnmoved(toggle, !wasOn);
+ expect(state.seen).toHaveLength(2);
+ expect(state.seen[1].config.memory.enabled).toBe(!wasOn);
+});
+
+test("a refused flip of the shared Skills switch keeps the reason under that card, and only there", async ({
+ page,
+}) => {
+ const projectId = await projectWithModel(page, "r186skills");
+ const state = { seen: [], refuse: true };
+ await interceptConfigPut(page, projectId, state);
+
+ await page.goto(`/agents/${AGENT}?tab=skills`);
+ const toggle = page.getByRole("switch", { name: "启用技能" });
+ await expect(toggle).toBeVisible();
+ const wasOn = await toggle.isChecked();
+ const line = refusedLine("技能", wasOn);
+
+ await toggle.click();
+
+ // 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);
+ expect(state.seen).toHaveLength(1);
+ await expectUnmoved(toggle, wasOn);
+
+ await page.waitForTimeout(7_000);
+ await expect(page.getByRole("alert")).toHaveText(line);
+});
diff --git a/packages/web/src/features/agents/feature-switch-refusal.ts b/packages/web/src/features/agents/feature-switch-refusal.ts
new file mode 100644
index 00000000..7ffaa726
--- /dev/null
+++ b/packages/web/src/features/agents/feature-switch-refusal.ts
@@ -0,0 +1,24 @@
+/**
+ * The enable switch at the head of an Agent settings tab (Memory's own, and the one shared by
+ * Skills / Vault / Schedules / Hooks), and the line a refusal leaves under its card.
+ *
+ * None of these switches moves optimistically: the switch shows the position the server answered
+ * with, so a refused flip leaves the card exactly as it was — the switch in its old position, the
+ * tab unchanged — and the reason used to live only in a toast that dismissed itself after six
+ * seconds. Six seconds later the switch simply looked as if it had been pressed and come back, with
+ * nothing on screen saying why; that is the shape 7.19 bans app-wide, and this is the page where
+ * the switch gates the whole feature below it (memory not entering the context, no hooks assembled
+ * into a new Session, an unreachable vault).
+ *
+ * The sentence names the direction that failed, and it has to: the switch is still in the other
+ * position, so "why is it still off" and "why is it still on" are two different sentences, and
+ * naming the wrong one would say something the person never asked for. The noun is the feature's
+ * own (`switchNoun` beside each `enable` label), not that label — every label already begins with
+ * "启用" / "Enable", and reading it back inside a sentence about turning it on says it twice.
+ */
+import { S } from "../../lib/strings";
+
+/** The line a refused flip leaves under the switch's card: the feature, which way it was asked to move, and the server's reason as it gave it. */
+export function featureSwitchRefused(noun: string, enabled: boolean, reason: string): string {
+ return enabled ? S.agent.switchOnRefused(noun, reason) : S.agent.switchOffRefused(noun, reason);
+}
diff --git a/packages/web/src/features/agents/memory-tab.tsx b/packages/web/src/features/agents/memory-tab.tsx
index b46619d2..33cd57e9 100644
--- a/packages/web/src/features/agents/memory-tab.tsx
+++ b/packages/web/src/features/agents/memory-tab.tsx
@@ -63,11 +63,13 @@ import {
import type { SheetSnap } from "@adelie/ui";
import * as api from "../../api/endpoints";
import { S } from "../../lib/strings";
-import { apiErrorText } from "../../lib/api-error";
+import { apiErrorText, refusalText } from "../../lib/api-error";
+import { toneInk } from "../../lib/tone";
import { formatRelativeDate } from "../../lib/format";
import { useAuth } from "../../state/auth";
import { useLocale } from "../../state/locale";
import { useProject } from "../../state/project";
+import { featureSwitchRefused } from "./feature-switch-refusal";
import { useSaveConfirm } from "./save-confirm";
import { useAiBridge } from "../ai-create";
import { buildMemoryAddPrompt, buildMemoryEditPrompt } from "./memory-chat-prompts";
@@ -153,6 +155,9 @@ export function MemoryTab({
// Tab-level error is the initial load failure only; actions report via toast.
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
+ // switch keeps the position the server has, so this line is the only account of why.
+ const [switchRefusal, setSwitchRefusal] = useState<string | null>(null);
const collapseKey = userId && projectId ? collapsedStoreKey(userId, projectId, agentId) : null;
const [collapsed, setCollapsed] = useState<Set<string>>(() => readCollapsedScopes(collapseKey));
const [memoryPrompt, setMemoryPrompt] = useState("");
@@ -262,6 +267,7 @@ export function MemoryTab({
const toggleEnabled = async (next: boolean) => {
if (!projectId) return;
setSwitchBusy(true);
+ setSwitchRefusal(null);
try {
const res = await api.putAgentConfig(projectId, agentId, {
config: { memory: { enabled: next } },
@@ -270,6 +276,9 @@ export function MemoryTab({
toastSuccess(S.agent.savedTakesEffect);
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.
+ setSwitchRefusal(featureSwitchRefused(S.memory.switchNoun, next, refusalText(e)));
toastError(apiErrorText(e));
} finally {
setSwitchBusy(false);
@@ -600,6 +609,14 @@ export function MemoryTab({
disabled={switchBusy}
/>
+ {/* The switch shows the position the server holds (a refused write answers nothing), so this
+ sentence is what says why it did not move — and the switch above it is the retry. */}
+ {switchRefusal !== null && (
+ <p role="alert" className={`text-xs break-words ${toneInk.danger}`}>
+ {switchRefusal}
+ </p>
+ )}
+
{!templateHasMemory && (
<Notice
tone="attention"
diff --git a/packages/web/src/features/agents/prompt-injection-controls.tsx b/packages/web/src/features/agents/prompt-injection-controls.tsx
index 3c22e1cf..2509117a 100644
--- a/packages/web/src/features/agents/prompt-injection-controls.tsx
+++ b/packages/web/src/features/agents/prompt-injection-controls.tsx
@@ -40,8 +40,10 @@ import {
} from "@adelie/ui";
import * as api from "../../api/endpoints";
import { S } from "../../lib/strings";
-import { apiErrorText } from "../../lib/api-error";
+import { apiErrorText, refusalText } from "../../lib/api-error";
+import { toneInk } from "../../lib/tone";
import { useProject } from "../../state/project";
+import { featureSwitchRefused } from "./feature-switch-refusal";
import { useSaveConfirm } from "./save-confirm";
export type PromptInjectionFeature = "skills" | "vault" | "schedules" | "hooks";
@@ -49,6 +51,8 @@ export type PromptInjectionFeature = "skills" | "vault" | "schedules" | "hooks";
/** What every feature supplies: the switch card's label, plus the two strings a switch-only feature needs in place of the prompt section's own wording. */
interface ToggleStrings {
enable: string;
+ /** What a refused flip of this switch names (feature-switch-refusal.ts): the feature, not the label — the label already starts with "启用". */
+ switchNoun: string;
/** Disclosed beside the label ("?"): what the switch decides and when a change lands. Omitted where the tab's own description already says it. */
enableHint?: string;
/** Toast after a successful flip; defaults to the agent-config wording, whose compaction clause only fits a prompt section. */
@@ -126,6 +130,9 @@ export function usePromptInjection({
const [state, setState] = useState<SectionConfigState | null>(null);
const [prompt, setPrompt] = useState("");
const [switchBusy, setSwitchBusy] = useState(false);
+ // The server's words for a flip it refused, drawn under the switch card: the switch stays where
+ // the server has it, so this line is the only account of why it did not move.
+ const [switchRefusal, setSwitchRefusal] = useState<string | null>(null);
const promptRef = useRef<HTMLTextAreaElement>(null);
const { requestSave, element: saveConfirm } = useSaveConfirm();
@@ -158,12 +165,16 @@ export function usePromptInjection({
const toggleEnabled = async (next: boolean) => {
if (!projectId) return;
setSwitchBusy(true);
+ setSwitchRefusal(null);
try {
const res = await api.putAgentConfig(projectId, agentId, featurePatch({ enabled: next }));
applyConfig(res.config);
toastSuccess(strings.savedToast ?? S.agent.savedTakesEffect);
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.
+ setSwitchRefusal(featureSwitchRefused(strings.switchNoun, next, refusalText(e)));
toastError(apiErrorText(e));
} finally {
setSwitchBusy(false);
@@ -209,14 +220,24 @@ export function usePromptInjection({
});
const toggleCard = state !== null && (
- <ToggleRow
- variant="card"
- label={strings.enable}
- info={strings.enableHint}
- checked={state.enabled}
- onChange={(v) => void toggleEnabled(v)}
- disabled={switchBusy || !canEdit}
- />
+ <>
+ <ToggleRow
+ variant="card"
+ label={strings.enable}
+ info={strings.enableHint}
+ checked={state.enabled}
+ onChange={(v) => void toggleEnabled(v)}
+ disabled={switchBusy || !canEdit}
+ />
+ {/* The card is drawn from the config the server answered with, never from the click, so a
+ refused flip leaves it in the old position — this sentence is what says why, and the
+ switch above it is the retry. Cleared when the next flip is sent. */}
+ {switchRefusal !== null && (
+ <p role="alert" className={`text-xs break-words ${toneInk.danger}`}>
+ {switchRefusal}
+ </p>
+ )}
+ </>
);
// Legacy templates get the migration wording (and the legacy strings always exist for the
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index 1ec7f6cb..7bd92ad3 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -1612,6 +1612,15 @@ export const en: Strings = {
savedTakesEffect:
"Saved. New conversations pick it up right away; running ones after their next compaction.",
savedTakesEffectNow: "Saved. It takes effect immediately, including running conversations.",
+ /**
+ * A feature's enable switch that the server refused (feature-switch-refusal.ts), drawn under
+ * the card that holds it: which way the switch was asked to move — it never moved, the
+ * position on screen is the server's — and the reason, as the server gave it.
+ */
+ switchOnRefused: (noun: string, reason: string): string =>
+ `Turning the ${noun} switch on was refused: ${reason}`,
+ switchOffRefused: (noun: string, reason: string): string =>
+ `Turning the ${noun} switch off was refused: ${reason}`,
takesEffectSuffix:
" — new conversations pick it up right away, running ones after their next compaction",
listTitle: "Agents",
@@ -2380,6 +2389,7 @@ export const en: Strings = {
memory: {
desc: "Long-term memory across Sessions (stored in agent_state/memory/): the agent saves what is worth keeping as it works, and you can also just ask it to remember something. User memory applies to all of this agent's sessions; workspace memory is kept per workspace. Memory edits are made by the agent in chat. Turning the switch off only stops memory from being used and deletes nothing.",
enable: "Enable memory",
+ switchNoun: "memory",
userScope: "User memory",
templateMissing:
"The prompt template has no {{MEMORY}} placeholder, so memory never enters the context.",
@@ -2551,6 +2561,7 @@ export const en: Strings = {
/** Prompt-injection controls (toggle card / template alert / prompt editor), mirroring the memory tab's set. */
injection: {
enable: "Enable vault",
+ switchNoun: "vault",
templateMissing:
"The prompt template has no {{VAULT}} placeholder, so the vault section never enters the context.",
legacyTemplate:
@@ -2735,6 +2746,7 @@ export const en: Strings = {
/** Prompt-injection controls (toggle card / template alert / prompt editor), mirroring the memory tab's set. */
injection: {
enable: "Enable schedules",
+ switchNoun: "schedules",
templateMissing:
"The prompt template has no {{SCHEDULES}} placeholder, so the scheduled-tasks section never enters the context.",
insertPlaceholder: "Insert the {{SCHEDULES}} placeholder",
@@ -3046,6 +3058,7 @@ export const en: Strings = {
/** The Agent-level switch card at the top of the tab (usePromptInjection); hooks have no prompt half. */
injection: {
enable: "Enable hooks",
+ switchNoun: "hooks",
enableHint:
"With it on, every Session this agent starts runs all installed hook packages at the loop's hook points. With it off, a new Session runs no hooks at all and the installed packages stay on disk. A Task already running keeps the setting it started with until its context is compacted.",
savedToast: "Saved — takes effect from the next turn",
@@ -3137,6 +3150,7 @@ export const en: Strings = {
/** Prompt-injection controls (toggle card / template alert / prompt editor), mirroring the memory tab's set. */
injection: {
enable: "Enable skills",
+ switchNoun: "skills",
templateMissing:
"The prompt template has no {{SKILLS}} placeholder, so the skills section never enters the context.",
legacyTemplate:
diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.ts
index bfdfda05..9793ab52 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -1658,6 +1658,13 @@ export const zh = {
savedTakesEffect: "已保存。新对话立即生效;进行中的对话在下一次压缩后生效。",
/** Save feedback when the change touched compaction settings only: the engine re-reads them at every compaction checkpoint, so a running conversation does not have to reach one first. */
savedTakesEffectNow: "已保存,立即生效(包括进行中的对话)。",
+ /**
+ * A feature's enable switch that the server refused (feature-switch-refusal.ts), drawn under
+ * the card that holds it: which way the switch was asked to move — it never moved, the
+ * position on screen is the server's — and the reason, as the server gave it.
+ */
+ switchOnRefused: (noun: string, reason: string): string => `开启${noun}的开关被拒:${reason}`,
+ switchOffRefused: (noun: string, reason: string): string => `关闭${noun}的开关被拒:${reason}`,
/** Appended to an action's own toast (skill install / uninstall) — same timing statement. */
takesEffectSuffix: ";新对话立即生效,进行中的对话在下一次压缩后生效",
listTitle: "Agents",
@@ -2442,6 +2449,8 @@ export const zh = {
memory: {
desc: "跨 Session 的长期记忆(存于 agent_state/memory/):agent 会在对话中自行记下值得保留的信息,你也可以直接让它记住某件事。用户记忆对本 Agent 的所有会话生效,工作区记忆按工作区隔离;记忆修改在对话中由 agent 完成。关闭开关只停止使用记忆,不删除任何文件。",
enable: "启用记忆",
+ /** What a refused flip of this switch names (feature-switch-refusal.ts): the switch, not the label. */
+ switchNoun: "记忆",
userScope: "用户记忆",
templateMissing: "提示词模板中没有 {{MEMORY}} 占位符,记忆不会进入上下文。",
insertPlaceholder: "插入 {{MEMORY}} 占位符",
@@ -2614,6 +2623,7 @@ export const zh = {
/** Prompt-injection controls (toggle card / template alert / prompt editor), mirroring the memory tab's set. */
injection: {
enable: "启用密钥保险柜",
+ switchNoun: "密钥保险柜",
templateMissing: "提示词模板中没有 {{VAULT}} 占位符,保险柜小节不会进入上下文。",
legacyTemplate:
"模板仍是旧版硬编码的 # Vault 段落:一键迁移会将该段落原位替换为 {{VAULT}} 占位符,措辞不变,此后可在下方编辑。",
@@ -2787,6 +2797,7 @@ export const zh = {
/** Prompt-injection controls (toggle card / template alert / prompt editor), mirroring the memory tab's set. */
injection: {
enable: "启用定时任务",
+ switchNoun: "定时任务",
templateMissing: "提示词模板中没有 {{SCHEDULES}} 占位符,定时任务小节不会进入上下文。",
insertPlaceholder: "插入 {{SCHEDULES}} 占位符",
promptSection: "定时任务提示词",
@@ -3089,6 +3100,7 @@ export const zh = {
/** The Agent-level switch card at the top of the tab (usePromptInjection); hooks have no prompt half. */
injection: {
enable: "启用钩子",
+ switchNoun: "钩子",
enableHint:
"开启后,该 Agent 新建的 Session 会在钩子点运行全部已安装的钩子包;关闭后新建的 Session 不运行任何钩子,已安装的包仍保留在磁盘上。进行中的 Task 保持开始时的设置,直到其上下文被压缩。",
savedToast: "已保存,自下一轮对话起生效",
@@ -3179,6 +3191,7 @@ export const zh = {
/** Prompt-injection controls (toggle card / template alert / prompt editor), mirroring the memory tab's set. */
injection: {
enable: "启用技能",
+ switchNoun: "技能",
templateMissing: "提示词模板中没有 {{SKILLS}} 占位符,技能小节不会进入上下文。",
legacyTemplate:
"模板仍是旧版硬编码的 # Skills 段落:一键迁移会将该段落原位替换为 {{SKILLS}} 占位符,措辞不变,此后可在下方编辑。",
diff --git a/packages/web/test/feature-switch-refusal.test.ts b/packages/web/test/feature-switch-refusal.test.ts
new file mode 100644
index 00000000..cfcdcaf8
--- /dev/null
+++ b/packages/web/test/feature-switch-refusal.test.ts
@@ -0,0 +1,84 @@
+/**
+ * How the Agent settings tabs name a refused flip of a feature's enable switch
+ * (`featureSwitchRefused`): the Memory tab's own card, and the card shared by Skills / Vault /
+ * Schedules / Hooks.
+ *
+ * None of those switches move optimistically — the card shows the position the server answered
+ * with — so a toast used to be the only account of a failure, and six seconds later the switch
+ * looked as though it had been pressed and come back by itself.
+ *
+ * - The sentence names the direction that failed ("开启" / "关闭"), because the switch is still in
+ * the other position: naming the wrong one would answer a question nobody asked.
+ * - It names the feature with its own noun, not the card's label — every label already begins with
+ * "启用" / "Enable", and reading that back inside a sentence about turning it on says it twice.
+ * - The reason is whatever the server gave, verbatim.
+ */
+import { afterEach, describe, expect, it } from "vitest";
+import { S, setActiveStrings, zh as ZH } from "../src/lib/strings";
+import { en as EN } from "../src/lib/strings-en";
+import { featureSwitchRefused } from "../src/features/agents/feature-switch-refusal";
+
+afterEach(() => {
+ setActiveStrings(ZH);
+});
+
+describe("featureSwitchRefused", () => {
+ it("names turning the feature on as the ask that failed", () => {
+ expect(featureSwitchRefused("记忆", true, "Internal server error")).toBe(
+ "开启记忆的开关被拒:Internal server error",
+ );
+ });
+
+ it("names turning it off as a different ask", () => {
+ // The switch is still where the server has it, so the direction cannot be inferred on screen.
+ expect(featureSwitchRefused("记忆", false, "Internal server error")).toBe(
+ "关闭记忆的开关被拒:Internal server error",
+ );
+ });
+
+ it("carries the server's reason verbatim, punctuation and all", () => {
+ expect(featureSwitchRefused("钩子", true, "服务器内部错误,请稍后重试。")).toBe(
+ "开启钩子的开关被拒:服务器内部错误,请稍后重试。",
+ );
+ });
+
+ it("names the feature the card belongs to, so each tab's line says which switch", () => {
+ // Every noun travels with its own card: two tabs are never on screen at once, but the sentence
+ // has to be right for the one that is.
+ expect(featureSwitchRefused(S.memory.switchNoun, false, "nope")).toBe(
+ "关闭记忆的开关被拒:nope",
+ );
+ expect(featureSwitchRefused(S.skills.injection.switchNoun, false, "nope")).toBe(
+ "关闭技能的开关被拒:nope",
+ );
+ expect(featureSwitchRefused(S.vault.injection.switchNoun, false, "nope")).toBe(
+ "关闭密钥保险柜的开关被拒:nope",
+ );
+ expect(featureSwitchRefused(S.schedule.injection.switchNoun, true, "nope")).toBe(
+ "开启定时任务的开关被拒:nope",
+ );
+ expect(featureSwitchRefused(S.hooks.injection.switchNoun, true, "nope")).toBe(
+ "开启钩子的开关被拒:nope",
+ );
+ });
+
+ it("does not repeat the label's own 启用", () => {
+ // The trap the noun exists for: "启用技能" is the label, and "开启启用技能" says it twice.
+ expect(featureSwitchRefused(S.skills.injection.switchNoun, true, "nope")).not.toContain(
+ "开启启用",
+ );
+ });
+
+ it("follows the interface language", () => {
+ setActiveStrings(EN);
+ expect(S.agent.switchOnRefused("memory", "nope")).toBe(
+ "Turning the memory switch on was refused: nope",
+ );
+ expect(S.agent.switchOffRefused("memory", "nope")).toBe(
+ "Turning the memory switch off was refused: nope",
+ );
+ expect(featureSwitchRefused(S.hooks.injection.switchNoun, true, "nope")).toBe(
+ "Turning the hooks switch on was refused: nope",
+ );
+ });
+});