okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
61c43ca
main
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 ): 11def test_project_memory_and_journal_are_searchable_and_loaded_into_new_sessions ( 12self , 13 ): 14def script (request ): 15last = request ["input" ][- 1 ] 16if last .get ("role" )== "user" and "save notes" in str (last .get ("content" )): 17return 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 ) 26return text ("done" ) 27 28provider = Provider (script ) 29self .addCleanup (provider .close ) 30with Albedo (provider ,protocol = "responses" )as app : 31workspace = app .root / "MiXeD-workspace" 32workspace .mkdir () 33first = app .session (workspace ) 34app .prompt (first ,"save notes" ).close () 35app .idle (first ) 36output = next ( 37json .loads (part ["value" ])["output" ] 38for entry in app .history (first )["items" ] 39if entry ["kind" ]== "tool_result" and entry ["tool" ]["name" ]== "python" 40for part in entry ["content" ] 41if part ["kind" ]== "json" and part ["field" ]== "result" 42 ) 43self .assertIn ("memory.md:3:" ,output ) 44self .assertRegex (output ,r"journal/\d{4}-\d{2}-\d{2}\.md:1:" ) 45self .assertIn ("VioletStore supports durable receipts" ,output ) 46slug = re .sub (r"[^A-Za-z0-9]" ,"-" ,str (workspace )) 47root = app .home / "memories" / slug 48self .assertIn (slug , [entry .name for entry in root .parent .iterdir ()]) 49self .assertEqual ( 50 (root / "memory.md" ).read_text (), 51"Prefer narrow adapters for VioletStore.\n\n" 52"VioletStore supports durable receipts\n" , 53 ) 54second = app .session (workspace ) 55app .prompt (second ,"what do we know?" ).close () 56app .idle (second ) 57instructions = provider .requests [- 1 ]["request" ]["instructions" ] 58self .assertIn ("Prefer narrow adapters for VioletStore" ,instructions ) 59self .assertIn ("memory.search" ,instructions ) 60other = app .root / "other-workspace" 61other .mkdir () 62isolated = app .session (workspace = other ) 63app .prompt (isolated ,"what do we know?" ).close () 64app .idle (isolated ) 65instructions = provider .requests [- 1 ]["request" ]["instructions" ] 66self .assertNotIn ("Prefer narrow adapters for VioletStore" ,instructions )