okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

Aly Raffauffeat(api)!: migrate daemon and clients to protocol 361c43ca

main
3.0 KiB66 linesraw
1"""Project memories survive sessions and can be recalled without scanning the workspace."""
2
3import json
4import re
5import unittest
6
7from harness import Albedo, Provider, python, text
8
9
10class MemoryTests(unittest.TestCase):
11    def test_project_memory_and_journal_are_searchable_and_loaded_into_new_sessions(
12        self,
13    ):
14        def script(request):
15            last = request["input"][-1]
16            if last.get("role") == "user" and "save notes" in str(last.get("content")):
17                return python(
18                    "memory.save('Prefer narrow adapters for VioletStore.\\n')\n"
19                    "memory.append('VioletStore supports durable receipts')\n"
20                    "memory.journal('Fixed VioletStore receipt replay')\n"
21                    "print(memory.read())\n"
22                    "print(memory.grep('receipt'))\n"
23                    "print(memory.search('receipts'))\n"
24                    "print(memory.search('replay'))"
25                )
26            return text("done")
27
28        provider = Provider(script)
29        self.addCleanup(provider.close)
30        with Albedo(provider, protocol="responses") as app:
31            workspace = app.root / "MiXeD-workspace"
32            workspace.mkdir()
33            first = app.session(workspace)
34            app.prompt(first, "save notes").close()
35            app.idle(first)
36            output = next(
37                json.loads(part["value"])["output"]
38                for entry in app.history(first)["items"]
39                if entry["kind"] == "tool_result" and entry["tool"]["name"] == "python"
40                for part in entry["content"]
41                if part["kind"] == "json" and part["field"] == "result"
42            )
43            self.assertIn("memory.md:3:", output)
44            self.assertRegex(output, r"journal/\d{4}-\d{2}-\d{2}\.md:1:")
45            self.assertIn("VioletStore supports durable receipts", output)
46            slug = re.sub(r"[^A-Za-z0-9]", "-", str(workspace))
47            root = app.home / "memories" / slug
48            self.assertIn(slug, [entry.name for entry in root.parent.iterdir()])
49            self.assertEqual(
50                (root / "memory.md").read_text(),
51                "Prefer narrow adapters for VioletStore.\n\n"
52                "VioletStore supports durable receipts\n",
53            )
54            second = app.session(workspace)
55            app.prompt(second, "what do we know?").close()
56            app.idle(second)
57            instructions = provider.requests[-1]["request"]["instructions"]
58            self.assertIn("Prefer narrow adapters for VioletStore", instructions)
59            self.assertIn("memory.search", instructions)
60            other = app.root / "other-workspace"
61            other.mkdir()
62            isolated = app.session(workspace=other)
63            app.prompt(isolated, "what do we know?").close()
64            app.idle(isolated)
65            instructions = provider.requests[-1]["request"]["instructions"]
66            self.assertNotIn("Prefer narrow adapters for VioletStore", instructions)