Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 183 additions & 7 deletions ts/docs/architecture/memory/view-maintenance.md

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions ts/packages/agents/browser/src/agent/memoryViews.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { createMemoryServiceRpcFacade } from "@typeagent/memory-service/rpc";
import type { MemoryAcquisitionProgressService } from "@typeagent/memory-client";
import {
readViewDetail,
viewSeparationRequestSchema,
inventoryPageRequestSchema,
viewSummaryRequestSchema,
viewPublicationBatchRequestSchema,
Expand Down Expand Up @@ -61,6 +62,7 @@ type ViewMethods = Pick<
| "memoryBuildViews"
| "memoryPlanViewMaintenance"
| "memoryMaintainViews"
| "memorySeparateView"
| "memoryUpdateViewMaintenance"
| "memoryGetViewMaintenance"
| "memoryGetViewBuild"
Expand Down Expand Up @@ -209,6 +211,10 @@ export function createMemoryViewFunctions(
memoryPlanViewMaintenance: (request) =>
views().planViewMaintenance(request),
memoryMaintainViews: (request) => views().maintainViews(request),
memorySeparateView: (request) =>
required("separateView")(
viewSeparationRequestSchema.parse(request),
),
memoryUpdateViewMaintenance: (request) =>
views().updateViewMaintenance(request),
memoryGetViewMaintenance: (request) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,12 @@ describe("Memory Hub project brief selector, editor and scope safety", () => {
jest.restoreAllMocks();
});
test.each([
{
summary: content.summary,
coverageNote: "",
goalHeading: "Goals",
expectedGoalHeading: "Goals",
},
{
summary: content.summary,
coverageNote: "Selected evidence only",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import type {
ViewSeparationProposal,
ViewVersion,
} from "@typeagent/memory-service";
import { createSeparationPanel } from "./memoryHubSeparation";
import { invokeMemory } from "./viewClient";

jest.mock("./viewClient", () => ({ invokeMemory: jest.fn() }));
const invoke = invokeMemory as jest.Mock<Promise<unknown>, [string, unknown]>;
const view = {
corpusId: "corpus",
viewId: "overview",
revisionId: "accepted",
version: 2,
} as ViewVersion;
const proposal: ViewSeparationProposal = {
receiptId: "split-proposal",
corpusId: "corpus",
viewId: "overview",
acceptedRevisionId: "accepted",
acceptedVersion: 2,
contentHash: "a".repeat(64),
definitionHash: "b".repeat(64),
assessmentHash: "c".repeat(64),
confirmationToken: "d".repeat(64),
reason: "Separate scoped purposes",
overview: {
title: "Complete original overview",
retainedSectionIds: ["old-anchor"],
retainedHumanUnits: ["section:old-anchor:body"],
},
destinations: ["Acquisition", "Publication"].map((purpose, index) => ({
viewId: `child-${index}`,
purpose,
sectionIds: ["old-anchor"],
citations: [
{
sourceId: "source",
revisionId: "original",
locator: "indexed:0",
excerpt: "Original evidence",
},
],
})),
unresolved: ["Human qualification remains in overview"],
state: "proposed",
reasonForState: "Awaiting explicit confirmation",
createdAt: "2026-11-15T00:00:00Z",
};
function copyProposal(): ViewSeparationProposal {
return JSON.parse(JSON.stringify(proposal));
}
async function settle() {
for (let turn = 0; turn < 8; turn++) await Promise.resolve();
}
async function open() {
const panel = createSeparationPanel(view);
document.body.replaceChildren(panel);
const disclosure = panel as HTMLDetailsElement;
disclosure.open = true;
disclosure.dispatchEvent(new Event("toggle"));
await settle();
return panel;
}
beforeEach(() => {
invoke.mockReset();
invoke.mockResolvedValue({
head: "e".repeat(40),
proposal: copyProposal(),
});
});
afterEach(() => document.body.replaceChildren());

test("destinations and retained human anchors are shown without ever confirming automatically", async () => {
const panel = await open();
expect(panel.textContent).toContain("Acquisition");
expect(panel.textContent).toContain("Publication");
expect(panel.textContent).toContain("old-anchor");
expect(panel.textContent).toContain("section:old-anchor:body");
expect(panel.textContent).toContain(
"Human qualification remains in overview",
);
expect(invoke).toHaveBeenCalledTimes(1);
const confirm = [...panel.querySelectorAll("button")].find(
(button) => button.textContent === "Confirm this separation",
)!;
expect(confirm.disabled).toBe(true);
confirm.click();
expect(invoke).toHaveBeenCalledTimes(1);
const checkbox = panel.querySelector("input")!;
checkbox.checked = true;
checkbox.dispatchEvent(new Event("change"));
confirm.click();
await settle();
expect(invoke).toHaveBeenLastCalledWith("memorySeparateView", {
operation: "confirm",
corpusId: "corpus",
receiptId: "split-proposal",
expectedHead: "e".repeat(40),
confirmationToken: proposal.confirmationToken,
});
});

test("partial accepted destinations never become navigation; active destinations link exact revisions", async () => {
const incomplete = copyProposal();
incomplete.state = "incomplete";
incomplete.destinations[0].acceptedRevisionId = "child-revision-0";
invoke.mockResolvedValue({ head: null, proposal: incomplete });
let panel = await open();
expect(panel.querySelectorAll("a")).toHaveLength(0);
expect(panel.textContent).toContain("navigation withheld");
const active = copyProposal();
active.state = "active";
active.destinations[0].acceptedRevisionId = "child-revision-0";
active.destinations[1].acceptedRevisionId = "child-revision-1";
invoke.mockResolvedValue({ head: null, proposal: active });
panel = await open();
expect(
[...panel.querySelectorAll("a")].map((link) =>
link.getAttribute("href"),
),
).toEqual([
"#/views/corpus/child-0/revision/child-revision-0",
"#/views/corpus/child-1/revision/child-revision-1",
]);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import type {
ViewVersion,
ViewSeparationProposal,
ViewSeparationRequest,
ViewSeparationResult,
} from "@typeagent/memory-service";
import { invokeMemory } from "./viewClient";
import { rbButton, rbError, rbNode } from "./memoryHubDocumentUi";

export function createSeparationPanel(view: ViewVersion): HTMLElement {
const panel = rbNode("details");
panel.append(rbNode("summary", "Narrower articles and separation"));
const body = rbNode("div");
const error = rbNode("div");
panel.append(body, error);
let head: string | null = null;
let proposal: ViewSeparationProposal | null = null;
let loaded = false;
let running = false;

async function request(input: ViewSeparationRequest): Promise<void> {
error.replaceChildren();
try {
const result: ViewSeparationResult = await invokeMemory(
"memorySeparateView",
input,
);
head = result.head;
proposal = result.proposal;
render();
} catch (reason) {
if (input.operation === "confirm") await read();
error.replaceChildren(rbError(reason));
}
}

const read = () =>
request({
operation: "read",
corpusId: view.corpusId,
viewId: view.viewId,
});
const preview = () =>
request({
operation: "preview",
corpusId: view.corpusId,
viewId: view.viewId,
expectedHead: head,
expectedVersion: view.version,
revisionId: view.revisionId,
});
function render(): void {
body.replaceChildren(
rbNode(
"p",
"The accepted overview stays unchanged, including all facts, old anchors and human-authored units. Only explicitly confirmed narrower articles can be added.",
),
);
if (!proposal) {
body.append(
rbButton("Preview proposed separation", () => {
void preview();
}),
);
return;
}
const current = proposal;
body.append(
rbNode("p", `${current.state}: ${current.reasonForState}`),
rbNode("p", current.reason),
rbNode("h4", `Retained overview: ${current.overview.title}`),
rbNode(
"p",
`Retained anchors: ${current.overview.retainedSectionIds.join(", ")}`,
),
rbNode(
"p",
`Retained human units: ${current.overview.retainedHumanUnits.join(", ") || "none recorded"}`,
),
);
const destinations = rbNode("ul");
for (const destination of current.destinations) {
const item = rbNode("li");
item.append(rbNode("p", destination.purpose));
item.append(
rbNode(
"p",
`Original sections: ${destination.sectionIds.join(", ")}; original evidence: ${destination.citations.map((citation) => `${citation.sourceId} @ ${citation.revisionId} (${citation.locator})`).join("; ")}`,
),
);
if (current.state === "active" && destination.acceptedRevisionId) {
const link = rbNode("a", "Read narrower article");
link.href = `#/views/${encodeURIComponent(view.corpusId)}/${encodeURIComponent(destination.viewId)}/revision/${encodeURIComponent(destination.acceptedRevisionId)}`;
item.append(link);
} else {
item.append(
rbNode(
"p",
destination.acceptedRevisionId
? "Accepted destination; navigation withheld until every exact index is ready"
: "Destination not yet accepted",
),
);
}
destinations.append(item);
}
body.append(destinations);
if (current.unresolved.length)
body.append(
rbNode(
"p",
`Unresolved assignments remain in the unchanged overview: ${current.unresolved.join("; ")}`,
),
);
if (
["proposed", "incomplete", "cancelled", "confirmed"].includes(
current.state,
)
) {
const label = rbNode("label");
const consent = document.createElement("input");
consent.type = "checkbox";
label.append(
consent,
rbNode(
"span",
"I confirm this proposal's destinations and retention of the complete original overview.",
),
);
const confirm = rbButton(
current.confirmedAt
? "Retry confirmed separation"
: "Confirm this separation",
() => {
if (!consent.checked || running) return;
running = true;
confirm.disabled = true;
void request({
operation: "confirm",
corpusId: view.corpusId,
receiptId: current.receiptId,
expectedHead: head,
confirmationToken: current.confirmationToken,
}).finally(() => {
running = false;
confirm.disabled = !consent.checked;
});
},
);
confirm.disabled = true;
consent.onchange = () => {
confirm.disabled = !consent.checked || running;
};
body.append(label, confirm);
body.append(
rbButton("Cancel separation", () => {
void request({
operation: "cancel",
corpusId: view.corpusId,
receiptId: current.receiptId,
expectedHead: head,
});
}),
);
}
if (current.state === "stale")
body.append(
rbNode(
"p",
"Run semantic review for the current article and request a new preview before continuing.",
),
rbButton("Preview updated separation", () => {
void preview();
}),
);
body.append(
rbButton("Refresh separation status", () => {
void read();
}),
);
}
panel.ontoggle = () => {
if (!panel.open || loaded) return;
loaded = true;
void read();
};
return panel;
}
Loading
Loading