Skip to content

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

fix(web): a refused memory export keeps its reason in the group

lmlihenga5fa642634ab
diff --git a/changelog/unreleased/2026-11-11-memory-export-refusal.md b/changelog/unreleased/2026-11-11-memory-export-refusal.md
new file mode 100644
index 00000000..11f7693b
--- /dev/null
+++ b/changelog/unreleased/2026-11-11-memory-export-refusal.md
@@ -0,0 +1,62 @@
+# A memory group that was not exported keeps its reason in the group
+
+- **Date:** 2026-11-11
+- **Type:** fix
+- **Scope:** `web` (one slot added in `ui`)
+- **Breaking:** no
+
+[中文版](2026-11-11-memory-export-refusal.zh.md)
+
+Every group on the Memory tab carries "Export" on its head strip: it fetches that group's transfer
+document and hands it to the browser through an object URL. When the server refused the download,
+the group was still there, every memory in it was still there, and the button that asked was still
+under the pointer — while the only thing saying why was a notification that dismissed itself after
+six seconds, floating above the list while the reader was looking at one group below it.
+
+That is the shape 7.19 forbids, and the same one the Skills tab (7.101), the Hooks tab (7.103) and
+the plugin card (7.107) each already fixed: the Memory tab was the last one still answering with a
+toast. The reason is now drawn in the group that asked (`role="alert"`, danger ink, at most two
+lines, the whole sentence on hover) and stays until the next attempt; pressing "Export" again is the
+retry. The sentence says the export only reads and no memory was changed — an export really is a
+read, and a failed one is the moment a reader wonders whether the attempt went through the files.
+
+This host has a wrinkle the others do not: the export button sits on a **collapsible section's** head
+strip, and the body it folds away is where the rows live. So `CollapsibleSection` in `ui` gained a
+`notice` slot — between the head strip and the fold, inside the card and outside the folded part:
+with the group folded, the head strip is all of it that shows, and the sentence has to stay with it.
+
+## Details
+
+- `packages/ui/src/components/layout/collapsible-section/collapsible-section.tsx`: a `notice` slot
+ after the head strip and before the fold (`border-line-muted` separator). Omit it and the card
+ reads exactly as before; existing callers are untouched.
+- New `packages/web/src/features/agents/memory-export-refusal.ts`: `memoryExportRefused(scope,
+ error)` builds the sentence (`refusalText`, the rule every refusal in the app follows), and
+ `memoryExportRefusalFor(refusal, scopeKey)` decides which group draws it — by **key**, not title:
+ two Workspaces' folders can share a last segment, and the key is the group the attempt asked.
+- `packages/web/src/features/agents/memory-tab.tsx`: `exportScope` records a failure in
+ `exportRefusal` for its group's `notice` instead of calling `toastError`, and clears the previous
+ sentence when an attempt starts. `scopeTitle` moved to module level: the refusal is built at the
+ moment of failure, on a render path that may have returned early.
+- `packages/web/src/lib/strings{,-en}.ts`: one new `memory.exportRefused(scope, reason)`.
+
+## Tests
+
+- `packages/ui/test/collapsible-section.test.ts`: the notice sits after the head strip and before the
+ body (folded too), and without the prop the slot does not exist at all.
+- `packages/web/test/memory-export-refusal.test.ts` (new, 9 cases): a server answer is read through
+ its code's own sentence (never the wire message), a value raised in the interface keeps its words,
+ nothing said falls back to the generic text, the group is named, the sentence says the export only
+ read, the English copy, and three cases for "only the group that asked, by key and not by title".
+- `packages/web/e2e/memory-export-refusal.spec.mjs` (new, 2 cases, real server + real browser): a
+ refused export leaves one sentence in that group, verbatim, with no toast, still there seven
+ seconds later and still readable once the group is folded; after the download is allowed, the same
+ button makes the sentence go and the browser really receives the document, with the server's
+ memories exactly as they were.
+
+## Compatibility
+
+No interface change on the wire, no new dependency, no Project config change. Existing
+`CollapsibleSection` callers (model library, plugin library, gallery) are unchanged, and the Memory
+tab's other actions — view / edit / add through a chat, the delete and import confirmations with
+their own refusals, the two prompt fields and their placeholders — are not touched.
diff --git a/changelog/unreleased/2026-11-11-memory-export-refusal.zh.md b/changelog/unreleased/2026-11-11-memory-export-refusal.zh.md
new file mode 100644
index 00000000..bf307c6f
--- /dev/null
+++ b/changelog/unreleased/2026-11-11-memory-export-refusal.zh.md
@@ -0,0 +1,49 @@
+# 记忆组没有导出成时,原因留在那一组里
+
+- **日期:** 2026-11-11
+- **类型:** 修复
+- **范围:** `web`(`ui` 的折叠段多一个槽)
+- **破坏性变更:** 否
+
+[English](2026-11-11-memory-export-refusal.md)
+
+记忆页每一组的标题条上都有「导出」:拉一次那组记忆的传输文档,再用一个临时的对象地址交给浏览器。服务端拒了这次
+下载时,那一组还在、组里每一条记忆都还在、连按下去的那颗按钮都还在原地,可唯一解释原因的那句话是一条六秒后
+自己消失的通知 —— 它浮在列表上方,而读者的视线落在下面某一组上。
+
+这正是 7.19 禁止的形状,也是技能页(7.101)、钩子页(7.103)与插件卡片(7.107)各自已经改过一次的同一件事,只剩
+记忆页这一处还在弹通知。原因现在画在发问的那一组里(`role="alert"`、危险色、最多两行、整句挂悬停),留到下一次
+尝试开始为止;再按一次那颗「导出」就是重试。句子说「导出只是读取,记忆一条都没有被改动」—— 导出确实只读,而
+这正是读者会怀疑「是不是动到文件了」的那一刻。
+
+这一处的宿主有个别处没有的麻烦:导出按钮在**折叠段**的标题条上,而正文是会被折起来的。所以折叠段(`ui` 的
+`CollapsibleSection`)多了一个 `notice` 槽:它画在标题条与正文之间、卡片之内、折起来的那部分之外 —— 组是折着的
+时候,标题条就是这一组仅有的可见部分,句子必须跟着它留下。
+
+## 细节
+
+- `packages/ui/src/components/layout/collapsible-section/collapsible-section.tsx`:新增 `notice` 槽(head 之后、
+ fold 之前,`border-line-muted` 分隔)。不传就是空的,既有用法一个字节没变。
+- 新增 `packages/web/src/features/agents/memory-export-refusal.ts`:`memoryExportRefused(scope, error)` 造句
+ (原因走 `refusalText`,与全应用每一个拒绝同一个规则);`memoryExportRefusalFor(refusal, scopeKey)` 决定这句
+ 归哪一组 —— 按**键**认领而不是标题,两个工作区的目录可能叫同一个名字,而键才是这次尝试真正发问的那一组。
+- `packages/web/src/features/agents/memory-tab.tsx`:`exportScope` 失败不再 `toastError`,记进 `exportRefusal`
+ 交给那一组的 `notice`;每次尝试开始先清上一句。`scopeTitle` 从组件内提到模块级:拒绝句要在失败的那一刻造句,
+ 而那条路径可能在组件提前返回之后。
+- `packages/web/src/lib/strings{,-en}.ts`:新增一句 `memory.exportRefused(scope, reason)`。
+
+## 测试
+
+- `packages/ui/test/collapsible-section.test.ts`:`notice` 在 head 之后、body 之前(折着也在),不传就根本没有
+ 这一段。
+- `packages/web/test/memory-export-refusal.test.ts`(新增,9 条):服务端的原因按错误码念(绝不念线上原文)、
+ 界面自己抛出的句子原样保留、什么都没说时落到通用文案、念出组名、点明导出只是读取没有改动记忆、英文那一句、
+ 以及「只归发问的那一组、按键而不是按标题」三条。
+- `packages/web/e2e/memory-export-refusal.spec.mjs`(新增,2 条,真服务端 + 真浏览器):被拒时句子只在那一组里、
+ 逐字、通知区 0 条、七秒后仍在、折起来之后仍然可见;放行后按同一颗按钮,句子消失、浏览器真拿到那份文档,服务端
+ 那份记忆与开始时逐项相同。
+
+## 兼容性
+
+线上接口没变、没有新依赖、Project 配置没变。折叠段的既有用法(模型库、插件库、画廊)原样不变;记忆页其它动作
+—— 查看 / 编辑 / 添加走对话、删除与导入的确认框及其拒绝行、提示词的两段与占位符 —— 一个字节没动。
diff --git a/packages/ui/src/components/layout/collapsible-section/collapsible-section.tsx b/packages/ui/src/components/layout/collapsible-section/collapsible-section.tsx
index 9e8448f4..f7a6bada 100644
--- a/packages/ui/src/components/layout/collapsible-section/collapsible-section.tsx
+++ b/packages/ui/src/components/layout/collapsible-section/collapsible-section.tsx
@@ -17,6 +17,10 @@
* One long line would make the column wider than the card: every row in the section would run past
* its edge, and the card would clip each row's actions.
*
+ * The `notice` slot sits between the head strip and the fold, inside the card and outside the
+ * folded body — a line the section itself has to show (a refusal of what its head offered) stays
+ * readable while the body is folded, which is exactly when the head's buttons are all that shows.
+ *
* Open or folded is the caller's when it passes `open` (a page that remembers it), the section's
* own otherwise, starting from `defaultOpen`.
*/
@@ -33,6 +37,8 @@ export interface CollapsibleSectionProps {
meta?: ReactNode;
/** The section's own controls, after the toggle. */
actions?: ReactNode;
+ /** A line the section has to show, between the head strip and the body: visible while folded. */
+ notice?: ReactNode;
/** Whether the body shows, when the caller keeps it. */
open?: boolean;
/** Where an uncontrolled section starts. */
@@ -48,6 +54,7 @@ export function CollapsibleSection({
leading,
meta,
actions,
+ notice,
open: openProp,
defaultOpen = true,
onOpenChange,
@@ -82,6 +89,11 @@ export function CollapsibleSection({
</button>
{actions !== undefined && <div className="flex shrink-0 items-center gap-1">{actions}</div>}
</div>
+ {notice !== undefined && (
+ <div data-slot="notice" className="border-t border-line-muted px-3 py-2">
+ {notice}
+ </div>
+ )}
<div
data-slot="body"
data-layout-motion
diff --git a/packages/ui/test/collapsible-section.test.ts b/packages/ui/test/collapsible-section.test.ts
index a721e24d..34ab2990 100644
--- a/packages/ui/test/collapsible-section.test.ts
+++ b/packages/ui/test/collapsible-section.test.ts
@@ -49,4 +49,20 @@ describe("CollapsibleSection", () => {
it("follows the caller's open over its own default", () => {
expect(render({ open: false, defaultOpen: true })).toContain('aria-expanded="false"');
});
+
+ it("draws a notice inside the card and outside the fold, so folding keeps it readable", () => {
+ const notice = createElement("p", { role: "alert" }, "not exported");
+ for (const html of [render({ notice }), render({ notice, defaultOpen: false })]) {
+ const head = html.indexOf('data-slot="head"');
+ const slot = html.indexOf('data-slot="notice"');
+ const body = html.indexOf('data-slot="body"');
+ expect(head).toBeGreaterThan(-1);
+ // After the head strip (the buttons that asked), before the body it does not fold with.
+ expect(head).toBeLessThan(slot);
+ expect(slot).toBeLessThan(body);
+ expect(html).toContain('<p role="alert">not exported</p>');
+ }
+ // No slot, no empty strip: the card reads exactly as it did before the prop existed.
+ expect(render({})).not.toContain('data-slot="notice"');
+ });
});
diff --git a/packages/web/e2e/memory-export-refusal.spec.mjs b/packages/web/e2e/memory-export-refusal.spec.mjs
new file mode 100644
index 00000000..3960520d
--- /dev/null
+++ b/packages/web/e2e/memory-export-refusal.spec.mjs
@@ -0,0 +1,192 @@
+/**
+ * Regression: a memory group's "Export" that the download refused leaves its reason inside the
+ * group that asked, instead of only in a notification that dismisses itself after six seconds.
+ *
+ * The export is a plain fetch of one scope's transfer document: nothing is written on the server,
+ * no memory moves and no client state changes, so a refusal leaves the group, its export button and
+ * every memory on screen. That is exactly where the reason belongs (7.19's rule) — before this,
+ * `exportScope` answered with `toastError`, and a reader who looked away had no file and nothing
+ * saying why. The Skills (7.101), Hooks (7.103) and plugin card (7.107) twins are the same family;
+ * this one hangs off a folded section, so its reason sits in `CollapsibleSection`'s `notice` slot —
+ * inside the card, under the head strip, and visible while the group is folded.
+ *
+ * The memory is seeded through the export document the import route accepts (the tab has no "new
+ * file" form by design: a memory's text is the model's document). The refused download is the
+ * page's own request as seen by `page.route`; both halves are the page's contract with the server.
+ */
+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";
+const FILE = "probe-export-memory.md";
+const TITLE = "Probe export memory";
+const SCOPE = "用户记忆";
+
+/** The refused download: its code's own localized sentence is what the group has to draw. */
+const REFUSAL = { code: "internal", message: "the scope could not be read" };
+/** S.errors.byCode.internal — the copy that code stands for in a zh-CN interface. */
+const REASON = "服务器内部错误,请稍后重试。";
+
+/** One memory document as the export route writes it (the import route's own shape). */
+function documentFor(content) {
+ return {
+ format: "penguin-memory-scope",
+ version: 1,
+ scopeKey: "user",
+ kind: "user",
+ exportedAt: new Date().toISOString(),
+ index: `- [${TITLE}](${FILE}) — seeded by the e2e run\n`,
+ files: [
+ {
+ name: FILE,
+ content: `---\nname: ${TITLE}\ndescription: A memory the export refusal test reads.\n---\n\n${content}\n`,
+ },
+ ],
+ };
+}
+
+/**
+ * Provision the user, give the Project a model (the onboarding overlay covers the page without
+ * one), and seed one user-scope memory so the group has something to export. Rerunning this file
+ * shares one data root with earlier runs, so the seed overwrites what a previous run left.
+ */
+async function projectWithMemory(page, user, content) {
+ 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 scopeBase = `${BASE}/api/projects/${projectId}/agents/${AGENT}/memory/scopes/user`;
+ const seeded = await page.request.post(`${scopeBase}/import`, {
+ data: { mode: "overwrite", confirm: true, payload: documentFor(content) },
+ });
+ expect(seeded.ok(), "seed the memory").toBeTruthy();
+
+ /** The scope's topic files as the server holds them: what the page reads. */
+ const files = async () => (await (await page.request.get(`${scopeBase}/files`)).json()).files;
+
+ return { projectId, files };
+}
+
+/** The user group's head strip export button (accessible name: the verb plus the group's title). */
+const exportButton = (page) => page.getByRole("button", { name: `导出${SCOPE}`, exact: true });
+
+/** The group's card: the export button's head strip, then the section itself. */
+const groupCard = (page) => exportButton(page).locator("xpath=../../..");
+
+/** The reason line inside that card. */
+const refusalLine = (page) => page.getByTestId("export-refusal");
+
+/** The notification region: a refusal must not be announced there (that is the old toast). */
+const notifications = (page) => page.getByRole("region", { name: "通知" });
+
+/** Take over the scope export: every GET is kept in `seen`, and while `state.refuse` is set it is
+ * answered with the server's refusal instead of reaching the real route. */
+async function interceptExport(page, state) {
+ await page.route("**/api/projects/*/agents/*/memory/scopes/*/export", async (route) => {
+ state.seen.push(new URL(route.request().url()).pathname);
+ if (!state.refuse) return route.fallback();
+ await route.fulfill({
+ status: 500,
+ contentType: "application/json",
+ body: JSON.stringify({ error: REFUSAL }),
+ });
+ });
+}
+
+test("a refused export keeps its reason in the group, folded or not, and nothing else changes", async ({
+ page,
+}) => {
+ const { files } = await projectWithMemory(page, "r222memexportrefuse", "What the scope held.");
+ const before = await files();
+
+ const state = { seen: [], refuse: true };
+ await interceptExport(page, state);
+
+ await page.goto(`/agents/${AGENT}?tab=memory`);
+ await expect(page.getByText(TITLE, { exact: true })).toBeVisible();
+ await expect(refusalLine(page)).toHaveCount(0);
+ const headLine = await groupCard(page).locator('[data-slot="head"]').innerText();
+
+ await exportButton(page).click();
+
+ // The reason is in the group that asked, and it is not a toast: the notification region holds no
+ // dismissible button, and the head strip reads exactly as it did before the attempt.
+ await expect(refusalLine(page)).toHaveCount(1);
+ await expect(refusalLine(page)).toHaveText(
+ `记忆组「${SCOPE}」没有导出成文档,导出只是读取,记忆一条都没有被改动:${REASON}`,
+ );
+ await expect(groupCard(page).getByTestId("export-refusal")).toHaveCount(1);
+ expect(await groupCard(page).locator('[data-slot="head"]').innerText()).toBe(headLine);
+ await expect(notifications(page).getByRole("button")).toHaveCount(0);
+ expect(state.seen).toHaveLength(1);
+ expect(state.seen[0]).toMatch(/\/memory\/scopes\/user\/export$/);
+
+ // One group, one sentence: no other card grew one.
+ await expect(page.getByTestId("export-refusal")).toHaveCount(1);
+
+ // Six seconds is where the old toast gave up; the sentence is still there.
+ await page.waitForTimeout(7000);
+ await expect(refusalLine(page)).toHaveCount(1);
+
+ // Folded, the head strip is all that shows — and the reason stays readable rather than folding
+ // into an `inert`, zero-height body with the rows it is about.
+ await groupCard(page).getByRole("button", { expanded: true }).first().click();
+ await expect(groupCard(page).getByRole("button", { expanded: false }).first()).toBeVisible();
+ await expect(groupCard(page).locator('[data-slot="body"]')).toHaveClass(/grid-rows-\[0fr\]/);
+ await expect(refusalLine(page)).toBeVisible();
+
+ // Nothing was exported and nothing was touched: the memory is still there, on both sides.
+ expect(await files()).toEqual(before);
+});
+
+test("the retry after a refused export lands, and only a new attempt clears the reason", async ({
+ page,
+}) => {
+ const { files } = await projectWithMemory(
+ page,
+ "r222memexportretry",
+ "Kept until it is exported.",
+ );
+ const before = await files();
+
+ const state = { seen: [], refuse: true };
+ await interceptExport(page, state);
+
+ await page.goto(`/agents/${AGENT}?tab=memory`);
+ await expect(page.getByText(TITLE, { exact: true })).toBeVisible();
+ await exportButton(page).click();
+ await expect(refusalLine(page)).toHaveCount(1);
+ expect(state.seen).toHaveLength(1);
+
+ // The retry is the same button; this time the document really comes back: the sentence goes, and
+ // the file is handed to the browser as a download.
+ state.refuse = false;
+ const download = page.waitForEvent("download");
+ await exportButton(page).click();
+ await expect(refusalLine(page)).toHaveCount(0);
+ expect(state.seen).toHaveLength(2);
+ const file = await download;
+ expect(file.suggestedFilename()).toMatch(/^default_agent-user-memory(-\d{8}-\d{4})?\.json$/);
+
+ // A refused export changed neither side: the memory is still listed and still on disk.
+ await expect(page.getByText(TITLE, { exact: true })).toBeVisible();
+ expect(await files()).toEqual(before);
+});
diff --git a/packages/web/src/api/endpoints.ts b/packages/web/src/api/endpoints.ts
index 840c6380..5c10a25d 100644
--- a/packages/web/src/api/endpoints.ts
+++ b/packages/web/src/api/endpoints.ts
@@ -793,9 +793,9 @@ const memoryScopeBase = (projectId: string, agentId: string, scopeKey: string) =
/**
* One scope as a transfer document. Fetched as ordinary JSON rather than followed as a download
- * link so a failure arrives as an ApiError and reaches the user as a toast — a bare `<a download>`
- * would save the error body as a file (the skills tab hit the same wall). The server still sets
- * Content-Disposition, for anyone opening the URL directly.
+ * link so a failure arrives as an ApiError and is shown in the group that asked — a bare
+ * `<a download>` would save the error body as a file (the skills tab hit the same wall). The server
+ * still sets Content-Disposition, for anyone opening the URL directly.
*/
export const exportMemoryScope = (projectId: string, agentId: string, scopeKey: string) =>
apiFetch<MemoryScopeExport>(`${memoryScopeBase(projectId, agentId, scopeKey)}/export`);
diff --git a/packages/web/src/features/agents/memory-export-refusal.ts b/packages/web/src/features/agents/memory-export-refusal.ts
new file mode 100644
index 00000000..167b1b10
--- /dev/null
+++ b/packages/web/src/features/agents/memory-export-refusal.ts
@@ -0,0 +1,52 @@
+/**
+ * A memory group's "Export" button on the Agent's Memory tab (`memory-tab.tsx`), and the
+ * sentence one refused export leaves behind — the fourth of this family, after the Skills tab's
+ * rows (7.101, `agents/skill-export-refusal.ts`), the Hooks tab's (7.103,
+ * `agents/hook-export-refusal.ts`) and the plugin card's (7.107,
+ * `features/plugins/plugin-export-refusal.ts`).
+ *
+ * The export is a plain fetch of one scope's transfer document through
+ * `/api/projects/:p/agents/:a/memory/scopes/:scope/export`: nothing is written on the server, no
+ * memory moves and no client state changes while the request is out — so when the request is
+ * refused the group that sent it is still on screen, right under the button that retries it. The
+ * reason used to arrive only as a notification: it dismissed itself after six seconds, sat above
+ * the list, and a reader who had looked away was left with no file and nothing saying why (7.19's
+ * rule, app-wide — the sentence belongs where the attempt was made).
+ *
+ * The sentence hangs off the scope's **key**, not its title: a title is a label (two Workspaces
+ * whose folders share a last segment read the same), while the key is what the attempt was about
+ * and what the server's route took.
+ *
+ * Which words: `refusalText`, the rule every refusal in the app follows — an answer the server
+ * gave is read through its code's own localized sentence, and a value this codebase raised itself
+ * is shown as it wrote it. The sentence says the memories were not touched, because a failed
+ * export is the one moment a reader wonders whether the attempt went through the files.
+ */
+import { refusalText } from "../../lib/api-error";
+import { S } from "../../lib/strings";
+
+/** The sentence one refused export left, and the scope it was for. */
+export interface MemoryExportRefusal {
+ readonly scopeKey: string;
+ readonly text: string;
+}
+
+/** The sentence: which group was not exported, and why. */
+export function memoryExportRefused(scope: string, error: unknown): string {
+ return S.memory.exportRefused(scope, refusalText(error));
+}
+
+/**
+ * What this group draws for a refusal, if anything.
+ *
+ * The tab keeps one refusal at a time — an attempt supersedes the reason of the attempt before it
+ * — so a refusal belongs to the group it was made for and no other group may read it. Groups for
+ * other scopes in the same list must stay exactly as they were.
+ */
+export function memoryExportRefusalFor(
+ refusal: MemoryExportRefusal | null,
+ scopeKey: string,
+): string | undefined {
+ if (refusal === null || refusal.scopeKey !== scopeKey) return undefined;
+ return refusal.text;
+}
diff --git a/packages/web/src/features/agents/memory-tab.tsx b/packages/web/src/features/agents/memory-tab.tsx
index 473ead86..3b964724 100644
--- a/packages/web/src/features/agents/memory-tab.tsx
+++ b/packages/web/src/features/agents/memory-tab.tsx
@@ -74,6 +74,8 @@ import { placeholderInsertRefused } from "./placeholder-insert-refusal";
import { useSaveConfirm } from "./save-confirm";
import { useAiBridge } from "../ai-create";
import { buildMemoryAddPrompt, buildMemoryEditPrompt } from "./memory-chat-prompts";
+import { memoryExportRefusalFor, memoryExportRefused } from "./memory-export-refusal";
+import type { MemoryExportRefusal } from "./memory-export-refusal";
import {
MemoryDocumentError,
memoryDocumentFileName,
@@ -132,6 +134,16 @@ interface Selected {
file: MemoryFileInfo;
}
+/**
+ * A group's name in the interface: user memory, or a Workspace's last path segment (its key as a
+ * last resort). Module level because the export refusal names the group it was made for, and that
+ * sentence is built where the attempt fails — during a render that may have returned early.
+ */
+const scopeTitle = (scope: MemoryScopeInfo): string =>
+ scope.kind === "user"
+ ? S.memory.userScope
+ : (scope.workspacePath?.split(/[\\/]/).filter(Boolean).at(-1) ?? scope.scopeKey);
+
export function MemoryTab({
agentId,
onConfigChanged,
@@ -162,6 +174,10 @@ export function MemoryTab({
// 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);
+ // The reason an export that did not land left in the group that asked (memory-export-refusal.ts):
+ // the group's head strip, its export button and every memory are still there, so a notification
+ // that dismisses itself after six seconds is the one thing that would carry that reason away.
+ const [exportRefusal, setExportRefusal] = useState<MemoryExportRefusal | null>(null);
const collapseKey = userId && projectId ? collapsedStoreKey(userId, projectId, agentId) : null;
const [collapsed, setCollapsed] = useState<Set<string>>(() => readCollapsedScopes(collapseKey));
const [memoryPrompt, setMemoryPrompt] = useState("");
@@ -412,11 +428,17 @@ export function MemoryTab({
/**
* Downloads one group as a transfer document. Fetched as JSON and saved through an object URL
- * rather than followed as a link, so a failed request becomes a toast instead of an error body
- * saved to disk (the skills tab's export made the same call).
+ * rather than followed as a link, so a failed request stays a value this tab can show instead of
+ * an error body saved to disk (the skills tab's export made the same call).
+ *
+ * A refusal leaves its reason in the group that asked (memory-export-refusal.ts): the group, its
+ * export button and every memory are still on screen, so a six-second notification is the one
+ * thing that would carry the reason away. Starting an attempt clears the previous sentence — it
+ * belonged to the attempt before, not to the group this one is about.
*/
const exportScope = async (scope: MemoryScopeInfo) => {
if (!projectId) return;
+ setExportRefusal(null);
try {
const doc = await api.exportMemoryScope(projectId, agentId, scope.scopeKey);
const url = URL.createObjectURL(
@@ -430,7 +452,10 @@ export function MemoryTab({
anchor.remove();
URL.revokeObjectURL(url);
} catch (e) {
- toastError(apiErrorText(e));
+ setExportRefusal({
+ scopeKey: scope.scopeKey,
+ text: memoryExportRefused(scopeTitle(scope), e),
+ });
}
};
@@ -534,11 +559,6 @@ export function MemoryTab({
if (error) return <p className="text-sm text-red-600 dark:text-red-400">{error}</p>;
- const scopeTitle = (scope: MemoryScopeInfo): string =>
- scope.kind === "user"
- ? S.memory.userScope
- : (scope.workspacePath?.split(/[\\/]/).filter(Boolean).at(-1) ?? scope.scopeKey);
-
// Icon-only row actions (the skills tab's affordance: neutral bordered icons, danger
// variant with red text/hover for delete); the tooltip + aria-label carry the wording.
const rowActions = (scope: MemoryScopeInfo, file: MemoryFileInfo) => (
@@ -656,6 +676,7 @@ export function MemoryTab({
<div className={enabled ? "space-y-4" : "space-y-4 opacity-60"}>
{groups.map(({ scope, files }) => {
const open = !collapsed.has(scope.scopeKey);
+ const refusal = memoryExportRefusalFor(exportRefusal, scope.scopeKey);
return (
/* One collapsible section per scope: the head strip folds the group; the group's
own actions sit after the toggle, outside it, since a button cannot hold
@@ -684,6 +705,23 @@ export function MemoryTab({
meta={S.memory.itemCount(files.length)}
open={open}
onOpenChange={() => toggleCollapsed(scope.scopeKey)}
+ notice={
+ /* An export this group offered that did not land: the head strip (and the button
+ that retries it) is on the card whether the group is folded or not, so the
+ reason sits under that strip rather than in a notification that dismisses
+ itself (memory-export-refusal.ts). */
+ refusal !== undefined ? (
+ <p
+ role="alert"
+ data-testid="export-refusal"
+ data-tooltip={refusal}
+ data-tooltip-content="text"
+ className={`line-clamp-2 break-words text-xs ${toneInk.danger}`}
+ >
+ {refusal}
+ </p>
+ ) : undefined
+ }
actions={
/* Whole-group transfer, icon + label (the labels are what say which way a
transfer goes, wherever the row is wide enough to keep them): export for any
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index b0a85ca2..db5e47bf 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -2491,6 +2491,9 @@ export const en: Strings = {
exportScope: "Export",
exportScopeHint: "Download every memory in this group as one JSON document",
exportScopeLabel: (scope: string): string => `Export ${scope}`,
+ /** An export the download refused (memory-export-refusal.ts), drawn in the group that asked. */
+ exportRefused: (scope: string, reason: string): string =>
+ `The memory group "${scope}" was not exported as a document — an export only reads, so no memory was changed: ${reason}`,
importScope: "Import",
importScopeHint: "Restore memories into this group from an exported JSON document",
importScopeLabel: (scope: string): string => `Import into ${scope}`,
diff --git a/packages/web/src/lib/strings.ts b/packages/web/src/lib/strings.ts
index dae2e5d4..43b892b9 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -2545,6 +2545,13 @@ export const zh = {
exportScope: "导出",
exportScopeHint: "将该组全部记忆下载为一份 JSON 文档",
exportScopeLabel: (scope: string): string => `导出${scope}`,
+ /**
+ * An export the download refused (memory-export-refusal.ts), drawn in the group that asked.
+ * Says the export only reads, because that is the one moment a reader wonders whether the
+ * attempt touched the memories; the reason goes last, as in every other refusal sentence.
+ */
+ exportRefused: (scope: string, reason: string): string =>
+ `记忆组「${scope}」没有导出成文档,导出只是读取,记忆一条都没有被改动:${reason}`,
importScope: "导入",
importScopeHint: "从导出的 JSON 文档恢复记忆到该组",
importScopeLabel: (scope: string): string => `导入到${scope}`,
diff --git a/packages/web/test/memory-export-refusal.test.ts b/packages/web/test/memory-export-refusal.test.ts
new file mode 100644
index 00000000..f938dce5
--- /dev/null
+++ b/packages/web/test/memory-export-refusal.test.ts
@@ -0,0 +1,81 @@
+/**
+ * A memory group's export that did not land (src/features/agents/memory-export-refusal.ts): the
+ * sentence that group draws, and the one thing it must not do — speak for another group.
+ *
+ * The export writes nothing on the server and moves no client state, so a refusal leaves the
+ * group, its memories and the same button on screen — the sentence is the only thing saying no
+ * file was saved. Three things it has to get right: an answer the server gave speaks the
+ * interface's own language rather than the wire message (7.19's rule), a failure this codebase
+ * raised itself keeps what it knows, and it names the group it is about.
+ */
+import { afterEach, describe, expect, it } from "vitest";
+import { ApiError } from "../src/api/client";
+import { S, setActiveStrings, zh as ZH } from "../src/lib/strings";
+import { en as EN } from "../src/lib/strings-en";
+import {
+ memoryExportRefusalFor,
+ memoryExportRefused,
+} from "../src/features/agents/memory-export-refusal";
+
+afterEach(() => {
+ setActiveStrings(ZH);
+});
+
+describe("memoryExportRefused", () => {
+ it("reads a refusal through the code's own sentence, not the wire message", () => {
+ const line = memoryExportRefused("用户记忆", new ApiError(500, "internal", "RAW ENGLISH"));
+ expect(line).not.toContain("RAW ENGLISH");
+ expect(line).toBe(S.memory.exportRefused("用户记忆", S.errors.byCode.internal as string));
+ });
+
+ it("keeps what a failure that never reached the route has to say", () => {
+ expect(memoryExportRefused("用户记忆", new Error("Failed to fetch"))).toBe(
+ S.memory.exportRefused("用户记忆", "Failed to fetch"),
+ );
+ });
+
+ it("falls back to the generic text when the value has nothing to say", () => {
+ expect(memoryExportRefused("用户记忆", undefined)).toBe(
+ S.memory.exportRefused("用户记忆", S.common.unknownError),
+ );
+ });
+
+ it("names the group that was not exported", () => {
+ expect(memoryExportRefused("adelie-fork", new Error("boom"))).toContain("adelie-fork");
+ });
+
+ it("says the export only read, so no memory changed", () => {
+ // A failed export is the one moment a reader wonders whether the attempt went through the
+ // files; the sentence answers that without claiming the group still holds what it held.
+ expect(memoryExportRefused("用户记忆", new Error("boom"))).toContain("记忆一条都没有被改动");
+ });
+
+ it("speaks the active language", () => {
+ setActiveStrings(EN);
+ expect(memoryExportRefused("User memory", new ApiError(500, "internal", "RAW"))).toBe(
+ EN.memory.exportRefused("User memory", EN.errors.byCode.internal as string),
+ );
+ expect(memoryExportRefused("User memory", new Error("boom"))).toContain(
+ "no memory was changed",
+ );
+ });
+});
+
+describe("memoryExportRefusalFor", () => {
+ it("draws nothing when no attempt was refused", () => {
+ expect(memoryExportRefusalFor(null, "user")).toBeUndefined();
+ });
+
+ it("draws the reason in the group the attempt was made for, and only there", () => {
+ const refusal = { scopeKey: "user", text: "not exported" };
+ expect(memoryExportRefusalFor(refusal, "user")).toBe("not exported");
+ // Another group's card must read exactly as it did before the attempt.
+ expect(memoryExportRefusalFor(refusal, "/root/adelie-fork")).toBeUndefined();
+ });
+
+ it("claims by key, so two groups whose titles read alike stay apart", () => {
+ // Two Workspaces can end in the same folder name; the sentence belongs to one of them.
+ const refusal = { scopeKey: "ws:/root/a/adelie", text: "not exported" };
+ expect(memoryExportRefusalFor(refusal, "ws:/root/b/adelie")).toBeUndefined();
+ });
+});