Python
fix(memhub): stabilize memory detail and pagination
kristinhe556d95df84ed
diff --git a/memhub/apps/web/src/MemoryMap.test.tsx b/memhub/apps/web/src/MemoryMap.test.tsxindex 6878869..3ec218b 100644--- a/memhub/apps/web/src/MemoryMap.test.tsx+++ b/memhub/apps/web/src/MemoryMap.test.tsx@@ -265,6 +265,29 @@ it("OBS-15: switching memory shows a read in progress instead of the previous meexpect(screen.getByRole("status").textContent).toContain("正在读取这条记忆");});+it("keeps the detail header outside the scrolling body and resets detail scroll on selection", async () => {+ const { container } = render(+ <Host simplified sources={[importedSources[0]]} />,+ );+ const heading = screen+ .getByRole("heading", { name: "记忆详情" })+ .closest(".map-inspector-heading");+ const body = container.querySelector<HTMLElement>(".map-inspector-body");+ expect(heading?.nextElementSibling).toBe(body);+ if (!body) throw new Error("Memory detail scroll body is missing");+ body.scrollTop = 180;+ await userEvent.click(+ within(screen.getByRole("list", { name: "地图记忆列表" })).getByRole(+ "button",+ { name: /第二条/ },+ ),+ );+ expect(body.scrollTop).toBe(0);+ body.scrollTop = 120;+ await userEvent.click(screen.getByRole("button", { name: "图中选择 Codex" }));+ expect(body.scrollTop).toBe(0);+});+it("OBS-12: the graph legend stays with the graph instead of sitting under a stage without one", () => {// While the first page is still being read there is no graph yet: the// legend used to sit there anyway, describing nothing.@@ -546,6 +569,73 @@ it("D96: lists a memory by when its conversation happened, not when it was gener).toBe(true);});+it("keeps pagination and current detail stable while the next page is loading", async () => {+ const onPage = vi.fn();+ const page = {+ items: memories,+ total: 202,+ offset: 0,+ limit: 100,+ source_ids_by_memory: { m0: ["codex"], m1: ["codex"] },+ };+ const libraryView = { ...pagedView(page), onPage };+ const view = render(<Host simplified libraryView={libraryView} />);+ const list = screen.getByRole("list", { name: "地图记忆列表" });+ list.scrollTop = 160;+ const pager = screen.getByRole("navigation", { name: "地图记忆分页" });+ await userEvent.click(+ within(pager).getByRole("button", { name: "下一页记忆" }),+ );+ expect(onPage).toHaveBeenCalledWith(100);+ view.rerender(+ <Host simplified libraryView={{ ...libraryView, loading: true }} />,+ );+ expect(+ screen+ .getByRole("navigation", { name: "地图记忆分页" })+ .getAttribute("aria-busy"),+ ).toBe("true");+ expect(+ (+ screen.getByRole("button", {+ name: "下一页记忆",+ }) as HTMLButtonElement+ ).disabled,+ ).toBe(true);+ expect(screen.getByRole("heading", { name: "第一条" })).toBeTruthy();+ expect(list.scrollTop).toBe(160);++ const nextItems = memories.map((memory, index) => ({+ ...memory,+ memory_id: `next-${index}`,+ content: `下一页第 ${index + 1} 条`,+ }));+ view.rerender(+ <Host+ simplified+ items={nextItems}+ libraryView={{+ ...libraryView,+ page: {+ ...page,+ items: nextItems,+ offset: 100,+ source_ids_by_memory: {+ "next-0": ["codex"],+ "next-1": ["codex"],+ },+ },+ loading: false,+ }}+ />,+ );+ expect(list.scrollTop).toBe(0);+ expect(within(list).getByText("下一页第 1 条")).toBeTruthy();+ await waitFor(() =>+ expect(screen.queryByRole("heading", { name: "第一条" })).toBeNull(),+ );+});+it("names the SDK's no-source bucket 未识别来源, apart from a source under review", () => {const items = ["有来源", "无来源"].map((content, i) => ({...memories[0],diff --git a/memhub/apps/web/src/MemoryMap.tsx b/memhub/apps/web/src/MemoryMap.tsxindex 2ef795c..1de69a4 100644--- a/memhub/apps/web/src/MemoryMap.tsx+++ b/memhub/apps/web/src/MemoryMap.tsx@@ -25,6 +25,7 @@ import {type RefObject,useCallback,useEffect,+ useLayoutEffect,useMemo,useRef,useState,@@ -220,6 +221,8 @@ export function MemoryMap(props: Props) {const compact = useMediaPreference("(max-width: 1100px)");const composing = useRef(false);const pane = useRef<HTMLElement>(null);+ const memoryList = useRef<HTMLUListElement>(null);+ const inspectorBody = useRef<HTMLDivElement>(null);const openedDefault = useRef(false);const scrollSelection = useRef(false);const controlledSource = library@@ -367,6 +370,11 @@ export function MemoryMap(props: Props) {const activeId = active.some((memory) => memory.memory_id === requestedId)? requestedId: null;+ const inspectorIdentity = activeId+ ? `memory:${activeId}`+ : selectedSource+ ? `source:${selectedSource.source_id}`+ : (visibleGroupNode?.node_id ?? "empty");const visibleDetail =detail &&(!activeId || activeId === detail.memory.memory_id) &&@@ -427,6 +435,19 @@ export function MemoryMap(props: Props) {container.scrollTop += itemBounds.bottom - containerBounds.bottom;}}, [activeId]);+ useLayoutEffect(() => {+ // Detail content owns its own scrollport. A newly selected memory must+ // start at its heading instead of inheriting the previous inspector view.+ if (inspectorIdentity === "empty") return;+ if (inspectorBody.current) inspectorBody.current.scrollTop = 0;+ }, [inspectorIdentity]);+ const settledPageOffset = library?.page?.offset;+ useLayoutEffect(() => {+ // A settled page is a new reading surface, not a continuation of the+ // previous page's scroll position.+ if (settledPageOffset === undefined) return;+ if (memoryList.current) memoryList.current.scrollTop = 0;+ }, [settledPageOffset]);const clear = useCallback(() => {setSelectedId(null);@@ -781,6 +802,7 @@ export function MemoryMap(props: Props) {</p>)}<ul+ ref={memoryList}className="map-memory-list"aria-label={text("地图记忆列表")}id="memory-pane-memories"@@ -874,18 +896,21 @@ export function MemoryMap(props: Props) {</p>)}{library?.page &&- !library.loading &&+ (!library.loading || library.page.total > 0) &&!library.failed &&!library.stale && (- <nav aria-label={text("地图记忆分页")} className="map-pagination">+ <nav+ aria-label={text("地图记忆分页")}+ aria-busy={library.loading || undefined}+ className="map-pagination"+ ><buttontype="button"className="quiet map-tool"aria-label={text("上一页记忆")}title={text("上一页记忆")}- disabled={library.page.offset === 0}+ disabled={library.loading || library.page.offset === 0}onClick={() => {- clear();if (axis === "topic") setGroupKey("");if (library.page)library.onPage(library.page.offset - library.page.limit);@@ -914,10 +939,11 @@ export function MemoryMap(props: Props) {aria-label={text("下一页记忆")}title={text("下一页记忆")}disabled={- library.page.offset + library.page.limit >= library.page.total+ library.loading ||+ library.page.offset + library.page.limit >=+ library.page.total}onClick={() => {- clear();if (axis === "topic") setGroupKey("");if (library.page)library.onPage(library.page.offset + library.page.limit);@@ -1117,142 +1143,144 @@ export function MemoryMap(props: Props) {</button>)}</header>- {selectedSource ? (- inspectorOpen &&- !overlaysSuspended && (- <SourceImportReceipt- key={selectedSource.source_id}- source={selectedSource}- />- )- ) : props.simplified && inspectorDetail ? (- <div- aria-busy={- refreshing ||- inspectorDetail.memory.memory_id !== activeId ||- undefined- }- onClickCapture={(event) => {- // React portal events follow this owner too, including editor saves.- if (- refreshing &&- (event.target as Element).closest("button, summary")- ) {- event.preventDefault();- event.stopPropagation();- }- }}- onSubmitCapture={(event) => {- if (refreshing) {- event.preventDefault();- event.stopPropagation();+ <div className="map-inspector-body" ref={inspectorBody}>+ {selectedSource ? (+ inspectorOpen &&+ !overlaysSuspended && (+ <SourceImportReceipt+ key={selectedSource.source_id}+ source={selectedSource}+ />+ )+ ) : props.simplified && inspectorDetail ? (+ <div+ aria-busy={+ refreshing ||+ inspectorDetail.memory.memory_id !== activeId ||+ undefined}- }}- >- {/* The pane used to keep the previously read memory on screen+ onClickCapture={(event) => {+ // React portal events follow this owner too, including editor saves.+ if (+ refreshing &&+ (event.target as Element).closest("button, summary")+ ) {+ event.preventDefault();+ event.stopPropagation();+ }+ }}+ onSubmitCapture={(event) => {+ if (refreshing) {+ event.preventDefault();+ event.stopPropagation();+ }+ }}+ >+ {/* The pane used to keep the previously read memory on screenuntil the new one arrived, which read as "nothing happened"for two or three seconds. A read is not a value: show that aread is happening instead. */}- {activeId && inspectorDetail.memory.memory_id !== activeId ? (- <div className="map-detail-loading">+ {activeId && inspectorDetail.memory.memory_id !== activeId ? (+ <div className="map-detail-loading">+ <div className="map-detail-skeleton" aria-hidden="true">+ <i />+ <i />+ <i />+ <i />+ </div>+ <p role="status">{text("正在读取这条记忆…")}</p>+ </div>+ ) : (+ <SelectedMemoryDetail+ detail={inspectorDetail}+ sources={sources}+ conversationAt={+ library?.page?.source_time_by_memory?.[+ inspectorDetail.memory.memory_id+ ] ?? null+ }+ />+ )}+ </div>+ ) : inspectorDetail || visibleGroupNode ? (+ <NodeDetail+ key={+ inspectorDetail?.memory.memory_id ||+ visibleGroupNode?.node_id ||+ "empty"+ }+ compact+ node={visibleGroupNode}+ graph={projection}+ detail={inspectorDetail}+ draft={props.draft}+ busy={busy}+ matterLabel={label}+ onDraft={props.onDraft}+ onSave={props.onSave}+ onDelete={props.onDelete}+ requestIds={props.requestIds}+ onClose={closeInspector}+ />+ ) : (+ <div+ className={`map-inspector-empty${activeId ? " map-inspector-loading" : ""}`}+ >+ {activeId ? (<div className="map-detail-skeleton" aria-hidden="true"><i /><i /><i /><i /></div>- <p role="status">{text("正在读取这条记忆…")}</p>- </div>- ) : (- <SelectedMemoryDetail- detail={inspectorDetail}- sources={sources}- conversationAt={- library?.page?.source_time_by_memory?.[- inspectorDetail.memory.memory_id- ] ?? null- }- />- )}- </div>- ) : inspectorDetail || visibleGroupNode ? (- <NodeDetail- key={- inspectorDetail?.memory.memory_id ||- visibleGroupNode?.node_id ||- "empty"- }- compact- node={visibleGroupNode}- graph={projection}- detail={inspectorDetail}- draft={props.draft}- busy={busy}- matterLabel={label}- onDraft={props.onDraft}- onSave={props.onSave}- onDelete={props.onDelete}- requestIds={props.requestIds}- onClose={closeInspector}- />- ) : (- <div- className={`map-inspector-empty${activeId ? " map-inspector-loading" : ""}`}- >- {activeId ? (- <div className="map-detail-skeleton" aria-hidden="true">- <i />- <i />- <i />- <i />- </div>- ) : (- <FileText size={28} strokeWidth={1} />- )}- {props.detailLoad?.memoryId === activeId &&- props.detailLoad.status === "failed" ? (- <>- <p role="alert">- {text("这条记忆的原文暂时无法读取,选择已保留。")}- </p>- <button- type="button"- className="secondary"- onClick={() => activeId && onOpenMemory(activeId)}- >- {text("重试读取原文")}- </button>- </>- ) : props.simplified && !activeId && filtered.length ? (- // Nothing is selected, but this conversation has already- // settled: naming what came out of it beats a placeholder that- // asks for the settle that already happened. Only the- // single-column surface needs it — the three-column one already- // lists the same memories in the pane beside this one.- <>+ ) : (+ <FileText size={28} strokeWidth={1} />+ )}+ {props.detailLoad?.memoryId === activeId &&+ props.detailLoad.status === "failed" ? (+ <>+ <p role="alert">+ {text("这条记忆的原文暂时无法读取,选择已保留。")}+ </p>+ <button+ type="button"+ className="secondary"+ onClick={() => activeId && onOpenMemory(activeId)}+ >+ {text("重试读取原文")}+ </button>+ </>+ ) : props.simplified && !activeId && filtered.length ? (+ // Nothing is selected, but this conversation has already+ // settled: naming what came out of it beats a placeholder that+ // asks for the settle that already happened. Only the+ // single-column surface needs it — the three-column one already+ // lists the same memories in the pane beside this one.+ <>+ <p>+ {text(+ "已沉淀 {count} 条记忆",+ { count: plain(filtered.length) },+ filtered.length,+ )}+ </p>+ <ul+ className="map-settled-list"+ aria-label={text("已沉淀的记忆")}+ >+ {filtered.map((m) => (+ <li key={m.memory_id}>{m.content}</li>+ ))}+ </ul>+ </>+ ) : (<p>- {text(- "已沉淀 {count} 条记忆",- { count: plain(filtered.length) },- filtered.length,- )}+ {text(activeId ? "正在读取记忆详情…" : "沉淀记忆后查看详情")}</p>- <ul- className="map-settled-list"- aria-label={text("已沉淀的记忆")}- >- {filtered.map((m) => (- <li key={m.memory_id}>{m.content}</li>- ))}- </ul>- </>- ) : (- <p>- {text(activeId ? "正在读取记忆详情…" : "沉淀记忆后查看详情")}- </p>- )}- </div>- )}+ )}+ </div>+ )}+ </div></MemoryEvidencePanel></section>);diff --git a/memhub/apps/web/src/MemorySpace.r6.test.tsx b/memhub/apps/web/src/MemorySpace.r6.test.tsxindex 2e84f26..71cdcee 100644--- a/memhub/apps/web/src/MemorySpace.r6.test.tsx+++ b/memhub/apps/web/src/MemorySpace.r6.test.tsx@@ -201,8 +201,9 @@ it("keeps an added memory visible while it waits for model processing", async ()render(<MemorySpace simplified onConfigureModel={vi.fn()} />);fireEvent.click(screen.getByRole("button", { name: "补充记忆" }));expect(- screen.getByText(/原话已保存,正在等待整理:项目周会统一安排在周三上午。/),+ screen.getByText(/正在等待整理:项目周会统一安排在周三上午。/),).toBeTruthy();+ expect(screen.queryByText(/原话已保存/)).toBeNull();expect(screen.getByRole("button", { name: "配置整理模型" })).toBeTruthy();expect(screen.queryByText("还没有已生成的记忆")).toBeNull();});diff --git a/memhub/apps/web/src/MemorySpace.tsx b/memhub/apps/web/src/MemorySpace.tsxindex dec2d11..8d665c3 100644--- a/memhub/apps/web/src/MemorySpace.tsx+++ b/memhub/apps/web/src/MemorySpace.tsx@@ -953,7 +953,7 @@ export function MemorySpace({{simplified && pendingAdd ? (<p className="memory-pending-add" role="status"><span>- {t("memory:原话已保存,正在等待整理:")}+ {t("memory:正在等待整理:")}{pendingAdd.text}</span>{pendingAdd.state === "waiting_for_model" ? (diff --git a/memhub/apps/web/src/core-visual.css b/memhub/apps/web/src/core-visual.cssindex 4dba59c..3976c4b 100644--- a/memhub/apps/web/src/core-visual.css+++ b/memhub/apps/web/src/core-visual.css@@ -1086,8 +1086,9 @@ button.map-tool {border-radius: 6px;}.map-inspector {- overflow-y: auto;- overscroll-behavior: contain;+ display: flex;+ flex-direction: column;+ overflow: hidden;padding: 24px;background: var(--glass-drawer);border-left: 1px solid var(--bd);@@ -1095,10 +1096,19 @@ button.map-tool {}.map-inspector-heading {display: flex;+ flex: none;justify-content: space-between;align-items: center;margin-bottom: 22px;}+.map-inspector-body {+ flex: 1;+ min-height: 0;+ overflow-y: auto;+ overflow-anchor: none;+ overscroll-behavior: contain;+ scrollbar-gutter: stable;+}.map-inspector-heading h2 {font-size: 13px;font-weight: 600;diff --git a/memhub/apps/web/src/selected-memory.css b/memhub/apps/web/src/selected-memory.cssindex e1fde08..dd58dcd 100644--- a/memhub/apps/web/src/selected-memory.css+++ b/memhub/apps/web/src/selected-memory.css@@ -219,12 +219,14 @@}.r6-shell .r6-memory .map-inspector {padding: 14px 22px 24px;- background: rgb(255 255 255 / 30%);+ background: #f2f6f8;border: 0;border-radius: 0;- overflow-y: auto;- overflow-anchor: none;+ overflow: hidden;min-height: 0;+ isolation: isolate;+ backdrop-filter: none;+ -webkit-backdrop-filter: none;}.r6-shell .r6-memory .map-inspector-heading {padding: 0;@@ -498,11 +500,8 @@width: min(418px, calc(100vw - 32px));}.r6-shell .r6-memory .map-inspector-heading {- position: sticky;- top: -14px;- z-index: 1;- background: #eff5f8;- padding: 10px 0;+ position: static;+ padding: 0;}.selected-editor {padding-left: 0;diff --git a/memhub/packages/i18n/src/gui-i18n-english.ts b/memhub/packages/i18n/src/gui-i18n-english.tsindex 2e73777..8cd10e6 100644--- a/memhub/packages/i18n/src/gui-i18n-english.ts+++ b/memhub/packages/i18n/src/gui-i18n-english.ts@@ -1809,8 +1809,7 @@ const baseEnglishMessages = {"{count} memories created{filter} · Showing {shown}","memory:({filter})": " ({filter})","memory:第 {page} 页": "Page {page}",- "memory:原话已保存,正在等待整理:":- "Original text saved, awaiting processing: ",+ "memory:正在等待整理:": "Awaiting processing: ","memory:记忆未在生成": "Memories are not being created","memory:还没有开始生成记忆:{reason}({count} 条待处理)":"Memories are not being created: {reason} ({count} pending)",diff --git a/memhub/packages/i18n/src/gui-i18n-memory.ts b/memhub/packages/i18n/src/gui-i18n-memory.tsindex 03266c8..d27ee09 100644--- a/memhub/packages/i18n/src/gui-i18n-memory.ts+++ b/memhub/packages/i18n/src/gui-i18n-memory.ts@@ -370,7 +370,7 @@ export const memoryChineseMessages = {"已沉淀 {count} 条{filter} · 当前展示 {shown} 条","memory:({filter})": "({filter})","memory:第 {page} 页": "第 {page} 页",- "memory:原话已保存,正在等待整理:": "原话已保存,正在等待整理:",+ "memory:正在等待整理:": "正在等待整理:","memory:记忆未在生成": "记忆未在生成","memory:还没有开始生成记忆:{reason}({count} 条待处理)":"还没有开始生成记忆:{reason}({count} 条待处理)",@@ -786,8 +786,7 @@ export const memorySpanishMessages: Record<"{count} memoria guardada{filter} · {shown} visibles","memory:({filter})": " ({filter})","memory:第 {page} 页": "Página {page}",- "memory:原话已保存,正在等待整理:":- "Texto guardado; pendiente de procesar: ",+ "memory:正在等待整理:": "Pendiente de procesar: ","memory:记忆未在生成": "Generación de memorias detenida","memory:还没有开始生成记忆:{reason}({count} 条待处理)":"Aún no se generan memorias: {reason} ({count} pendientes)",