Python
fix(memhub): show attributed app calls on home
kristinhecb97aa5822f3
diff --git a/memhub/apps/web/src/ApplicationsHome.test.tsx b/memhub/apps/web/src/ApplicationsHome.test.tsxindex 99c156c..b6d2de2 100644--- a/memhub/apps/web/src/ApplicationsHome.test.tsx+++ b/memhub/apps/web/src/ApplicationsHome.test.tsx@@ -233,7 +233,7 @@ it("shows latest recorded call separately without exposing recent-update detailawait screen.findByText("Codex 查到 3 条相关内容");expect(document.querySelector(".r6-home-call-direction")).toBeTruthy();expect(screen.queryByText("实际治理记忆")).toBeNull();- expect(screen.getByText(/今天 .+ · 查询成功/)).toBeTruthy();+ expect(screen.getByText(/Codex · 今天 .+ · 查询成功/)).toBeTruthy();fireEvent.click(screen.getByRole("tab", { name: "最近更新" }));expect(screen.getByText("实际治理记忆")).toBeTruthy();expect(screen.queryByRole("button", { name: "查看记忆" })).toBeNull();@@ -246,11 +246,56 @@ it("shows latest recorded call separately without exposing recent-update detail} else {// D96: the recent call still shows on the home page; only the way into// the call-history page is hidden.- expect(screen.getByText(/今天 .+ · 查询成功/)).toBeTruthy();+ expect(screen.getByText(/Codex · 今天 .+ · 查询成功/)).toBeTruthy();expect(screen.queryByRole("button", { name: "查看记录" })).toBeNull();expect(onCalls).not.toHaveBeenCalled();}});+it("skips direct diagnostics and shows the latest attributed application call", async () => {+ history.mockResolvedValue({+ available: true,+ recording_error: false,+ items: [+ {+ event_id: "direct-diagnostic",+ host_id: null,+ state: "grounded",+ occurred_at: new Date().toISOString(),+ memory_count: 1,+ raw_count: 0,+ references: [],+ },+ {+ event_id: "workbuddy-call",+ host_id: "workbuddy",+ state: "grounded",+ occurred_at: new Date(Date.now() - 60_000).toISOString(),+ memory_count: 5,+ raw_count: 0,+ references: [],+ },+ ],+ });+ render(+ <ApplicationsHome+ imports={imports}+ onManage={() => {}}+ onMemories={() => {}}+ onSettings={() => {}}+ onCalls={() => {}}+ />,+ );++ fireEvent.click(await screen.findByRole("tab", { name: "最近调用" }));+ expect(await screen.findByText("WorkBuddy 查到 5 条相关内容")).toBeTruthy();+ expect(screen.queryByText(/直接调用/)).toBeNull();+ expect(screen.getByText(/WorkBuddy · 今天 .+ · 查询成功/)).toBeTruthy();+ const direction = document.querySelector(".r6-home-call-direction");+ expect(direction?.querySelector("img")?.getAttribute("src")).toContain(+ "/r6/workbuddy.png",+ );+ expect(direction?.querySelector(".r6-app-initial")).toBeNull();+});it("shows only the host for memory hits whose references have no source", async () => {history.mockResolvedValue({available: true,diff --git a/memhub/apps/web/src/ApplicationsHome.tsx b/memhub/apps/web/src/ApplicationsHome.tsxindex a73d104..71d6288 100644--- a/memhub/apps/web/src/ApplicationsHome.tsx+++ b/memhub/apps/web/src/ApplicationsHome.tsx@@ -94,6 +94,10 @@ function successfulCall(item: CallEvent) {return item.state === "grounded" || item.state === "empty";}+function attributedSuccessfulCall(item: CallEvent) {+ return item.host_id !== null && successfulCall(item);+}+function callAttention(events: CallEvent[]) {const hosts = new Set<string>();for (const event of events) {@@ -212,7 +216,10 @@ export function ApplicationsHome({const result = await getCallHistory({ limit: 20, offset: 0 });if (cancelled) return;setCallEvents(result.items);- setRecentCall(result.items.find(successfulCall) ?? null);+ // The home card promises an application identity. Direct diagnostic+ // calls have no host and remain available in call history, but cannot+ // truthfully supply the icon and name required by this surface.+ setRecentCall(result.items.find(attributedSuccessfulCall) ?? null);setCallState(!result.available? "disabled"@@ -597,6 +604,9 @@ export function ApplicationsHome({const recentCallHost = imports.sources.find((source) =>sourceMatchesHost(source.source_id, recentCall?.host_id ?? null),);+ const recentCallHostName = recentCall+ ? (recentCallHost?.display_name ?? callHostName(recentCall.host_id, locale))+ : null;const attention = callAttention(callEvents);const attentionHost = attention ? callHostName(attention.host, locale) : null;const activity = summaryUnavailable@@ -934,8 +944,7 @@ export function ApplicationsHome({: activity === "call" && recentCall? callDetailHeadline(recentCall,- recentCallHost?.display_name ??- callHostName(recentCall.host_id, locale),+ recentCallHostName ?? undefined,locale,): activity === "memory" && latest@@ -956,7 +965,7 @@ export function ApplicationsHome({? t("apps.callReadFailure"): t("apps.memoryReadFailure"): activity === "call" && recentCall- ? `${stamped(recentCall.occurred_at, locale, t)} · ${callRowDetail(recentCall, locale)}${callState === "incomplete" ? t("apps.incompleteCalls") : ""}`+ ? `${recentCallHostName} · ${stamped(recentCall.occurred_at, locale, t)} · ${callRowDetail(recentCall, locale)}${callState === "incomplete" ? t("apps.incompleteCalls") : ""}`: activity === "memory" && latest? [time, latestSourceNames.join(", ")].filter(Boolean)