@niwa-labs/memory 0.0.0-stage → 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +107 -2
- package/package.json +33 -4
- package/src/cockpit/actions.ts +95 -0
- package/src/cockpit/index.tsx +23 -0
- package/src/cockpit/notes.ts +78 -0
- package/src/cockpit/page.tsx +191 -0
- package/src/consolidate.ts +113 -0
- package/src/context.ts +41 -0
- package/src/fold.ts +308 -0
- package/src/holds.ts +13 -0
- package/src/index.ts +775 -0
- package/src/records.ts +538 -0
- package/src/same.ts +15 -0
- package/src/search.ts +48 -0
- package/src/share-question.ts +27 -0
- package/src/top.ts +44 -0
- package/test/cockpit-actions.test.ts +53 -0
- package/test/cockpit-notes.test.ts +89 -0
- package/test/consolidate.test.ts +171 -0
- package/test/context.test.ts +241 -0
- package/test/corroboration.test.ts +61 -0
- package/test/delegate-context.test.ts +16 -0
- package/test/fixtures/host.ts +229 -0
- package/test/intake.test.ts +69 -0
- package/test/notes.test.ts +124 -0
- package/test/projects.test.ts +37 -0
- package/test/recovery.test.ts +174 -0
- package/test/search.test.ts +88 -0
- package/test/top.test.ts +84 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// The copy of the actions the memory page keeps reads what the host answers, the host lists the module, and a share
|
|
2
|
+
// question the memory asked is found among what waits for the owner.
|
|
3
|
+
|
|
4
|
+
import { afterEach, expect, test } from "bun:test";
|
|
5
|
+
import { actionName } from "@niwa-labs/core";
|
|
6
|
+
import { agentList } from "@niwa-labs/agent/records";
|
|
7
|
+
import { requestOpen } from "@niwa-labs/requests/records";
|
|
8
|
+
import { unreadable, unsendable } from "@niwa-labs/testing";
|
|
9
|
+
|
|
10
|
+
import { memoryGet, memoryList, memoryPageGet, memoryPageList } from "../src/records.ts";
|
|
11
|
+
import { agentListAction, noteGetAction, noteListAction, openAction, pageGetAction, pageListAction } from "../src/cockpit/actions.ts";
|
|
12
|
+
import { shareQuestions } from "../src/cockpit/notes.ts";
|
|
13
|
+
import { bob, closeAll, memoryHost, owner, rin, until } from "./fixtures/host.ts";
|
|
14
|
+
|
|
15
|
+
afterEach(closeAll);
|
|
16
|
+
|
|
17
|
+
test.each([
|
|
18
|
+
["agent.list", agentListAction, agentList],
|
|
19
|
+
["memory.list", noteListAction, memoryList],
|
|
20
|
+
["memory.get", noteGetAction, memoryGet],
|
|
21
|
+
["memory.page.list", pageListAction, memoryPageList],
|
|
22
|
+
["memory.page.get", pageGetAction, memoryPageGet],
|
|
23
|
+
["request.open", openAction, requestOpen],
|
|
24
|
+
] as const)("%s is sent as the host takes it and its answer is read", (name, copy, real) => {
|
|
25
|
+
expect(String(copy.name)).toBe(name);
|
|
26
|
+
expect(String(real.name)).toBe(name);
|
|
27
|
+
expect(unsendable(copy.input, real.input)).toEqual([]);
|
|
28
|
+
expect(unreadable(copy.output, real.output)).toEqual([]);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("the plugin offers its page to the cockpit", async () => {
|
|
32
|
+
const host = await memoryHost();
|
|
33
|
+
const catalog = (await host.host.call(actionName("niwa.cockpit.catalog"), {})) as { modules: Array<{ id: string; plugin: string }> };
|
|
34
|
+
expect(catalog.modules).toContainEqual(expect.objectContaining({ id: "memory", plugin: "memory" }));
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("a note about the owner that another agent wanted is a question waiting for him, found for the memory that asked", async () => {
|
|
38
|
+
const host = await memoryHost({}, { agents: [{ name: "rin", harness: "h", prompt: "p" }, { name: "bob", harness: "h", prompt: "p" }] });
|
|
39
|
+
const note = await host.as<{ note: string }>(rin, "memory.note", { text: "He is on leave in May.", about: "owner", source: { kind: "session", session: "claude s-1", upto: "l-3" } });
|
|
40
|
+
await host.as(bob, "memory.context", { memory: "rin", query: "leave May", purpose: "to plan the week" });
|
|
41
|
+
await until(host, "request.created");
|
|
42
|
+
|
|
43
|
+
const { requests } = await host.as<{ requests: Parameters<typeof shareQuestions>[0] }>(owner, "request.open", {});
|
|
44
|
+
const found = shareQuestions(requests, "rin");
|
|
45
|
+
expect(found).toHaveLength(1);
|
|
46
|
+
expect(found[0]?.title).toBe("May agent bob be told what agent rin remembers about you?");
|
|
47
|
+
// What waits for him names the note; its text is read when it is shown, not kept in the question.
|
|
48
|
+
expect(found[0]?.detail).not.toContain("He is on leave in May.");
|
|
49
|
+
expect(found[0]?.reference).toEqual({ memory: "rin", note: note.note, revision: 1 });
|
|
50
|
+
expect(found[0]?.purpose).toBe("to plan the week");
|
|
51
|
+
expect(note.note).toMatch(/^note-/);
|
|
52
|
+
expect(shareQuestions(requests, "bob")).toEqual([]);
|
|
53
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// The memory page: the top layer by part, how a note reads, which memory is shown, and which questions are the memory's.
|
|
2
|
+
|
|
3
|
+
import { expect, test } from "bun:test";
|
|
4
|
+
|
|
5
|
+
import type { Note, Open } from "../src/cockpit/actions.ts";
|
|
6
|
+
import { memoryChoice, newestFirst, shareQuestions, shownText, sourceText, standingText, topParts } from "../src/cockpit/notes.ts";
|
|
7
|
+
import { shareDetail, shareReferenceOf } from "../src/share-question.ts";
|
|
8
|
+
|
|
9
|
+
let counter = 0;
|
|
10
|
+
function note(text: string, extra: Partial<Note> = {}): Note {
|
|
11
|
+
counter += 1;
|
|
12
|
+
return { note: `note-${String(counter)}`, text, about: "work", source: { kind: "inferred" }, confirmed: false, sources: 1, top: false, pinned: false, revision: 1, written: counter, ...extra };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
test("the top layer is by part: the owner first, then each project, then what holds in general, the newest first", () => {
|
|
16
|
+
const parts = topParts([
|
|
17
|
+
note("tea", { about: "owner", top: true }),
|
|
18
|
+
note("old general", { top: true }),
|
|
19
|
+
note("billing", { project: "/work/billing", top: true }),
|
|
20
|
+
note("not lifted", { about: "owner" }),
|
|
21
|
+
note("new general", { top: true }),
|
|
22
|
+
note("payroll", { project: "/work/payroll", top: true }),
|
|
23
|
+
note("coffee", { about: "owner", project: "/work/billing", top: true }),
|
|
24
|
+
]);
|
|
25
|
+
expect(parts.map((part) => [part.heading, part.notes.map((one) => one.text)])).toEqual([
|
|
26
|
+
["О владельце", ["coffee", "tea"]],
|
|
27
|
+
["Проект /work/billing", ["billing"]],
|
|
28
|
+
["Проект /work/payroll", ["payroll"]],
|
|
29
|
+
["Общее", ["new general", "old general"]],
|
|
30
|
+
]);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("a part with nothing lifted is not shown", () => {
|
|
34
|
+
expect(topParts([note("a"), note("b", { about: "owner" })])).toEqual([]);
|
|
35
|
+
expect(topParts([note("a", { top: true })]).map((part) => part.heading)).toEqual(["Общее"]);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("notes are listed newest first", () => {
|
|
39
|
+
expect(newestFirst([note("a"), note("b"), note("c")]).map((one) => one.text)).toEqual(["c", "b", "a"]);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("a source and a note's standing read in a few words", () => {
|
|
43
|
+
expect(sourceText({ kind: "owner" })).toBe("слова владельца");
|
|
44
|
+
expect(sourceText({ kind: "inferred" })).toBe("вывод автора");
|
|
45
|
+
expect(sourceText({ kind: "session", session: "claude s-1" })).toBe("сессия claude s-1");
|
|
46
|
+
expect(sourceText({ kind: "record", record: "r-9" })).toBe("запись r-9");
|
|
47
|
+
expect(standingText({ confirmed: true, sources: 1 })).toBe("подтверждено владельцем");
|
|
48
|
+
expect(standingText({ confirmed: false, sources: 1 })).toBe("один источник");
|
|
49
|
+
expect(standingText({ confirmed: false, sources: 3 })).toBe("источников: 3");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("the memory asked for is shown when an agent has it, else the first", () => {
|
|
53
|
+
expect(memoryChoice("bob", ["rin", "bob"])).toBe("bob");
|
|
54
|
+
expect(memoryChoice("nobody", ["rin", "bob"])).toBe("rin");
|
|
55
|
+
expect(memoryChoice(undefined, ["rin", "bob"])).toBe("rin");
|
|
56
|
+
expect(memoryChoice("rin", [])).toBeUndefined();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
function request(id: string, question: string, from: { kind: string; id?: string } | undefined, title = "May bob be told?"): Open {
|
|
60
|
+
return { id, to: { kind: "owner" }, question, input: { kind: "confirm", title, detail: "why" }, ...(from === undefined ? {} : { from }) };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
test("a share question is one the memory asked, and nothing else that waits is", () => {
|
|
64
|
+
const found = shareQuestions(
|
|
65
|
+
[
|
|
66
|
+
request("req-1", "memory.share", { kind: "agent", id: "rin" }),
|
|
67
|
+
request("req-2", "memory.share", { kind: "agent", id: "bob" }),
|
|
68
|
+
request("req-3", "deploy.approve", { kind: "agent", id: "rin" }),
|
|
69
|
+
request("req-4", "memory.share", undefined),
|
|
70
|
+
request("req-5", "memory.share", { kind: "session", id: "rin" }),
|
|
71
|
+
{ kind: "paused", invocation: "inv-1" },
|
|
72
|
+
],
|
|
73
|
+
"rin",
|
|
74
|
+
);
|
|
75
|
+
expect(found).toEqual([{ id: "req-1", title: "May bob be told?", detail: "why", reference: undefined, purpose: undefined }]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("a share question names its note and revision and the purpose, and the text is shown only while the note holds as named", () => {
|
|
79
|
+
const reference = { memory: "rin", note: "note-0123456789ab", revision: 2 };
|
|
80
|
+
const detail = shareDetail(reference, "to plan the week.\nTwo lines");
|
|
81
|
+
expect(shareReferenceOf(detail)).toEqual({ reference, purpose: "to plan the week.\nTwo lines" });
|
|
82
|
+
expect(shareReferenceOf("why")).toBeUndefined();
|
|
83
|
+
const [found] = shareQuestions([{ ...request("req-1", "memory.share", { kind: "agent", id: "rin" }), input: { kind: "confirm", title: "May bob be told?", detail } }], "rin");
|
|
84
|
+
expect(found).toMatchObject({ reference, purpose: "to plan the week.\nTwo lines" });
|
|
85
|
+
expect(shownText(reference, { text: "He is on leave.", revision: 2, status: "live" })).toBe("He is on leave.");
|
|
86
|
+
expect(shownText(reference, { text: "He is on leave.", revision: 3, status: "live" })).toBeUndefined();
|
|
87
|
+
expect(shownText(reference, { text: "", revision: 2, status: "erased" })).toBeUndefined();
|
|
88
|
+
expect(shownText(reference, { text: "He is on leave.", revision: 2, status: "retracted" })).toBeUndefined();
|
|
89
|
+
});
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// Consolidation: notes that say the same are merged, the notes that earned it are lifted, the weakest
|
|
2
|
+
// drop out of a part of the top layer grown too long, stale or surplus notes are retired, and notes placed
|
|
3
|
+
// by hand stay where they are. A memory consolidates by itself as digests keep coming in.
|
|
4
|
+
|
|
5
|
+
import { afterEach, expect, test } from "bun:test";
|
|
6
|
+
|
|
7
|
+
import { AgentTurnQueued } from "@niwa-labs/agent/records";
|
|
8
|
+
|
|
9
|
+
import { closeAll, dataOf, memoryHost, owner, rin, until } from "./fixtures/host.ts";
|
|
10
|
+
import type { MemoryHost } from "./fixtures/host.ts";
|
|
11
|
+
|
|
12
|
+
afterEach(closeAll);
|
|
13
|
+
|
|
14
|
+
type Plan = { memory: string; merged: Array<{ note: string; into: string }>; lifted: string[]; dropped: string[]; retired: string[] };
|
|
15
|
+
type View = { note: string; status: string; top: boolean; sources: number; confirmed: boolean };
|
|
16
|
+
|
|
17
|
+
const DAY = 24 * 60 * 60 * 1000;
|
|
18
|
+
|
|
19
|
+
async function noted(host: MemoryHost, text: string, more: Record<string, unknown> = {}): Promise<string> {
|
|
20
|
+
return (await host.as<{ note: string }>(rin, "memory.note", { text, ...more })).note;
|
|
21
|
+
}
|
|
22
|
+
const session = (n: number) => ({ kind: "session", session: `claude s-${String(n)}`, upto: "l-1" });
|
|
23
|
+
const view = (host: MemoryHost, note: string) => host.as<View>(rin, "memory.get", { note });
|
|
24
|
+
|
|
25
|
+
test("notes that came to say the same are merged into the older one, or into the one the owner confirmed", async () => {
|
|
26
|
+
const host = await memoryHost();
|
|
27
|
+
const fridays = await noted(host, "Releases go out on Fridays.", { source: session(1) });
|
|
28
|
+
const thursdays = await noted(host, "Releases go out on Thursdays.", { source: session(2) });
|
|
29
|
+
await host.as(rin, "memory.correct", { note: thursdays, text: "Releases go out on Fridays." });
|
|
30
|
+
const tea = await noted(host, "He drinks green tea.", { about: "owner" });
|
|
31
|
+
const teaToo = await noted(host, "He drinks black tea.", { about: "owner", source: session(3) });
|
|
32
|
+
await host.as(rin, "memory.correct", { note: teaToo, text: "He drinks green tea" });
|
|
33
|
+
await host.as(owner, "memory.confirm", { memory: "rin", note: teaToo });
|
|
34
|
+
|
|
35
|
+
const plan = await host.as<Plan>(rin, "memory.consolidate", {});
|
|
36
|
+
expect(plan.merged).toEqual([
|
|
37
|
+
{ note: thursdays, into: fridays },
|
|
38
|
+
{ note: tea, into: teaToo },
|
|
39
|
+
]);
|
|
40
|
+
expect(await view(host, thursdays)).toMatchObject({ status: "merged" });
|
|
41
|
+
expect(await view(host, fridays)).toMatchObject({ status: "live", sources: 2 });
|
|
42
|
+
expect(await view(host, teaToo)).toMatchObject({ status: "live", confirmed: true });
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("a note is lifted once the owner confirmed it or it has enough sources; one dropped by hand stays out", async () => {
|
|
46
|
+
const host = await memoryHost({ limits: { liftAfter: 3 } });
|
|
47
|
+
const told = await noted(host, "Deploys need a review.", { source: session(1) });
|
|
48
|
+
for (const n of [2, 3]) await noted(host, "Deploys need a review.", { source: session(n) });
|
|
49
|
+
const confirmed = await noted(host, "He reads mail in the morning.", { about: "owner" });
|
|
50
|
+
await host.as(owner, "memory.confirm", { memory: "rin", note: confirmed });
|
|
51
|
+
const twice = await noted(host, "Tests run in CI.", { source: session(4) });
|
|
52
|
+
await noted(host, "Tests run in CI.", { source: session(5) });
|
|
53
|
+
const kept = await noted(host, "Lint runs before tests.", { source: session(6) });
|
|
54
|
+
for (const n of [7, 8]) await noted(host, "Lint runs before tests.", { source: session(n) });
|
|
55
|
+
await host.as(rin, "memory.drop", { note: kept });
|
|
56
|
+
|
|
57
|
+
const plan = await host.as<Plan>(rin, "memory.consolidate", {});
|
|
58
|
+
expect(plan.lifted.sort()).toEqual([told, confirmed].sort());
|
|
59
|
+
expect(await view(host, twice)).toMatchObject({ top: false });
|
|
60
|
+
expect(await view(host, kept)).toMatchObject({ top: false });
|
|
61
|
+
expect((await host.as<{ notes: string[] }>(rin, "memory.top", {})).notes.sort()).toEqual([told, confirmed].sort());
|
|
62
|
+
// Consolidated again, nothing more is to be done.
|
|
63
|
+
expect(await host.as<Plan>(rin, "memory.consolidate", {})).toEqual({ memory: "rin", merged: [], lifted: [], dropped: [], retired: [] });
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("a part of the top layer grown too long keeps its strongest notes, and never drops one lifted by hand", async () => {
|
|
67
|
+
const host = await memoryHost({ limits: { topNotes: 2 } });
|
|
68
|
+
const byHand = await noted(host, "Weakest but placed by hand.");
|
|
69
|
+
await host.as(rin, "memory.lift", { note: byHand });
|
|
70
|
+
const weak = await noted(host, "Weaker note with sources.", { source: session(1) });
|
|
71
|
+
for (const n of [2, 3]) await noted(host, "Weaker note with sources.", { source: session(n) });
|
|
72
|
+
expect((await host.as<Plan>(rin, "memory.consolidate", {})).lifted).toEqual([weak]);
|
|
73
|
+
|
|
74
|
+
const strong = await noted(host, "Strong note with sources.", { source: session(4) });
|
|
75
|
+
for (const n of [5, 6, 7]) await noted(host, "Strong note with sources.", { source: session(n) });
|
|
76
|
+
const plan = await host.as<Plan>(rin, "memory.consolidate", {});
|
|
77
|
+
expect(plan.lifted).toEqual([strong]);
|
|
78
|
+
expect(plan.dropped).toEqual([weak]);
|
|
79
|
+
expect((await host.as<{ notes: string[] }>(rin, "memory.top", {})).notes.sort()).toEqual([byHand, strong].sort());
|
|
80
|
+
// A note that would not fit is not lifted to be dropped at once.
|
|
81
|
+
const weaker = await noted(host, "Weakest note with sources.", { source: session(8) });
|
|
82
|
+
for (const n of [9, 10]) await noted(host, "Weakest note with sources.", { source: session(n) });
|
|
83
|
+
expect(await host.as<Plan>(rin, "memory.consolidate", {})).toMatchObject({ lifted: [], dropped: [] });
|
|
84
|
+
expect(await view(host, weaker)).toMatchObject({ top: false });
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("an unconfirmed note of one source goes stale and is retired; past the limit the oldest are retired", async () => {
|
|
88
|
+
const host = await memoryHost({ limits: { notes: 3, staleAfter: 30 * DAY } });
|
|
89
|
+
const stale = await noted(host, "The office is on the third floor.");
|
|
90
|
+
const confirmed = await noted(host, "He works from home on Mondays.", { about: "owner" });
|
|
91
|
+
await host.as(owner, "memory.confirm", { memory: "rin", note: confirmed });
|
|
92
|
+
const sourced = await noted(host, "The build takes ten minutes.", { source: session(1) });
|
|
93
|
+
await noted(host, "The build takes ten minutes.", { source: session(2) });
|
|
94
|
+
await host.clock.advance(31 * DAY);
|
|
95
|
+
const recent = await noted(host, "The coffee machine is broken.");
|
|
96
|
+
expect((await host.as<Plan>(rin, "memory.consolidate", {})).retired).toEqual([stale]);
|
|
97
|
+
expect(await view(host, stale)).toMatchObject({ status: "retired" });
|
|
98
|
+
expect((await host.as<{ hits: unknown[] }>(rin, "memory.search", { query: "office floor" })).hits).toEqual([]);
|
|
99
|
+
|
|
100
|
+
const newer = await noted(host, "Standup is at ten.");
|
|
101
|
+
const newest = await noted(host, "Lunch is at one.");
|
|
102
|
+
// Five hold and three fit: the oldest that are neither confirmed, placed by hand nor in the top layer go.
|
|
103
|
+
expect((await host.as<Plan>(rin, "memory.consolidate", {})).retired).toEqual([sourced, recent]);
|
|
104
|
+
expect((await host.as<{ notes: Array<{ note: string }> }>(rin, "memory.list", {})).notes.map((one) => one.note)).toEqual([newest, newer, confirmed]);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("a memory consolidates by itself once enough has changed in it as digests come in", async () => {
|
|
108
|
+
const host = await memoryHost({ limits: { consolidateEvery: 3, liftAfter: 2 } });
|
|
109
|
+
const note = await noted(host, "Invoices are made nightly.", { source: session(1) });
|
|
110
|
+
await noted(host, "Invoices are made nightly.", { source: session(2) });
|
|
111
|
+
const digest = (turn: string) => ({
|
|
112
|
+
agent: "rin",
|
|
113
|
+
turn,
|
|
114
|
+
kind: "fact" as const,
|
|
115
|
+
author: { kind: "niwa" as const, by: "workflow" },
|
|
116
|
+
text: "The session paused.",
|
|
117
|
+
source: { kind: "session-digest" as const, session: "claude s-1", upto: turn },
|
|
118
|
+
});
|
|
119
|
+
await host.host.emit(AgentTurnQueued, digest("fact-000001"));
|
|
120
|
+
const records = await until(host, "memory.consolidated");
|
|
121
|
+
expect(dataOf(records, "memory.consolidated")).toEqual([{ operation: expect.any(String), memory: "rin", merged: [], lifted: [note], dropped: [], retired: [] }]);
|
|
122
|
+
// Only one change since: the next digest does not consolidate again.
|
|
123
|
+
await host.host.emit(AgentTurnQueued, digest("fact-000002"));
|
|
124
|
+
await until(host, "memory.digest.taken", 2);
|
|
125
|
+
expect(dataOf(await host.records(), "memory.consolidated")).toHaveLength(1);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("a note the owner confirmed is never retired, even outside the top layer and past the limit", async () => {
|
|
129
|
+
const host = await memoryHost({ limits: { topNotes: 1, notes: 1, staleAfter: DAY } });
|
|
130
|
+
const older = await noted(host, "He works from home on Mondays.", { about: "owner" });
|
|
131
|
+
const newer = await noted(host, "He takes calls after ten.", { about: "owner" });
|
|
132
|
+
for (const note of [older, newer]) await host.as(owner, "memory.confirm", { memory: "rin", note });
|
|
133
|
+
await host.clock.advance(2 * DAY);
|
|
134
|
+
const plan = await host.as<Plan>(rin, "memory.consolidate", {});
|
|
135
|
+
expect(plan.lifted).toEqual([newer]);
|
|
136
|
+
expect(plan.retired).toEqual([]);
|
|
137
|
+
expect(await view(host, older)).toMatchObject({ status: "live", top: false });
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test("a corrected note stands on its new text alone: the sources of the old one and its place in the top layer do not carry over", async () => {
|
|
141
|
+
const host = await memoryHost({ limits: { liftAfter: 3 } });
|
|
142
|
+
const note = await noted(host, "Deploys need a review.", { source: session(1) });
|
|
143
|
+
for (const n of [2, 3]) await noted(host, "Deploys need a review.", { source: session(n) });
|
|
144
|
+
expect((await host.as<Plan>(rin, "memory.consolidate", {})).lifted).toEqual([note]);
|
|
145
|
+
expect(await view(host, note)).toMatchObject({ top: true, sources: 3 });
|
|
146
|
+
|
|
147
|
+
await host.as(rin, "memory.correct", { note, text: "Deploys need no review." });
|
|
148
|
+
expect(await view(host, note)).toMatchObject({ top: false, sources: 1, confirmed: false, revision: 2, by: rin, source: { kind: "inferred" } });
|
|
149
|
+
expect(await host.as<Plan>(rin, "memory.consolidate", {})).toMatchObject({ lifted: [] });
|
|
150
|
+
expect((await host.as<{ notes: string[] }>(rin, "memory.top", {})).notes).toEqual([]);
|
|
151
|
+
// The new text earns its own sources.
|
|
152
|
+
for (const n of [4, 5]) await noted(host, "Deploys need no review.", { source: session(n) });
|
|
153
|
+
expect(await view(host, note)).toMatchObject({ sources: 3 });
|
|
154
|
+
expect((await host.as<Plan>(rin, "memory.consolidate", {})).lifted).toEqual([note]);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test("the owner's correction is his word and one source; a note placed by hand keeps its place through a correction", async () => {
|
|
158
|
+
const host = await memoryHost({ limits: { liftAfter: 3 } });
|
|
159
|
+
const note = await noted(host, "Deploys need a review.", { source: session(1) });
|
|
160
|
+
for (const n of [2, 3]) await noted(host, "Deploys need a review.", { source: session(n) });
|
|
161
|
+
const placed = await noted(host, "Lint runs before tests.");
|
|
162
|
+
await host.as(rin, "memory.lift", { note: placed });
|
|
163
|
+
await host.as<Plan>(rin, "memory.consolidate", {});
|
|
164
|
+
|
|
165
|
+
await host.as(owner, "memory.correct", { memory: "rin", note, text: "Deploys need two reviews." });
|
|
166
|
+
expect(await view(host, note)).toMatchObject({ top: false, sources: 1, confirmed: true, by: owner, source: { kind: "owner" } });
|
|
167
|
+
expect((await host.as<Plan>(rin, "memory.consolidate", {})).lifted).toEqual([note]);
|
|
168
|
+
|
|
169
|
+
await host.as(rin, "memory.correct", { note: placed, text: "Lint runs after tests." });
|
|
170
|
+
expect(await view(host, placed)).toMatchObject({ top: true, pinned: true, sources: 1 });
|
|
171
|
+
});
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// Context requests: another agent is told only conclusions with their scope; a project's notes go to that
|
|
2
|
+
// project's agents; a note about the owner leaves only on his own answer. Every conclusion carries its
|
|
3
|
+
// source, and an answer can be read again as the memory stood when it was given.
|
|
4
|
+
|
|
5
|
+
import { afterEach, expect, test } from "bun:test";
|
|
6
|
+
|
|
7
|
+
import { CONFIRM_NO, CONFIRM_YES } from "@niwa-labs/core";
|
|
8
|
+
import type { Address } from "@niwa-labs/core";
|
|
9
|
+
import { connectAsOwner } from "@niwa-labs/testing";
|
|
10
|
+
|
|
11
|
+
import { bob, closeAll, dataOf, memoryHost, owner, rin, until } from "./fixtures/host.ts";
|
|
12
|
+
import type { MemoryHost } from "./fixtures/host.ts";
|
|
13
|
+
|
|
14
|
+
afterEach(closeAll);
|
|
15
|
+
|
|
16
|
+
type Item = { note: string; text: string; about: string; project?: string; detail?: string; confirmed: boolean; source: { owner: Address; note: string; seq: number } };
|
|
17
|
+
type Withheld = { note: string; reason: string; status?: string };
|
|
18
|
+
type Context = { memory: Address; for: Address; at: number; items: Item[]; withheld: Withheld[] };
|
|
19
|
+
|
|
20
|
+
const lead: Address = { kind: "agent", id: "lead" };
|
|
21
|
+
const AGENTS = [
|
|
22
|
+
{ name: "rin", harness: "h", prompt: "p" },
|
|
23
|
+
{ name: "bob", harness: "h", prompt: "p" },
|
|
24
|
+
{ name: "lead", harness: "h", prompt: "p", project: { cwd: "/work/billing" } },
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
async function served(): Promise<MemoryHost> {
|
|
28
|
+
return memoryHost({}, { agents: AGENTS });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function noted(host: MemoryHost, input: Record<string, unknown>, who: Address = rin): Promise<string> {
|
|
32
|
+
return (await host.as<{ note: string }>(who, "memory.note", input)).note;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const ask = (host: MemoryHost, who: Address | undefined, input: Record<string, unknown>) => host.as<Context>(who, "memory.context", { memory: "rin", purpose: "to plan the week", ...input });
|
|
36
|
+
|
|
37
|
+
async function answer(host: MemoryHost, id: string, yes: boolean): Promise<void> {
|
|
38
|
+
const client = await connectAsOwner(host.home);
|
|
39
|
+
try {
|
|
40
|
+
await client.call("request.answer" as never, { id, answer: { ids: [yes ? CONFIRM_YES : CONFIRM_NO] } } as never);
|
|
41
|
+
} finally {
|
|
42
|
+
await client.close();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
test("the memory's own agent and the owner are told everything; another agent only the conclusion and its scope", async () => {
|
|
47
|
+
const host = await served();
|
|
48
|
+
const note = await noted(host, { text: "Releases go out on Fridays.", detail: "Bob said so in the retro of week 40." });
|
|
49
|
+
const mine = await ask(host, rin, { query: "releases" });
|
|
50
|
+
expect(mine.for).toEqual(rin);
|
|
51
|
+
expect(mine.items).toEqual([
|
|
52
|
+
{ note, text: "Releases go out on Fridays.", about: "work", detail: "Bob said so in the retro of week 40.", confirmed: false, source: { owner: rin, note, seq: mine.items[0]!.source.seq } },
|
|
53
|
+
]);
|
|
54
|
+
expect((await ask(host, owner, { query: "releases" })).items[0]?.detail).toBe("Bob said so in the retro of week 40.");
|
|
55
|
+
const theirs = await ask(host, bob, { query: "releases" });
|
|
56
|
+
expect(theirs.items).toEqual([{ note, text: "Releases go out on Fridays.", about: "work", confirmed: false, source: { owner: rin, note, seq: mine.items[0]!.source.seq } }]);
|
|
57
|
+
expect(theirs.withheld).toEqual([]);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("a caller asks for itself; a handler or the host names the addressee", async () => {
|
|
61
|
+
const host = await served();
|
|
62
|
+
await noted(host, { text: "Releases go out on Fridays." });
|
|
63
|
+
await expect(ask(host, bob, { query: "releases", for: lead })).rejects.toThrow(/asks for itself/);
|
|
64
|
+
await expect(ask(host, undefined, { query: "releases" })).rejects.toThrow(/name the addressee/);
|
|
65
|
+
expect((await ask(host, undefined, { query: "releases", for: lead })).for).toEqual(lead);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("a project's notes go to that project's agents, and stay home from the others", async () => {
|
|
69
|
+
const host = await served();
|
|
70
|
+
const billing = await noted(host, { text: "Invoices are made nightly.", project: "/work/billing/api" });
|
|
71
|
+
const general = await noted(host, { text: "Invoices are checked by a person." });
|
|
72
|
+
const forLead = await ask(host, lead, { query: "invoices" });
|
|
73
|
+
expect(forLead.items.map((item) => item.note).sort()).toEqual([billing, general].sort());
|
|
74
|
+
const forBob = await ask(host, bob, { query: "invoices" });
|
|
75
|
+
expect(forBob.items.map((item) => item.note)).toEqual([general]);
|
|
76
|
+
// A note of another project is not even said to exist.
|
|
77
|
+
expect(forBob.withheld).toEqual([]);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("a note about the owner leaves only once he said yes, and is asked again when it changes", async () => {
|
|
81
|
+
const host = await served();
|
|
82
|
+
const note = await noted(host, { text: "He is on leave in May.", about: "owner", source: { kind: "session", session: "claude s-1", upto: "l-3" } });
|
|
83
|
+
const first = await ask(host, bob, { query: "leave May" });
|
|
84
|
+
expect(first.items).toEqual([]);
|
|
85
|
+
expect(first.withheld).toEqual([{ note, reason: "about-the-owner", status: "asked" }]);
|
|
86
|
+
const created = (await until(host, "request.created")).filter((one) => one.type === "request.created");
|
|
87
|
+
expect(created).toHaveLength(1);
|
|
88
|
+
const request = created[0]!.data as { id: string; to: Address; from: Address; input: { title: string; detail: string } };
|
|
89
|
+
expect(request.to).toEqual(owner);
|
|
90
|
+
expect(request.from).toEqual(rin);
|
|
91
|
+
expect(request.input.title).toBe("May agent bob be told what agent rin remembers about you?");
|
|
92
|
+
// The question names the note and says why; the text of a note about the owner is not in it.
|
|
93
|
+
expect(request.input.detail).not.toContain("He is on leave in May.");
|
|
94
|
+
expect(request.input.detail).toContain(note);
|
|
95
|
+
expect(request.input.detail).toContain("to plan the week");
|
|
96
|
+
// Asked again before he answers, he is not asked twice.
|
|
97
|
+
expect((await ask(host, bob, { query: "leave" })).withheld).toEqual([{ note, reason: "about-the-owner", status: "asked" }]);
|
|
98
|
+
|
|
99
|
+
await answer(host, request.id, true);
|
|
100
|
+
await until(host, "memory.share.answered");
|
|
101
|
+
const released = await ask(host, bob, { query: "leave" });
|
|
102
|
+
expect(released.items.map((item) => item.text)).toEqual(["He is on leave in May."]);
|
|
103
|
+
// The yes was for bob, not for every agent.
|
|
104
|
+
expect((await ask(host, lead, { query: "leave" })).withheld).toEqual([{ note, reason: "about-the-owner", status: "asked" }]);
|
|
105
|
+
|
|
106
|
+
await host.as(rin, "memory.correct", { note, text: "He is on leave in June." });
|
|
107
|
+
expect((await ask(host, bob, { query: "leave" })).withheld).toEqual([{ note, reason: "about-the-owner", status: "asked" }]);
|
|
108
|
+
expect(dataOf(await host.records(), "request.created")).toHaveLength(3);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("a no from the owner keeps the note home until he says otherwise", async () => {
|
|
112
|
+
const host = await served();
|
|
113
|
+
const note = await noted(host, { text: "He is on leave in May.", about: "owner" });
|
|
114
|
+
await ask(host, bob, { query: "leave" });
|
|
115
|
+
const [created] = await until(host, "request.created").then((all) => all.filter((one) => one.type === "request.created"));
|
|
116
|
+
await answer(host, (created!.data as { id: string }).id, false);
|
|
117
|
+
await until(host, "memory.share.answered");
|
|
118
|
+
expect((await ask(host, bob, { query: "leave" })).withheld).toEqual([{ note, reason: "about-the-owner", status: "refused" }]);
|
|
119
|
+
await expect(host.as(rin, "memory.share", { memory: "rin", note, for: bob, allowed: true })).rejects.toThrow(/only the owner/);
|
|
120
|
+
await host.as(owner, "memory.share", { memory: "rin", note, for: bob, allowed: true });
|
|
121
|
+
expect((await ask(host, bob, { query: "leave" })).items.map((item) => item.note)).toEqual([note]);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("an answer that is not the owner's own lets nothing leave", async () => {
|
|
125
|
+
const host = await served();
|
|
126
|
+
const note = await noted(host, { text: "He is on leave in May.", about: "owner" });
|
|
127
|
+
await ask(host, bob, { query: "leave" });
|
|
128
|
+
const [created] = await until(host, "request.created").then((all) => all.filter((one) => one.type === "request.created"));
|
|
129
|
+
const { id } = created!.data as { id: string };
|
|
130
|
+
expect(created!.data).toMatchObject({ answerPolicy: "owner-only" });
|
|
131
|
+
expect(await host.as(undefined, "request.resolve", { id, answer: { ids: [CONFIRM_YES] } })).toEqual({ answered: false });
|
|
132
|
+
expect((await ask(host, bob, { query: "leave" })).withheld).toEqual([{ note, reason: "about-the-owner", status: "asked" }]);
|
|
133
|
+
await answer(host, id, true);
|
|
134
|
+
await until(host, "memory.share.answered");
|
|
135
|
+
expect((await ask(host, bob, { query: "leave" })).items.map(item => item.note)).toEqual([note]);
|
|
136
|
+
expect(dataOf(await host.records(), "memory.share.answered")).toMatchObject([{ allowed: true, request: id }]);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test("an answer read again at its position tells the memory as it stood then", async () => {
|
|
140
|
+
const host = await served();
|
|
141
|
+
const note = await noted(host, { text: "Releases go out on Fridays." });
|
|
142
|
+
const then = await ask(host, bob, { query: "releases" });
|
|
143
|
+
await host.as(rin, "memory.correct", { note, text: "Releases go out on Thursdays." });
|
|
144
|
+
await host.as(rin, "memory.note", { text: "Releases are announced in the channel." });
|
|
145
|
+
expect((await ask(host, bob, { query: "releases" })).items.map((item) => item.text).sort()).toEqual(["Releases are announced in the channel.", "Releases go out on Thursdays."]);
|
|
146
|
+
const again = await ask(host, bob, { query: "releases", at: then.at });
|
|
147
|
+
expect(again.at).toBe(then.at);
|
|
148
|
+
expect(again.items).toEqual(then.items);
|
|
149
|
+
// Erased since, the note cannot be read back even at the old position.
|
|
150
|
+
await host.as(owner, "memory.erase", { memory: "rin", note });
|
|
151
|
+
expect((await ask(host, bob, { query: "fridays", at: then.at })).items).toEqual([]);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("only what the reader may read is ranked, and the limit counts only that", async () => {
|
|
155
|
+
const host = await served();
|
|
156
|
+
await noted(host, { text: "Invoices, invoices and more invoices are made nightly.", project: "/work/shop" });
|
|
157
|
+
const owners = await noted(host, { text: "He wants invoices invoices invoices checked by hand.", about: "owner" });
|
|
158
|
+
const general = await noted(host, { text: "Invoices are checked by a person." });
|
|
159
|
+
const told = await ask(host, lead, { query: "invoices", limit: 1 });
|
|
160
|
+
expect(told.items.map((item) => item.note)).toEqual([general]);
|
|
161
|
+
expect(told.withheld).toEqual([{ note: owners, reason: "about-the-owner", status: "asked" }]);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test("an answer rests on one position even while the addressee's definition is awaited", async () => {
|
|
165
|
+
let release: () => void = () => {};
|
|
166
|
+
const hold = new Promise<void>((resolve) => {
|
|
167
|
+
release = resolve;
|
|
168
|
+
});
|
|
169
|
+
const host = await memoryHost({}, { agents: AGENTS, hold });
|
|
170
|
+
await noted(host, { text: "Releases go out on Fridays." });
|
|
171
|
+
const pending = ask(host, undefined, { query: "releases", for: bob });
|
|
172
|
+
// While it waits, a note is written and a read moves the fold on.
|
|
173
|
+
await host.as(undefined, "memory.note", { memory: "rin", text: "Releases are announced in the channel." });
|
|
174
|
+
await host.as(owner, "memory.list", { memory: "rin" });
|
|
175
|
+
release();
|
|
176
|
+
const told = await pending;
|
|
177
|
+
expect(told.items.map((item) => item.text).sort()).toEqual(["Releases are announced in the channel.", "Releases go out on Fridays."]);
|
|
178
|
+
expect(told.items.every((item) => item.source.seq <= told.at)).toBe(true);
|
|
179
|
+
expect((await ask(host, undefined, { query: "releases", for: bob, at: told.at })).items).toEqual(told.items);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test("'asked' is said only when the owner was asked: a read at a position asks nobody and says so", async () => {
|
|
183
|
+
const host = await served();
|
|
184
|
+
const note = await noted(host, { text: "He is on leave in May.", about: "owner" });
|
|
185
|
+
const before = await ask(host, undefined, { query: "leave", for: bob, at: Number((await host.records()).at(-1)!.seq) });
|
|
186
|
+
expect(before.withheld).toEqual([{ note, reason: "about-the-owner", status: "not-asked" }]);
|
|
187
|
+
expect(dataOf(await host.records(), "memory.share.wanted")).toEqual([]);
|
|
188
|
+
|
|
189
|
+
expect((await ask(host, bob, { query: "leave" })).withheld).toEqual([{ note, reason: "about-the-owner", status: "asked" }]);
|
|
190
|
+
expect(dataOf(await host.records(), "memory.share.wanted")).toHaveLength(1);
|
|
191
|
+
// The question exists now; read at a position before it was put, the answer still says nobody had been asked.
|
|
192
|
+
expect((await ask(host, undefined, { query: "leave", for: bob, at: before.at })).withheld).toEqual([{ note, reason: "about-the-owner", status: "not-asked" }]);
|
|
193
|
+
expect((await ask(host, undefined, { query: "leave", for: bob, at: Number((await host.records()).at(-1)!.seq) })).withheld).toEqual([
|
|
194
|
+
{ note, reason: "about-the-owner", status: "asked" },
|
|
195
|
+
]);
|
|
196
|
+
expect(dataOf(await host.records(), "memory.share.wanted")).toHaveLength(1);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test("the owner's yes is for the purpose he was told, and a request for another purpose asks him again", async () => {
|
|
200
|
+
const host = await served();
|
|
201
|
+
const note = await noted(host, { text: "He is on leave in May.", about: "owner" });
|
|
202
|
+
await ask(host, bob, { query: "leave", purpose: "to plan the week" });
|
|
203
|
+
const [first] = (await until(host, "request.created")).filter((one) => one.type === "request.created");
|
|
204
|
+
await answer(host, (first!.data as { id: string }).id, true);
|
|
205
|
+
await until(host, "memory.share.answered");
|
|
206
|
+
expect((await ask(host, bob, { query: "leave", purpose: "to plan the week" })).items.map((item) => item.note)).toEqual([note]);
|
|
207
|
+
|
|
208
|
+
const other = await ask(host, bob, { query: "leave", purpose: "to write him a letter" });
|
|
209
|
+
expect(other.items).toEqual([]);
|
|
210
|
+
expect(other.withheld).toEqual([{ note, reason: "about-the-owner", status: "asked" }]);
|
|
211
|
+
const created = (await until(host, "request.created", 2)).filter((one) => one.type === "request.created");
|
|
212
|
+
expect((created[1]!.data as { input: { detail: string } }).input.detail).toContain("to write him a letter");
|
|
213
|
+
expect(dataOf(await host.records(), "memory.share.answered")).toMatchObject([{ purpose: "to plan the week", allowed: true }]);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test("the owner may allow a note for every purpose, or for one, in his own words", async () => {
|
|
217
|
+
const host = await served();
|
|
218
|
+
const note = await noted(host, { text: "He is on leave in May.", about: "owner" });
|
|
219
|
+
await host.as(owner, "memory.share", { memory: "rin", note, for: bob, allowed: true, purpose: "to plan the week" });
|
|
220
|
+
expect((await ask(host, bob, { query: "leave", purpose: "to plan the week" })).items).toHaveLength(1);
|
|
221
|
+
expect((await ask(host, bob, { query: "leave", purpose: "to write him a letter" })).items).toEqual([]);
|
|
222
|
+
await host.as(owner, "memory.share", { memory: "rin", note, for: bob, allowed: true });
|
|
223
|
+
expect((await ask(host, bob, { query: "leave", purpose: "to write him a letter" })).items).toHaveLength(1);
|
|
224
|
+
expect((await ask(host, lead, { query: "leave", purpose: "to plan the week" })).items).toEqual([]);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test("a question about a note that was corrected, retracted or erased is closed", async () => {
|
|
228
|
+
const host = await served();
|
|
229
|
+
const text = (n: number) => `He is on leave in month ${String(n)}.`;
|
|
230
|
+
const notes = [await noted(host, { text: text(1), about: "owner" }), await noted(host, { text: text(2), about: "owner" }), await noted(host, { text: text(3), about: "owner" })];
|
|
231
|
+
await ask(host, bob, { query: "leave month" });
|
|
232
|
+
const created = (await until(host, "request.created", 3)).filter((one) => one.type === "request.created");
|
|
233
|
+
expect(created).toHaveLength(3);
|
|
234
|
+
await host.as(rin, "memory.correct", { note: notes[0], text: "He is on leave in the autumn." });
|
|
235
|
+
await host.as(rin, "memory.retract", { note: notes[1] });
|
|
236
|
+
await host.as(owner, "memory.erase", { memory: "rin", note: notes[2] });
|
|
237
|
+
const ended = (await until(host, "request.cancelled", 3)).filter((one) => one.type === "request.cancelled");
|
|
238
|
+
expect(ended.map((one) => (one.data as { id: string }).id).sort()).toEqual(created.map((one) => (one.data as { id: string }).id).sort());
|
|
239
|
+
const { requests } = await host.as<{ requests: unknown[] }>(owner, "request.open", {});
|
|
240
|
+
expect(requests).toEqual([]);
|
|
241
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// A note written again in the same words is one more source of the note the memory holds, not a
|
|
2
|
+
// second copy; the same source counts once, and so does the same writer's own conclusion.
|
|
3
|
+
|
|
4
|
+
import { afterEach, expect, test } from "bun:test";
|
|
5
|
+
|
|
6
|
+
import { same } from "../src/same.ts";
|
|
7
|
+
import { closeAll, dataOf, memoryHost, owner, rin } from "./fixtures/host.ts";
|
|
8
|
+
|
|
9
|
+
afterEach(closeAll);
|
|
10
|
+
|
|
11
|
+
type Noted = { memory: string; note: string; corroborated: boolean };
|
|
12
|
+
|
|
13
|
+
test("texts say the same only when their words, their order, their numbers and their negations are the same", () => {
|
|
14
|
+
expect(same("Releases go out on Fridays.", "releases go out on fridays")).toBe(true);
|
|
15
|
+
expect(same("Releases go out on Fridays after the check.", "Releases go out on Fridays after a check.")).toBe(false);
|
|
16
|
+
expect(same("Releases go out on Fridays.", "Releases go out on Mondays.")).toBe(false);
|
|
17
|
+
expect(same("Billing deploys before reporting.", "Reporting deploys before billing.")).toBe(false);
|
|
18
|
+
expect(same("Deploy 5 servers.", "Deploy 6 servers.")).toBe(false);
|
|
19
|
+
expect(same("Deploys need a review.", "Deploys do not need a review.")).toBe(false);
|
|
20
|
+
expect(same("", "!")).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("a note that says the opposite in the same words is not the owner's word because he wrote the other order", async () => {
|
|
24
|
+
const host = await memoryHost();
|
|
25
|
+
const agents = await host.as<Noted>(rin, "memory.note", { text: "Billing deploys before reporting." });
|
|
26
|
+
const his = await host.as<Noted>(owner, "memory.note", { memory: "rin", text: "Reporting deploys before billing.", source: { kind: "owner" } });
|
|
27
|
+
expect(his.corroborated).toBe(false);
|
|
28
|
+
expect(his.note).not.toBe(agents.note);
|
|
29
|
+
expect(await host.as(rin, "memory.get", { note: agents.note })).toMatchObject({ confirmed: false, sources: 1, text: "Billing deploys before reporting." });
|
|
30
|
+
expect(await host.as(rin, "memory.get", { note: his.note })).toMatchObject({ confirmed: true, text: "Reporting deploys before billing." });
|
|
31
|
+
const plan = await host.as<{ merged: unknown[] }>(rin, "memory.consolidate", {});
|
|
32
|
+
expect(plan.merged).toEqual([]);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("a note written again from another source gains a source; from the same one it is the same note", async () => {
|
|
36
|
+
const host = await memoryHost();
|
|
37
|
+
const first = await host.as<Noted>(rin, "memory.note", { text: "Releases go out on Fridays.", source: { kind: "session", session: "claude s-1", upto: "l-2" } });
|
|
38
|
+
expect(first.corroborated).toBe(false);
|
|
39
|
+
const again = await host.as<Noted>(rin, "memory.note", { text: "releases go out on fridays", source: { kind: "session", session: "claude s-2", upto: "l-7" } });
|
|
40
|
+
expect(again).toEqual({ memory: "rin", note: first.note, corroborated: true });
|
|
41
|
+
const same = await host.as<Noted>(owner, "memory.note", { memory: "rin", text: "Releases go out on Fridays.", source: { kind: "session", session: "claude s-1", upto: "l-2" } });
|
|
42
|
+
expect(same).toEqual({ memory: "rin", note: first.note, corroborated: true });
|
|
43
|
+
// Her own conclusion, said twice, is still one source.
|
|
44
|
+
await host.as(rin, "memory.note", { text: "Releases go out on Fridays." });
|
|
45
|
+
await host.as(rin, "memory.note", { text: "Releases go out on Fridays!" });
|
|
46
|
+
const records = await host.records();
|
|
47
|
+
expect(dataOf(records, "memory.note.written")).toHaveLength(1);
|
|
48
|
+
expect(dataOf(records, "memory.note.corroborated")).toHaveLength(2);
|
|
49
|
+
expect(await host.as(rin, "memory.get", { note: first.note })).toMatchObject({ sources: 3 });
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("only a note that holds, about the same and for the same project, is corroborated", async () => {
|
|
53
|
+
const host = await memoryHost();
|
|
54
|
+
const billing = await host.as<Noted>(rin, "memory.note", { text: "Deploys need a review.", project: "/work/billing" });
|
|
55
|
+
expect((await host.as<Noted>(rin, "memory.note", { text: "Deploys need a review.", project: "/work/site" })).note).not.toBe(billing.note);
|
|
56
|
+
expect((await host.as<Noted>(rin, "memory.note", { text: "Deploys need a review.", about: "owner" })).note).not.toBe(billing.note);
|
|
57
|
+
await host.as(rin, "memory.retract", { note: billing.note });
|
|
58
|
+
const after = await host.as<Noted>(rin, "memory.note", { text: "Deploys need a review.", project: "/work/billing" });
|
|
59
|
+
expect(after.corroborated).toBe(false);
|
|
60
|
+
expect(after.note).not.toBe(billing.note);
|
|
61
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Delegate asks a memory for context without importing it: it sends and reads the part of
|
|
2
|
+
// memory.context its records describe. That part must stay one the memory takes and answers.
|
|
3
|
+
|
|
4
|
+
import { expect, test } from "bun:test";
|
|
5
|
+
import { ContextAnswer, ContextRequest } from "@niwa-labs/delegate/records";
|
|
6
|
+
import { unreadable, unsendable } from "@niwa-labs/testing";
|
|
7
|
+
|
|
8
|
+
import { memoryContext } from "../src/records.ts";
|
|
9
|
+
|
|
10
|
+
test("the memory takes the request for context delegate sends", () => {
|
|
11
|
+
expect(unsendable(ContextRequest, memoryContext.input)).toEqual([]);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test("delegate reads what the memory answers", () => {
|
|
15
|
+
expect(unreadable(ContextAnswer, memoryContext.output)).toEqual([]);
|
|
16
|
+
});
|