diff --git a/apps/mobile/src/components/ProjectKnowledgeEntry.test.tsx b/apps/mobile/src/components/ProjectKnowledgeEntry.test.tsx index 5d1b205e7c91f..90506c6fc8260 100644 --- a/apps/mobile/src/components/ProjectKnowledgeEntry.test.tsx +++ b/apps/mobile/src/components/ProjectKnowledgeEntry.test.tsx @@ -23,6 +23,7 @@ import type { SheetProps } from "./ui/Sheet.types"; const state = vi.hoisted(() => ({ uuidSequence: 0, deliveryCapabilities: {} as Record, + curation: false, deliveries: null as unknown, readDeliveries: vi.fn(), focused: true, @@ -165,6 +166,7 @@ vi.mock("../state/server", () => ({ capabilities: { projectKnowledge: true, projectKnowledgeHistory: true, + projectKnowledgeCuration: state.curation, projectKnowledgeDeliveries: state.deliveryCapabilities[environmentId], }, }, @@ -287,9 +289,10 @@ const deliveryRecord: ProjectKnowledgeDeliveries = { }, ], }; -function setup(entries: Array = [scope]) { +function setup(entries: Array = [scope], curation = false) { state.uuidSequence = 0; state.deliveryCapabilities = {}; + state.curation = curation; state.deliveries = null; state.readDeliveries.mockReset(); state.focused = true; @@ -672,8 +675,8 @@ it("forgets a fact only after the permanent-erase warning is confirmed", async ( }); }); -it("marks a superseded fact read-only and lists superseded facts on request", async () => { - using screen = setup(); +it.each([false, true])("handles superseded facts with curation support %s", async (curation) => { + using screen = setup([scope], curation); state.list = { facts: [{ ...fact, supersededBy: ProjectFactId.make("replacement") }], nextCursor: null, @@ -684,6 +687,7 @@ it("marks a superseded fact read-only and lists superseded facts on request", as const labels = [...screen.container.querySelectorAll("button")].map((item) => item.textContent); expect(labels).not.toContain("Edit"); expect(labels).not.toContain("Supersede"); + expect(labels.includes("Restore to recall")).toBe(curation); await screen.click("Back"); expect(state.listInputs.at(-1)).not.toHaveProperty("includeSuperseded"); await act(async () => @@ -692,6 +696,20 @@ it("marks a superseded fact read-only and lists superseded facts on request", as ).click(), ); expect(state.listInputs.at(-1)).toMatchObject({ includeSuperseded: true }); + if (!curation) return; + await screen.click(`Inspect fact: ${fact.content}`); + await screen.click("Restore to recall"); + expect(state.mutate).toHaveBeenCalledWith({ + environmentId: scope.environmentId, + input: { + action: "restore", + commandId: expect.any(String), + projectId: scope.projectId, + factId: fact.id, + expectedRevision: fact.revision, + }, + }); + expect(screen.container.textContent).not.toContain("Restore to recall"); }); it("supersedes a fact with a new replacement and shows the returned conflict hints", async () => { diff --git a/apps/mobile/src/components/ProjectKnowledgeEntry.tsx b/apps/mobile/src/components/ProjectKnowledgeEntry.tsx index 1f58634fa343d..380900d8a7e7f 100644 --- a/apps/mobile/src/components/ProjectKnowledgeEntry.tsx +++ b/apps/mobile/src/components/ProjectKnowledgeEntry.tsx @@ -134,7 +134,7 @@ export function ProjectKnowledgeEntry(props: Scope) { // Older servers lack readFact, status and supersede. history={config.environment.capabilities.projectKnowledgeHistory === true} assisted={config.environment.capabilities.projectKnowledgeAssistedLearning === true} - standingCheck={config.environment.capabilities.projectKnowledgeStandingCheck === true} + curation={config.environment.capabilities.projectKnowledgeCuration === true} seedMessage={open.seed} onClose={() => setOpen(null)} /> @@ -145,7 +145,7 @@ function ProjectKnowledgeSheet( props: Scope & { readonly history: boolean; readonly assisted: boolean; - readonly standingCheck: boolean; + readonly curation: boolean; readonly seedMessage: MessageCitation | null; readonly onClose: () => void; }, @@ -462,7 +462,6 @@ function ProjectKnowledgeSheet( projectId={props.projectId} browse={browse} assisted={props.assisted} - standingCheck={props.standingCheck} canMutate={canMutate} busy={busy} selectionState={selectionState} @@ -485,6 +484,7 @@ function ProjectKnowledgeSheet( detail={detailData} detailError={detail.error} history={props.history} + curation={props.curation} sourceUnavailable={ detailData?.sourceUnavailable ?? browse.unavailableReasons.get(inspectedFact.id) ?? @@ -517,6 +517,7 @@ function ProjectKnowledgeSheet( void apply({ action: "forget", ...factMutation(inspectedFact) }), }) } + onRestore={() => void apply({ action: "restore", ...factMutation(inspectedFact) })} onFeedback={(helpful) => void apply({ action: "feedback", helpful, ...factMutation(inspectedFact) }) } diff --git a/apps/mobile/src/components/ProjectKnowledgeFactDetail.tsx b/apps/mobile/src/components/ProjectKnowledgeFactDetail.tsx index b94d17ae18257..085d1c5a9911c 100644 --- a/apps/mobile/src/components/ProjectKnowledgeFactDetail.tsx +++ b/apps/mobile/src/components/ProjectKnowledgeFactDetail.tsx @@ -17,9 +17,11 @@ import type { import { messageAuthorLabel } from "@t3tools/client-runtime/conversationSummaries"; import { KNOWLEDGE_SOURCE_UNAVAILABLE_LABEL, + canRestoreFactToRecall, isSupersededFact, knowledgeConflictHintLabel, knowledgeOriginLabel, + memoryCurationRunLabel, projectFactVerdictLabel, projectFactHistoryLabel, } from "@t3tools/client-runtime/projectKnowledge"; @@ -96,6 +98,9 @@ function HistoryRow(props: { readonly entry: ProjectFactHistoryEntry }) { Trust {entry.trustBefore.toFixed(2)} → {entry.trustAfter.toFixed(2)} ) : null} + {entry.reason ? ( + {entry.reason} + ) : null} {content !== null ? ( {content.length > REVISION_PREVIEW_LENGTH @@ -118,6 +123,7 @@ export function ProjectFactInspector(props: { readonly detail: ProjectKnowledgeFactDetail | null; readonly detailError: string | null; readonly history: boolean; + readonly curation: boolean; readonly sourceUnavailable: KnowledgeSourceUnavailableReason | null; readonly hints: ReadonlyArray; readonly selection: KnowledgeSelectionState | null; @@ -129,6 +135,7 @@ export function ProjectFactInspector(props: { readonly onOpenFact: OpenFact; readonly onEdit: (mode: "edit" | "supersede") => void; readonly onForget: () => void; + readonly onRestore: () => void; readonly onFeedback: (helpful: boolean) => void; readonly onDismissHints: () => void; }) { @@ -203,6 +210,14 @@ export function ProjectFactInspector(props: { {active ? ( + {props.curation && canRestoreFactToRecall(fact) ? ( + + ) : null} {/* The server rejects revisions of a superseded fact; its replacement is the one to change. */} {!superseded ? (