Skip to content

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

fix(web): 插入占位符被拒时,原因留在提示条下面,不再只活六秒

lmlihengaf336ae61f2e
diff --git a/changelog/unreleased/2026-11-03-placeholder-insert-refusal.md b/changelog/unreleased/2026-11-03-placeholder-insert-refusal.md
new file mode 100644
index 00000000..c17f01fe
--- /dev/null
+++ b/changelog/unreleased/2026-11-03-placeholder-insert-refusal.md
@@ -0,0 +1,55 @@
+# A refused placeholder insert says so under the strip that asked, past the toast it used to be
+
+- **Date:** 2026-11-03
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文](2026-11-03-placeholder-insert-refusal.zh.md)
+
+The top of the Memory tab — and of the Skills, Vault and Schedules tabs — carries a strip while the
+Agent's prompt template still lacks its placeholder, and the strip's button asks the server to
+write that placeholder in. Nothing on the page moves until the write lands, so a refused one leaves
+the template without the placeholder and the strip — with its button — exactly where it was; the
+reason used to arrive only as a six-second notification, and six seconds later the strip looked as
+though it had never been pressed. This one is more than a settings write: it is the path that
+adopts the whole feature into the context (memory entering it, the skills and vault sections
+present, the schedules section present).
+
+The reason now stays directly under the strip, in the words of the button that was pressed (a legacy
+template's button migrates, so the sentence says "migrating" rather than "inserting"), names which
+placeholder — four sections share the one sentence — and carries the server's reason as given. It
+stays until the next insert; the strip's own button is the retry.
+
+## Details
+
+- `packages/web/src/features/agents/placeholder-insert-refusal.ts` (new):
+ `placeholderInsertRefused(token, legacy, reason)` — the placeholder token, whether the button
+ that was pressed inserts or migrates, and the server's reason.
+- `packages/web/src/lib/strings{,-en}.ts`: the two sentences
+ (`agent.placeholderInsertRefused` / `placeholderMigrateRefused`), plus four `placeholderToken`
+ fields — memory, skills, vault, schedules — each written beside its own strip and button wording.
+- `packages/web/src/features/agents/memory-tab.tsx` and `prompt-injection-controls.tsx`: one
+ `insertRefusal` state each (cleared when a write starts, set when one is refused), drawn under the
+ strip (`role="alert"`, danger ink, capped at two lines). The failure notification stays — this
+ adds the account that outlives it, it does not take one away.
+
+## Tests
+
+- `packages/web/test/placeholder-insert-refusal.test.ts` (new, 5 cases): the insert and migrate
+ wordings, each section's own token, the reason travelling verbatim (its punctuation included),
+ the active language.
+- `packages/web/e2e/placeholder-insert-refusal.spec.mjs` (new, two cases on a real server): the
+ Agent's prompt template is first replaced with plain text (the default template carries every
+ placeholder, so no strip would appear at all); one case on the Memory tab and one on Skills — a
+ refusal leaves exactly one sentence under the strip, the strip and its button still there, no
+ dismissible entry in the notification region, and seven seconds later the sentence is still
+ there; with the refusal lifted the same button goes through, the sentence and the strip go, and
+ the template holds the placeholder.
+
+## Compatibility
+
+- No interface, request or storage change: the same four
+ `POST …/{memory,skills,vault,schedules}/template-placeholder` calls. Only where a refused one is
+ drawn has moved — from a notification alone to a line under the strip, which the notification no
+ longer has to carry on its own.
diff --git a/changelog/unreleased/2026-11-03-placeholder-insert-refusal.zh.md b/changelog/unreleased/2026-11-03-placeholder-insert-refusal.zh.md
new file mode 100644
index 00000000..1d1932bf
--- /dev/null
+++ b/changelog/unreleased/2026-11-03-placeholder-insert-refusal.zh.md
@@ -0,0 +1,44 @@
+# 插入占位符被拒时,原因留在那条提示条下面,不再只活六秒
+
+- **日期:** 2026-11-03
+- **类型:** fix
+- **范围:** `web`
+- **破坏性:** 无
+
+[English](2026-11-03-placeholder-insert-refusal.md)
+
+Agent 设置的记忆页与技能 / 密钥保险柜 / 定时任务各页顶上,在提示词模板还缺占位符时都有一条提示条,
+条上那颗按钮请服务端把占位符写进模板。写没落地之前页面上什么都不动,所以被拒之后模板照旧没有占位符、
+提示条和那颗按钮都还在 —— 而原因此前只进一条六秒的通知。六秒之后提示条看上去像没被按过;这一处还
+不只是个设置写:它是整个功能接进上下文的那条路(记忆进不进上下文、技能与保险柜小节在不在、定时任务
+小节在不在)。
+
+现在原因留在提示条正下方,按的是那颗按钮自己的措辞(旧版模板的按钮是「迁移」,句子就说「迁移为」而
+不是「插入」),点明是哪一个占位符(四个小节共用这句话),并带上服务端给出的原话,留到下一次插入为
+止 —— 提示条上那颗按钮就是重试。
+
+## 细节
+
+- `packages/web/src/features/agents/placeholder-insert-refusal.ts`(新):
+ `placeholderInsertRefused(token, legacy, reason)` —— 占位符 token、这一次按的是「插入」还是
+ 「迁移」、服务端原话。
+- `packages/web/src/lib/strings{,-en}.ts`:`agent.placeholderInsertRefused` /
+ `placeholderMigrateRefused` 两对句,以及四处 `placeholderToken`(记忆、技能、保险柜、定时任务各一个,
+ 写在它自己那条提示条与按钮的文案旁边)。
+- `packages/web/src/features/agents/memory-tab.tsx` 与 `prompt-injection-controls.tsx`:各一个
+ `insertRefusal` 状态(发出写时清掉、被拒时写上),句子画在提示条下面(`role="alert"`、危险色、
+ 限两行)。失败通知保留 —— 本笔补上一条活得更久的说法,没有撤掉任何一条。
+
+## 测试
+
+- `packages/web/test/placeholder-insert-refusal.test.ts`(新,5 条):插入与迁移两种措辞、四个小节各有
+ 自己的 token、原因原样带过去(含服务端自己的标点)、跟着界面语言走。
+- `packages/web/e2e/placeholder-insert-refusal.spec.mjs`(新,真服务端两条):先把 Agent 的提示词模板
+ 换成不带占位符的纯文本(否则默认模板里什么都有、提示条根本不出现);记忆页与技能页各一条 —— 被拒后
+ 提示条下面恰好一句、提示条与按钮都还在、通知区没有可点的条目、七秒后句子仍在;放开拒绝再按同一颗
+ 按钮,句子和提示条一起消失、模板里有了占位符。
+
+## 兼容
+
+- 接口、请求与存储都没变:还是那四个 `POST …/{memory,skills,vault,schedules}/template-placeholder`。
+ 改变的只有被拒之后画在哪里 —— 从「只有一条通知」到「提示条下面多一条活得下去的说法」。
diff --git a/packages/web/e2e/placeholder-insert-refusal.spec.mjs b/packages/web/e2e/placeholder-insert-refusal.spec.mjs
new file mode 100644
index 00000000..88b30c9f
--- /dev/null
+++ b/packages/web/e2e/placeholder-insert-refusal.spec.mjs
@@ -0,0 +1,153 @@
+/**
+ * Regression: the "insert the placeholder" strip at the head of a prompt section says why the
+ * write it asked for did not land, under that strip — instead of leaving the template untouched
+ * with the reason in a toast that dismissed itself after six seconds.
+ *
+ * The strip stays either way: nothing is written until the server writes it, so a refused insert
+ * leaves the template without its placeholder, and the button that asked is still there to ask
+ * again. Six seconds later it used to look as though it had never been pressed. The two cases are
+ * Memory's own strip and the one the Skills / Vault / Schedules tabs share
+ * (`usePromptInjection`) — two different code paths behind the same sentence.
+ *
+ * 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
+ * the code is one the app has no sentence for, so what must appear on screen is the server's own
+ * message. 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 write: a code the app has no sentence for, so its own message reaches the screen. */
+const REFUSAL = { code: "agent_config_read_only", message: "agent config is read-only" };
+
+/** A template carrying no placeholder and no legacy hardcoded section: every strip would show. */
+const PLAIN_TEMPLATE = "You are a probe agent. Answer briefly.";
+
+const agentBase = (projectId) => `/api/projects/${projectId}/agents/${AGENT}`;
+const placeholderPath = (projectId, feature) =>
+ `${agentBase(projectId)}/${feature}/template-placeholder`;
+
+/**
+ * Provision the user, give the Project a model (the onboarding overlay covers the page without
+ * one), and replace the Agent's prompt template with a plain one so the strips have something to
+ * offer this agent.
+ */
+async function projectWithPlainTemplate(page, user) {
+ await provisionAndLogin(page.request, user, P);
+ const projectId = (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0]
+ .projectId;
+ const models = await page.request.put(`${BASE}/api/projects/${projectId}/models`, {
+ data: {
+ defaultModel: { provider: "custom", modelId: "claude-4-8" },
+ models: [
+ {
+ provider: "custom",
+ modelId: "claude-4-8",
+ apiKey: "sk-mock",
+ baseUrl: MOCK,
+ contextWindow: 200000,
+ },
+ ],
+ },
+ });
+ expect(models.ok(), "put models").toBeTruthy();
+ const template = await page.request.put(`${BASE}${agentBase(projectId)}/config`, {
+ data: { config: { systemPrompt: PLAIN_TEMPLATE } },
+ });
+ expect(template.ok(), "plain template").toBeTruthy();
+ return projectId;
+}
+
+/**
+ * Take over the placeholder write: every POST is counted 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 interceptInsert(page, projectId, feature, state) {
+ await page.route(`**${placeholderPath(projectId, feature)}`, async (route) => {
+ if (route.request().method() !== "POST") return route.fallback();
+ state.seen.push(route.request().method());
+ if (!state.refuse) return route.fallback();
+ await route.fulfill({
+ status: 500,
+ contentType: "application/json",
+ body: JSON.stringify({ error: REFUSAL }),
+ });
+ });
+}
+
+/** The notification region: a refusal must not be announced there (that is the old toast). */
+const notifications = (page) => page.getByRole("region", { name: "通知" });
+
+test("a refused Memory placeholder insert keeps the reason under the strip, and the button retries", async ({
+ page,
+}) => {
+ const projectId = await projectWithPlainTemplate(page, "r187memory");
+ const state = { seen: [], refuse: true };
+ await interceptInsert(page, projectId, "memory", state);
+
+ await page.goto(`/agents/${AGENT}?tab=memory`);
+ const insert = page.getByRole("button", { name: "插入 {{MEMORY}} 占位符" });
+ await expect(insert).toBeVisible();
+ await expect(page.getByRole("alert")).toHaveCount(0);
+
+ await insert.click();
+
+ // The sentence names the placeholder and carries the server's words; the strip and the button
+ // 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 expect(insert).toBeVisible();
+ expect(state.seen).toHaveLength(1);
+
+ // 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);
+ await expect(insert).toBeVisible();
+
+ // The same button is the retry: this time the write lands, so the line goes and the strip goes
+ // with the placeholder it was offering.
+ state.refuse = false;
+ await insert.click();
+ await expect(page.getByRole("alert")).toHaveCount(0);
+ await expect(insert).toHaveCount(0);
+ expect(state.seen).toHaveLength(2);
+});
+
+test("a refused Skills placeholder insert keeps the reason under that strip, and only there", async ({
+ page,
+}) => {
+ const projectId = await projectWithPlainTemplate(page, "r187skills");
+ const state = { seen: [], refuse: true };
+ await interceptInsert(page, projectId, "skills", state);
+
+ await page.goto(`/agents/${AGENT}?tab=skills`);
+ const insert = page.getByRole("button", { name: "插入 {{SKILLS}} 占位符" });
+ await expect(insert).toBeVisible();
+
+ await insert.click();
+
+ // Same shape as Memory's strip above and the same sentence builder, but a different tab and a
+ // 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 expect(insert).toBeVisible();
+ expect(state.seen).toHaveLength(1);
+
+ await page.waitForTimeout(7_000);
+ await expect(page.getByRole("alert")).toHaveText(line);
+
+ state.refuse = false;
+ await insert.click();
+ await expect(page.getByRole("alert")).toHaveCount(0);
+ await expect(insert).toHaveCount(0);
+ expect(state.seen).toHaveLength(2);
+});
diff --git a/packages/web/src/features/agents/memory-tab.tsx b/packages/web/src/features/agents/memory-tab.tsx
index 33cd57e9..d2745da5 100644
--- a/packages/web/src/features/agents/memory-tab.tsx
+++ b/packages/web/src/features/agents/memory-tab.tsx
@@ -70,6 +70,7 @@ import { useAuth } from "../../state/auth";
import { useLocale } from "../../state/locale";
import { useProject } from "../../state/project";
import { featureSwitchRefused } from "./feature-switch-refusal";
+import { placeholderInsertRefused } from "./placeholder-insert-refusal";
import { useSaveConfirm } from "./save-confirm";
import { useAiBridge } from "../ai-create";
import { buildMemoryAddPrompt, buildMemoryEditPrompt } from "./memory-chat-prompts";
@@ -158,6 +159,9 @@ export function MemoryTab({
// 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);
+ // The server's words for a refused placeholder write, drawn under the strip that asked: the
+ // template still has no {{MEMORY}}, so the strip and its button stay and that button is the retry.
+ const [insertRefusal, setInsertRefusal] = 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("");
@@ -288,12 +292,17 @@ export function MemoryTab({
/** The explicit adoption path for an agent whose template predates Memory: one idempotent config write. */
const insertPlaceholder = async () => {
if (!projectId) return;
+ setInsertRefusal(null);
try {
const overview = await api.insertMemoryPlaceholder(projectId, agentId);
setTemplateHasMemory(overview.templateHasMemory);
toastSuccess(S.memory.insertPlaceholderDone);
onConfigChanged?.();
} 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").
+ setInsertRefusal(placeholderInsertRefused(S.memory.placeholderToken, false, refusalText(e)));
toastError(apiErrorText(e));
}
};
@@ -618,13 +627,22 @@ export function MemoryTab({
)}
{!templateHasMemory && (
- <Notice
- tone="attention"
- variant="callout"
- action={{ label: S.memory.insertPlaceholder, onClick: () => void insertPlaceholder() }}
- >
- {S.memory.templateMissing}
- </Notice>
+ <>
+ <Notice
+ tone="attention"
+ variant="callout"
+ action={{ label: S.memory.insertPlaceholder, onClick: () => void insertPlaceholder() }}
+ >
+ {S.memory.templateMissing}
+ </Notice>
+ {/* A refused write leaves the strip (and its button) in place, so the reason can sit
+ right under it — the strip's own button is what retries. */}
+ {insertRefusal !== null && (
+ <p role="alert" className={`text-xs break-words ${toneInk.danger}`}>
+ {insertRefusal}
+ </p>
+ )}
+ </>
)}
{groups === null ? (
diff --git a/packages/web/src/features/agents/placeholder-insert-refusal.ts b/packages/web/src/features/agents/placeholder-insert-refusal.ts
new file mode 100644
index 00000000..1c7e803d
--- /dev/null
+++ b/packages/web/src/features/agents/placeholder-insert-refusal.ts
@@ -0,0 +1,25 @@
+/**
+ * The "insert the placeholder" strip at the head of a prompt section — Memory's own, and one each
+ * for Skills / Vault / Schedules — and the line a refusal leaves under it.
+ *
+ * The strip's button asks the server to write a placeholder into the Agent's prompt template.
+ * Nothing on the page moves until that write lands, so a refused one leaves the template exactly
+ * as it was: the strip stays, its button stays, and that button is the retry. The reason used to
+ * live only in a toast that dismissed itself after six seconds, and six seconds later the strip
+ * looked as though it had never been pressed — the shape 7.19 bans app-wide. It matters more here
+ * than for a bare settings write: this is the adoption path for the whole feature (memory never
+ * entering the context, no skills or vault section, no schedules section).
+ *
+ * The sentence names the placeholder token, because four sections share the one sentence and
+ * "the placeholder" alone would not say which. The verb follows the button that was pressed: a
+ * legacy template's button migrates the old hardcoded section instead of inserting, and saying
+ * "insert" there would describe a request nobody made.
+ */
+import { S } from "../../lib/strings";
+
+/** The line a refused placeholder write leaves under the strip: which placeholder, the verb its button carried, and the server's reason as it gave it. */
+export function placeholderInsertRefused(token: string, legacy: boolean, reason: string): string {
+ return legacy
+ ? S.agent.placeholderMigrateRefused(token, reason)
+ : S.agent.placeholderInsertRefused(token, reason);
+}
diff --git a/packages/web/src/features/agents/prompt-injection-controls.tsx b/packages/web/src/features/agents/prompt-injection-controls.tsx
index 2509117a..84ebaf98 100644
--- a/packages/web/src/features/agents/prompt-injection-controls.tsx
+++ b/packages/web/src/features/agents/prompt-injection-controls.tsx
@@ -44,6 +44,7 @@ import { apiErrorText, refusalText } from "../../lib/api-error";
import { toneInk } from "../../lib/tone";
import { useProject } from "../../state/project";
import { featureSwitchRefused } from "./feature-switch-refusal";
+import { placeholderInsertRefused } from "./placeholder-insert-refusal";
import { useSaveConfirm } from "./save-confirm";
export type PromptInjectionFeature = "skills" | "vault" | "schedules" | "hooks";
@@ -64,6 +65,8 @@ interface PromptInjectionStrings extends ToggleStrings {
templateMissing: string;
legacyTemplate?: string;
insertPlaceholder: string;
+ /** What a refused insert names (placeholder-insert-refusal.ts): the token this section's strip and button carry. */
+ placeholderToken: string;
migrate?: string;
promptSection: string;
promptSectionHint: string;
@@ -133,6 +136,9 @@ export function usePromptInjection({
// 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);
+ // The server's words for a refused placeholder write, drawn under the alert strip: the template
+ // still has no placeholder, so the strip and its button stay and that button is the retry.
+ const [insertRefusal, setInsertRefusal] = useState<string | null>(null);
const promptRef = useRef<HTMLTextAreaElement>(null);
const { requestSave, element: saveConfirm } = useSaveConfirm();
@@ -192,8 +198,10 @@ export function usePromptInjection({
: feature === "schedules"
? api.insertSchedulesPlaceholder
: null;
- // Only the alert strip calls this, and a switch-only feature has no alert strip.
- if (insert === null) return;
+ // Only the alert strip calls this, and a switch-only feature has neither a strip nor prompt
+ // strings (the token the refusal names comes from them).
+ if (insert === null || promptStrings === null) return;
+ setInsertRefusal(null);
try {
const dto = await insert(projectId, agentId);
setState(dto);
@@ -201,6 +209,15 @@ export function usePromptInjection({
toastSuccess(S.agent.savedTakesEffect);
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.
+ setInsertRefusal(
+ placeholderInsertRefused(
+ promptStrings.placeholderToken,
+ state?.legacySectionPresent === true,
+ refusalText(e),
+ ),
+ );
toastError(apiErrorText(e));
}
};
@@ -244,24 +261,33 @@ export function usePromptInjection({
// features that can report legacySectionPresent); everything else gets the plain insert.
const legacy = state?.legacySectionPresent === true;
const alertStrip = promptStrings !== null && state !== null && !state.templateHasPlaceholder && (
- <Notice
- tone="attention"
- variant="callout"
- action={
- canEdit
- ? {
- label: legacy
- ? (promptStrings.migrate ?? promptStrings.insertPlaceholder)
- : promptStrings.insertPlaceholder,
- onClick: () => void insertPlaceholder(),
- }
- : undefined
- }
- >
- {legacy
- ? (promptStrings.legacyTemplate ?? promptStrings.templateMissing)
- : promptStrings.templateMissing}
- </Notice>
+ <>
+ <Notice
+ tone="attention"
+ variant="callout"
+ action={
+ canEdit
+ ? {
+ label: legacy
+ ? (promptStrings.migrate ?? promptStrings.insertPlaceholder)
+ : promptStrings.insertPlaceholder,
+ onClick: () => void insertPlaceholder(),
+ }
+ : undefined
+ }
+ >
+ {legacy
+ ? (promptStrings.legacyTemplate ?? promptStrings.templateMissing)
+ : promptStrings.templateMissing}
+ </Notice>
+ {/* A refused write leaves this strip — and with it the button that was pressed — in place,
+ so the reason can sit directly under it; that button is the retry. */}
+ {insertRefusal !== null && (
+ <p role="alert" className={`text-xs break-words ${toneInk.danger}`}>
+ {insertRefusal}
+ </p>
+ )}
+ </>
);
const promptSection = promptStrings !== null && state !== null && (
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index 7bd92ad3..e0789c1a 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -1621,6 +1621,16 @@ export const en: Strings = {
`Turning the ${noun} switch on was refused: ${reason}`,
switchOffRefused: (noun: string, reason: string): string =>
`Turning the ${noun} switch off was refused: ${reason}`,
+ /**
+ * A placeholder the server refused to write into the prompt template
+ * (placeholder-insert-refusal.ts), drawn under the strip that asked: which placeholder and the
+ * reason, as the server gave it. The second verb is for a legacy template, whose button
+ * migrates the old hardcoded section instead of inserting.
+ */
+ placeholderInsertRefused: (token: string, reason: string): string =>
+ `Inserting the ${token} placeholder was refused: ${reason}`,
+ placeholderMigrateRefused: (token: string, reason: string): string =>
+ `Migrating to the ${token} placeholder was refused: ${reason}`,
takesEffectSuffix:
" — new conversations pick it up right away, running ones after their next compaction",
listTitle: "Agents",
@@ -2394,6 +2404,8 @@ export const en: Strings = {
templateMissing:
"The prompt template has no {{MEMORY}} placeholder, so memory never enters the context.",
insertPlaceholder: "Insert the {{MEMORY}} placeholder",
+ /** What a refused insert names (placeholder-insert-refusal.ts): the token its button also carries. */
+ placeholderToken: "{{MEMORY}}",
insertPlaceholderDone: "Inserted",
promptSection: "Memory prompt",
promptSectionHint:
@@ -2567,6 +2579,8 @@ export const en: Strings = {
legacyTemplate:
"The template still carries the legacy hardcoded # Vault section: one-click migration replaces it in place with the {{VAULT}} placeholder, wording unchanged, after which it is editable below.",
insertPlaceholder: "Insert the {{VAULT}} placeholder",
+ /** What a refused insert names (placeholder-insert-refusal.ts): the token its button also carries. */
+ placeholderToken: "{{VAULT}}",
migrate: "Migrate to the {{VAULT}} placeholder",
promptSection: "Vault prompt",
promptSectionHint:
@@ -2750,6 +2764,8 @@ export const en: Strings = {
templateMissing:
"The prompt template has no {{SCHEDULES}} placeholder, so the scheduled-tasks section never enters the context.",
insertPlaceholder: "Insert the {{SCHEDULES}} placeholder",
+ /** What a refused insert names (placeholder-insert-refusal.ts): the token its button also carries. */
+ placeholderToken: "{{SCHEDULES}}",
promptSection: "Schedules prompt",
promptSectionHint:
"What the template's {{SCHEDULES}} placeholder expands to — teaches the model to manage scheduled tasks with its file tools; nothing is injected when the toggle is off or the template lacks the placeholder.",
@@ -3156,6 +3172,8 @@ export const en: Strings = {
legacyTemplate:
"The template still carries the legacy hardcoded # Skills section: one-click migration replaces it in place with the {{SKILLS}} placeholder, wording unchanged, after which it is editable below.",
insertPlaceholder: "Insert the {{SKILLS}} placeholder",
+ /** What a refused insert names (placeholder-insert-refusal.ts): the token its button also carries. */
+ placeholderToken: "{{SKILLS}}",
migrate: "Migrate to the {{SKILLS}} placeholder",
promptSection: "Skills prompt",
promptSectionHint:
diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.ts
index 9793ab52..121a06b3 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -1665,6 +1665,16 @@ export const zh = {
*/
switchOnRefused: (noun: string, reason: string): string => `开启${noun}的开关被拒:${reason}`,
switchOffRefused: (noun: string, reason: string): string => `关闭${noun}的开关被拒:${reason}`,
+ /**
+ * A placeholder the server refused to write into the prompt template
+ * (placeholder-insert-refusal.ts), drawn under the strip that asked: which placeholder — four
+ * sections share this sentence — and the reason, as the server gave it. The second verb is for
+ * a legacy template, whose button migrates the old hardcoded section instead of inserting.
+ */
+ placeholderInsertRefused: (token: string, reason: string): string =>
+ `插入 ${token} 占位符被拒:${reason}`,
+ placeholderMigrateRefused: (token: string, reason: string): string =>
+ `迁移为 ${token} 占位符被拒:${reason}`,
/** Appended to an action's own toast (skill install / uninstall) — same timing statement. */
takesEffectSuffix: ";新对话立即生效,进行中的对话在下一次压缩后生效",
listTitle: "Agents",
@@ -2454,6 +2464,8 @@ export const zh = {
userScope: "用户记忆",
templateMissing: "提示词模板中没有 {{MEMORY}} 占位符,记忆不会进入上下文。",
insertPlaceholder: "插入 {{MEMORY}} 占位符",
+ /** What a refused insert names (placeholder-insert-refusal.ts): the token its button also carries. */
+ placeholderToken: "{{MEMORY}}",
insertPlaceholderDone: "已插入",
promptSection: "记忆提示词",
promptSectionHint:
@@ -2628,6 +2640,8 @@ export const zh = {
legacyTemplate:
"模板仍是旧版硬编码的 # Vault 段落:一键迁移会将该段落原位替换为 {{VAULT}} 占位符,措辞不变,此后可在下方编辑。",
insertPlaceholder: "插入 {{VAULT}} 占位符",
+ /** What a refused insert names (placeholder-insert-refusal.ts): the token its button also carries. */
+ placeholderToken: "{{VAULT}}",
migrate: "迁移为 {{VAULT}} 占位符",
promptSection: "保险柜提示词",
promptSectionHint: "注入模板 {{VAULT}} 占位符的内容;开关关闭或模板无占位符时不注入。",
@@ -2800,6 +2814,8 @@ export const zh = {
switchNoun: "定时任务",
templateMissing: "提示词模板中没有 {{SCHEDULES}} 占位符,定时任务小节不会进入上下文。",
insertPlaceholder: "插入 {{SCHEDULES}} 占位符",
+ /** What a refused insert names (placeholder-insert-refusal.ts): the token its button also carries. */
+ placeholderToken: "{{SCHEDULES}}",
promptSection: "定时任务提示词",
promptSectionHint:
"注入模板 {{SCHEDULES}} 占位符的内容,教模型用文件工具管理定时任务;开关关闭或模板无占位符时不注入。",
@@ -3196,6 +3212,8 @@ export const zh = {
legacyTemplate:
"模板仍是旧版硬编码的 # Skills 段落:一键迁移会将该段落原位替换为 {{SKILLS}} 占位符,措辞不变,此后可在下方编辑。",
insertPlaceholder: "插入 {{SKILLS}} 占位符",
+ /** What a refused insert names (placeholder-insert-refusal.ts): the token its button also carries. */
+ placeholderToken: "{{SKILLS}}",
migrate: "迁移为 {{SKILLS}} 占位符",
promptSection: "技能提示词",
promptSectionHint: "注入模板 {{SKILLS}} 占位符的内容;开关关闭或模板无占位符时不注入。",
diff --git a/packages/web/test/placeholder-insert-refusal.test.ts b/packages/web/test/placeholder-insert-refusal.test.ts
new file mode 100644
index 00000000..7f18ca73
--- /dev/null
+++ b/packages/web/test/placeholder-insert-refusal.test.ts
@@ -0,0 +1,68 @@
+/**
+ * How a refused placeholder write is worded (`placeholderInsertRefused`): the strip at the head of
+ * Memory, Skills, Vault and Schedules — four sections behind one sentence.
+ *
+ * Nothing on the page moves until the write lands, so a refused one leaves the strip and the
+ * button that asked exactly where they were; a toast used to be the only account of it, and six
+ * seconds later the strip looked as though it had never been pressed.
+ *
+ * - The sentence names the placeholder token, because four sections share it and "the placeholder"
+ * alone would not say which one.
+ * - A legacy template's button migrates instead of inserting, so the verb follows the button.
+ * - 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 { placeholderInsertRefused } from "../src/features/agents/placeholder-insert-refusal";
+
+afterEach(() => {
+ setActiveStrings(ZH);
+});
+
+describe("placeholderInsertRefused", () => {
+ it("names the placeholder and carries the server's reason verbatim", () => {
+ expect(placeholderInsertRefused("{{MEMORY}}", false, "Internal server error")).toBe(
+ "插入 {{MEMORY}} 占位符被拒:Internal server error",
+ );
+ });
+
+ it("uses the migrate verb when the button migrates a legacy section instead", () => {
+ // The Vault and Skills strips switch their own button's wording on a legacy template; saying
+ // "insert" about a migration would describe a request nobody made.
+ expect(placeholderInsertRefused("{{VAULT}}", true, "Internal server error")).toBe(
+ "迁移为 {{VAULT}} 占位符被拒:Internal server error",
+ );
+ });
+
+ it("names each section's own token, so the line says which placeholder", () => {
+ expect(placeholderInsertRefused(S.memory.placeholderToken, false, "nope")).toBe(
+ "插入 {{MEMORY}} 占位符被拒:nope",
+ );
+ expect(placeholderInsertRefused(S.skills.injection.placeholderToken, false, "nope")).toBe(
+ "插入 {{SKILLS}} 占位符被拒:nope",
+ );
+ expect(placeholderInsertRefused(S.vault.injection.placeholderToken, true, "nope")).toBe(
+ "迁移为 {{VAULT}} 占位符被拒:nope",
+ );
+ expect(placeholderInsertRefused(S.schedule.injection.placeholderToken, false, "nope")).toBe(
+ "插入 {{SCHEDULES}} 占位符被拒:nope",
+ );
+ });
+
+ it("keeps the reason's own punctuation", () => {
+ expect(placeholderInsertRefused("{{SKILLS}}", false, "服务器内部错误,请稍后重试。")).toBe(
+ "插入 {{SKILLS}} 占位符被拒:服务器内部错误,请稍后重试。",
+ );
+ });
+
+ it("follows the interface language, both verbs", () => {
+ setActiveStrings(EN);
+ expect(placeholderInsertRefused("{{MEMORY}}", false, "nope")).toBe(
+ "Inserting the {{MEMORY}} placeholder was refused: nope",
+ );
+ expect(placeholderInsertRefused("{{SKILLS}}", true, "nope")).toBe(
+ "Migrating to the {{SKILLS}} placeholder was refused: nope",
+ );
+ });
+});