Skip to content

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

fix(web): a picked file the import never read keeps its reason in the group

lmliheng04ef36dba2a5
diff --git a/changelog/unreleased/2026-11-11-memory-import-refusal.md b/changelog/unreleased/2026-11-11-memory-import-refusal.md
new file mode 100644
index 00000000..f77927cc
--- /dev/null
+++ b/changelog/unreleased/2026-11-11-memory-import-refusal.md
@@ -0,0 +1,62 @@
+# A memory group keeps the reason a picked file was not imported
+
+- **Date:** 2026-11-11
+- **Type:** fix
+- **Scope:** `web`
+- **Breaking:** no
+
+[中文版](2026-11-11-memory-import-refusal.zh.md)
+
+Each group on the Memory tab carries "Import" on its head strip for the owner: a file input wrapped
+in that strip's label, which reads the picked export document and opens the import dialog. A file
+that is not a memory export never reached that dialog — and the only thing that said why was a
+notification that dismissed itself after six seconds, floating above the list while the reader was
+looking at the group they had just picked the file for. Nothing had happened, no dialog was open,
+and a moment later nothing explained it.
+
+That is the shape 7.19 forbids, and the one thing the Memory tab still answered with a toast after
+its export (7.109) and the Skills (7.101), Hooks (7.103) and plugin card (7.107) refusals moved into
+the surface that asked. The reason is now drawn in that group, in the same slot the export refusal
+uses — `role="alert"`, danger ink, at most two lines, the whole sentence on hover — and stays until
+the next attempt. The group is the host because the file picker **is** this group's own control, so
+the reason sits right under the strip that opened it, and stays readable when the group is folded.
+Picking a real document clears the sentence and opens the dialog as before, so the retry is the same
+control rather than a search for something else.
+
+The sentence says the file was never read and no memory was changed, which is exactly true: the
+parse runs in the page, so not a single request left it.
+
+## Details
+
+- `packages/web/src/features/agents/memory-group-refusal.ts` (was `memory-export-refusal.ts`): one
+ module for both directions of a group's whole-group transfer, since both hang off the same head
+ strip and draw in the same slot. `MemoryGroupRefusal` / `memoryGroupRefusalFor` decide which group
+ claims the sentence (by **key**, not title: two Workspaces' folders can share a last segment), and
+ `memoryImportRefused(scope, error)` words the new one — a document error keeps its own localized
+ message ("this file carries no memories" stays that, rather than collapsing into "not an export"),
+ anything else raised while reading the file falls back to "this file is not a memory export",
+ because a File API failure's message is the browser's own and never localized.
+- `packages/web/src/features/agents/memory-tab.tsx`: one `groupRefusal` state for the group's
+ `notice` slot (a later attempt supersedes the earlier one, whichever direction it went) instead of
+ the export-only one; `pickImport`'s failure writes into it instead of calling `toastError`, and
+ clears it when a pick starts. The slot's test id is now `memory-refusal`.
+- `packages/web/src/lib/strings{,-en}.ts`: one new `memory.importRefused(scope, reason)`.
+
+## Tests
+
+- `packages/web/test/memory-group-refusal.test.ts` (renamed from `memory-export-refusal.test.ts`,
+ now 14 cases): the nine export cases unchanged, plus five for the import sentence — the document's
+ own words are kept, a File API failure becomes "not a memory export" rather than the browser's
+ English, the group is named, the sentence says the file was never read, and the English copy.
+- `packages/web/e2e/memory-group-refusal.spec.mjs` (renamed from `memory-export-refusal.spec.mjs`,
+ now 4 cases, real server + real browser): the two export cases unchanged, plus a picked `.txt`
+ that leaves one sentence verbatim in that group with no dialog open, no notification, no request
+ to any memory route, still there seven seconds later and still readable folded, and goes away —
+ opening the dialog — as soon as a real document is picked; and one case that a group shows a
+ single sentence, the later attempt's, after an export refusal followed by a bad pick.
+
+## Compatibility
+
+No interface change on the wire, no new dependency, no Project config change. The export sentence,
+the group's other actions, and the import dialog's own refusal (a server-refused import, which is
+drawn in the dialog or the confirmation that asked) are unchanged.
diff --git a/changelog/unreleased/2026-11-11-memory-import-refusal.zh.md b/changelog/unreleased/2026-11-11-memory-import-refusal.zh.md
new file mode 100644
index 00000000..27886a0f
--- /dev/null
+++ b/changelog/unreleased/2026-11-11-memory-import-refusal.zh.md
@@ -0,0 +1,48 @@
+# 记忆页选中的文件没有导入成时,原因留在那一组里
+
+- **日期:** 2026-11-11
+- **类型:** 修复
+- **范围:** `web`
+- **破坏性变更:** 否
+
+[English](2026-11-11-memory-import-refusal.md)
+
+记忆页每一组的标题条上,主人还有一颗「导入」:它是包着文件输入的那个标签,读到选中的导出文档就打开导入框。选中的
+文件不是记忆导出文档时,那个框根本不会打开 —— 而唯一解释原因的那句话是一条六秒后自己消失的通知,它浮在列表上方,
+而读者刚才是对着某一组的标题条选的这个文件。什么都没发生、框没开、过了一会儿也没有任何东西再提这件事。
+
+这正是 7.19 禁止的形状,也是记忆页在导出(7.109)、技能页(7.101)、钩子页(7.103)、插件卡片(7.107)各自改过
+之后还剩下的一处通知。原因现在画在那一组里、与导出的拒绝共用同一个槽(`role="alert"`、危险色、最多两行、整句挂
+悬停),留到下一次尝试开始为止。宿主是那一组,是因为**文件选择器就是这一组自己的控件** —— 句子就贴在打开它的那条
+标题条下面,组折起来时也照样看得见。选到真的文档时,句子清掉、导入框照旧打开,所以重试还是同一个控件,不必再去找
+别处。
+
+句子说「这个文件没有读成,记忆一条都没有被改动」,这确实是实情:解析就在页面里做,一个请求都没有发出去。
+
+## 细节
+
+- `packages/web/src/features/agents/memory-group-refusal.ts`(原 `memory-export-refusal.ts`):一组记忆
+ 整组转移的两个方向共用这一个模块 —— 它们挂在同一条标题条上、画进同一个槽。`MemoryGroupRefusal` /
+ `memoryGroupRefusalFor` 决定这句话归哪一组(按**键**而不是按标题:两个工作区的目录可能叫同一个名字);
+ 新增 `memoryImportRefused(scope, error)` —— 文档解析错误保留它自己的本地化句子(「这个文件里没有记忆。」
+ 不会被压成「不是记忆导出文件。」),读文件时别的原因(File API 自己的拒绝,消息是浏览器原话、从不本地化)
+ 则落到「这个文件不是记忆导出文件。」。
+- `packages/web/src/features/agents/memory-tab.tsx`:组的 `notice` 槽改由一个 `groupRefusal` 承载(后一次尝试
+ 盖掉前一次,不分方向),不再是只服务导出的那个;`pickImport` 失败不再 `toastError`,写进它,并在选文件开始时
+ 先清上一句。槽的测试 id 现在是 `memory-refusal`。
+- `packages/web/src/lib/strings{,-en}.ts`:新增一句 `memory.importRefused(scope, reason)`。
+
+## 测试
+
+- `packages/web/test/memory-group-refusal.test.ts`(由 `memory-export-refusal.test.ts` 改名,现有 14 条):导出
+ 那九条原样,另加导入五条 —— 文档自己的话保留、File API 的失败落成「不是记忆导出文件」而不是浏览器原文、念出组名、
+ 点明文件没有读成、英文那一句。
+- `packages/web/e2e/memory-group-refusal.spec.mjs`(由 `memory-export-refusal.spec.mjs` 改名,现有 4 条,真服务端
+ \+ 真浏览器):导出那两条原样;另加一条选中 `.txt` 时那一组里逐字出现这句话、导入框没开、通知区 0 条、**没有任何
+ 发往记忆路由的 POST**、七秒后仍在且折起来也看得见,换成真的文档后句子消失、导入框打开;还有一条:先被拒的导出
+ 紧接一次坏文件,一组只显示后一次的那句话。
+
+## 兼容性
+
+线上接口没变、没有新依赖、Project 配置没变。导出的那句话、组里的其它动作、以及导入框自己的拒绝(服务端拒绝的
+一次导入,画在发问的框或确认框里)都一字未改。
diff --git a/packages/web/e2e/memory-export-refusal.spec.mjs b/packages/web/e2e/memory-group-refusal.spec.mjs
similarity index 58%
rename from packages/web/e2e/memory-export-refusal.spec.mjs
rename to packages/web/e2e/memory-group-refusal.spec.mjs
index 3960520d..acd280ea 100644
--- a/packages/web/e2e/memory-export-refusal.spec.mjs
+++ b/packages/web/e2e/memory-group-refusal.spec.mjs
@@ -1,14 +1,18 @@
/**
- * Regression: a memory group's "Export" that the download refused leaves its reason inside the
+ * Regression: a memory group's whole-group attempt that did not land leaves its reason inside the
* group that asked, instead of only in a notification that dismisses itself after six seconds.
+ * Two directions share that slot — an "Export" the download refused (7.109) and a picked file the
+ * import never got to read (7.110).
*
- * 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.
+ * An 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. A picked file that is not a document stops even earlier — the parse runs
+ * in the page, so not a single request leaves it. Both times the reason belongs where the attempt
+ * was made (7.19's rule); before this, each answered with `toastError`, and a reader who looked away
+ * had either no file or an unopened dialog 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
@@ -91,8 +95,8 @@ const exportButton = (page) => page.getByRole("button", { name: `导出${SCOPE}`
/** 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 reason line inside that card (one slot, whichever direction put the sentence there). */
+const refusalLine = (page) => page.getByTestId("memory-refusal");
/** The notification region: a refusal must not be announced there (that is the old toast). */
const notifications = (page) => page.getByRole("region", { name: "通知" });
@@ -133,14 +137,14 @@ test("a refused export keeps its reason in the group, folded or not, and nothing
await expect(refusalLine(page)).toHaveText(
`记忆组「${SCOPE}」没有导出成文档,导出只是读取,记忆一条都没有被改动:${REASON}`,
);
- await expect(groupCard(page).getByTestId("export-refusal")).toHaveCount(1);
+ await expect(groupCard(page).getByTestId("memory-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);
+ await expect(page.getByTestId("memory-refusal")).toHaveCount(1);
// Six seconds is where the old toast gave up; the sentence is still there.
await page.waitForTimeout(7000);
@@ -190,3 +194,85 @@ test("the retry after a refused export lands, and only a new attempt clears the
await expect(page.getByText(TITLE, { exact: true })).toBeVisible();
expect(await files()).toEqual(before);
});
+
+test("a picked file that is not a memory document keeps its reason in the group that picked it", async ({
+ page,
+}) => {
+ const { files } = await projectWithMemory(page, "r223memimportrefuse", "What the group held.");
+ const before = await files();
+
+ // Watch the whole conversation: this refusal happens before any request, and that is the claim.
+ const requests = [];
+ page.on("request", (r) => requests.push(`${r.method()} ${new URL(r.url()).pathname}`));
+
+ 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();
+ const importModal = page.getByRole("dialog", { name: "导入记忆" });
+ const importInput = groupCard(page).locator('input[type="file"]');
+
+ // The group's own import control takes a file that is not a transfer document: the parse stops
+ // in the page, so the import dialog never opens and the only thing that can say why is this line.
+ await importInput.setInputFiles({
+ name: "notes.txt",
+ mimeType: "text/plain",
+ buffer: Buffer.from("not a memory document at all\n"),
+ });
+
+ await expect(refusalLine(page)).toHaveCount(1);
+ await expect(refusalLine(page)).toHaveText(
+ `记忆组「${SCOPE}」没有导入,这个文件没有读成,记忆一条都没有被改动:这个文件不是记忆导出文件。`,
+ );
+ await expect(groupCard(page).getByTestId("memory-refusal")).toHaveCount(1);
+ await expect(importModal).toHaveCount(0);
+ expect(await groupCard(page).locator('[data-slot="head"]').innerText()).toBe(headLine);
+ await expect(notifications(page).getByRole("button")).toHaveCount(0);
+ // The refusal happened before any request: nothing about this group was written, or even asked.
+ expect(requests.filter((line) => line.startsWith("POST ") && line.includes("/memory/"))).toEqual(
+ [],
+ );
+
+ // One group, one sentence — and folded, the head strip is all that shows while it stays readable.
+ await expect(page.getByTestId("memory-refusal")).toHaveCount(1);
+ await groupCard(page).getByRole("button", { expanded: true }).first().click();
+ await expect(groupCard(page).locator('[data-slot="body"]')).toHaveClass(/grid-rows-\[0fr\]/);
+ await expect(refusalLine(page)).toBeVisible();
+
+ // Six seconds is where the old toast gave up; the sentence is still there.
+ await page.waitForTimeout(7000);
+ await expect(refusalLine(page)).toHaveCount(1);
+
+ // The same control with a real document: the sentence goes and the import dialog opens, so the
+ // retry really is the control that asked rather than a fresh trip to the file picker.
+ await importInput.setInputFiles({
+ name: "user-memory.json",
+ mimeType: "application/json",
+ buffer: Buffer.from(JSON.stringify(documentFor("A real document."))),
+ });
+ await expect(refusalLine(page)).toHaveCount(0);
+ await expect(importModal).toBeVisible();
+
+ // Nothing was written by the refused pick: the group on disk is exactly as it was.
+ expect(await files()).toEqual(before);
+});
+
+test("one group shows one sentence, whichever direction wrote it last", async ({ page }) => {
+ await projectWithMemory(page, "r223memoneslot", "Kept until it is exported.");
+ 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);
+
+ // Then a pick fails for a different reason: the slot carries the later attempt, not both.
+ await groupCard(page)
+ .locator('input[type="file"]')
+ .setInputFiles({ name: "notes.txt", mimeType: "text/plain", buffer: Buffer.from("nope") });
+ await expect(page.getByTestId("memory-refusal")).toHaveCount(1);
+ await expect(refusalLine(page)).toHaveText(
+ `记忆组「${SCOPE}」没有导入,这个文件没有读成,记忆一条都没有被改动:这个文件不是记忆导出文件。`,
+ );
+});
diff --git a/packages/web/src/features/agents/memory-export-refusal.ts b/packages/web/src/features/agents/memory-export-refusal.ts
deleted file mode 100644
index 167b1b10..00000000
--- a/packages/web/src/features/agents/memory-export-refusal.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * 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-group-refusal.ts b/packages/web/src/features/agents/memory-group-refusal.ts
new file mode 100644
index 00000000..d3a68c57
--- /dev/null
+++ b/packages/web/src/features/agents/memory-group-refusal.ts
@@ -0,0 +1,65 @@
+/**
+ * A memory group on the Agent's Memory tab (`memory-tab.tsx`) and the sentence one refused
+ * whole-group attempt leaves behind: a download the server would not serve (7.109), and a picked
+ * file that never became a document (7.110).
+ *
+ * Both hang off the same host, so they live in one module. Each group's head strip carries
+ * "Export" and — for the owner — "Import", and the import control is a file input wrapped in that
+ * strip's label: the file picker **is** this group's control, which is why the reason belongs to
+ * the group rather than to a picker of its own. The card's `notice` slot sits between the head
+ * strip and the fold, so the sentence stays on screen with the control that retries it even when
+ * the group is folded.
+ *
+ * Neither attempt writes anything. An export only reads, and a file that fails to parse stops
+ * before a single request leaves the page — so both sentences may say no memory was changed, which
+ * is exactly the doubt a reader has at that moment.
+ *
+ * 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: an answer the server gave is read through `refusalText`, the rule every refusal in
+ * the app follows. A document error already carries the interface's own sentence for what is wrong
+ * with the file, so it is kept as written; anything else raised while reading the file is the File
+ * API handing over no bytes, whose message is the browser's own and never localized — the sentence
+ * says instead that the file is not a memory export, which is what the reader is holding.
+ */
+import { refusalText } from "../../lib/api-error";
+import { S } from "../../lib/strings";
+import { MemoryDocumentError } from "./memory-transfer";
+
+/** The sentence one refused attempt left, and the scope it was for. */
+export interface MemoryGroupRefusal {
+ 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));
+}
+
+/**
+ * The sentence for a picked file that never reached the import modal. The reason is the document
+ * error's own words when it has them (an empty document says so), and the plain "this is not a
+ * memory export" otherwise.
+ */
+export function memoryImportRefused(scope: string, error: unknown): string {
+ const reason = error instanceof MemoryDocumentError ? error.message : S.memory.importInvalidFile;
+ return S.memory.importRefused(scope, reason);
+}
+
+/**
+ * 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,
+ * whichever direction it went — 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 memoryGroupRefusalFor(
+ refusal: MemoryGroupRefusal | 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 3b964724..86e3474c 100644
--- a/packages/web/src/features/agents/memory-tab.tsx
+++ b/packages/web/src/features/agents/memory-tab.tsx
@@ -74,10 +74,13 @@ 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,
+ memoryExportRefused,
+ memoryGroupRefusalFor,
+ memoryImportRefused,
+} from "./memory-group-refusal";
+import type { MemoryGroupRefusal } from "./memory-group-refusal";
+import {
memoryDocumentFileName,
parseMemoryScopeDocument,
planMemoryImport,
@@ -174,10 +177,11 @@ 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);
+ // The reason one whole-group attempt did not land, kept in the group that asked
+ // (memory-group-refusal.ts): the group's head strip, the control that asked 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. One slot for both directions — a later attempt supersedes it.
+ const [groupRefusal, setGroupRefusal] = useState<MemoryGroupRefusal | null>(null);
const collapseKey = userId && projectId ? collapsedStoreKey(userId, projectId, agentId) : null;
const [collapsed, setCollapsed] = useState<Set<string>>(() => readCollapsedScopes(collapseKey));
const [memoryPrompt, setMemoryPrompt] = useState("");
@@ -431,14 +435,14 @@ export function MemoryTab({
* 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
+ * A refusal leaves its reason in the group that asked (memory-group-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);
+ setGroupRefusal(null);
try {
const doc = await api.exportMemoryScope(projectId, agentId, scope.scopeKey);
const url = URL.createObjectURL(
@@ -452,27 +456,38 @@ export function MemoryTab({
anchor.remove();
URL.revokeObjectURL(url);
} catch (e) {
- setExportRefusal({
+ setGroupRefusal({
scopeKey: scope.scopeKey,
text: memoryExportRefused(scopeTitle(scope), e),
});
}
};
- /** Reads the picked file and opens the import modal; a file that is not a document never gets that far. */
+ /**
+ * Reads the picked file and opens the import modal; a file that is not a document never gets that
+ * far. That refusal is this group's too (memory-group-refusal.ts): the file input is the group's
+ * own import control, so the attention line would float over a list while the reader is looking
+ * at the head strip that asked — and it would be gone in six seconds, leaving a pick that did
+ * nothing and nothing saying why.
+ */
const pickImport = async (scope: MemoryScopeInfo, event: ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0];
// Cleared so picking the same file again still fires a change event.
event.target.value = "";
if (!file) return;
+ // A picked document starts without the previous attempt's reason, whichever direction it went.
+ setGroupRefusal(null);
try {
const doc = parseMemoryScopeDocument(await file.text());
setImportMode("skip");
- // A newly picked document starts without the previous attempt's reason.
+ // A newly picked document starts the dialog without the previous attempt's reason.
setImportRefusal(null);
setImporting({ scope, fileName: file.name, doc });
} catch (e) {
- toastError(e instanceof MemoryDocumentError ? e.message : S.memory.importInvalidFile);
+ setGroupRefusal({
+ scopeKey: scope.scopeKey,
+ text: memoryImportRefused(scopeTitle(scope), e),
+ });
}
};
@@ -676,7 +691,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);
+ const refusal = memoryGroupRefusalFor(groupRefusal, 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
@@ -706,14 +721,15 @@ export function MemoryTab({
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). */
+ /* A whole-group attempt this card offered that did not land — an export the
+ server would not serve, or a file the import never got to read: the head strip
+ (and the control 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-group-refusal.ts). */
refusal !== undefined ? (
<p
role="alert"
- data-testid="export-refusal"
+ data-testid="memory-refusal"
data-tooltip={refusal}
data-tooltip-content="text"
className={`line-clamp-2 break-words text-xs ${toneInk.danger}`}
diff --git a/packages/web/src/features/agents/memory-transfer.ts b/packages/web/src/features/agents/memory-transfer.ts
index b3ce9c63..80a399e9 100644
--- a/packages/web/src/features/agents/memory-transfer.ts
+++ b/packages/web/src/features/agents/memory-transfer.ts
@@ -18,7 +18,7 @@ import { S } from "../../lib/strings";
const SCOPE_FORMAT: MemoryScopeExport["format"] = "penguin-memory-scope";
const SCOPE_FORMAT_VERSION: MemoryScopeExport["version"] = 1;
-/** A picked file that is not a scope document. Its message is already localized, so callers toast it as is. */
+/** A picked file that is not a scope document. Its message is already localized, so the group that picked it shows it as is (memory-group-refusal.ts). */
export class MemoryDocumentError extends Error {
constructor(message: string) {
super(message);
diff --git a/packages/web/src/lib/strings-en.ts b/packages/web/src/lib/strings-en.ts
index db5e47bf..f1f541f9 100644
--- a/packages/web/src/lib/strings-en.ts
+++ b/packages/web/src/lib/strings-en.ts
@@ -2491,9 +2491,15 @@ 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. */
+ /** An export the download refused (memory-group-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}`,
+ /**
+ * A picked file the import never got to read (memory-group-refusal.ts), drawn in the group
+ * whose import control picked it.
+ */
+ importRefused: (scope: string, reason: string): string =>
+ `The memory group "${scope}" was not imported — this file could not be read, 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 43b892b9..b1ca6e2d 100644
--- a/packages/web/src/lib/strings.ts
+++ b/packages/web/src/lib/strings.ts
@@ -2546,12 +2546,19 @@ export const zh = {
exportScopeHint: "将该组全部记忆下载为一份 JSON 文档",
exportScopeLabel: (scope: string): string => `导出${scope}`,
/**
- * An export the download refused (memory-export-refusal.ts), drawn in the group that asked.
+ * An export the download refused (memory-group-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}`,
+ /**
+ * A picked file the import never got to read (memory-group-refusal.ts), drawn in the group
+ * whose import control picked it. Says the file never got read, because that is what stopped
+ * it: no request left the page, so nothing in the group moved.
+ */
+ importRefused: (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
deleted file mode 100644
index f938dce5..00000000
--- a/packages/web/test/memory-export-refusal.test.ts
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * 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();
- });
-});
diff --git a/packages/web/test/memory-group-refusal.test.ts b/packages/web/test/memory-group-refusal.test.ts
new file mode 100644
index 00000000..858b12fc
--- /dev/null
+++ b/packages/web/test/memory-group-refusal.test.ts
@@ -0,0 +1,134 @@
+/**
+ * A memory group's whole-group attempt that did not land (src/features/agents/memory-group-refusal.ts):
+ * the sentence that group draws — for an export the server would not serve, or a picked file the
+ * import never got to read — and the one thing it must not do, speak for another group.
+ *
+ * Neither attempt writes anything: an export only reads, and a file that fails to parse stops
+ * before a request leaves the page. So a refusal leaves the group, its memories and the same control
+ * on screen, and the sentence is the only thing saying nothing was written. What 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 document this codebase rejected keeps its own words, a value with nothing to say
+ * falls back rather than showing a browser's English, 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 {
+ memoryExportRefused,
+ memoryGroupRefusalFor,
+ memoryImportRefused,
+} from "../src/features/agents/memory-group-refusal";
+import { MemoryDocumentError } from "../src/features/agents/memory-transfer";
+
+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("memoryImportRefused", () => {
+ it("keeps the document's own words for what is wrong with the file", () => {
+ // "This file carries no memories" is the more useful sentence of the two the parser raises;
+ // it must not be flattened into the generic one.
+ const empty = new MemoryDocumentError(S.memory.importEmptyFile);
+ expect(memoryImportRefused("用户记忆", empty)).toBe(
+ S.memory.importRefused("用户记忆", S.memory.importEmptyFile),
+ );
+ expect(memoryImportRefused("用户记忆", empty)).not.toBe(
+ S.memory.importRefused("用户记忆", S.memory.importInvalidFile),
+ );
+ });
+
+ it("says the file is not a memory export when reading it failed for another reason", () => {
+ // A File API rejection's message is the browser's own and never localized; the reader is left
+ // with a file they cannot use, and that is what the sentence has to say.
+ const browserFailure = new DOMException(
+ "The requested file could not be read",
+ "NotReadableError",
+ );
+ expect(memoryImportRefused("用户记忆", browserFailure)).toBe(
+ S.memory.importRefused("用户记忆", S.memory.importInvalidFile),
+ );
+ expect(memoryImportRefused("用户记忆", browserFailure)).not.toContain("NotReadableError");
+ });
+
+ it("names the group the pick was made for", () => {
+ expect(
+ memoryImportRefused("adelie-fork", new MemoryDocumentError(S.memory.importInvalidFile)),
+ ).toContain("adelie-fork");
+ });
+
+ it("says the file was never read, so no memory changed", () => {
+ expect(
+ memoryImportRefused("用户记忆", new MemoryDocumentError(S.memory.importInvalidFile)),
+ ).toContain("记忆一条都没有被改动");
+ });
+
+ it("speaks the active language", () => {
+ setActiveStrings(EN);
+ expect(
+ memoryImportRefused("User memory", new MemoryDocumentError(EN.memory.importInvalidFile)),
+ ).toBe(EN.memory.importRefused("User memory", EN.memory.importInvalidFile));
+ expect(
+ memoryImportRefused("User memory", new DOMException("nope", "NotReadableError")),
+ ).toContain("no memory was changed");
+ });
+});
+
+describe("memoryGroupRefusalFor", () => {
+ it("draws nothing when no attempt was refused", () => {
+ expect(memoryGroupRefusalFor(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(memoryGroupRefusalFor(refusal, "user")).toBe("not exported");
+ // Another group's card must read exactly as it did before the attempt.
+ expect(memoryGroupRefusalFor(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(memoryGroupRefusalFor(refusal, "ws:/root/b/adelie")).toBeUndefined();
+ });
+});